be_ethtool.c 20 KB

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