nicvf_ethtool.c 23 KB

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