nicvf_ethtool.c 22 KB

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