be_ethtool.c 19 KB

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