siena.c 17 KB

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