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