i40e_ethtool.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691
  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("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts),
  109. I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
  110. /* LPI stats */
  111. I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
  112. I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
  113. I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
  114. I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
  115. };
  116. #define I40E_QUEUE_STATS_LEN(n) \
  117. ((((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs + \
  118. ((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs) * 2)
  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. (u8 *)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, (u8 *)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_vsi *vsi = np->vsi;
  569. struct i40e_pf *pf = vsi->back;
  570. int i = 0;
  571. char *p;
  572. int j;
  573. struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
  574. unsigned int start;
  575. i40e_update_stats(vsi);
  576. for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
  577. p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
  578. data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
  579. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  580. }
  581. rcu_read_lock();
  582. for (j = 0; j < vsi->num_queue_pairs; j++, i += 4) {
  583. struct i40e_ring *tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
  584. struct i40e_ring *rx_ring;
  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. /* Rx ring is the 2nd half of the queue pair */
  594. rx_ring = &tx_ring[1];
  595. do {
  596. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  597. data[i + 2] = rx_ring->stats.packets;
  598. data[i + 3] = rx_ring->stats.bytes;
  599. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  600. }
  601. rcu_read_unlock();
  602. if (vsi == pf->vsi[pf->lan_vsi]) {
  603. for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
  604. p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
  605. data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
  606. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  607. }
  608. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  609. data[i++] = pf->stats.priority_xon_tx[j];
  610. data[i++] = pf->stats.priority_xoff_tx[j];
  611. }
  612. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  613. data[i++] = pf->stats.priority_xon_rx[j];
  614. data[i++] = pf->stats.priority_xoff_rx[j];
  615. }
  616. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
  617. data[i++] = pf->stats.priority_xon_2_xoff[j];
  618. }
  619. }
  620. static void i40e_get_strings(struct net_device *netdev, u32 stringset,
  621. u8 *data)
  622. {
  623. struct i40e_netdev_priv *np = netdev_priv(netdev);
  624. struct i40e_vsi *vsi = np->vsi;
  625. struct i40e_pf *pf = vsi->back;
  626. char *p = (char *)data;
  627. int i;
  628. switch (stringset) {
  629. case ETH_SS_TEST:
  630. for (i = 0; i < I40E_TEST_LEN; i++) {
  631. memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
  632. data += ETH_GSTRING_LEN;
  633. }
  634. break;
  635. case ETH_SS_STATS:
  636. for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
  637. snprintf(p, ETH_GSTRING_LEN, "%s",
  638. i40e_gstrings_net_stats[i].stat_string);
  639. p += ETH_GSTRING_LEN;
  640. }
  641. for (i = 0; i < vsi->num_queue_pairs; i++) {
  642. snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
  643. p += ETH_GSTRING_LEN;
  644. snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
  645. p += ETH_GSTRING_LEN;
  646. snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
  647. p += ETH_GSTRING_LEN;
  648. snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
  649. p += ETH_GSTRING_LEN;
  650. }
  651. if (vsi == pf->vsi[pf->lan_vsi]) {
  652. for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
  653. snprintf(p, ETH_GSTRING_LEN, "port.%s",
  654. i40e_gstrings_stats[i].stat_string);
  655. p += ETH_GSTRING_LEN;
  656. }
  657. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  658. snprintf(p, ETH_GSTRING_LEN,
  659. "port.tx_priority_%u_xon", i);
  660. p += ETH_GSTRING_LEN;
  661. snprintf(p, ETH_GSTRING_LEN,
  662. "port.tx_priority_%u_xoff", i);
  663. p += ETH_GSTRING_LEN;
  664. }
  665. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  666. snprintf(p, ETH_GSTRING_LEN,
  667. "port.rx_priority_%u_xon", i);
  668. p += ETH_GSTRING_LEN;
  669. snprintf(p, ETH_GSTRING_LEN,
  670. "port.rx_priority_%u_xoff", i);
  671. p += ETH_GSTRING_LEN;
  672. }
  673. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  674. snprintf(p, ETH_GSTRING_LEN,
  675. "port.rx_priority_%u_xon_2_xoff", i);
  676. p += ETH_GSTRING_LEN;
  677. }
  678. }
  679. /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
  680. break;
  681. }
  682. }
  683. static int i40e_get_ts_info(struct net_device *dev,
  684. struct ethtool_ts_info *info)
  685. {
  686. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  687. info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  688. SOF_TIMESTAMPING_RX_SOFTWARE |
  689. SOF_TIMESTAMPING_SOFTWARE |
  690. SOF_TIMESTAMPING_TX_HARDWARE |
  691. SOF_TIMESTAMPING_RX_HARDWARE |
  692. SOF_TIMESTAMPING_RAW_HARDWARE;
  693. if (pf->ptp_clock)
  694. info->phc_index = ptp_clock_index(pf->ptp_clock);
  695. else
  696. info->phc_index = -1;
  697. info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
  698. info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
  699. (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
  700. (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
  701. (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
  702. (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
  703. (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
  704. (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
  705. (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
  706. (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
  707. (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
  708. (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
  709. (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
  710. return 0;
  711. }
  712. static int i40e_link_test(struct net_device *netdev, u64 *data)
  713. {
  714. struct i40e_netdev_priv *np = netdev_priv(netdev);
  715. struct i40e_pf *pf = np->vsi->back;
  716. netif_info(pf, hw, netdev, "link test\n");
  717. if (i40e_get_link_status(&pf->hw))
  718. *data = 0;
  719. else
  720. *data = 1;
  721. return *data;
  722. }
  723. static int i40e_reg_test(struct net_device *netdev, u64 *data)
  724. {
  725. struct i40e_netdev_priv *np = netdev_priv(netdev);
  726. struct i40e_pf *pf = np->vsi->back;
  727. netif_info(pf, hw, netdev, "register test\n");
  728. *data = i40e_diag_reg_test(&pf->hw);
  729. return *data;
  730. }
  731. static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
  732. {
  733. struct i40e_netdev_priv *np = netdev_priv(netdev);
  734. struct i40e_pf *pf = np->vsi->back;
  735. netif_info(pf, hw, netdev, "eeprom test\n");
  736. *data = i40e_diag_eeprom_test(&pf->hw);
  737. return *data;
  738. }
  739. static int i40e_intr_test(struct net_device *netdev, u64 *data)
  740. {
  741. struct i40e_netdev_priv *np = netdev_priv(netdev);
  742. struct i40e_pf *pf = np->vsi->back;
  743. u16 swc_old = pf->sw_int_count;
  744. netif_info(pf, hw, netdev, "interrupt test\n");
  745. wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
  746. (I40E_PFINT_DYN_CTL0_INTENA_MASK |
  747. I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
  748. usleep_range(1000, 2000);
  749. *data = (swc_old == pf->sw_int_count);
  750. return *data;
  751. }
  752. static int i40e_loopback_test(struct net_device *netdev, u64 *data)
  753. {
  754. struct i40e_netdev_priv *np = netdev_priv(netdev);
  755. struct i40e_pf *pf = np->vsi->back;
  756. netif_info(pf, hw, netdev, "loopback test not implemented\n");
  757. *data = 0;
  758. return *data;
  759. }
  760. static void i40e_diag_test(struct net_device *netdev,
  761. struct ethtool_test *eth_test, u64 *data)
  762. {
  763. struct i40e_netdev_priv *np = netdev_priv(netdev);
  764. struct i40e_pf *pf = np->vsi->back;
  765. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  766. /* Offline tests */
  767. netif_info(pf, drv, netdev, "offline testing starting\n");
  768. set_bit(__I40E_TESTING, &pf->state);
  769. /* Link test performed before hardware reset
  770. * so autoneg doesn't interfere with test result
  771. */
  772. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  773. eth_test->flags |= ETH_TEST_FL_FAILED;
  774. if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
  775. eth_test->flags |= ETH_TEST_FL_FAILED;
  776. if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
  777. eth_test->flags |= ETH_TEST_FL_FAILED;
  778. if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
  779. eth_test->flags |= ETH_TEST_FL_FAILED;
  780. /* run reg test last, a reset is required after it */
  781. if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
  782. eth_test->flags |= ETH_TEST_FL_FAILED;
  783. clear_bit(__I40E_TESTING, &pf->state);
  784. i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
  785. } else {
  786. /* Online tests */
  787. netif_info(pf, drv, netdev, "online testing starting\n");
  788. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  789. eth_test->flags |= ETH_TEST_FL_FAILED;
  790. /* Offline only tests, not run in online; pass by default */
  791. data[I40E_ETH_TEST_REG] = 0;
  792. data[I40E_ETH_TEST_EEPROM] = 0;
  793. data[I40E_ETH_TEST_INTR] = 0;
  794. data[I40E_ETH_TEST_LOOPBACK] = 0;
  795. }
  796. netif_info(pf, drv, netdev, "testing finished\n");
  797. }
  798. static void i40e_get_wol(struct net_device *netdev,
  799. struct ethtool_wolinfo *wol)
  800. {
  801. struct i40e_netdev_priv *np = netdev_priv(netdev);
  802. struct i40e_pf *pf = np->vsi->back;
  803. struct i40e_hw *hw = &pf->hw;
  804. u16 wol_nvm_bits;
  805. /* NVM bit on means WoL disabled for the port */
  806. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  807. if ((1 << hw->port) & wol_nvm_bits) {
  808. wol->supported = 0;
  809. wol->wolopts = 0;
  810. } else {
  811. wol->supported = WAKE_MAGIC;
  812. wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
  813. }
  814. }
  815. static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  816. {
  817. struct i40e_netdev_priv *np = netdev_priv(netdev);
  818. struct i40e_pf *pf = np->vsi->back;
  819. struct i40e_hw *hw = &pf->hw;
  820. u16 wol_nvm_bits;
  821. /* NVM bit on means WoL disabled for the port */
  822. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  823. if (((1 << hw->port) & wol_nvm_bits))
  824. return -EOPNOTSUPP;
  825. /* only magic packet is supported */
  826. if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
  827. return -EOPNOTSUPP;
  828. /* is this a new value? */
  829. if (pf->wol_en != !!wol->wolopts) {
  830. pf->wol_en = !!wol->wolopts;
  831. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  832. }
  833. return 0;
  834. }
  835. static int i40e_nway_reset(struct net_device *netdev)
  836. {
  837. /* restart autonegotiation */
  838. struct i40e_netdev_priv *np = netdev_priv(netdev);
  839. struct i40e_pf *pf = np->vsi->back;
  840. struct i40e_hw *hw = &pf->hw;
  841. i40e_status ret = 0;
  842. ret = i40e_aq_set_link_restart_an(hw, NULL);
  843. if (ret) {
  844. netdev_info(netdev, "link restart failed, aq_err=%d\n",
  845. pf->hw.aq.asq_last_status);
  846. return -EIO;
  847. }
  848. return 0;
  849. }
  850. static int i40e_set_phys_id(struct net_device *netdev,
  851. enum ethtool_phys_id_state state)
  852. {
  853. struct i40e_netdev_priv *np = netdev_priv(netdev);
  854. struct i40e_pf *pf = np->vsi->back;
  855. struct i40e_hw *hw = &pf->hw;
  856. int blink_freq = 2;
  857. switch (state) {
  858. case ETHTOOL_ID_ACTIVE:
  859. pf->led_status = i40e_led_get(hw);
  860. return blink_freq;
  861. case ETHTOOL_ID_ON:
  862. i40e_led_set(hw, 0xF, false);
  863. break;
  864. case ETHTOOL_ID_OFF:
  865. i40e_led_set(hw, 0x0, false);
  866. break;
  867. case ETHTOOL_ID_INACTIVE:
  868. i40e_led_set(hw, pf->led_status, false);
  869. break;
  870. }
  871. return 0;
  872. }
  873. /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
  874. * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
  875. * 125us (8000 interrupts per second) == ITR(62)
  876. */
  877. static int i40e_get_coalesce(struct net_device *netdev,
  878. struct ethtool_coalesce *ec)
  879. {
  880. struct i40e_netdev_priv *np = netdev_priv(netdev);
  881. struct i40e_vsi *vsi = np->vsi;
  882. ec->tx_max_coalesced_frames_irq = vsi->work_limit;
  883. ec->rx_max_coalesced_frames_irq = vsi->work_limit;
  884. if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
  885. ec->rx_coalesce_usecs = 1;
  886. else
  887. ec->rx_coalesce_usecs = vsi->rx_itr_setting;
  888. if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
  889. ec->tx_coalesce_usecs = 1;
  890. else
  891. ec->tx_coalesce_usecs = vsi->tx_itr_setting;
  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. switch (ec->rx_coalesce_usecs) {
  907. case 0:
  908. vsi->rx_itr_setting = 0;
  909. break;
  910. case 1:
  911. vsi->rx_itr_setting = (I40E_ITR_DYNAMIC |
  912. ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
  913. break;
  914. default:
  915. if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  916. (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)))
  917. return -EINVAL;
  918. vsi->rx_itr_setting = ec->rx_coalesce_usecs;
  919. break;
  920. }
  921. switch (ec->tx_coalesce_usecs) {
  922. case 0:
  923. vsi->tx_itr_setting = 0;
  924. break;
  925. case 1:
  926. vsi->tx_itr_setting = (I40E_ITR_DYNAMIC |
  927. ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
  928. break;
  929. default:
  930. if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  931. (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)))
  932. return -EINVAL;
  933. vsi->tx_itr_setting = ec->tx_coalesce_usecs;
  934. break;
  935. }
  936. vector = vsi->base_vector;
  937. for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
  938. q_vector = vsi->q_vectors[i];
  939. q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
  940. wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
  941. q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
  942. wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
  943. i40e_flush(hw);
  944. }
  945. return 0;
  946. }
  947. /**
  948. * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
  949. * @pf: pointer to the physical function struct
  950. * @cmd: ethtool rxnfc command
  951. *
  952. * Returns Success if the flow is supported, else Invalid Input.
  953. **/
  954. static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
  955. {
  956. cmd->data = 0;
  957. /* Report default options for RSS on i40e */
  958. switch (cmd->flow_type) {
  959. case TCP_V4_FLOW:
  960. case UDP_V4_FLOW:
  961. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  962. /* fall through to add IP fields */
  963. case SCTP_V4_FLOW:
  964. case AH_ESP_V4_FLOW:
  965. case AH_V4_FLOW:
  966. case ESP_V4_FLOW:
  967. case IPV4_FLOW:
  968. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  969. break;
  970. case TCP_V6_FLOW:
  971. case UDP_V6_FLOW:
  972. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  973. /* fall through to add IP fields */
  974. case SCTP_V6_FLOW:
  975. case AH_ESP_V6_FLOW:
  976. case AH_V6_FLOW:
  977. case ESP_V6_FLOW:
  978. case IPV6_FLOW:
  979. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  980. break;
  981. default:
  982. return -EINVAL;
  983. }
  984. return 0;
  985. }
  986. /**
  987. * i40e_get_ethtool_fdir_all - Populates the rule count of a command
  988. * @pf: Pointer to the physical function struct
  989. * @cmd: The command to get or set Rx flow classification rules
  990. * @rule_locs: Array of used rule locations
  991. *
  992. * This function populates both the total and actual rule count of
  993. * the ethtool flow classification command
  994. *
  995. * Returns 0 on success or -EMSGSIZE if entry not found
  996. **/
  997. static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
  998. struct ethtool_rxnfc *cmd,
  999. u32 *rule_locs)
  1000. {
  1001. struct i40e_fdir_filter *rule;
  1002. struct hlist_node *node2;
  1003. int cnt = 0;
  1004. /* report total rule count */
  1005. cmd->data = pf->hw.fdir_shared_filter_count +
  1006. pf->fdir_pf_filter_count;
  1007. hlist_for_each_entry_safe(rule, node2,
  1008. &pf->fdir_filter_list, fdir_node) {
  1009. if (cnt == cmd->rule_cnt)
  1010. return -EMSGSIZE;
  1011. rule_locs[cnt] = rule->fd_id;
  1012. cnt++;
  1013. }
  1014. cmd->rule_cnt = cnt;
  1015. return 0;
  1016. }
  1017. /**
  1018. * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
  1019. * @pf: Pointer to the physical function struct
  1020. * @cmd: The command to get or set Rx flow classification rules
  1021. *
  1022. * This function looks up a filter based on the Rx flow classification
  1023. * command and fills the flow spec info for it if found
  1024. *
  1025. * Returns 0 on success or -EINVAL if filter not found
  1026. **/
  1027. static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
  1028. struct ethtool_rxnfc *cmd)
  1029. {
  1030. struct ethtool_rx_flow_spec *fsp =
  1031. (struct ethtool_rx_flow_spec *)&cmd->fs;
  1032. struct i40e_fdir_filter *rule = NULL;
  1033. struct hlist_node *node2;
  1034. /* report total rule count */
  1035. cmd->data = pf->hw.fdir_shared_filter_count +
  1036. pf->fdir_pf_filter_count;
  1037. hlist_for_each_entry_safe(rule, node2,
  1038. &pf->fdir_filter_list, fdir_node) {
  1039. if (fsp->location <= rule->fd_id)
  1040. break;
  1041. }
  1042. if (!rule || fsp->location != rule->fd_id)
  1043. return -EINVAL;
  1044. fsp->flow_type = rule->flow_type;
  1045. fsp->h_u.tcp_ip4_spec.psrc = rule->src_port;
  1046. fsp->h_u.tcp_ip4_spec.pdst = rule->dst_port;
  1047. fsp->h_u.tcp_ip4_spec.ip4src = rule->src_ip[0];
  1048. fsp->h_u.tcp_ip4_spec.ip4dst = rule->dst_ip[0];
  1049. fsp->ring_cookie = rule->q_index;
  1050. return 0;
  1051. }
  1052. /**
  1053. * i40e_get_rxnfc - command to get RX flow classification rules
  1054. * @netdev: network interface device structure
  1055. * @cmd: ethtool rxnfc command
  1056. *
  1057. * Returns Success if the command is supported.
  1058. **/
  1059. static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
  1060. u32 *rule_locs)
  1061. {
  1062. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1063. struct i40e_vsi *vsi = np->vsi;
  1064. struct i40e_pf *pf = vsi->back;
  1065. int ret = -EOPNOTSUPP;
  1066. switch (cmd->cmd) {
  1067. case ETHTOOL_GRXRINGS:
  1068. cmd->data = vsi->alloc_queue_pairs;
  1069. ret = 0;
  1070. break;
  1071. case ETHTOOL_GRXFH:
  1072. ret = i40e_get_rss_hash_opts(pf, cmd);
  1073. break;
  1074. case ETHTOOL_GRXCLSRLCNT:
  1075. cmd->rule_cnt = pf->fdir_pf_active_filters;
  1076. ret = 0;
  1077. break;
  1078. case ETHTOOL_GRXCLSRULE:
  1079. ret = i40e_get_ethtool_fdir_entry(pf, cmd);
  1080. break;
  1081. case ETHTOOL_GRXCLSRLALL:
  1082. ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
  1083. break;
  1084. default:
  1085. break;
  1086. }
  1087. return ret;
  1088. }
  1089. /**
  1090. * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
  1091. * @pf: pointer to the physical function struct
  1092. * @cmd: ethtool rxnfc command
  1093. *
  1094. * Returns Success if the flow input set is supported.
  1095. **/
  1096. static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
  1097. {
  1098. struct i40e_hw *hw = &pf->hw;
  1099. u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
  1100. ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
  1101. /* RSS does not support anything other than hashing
  1102. * to queues on src and dst IPs and ports
  1103. */
  1104. if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
  1105. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  1106. return -EINVAL;
  1107. /* We need at least the IP SRC and DEST fields for hashing */
  1108. if (!(nfc->data & RXH_IP_SRC) ||
  1109. !(nfc->data & RXH_IP_DST))
  1110. return -EINVAL;
  1111. switch (nfc->flow_type) {
  1112. case TCP_V4_FLOW:
  1113. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1114. case 0:
  1115. hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  1116. break;
  1117. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  1118. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  1119. break;
  1120. default:
  1121. return -EINVAL;
  1122. }
  1123. break;
  1124. case TCP_V6_FLOW:
  1125. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1126. case 0:
  1127. hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  1128. break;
  1129. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  1130. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  1131. break;
  1132. default:
  1133. return -EINVAL;
  1134. }
  1135. break;
  1136. case UDP_V4_FLOW:
  1137. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1138. case 0:
  1139. hena &=
  1140. ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
  1141. ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
  1142. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
  1143. break;
  1144. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  1145. hena |=
  1146. (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
  1147. ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
  1148. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
  1149. break;
  1150. default:
  1151. return -EINVAL;
  1152. }
  1153. break;
  1154. case UDP_V6_FLOW:
  1155. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1156. case 0:
  1157. hena &=
  1158. ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
  1159. ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
  1160. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
  1161. break;
  1162. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  1163. hena |=
  1164. (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
  1165. ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
  1166. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
  1167. break;
  1168. default:
  1169. return -EINVAL;
  1170. }
  1171. break;
  1172. case AH_ESP_V4_FLOW:
  1173. case AH_V4_FLOW:
  1174. case ESP_V4_FLOW:
  1175. case SCTP_V4_FLOW:
  1176. if ((nfc->data & RXH_L4_B_0_1) ||
  1177. (nfc->data & RXH_L4_B_2_3))
  1178. return -EINVAL;
  1179. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
  1180. break;
  1181. case AH_ESP_V6_FLOW:
  1182. case AH_V6_FLOW:
  1183. case ESP_V6_FLOW:
  1184. case SCTP_V6_FLOW:
  1185. if ((nfc->data & RXH_L4_B_0_1) ||
  1186. (nfc->data & RXH_L4_B_2_3))
  1187. return -EINVAL;
  1188. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
  1189. break;
  1190. case IPV4_FLOW:
  1191. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
  1192. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
  1193. break;
  1194. case IPV6_FLOW:
  1195. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
  1196. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
  1197. break;
  1198. default:
  1199. return -EINVAL;
  1200. }
  1201. wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
  1202. wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  1203. i40e_flush(hw);
  1204. return 0;
  1205. }
  1206. /**
  1207. * i40e_match_fdir_input_set - Match a new filter against an existing one
  1208. * @rule: The filter already added
  1209. * @input: The new filter to comapre against
  1210. *
  1211. * Returns true if the two input set match
  1212. **/
  1213. static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
  1214. struct i40e_fdir_filter *input)
  1215. {
  1216. if ((rule->dst_ip[0] != input->dst_ip[0]) ||
  1217. (rule->src_ip[0] != input->src_ip[0]) ||
  1218. (rule->dst_port != input->dst_port) ||
  1219. (rule->src_port != input->src_port))
  1220. return false;
  1221. return true;
  1222. }
  1223. /**
  1224. * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
  1225. * @vsi: Pointer to the targeted VSI
  1226. * @input: The filter to update or NULL to indicate deletion
  1227. * @sw_idx: Software index to the filter
  1228. * @cmd: The command to get or set Rx flow classification rules
  1229. *
  1230. * This function updates (or deletes) a Flow Director entry from
  1231. * the hlist of the corresponding PF
  1232. *
  1233. * Returns 0 on success
  1234. **/
  1235. static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
  1236. struct i40e_fdir_filter *input,
  1237. u16 sw_idx,
  1238. struct ethtool_rxnfc *cmd)
  1239. {
  1240. struct i40e_fdir_filter *rule, *parent;
  1241. struct i40e_pf *pf = vsi->back;
  1242. struct hlist_node *node2;
  1243. int err = -EINVAL;
  1244. parent = NULL;
  1245. rule = NULL;
  1246. hlist_for_each_entry_safe(rule, node2,
  1247. &pf->fdir_filter_list, fdir_node) {
  1248. /* hash found, or no matching entry */
  1249. if (rule->fd_id >= sw_idx)
  1250. break;
  1251. parent = rule;
  1252. }
  1253. /* if there is an old rule occupying our place remove it */
  1254. if (rule && (rule->fd_id == sw_idx)) {
  1255. if (input && !i40e_match_fdir_input_set(rule, input))
  1256. err = i40e_add_del_fdir(vsi, rule, false);
  1257. else if (!input)
  1258. err = i40e_add_del_fdir(vsi, rule, false);
  1259. hlist_del(&rule->fdir_node);
  1260. kfree(rule);
  1261. pf->fdir_pf_active_filters--;
  1262. }
  1263. /* If no input this was a delete, err should be 0 if a rule was
  1264. * successfully found and removed from the list else -EINVAL
  1265. */
  1266. if (!input)
  1267. return err;
  1268. /* initialize node and set software index */
  1269. INIT_HLIST_NODE(&input->fdir_node);
  1270. /* add filter to the list */
  1271. if (parent)
  1272. hlist_add_after(&parent->fdir_node, &input->fdir_node);
  1273. else
  1274. hlist_add_head(&input->fdir_node,
  1275. &pf->fdir_filter_list);
  1276. /* update counts */
  1277. pf->fdir_pf_active_filters++;
  1278. return 0;
  1279. }
  1280. /**
  1281. * i40e_del_fdir_entry - Deletes a Flow Director filter entry
  1282. * @vsi: Pointer to the targeted VSI
  1283. * @cmd: The command to get or set Rx flow classification rules
  1284. *
  1285. * The function removes a Flow Director filter entry from the
  1286. * hlist of the corresponding PF
  1287. *
  1288. * Returns 0 on success
  1289. */
  1290. static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
  1291. struct ethtool_rxnfc *cmd)
  1292. {
  1293. struct ethtool_rx_flow_spec *fsp =
  1294. (struct ethtool_rx_flow_spec *)&cmd->fs;
  1295. struct i40e_pf *pf = vsi->back;
  1296. int ret = 0;
  1297. ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
  1298. i40e_fdir_check_and_reenable(pf);
  1299. return ret;
  1300. }
  1301. /**
  1302. * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
  1303. * @vsi: pointer to the targeted VSI
  1304. * @cmd: command to get or set RX flow classification rules
  1305. *
  1306. * Add Flow Director filters for a specific flow spec based on their
  1307. * protocol. Returns 0 if the filters were successfully added.
  1308. **/
  1309. static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
  1310. struct ethtool_rxnfc *cmd)
  1311. {
  1312. struct ethtool_rx_flow_spec *fsp;
  1313. struct i40e_fdir_filter *input;
  1314. struct i40e_pf *pf;
  1315. int ret = -EINVAL;
  1316. if (!vsi)
  1317. return -EINVAL;
  1318. pf = vsi->back;
  1319. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  1320. return -EOPNOTSUPP;
  1321. if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
  1322. return -ENOSPC;
  1323. fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
  1324. if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
  1325. pf->hw.func_caps.fd_filters_guaranteed)) {
  1326. return -EINVAL;
  1327. }
  1328. if (fsp->ring_cookie >= vsi->num_queue_pairs)
  1329. return -EINVAL;
  1330. input = kzalloc(sizeof(*input), GFP_KERNEL);
  1331. if (!input)
  1332. return -ENOMEM;
  1333. input->fd_id = fsp->location;
  1334. input->q_index = fsp->ring_cookie;
  1335. input->flex_off = 0;
  1336. input->pctype = 0;
  1337. input->dest_vsi = vsi->id;
  1338. input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
  1339. input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
  1340. input->cnt_index = 0;
  1341. input->flow_type = fsp->flow_type;
  1342. input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
  1343. input->src_port = fsp->h_u.tcp_ip4_spec.psrc;
  1344. input->dst_port = fsp->h_u.tcp_ip4_spec.pdst;
  1345. input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
  1346. input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
  1347. ret = i40e_add_del_fdir(vsi, input, true);
  1348. if (ret)
  1349. kfree(input);
  1350. else
  1351. i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
  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_fdir_ethtool(vsi, cmd);
  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. }