qlge_ethtool.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. #include <linux/kernel.h>
  2. #include <linux/init.h>
  3. #include <linux/types.h>
  4. #include <linux/module.h>
  5. #include <linux/list.h>
  6. #include <linux/pci.h>
  7. #include <linux/dma-mapping.h>
  8. #include <linux/pagemap.h>
  9. #include <linux/sched.h>
  10. #include <linux/slab.h>
  11. #include <linux/dmapool.h>
  12. #include <linux/mempool.h>
  13. #include <linux/spinlock.h>
  14. #include <linux/kthread.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/errno.h>
  17. #include <linux/ioport.h>
  18. #include <linux/in.h>
  19. #include <linux/ip.h>
  20. #include <linux/ipv6.h>
  21. #include <net/ipv6.h>
  22. #include <linux/tcp.h>
  23. #include <linux/udp.h>
  24. #include <linux/if_arp.h>
  25. #include <linux/if_ether.h>
  26. #include <linux/netdevice.h>
  27. #include <linux/etherdevice.h>
  28. #include <linux/ethtool.h>
  29. #include <linux/skbuff.h>
  30. #include <linux/rtnetlink.h>
  31. #include <linux/if_vlan.h>
  32. #include <linux/init.h>
  33. #include <linux/delay.h>
  34. #include <linux/mm.h>
  35. #include <linux/vmalloc.h>
  36. #include <linux/version.h>
  37. #include "qlge.h"
  38. static int ql_update_ring_coalescing(struct ql_adapter *qdev)
  39. {
  40. int i, status = 0;
  41. struct rx_ring *rx_ring;
  42. struct cqicb *cqicb;
  43. if (!netif_running(qdev->ndev))
  44. return status;
  45. spin_lock(&qdev->hw_lock);
  46. /* Skip the default queue, and update the outbound handler
  47. * queues if they changed.
  48. */
  49. cqicb = (struct cqicb *)&qdev->rx_ring[1];
  50. if (le16_to_cpu(cqicb->irq_delay) != qdev->tx_coalesce_usecs ||
  51. le16_to_cpu(cqicb->pkt_delay) != qdev->tx_max_coalesced_frames) {
  52. for (i = 1; i < qdev->rss_ring_first_cq_id; i++, rx_ring++) {
  53. rx_ring = &qdev->rx_ring[i];
  54. cqicb = (struct cqicb *)rx_ring;
  55. cqicb->irq_delay = le16_to_cpu(qdev->tx_coalesce_usecs);
  56. cqicb->pkt_delay =
  57. le16_to_cpu(qdev->tx_max_coalesced_frames);
  58. cqicb->flags = FLAGS_LI;
  59. status = ql_write_cfg(qdev, cqicb, sizeof(cqicb),
  60. CFG_LCQ, rx_ring->cq_id);
  61. if (status) {
  62. QPRINTK(qdev, IFUP, ERR,
  63. "Failed to load CQICB.\n");
  64. goto exit;
  65. }
  66. }
  67. }
  68. /* Update the inbound (RSS) handler queues if they changed. */
  69. cqicb = (struct cqicb *)&qdev->rx_ring[qdev->rss_ring_first_cq_id];
  70. if (le16_to_cpu(cqicb->irq_delay) != qdev->rx_coalesce_usecs ||
  71. le16_to_cpu(cqicb->pkt_delay) != qdev->rx_max_coalesced_frames) {
  72. for (i = qdev->rss_ring_first_cq_id;
  73. i <= qdev->rss_ring_first_cq_id + qdev->rss_ring_count;
  74. i++) {
  75. rx_ring = &qdev->rx_ring[i];
  76. cqicb = (struct cqicb *)rx_ring;
  77. cqicb->irq_delay = le16_to_cpu(qdev->rx_coalesce_usecs);
  78. cqicb->pkt_delay =
  79. le16_to_cpu(qdev->rx_max_coalesced_frames);
  80. cqicb->flags = FLAGS_LI;
  81. status = ql_write_cfg(qdev, cqicb, sizeof(cqicb),
  82. CFG_LCQ, rx_ring->cq_id);
  83. if (status) {
  84. QPRINTK(qdev, IFUP, ERR,
  85. "Failed to load CQICB.\n");
  86. goto exit;
  87. }
  88. }
  89. }
  90. exit:
  91. spin_unlock(&qdev->hw_lock);
  92. return status;
  93. }
  94. void ql_update_stats(struct ql_adapter *qdev)
  95. {
  96. u32 i;
  97. u64 data;
  98. u64 *iter = &qdev->nic_stats.tx_pkts;
  99. spin_lock(&qdev->stats_lock);
  100. if (ql_sem_spinlock(qdev, qdev->xg_sem_mask)) {
  101. QPRINTK(qdev, DRV, ERR,
  102. "Couldn't get xgmac sem.\n");
  103. goto quit;
  104. }
  105. /*
  106. * Get TX statistics.
  107. */
  108. for (i = 0x200; i < 0x280; i += 8) {
  109. if (ql_read_xgmac_reg64(qdev, i, &data)) {
  110. QPRINTK(qdev, DRV, ERR,
  111. "Error reading status register 0x%.04x.\n", i);
  112. goto end;
  113. } else
  114. *iter = data;
  115. iter++;
  116. }
  117. /*
  118. * Get RX statistics.
  119. */
  120. for (i = 0x300; i < 0x3d0; i += 8) {
  121. if (ql_read_xgmac_reg64(qdev, i, &data)) {
  122. QPRINTK(qdev, DRV, ERR,
  123. "Error reading status register 0x%.04x.\n", i);
  124. goto end;
  125. } else
  126. *iter = data;
  127. iter++;
  128. }
  129. end:
  130. ql_sem_unlock(qdev, qdev->xg_sem_mask);
  131. quit:
  132. spin_unlock(&qdev->stats_lock);
  133. QL_DUMP_STAT(qdev);
  134. return;
  135. }
  136. static char ql_stats_str_arr[][ETH_GSTRING_LEN] = {
  137. {"tx_pkts"},
  138. {"tx_bytes"},
  139. {"tx_mcast_pkts"},
  140. {"tx_bcast_pkts"},
  141. {"tx_ucast_pkts"},
  142. {"tx_ctl_pkts"},
  143. {"tx_pause_pkts"},
  144. {"tx_64_pkts"},
  145. {"tx_65_to_127_pkts"},
  146. {"tx_128_to_255_pkts"},
  147. {"tx_256_511_pkts"},
  148. {"tx_512_to_1023_pkts"},
  149. {"tx_1024_to_1518_pkts"},
  150. {"tx_1519_to_max_pkts"},
  151. {"tx_undersize_pkts"},
  152. {"tx_oversize_pkts"},
  153. {"rx_bytes"},
  154. {"rx_bytes_ok"},
  155. {"rx_pkts"},
  156. {"rx_pkts_ok"},
  157. {"rx_bcast_pkts"},
  158. {"rx_mcast_pkts"},
  159. {"rx_ucast_pkts"},
  160. {"rx_undersize_pkts"},
  161. {"rx_oversize_pkts"},
  162. {"rx_jabber_pkts"},
  163. {"rx_undersize_fcerr_pkts"},
  164. {"rx_drop_events"},
  165. {"rx_fcerr_pkts"},
  166. {"rx_align_err"},
  167. {"rx_symbol_err"},
  168. {"rx_mac_err"},
  169. {"rx_ctl_pkts"},
  170. {"rx_pause_pkts"},
  171. {"rx_64_pkts"},
  172. {"rx_65_to_127_pkts"},
  173. {"rx_128_255_pkts"},
  174. {"rx_256_511_pkts"},
  175. {"rx_512_to_1023_pkts"},
  176. {"rx_1024_to_1518_pkts"},
  177. {"rx_1519_to_max_pkts"},
  178. {"rx_len_err_pkts"},
  179. };
  180. static void ql_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  181. {
  182. switch (stringset) {
  183. case ETH_SS_STATS:
  184. memcpy(buf, ql_stats_str_arr, sizeof(ql_stats_str_arr));
  185. break;
  186. }
  187. }
  188. static int ql_get_sset_count(struct net_device *dev, int sset)
  189. {
  190. switch (sset) {
  191. case ETH_SS_STATS:
  192. return ARRAY_SIZE(ql_stats_str_arr);
  193. default:
  194. return -EOPNOTSUPP;
  195. }
  196. }
  197. static void
  198. ql_get_ethtool_stats(struct net_device *ndev,
  199. struct ethtool_stats *stats, u64 *data)
  200. {
  201. struct ql_adapter *qdev = netdev_priv(ndev);
  202. struct nic_stats *s = &qdev->nic_stats;
  203. ql_update_stats(qdev);
  204. *data++ = s->tx_pkts;
  205. *data++ = s->tx_bytes;
  206. *data++ = s->tx_mcast_pkts;
  207. *data++ = s->tx_bcast_pkts;
  208. *data++ = s->tx_ucast_pkts;
  209. *data++ = s->tx_ctl_pkts;
  210. *data++ = s->tx_pause_pkts;
  211. *data++ = s->tx_64_pkt;
  212. *data++ = s->tx_65_to_127_pkt;
  213. *data++ = s->tx_128_to_255_pkt;
  214. *data++ = s->tx_256_511_pkt;
  215. *data++ = s->tx_512_to_1023_pkt;
  216. *data++ = s->tx_1024_to_1518_pkt;
  217. *data++ = s->tx_1519_to_max_pkt;
  218. *data++ = s->tx_undersize_pkt;
  219. *data++ = s->tx_oversize_pkt;
  220. *data++ = s->rx_bytes;
  221. *data++ = s->rx_bytes_ok;
  222. *data++ = s->rx_pkts;
  223. *data++ = s->rx_pkts_ok;
  224. *data++ = s->rx_bcast_pkts;
  225. *data++ = s->rx_mcast_pkts;
  226. *data++ = s->rx_ucast_pkts;
  227. *data++ = s->rx_undersize_pkts;
  228. *data++ = s->rx_oversize_pkts;
  229. *data++ = s->rx_jabber_pkts;
  230. *data++ = s->rx_undersize_fcerr_pkts;
  231. *data++ = s->rx_drop_events;
  232. *data++ = s->rx_fcerr_pkts;
  233. *data++ = s->rx_align_err;
  234. *data++ = s->rx_symbol_err;
  235. *data++ = s->rx_mac_err;
  236. *data++ = s->rx_ctl_pkts;
  237. *data++ = s->rx_pause_pkts;
  238. *data++ = s->rx_64_pkts;
  239. *data++ = s->rx_65_to_127_pkts;
  240. *data++ = s->rx_128_255_pkts;
  241. *data++ = s->rx_256_511_pkts;
  242. *data++ = s->rx_512_to_1023_pkts;
  243. *data++ = s->rx_1024_to_1518_pkts;
  244. *data++ = s->rx_1519_to_max_pkts;
  245. *data++ = s->rx_len_err_pkts;
  246. }
  247. static int ql_get_settings(struct net_device *ndev,
  248. struct ethtool_cmd *ecmd)
  249. {
  250. struct ql_adapter *qdev = netdev_priv(ndev);
  251. ecmd->supported = SUPPORTED_10000baseT_Full;
  252. ecmd->advertising = ADVERTISED_10000baseT_Full;
  253. ecmd->autoneg = AUTONEG_ENABLE;
  254. ecmd->transceiver = XCVR_EXTERNAL;
  255. if ((qdev->link_status & LINK_TYPE_MASK) == LINK_TYPE_10GBASET) {
  256. ecmd->supported |= (SUPPORTED_TP | SUPPORTED_Autoneg);
  257. ecmd->advertising |= (ADVERTISED_TP | ADVERTISED_Autoneg);
  258. ecmd->port = PORT_TP;
  259. } else {
  260. ecmd->supported |= SUPPORTED_FIBRE;
  261. ecmd->advertising |= ADVERTISED_FIBRE;
  262. ecmd->port = PORT_FIBRE;
  263. }
  264. ecmd->speed = SPEED_10000;
  265. ecmd->duplex = DUPLEX_FULL;
  266. return 0;
  267. }
  268. static void ql_get_drvinfo(struct net_device *ndev,
  269. struct ethtool_drvinfo *drvinfo)
  270. {
  271. struct ql_adapter *qdev = netdev_priv(ndev);
  272. strncpy(drvinfo->driver, qlge_driver_name, 32);
  273. strncpy(drvinfo->version, qlge_driver_version, 32);
  274. strncpy(drvinfo->fw_version, "N/A", 32);
  275. strncpy(drvinfo->bus_info, pci_name(qdev->pdev), 32);
  276. drvinfo->n_stats = 0;
  277. drvinfo->testinfo_len = 0;
  278. drvinfo->regdump_len = 0;
  279. drvinfo->eedump_len = 0;
  280. }
  281. static int ql_get_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
  282. {
  283. struct ql_adapter *qdev = netdev_priv(dev);
  284. c->rx_coalesce_usecs = qdev->rx_coalesce_usecs;
  285. c->tx_coalesce_usecs = qdev->tx_coalesce_usecs;
  286. /* This chip coalesces as follows:
  287. * If a packet arrives, hold off interrupts until
  288. * cqicb->int_delay expires, but if no other packets arrive don't
  289. * wait longer than cqicb->pkt_int_delay. But ethtool doesn't use a
  290. * timer to coalesce on a frame basis. So, we have to take ethtool's
  291. * max_coalesced_frames value and convert it to a delay in microseconds.
  292. * We do this by using a basic thoughput of 1,000,000 frames per
  293. * second @ (1024 bytes). This means one frame per usec. So it's a
  294. * simple one to one ratio.
  295. */
  296. c->rx_max_coalesced_frames = qdev->rx_max_coalesced_frames;
  297. c->tx_max_coalesced_frames = qdev->tx_max_coalesced_frames;
  298. return 0;
  299. }
  300. static int ql_set_coalesce(struct net_device *ndev, struct ethtool_coalesce *c)
  301. {
  302. struct ql_adapter *qdev = netdev_priv(ndev);
  303. /* Validate user parameters. */
  304. if (c->rx_coalesce_usecs > qdev->rx_ring_size / 2)
  305. return -EINVAL;
  306. /* Don't wait more than 10 usec. */
  307. if (c->rx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
  308. return -EINVAL;
  309. if (c->tx_coalesce_usecs > qdev->tx_ring_size / 2)
  310. return -EINVAL;
  311. if (c->tx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
  312. return -EINVAL;
  313. /* Verify a change took place before updating the hardware. */
  314. if (qdev->rx_coalesce_usecs == c->rx_coalesce_usecs &&
  315. qdev->tx_coalesce_usecs == c->tx_coalesce_usecs &&
  316. qdev->rx_max_coalesced_frames == c->rx_max_coalesced_frames &&
  317. qdev->tx_max_coalesced_frames == c->tx_max_coalesced_frames)
  318. return 0;
  319. qdev->rx_coalesce_usecs = c->rx_coalesce_usecs;
  320. qdev->tx_coalesce_usecs = c->tx_coalesce_usecs;
  321. qdev->rx_max_coalesced_frames = c->rx_max_coalesced_frames;
  322. qdev->tx_max_coalesced_frames = c->tx_max_coalesced_frames;
  323. return ql_update_ring_coalescing(qdev);
  324. }
  325. static u32 ql_get_rx_csum(struct net_device *netdev)
  326. {
  327. struct ql_adapter *qdev = netdev_priv(netdev);
  328. return qdev->rx_csum;
  329. }
  330. static int ql_set_rx_csum(struct net_device *netdev, uint32_t data)
  331. {
  332. struct ql_adapter *qdev = netdev_priv(netdev);
  333. qdev->rx_csum = data;
  334. return 0;
  335. }
  336. static int ql_set_tso(struct net_device *ndev, uint32_t data)
  337. {
  338. if (data) {
  339. ndev->features |= NETIF_F_TSO;
  340. ndev->features |= NETIF_F_TSO6;
  341. } else {
  342. ndev->features &= ~NETIF_F_TSO;
  343. ndev->features &= ~NETIF_F_TSO6;
  344. }
  345. return 0;
  346. }
  347. static u32 ql_get_msglevel(struct net_device *ndev)
  348. {
  349. struct ql_adapter *qdev = netdev_priv(ndev);
  350. return qdev->msg_enable;
  351. }
  352. static void ql_set_msglevel(struct net_device *ndev, u32 value)
  353. {
  354. struct ql_adapter *qdev = netdev_priv(ndev);
  355. qdev->msg_enable = value;
  356. }
  357. const struct ethtool_ops qlge_ethtool_ops = {
  358. .get_settings = ql_get_settings,
  359. .get_drvinfo = ql_get_drvinfo,
  360. .get_msglevel = ql_get_msglevel,
  361. .set_msglevel = ql_set_msglevel,
  362. .get_link = ethtool_op_get_link,
  363. .get_rx_csum = ql_get_rx_csum,
  364. .set_rx_csum = ql_set_rx_csum,
  365. .get_tx_csum = ethtool_op_get_tx_csum,
  366. .get_sg = ethtool_op_get_sg,
  367. .set_sg = ethtool_op_set_sg,
  368. .get_tso = ethtool_op_get_tso,
  369. .set_tso = ql_set_tso,
  370. .get_coalesce = ql_get_coalesce,
  371. .set_coalesce = ql_set_coalesce,
  372. .get_sset_count = ql_get_sset_count,
  373. .get_strings = ql_get_strings,
  374. .get_ethtool_stats = ql_get_ethtool_stats,
  375. };