i40e_ethtool.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 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 with
  16. * this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * The full GNU General Public License is included in this distribution in
  20. * the file called "COPYING".
  21. *
  22. * Contact Information:
  23. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  24. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  25. *
  26. ******************************************************************************/
  27. /* ethtool support for i40e */
  28. #include "i40e.h"
  29. #include "i40e_diag.h"
  30. struct i40e_stats {
  31. char stat_string[ETH_GSTRING_LEN];
  32. int sizeof_stat;
  33. int stat_offset;
  34. };
  35. #define I40E_STAT(_type, _name, _stat) { \
  36. .stat_string = _name, \
  37. .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
  38. .stat_offset = offsetof(_type, _stat) \
  39. }
  40. #define I40E_NETDEV_STAT(_net_stat) \
  41. I40E_STAT(struct net_device_stats, #_net_stat, _net_stat)
  42. #define I40E_PF_STAT(_name, _stat) \
  43. I40E_STAT(struct i40e_pf, _name, _stat)
  44. #define I40E_VSI_STAT(_name, _stat) \
  45. I40E_STAT(struct i40e_vsi, _name, _stat)
  46. static const struct i40e_stats i40e_gstrings_net_stats[] = {
  47. I40E_NETDEV_STAT(rx_packets),
  48. I40E_NETDEV_STAT(tx_packets),
  49. I40E_NETDEV_STAT(rx_bytes),
  50. I40E_NETDEV_STAT(tx_bytes),
  51. I40E_NETDEV_STAT(rx_errors),
  52. I40E_NETDEV_STAT(tx_errors),
  53. I40E_NETDEV_STAT(rx_dropped),
  54. I40E_NETDEV_STAT(tx_dropped),
  55. I40E_NETDEV_STAT(multicast),
  56. I40E_NETDEV_STAT(collisions),
  57. I40E_NETDEV_STAT(rx_length_errors),
  58. I40E_NETDEV_STAT(rx_crc_errors),
  59. };
  60. /* These PF_STATs might look like duplicates of some NETDEV_STATs,
  61. * but they are separate. This device supports Virtualization, and
  62. * as such might have several netdevs supporting VMDq and FCoE going
  63. * through a single port. The NETDEV_STATs are for individual netdevs
  64. * seen at the top of the stack, and the PF_STATs are for the physical
  65. * function at the bottom of the stack hosting those netdevs.
  66. *
  67. * The PF_STATs are appended to the netdev stats only when ethtool -S
  68. * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
  69. */
  70. static struct i40e_stats i40e_gstrings_stats[] = {
  71. I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
  72. I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
  73. I40E_PF_STAT("rx_errors", stats.eth.rx_errors),
  74. I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
  75. I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
  76. I40E_PF_STAT("tx_dropped", stats.eth.tx_discards),
  77. I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
  78. I40E_PF_STAT("crc_errors", stats.crc_errors),
  79. I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
  80. I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
  81. I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
  82. I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
  83. I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
  84. I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
  85. I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
  86. I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
  87. I40E_PF_STAT("rx_size_64", stats.rx_size_64),
  88. I40E_PF_STAT("rx_size_127", stats.rx_size_127),
  89. I40E_PF_STAT("rx_size_255", stats.rx_size_255),
  90. I40E_PF_STAT("rx_size_511", stats.rx_size_511),
  91. I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
  92. I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
  93. I40E_PF_STAT("rx_size_big", stats.rx_size_big),
  94. I40E_PF_STAT("tx_size_64", stats.tx_size_64),
  95. I40E_PF_STAT("tx_size_127", stats.tx_size_127),
  96. I40E_PF_STAT("tx_size_255", stats.tx_size_255),
  97. I40E_PF_STAT("tx_size_511", stats.tx_size_511),
  98. I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
  99. I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
  100. I40E_PF_STAT("tx_size_big", stats.tx_size_big),
  101. I40E_PF_STAT("rx_undersize", stats.rx_undersize),
  102. I40E_PF_STAT("rx_fragments", stats.rx_fragments),
  103. I40E_PF_STAT("rx_oversize", stats.rx_oversize),
  104. I40E_PF_STAT("rx_jabber", stats.rx_jabber),
  105. I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
  106. };
  107. #define I40E_QUEUE_STATS_LEN(n) \
  108. ((((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs + \
  109. ((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs) * 2)
  110. #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
  111. #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
  112. #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
  113. I40E_QUEUE_STATS_LEN((n)))
  114. #define I40E_PFC_STATS_LEN ( \
  115. (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
  116. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
  117. FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
  118. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
  119. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
  120. / sizeof(u64))
  121. #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
  122. I40E_PFC_STATS_LEN + \
  123. I40E_VSI_STATS_LEN((n)))
  124. enum i40e_ethtool_test_id {
  125. I40E_ETH_TEST_REG = 0,
  126. I40E_ETH_TEST_EEPROM,
  127. I40E_ETH_TEST_INTR,
  128. I40E_ETH_TEST_LOOPBACK,
  129. I40E_ETH_TEST_LINK,
  130. };
  131. static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
  132. "Register test (offline)",
  133. "Eeprom test (offline)",
  134. "Interrupt test (offline)",
  135. "Loopback test (offline)",
  136. "Link test (on/offline)"
  137. };
  138. #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
  139. /**
  140. * i40e_get_settings - Get Link Speed and Duplex settings
  141. * @netdev: network interface device structure
  142. * @ecmd: ethtool command
  143. *
  144. * Reports speed/duplex settings based on media_type
  145. **/
  146. static int i40e_get_settings(struct net_device *netdev,
  147. struct ethtool_cmd *ecmd)
  148. {
  149. struct i40e_netdev_priv *np = netdev_priv(netdev);
  150. struct i40e_pf *pf = np->vsi->back;
  151. struct i40e_hw *hw = &pf->hw;
  152. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  153. bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
  154. u32 link_speed = hw_link_info->link_speed;
  155. /* hardware is either in 40G mode or 10G mode
  156. * NOTE: this section initializes supported and advertising
  157. */
  158. switch (hw_link_info->phy_type) {
  159. case I40E_PHY_TYPE_40GBASE_CR4:
  160. case I40E_PHY_TYPE_40GBASE_CR4_CU:
  161. ecmd->supported = SUPPORTED_40000baseCR4_Full;
  162. ecmd->advertising = ADVERTISED_40000baseCR4_Full;
  163. break;
  164. case I40E_PHY_TYPE_40GBASE_KR4:
  165. ecmd->supported = SUPPORTED_40000baseKR4_Full;
  166. ecmd->advertising = ADVERTISED_40000baseKR4_Full;
  167. break;
  168. case I40E_PHY_TYPE_40GBASE_SR4:
  169. ecmd->supported = SUPPORTED_40000baseSR4_Full;
  170. ecmd->advertising = ADVERTISED_40000baseSR4_Full;
  171. break;
  172. case I40E_PHY_TYPE_40GBASE_LR4:
  173. ecmd->supported = SUPPORTED_40000baseLR4_Full;
  174. ecmd->advertising = ADVERTISED_40000baseLR4_Full;
  175. break;
  176. case I40E_PHY_TYPE_10GBASE_KX4:
  177. ecmd->supported = SUPPORTED_10000baseKX4_Full;
  178. ecmd->advertising = ADVERTISED_10000baseKX4_Full;
  179. break;
  180. case I40E_PHY_TYPE_10GBASE_KR:
  181. ecmd->supported = SUPPORTED_10000baseKR_Full;
  182. ecmd->advertising = ADVERTISED_10000baseKR_Full;
  183. break;
  184. case I40E_PHY_TYPE_10GBASE_T:
  185. default:
  186. ecmd->supported = SUPPORTED_10000baseT_Full;
  187. ecmd->advertising = ADVERTISED_10000baseT_Full;
  188. break;
  189. }
  190. /* for now just say autoneg all the time */
  191. ecmd->supported |= SUPPORTED_Autoneg;
  192. if (hw->phy.media_type == I40E_MEDIA_TYPE_BACKPLANE) {
  193. ecmd->supported |= SUPPORTED_Backplane;
  194. ecmd->advertising |= ADVERTISED_Backplane;
  195. ecmd->port = PORT_NONE;
  196. } else if (hw->phy.media_type == I40E_MEDIA_TYPE_BASET) {
  197. ecmd->supported |= SUPPORTED_TP;
  198. ecmd->advertising |= ADVERTISED_TP;
  199. ecmd->port = PORT_TP;
  200. } else {
  201. ecmd->supported |= SUPPORTED_FIBRE;
  202. ecmd->advertising |= ADVERTISED_FIBRE;
  203. ecmd->port = PORT_FIBRE;
  204. }
  205. ecmd->transceiver = XCVR_EXTERNAL;
  206. if (link_up) {
  207. switch (link_speed) {
  208. case I40E_LINK_SPEED_40GB:
  209. /* need a SPEED_40000 in ethtool.h */
  210. ethtool_cmd_speed_set(ecmd, 40000);
  211. break;
  212. case I40E_LINK_SPEED_10GB:
  213. ethtool_cmd_speed_set(ecmd, SPEED_10000);
  214. break;
  215. default:
  216. break;
  217. }
  218. ecmd->duplex = DUPLEX_FULL;
  219. } else {
  220. ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
  221. ecmd->duplex = DUPLEX_UNKNOWN;
  222. }
  223. return 0;
  224. }
  225. /**
  226. * i40e_get_pauseparam - Get Flow Control status
  227. * Return tx/rx-pause status
  228. **/
  229. static void i40e_get_pauseparam(struct net_device *netdev,
  230. struct ethtool_pauseparam *pause)
  231. {
  232. struct i40e_netdev_priv *np = netdev_priv(netdev);
  233. struct i40e_pf *pf = np->vsi->back;
  234. struct i40e_hw *hw = &pf->hw;
  235. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  236. pause->autoneg =
  237. ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  238. AUTONEG_ENABLE : AUTONEG_DISABLE);
  239. pause->rx_pause = 0;
  240. pause->tx_pause = 0;
  241. if (hw_link_info->an_info & I40E_AQ_LINK_PAUSE_RX)
  242. pause->rx_pause = 1;
  243. if (hw_link_info->an_info & I40E_AQ_LINK_PAUSE_TX)
  244. pause->tx_pause = 1;
  245. }
  246. static u32 i40e_get_msglevel(struct net_device *netdev)
  247. {
  248. struct i40e_netdev_priv *np = netdev_priv(netdev);
  249. struct i40e_pf *pf = np->vsi->back;
  250. return pf->msg_enable;
  251. }
  252. static void i40e_set_msglevel(struct net_device *netdev, u32 data)
  253. {
  254. struct i40e_netdev_priv *np = netdev_priv(netdev);
  255. struct i40e_pf *pf = np->vsi->back;
  256. if (I40E_DEBUG_USER & data)
  257. pf->hw.debug_mask = data;
  258. pf->msg_enable = data;
  259. }
  260. static int i40e_get_regs_len(struct net_device *netdev)
  261. {
  262. int reg_count = 0;
  263. int i;
  264. for (i = 0; i40e_reg_list[i].offset != 0; i++)
  265. reg_count += i40e_reg_list[i].elements;
  266. return reg_count * sizeof(u32);
  267. }
  268. static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
  269. void *p)
  270. {
  271. struct i40e_netdev_priv *np = netdev_priv(netdev);
  272. struct i40e_pf *pf = np->vsi->back;
  273. struct i40e_hw *hw = &pf->hw;
  274. u32 *reg_buf = p;
  275. int i, j, ri;
  276. u32 reg;
  277. /* Tell ethtool which driver-version-specific regs output we have.
  278. *
  279. * At some point, if we have ethtool doing special formatting of
  280. * this data, it will rely on this version number to know how to
  281. * interpret things. Hence, this needs to be updated if/when the
  282. * diags register table is changed.
  283. */
  284. regs->version = 1;
  285. /* loop through the diags reg table for what to print */
  286. ri = 0;
  287. for (i = 0; i40e_reg_list[i].offset != 0; i++) {
  288. for (j = 0; j < i40e_reg_list[i].elements; j++) {
  289. reg = i40e_reg_list[i].offset
  290. + (j * i40e_reg_list[i].stride);
  291. reg_buf[ri++] = rd32(hw, reg);
  292. }
  293. }
  294. }
  295. static int i40e_get_eeprom(struct net_device *netdev,
  296. struct ethtool_eeprom *eeprom, u8 *bytes)
  297. {
  298. struct i40e_netdev_priv *np = netdev_priv(netdev);
  299. struct i40e_hw *hw = &np->vsi->back->hw;
  300. int first_word, last_word;
  301. u16 i, eeprom_len;
  302. u16 *eeprom_buff;
  303. int ret_val = 0;
  304. if (eeprom->len == 0)
  305. return -EINVAL;
  306. eeprom->magic = hw->vendor_id | (hw->device_id << 16);
  307. first_word = eeprom->offset >> 1;
  308. last_word = (eeprom->offset + eeprom->len - 1) >> 1;
  309. eeprom_len = last_word - first_word + 1;
  310. eeprom_buff = kmalloc(sizeof(u16) * eeprom_len, GFP_KERNEL);
  311. if (!eeprom_buff)
  312. return -ENOMEM;
  313. ret_val = i40e_read_nvm_buffer(hw, first_word, &eeprom_len,
  314. eeprom_buff);
  315. if (eeprom_len == 0) {
  316. kfree(eeprom_buff);
  317. return -EACCES;
  318. }
  319. /* Device's eeprom is always little-endian, word addressable */
  320. for (i = 0; i < eeprom_len; i++)
  321. le16_to_cpus(&eeprom_buff[i]);
  322. memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
  323. kfree(eeprom_buff);
  324. return ret_val;
  325. }
  326. static int i40e_get_eeprom_len(struct net_device *netdev)
  327. {
  328. struct i40e_netdev_priv *np = netdev_priv(netdev);
  329. struct i40e_hw *hw = &np->vsi->back->hw;
  330. return hw->nvm.sr_size * 2;
  331. }
  332. static void i40e_get_drvinfo(struct net_device *netdev,
  333. struct ethtool_drvinfo *drvinfo)
  334. {
  335. struct i40e_netdev_priv *np = netdev_priv(netdev);
  336. struct i40e_vsi *vsi = np->vsi;
  337. struct i40e_pf *pf = vsi->back;
  338. strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
  339. strlcpy(drvinfo->version, i40e_driver_version_str,
  340. sizeof(drvinfo->version));
  341. strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
  342. sizeof(drvinfo->fw_version));
  343. strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
  344. sizeof(drvinfo->bus_info));
  345. }
  346. static void i40e_get_ringparam(struct net_device *netdev,
  347. struct ethtool_ringparam *ring)
  348. {
  349. struct i40e_netdev_priv *np = netdev_priv(netdev);
  350. struct i40e_pf *pf = np->vsi->back;
  351. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  352. ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  353. ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  354. ring->rx_mini_max_pending = 0;
  355. ring->rx_jumbo_max_pending = 0;
  356. ring->rx_pending = vsi->rx_rings[0].count;
  357. ring->tx_pending = vsi->tx_rings[0].count;
  358. ring->rx_mini_pending = 0;
  359. ring->rx_jumbo_pending = 0;
  360. }
  361. static int i40e_set_ringparam(struct net_device *netdev,
  362. struct ethtool_ringparam *ring)
  363. {
  364. struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
  365. struct i40e_netdev_priv *np = netdev_priv(netdev);
  366. struct i40e_vsi *vsi = np->vsi;
  367. struct i40e_pf *pf = vsi->back;
  368. u32 new_rx_count, new_tx_count;
  369. int i, err = 0;
  370. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  371. return -EINVAL;
  372. new_tx_count = clamp_t(u32, ring->tx_pending,
  373. I40E_MIN_NUM_DESCRIPTORS,
  374. I40E_MAX_NUM_DESCRIPTORS);
  375. new_tx_count = ALIGN(new_tx_count, I40E_REQ_DESCRIPTOR_MULTIPLE);
  376. new_rx_count = clamp_t(u32, ring->rx_pending,
  377. I40E_MIN_NUM_DESCRIPTORS,
  378. I40E_MAX_NUM_DESCRIPTORS);
  379. new_rx_count = ALIGN(new_rx_count, I40E_REQ_DESCRIPTOR_MULTIPLE);
  380. /* if nothing to do return success */
  381. if ((new_tx_count == vsi->tx_rings[0].count) &&
  382. (new_rx_count == vsi->rx_rings[0].count))
  383. return 0;
  384. while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
  385. usleep_range(1000, 2000);
  386. if (!netif_running(vsi->netdev)) {
  387. /* simple case - set for the next time the netdev is started */
  388. for (i = 0; i < vsi->num_queue_pairs; i++) {
  389. vsi->tx_rings[i].count = new_tx_count;
  390. vsi->rx_rings[i].count = new_rx_count;
  391. }
  392. goto done;
  393. }
  394. /* We can't just free everything and then setup again,
  395. * because the ISRs in MSI-X mode get passed pointers
  396. * to the Tx and Rx ring structs.
  397. */
  398. /* alloc updated Tx resources */
  399. if (new_tx_count != vsi->tx_rings[0].count) {
  400. netdev_info(netdev,
  401. "Changing Tx descriptor count from %d to %d.\n",
  402. vsi->tx_rings[0].count, new_tx_count);
  403. tx_rings = kcalloc(vsi->alloc_queue_pairs,
  404. sizeof(struct i40e_ring), GFP_KERNEL);
  405. if (!tx_rings) {
  406. err = -ENOMEM;
  407. goto done;
  408. }
  409. for (i = 0; i < vsi->num_queue_pairs; i++) {
  410. /* clone ring and setup updated count */
  411. tx_rings[i] = vsi->tx_rings[i];
  412. tx_rings[i].count = new_tx_count;
  413. err = i40e_setup_tx_descriptors(&tx_rings[i]);
  414. if (err) {
  415. while (i) {
  416. i--;
  417. i40e_free_tx_resources(&tx_rings[i]);
  418. }
  419. kfree(tx_rings);
  420. tx_rings = NULL;
  421. goto done;
  422. }
  423. }
  424. }
  425. /* alloc updated Rx resources */
  426. if (new_rx_count != vsi->rx_rings[0].count) {
  427. netdev_info(netdev,
  428. "Changing Rx descriptor count from %d to %d\n",
  429. vsi->rx_rings[0].count, new_rx_count);
  430. rx_rings = kcalloc(vsi->alloc_queue_pairs,
  431. sizeof(struct i40e_ring), GFP_KERNEL);
  432. if (!rx_rings) {
  433. err = -ENOMEM;
  434. goto free_tx;
  435. }
  436. for (i = 0; i < vsi->num_queue_pairs; i++) {
  437. /* clone ring and setup updated count */
  438. rx_rings[i] = vsi->rx_rings[i];
  439. rx_rings[i].count = new_rx_count;
  440. err = i40e_setup_rx_descriptors(&rx_rings[i]);
  441. if (err) {
  442. while (i) {
  443. i--;
  444. i40e_free_rx_resources(&rx_rings[i]);
  445. }
  446. kfree(rx_rings);
  447. rx_rings = NULL;
  448. goto free_tx;
  449. }
  450. }
  451. }
  452. /* Bring interface down, copy in the new ring info,
  453. * then restore the interface
  454. */
  455. i40e_down(vsi);
  456. if (tx_rings) {
  457. for (i = 0; i < vsi->num_queue_pairs; i++) {
  458. i40e_free_tx_resources(&vsi->tx_rings[i]);
  459. vsi->tx_rings[i] = tx_rings[i];
  460. }
  461. kfree(tx_rings);
  462. tx_rings = NULL;
  463. }
  464. if (rx_rings) {
  465. for (i = 0; i < vsi->num_queue_pairs; i++) {
  466. i40e_free_rx_resources(&vsi->rx_rings[i]);
  467. vsi->rx_rings[i] = rx_rings[i];
  468. }
  469. kfree(rx_rings);
  470. rx_rings = NULL;
  471. }
  472. i40e_up(vsi);
  473. free_tx:
  474. /* error cleanup if the Rx allocations failed after getting Tx */
  475. if (tx_rings) {
  476. for (i = 0; i < vsi->num_queue_pairs; i++)
  477. i40e_free_tx_resources(&tx_rings[i]);
  478. kfree(tx_rings);
  479. tx_rings = NULL;
  480. }
  481. done:
  482. clear_bit(__I40E_CONFIG_BUSY, &pf->state);
  483. return err;
  484. }
  485. static int i40e_get_sset_count(struct net_device *netdev, int sset)
  486. {
  487. struct i40e_netdev_priv *np = netdev_priv(netdev);
  488. struct i40e_vsi *vsi = np->vsi;
  489. struct i40e_pf *pf = vsi->back;
  490. switch (sset) {
  491. case ETH_SS_TEST:
  492. return I40E_TEST_LEN;
  493. case ETH_SS_STATS:
  494. if (vsi == pf->vsi[pf->lan_vsi])
  495. return I40E_PF_STATS_LEN(netdev);
  496. else
  497. return I40E_VSI_STATS_LEN(netdev);
  498. default:
  499. return -EOPNOTSUPP;
  500. }
  501. }
  502. static void i40e_get_ethtool_stats(struct net_device *netdev,
  503. struct ethtool_stats *stats, u64 *data)
  504. {
  505. struct i40e_netdev_priv *np = netdev_priv(netdev);
  506. struct i40e_vsi *vsi = np->vsi;
  507. struct i40e_pf *pf = vsi->back;
  508. int i = 0;
  509. char *p;
  510. int j;
  511. struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
  512. i40e_update_stats(vsi);
  513. for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
  514. p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
  515. data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
  516. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  517. }
  518. for (j = 0; j < vsi->num_queue_pairs; j++) {
  519. data[i++] = vsi->tx_rings[j].tx_stats.packets;
  520. data[i++] = vsi->tx_rings[j].tx_stats.bytes;
  521. }
  522. for (j = 0; j < vsi->num_queue_pairs; j++) {
  523. data[i++] = vsi->rx_rings[j].rx_stats.packets;
  524. data[i++] = vsi->rx_rings[j].rx_stats.bytes;
  525. }
  526. if (vsi == pf->vsi[pf->lan_vsi]) {
  527. for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
  528. p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
  529. data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
  530. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  531. }
  532. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  533. data[i++] = pf->stats.priority_xon_tx[j];
  534. data[i++] = pf->stats.priority_xoff_tx[j];
  535. }
  536. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  537. data[i++] = pf->stats.priority_xon_rx[j];
  538. data[i++] = pf->stats.priority_xoff_rx[j];
  539. }
  540. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
  541. data[i++] = pf->stats.priority_xon_2_xoff[j];
  542. }
  543. }
  544. static void i40e_get_strings(struct net_device *netdev, u32 stringset,
  545. u8 *data)
  546. {
  547. struct i40e_netdev_priv *np = netdev_priv(netdev);
  548. struct i40e_vsi *vsi = np->vsi;
  549. struct i40e_pf *pf = vsi->back;
  550. char *p = (char *)data;
  551. int i;
  552. switch (stringset) {
  553. case ETH_SS_TEST:
  554. for (i = 0; i < I40E_TEST_LEN; i++) {
  555. memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
  556. data += ETH_GSTRING_LEN;
  557. }
  558. break;
  559. case ETH_SS_STATS:
  560. for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
  561. snprintf(p, ETH_GSTRING_LEN, "%s",
  562. i40e_gstrings_net_stats[i].stat_string);
  563. p += ETH_GSTRING_LEN;
  564. }
  565. for (i = 0; i < vsi->num_queue_pairs; i++) {
  566. snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
  567. p += ETH_GSTRING_LEN;
  568. snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
  569. p += ETH_GSTRING_LEN;
  570. }
  571. for (i = 0; i < vsi->num_queue_pairs; i++) {
  572. snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
  573. p += ETH_GSTRING_LEN;
  574. snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
  575. p += ETH_GSTRING_LEN;
  576. }
  577. if (vsi == pf->vsi[pf->lan_vsi]) {
  578. for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
  579. snprintf(p, ETH_GSTRING_LEN, "port.%s",
  580. i40e_gstrings_stats[i].stat_string);
  581. p += ETH_GSTRING_LEN;
  582. }
  583. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  584. snprintf(p, ETH_GSTRING_LEN,
  585. "port.tx_priority_%u_xon", i);
  586. p += ETH_GSTRING_LEN;
  587. snprintf(p, ETH_GSTRING_LEN,
  588. "port.tx_priority_%u_xoff", i);
  589. p += ETH_GSTRING_LEN;
  590. }
  591. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  592. snprintf(p, ETH_GSTRING_LEN,
  593. "port.rx_priority_%u_xon", i);
  594. p += ETH_GSTRING_LEN;
  595. snprintf(p, ETH_GSTRING_LEN,
  596. "port.rx_priority_%u_xoff", i);
  597. p += ETH_GSTRING_LEN;
  598. }
  599. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  600. snprintf(p, ETH_GSTRING_LEN,
  601. "port.rx_priority_%u_xon_2_xoff", i);
  602. p += ETH_GSTRING_LEN;
  603. }
  604. }
  605. /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
  606. break;
  607. }
  608. }
  609. static int i40e_get_ts_info(struct net_device *dev,
  610. struct ethtool_ts_info *info)
  611. {
  612. return ethtool_op_get_ts_info(dev, info);
  613. }
  614. static int i40e_link_test(struct i40e_pf *pf, u64 *data)
  615. {
  616. if (i40e_get_link_status(&pf->hw))
  617. *data = 0;
  618. else
  619. *data = 1;
  620. return *data;
  621. }
  622. static int i40e_reg_test(struct i40e_pf *pf, u64 *data)
  623. {
  624. i40e_status ret;
  625. ret = i40e_diag_reg_test(&pf->hw);
  626. *data = ret;
  627. return ret;
  628. }
  629. static int i40e_eeprom_test(struct i40e_pf *pf, u64 *data)
  630. {
  631. i40e_status ret;
  632. ret = i40e_diag_eeprom_test(&pf->hw);
  633. *data = ret;
  634. return ret;
  635. }
  636. static int i40e_intr_test(struct i40e_pf *pf, u64 *data)
  637. {
  638. *data = -ENOSYS;
  639. return *data;
  640. }
  641. static int i40e_loopback_test(struct i40e_pf *pf, u64 *data)
  642. {
  643. *data = -ENOSYS;
  644. return *data;
  645. }
  646. static void i40e_diag_test(struct net_device *netdev,
  647. struct ethtool_test *eth_test, u64 *data)
  648. {
  649. struct i40e_netdev_priv *np = netdev_priv(netdev);
  650. struct i40e_pf *pf = np->vsi->back;
  651. set_bit(__I40E_TESTING, &pf->state);
  652. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  653. /* Offline tests */
  654. netdev_info(netdev, "offline testing starting\n");
  655. /* Link test performed before hardware reset
  656. * so autoneg doesn't interfere with test result
  657. */
  658. netdev_info(netdev, "link test starting\n");
  659. if (i40e_link_test(pf, &data[I40E_ETH_TEST_LINK]))
  660. eth_test->flags |= ETH_TEST_FL_FAILED;
  661. netdev_info(netdev, "register test starting\n");
  662. if (i40e_reg_test(pf, &data[I40E_ETH_TEST_REG]))
  663. eth_test->flags |= ETH_TEST_FL_FAILED;
  664. i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
  665. netdev_info(netdev, "eeprom test starting\n");
  666. if (i40e_eeprom_test(pf, &data[I40E_ETH_TEST_EEPROM]))
  667. eth_test->flags |= ETH_TEST_FL_FAILED;
  668. i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
  669. netdev_info(netdev, "interrupt test starting\n");
  670. if (i40e_intr_test(pf, &data[I40E_ETH_TEST_INTR]))
  671. eth_test->flags |= ETH_TEST_FL_FAILED;
  672. i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
  673. netdev_info(netdev, "loopback test starting\n");
  674. if (i40e_loopback_test(pf, &data[I40E_ETH_TEST_LOOPBACK]))
  675. eth_test->flags |= ETH_TEST_FL_FAILED;
  676. } else {
  677. netdev_info(netdev, "online test starting\n");
  678. /* Online tests */
  679. if (i40e_link_test(pf, &data[I40E_ETH_TEST_LINK]))
  680. eth_test->flags |= ETH_TEST_FL_FAILED;
  681. /* Offline only tests, not run in online; pass by default */
  682. data[I40E_ETH_TEST_REG] = 0;
  683. data[I40E_ETH_TEST_EEPROM] = 0;
  684. data[I40E_ETH_TEST_INTR] = 0;
  685. data[I40E_ETH_TEST_LOOPBACK] = 0;
  686. clear_bit(__I40E_TESTING, &pf->state);
  687. }
  688. }
  689. static void i40e_get_wol(struct net_device *netdev,
  690. struct ethtool_wolinfo *wol)
  691. {
  692. wol->supported = 0;
  693. wol->wolopts = 0;
  694. }
  695. static int i40e_nway_reset(struct net_device *netdev)
  696. {
  697. /* restart autonegotiation */
  698. struct i40e_netdev_priv *np = netdev_priv(netdev);
  699. struct i40e_pf *pf = np->vsi->back;
  700. struct i40e_hw *hw = &pf->hw;
  701. i40e_status ret = 0;
  702. ret = i40e_aq_set_link_restart_an(hw, NULL);
  703. if (ret) {
  704. netdev_info(netdev, "link restart failed, aq_err=%d\n",
  705. pf->hw.aq.asq_last_status);
  706. return -EIO;
  707. }
  708. return 0;
  709. }
  710. static int i40e_set_phys_id(struct net_device *netdev,
  711. enum ethtool_phys_id_state state)
  712. {
  713. struct i40e_netdev_priv *np = netdev_priv(netdev);
  714. struct i40e_pf *pf = np->vsi->back;
  715. struct i40e_hw *hw = &pf->hw;
  716. int blink_freq = 2;
  717. switch (state) {
  718. case ETHTOOL_ID_ACTIVE:
  719. pf->led_status = i40e_led_get(hw);
  720. return blink_freq;
  721. case ETHTOOL_ID_ON:
  722. i40e_led_set(hw, 0xF);
  723. break;
  724. case ETHTOOL_ID_OFF:
  725. i40e_led_set(hw, 0x0);
  726. break;
  727. case ETHTOOL_ID_INACTIVE:
  728. i40e_led_set(hw, pf->led_status);
  729. break;
  730. }
  731. return 0;
  732. }
  733. /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
  734. * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
  735. * 125us (8000 interrupts per second) == ITR(62)
  736. */
  737. static int i40e_get_coalesce(struct net_device *netdev,
  738. struct ethtool_coalesce *ec)
  739. {
  740. struct i40e_netdev_priv *np = netdev_priv(netdev);
  741. struct i40e_vsi *vsi = np->vsi;
  742. ec->tx_max_coalesced_frames_irq = vsi->work_limit;
  743. ec->rx_max_coalesced_frames_irq = vsi->work_limit;
  744. if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
  745. ec->rx_coalesce_usecs = 1;
  746. else
  747. ec->rx_coalesce_usecs = vsi->rx_itr_setting;
  748. if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
  749. ec->tx_coalesce_usecs = 1;
  750. else
  751. ec->tx_coalesce_usecs = vsi->tx_itr_setting;
  752. return 0;
  753. }
  754. static int i40e_set_coalesce(struct net_device *netdev,
  755. struct ethtool_coalesce *ec)
  756. {
  757. struct i40e_netdev_priv *np = netdev_priv(netdev);
  758. struct i40e_q_vector *q_vector;
  759. struct i40e_vsi *vsi = np->vsi;
  760. struct i40e_pf *pf = vsi->back;
  761. struct i40e_hw *hw = &pf->hw;
  762. u16 vector;
  763. int i;
  764. if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
  765. vsi->work_limit = ec->tx_max_coalesced_frames_irq;
  766. switch (ec->rx_coalesce_usecs) {
  767. case 0:
  768. vsi->rx_itr_setting = 0;
  769. break;
  770. case 1:
  771. vsi->rx_itr_setting = (I40E_ITR_DYNAMIC |
  772. ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
  773. break;
  774. default:
  775. if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  776. (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)))
  777. return -EINVAL;
  778. vsi->rx_itr_setting = ec->rx_coalesce_usecs;
  779. break;
  780. }
  781. switch (ec->tx_coalesce_usecs) {
  782. case 0:
  783. vsi->tx_itr_setting = 0;
  784. break;
  785. case 1:
  786. vsi->tx_itr_setting = (I40E_ITR_DYNAMIC |
  787. ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
  788. break;
  789. default:
  790. if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  791. (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)))
  792. return -EINVAL;
  793. vsi->tx_itr_setting = ec->tx_coalesce_usecs;
  794. break;
  795. }
  796. vector = vsi->base_vector;
  797. q_vector = vsi->q_vectors;
  798. for (i = 0; i < vsi->num_q_vectors; i++, vector++, q_vector++) {
  799. q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
  800. wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
  801. q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
  802. wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
  803. i40e_flush(hw);
  804. }
  805. return 0;
  806. }
  807. /**
  808. * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
  809. * @pf: pointer to the physical function struct
  810. * @cmd: ethtool rxnfc command
  811. *
  812. * Returns Success if the flow is supported, else Invalid Input.
  813. **/
  814. static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
  815. {
  816. cmd->data = 0;
  817. /* Report default options for RSS on i40e */
  818. switch (cmd->flow_type) {
  819. case TCP_V4_FLOW:
  820. case UDP_V4_FLOW:
  821. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  822. /* fall through to add IP fields */
  823. case SCTP_V4_FLOW:
  824. case AH_ESP_V4_FLOW:
  825. case AH_V4_FLOW:
  826. case ESP_V4_FLOW:
  827. case IPV4_FLOW:
  828. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  829. break;
  830. case TCP_V6_FLOW:
  831. case UDP_V6_FLOW:
  832. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  833. /* fall through to add IP fields */
  834. case SCTP_V6_FLOW:
  835. case AH_ESP_V6_FLOW:
  836. case AH_V6_FLOW:
  837. case ESP_V6_FLOW:
  838. case IPV6_FLOW:
  839. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  840. break;
  841. default:
  842. return -EINVAL;
  843. }
  844. return 0;
  845. }
  846. /**
  847. * i40e_get_rxnfc - command to get RX flow classification rules
  848. * @netdev: network interface device structure
  849. * @cmd: ethtool rxnfc command
  850. *
  851. * Returns Success if the command is supported.
  852. **/
  853. static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
  854. u32 *rule_locs)
  855. {
  856. struct i40e_netdev_priv *np = netdev_priv(netdev);
  857. struct i40e_vsi *vsi = np->vsi;
  858. struct i40e_pf *pf = vsi->back;
  859. int ret = -EOPNOTSUPP;
  860. switch (cmd->cmd) {
  861. case ETHTOOL_GRXRINGS:
  862. cmd->data = vsi->alloc_queue_pairs;
  863. ret = 0;
  864. break;
  865. case ETHTOOL_GRXFH:
  866. ret = i40e_get_rss_hash_opts(pf, cmd);
  867. break;
  868. case ETHTOOL_GRXCLSRLCNT:
  869. ret = 0;
  870. break;
  871. case ETHTOOL_GRXCLSRULE:
  872. ret = 0;
  873. break;
  874. case ETHTOOL_GRXCLSRLALL:
  875. cmd->data = 500;
  876. ret = 0;
  877. default:
  878. break;
  879. }
  880. return ret;
  881. }
  882. /**
  883. * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
  884. * @pf: pointer to the physical function struct
  885. * @cmd: ethtool rxnfc command
  886. *
  887. * Returns Success if the flow input set is supported.
  888. **/
  889. static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
  890. {
  891. struct i40e_hw *hw = &pf->hw;
  892. u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
  893. ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
  894. /* RSS does not support anything other than hashing
  895. * to queues on src and dst IPs and ports
  896. */
  897. if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
  898. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  899. return -EINVAL;
  900. /* We need at least the IP SRC and DEST fields for hashing */
  901. if (!(nfc->data & RXH_IP_SRC) ||
  902. !(nfc->data & RXH_IP_DST))
  903. return -EINVAL;
  904. switch (nfc->flow_type) {
  905. case TCP_V4_FLOW:
  906. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  907. case 0:
  908. hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  909. break;
  910. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  911. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  912. break;
  913. default:
  914. return -EINVAL;
  915. }
  916. break;
  917. case TCP_V6_FLOW:
  918. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  919. case 0:
  920. hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  921. break;
  922. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  923. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  924. break;
  925. default:
  926. return -EINVAL;
  927. }
  928. break;
  929. case UDP_V4_FLOW:
  930. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  931. case 0:
  932. hena &=
  933. ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
  934. ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
  935. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
  936. break;
  937. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  938. hena |=
  939. (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
  940. ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
  941. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
  942. break;
  943. default:
  944. return -EINVAL;
  945. }
  946. break;
  947. case UDP_V6_FLOW:
  948. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  949. case 0:
  950. hena &=
  951. ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
  952. ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
  953. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
  954. break;
  955. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  956. hena |=
  957. (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
  958. ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
  959. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
  960. break;
  961. default:
  962. return -EINVAL;
  963. }
  964. break;
  965. case AH_ESP_V4_FLOW:
  966. case AH_V4_FLOW:
  967. case ESP_V4_FLOW:
  968. case SCTP_V4_FLOW:
  969. if ((nfc->data & RXH_L4_B_0_1) ||
  970. (nfc->data & RXH_L4_B_2_3))
  971. return -EINVAL;
  972. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
  973. break;
  974. case AH_ESP_V6_FLOW:
  975. case AH_V6_FLOW:
  976. case ESP_V6_FLOW:
  977. case SCTP_V6_FLOW:
  978. if ((nfc->data & RXH_L4_B_0_1) ||
  979. (nfc->data & RXH_L4_B_2_3))
  980. return -EINVAL;
  981. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
  982. break;
  983. case IPV4_FLOW:
  984. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
  985. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
  986. break;
  987. case IPV6_FLOW:
  988. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
  989. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
  990. break;
  991. default:
  992. return -EINVAL;
  993. }
  994. wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
  995. wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  996. i40e_flush(hw);
  997. return 0;
  998. }
  999. #define IP_HEADER_OFFSET 14
  1000. /**
  1001. * i40e_add_del_fdir_udpv4 - Add/Remove UDPv4 Flow Director filters for
  1002. * a specific flow spec
  1003. * @vsi: pointer to the targeted VSI
  1004. * @fd_data: the flow director data required from the FDir descriptor
  1005. * @ethtool_rx_flow_spec: the flow spec
  1006. * @add: true adds a filter, false removes it
  1007. *
  1008. * Returns 0 if the filters were successfully added or removed
  1009. **/
  1010. static int i40e_add_del_fdir_udpv4(struct i40e_vsi *vsi,
  1011. struct i40e_fdir_data *fd_data,
  1012. struct ethtool_rx_flow_spec *fsp, bool add)
  1013. {
  1014. struct i40e_pf *pf = vsi->back;
  1015. struct udphdr *udp;
  1016. struct iphdr *ip;
  1017. bool err = false;
  1018. int ret;
  1019. int i;
  1020. ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
  1021. udp = (struct udphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET
  1022. + sizeof(struct iphdr));
  1023. ip->saddr = fsp->h_u.tcp_ip4_spec.ip4src;
  1024. ip->daddr = fsp->h_u.tcp_ip4_spec.ip4dst;
  1025. udp->source = fsp->h_u.tcp_ip4_spec.psrc;
  1026. udp->dest = fsp->h_u.tcp_ip4_spec.pdst;
  1027. for (i = I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP;
  1028. i <= I40E_FILTER_PCTYPE_NONF_IPV4_UDP; i++) {
  1029. fd_data->pctype = i;
  1030. ret = i40e_program_fdir_filter(fd_data, pf, add);
  1031. if (ret) {
  1032. dev_info(&pf->pdev->dev,
  1033. "Filter command send failed for PCTYPE %d (ret = %d)\n",
  1034. fd_data->pctype, ret);
  1035. err = true;
  1036. } else {
  1037. dev_info(&pf->pdev->dev,
  1038. "Filter OK for PCTYPE %d (ret = %d)\n",
  1039. fd_data->pctype, ret);
  1040. }
  1041. }
  1042. return err ? -EOPNOTSUPP : 0;
  1043. }
  1044. /**
  1045. * i40e_add_del_fdir_tcpv4 - Add/Remove TCPv4 Flow Director filters for
  1046. * a specific flow spec
  1047. * @vsi: pointer to the targeted VSI
  1048. * @fd_data: the flow director data required from the FDir descriptor
  1049. * @ethtool_rx_flow_spec: the flow spec
  1050. * @add: true adds a filter, false removes it
  1051. *
  1052. * Returns 0 if the filters were successfully added or removed
  1053. **/
  1054. static int i40e_add_del_fdir_tcpv4(struct i40e_vsi *vsi,
  1055. struct i40e_fdir_data *fd_data,
  1056. struct ethtool_rx_flow_spec *fsp, bool add)
  1057. {
  1058. struct i40e_pf *pf = vsi->back;
  1059. struct tcphdr *tcp;
  1060. struct iphdr *ip;
  1061. bool err = false;
  1062. int ret;
  1063. ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
  1064. tcp = (struct tcphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET
  1065. + sizeof(struct iphdr));
  1066. ip->daddr = fsp->h_u.tcp_ip4_spec.ip4dst;
  1067. tcp->dest = fsp->h_u.tcp_ip4_spec.pdst;
  1068. fd_data->pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN;
  1069. ret = i40e_program_fdir_filter(fd_data, pf, add);
  1070. if (ret) {
  1071. dev_info(&pf->pdev->dev,
  1072. "Filter command send failed for PCTYPE %d (ret = %d)\n",
  1073. fd_data->pctype, ret);
  1074. err = true;
  1075. } else {
  1076. dev_info(&pf->pdev->dev, "Filter OK for PCTYPE %d (ret = %d)\n",
  1077. fd_data->pctype, ret);
  1078. }
  1079. ip->saddr = fsp->h_u.tcp_ip4_spec.ip4src;
  1080. tcp->source = fsp->h_u.tcp_ip4_spec.psrc;
  1081. fd_data->pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
  1082. ret = i40e_program_fdir_filter(fd_data, pf, add);
  1083. if (ret) {
  1084. dev_info(&pf->pdev->dev,
  1085. "Filter command send failed for PCTYPE %d (ret = %d)\n",
  1086. fd_data->pctype, ret);
  1087. err = true;
  1088. } else {
  1089. dev_info(&pf->pdev->dev, "Filter OK for PCTYPE %d (ret = %d)\n",
  1090. fd_data->pctype, ret);
  1091. }
  1092. return err ? -EOPNOTSUPP : 0;
  1093. }
  1094. /**
  1095. * i40e_add_del_fdir_sctpv4 - Add/Remove SCTPv4 Flow Director filters for
  1096. * a specific flow spec
  1097. * @vsi: pointer to the targeted VSI
  1098. * @fd_data: the flow director data required from the FDir descriptor
  1099. * @ethtool_rx_flow_spec: the flow spec
  1100. * @add: true adds a filter, false removes it
  1101. *
  1102. * Returns 0 if the filters were successfully added or removed
  1103. **/
  1104. static int i40e_add_del_fdir_sctpv4(struct i40e_vsi *vsi,
  1105. struct i40e_fdir_data *fd_data,
  1106. struct ethtool_rx_flow_spec *fsp, bool add)
  1107. {
  1108. return -EOPNOTSUPP;
  1109. }
  1110. /**
  1111. * i40e_add_del_fdir_ipv4 - Add/Remove IPv4 Flow Director filters for
  1112. * a specific flow spec
  1113. * @vsi: pointer to the targeted VSI
  1114. * @fd_data: the flow director data required for the FDir descriptor
  1115. * @fsp: the ethtool flow spec
  1116. * @add: true adds a filter, false removes it
  1117. *
  1118. * Returns 0 if the filters were successfully added or removed
  1119. **/
  1120. static int i40e_add_del_fdir_ipv4(struct i40e_vsi *vsi,
  1121. struct i40e_fdir_data *fd_data,
  1122. struct ethtool_rx_flow_spec *fsp, bool add)
  1123. {
  1124. struct i40e_pf *pf = vsi->back;
  1125. struct iphdr *ip;
  1126. bool err = false;
  1127. int ret;
  1128. int i;
  1129. ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
  1130. ip->saddr = fsp->h_u.usr_ip4_spec.ip4src;
  1131. ip->daddr = fsp->h_u.usr_ip4_spec.ip4dst;
  1132. ip->protocol = fsp->h_u.usr_ip4_spec.proto;
  1133. for (i = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
  1134. i <= I40E_FILTER_PCTYPE_FRAG_IPV4; i++) {
  1135. fd_data->pctype = i;
  1136. ret = i40e_program_fdir_filter(fd_data, pf, add);
  1137. if (ret) {
  1138. dev_info(&pf->pdev->dev,
  1139. "Filter command send failed for PCTYPE %d (ret = %d)\n",
  1140. fd_data->pctype, ret);
  1141. err = true;
  1142. } else {
  1143. dev_info(&pf->pdev->dev,
  1144. "Filter OK for PCTYPE %d (ret = %d)\n",
  1145. fd_data->pctype, ret);
  1146. }
  1147. }
  1148. return err ? -EOPNOTSUPP : 0;
  1149. }
  1150. /**
  1151. * i40e_add_del_fdir_ethtool - Add/Remove Flow Director filters for
  1152. * a specific flow spec based on their protocol
  1153. * @vsi: pointer to the targeted VSI
  1154. * @cmd: command to get or set RX flow classification rules
  1155. * @add: true adds a filter, false removes it
  1156. *
  1157. * Returns 0 if the filters were successfully added or removed
  1158. **/
  1159. static int i40e_add_del_fdir_ethtool(struct i40e_vsi *vsi,
  1160. struct ethtool_rxnfc *cmd, bool add)
  1161. {
  1162. struct i40e_fdir_data fd_data;
  1163. int ret = -EINVAL;
  1164. struct i40e_pf *pf;
  1165. struct ethtool_rx_flow_spec *fsp =
  1166. (struct ethtool_rx_flow_spec *)&cmd->fs;
  1167. if (!vsi)
  1168. return -EINVAL;
  1169. pf = vsi->back;
  1170. if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
  1171. (fsp->ring_cookie >= vsi->num_queue_pairs))
  1172. return -EINVAL;
  1173. /* Populate the Flow Director that we have at the moment
  1174. * and allocate the raw packet buffer for the calling functions
  1175. */
  1176. fd_data.raw_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_LOOKUP,
  1177. GFP_KERNEL);
  1178. if (!fd_data.raw_packet) {
  1179. dev_info(&pf->pdev->dev, "Could not allocate memory\n");
  1180. return -ENOMEM;
  1181. }
  1182. fd_data.q_index = fsp->ring_cookie;
  1183. fd_data.flex_off = 0;
  1184. fd_data.pctype = 0;
  1185. fd_data.dest_vsi = vsi->id;
  1186. fd_data.dest_ctl = 0;
  1187. fd_data.fd_status = 0;
  1188. fd_data.cnt_index = 0;
  1189. fd_data.fd_id = 0;
  1190. switch (fsp->flow_type & ~FLOW_EXT) {
  1191. case TCP_V4_FLOW:
  1192. ret = i40e_add_del_fdir_tcpv4(vsi, &fd_data, fsp, add);
  1193. break;
  1194. case UDP_V4_FLOW:
  1195. ret = i40e_add_del_fdir_udpv4(vsi, &fd_data, fsp, add);
  1196. break;
  1197. case SCTP_V4_FLOW:
  1198. ret = i40e_add_del_fdir_sctpv4(vsi, &fd_data, fsp, add);
  1199. break;
  1200. case IPV4_FLOW:
  1201. ret = i40e_add_del_fdir_ipv4(vsi, &fd_data, fsp, add);
  1202. break;
  1203. case IP_USER_FLOW:
  1204. switch (fsp->h_u.usr_ip4_spec.proto) {
  1205. case IPPROTO_TCP:
  1206. ret = i40e_add_del_fdir_tcpv4(vsi, &fd_data, fsp, add);
  1207. break;
  1208. case IPPROTO_UDP:
  1209. ret = i40e_add_del_fdir_udpv4(vsi, &fd_data, fsp, add);
  1210. break;
  1211. case IPPROTO_SCTP:
  1212. ret = i40e_add_del_fdir_sctpv4(vsi, &fd_data, fsp, add);
  1213. break;
  1214. default:
  1215. ret = i40e_add_del_fdir_ipv4(vsi, &fd_data, fsp, add);
  1216. break;
  1217. }
  1218. break;
  1219. default:
  1220. dev_info(&pf->pdev->dev, "Could not specify spec type\n");
  1221. ret = -EINVAL;
  1222. }
  1223. kfree(fd_data.raw_packet);
  1224. fd_data.raw_packet = NULL;
  1225. return ret;
  1226. }
  1227. /**
  1228. * i40e_set_rxnfc - command to set RX flow classification rules
  1229. * @netdev: network interface device structure
  1230. * @cmd: ethtool rxnfc command
  1231. *
  1232. * Returns Success if the command is supported.
  1233. **/
  1234. static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
  1235. {
  1236. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1237. struct i40e_vsi *vsi = np->vsi;
  1238. struct i40e_pf *pf = vsi->back;
  1239. int ret = -EOPNOTSUPP;
  1240. switch (cmd->cmd) {
  1241. case ETHTOOL_SRXFH:
  1242. ret = i40e_set_rss_hash_opt(pf, cmd);
  1243. break;
  1244. case ETHTOOL_SRXCLSRLINS:
  1245. ret = i40e_add_del_fdir_ethtool(vsi, cmd, true);
  1246. break;
  1247. case ETHTOOL_SRXCLSRLDEL:
  1248. ret = i40e_add_del_fdir_ethtool(vsi, cmd, false);
  1249. break;
  1250. default:
  1251. break;
  1252. }
  1253. return ret;
  1254. }
  1255. static const struct ethtool_ops i40e_ethtool_ops = {
  1256. .get_settings = i40e_get_settings,
  1257. .get_drvinfo = i40e_get_drvinfo,
  1258. .get_regs_len = i40e_get_regs_len,
  1259. .get_regs = i40e_get_regs,
  1260. .nway_reset = i40e_nway_reset,
  1261. .get_link = ethtool_op_get_link,
  1262. .get_wol = i40e_get_wol,
  1263. .get_eeprom_len = i40e_get_eeprom_len,
  1264. .get_eeprom = i40e_get_eeprom,
  1265. .get_ringparam = i40e_get_ringparam,
  1266. .set_ringparam = i40e_set_ringparam,
  1267. .get_pauseparam = i40e_get_pauseparam,
  1268. .get_msglevel = i40e_get_msglevel,
  1269. .set_msglevel = i40e_set_msglevel,
  1270. .get_rxnfc = i40e_get_rxnfc,
  1271. .set_rxnfc = i40e_set_rxnfc,
  1272. .self_test = i40e_diag_test,
  1273. .get_strings = i40e_get_strings,
  1274. .set_phys_id = i40e_set_phys_id,
  1275. .get_sset_count = i40e_get_sset_count,
  1276. .get_ethtool_stats = i40e_get_ethtool_stats,
  1277. .get_coalesce = i40e_get_coalesce,
  1278. .set_coalesce = i40e_set_coalesce,
  1279. .get_ts_info = i40e_get_ts_info,
  1280. };
  1281. void i40e_set_ethtool_ops(struct net_device *netdev)
  1282. {
  1283. SET_ETHTOOL_OPS(netdev, &i40e_ethtool_ops);
  1284. }