siena.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006-2010 Solarflare Communications Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation, incorporated herein by reference.
  9. */
  10. #include <linux/bitops.h>
  11. #include <linux/delay.h>
  12. #include <linux/pci.h>
  13. #include <linux/module.h>
  14. #include <linux/slab.h>
  15. #include <linux/random.h>
  16. #include "net_driver.h"
  17. #include "bitfield.h"
  18. #include "efx.h"
  19. #include "nic.h"
  20. #include "mac.h"
  21. #include "spi.h"
  22. #include "regs.h"
  23. #include "io.h"
  24. #include "phy.h"
  25. #include "workarounds.h"
  26. #include "mcdi.h"
  27. #include "mcdi_pcol.h"
  28. /* Hardware control for SFC9000 family including SFL9021 (aka Siena). */
  29. static void siena_init_wol(struct efx_nic *efx);
  30. static void siena_push_irq_moderation(struct efx_channel *channel)
  31. {
  32. efx_dword_t timer_cmd;
  33. BUILD_BUG_ON(EFX_IRQ_MOD_MAX > (1 << FRF_CZ_TC_TIMER_VAL_WIDTH));
  34. if (channel->irq_moderation)
  35. EFX_POPULATE_DWORD_2(timer_cmd,
  36. FRF_CZ_TC_TIMER_MODE,
  37. FFE_CZ_TIMER_MODE_INT_HLDOFF,
  38. FRF_CZ_TC_TIMER_VAL,
  39. channel->irq_moderation - 1);
  40. else
  41. EFX_POPULATE_DWORD_2(timer_cmd,
  42. FRF_CZ_TC_TIMER_MODE,
  43. FFE_CZ_TIMER_MODE_DIS,
  44. FRF_CZ_TC_TIMER_VAL, 0);
  45. efx_writed_page_locked(channel->efx, &timer_cmd, FR_BZ_TIMER_COMMAND_P0,
  46. channel->channel);
  47. }
  48. static void siena_push_multicast_hash(struct efx_nic *efx)
  49. {
  50. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  51. efx_mcdi_rpc(efx, MC_CMD_SET_MCAST_HASH,
  52. efx->multicast_hash.byte, sizeof(efx->multicast_hash),
  53. NULL, 0, NULL);
  54. }
  55. static int siena_mdio_write(struct net_device *net_dev,
  56. int prtad, int devad, u16 addr, u16 value)
  57. {
  58. struct efx_nic *efx = netdev_priv(net_dev);
  59. uint32_t status;
  60. int rc;
  61. rc = efx_mcdi_mdio_write(efx, efx->mdio_bus, prtad, devad,
  62. addr, value, &status);
  63. if (rc)
  64. return rc;
  65. if (status != MC_CMD_MDIO_STATUS_GOOD)
  66. return -EIO;
  67. return 0;
  68. }
  69. static int siena_mdio_read(struct net_device *net_dev,
  70. int prtad, int devad, u16 addr)
  71. {
  72. struct efx_nic *efx = netdev_priv(net_dev);
  73. uint16_t value;
  74. uint32_t status;
  75. int rc;
  76. rc = efx_mcdi_mdio_read(efx, efx->mdio_bus, prtad, devad,
  77. addr, &value, &status);
  78. if (rc)
  79. return rc;
  80. if (status != MC_CMD_MDIO_STATUS_GOOD)
  81. return -EIO;
  82. return (int)value;
  83. }
  84. /* This call is responsible for hooking in the MAC and PHY operations */
  85. static int siena_probe_port(struct efx_nic *efx)
  86. {
  87. int rc;
  88. /* Hook in PHY operations table */
  89. efx->phy_op = &efx_mcdi_phy_ops;
  90. /* Set up MDIO structure for PHY */
  91. efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  92. efx->mdio.mdio_read = siena_mdio_read;
  93. efx->mdio.mdio_write = siena_mdio_write;
  94. /* Fill out MDIO structure, loopback modes, and initial link state */
  95. rc = efx->phy_op->probe(efx);
  96. if (rc != 0)
  97. return rc;
  98. /* Allocate buffer for stats */
  99. rc = efx_nic_alloc_buffer(efx, &efx->stats_buffer,
  100. MC_CMD_MAC_NSTATS * sizeof(u64));
  101. if (rc)
  102. return rc;
  103. netif_dbg(efx, probe, efx->net_dev,
  104. "stats buffer at %llx (virt %p phys %llx)\n",
  105. (u64)efx->stats_buffer.dma_addr,
  106. efx->stats_buffer.addr,
  107. (u64)virt_to_phys(efx->stats_buffer.addr));
  108. efx_mcdi_mac_stats(efx, efx->stats_buffer.dma_addr, 0, 0, 1);
  109. return 0;
  110. }
  111. static void siena_remove_port(struct efx_nic *efx)
  112. {
  113. efx->phy_op->remove(efx);
  114. efx_nic_free_buffer(efx, &efx->stats_buffer);
  115. }
  116. static const struct efx_nic_register_test siena_register_tests[] = {
  117. { FR_AZ_ADR_REGION,
  118. EFX_OWORD32(0x0003FFFF, 0x0003FFFF, 0x0003FFFF, 0x0003FFFF) },
  119. { FR_CZ_USR_EV_CFG,
  120. EFX_OWORD32(0x000103FF, 0x00000000, 0x00000000, 0x00000000) },
  121. { FR_AZ_RX_CFG,
  122. EFX_OWORD32(0xFFFFFFFE, 0xFFFFFFFF, 0x0003FFFF, 0x00000000) },
  123. { FR_AZ_TX_CFG,
  124. EFX_OWORD32(0x7FFF0037, 0xFFFF8000, 0xFFFFFFFF, 0x03FFFFFF) },
  125. { FR_AZ_TX_RESERVED,
  126. EFX_OWORD32(0xFFFEFE80, 0x1FFFFFFF, 0x020000FE, 0x007FFFFF) },
  127. { FR_AZ_SRM_TX_DC_CFG,
  128. EFX_OWORD32(0x001FFFFF, 0x00000000, 0x00000000, 0x00000000) },
  129. { FR_AZ_RX_DC_CFG,
  130. EFX_OWORD32(0x00000003, 0x00000000, 0x00000000, 0x00000000) },
  131. { FR_AZ_RX_DC_PF_WM,
  132. EFX_OWORD32(0x000003FF, 0x00000000, 0x00000000, 0x00000000) },
  133. { FR_BZ_DP_CTRL,
  134. EFX_OWORD32(0x00000FFF, 0x00000000, 0x00000000, 0x00000000) },
  135. { FR_BZ_RX_RSS_TKEY,
  136. EFX_OWORD32(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF) },
  137. { FR_CZ_RX_RSS_IPV6_REG1,
  138. EFX_OWORD32(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF) },
  139. { FR_CZ_RX_RSS_IPV6_REG2,
  140. EFX_OWORD32(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF) },
  141. { FR_CZ_RX_RSS_IPV6_REG3,
  142. EFX_OWORD32(0xFFFFFFFF, 0xFFFFFFFF, 0x00000007, 0x00000000) },
  143. };
  144. static int siena_test_registers(struct efx_nic *efx)
  145. {
  146. return efx_nic_test_registers(efx, siena_register_tests,
  147. ARRAY_SIZE(siena_register_tests));
  148. }
  149. /**************************************************************************
  150. *
  151. * Device reset
  152. *
  153. **************************************************************************
  154. */
  155. static enum reset_type siena_map_reset_reason(enum reset_type reason)
  156. {
  157. return RESET_TYPE_ALL;
  158. }
  159. static int siena_map_reset_flags(u32 *flags)
  160. {
  161. enum {
  162. SIENA_RESET_PORT = (ETH_RESET_DMA | ETH_RESET_FILTER |
  163. ETH_RESET_OFFLOAD | ETH_RESET_MAC |
  164. ETH_RESET_PHY),
  165. SIENA_RESET_MC = (SIENA_RESET_PORT |
  166. ETH_RESET_MGMT << ETH_RESET_SHARED_SHIFT),
  167. };
  168. if ((*flags & SIENA_RESET_MC) == SIENA_RESET_MC) {
  169. *flags &= ~SIENA_RESET_MC;
  170. return RESET_TYPE_WORLD;
  171. }
  172. if ((*flags & SIENA_RESET_PORT) == SIENA_RESET_PORT) {
  173. *flags &= ~SIENA_RESET_PORT;
  174. return RESET_TYPE_ALL;
  175. }
  176. /* no invisible reset implemented */
  177. return -EINVAL;
  178. }
  179. static int siena_reset_hw(struct efx_nic *efx, enum reset_type method)
  180. {
  181. int rc;
  182. /* Recover from a failed assertion pre-reset */
  183. rc = efx_mcdi_handle_assertion(efx);
  184. if (rc)
  185. return rc;
  186. if (method == RESET_TYPE_WORLD)
  187. return efx_mcdi_reset_mc(efx);
  188. else
  189. return efx_mcdi_reset_port(efx);
  190. }
  191. static int siena_probe_nvconfig(struct efx_nic *efx)
  192. {
  193. return efx_mcdi_get_board_cfg(efx, efx->net_dev->perm_addr, NULL);
  194. }
  195. static int siena_probe_nic(struct efx_nic *efx)
  196. {
  197. struct siena_nic_data *nic_data;
  198. bool already_attached = 0;
  199. efx_oword_t reg;
  200. int rc;
  201. /* Allocate storage for hardware specific data */
  202. nic_data = kzalloc(sizeof(struct siena_nic_data), GFP_KERNEL);
  203. if (!nic_data)
  204. return -ENOMEM;
  205. efx->nic_data = nic_data;
  206. if (efx_nic_fpga_ver(efx) != 0) {
  207. netif_err(efx, probe, efx->net_dev,
  208. "Siena FPGA not supported\n");
  209. rc = -ENODEV;
  210. goto fail1;
  211. }
  212. efx_reado(efx, &reg, FR_AZ_CS_DEBUG);
  213. efx->net_dev->dev_id = EFX_OWORD_FIELD(reg, FRF_CZ_CS_PORT_NUM) - 1;
  214. efx_mcdi_init(efx);
  215. /* Recover from a failed assertion before probing */
  216. rc = efx_mcdi_handle_assertion(efx);
  217. if (rc)
  218. goto fail1;
  219. /* Let the BMC know that the driver is now in charge of link and
  220. * filter settings. We must do this before we reset the NIC */
  221. rc = efx_mcdi_drv_attach(efx, true, &already_attached);
  222. if (rc) {
  223. netif_err(efx, probe, efx->net_dev,
  224. "Unable to register driver with MCPU\n");
  225. goto fail2;
  226. }
  227. if (already_attached)
  228. /* Not a fatal error */
  229. netif_err(efx, probe, efx->net_dev,
  230. "Host already registered with MCPU\n");
  231. /* Now we can reset the NIC */
  232. rc = siena_reset_hw(efx, RESET_TYPE_ALL);
  233. if (rc) {
  234. netif_err(efx, probe, efx->net_dev, "failed to reset NIC\n");
  235. goto fail3;
  236. }
  237. siena_init_wol(efx);
  238. /* Allocate memory for INT_KER */
  239. rc = efx_nic_alloc_buffer(efx, &efx->irq_status, sizeof(efx_oword_t));
  240. if (rc)
  241. goto fail4;
  242. BUG_ON(efx->irq_status.dma_addr & 0x0f);
  243. netif_dbg(efx, probe, efx->net_dev,
  244. "INT_KER at %llx (virt %p phys %llx)\n",
  245. (unsigned long long)efx->irq_status.dma_addr,
  246. efx->irq_status.addr,
  247. (unsigned long long)virt_to_phys(efx->irq_status.addr));
  248. /* Read in the non-volatile configuration */
  249. rc = siena_probe_nvconfig(efx);
  250. if (rc == -EINVAL) {
  251. netif_err(efx, probe, efx->net_dev,
  252. "NVRAM is invalid therefore using defaults\n");
  253. efx->phy_type = PHY_TYPE_NONE;
  254. efx->mdio.prtad = MDIO_PRTAD_NONE;
  255. } else if (rc) {
  256. goto fail5;
  257. }
  258. return 0;
  259. fail5:
  260. efx_nic_free_buffer(efx, &efx->irq_status);
  261. fail4:
  262. fail3:
  263. efx_mcdi_drv_attach(efx, false, NULL);
  264. fail2:
  265. fail1:
  266. kfree(efx->nic_data);
  267. return rc;
  268. }
  269. /* This call performs hardware-specific global initialisation, such as
  270. * defining the descriptor cache sizes and number of RSS channels.
  271. * It does not set up any buffers, descriptor rings or event queues.
  272. */
  273. static int siena_init_nic(struct efx_nic *efx)
  274. {
  275. efx_oword_t temp;
  276. int rc;
  277. /* Recover from a failed assertion post-reset */
  278. rc = efx_mcdi_handle_assertion(efx);
  279. if (rc)
  280. return rc;
  281. /* Squash TX of packets of 16 bytes or less */
  282. efx_reado(efx, &temp, FR_AZ_TX_RESERVED);
  283. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TX_FLUSH_MIN_LEN_EN, 1);
  284. efx_writeo(efx, &temp, FR_AZ_TX_RESERVED);
  285. /* Do not enable TX_NO_EOP_DISC_EN, since it limits packets to 16
  286. * descriptors (which is bad).
  287. */
  288. efx_reado(efx, &temp, FR_AZ_TX_CFG);
  289. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_NO_EOP_DISC_EN, 0);
  290. EFX_SET_OWORD_FIELD(temp, FRF_CZ_TX_FILTER_EN_BIT, 1);
  291. efx_writeo(efx, &temp, FR_AZ_TX_CFG);
  292. efx_reado(efx, &temp, FR_AZ_RX_CFG);
  293. EFX_SET_OWORD_FIELD(temp, FRF_BZ_RX_DESC_PUSH_EN, 0);
  294. EFX_SET_OWORD_FIELD(temp, FRF_BZ_RX_INGR_EN, 1);
  295. /* Enable hash insertion. This is broken for the 'Falcon' hash
  296. * if IPv6 hashing is also enabled, so also select Toeplitz
  297. * TCP/IPv4 and IPv4 hashes. */
  298. EFX_SET_OWORD_FIELD(temp, FRF_BZ_RX_HASH_INSRT_HDR, 1);
  299. EFX_SET_OWORD_FIELD(temp, FRF_BZ_RX_HASH_ALG, 1);
  300. EFX_SET_OWORD_FIELD(temp, FRF_BZ_RX_IP_HASH, 1);
  301. efx_writeo(efx, &temp, FR_AZ_RX_CFG);
  302. /* Set hash key for IPv4 */
  303. memcpy(&temp, efx->rx_hash_key, sizeof(temp));
  304. efx_writeo(efx, &temp, FR_BZ_RX_RSS_TKEY);
  305. /* Enable IPv6 RSS */
  306. BUILD_BUG_ON(sizeof(efx->rx_hash_key) <
  307. 2 * sizeof(temp) + FRF_CZ_RX_RSS_IPV6_TKEY_HI_WIDTH / 8 ||
  308. FRF_CZ_RX_RSS_IPV6_TKEY_HI_LBN != 0);
  309. memcpy(&temp, efx->rx_hash_key, sizeof(temp));
  310. efx_writeo(efx, &temp, FR_CZ_RX_RSS_IPV6_REG1);
  311. memcpy(&temp, efx->rx_hash_key + sizeof(temp), sizeof(temp));
  312. efx_writeo(efx, &temp, FR_CZ_RX_RSS_IPV6_REG2);
  313. EFX_POPULATE_OWORD_2(temp, FRF_CZ_RX_RSS_IPV6_THASH_ENABLE, 1,
  314. FRF_CZ_RX_RSS_IPV6_IP_THASH_ENABLE, 1);
  315. memcpy(&temp, efx->rx_hash_key + 2 * sizeof(temp),
  316. FRF_CZ_RX_RSS_IPV6_TKEY_HI_WIDTH / 8);
  317. efx_writeo(efx, &temp, FR_CZ_RX_RSS_IPV6_REG3);
  318. /* Enable event logging */
  319. rc = efx_mcdi_log_ctrl(efx, true, false, 0);
  320. if (rc)
  321. return rc;
  322. /* Set destination of both TX and RX Flush events */
  323. EFX_POPULATE_OWORD_1(temp, FRF_BZ_FLS_EVQ_ID, 0);
  324. efx_writeo(efx, &temp, FR_BZ_DP_CTRL);
  325. EFX_POPULATE_OWORD_1(temp, FRF_CZ_USREV_DIS, 1);
  326. efx_writeo(efx, &temp, FR_CZ_USR_EV_CFG);
  327. efx_nic_init_common(efx);
  328. return 0;
  329. }
  330. static void siena_remove_nic(struct efx_nic *efx)
  331. {
  332. efx_nic_free_buffer(efx, &efx->irq_status);
  333. siena_reset_hw(efx, RESET_TYPE_ALL);
  334. /* Relinquish the device back to the BMC */
  335. if (efx_nic_has_mc(efx))
  336. efx_mcdi_drv_attach(efx, false, NULL);
  337. /* Tear down the private nic state */
  338. kfree(efx->nic_data);
  339. efx->nic_data = NULL;
  340. }
  341. #define STATS_GENERATION_INVALID ((__force __le64)(-1))
  342. static int siena_try_update_nic_stats(struct efx_nic *efx)
  343. {
  344. __le64 *dma_stats;
  345. struct efx_mac_stats *mac_stats;
  346. __le64 generation_start, generation_end;
  347. mac_stats = &efx->mac_stats;
  348. dma_stats = efx->stats_buffer.addr;
  349. generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
  350. if (generation_end == STATS_GENERATION_INVALID)
  351. return 0;
  352. rmb();
  353. #define MAC_STAT(M, D) \
  354. mac_stats->M = le64_to_cpu(dma_stats[MC_CMD_MAC_ ## D])
  355. MAC_STAT(tx_bytes, TX_BYTES);
  356. MAC_STAT(tx_bad_bytes, TX_BAD_BYTES);
  357. mac_stats->tx_good_bytes = (mac_stats->tx_bytes -
  358. mac_stats->tx_bad_bytes);
  359. MAC_STAT(tx_packets, TX_PKTS);
  360. MAC_STAT(tx_bad, TX_BAD_FCS_PKTS);
  361. MAC_STAT(tx_pause, TX_PAUSE_PKTS);
  362. MAC_STAT(tx_control, TX_CONTROL_PKTS);
  363. MAC_STAT(tx_unicast, TX_UNICAST_PKTS);
  364. MAC_STAT(tx_multicast, TX_MULTICAST_PKTS);
  365. MAC_STAT(tx_broadcast, TX_BROADCAST_PKTS);
  366. MAC_STAT(tx_lt64, TX_LT64_PKTS);
  367. MAC_STAT(tx_64, TX_64_PKTS);
  368. MAC_STAT(tx_65_to_127, TX_65_TO_127_PKTS);
  369. MAC_STAT(tx_128_to_255, TX_128_TO_255_PKTS);
  370. MAC_STAT(tx_256_to_511, TX_256_TO_511_PKTS);
  371. MAC_STAT(tx_512_to_1023, TX_512_TO_1023_PKTS);
  372. MAC_STAT(tx_1024_to_15xx, TX_1024_TO_15XX_PKTS);
  373. MAC_STAT(tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS);
  374. MAC_STAT(tx_gtjumbo, TX_GTJUMBO_PKTS);
  375. mac_stats->tx_collision = 0;
  376. MAC_STAT(tx_single_collision, TX_SINGLE_COLLISION_PKTS);
  377. MAC_STAT(tx_multiple_collision, TX_MULTIPLE_COLLISION_PKTS);
  378. MAC_STAT(tx_excessive_collision, TX_EXCESSIVE_COLLISION_PKTS);
  379. MAC_STAT(tx_deferred, TX_DEFERRED_PKTS);
  380. MAC_STAT(tx_late_collision, TX_LATE_COLLISION_PKTS);
  381. mac_stats->tx_collision = (mac_stats->tx_single_collision +
  382. mac_stats->tx_multiple_collision +
  383. mac_stats->tx_excessive_collision +
  384. mac_stats->tx_late_collision);
  385. MAC_STAT(tx_excessive_deferred, TX_EXCESSIVE_DEFERRED_PKTS);
  386. MAC_STAT(tx_non_tcpudp, TX_NON_TCPUDP_PKTS);
  387. MAC_STAT(tx_mac_src_error, TX_MAC_SRC_ERR_PKTS);
  388. MAC_STAT(tx_ip_src_error, TX_IP_SRC_ERR_PKTS);
  389. MAC_STAT(rx_bytes, RX_BYTES);
  390. MAC_STAT(rx_bad_bytes, RX_BAD_BYTES);
  391. mac_stats->rx_good_bytes = (mac_stats->rx_bytes -
  392. mac_stats->rx_bad_bytes);
  393. MAC_STAT(rx_packets, RX_PKTS);
  394. MAC_STAT(rx_good, RX_GOOD_PKTS);
  395. MAC_STAT(rx_bad, RX_BAD_FCS_PKTS);
  396. MAC_STAT(rx_pause, RX_PAUSE_PKTS);
  397. MAC_STAT(rx_control, RX_CONTROL_PKTS);
  398. MAC_STAT(rx_unicast, RX_UNICAST_PKTS);
  399. MAC_STAT(rx_multicast, RX_MULTICAST_PKTS);
  400. MAC_STAT(rx_broadcast, RX_BROADCAST_PKTS);
  401. MAC_STAT(rx_lt64, RX_UNDERSIZE_PKTS);
  402. MAC_STAT(rx_64, RX_64_PKTS);
  403. MAC_STAT(rx_65_to_127, RX_65_TO_127_PKTS);
  404. MAC_STAT(rx_128_to_255, RX_128_TO_255_PKTS);
  405. MAC_STAT(rx_256_to_511, RX_256_TO_511_PKTS);
  406. MAC_STAT(rx_512_to_1023, RX_512_TO_1023_PKTS);
  407. MAC_STAT(rx_1024_to_15xx, RX_1024_TO_15XX_PKTS);
  408. MAC_STAT(rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS);
  409. MAC_STAT(rx_gtjumbo, RX_GTJUMBO_PKTS);
  410. mac_stats->rx_bad_lt64 = 0;
  411. mac_stats->rx_bad_64_to_15xx = 0;
  412. mac_stats->rx_bad_15xx_to_jumbo = 0;
  413. MAC_STAT(rx_bad_gtjumbo, RX_JABBER_PKTS);
  414. MAC_STAT(rx_overflow, RX_OVERFLOW_PKTS);
  415. mac_stats->rx_missed = 0;
  416. MAC_STAT(rx_false_carrier, RX_FALSE_CARRIER_PKTS);
  417. MAC_STAT(rx_symbol_error, RX_SYMBOL_ERROR_PKTS);
  418. MAC_STAT(rx_align_error, RX_ALIGN_ERROR_PKTS);
  419. MAC_STAT(rx_length_error, RX_LENGTH_ERROR_PKTS);
  420. MAC_STAT(rx_internal_error, RX_INTERNAL_ERROR_PKTS);
  421. mac_stats->rx_good_lt64 = 0;
  422. efx->n_rx_nodesc_drop_cnt =
  423. le64_to_cpu(dma_stats[MC_CMD_MAC_RX_NODESC_DROPS]);
  424. #undef MAC_STAT
  425. rmb();
  426. generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
  427. if (generation_end != generation_start)
  428. return -EAGAIN;
  429. return 0;
  430. }
  431. static void siena_update_nic_stats(struct efx_nic *efx)
  432. {
  433. int retry;
  434. /* If we're unlucky enough to read statistics wduring the DMA, wait
  435. * up to 10ms for it to finish (typically takes <500us) */
  436. for (retry = 0; retry < 100; ++retry) {
  437. if (siena_try_update_nic_stats(efx) == 0)
  438. return;
  439. udelay(100);
  440. }
  441. /* Use the old values instead */
  442. }
  443. static void siena_start_nic_stats(struct efx_nic *efx)
  444. {
  445. __le64 *dma_stats = efx->stats_buffer.addr;
  446. dma_stats[MC_CMD_MAC_GENERATION_END] = STATS_GENERATION_INVALID;
  447. efx_mcdi_mac_stats(efx, efx->stats_buffer.dma_addr,
  448. MC_CMD_MAC_NSTATS * sizeof(u64), 1, 0);
  449. }
  450. static void siena_stop_nic_stats(struct efx_nic *efx)
  451. {
  452. efx_mcdi_mac_stats(efx, efx->stats_buffer.dma_addr, 0, 0, 0);
  453. }
  454. /**************************************************************************
  455. *
  456. * Wake on LAN
  457. *
  458. **************************************************************************
  459. */
  460. static void siena_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
  461. {
  462. struct siena_nic_data *nic_data = efx->nic_data;
  463. wol->supported = WAKE_MAGIC;
  464. if (nic_data->wol_filter_id != -1)
  465. wol->wolopts = WAKE_MAGIC;
  466. else
  467. wol->wolopts = 0;
  468. memset(&wol->sopass, 0, sizeof(wol->sopass));
  469. }
  470. static int siena_set_wol(struct efx_nic *efx, u32 type)
  471. {
  472. struct siena_nic_data *nic_data = efx->nic_data;
  473. int rc;
  474. if (type & ~WAKE_MAGIC)
  475. return -EINVAL;
  476. if (type & WAKE_MAGIC) {
  477. if (nic_data->wol_filter_id != -1)
  478. efx_mcdi_wol_filter_remove(efx,
  479. nic_data->wol_filter_id);
  480. rc = efx_mcdi_wol_filter_set_magic(efx, efx->net_dev->dev_addr,
  481. &nic_data->wol_filter_id);
  482. if (rc)
  483. goto fail;
  484. pci_wake_from_d3(efx->pci_dev, true);
  485. } else {
  486. rc = efx_mcdi_wol_filter_reset(efx);
  487. nic_data->wol_filter_id = -1;
  488. pci_wake_from_d3(efx->pci_dev, false);
  489. if (rc)
  490. goto fail;
  491. }
  492. return 0;
  493. fail:
  494. netif_err(efx, hw, efx->net_dev, "%s failed: type=%d rc=%d\n",
  495. __func__, type, rc);
  496. return rc;
  497. }
  498. static void siena_init_wol(struct efx_nic *efx)
  499. {
  500. struct siena_nic_data *nic_data = efx->nic_data;
  501. int rc;
  502. rc = efx_mcdi_wol_filter_get_magic(efx, &nic_data->wol_filter_id);
  503. if (rc != 0) {
  504. /* If it failed, attempt to get into a synchronised
  505. * state with MC by resetting any set WoL filters */
  506. efx_mcdi_wol_filter_reset(efx);
  507. nic_data->wol_filter_id = -1;
  508. } else if (nic_data->wol_filter_id != -1) {
  509. pci_wake_from_d3(efx->pci_dev, true);
  510. }
  511. }
  512. /**************************************************************************
  513. *
  514. * Revision-dependent attributes used by efx.c and nic.c
  515. *
  516. **************************************************************************
  517. */
  518. const struct efx_nic_type siena_a0_nic_type = {
  519. .probe = siena_probe_nic,
  520. .remove = siena_remove_nic,
  521. .init = siena_init_nic,
  522. .fini = efx_port_dummy_op_void,
  523. .monitor = NULL,
  524. .map_reset_reason = siena_map_reset_reason,
  525. .map_reset_flags = siena_map_reset_flags,
  526. .reset = siena_reset_hw,
  527. .probe_port = siena_probe_port,
  528. .remove_port = siena_remove_port,
  529. .prepare_flush = efx_port_dummy_op_void,
  530. .update_stats = siena_update_nic_stats,
  531. .start_stats = siena_start_nic_stats,
  532. .stop_stats = siena_stop_nic_stats,
  533. .set_id_led = efx_mcdi_set_id_led,
  534. .push_irq_moderation = siena_push_irq_moderation,
  535. .push_multicast_hash = siena_push_multicast_hash,
  536. .reconfigure_port = efx_mcdi_phy_reconfigure,
  537. .get_wol = siena_get_wol,
  538. .set_wol = siena_set_wol,
  539. .resume_wol = siena_init_wol,
  540. .test_registers = siena_test_registers,
  541. .test_nvram = efx_mcdi_nvram_test_all,
  542. .default_mac_ops = &efx_mcdi_mac_operations,
  543. .revision = EFX_REV_SIENA_A0,
  544. .mem_map_size = (FR_CZ_MC_TREG_SMEM +
  545. FR_CZ_MC_TREG_SMEM_STEP * FR_CZ_MC_TREG_SMEM_ROWS),
  546. .txd_ptr_tbl_base = FR_BZ_TX_DESC_PTR_TBL,
  547. .rxd_ptr_tbl_base = FR_BZ_RX_DESC_PTR_TBL,
  548. .buf_tbl_base = FR_BZ_BUF_FULL_TBL,
  549. .evq_ptr_tbl_base = FR_BZ_EVQ_PTR_TBL,
  550. .evq_rptr_tbl_base = FR_BZ_EVQ_RPTR,
  551. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  552. .rx_buffer_hash_size = 0x10,
  553. .rx_buffer_padding = 0,
  554. .max_interrupt_mode = EFX_INT_MODE_MSIX,
  555. .phys_addr_channels = 32, /* Hardware limit is 64, but the legacy
  556. * interrupt handler only supports 32
  557. * channels */
  558. .tx_dc_base = 0x88000,
  559. .rx_dc_base = 0x68000,
  560. .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  561. NETIF_F_RXHASH | NETIF_F_NTUPLE),
  562. };