nicvf_ethtool.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  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_CMP_QUEUE_LEN;
  404. ring->rx_pending = qs->cq_len;
  405. ring->tx_max_pending = MAX_SND_QUEUE_LEN;
  406. ring->tx_pending = qs->sq_len;
  407. }
  408. static int nicvf_set_ringparam(struct net_device *netdev,
  409. struct ethtool_ringparam *ring)
  410. {
  411. struct nicvf *nic = netdev_priv(netdev);
  412. struct queue_set *qs = nic->qs;
  413. u32 rx_count, tx_count;
  414. /* Due to HW errata this is not supported on T88 pass 1.x silicon */
  415. if (pass1_silicon(nic->pdev))
  416. return -EINVAL;
  417. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  418. return -EINVAL;
  419. tx_count = clamp_t(u32, ring->tx_pending,
  420. MIN_SND_QUEUE_LEN, MAX_SND_QUEUE_LEN);
  421. rx_count = clamp_t(u32, ring->rx_pending,
  422. MIN_CMP_QUEUE_LEN, MAX_CMP_QUEUE_LEN);
  423. if ((tx_count == qs->sq_len) && (rx_count == qs->cq_len))
  424. return 0;
  425. /* Permitted lengths are 1K, 2K, 4K, 8K, 16K, 32K, 64K */
  426. qs->sq_len = rounddown_pow_of_two(tx_count);
  427. qs->cq_len = rounddown_pow_of_two(rx_count);
  428. if (netif_running(netdev)) {
  429. nicvf_stop(netdev);
  430. nicvf_open(netdev);
  431. }
  432. return 0;
  433. }
  434. static int nicvf_get_rss_hash_opts(struct nicvf *nic,
  435. struct ethtool_rxnfc *info)
  436. {
  437. info->data = 0;
  438. switch (info->flow_type) {
  439. case TCP_V4_FLOW:
  440. case TCP_V6_FLOW:
  441. case UDP_V4_FLOW:
  442. case UDP_V6_FLOW:
  443. case SCTP_V4_FLOW:
  444. case SCTP_V6_FLOW:
  445. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  446. case IPV4_FLOW:
  447. case IPV6_FLOW:
  448. info->data |= RXH_IP_SRC | RXH_IP_DST;
  449. break;
  450. default:
  451. return -EINVAL;
  452. }
  453. return 0;
  454. }
  455. static int nicvf_get_rxnfc(struct net_device *dev,
  456. struct ethtool_rxnfc *info, u32 *rules)
  457. {
  458. struct nicvf *nic = netdev_priv(dev);
  459. int ret = -EOPNOTSUPP;
  460. switch (info->cmd) {
  461. case ETHTOOL_GRXRINGS:
  462. info->data = nic->rx_queues;
  463. ret = 0;
  464. break;
  465. case ETHTOOL_GRXFH:
  466. return nicvf_get_rss_hash_opts(nic, info);
  467. default:
  468. break;
  469. }
  470. return ret;
  471. }
  472. static int nicvf_set_rss_hash_opts(struct nicvf *nic,
  473. struct ethtool_rxnfc *info)
  474. {
  475. struct nicvf_rss_info *rss = &nic->rss_info;
  476. u64 rss_cfg = nicvf_reg_read(nic, NIC_VNIC_RSS_CFG);
  477. if (!rss->enable)
  478. netdev_err(nic->netdev,
  479. "RSS is disabled, hash cannot be set\n");
  480. netdev_info(nic->netdev, "Set RSS flow type = %d, data = %lld\n",
  481. info->flow_type, info->data);
  482. if (!(info->data & RXH_IP_SRC) || !(info->data & RXH_IP_DST))
  483. return -EINVAL;
  484. switch (info->flow_type) {
  485. case TCP_V4_FLOW:
  486. case TCP_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_TCP);
  490. break;
  491. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  492. rss_cfg |= (1ULL << RSS_HASH_TCP);
  493. break;
  494. default:
  495. return -EINVAL;
  496. }
  497. break;
  498. case UDP_V4_FLOW:
  499. case UDP_V6_FLOW:
  500. switch (info->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  501. case 0:
  502. rss_cfg &= ~(1ULL << RSS_HASH_UDP);
  503. break;
  504. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  505. rss_cfg |= (1ULL << RSS_HASH_UDP);
  506. break;
  507. default:
  508. return -EINVAL;
  509. }
  510. break;
  511. case SCTP_V4_FLOW:
  512. case SCTP_V6_FLOW:
  513. switch (info->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  514. case 0:
  515. rss_cfg &= ~(1ULL << RSS_HASH_L4ETC);
  516. break;
  517. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  518. rss_cfg |= (1ULL << RSS_HASH_L4ETC);
  519. break;
  520. default:
  521. return -EINVAL;
  522. }
  523. break;
  524. case IPV4_FLOW:
  525. case IPV6_FLOW:
  526. rss_cfg = RSS_HASH_IP;
  527. break;
  528. default:
  529. return -EINVAL;
  530. }
  531. nicvf_reg_write(nic, NIC_VNIC_RSS_CFG, rss_cfg);
  532. return 0;
  533. }
  534. static int nicvf_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
  535. {
  536. struct nicvf *nic = netdev_priv(dev);
  537. switch (info->cmd) {
  538. case ETHTOOL_SRXFH:
  539. return nicvf_set_rss_hash_opts(nic, info);
  540. default:
  541. break;
  542. }
  543. return -EOPNOTSUPP;
  544. }
  545. static u32 nicvf_get_rxfh_key_size(struct net_device *netdev)
  546. {
  547. return RSS_HASH_KEY_SIZE * sizeof(u64);
  548. }
  549. static u32 nicvf_get_rxfh_indir_size(struct net_device *dev)
  550. {
  551. struct nicvf *nic = netdev_priv(dev);
  552. return nic->rss_info.rss_size;
  553. }
  554. static int nicvf_get_rxfh(struct net_device *dev, u32 *indir, u8 *hkey,
  555. u8 *hfunc)
  556. {
  557. struct nicvf *nic = netdev_priv(dev);
  558. struct nicvf_rss_info *rss = &nic->rss_info;
  559. int idx;
  560. if (indir) {
  561. for (idx = 0; idx < rss->rss_size; idx++)
  562. indir[idx] = rss->ind_tbl[idx];
  563. }
  564. if (hkey)
  565. memcpy(hkey, rss->key, RSS_HASH_KEY_SIZE * sizeof(u64));
  566. if (hfunc)
  567. *hfunc = ETH_RSS_HASH_TOP;
  568. return 0;
  569. }
  570. static int nicvf_set_rxfh(struct net_device *dev, const u32 *indir,
  571. const u8 *hkey, const u8 hfunc)
  572. {
  573. struct nicvf *nic = netdev_priv(dev);
  574. struct nicvf_rss_info *rss = &nic->rss_info;
  575. int idx;
  576. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
  577. return -EOPNOTSUPP;
  578. if (!rss->enable) {
  579. netdev_err(nic->netdev,
  580. "RSS is disabled, cannot change settings\n");
  581. return -EIO;
  582. }
  583. if (indir) {
  584. for (idx = 0; idx < rss->rss_size; idx++)
  585. rss->ind_tbl[idx] = indir[idx];
  586. }
  587. if (hkey) {
  588. memcpy(rss->key, hkey, RSS_HASH_KEY_SIZE * sizeof(u64));
  589. nicvf_set_rss_key(nic);
  590. }
  591. nicvf_config_rss(nic);
  592. return 0;
  593. }
  594. /* Get no of queues device supports and current queue count */
  595. static void nicvf_get_channels(struct net_device *dev,
  596. struct ethtool_channels *channel)
  597. {
  598. struct nicvf *nic = netdev_priv(dev);
  599. memset(channel, 0, sizeof(*channel));
  600. channel->max_rx = nic->max_queues;
  601. channel->max_tx = nic->max_queues;
  602. channel->rx_count = nic->rx_queues;
  603. channel->tx_count = nic->tx_queues;
  604. }
  605. /* Set no of Tx, Rx queues to be used */
  606. static int nicvf_set_channels(struct net_device *dev,
  607. struct ethtool_channels *channel)
  608. {
  609. struct nicvf *nic = netdev_priv(dev);
  610. int err = 0;
  611. bool if_up = netif_running(dev);
  612. int cqcount;
  613. if (!channel->rx_count || !channel->tx_count)
  614. return -EINVAL;
  615. if (channel->rx_count > nic->max_queues)
  616. return -EINVAL;
  617. if (channel->tx_count > nic->max_queues)
  618. return -EINVAL;
  619. if (if_up)
  620. nicvf_stop(dev);
  621. cqcount = max(channel->rx_count, channel->tx_count);
  622. if (cqcount > MAX_CMP_QUEUES_PER_QS) {
  623. nic->sqs_count = roundup(cqcount, MAX_CMP_QUEUES_PER_QS);
  624. nic->sqs_count = (nic->sqs_count / MAX_CMP_QUEUES_PER_QS) - 1;
  625. } else {
  626. nic->sqs_count = 0;
  627. }
  628. nic->qs->rq_cnt = min_t(u32, channel->rx_count, MAX_RCV_QUEUES_PER_QS);
  629. nic->qs->sq_cnt = min_t(u32, channel->tx_count, MAX_SND_QUEUES_PER_QS);
  630. nic->qs->cq_cnt = max(nic->qs->rq_cnt, nic->qs->sq_cnt);
  631. nic->rx_queues = channel->rx_count;
  632. nic->tx_queues = channel->tx_count;
  633. err = nicvf_set_real_num_queues(dev, nic->tx_queues, nic->rx_queues);
  634. if (err)
  635. return err;
  636. if (if_up)
  637. nicvf_open(dev);
  638. netdev_info(dev, "Setting num Tx rings to %d, Rx rings to %d success\n",
  639. nic->tx_queues, nic->rx_queues);
  640. return err;
  641. }
  642. static void nicvf_get_pauseparam(struct net_device *dev,
  643. struct ethtool_pauseparam *pause)
  644. {
  645. struct nicvf *nic = netdev_priv(dev);
  646. union nic_mbx mbx = {};
  647. /* Supported only for 10G/40G interfaces */
  648. if ((nic->mac_type == BGX_MODE_SGMII) ||
  649. (nic->mac_type == BGX_MODE_QSGMII) ||
  650. (nic->mac_type == BGX_MODE_RGMII))
  651. return;
  652. mbx.pfc.msg = NIC_MBOX_MSG_PFC;
  653. mbx.pfc.get = 1;
  654. if (!nicvf_send_msg_to_pf(nic, &mbx)) {
  655. pause->autoneg = nic->pfc.autoneg;
  656. pause->rx_pause = nic->pfc.fc_rx;
  657. pause->tx_pause = nic->pfc.fc_tx;
  658. }
  659. }
  660. static int nicvf_set_pauseparam(struct net_device *dev,
  661. struct ethtool_pauseparam *pause)
  662. {
  663. struct nicvf *nic = netdev_priv(dev);
  664. union nic_mbx mbx = {};
  665. /* Supported only for 10G/40G interfaces */
  666. if ((nic->mac_type == BGX_MODE_SGMII) ||
  667. (nic->mac_type == BGX_MODE_QSGMII) ||
  668. (nic->mac_type == BGX_MODE_RGMII))
  669. return -EOPNOTSUPP;
  670. if (pause->autoneg)
  671. return -EOPNOTSUPP;
  672. mbx.pfc.msg = NIC_MBOX_MSG_PFC;
  673. mbx.pfc.get = 0;
  674. mbx.pfc.fc_rx = pause->rx_pause;
  675. mbx.pfc.fc_tx = pause->tx_pause;
  676. if (nicvf_send_msg_to_pf(nic, &mbx))
  677. return -EAGAIN;
  678. nic->pfc.fc_rx = pause->rx_pause;
  679. nic->pfc.fc_tx = pause->tx_pause;
  680. return 0;
  681. }
  682. static const struct ethtool_ops nicvf_ethtool_ops = {
  683. .get_link = nicvf_get_link,
  684. .get_drvinfo = nicvf_get_drvinfo,
  685. .get_msglevel = nicvf_get_msglevel,
  686. .set_msglevel = nicvf_set_msglevel,
  687. .get_strings = nicvf_get_strings,
  688. .get_sset_count = nicvf_get_sset_count,
  689. .get_ethtool_stats = nicvf_get_ethtool_stats,
  690. .get_regs_len = nicvf_get_regs_len,
  691. .get_regs = nicvf_get_regs,
  692. .get_coalesce = nicvf_get_coalesce,
  693. .get_ringparam = nicvf_get_ringparam,
  694. .set_ringparam = nicvf_set_ringparam,
  695. .get_rxnfc = nicvf_get_rxnfc,
  696. .set_rxnfc = nicvf_set_rxnfc,
  697. .get_rxfh_key_size = nicvf_get_rxfh_key_size,
  698. .get_rxfh_indir_size = nicvf_get_rxfh_indir_size,
  699. .get_rxfh = nicvf_get_rxfh,
  700. .set_rxfh = nicvf_set_rxfh,
  701. .get_channels = nicvf_get_channels,
  702. .set_channels = nicvf_set_channels,
  703. .get_pauseparam = nicvf_get_pauseparam,
  704. .set_pauseparam = nicvf_set_pauseparam,
  705. .get_ts_info = ethtool_op_get_ts_info,
  706. .get_link_ksettings = nicvf_get_link_ksettings,
  707. };
  708. void nicvf_set_ethtool_ops(struct net_device *netdev)
  709. {
  710. netdev->ethtool_ops = &nicvf_ethtool_ops;
  711. }