be_ethtool.c 18 KB

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