i40e_ethtool.c 90 KB

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