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 "qlge.h"
  36. static int ql_update_ring_coalescing(struct ql_adapter *qdev)
  37. {
  38. int i, status = 0;
  39. struct rx_ring *rx_ring;
  40. struct cqicb *cqicb;
  41. if (!netif_running(qdev->ndev))
  42. return status;
  43. spin_lock(&qdev->hw_lock);
  44. /* Skip the default queue, and update the outbound handler
  45. * queues if they changed.
  46. */
  47. cqicb = (struct cqicb *)&qdev->rx_ring[1];
  48. if (le16_to_cpu(cqicb->irq_delay) != qdev->tx_coalesce_usecs ||
  49. le16_to_cpu(cqicb->pkt_delay) != qdev->tx_max_coalesced_frames) {
  50. for (i = 1; i < qdev->rss_ring_first_cq_id; i++, rx_ring++) {
  51. rx_ring = &qdev->rx_ring[i];
  52. cqicb = (struct cqicb *)rx_ring;
  53. cqicb->irq_delay = cpu_to_le16(qdev->tx_coalesce_usecs);
  54. cqicb->pkt_delay =
  55. cpu_to_le16(qdev->tx_max_coalesced_frames);
  56. cqicb->flags = FLAGS_LI;
  57. status = ql_write_cfg(qdev, cqicb, sizeof(cqicb),
  58. CFG_LCQ, rx_ring->cq_id);
  59. if (status) {
  60. QPRINTK(qdev, IFUP, ERR,
  61. "Failed to load CQICB.\n");
  62. goto exit;
  63. }
  64. }
  65. }
  66. /* Update the inbound (RSS) handler queues if they changed. */
  67. cqicb = (struct cqicb *)&qdev->rx_ring[qdev->rss_ring_first_cq_id];
  68. if (le16_to_cpu(cqicb->irq_delay) != qdev->rx_coalesce_usecs ||
  69. le16_to_cpu(cqicb->pkt_delay) != qdev->rx_max_coalesced_frames) {
  70. for (i = qdev->rss_ring_first_cq_id;
  71. i <= qdev->rss_ring_first_cq_id + qdev->rss_ring_count;
  72. i++) {
  73. rx_ring = &qdev->rx_ring[i];
  74. cqicb = (struct cqicb *)rx_ring;
  75. cqicb->irq_delay = cpu_to_le16(qdev->rx_coalesce_usecs);
  76. cqicb->pkt_delay =
  77. cpu_to_le16(qdev->rx_max_coalesced_frames);
  78. cqicb->flags = FLAGS_LI;
  79. status = ql_write_cfg(qdev, cqicb, sizeof(cqicb),
  80. CFG_LCQ, rx_ring->cq_id);
  81. if (status) {
  82. QPRINTK(qdev, IFUP, ERR,
  83. "Failed to load CQICB.\n");
  84. goto exit;
  85. }
  86. }
  87. }
  88. exit:
  89. spin_unlock(&qdev->hw_lock);
  90. return status;
  91. }
  92. static void ql_update_stats(struct ql_adapter *qdev)
  93. {
  94. u32 i;
  95. u64 data;
  96. u64 *iter = &qdev->nic_stats.tx_pkts;
  97. spin_lock(&qdev->stats_lock);
  98. if (ql_sem_spinlock(qdev, qdev->xg_sem_mask)) {
  99. QPRINTK(qdev, DRV, ERR,
  100. "Couldn't get xgmac sem.\n");
  101. goto quit;
  102. }
  103. /*
  104. * Get TX statistics.
  105. */
  106. for (i = 0x200; i < 0x280; i += 8) {
  107. if (ql_read_xgmac_reg64(qdev, i, &data)) {
  108. QPRINTK(qdev, DRV, ERR,
  109. "Error reading status register 0x%.04x.\n", i);
  110. goto end;
  111. } else
  112. *iter = data;
  113. iter++;
  114. }
  115. /*
  116. * Get RX statistics.
  117. */
  118. for (i = 0x300; i < 0x3d0; i += 8) {
  119. if (ql_read_xgmac_reg64(qdev, i, &data)) {
  120. QPRINTK(qdev, DRV, ERR,
  121. "Error reading status register 0x%.04x.\n", i);
  122. goto end;
  123. } else
  124. *iter = data;
  125. iter++;
  126. }
  127. end:
  128. ql_sem_unlock(qdev, qdev->xg_sem_mask);
  129. quit:
  130. spin_unlock(&qdev->stats_lock);
  131. QL_DUMP_STAT(qdev);
  132. return;
  133. }
  134. static char ql_stats_str_arr[][ETH_GSTRING_LEN] = {
  135. {"tx_pkts"},
  136. {"tx_bytes"},
  137. {"tx_mcast_pkts"},
  138. {"tx_bcast_pkts"},
  139. {"tx_ucast_pkts"},
  140. {"tx_ctl_pkts"},
  141. {"tx_pause_pkts"},
  142. {"tx_64_pkts"},
  143. {"tx_65_to_127_pkts"},
  144. {"tx_128_to_255_pkts"},
  145. {"tx_256_511_pkts"},
  146. {"tx_512_to_1023_pkts"},
  147. {"tx_1024_to_1518_pkts"},
  148. {"tx_1519_to_max_pkts"},
  149. {"tx_undersize_pkts"},
  150. {"tx_oversize_pkts"},
  151. {"rx_bytes"},
  152. {"rx_bytes_ok"},
  153. {"rx_pkts"},
  154. {"rx_pkts_ok"},
  155. {"rx_bcast_pkts"},
  156. {"rx_mcast_pkts"},
  157. {"rx_ucast_pkts"},
  158. {"rx_undersize_pkts"},
  159. {"rx_oversize_pkts"},
  160. {"rx_jabber_pkts"},
  161. {"rx_undersize_fcerr_pkts"},
  162. {"rx_drop_events"},
  163. {"rx_fcerr_pkts"},
  164. {"rx_align_err"},
  165. {"rx_symbol_err"},
  166. {"rx_mac_err"},
  167. {"rx_ctl_pkts"},
  168. {"rx_pause_pkts"},
  169. {"rx_64_pkts"},
  170. {"rx_65_to_127_pkts"},
  171. {"rx_128_255_pkts"},
  172. {"rx_256_511_pkts"},
  173. {"rx_512_to_1023_pkts"},
  174. {"rx_1024_to_1518_pkts"},
  175. {"rx_1519_to_max_pkts"},
  176. {"rx_len_err_pkts"},
  177. };
  178. static void ql_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  179. {
  180. switch (stringset) {
  181. case ETH_SS_STATS:
  182. memcpy(buf, ql_stats_str_arr, sizeof(ql_stats_str_arr));
  183. break;
  184. }
  185. }
  186. static int ql_get_sset_count(struct net_device *dev, int sset)
  187. {
  188. switch (sset) {
  189. case ETH_SS_STATS:
  190. return ARRAY_SIZE(ql_stats_str_arr);
  191. default:
  192. return -EOPNOTSUPP;
  193. }
  194. }
  195. static void
  196. ql_get_ethtool_stats(struct net_device *ndev,
  197. struct ethtool_stats *stats, u64 *data)
  198. {
  199. struct ql_adapter *qdev = netdev_priv(ndev);
  200. struct nic_stats *s = &qdev->nic_stats;
  201. ql_update_stats(qdev);
  202. *data++ = s->tx_pkts;
  203. *data++ = s->tx_bytes;
  204. *data++ = s->tx_mcast_pkts;
  205. *data++ = s->tx_bcast_pkts;
  206. *data++ = s->tx_ucast_pkts;
  207. *data++ = s->tx_ctl_pkts;
  208. *data++ = s->tx_pause_pkts;
  209. *data++ = s->tx_64_pkt;
  210. *data++ = s->tx_65_to_127_pkt;
  211. *data++ = s->tx_128_to_255_pkt;
  212. *data++ = s->tx_256_511_pkt;
  213. *data++ = s->tx_512_to_1023_pkt;
  214. *data++ = s->tx_1024_to_1518_pkt;
  215. *data++ = s->tx_1519_to_max_pkt;
  216. *data++ = s->tx_undersize_pkt;
  217. *data++ = s->tx_oversize_pkt;
  218. *data++ = s->rx_bytes;
  219. *data++ = s->rx_bytes_ok;
  220. *data++ = s->rx_pkts;
  221. *data++ = s->rx_pkts_ok;
  222. *data++ = s->rx_bcast_pkts;
  223. *data++ = s->rx_mcast_pkts;
  224. *data++ = s->rx_ucast_pkts;
  225. *data++ = s->rx_undersize_pkts;
  226. *data++ = s->rx_oversize_pkts;
  227. *data++ = s->rx_jabber_pkts;
  228. *data++ = s->rx_undersize_fcerr_pkts;
  229. *data++ = s->rx_drop_events;
  230. *data++ = s->rx_fcerr_pkts;
  231. *data++ = s->rx_align_err;
  232. *data++ = s->rx_symbol_err;
  233. *data++ = s->rx_mac_err;
  234. *data++ = s->rx_ctl_pkts;
  235. *data++ = s->rx_pause_pkts;
  236. *data++ = s->rx_64_pkts;
  237. *data++ = s->rx_65_to_127_pkts;
  238. *data++ = s->rx_128_255_pkts;
  239. *data++ = s->rx_256_511_pkts;
  240. *data++ = s->rx_512_to_1023_pkts;
  241. *data++ = s->rx_1024_to_1518_pkts;
  242. *data++ = s->rx_1519_to_max_pkts;
  243. *data++ = s->rx_len_err_pkts;
  244. }
  245. static int ql_get_settings(struct net_device *ndev,
  246. struct ethtool_cmd *ecmd)
  247. {
  248. struct ql_adapter *qdev = netdev_priv(ndev);
  249. ecmd->supported = SUPPORTED_10000baseT_Full;
  250. ecmd->advertising = ADVERTISED_10000baseT_Full;
  251. ecmd->autoneg = AUTONEG_ENABLE;
  252. ecmd->transceiver = XCVR_EXTERNAL;
  253. if ((qdev->link_status & STS_LINK_TYPE_MASK) ==
  254. STS_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. };