i40e_ethtool.c 71 KB

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