i40e_ethtool.c 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2016 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. /* ethtool support for i40e */
  27. #include "i40e.h"
  28. #include "i40e_diag.h"
  29. struct i40e_stats {
  30. char stat_string[ETH_GSTRING_LEN];
  31. int sizeof_stat;
  32. int stat_offset;
  33. };
  34. #define I40E_STAT(_type, _name, _stat) { \
  35. .stat_string = _name, \
  36. .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
  37. .stat_offset = offsetof(_type, _stat) \
  38. }
  39. #define I40E_NETDEV_STAT(_net_stat) \
  40. I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
  41. #define I40E_PF_STAT(_name, _stat) \
  42. I40E_STAT(struct i40e_pf, _name, _stat)
  43. #define I40E_VSI_STAT(_name, _stat) \
  44. I40E_STAT(struct i40e_vsi, _name, _stat)
  45. #define I40E_VEB_STAT(_name, _stat) \
  46. I40E_STAT(struct i40e_veb, _name, _stat)
  47. static const struct i40e_stats i40e_gstrings_net_stats[] = {
  48. I40E_NETDEV_STAT(rx_packets),
  49. I40E_NETDEV_STAT(tx_packets),
  50. I40E_NETDEV_STAT(rx_bytes),
  51. I40E_NETDEV_STAT(tx_bytes),
  52. I40E_NETDEV_STAT(rx_errors),
  53. I40E_NETDEV_STAT(tx_errors),
  54. I40E_NETDEV_STAT(rx_dropped),
  55. I40E_NETDEV_STAT(tx_dropped),
  56. I40E_NETDEV_STAT(collisions),
  57. I40E_NETDEV_STAT(rx_length_errors),
  58. I40E_NETDEV_STAT(rx_crc_errors),
  59. };
  60. static const struct i40e_stats i40e_gstrings_veb_stats[] = {
  61. I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
  62. I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
  63. I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
  64. I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
  65. I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
  66. I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
  67. I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
  68. I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
  69. I40E_VEB_STAT("rx_discards", stats.rx_discards),
  70. I40E_VEB_STAT("tx_discards", stats.tx_discards),
  71. I40E_VEB_STAT("tx_errors", stats.tx_errors),
  72. I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
  73. };
  74. static const struct i40e_stats i40e_gstrings_misc_stats[] = {
  75. I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
  76. I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
  77. I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
  78. I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
  79. I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
  80. I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
  81. I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
  82. I40E_VSI_STAT("tx_linearize", tx_linearize),
  83. I40E_VSI_STAT("tx_force_wb", tx_force_wb),
  84. I40E_VSI_STAT("tx_lost_interrupt", tx_lost_interrupt),
  85. I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed),
  86. I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
  87. };
  88. /* These PF_STATs might look like duplicates of some NETDEV_STATs,
  89. * but they are separate. This device supports Virtualization, and
  90. * as such might have several netdevs supporting VMDq and FCoE going
  91. * through a single port. The NETDEV_STATs are for individual netdevs
  92. * seen at the top of the stack, and the PF_STATs are for the physical
  93. * function at the bottom of the stack hosting those netdevs.
  94. *
  95. * The PF_STATs are appended to the netdev stats only when ethtool -S
  96. * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
  97. */
  98. static struct i40e_stats i40e_gstrings_stats[] = {
  99. I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
  100. I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
  101. I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
  102. I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
  103. I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
  104. I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
  105. I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
  106. I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
  107. I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
  108. I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
  109. I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
  110. I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
  111. I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
  112. I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
  113. I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
  114. I40E_PF_STAT("tx_timeout", tx_timeout_count),
  115. I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
  116. I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
  117. I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
  118. I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
  119. I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
  120. I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
  121. I40E_PF_STAT("rx_size_64", stats.rx_size_64),
  122. I40E_PF_STAT("rx_size_127", stats.rx_size_127),
  123. I40E_PF_STAT("rx_size_255", stats.rx_size_255),
  124. I40E_PF_STAT("rx_size_511", stats.rx_size_511),
  125. I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
  126. I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
  127. I40E_PF_STAT("rx_size_big", stats.rx_size_big),
  128. I40E_PF_STAT("tx_size_64", stats.tx_size_64),
  129. I40E_PF_STAT("tx_size_127", stats.tx_size_127),
  130. I40E_PF_STAT("tx_size_255", stats.tx_size_255),
  131. I40E_PF_STAT("tx_size_511", stats.tx_size_511),
  132. I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
  133. I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
  134. I40E_PF_STAT("tx_size_big", stats.tx_size_big),
  135. I40E_PF_STAT("rx_undersize", stats.rx_undersize),
  136. I40E_PF_STAT("rx_fragments", stats.rx_fragments),
  137. I40E_PF_STAT("rx_oversize", stats.rx_oversize),
  138. I40E_PF_STAT("rx_jabber", stats.rx_jabber),
  139. I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
  140. I40E_PF_STAT("arq_overflows", arq_overflows),
  141. I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
  142. I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
  143. I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
  144. I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
  145. I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
  146. I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
  147. I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
  148. /* LPI stats */
  149. I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
  150. I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
  151. I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
  152. I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
  153. };
  154. #ifdef I40E_FCOE
  155. static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
  156. I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
  157. I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
  158. I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
  159. I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
  160. I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
  161. I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
  162. I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
  163. I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
  164. };
  165. #endif /* I40E_FCOE */
  166. #define I40E_QUEUE_STATS_LEN(n) \
  167. (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
  168. * 2 /* Tx and Rx together */ \
  169. * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
  170. #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
  171. #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
  172. #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
  173. #ifdef I40E_FCOE
  174. #define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
  175. #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
  176. I40E_FCOE_STATS_LEN + \
  177. I40E_MISC_STATS_LEN + \
  178. I40E_QUEUE_STATS_LEN((n)))
  179. #else
  180. #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
  181. I40E_MISC_STATS_LEN + \
  182. I40E_QUEUE_STATS_LEN((n)))
  183. #endif /* I40E_FCOE */
  184. #define I40E_PFC_STATS_LEN ( \
  185. (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
  186. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
  187. FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
  188. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
  189. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
  190. / sizeof(u64))
  191. #define I40E_VEB_TC_STATS_LEN ( \
  192. (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
  193. FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
  194. FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
  195. FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
  196. / sizeof(u64))
  197. #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
  198. #define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
  199. #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
  200. I40E_PFC_STATS_LEN + \
  201. I40E_VSI_STATS_LEN((n)))
  202. enum i40e_ethtool_test_id {
  203. I40E_ETH_TEST_REG = 0,
  204. I40E_ETH_TEST_EEPROM,
  205. I40E_ETH_TEST_INTR,
  206. I40E_ETH_TEST_LOOPBACK,
  207. I40E_ETH_TEST_LINK,
  208. };
  209. static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
  210. "Register test (offline)",
  211. "Eeprom test (offline)",
  212. "Interrupt test (offline)",
  213. "Loopback test (offline)",
  214. "Link test (on/offline)"
  215. };
  216. #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
  217. static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
  218. "NPAR",
  219. "LinkPolling",
  220. "flow-director-atr",
  221. "veb-stats",
  222. "packet-split",
  223. "hw-atr-eviction",
  224. };
  225. #define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
  226. /**
  227. * i40e_partition_setting_complaint - generic complaint for MFP restriction
  228. * @pf: the PF struct
  229. **/
  230. static void i40e_partition_setting_complaint(struct i40e_pf *pf)
  231. {
  232. dev_info(&pf->pdev->dev,
  233. "The link settings are allowed to be changed only from the first partition of a given port. Please switch to the first partition in order to change the setting.\n");
  234. }
  235. /**
  236. * i40e_get_settings_link_up - Get the Link settings for when link is up
  237. * @hw: hw structure
  238. * @ecmd: ethtool command to fill in
  239. * @netdev: network interface device structure
  240. *
  241. **/
  242. static void i40e_get_settings_link_up(struct i40e_hw *hw,
  243. struct ethtool_cmd *ecmd,
  244. struct net_device *netdev,
  245. struct i40e_pf *pf)
  246. {
  247. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  248. u32 link_speed = hw_link_info->link_speed;
  249. /* Initialize supported and advertised settings based on phy settings */
  250. switch (hw_link_info->phy_type) {
  251. case I40E_PHY_TYPE_40GBASE_CR4:
  252. case I40E_PHY_TYPE_40GBASE_CR4_CU:
  253. ecmd->supported = SUPPORTED_Autoneg |
  254. SUPPORTED_40000baseCR4_Full;
  255. ecmd->advertising = ADVERTISED_Autoneg |
  256. ADVERTISED_40000baseCR4_Full;
  257. break;
  258. case I40E_PHY_TYPE_XLAUI:
  259. case I40E_PHY_TYPE_XLPPI:
  260. case I40E_PHY_TYPE_40GBASE_AOC:
  261. ecmd->supported = SUPPORTED_40000baseCR4_Full;
  262. break;
  263. case I40E_PHY_TYPE_40GBASE_SR4:
  264. ecmd->supported = SUPPORTED_40000baseSR4_Full;
  265. break;
  266. case I40E_PHY_TYPE_40GBASE_LR4:
  267. ecmd->supported = SUPPORTED_40000baseLR4_Full;
  268. break;
  269. case I40E_PHY_TYPE_10GBASE_SR:
  270. case I40E_PHY_TYPE_10GBASE_LR:
  271. case I40E_PHY_TYPE_1000BASE_SX:
  272. case I40E_PHY_TYPE_1000BASE_LX:
  273. ecmd->supported = SUPPORTED_10000baseT_Full;
  274. if (hw_link_info->module_type[2] &
  275. I40E_MODULE_TYPE_1000BASE_SX ||
  276. hw_link_info->module_type[2] &
  277. I40E_MODULE_TYPE_1000BASE_LX) {
  278. ecmd->supported |= SUPPORTED_1000baseT_Full;
  279. if (hw_link_info->requested_speeds &
  280. I40E_LINK_SPEED_1GB)
  281. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  282. }
  283. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  284. ecmd->advertising |= ADVERTISED_10000baseT_Full;
  285. break;
  286. case I40E_PHY_TYPE_10GBASE_T:
  287. case I40E_PHY_TYPE_1000BASE_T:
  288. ecmd->supported = SUPPORTED_Autoneg |
  289. SUPPORTED_10000baseT_Full |
  290. SUPPORTED_1000baseT_Full;
  291. ecmd->advertising = ADVERTISED_Autoneg;
  292. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  293. ecmd->advertising |= ADVERTISED_10000baseT_Full;
  294. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  295. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  296. /* adding 100baseT support for 10GBASET_PHY */
  297. if (pf->flags & I40E_FLAG_HAVE_10GBASET_PHY) {
  298. ecmd->supported |= SUPPORTED_100baseT_Full;
  299. ecmd->advertising |= ADVERTISED_100baseT_Full |
  300. ADVERTISED_1000baseT_Full |
  301. ADVERTISED_10000baseT_Full;
  302. }
  303. break;
  304. case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
  305. ecmd->supported = SUPPORTED_Autoneg |
  306. SUPPORTED_1000baseT_Full;
  307. ecmd->advertising = ADVERTISED_Autoneg |
  308. ADVERTISED_1000baseT_Full;
  309. break;
  310. case I40E_PHY_TYPE_100BASE_TX:
  311. ecmd->supported = SUPPORTED_Autoneg |
  312. SUPPORTED_100baseT_Full;
  313. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
  314. ecmd->advertising |= ADVERTISED_100baseT_Full;
  315. /* firmware detects 10G phy as 100M phy at 100M speed */
  316. if (pf->flags & I40E_FLAG_HAVE_10GBASET_PHY) {
  317. ecmd->supported |= SUPPORTED_10000baseT_Full |
  318. SUPPORTED_1000baseT_Full;
  319. ecmd->advertising |= ADVERTISED_Autoneg |
  320. ADVERTISED_100baseT_Full |
  321. ADVERTISED_1000baseT_Full |
  322. ADVERTISED_10000baseT_Full;
  323. }
  324. break;
  325. case I40E_PHY_TYPE_10GBASE_CR1_CU:
  326. case I40E_PHY_TYPE_10GBASE_CR1:
  327. ecmd->supported = SUPPORTED_Autoneg |
  328. SUPPORTED_10000baseT_Full;
  329. ecmd->advertising = ADVERTISED_Autoneg |
  330. ADVERTISED_10000baseT_Full;
  331. break;
  332. case I40E_PHY_TYPE_XAUI:
  333. case I40E_PHY_TYPE_XFI:
  334. case I40E_PHY_TYPE_SFI:
  335. case I40E_PHY_TYPE_10GBASE_SFPP_CU:
  336. case I40E_PHY_TYPE_10GBASE_AOC:
  337. ecmd->supported = SUPPORTED_10000baseT_Full;
  338. break;
  339. case I40E_PHY_TYPE_SGMII:
  340. ecmd->supported = SUPPORTED_Autoneg |
  341. SUPPORTED_1000baseT_Full;
  342. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  343. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  344. if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
  345. ecmd->supported |= SUPPORTED_100baseT_Full;
  346. if (hw_link_info->requested_speeds &
  347. I40E_LINK_SPEED_100MB)
  348. ecmd->advertising |= ADVERTISED_100baseT_Full;
  349. }
  350. break;
  351. /* Backplane is set based on supported phy types in get_settings
  352. * so don't set anything here but don't warn either
  353. */
  354. case I40E_PHY_TYPE_40GBASE_KR4:
  355. case I40E_PHY_TYPE_20GBASE_KR2:
  356. case I40E_PHY_TYPE_10GBASE_KR:
  357. case I40E_PHY_TYPE_10GBASE_KX4:
  358. case I40E_PHY_TYPE_1000BASE_KX:
  359. break;
  360. default:
  361. /* if we got here and link is up something bad is afoot */
  362. netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
  363. hw_link_info->phy_type);
  364. }
  365. /* Set speed and duplex */
  366. switch (link_speed) {
  367. case I40E_LINK_SPEED_40GB:
  368. ethtool_cmd_speed_set(ecmd, SPEED_40000);
  369. break;
  370. case I40E_LINK_SPEED_20GB:
  371. ethtool_cmd_speed_set(ecmd, SPEED_20000);
  372. break;
  373. case I40E_LINK_SPEED_10GB:
  374. ethtool_cmd_speed_set(ecmd, SPEED_10000);
  375. break;
  376. case I40E_LINK_SPEED_1GB:
  377. ethtool_cmd_speed_set(ecmd, SPEED_1000);
  378. break;
  379. case I40E_LINK_SPEED_100MB:
  380. ethtool_cmd_speed_set(ecmd, SPEED_100);
  381. break;
  382. default:
  383. break;
  384. }
  385. ecmd->duplex = DUPLEX_FULL;
  386. }
  387. /**
  388. * i40e_get_settings_link_down - Get the Link settings for when link is down
  389. * @hw: hw structure
  390. * @ecmd: ethtool command to fill in
  391. *
  392. * Reports link settings that can be determined when link is down
  393. **/
  394. static void i40e_get_settings_link_down(struct i40e_hw *hw,
  395. struct ethtool_cmd *ecmd,
  396. struct i40e_pf *pf)
  397. {
  398. enum i40e_aq_capabilities_phy_type phy_types = hw->phy.phy_types;
  399. /* link is down and the driver needs to fall back on
  400. * supported phy types to figure out what info to display
  401. */
  402. ecmd->supported = 0x0;
  403. ecmd->advertising = 0x0;
  404. if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
  405. ecmd->supported |= SUPPORTED_Autoneg |
  406. SUPPORTED_1000baseT_Full;
  407. ecmd->advertising |= ADVERTISED_Autoneg |
  408. ADVERTISED_1000baseT_Full;
  409. if (pf->hw.mac.type == I40E_MAC_X722) {
  410. ecmd->supported |= SUPPORTED_100baseT_Full;
  411. ecmd->advertising |= ADVERTISED_100baseT_Full;
  412. if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
  413. ecmd->supported |= SUPPORTED_100baseT_Full;
  414. ecmd->advertising |= ADVERTISED_100baseT_Full;
  415. }
  416. }
  417. }
  418. if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
  419. phy_types & I40E_CAP_PHY_TYPE_XFI ||
  420. phy_types & I40E_CAP_PHY_TYPE_SFI ||
  421. phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
  422. phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
  423. ecmd->supported |= SUPPORTED_10000baseT_Full;
  424. if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
  425. phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
  426. phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
  427. phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
  428. phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
  429. ecmd->supported |= SUPPORTED_Autoneg |
  430. SUPPORTED_10000baseT_Full;
  431. ecmd->advertising |= ADVERTISED_Autoneg |
  432. ADVERTISED_10000baseT_Full;
  433. }
  434. if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
  435. phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
  436. phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
  437. ecmd->supported |= SUPPORTED_40000baseCR4_Full;
  438. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
  439. phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
  440. ecmd->supported |= SUPPORTED_Autoneg |
  441. SUPPORTED_40000baseCR4_Full;
  442. ecmd->advertising |= ADVERTISED_Autoneg |
  443. ADVERTISED_40000baseCR4_Full;
  444. }
  445. if ((phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) &&
  446. !(phy_types & I40E_CAP_PHY_TYPE_1000BASE_T)) {
  447. ecmd->supported |= SUPPORTED_Autoneg |
  448. SUPPORTED_100baseT_Full;
  449. ecmd->advertising |= ADVERTISED_Autoneg |
  450. ADVERTISED_100baseT_Full;
  451. }
  452. if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
  453. phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
  454. phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
  455. phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
  456. ecmd->supported |= SUPPORTED_Autoneg |
  457. SUPPORTED_1000baseT_Full;
  458. ecmd->advertising |= ADVERTISED_Autoneg |
  459. ADVERTISED_1000baseT_Full;
  460. }
  461. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
  462. ecmd->supported |= SUPPORTED_40000baseSR4_Full;
  463. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
  464. ecmd->supported |= SUPPORTED_40000baseLR4_Full;
  465. /* With no link speed and duplex are unknown */
  466. ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
  467. ecmd->duplex = DUPLEX_UNKNOWN;
  468. }
  469. /**
  470. * i40e_get_settings - Get Link Speed and Duplex settings
  471. * @netdev: network interface device structure
  472. * @ecmd: ethtool command
  473. *
  474. * Reports speed/duplex settings based on media_type
  475. **/
  476. static int i40e_get_settings(struct net_device *netdev,
  477. struct ethtool_cmd *ecmd)
  478. {
  479. struct i40e_netdev_priv *np = netdev_priv(netdev);
  480. struct i40e_pf *pf = np->vsi->back;
  481. struct i40e_hw *hw = &pf->hw;
  482. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  483. bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
  484. if (link_up)
  485. i40e_get_settings_link_up(hw, ecmd, netdev, pf);
  486. else
  487. i40e_get_settings_link_down(hw, ecmd, pf);
  488. /* Now set the settings that don't rely on link being up/down */
  489. /* For backplane, supported and advertised are only reliant on the
  490. * phy types the NVM specifies are supported.
  491. */
  492. if (hw->device_id == I40E_DEV_ID_KX_B ||
  493. hw->device_id == I40E_DEV_ID_KX_C ||
  494. hw->device_id == I40E_DEV_ID_20G_KR2 ||
  495. hw->device_id == I40E_DEV_ID_20G_KR2_A) {
  496. ecmd->supported = SUPPORTED_Autoneg;
  497. ecmd->advertising = ADVERTISED_Autoneg;
  498. if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
  499. ecmd->supported |= SUPPORTED_40000baseKR4_Full;
  500. ecmd->advertising |= ADVERTISED_40000baseKR4_Full;
  501. }
  502. if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
  503. ecmd->supported |= SUPPORTED_20000baseKR2_Full;
  504. ecmd->advertising |= ADVERTISED_20000baseKR2_Full;
  505. }
  506. if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
  507. ecmd->supported |= SUPPORTED_10000baseKR_Full;
  508. ecmd->advertising |= ADVERTISED_10000baseKR_Full;
  509. }
  510. if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
  511. ecmd->supported |= SUPPORTED_10000baseKX4_Full;
  512. ecmd->advertising |= ADVERTISED_10000baseKX4_Full;
  513. }
  514. if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
  515. ecmd->supported |= SUPPORTED_1000baseKX_Full;
  516. ecmd->advertising |= ADVERTISED_1000baseKX_Full;
  517. }
  518. }
  519. /* Set autoneg settings */
  520. ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  521. AUTONEG_ENABLE : AUTONEG_DISABLE);
  522. switch (hw->phy.media_type) {
  523. case I40E_MEDIA_TYPE_BACKPLANE:
  524. ecmd->supported |= SUPPORTED_Autoneg |
  525. SUPPORTED_Backplane;
  526. ecmd->advertising |= ADVERTISED_Autoneg |
  527. ADVERTISED_Backplane;
  528. ecmd->port = PORT_NONE;
  529. break;
  530. case I40E_MEDIA_TYPE_BASET:
  531. ecmd->supported |= SUPPORTED_TP;
  532. ecmd->advertising |= ADVERTISED_TP;
  533. ecmd->port = PORT_TP;
  534. break;
  535. case I40E_MEDIA_TYPE_DA:
  536. case I40E_MEDIA_TYPE_CX4:
  537. ecmd->supported |= SUPPORTED_FIBRE;
  538. ecmd->advertising |= ADVERTISED_FIBRE;
  539. ecmd->port = PORT_DA;
  540. break;
  541. case I40E_MEDIA_TYPE_FIBER:
  542. ecmd->supported |= SUPPORTED_FIBRE;
  543. ecmd->port = PORT_FIBRE;
  544. break;
  545. case I40E_MEDIA_TYPE_UNKNOWN:
  546. default:
  547. ecmd->port = PORT_OTHER;
  548. break;
  549. }
  550. /* Set transceiver */
  551. ecmd->transceiver = XCVR_EXTERNAL;
  552. /* Set flow control settings */
  553. ecmd->supported |= SUPPORTED_Pause;
  554. switch (hw->fc.requested_mode) {
  555. case I40E_FC_FULL:
  556. ecmd->advertising |= ADVERTISED_Pause;
  557. break;
  558. case I40E_FC_TX_PAUSE:
  559. ecmd->advertising |= ADVERTISED_Asym_Pause;
  560. break;
  561. case I40E_FC_RX_PAUSE:
  562. ecmd->advertising |= (ADVERTISED_Pause |
  563. ADVERTISED_Asym_Pause);
  564. break;
  565. default:
  566. ecmd->advertising &= ~(ADVERTISED_Pause |
  567. ADVERTISED_Asym_Pause);
  568. break;
  569. }
  570. return 0;
  571. }
  572. /**
  573. * i40e_set_settings - Set Speed and Duplex
  574. * @netdev: network interface device structure
  575. * @ecmd: ethtool command
  576. *
  577. * Set speed/duplex per media_types advertised/forced
  578. **/
  579. static int i40e_set_settings(struct net_device *netdev,
  580. struct ethtool_cmd *ecmd)
  581. {
  582. struct i40e_netdev_priv *np = netdev_priv(netdev);
  583. struct i40e_aq_get_phy_abilities_resp abilities;
  584. struct i40e_aq_set_phy_config config;
  585. struct i40e_pf *pf = np->vsi->back;
  586. struct i40e_vsi *vsi = np->vsi;
  587. struct i40e_hw *hw = &pf->hw;
  588. struct ethtool_cmd safe_ecmd;
  589. i40e_status status = 0;
  590. bool change = false;
  591. int err = 0;
  592. u8 autoneg;
  593. u32 advertise;
  594. /* Changing port settings is not supported if this isn't the
  595. * port's controlling PF
  596. */
  597. if (hw->partition_id != 1) {
  598. i40e_partition_setting_complaint(pf);
  599. return -EOPNOTSUPP;
  600. }
  601. if (vsi != pf->vsi[pf->lan_vsi])
  602. return -EOPNOTSUPP;
  603. if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
  604. hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
  605. hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
  606. hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
  607. return -EOPNOTSUPP;
  608. if (hw->device_id == I40E_DEV_ID_KX_B ||
  609. hw->device_id == I40E_DEV_ID_KX_C ||
  610. hw->device_id == I40E_DEV_ID_20G_KR2 ||
  611. hw->device_id == I40E_DEV_ID_20G_KR2_A) {
  612. netdev_info(netdev, "Changing settings is not supported on backplane.\n");
  613. return -EOPNOTSUPP;
  614. }
  615. /* get our own copy of the bits to check against */
  616. memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
  617. i40e_get_settings(netdev, &safe_ecmd);
  618. /* save autoneg and speed out of ecmd */
  619. autoneg = ecmd->autoneg;
  620. advertise = ecmd->advertising;
  621. /* set autoneg and speed back to what they currently are */
  622. ecmd->autoneg = safe_ecmd.autoneg;
  623. ecmd->advertising = safe_ecmd.advertising;
  624. ecmd->cmd = safe_ecmd.cmd;
  625. /* If ecmd and safe_ecmd are not the same now, then they are
  626. * trying to set something that we do not support
  627. */
  628. if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
  629. return -EOPNOTSUPP;
  630. while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
  631. usleep_range(1000, 2000);
  632. /* Get the current phy config */
  633. status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
  634. NULL);
  635. if (status)
  636. return -EAGAIN;
  637. /* Copy abilities to config in case autoneg is not
  638. * set below
  639. */
  640. memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
  641. config.abilities = abilities.abilities;
  642. /* Check autoneg */
  643. if (autoneg == AUTONEG_ENABLE) {
  644. /* If autoneg was not already enabled */
  645. if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
  646. /* If autoneg is not supported, return error */
  647. if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
  648. netdev_info(netdev, "Autoneg not supported on this phy\n");
  649. return -EINVAL;
  650. }
  651. /* Autoneg is allowed to change */
  652. config.abilities = abilities.abilities |
  653. I40E_AQ_PHY_ENABLE_AN;
  654. change = true;
  655. }
  656. } else {
  657. /* If autoneg is currently enabled */
  658. if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
  659. /* If autoneg is supported 10GBASE_T is the only PHY
  660. * that can disable it, so otherwise return error
  661. */
  662. if (safe_ecmd.supported & SUPPORTED_Autoneg &&
  663. hw->phy.link_info.phy_type !=
  664. I40E_PHY_TYPE_10GBASE_T) {
  665. netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
  666. return -EINVAL;
  667. }
  668. /* Autoneg is allowed to change */
  669. config.abilities = abilities.abilities &
  670. ~I40E_AQ_PHY_ENABLE_AN;
  671. change = true;
  672. }
  673. }
  674. if (advertise & ~safe_ecmd.supported)
  675. return -EINVAL;
  676. if (advertise & ADVERTISED_100baseT_Full)
  677. config.link_speed |= I40E_LINK_SPEED_100MB;
  678. if (advertise & ADVERTISED_1000baseT_Full ||
  679. advertise & ADVERTISED_1000baseKX_Full)
  680. config.link_speed |= I40E_LINK_SPEED_1GB;
  681. if (advertise & ADVERTISED_10000baseT_Full ||
  682. advertise & ADVERTISED_10000baseKX4_Full ||
  683. advertise & ADVERTISED_10000baseKR_Full)
  684. config.link_speed |= I40E_LINK_SPEED_10GB;
  685. if (advertise & ADVERTISED_20000baseKR2_Full)
  686. config.link_speed |= I40E_LINK_SPEED_20GB;
  687. if (advertise & ADVERTISED_40000baseKR4_Full ||
  688. advertise & ADVERTISED_40000baseCR4_Full ||
  689. advertise & ADVERTISED_40000baseSR4_Full ||
  690. advertise & ADVERTISED_40000baseLR4_Full)
  691. config.link_speed |= I40E_LINK_SPEED_40GB;
  692. /* If speed didn't get set, set it to what it currently is.
  693. * This is needed because if advertise is 0 (as it is when autoneg
  694. * is disabled) then speed won't get set.
  695. */
  696. if (!config.link_speed)
  697. config.link_speed = abilities.link_speed;
  698. if (change || (abilities.link_speed != config.link_speed)) {
  699. /* copy over the rest of the abilities */
  700. config.phy_type = abilities.phy_type;
  701. config.eee_capability = abilities.eee_capability;
  702. config.eeer = abilities.eeer_val;
  703. config.low_power_ctrl = abilities.d3_lpan;
  704. /* save the requested speeds */
  705. hw->phy.link_info.requested_speeds = config.link_speed;
  706. /* set link and auto negotiation so changes take effect */
  707. config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
  708. /* If link is up put link down */
  709. if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
  710. /* Tell the OS link is going down, the link will go
  711. * back up when fw says it is ready asynchronously
  712. */
  713. i40e_print_link_message(vsi, false);
  714. netif_carrier_off(netdev);
  715. netif_tx_stop_all_queues(netdev);
  716. }
  717. /* make the aq call */
  718. status = i40e_aq_set_phy_config(hw, &config, NULL);
  719. if (status) {
  720. netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
  721. i40e_stat_str(hw, status),
  722. i40e_aq_str(hw, hw->aq.asq_last_status));
  723. return -EAGAIN;
  724. }
  725. status = i40e_update_link_info(hw);
  726. if (status)
  727. netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
  728. i40e_stat_str(hw, status),
  729. i40e_aq_str(hw, hw->aq.asq_last_status));
  730. } else {
  731. netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
  732. }
  733. return err;
  734. }
  735. static int i40e_nway_reset(struct net_device *netdev)
  736. {
  737. /* restart autonegotiation */
  738. struct i40e_netdev_priv *np = netdev_priv(netdev);
  739. struct i40e_pf *pf = np->vsi->back;
  740. struct i40e_hw *hw = &pf->hw;
  741. bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
  742. i40e_status ret = 0;
  743. ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
  744. if (ret) {
  745. netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
  746. i40e_stat_str(hw, ret),
  747. i40e_aq_str(hw, hw->aq.asq_last_status));
  748. return -EIO;
  749. }
  750. return 0;
  751. }
  752. /**
  753. * i40e_get_pauseparam - Get Flow Control status
  754. * Return tx/rx-pause status
  755. **/
  756. static void i40e_get_pauseparam(struct net_device *netdev,
  757. struct ethtool_pauseparam *pause)
  758. {
  759. struct i40e_netdev_priv *np = netdev_priv(netdev);
  760. struct i40e_pf *pf = np->vsi->back;
  761. struct i40e_hw *hw = &pf->hw;
  762. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  763. struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
  764. pause->autoneg =
  765. ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  766. AUTONEG_ENABLE : AUTONEG_DISABLE);
  767. /* PFC enabled so report LFC as off */
  768. if (dcbx_cfg->pfc.pfcenable) {
  769. pause->rx_pause = 0;
  770. pause->tx_pause = 0;
  771. return;
  772. }
  773. if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
  774. pause->rx_pause = 1;
  775. } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
  776. pause->tx_pause = 1;
  777. } else if (hw->fc.current_mode == I40E_FC_FULL) {
  778. pause->rx_pause = 1;
  779. pause->tx_pause = 1;
  780. }
  781. }
  782. /**
  783. * i40e_set_pauseparam - Set Flow Control parameter
  784. * @netdev: network interface device structure
  785. * @pause: return tx/rx flow control status
  786. **/
  787. static int i40e_set_pauseparam(struct net_device *netdev,
  788. struct ethtool_pauseparam *pause)
  789. {
  790. struct i40e_netdev_priv *np = netdev_priv(netdev);
  791. struct i40e_pf *pf = np->vsi->back;
  792. struct i40e_vsi *vsi = np->vsi;
  793. struct i40e_hw *hw = &pf->hw;
  794. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  795. struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
  796. bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
  797. i40e_status status;
  798. u8 aq_failures;
  799. int err = 0;
  800. /* Changing the port's flow control is not supported if this isn't the
  801. * port's controlling PF
  802. */
  803. if (hw->partition_id != 1) {
  804. i40e_partition_setting_complaint(pf);
  805. return -EOPNOTSUPP;
  806. }
  807. if (vsi != pf->vsi[pf->lan_vsi])
  808. return -EOPNOTSUPP;
  809. if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  810. AUTONEG_ENABLE : AUTONEG_DISABLE)) {
  811. netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
  812. return -EOPNOTSUPP;
  813. }
  814. /* If we have link and don't have autoneg */
  815. if (!test_bit(__I40E_DOWN, &pf->state) &&
  816. !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
  817. /* Send message that it might not necessarily work*/
  818. netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
  819. }
  820. if (dcbx_cfg->pfc.pfcenable) {
  821. netdev_info(netdev,
  822. "Priority flow control enabled. Cannot set link flow control.\n");
  823. return -EOPNOTSUPP;
  824. }
  825. if (pause->rx_pause && pause->tx_pause)
  826. hw->fc.requested_mode = I40E_FC_FULL;
  827. else if (pause->rx_pause && !pause->tx_pause)
  828. hw->fc.requested_mode = I40E_FC_RX_PAUSE;
  829. else if (!pause->rx_pause && pause->tx_pause)
  830. hw->fc.requested_mode = I40E_FC_TX_PAUSE;
  831. else if (!pause->rx_pause && !pause->tx_pause)
  832. hw->fc.requested_mode = I40E_FC_NONE;
  833. else
  834. return -EINVAL;
  835. /* Tell the OS link is going down, the link will go back up when fw
  836. * says it is ready asynchronously
  837. */
  838. i40e_print_link_message(vsi, false);
  839. netif_carrier_off(netdev);
  840. netif_tx_stop_all_queues(netdev);
  841. /* Set the fc mode and only restart an if link is up*/
  842. status = i40e_set_fc(hw, &aq_failures, link_up);
  843. if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
  844. netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
  845. i40e_stat_str(hw, status),
  846. i40e_aq_str(hw, hw->aq.asq_last_status));
  847. err = -EAGAIN;
  848. }
  849. if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
  850. netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
  851. i40e_stat_str(hw, status),
  852. i40e_aq_str(hw, hw->aq.asq_last_status));
  853. err = -EAGAIN;
  854. }
  855. if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
  856. netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
  857. i40e_stat_str(hw, status),
  858. i40e_aq_str(hw, hw->aq.asq_last_status));
  859. err = -EAGAIN;
  860. }
  861. if (!test_bit(__I40E_DOWN, &pf->state)) {
  862. /* Give it a little more time to try to come back */
  863. msleep(75);
  864. if (!test_bit(__I40E_DOWN, &pf->state))
  865. return i40e_nway_reset(netdev);
  866. }
  867. return err;
  868. }
  869. static u32 i40e_get_msglevel(struct net_device *netdev)
  870. {
  871. struct i40e_netdev_priv *np = netdev_priv(netdev);
  872. struct i40e_pf *pf = np->vsi->back;
  873. return pf->msg_enable;
  874. }
  875. static void i40e_set_msglevel(struct net_device *netdev, u32 data)
  876. {
  877. struct i40e_netdev_priv *np = netdev_priv(netdev);
  878. struct i40e_pf *pf = np->vsi->back;
  879. if (I40E_DEBUG_USER & data)
  880. pf->hw.debug_mask = data;
  881. pf->msg_enable = data;
  882. }
  883. static int i40e_get_regs_len(struct net_device *netdev)
  884. {
  885. int reg_count = 0;
  886. int i;
  887. for (i = 0; i40e_reg_list[i].offset != 0; i++)
  888. reg_count += i40e_reg_list[i].elements;
  889. return reg_count * sizeof(u32);
  890. }
  891. static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
  892. void *p)
  893. {
  894. struct i40e_netdev_priv *np = netdev_priv(netdev);
  895. struct i40e_pf *pf = np->vsi->back;
  896. struct i40e_hw *hw = &pf->hw;
  897. u32 *reg_buf = p;
  898. int i, j, ri;
  899. u32 reg;
  900. /* Tell ethtool which driver-version-specific regs output we have.
  901. *
  902. * At some point, if we have ethtool doing special formatting of
  903. * this data, it will rely on this version number to know how to
  904. * interpret things. Hence, this needs to be updated if/when the
  905. * diags register table is changed.
  906. */
  907. regs->version = 1;
  908. /* loop through the diags reg table for what to print */
  909. ri = 0;
  910. for (i = 0; i40e_reg_list[i].offset != 0; i++) {
  911. for (j = 0; j < i40e_reg_list[i].elements; j++) {
  912. reg = i40e_reg_list[i].offset
  913. + (j * i40e_reg_list[i].stride);
  914. reg_buf[ri++] = rd32(hw, reg);
  915. }
  916. }
  917. }
  918. static int i40e_get_eeprom(struct net_device *netdev,
  919. struct ethtool_eeprom *eeprom, u8 *bytes)
  920. {
  921. struct i40e_netdev_priv *np = netdev_priv(netdev);
  922. struct i40e_hw *hw = &np->vsi->back->hw;
  923. struct i40e_pf *pf = np->vsi->back;
  924. int ret_val = 0, len, offset;
  925. u8 *eeprom_buff;
  926. u16 i, sectors;
  927. bool last;
  928. u32 magic;
  929. #define I40E_NVM_SECTOR_SIZE 4096
  930. if (eeprom->len == 0)
  931. return -EINVAL;
  932. /* check for NVMUpdate access method */
  933. magic = hw->vendor_id | (hw->device_id << 16);
  934. if (eeprom->magic && eeprom->magic != magic) {
  935. struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
  936. int errno = 0;
  937. /* make sure it is the right magic for NVMUpdate */
  938. if ((eeprom->magic >> 16) != hw->device_id)
  939. errno = -EINVAL;
  940. else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  941. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  942. errno = -EBUSY;
  943. else
  944. ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
  945. if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
  946. dev_info(&pf->pdev->dev,
  947. "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
  948. ret_val, hw->aq.asq_last_status, errno,
  949. (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
  950. cmd->offset, cmd->data_size);
  951. return errno;
  952. }
  953. /* normal ethtool get_eeprom support */
  954. eeprom->magic = hw->vendor_id | (hw->device_id << 16);
  955. eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
  956. if (!eeprom_buff)
  957. return -ENOMEM;
  958. ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
  959. if (ret_val) {
  960. dev_info(&pf->pdev->dev,
  961. "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
  962. ret_val, hw->aq.asq_last_status);
  963. goto free_buff;
  964. }
  965. sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
  966. sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
  967. len = I40E_NVM_SECTOR_SIZE;
  968. last = false;
  969. for (i = 0; i < sectors; i++) {
  970. if (i == (sectors - 1)) {
  971. len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
  972. last = true;
  973. }
  974. offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
  975. ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
  976. (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
  977. last, NULL);
  978. if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
  979. dev_info(&pf->pdev->dev,
  980. "read NVM failed, invalid offset 0x%x\n",
  981. offset);
  982. break;
  983. } else if (ret_val &&
  984. hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
  985. dev_info(&pf->pdev->dev,
  986. "read NVM failed, access, offset 0x%x\n",
  987. offset);
  988. break;
  989. } else if (ret_val) {
  990. dev_info(&pf->pdev->dev,
  991. "read NVM failed offset %d err=%d status=0x%x\n",
  992. offset, ret_val, hw->aq.asq_last_status);
  993. break;
  994. }
  995. }
  996. i40e_release_nvm(hw);
  997. memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
  998. free_buff:
  999. kfree(eeprom_buff);
  1000. return ret_val;
  1001. }
  1002. static int i40e_get_eeprom_len(struct net_device *netdev)
  1003. {
  1004. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1005. struct i40e_hw *hw = &np->vsi->back->hw;
  1006. u32 val;
  1007. val = (rd32(hw, I40E_GLPCI_LBARCTRL)
  1008. & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
  1009. >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
  1010. /* register returns value in power of 2, 64Kbyte chunks. */
  1011. val = (64 * 1024) * BIT(val);
  1012. return val;
  1013. }
  1014. static int i40e_set_eeprom(struct net_device *netdev,
  1015. struct ethtool_eeprom *eeprom, u8 *bytes)
  1016. {
  1017. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1018. struct i40e_hw *hw = &np->vsi->back->hw;
  1019. struct i40e_pf *pf = np->vsi->back;
  1020. struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
  1021. int ret_val = 0;
  1022. int errno = 0;
  1023. u32 magic;
  1024. /* normal ethtool set_eeprom is not supported */
  1025. magic = hw->vendor_id | (hw->device_id << 16);
  1026. if (eeprom->magic == magic)
  1027. errno = -EOPNOTSUPP;
  1028. /* check for NVMUpdate access method */
  1029. else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
  1030. errno = -EINVAL;
  1031. else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  1032. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  1033. errno = -EBUSY;
  1034. else
  1035. ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
  1036. if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
  1037. dev_info(&pf->pdev->dev,
  1038. "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
  1039. ret_val, hw->aq.asq_last_status, errno,
  1040. (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
  1041. cmd->offset, cmd->data_size);
  1042. return errno;
  1043. }
  1044. static void i40e_get_drvinfo(struct net_device *netdev,
  1045. struct ethtool_drvinfo *drvinfo)
  1046. {
  1047. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1048. struct i40e_vsi *vsi = np->vsi;
  1049. struct i40e_pf *pf = vsi->back;
  1050. strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
  1051. strlcpy(drvinfo->version, i40e_driver_version_str,
  1052. sizeof(drvinfo->version));
  1053. strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
  1054. sizeof(drvinfo->fw_version));
  1055. strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
  1056. sizeof(drvinfo->bus_info));
  1057. }
  1058. static void i40e_get_ringparam(struct net_device *netdev,
  1059. struct ethtool_ringparam *ring)
  1060. {
  1061. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1062. struct i40e_pf *pf = np->vsi->back;
  1063. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  1064. ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  1065. ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  1066. ring->rx_mini_max_pending = 0;
  1067. ring->rx_jumbo_max_pending = 0;
  1068. ring->rx_pending = vsi->rx_rings[0]->count;
  1069. ring->tx_pending = vsi->tx_rings[0]->count;
  1070. ring->rx_mini_pending = 0;
  1071. ring->rx_jumbo_pending = 0;
  1072. }
  1073. static int i40e_set_ringparam(struct net_device *netdev,
  1074. struct ethtool_ringparam *ring)
  1075. {
  1076. struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
  1077. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1078. struct i40e_vsi *vsi = np->vsi;
  1079. struct i40e_pf *pf = vsi->back;
  1080. u32 new_rx_count, new_tx_count;
  1081. int i, err = 0;
  1082. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  1083. return -EINVAL;
  1084. if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  1085. ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
  1086. ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  1087. ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
  1088. netdev_info(netdev,
  1089. "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
  1090. ring->tx_pending, ring->rx_pending,
  1091. I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
  1092. return -EINVAL;
  1093. }
  1094. new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  1095. new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  1096. /* if nothing to do return success */
  1097. if ((new_tx_count == vsi->tx_rings[0]->count) &&
  1098. (new_rx_count == vsi->rx_rings[0]->count))
  1099. return 0;
  1100. while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
  1101. usleep_range(1000, 2000);
  1102. if (!netif_running(vsi->netdev)) {
  1103. /* simple case - set for the next time the netdev is started */
  1104. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1105. vsi->tx_rings[i]->count = new_tx_count;
  1106. vsi->rx_rings[i]->count = new_rx_count;
  1107. }
  1108. goto done;
  1109. }
  1110. /* We can't just free everything and then setup again,
  1111. * because the ISRs in MSI-X mode get passed pointers
  1112. * to the Tx and Rx ring structs.
  1113. */
  1114. /* alloc updated Tx resources */
  1115. if (new_tx_count != vsi->tx_rings[0]->count) {
  1116. netdev_info(netdev,
  1117. "Changing Tx descriptor count from %d to %d.\n",
  1118. vsi->tx_rings[0]->count, new_tx_count);
  1119. tx_rings = kcalloc(vsi->alloc_queue_pairs,
  1120. sizeof(struct i40e_ring), GFP_KERNEL);
  1121. if (!tx_rings) {
  1122. err = -ENOMEM;
  1123. goto done;
  1124. }
  1125. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1126. /* clone ring and setup updated count */
  1127. tx_rings[i] = *vsi->tx_rings[i];
  1128. tx_rings[i].count = new_tx_count;
  1129. /* the desc and bi pointers will be reallocated in the
  1130. * setup call
  1131. */
  1132. tx_rings[i].desc = NULL;
  1133. tx_rings[i].rx_bi = NULL;
  1134. err = i40e_setup_tx_descriptors(&tx_rings[i]);
  1135. if (err) {
  1136. while (i) {
  1137. i--;
  1138. i40e_free_tx_resources(&tx_rings[i]);
  1139. }
  1140. kfree(tx_rings);
  1141. tx_rings = NULL;
  1142. goto done;
  1143. }
  1144. }
  1145. }
  1146. /* alloc updated Rx resources */
  1147. if (new_rx_count != vsi->rx_rings[0]->count) {
  1148. netdev_info(netdev,
  1149. "Changing Rx descriptor count from %d to %d\n",
  1150. vsi->rx_rings[0]->count, new_rx_count);
  1151. rx_rings = kcalloc(vsi->alloc_queue_pairs,
  1152. sizeof(struct i40e_ring), GFP_KERNEL);
  1153. if (!rx_rings) {
  1154. err = -ENOMEM;
  1155. goto free_tx;
  1156. }
  1157. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1158. /* clone ring and setup updated count */
  1159. rx_rings[i] = *vsi->rx_rings[i];
  1160. rx_rings[i].count = new_rx_count;
  1161. /* the desc and bi pointers will be reallocated in the
  1162. * setup call
  1163. */
  1164. rx_rings[i].desc = NULL;
  1165. rx_rings[i].rx_bi = NULL;
  1166. err = i40e_setup_rx_descriptors(&rx_rings[i]);
  1167. if (err) {
  1168. while (i) {
  1169. i--;
  1170. i40e_free_rx_resources(&rx_rings[i]);
  1171. }
  1172. kfree(rx_rings);
  1173. rx_rings = NULL;
  1174. goto free_tx;
  1175. }
  1176. }
  1177. }
  1178. /* Bring interface down, copy in the new ring info,
  1179. * then restore the interface
  1180. */
  1181. i40e_down(vsi);
  1182. if (tx_rings) {
  1183. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1184. i40e_free_tx_resources(vsi->tx_rings[i]);
  1185. *vsi->tx_rings[i] = tx_rings[i];
  1186. }
  1187. kfree(tx_rings);
  1188. tx_rings = NULL;
  1189. }
  1190. if (rx_rings) {
  1191. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1192. i40e_free_rx_resources(vsi->rx_rings[i]);
  1193. *vsi->rx_rings[i] = rx_rings[i];
  1194. }
  1195. kfree(rx_rings);
  1196. rx_rings = NULL;
  1197. }
  1198. i40e_up(vsi);
  1199. free_tx:
  1200. /* error cleanup if the Rx allocations failed after getting Tx */
  1201. if (tx_rings) {
  1202. for (i = 0; i < vsi->num_queue_pairs; i++)
  1203. i40e_free_tx_resources(&tx_rings[i]);
  1204. kfree(tx_rings);
  1205. tx_rings = NULL;
  1206. }
  1207. done:
  1208. clear_bit(__I40E_CONFIG_BUSY, &pf->state);
  1209. return err;
  1210. }
  1211. static int i40e_get_sset_count(struct net_device *netdev, int sset)
  1212. {
  1213. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1214. struct i40e_vsi *vsi = np->vsi;
  1215. struct i40e_pf *pf = vsi->back;
  1216. switch (sset) {
  1217. case ETH_SS_TEST:
  1218. return I40E_TEST_LEN;
  1219. case ETH_SS_STATS:
  1220. if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
  1221. int len = I40E_PF_STATS_LEN(netdev);
  1222. if ((pf->lan_veb != I40E_NO_VEB) &&
  1223. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
  1224. len += I40E_VEB_STATS_TOTAL;
  1225. return len;
  1226. } else {
  1227. return I40E_VSI_STATS_LEN(netdev);
  1228. }
  1229. case ETH_SS_PRIV_FLAGS:
  1230. return I40E_PRIV_FLAGS_STR_LEN;
  1231. default:
  1232. return -EOPNOTSUPP;
  1233. }
  1234. }
  1235. static void i40e_get_ethtool_stats(struct net_device *netdev,
  1236. struct ethtool_stats *stats, u64 *data)
  1237. {
  1238. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1239. struct i40e_ring *tx_ring, *rx_ring;
  1240. struct i40e_vsi *vsi = np->vsi;
  1241. struct i40e_pf *pf = vsi->back;
  1242. int i = 0;
  1243. char *p;
  1244. int j;
  1245. struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
  1246. unsigned int start;
  1247. i40e_update_stats(vsi);
  1248. for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
  1249. p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
  1250. data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
  1251. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1252. }
  1253. for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
  1254. p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
  1255. data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
  1256. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1257. }
  1258. #ifdef I40E_FCOE
  1259. for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
  1260. p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
  1261. data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
  1262. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1263. }
  1264. #endif
  1265. rcu_read_lock();
  1266. for (j = 0; j < vsi->num_queue_pairs; j++) {
  1267. tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
  1268. if (!tx_ring)
  1269. continue;
  1270. /* process Tx ring statistics */
  1271. do {
  1272. start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
  1273. data[i] = tx_ring->stats.packets;
  1274. data[i + 1] = tx_ring->stats.bytes;
  1275. } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
  1276. i += 2;
  1277. /* Rx ring is the 2nd half of the queue pair */
  1278. rx_ring = &tx_ring[1];
  1279. do {
  1280. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  1281. data[i] = rx_ring->stats.packets;
  1282. data[i + 1] = rx_ring->stats.bytes;
  1283. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  1284. i += 2;
  1285. }
  1286. rcu_read_unlock();
  1287. if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
  1288. return;
  1289. if ((pf->lan_veb != I40E_NO_VEB) &&
  1290. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  1291. struct i40e_veb *veb = pf->veb[pf->lan_veb];
  1292. for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
  1293. p = (char *)veb;
  1294. p += i40e_gstrings_veb_stats[j].stat_offset;
  1295. data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
  1296. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1297. }
  1298. for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
  1299. data[i++] = veb->tc_stats.tc_tx_packets[j];
  1300. data[i++] = veb->tc_stats.tc_tx_bytes[j];
  1301. data[i++] = veb->tc_stats.tc_rx_packets[j];
  1302. data[i++] = veb->tc_stats.tc_rx_bytes[j];
  1303. }
  1304. }
  1305. for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
  1306. p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
  1307. data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
  1308. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1309. }
  1310. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  1311. data[i++] = pf->stats.priority_xon_tx[j];
  1312. data[i++] = pf->stats.priority_xoff_tx[j];
  1313. }
  1314. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  1315. data[i++] = pf->stats.priority_xon_rx[j];
  1316. data[i++] = pf->stats.priority_xoff_rx[j];
  1317. }
  1318. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
  1319. data[i++] = pf->stats.priority_xon_2_xoff[j];
  1320. }
  1321. static void i40e_get_strings(struct net_device *netdev, u32 stringset,
  1322. u8 *data)
  1323. {
  1324. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1325. struct i40e_vsi *vsi = np->vsi;
  1326. struct i40e_pf *pf = vsi->back;
  1327. char *p = (char *)data;
  1328. int i;
  1329. switch (stringset) {
  1330. case ETH_SS_TEST:
  1331. for (i = 0; i < I40E_TEST_LEN; i++) {
  1332. memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
  1333. data += ETH_GSTRING_LEN;
  1334. }
  1335. break;
  1336. case ETH_SS_STATS:
  1337. for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
  1338. snprintf(p, ETH_GSTRING_LEN, "%s",
  1339. i40e_gstrings_net_stats[i].stat_string);
  1340. p += ETH_GSTRING_LEN;
  1341. }
  1342. for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
  1343. snprintf(p, ETH_GSTRING_LEN, "%s",
  1344. i40e_gstrings_misc_stats[i].stat_string);
  1345. p += ETH_GSTRING_LEN;
  1346. }
  1347. #ifdef I40E_FCOE
  1348. for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
  1349. snprintf(p, ETH_GSTRING_LEN, "%s",
  1350. i40e_gstrings_fcoe_stats[i].stat_string);
  1351. p += ETH_GSTRING_LEN;
  1352. }
  1353. #endif
  1354. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1355. snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
  1356. p += ETH_GSTRING_LEN;
  1357. snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
  1358. p += ETH_GSTRING_LEN;
  1359. snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
  1360. p += ETH_GSTRING_LEN;
  1361. snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
  1362. p += ETH_GSTRING_LEN;
  1363. }
  1364. if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
  1365. return;
  1366. if ((pf->lan_veb != I40E_NO_VEB) &&
  1367. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  1368. for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
  1369. snprintf(p, ETH_GSTRING_LEN, "veb.%s",
  1370. i40e_gstrings_veb_stats[i].stat_string);
  1371. p += ETH_GSTRING_LEN;
  1372. }
  1373. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1374. snprintf(p, ETH_GSTRING_LEN,
  1375. "veb.tc_%u_tx_packets", i);
  1376. p += ETH_GSTRING_LEN;
  1377. snprintf(p, ETH_GSTRING_LEN,
  1378. "veb.tc_%u_tx_bytes", i);
  1379. p += ETH_GSTRING_LEN;
  1380. snprintf(p, ETH_GSTRING_LEN,
  1381. "veb.tc_%u_rx_packets", i);
  1382. p += ETH_GSTRING_LEN;
  1383. snprintf(p, ETH_GSTRING_LEN,
  1384. "veb.tc_%u_rx_bytes", i);
  1385. p += ETH_GSTRING_LEN;
  1386. }
  1387. }
  1388. for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
  1389. snprintf(p, ETH_GSTRING_LEN, "port.%s",
  1390. i40e_gstrings_stats[i].stat_string);
  1391. p += ETH_GSTRING_LEN;
  1392. }
  1393. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1394. snprintf(p, ETH_GSTRING_LEN,
  1395. "port.tx_priority_%u_xon", i);
  1396. p += ETH_GSTRING_LEN;
  1397. snprintf(p, ETH_GSTRING_LEN,
  1398. "port.tx_priority_%u_xoff", i);
  1399. p += ETH_GSTRING_LEN;
  1400. }
  1401. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1402. snprintf(p, ETH_GSTRING_LEN,
  1403. "port.rx_priority_%u_xon", i);
  1404. p += ETH_GSTRING_LEN;
  1405. snprintf(p, ETH_GSTRING_LEN,
  1406. "port.rx_priority_%u_xoff", i);
  1407. p += ETH_GSTRING_LEN;
  1408. }
  1409. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1410. snprintf(p, ETH_GSTRING_LEN,
  1411. "port.rx_priority_%u_xon_2_xoff", i);
  1412. p += ETH_GSTRING_LEN;
  1413. }
  1414. /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
  1415. break;
  1416. case ETH_SS_PRIV_FLAGS:
  1417. for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
  1418. memcpy(data, i40e_priv_flags_strings[i],
  1419. ETH_GSTRING_LEN);
  1420. data += ETH_GSTRING_LEN;
  1421. }
  1422. break;
  1423. default:
  1424. break;
  1425. }
  1426. }
  1427. static int i40e_get_ts_info(struct net_device *dev,
  1428. struct ethtool_ts_info *info)
  1429. {
  1430. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  1431. /* only report HW timestamping if PTP is enabled */
  1432. if (!(pf->flags & I40E_FLAG_PTP))
  1433. return ethtool_op_get_ts_info(dev, info);
  1434. info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  1435. SOF_TIMESTAMPING_RX_SOFTWARE |
  1436. SOF_TIMESTAMPING_SOFTWARE |
  1437. SOF_TIMESTAMPING_TX_HARDWARE |
  1438. SOF_TIMESTAMPING_RX_HARDWARE |
  1439. SOF_TIMESTAMPING_RAW_HARDWARE;
  1440. if (pf->ptp_clock)
  1441. info->phc_index = ptp_clock_index(pf->ptp_clock);
  1442. else
  1443. info->phc_index = -1;
  1444. info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
  1445. info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
  1446. BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
  1447. BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
  1448. return 0;
  1449. }
  1450. static int i40e_link_test(struct net_device *netdev, u64 *data)
  1451. {
  1452. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1453. struct i40e_pf *pf = np->vsi->back;
  1454. i40e_status status;
  1455. bool link_up = false;
  1456. netif_info(pf, hw, netdev, "link test\n");
  1457. status = i40e_get_link_status(&pf->hw, &link_up);
  1458. if (status) {
  1459. netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
  1460. *data = 1;
  1461. return *data;
  1462. }
  1463. if (link_up)
  1464. *data = 0;
  1465. else
  1466. *data = 1;
  1467. return *data;
  1468. }
  1469. static int i40e_reg_test(struct net_device *netdev, u64 *data)
  1470. {
  1471. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1472. struct i40e_pf *pf = np->vsi->back;
  1473. netif_info(pf, hw, netdev, "register test\n");
  1474. *data = i40e_diag_reg_test(&pf->hw);
  1475. return *data;
  1476. }
  1477. static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
  1478. {
  1479. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1480. struct i40e_pf *pf = np->vsi->back;
  1481. netif_info(pf, hw, netdev, "eeprom test\n");
  1482. *data = i40e_diag_eeprom_test(&pf->hw);
  1483. /* forcebly clear the NVM Update state machine */
  1484. pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
  1485. return *data;
  1486. }
  1487. static int i40e_intr_test(struct net_device *netdev, u64 *data)
  1488. {
  1489. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1490. struct i40e_pf *pf = np->vsi->back;
  1491. u16 swc_old = pf->sw_int_count;
  1492. netif_info(pf, hw, netdev, "interrupt test\n");
  1493. wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
  1494. (I40E_PFINT_DYN_CTL0_INTENA_MASK |
  1495. I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
  1496. I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
  1497. I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
  1498. I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
  1499. usleep_range(1000, 2000);
  1500. *data = (swc_old == pf->sw_int_count);
  1501. return *data;
  1502. }
  1503. static int i40e_loopback_test(struct net_device *netdev, u64 *data)
  1504. {
  1505. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1506. struct i40e_pf *pf = np->vsi->back;
  1507. netif_info(pf, hw, netdev, "loopback test not implemented\n");
  1508. *data = 0;
  1509. return *data;
  1510. }
  1511. static inline bool i40e_active_vfs(struct i40e_pf *pf)
  1512. {
  1513. struct i40e_vf *vfs = pf->vf;
  1514. int i;
  1515. for (i = 0; i < pf->num_alloc_vfs; i++)
  1516. if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
  1517. return true;
  1518. return false;
  1519. }
  1520. static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
  1521. {
  1522. struct i40e_vsi **vsi = pf->vsi;
  1523. int i;
  1524. for (i = 0; i < pf->num_alloc_vsi; i++) {
  1525. if (!vsi[i])
  1526. continue;
  1527. if (vsi[i]->type == I40E_VSI_VMDQ2)
  1528. return true;
  1529. }
  1530. return false;
  1531. }
  1532. static void i40e_diag_test(struct net_device *netdev,
  1533. struct ethtool_test *eth_test, u64 *data)
  1534. {
  1535. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1536. bool if_running = netif_running(netdev);
  1537. struct i40e_pf *pf = np->vsi->back;
  1538. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  1539. /* Offline tests */
  1540. netif_info(pf, drv, netdev, "offline testing starting\n");
  1541. set_bit(__I40E_TESTING, &pf->state);
  1542. if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
  1543. dev_warn(&pf->pdev->dev,
  1544. "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
  1545. data[I40E_ETH_TEST_REG] = 1;
  1546. data[I40E_ETH_TEST_EEPROM] = 1;
  1547. data[I40E_ETH_TEST_INTR] = 1;
  1548. data[I40E_ETH_TEST_LOOPBACK] = 1;
  1549. data[I40E_ETH_TEST_LINK] = 1;
  1550. eth_test->flags |= ETH_TEST_FL_FAILED;
  1551. clear_bit(__I40E_TESTING, &pf->state);
  1552. goto skip_ol_tests;
  1553. }
  1554. /* If the device is online then take it offline */
  1555. if (if_running)
  1556. /* indicate we're in test mode */
  1557. i40e_close(netdev);
  1558. else
  1559. /* This reset does not affect link - if it is
  1560. * changed to a type of reset that does affect
  1561. * link then the following link test would have
  1562. * to be moved to before the reset
  1563. */
  1564. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
  1565. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  1566. eth_test->flags |= ETH_TEST_FL_FAILED;
  1567. if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
  1568. eth_test->flags |= ETH_TEST_FL_FAILED;
  1569. if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
  1570. eth_test->flags |= ETH_TEST_FL_FAILED;
  1571. if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
  1572. eth_test->flags |= ETH_TEST_FL_FAILED;
  1573. /* run reg test last, a reset is required after it */
  1574. if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
  1575. eth_test->flags |= ETH_TEST_FL_FAILED;
  1576. clear_bit(__I40E_TESTING, &pf->state);
  1577. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
  1578. if (if_running)
  1579. i40e_open(netdev);
  1580. } else {
  1581. /* Online tests */
  1582. netif_info(pf, drv, netdev, "online testing starting\n");
  1583. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  1584. eth_test->flags |= ETH_TEST_FL_FAILED;
  1585. /* Offline only tests, not run in online; pass by default */
  1586. data[I40E_ETH_TEST_REG] = 0;
  1587. data[I40E_ETH_TEST_EEPROM] = 0;
  1588. data[I40E_ETH_TEST_INTR] = 0;
  1589. data[I40E_ETH_TEST_LOOPBACK] = 0;
  1590. }
  1591. skip_ol_tests:
  1592. netif_info(pf, drv, netdev, "testing finished\n");
  1593. }
  1594. static void i40e_get_wol(struct net_device *netdev,
  1595. struct ethtool_wolinfo *wol)
  1596. {
  1597. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1598. struct i40e_pf *pf = np->vsi->back;
  1599. struct i40e_hw *hw = &pf->hw;
  1600. u16 wol_nvm_bits;
  1601. /* NVM bit on means WoL disabled for the port */
  1602. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  1603. if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
  1604. wol->supported = 0;
  1605. wol->wolopts = 0;
  1606. } else {
  1607. wol->supported = WAKE_MAGIC;
  1608. wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
  1609. }
  1610. }
  1611. /**
  1612. * i40e_set_wol - set the WakeOnLAN configuration
  1613. * @netdev: the netdev in question
  1614. * @wol: the ethtool WoL setting data
  1615. **/
  1616. static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1617. {
  1618. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1619. struct i40e_pf *pf = np->vsi->back;
  1620. struct i40e_vsi *vsi = np->vsi;
  1621. struct i40e_hw *hw = &pf->hw;
  1622. u16 wol_nvm_bits;
  1623. /* WoL not supported if this isn't the controlling PF on the port */
  1624. if (hw->partition_id != 1) {
  1625. i40e_partition_setting_complaint(pf);
  1626. return -EOPNOTSUPP;
  1627. }
  1628. if (vsi != pf->vsi[pf->lan_vsi])
  1629. return -EOPNOTSUPP;
  1630. /* NVM bit on means WoL disabled for the port */
  1631. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  1632. if (BIT(hw->port) & wol_nvm_bits)
  1633. return -EOPNOTSUPP;
  1634. /* only magic packet is supported */
  1635. if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
  1636. return -EOPNOTSUPP;
  1637. /* is this a new value? */
  1638. if (pf->wol_en != !!wol->wolopts) {
  1639. pf->wol_en = !!wol->wolopts;
  1640. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  1641. }
  1642. return 0;
  1643. }
  1644. static int i40e_set_phys_id(struct net_device *netdev,
  1645. enum ethtool_phys_id_state state)
  1646. {
  1647. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1648. i40e_status ret = 0;
  1649. struct i40e_pf *pf = np->vsi->back;
  1650. struct i40e_hw *hw = &pf->hw;
  1651. int blink_freq = 2;
  1652. u16 temp_status;
  1653. switch (state) {
  1654. case ETHTOOL_ID_ACTIVE:
  1655. if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
  1656. pf->led_status = i40e_led_get(hw);
  1657. } else {
  1658. i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_PORT, NULL);
  1659. ret = i40e_led_get_phy(hw, &temp_status,
  1660. &pf->phy_led_val);
  1661. pf->led_status = temp_status;
  1662. }
  1663. return blink_freq;
  1664. case ETHTOOL_ID_ON:
  1665. if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
  1666. i40e_led_set(hw, 0xf, false);
  1667. else
  1668. ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
  1669. break;
  1670. case ETHTOOL_ID_OFF:
  1671. if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
  1672. i40e_led_set(hw, 0x0, false);
  1673. else
  1674. ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
  1675. break;
  1676. case ETHTOOL_ID_INACTIVE:
  1677. if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
  1678. i40e_led_set(hw, false, pf->led_status);
  1679. } else {
  1680. ret = i40e_led_set_phy(hw, false, pf->led_status,
  1681. (pf->phy_led_val |
  1682. I40E_PHY_LED_MODE_ORIG));
  1683. i40e_aq_set_phy_debug(hw, 0, NULL);
  1684. }
  1685. break;
  1686. default:
  1687. break;
  1688. }
  1689. if (ret)
  1690. return -ENOENT;
  1691. else
  1692. return 0;
  1693. }
  1694. /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
  1695. * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
  1696. * 125us (8000 interrupts per second) == ITR(62)
  1697. */
  1698. static int __i40e_get_coalesce(struct net_device *netdev,
  1699. struct ethtool_coalesce *ec,
  1700. int queue)
  1701. {
  1702. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1703. struct i40e_vsi *vsi = np->vsi;
  1704. ec->tx_max_coalesced_frames_irq = vsi->work_limit;
  1705. ec->rx_max_coalesced_frames_irq = vsi->work_limit;
  1706. /* rx and tx usecs has per queue value. If user doesn't specify the queue,
  1707. * return queue 0's value to represent.
  1708. */
  1709. if (queue < 0) {
  1710. queue = 0;
  1711. } else if (queue >= vsi->num_queue_pairs) {
  1712. return -EINVAL;
  1713. }
  1714. if (ITR_IS_DYNAMIC(vsi->rx_rings[queue]->rx_itr_setting))
  1715. ec->use_adaptive_rx_coalesce = 1;
  1716. if (ITR_IS_DYNAMIC(vsi->tx_rings[queue]->tx_itr_setting))
  1717. ec->use_adaptive_tx_coalesce = 1;
  1718. ec->rx_coalesce_usecs = vsi->rx_rings[queue]->rx_itr_setting & ~I40E_ITR_DYNAMIC;
  1719. ec->tx_coalesce_usecs = vsi->tx_rings[queue]->tx_itr_setting & ~I40E_ITR_DYNAMIC;
  1720. /* we use the _usecs_high to store/set the interrupt rate limit
  1721. * that the hardware supports, that almost but not quite
  1722. * fits the original intent of the ethtool variable,
  1723. * the rx_coalesce_usecs_high limits total interrupts
  1724. * per second from both tx/rx sources.
  1725. */
  1726. ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
  1727. ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
  1728. return 0;
  1729. }
  1730. static int i40e_get_coalesce(struct net_device *netdev,
  1731. struct ethtool_coalesce *ec)
  1732. {
  1733. return __i40e_get_coalesce(netdev, ec, -1);
  1734. }
  1735. static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
  1736. struct ethtool_coalesce *ec)
  1737. {
  1738. return __i40e_get_coalesce(netdev, ec, queue);
  1739. }
  1740. static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
  1741. struct ethtool_coalesce *ec,
  1742. int queue)
  1743. {
  1744. struct i40e_pf *pf = vsi->back;
  1745. struct i40e_hw *hw = &pf->hw;
  1746. struct i40e_q_vector *q_vector;
  1747. u16 vector, intrl;
  1748. intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit);
  1749. vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
  1750. vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
  1751. if (ec->use_adaptive_rx_coalesce)
  1752. vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
  1753. else
  1754. vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
  1755. if (ec->use_adaptive_tx_coalesce)
  1756. vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
  1757. else
  1758. vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
  1759. q_vector = vsi->rx_rings[queue]->q_vector;
  1760. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
  1761. vector = vsi->base_vector + q_vector->v_idx;
  1762. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
  1763. q_vector = vsi->tx_rings[queue]->q_vector;
  1764. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
  1765. vector = vsi->base_vector + q_vector->v_idx;
  1766. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
  1767. wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
  1768. i40e_flush(hw);
  1769. }
  1770. static int __i40e_set_coalesce(struct net_device *netdev,
  1771. struct ethtool_coalesce *ec,
  1772. int queue)
  1773. {
  1774. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1775. struct i40e_vsi *vsi = np->vsi;
  1776. struct i40e_pf *pf = vsi->back;
  1777. int i;
  1778. if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
  1779. vsi->work_limit = ec->tx_max_coalesced_frames_irq;
  1780. /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
  1781. if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
  1782. netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
  1783. return -EINVAL;
  1784. }
  1785. if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
  1786. netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n");
  1787. return -EINVAL;
  1788. }
  1789. if (ec->rx_coalesce_usecs == 0) {
  1790. if (ec->use_adaptive_rx_coalesce)
  1791. netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
  1792. } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  1793. (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
  1794. netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
  1795. return -EINVAL;
  1796. }
  1797. vsi->int_rate_limit = ec->rx_coalesce_usecs_high;
  1798. if (ec->tx_coalesce_usecs == 0) {
  1799. if (ec->use_adaptive_tx_coalesce)
  1800. netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
  1801. } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  1802. (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
  1803. netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
  1804. return -EINVAL;
  1805. }
  1806. /* rx and tx usecs has per queue value. If user doesn't specify the queue,
  1807. * apply to all queues.
  1808. */
  1809. if (queue < 0) {
  1810. for (i = 0; i < vsi->num_queue_pairs; i++)
  1811. i40e_set_itr_per_queue(vsi, ec, i);
  1812. } else if (queue < vsi->num_queue_pairs) {
  1813. i40e_set_itr_per_queue(vsi, ec, queue);
  1814. } else {
  1815. netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
  1816. vsi->num_queue_pairs - 1);
  1817. return -EINVAL;
  1818. }
  1819. return 0;
  1820. }
  1821. static int i40e_set_coalesce(struct net_device *netdev,
  1822. struct ethtool_coalesce *ec)
  1823. {
  1824. return __i40e_set_coalesce(netdev, ec, -1);
  1825. }
  1826. static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
  1827. struct ethtool_coalesce *ec)
  1828. {
  1829. return __i40e_set_coalesce(netdev, ec, queue);
  1830. }
  1831. /**
  1832. * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
  1833. * @pf: pointer to the physical function struct
  1834. * @cmd: ethtool rxnfc command
  1835. *
  1836. * Returns Success if the flow is supported, else Invalid Input.
  1837. **/
  1838. static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
  1839. {
  1840. cmd->data = 0;
  1841. if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
  1842. cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
  1843. cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
  1844. return 0;
  1845. }
  1846. /* Report default options for RSS on i40e */
  1847. switch (cmd->flow_type) {
  1848. case TCP_V4_FLOW:
  1849. case UDP_V4_FLOW:
  1850. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1851. /* fall through to add IP fields */
  1852. case SCTP_V4_FLOW:
  1853. case AH_ESP_V4_FLOW:
  1854. case AH_V4_FLOW:
  1855. case ESP_V4_FLOW:
  1856. case IPV4_FLOW:
  1857. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  1858. break;
  1859. case TCP_V6_FLOW:
  1860. case UDP_V6_FLOW:
  1861. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1862. /* fall through to add IP fields */
  1863. case SCTP_V6_FLOW:
  1864. case AH_ESP_V6_FLOW:
  1865. case AH_V6_FLOW:
  1866. case ESP_V6_FLOW:
  1867. case IPV6_FLOW:
  1868. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  1869. break;
  1870. default:
  1871. return -EINVAL;
  1872. }
  1873. return 0;
  1874. }
  1875. /**
  1876. * i40e_get_ethtool_fdir_all - Populates the rule count of a command
  1877. * @pf: Pointer to the physical function struct
  1878. * @cmd: The command to get or set Rx flow classification rules
  1879. * @rule_locs: Array of used rule locations
  1880. *
  1881. * This function populates both the total and actual rule count of
  1882. * the ethtool flow classification command
  1883. *
  1884. * Returns 0 on success or -EMSGSIZE if entry not found
  1885. **/
  1886. static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
  1887. struct ethtool_rxnfc *cmd,
  1888. u32 *rule_locs)
  1889. {
  1890. struct i40e_fdir_filter *rule;
  1891. struct hlist_node *node2;
  1892. int cnt = 0;
  1893. /* report total rule count */
  1894. cmd->data = i40e_get_fd_cnt_all(pf);
  1895. hlist_for_each_entry_safe(rule, node2,
  1896. &pf->fdir_filter_list, fdir_node) {
  1897. if (cnt == cmd->rule_cnt)
  1898. return -EMSGSIZE;
  1899. rule_locs[cnt] = rule->fd_id;
  1900. cnt++;
  1901. }
  1902. cmd->rule_cnt = cnt;
  1903. return 0;
  1904. }
  1905. /**
  1906. * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
  1907. * @pf: Pointer to the physical function struct
  1908. * @cmd: The command to get or set Rx flow classification rules
  1909. *
  1910. * This function looks up a filter based on the Rx flow classification
  1911. * command and fills the flow spec info for it if found
  1912. *
  1913. * Returns 0 on success or -EINVAL if filter not found
  1914. **/
  1915. static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
  1916. struct ethtool_rxnfc *cmd)
  1917. {
  1918. struct ethtool_rx_flow_spec *fsp =
  1919. (struct ethtool_rx_flow_spec *)&cmd->fs;
  1920. struct i40e_fdir_filter *rule = NULL;
  1921. struct hlist_node *node2;
  1922. hlist_for_each_entry_safe(rule, node2,
  1923. &pf->fdir_filter_list, fdir_node) {
  1924. if (fsp->location <= rule->fd_id)
  1925. break;
  1926. }
  1927. if (!rule || fsp->location != rule->fd_id)
  1928. return -EINVAL;
  1929. fsp->flow_type = rule->flow_type;
  1930. if (fsp->flow_type == IP_USER_FLOW) {
  1931. fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
  1932. fsp->h_u.usr_ip4_spec.proto = 0;
  1933. fsp->m_u.usr_ip4_spec.proto = 0;
  1934. }
  1935. /* Reverse the src and dest notion, since the HW views them from
  1936. * Tx perspective where as the user expects it from Rx filter view.
  1937. */
  1938. fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
  1939. fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
  1940. fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
  1941. fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
  1942. if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
  1943. fsp->ring_cookie = RX_CLS_FLOW_DISC;
  1944. else
  1945. fsp->ring_cookie = rule->q_index;
  1946. if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
  1947. struct i40e_vsi *vsi;
  1948. vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
  1949. if (vsi && vsi->type == I40E_VSI_SRIOV) {
  1950. fsp->h_ext.data[1] = htonl(vsi->vf_id);
  1951. fsp->m_ext.data[1] = htonl(0x1);
  1952. }
  1953. }
  1954. return 0;
  1955. }
  1956. /**
  1957. * i40e_get_rxnfc - command to get RX flow classification rules
  1958. * @netdev: network interface device structure
  1959. * @cmd: ethtool rxnfc command
  1960. *
  1961. * Returns Success if the command is supported.
  1962. **/
  1963. static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
  1964. u32 *rule_locs)
  1965. {
  1966. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1967. struct i40e_vsi *vsi = np->vsi;
  1968. struct i40e_pf *pf = vsi->back;
  1969. int ret = -EOPNOTSUPP;
  1970. switch (cmd->cmd) {
  1971. case ETHTOOL_GRXRINGS:
  1972. cmd->data = vsi->num_queue_pairs;
  1973. ret = 0;
  1974. break;
  1975. case ETHTOOL_GRXFH:
  1976. ret = i40e_get_rss_hash_opts(pf, cmd);
  1977. break;
  1978. case ETHTOOL_GRXCLSRLCNT:
  1979. cmd->rule_cnt = pf->fdir_pf_active_filters;
  1980. /* report total rule count */
  1981. cmd->data = i40e_get_fd_cnt_all(pf);
  1982. ret = 0;
  1983. break;
  1984. case ETHTOOL_GRXCLSRULE:
  1985. ret = i40e_get_ethtool_fdir_entry(pf, cmd);
  1986. break;
  1987. case ETHTOOL_GRXCLSRLALL:
  1988. ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
  1989. break;
  1990. default:
  1991. break;
  1992. }
  1993. return ret;
  1994. }
  1995. /**
  1996. * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
  1997. * @pf: pointer to the physical function struct
  1998. * @cmd: ethtool rxnfc command
  1999. *
  2000. * Returns Success if the flow input set is supported.
  2001. **/
  2002. static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
  2003. {
  2004. struct i40e_hw *hw = &pf->hw;
  2005. u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
  2006. ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
  2007. /* RSS does not support anything other than hashing
  2008. * to queues on src and dst IPs and ports
  2009. */
  2010. if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
  2011. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  2012. return -EINVAL;
  2013. /* We need at least the IP SRC and DEST fields for hashing */
  2014. if (!(nfc->data & RXH_IP_SRC) ||
  2015. !(nfc->data & RXH_IP_DST))
  2016. return -EINVAL;
  2017. switch (nfc->flow_type) {
  2018. case TCP_V4_FLOW:
  2019. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  2020. case 0:
  2021. return -EINVAL;
  2022. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  2023. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2024. hena |=
  2025. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
  2026. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  2027. break;
  2028. default:
  2029. return -EINVAL;
  2030. }
  2031. break;
  2032. case TCP_V6_FLOW:
  2033. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  2034. case 0:
  2035. return -EINVAL;
  2036. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  2037. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2038. hena |=
  2039. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
  2040. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  2041. break;
  2042. default:
  2043. return -EINVAL;
  2044. }
  2045. break;
  2046. case UDP_V4_FLOW:
  2047. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  2048. case 0:
  2049. return -EINVAL;
  2050. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  2051. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2052. hena |=
  2053. BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
  2054. BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
  2055. hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
  2056. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
  2057. break;
  2058. default:
  2059. return -EINVAL;
  2060. }
  2061. break;
  2062. case UDP_V6_FLOW:
  2063. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  2064. case 0:
  2065. return -EINVAL;
  2066. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  2067. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2068. hena |=
  2069. BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
  2070. BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
  2071. hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
  2072. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
  2073. break;
  2074. default:
  2075. return -EINVAL;
  2076. }
  2077. break;
  2078. case AH_ESP_V4_FLOW:
  2079. case AH_V4_FLOW:
  2080. case ESP_V4_FLOW:
  2081. case SCTP_V4_FLOW:
  2082. if ((nfc->data & RXH_L4_B_0_1) ||
  2083. (nfc->data & RXH_L4_B_2_3))
  2084. return -EINVAL;
  2085. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
  2086. break;
  2087. case AH_ESP_V6_FLOW:
  2088. case AH_V6_FLOW:
  2089. case ESP_V6_FLOW:
  2090. case SCTP_V6_FLOW:
  2091. if ((nfc->data & RXH_L4_B_0_1) ||
  2092. (nfc->data & RXH_L4_B_2_3))
  2093. return -EINVAL;
  2094. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
  2095. break;
  2096. case IPV4_FLOW:
  2097. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
  2098. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
  2099. break;
  2100. case IPV6_FLOW:
  2101. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
  2102. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
  2103. break;
  2104. default:
  2105. return -EINVAL;
  2106. }
  2107. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
  2108. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  2109. i40e_flush(hw);
  2110. /* Save setting for future output/update */
  2111. pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
  2112. return 0;
  2113. }
  2114. /**
  2115. * i40e_match_fdir_input_set - Match a new filter against an existing one
  2116. * @rule: The filter already added
  2117. * @input: The new filter to comapre against
  2118. *
  2119. * Returns true if the two input set match
  2120. **/
  2121. static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
  2122. struct i40e_fdir_filter *input)
  2123. {
  2124. if ((rule->dst_ip[0] != input->dst_ip[0]) ||
  2125. (rule->src_ip[0] != input->src_ip[0]) ||
  2126. (rule->dst_port != input->dst_port) ||
  2127. (rule->src_port != input->src_port))
  2128. return false;
  2129. return true;
  2130. }
  2131. /**
  2132. * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
  2133. * @vsi: Pointer to the targeted VSI
  2134. * @input: The filter to update or NULL to indicate deletion
  2135. * @sw_idx: Software index to the filter
  2136. * @cmd: The command to get or set Rx flow classification rules
  2137. *
  2138. * This function updates (or deletes) a Flow Director entry from
  2139. * the hlist of the corresponding PF
  2140. *
  2141. * Returns 0 on success
  2142. **/
  2143. static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
  2144. struct i40e_fdir_filter *input,
  2145. u16 sw_idx,
  2146. struct ethtool_rxnfc *cmd)
  2147. {
  2148. struct i40e_fdir_filter *rule, *parent;
  2149. struct i40e_pf *pf = vsi->back;
  2150. struct hlist_node *node2;
  2151. int err = -EINVAL;
  2152. parent = NULL;
  2153. rule = NULL;
  2154. hlist_for_each_entry_safe(rule, node2,
  2155. &pf->fdir_filter_list, fdir_node) {
  2156. /* hash found, or no matching entry */
  2157. if (rule->fd_id >= sw_idx)
  2158. break;
  2159. parent = rule;
  2160. }
  2161. /* if there is an old rule occupying our place remove it */
  2162. if (rule && (rule->fd_id == sw_idx)) {
  2163. if (input && !i40e_match_fdir_input_set(rule, input))
  2164. err = i40e_add_del_fdir(vsi, rule, false);
  2165. else if (!input)
  2166. err = i40e_add_del_fdir(vsi, rule, false);
  2167. hlist_del(&rule->fdir_node);
  2168. kfree(rule);
  2169. pf->fdir_pf_active_filters--;
  2170. }
  2171. /* If no input this was a delete, err should be 0 if a rule was
  2172. * successfully found and removed from the list else -EINVAL
  2173. */
  2174. if (!input)
  2175. return err;
  2176. /* initialize node and set software index */
  2177. INIT_HLIST_NODE(&input->fdir_node);
  2178. /* add filter to the list */
  2179. if (parent)
  2180. hlist_add_behind(&input->fdir_node, &parent->fdir_node);
  2181. else
  2182. hlist_add_head(&input->fdir_node,
  2183. &pf->fdir_filter_list);
  2184. /* update counts */
  2185. pf->fdir_pf_active_filters++;
  2186. return 0;
  2187. }
  2188. /**
  2189. * i40e_del_fdir_entry - Deletes a Flow Director filter entry
  2190. * @vsi: Pointer to the targeted VSI
  2191. * @cmd: The command to get or set Rx flow classification rules
  2192. *
  2193. * The function removes a Flow Director filter entry from the
  2194. * hlist of the corresponding PF
  2195. *
  2196. * Returns 0 on success
  2197. */
  2198. static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
  2199. struct ethtool_rxnfc *cmd)
  2200. {
  2201. struct ethtool_rx_flow_spec *fsp =
  2202. (struct ethtool_rx_flow_spec *)&cmd->fs;
  2203. struct i40e_pf *pf = vsi->back;
  2204. int ret = 0;
  2205. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  2206. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  2207. return -EBUSY;
  2208. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  2209. return -EBUSY;
  2210. ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
  2211. i40e_fdir_check_and_reenable(pf);
  2212. return ret;
  2213. }
  2214. /**
  2215. * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
  2216. * @vsi: pointer to the targeted VSI
  2217. * @cmd: command to get or set RX flow classification rules
  2218. *
  2219. * Add Flow Director filters for a specific flow spec based on their
  2220. * protocol. Returns 0 if the filters were successfully added.
  2221. **/
  2222. static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
  2223. struct ethtool_rxnfc *cmd)
  2224. {
  2225. struct ethtool_rx_flow_spec *fsp;
  2226. struct i40e_fdir_filter *input;
  2227. struct i40e_pf *pf;
  2228. int ret = -EINVAL;
  2229. u16 vf_id;
  2230. if (!vsi)
  2231. return -EINVAL;
  2232. pf = vsi->back;
  2233. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  2234. return -EOPNOTSUPP;
  2235. if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
  2236. return -ENOSPC;
  2237. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  2238. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  2239. return -EBUSY;
  2240. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  2241. return -EBUSY;
  2242. fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
  2243. if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
  2244. pf->hw.func_caps.fd_filters_guaranteed)) {
  2245. return -EINVAL;
  2246. }
  2247. if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
  2248. (fsp->ring_cookie >= vsi->num_queue_pairs))
  2249. return -EINVAL;
  2250. input = kzalloc(sizeof(*input), GFP_KERNEL);
  2251. if (!input)
  2252. return -ENOMEM;
  2253. input->fd_id = fsp->location;
  2254. if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
  2255. input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
  2256. else
  2257. input->dest_ctl =
  2258. I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
  2259. input->q_index = fsp->ring_cookie;
  2260. input->flex_off = 0;
  2261. input->pctype = 0;
  2262. input->dest_vsi = vsi->id;
  2263. input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
  2264. input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
  2265. input->flow_type = fsp->flow_type;
  2266. input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
  2267. /* Reverse the src and dest notion, since the HW expects them to be from
  2268. * Tx perspective where as the input from user is from Rx filter view.
  2269. */
  2270. input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
  2271. input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
  2272. input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
  2273. input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
  2274. if (ntohl(fsp->m_ext.data[1])) {
  2275. if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
  2276. netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
  2277. goto free_input;
  2278. }
  2279. vf_id = ntohl(fsp->h_ext.data[1]);
  2280. /* Find vsi id from vf id and override dest vsi */
  2281. input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
  2282. if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
  2283. netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
  2284. goto free_input;
  2285. }
  2286. }
  2287. ret = i40e_add_del_fdir(vsi, input, true);
  2288. free_input:
  2289. if (ret)
  2290. kfree(input);
  2291. else
  2292. i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
  2293. return ret;
  2294. }
  2295. /**
  2296. * i40e_set_rxnfc - command to set RX flow classification rules
  2297. * @netdev: network interface device structure
  2298. * @cmd: ethtool rxnfc command
  2299. *
  2300. * Returns Success if the command is supported.
  2301. **/
  2302. static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
  2303. {
  2304. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2305. struct i40e_vsi *vsi = np->vsi;
  2306. struct i40e_pf *pf = vsi->back;
  2307. int ret = -EOPNOTSUPP;
  2308. switch (cmd->cmd) {
  2309. case ETHTOOL_SRXFH:
  2310. ret = i40e_set_rss_hash_opt(pf, cmd);
  2311. break;
  2312. case ETHTOOL_SRXCLSRLINS:
  2313. ret = i40e_add_fdir_ethtool(vsi, cmd);
  2314. break;
  2315. case ETHTOOL_SRXCLSRLDEL:
  2316. ret = i40e_del_fdir_entry(vsi, cmd);
  2317. break;
  2318. default:
  2319. break;
  2320. }
  2321. return ret;
  2322. }
  2323. /**
  2324. * i40e_max_channels - get Max number of combined channels supported
  2325. * @vsi: vsi pointer
  2326. **/
  2327. static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
  2328. {
  2329. /* TODO: This code assumes DCB and FD is disabled for now. */
  2330. return vsi->alloc_queue_pairs;
  2331. }
  2332. /**
  2333. * i40e_get_channels - Get the current channels enabled and max supported etc.
  2334. * @netdev: network interface device structure
  2335. * @ch: ethtool channels structure
  2336. *
  2337. * We don't support separate tx and rx queues as channels. The other count
  2338. * represents how many queues are being used for control. max_combined counts
  2339. * how many queue pairs we can support. They may not be mapped 1 to 1 with
  2340. * q_vectors since we support a lot more queue pairs than q_vectors.
  2341. **/
  2342. static void i40e_get_channels(struct net_device *dev,
  2343. struct ethtool_channels *ch)
  2344. {
  2345. struct i40e_netdev_priv *np = netdev_priv(dev);
  2346. struct i40e_vsi *vsi = np->vsi;
  2347. struct i40e_pf *pf = vsi->back;
  2348. /* report maximum channels */
  2349. ch->max_combined = i40e_max_channels(vsi);
  2350. /* report info for other vector */
  2351. ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
  2352. ch->max_other = ch->other_count;
  2353. /* Note: This code assumes DCB is disabled for now. */
  2354. ch->combined_count = vsi->num_queue_pairs;
  2355. }
  2356. /**
  2357. * i40e_set_channels - Set the new channels count.
  2358. * @netdev: network interface device structure
  2359. * @ch: ethtool channels structure
  2360. *
  2361. * The new channels count may not be the same as requested by the user
  2362. * since it gets rounded down to a power of 2 value.
  2363. **/
  2364. static int i40e_set_channels(struct net_device *dev,
  2365. struct ethtool_channels *ch)
  2366. {
  2367. struct i40e_netdev_priv *np = netdev_priv(dev);
  2368. unsigned int count = ch->combined_count;
  2369. struct i40e_vsi *vsi = np->vsi;
  2370. struct i40e_pf *pf = vsi->back;
  2371. int new_count;
  2372. /* We do not support setting channels for any other VSI at present */
  2373. if (vsi->type != I40E_VSI_MAIN)
  2374. return -EINVAL;
  2375. /* verify they are not requesting separate vectors */
  2376. if (!count || ch->rx_count || ch->tx_count)
  2377. return -EINVAL;
  2378. /* verify other_count has not changed */
  2379. if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
  2380. return -EINVAL;
  2381. /* verify the number of channels does not exceed hardware limits */
  2382. if (count > i40e_max_channels(vsi))
  2383. return -EINVAL;
  2384. /* update feature limits from largest to smallest supported values */
  2385. /* TODO: Flow director limit, DCB etc */
  2386. /* use rss_reconfig to rebuild with new queue count and update traffic
  2387. * class queue mapping
  2388. */
  2389. new_count = i40e_reconfig_rss_queues(pf, count);
  2390. if (new_count > 0)
  2391. return 0;
  2392. else
  2393. return -EINVAL;
  2394. }
  2395. /**
  2396. * i40e_get_rxfh_key_size - get the RSS hash key size
  2397. * @netdev: network interface device structure
  2398. *
  2399. * Returns the table size.
  2400. **/
  2401. static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
  2402. {
  2403. return I40E_HKEY_ARRAY_SIZE;
  2404. }
  2405. /**
  2406. * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
  2407. * @netdev: network interface device structure
  2408. *
  2409. * Returns the table size.
  2410. **/
  2411. static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
  2412. {
  2413. return I40E_HLUT_ARRAY_SIZE;
  2414. }
  2415. static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
  2416. u8 *hfunc)
  2417. {
  2418. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2419. struct i40e_vsi *vsi = np->vsi;
  2420. u8 *lut, *seed = NULL;
  2421. int ret;
  2422. u16 i;
  2423. if (hfunc)
  2424. *hfunc = ETH_RSS_HASH_TOP;
  2425. if (!indir)
  2426. return 0;
  2427. seed = key;
  2428. lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
  2429. if (!lut)
  2430. return -ENOMEM;
  2431. ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
  2432. if (ret)
  2433. goto out;
  2434. for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
  2435. indir[i] = (u32)(lut[i]);
  2436. out:
  2437. kfree(lut);
  2438. return ret;
  2439. }
  2440. /**
  2441. * i40e_set_rxfh - set the rx flow hash indirection table
  2442. * @netdev: network interface device structure
  2443. * @indir: indirection table
  2444. * @key: hash key
  2445. *
  2446. * Returns -EINVAL if the table specifies an invalid queue id, otherwise
  2447. * returns 0 after programming the table.
  2448. **/
  2449. static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
  2450. const u8 *key, const u8 hfunc)
  2451. {
  2452. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2453. struct i40e_vsi *vsi = np->vsi;
  2454. u8 *seed = NULL;
  2455. u16 i;
  2456. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
  2457. return -EOPNOTSUPP;
  2458. if (!indir)
  2459. return 0;
  2460. if (key) {
  2461. if (!vsi->rss_hkey_user) {
  2462. vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
  2463. GFP_KERNEL);
  2464. if (!vsi->rss_hkey_user)
  2465. return -ENOMEM;
  2466. }
  2467. memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
  2468. seed = vsi->rss_hkey_user;
  2469. }
  2470. if (!vsi->rss_lut_user) {
  2471. vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
  2472. if (!vsi->rss_lut_user)
  2473. return -ENOMEM;
  2474. }
  2475. /* Each 32 bits pointed by 'indir' is stored with a lut entry */
  2476. for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
  2477. vsi->rss_lut_user[i] = (u8)(indir[i]);
  2478. return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
  2479. I40E_HLUT_ARRAY_SIZE);
  2480. }
  2481. /**
  2482. * i40e_get_priv_flags - report device private flags
  2483. * @dev: network interface device structure
  2484. *
  2485. * The get string set count and the string set should be matched for each
  2486. * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
  2487. * array.
  2488. *
  2489. * Returns a u32 bitmap of flags.
  2490. **/
  2491. static u32 i40e_get_priv_flags(struct net_device *dev)
  2492. {
  2493. struct i40e_netdev_priv *np = netdev_priv(dev);
  2494. struct i40e_vsi *vsi = np->vsi;
  2495. struct i40e_pf *pf = vsi->back;
  2496. u32 ret_flags = 0;
  2497. ret_flags |= pf->hw.func_caps.npar_enable ?
  2498. I40E_PRIV_FLAGS_NPAR_FLAG : 0;
  2499. ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
  2500. I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
  2501. ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
  2502. I40E_PRIV_FLAGS_FD_ATR : 0;
  2503. ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
  2504. I40E_PRIV_FLAGS_VEB_STATS : 0;
  2505. ret_flags |= pf->flags & I40E_FLAG_RX_PS_ENABLED ?
  2506. I40E_PRIV_FLAGS_PS : 0;
  2507. ret_flags |= pf->auto_disable_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE ?
  2508. 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT;
  2509. return ret_flags;
  2510. }
  2511. /**
  2512. * i40e_set_priv_flags - set private flags
  2513. * @dev: network interface device structure
  2514. * @flags: bit flags to be set
  2515. **/
  2516. static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
  2517. {
  2518. struct i40e_netdev_priv *np = netdev_priv(dev);
  2519. struct i40e_vsi *vsi = np->vsi;
  2520. struct i40e_pf *pf = vsi->back;
  2521. bool reset_required = false;
  2522. /* NOTE: MFP is not settable */
  2523. /* allow the user to control the method of receive
  2524. * buffer DMA, whether the packet is split at header
  2525. * boundaries into two separate buffers. In some cases
  2526. * one routine or the other will perform better.
  2527. */
  2528. if ((flags & I40E_PRIV_FLAGS_PS) &&
  2529. !(pf->flags & I40E_FLAG_RX_PS_ENABLED)) {
  2530. pf->flags |= I40E_FLAG_RX_PS_ENABLED;
  2531. pf->flags &= ~I40E_FLAG_RX_1BUF_ENABLED;
  2532. reset_required = true;
  2533. } else if (!(flags & I40E_PRIV_FLAGS_PS) &&
  2534. (pf->flags & I40E_FLAG_RX_PS_ENABLED)) {
  2535. pf->flags &= ~I40E_FLAG_RX_PS_ENABLED;
  2536. pf->flags |= I40E_FLAG_RX_1BUF_ENABLED;
  2537. reset_required = true;
  2538. }
  2539. if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
  2540. pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
  2541. else
  2542. pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
  2543. /* allow the user to control the state of the Flow
  2544. * Director ATR (Application Targeted Routing) feature
  2545. * of the driver
  2546. */
  2547. if (flags & I40E_PRIV_FLAGS_FD_ATR) {
  2548. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  2549. } else {
  2550. pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  2551. pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
  2552. }
  2553. if ((flags & I40E_PRIV_FLAGS_VEB_STATS) &&
  2554. !(pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  2555. pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
  2556. reset_required = true;
  2557. } else if (!(flags & I40E_PRIV_FLAGS_VEB_STATS) &&
  2558. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  2559. pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
  2560. reset_required = true;
  2561. }
  2562. if ((flags & I40E_PRIV_FLAGS_HW_ATR_EVICT) &&
  2563. (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE))
  2564. pf->auto_disable_flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  2565. else
  2566. pf->auto_disable_flags |= I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  2567. /* if needed, issue reset to cause things to take effect */
  2568. if (reset_required)
  2569. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
  2570. return 0;
  2571. }
  2572. static const struct ethtool_ops i40e_ethtool_ops = {
  2573. .get_settings = i40e_get_settings,
  2574. .set_settings = i40e_set_settings,
  2575. .get_drvinfo = i40e_get_drvinfo,
  2576. .get_regs_len = i40e_get_regs_len,
  2577. .get_regs = i40e_get_regs,
  2578. .nway_reset = i40e_nway_reset,
  2579. .get_link = ethtool_op_get_link,
  2580. .get_wol = i40e_get_wol,
  2581. .set_wol = i40e_set_wol,
  2582. .set_eeprom = i40e_set_eeprom,
  2583. .get_eeprom_len = i40e_get_eeprom_len,
  2584. .get_eeprom = i40e_get_eeprom,
  2585. .get_ringparam = i40e_get_ringparam,
  2586. .set_ringparam = i40e_set_ringparam,
  2587. .get_pauseparam = i40e_get_pauseparam,
  2588. .set_pauseparam = i40e_set_pauseparam,
  2589. .get_msglevel = i40e_get_msglevel,
  2590. .set_msglevel = i40e_set_msglevel,
  2591. .get_rxnfc = i40e_get_rxnfc,
  2592. .set_rxnfc = i40e_set_rxnfc,
  2593. .self_test = i40e_diag_test,
  2594. .get_strings = i40e_get_strings,
  2595. .set_phys_id = i40e_set_phys_id,
  2596. .get_sset_count = i40e_get_sset_count,
  2597. .get_ethtool_stats = i40e_get_ethtool_stats,
  2598. .get_coalesce = i40e_get_coalesce,
  2599. .set_coalesce = i40e_set_coalesce,
  2600. .get_rxfh_key_size = i40e_get_rxfh_key_size,
  2601. .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
  2602. .get_rxfh = i40e_get_rxfh,
  2603. .set_rxfh = i40e_set_rxfh,
  2604. .get_channels = i40e_get_channels,
  2605. .set_channels = i40e_set_channels,
  2606. .get_ts_info = i40e_get_ts_info,
  2607. .get_priv_flags = i40e_get_priv_flags,
  2608. .set_priv_flags = i40e_set_priv_flags,
  2609. .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
  2610. .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
  2611. };
  2612. void i40e_set_ethtool_ops(struct net_device *netdev)
  2613. {
  2614. netdev->ethtool_ops = &i40e_ethtool_ops;
  2615. }