qlge_ethtool.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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. /* Skip the default queue, and update the outbound handler
  44. * queues if they changed.
  45. */
  46. cqicb = (struct cqicb *)&qdev->rx_ring[qdev->rss_ring_count];
  47. if (le16_to_cpu(cqicb->irq_delay) != qdev->tx_coalesce_usecs ||
  48. le16_to_cpu(cqicb->pkt_delay) !=
  49. qdev->tx_max_coalesced_frames) {
  50. for (i = qdev->rss_ring_count; i < qdev->rx_ring_count; i++) {
  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[0];
  68. if (le16_to_cpu(cqicb->irq_delay) != qdev->rx_coalesce_usecs ||
  69. le16_to_cpu(cqicb->pkt_delay) !=
  70. qdev->rx_max_coalesced_frames) {
  71. for (i = 0; i < qdev->rss_ring_count; i++, rx_ring++) {
  72. rx_ring = &qdev->rx_ring[i];
  73. cqicb = (struct cqicb *)rx_ring;
  74. cqicb->irq_delay = cpu_to_le16(qdev->rx_coalesce_usecs);
  75. cqicb->pkt_delay =
  76. cpu_to_le16(qdev->rx_max_coalesced_frames);
  77. cqicb->flags = FLAGS_LI;
  78. status = ql_write_cfg(qdev, cqicb, sizeof(*cqicb),
  79. CFG_LCQ, rx_ring->cq_id);
  80. if (status) {
  81. QPRINTK(qdev, IFUP, ERR,
  82. "Failed to load CQICB.\n");
  83. goto exit;
  84. }
  85. }
  86. }
  87. exit:
  88. return status;
  89. }
  90. static void ql_update_stats(struct ql_adapter *qdev)
  91. {
  92. u32 i;
  93. u64 data;
  94. u64 *iter = &qdev->nic_stats.tx_pkts;
  95. spin_lock(&qdev->stats_lock);
  96. if (ql_sem_spinlock(qdev, qdev->xg_sem_mask)) {
  97. QPRINTK(qdev, DRV, ERR,
  98. "Couldn't get xgmac sem.\n");
  99. goto quit;
  100. }
  101. /*
  102. * Get TX statistics.
  103. */
  104. for (i = 0x200; i < 0x280; i += 8) {
  105. if (ql_read_xgmac_reg64(qdev, i, &data)) {
  106. QPRINTK(qdev, DRV, ERR,
  107. "Error reading status register 0x%.04x.\n", i);
  108. goto end;
  109. } else
  110. *iter = data;
  111. iter++;
  112. }
  113. /*
  114. * Get RX statistics.
  115. */
  116. for (i = 0x300; i < 0x3d0; i += 8) {
  117. if (ql_read_xgmac_reg64(qdev, i, &data)) {
  118. QPRINTK(qdev, DRV, ERR,
  119. "Error reading status register 0x%.04x.\n", i);
  120. goto end;
  121. } else
  122. *iter = data;
  123. iter++;
  124. }
  125. end:
  126. ql_sem_unlock(qdev, qdev->xg_sem_mask);
  127. quit:
  128. spin_unlock(&qdev->stats_lock);
  129. QL_DUMP_STAT(qdev);
  130. return;
  131. }
  132. static char ql_stats_str_arr[][ETH_GSTRING_LEN] = {
  133. {"tx_pkts"},
  134. {"tx_bytes"},
  135. {"tx_mcast_pkts"},
  136. {"tx_bcast_pkts"},
  137. {"tx_ucast_pkts"},
  138. {"tx_ctl_pkts"},
  139. {"tx_pause_pkts"},
  140. {"tx_64_pkts"},
  141. {"tx_65_to_127_pkts"},
  142. {"tx_128_to_255_pkts"},
  143. {"tx_256_511_pkts"},
  144. {"tx_512_to_1023_pkts"},
  145. {"tx_1024_to_1518_pkts"},
  146. {"tx_1519_to_max_pkts"},
  147. {"tx_undersize_pkts"},
  148. {"tx_oversize_pkts"},
  149. {"rx_bytes"},
  150. {"rx_bytes_ok"},
  151. {"rx_pkts"},
  152. {"rx_pkts_ok"},
  153. {"rx_bcast_pkts"},
  154. {"rx_mcast_pkts"},
  155. {"rx_ucast_pkts"},
  156. {"rx_undersize_pkts"},
  157. {"rx_oversize_pkts"},
  158. {"rx_jabber_pkts"},
  159. {"rx_undersize_fcerr_pkts"},
  160. {"rx_drop_events"},
  161. {"rx_fcerr_pkts"},
  162. {"rx_align_err"},
  163. {"rx_symbol_err"},
  164. {"rx_mac_err"},
  165. {"rx_ctl_pkts"},
  166. {"rx_pause_pkts"},
  167. {"rx_64_pkts"},
  168. {"rx_65_to_127_pkts"},
  169. {"rx_128_255_pkts"},
  170. {"rx_256_511_pkts"},
  171. {"rx_512_to_1023_pkts"},
  172. {"rx_1024_to_1518_pkts"},
  173. {"rx_1519_to_max_pkts"},
  174. {"rx_len_err_pkts"},
  175. };
  176. static void ql_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  177. {
  178. switch (stringset) {
  179. case ETH_SS_STATS:
  180. memcpy(buf, ql_stats_str_arr, sizeof(ql_stats_str_arr));
  181. break;
  182. }
  183. }
  184. static int ql_get_sset_count(struct net_device *dev, int sset)
  185. {
  186. switch (sset) {
  187. case ETH_SS_STATS:
  188. return ARRAY_SIZE(ql_stats_str_arr);
  189. default:
  190. return -EOPNOTSUPP;
  191. }
  192. }
  193. static void
  194. ql_get_ethtool_stats(struct net_device *ndev,
  195. struct ethtool_stats *stats, u64 *data)
  196. {
  197. struct ql_adapter *qdev = netdev_priv(ndev);
  198. struct nic_stats *s = &qdev->nic_stats;
  199. ql_update_stats(qdev);
  200. *data++ = s->tx_pkts;
  201. *data++ = s->tx_bytes;
  202. *data++ = s->tx_mcast_pkts;
  203. *data++ = s->tx_bcast_pkts;
  204. *data++ = s->tx_ucast_pkts;
  205. *data++ = s->tx_ctl_pkts;
  206. *data++ = s->tx_pause_pkts;
  207. *data++ = s->tx_64_pkt;
  208. *data++ = s->tx_65_to_127_pkt;
  209. *data++ = s->tx_128_to_255_pkt;
  210. *data++ = s->tx_256_511_pkt;
  211. *data++ = s->tx_512_to_1023_pkt;
  212. *data++ = s->tx_1024_to_1518_pkt;
  213. *data++ = s->tx_1519_to_max_pkt;
  214. *data++ = s->tx_undersize_pkt;
  215. *data++ = s->tx_oversize_pkt;
  216. *data++ = s->rx_bytes;
  217. *data++ = s->rx_bytes_ok;
  218. *data++ = s->rx_pkts;
  219. *data++ = s->rx_pkts_ok;
  220. *data++ = s->rx_bcast_pkts;
  221. *data++ = s->rx_mcast_pkts;
  222. *data++ = s->rx_ucast_pkts;
  223. *data++ = s->rx_undersize_pkts;
  224. *data++ = s->rx_oversize_pkts;
  225. *data++ = s->rx_jabber_pkts;
  226. *data++ = s->rx_undersize_fcerr_pkts;
  227. *data++ = s->rx_drop_events;
  228. *data++ = s->rx_fcerr_pkts;
  229. *data++ = s->rx_align_err;
  230. *data++ = s->rx_symbol_err;
  231. *data++ = s->rx_mac_err;
  232. *data++ = s->rx_ctl_pkts;
  233. *data++ = s->rx_pause_pkts;
  234. *data++ = s->rx_64_pkts;
  235. *data++ = s->rx_65_to_127_pkts;
  236. *data++ = s->rx_128_255_pkts;
  237. *data++ = s->rx_256_511_pkts;
  238. *data++ = s->rx_512_to_1023_pkts;
  239. *data++ = s->rx_1024_to_1518_pkts;
  240. *data++ = s->rx_1519_to_max_pkts;
  241. *data++ = s->rx_len_err_pkts;
  242. }
  243. static int ql_get_settings(struct net_device *ndev,
  244. struct ethtool_cmd *ecmd)
  245. {
  246. struct ql_adapter *qdev = netdev_priv(ndev);
  247. ecmd->supported = SUPPORTED_10000baseT_Full;
  248. ecmd->advertising = ADVERTISED_10000baseT_Full;
  249. ecmd->autoneg = AUTONEG_ENABLE;
  250. ecmd->transceiver = XCVR_EXTERNAL;
  251. if ((qdev->link_status & STS_LINK_TYPE_MASK) ==
  252. STS_LINK_TYPE_10GBASET) {
  253. ecmd->supported |= (SUPPORTED_TP | SUPPORTED_Autoneg);
  254. ecmd->advertising |= (ADVERTISED_TP | ADVERTISED_Autoneg);
  255. ecmd->port = PORT_TP;
  256. } else {
  257. ecmd->supported |= SUPPORTED_FIBRE;
  258. ecmd->advertising |= ADVERTISED_FIBRE;
  259. ecmd->port = PORT_FIBRE;
  260. }
  261. ecmd->speed = SPEED_10000;
  262. ecmd->duplex = DUPLEX_FULL;
  263. return 0;
  264. }
  265. static void ql_get_drvinfo(struct net_device *ndev,
  266. struct ethtool_drvinfo *drvinfo)
  267. {
  268. struct ql_adapter *qdev = netdev_priv(ndev);
  269. strncpy(drvinfo->driver, qlge_driver_name, 32);
  270. strncpy(drvinfo->version, qlge_driver_version, 32);
  271. snprintf(drvinfo->fw_version, 32, "v%d.%d.%d",
  272. (qdev->fw_rev_id & 0x00ff0000) >> 16,
  273. (qdev->fw_rev_id & 0x0000ff00) >> 8,
  274. (qdev->fw_rev_id & 0x000000ff));
  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. .set_tx_csum = ethtool_op_set_tx_csum,
  367. .get_sg = ethtool_op_get_sg,
  368. .set_sg = ethtool_op_set_sg,
  369. .get_tso = ethtool_op_get_tso,
  370. .set_tso = ql_set_tso,
  371. .get_coalesce = ql_get_coalesce,
  372. .set_coalesce = ql_set_coalesce,
  373. .get_sset_count = ql_get_sset_count,
  374. .get_strings = ql_get_strings,
  375. .get_ethtool_stats = ql_get_ethtool_stats,
  376. };