be_ethtool.c 36 KB

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