nicvf_ethtool.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2015 Cavium, Inc.
  4. */
  5. /* ETHTOOL Support for VNIC_VF Device*/
  6. #include <linux/ethtool.h>
  7. #include <linux/pci.h>
  8. #include <linux/net_tstamp.h>
  9. #include "nic_reg.h"
  10. #include "nic.h"
  11. #include "nicvf_queues.h"
  12. #include "q_struct.h"
  13. #include "thunder_bgx.h"
  14. #include "../common/cavium_ptp.h"
  15. #define DRV_NAME "nicvf"
  16. struct nicvf_stat {
  17. char name[ETH_GSTRING_LEN];
  18. unsigned int index;
  19. };
  20. #define NICVF_HW_STAT(stat) { \
  21. .name = #stat, \
  22. .index = offsetof(struct nicvf_hw_stats, stat) / sizeof(u64), \
  23. }
  24. #define NICVF_DRV_STAT(stat) { \
  25. .name = #stat, \
  26. .index = offsetof(struct nicvf_drv_stats, stat) / sizeof(u64), \
  27. }
  28. static const struct nicvf_stat nicvf_hw_stats[] = {
  29. NICVF_HW_STAT(rx_bytes),
  30. NICVF_HW_STAT(rx_frames),
  31. NICVF_HW_STAT(rx_ucast_frames),
  32. NICVF_HW_STAT(rx_bcast_frames),
  33. NICVF_HW_STAT(rx_mcast_frames),
  34. NICVF_HW_STAT(rx_drops),
  35. NICVF_HW_STAT(rx_drop_red),
  36. NICVF_HW_STAT(rx_drop_red_bytes),
  37. NICVF_HW_STAT(rx_drop_overrun),
  38. NICVF_HW_STAT(rx_drop_overrun_bytes),
  39. NICVF_HW_STAT(rx_drop_bcast),
  40. NICVF_HW_STAT(rx_drop_mcast),
  41. NICVF_HW_STAT(rx_drop_l3_bcast),
  42. NICVF_HW_STAT(rx_drop_l3_mcast),
  43. NICVF_HW_STAT(rx_fcs_errors),
  44. NICVF_HW_STAT(rx_l2_errors),
  45. NICVF_HW_STAT(tx_bytes),
  46. NICVF_HW_STAT(tx_frames),
  47. NICVF_HW_STAT(tx_ucast_frames),
  48. NICVF_HW_STAT(tx_bcast_frames),
  49. NICVF_HW_STAT(tx_mcast_frames),
  50. NICVF_HW_STAT(tx_drops),
  51. };
  52. static const struct nicvf_stat nicvf_drv_stats[] = {
  53. NICVF_DRV_STAT(rx_bgx_truncated_pkts),
  54. NICVF_DRV_STAT(rx_jabber_errs),
  55. NICVF_DRV_STAT(rx_fcs_errs),
  56. NICVF_DRV_STAT(rx_bgx_errs),
  57. NICVF_DRV_STAT(rx_prel2_errs),
  58. NICVF_DRV_STAT(rx_l2_hdr_malformed),
  59. NICVF_DRV_STAT(rx_oversize),
  60. NICVF_DRV_STAT(rx_undersize),
  61. NICVF_DRV_STAT(rx_l2_len_mismatch),
  62. NICVF_DRV_STAT(rx_l2_pclp),
  63. NICVF_DRV_STAT(rx_ip_ver_errs),
  64. NICVF_DRV_STAT(rx_ip_csum_errs),
  65. NICVF_DRV_STAT(rx_ip_hdr_malformed),
  66. NICVF_DRV_STAT(rx_ip_payload_malformed),
  67. NICVF_DRV_STAT(rx_ip_ttl_errs),
  68. NICVF_DRV_STAT(rx_l3_pclp),
  69. NICVF_DRV_STAT(rx_l4_malformed),
  70. NICVF_DRV_STAT(rx_l4_csum_errs),
  71. NICVF_DRV_STAT(rx_udp_len_errs),
  72. NICVF_DRV_STAT(rx_l4_port_errs),
  73. NICVF_DRV_STAT(rx_tcp_flag_errs),
  74. NICVF_DRV_STAT(rx_tcp_offset_errs),
  75. NICVF_DRV_STAT(rx_l4_pclp),
  76. NICVF_DRV_STAT(rx_truncated_pkts),
  77. NICVF_DRV_STAT(tx_desc_fault),
  78. NICVF_DRV_STAT(tx_hdr_cons_err),
  79. NICVF_DRV_STAT(tx_subdesc_err),
  80. NICVF_DRV_STAT(tx_max_size_exceeded),
  81. NICVF_DRV_STAT(tx_imm_size_oflow),
  82. NICVF_DRV_STAT(tx_data_seq_err),
  83. NICVF_DRV_STAT(tx_mem_seq_err),
  84. NICVF_DRV_STAT(tx_lock_viol),
  85. NICVF_DRV_STAT(tx_data_fault),
  86. NICVF_DRV_STAT(tx_tstmp_conflict),
  87. NICVF_DRV_STAT(tx_tstmp_timeout),
  88. NICVF_DRV_STAT(tx_mem_fault),
  89. NICVF_DRV_STAT(tx_csum_overlap),
  90. NICVF_DRV_STAT(tx_csum_overflow),
  91. NICVF_DRV_STAT(tx_tso),
  92. NICVF_DRV_STAT(tx_timeout),
  93. NICVF_DRV_STAT(txq_stop),
  94. NICVF_DRV_STAT(txq_wake),
  95. NICVF_DRV_STAT(rcv_buffer_alloc_failures),
  96. NICVF_DRV_STAT(page_alloc),
  97. };
  98. static const struct nicvf_stat nicvf_queue_stats[] = {
  99. { "bytes", 0 },
  100. { "frames", 1 },
  101. };
  102. static const unsigned int nicvf_n_hw_stats = ARRAY_SIZE(nicvf_hw_stats);
  103. static const unsigned int nicvf_n_drv_stats = ARRAY_SIZE(nicvf_drv_stats);
  104. static const unsigned int nicvf_n_queue_stats = ARRAY_SIZE(nicvf_queue_stats);
  105. static int nicvf_get_link_ksettings(struct net_device *netdev,
  106. struct ethtool_link_ksettings *cmd)
  107. {
  108. struct nicvf *nic = netdev_priv(netdev);
  109. u32 supported, advertising;
  110. supported = 0;
  111. advertising = 0;
  112. if (!nic->link_up) {
  113. cmd->base.duplex = DUPLEX_UNKNOWN;
  114. cmd->base.speed = SPEED_UNKNOWN;
  115. return 0;
  116. }
  117. switch (nic->speed) {
  118. case SPEED_1000:
  119. cmd->base.port = PORT_MII | PORT_TP;
  120. cmd->base.autoneg = AUTONEG_ENABLE;
  121. supported |= SUPPORTED_MII | SUPPORTED_TP;
  122. supported |= SUPPORTED_1000baseT_Full |
  123. SUPPORTED_1000baseT_Half |
  124. SUPPORTED_100baseT_Full |
  125. SUPPORTED_100baseT_Half |
  126. SUPPORTED_10baseT_Full |
  127. SUPPORTED_10baseT_Half;
  128. supported |= SUPPORTED_Autoneg;
  129. advertising |= ADVERTISED_1000baseT_Full |
  130. ADVERTISED_1000baseT_Half |
  131. ADVERTISED_100baseT_Full |
  132. ADVERTISED_100baseT_Half |
  133. ADVERTISED_10baseT_Full |
  134. ADVERTISED_10baseT_Half;
  135. break;
  136. case SPEED_10000:
  137. if (nic->mac_type == BGX_MODE_RXAUI) {
  138. cmd->base.port = PORT_TP;
  139. supported |= SUPPORTED_TP;
  140. } else {
  141. cmd->base.port = PORT_FIBRE;
  142. supported |= SUPPORTED_FIBRE;
  143. }
  144. cmd->base.autoneg = AUTONEG_DISABLE;
  145. supported |= SUPPORTED_10000baseT_Full;
  146. break;
  147. case SPEED_40000:
  148. cmd->base.port = PORT_FIBRE;
  149. cmd->base.autoneg = AUTONEG_DISABLE;
  150. supported |= SUPPORTED_FIBRE;
  151. supported |= SUPPORTED_40000baseCR4_Full;
  152. break;
  153. }
  154. cmd->base.duplex = nic->duplex;
  155. cmd->base.speed = nic->speed;
  156. ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
  157. supported);
  158. ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
  159. advertising);
  160. return 0;
  161. }
  162. static u32 nicvf_get_link(struct net_device *netdev)
  163. {
  164. struct nicvf *nic = netdev_priv(netdev);
  165. return nic->link_up;
  166. }
  167. static void nicvf_get_drvinfo(struct net_device *netdev,
  168. struct ethtool_drvinfo *info)
  169. {
  170. struct nicvf *nic = netdev_priv(netdev);
  171. strscpy(info->driver, DRV_NAME, sizeof(info->driver));
  172. strscpy(info->bus_info, pci_name(nic->pdev), sizeof(info->bus_info));
  173. }
  174. static u32 nicvf_get_msglevel(struct net_device *netdev)
  175. {
  176. struct nicvf *nic = netdev_priv(netdev);
  177. return nic->msg_enable;
  178. }
  179. static void nicvf_set_msglevel(struct net_device *netdev, u32 lvl)
  180. {
  181. struct nicvf *nic = netdev_priv(netdev);
  182. nic->msg_enable = lvl;
  183. }
  184. static void nicvf_get_qset_strings(struct nicvf *nic, u8 **data, int qset)
  185. {
  186. int stats, qidx;
  187. int start_qidx = qset * MAX_RCV_QUEUES_PER_QS;
  188. for (qidx = 0; qidx < nic->qs->rq_cnt; qidx++) {
  189. for (stats = 0; stats < nicvf_n_queue_stats; stats++) {
  190. sprintf(*data, "rxq%d: %s", qidx + start_qidx,
  191. nicvf_queue_stats[stats].name);
  192. *data += ETH_GSTRING_LEN;
  193. }
  194. }
  195. for (qidx = 0; qidx < nic->qs->sq_cnt; qidx++) {
  196. for (stats = 0; stats < nicvf_n_queue_stats; stats++) {
  197. sprintf(*data, "txq%d: %s", qidx + start_qidx,
  198. nicvf_queue_stats[stats].name);
  199. *data += ETH_GSTRING_LEN;
  200. }
  201. }
  202. }
  203. static void nicvf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
  204. {
  205. struct nicvf *nic = netdev_priv(netdev);
  206. int stats;
  207. int sqs;
  208. if (sset != ETH_SS_STATS)
  209. return;
  210. for (stats = 0; stats < nicvf_n_hw_stats; stats++) {
  211. memcpy(data, nicvf_hw_stats[stats].name, ETH_GSTRING_LEN);
  212. data += ETH_GSTRING_LEN;
  213. }
  214. for (stats = 0; stats < nicvf_n_drv_stats; stats++) {
  215. memcpy(data, nicvf_drv_stats[stats].name, ETH_GSTRING_LEN);
  216. data += ETH_GSTRING_LEN;
  217. }
  218. nicvf_get_qset_strings(nic, &data, 0);
  219. for (sqs = 0; sqs < nic->sqs_count; sqs++) {
  220. if (!nic->snicvf[sqs])
  221. continue;
  222. nicvf_get_qset_strings(nic->snicvf[sqs], &data, sqs + 1);
  223. }
  224. for (stats = 0; stats < BGX_RX_STATS_COUNT; stats++) {
  225. sprintf(data, "bgx_rxstat%d: ", stats);
  226. data += ETH_GSTRING_LEN;
  227. }
  228. for (stats = 0; stats < BGX_TX_STATS_COUNT; stats++) {
  229. sprintf(data, "bgx_txstat%d: ", stats);
  230. data += ETH_GSTRING_LEN;
  231. }
  232. }
  233. static int nicvf_get_sset_count(struct net_device *netdev, int sset)
  234. {
  235. struct nicvf *nic = netdev_priv(netdev);
  236. int qstats_count;
  237. int sqs;
  238. if (sset != ETH_SS_STATS)
  239. return -EINVAL;
  240. qstats_count = nicvf_n_queue_stats *
  241. (nic->qs->rq_cnt + nic->qs->sq_cnt);
  242. for (sqs = 0; sqs < nic->sqs_count; sqs++) {
  243. struct nicvf *snic;
  244. snic = nic->snicvf[sqs];
  245. if (!snic)
  246. continue;
  247. qstats_count += nicvf_n_queue_stats *
  248. (snic->qs->rq_cnt + snic->qs->sq_cnt);
  249. }
  250. return nicvf_n_hw_stats + nicvf_n_drv_stats +
  251. qstats_count +
  252. BGX_RX_STATS_COUNT + BGX_TX_STATS_COUNT;
  253. }
  254. static void nicvf_get_qset_stats(struct nicvf *nic,
  255. struct ethtool_stats *stats, u64 **data)
  256. {
  257. int stat, qidx;
  258. if (!nic)
  259. return;
  260. for (qidx = 0; qidx < nic->qs->rq_cnt; qidx++) {
  261. nicvf_update_rq_stats(nic, qidx);
  262. for (stat = 0; stat < nicvf_n_queue_stats; stat++)
  263. *((*data)++) = ((u64 *)&nic->qs->rq[qidx].stats)
  264. [nicvf_queue_stats[stat].index];
  265. }
  266. for (qidx = 0; qidx < nic->qs->sq_cnt; qidx++) {
  267. nicvf_update_sq_stats(nic, qidx);
  268. for (stat = 0; stat < nicvf_n_queue_stats; stat++)
  269. *((*data)++) = ((u64 *)&nic->qs->sq[qidx].stats)
  270. [nicvf_queue_stats[stat].index];
  271. }
  272. }
  273. static void nicvf_get_ethtool_stats(struct net_device *netdev,
  274. struct ethtool_stats *stats, u64 *data)
  275. {
  276. struct nicvf *nic = netdev_priv(netdev);
  277. int stat, tmp_stats;
  278. int sqs, cpu;
  279. nicvf_update_stats(nic);
  280. /* Update LMAC stats */
  281. nicvf_update_lmac_stats(nic);
  282. for (stat = 0; stat < nicvf_n_hw_stats; stat++)
  283. *(data++) = ((u64 *)&nic->hw_stats)
  284. [nicvf_hw_stats[stat].index];
  285. for (stat = 0; stat < nicvf_n_drv_stats; stat++) {
  286. tmp_stats = 0;
  287. for_each_possible_cpu(cpu)
  288. tmp_stats += ((u64 *)per_cpu_ptr(nic->drv_stats, cpu))
  289. [nicvf_drv_stats[stat].index];
  290. *(data++) = tmp_stats;
  291. }
  292. nicvf_get_qset_stats(nic, stats, &data);
  293. for (sqs = 0; sqs < nic->sqs_count; sqs++) {
  294. if (!nic->snicvf[sqs])
  295. continue;
  296. nicvf_get_qset_stats(nic->snicvf[sqs], stats, &data);
  297. }
  298. for (stat = 0; stat < BGX_RX_STATS_COUNT; stat++)
  299. *(data++) = nic->bgx_stats.rx_stats[stat];
  300. for (stat = 0; stat < BGX_TX_STATS_COUNT; stat++)
  301. *(data++) = nic->bgx_stats.tx_stats[stat];
  302. }
  303. static int nicvf_get_regs_len(struct net_device *dev)
  304. {
  305. return sizeof(u64) * NIC_VF_REG_COUNT;
  306. }
  307. static void nicvf_get_regs(struct net_device *dev,
  308. struct ethtool_regs *regs, void *reg)
  309. {
  310. struct nicvf *nic = netdev_priv(dev);
  311. u64 *p = (u64 *)reg;
  312. u64 reg_offset;
  313. int mbox, key, stat, q;
  314. int i = 0;
  315. regs->version = 0;
  316. memset(p, 0, NIC_VF_REG_COUNT);
  317. p[i++] = nicvf_reg_read(nic, NIC_VNIC_CFG);
  318. /* Mailbox registers */
  319. for (mbox = 0; mbox < NIC_PF_VF_MAILBOX_SIZE; mbox++)
  320. p[i++] = nicvf_reg_read(nic,
  321. NIC_VF_PF_MAILBOX_0_1 | (mbox << 3));
  322. p[i++] = nicvf_reg_read(nic, NIC_VF_INT);
  323. p[i++] = nicvf_reg_read(nic, NIC_VF_INT_W1S);
  324. p[i++] = nicvf_reg_read(nic, NIC_VF_ENA_W1C);
  325. p[i++] = nicvf_reg_read(nic, NIC_VF_ENA_W1S);
  326. p[i++] = nicvf_reg_read(nic, NIC_VNIC_RSS_CFG);
  327. for (key = 0; key < RSS_HASH_KEY_SIZE; key++)
  328. p[i++] = nicvf_reg_read(nic, NIC_VNIC_RSS_KEY_0_4 | (key << 3));
  329. /* Tx/Rx statistics */
  330. for (stat = 0; stat < TX_STATS_ENUM_LAST; stat++)
  331. p[i++] = nicvf_reg_read(nic,
  332. NIC_VNIC_TX_STAT_0_4 | (stat << 3));
  333. for (i = 0; i < RX_STATS_ENUM_LAST; i++)
  334. p[i++] = nicvf_reg_read(nic,
  335. NIC_VNIC_RX_STAT_0_13 | (stat << 3));
  336. p[i++] = nicvf_reg_read(nic, NIC_QSET_RQ_GEN_CFG);
  337. /* All completion queue's registers */
  338. for (q = 0; q < MAX_CMP_QUEUES_PER_QS; q++) {
  339. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_CFG, q);
  340. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_CFG2, q);
  341. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_THRESH, q);
  342. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_BASE, q);
  343. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_HEAD, q);
  344. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_TAIL, q);
  345. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_DOOR, q);
  346. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_STATUS, q);
  347. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_STATUS2, q);
  348. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_DEBUG, q);
  349. }
  350. /* All receive queue's registers */
  351. for (q = 0; q < MAX_RCV_QUEUES_PER_QS; q++) {
  352. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RQ_0_7_CFG, q);
  353. p[i++] = nicvf_queue_reg_read(nic,
  354. NIC_QSET_RQ_0_7_STAT_0_1, q);
  355. reg_offset = NIC_QSET_RQ_0_7_STAT_0_1 | (1 << 3);
  356. p[i++] = nicvf_queue_reg_read(nic, reg_offset, q);
  357. }
  358. for (q = 0; q < MAX_SND_QUEUES_PER_QS; q++) {
  359. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_CFG, q);
  360. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_THRESH, q);
  361. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_BASE, q);
  362. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_HEAD, q);
  363. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_TAIL, q);
  364. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_DOOR, q);
  365. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_STATUS, q);
  366. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_DEBUG, q);
  367. /* Padding, was NIC_QSET_SQ_0_7_CNM_CHG, which
  368. * produces bus errors when read
  369. */
  370. p[i++] = 0;
  371. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_STAT_0_1, q);
  372. reg_offset = NIC_QSET_SQ_0_7_STAT_0_1 | (1 << 3);
  373. p[i++] = nicvf_queue_reg_read(nic, reg_offset, q);
  374. }
  375. for (q = 0; q < MAX_RCV_BUF_DESC_RINGS_PER_QS; q++) {
  376. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_CFG, q);
  377. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_THRESH, q);
  378. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_BASE, q);
  379. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_HEAD, q);
  380. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_TAIL, q);
  381. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_DOOR, q);
  382. p[i++] = nicvf_queue_reg_read(nic,
  383. NIC_QSET_RBDR_0_1_STATUS0, q);
  384. p[i++] = nicvf_queue_reg_read(nic,
  385. NIC_QSET_RBDR_0_1_STATUS1, q);
  386. reg_offset = NIC_QSET_RBDR_0_1_PREFETCH_STATUS;
  387. p[i++] = nicvf_queue_reg_read(nic, reg_offset, q);
  388. }
  389. }
  390. static int nicvf_get_coalesce(struct net_device *netdev,
  391. struct ethtool_coalesce *cmd,
  392. struct kernel_ethtool_coalesce *kernel_coal,
  393. struct netlink_ext_ack *extack)
  394. {
  395. struct nicvf *nic = netdev_priv(netdev);
  396. cmd->rx_coalesce_usecs = nic->cq_coalesce_usecs;
  397. return 0;
  398. }
  399. static void nicvf_get_ringparam(struct net_device *netdev,
  400. struct ethtool_ringparam *ring,
  401. struct kernel_ethtool_ringparam *kernel_ring,
  402. struct netlink_ext_ack *extack)
  403. {
  404. struct nicvf *nic = netdev_priv(netdev);
  405. struct queue_set *qs = nic->qs;
  406. ring->rx_max_pending = MAX_CMP_QUEUE_LEN;
  407. ring->rx_pending = qs->cq_len;
  408. ring->tx_max_pending = MAX_SND_QUEUE_LEN;
  409. ring->tx_pending = qs->sq_len;
  410. }
  411. static int nicvf_set_ringparam(struct net_device *netdev,
  412. struct ethtool_ringparam *ring,
  413. struct kernel_ethtool_ringparam *kernel_ring,
  414. struct netlink_ext_ack *extack)
  415. {
  416. struct nicvf *nic = netdev_priv(netdev);
  417. struct queue_set *qs = nic->qs;
  418. u32 rx_count, tx_count;
  419. /* Due to HW errata this is not supported on T88 pass 1.x silicon */
  420. if (pass1_silicon(nic->pdev))
  421. return -EINVAL;
  422. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  423. return -EINVAL;
  424. tx_count = clamp_t(u32, ring->tx_pending,
  425. MIN_SND_QUEUE_LEN, MAX_SND_QUEUE_LEN);
  426. rx_count = clamp_t(u32, ring->rx_pending,
  427. MIN_CMP_QUEUE_LEN, MAX_CMP_QUEUE_LEN);
  428. if ((tx_count == qs->sq_len) && (rx_count == qs->cq_len))
  429. return 0;
  430. /* Permitted lengths are 1K, 2K, 4K, 8K, 16K, 32K, 64K */
  431. qs->sq_len = rounddown_pow_of_two(tx_count);
  432. qs->cq_len = rounddown_pow_of_two(rx_count);
  433. if (netif_running(netdev)) {
  434. nicvf_stop(netdev);
  435. nicvf_open(netdev);
  436. }
  437. return 0;
  438. }
  439. static int nicvf_get_rxfh_fields(struct net_device *dev,
  440. struct ethtool_rxfh_fields *info)
  441. {
  442. info->data = 0;
  443. switch (info->flow_type) {
  444. case TCP_V4_FLOW:
  445. case TCP_V6_FLOW:
  446. case UDP_V4_FLOW:
  447. case UDP_V6_FLOW:
  448. case SCTP_V4_FLOW:
  449. case SCTP_V6_FLOW:
  450. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  451. fallthrough;
  452. case IPV4_FLOW:
  453. case IPV6_FLOW:
  454. info->data |= RXH_IP_SRC | RXH_IP_DST;
  455. break;
  456. default:
  457. return -EINVAL;
  458. }
  459. return 0;
  460. }
  461. static u32 nicvf_get_rx_ring_count(struct net_device *dev)
  462. {
  463. struct nicvf *nic = netdev_priv(dev);
  464. return nic->rx_queues;
  465. }
  466. static int nicvf_set_rxfh_fields(struct net_device *dev,
  467. const struct ethtool_rxfh_fields *info,
  468. struct netlink_ext_ack *extack)
  469. {
  470. struct nicvf *nic = netdev_priv(dev);
  471. struct nicvf_rss_info *rss;
  472. u64 rss_cfg;
  473. rss = &nic->rss_info;
  474. rss_cfg = nicvf_reg_read(nic, NIC_VNIC_RSS_CFG);
  475. if (!rss->enable)
  476. netdev_err(nic->netdev,
  477. "RSS is disabled, hash cannot be set\n");
  478. netdev_info(nic->netdev, "Set RSS flow type = %d, data = %u\n",
  479. info->flow_type, info->data);
  480. if (!(info->data & RXH_IP_SRC) || !(info->data & RXH_IP_DST))
  481. return -EINVAL;
  482. switch (info->flow_type) {
  483. case TCP_V4_FLOW:
  484. case TCP_V6_FLOW:
  485. switch (info->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  486. case 0:
  487. rss_cfg &= ~(1ULL << RSS_HASH_TCP);
  488. break;
  489. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  490. rss_cfg |= (1ULL << RSS_HASH_TCP);
  491. break;
  492. default:
  493. return -EINVAL;
  494. }
  495. break;
  496. case UDP_V4_FLOW:
  497. case UDP_V6_FLOW:
  498. switch (info->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  499. case 0:
  500. rss_cfg &= ~(1ULL << RSS_HASH_UDP);
  501. break;
  502. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  503. rss_cfg |= (1ULL << RSS_HASH_UDP);
  504. break;
  505. default:
  506. return -EINVAL;
  507. }
  508. break;
  509. case SCTP_V4_FLOW:
  510. case SCTP_V6_FLOW:
  511. switch (info->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  512. case 0:
  513. rss_cfg &= ~(1ULL << RSS_HASH_L4ETC);
  514. break;
  515. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  516. rss_cfg |= (1ULL << RSS_HASH_L4ETC);
  517. break;
  518. default:
  519. return -EINVAL;
  520. }
  521. break;
  522. case IPV4_FLOW:
  523. case IPV6_FLOW:
  524. rss_cfg = RSS_HASH_IP;
  525. break;
  526. default:
  527. return -EINVAL;
  528. }
  529. nicvf_reg_write(nic, NIC_VNIC_RSS_CFG, rss_cfg);
  530. return 0;
  531. }
  532. static u32 nicvf_get_rxfh_key_size(struct net_device *netdev)
  533. {
  534. return RSS_HASH_KEY_SIZE * sizeof(u64);
  535. }
  536. static u32 nicvf_get_rxfh_indir_size(struct net_device *dev)
  537. {
  538. struct nicvf *nic = netdev_priv(dev);
  539. return nic->rss_info.rss_size;
  540. }
  541. static int nicvf_get_rxfh(struct net_device *dev,
  542. struct ethtool_rxfh_param *rxfh)
  543. {
  544. struct nicvf *nic = netdev_priv(dev);
  545. struct nicvf_rss_info *rss = &nic->rss_info;
  546. int idx;
  547. if (rxfh->indir) {
  548. for (idx = 0; idx < rss->rss_size; idx++)
  549. rxfh->indir[idx] = rss->ind_tbl[idx];
  550. }
  551. if (rxfh->key)
  552. memcpy(rxfh->key, rss->key, RSS_HASH_KEY_SIZE * sizeof(u64));
  553. rxfh->hfunc = ETH_RSS_HASH_TOP;
  554. return 0;
  555. }
  556. static int nicvf_set_rxfh(struct net_device *dev,
  557. struct ethtool_rxfh_param *rxfh,
  558. struct netlink_ext_ack *extack)
  559. {
  560. struct nicvf *nic = netdev_priv(dev);
  561. struct nicvf_rss_info *rss = &nic->rss_info;
  562. int idx;
  563. if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE &&
  564. rxfh->hfunc != ETH_RSS_HASH_TOP)
  565. return -EOPNOTSUPP;
  566. if (!rss->enable) {
  567. netdev_err(nic->netdev,
  568. "RSS is disabled, cannot change settings\n");
  569. return -EIO;
  570. }
  571. if (rxfh->indir) {
  572. for (idx = 0; idx < rss->rss_size; idx++)
  573. rss->ind_tbl[idx] = rxfh->indir[idx];
  574. }
  575. if (rxfh->key) {
  576. memcpy(rss->key, rxfh->key, RSS_HASH_KEY_SIZE * sizeof(u64));
  577. nicvf_set_rss_key(nic);
  578. }
  579. nicvf_config_rss(nic);
  580. return 0;
  581. }
  582. /* Get no of queues device supports and current queue count */
  583. static void nicvf_get_channels(struct net_device *dev,
  584. struct ethtool_channels *channel)
  585. {
  586. struct nicvf *nic = netdev_priv(dev);
  587. memset(channel, 0, sizeof(*channel));
  588. channel->max_rx = nic->max_queues;
  589. channel->max_tx = nic->max_queues;
  590. channel->rx_count = nic->rx_queues;
  591. channel->tx_count = nic->tx_queues;
  592. }
  593. /* Set no of Tx, Rx queues to be used */
  594. static int nicvf_set_channels(struct net_device *dev,
  595. struct ethtool_channels *channel)
  596. {
  597. struct nicvf *nic = netdev_priv(dev);
  598. int err = 0;
  599. bool if_up = netif_running(dev);
  600. u8 cqcount, txq_count;
  601. if (!channel->rx_count || !channel->tx_count)
  602. return -EINVAL;
  603. if (channel->rx_count > nic->max_queues)
  604. return -EINVAL;
  605. if (channel->tx_count > nic->max_queues)
  606. return -EINVAL;
  607. if (channel->tx_count + channel->rx_count > nic->max_queues) {
  608. if (nic->xdp_prog) {
  609. netdev_err(nic->netdev,
  610. "XDP mode, RXQs + TXQs > Max %d\n",
  611. nic->max_queues);
  612. return -EINVAL;
  613. }
  614. xdp_clear_features_flag(nic->netdev);
  615. } else if (!pass1_silicon(nic->pdev)) {
  616. xdp_set_features_flag(dev, NETDEV_XDP_ACT_BASIC);
  617. }
  618. if (if_up)
  619. nicvf_stop(dev);
  620. nic->rx_queues = channel->rx_count;
  621. nic->tx_queues = channel->tx_count;
  622. if (!nic->xdp_prog)
  623. nic->xdp_tx_queues = 0;
  624. else
  625. nic->xdp_tx_queues = channel->rx_count;
  626. txq_count = nic->xdp_tx_queues + nic->tx_queues;
  627. cqcount = max(nic->rx_queues, txq_count);
  628. if (cqcount > MAX_CMP_QUEUES_PER_QS) {
  629. nic->sqs_count = roundup(cqcount, MAX_CMP_QUEUES_PER_QS);
  630. nic->sqs_count = (nic->sqs_count / MAX_CMP_QUEUES_PER_QS) - 1;
  631. } else {
  632. nic->sqs_count = 0;
  633. }
  634. nic->qs->rq_cnt = min_t(u8, nic->rx_queues, MAX_RCV_QUEUES_PER_QS);
  635. nic->qs->sq_cnt = min_t(u8, txq_count, MAX_SND_QUEUES_PER_QS);
  636. nic->qs->cq_cnt = max(nic->qs->rq_cnt, nic->qs->sq_cnt);
  637. err = nicvf_set_real_num_queues(dev, nic->tx_queues, nic->rx_queues);
  638. if (err)
  639. return err;
  640. if (if_up)
  641. nicvf_open(dev);
  642. netdev_info(dev, "Setting num Tx rings to %d, Rx rings to %d success\n",
  643. nic->tx_queues, nic->rx_queues);
  644. return err;
  645. }
  646. static void nicvf_get_pauseparam(struct net_device *dev,
  647. struct ethtool_pauseparam *pause)
  648. {
  649. struct nicvf *nic = netdev_priv(dev);
  650. union nic_mbx mbx = {};
  651. /* Supported only for 10G/40G interfaces */
  652. if ((nic->mac_type == BGX_MODE_SGMII) ||
  653. (nic->mac_type == BGX_MODE_QSGMII) ||
  654. (nic->mac_type == BGX_MODE_RGMII))
  655. return;
  656. mbx.pfc.msg = NIC_MBOX_MSG_PFC;
  657. mbx.pfc.get = 1;
  658. if (!nicvf_send_msg_to_pf(nic, &mbx)) {
  659. pause->autoneg = nic->pfc.autoneg;
  660. pause->rx_pause = nic->pfc.fc_rx;
  661. pause->tx_pause = nic->pfc.fc_tx;
  662. }
  663. }
  664. static int nicvf_set_pauseparam(struct net_device *dev,
  665. struct ethtool_pauseparam *pause)
  666. {
  667. struct nicvf *nic = netdev_priv(dev);
  668. union nic_mbx mbx = {};
  669. /* Supported only for 10G/40G interfaces */
  670. if ((nic->mac_type == BGX_MODE_SGMII) ||
  671. (nic->mac_type == BGX_MODE_QSGMII) ||
  672. (nic->mac_type == BGX_MODE_RGMII))
  673. return -EOPNOTSUPP;
  674. if (pause->autoneg)
  675. return -EOPNOTSUPP;
  676. mbx.pfc.msg = NIC_MBOX_MSG_PFC;
  677. mbx.pfc.get = 0;
  678. mbx.pfc.fc_rx = pause->rx_pause;
  679. mbx.pfc.fc_tx = pause->tx_pause;
  680. if (nicvf_send_msg_to_pf(nic, &mbx))
  681. return -EAGAIN;
  682. nic->pfc.fc_rx = pause->rx_pause;
  683. nic->pfc.fc_tx = pause->tx_pause;
  684. return 0;
  685. }
  686. static int nicvf_get_ts_info(struct net_device *netdev,
  687. struct kernel_ethtool_ts_info *info)
  688. {
  689. struct nicvf *nic = netdev_priv(netdev);
  690. if (!nic->ptp_clock)
  691. return ethtool_op_get_ts_info(netdev, info);
  692. info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  693. SOF_TIMESTAMPING_TX_HARDWARE |
  694. SOF_TIMESTAMPING_RX_HARDWARE |
  695. SOF_TIMESTAMPING_RAW_HARDWARE;
  696. info->phc_index = cavium_ptp_clock_index(nic->ptp_clock);
  697. info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
  698. info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
  699. (1 << HWTSTAMP_FILTER_ALL);
  700. return 0;
  701. }
  702. static const struct ethtool_ops nicvf_ethtool_ops = {
  703. .get_link = nicvf_get_link,
  704. .get_drvinfo = nicvf_get_drvinfo,
  705. .get_msglevel = nicvf_get_msglevel,
  706. .set_msglevel = nicvf_set_msglevel,
  707. .get_strings = nicvf_get_strings,
  708. .get_sset_count = nicvf_get_sset_count,
  709. .get_ethtool_stats = nicvf_get_ethtool_stats,
  710. .get_regs_len = nicvf_get_regs_len,
  711. .get_regs = nicvf_get_regs,
  712. .get_coalesce = nicvf_get_coalesce,
  713. .get_ringparam = nicvf_get_ringparam,
  714. .set_ringparam = nicvf_set_ringparam,
  715. .get_rx_ring_count = nicvf_get_rx_ring_count,
  716. .get_rxfh_key_size = nicvf_get_rxfh_key_size,
  717. .get_rxfh_indir_size = nicvf_get_rxfh_indir_size,
  718. .get_rxfh = nicvf_get_rxfh,
  719. .set_rxfh = nicvf_set_rxfh,
  720. .get_rxfh_fields = nicvf_get_rxfh_fields,
  721. .set_rxfh_fields = nicvf_set_rxfh_fields,
  722. .get_channels = nicvf_get_channels,
  723. .set_channels = nicvf_set_channels,
  724. .get_pauseparam = nicvf_get_pauseparam,
  725. .set_pauseparam = nicvf_set_pauseparam,
  726. .get_ts_info = nicvf_get_ts_info,
  727. .get_link_ksettings = nicvf_get_link_ksettings,
  728. };
  729. void nicvf_set_ethtool_ops(struct net_device *netdev)
  730. {
  731. netdev->ethtool_ops = &nicvf_ethtool_ops;
  732. }