be_ethtool.c 39 KB

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