be_ethtool.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  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(rx_crc_errors)},
  37. {DRVSTAT_INFO(rx_alignment_symbol_errors)},
  38. {DRVSTAT_INFO(rx_pause_frames)},
  39. {DRVSTAT_INFO(rx_control_frames)},
  40. /* Received packets dropped when the Ethernet length field
  41. * is not equal to the actual Ethernet data length.
  42. */
  43. {DRVSTAT_INFO(rx_in_range_errors)},
  44. /* Received packets dropped when their length field is >= 1501 bytes
  45. * and <= 1535 bytes.
  46. */
  47. {DRVSTAT_INFO(rx_out_range_errors)},
  48. /* Received packets dropped when they are longer than 9216 bytes */
  49. {DRVSTAT_INFO(rx_frame_too_long)},
  50. /* Received packets dropped when they don't pass the unicast or
  51. * multicast address filtering.
  52. */
  53. {DRVSTAT_INFO(rx_address_mismatch_drops)},
  54. /* Received packets dropped when IP packet length field is less than
  55. * the IP header length field.
  56. */
  57. {DRVSTAT_INFO(rx_dropped_too_small)},
  58. /* Received packets dropped when IP length field is greater than
  59. * the actual packet length.
  60. */
  61. {DRVSTAT_INFO(rx_dropped_too_short)},
  62. /* Received packets dropped when the IP header length field is less
  63. * than 5.
  64. */
  65. {DRVSTAT_INFO(rx_dropped_header_too_small)},
  66. /* Received packets dropped when the TCP header length field is less
  67. * than 5 or the TCP header length + IP header length is more
  68. * than IP packet length.
  69. */
  70. {DRVSTAT_INFO(rx_dropped_tcp_length)},
  71. {DRVSTAT_INFO(rx_dropped_runt)},
  72. /* Number of received packets dropped when a fifo for descriptors going
  73. * into the packet demux block overflows. In normal operation, this
  74. * fifo must never overflow.
  75. */
  76. {DRVSTAT_INFO(rxpp_fifo_overflow_drop)},
  77. {DRVSTAT_INFO(rx_input_fifo_overflow_drop)},
  78. {DRVSTAT_INFO(rx_ip_checksum_errs)},
  79. {DRVSTAT_INFO(rx_tcp_checksum_errs)},
  80. {DRVSTAT_INFO(rx_udp_checksum_errs)},
  81. {DRVSTAT_INFO(tx_pauseframes)},
  82. {DRVSTAT_INFO(tx_controlframes)},
  83. {DRVSTAT_INFO(rx_priority_pause_frames)},
  84. /* Received packets dropped when an internal fifo going into
  85. * main packet buffer tank (PMEM) overflows.
  86. */
  87. {DRVSTAT_INFO(pmem_fifo_overflow_drop)},
  88. {DRVSTAT_INFO(jabber_events)},
  89. /* Received packets dropped due to lack of available HW packet buffers
  90. * used to temporarily hold the received packets.
  91. */
  92. {DRVSTAT_INFO(rx_drops_no_pbuf)},
  93. /* Received packets dropped due to input receive buffer
  94. * descriptor fifo overflowing.
  95. */
  96. {DRVSTAT_INFO(rx_drops_no_erx_descr)},
  97. /* Packets dropped because the internal FIFO to the offloaded TCP
  98. * receive processing block is full. This could happen only for
  99. * offloaded iSCSI or FCoE trarffic.
  100. */
  101. {DRVSTAT_INFO(rx_drops_no_tpre_descr)},
  102. /* Received packets dropped when they need more than 8
  103. * receive buffers. This cannot happen as the driver configures
  104. * 2048 byte receive buffers.
  105. */
  106. {DRVSTAT_INFO(rx_drops_too_many_frags)},
  107. {DRVSTAT_INFO(forwarded_packets)},
  108. /* Received packets dropped when the frame length
  109. * is more than 9018 bytes
  110. */
  111. {DRVSTAT_INFO(rx_drops_mtu)},
  112. /* Number of packets dropped due to random early drop function */
  113. {DRVSTAT_INFO(eth_red_drops)},
  114. {DRVSTAT_INFO(be_on_die_temperature)}
  115. };
  116. #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
  117. /* Stats related to multi RX queues: get_stats routine assumes bytes, pkts
  118. * are first and second members respectively.
  119. */
  120. static const struct be_ethtool_stat et_rx_stats[] = {
  121. {DRVSTAT_RX_INFO(rx_bytes)},/* If moving this member see above note */
  122. {DRVSTAT_RX_INFO(rx_pkts)}, /* If moving this member see above note */
  123. {DRVSTAT_RX_INFO(rx_compl)},
  124. {DRVSTAT_RX_INFO(rx_mcast_pkts)},
  125. /* Number of page allocation failures while posting receive buffers
  126. * to HW.
  127. */
  128. {DRVSTAT_RX_INFO(rx_post_fail)},
  129. /* Recevied packets dropped due to skb allocation failure */
  130. {DRVSTAT_RX_INFO(rx_drops_no_skbs)},
  131. /* Received packets dropped due to lack of available fetched buffers
  132. * posted by the driver.
  133. */
  134. {DRVSTAT_RX_INFO(rx_drops_no_frags)}
  135. };
  136. #define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
  137. /* Stats related to multi TX queues: get_stats routine assumes compl is the
  138. * first member
  139. */
  140. static const struct be_ethtool_stat et_tx_stats[] = {
  141. {DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */
  142. {DRVSTAT_TX_INFO(tx_bytes)},
  143. {DRVSTAT_TX_INFO(tx_pkts)},
  144. /* Number of skbs queued for trasmission by the driver */
  145. {DRVSTAT_TX_INFO(tx_reqs)},
  146. /* Number of TX work request blocks DMAed to HW */
  147. {DRVSTAT_TX_INFO(tx_wrbs)},
  148. /* Number of times the TX queue was stopped due to lack
  149. * of spaces in the TXQ.
  150. */
  151. {DRVSTAT_TX_INFO(tx_stops)}
  152. };
  153. #define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats))
  154. static const char et_self_tests[][ETH_GSTRING_LEN] = {
  155. "MAC Loopback test",
  156. "PHY Loopback test",
  157. "External Loopback test",
  158. "DDR DMA test",
  159. "Link test"
  160. };
  161. #define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
  162. #define BE_MAC_LOOPBACK 0x0
  163. #define BE_PHY_LOOPBACK 0x1
  164. #define BE_ONE_PORT_EXT_LOOPBACK 0x2
  165. #define BE_NO_LOOPBACK 0xff
  166. static void be_get_drvinfo(struct net_device *netdev,
  167. struct ethtool_drvinfo *drvinfo)
  168. {
  169. struct be_adapter *adapter = netdev_priv(netdev);
  170. char fw_on_flash[FW_VER_LEN];
  171. memset(fw_on_flash, 0 , sizeof(fw_on_flash));
  172. be_cmd_get_fw_ver(adapter, adapter->fw_ver, fw_on_flash);
  173. strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
  174. strlcpy(drvinfo->version, DRV_VER, sizeof(drvinfo->version));
  175. if (!memcmp(adapter->fw_ver, fw_on_flash, FW_VER_LEN))
  176. strlcpy(drvinfo->fw_version, adapter->fw_ver,
  177. sizeof(drvinfo->fw_version));
  178. else
  179. snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
  180. "%s [%s]", adapter->fw_ver, fw_on_flash);
  181. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
  182. sizeof(drvinfo->bus_info));
  183. drvinfo->testinfo_len = 0;
  184. drvinfo->regdump_len = 0;
  185. drvinfo->eedump_len = 0;
  186. }
  187. static u32
  188. lancer_cmd_get_file_len(struct be_adapter *adapter, u8 *file_name)
  189. {
  190. u32 data_read = 0, eof;
  191. u8 addn_status;
  192. struct be_dma_mem data_len_cmd;
  193. int status;
  194. memset(&data_len_cmd, 0, sizeof(data_len_cmd));
  195. /* data_offset and data_size should be 0 to get reg len */
  196. status = lancer_cmd_read_object(adapter, &data_len_cmd, 0, 0,
  197. file_name, &data_read, &eof, &addn_status);
  198. return data_read;
  199. }
  200. static int
  201. lancer_cmd_read_file(struct be_adapter *adapter, u8 *file_name,
  202. u32 buf_len, void *buf)
  203. {
  204. struct be_dma_mem read_cmd;
  205. u32 read_len = 0, total_read_len = 0, chunk_size;
  206. u32 eof = 0;
  207. u8 addn_status;
  208. int status = 0;
  209. read_cmd.size = LANCER_READ_FILE_CHUNK;
  210. read_cmd.va = pci_alloc_consistent(adapter->pdev, read_cmd.size,
  211. &read_cmd.dma);
  212. if (!read_cmd.va) {
  213. dev_err(&adapter->pdev->dev,
  214. "Memory allocation failure while reading dump\n");
  215. return -ENOMEM;
  216. }
  217. while ((total_read_len < buf_len) && !eof) {
  218. chunk_size = min_t(u32, (buf_len - total_read_len),
  219. LANCER_READ_FILE_CHUNK);
  220. chunk_size = ALIGN(chunk_size, 4);
  221. status = lancer_cmd_read_object(adapter, &read_cmd, chunk_size,
  222. total_read_len, file_name, &read_len,
  223. &eof, &addn_status);
  224. if (!status) {
  225. memcpy(buf + total_read_len, read_cmd.va, read_len);
  226. total_read_len += read_len;
  227. eof &= LANCER_READ_FILE_EOF_MASK;
  228. } else {
  229. status = -EIO;
  230. break;
  231. }
  232. }
  233. pci_free_consistent(adapter->pdev, read_cmd.size, read_cmd.va,
  234. read_cmd.dma);
  235. return status;
  236. }
  237. static int
  238. be_get_reg_len(struct net_device *netdev)
  239. {
  240. struct be_adapter *adapter = netdev_priv(netdev);
  241. u32 log_size = 0;
  242. if (!check_privilege(adapter, MAX_PRIVILEGES))
  243. return 0;
  244. if (be_physfn(adapter)) {
  245. if (lancer_chip(adapter))
  246. log_size = lancer_cmd_get_file_len(adapter,
  247. LANCER_FW_DUMP_FILE);
  248. else
  249. be_cmd_get_reg_len(adapter, &log_size);
  250. }
  251. return log_size;
  252. }
  253. static void
  254. be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
  255. {
  256. struct be_adapter *adapter = netdev_priv(netdev);
  257. if (be_physfn(adapter)) {
  258. memset(buf, 0, regs->len);
  259. if (lancer_chip(adapter))
  260. lancer_cmd_read_file(adapter, LANCER_FW_DUMP_FILE,
  261. regs->len, buf);
  262. else
  263. be_cmd_get_regs(adapter, regs->len, buf);
  264. }
  265. }
  266. static int be_get_coalesce(struct net_device *netdev,
  267. struct ethtool_coalesce *et)
  268. {
  269. struct be_adapter *adapter = netdev_priv(netdev);
  270. struct be_eq_obj *eqo = &adapter->eq_obj[0];
  271. et->rx_coalesce_usecs = eqo->cur_eqd;
  272. et->rx_coalesce_usecs_high = eqo->max_eqd;
  273. et->rx_coalesce_usecs_low = eqo->min_eqd;
  274. et->tx_coalesce_usecs = eqo->cur_eqd;
  275. et->tx_coalesce_usecs_high = eqo->max_eqd;
  276. et->tx_coalesce_usecs_low = eqo->min_eqd;
  277. et->use_adaptive_rx_coalesce = eqo->enable_aic;
  278. et->use_adaptive_tx_coalesce = eqo->enable_aic;
  279. return 0;
  280. }
  281. /* TX attributes are ignored. Only RX attributes are considered
  282. * eqd cmd is issued in the worker thread.
  283. */
  284. static int be_set_coalesce(struct net_device *netdev,
  285. struct ethtool_coalesce *et)
  286. {
  287. struct be_adapter *adapter = netdev_priv(netdev);
  288. struct be_eq_obj *eqo;
  289. int i;
  290. for_all_evt_queues(adapter, eqo, i) {
  291. eqo->enable_aic = et->use_adaptive_rx_coalesce;
  292. eqo->max_eqd = min(et->rx_coalesce_usecs_high, BE_MAX_EQD);
  293. eqo->min_eqd = min(et->rx_coalesce_usecs_low, eqo->max_eqd);
  294. eqo->eqd = et->rx_coalesce_usecs;
  295. }
  296. return 0;
  297. }
  298. static void
  299. be_get_ethtool_stats(struct net_device *netdev,
  300. struct ethtool_stats *stats, uint64_t *data)
  301. {
  302. struct be_adapter *adapter = netdev_priv(netdev);
  303. struct be_rx_obj *rxo;
  304. struct be_tx_obj *txo;
  305. void *p;
  306. unsigned int i, j, base = 0, start;
  307. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  308. p = (u8 *)&adapter->drv_stats + et_stats[i].offset;
  309. data[i] = *(u32 *)p;
  310. }
  311. base += ETHTOOL_STATS_NUM;
  312. for_all_rx_queues(adapter, rxo, j) {
  313. struct be_rx_stats *stats = rx_stats(rxo);
  314. do {
  315. start = u64_stats_fetch_begin_bh(&stats->sync);
  316. data[base] = stats->rx_bytes;
  317. data[base + 1] = stats->rx_pkts;
  318. } while (u64_stats_fetch_retry_bh(&stats->sync, start));
  319. for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) {
  320. p = (u8 *)stats + et_rx_stats[i].offset;
  321. data[base + i] = *(u32 *)p;
  322. }
  323. base += ETHTOOL_RXSTATS_NUM;
  324. }
  325. for_all_tx_queues(adapter, txo, j) {
  326. struct be_tx_stats *stats = tx_stats(txo);
  327. do {
  328. start = u64_stats_fetch_begin_bh(&stats->sync_compl);
  329. data[base] = stats->tx_compl;
  330. } while (u64_stats_fetch_retry_bh(&stats->sync_compl, start));
  331. do {
  332. start = u64_stats_fetch_begin_bh(&stats->sync);
  333. for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) {
  334. p = (u8 *)stats + et_tx_stats[i].offset;
  335. data[base + i] =
  336. (et_tx_stats[i].size == sizeof(u64)) ?
  337. *(u64 *)p : *(u32 *)p;
  338. }
  339. } while (u64_stats_fetch_retry_bh(&stats->sync, start));
  340. base += ETHTOOL_TXSTATS_NUM;
  341. }
  342. }
  343. static void
  344. be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
  345. uint8_t *data)
  346. {
  347. struct be_adapter *adapter = netdev_priv(netdev);
  348. int i, j;
  349. switch (stringset) {
  350. case ETH_SS_STATS:
  351. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  352. memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
  353. data += ETH_GSTRING_LEN;
  354. }
  355. for (i = 0; i < adapter->num_rx_qs; i++) {
  356. for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
  357. sprintf(data, "rxq%d: %s", i,
  358. et_rx_stats[j].desc);
  359. data += ETH_GSTRING_LEN;
  360. }
  361. }
  362. for (i = 0; i < adapter->num_tx_qs; i++) {
  363. for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) {
  364. sprintf(data, "txq%d: %s", i,
  365. et_tx_stats[j].desc);
  366. data += ETH_GSTRING_LEN;
  367. }
  368. }
  369. break;
  370. case ETH_SS_TEST:
  371. for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
  372. memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
  373. data += ETH_GSTRING_LEN;
  374. }
  375. break;
  376. }
  377. }
  378. static int be_get_sset_count(struct net_device *netdev, int stringset)
  379. {
  380. struct be_adapter *adapter = netdev_priv(netdev);
  381. switch (stringset) {
  382. case ETH_SS_TEST:
  383. return ETHTOOL_TESTS_NUM;
  384. case ETH_SS_STATS:
  385. return ETHTOOL_STATS_NUM +
  386. adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
  387. adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
  388. default:
  389. return -EINVAL;
  390. }
  391. }
  392. static u32 be_get_port_type(u32 phy_type, u32 dac_cable_len)
  393. {
  394. u32 port;
  395. switch (phy_type) {
  396. case PHY_TYPE_BASET_1GB:
  397. case PHY_TYPE_BASEX_1GB:
  398. case PHY_TYPE_SGMII:
  399. port = PORT_TP;
  400. break;
  401. case PHY_TYPE_SFP_PLUS_10GB:
  402. port = dac_cable_len ? PORT_DA : PORT_FIBRE;
  403. break;
  404. case PHY_TYPE_XFP_10GB:
  405. case PHY_TYPE_SFP_1GB:
  406. port = PORT_FIBRE;
  407. break;
  408. case PHY_TYPE_BASET_10GB:
  409. port = PORT_TP;
  410. break;
  411. default:
  412. port = PORT_OTHER;
  413. }
  414. return port;
  415. }
  416. static u32 convert_to_et_setting(u32 if_type, u32 if_speeds)
  417. {
  418. u32 val = 0;
  419. switch (if_type) {
  420. case PHY_TYPE_BASET_1GB:
  421. case PHY_TYPE_BASEX_1GB:
  422. case PHY_TYPE_SGMII:
  423. val |= SUPPORTED_TP;
  424. if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
  425. val |= SUPPORTED_1000baseT_Full;
  426. if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
  427. val |= SUPPORTED_100baseT_Full;
  428. if (if_speeds & BE_SUPPORTED_SPEED_10MBPS)
  429. val |= SUPPORTED_10baseT_Full;
  430. break;
  431. case PHY_TYPE_KX4_10GB:
  432. val |= SUPPORTED_Backplane;
  433. if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
  434. val |= SUPPORTED_1000baseKX_Full;
  435. if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
  436. val |= SUPPORTED_10000baseKX4_Full;
  437. break;
  438. case PHY_TYPE_KR_10GB:
  439. val |= SUPPORTED_Backplane |
  440. SUPPORTED_10000baseKR_Full;
  441. break;
  442. case PHY_TYPE_SFP_PLUS_10GB:
  443. case PHY_TYPE_XFP_10GB:
  444. case PHY_TYPE_SFP_1GB:
  445. val |= SUPPORTED_FIBRE;
  446. if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
  447. val |= SUPPORTED_10000baseT_Full;
  448. if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
  449. val |= SUPPORTED_1000baseT_Full;
  450. break;
  451. case PHY_TYPE_BASET_10GB:
  452. val |= SUPPORTED_TP;
  453. if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
  454. val |= SUPPORTED_10000baseT_Full;
  455. if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
  456. val |= SUPPORTED_1000baseT_Full;
  457. if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
  458. val |= SUPPORTED_100baseT_Full;
  459. break;
  460. default:
  461. val |= SUPPORTED_TP;
  462. }
  463. return val;
  464. }
  465. bool be_pause_supported(struct be_adapter *adapter)
  466. {
  467. return (adapter->phy.interface_type == PHY_TYPE_SFP_PLUS_10GB ||
  468. adapter->phy.interface_type == PHY_TYPE_XFP_10GB) ?
  469. false : true;
  470. }
  471. static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  472. {
  473. struct be_adapter *adapter = netdev_priv(netdev);
  474. u8 link_status;
  475. u16 link_speed = 0;
  476. int status;
  477. u32 auto_speeds;
  478. u32 fixed_speeds;
  479. u32 dac_cable_len;
  480. u16 interface_type;
  481. if (adapter->phy.link_speed < 0) {
  482. status = be_cmd_link_status_query(adapter, &link_speed,
  483. &link_status, 0);
  484. if (!status)
  485. be_link_status_update(adapter, link_status);
  486. ethtool_cmd_speed_set(ecmd, link_speed);
  487. status = be_cmd_get_phy_info(adapter);
  488. if (!status) {
  489. interface_type = adapter->phy.interface_type;
  490. auto_speeds = adapter->phy.auto_speeds_supported;
  491. fixed_speeds = adapter->phy.fixed_speeds_supported;
  492. dac_cable_len = adapter->phy.dac_cable_len;
  493. ecmd->supported =
  494. convert_to_et_setting(interface_type,
  495. auto_speeds |
  496. fixed_speeds);
  497. ecmd->advertising =
  498. convert_to_et_setting(interface_type,
  499. auto_speeds);
  500. ecmd->port = be_get_port_type(interface_type,
  501. dac_cable_len);
  502. if (adapter->phy.auto_speeds_supported) {
  503. ecmd->supported |= SUPPORTED_Autoneg;
  504. ecmd->autoneg = AUTONEG_ENABLE;
  505. ecmd->advertising |= ADVERTISED_Autoneg;
  506. }
  507. ecmd->supported |= SUPPORTED_Pause;
  508. if (be_pause_supported(adapter))
  509. ecmd->advertising |= ADVERTISED_Pause;
  510. switch (adapter->phy.interface_type) {
  511. case PHY_TYPE_KR_10GB:
  512. case PHY_TYPE_KX4_10GB:
  513. ecmd->transceiver = XCVR_INTERNAL;
  514. break;
  515. default:
  516. ecmd->transceiver = XCVR_EXTERNAL;
  517. break;
  518. }
  519. } else {
  520. ecmd->port = PORT_OTHER;
  521. ecmd->autoneg = AUTONEG_DISABLE;
  522. ecmd->transceiver = XCVR_DUMMY1;
  523. }
  524. /* Save for future use */
  525. adapter->phy.link_speed = ethtool_cmd_speed(ecmd);
  526. adapter->phy.port_type = ecmd->port;
  527. adapter->phy.transceiver = ecmd->transceiver;
  528. adapter->phy.autoneg = ecmd->autoneg;
  529. adapter->phy.advertising = ecmd->advertising;
  530. adapter->phy.supported = ecmd->supported;
  531. } else {
  532. ethtool_cmd_speed_set(ecmd, adapter->phy.link_speed);
  533. ecmd->port = adapter->phy.port_type;
  534. ecmd->transceiver = adapter->phy.transceiver;
  535. ecmd->autoneg = adapter->phy.autoneg;
  536. ecmd->advertising = adapter->phy.advertising;
  537. ecmd->supported = adapter->phy.supported;
  538. }
  539. ecmd->duplex = netif_carrier_ok(netdev) ? DUPLEX_FULL : DUPLEX_UNKNOWN;
  540. ecmd->phy_address = adapter->port_num;
  541. return 0;
  542. }
  543. static void be_get_ringparam(struct net_device *netdev,
  544. struct ethtool_ringparam *ring)
  545. {
  546. struct be_adapter *adapter = netdev_priv(netdev);
  547. ring->rx_max_pending = ring->rx_pending = adapter->rx_obj[0].q.len;
  548. ring->tx_max_pending = ring->tx_pending = adapter->tx_obj[0].q.len;
  549. }
  550. static void
  551. be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  552. {
  553. struct be_adapter *adapter = netdev_priv(netdev);
  554. be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
  555. ecmd->autoneg = adapter->phy.fc_autoneg;
  556. }
  557. static int
  558. be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  559. {
  560. struct be_adapter *adapter = netdev_priv(netdev);
  561. int status;
  562. if (ecmd->autoneg != adapter->phy.fc_autoneg)
  563. return -EINVAL;
  564. adapter->tx_fc = ecmd->tx_pause;
  565. adapter->rx_fc = ecmd->rx_pause;
  566. status = be_cmd_set_flow_control(adapter,
  567. adapter->tx_fc, adapter->rx_fc);
  568. if (status)
  569. dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
  570. return status;
  571. }
  572. static int
  573. be_set_phys_id(struct net_device *netdev,
  574. enum ethtool_phys_id_state state)
  575. {
  576. struct be_adapter *adapter = netdev_priv(netdev);
  577. switch (state) {
  578. case ETHTOOL_ID_ACTIVE:
  579. be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
  580. &adapter->beacon_state);
  581. return 1; /* cycle on/off once per second */
  582. case ETHTOOL_ID_ON:
  583. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  584. BEACON_STATE_ENABLED);
  585. break;
  586. case ETHTOOL_ID_OFF:
  587. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  588. BEACON_STATE_DISABLED);
  589. break;
  590. case ETHTOOL_ID_INACTIVE:
  591. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  592. adapter->beacon_state);
  593. }
  594. return 0;
  595. }
  596. static void
  597. be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  598. {
  599. struct be_adapter *adapter = netdev_priv(netdev);
  600. if (be_is_wol_supported(adapter)) {
  601. wol->supported |= WAKE_MAGIC;
  602. wol->wolopts |= WAKE_MAGIC;
  603. } else
  604. wol->wolopts = 0;
  605. memset(&wol->sopass, 0, sizeof(wol->sopass));
  606. }
  607. static int
  608. be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  609. {
  610. struct be_adapter *adapter = netdev_priv(netdev);
  611. if (wol->wolopts & ~WAKE_MAGIC)
  612. return -EOPNOTSUPP;
  613. if (!be_is_wol_supported(adapter)) {
  614. dev_warn(&adapter->pdev->dev, "WOL not supported\n");
  615. return -EOPNOTSUPP;
  616. }
  617. if (wol->wolopts & WAKE_MAGIC)
  618. adapter->wol = true;
  619. else
  620. adapter->wol = false;
  621. return 0;
  622. }
  623. static int
  624. be_test_ddr_dma(struct be_adapter *adapter)
  625. {
  626. int ret, i;
  627. struct be_dma_mem ddrdma_cmd;
  628. static const u64 pattern[2] = {
  629. 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
  630. };
  631. ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
  632. ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
  633. &ddrdma_cmd.dma, GFP_KERNEL);
  634. if (!ddrdma_cmd.va) {
  635. dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
  636. return -ENOMEM;
  637. }
  638. for (i = 0; i < 2; i++) {
  639. ret = be_cmd_ddr_dma_test(adapter, pattern[i],
  640. 4096, &ddrdma_cmd);
  641. if (ret != 0)
  642. goto err;
  643. }
  644. err:
  645. dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
  646. ddrdma_cmd.dma);
  647. return ret;
  648. }
  649. static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
  650. u64 *status)
  651. {
  652. be_cmd_set_loopback(adapter, adapter->hba_port_num,
  653. loopback_type, 1);
  654. *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
  655. loopback_type, 1500,
  656. 2, 0xabc);
  657. be_cmd_set_loopback(adapter, adapter->hba_port_num,
  658. BE_NO_LOOPBACK, 1);
  659. return *status;
  660. }
  661. static void
  662. be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
  663. {
  664. struct be_adapter *adapter = netdev_priv(netdev);
  665. int status;
  666. u8 link_status = 0;
  667. memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
  668. if (test->flags & ETH_TEST_FL_OFFLINE) {
  669. if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
  670. &data[0]) != 0) {
  671. test->flags |= ETH_TEST_FL_FAILED;
  672. }
  673. if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
  674. &data[1]) != 0) {
  675. test->flags |= ETH_TEST_FL_FAILED;
  676. }
  677. if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
  678. &data[2]) != 0) {
  679. test->flags |= ETH_TEST_FL_FAILED;
  680. }
  681. }
  682. if (!lancer_chip(adapter) && be_test_ddr_dma(adapter) != 0) {
  683. data[3] = 1;
  684. test->flags |= ETH_TEST_FL_FAILED;
  685. }
  686. status = be_cmd_link_status_query(adapter, NULL, &link_status, 0);
  687. if (status) {
  688. test->flags |= ETH_TEST_FL_FAILED;
  689. data[4] = -1;
  690. } else if (!link_status) {
  691. test->flags |= ETH_TEST_FL_FAILED;
  692. data[4] = 1;
  693. }
  694. }
  695. static int
  696. be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
  697. {
  698. struct be_adapter *adapter = netdev_priv(netdev);
  699. return be_load_fw(adapter, efl->data);
  700. }
  701. static int
  702. be_get_eeprom_len(struct net_device *netdev)
  703. {
  704. struct be_adapter *adapter = netdev_priv(netdev);
  705. if (!check_privilege(adapter, MAX_PRIVILEGES))
  706. return 0;
  707. if (lancer_chip(adapter)) {
  708. if (be_physfn(adapter))
  709. return lancer_cmd_get_file_len(adapter,
  710. LANCER_VPD_PF_FILE);
  711. else
  712. return lancer_cmd_get_file_len(adapter,
  713. LANCER_VPD_VF_FILE);
  714. } else {
  715. return BE_READ_SEEPROM_LEN;
  716. }
  717. }
  718. static int
  719. be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
  720. uint8_t *data)
  721. {
  722. struct be_adapter *adapter = netdev_priv(netdev);
  723. struct be_dma_mem eeprom_cmd;
  724. struct be_cmd_resp_seeprom_read *resp;
  725. int status;
  726. if (!eeprom->len)
  727. return -EINVAL;
  728. if (lancer_chip(adapter)) {
  729. if (be_physfn(adapter))
  730. return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE,
  731. eeprom->len, data);
  732. else
  733. return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE,
  734. eeprom->len, data);
  735. }
  736. eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
  737. memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
  738. eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
  739. eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
  740. &eeprom_cmd.dma, GFP_KERNEL);
  741. if (!eeprom_cmd.va) {
  742. dev_err(&adapter->pdev->dev,
  743. "Memory allocation failure. Could not read eeprom\n");
  744. return -ENOMEM;
  745. }
  746. status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
  747. if (!status) {
  748. resp = eeprom_cmd.va;
  749. memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
  750. }
  751. dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
  752. eeprom_cmd.dma);
  753. return status;
  754. }
  755. static u32 be_get_msg_level(struct net_device *netdev)
  756. {
  757. struct be_adapter *adapter = netdev_priv(netdev);
  758. if (lancer_chip(adapter)) {
  759. dev_err(&adapter->pdev->dev, "Operation not supported\n");
  760. return -EOPNOTSUPP;
  761. }
  762. return adapter->msg_enable;
  763. }
  764. static void be_set_fw_log_level(struct be_adapter *adapter, u32 level)
  765. {
  766. struct be_dma_mem extfat_cmd;
  767. struct be_fat_conf_params *cfgs;
  768. int status;
  769. int i, j;
  770. memset(&extfat_cmd, 0, sizeof(struct be_dma_mem));
  771. extfat_cmd.size = sizeof(struct be_cmd_resp_get_ext_fat_caps);
  772. extfat_cmd.va = pci_alloc_consistent(adapter->pdev, extfat_cmd.size,
  773. &extfat_cmd.dma);
  774. if (!extfat_cmd.va) {
  775. dev_err(&adapter->pdev->dev, "%s: Memory allocation failure\n",
  776. __func__);
  777. goto err;
  778. }
  779. status = be_cmd_get_ext_fat_capabilites(adapter, &extfat_cmd);
  780. if (!status) {
  781. cfgs = (struct be_fat_conf_params *)(extfat_cmd.va +
  782. sizeof(struct be_cmd_resp_hdr));
  783. for (i = 0; i < le32_to_cpu(cfgs->num_modules); i++) {
  784. u32 num_modes = le32_to_cpu(cfgs->module[i].num_modes);
  785. for (j = 0; j < num_modes; j++) {
  786. if (cfgs->module[i].trace_lvl[j].mode ==
  787. MODE_UART)
  788. cfgs->module[i].trace_lvl[j].dbg_lvl =
  789. cpu_to_le32(level);
  790. }
  791. }
  792. status = be_cmd_set_ext_fat_capabilites(adapter, &extfat_cmd,
  793. cfgs);
  794. if (status)
  795. dev_err(&adapter->pdev->dev,
  796. "Message level set failed\n");
  797. } else {
  798. dev_err(&adapter->pdev->dev, "Message level get failed\n");
  799. }
  800. pci_free_consistent(adapter->pdev, extfat_cmd.size, extfat_cmd.va,
  801. extfat_cmd.dma);
  802. err:
  803. return;
  804. }
  805. static void be_set_msg_level(struct net_device *netdev, u32 level)
  806. {
  807. struct be_adapter *adapter = netdev_priv(netdev);
  808. if (lancer_chip(adapter)) {
  809. dev_err(&adapter->pdev->dev, "Operation not supported\n");
  810. return;
  811. }
  812. if (adapter->msg_enable == level)
  813. return;
  814. if ((level & NETIF_MSG_HW) != (adapter->msg_enable & NETIF_MSG_HW))
  815. be_set_fw_log_level(adapter, level & NETIF_MSG_HW ?
  816. FW_LOG_LEVEL_DEFAULT : FW_LOG_LEVEL_FATAL);
  817. adapter->msg_enable = level;
  818. return;
  819. }
  820. const struct ethtool_ops be_ethtool_ops = {
  821. .get_settings = be_get_settings,
  822. .get_drvinfo = be_get_drvinfo,
  823. .get_wol = be_get_wol,
  824. .set_wol = be_set_wol,
  825. .get_link = ethtool_op_get_link,
  826. .get_eeprom_len = be_get_eeprom_len,
  827. .get_eeprom = be_read_eeprom,
  828. .get_coalesce = be_get_coalesce,
  829. .set_coalesce = be_set_coalesce,
  830. .get_ringparam = be_get_ringparam,
  831. .get_pauseparam = be_get_pauseparam,
  832. .set_pauseparam = be_set_pauseparam,
  833. .get_strings = be_get_stat_strings,
  834. .set_phys_id = be_set_phys_id,
  835. .get_msglevel = be_get_msg_level,
  836. .set_msglevel = be_set_msg_level,
  837. .get_sset_count = be_get_sset_count,
  838. .get_ethtool_stats = be_get_ethtool_stats,
  839. .get_regs_len = be_get_reg_len,
  840. .get_regs = be_get_regs,
  841. .flash_device = be_do_flash,
  842. .self_test = be_self_test,
  843. };