i40e_ethtool.c 47 KB

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