be_ethtool.c 19 KB

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