i40e_ethtool.c 77 KB

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