be_ethtool.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. /*
  2. * Copyright (C) 2005 - 2011 Emulex
  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@emulex.com
  12. *
  13. * Emulex
  14. * 3333 Susan Street
  15. * Costa Mesa, CA 92626
  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 {DRVSTAT_TX, DRVSTAT_RX, DRVSTAT};
  27. #define FIELDINFO(_struct, field) FIELD_SIZEOF(_struct, field), \
  28. offsetof(_struct, field)
  29. #define DRVSTAT_TX_INFO(field) #field, DRVSTAT_TX,\
  30. FIELDINFO(struct be_tx_stats, field)
  31. #define DRVSTAT_RX_INFO(field) #field, DRVSTAT_RX,\
  32. FIELDINFO(struct be_rx_stats, field)
  33. #define DRVSTAT_INFO(field) #field, DRVSTAT,\
  34. FIELDINFO(struct be_drv_stats, field)
  35. static const struct be_ethtool_stat et_stats[] = {
  36. {DRVSTAT_INFO(tx_events)},
  37. {DRVSTAT_INFO(rx_crc_errors)},
  38. {DRVSTAT_INFO(rx_alignment_symbol_errors)},
  39. {DRVSTAT_INFO(rx_pause_frames)},
  40. {DRVSTAT_INFO(rx_control_frames)},
  41. {DRVSTAT_INFO(rx_in_range_errors)},
  42. {DRVSTAT_INFO(rx_out_range_errors)},
  43. {DRVSTAT_INFO(rx_frame_too_long)},
  44. {DRVSTAT_INFO(rx_address_match_errors)},
  45. {DRVSTAT_INFO(rx_dropped_too_small)},
  46. {DRVSTAT_INFO(rx_dropped_too_short)},
  47. {DRVSTAT_INFO(rx_dropped_header_too_small)},
  48. {DRVSTAT_INFO(rx_dropped_tcp_length)},
  49. {DRVSTAT_INFO(rx_dropped_runt)},
  50. {DRVSTAT_INFO(rxpp_fifo_overflow_drop)},
  51. {DRVSTAT_INFO(rx_input_fifo_overflow_drop)},
  52. {DRVSTAT_INFO(rx_ip_checksum_errs)},
  53. {DRVSTAT_INFO(rx_tcp_checksum_errs)},
  54. {DRVSTAT_INFO(rx_udp_checksum_errs)},
  55. {DRVSTAT_INFO(tx_pauseframes)},
  56. {DRVSTAT_INFO(tx_controlframes)},
  57. {DRVSTAT_INFO(rx_priority_pause_frames)},
  58. {DRVSTAT_INFO(pmem_fifo_overflow_drop)},
  59. {DRVSTAT_INFO(jabber_events)},
  60. {DRVSTAT_INFO(rx_drops_no_pbuf)},
  61. {DRVSTAT_INFO(rx_drops_no_txpb)},
  62. {DRVSTAT_INFO(rx_drops_no_erx_descr)},
  63. {DRVSTAT_INFO(rx_drops_no_tpre_descr)},
  64. {DRVSTAT_INFO(rx_drops_too_many_frags)},
  65. {DRVSTAT_INFO(rx_drops_invalid_ring)},
  66. {DRVSTAT_INFO(forwarded_packets)},
  67. {DRVSTAT_INFO(rx_drops_mtu)},
  68. {DRVSTAT_INFO(eth_red_drops)},
  69. {DRVSTAT_INFO(be_on_die_temperature)}
  70. };
  71. #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
  72. /* Stats related to multi RX queues: get_stats routine assumes bytes, pkts
  73. * are first and second members respectively.
  74. */
  75. static const struct be_ethtool_stat et_rx_stats[] = {
  76. {DRVSTAT_RX_INFO(rx_bytes)},/* If moving this member see above note */
  77. {DRVSTAT_RX_INFO(rx_pkts)}, /* If moving this member see above note */
  78. {DRVSTAT_RX_INFO(rx_polls)},
  79. {DRVSTAT_RX_INFO(rx_events)},
  80. {DRVSTAT_RX_INFO(rx_compl)},
  81. {DRVSTAT_RX_INFO(rx_mcast_pkts)},
  82. {DRVSTAT_RX_INFO(rx_post_fail)},
  83. {DRVSTAT_RX_INFO(rx_drops_no_skbs)},
  84. {DRVSTAT_RX_INFO(rx_drops_no_frags)}
  85. };
  86. #define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
  87. /* Stats related to multi TX queues: get_stats routine assumes compl is the
  88. * first member
  89. */
  90. static const struct be_ethtool_stat et_tx_stats[] = {
  91. {DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */
  92. {DRVSTAT_TX_INFO(tx_bytes)},
  93. {DRVSTAT_TX_INFO(tx_pkts)},
  94. {DRVSTAT_TX_INFO(tx_reqs)},
  95. {DRVSTAT_TX_INFO(tx_wrbs)},
  96. {DRVSTAT_TX_INFO(tx_compl)},
  97. {DRVSTAT_TX_INFO(tx_stops)}
  98. };
  99. #define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats))
  100. static const char et_self_tests[][ETH_GSTRING_LEN] = {
  101. "MAC Loopback test",
  102. "PHY Loopback test",
  103. "External Loopback test",
  104. "DDR DMA test",
  105. "Link test"
  106. };
  107. #define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
  108. #define BE_MAC_LOOPBACK 0x0
  109. #define BE_PHY_LOOPBACK 0x1
  110. #define BE_ONE_PORT_EXT_LOOPBACK 0x2
  111. #define BE_NO_LOOPBACK 0xff
  112. static void
  113. be_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
  114. {
  115. struct be_adapter *adapter = netdev_priv(netdev);
  116. strcpy(drvinfo->driver, DRV_NAME);
  117. strcpy(drvinfo->version, DRV_VER);
  118. strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN);
  119. strcpy(drvinfo->bus_info, pci_name(adapter->pdev));
  120. drvinfo->testinfo_len = 0;
  121. drvinfo->regdump_len = 0;
  122. drvinfo->eedump_len = 0;
  123. }
  124. static int
  125. be_get_reg_len(struct net_device *netdev)
  126. {
  127. struct be_adapter *adapter = netdev_priv(netdev);
  128. u32 log_size = 0;
  129. if (be_physfn(adapter))
  130. be_cmd_get_reg_len(adapter, &log_size);
  131. return log_size;
  132. }
  133. static void
  134. be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
  135. {
  136. struct be_adapter *adapter = netdev_priv(netdev);
  137. if (be_physfn(adapter)) {
  138. memset(buf, 0, regs->len);
  139. be_cmd_get_regs(adapter, regs->len, buf);
  140. }
  141. }
  142. static int
  143. be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
  144. {
  145. struct be_adapter *adapter = netdev_priv(netdev);
  146. struct be_eq_obj *rx_eq = &adapter->rx_obj[0].rx_eq;
  147. struct be_eq_obj *tx_eq = &adapter->tx_eq;
  148. coalesce->rx_coalesce_usecs = rx_eq->cur_eqd;
  149. coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd;
  150. coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd;
  151. coalesce->tx_coalesce_usecs = tx_eq->cur_eqd;
  152. coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd;
  153. coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd;
  154. coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
  155. coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
  156. return 0;
  157. }
  158. /*
  159. * This routine is used to set interrup coalescing delay
  160. */
  161. static int
  162. be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
  163. {
  164. struct be_adapter *adapter = netdev_priv(netdev);
  165. struct be_rx_obj *rxo;
  166. struct be_eq_obj *rx_eq;
  167. struct be_eq_obj *tx_eq = &adapter->tx_eq;
  168. u32 rx_max, rx_min, rx_cur;
  169. int status = 0, i;
  170. u32 tx_cur;
  171. if (coalesce->use_adaptive_tx_coalesce == 1)
  172. return -EINVAL;
  173. for_all_rx_queues(adapter, rxo, i) {
  174. rx_eq = &rxo->rx_eq;
  175. if (!rx_eq->enable_aic && coalesce->use_adaptive_rx_coalesce)
  176. rx_eq->cur_eqd = 0;
  177. rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce;
  178. rx_max = coalesce->rx_coalesce_usecs_high;
  179. rx_min = coalesce->rx_coalesce_usecs_low;
  180. rx_cur = coalesce->rx_coalesce_usecs;
  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. }
  203. tx_cur = coalesce->tx_coalesce_usecs;
  204. if (tx_cur > BE_MAX_EQD)
  205. tx_cur = BE_MAX_EQD;
  206. if (tx_eq->cur_eqd != tx_cur) {
  207. status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
  208. if (!status)
  209. tx_eq->cur_eqd = tx_cur;
  210. }
  211. return 0;
  212. }
  213. static void
  214. be_get_ethtool_stats(struct net_device *netdev,
  215. struct ethtool_stats *stats, uint64_t *data)
  216. {
  217. struct be_adapter *adapter = netdev_priv(netdev);
  218. struct be_rx_obj *rxo;
  219. struct be_tx_obj *txo;
  220. void *p;
  221. unsigned int i, j, base = 0, start;
  222. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  223. p = (u8 *)&adapter->drv_stats + et_stats[i].offset;
  224. data[i] = *(u32 *)p;
  225. }
  226. base += ETHTOOL_STATS_NUM;
  227. for_all_rx_queues(adapter, rxo, j) {
  228. struct be_rx_stats *stats = rx_stats(rxo);
  229. do {
  230. start = u64_stats_fetch_begin_bh(&stats->sync);
  231. data[base] = stats->rx_bytes;
  232. data[base + 1] = stats->rx_pkts;
  233. } while (u64_stats_fetch_retry_bh(&stats->sync, start));
  234. for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) {
  235. p = (u8 *)stats + et_rx_stats[i].offset;
  236. data[base + i] = *(u32 *)p;
  237. }
  238. base += ETHTOOL_RXSTATS_NUM;
  239. }
  240. for_all_tx_queues(adapter, txo, j) {
  241. struct be_tx_stats *stats = tx_stats(txo);
  242. do {
  243. start = u64_stats_fetch_begin_bh(&stats->sync_compl);
  244. data[base] = stats->tx_compl;
  245. } while (u64_stats_fetch_retry_bh(&stats->sync_compl, start));
  246. do {
  247. start = u64_stats_fetch_begin_bh(&stats->sync);
  248. for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) {
  249. p = (u8 *)stats + et_tx_stats[i].offset;
  250. data[base + i] =
  251. (et_tx_stats[i].size == sizeof(u64)) ?
  252. *(u64 *)p : *(u32 *)p;
  253. }
  254. } while (u64_stats_fetch_retry_bh(&stats->sync, start));
  255. base += ETHTOOL_TXSTATS_NUM;
  256. }
  257. }
  258. static void
  259. be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
  260. uint8_t *data)
  261. {
  262. struct be_adapter *adapter = netdev_priv(netdev);
  263. int i, j;
  264. switch (stringset) {
  265. case ETH_SS_STATS:
  266. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  267. memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
  268. data += ETH_GSTRING_LEN;
  269. }
  270. for (i = 0; i < adapter->num_rx_qs; i++) {
  271. for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
  272. sprintf(data, "rxq%d: %s", i,
  273. et_rx_stats[j].desc);
  274. data += ETH_GSTRING_LEN;
  275. }
  276. }
  277. for (i = 0; i < adapter->num_tx_qs; i++) {
  278. for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) {
  279. sprintf(data, "txq%d: %s", i,
  280. et_tx_stats[j].desc);
  281. data += ETH_GSTRING_LEN;
  282. }
  283. }
  284. break;
  285. case ETH_SS_TEST:
  286. for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
  287. memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
  288. data += ETH_GSTRING_LEN;
  289. }
  290. break;
  291. }
  292. }
  293. static int be_get_sset_count(struct net_device *netdev, int stringset)
  294. {
  295. struct be_adapter *adapter = netdev_priv(netdev);
  296. switch (stringset) {
  297. case ETH_SS_TEST:
  298. return ETHTOOL_TESTS_NUM;
  299. case ETH_SS_STATS:
  300. return ETHTOOL_STATS_NUM +
  301. adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
  302. adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
  303. default:
  304. return -EINVAL;
  305. }
  306. }
  307. static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  308. {
  309. struct be_adapter *adapter = netdev_priv(netdev);
  310. struct be_phy_info phy_info;
  311. u8 mac_speed = 0;
  312. u16 link_speed = 0;
  313. int status;
  314. if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) {
  315. status = be_cmd_link_status_query(adapter, &mac_speed,
  316. &link_speed, 0);
  317. /* link_speed is in units of 10 Mbps */
  318. if (link_speed) {
  319. ethtool_cmd_speed_set(ecmd, link_speed*10);
  320. } else {
  321. switch (mac_speed) {
  322. case PHY_LINK_SPEED_10MBPS:
  323. ethtool_cmd_speed_set(ecmd, SPEED_10);
  324. break;
  325. case PHY_LINK_SPEED_100MBPS:
  326. ethtool_cmd_speed_set(ecmd, SPEED_100);
  327. break;
  328. case PHY_LINK_SPEED_1GBPS:
  329. ethtool_cmd_speed_set(ecmd, SPEED_1000);
  330. break;
  331. case PHY_LINK_SPEED_10GBPS:
  332. ethtool_cmd_speed_set(ecmd, SPEED_10000);
  333. break;
  334. case PHY_LINK_SPEED_ZERO:
  335. ethtool_cmd_speed_set(ecmd, 0);
  336. break;
  337. }
  338. }
  339. status = be_cmd_get_phy_info(adapter, &phy_info);
  340. if (!status) {
  341. switch (phy_info.interface_type) {
  342. case PHY_TYPE_XFP_10GB:
  343. case PHY_TYPE_SFP_1GB:
  344. case PHY_TYPE_SFP_PLUS_10GB:
  345. ecmd->port = PORT_FIBRE;
  346. break;
  347. default:
  348. ecmd->port = PORT_TP;
  349. break;
  350. }
  351. switch (phy_info.interface_type) {
  352. case PHY_TYPE_KR_10GB:
  353. case PHY_TYPE_KX4_10GB:
  354. ecmd->autoneg = AUTONEG_ENABLE;
  355. ecmd->transceiver = XCVR_INTERNAL;
  356. break;
  357. default:
  358. ecmd->autoneg = AUTONEG_DISABLE;
  359. ecmd->transceiver = XCVR_EXTERNAL;
  360. break;
  361. }
  362. }
  363. /* Save for future use */
  364. adapter->link_speed = ethtool_cmd_speed(ecmd);
  365. adapter->port_type = ecmd->port;
  366. adapter->transceiver = ecmd->transceiver;
  367. adapter->autoneg = ecmd->autoneg;
  368. } else {
  369. ethtool_cmd_speed_set(ecmd, adapter->link_speed);
  370. ecmd->port = adapter->port_type;
  371. ecmd->transceiver = adapter->transceiver;
  372. ecmd->autoneg = adapter->autoneg;
  373. }
  374. ecmd->duplex = DUPLEX_FULL;
  375. ecmd->phy_address = adapter->port_num;
  376. switch (ecmd->port) {
  377. case PORT_FIBRE:
  378. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
  379. break;
  380. case PORT_TP:
  381. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP);
  382. break;
  383. case PORT_AUI:
  384. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI);
  385. break;
  386. }
  387. if (ecmd->autoneg) {
  388. ecmd->supported |= SUPPORTED_1000baseT_Full;
  389. ecmd->supported |= SUPPORTED_Autoneg;
  390. ecmd->advertising |= (ADVERTISED_10000baseT_Full |
  391. ADVERTISED_1000baseT_Full);
  392. }
  393. return 0;
  394. }
  395. static void
  396. be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
  397. {
  398. struct be_adapter *adapter = netdev_priv(netdev);
  399. ring->rx_max_pending = adapter->rx_obj[0].q.len;
  400. ring->tx_max_pending = adapter->tx_obj[0].q.len;
  401. ring->rx_pending = atomic_read(&adapter->rx_obj[0].q.used);
  402. ring->tx_pending = atomic_read(&adapter->tx_obj[0].q.used);
  403. }
  404. static void
  405. be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  406. {
  407. struct be_adapter *adapter = netdev_priv(netdev);
  408. be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
  409. ecmd->autoneg = 0;
  410. }
  411. static int
  412. be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  413. {
  414. struct be_adapter *adapter = netdev_priv(netdev);
  415. int status;
  416. if (ecmd->autoneg != 0)
  417. return -EINVAL;
  418. adapter->tx_fc = ecmd->tx_pause;
  419. adapter->rx_fc = ecmd->rx_pause;
  420. status = be_cmd_set_flow_control(adapter,
  421. adapter->tx_fc, adapter->rx_fc);
  422. if (status)
  423. dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
  424. return status;
  425. }
  426. static int
  427. be_set_phys_id(struct net_device *netdev,
  428. enum ethtool_phys_id_state state)
  429. {
  430. struct be_adapter *adapter = netdev_priv(netdev);
  431. switch (state) {
  432. case ETHTOOL_ID_ACTIVE:
  433. be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
  434. &adapter->beacon_state);
  435. return 1; /* cycle on/off once per second */
  436. case ETHTOOL_ID_ON:
  437. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  438. BEACON_STATE_ENABLED);
  439. break;
  440. case ETHTOOL_ID_OFF:
  441. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  442. BEACON_STATE_DISABLED);
  443. break;
  444. case ETHTOOL_ID_INACTIVE:
  445. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  446. adapter->beacon_state);
  447. }
  448. return 0;
  449. }
  450. static bool
  451. be_is_wol_supported(struct be_adapter *adapter)
  452. {
  453. if (!be_physfn(adapter))
  454. return false;
  455. else
  456. return true;
  457. }
  458. static void
  459. be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  460. {
  461. struct be_adapter *adapter = netdev_priv(netdev);
  462. if (be_is_wol_supported(adapter))
  463. wol->supported = WAKE_MAGIC;
  464. if (adapter->wol)
  465. wol->wolopts = WAKE_MAGIC;
  466. else
  467. wol->wolopts = 0;
  468. memset(&wol->sopass, 0, sizeof(wol->sopass));
  469. }
  470. static int
  471. be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  472. {
  473. struct be_adapter *adapter = netdev_priv(netdev);
  474. if (wol->wolopts & ~WAKE_MAGIC)
  475. return -EINVAL;
  476. if ((wol->wolopts & WAKE_MAGIC) && be_is_wol_supported(adapter))
  477. adapter->wol = true;
  478. else
  479. adapter->wol = false;
  480. return 0;
  481. }
  482. static int
  483. be_test_ddr_dma(struct be_adapter *adapter)
  484. {
  485. int ret, i;
  486. struct be_dma_mem ddrdma_cmd;
  487. static const u64 pattern[2] = {
  488. 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
  489. };
  490. ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
  491. ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
  492. &ddrdma_cmd.dma, GFP_KERNEL);
  493. if (!ddrdma_cmd.va) {
  494. dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
  495. return -ENOMEM;
  496. }
  497. for (i = 0; i < 2; i++) {
  498. ret = be_cmd_ddr_dma_test(adapter, pattern[i],
  499. 4096, &ddrdma_cmd);
  500. if (ret != 0)
  501. goto err;
  502. }
  503. err:
  504. dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
  505. ddrdma_cmd.dma);
  506. return ret;
  507. }
  508. static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
  509. u64 *status)
  510. {
  511. be_cmd_set_loopback(adapter, adapter->hba_port_num,
  512. loopback_type, 1);
  513. *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
  514. loopback_type, 1500,
  515. 2, 0xabc);
  516. be_cmd_set_loopback(adapter, adapter->hba_port_num,
  517. BE_NO_LOOPBACK, 1);
  518. return *status;
  519. }
  520. static void
  521. be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
  522. {
  523. struct be_adapter *adapter = netdev_priv(netdev);
  524. u8 mac_speed = 0;
  525. u16 qos_link_speed = 0;
  526. memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
  527. if (test->flags & ETH_TEST_FL_OFFLINE) {
  528. if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
  529. &data[0]) != 0) {
  530. test->flags |= ETH_TEST_FL_FAILED;
  531. }
  532. if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
  533. &data[1]) != 0) {
  534. test->flags |= ETH_TEST_FL_FAILED;
  535. }
  536. if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
  537. &data[2]) != 0) {
  538. test->flags |= ETH_TEST_FL_FAILED;
  539. }
  540. }
  541. if (be_test_ddr_dma(adapter) != 0) {
  542. data[3] = 1;
  543. test->flags |= ETH_TEST_FL_FAILED;
  544. }
  545. if (be_cmd_link_status_query(adapter, &mac_speed,
  546. &qos_link_speed, 0) != 0) {
  547. test->flags |= ETH_TEST_FL_FAILED;
  548. data[4] = -1;
  549. } else if (!mac_speed) {
  550. test->flags |= ETH_TEST_FL_FAILED;
  551. data[4] = 1;
  552. }
  553. }
  554. static int
  555. be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
  556. {
  557. struct be_adapter *adapter = netdev_priv(netdev);
  558. char file_name[ETHTOOL_FLASH_MAX_FILENAME];
  559. file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
  560. strcpy(file_name, efl->data);
  561. return be_load_fw(adapter, file_name);
  562. }
  563. static int
  564. be_get_eeprom_len(struct net_device *netdev)
  565. {
  566. return BE_READ_SEEPROM_LEN;
  567. }
  568. static int
  569. be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
  570. uint8_t *data)
  571. {
  572. struct be_adapter *adapter = netdev_priv(netdev);
  573. struct be_dma_mem eeprom_cmd;
  574. struct be_cmd_resp_seeprom_read *resp;
  575. int status;
  576. if (!eeprom->len)
  577. return -EINVAL;
  578. eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
  579. memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
  580. eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
  581. eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
  582. &eeprom_cmd.dma, GFP_KERNEL);
  583. if (!eeprom_cmd.va) {
  584. dev_err(&adapter->pdev->dev,
  585. "Memory allocation failure. Could not read eeprom\n");
  586. return -ENOMEM;
  587. }
  588. status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
  589. if (!status) {
  590. resp = eeprom_cmd.va;
  591. memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
  592. }
  593. dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
  594. eeprom_cmd.dma);
  595. return status;
  596. }
  597. const struct ethtool_ops be_ethtool_ops = {
  598. .get_settings = be_get_settings,
  599. .get_drvinfo = be_get_drvinfo,
  600. .get_wol = be_get_wol,
  601. .set_wol = be_set_wol,
  602. .get_link = ethtool_op_get_link,
  603. .get_eeprom_len = be_get_eeprom_len,
  604. .get_eeprom = be_read_eeprom,
  605. .get_coalesce = be_get_coalesce,
  606. .set_coalesce = be_set_coalesce,
  607. .get_ringparam = be_get_ringparam,
  608. .get_pauseparam = be_get_pauseparam,
  609. .set_pauseparam = be_set_pauseparam,
  610. .get_strings = be_get_stat_strings,
  611. .set_phys_id = be_set_phys_id,
  612. .get_sset_count = be_get_sset_count,
  613. .get_ethtool_stats = be_get_ethtool_stats,
  614. .get_regs_len = be_get_reg_len,
  615. .get_regs = be_get_regs,
  616. .flash_device = be_do_flash,
  617. .self_test = be_self_test,
  618. };