lio_ethtool.c 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185
  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. }