siena.c 19 KB

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