qlge_ethtool.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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. /*
  126. * Get Per-priority TX pause frame counter statistics.
  127. */
  128. for (i = 0x500; i < 0x540; i += 8) {
  129. if (ql_read_xgmac_reg64(qdev, i, &data)) {
  130. QPRINTK(qdev, DRV, ERR,
  131. "Error reading status register 0x%.04x.\n", i);
  132. goto end;
  133. } else
  134. *iter = data;
  135. iter++;
  136. }
  137. /*
  138. * Get Per-priority RX pause frame counter statistics.
  139. */
  140. for (i = 0x568; i < 0x5a8; i += 8) {
  141. if (ql_read_xgmac_reg64(qdev, i, &data)) {
  142. QPRINTK(qdev, DRV, ERR,
  143. "Error reading status register 0x%.04x.\n", i);
  144. goto end;
  145. } else
  146. *iter = data;
  147. iter++;
  148. }
  149. /*
  150. * Get RX NIC FIFO DROP statistics.
  151. */
  152. if (ql_read_xgmac_reg64(qdev, 0x5b8, &data)) {
  153. QPRINTK(qdev, DRV, ERR,
  154. "Error reading status register 0x%.04x.\n", i);
  155. goto end;
  156. } else
  157. *iter = data;
  158. end:
  159. ql_sem_unlock(qdev, qdev->xg_sem_mask);
  160. quit:
  161. spin_unlock(&qdev->stats_lock);
  162. QL_DUMP_STAT(qdev);
  163. return;
  164. }
  165. static char ql_stats_str_arr[][ETH_GSTRING_LEN] = {
  166. {"tx_pkts"},
  167. {"tx_bytes"},
  168. {"tx_mcast_pkts"},
  169. {"tx_bcast_pkts"},
  170. {"tx_ucast_pkts"},
  171. {"tx_ctl_pkts"},
  172. {"tx_pause_pkts"},
  173. {"tx_64_pkts"},
  174. {"tx_65_to_127_pkts"},
  175. {"tx_128_to_255_pkts"},
  176. {"tx_256_511_pkts"},
  177. {"tx_512_to_1023_pkts"},
  178. {"tx_1024_to_1518_pkts"},
  179. {"tx_1519_to_max_pkts"},
  180. {"tx_undersize_pkts"},
  181. {"tx_oversize_pkts"},
  182. {"rx_bytes"},
  183. {"rx_bytes_ok"},
  184. {"rx_pkts"},
  185. {"rx_pkts_ok"},
  186. {"rx_bcast_pkts"},
  187. {"rx_mcast_pkts"},
  188. {"rx_ucast_pkts"},
  189. {"rx_undersize_pkts"},
  190. {"rx_oversize_pkts"},
  191. {"rx_jabber_pkts"},
  192. {"rx_undersize_fcerr_pkts"},
  193. {"rx_drop_events"},
  194. {"rx_fcerr_pkts"},
  195. {"rx_align_err"},
  196. {"rx_symbol_err"},
  197. {"rx_mac_err"},
  198. {"rx_ctl_pkts"},
  199. {"rx_pause_pkts"},
  200. {"rx_64_pkts"},
  201. {"rx_65_to_127_pkts"},
  202. {"rx_128_255_pkts"},
  203. {"rx_256_511_pkts"},
  204. {"rx_512_to_1023_pkts"},
  205. {"rx_1024_to_1518_pkts"},
  206. {"rx_1519_to_max_pkts"},
  207. {"rx_len_err_pkts"},
  208. {"tx_cbfc_pause_frames0"},
  209. {"tx_cbfc_pause_frames1"},
  210. {"tx_cbfc_pause_frames2"},
  211. {"tx_cbfc_pause_frames3"},
  212. {"tx_cbfc_pause_frames4"},
  213. {"tx_cbfc_pause_frames5"},
  214. {"tx_cbfc_pause_frames6"},
  215. {"tx_cbfc_pause_frames7"},
  216. {"rx_cbfc_pause_frames0"},
  217. {"rx_cbfc_pause_frames1"},
  218. {"rx_cbfc_pause_frames2"},
  219. {"rx_cbfc_pause_frames3"},
  220. {"rx_cbfc_pause_frames4"},
  221. {"rx_cbfc_pause_frames5"},
  222. {"rx_cbfc_pause_frames6"},
  223. {"rx_cbfc_pause_frames7"},
  224. {"rx_nic_fifo_drop"},
  225. };
  226. static void ql_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  227. {
  228. switch (stringset) {
  229. case ETH_SS_STATS:
  230. memcpy(buf, ql_stats_str_arr, sizeof(ql_stats_str_arr));
  231. break;
  232. }
  233. }
  234. static int ql_get_sset_count(struct net_device *dev, int sset)
  235. {
  236. switch (sset) {
  237. case ETH_SS_STATS:
  238. return ARRAY_SIZE(ql_stats_str_arr);
  239. default:
  240. return -EOPNOTSUPP;
  241. }
  242. }
  243. static void
  244. ql_get_ethtool_stats(struct net_device *ndev,
  245. struct ethtool_stats *stats, u64 *data)
  246. {
  247. struct ql_adapter *qdev = netdev_priv(ndev);
  248. struct nic_stats *s = &qdev->nic_stats;
  249. ql_update_stats(qdev);
  250. *data++ = s->tx_pkts;
  251. *data++ = s->tx_bytes;
  252. *data++ = s->tx_mcast_pkts;
  253. *data++ = s->tx_bcast_pkts;
  254. *data++ = s->tx_ucast_pkts;
  255. *data++ = s->tx_ctl_pkts;
  256. *data++ = s->tx_pause_pkts;
  257. *data++ = s->tx_64_pkt;
  258. *data++ = s->tx_65_to_127_pkt;
  259. *data++ = s->tx_128_to_255_pkt;
  260. *data++ = s->tx_256_511_pkt;
  261. *data++ = s->tx_512_to_1023_pkt;
  262. *data++ = s->tx_1024_to_1518_pkt;
  263. *data++ = s->tx_1519_to_max_pkt;
  264. *data++ = s->tx_undersize_pkt;
  265. *data++ = s->tx_oversize_pkt;
  266. *data++ = s->rx_bytes;
  267. *data++ = s->rx_bytes_ok;
  268. *data++ = s->rx_pkts;
  269. *data++ = s->rx_pkts_ok;
  270. *data++ = s->rx_bcast_pkts;
  271. *data++ = s->rx_mcast_pkts;
  272. *data++ = s->rx_ucast_pkts;
  273. *data++ = s->rx_undersize_pkts;
  274. *data++ = s->rx_oversize_pkts;
  275. *data++ = s->rx_jabber_pkts;
  276. *data++ = s->rx_undersize_fcerr_pkts;
  277. *data++ = s->rx_drop_events;
  278. *data++ = s->rx_fcerr_pkts;
  279. *data++ = s->rx_align_err;
  280. *data++ = s->rx_symbol_err;
  281. *data++ = s->rx_mac_err;
  282. *data++ = s->rx_ctl_pkts;
  283. *data++ = s->rx_pause_pkts;
  284. *data++ = s->rx_64_pkts;
  285. *data++ = s->rx_65_to_127_pkts;
  286. *data++ = s->rx_128_255_pkts;
  287. *data++ = s->rx_256_511_pkts;
  288. *data++ = s->rx_512_to_1023_pkts;
  289. *data++ = s->rx_1024_to_1518_pkts;
  290. *data++ = s->rx_1519_to_max_pkts;
  291. *data++ = s->rx_len_err_pkts;
  292. *data++ = s->tx_cbfc_pause_frames0;
  293. *data++ = s->tx_cbfc_pause_frames1;
  294. *data++ = s->tx_cbfc_pause_frames2;
  295. *data++ = s->tx_cbfc_pause_frames3;
  296. *data++ = s->tx_cbfc_pause_frames4;
  297. *data++ = s->tx_cbfc_pause_frames5;
  298. *data++ = s->tx_cbfc_pause_frames6;
  299. *data++ = s->tx_cbfc_pause_frames7;
  300. *data++ = s->rx_cbfc_pause_frames0;
  301. *data++ = s->rx_cbfc_pause_frames1;
  302. *data++ = s->rx_cbfc_pause_frames2;
  303. *data++ = s->rx_cbfc_pause_frames3;
  304. *data++ = s->rx_cbfc_pause_frames4;
  305. *data++ = s->rx_cbfc_pause_frames5;
  306. *data++ = s->rx_cbfc_pause_frames6;
  307. *data++ = s->rx_cbfc_pause_frames7;
  308. *data++ = s->rx_nic_fifo_drop;
  309. }
  310. static int ql_get_settings(struct net_device *ndev,
  311. struct ethtool_cmd *ecmd)
  312. {
  313. struct ql_adapter *qdev = netdev_priv(ndev);
  314. ecmd->supported = SUPPORTED_10000baseT_Full;
  315. ecmd->advertising = ADVERTISED_10000baseT_Full;
  316. ecmd->autoneg = AUTONEG_ENABLE;
  317. ecmd->transceiver = XCVR_EXTERNAL;
  318. if ((qdev->link_status & STS_LINK_TYPE_MASK) ==
  319. STS_LINK_TYPE_10GBASET) {
  320. ecmd->supported |= (SUPPORTED_TP | SUPPORTED_Autoneg);
  321. ecmd->advertising |= (ADVERTISED_TP | ADVERTISED_Autoneg);
  322. ecmd->port = PORT_TP;
  323. } else {
  324. ecmd->supported |= SUPPORTED_FIBRE;
  325. ecmd->advertising |= ADVERTISED_FIBRE;
  326. ecmd->port = PORT_FIBRE;
  327. }
  328. ecmd->speed = SPEED_10000;
  329. ecmd->duplex = DUPLEX_FULL;
  330. return 0;
  331. }
  332. static void ql_get_drvinfo(struct net_device *ndev,
  333. struct ethtool_drvinfo *drvinfo)
  334. {
  335. struct ql_adapter *qdev = netdev_priv(ndev);
  336. strncpy(drvinfo->driver, qlge_driver_name, 32);
  337. strncpy(drvinfo->version, qlge_driver_version, 32);
  338. snprintf(drvinfo->fw_version, 32, "v%d.%d.%d",
  339. (qdev->fw_rev_id & 0x00ff0000) >> 16,
  340. (qdev->fw_rev_id & 0x0000ff00) >> 8,
  341. (qdev->fw_rev_id & 0x000000ff));
  342. strncpy(drvinfo->bus_info, pci_name(qdev->pdev), 32);
  343. drvinfo->n_stats = 0;
  344. drvinfo->testinfo_len = 0;
  345. drvinfo->regdump_len = 0;
  346. drvinfo->eedump_len = 0;
  347. }
  348. static int ql_phys_id(struct net_device *ndev, u32 data)
  349. {
  350. struct ql_adapter *qdev = netdev_priv(ndev);
  351. u32 led_reg, i;
  352. int status;
  353. /* Save the current LED settings */
  354. status = ql_mb_get_led_cfg(qdev);
  355. if (status)
  356. return status;
  357. led_reg = qdev->led_config;
  358. /* Start blinking the led */
  359. if (!data || data > 300)
  360. data = 300;
  361. for (i = 0; i < (data * 10); i++)
  362. ql_mb_set_led_cfg(qdev, QL_LED_BLINK);
  363. /* Restore LED settings */
  364. status = ql_mb_set_led_cfg(qdev, led_reg);
  365. if (status)
  366. return status;
  367. return 0;
  368. }
  369. static int ql_get_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
  370. {
  371. struct ql_adapter *qdev = netdev_priv(dev);
  372. c->rx_coalesce_usecs = qdev->rx_coalesce_usecs;
  373. c->tx_coalesce_usecs = qdev->tx_coalesce_usecs;
  374. /* This chip coalesces as follows:
  375. * If a packet arrives, hold off interrupts until
  376. * cqicb->int_delay expires, but if no other packets arrive don't
  377. * wait longer than cqicb->pkt_int_delay. But ethtool doesn't use a
  378. * timer to coalesce on a frame basis. So, we have to take ethtool's
  379. * max_coalesced_frames value and convert it to a delay in microseconds.
  380. * We do this by using a basic thoughput of 1,000,000 frames per
  381. * second @ (1024 bytes). This means one frame per usec. So it's a
  382. * simple one to one ratio.
  383. */
  384. c->rx_max_coalesced_frames = qdev->rx_max_coalesced_frames;
  385. c->tx_max_coalesced_frames = qdev->tx_max_coalesced_frames;
  386. return 0;
  387. }
  388. static int ql_set_coalesce(struct net_device *ndev, struct ethtool_coalesce *c)
  389. {
  390. struct ql_adapter *qdev = netdev_priv(ndev);
  391. /* Validate user parameters. */
  392. if (c->rx_coalesce_usecs > qdev->rx_ring_size / 2)
  393. return -EINVAL;
  394. /* Don't wait more than 10 usec. */
  395. if (c->rx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
  396. return -EINVAL;
  397. if (c->tx_coalesce_usecs > qdev->tx_ring_size / 2)
  398. return -EINVAL;
  399. if (c->tx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
  400. return -EINVAL;
  401. /* Verify a change took place before updating the hardware. */
  402. if (qdev->rx_coalesce_usecs == c->rx_coalesce_usecs &&
  403. qdev->tx_coalesce_usecs == c->tx_coalesce_usecs &&
  404. qdev->rx_max_coalesced_frames == c->rx_max_coalesced_frames &&
  405. qdev->tx_max_coalesced_frames == c->tx_max_coalesced_frames)
  406. return 0;
  407. qdev->rx_coalesce_usecs = c->rx_coalesce_usecs;
  408. qdev->tx_coalesce_usecs = c->tx_coalesce_usecs;
  409. qdev->rx_max_coalesced_frames = c->rx_max_coalesced_frames;
  410. qdev->tx_max_coalesced_frames = c->tx_max_coalesced_frames;
  411. return ql_update_ring_coalescing(qdev);
  412. }
  413. static void ql_get_pauseparam(struct net_device *netdev,
  414. struct ethtool_pauseparam *pause)
  415. {
  416. struct ql_adapter *qdev = netdev_priv(netdev);
  417. ql_mb_get_port_cfg(qdev);
  418. if (qdev->link_config & CFG_PAUSE_STD) {
  419. pause->rx_pause = 1;
  420. pause->tx_pause = 1;
  421. }
  422. }
  423. static int ql_set_pauseparam(struct net_device *netdev,
  424. struct ethtool_pauseparam *pause)
  425. {
  426. struct ql_adapter *qdev = netdev_priv(netdev);
  427. int status = 0;
  428. if ((pause->rx_pause) && (pause->tx_pause))
  429. qdev->link_config |= CFG_PAUSE_STD;
  430. else if (!pause->rx_pause && !pause->tx_pause)
  431. qdev->link_config &= ~CFG_PAUSE_STD;
  432. else
  433. return -EINVAL;
  434. status = ql_mb_set_port_cfg(qdev);
  435. if (status)
  436. return status;
  437. return status;
  438. }
  439. static u32 ql_get_rx_csum(struct net_device *netdev)
  440. {
  441. struct ql_adapter *qdev = netdev_priv(netdev);
  442. return qdev->rx_csum;
  443. }
  444. static int ql_set_rx_csum(struct net_device *netdev, uint32_t data)
  445. {
  446. struct ql_adapter *qdev = netdev_priv(netdev);
  447. qdev->rx_csum = data;
  448. return 0;
  449. }
  450. static int ql_set_tso(struct net_device *ndev, uint32_t data)
  451. {
  452. if (data) {
  453. ndev->features |= NETIF_F_TSO;
  454. ndev->features |= NETIF_F_TSO6;
  455. } else {
  456. ndev->features &= ~NETIF_F_TSO;
  457. ndev->features &= ~NETIF_F_TSO6;
  458. }
  459. return 0;
  460. }
  461. static u32 ql_get_msglevel(struct net_device *ndev)
  462. {
  463. struct ql_adapter *qdev = netdev_priv(ndev);
  464. return qdev->msg_enable;
  465. }
  466. static void ql_set_msglevel(struct net_device *ndev, u32 value)
  467. {
  468. struct ql_adapter *qdev = netdev_priv(ndev);
  469. qdev->msg_enable = value;
  470. }
  471. const struct ethtool_ops qlge_ethtool_ops = {
  472. .get_settings = ql_get_settings,
  473. .get_drvinfo = ql_get_drvinfo,
  474. .get_msglevel = ql_get_msglevel,
  475. .set_msglevel = ql_set_msglevel,
  476. .get_link = ethtool_op_get_link,
  477. .phys_id = ql_phys_id,
  478. .get_pauseparam = ql_get_pauseparam,
  479. .set_pauseparam = ql_set_pauseparam,
  480. .get_rx_csum = ql_get_rx_csum,
  481. .set_rx_csum = ql_set_rx_csum,
  482. .get_tx_csum = ethtool_op_get_tx_csum,
  483. .set_tx_csum = ethtool_op_set_tx_csum,
  484. .get_sg = ethtool_op_get_sg,
  485. .set_sg = ethtool_op_set_sg,
  486. .get_tso = ethtool_op_get_tso,
  487. .set_tso = ql_set_tso,
  488. .get_coalesce = ql_get_coalesce,
  489. .set_coalesce = ql_set_coalesce,
  490. .get_sset_count = ql_get_sset_count,
  491. .get_strings = ql_get_strings,
  492. .get_ethtool_stats = ql_get_ethtool_stats,
  493. };