be_ethtool.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. /*
  2. * Copyright (C) 2005 - 2010 ServerEngines
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation. The full GNU General
  8. * Public License is included in this distribution in the file called COPYING.
  9. *
  10. * Contact Information:
  11. * linux-drivers@serverengines.com
  12. *
  13. * ServerEngines
  14. * 209 N. Fair Oaks Ave
  15. * Sunnyvale, CA 94085
  16. */
  17. #include "be.h"
  18. #include "be_cmds.h"
  19. #include <linux/ethtool.h>
  20. struct be_ethtool_stat {
  21. char desc[ETH_GSTRING_LEN];
  22. int type;
  23. int size;
  24. int offset;
  25. };
  26. enum {NETSTAT, PORTSTAT, MISCSTAT, DRVSTAT_TX, DRVSTAT_RX, ERXSTAT};
  27. #define FIELDINFO(_struct, field) FIELD_SIZEOF(_struct, field), \
  28. offsetof(_struct, field)
  29. #define NETSTAT_INFO(field) #field, NETSTAT,\
  30. FIELDINFO(struct net_device_stats,\
  31. field)
  32. #define DRVSTAT_TX_INFO(field) #field, DRVSTAT_TX,\
  33. FIELDINFO(struct be_tx_stats, field)
  34. #define DRVSTAT_RX_INFO(field) #field, DRVSTAT_RX,\
  35. FIELDINFO(struct be_rx_stats, field)
  36. #define MISCSTAT_INFO(field) #field, MISCSTAT,\
  37. FIELDINFO(struct be_rxf_stats, field)
  38. #define PORTSTAT_INFO(field) #field, PORTSTAT,\
  39. FIELDINFO(struct be_port_rxf_stats, \
  40. field)
  41. #define ERXSTAT_INFO(field) #field, ERXSTAT,\
  42. FIELDINFO(struct be_erx_stats, field)
  43. static const struct be_ethtool_stat et_stats[] = {
  44. {NETSTAT_INFO(rx_packets)},
  45. {NETSTAT_INFO(tx_packets)},
  46. {NETSTAT_INFO(rx_bytes)},
  47. {NETSTAT_INFO(tx_bytes)},
  48. {NETSTAT_INFO(rx_errors)},
  49. {NETSTAT_INFO(tx_errors)},
  50. {NETSTAT_INFO(rx_dropped)},
  51. {NETSTAT_INFO(tx_dropped)},
  52. {DRVSTAT_TX_INFO(be_tx_rate)},
  53. {DRVSTAT_TX_INFO(be_tx_reqs)},
  54. {DRVSTAT_TX_INFO(be_tx_wrbs)},
  55. {DRVSTAT_TX_INFO(be_tx_stops)},
  56. {DRVSTAT_TX_INFO(be_tx_events)},
  57. {DRVSTAT_TX_INFO(be_tx_compl)},
  58. {PORTSTAT_INFO(rx_unicast_frames)},
  59. {PORTSTAT_INFO(rx_multicast_frames)},
  60. {PORTSTAT_INFO(rx_broadcast_frames)},
  61. {PORTSTAT_INFO(rx_crc_errors)},
  62. {PORTSTAT_INFO(rx_alignment_symbol_errors)},
  63. {PORTSTAT_INFO(rx_pause_frames)},
  64. {PORTSTAT_INFO(rx_control_frames)},
  65. {PORTSTAT_INFO(rx_in_range_errors)},
  66. {PORTSTAT_INFO(rx_out_range_errors)},
  67. {PORTSTAT_INFO(rx_frame_too_long)},
  68. {PORTSTAT_INFO(rx_address_match_errors)},
  69. {PORTSTAT_INFO(rx_vlan_mismatch)},
  70. {PORTSTAT_INFO(rx_dropped_too_small)},
  71. {PORTSTAT_INFO(rx_dropped_too_short)},
  72. {PORTSTAT_INFO(rx_dropped_header_too_small)},
  73. {PORTSTAT_INFO(rx_dropped_tcp_length)},
  74. {PORTSTAT_INFO(rx_dropped_runt)},
  75. {PORTSTAT_INFO(rx_fifo_overflow)},
  76. {PORTSTAT_INFO(rx_input_fifo_overflow)},
  77. {PORTSTAT_INFO(rx_ip_checksum_errs)},
  78. {PORTSTAT_INFO(rx_tcp_checksum_errs)},
  79. {PORTSTAT_INFO(rx_udp_checksum_errs)},
  80. {PORTSTAT_INFO(rx_non_rss_packets)},
  81. {PORTSTAT_INFO(rx_ipv4_packets)},
  82. {PORTSTAT_INFO(rx_ipv6_packets)},
  83. {PORTSTAT_INFO(rx_switched_unicast_packets)},
  84. {PORTSTAT_INFO(rx_switched_multicast_packets)},
  85. {PORTSTAT_INFO(rx_switched_broadcast_packets)},
  86. {PORTSTAT_INFO(tx_unicastframes)},
  87. {PORTSTAT_INFO(tx_multicastframes)},
  88. {PORTSTAT_INFO(tx_broadcastframes)},
  89. {PORTSTAT_INFO(tx_pauseframes)},
  90. {PORTSTAT_INFO(tx_controlframes)},
  91. {MISCSTAT_INFO(rx_drops_no_pbuf)},
  92. {MISCSTAT_INFO(rx_drops_no_txpb)},
  93. {MISCSTAT_INFO(rx_drops_no_erx_descr)},
  94. {MISCSTAT_INFO(rx_drops_no_tpre_descr)},
  95. {MISCSTAT_INFO(rx_drops_too_many_frags)},
  96. {MISCSTAT_INFO(rx_drops_invalid_ring)},
  97. {MISCSTAT_INFO(forwarded_packets)},
  98. {MISCSTAT_INFO(rx_drops_mtu)}
  99. };
  100. #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
  101. /* Stats related to multi RX queues */
  102. static const struct be_ethtool_stat et_rx_stats[] = {
  103. {DRVSTAT_RX_INFO(rx_bytes)},
  104. {DRVSTAT_RX_INFO(rx_pkts)},
  105. {DRVSTAT_RX_INFO(rx_rate)},
  106. {DRVSTAT_RX_INFO(rx_polls)},
  107. {DRVSTAT_RX_INFO(rx_events)},
  108. {DRVSTAT_RX_INFO(rx_compl)},
  109. {DRVSTAT_RX_INFO(rx_mcast_pkts)},
  110. {DRVSTAT_RX_INFO(rx_post_fail)},
  111. {ERXSTAT_INFO(rx_drops_no_fragments)}
  112. };
  113. #define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
  114. static const char et_self_tests[][ETH_GSTRING_LEN] = {
  115. "MAC Loopback test",
  116. "PHY Loopback test",
  117. "External Loopback test",
  118. "DDR DMA test"
  119. "Link test"
  120. };
  121. #define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
  122. #define BE_MAC_LOOPBACK 0x0
  123. #define BE_PHY_LOOPBACK 0x1
  124. #define BE_ONE_PORT_EXT_LOOPBACK 0x2
  125. #define BE_NO_LOOPBACK 0xff
  126. static void
  127. be_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
  128. {
  129. struct be_adapter *adapter = netdev_priv(netdev);
  130. strcpy(drvinfo->driver, DRV_NAME);
  131. strcpy(drvinfo->version, DRV_VER);
  132. strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN);
  133. strcpy(drvinfo->bus_info, pci_name(adapter->pdev));
  134. drvinfo->testinfo_len = 0;
  135. drvinfo->regdump_len = 0;
  136. drvinfo->eedump_len = 0;
  137. }
  138. static int
  139. be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
  140. {
  141. struct be_adapter *adapter = netdev_priv(netdev);
  142. struct be_eq_obj *rx_eq = &adapter->rx_obj[0].rx_eq;
  143. struct be_eq_obj *tx_eq = &adapter->tx_eq;
  144. coalesce->rx_coalesce_usecs = rx_eq->cur_eqd;
  145. coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd;
  146. coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd;
  147. coalesce->tx_coalesce_usecs = tx_eq->cur_eqd;
  148. coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd;
  149. coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd;
  150. coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
  151. coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
  152. return 0;
  153. }
  154. /*
  155. * This routine is used to set interrup coalescing delay
  156. */
  157. static int
  158. be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
  159. {
  160. struct be_adapter *adapter = netdev_priv(netdev);
  161. struct be_rx_obj *rxo;
  162. struct be_eq_obj *rx_eq;
  163. struct be_eq_obj *tx_eq = &adapter->tx_eq;
  164. u32 tx_max, tx_min, tx_cur;
  165. u32 rx_max, rx_min, rx_cur;
  166. int status = 0, i;
  167. if (coalesce->use_adaptive_tx_coalesce == 1)
  168. return -EINVAL;
  169. for_all_rx_queues(adapter, rxo, i) {
  170. rx_eq = &rxo->rx_eq;
  171. if (!rx_eq->enable_aic && coalesce->use_adaptive_rx_coalesce)
  172. rx_eq->cur_eqd = 0;
  173. rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce;
  174. rx_max = coalesce->rx_coalesce_usecs_high;
  175. rx_min = coalesce->rx_coalesce_usecs_low;
  176. rx_cur = coalesce->rx_coalesce_usecs;
  177. if (rx_eq->enable_aic) {
  178. if (rx_max > BE_MAX_EQD)
  179. rx_max = BE_MAX_EQD;
  180. if (rx_min > rx_max)
  181. rx_min = rx_max;
  182. rx_eq->max_eqd = rx_max;
  183. rx_eq->min_eqd = rx_min;
  184. if (rx_eq->cur_eqd > rx_max)
  185. rx_eq->cur_eqd = rx_max;
  186. if (rx_eq->cur_eqd < rx_min)
  187. rx_eq->cur_eqd = rx_min;
  188. } else {
  189. if (rx_cur > BE_MAX_EQD)
  190. rx_cur = BE_MAX_EQD;
  191. if (rx_eq->cur_eqd != rx_cur) {
  192. status = be_cmd_modify_eqd(adapter, rx_eq->q.id,
  193. rx_cur);
  194. if (!status)
  195. rx_eq->cur_eqd = rx_cur;
  196. }
  197. }
  198. }
  199. tx_max = coalesce->tx_coalesce_usecs_high;
  200. tx_min = coalesce->tx_coalesce_usecs_low;
  201. tx_cur = coalesce->tx_coalesce_usecs;
  202. if (tx_cur > BE_MAX_EQD)
  203. tx_cur = BE_MAX_EQD;
  204. if (tx_eq->cur_eqd != tx_cur) {
  205. status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
  206. if (!status)
  207. tx_eq->cur_eqd = tx_cur;
  208. }
  209. return 0;
  210. }
  211. static u32 be_get_rx_csum(struct net_device *netdev)
  212. {
  213. struct be_adapter *adapter = netdev_priv(netdev);
  214. return adapter->rx_csum;
  215. }
  216. static int be_set_rx_csum(struct net_device *netdev, uint32_t data)
  217. {
  218. struct be_adapter *adapter = netdev_priv(netdev);
  219. if (data)
  220. adapter->rx_csum = true;
  221. else
  222. adapter->rx_csum = false;
  223. return 0;
  224. }
  225. static void
  226. be_get_ethtool_stats(struct net_device *netdev,
  227. struct ethtool_stats *stats, uint64_t *data)
  228. {
  229. struct be_adapter *adapter = netdev_priv(netdev);
  230. struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats_cmd.va);
  231. struct be_erx_stats *erx_stats = &hw_stats->erx;
  232. struct be_rx_obj *rxo;
  233. void *p = NULL;
  234. int i, j;
  235. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  236. switch (et_stats[i].type) {
  237. case NETSTAT:
  238. p = &netdev->stats;
  239. break;
  240. case DRVSTAT_TX:
  241. p = &adapter->tx_stats;
  242. break;
  243. case PORTSTAT:
  244. p = &hw_stats->rxf.port[adapter->port_num];
  245. break;
  246. case MISCSTAT:
  247. p = &hw_stats->rxf;
  248. break;
  249. }
  250. p = (u8 *)p + et_stats[i].offset;
  251. data[i] = (et_stats[i].size == sizeof(u64)) ?
  252. *(u64 *)p: *(u32 *)p;
  253. }
  254. for_all_rx_queues(adapter, rxo, j) {
  255. for (i = 0; i < ETHTOOL_RXSTATS_NUM; i++) {
  256. switch (et_rx_stats[i].type) {
  257. case DRVSTAT_RX:
  258. p = (u8 *)&rxo->stats + et_rx_stats[i].offset;
  259. break;
  260. case ERXSTAT:
  261. p = (u32 *)erx_stats + rxo->q.id;
  262. break;
  263. }
  264. data[ETHTOOL_STATS_NUM + j * ETHTOOL_RXSTATS_NUM + i] =
  265. (et_rx_stats[i].size == sizeof(u64)) ?
  266. *(u64 *)p: *(u32 *)p;
  267. }
  268. }
  269. }
  270. static void
  271. be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
  272. uint8_t *data)
  273. {
  274. struct be_adapter *adapter = netdev_priv(netdev);
  275. int i, j;
  276. switch (stringset) {
  277. case ETH_SS_STATS:
  278. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  279. memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
  280. data += ETH_GSTRING_LEN;
  281. }
  282. for (i = 0; i < adapter->num_rx_qs; i++) {
  283. for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
  284. sprintf(data, "rxq%d: %s", i,
  285. et_rx_stats[j].desc);
  286. data += ETH_GSTRING_LEN;
  287. }
  288. }
  289. break;
  290. case ETH_SS_TEST:
  291. for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
  292. memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
  293. data += ETH_GSTRING_LEN;
  294. }
  295. break;
  296. }
  297. }
  298. static int be_get_sset_count(struct net_device *netdev, int stringset)
  299. {
  300. struct be_adapter *adapter = netdev_priv(netdev);
  301. switch (stringset) {
  302. case ETH_SS_TEST:
  303. return ETHTOOL_TESTS_NUM;
  304. case ETH_SS_STATS:
  305. return ETHTOOL_STATS_NUM +
  306. adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM;
  307. default:
  308. return -EINVAL;
  309. }
  310. }
  311. static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  312. {
  313. struct be_adapter *adapter = netdev_priv(netdev);
  314. struct be_dma_mem phy_cmd;
  315. struct be_cmd_resp_get_phy_info *resp;
  316. u8 mac_speed = 0;
  317. u16 link_speed = 0;
  318. bool link_up = false;
  319. int status;
  320. u16 intf_type;
  321. if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) {
  322. status = be_cmd_link_status_query(adapter, &link_up,
  323. &mac_speed, &link_speed);
  324. be_link_status_update(adapter, link_up);
  325. /* link_speed is in units of 10 Mbps */
  326. if (link_speed) {
  327. ecmd->speed = link_speed*10;
  328. } else {
  329. switch (mac_speed) {
  330. case PHY_LINK_SPEED_1GBPS:
  331. ecmd->speed = SPEED_1000;
  332. break;
  333. case PHY_LINK_SPEED_10GBPS:
  334. ecmd->speed = SPEED_10000;
  335. break;
  336. }
  337. }
  338. phy_cmd.size = sizeof(struct be_cmd_req_get_phy_info);
  339. phy_cmd.va = pci_alloc_consistent(adapter->pdev, phy_cmd.size,
  340. &phy_cmd.dma);
  341. if (!phy_cmd.va) {
  342. dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
  343. return -ENOMEM;
  344. }
  345. status = be_cmd_get_phy_info(adapter, &phy_cmd);
  346. if (!status) {
  347. resp = (struct be_cmd_resp_get_phy_info *) phy_cmd.va;
  348. intf_type = le16_to_cpu(resp->interface_type);
  349. switch (intf_type) {
  350. case PHY_TYPE_XFP_10GB:
  351. case PHY_TYPE_SFP_1GB:
  352. case PHY_TYPE_SFP_PLUS_10GB:
  353. ecmd->port = PORT_FIBRE;
  354. break;
  355. default:
  356. ecmd->port = PORT_TP;
  357. break;
  358. }
  359. switch (intf_type) {
  360. case PHY_TYPE_KR_10GB:
  361. case PHY_TYPE_KX4_10GB:
  362. ecmd->autoneg = AUTONEG_ENABLE;
  363. ecmd->transceiver = XCVR_INTERNAL;
  364. break;
  365. default:
  366. ecmd->autoneg = AUTONEG_DISABLE;
  367. ecmd->transceiver = XCVR_EXTERNAL;
  368. break;
  369. }
  370. }
  371. /* Save for future use */
  372. adapter->link_speed = ecmd->speed;
  373. adapter->port_type = ecmd->port;
  374. adapter->transceiver = ecmd->transceiver;
  375. adapter->autoneg = ecmd->autoneg;
  376. pci_free_consistent(adapter->pdev, phy_cmd.size,
  377. phy_cmd.va, phy_cmd.dma);
  378. } else {
  379. ecmd->speed = adapter->link_speed;
  380. ecmd->port = adapter->port_type;
  381. ecmd->transceiver = adapter->transceiver;
  382. ecmd->autoneg = adapter->autoneg;
  383. }
  384. ecmd->duplex = DUPLEX_FULL;
  385. ecmd->phy_address = adapter->port_num;
  386. switch (ecmd->port) {
  387. case PORT_FIBRE:
  388. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
  389. break;
  390. case PORT_TP:
  391. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP);
  392. break;
  393. case PORT_AUI:
  394. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI);
  395. break;
  396. }
  397. if (ecmd->autoneg) {
  398. ecmd->supported |= SUPPORTED_1000baseT_Full;
  399. ecmd->supported |= SUPPORTED_Autoneg;
  400. ecmd->advertising |= (ADVERTISED_10000baseT_Full |
  401. ADVERTISED_1000baseT_Full);
  402. }
  403. return 0;
  404. }
  405. static void
  406. be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
  407. {
  408. struct be_adapter *adapter = netdev_priv(netdev);
  409. ring->rx_max_pending = adapter->rx_obj[0].q.len;
  410. ring->tx_max_pending = adapter->tx_obj.q.len;
  411. ring->rx_pending = atomic_read(&adapter->rx_obj[0].q.used);
  412. ring->tx_pending = atomic_read(&adapter->tx_obj.q.used);
  413. }
  414. static void
  415. be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  416. {
  417. struct be_adapter *adapter = netdev_priv(netdev);
  418. be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
  419. ecmd->autoneg = 0;
  420. }
  421. static int
  422. be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  423. {
  424. struct be_adapter *adapter = netdev_priv(netdev);
  425. int status;
  426. if (ecmd->autoneg != 0)
  427. return -EINVAL;
  428. adapter->tx_fc = ecmd->tx_pause;
  429. adapter->rx_fc = ecmd->rx_pause;
  430. status = be_cmd_set_flow_control(adapter,
  431. adapter->tx_fc, adapter->rx_fc);
  432. if (status)
  433. dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
  434. return status;
  435. }
  436. static int
  437. be_phys_id(struct net_device *netdev, u32 data)
  438. {
  439. struct be_adapter *adapter = netdev_priv(netdev);
  440. int status;
  441. u32 cur;
  442. be_cmd_get_beacon_state(adapter, adapter->port_num, &cur);
  443. if (cur == BEACON_STATE_ENABLED)
  444. return 0;
  445. if (data < 2)
  446. data = 2;
  447. status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0,
  448. BEACON_STATE_ENABLED);
  449. set_current_state(TASK_INTERRUPTIBLE);
  450. schedule_timeout(data*HZ);
  451. status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0,
  452. BEACON_STATE_DISABLED);
  453. return status;
  454. }
  455. static void
  456. be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  457. {
  458. struct be_adapter *adapter = netdev_priv(netdev);
  459. wol->supported = WAKE_MAGIC;
  460. if (adapter->wol)
  461. wol->wolopts = WAKE_MAGIC;
  462. else
  463. wol->wolopts = 0;
  464. memset(&wol->sopass, 0, sizeof(wol->sopass));
  465. }
  466. static int
  467. be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  468. {
  469. struct be_adapter *adapter = netdev_priv(netdev);
  470. if (wol->wolopts & ~WAKE_MAGIC)
  471. return -EINVAL;
  472. if (wol->wolopts & WAKE_MAGIC)
  473. adapter->wol = true;
  474. else
  475. adapter->wol = false;
  476. return 0;
  477. }
  478. static int
  479. be_test_ddr_dma(struct be_adapter *adapter)
  480. {
  481. int ret, i;
  482. struct be_dma_mem ddrdma_cmd;
  483. static const u64 pattern[2] = {
  484. 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
  485. };
  486. ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
  487. ddrdma_cmd.va = pci_alloc_consistent(adapter->pdev, ddrdma_cmd.size,
  488. &ddrdma_cmd.dma);
  489. if (!ddrdma_cmd.va) {
  490. dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
  491. return -ENOMEM;
  492. }
  493. for (i = 0; i < 2; i++) {
  494. ret = be_cmd_ddr_dma_test(adapter, pattern[i],
  495. 4096, &ddrdma_cmd);
  496. if (ret != 0)
  497. goto err;
  498. }
  499. err:
  500. pci_free_consistent(adapter->pdev, ddrdma_cmd.size,
  501. ddrdma_cmd.va, ddrdma_cmd.dma);
  502. return ret;
  503. }
  504. static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
  505. u64 *status)
  506. {
  507. be_cmd_set_loopback(adapter, adapter->port_num,
  508. loopback_type, 1);
  509. *status = be_cmd_loopback_test(adapter, adapter->port_num,
  510. loopback_type, 1500,
  511. 2, 0xabc);
  512. be_cmd_set_loopback(adapter, adapter->port_num,
  513. BE_NO_LOOPBACK, 1);
  514. return *status;
  515. }
  516. static void
  517. be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
  518. {
  519. struct be_adapter *adapter = netdev_priv(netdev);
  520. bool link_up;
  521. u8 mac_speed = 0;
  522. u16 qos_link_speed = 0;
  523. memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
  524. if (test->flags & ETH_TEST_FL_OFFLINE) {
  525. if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
  526. &data[0]) != 0) {
  527. test->flags |= ETH_TEST_FL_FAILED;
  528. }
  529. if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
  530. &data[1]) != 0) {
  531. test->flags |= ETH_TEST_FL_FAILED;
  532. }
  533. if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
  534. &data[2]) != 0) {
  535. test->flags |= ETH_TEST_FL_FAILED;
  536. }
  537. }
  538. if (be_test_ddr_dma(adapter) != 0) {
  539. data[3] = 1;
  540. test->flags |= ETH_TEST_FL_FAILED;
  541. }
  542. if (be_cmd_link_status_query(adapter, &link_up, &mac_speed,
  543. &qos_link_speed) != 0) {
  544. test->flags |= ETH_TEST_FL_FAILED;
  545. data[4] = -1;
  546. } else if (mac_speed) {
  547. data[4] = 1;
  548. }
  549. }
  550. static int
  551. be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
  552. {
  553. struct be_adapter *adapter = netdev_priv(netdev);
  554. char file_name[ETHTOOL_FLASH_MAX_FILENAME];
  555. u32 region;
  556. file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
  557. strcpy(file_name, efl->data);
  558. region = efl->region;
  559. return be_load_fw(adapter, file_name);
  560. }
  561. static int
  562. be_get_eeprom_len(struct net_device *netdev)
  563. {
  564. return BE_READ_SEEPROM_LEN;
  565. }
  566. static int
  567. be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
  568. uint8_t *data)
  569. {
  570. struct be_adapter *adapter = netdev_priv(netdev);
  571. struct be_dma_mem eeprom_cmd;
  572. struct be_cmd_resp_seeprom_read *resp;
  573. int status;
  574. if (!eeprom->len)
  575. return -EINVAL;
  576. eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
  577. memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
  578. eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
  579. eeprom_cmd.va = pci_alloc_consistent(adapter->pdev, eeprom_cmd.size,
  580. &eeprom_cmd.dma);
  581. if (!eeprom_cmd.va) {
  582. dev_err(&adapter->pdev->dev,
  583. "Memory allocation failure. Could not read eeprom\n");
  584. return -ENOMEM;
  585. }
  586. status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
  587. if (!status) {
  588. resp = (struct be_cmd_resp_seeprom_read *) eeprom_cmd.va;
  589. memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
  590. }
  591. pci_free_consistent(adapter->pdev, eeprom_cmd.size, eeprom_cmd.va,
  592. eeprom_cmd.dma);
  593. return status;
  594. }
  595. const struct ethtool_ops be_ethtool_ops = {
  596. .get_settings = be_get_settings,
  597. .get_drvinfo = be_get_drvinfo,
  598. .get_wol = be_get_wol,
  599. .set_wol = be_set_wol,
  600. .get_link = ethtool_op_get_link,
  601. .get_eeprom_len = be_get_eeprom_len,
  602. .get_eeprom = be_read_eeprom,
  603. .get_coalesce = be_get_coalesce,
  604. .set_coalesce = be_set_coalesce,
  605. .get_ringparam = be_get_ringparam,
  606. .get_pauseparam = be_get_pauseparam,
  607. .set_pauseparam = be_set_pauseparam,
  608. .get_rx_csum = be_get_rx_csum,
  609. .set_rx_csum = be_set_rx_csum,
  610. .get_tx_csum = ethtool_op_get_tx_csum,
  611. .set_tx_csum = ethtool_op_set_tx_hw_csum,
  612. .get_sg = ethtool_op_get_sg,
  613. .set_sg = ethtool_op_set_sg,
  614. .get_tso = ethtool_op_get_tso,
  615. .set_tso = ethtool_op_set_tso,
  616. .get_strings = be_get_stat_strings,
  617. .phys_id = be_phys_id,
  618. .get_sset_count = be_get_sset_count,
  619. .get_ethtool_stats = be_get_ethtool_stats,
  620. .flash_device = be_do_flash,
  621. .self_test = be_self_test,
  622. };