be_ethtool.c 29 KB

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