enic_ethtool.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /**
  2. * Copyright 2013 Cisco Systems, Inc. All rights reserved.
  3. *
  4. * This program is free software; you may redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; version 2 of the License.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  9. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  11. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  12. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  13. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  14. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  15. * SOFTWARE.
  16. *
  17. */
  18. #include <linux/netdevice.h>
  19. #include <linux/ethtool.h>
  20. #include <linux/net_tstamp.h>
  21. #include "enic_res.h"
  22. #include "enic.h"
  23. #include "enic_dev.h"
  24. #include "enic_clsf.h"
  25. #include "vnic_rss.h"
  26. #include "vnic_stats.h"
  27. struct enic_stat {
  28. char name[ETH_GSTRING_LEN];
  29. unsigned int index;
  30. };
  31. #define ENIC_TX_STAT(stat) { \
  32. .name = #stat, \
  33. .index = offsetof(struct vnic_tx_stats, stat) / sizeof(u64) \
  34. }
  35. #define ENIC_RX_STAT(stat) { \
  36. .name = #stat, \
  37. .index = offsetof(struct vnic_rx_stats, stat) / sizeof(u64) \
  38. }
  39. #define ENIC_GEN_STAT(stat) { \
  40. .name = #stat, \
  41. .index = offsetof(struct vnic_gen_stats, stat) / sizeof(u64)\
  42. }
  43. static const struct enic_stat enic_tx_stats[] = {
  44. ENIC_TX_STAT(tx_frames_ok),
  45. ENIC_TX_STAT(tx_unicast_frames_ok),
  46. ENIC_TX_STAT(tx_multicast_frames_ok),
  47. ENIC_TX_STAT(tx_broadcast_frames_ok),
  48. ENIC_TX_STAT(tx_bytes_ok),
  49. ENIC_TX_STAT(tx_unicast_bytes_ok),
  50. ENIC_TX_STAT(tx_multicast_bytes_ok),
  51. ENIC_TX_STAT(tx_broadcast_bytes_ok),
  52. ENIC_TX_STAT(tx_drops),
  53. ENIC_TX_STAT(tx_errors),
  54. ENIC_TX_STAT(tx_tso),
  55. };
  56. static const struct enic_stat enic_rx_stats[] = {
  57. ENIC_RX_STAT(rx_frames_ok),
  58. ENIC_RX_STAT(rx_frames_total),
  59. ENIC_RX_STAT(rx_unicast_frames_ok),
  60. ENIC_RX_STAT(rx_multicast_frames_ok),
  61. ENIC_RX_STAT(rx_broadcast_frames_ok),
  62. ENIC_RX_STAT(rx_bytes_ok),
  63. ENIC_RX_STAT(rx_unicast_bytes_ok),
  64. ENIC_RX_STAT(rx_multicast_bytes_ok),
  65. ENIC_RX_STAT(rx_broadcast_bytes_ok),
  66. ENIC_RX_STAT(rx_drop),
  67. ENIC_RX_STAT(rx_no_bufs),
  68. ENIC_RX_STAT(rx_errors),
  69. ENIC_RX_STAT(rx_rss),
  70. ENIC_RX_STAT(rx_crc_errors),
  71. ENIC_RX_STAT(rx_frames_64),
  72. ENIC_RX_STAT(rx_frames_127),
  73. ENIC_RX_STAT(rx_frames_255),
  74. ENIC_RX_STAT(rx_frames_511),
  75. ENIC_RX_STAT(rx_frames_1023),
  76. ENIC_RX_STAT(rx_frames_1518),
  77. ENIC_RX_STAT(rx_frames_to_max),
  78. };
  79. static const struct enic_stat enic_gen_stats[] = {
  80. ENIC_GEN_STAT(dma_map_error),
  81. };
  82. static const unsigned int enic_n_tx_stats = ARRAY_SIZE(enic_tx_stats);
  83. static const unsigned int enic_n_rx_stats = ARRAY_SIZE(enic_rx_stats);
  84. static const unsigned int enic_n_gen_stats = ARRAY_SIZE(enic_gen_stats);
  85. static void enic_intr_coal_set_rx(struct enic *enic, u32 timer)
  86. {
  87. int i;
  88. int intr;
  89. for (i = 0; i < enic->rq_count; i++) {
  90. intr = enic_msix_rq_intr(enic, i);
  91. vnic_intr_coalescing_timer_set(&enic->intr[intr], timer);
  92. }
  93. }
  94. static int enic_get_ksettings(struct net_device *netdev,
  95. struct ethtool_link_ksettings *ecmd)
  96. {
  97. struct enic *enic = netdev_priv(netdev);
  98. struct ethtool_link_settings *base = &ecmd->base;
  99. ethtool_link_ksettings_add_link_mode(ecmd, supported,
  100. 10000baseT_Full);
  101. ethtool_link_ksettings_add_link_mode(ecmd, supported, FIBRE);
  102. ethtool_link_ksettings_add_link_mode(ecmd, advertising,
  103. 10000baseT_Full);
  104. ethtool_link_ksettings_add_link_mode(ecmd, advertising, FIBRE);
  105. base->port = PORT_FIBRE;
  106. if (netif_carrier_ok(netdev)) {
  107. base->speed = vnic_dev_port_speed(enic->vdev);
  108. base->duplex = DUPLEX_FULL;
  109. } else {
  110. base->speed = SPEED_UNKNOWN;
  111. base->duplex = DUPLEX_UNKNOWN;
  112. }
  113. base->autoneg = AUTONEG_DISABLE;
  114. return 0;
  115. }
  116. static void enic_get_drvinfo(struct net_device *netdev,
  117. struct ethtool_drvinfo *drvinfo)
  118. {
  119. struct enic *enic = netdev_priv(netdev);
  120. struct vnic_devcmd_fw_info *fw_info;
  121. int err;
  122. err = enic_dev_fw_info(enic, &fw_info);
  123. /* return only when pci_zalloc_consistent fails in vnic_dev_fw_info
  124. * For other failures, like devcmd failure, we return previously
  125. * recorded info.
  126. */
  127. if (err == -ENOMEM)
  128. return;
  129. strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
  130. strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
  131. strlcpy(drvinfo->fw_version, fw_info->fw_version,
  132. sizeof(drvinfo->fw_version));
  133. strlcpy(drvinfo->bus_info, pci_name(enic->pdev),
  134. sizeof(drvinfo->bus_info));
  135. }
  136. static void enic_get_strings(struct net_device *netdev, u32 stringset,
  137. u8 *data)
  138. {
  139. unsigned int i;
  140. switch (stringset) {
  141. case ETH_SS_STATS:
  142. for (i = 0; i < enic_n_tx_stats; i++) {
  143. memcpy(data, enic_tx_stats[i].name, ETH_GSTRING_LEN);
  144. data += ETH_GSTRING_LEN;
  145. }
  146. for (i = 0; i < enic_n_rx_stats; i++) {
  147. memcpy(data, enic_rx_stats[i].name, ETH_GSTRING_LEN);
  148. data += ETH_GSTRING_LEN;
  149. }
  150. for (i = 0; i < enic_n_gen_stats; i++) {
  151. memcpy(data, enic_gen_stats[i].name, ETH_GSTRING_LEN);
  152. data += ETH_GSTRING_LEN;
  153. }
  154. break;
  155. }
  156. }
  157. static void enic_get_ringparam(struct net_device *netdev,
  158. struct ethtool_ringparam *ring)
  159. {
  160. struct enic *enic = netdev_priv(netdev);
  161. struct vnic_enet_config *c = &enic->config;
  162. ring->rx_max_pending = ENIC_MAX_RQ_DESCS;
  163. ring->rx_pending = c->rq_desc_count;
  164. ring->tx_max_pending = ENIC_MAX_WQ_DESCS;
  165. ring->tx_pending = c->wq_desc_count;
  166. }
  167. static int enic_set_ringparam(struct net_device *netdev,
  168. struct ethtool_ringparam *ring)
  169. {
  170. struct enic *enic = netdev_priv(netdev);
  171. struct vnic_enet_config *c = &enic->config;
  172. int running = netif_running(netdev);
  173. unsigned int rx_pending;
  174. unsigned int tx_pending;
  175. int err = 0;
  176. if (ring->rx_mini_max_pending || ring->rx_mini_pending) {
  177. netdev_info(netdev,
  178. "modifying mini ring params is not supported");
  179. return -EINVAL;
  180. }
  181. if (ring->rx_jumbo_max_pending || ring->rx_jumbo_pending) {
  182. netdev_info(netdev,
  183. "modifying jumbo ring params is not supported");
  184. return -EINVAL;
  185. }
  186. rx_pending = c->rq_desc_count;
  187. tx_pending = c->wq_desc_count;
  188. if (ring->rx_pending > ENIC_MAX_RQ_DESCS ||
  189. ring->rx_pending < ENIC_MIN_RQ_DESCS) {
  190. netdev_info(netdev, "rx pending (%u) not in range [%u,%u]",
  191. ring->rx_pending, ENIC_MIN_RQ_DESCS,
  192. ENIC_MAX_RQ_DESCS);
  193. return -EINVAL;
  194. }
  195. if (ring->tx_pending > ENIC_MAX_WQ_DESCS ||
  196. ring->tx_pending < ENIC_MIN_WQ_DESCS) {
  197. netdev_info(netdev, "tx pending (%u) not in range [%u,%u]",
  198. ring->tx_pending, ENIC_MIN_WQ_DESCS,
  199. ENIC_MAX_WQ_DESCS);
  200. return -EINVAL;
  201. }
  202. if (running)
  203. dev_close(netdev);
  204. c->rq_desc_count =
  205. ring->rx_pending & 0xffffffe0; /* must be aligned to groups of 32 */
  206. c->wq_desc_count =
  207. ring->tx_pending & 0xffffffe0; /* must be aligned to groups of 32 */
  208. enic_free_vnic_resources(enic);
  209. err = enic_alloc_vnic_resources(enic);
  210. if (err) {
  211. netdev_err(netdev,
  212. "Failed to alloc vNIC resources, aborting\n");
  213. enic_free_vnic_resources(enic);
  214. goto err_out;
  215. }
  216. enic_init_vnic_resources(enic);
  217. if (running) {
  218. err = dev_open(netdev);
  219. if (err)
  220. goto err_out;
  221. }
  222. return 0;
  223. err_out:
  224. c->rq_desc_count = rx_pending;
  225. c->wq_desc_count = tx_pending;
  226. return err;
  227. }
  228. static int enic_get_sset_count(struct net_device *netdev, int sset)
  229. {
  230. switch (sset) {
  231. case ETH_SS_STATS:
  232. return enic_n_tx_stats + enic_n_rx_stats + enic_n_gen_stats;
  233. default:
  234. return -EOPNOTSUPP;
  235. }
  236. }
  237. static void enic_get_ethtool_stats(struct net_device *netdev,
  238. struct ethtool_stats *stats, u64 *data)
  239. {
  240. struct enic *enic = netdev_priv(netdev);
  241. struct vnic_stats *vstats;
  242. unsigned int i;
  243. int err;
  244. err = enic_dev_stats_dump(enic, &vstats);
  245. /* return only when pci_zalloc_consistent fails in vnic_dev_stats_dump
  246. * For other failures, like devcmd failure, we return previously
  247. * recorded stats.
  248. */
  249. if (err == -ENOMEM)
  250. return;
  251. for (i = 0; i < enic_n_tx_stats; i++)
  252. *(data++) = ((u64 *)&vstats->tx)[enic_tx_stats[i].index];
  253. for (i = 0; i < enic_n_rx_stats; i++)
  254. *(data++) = ((u64 *)&vstats->rx)[enic_rx_stats[i].index];
  255. for (i = 0; i < enic_n_gen_stats; i++)
  256. *(data++) = ((u64 *)&enic->gen_stats)[enic_gen_stats[i].index];
  257. }
  258. static u32 enic_get_msglevel(struct net_device *netdev)
  259. {
  260. struct enic *enic = netdev_priv(netdev);
  261. return enic->msg_enable;
  262. }
  263. static void enic_set_msglevel(struct net_device *netdev, u32 value)
  264. {
  265. struct enic *enic = netdev_priv(netdev);
  266. enic->msg_enable = value;
  267. }
  268. static int enic_get_coalesce(struct net_device *netdev,
  269. struct ethtool_coalesce *ecmd)
  270. {
  271. struct enic *enic = netdev_priv(netdev);
  272. struct enic_rx_coal *rxcoal = &enic->rx_coalesce_setting;
  273. if (vnic_dev_get_intr_mode(enic->vdev) == VNIC_DEV_INTR_MODE_MSIX)
  274. ecmd->tx_coalesce_usecs = enic->tx_coalesce_usecs;
  275. ecmd->rx_coalesce_usecs = enic->rx_coalesce_usecs;
  276. if (rxcoal->use_adaptive_rx_coalesce)
  277. ecmd->use_adaptive_rx_coalesce = 1;
  278. ecmd->rx_coalesce_usecs_low = rxcoal->small_pkt_range_start;
  279. ecmd->rx_coalesce_usecs_high = rxcoal->range_end;
  280. return 0;
  281. }
  282. static int enic_coalesce_valid(struct enic *enic,
  283. struct ethtool_coalesce *ec)
  284. {
  285. u32 coalesce_usecs_max = vnic_dev_get_intr_coal_timer_max(enic->vdev);
  286. u32 rx_coalesce_usecs_high = min_t(u32, coalesce_usecs_max,
  287. ec->rx_coalesce_usecs_high);
  288. u32 rx_coalesce_usecs_low = min_t(u32, coalesce_usecs_max,
  289. ec->rx_coalesce_usecs_low);
  290. if (ec->rx_max_coalesced_frames ||
  291. ec->rx_coalesce_usecs_irq ||
  292. ec->rx_max_coalesced_frames_irq ||
  293. ec->tx_max_coalesced_frames ||
  294. ec->tx_coalesce_usecs_irq ||
  295. ec->tx_max_coalesced_frames_irq ||
  296. ec->stats_block_coalesce_usecs ||
  297. ec->use_adaptive_tx_coalesce ||
  298. ec->pkt_rate_low ||
  299. ec->rx_max_coalesced_frames_low ||
  300. ec->tx_coalesce_usecs_low ||
  301. ec->tx_max_coalesced_frames_low ||
  302. ec->pkt_rate_high ||
  303. ec->rx_max_coalesced_frames_high ||
  304. ec->tx_coalesce_usecs_high ||
  305. ec->tx_max_coalesced_frames_high ||
  306. ec->rate_sample_interval)
  307. return -EINVAL;
  308. if ((vnic_dev_get_intr_mode(enic->vdev) != VNIC_DEV_INTR_MODE_MSIX) &&
  309. ec->tx_coalesce_usecs)
  310. return -EINVAL;
  311. if ((ec->tx_coalesce_usecs > coalesce_usecs_max) ||
  312. (ec->rx_coalesce_usecs > coalesce_usecs_max) ||
  313. (ec->rx_coalesce_usecs_low > coalesce_usecs_max) ||
  314. (ec->rx_coalesce_usecs_high > coalesce_usecs_max))
  315. netdev_info(enic->netdev, "ethtool_set_coalesce: adaptor supports max coalesce value of %d. Setting max value.\n",
  316. coalesce_usecs_max);
  317. if (ec->rx_coalesce_usecs_high &&
  318. (rx_coalesce_usecs_high <
  319. rx_coalesce_usecs_low + ENIC_AIC_LARGE_PKT_DIFF))
  320. return -EINVAL;
  321. return 0;
  322. }
  323. static int enic_set_coalesce(struct net_device *netdev,
  324. struct ethtool_coalesce *ecmd)
  325. {
  326. struct enic *enic = netdev_priv(netdev);
  327. u32 tx_coalesce_usecs;
  328. u32 rx_coalesce_usecs;
  329. u32 rx_coalesce_usecs_low;
  330. u32 rx_coalesce_usecs_high;
  331. u32 coalesce_usecs_max;
  332. unsigned int i, intr;
  333. int ret;
  334. struct enic_rx_coal *rxcoal = &enic->rx_coalesce_setting;
  335. ret = enic_coalesce_valid(enic, ecmd);
  336. if (ret)
  337. return ret;
  338. coalesce_usecs_max = vnic_dev_get_intr_coal_timer_max(enic->vdev);
  339. tx_coalesce_usecs = min_t(u32, ecmd->tx_coalesce_usecs,
  340. coalesce_usecs_max);
  341. rx_coalesce_usecs = min_t(u32, ecmd->rx_coalesce_usecs,
  342. coalesce_usecs_max);
  343. rx_coalesce_usecs_low = min_t(u32, ecmd->rx_coalesce_usecs_low,
  344. coalesce_usecs_max);
  345. rx_coalesce_usecs_high = min_t(u32, ecmd->rx_coalesce_usecs_high,
  346. coalesce_usecs_max);
  347. if (vnic_dev_get_intr_mode(enic->vdev) == VNIC_DEV_INTR_MODE_MSIX) {
  348. for (i = 0; i < enic->wq_count; i++) {
  349. intr = enic_msix_wq_intr(enic, i);
  350. vnic_intr_coalescing_timer_set(&enic->intr[intr],
  351. tx_coalesce_usecs);
  352. }
  353. enic->tx_coalesce_usecs = tx_coalesce_usecs;
  354. }
  355. rxcoal->use_adaptive_rx_coalesce = !!ecmd->use_adaptive_rx_coalesce;
  356. if (!rxcoal->use_adaptive_rx_coalesce)
  357. enic_intr_coal_set_rx(enic, rx_coalesce_usecs);
  358. if (ecmd->rx_coalesce_usecs_high) {
  359. rxcoal->range_end = rx_coalesce_usecs_high;
  360. rxcoal->small_pkt_range_start = rx_coalesce_usecs_low;
  361. rxcoal->large_pkt_range_start = rx_coalesce_usecs_low +
  362. ENIC_AIC_LARGE_PKT_DIFF;
  363. }
  364. enic->rx_coalesce_usecs = rx_coalesce_usecs;
  365. return 0;
  366. }
  367. static int enic_grxclsrlall(struct enic *enic, struct ethtool_rxnfc *cmd,
  368. u32 *rule_locs)
  369. {
  370. int j, ret = 0, cnt = 0;
  371. cmd->data = enic->rfs_h.max - enic->rfs_h.free;
  372. for (j = 0; j < (1 << ENIC_RFS_FLW_BITSHIFT); j++) {
  373. struct hlist_head *hhead;
  374. struct hlist_node *tmp;
  375. struct enic_rfs_fltr_node *n;
  376. hhead = &enic->rfs_h.ht_head[j];
  377. hlist_for_each_entry_safe(n, tmp, hhead, node) {
  378. if (cnt == cmd->rule_cnt)
  379. return -EMSGSIZE;
  380. rule_locs[cnt] = n->fltr_id;
  381. cnt++;
  382. }
  383. }
  384. cmd->rule_cnt = cnt;
  385. return ret;
  386. }
  387. static int enic_grxclsrule(struct enic *enic, struct ethtool_rxnfc *cmd)
  388. {
  389. struct ethtool_rx_flow_spec *fsp =
  390. (struct ethtool_rx_flow_spec *)&cmd->fs;
  391. struct enic_rfs_fltr_node *n;
  392. n = htbl_fltr_search(enic, (u16)fsp->location);
  393. if (!n)
  394. return -EINVAL;
  395. switch (n->keys.basic.ip_proto) {
  396. case IPPROTO_TCP:
  397. fsp->flow_type = TCP_V4_FLOW;
  398. break;
  399. case IPPROTO_UDP:
  400. fsp->flow_type = UDP_V4_FLOW;
  401. break;
  402. default:
  403. return -EINVAL;
  404. break;
  405. }
  406. fsp->h_u.tcp_ip4_spec.ip4src = flow_get_u32_src(&n->keys);
  407. fsp->m_u.tcp_ip4_spec.ip4src = (__u32)~0;
  408. fsp->h_u.tcp_ip4_spec.ip4dst = flow_get_u32_dst(&n->keys);
  409. fsp->m_u.tcp_ip4_spec.ip4dst = (__u32)~0;
  410. fsp->h_u.tcp_ip4_spec.psrc = n->keys.ports.src;
  411. fsp->m_u.tcp_ip4_spec.psrc = (__u16)~0;
  412. fsp->h_u.tcp_ip4_spec.pdst = n->keys.ports.dst;
  413. fsp->m_u.tcp_ip4_spec.pdst = (__u16)~0;
  414. fsp->ring_cookie = n->rq_id;
  415. return 0;
  416. }
  417. static int enic_get_rx_flow_hash(struct enic *enic, struct ethtool_rxnfc *cmd)
  418. {
  419. u8 rss_hash_type = 0;
  420. cmd->data = 0;
  421. spin_lock_bh(&enic->devcmd_lock);
  422. (void)vnic_dev_capable_rss_hash_type(enic->vdev, &rss_hash_type);
  423. spin_unlock_bh(&enic->devcmd_lock);
  424. switch (cmd->flow_type) {
  425. case TCP_V6_FLOW:
  426. case TCP_V4_FLOW:
  427. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3 |
  428. RXH_IP_SRC | RXH_IP_DST;
  429. break;
  430. case UDP_V6_FLOW:
  431. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  432. if (rss_hash_type & NIC_CFG_RSS_HASH_TYPE_UDP_IPV6)
  433. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  434. break;
  435. case UDP_V4_FLOW:
  436. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  437. if (rss_hash_type & NIC_CFG_RSS_HASH_TYPE_UDP_IPV4)
  438. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  439. break;
  440. case SCTP_V4_FLOW:
  441. case AH_ESP_V4_FLOW:
  442. case AH_V4_FLOW:
  443. case ESP_V4_FLOW:
  444. case SCTP_V6_FLOW:
  445. case AH_ESP_V6_FLOW:
  446. case AH_V6_FLOW:
  447. case ESP_V6_FLOW:
  448. case IPV4_FLOW:
  449. case IPV6_FLOW:
  450. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  451. break;
  452. default:
  453. return -EINVAL;
  454. }
  455. return 0;
  456. }
  457. static int enic_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
  458. u32 *rule_locs)
  459. {
  460. struct enic *enic = netdev_priv(dev);
  461. int ret = 0;
  462. switch (cmd->cmd) {
  463. case ETHTOOL_GRXRINGS:
  464. cmd->data = enic->rq_count;
  465. break;
  466. case ETHTOOL_GRXCLSRLCNT:
  467. spin_lock_bh(&enic->rfs_h.lock);
  468. cmd->rule_cnt = enic->rfs_h.max - enic->rfs_h.free;
  469. cmd->data = enic->rfs_h.max;
  470. spin_unlock_bh(&enic->rfs_h.lock);
  471. break;
  472. case ETHTOOL_GRXCLSRLALL:
  473. spin_lock_bh(&enic->rfs_h.lock);
  474. ret = enic_grxclsrlall(enic, cmd, rule_locs);
  475. spin_unlock_bh(&enic->rfs_h.lock);
  476. break;
  477. case ETHTOOL_GRXCLSRULE:
  478. spin_lock_bh(&enic->rfs_h.lock);
  479. ret = enic_grxclsrule(enic, cmd);
  480. spin_unlock_bh(&enic->rfs_h.lock);
  481. break;
  482. case ETHTOOL_GRXFH:
  483. ret = enic_get_rx_flow_hash(enic, cmd);
  484. break;
  485. default:
  486. ret = -EOPNOTSUPP;
  487. break;
  488. }
  489. return ret;
  490. }
  491. static int enic_get_tunable(struct net_device *dev,
  492. const struct ethtool_tunable *tuna, void *data)
  493. {
  494. struct enic *enic = netdev_priv(dev);
  495. int ret = 0;
  496. switch (tuna->id) {
  497. case ETHTOOL_RX_COPYBREAK:
  498. *(u32 *)data = enic->rx_copybreak;
  499. break;
  500. default:
  501. ret = -EINVAL;
  502. break;
  503. }
  504. return ret;
  505. }
  506. static int enic_set_tunable(struct net_device *dev,
  507. const struct ethtool_tunable *tuna,
  508. const void *data)
  509. {
  510. struct enic *enic = netdev_priv(dev);
  511. int ret = 0;
  512. switch (tuna->id) {
  513. case ETHTOOL_RX_COPYBREAK:
  514. enic->rx_copybreak = *(u32 *)data;
  515. break;
  516. default:
  517. ret = -EINVAL;
  518. break;
  519. }
  520. return ret;
  521. }
  522. static u32 enic_get_rxfh_key_size(struct net_device *netdev)
  523. {
  524. return ENIC_RSS_LEN;
  525. }
  526. static int enic_get_rxfh(struct net_device *netdev, u32 *indir, u8 *hkey,
  527. u8 *hfunc)
  528. {
  529. struct enic *enic = netdev_priv(netdev);
  530. if (hkey)
  531. memcpy(hkey, enic->rss_key, ENIC_RSS_LEN);
  532. if (hfunc)
  533. *hfunc = ETH_RSS_HASH_TOP;
  534. return 0;
  535. }
  536. static int enic_set_rxfh(struct net_device *netdev, const u32 *indir,
  537. const u8 *hkey, const u8 hfunc)
  538. {
  539. struct enic *enic = netdev_priv(netdev);
  540. if ((hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) ||
  541. indir)
  542. return -EINVAL;
  543. if (hkey)
  544. memcpy(enic->rss_key, hkey, ENIC_RSS_LEN);
  545. return __enic_set_rsskey(enic);
  546. }
  547. static int enic_get_ts_info(struct net_device *netdev,
  548. struct ethtool_ts_info *info)
  549. {
  550. info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  551. SOF_TIMESTAMPING_RX_SOFTWARE |
  552. SOF_TIMESTAMPING_SOFTWARE;
  553. return 0;
  554. }
  555. static const struct ethtool_ops enic_ethtool_ops = {
  556. .get_drvinfo = enic_get_drvinfo,
  557. .get_msglevel = enic_get_msglevel,
  558. .set_msglevel = enic_set_msglevel,
  559. .get_link = ethtool_op_get_link,
  560. .get_strings = enic_get_strings,
  561. .get_ringparam = enic_get_ringparam,
  562. .set_ringparam = enic_set_ringparam,
  563. .get_sset_count = enic_get_sset_count,
  564. .get_ethtool_stats = enic_get_ethtool_stats,
  565. .get_coalesce = enic_get_coalesce,
  566. .set_coalesce = enic_set_coalesce,
  567. .get_rxnfc = enic_get_rxnfc,
  568. .get_tunable = enic_get_tunable,
  569. .set_tunable = enic_set_tunable,
  570. .get_rxfh_key_size = enic_get_rxfh_key_size,
  571. .get_rxfh = enic_get_rxfh,
  572. .set_rxfh = enic_set_rxfh,
  573. .get_link_ksettings = enic_get_ksettings,
  574. .get_ts_info = enic_get_ts_info,
  575. };
  576. void enic_set_ethtool_ops(struct net_device *netdev)
  577. {
  578. netdev->ethtool_ops = &enic_ethtool_ops;
  579. }