Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | * Driver for Solarflare Solarstorm network controllers and boards |
Ben Hutchings | 0a6f40c | 2011-02-25 00:01:34 +0000 | [diff] [blame] | 3 | * Copyright 2008-2011 Solarflare Communications Inc. |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published |
| 7 | * by the Free Software Foundation, incorporated herein by reference. |
| 8 | */ |
| 9 | |
| 10 | #include <linux/delay.h> |
| 11 | #include "net_driver.h" |
| 12 | #include "nic.h" |
| 13 | #include "io.h" |
Ben Hutchings | 8b8a95a | 2012-09-18 01:57:07 +0100 | [diff] [blame] | 14 | #include "farch_regs.h" |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 15 | #include "mcdi_pcol.h" |
| 16 | #include "phy.h" |
| 17 | |
| 18 | /************************************************************************** |
| 19 | * |
| 20 | * Management-Controller-to-Driver Interface |
| 21 | * |
| 22 | ************************************************************************** |
| 23 | */ |
| 24 | |
Ben Hutchings | ebf98e7 | 2012-12-01 02:21:17 +0000 | [diff] [blame] | 25 | #define MCDI_RPC_TIMEOUT (10 * HZ) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 26 | |
Ben Hutchings | 3f713bf | 2011-12-20 23:39:31 +0000 | [diff] [blame] | 27 | /* A reboot/assertion causes the MCDI status word to be set after the |
| 28 | * command word is set or a REBOOT event is sent. If we notice a reboot |
| 29 | * via these mechanisms then wait 10ms for the status word to be set. */ |
| 30 | #define MCDI_STATUS_DELAY_US 100 |
| 31 | #define MCDI_STATUS_DELAY_COUNT 100 |
| 32 | #define MCDI_STATUS_SLEEP_MS \ |
| 33 | (MCDI_STATUS_DELAY_US * MCDI_STATUS_DELAY_COUNT / 1000) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 34 | |
| 35 | #define SEQ_MASK \ |
| 36 | EFX_MASK32(EFX_WIDTH(MCDI_HEADER_SEQ)) |
| 37 | |
| 38 | static inline struct efx_mcdi_iface *efx_mcdi(struct efx_nic *efx) |
| 39 | { |
Ben Hutchings | f3ad500 | 2012-09-18 02:33:56 +0100 | [diff] [blame] | 40 | EFX_BUG_ON_PARANOID(!efx->mcdi); |
| 41 | return &efx->mcdi->iface; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Ben Hutchings | f073dde | 2012-09-18 02:33:55 +0100 | [diff] [blame] | 44 | int efx_mcdi_init(struct efx_nic *efx) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 45 | { |
| 46 | struct efx_mcdi_iface *mcdi; |
| 47 | |
Ben Hutchings | f3ad500 | 2012-09-18 02:33:56 +0100 | [diff] [blame] | 48 | efx->mcdi = kzalloc(sizeof(*efx->mcdi), GFP_KERNEL); |
| 49 | if (!efx->mcdi) |
| 50 | return -ENOMEM; |
| 51 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 52 | mcdi = efx_mcdi(efx); |
| 53 | init_waitqueue_head(&mcdi->wq); |
| 54 | spin_lock_init(&mcdi->iface_lock); |
| 55 | atomic_set(&mcdi->state, MCDI_STATE_QUIESCENT); |
| 56 | mcdi->mode = MCDI_MODE_POLL; |
| 57 | |
| 58 | (void) efx_mcdi_poll_reboot(efx); |
Ben Hutchings | f073dde | 2012-09-18 02:33:55 +0100 | [diff] [blame] | 59 | |
| 60 | /* Recover from a failed assertion before probing */ |
| 61 | return efx_mcdi_handle_assertion(efx); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Ben Hutchings | f3ad500 | 2012-09-18 02:33:56 +0100 | [diff] [blame] | 64 | void efx_mcdi_fini(struct efx_nic *efx) |
| 65 | { |
| 66 | BUG_ON(efx->mcdi && |
| 67 | atomic_read(&efx->mcdi->iface.state) != MCDI_STATE_QUIESCENT); |
| 68 | kfree(efx->mcdi); |
| 69 | } |
| 70 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 71 | static void efx_mcdi_copyin(struct efx_nic *efx, unsigned cmd, |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 72 | const efx_dword_t *inbuf, size_t inlen) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 73 | { |
| 74 | struct efx_mcdi_iface *mcdi = efx_mcdi(efx); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 75 | efx_dword_t hdr; |
| 76 | u32 xflags, seqno; |
| 77 | |
| 78 | BUG_ON(atomic_read(&mcdi->state) == MCDI_STATE_QUIESCENT); |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 79 | BUG_ON(inlen > MCDI_CTL_SDU_LEN_MAX_V1); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 80 | |
| 81 | seqno = mcdi->seqno & SEQ_MASK; |
| 82 | xflags = 0; |
| 83 | if (mcdi->mode == MCDI_MODE_EVENTS) |
| 84 | xflags |= MCDI_HEADER_XFLAGS_EVREQ; |
| 85 | |
| 86 | EFX_POPULATE_DWORD_6(hdr, |
| 87 | MCDI_HEADER_RESPONSE, 0, |
| 88 | MCDI_HEADER_RESYNC, 1, |
| 89 | MCDI_HEADER_CODE, cmd, |
| 90 | MCDI_HEADER_DATALEN, inlen, |
| 91 | MCDI_HEADER_SEQ, seqno, |
| 92 | MCDI_HEADER_XFLAGS, xflags); |
| 93 | |
Ben Hutchings | f3ad500 | 2012-09-18 02:33:56 +0100 | [diff] [blame] | 94 | efx->type->mcdi_request(efx, &hdr, 4, inbuf, inlen); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 97 | static void |
| 98 | efx_mcdi_copyout(struct efx_nic *efx, efx_dword_t *outbuf, size_t outlen) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 99 | { |
| 100 | struct efx_mcdi_iface *mcdi = efx_mcdi(efx); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 101 | |
| 102 | BUG_ON(atomic_read(&mcdi->state) == MCDI_STATE_QUIESCENT); |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 103 | BUG_ON(outlen > MCDI_CTL_SDU_LEN_MAX_V1); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 104 | |
Ben Hutchings | f3ad500 | 2012-09-18 02:33:56 +0100 | [diff] [blame] | 105 | efx->type->mcdi_read_response(efx, outbuf, 4, outlen); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Ben Hutchings | 5bc283e | 2012-10-08 21:43:00 +0100 | [diff] [blame^] | 108 | static int efx_mcdi_errno(unsigned int mcdi_err) |
| 109 | { |
| 110 | switch (mcdi_err) { |
| 111 | case 0: |
| 112 | return 0; |
| 113 | #define TRANSLATE_ERROR(name) \ |
| 114 | case MC_CMD_ERR_ ## name: \ |
| 115 | return -name; |
| 116 | TRANSLATE_ERROR(ENOENT); |
| 117 | TRANSLATE_ERROR(EINTR); |
| 118 | TRANSLATE_ERROR(EACCES); |
| 119 | TRANSLATE_ERROR(EBUSY); |
| 120 | TRANSLATE_ERROR(EINVAL); |
| 121 | TRANSLATE_ERROR(EDEADLK); |
| 122 | TRANSLATE_ERROR(ENOSYS); |
| 123 | TRANSLATE_ERROR(ETIME); |
| 124 | #undef TRANSLATE_ERROR |
| 125 | default: |
| 126 | return -EIO; |
| 127 | } |
| 128 | } |
| 129 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 130 | static int efx_mcdi_poll(struct efx_nic *efx) |
| 131 | { |
| 132 | struct efx_mcdi_iface *mcdi = efx_mcdi(efx); |
Ben Hutchings | ebf98e7 | 2012-12-01 02:21:17 +0000 | [diff] [blame] | 133 | unsigned long time, finish; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 134 | unsigned int respseq, respcmd, error; |
Ben Hutchings | 5bc283e | 2012-10-08 21:43:00 +0100 | [diff] [blame^] | 135 | unsigned int spins; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 136 | efx_dword_t reg; |
Ben Hutchings | 5bc283e | 2012-10-08 21:43:00 +0100 | [diff] [blame^] | 137 | int rc; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 138 | |
| 139 | /* Check for a reboot atomically with respect to efx_mcdi_copyout() */ |
Ben Hutchings | 5bc283e | 2012-10-08 21:43:00 +0100 | [diff] [blame^] | 140 | rc = efx_mcdi_poll_reboot(efx); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 141 | if (rc) |
| 142 | goto out; |
| 143 | |
| 144 | /* Poll for completion. Poll quickly (once a us) for the 1st jiffy, |
| 145 | * because generally mcdi responses are fast. After that, back off |
| 146 | * and poll once a jiffy (approximately) |
| 147 | */ |
| 148 | spins = TICK_USEC; |
Ben Hutchings | ebf98e7 | 2012-12-01 02:21:17 +0000 | [diff] [blame] | 149 | finish = jiffies + MCDI_RPC_TIMEOUT; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 150 | |
| 151 | while (1) { |
| 152 | if (spins != 0) { |
| 153 | --spins; |
| 154 | udelay(1); |
Ben Hutchings | 55029c1 | 2010-01-13 04:34:25 +0000 | [diff] [blame] | 155 | } else { |
| 156 | schedule_timeout_uninterruptible(1); |
| 157 | } |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 158 | |
Ben Hutchings | ebf98e7 | 2012-12-01 02:21:17 +0000 | [diff] [blame] | 159 | time = jiffies; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 160 | |
Ben Hutchings | 86c432c | 2011-09-01 12:09:29 +0000 | [diff] [blame] | 161 | rmb(); |
Ben Hutchings | f3ad500 | 2012-09-18 02:33:56 +0100 | [diff] [blame] | 162 | if (efx->type->mcdi_poll_response(efx)) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 163 | break; |
| 164 | |
Ben Hutchings | ebf98e7 | 2012-12-01 02:21:17 +0000 | [diff] [blame] | 165 | if (time_after(time, finish)) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 166 | return -ETIMEDOUT; |
| 167 | } |
| 168 | |
Ben Hutchings | f3ad500 | 2012-09-18 02:33:56 +0100 | [diff] [blame] | 169 | efx->type->mcdi_read_response(efx, ®, 0, 4); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 170 | mcdi->resplen = EFX_DWORD_FIELD(reg, MCDI_HEADER_DATALEN); |
| 171 | respseq = EFX_DWORD_FIELD(reg, MCDI_HEADER_SEQ); |
| 172 | respcmd = EFX_DWORD_FIELD(reg, MCDI_HEADER_CODE); |
| 173 | error = EFX_DWORD_FIELD(reg, MCDI_HEADER_ERROR); |
| 174 | |
| 175 | if (error && mcdi->resplen == 0) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 176 | netif_err(efx, hw, efx->net_dev, "MC rebooted\n"); |
Ben Hutchings | 5bc283e | 2012-10-08 21:43:00 +0100 | [diff] [blame^] | 177 | rc = -EIO; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 178 | } else if ((respseq ^ mcdi->seqno) & SEQ_MASK) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 179 | netif_err(efx, hw, efx->net_dev, |
| 180 | "MC response mismatch tx seq 0x%x rx seq 0x%x\n", |
| 181 | respseq, mcdi->seqno); |
Ben Hutchings | 5bc283e | 2012-10-08 21:43:00 +0100 | [diff] [blame^] | 182 | rc = -EIO; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 183 | } else if (error) { |
Ben Hutchings | f3ad500 | 2012-09-18 02:33:56 +0100 | [diff] [blame] | 184 | efx->type->mcdi_read_response(efx, ®, 4, 4); |
Ben Hutchings | 5bc283e | 2012-10-08 21:43:00 +0100 | [diff] [blame^] | 185 | rc = efx_mcdi_errno(EFX_DWORD_FIELD(reg, EFX_DWORD_0)); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 186 | } else |
| 187 | rc = 0; |
| 188 | |
| 189 | out: |
| 190 | mcdi->resprc = rc; |
| 191 | if (rc) |
| 192 | mcdi->resplen = 0; |
| 193 | |
| 194 | /* Return rc=0 like wait_event_timeout() */ |
| 195 | return 0; |
| 196 | } |
| 197 | |
Ben Hutchings | 876be08 | 2012-10-01 20:58:35 +0100 | [diff] [blame] | 198 | /* Test and clear MC-rebooted flag for this port/function; reset |
| 199 | * software state as necessary. |
| 200 | */ |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 201 | int efx_mcdi_poll_reboot(struct efx_nic *efx) |
| 202 | { |
Ben Hutchings | f3ad500 | 2012-09-18 02:33:56 +0100 | [diff] [blame] | 203 | int rc; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 204 | |
Ben Hutchings | f3ad500 | 2012-09-18 02:33:56 +0100 | [diff] [blame] | 205 | if (!efx->mcdi) |
| 206 | return 0; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 207 | |
Ben Hutchings | f3ad500 | 2012-09-18 02:33:56 +0100 | [diff] [blame] | 208 | rc = efx->type->mcdi_poll_reboot(efx); |
| 209 | if (!rc) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 210 | return 0; |
| 211 | |
Ben Hutchings | 876be08 | 2012-10-01 20:58:35 +0100 | [diff] [blame] | 212 | /* MAC statistics have been cleared on the NIC; clear our copy |
| 213 | * so that efx_update_diff_stat() can continue to work. |
| 214 | */ |
| 215 | memset(&efx->mac_stats, 0, sizeof(efx->mac_stats)); |
| 216 | |
Ben Hutchings | f3ad500 | 2012-09-18 02:33:56 +0100 | [diff] [blame] | 217 | return rc; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | static void efx_mcdi_acquire(struct efx_mcdi_iface *mcdi) |
| 221 | { |
| 222 | /* Wait until the interface becomes QUIESCENT and we win the race |
| 223 | * to mark it RUNNING. */ |
| 224 | wait_event(mcdi->wq, |
| 225 | atomic_cmpxchg(&mcdi->state, |
| 226 | MCDI_STATE_QUIESCENT, |
| 227 | MCDI_STATE_RUNNING) |
| 228 | == MCDI_STATE_QUIESCENT); |
| 229 | } |
| 230 | |
| 231 | static int efx_mcdi_await_completion(struct efx_nic *efx) |
| 232 | { |
| 233 | struct efx_mcdi_iface *mcdi = efx_mcdi(efx); |
| 234 | |
| 235 | if (wait_event_timeout( |
| 236 | mcdi->wq, |
| 237 | atomic_read(&mcdi->state) == MCDI_STATE_COMPLETED, |
Ben Hutchings | ebf98e7 | 2012-12-01 02:21:17 +0000 | [diff] [blame] | 238 | MCDI_RPC_TIMEOUT) == 0) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 239 | return -ETIMEDOUT; |
| 240 | |
| 241 | /* Check if efx_mcdi_set_mode() switched us back to polled completions. |
| 242 | * In which case, poll for completions directly. If efx_mcdi_ev_cpl() |
| 243 | * completed the request first, then we'll just end up completing the |
| 244 | * request again, which is safe. |
| 245 | * |
| 246 | * We need an smp_rmb() to synchronise with efx_mcdi_mode_poll(), which |
| 247 | * wait_event_timeout() implicitly provides. |
| 248 | */ |
| 249 | if (mcdi->mode == MCDI_MODE_POLL) |
| 250 | return efx_mcdi_poll(efx); |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | static bool efx_mcdi_complete(struct efx_mcdi_iface *mcdi) |
| 256 | { |
| 257 | /* If the interface is RUNNING, then move to COMPLETED and wake any |
| 258 | * waiters. If the interface isn't in RUNNING then we've received a |
| 259 | * duplicate completion after we've already transitioned back to |
| 260 | * QUIESCENT. [A subsequent invocation would increment seqno, so would |
| 261 | * have failed the seqno check]. |
| 262 | */ |
| 263 | if (atomic_cmpxchg(&mcdi->state, |
| 264 | MCDI_STATE_RUNNING, |
| 265 | MCDI_STATE_COMPLETED) == MCDI_STATE_RUNNING) { |
| 266 | wake_up(&mcdi->wq); |
| 267 | return true; |
| 268 | } |
| 269 | |
| 270 | return false; |
| 271 | } |
| 272 | |
| 273 | static void efx_mcdi_release(struct efx_mcdi_iface *mcdi) |
| 274 | { |
| 275 | atomic_set(&mcdi->state, MCDI_STATE_QUIESCENT); |
| 276 | wake_up(&mcdi->wq); |
| 277 | } |
| 278 | |
| 279 | static void efx_mcdi_ev_cpl(struct efx_nic *efx, unsigned int seqno, |
Ben Hutchings | 5bc283e | 2012-10-08 21:43:00 +0100 | [diff] [blame^] | 280 | unsigned int datalen, unsigned int mcdi_err) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 281 | { |
| 282 | struct efx_mcdi_iface *mcdi = efx_mcdi(efx); |
| 283 | bool wake = false; |
| 284 | |
| 285 | spin_lock(&mcdi->iface_lock); |
| 286 | |
| 287 | if ((seqno ^ mcdi->seqno) & SEQ_MASK) { |
| 288 | if (mcdi->credits) |
| 289 | /* The request has been cancelled */ |
| 290 | --mcdi->credits; |
| 291 | else |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 292 | netif_err(efx, hw, efx->net_dev, |
| 293 | "MC response mismatch tx seq 0x%x rx " |
| 294 | "seq 0x%x\n", seqno, mcdi->seqno); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 295 | } else { |
Ben Hutchings | 5bc283e | 2012-10-08 21:43:00 +0100 | [diff] [blame^] | 296 | mcdi->resprc = efx_mcdi_errno(mcdi_err); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 297 | mcdi->resplen = datalen; |
| 298 | |
| 299 | wake = true; |
| 300 | } |
| 301 | |
| 302 | spin_unlock(&mcdi->iface_lock); |
| 303 | |
| 304 | if (wake) |
| 305 | efx_mcdi_complete(mcdi); |
| 306 | } |
| 307 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 308 | int efx_mcdi_rpc(struct efx_nic *efx, unsigned cmd, |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 309 | const efx_dword_t *inbuf, size_t inlen, |
| 310 | efx_dword_t *outbuf, size_t outlen, |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 311 | size_t *outlen_actual) |
| 312 | { |
Stuart Hodgson | c3cba72 | 2012-07-16 17:40:47 +0100 | [diff] [blame] | 313 | efx_mcdi_rpc_start(efx, cmd, inbuf, inlen); |
| 314 | return efx_mcdi_rpc_finish(efx, cmd, inlen, |
| 315 | outbuf, outlen, outlen_actual); |
| 316 | } |
| 317 | |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 318 | void efx_mcdi_rpc_start(struct efx_nic *efx, unsigned cmd, |
| 319 | const efx_dword_t *inbuf, size_t inlen) |
Stuart Hodgson | c3cba72 | 2012-07-16 17:40:47 +0100 | [diff] [blame] | 320 | { |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 321 | struct efx_mcdi_iface *mcdi = efx_mcdi(efx); |
Stuart Hodgson | c3cba72 | 2012-07-16 17:40:47 +0100 | [diff] [blame] | 322 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 323 | efx_mcdi_acquire(mcdi); |
| 324 | |
| 325 | /* Serialise with efx_mcdi_ev_cpl() and efx_mcdi_ev_death() */ |
| 326 | spin_lock_bh(&mcdi->iface_lock); |
| 327 | ++mcdi->seqno; |
| 328 | spin_unlock_bh(&mcdi->iface_lock); |
| 329 | |
| 330 | efx_mcdi_copyin(efx, cmd, inbuf, inlen); |
Stuart Hodgson | c3cba72 | 2012-07-16 17:40:47 +0100 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | int efx_mcdi_rpc_finish(struct efx_nic *efx, unsigned cmd, size_t inlen, |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 334 | efx_dword_t *outbuf, size_t outlen, |
| 335 | size_t *outlen_actual) |
Stuart Hodgson | c3cba72 | 2012-07-16 17:40:47 +0100 | [diff] [blame] | 336 | { |
| 337 | struct efx_mcdi_iface *mcdi = efx_mcdi(efx); |
| 338 | int rc; |
| 339 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 340 | if (mcdi->mode == MCDI_MODE_POLL) |
| 341 | rc = efx_mcdi_poll(efx); |
| 342 | else |
| 343 | rc = efx_mcdi_await_completion(efx); |
| 344 | |
| 345 | if (rc != 0) { |
| 346 | /* Close the race with efx_mcdi_ev_cpl() executing just too late |
| 347 | * and completing a request we've just cancelled, by ensuring |
| 348 | * that the seqno check therein fails. |
| 349 | */ |
| 350 | spin_lock_bh(&mcdi->iface_lock); |
| 351 | ++mcdi->seqno; |
| 352 | ++mcdi->credits; |
| 353 | spin_unlock_bh(&mcdi->iface_lock); |
| 354 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 355 | netif_err(efx, hw, efx->net_dev, |
| 356 | "MC command 0x%x inlen %d mode %d timed out\n", |
| 357 | cmd, (int)inlen, mcdi->mode); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 358 | } else { |
| 359 | size_t resplen; |
| 360 | |
| 361 | /* At the very least we need a memory barrier here to ensure |
| 362 | * we pick up changes from efx_mcdi_ev_cpl(). Protect against |
| 363 | * a spurious efx_mcdi_ev_cpl() running concurrently by |
| 364 | * acquiring the iface_lock. */ |
| 365 | spin_lock_bh(&mcdi->iface_lock); |
Ben Hutchings | 5bc283e | 2012-10-08 21:43:00 +0100 | [diff] [blame^] | 366 | rc = mcdi->resprc; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 367 | resplen = mcdi->resplen; |
| 368 | spin_unlock_bh(&mcdi->iface_lock); |
| 369 | |
Ben Hutchings | 5bc283e | 2012-10-08 21:43:00 +0100 | [diff] [blame^] | 370 | BUG_ON(rc > 0); |
| 371 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 372 | if (rc == 0) { |
| 373 | efx_mcdi_copyout(efx, outbuf, |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 374 | min(outlen, mcdi->resplen)); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 375 | if (outlen_actual != NULL) |
| 376 | *outlen_actual = resplen; |
| 377 | } else if (cmd == MC_CMD_REBOOT && rc == -EIO) |
| 378 | ; /* Don't reset if MC_CMD_REBOOT returns EIO */ |
| 379 | else if (rc == -EIO || rc == -EINTR) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 380 | netif_err(efx, hw, efx->net_dev, "MC fatal error %d\n", |
| 381 | -rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 382 | efx_schedule_reset(efx, RESET_TYPE_MC_FAILURE); |
| 383 | } else |
Ben Hutchings | f18ca36 | 2010-12-02 13:46:09 +0000 | [diff] [blame] | 384 | netif_dbg(efx, hw, efx->net_dev, |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 385 | "MC command 0x%x inlen %d failed rc=%d\n", |
| 386 | cmd, (int)inlen, -rc); |
Ben Hutchings | 3f713bf | 2011-12-20 23:39:31 +0000 | [diff] [blame] | 387 | |
| 388 | if (rc == -EIO || rc == -EINTR) { |
| 389 | msleep(MCDI_STATUS_SLEEP_MS); |
| 390 | efx_mcdi_poll_reboot(efx); |
| 391 | } |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | efx_mcdi_release(mcdi); |
| 395 | return rc; |
| 396 | } |
| 397 | |
| 398 | void efx_mcdi_mode_poll(struct efx_nic *efx) |
| 399 | { |
| 400 | struct efx_mcdi_iface *mcdi; |
| 401 | |
Ben Hutchings | f3ad500 | 2012-09-18 02:33:56 +0100 | [diff] [blame] | 402 | if (!efx->mcdi) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 403 | return; |
| 404 | |
| 405 | mcdi = efx_mcdi(efx); |
| 406 | if (mcdi->mode == MCDI_MODE_POLL) |
| 407 | return; |
| 408 | |
| 409 | /* We can switch from event completion to polled completion, because |
| 410 | * mcdi requests are always completed in shared memory. We do this by |
| 411 | * switching the mode to POLL'd then completing the request. |
| 412 | * efx_mcdi_await_completion() will then call efx_mcdi_poll(). |
| 413 | * |
| 414 | * We need an smp_wmb() to synchronise with efx_mcdi_await_completion(), |
| 415 | * which efx_mcdi_complete() provides for us. |
| 416 | */ |
| 417 | mcdi->mode = MCDI_MODE_POLL; |
| 418 | |
| 419 | efx_mcdi_complete(mcdi); |
| 420 | } |
| 421 | |
| 422 | void efx_mcdi_mode_event(struct efx_nic *efx) |
| 423 | { |
| 424 | struct efx_mcdi_iface *mcdi; |
| 425 | |
Ben Hutchings | f3ad500 | 2012-09-18 02:33:56 +0100 | [diff] [blame] | 426 | if (!efx->mcdi) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 427 | return; |
| 428 | |
| 429 | mcdi = efx_mcdi(efx); |
| 430 | |
| 431 | if (mcdi->mode == MCDI_MODE_EVENTS) |
| 432 | return; |
| 433 | |
| 434 | /* We can't switch from polled to event completion in the middle of a |
| 435 | * request, because the completion method is specified in the request. |
| 436 | * So acquire the interface to serialise the requestors. We don't need |
| 437 | * to acquire the iface_lock to change the mode here, but we do need a |
| 438 | * write memory barrier ensure that efx_mcdi_rpc() sees it, which |
| 439 | * efx_mcdi_acquire() provides. |
| 440 | */ |
| 441 | efx_mcdi_acquire(mcdi); |
| 442 | mcdi->mode = MCDI_MODE_EVENTS; |
| 443 | efx_mcdi_release(mcdi); |
| 444 | } |
| 445 | |
| 446 | static void efx_mcdi_ev_death(struct efx_nic *efx, int rc) |
| 447 | { |
| 448 | struct efx_mcdi_iface *mcdi = efx_mcdi(efx); |
| 449 | |
| 450 | /* If there is an outstanding MCDI request, it has been terminated |
| 451 | * either by a BADASSERT or REBOOT event. If the mcdi interface is |
| 452 | * in polled mode, then do nothing because the MC reboot handler will |
| 453 | * set the header correctly. However, if the mcdi interface is waiting |
| 454 | * for a CMDDONE event it won't receive it [and since all MCDI events |
| 455 | * are sent to the same queue, we can't be racing with |
| 456 | * efx_mcdi_ev_cpl()] |
| 457 | * |
| 458 | * There's a race here with efx_mcdi_rpc(), because we might receive |
| 459 | * a REBOOT event *before* the request has been copied out. In polled |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 460 | * mode (during startup) this is irrelevant, because efx_mcdi_complete() |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 461 | * is ignored. In event mode, this condition is just an edge-case of |
| 462 | * receiving a REBOOT event after posting the MCDI request. Did the mc |
| 463 | * reboot before or after the copyout? The best we can do always is |
| 464 | * just return failure. |
| 465 | */ |
| 466 | spin_lock(&mcdi->iface_lock); |
| 467 | if (efx_mcdi_complete(mcdi)) { |
| 468 | if (mcdi->mode == MCDI_MODE_EVENTS) { |
| 469 | mcdi->resprc = rc; |
| 470 | mcdi->resplen = 0; |
Steve Hodgson | 18e3ee2 | 2010-12-02 13:46:55 +0000 | [diff] [blame] | 471 | ++mcdi->credits; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 472 | } |
Ben Hutchings | 3f713bf | 2011-12-20 23:39:31 +0000 | [diff] [blame] | 473 | } else { |
| 474 | int count; |
| 475 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 476 | /* Nobody was waiting for an MCDI request, so trigger a reset */ |
| 477 | efx_schedule_reset(efx, RESET_TYPE_MC_FAILURE); |
| 478 | |
Ben Hutchings | 3f713bf | 2011-12-20 23:39:31 +0000 | [diff] [blame] | 479 | /* Consume the status word since efx_mcdi_rpc_finish() won't */ |
| 480 | for (count = 0; count < MCDI_STATUS_DELAY_COUNT; ++count) { |
| 481 | if (efx_mcdi_poll_reboot(efx)) |
| 482 | break; |
| 483 | udelay(MCDI_STATUS_DELAY_US); |
| 484 | } |
| 485 | } |
| 486 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 487 | spin_unlock(&mcdi->iface_lock); |
| 488 | } |
| 489 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 490 | /* Called from falcon_process_eventq for MCDI events */ |
| 491 | void efx_mcdi_process_event(struct efx_channel *channel, |
| 492 | efx_qword_t *event) |
| 493 | { |
| 494 | struct efx_nic *efx = channel->efx; |
| 495 | int code = EFX_QWORD_FIELD(*event, MCDI_EVENT_CODE); |
| 496 | u32 data = EFX_QWORD_FIELD(*event, MCDI_EVENT_DATA); |
| 497 | |
| 498 | switch (code) { |
| 499 | case MCDI_EVENT_CODE_BADSSERT: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 500 | netif_err(efx, hw, efx->net_dev, |
| 501 | "MC watchdog or assertion failure at 0x%x\n", data); |
Ben Hutchings | 5bc283e | 2012-10-08 21:43:00 +0100 | [diff] [blame^] | 502 | efx_mcdi_ev_death(efx, -EINTR); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 503 | break; |
| 504 | |
| 505 | case MCDI_EVENT_CODE_PMNOTICE: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 506 | netif_info(efx, wol, efx->net_dev, "MCDI PM event.\n"); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 507 | break; |
| 508 | |
| 509 | case MCDI_EVENT_CODE_CMDDONE: |
| 510 | efx_mcdi_ev_cpl(efx, |
| 511 | MCDI_EVENT_FIELD(*event, CMDDONE_SEQ), |
| 512 | MCDI_EVENT_FIELD(*event, CMDDONE_DATALEN), |
| 513 | MCDI_EVENT_FIELD(*event, CMDDONE_ERRNO)); |
| 514 | break; |
| 515 | |
| 516 | case MCDI_EVENT_CODE_LINKCHANGE: |
| 517 | efx_mcdi_process_link_change(efx, event); |
| 518 | break; |
| 519 | case MCDI_EVENT_CODE_SENSOREVT: |
| 520 | efx_mcdi_sensor_event(efx, event); |
| 521 | break; |
| 522 | case MCDI_EVENT_CODE_SCHEDERR: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 523 | netif_info(efx, hw, efx->net_dev, |
| 524 | "MC Scheduler error address=0x%x\n", data); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 525 | break; |
| 526 | case MCDI_EVENT_CODE_REBOOT: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 527 | netif_info(efx, hw, efx->net_dev, "MC Reboot\n"); |
Ben Hutchings | 5bc283e | 2012-10-08 21:43:00 +0100 | [diff] [blame^] | 528 | efx_mcdi_ev_death(efx, -EIO); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 529 | break; |
| 530 | case MCDI_EVENT_CODE_MAC_STATS_DMA: |
| 531 | /* MAC stats are gather lazily. We can ignore this. */ |
| 532 | break; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 533 | case MCDI_EVENT_CODE_FLR: |
| 534 | efx_sriov_flr(efx, MCDI_EVENT_FIELD(*event, FLR_VF)); |
| 535 | break; |
Stuart Hodgson | 7c236c4 | 2012-09-03 11:09:36 +0100 | [diff] [blame] | 536 | case MCDI_EVENT_CODE_PTP_RX: |
| 537 | case MCDI_EVENT_CODE_PTP_FAULT: |
| 538 | case MCDI_EVENT_CODE_PTP_PPS: |
| 539 | efx_ptp_event(efx, event); |
| 540 | break; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 541 | |
| 542 | default: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 543 | netif_err(efx, hw, efx->net_dev, "Unknown MCDI event 0x%x\n", |
| 544 | code); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 545 | } |
| 546 | } |
| 547 | |
| 548 | /************************************************************************** |
| 549 | * |
| 550 | * Specific request functions |
| 551 | * |
| 552 | ************************************************************************** |
| 553 | */ |
| 554 | |
Ben Hutchings | e5f0fd2 | 2011-02-24 23:57:47 +0000 | [diff] [blame] | 555 | void efx_mcdi_print_fwver(struct efx_nic *efx, char *buf, size_t len) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 556 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 557 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_VERSION_OUT_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 558 | size_t outlength; |
| 559 | const __le16 *ver_words; |
| 560 | int rc; |
| 561 | |
| 562 | BUILD_BUG_ON(MC_CMD_GET_VERSION_IN_LEN != 0); |
| 563 | |
| 564 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_VERSION, NULL, 0, |
| 565 | outbuf, sizeof(outbuf), &outlength); |
| 566 | if (rc) |
| 567 | goto fail; |
| 568 | |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 569 | if (outlength < MC_CMD_GET_VERSION_OUT_LEN) { |
Ben Hutchings | 00bbb4a | 2010-04-28 09:27:14 +0000 | [diff] [blame] | 570 | rc = -EIO; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 571 | goto fail; |
| 572 | } |
| 573 | |
| 574 | ver_words = (__le16 *)MCDI_PTR(outbuf, GET_VERSION_OUT_VERSION); |
Ben Hutchings | e5f0fd2 | 2011-02-24 23:57:47 +0000 | [diff] [blame] | 575 | snprintf(buf, len, "%u.%u.%u.%u", |
| 576 | le16_to_cpu(ver_words[0]), le16_to_cpu(ver_words[1]), |
| 577 | le16_to_cpu(ver_words[2]), le16_to_cpu(ver_words[3])); |
| 578 | return; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 579 | |
| 580 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 581 | netif_err(efx, probe, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Ben Hutchings | e5f0fd2 | 2011-02-24 23:57:47 +0000 | [diff] [blame] | 582 | buf[0] = 0; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | int efx_mcdi_drv_attach(struct efx_nic *efx, bool driver_operating, |
| 586 | bool *was_attached) |
| 587 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 588 | MCDI_DECLARE_BUF(inbuf, MC_CMD_DRV_ATTACH_IN_LEN); |
| 589 | MCDI_DECLARE_BUF(outbuf, MC_CMD_DRV_ATTACH_OUT_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 590 | size_t outlen; |
| 591 | int rc; |
| 592 | |
| 593 | MCDI_SET_DWORD(inbuf, DRV_ATTACH_IN_NEW_STATE, |
| 594 | driver_operating ? 1 : 0); |
| 595 | MCDI_SET_DWORD(inbuf, DRV_ATTACH_IN_UPDATE, 1); |
| 596 | |
| 597 | rc = efx_mcdi_rpc(efx, MC_CMD_DRV_ATTACH, inbuf, sizeof(inbuf), |
| 598 | outbuf, sizeof(outbuf), &outlen); |
| 599 | if (rc) |
| 600 | goto fail; |
Ben Hutchings | 00bbb4a | 2010-04-28 09:27:14 +0000 | [diff] [blame] | 601 | if (outlen < MC_CMD_DRV_ATTACH_OUT_LEN) { |
| 602 | rc = -EIO; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 603 | goto fail; |
Ben Hutchings | 00bbb4a | 2010-04-28 09:27:14 +0000 | [diff] [blame] | 604 | } |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 605 | |
| 606 | if (was_attached != NULL) |
| 607 | *was_attached = MCDI_DWORD(outbuf, DRV_ATTACH_OUT_OLD_STATE); |
| 608 | return 0; |
| 609 | |
| 610 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 611 | netif_err(efx, probe, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 612 | return rc; |
| 613 | } |
| 614 | |
| 615 | int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address, |
Matthew Slattery | 6aa9c7f | 2010-07-14 15:36:19 +0100 | [diff] [blame] | 616 | u16 *fw_subtype_list, u32 *capabilities) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 617 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 618 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_BOARD_CFG_OUT_LENMAX); |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 619 | size_t outlen, i; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 620 | int port_num = efx_port_num(efx); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 621 | int rc; |
| 622 | |
| 623 | BUILD_BUG_ON(MC_CMD_GET_BOARD_CFG_IN_LEN != 0); |
| 624 | |
| 625 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_BOARD_CFG, NULL, 0, |
| 626 | outbuf, sizeof(outbuf), &outlen); |
| 627 | if (rc) |
| 628 | goto fail; |
| 629 | |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 630 | if (outlen < MC_CMD_GET_BOARD_CFG_OUT_LENMIN) { |
Ben Hutchings | 00bbb4a | 2010-04-28 09:27:14 +0000 | [diff] [blame] | 631 | rc = -EIO; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 632 | goto fail; |
| 633 | } |
| 634 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 635 | if (mac_address) |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 636 | memcpy(mac_address, |
| 637 | port_num ? |
| 638 | MCDI_PTR(outbuf, GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT1) : |
| 639 | MCDI_PTR(outbuf, GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT0), |
| 640 | ETH_ALEN); |
Ben Hutchings | bfeed90 | 2012-09-07 00:58:10 +0100 | [diff] [blame] | 641 | if (fw_subtype_list) { |
Ben Hutchings | bfeed90 | 2012-09-07 00:58:10 +0100 | [diff] [blame] | 642 | for (i = 0; |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 643 | i < MCDI_VAR_ARRAY_LEN(outlen, |
| 644 | GET_BOARD_CFG_OUT_FW_SUBTYPE_LIST); |
| 645 | i++) |
| 646 | fw_subtype_list[i] = MCDI_ARRAY_WORD( |
| 647 | outbuf, GET_BOARD_CFG_OUT_FW_SUBTYPE_LIST, i); |
| 648 | for (; i < MC_CMD_GET_BOARD_CFG_OUT_FW_SUBTYPE_LIST_MAXNUM; i++) |
| 649 | fw_subtype_list[i] = 0; |
Ben Hutchings | bfeed90 | 2012-09-07 00:58:10 +0100 | [diff] [blame] | 650 | } |
Matthew Slattery | 6aa9c7f | 2010-07-14 15:36:19 +0100 | [diff] [blame] | 651 | if (capabilities) { |
| 652 | if (port_num) |
| 653 | *capabilities = MCDI_DWORD(outbuf, |
| 654 | GET_BOARD_CFG_OUT_CAPABILITIES_PORT1); |
| 655 | else |
| 656 | *capabilities = MCDI_DWORD(outbuf, |
| 657 | GET_BOARD_CFG_OUT_CAPABILITIES_PORT0); |
| 658 | } |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 659 | |
| 660 | return 0; |
| 661 | |
| 662 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 663 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d len=%d\n", |
| 664 | __func__, rc, (int)outlen); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 665 | |
| 666 | return rc; |
| 667 | } |
| 668 | |
| 669 | int efx_mcdi_log_ctrl(struct efx_nic *efx, bool evq, bool uart, u32 dest_evq) |
| 670 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 671 | MCDI_DECLARE_BUF(inbuf, MC_CMD_LOG_CTRL_IN_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 672 | u32 dest = 0; |
| 673 | int rc; |
| 674 | |
| 675 | if (uart) |
| 676 | dest |= MC_CMD_LOG_CTRL_IN_LOG_DEST_UART; |
| 677 | if (evq) |
| 678 | dest |= MC_CMD_LOG_CTRL_IN_LOG_DEST_EVQ; |
| 679 | |
| 680 | MCDI_SET_DWORD(inbuf, LOG_CTRL_IN_LOG_DEST, dest); |
| 681 | MCDI_SET_DWORD(inbuf, LOG_CTRL_IN_LOG_DEST_EVQ, dest_evq); |
| 682 | |
| 683 | BUILD_BUG_ON(MC_CMD_LOG_CTRL_OUT_LEN != 0); |
| 684 | |
| 685 | rc = efx_mcdi_rpc(efx, MC_CMD_LOG_CTRL, inbuf, sizeof(inbuf), |
| 686 | NULL, 0, NULL); |
| 687 | if (rc) |
| 688 | goto fail; |
| 689 | |
| 690 | return 0; |
| 691 | |
| 692 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 693 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 694 | return rc; |
| 695 | } |
| 696 | |
| 697 | int efx_mcdi_nvram_types(struct efx_nic *efx, u32 *nvram_types_out) |
| 698 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 699 | MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_TYPES_OUT_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 700 | size_t outlen; |
| 701 | int rc; |
| 702 | |
| 703 | BUILD_BUG_ON(MC_CMD_NVRAM_TYPES_IN_LEN != 0); |
| 704 | |
| 705 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_TYPES, NULL, 0, |
| 706 | outbuf, sizeof(outbuf), &outlen); |
| 707 | if (rc) |
| 708 | goto fail; |
Ben Hutchings | 00bbb4a | 2010-04-28 09:27:14 +0000 | [diff] [blame] | 709 | if (outlen < MC_CMD_NVRAM_TYPES_OUT_LEN) { |
| 710 | rc = -EIO; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 711 | goto fail; |
Ben Hutchings | 00bbb4a | 2010-04-28 09:27:14 +0000 | [diff] [blame] | 712 | } |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 713 | |
| 714 | *nvram_types_out = MCDI_DWORD(outbuf, NVRAM_TYPES_OUT_TYPES); |
| 715 | return 0; |
| 716 | |
| 717 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 718 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", |
| 719 | __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 720 | return rc; |
| 721 | } |
| 722 | |
| 723 | int efx_mcdi_nvram_info(struct efx_nic *efx, unsigned int type, |
| 724 | size_t *size_out, size_t *erase_size_out, |
| 725 | bool *protected_out) |
| 726 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 727 | MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_INFO_IN_LEN); |
| 728 | MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_INFO_OUT_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 729 | size_t outlen; |
| 730 | int rc; |
| 731 | |
| 732 | MCDI_SET_DWORD(inbuf, NVRAM_INFO_IN_TYPE, type); |
| 733 | |
| 734 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_INFO, inbuf, sizeof(inbuf), |
| 735 | outbuf, sizeof(outbuf), &outlen); |
| 736 | if (rc) |
| 737 | goto fail; |
Ben Hutchings | 00bbb4a | 2010-04-28 09:27:14 +0000 | [diff] [blame] | 738 | if (outlen < MC_CMD_NVRAM_INFO_OUT_LEN) { |
| 739 | rc = -EIO; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 740 | goto fail; |
Ben Hutchings | 00bbb4a | 2010-04-28 09:27:14 +0000 | [diff] [blame] | 741 | } |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 742 | |
| 743 | *size_out = MCDI_DWORD(outbuf, NVRAM_INFO_OUT_SIZE); |
| 744 | *erase_size_out = MCDI_DWORD(outbuf, NVRAM_INFO_OUT_ERASESIZE); |
| 745 | *protected_out = !!(MCDI_DWORD(outbuf, NVRAM_INFO_OUT_FLAGS) & |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 746 | (1 << MC_CMD_NVRAM_INFO_OUT_PROTECTED_LBN)); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 747 | return 0; |
| 748 | |
| 749 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 750 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 751 | return rc; |
| 752 | } |
| 753 | |
| 754 | int efx_mcdi_nvram_update_start(struct efx_nic *efx, unsigned int type) |
| 755 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 756 | MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_UPDATE_START_IN_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 757 | int rc; |
| 758 | |
| 759 | MCDI_SET_DWORD(inbuf, NVRAM_UPDATE_START_IN_TYPE, type); |
| 760 | |
| 761 | BUILD_BUG_ON(MC_CMD_NVRAM_UPDATE_START_OUT_LEN != 0); |
| 762 | |
| 763 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_UPDATE_START, inbuf, sizeof(inbuf), |
| 764 | NULL, 0, NULL); |
| 765 | if (rc) |
| 766 | goto fail; |
| 767 | |
| 768 | return 0; |
| 769 | |
| 770 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 771 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 772 | return rc; |
| 773 | } |
| 774 | |
| 775 | int efx_mcdi_nvram_read(struct efx_nic *efx, unsigned int type, |
| 776 | loff_t offset, u8 *buffer, size_t length) |
| 777 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 778 | MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_READ_IN_LEN); |
| 779 | MCDI_DECLARE_BUF(outbuf, |
| 780 | MC_CMD_NVRAM_READ_OUT_LEN(EFX_MCDI_NVRAM_LEN_MAX)); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 781 | size_t outlen; |
| 782 | int rc; |
| 783 | |
| 784 | MCDI_SET_DWORD(inbuf, NVRAM_READ_IN_TYPE, type); |
| 785 | MCDI_SET_DWORD(inbuf, NVRAM_READ_IN_OFFSET, offset); |
| 786 | MCDI_SET_DWORD(inbuf, NVRAM_READ_IN_LENGTH, length); |
| 787 | |
| 788 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_READ, inbuf, sizeof(inbuf), |
| 789 | outbuf, sizeof(outbuf), &outlen); |
| 790 | if (rc) |
| 791 | goto fail; |
| 792 | |
| 793 | memcpy(buffer, MCDI_PTR(outbuf, NVRAM_READ_OUT_READ_BUFFER), length); |
| 794 | return 0; |
| 795 | |
| 796 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 797 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 798 | return rc; |
| 799 | } |
| 800 | |
| 801 | int efx_mcdi_nvram_write(struct efx_nic *efx, unsigned int type, |
| 802 | loff_t offset, const u8 *buffer, size_t length) |
| 803 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 804 | MCDI_DECLARE_BUF(inbuf, |
| 805 | MC_CMD_NVRAM_WRITE_IN_LEN(EFX_MCDI_NVRAM_LEN_MAX)); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 806 | int rc; |
| 807 | |
| 808 | MCDI_SET_DWORD(inbuf, NVRAM_WRITE_IN_TYPE, type); |
| 809 | MCDI_SET_DWORD(inbuf, NVRAM_WRITE_IN_OFFSET, offset); |
| 810 | MCDI_SET_DWORD(inbuf, NVRAM_WRITE_IN_LENGTH, length); |
| 811 | memcpy(MCDI_PTR(inbuf, NVRAM_WRITE_IN_WRITE_BUFFER), buffer, length); |
| 812 | |
| 813 | BUILD_BUG_ON(MC_CMD_NVRAM_WRITE_OUT_LEN != 0); |
| 814 | |
Ben Hutchings | 5a27e86 | 2010-01-25 15:49:59 -0800 | [diff] [blame] | 815 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_WRITE, inbuf, |
| 816 | ALIGN(MC_CMD_NVRAM_WRITE_IN_LEN(length), 4), |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 817 | NULL, 0, NULL); |
| 818 | if (rc) |
| 819 | goto fail; |
| 820 | |
| 821 | return 0; |
| 822 | |
| 823 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 824 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 825 | return rc; |
| 826 | } |
| 827 | |
| 828 | int efx_mcdi_nvram_erase(struct efx_nic *efx, unsigned int type, |
| 829 | loff_t offset, size_t length) |
| 830 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 831 | MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_ERASE_IN_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 832 | int rc; |
| 833 | |
| 834 | MCDI_SET_DWORD(inbuf, NVRAM_ERASE_IN_TYPE, type); |
| 835 | MCDI_SET_DWORD(inbuf, NVRAM_ERASE_IN_OFFSET, offset); |
| 836 | MCDI_SET_DWORD(inbuf, NVRAM_ERASE_IN_LENGTH, length); |
| 837 | |
| 838 | BUILD_BUG_ON(MC_CMD_NVRAM_ERASE_OUT_LEN != 0); |
| 839 | |
| 840 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_ERASE, inbuf, sizeof(inbuf), |
| 841 | NULL, 0, NULL); |
| 842 | if (rc) |
| 843 | goto fail; |
| 844 | |
| 845 | return 0; |
| 846 | |
| 847 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 848 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 849 | return rc; |
| 850 | } |
| 851 | |
| 852 | int efx_mcdi_nvram_update_finish(struct efx_nic *efx, unsigned int type) |
| 853 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 854 | MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_UPDATE_FINISH_IN_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 855 | int rc; |
| 856 | |
| 857 | MCDI_SET_DWORD(inbuf, NVRAM_UPDATE_FINISH_IN_TYPE, type); |
| 858 | |
| 859 | BUILD_BUG_ON(MC_CMD_NVRAM_UPDATE_FINISH_OUT_LEN != 0); |
| 860 | |
| 861 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_UPDATE_FINISH, inbuf, sizeof(inbuf), |
| 862 | NULL, 0, NULL); |
| 863 | if (rc) |
| 864 | goto fail; |
| 865 | |
| 866 | return 0; |
| 867 | |
| 868 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 869 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 870 | return rc; |
| 871 | } |
| 872 | |
Ben Hutchings | 2e80340 | 2010-02-03 09:31:01 +0000 | [diff] [blame] | 873 | static int efx_mcdi_nvram_test(struct efx_nic *efx, unsigned int type) |
| 874 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 875 | MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_TEST_IN_LEN); |
| 876 | MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_TEST_OUT_LEN); |
Ben Hutchings | 2e80340 | 2010-02-03 09:31:01 +0000 | [diff] [blame] | 877 | int rc; |
| 878 | |
| 879 | MCDI_SET_DWORD(inbuf, NVRAM_TEST_IN_TYPE, type); |
| 880 | |
| 881 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_TEST, inbuf, sizeof(inbuf), |
| 882 | outbuf, sizeof(outbuf), NULL); |
| 883 | if (rc) |
| 884 | return rc; |
| 885 | |
| 886 | switch (MCDI_DWORD(outbuf, NVRAM_TEST_OUT_RESULT)) { |
| 887 | case MC_CMD_NVRAM_TEST_PASS: |
| 888 | case MC_CMD_NVRAM_TEST_NOTSUPP: |
| 889 | return 0; |
| 890 | default: |
| 891 | return -EIO; |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | int efx_mcdi_nvram_test_all(struct efx_nic *efx) |
| 896 | { |
| 897 | u32 nvram_types; |
| 898 | unsigned int type; |
| 899 | int rc; |
| 900 | |
| 901 | rc = efx_mcdi_nvram_types(efx, &nvram_types); |
| 902 | if (rc) |
Ben Hutchings | b548a98 | 2010-04-28 09:28:36 +0000 | [diff] [blame] | 903 | goto fail1; |
Ben Hutchings | 2e80340 | 2010-02-03 09:31:01 +0000 | [diff] [blame] | 904 | |
| 905 | type = 0; |
| 906 | while (nvram_types != 0) { |
| 907 | if (nvram_types & 1) { |
| 908 | rc = efx_mcdi_nvram_test(efx, type); |
| 909 | if (rc) |
Ben Hutchings | b548a98 | 2010-04-28 09:28:36 +0000 | [diff] [blame] | 910 | goto fail2; |
Ben Hutchings | 2e80340 | 2010-02-03 09:31:01 +0000 | [diff] [blame] | 911 | } |
| 912 | type++; |
| 913 | nvram_types >>= 1; |
| 914 | } |
| 915 | |
| 916 | return 0; |
Ben Hutchings | b548a98 | 2010-04-28 09:28:36 +0000 | [diff] [blame] | 917 | |
| 918 | fail2: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 919 | netif_err(efx, hw, efx->net_dev, "%s: failed type=%u\n", |
| 920 | __func__, type); |
Ben Hutchings | b548a98 | 2010-04-28 09:28:36 +0000 | [diff] [blame] | 921 | fail1: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 922 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Ben Hutchings | b548a98 | 2010-04-28 09:28:36 +0000 | [diff] [blame] | 923 | return rc; |
Ben Hutchings | 2e80340 | 2010-02-03 09:31:01 +0000 | [diff] [blame] | 924 | } |
| 925 | |
Steve Hodgson | 8b2103a | 2010-02-03 09:30:17 +0000 | [diff] [blame] | 926 | static int efx_mcdi_read_assertion(struct efx_nic *efx) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 927 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 928 | MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_ASSERTS_IN_LEN); |
| 929 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_ASSERTS_OUT_LEN); |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 930 | unsigned int flags, index; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 931 | const char *reason; |
| 932 | size_t outlen; |
| 933 | int retry; |
| 934 | int rc; |
| 935 | |
Steve Hodgson | 8b2103a | 2010-02-03 09:30:17 +0000 | [diff] [blame] | 936 | /* Attempt to read any stored assertion state before we reboot |
| 937 | * the mcfw out of the assertion handler. Retry twice, once |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 938 | * because a boot-time assertion might cause this command to fail |
| 939 | * with EINTR. And once again because GET_ASSERTS can race with |
| 940 | * MC_CMD_REBOOT running on the other port. */ |
| 941 | retry = 2; |
| 942 | do { |
Steve Hodgson | 8b2103a | 2010-02-03 09:30:17 +0000 | [diff] [blame] | 943 | MCDI_SET_DWORD(inbuf, GET_ASSERTS_IN_CLEAR, 1); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 944 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_ASSERTS, |
Steve Hodgson | 8b2103a | 2010-02-03 09:30:17 +0000 | [diff] [blame] | 945 | inbuf, MC_CMD_GET_ASSERTS_IN_LEN, |
| 946 | outbuf, sizeof(outbuf), &outlen); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 947 | } while ((rc == -EINTR || rc == -EIO) && retry-- > 0); |
| 948 | |
| 949 | if (rc) |
| 950 | return rc; |
| 951 | if (outlen < MC_CMD_GET_ASSERTS_OUT_LEN) |
Ben Hutchings | 00bbb4a | 2010-04-28 09:27:14 +0000 | [diff] [blame] | 952 | return -EIO; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 953 | |
Steve Hodgson | 8b2103a | 2010-02-03 09:30:17 +0000 | [diff] [blame] | 954 | /* Print out any recorded assertion state */ |
| 955 | flags = MCDI_DWORD(outbuf, GET_ASSERTS_OUT_GLOBAL_FLAGS); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 956 | if (flags == MC_CMD_GET_ASSERTS_FLAGS_NO_FAILS) |
| 957 | return 0; |
| 958 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 959 | reason = (flags == MC_CMD_GET_ASSERTS_FLAGS_SYS_FAIL) |
| 960 | ? "system-level assertion" |
| 961 | : (flags == MC_CMD_GET_ASSERTS_FLAGS_THR_FAIL) |
| 962 | ? "thread-level assertion" |
| 963 | : (flags == MC_CMD_GET_ASSERTS_FLAGS_WDOG_FIRED) |
| 964 | ? "watchdog reset" |
| 965 | : "unknown assertion"; |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 966 | netif_err(efx, hw, efx->net_dev, |
| 967 | "MCPU %s at PC = 0x%.8x in thread 0x%.8x\n", reason, |
| 968 | MCDI_DWORD(outbuf, GET_ASSERTS_OUT_SAVED_PC_OFFS), |
| 969 | MCDI_DWORD(outbuf, GET_ASSERTS_OUT_THREAD_OFFS)); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 970 | |
| 971 | /* Print out the registers */ |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 972 | for (index = 0; |
| 973 | index < MC_CMD_GET_ASSERTS_OUT_GP_REGS_OFFS_NUM; |
| 974 | index++) |
| 975 | netif_err(efx, hw, efx->net_dev, "R%.2d (?): 0x%.8x\n", |
| 976 | 1 + index, |
| 977 | MCDI_ARRAY_DWORD(outbuf, GET_ASSERTS_OUT_GP_REGS_OFFS, |
| 978 | index)); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 979 | |
| 980 | return 0; |
| 981 | } |
| 982 | |
Steve Hodgson | 8b2103a | 2010-02-03 09:30:17 +0000 | [diff] [blame] | 983 | static void efx_mcdi_exit_assertion(struct efx_nic *efx) |
| 984 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 985 | MCDI_DECLARE_BUF(inbuf, MC_CMD_REBOOT_IN_LEN); |
Steve Hodgson | 8b2103a | 2010-02-03 09:30:17 +0000 | [diff] [blame] | 986 | |
Ben Hutchings | 0f1e54a | 2012-07-02 23:37:40 +0100 | [diff] [blame] | 987 | /* If the MC is running debug firmware, it might now be |
| 988 | * waiting for a debugger to attach, but we just want it to |
| 989 | * reboot. We set a flag that makes the command a no-op if it |
| 990 | * has already done so. We don't know what return code to |
| 991 | * expect (0 or -EIO), so ignore it. |
| 992 | */ |
Steve Hodgson | 8b2103a | 2010-02-03 09:30:17 +0000 | [diff] [blame] | 993 | BUILD_BUG_ON(MC_CMD_REBOOT_OUT_LEN != 0); |
| 994 | MCDI_SET_DWORD(inbuf, REBOOT_IN_FLAGS, |
| 995 | MC_CMD_REBOOT_FLAGS_AFTER_ASSERTION); |
Ben Hutchings | 0f1e54a | 2012-07-02 23:37:40 +0100 | [diff] [blame] | 996 | (void) efx_mcdi_rpc(efx, MC_CMD_REBOOT, inbuf, MC_CMD_REBOOT_IN_LEN, |
| 997 | NULL, 0, NULL); |
Steve Hodgson | 8b2103a | 2010-02-03 09:30:17 +0000 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | int efx_mcdi_handle_assertion(struct efx_nic *efx) |
| 1001 | { |
| 1002 | int rc; |
| 1003 | |
| 1004 | rc = efx_mcdi_read_assertion(efx); |
| 1005 | if (rc) |
| 1006 | return rc; |
| 1007 | |
| 1008 | efx_mcdi_exit_assertion(efx); |
| 1009 | |
| 1010 | return 0; |
| 1011 | } |
| 1012 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1013 | void efx_mcdi_set_id_led(struct efx_nic *efx, enum efx_led_mode mode) |
| 1014 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 1015 | MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_ID_LED_IN_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1016 | int rc; |
| 1017 | |
| 1018 | BUILD_BUG_ON(EFX_LED_OFF != MC_CMD_LED_OFF); |
| 1019 | BUILD_BUG_ON(EFX_LED_ON != MC_CMD_LED_ON); |
| 1020 | BUILD_BUG_ON(EFX_LED_DEFAULT != MC_CMD_LED_DEFAULT); |
| 1021 | |
| 1022 | BUILD_BUG_ON(MC_CMD_SET_ID_LED_OUT_LEN != 0); |
| 1023 | |
| 1024 | MCDI_SET_DWORD(inbuf, SET_ID_LED_IN_STATE, mode); |
| 1025 | |
| 1026 | rc = efx_mcdi_rpc(efx, MC_CMD_SET_ID_LED, inbuf, sizeof(inbuf), |
| 1027 | NULL, 0, NULL); |
| 1028 | if (rc) |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1029 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", |
| 1030 | __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
Ben Hutchings | 6bff861 | 2012-09-18 02:33:52 +0100 | [diff] [blame] | 1033 | static int efx_mcdi_reset_port(struct efx_nic *efx) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1034 | { |
Ben Hutchings | 05a9320 | 2011-12-20 00:44:06 +0000 | [diff] [blame] | 1035 | int rc = efx_mcdi_rpc(efx, MC_CMD_ENTITY_RESET, NULL, 0, NULL, 0, NULL); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1036 | if (rc) |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1037 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", |
| 1038 | __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1039 | return rc; |
| 1040 | } |
| 1041 | |
Ben Hutchings | 6bff861 | 2012-09-18 02:33:52 +0100 | [diff] [blame] | 1042 | static int efx_mcdi_reset_mc(struct efx_nic *efx) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1043 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 1044 | MCDI_DECLARE_BUF(inbuf, MC_CMD_REBOOT_IN_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1045 | int rc; |
| 1046 | |
| 1047 | BUILD_BUG_ON(MC_CMD_REBOOT_OUT_LEN != 0); |
| 1048 | MCDI_SET_DWORD(inbuf, REBOOT_IN_FLAGS, 0); |
| 1049 | rc = efx_mcdi_rpc(efx, MC_CMD_REBOOT, inbuf, sizeof(inbuf), |
| 1050 | NULL, 0, NULL); |
| 1051 | /* White is black, and up is down */ |
| 1052 | if (rc == -EIO) |
| 1053 | return 0; |
| 1054 | if (rc == 0) |
| 1055 | rc = -EIO; |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1056 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1057 | return rc; |
| 1058 | } |
| 1059 | |
Ben Hutchings | 6bff861 | 2012-09-18 02:33:52 +0100 | [diff] [blame] | 1060 | enum reset_type efx_mcdi_map_reset_reason(enum reset_type reason) |
| 1061 | { |
| 1062 | return RESET_TYPE_RECOVER_OR_ALL; |
| 1063 | } |
| 1064 | |
| 1065 | int efx_mcdi_reset(struct efx_nic *efx, enum reset_type method) |
| 1066 | { |
| 1067 | int rc; |
| 1068 | |
| 1069 | /* Recover from a failed assertion pre-reset */ |
| 1070 | rc = efx_mcdi_handle_assertion(efx); |
| 1071 | if (rc) |
| 1072 | return rc; |
| 1073 | |
| 1074 | if (method == RESET_TYPE_WORLD) |
| 1075 | return efx_mcdi_reset_mc(efx); |
| 1076 | else |
| 1077 | return efx_mcdi_reset_port(efx); |
| 1078 | } |
| 1079 | |
stephen hemminger | d215697 | 2010-10-18 05:27:31 +0000 | [diff] [blame] | 1080 | static int efx_mcdi_wol_filter_set(struct efx_nic *efx, u32 type, |
| 1081 | const u8 *mac, int *id_out) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1082 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 1083 | MCDI_DECLARE_BUF(inbuf, MC_CMD_WOL_FILTER_SET_IN_LEN); |
| 1084 | MCDI_DECLARE_BUF(outbuf, MC_CMD_WOL_FILTER_SET_OUT_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1085 | size_t outlen; |
| 1086 | int rc; |
| 1087 | |
| 1088 | MCDI_SET_DWORD(inbuf, WOL_FILTER_SET_IN_WOL_TYPE, type); |
| 1089 | MCDI_SET_DWORD(inbuf, WOL_FILTER_SET_IN_FILTER_MODE, |
| 1090 | MC_CMD_FILTER_MODE_SIMPLE); |
| 1091 | memcpy(MCDI_PTR(inbuf, WOL_FILTER_SET_IN_MAGIC_MAC), mac, ETH_ALEN); |
| 1092 | |
| 1093 | rc = efx_mcdi_rpc(efx, MC_CMD_WOL_FILTER_SET, inbuf, sizeof(inbuf), |
| 1094 | outbuf, sizeof(outbuf), &outlen); |
| 1095 | if (rc) |
| 1096 | goto fail; |
| 1097 | |
| 1098 | if (outlen < MC_CMD_WOL_FILTER_SET_OUT_LEN) { |
Ben Hutchings | 00bbb4a | 2010-04-28 09:27:14 +0000 | [diff] [blame] | 1099 | rc = -EIO; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1100 | goto fail; |
| 1101 | } |
| 1102 | |
| 1103 | *id_out = (int)MCDI_DWORD(outbuf, WOL_FILTER_SET_OUT_FILTER_ID); |
| 1104 | |
| 1105 | return 0; |
| 1106 | |
| 1107 | fail: |
| 1108 | *id_out = -1; |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1109 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1110 | return rc; |
| 1111 | |
| 1112 | } |
| 1113 | |
| 1114 | |
| 1115 | int |
| 1116 | efx_mcdi_wol_filter_set_magic(struct efx_nic *efx, const u8 *mac, int *id_out) |
| 1117 | { |
| 1118 | return efx_mcdi_wol_filter_set(efx, MC_CMD_WOL_TYPE_MAGIC, mac, id_out); |
| 1119 | } |
| 1120 | |
| 1121 | |
| 1122 | int efx_mcdi_wol_filter_get_magic(struct efx_nic *efx, int *id_out) |
| 1123 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 1124 | MCDI_DECLARE_BUF(outbuf, MC_CMD_WOL_FILTER_GET_OUT_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1125 | size_t outlen; |
| 1126 | int rc; |
| 1127 | |
| 1128 | rc = efx_mcdi_rpc(efx, MC_CMD_WOL_FILTER_GET, NULL, 0, |
| 1129 | outbuf, sizeof(outbuf), &outlen); |
| 1130 | if (rc) |
| 1131 | goto fail; |
| 1132 | |
| 1133 | if (outlen < MC_CMD_WOL_FILTER_GET_OUT_LEN) { |
Ben Hutchings | 00bbb4a | 2010-04-28 09:27:14 +0000 | [diff] [blame] | 1134 | rc = -EIO; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1135 | goto fail; |
| 1136 | } |
| 1137 | |
| 1138 | *id_out = (int)MCDI_DWORD(outbuf, WOL_FILTER_GET_OUT_FILTER_ID); |
| 1139 | |
| 1140 | return 0; |
| 1141 | |
| 1142 | fail: |
| 1143 | *id_out = -1; |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1144 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1145 | return rc; |
| 1146 | } |
| 1147 | |
| 1148 | |
| 1149 | int efx_mcdi_wol_filter_remove(struct efx_nic *efx, int id) |
| 1150 | { |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 1151 | MCDI_DECLARE_BUF(inbuf, MC_CMD_WOL_FILTER_REMOVE_IN_LEN); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1152 | int rc; |
| 1153 | |
| 1154 | MCDI_SET_DWORD(inbuf, WOL_FILTER_REMOVE_IN_FILTER_ID, (u32)id); |
| 1155 | |
| 1156 | rc = efx_mcdi_rpc(efx, MC_CMD_WOL_FILTER_REMOVE, inbuf, sizeof(inbuf), |
| 1157 | NULL, 0, NULL); |
| 1158 | if (rc) |
| 1159 | goto fail; |
| 1160 | |
| 1161 | return 0; |
| 1162 | |
| 1163 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1164 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1165 | return rc; |
| 1166 | } |
| 1167 | |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1168 | int efx_mcdi_flush_rxqs(struct efx_nic *efx) |
| 1169 | { |
| 1170 | struct efx_channel *channel; |
| 1171 | struct efx_rx_queue *rx_queue; |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 1172 | MCDI_DECLARE_BUF(inbuf, |
| 1173 | MC_CMD_FLUSH_RX_QUEUES_IN_LEN(EFX_MAX_CHANNELS)); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1174 | int rc, count; |
| 1175 | |
Ben Hutchings | 4507837 | 2012-09-19 02:53:34 +0100 | [diff] [blame] | 1176 | BUILD_BUG_ON(EFX_MAX_CHANNELS > |
| 1177 | MC_CMD_FLUSH_RX_QUEUES_IN_QID_OFST_MAXNUM); |
| 1178 | |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1179 | count = 0; |
| 1180 | efx_for_each_channel(channel, efx) { |
| 1181 | efx_for_each_channel_rx_queue(rx_queue, channel) { |
| 1182 | if (rx_queue->flush_pending) { |
| 1183 | rx_queue->flush_pending = false; |
| 1184 | atomic_dec(&efx->rxq_flush_pending); |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 1185 | MCDI_SET_ARRAY_DWORD( |
| 1186 | inbuf, FLUSH_RX_QUEUES_IN_QID_OFST, |
| 1187 | count, efx_rx_queue_index(rx_queue)); |
| 1188 | count++; |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1189 | } |
| 1190 | } |
| 1191 | } |
| 1192 | |
Ben Hutchings | c5bb0e9 | 2012-09-14 17:31:33 +0100 | [diff] [blame] | 1193 | rc = efx_mcdi_rpc(efx, MC_CMD_FLUSH_RX_QUEUES, inbuf, |
| 1194 | MC_CMD_FLUSH_RX_QUEUES_IN_LEN(count), NULL, 0, NULL); |
Ben Hutchings | bbec969 | 2012-09-11 18:25:13 +0100 | [diff] [blame] | 1195 | WARN_ON(rc < 0); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1196 | |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1197 | return rc; |
| 1198 | } |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1199 | |
| 1200 | int efx_mcdi_wol_filter_reset(struct efx_nic *efx) |
| 1201 | { |
| 1202 | int rc; |
| 1203 | |
| 1204 | rc = efx_mcdi_rpc(efx, MC_CMD_WOL_FILTER_RESET, NULL, 0, NULL, 0, NULL); |
| 1205 | if (rc) |
| 1206 | goto fail; |
| 1207 | |
| 1208 | return 0; |
| 1209 | |
| 1210 | fail: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1211 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1212 | return rc; |
| 1213 | } |
| 1214 | |