be_ethtool.c 36 KB

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