be_ethtool.c 36 KB

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