i40e_ethtool.c 47 KB

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