be_ethtool.c 39 KB

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