funeth_ethtool.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  1. // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
  2. #include <linux/ethtool.h>
  3. #include <linux/linkmode.h>
  4. #include <linux/netdevice.h>
  5. #include <linux/nvme.h>
  6. #include <linux/io.h>
  7. #include <linux/io-64-nonatomic-lo-hi.h>
  8. #include <linux/pci.h>
  9. #include <linux/rtnetlink.h>
  10. #include "funeth.h"
  11. #include "fun_port.h"
  12. #include "funeth_txrx.h"
  13. /* Min queue depth. The smallest power-of-2 supporting jumbo frames with 4K
  14. * pages is 8. Require it for all types of queues though some could work with
  15. * fewer entries.
  16. */
  17. #define FUNETH_MIN_QDEPTH 8
  18. static const char mac_tx_stat_names[][ETH_GSTRING_LEN] = {
  19. "mac_tx_octets_total",
  20. "mac_tx_frames_total",
  21. "mac_tx_vlan_frames_ok",
  22. "mac_tx_unicast_frames",
  23. "mac_tx_multicast_frames",
  24. "mac_tx_broadcast_frames",
  25. "mac_tx_errors",
  26. "mac_tx_CBFCPAUSE0",
  27. "mac_tx_CBFCPAUSE1",
  28. "mac_tx_CBFCPAUSE2",
  29. "mac_tx_CBFCPAUSE3",
  30. "mac_tx_CBFCPAUSE4",
  31. "mac_tx_CBFCPAUSE5",
  32. "mac_tx_CBFCPAUSE6",
  33. "mac_tx_CBFCPAUSE7",
  34. "mac_tx_CBFCPAUSE8",
  35. "mac_tx_CBFCPAUSE9",
  36. "mac_tx_CBFCPAUSE10",
  37. "mac_tx_CBFCPAUSE11",
  38. "mac_tx_CBFCPAUSE12",
  39. "mac_tx_CBFCPAUSE13",
  40. "mac_tx_CBFCPAUSE14",
  41. "mac_tx_CBFCPAUSE15",
  42. };
  43. static const char mac_rx_stat_names[][ETH_GSTRING_LEN] = {
  44. "mac_rx_octets_total",
  45. "mac_rx_frames_total",
  46. "mac_rx_VLAN_frames_ok",
  47. "mac_rx_unicast_frames",
  48. "mac_rx_multicast_frames",
  49. "mac_rx_broadcast_frames",
  50. "mac_rx_drop_events",
  51. "mac_rx_errors",
  52. "mac_rx_alignment_errors",
  53. "mac_rx_CBFCPAUSE0",
  54. "mac_rx_CBFCPAUSE1",
  55. "mac_rx_CBFCPAUSE2",
  56. "mac_rx_CBFCPAUSE3",
  57. "mac_rx_CBFCPAUSE4",
  58. "mac_rx_CBFCPAUSE5",
  59. "mac_rx_CBFCPAUSE6",
  60. "mac_rx_CBFCPAUSE7",
  61. "mac_rx_CBFCPAUSE8",
  62. "mac_rx_CBFCPAUSE9",
  63. "mac_rx_CBFCPAUSE10",
  64. "mac_rx_CBFCPAUSE11",
  65. "mac_rx_CBFCPAUSE12",
  66. "mac_rx_CBFCPAUSE13",
  67. "mac_rx_CBFCPAUSE14",
  68. "mac_rx_CBFCPAUSE15",
  69. };
  70. static const char * const txq_stat_names[] = {
  71. "tx_pkts",
  72. "tx_bytes",
  73. "tx_cso",
  74. "tx_tso",
  75. "tx_encapsulated_tso",
  76. "tx_uso",
  77. "tx_more",
  78. "tx_queue_stops",
  79. "tx_queue_restarts",
  80. "tx_mapping_errors",
  81. "tx_tls_encrypted_packets",
  82. "tx_tls_encrypted_bytes",
  83. "tx_tls_ooo",
  84. "tx_tls_drop_no_sync_data",
  85. };
  86. static const char * const xdpq_stat_names[] = {
  87. "tx_xdp_pkts",
  88. "tx_xdp_bytes",
  89. "tx_xdp_full",
  90. "tx_xdp_mapping_errors",
  91. };
  92. static const char * const rxq_stat_names[] = {
  93. "rx_pkts",
  94. "rx_bytes",
  95. "rx_cso",
  96. "gro_pkts",
  97. "gro_merged",
  98. "rx_xdp_tx",
  99. "rx_xdp_redir",
  100. "rx_xdp_drops",
  101. "rx_buffers",
  102. "rx_page_allocs",
  103. "rx_drops",
  104. "rx_budget_exhausted",
  105. "rx_mapping_errors",
  106. };
  107. static const char * const tls_stat_names[] = {
  108. "tx_tls_ctx",
  109. "tx_tls_del",
  110. "tx_tls_resync",
  111. };
  112. static void fun_link_modes_to_ethtool(u64 modes,
  113. unsigned long *ethtool_modes_map)
  114. {
  115. #define ADD_LINK_MODE(mode) \
  116. __set_bit(ETHTOOL_LINK_MODE_ ## mode ## _BIT, ethtool_modes_map)
  117. if (modes & FUN_PORT_CAP_AUTONEG)
  118. ADD_LINK_MODE(Autoneg);
  119. if (modes & FUN_PORT_CAP_1000_X)
  120. ADD_LINK_MODE(1000baseX_Full);
  121. if (modes & FUN_PORT_CAP_10G_R) {
  122. ADD_LINK_MODE(10000baseCR_Full);
  123. ADD_LINK_MODE(10000baseSR_Full);
  124. ADD_LINK_MODE(10000baseLR_Full);
  125. ADD_LINK_MODE(10000baseER_Full);
  126. }
  127. if (modes & FUN_PORT_CAP_25G_R) {
  128. ADD_LINK_MODE(25000baseCR_Full);
  129. ADD_LINK_MODE(25000baseSR_Full);
  130. }
  131. if (modes & FUN_PORT_CAP_40G_R4) {
  132. ADD_LINK_MODE(40000baseCR4_Full);
  133. ADD_LINK_MODE(40000baseSR4_Full);
  134. ADD_LINK_MODE(40000baseLR4_Full);
  135. }
  136. if (modes & FUN_PORT_CAP_50G_R2) {
  137. ADD_LINK_MODE(50000baseCR2_Full);
  138. ADD_LINK_MODE(50000baseSR2_Full);
  139. }
  140. if (modes & FUN_PORT_CAP_50G_R) {
  141. ADD_LINK_MODE(50000baseCR_Full);
  142. ADD_LINK_MODE(50000baseSR_Full);
  143. ADD_LINK_MODE(50000baseLR_ER_FR_Full);
  144. }
  145. if (modes & FUN_PORT_CAP_100G_R4) {
  146. ADD_LINK_MODE(100000baseCR4_Full);
  147. ADD_LINK_MODE(100000baseSR4_Full);
  148. ADD_LINK_MODE(100000baseLR4_ER4_Full);
  149. }
  150. if (modes & FUN_PORT_CAP_100G_R2) {
  151. ADD_LINK_MODE(100000baseCR2_Full);
  152. ADD_LINK_MODE(100000baseSR2_Full);
  153. ADD_LINK_MODE(100000baseLR2_ER2_FR2_Full);
  154. }
  155. if (modes & FUN_PORT_CAP_FEC_NONE)
  156. ADD_LINK_MODE(FEC_NONE);
  157. if (modes & FUN_PORT_CAP_FEC_FC)
  158. ADD_LINK_MODE(FEC_BASER);
  159. if (modes & FUN_PORT_CAP_FEC_RS)
  160. ADD_LINK_MODE(FEC_RS);
  161. if (modes & FUN_PORT_CAP_RX_PAUSE)
  162. ADD_LINK_MODE(Pause);
  163. #undef ADD_LINK_MODE
  164. }
  165. static void set_asym_pause(u64 advertising, struct ethtool_link_ksettings *ks)
  166. {
  167. bool rx_pause, tx_pause;
  168. rx_pause = advertising & FUN_PORT_CAP_RX_PAUSE;
  169. tx_pause = advertising & FUN_PORT_CAP_TX_PAUSE;
  170. if (tx_pause ^ rx_pause)
  171. ethtool_link_ksettings_add_link_mode(ks, advertising,
  172. Asym_Pause);
  173. }
  174. static unsigned int fun_port_type(unsigned int xcvr)
  175. {
  176. if (!xcvr)
  177. return PORT_NONE;
  178. switch (xcvr & 7) {
  179. case FUN_XCVR_BASET:
  180. return PORT_TP;
  181. case FUN_XCVR_CU:
  182. return PORT_DA;
  183. default:
  184. return PORT_FIBRE;
  185. }
  186. }
  187. static int fun_get_link_ksettings(struct net_device *netdev,
  188. struct ethtool_link_ksettings *ks)
  189. {
  190. const struct funeth_priv *fp = netdev_priv(netdev);
  191. unsigned int seq, speed, xcvr;
  192. u64 lp_advertising;
  193. bool link_up;
  194. ethtool_link_ksettings_zero_link_mode(ks, supported);
  195. ethtool_link_ksettings_zero_link_mode(ks, advertising);
  196. ethtool_link_ksettings_zero_link_mode(ks, lp_advertising);
  197. /* Link settings change asynchronously, take a consistent snapshot */
  198. do {
  199. seq = read_seqcount_begin(&fp->link_seq);
  200. link_up = netif_carrier_ok(netdev);
  201. speed = fp->link_speed;
  202. xcvr = fp->xcvr_type;
  203. lp_advertising = fp->lp_advertising;
  204. } while (read_seqcount_retry(&fp->link_seq, seq));
  205. if (link_up) {
  206. ks->base.speed = speed;
  207. ks->base.duplex = DUPLEX_FULL;
  208. fun_link_modes_to_ethtool(lp_advertising,
  209. ks->link_modes.lp_advertising);
  210. } else {
  211. ks->base.speed = SPEED_UNKNOWN;
  212. ks->base.duplex = DUPLEX_UNKNOWN;
  213. }
  214. ks->base.autoneg = (fp->advertising & FUN_PORT_CAP_AUTONEG) ?
  215. AUTONEG_ENABLE : AUTONEG_DISABLE;
  216. ks->base.port = fun_port_type(xcvr);
  217. fun_link_modes_to_ethtool(fp->port_caps, ks->link_modes.supported);
  218. if (fp->port_caps & (FUN_PORT_CAP_RX_PAUSE | FUN_PORT_CAP_TX_PAUSE))
  219. ethtool_link_ksettings_add_link_mode(ks, supported, Asym_Pause);
  220. fun_link_modes_to_ethtool(fp->advertising, ks->link_modes.advertising);
  221. set_asym_pause(fp->advertising, ks);
  222. return 0;
  223. }
  224. static u64 fun_advert_modes(const struct ethtool_link_ksettings *ks)
  225. {
  226. u64 modes = 0;
  227. #define HAS_MODE(mode) \
  228. ethtool_link_ksettings_test_link_mode(ks, advertising, mode)
  229. if (HAS_MODE(1000baseX_Full))
  230. modes |= FUN_PORT_CAP_1000_X;
  231. if (HAS_MODE(10000baseCR_Full) || HAS_MODE(10000baseSR_Full) ||
  232. HAS_MODE(10000baseLR_Full) || HAS_MODE(10000baseER_Full))
  233. modes |= FUN_PORT_CAP_10G_R;
  234. if (HAS_MODE(25000baseCR_Full) || HAS_MODE(25000baseSR_Full))
  235. modes |= FUN_PORT_CAP_25G_R;
  236. if (HAS_MODE(40000baseCR4_Full) || HAS_MODE(40000baseSR4_Full) ||
  237. HAS_MODE(40000baseLR4_Full))
  238. modes |= FUN_PORT_CAP_40G_R4;
  239. if (HAS_MODE(50000baseCR2_Full) || HAS_MODE(50000baseSR2_Full))
  240. modes |= FUN_PORT_CAP_50G_R2;
  241. if (HAS_MODE(50000baseCR_Full) || HAS_MODE(50000baseSR_Full) ||
  242. HAS_MODE(50000baseLR_ER_FR_Full))
  243. modes |= FUN_PORT_CAP_50G_R;
  244. if (HAS_MODE(100000baseCR4_Full) || HAS_MODE(100000baseSR4_Full) ||
  245. HAS_MODE(100000baseLR4_ER4_Full))
  246. modes |= FUN_PORT_CAP_100G_R4;
  247. if (HAS_MODE(100000baseCR2_Full) || HAS_MODE(100000baseSR2_Full) ||
  248. HAS_MODE(100000baseLR2_ER2_FR2_Full))
  249. modes |= FUN_PORT_CAP_100G_R2;
  250. return modes;
  251. #undef HAS_MODE
  252. }
  253. static u64 fun_speed_to_link_mode(unsigned int speed)
  254. {
  255. switch (speed) {
  256. case SPEED_100000:
  257. return FUN_PORT_CAP_100G_R4 | FUN_PORT_CAP_100G_R2;
  258. case SPEED_50000:
  259. return FUN_PORT_CAP_50G_R | FUN_PORT_CAP_50G_R2;
  260. case SPEED_40000:
  261. return FUN_PORT_CAP_40G_R4;
  262. case SPEED_25000:
  263. return FUN_PORT_CAP_25G_R;
  264. case SPEED_10000:
  265. return FUN_PORT_CAP_10G_R;
  266. case SPEED_1000:
  267. return FUN_PORT_CAP_1000_X;
  268. default:
  269. return 0;
  270. }
  271. }
  272. static int fun_change_advert(struct funeth_priv *fp, u64 new_advert)
  273. {
  274. int err;
  275. if (new_advert == fp->advertising)
  276. return 0;
  277. err = fun_port_write_cmd(fp, FUN_ADMIN_PORT_KEY_ADVERT, new_advert);
  278. if (!err)
  279. fp->advertising = new_advert;
  280. return err;
  281. }
  282. #define FUN_PORT_CAP_FEC_MASK \
  283. (FUN_PORT_CAP_FEC_NONE | FUN_PORT_CAP_FEC_FC | FUN_PORT_CAP_FEC_RS)
  284. static int fun_set_link_ksettings(struct net_device *netdev,
  285. const struct ethtool_link_ksettings *ks)
  286. {
  287. __ETHTOOL_DECLARE_LINK_MODE_MASK(supported) = {};
  288. struct funeth_priv *fp = netdev_priv(netdev);
  289. u64 new_advert;
  290. /* eswitch ports don't support mode changes */
  291. if (fp->port_caps & FUN_PORT_CAP_VPORT)
  292. return -EOPNOTSUPP;
  293. if (ks->base.duplex == DUPLEX_HALF)
  294. return -EINVAL;
  295. if (ks->base.autoneg == AUTONEG_ENABLE &&
  296. !(fp->port_caps & FUN_PORT_CAP_AUTONEG))
  297. return -EINVAL;
  298. if (ks->base.autoneg == AUTONEG_ENABLE) {
  299. if (linkmode_empty(ks->link_modes.advertising))
  300. return -EINVAL;
  301. fun_link_modes_to_ethtool(fp->port_caps, supported);
  302. if (!linkmode_subset(ks->link_modes.advertising, supported))
  303. return -EINVAL;
  304. new_advert = fun_advert_modes(ks) | FUN_PORT_CAP_AUTONEG;
  305. } else {
  306. new_advert = fun_speed_to_link_mode(ks->base.speed);
  307. new_advert &= fp->port_caps;
  308. if (!new_advert)
  309. return -EINVAL;
  310. }
  311. new_advert |= fp->advertising &
  312. (FUN_PORT_CAP_PAUSE_MASK | FUN_PORT_CAP_FEC_MASK);
  313. return fun_change_advert(fp, new_advert);
  314. }
  315. static void fun_get_pauseparam(struct net_device *netdev,
  316. struct ethtool_pauseparam *pause)
  317. {
  318. const struct funeth_priv *fp = netdev_priv(netdev);
  319. u8 active_pause = fp->active_fc;
  320. pause->rx_pause = !!(active_pause & FUN_PORT_CAP_RX_PAUSE);
  321. pause->tx_pause = !!(active_pause & FUN_PORT_CAP_TX_PAUSE);
  322. pause->autoneg = !!(fp->advertising & FUN_PORT_CAP_AUTONEG);
  323. }
  324. static int fun_set_pauseparam(struct net_device *netdev,
  325. struct ethtool_pauseparam *pause)
  326. {
  327. struct funeth_priv *fp = netdev_priv(netdev);
  328. u64 new_advert;
  329. if (fp->port_caps & FUN_PORT_CAP_VPORT)
  330. return -EOPNOTSUPP;
  331. /* Forcing PAUSE settings with AN enabled is unsupported. */
  332. if (!pause->autoneg && (fp->advertising & FUN_PORT_CAP_AUTONEG))
  333. return -EOPNOTSUPP;
  334. if (pause->autoneg && !(fp->advertising & FUN_PORT_CAP_AUTONEG))
  335. return -EINVAL;
  336. if (pause->tx_pause && !(fp->port_caps & FUN_PORT_CAP_TX_PAUSE))
  337. return -EINVAL;
  338. if (pause->rx_pause && !(fp->port_caps & FUN_PORT_CAP_RX_PAUSE))
  339. return -EINVAL;
  340. new_advert = fp->advertising & ~FUN_PORT_CAP_PAUSE_MASK;
  341. if (pause->tx_pause)
  342. new_advert |= FUN_PORT_CAP_TX_PAUSE;
  343. if (pause->rx_pause)
  344. new_advert |= FUN_PORT_CAP_RX_PAUSE;
  345. return fun_change_advert(fp, new_advert);
  346. }
  347. static int fun_restart_an(struct net_device *netdev)
  348. {
  349. struct funeth_priv *fp = netdev_priv(netdev);
  350. if (!(fp->advertising & FUN_PORT_CAP_AUTONEG))
  351. return -EOPNOTSUPP;
  352. return fun_port_write_cmd(fp, FUN_ADMIN_PORT_KEY_ADVERT,
  353. FUN_PORT_CAP_AUTONEG);
  354. }
  355. static int fun_set_phys_id(struct net_device *netdev,
  356. enum ethtool_phys_id_state state)
  357. {
  358. struct funeth_priv *fp = netdev_priv(netdev);
  359. unsigned int beacon;
  360. if (fp->port_caps & FUN_PORT_CAP_VPORT)
  361. return -EOPNOTSUPP;
  362. if (state != ETHTOOL_ID_ACTIVE && state != ETHTOOL_ID_INACTIVE)
  363. return -EOPNOTSUPP;
  364. beacon = state == ETHTOOL_ID_ACTIVE ? FUN_PORT_LED_BEACON_ON :
  365. FUN_PORT_LED_BEACON_OFF;
  366. return fun_port_write_cmd(fp, FUN_ADMIN_PORT_KEY_LED, beacon);
  367. }
  368. static void fun_get_drvinfo(struct net_device *netdev,
  369. struct ethtool_drvinfo *info)
  370. {
  371. const struct funeth_priv *fp = netdev_priv(netdev);
  372. strscpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
  373. strscpy(info->bus_info, pci_name(fp->pdev), sizeof(info->bus_info));
  374. }
  375. static u32 fun_get_msglevel(struct net_device *netdev)
  376. {
  377. const struct funeth_priv *fp = netdev_priv(netdev);
  378. return fp->msg_enable;
  379. }
  380. static void fun_set_msglevel(struct net_device *netdev, u32 value)
  381. {
  382. struct funeth_priv *fp = netdev_priv(netdev);
  383. fp->msg_enable = value;
  384. }
  385. static int fun_get_regs_len(struct net_device *dev)
  386. {
  387. return NVME_REG_ACQ + sizeof(u64);
  388. }
  389. static void fun_get_regs(struct net_device *dev, struct ethtool_regs *regs,
  390. void *buf)
  391. {
  392. const struct funeth_priv *fp = netdev_priv(dev);
  393. void __iomem *bar = fp->fdev->bar;
  394. regs->version = 0;
  395. *(u64 *)(buf + NVME_REG_CAP) = readq(bar + NVME_REG_CAP);
  396. *(u32 *)(buf + NVME_REG_VS) = readl(bar + NVME_REG_VS);
  397. *(u32 *)(buf + NVME_REG_INTMS) = readl(bar + NVME_REG_INTMS);
  398. *(u32 *)(buf + NVME_REG_INTMC) = readl(bar + NVME_REG_INTMC);
  399. *(u32 *)(buf + NVME_REG_CC) = readl(bar + NVME_REG_CC);
  400. *(u32 *)(buf + NVME_REG_CSTS) = readl(bar + NVME_REG_CSTS);
  401. *(u32 *)(buf + NVME_REG_AQA) = readl(bar + NVME_REG_AQA);
  402. *(u64 *)(buf + NVME_REG_ASQ) = readq(bar + NVME_REG_ASQ);
  403. *(u64 *)(buf + NVME_REG_ACQ) = readq(bar + NVME_REG_ACQ);
  404. }
  405. static int fun_get_coalesce(struct net_device *netdev,
  406. struct ethtool_coalesce *coal,
  407. struct kernel_ethtool_coalesce *kcoal,
  408. struct netlink_ext_ack *ext_ack)
  409. {
  410. const struct funeth_priv *fp = netdev_priv(netdev);
  411. coal->rx_coalesce_usecs = fp->rx_coal_usec;
  412. coal->rx_max_coalesced_frames = fp->rx_coal_count;
  413. coal->use_adaptive_rx_coalesce = !fp->cq_irq_db;
  414. coal->tx_coalesce_usecs = fp->tx_coal_usec;
  415. coal->tx_max_coalesced_frames = fp->tx_coal_count;
  416. return 0;
  417. }
  418. static int fun_set_coalesce(struct net_device *netdev,
  419. struct ethtool_coalesce *coal,
  420. struct kernel_ethtool_coalesce *kcoal,
  421. struct netlink_ext_ack *ext_ack)
  422. {
  423. struct funeth_priv *fp = netdev_priv(netdev);
  424. struct funeth_rxq **rxqs;
  425. unsigned int i, db_val;
  426. if (coal->rx_coalesce_usecs > FUN_DB_INTCOAL_USEC_M ||
  427. coal->rx_max_coalesced_frames > FUN_DB_INTCOAL_ENTRIES_M ||
  428. (coal->rx_coalesce_usecs | coal->rx_max_coalesced_frames) == 0 ||
  429. coal->tx_coalesce_usecs > FUN_DB_INTCOAL_USEC_M ||
  430. coal->tx_max_coalesced_frames > FUN_DB_INTCOAL_ENTRIES_M ||
  431. (coal->tx_coalesce_usecs | coal->tx_max_coalesced_frames) == 0)
  432. return -EINVAL;
  433. /* a timer is required if there's any coalescing */
  434. if ((coal->rx_max_coalesced_frames > 1 && !coal->rx_coalesce_usecs) ||
  435. (coal->tx_max_coalesced_frames > 1 && !coal->tx_coalesce_usecs))
  436. return -EINVAL;
  437. fp->rx_coal_usec = coal->rx_coalesce_usecs;
  438. fp->rx_coal_count = coal->rx_max_coalesced_frames;
  439. fp->tx_coal_usec = coal->tx_coalesce_usecs;
  440. fp->tx_coal_count = coal->tx_max_coalesced_frames;
  441. db_val = FUN_IRQ_CQ_DB(fp->rx_coal_usec, fp->rx_coal_count);
  442. WRITE_ONCE(fp->cq_irq_db, db_val);
  443. rxqs = rtnl_dereference(fp->rxqs);
  444. if (!rxqs)
  445. return 0;
  446. for (i = 0; i < netdev->real_num_rx_queues; i++)
  447. WRITE_ONCE(rxqs[i]->irq_db_val, db_val);
  448. db_val = FUN_IRQ_SQ_DB(fp->tx_coal_usec, fp->tx_coal_count);
  449. for (i = 0; i < netdev->real_num_tx_queues; i++)
  450. WRITE_ONCE(fp->txqs[i]->irq_db_val, db_val);
  451. return 0;
  452. }
  453. static void fun_get_channels(struct net_device *netdev,
  454. struct ethtool_channels *chan)
  455. {
  456. chan->max_rx = netdev->num_rx_queues;
  457. chan->rx_count = netdev->real_num_rx_queues;
  458. chan->max_tx = netdev->num_tx_queues;
  459. chan->tx_count = netdev->real_num_tx_queues;
  460. }
  461. static int fun_set_channels(struct net_device *netdev,
  462. struct ethtool_channels *chan)
  463. {
  464. if (!chan->tx_count || !chan->rx_count)
  465. return -EINVAL;
  466. if (chan->tx_count == netdev->real_num_tx_queues &&
  467. chan->rx_count == netdev->real_num_rx_queues)
  468. return 0;
  469. if (netif_running(netdev))
  470. return fun_change_num_queues(netdev, chan->tx_count,
  471. chan->rx_count);
  472. fun_set_ring_count(netdev, chan->tx_count, chan->rx_count);
  473. return 0;
  474. }
  475. static void fun_get_ringparam(struct net_device *netdev,
  476. struct ethtool_ringparam *ring,
  477. struct kernel_ethtool_ringparam *kring,
  478. struct netlink_ext_ack *extack)
  479. {
  480. const struct funeth_priv *fp = netdev_priv(netdev);
  481. unsigned int max_depth = fp->fdev->q_depth;
  482. /* We size CQs to be twice the RQ depth so max RQ depth is half the
  483. * max queue depth.
  484. */
  485. ring->rx_max_pending = max_depth / 2;
  486. ring->tx_max_pending = max_depth;
  487. ring->rx_pending = fp->rq_depth;
  488. ring->tx_pending = fp->sq_depth;
  489. kring->rx_buf_len = PAGE_SIZE;
  490. kring->cqe_size = FUNETH_CQE_SIZE;
  491. }
  492. static int fun_set_ringparam(struct net_device *netdev,
  493. struct ethtool_ringparam *ring,
  494. struct kernel_ethtool_ringparam *kring,
  495. struct netlink_ext_ack *extack)
  496. {
  497. struct funeth_priv *fp = netdev_priv(netdev);
  498. int rc;
  499. if (ring->rx_mini_pending || ring->rx_jumbo_pending)
  500. return -EINVAL;
  501. /* queue depths must be powers-of-2 */
  502. if (!is_power_of_2(ring->rx_pending) ||
  503. !is_power_of_2(ring->tx_pending))
  504. return -EINVAL;
  505. if (ring->rx_pending < FUNETH_MIN_QDEPTH ||
  506. ring->tx_pending < FUNETH_MIN_QDEPTH)
  507. return -EINVAL;
  508. if (fp->sq_depth == ring->tx_pending &&
  509. fp->rq_depth == ring->rx_pending)
  510. return 0;
  511. if (netif_running(netdev)) {
  512. struct fun_qset req = {
  513. .cq_depth = 2 * ring->rx_pending,
  514. .rq_depth = ring->rx_pending,
  515. .sq_depth = ring->tx_pending
  516. };
  517. rc = fun_replace_queues(netdev, &req, extack);
  518. if (rc)
  519. return rc;
  520. }
  521. fp->sq_depth = ring->tx_pending;
  522. fp->rq_depth = ring->rx_pending;
  523. fp->cq_depth = 2 * fp->rq_depth;
  524. return 0;
  525. }
  526. static int fun_get_sset_count(struct net_device *dev, int sset)
  527. {
  528. const struct funeth_priv *fp = netdev_priv(dev);
  529. int n;
  530. switch (sset) {
  531. case ETH_SS_STATS:
  532. n = (dev->real_num_tx_queues + 1) * ARRAY_SIZE(txq_stat_names) +
  533. (dev->real_num_rx_queues + 1) * ARRAY_SIZE(rxq_stat_names) +
  534. (fp->num_xdpqs + 1) * ARRAY_SIZE(xdpq_stat_names) +
  535. ARRAY_SIZE(tls_stat_names);
  536. if (fp->port_caps & FUN_PORT_CAP_STATS) {
  537. n += ARRAY_SIZE(mac_tx_stat_names) +
  538. ARRAY_SIZE(mac_rx_stat_names);
  539. }
  540. return n;
  541. default:
  542. break;
  543. }
  544. return 0;
  545. }
  546. static void fun_get_strings(struct net_device *netdev, u32 sset, u8 *data)
  547. {
  548. const struct funeth_priv *fp = netdev_priv(netdev);
  549. unsigned int i, j;
  550. u8 *p = data;
  551. switch (sset) {
  552. case ETH_SS_STATS:
  553. if (fp->port_caps & FUN_PORT_CAP_STATS) {
  554. memcpy(p, mac_tx_stat_names, sizeof(mac_tx_stat_names));
  555. p += sizeof(mac_tx_stat_names);
  556. memcpy(p, mac_rx_stat_names, sizeof(mac_rx_stat_names));
  557. p += sizeof(mac_rx_stat_names);
  558. }
  559. for (i = 0; i < netdev->real_num_tx_queues; i++) {
  560. for (j = 0; j < ARRAY_SIZE(txq_stat_names); j++)
  561. ethtool_sprintf(&p, "%s[%u]", txq_stat_names[j],
  562. i);
  563. }
  564. for (j = 0; j < ARRAY_SIZE(txq_stat_names); j++)
  565. ethtool_puts(&p, txq_stat_names[j]);
  566. for (i = 0; i < fp->num_xdpqs; i++) {
  567. for (j = 0; j < ARRAY_SIZE(xdpq_stat_names); j++)
  568. ethtool_sprintf(&p, "%s[%u]",
  569. xdpq_stat_names[j], i);
  570. }
  571. for (j = 0; j < ARRAY_SIZE(xdpq_stat_names); j++)
  572. ethtool_puts(&p, xdpq_stat_names[j]);
  573. for (i = 0; i < netdev->real_num_rx_queues; i++) {
  574. for (j = 0; j < ARRAY_SIZE(rxq_stat_names); j++)
  575. ethtool_sprintf(&p, "%s[%u]", rxq_stat_names[j],
  576. i);
  577. }
  578. for (j = 0; j < ARRAY_SIZE(rxq_stat_names); j++)
  579. ethtool_puts(&p, rxq_stat_names[j]);
  580. for (j = 0; j < ARRAY_SIZE(tls_stat_names); j++)
  581. ethtool_puts(&p, tls_stat_names[j]);
  582. break;
  583. default:
  584. break;
  585. }
  586. }
  587. static u64 *get_mac_stats(const struct funeth_priv *fp, u64 *data)
  588. {
  589. #define TX_STAT(s) \
  590. *data++ = be64_to_cpu(fp->stats[PORT_MAC_RX_STATS_MAX + PORT_MAC_TX_##s])
  591. TX_STAT(etherStatsOctets);
  592. TX_STAT(etherStatsPkts);
  593. TX_STAT(VLANTransmittedOK);
  594. TX_STAT(ifOutUcastPkts);
  595. TX_STAT(ifOutMulticastPkts);
  596. TX_STAT(ifOutBroadcastPkts);
  597. TX_STAT(ifOutErrors);
  598. TX_STAT(CBFCPAUSEFramesTransmitted_0);
  599. TX_STAT(CBFCPAUSEFramesTransmitted_1);
  600. TX_STAT(CBFCPAUSEFramesTransmitted_2);
  601. TX_STAT(CBFCPAUSEFramesTransmitted_3);
  602. TX_STAT(CBFCPAUSEFramesTransmitted_4);
  603. TX_STAT(CBFCPAUSEFramesTransmitted_5);
  604. TX_STAT(CBFCPAUSEFramesTransmitted_6);
  605. TX_STAT(CBFCPAUSEFramesTransmitted_7);
  606. TX_STAT(CBFCPAUSEFramesTransmitted_8);
  607. TX_STAT(CBFCPAUSEFramesTransmitted_9);
  608. TX_STAT(CBFCPAUSEFramesTransmitted_10);
  609. TX_STAT(CBFCPAUSEFramesTransmitted_11);
  610. TX_STAT(CBFCPAUSEFramesTransmitted_12);
  611. TX_STAT(CBFCPAUSEFramesTransmitted_13);
  612. TX_STAT(CBFCPAUSEFramesTransmitted_14);
  613. TX_STAT(CBFCPAUSEFramesTransmitted_15);
  614. #define RX_STAT(s) *data++ = be64_to_cpu(fp->stats[PORT_MAC_RX_##s])
  615. RX_STAT(etherStatsOctets);
  616. RX_STAT(etherStatsPkts);
  617. RX_STAT(VLANReceivedOK);
  618. RX_STAT(ifInUcastPkts);
  619. RX_STAT(ifInMulticastPkts);
  620. RX_STAT(ifInBroadcastPkts);
  621. RX_STAT(etherStatsDropEvents);
  622. RX_STAT(ifInErrors);
  623. RX_STAT(aAlignmentErrors);
  624. RX_STAT(CBFCPAUSEFramesReceived_0);
  625. RX_STAT(CBFCPAUSEFramesReceived_1);
  626. RX_STAT(CBFCPAUSEFramesReceived_2);
  627. RX_STAT(CBFCPAUSEFramesReceived_3);
  628. RX_STAT(CBFCPAUSEFramesReceived_4);
  629. RX_STAT(CBFCPAUSEFramesReceived_5);
  630. RX_STAT(CBFCPAUSEFramesReceived_6);
  631. RX_STAT(CBFCPAUSEFramesReceived_7);
  632. RX_STAT(CBFCPAUSEFramesReceived_8);
  633. RX_STAT(CBFCPAUSEFramesReceived_9);
  634. RX_STAT(CBFCPAUSEFramesReceived_10);
  635. RX_STAT(CBFCPAUSEFramesReceived_11);
  636. RX_STAT(CBFCPAUSEFramesReceived_12);
  637. RX_STAT(CBFCPAUSEFramesReceived_13);
  638. RX_STAT(CBFCPAUSEFramesReceived_14);
  639. RX_STAT(CBFCPAUSEFramesReceived_15);
  640. return data;
  641. #undef TX_STAT
  642. #undef RX_STAT
  643. }
  644. static void fun_get_ethtool_stats(struct net_device *netdev,
  645. struct ethtool_stats *stats, u64 *data)
  646. {
  647. const struct funeth_priv *fp = netdev_priv(netdev);
  648. struct funeth_txq_stats txs;
  649. struct funeth_rxq_stats rxs;
  650. struct funeth_txq **xdpqs;
  651. struct funeth_rxq **rxqs;
  652. unsigned int i, start;
  653. u64 *totals, *tot;
  654. if (fp->port_caps & FUN_PORT_CAP_STATS)
  655. data = get_mac_stats(fp, data);
  656. rxqs = rtnl_dereference(fp->rxqs);
  657. if (!rxqs)
  658. return;
  659. #define ADD_STAT(cnt) do { \
  660. *data = (cnt); *tot++ += *data++; \
  661. } while (0)
  662. /* Tx queues */
  663. totals = data + netdev->real_num_tx_queues * ARRAY_SIZE(txq_stat_names);
  664. for (i = 0; i < netdev->real_num_tx_queues; i++) {
  665. tot = totals;
  666. FUN_QSTAT_READ(fp->txqs[i], start, txs);
  667. ADD_STAT(txs.tx_pkts);
  668. ADD_STAT(txs.tx_bytes);
  669. ADD_STAT(txs.tx_cso);
  670. ADD_STAT(txs.tx_tso);
  671. ADD_STAT(txs.tx_encap_tso);
  672. ADD_STAT(txs.tx_uso);
  673. ADD_STAT(txs.tx_more);
  674. ADD_STAT(txs.tx_nstops);
  675. ADD_STAT(txs.tx_nrestarts);
  676. ADD_STAT(txs.tx_map_err);
  677. ADD_STAT(txs.tx_tls_pkts);
  678. ADD_STAT(txs.tx_tls_bytes);
  679. ADD_STAT(txs.tx_tls_fallback);
  680. ADD_STAT(txs.tx_tls_drops);
  681. }
  682. data += ARRAY_SIZE(txq_stat_names);
  683. /* XDP Tx queues */
  684. xdpqs = rtnl_dereference(fp->xdpqs);
  685. totals = data + fp->num_xdpqs * ARRAY_SIZE(xdpq_stat_names);
  686. for (i = 0; i < fp->num_xdpqs; i++) {
  687. tot = totals;
  688. FUN_QSTAT_READ(xdpqs[i], start, txs);
  689. ADD_STAT(txs.tx_pkts);
  690. ADD_STAT(txs.tx_bytes);
  691. ADD_STAT(txs.tx_xdp_full);
  692. ADD_STAT(txs.tx_map_err);
  693. }
  694. data += ARRAY_SIZE(xdpq_stat_names);
  695. /* Rx queues */
  696. totals = data + netdev->real_num_rx_queues * ARRAY_SIZE(rxq_stat_names);
  697. for (i = 0; i < netdev->real_num_rx_queues; i++) {
  698. tot = totals;
  699. FUN_QSTAT_READ(rxqs[i], start, rxs);
  700. ADD_STAT(rxs.rx_pkts);
  701. ADD_STAT(rxs.rx_bytes);
  702. ADD_STAT(rxs.rx_cso);
  703. ADD_STAT(rxs.gro_pkts);
  704. ADD_STAT(rxs.gro_merged);
  705. ADD_STAT(rxs.xdp_tx);
  706. ADD_STAT(rxs.xdp_redir);
  707. ADD_STAT(rxs.xdp_drops);
  708. ADD_STAT(rxs.rx_bufs);
  709. ADD_STAT(rxs.rx_page_alloc);
  710. ADD_STAT(rxs.rx_mem_drops + rxs.xdp_err);
  711. ADD_STAT(rxs.rx_budget);
  712. ADD_STAT(rxs.rx_map_err);
  713. }
  714. data += ARRAY_SIZE(rxq_stat_names);
  715. #undef ADD_STAT
  716. *data++ = atomic64_read(&fp->tx_tls_add);
  717. *data++ = atomic64_read(&fp->tx_tls_del);
  718. *data++ = atomic64_read(&fp->tx_tls_resync);
  719. }
  720. #define RX_STAT(fp, s) be64_to_cpu((fp)->stats[PORT_MAC_RX_##s])
  721. #define TX_STAT(fp, s) \
  722. be64_to_cpu((fp)->stats[PORT_MAC_RX_STATS_MAX + PORT_MAC_TX_##s])
  723. #define FEC_STAT(fp, s) \
  724. be64_to_cpu((fp)->stats[PORT_MAC_RX_STATS_MAX + \
  725. PORT_MAC_TX_STATS_MAX + PORT_MAC_FEC_##s])
  726. static void fun_get_pause_stats(struct net_device *netdev,
  727. struct ethtool_pause_stats *stats)
  728. {
  729. const struct funeth_priv *fp = netdev_priv(netdev);
  730. if (!(fp->port_caps & FUN_PORT_CAP_STATS))
  731. return;
  732. stats->tx_pause_frames = TX_STAT(fp, aPAUSEMACCtrlFramesTransmitted);
  733. stats->rx_pause_frames = RX_STAT(fp, aPAUSEMACCtrlFramesReceived);
  734. }
  735. static void fun_get_802_3_stats(struct net_device *netdev,
  736. struct ethtool_eth_mac_stats *stats)
  737. {
  738. const struct funeth_priv *fp = netdev_priv(netdev);
  739. if (!(fp->port_caps & FUN_PORT_CAP_STATS))
  740. return;
  741. stats->FramesTransmittedOK = TX_STAT(fp, aFramesTransmittedOK);
  742. stats->FramesReceivedOK = RX_STAT(fp, aFramesReceivedOK);
  743. stats->FrameCheckSequenceErrors = RX_STAT(fp, aFrameCheckSequenceErrors);
  744. stats->OctetsTransmittedOK = TX_STAT(fp, OctetsTransmittedOK);
  745. stats->OctetsReceivedOK = RX_STAT(fp, OctetsReceivedOK);
  746. stats->InRangeLengthErrors = RX_STAT(fp, aInRangeLengthErrors);
  747. stats->FrameTooLongErrors = RX_STAT(fp, aFrameTooLongErrors);
  748. }
  749. static void fun_get_802_3_ctrl_stats(struct net_device *netdev,
  750. struct ethtool_eth_ctrl_stats *stats)
  751. {
  752. const struct funeth_priv *fp = netdev_priv(netdev);
  753. if (!(fp->port_caps & FUN_PORT_CAP_STATS))
  754. return;
  755. stats->MACControlFramesTransmitted = TX_STAT(fp, MACControlFramesTransmitted);
  756. stats->MACControlFramesReceived = RX_STAT(fp, MACControlFramesReceived);
  757. }
  758. static void fun_get_rmon_stats(struct net_device *netdev,
  759. struct ethtool_rmon_stats *stats,
  760. const struct ethtool_rmon_hist_range **ranges)
  761. {
  762. static const struct ethtool_rmon_hist_range rmon_ranges[] = {
  763. { 64, 64 },
  764. { 65, 127 },
  765. { 128, 255 },
  766. { 256, 511 },
  767. { 512, 1023 },
  768. { 1024, 1518 },
  769. { 1519, 32767 },
  770. {}
  771. };
  772. const struct funeth_priv *fp = netdev_priv(netdev);
  773. if (!(fp->port_caps & FUN_PORT_CAP_STATS))
  774. return;
  775. stats->undersize_pkts = RX_STAT(fp, etherStatsUndersizePkts);
  776. stats->oversize_pkts = RX_STAT(fp, etherStatsOversizePkts);
  777. stats->fragments = RX_STAT(fp, etherStatsFragments);
  778. stats->jabbers = RX_STAT(fp, etherStatsJabbers);
  779. stats->hist[0] = RX_STAT(fp, etherStatsPkts64Octets);
  780. stats->hist[1] = RX_STAT(fp, etherStatsPkts65to127Octets);
  781. stats->hist[2] = RX_STAT(fp, etherStatsPkts128to255Octets);
  782. stats->hist[3] = RX_STAT(fp, etherStatsPkts256to511Octets);
  783. stats->hist[4] = RX_STAT(fp, etherStatsPkts512to1023Octets);
  784. stats->hist[5] = RX_STAT(fp, etherStatsPkts1024to1518Octets);
  785. stats->hist[6] = RX_STAT(fp, etherStatsPkts1519toMaxOctets);
  786. stats->hist_tx[0] = TX_STAT(fp, etherStatsPkts64Octets);
  787. stats->hist_tx[1] = TX_STAT(fp, etherStatsPkts65to127Octets);
  788. stats->hist_tx[2] = TX_STAT(fp, etherStatsPkts128to255Octets);
  789. stats->hist_tx[3] = TX_STAT(fp, etherStatsPkts256to511Octets);
  790. stats->hist_tx[4] = TX_STAT(fp, etherStatsPkts512to1023Octets);
  791. stats->hist_tx[5] = TX_STAT(fp, etherStatsPkts1024to1518Octets);
  792. stats->hist_tx[6] = TX_STAT(fp, etherStatsPkts1519toMaxOctets);
  793. *ranges = rmon_ranges;
  794. }
  795. static void fun_get_fec_stats(struct net_device *netdev,
  796. struct ethtool_fec_stats *stats)
  797. {
  798. const struct funeth_priv *fp = netdev_priv(netdev);
  799. if (!(fp->port_caps & FUN_PORT_CAP_STATS))
  800. return;
  801. stats->corrected_blocks.total = FEC_STAT(fp, Correctable);
  802. stats->uncorrectable_blocks.total = FEC_STAT(fp, Uncorrectable);
  803. }
  804. #undef RX_STAT
  805. #undef TX_STAT
  806. #undef FEC_STAT
  807. static int fun_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
  808. u32 *rule_locs)
  809. {
  810. switch (cmd->cmd) {
  811. case ETHTOOL_GRXRINGS:
  812. cmd->data = netdev->real_num_rx_queues;
  813. return 0;
  814. default:
  815. break;
  816. }
  817. return -EOPNOTSUPP;
  818. }
  819. static int fun_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *info)
  820. {
  821. return 0;
  822. }
  823. static u32 fun_get_rxfh_indir_size(struct net_device *netdev)
  824. {
  825. const struct funeth_priv *fp = netdev_priv(netdev);
  826. return fp->indir_table_nentries;
  827. }
  828. static u32 fun_get_rxfh_key_size(struct net_device *netdev)
  829. {
  830. const struct funeth_priv *fp = netdev_priv(netdev);
  831. return sizeof(fp->rss_key);
  832. }
  833. static int fun_get_rxfh(struct net_device *netdev,
  834. struct ethtool_rxfh_param *rxfh)
  835. {
  836. const struct funeth_priv *fp = netdev_priv(netdev);
  837. if (!fp->rss_cfg)
  838. return -EOPNOTSUPP;
  839. if (rxfh->indir)
  840. memcpy(rxfh->indir, fp->indir_table,
  841. sizeof(u32) * fp->indir_table_nentries);
  842. if (rxfh->key)
  843. memcpy(rxfh->key, fp->rss_key, sizeof(fp->rss_key));
  844. rxfh->hfunc = fp->hash_algo == FUN_ETH_RSS_ALG_TOEPLITZ ?
  845. ETH_RSS_HASH_TOP : ETH_RSS_HASH_CRC32;
  846. return 0;
  847. }
  848. static int fun_set_rxfh(struct net_device *netdev,
  849. struct ethtool_rxfh_param *rxfh,
  850. struct netlink_ext_ack *extack)
  851. {
  852. struct funeth_priv *fp = netdev_priv(netdev);
  853. const u32 *rss_indir = rxfh->indir ? rxfh->indir : fp->indir_table;
  854. const u8 *rss_key = rxfh->key ? rxfh->key : fp->rss_key;
  855. enum fun_eth_hash_alg algo;
  856. if (!fp->rss_cfg)
  857. return -EOPNOTSUPP;
  858. if (rxfh->hfunc == ETH_RSS_HASH_NO_CHANGE)
  859. algo = fp->hash_algo;
  860. else if (rxfh->hfunc == ETH_RSS_HASH_CRC32)
  861. algo = FUN_ETH_RSS_ALG_CRC32;
  862. else if (rxfh->hfunc == ETH_RSS_HASH_TOP)
  863. algo = FUN_ETH_RSS_ALG_TOEPLITZ;
  864. else
  865. return -EINVAL;
  866. /* If the port is enabled try to reconfigure RSS and keep the new
  867. * settings if successful. If it is down we update the RSS settings
  868. * and apply them at the next UP time.
  869. */
  870. if (netif_running(netdev)) {
  871. int rc = fun_config_rss(netdev, algo, rss_key, rss_indir,
  872. FUN_ADMIN_SUBOP_MODIFY);
  873. if (rc)
  874. return rc;
  875. }
  876. fp->hash_algo = algo;
  877. if (rxfh->key)
  878. memcpy(fp->rss_key, rxfh->key, sizeof(fp->rss_key));
  879. if (rxfh->indir)
  880. memcpy(fp->indir_table, rxfh->indir,
  881. sizeof(u32) * fp->indir_table_nentries);
  882. return 0;
  883. }
  884. static int fun_get_ts_info(struct net_device *netdev,
  885. struct kernel_ethtool_ts_info *info)
  886. {
  887. info->so_timestamping = SOF_TIMESTAMPING_RX_HARDWARE |
  888. SOF_TIMESTAMPING_TX_SOFTWARE |
  889. SOF_TIMESTAMPING_RAW_HARDWARE;
  890. info->tx_types = BIT(HWTSTAMP_TX_OFF);
  891. info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | BIT(HWTSTAMP_FILTER_ALL);
  892. return 0;
  893. }
  894. static unsigned int to_ethtool_fec(unsigned int fun_fec)
  895. {
  896. unsigned int fec = 0;
  897. if (fun_fec == FUN_PORT_FEC_NA)
  898. fec |= ETHTOOL_FEC_NONE;
  899. if (fun_fec & FUN_PORT_FEC_OFF)
  900. fec |= ETHTOOL_FEC_OFF;
  901. if (fun_fec & FUN_PORT_FEC_RS)
  902. fec |= ETHTOOL_FEC_RS;
  903. if (fun_fec & FUN_PORT_FEC_FC)
  904. fec |= ETHTOOL_FEC_BASER;
  905. if (fun_fec & FUN_PORT_FEC_AUTO)
  906. fec |= ETHTOOL_FEC_AUTO;
  907. return fec;
  908. }
  909. static int fun_get_fecparam(struct net_device *netdev,
  910. struct ethtool_fecparam *fec)
  911. {
  912. struct funeth_priv *fp = netdev_priv(netdev);
  913. u64 fec_data;
  914. int rc;
  915. rc = fun_port_read_cmd(fp, FUN_ADMIN_PORT_KEY_FEC, &fec_data);
  916. if (rc)
  917. return rc;
  918. fec->active_fec = to_ethtool_fec(fec_data & 0xff);
  919. fec->fec = to_ethtool_fec(fec_data >> 8);
  920. return 0;
  921. }
  922. static int fun_set_fecparam(struct net_device *netdev,
  923. struct ethtool_fecparam *fec)
  924. {
  925. struct funeth_priv *fp = netdev_priv(netdev);
  926. u64 fec_mode;
  927. switch (fec->fec) {
  928. case ETHTOOL_FEC_AUTO:
  929. fec_mode = FUN_PORT_FEC_AUTO;
  930. break;
  931. case ETHTOOL_FEC_OFF:
  932. if (!(fp->port_caps & FUN_PORT_CAP_FEC_NONE))
  933. return -EINVAL;
  934. fec_mode = FUN_PORT_FEC_OFF;
  935. break;
  936. case ETHTOOL_FEC_BASER:
  937. if (!(fp->port_caps & FUN_PORT_CAP_FEC_FC))
  938. return -EINVAL;
  939. fec_mode = FUN_PORT_FEC_FC;
  940. break;
  941. case ETHTOOL_FEC_RS:
  942. if (!(fp->port_caps & FUN_PORT_CAP_FEC_RS))
  943. return -EINVAL;
  944. fec_mode = FUN_PORT_FEC_RS;
  945. break;
  946. default:
  947. return -EINVAL;
  948. }
  949. return fun_port_write_cmd(fp, FUN_ADMIN_PORT_KEY_FEC, fec_mode);
  950. }
  951. static int fun_get_port_module_page(struct net_device *netdev,
  952. const struct ethtool_module_eeprom *req,
  953. struct netlink_ext_ack *extack)
  954. {
  955. union {
  956. struct fun_admin_port_req req;
  957. struct fun_admin_port_xcvr_read_rsp rsp;
  958. } cmd;
  959. struct funeth_priv *fp = netdev_priv(netdev);
  960. int rc;
  961. if (fp->port_caps & FUN_PORT_CAP_VPORT) {
  962. NL_SET_ERR_MSG_MOD(extack,
  963. "Specified port is virtual, only physical ports have modules");
  964. return -EOPNOTSUPP;
  965. }
  966. cmd.req.common = FUN_ADMIN_REQ_COMMON_INIT2(FUN_ADMIN_OP_PORT,
  967. sizeof(cmd.req));
  968. cmd.req.u.xcvr_read =
  969. FUN_ADMIN_PORT_XCVR_READ_REQ_INIT(0, netdev->dev_port,
  970. req->bank, req->page,
  971. req->offset, req->length,
  972. req->i2c_address);
  973. rc = fun_submit_admin_sync_cmd(fp->fdev, &cmd.req.common, &cmd.rsp,
  974. sizeof(cmd.rsp), 0);
  975. if (rc)
  976. return rc;
  977. memcpy(req->data, cmd.rsp.data, req->length);
  978. return req->length;
  979. }
  980. static const struct ethtool_ops fun_ethtool_ops = {
  981. .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
  982. ETHTOOL_COALESCE_MAX_FRAMES,
  983. .get_link_ksettings = fun_get_link_ksettings,
  984. .set_link_ksettings = fun_set_link_ksettings,
  985. .set_phys_id = fun_set_phys_id,
  986. .get_drvinfo = fun_get_drvinfo,
  987. .get_msglevel = fun_get_msglevel,
  988. .set_msglevel = fun_set_msglevel,
  989. .get_regs_len = fun_get_regs_len,
  990. .get_regs = fun_get_regs,
  991. .get_link = ethtool_op_get_link,
  992. .get_coalesce = fun_get_coalesce,
  993. .set_coalesce = fun_set_coalesce,
  994. .get_ts_info = fun_get_ts_info,
  995. .get_ringparam = fun_get_ringparam,
  996. .set_ringparam = fun_set_ringparam,
  997. .get_sset_count = fun_get_sset_count,
  998. .get_strings = fun_get_strings,
  999. .get_ethtool_stats = fun_get_ethtool_stats,
  1000. .get_rxnfc = fun_get_rxnfc,
  1001. .set_rxnfc = fun_set_rxnfc,
  1002. .get_rxfh_indir_size = fun_get_rxfh_indir_size,
  1003. .get_rxfh_key_size = fun_get_rxfh_key_size,
  1004. .get_rxfh = fun_get_rxfh,
  1005. .set_rxfh = fun_set_rxfh,
  1006. .get_channels = fun_get_channels,
  1007. .set_channels = fun_set_channels,
  1008. .get_fecparam = fun_get_fecparam,
  1009. .set_fecparam = fun_set_fecparam,
  1010. .get_pauseparam = fun_get_pauseparam,
  1011. .set_pauseparam = fun_set_pauseparam,
  1012. .nway_reset = fun_restart_an,
  1013. .get_pause_stats = fun_get_pause_stats,
  1014. .get_fec_stats = fun_get_fec_stats,
  1015. .get_eth_mac_stats = fun_get_802_3_stats,
  1016. .get_eth_ctrl_stats = fun_get_802_3_ctrl_stats,
  1017. .get_rmon_stats = fun_get_rmon_stats,
  1018. .get_module_eeprom_by_page = fun_get_port_module_page,
  1019. };
  1020. void fun_set_ethtool_ops(struct net_device *netdev)
  1021. {
  1022. netdev->ethtool_ops = &fun_ethtool_ops;
  1023. }