be_ethtool.c 17 KB

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