nicvf_ethtool.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  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_settings(struct net_device *netdev,
  106. struct ethtool_cmd *cmd)
  107. {
  108. struct nicvf *nic = netdev_priv(netdev);
  109. cmd->supported = 0;
  110. cmd->transceiver = XCVR_EXTERNAL;
  111. if (!nic->link_up) {
  112. cmd->duplex = DUPLEX_UNKNOWN;
  113. ethtool_cmd_speed_set(cmd, SPEED_UNKNOWN);
  114. return 0;
  115. }
  116. if (nic->speed <= 1000) {
  117. cmd->port = PORT_MII;
  118. cmd->autoneg = AUTONEG_ENABLE;
  119. } else {
  120. cmd->port = PORT_FIBRE;
  121. cmd->autoneg = AUTONEG_DISABLE;
  122. }
  123. cmd->duplex = nic->duplex;
  124. ethtool_cmd_speed_set(cmd, nic->speed);
  125. return 0;
  126. }
  127. static u32 nicvf_get_link(struct net_device *netdev)
  128. {
  129. struct nicvf *nic = netdev_priv(netdev);
  130. return nic->link_up;
  131. }
  132. static void nicvf_get_drvinfo(struct net_device *netdev,
  133. struct ethtool_drvinfo *info)
  134. {
  135. struct nicvf *nic = netdev_priv(netdev);
  136. strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
  137. strlcpy(info->version, DRV_VERSION, sizeof(info->version));
  138. strlcpy(info->bus_info, pci_name(nic->pdev), sizeof(info->bus_info));
  139. }
  140. static u32 nicvf_get_msglevel(struct net_device *netdev)
  141. {
  142. struct nicvf *nic = netdev_priv(netdev);
  143. return nic->msg_enable;
  144. }
  145. static void nicvf_set_msglevel(struct net_device *netdev, u32 lvl)
  146. {
  147. struct nicvf *nic = netdev_priv(netdev);
  148. nic->msg_enable = lvl;
  149. }
  150. static void nicvf_get_qset_strings(struct nicvf *nic, u8 **data, int qset)
  151. {
  152. int stats, qidx;
  153. int start_qidx = qset * MAX_RCV_QUEUES_PER_QS;
  154. for (qidx = 0; qidx < nic->qs->rq_cnt; qidx++) {
  155. for (stats = 0; stats < nicvf_n_queue_stats; stats++) {
  156. sprintf(*data, "rxq%d: %s", qidx + start_qidx,
  157. nicvf_queue_stats[stats].name);
  158. *data += ETH_GSTRING_LEN;
  159. }
  160. }
  161. for (qidx = 0; qidx < nic->qs->sq_cnt; qidx++) {
  162. for (stats = 0; stats < nicvf_n_queue_stats; stats++) {
  163. sprintf(*data, "txq%d: %s", qidx + start_qidx,
  164. nicvf_queue_stats[stats].name);
  165. *data += ETH_GSTRING_LEN;
  166. }
  167. }
  168. }
  169. static void nicvf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
  170. {
  171. struct nicvf *nic = netdev_priv(netdev);
  172. int stats;
  173. int sqs;
  174. if (sset != ETH_SS_STATS)
  175. return;
  176. for (stats = 0; stats < nicvf_n_hw_stats; stats++) {
  177. memcpy(data, nicvf_hw_stats[stats].name, ETH_GSTRING_LEN);
  178. data += ETH_GSTRING_LEN;
  179. }
  180. for (stats = 0; stats < nicvf_n_drv_stats; stats++) {
  181. memcpy(data, nicvf_drv_stats[stats].name, ETH_GSTRING_LEN);
  182. data += ETH_GSTRING_LEN;
  183. }
  184. nicvf_get_qset_strings(nic, &data, 0);
  185. for (sqs = 0; sqs < nic->sqs_count; sqs++) {
  186. if (!nic->snicvf[sqs])
  187. continue;
  188. nicvf_get_qset_strings(nic->snicvf[sqs], &data, sqs + 1);
  189. }
  190. for (stats = 0; stats < BGX_RX_STATS_COUNT; stats++) {
  191. sprintf(data, "bgx_rxstat%d: ", stats);
  192. data += ETH_GSTRING_LEN;
  193. }
  194. for (stats = 0; stats < BGX_TX_STATS_COUNT; stats++) {
  195. sprintf(data, "bgx_txstat%d: ", stats);
  196. data += ETH_GSTRING_LEN;
  197. }
  198. }
  199. static int nicvf_get_sset_count(struct net_device *netdev, int sset)
  200. {
  201. struct nicvf *nic = netdev_priv(netdev);
  202. int qstats_count;
  203. int sqs;
  204. if (sset != ETH_SS_STATS)
  205. return -EINVAL;
  206. qstats_count = nicvf_n_queue_stats *
  207. (nic->qs->rq_cnt + nic->qs->sq_cnt);
  208. for (sqs = 0; sqs < nic->sqs_count; sqs++) {
  209. struct nicvf *snic;
  210. snic = nic->snicvf[sqs];
  211. if (!snic)
  212. continue;
  213. qstats_count += nicvf_n_queue_stats *
  214. (snic->qs->rq_cnt + snic->qs->sq_cnt);
  215. }
  216. return nicvf_n_hw_stats + nicvf_n_drv_stats +
  217. qstats_count +
  218. BGX_RX_STATS_COUNT + BGX_TX_STATS_COUNT;
  219. }
  220. static void nicvf_get_qset_stats(struct nicvf *nic,
  221. struct ethtool_stats *stats, u64 **data)
  222. {
  223. int stat, qidx;
  224. if (!nic)
  225. return;
  226. for (qidx = 0; qidx < nic->qs->rq_cnt; qidx++) {
  227. nicvf_update_rq_stats(nic, qidx);
  228. for (stat = 0; stat < nicvf_n_queue_stats; stat++)
  229. *((*data)++) = ((u64 *)&nic->qs->rq[qidx].stats)
  230. [nicvf_queue_stats[stat].index];
  231. }
  232. for (qidx = 0; qidx < nic->qs->sq_cnt; qidx++) {
  233. nicvf_update_sq_stats(nic, qidx);
  234. for (stat = 0; stat < nicvf_n_queue_stats; stat++)
  235. *((*data)++) = ((u64 *)&nic->qs->sq[qidx].stats)
  236. [nicvf_queue_stats[stat].index];
  237. }
  238. }
  239. static void nicvf_get_ethtool_stats(struct net_device *netdev,
  240. struct ethtool_stats *stats, u64 *data)
  241. {
  242. struct nicvf *nic = netdev_priv(netdev);
  243. int stat, tmp_stats;
  244. int sqs, cpu;
  245. nicvf_update_stats(nic);
  246. /* Update LMAC stats */
  247. nicvf_update_lmac_stats(nic);
  248. for (stat = 0; stat < nicvf_n_hw_stats; stat++)
  249. *(data++) = ((u64 *)&nic->hw_stats)
  250. [nicvf_hw_stats[stat].index];
  251. for (stat = 0; stat < nicvf_n_drv_stats; stat++) {
  252. tmp_stats = 0;
  253. for_each_possible_cpu(cpu)
  254. tmp_stats += ((u64 *)per_cpu_ptr(nic->drv_stats, cpu))
  255. [nicvf_drv_stats[stat].index];
  256. *(data++) = tmp_stats;
  257. }
  258. nicvf_get_qset_stats(nic, stats, &data);
  259. for (sqs = 0; sqs < nic->sqs_count; sqs++) {
  260. if (!nic->snicvf[sqs])
  261. continue;
  262. nicvf_get_qset_stats(nic->snicvf[sqs], stats, &data);
  263. }
  264. for (stat = 0; stat < BGX_RX_STATS_COUNT; stat++)
  265. *(data++) = nic->bgx_stats.rx_stats[stat];
  266. for (stat = 0; stat < BGX_TX_STATS_COUNT; stat++)
  267. *(data++) = nic->bgx_stats.tx_stats[stat];
  268. }
  269. static int nicvf_get_regs_len(struct net_device *dev)
  270. {
  271. return sizeof(u64) * NIC_VF_REG_COUNT;
  272. }
  273. static void nicvf_get_regs(struct net_device *dev,
  274. struct ethtool_regs *regs, void *reg)
  275. {
  276. struct nicvf *nic = netdev_priv(dev);
  277. u64 *p = (u64 *)reg;
  278. u64 reg_offset;
  279. int mbox, key, stat, q;
  280. int i = 0;
  281. regs->version = 0;
  282. memset(p, 0, NIC_VF_REG_COUNT);
  283. p[i++] = nicvf_reg_read(nic, NIC_VNIC_CFG);
  284. /* Mailbox registers */
  285. for (mbox = 0; mbox < NIC_PF_VF_MAILBOX_SIZE; mbox++)
  286. p[i++] = nicvf_reg_read(nic,
  287. NIC_VF_PF_MAILBOX_0_1 | (mbox << 3));
  288. p[i++] = nicvf_reg_read(nic, NIC_VF_INT);
  289. p[i++] = nicvf_reg_read(nic, NIC_VF_INT_W1S);
  290. p[i++] = nicvf_reg_read(nic, NIC_VF_ENA_W1C);
  291. p[i++] = nicvf_reg_read(nic, NIC_VF_ENA_W1S);
  292. p[i++] = nicvf_reg_read(nic, NIC_VNIC_RSS_CFG);
  293. for (key = 0; key < RSS_HASH_KEY_SIZE; key++)
  294. p[i++] = nicvf_reg_read(nic, NIC_VNIC_RSS_KEY_0_4 | (key << 3));
  295. /* Tx/Rx statistics */
  296. for (stat = 0; stat < TX_STATS_ENUM_LAST; stat++)
  297. p[i++] = nicvf_reg_read(nic,
  298. NIC_VNIC_TX_STAT_0_4 | (stat << 3));
  299. for (i = 0; i < RX_STATS_ENUM_LAST; i++)
  300. p[i++] = nicvf_reg_read(nic,
  301. NIC_VNIC_RX_STAT_0_13 | (stat << 3));
  302. p[i++] = nicvf_reg_read(nic, NIC_QSET_RQ_GEN_CFG);
  303. /* All completion queue's registers */
  304. for (q = 0; q < MAX_CMP_QUEUES_PER_QS; q++) {
  305. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_CFG, q);
  306. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_CFG2, q);
  307. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_THRESH, q);
  308. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_BASE, q);
  309. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_HEAD, q);
  310. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_TAIL, q);
  311. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_DOOR, q);
  312. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_STATUS, q);
  313. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_STATUS2, q);
  314. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_DEBUG, q);
  315. }
  316. /* All receive queue's registers */
  317. for (q = 0; q < MAX_RCV_QUEUES_PER_QS; q++) {
  318. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RQ_0_7_CFG, q);
  319. p[i++] = nicvf_queue_reg_read(nic,
  320. NIC_QSET_RQ_0_7_STAT_0_1, q);
  321. reg_offset = NIC_QSET_RQ_0_7_STAT_0_1 | (1 << 3);
  322. p[i++] = nicvf_queue_reg_read(nic, reg_offset, q);
  323. }
  324. for (q = 0; q < MAX_SND_QUEUES_PER_QS; q++) {
  325. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_CFG, q);
  326. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_THRESH, q);
  327. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_BASE, q);
  328. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_HEAD, q);
  329. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_TAIL, q);
  330. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_DOOR, q);
  331. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_STATUS, q);
  332. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_DEBUG, q);
  333. /* Padding, was NIC_QSET_SQ_0_7_CNM_CHG, which
  334. * produces bus errors when read
  335. */
  336. p[i++] = 0;
  337. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_STAT_0_1, q);
  338. reg_offset = NIC_QSET_SQ_0_7_STAT_0_1 | (1 << 3);
  339. p[i++] = nicvf_queue_reg_read(nic, reg_offset, q);
  340. }
  341. for (q = 0; q < MAX_RCV_BUF_DESC_RINGS_PER_QS; q++) {
  342. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_CFG, q);
  343. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_THRESH, q);
  344. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_BASE, q);
  345. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_HEAD, q);
  346. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_TAIL, q);
  347. p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_DOOR, q);
  348. p[i++] = nicvf_queue_reg_read(nic,
  349. NIC_QSET_RBDR_0_1_STATUS0, q);
  350. p[i++] = nicvf_queue_reg_read(nic,
  351. NIC_QSET_RBDR_0_1_STATUS1, q);
  352. reg_offset = NIC_QSET_RBDR_0_1_PREFETCH_STATUS;
  353. p[i++] = nicvf_queue_reg_read(nic, reg_offset, q);
  354. }
  355. }
  356. static int nicvf_get_coalesce(struct net_device *netdev,
  357. struct ethtool_coalesce *cmd)
  358. {
  359. struct nicvf *nic = netdev_priv(netdev);
  360. cmd->rx_coalesce_usecs = nic->cq_coalesce_usecs;
  361. return 0;
  362. }
  363. static void nicvf_get_ringparam(struct net_device *netdev,
  364. struct ethtool_ringparam *ring)
  365. {
  366. struct nicvf *nic = netdev_priv(netdev);
  367. struct queue_set *qs = nic->qs;
  368. ring->rx_max_pending = MAX_RCV_BUF_COUNT;
  369. ring->rx_pending = qs->rbdr_len;
  370. ring->tx_max_pending = MAX_SND_QUEUE_LEN;
  371. ring->tx_pending = qs->sq_len;
  372. }
  373. static int nicvf_get_rss_hash_opts(struct nicvf *nic,
  374. struct ethtool_rxnfc *info)
  375. {
  376. info->data = 0;
  377. switch (info->flow_type) {
  378. case TCP_V4_FLOW:
  379. case TCP_V6_FLOW:
  380. case UDP_V4_FLOW:
  381. case UDP_V6_FLOW:
  382. case SCTP_V4_FLOW:
  383. case SCTP_V6_FLOW:
  384. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  385. case IPV4_FLOW:
  386. case IPV6_FLOW:
  387. info->data |= RXH_IP_SRC | RXH_IP_DST;
  388. break;
  389. default:
  390. return -EINVAL;
  391. }
  392. return 0;
  393. }
  394. static int nicvf_get_rxnfc(struct net_device *dev,
  395. struct ethtool_rxnfc *info, u32 *rules)
  396. {
  397. struct nicvf *nic = netdev_priv(dev);
  398. int ret = -EOPNOTSUPP;
  399. switch (info->cmd) {
  400. case ETHTOOL_GRXRINGS:
  401. info->data = nic->rx_queues;
  402. ret = 0;
  403. break;
  404. case ETHTOOL_GRXFH:
  405. return nicvf_get_rss_hash_opts(nic, info);
  406. default:
  407. break;
  408. }
  409. return ret;
  410. }
  411. static int nicvf_set_rss_hash_opts(struct nicvf *nic,
  412. struct ethtool_rxnfc *info)
  413. {
  414. struct nicvf_rss_info *rss = &nic->rss_info;
  415. u64 rss_cfg = nicvf_reg_read(nic, NIC_VNIC_RSS_CFG);
  416. if (!rss->enable)
  417. netdev_err(nic->netdev,
  418. "RSS is disabled, hash cannot be set\n");
  419. netdev_info(nic->netdev, "Set RSS flow type = %d, data = %lld\n",
  420. info->flow_type, info->data);
  421. if (!(info->data & RXH_IP_SRC) || !(info->data & RXH_IP_DST))
  422. return -EINVAL;
  423. switch (info->flow_type) {
  424. case TCP_V4_FLOW:
  425. case TCP_V6_FLOW:
  426. switch (info->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  427. case 0:
  428. rss_cfg &= ~(1ULL << RSS_HASH_TCP);
  429. break;
  430. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  431. rss_cfg |= (1ULL << RSS_HASH_TCP);
  432. break;
  433. default:
  434. return -EINVAL;
  435. }
  436. break;
  437. case UDP_V4_FLOW:
  438. case UDP_V6_FLOW:
  439. switch (info->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  440. case 0:
  441. rss_cfg &= ~(1ULL << RSS_HASH_UDP);
  442. break;
  443. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  444. rss_cfg |= (1ULL << RSS_HASH_UDP);
  445. break;
  446. default:
  447. return -EINVAL;
  448. }
  449. break;
  450. case SCTP_V4_FLOW:
  451. case SCTP_V6_FLOW:
  452. switch (info->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  453. case 0:
  454. rss_cfg &= ~(1ULL << RSS_HASH_L4ETC);
  455. break;
  456. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  457. rss_cfg |= (1ULL << RSS_HASH_L4ETC);
  458. break;
  459. default:
  460. return -EINVAL;
  461. }
  462. break;
  463. case IPV4_FLOW:
  464. case IPV6_FLOW:
  465. rss_cfg = RSS_HASH_IP;
  466. break;
  467. default:
  468. return -EINVAL;
  469. }
  470. nicvf_reg_write(nic, NIC_VNIC_RSS_CFG, rss_cfg);
  471. return 0;
  472. }
  473. static int nicvf_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
  474. {
  475. struct nicvf *nic = netdev_priv(dev);
  476. switch (info->cmd) {
  477. case ETHTOOL_SRXFH:
  478. return nicvf_set_rss_hash_opts(nic, info);
  479. default:
  480. break;
  481. }
  482. return -EOPNOTSUPP;
  483. }
  484. static u32 nicvf_get_rxfh_key_size(struct net_device *netdev)
  485. {
  486. return RSS_HASH_KEY_SIZE * sizeof(u64);
  487. }
  488. static u32 nicvf_get_rxfh_indir_size(struct net_device *dev)
  489. {
  490. struct nicvf *nic = netdev_priv(dev);
  491. return nic->rss_info.rss_size;
  492. }
  493. static int nicvf_get_rxfh(struct net_device *dev, u32 *indir, u8 *hkey,
  494. u8 *hfunc)
  495. {
  496. struct nicvf *nic = netdev_priv(dev);
  497. struct nicvf_rss_info *rss = &nic->rss_info;
  498. int idx;
  499. if (indir) {
  500. for (idx = 0; idx < rss->rss_size; idx++)
  501. indir[idx] = rss->ind_tbl[idx];
  502. }
  503. if (hkey)
  504. memcpy(hkey, rss->key, RSS_HASH_KEY_SIZE * sizeof(u64));
  505. if (hfunc)
  506. *hfunc = ETH_RSS_HASH_TOP;
  507. return 0;
  508. }
  509. static int nicvf_set_rxfh(struct net_device *dev, const u32 *indir,
  510. const u8 *hkey, u8 hfunc)
  511. {
  512. struct nicvf *nic = netdev_priv(dev);
  513. struct nicvf_rss_info *rss = &nic->rss_info;
  514. int idx;
  515. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
  516. return -EOPNOTSUPP;
  517. if (!rss->enable) {
  518. netdev_err(nic->netdev,
  519. "RSS is disabled, cannot change settings\n");
  520. return -EIO;
  521. }
  522. if (indir) {
  523. for (idx = 0; idx < rss->rss_size; idx++)
  524. rss->ind_tbl[idx] = indir[idx];
  525. }
  526. if (hkey) {
  527. memcpy(rss->key, hkey, RSS_HASH_KEY_SIZE * sizeof(u64));
  528. nicvf_set_rss_key(nic);
  529. }
  530. nicvf_config_rss(nic);
  531. return 0;
  532. }
  533. /* Get no of queues device supports and current queue count */
  534. static void nicvf_get_channels(struct net_device *dev,
  535. struct ethtool_channels *channel)
  536. {
  537. struct nicvf *nic = netdev_priv(dev);
  538. memset(channel, 0, sizeof(*channel));
  539. channel->max_rx = nic->max_queues;
  540. channel->max_tx = nic->max_queues;
  541. channel->rx_count = nic->rx_queues;
  542. channel->tx_count = nic->tx_queues;
  543. }
  544. /* Set no of Tx, Rx queues to be used */
  545. static int nicvf_set_channels(struct net_device *dev,
  546. struct ethtool_channels *channel)
  547. {
  548. struct nicvf *nic = netdev_priv(dev);
  549. int err = 0;
  550. bool if_up = netif_running(dev);
  551. int cqcount;
  552. if (!channel->rx_count || !channel->tx_count)
  553. return -EINVAL;
  554. if (channel->rx_count > nic->max_queues)
  555. return -EINVAL;
  556. if (channel->tx_count > nic->max_queues)
  557. return -EINVAL;
  558. if (if_up)
  559. nicvf_stop(dev);
  560. cqcount = max(channel->rx_count, channel->tx_count);
  561. if (cqcount > MAX_CMP_QUEUES_PER_QS) {
  562. nic->sqs_count = roundup(cqcount, MAX_CMP_QUEUES_PER_QS);
  563. nic->sqs_count = (nic->sqs_count / MAX_CMP_QUEUES_PER_QS) - 1;
  564. } else {
  565. nic->sqs_count = 0;
  566. }
  567. nic->qs->rq_cnt = min_t(u32, channel->rx_count, MAX_RCV_QUEUES_PER_QS);
  568. nic->qs->sq_cnt = min_t(u32, channel->tx_count, MAX_SND_QUEUES_PER_QS);
  569. nic->qs->cq_cnt = max(nic->qs->rq_cnt, nic->qs->sq_cnt);
  570. nic->rx_queues = channel->rx_count;
  571. nic->tx_queues = channel->tx_count;
  572. err = nicvf_set_real_num_queues(dev, nic->tx_queues, nic->rx_queues);
  573. if (err)
  574. return err;
  575. if (if_up)
  576. nicvf_open(dev);
  577. netdev_info(dev, "Setting num Tx rings to %d, Rx rings to %d success\n",
  578. nic->tx_queues, nic->rx_queues);
  579. return err;
  580. }
  581. static const struct ethtool_ops nicvf_ethtool_ops = {
  582. .get_settings = nicvf_get_settings,
  583. .get_link = nicvf_get_link,
  584. .get_drvinfo = nicvf_get_drvinfo,
  585. .get_msglevel = nicvf_get_msglevel,
  586. .set_msglevel = nicvf_set_msglevel,
  587. .get_strings = nicvf_get_strings,
  588. .get_sset_count = nicvf_get_sset_count,
  589. .get_ethtool_stats = nicvf_get_ethtool_stats,
  590. .get_regs_len = nicvf_get_regs_len,
  591. .get_regs = nicvf_get_regs,
  592. .get_coalesce = nicvf_get_coalesce,
  593. .get_ringparam = nicvf_get_ringparam,
  594. .get_rxnfc = nicvf_get_rxnfc,
  595. .set_rxnfc = nicvf_set_rxnfc,
  596. .get_rxfh_key_size = nicvf_get_rxfh_key_size,
  597. .get_rxfh_indir_size = nicvf_get_rxfh_indir_size,
  598. .get_rxfh = nicvf_get_rxfh,
  599. .set_rxfh = nicvf_set_rxfh,
  600. .get_channels = nicvf_get_channels,
  601. .set_channels = nicvf_set_channels,
  602. .get_ts_info = ethtool_op_get_ts_info,
  603. };
  604. void nicvf_set_ethtool_ops(struct net_device *netdev)
  605. {
  606. netdev->ethtool_ops = &nicvf_ethtool_ops;
  607. }