nicvf_ethtool.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  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(rcv_buffer_alloc_failures),
  93. NICVF_DRV_STAT(tx_tso),
  94. NICVF_DRV_STAT(tx_timeout),
  95. NICVF_DRV_STAT(txq_stop),
  96. NICVF_DRV_STAT(txq_wake),
  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. strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
  172. strlcpy(info->version, DRV_VERSION, sizeof(info->version));
  173. strlcpy(info->bus_info, pci_name(nic->pdev), sizeof(info->bus_info));
  174. }
  175. static u32 nicvf_get_msglevel(struct net_device *netdev)
  176. {
  177. struct nicvf *nic = netdev_priv(netdev);
  178. return nic->msg_enable;
  179. }
  180. static void nicvf_set_msglevel(struct net_device *netdev, u32 lvl)
  181. {
  182. struct nicvf *nic = netdev_priv(netdev);
  183. nic->msg_enable = lvl;
  184. }
  185. static void nicvf_get_qset_strings(struct nicvf *nic, u8 **data, int qset)
  186. {
  187. int stats, qidx;
  188. int start_qidx = qset * MAX_RCV_QUEUES_PER_QS;
  189. for (qidx = 0; qidx < nic->qs->rq_cnt; qidx++) {
  190. for (stats = 0; stats < nicvf_n_queue_stats; stats++) {
  191. sprintf(*data, "rxq%d: %s", qidx + start_qidx,
  192. nicvf_queue_stats[stats].name);
  193. *data += ETH_GSTRING_LEN;
  194. }
  195. }
  196. for (qidx = 0; qidx < nic->qs->sq_cnt; qidx++) {
  197. for (stats = 0; stats < nicvf_n_queue_stats; stats++) {
  198. sprintf(*data, "txq%d: %s", qidx + start_qidx,
  199. nicvf_queue_stats[stats].name);
  200. *data += ETH_GSTRING_LEN;
  201. }
  202. }
  203. }
  204. static void nicvf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
  205. {
  206. struct nicvf *nic = netdev_priv(netdev);
  207. int stats;
  208. int sqs;
  209. if (sset != ETH_SS_STATS)
  210. return;
  211. for (stats = 0; stats < nicvf_n_hw_stats; stats++) {
  212. memcpy(data, nicvf_hw_stats[stats].name, ETH_GSTRING_LEN);
  213. data += ETH_GSTRING_LEN;
  214. }
  215. for (stats = 0; stats < nicvf_n_drv_stats; stats++) {
  216. memcpy(data, nicvf_drv_stats[stats].name, ETH_GSTRING_LEN);
  217. data += ETH_GSTRING_LEN;
  218. }
  219. nicvf_get_qset_strings(nic, &data, 0);
  220. for (sqs = 0; sqs < nic->sqs_count; sqs++) {
  221. if (!nic->snicvf[sqs])
  222. continue;
  223. nicvf_get_qset_strings(nic->snicvf[sqs], &data, sqs + 1);
  224. }
  225. for (stats = 0; stats < BGX_RX_STATS_COUNT; stats++) {
  226. sprintf(data, "bgx_rxstat%d: ", stats);
  227. data += ETH_GSTRING_LEN;
  228. }
  229. for (stats = 0; stats < BGX_TX_STATS_COUNT; stats++) {
  230. sprintf(data, "bgx_txstat%d: ", stats);
  231. data += ETH_GSTRING_LEN;
  232. }
  233. }
  234. static int nicvf_get_sset_count(struct net_device *netdev, int sset)
  235. {
  236. struct nicvf *nic = netdev_priv(netdev);
  237. int qstats_count;
  238. int sqs;
  239. if (sset != ETH_SS_STATS)
  240. return -EINVAL;
  241. qstats_count = nicvf_n_queue_stats *
  242. (nic->qs->rq_cnt + nic->qs->sq_cnt);
  243. for (sqs = 0; sqs < nic->sqs_count; sqs++) {
  244. struct nicvf *snic;
  245. snic = nic->snicvf[sqs];
  246. if (!snic)
  247. continue;
  248. qstats_count += nicvf_n_queue_stats *
  249. (snic->qs->rq_cnt + snic->qs->sq_cnt);
  250. }
  251. return nicvf_n_hw_stats + nicvf_n_drv_stats +
  252. qstats_count +
  253. BGX_RX_STATS_COUNT + BGX_TX_STATS_COUNT;
  254. }
  255. static void nicvf_get_qset_stats(struct nicvf *nic,
  256. struct ethtool_stats *stats, u64 **data)
  257. {
  258. int stat, qidx;
  259. if (!nic)
  260. return;
  261. for (qidx = 0; qidx < nic->qs->rq_cnt; qidx++) {
  262. nicvf_update_rq_stats(nic, qidx);
  263. for (stat = 0; stat < nicvf_n_queue_stats; stat++)
  264. *((*data)++) = ((u64 *)&nic->qs->rq[qidx].stats)
  265. [nicvf_queue_stats[stat].index];
  266. }
  267. for (qidx = 0; qidx < nic->qs->sq_cnt; qidx++) {
  268. nicvf_update_sq_stats(nic, qidx);
  269. for (stat = 0; stat < nicvf_n_queue_stats; stat++)
  270. *((*data)++) = ((u64 *)&nic->qs->sq[qidx].stats)
  271. [nicvf_queue_stats[stat].index];
  272. }
  273. }
  274. static void nicvf_get_ethtool_stats(struct net_device *netdev,
  275. struct ethtool_stats *stats, u64 *data)
  276. {
  277. struct nicvf *nic = netdev_priv(netdev);
  278. int stat, tmp_stats;
  279. int sqs, cpu;
  280. nicvf_update_stats(nic);
  281. /* Update LMAC stats */
  282. nicvf_update_lmac_stats(nic);
  283. for (stat = 0; stat < nicvf_n_hw_stats; stat++)
  284. *(data++) = ((u64 *)&nic->hw_stats)
  285. [nicvf_hw_stats[stat].index];
  286. for (stat = 0; stat < nicvf_n_drv_stats; stat++) {
  287. tmp_stats = 0;
  288. for_each_possible_cpu(cpu)
  289. tmp_stats += ((u64 *)per_cpu_ptr(nic->drv_stats, cpu))
  290. [nicvf_drv_stats[stat].index];
  291. *(data++) = tmp_stats;
  292. }
  293. nicvf_get_qset_stats(nic, stats, &data);
  294. for (sqs = 0; sqs < nic->sqs_count; sqs++) {
  295. if (!nic->snicvf[sqs])
  296. continue;
  297. nicvf_get_qset_stats(nic->snicvf[sqs], stats, &data);
  298. }
  299. for (stat = 0; stat < BGX_RX_STATS_COUNT; stat++)
  300. *(data++) = nic->bgx_stats.rx_stats[stat];
  301. for (stat = 0; stat < BGX_TX_STATS_COUNT; stat++)
  302. *(data++) = nic->bgx_stats.tx_stats[stat];
  303. }
  304. static int nicvf_get_regs_len(struct net_device *dev)
  305. {
  306. return sizeof(u64) * NIC_VF_REG_COUNT;
  307. }
  308. static void nicvf_get_regs(struct net_device *dev,
  309. struct ethtool_regs *regs, void *reg)
  310. {
  311. struct nicvf *nic = netdev_priv(dev);
  312. u64 *p = (u64 *)reg;
  313. u64 reg_offset;
  314. int mbox, key, stat, q;
  315. int i = 0;
  316. regs->version = 0;
  317. memset(p, 0, NIC_VF_REG_COUNT);
  318. p[i++] = nicvf_reg_read(nic, NIC_VNIC_CFG);
  319. /* Mailbox registers */
  320. for (mbox = 0; mbox < NIC_PF_VF_MAILBOX_SIZE; mbox++)
  321. p[i++] = nicvf_reg_read(nic,
  322. NIC_VF_PF_MAILBOX_0_1 | (mbox << 3));
  323. p[i++] = nicvf_reg_read(nic, NIC_VF_INT);
  324. p[i++] = nicvf_reg_read(nic, NIC_VF_INT_W1S);
  325. p[i++] = nicvf_reg_read(nic, NIC_VF_ENA_W1C);
  326. p[i++] = nicvf_reg_read(nic, NIC_VF_ENA_W1S);
  327. p[i++] = nicvf_reg_read(nic, NIC_VNIC_RSS_CFG);
  328. for (key = 0; key < RSS_HASH_KEY_SIZE; key++)
  329. p[i++] = nicvf_reg_read(nic, NIC_VNIC_RSS_KEY_0_4 | (key << 3));
  330. /* Tx/Rx statistics */
  331. for (stat = 0; stat < TX_STATS_ENUM_LAST; stat++)
  332. p[i++] = nicvf_reg_read(nic,
  333. NIC_VNIC_TX_STAT_0_4 | (stat << 3));
  334. for (i = 0; i < RX_STATS_ENUM_LAST; i++)
  335. p[i++] = nicvf_reg_read(nic,
  336. NIC_VNIC_RX_STAT_0_13 | (stat << 3));
  337. p[i++] = nicvf_reg_read(nic, NIC_QSET_RQ_GEN_CFG);
  338. /* All completion queue's registers */
  339. for (q = 0; q < MAX_CMP_QUEUES_PER_QS; q++) {
  340. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_CFG, q);
  341. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_CFG2, q);
  342. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_THRESH, q);
  343. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_BASE, q);
  344. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_HEAD, q);
  345. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_TAIL, q);
  346. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_DOOR, q);
  347. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_STATUS, q);
  348. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_STATUS2, q);
  349. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_DEBUG, q);
  350. }
  351. /* All receive queue's registers */
  352. for (q = 0; q < MAX_RCV_QUEUES_PER_QS; q++) {
  353. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RQ_0_7_CFG, q);
  354. p[i++] = nicvf_queue_reg_read(nic,
  355. NIC_QSET_RQ_0_7_STAT_0_1, q);
  356. reg_offset = NIC_QSET_RQ_0_7_STAT_0_1 | (1 << 3);
  357. p[i++] = nicvf_queue_reg_read(nic, reg_offset, q);
  358. }
  359. for (q = 0; q < MAX_SND_QUEUES_PER_QS; q++) {
  360. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_CFG, q);
  361. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_THRESH, q);
  362. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_BASE, q);
  363. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_HEAD, q);
  364. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_TAIL, q);
  365. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_DOOR, q);
  366. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_STATUS, q);
  367. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_DEBUG, q);
  368. /* Padding, was NIC_QSET_SQ_0_7_CNM_CHG, which
  369. * produces bus errors when read
  370. */
  371. p[i++] = 0;
  372. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_STAT_0_1, q);
  373. reg_offset = NIC_QSET_SQ_0_7_STAT_0_1 | (1 << 3);
  374. p[i++] = nicvf_queue_reg_read(nic, reg_offset, q);
  375. }
  376. for (q = 0; q < MAX_RCV_BUF_DESC_RINGS_PER_QS; q++) {
  377. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_CFG, q);
  378. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_THRESH, q);
  379. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_BASE, q);
  380. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_HEAD, q);
  381. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_TAIL, q);
  382. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_DOOR, q);
  383. p[i++] = nicvf_queue_reg_read(nic,
  384. NIC_QSET_RBDR_0_1_STATUS0, q);
  385. p[i++] = nicvf_queue_reg_read(nic,
  386. NIC_QSET_RBDR_0_1_STATUS1, q);
  387. reg_offset = NIC_QSET_RBDR_0_1_PREFETCH_STATUS;
  388. p[i++] = nicvf_queue_reg_read(nic, reg_offset, q);
  389. }
  390. }
  391. static int nicvf_get_coalesce(struct net_device *netdev,
  392. struct ethtool_coalesce *cmd)
  393. {
  394. struct nicvf *nic = netdev_priv(netdev);
  395. cmd->rx_coalesce_usecs = nic->cq_coalesce_usecs;
  396. return 0;
  397. }
  398. static void nicvf_get_ringparam(struct net_device *netdev,
  399. struct ethtool_ringparam *ring)
  400. {
  401. struct nicvf *nic = netdev_priv(netdev);
  402. struct queue_set *qs = nic->qs;
  403. ring->rx_max_pending = MAX_RCV_BUF_COUNT;
  404. ring->rx_pending = qs->rbdr_len;
  405. ring->tx_max_pending = MAX_SND_QUEUE_LEN;
  406. ring->tx_pending = qs->sq_len;
  407. }
  408. static int nicvf_get_rss_hash_opts(struct nicvf *nic,
  409. struct ethtool_rxnfc *info)
  410. {
  411. info->data = 0;
  412. switch (info->flow_type) {
  413. case TCP_V4_FLOW:
  414. case TCP_V6_FLOW:
  415. case UDP_V4_FLOW:
  416. case UDP_V6_FLOW:
  417. case SCTP_V4_FLOW:
  418. case SCTP_V6_FLOW:
  419. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  420. case IPV4_FLOW:
  421. case IPV6_FLOW:
  422. info->data |= RXH_IP_SRC | RXH_IP_DST;
  423. break;
  424. default:
  425. return -EINVAL;
  426. }
  427. return 0;
  428. }
  429. static int nicvf_get_rxnfc(struct net_device *dev,
  430. struct ethtool_rxnfc *info, u32 *rules)
  431. {
  432. struct nicvf *nic = netdev_priv(dev);
  433. int ret = -EOPNOTSUPP;
  434. switch (info->cmd) {
  435. case ETHTOOL_GRXRINGS:
  436. info->data = nic->rx_queues;
  437. ret = 0;
  438. break;
  439. case ETHTOOL_GRXFH:
  440. return nicvf_get_rss_hash_opts(nic, info);
  441. default:
  442. break;
  443. }
  444. return ret;
  445. }
  446. static int nicvf_set_rss_hash_opts(struct nicvf *nic,
  447. struct ethtool_rxnfc *info)
  448. {
  449. struct nicvf_rss_info *rss = &nic->rss_info;
  450. u64 rss_cfg = nicvf_reg_read(nic, NIC_VNIC_RSS_CFG);
  451. if (!rss->enable)
  452. netdev_err(nic->netdev,
  453. "RSS is disabled, hash cannot be set\n");
  454. netdev_info(nic->netdev, "Set RSS flow type = %d, data = %lld\n",
  455. info->flow_type, info->data);
  456. if (!(info->data & RXH_IP_SRC) || !(info->data & RXH_IP_DST))
  457. return -EINVAL;
  458. switch (info->flow_type) {
  459. case TCP_V4_FLOW:
  460. case TCP_V6_FLOW:
  461. switch (info->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  462. case 0:
  463. rss_cfg &= ~(1ULL << RSS_HASH_TCP);
  464. break;
  465. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  466. rss_cfg |= (1ULL << RSS_HASH_TCP);
  467. break;
  468. default:
  469. return -EINVAL;
  470. }
  471. break;
  472. case UDP_V4_FLOW:
  473. case UDP_V6_FLOW:
  474. switch (info->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  475. case 0:
  476. rss_cfg &= ~(1ULL << RSS_HASH_UDP);
  477. break;
  478. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  479. rss_cfg |= (1ULL << RSS_HASH_UDP);
  480. break;
  481. default:
  482. return -EINVAL;
  483. }
  484. break;
  485. case SCTP_V4_FLOW:
  486. case SCTP_V6_FLOW:
  487. switch (info->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  488. case 0:
  489. rss_cfg &= ~(1ULL << RSS_HASH_L4ETC);
  490. break;
  491. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  492. rss_cfg |= (1ULL << RSS_HASH_L4ETC);
  493. break;
  494. default:
  495. return -EINVAL;
  496. }
  497. break;
  498. case IPV4_FLOW:
  499. case IPV6_FLOW:
  500. rss_cfg = RSS_HASH_IP;
  501. break;
  502. default:
  503. return -EINVAL;
  504. }
  505. nicvf_reg_write(nic, NIC_VNIC_RSS_CFG, rss_cfg);
  506. return 0;
  507. }
  508. static int nicvf_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
  509. {
  510. struct nicvf *nic = netdev_priv(dev);
  511. switch (info->cmd) {
  512. case ETHTOOL_SRXFH:
  513. return nicvf_set_rss_hash_opts(nic, info);
  514. default:
  515. break;
  516. }
  517. return -EOPNOTSUPP;
  518. }
  519. static u32 nicvf_get_rxfh_key_size(struct net_device *netdev)
  520. {
  521. return RSS_HASH_KEY_SIZE * sizeof(u64);
  522. }
  523. static u32 nicvf_get_rxfh_indir_size(struct net_device *dev)
  524. {
  525. struct nicvf *nic = netdev_priv(dev);
  526. return nic->rss_info.rss_size;
  527. }
  528. static int nicvf_get_rxfh(struct net_device *dev, u32 *indir, u8 *hkey,
  529. u8 *hfunc)
  530. {
  531. struct nicvf *nic = netdev_priv(dev);
  532. struct nicvf_rss_info *rss = &nic->rss_info;
  533. int idx;
  534. if (indir) {
  535. for (idx = 0; idx < rss->rss_size; idx++)
  536. indir[idx] = rss->ind_tbl[idx];
  537. }
  538. if (hkey)
  539. memcpy(hkey, rss->key, RSS_HASH_KEY_SIZE * sizeof(u64));
  540. if (hfunc)
  541. *hfunc = ETH_RSS_HASH_TOP;
  542. return 0;
  543. }
  544. static int nicvf_set_rxfh(struct net_device *dev, const u32 *indir,
  545. const u8 *hkey, u8 hfunc)
  546. {
  547. struct nicvf *nic = netdev_priv(dev);
  548. struct nicvf_rss_info *rss = &nic->rss_info;
  549. int idx;
  550. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
  551. return -EOPNOTSUPP;
  552. if (!rss->enable) {
  553. netdev_err(nic->netdev,
  554. "RSS is disabled, cannot change settings\n");
  555. return -EIO;
  556. }
  557. if (indir) {
  558. for (idx = 0; idx < rss->rss_size; idx++)
  559. rss->ind_tbl[idx] = indir[idx];
  560. }
  561. if (hkey) {
  562. memcpy(rss->key, hkey, RSS_HASH_KEY_SIZE * sizeof(u64));
  563. nicvf_set_rss_key(nic);
  564. }
  565. nicvf_config_rss(nic);
  566. return 0;
  567. }
  568. /* Get no of queues device supports and current queue count */
  569. static void nicvf_get_channels(struct net_device *dev,
  570. struct ethtool_channels *channel)
  571. {
  572. struct nicvf *nic = netdev_priv(dev);
  573. memset(channel, 0, sizeof(*channel));
  574. channel->max_rx = nic->max_queues;
  575. channel->max_tx = nic->max_queues;
  576. channel->rx_count = nic->rx_queues;
  577. channel->tx_count = nic->tx_queues;
  578. }
  579. /* Set no of Tx, Rx queues to be used */
  580. static int nicvf_set_channels(struct net_device *dev,
  581. struct ethtool_channels *channel)
  582. {
  583. struct nicvf *nic = netdev_priv(dev);
  584. int err = 0;
  585. bool if_up = netif_running(dev);
  586. int cqcount;
  587. if (!channel->rx_count || !channel->tx_count)
  588. return -EINVAL;
  589. if (channel->rx_count > nic->max_queues)
  590. return -EINVAL;
  591. if (channel->tx_count > nic->max_queues)
  592. return -EINVAL;
  593. if (if_up)
  594. nicvf_stop(dev);
  595. cqcount = max(channel->rx_count, channel->tx_count);
  596. if (cqcount > MAX_CMP_QUEUES_PER_QS) {
  597. nic->sqs_count = roundup(cqcount, MAX_CMP_QUEUES_PER_QS);
  598. nic->sqs_count = (nic->sqs_count / MAX_CMP_QUEUES_PER_QS) - 1;
  599. } else {
  600. nic->sqs_count = 0;
  601. }
  602. nic->qs->rq_cnt = min_t(u32, channel->rx_count, MAX_RCV_QUEUES_PER_QS);
  603. nic->qs->sq_cnt = min_t(u32, channel->tx_count, MAX_SND_QUEUES_PER_QS);
  604. nic->qs->cq_cnt = max(nic->qs->rq_cnt, nic->qs->sq_cnt);
  605. nic->rx_queues = channel->rx_count;
  606. nic->tx_queues = channel->tx_count;
  607. err = nicvf_set_real_num_queues(dev, nic->tx_queues, nic->rx_queues);
  608. if (err)
  609. return err;
  610. if (if_up)
  611. nicvf_open(dev);
  612. netdev_info(dev, "Setting num Tx rings to %d, Rx rings to %d success\n",
  613. nic->tx_queues, nic->rx_queues);
  614. return err;
  615. }
  616. static void nicvf_get_pauseparam(struct net_device *dev,
  617. struct ethtool_pauseparam *pause)
  618. {
  619. struct nicvf *nic = netdev_priv(dev);
  620. union nic_mbx mbx = {};
  621. /* Supported only for 10G/40G interfaces */
  622. if ((nic->mac_type == BGX_MODE_SGMII) ||
  623. (nic->mac_type == BGX_MODE_QSGMII) ||
  624. (nic->mac_type == BGX_MODE_RGMII))
  625. return;
  626. mbx.pfc.msg = NIC_MBOX_MSG_PFC;
  627. mbx.pfc.get = 1;
  628. if (!nicvf_send_msg_to_pf(nic, &mbx)) {
  629. pause->autoneg = nic->pfc.autoneg;
  630. pause->rx_pause = nic->pfc.fc_rx;
  631. pause->tx_pause = nic->pfc.fc_tx;
  632. }
  633. }
  634. static int nicvf_set_pauseparam(struct net_device *dev,
  635. struct ethtool_pauseparam *pause)
  636. {
  637. struct nicvf *nic = netdev_priv(dev);
  638. union nic_mbx mbx = {};
  639. /* Supported only for 10G/40G interfaces */
  640. if ((nic->mac_type == BGX_MODE_SGMII) ||
  641. (nic->mac_type == BGX_MODE_QSGMII) ||
  642. (nic->mac_type == BGX_MODE_RGMII))
  643. return -EOPNOTSUPP;
  644. if (pause->autoneg)
  645. return -EOPNOTSUPP;
  646. mbx.pfc.msg = NIC_MBOX_MSG_PFC;
  647. mbx.pfc.get = 0;
  648. mbx.pfc.fc_rx = pause->rx_pause;
  649. mbx.pfc.fc_tx = pause->tx_pause;
  650. if (nicvf_send_msg_to_pf(nic, &mbx))
  651. return -EAGAIN;
  652. nic->pfc.fc_rx = pause->rx_pause;
  653. nic->pfc.fc_tx = pause->tx_pause;
  654. return 0;
  655. }
  656. static const struct ethtool_ops nicvf_ethtool_ops = {
  657. .get_link = nicvf_get_link,
  658. .get_drvinfo = nicvf_get_drvinfo,
  659. .get_msglevel = nicvf_get_msglevel,
  660. .set_msglevel = nicvf_set_msglevel,
  661. .get_strings = nicvf_get_strings,
  662. .get_sset_count = nicvf_get_sset_count,
  663. .get_ethtool_stats = nicvf_get_ethtool_stats,
  664. .get_regs_len = nicvf_get_regs_len,
  665. .get_regs = nicvf_get_regs,
  666. .get_coalesce = nicvf_get_coalesce,
  667. .get_ringparam = nicvf_get_ringparam,
  668. .get_rxnfc = nicvf_get_rxnfc,
  669. .set_rxnfc = nicvf_set_rxnfc,
  670. .get_rxfh_key_size = nicvf_get_rxfh_key_size,
  671. .get_rxfh_indir_size = nicvf_get_rxfh_indir_size,
  672. .get_rxfh = nicvf_get_rxfh,
  673. .set_rxfh = nicvf_set_rxfh,
  674. .get_channels = nicvf_get_channels,
  675. .set_channels = nicvf_set_channels,
  676. .get_pauseparam = nicvf_get_pauseparam,
  677. .set_pauseparam = nicvf_set_pauseparam,
  678. .get_ts_info = ethtool_op_get_ts_info,
  679. .get_link_ksettings = nicvf_get_link_ksettings,
  680. };
  681. void nicvf_set_ethtool_ops(struct net_device *netdev)
  682. {
  683. netdev->ethtool_ops = &nicvf_ethtool_ops;
  684. }