be_ethtool.c 36 KB

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