be_ethtool.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  1. /*
  2. * Copyright (C) 2005 - 2015 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. /* Received packets dropped when the RX block runs out of space in
  78. * one of its input FIFOs. This could happen due a long burst of
  79. * minimum-sized (64b) frames in the receive path.
  80. * This counter may also be erroneously incremented rarely.
  81. */
  82. {DRVSTAT_INFO(rx_input_fifo_overflow_drop)},
  83. {DRVSTAT_INFO(rx_ip_checksum_errs)},
  84. {DRVSTAT_INFO(rx_tcp_checksum_errs)},
  85. {DRVSTAT_INFO(rx_udp_checksum_errs)},
  86. {DRVSTAT_INFO(tx_pauseframes)},
  87. {DRVSTAT_INFO(tx_controlframes)},
  88. {DRVSTAT_INFO(rx_priority_pause_frames)},
  89. {DRVSTAT_INFO(tx_priority_pauseframes)},
  90. /* Received packets dropped when an internal fifo going into
  91. * main packet buffer tank (PMEM) overflows.
  92. */
  93. {DRVSTAT_INFO(pmem_fifo_overflow_drop)},
  94. {DRVSTAT_INFO(jabber_events)},
  95. /* Received packets dropped due to lack of available HW packet buffers
  96. * used to temporarily hold the received packets.
  97. */
  98. {DRVSTAT_INFO(rx_drops_no_pbuf)},
  99. /* Received packets dropped due to input receive buffer
  100. * descriptor fifo overflowing.
  101. */
  102. {DRVSTAT_INFO(rx_drops_no_erx_descr)},
  103. /* Packets dropped because the internal FIFO to the offloaded TCP
  104. * receive processing block is full. This could happen only for
  105. * offloaded iSCSI or FCoE trarffic.
  106. */
  107. {DRVSTAT_INFO(rx_drops_no_tpre_descr)},
  108. /* Received packets dropped when they need more than 8
  109. * receive buffers. This cannot happen as the driver configures
  110. * 2048 byte receive buffers.
  111. */
  112. {DRVSTAT_INFO(rx_drops_too_many_frags)},
  113. {DRVSTAT_INFO(forwarded_packets)},
  114. /* Received packets dropped when the frame length
  115. * is more than 9018 bytes
  116. */
  117. {DRVSTAT_INFO(rx_drops_mtu)},
  118. /* Number of dma mapping errors */
  119. {DRVSTAT_INFO(dma_map_errors)},
  120. /* Number of packets dropped due to random early drop function */
  121. {DRVSTAT_INFO(eth_red_drops)},
  122. {DRVSTAT_INFO(rx_roce_bytes_lsd)},
  123. {DRVSTAT_INFO(rx_roce_bytes_msd)},
  124. {DRVSTAT_INFO(rx_roce_frames)},
  125. {DRVSTAT_INFO(roce_drops_payload_len)},
  126. {DRVSTAT_INFO(roce_drops_crc)}
  127. };
  128. #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
  129. /* Stats related to multi RX queues: get_stats routine assumes bytes, pkts
  130. * are first and second members respectively.
  131. */
  132. static const struct be_ethtool_stat et_rx_stats[] = {
  133. {DRVSTAT_RX_INFO(rx_bytes)},/* If moving this member see above note */
  134. {DRVSTAT_RX_INFO(rx_pkts)}, /* If moving this member see above note */
  135. {DRVSTAT_RX_INFO(rx_vxlan_offload_pkts)},
  136. {DRVSTAT_RX_INFO(rx_compl)},
  137. {DRVSTAT_RX_INFO(rx_compl_err)},
  138. {DRVSTAT_RX_INFO(rx_mcast_pkts)},
  139. /* Number of page allocation failures while posting receive buffers
  140. * to HW.
  141. */
  142. {DRVSTAT_RX_INFO(rx_post_fail)},
  143. /* Recevied packets dropped due to skb allocation failure */
  144. {DRVSTAT_RX_INFO(rx_drops_no_skbs)},
  145. /* Received packets dropped due to lack of available fetched buffers
  146. * posted by the driver.
  147. */
  148. {DRVSTAT_RX_INFO(rx_drops_no_frags)}
  149. };
  150. #define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
  151. /* Stats related to multi TX queues: get_stats routine assumes compl is the
  152. * first member
  153. */
  154. static const struct be_ethtool_stat et_tx_stats[] = {
  155. {DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */
  156. /* This counter is incremented when the HW encounters an error while
  157. * parsing the packet header of an outgoing TX request. This counter is
  158. * applicable only for BE2, BE3 and Skyhawk based adapters.
  159. */
  160. {DRVSTAT_TX_INFO(tx_hdr_parse_err)},
  161. /* This counter is incremented when an error occurs in the DMA
  162. * operation associated with the TX request from the host to the device.
  163. */
  164. {DRVSTAT_TX_INFO(tx_dma_err)},
  165. /* This counter is incremented when MAC or VLAN spoof checking is
  166. * enabled on the interface and the TX request fails the spoof check
  167. * in HW.
  168. */
  169. {DRVSTAT_TX_INFO(tx_spoof_check_err)},
  170. /* This counter is incremented when the HW encounters an error while
  171. * performing TSO offload. This counter is applicable only for Lancer
  172. * adapters.
  173. */
  174. {DRVSTAT_TX_INFO(tx_tso_err)},
  175. /* This counter is incremented when the HW detects Q-in-Q style VLAN
  176. * tagging in a packet and such tagging is not expected on the outgoing
  177. * interface. This counter is applicable only for Lancer adapters.
  178. */
  179. {DRVSTAT_TX_INFO(tx_qinq_err)},
  180. /* This counter is incremented when the HW detects parity errors in the
  181. * packet data. This counter is applicable only for Lancer adapters.
  182. */
  183. {DRVSTAT_TX_INFO(tx_internal_parity_err)},
  184. {DRVSTAT_TX_INFO(tx_bytes)},
  185. {DRVSTAT_TX_INFO(tx_pkts)},
  186. {DRVSTAT_TX_INFO(tx_vxlan_offload_pkts)},
  187. /* Number of skbs queued for trasmission by the driver */
  188. {DRVSTAT_TX_INFO(tx_reqs)},
  189. /* Number of times the TX queue was stopped due to lack
  190. * of spaces in the TXQ.
  191. */
  192. {DRVSTAT_TX_INFO(tx_stops)},
  193. /* Pkts dropped in the driver's transmit path */
  194. {DRVSTAT_TX_INFO(tx_drv_drops)}
  195. };
  196. #define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats))
  197. static const char et_self_tests[][ETH_GSTRING_LEN] = {
  198. "MAC Loopback test",
  199. "PHY Loopback test",
  200. "External Loopback test",
  201. "DDR DMA test",
  202. "Link test"
  203. };
  204. #define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
  205. #define BE_MAC_LOOPBACK 0x0
  206. #define BE_PHY_LOOPBACK 0x1
  207. #define BE_ONE_PORT_EXT_LOOPBACK 0x2
  208. #define BE_NO_LOOPBACK 0xff
  209. static void be_get_drvinfo(struct net_device *netdev,
  210. struct ethtool_drvinfo *drvinfo)
  211. {
  212. struct be_adapter *adapter = netdev_priv(netdev);
  213. strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
  214. strlcpy(drvinfo->version, DRV_VER, sizeof(drvinfo->version));
  215. if (!memcmp(adapter->fw_ver, adapter->fw_on_flash, FW_VER_LEN))
  216. strlcpy(drvinfo->fw_version, adapter->fw_ver,
  217. sizeof(drvinfo->fw_version));
  218. else
  219. snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
  220. "%s [%s]", adapter->fw_ver, adapter->fw_on_flash);
  221. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
  222. sizeof(drvinfo->bus_info));
  223. drvinfo->testinfo_len = 0;
  224. drvinfo->regdump_len = 0;
  225. drvinfo->eedump_len = 0;
  226. }
  227. static u32 lancer_cmd_get_file_len(struct be_adapter *adapter, u8 *file_name)
  228. {
  229. u32 data_read = 0, eof;
  230. u8 addn_status;
  231. struct be_dma_mem data_len_cmd;
  232. int status;
  233. memset(&data_len_cmd, 0, sizeof(data_len_cmd));
  234. /* data_offset and data_size should be 0 to get reg len */
  235. status = lancer_cmd_read_object(adapter, &data_len_cmd, 0, 0,
  236. file_name, &data_read, &eof,
  237. &addn_status);
  238. return data_read;
  239. }
  240. static int lancer_cmd_read_file(struct be_adapter *adapter, u8 *file_name,
  241. u32 buf_len, void *buf)
  242. {
  243. struct be_dma_mem read_cmd;
  244. u32 read_len = 0, total_read_len = 0, chunk_size;
  245. u32 eof = 0;
  246. u8 addn_status;
  247. int status = 0;
  248. read_cmd.size = LANCER_READ_FILE_CHUNK;
  249. read_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, read_cmd.size,
  250. &read_cmd.dma, GFP_ATOMIC);
  251. if (!read_cmd.va) {
  252. dev_err(&adapter->pdev->dev,
  253. "Memory allocation failure while reading dump\n");
  254. return -ENOMEM;
  255. }
  256. while ((total_read_len < buf_len) && !eof) {
  257. chunk_size = min_t(u32, (buf_len - total_read_len),
  258. LANCER_READ_FILE_CHUNK);
  259. chunk_size = ALIGN(chunk_size, 4);
  260. status = lancer_cmd_read_object(adapter, &read_cmd, chunk_size,
  261. total_read_len, file_name,
  262. &read_len, &eof, &addn_status);
  263. if (!status) {
  264. memcpy(buf + total_read_len, read_cmd.va, read_len);
  265. total_read_len += read_len;
  266. eof &= LANCER_READ_FILE_EOF_MASK;
  267. } else {
  268. status = -EIO;
  269. break;
  270. }
  271. }
  272. dma_free_coherent(&adapter->pdev->dev, read_cmd.size, read_cmd.va,
  273. read_cmd.dma);
  274. return status;
  275. }
  276. static int be_get_reg_len(struct net_device *netdev)
  277. {
  278. struct be_adapter *adapter = netdev_priv(netdev);
  279. u32 log_size = 0;
  280. if (!check_privilege(adapter, MAX_PRIVILEGES))
  281. return 0;
  282. if (be_physfn(adapter)) {
  283. if (lancer_chip(adapter))
  284. log_size = lancer_cmd_get_file_len(adapter,
  285. LANCER_FW_DUMP_FILE);
  286. else
  287. be_cmd_get_reg_len(adapter, &log_size);
  288. }
  289. return log_size;
  290. }
  291. static void
  292. be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
  293. {
  294. struct be_adapter *adapter = netdev_priv(netdev);
  295. if (be_physfn(adapter)) {
  296. memset(buf, 0, regs->len);
  297. if (lancer_chip(adapter))
  298. lancer_cmd_read_file(adapter, LANCER_FW_DUMP_FILE,
  299. regs->len, buf);
  300. else
  301. be_cmd_get_regs(adapter, regs->len, buf);
  302. }
  303. }
  304. static int be_get_coalesce(struct net_device *netdev,
  305. struct ethtool_coalesce *et)
  306. {
  307. struct be_adapter *adapter = netdev_priv(netdev);
  308. struct be_aic_obj *aic = &adapter->aic_obj[0];
  309. et->rx_coalesce_usecs = aic->prev_eqd;
  310. et->rx_coalesce_usecs_high = aic->max_eqd;
  311. et->rx_coalesce_usecs_low = aic->min_eqd;
  312. et->tx_coalesce_usecs = aic->prev_eqd;
  313. et->tx_coalesce_usecs_high = aic->max_eqd;
  314. et->tx_coalesce_usecs_low = aic->min_eqd;
  315. et->use_adaptive_rx_coalesce = aic->enable;
  316. et->use_adaptive_tx_coalesce = aic->enable;
  317. return 0;
  318. }
  319. /* TX attributes are ignored. Only RX attributes are considered
  320. * eqd cmd is issued in the worker thread.
  321. */
  322. static int be_set_coalesce(struct net_device *netdev,
  323. struct ethtool_coalesce *et)
  324. {
  325. struct be_adapter *adapter = netdev_priv(netdev);
  326. struct be_aic_obj *aic = &adapter->aic_obj[0];
  327. struct be_eq_obj *eqo;
  328. int i;
  329. for_all_evt_queues(adapter, eqo, i) {
  330. aic->enable = et->use_adaptive_rx_coalesce;
  331. aic->max_eqd = min(et->rx_coalesce_usecs_high, BE_MAX_EQD);
  332. aic->min_eqd = min(et->rx_coalesce_usecs_low, aic->max_eqd);
  333. aic->et_eqd = min(et->rx_coalesce_usecs, aic->max_eqd);
  334. aic->et_eqd = max(aic->et_eqd, aic->min_eqd);
  335. aic++;
  336. }
  337. /* For Skyhawk, the EQD setting happens via EQ_DB when AIC is enabled.
  338. * When AIC is disabled, persistently force set EQD value via the
  339. * FW cmd, so that we don't have to calculate the delay multiplier
  340. * encode value each time EQ_DB is rung
  341. */
  342. if (!et->use_adaptive_rx_coalesce && skyhawk_chip(adapter))
  343. be_eqd_update(adapter, true);
  344. return 0;
  345. }
  346. static void be_get_ethtool_stats(struct net_device *netdev,
  347. struct ethtool_stats *stats, uint64_t *data)
  348. {
  349. struct be_adapter *adapter = netdev_priv(netdev);
  350. struct be_rx_obj *rxo;
  351. struct be_tx_obj *txo;
  352. void *p;
  353. unsigned int i, j, base = 0, start;
  354. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  355. p = (u8 *)&adapter->drv_stats + et_stats[i].offset;
  356. data[i] = *(u32 *)p;
  357. }
  358. base += ETHTOOL_STATS_NUM;
  359. for_all_rx_queues(adapter, rxo, j) {
  360. struct be_rx_stats *stats = rx_stats(rxo);
  361. do {
  362. start = u64_stats_fetch_begin_irq(&stats->sync);
  363. data[base] = stats->rx_bytes;
  364. data[base + 1] = stats->rx_pkts;
  365. } while (u64_stats_fetch_retry_irq(&stats->sync, start));
  366. for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) {
  367. p = (u8 *)stats + et_rx_stats[i].offset;
  368. data[base + i] = *(u32 *)p;
  369. }
  370. base += ETHTOOL_RXSTATS_NUM;
  371. }
  372. for_all_tx_queues(adapter, txo, j) {
  373. struct be_tx_stats *stats = tx_stats(txo);
  374. do {
  375. start = u64_stats_fetch_begin_irq(&stats->sync_compl);
  376. data[base] = stats->tx_compl;
  377. } while (u64_stats_fetch_retry_irq(&stats->sync_compl, start));
  378. do {
  379. start = u64_stats_fetch_begin_irq(&stats->sync);
  380. for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) {
  381. p = (u8 *)stats + et_tx_stats[i].offset;
  382. data[base + i] =
  383. (et_tx_stats[i].size == sizeof(u64)) ?
  384. *(u64 *)p : *(u32 *)p;
  385. }
  386. } while (u64_stats_fetch_retry_irq(&stats->sync, start));
  387. base += ETHTOOL_TXSTATS_NUM;
  388. }
  389. }
  390. static void be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
  391. uint8_t *data)
  392. {
  393. struct be_adapter *adapter = netdev_priv(netdev);
  394. int i, j;
  395. switch (stringset) {
  396. case ETH_SS_STATS:
  397. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  398. memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
  399. data += ETH_GSTRING_LEN;
  400. }
  401. for (i = 0; i < adapter->num_rx_qs; i++) {
  402. for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
  403. sprintf(data, "rxq%d: %s", i,
  404. et_rx_stats[j].desc);
  405. data += ETH_GSTRING_LEN;
  406. }
  407. }
  408. for (i = 0; i < adapter->num_tx_qs; i++) {
  409. for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) {
  410. sprintf(data, "txq%d: %s", i,
  411. et_tx_stats[j].desc);
  412. data += ETH_GSTRING_LEN;
  413. }
  414. }
  415. break;
  416. case ETH_SS_TEST:
  417. for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
  418. memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
  419. data += ETH_GSTRING_LEN;
  420. }
  421. break;
  422. }
  423. }
  424. static int be_get_sset_count(struct net_device *netdev, int stringset)
  425. {
  426. struct be_adapter *adapter = netdev_priv(netdev);
  427. switch (stringset) {
  428. case ETH_SS_TEST:
  429. return ETHTOOL_TESTS_NUM;
  430. case ETH_SS_STATS:
  431. return ETHTOOL_STATS_NUM +
  432. adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
  433. adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
  434. default:
  435. return -EINVAL;
  436. }
  437. }
  438. static u32 be_get_port_type(struct be_adapter *adapter)
  439. {
  440. u32 port;
  441. switch (adapter->phy.interface_type) {
  442. case PHY_TYPE_BASET_1GB:
  443. case PHY_TYPE_BASEX_1GB:
  444. case PHY_TYPE_SGMII:
  445. port = PORT_TP;
  446. break;
  447. case PHY_TYPE_SFP_PLUS_10GB:
  448. if (adapter->phy.cable_type & SFP_PLUS_COPPER_CABLE)
  449. port = PORT_DA;
  450. else
  451. port = PORT_FIBRE;
  452. break;
  453. case PHY_TYPE_QSFP:
  454. if (adapter->phy.cable_type & QSFP_PLUS_CR4_CABLE)
  455. port = PORT_DA;
  456. else
  457. port = PORT_FIBRE;
  458. break;
  459. case PHY_TYPE_XFP_10GB:
  460. case PHY_TYPE_SFP_1GB:
  461. port = PORT_FIBRE;
  462. break;
  463. case PHY_TYPE_BASET_10GB:
  464. port = PORT_TP;
  465. break;
  466. default:
  467. port = PORT_OTHER;
  468. }
  469. return port;
  470. }
  471. static u32 convert_to_et_setting(struct be_adapter *adapter, u32 if_speeds)
  472. {
  473. u32 val = 0;
  474. switch (adapter->phy.interface_type) {
  475. case PHY_TYPE_BASET_1GB:
  476. case PHY_TYPE_BASEX_1GB:
  477. case PHY_TYPE_SGMII:
  478. val |= SUPPORTED_TP;
  479. if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
  480. val |= SUPPORTED_1000baseT_Full;
  481. if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
  482. val |= SUPPORTED_100baseT_Full;
  483. if (if_speeds & BE_SUPPORTED_SPEED_10MBPS)
  484. val |= SUPPORTED_10baseT_Full;
  485. break;
  486. case PHY_TYPE_KX4_10GB:
  487. val |= SUPPORTED_Backplane;
  488. if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
  489. val |= SUPPORTED_1000baseKX_Full;
  490. if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
  491. val |= SUPPORTED_10000baseKX4_Full;
  492. break;
  493. case PHY_TYPE_KR2_20GB:
  494. val |= SUPPORTED_Backplane;
  495. if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
  496. val |= SUPPORTED_10000baseKR_Full;
  497. if (if_speeds & BE_SUPPORTED_SPEED_20GBPS)
  498. val |= SUPPORTED_20000baseKR2_Full;
  499. break;
  500. case PHY_TYPE_KR_10GB:
  501. val |= SUPPORTED_Backplane |
  502. SUPPORTED_10000baseKR_Full;
  503. break;
  504. case PHY_TYPE_KR4_40GB:
  505. val |= SUPPORTED_Backplane;
  506. if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
  507. val |= SUPPORTED_10000baseKR_Full;
  508. if (if_speeds & BE_SUPPORTED_SPEED_40GBPS)
  509. val |= SUPPORTED_40000baseKR4_Full;
  510. break;
  511. case PHY_TYPE_QSFP:
  512. if (if_speeds & BE_SUPPORTED_SPEED_40GBPS) {
  513. switch (adapter->phy.cable_type) {
  514. case QSFP_PLUS_CR4_CABLE:
  515. val |= SUPPORTED_40000baseCR4_Full;
  516. break;
  517. case QSFP_PLUS_LR4_CABLE:
  518. val |= SUPPORTED_40000baseLR4_Full;
  519. break;
  520. default:
  521. val |= SUPPORTED_40000baseSR4_Full;
  522. break;
  523. }
  524. }
  525. case PHY_TYPE_SFP_PLUS_10GB:
  526. case PHY_TYPE_XFP_10GB:
  527. case PHY_TYPE_SFP_1GB:
  528. val |= SUPPORTED_FIBRE;
  529. if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
  530. val |= SUPPORTED_10000baseT_Full;
  531. if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
  532. val |= SUPPORTED_1000baseT_Full;
  533. break;
  534. case PHY_TYPE_BASET_10GB:
  535. val |= SUPPORTED_TP;
  536. if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
  537. val |= SUPPORTED_10000baseT_Full;
  538. if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
  539. val |= SUPPORTED_1000baseT_Full;
  540. if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
  541. val |= SUPPORTED_100baseT_Full;
  542. break;
  543. default:
  544. val |= SUPPORTED_TP;
  545. }
  546. return val;
  547. }
  548. bool be_pause_supported(struct be_adapter *adapter)
  549. {
  550. return (adapter->phy.interface_type == PHY_TYPE_SFP_PLUS_10GB ||
  551. adapter->phy.interface_type == PHY_TYPE_XFP_10GB) ?
  552. false : true;
  553. }
  554. static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  555. {
  556. struct be_adapter *adapter = netdev_priv(netdev);
  557. u8 link_status;
  558. u16 link_speed = 0;
  559. int status;
  560. u32 auto_speeds;
  561. u32 fixed_speeds;
  562. if (adapter->phy.link_speed < 0) {
  563. status = be_cmd_link_status_query(adapter, &link_speed,
  564. &link_status, 0);
  565. if (!status)
  566. be_link_status_update(adapter, link_status);
  567. ethtool_cmd_speed_set(ecmd, link_speed);
  568. status = be_cmd_get_phy_info(adapter);
  569. if (!status) {
  570. auto_speeds = adapter->phy.auto_speeds_supported;
  571. fixed_speeds = adapter->phy.fixed_speeds_supported;
  572. be_cmd_query_cable_type(adapter);
  573. ecmd->supported =
  574. convert_to_et_setting(adapter,
  575. auto_speeds |
  576. fixed_speeds);
  577. ecmd->advertising =
  578. convert_to_et_setting(adapter, auto_speeds);
  579. ecmd->port = be_get_port_type(adapter);
  580. if (adapter->phy.auto_speeds_supported) {
  581. ecmd->supported |= SUPPORTED_Autoneg;
  582. ecmd->autoneg = AUTONEG_ENABLE;
  583. ecmd->advertising |= ADVERTISED_Autoneg;
  584. }
  585. ecmd->supported |= SUPPORTED_Pause;
  586. if (be_pause_supported(adapter))
  587. ecmd->advertising |= ADVERTISED_Pause;
  588. switch (adapter->phy.interface_type) {
  589. case PHY_TYPE_KR_10GB:
  590. case PHY_TYPE_KX4_10GB:
  591. ecmd->transceiver = XCVR_INTERNAL;
  592. break;
  593. default:
  594. ecmd->transceiver = XCVR_EXTERNAL;
  595. break;
  596. }
  597. } else {
  598. ecmd->port = PORT_OTHER;
  599. ecmd->autoneg = AUTONEG_DISABLE;
  600. ecmd->transceiver = XCVR_DUMMY1;
  601. }
  602. /* Save for future use */
  603. adapter->phy.link_speed = ethtool_cmd_speed(ecmd);
  604. adapter->phy.port_type = ecmd->port;
  605. adapter->phy.transceiver = ecmd->transceiver;
  606. adapter->phy.autoneg = ecmd->autoneg;
  607. adapter->phy.advertising = ecmd->advertising;
  608. adapter->phy.supported = ecmd->supported;
  609. } else {
  610. ethtool_cmd_speed_set(ecmd, adapter->phy.link_speed);
  611. ecmd->port = adapter->phy.port_type;
  612. ecmd->transceiver = adapter->phy.transceiver;
  613. ecmd->autoneg = adapter->phy.autoneg;
  614. ecmd->advertising = adapter->phy.advertising;
  615. ecmd->supported = adapter->phy.supported;
  616. }
  617. ecmd->duplex = netif_carrier_ok(netdev) ? DUPLEX_FULL : DUPLEX_UNKNOWN;
  618. ecmd->phy_address = adapter->port_num;
  619. return 0;
  620. }
  621. static void be_get_ringparam(struct net_device *netdev,
  622. struct ethtool_ringparam *ring)
  623. {
  624. struct be_adapter *adapter = netdev_priv(netdev);
  625. ring->rx_max_pending = adapter->rx_obj[0].q.len;
  626. ring->rx_pending = adapter->rx_obj[0].q.len;
  627. ring->tx_max_pending = adapter->tx_obj[0].q.len;
  628. ring->tx_pending = adapter->tx_obj[0].q.len;
  629. }
  630. static void
  631. be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  632. {
  633. struct be_adapter *adapter = netdev_priv(netdev);
  634. be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
  635. ecmd->autoneg = adapter->phy.fc_autoneg;
  636. }
  637. static int
  638. be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  639. {
  640. struct be_adapter *adapter = netdev_priv(netdev);
  641. int status;
  642. if (ecmd->autoneg != adapter->phy.fc_autoneg)
  643. return -EINVAL;
  644. status = be_cmd_set_flow_control(adapter, ecmd->tx_pause,
  645. ecmd->rx_pause);
  646. if (status) {
  647. dev_warn(&adapter->pdev->dev, "Pause param set failed\n");
  648. return be_cmd_status(status);
  649. }
  650. adapter->tx_fc = ecmd->tx_pause;
  651. adapter->rx_fc = ecmd->rx_pause;
  652. return 0;
  653. }
  654. static int be_set_phys_id(struct net_device *netdev,
  655. enum ethtool_phys_id_state state)
  656. {
  657. struct be_adapter *adapter = netdev_priv(netdev);
  658. switch (state) {
  659. case ETHTOOL_ID_ACTIVE:
  660. be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
  661. &adapter->beacon_state);
  662. return 1; /* cycle on/off once per second */
  663. case ETHTOOL_ID_ON:
  664. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  665. BEACON_STATE_ENABLED);
  666. break;
  667. case ETHTOOL_ID_OFF:
  668. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  669. BEACON_STATE_DISABLED);
  670. break;
  671. case ETHTOOL_ID_INACTIVE:
  672. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  673. adapter->beacon_state);
  674. }
  675. return 0;
  676. }
  677. static int be_set_dump(struct net_device *netdev, struct ethtool_dump *dump)
  678. {
  679. struct be_adapter *adapter = netdev_priv(netdev);
  680. struct device *dev = &adapter->pdev->dev;
  681. int status;
  682. if (!lancer_chip(adapter) ||
  683. !check_privilege(adapter, MAX_PRIVILEGES))
  684. return -EOPNOTSUPP;
  685. switch (dump->flag) {
  686. case LANCER_INITIATE_FW_DUMP:
  687. status = lancer_initiate_dump(adapter);
  688. if (!status)
  689. dev_info(dev, "FW dump initiated successfully\n");
  690. break;
  691. case LANCER_DELETE_FW_DUMP:
  692. status = lancer_delete_dump(adapter);
  693. if (!status)
  694. dev_info(dev, "FW dump deleted successfully\n");
  695. break;
  696. default:
  697. dev_err(dev, "Invalid dump level: 0x%x\n", dump->flag);
  698. return -EINVAL;
  699. }
  700. return status;
  701. }
  702. static void be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  703. {
  704. struct be_adapter *adapter = netdev_priv(netdev);
  705. if (adapter->wol_cap & BE_WOL_CAP) {
  706. wol->supported |= WAKE_MAGIC;
  707. if (adapter->wol_en)
  708. wol->wolopts |= WAKE_MAGIC;
  709. } else {
  710. wol->wolopts = 0;
  711. }
  712. memset(&wol->sopass, 0, sizeof(wol->sopass));
  713. }
  714. static int be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  715. {
  716. struct be_adapter *adapter = netdev_priv(netdev);
  717. if (wol->wolopts & ~WAKE_MAGIC)
  718. return -EOPNOTSUPP;
  719. if (!(adapter->wol_cap & BE_WOL_CAP)) {
  720. dev_warn(&adapter->pdev->dev, "WOL not supported\n");
  721. return -EOPNOTSUPP;
  722. }
  723. if (wol->wolopts & WAKE_MAGIC)
  724. adapter->wol_en = true;
  725. else
  726. adapter->wol_en = false;
  727. return 0;
  728. }
  729. static int be_test_ddr_dma(struct be_adapter *adapter)
  730. {
  731. int ret, i;
  732. struct be_dma_mem ddrdma_cmd;
  733. static const u64 pattern[2] = {
  734. 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
  735. };
  736. ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
  737. ddrdma_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
  738. ddrdma_cmd.size, &ddrdma_cmd.dma,
  739. GFP_KERNEL);
  740. if (!ddrdma_cmd.va)
  741. return -ENOMEM;
  742. for (i = 0; i < 2; i++) {
  743. ret = be_cmd_ddr_dma_test(adapter, pattern[i],
  744. 4096, &ddrdma_cmd);
  745. if (ret != 0)
  746. goto err;
  747. }
  748. err:
  749. dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
  750. ddrdma_cmd.dma);
  751. return be_cmd_status(ret);
  752. }
  753. static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
  754. u64 *status)
  755. {
  756. int ret;
  757. ret = be_cmd_set_loopback(adapter, adapter->hba_port_num,
  758. loopback_type, 1);
  759. if (ret)
  760. return ret;
  761. *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
  762. loopback_type, 1500, 2, 0xabc);
  763. ret = be_cmd_set_loopback(adapter, adapter->hba_port_num,
  764. BE_NO_LOOPBACK, 1);
  765. if (ret)
  766. return ret;
  767. return *status;
  768. }
  769. static void be_self_test(struct net_device *netdev, struct ethtool_test *test,
  770. u64 *data)
  771. {
  772. struct be_adapter *adapter = netdev_priv(netdev);
  773. int status;
  774. u8 link_status = 0;
  775. if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC) {
  776. dev_err(&adapter->pdev->dev, "Self test not supported\n");
  777. test->flags |= ETH_TEST_FL_FAILED;
  778. return;
  779. }
  780. memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
  781. if (test->flags & ETH_TEST_FL_OFFLINE) {
  782. if (be_loopback_test(adapter, BE_MAC_LOOPBACK, &data[0]) != 0)
  783. test->flags |= ETH_TEST_FL_FAILED;
  784. if (be_loopback_test(adapter, BE_PHY_LOOPBACK, &data[1]) != 0)
  785. test->flags |= ETH_TEST_FL_FAILED;
  786. if (test->flags & ETH_TEST_FL_EXTERNAL_LB) {
  787. if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
  788. &data[2]) != 0)
  789. test->flags |= ETH_TEST_FL_FAILED;
  790. test->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
  791. }
  792. }
  793. if (!lancer_chip(adapter) && be_test_ddr_dma(adapter) != 0) {
  794. data[3] = 1;
  795. test->flags |= ETH_TEST_FL_FAILED;
  796. }
  797. status = be_cmd_link_status_query(adapter, NULL, &link_status, 0);
  798. if (status) {
  799. test->flags |= ETH_TEST_FL_FAILED;
  800. data[4] = -1;
  801. } else if (!link_status) {
  802. test->flags |= ETH_TEST_FL_FAILED;
  803. data[4] = 1;
  804. }
  805. }
  806. static int be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
  807. {
  808. struct be_adapter *adapter = netdev_priv(netdev);
  809. return be_load_fw(adapter, efl->data);
  810. }
  811. static int be_get_eeprom_len(struct net_device *netdev)
  812. {
  813. struct be_adapter *adapter = netdev_priv(netdev);
  814. if (!check_privilege(adapter, MAX_PRIVILEGES))
  815. return 0;
  816. if (lancer_chip(adapter)) {
  817. if (be_physfn(adapter))
  818. return lancer_cmd_get_file_len(adapter,
  819. LANCER_VPD_PF_FILE);
  820. else
  821. return lancer_cmd_get_file_len(adapter,
  822. LANCER_VPD_VF_FILE);
  823. } else {
  824. return BE_READ_SEEPROM_LEN;
  825. }
  826. }
  827. static int be_read_eeprom(struct net_device *netdev,
  828. struct ethtool_eeprom *eeprom, uint8_t *data)
  829. {
  830. struct be_adapter *adapter = netdev_priv(netdev);
  831. struct be_dma_mem eeprom_cmd;
  832. struct be_cmd_resp_seeprom_read *resp;
  833. int status;
  834. if (!eeprom->len)
  835. return -EINVAL;
  836. if (lancer_chip(adapter)) {
  837. if (be_physfn(adapter))
  838. return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE,
  839. eeprom->len, data);
  840. else
  841. return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE,
  842. eeprom->len, data);
  843. }
  844. eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
  845. memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
  846. eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
  847. eeprom_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
  848. eeprom_cmd.size, &eeprom_cmd.dma,
  849. GFP_KERNEL);
  850. if (!eeprom_cmd.va)
  851. return -ENOMEM;
  852. status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
  853. if (!status) {
  854. resp = eeprom_cmd.va;
  855. memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
  856. }
  857. dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
  858. eeprom_cmd.dma);
  859. return be_cmd_status(status);
  860. }
  861. static u32 be_get_msg_level(struct net_device *netdev)
  862. {
  863. struct be_adapter *adapter = netdev_priv(netdev);
  864. return adapter->msg_enable;
  865. }
  866. static void be_set_msg_level(struct net_device *netdev, u32 level)
  867. {
  868. struct be_adapter *adapter = netdev_priv(netdev);
  869. if (adapter->msg_enable == level)
  870. return;
  871. if ((level & NETIF_MSG_HW) != (adapter->msg_enable & NETIF_MSG_HW))
  872. if (BEx_chip(adapter))
  873. be_cmd_set_fw_log_level(adapter, level & NETIF_MSG_HW ?
  874. FW_LOG_LEVEL_DEFAULT :
  875. FW_LOG_LEVEL_FATAL);
  876. adapter->msg_enable = level;
  877. }
  878. static u64 be_get_rss_hash_opts(struct be_adapter *adapter, u64 flow_type)
  879. {
  880. u64 data = 0;
  881. switch (flow_type) {
  882. case TCP_V4_FLOW:
  883. if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
  884. data |= RXH_IP_DST | RXH_IP_SRC;
  885. if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV4)
  886. data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  887. break;
  888. case UDP_V4_FLOW:
  889. if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
  890. data |= RXH_IP_DST | RXH_IP_SRC;
  891. if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV4)
  892. data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  893. break;
  894. case TCP_V6_FLOW:
  895. if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
  896. data |= RXH_IP_DST | RXH_IP_SRC;
  897. if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV6)
  898. data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  899. break;
  900. case UDP_V6_FLOW:
  901. if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
  902. data |= RXH_IP_DST | RXH_IP_SRC;
  903. if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV6)
  904. data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  905. break;
  906. }
  907. return data;
  908. }
  909. static int be_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
  910. u32 *rule_locs)
  911. {
  912. struct be_adapter *adapter = netdev_priv(netdev);
  913. if (!be_multi_rxq(adapter)) {
  914. dev_info(&adapter->pdev->dev,
  915. "ethtool::get_rxnfc: RX flow hashing is disabled\n");
  916. return -EINVAL;
  917. }
  918. switch (cmd->cmd) {
  919. case ETHTOOL_GRXFH:
  920. cmd->data = be_get_rss_hash_opts(adapter, cmd->flow_type);
  921. break;
  922. case ETHTOOL_GRXRINGS:
  923. cmd->data = adapter->num_rx_qs - 1;
  924. break;
  925. default:
  926. return -EINVAL;
  927. }
  928. return 0;
  929. }
  930. static int be_set_rss_hash_opts(struct be_adapter *adapter,
  931. struct ethtool_rxnfc *cmd)
  932. {
  933. struct be_rx_obj *rxo;
  934. int status = 0, i, j;
  935. u8 rsstable[128];
  936. u32 rss_flags = adapter->rss_info.rss_flags;
  937. if (cmd->data != L3_RSS_FLAGS &&
  938. cmd->data != (L3_RSS_FLAGS | L4_RSS_FLAGS))
  939. return -EINVAL;
  940. switch (cmd->flow_type) {
  941. case TCP_V4_FLOW:
  942. if (cmd->data == L3_RSS_FLAGS)
  943. rss_flags &= ~RSS_ENABLE_TCP_IPV4;
  944. else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
  945. rss_flags |= RSS_ENABLE_IPV4 |
  946. RSS_ENABLE_TCP_IPV4;
  947. break;
  948. case TCP_V6_FLOW:
  949. if (cmd->data == L3_RSS_FLAGS)
  950. rss_flags &= ~RSS_ENABLE_TCP_IPV6;
  951. else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
  952. rss_flags |= RSS_ENABLE_IPV6 |
  953. RSS_ENABLE_TCP_IPV6;
  954. break;
  955. case UDP_V4_FLOW:
  956. if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
  957. BEx_chip(adapter))
  958. return -EINVAL;
  959. if (cmd->data == L3_RSS_FLAGS)
  960. rss_flags &= ~RSS_ENABLE_UDP_IPV4;
  961. else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
  962. rss_flags |= RSS_ENABLE_IPV4 |
  963. RSS_ENABLE_UDP_IPV4;
  964. break;
  965. case UDP_V6_FLOW:
  966. if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
  967. BEx_chip(adapter))
  968. return -EINVAL;
  969. if (cmd->data == L3_RSS_FLAGS)
  970. rss_flags &= ~RSS_ENABLE_UDP_IPV6;
  971. else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
  972. rss_flags |= RSS_ENABLE_IPV6 |
  973. RSS_ENABLE_UDP_IPV6;
  974. break;
  975. default:
  976. return -EINVAL;
  977. }
  978. if (rss_flags == adapter->rss_info.rss_flags)
  979. return status;
  980. if (be_multi_rxq(adapter)) {
  981. for (j = 0; j < 128; j += adapter->num_rss_qs) {
  982. for_all_rss_queues(adapter, rxo, i) {
  983. if ((j + i) >= 128)
  984. break;
  985. rsstable[j + i] = rxo->rss_id;
  986. }
  987. }
  988. }
  989. status = be_cmd_rss_config(adapter, adapter->rss_info.rsstable,
  990. rss_flags, 128, adapter->rss_info.rss_hkey);
  991. if (!status)
  992. adapter->rss_info.rss_flags = rss_flags;
  993. return be_cmd_status(status);
  994. }
  995. static int be_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
  996. {
  997. struct be_adapter *adapter = netdev_priv(netdev);
  998. int status = 0;
  999. if (!be_multi_rxq(adapter)) {
  1000. dev_err(&adapter->pdev->dev,
  1001. "ethtool::set_rxnfc: RX flow hashing is disabled\n");
  1002. return -EINVAL;
  1003. }
  1004. switch (cmd->cmd) {
  1005. case ETHTOOL_SRXFH:
  1006. status = be_set_rss_hash_opts(adapter, cmd);
  1007. break;
  1008. default:
  1009. return -EINVAL;
  1010. }
  1011. return status;
  1012. }
  1013. static void be_get_channels(struct net_device *netdev,
  1014. struct ethtool_channels *ch)
  1015. {
  1016. struct be_adapter *adapter = netdev_priv(netdev);
  1017. ch->combined_count = adapter->num_evt_qs;
  1018. ch->max_combined = be_max_qs(adapter);
  1019. }
  1020. static int be_set_channels(struct net_device *netdev,
  1021. struct ethtool_channels *ch)
  1022. {
  1023. struct be_adapter *adapter = netdev_priv(netdev);
  1024. int status;
  1025. if (ch->rx_count || ch->tx_count || ch->other_count ||
  1026. !ch->combined_count || ch->combined_count > be_max_qs(adapter))
  1027. return -EINVAL;
  1028. adapter->cfg_num_qs = ch->combined_count;
  1029. status = be_update_queues(adapter);
  1030. return be_cmd_status(status);
  1031. }
  1032. static u32 be_get_rxfh_indir_size(struct net_device *netdev)
  1033. {
  1034. return RSS_INDIR_TABLE_LEN;
  1035. }
  1036. static u32 be_get_rxfh_key_size(struct net_device *netdev)
  1037. {
  1038. return RSS_HASH_KEY_LEN;
  1039. }
  1040. static int be_get_rxfh(struct net_device *netdev, u32 *indir, u8 *hkey,
  1041. u8 *hfunc)
  1042. {
  1043. struct be_adapter *adapter = netdev_priv(netdev);
  1044. int i;
  1045. struct rss_info *rss = &adapter->rss_info;
  1046. if (indir) {
  1047. for (i = 0; i < RSS_INDIR_TABLE_LEN; i++)
  1048. indir[i] = rss->rss_queue[i];
  1049. }
  1050. if (hkey)
  1051. memcpy(hkey, rss->rss_hkey, RSS_HASH_KEY_LEN);
  1052. if (hfunc)
  1053. *hfunc = ETH_RSS_HASH_TOP;
  1054. return 0;
  1055. }
  1056. static int be_set_rxfh(struct net_device *netdev, const u32 *indir,
  1057. const u8 *hkey, const u8 hfunc)
  1058. {
  1059. int rc = 0, i, j;
  1060. struct be_adapter *adapter = netdev_priv(netdev);
  1061. u8 rsstable[RSS_INDIR_TABLE_LEN];
  1062. /* We do not allow change in unsupported parameters */
  1063. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
  1064. return -EOPNOTSUPP;
  1065. if (indir) {
  1066. struct be_rx_obj *rxo;
  1067. for (i = 0; i < RSS_INDIR_TABLE_LEN; i++) {
  1068. j = indir[i];
  1069. rxo = &adapter->rx_obj[j];
  1070. rsstable[i] = rxo->rss_id;
  1071. adapter->rss_info.rss_queue[i] = j;
  1072. }
  1073. } else {
  1074. memcpy(rsstable, adapter->rss_info.rsstable,
  1075. RSS_INDIR_TABLE_LEN);
  1076. }
  1077. if (!hkey)
  1078. hkey = adapter->rss_info.rss_hkey;
  1079. rc = be_cmd_rss_config(adapter, rsstable,
  1080. adapter->rss_info.rss_flags,
  1081. RSS_INDIR_TABLE_LEN, hkey);
  1082. if (rc) {
  1083. adapter->rss_info.rss_flags = RSS_ENABLE_NONE;
  1084. return -EIO;
  1085. }
  1086. memcpy(adapter->rss_info.rss_hkey, hkey, RSS_HASH_KEY_LEN);
  1087. memcpy(adapter->rss_info.rsstable, rsstable,
  1088. RSS_INDIR_TABLE_LEN);
  1089. return 0;
  1090. }
  1091. static int be_get_module_info(struct net_device *netdev,
  1092. struct ethtool_modinfo *modinfo)
  1093. {
  1094. struct be_adapter *adapter = netdev_priv(netdev);
  1095. u8 page_data[PAGE_DATA_LEN];
  1096. int status;
  1097. if (!check_privilege(adapter, MAX_PRIVILEGES))
  1098. return -EOPNOTSUPP;
  1099. status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
  1100. page_data);
  1101. if (!status) {
  1102. if (!page_data[SFP_PLUS_SFF_8472_COMP]) {
  1103. modinfo->type = ETH_MODULE_SFF_8079;
  1104. modinfo->eeprom_len = PAGE_DATA_LEN;
  1105. } else {
  1106. modinfo->type = ETH_MODULE_SFF_8472;
  1107. modinfo->eeprom_len = 2 * PAGE_DATA_LEN;
  1108. }
  1109. }
  1110. return be_cmd_status(status);
  1111. }
  1112. static int be_get_module_eeprom(struct net_device *netdev,
  1113. struct ethtool_eeprom *eeprom, u8 *data)
  1114. {
  1115. struct be_adapter *adapter = netdev_priv(netdev);
  1116. int status;
  1117. if (!check_privilege(adapter, MAX_PRIVILEGES))
  1118. return -EOPNOTSUPP;
  1119. status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
  1120. data);
  1121. if (status)
  1122. goto err;
  1123. if (eeprom->offset + eeprom->len > PAGE_DATA_LEN) {
  1124. status = be_cmd_read_port_transceiver_data(adapter,
  1125. TR_PAGE_A2,
  1126. data +
  1127. PAGE_DATA_LEN);
  1128. if (status)
  1129. goto err;
  1130. }
  1131. if (eeprom->offset)
  1132. memcpy(data, data + eeprom->offset, eeprom->len);
  1133. err:
  1134. return be_cmd_status(status);
  1135. }
  1136. const struct ethtool_ops be_ethtool_ops = {
  1137. .get_settings = be_get_settings,
  1138. .get_drvinfo = be_get_drvinfo,
  1139. .get_wol = be_get_wol,
  1140. .set_wol = be_set_wol,
  1141. .get_link = ethtool_op_get_link,
  1142. .get_eeprom_len = be_get_eeprom_len,
  1143. .get_eeprom = be_read_eeprom,
  1144. .get_coalesce = be_get_coalesce,
  1145. .set_coalesce = be_set_coalesce,
  1146. .get_ringparam = be_get_ringparam,
  1147. .get_pauseparam = be_get_pauseparam,
  1148. .set_pauseparam = be_set_pauseparam,
  1149. .get_strings = be_get_stat_strings,
  1150. .set_phys_id = be_set_phys_id,
  1151. .set_dump = be_set_dump,
  1152. .get_msglevel = be_get_msg_level,
  1153. .set_msglevel = be_set_msg_level,
  1154. .get_sset_count = be_get_sset_count,
  1155. .get_ethtool_stats = be_get_ethtool_stats,
  1156. .get_regs_len = be_get_reg_len,
  1157. .get_regs = be_get_regs,
  1158. .flash_device = be_do_flash,
  1159. .self_test = be_self_test,
  1160. .get_rxnfc = be_get_rxnfc,
  1161. .set_rxnfc = be_set_rxnfc,
  1162. .get_rxfh_indir_size = be_get_rxfh_indir_size,
  1163. .get_rxfh_key_size = be_get_rxfh_key_size,
  1164. .get_rxfh = be_get_rxfh,
  1165. .set_rxfh = be_set_rxfh,
  1166. .get_channels = be_get_channels,
  1167. .set_channels = be_set_channels,
  1168. .get_module_info = be_get_module_info,
  1169. .get_module_eeprom = be_get_module_eeprom
  1170. };