lio_ethtool.c 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186
  1. /**********************************************************************
  2. * Author: Cavium, Inc.
  3. *
  4. * Contact: support@cavium.com
  5. * Please include "LiquidIO" in the subject.
  6. *
  7. * Copyright (c) 2003-2016 Cavium, Inc.
  8. *
  9. * This file is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License, Version 2, as
  11. * published by the Free Software Foundation.
  12. *
  13. * This file is distributed in the hope that it will be useful, but
  14. * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
  16. * NONINFRINGEMENT. See the GNU General Public License for more details.
  17. ***********************************************************************/
  18. #include <linux/netdevice.h>
  19. #include <linux/net_tstamp.h>
  20. #include <linux/pci.h>
  21. #include "liquidio_common.h"
  22. #include "octeon_droq.h"
  23. #include "octeon_iq.h"
  24. #include "response_manager.h"
  25. #include "octeon_device.h"
  26. #include "octeon_nic.h"
  27. #include "octeon_main.h"
  28. #include "octeon_network.h"
  29. #include "cn66xx_regs.h"
  30. #include "cn66xx_device.h"
  31. #include "cn23xx_pf_device.h"
  32. #include "cn23xx_vf_device.h"
  33. static int lio_reset_queues(struct net_device *netdev, uint32_t num_qs);
  34. struct oct_intrmod_context {
  35. int octeon_id;
  36. wait_queue_head_t wc;
  37. int cond;
  38. int status;
  39. };
  40. struct oct_intrmod_resp {
  41. u64 rh;
  42. struct oct_intrmod_cfg intrmod;
  43. u64 status;
  44. };
  45. struct oct_mdio_cmd_context {
  46. int octeon_id;
  47. wait_queue_head_t wc;
  48. int cond;
  49. };
  50. struct oct_mdio_cmd_resp {
  51. u64 rh;
  52. struct oct_mdio_cmd resp;
  53. u64 status;
  54. };
  55. #define OCT_MDIO45_RESP_SIZE (sizeof(struct oct_mdio_cmd_resp))
  56. /* Octeon's interface mode of operation */
  57. enum {
  58. INTERFACE_MODE_DISABLED,
  59. INTERFACE_MODE_RGMII,
  60. INTERFACE_MODE_GMII,
  61. INTERFACE_MODE_SPI,
  62. INTERFACE_MODE_PCIE,
  63. INTERFACE_MODE_XAUI,
  64. INTERFACE_MODE_SGMII,
  65. INTERFACE_MODE_PICMG,
  66. INTERFACE_MODE_NPI,
  67. INTERFACE_MODE_LOOP,
  68. INTERFACE_MODE_SRIO,
  69. INTERFACE_MODE_ILK,
  70. INTERFACE_MODE_RXAUI,
  71. INTERFACE_MODE_QSGMII,
  72. INTERFACE_MODE_AGL,
  73. INTERFACE_MODE_XLAUI,
  74. INTERFACE_MODE_XFI,
  75. INTERFACE_MODE_10G_KR,
  76. INTERFACE_MODE_40G_KR4,
  77. INTERFACE_MODE_MIXED,
  78. };
  79. #define OCT_ETHTOOL_REGDUMP_LEN 4096
  80. #define OCT_ETHTOOL_REGDUMP_LEN_23XX (4096 * 11)
  81. #define OCT_ETHTOOL_REGDUMP_LEN_23XX_VF (4096 * 2)
  82. #define OCT_ETHTOOL_REGSVER 1
  83. /* statistics of PF */
  84. static const char oct_stats_strings[][ETH_GSTRING_LEN] = {
  85. "rx_packets",
  86. "tx_packets",
  87. "rx_bytes",
  88. "tx_bytes",
  89. "rx_errors",
  90. "tx_errors",
  91. "rx_dropped",
  92. "tx_dropped",
  93. "tx_total_sent",
  94. "tx_total_fwd",
  95. "tx_err_pko",
  96. "tx_err_pki",
  97. "tx_err_link",
  98. "tx_err_drop",
  99. "tx_tso",
  100. "tx_tso_packets",
  101. "tx_tso_err",
  102. "tx_vxlan",
  103. "tx_mcast",
  104. "tx_bcast",
  105. "mac_tx_total_pkts",
  106. "mac_tx_total_bytes",
  107. "mac_tx_mcast_pkts",
  108. "mac_tx_bcast_pkts",
  109. "mac_tx_ctl_packets",
  110. "mac_tx_total_collisions",
  111. "mac_tx_one_collision",
  112. "mac_tx_multi_collision",
  113. "mac_tx_max_collision_fail",
  114. "mac_tx_max_deferal_fail",
  115. "mac_tx_fifo_err",
  116. "mac_tx_runts",
  117. "rx_total_rcvd",
  118. "rx_total_fwd",
  119. "rx_mcast",
  120. "rx_bcast",
  121. "rx_jabber_err",
  122. "rx_l2_err",
  123. "rx_frame_err",
  124. "rx_err_pko",
  125. "rx_err_link",
  126. "rx_err_drop",
  127. "rx_vxlan",
  128. "rx_vxlan_err",
  129. "rx_lro_pkts",
  130. "rx_lro_bytes",
  131. "rx_total_lro",
  132. "rx_lro_aborts",
  133. "rx_lro_aborts_port",
  134. "rx_lro_aborts_seq",
  135. "rx_lro_aborts_tsval",
  136. "rx_lro_aborts_timer",
  137. "rx_fwd_rate",
  138. "mac_rx_total_rcvd",
  139. "mac_rx_bytes",
  140. "mac_rx_total_bcst",
  141. "mac_rx_total_mcst",
  142. "mac_rx_runts",
  143. "mac_rx_ctl_packets",
  144. "mac_rx_fifo_err",
  145. "mac_rx_dma_drop",
  146. "mac_rx_fcs_err",
  147. "link_state_changes",
  148. };
  149. /* statistics of VF */
  150. static const char oct_vf_stats_strings[][ETH_GSTRING_LEN] = {
  151. "rx_packets",
  152. "tx_packets",
  153. "rx_bytes",
  154. "tx_bytes",
  155. "rx_errors",
  156. "tx_errors",
  157. "rx_dropped",
  158. "tx_dropped",
  159. "rx_mcast",
  160. "tx_mcast",
  161. "rx_bcast",
  162. "tx_bcast",
  163. "link_state_changes",
  164. };
  165. /* statistics of host tx queue */
  166. static const char oct_iq_stats_strings[][ETH_GSTRING_LEN] = {
  167. "packets",
  168. "bytes",
  169. "dropped",
  170. "iq_busy",
  171. "sgentry_sent",
  172. "fw_instr_posted",
  173. "fw_instr_processed",
  174. "fw_instr_dropped",
  175. "fw_bytes_sent",
  176. "tso",
  177. "vxlan",
  178. "txq_restart",
  179. };
  180. /* statistics of host rx queue */
  181. static const char oct_droq_stats_strings[][ETH_GSTRING_LEN] = {
  182. "packets",
  183. "bytes",
  184. "dropped",
  185. "dropped_nomem",
  186. "dropped_toomany",
  187. "fw_dropped",
  188. "fw_pkts_received",
  189. "fw_bytes_received",
  190. "fw_dropped_nodispatch",
  191. "vxlan",
  192. "buffer_alloc_failure",
  193. };
  194. /* LiquidIO driver private flags */
  195. static const char oct_priv_flags_strings[][ETH_GSTRING_LEN] = {
  196. };
  197. #define OCTNIC_NCMD_AUTONEG_ON 0x1
  198. #define OCTNIC_NCMD_PHY_ON 0x2
  199. static int lio_get_link_ksettings(struct net_device *netdev,
  200. struct ethtool_link_ksettings *ecmd)
  201. {
  202. struct lio *lio = GET_LIO(netdev);
  203. struct octeon_device *oct = lio->oct_dev;
  204. struct oct_link_info *linfo;
  205. linfo = &lio->linfo;
  206. ethtool_link_ksettings_zero_link_mode(ecmd, supported);
  207. ethtool_link_ksettings_zero_link_mode(ecmd, advertising);
  208. switch (linfo->link.s.phy_type) {
  209. case LIO_PHY_PORT_TP:
  210. ecmd->base.port = PORT_TP;
  211. ecmd->base.autoneg = AUTONEG_DISABLE;
  212. ethtool_link_ksettings_add_link_mode(ecmd, supported, TP);
  213. ethtool_link_ksettings_add_link_mode(ecmd, supported, Pause);
  214. ethtool_link_ksettings_add_link_mode(ecmd, supported,
  215. 10000baseT_Full);
  216. ethtool_link_ksettings_add_link_mode(ecmd, advertising, Pause);
  217. ethtool_link_ksettings_add_link_mode(ecmd, advertising,
  218. 10000baseT_Full);
  219. break;
  220. case LIO_PHY_PORT_FIBRE:
  221. if (linfo->link.s.if_mode == INTERFACE_MODE_XAUI ||
  222. linfo->link.s.if_mode == INTERFACE_MODE_RXAUI ||
  223. linfo->link.s.if_mode == INTERFACE_MODE_XLAUI ||
  224. linfo->link.s.if_mode == INTERFACE_MODE_XFI) {
  225. dev_dbg(&oct->pci_dev->dev, "ecmd->base.transceiver is XCVR_EXTERNAL\n");
  226. } else {
  227. dev_err(&oct->pci_dev->dev, "Unknown link interface mode: %d\n",
  228. linfo->link.s.if_mode);
  229. }
  230. ecmd->base.port = PORT_FIBRE;
  231. ecmd->base.autoneg = AUTONEG_DISABLE;
  232. ethtool_link_ksettings_add_link_mode(ecmd, supported, FIBRE);
  233. ethtool_link_ksettings_add_link_mode(ecmd, supported, Pause);
  234. ethtool_link_ksettings_add_link_mode(ecmd, advertising, Pause);
  235. if (oct->subsystem_id == OCTEON_CN2350_25GB_SUBSYS_ID ||
  236. oct->subsystem_id == OCTEON_CN2360_25GB_SUBSYS_ID) {
  237. if (OCTEON_CN23XX_PF(oct)) {
  238. ethtool_link_ksettings_add_link_mode
  239. (ecmd, supported, 25000baseSR_Full);
  240. ethtool_link_ksettings_add_link_mode
  241. (ecmd, supported, 25000baseKR_Full);
  242. ethtool_link_ksettings_add_link_mode
  243. (ecmd, supported, 25000baseCR_Full);
  244. if (oct->no_speed_setting == 0) {
  245. ethtool_link_ksettings_add_link_mode
  246. (ecmd, supported,
  247. 10000baseSR_Full);
  248. ethtool_link_ksettings_add_link_mode
  249. (ecmd, supported,
  250. 10000baseKR_Full);
  251. ethtool_link_ksettings_add_link_mode
  252. (ecmd, supported,
  253. 10000baseCR_Full);
  254. }
  255. if (oct->no_speed_setting == 0)
  256. liquidio_get_speed(lio);
  257. else
  258. oct->speed_setting = 25;
  259. if (oct->speed_setting == 10) {
  260. ethtool_link_ksettings_add_link_mode
  261. (ecmd, advertising,
  262. 10000baseSR_Full);
  263. ethtool_link_ksettings_add_link_mode
  264. (ecmd, advertising,
  265. 10000baseKR_Full);
  266. ethtool_link_ksettings_add_link_mode
  267. (ecmd, advertising,
  268. 10000baseCR_Full);
  269. }
  270. if (oct->speed_setting == 25) {
  271. ethtool_link_ksettings_add_link_mode
  272. (ecmd, advertising,
  273. 25000baseSR_Full);
  274. ethtool_link_ksettings_add_link_mode
  275. (ecmd, advertising,
  276. 25000baseKR_Full);
  277. ethtool_link_ksettings_add_link_mode
  278. (ecmd, advertising,
  279. 25000baseCR_Full);
  280. }
  281. } else { /* VF */
  282. if (linfo->link.s.speed == 10000) {
  283. ethtool_link_ksettings_add_link_mode
  284. (ecmd, supported,
  285. 10000baseSR_Full);
  286. ethtool_link_ksettings_add_link_mode
  287. (ecmd, supported,
  288. 10000baseKR_Full);
  289. ethtool_link_ksettings_add_link_mode
  290. (ecmd, supported,
  291. 10000baseCR_Full);
  292. ethtool_link_ksettings_add_link_mode
  293. (ecmd, advertising,
  294. 10000baseSR_Full);
  295. ethtool_link_ksettings_add_link_mode
  296. (ecmd, advertising,
  297. 10000baseKR_Full);
  298. ethtool_link_ksettings_add_link_mode
  299. (ecmd, advertising,
  300. 10000baseCR_Full);
  301. }
  302. if (linfo->link.s.speed == 25000) {
  303. ethtool_link_ksettings_add_link_mode
  304. (ecmd, supported,
  305. 25000baseSR_Full);
  306. ethtool_link_ksettings_add_link_mode
  307. (ecmd, supported,
  308. 25000baseKR_Full);
  309. ethtool_link_ksettings_add_link_mode
  310. (ecmd, supported,
  311. 25000baseCR_Full);
  312. ethtool_link_ksettings_add_link_mode
  313. (ecmd, advertising,
  314. 25000baseSR_Full);
  315. ethtool_link_ksettings_add_link_mode
  316. (ecmd, advertising,
  317. 25000baseKR_Full);
  318. ethtool_link_ksettings_add_link_mode
  319. (ecmd, advertising,
  320. 25000baseCR_Full);
  321. }
  322. }
  323. } else {
  324. ethtool_link_ksettings_add_link_mode(ecmd, supported,
  325. 10000baseT_Full);
  326. ethtool_link_ksettings_add_link_mode(ecmd, advertising,
  327. 10000baseT_Full);
  328. }
  329. break;
  330. }
  331. if (linfo->link.s.link_up) {
  332. ecmd->base.speed = linfo->link.s.speed;
  333. ecmd->base.duplex = linfo->link.s.duplex;
  334. } else {
  335. ecmd->base.speed = SPEED_UNKNOWN;
  336. ecmd->base.duplex = DUPLEX_UNKNOWN;
  337. }
  338. return 0;
  339. }
  340. static int lio_set_link_ksettings(struct net_device *netdev,
  341. const struct ethtool_link_ksettings *ecmd)
  342. {
  343. const int speed = ecmd->base.speed;
  344. struct lio *lio = GET_LIO(netdev);
  345. struct oct_link_info *linfo;
  346. struct octeon_device *oct;
  347. oct = lio->oct_dev;
  348. linfo = &lio->linfo;
  349. if (!(oct->subsystem_id == OCTEON_CN2350_25GB_SUBSYS_ID ||
  350. oct->subsystem_id == OCTEON_CN2360_25GB_SUBSYS_ID))
  351. return -EOPNOTSUPP;
  352. if (oct->no_speed_setting) {
  353. dev_err(&oct->pci_dev->dev, "%s: Changing speed is not supported\n",
  354. __func__);
  355. return -EOPNOTSUPP;
  356. }
  357. if ((ecmd->base.duplex != DUPLEX_UNKNOWN &&
  358. ecmd->base.duplex != linfo->link.s.duplex) ||
  359. ecmd->base.autoneg != AUTONEG_DISABLE ||
  360. (ecmd->base.speed != 10000 && ecmd->base.speed != 25000 &&
  361. ecmd->base.speed != SPEED_UNKNOWN))
  362. return -EOPNOTSUPP;
  363. if ((oct->speed_boot == speed / 1000) &&
  364. oct->speed_boot == oct->speed_setting)
  365. return 0;
  366. liquidio_set_speed(lio, speed / 1000);
  367. dev_dbg(&oct->pci_dev->dev, "Port speed is set to %dG\n",
  368. oct->speed_setting);
  369. return 0;
  370. }
  371. static void
  372. lio_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
  373. {
  374. struct lio *lio;
  375. struct octeon_device *oct;
  376. lio = GET_LIO(netdev);
  377. oct = lio->oct_dev;
  378. memset(drvinfo, 0, sizeof(struct ethtool_drvinfo));
  379. strcpy(drvinfo->driver, "liquidio");
  380. strcpy(drvinfo->version, LIQUIDIO_VERSION);
  381. strncpy(drvinfo->fw_version, oct->fw_info.liquidio_firmware_version,
  382. ETHTOOL_FWVERS_LEN);
  383. strncpy(drvinfo->bus_info, pci_name(oct->pci_dev), 32);
  384. }
  385. static void
  386. lio_get_vf_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
  387. {
  388. struct octeon_device *oct;
  389. struct lio *lio;
  390. lio = GET_LIO(netdev);
  391. oct = lio->oct_dev;
  392. memset(drvinfo, 0, sizeof(struct ethtool_drvinfo));
  393. strcpy(drvinfo->driver, "liquidio_vf");
  394. strcpy(drvinfo->version, LIQUIDIO_VERSION);
  395. strncpy(drvinfo->fw_version, oct->fw_info.liquidio_firmware_version,
  396. ETHTOOL_FWVERS_LEN);
  397. strncpy(drvinfo->bus_info, pci_name(oct->pci_dev), 32);
  398. }
  399. static int
  400. lio_send_queue_count_update(struct net_device *netdev, uint32_t num_queues)
  401. {
  402. struct lio *lio = GET_LIO(netdev);
  403. struct octeon_device *oct = lio->oct_dev;
  404. struct octnic_ctrl_pkt nctrl;
  405. int ret = 0;
  406. memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
  407. nctrl.ncmd.u64 = 0;
  408. nctrl.ncmd.s.cmd = OCTNET_CMD_QUEUE_COUNT_CTL;
  409. nctrl.ncmd.s.param1 = num_queues;
  410. nctrl.ncmd.s.param2 = num_queues;
  411. nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
  412. nctrl.wait_time = 100;
  413. nctrl.netpndev = (u64)netdev;
  414. nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
  415. ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
  416. if (ret < 0) {
  417. dev_err(&oct->pci_dev->dev, "Failed to send Queue reset command (ret: 0x%x)\n",
  418. ret);
  419. return -1;
  420. }
  421. return 0;
  422. }
  423. static void
  424. lio_ethtool_get_channels(struct net_device *dev,
  425. struct ethtool_channels *channel)
  426. {
  427. struct lio *lio = GET_LIO(dev);
  428. struct octeon_device *oct = lio->oct_dev;
  429. u32 max_rx = 0, max_tx = 0, tx_count = 0, rx_count = 0;
  430. u32 combined_count = 0, max_combined = 0;
  431. if (OCTEON_CN6XXX(oct)) {
  432. struct octeon_config *conf6x = CHIP_CONF(oct, cn6xxx);
  433. max_rx = CFG_GET_OQ_MAX_Q(conf6x);
  434. max_tx = CFG_GET_IQ_MAX_Q(conf6x);
  435. rx_count = CFG_GET_NUM_RXQS_NIC_IF(conf6x, lio->ifidx);
  436. tx_count = CFG_GET_NUM_TXQS_NIC_IF(conf6x, lio->ifidx);
  437. } else if (OCTEON_CN23XX_PF(oct)) {
  438. if (oct->sriov_info.sriov_enabled) {
  439. max_combined = lio->linfo.num_txpciq;
  440. } else {
  441. struct octeon_config *conf23_pf =
  442. CHIP_CONF(oct, cn23xx_pf);
  443. max_combined = CFG_GET_IQ_MAX_Q(conf23_pf);
  444. }
  445. combined_count = oct->num_iqs;
  446. } else if (OCTEON_CN23XX_VF(oct)) {
  447. u64 reg_val = 0ULL;
  448. u64 ctrl = CN23XX_VF_SLI_IQ_PKT_CONTROL64(0);
  449. reg_val = octeon_read_csr64(oct, ctrl);
  450. reg_val = reg_val >> CN23XX_PKT_INPUT_CTL_RPVF_POS;
  451. max_combined = reg_val & CN23XX_PKT_INPUT_CTL_RPVF_MASK;
  452. combined_count = oct->num_iqs;
  453. }
  454. channel->max_rx = max_rx;
  455. channel->max_tx = max_tx;
  456. channel->max_combined = max_combined;
  457. channel->rx_count = rx_count;
  458. channel->tx_count = tx_count;
  459. channel->combined_count = combined_count;
  460. }
  461. static int
  462. lio_irq_reallocate_irqs(struct octeon_device *oct, uint32_t num_ioqs)
  463. {
  464. struct msix_entry *msix_entries;
  465. int num_msix_irqs = 0;
  466. int i;
  467. if (!oct->msix_on)
  468. return 0;
  469. /* Disable the input and output queues now. No more packets will
  470. * arrive from Octeon.
  471. */
  472. oct->fn_list.disable_interrupt(oct, OCTEON_ALL_INTR);
  473. if (oct->msix_on) {
  474. if (OCTEON_CN23XX_PF(oct))
  475. num_msix_irqs = oct->num_msix_irqs - 1;
  476. else if (OCTEON_CN23XX_VF(oct))
  477. num_msix_irqs = oct->num_msix_irqs;
  478. msix_entries = (struct msix_entry *)oct->msix_entries;
  479. for (i = 0; i < num_msix_irqs; i++) {
  480. if (oct->ioq_vector[i].vector) {
  481. /* clear the affinity_cpumask */
  482. irq_set_affinity_hint(msix_entries[i].vector,
  483. NULL);
  484. free_irq(msix_entries[i].vector,
  485. &oct->ioq_vector[i]);
  486. oct->ioq_vector[i].vector = 0;
  487. }
  488. }
  489. /* non-iov vector's argument is oct struct */
  490. if (OCTEON_CN23XX_PF(oct))
  491. free_irq(msix_entries[i].vector, oct);
  492. pci_disable_msix(oct->pci_dev);
  493. kfree(oct->msix_entries);
  494. oct->msix_entries = NULL;
  495. }
  496. kfree(oct->irq_name_storage);
  497. oct->irq_name_storage = NULL;
  498. if (octeon_allocate_ioq_vector(oct, num_ioqs)) {
  499. dev_err(&oct->pci_dev->dev, "OCTEON: ioq vector allocation failed\n");
  500. return -1;
  501. }
  502. if (octeon_setup_interrupt(oct, num_ioqs)) {
  503. dev_info(&oct->pci_dev->dev, "Setup interrupt failed\n");
  504. return -1;
  505. }
  506. /* Enable Octeon device interrupts */
  507. oct->fn_list.enable_interrupt(oct, OCTEON_ALL_INTR);
  508. return 0;
  509. }
  510. static int
  511. lio_ethtool_set_channels(struct net_device *dev,
  512. struct ethtool_channels *channel)
  513. {
  514. u32 combined_count, max_combined;
  515. struct lio *lio = GET_LIO(dev);
  516. struct octeon_device *oct = lio->oct_dev;
  517. int stopped = 0;
  518. if (strcmp(oct->fw_info.liquidio_firmware_version, "1.6.1") < 0) {
  519. dev_err(&oct->pci_dev->dev, "Minimum firmware version required is 1.6.1\n");
  520. return -EINVAL;
  521. }
  522. if (!channel->combined_count || channel->other_count ||
  523. channel->rx_count || channel->tx_count)
  524. return -EINVAL;
  525. combined_count = channel->combined_count;
  526. if (OCTEON_CN23XX_PF(oct)) {
  527. if (oct->sriov_info.sriov_enabled) {
  528. max_combined = lio->linfo.num_txpciq;
  529. } else {
  530. struct octeon_config *conf23_pf =
  531. CHIP_CONF(oct,
  532. cn23xx_pf);
  533. max_combined =
  534. CFG_GET_IQ_MAX_Q(conf23_pf);
  535. }
  536. } else if (OCTEON_CN23XX_VF(oct)) {
  537. u64 reg_val = 0ULL;
  538. u64 ctrl = CN23XX_VF_SLI_IQ_PKT_CONTROL64(0);
  539. reg_val = octeon_read_csr64(oct, ctrl);
  540. reg_val = reg_val >> CN23XX_PKT_INPUT_CTL_RPVF_POS;
  541. max_combined = reg_val & CN23XX_PKT_INPUT_CTL_RPVF_MASK;
  542. } else {
  543. return -EINVAL;
  544. }
  545. if (combined_count > max_combined || combined_count < 1)
  546. return -EINVAL;
  547. if (combined_count == oct->num_iqs)
  548. return 0;
  549. ifstate_set(lio, LIO_IFSTATE_RESETTING);
  550. if (netif_running(dev)) {
  551. dev->netdev_ops->ndo_stop(dev);
  552. stopped = 1;
  553. }
  554. if (lio_reset_queues(dev, combined_count))
  555. return -EINVAL;
  556. if (stopped)
  557. dev->netdev_ops->ndo_open(dev);
  558. ifstate_reset(lio, LIO_IFSTATE_RESETTING);
  559. return 0;
  560. }
  561. static int lio_get_eeprom_len(struct net_device *netdev)
  562. {
  563. u8 buf[192];
  564. struct lio *lio = GET_LIO(netdev);
  565. struct octeon_device *oct_dev = lio->oct_dev;
  566. struct octeon_board_info *board_info;
  567. int len;
  568. board_info = (struct octeon_board_info *)(&oct_dev->boardinfo);
  569. len = sprintf(buf, "boardname:%s serialnum:%s maj:%lld min:%lld\n",
  570. board_info->name, board_info->serial_number,
  571. board_info->major, board_info->minor);
  572. return len;
  573. }
  574. static int
  575. lio_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
  576. u8 *bytes)
  577. {
  578. struct lio *lio = GET_LIO(netdev);
  579. struct octeon_device *oct_dev = lio->oct_dev;
  580. struct octeon_board_info *board_info;
  581. if (eeprom->offset)
  582. return -EINVAL;
  583. eeprom->magic = oct_dev->pci_dev->vendor;
  584. board_info = (struct octeon_board_info *)(&oct_dev->boardinfo);
  585. sprintf((char *)bytes,
  586. "boardname:%s serialnum:%s maj:%lld min:%lld\n",
  587. board_info->name, board_info->serial_number,
  588. board_info->major, board_info->minor);
  589. return 0;
  590. }
  591. static int octnet_gpio_access(struct net_device *netdev, int addr, int val)
  592. {
  593. struct lio *lio = GET_LIO(netdev);
  594. struct octeon_device *oct = lio->oct_dev;
  595. struct octnic_ctrl_pkt nctrl;
  596. int ret = 0;
  597. memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
  598. nctrl.ncmd.u64 = 0;
  599. nctrl.ncmd.s.cmd = OCTNET_CMD_GPIO_ACCESS;
  600. nctrl.ncmd.s.param1 = addr;
  601. nctrl.ncmd.s.param2 = val;
  602. nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
  603. nctrl.wait_time = 100;
  604. nctrl.netpndev = (u64)netdev;
  605. nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
  606. ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
  607. if (ret < 0) {
  608. dev_err(&oct->pci_dev->dev, "Failed to configure gpio value\n");
  609. return -EINVAL;
  610. }
  611. return 0;
  612. }
  613. static int octnet_id_active(struct net_device *netdev, int val)
  614. {
  615. struct lio *lio = GET_LIO(netdev);
  616. struct octeon_device *oct = lio->oct_dev;
  617. struct octnic_ctrl_pkt nctrl;
  618. int ret = 0;
  619. memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
  620. nctrl.ncmd.u64 = 0;
  621. nctrl.ncmd.s.cmd = OCTNET_CMD_ID_ACTIVE;
  622. nctrl.ncmd.s.param1 = val;
  623. nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
  624. nctrl.wait_time = 100;
  625. nctrl.netpndev = (u64)netdev;
  626. nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
  627. ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
  628. if (ret < 0) {
  629. dev_err(&oct->pci_dev->dev, "Failed to configure gpio value\n");
  630. return -EINVAL;
  631. }
  632. return 0;
  633. }
  634. /* Callback for when mdio command response arrives
  635. */
  636. static void octnet_mdio_resp_callback(struct octeon_device *oct,
  637. u32 status,
  638. void *buf)
  639. {
  640. struct oct_mdio_cmd_context *mdio_cmd_ctx;
  641. struct octeon_soft_command *sc = (struct octeon_soft_command *)buf;
  642. mdio_cmd_ctx = (struct oct_mdio_cmd_context *)sc->ctxptr;
  643. oct = lio_get_device(mdio_cmd_ctx->octeon_id);
  644. if (status) {
  645. dev_err(&oct->pci_dev->dev, "MIDO instruction failed. Status: %llx\n",
  646. CVM_CAST64(status));
  647. WRITE_ONCE(mdio_cmd_ctx->cond, -1);
  648. } else {
  649. WRITE_ONCE(mdio_cmd_ctx->cond, 1);
  650. }
  651. wake_up_interruptible(&mdio_cmd_ctx->wc);
  652. }
  653. /* This routine provides PHY access routines for
  654. * mdio clause45 .
  655. */
  656. static int
  657. octnet_mdio45_access(struct lio *lio, int op, int loc, int *value)
  658. {
  659. struct octeon_device *oct_dev = lio->oct_dev;
  660. struct octeon_soft_command *sc;
  661. struct oct_mdio_cmd_resp *mdio_cmd_rsp;
  662. struct oct_mdio_cmd_context *mdio_cmd_ctx;
  663. struct oct_mdio_cmd *mdio_cmd;
  664. int retval = 0;
  665. sc = (struct octeon_soft_command *)
  666. octeon_alloc_soft_command(oct_dev,
  667. sizeof(struct oct_mdio_cmd),
  668. sizeof(struct oct_mdio_cmd_resp),
  669. sizeof(struct oct_mdio_cmd_context));
  670. if (!sc)
  671. return -ENOMEM;
  672. mdio_cmd_ctx = (struct oct_mdio_cmd_context *)sc->ctxptr;
  673. mdio_cmd_rsp = (struct oct_mdio_cmd_resp *)sc->virtrptr;
  674. mdio_cmd = (struct oct_mdio_cmd *)sc->virtdptr;
  675. WRITE_ONCE(mdio_cmd_ctx->cond, 0);
  676. mdio_cmd_ctx->octeon_id = lio_get_device_id(oct_dev);
  677. mdio_cmd->op = op;
  678. mdio_cmd->mdio_addr = loc;
  679. if (op)
  680. mdio_cmd->value1 = *value;
  681. octeon_swap_8B_data((u64 *)mdio_cmd, sizeof(struct oct_mdio_cmd) / 8);
  682. sc->iq_no = lio->linfo.txpciq[0].s.q_no;
  683. octeon_prepare_soft_command(oct_dev, sc, OPCODE_NIC, OPCODE_NIC_MDIO45,
  684. 0, 0, 0);
  685. sc->wait_time = 1000;
  686. sc->callback = octnet_mdio_resp_callback;
  687. sc->callback_arg = sc;
  688. init_waitqueue_head(&mdio_cmd_ctx->wc);
  689. retval = octeon_send_soft_command(oct_dev, sc);
  690. if (retval == IQ_SEND_FAILED) {
  691. dev_err(&oct_dev->pci_dev->dev,
  692. "octnet_mdio45_access instruction failed status: %x\n",
  693. retval);
  694. retval = -EBUSY;
  695. } else {
  696. /* Sleep on a wait queue till the cond flag indicates that the
  697. * response arrived
  698. */
  699. sleep_cond(&mdio_cmd_ctx->wc, &mdio_cmd_ctx->cond);
  700. retval = mdio_cmd_rsp->status;
  701. if (retval) {
  702. dev_err(&oct_dev->pci_dev->dev, "octnet mdio45 access failed\n");
  703. retval = -EBUSY;
  704. } else {
  705. octeon_swap_8B_data((u64 *)(&mdio_cmd_rsp->resp),
  706. sizeof(struct oct_mdio_cmd) / 8);
  707. if (READ_ONCE(mdio_cmd_ctx->cond) == 1) {
  708. if (!op)
  709. *value = mdio_cmd_rsp->resp.value1;
  710. } else {
  711. retval = -EINVAL;
  712. }
  713. }
  714. }
  715. octeon_free_soft_command(oct_dev, sc);
  716. return retval;
  717. }
  718. static int lio_set_phys_id(struct net_device *netdev,
  719. enum ethtool_phys_id_state state)
  720. {
  721. struct lio *lio = GET_LIO(netdev);
  722. struct octeon_device *oct = lio->oct_dev;
  723. struct oct_link_info *linfo;
  724. int value, ret;
  725. u32 cur_ver;
  726. linfo = &lio->linfo;
  727. cur_ver = OCT_FW_VER(oct->fw_info.ver.maj,
  728. oct->fw_info.ver.min,
  729. oct->fw_info.ver.rev);
  730. switch (state) {
  731. case ETHTOOL_ID_ACTIVE:
  732. if (oct->chip_id == OCTEON_CN66XX) {
  733. octnet_gpio_access(netdev, VITESSE_PHY_GPIO_CFG,
  734. VITESSE_PHY_GPIO_DRIVEON);
  735. return 2;
  736. } else if (oct->chip_id == OCTEON_CN68XX) {
  737. /* Save the current LED settings */
  738. ret = octnet_mdio45_access(lio, 0,
  739. LIO68XX_LED_BEACON_ADDR,
  740. &lio->phy_beacon_val);
  741. if (ret)
  742. return ret;
  743. ret = octnet_mdio45_access(lio, 0,
  744. LIO68XX_LED_CTRL_ADDR,
  745. &lio->led_ctrl_val);
  746. if (ret)
  747. return ret;
  748. /* Configure Beacon values */
  749. value = LIO68XX_LED_BEACON_CFGON;
  750. ret = octnet_mdio45_access(lio, 1,
  751. LIO68XX_LED_BEACON_ADDR,
  752. &value);
  753. if (ret)
  754. return ret;
  755. value = LIO68XX_LED_CTRL_CFGON;
  756. ret = octnet_mdio45_access(lio, 1,
  757. LIO68XX_LED_CTRL_ADDR,
  758. &value);
  759. if (ret)
  760. return ret;
  761. } else if (oct->chip_id == OCTEON_CN23XX_PF_VID) {
  762. octnet_id_active(netdev, LED_IDENTIFICATION_ON);
  763. if (linfo->link.s.phy_type == LIO_PHY_PORT_TP &&
  764. cur_ver > OCT_FW_VER(1, 7, 2))
  765. return 2;
  766. else
  767. return 0;
  768. } else {
  769. return -EINVAL;
  770. }
  771. break;
  772. case ETHTOOL_ID_ON:
  773. if (oct->chip_id == OCTEON_CN23XX_PF_VID &&
  774. linfo->link.s.phy_type == LIO_PHY_PORT_TP &&
  775. cur_ver > OCT_FW_VER(1, 7, 2))
  776. octnet_id_active(netdev, LED_IDENTIFICATION_ON);
  777. else if (oct->chip_id == OCTEON_CN66XX)
  778. octnet_gpio_access(netdev, VITESSE_PHY_GPIO_CFG,
  779. VITESSE_PHY_GPIO_HIGH);
  780. else
  781. return -EINVAL;
  782. break;
  783. case ETHTOOL_ID_OFF:
  784. if (oct->chip_id == OCTEON_CN23XX_PF_VID &&
  785. linfo->link.s.phy_type == LIO_PHY_PORT_TP &&
  786. cur_ver > OCT_FW_VER(1, 7, 2))
  787. octnet_id_active(netdev, LED_IDENTIFICATION_OFF);
  788. else if (oct->chip_id == OCTEON_CN66XX)
  789. octnet_gpio_access(netdev, VITESSE_PHY_GPIO_CFG,
  790. VITESSE_PHY_GPIO_LOW);
  791. else
  792. return -EINVAL;
  793. break;
  794. case ETHTOOL_ID_INACTIVE:
  795. if (oct->chip_id == OCTEON_CN66XX) {
  796. octnet_gpio_access(netdev, VITESSE_PHY_GPIO_CFG,
  797. VITESSE_PHY_GPIO_DRIVEOFF);
  798. } else if (oct->chip_id == OCTEON_CN68XX) {
  799. /* Restore LED settings */
  800. ret = octnet_mdio45_access(lio, 1,
  801. LIO68XX_LED_CTRL_ADDR,
  802. &lio->led_ctrl_val);
  803. if (ret)
  804. return ret;
  805. ret = octnet_mdio45_access(lio, 1,
  806. LIO68XX_LED_BEACON_ADDR,
  807. &lio->phy_beacon_val);
  808. if (ret)
  809. return ret;
  810. } else if (oct->chip_id == OCTEON_CN23XX_PF_VID) {
  811. octnet_id_active(netdev, LED_IDENTIFICATION_OFF);
  812. return 0;
  813. } else {
  814. return -EINVAL;
  815. }
  816. break;
  817. default:
  818. return -EINVAL;
  819. }
  820. return 0;
  821. }
  822. static void
  823. lio_ethtool_get_ringparam(struct net_device *netdev,
  824. struct ethtool_ringparam *ering)
  825. {
  826. struct lio *lio = GET_LIO(netdev);
  827. struct octeon_device *oct = lio->oct_dev;
  828. u32 tx_max_pending = 0, rx_max_pending = 0, tx_pending = 0,
  829. rx_pending = 0;
  830. if (ifstate_check(lio, LIO_IFSTATE_RESETTING))
  831. return;
  832. if (OCTEON_CN6XXX(oct)) {
  833. struct octeon_config *conf6x = CHIP_CONF(oct, cn6xxx);
  834. tx_max_pending = CN6XXX_MAX_IQ_DESCRIPTORS;
  835. rx_max_pending = CN6XXX_MAX_OQ_DESCRIPTORS;
  836. rx_pending = CFG_GET_NUM_RX_DESCS_NIC_IF(conf6x, lio->ifidx);
  837. tx_pending = CFG_GET_NUM_TX_DESCS_NIC_IF(conf6x, lio->ifidx);
  838. } else if (OCTEON_CN23XX_PF(oct) || OCTEON_CN23XX_VF(oct)) {
  839. tx_max_pending = CN23XX_MAX_IQ_DESCRIPTORS;
  840. rx_max_pending = CN23XX_MAX_OQ_DESCRIPTORS;
  841. rx_pending = oct->droq[0]->max_count;
  842. tx_pending = oct->instr_queue[0]->max_count;
  843. }
  844. ering->tx_pending = tx_pending;
  845. ering->tx_max_pending = tx_max_pending;
  846. ering->rx_pending = rx_pending;
  847. ering->rx_max_pending = rx_max_pending;
  848. ering->rx_mini_pending = 0;
  849. ering->rx_jumbo_pending = 0;
  850. ering->rx_mini_max_pending = 0;
  851. ering->rx_jumbo_max_pending = 0;
  852. }
  853. static int lio_23xx_reconfigure_queue_count(struct lio *lio)
  854. {
  855. struct octeon_device *oct = lio->oct_dev;
  856. struct liquidio_if_cfg_context *ctx;
  857. u32 resp_size, ctx_size, data_size;
  858. struct liquidio_if_cfg_resp *resp;
  859. struct octeon_soft_command *sc;
  860. union oct_nic_if_cfg if_cfg;
  861. struct lio_version *vdata;
  862. u32 ifidx_or_pfnum;
  863. int retval;
  864. int j;
  865. resp_size = sizeof(struct liquidio_if_cfg_resp);
  866. ctx_size = sizeof(struct liquidio_if_cfg_context);
  867. data_size = sizeof(struct lio_version);
  868. sc = (struct octeon_soft_command *)
  869. octeon_alloc_soft_command(oct, data_size,
  870. resp_size, ctx_size);
  871. if (!sc) {
  872. dev_err(&oct->pci_dev->dev, "%s: Failed to allocate soft command\n",
  873. __func__);
  874. return -1;
  875. }
  876. resp = (struct liquidio_if_cfg_resp *)sc->virtrptr;
  877. ctx = (struct liquidio_if_cfg_context *)sc->ctxptr;
  878. vdata = (struct lio_version *)sc->virtdptr;
  879. vdata->major = (__force u16)cpu_to_be16(LIQUIDIO_BASE_MAJOR_VERSION);
  880. vdata->minor = (__force u16)cpu_to_be16(LIQUIDIO_BASE_MINOR_VERSION);
  881. vdata->micro = (__force u16)cpu_to_be16(LIQUIDIO_BASE_MICRO_VERSION);
  882. ifidx_or_pfnum = oct->pf_num;
  883. WRITE_ONCE(ctx->cond, 0);
  884. ctx->octeon_id = lio_get_device_id(oct);
  885. init_waitqueue_head(&ctx->wc);
  886. if_cfg.u64 = 0;
  887. if_cfg.s.num_iqueues = oct->sriov_info.num_pf_rings;
  888. if_cfg.s.num_oqueues = oct->sriov_info.num_pf_rings;
  889. if_cfg.s.base_queue = oct->sriov_info.pf_srn;
  890. if_cfg.s.gmx_port_id = oct->pf_num;
  891. sc->iq_no = 0;
  892. octeon_prepare_soft_command(oct, sc, OPCODE_NIC,
  893. OPCODE_NIC_QCOUNT_UPDATE, 0,
  894. if_cfg.u64, 0);
  895. sc->callback = lio_if_cfg_callback;
  896. sc->callback_arg = sc;
  897. sc->wait_time = LIO_IFCFG_WAIT_TIME;
  898. retval = octeon_send_soft_command(oct, sc);
  899. if (retval == IQ_SEND_FAILED) {
  900. dev_err(&oct->pci_dev->dev,
  901. "iq/oq config failed status: %x\n",
  902. retval);
  903. goto qcount_update_fail;
  904. }
  905. if (sleep_cond(&ctx->wc, &ctx->cond) == -EINTR) {
  906. dev_err(&oct->pci_dev->dev, "Wait interrupted\n");
  907. return -1;
  908. }
  909. retval = resp->status;
  910. if (retval) {
  911. dev_err(&oct->pci_dev->dev, "iq/oq config failed\n");
  912. goto qcount_update_fail;
  913. }
  914. octeon_swap_8B_data((u64 *)(&resp->cfg_info),
  915. (sizeof(struct liquidio_if_cfg_info)) >> 3);
  916. lio->ifidx = ifidx_or_pfnum;
  917. lio->linfo.num_rxpciq = hweight64(resp->cfg_info.iqmask);
  918. lio->linfo.num_txpciq = hweight64(resp->cfg_info.iqmask);
  919. for (j = 0; j < lio->linfo.num_rxpciq; j++) {
  920. lio->linfo.rxpciq[j].u64 =
  921. resp->cfg_info.linfo.rxpciq[j].u64;
  922. }
  923. for (j = 0; j < lio->linfo.num_txpciq; j++) {
  924. lio->linfo.txpciq[j].u64 =
  925. resp->cfg_info.linfo.txpciq[j].u64;
  926. }
  927. lio->linfo.hw_addr = resp->cfg_info.linfo.hw_addr;
  928. lio->linfo.gmxport = resp->cfg_info.linfo.gmxport;
  929. lio->linfo.link.u64 = resp->cfg_info.linfo.link.u64;
  930. lio->txq = lio->linfo.txpciq[0].s.q_no;
  931. lio->rxq = lio->linfo.rxpciq[0].s.q_no;
  932. octeon_free_soft_command(oct, sc);
  933. dev_info(&oct->pci_dev->dev, "Queue count updated to %d\n",
  934. lio->linfo.num_rxpciq);
  935. return 0;
  936. qcount_update_fail:
  937. octeon_free_soft_command(oct, sc);
  938. return -1;
  939. }
  940. static int lio_reset_queues(struct net_device *netdev, uint32_t num_qs)
  941. {
  942. struct lio *lio = GET_LIO(netdev);
  943. struct octeon_device *oct = lio->oct_dev;
  944. int i, queue_count_update = 0;
  945. struct napi_struct *napi, *n;
  946. int ret;
  947. schedule_timeout_uninterruptible(msecs_to_jiffies(100));
  948. if (wait_for_pending_requests(oct))
  949. dev_err(&oct->pci_dev->dev, "There were pending requests\n");
  950. if (lio_wait_for_instr_fetch(oct))
  951. dev_err(&oct->pci_dev->dev, "IQ had pending instructions\n");
  952. if (octeon_set_io_queues_off(oct)) {
  953. dev_err(&oct->pci_dev->dev, "Setting io queues off failed\n");
  954. return -1;
  955. }
  956. /* Disable the input and output queues now. No more packets will
  957. * arrive from Octeon.
  958. */
  959. oct->fn_list.disable_io_queues(oct);
  960. /* Delete NAPI */
  961. list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list)
  962. netif_napi_del(napi);
  963. if (num_qs != oct->num_iqs) {
  964. ret = netif_set_real_num_rx_queues(netdev, num_qs);
  965. if (ret) {
  966. dev_err(&oct->pci_dev->dev,
  967. "Setting real number rx failed\n");
  968. return ret;
  969. }
  970. ret = netif_set_real_num_tx_queues(netdev, num_qs);
  971. if (ret) {
  972. dev_err(&oct->pci_dev->dev,
  973. "Setting real number tx failed\n");
  974. return ret;
  975. }
  976. /* The value of queue_count_update decides whether it is the
  977. * queue count or the descriptor count that is being
  978. * re-configured.
  979. */
  980. queue_count_update = 1;
  981. }
  982. /* Re-configuration of queues can happen in two scenarios, SRIOV enabled
  983. * and SRIOV disabled. Few things like recreating queue zero, resetting
  984. * glists and IRQs are required for both. For the latter, some more
  985. * steps like updating sriov_info for the octeon device need to be done.
  986. */
  987. if (queue_count_update) {
  988. lio_delete_glists(lio);
  989. /* Delete mbox for PF which is SRIOV disabled because sriov_info
  990. * will be now changed.
  991. */
  992. if ((OCTEON_CN23XX_PF(oct)) && !oct->sriov_info.sriov_enabled)
  993. oct->fn_list.free_mbox(oct);
  994. }
  995. for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct); i++) {
  996. if (!(oct->io_qmask.oq & BIT_ULL(i)))
  997. continue;
  998. octeon_delete_droq(oct, i);
  999. }
  1000. for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct); i++) {
  1001. if (!(oct->io_qmask.iq & BIT_ULL(i)))
  1002. continue;
  1003. octeon_delete_instr_queue(oct, i);
  1004. }
  1005. if (queue_count_update) {
  1006. /* For PF re-configure sriov related information */
  1007. if ((OCTEON_CN23XX_PF(oct)) &&
  1008. !oct->sriov_info.sriov_enabled) {
  1009. oct->sriov_info.num_pf_rings = num_qs;
  1010. if (cn23xx_sriov_config(oct)) {
  1011. dev_err(&oct->pci_dev->dev,
  1012. "Queue reset aborted: SRIOV config failed\n");
  1013. return -1;
  1014. }
  1015. num_qs = oct->sriov_info.num_pf_rings;
  1016. }
  1017. }
  1018. if (oct->fn_list.setup_device_regs(oct)) {
  1019. dev_err(&oct->pci_dev->dev, "Failed to configure device registers\n");
  1020. return -1;
  1021. }
  1022. /* The following are needed in case of queue count re-configuration and
  1023. * not for descriptor count re-configuration.
  1024. */
  1025. if (queue_count_update) {
  1026. if (octeon_setup_instr_queues(oct))
  1027. return -1;
  1028. if (octeon_setup_output_queues(oct))
  1029. return -1;
  1030. /* Recreating mbox for PF that is SRIOV disabled */
  1031. if (OCTEON_CN23XX_PF(oct) && !oct->sriov_info.sriov_enabled) {
  1032. if (oct->fn_list.setup_mbox(oct)) {
  1033. dev_err(&oct->pci_dev->dev, "Mailbox setup failed\n");
  1034. return -1;
  1035. }
  1036. }
  1037. /* Deleting and recreating IRQs whether the interface is SRIOV
  1038. * enabled or disabled.
  1039. */
  1040. if (lio_irq_reallocate_irqs(oct, num_qs)) {
  1041. dev_err(&oct->pci_dev->dev, "IRQs could not be allocated\n");
  1042. return -1;
  1043. }
  1044. /* Enable the input and output queues for this Octeon device */
  1045. if (oct->fn_list.enable_io_queues(oct)) {
  1046. dev_err(&oct->pci_dev->dev, "Failed to enable input/output queues\n");
  1047. return -1;
  1048. }
  1049. for (i = 0; i < oct->num_oqs; i++)
  1050. writel(oct->droq[i]->max_count,
  1051. oct->droq[i]->pkts_credit_reg);
  1052. /* Informing firmware about the new queue count. It is required
  1053. * for firmware to allocate more number of queues than those at
  1054. * load time.
  1055. */
  1056. if (OCTEON_CN23XX_PF(oct) && !oct->sriov_info.sriov_enabled) {
  1057. if (lio_23xx_reconfigure_queue_count(lio))
  1058. return -1;
  1059. }
  1060. }
  1061. /* Once firmware is aware of the new value, queues can be recreated */
  1062. if (liquidio_setup_io_queues(oct, 0, num_qs, num_qs)) {
  1063. dev_err(&oct->pci_dev->dev, "I/O queues creation failed\n");
  1064. return -1;
  1065. }
  1066. if (queue_count_update) {
  1067. if (lio_setup_glists(oct, lio, num_qs)) {
  1068. dev_err(&oct->pci_dev->dev, "Gather list allocation failed\n");
  1069. return -1;
  1070. }
  1071. /* Send firmware the information about new number of queues
  1072. * if the interface is a VF or a PF that is SRIOV enabled.
  1073. */
  1074. if (oct->sriov_info.sriov_enabled || OCTEON_CN23XX_VF(oct))
  1075. if (lio_send_queue_count_update(netdev, num_qs))
  1076. return -1;
  1077. }
  1078. return 0;
  1079. }
  1080. static int lio_ethtool_set_ringparam(struct net_device *netdev,
  1081. struct ethtool_ringparam *ering)
  1082. {
  1083. u32 rx_count, tx_count, rx_count_old, tx_count_old;
  1084. struct lio *lio = GET_LIO(netdev);
  1085. struct octeon_device *oct = lio->oct_dev;
  1086. int stopped = 0;
  1087. if (!OCTEON_CN23XX_PF(oct) && !OCTEON_CN23XX_VF(oct))
  1088. return -EINVAL;
  1089. if (ering->rx_mini_pending || ering->rx_jumbo_pending)
  1090. return -EINVAL;
  1091. rx_count = clamp_t(u32, ering->rx_pending, CN23XX_MIN_OQ_DESCRIPTORS,
  1092. CN23XX_MAX_OQ_DESCRIPTORS);
  1093. tx_count = clamp_t(u32, ering->tx_pending, CN23XX_MIN_IQ_DESCRIPTORS,
  1094. CN23XX_MAX_IQ_DESCRIPTORS);
  1095. rx_count_old = oct->droq[0]->max_count;
  1096. tx_count_old = oct->instr_queue[0]->max_count;
  1097. if (rx_count == rx_count_old && tx_count == tx_count_old)
  1098. return 0;
  1099. ifstate_set(lio, LIO_IFSTATE_RESETTING);
  1100. if (netif_running(netdev)) {
  1101. netdev->netdev_ops->ndo_stop(netdev);
  1102. stopped = 1;
  1103. }
  1104. /* Change RX/TX DESCS count */
  1105. if (tx_count != tx_count_old)
  1106. CFG_SET_NUM_TX_DESCS_NIC_IF(octeon_get_conf(oct), lio->ifidx,
  1107. tx_count);
  1108. if (rx_count != rx_count_old)
  1109. CFG_SET_NUM_RX_DESCS_NIC_IF(octeon_get_conf(oct), lio->ifidx,
  1110. rx_count);
  1111. if (lio_reset_queues(netdev, oct->num_iqs))
  1112. goto err_lio_reset_queues;
  1113. if (stopped)
  1114. netdev->netdev_ops->ndo_open(netdev);
  1115. ifstate_reset(lio, LIO_IFSTATE_RESETTING);
  1116. return 0;
  1117. err_lio_reset_queues:
  1118. if (tx_count != tx_count_old)
  1119. CFG_SET_NUM_TX_DESCS_NIC_IF(octeon_get_conf(oct), lio->ifidx,
  1120. tx_count_old);
  1121. if (rx_count != rx_count_old)
  1122. CFG_SET_NUM_RX_DESCS_NIC_IF(octeon_get_conf(oct), lio->ifidx,
  1123. rx_count_old);
  1124. return -EINVAL;
  1125. }
  1126. static u32 lio_get_msglevel(struct net_device *netdev)
  1127. {
  1128. struct lio *lio = GET_LIO(netdev);
  1129. return lio->msg_enable;
  1130. }
  1131. static void lio_set_msglevel(struct net_device *netdev, u32 msglvl)
  1132. {
  1133. struct lio *lio = GET_LIO(netdev);
  1134. if ((msglvl ^ lio->msg_enable) & NETIF_MSG_HW) {
  1135. if (msglvl & NETIF_MSG_HW)
  1136. liquidio_set_feature(netdev,
  1137. OCTNET_CMD_VERBOSE_ENABLE, 0);
  1138. else
  1139. liquidio_set_feature(netdev,
  1140. OCTNET_CMD_VERBOSE_DISABLE, 0);
  1141. }
  1142. lio->msg_enable = msglvl;
  1143. }
  1144. static void lio_vf_set_msglevel(struct net_device *netdev, u32 msglvl)
  1145. {
  1146. struct lio *lio = GET_LIO(netdev);
  1147. lio->msg_enable = msglvl;
  1148. }
  1149. static void
  1150. lio_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
  1151. {
  1152. /* Notes: Not supporting any auto negotiation in these
  1153. * drivers. Just report pause frame support.
  1154. */
  1155. struct lio *lio = GET_LIO(netdev);
  1156. struct octeon_device *oct = lio->oct_dev;
  1157. pause->autoneg = 0;
  1158. pause->tx_pause = oct->tx_pause;
  1159. pause->rx_pause = oct->rx_pause;
  1160. }
  1161. static int
  1162. lio_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
  1163. {
  1164. /* Notes: Not supporting any auto negotiation in these
  1165. * drivers.
  1166. */
  1167. struct lio *lio = GET_LIO(netdev);
  1168. struct octeon_device *oct = lio->oct_dev;
  1169. struct octnic_ctrl_pkt nctrl;
  1170. struct oct_link_info *linfo = &lio->linfo;
  1171. int ret = 0;
  1172. if (oct->chip_id != OCTEON_CN23XX_PF_VID)
  1173. return -EINVAL;
  1174. if (linfo->link.s.duplex == 0) {
  1175. /*no flow control for half duplex*/
  1176. if (pause->rx_pause || pause->tx_pause)
  1177. return -EINVAL;
  1178. }
  1179. /*do not support autoneg of link flow control*/
  1180. if (pause->autoneg == AUTONEG_ENABLE)
  1181. return -EINVAL;
  1182. memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
  1183. nctrl.ncmd.u64 = 0;
  1184. nctrl.ncmd.s.cmd = OCTNET_CMD_SET_FLOW_CTL;
  1185. nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
  1186. nctrl.wait_time = 100;
  1187. nctrl.netpndev = (u64)netdev;
  1188. nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
  1189. if (pause->rx_pause) {
  1190. /*enable rx pause*/
  1191. nctrl.ncmd.s.param1 = 1;
  1192. } else {
  1193. /*disable rx pause*/
  1194. nctrl.ncmd.s.param1 = 0;
  1195. }
  1196. if (pause->tx_pause) {
  1197. /*enable tx pause*/
  1198. nctrl.ncmd.s.param2 = 1;
  1199. } else {
  1200. /*disable tx pause*/
  1201. nctrl.ncmd.s.param2 = 0;
  1202. }
  1203. ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
  1204. if (ret < 0) {
  1205. dev_err(&oct->pci_dev->dev, "Failed to set pause parameter\n");
  1206. return -EINVAL;
  1207. }
  1208. oct->rx_pause = pause->rx_pause;
  1209. oct->tx_pause = pause->tx_pause;
  1210. return 0;
  1211. }
  1212. static void
  1213. lio_get_ethtool_stats(struct net_device *netdev,
  1214. struct ethtool_stats *stats __attribute__((unused)),
  1215. u64 *data)
  1216. {
  1217. struct lio *lio = GET_LIO(netdev);
  1218. struct octeon_device *oct_dev = lio->oct_dev;
  1219. struct rtnl_link_stats64 lstats;
  1220. int i = 0, j;
  1221. if (ifstate_check(lio, LIO_IFSTATE_RESETTING))
  1222. return;
  1223. netdev->netdev_ops->ndo_get_stats64(netdev, &lstats);
  1224. /*sum of oct->droq[oq_no]->stats->rx_pkts_received */
  1225. data[i++] = lstats.rx_packets;
  1226. /*sum of oct->instr_queue[iq_no]->stats.tx_done */
  1227. data[i++] = lstats.tx_packets;
  1228. /*sum of oct->droq[oq_no]->stats->rx_bytes_received */
  1229. data[i++] = lstats.rx_bytes;
  1230. /*sum of oct->instr_queue[iq_no]->stats.tx_tot_bytes */
  1231. data[i++] = lstats.tx_bytes;
  1232. data[i++] = lstats.rx_errors +
  1233. oct_dev->link_stats.fromwire.fcs_err +
  1234. oct_dev->link_stats.fromwire.jabber_err +
  1235. oct_dev->link_stats.fromwire.l2_err +
  1236. oct_dev->link_stats.fromwire.frame_err;
  1237. data[i++] = lstats.tx_errors;
  1238. /*sum of oct->droq[oq_no]->stats->rx_dropped +
  1239. *oct->droq[oq_no]->stats->dropped_nodispatch +
  1240. *oct->droq[oq_no]->stats->dropped_toomany +
  1241. *oct->droq[oq_no]->stats->dropped_nomem
  1242. */
  1243. data[i++] = lstats.rx_dropped +
  1244. oct_dev->link_stats.fromwire.fifo_err +
  1245. oct_dev->link_stats.fromwire.dmac_drop +
  1246. oct_dev->link_stats.fromwire.red_drops +
  1247. oct_dev->link_stats.fromwire.fw_err_pko +
  1248. oct_dev->link_stats.fromwire.fw_err_link +
  1249. oct_dev->link_stats.fromwire.fw_err_drop;
  1250. /*sum of oct->instr_queue[iq_no]->stats.tx_dropped */
  1251. data[i++] = lstats.tx_dropped +
  1252. oct_dev->link_stats.fromhost.max_collision_fail +
  1253. oct_dev->link_stats.fromhost.max_deferral_fail +
  1254. oct_dev->link_stats.fromhost.total_collisions +
  1255. oct_dev->link_stats.fromhost.fw_err_pko +
  1256. oct_dev->link_stats.fromhost.fw_err_link +
  1257. oct_dev->link_stats.fromhost.fw_err_drop +
  1258. oct_dev->link_stats.fromhost.fw_err_pki;
  1259. /* firmware tx stats */
  1260. /*per_core_stats[cvmx_get_core_num()].link_stats[mdata->from_ifidx].
  1261. *fromhost.fw_total_sent
  1262. */
  1263. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_total_sent);
  1264. /*per_core_stats[i].link_stats[port].fromwire.fw_total_fwd */
  1265. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_total_fwd);
  1266. /*per_core_stats[j].link_stats[i].fromhost.fw_err_pko */
  1267. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_err_pko);
  1268. /*per_core_stats[j].link_stats[i].fromhost.fw_err_pki */
  1269. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_err_pki);
  1270. /*per_core_stats[j].link_stats[i].fromhost.fw_err_link */
  1271. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_err_link);
  1272. /*per_core_stats[cvmx_get_core_num()].link_stats[idx].fromhost.
  1273. *fw_err_drop
  1274. */
  1275. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_err_drop);
  1276. /*per_core_stats[cvmx_get_core_num()].link_stats[idx].fromhost.fw_tso */
  1277. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_tso);
  1278. /*per_core_stats[cvmx_get_core_num()].link_stats[idx].fromhost.
  1279. *fw_tso_fwd
  1280. */
  1281. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_tso_fwd);
  1282. /*per_core_stats[cvmx_get_core_num()].link_stats[idx].fromhost.
  1283. *fw_err_tso
  1284. */
  1285. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_err_tso);
  1286. /*per_core_stats[cvmx_get_core_num()].link_stats[idx].fromhost.
  1287. *fw_tx_vxlan
  1288. */
  1289. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fw_tx_vxlan);
  1290. /* Multicast packets sent by this port */
  1291. data[i++] = oct_dev->link_stats.fromhost.fw_total_mcast_sent;
  1292. data[i++] = oct_dev->link_stats.fromhost.fw_total_bcast_sent;
  1293. /* mac tx statistics */
  1294. /*CVMX_BGXX_CMRX_TX_STAT5 */
  1295. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.total_pkts_sent);
  1296. /*CVMX_BGXX_CMRX_TX_STAT4 */
  1297. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.total_bytes_sent);
  1298. /*CVMX_BGXX_CMRX_TX_STAT15 */
  1299. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.mcast_pkts_sent);
  1300. /*CVMX_BGXX_CMRX_TX_STAT14 */
  1301. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.bcast_pkts_sent);
  1302. /*CVMX_BGXX_CMRX_TX_STAT17 */
  1303. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.ctl_sent);
  1304. /*CVMX_BGXX_CMRX_TX_STAT0 */
  1305. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.total_collisions);
  1306. /*CVMX_BGXX_CMRX_TX_STAT3 */
  1307. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.one_collision_sent);
  1308. /*CVMX_BGXX_CMRX_TX_STAT2 */
  1309. data[i++] =
  1310. CVM_CAST64(oct_dev->link_stats.fromhost.multi_collision_sent);
  1311. /*CVMX_BGXX_CMRX_TX_STAT0 */
  1312. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.max_collision_fail);
  1313. /*CVMX_BGXX_CMRX_TX_STAT1 */
  1314. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.max_deferral_fail);
  1315. /*CVMX_BGXX_CMRX_TX_STAT16 */
  1316. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.fifo_err);
  1317. /*CVMX_BGXX_CMRX_TX_STAT6 */
  1318. data[i++] = CVM_CAST64(oct_dev->link_stats.fromhost.runts);
  1319. /* RX firmware stats */
  1320. /*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
  1321. *fw_total_rcvd
  1322. */
  1323. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_total_rcvd);
  1324. /*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
  1325. *fw_total_fwd
  1326. */
  1327. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_total_fwd);
  1328. /* Multicast packets received on this port */
  1329. data[i++] = oct_dev->link_stats.fromwire.fw_total_mcast;
  1330. data[i++] = oct_dev->link_stats.fromwire.fw_total_bcast;
  1331. /*per_core_stats[core_id].link_stats[ifidx].fromwire.jabber_err */
  1332. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.jabber_err);
  1333. /*per_core_stats[core_id].link_stats[ifidx].fromwire.l2_err */
  1334. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.l2_err);
  1335. /*per_core_stats[core_id].link_stats[ifidx].fromwire.frame_err */
  1336. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.frame_err);
  1337. /*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
  1338. *fw_err_pko
  1339. */
  1340. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_err_pko);
  1341. /*per_core_stats[j].link_stats[i].fromwire.fw_err_link */
  1342. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_err_link);
  1343. /*per_core_stats[cvmx_get_core_num()].link_stats[lro_ctx->ifidx].
  1344. *fromwire.fw_err_drop
  1345. */
  1346. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_err_drop);
  1347. /*per_core_stats[cvmx_get_core_num()].link_stats[lro_ctx->ifidx].
  1348. *fromwire.fw_rx_vxlan
  1349. */
  1350. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_rx_vxlan);
  1351. /*per_core_stats[cvmx_get_core_num()].link_stats[lro_ctx->ifidx].
  1352. *fromwire.fw_rx_vxlan_err
  1353. */
  1354. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_rx_vxlan_err);
  1355. /* LRO */
  1356. /*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
  1357. *fw_lro_pkts
  1358. */
  1359. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_pkts);
  1360. /*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
  1361. *fw_lro_octs
  1362. */
  1363. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_octs);
  1364. /*per_core_stats[j].link_stats[i].fromwire.fw_total_lro */
  1365. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_total_lro);
  1366. /*per_core_stats[j].link_stats[i].fromwire.fw_lro_aborts */
  1367. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_aborts);
  1368. /*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
  1369. *fw_lro_aborts_port
  1370. */
  1371. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_aborts_port);
  1372. /*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
  1373. *fw_lro_aborts_seq
  1374. */
  1375. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_aborts_seq);
  1376. /*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
  1377. *fw_lro_aborts_tsval
  1378. */
  1379. data[i++] =
  1380. CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_aborts_tsval);
  1381. /*per_core_stats[cvmx_get_core_num()].link_stats[ifidx].fromwire.
  1382. *fw_lro_aborts_timer
  1383. */
  1384. /* intrmod: packet forward rate */
  1385. data[i++] =
  1386. CVM_CAST64(oct_dev->link_stats.fromwire.fw_lro_aborts_timer);
  1387. /*per_core_stats[j].link_stats[i].fromwire.fw_lro_aborts */
  1388. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fwd_rate);
  1389. /* mac: link-level stats */
  1390. /*CVMX_BGXX_CMRX_RX_STAT0 */
  1391. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.total_rcvd);
  1392. /*CVMX_BGXX_CMRX_RX_STAT1 */
  1393. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.bytes_rcvd);
  1394. /*CVMX_PKI_STATX_STAT5 */
  1395. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.total_bcst);
  1396. /*CVMX_PKI_STATX_STAT5 */
  1397. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.total_mcst);
  1398. /*wqe->word2.err_code or wqe->word2.err_level */
  1399. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.runts);
  1400. /*CVMX_BGXX_CMRX_RX_STAT2 */
  1401. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.ctl_rcvd);
  1402. /*CVMX_BGXX_CMRX_RX_STAT6 */
  1403. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fifo_err);
  1404. /*CVMX_BGXX_CMRX_RX_STAT4 */
  1405. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.dmac_drop);
  1406. /*wqe->word2.err_code or wqe->word2.err_level */
  1407. data[i++] = CVM_CAST64(oct_dev->link_stats.fromwire.fcs_err);
  1408. /*lio->link_changes*/
  1409. data[i++] = CVM_CAST64(lio->link_changes);
  1410. for (j = 0; j < MAX_OCTEON_INSTR_QUEUES(oct_dev); j++) {
  1411. if (!(oct_dev->io_qmask.iq & BIT_ULL(j)))
  1412. continue;
  1413. /*packets to network port*/
  1414. /*# of packets tx to network */
  1415. data[i++] = CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_done);
  1416. /*# of bytes tx to network */
  1417. data[i++] =
  1418. CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_tot_bytes);
  1419. /*# of packets dropped */
  1420. data[i++] =
  1421. CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_dropped);
  1422. /*# of tx fails due to queue full */
  1423. data[i++] =
  1424. CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_iq_busy);
  1425. /*XXX gather entries sent */
  1426. data[i++] =
  1427. CVM_CAST64(oct_dev->instr_queue[j]->stats.sgentry_sent);
  1428. /*instruction to firmware: data and control */
  1429. /*# of instructions to the queue */
  1430. data[i++] =
  1431. CVM_CAST64(oct_dev->instr_queue[j]->stats.instr_posted);
  1432. /*# of instructions processed */
  1433. data[i++] = CVM_CAST64(
  1434. oct_dev->instr_queue[j]->stats.instr_processed);
  1435. /*# of instructions could not be processed */
  1436. data[i++] = CVM_CAST64(
  1437. oct_dev->instr_queue[j]->stats.instr_dropped);
  1438. /*bytes sent through the queue */
  1439. data[i++] =
  1440. CVM_CAST64(oct_dev->instr_queue[j]->stats.bytes_sent);
  1441. /*tso request*/
  1442. data[i++] = CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_gso);
  1443. /*vxlan request*/
  1444. data[i++] = CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_vxlan);
  1445. /*txq restart*/
  1446. data[i++] =
  1447. CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_restart);
  1448. }
  1449. /* RX */
  1450. for (j = 0; j < MAX_OCTEON_OUTPUT_QUEUES(oct_dev); j++) {
  1451. if (!(oct_dev->io_qmask.oq & BIT_ULL(j)))
  1452. continue;
  1453. /*packets send to TCP/IP network stack */
  1454. /*# of packets to network stack */
  1455. data[i++] =
  1456. CVM_CAST64(oct_dev->droq[j]->stats.rx_pkts_received);
  1457. /*# of bytes to network stack */
  1458. data[i++] =
  1459. CVM_CAST64(oct_dev->droq[j]->stats.rx_bytes_received);
  1460. /*# of packets dropped */
  1461. data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.dropped_nomem +
  1462. oct_dev->droq[j]->stats.dropped_toomany +
  1463. oct_dev->droq[j]->stats.rx_dropped);
  1464. data[i++] =
  1465. CVM_CAST64(oct_dev->droq[j]->stats.dropped_nomem);
  1466. data[i++] =
  1467. CVM_CAST64(oct_dev->droq[j]->stats.dropped_toomany);
  1468. data[i++] =
  1469. CVM_CAST64(oct_dev->droq[j]->stats.rx_dropped);
  1470. /*control and data path*/
  1471. data[i++] =
  1472. CVM_CAST64(oct_dev->droq[j]->stats.pkts_received);
  1473. data[i++] =
  1474. CVM_CAST64(oct_dev->droq[j]->stats.bytes_received);
  1475. data[i++] =
  1476. CVM_CAST64(oct_dev->droq[j]->stats.dropped_nodispatch);
  1477. data[i++] =
  1478. CVM_CAST64(oct_dev->droq[j]->stats.rx_vxlan);
  1479. data[i++] =
  1480. CVM_CAST64(oct_dev->droq[j]->stats.rx_alloc_failure);
  1481. }
  1482. }
  1483. static void lio_vf_get_ethtool_stats(struct net_device *netdev,
  1484. struct ethtool_stats *stats
  1485. __attribute__((unused)),
  1486. u64 *data)
  1487. {
  1488. struct rtnl_link_stats64 lstats;
  1489. struct lio *lio = GET_LIO(netdev);
  1490. struct octeon_device *oct_dev = lio->oct_dev;
  1491. int i = 0, j, vj;
  1492. if (ifstate_check(lio, LIO_IFSTATE_RESETTING))
  1493. return;
  1494. netdev->netdev_ops->ndo_get_stats64(netdev, &lstats);
  1495. /* sum of oct->droq[oq_no]->stats->rx_pkts_received */
  1496. data[i++] = lstats.rx_packets;
  1497. /* sum of oct->instr_queue[iq_no]->stats.tx_done */
  1498. data[i++] = lstats.tx_packets;
  1499. /* sum of oct->droq[oq_no]->stats->rx_bytes_received */
  1500. data[i++] = lstats.rx_bytes;
  1501. /* sum of oct->instr_queue[iq_no]->stats.tx_tot_bytes */
  1502. data[i++] = lstats.tx_bytes;
  1503. data[i++] = lstats.rx_errors;
  1504. data[i++] = lstats.tx_errors;
  1505. /* sum of oct->droq[oq_no]->stats->rx_dropped +
  1506. * oct->droq[oq_no]->stats->dropped_nodispatch +
  1507. * oct->droq[oq_no]->stats->dropped_toomany +
  1508. * oct->droq[oq_no]->stats->dropped_nomem
  1509. */
  1510. data[i++] = lstats.rx_dropped;
  1511. /* sum of oct->instr_queue[iq_no]->stats.tx_dropped */
  1512. data[i++] = lstats.tx_dropped;
  1513. data[i++] = oct_dev->link_stats.fromwire.fw_total_mcast;
  1514. data[i++] = oct_dev->link_stats.fromhost.fw_total_mcast_sent;
  1515. data[i++] = oct_dev->link_stats.fromwire.fw_total_bcast;
  1516. data[i++] = oct_dev->link_stats.fromhost.fw_total_bcast_sent;
  1517. /* lio->link_changes */
  1518. data[i++] = CVM_CAST64(lio->link_changes);
  1519. for (vj = 0; vj < oct_dev->num_iqs; vj++) {
  1520. j = lio->linfo.txpciq[vj].s.q_no;
  1521. /* packets to network port */
  1522. /* # of packets tx to network */
  1523. data[i++] = CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_done);
  1524. /* # of bytes tx to network */
  1525. data[i++] = CVM_CAST64(
  1526. oct_dev->instr_queue[j]->stats.tx_tot_bytes);
  1527. /* # of packets dropped */
  1528. data[i++] = CVM_CAST64(
  1529. oct_dev->instr_queue[j]->stats.tx_dropped);
  1530. /* # of tx fails due to queue full */
  1531. data[i++] = CVM_CAST64(
  1532. oct_dev->instr_queue[j]->stats.tx_iq_busy);
  1533. /* XXX gather entries sent */
  1534. data[i++] = CVM_CAST64(
  1535. oct_dev->instr_queue[j]->stats.sgentry_sent);
  1536. /* instruction to firmware: data and control */
  1537. /* # of instructions to the queue */
  1538. data[i++] = CVM_CAST64(
  1539. oct_dev->instr_queue[j]->stats.instr_posted);
  1540. /* # of instructions processed */
  1541. data[i++] =
  1542. CVM_CAST64(oct_dev->instr_queue[j]->stats.instr_processed);
  1543. /* # of instructions could not be processed */
  1544. data[i++] =
  1545. CVM_CAST64(oct_dev->instr_queue[j]->stats.instr_dropped);
  1546. /* bytes sent through the queue */
  1547. data[i++] = CVM_CAST64(
  1548. oct_dev->instr_queue[j]->stats.bytes_sent);
  1549. /* tso request */
  1550. data[i++] = CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_gso);
  1551. /* vxlan request */
  1552. data[i++] = CVM_CAST64(oct_dev->instr_queue[j]->stats.tx_vxlan);
  1553. /* txq restart */
  1554. data[i++] = CVM_CAST64(
  1555. oct_dev->instr_queue[j]->stats.tx_restart);
  1556. }
  1557. /* RX */
  1558. for (vj = 0; vj < oct_dev->num_oqs; vj++) {
  1559. j = lio->linfo.rxpciq[vj].s.q_no;
  1560. /* packets send to TCP/IP network stack */
  1561. /* # of packets to network stack */
  1562. data[i++] = CVM_CAST64(
  1563. oct_dev->droq[j]->stats.rx_pkts_received);
  1564. /* # of bytes to network stack */
  1565. data[i++] = CVM_CAST64(
  1566. oct_dev->droq[j]->stats.rx_bytes_received);
  1567. data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.dropped_nomem +
  1568. oct_dev->droq[j]->stats.dropped_toomany +
  1569. oct_dev->droq[j]->stats.rx_dropped);
  1570. data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.dropped_nomem);
  1571. data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.dropped_toomany);
  1572. data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.rx_dropped);
  1573. /* control and data path */
  1574. data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.pkts_received);
  1575. data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.bytes_received);
  1576. data[i++] =
  1577. CVM_CAST64(oct_dev->droq[j]->stats.dropped_nodispatch);
  1578. data[i++] = CVM_CAST64(oct_dev->droq[j]->stats.rx_vxlan);
  1579. data[i++] =
  1580. CVM_CAST64(oct_dev->droq[j]->stats.rx_alloc_failure);
  1581. }
  1582. }
  1583. static void lio_get_priv_flags_strings(struct lio *lio, u8 *data)
  1584. {
  1585. struct octeon_device *oct_dev = lio->oct_dev;
  1586. int i;
  1587. switch (oct_dev->chip_id) {
  1588. case OCTEON_CN23XX_PF_VID:
  1589. case OCTEON_CN23XX_VF_VID:
  1590. for (i = 0; i < ARRAY_SIZE(oct_priv_flags_strings); i++) {
  1591. sprintf(data, "%s", oct_priv_flags_strings[i]);
  1592. data += ETH_GSTRING_LEN;
  1593. }
  1594. break;
  1595. case OCTEON_CN68XX:
  1596. case OCTEON_CN66XX:
  1597. break;
  1598. default:
  1599. netif_info(lio, drv, lio->netdev, "Unknown Chip !!\n");
  1600. break;
  1601. }
  1602. }
  1603. static void lio_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
  1604. {
  1605. struct lio *lio = GET_LIO(netdev);
  1606. struct octeon_device *oct_dev = lio->oct_dev;
  1607. int num_iq_stats, num_oq_stats, i, j;
  1608. int num_stats;
  1609. switch (stringset) {
  1610. case ETH_SS_STATS:
  1611. num_stats = ARRAY_SIZE(oct_stats_strings);
  1612. for (j = 0; j < num_stats; j++) {
  1613. sprintf(data, "%s", oct_stats_strings[j]);
  1614. data += ETH_GSTRING_LEN;
  1615. }
  1616. num_iq_stats = ARRAY_SIZE(oct_iq_stats_strings);
  1617. for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct_dev); i++) {
  1618. if (!(oct_dev->io_qmask.iq & BIT_ULL(i)))
  1619. continue;
  1620. for (j = 0; j < num_iq_stats; j++) {
  1621. sprintf(data, "tx-%d-%s", i,
  1622. oct_iq_stats_strings[j]);
  1623. data += ETH_GSTRING_LEN;
  1624. }
  1625. }
  1626. num_oq_stats = ARRAY_SIZE(oct_droq_stats_strings);
  1627. for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct_dev); i++) {
  1628. if (!(oct_dev->io_qmask.oq & BIT_ULL(i)))
  1629. continue;
  1630. for (j = 0; j < num_oq_stats; j++) {
  1631. sprintf(data, "rx-%d-%s", i,
  1632. oct_droq_stats_strings[j]);
  1633. data += ETH_GSTRING_LEN;
  1634. }
  1635. }
  1636. break;
  1637. case ETH_SS_PRIV_FLAGS:
  1638. lio_get_priv_flags_strings(lio, data);
  1639. break;
  1640. default:
  1641. netif_info(lio, drv, lio->netdev, "Unknown Stringset !!\n");
  1642. break;
  1643. }
  1644. }
  1645. static void lio_vf_get_strings(struct net_device *netdev, u32 stringset,
  1646. u8 *data)
  1647. {
  1648. int num_iq_stats, num_oq_stats, i, j;
  1649. struct lio *lio = GET_LIO(netdev);
  1650. struct octeon_device *oct_dev = lio->oct_dev;
  1651. int num_stats;
  1652. switch (stringset) {
  1653. case ETH_SS_STATS:
  1654. num_stats = ARRAY_SIZE(oct_vf_stats_strings);
  1655. for (j = 0; j < num_stats; j++) {
  1656. sprintf(data, "%s", oct_vf_stats_strings[j]);
  1657. data += ETH_GSTRING_LEN;
  1658. }
  1659. num_iq_stats = ARRAY_SIZE(oct_iq_stats_strings);
  1660. for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct_dev); i++) {
  1661. if (!(oct_dev->io_qmask.iq & BIT_ULL(i)))
  1662. continue;
  1663. for (j = 0; j < num_iq_stats; j++) {
  1664. sprintf(data, "tx-%d-%s", i,
  1665. oct_iq_stats_strings[j]);
  1666. data += ETH_GSTRING_LEN;
  1667. }
  1668. }
  1669. num_oq_stats = ARRAY_SIZE(oct_droq_stats_strings);
  1670. for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct_dev); i++) {
  1671. if (!(oct_dev->io_qmask.oq & BIT_ULL(i)))
  1672. continue;
  1673. for (j = 0; j < num_oq_stats; j++) {
  1674. sprintf(data, "rx-%d-%s", i,
  1675. oct_droq_stats_strings[j]);
  1676. data += ETH_GSTRING_LEN;
  1677. }
  1678. }
  1679. break;
  1680. case ETH_SS_PRIV_FLAGS:
  1681. lio_get_priv_flags_strings(lio, data);
  1682. break;
  1683. default:
  1684. netif_info(lio, drv, lio->netdev, "Unknown Stringset !!\n");
  1685. break;
  1686. }
  1687. }
  1688. static int lio_get_priv_flags_ss_count(struct lio *lio)
  1689. {
  1690. struct octeon_device *oct_dev = lio->oct_dev;
  1691. switch (oct_dev->chip_id) {
  1692. case OCTEON_CN23XX_PF_VID:
  1693. case OCTEON_CN23XX_VF_VID:
  1694. return ARRAY_SIZE(oct_priv_flags_strings);
  1695. case OCTEON_CN68XX:
  1696. case OCTEON_CN66XX:
  1697. return -EOPNOTSUPP;
  1698. default:
  1699. netif_info(lio, drv, lio->netdev, "Unknown Chip !!\n");
  1700. return -EOPNOTSUPP;
  1701. }
  1702. }
  1703. static int lio_get_sset_count(struct net_device *netdev, int sset)
  1704. {
  1705. struct lio *lio = GET_LIO(netdev);
  1706. struct octeon_device *oct_dev = lio->oct_dev;
  1707. switch (sset) {
  1708. case ETH_SS_STATS:
  1709. return (ARRAY_SIZE(oct_stats_strings) +
  1710. ARRAY_SIZE(oct_iq_stats_strings) * oct_dev->num_iqs +
  1711. ARRAY_SIZE(oct_droq_stats_strings) * oct_dev->num_oqs);
  1712. case ETH_SS_PRIV_FLAGS:
  1713. return lio_get_priv_flags_ss_count(lio);
  1714. default:
  1715. return -EOPNOTSUPP;
  1716. }
  1717. }
  1718. static int lio_vf_get_sset_count(struct net_device *netdev, int sset)
  1719. {
  1720. struct lio *lio = GET_LIO(netdev);
  1721. struct octeon_device *oct_dev = lio->oct_dev;
  1722. switch (sset) {
  1723. case ETH_SS_STATS:
  1724. return (ARRAY_SIZE(oct_vf_stats_strings) +
  1725. ARRAY_SIZE(oct_iq_stats_strings) * oct_dev->num_iqs +
  1726. ARRAY_SIZE(oct_droq_stats_strings) * oct_dev->num_oqs);
  1727. case ETH_SS_PRIV_FLAGS:
  1728. return lio_get_priv_flags_ss_count(lio);
  1729. default:
  1730. return -EOPNOTSUPP;
  1731. }
  1732. }
  1733. /* Callback function for intrmod */
  1734. static void octnet_intrmod_callback(struct octeon_device *oct_dev,
  1735. u32 status,
  1736. void *ptr)
  1737. {
  1738. struct octeon_soft_command *sc = (struct octeon_soft_command *)ptr;
  1739. struct oct_intrmod_context *ctx;
  1740. ctx = (struct oct_intrmod_context *)sc->ctxptr;
  1741. ctx->status = status;
  1742. WRITE_ONCE(ctx->cond, 1);
  1743. /* This barrier is required to be sure that the response has been
  1744. * written fully before waking up the handler
  1745. */
  1746. wmb();
  1747. wake_up_interruptible(&ctx->wc);
  1748. }
  1749. /* get interrupt moderation parameters */
  1750. static int octnet_get_intrmod_cfg(struct lio *lio,
  1751. struct oct_intrmod_cfg *intr_cfg)
  1752. {
  1753. struct octeon_soft_command *sc;
  1754. struct oct_intrmod_context *ctx;
  1755. struct oct_intrmod_resp *resp;
  1756. int retval;
  1757. struct octeon_device *oct_dev = lio->oct_dev;
  1758. /* Alloc soft command */
  1759. sc = (struct octeon_soft_command *)
  1760. octeon_alloc_soft_command(oct_dev,
  1761. 0,
  1762. sizeof(struct oct_intrmod_resp),
  1763. sizeof(struct oct_intrmod_context));
  1764. if (!sc)
  1765. return -ENOMEM;
  1766. resp = (struct oct_intrmod_resp *)sc->virtrptr;
  1767. memset(resp, 0, sizeof(struct oct_intrmod_resp));
  1768. ctx = (struct oct_intrmod_context *)sc->ctxptr;
  1769. memset(ctx, 0, sizeof(struct oct_intrmod_context));
  1770. WRITE_ONCE(ctx->cond, 0);
  1771. ctx->octeon_id = lio_get_device_id(oct_dev);
  1772. init_waitqueue_head(&ctx->wc);
  1773. sc->iq_no = lio->linfo.txpciq[0].s.q_no;
  1774. octeon_prepare_soft_command(oct_dev, sc, OPCODE_NIC,
  1775. OPCODE_NIC_INTRMOD_PARAMS, 0, 0, 0);
  1776. sc->callback = octnet_intrmod_callback;
  1777. sc->callback_arg = sc;
  1778. sc->wait_time = 1000;
  1779. retval = octeon_send_soft_command(oct_dev, sc);
  1780. if (retval == IQ_SEND_FAILED) {
  1781. octeon_free_soft_command(oct_dev, sc);
  1782. return -EINVAL;
  1783. }
  1784. /* Sleep on a wait queue till the cond flag indicates that the
  1785. * response arrived or timed-out.
  1786. */
  1787. if (sleep_cond(&ctx->wc, &ctx->cond) == -EINTR) {
  1788. dev_err(&oct_dev->pci_dev->dev, "Wait interrupted\n");
  1789. goto intrmod_info_wait_intr;
  1790. }
  1791. retval = ctx->status || resp->status;
  1792. if (retval) {
  1793. dev_err(&oct_dev->pci_dev->dev,
  1794. "Get interrupt moderation parameters failed\n");
  1795. goto intrmod_info_wait_fail;
  1796. }
  1797. octeon_swap_8B_data((u64 *)&resp->intrmod,
  1798. (sizeof(struct oct_intrmod_cfg)) / 8);
  1799. memcpy(intr_cfg, &resp->intrmod, sizeof(struct oct_intrmod_cfg));
  1800. octeon_free_soft_command(oct_dev, sc);
  1801. return 0;
  1802. intrmod_info_wait_fail:
  1803. octeon_free_soft_command(oct_dev, sc);
  1804. intrmod_info_wait_intr:
  1805. return -ENODEV;
  1806. }
  1807. /* Configure interrupt moderation parameters */
  1808. static int octnet_set_intrmod_cfg(struct lio *lio,
  1809. struct oct_intrmod_cfg *intr_cfg)
  1810. {
  1811. struct octeon_soft_command *sc;
  1812. struct oct_intrmod_context *ctx;
  1813. struct oct_intrmod_cfg *cfg;
  1814. int retval;
  1815. struct octeon_device *oct_dev = lio->oct_dev;
  1816. /* Alloc soft command */
  1817. sc = (struct octeon_soft_command *)
  1818. octeon_alloc_soft_command(oct_dev,
  1819. sizeof(struct oct_intrmod_cfg),
  1820. 0,
  1821. sizeof(struct oct_intrmod_context));
  1822. if (!sc)
  1823. return -ENOMEM;
  1824. ctx = (struct oct_intrmod_context *)sc->ctxptr;
  1825. WRITE_ONCE(ctx->cond, 0);
  1826. ctx->octeon_id = lio_get_device_id(oct_dev);
  1827. init_waitqueue_head(&ctx->wc);
  1828. cfg = (struct oct_intrmod_cfg *)sc->virtdptr;
  1829. memcpy(cfg, intr_cfg, sizeof(struct oct_intrmod_cfg));
  1830. octeon_swap_8B_data((u64 *)cfg, (sizeof(struct oct_intrmod_cfg)) / 8);
  1831. sc->iq_no = lio->linfo.txpciq[0].s.q_no;
  1832. octeon_prepare_soft_command(oct_dev, sc, OPCODE_NIC,
  1833. OPCODE_NIC_INTRMOD_CFG, 0, 0, 0);
  1834. sc->callback = octnet_intrmod_callback;
  1835. sc->callback_arg = sc;
  1836. sc->wait_time = 1000;
  1837. retval = octeon_send_soft_command(oct_dev, sc);
  1838. if (retval == IQ_SEND_FAILED) {
  1839. octeon_free_soft_command(oct_dev, sc);
  1840. return -EINVAL;
  1841. }
  1842. /* Sleep on a wait queue till the cond flag indicates that the
  1843. * response arrived or timed-out.
  1844. */
  1845. if (sleep_cond(&ctx->wc, &ctx->cond) != -EINTR) {
  1846. retval = ctx->status;
  1847. if (retval)
  1848. dev_err(&oct_dev->pci_dev->dev,
  1849. "intrmod config failed. Status: %llx\n",
  1850. CVM_CAST64(retval));
  1851. else
  1852. dev_info(&oct_dev->pci_dev->dev,
  1853. "Rx-Adaptive Interrupt moderation %s\n",
  1854. (intr_cfg->rx_enable) ?
  1855. "enabled" : "disabled");
  1856. octeon_free_soft_command(oct_dev, sc);
  1857. return ((retval) ? -ENODEV : 0);
  1858. }
  1859. dev_err(&oct_dev->pci_dev->dev, "iq/oq config failed\n");
  1860. return -EINTR;
  1861. }
  1862. static int lio_get_intr_coalesce(struct net_device *netdev,
  1863. struct ethtool_coalesce *intr_coal)
  1864. {
  1865. struct lio *lio = GET_LIO(netdev);
  1866. struct octeon_device *oct = lio->oct_dev;
  1867. struct octeon_instr_queue *iq;
  1868. struct oct_intrmod_cfg intrmod_cfg;
  1869. if (octnet_get_intrmod_cfg(lio, &intrmod_cfg))
  1870. return -ENODEV;
  1871. switch (oct->chip_id) {
  1872. case OCTEON_CN23XX_PF_VID:
  1873. case OCTEON_CN23XX_VF_VID: {
  1874. if (!intrmod_cfg.rx_enable) {
  1875. intr_coal->rx_coalesce_usecs = oct->rx_coalesce_usecs;
  1876. intr_coal->rx_max_coalesced_frames =
  1877. oct->rx_max_coalesced_frames;
  1878. }
  1879. if (!intrmod_cfg.tx_enable)
  1880. intr_coal->tx_max_coalesced_frames =
  1881. oct->tx_max_coalesced_frames;
  1882. break;
  1883. }
  1884. case OCTEON_CN68XX:
  1885. case OCTEON_CN66XX: {
  1886. struct octeon_cn6xxx *cn6xxx =
  1887. (struct octeon_cn6xxx *)oct->chip;
  1888. if (!intrmod_cfg.rx_enable) {
  1889. intr_coal->rx_coalesce_usecs =
  1890. CFG_GET_OQ_INTR_TIME(cn6xxx->conf);
  1891. intr_coal->rx_max_coalesced_frames =
  1892. CFG_GET_OQ_INTR_PKT(cn6xxx->conf);
  1893. }
  1894. iq = oct->instr_queue[lio->linfo.txpciq[0].s.q_no];
  1895. intr_coal->tx_max_coalesced_frames = iq->fill_threshold;
  1896. break;
  1897. }
  1898. default:
  1899. netif_info(lio, drv, lio->netdev, "Unknown Chip !!\n");
  1900. return -EINVAL;
  1901. }
  1902. if (intrmod_cfg.rx_enable) {
  1903. intr_coal->use_adaptive_rx_coalesce =
  1904. intrmod_cfg.rx_enable;
  1905. intr_coal->rate_sample_interval =
  1906. intrmod_cfg.check_intrvl;
  1907. intr_coal->pkt_rate_high =
  1908. intrmod_cfg.maxpkt_ratethr;
  1909. intr_coal->pkt_rate_low =
  1910. intrmod_cfg.minpkt_ratethr;
  1911. intr_coal->rx_max_coalesced_frames_high =
  1912. intrmod_cfg.rx_maxcnt_trigger;
  1913. intr_coal->rx_coalesce_usecs_high =
  1914. intrmod_cfg.rx_maxtmr_trigger;
  1915. intr_coal->rx_coalesce_usecs_low =
  1916. intrmod_cfg.rx_mintmr_trigger;
  1917. intr_coal->rx_max_coalesced_frames_low =
  1918. intrmod_cfg.rx_mincnt_trigger;
  1919. }
  1920. if ((OCTEON_CN23XX_PF(oct) || OCTEON_CN23XX_VF(oct)) &&
  1921. (intrmod_cfg.tx_enable)) {
  1922. intr_coal->use_adaptive_tx_coalesce =
  1923. intrmod_cfg.tx_enable;
  1924. intr_coal->tx_max_coalesced_frames_high =
  1925. intrmod_cfg.tx_maxcnt_trigger;
  1926. intr_coal->tx_max_coalesced_frames_low =
  1927. intrmod_cfg.tx_mincnt_trigger;
  1928. }
  1929. return 0;
  1930. }
  1931. /* Enable/Disable auto interrupt Moderation */
  1932. static int oct_cfg_adaptive_intr(struct lio *lio,
  1933. struct oct_intrmod_cfg *intrmod_cfg,
  1934. struct ethtool_coalesce *intr_coal)
  1935. {
  1936. int ret = 0;
  1937. if (intrmod_cfg->rx_enable || intrmod_cfg->tx_enable) {
  1938. intrmod_cfg->check_intrvl = intr_coal->rate_sample_interval;
  1939. intrmod_cfg->maxpkt_ratethr = intr_coal->pkt_rate_high;
  1940. intrmod_cfg->minpkt_ratethr = intr_coal->pkt_rate_low;
  1941. }
  1942. if (intrmod_cfg->rx_enable) {
  1943. intrmod_cfg->rx_maxcnt_trigger =
  1944. intr_coal->rx_max_coalesced_frames_high;
  1945. intrmod_cfg->rx_maxtmr_trigger =
  1946. intr_coal->rx_coalesce_usecs_high;
  1947. intrmod_cfg->rx_mintmr_trigger =
  1948. intr_coal->rx_coalesce_usecs_low;
  1949. intrmod_cfg->rx_mincnt_trigger =
  1950. intr_coal->rx_max_coalesced_frames_low;
  1951. }
  1952. if (intrmod_cfg->tx_enable) {
  1953. intrmod_cfg->tx_maxcnt_trigger =
  1954. intr_coal->tx_max_coalesced_frames_high;
  1955. intrmod_cfg->tx_mincnt_trigger =
  1956. intr_coal->tx_max_coalesced_frames_low;
  1957. }
  1958. ret = octnet_set_intrmod_cfg(lio, intrmod_cfg);
  1959. return ret;
  1960. }
  1961. static int
  1962. oct_cfg_rx_intrcnt(struct lio *lio,
  1963. struct oct_intrmod_cfg *intrmod,
  1964. struct ethtool_coalesce *intr_coal)
  1965. {
  1966. struct octeon_device *oct = lio->oct_dev;
  1967. u32 rx_max_coalesced_frames;
  1968. /* Config Cnt based interrupt values */
  1969. switch (oct->chip_id) {
  1970. case OCTEON_CN68XX:
  1971. case OCTEON_CN66XX: {
  1972. struct octeon_cn6xxx *cn6xxx =
  1973. (struct octeon_cn6xxx *)oct->chip;
  1974. if (!intr_coal->rx_max_coalesced_frames)
  1975. rx_max_coalesced_frames = CN6XXX_OQ_INTR_PKT;
  1976. else
  1977. rx_max_coalesced_frames =
  1978. intr_coal->rx_max_coalesced_frames;
  1979. octeon_write_csr(oct, CN6XXX_SLI_OQ_INT_LEVEL_PKTS,
  1980. rx_max_coalesced_frames);
  1981. CFG_SET_OQ_INTR_PKT(cn6xxx->conf, rx_max_coalesced_frames);
  1982. break;
  1983. }
  1984. case OCTEON_CN23XX_PF_VID: {
  1985. int q_no;
  1986. if (!intr_coal->rx_max_coalesced_frames)
  1987. rx_max_coalesced_frames = intrmod->rx_frames;
  1988. else
  1989. rx_max_coalesced_frames =
  1990. intr_coal->rx_max_coalesced_frames;
  1991. for (q_no = 0; q_no < oct->num_oqs; q_no++) {
  1992. q_no += oct->sriov_info.pf_srn;
  1993. octeon_write_csr64(
  1994. oct, CN23XX_SLI_OQ_PKT_INT_LEVELS(q_no),
  1995. (octeon_read_csr64(
  1996. oct, CN23XX_SLI_OQ_PKT_INT_LEVELS(q_no)) &
  1997. (0x3fffff00000000UL)) |
  1998. (rx_max_coalesced_frames - 1));
  1999. /*consider setting resend bit*/
  2000. }
  2001. intrmod->rx_frames = rx_max_coalesced_frames;
  2002. oct->rx_max_coalesced_frames = rx_max_coalesced_frames;
  2003. break;
  2004. }
  2005. case OCTEON_CN23XX_VF_VID: {
  2006. int q_no;
  2007. if (!intr_coal->rx_max_coalesced_frames)
  2008. rx_max_coalesced_frames = intrmod->rx_frames;
  2009. else
  2010. rx_max_coalesced_frames =
  2011. intr_coal->rx_max_coalesced_frames;
  2012. for (q_no = 0; q_no < oct->num_oqs; q_no++) {
  2013. octeon_write_csr64(
  2014. oct, CN23XX_VF_SLI_OQ_PKT_INT_LEVELS(q_no),
  2015. (octeon_read_csr64(
  2016. oct, CN23XX_VF_SLI_OQ_PKT_INT_LEVELS(q_no)) &
  2017. (0x3fffff00000000UL)) |
  2018. (rx_max_coalesced_frames - 1));
  2019. /*consider writing to resend bit here*/
  2020. }
  2021. intrmod->rx_frames = rx_max_coalesced_frames;
  2022. oct->rx_max_coalesced_frames = rx_max_coalesced_frames;
  2023. break;
  2024. }
  2025. default:
  2026. return -EINVAL;
  2027. }
  2028. return 0;
  2029. }
  2030. static int oct_cfg_rx_intrtime(struct lio *lio,
  2031. struct oct_intrmod_cfg *intrmod,
  2032. struct ethtool_coalesce *intr_coal)
  2033. {
  2034. struct octeon_device *oct = lio->oct_dev;
  2035. u32 time_threshold, rx_coalesce_usecs;
  2036. /* Config Time based interrupt values */
  2037. switch (oct->chip_id) {
  2038. case OCTEON_CN68XX:
  2039. case OCTEON_CN66XX: {
  2040. struct octeon_cn6xxx *cn6xxx =
  2041. (struct octeon_cn6xxx *)oct->chip;
  2042. if (!intr_coal->rx_coalesce_usecs)
  2043. rx_coalesce_usecs = CN6XXX_OQ_INTR_TIME;
  2044. else
  2045. rx_coalesce_usecs = intr_coal->rx_coalesce_usecs;
  2046. time_threshold = lio_cn6xxx_get_oq_ticks(oct,
  2047. rx_coalesce_usecs);
  2048. octeon_write_csr(oct,
  2049. CN6XXX_SLI_OQ_INT_LEVEL_TIME,
  2050. time_threshold);
  2051. CFG_SET_OQ_INTR_TIME(cn6xxx->conf, rx_coalesce_usecs);
  2052. break;
  2053. }
  2054. case OCTEON_CN23XX_PF_VID: {
  2055. u64 time_threshold;
  2056. int q_no;
  2057. if (!intr_coal->rx_coalesce_usecs)
  2058. rx_coalesce_usecs = intrmod->rx_usecs;
  2059. else
  2060. rx_coalesce_usecs = intr_coal->rx_coalesce_usecs;
  2061. time_threshold =
  2062. cn23xx_pf_get_oq_ticks(oct, (u32)rx_coalesce_usecs);
  2063. for (q_no = 0; q_no < oct->num_oqs; q_no++) {
  2064. q_no += oct->sriov_info.pf_srn;
  2065. octeon_write_csr64(oct,
  2066. CN23XX_SLI_OQ_PKT_INT_LEVELS(q_no),
  2067. (intrmod->rx_frames |
  2068. ((u64)time_threshold << 32)));
  2069. /*consider writing to resend bit here*/
  2070. }
  2071. intrmod->rx_usecs = rx_coalesce_usecs;
  2072. oct->rx_coalesce_usecs = rx_coalesce_usecs;
  2073. break;
  2074. }
  2075. case OCTEON_CN23XX_VF_VID: {
  2076. u64 time_threshold;
  2077. int q_no;
  2078. if (!intr_coal->rx_coalesce_usecs)
  2079. rx_coalesce_usecs = intrmod->rx_usecs;
  2080. else
  2081. rx_coalesce_usecs = intr_coal->rx_coalesce_usecs;
  2082. time_threshold =
  2083. cn23xx_vf_get_oq_ticks(oct, (u32)rx_coalesce_usecs);
  2084. for (q_no = 0; q_no < oct->num_oqs; q_no++) {
  2085. octeon_write_csr64(
  2086. oct, CN23XX_VF_SLI_OQ_PKT_INT_LEVELS(q_no),
  2087. (intrmod->rx_frames |
  2088. ((u64)time_threshold << 32)));
  2089. /*consider setting resend bit*/
  2090. }
  2091. intrmod->rx_usecs = rx_coalesce_usecs;
  2092. oct->rx_coalesce_usecs = rx_coalesce_usecs;
  2093. break;
  2094. }
  2095. default:
  2096. return -EINVAL;
  2097. }
  2098. return 0;
  2099. }
  2100. static int
  2101. oct_cfg_tx_intrcnt(struct lio *lio,
  2102. struct oct_intrmod_cfg *intrmod,
  2103. struct ethtool_coalesce *intr_coal)
  2104. {
  2105. struct octeon_device *oct = lio->oct_dev;
  2106. u32 iq_intr_pkt;
  2107. void __iomem *inst_cnt_reg;
  2108. u64 val;
  2109. /* Config Cnt based interrupt values */
  2110. switch (oct->chip_id) {
  2111. case OCTEON_CN68XX:
  2112. case OCTEON_CN66XX:
  2113. break;
  2114. case OCTEON_CN23XX_VF_VID:
  2115. case OCTEON_CN23XX_PF_VID: {
  2116. int q_no;
  2117. if (!intr_coal->tx_max_coalesced_frames)
  2118. iq_intr_pkt = CN23XX_DEF_IQ_INTR_THRESHOLD &
  2119. CN23XX_PKT_IN_DONE_WMARK_MASK;
  2120. else
  2121. iq_intr_pkt = intr_coal->tx_max_coalesced_frames &
  2122. CN23XX_PKT_IN_DONE_WMARK_MASK;
  2123. for (q_no = 0; q_no < oct->num_iqs; q_no++) {
  2124. inst_cnt_reg = (oct->instr_queue[q_no])->inst_cnt_reg;
  2125. val = readq(inst_cnt_reg);
  2126. /*clear wmark and count.dont want to write count back*/
  2127. val = (val & 0xFFFF000000000000ULL) |
  2128. ((u64)(iq_intr_pkt - 1)
  2129. << CN23XX_PKT_IN_DONE_WMARK_BIT_POS);
  2130. writeq(val, inst_cnt_reg);
  2131. /*consider setting resend bit*/
  2132. }
  2133. intrmod->tx_frames = iq_intr_pkt;
  2134. oct->tx_max_coalesced_frames = iq_intr_pkt;
  2135. break;
  2136. }
  2137. default:
  2138. return -EINVAL;
  2139. }
  2140. return 0;
  2141. }
  2142. static int lio_set_intr_coalesce(struct net_device *netdev,
  2143. struct ethtool_coalesce *intr_coal)
  2144. {
  2145. struct lio *lio = GET_LIO(netdev);
  2146. int ret;
  2147. struct octeon_device *oct = lio->oct_dev;
  2148. struct oct_intrmod_cfg intrmod = {0};
  2149. u32 j, q_no;
  2150. int db_max, db_min;
  2151. switch (oct->chip_id) {
  2152. case OCTEON_CN68XX:
  2153. case OCTEON_CN66XX:
  2154. db_min = CN6XXX_DB_MIN;
  2155. db_max = CN6XXX_DB_MAX;
  2156. if ((intr_coal->tx_max_coalesced_frames >= db_min) &&
  2157. (intr_coal->tx_max_coalesced_frames <= db_max)) {
  2158. for (j = 0; j < lio->linfo.num_txpciq; j++) {
  2159. q_no = lio->linfo.txpciq[j].s.q_no;
  2160. oct->instr_queue[q_no]->fill_threshold =
  2161. intr_coal->tx_max_coalesced_frames;
  2162. }
  2163. } else {
  2164. dev_err(&oct->pci_dev->dev,
  2165. "LIQUIDIO: Invalid tx-frames:%d. Range is min:%d max:%d\n",
  2166. intr_coal->tx_max_coalesced_frames,
  2167. db_min, db_max);
  2168. return -EINVAL;
  2169. }
  2170. break;
  2171. case OCTEON_CN23XX_PF_VID:
  2172. case OCTEON_CN23XX_VF_VID:
  2173. break;
  2174. default:
  2175. return -EINVAL;
  2176. }
  2177. intrmod.rx_enable = intr_coal->use_adaptive_rx_coalesce ? 1 : 0;
  2178. intrmod.tx_enable = intr_coal->use_adaptive_tx_coalesce ? 1 : 0;
  2179. intrmod.rx_frames = CFG_GET_OQ_INTR_PKT(octeon_get_conf(oct));
  2180. intrmod.rx_usecs = CFG_GET_OQ_INTR_TIME(octeon_get_conf(oct));
  2181. intrmod.tx_frames = CFG_GET_IQ_INTR_PKT(octeon_get_conf(oct));
  2182. ret = oct_cfg_adaptive_intr(lio, &intrmod, intr_coal);
  2183. if (!intr_coal->use_adaptive_rx_coalesce) {
  2184. ret = oct_cfg_rx_intrtime(lio, &intrmod, intr_coal);
  2185. if (ret)
  2186. goto ret_intrmod;
  2187. ret = oct_cfg_rx_intrcnt(lio, &intrmod, intr_coal);
  2188. if (ret)
  2189. goto ret_intrmod;
  2190. } else {
  2191. oct->rx_coalesce_usecs =
  2192. CFG_GET_OQ_INTR_TIME(octeon_get_conf(oct));
  2193. oct->rx_max_coalesced_frames =
  2194. CFG_GET_OQ_INTR_PKT(octeon_get_conf(oct));
  2195. }
  2196. if (!intr_coal->use_adaptive_tx_coalesce) {
  2197. ret = oct_cfg_tx_intrcnt(lio, &intrmod, intr_coal);
  2198. if (ret)
  2199. goto ret_intrmod;
  2200. } else {
  2201. oct->tx_max_coalesced_frames =
  2202. CFG_GET_IQ_INTR_PKT(octeon_get_conf(oct));
  2203. }
  2204. return 0;
  2205. ret_intrmod:
  2206. return ret;
  2207. }
  2208. static int lio_get_ts_info(struct net_device *netdev,
  2209. struct ethtool_ts_info *info)
  2210. {
  2211. struct lio *lio = GET_LIO(netdev);
  2212. info->so_timestamping =
  2213. #ifdef PTP_HARDWARE_TIMESTAMPING
  2214. SOF_TIMESTAMPING_TX_HARDWARE |
  2215. SOF_TIMESTAMPING_RX_HARDWARE |
  2216. SOF_TIMESTAMPING_RAW_HARDWARE |
  2217. SOF_TIMESTAMPING_TX_SOFTWARE |
  2218. #endif
  2219. SOF_TIMESTAMPING_RX_SOFTWARE |
  2220. SOF_TIMESTAMPING_SOFTWARE;
  2221. if (lio->ptp_clock)
  2222. info->phc_index = ptp_clock_index(lio->ptp_clock);
  2223. else
  2224. info->phc_index = -1;
  2225. #ifdef PTP_HARDWARE_TIMESTAMPING
  2226. info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
  2227. info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
  2228. (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
  2229. (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
  2230. (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT);
  2231. #endif
  2232. return 0;
  2233. }
  2234. /* Return register dump len. */
  2235. static int lio_get_regs_len(struct net_device *dev)
  2236. {
  2237. struct lio *lio = GET_LIO(dev);
  2238. struct octeon_device *oct = lio->oct_dev;
  2239. switch (oct->chip_id) {
  2240. case OCTEON_CN23XX_PF_VID:
  2241. return OCT_ETHTOOL_REGDUMP_LEN_23XX;
  2242. case OCTEON_CN23XX_VF_VID:
  2243. return OCT_ETHTOOL_REGDUMP_LEN_23XX_VF;
  2244. default:
  2245. return OCT_ETHTOOL_REGDUMP_LEN;
  2246. }
  2247. }
  2248. static int cn23xx_read_csr_reg(char *s, struct octeon_device *oct)
  2249. {
  2250. u32 reg;
  2251. u8 pf_num = oct->pf_num;
  2252. int len = 0;
  2253. int i;
  2254. /* PCI Window Registers */
  2255. len += sprintf(s + len, "\n\t Octeon CSR Registers\n\n");
  2256. /*0x29030 or 0x29040*/
  2257. reg = CN23XX_SLI_PKT_MAC_RINFO64(oct->pcie_port, oct->pf_num);
  2258. len += sprintf(s + len,
  2259. "\n[%08x] (SLI_PKT_MAC%d_PF%d_RINFO): %016llx\n",
  2260. reg, oct->pcie_port, oct->pf_num,
  2261. (u64)octeon_read_csr64(oct, reg));
  2262. /*0x27080 or 0x27090*/
  2263. reg = CN23XX_SLI_MAC_PF_INT_ENB64(oct->pcie_port, oct->pf_num);
  2264. len +=
  2265. sprintf(s + len, "\n[%08x] (SLI_MAC%d_PF%d_INT_ENB): %016llx\n",
  2266. reg, oct->pcie_port, oct->pf_num,
  2267. (u64)octeon_read_csr64(oct, reg));
  2268. /*0x27000 or 0x27010*/
  2269. reg = CN23XX_SLI_MAC_PF_INT_SUM64(oct->pcie_port, oct->pf_num);
  2270. len +=
  2271. sprintf(s + len, "\n[%08x] (SLI_MAC%d_PF%d_INT_SUM): %016llx\n",
  2272. reg, oct->pcie_port, oct->pf_num,
  2273. (u64)octeon_read_csr64(oct, reg));
  2274. /*0x29120*/
  2275. reg = 0x29120;
  2276. len += sprintf(s + len, "\n[%08x] (SLI_PKT_MEM_CTL): %016llx\n", reg,
  2277. (u64)octeon_read_csr64(oct, reg));
  2278. /*0x27300*/
  2279. reg = 0x27300 + oct->pcie_port * CN23XX_MAC_INT_OFFSET +
  2280. (oct->pf_num) * CN23XX_PF_INT_OFFSET;
  2281. len += sprintf(
  2282. s + len, "\n[%08x] (SLI_MAC%d_PF%d_PKT_VF_INT): %016llx\n", reg,
  2283. oct->pcie_port, oct->pf_num, (u64)octeon_read_csr64(oct, reg));
  2284. /*0x27200*/
  2285. reg = 0x27200 + oct->pcie_port * CN23XX_MAC_INT_OFFSET +
  2286. (oct->pf_num) * CN23XX_PF_INT_OFFSET;
  2287. len += sprintf(s + len,
  2288. "\n[%08x] (SLI_MAC%d_PF%d_PP_VF_INT): %016llx\n",
  2289. reg, oct->pcie_port, oct->pf_num,
  2290. (u64)octeon_read_csr64(oct, reg));
  2291. /*29130*/
  2292. reg = CN23XX_SLI_PKT_CNT_INT;
  2293. len += sprintf(s + len, "\n[%08x] (SLI_PKT_CNT_INT): %016llx\n", reg,
  2294. (u64)octeon_read_csr64(oct, reg));
  2295. /*0x29140*/
  2296. reg = CN23XX_SLI_PKT_TIME_INT;
  2297. len += sprintf(s + len, "\n[%08x] (SLI_PKT_TIME_INT): %016llx\n", reg,
  2298. (u64)octeon_read_csr64(oct, reg));
  2299. /*0x29160*/
  2300. reg = 0x29160;
  2301. len += sprintf(s + len, "\n[%08x] (SLI_PKT_INT): %016llx\n", reg,
  2302. (u64)octeon_read_csr64(oct, reg));
  2303. /*0x29180*/
  2304. reg = CN23XX_SLI_OQ_WMARK;
  2305. len += sprintf(s + len, "\n[%08x] (SLI_PKT_OUTPUT_WMARK): %016llx\n",
  2306. reg, (u64)octeon_read_csr64(oct, reg));
  2307. /*0x291E0*/
  2308. reg = CN23XX_SLI_PKT_IOQ_RING_RST;
  2309. len += sprintf(s + len, "\n[%08x] (SLI_PKT_RING_RST): %016llx\n", reg,
  2310. (u64)octeon_read_csr64(oct, reg));
  2311. /*0x29210*/
  2312. reg = CN23XX_SLI_GBL_CONTROL;
  2313. len += sprintf(s + len,
  2314. "\n[%08x] (SLI_PKT_GBL_CONTROL): %016llx\n", reg,
  2315. (u64)octeon_read_csr64(oct, reg));
  2316. /*0x29220*/
  2317. reg = 0x29220;
  2318. len += sprintf(s + len, "\n[%08x] (SLI_PKT_BIST_STATUS): %016llx\n",
  2319. reg, (u64)octeon_read_csr64(oct, reg));
  2320. /*PF only*/
  2321. if (pf_num == 0) {
  2322. /*0x29260*/
  2323. reg = CN23XX_SLI_OUT_BP_EN_W1S;
  2324. len += sprintf(s + len,
  2325. "\n[%08x] (SLI_PKT_OUT_BP_EN_W1S): %016llx\n",
  2326. reg, (u64)octeon_read_csr64(oct, reg));
  2327. } else if (pf_num == 1) {
  2328. /*0x29270*/
  2329. reg = CN23XX_SLI_OUT_BP_EN2_W1S;
  2330. len += sprintf(s + len,
  2331. "\n[%08x] (SLI_PKT_OUT_BP_EN2_W1S): %016llx\n",
  2332. reg, (u64)octeon_read_csr64(oct, reg));
  2333. }
  2334. for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
  2335. reg = CN23XX_SLI_OQ_BUFF_INFO_SIZE(i);
  2336. len +=
  2337. sprintf(s + len, "\n[%08x] (SLI_PKT%d_OUT_SIZE): %016llx\n",
  2338. reg, i, (u64)octeon_read_csr64(oct, reg));
  2339. }
  2340. /*0x10040*/
  2341. for (i = 0; i < CN23XX_MAX_INPUT_QUEUES; i++) {
  2342. reg = CN23XX_SLI_IQ_INSTR_COUNT64(i);
  2343. len += sprintf(s + len,
  2344. "\n[%08x] (SLI_PKT_IN_DONE%d_CNTS): %016llx\n",
  2345. reg, i, (u64)octeon_read_csr64(oct, reg));
  2346. }
  2347. /*0x10080*/
  2348. for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
  2349. reg = CN23XX_SLI_OQ_PKTS_CREDIT(i);
  2350. len += sprintf(s + len,
  2351. "\n[%08x] (SLI_PKT%d_SLIST_BAOFF_DBELL): %016llx\n",
  2352. reg, i, (u64)octeon_read_csr64(oct, reg));
  2353. }
  2354. /*0x10090*/
  2355. for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
  2356. reg = CN23XX_SLI_OQ_SIZE(i);
  2357. len += sprintf(
  2358. s + len, "\n[%08x] (SLI_PKT%d_SLIST_FIFO_RSIZE): %016llx\n",
  2359. reg, i, (u64)octeon_read_csr64(oct, reg));
  2360. }
  2361. /*0x10050*/
  2362. for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
  2363. reg = CN23XX_SLI_OQ_PKT_CONTROL(i);
  2364. len += sprintf(
  2365. s + len,
  2366. "\n[%08x] (SLI_PKT%d__OUTPUT_CONTROL): %016llx\n",
  2367. reg, i, (u64)octeon_read_csr64(oct, reg));
  2368. }
  2369. /*0x10070*/
  2370. for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
  2371. reg = CN23XX_SLI_OQ_BASE_ADDR64(i);
  2372. len += sprintf(s + len,
  2373. "\n[%08x] (SLI_PKT%d_SLIST_BADDR): %016llx\n",
  2374. reg, i, (u64)octeon_read_csr64(oct, reg));
  2375. }
  2376. /*0x100a0*/
  2377. for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
  2378. reg = CN23XX_SLI_OQ_PKT_INT_LEVELS(i);
  2379. len += sprintf(s + len,
  2380. "\n[%08x] (SLI_PKT%d_INT_LEVELS): %016llx\n",
  2381. reg, i, (u64)octeon_read_csr64(oct, reg));
  2382. }
  2383. /*0x100b0*/
  2384. for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
  2385. reg = CN23XX_SLI_OQ_PKTS_SENT(i);
  2386. len += sprintf(s + len, "\n[%08x] (SLI_PKT%d_CNTS): %016llx\n",
  2387. reg, i, (u64)octeon_read_csr64(oct, reg));
  2388. }
  2389. /*0x100c0*/
  2390. for (i = 0; i < CN23XX_MAX_OUTPUT_QUEUES; i++) {
  2391. reg = 0x100c0 + i * CN23XX_OQ_OFFSET;
  2392. len += sprintf(s + len,
  2393. "\n[%08x] (SLI_PKT%d_ERROR_INFO): %016llx\n",
  2394. reg, i, (u64)octeon_read_csr64(oct, reg));
  2395. /*0x10000*/
  2396. for (i = 0; i < CN23XX_MAX_INPUT_QUEUES; i++) {
  2397. reg = CN23XX_SLI_IQ_PKT_CONTROL64(i);
  2398. len += sprintf(
  2399. s + len,
  2400. "\n[%08x] (SLI_PKT%d_INPUT_CONTROL): %016llx\n",
  2401. reg, i, (u64)octeon_read_csr64(oct, reg));
  2402. }
  2403. /*0x10010*/
  2404. for (i = 0; i < CN23XX_MAX_INPUT_QUEUES; i++) {
  2405. reg = CN23XX_SLI_IQ_BASE_ADDR64(i);
  2406. len += sprintf(
  2407. s + len,
  2408. "\n[%08x] (SLI_PKT%d_INSTR_BADDR): %016llx\n", reg,
  2409. i, (u64)octeon_read_csr64(oct, reg));
  2410. }
  2411. /*0x10020*/
  2412. for (i = 0; i < CN23XX_MAX_INPUT_QUEUES; i++) {
  2413. reg = CN23XX_SLI_IQ_DOORBELL(i);
  2414. len += sprintf(
  2415. s + len,
  2416. "\n[%08x] (SLI_PKT%d_INSTR_BAOFF_DBELL): %016llx\n",
  2417. reg, i, (u64)octeon_read_csr64(oct, reg));
  2418. }
  2419. /*0x10030*/
  2420. for (i = 0; i < CN23XX_MAX_INPUT_QUEUES; i++) {
  2421. reg = CN23XX_SLI_IQ_SIZE(i);
  2422. len += sprintf(
  2423. s + len,
  2424. "\n[%08x] (SLI_PKT%d_INSTR_FIFO_RSIZE): %016llx\n",
  2425. reg, i, (u64)octeon_read_csr64(oct, reg));
  2426. }
  2427. /*0x10040*/
  2428. for (i = 0; i < CN23XX_MAX_INPUT_QUEUES; i++)
  2429. reg = CN23XX_SLI_IQ_INSTR_COUNT64(i);
  2430. len += sprintf(s + len,
  2431. "\n[%08x] (SLI_PKT_IN_DONE%d_CNTS): %016llx\n",
  2432. reg, i, (u64)octeon_read_csr64(oct, reg));
  2433. }
  2434. return len;
  2435. }
  2436. static int cn23xx_vf_read_csr_reg(char *s, struct octeon_device *oct)
  2437. {
  2438. int len = 0;
  2439. u32 reg;
  2440. int i;
  2441. /* PCI Window Registers */
  2442. len += sprintf(s + len, "\n\t Octeon CSR Registers\n\n");
  2443. for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
  2444. reg = CN23XX_VF_SLI_OQ_BUFF_INFO_SIZE(i);
  2445. len += sprintf(s + len,
  2446. "\n[%08x] (SLI_PKT%d_OUT_SIZE): %016llx\n",
  2447. reg, i, (u64)octeon_read_csr64(oct, reg));
  2448. }
  2449. for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
  2450. reg = CN23XX_VF_SLI_IQ_INSTR_COUNT64(i);
  2451. len += sprintf(s + len,
  2452. "\n[%08x] (SLI_PKT_IN_DONE%d_CNTS): %016llx\n",
  2453. reg, i, (u64)octeon_read_csr64(oct, reg));
  2454. }
  2455. for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
  2456. reg = CN23XX_VF_SLI_OQ_PKTS_CREDIT(i);
  2457. len += sprintf(s + len,
  2458. "\n[%08x] (SLI_PKT%d_SLIST_BAOFF_DBELL): %016llx\n",
  2459. reg, i, (u64)octeon_read_csr64(oct, reg));
  2460. }
  2461. for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
  2462. reg = CN23XX_VF_SLI_OQ_SIZE(i);
  2463. len += sprintf(s + len,
  2464. "\n[%08x] (SLI_PKT%d_SLIST_FIFO_RSIZE): %016llx\n",
  2465. reg, i, (u64)octeon_read_csr64(oct, reg));
  2466. }
  2467. for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
  2468. reg = CN23XX_VF_SLI_OQ_PKT_CONTROL(i);
  2469. len += sprintf(s + len,
  2470. "\n[%08x] (SLI_PKT%d__OUTPUT_CONTROL): %016llx\n",
  2471. reg, i, (u64)octeon_read_csr64(oct, reg));
  2472. }
  2473. for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
  2474. reg = CN23XX_VF_SLI_OQ_BASE_ADDR64(i);
  2475. len += sprintf(s + len,
  2476. "\n[%08x] (SLI_PKT%d_SLIST_BADDR): %016llx\n",
  2477. reg, i, (u64)octeon_read_csr64(oct, reg));
  2478. }
  2479. for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
  2480. reg = CN23XX_VF_SLI_OQ_PKT_INT_LEVELS(i);
  2481. len += sprintf(s + len,
  2482. "\n[%08x] (SLI_PKT%d_INT_LEVELS): %016llx\n",
  2483. reg, i, (u64)octeon_read_csr64(oct, reg));
  2484. }
  2485. for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
  2486. reg = CN23XX_VF_SLI_OQ_PKTS_SENT(i);
  2487. len += sprintf(s + len, "\n[%08x] (SLI_PKT%d_CNTS): %016llx\n",
  2488. reg, i, (u64)octeon_read_csr64(oct, reg));
  2489. }
  2490. for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
  2491. reg = 0x100c0 + i * CN23XX_VF_OQ_OFFSET;
  2492. len += sprintf(s + len,
  2493. "\n[%08x] (SLI_PKT%d_ERROR_INFO): %016llx\n",
  2494. reg, i, (u64)octeon_read_csr64(oct, reg));
  2495. }
  2496. for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
  2497. reg = 0x100d0 + i * CN23XX_VF_IQ_OFFSET;
  2498. len += sprintf(s + len,
  2499. "\n[%08x] (SLI_PKT%d_VF_INT_SUM): %016llx\n",
  2500. reg, i, (u64)octeon_read_csr64(oct, reg));
  2501. }
  2502. for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
  2503. reg = CN23XX_VF_SLI_IQ_PKT_CONTROL64(i);
  2504. len += sprintf(s + len,
  2505. "\n[%08x] (SLI_PKT%d_INPUT_CONTROL): %016llx\n",
  2506. reg, i, (u64)octeon_read_csr64(oct, reg));
  2507. }
  2508. for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
  2509. reg = CN23XX_VF_SLI_IQ_BASE_ADDR64(i);
  2510. len += sprintf(s + len,
  2511. "\n[%08x] (SLI_PKT%d_INSTR_BADDR): %016llx\n",
  2512. reg, i, (u64)octeon_read_csr64(oct, reg));
  2513. }
  2514. for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
  2515. reg = CN23XX_VF_SLI_IQ_DOORBELL(i);
  2516. len += sprintf(s + len,
  2517. "\n[%08x] (SLI_PKT%d_INSTR_BAOFF_DBELL): %016llx\n",
  2518. reg, i, (u64)octeon_read_csr64(oct, reg));
  2519. }
  2520. for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
  2521. reg = CN23XX_VF_SLI_IQ_SIZE(i);
  2522. len += sprintf(s + len,
  2523. "\n[%08x] (SLI_PKT%d_INSTR_FIFO_RSIZE): %016llx\n",
  2524. reg, i, (u64)octeon_read_csr64(oct, reg));
  2525. }
  2526. for (i = 0; i < (oct->sriov_info.rings_per_vf); i++) {
  2527. reg = CN23XX_VF_SLI_IQ_INSTR_COUNT64(i);
  2528. len += sprintf(s + len,
  2529. "\n[%08x] (SLI_PKT_IN_DONE%d_CNTS): %016llx\n",
  2530. reg, i, (u64)octeon_read_csr64(oct, reg));
  2531. }
  2532. return len;
  2533. }
  2534. static int cn6xxx_read_csr_reg(char *s, struct octeon_device *oct)
  2535. {
  2536. u32 reg;
  2537. int i, len = 0;
  2538. /* PCI Window Registers */
  2539. len += sprintf(s + len, "\n\t Octeon CSR Registers\n\n");
  2540. reg = CN6XXX_WIN_WR_ADDR_LO;
  2541. len += sprintf(s + len, "\n[%02x] (WIN_WR_ADDR_LO): %08x\n",
  2542. CN6XXX_WIN_WR_ADDR_LO, octeon_read_csr(oct, reg));
  2543. reg = CN6XXX_WIN_WR_ADDR_HI;
  2544. len += sprintf(s + len, "[%02x] (WIN_WR_ADDR_HI): %08x\n",
  2545. CN6XXX_WIN_WR_ADDR_HI, octeon_read_csr(oct, reg));
  2546. reg = CN6XXX_WIN_RD_ADDR_LO;
  2547. len += sprintf(s + len, "[%02x] (WIN_RD_ADDR_LO): %08x\n",
  2548. CN6XXX_WIN_RD_ADDR_LO, octeon_read_csr(oct, reg));
  2549. reg = CN6XXX_WIN_RD_ADDR_HI;
  2550. len += sprintf(s + len, "[%02x] (WIN_RD_ADDR_HI): %08x\n",
  2551. CN6XXX_WIN_RD_ADDR_HI, octeon_read_csr(oct, reg));
  2552. reg = CN6XXX_WIN_WR_DATA_LO;
  2553. len += sprintf(s + len, "[%02x] (WIN_WR_DATA_LO): %08x\n",
  2554. CN6XXX_WIN_WR_DATA_LO, octeon_read_csr(oct, reg));
  2555. reg = CN6XXX_WIN_WR_DATA_HI;
  2556. len += sprintf(s + len, "[%02x] (WIN_WR_DATA_HI): %08x\n",
  2557. CN6XXX_WIN_WR_DATA_HI, octeon_read_csr(oct, reg));
  2558. len += sprintf(s + len, "[%02x] (WIN_WR_MASK_REG): %08x\n",
  2559. CN6XXX_WIN_WR_MASK_REG,
  2560. octeon_read_csr(oct, CN6XXX_WIN_WR_MASK_REG));
  2561. /* PCI Interrupt Register */
  2562. len += sprintf(s + len, "\n[%x] (INT_ENABLE PORT 0): %08x\n",
  2563. CN6XXX_SLI_INT_ENB64_PORT0, octeon_read_csr(oct,
  2564. CN6XXX_SLI_INT_ENB64_PORT0));
  2565. len += sprintf(s + len, "\n[%x] (INT_ENABLE PORT 1): %08x\n",
  2566. CN6XXX_SLI_INT_ENB64_PORT1,
  2567. octeon_read_csr(oct, CN6XXX_SLI_INT_ENB64_PORT1));
  2568. len += sprintf(s + len, "[%x] (INT_SUM): %08x\n", CN6XXX_SLI_INT_SUM64,
  2569. octeon_read_csr(oct, CN6XXX_SLI_INT_SUM64));
  2570. /* PCI Output queue registers */
  2571. for (i = 0; i < oct->num_oqs; i++) {
  2572. reg = CN6XXX_SLI_OQ_PKTS_SENT(i);
  2573. len += sprintf(s + len, "\n[%x] (PKTS_SENT_%d): %08x\n",
  2574. reg, i, octeon_read_csr(oct, reg));
  2575. reg = CN6XXX_SLI_OQ_PKTS_CREDIT(i);
  2576. len += sprintf(s + len, "[%x] (PKT_CREDITS_%d): %08x\n",
  2577. reg, i, octeon_read_csr(oct, reg));
  2578. }
  2579. reg = CN6XXX_SLI_OQ_INT_LEVEL_PKTS;
  2580. len += sprintf(s + len, "\n[%x] (PKTS_SENT_INT_LEVEL): %08x\n",
  2581. reg, octeon_read_csr(oct, reg));
  2582. reg = CN6XXX_SLI_OQ_INT_LEVEL_TIME;
  2583. len += sprintf(s + len, "[%x] (PKTS_SENT_TIME): %08x\n",
  2584. reg, octeon_read_csr(oct, reg));
  2585. /* PCI Input queue registers */
  2586. for (i = 0; i <= 3; i++) {
  2587. u32 reg;
  2588. reg = CN6XXX_SLI_IQ_DOORBELL(i);
  2589. len += sprintf(s + len, "\n[%x] (INSTR_DOORBELL_%d): %08x\n",
  2590. reg, i, octeon_read_csr(oct, reg));
  2591. reg = CN6XXX_SLI_IQ_INSTR_COUNT(i);
  2592. len += sprintf(s + len, "[%x] (INSTR_COUNT_%d): %08x\n",
  2593. reg, i, octeon_read_csr(oct, reg));
  2594. }
  2595. /* PCI DMA registers */
  2596. len += sprintf(s + len, "\n[%x] (DMA_CNT_0): %08x\n",
  2597. CN6XXX_DMA_CNT(0),
  2598. octeon_read_csr(oct, CN6XXX_DMA_CNT(0)));
  2599. reg = CN6XXX_DMA_PKT_INT_LEVEL(0);
  2600. len += sprintf(s + len, "[%x] (DMA_INT_LEV_0): %08x\n",
  2601. CN6XXX_DMA_PKT_INT_LEVEL(0), octeon_read_csr(oct, reg));
  2602. reg = CN6XXX_DMA_TIME_INT_LEVEL(0);
  2603. len += sprintf(s + len, "[%x] (DMA_TIME_0): %08x\n",
  2604. CN6XXX_DMA_TIME_INT_LEVEL(0),
  2605. octeon_read_csr(oct, reg));
  2606. len += sprintf(s + len, "\n[%x] (DMA_CNT_1): %08x\n",
  2607. CN6XXX_DMA_CNT(1),
  2608. octeon_read_csr(oct, CN6XXX_DMA_CNT(1)));
  2609. reg = CN6XXX_DMA_PKT_INT_LEVEL(1);
  2610. len += sprintf(s + len, "[%x] (DMA_INT_LEV_1): %08x\n",
  2611. CN6XXX_DMA_PKT_INT_LEVEL(1),
  2612. octeon_read_csr(oct, reg));
  2613. reg = CN6XXX_DMA_PKT_INT_LEVEL(1);
  2614. len += sprintf(s + len, "[%x] (DMA_TIME_1): %08x\n",
  2615. CN6XXX_DMA_TIME_INT_LEVEL(1),
  2616. octeon_read_csr(oct, reg));
  2617. /* PCI Index registers */
  2618. len += sprintf(s + len, "\n");
  2619. for (i = 0; i < 16; i++) {
  2620. reg = lio_pci_readq(oct, CN6XXX_BAR1_REG(i, oct->pcie_port));
  2621. len += sprintf(s + len, "[%llx] (BAR1_INDEX_%02d): %08x\n",
  2622. CN6XXX_BAR1_REG(i, oct->pcie_port), i, reg);
  2623. }
  2624. return len;
  2625. }
  2626. static int cn6xxx_read_config_reg(char *s, struct octeon_device *oct)
  2627. {
  2628. u32 val;
  2629. int i, len = 0;
  2630. /* PCI CONFIG Registers */
  2631. len += sprintf(s + len,
  2632. "\n\t Octeon Config space Registers\n\n");
  2633. for (i = 0; i <= 13; i++) {
  2634. pci_read_config_dword(oct->pci_dev, (i * 4), &val);
  2635. len += sprintf(s + len, "[0x%x] (Config[%d]): 0x%08x\n",
  2636. (i * 4), i, val);
  2637. }
  2638. for (i = 30; i <= 34; i++) {
  2639. pci_read_config_dword(oct->pci_dev, (i * 4), &val);
  2640. len += sprintf(s + len, "[0x%x] (Config[%d]): 0x%08x\n",
  2641. (i * 4), i, val);
  2642. }
  2643. return len;
  2644. }
  2645. /* Return register dump user app. */
  2646. static void lio_get_regs(struct net_device *dev,
  2647. struct ethtool_regs *regs, void *regbuf)
  2648. {
  2649. struct lio *lio = GET_LIO(dev);
  2650. int len = 0;
  2651. struct octeon_device *oct = lio->oct_dev;
  2652. regs->version = OCT_ETHTOOL_REGSVER;
  2653. switch (oct->chip_id) {
  2654. case OCTEON_CN23XX_PF_VID:
  2655. memset(regbuf, 0, OCT_ETHTOOL_REGDUMP_LEN_23XX);
  2656. len += cn23xx_read_csr_reg(regbuf + len, oct);
  2657. break;
  2658. case OCTEON_CN23XX_VF_VID:
  2659. memset(regbuf, 0, OCT_ETHTOOL_REGDUMP_LEN_23XX_VF);
  2660. len += cn23xx_vf_read_csr_reg(regbuf + len, oct);
  2661. break;
  2662. case OCTEON_CN68XX:
  2663. case OCTEON_CN66XX:
  2664. memset(regbuf, 0, OCT_ETHTOOL_REGDUMP_LEN);
  2665. len += cn6xxx_read_csr_reg(regbuf + len, oct);
  2666. len += cn6xxx_read_config_reg(regbuf + len, oct);
  2667. break;
  2668. default:
  2669. dev_err(&oct->pci_dev->dev, "%s Unknown chipid: %d\n",
  2670. __func__, oct->chip_id);
  2671. }
  2672. }
  2673. static u32 lio_get_priv_flags(struct net_device *netdev)
  2674. {
  2675. struct lio *lio = GET_LIO(netdev);
  2676. return lio->oct_dev->priv_flags;
  2677. }
  2678. static int lio_set_priv_flags(struct net_device *netdev, u32 flags)
  2679. {
  2680. struct lio *lio = GET_LIO(netdev);
  2681. bool intr_by_tx_bytes = !!(flags & (0x1 << OCT_PRIV_FLAG_TX_BYTES));
  2682. lio_set_priv_flag(lio->oct_dev, OCT_PRIV_FLAG_TX_BYTES,
  2683. intr_by_tx_bytes);
  2684. return 0;
  2685. }
  2686. static const struct ethtool_ops lio_ethtool_ops = {
  2687. .get_link_ksettings = lio_get_link_ksettings,
  2688. .set_link_ksettings = lio_set_link_ksettings,
  2689. .get_link = ethtool_op_get_link,
  2690. .get_drvinfo = lio_get_drvinfo,
  2691. .get_ringparam = lio_ethtool_get_ringparam,
  2692. .set_ringparam = lio_ethtool_set_ringparam,
  2693. .get_channels = lio_ethtool_get_channels,
  2694. .set_channels = lio_ethtool_set_channels,
  2695. .set_phys_id = lio_set_phys_id,
  2696. .get_eeprom_len = lio_get_eeprom_len,
  2697. .get_eeprom = lio_get_eeprom,
  2698. .get_strings = lio_get_strings,
  2699. .get_ethtool_stats = lio_get_ethtool_stats,
  2700. .get_pauseparam = lio_get_pauseparam,
  2701. .set_pauseparam = lio_set_pauseparam,
  2702. .get_regs_len = lio_get_regs_len,
  2703. .get_regs = lio_get_regs,
  2704. .get_msglevel = lio_get_msglevel,
  2705. .set_msglevel = lio_set_msglevel,
  2706. .get_sset_count = lio_get_sset_count,
  2707. .get_coalesce = lio_get_intr_coalesce,
  2708. .set_coalesce = lio_set_intr_coalesce,
  2709. .get_priv_flags = lio_get_priv_flags,
  2710. .set_priv_flags = lio_set_priv_flags,
  2711. .get_ts_info = lio_get_ts_info,
  2712. };
  2713. static const struct ethtool_ops lio_vf_ethtool_ops = {
  2714. .get_link_ksettings = lio_get_link_ksettings,
  2715. .get_link = ethtool_op_get_link,
  2716. .get_drvinfo = lio_get_vf_drvinfo,
  2717. .get_ringparam = lio_ethtool_get_ringparam,
  2718. .set_ringparam = lio_ethtool_set_ringparam,
  2719. .get_channels = lio_ethtool_get_channels,
  2720. .set_channels = lio_ethtool_set_channels,
  2721. .get_strings = lio_vf_get_strings,
  2722. .get_ethtool_stats = lio_vf_get_ethtool_stats,
  2723. .get_regs_len = lio_get_regs_len,
  2724. .get_regs = lio_get_regs,
  2725. .get_msglevel = lio_get_msglevel,
  2726. .set_msglevel = lio_vf_set_msglevel,
  2727. .get_sset_count = lio_vf_get_sset_count,
  2728. .get_coalesce = lio_get_intr_coalesce,
  2729. .set_coalesce = lio_set_intr_coalesce,
  2730. .get_priv_flags = lio_get_priv_flags,
  2731. .set_priv_flags = lio_set_priv_flags,
  2732. .get_ts_info = lio_get_ts_info,
  2733. };
  2734. void liquidio_set_ethtool_ops(struct net_device *netdev)
  2735. {
  2736. struct lio *lio = GET_LIO(netdev);
  2737. struct octeon_device *oct = lio->oct_dev;
  2738. if (OCTEON_CN23XX_VF(oct))
  2739. netdev->ethtool_ops = &lio_vf_ethtool_ops;
  2740. else
  2741. netdev->ethtool_ops = &lio_ethtool_ops;
  2742. }