nicvf_ethtool.c 18 KB

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