PageRenderTime 59ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/net/bnx2x/bnx2x_ethtool.c

https://bitbucket.org/slukk/jb-tsm-kernel-4.2
C | 2139 lines | 1676 code | 349 blank | 114 comment | 333 complexity | 85bf832b1a4ff9cb467fb3c5ae683577 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /* bnx2x_ethtool.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2011 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  10. * Written by: Eliezer Tamir
  11. * Based on code from Michael Chan's bnx2 driver
  12. * UDP CSUM errata workaround by Arik Gendelman
  13. * Slowpath and fastpath rework by Vladislav Zolotarov
  14. * Statistics and Link management by Yitchak Gertner
  15. *
  16. */
  17. #include <linux/ethtool.h>
  18. #include <linux/netdevice.h>
  19. #include <linux/types.h>
  20. #include <linux/sched.h>
  21. #include <linux/crc32.h>
  22. #include "bnx2x.h"
  23. #include "bnx2x_cmn.h"
  24. #include "bnx2x_dump.h"
  25. #include "bnx2x_init.h"
  26. /* Note: in the format strings below %s is replaced by the queue-name which is
  27. * either its index or 'fcoe' for the fcoe queue. Make sure the format string
  28. * length does not exceed ETH_GSTRING_LEN - MAX_QUEUE_NAME_LEN + 2
  29. */
  30. #define MAX_QUEUE_NAME_LEN 4
  31. static const struct {
  32. long offset;
  33. int size;
  34. char string[ETH_GSTRING_LEN];
  35. } bnx2x_q_stats_arr[] = {
  36. /* 1 */ { Q_STATS_OFFSET32(total_bytes_received_hi), 8, "[%s]: rx_bytes" },
  37. { Q_STATS_OFFSET32(error_bytes_received_hi),
  38. 8, "[%s]: rx_error_bytes" },
  39. { Q_STATS_OFFSET32(total_unicast_packets_received_hi),
  40. 8, "[%s]: rx_ucast_packets" },
  41. { Q_STATS_OFFSET32(total_multicast_packets_received_hi),
  42. 8, "[%s]: rx_mcast_packets" },
  43. { Q_STATS_OFFSET32(total_broadcast_packets_received_hi),
  44. 8, "[%s]: rx_bcast_packets" },
  45. { Q_STATS_OFFSET32(no_buff_discard_hi), 8, "[%s]: rx_discards" },
  46. { Q_STATS_OFFSET32(rx_err_discard_pkt),
  47. 4, "[%s]: rx_phy_ip_err_discards"},
  48. { Q_STATS_OFFSET32(rx_skb_alloc_failed),
  49. 4, "[%s]: rx_skb_alloc_discard" },
  50. { Q_STATS_OFFSET32(hw_csum_err), 4, "[%s]: rx_csum_offload_errors" },
  51. /* 10 */{ Q_STATS_OFFSET32(total_bytes_transmitted_hi), 8, "[%s]: tx_bytes" },
  52. { Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi),
  53. 8, "[%s]: tx_ucast_packets" },
  54. { Q_STATS_OFFSET32(total_multicast_packets_transmitted_hi),
  55. 8, "[%s]: tx_mcast_packets" },
  56. { Q_STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
  57. 8, "[%s]: tx_bcast_packets" }
  58. };
  59. #define BNX2X_NUM_Q_STATS ARRAY_SIZE(bnx2x_q_stats_arr)
  60. static const struct {
  61. long offset;
  62. int size;
  63. u32 flags;
  64. #define STATS_FLAGS_PORT 1
  65. #define STATS_FLAGS_FUNC 2
  66. #define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT)
  67. char string[ETH_GSTRING_LEN];
  68. } bnx2x_stats_arr[] = {
  69. /* 1 */ { STATS_OFFSET32(total_bytes_received_hi),
  70. 8, STATS_FLAGS_BOTH, "rx_bytes" },
  71. { STATS_OFFSET32(error_bytes_received_hi),
  72. 8, STATS_FLAGS_BOTH, "rx_error_bytes" },
  73. { STATS_OFFSET32(total_unicast_packets_received_hi),
  74. 8, STATS_FLAGS_BOTH, "rx_ucast_packets" },
  75. { STATS_OFFSET32(total_multicast_packets_received_hi),
  76. 8, STATS_FLAGS_BOTH, "rx_mcast_packets" },
  77. { STATS_OFFSET32(total_broadcast_packets_received_hi),
  78. 8, STATS_FLAGS_BOTH, "rx_bcast_packets" },
  79. { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi),
  80. 8, STATS_FLAGS_PORT, "rx_crc_errors" },
  81. { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi),
  82. 8, STATS_FLAGS_PORT, "rx_align_errors" },
  83. { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi),
  84. 8, STATS_FLAGS_PORT, "rx_undersize_packets" },
  85. { STATS_OFFSET32(etherstatsoverrsizepkts_hi),
  86. 8, STATS_FLAGS_PORT, "rx_oversize_packets" },
  87. /* 10 */{ STATS_OFFSET32(rx_stat_etherstatsfragments_hi),
  88. 8, STATS_FLAGS_PORT, "rx_fragments" },
  89. { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi),
  90. 8, STATS_FLAGS_PORT, "rx_jabbers" },
  91. { STATS_OFFSET32(no_buff_discard_hi),
  92. 8, STATS_FLAGS_BOTH, "rx_discards" },
  93. { STATS_OFFSET32(mac_filter_discard),
  94. 4, STATS_FLAGS_PORT, "rx_filtered_packets" },
  95. { STATS_OFFSET32(xxoverflow_discard),
  96. 4, STATS_FLAGS_PORT, "rx_fw_discards" },
  97. { STATS_OFFSET32(brb_drop_hi),
  98. 8, STATS_FLAGS_PORT, "rx_brb_discard" },
  99. { STATS_OFFSET32(brb_truncate_hi),
  100. 8, STATS_FLAGS_PORT, "rx_brb_truncate" },
  101. { STATS_OFFSET32(pause_frames_received_hi),
  102. 8, STATS_FLAGS_PORT, "rx_pause_frames" },
  103. { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi),
  104. 8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" },
  105. { STATS_OFFSET32(nig_timer_max),
  106. 4, STATS_FLAGS_PORT, "rx_constant_pause_events" },
  107. /* 20 */{ STATS_OFFSET32(rx_err_discard_pkt),
  108. 4, STATS_FLAGS_BOTH, "rx_phy_ip_err_discards"},
  109. { STATS_OFFSET32(rx_skb_alloc_failed),
  110. 4, STATS_FLAGS_BOTH, "rx_skb_alloc_discard" },
  111. { STATS_OFFSET32(hw_csum_err),
  112. 4, STATS_FLAGS_BOTH, "rx_csum_offload_errors" },
  113. { STATS_OFFSET32(total_bytes_transmitted_hi),
  114. 8, STATS_FLAGS_BOTH, "tx_bytes" },
  115. { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi),
  116. 8, STATS_FLAGS_PORT, "tx_error_bytes" },
  117. { STATS_OFFSET32(total_unicast_packets_transmitted_hi),
  118. 8, STATS_FLAGS_BOTH, "tx_ucast_packets" },
  119. { STATS_OFFSET32(total_multicast_packets_transmitted_hi),
  120. 8, STATS_FLAGS_BOTH, "tx_mcast_packets" },
  121. { STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
  122. 8, STATS_FLAGS_BOTH, "tx_bcast_packets" },
  123. { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi),
  124. 8, STATS_FLAGS_PORT, "tx_mac_errors" },
  125. { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi),
  126. 8, STATS_FLAGS_PORT, "tx_carrier_errors" },
  127. /* 30 */{ STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi),
  128. 8, STATS_FLAGS_PORT, "tx_single_collisions" },
  129. { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi),
  130. 8, STATS_FLAGS_PORT, "tx_multi_collisions" },
  131. { STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi),
  132. 8, STATS_FLAGS_PORT, "tx_deferred" },
  133. { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi),
  134. 8, STATS_FLAGS_PORT, "tx_excess_collisions" },
  135. { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi),
  136. 8, STATS_FLAGS_PORT, "tx_late_collisions" },
  137. { STATS_OFFSET32(tx_stat_etherstatscollisions_hi),
  138. 8, STATS_FLAGS_PORT, "tx_total_collisions" },
  139. { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi),
  140. 8, STATS_FLAGS_PORT, "tx_64_byte_packets" },
  141. { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi),
  142. 8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" },
  143. { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi),
  144. 8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" },
  145. { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi),
  146. 8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" },
  147. /* 40 */{ STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi),
  148. 8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" },
  149. { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi),
  150. 8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" },
  151. { STATS_OFFSET32(etherstatspktsover1522octets_hi),
  152. 8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" },
  153. { STATS_OFFSET32(pause_frames_sent_hi),
  154. 8, STATS_FLAGS_PORT, "tx_pause_frames" }
  155. };
  156. #define BNX2X_NUM_STATS ARRAY_SIZE(bnx2x_stats_arr)
  157. static int bnx2x_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  158. {
  159. struct bnx2x *bp = netdev_priv(dev);
  160. int cfg_idx = bnx2x_get_link_cfg_idx(bp);
  161. /* Dual Media boards present all available port types */
  162. cmd->supported = bp->port.supported[cfg_idx] |
  163. (bp->port.supported[cfg_idx ^ 1] &
  164. (SUPPORTED_TP | SUPPORTED_FIBRE));
  165. cmd->advertising = bp->port.advertising[cfg_idx];
  166. if ((bp->state == BNX2X_STATE_OPEN) &&
  167. !(bp->flags & MF_FUNC_DIS) &&
  168. (bp->link_vars.link_up)) {
  169. ethtool_cmd_speed_set(cmd, bp->link_vars.line_speed);
  170. cmd->duplex = bp->link_vars.duplex;
  171. } else {
  172. ethtool_cmd_speed_set(
  173. cmd, bp->link_params.req_line_speed[cfg_idx]);
  174. cmd->duplex = bp->link_params.req_duplex[cfg_idx];
  175. }
  176. if (IS_MF(bp))
  177. ethtool_cmd_speed_set(cmd, bnx2x_get_mf_speed(bp));
  178. if (bp->port.supported[cfg_idx] & SUPPORTED_TP)
  179. cmd->port = PORT_TP;
  180. else if (bp->port.supported[cfg_idx] & SUPPORTED_FIBRE)
  181. cmd->port = PORT_FIBRE;
  182. else
  183. BNX2X_ERR("XGXS PHY Failure detected\n");
  184. cmd->phy_address = bp->mdio.prtad;
  185. cmd->transceiver = XCVR_INTERNAL;
  186. if (bp->link_params.req_line_speed[cfg_idx] == SPEED_AUTO_NEG)
  187. cmd->autoneg = AUTONEG_ENABLE;
  188. else
  189. cmd->autoneg = AUTONEG_DISABLE;
  190. cmd->maxtxpkt = 0;
  191. cmd->maxrxpkt = 0;
  192. DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n"
  193. DP_LEVEL " supported 0x%x advertising 0x%x speed %u\n"
  194. DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n"
  195. DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n",
  196. cmd->cmd, cmd->supported, cmd->advertising,
  197. ethtool_cmd_speed(cmd),
  198. cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
  199. cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
  200. return 0;
  201. }
  202. static int bnx2x_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  203. {
  204. struct bnx2x *bp = netdev_priv(dev);
  205. u32 advertising, cfg_idx, old_multi_phy_config, new_multi_phy_config;
  206. u32 speed;
  207. if (IS_MF_SD(bp))
  208. return 0;
  209. DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n"
  210. " supported 0x%x advertising 0x%x speed %u\n"
  211. " duplex %d port %d phy_address %d transceiver %d\n"
  212. " autoneg %d maxtxpkt %d maxrxpkt %d\n",
  213. cmd->cmd, cmd->supported, cmd->advertising,
  214. ethtool_cmd_speed(cmd),
  215. cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
  216. cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
  217. speed = ethtool_cmd_speed(cmd);
  218. if (IS_MF_SI(bp)) {
  219. u32 part;
  220. u32 line_speed = bp->link_vars.line_speed;
  221. /* use 10G if no link detected */
  222. if (!line_speed)
  223. line_speed = 10000;
  224. if (bp->common.bc_ver < REQ_BC_VER_4_SET_MF_BW) {
  225. BNX2X_DEV_INFO("To set speed BC %X or higher "
  226. "is required, please upgrade BC\n",
  227. REQ_BC_VER_4_SET_MF_BW);
  228. return -EINVAL;
  229. }
  230. part = (speed * 100) / line_speed;
  231. if (line_speed < speed || !part) {
  232. BNX2X_DEV_INFO("Speed setting should be in a range "
  233. "from 1%% to 100%% "
  234. "of actual line speed\n");
  235. return -EINVAL;
  236. }
  237. if (bp->state != BNX2X_STATE_OPEN)
  238. /* store value for following "load" */
  239. bp->pending_max = part;
  240. else
  241. bnx2x_update_max_mf_config(bp, part);
  242. return 0;
  243. }
  244. cfg_idx = bnx2x_get_link_cfg_idx(bp);
  245. old_multi_phy_config = bp->link_params.multi_phy_config;
  246. switch (cmd->port) {
  247. case PORT_TP:
  248. if (bp->port.supported[cfg_idx] & SUPPORTED_TP)
  249. break; /* no port change */
  250. if (!(bp->port.supported[0] & SUPPORTED_TP ||
  251. bp->port.supported[1] & SUPPORTED_TP)) {
  252. DP(NETIF_MSG_LINK, "Unsupported port type\n");
  253. return -EINVAL;
  254. }
  255. bp->link_params.multi_phy_config &=
  256. ~PORT_HW_CFG_PHY_SELECTION_MASK;
  257. if (bp->link_params.multi_phy_config &
  258. PORT_HW_CFG_PHY_SWAPPED_ENABLED)
  259. bp->link_params.multi_phy_config |=
  260. PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
  261. else
  262. bp->link_params.multi_phy_config |=
  263. PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
  264. break;
  265. case PORT_FIBRE:
  266. if (bp->port.supported[cfg_idx] & SUPPORTED_FIBRE)
  267. break; /* no port change */
  268. if (!(bp->port.supported[0] & SUPPORTED_FIBRE ||
  269. bp->port.supported[1] & SUPPORTED_FIBRE)) {
  270. DP(NETIF_MSG_LINK, "Unsupported port type\n");
  271. return -EINVAL;
  272. }
  273. bp->link_params.multi_phy_config &=
  274. ~PORT_HW_CFG_PHY_SELECTION_MASK;
  275. if (bp->link_params.multi_phy_config &
  276. PORT_HW_CFG_PHY_SWAPPED_ENABLED)
  277. bp->link_params.multi_phy_config |=
  278. PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
  279. else
  280. bp->link_params.multi_phy_config |=
  281. PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
  282. break;
  283. default:
  284. DP(NETIF_MSG_LINK, "Unsupported port type\n");
  285. return -EINVAL;
  286. }
  287. /* Save new config in case command complete successuly */
  288. new_multi_phy_config = bp->link_params.multi_phy_config;
  289. /* Get the new cfg_idx */
  290. cfg_idx = bnx2x_get_link_cfg_idx(bp);
  291. /* Restore old config in case command failed */
  292. bp->link_params.multi_phy_config = old_multi_phy_config;
  293. DP(NETIF_MSG_LINK, "cfg_idx = %x\n", cfg_idx);
  294. if (cmd->autoneg == AUTONEG_ENABLE) {
  295. if (!(bp->port.supported[cfg_idx] & SUPPORTED_Autoneg)) {
  296. DP(NETIF_MSG_LINK, "Autoneg not supported\n");
  297. return -EINVAL;
  298. }
  299. /* advertise the requested speed and duplex if supported */
  300. cmd->advertising &= bp->port.supported[cfg_idx];
  301. bp->link_params.req_line_speed[cfg_idx] = SPEED_AUTO_NEG;
  302. bp->link_params.req_duplex[cfg_idx] = DUPLEX_FULL;
  303. bp->port.advertising[cfg_idx] |= (ADVERTISED_Autoneg |
  304. cmd->advertising);
  305. } else { /* forced speed */
  306. /* advertise the requested speed and duplex if supported */
  307. switch (speed) {
  308. case SPEED_10:
  309. if (cmd->duplex == DUPLEX_FULL) {
  310. if (!(bp->port.supported[cfg_idx] &
  311. SUPPORTED_10baseT_Full)) {
  312. DP(NETIF_MSG_LINK,
  313. "10M full not supported\n");
  314. return -EINVAL;
  315. }
  316. advertising = (ADVERTISED_10baseT_Full |
  317. ADVERTISED_TP);
  318. } else {
  319. if (!(bp->port.supported[cfg_idx] &
  320. SUPPORTED_10baseT_Half)) {
  321. DP(NETIF_MSG_LINK,
  322. "10M half not supported\n");
  323. return -EINVAL;
  324. }
  325. advertising = (ADVERTISED_10baseT_Half |
  326. ADVERTISED_TP);
  327. }
  328. break;
  329. case SPEED_100:
  330. if (cmd->duplex == DUPLEX_FULL) {
  331. if (!(bp->port.supported[cfg_idx] &
  332. SUPPORTED_100baseT_Full)) {
  333. DP(NETIF_MSG_LINK,
  334. "100M full not supported\n");
  335. return -EINVAL;
  336. }
  337. advertising = (ADVERTISED_100baseT_Full |
  338. ADVERTISED_TP);
  339. } else {
  340. if (!(bp->port.supported[cfg_idx] &
  341. SUPPORTED_100baseT_Half)) {
  342. DP(NETIF_MSG_LINK,
  343. "100M half not supported\n");
  344. return -EINVAL;
  345. }
  346. advertising = (ADVERTISED_100baseT_Half |
  347. ADVERTISED_TP);
  348. }
  349. break;
  350. case SPEED_1000:
  351. if (cmd->duplex != DUPLEX_FULL) {
  352. DP(NETIF_MSG_LINK, "1G half not supported\n");
  353. return -EINVAL;
  354. }
  355. if (!(bp->port.supported[cfg_idx] &
  356. SUPPORTED_1000baseT_Full)) {
  357. DP(NETIF_MSG_LINK, "1G full not supported\n");
  358. return -EINVAL;
  359. }
  360. advertising = (ADVERTISED_1000baseT_Full |
  361. ADVERTISED_TP);
  362. break;
  363. case SPEED_2500:
  364. if (cmd->duplex != DUPLEX_FULL) {
  365. DP(NETIF_MSG_LINK,
  366. "2.5G half not supported\n");
  367. return -EINVAL;
  368. }
  369. if (!(bp->port.supported[cfg_idx]
  370. & SUPPORTED_2500baseX_Full)) {
  371. DP(NETIF_MSG_LINK,
  372. "2.5G full not supported\n");
  373. return -EINVAL;
  374. }
  375. advertising = (ADVERTISED_2500baseX_Full |
  376. ADVERTISED_TP);
  377. break;
  378. case SPEED_10000:
  379. if (cmd->duplex != DUPLEX_FULL) {
  380. DP(NETIF_MSG_LINK, "10G half not supported\n");
  381. return -EINVAL;
  382. }
  383. if (!(bp->port.supported[cfg_idx]
  384. & SUPPORTED_10000baseT_Full)) {
  385. DP(NETIF_MSG_LINK, "10G full not supported\n");
  386. return -EINVAL;
  387. }
  388. advertising = (ADVERTISED_10000baseT_Full |
  389. ADVERTISED_FIBRE);
  390. break;
  391. default:
  392. DP(NETIF_MSG_LINK, "Unsupported speed %u\n", speed);
  393. return -EINVAL;
  394. }
  395. bp->link_params.req_line_speed[cfg_idx] = speed;
  396. bp->link_params.req_duplex[cfg_idx] = cmd->duplex;
  397. bp->port.advertising[cfg_idx] = advertising;
  398. }
  399. DP(NETIF_MSG_LINK, "req_line_speed %d\n"
  400. DP_LEVEL " req_duplex %d advertising 0x%x\n",
  401. bp->link_params.req_line_speed[cfg_idx],
  402. bp->link_params.req_duplex[cfg_idx],
  403. bp->port.advertising[cfg_idx]);
  404. /* Set new config */
  405. bp->link_params.multi_phy_config = new_multi_phy_config;
  406. if (netif_running(dev)) {
  407. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  408. bnx2x_link_set(bp);
  409. }
  410. return 0;
  411. }
  412. #define IS_E1_ONLINE(info) (((info) & RI_E1_ONLINE) == RI_E1_ONLINE)
  413. #define IS_E1H_ONLINE(info) (((info) & RI_E1H_ONLINE) == RI_E1H_ONLINE)
  414. #define IS_E2_ONLINE(info) (((info) & RI_E2_ONLINE) == RI_E2_ONLINE)
  415. static int bnx2x_get_regs_len(struct net_device *dev)
  416. {
  417. struct bnx2x *bp = netdev_priv(dev);
  418. int regdump_len = 0;
  419. int i, j, k;
  420. if (CHIP_IS_E1(bp)) {
  421. for (i = 0; i < REGS_COUNT; i++)
  422. if (IS_E1_ONLINE(reg_addrs[i].info))
  423. regdump_len += reg_addrs[i].size;
  424. for (i = 0; i < WREGS_COUNT_E1; i++)
  425. if (IS_E1_ONLINE(wreg_addrs_e1[i].info))
  426. regdump_len += wreg_addrs_e1[i].size *
  427. (1 + wreg_addrs_e1[i].read_regs_count);
  428. } else if (CHIP_IS_E1H(bp)) {
  429. for (i = 0; i < REGS_COUNT; i++)
  430. if (IS_E1H_ONLINE(reg_addrs[i].info))
  431. regdump_len += reg_addrs[i].size;
  432. for (i = 0; i < WREGS_COUNT_E1H; i++)
  433. if (IS_E1H_ONLINE(wreg_addrs_e1h[i].info))
  434. regdump_len += wreg_addrs_e1h[i].size *
  435. (1 + wreg_addrs_e1h[i].read_regs_count);
  436. } else if (CHIP_IS_E2(bp)) {
  437. for (i = 0; i < REGS_COUNT; i++)
  438. if (IS_E2_ONLINE(reg_addrs[i].info))
  439. regdump_len += reg_addrs[i].size;
  440. for (i = 0; i < WREGS_COUNT_E2; i++)
  441. if (IS_E2_ONLINE(wreg_addrs_e2[i].info))
  442. regdump_len += wreg_addrs_e2[i].size *
  443. (1 + wreg_addrs_e2[i].read_regs_count);
  444. for (i = 0; i < PAGE_MODE_VALUES_E2; i++)
  445. for (j = 0; j < PAGE_WRITE_REGS_E2; j++) {
  446. for (k = 0; k < PAGE_READ_REGS_E2; k++)
  447. if (IS_E2_ONLINE(page_read_regs_e2[k].
  448. info))
  449. regdump_len +=
  450. page_read_regs_e2[k].size;
  451. }
  452. }
  453. regdump_len *= 4;
  454. regdump_len += sizeof(struct dump_hdr);
  455. return regdump_len;
  456. }
  457. static inline void bnx2x_read_pages_regs_e2(struct bnx2x *bp, u32 *p)
  458. {
  459. u32 i, j, k, n;
  460. for (i = 0; i < PAGE_MODE_VALUES_E2; i++) {
  461. for (j = 0; j < PAGE_WRITE_REGS_E2; j++) {
  462. REG_WR(bp, page_write_regs_e2[j], page_vals_e2[i]);
  463. for (k = 0; k < PAGE_READ_REGS_E2; k++)
  464. if (IS_E2_ONLINE(page_read_regs_e2[k].info))
  465. for (n = 0; n <
  466. page_read_regs_e2[k].size; n++)
  467. *p++ = REG_RD(bp,
  468. page_read_regs_e2[k].addr + n*4);
  469. }
  470. }
  471. }
  472. static void bnx2x_get_regs(struct net_device *dev,
  473. struct ethtool_regs *regs, void *_p)
  474. {
  475. u32 *p = _p, i, j;
  476. struct bnx2x *bp = netdev_priv(dev);
  477. struct dump_hdr dump_hdr = {0};
  478. regs->version = 0;
  479. memset(p, 0, regs->len);
  480. if (!netif_running(bp->dev))
  481. return;
  482. /* Disable parity attentions as long as following dump may
  483. * cause false alarms by reading never written registers. We
  484. * will re-enable parity attentions right after the dump.
  485. */
  486. bnx2x_disable_blocks_parity(bp);
  487. dump_hdr.hdr_size = (sizeof(struct dump_hdr) / 4) - 1;
  488. dump_hdr.dump_sign = dump_sign_all;
  489. dump_hdr.xstorm_waitp = REG_RD(bp, XSTORM_WAITP_ADDR);
  490. dump_hdr.tstorm_waitp = REG_RD(bp, TSTORM_WAITP_ADDR);
  491. dump_hdr.ustorm_waitp = REG_RD(bp, USTORM_WAITP_ADDR);
  492. dump_hdr.cstorm_waitp = REG_RD(bp, CSTORM_WAITP_ADDR);
  493. if (CHIP_IS_E1(bp))
  494. dump_hdr.info = RI_E1_ONLINE;
  495. else if (CHIP_IS_E1H(bp))
  496. dump_hdr.info = RI_E1H_ONLINE;
  497. else if (CHIP_IS_E2(bp))
  498. dump_hdr.info = RI_E2_ONLINE |
  499. (BP_PATH(bp) ? RI_PATH1_DUMP : RI_PATH0_DUMP);
  500. memcpy(p, &dump_hdr, sizeof(struct dump_hdr));
  501. p += dump_hdr.hdr_size + 1;
  502. if (CHIP_IS_E1(bp)) {
  503. for (i = 0; i < REGS_COUNT; i++)
  504. if (IS_E1_ONLINE(reg_addrs[i].info))
  505. for (j = 0; j < reg_addrs[i].size; j++)
  506. *p++ = REG_RD(bp,
  507. reg_addrs[i].addr + j*4);
  508. } else if (CHIP_IS_E1H(bp)) {
  509. for (i = 0; i < REGS_COUNT; i++)
  510. if (IS_E1H_ONLINE(reg_addrs[i].info))
  511. for (j = 0; j < reg_addrs[i].size; j++)
  512. *p++ = REG_RD(bp,
  513. reg_addrs[i].addr + j*4);
  514. } else if (CHIP_IS_E2(bp)) {
  515. for (i = 0; i < REGS_COUNT; i++)
  516. if (IS_E2_ONLINE(reg_addrs[i].info))
  517. for (j = 0; j < reg_addrs[i].size; j++)
  518. *p++ = REG_RD(bp,
  519. reg_addrs[i].addr + j*4);
  520. bnx2x_read_pages_regs_e2(bp, p);
  521. }
  522. /* Re-enable parity attentions */
  523. bnx2x_clear_blocks_parity(bp);
  524. if (CHIP_PARITY_ENABLED(bp))
  525. bnx2x_enable_blocks_parity(bp);
  526. }
  527. #define PHY_FW_VER_LEN 20
  528. static void bnx2x_get_drvinfo(struct net_device *dev,
  529. struct ethtool_drvinfo *info)
  530. {
  531. struct bnx2x *bp = netdev_priv(dev);
  532. u8 phy_fw_ver[PHY_FW_VER_LEN];
  533. strcpy(info->driver, DRV_MODULE_NAME);
  534. strcpy(info->version, DRV_MODULE_VERSION);
  535. phy_fw_ver[0] = '\0';
  536. if (bp->port.pmf) {
  537. bnx2x_acquire_phy_lock(bp);
  538. bnx2x_get_ext_phy_fw_version(&bp->link_params,
  539. (bp->state != BNX2X_STATE_CLOSED),
  540. phy_fw_ver, PHY_FW_VER_LEN);
  541. bnx2x_release_phy_lock(bp);
  542. }
  543. strncpy(info->fw_version, bp->fw_ver, 32);
  544. snprintf(info->fw_version + strlen(bp->fw_ver), 32 - strlen(bp->fw_ver),
  545. "bc %d.%d.%d%s%s",
  546. (bp->common.bc_ver & 0xff0000) >> 16,
  547. (bp->common.bc_ver & 0xff00) >> 8,
  548. (bp->common.bc_ver & 0xff),
  549. ((phy_fw_ver[0] != '\0') ? " phy " : ""), phy_fw_ver);
  550. strcpy(info->bus_info, pci_name(bp->pdev));
  551. info->n_stats = BNX2X_NUM_STATS;
  552. info->testinfo_len = BNX2X_NUM_TESTS;
  553. info->eedump_len = bp->common.flash_size;
  554. info->regdump_len = bnx2x_get_regs_len(dev);
  555. }
  556. static void bnx2x_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  557. {
  558. struct bnx2x *bp = netdev_priv(dev);
  559. if (bp->flags & NO_WOL_FLAG) {
  560. wol->supported = 0;
  561. wol->wolopts = 0;
  562. } else {
  563. wol->supported = WAKE_MAGIC;
  564. if (bp->wol)
  565. wol->wolopts = WAKE_MAGIC;
  566. else
  567. wol->wolopts = 0;
  568. }
  569. memset(&wol->sopass, 0, sizeof(wol->sopass));
  570. }
  571. static int bnx2x_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  572. {
  573. struct bnx2x *bp = netdev_priv(dev);
  574. if (wol->wolopts & ~WAKE_MAGIC)
  575. return -EINVAL;
  576. if (wol->wolopts & WAKE_MAGIC) {
  577. if (bp->flags & NO_WOL_FLAG)
  578. return -EINVAL;
  579. bp->wol = 1;
  580. } else
  581. bp->wol = 0;
  582. return 0;
  583. }
  584. static u32 bnx2x_get_msglevel(struct net_device *dev)
  585. {
  586. struct bnx2x *bp = netdev_priv(dev);
  587. return bp->msg_enable;
  588. }
  589. static void bnx2x_set_msglevel(struct net_device *dev, u32 level)
  590. {
  591. struct bnx2x *bp = netdev_priv(dev);
  592. if (capable(CAP_NET_ADMIN))
  593. bp->msg_enable = level;
  594. }
  595. static int bnx2x_nway_reset(struct net_device *dev)
  596. {
  597. struct bnx2x *bp = netdev_priv(dev);
  598. if (!bp->port.pmf)
  599. return 0;
  600. if (netif_running(dev)) {
  601. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  602. bnx2x_link_set(bp);
  603. }
  604. return 0;
  605. }
  606. static u32 bnx2x_get_link(struct net_device *dev)
  607. {
  608. struct bnx2x *bp = netdev_priv(dev);
  609. if (bp->flags & MF_FUNC_DIS || (bp->state != BNX2X_STATE_OPEN))
  610. return 0;
  611. return bp->link_vars.link_up;
  612. }
  613. static int bnx2x_get_eeprom_len(struct net_device *dev)
  614. {
  615. struct bnx2x *bp = netdev_priv(dev);
  616. return bp->common.flash_size;
  617. }
  618. static int bnx2x_acquire_nvram_lock(struct bnx2x *bp)
  619. {
  620. int port = BP_PORT(bp);
  621. int count, i;
  622. u32 val = 0;
  623. /* adjust timeout for emulation/FPGA */
  624. count = NVRAM_TIMEOUT_COUNT;
  625. if (CHIP_REV_IS_SLOW(bp))
  626. count *= 100;
  627. /* request access to nvram interface */
  628. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  629. (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port));
  630. for (i = 0; i < count*10; i++) {
  631. val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
  632. if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))
  633. break;
  634. udelay(5);
  635. }
  636. if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
  637. DP(BNX2X_MSG_NVM, "cannot get access to nvram interface\n");
  638. return -EBUSY;
  639. }
  640. return 0;
  641. }
  642. static int bnx2x_release_nvram_lock(struct bnx2x *bp)
  643. {
  644. int port = BP_PORT(bp);
  645. int count, i;
  646. u32 val = 0;
  647. /* adjust timeout for emulation/FPGA */
  648. count = NVRAM_TIMEOUT_COUNT;
  649. if (CHIP_REV_IS_SLOW(bp))
  650. count *= 100;
  651. /* relinquish nvram interface */
  652. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  653. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port));
  654. for (i = 0; i < count*10; i++) {
  655. val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
  656. if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)))
  657. break;
  658. udelay(5);
  659. }
  660. if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
  661. DP(BNX2X_MSG_NVM, "cannot free access to nvram interface\n");
  662. return -EBUSY;
  663. }
  664. return 0;
  665. }
  666. static void bnx2x_enable_nvram_access(struct bnx2x *bp)
  667. {
  668. u32 val;
  669. val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
  670. /* enable both bits, even on read */
  671. REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
  672. (val | MCPR_NVM_ACCESS_ENABLE_EN |
  673. MCPR_NVM_ACCESS_ENABLE_WR_EN));
  674. }
  675. static void bnx2x_disable_nvram_access(struct bnx2x *bp)
  676. {
  677. u32 val;
  678. val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
  679. /* disable both bits, even after read */
  680. REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
  681. (val & ~(MCPR_NVM_ACCESS_ENABLE_EN |
  682. MCPR_NVM_ACCESS_ENABLE_WR_EN)));
  683. }
  684. static int bnx2x_nvram_read_dword(struct bnx2x *bp, u32 offset, __be32 *ret_val,
  685. u32 cmd_flags)
  686. {
  687. int count, i, rc;
  688. u32 val;
  689. /* build the command word */
  690. cmd_flags |= MCPR_NVM_COMMAND_DOIT;
  691. /* need to clear DONE bit separately */
  692. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
  693. /* address of the NVRAM to read from */
  694. REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
  695. (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
  696. /* issue a read command */
  697. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
  698. /* adjust timeout for emulation/FPGA */
  699. count = NVRAM_TIMEOUT_COUNT;
  700. if (CHIP_REV_IS_SLOW(bp))
  701. count *= 100;
  702. /* wait for completion */
  703. *ret_val = 0;
  704. rc = -EBUSY;
  705. for (i = 0; i < count; i++) {
  706. udelay(5);
  707. val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
  708. if (val & MCPR_NVM_COMMAND_DONE) {
  709. val = REG_RD(bp, MCP_REG_MCPR_NVM_READ);
  710. /* we read nvram data in cpu order
  711. * but ethtool sees it as an array of bytes
  712. * converting to big-endian will do the work */
  713. *ret_val = cpu_to_be32(val);
  714. rc = 0;
  715. break;
  716. }
  717. }
  718. return rc;
  719. }
  720. static int bnx2x_nvram_read(struct bnx2x *bp, u32 offset, u8 *ret_buf,
  721. int buf_size)
  722. {
  723. int rc;
  724. u32 cmd_flags;
  725. __be32 val;
  726. if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
  727. DP(BNX2X_MSG_NVM,
  728. "Invalid parameter: offset 0x%x buf_size 0x%x\n",
  729. offset, buf_size);
  730. return -EINVAL;
  731. }
  732. if (offset + buf_size > bp->common.flash_size) {
  733. DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
  734. " buf_size (0x%x) > flash_size (0x%x)\n",
  735. offset, buf_size, bp->common.flash_size);
  736. return -EINVAL;
  737. }
  738. /* request access to nvram interface */
  739. rc = bnx2x_acquire_nvram_lock(bp);
  740. if (rc)
  741. return rc;
  742. /* enable access to nvram interface */
  743. bnx2x_enable_nvram_access(bp);
  744. /* read the first word(s) */
  745. cmd_flags = MCPR_NVM_COMMAND_FIRST;
  746. while ((buf_size > sizeof(u32)) && (rc == 0)) {
  747. rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
  748. memcpy(ret_buf, &val, 4);
  749. /* advance to the next dword */
  750. offset += sizeof(u32);
  751. ret_buf += sizeof(u32);
  752. buf_size -= sizeof(u32);
  753. cmd_flags = 0;
  754. }
  755. if (rc == 0) {
  756. cmd_flags |= MCPR_NVM_COMMAND_LAST;
  757. rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
  758. memcpy(ret_buf, &val, 4);
  759. }
  760. /* disable access to nvram interface */
  761. bnx2x_disable_nvram_access(bp);
  762. bnx2x_release_nvram_lock(bp);
  763. return rc;
  764. }
  765. static int bnx2x_get_eeprom(struct net_device *dev,
  766. struct ethtool_eeprom *eeprom, u8 *eebuf)
  767. {
  768. struct bnx2x *bp = netdev_priv(dev);
  769. int rc;
  770. if (!netif_running(dev))
  771. return -EAGAIN;
  772. DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
  773. DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
  774. eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
  775. eeprom->len, eeprom->len);
  776. /* parameters already validated in ethtool_get_eeprom */
  777. rc = bnx2x_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
  778. return rc;
  779. }
  780. static int bnx2x_nvram_write_dword(struct bnx2x *bp, u32 offset, u32 val,
  781. u32 cmd_flags)
  782. {
  783. int count, i, rc;
  784. /* build the command word */
  785. cmd_flags |= MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR;
  786. /* need to clear DONE bit separately */
  787. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
  788. /* write the data */
  789. REG_WR(bp, MCP_REG_MCPR_NVM_WRITE, val);
  790. /* address of the NVRAM to write to */
  791. REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
  792. (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
  793. /* issue the write command */
  794. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
  795. /* adjust timeout for emulation/FPGA */
  796. count = NVRAM_TIMEOUT_COUNT;
  797. if (CHIP_REV_IS_SLOW(bp))
  798. count *= 100;
  799. /* wait for completion */
  800. rc = -EBUSY;
  801. for (i = 0; i < count; i++) {
  802. udelay(5);
  803. val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
  804. if (val & MCPR_NVM_COMMAND_DONE) {
  805. rc = 0;
  806. break;
  807. }
  808. }
  809. return rc;
  810. }
  811. #define BYTE_OFFSET(offset) (8 * (offset & 0x03))
  812. static int bnx2x_nvram_write1(struct bnx2x *bp, u32 offset, u8 *data_buf,
  813. int buf_size)
  814. {
  815. int rc;
  816. u32 cmd_flags;
  817. u32 align_offset;
  818. __be32 val;
  819. if (offset + buf_size > bp->common.flash_size) {
  820. DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
  821. " buf_size (0x%x) > flash_size (0x%x)\n",
  822. offset, buf_size, bp->common.flash_size);
  823. return -EINVAL;
  824. }
  825. /* request access to nvram interface */
  826. rc = bnx2x_acquire_nvram_lock(bp);
  827. if (rc)
  828. return rc;
  829. /* enable access to nvram interface */
  830. bnx2x_enable_nvram_access(bp);
  831. cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST);
  832. align_offset = (offset & ~0x03);
  833. rc = bnx2x_nvram_read_dword(bp, align_offset, &val, cmd_flags);
  834. if (rc == 0) {
  835. val &= ~(0xff << BYTE_OFFSET(offset));
  836. val |= (*data_buf << BYTE_OFFSET(offset));
  837. /* nvram data is returned as an array of bytes
  838. * convert it back to cpu order */
  839. val = be32_to_cpu(val);
  840. rc = bnx2x_nvram_write_dword(bp, align_offset, val,
  841. cmd_flags);
  842. }
  843. /* disable access to nvram interface */
  844. bnx2x_disable_nvram_access(bp);
  845. bnx2x_release_nvram_lock(bp);
  846. return rc;
  847. }
  848. static int bnx2x_nvram_write(struct bnx2x *bp, u32 offset, u8 *data_buf,
  849. int buf_size)
  850. {
  851. int rc;
  852. u32 cmd_flags;
  853. u32 val;
  854. u32 written_so_far;
  855. if (buf_size == 1) /* ethtool */
  856. return bnx2x_nvram_write1(bp, offset, data_buf, buf_size);
  857. if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
  858. DP(BNX2X_MSG_NVM,
  859. "Invalid parameter: offset 0x%x buf_size 0x%x\n",
  860. offset, buf_size);
  861. return -EINVAL;
  862. }
  863. if (offset + buf_size > bp->common.flash_size) {
  864. DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
  865. " buf_size (0x%x) > flash_size (0x%x)\n",
  866. offset, buf_size, bp->common.flash_size);
  867. return -EINVAL;
  868. }
  869. /* request access to nvram interface */
  870. rc = bnx2x_acquire_nvram_lock(bp);
  871. if (rc)
  872. return rc;
  873. /* enable access to nvram interface */
  874. bnx2x_enable_nvram_access(bp);
  875. written_so_far = 0;
  876. cmd_flags = MCPR_NVM_COMMAND_FIRST;
  877. while ((written_so_far < buf_size) && (rc == 0)) {
  878. if (written_so_far == (buf_size - sizeof(u32)))
  879. cmd_flags |= MCPR_NVM_COMMAND_LAST;
  880. else if (((offset + 4) % NVRAM_PAGE_SIZE) == 0)
  881. cmd_flags |= MCPR_NVM_COMMAND_LAST;
  882. else if ((offset % NVRAM_PAGE_SIZE) == 0)
  883. cmd_flags |= MCPR_NVM_COMMAND_FIRST;
  884. memcpy(&val, data_buf, 4);
  885. rc = bnx2x_nvram_write_dword(bp, offset, val, cmd_flags);
  886. /* advance to the next dword */
  887. offset += sizeof(u32);
  888. data_buf += sizeof(u32);
  889. written_so_far += sizeof(u32);
  890. cmd_flags = 0;
  891. }
  892. /* disable access to nvram interface */
  893. bnx2x_disable_nvram_access(bp);
  894. bnx2x_release_nvram_lock(bp);
  895. return rc;
  896. }
  897. static int bnx2x_set_eeprom(struct net_device *dev,
  898. struct ethtool_eeprom *eeprom, u8 *eebuf)
  899. {
  900. struct bnx2x *bp = netdev_priv(dev);
  901. int port = BP_PORT(bp);
  902. int rc = 0;
  903. u32 ext_phy_config;
  904. if (!netif_running(dev))
  905. return -EAGAIN;
  906. DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
  907. DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
  908. eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
  909. eeprom->len, eeprom->len);
  910. /* parameters already validated in ethtool_set_eeprom */
  911. /* PHY eeprom can be accessed only by the PMF */
  912. if ((eeprom->magic >= 0x50485900) && (eeprom->magic <= 0x504859FF) &&
  913. !bp->port.pmf)
  914. return -EINVAL;
  915. ext_phy_config =
  916. SHMEM_RD(bp,
  917. dev_info.port_hw_config[port].external_phy_config);
  918. if (eeprom->magic == 0x50485950) {
  919. /* 'PHYP' (0x50485950): prepare phy for FW upgrade */
  920. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  921. bnx2x_acquire_phy_lock(bp);
  922. rc |= bnx2x_link_reset(&bp->link_params,
  923. &bp->link_vars, 0);
  924. if (XGXS_EXT_PHY_TYPE(ext_phy_config) ==
  925. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101)
  926. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
  927. MISC_REGISTERS_GPIO_HIGH, port);
  928. bnx2x_release_phy_lock(bp);
  929. bnx2x_link_report(bp);
  930. } else if (eeprom->magic == 0x50485952) {
  931. /* 'PHYR' (0x50485952): re-init link after FW upgrade */
  932. if (bp->state == BNX2X_STATE_OPEN) {
  933. bnx2x_acquire_phy_lock(bp);
  934. rc |= bnx2x_link_reset(&bp->link_params,
  935. &bp->link_vars, 1);
  936. rc |= bnx2x_phy_init(&bp->link_params,
  937. &bp->link_vars);
  938. bnx2x_release_phy_lock(bp);
  939. bnx2x_calc_fc_adv(bp);
  940. }
  941. } else if (eeprom->magic == 0x53985943) {
  942. /* 'PHYC' (0x53985943): PHY FW upgrade completed */
  943. if (XGXS_EXT_PHY_TYPE(ext_phy_config) ==
  944. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101) {
  945. /* DSP Remove Download Mode */
  946. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
  947. MISC_REGISTERS_GPIO_LOW, port);
  948. bnx2x_acquire_phy_lock(bp);
  949. bnx2x_sfx7101_sp_sw_reset(bp,
  950. &bp->link_params.phy[EXT_PHY1]);
  951. /* wait 0.5 sec to allow it to run */
  952. msleep(500);
  953. bnx2x_ext_phy_hw_reset(bp, port);
  954. msleep(500);
  955. bnx2x_release_phy_lock(bp);
  956. }
  957. } else
  958. rc = bnx2x_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
  959. return rc;
  960. }
  961. static int bnx2x_get_coalesce(struct net_device *dev,
  962. struct ethtool_coalesce *coal)
  963. {
  964. struct bnx2x *bp = netdev_priv(dev);
  965. memset(coal, 0, sizeof(struct ethtool_coalesce));
  966. coal->rx_coalesce_usecs = bp->rx_ticks;
  967. coal->tx_coalesce_usecs = bp->tx_ticks;
  968. return 0;
  969. }
  970. static int bnx2x_set_coalesce(struct net_device *dev,
  971. struct ethtool_coalesce *coal)
  972. {
  973. struct bnx2x *bp = netdev_priv(dev);
  974. bp->rx_ticks = (u16)coal->rx_coalesce_usecs;
  975. if (bp->rx_ticks > BNX2X_MAX_COALESCE_TOUT)
  976. bp->rx_ticks = BNX2X_MAX_COALESCE_TOUT;
  977. bp->tx_ticks = (u16)coal->tx_coalesce_usecs;
  978. if (bp->tx_ticks > BNX2X_MAX_COALESCE_TOUT)
  979. bp->tx_ticks = BNX2X_MAX_COALESCE_TOUT;
  980. if (netif_running(dev))
  981. bnx2x_update_coalesce(bp);
  982. return 0;
  983. }
  984. static void bnx2x_get_ringparam(struct net_device *dev,
  985. struct ethtool_ringparam *ering)
  986. {
  987. struct bnx2x *bp = netdev_priv(dev);
  988. ering->rx_max_pending = MAX_RX_AVAIL;
  989. ering->rx_mini_max_pending = 0;
  990. ering->rx_jumbo_max_pending = 0;
  991. if (bp->rx_ring_size)
  992. ering->rx_pending = bp->rx_ring_size;
  993. else
  994. if (bp->state == BNX2X_STATE_OPEN && bp->num_queues)
  995. ering->rx_pending = MAX_RX_AVAIL/bp->num_queues;
  996. else
  997. ering->rx_pending = MAX_RX_AVAIL;
  998. ering->rx_mini_pending = 0;
  999. ering->rx_jumbo_pending = 0;
  1000. ering->tx_max_pending = MAX_TX_AVAIL;
  1001. ering->tx_pending = bp->tx_ring_size;
  1002. }
  1003. static int bnx2x_set_ringparam(struct net_device *dev,
  1004. struct ethtool_ringparam *ering)
  1005. {
  1006. struct bnx2x *bp = netdev_priv(dev);
  1007. int rc = 0;
  1008. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  1009. printk(KERN_ERR "Handling parity error recovery. Try again later\n");
  1010. return -EAGAIN;
  1011. }
  1012. if ((ering->rx_pending > MAX_RX_AVAIL) ||
  1013. (ering->rx_pending < (bp->disable_tpa ? MIN_RX_SIZE_NONTPA :
  1014. MIN_RX_SIZE_TPA)) ||
  1015. (ering->tx_pending > MAX_TX_AVAIL) ||
  1016. (ering->tx_pending <= MAX_SKB_FRAGS + 4))
  1017. return -EINVAL;
  1018. bp->rx_ring_size = ering->rx_pending;
  1019. bp->tx_ring_size = ering->tx_pending;
  1020. if (netif_running(dev)) {
  1021. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  1022. rc = bnx2x_nic_load(bp, LOAD_NORMAL);
  1023. }
  1024. return rc;
  1025. }
  1026. static void bnx2x_get_pauseparam(struct net_device *dev,
  1027. struct ethtool_pauseparam *epause)
  1028. {
  1029. struct bnx2x *bp = netdev_priv(dev);
  1030. int cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1031. epause->autoneg = (bp->link_params.req_flow_ctrl[cfg_idx] ==
  1032. BNX2X_FLOW_CTRL_AUTO);
  1033. epause->rx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) ==
  1034. BNX2X_FLOW_CTRL_RX);
  1035. epause->tx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) ==
  1036. BNX2X_FLOW_CTRL_TX);
  1037. DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
  1038. DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n",
  1039. epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
  1040. }
  1041. static int bnx2x_set_pauseparam(struct net_device *dev,
  1042. struct ethtool_pauseparam *epause)
  1043. {
  1044. struct bnx2x *bp = netdev_priv(dev);
  1045. u32 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1046. if (IS_MF(bp))
  1047. return 0;
  1048. DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
  1049. DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n",
  1050. epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
  1051. bp->link_params.req_flow_ctrl[cfg_idx] = BNX2X_FLOW_CTRL_AUTO;
  1052. if (epause->rx_pause)
  1053. bp->link_params.req_flow_ctrl[cfg_idx] |= BNX2X_FLOW_CTRL_RX;
  1054. if (epause->tx_pause)
  1055. bp->link_params.req_flow_ctrl[cfg_idx] |= BNX2X_FLOW_CTRL_TX;
  1056. if (bp->link_params.req_flow_ctrl[cfg_idx] == BNX2X_FLOW_CTRL_AUTO)
  1057. bp->link_params.req_flow_ctrl[cfg_idx] = BNX2X_FLOW_CTRL_NONE;
  1058. if (epause->autoneg) {
  1059. if (!(bp->port.supported[cfg_idx] & SUPPORTED_Autoneg)) {
  1060. DP(NETIF_MSG_LINK, "autoneg not supported\n");
  1061. return -EINVAL;
  1062. }
  1063. if (bp->link_params.req_line_speed[cfg_idx] == SPEED_AUTO_NEG) {
  1064. bp->link_params.req_flow_ctrl[cfg_idx] =
  1065. BNX2X_FLOW_CTRL_AUTO;
  1066. }
  1067. }
  1068. DP(NETIF_MSG_LINK,
  1069. "req_flow_ctrl 0x%x\n", bp->link_params.req_flow_ctrl[cfg_idx]);
  1070. if (netif_running(dev)) {
  1071. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  1072. bnx2x_link_set(bp);
  1073. }
  1074. return 0;
  1075. }
  1076. static const struct {
  1077. char string[ETH_GSTRING_LEN];
  1078. } bnx2x_tests_str_arr[BNX2X_NUM_TESTS] = {
  1079. { "register_test (offline)" },
  1080. { "memory_test (offline)" },
  1081. { "loopback_test (offline)" },
  1082. { "nvram_test (online)" },
  1083. { "interrupt_test (online)" },
  1084. { "link_test (online)" },
  1085. { "idle check (online)" }
  1086. };
  1087. static int bnx2x_test_registers(struct bnx2x *bp)
  1088. {
  1089. int idx, i, rc = -ENODEV;
  1090. u32 wr_val = 0;
  1091. int port = BP_PORT(bp);
  1092. static const struct {
  1093. u32 offset0;
  1094. u32 offset1;
  1095. u32 mask;
  1096. } reg_tbl[] = {
  1097. /* 0 */ { BRB1_REG_PAUSE_LOW_THRESHOLD_0, 4, 0x000003ff },
  1098. { DORQ_REG_DB_ADDR0, 4, 0xffffffff },
  1099. { HC_REG_AGG_INT_0, 4, 0x000003ff },
  1100. { PBF_REG_MAC_IF0_ENABLE, 4, 0x00000001 },
  1101. { PBF_REG_P0_INIT_CRD, 4, 0x000007ff },
  1102. { PRS_REG_CID_PORT_0, 4, 0x00ffffff },
  1103. { PXP2_REG_PSWRQ_CDU0_L2P, 4, 0x000fffff },
  1104. { PXP2_REG_RQ_CDU0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
  1105. { PXP2_REG_PSWRQ_TM0_L2P, 4, 0x000fffff },
  1106. { PXP2_REG_RQ_USDM0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
  1107. /* 10 */ { PXP2_REG_PSWRQ_TSDM0_L2P, 4, 0x000fffff },
  1108. { QM_REG_CONNNUM_0, 4, 0x000fffff },
  1109. { TM_REG_LIN0_MAX_ACTIVE_CID, 4, 0x0003ffff },
  1110. { SRC_REG_KEYRSS0_0, 40, 0xffffffff },
  1111. { SRC_REG_KEYRSS0_7, 40, 0xffffffff },
  1112. { XCM_REG_WU_DA_SET_TMR_CNT_FLG_CMD00, 4, 0x00000001 },
  1113. { XCM_REG_WU_DA_CNT_CMD00, 4, 0x00000003 },
  1114. { XCM_REG_GLB_DEL_ACK_MAX_CNT_0, 4, 0x000000ff },
  1115. { NIG_REG_LLH0_T_BIT, 4, 0x00000001 },
  1116. { NIG_REG_EMAC0_IN_EN, 4, 0x00000001 },
  1117. /* 20 */ { NIG_REG_BMAC0_IN_EN, 4, 0x00000001 },
  1118. { NIG_REG_XCM0_OUT_EN, 4, 0x00000001 },
  1119. { NIG_REG_BRB0_OUT_EN, 4, 0x00000001 },
  1120. { NIG_REG_LLH0_XCM_MASK, 4, 0x00000007 },
  1121. { NIG_REG_LLH0_ACPI_PAT_6_LEN, 68, 0x000000ff },
  1122. { NIG_REG_LLH0_ACPI_PAT_0_CRC, 68, 0xffffffff },
  1123. { NIG_REG_LLH0_DEST_MAC_0_0, 160, 0xffffffff },
  1124. { NIG_REG_LLH0_DEST_IP_0_1, 160, 0xffffffff },
  1125. { NIG_REG_LLH0_IPV4_IPV6_0, 160, 0x00000001 },
  1126. { NIG_REG_LLH0_DEST_UDP_0, 160, 0x0000ffff },
  1127. /* 30 */ { NIG_REG_LLH0_DEST_TCP_0, 160, 0x0000ffff },
  1128. { NIG_REG_LLH0_VLAN_ID_0, 160, 0x00000fff },
  1129. { NIG_REG_XGXS_SERDES0_MODE_SEL, 4, 0x00000001 },
  1130. { NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0, 4, 0x00000001 },
  1131. { NIG_REG_STATUS_INTERRUPT_PORT0, 4, 0x07ffffff },
  1132. { NIG_REG_XGXS0_CTRL_EXTREMOTEMDIOST, 24, 0x00000001 },
  1133. { NIG_REG_SERDES0_CTRL_PHY_ADDR, 16, 0x0000001f },
  1134. { 0xffffffff, 0, 0x00000000 }
  1135. };
  1136. if (!netif_running(bp->dev))
  1137. return rc;
  1138. /* Repeat the test twice:
  1139. First by writing 0x00000000, second by writing 0xffffffff */
  1140. for (idx = 0; idx < 2; idx++) {
  1141. switch (idx) {
  1142. case 0:
  1143. wr_val = 0;
  1144. break;
  1145. case 1:
  1146. wr_val = 0xffffffff;
  1147. break;
  1148. }
  1149. for (i = 0; reg_tbl[i].offset0 != 0xffffffff; i++) {
  1150. u32 offset, mask, save_val, val;
  1151. if (CHIP_IS_E2(bp) &&
  1152. reg_tbl[i].offset0 == HC_REG_AGG_INT_0)
  1153. continue;
  1154. offset = reg_tbl[i].offset0 + port*reg_tbl[i].offset1;
  1155. mask = reg_tbl[i].mask;
  1156. save_val = REG_RD(bp, offset);
  1157. REG_WR(bp, offset, wr_val & mask);
  1158. val = REG_RD(bp, offset);
  1159. /* Restore the original register's value */
  1160. REG_WR(bp, offset, save_val);
  1161. /* verify value is as expected */
  1162. if ((val & mask) != (wr_val & mask)) {
  1163. DP(NETIF_MSG_PROBE,
  1164. "offset 0x%x: val 0x%x != 0x%x mask 0x%x\n",
  1165. offset, val, wr_val, mask);
  1166. goto test_reg_exit;
  1167. }
  1168. }
  1169. }
  1170. rc = 0;
  1171. test_reg_exit:
  1172. return rc;
  1173. }
  1174. static int bnx2x_test_memory(struct bnx2x *bp)
  1175. {
  1176. int i, j, rc = -ENODEV;
  1177. u32 val;
  1178. static const struct {
  1179. u32 offset;
  1180. int size;
  1181. } mem_tbl[] = {
  1182. { CCM_REG_XX_DESCR_TABLE, CCM_REG_XX_DESCR_TABLE_SIZE },
  1183. { CFC_REG_ACTIVITY_COUNTER, CFC_REG_ACTIVITY_COUNTER_SIZE },
  1184. { CFC_REG_LINK_LIST, CFC_REG_LINK_LIST_SIZE },
  1185. { DMAE_REG_CMD_MEM, DMAE_REG_CMD_MEM_SIZE },
  1186. { TCM_REG_XX_DESCR_TABLE, TCM_REG_XX_DESCR_TABLE_SIZE },
  1187. { UCM_REG_XX_DESCR_TABLE, UCM_REG_XX_DESCR_TABLE_SIZE },
  1188. { XCM_REG_XX_DESCR_TABLE, XCM_REG_XX_DESCR_TABLE_SIZE },
  1189. { 0xffffffff, 0 }
  1190. };
  1191. static const struct {
  1192. char *name;
  1193. u32 offset;
  1194. u32 e1_mask;
  1195. u32 e1h_mask;
  1196. u32 e2_mask;
  1197. } prty_tbl[] = {
  1198. { "CCM_PRTY_STS", CCM_REG_CCM_PRTY_STS, 0x3ffc0, 0, 0 },
  1199. { "CFC_PRTY_STS", CFC_REG_CFC_PRTY_STS, 0x2, 0x2, 0 },
  1200. { "DMAE_PRTY_STS", DMAE_REG_DMAE_PRTY_STS, 0, 0, 0 },
  1201. { "TCM_PRTY_STS", TCM_REG_TCM_PRTY_STS, 0x3ffc0, 0, 0 },
  1202. { "UCM_PRTY_STS", UCM_REG_UCM_PRTY_STS, 0x3ffc0, 0, 0 },
  1203. { "XCM_PRTY_STS", XCM_REG_XCM_PRTY_STS, 0x3ffc1, 0, 0 },
  1204. { NULL, 0xffffffff, 0, 0, 0 }
  1205. };
  1206. if (!netif_running(bp->dev))
  1207. return rc;
  1208. /* pre-Check the parity status */
  1209. for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
  1210. val = REG_RD(bp, prty_tbl[i].offset);
  1211. if ((CHIP_IS_E1(bp) && (val & ~(prty_tbl[i].e1_mask))) ||
  1212. (CHIP_IS_E1H(bp) && (val & ~(prty_tbl[i].e1h_mask))) ||
  1213. (CHIP_IS_E2(bp) && (val & ~(prty_tbl[i].e2_mask)))) {
  1214. DP(NETIF_MSG_HW,
  1215. "%s is 0x%x\n", prty_tbl[i].name, val);
  1216. goto test_mem_exit;
  1217. }
  1218. }
  1219. /* Go through all the memories */
  1220. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++)
  1221. for (j = 0; j < mem_tbl[i].size; j++)
  1222. REG_RD(bp, mem_tbl[i].offset + j*4);
  1223. /* Check the parity status */
  1224. for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
  1225. val = REG_RD(bp, prty_tbl[i].offset);
  1226. if ((CHIP_IS_E1(bp) && (val & ~(prty_tbl[i].e1_mask))) ||
  1227. (CHIP_IS_E1H(bp) && (val & ~(prty_tbl[i].e1h_mask))) ||
  1228. (CHIP_IS_E2(bp) && (val & ~(prty_tbl[i].e2_mask)))) {
  1229. DP(NETIF_MSG_HW,
  1230. "%s is 0x%x\n", prty_tbl[i].name, val);
  1231. goto test_mem_exit;
  1232. }
  1233. }
  1234. rc = 0;
  1235. test_mem_exit:
  1236. return rc;
  1237. }
  1238. static void bnx2x_wait_for_link(struct bnx2x *bp, u8 link_up, u8 is_serdes)
  1239. {
  1240. int cnt = 1400;
  1241. if (link_up)
  1242. while (bnx2x_link_test(bp, is_serdes) && cnt--)
  1243. msleep(10);
  1244. }
  1245. static int bnx2x_run_loopback(struct bnx2x *bp, int loopback_mode, u8 link_up)
  1246. {
  1247. unsigned int pkt_size, num_pkts, i;
  1248. struct sk_buff *skb;
  1249. unsigned char *packet;
  1250. struct bnx2x_fastpath *fp_rx = &bp->fp[0];
  1251. struct bnx2x_fastpath *fp_tx = &bp->fp[0];
  1252. u16 tx_start_idx, tx_idx;
  1253. u16 rx_start_idx, rx_idx;
  1254. u16 pkt_prod, bd_prod;
  1255. struct sw_tx_bd *tx_buf;
  1256. struct eth_tx_start_bd *tx_start_bd;
  1257. struct eth_tx_parse_bd_e1x *pbd_e1x = NULL;
  1258. struct eth_tx_parse_bd_e2 *pbd_e2 = NULL;
  1259. dma_addr_t mapping;
  1260. union eth_rx_cqe *cqe;
  1261. u8 cqe_fp_flags;
  1262. struct sw_rx_bd *rx_buf;
  1263. u16 len;
  1264. int rc = -ENODEV;
  1265. /* check the loopback mode */
  1266. switch (loopback_mode) {
  1267. case BNX2X_PHY_LOOPBACK:
  1268. if (bp->link_params.loopback_mode != LOOPBACK_XGXS)
  1269. return -EINVAL;
  1270. break;
  1271. case BNX2X_MAC_LOOPBACK:
  1272. bp->link_params.loopback_mode = LOOPBACK_BMAC;
  1273. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1274. break;
  1275. default:
  1276. return -EINVAL;
  1277. }
  1278. /* prepare the loopback packet */
  1279. pkt_size = (((bp->dev->mtu < ETH_MAX_PACKET_SIZE) ?
  1280. bp->dev->mtu : ETH_MAX_PACKET_SIZE) + ETH_HLEN);
  1281. skb = netdev_alloc_skb(bp->dev, fp_rx->rx_buf_size);
  1282. if (!skb) {
  1283. rc = -ENOMEM;
  1284. goto test_loopback_exit;
  1285. }
  1286. packet = skb_put(skb, pkt_size);
  1287. memcpy(packet, bp->dev->dev_addr, ETH_ALEN);
  1288. memset(packet + ETH_ALEN, 0, ETH_ALEN);
  1289. memset(packet + 2*ETH_ALEN, 0x77, (ETH_HLEN - 2*ETH_ALEN));
  1290. for (i = ETH_HLEN; i < pkt_size; i++)
  1291. packet[i] = (unsigned char) (i & 0xff);
  1292. /* send the loopback packet */
  1293. num_pkts = 0;
  1294. tx_start_idx = le16_to_cpu(*fp_tx->tx_cons_sb);
  1295. rx_start_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
  1296. pkt_prod = fp_tx->tx_pkt_prod++;
  1297. tx_buf = &fp_tx->tx_buf_ring[TX_BD(pkt_prod)];
  1298. tx_buf->first_bd = fp_tx->tx_bd_prod;
  1299. tx_buf->skb = skb;
  1300. tx_buf->flags = 0;
  1301. bd_prod = TX_BD(fp_tx->tx_bd_prod);
  1302. tx_start_bd = &fp_tx->tx_desc_ring[bd_prod].start_bd;
  1303. mapping = dma_map_single(&bp->pdev->dev, skb->data,
  1304. skb_headlen(skb), DMA_TO_DEVICE);
  1305. tx_start_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  1306. tx_start_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  1307. tx_start_bd->nbd = cpu_to_le16(2); /* start + pbd */
  1308. tx_start_bd->nbytes = cpu_to_le16(skb_headlen(skb));
  1309. tx_start_bd->vlan_or_ethertype = cpu_to_le16(pkt_prod);
  1310. tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
  1311. SET_FLAG(tx_start_bd->general_data,
  1312. ETH_TX_START_BD_ETH_ADDR_TYPE,
  1313. UNICAST_ADDRESS);
  1314. SET_FLAG(tx_start_bd->general_data,
  1315. ETH_TX_START_BD_HDR_NBDS,
  1316. 1);
  1317. /* turn on parsing and get a BD */
  1318. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  1319. pbd_e1x = &fp_tx->tx_desc_ring[bd_prod].parse_bd_e1x;
  1320. pbd_e2 = &fp_tx->tx_desc_ring[bd_prod].parse_bd_e2;
  1321. memset(pbd_e2, 0, sizeof(struct eth_tx_parse_bd_e2));
  1322. memset(pbd_e1x, 0, sizeof(struct eth_tx_parse_bd_e1x));
  1323. wmb();
  1324. fp_tx->tx_db.data.prod += 2;
  1325. barrier();
  1326. DOORBELL(bp, fp_tx->index, fp_tx->tx_db.raw);
  1327. mmiowb();
  1328. num_pkts++;
  1329. fp_tx->tx_bd_prod += 2; /* start + pbd */
  1330. udelay(100);
  1331. tx_idx = le16_to_cpu(*fp_tx->tx_cons_sb);
  1332. if (tx_idx != tx_start_idx + num_pkts)
  1333. goto test_loopback_exit;
  1334. /* Unlike HC IGU won't generate an interrupt for status block
  1335. * updates that have been performed while interrupts were
  1336. * disabled.
  1337. */
  1338. if (bp->common.int_block == INT_BLOCK_IGU) {
  1339. /* Disable local BHes to prevent a dead-lock situation between
  1340. * sch_direct_xmit() and bnx2x_run_loopback() (calling
  1341. * bnx2x_tx_int()), as both are taking netif_tx_lock().
  1342. */
  1343. local_bh_disable();
  1344. bnx2x_tx_int(fp_tx);
  1345. local_bh_enable();
  1346. }
  1347. rx_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
  1348. if (rx_idx != rx_start_idx + num_pkts)
  1349. goto test_loopback_exit;
  1350. cqe = &fp_rx->rx_comp_ring[RCQ_BD(fp_rx->rx_comp_cons)];
  1351. cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
  1352. if (CQE_TYPE(cqe_fp_flags) || (cqe_fp_flags & ETH_RX_ERROR_FALGS))
  1353. goto test_loopback_rx_exit;
  1354. len = le16_to_cpu(cqe->fast_path_cqe.pkt_len);
  1355. if (len != pkt_size)
  1356. goto test_loopback_rx_exit;
  1357. rx_buf = &fp_rx->rx_buf_ring[RX_BD(fp_rx->rx_bd_cons)];
  1358. skb = rx_buf->skb;
  1359. skb_reserve(skb, cqe->fast_path_cqe.placement_offset);
  1360. for (i = ETH_HLEN; i < pkt_size; i++)
  1361. if (*(skb->data + i) != (unsigned char) (i & 0xff))
  1362. goto test_loopback_rx_exit;
  1363. rc = 0;
  1364. test_loopback_rx_exit:
  1365. fp_rx->rx_bd_cons = NEXT_RX_IDX(fp_rx->rx_bd_cons);
  1366. fp_rx->rx_bd_prod = NEXT_RX_IDX(fp_rx->rx_bd_prod);
  1367. fp_rx->rx_comp_cons = NEXT_RCQ_IDX(fp_rx->rx_comp_cons);
  1368. fp_rx->rx_comp_prod = NEXT_RCQ_IDX(fp_rx->rx_comp_prod);
  1369. /* Update producers */
  1370. bnx2x_update_rx_prod(bp, fp_rx, fp_rx->rx_bd_prod, fp_rx->rx_comp_prod,
  1371. fp_rx->rx_sge_prod);
  1372. test_loopback_exit:
  1373. bp->link_params.loopback_mode = LOOPBACK_NONE;
  1374. return rc;
  1375. }
  1376. static int bnx2x_test_loopback(struct bnx2x *bp, u8 link_up)
  1377. {
  1378. int rc = 0, res;
  1379. if (BP_NOMCP(bp))
  1380. return rc;
  1381. if (!netif_running(bp->dev))
  1382. return BNX2X_LOOPBACK_FAILED;
  1383. bnx2x_netif_stop(bp, 1);
  1384. bnx2x_acquire_phy_lock(bp);
  1385. res = bnx2x_run_loopback(bp, BNX2X_PHY_LOOPBACK, link_up);
  1386. if (res) {
  1387. DP(NETIF_MSG_PROBE, " PHY loopback failed (res %d)\n", res);
  1388. rc |= BNX2X_PHY_LOOPBACK_FAILED;
  1389. }
  1390. res = bnx2x_run_loopback(bp, BNX2X_MAC_LOOPBACK, link_up);
  1391. if (res) {
  1392. DP(NETIF_MSG_PROBE, " MAC loopback failed (res %d)\n", res);
  1393. rc |= BNX2X_MAC_LOOPBACK_FAILED;
  1394. }
  1395. bnx2x_release_phy_lock(bp);
  1396. bnx2x_netif_start(bp);
  1397. return rc;
  1398. }
  1399. #define CRC32_RESIDUAL 0xdebb20e3
  1400. static int bnx2x_test_nvram(struct bnx2x *bp)
  1401. {
  1402. static const struct {
  1403. int offset;
  1404. int size;
  1405. } nvram_tbl[] = {
  1406. { 0, 0x14 }, /* bootstrap */
  1407. { 0x14, 0xec }, /* dir */
  1408. { 0x100, 0x350 }, /* manuf_info */
  1409. { 0x450, 0xf0 }, /* feature_info */
  1410. { 0x640, 0x64 }, /* upgrade_key_info */
  1411. { 0x708, 0x70 }, /* manuf_key_info */
  1412. { 0, 0 }
  1413. };
  1414. __be32 buf[0x350 / 4];
  1415. u8 *data = (u8 *)buf;
  1416. int i, rc;
  1417. u32 magic, crc;
  1418. if (BP_NOMCP(bp))
  1419. return 0;
  1420. rc = bnx2x_nvram_read(bp, 0, data, 4);
  1421. if (rc) {
  1422. DP(NETIF_MSG_PROBE, "magic value read (rc %d)\n", rc);
  1423. goto test_nvram_exit;
  1424. }
  1425. magic = be32_to_cpu(buf[0]);
  1426. if (magic != 0x669955aa) {
  1427. DP(NETIF_MSG_PROBE, "magic value (0x%08x)\n", magic);
  1428. rc = -ENODEV;
  1429. goto test_nvram_exit;
  1430. }
  1431. for (i = 0; nvram_tbl[i].size; i++) {
  1432. rc = bnx2x_nvram_read(bp, nvram_tbl[i].offset, data,
  1433. nvram_tbl[i].size);
  1434. if (rc) {
  1435. DP(NETIF_MSG_PROBE,
  1436. "nvram_tbl[%d] read data (rc %d)\n", i, rc);
  1437. goto test_nvram_exit;
  1438. }
  1439. crc = ether_crc_le(nvram_tbl[i].size, data);
  1440. if (crc != CRC32_RESIDUAL) {
  1441. DP(NETIF_MSG_PROBE,
  1442. "nvram_tbl[%d] crc value (0x%08x)\n", i, crc);
  1443. rc = -ENODEV;
  1444. goto test_nvram_exit;
  1445. }
  1446. }
  1447. test_nvram_exit:
  1448. return rc;
  1449. }
  1450. static int bnx2x_test_intr(struct bnx2x *bp)
  1451. {
  1452. struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config);
  1453. int i, rc;
  1454. if (!netif_running(bp->dev))
  1455. return -ENODEV;
  1456. config->hdr.length = 0;
  1457. if (CHIP_IS_E1(bp))
  1458. config->hdr.offset = (BP_PORT(bp) ? 32 : 0);
  1459. else
  1460. config->hdr.offset = BP_FUNC(bp);
  1461. config->hdr.client_id = bp->fp->cl_id;
  1462. config->hdr.reserved1 = 0;
  1463. bp->set_mac_pending = 1;
  1464. smp_wmb();
  1465. rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_SET_MAC, 0,
  1466. U64_HI(bnx2x_sp_mapping(bp, mac_config)),
  1467. U64_LO(bnx2x_sp_mapping(bp, mac_config)), 1);
  1468. if (rc == 0) {
  1469. for (i = 0; i < 10; i++) {
  1470. if (!bp->set_mac_pending)
  1471. break;
  1472. smp_rmb();
  1473. msleep_interruptible(10);
  1474. }
  1475. if (i == 10)
  1476. rc = -ENODEV;
  1477. }
  1478. return rc;
  1479. }
  1480. static void bnx2x_self_test(struct net_device *dev,
  1481. struct ethtool_test *etest, u64 *buf)
  1482. {
  1483. struct bnx2x *bp = netdev_priv(dev);
  1484. u8 is_serdes;
  1485. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  1486. printk(KERN_ERR "Handling parity error recovery. Try again later\n");
  1487. etest->flags |= ETH_TEST_FL_FAILED;
  1488. return;
  1489. }
  1490. memset(buf, 0, sizeof(u64) * BNX2X_NUM_TESTS);
  1491. if (!netif_running(dev))
  1492. return;
  1493. /* offline tests are not supported in MF mode */
  1494. if (IS_MF(bp))
  1495. etest->flags &= ~ETH_TEST_FL_OFFLINE;
  1496. is_serdes = (bp->link_vars.link_status & LINK_STATUS_SERDES_LINK) > 0;
  1497. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  1498. int port = BP_PORT(bp);
  1499. u32 val;
  1500. u8 link_up;
  1501. /* save current value of input enable for TX port IF */
  1502. val = REG_RD(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4);
  1503. /* disable input for TX port IF */
  1504. REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, 0);
  1505. link_up = bp->link_vars.link_up;
  1506. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  1507. bnx2x_nic_load(bp, LOAD_DIAG);
  1508. /* wait until link state is restored */
  1509. bnx2x_wait_for_link(bp, link_up, is_serdes);
  1510. if (bnx2x_test_registers(bp) != 0) {
  1511. buf[0] = 1;
  1512. etest->flags |= ETH_TEST_FL_FAILED;
  1513. }
  1514. if (bnx2x_test_memory(bp) != 0) {
  1515. buf[1] = 1;
  1516. etest->flags |= ETH_TEST_FL_FAILED;
  1517. }
  1518. buf[2] = bnx2x_test_loopback(bp, link_up);
  1519. if (buf[2] != 0)
  1520. etest->flags |= ETH_TEST_FL_FAILED;
  1521. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  1522. /* restore input for TX port IF */
  1523. REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, val);
  1524. bnx2x_nic_load(bp, LOAD_NORMAL);
  1525. /* wait until link state is restored */
  1526. bnx2x_wait_for_link(bp, link_up, is_serdes);
  1527. }
  1528. if (bnx2x_test_nvram(bp) != 0) {
  1529. buf[3] = 1;
  1530. etest->flags |= ETH_TEST_FL_FAILED;
  1531. }
  1532. if (bnx2x_test_intr(bp) != 0) {
  1533. buf[4] = 1;
  1534. etest->flags |= ETH_TEST_FL_FAILED;
  1535. }
  1536. if (bnx2x_link_test(bp, is_serdes) != 0) {
  1537. buf[5] = 1;
  1538. etest->flags |= ETH_TEST_FL_FAILED;
  1539. }
  1540. #ifdef BNX2X_EXTRA_DEBUG
  1541. bnx2x_panic_dump(bp);
  1542. #endif
  1543. }
  1544. #define IS_PORT_STAT(i) \
  1545. ((bnx2x_stats_arr[i].flags & STATS_FLAGS_BOTH) == STATS_FLAGS_PORT)
  1546. #define IS_FUNC_STAT(i) (bnx2x_stats_arr[i].flags & STATS_FLAGS_FUNC)
  1547. #define IS_MF_MODE_STAT(bp) \
  1548. (IS_MF(bp) && !(bp->msg_enable & BNX2X_MSG_STATS))
  1549. static int bnx2x_get_sset_count(struct net_device *dev, int stringset)
  1550. {
  1551. struct bnx2x *bp = netdev_priv(dev);
  1552. int i, num_stats;
  1553. switch (stringset) {
  1554. case ETH_SS_STATS:
  1555. if (is_multi(bp)) {
  1556. num_stats = BNX2X_NUM_STAT_QUEUES(bp) *
  1557. BNX2X_NUM_Q_STATS;
  1558. if (!IS_MF_MODE_STAT(bp))
  1559. num_stats += BNX2X_NUM_STATS;
  1560. } else {
  1561. if (IS_MF_MODE_STAT(bp)) {
  1562. num_stats = 0;
  1563. for (i = 0; i < BNX2X_NUM_STATS; i++)
  1564. if (IS_FUNC_STAT(i))
  1565. num_stats++;
  1566. } else
  1567. num_stats = BNX2X_NUM_STATS;
  1568. }
  1569. return num_stats;
  1570. case ETH_SS_TEST:
  1571. return BNX2X_NUM_TESTS;
  1572. default:
  1573. return -EINVAL;
  1574. }
  1575. }
  1576. static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  1577. {
  1578. struct bnx2x *bp = netdev_priv(dev);
  1579. int i, j, k;
  1580. char queue_name[MAX_QUEUE_NAME_LEN+1];
  1581. switch (stringset) {
  1582. case ETH_SS_STATS:
  1583. if (is_multi(bp)) {
  1584. k = 0;
  1585. for_each_napi_queue(bp, i) {
  1586. memset(queue_name, 0, sizeof(queue_name));
  1587. if (IS_FCOE_IDX(i))
  1588. sprintf(queue_name, "fcoe");
  1589. else
  1590. sprintf(queue_name, "%d", i);
  1591. for (j = 0; j < BNX2X_NUM_Q_STATS; j++)
  1592. snprintf(buf + (k + j)*ETH_GSTRING_LEN,
  1593. ETH_GSTRING_LEN,
  1594. bnx2x_q_stats_arr[j].string,
  1595. queue_name);
  1596. k += BNX2X_NUM_Q_STATS;
  1597. }
  1598. if (IS_MF_MODE_STAT(bp))
  1599. break;
  1600. for (j = 0; j < BNX2X_NUM_STATS; j++)
  1601. strcpy(buf + (k + j)*ETH_GSTRING_LEN,
  1602. bnx2x_stats_arr[j].string);
  1603. } else {
  1604. for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
  1605. if (IS_MF_MODE_STAT(bp) && IS_PORT_STAT(i))
  1606. continue;
  1607. strcpy(buf + j*ETH_GSTRING_LEN,
  1608. bnx2x_stats_arr[i].string);
  1609. j++;
  1610. }
  1611. }
  1612. break;
  1613. case ETH_SS_TEST:
  1614. memcpy(buf, bnx2x_tests_str_arr, sizeof(bnx2x_tests_str_arr));
  1615. break;
  1616. }
  1617. }
  1618. static void bnx2x_get_ethtool_stats(struct net_device *dev,
  1619. struct ethtool_stats *stats, u64 *buf)
  1620. {
  1621. struct bnx2x *bp = netdev_priv(dev);
  1622. u32 *hw_stats, *offset;
  1623. int i, j, k;
  1624. if (is_multi(bp)) {
  1625. k = 0;
  1626. for_each_napi_queue(bp, i) {
  1627. hw_stats = (u32 *)&bp->fp[i].eth_q_stats;
  1628. for (j = 0; j < BNX2X_NUM_Q_STATS; j++) {
  1629. if (bnx2x_q_stats_arr[j].size == 0) {
  1630. /* skip this counter */
  1631. buf[k + j] = 0;
  1632. continue;
  1633. }
  1634. offset = (hw_stats +
  1635. bnx2x_q_stats_arr[j].offset);
  1636. if (bnx2x_q_stats_arr[j].size == 4) {
  1637. /* 4-byte counter */
  1638. buf[k + j] = (u64) *offset;
  1639. continue;
  1640. }
  1641. /* 8-byte counter */
  1642. buf[k + j] = HILO_U64(*offset, *(offset + 1));
  1643. }
  1644. k += BNX2X_NUM_Q_STATS;
  1645. }
  1646. if (IS_MF_MODE_STAT(bp))
  1647. return;
  1648. hw_stats = (u32 *)&bp->eth_stats;
  1649. for (j = 0; j < BNX2X_NUM_STATS; j++) {
  1650. if (bnx2x_stats_arr[j].size == 0) {
  1651. /* skip this counter */
  1652. buf[k + j] = 0;
  1653. continue;
  1654. }
  1655. offset = (hw_stats + bnx2x_stats_arr[j].offset);
  1656. if (bnx2x_stats_arr[j].size == 4) {
  1657. /* 4-byte counter */
  1658. buf[k + j] = (u64) *offset;
  1659. continue;
  1660. }
  1661. /* 8-byte counter */
  1662. buf[k + j] = HILO_U64(*offset, *(offset + 1));
  1663. }
  1664. } else {
  1665. hw_stats = (u32 *)&bp->eth_stats;
  1666. for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
  1667. if (IS_MF_MODE_STAT(bp) && IS_PORT_STAT(i))
  1668. continue;
  1669. if (bnx2x_stats_arr[i].size == 0) {
  1670. /* skip this counter */
  1671. buf[j] = 0;
  1672. j++;
  1673. continue;
  1674. }
  1675. offset = (hw_stats + bnx2x_stats_arr[i].offset);
  1676. if (bnx2x_stats_arr[i].size == 4) {
  1677. /* 4-byte counter */
  1678. buf[j] = (u64) *offset;
  1679. j++;
  1680. continue;
  1681. }
  1682. /* 8-byte counter */
  1683. buf[j] = HILO_U64(*offset, *(offset + 1));
  1684. j++;
  1685. }
  1686. }
  1687. }
  1688. static int bnx2x_set_phys_id(struct net_device *dev,
  1689. enum ethtool_phys_id_state state)
  1690. {
  1691. struct bnx2x *bp = netdev_priv(dev);
  1692. if (!netif_running(dev))
  1693. return -EAGAIN;
  1694. if (!bp->port.pmf)
  1695. return -EOPNOTSUPP;
  1696. switch (state) {
  1697. case ETHTOOL_ID_ACTIVE:
  1698. return 1; /* cycle on/off once per second */
  1699. case ETHTOOL_ID_ON:
  1700. bnx2x_set_led(&bp->link_params, &bp->link_vars,
  1701. LED_MODE_ON, SPEED_1000);
  1702. break;
  1703. case ETHTOOL_ID_OFF:
  1704. bnx2x_set_led(&bp->link_params, &bp->link_vars,
  1705. LED_MODE_FRONT_PANEL_OFF, 0);
  1706. break;
  1707. case ETHTOOL_ID_INACTIVE:
  1708. bnx2x_set_led(&bp->link_params, &bp->link_vars,
  1709. LED_MODE_OPER,
  1710. bp->link_vars.line_speed);
  1711. }
  1712. return 0;
  1713. }
  1714. static int bnx2x_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
  1715. void *rules __always_unused)
  1716. {
  1717. struct bnx2x *bp = netdev_priv(dev);
  1718. switch (info->cmd) {
  1719. case ETHTOOL_GRXRINGS:
  1720. info->data = BNX2X_NUM_ETH_QUEUES(bp);
  1721. return 0;
  1722. default:
  1723. return -EOPNOTSUPP;
  1724. }
  1725. }
  1726. static int bnx2x_get_rxfh_indir(struct net_device *dev,
  1727. struct ethtool_rxfh_indir *indir)
  1728. {
  1729. struct bnx2x *bp = netdev_priv(dev);
  1730. size_t copy_size =
  1731. min_t(size_t, indir->size, TSTORM_INDIRECTION_TABLE_SIZE);
  1732. if (bp->multi_mode == ETH_RSS_MODE_DISABLED)
  1733. return -EOPNOTSUPP;
  1734. indir->size = TSTORM_INDIRECTION_TABLE_SIZE;
  1735. memcpy(indir->ring_index, bp->rx_indir_table,
  1736. copy_size * sizeof(bp->rx_indir_table[0]));
  1737. return 0;
  1738. }
  1739. static int bnx2x_set_rxfh_indir(struct net_device *dev,
  1740. const struct ethtool_rxfh_indir *indir)
  1741. {
  1742. struct bnx2x *bp = netdev_priv(dev);
  1743. size_t i;
  1744. if (bp->multi_mode == ETH_RSS_MODE_DISABLED)
  1745. return -EOPNOTSUPP;
  1746. /* Validate size and indices */
  1747. if (indir->size != TSTORM_INDIRECTION_TABLE_SIZE)
  1748. return -EINVAL;
  1749. for (i = 0; i < TSTORM_INDIRECTION_TABLE_SIZE; i++)
  1750. if (indir->ring_index[i] >= BNX2X_NUM_ETH_QUEUES(bp))
  1751. return -EINVAL;
  1752. memcpy(bp->rx_indir_table, indir->ring_index,
  1753. indir->size * sizeof(bp->rx_indir_table[0]));
  1754. bnx2x_push_indir_table(bp);
  1755. return 0;
  1756. }
  1757. static const struct ethtool_ops bnx2x_ethtool_ops = {
  1758. .get_settings = bnx2x_get_settings,
  1759. .set_settings = bnx2x_set_settings,
  1760. .get_drvinfo = bnx2x_get_drvinfo,
  1761. .get_regs_len = bnx2x_get_regs_len,
  1762. .get_regs = bnx2x_get_regs,
  1763. .get_wol = bnx2x_get_wol,
  1764. .set_wol = bnx2x_set_wol,
  1765. .get_msglevel = bnx2x_get_msglevel,
  1766. .set_msglevel = bnx2x_set_msglevel,
  1767. .nway_reset = bnx2x_nway_reset,
  1768. .get_link = bnx2x_get_link,
  1769. .get_eeprom_len = bnx2x_get_eeprom_len,
  1770. .get_eeprom = bnx2x_get_eeprom,
  1771. .set_eeprom = bnx2x_set_eeprom,
  1772. .get_coalesce = bnx2x_get_coalesce,
  1773. .set_coalesce = bnx2x_set_coalesce,
  1774. .get_ringparam = bnx2x_get_ringparam,
  1775. .set_ringparam = bnx2x_set_ringparam,
  1776. .get_pauseparam = bnx2x_get_pauseparam,
  1777. .set_pauseparam = bnx2x_set_pauseparam,
  1778. .self_test = bnx2x_self_test,
  1779. .get_sset_count = bnx2x_get_sset_count,
  1780. .get_strings = bnx2x_get_strings,
  1781. .set_phys_id = bnx2x_set_phys_id,
  1782. .get_ethtool_stats = bnx2x_get_ethtool_stats,
  1783. .get_rxnfc = bnx2x_get_rxnfc,
  1784. .get_rxfh_indir = bnx2x_get_rxfh_indir,
  1785. .set_rxfh_indir = bnx2x_set_rxfh_indir,
  1786. };
  1787. void bnx2x_set_ethtool_ops(struct net_device *netdev)
  1788. {
  1789. SET_ETHTOOL_OPS(netdev, &bnx2x_ethtool_ops);
  1790. }