i40e_ethtool.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2014 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 net_device_stats, #_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", stats.eth.tx_discards),
  107. I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
  108. I40E_PF_STAT("crc_errors", stats.crc_errors),
  109. I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
  110. I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
  111. I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
  112. I40E_PF_STAT("tx_timeout", tx_timeout_count),
  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. /* LPI stats */
  139. I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
  140. I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
  141. I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
  142. I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
  143. };
  144. #define I40E_QUEUE_STATS_LEN(n) \
  145. (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
  146. * 2 /* Tx and Rx together */ \
  147. * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
  148. #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
  149. #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
  150. #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
  151. #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
  152. I40E_MISC_STATS_LEN + \
  153. I40E_QUEUE_STATS_LEN((n)))
  154. #define I40E_PFC_STATS_LEN ( \
  155. (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
  156. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
  157. FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
  158. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
  159. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
  160. / sizeof(u64))
  161. #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
  162. #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
  163. I40E_PFC_STATS_LEN + \
  164. I40E_VSI_STATS_LEN((n)))
  165. enum i40e_ethtool_test_id {
  166. I40E_ETH_TEST_REG = 0,
  167. I40E_ETH_TEST_EEPROM,
  168. I40E_ETH_TEST_INTR,
  169. I40E_ETH_TEST_LOOPBACK,
  170. I40E_ETH_TEST_LINK,
  171. };
  172. static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
  173. "Register test (offline)",
  174. "Eeprom test (offline)",
  175. "Interrupt test (offline)",
  176. "Loopback test (offline)",
  177. "Link test (on/offline)"
  178. };
  179. #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
  180. /**
  181. * i40e_get_settings - Get Link Speed and Duplex settings
  182. * @netdev: network interface device structure
  183. * @ecmd: ethtool command
  184. *
  185. * Reports speed/duplex settings based on media_type
  186. **/
  187. static int i40e_get_settings(struct net_device *netdev,
  188. struct ethtool_cmd *ecmd)
  189. {
  190. struct i40e_netdev_priv *np = netdev_priv(netdev);
  191. struct i40e_pf *pf = np->vsi->back;
  192. struct i40e_hw *hw = &pf->hw;
  193. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  194. bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
  195. u32 link_speed = hw_link_info->link_speed;
  196. /* hardware is either in 40G mode or 10G mode
  197. * NOTE: this section initializes supported and advertising
  198. */
  199. switch (hw_link_info->phy_type) {
  200. case I40E_PHY_TYPE_40GBASE_CR4:
  201. case I40E_PHY_TYPE_40GBASE_CR4_CU:
  202. ecmd->supported = SUPPORTED_40000baseCR4_Full;
  203. ecmd->advertising = ADVERTISED_40000baseCR4_Full;
  204. break;
  205. case I40E_PHY_TYPE_40GBASE_KR4:
  206. ecmd->supported = SUPPORTED_40000baseKR4_Full;
  207. ecmd->advertising = ADVERTISED_40000baseKR4_Full;
  208. break;
  209. case I40E_PHY_TYPE_40GBASE_SR4:
  210. ecmd->supported = SUPPORTED_40000baseSR4_Full;
  211. ecmd->advertising = ADVERTISED_40000baseSR4_Full;
  212. break;
  213. case I40E_PHY_TYPE_40GBASE_LR4:
  214. ecmd->supported = SUPPORTED_40000baseLR4_Full;
  215. ecmd->advertising = ADVERTISED_40000baseLR4_Full;
  216. break;
  217. case I40E_PHY_TYPE_10GBASE_KX4:
  218. ecmd->supported = SUPPORTED_10000baseKX4_Full;
  219. ecmd->advertising = ADVERTISED_10000baseKX4_Full;
  220. break;
  221. case I40E_PHY_TYPE_10GBASE_KR:
  222. ecmd->supported = SUPPORTED_10000baseKR_Full;
  223. ecmd->advertising = ADVERTISED_10000baseKR_Full;
  224. break;
  225. default:
  226. if (i40e_is_40G_device(hw->device_id)) {
  227. ecmd->supported = SUPPORTED_40000baseSR4_Full;
  228. ecmd->advertising = ADVERTISED_40000baseSR4_Full;
  229. } else {
  230. ecmd->supported = SUPPORTED_10000baseT_Full;
  231. ecmd->advertising = ADVERTISED_10000baseT_Full;
  232. }
  233. break;
  234. }
  235. ecmd->supported |= SUPPORTED_Autoneg;
  236. ecmd->advertising |= ADVERTISED_Autoneg;
  237. ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  238. AUTONEG_ENABLE : AUTONEG_DISABLE);
  239. switch (hw->phy.media_type) {
  240. case I40E_MEDIA_TYPE_BACKPLANE:
  241. ecmd->supported |= SUPPORTED_Backplane;
  242. ecmd->advertising |= ADVERTISED_Backplane;
  243. ecmd->port = PORT_NONE;
  244. break;
  245. case I40E_MEDIA_TYPE_BASET:
  246. ecmd->supported |= SUPPORTED_TP;
  247. ecmd->advertising |= ADVERTISED_TP;
  248. ecmd->port = PORT_TP;
  249. break;
  250. case I40E_MEDIA_TYPE_DA:
  251. case I40E_MEDIA_TYPE_CX4:
  252. ecmd->supported |= SUPPORTED_FIBRE;
  253. ecmd->advertising |= ADVERTISED_FIBRE;
  254. ecmd->port = PORT_DA;
  255. break;
  256. case I40E_MEDIA_TYPE_FIBER:
  257. ecmd->supported |= SUPPORTED_FIBRE;
  258. ecmd->advertising |= ADVERTISED_FIBRE;
  259. ecmd->port = PORT_FIBRE;
  260. break;
  261. case I40E_MEDIA_TYPE_UNKNOWN:
  262. default:
  263. ecmd->port = PORT_OTHER;
  264. break;
  265. }
  266. ecmd->transceiver = XCVR_EXTERNAL;
  267. if (link_up) {
  268. switch (link_speed) {
  269. case I40E_LINK_SPEED_40GB:
  270. /* need a SPEED_40000 in ethtool.h */
  271. ethtool_cmd_speed_set(ecmd, 40000);
  272. break;
  273. case I40E_LINK_SPEED_10GB:
  274. ethtool_cmd_speed_set(ecmd, SPEED_10000);
  275. break;
  276. default:
  277. break;
  278. }
  279. ecmd->duplex = DUPLEX_FULL;
  280. } else {
  281. ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
  282. ecmd->duplex = DUPLEX_UNKNOWN;
  283. }
  284. return 0;
  285. }
  286. /**
  287. * i40e_get_pauseparam - Get Flow Control status
  288. * Return tx/rx-pause status
  289. **/
  290. static void i40e_get_pauseparam(struct net_device *netdev,
  291. struct ethtool_pauseparam *pause)
  292. {
  293. struct i40e_netdev_priv *np = netdev_priv(netdev);
  294. struct i40e_pf *pf = np->vsi->back;
  295. struct i40e_hw *hw = &pf->hw;
  296. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  297. pause->autoneg =
  298. ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  299. AUTONEG_ENABLE : AUTONEG_DISABLE);
  300. if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
  301. pause->rx_pause = 1;
  302. } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
  303. pause->tx_pause = 1;
  304. } else if (hw->fc.current_mode == I40E_FC_FULL) {
  305. pause->rx_pause = 1;
  306. pause->tx_pause = 1;
  307. }
  308. }
  309. static u32 i40e_get_msglevel(struct net_device *netdev)
  310. {
  311. struct i40e_netdev_priv *np = netdev_priv(netdev);
  312. struct i40e_pf *pf = np->vsi->back;
  313. return pf->msg_enable;
  314. }
  315. static void i40e_set_msglevel(struct net_device *netdev, u32 data)
  316. {
  317. struct i40e_netdev_priv *np = netdev_priv(netdev);
  318. struct i40e_pf *pf = np->vsi->back;
  319. if (I40E_DEBUG_USER & data)
  320. pf->hw.debug_mask = data;
  321. pf->msg_enable = data;
  322. }
  323. static int i40e_get_regs_len(struct net_device *netdev)
  324. {
  325. int reg_count = 0;
  326. int i;
  327. for (i = 0; i40e_reg_list[i].offset != 0; i++)
  328. reg_count += i40e_reg_list[i].elements;
  329. return reg_count * sizeof(u32);
  330. }
  331. static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
  332. void *p)
  333. {
  334. struct i40e_netdev_priv *np = netdev_priv(netdev);
  335. struct i40e_pf *pf = np->vsi->back;
  336. struct i40e_hw *hw = &pf->hw;
  337. u32 *reg_buf = p;
  338. int i, j, ri;
  339. u32 reg;
  340. /* Tell ethtool which driver-version-specific regs output we have.
  341. *
  342. * At some point, if we have ethtool doing special formatting of
  343. * this data, it will rely on this version number to know how to
  344. * interpret things. Hence, this needs to be updated if/when the
  345. * diags register table is changed.
  346. */
  347. regs->version = 1;
  348. /* loop through the diags reg table for what to print */
  349. ri = 0;
  350. for (i = 0; i40e_reg_list[i].offset != 0; i++) {
  351. for (j = 0; j < i40e_reg_list[i].elements; j++) {
  352. reg = i40e_reg_list[i].offset
  353. + (j * i40e_reg_list[i].stride);
  354. reg_buf[ri++] = rd32(hw, reg);
  355. }
  356. }
  357. }
  358. static int i40e_get_eeprom(struct net_device *netdev,
  359. struct ethtool_eeprom *eeprom, u8 *bytes)
  360. {
  361. struct i40e_netdev_priv *np = netdev_priv(netdev);
  362. struct i40e_hw *hw = &np->vsi->back->hw;
  363. struct i40e_pf *pf = np->vsi->back;
  364. int ret_val = 0, len;
  365. u8 *eeprom_buff;
  366. u16 i, sectors;
  367. bool last;
  368. #define I40E_NVM_SECTOR_SIZE 4096
  369. if (eeprom->len == 0)
  370. return -EINVAL;
  371. eeprom->magic = hw->vendor_id | (hw->device_id << 16);
  372. eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
  373. if (!eeprom_buff)
  374. return -ENOMEM;
  375. ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
  376. if (ret_val) {
  377. dev_info(&pf->pdev->dev,
  378. "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
  379. ret_val, hw->aq.asq_last_status);
  380. goto free_buff;
  381. }
  382. sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
  383. sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
  384. len = I40E_NVM_SECTOR_SIZE;
  385. last = false;
  386. for (i = 0; i < sectors; i++) {
  387. if (i == (sectors - 1)) {
  388. len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
  389. last = true;
  390. }
  391. ret_val = i40e_aq_read_nvm(hw, 0x0,
  392. eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
  393. len,
  394. eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
  395. last, NULL);
  396. if (ret_val) {
  397. dev_info(&pf->pdev->dev,
  398. "read NVM failed err=%d status=0x%x\n",
  399. ret_val, hw->aq.asq_last_status);
  400. goto release_nvm;
  401. }
  402. }
  403. release_nvm:
  404. i40e_release_nvm(hw);
  405. memcpy(bytes, eeprom_buff, eeprom->len);
  406. free_buff:
  407. kfree(eeprom_buff);
  408. return ret_val;
  409. }
  410. static int i40e_get_eeprom_len(struct net_device *netdev)
  411. {
  412. struct i40e_netdev_priv *np = netdev_priv(netdev);
  413. struct i40e_hw *hw = &np->vsi->back->hw;
  414. u32 val;
  415. val = (rd32(hw, I40E_GLPCI_LBARCTRL)
  416. & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
  417. >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
  418. /* register returns value in power of 2, 64Kbyte chunks. */
  419. val = (64 * 1024) * (1 << val);
  420. return val;
  421. }
  422. static void i40e_get_drvinfo(struct net_device *netdev,
  423. struct ethtool_drvinfo *drvinfo)
  424. {
  425. struct i40e_netdev_priv *np = netdev_priv(netdev);
  426. struct i40e_vsi *vsi = np->vsi;
  427. struct i40e_pf *pf = vsi->back;
  428. strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
  429. strlcpy(drvinfo->version, i40e_driver_version_str,
  430. sizeof(drvinfo->version));
  431. strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
  432. sizeof(drvinfo->fw_version));
  433. strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
  434. sizeof(drvinfo->bus_info));
  435. }
  436. static void i40e_get_ringparam(struct net_device *netdev,
  437. struct ethtool_ringparam *ring)
  438. {
  439. struct i40e_netdev_priv *np = netdev_priv(netdev);
  440. struct i40e_pf *pf = np->vsi->back;
  441. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  442. ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  443. ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  444. ring->rx_mini_max_pending = 0;
  445. ring->rx_jumbo_max_pending = 0;
  446. ring->rx_pending = vsi->rx_rings[0]->count;
  447. ring->tx_pending = vsi->tx_rings[0]->count;
  448. ring->rx_mini_pending = 0;
  449. ring->rx_jumbo_pending = 0;
  450. }
  451. static int i40e_set_ringparam(struct net_device *netdev,
  452. struct ethtool_ringparam *ring)
  453. {
  454. struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
  455. struct i40e_netdev_priv *np = netdev_priv(netdev);
  456. struct i40e_vsi *vsi = np->vsi;
  457. struct i40e_pf *pf = vsi->back;
  458. u32 new_rx_count, new_tx_count;
  459. int i, err = 0;
  460. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  461. return -EINVAL;
  462. if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  463. ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
  464. ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  465. ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
  466. netdev_info(netdev,
  467. "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
  468. ring->tx_pending, ring->rx_pending,
  469. I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
  470. return -EINVAL;
  471. }
  472. new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  473. new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  474. /* if nothing to do return success */
  475. if ((new_tx_count == vsi->tx_rings[0]->count) &&
  476. (new_rx_count == vsi->rx_rings[0]->count))
  477. return 0;
  478. while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
  479. usleep_range(1000, 2000);
  480. if (!netif_running(vsi->netdev)) {
  481. /* simple case - set for the next time the netdev is started */
  482. for (i = 0; i < vsi->num_queue_pairs; i++) {
  483. vsi->tx_rings[i]->count = new_tx_count;
  484. vsi->rx_rings[i]->count = new_rx_count;
  485. }
  486. goto done;
  487. }
  488. /* We can't just free everything and then setup again,
  489. * because the ISRs in MSI-X mode get passed pointers
  490. * to the Tx and Rx ring structs.
  491. */
  492. /* alloc updated Tx resources */
  493. if (new_tx_count != vsi->tx_rings[0]->count) {
  494. netdev_info(netdev,
  495. "Changing Tx descriptor count from %d to %d.\n",
  496. vsi->tx_rings[0]->count, new_tx_count);
  497. tx_rings = kcalloc(vsi->alloc_queue_pairs,
  498. sizeof(struct i40e_ring), GFP_KERNEL);
  499. if (!tx_rings) {
  500. err = -ENOMEM;
  501. goto done;
  502. }
  503. for (i = 0; i < vsi->num_queue_pairs; i++) {
  504. /* clone ring and setup updated count */
  505. tx_rings[i] = *vsi->tx_rings[i];
  506. tx_rings[i].count = new_tx_count;
  507. err = i40e_setup_tx_descriptors(&tx_rings[i]);
  508. if (err) {
  509. while (i) {
  510. i--;
  511. i40e_free_tx_resources(&tx_rings[i]);
  512. }
  513. kfree(tx_rings);
  514. tx_rings = NULL;
  515. goto done;
  516. }
  517. }
  518. }
  519. /* alloc updated Rx resources */
  520. if (new_rx_count != vsi->rx_rings[0]->count) {
  521. netdev_info(netdev,
  522. "Changing Rx descriptor count from %d to %d\n",
  523. vsi->rx_rings[0]->count, new_rx_count);
  524. rx_rings = kcalloc(vsi->alloc_queue_pairs,
  525. sizeof(struct i40e_ring), GFP_KERNEL);
  526. if (!rx_rings) {
  527. err = -ENOMEM;
  528. goto free_tx;
  529. }
  530. for (i = 0; i < vsi->num_queue_pairs; i++) {
  531. /* clone ring and setup updated count */
  532. rx_rings[i] = *vsi->rx_rings[i];
  533. rx_rings[i].count = new_rx_count;
  534. err = i40e_setup_rx_descriptors(&rx_rings[i]);
  535. if (err) {
  536. while (i) {
  537. i--;
  538. i40e_free_rx_resources(&rx_rings[i]);
  539. }
  540. kfree(rx_rings);
  541. rx_rings = NULL;
  542. goto free_tx;
  543. }
  544. }
  545. }
  546. /* Bring interface down, copy in the new ring info,
  547. * then restore the interface
  548. */
  549. i40e_down(vsi);
  550. if (tx_rings) {
  551. for (i = 0; i < vsi->num_queue_pairs; i++) {
  552. i40e_free_tx_resources(vsi->tx_rings[i]);
  553. *vsi->tx_rings[i] = tx_rings[i];
  554. }
  555. kfree(tx_rings);
  556. tx_rings = NULL;
  557. }
  558. if (rx_rings) {
  559. for (i = 0; i < vsi->num_queue_pairs; i++) {
  560. i40e_free_rx_resources(vsi->rx_rings[i]);
  561. *vsi->rx_rings[i] = rx_rings[i];
  562. }
  563. kfree(rx_rings);
  564. rx_rings = NULL;
  565. }
  566. i40e_up(vsi);
  567. free_tx:
  568. /* error cleanup if the Rx allocations failed after getting Tx */
  569. if (tx_rings) {
  570. for (i = 0; i < vsi->num_queue_pairs; i++)
  571. i40e_free_tx_resources(&tx_rings[i]);
  572. kfree(tx_rings);
  573. tx_rings = NULL;
  574. }
  575. done:
  576. clear_bit(__I40E_CONFIG_BUSY, &pf->state);
  577. return err;
  578. }
  579. static int i40e_get_sset_count(struct net_device *netdev, int sset)
  580. {
  581. struct i40e_netdev_priv *np = netdev_priv(netdev);
  582. struct i40e_vsi *vsi = np->vsi;
  583. struct i40e_pf *pf = vsi->back;
  584. switch (sset) {
  585. case ETH_SS_TEST:
  586. return I40E_TEST_LEN;
  587. case ETH_SS_STATS:
  588. if (vsi == pf->vsi[pf->lan_vsi]) {
  589. int len = I40E_PF_STATS_LEN(netdev);
  590. if (pf->lan_veb != I40E_NO_VEB)
  591. len += I40E_VEB_STATS_LEN;
  592. return len;
  593. } else {
  594. return I40E_VSI_STATS_LEN(netdev);
  595. }
  596. default:
  597. return -EOPNOTSUPP;
  598. }
  599. }
  600. static void i40e_get_ethtool_stats(struct net_device *netdev,
  601. struct ethtool_stats *stats, u64 *data)
  602. {
  603. struct i40e_netdev_priv *np = netdev_priv(netdev);
  604. struct i40e_ring *tx_ring, *rx_ring;
  605. struct i40e_vsi *vsi = np->vsi;
  606. struct i40e_pf *pf = vsi->back;
  607. int i = 0;
  608. char *p;
  609. int j;
  610. struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
  611. unsigned int start;
  612. i40e_update_stats(vsi);
  613. for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
  614. p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
  615. data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
  616. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  617. }
  618. for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
  619. p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
  620. data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
  621. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  622. }
  623. rcu_read_lock();
  624. for (j = 0; j < vsi->num_queue_pairs; j++) {
  625. tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
  626. if (!tx_ring)
  627. continue;
  628. /* process Tx ring statistics */
  629. do {
  630. start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
  631. data[i] = tx_ring->stats.packets;
  632. data[i + 1] = tx_ring->stats.bytes;
  633. } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
  634. i += 2;
  635. /* Rx ring is the 2nd half of the queue pair */
  636. rx_ring = &tx_ring[1];
  637. do {
  638. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  639. data[i] = rx_ring->stats.packets;
  640. data[i + 1] = rx_ring->stats.bytes;
  641. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  642. i += 2;
  643. }
  644. rcu_read_unlock();
  645. if (vsi != pf->vsi[pf->lan_vsi])
  646. return;
  647. if (pf->lan_veb != I40E_NO_VEB) {
  648. struct i40e_veb *veb = pf->veb[pf->lan_veb];
  649. for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
  650. p = (char *)veb;
  651. p += i40e_gstrings_veb_stats[j].stat_offset;
  652. data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
  653. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  654. }
  655. }
  656. for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
  657. p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
  658. data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
  659. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  660. }
  661. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  662. data[i++] = pf->stats.priority_xon_tx[j];
  663. data[i++] = pf->stats.priority_xoff_tx[j];
  664. }
  665. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  666. data[i++] = pf->stats.priority_xon_rx[j];
  667. data[i++] = pf->stats.priority_xoff_rx[j];
  668. }
  669. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
  670. data[i++] = pf->stats.priority_xon_2_xoff[j];
  671. }
  672. static void i40e_get_strings(struct net_device *netdev, u32 stringset,
  673. u8 *data)
  674. {
  675. struct i40e_netdev_priv *np = netdev_priv(netdev);
  676. struct i40e_vsi *vsi = np->vsi;
  677. struct i40e_pf *pf = vsi->back;
  678. char *p = (char *)data;
  679. int i;
  680. switch (stringset) {
  681. case ETH_SS_TEST:
  682. for (i = 0; i < I40E_TEST_LEN; i++) {
  683. memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
  684. data += ETH_GSTRING_LEN;
  685. }
  686. break;
  687. case ETH_SS_STATS:
  688. for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
  689. snprintf(p, ETH_GSTRING_LEN, "%s",
  690. i40e_gstrings_net_stats[i].stat_string);
  691. p += ETH_GSTRING_LEN;
  692. }
  693. for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
  694. snprintf(p, ETH_GSTRING_LEN, "%s",
  695. i40e_gstrings_misc_stats[i].stat_string);
  696. p += ETH_GSTRING_LEN;
  697. }
  698. for (i = 0; i < vsi->num_queue_pairs; i++) {
  699. snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
  700. p += ETH_GSTRING_LEN;
  701. snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
  702. p += ETH_GSTRING_LEN;
  703. snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
  704. p += ETH_GSTRING_LEN;
  705. snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
  706. p += ETH_GSTRING_LEN;
  707. }
  708. if (vsi != pf->vsi[pf->lan_vsi])
  709. return;
  710. if (pf->lan_veb != I40E_NO_VEB) {
  711. for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
  712. snprintf(p, ETH_GSTRING_LEN, "veb.%s",
  713. i40e_gstrings_veb_stats[i].stat_string);
  714. p += ETH_GSTRING_LEN;
  715. }
  716. }
  717. for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
  718. snprintf(p, ETH_GSTRING_LEN, "port.%s",
  719. i40e_gstrings_stats[i].stat_string);
  720. p += ETH_GSTRING_LEN;
  721. }
  722. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  723. snprintf(p, ETH_GSTRING_LEN,
  724. "port.tx_priority_%u_xon", i);
  725. p += ETH_GSTRING_LEN;
  726. snprintf(p, ETH_GSTRING_LEN,
  727. "port.tx_priority_%u_xoff", i);
  728. p += ETH_GSTRING_LEN;
  729. }
  730. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  731. snprintf(p, ETH_GSTRING_LEN,
  732. "port.rx_priority_%u_xon", i);
  733. p += ETH_GSTRING_LEN;
  734. snprintf(p, ETH_GSTRING_LEN,
  735. "port.rx_priority_%u_xoff", i);
  736. p += ETH_GSTRING_LEN;
  737. }
  738. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  739. snprintf(p, ETH_GSTRING_LEN,
  740. "port.rx_priority_%u_xon_2_xoff", i);
  741. p += ETH_GSTRING_LEN;
  742. }
  743. /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
  744. break;
  745. }
  746. }
  747. static int i40e_get_ts_info(struct net_device *dev,
  748. struct ethtool_ts_info *info)
  749. {
  750. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  751. info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  752. SOF_TIMESTAMPING_RX_SOFTWARE |
  753. SOF_TIMESTAMPING_SOFTWARE |
  754. SOF_TIMESTAMPING_TX_HARDWARE |
  755. SOF_TIMESTAMPING_RX_HARDWARE |
  756. SOF_TIMESTAMPING_RAW_HARDWARE;
  757. if (pf->ptp_clock)
  758. info->phc_index = ptp_clock_index(pf->ptp_clock);
  759. else
  760. info->phc_index = -1;
  761. info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
  762. info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
  763. (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
  764. (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
  765. (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
  766. (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
  767. (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
  768. (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
  769. (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
  770. (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
  771. (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
  772. (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
  773. (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
  774. return 0;
  775. }
  776. static int i40e_link_test(struct net_device *netdev, u64 *data)
  777. {
  778. struct i40e_netdev_priv *np = netdev_priv(netdev);
  779. struct i40e_pf *pf = np->vsi->back;
  780. netif_info(pf, hw, netdev, "link test\n");
  781. if (i40e_get_link_status(&pf->hw))
  782. *data = 0;
  783. else
  784. *data = 1;
  785. return *data;
  786. }
  787. static int i40e_reg_test(struct net_device *netdev, u64 *data)
  788. {
  789. struct i40e_netdev_priv *np = netdev_priv(netdev);
  790. struct i40e_pf *pf = np->vsi->back;
  791. netif_info(pf, hw, netdev, "register test\n");
  792. *data = i40e_diag_reg_test(&pf->hw);
  793. return *data;
  794. }
  795. static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
  796. {
  797. struct i40e_netdev_priv *np = netdev_priv(netdev);
  798. struct i40e_pf *pf = np->vsi->back;
  799. netif_info(pf, hw, netdev, "eeprom test\n");
  800. *data = i40e_diag_eeprom_test(&pf->hw);
  801. return *data;
  802. }
  803. static int i40e_intr_test(struct net_device *netdev, u64 *data)
  804. {
  805. struct i40e_netdev_priv *np = netdev_priv(netdev);
  806. struct i40e_pf *pf = np->vsi->back;
  807. u16 swc_old = pf->sw_int_count;
  808. netif_info(pf, hw, netdev, "interrupt test\n");
  809. wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
  810. (I40E_PFINT_DYN_CTL0_INTENA_MASK |
  811. I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
  812. usleep_range(1000, 2000);
  813. *data = (swc_old == pf->sw_int_count);
  814. return *data;
  815. }
  816. static int i40e_loopback_test(struct net_device *netdev, u64 *data)
  817. {
  818. struct i40e_netdev_priv *np = netdev_priv(netdev);
  819. struct i40e_pf *pf = np->vsi->back;
  820. netif_info(pf, hw, netdev, "loopback test not implemented\n");
  821. *data = 0;
  822. return *data;
  823. }
  824. static void i40e_diag_test(struct net_device *netdev,
  825. struct ethtool_test *eth_test, u64 *data)
  826. {
  827. struct i40e_netdev_priv *np = netdev_priv(netdev);
  828. struct i40e_pf *pf = np->vsi->back;
  829. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  830. /* Offline tests */
  831. netif_info(pf, drv, netdev, "offline testing starting\n");
  832. set_bit(__I40E_TESTING, &pf->state);
  833. /* Link test performed before hardware reset
  834. * so autoneg doesn't interfere with test result
  835. */
  836. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  837. eth_test->flags |= ETH_TEST_FL_FAILED;
  838. if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
  839. eth_test->flags |= ETH_TEST_FL_FAILED;
  840. if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
  841. eth_test->flags |= ETH_TEST_FL_FAILED;
  842. if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
  843. eth_test->flags |= ETH_TEST_FL_FAILED;
  844. /* run reg test last, a reset is required after it */
  845. if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
  846. eth_test->flags |= ETH_TEST_FL_FAILED;
  847. clear_bit(__I40E_TESTING, &pf->state);
  848. i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
  849. } else {
  850. /* Online tests */
  851. netif_info(pf, drv, netdev, "online testing starting\n");
  852. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  853. eth_test->flags |= ETH_TEST_FL_FAILED;
  854. /* Offline only tests, not run in online; pass by default */
  855. data[I40E_ETH_TEST_REG] = 0;
  856. data[I40E_ETH_TEST_EEPROM] = 0;
  857. data[I40E_ETH_TEST_INTR] = 0;
  858. data[I40E_ETH_TEST_LOOPBACK] = 0;
  859. }
  860. netif_info(pf, drv, netdev, "testing finished\n");
  861. }
  862. static void i40e_get_wol(struct net_device *netdev,
  863. struct ethtool_wolinfo *wol)
  864. {
  865. struct i40e_netdev_priv *np = netdev_priv(netdev);
  866. struct i40e_pf *pf = np->vsi->back;
  867. struct i40e_hw *hw = &pf->hw;
  868. u16 wol_nvm_bits;
  869. /* NVM bit on means WoL disabled for the port */
  870. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  871. if ((1 << hw->port) & wol_nvm_bits) {
  872. wol->supported = 0;
  873. wol->wolopts = 0;
  874. } else {
  875. wol->supported = WAKE_MAGIC;
  876. wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
  877. }
  878. }
  879. static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  880. {
  881. struct i40e_netdev_priv *np = netdev_priv(netdev);
  882. struct i40e_pf *pf = np->vsi->back;
  883. struct i40e_hw *hw = &pf->hw;
  884. u16 wol_nvm_bits;
  885. /* NVM bit on means WoL disabled for the port */
  886. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  887. if (((1 << hw->port) & wol_nvm_bits))
  888. return -EOPNOTSUPP;
  889. /* only magic packet is supported */
  890. if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
  891. return -EOPNOTSUPP;
  892. /* is this a new value? */
  893. if (pf->wol_en != !!wol->wolopts) {
  894. pf->wol_en = !!wol->wolopts;
  895. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  896. }
  897. return 0;
  898. }
  899. static int i40e_nway_reset(struct net_device *netdev)
  900. {
  901. /* restart autonegotiation */
  902. struct i40e_netdev_priv *np = netdev_priv(netdev);
  903. struct i40e_pf *pf = np->vsi->back;
  904. struct i40e_hw *hw = &pf->hw;
  905. i40e_status ret = 0;
  906. ret = i40e_aq_set_link_restart_an(hw, NULL);
  907. if (ret) {
  908. netdev_info(netdev, "link restart failed, aq_err=%d\n",
  909. pf->hw.aq.asq_last_status);
  910. return -EIO;
  911. }
  912. return 0;
  913. }
  914. static int i40e_set_phys_id(struct net_device *netdev,
  915. enum ethtool_phys_id_state state)
  916. {
  917. struct i40e_netdev_priv *np = netdev_priv(netdev);
  918. struct i40e_pf *pf = np->vsi->back;
  919. struct i40e_hw *hw = &pf->hw;
  920. int blink_freq = 2;
  921. switch (state) {
  922. case ETHTOOL_ID_ACTIVE:
  923. pf->led_status = i40e_led_get(hw);
  924. return blink_freq;
  925. case ETHTOOL_ID_ON:
  926. i40e_led_set(hw, 0xF, false);
  927. break;
  928. case ETHTOOL_ID_OFF:
  929. i40e_led_set(hw, 0x0, false);
  930. break;
  931. case ETHTOOL_ID_INACTIVE:
  932. i40e_led_set(hw, pf->led_status, false);
  933. break;
  934. }
  935. return 0;
  936. }
  937. /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
  938. * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
  939. * 125us (8000 interrupts per second) == ITR(62)
  940. */
  941. static int i40e_get_coalesce(struct net_device *netdev,
  942. struct ethtool_coalesce *ec)
  943. {
  944. struct i40e_netdev_priv *np = netdev_priv(netdev);
  945. struct i40e_vsi *vsi = np->vsi;
  946. ec->tx_max_coalesced_frames_irq = vsi->work_limit;
  947. ec->rx_max_coalesced_frames_irq = vsi->work_limit;
  948. if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
  949. ec->use_adaptive_rx_coalesce = 1;
  950. if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
  951. ec->use_adaptive_tx_coalesce = 1;
  952. ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
  953. ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
  954. return 0;
  955. }
  956. static int i40e_set_coalesce(struct net_device *netdev,
  957. struct ethtool_coalesce *ec)
  958. {
  959. struct i40e_netdev_priv *np = netdev_priv(netdev);
  960. struct i40e_q_vector *q_vector;
  961. struct i40e_vsi *vsi = np->vsi;
  962. struct i40e_pf *pf = vsi->back;
  963. struct i40e_hw *hw = &pf->hw;
  964. u16 vector;
  965. int i;
  966. if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
  967. vsi->work_limit = ec->tx_max_coalesced_frames_irq;
  968. if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
  969. (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
  970. vsi->rx_itr_setting = ec->rx_coalesce_usecs;
  971. else
  972. return -EINVAL;
  973. if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
  974. (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
  975. vsi->tx_itr_setting = ec->tx_coalesce_usecs;
  976. else
  977. return -EINVAL;
  978. if (ec->use_adaptive_rx_coalesce)
  979. vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
  980. else
  981. vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
  982. if (ec->use_adaptive_tx_coalesce)
  983. vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
  984. else
  985. vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
  986. vector = vsi->base_vector;
  987. for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
  988. q_vector = vsi->q_vectors[i];
  989. q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
  990. wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
  991. q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
  992. wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
  993. i40e_flush(hw);
  994. }
  995. return 0;
  996. }
  997. /**
  998. * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
  999. * @pf: pointer to the physical function struct
  1000. * @cmd: ethtool rxnfc command
  1001. *
  1002. * Returns Success if the flow is supported, else Invalid Input.
  1003. **/
  1004. static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
  1005. {
  1006. cmd->data = 0;
  1007. /* Report default options for RSS on i40e */
  1008. switch (cmd->flow_type) {
  1009. case TCP_V4_FLOW:
  1010. case UDP_V4_FLOW:
  1011. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1012. /* fall through to add IP fields */
  1013. case SCTP_V4_FLOW:
  1014. case AH_ESP_V4_FLOW:
  1015. case AH_V4_FLOW:
  1016. case ESP_V4_FLOW:
  1017. case IPV4_FLOW:
  1018. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  1019. break;
  1020. case TCP_V6_FLOW:
  1021. case UDP_V6_FLOW:
  1022. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1023. /* fall through to add IP fields */
  1024. case SCTP_V6_FLOW:
  1025. case AH_ESP_V6_FLOW:
  1026. case AH_V6_FLOW:
  1027. case ESP_V6_FLOW:
  1028. case IPV6_FLOW:
  1029. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  1030. break;
  1031. default:
  1032. return -EINVAL;
  1033. }
  1034. return 0;
  1035. }
  1036. /**
  1037. * i40e_get_ethtool_fdir_all - Populates the rule count of a command
  1038. * @pf: Pointer to the physical function struct
  1039. * @cmd: The command to get or set Rx flow classification rules
  1040. * @rule_locs: Array of used rule locations
  1041. *
  1042. * This function populates both the total and actual rule count of
  1043. * the ethtool flow classification command
  1044. *
  1045. * Returns 0 on success or -EMSGSIZE if entry not found
  1046. **/
  1047. static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
  1048. struct ethtool_rxnfc *cmd,
  1049. u32 *rule_locs)
  1050. {
  1051. struct i40e_fdir_filter *rule;
  1052. struct hlist_node *node2;
  1053. int cnt = 0;
  1054. /* report total rule count */
  1055. cmd->data = i40e_get_fd_cnt_all(pf);
  1056. hlist_for_each_entry_safe(rule, node2,
  1057. &pf->fdir_filter_list, fdir_node) {
  1058. if (cnt == cmd->rule_cnt)
  1059. return -EMSGSIZE;
  1060. rule_locs[cnt] = rule->fd_id;
  1061. cnt++;
  1062. }
  1063. cmd->rule_cnt = cnt;
  1064. return 0;
  1065. }
  1066. /**
  1067. * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
  1068. * @pf: Pointer to the physical function struct
  1069. * @cmd: The command to get or set Rx flow classification rules
  1070. *
  1071. * This function looks up a filter based on the Rx flow classification
  1072. * command and fills the flow spec info for it if found
  1073. *
  1074. * Returns 0 on success or -EINVAL if filter not found
  1075. **/
  1076. static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
  1077. struct ethtool_rxnfc *cmd)
  1078. {
  1079. struct ethtool_rx_flow_spec *fsp =
  1080. (struct ethtool_rx_flow_spec *)&cmd->fs;
  1081. struct i40e_fdir_filter *rule = NULL;
  1082. struct hlist_node *node2;
  1083. hlist_for_each_entry_safe(rule, node2,
  1084. &pf->fdir_filter_list, fdir_node) {
  1085. if (fsp->location <= rule->fd_id)
  1086. break;
  1087. }
  1088. if (!rule || fsp->location != rule->fd_id)
  1089. return -EINVAL;
  1090. fsp->flow_type = rule->flow_type;
  1091. if (fsp->flow_type == IP_USER_FLOW) {
  1092. fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
  1093. fsp->h_u.usr_ip4_spec.proto = 0;
  1094. fsp->m_u.usr_ip4_spec.proto = 0;
  1095. }
  1096. fsp->h_u.tcp_ip4_spec.psrc = rule->src_port;
  1097. fsp->h_u.tcp_ip4_spec.pdst = rule->dst_port;
  1098. fsp->h_u.tcp_ip4_spec.ip4src = rule->src_ip[0];
  1099. fsp->h_u.tcp_ip4_spec.ip4dst = rule->dst_ip[0];
  1100. fsp->ring_cookie = rule->q_index;
  1101. return 0;
  1102. }
  1103. /**
  1104. * i40e_get_rxnfc - command to get RX flow classification rules
  1105. * @netdev: network interface device structure
  1106. * @cmd: ethtool rxnfc command
  1107. *
  1108. * Returns Success if the command is supported.
  1109. **/
  1110. static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
  1111. u32 *rule_locs)
  1112. {
  1113. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1114. struct i40e_vsi *vsi = np->vsi;
  1115. struct i40e_pf *pf = vsi->back;
  1116. int ret = -EOPNOTSUPP;
  1117. switch (cmd->cmd) {
  1118. case ETHTOOL_GRXRINGS:
  1119. cmd->data = vsi->alloc_queue_pairs;
  1120. ret = 0;
  1121. break;
  1122. case ETHTOOL_GRXFH:
  1123. ret = i40e_get_rss_hash_opts(pf, cmd);
  1124. break;
  1125. case ETHTOOL_GRXCLSRLCNT:
  1126. cmd->rule_cnt = pf->fdir_pf_active_filters;
  1127. /* report total rule count */
  1128. cmd->data = i40e_get_fd_cnt_all(pf);
  1129. ret = 0;
  1130. break;
  1131. case ETHTOOL_GRXCLSRULE:
  1132. ret = i40e_get_ethtool_fdir_entry(pf, cmd);
  1133. break;
  1134. case ETHTOOL_GRXCLSRLALL:
  1135. ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
  1136. break;
  1137. default:
  1138. break;
  1139. }
  1140. return ret;
  1141. }
  1142. /**
  1143. * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
  1144. * @pf: pointer to the physical function struct
  1145. * @cmd: ethtool rxnfc command
  1146. *
  1147. * Returns Success if the flow input set is supported.
  1148. **/
  1149. static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
  1150. {
  1151. struct i40e_hw *hw = &pf->hw;
  1152. u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
  1153. ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
  1154. /* RSS does not support anything other than hashing
  1155. * to queues on src and dst IPs and ports
  1156. */
  1157. if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
  1158. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  1159. return -EINVAL;
  1160. /* We need at least the IP SRC and DEST fields for hashing */
  1161. if (!(nfc->data & RXH_IP_SRC) ||
  1162. !(nfc->data & RXH_IP_DST))
  1163. return -EINVAL;
  1164. switch (nfc->flow_type) {
  1165. case TCP_V4_FLOW:
  1166. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1167. case 0:
  1168. hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  1169. break;
  1170. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  1171. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  1172. break;
  1173. default:
  1174. return -EINVAL;
  1175. }
  1176. break;
  1177. case TCP_V6_FLOW:
  1178. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1179. case 0:
  1180. hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  1181. break;
  1182. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  1183. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  1184. break;
  1185. default:
  1186. return -EINVAL;
  1187. }
  1188. break;
  1189. case UDP_V4_FLOW:
  1190. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1191. case 0:
  1192. hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
  1193. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
  1194. break;
  1195. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  1196. hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
  1197. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
  1198. break;
  1199. default:
  1200. return -EINVAL;
  1201. }
  1202. break;
  1203. case UDP_V6_FLOW:
  1204. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1205. case 0:
  1206. hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
  1207. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
  1208. break;
  1209. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  1210. hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
  1211. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
  1212. break;
  1213. default:
  1214. return -EINVAL;
  1215. }
  1216. break;
  1217. case AH_ESP_V4_FLOW:
  1218. case AH_V4_FLOW:
  1219. case ESP_V4_FLOW:
  1220. case SCTP_V4_FLOW:
  1221. if ((nfc->data & RXH_L4_B_0_1) ||
  1222. (nfc->data & RXH_L4_B_2_3))
  1223. return -EINVAL;
  1224. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
  1225. break;
  1226. case AH_ESP_V6_FLOW:
  1227. case AH_V6_FLOW:
  1228. case ESP_V6_FLOW:
  1229. case SCTP_V6_FLOW:
  1230. if ((nfc->data & RXH_L4_B_0_1) ||
  1231. (nfc->data & RXH_L4_B_2_3))
  1232. return -EINVAL;
  1233. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
  1234. break;
  1235. case IPV4_FLOW:
  1236. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
  1237. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
  1238. break;
  1239. case IPV6_FLOW:
  1240. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
  1241. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
  1242. break;
  1243. default:
  1244. return -EINVAL;
  1245. }
  1246. wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
  1247. wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  1248. i40e_flush(hw);
  1249. return 0;
  1250. }
  1251. /**
  1252. * i40e_match_fdir_input_set - Match a new filter against an existing one
  1253. * @rule: The filter already added
  1254. * @input: The new filter to comapre against
  1255. *
  1256. * Returns true if the two input set match
  1257. **/
  1258. static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
  1259. struct i40e_fdir_filter *input)
  1260. {
  1261. if ((rule->dst_ip[0] != input->dst_ip[0]) ||
  1262. (rule->src_ip[0] != input->src_ip[0]) ||
  1263. (rule->dst_port != input->dst_port) ||
  1264. (rule->src_port != input->src_port))
  1265. return false;
  1266. return true;
  1267. }
  1268. /**
  1269. * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
  1270. * @vsi: Pointer to the targeted VSI
  1271. * @input: The filter to update or NULL to indicate deletion
  1272. * @sw_idx: Software index to the filter
  1273. * @cmd: The command to get or set Rx flow classification rules
  1274. *
  1275. * This function updates (or deletes) a Flow Director entry from
  1276. * the hlist of the corresponding PF
  1277. *
  1278. * Returns 0 on success
  1279. **/
  1280. static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
  1281. struct i40e_fdir_filter *input,
  1282. u16 sw_idx,
  1283. struct ethtool_rxnfc *cmd)
  1284. {
  1285. struct i40e_fdir_filter *rule, *parent;
  1286. struct i40e_pf *pf = vsi->back;
  1287. struct hlist_node *node2;
  1288. int err = -EINVAL;
  1289. parent = NULL;
  1290. rule = NULL;
  1291. hlist_for_each_entry_safe(rule, node2,
  1292. &pf->fdir_filter_list, fdir_node) {
  1293. /* hash found, or no matching entry */
  1294. if (rule->fd_id >= sw_idx)
  1295. break;
  1296. parent = rule;
  1297. }
  1298. /* if there is an old rule occupying our place remove it */
  1299. if (rule && (rule->fd_id == sw_idx)) {
  1300. if (input && !i40e_match_fdir_input_set(rule, input))
  1301. err = i40e_add_del_fdir(vsi, rule, false);
  1302. else if (!input)
  1303. err = i40e_add_del_fdir(vsi, rule, false);
  1304. hlist_del(&rule->fdir_node);
  1305. kfree(rule);
  1306. pf->fdir_pf_active_filters--;
  1307. }
  1308. /* If no input this was a delete, err should be 0 if a rule was
  1309. * successfully found and removed from the list else -EINVAL
  1310. */
  1311. if (!input)
  1312. return err;
  1313. /* initialize node and set software index */
  1314. INIT_HLIST_NODE(&input->fdir_node);
  1315. /* add filter to the list */
  1316. if (parent)
  1317. hlist_add_after(&parent->fdir_node, &input->fdir_node);
  1318. else
  1319. hlist_add_head(&input->fdir_node,
  1320. &pf->fdir_filter_list);
  1321. /* update counts */
  1322. pf->fdir_pf_active_filters++;
  1323. return 0;
  1324. }
  1325. /**
  1326. * i40e_del_fdir_entry - Deletes a Flow Director filter entry
  1327. * @vsi: Pointer to the targeted VSI
  1328. * @cmd: The command to get or set Rx flow classification rules
  1329. *
  1330. * The function removes a Flow Director filter entry from the
  1331. * hlist of the corresponding PF
  1332. *
  1333. * Returns 0 on success
  1334. */
  1335. static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
  1336. struct ethtool_rxnfc *cmd)
  1337. {
  1338. struct ethtool_rx_flow_spec *fsp =
  1339. (struct ethtool_rx_flow_spec *)&cmd->fs;
  1340. struct i40e_pf *pf = vsi->back;
  1341. int ret = 0;
  1342. ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
  1343. i40e_fdir_check_and_reenable(pf);
  1344. return ret;
  1345. }
  1346. /**
  1347. * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
  1348. * @vsi: pointer to the targeted VSI
  1349. * @cmd: command to get or set RX flow classification rules
  1350. *
  1351. * Add Flow Director filters for a specific flow spec based on their
  1352. * protocol. Returns 0 if the filters were successfully added.
  1353. **/
  1354. static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
  1355. struct ethtool_rxnfc *cmd)
  1356. {
  1357. struct ethtool_rx_flow_spec *fsp;
  1358. struct i40e_fdir_filter *input;
  1359. struct i40e_pf *pf;
  1360. int ret = -EINVAL;
  1361. if (!vsi)
  1362. return -EINVAL;
  1363. pf = vsi->back;
  1364. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  1365. return -EOPNOTSUPP;
  1366. if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
  1367. return -ENOSPC;
  1368. fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
  1369. if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
  1370. pf->hw.func_caps.fd_filters_guaranteed)) {
  1371. return -EINVAL;
  1372. }
  1373. if (fsp->ring_cookie >= vsi->num_queue_pairs)
  1374. return -EINVAL;
  1375. input = kzalloc(sizeof(*input), GFP_KERNEL);
  1376. if (!input)
  1377. return -ENOMEM;
  1378. input->fd_id = fsp->location;
  1379. if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
  1380. input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
  1381. else
  1382. input->dest_ctl =
  1383. I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
  1384. input->q_index = fsp->ring_cookie;
  1385. input->flex_off = 0;
  1386. input->pctype = 0;
  1387. input->dest_vsi = vsi->id;
  1388. input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
  1389. input->cnt_index = 0;
  1390. input->flow_type = fsp->flow_type;
  1391. input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
  1392. input->src_port = fsp->h_u.tcp_ip4_spec.psrc;
  1393. input->dst_port = fsp->h_u.tcp_ip4_spec.pdst;
  1394. input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
  1395. input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
  1396. ret = i40e_add_del_fdir(vsi, input, true);
  1397. if (ret)
  1398. kfree(input);
  1399. else
  1400. i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
  1401. return ret;
  1402. }
  1403. /**
  1404. * i40e_set_rxnfc - command to set RX flow classification rules
  1405. * @netdev: network interface device structure
  1406. * @cmd: ethtool rxnfc command
  1407. *
  1408. * Returns Success if the command is supported.
  1409. **/
  1410. static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
  1411. {
  1412. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1413. struct i40e_vsi *vsi = np->vsi;
  1414. struct i40e_pf *pf = vsi->back;
  1415. int ret = -EOPNOTSUPP;
  1416. switch (cmd->cmd) {
  1417. case ETHTOOL_SRXFH:
  1418. ret = i40e_set_rss_hash_opt(pf, cmd);
  1419. break;
  1420. case ETHTOOL_SRXCLSRLINS:
  1421. ret = i40e_add_fdir_ethtool(vsi, cmd);
  1422. break;
  1423. case ETHTOOL_SRXCLSRLDEL:
  1424. ret = i40e_del_fdir_entry(vsi, cmd);
  1425. break;
  1426. default:
  1427. break;
  1428. }
  1429. return ret;
  1430. }
  1431. /**
  1432. * i40e_max_channels - get Max number of combined channels supported
  1433. * @vsi: vsi pointer
  1434. **/
  1435. static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
  1436. {
  1437. /* TODO: This code assumes DCB and FD is disabled for now. */
  1438. return vsi->alloc_queue_pairs;
  1439. }
  1440. /**
  1441. * i40e_get_channels - Get the current channels enabled and max supported etc.
  1442. * @netdev: network interface device structure
  1443. * @ch: ethtool channels structure
  1444. *
  1445. * We don't support separate tx and rx queues as channels. The other count
  1446. * represents how many queues are being used for control. max_combined counts
  1447. * how many queue pairs we can support. They may not be mapped 1 to 1 with
  1448. * q_vectors since we support a lot more queue pairs than q_vectors.
  1449. **/
  1450. static void i40e_get_channels(struct net_device *dev,
  1451. struct ethtool_channels *ch)
  1452. {
  1453. struct i40e_netdev_priv *np = netdev_priv(dev);
  1454. struct i40e_vsi *vsi = np->vsi;
  1455. struct i40e_pf *pf = vsi->back;
  1456. /* report maximum channels */
  1457. ch->max_combined = i40e_max_channels(vsi);
  1458. /* report info for other vector */
  1459. ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
  1460. ch->max_other = ch->other_count;
  1461. /* Note: This code assumes DCB is disabled for now. */
  1462. ch->combined_count = vsi->num_queue_pairs;
  1463. }
  1464. /**
  1465. * i40e_set_channels - Set the new channels count.
  1466. * @netdev: network interface device structure
  1467. * @ch: ethtool channels structure
  1468. *
  1469. * The new channels count may not be the same as requested by the user
  1470. * since it gets rounded down to a power of 2 value.
  1471. **/
  1472. static int i40e_set_channels(struct net_device *dev,
  1473. struct ethtool_channels *ch)
  1474. {
  1475. struct i40e_netdev_priv *np = netdev_priv(dev);
  1476. unsigned int count = ch->combined_count;
  1477. struct i40e_vsi *vsi = np->vsi;
  1478. struct i40e_pf *pf = vsi->back;
  1479. int new_count;
  1480. /* We do not support setting channels for any other VSI at present */
  1481. if (vsi->type != I40E_VSI_MAIN)
  1482. return -EINVAL;
  1483. /* verify they are not requesting separate vectors */
  1484. if (!count || ch->rx_count || ch->tx_count)
  1485. return -EINVAL;
  1486. /* verify other_count has not changed */
  1487. if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
  1488. return -EINVAL;
  1489. /* verify the number of channels does not exceed hardware limits */
  1490. if (count > i40e_max_channels(vsi))
  1491. return -EINVAL;
  1492. /* update feature limits from largest to smallest supported values */
  1493. /* TODO: Flow director limit, DCB etc */
  1494. /* cap RSS limit */
  1495. if (count > pf->rss_size_max)
  1496. count = pf->rss_size_max;
  1497. /* use rss_reconfig to rebuild with new queue count and update traffic
  1498. * class queue mapping
  1499. */
  1500. new_count = i40e_reconfig_rss_queues(pf, count);
  1501. if (new_count > 0)
  1502. return 0;
  1503. else
  1504. return -EINVAL;
  1505. }
  1506. static const struct ethtool_ops i40e_ethtool_ops = {
  1507. .get_settings = i40e_get_settings,
  1508. .get_drvinfo = i40e_get_drvinfo,
  1509. .get_regs_len = i40e_get_regs_len,
  1510. .get_regs = i40e_get_regs,
  1511. .nway_reset = i40e_nway_reset,
  1512. .get_link = ethtool_op_get_link,
  1513. .get_wol = i40e_get_wol,
  1514. .set_wol = i40e_set_wol,
  1515. .get_eeprom_len = i40e_get_eeprom_len,
  1516. .get_eeprom = i40e_get_eeprom,
  1517. .get_ringparam = i40e_get_ringparam,
  1518. .set_ringparam = i40e_set_ringparam,
  1519. .get_pauseparam = i40e_get_pauseparam,
  1520. .get_msglevel = i40e_get_msglevel,
  1521. .set_msglevel = i40e_set_msglevel,
  1522. .get_rxnfc = i40e_get_rxnfc,
  1523. .set_rxnfc = i40e_set_rxnfc,
  1524. .self_test = i40e_diag_test,
  1525. .get_strings = i40e_get_strings,
  1526. .set_phys_id = i40e_set_phys_id,
  1527. .get_sset_count = i40e_get_sset_count,
  1528. .get_ethtool_stats = i40e_get_ethtool_stats,
  1529. .get_coalesce = i40e_get_coalesce,
  1530. .set_coalesce = i40e_set_coalesce,
  1531. .get_channels = i40e_get_channels,
  1532. .set_channels = i40e_set_channels,
  1533. .get_ts_info = i40e_get_ts_info,
  1534. };
  1535. void i40e_set_ethtool_ops(struct net_device *netdev)
  1536. {
  1537. netdev->ethtool_ops = &i40e_ethtool_ops;
  1538. }