i40e_ethtool.c 40 KB

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