qlge_ethtool.c 18 KB

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