i40e_ethtool.c 82 KB

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