be_ethtool.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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 tx_max, tx_min, tx_cur;
  190. u32 rx_max, rx_min, rx_cur;
  191. int status = 0, i;
  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_max = coalesce->tx_coalesce_usecs_high;
  225. tx_min = coalesce->tx_coalesce_usecs_low;
  226. tx_cur = coalesce->tx_coalesce_usecs;
  227. if (tx_cur > BE_MAX_EQD)
  228. tx_cur = BE_MAX_EQD;
  229. if (tx_eq->cur_eqd != tx_cur) {
  230. status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
  231. if (!status)
  232. tx_eq->cur_eqd = tx_cur;
  233. }
  234. return 0;
  235. }
  236. static void
  237. be_get_ethtool_stats(struct net_device *netdev,
  238. struct ethtool_stats *stats, uint64_t *data)
  239. {
  240. struct be_adapter *adapter = netdev_priv(netdev);
  241. struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats_cmd.va);
  242. struct be_erx_stats *erx_stats = &hw_stats->erx;
  243. struct be_rx_obj *rxo;
  244. void *p = NULL;
  245. int i, j;
  246. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  247. switch (et_stats[i].type) {
  248. case NETSTAT:
  249. p = &netdev->stats;
  250. break;
  251. case DRVSTAT_TX:
  252. p = &adapter->tx_stats;
  253. break;
  254. case PORTSTAT:
  255. p = &hw_stats->rxf.port[adapter->port_num];
  256. break;
  257. case MISCSTAT:
  258. p = &hw_stats->rxf;
  259. break;
  260. case PMEMSTAT:
  261. p = &hw_stats->pmem;
  262. break;
  263. case DRVSTAT:
  264. p = &adapter->drv_stats;
  265. break;
  266. }
  267. p = (u8 *)p + et_stats[i].offset;
  268. data[i] = (et_stats[i].size == sizeof(u64)) ?
  269. *(u64 *)p: *(u32 *)p;
  270. }
  271. for_all_rx_queues(adapter, rxo, j) {
  272. for (i = 0; i < ETHTOOL_RXSTATS_NUM; i++) {
  273. switch (et_rx_stats[i].type) {
  274. case DRVSTAT_RX:
  275. p = (u8 *)&rxo->stats + et_rx_stats[i].offset;
  276. break;
  277. case ERXSTAT:
  278. p = (u32 *)erx_stats + rxo->q.id;
  279. break;
  280. }
  281. data[ETHTOOL_STATS_NUM + j * ETHTOOL_RXSTATS_NUM + i] =
  282. (et_rx_stats[i].size == sizeof(u64)) ?
  283. *(u64 *)p: *(u32 *)p;
  284. }
  285. }
  286. }
  287. static void
  288. be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
  289. uint8_t *data)
  290. {
  291. struct be_adapter *adapter = netdev_priv(netdev);
  292. int i, j;
  293. switch (stringset) {
  294. case ETH_SS_STATS:
  295. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  296. memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
  297. data += ETH_GSTRING_LEN;
  298. }
  299. for (i = 0; i < adapter->num_rx_qs; i++) {
  300. for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
  301. sprintf(data, "rxq%d: %s", i,
  302. et_rx_stats[j].desc);
  303. data += ETH_GSTRING_LEN;
  304. }
  305. }
  306. break;
  307. case ETH_SS_TEST:
  308. for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
  309. memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
  310. data += ETH_GSTRING_LEN;
  311. }
  312. break;
  313. }
  314. }
  315. static int be_get_sset_count(struct net_device *netdev, int stringset)
  316. {
  317. struct be_adapter *adapter = netdev_priv(netdev);
  318. switch (stringset) {
  319. case ETH_SS_TEST:
  320. return ETHTOOL_TESTS_NUM;
  321. case ETH_SS_STATS:
  322. return ETHTOOL_STATS_NUM +
  323. adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM;
  324. default:
  325. return -EINVAL;
  326. }
  327. }
  328. static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  329. {
  330. struct be_adapter *adapter = netdev_priv(netdev);
  331. struct be_dma_mem phy_cmd;
  332. struct be_cmd_resp_get_phy_info *resp;
  333. u8 mac_speed = 0;
  334. u16 link_speed = 0;
  335. bool link_up = false;
  336. int status;
  337. u16 intf_type;
  338. if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) {
  339. status = be_cmd_link_status_query(adapter, &link_up,
  340. &mac_speed, &link_speed);
  341. be_link_status_update(adapter, link_up);
  342. /* link_speed is in units of 10 Mbps */
  343. if (link_speed) {
  344. ecmd->speed = link_speed*10;
  345. } else {
  346. switch (mac_speed) {
  347. case PHY_LINK_SPEED_1GBPS:
  348. ecmd->speed = SPEED_1000;
  349. break;
  350. case PHY_LINK_SPEED_10GBPS:
  351. ecmd->speed = SPEED_10000;
  352. break;
  353. }
  354. }
  355. phy_cmd.size = sizeof(struct be_cmd_req_get_phy_info);
  356. phy_cmd.va = dma_alloc_coherent(&adapter->pdev->dev,
  357. phy_cmd.size, &phy_cmd.dma,
  358. GFP_KERNEL);
  359. if (!phy_cmd.va) {
  360. dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
  361. return -ENOMEM;
  362. }
  363. status = be_cmd_get_phy_info(adapter, &phy_cmd);
  364. if (!status) {
  365. resp = (struct be_cmd_resp_get_phy_info *) phy_cmd.va;
  366. intf_type = le16_to_cpu(resp->interface_type);
  367. switch (intf_type) {
  368. case PHY_TYPE_XFP_10GB:
  369. case PHY_TYPE_SFP_1GB:
  370. case PHY_TYPE_SFP_PLUS_10GB:
  371. ecmd->port = PORT_FIBRE;
  372. break;
  373. default:
  374. ecmd->port = PORT_TP;
  375. break;
  376. }
  377. switch (intf_type) {
  378. case PHY_TYPE_KR_10GB:
  379. case PHY_TYPE_KX4_10GB:
  380. ecmd->autoneg = AUTONEG_ENABLE;
  381. ecmd->transceiver = XCVR_INTERNAL;
  382. break;
  383. default:
  384. ecmd->autoneg = AUTONEG_DISABLE;
  385. ecmd->transceiver = XCVR_EXTERNAL;
  386. break;
  387. }
  388. }
  389. /* Save for future use */
  390. adapter->link_speed = ecmd->speed;
  391. adapter->port_type = ecmd->port;
  392. adapter->transceiver = ecmd->transceiver;
  393. adapter->autoneg = ecmd->autoneg;
  394. dma_free_coherent(&adapter->pdev->dev, phy_cmd.size, phy_cmd.va,
  395. phy_cmd.dma);
  396. } else {
  397. ecmd->speed = adapter->link_speed;
  398. ecmd->port = adapter->port_type;
  399. ecmd->transceiver = adapter->transceiver;
  400. ecmd->autoneg = adapter->autoneg;
  401. }
  402. ecmd->duplex = DUPLEX_FULL;
  403. ecmd->phy_address = adapter->port_num;
  404. switch (ecmd->port) {
  405. case PORT_FIBRE:
  406. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
  407. break;
  408. case PORT_TP:
  409. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP);
  410. break;
  411. case PORT_AUI:
  412. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI);
  413. break;
  414. }
  415. if (ecmd->autoneg) {
  416. ecmd->supported |= SUPPORTED_1000baseT_Full;
  417. ecmd->supported |= SUPPORTED_Autoneg;
  418. ecmd->advertising |= (ADVERTISED_10000baseT_Full |
  419. ADVERTISED_1000baseT_Full);
  420. }
  421. return 0;
  422. }
  423. static void
  424. be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
  425. {
  426. struct be_adapter *adapter = netdev_priv(netdev);
  427. ring->rx_max_pending = adapter->rx_obj[0].q.len;
  428. ring->tx_max_pending = adapter->tx_obj.q.len;
  429. ring->rx_pending = atomic_read(&adapter->rx_obj[0].q.used);
  430. ring->tx_pending = atomic_read(&adapter->tx_obj.q.used);
  431. }
  432. static void
  433. be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  434. {
  435. struct be_adapter *adapter = netdev_priv(netdev);
  436. be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
  437. ecmd->autoneg = 0;
  438. }
  439. static int
  440. be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  441. {
  442. struct be_adapter *adapter = netdev_priv(netdev);
  443. int status;
  444. if (ecmd->autoneg != 0)
  445. return -EINVAL;
  446. adapter->tx_fc = ecmd->tx_pause;
  447. adapter->rx_fc = ecmd->rx_pause;
  448. status = be_cmd_set_flow_control(adapter,
  449. adapter->tx_fc, adapter->rx_fc);
  450. if (status)
  451. dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
  452. return status;
  453. }
  454. static int
  455. be_set_phys_id(struct net_device *netdev,
  456. enum ethtool_phys_id_state state)
  457. {
  458. struct be_adapter *adapter = netdev_priv(netdev);
  459. switch (state) {
  460. case ETHTOOL_ID_ACTIVE:
  461. be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
  462. &adapter->beacon_state);
  463. return -EINVAL;
  464. case ETHTOOL_ID_ON:
  465. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  466. BEACON_STATE_ENABLED);
  467. break;
  468. case ETHTOOL_ID_OFF:
  469. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  470. BEACON_STATE_DISABLED);
  471. break;
  472. case ETHTOOL_ID_INACTIVE:
  473. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  474. adapter->beacon_state);
  475. }
  476. return 0;
  477. }
  478. static bool
  479. be_is_wol_supported(struct be_adapter *adapter)
  480. {
  481. if (!be_physfn(adapter))
  482. return false;
  483. else
  484. return true;
  485. }
  486. static void
  487. be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  488. {
  489. struct be_adapter *adapter = netdev_priv(netdev);
  490. if (be_is_wol_supported(adapter))
  491. wol->supported = WAKE_MAGIC;
  492. if (adapter->wol)
  493. wol->wolopts = WAKE_MAGIC;
  494. else
  495. wol->wolopts = 0;
  496. memset(&wol->sopass, 0, sizeof(wol->sopass));
  497. }
  498. static int
  499. be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  500. {
  501. struct be_adapter *adapter = netdev_priv(netdev);
  502. if (wol->wolopts & ~WAKE_MAGIC)
  503. return -EINVAL;
  504. if ((wol->wolopts & WAKE_MAGIC) && be_is_wol_supported(adapter))
  505. adapter->wol = true;
  506. else
  507. adapter->wol = false;
  508. return 0;
  509. }
  510. static int
  511. be_test_ddr_dma(struct be_adapter *adapter)
  512. {
  513. int ret, i;
  514. struct be_dma_mem ddrdma_cmd;
  515. static const u64 pattern[2] = {
  516. 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
  517. };
  518. ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
  519. ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
  520. &ddrdma_cmd.dma, GFP_KERNEL);
  521. if (!ddrdma_cmd.va) {
  522. dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
  523. return -ENOMEM;
  524. }
  525. for (i = 0; i < 2; i++) {
  526. ret = be_cmd_ddr_dma_test(adapter, pattern[i],
  527. 4096, &ddrdma_cmd);
  528. if (ret != 0)
  529. goto err;
  530. }
  531. err:
  532. dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
  533. ddrdma_cmd.dma);
  534. return ret;
  535. }
  536. static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
  537. u64 *status)
  538. {
  539. be_cmd_set_loopback(adapter, adapter->hba_port_num,
  540. loopback_type, 1);
  541. *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
  542. loopback_type, 1500,
  543. 2, 0xabc);
  544. be_cmd_set_loopback(adapter, adapter->hba_port_num,
  545. BE_NO_LOOPBACK, 1);
  546. return *status;
  547. }
  548. static void
  549. be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
  550. {
  551. struct be_adapter *adapter = netdev_priv(netdev);
  552. bool link_up;
  553. u8 mac_speed = 0;
  554. u16 qos_link_speed = 0;
  555. memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
  556. if (test->flags & ETH_TEST_FL_OFFLINE) {
  557. if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
  558. &data[0]) != 0) {
  559. test->flags |= ETH_TEST_FL_FAILED;
  560. }
  561. if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
  562. &data[1]) != 0) {
  563. test->flags |= ETH_TEST_FL_FAILED;
  564. }
  565. if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
  566. &data[2]) != 0) {
  567. test->flags |= ETH_TEST_FL_FAILED;
  568. }
  569. }
  570. if (be_test_ddr_dma(adapter) != 0) {
  571. data[3] = 1;
  572. test->flags |= ETH_TEST_FL_FAILED;
  573. }
  574. if (be_cmd_link_status_query(adapter, &link_up, &mac_speed,
  575. &qos_link_speed) != 0) {
  576. test->flags |= ETH_TEST_FL_FAILED;
  577. data[4] = -1;
  578. } else if (!mac_speed) {
  579. test->flags |= ETH_TEST_FL_FAILED;
  580. data[4] = 1;
  581. }
  582. }
  583. static int
  584. be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
  585. {
  586. struct be_adapter *adapter = netdev_priv(netdev);
  587. char file_name[ETHTOOL_FLASH_MAX_FILENAME];
  588. u32 region;
  589. file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
  590. strcpy(file_name, efl->data);
  591. region = efl->region;
  592. return be_load_fw(adapter, file_name);
  593. }
  594. static int
  595. be_get_eeprom_len(struct net_device *netdev)
  596. {
  597. return BE_READ_SEEPROM_LEN;
  598. }
  599. static int
  600. be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
  601. uint8_t *data)
  602. {
  603. struct be_adapter *adapter = netdev_priv(netdev);
  604. struct be_dma_mem eeprom_cmd;
  605. struct be_cmd_resp_seeprom_read *resp;
  606. int status;
  607. if (!eeprom->len)
  608. return -EINVAL;
  609. eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
  610. memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
  611. eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
  612. eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
  613. &eeprom_cmd.dma, GFP_KERNEL);
  614. if (!eeprom_cmd.va) {
  615. dev_err(&adapter->pdev->dev,
  616. "Memory allocation failure. Could not read eeprom\n");
  617. return -ENOMEM;
  618. }
  619. status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
  620. if (!status) {
  621. resp = (struct be_cmd_resp_seeprom_read *) eeprom_cmd.va;
  622. memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
  623. }
  624. dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
  625. eeprom_cmd.dma);
  626. return status;
  627. }
  628. static int be_set_flags(struct net_device *netdev, u32 data)
  629. {
  630. struct be_adapter *adapter = netdev_priv(netdev);
  631. int rc = -1;
  632. if (be_multi_rxq(adapter))
  633. rc = ethtool_op_set_flags(netdev, data, ETH_FLAG_RXHASH |
  634. ETH_FLAG_TXVLAN | ETH_FLAG_RXVLAN);
  635. return rc;
  636. }
  637. const struct ethtool_ops be_ethtool_ops = {
  638. .get_settings = be_get_settings,
  639. .get_drvinfo = be_get_drvinfo,
  640. .get_wol = be_get_wol,
  641. .set_wol = be_set_wol,
  642. .get_link = ethtool_op_get_link,
  643. .get_eeprom_len = be_get_eeprom_len,
  644. .get_eeprom = be_read_eeprom,
  645. .get_coalesce = be_get_coalesce,
  646. .set_coalesce = be_set_coalesce,
  647. .get_ringparam = be_get_ringparam,
  648. .get_pauseparam = be_get_pauseparam,
  649. .set_pauseparam = be_set_pauseparam,
  650. .get_strings = be_get_stat_strings,
  651. .set_phys_id = be_set_phys_id,
  652. .get_sset_count = be_get_sset_count,
  653. .get_ethtool_stats = be_get_ethtool_stats,
  654. .get_regs_len = be_get_reg_len,
  655. .get_regs = be_get_regs,
  656. .flash_device = be_do_flash,
  657. .self_test = be_self_test,
  658. .set_flags = be_set_flags,
  659. };