be_ethtool.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  1. /*
  2. * Copyright (C) 2005 - 2013 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. {DRVSTAT_INFO(rx_input_fifo_overflow_drop)},
  78. {DRVSTAT_INFO(rx_ip_checksum_errs)},
  79. {DRVSTAT_INFO(rx_tcp_checksum_errs)},
  80. {DRVSTAT_INFO(rx_udp_checksum_errs)},
  81. {DRVSTAT_INFO(tx_pauseframes)},
  82. {DRVSTAT_INFO(tx_controlframes)},
  83. {DRVSTAT_INFO(rx_priority_pause_frames)},
  84. /* Received packets dropped when an internal fifo going into
  85. * main packet buffer tank (PMEM) overflows.
  86. */
  87. {DRVSTAT_INFO(pmem_fifo_overflow_drop)},
  88. {DRVSTAT_INFO(jabber_events)},
  89. /* Received packets dropped due to lack of available HW packet buffers
  90. * used to temporarily hold the received packets.
  91. */
  92. {DRVSTAT_INFO(rx_drops_no_pbuf)},
  93. /* Received packets dropped due to input receive buffer
  94. * descriptor fifo overflowing.
  95. */
  96. {DRVSTAT_INFO(rx_drops_no_erx_descr)},
  97. /* Packets dropped because the internal FIFO to the offloaded TCP
  98. * receive processing block is full. This could happen only for
  99. * offloaded iSCSI or FCoE trarffic.
  100. */
  101. {DRVSTAT_INFO(rx_drops_no_tpre_descr)},
  102. /* Received packets dropped when they need more than 8
  103. * receive buffers. This cannot happen as the driver configures
  104. * 2048 byte receive buffers.
  105. */
  106. {DRVSTAT_INFO(rx_drops_too_many_frags)},
  107. {DRVSTAT_INFO(forwarded_packets)},
  108. /* Received packets dropped when the frame length
  109. * is more than 9018 bytes
  110. */
  111. {DRVSTAT_INFO(rx_drops_mtu)},
  112. /* Number of packets dropped due to random early drop function */
  113. {DRVSTAT_INFO(eth_red_drops)},
  114. {DRVSTAT_INFO(be_on_die_temperature)}
  115. };
  116. #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
  117. /* Stats related to multi RX queues: get_stats routine assumes bytes, pkts
  118. * are first and second members respectively.
  119. */
  120. static const struct be_ethtool_stat et_rx_stats[] = {
  121. {DRVSTAT_RX_INFO(rx_bytes)},/* If moving this member see above note */
  122. {DRVSTAT_RX_INFO(rx_pkts)}, /* If moving this member see above note */
  123. {DRVSTAT_RX_INFO(rx_compl)},
  124. {DRVSTAT_RX_INFO(rx_mcast_pkts)},
  125. /* Number of page allocation failures while posting receive buffers
  126. * to HW.
  127. */
  128. {DRVSTAT_RX_INFO(rx_post_fail)},
  129. /* Recevied packets dropped due to skb allocation failure */
  130. {DRVSTAT_RX_INFO(rx_drops_no_skbs)},
  131. /* Received packets dropped due to lack of available fetched buffers
  132. * posted by the driver.
  133. */
  134. {DRVSTAT_RX_INFO(rx_drops_no_frags)}
  135. };
  136. #define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
  137. /* Stats related to multi TX queues: get_stats routine assumes compl is the
  138. * first member
  139. */
  140. static const struct be_ethtool_stat et_tx_stats[] = {
  141. {DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */
  142. {DRVSTAT_TX_INFO(tx_bytes)},
  143. {DRVSTAT_TX_INFO(tx_pkts)},
  144. /* Number of skbs queued for trasmission by the driver */
  145. {DRVSTAT_TX_INFO(tx_reqs)},
  146. /* Number of TX work request blocks DMAed to HW */
  147. {DRVSTAT_TX_INFO(tx_wrbs)},
  148. /* Number of times the TX queue was stopped due to lack
  149. * of spaces in the TXQ.
  150. */
  151. {DRVSTAT_TX_INFO(tx_stops)}
  152. };
  153. #define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats))
  154. static const char et_self_tests[][ETH_GSTRING_LEN] = {
  155. "MAC Loopback test",
  156. "PHY Loopback test",
  157. "External Loopback test",
  158. "DDR DMA test",
  159. "Link test"
  160. };
  161. #define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
  162. #define BE_MAC_LOOPBACK 0x0
  163. #define BE_PHY_LOOPBACK 0x1
  164. #define BE_ONE_PORT_EXT_LOOPBACK 0x2
  165. #define BE_NO_LOOPBACK 0xff
  166. static void be_get_drvinfo(struct net_device *netdev,
  167. struct ethtool_drvinfo *drvinfo)
  168. {
  169. struct be_adapter *adapter = netdev_priv(netdev);
  170. char fw_on_flash[FW_VER_LEN];
  171. memset(fw_on_flash, 0 , sizeof(fw_on_flash));
  172. be_cmd_get_fw_ver(adapter, adapter->fw_ver, fw_on_flash);
  173. strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
  174. strlcpy(drvinfo->version, DRV_VER, sizeof(drvinfo->version));
  175. if (!memcmp(adapter->fw_ver, fw_on_flash, FW_VER_LEN))
  176. strlcpy(drvinfo->fw_version, adapter->fw_ver,
  177. sizeof(drvinfo->fw_version));
  178. else
  179. snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
  180. "%s [%s]", adapter->fw_ver, fw_on_flash);
  181. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
  182. sizeof(drvinfo->bus_info));
  183. drvinfo->testinfo_len = 0;
  184. drvinfo->regdump_len = 0;
  185. drvinfo->eedump_len = 0;
  186. }
  187. static u32
  188. lancer_cmd_get_file_len(struct be_adapter *adapter, u8 *file_name)
  189. {
  190. u32 data_read = 0, eof;
  191. u8 addn_status;
  192. struct be_dma_mem data_len_cmd;
  193. int status;
  194. memset(&data_len_cmd, 0, sizeof(data_len_cmd));
  195. /* data_offset and data_size should be 0 to get reg len */
  196. status = lancer_cmd_read_object(adapter, &data_len_cmd, 0, 0,
  197. file_name, &data_read, &eof, &addn_status);
  198. return data_read;
  199. }
  200. static int
  201. lancer_cmd_read_file(struct be_adapter *adapter, u8 *file_name,
  202. u32 buf_len, void *buf)
  203. {
  204. struct be_dma_mem read_cmd;
  205. u32 read_len = 0, total_read_len = 0, chunk_size;
  206. u32 eof = 0;
  207. u8 addn_status;
  208. int status = 0;
  209. read_cmd.size = LANCER_READ_FILE_CHUNK;
  210. read_cmd.va = pci_alloc_consistent(adapter->pdev, read_cmd.size,
  211. &read_cmd.dma);
  212. if (!read_cmd.va) {
  213. dev_err(&adapter->pdev->dev,
  214. "Memory allocation failure while reading dump\n");
  215. return -ENOMEM;
  216. }
  217. while ((total_read_len < buf_len) && !eof) {
  218. chunk_size = min_t(u32, (buf_len - total_read_len),
  219. LANCER_READ_FILE_CHUNK);
  220. chunk_size = ALIGN(chunk_size, 4);
  221. status = lancer_cmd_read_object(adapter, &read_cmd, chunk_size,
  222. total_read_len, file_name, &read_len,
  223. &eof, &addn_status);
  224. if (!status) {
  225. memcpy(buf + total_read_len, read_cmd.va, read_len);
  226. total_read_len += read_len;
  227. eof &= LANCER_READ_FILE_EOF_MASK;
  228. } else {
  229. status = -EIO;
  230. break;
  231. }
  232. }
  233. pci_free_consistent(adapter->pdev, read_cmd.size, read_cmd.va,
  234. read_cmd.dma);
  235. return status;
  236. }
  237. static int
  238. be_get_reg_len(struct net_device *netdev)
  239. {
  240. struct be_adapter *adapter = netdev_priv(netdev);
  241. u32 log_size = 0;
  242. if (!check_privilege(adapter, MAX_PRIVILEGES))
  243. return 0;
  244. if (be_physfn(adapter)) {
  245. if (lancer_chip(adapter))
  246. log_size = lancer_cmd_get_file_len(adapter,
  247. LANCER_FW_DUMP_FILE);
  248. else
  249. be_cmd_get_reg_len(adapter, &log_size);
  250. }
  251. return log_size;
  252. }
  253. static void
  254. be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
  255. {
  256. struct be_adapter *adapter = netdev_priv(netdev);
  257. if (be_physfn(adapter)) {
  258. memset(buf, 0, regs->len);
  259. if (lancer_chip(adapter))
  260. lancer_cmd_read_file(adapter, LANCER_FW_DUMP_FILE,
  261. regs->len, buf);
  262. else
  263. be_cmd_get_regs(adapter, regs->len, buf);
  264. }
  265. }
  266. static int be_get_coalesce(struct net_device *netdev,
  267. struct ethtool_coalesce *et)
  268. {
  269. struct be_adapter *adapter = netdev_priv(netdev);
  270. struct be_eq_obj *eqo = &adapter->eq_obj[0];
  271. et->rx_coalesce_usecs = eqo->cur_eqd;
  272. et->rx_coalesce_usecs_high = eqo->max_eqd;
  273. et->rx_coalesce_usecs_low = eqo->min_eqd;
  274. et->tx_coalesce_usecs = eqo->cur_eqd;
  275. et->tx_coalesce_usecs_high = eqo->max_eqd;
  276. et->tx_coalesce_usecs_low = eqo->min_eqd;
  277. et->use_adaptive_rx_coalesce = eqo->enable_aic;
  278. et->use_adaptive_tx_coalesce = eqo->enable_aic;
  279. return 0;
  280. }
  281. /* TX attributes are ignored. Only RX attributes are considered
  282. * eqd cmd is issued in the worker thread.
  283. */
  284. static int be_set_coalesce(struct net_device *netdev,
  285. struct ethtool_coalesce *et)
  286. {
  287. struct be_adapter *adapter = netdev_priv(netdev);
  288. struct be_eq_obj *eqo;
  289. int i;
  290. for_all_evt_queues(adapter, eqo, i) {
  291. eqo->enable_aic = et->use_adaptive_rx_coalesce;
  292. eqo->max_eqd = min(et->rx_coalesce_usecs_high, BE_MAX_EQD);
  293. eqo->min_eqd = min(et->rx_coalesce_usecs_low, eqo->max_eqd);
  294. eqo->eqd = et->rx_coalesce_usecs;
  295. }
  296. return 0;
  297. }
  298. static void
  299. be_get_ethtool_stats(struct net_device *netdev,
  300. struct ethtool_stats *stats, uint64_t *data)
  301. {
  302. struct be_adapter *adapter = netdev_priv(netdev);
  303. struct be_rx_obj *rxo;
  304. struct be_tx_obj *txo;
  305. void *p;
  306. unsigned int i, j, base = 0, start;
  307. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  308. p = (u8 *)&adapter->drv_stats + et_stats[i].offset;
  309. data[i] = *(u32 *)p;
  310. }
  311. base += ETHTOOL_STATS_NUM;
  312. for_all_rx_queues(adapter, rxo, j) {
  313. struct be_rx_stats *stats = rx_stats(rxo);
  314. do {
  315. start = u64_stats_fetch_begin_bh(&stats->sync);
  316. data[base] = stats->rx_bytes;
  317. data[base + 1] = stats->rx_pkts;
  318. } while (u64_stats_fetch_retry_bh(&stats->sync, start));
  319. for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) {
  320. p = (u8 *)stats + et_rx_stats[i].offset;
  321. data[base + i] = *(u32 *)p;
  322. }
  323. base += ETHTOOL_RXSTATS_NUM;
  324. }
  325. for_all_tx_queues(adapter, txo, j) {
  326. struct be_tx_stats *stats = tx_stats(txo);
  327. do {
  328. start = u64_stats_fetch_begin_bh(&stats->sync_compl);
  329. data[base] = stats->tx_compl;
  330. } while (u64_stats_fetch_retry_bh(&stats->sync_compl, start));
  331. do {
  332. start = u64_stats_fetch_begin_bh(&stats->sync);
  333. for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) {
  334. p = (u8 *)stats + et_tx_stats[i].offset;
  335. data[base + i] =
  336. (et_tx_stats[i].size == sizeof(u64)) ?
  337. *(u64 *)p : *(u32 *)p;
  338. }
  339. } while (u64_stats_fetch_retry_bh(&stats->sync, start));
  340. base += ETHTOOL_TXSTATS_NUM;
  341. }
  342. }
  343. static void
  344. be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
  345. uint8_t *data)
  346. {
  347. struct be_adapter *adapter = netdev_priv(netdev);
  348. int i, j;
  349. switch (stringset) {
  350. case ETH_SS_STATS:
  351. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  352. memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
  353. data += ETH_GSTRING_LEN;
  354. }
  355. for (i = 0; i < adapter->num_rx_qs; i++) {
  356. for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
  357. sprintf(data, "rxq%d: %s", i,
  358. et_rx_stats[j].desc);
  359. data += ETH_GSTRING_LEN;
  360. }
  361. }
  362. for (i = 0; i < adapter->num_tx_qs; i++) {
  363. for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) {
  364. sprintf(data, "txq%d: %s", i,
  365. et_tx_stats[j].desc);
  366. data += ETH_GSTRING_LEN;
  367. }
  368. }
  369. break;
  370. case ETH_SS_TEST:
  371. for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
  372. memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
  373. data += ETH_GSTRING_LEN;
  374. }
  375. break;
  376. }
  377. }
  378. static int be_get_sset_count(struct net_device *netdev, int stringset)
  379. {
  380. struct be_adapter *adapter = netdev_priv(netdev);
  381. switch (stringset) {
  382. case ETH_SS_TEST:
  383. return ETHTOOL_TESTS_NUM;
  384. case ETH_SS_STATS:
  385. return ETHTOOL_STATS_NUM +
  386. adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
  387. adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
  388. default:
  389. return -EINVAL;
  390. }
  391. }
  392. static u32 be_get_port_type(u32 phy_type, u32 dac_cable_len)
  393. {
  394. u32 port;
  395. switch (phy_type) {
  396. case PHY_TYPE_BASET_1GB:
  397. case PHY_TYPE_BASEX_1GB:
  398. case PHY_TYPE_SGMII:
  399. port = PORT_TP;
  400. break;
  401. case PHY_TYPE_SFP_PLUS_10GB:
  402. port = dac_cable_len ? PORT_DA : PORT_FIBRE;
  403. break;
  404. case PHY_TYPE_XFP_10GB:
  405. case PHY_TYPE_SFP_1GB:
  406. port = PORT_FIBRE;
  407. break;
  408. case PHY_TYPE_BASET_10GB:
  409. port = PORT_TP;
  410. break;
  411. default:
  412. port = PORT_OTHER;
  413. }
  414. return port;
  415. }
  416. static u32 convert_to_et_setting(u32 if_type, u32 if_speeds)
  417. {
  418. u32 val = 0;
  419. switch (if_type) {
  420. case PHY_TYPE_BASET_1GB:
  421. case PHY_TYPE_BASEX_1GB:
  422. case PHY_TYPE_SGMII:
  423. val |= SUPPORTED_TP;
  424. if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
  425. val |= SUPPORTED_1000baseT_Full;
  426. if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
  427. val |= SUPPORTED_100baseT_Full;
  428. if (if_speeds & BE_SUPPORTED_SPEED_10MBPS)
  429. val |= SUPPORTED_10baseT_Full;
  430. break;
  431. case PHY_TYPE_KX4_10GB:
  432. val |= SUPPORTED_Backplane;
  433. if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
  434. val |= SUPPORTED_1000baseKX_Full;
  435. if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
  436. val |= SUPPORTED_10000baseKX4_Full;
  437. break;
  438. case PHY_TYPE_KR_10GB:
  439. val |= SUPPORTED_Backplane |
  440. SUPPORTED_10000baseKR_Full;
  441. break;
  442. case PHY_TYPE_SFP_PLUS_10GB:
  443. case PHY_TYPE_XFP_10GB:
  444. case PHY_TYPE_SFP_1GB:
  445. val |= SUPPORTED_FIBRE;
  446. if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
  447. val |= SUPPORTED_10000baseT_Full;
  448. if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
  449. val |= SUPPORTED_1000baseT_Full;
  450. break;
  451. case PHY_TYPE_BASET_10GB:
  452. val |= SUPPORTED_TP;
  453. if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
  454. val |= SUPPORTED_10000baseT_Full;
  455. if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
  456. val |= SUPPORTED_1000baseT_Full;
  457. if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
  458. val |= SUPPORTED_100baseT_Full;
  459. break;
  460. default:
  461. val |= SUPPORTED_TP;
  462. }
  463. return val;
  464. }
  465. bool be_pause_supported(struct be_adapter *adapter)
  466. {
  467. return (adapter->phy.interface_type == PHY_TYPE_SFP_PLUS_10GB ||
  468. adapter->phy.interface_type == PHY_TYPE_XFP_10GB) ?
  469. false : true;
  470. }
  471. static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  472. {
  473. struct be_adapter *adapter = netdev_priv(netdev);
  474. u8 link_status;
  475. u16 link_speed = 0;
  476. int status;
  477. u32 auto_speeds;
  478. u32 fixed_speeds;
  479. u32 dac_cable_len;
  480. u16 interface_type;
  481. if (adapter->phy.link_speed < 0) {
  482. status = be_cmd_link_status_query(adapter, &link_speed,
  483. &link_status, 0);
  484. if (!status)
  485. be_link_status_update(adapter, link_status);
  486. ethtool_cmd_speed_set(ecmd, link_speed);
  487. status = be_cmd_get_phy_info(adapter);
  488. if (!status) {
  489. interface_type = adapter->phy.interface_type;
  490. auto_speeds = adapter->phy.auto_speeds_supported;
  491. fixed_speeds = adapter->phy.fixed_speeds_supported;
  492. dac_cable_len = adapter->phy.dac_cable_len;
  493. ecmd->supported =
  494. convert_to_et_setting(interface_type,
  495. auto_speeds |
  496. fixed_speeds);
  497. ecmd->advertising =
  498. convert_to_et_setting(interface_type,
  499. auto_speeds);
  500. ecmd->port = be_get_port_type(interface_type,
  501. dac_cable_len);
  502. if (adapter->phy.auto_speeds_supported) {
  503. ecmd->supported |= SUPPORTED_Autoneg;
  504. ecmd->autoneg = AUTONEG_ENABLE;
  505. ecmd->advertising |= ADVERTISED_Autoneg;
  506. }
  507. ecmd->supported |= SUPPORTED_Pause;
  508. if (be_pause_supported(adapter))
  509. ecmd->advertising |= ADVERTISED_Pause;
  510. switch (adapter->phy.interface_type) {
  511. case PHY_TYPE_KR_10GB:
  512. case PHY_TYPE_KX4_10GB:
  513. ecmd->transceiver = XCVR_INTERNAL;
  514. break;
  515. default:
  516. ecmd->transceiver = XCVR_EXTERNAL;
  517. break;
  518. }
  519. } else {
  520. ecmd->port = PORT_OTHER;
  521. ecmd->autoneg = AUTONEG_DISABLE;
  522. ecmd->transceiver = XCVR_DUMMY1;
  523. }
  524. /* Save for future use */
  525. adapter->phy.link_speed = ethtool_cmd_speed(ecmd);
  526. adapter->phy.port_type = ecmd->port;
  527. adapter->phy.transceiver = ecmd->transceiver;
  528. adapter->phy.autoneg = ecmd->autoneg;
  529. adapter->phy.advertising = ecmd->advertising;
  530. adapter->phy.supported = ecmd->supported;
  531. } else {
  532. ethtool_cmd_speed_set(ecmd, adapter->phy.link_speed);
  533. ecmd->port = adapter->phy.port_type;
  534. ecmd->transceiver = adapter->phy.transceiver;
  535. ecmd->autoneg = adapter->phy.autoneg;
  536. ecmd->advertising = adapter->phy.advertising;
  537. ecmd->supported = adapter->phy.supported;
  538. }
  539. ecmd->duplex = netif_carrier_ok(netdev) ? DUPLEX_FULL : DUPLEX_UNKNOWN;
  540. ecmd->phy_address = adapter->port_num;
  541. return 0;
  542. }
  543. static void be_get_ringparam(struct net_device *netdev,
  544. struct ethtool_ringparam *ring)
  545. {
  546. struct be_adapter *adapter = netdev_priv(netdev);
  547. ring->rx_max_pending = ring->rx_pending = adapter->rx_obj[0].q.len;
  548. ring->tx_max_pending = ring->tx_pending = adapter->tx_obj[0].q.len;
  549. }
  550. static void
  551. be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  552. {
  553. struct be_adapter *adapter = netdev_priv(netdev);
  554. be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
  555. ecmd->autoneg = adapter->phy.fc_autoneg;
  556. }
  557. static int
  558. be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  559. {
  560. struct be_adapter *adapter = netdev_priv(netdev);
  561. int status;
  562. if (ecmd->autoneg != adapter->phy.fc_autoneg)
  563. return -EINVAL;
  564. adapter->tx_fc = ecmd->tx_pause;
  565. adapter->rx_fc = ecmd->rx_pause;
  566. status = be_cmd_set_flow_control(adapter,
  567. adapter->tx_fc, adapter->rx_fc);
  568. if (status)
  569. dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
  570. return status;
  571. }
  572. static int
  573. be_set_phys_id(struct net_device *netdev,
  574. enum ethtool_phys_id_state state)
  575. {
  576. struct be_adapter *adapter = netdev_priv(netdev);
  577. switch (state) {
  578. case ETHTOOL_ID_ACTIVE:
  579. be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
  580. &adapter->beacon_state);
  581. return 1; /* cycle on/off once per second */
  582. case ETHTOOL_ID_ON:
  583. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  584. BEACON_STATE_ENABLED);
  585. break;
  586. case ETHTOOL_ID_OFF:
  587. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  588. BEACON_STATE_DISABLED);
  589. break;
  590. case ETHTOOL_ID_INACTIVE:
  591. be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
  592. adapter->beacon_state);
  593. }
  594. return 0;
  595. }
  596. static void
  597. be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  598. {
  599. struct be_adapter *adapter = netdev_priv(netdev);
  600. if (be_is_wol_supported(adapter)) {
  601. wol->supported |= WAKE_MAGIC;
  602. wol->wolopts |= WAKE_MAGIC;
  603. } else
  604. wol->wolopts = 0;
  605. memset(&wol->sopass, 0, sizeof(wol->sopass));
  606. }
  607. static int
  608. be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  609. {
  610. struct be_adapter *adapter = netdev_priv(netdev);
  611. if (wol->wolopts & ~WAKE_MAGIC)
  612. return -EOPNOTSUPP;
  613. if (!be_is_wol_supported(adapter)) {
  614. dev_warn(&adapter->pdev->dev, "WOL not supported\n");
  615. return -EOPNOTSUPP;
  616. }
  617. if (wol->wolopts & WAKE_MAGIC)
  618. adapter->wol = true;
  619. else
  620. adapter->wol = false;
  621. return 0;
  622. }
  623. static int
  624. be_test_ddr_dma(struct be_adapter *adapter)
  625. {
  626. int ret, i;
  627. struct be_dma_mem ddrdma_cmd;
  628. static const u64 pattern[2] = {
  629. 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
  630. };
  631. ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
  632. ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
  633. &ddrdma_cmd.dma, GFP_KERNEL);
  634. if (!ddrdma_cmd.va)
  635. return -ENOMEM;
  636. for (i = 0; i < 2; i++) {
  637. ret = be_cmd_ddr_dma_test(adapter, pattern[i],
  638. 4096, &ddrdma_cmd);
  639. if (ret != 0)
  640. goto err;
  641. }
  642. err:
  643. dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
  644. ddrdma_cmd.dma);
  645. return ret;
  646. }
  647. static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
  648. u64 *status)
  649. {
  650. be_cmd_set_loopback(adapter, adapter->hba_port_num,
  651. loopback_type, 1);
  652. *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
  653. loopback_type, 1500,
  654. 2, 0xabc);
  655. be_cmd_set_loopback(adapter, adapter->hba_port_num,
  656. BE_NO_LOOPBACK, 1);
  657. return *status;
  658. }
  659. static void
  660. be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
  661. {
  662. struct be_adapter *adapter = netdev_priv(netdev);
  663. int status;
  664. u8 link_status = 0;
  665. memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
  666. if (test->flags & ETH_TEST_FL_OFFLINE) {
  667. if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
  668. &data[0]) != 0) {
  669. test->flags |= ETH_TEST_FL_FAILED;
  670. }
  671. if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
  672. &data[1]) != 0) {
  673. test->flags |= ETH_TEST_FL_FAILED;
  674. }
  675. if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
  676. &data[2]) != 0) {
  677. test->flags |= ETH_TEST_FL_FAILED;
  678. }
  679. }
  680. if (!lancer_chip(adapter) && be_test_ddr_dma(adapter) != 0) {
  681. data[3] = 1;
  682. test->flags |= ETH_TEST_FL_FAILED;
  683. }
  684. status = be_cmd_link_status_query(adapter, NULL, &link_status, 0);
  685. if (status) {
  686. test->flags |= ETH_TEST_FL_FAILED;
  687. data[4] = -1;
  688. } else if (!link_status) {
  689. test->flags |= ETH_TEST_FL_FAILED;
  690. data[4] = 1;
  691. }
  692. }
  693. static int
  694. be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
  695. {
  696. struct be_adapter *adapter = netdev_priv(netdev);
  697. return be_load_fw(adapter, efl->data);
  698. }
  699. static int
  700. be_get_eeprom_len(struct net_device *netdev)
  701. {
  702. struct be_adapter *adapter = netdev_priv(netdev);
  703. if (!check_privilege(adapter, MAX_PRIVILEGES))
  704. return 0;
  705. if (lancer_chip(adapter)) {
  706. if (be_physfn(adapter))
  707. return lancer_cmd_get_file_len(adapter,
  708. LANCER_VPD_PF_FILE);
  709. else
  710. return lancer_cmd_get_file_len(adapter,
  711. LANCER_VPD_VF_FILE);
  712. } else {
  713. return BE_READ_SEEPROM_LEN;
  714. }
  715. }
  716. static int
  717. be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
  718. uint8_t *data)
  719. {
  720. struct be_adapter *adapter = netdev_priv(netdev);
  721. struct be_dma_mem eeprom_cmd;
  722. struct be_cmd_resp_seeprom_read *resp;
  723. int status;
  724. if (!eeprom->len)
  725. return -EINVAL;
  726. if (lancer_chip(adapter)) {
  727. if (be_physfn(adapter))
  728. return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE,
  729. eeprom->len, data);
  730. else
  731. return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE,
  732. eeprom->len, data);
  733. }
  734. eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
  735. memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
  736. eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
  737. eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
  738. &eeprom_cmd.dma, GFP_KERNEL);
  739. if (!eeprom_cmd.va)
  740. return -ENOMEM;
  741. status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
  742. if (!status) {
  743. resp = eeprom_cmd.va;
  744. memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
  745. }
  746. dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
  747. eeprom_cmd.dma);
  748. return status;
  749. }
  750. static u32 be_get_msg_level(struct net_device *netdev)
  751. {
  752. struct be_adapter *adapter = netdev_priv(netdev);
  753. if (lancer_chip(adapter)) {
  754. dev_err(&adapter->pdev->dev, "Operation not supported\n");
  755. return -EOPNOTSUPP;
  756. }
  757. return adapter->msg_enable;
  758. }
  759. static void be_set_fw_log_level(struct be_adapter *adapter, u32 level)
  760. {
  761. struct be_dma_mem extfat_cmd;
  762. struct be_fat_conf_params *cfgs;
  763. int status;
  764. int i, j;
  765. memset(&extfat_cmd, 0, sizeof(struct be_dma_mem));
  766. extfat_cmd.size = sizeof(struct be_cmd_resp_get_ext_fat_caps);
  767. extfat_cmd.va = pci_alloc_consistent(adapter->pdev, extfat_cmd.size,
  768. &extfat_cmd.dma);
  769. if (!extfat_cmd.va) {
  770. dev_err(&adapter->pdev->dev, "%s: Memory allocation failure\n",
  771. __func__);
  772. goto err;
  773. }
  774. status = be_cmd_get_ext_fat_capabilites(adapter, &extfat_cmd);
  775. if (!status) {
  776. cfgs = (struct be_fat_conf_params *)(extfat_cmd.va +
  777. sizeof(struct be_cmd_resp_hdr));
  778. for (i = 0; i < le32_to_cpu(cfgs->num_modules); i++) {
  779. u32 num_modes = le32_to_cpu(cfgs->module[i].num_modes);
  780. for (j = 0; j < num_modes; j++) {
  781. if (cfgs->module[i].trace_lvl[j].mode ==
  782. MODE_UART)
  783. cfgs->module[i].trace_lvl[j].dbg_lvl =
  784. cpu_to_le32(level);
  785. }
  786. }
  787. status = be_cmd_set_ext_fat_capabilites(adapter, &extfat_cmd,
  788. cfgs);
  789. if (status)
  790. dev_err(&adapter->pdev->dev,
  791. "Message level set failed\n");
  792. } else {
  793. dev_err(&adapter->pdev->dev, "Message level get failed\n");
  794. }
  795. pci_free_consistent(adapter->pdev, extfat_cmd.size, extfat_cmd.va,
  796. extfat_cmd.dma);
  797. err:
  798. return;
  799. }
  800. static void be_set_msg_level(struct net_device *netdev, u32 level)
  801. {
  802. struct be_adapter *adapter = netdev_priv(netdev);
  803. if (lancer_chip(adapter)) {
  804. dev_err(&adapter->pdev->dev, "Operation not supported\n");
  805. return;
  806. }
  807. if (adapter->msg_enable == level)
  808. return;
  809. if ((level & NETIF_MSG_HW) != (adapter->msg_enable & NETIF_MSG_HW))
  810. be_set_fw_log_level(adapter, level & NETIF_MSG_HW ?
  811. FW_LOG_LEVEL_DEFAULT : FW_LOG_LEVEL_FATAL);
  812. adapter->msg_enable = level;
  813. return;
  814. }
  815. static u64 be_get_rss_hash_opts(struct be_adapter *adapter, u64 flow_type)
  816. {
  817. u64 data = 0;
  818. switch (flow_type) {
  819. case TCP_V4_FLOW:
  820. if (adapter->rss_flags & RSS_ENABLE_IPV4)
  821. data |= RXH_IP_DST | RXH_IP_SRC;
  822. if (adapter->rss_flags & RSS_ENABLE_TCP_IPV4)
  823. data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  824. break;
  825. case UDP_V4_FLOW:
  826. if (adapter->rss_flags & RSS_ENABLE_IPV4)
  827. data |= RXH_IP_DST | RXH_IP_SRC;
  828. if (adapter->rss_flags & RSS_ENABLE_UDP_IPV4)
  829. data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  830. break;
  831. case TCP_V6_FLOW:
  832. if (adapter->rss_flags & RSS_ENABLE_IPV6)
  833. data |= RXH_IP_DST | RXH_IP_SRC;
  834. if (adapter->rss_flags & RSS_ENABLE_TCP_IPV6)
  835. data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  836. break;
  837. case UDP_V6_FLOW:
  838. if (adapter->rss_flags & RSS_ENABLE_IPV6)
  839. data |= RXH_IP_DST | RXH_IP_SRC;
  840. if (adapter->rss_flags & RSS_ENABLE_UDP_IPV6)
  841. data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  842. break;
  843. }
  844. return data;
  845. }
  846. static int be_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
  847. u32 *rule_locs)
  848. {
  849. struct be_adapter *adapter = netdev_priv(netdev);
  850. if (!be_multi_rxq(adapter)) {
  851. dev_info(&adapter->pdev->dev,
  852. "ethtool::get_rxnfc: RX flow hashing is disabled\n");
  853. return -EINVAL;
  854. }
  855. switch (cmd->cmd) {
  856. case ETHTOOL_GRXFH:
  857. cmd->data = be_get_rss_hash_opts(adapter, cmd->flow_type);
  858. break;
  859. case ETHTOOL_GRXRINGS:
  860. cmd->data = adapter->num_rx_qs - 1;
  861. break;
  862. default:
  863. return -EINVAL;
  864. }
  865. return 0;
  866. }
  867. static int be_set_rss_hash_opts(struct be_adapter *adapter,
  868. struct ethtool_rxnfc *cmd)
  869. {
  870. struct be_rx_obj *rxo;
  871. int status = 0, i, j;
  872. u8 rsstable[128];
  873. u32 rss_flags = adapter->rss_flags;
  874. if (cmd->data != L3_RSS_FLAGS &&
  875. cmd->data != (L3_RSS_FLAGS | L4_RSS_FLAGS))
  876. return -EINVAL;
  877. switch (cmd->flow_type) {
  878. case TCP_V4_FLOW:
  879. if (cmd->data == L3_RSS_FLAGS)
  880. rss_flags &= ~RSS_ENABLE_TCP_IPV4;
  881. else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
  882. rss_flags |= RSS_ENABLE_IPV4 |
  883. RSS_ENABLE_TCP_IPV4;
  884. break;
  885. case TCP_V6_FLOW:
  886. if (cmd->data == L3_RSS_FLAGS)
  887. rss_flags &= ~RSS_ENABLE_TCP_IPV6;
  888. else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
  889. rss_flags |= RSS_ENABLE_IPV6 |
  890. RSS_ENABLE_TCP_IPV6;
  891. break;
  892. case UDP_V4_FLOW:
  893. if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
  894. BEx_chip(adapter))
  895. return -EINVAL;
  896. if (cmd->data == L3_RSS_FLAGS)
  897. rss_flags &= ~RSS_ENABLE_UDP_IPV4;
  898. else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
  899. rss_flags |= RSS_ENABLE_IPV4 |
  900. RSS_ENABLE_UDP_IPV4;
  901. break;
  902. case UDP_V6_FLOW:
  903. if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
  904. BEx_chip(adapter))
  905. return -EINVAL;
  906. if (cmd->data == L3_RSS_FLAGS)
  907. rss_flags &= ~RSS_ENABLE_UDP_IPV6;
  908. else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
  909. rss_flags |= RSS_ENABLE_IPV6 |
  910. RSS_ENABLE_UDP_IPV6;
  911. break;
  912. default:
  913. return -EINVAL;
  914. }
  915. if (rss_flags == adapter->rss_flags)
  916. return status;
  917. if (be_multi_rxq(adapter)) {
  918. for (j = 0; j < 128; j += adapter->num_rx_qs - 1) {
  919. for_all_rss_queues(adapter, rxo, i) {
  920. if ((j + i) >= 128)
  921. break;
  922. rsstable[j + i] = rxo->rss_id;
  923. }
  924. }
  925. }
  926. status = be_cmd_rss_config(adapter, rsstable, rss_flags, 128);
  927. if (!status)
  928. adapter->rss_flags = rss_flags;
  929. return status;
  930. }
  931. static int be_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
  932. {
  933. struct be_adapter *adapter = netdev_priv(netdev);
  934. int status = 0;
  935. if (!be_multi_rxq(adapter)) {
  936. dev_err(&adapter->pdev->dev,
  937. "ethtool::set_rxnfc: RX flow hashing is disabled\n");
  938. return -EINVAL;
  939. }
  940. switch (cmd->cmd) {
  941. case ETHTOOL_SRXFH:
  942. status = be_set_rss_hash_opts(adapter, cmd);
  943. break;
  944. default:
  945. return -EINVAL;
  946. }
  947. return status;
  948. }
  949. const struct ethtool_ops be_ethtool_ops = {
  950. .get_settings = be_get_settings,
  951. .get_drvinfo = be_get_drvinfo,
  952. .get_wol = be_get_wol,
  953. .set_wol = be_set_wol,
  954. .get_link = ethtool_op_get_link,
  955. .get_eeprom_len = be_get_eeprom_len,
  956. .get_eeprom = be_read_eeprom,
  957. .get_coalesce = be_get_coalesce,
  958. .set_coalesce = be_set_coalesce,
  959. .get_ringparam = be_get_ringparam,
  960. .get_pauseparam = be_get_pauseparam,
  961. .set_pauseparam = be_set_pauseparam,
  962. .get_strings = be_get_stat_strings,
  963. .set_phys_id = be_set_phys_id,
  964. .get_msglevel = be_get_msg_level,
  965. .set_msglevel = be_set_msg_level,
  966. .get_sset_count = be_get_sset_count,
  967. .get_ethtool_stats = be_get_ethtool_stats,
  968. .get_regs_len = be_get_reg_len,
  969. .get_regs = be_get_regs,
  970. .flash_device = be_do_flash,
  971. .self_test = be_self_test,
  972. .get_rxnfc = be_get_rxnfc,
  973. .set_rxnfc = be_set_rxnfc,
  974. };