be_ethtool.c 35 KB

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