i40e_ethtool.c 50 KB

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