enic_ethtool.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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 "enic_res.h"
  21. #include "enic.h"
  22. #include "enic_dev.h"
  23. #include "enic_clsf.h"
  24. #include "vnic_rss.h"
  25. #include "vnic_stats.h"
  26. struct enic_stat {
  27. char name[ETH_GSTRING_LEN];
  28. unsigned int index;
  29. };
  30. #define ENIC_TX_STAT(stat) { \
  31. .name = #stat, \
  32. .index = offsetof(struct vnic_tx_stats, stat) / sizeof(u64) \
  33. }
  34. #define ENIC_RX_STAT(stat) { \
  35. .name = #stat, \
  36. .index = offsetof(struct vnic_rx_stats, stat) / sizeof(u64) \
  37. }
  38. #define ENIC_GEN_STAT(stat) { \
  39. .name = #stat, \
  40. .index = offsetof(struct vnic_gen_stats, stat) / sizeof(u64)\
  41. }
  42. static const struct enic_stat enic_tx_stats[] = {
  43. ENIC_TX_STAT(tx_frames_ok),
  44. ENIC_TX_STAT(tx_unicast_frames_ok),
  45. ENIC_TX_STAT(tx_multicast_frames_ok),
  46. ENIC_TX_STAT(tx_broadcast_frames_ok),
  47. ENIC_TX_STAT(tx_bytes_ok),
  48. ENIC_TX_STAT(tx_unicast_bytes_ok),
  49. ENIC_TX_STAT(tx_multicast_bytes_ok),
  50. ENIC_TX_STAT(tx_broadcast_bytes_ok),
  51. ENIC_TX_STAT(tx_drops),
  52. ENIC_TX_STAT(tx_errors),
  53. ENIC_TX_STAT(tx_tso),
  54. };
  55. static const struct enic_stat enic_rx_stats[] = {
  56. ENIC_RX_STAT(rx_frames_ok),
  57. ENIC_RX_STAT(rx_frames_total),
  58. ENIC_RX_STAT(rx_unicast_frames_ok),
  59. ENIC_RX_STAT(rx_multicast_frames_ok),
  60. ENIC_RX_STAT(rx_broadcast_frames_ok),
  61. ENIC_RX_STAT(rx_bytes_ok),
  62. ENIC_RX_STAT(rx_unicast_bytes_ok),
  63. ENIC_RX_STAT(rx_multicast_bytes_ok),
  64. ENIC_RX_STAT(rx_broadcast_bytes_ok),
  65. ENIC_RX_STAT(rx_drop),
  66. ENIC_RX_STAT(rx_no_bufs),
  67. ENIC_RX_STAT(rx_errors),
  68. ENIC_RX_STAT(rx_rss),
  69. ENIC_RX_STAT(rx_crc_errors),
  70. ENIC_RX_STAT(rx_frames_64),
  71. ENIC_RX_STAT(rx_frames_127),
  72. ENIC_RX_STAT(rx_frames_255),
  73. ENIC_RX_STAT(rx_frames_511),
  74. ENIC_RX_STAT(rx_frames_1023),
  75. ENIC_RX_STAT(rx_frames_1518),
  76. ENIC_RX_STAT(rx_frames_to_max),
  77. };
  78. static const struct enic_stat enic_gen_stats[] = {
  79. ENIC_GEN_STAT(dma_map_error),
  80. };
  81. static const unsigned int enic_n_tx_stats = ARRAY_SIZE(enic_tx_stats);
  82. static const unsigned int enic_n_rx_stats = ARRAY_SIZE(enic_rx_stats);
  83. static const unsigned int enic_n_gen_stats = ARRAY_SIZE(enic_gen_stats);
  84. static void enic_intr_coal_set_rx(struct enic *enic, u32 timer)
  85. {
  86. int i;
  87. int intr;
  88. for (i = 0; i < enic->rq_count; i++) {
  89. intr = enic_msix_rq_intr(enic, i);
  90. vnic_intr_coalescing_timer_set(&enic->intr[intr], timer);
  91. }
  92. }
  93. static int enic_get_settings(struct net_device *netdev,
  94. struct ethtool_cmd *ecmd)
  95. {
  96. struct enic *enic = netdev_priv(netdev);
  97. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
  98. ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
  99. ecmd->port = PORT_FIBRE;
  100. ecmd->transceiver = XCVR_EXTERNAL;
  101. if (netif_carrier_ok(netdev)) {
  102. ethtool_cmd_speed_set(ecmd, vnic_dev_port_speed(enic->vdev));
  103. ecmd->duplex = DUPLEX_FULL;
  104. } else {
  105. ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
  106. ecmd->duplex = DUPLEX_UNKNOWN;
  107. }
  108. ecmd->autoneg = AUTONEG_DISABLE;
  109. return 0;
  110. }
  111. static void enic_get_drvinfo(struct net_device *netdev,
  112. struct ethtool_drvinfo *drvinfo)
  113. {
  114. struct enic *enic = netdev_priv(netdev);
  115. struct vnic_devcmd_fw_info *fw_info;
  116. enic_dev_fw_info(enic, &fw_info);
  117. strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
  118. strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
  119. strlcpy(drvinfo->fw_version, fw_info->fw_version,
  120. sizeof(drvinfo->fw_version));
  121. strlcpy(drvinfo->bus_info, pci_name(enic->pdev),
  122. sizeof(drvinfo->bus_info));
  123. }
  124. static void enic_get_strings(struct net_device *netdev, u32 stringset,
  125. u8 *data)
  126. {
  127. unsigned int i;
  128. switch (stringset) {
  129. case ETH_SS_STATS:
  130. for (i = 0; i < enic_n_tx_stats; i++) {
  131. memcpy(data, enic_tx_stats[i].name, ETH_GSTRING_LEN);
  132. data += ETH_GSTRING_LEN;
  133. }
  134. for (i = 0; i < enic_n_rx_stats; i++) {
  135. memcpy(data, enic_rx_stats[i].name, ETH_GSTRING_LEN);
  136. data += ETH_GSTRING_LEN;
  137. }
  138. for (i = 0; i < enic_n_gen_stats; i++) {
  139. memcpy(data, enic_gen_stats[i].name, ETH_GSTRING_LEN);
  140. data += ETH_GSTRING_LEN;
  141. }
  142. break;
  143. }
  144. }
  145. static int enic_get_sset_count(struct net_device *netdev, int sset)
  146. {
  147. switch (sset) {
  148. case ETH_SS_STATS:
  149. return enic_n_tx_stats + enic_n_rx_stats + enic_n_gen_stats;
  150. default:
  151. return -EOPNOTSUPP;
  152. }
  153. }
  154. static void enic_get_ethtool_stats(struct net_device *netdev,
  155. struct ethtool_stats *stats, u64 *data)
  156. {
  157. struct enic *enic = netdev_priv(netdev);
  158. struct vnic_stats *vstats;
  159. unsigned int i;
  160. enic_dev_stats_dump(enic, &vstats);
  161. for (i = 0; i < enic_n_tx_stats; i++)
  162. *(data++) = ((u64 *)&vstats->tx)[enic_tx_stats[i].index];
  163. for (i = 0; i < enic_n_rx_stats; i++)
  164. *(data++) = ((u64 *)&vstats->rx)[enic_rx_stats[i].index];
  165. for (i = 0; i < enic_n_gen_stats; i++)
  166. *(data++) = ((u64 *)&enic->gen_stats)[enic_gen_stats[i].index];
  167. }
  168. static u32 enic_get_msglevel(struct net_device *netdev)
  169. {
  170. struct enic *enic = netdev_priv(netdev);
  171. return enic->msg_enable;
  172. }
  173. static void enic_set_msglevel(struct net_device *netdev, u32 value)
  174. {
  175. struct enic *enic = netdev_priv(netdev);
  176. enic->msg_enable = value;
  177. }
  178. static int enic_get_coalesce(struct net_device *netdev,
  179. struct ethtool_coalesce *ecmd)
  180. {
  181. struct enic *enic = netdev_priv(netdev);
  182. struct enic_rx_coal *rxcoal = &enic->rx_coalesce_setting;
  183. ecmd->tx_coalesce_usecs = enic->tx_coalesce_usecs;
  184. ecmd->rx_coalesce_usecs = enic->rx_coalesce_usecs;
  185. if (rxcoal->use_adaptive_rx_coalesce)
  186. ecmd->use_adaptive_rx_coalesce = 1;
  187. ecmd->rx_coalesce_usecs_low = rxcoal->small_pkt_range_start;
  188. ecmd->rx_coalesce_usecs_high = rxcoal->range_end;
  189. return 0;
  190. }
  191. static int enic_set_coalesce(struct net_device *netdev,
  192. struct ethtool_coalesce *ecmd)
  193. {
  194. struct enic *enic = netdev_priv(netdev);
  195. u32 tx_coalesce_usecs;
  196. u32 rx_coalesce_usecs;
  197. u32 rx_coalesce_usecs_low;
  198. u32 rx_coalesce_usecs_high;
  199. u32 coalesce_usecs_max;
  200. unsigned int i, intr;
  201. struct enic_rx_coal *rxcoal = &enic->rx_coalesce_setting;
  202. coalesce_usecs_max = vnic_dev_get_intr_coal_timer_max(enic->vdev);
  203. tx_coalesce_usecs = min_t(u32, ecmd->tx_coalesce_usecs,
  204. coalesce_usecs_max);
  205. rx_coalesce_usecs = min_t(u32, ecmd->rx_coalesce_usecs,
  206. coalesce_usecs_max);
  207. rx_coalesce_usecs_low = min_t(u32, ecmd->rx_coalesce_usecs_low,
  208. coalesce_usecs_max);
  209. rx_coalesce_usecs_high = min_t(u32, ecmd->rx_coalesce_usecs_high,
  210. coalesce_usecs_max);
  211. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  212. case VNIC_DEV_INTR_MODE_INTX:
  213. if (tx_coalesce_usecs != rx_coalesce_usecs)
  214. return -EINVAL;
  215. if (ecmd->use_adaptive_rx_coalesce ||
  216. ecmd->rx_coalesce_usecs_low ||
  217. ecmd->rx_coalesce_usecs_high)
  218. return -EINVAL;
  219. intr = enic_legacy_io_intr();
  220. vnic_intr_coalescing_timer_set(&enic->intr[intr],
  221. tx_coalesce_usecs);
  222. break;
  223. case VNIC_DEV_INTR_MODE_MSI:
  224. if (tx_coalesce_usecs != rx_coalesce_usecs)
  225. return -EINVAL;
  226. if (ecmd->use_adaptive_rx_coalesce ||
  227. ecmd->rx_coalesce_usecs_low ||
  228. ecmd->rx_coalesce_usecs_high)
  229. return -EINVAL;
  230. vnic_intr_coalescing_timer_set(&enic->intr[0],
  231. tx_coalesce_usecs);
  232. break;
  233. case VNIC_DEV_INTR_MODE_MSIX:
  234. if (ecmd->rx_coalesce_usecs_high &&
  235. (rx_coalesce_usecs_high <
  236. rx_coalesce_usecs_low + ENIC_AIC_LARGE_PKT_DIFF))
  237. return -EINVAL;
  238. for (i = 0; i < enic->wq_count; i++) {
  239. intr = enic_msix_wq_intr(enic, i);
  240. vnic_intr_coalescing_timer_set(&enic->intr[intr],
  241. tx_coalesce_usecs);
  242. }
  243. rxcoal->use_adaptive_rx_coalesce =
  244. !!ecmd->use_adaptive_rx_coalesce;
  245. if (!rxcoal->use_adaptive_rx_coalesce)
  246. enic_intr_coal_set_rx(enic, rx_coalesce_usecs);
  247. if (ecmd->rx_coalesce_usecs_high) {
  248. rxcoal->range_end = rx_coalesce_usecs_high;
  249. rxcoal->small_pkt_range_start = rx_coalesce_usecs_low;
  250. rxcoal->large_pkt_range_start = rx_coalesce_usecs_low +
  251. ENIC_AIC_LARGE_PKT_DIFF;
  252. }
  253. break;
  254. default:
  255. break;
  256. }
  257. enic->tx_coalesce_usecs = tx_coalesce_usecs;
  258. enic->rx_coalesce_usecs = rx_coalesce_usecs;
  259. return 0;
  260. }
  261. static int enic_grxclsrlall(struct enic *enic, struct ethtool_rxnfc *cmd,
  262. u32 *rule_locs)
  263. {
  264. int j, ret = 0, cnt = 0;
  265. cmd->data = enic->rfs_h.max - enic->rfs_h.free;
  266. for (j = 0; j < (1 << ENIC_RFS_FLW_BITSHIFT); j++) {
  267. struct hlist_head *hhead;
  268. struct hlist_node *tmp;
  269. struct enic_rfs_fltr_node *n;
  270. hhead = &enic->rfs_h.ht_head[j];
  271. hlist_for_each_entry_safe(n, tmp, hhead, node) {
  272. if (cnt == cmd->rule_cnt)
  273. return -EMSGSIZE;
  274. rule_locs[cnt] = n->fltr_id;
  275. cnt++;
  276. }
  277. }
  278. cmd->rule_cnt = cnt;
  279. return ret;
  280. }
  281. static int enic_grxclsrule(struct enic *enic, struct ethtool_rxnfc *cmd)
  282. {
  283. struct ethtool_rx_flow_spec *fsp =
  284. (struct ethtool_rx_flow_spec *)&cmd->fs;
  285. struct enic_rfs_fltr_node *n;
  286. n = htbl_fltr_search(enic, (u16)fsp->location);
  287. if (!n)
  288. return -EINVAL;
  289. switch (n->keys.ip_proto) {
  290. case IPPROTO_TCP:
  291. fsp->flow_type = TCP_V4_FLOW;
  292. break;
  293. case IPPROTO_UDP:
  294. fsp->flow_type = UDP_V4_FLOW;
  295. break;
  296. default:
  297. return -EINVAL;
  298. break;
  299. }
  300. fsp->h_u.tcp_ip4_spec.ip4src = n->keys.src;
  301. fsp->m_u.tcp_ip4_spec.ip4src = (__u32)~0;
  302. fsp->h_u.tcp_ip4_spec.ip4dst = n->keys.dst;
  303. fsp->m_u.tcp_ip4_spec.ip4dst = (__u32)~0;
  304. fsp->h_u.tcp_ip4_spec.psrc = n->keys.port16[0];
  305. fsp->m_u.tcp_ip4_spec.psrc = (__u16)~0;
  306. fsp->h_u.tcp_ip4_spec.pdst = n->keys.port16[1];
  307. fsp->m_u.tcp_ip4_spec.pdst = (__u16)~0;
  308. fsp->ring_cookie = n->rq_id;
  309. return 0;
  310. }
  311. static int enic_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
  312. u32 *rule_locs)
  313. {
  314. struct enic *enic = netdev_priv(dev);
  315. int ret = 0;
  316. switch (cmd->cmd) {
  317. case ETHTOOL_GRXRINGS:
  318. cmd->data = enic->rq_count;
  319. break;
  320. case ETHTOOL_GRXCLSRLCNT:
  321. spin_lock_bh(&enic->rfs_h.lock);
  322. cmd->rule_cnt = enic->rfs_h.max - enic->rfs_h.free;
  323. cmd->data = enic->rfs_h.max;
  324. spin_unlock_bh(&enic->rfs_h.lock);
  325. break;
  326. case ETHTOOL_GRXCLSRLALL:
  327. spin_lock_bh(&enic->rfs_h.lock);
  328. ret = enic_grxclsrlall(enic, cmd, rule_locs);
  329. spin_unlock_bh(&enic->rfs_h.lock);
  330. break;
  331. case ETHTOOL_GRXCLSRULE:
  332. spin_lock_bh(&enic->rfs_h.lock);
  333. ret = enic_grxclsrule(enic, cmd);
  334. spin_unlock_bh(&enic->rfs_h.lock);
  335. break;
  336. default:
  337. ret = -EOPNOTSUPP;
  338. break;
  339. }
  340. return ret;
  341. }
  342. static int enic_get_tunable(struct net_device *dev,
  343. const struct ethtool_tunable *tuna, void *data)
  344. {
  345. struct enic *enic = netdev_priv(dev);
  346. int ret = 0;
  347. switch (tuna->id) {
  348. case ETHTOOL_RX_COPYBREAK:
  349. *(u32 *)data = enic->rx_copybreak;
  350. break;
  351. default:
  352. ret = -EINVAL;
  353. break;
  354. }
  355. return ret;
  356. }
  357. static int enic_set_tunable(struct net_device *dev,
  358. const struct ethtool_tunable *tuna,
  359. const void *data)
  360. {
  361. struct enic *enic = netdev_priv(dev);
  362. int ret = 0;
  363. switch (tuna->id) {
  364. case ETHTOOL_RX_COPYBREAK:
  365. enic->rx_copybreak = *(u32 *)data;
  366. break;
  367. default:
  368. ret = -EINVAL;
  369. break;
  370. }
  371. return ret;
  372. }
  373. static u32 enic_get_rxfh_key_size(struct net_device *netdev)
  374. {
  375. return ENIC_RSS_LEN;
  376. }
  377. static int enic_get_rxfh(struct net_device *netdev, u32 *indir, u8 *hkey,
  378. u8 *hfunc)
  379. {
  380. struct enic *enic = netdev_priv(netdev);
  381. if (hkey)
  382. memcpy(hkey, enic->rss_key, ENIC_RSS_LEN);
  383. if (hfunc)
  384. *hfunc = ETH_RSS_HASH_TOP;
  385. return 0;
  386. }
  387. static int enic_set_rxfh(struct net_device *netdev, const u32 *indir,
  388. const u8 *hkey, const u8 hfunc)
  389. {
  390. struct enic *enic = netdev_priv(netdev);
  391. if ((hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) ||
  392. indir)
  393. return -EINVAL;
  394. if (hkey)
  395. memcpy(enic->rss_key, hkey, ENIC_RSS_LEN);
  396. return __enic_set_rsskey(enic);
  397. }
  398. static const struct ethtool_ops enic_ethtool_ops = {
  399. .get_settings = enic_get_settings,
  400. .get_drvinfo = enic_get_drvinfo,
  401. .get_msglevel = enic_get_msglevel,
  402. .set_msglevel = enic_set_msglevel,
  403. .get_link = ethtool_op_get_link,
  404. .get_strings = enic_get_strings,
  405. .get_sset_count = enic_get_sset_count,
  406. .get_ethtool_stats = enic_get_ethtool_stats,
  407. .get_coalesce = enic_get_coalesce,
  408. .set_coalesce = enic_set_coalesce,
  409. .get_rxnfc = enic_get_rxnfc,
  410. .get_tunable = enic_get_tunable,
  411. .set_tunable = enic_set_tunable,
  412. .get_rxfh_key_size = enic_get_rxfh_key_size,
  413. .get_rxfh = enic_get_rxfh,
  414. .set_rxfh = enic_set_rxfh,
  415. };
  416. void enic_set_ethtool_ops(struct net_device *netdev)
  417. {
  418. netdev->ethtool_ops = &enic_ethtool_ops;
  419. }