be_ethtool.c 19 KB

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