qlge_ethtool.c 11 KB

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