siena.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006-2009 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. EFX_LOG(efx, "stats buffer at %llx (virt %p phys %llx)\n",
  103. (u64)efx->stats_buffer.dma_addr,
  104. efx->stats_buffer.addr,
  105. (u64)virt_to_phys(efx->stats_buffer.addr));
  106. efx_mcdi_mac_stats(efx, efx->stats_buffer.dma_addr, 0, 0, 1);
  107. return 0;
  108. }
  109. void siena_remove_port(struct efx_nic *efx)
  110. {
  111. efx->phy_op->remove(efx);
  112. efx_nic_free_buffer(efx, &efx->stats_buffer);
  113. }
  114. static const struct efx_nic_register_test siena_register_tests[] = {
  115. { FR_AZ_ADR_REGION,
  116. EFX_OWORD32(0x0003FFFF, 0x0003FFFF, 0x0003FFFF, 0x0003FFFF) },
  117. { FR_CZ_USR_EV_CFG,
  118. EFX_OWORD32(0x000103FF, 0x00000000, 0x00000000, 0x00000000) },
  119. { FR_AZ_RX_CFG,
  120. EFX_OWORD32(0xFFFFFFFE, 0xFFFFFFFF, 0x0003FFFF, 0x00000000) },
  121. { FR_AZ_TX_CFG,
  122. EFX_OWORD32(0x7FFF0037, 0xFFFF8000, 0xFFFFFFFF, 0x03FFFFFF) },
  123. { FR_AZ_TX_RESERVED,
  124. EFX_OWORD32(0xFFFEFE80, 0x1FFFFFFF, 0x020000FE, 0x007FFFFF) },
  125. { FR_AZ_SRM_TX_DC_CFG,
  126. EFX_OWORD32(0x001FFFFF, 0x00000000, 0x00000000, 0x00000000) },
  127. { FR_AZ_RX_DC_CFG,
  128. EFX_OWORD32(0x00000003, 0x00000000, 0x00000000, 0x00000000) },
  129. { FR_AZ_RX_DC_PF_WM,
  130. EFX_OWORD32(0x000003FF, 0x00000000, 0x00000000, 0x00000000) },
  131. { FR_BZ_DP_CTRL,
  132. EFX_OWORD32(0x00000FFF, 0x00000000, 0x00000000, 0x00000000) },
  133. { FR_BZ_RX_RSS_TKEY,
  134. EFX_OWORD32(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF) },
  135. { FR_CZ_RX_RSS_IPV6_REG1,
  136. EFX_OWORD32(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF) },
  137. { FR_CZ_RX_RSS_IPV6_REG2,
  138. EFX_OWORD32(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF) },
  139. { FR_CZ_RX_RSS_IPV6_REG3,
  140. EFX_OWORD32(0xFFFFFFFF, 0xFFFFFFFF, 0x00000007, 0x00000000) },
  141. };
  142. static int siena_test_registers(struct efx_nic *efx)
  143. {
  144. return efx_nic_test_registers(efx, siena_register_tests,
  145. ARRAY_SIZE(siena_register_tests));
  146. }
  147. /**************************************************************************
  148. *
  149. * Device reset
  150. *
  151. **************************************************************************
  152. */
  153. static int siena_reset_hw(struct efx_nic *efx, enum reset_type method)
  154. {
  155. int rc;
  156. /* Recover from a failed assertion pre-reset */
  157. rc = efx_mcdi_handle_assertion(efx);
  158. if (rc)
  159. return rc;
  160. if (method == RESET_TYPE_WORLD)
  161. return efx_mcdi_reset_mc(efx);
  162. else
  163. return efx_mcdi_reset_port(efx);
  164. }
  165. static int siena_probe_nvconfig(struct efx_nic *efx)
  166. {
  167. int rc;
  168. rc = efx_mcdi_get_board_cfg(efx, efx->mac_address, NULL);
  169. if (rc)
  170. return rc;
  171. return 0;
  172. }
  173. static int siena_probe_nic(struct efx_nic *efx)
  174. {
  175. struct siena_nic_data *nic_data;
  176. bool already_attached = 0;
  177. int rc;
  178. /* Allocate storage for hardware specific data */
  179. nic_data = kzalloc(sizeof(struct siena_nic_data), GFP_KERNEL);
  180. if (!nic_data)
  181. return -ENOMEM;
  182. efx->nic_data = nic_data;
  183. if (efx_nic_fpga_ver(efx) != 0) {
  184. EFX_ERR(efx, "Siena FPGA not supported\n");
  185. rc = -ENODEV;
  186. goto fail1;
  187. }
  188. efx_mcdi_init(efx);
  189. /* Recover from a failed assertion before probing */
  190. rc = efx_mcdi_handle_assertion(efx);
  191. if (rc)
  192. goto fail1;
  193. rc = efx_mcdi_fwver(efx, &nic_data->fw_version, &nic_data->fw_build);
  194. if (rc) {
  195. EFX_ERR(efx, "Failed to read MCPU firmware version - "
  196. "rc %d\n", rc);
  197. goto fail1; /* MCPU absent? */
  198. }
  199. /* Let the BMC know that the driver is now in charge of link and
  200. * filter settings. We must do this before we reset the NIC */
  201. rc = efx_mcdi_drv_attach(efx, true, &already_attached);
  202. if (rc) {
  203. EFX_ERR(efx, "Unable to register driver with MCPU\n");
  204. goto fail2;
  205. }
  206. if (already_attached)
  207. /* Not a fatal error */
  208. EFX_ERR(efx, "Host already registered with MCPU\n");
  209. /* Now we can reset the NIC */
  210. rc = siena_reset_hw(efx, RESET_TYPE_ALL);
  211. if (rc) {
  212. EFX_ERR(efx, "failed to reset NIC\n");
  213. goto fail3;
  214. }
  215. siena_init_wol(efx);
  216. /* Allocate memory for INT_KER */
  217. rc = efx_nic_alloc_buffer(efx, &efx->irq_status, sizeof(efx_oword_t));
  218. if (rc)
  219. goto fail4;
  220. BUG_ON(efx->irq_status.dma_addr & 0x0f);
  221. EFX_LOG(efx, "INT_KER at %llx (virt %p phys %llx)\n",
  222. (unsigned long long)efx->irq_status.dma_addr,
  223. efx->irq_status.addr,
  224. (unsigned long long)virt_to_phys(efx->irq_status.addr));
  225. /* Read in the non-volatile configuration */
  226. rc = siena_probe_nvconfig(efx);
  227. if (rc == -EINVAL) {
  228. EFX_ERR(efx, "NVRAM is invalid therefore using defaults\n");
  229. efx->phy_type = PHY_TYPE_NONE;
  230. efx->mdio.prtad = MDIO_PRTAD_NONE;
  231. } else if (rc) {
  232. goto fail5;
  233. }
  234. get_random_bytes(&nic_data->ipv6_rss_key,
  235. sizeof(nic_data->ipv6_rss_key));
  236. return 0;
  237. fail5:
  238. efx_nic_free_buffer(efx, &efx->irq_status);
  239. fail4:
  240. fail3:
  241. efx_mcdi_drv_attach(efx, false, NULL);
  242. fail2:
  243. fail1:
  244. kfree(efx->nic_data);
  245. return rc;
  246. }
  247. /* This call performs hardware-specific global initialisation, such as
  248. * defining the descriptor cache sizes and number of RSS channels.
  249. * It does not set up any buffers, descriptor rings or event queues.
  250. */
  251. static int siena_init_nic(struct efx_nic *efx)
  252. {
  253. struct siena_nic_data *nic_data = efx->nic_data;
  254. efx_oword_t temp;
  255. int rc;
  256. /* Recover from a failed assertion post-reset */
  257. rc = efx_mcdi_handle_assertion(efx);
  258. if (rc)
  259. return rc;
  260. /* Squash TX of packets of 16 bytes or less */
  261. efx_reado(efx, &temp, FR_AZ_TX_RESERVED);
  262. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TX_FLUSH_MIN_LEN_EN, 1);
  263. efx_writeo(efx, &temp, FR_AZ_TX_RESERVED);
  264. /* Do not enable TX_NO_EOP_DISC_EN, since it limits packets to 16
  265. * descriptors (which is bad).
  266. */
  267. efx_reado(efx, &temp, FR_AZ_TX_CFG);
  268. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_NO_EOP_DISC_EN, 0);
  269. EFX_SET_OWORD_FIELD(temp, FRF_CZ_TX_FILTER_EN_BIT, 1);
  270. efx_writeo(efx, &temp, FR_AZ_TX_CFG);
  271. efx_reado(efx, &temp, FR_AZ_RX_CFG);
  272. EFX_SET_OWORD_FIELD(temp, FRF_BZ_RX_DESC_PUSH_EN, 0);
  273. EFX_SET_OWORD_FIELD(temp, FRF_BZ_RX_INGR_EN, 1);
  274. efx_writeo(efx, &temp, FR_AZ_RX_CFG);
  275. /* Enable IPv6 RSS */
  276. BUILD_BUG_ON(sizeof(nic_data->ipv6_rss_key) !=
  277. 2 * sizeof(temp) + FRF_CZ_RX_RSS_IPV6_TKEY_HI_WIDTH / 8 ||
  278. FRF_CZ_RX_RSS_IPV6_TKEY_HI_LBN != 0);
  279. memcpy(&temp, nic_data->ipv6_rss_key, sizeof(temp));
  280. efx_writeo(efx, &temp, FR_CZ_RX_RSS_IPV6_REG1);
  281. memcpy(&temp, nic_data->ipv6_rss_key + sizeof(temp), sizeof(temp));
  282. efx_writeo(efx, &temp, FR_CZ_RX_RSS_IPV6_REG2);
  283. EFX_POPULATE_OWORD_2(temp, FRF_CZ_RX_RSS_IPV6_THASH_ENABLE, 1,
  284. FRF_CZ_RX_RSS_IPV6_IP_THASH_ENABLE, 1);
  285. memcpy(&temp, nic_data->ipv6_rss_key + 2 * sizeof(temp),
  286. FRF_CZ_RX_RSS_IPV6_TKEY_HI_WIDTH / 8);
  287. efx_writeo(efx, &temp, FR_CZ_RX_RSS_IPV6_REG3);
  288. if (efx_nic_rx_xoff_thresh >= 0 || efx_nic_rx_xon_thresh >= 0)
  289. /* No MCDI operation has been defined to set thresholds */
  290. EFX_ERR(efx, "ignoring RX flow control thresholds\n");
  291. /* Enable event logging */
  292. rc = efx_mcdi_log_ctrl(efx, true, false, 0);
  293. if (rc)
  294. return rc;
  295. /* Set destination of both TX and RX Flush events */
  296. EFX_POPULATE_OWORD_1(temp, FRF_BZ_FLS_EVQ_ID, 0);
  297. efx_writeo(efx, &temp, FR_BZ_DP_CTRL);
  298. EFX_POPULATE_OWORD_1(temp, FRF_CZ_USREV_DIS, 1);
  299. efx_writeo(efx, &temp, FR_CZ_USR_EV_CFG);
  300. efx_nic_init_common(efx);
  301. return 0;
  302. }
  303. static void siena_remove_nic(struct efx_nic *efx)
  304. {
  305. efx_nic_free_buffer(efx, &efx->irq_status);
  306. siena_reset_hw(efx, RESET_TYPE_ALL);
  307. /* Relinquish the device back to the BMC */
  308. if (efx_nic_has_mc(efx))
  309. efx_mcdi_drv_attach(efx, false, NULL);
  310. /* Tear down the private nic state */
  311. kfree(efx->nic_data);
  312. efx->nic_data = NULL;
  313. }
  314. #define STATS_GENERATION_INVALID ((u64)(-1))
  315. static int siena_try_update_nic_stats(struct efx_nic *efx)
  316. {
  317. u64 *dma_stats;
  318. struct efx_mac_stats *mac_stats;
  319. u64 generation_start;
  320. u64 generation_end;
  321. mac_stats = &efx->mac_stats;
  322. dma_stats = (u64 *)efx->stats_buffer.addr;
  323. generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
  324. if (generation_end == STATS_GENERATION_INVALID)
  325. return 0;
  326. rmb();
  327. #define MAC_STAT(M, D) \
  328. mac_stats->M = dma_stats[MC_CMD_MAC_ ## D]
  329. MAC_STAT(tx_bytes, TX_BYTES);
  330. MAC_STAT(tx_bad_bytes, TX_BAD_BYTES);
  331. mac_stats->tx_good_bytes = (mac_stats->tx_bytes -
  332. mac_stats->tx_bad_bytes);
  333. MAC_STAT(tx_packets, TX_PKTS);
  334. MAC_STAT(tx_bad, TX_BAD_FCS_PKTS);
  335. MAC_STAT(tx_pause, TX_PAUSE_PKTS);
  336. MAC_STAT(tx_control, TX_CONTROL_PKTS);
  337. MAC_STAT(tx_unicast, TX_UNICAST_PKTS);
  338. MAC_STAT(tx_multicast, TX_MULTICAST_PKTS);
  339. MAC_STAT(tx_broadcast, TX_BROADCAST_PKTS);
  340. MAC_STAT(tx_lt64, TX_LT64_PKTS);
  341. MAC_STAT(tx_64, TX_64_PKTS);
  342. MAC_STAT(tx_65_to_127, TX_65_TO_127_PKTS);
  343. MAC_STAT(tx_128_to_255, TX_128_TO_255_PKTS);
  344. MAC_STAT(tx_256_to_511, TX_256_TO_511_PKTS);
  345. MAC_STAT(tx_512_to_1023, TX_512_TO_1023_PKTS);
  346. MAC_STAT(tx_1024_to_15xx, TX_1024_TO_15XX_PKTS);
  347. MAC_STAT(tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS);
  348. MAC_STAT(tx_gtjumbo, TX_GTJUMBO_PKTS);
  349. mac_stats->tx_collision = 0;
  350. MAC_STAT(tx_single_collision, TX_SINGLE_COLLISION_PKTS);
  351. MAC_STAT(tx_multiple_collision, TX_MULTIPLE_COLLISION_PKTS);
  352. MAC_STAT(tx_excessive_collision, TX_EXCESSIVE_COLLISION_PKTS);
  353. MAC_STAT(tx_deferred, TX_DEFERRED_PKTS);
  354. MAC_STAT(tx_late_collision, TX_LATE_COLLISION_PKTS);
  355. mac_stats->tx_collision = (mac_stats->tx_single_collision +
  356. mac_stats->tx_multiple_collision +
  357. mac_stats->tx_excessive_collision +
  358. mac_stats->tx_late_collision);
  359. MAC_STAT(tx_excessive_deferred, TX_EXCESSIVE_DEFERRED_PKTS);
  360. MAC_STAT(tx_non_tcpudp, TX_NON_TCPUDP_PKTS);
  361. MAC_STAT(tx_mac_src_error, TX_MAC_SRC_ERR_PKTS);
  362. MAC_STAT(tx_ip_src_error, TX_IP_SRC_ERR_PKTS);
  363. MAC_STAT(rx_bytes, RX_BYTES);
  364. MAC_STAT(rx_bad_bytes, RX_BAD_BYTES);
  365. mac_stats->rx_good_bytes = (mac_stats->rx_bytes -
  366. mac_stats->rx_bad_bytes);
  367. MAC_STAT(rx_packets, RX_PKTS);
  368. MAC_STAT(rx_good, RX_GOOD_PKTS);
  369. mac_stats->rx_bad = mac_stats->rx_packets - mac_stats->rx_good;
  370. MAC_STAT(rx_pause, RX_PAUSE_PKTS);
  371. MAC_STAT(rx_control, RX_CONTROL_PKTS);
  372. MAC_STAT(rx_unicast, RX_UNICAST_PKTS);
  373. MAC_STAT(rx_multicast, RX_MULTICAST_PKTS);
  374. MAC_STAT(rx_broadcast, RX_BROADCAST_PKTS);
  375. MAC_STAT(rx_lt64, RX_UNDERSIZE_PKTS);
  376. MAC_STAT(rx_64, RX_64_PKTS);
  377. MAC_STAT(rx_65_to_127, RX_65_TO_127_PKTS);
  378. MAC_STAT(rx_128_to_255, RX_128_TO_255_PKTS);
  379. MAC_STAT(rx_256_to_511, RX_256_TO_511_PKTS);
  380. MAC_STAT(rx_512_to_1023, RX_512_TO_1023_PKTS);
  381. MAC_STAT(rx_1024_to_15xx, RX_1024_TO_15XX_PKTS);
  382. MAC_STAT(rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS);
  383. MAC_STAT(rx_gtjumbo, RX_GTJUMBO_PKTS);
  384. mac_stats->rx_bad_lt64 = 0;
  385. mac_stats->rx_bad_64_to_15xx = 0;
  386. mac_stats->rx_bad_15xx_to_jumbo = 0;
  387. MAC_STAT(rx_bad_gtjumbo, RX_JABBER_PKTS);
  388. MAC_STAT(rx_overflow, RX_OVERFLOW_PKTS);
  389. mac_stats->rx_missed = 0;
  390. MAC_STAT(rx_false_carrier, RX_FALSE_CARRIER_PKTS);
  391. MAC_STAT(rx_symbol_error, RX_SYMBOL_ERROR_PKTS);
  392. MAC_STAT(rx_align_error, RX_ALIGN_ERROR_PKTS);
  393. MAC_STAT(rx_length_error, RX_LENGTH_ERROR_PKTS);
  394. MAC_STAT(rx_internal_error, RX_INTERNAL_ERROR_PKTS);
  395. mac_stats->rx_good_lt64 = 0;
  396. efx->n_rx_nodesc_drop_cnt = dma_stats[MC_CMD_MAC_RX_NODESC_DROPS];
  397. #undef MAC_STAT
  398. rmb();
  399. generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
  400. if (generation_end != generation_start)
  401. return -EAGAIN;
  402. return 0;
  403. }
  404. static void siena_update_nic_stats(struct efx_nic *efx)
  405. {
  406. int retry;
  407. /* If we're unlucky enough to read statistics wduring the DMA, wait
  408. * up to 10ms for it to finish (typically takes <500us) */
  409. for (retry = 0; retry < 100; ++retry) {
  410. if (siena_try_update_nic_stats(efx) == 0)
  411. return;
  412. udelay(100);
  413. }
  414. /* Use the old values instead */
  415. }
  416. static void siena_start_nic_stats(struct efx_nic *efx)
  417. {
  418. u64 *dma_stats = (u64 *)efx->stats_buffer.addr;
  419. dma_stats[MC_CMD_MAC_GENERATION_END] = STATS_GENERATION_INVALID;
  420. efx_mcdi_mac_stats(efx, efx->stats_buffer.dma_addr,
  421. MC_CMD_MAC_NSTATS * sizeof(u64), 1, 0);
  422. }
  423. static void siena_stop_nic_stats(struct efx_nic *efx)
  424. {
  425. efx_mcdi_mac_stats(efx, efx->stats_buffer.dma_addr, 0, 0, 0);
  426. }
  427. void siena_print_fwver(struct efx_nic *efx, char *buf, size_t len)
  428. {
  429. struct siena_nic_data *nic_data = efx->nic_data;
  430. snprintf(buf, len, "%u.%u.%u.%u",
  431. (unsigned int)(nic_data->fw_version >> 48),
  432. (unsigned int)(nic_data->fw_version >> 32 & 0xffff),
  433. (unsigned int)(nic_data->fw_version >> 16 & 0xffff),
  434. (unsigned int)(nic_data->fw_version & 0xffff));
  435. }
  436. /**************************************************************************
  437. *
  438. * Wake on LAN
  439. *
  440. **************************************************************************
  441. */
  442. static void siena_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
  443. {
  444. struct siena_nic_data *nic_data = efx->nic_data;
  445. wol->supported = WAKE_MAGIC;
  446. if (nic_data->wol_filter_id != -1)
  447. wol->wolopts = WAKE_MAGIC;
  448. else
  449. wol->wolopts = 0;
  450. memset(&wol->sopass, 0, sizeof(wol->sopass));
  451. }
  452. static int siena_set_wol(struct efx_nic *efx, u32 type)
  453. {
  454. struct siena_nic_data *nic_data = efx->nic_data;
  455. int rc;
  456. if (type & ~WAKE_MAGIC)
  457. return -EINVAL;
  458. if (type & WAKE_MAGIC) {
  459. if (nic_data->wol_filter_id != -1)
  460. efx_mcdi_wol_filter_remove(efx,
  461. nic_data->wol_filter_id);
  462. rc = efx_mcdi_wol_filter_set_magic(efx, efx->mac_address,
  463. &nic_data->wol_filter_id);
  464. if (rc)
  465. goto fail;
  466. pci_wake_from_d3(efx->pci_dev, true);
  467. } else {
  468. rc = efx_mcdi_wol_filter_reset(efx);
  469. nic_data->wol_filter_id = -1;
  470. pci_wake_from_d3(efx->pci_dev, false);
  471. if (rc)
  472. goto fail;
  473. }
  474. return 0;
  475. fail:
  476. EFX_ERR(efx, "%s failed: type=%d rc=%d\n", __func__, type, rc);
  477. return rc;
  478. }
  479. static void siena_init_wol(struct efx_nic *efx)
  480. {
  481. struct siena_nic_data *nic_data = efx->nic_data;
  482. int rc;
  483. rc = efx_mcdi_wol_filter_get_magic(efx, &nic_data->wol_filter_id);
  484. if (rc != 0) {
  485. /* If it failed, attempt to get into a synchronised
  486. * state with MC by resetting any set WoL filters */
  487. efx_mcdi_wol_filter_reset(efx);
  488. nic_data->wol_filter_id = -1;
  489. } else if (nic_data->wol_filter_id != -1) {
  490. pci_wake_from_d3(efx->pci_dev, true);
  491. }
  492. }
  493. /**************************************************************************
  494. *
  495. * Revision-dependent attributes used by efx.c and nic.c
  496. *
  497. **************************************************************************
  498. */
  499. struct efx_nic_type siena_a0_nic_type = {
  500. .probe = siena_probe_nic,
  501. .remove = siena_remove_nic,
  502. .init = siena_init_nic,
  503. .fini = efx_port_dummy_op_void,
  504. .monitor = NULL,
  505. .reset = siena_reset_hw,
  506. .probe_port = siena_probe_port,
  507. .remove_port = siena_remove_port,
  508. .prepare_flush = efx_port_dummy_op_void,
  509. .update_stats = siena_update_nic_stats,
  510. .start_stats = siena_start_nic_stats,
  511. .stop_stats = siena_stop_nic_stats,
  512. .set_id_led = efx_mcdi_set_id_led,
  513. .push_irq_moderation = siena_push_irq_moderation,
  514. .push_multicast_hash = siena_push_multicast_hash,
  515. .reconfigure_port = efx_mcdi_phy_reconfigure,
  516. .get_wol = siena_get_wol,
  517. .set_wol = siena_set_wol,
  518. .resume_wol = siena_init_wol,
  519. .test_registers = siena_test_registers,
  520. .test_nvram = efx_mcdi_nvram_test_all,
  521. .default_mac_ops = &efx_mcdi_mac_operations,
  522. .revision = EFX_REV_SIENA_A0,
  523. .mem_map_size = (FR_CZ_MC_TREG_SMEM +
  524. FR_CZ_MC_TREG_SMEM_STEP * FR_CZ_MC_TREG_SMEM_ROWS),
  525. .txd_ptr_tbl_base = FR_BZ_TX_DESC_PTR_TBL,
  526. .rxd_ptr_tbl_base = FR_BZ_RX_DESC_PTR_TBL,
  527. .buf_tbl_base = FR_BZ_BUF_FULL_TBL,
  528. .evq_ptr_tbl_base = FR_BZ_EVQ_PTR_TBL,
  529. .evq_rptr_tbl_base = FR_BZ_EVQ_RPTR,
  530. .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH),
  531. .rx_buffer_padding = 0,
  532. .max_interrupt_mode = EFX_INT_MODE_MSIX,
  533. .phys_addr_channels = 32, /* Hardware limit is 64, but the legacy
  534. * interrupt handler only supports 32
  535. * channels */
  536. .tx_dc_base = 0x88000,
  537. .rx_dc_base = 0x68000,
  538. .offload_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM,
  539. .reset_world_flags = ETH_RESET_MGMT << ETH_RESET_SHARED_SHIFT,
  540. };