qlge_ethtool.c 18 KB

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