be_ethtool.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397
  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 void be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
  379. uint8_t *data)
  380. {
  381. struct be_adapter *adapter = netdev_priv(netdev);
  382. int i, j;
  383. switch (stringset) {
  384. case ETH_SS_STATS:
  385. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  386. memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
  387. data += ETH_GSTRING_LEN;
  388. }
  389. for (i = 0; i < adapter->num_rx_qs; i++) {
  390. for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
  391. sprintf(data, "rxq%d: %s", i,
  392. et_rx_stats[j].desc);
  393. data += ETH_GSTRING_LEN;
  394. }
  395. }
  396. for (i = 0; i < adapter->num_tx_qs; i++) {
  397. for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) {
  398. sprintf(data, "txq%d: %s", i,
  399. et_tx_stats[j].desc);
  400. data += ETH_GSTRING_LEN;
  401. }
  402. }
  403. break;
  404. case ETH_SS_TEST:
  405. for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
  406. memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
  407. data += ETH_GSTRING_LEN;
  408. }
  409. break;
  410. }
  411. }
  412. static int be_get_sset_count(struct net_device *netdev, int stringset)
  413. {
  414. struct be_adapter *adapter = netdev_priv(netdev);
  415. switch (stringset) {
  416. case ETH_SS_TEST:
  417. return ETHTOOL_TESTS_NUM;
  418. case ETH_SS_STATS:
  419. return ETHTOOL_STATS_NUM +
  420. adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
  421. adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
  422. default:
  423. return -EINVAL;
  424. }
  425. }
  426. static u32 be_get_port_type(struct be_adapter *adapter)
  427. {
  428. u32 port;
  429. switch (adapter->phy.interface_type) {
  430. case PHY_TYPE_BASET_1GB:
  431. case PHY_TYPE_BASEX_1GB:
  432. case PHY_TYPE_SGMII:
  433. port = PORT_TP;
  434. break;
  435. case PHY_TYPE_SFP_PLUS_10GB:
  436. if (adapter->phy.cable_type & SFP_PLUS_COPPER_CABLE)
  437. port = PORT_DA;
  438. else
  439. port = PORT_FIBRE;
  440. break;
  441. case PHY_TYPE_QSFP:
  442. if (adapter->phy.cable_type & QSFP_PLUS_CR4_CABLE)
  443. port = PORT_DA;
  444. else
  445. port = PORT_FIBRE;
  446. break;
  447. case PHY_TYPE_XFP_10GB:
  448. case PHY_TYPE_SFP_1GB:
  449. port = PORT_FIBRE;
  450. break;
  451. case PHY_TYPE_BASET_10GB:
  452. port = PORT_TP;
  453. break;
  454. default:
  455. port = PORT_OTHER;
  456. }
  457. return port;
  458. }
  459. static u32 convert_to_et_setting(struct be_adapter *adapter, u32 if_speeds)
  460. {
  461. u32 val = 0;
  462. switch (adapter->phy.interface_type) {
  463. case PHY_TYPE_BASET_1GB:
  464. case PHY_TYPE_BASEX_1GB:
  465. case PHY_TYPE_SGMII:
  466. val |= SUPPORTED_TP;
  467. if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
  468. val |= SUPPORTED_1000baseT_Full;
  469. if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
  470. val |= SUPPORTED_100baseT_Full;
  471. if (if_speeds & BE_SUPPORTED_SPEED_10MBPS)
  472. val |= SUPPORTED_10baseT_Full;
  473. break;
  474. case PHY_TYPE_KX4_10GB:
  475. val |= SUPPORTED_Backplane;
  476. if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
  477. val |= SUPPORTED_1000baseKX_Full;
  478. if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
  479. val |= SUPPORTED_10000baseKX4_Full;
  480. break;
  481. case PHY_TYPE_KR2_20GB:
  482. val |= SUPPORTED_Backplane;
  483. if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
  484. val |= SUPPORTED_10000baseKR_Full;
  485. if (if_speeds & BE_SUPPORTED_SPEED_20GBPS)
  486. val |= SUPPORTED_20000baseKR2_Full;
  487. break;
  488. case PHY_TYPE_KR_10GB:
  489. val |= SUPPORTED_Backplane |
  490. SUPPORTED_10000baseKR_Full;
  491. break;
  492. case PHY_TYPE_KR4_40GB:
  493. val |= SUPPORTED_Backplane;
  494. if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
  495. val |= SUPPORTED_10000baseKR_Full;
  496. if (if_speeds & BE_SUPPORTED_SPEED_40GBPS)
  497. val |= SUPPORTED_40000baseKR4_Full;
  498. break;
  499. case PHY_TYPE_QSFP:
  500. if (if_speeds & BE_SUPPORTED_SPEED_40GBPS) {
  501. switch (adapter->phy.cable_type) {
  502. case QSFP_PLUS_CR4_CABLE:
  503. val |= SUPPORTED_40000baseCR4_Full;
  504. break;
  505. case QSFP_PLUS_LR4_CABLE:
  506. val |= SUPPORTED_40000baseLR4_Full;
  507. break;
  508. default:
  509. val |= SUPPORTED_40000baseSR4_Full;
  510. break;
  511. }
  512. }
  513. case PHY_TYPE_SFP_PLUS_10GB:
  514. case PHY_TYPE_XFP_10GB:
  515. case PHY_TYPE_SFP_1GB:
  516. val |= SUPPORTED_FIBRE;
  517. if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
  518. val |= SUPPORTED_10000baseT_Full;
  519. if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
  520. val |= SUPPORTED_1000baseT_Full;
  521. break;
  522. case PHY_TYPE_BASET_10GB:
  523. val |= SUPPORTED_TP;
  524. if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
  525. val |= SUPPORTED_10000baseT_Full;
  526. if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
  527. val |= SUPPORTED_1000baseT_Full;
  528. if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
  529. val |= SUPPORTED_100baseT_Full;
  530. break;
  531. default:
  532. val |= SUPPORTED_TP;
  533. }
  534. return val;
  535. }
  536. bool be_pause_supported(struct be_adapter *adapter)
  537. {
  538. return (adapter->phy.interface_type == PHY_TYPE_SFP_PLUS_10GB ||
  539. adapter->phy.interface_type == PHY_TYPE_XFP_10GB) ?
  540. false : true;
  541. }
  542. static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  543. {
  544. struct be_adapter *adapter = netdev_priv(netdev);
  545. u8 link_status;
  546. u16 link_speed = 0;
  547. int status;
  548. u32 auto_speeds;
  549. u32 fixed_speeds;
  550. if (adapter->phy.link_speed < 0) {
  551. status = be_cmd_link_status_query(adapter, &link_speed,
  552. &link_status, 0);
  553. if (!status)
  554. be_link_status_update(adapter, link_status);
  555. ethtool_cmd_speed_set(ecmd, link_speed);
  556. status = be_cmd_get_phy_info(adapter);
  557. if (!status) {
  558. auto_speeds = adapter->phy.auto_speeds_supported;
  559. fixed_speeds = adapter->phy.fixed_speeds_supported;
  560. be_cmd_query_cable_type(adapter);
  561. ecmd->supported =
  562. convert_to_et_setting(adapter,
  563. auto_speeds |
  564. fixed_speeds);
  565. ecmd->advertising =
  566. convert_to_et_setting(adapter, auto_speeds);
  567. ecmd->port = be_get_port_type(adapter);
  568. if (adapter->phy.auto_speeds_supported) {
  569. ecmd->supported |= SUPPORTED_Autoneg;
  570. ecmd->autoneg = AUTONEG_ENABLE;
  571. ecmd->advertising |= ADVERTISED_Autoneg;
  572. }
  573. ecmd->supported |= SUPPORTED_Pause;
  574. if (be_pause_supported(adapter))
  575. ecmd->advertising |= ADVERTISED_Pause;
  576. switch (adapter->phy.interface_type) {
  577. case PHY_TYPE_KR_10GB:
  578. case PHY_TYPE_KX4_10GB:
  579. ecmd->transceiver = XCVR_INTERNAL;
  580. break;
  581. default:
  582. ecmd->transceiver = XCVR_EXTERNAL;
  583. break;
  584. }
  585. } else {
  586. ecmd->port = PORT_OTHER;
  587. ecmd->autoneg = AUTONEG_DISABLE;
  588. ecmd->transceiver = XCVR_DUMMY1;
  589. }
  590. /* Save for future use */
  591. adapter->phy.link_speed = ethtool_cmd_speed(ecmd);
  592. adapter->phy.port_type = ecmd->port;
  593. adapter->phy.transceiver = ecmd->transceiver;
  594. adapter->phy.autoneg = ecmd->autoneg;
  595. adapter->phy.advertising = ecmd->advertising;
  596. adapter->phy.supported = ecmd->supported;
  597. } else {
  598. ethtool_cmd_speed_set(ecmd, adapter->phy.link_speed);
  599. ecmd->port = adapter->phy.port_type;
  600. ecmd->transceiver = adapter->phy.transceiver;
  601. ecmd->autoneg = adapter->phy.autoneg;
  602. ecmd->advertising = adapter->phy.advertising;
  603. ecmd->supported = adapter->phy.supported;
  604. }
  605. ecmd->duplex = netif_carrier_ok(netdev) ? DUPLEX_FULL : DUPLEX_UNKNOWN;
  606. ecmd->phy_address = adapter->port_num;
  607. return 0;
  608. }
  609. static void be_get_ringparam(struct net_device *netdev,
  610. struct ethtool_ringparam *ring)
  611. {
  612. struct be_adapter *adapter = netdev_priv(netdev);
  613. ring->rx_max_pending = adapter->rx_obj[0].q.len;
  614. ring->rx_pending = adapter->rx_obj[0].q.len;
  615. ring->tx_max_pending = adapter->tx_obj[0].q.len;
  616. ring->tx_pending = adapter->tx_obj[0].q.len;
  617. }
  618. static void
  619. be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  620. {
  621. struct be_adapter *adapter = netdev_priv(netdev);
  622. be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
  623. ecmd->autoneg = adapter->phy.fc_autoneg;
  624. }
  625. static int
  626. be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  627. {
  628. struct be_adapter *adapter = netdev_priv(netdev);
  629. int status;
  630. if (ecmd->autoneg != adapter->phy.fc_autoneg)
  631. return -EINVAL;
  632. status = be_cmd_set_flow_control(adapter, ecmd->tx_pause,
  633. ecmd->rx_pause);
  634. if (status) {
  635. dev_warn(&adapter->pdev->dev, "Pause param set failed\n");
  636. return be_cmd_status(status);
  637. }
  638. adapter->tx_fc = ecmd->tx_pause;
  639. adapter->rx_fc = ecmd->rx_pause;
  640. return 0;
  641. }
  642. static int be_set_phys_id(struct net_device *netdev,
  643. enum ethtool_phys_id_state state)
  644. {
  645. struct be_adapter *adapter = netdev_priv(netdev);
  646. int status = 0;
  647. switch (state) {
  648. case ETHTOOL_ID_ACTIVE:
  649. status = be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
  650. &adapter->beacon_state);
  651. if (status)
  652. return be_cmd_status(status);
  653. return 1; /* cycle on/off once per second */
  654. case ETHTOOL_ID_ON:
  655. status = be_cmd_set_beacon_state(adapter, adapter->hba_port_num,
  656. 0, 0, BEACON_STATE_ENABLED);
  657. break;
  658. case ETHTOOL_ID_OFF:
  659. status = be_cmd_set_beacon_state(adapter, adapter->hba_port_num,
  660. 0, 0, BEACON_STATE_DISABLED);
  661. break;
  662. case ETHTOOL_ID_INACTIVE:
  663. status = be_cmd_set_beacon_state(adapter, adapter->hba_port_num,
  664. 0, 0, adapter->beacon_state);
  665. }
  666. return be_cmd_status(status);
  667. }
  668. static int be_set_dump(struct net_device *netdev, struct ethtool_dump *dump)
  669. {
  670. struct be_adapter *adapter = netdev_priv(netdev);
  671. struct device *dev = &adapter->pdev->dev;
  672. int status;
  673. if (!lancer_chip(adapter) ||
  674. !check_privilege(adapter, MAX_PRIVILEGES))
  675. return -EOPNOTSUPP;
  676. switch (dump->flag) {
  677. case LANCER_INITIATE_FW_DUMP:
  678. status = lancer_initiate_dump(adapter);
  679. if (!status)
  680. dev_info(dev, "FW dump initiated successfully\n");
  681. break;
  682. case LANCER_DELETE_FW_DUMP:
  683. status = lancer_delete_dump(adapter);
  684. if (!status)
  685. dev_info(dev, "FW dump deleted successfully\n");
  686. break;
  687. default:
  688. dev_err(dev, "Invalid dump level: 0x%x\n", dump->flag);
  689. return -EINVAL;
  690. }
  691. return status;
  692. }
  693. static void be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  694. {
  695. struct be_adapter *adapter = netdev_priv(netdev);
  696. if (adapter->wol_cap & BE_WOL_CAP) {
  697. wol->supported |= WAKE_MAGIC;
  698. if (adapter->wol_en)
  699. wol->wolopts |= WAKE_MAGIC;
  700. } else {
  701. wol->wolopts = 0;
  702. }
  703. memset(&wol->sopass, 0, sizeof(wol->sopass));
  704. }
  705. static int be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  706. {
  707. struct be_adapter *adapter = netdev_priv(netdev);
  708. struct device *dev = &adapter->pdev->dev;
  709. struct be_dma_mem cmd;
  710. u8 mac[ETH_ALEN];
  711. bool enable;
  712. int status;
  713. if (wol->wolopts & ~WAKE_MAGIC)
  714. return -EOPNOTSUPP;
  715. if (!(adapter->wol_cap & BE_WOL_CAP)) {
  716. dev_warn(&adapter->pdev->dev, "WOL not supported\n");
  717. return -EOPNOTSUPP;
  718. }
  719. cmd.size = sizeof(struct be_cmd_req_acpi_wol_magic_config);
  720. cmd.va = dma_zalloc_coherent(dev, cmd.size, &cmd.dma, GFP_KERNEL);
  721. if (!cmd.va)
  722. return -ENOMEM;
  723. eth_zero_addr(mac);
  724. enable = wol->wolopts & WAKE_MAGIC;
  725. if (enable)
  726. ether_addr_copy(mac, adapter->netdev->dev_addr);
  727. status = be_cmd_enable_magic_wol(adapter, mac, &cmd);
  728. if (status) {
  729. dev_err(dev, "Could not set Wake-on-lan mac address\n");
  730. status = be_cmd_status(status);
  731. goto err;
  732. }
  733. pci_enable_wake(adapter->pdev, PCI_D3hot, enable);
  734. pci_enable_wake(adapter->pdev, PCI_D3cold, enable);
  735. adapter->wol_en = enable ? true : false;
  736. err:
  737. dma_free_coherent(dev, cmd.size, cmd.va, cmd.dma);
  738. return status;
  739. }
  740. static int be_test_ddr_dma(struct be_adapter *adapter)
  741. {
  742. int ret, i;
  743. struct be_dma_mem ddrdma_cmd;
  744. static const u64 pattern[2] = {
  745. 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
  746. };
  747. ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
  748. ddrdma_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
  749. ddrdma_cmd.size, &ddrdma_cmd.dma,
  750. GFP_KERNEL);
  751. if (!ddrdma_cmd.va)
  752. return -ENOMEM;
  753. for (i = 0; i < 2; i++) {
  754. ret = be_cmd_ddr_dma_test(adapter, pattern[i],
  755. 4096, &ddrdma_cmd);
  756. if (ret != 0)
  757. goto err;
  758. }
  759. err:
  760. dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
  761. ddrdma_cmd.dma);
  762. return be_cmd_status(ret);
  763. }
  764. static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
  765. u64 *status)
  766. {
  767. int ret;
  768. ret = be_cmd_set_loopback(adapter, adapter->hba_port_num,
  769. loopback_type, 1);
  770. if (ret)
  771. return ret;
  772. *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
  773. loopback_type, 1500, 2, 0xabc);
  774. ret = be_cmd_set_loopback(adapter, adapter->hba_port_num,
  775. BE_NO_LOOPBACK, 1);
  776. if (ret)
  777. return ret;
  778. return *status;
  779. }
  780. static void be_self_test(struct net_device *netdev, struct ethtool_test *test,
  781. u64 *data)
  782. {
  783. struct be_adapter *adapter = netdev_priv(netdev);
  784. int status;
  785. u8 link_status = 0;
  786. if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC) {
  787. dev_err(&adapter->pdev->dev, "Self test not supported\n");
  788. test->flags |= ETH_TEST_FL_FAILED;
  789. return;
  790. }
  791. memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
  792. if (test->flags & ETH_TEST_FL_OFFLINE) {
  793. if (be_loopback_test(adapter, BE_MAC_LOOPBACK, &data[0]) != 0)
  794. test->flags |= ETH_TEST_FL_FAILED;
  795. if (be_loopback_test(adapter, BE_PHY_LOOPBACK, &data[1]) != 0)
  796. test->flags |= ETH_TEST_FL_FAILED;
  797. if (test->flags & ETH_TEST_FL_EXTERNAL_LB) {
  798. if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
  799. &data[2]) != 0)
  800. test->flags |= ETH_TEST_FL_FAILED;
  801. test->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
  802. }
  803. }
  804. if (!lancer_chip(adapter) && be_test_ddr_dma(adapter) != 0) {
  805. data[3] = 1;
  806. test->flags |= ETH_TEST_FL_FAILED;
  807. }
  808. status = be_cmd_link_status_query(adapter, NULL, &link_status, 0);
  809. if (status) {
  810. test->flags |= ETH_TEST_FL_FAILED;
  811. data[4] = -1;
  812. } else if (!link_status) {
  813. test->flags |= ETH_TEST_FL_FAILED;
  814. data[4] = 1;
  815. }
  816. }
  817. static int be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
  818. {
  819. struct be_adapter *adapter = netdev_priv(netdev);
  820. return be_load_fw(adapter, efl->data);
  821. }
  822. static int
  823. be_get_dump_flag(struct net_device *netdev, struct ethtool_dump *dump)
  824. {
  825. struct be_adapter *adapter = netdev_priv(netdev);
  826. if (!check_privilege(adapter, MAX_PRIVILEGES))
  827. return -EOPNOTSUPP;
  828. dump->len = be_get_dump_len(adapter);
  829. dump->version = 1;
  830. dump->flag = 0x1; /* FW dump is enabled */
  831. return 0;
  832. }
  833. static int
  834. be_get_dump_data(struct net_device *netdev, struct ethtool_dump *dump,
  835. void *buf)
  836. {
  837. struct be_adapter *adapter = netdev_priv(netdev);
  838. int status;
  839. if (!check_privilege(adapter, MAX_PRIVILEGES))
  840. return -EOPNOTSUPP;
  841. status = be_read_dump_data(adapter, dump->len, buf);
  842. return be_cmd_status(status);
  843. }
  844. static int be_get_eeprom_len(struct net_device *netdev)
  845. {
  846. struct be_adapter *adapter = netdev_priv(netdev);
  847. if (!check_privilege(adapter, MAX_PRIVILEGES))
  848. return 0;
  849. if (lancer_chip(adapter)) {
  850. if (be_physfn(adapter))
  851. return lancer_cmd_get_file_len(adapter,
  852. LANCER_VPD_PF_FILE);
  853. else
  854. return lancer_cmd_get_file_len(adapter,
  855. LANCER_VPD_VF_FILE);
  856. } else {
  857. return BE_READ_SEEPROM_LEN;
  858. }
  859. }
  860. static int be_read_eeprom(struct net_device *netdev,
  861. struct ethtool_eeprom *eeprom, uint8_t *data)
  862. {
  863. struct be_adapter *adapter = netdev_priv(netdev);
  864. struct be_dma_mem eeprom_cmd;
  865. struct be_cmd_resp_seeprom_read *resp;
  866. int status;
  867. if (!eeprom->len)
  868. return -EINVAL;
  869. if (lancer_chip(adapter)) {
  870. if (be_physfn(adapter))
  871. return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE,
  872. eeprom->len, data);
  873. else
  874. return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE,
  875. eeprom->len, data);
  876. }
  877. eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
  878. memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
  879. eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
  880. eeprom_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
  881. eeprom_cmd.size, &eeprom_cmd.dma,
  882. GFP_KERNEL);
  883. if (!eeprom_cmd.va)
  884. return -ENOMEM;
  885. status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
  886. if (!status) {
  887. resp = eeprom_cmd.va;
  888. memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
  889. }
  890. dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
  891. eeprom_cmd.dma);
  892. return be_cmd_status(status);
  893. }
  894. static u32 be_get_msg_level(struct net_device *netdev)
  895. {
  896. struct be_adapter *adapter = netdev_priv(netdev);
  897. return adapter->msg_enable;
  898. }
  899. static void be_set_msg_level(struct net_device *netdev, u32 level)
  900. {
  901. struct be_adapter *adapter = netdev_priv(netdev);
  902. if (adapter->msg_enable == level)
  903. return;
  904. if ((level & NETIF_MSG_HW) != (adapter->msg_enable & NETIF_MSG_HW))
  905. if (BEx_chip(adapter))
  906. be_cmd_set_fw_log_level(adapter, level & NETIF_MSG_HW ?
  907. FW_LOG_LEVEL_DEFAULT :
  908. FW_LOG_LEVEL_FATAL);
  909. adapter->msg_enable = level;
  910. }
  911. static u64 be_get_rss_hash_opts(struct be_adapter *adapter, u64 flow_type)
  912. {
  913. u64 data = 0;
  914. switch (flow_type) {
  915. case TCP_V4_FLOW:
  916. if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
  917. data |= RXH_IP_DST | RXH_IP_SRC;
  918. if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV4)
  919. data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  920. break;
  921. case UDP_V4_FLOW:
  922. if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
  923. data |= RXH_IP_DST | RXH_IP_SRC;
  924. if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV4)
  925. data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  926. break;
  927. case TCP_V6_FLOW:
  928. if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
  929. data |= RXH_IP_DST | RXH_IP_SRC;
  930. if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV6)
  931. data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  932. break;
  933. case UDP_V6_FLOW:
  934. if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
  935. data |= RXH_IP_DST | RXH_IP_SRC;
  936. if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV6)
  937. data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  938. break;
  939. }
  940. return data;
  941. }
  942. static int be_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
  943. u32 *rule_locs)
  944. {
  945. struct be_adapter *adapter = netdev_priv(netdev);
  946. if (!be_multi_rxq(adapter)) {
  947. dev_info(&adapter->pdev->dev,
  948. "ethtool::get_rxnfc: RX flow hashing is disabled\n");
  949. return -EINVAL;
  950. }
  951. switch (cmd->cmd) {
  952. case ETHTOOL_GRXFH:
  953. cmd->data = be_get_rss_hash_opts(adapter, cmd->flow_type);
  954. break;
  955. case ETHTOOL_GRXRINGS:
  956. cmd->data = adapter->num_rx_qs - 1;
  957. break;
  958. default:
  959. return -EINVAL;
  960. }
  961. return 0;
  962. }
  963. static int be_set_rss_hash_opts(struct be_adapter *adapter,
  964. struct ethtool_rxnfc *cmd)
  965. {
  966. int status;
  967. u32 rss_flags = adapter->rss_info.rss_flags;
  968. if (cmd->data != L3_RSS_FLAGS &&
  969. cmd->data != (L3_RSS_FLAGS | L4_RSS_FLAGS))
  970. return -EINVAL;
  971. switch (cmd->flow_type) {
  972. case TCP_V4_FLOW:
  973. if (cmd->data == L3_RSS_FLAGS)
  974. rss_flags &= ~RSS_ENABLE_TCP_IPV4;
  975. else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
  976. rss_flags |= RSS_ENABLE_IPV4 |
  977. RSS_ENABLE_TCP_IPV4;
  978. break;
  979. case TCP_V6_FLOW:
  980. if (cmd->data == L3_RSS_FLAGS)
  981. rss_flags &= ~RSS_ENABLE_TCP_IPV6;
  982. else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
  983. rss_flags |= RSS_ENABLE_IPV6 |
  984. RSS_ENABLE_TCP_IPV6;
  985. break;
  986. case UDP_V4_FLOW:
  987. if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
  988. BEx_chip(adapter))
  989. return -EINVAL;
  990. if (cmd->data == L3_RSS_FLAGS)
  991. rss_flags &= ~RSS_ENABLE_UDP_IPV4;
  992. else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
  993. rss_flags |= RSS_ENABLE_IPV4 |
  994. RSS_ENABLE_UDP_IPV4;
  995. break;
  996. case UDP_V6_FLOW:
  997. if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
  998. BEx_chip(adapter))
  999. return -EINVAL;
  1000. if (cmd->data == L3_RSS_FLAGS)
  1001. rss_flags &= ~RSS_ENABLE_UDP_IPV6;
  1002. else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
  1003. rss_flags |= RSS_ENABLE_IPV6 |
  1004. RSS_ENABLE_UDP_IPV6;
  1005. break;
  1006. default:
  1007. return -EINVAL;
  1008. }
  1009. if (rss_flags == adapter->rss_info.rss_flags)
  1010. return 0;
  1011. status = be_cmd_rss_config(adapter, adapter->rss_info.rsstable,
  1012. rss_flags, RSS_INDIR_TABLE_LEN,
  1013. adapter->rss_info.rss_hkey);
  1014. if (!status)
  1015. adapter->rss_info.rss_flags = rss_flags;
  1016. return be_cmd_status(status);
  1017. }
  1018. static int be_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
  1019. {
  1020. struct be_adapter *adapter = netdev_priv(netdev);
  1021. int status = 0;
  1022. if (!be_multi_rxq(adapter)) {
  1023. dev_err(&adapter->pdev->dev,
  1024. "ethtool::set_rxnfc: RX flow hashing is disabled\n");
  1025. return -EINVAL;
  1026. }
  1027. switch (cmd->cmd) {
  1028. case ETHTOOL_SRXFH:
  1029. status = be_set_rss_hash_opts(adapter, cmd);
  1030. break;
  1031. default:
  1032. return -EINVAL;
  1033. }
  1034. return status;
  1035. }
  1036. static void be_get_channels(struct net_device *netdev,
  1037. struct ethtool_channels *ch)
  1038. {
  1039. struct be_adapter *adapter = netdev_priv(netdev);
  1040. u16 num_rx_irqs = max_t(u16, adapter->num_rss_qs, 1);
  1041. /* num_tx_qs is always same as the number of irqs used for TX */
  1042. ch->combined_count = min(adapter->num_tx_qs, num_rx_irqs);
  1043. ch->rx_count = num_rx_irqs - ch->combined_count;
  1044. ch->tx_count = adapter->num_tx_qs - ch->combined_count;
  1045. ch->max_combined = be_max_qp_irqs(adapter);
  1046. /* The user must create atleast one combined channel */
  1047. ch->max_rx = be_max_rx_irqs(adapter) - 1;
  1048. ch->max_tx = be_max_tx_irqs(adapter) - 1;
  1049. }
  1050. static int be_set_channels(struct net_device *netdev,
  1051. struct ethtool_channels *ch)
  1052. {
  1053. struct be_adapter *adapter = netdev_priv(netdev);
  1054. int status;
  1055. /* we support either only combined channels or a combination of
  1056. * combined and either RX-only or TX-only channels.
  1057. */
  1058. if (ch->other_count || !ch->combined_count ||
  1059. (ch->rx_count && ch->tx_count))
  1060. return -EINVAL;
  1061. if (ch->combined_count > be_max_qp_irqs(adapter) ||
  1062. (ch->rx_count &&
  1063. (ch->rx_count + ch->combined_count) > be_max_rx_irqs(adapter)) ||
  1064. (ch->tx_count &&
  1065. (ch->tx_count + ch->combined_count) > be_max_tx_irqs(adapter)))
  1066. return -EINVAL;
  1067. adapter->cfg_num_rx_irqs = ch->combined_count + ch->rx_count;
  1068. adapter->cfg_num_tx_irqs = ch->combined_count + ch->tx_count;
  1069. status = be_update_queues(adapter);
  1070. return be_cmd_status(status);
  1071. }
  1072. static u32 be_get_rxfh_indir_size(struct net_device *netdev)
  1073. {
  1074. return RSS_INDIR_TABLE_LEN;
  1075. }
  1076. static u32 be_get_rxfh_key_size(struct net_device *netdev)
  1077. {
  1078. return RSS_HASH_KEY_LEN;
  1079. }
  1080. static int be_get_rxfh(struct net_device *netdev, u32 *indir, u8 *hkey,
  1081. u8 *hfunc)
  1082. {
  1083. struct be_adapter *adapter = netdev_priv(netdev);
  1084. int i;
  1085. struct rss_info *rss = &adapter->rss_info;
  1086. if (indir) {
  1087. for (i = 0; i < RSS_INDIR_TABLE_LEN; i++)
  1088. indir[i] = rss->rss_queue[i];
  1089. }
  1090. if (hkey)
  1091. memcpy(hkey, rss->rss_hkey, RSS_HASH_KEY_LEN);
  1092. if (hfunc)
  1093. *hfunc = ETH_RSS_HASH_TOP;
  1094. return 0;
  1095. }
  1096. static int be_set_rxfh(struct net_device *netdev, const u32 *indir,
  1097. const u8 *hkey, const u8 hfunc)
  1098. {
  1099. int rc = 0, i, j;
  1100. struct be_adapter *adapter = netdev_priv(netdev);
  1101. u8 rsstable[RSS_INDIR_TABLE_LEN];
  1102. /* We do not allow change in unsupported parameters */
  1103. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
  1104. return -EOPNOTSUPP;
  1105. if (indir) {
  1106. struct be_rx_obj *rxo;
  1107. for (i = 0; i < RSS_INDIR_TABLE_LEN; i++) {
  1108. j = indir[i];
  1109. rxo = &adapter->rx_obj[j];
  1110. rsstable[i] = rxo->rss_id;
  1111. adapter->rss_info.rss_queue[i] = j;
  1112. }
  1113. } else {
  1114. memcpy(rsstable, adapter->rss_info.rsstable,
  1115. RSS_INDIR_TABLE_LEN);
  1116. }
  1117. if (!hkey)
  1118. hkey = adapter->rss_info.rss_hkey;
  1119. rc = be_cmd_rss_config(adapter, rsstable,
  1120. adapter->rss_info.rss_flags,
  1121. RSS_INDIR_TABLE_LEN, hkey);
  1122. if (rc) {
  1123. adapter->rss_info.rss_flags = RSS_ENABLE_NONE;
  1124. return -EIO;
  1125. }
  1126. memcpy(adapter->rss_info.rss_hkey, hkey, RSS_HASH_KEY_LEN);
  1127. memcpy(adapter->rss_info.rsstable, rsstable,
  1128. RSS_INDIR_TABLE_LEN);
  1129. return 0;
  1130. }
  1131. static int be_get_module_info(struct net_device *netdev,
  1132. struct ethtool_modinfo *modinfo)
  1133. {
  1134. struct be_adapter *adapter = netdev_priv(netdev);
  1135. u8 page_data[PAGE_DATA_LEN];
  1136. int status;
  1137. if (!check_privilege(adapter, MAX_PRIVILEGES))
  1138. return -EOPNOTSUPP;
  1139. status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
  1140. page_data);
  1141. if (!status) {
  1142. if (!page_data[SFP_PLUS_SFF_8472_COMP]) {
  1143. modinfo->type = ETH_MODULE_SFF_8079;
  1144. modinfo->eeprom_len = PAGE_DATA_LEN;
  1145. } else {
  1146. modinfo->type = ETH_MODULE_SFF_8472;
  1147. modinfo->eeprom_len = 2 * PAGE_DATA_LEN;
  1148. }
  1149. }
  1150. return be_cmd_status(status);
  1151. }
  1152. static int be_get_module_eeprom(struct net_device *netdev,
  1153. struct ethtool_eeprom *eeprom, u8 *data)
  1154. {
  1155. struct be_adapter *adapter = netdev_priv(netdev);
  1156. int status;
  1157. if (!check_privilege(adapter, MAX_PRIVILEGES))
  1158. return -EOPNOTSUPP;
  1159. status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
  1160. data);
  1161. if (status)
  1162. goto err;
  1163. if (eeprom->offset + eeprom->len > PAGE_DATA_LEN) {
  1164. status = be_cmd_read_port_transceiver_data(adapter,
  1165. TR_PAGE_A2,
  1166. data +
  1167. PAGE_DATA_LEN);
  1168. if (status)
  1169. goto err;
  1170. }
  1171. if (eeprom->offset)
  1172. memcpy(data, data + eeprom->offset, eeprom->len);
  1173. err:
  1174. return be_cmd_status(status);
  1175. }
  1176. const struct ethtool_ops be_ethtool_ops = {
  1177. .get_settings = be_get_settings,
  1178. .get_drvinfo = be_get_drvinfo,
  1179. .get_wol = be_get_wol,
  1180. .set_wol = be_set_wol,
  1181. .get_link = ethtool_op_get_link,
  1182. .get_eeprom_len = be_get_eeprom_len,
  1183. .get_eeprom = be_read_eeprom,
  1184. .get_coalesce = be_get_coalesce,
  1185. .set_coalesce = be_set_coalesce,
  1186. .get_ringparam = be_get_ringparam,
  1187. .get_pauseparam = be_get_pauseparam,
  1188. .set_pauseparam = be_set_pauseparam,
  1189. .get_strings = be_get_stat_strings,
  1190. .set_phys_id = be_set_phys_id,
  1191. .set_dump = be_set_dump,
  1192. .get_msglevel = be_get_msg_level,
  1193. .set_msglevel = be_set_msg_level,
  1194. .get_sset_count = be_get_sset_count,
  1195. .get_ethtool_stats = be_get_ethtool_stats,
  1196. .flash_device = be_do_flash,
  1197. .self_test = be_self_test,
  1198. .get_rxnfc = be_get_rxnfc,
  1199. .set_rxnfc = be_set_rxnfc,
  1200. .get_rxfh_indir_size = be_get_rxfh_indir_size,
  1201. .get_rxfh_key_size = be_get_rxfh_key_size,
  1202. .get_rxfh = be_get_rxfh,
  1203. .set_rxfh = be_set_rxfh,
  1204. .get_dump_flag = be_get_dump_flag,
  1205. .get_dump_data = be_get_dump_data,
  1206. .get_channels = be_get_channels,
  1207. .set_channels = be_set_channels,
  1208. .get_module_info = be_get_module_info,
  1209. .get_module_eeprom = be_get_module_eeprom
  1210. };