enic_ethtool.c 11 KB

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