be_ethtool.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  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 be_get_drvinfo(struct net_device *netdev,
  113. struct ethtool_drvinfo *drvinfo)
  114. {
  115. struct be_adapter *adapter = netdev_priv(netdev);
  116. char fw_on_flash[FW_VER_LEN];
  117. memset(fw_on_flash, 0 , sizeof(fw_on_flash));
  118. be_cmd_get_fw_ver(adapter, adapter->fw_ver, fw_on_flash);
  119. strcpy(drvinfo->driver, DRV_NAME);
  120. strcpy(drvinfo->version, DRV_VER);
  121. strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN);
  122. if (memcmp(adapter->fw_ver, fw_on_flash, FW_VER_LEN) != 0) {
  123. strcat(drvinfo->fw_version, " [");
  124. strcat(drvinfo->fw_version, fw_on_flash);
  125. strcat(drvinfo->fw_version, "]");
  126. }
  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_reg_len(struct net_device *netdev)
  134. {
  135. struct be_adapter *adapter = netdev_priv(netdev);
  136. u32 log_size = 0;
  137. if (be_physfn(adapter))
  138. be_cmd_get_reg_len(adapter, &log_size);
  139. return log_size;
  140. }
  141. static void
  142. be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
  143. {
  144. struct be_adapter *adapter = netdev_priv(netdev);
  145. if (be_physfn(adapter)) {
  146. memset(buf, 0, regs->len);
  147. be_cmd_get_regs(adapter, regs->len, buf);
  148. }
  149. }
  150. static int
  151. be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
  152. {
  153. struct be_adapter *adapter = netdev_priv(netdev);
  154. struct be_eq_obj *rx_eq = &adapter->rx_obj[0].rx_eq;
  155. struct be_eq_obj *tx_eq = &adapter->tx_eq;
  156. coalesce->rx_coalesce_usecs = rx_eq->cur_eqd;
  157. coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd;
  158. coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd;
  159. coalesce->tx_coalesce_usecs = tx_eq->cur_eqd;
  160. coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd;
  161. coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd;
  162. coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
  163. coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
  164. return 0;
  165. }
  166. /*
  167. * This routine is used to set interrup coalescing delay
  168. */
  169. static int
  170. be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
  171. {
  172. struct be_adapter *adapter = netdev_priv(netdev);
  173. struct be_rx_obj *rxo;
  174. struct be_eq_obj *rx_eq;
  175. struct be_eq_obj *tx_eq = &adapter->tx_eq;
  176. u32 rx_max, rx_min, rx_cur;
  177. int status = 0, i;
  178. u32 tx_cur;
  179. if (coalesce->use_adaptive_tx_coalesce == 1)
  180. return -EINVAL;
  181. for_all_rx_queues(adapter, rxo, i) {
  182. rx_eq = &rxo->rx_eq;
  183. if (!rx_eq->enable_aic && coalesce->use_adaptive_rx_coalesce)
  184. rx_eq->cur_eqd = 0;
  185. rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce;
  186. rx_max = coalesce->rx_coalesce_usecs_high;
  187. rx_min = coalesce->rx_coalesce_usecs_low;
  188. rx_cur = coalesce->rx_coalesce_usecs;
  189. if (rx_eq->enable_aic) {
  190. if (rx_max > BE_MAX_EQD)
  191. rx_max = BE_MAX_EQD;
  192. if (rx_min > rx_max)
  193. rx_min = rx_max;
  194. rx_eq->max_eqd = rx_max;
  195. rx_eq->min_eqd = rx_min;
  196. if (rx_eq->cur_eqd > rx_max)
  197. rx_eq->cur_eqd = rx_max;
  198. if (rx_eq->cur_eqd < rx_min)
  199. rx_eq->cur_eqd = rx_min;
  200. } else {
  201. if (rx_cur > BE_MAX_EQD)
  202. rx_cur = BE_MAX_EQD;
  203. if (rx_eq->cur_eqd != rx_cur) {
  204. status = be_cmd_modify_eqd(adapter, rx_eq->q.id,
  205. rx_cur);
  206. if (!status)
  207. rx_eq->cur_eqd = rx_cur;
  208. }
  209. }
  210. }
  211. tx_cur = coalesce->tx_coalesce_usecs;
  212. if (tx_cur > BE_MAX_EQD)
  213. tx_cur = BE_MAX_EQD;
  214. if (tx_eq->cur_eqd != tx_cur) {
  215. status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
  216. if (!status)
  217. tx_eq->cur_eqd = tx_cur;
  218. }
  219. return 0;
  220. }
  221. static void
  222. be_get_ethtool_stats(struct net_device *netdev,
  223. struct ethtool_stats *stats, uint64_t *data)
  224. {
  225. struct be_adapter *adapter = netdev_priv(netdev);
  226. struct be_rx_obj *rxo;
  227. struct be_tx_obj *txo;
  228. void *p;
  229. unsigned int i, j, base = 0, start;
  230. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  231. p = (u8 *)&adapter->drv_stats + et_stats[i].offset;
  232. data[i] = *(u32 *)p;
  233. }
  234. base += ETHTOOL_STATS_NUM;
  235. for_all_rx_queues(adapter, rxo, j) {
  236. struct be_rx_stats *stats = rx_stats(rxo);
  237. do {
  238. start = u64_stats_fetch_begin_bh(&stats->sync);
  239. data[base] = stats->rx_bytes;
  240. data[base + 1] = stats->rx_pkts;
  241. } while (u64_stats_fetch_retry_bh(&stats->sync, start));
  242. for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) {
  243. p = (u8 *)stats + et_rx_stats[i].offset;
  244. data[base + i] = *(u32 *)p;
  245. }
  246. base += ETHTOOL_RXSTATS_NUM;
  247. }
  248. for_all_tx_queues(adapter, txo, j) {
  249. struct be_tx_stats *stats = tx_stats(txo);
  250. do {
  251. start = u64_stats_fetch_begin_bh(&stats->sync_compl);
  252. data[base] = stats->tx_compl;
  253. } while (u64_stats_fetch_retry_bh(&stats->sync_compl, start));
  254. do {
  255. start = u64_stats_fetch_begin_bh(&stats->sync);
  256. for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) {
  257. p = (u8 *)stats + et_tx_stats[i].offset;
  258. data[base + i] =
  259. (et_tx_stats[i].size == sizeof(u64)) ?
  260. *(u64 *)p : *(u32 *)p;
  261. }
  262. } while (u64_stats_fetch_retry_bh(&stats->sync, start));
  263. base += ETHTOOL_TXSTATS_NUM;
  264. }
  265. }
  266. static void
  267. be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
  268. uint8_t *data)
  269. {
  270. struct be_adapter *adapter = netdev_priv(netdev);
  271. int i, j;
  272. switch (stringset) {
  273. case ETH_SS_STATS:
  274. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  275. memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
  276. data += ETH_GSTRING_LEN;
  277. }
  278. for (i = 0; i < adapter->num_rx_qs; i++) {
  279. for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
  280. sprintf(data, "rxq%d: %s", i,
  281. et_rx_stats[j].desc);
  282. data += ETH_GSTRING_LEN;
  283. }
  284. }
  285. for (i = 0; i < adapter->num_tx_qs; i++) {
  286. for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) {
  287. sprintf(data, "txq%d: %s", i,
  288. et_tx_stats[j].desc);
  289. data += ETH_GSTRING_LEN;
  290. }
  291. }
  292. break;
  293. case ETH_SS_TEST:
  294. for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
  295. memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
  296. data += ETH_GSTRING_LEN;
  297. }
  298. break;
  299. }
  300. }
  301. static int be_get_sset_count(struct net_device *netdev, int stringset)
  302. {
  303. struct be_adapter *adapter = netdev_priv(netdev);
  304. switch (stringset) {
  305. case ETH_SS_TEST:
  306. return ETHTOOL_TESTS_NUM;
  307. case ETH_SS_STATS:
  308. return ETHTOOL_STATS_NUM +
  309. adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
  310. adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
  311. default:
  312. return -EINVAL;
  313. }
  314. }
  315. static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  316. {
  317. struct be_adapter *adapter = netdev_priv(netdev);
  318. struct be_phy_info phy_info;
  319. u8 mac_speed = 0;
  320. u16 link_speed = 0;
  321. int status;
  322. if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) {
  323. status = be_cmd_link_status_query(adapter, &mac_speed,
  324. &link_speed, 0);
  325. /* link_speed is in units of 10 Mbps */
  326. if (link_speed) {
  327. ethtool_cmd_speed_set(ecmd, link_speed*10);
  328. } else {
  329. switch (mac_speed) {
  330. case PHY_LINK_SPEED_10MBPS:
  331. ethtool_cmd_speed_set(ecmd, SPEED_10);
  332. break;
  333. case PHY_LINK_SPEED_100MBPS:
  334. ethtool_cmd_speed_set(ecmd, SPEED_100);
  335. break;
  336. case PHY_LINK_SPEED_1GBPS:
  337. ethtool_cmd_speed_set(ecmd, SPEED_1000);
  338. break;
  339. case PHY_LINK_SPEED_10GBPS:
  340. ethtool_cmd_speed_set(ecmd, SPEED_10000);
  341. break;
  342. case PHY_LINK_SPEED_ZERO:
  343. ethtool_cmd_speed_set(ecmd, 0);
  344. break;
  345. }
  346. }
  347. status = be_cmd_get_phy_info(adapter, &phy_info);
  348. if (!status) {
  349. switch (phy_info.interface_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 (phy_info.interface_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 = ethtool_cmd_speed(ecmd);
  373. adapter->port_type = ecmd->port;
  374. adapter->transceiver = ecmd->transceiver;
  375. adapter->autoneg = ecmd->autoneg;
  376. } else {
  377. ethtool_cmd_speed_set(ecmd, adapter->link_speed);
  378. ecmd->port = adapter->port_type;
  379. ecmd->transceiver = adapter->transceiver;
  380. ecmd->autoneg = adapter->autoneg;
  381. }
  382. ecmd->duplex = DUPLEX_FULL;
  383. ecmd->phy_address = adapter->port_num;
  384. switch (ecmd->port) {
  385. case PORT_FIBRE:
  386. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
  387. break;
  388. case PORT_TP:
  389. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP);
  390. break;
  391. case PORT_AUI:
  392. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI);
  393. break;
  394. }
  395. if (ecmd->autoneg) {
  396. ecmd->supported |= SUPPORTED_1000baseT_Full;
  397. ecmd->supported |= SUPPORTED_Autoneg;
  398. ecmd->advertising |= (ADVERTISED_10000baseT_Full |
  399. ADVERTISED_1000baseT_Full);
  400. }
  401. return 0;
  402. }
  403. static void
  404. be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
  405. {
  406. struct be_adapter *adapter = netdev_priv(netdev);
  407. ring->rx_max_pending = adapter->rx_obj[0].q.len;
  408. ring->tx_max_pending = adapter->tx_obj[0].q.len;
  409. ring->rx_pending = atomic_read(&adapter->rx_obj[0].q.used);
  410. ring->tx_pending = atomic_read(&adapter->tx_obj[0].q.used);
  411. }
  412. static void
  413. be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  414. {
  415. struct be_adapter *adapter = netdev_priv(netdev);
  416. be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
  417. ecmd->autoneg = 0;
  418. }
  419. static int
  420. be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  421. {
  422. struct be_adapter *adapter = netdev_priv(netdev);
  423. int status;
  424. if (ecmd->autoneg != 0)
  425. return -EINVAL;
  426. adapter->tx_fc = ecmd->tx_pause;
  427. adapter->rx_fc = ecmd->rx_pause;
  428. status = be_cmd_set_flow_control(adapter,
  429. adapter->tx_fc, adapter->rx_fc);
  430. if (status)
  431. dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
  432. return status;
  433. }
  434. static int
  435. be_set_phys_id(struct net_device *netdev,
  436. enum ethtool_phys_id_state state)
  437. {
  438. struct be_adapter *adapter = netdev_priv(netdev);
  439. switch (state) {
  440. case ETHTOOL_ID_ACTIVE:
  441. be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
  442. &adapter->beacon_state);
  443. return 1; /* cycle on/off once per second */
  444. case ETHTOOL_ID_ON:
  445. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  446. BEACON_STATE_ENABLED);
  447. break;
  448. case ETHTOOL_ID_OFF:
  449. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  450. BEACON_STATE_DISABLED);
  451. break;
  452. case ETHTOOL_ID_INACTIVE:
  453. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  454. adapter->beacon_state);
  455. }
  456. return 0;
  457. }
  458. static bool
  459. be_is_wol_supported(struct be_adapter *adapter)
  460. {
  461. if (!be_physfn(adapter))
  462. return false;
  463. else
  464. return true;
  465. }
  466. static void
  467. be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  468. {
  469. struct be_adapter *adapter = netdev_priv(netdev);
  470. if (be_is_wol_supported(adapter))
  471. wol->supported = WAKE_MAGIC;
  472. if (adapter->wol)
  473. wol->wolopts = WAKE_MAGIC;
  474. else
  475. wol->wolopts = 0;
  476. memset(&wol->sopass, 0, sizeof(wol->sopass));
  477. }
  478. static int
  479. be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  480. {
  481. struct be_adapter *adapter = netdev_priv(netdev);
  482. if (wol->wolopts & ~WAKE_MAGIC)
  483. return -EINVAL;
  484. if ((wol->wolopts & WAKE_MAGIC) && be_is_wol_supported(adapter))
  485. adapter->wol = true;
  486. else
  487. adapter->wol = false;
  488. return 0;
  489. }
  490. static int
  491. be_test_ddr_dma(struct be_adapter *adapter)
  492. {
  493. int ret, i;
  494. struct be_dma_mem ddrdma_cmd;
  495. static const u64 pattern[2] = {
  496. 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
  497. };
  498. ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
  499. ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
  500. &ddrdma_cmd.dma, GFP_KERNEL);
  501. if (!ddrdma_cmd.va) {
  502. dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
  503. return -ENOMEM;
  504. }
  505. for (i = 0; i < 2; i++) {
  506. ret = be_cmd_ddr_dma_test(adapter, pattern[i],
  507. 4096, &ddrdma_cmd);
  508. if (ret != 0)
  509. goto err;
  510. }
  511. err:
  512. dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
  513. ddrdma_cmd.dma);
  514. return ret;
  515. }
  516. static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
  517. u64 *status)
  518. {
  519. be_cmd_set_loopback(adapter, adapter->hba_port_num,
  520. loopback_type, 1);
  521. *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
  522. loopback_type, 1500,
  523. 2, 0xabc);
  524. be_cmd_set_loopback(adapter, adapter->hba_port_num,
  525. BE_NO_LOOPBACK, 1);
  526. return *status;
  527. }
  528. static void
  529. be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
  530. {
  531. struct be_adapter *adapter = netdev_priv(netdev);
  532. u8 mac_speed = 0;
  533. u16 qos_link_speed = 0;
  534. memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
  535. if (test->flags & ETH_TEST_FL_OFFLINE) {
  536. if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
  537. &data[0]) != 0) {
  538. test->flags |= ETH_TEST_FL_FAILED;
  539. }
  540. if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
  541. &data[1]) != 0) {
  542. test->flags |= ETH_TEST_FL_FAILED;
  543. }
  544. if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
  545. &data[2]) != 0) {
  546. test->flags |= ETH_TEST_FL_FAILED;
  547. }
  548. }
  549. if (be_test_ddr_dma(adapter) != 0) {
  550. data[3] = 1;
  551. test->flags |= ETH_TEST_FL_FAILED;
  552. }
  553. if (be_cmd_link_status_query(adapter, &mac_speed,
  554. &qos_link_speed, 0) != 0) {
  555. test->flags |= ETH_TEST_FL_FAILED;
  556. data[4] = -1;
  557. } else if (!mac_speed) {
  558. test->flags |= ETH_TEST_FL_FAILED;
  559. data[4] = 1;
  560. }
  561. }
  562. static int
  563. be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
  564. {
  565. struct be_adapter *adapter = netdev_priv(netdev);
  566. char file_name[ETHTOOL_FLASH_MAX_FILENAME];
  567. file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
  568. strcpy(file_name, efl->data);
  569. return be_load_fw(adapter, file_name);
  570. }
  571. static int
  572. be_get_eeprom_len(struct net_device *netdev)
  573. {
  574. return BE_READ_SEEPROM_LEN;
  575. }
  576. static int
  577. be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
  578. uint8_t *data)
  579. {
  580. struct be_adapter *adapter = netdev_priv(netdev);
  581. struct be_dma_mem eeprom_cmd;
  582. struct be_cmd_resp_seeprom_read *resp;
  583. int status;
  584. if (!eeprom->len)
  585. return -EINVAL;
  586. eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
  587. memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
  588. eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
  589. eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
  590. &eeprom_cmd.dma, GFP_KERNEL);
  591. if (!eeprom_cmd.va) {
  592. dev_err(&adapter->pdev->dev,
  593. "Memory allocation failure. Could not read eeprom\n");
  594. return -ENOMEM;
  595. }
  596. status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
  597. if (!status) {
  598. resp = eeprom_cmd.va;
  599. memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
  600. }
  601. dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
  602. eeprom_cmd.dma);
  603. return status;
  604. }
  605. const struct ethtool_ops be_ethtool_ops = {
  606. .get_settings = be_get_settings,
  607. .get_drvinfo = be_get_drvinfo,
  608. .get_wol = be_get_wol,
  609. .set_wol = be_set_wol,
  610. .get_link = ethtool_op_get_link,
  611. .get_eeprom_len = be_get_eeprom_len,
  612. .get_eeprom = be_read_eeprom,
  613. .get_coalesce = be_get_coalesce,
  614. .set_coalesce = be_set_coalesce,
  615. .get_ringparam = be_get_ringparam,
  616. .get_pauseparam = be_get_pauseparam,
  617. .set_pauseparam = be_set_pauseparam,
  618. .get_strings = be_get_stat_strings,
  619. .set_phys_id = be_set_phys_id,
  620. .get_sset_count = be_get_sset_count,
  621. .get_ethtool_stats = be_get_ethtool_stats,
  622. .get_regs_len = be_get_reg_len,
  623. .get_regs = be_get_regs,
  624. .flash_device = be_do_flash,
  625. .self_test = be_self_test,
  626. };