i40e_ethtool.c 75 KB

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