be_ethtool.c 29 KB

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