siena.c 21 KB

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