qlge_ethtool.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  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 const char ql_gstrings_test[][ETH_GSTRING_LEN] = {
  37. "Loopback test (offline)"
  38. };
  39. #define QLGE_TEST_LEN (sizeof(ql_gstrings_test) / ETH_GSTRING_LEN)
  40. static int ql_update_ring_coalescing(struct ql_adapter *qdev)
  41. {
  42. int i, status = 0;
  43. struct rx_ring *rx_ring;
  44. struct cqicb *cqicb;
  45. if (!netif_running(qdev->ndev))
  46. return status;
  47. /* Skip the default queue, and update the outbound handler
  48. * queues if they changed.
  49. */
  50. cqicb = (struct cqicb *)&qdev->rx_ring[qdev->rss_ring_count];
  51. if (le16_to_cpu(cqicb->irq_delay) != qdev->tx_coalesce_usecs ||
  52. le16_to_cpu(cqicb->pkt_delay) !=
  53. qdev->tx_max_coalesced_frames) {
  54. for (i = qdev->rss_ring_count; i < qdev->rx_ring_count; i++) {
  55. rx_ring = &qdev->rx_ring[i];
  56. cqicb = (struct cqicb *)rx_ring;
  57. cqicb->irq_delay = cpu_to_le16(qdev->tx_coalesce_usecs);
  58. cqicb->pkt_delay =
  59. cpu_to_le16(qdev->tx_max_coalesced_frames);
  60. cqicb->flags = FLAGS_LI;
  61. status = ql_write_cfg(qdev, cqicb, sizeof(*cqicb),
  62. CFG_LCQ, rx_ring->cq_id);
  63. if (status) {
  64. netif_err(qdev, ifup, qdev->ndev,
  65. "Failed to load CQICB.\n");
  66. goto exit;
  67. }
  68. }
  69. }
  70. /* Update the inbound (RSS) handler queues if they changed. */
  71. cqicb = (struct cqicb *)&qdev->rx_ring[0];
  72. if (le16_to_cpu(cqicb->irq_delay) != qdev->rx_coalesce_usecs ||
  73. le16_to_cpu(cqicb->pkt_delay) !=
  74. qdev->rx_max_coalesced_frames) {
  75. for (i = 0; i < qdev->rss_ring_count; i++, rx_ring++) {
  76. rx_ring = &qdev->rx_ring[i];
  77. cqicb = (struct cqicb *)rx_ring;
  78. cqicb->irq_delay = cpu_to_le16(qdev->rx_coalesce_usecs);
  79. cqicb->pkt_delay =
  80. cpu_to_le16(qdev->rx_max_coalesced_frames);
  81. cqicb->flags = FLAGS_LI;
  82. status = ql_write_cfg(qdev, cqicb, sizeof(*cqicb),
  83. CFG_LCQ, rx_ring->cq_id);
  84. if (status) {
  85. netif_err(qdev, ifup, qdev->ndev,
  86. "Failed to load CQICB.\n");
  87. goto exit;
  88. }
  89. }
  90. }
  91. exit:
  92. return status;
  93. }
  94. static 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. netif_err(qdev, drv, qdev->ndev,
  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. netif_err(qdev, drv, qdev->ndev,
  111. "Error reading status register 0x%.04x.\n",
  112. i);
  113. goto end;
  114. } else
  115. *iter = data;
  116. iter++;
  117. }
  118. /*
  119. * Get RX statistics.
  120. */
  121. for (i = 0x300; i < 0x3d0; i += 8) {
  122. if (ql_read_xgmac_reg64(qdev, i, &data)) {
  123. netif_err(qdev, drv, qdev->ndev,
  124. "Error reading status register 0x%.04x.\n",
  125. i);
  126. goto end;
  127. } else
  128. *iter = data;
  129. iter++;
  130. }
  131. /*
  132. * Get Per-priority TX pause frame counter statistics.
  133. */
  134. for (i = 0x500; i < 0x540; i += 8) {
  135. if (ql_read_xgmac_reg64(qdev, i, &data)) {
  136. netif_err(qdev, drv, qdev->ndev,
  137. "Error reading status register 0x%.04x.\n",
  138. i);
  139. goto end;
  140. } else
  141. *iter = data;
  142. iter++;
  143. }
  144. /*
  145. * Get Per-priority RX pause frame counter statistics.
  146. */
  147. for (i = 0x568; i < 0x5a8; i += 8) {
  148. if (ql_read_xgmac_reg64(qdev, i, &data)) {
  149. netif_err(qdev, drv, qdev->ndev,
  150. "Error reading status register 0x%.04x.\n",
  151. i);
  152. goto end;
  153. } else
  154. *iter = data;
  155. iter++;
  156. }
  157. /*
  158. * Get RX NIC FIFO DROP statistics.
  159. */
  160. if (ql_read_xgmac_reg64(qdev, 0x5b8, &data)) {
  161. netif_err(qdev, drv, qdev->ndev,
  162. "Error reading status register 0x%.04x.\n", i);
  163. goto end;
  164. } else
  165. *iter = data;
  166. end:
  167. ql_sem_unlock(qdev, qdev->xg_sem_mask);
  168. quit:
  169. spin_unlock(&qdev->stats_lock);
  170. QL_DUMP_STAT(qdev);
  171. return;
  172. }
  173. static char ql_stats_str_arr[][ETH_GSTRING_LEN] = {
  174. {"tx_pkts"},
  175. {"tx_bytes"},
  176. {"tx_mcast_pkts"},
  177. {"tx_bcast_pkts"},
  178. {"tx_ucast_pkts"},
  179. {"tx_ctl_pkts"},
  180. {"tx_pause_pkts"},
  181. {"tx_64_pkts"},
  182. {"tx_65_to_127_pkts"},
  183. {"tx_128_to_255_pkts"},
  184. {"tx_256_511_pkts"},
  185. {"tx_512_to_1023_pkts"},
  186. {"tx_1024_to_1518_pkts"},
  187. {"tx_1519_to_max_pkts"},
  188. {"tx_undersize_pkts"},
  189. {"tx_oversize_pkts"},
  190. {"rx_bytes"},
  191. {"rx_bytes_ok"},
  192. {"rx_pkts"},
  193. {"rx_pkts_ok"},
  194. {"rx_bcast_pkts"},
  195. {"rx_mcast_pkts"},
  196. {"rx_ucast_pkts"},
  197. {"rx_undersize_pkts"},
  198. {"rx_oversize_pkts"},
  199. {"rx_jabber_pkts"},
  200. {"rx_undersize_fcerr_pkts"},
  201. {"rx_drop_events"},
  202. {"rx_fcerr_pkts"},
  203. {"rx_align_err"},
  204. {"rx_symbol_err"},
  205. {"rx_mac_err"},
  206. {"rx_ctl_pkts"},
  207. {"rx_pause_pkts"},
  208. {"rx_64_pkts"},
  209. {"rx_65_to_127_pkts"},
  210. {"rx_128_255_pkts"},
  211. {"rx_256_511_pkts"},
  212. {"rx_512_to_1023_pkts"},
  213. {"rx_1024_to_1518_pkts"},
  214. {"rx_1519_to_max_pkts"},
  215. {"rx_len_err_pkts"},
  216. {"tx_cbfc_pause_frames0"},
  217. {"tx_cbfc_pause_frames1"},
  218. {"tx_cbfc_pause_frames2"},
  219. {"tx_cbfc_pause_frames3"},
  220. {"tx_cbfc_pause_frames4"},
  221. {"tx_cbfc_pause_frames5"},
  222. {"tx_cbfc_pause_frames6"},
  223. {"tx_cbfc_pause_frames7"},
  224. {"rx_cbfc_pause_frames0"},
  225. {"rx_cbfc_pause_frames1"},
  226. {"rx_cbfc_pause_frames2"},
  227. {"rx_cbfc_pause_frames3"},
  228. {"rx_cbfc_pause_frames4"},
  229. {"rx_cbfc_pause_frames5"},
  230. {"rx_cbfc_pause_frames6"},
  231. {"rx_cbfc_pause_frames7"},
  232. {"rx_nic_fifo_drop"},
  233. };
  234. static void ql_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  235. {
  236. switch (stringset) {
  237. case ETH_SS_STATS:
  238. memcpy(buf, ql_stats_str_arr, sizeof(ql_stats_str_arr));
  239. break;
  240. }
  241. }
  242. static int ql_get_sset_count(struct net_device *dev, int sset)
  243. {
  244. switch (sset) {
  245. case ETH_SS_TEST:
  246. return QLGE_TEST_LEN;
  247. case ETH_SS_STATS:
  248. return ARRAY_SIZE(ql_stats_str_arr);
  249. default:
  250. return -EOPNOTSUPP;
  251. }
  252. }
  253. static void
  254. ql_get_ethtool_stats(struct net_device *ndev,
  255. struct ethtool_stats *stats, u64 *data)
  256. {
  257. struct ql_adapter *qdev = netdev_priv(ndev);
  258. struct nic_stats *s = &qdev->nic_stats;
  259. ql_update_stats(qdev);
  260. *data++ = s->tx_pkts;
  261. *data++ = s->tx_bytes;
  262. *data++ = s->tx_mcast_pkts;
  263. *data++ = s->tx_bcast_pkts;
  264. *data++ = s->tx_ucast_pkts;
  265. *data++ = s->tx_ctl_pkts;
  266. *data++ = s->tx_pause_pkts;
  267. *data++ = s->tx_64_pkt;
  268. *data++ = s->tx_65_to_127_pkt;
  269. *data++ = s->tx_128_to_255_pkt;
  270. *data++ = s->tx_256_511_pkt;
  271. *data++ = s->tx_512_to_1023_pkt;
  272. *data++ = s->tx_1024_to_1518_pkt;
  273. *data++ = s->tx_1519_to_max_pkt;
  274. *data++ = s->tx_undersize_pkt;
  275. *data++ = s->tx_oversize_pkt;
  276. *data++ = s->rx_bytes;
  277. *data++ = s->rx_bytes_ok;
  278. *data++ = s->rx_pkts;
  279. *data++ = s->rx_pkts_ok;
  280. *data++ = s->rx_bcast_pkts;
  281. *data++ = s->rx_mcast_pkts;
  282. *data++ = s->rx_ucast_pkts;
  283. *data++ = s->rx_undersize_pkts;
  284. *data++ = s->rx_oversize_pkts;
  285. *data++ = s->rx_jabber_pkts;
  286. *data++ = s->rx_undersize_fcerr_pkts;
  287. *data++ = s->rx_drop_events;
  288. *data++ = s->rx_fcerr_pkts;
  289. *data++ = s->rx_align_err;
  290. *data++ = s->rx_symbol_err;
  291. *data++ = s->rx_mac_err;
  292. *data++ = s->rx_ctl_pkts;
  293. *data++ = s->rx_pause_pkts;
  294. *data++ = s->rx_64_pkts;
  295. *data++ = s->rx_65_to_127_pkts;
  296. *data++ = s->rx_128_255_pkts;
  297. *data++ = s->rx_256_511_pkts;
  298. *data++ = s->rx_512_to_1023_pkts;
  299. *data++ = s->rx_1024_to_1518_pkts;
  300. *data++ = s->rx_1519_to_max_pkts;
  301. *data++ = s->rx_len_err_pkts;
  302. *data++ = s->tx_cbfc_pause_frames0;
  303. *data++ = s->tx_cbfc_pause_frames1;
  304. *data++ = s->tx_cbfc_pause_frames2;
  305. *data++ = s->tx_cbfc_pause_frames3;
  306. *data++ = s->tx_cbfc_pause_frames4;
  307. *data++ = s->tx_cbfc_pause_frames5;
  308. *data++ = s->tx_cbfc_pause_frames6;
  309. *data++ = s->tx_cbfc_pause_frames7;
  310. *data++ = s->rx_cbfc_pause_frames0;
  311. *data++ = s->rx_cbfc_pause_frames1;
  312. *data++ = s->rx_cbfc_pause_frames2;
  313. *data++ = s->rx_cbfc_pause_frames3;
  314. *data++ = s->rx_cbfc_pause_frames4;
  315. *data++ = s->rx_cbfc_pause_frames5;
  316. *data++ = s->rx_cbfc_pause_frames6;
  317. *data++ = s->rx_cbfc_pause_frames7;
  318. *data++ = s->rx_nic_fifo_drop;
  319. }
  320. static int ql_get_settings(struct net_device *ndev,
  321. struct ethtool_cmd *ecmd)
  322. {
  323. struct ql_adapter *qdev = netdev_priv(ndev);
  324. ecmd->supported = SUPPORTED_10000baseT_Full;
  325. ecmd->advertising = ADVERTISED_10000baseT_Full;
  326. ecmd->autoneg = AUTONEG_ENABLE;
  327. ecmd->transceiver = XCVR_EXTERNAL;
  328. if ((qdev->link_status & STS_LINK_TYPE_MASK) ==
  329. STS_LINK_TYPE_10GBASET) {
  330. ecmd->supported |= (SUPPORTED_TP | SUPPORTED_Autoneg);
  331. ecmd->advertising |= (ADVERTISED_TP | ADVERTISED_Autoneg);
  332. ecmd->port = PORT_TP;
  333. } else {
  334. ecmd->supported |= SUPPORTED_FIBRE;
  335. ecmd->advertising |= ADVERTISED_FIBRE;
  336. ecmd->port = PORT_FIBRE;
  337. }
  338. ecmd->speed = SPEED_10000;
  339. ecmd->duplex = DUPLEX_FULL;
  340. return 0;
  341. }
  342. static void ql_get_drvinfo(struct net_device *ndev,
  343. struct ethtool_drvinfo *drvinfo)
  344. {
  345. struct ql_adapter *qdev = netdev_priv(ndev);
  346. strncpy(drvinfo->driver, qlge_driver_name, 32);
  347. strncpy(drvinfo->version, qlge_driver_version, 32);
  348. snprintf(drvinfo->fw_version, 32, "v%d.%d.%d",
  349. (qdev->fw_rev_id & 0x00ff0000) >> 16,
  350. (qdev->fw_rev_id & 0x0000ff00) >> 8,
  351. (qdev->fw_rev_id & 0x000000ff));
  352. strncpy(drvinfo->bus_info, pci_name(qdev->pdev), 32);
  353. drvinfo->n_stats = 0;
  354. drvinfo->testinfo_len = 0;
  355. drvinfo->regdump_len = 0;
  356. drvinfo->eedump_len = 0;
  357. }
  358. static void ql_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
  359. {
  360. struct ql_adapter *qdev = netdev_priv(ndev);
  361. /* What we support. */
  362. wol->supported = WAKE_MAGIC;
  363. /* What we've currently got set. */
  364. wol->wolopts = qdev->wol;
  365. }
  366. static int ql_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
  367. {
  368. struct ql_adapter *qdev = netdev_priv(ndev);
  369. int status;
  370. if (wol->wolopts & ~WAKE_MAGIC)
  371. return -EINVAL;
  372. qdev->wol = wol->wolopts;
  373. netif_info(qdev, drv, qdev->ndev, "Set wol option 0x%x\n", qdev->wol);
  374. if (!qdev->wol) {
  375. u32 wol = 0;
  376. status = ql_mb_wol_mode(qdev, wol);
  377. netif_err(qdev, drv, qdev->ndev, "WOL %s (wol code 0x%x)\n",
  378. status == 0 ? "cleared sucessfully" : "clear failed",
  379. wol);
  380. }
  381. return 0;
  382. }
  383. static int ql_phys_id(struct net_device *ndev, u32 data)
  384. {
  385. struct ql_adapter *qdev = netdev_priv(ndev);
  386. u32 led_reg, i;
  387. int status;
  388. /* Save the current LED settings */
  389. status = ql_mb_get_led_cfg(qdev);
  390. if (status)
  391. return status;
  392. led_reg = qdev->led_config;
  393. /* Start blinking the led */
  394. if (!data || data > 300)
  395. data = 300;
  396. for (i = 0; i < (data * 10); i++)
  397. ql_mb_set_led_cfg(qdev, QL_LED_BLINK);
  398. /* Restore LED settings */
  399. status = ql_mb_set_led_cfg(qdev, led_reg);
  400. if (status)
  401. return status;
  402. return 0;
  403. }
  404. static int ql_start_loopback(struct ql_adapter *qdev)
  405. {
  406. if (netif_carrier_ok(qdev->ndev)) {
  407. set_bit(QL_LB_LINK_UP, &qdev->flags);
  408. netif_carrier_off(qdev->ndev);
  409. } else
  410. clear_bit(QL_LB_LINK_UP, &qdev->flags);
  411. qdev->link_config |= CFG_LOOPBACK_PCS;
  412. return ql_mb_set_port_cfg(qdev);
  413. }
  414. static void ql_stop_loopback(struct ql_adapter *qdev)
  415. {
  416. qdev->link_config &= ~CFG_LOOPBACK_PCS;
  417. ql_mb_set_port_cfg(qdev);
  418. if (test_bit(QL_LB_LINK_UP, &qdev->flags)) {
  419. netif_carrier_on(qdev->ndev);
  420. clear_bit(QL_LB_LINK_UP, &qdev->flags);
  421. }
  422. }
  423. static void ql_create_lb_frame(struct sk_buff *skb,
  424. unsigned int frame_size)
  425. {
  426. memset(skb->data, 0xFF, frame_size);
  427. frame_size &= ~1;
  428. memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
  429. memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
  430. memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
  431. }
  432. void ql_check_lb_frame(struct ql_adapter *qdev,
  433. struct sk_buff *skb)
  434. {
  435. unsigned int frame_size = skb->len;
  436. if ((*(skb->data + 3) == 0xFF) &&
  437. (*(skb->data + frame_size / 2 + 10) == 0xBE) &&
  438. (*(skb->data + frame_size / 2 + 12) == 0xAF)) {
  439. atomic_dec(&qdev->lb_count);
  440. return;
  441. }
  442. }
  443. static int ql_run_loopback_test(struct ql_adapter *qdev)
  444. {
  445. int i;
  446. netdev_tx_t rc;
  447. struct sk_buff *skb;
  448. unsigned int size = SMALL_BUF_MAP_SIZE;
  449. for (i = 0; i < 64; i++) {
  450. skb = netdev_alloc_skb(qdev->ndev, size);
  451. if (!skb)
  452. return -ENOMEM;
  453. skb->queue_mapping = 0;
  454. skb_put(skb, size);
  455. ql_create_lb_frame(skb, size);
  456. rc = ql_lb_send(skb, qdev->ndev);
  457. if (rc != NETDEV_TX_OK)
  458. return -EPIPE;
  459. atomic_inc(&qdev->lb_count);
  460. }
  461. /* Give queue time to settle before testing results. */
  462. msleep(2);
  463. ql_clean_lb_rx_ring(&qdev->rx_ring[0], 128);
  464. return atomic_read(&qdev->lb_count) ? -EIO : 0;
  465. }
  466. static int ql_loopback_test(struct ql_adapter *qdev, u64 *data)
  467. {
  468. *data = ql_start_loopback(qdev);
  469. if (*data)
  470. goto out;
  471. *data = ql_run_loopback_test(qdev);
  472. out:
  473. ql_stop_loopback(qdev);
  474. return *data;
  475. }
  476. static void ql_self_test(struct net_device *ndev,
  477. struct ethtool_test *eth_test, u64 *data)
  478. {
  479. struct ql_adapter *qdev = netdev_priv(ndev);
  480. if (netif_running(ndev)) {
  481. set_bit(QL_SELFTEST, &qdev->flags);
  482. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  483. /* Offline tests */
  484. if (ql_loopback_test(qdev, &data[0]))
  485. eth_test->flags |= ETH_TEST_FL_FAILED;
  486. } else {
  487. /* Online tests */
  488. data[0] = 0;
  489. }
  490. clear_bit(QL_SELFTEST, &qdev->flags);
  491. /* Give link time to come up after
  492. * port configuration changes.
  493. */
  494. msleep_interruptible(4 * 1000);
  495. } else {
  496. netif_err(qdev, drv, qdev->ndev,
  497. "is down, Loopback test will fail.\n");
  498. eth_test->flags |= ETH_TEST_FL_FAILED;
  499. }
  500. }
  501. static int ql_get_regs_len(struct net_device *ndev)
  502. {
  503. return sizeof(struct ql_reg_dump);
  504. }
  505. static void ql_get_regs(struct net_device *ndev,
  506. struct ethtool_regs *regs, void *p)
  507. {
  508. struct ql_adapter *qdev = netdev_priv(ndev);
  509. ql_gen_reg_dump(qdev, p);
  510. }
  511. static int ql_get_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
  512. {
  513. struct ql_adapter *qdev = netdev_priv(dev);
  514. c->rx_coalesce_usecs = qdev->rx_coalesce_usecs;
  515. c->tx_coalesce_usecs = qdev->tx_coalesce_usecs;
  516. /* This chip coalesces as follows:
  517. * If a packet arrives, hold off interrupts until
  518. * cqicb->int_delay expires, but if no other packets arrive don't
  519. * wait longer than cqicb->pkt_int_delay. But ethtool doesn't use a
  520. * timer to coalesce on a frame basis. So, we have to take ethtool's
  521. * max_coalesced_frames value and convert it to a delay in microseconds.
  522. * We do this by using a basic thoughput of 1,000,000 frames per
  523. * second @ (1024 bytes). This means one frame per usec. So it's a
  524. * simple one to one ratio.
  525. */
  526. c->rx_max_coalesced_frames = qdev->rx_max_coalesced_frames;
  527. c->tx_max_coalesced_frames = qdev->tx_max_coalesced_frames;
  528. return 0;
  529. }
  530. static int ql_set_coalesce(struct net_device *ndev, struct ethtool_coalesce *c)
  531. {
  532. struct ql_adapter *qdev = netdev_priv(ndev);
  533. /* Validate user parameters. */
  534. if (c->rx_coalesce_usecs > qdev->rx_ring_size / 2)
  535. return -EINVAL;
  536. /* Don't wait more than 10 usec. */
  537. if (c->rx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
  538. return -EINVAL;
  539. if (c->tx_coalesce_usecs > qdev->tx_ring_size / 2)
  540. return -EINVAL;
  541. if (c->tx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
  542. return -EINVAL;
  543. /* Verify a change took place before updating the hardware. */
  544. if (qdev->rx_coalesce_usecs == c->rx_coalesce_usecs &&
  545. qdev->tx_coalesce_usecs == c->tx_coalesce_usecs &&
  546. qdev->rx_max_coalesced_frames == c->rx_max_coalesced_frames &&
  547. qdev->tx_max_coalesced_frames == c->tx_max_coalesced_frames)
  548. return 0;
  549. qdev->rx_coalesce_usecs = c->rx_coalesce_usecs;
  550. qdev->tx_coalesce_usecs = c->tx_coalesce_usecs;
  551. qdev->rx_max_coalesced_frames = c->rx_max_coalesced_frames;
  552. qdev->tx_max_coalesced_frames = c->tx_max_coalesced_frames;
  553. return ql_update_ring_coalescing(qdev);
  554. }
  555. static void ql_get_pauseparam(struct net_device *netdev,
  556. struct ethtool_pauseparam *pause)
  557. {
  558. struct ql_adapter *qdev = netdev_priv(netdev);
  559. ql_mb_get_port_cfg(qdev);
  560. if (qdev->link_config & CFG_PAUSE_STD) {
  561. pause->rx_pause = 1;
  562. pause->tx_pause = 1;
  563. }
  564. }
  565. static int ql_set_pauseparam(struct net_device *netdev,
  566. struct ethtool_pauseparam *pause)
  567. {
  568. struct ql_adapter *qdev = netdev_priv(netdev);
  569. int status = 0;
  570. if ((pause->rx_pause) && (pause->tx_pause))
  571. qdev->link_config |= CFG_PAUSE_STD;
  572. else if (!pause->rx_pause && !pause->tx_pause)
  573. qdev->link_config &= ~CFG_PAUSE_STD;
  574. else
  575. return -EINVAL;
  576. status = ql_mb_set_port_cfg(qdev);
  577. if (status)
  578. return status;
  579. return status;
  580. }
  581. static u32 ql_get_rx_csum(struct net_device *netdev)
  582. {
  583. struct ql_adapter *qdev = netdev_priv(netdev);
  584. return qdev->rx_csum;
  585. }
  586. static int ql_set_rx_csum(struct net_device *netdev, uint32_t data)
  587. {
  588. struct ql_adapter *qdev = netdev_priv(netdev);
  589. qdev->rx_csum = data;
  590. return 0;
  591. }
  592. static int ql_set_tso(struct net_device *ndev, uint32_t data)
  593. {
  594. if (data) {
  595. ndev->features |= NETIF_F_TSO;
  596. ndev->features |= NETIF_F_TSO6;
  597. } else {
  598. ndev->features &= ~NETIF_F_TSO;
  599. ndev->features &= ~NETIF_F_TSO6;
  600. }
  601. return 0;
  602. }
  603. static u32 ql_get_msglevel(struct net_device *ndev)
  604. {
  605. struct ql_adapter *qdev = netdev_priv(ndev);
  606. return qdev->msg_enable;
  607. }
  608. static void ql_set_msglevel(struct net_device *ndev, u32 value)
  609. {
  610. struct ql_adapter *qdev = netdev_priv(ndev);
  611. qdev->msg_enable = value;
  612. }
  613. const struct ethtool_ops qlge_ethtool_ops = {
  614. .get_settings = ql_get_settings,
  615. .get_drvinfo = ql_get_drvinfo,
  616. .get_wol = ql_get_wol,
  617. .set_wol = ql_set_wol,
  618. .get_regs_len = ql_get_regs_len,
  619. .get_regs = ql_get_regs,
  620. .get_msglevel = ql_get_msglevel,
  621. .set_msglevel = ql_set_msglevel,
  622. .get_link = ethtool_op_get_link,
  623. .phys_id = ql_phys_id,
  624. .self_test = ql_self_test,
  625. .get_pauseparam = ql_get_pauseparam,
  626. .set_pauseparam = ql_set_pauseparam,
  627. .get_rx_csum = ql_get_rx_csum,
  628. .set_rx_csum = ql_set_rx_csum,
  629. .get_tx_csum = ethtool_op_get_tx_csum,
  630. .set_tx_csum = ethtool_op_set_tx_csum,
  631. .get_sg = ethtool_op_get_sg,
  632. .set_sg = ethtool_op_set_sg,
  633. .get_tso = ethtool_op_get_tso,
  634. .set_tso = ql_set_tso,
  635. .get_coalesce = ql_get_coalesce,
  636. .set_coalesce = ql_set_coalesce,
  637. .get_sset_count = ql_get_sset_count,
  638. .get_strings = ql_get_strings,
  639. .get_ethtool_stats = ql_get_ethtool_stats,
  640. };