be_ethtool.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. /*
  2. * Copyright (C) 2005 - 2011 Emulex
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation. The full GNU General
  8. * Public License is included in this distribution in the file called COPYING.
  9. *
  10. * Contact Information:
  11. * linux-drivers@emulex.com
  12. *
  13. * Emulex
  14. * 3333 Susan Street
  15. * Costa Mesa, CA 92626
  16. */
  17. #include "be.h"
  18. #include "be_cmds.h"
  19. #include <linux/ethtool.h>
  20. struct be_ethtool_stat {
  21. char desc[ETH_GSTRING_LEN];
  22. int type;
  23. int size;
  24. int offset;
  25. };
  26. enum {DRVSTAT_TX, DRVSTAT_RX, DRVSTAT};
  27. #define FIELDINFO(_struct, field) FIELD_SIZEOF(_struct, field), \
  28. offsetof(_struct, field)
  29. #define DRVSTAT_TX_INFO(field) #field, DRVSTAT_TX,\
  30. FIELDINFO(struct be_tx_stats, field)
  31. #define DRVSTAT_RX_INFO(field) #field, DRVSTAT_RX,\
  32. FIELDINFO(struct be_rx_stats, field)
  33. #define DRVSTAT_INFO(field) #field, DRVSTAT,\
  34. FIELDINFO(struct be_drv_stats, field)
  35. static const struct be_ethtool_stat et_stats[] = {
  36. {DRVSTAT_INFO(tx_events)},
  37. {DRVSTAT_INFO(rx_crc_errors)},
  38. {DRVSTAT_INFO(rx_alignment_symbol_errors)},
  39. {DRVSTAT_INFO(rx_pause_frames)},
  40. {DRVSTAT_INFO(rx_control_frames)},
  41. {DRVSTAT_INFO(rx_in_range_errors)},
  42. {DRVSTAT_INFO(rx_out_range_errors)},
  43. {DRVSTAT_INFO(rx_frame_too_long)},
  44. {DRVSTAT_INFO(rx_address_match_errors)},
  45. {DRVSTAT_INFO(rx_dropped_too_small)},
  46. {DRVSTAT_INFO(rx_dropped_too_short)},
  47. {DRVSTAT_INFO(rx_dropped_header_too_small)},
  48. {DRVSTAT_INFO(rx_dropped_tcp_length)},
  49. {DRVSTAT_INFO(rx_dropped_runt)},
  50. {DRVSTAT_INFO(rxpp_fifo_overflow_drop)},
  51. {DRVSTAT_INFO(rx_input_fifo_overflow_drop)},
  52. {DRVSTAT_INFO(rx_ip_checksum_errs)},
  53. {DRVSTAT_INFO(rx_tcp_checksum_errs)},
  54. {DRVSTAT_INFO(rx_udp_checksum_errs)},
  55. {DRVSTAT_INFO(tx_pauseframes)},
  56. {DRVSTAT_INFO(tx_controlframes)},
  57. {DRVSTAT_INFO(rx_priority_pause_frames)},
  58. {DRVSTAT_INFO(pmem_fifo_overflow_drop)},
  59. {DRVSTAT_INFO(jabber_events)},
  60. {DRVSTAT_INFO(rx_drops_no_pbuf)},
  61. {DRVSTAT_INFO(rx_drops_no_txpb)},
  62. {DRVSTAT_INFO(rx_drops_no_erx_descr)},
  63. {DRVSTAT_INFO(rx_drops_no_tpre_descr)},
  64. {DRVSTAT_INFO(rx_drops_too_many_frags)},
  65. {DRVSTAT_INFO(rx_drops_invalid_ring)},
  66. {DRVSTAT_INFO(forwarded_packets)},
  67. {DRVSTAT_INFO(rx_drops_mtu)},
  68. {DRVSTAT_INFO(eth_red_drops)},
  69. {DRVSTAT_INFO(be_on_die_temperature)}
  70. };
  71. #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
  72. /* Stats related to multi RX queues: get_stats routine assumes bytes, pkts
  73. * are first and second members respectively.
  74. */
  75. static const struct be_ethtool_stat et_rx_stats[] = {
  76. {DRVSTAT_RX_INFO(rx_bytes)},/* If moving this member see above note */
  77. {DRVSTAT_RX_INFO(rx_pkts)}, /* If moving this member see above note */
  78. {DRVSTAT_RX_INFO(rx_polls)},
  79. {DRVSTAT_RX_INFO(rx_events)},
  80. {DRVSTAT_RX_INFO(rx_compl)},
  81. {DRVSTAT_RX_INFO(rx_mcast_pkts)},
  82. {DRVSTAT_RX_INFO(rx_post_fail)},
  83. {DRVSTAT_RX_INFO(rx_drops_no_skbs)},
  84. {DRVSTAT_RX_INFO(rx_drops_no_frags)}
  85. };
  86. #define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
  87. /* Stats related to multi TX queues: get_stats routine assumes compl is the
  88. * first member
  89. */
  90. static const struct be_ethtool_stat et_tx_stats[] = {
  91. {DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */
  92. {DRVSTAT_TX_INFO(tx_bytes)},
  93. {DRVSTAT_TX_INFO(tx_pkts)},
  94. {DRVSTAT_TX_INFO(tx_reqs)},
  95. {DRVSTAT_TX_INFO(tx_wrbs)},
  96. {DRVSTAT_TX_INFO(tx_compl)},
  97. {DRVSTAT_TX_INFO(tx_stops)}
  98. };
  99. #define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats))
  100. static const char et_self_tests[][ETH_GSTRING_LEN] = {
  101. "MAC Loopback test",
  102. "PHY Loopback test",
  103. "External Loopback test",
  104. "DDR DMA test",
  105. "Link test"
  106. };
  107. #define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
  108. #define BE_MAC_LOOPBACK 0x0
  109. #define BE_PHY_LOOPBACK 0x1
  110. #define BE_ONE_PORT_EXT_LOOPBACK 0x2
  111. #define BE_NO_LOOPBACK 0xff
  112. static void be_get_drvinfo(struct net_device *netdev,
  113. struct ethtool_drvinfo *drvinfo)
  114. {
  115. struct be_adapter *adapter = netdev_priv(netdev);
  116. char fw_on_flash[FW_VER_LEN];
  117. memset(fw_on_flash, 0 , sizeof(fw_on_flash));
  118. be_cmd_get_fw_ver(adapter, adapter->fw_ver, fw_on_flash);
  119. strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
  120. strlcpy(drvinfo->version, DRV_VER, sizeof(drvinfo->version));
  121. strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN);
  122. if (memcmp(adapter->fw_ver, fw_on_flash, FW_VER_LEN) != 0) {
  123. strcat(drvinfo->fw_version, " [");
  124. strcat(drvinfo->fw_version, fw_on_flash);
  125. strcat(drvinfo->fw_version, "]");
  126. }
  127. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
  128. sizeof(drvinfo->bus_info));
  129. drvinfo->testinfo_len = 0;
  130. drvinfo->regdump_len = 0;
  131. drvinfo->eedump_len = 0;
  132. }
  133. static u32
  134. lancer_cmd_get_file_len(struct be_adapter *adapter, u8 *file_name)
  135. {
  136. u32 data_read = 0, eof;
  137. u8 addn_status;
  138. struct be_dma_mem data_len_cmd;
  139. int status;
  140. memset(&data_len_cmd, 0, sizeof(data_len_cmd));
  141. /* data_offset and data_size should be 0 to get reg len */
  142. status = lancer_cmd_read_object(adapter, &data_len_cmd, 0, 0,
  143. file_name, &data_read, &eof, &addn_status);
  144. return data_read;
  145. }
  146. static int
  147. lancer_cmd_read_file(struct be_adapter *adapter, u8 *file_name,
  148. u32 buf_len, void *buf)
  149. {
  150. struct be_dma_mem read_cmd;
  151. u32 read_len = 0, total_read_len = 0, chunk_size;
  152. u32 eof = 0;
  153. u8 addn_status;
  154. int status = 0;
  155. read_cmd.size = LANCER_READ_FILE_CHUNK;
  156. read_cmd.va = pci_alloc_consistent(adapter->pdev, read_cmd.size,
  157. &read_cmd.dma);
  158. if (!read_cmd.va) {
  159. dev_err(&adapter->pdev->dev,
  160. "Memory allocation failure while reading dump\n");
  161. return -ENOMEM;
  162. }
  163. while ((total_read_len < buf_len) && !eof) {
  164. chunk_size = min_t(u32, (buf_len - total_read_len),
  165. LANCER_READ_FILE_CHUNK);
  166. chunk_size = ALIGN(chunk_size, 4);
  167. status = lancer_cmd_read_object(adapter, &read_cmd, chunk_size,
  168. total_read_len, file_name, &read_len,
  169. &eof, &addn_status);
  170. if (!status) {
  171. memcpy(buf + total_read_len, read_cmd.va, read_len);
  172. total_read_len += read_len;
  173. eof &= LANCER_READ_FILE_EOF_MASK;
  174. } else {
  175. status = -EIO;
  176. break;
  177. }
  178. }
  179. pci_free_consistent(adapter->pdev, read_cmd.size, read_cmd.va,
  180. read_cmd.dma);
  181. return status;
  182. }
  183. static int
  184. be_get_reg_len(struct net_device *netdev)
  185. {
  186. struct be_adapter *adapter = netdev_priv(netdev);
  187. u32 log_size = 0;
  188. if (be_physfn(adapter)) {
  189. if (lancer_chip(adapter))
  190. log_size = lancer_cmd_get_file_len(adapter,
  191. LANCER_FW_DUMP_FILE);
  192. else
  193. be_cmd_get_reg_len(adapter, &log_size);
  194. }
  195. return log_size;
  196. }
  197. static void
  198. be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
  199. {
  200. struct be_adapter *adapter = netdev_priv(netdev);
  201. if (be_physfn(adapter)) {
  202. memset(buf, 0, regs->len);
  203. if (lancer_chip(adapter))
  204. lancer_cmd_read_file(adapter, LANCER_FW_DUMP_FILE,
  205. regs->len, buf);
  206. else
  207. be_cmd_get_regs(adapter, regs->len, buf);
  208. }
  209. }
  210. static int
  211. be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
  212. {
  213. struct be_adapter *adapter = netdev_priv(netdev);
  214. struct be_eq_obj *rx_eq = &adapter->rx_obj[0].rx_eq;
  215. struct be_eq_obj *tx_eq = &adapter->tx_eq;
  216. coalesce->rx_coalesce_usecs = rx_eq->cur_eqd;
  217. coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd;
  218. coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd;
  219. coalesce->tx_coalesce_usecs = tx_eq->cur_eqd;
  220. coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd;
  221. coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd;
  222. coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
  223. coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
  224. return 0;
  225. }
  226. /*
  227. * This routine is used to set interrup coalescing delay
  228. */
  229. static int
  230. be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
  231. {
  232. struct be_adapter *adapter = netdev_priv(netdev);
  233. struct be_rx_obj *rxo;
  234. struct be_eq_obj *rx_eq;
  235. struct be_eq_obj *tx_eq = &adapter->tx_eq;
  236. u32 rx_max, rx_min, rx_cur;
  237. int status = 0, i;
  238. u32 tx_cur;
  239. if (coalesce->use_adaptive_tx_coalesce == 1)
  240. return -EINVAL;
  241. for_all_rx_queues(adapter, rxo, i) {
  242. rx_eq = &rxo->rx_eq;
  243. if (!rx_eq->enable_aic && coalesce->use_adaptive_rx_coalesce)
  244. rx_eq->cur_eqd = 0;
  245. rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce;
  246. rx_max = coalesce->rx_coalesce_usecs_high;
  247. rx_min = coalesce->rx_coalesce_usecs_low;
  248. rx_cur = coalesce->rx_coalesce_usecs;
  249. if (rx_eq->enable_aic) {
  250. if (rx_max > BE_MAX_EQD)
  251. rx_max = BE_MAX_EQD;
  252. if (rx_min > rx_max)
  253. rx_min = rx_max;
  254. rx_eq->max_eqd = rx_max;
  255. rx_eq->min_eqd = rx_min;
  256. if (rx_eq->cur_eqd > rx_max)
  257. rx_eq->cur_eqd = rx_max;
  258. if (rx_eq->cur_eqd < rx_min)
  259. rx_eq->cur_eqd = rx_min;
  260. } else {
  261. if (rx_cur > BE_MAX_EQD)
  262. rx_cur = BE_MAX_EQD;
  263. if (rx_eq->cur_eqd != rx_cur) {
  264. status = be_cmd_modify_eqd(adapter, rx_eq->q.id,
  265. rx_cur);
  266. if (!status)
  267. rx_eq->cur_eqd = rx_cur;
  268. }
  269. }
  270. }
  271. tx_cur = coalesce->tx_coalesce_usecs;
  272. if (tx_cur > BE_MAX_EQD)
  273. tx_cur = BE_MAX_EQD;
  274. if (tx_eq->cur_eqd != tx_cur) {
  275. status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
  276. if (!status)
  277. tx_eq->cur_eqd = tx_cur;
  278. }
  279. return 0;
  280. }
  281. static void
  282. be_get_ethtool_stats(struct net_device *netdev,
  283. struct ethtool_stats *stats, uint64_t *data)
  284. {
  285. struct be_adapter *adapter = netdev_priv(netdev);
  286. struct be_rx_obj *rxo;
  287. struct be_tx_obj *txo;
  288. void *p;
  289. unsigned int i, j, base = 0, start;
  290. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  291. p = (u8 *)&adapter->drv_stats + et_stats[i].offset;
  292. data[i] = *(u32 *)p;
  293. }
  294. base += ETHTOOL_STATS_NUM;
  295. for_all_rx_queues(adapter, rxo, j) {
  296. struct be_rx_stats *stats = rx_stats(rxo);
  297. do {
  298. start = u64_stats_fetch_begin_bh(&stats->sync);
  299. data[base] = stats->rx_bytes;
  300. data[base + 1] = stats->rx_pkts;
  301. } while (u64_stats_fetch_retry_bh(&stats->sync, start));
  302. for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) {
  303. p = (u8 *)stats + et_rx_stats[i].offset;
  304. data[base + i] = *(u32 *)p;
  305. }
  306. base += ETHTOOL_RXSTATS_NUM;
  307. }
  308. for_all_tx_queues(adapter, txo, j) {
  309. struct be_tx_stats *stats = tx_stats(txo);
  310. do {
  311. start = u64_stats_fetch_begin_bh(&stats->sync_compl);
  312. data[base] = stats->tx_compl;
  313. } while (u64_stats_fetch_retry_bh(&stats->sync_compl, start));
  314. do {
  315. start = u64_stats_fetch_begin_bh(&stats->sync);
  316. for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) {
  317. p = (u8 *)stats + et_tx_stats[i].offset;
  318. data[base + i] =
  319. (et_tx_stats[i].size == sizeof(u64)) ?
  320. *(u64 *)p : *(u32 *)p;
  321. }
  322. } while (u64_stats_fetch_retry_bh(&stats->sync, start));
  323. base += ETHTOOL_TXSTATS_NUM;
  324. }
  325. }
  326. static void
  327. be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
  328. uint8_t *data)
  329. {
  330. struct be_adapter *adapter = netdev_priv(netdev);
  331. int i, j;
  332. switch (stringset) {
  333. case ETH_SS_STATS:
  334. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  335. memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
  336. data += ETH_GSTRING_LEN;
  337. }
  338. for (i = 0; i < adapter->num_rx_qs; i++) {
  339. for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
  340. sprintf(data, "rxq%d: %s", i,
  341. et_rx_stats[j].desc);
  342. data += ETH_GSTRING_LEN;
  343. }
  344. }
  345. for (i = 0; i < adapter->num_tx_qs; i++) {
  346. for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) {
  347. sprintf(data, "txq%d: %s", i,
  348. et_tx_stats[j].desc);
  349. data += ETH_GSTRING_LEN;
  350. }
  351. }
  352. break;
  353. case ETH_SS_TEST:
  354. for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
  355. memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
  356. data += ETH_GSTRING_LEN;
  357. }
  358. break;
  359. }
  360. }
  361. static int be_get_sset_count(struct net_device *netdev, int stringset)
  362. {
  363. struct be_adapter *adapter = netdev_priv(netdev);
  364. switch (stringset) {
  365. case ETH_SS_TEST:
  366. return ETHTOOL_TESTS_NUM;
  367. case ETH_SS_STATS:
  368. return ETHTOOL_STATS_NUM +
  369. adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
  370. adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
  371. default:
  372. return -EINVAL;
  373. }
  374. }
  375. static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  376. {
  377. struct be_adapter *adapter = netdev_priv(netdev);
  378. struct be_phy_info phy_info;
  379. u8 mac_speed = 0;
  380. u16 link_speed = 0;
  381. u8 link_status;
  382. int status;
  383. if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) {
  384. status = be_cmd_link_status_query(adapter, &mac_speed,
  385. &link_speed, &link_status, 0);
  386. if (!status)
  387. be_link_status_update(adapter, link_status);
  388. /* link_speed is in units of 10 Mbps */
  389. if (link_speed) {
  390. ethtool_cmd_speed_set(ecmd, link_speed*10);
  391. } else {
  392. switch (mac_speed) {
  393. case PHY_LINK_SPEED_10MBPS:
  394. ethtool_cmd_speed_set(ecmd, SPEED_10);
  395. break;
  396. case PHY_LINK_SPEED_100MBPS:
  397. ethtool_cmd_speed_set(ecmd, SPEED_100);
  398. break;
  399. case PHY_LINK_SPEED_1GBPS:
  400. ethtool_cmd_speed_set(ecmd, SPEED_1000);
  401. break;
  402. case PHY_LINK_SPEED_10GBPS:
  403. ethtool_cmd_speed_set(ecmd, SPEED_10000);
  404. break;
  405. case PHY_LINK_SPEED_ZERO:
  406. ethtool_cmd_speed_set(ecmd, 0);
  407. break;
  408. }
  409. }
  410. status = be_cmd_get_phy_info(adapter, &phy_info);
  411. if (!status) {
  412. switch (phy_info.interface_type) {
  413. case PHY_TYPE_XFP_10GB:
  414. case PHY_TYPE_SFP_1GB:
  415. case PHY_TYPE_SFP_PLUS_10GB:
  416. ecmd->port = PORT_FIBRE;
  417. break;
  418. default:
  419. ecmd->port = PORT_TP;
  420. break;
  421. }
  422. switch (phy_info.interface_type) {
  423. case PHY_TYPE_KR_10GB:
  424. case PHY_TYPE_KX4_10GB:
  425. ecmd->autoneg = AUTONEG_ENABLE;
  426. ecmd->transceiver = XCVR_INTERNAL;
  427. break;
  428. default:
  429. ecmd->autoneg = AUTONEG_DISABLE;
  430. ecmd->transceiver = XCVR_EXTERNAL;
  431. break;
  432. }
  433. }
  434. /* Save for future use */
  435. adapter->link_speed = ethtool_cmd_speed(ecmd);
  436. adapter->port_type = ecmd->port;
  437. adapter->transceiver = ecmd->transceiver;
  438. adapter->autoneg = ecmd->autoneg;
  439. } else {
  440. ethtool_cmd_speed_set(ecmd, adapter->link_speed);
  441. ecmd->port = adapter->port_type;
  442. ecmd->transceiver = adapter->transceiver;
  443. ecmd->autoneg = adapter->autoneg;
  444. }
  445. ecmd->duplex = DUPLEX_FULL;
  446. ecmd->phy_address = adapter->port_num;
  447. switch (ecmd->port) {
  448. case PORT_FIBRE:
  449. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
  450. break;
  451. case PORT_TP:
  452. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP);
  453. break;
  454. case PORT_AUI:
  455. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI);
  456. break;
  457. }
  458. if (ecmd->autoneg) {
  459. ecmd->supported |= SUPPORTED_1000baseT_Full;
  460. ecmd->supported |= SUPPORTED_Autoneg;
  461. ecmd->advertising |= (ADVERTISED_10000baseT_Full |
  462. ADVERTISED_1000baseT_Full);
  463. }
  464. return 0;
  465. }
  466. static void be_get_ringparam(struct net_device *netdev,
  467. struct ethtool_ringparam *ring)
  468. {
  469. struct be_adapter *adapter = netdev_priv(netdev);
  470. ring->rx_max_pending = ring->rx_pending = adapter->rx_obj[0].q.len;
  471. ring->tx_max_pending = ring->tx_pending = adapter->tx_obj[0].q.len;
  472. }
  473. static void
  474. be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  475. {
  476. struct be_adapter *adapter = netdev_priv(netdev);
  477. be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
  478. ecmd->autoneg = 0;
  479. }
  480. static int
  481. be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  482. {
  483. struct be_adapter *adapter = netdev_priv(netdev);
  484. int status;
  485. if (ecmd->autoneg != 0)
  486. return -EINVAL;
  487. adapter->tx_fc = ecmd->tx_pause;
  488. adapter->rx_fc = ecmd->rx_pause;
  489. status = be_cmd_set_flow_control(adapter,
  490. adapter->tx_fc, adapter->rx_fc);
  491. if (status)
  492. dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
  493. return status;
  494. }
  495. static int
  496. be_set_phys_id(struct net_device *netdev,
  497. enum ethtool_phys_id_state state)
  498. {
  499. struct be_adapter *adapter = netdev_priv(netdev);
  500. switch (state) {
  501. case ETHTOOL_ID_ACTIVE:
  502. be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
  503. &adapter->beacon_state);
  504. return 1; /* cycle on/off once per second */
  505. case ETHTOOL_ID_ON:
  506. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  507. BEACON_STATE_ENABLED);
  508. break;
  509. case ETHTOOL_ID_OFF:
  510. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  511. BEACON_STATE_DISABLED);
  512. break;
  513. case ETHTOOL_ID_INACTIVE:
  514. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  515. adapter->beacon_state);
  516. }
  517. return 0;
  518. }
  519. static bool
  520. be_is_wol_supported(struct be_adapter *adapter)
  521. {
  522. if (!be_physfn(adapter))
  523. return false;
  524. else
  525. return true;
  526. }
  527. static void
  528. be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  529. {
  530. struct be_adapter *adapter = netdev_priv(netdev);
  531. if (be_is_wol_supported(adapter))
  532. wol->supported = WAKE_MAGIC;
  533. if (adapter->wol)
  534. wol->wolopts = WAKE_MAGIC;
  535. else
  536. wol->wolopts = 0;
  537. memset(&wol->sopass, 0, sizeof(wol->sopass));
  538. }
  539. static int
  540. be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  541. {
  542. struct be_adapter *adapter = netdev_priv(netdev);
  543. if (wol->wolopts & ~WAKE_MAGIC)
  544. return -EINVAL;
  545. if ((wol->wolopts & WAKE_MAGIC) && be_is_wol_supported(adapter))
  546. adapter->wol = true;
  547. else
  548. adapter->wol = false;
  549. return 0;
  550. }
  551. static int
  552. be_test_ddr_dma(struct be_adapter *adapter)
  553. {
  554. int ret, i;
  555. struct be_dma_mem ddrdma_cmd;
  556. static const u64 pattern[2] = {
  557. 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
  558. };
  559. ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
  560. ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
  561. &ddrdma_cmd.dma, GFP_KERNEL);
  562. if (!ddrdma_cmd.va) {
  563. dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
  564. return -ENOMEM;
  565. }
  566. for (i = 0; i < 2; i++) {
  567. ret = be_cmd_ddr_dma_test(adapter, pattern[i],
  568. 4096, &ddrdma_cmd);
  569. if (ret != 0)
  570. goto err;
  571. }
  572. err:
  573. dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
  574. ddrdma_cmd.dma);
  575. return ret;
  576. }
  577. static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
  578. u64 *status)
  579. {
  580. be_cmd_set_loopback(adapter, adapter->hba_port_num,
  581. loopback_type, 1);
  582. *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
  583. loopback_type, 1500,
  584. 2, 0xabc);
  585. be_cmd_set_loopback(adapter, adapter->hba_port_num,
  586. BE_NO_LOOPBACK, 1);
  587. return *status;
  588. }
  589. static void
  590. be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
  591. {
  592. struct be_adapter *adapter = netdev_priv(netdev);
  593. u8 mac_speed = 0;
  594. u16 qos_link_speed = 0;
  595. memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
  596. if (test->flags & ETH_TEST_FL_OFFLINE) {
  597. if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
  598. &data[0]) != 0) {
  599. test->flags |= ETH_TEST_FL_FAILED;
  600. }
  601. if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
  602. &data[1]) != 0) {
  603. test->flags |= ETH_TEST_FL_FAILED;
  604. }
  605. if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
  606. &data[2]) != 0) {
  607. test->flags |= ETH_TEST_FL_FAILED;
  608. }
  609. }
  610. if (be_test_ddr_dma(adapter) != 0) {
  611. data[3] = 1;
  612. test->flags |= ETH_TEST_FL_FAILED;
  613. }
  614. if (be_cmd_link_status_query(adapter, &mac_speed,
  615. &qos_link_speed, NULL, 0) != 0) {
  616. test->flags |= ETH_TEST_FL_FAILED;
  617. data[4] = -1;
  618. } else if (!mac_speed) {
  619. test->flags |= ETH_TEST_FL_FAILED;
  620. data[4] = 1;
  621. }
  622. }
  623. static int
  624. be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
  625. {
  626. struct be_adapter *adapter = netdev_priv(netdev);
  627. return be_load_fw(adapter, efl->data);
  628. }
  629. static int
  630. be_get_eeprom_len(struct net_device *netdev)
  631. {
  632. struct be_adapter *adapter = netdev_priv(netdev);
  633. if (lancer_chip(adapter)) {
  634. if (be_physfn(adapter))
  635. return lancer_cmd_get_file_len(adapter,
  636. LANCER_VPD_PF_FILE);
  637. else
  638. return lancer_cmd_get_file_len(adapter,
  639. LANCER_VPD_VF_FILE);
  640. } else {
  641. return BE_READ_SEEPROM_LEN;
  642. }
  643. }
  644. static int
  645. be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
  646. uint8_t *data)
  647. {
  648. struct be_adapter *adapter = netdev_priv(netdev);
  649. struct be_dma_mem eeprom_cmd;
  650. struct be_cmd_resp_seeprom_read *resp;
  651. int status;
  652. if (!eeprom->len)
  653. return -EINVAL;
  654. if (lancer_chip(adapter)) {
  655. if (be_physfn(adapter))
  656. return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE,
  657. eeprom->len, data);
  658. else
  659. return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE,
  660. eeprom->len, data);
  661. }
  662. eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
  663. memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
  664. eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
  665. eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
  666. &eeprom_cmd.dma, GFP_KERNEL);
  667. if (!eeprom_cmd.va) {
  668. dev_err(&adapter->pdev->dev,
  669. "Memory allocation failure. Could not read eeprom\n");
  670. return -ENOMEM;
  671. }
  672. status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
  673. if (!status) {
  674. resp = eeprom_cmd.va;
  675. memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
  676. }
  677. dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
  678. eeprom_cmd.dma);
  679. return status;
  680. }
  681. const struct ethtool_ops be_ethtool_ops = {
  682. .get_settings = be_get_settings,
  683. .get_drvinfo = be_get_drvinfo,
  684. .get_wol = be_get_wol,
  685. .set_wol = be_set_wol,
  686. .get_link = ethtool_op_get_link,
  687. .get_eeprom_len = be_get_eeprom_len,
  688. .get_eeprom = be_read_eeprom,
  689. .get_coalesce = be_get_coalesce,
  690. .set_coalesce = be_set_coalesce,
  691. .get_ringparam = be_get_ringparam,
  692. .get_pauseparam = be_get_pauseparam,
  693. .set_pauseparam = be_set_pauseparam,
  694. .get_strings = be_get_stat_strings,
  695. .set_phys_id = be_set_phys_id,
  696. .get_sset_count = be_get_sset_count,
  697. .get_ethtool_stats = be_get_ethtool_stats,
  698. .get_regs_len = be_get_reg_len,
  699. .get_regs = be_get_regs,
  700. .flash_device = be_do_flash,
  701. .self_test = be_self_test,
  702. };