1 /****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2008-2011 Solarflare Communications Inc.
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.
10 #include <linux/delay.h>
11 #include <asm/cmpxchg.h>
12 #include "net_driver.h"
15 #include "farch_regs.h"
16 #include "mcdi_pcol.h"
19 /**************************************************************************
21 * Management-Controller-to-Driver Interface
23 **************************************************************************
26 #define MCDI_RPC_TIMEOUT (10 * HZ)
28 /* A reboot/assertion causes the MCDI status word to be set after the
29 * command word is set or a REBOOT event is sent. If we notice a reboot
30 * via these mechanisms then wait 20ms for the status word to be set.
32 #define MCDI_STATUS_DELAY_US 100
33 #define MCDI_STATUS_DELAY_COUNT 200
34 #define MCDI_STATUS_SLEEP_MS \
35 (MCDI_STATUS_DELAY_US * MCDI_STATUS_DELAY_COUNT / 1000)
38 EFX_MASK32(EFX_WIDTH(MCDI_HEADER_SEQ))
40 struct efx_mcdi_async_param
{
41 struct list_head list
;
45 efx_mcdi_async_completer
*complete
;
47 /* followed by request/response buffer */
50 static void efx_mcdi_timeout_async(unsigned long context
);
52 static inline struct efx_mcdi_iface
*efx_mcdi(struct efx_nic
*efx
)
54 EFX_BUG_ON_PARANOID(!efx
->mcdi
);
55 return &efx
->mcdi
->iface
;
58 int efx_mcdi_init(struct efx_nic
*efx
)
60 struct efx_mcdi_iface
*mcdi
;
62 efx
->mcdi
= kzalloc(sizeof(*efx
->mcdi
), GFP_KERNEL
);
68 init_waitqueue_head(&mcdi
->wq
);
69 spin_lock_init(&mcdi
->iface_lock
);
70 mcdi
->state
= MCDI_STATE_QUIESCENT
;
71 mcdi
->mode
= MCDI_MODE_POLL
;
72 spin_lock_init(&mcdi
->async_lock
);
73 INIT_LIST_HEAD(&mcdi
->async_list
);
74 setup_timer(&mcdi
->async_timer
, efx_mcdi_timeout_async
,
77 (void) efx_mcdi_poll_reboot(efx
);
78 mcdi
->new_epoch
= true;
80 /* Recover from a failed assertion before probing */
81 return efx_mcdi_handle_assertion(efx
);
84 void efx_mcdi_fini(struct efx_nic
*efx
)
86 BUG_ON(efx
->mcdi
&& efx
->mcdi
->iface
.state
!= MCDI_STATE_QUIESCENT
);
90 static void efx_mcdi_send_request(struct efx_nic
*efx
, unsigned cmd
,
91 const efx_dword_t
*inbuf
, size_t inlen
)
93 struct efx_mcdi_iface
*mcdi
= efx_mcdi(efx
);
98 BUG_ON(mcdi
->state
== MCDI_STATE_QUIESCENT
);
100 /* Serialise with efx_mcdi_ev_cpl() and efx_mcdi_ev_death() */
101 spin_lock_bh(&mcdi
->iface_lock
);
103 spin_unlock_bh(&mcdi
->iface_lock
);
105 seqno
= mcdi
->seqno
& SEQ_MASK
;
107 if (mcdi
->mode
== MCDI_MODE_EVENTS
)
108 xflags
|= MCDI_HEADER_XFLAGS_EVREQ
;
110 if (efx
->type
->mcdi_max_ver
== 1) {
112 EFX_POPULATE_DWORD_7(hdr
[0],
113 MCDI_HEADER_RESPONSE
, 0,
114 MCDI_HEADER_RESYNC
, 1,
115 MCDI_HEADER_CODE
, cmd
,
116 MCDI_HEADER_DATALEN
, inlen
,
117 MCDI_HEADER_SEQ
, seqno
,
118 MCDI_HEADER_XFLAGS
, xflags
,
119 MCDI_HEADER_NOT_EPOCH
, !mcdi
->new_epoch
);
123 BUG_ON(inlen
> MCDI_CTL_SDU_LEN_MAX_V2
);
124 EFX_POPULATE_DWORD_7(hdr
[0],
125 MCDI_HEADER_RESPONSE
, 0,
126 MCDI_HEADER_RESYNC
, 1,
127 MCDI_HEADER_CODE
, MC_CMD_V2_EXTN
,
128 MCDI_HEADER_DATALEN
, 0,
129 MCDI_HEADER_SEQ
, seqno
,
130 MCDI_HEADER_XFLAGS
, xflags
,
131 MCDI_HEADER_NOT_EPOCH
, !mcdi
->new_epoch
);
132 EFX_POPULATE_DWORD_2(hdr
[1],
133 MC_CMD_V2_EXTN_IN_EXTENDED_CMD
, cmd
,
134 MC_CMD_V2_EXTN_IN_ACTUAL_LEN
, inlen
);
138 efx
->type
->mcdi_request(efx
, hdr
, hdr_len
, inbuf
, inlen
);
140 mcdi
->new_epoch
= false;
143 static int efx_mcdi_errno(unsigned int mcdi_err
)
148 #define TRANSLATE_ERROR(name) \
149 case MC_CMD_ERR_ ## name: \
151 TRANSLATE_ERROR(EPERM
);
152 TRANSLATE_ERROR(ENOENT
);
153 TRANSLATE_ERROR(EINTR
);
154 TRANSLATE_ERROR(EAGAIN
);
155 TRANSLATE_ERROR(EACCES
);
156 TRANSLATE_ERROR(EBUSY
);
157 TRANSLATE_ERROR(EINVAL
);
158 TRANSLATE_ERROR(EDEADLK
);
159 TRANSLATE_ERROR(ENOSYS
);
160 TRANSLATE_ERROR(ETIME
);
161 TRANSLATE_ERROR(EALREADY
);
162 TRANSLATE_ERROR(ENOSPC
);
163 #undef TRANSLATE_ERROR
164 case MC_CMD_ERR_ALLOC_FAIL
:
166 case MC_CMD_ERR_MAC_EXIST
:
173 static void efx_mcdi_read_response_header(struct efx_nic
*efx
)
175 struct efx_mcdi_iface
*mcdi
= efx_mcdi(efx
);
176 unsigned int respseq
, respcmd
, error
;
179 efx
->type
->mcdi_read_response(efx
, &hdr
, 0, 4);
180 respseq
= EFX_DWORD_FIELD(hdr
, MCDI_HEADER_SEQ
);
181 respcmd
= EFX_DWORD_FIELD(hdr
, MCDI_HEADER_CODE
);
182 error
= EFX_DWORD_FIELD(hdr
, MCDI_HEADER_ERROR
);
184 if (respcmd
!= MC_CMD_V2_EXTN
) {
185 mcdi
->resp_hdr_len
= 4;
186 mcdi
->resp_data_len
= EFX_DWORD_FIELD(hdr
, MCDI_HEADER_DATALEN
);
188 efx
->type
->mcdi_read_response(efx
, &hdr
, 4, 4);
189 mcdi
->resp_hdr_len
= 8;
190 mcdi
->resp_data_len
=
191 EFX_DWORD_FIELD(hdr
, MC_CMD_V2_EXTN_IN_ACTUAL_LEN
);
194 if (error
&& mcdi
->resp_data_len
== 0) {
195 netif_err(efx
, hw
, efx
->net_dev
, "MC rebooted\n");
197 } else if ((respseq
^ mcdi
->seqno
) & SEQ_MASK
) {
198 netif_err(efx
, hw
, efx
->net_dev
,
199 "MC response mismatch tx seq 0x%x rx seq 0x%x\n",
200 respseq
, mcdi
->seqno
);
203 efx
->type
->mcdi_read_response(efx
, &hdr
, mcdi
->resp_hdr_len
, 4);
205 efx_mcdi_errno(EFX_DWORD_FIELD(hdr
, EFX_DWORD_0
));
211 static int efx_mcdi_poll(struct efx_nic
*efx
)
213 struct efx_mcdi_iface
*mcdi
= efx_mcdi(efx
);
214 unsigned long time
, finish
;
218 /* Check for a reboot atomically with respect to efx_mcdi_copyout() */
219 rc
= efx_mcdi_poll_reboot(efx
);
221 spin_lock_bh(&mcdi
->iface_lock
);
223 mcdi
->resp_hdr_len
= 0;
224 mcdi
->resp_data_len
= 0;
225 spin_unlock_bh(&mcdi
->iface_lock
);
229 /* Poll for completion. Poll quickly (once a us) for the 1st jiffy,
230 * because generally mcdi responses are fast. After that, back off
231 * and poll once a jiffy (approximately)
234 finish
= jiffies
+ MCDI_RPC_TIMEOUT
;
241 schedule_timeout_uninterruptible(1);
247 if (efx
->type
->mcdi_poll_response(efx
))
250 if (time_after(time
, finish
))
254 spin_lock_bh(&mcdi
->iface_lock
);
255 efx_mcdi_read_response_header(efx
);
256 spin_unlock_bh(&mcdi
->iface_lock
);
258 /* Return rc=0 like wait_event_timeout() */
262 /* Test and clear MC-rebooted flag for this port/function; reset
263 * software state as necessary.
265 int efx_mcdi_poll_reboot(struct efx_nic
*efx
)
270 return efx
->type
->mcdi_poll_reboot(efx
);
273 static bool efx_mcdi_acquire_async(struct efx_mcdi_iface
*mcdi
)
275 return cmpxchg(&mcdi
->state
,
276 MCDI_STATE_QUIESCENT
, MCDI_STATE_RUNNING_ASYNC
) ==
277 MCDI_STATE_QUIESCENT
;
280 static void efx_mcdi_acquire_sync(struct efx_mcdi_iface
*mcdi
)
282 /* Wait until the interface becomes QUIESCENT and we win the race
283 * to mark it RUNNING_SYNC.
286 cmpxchg(&mcdi
->state
,
287 MCDI_STATE_QUIESCENT
, MCDI_STATE_RUNNING_SYNC
) ==
288 MCDI_STATE_QUIESCENT
);
291 static int efx_mcdi_await_completion(struct efx_nic
*efx
)
293 struct efx_mcdi_iface
*mcdi
= efx_mcdi(efx
);
295 if (wait_event_timeout(mcdi
->wq
, mcdi
->state
== MCDI_STATE_COMPLETED
,
296 MCDI_RPC_TIMEOUT
) == 0)
299 /* Check if efx_mcdi_set_mode() switched us back to polled completions.
300 * In which case, poll for completions directly. If efx_mcdi_ev_cpl()
301 * completed the request first, then we'll just end up completing the
302 * request again, which is safe.
304 * We need an smp_rmb() to synchronise with efx_mcdi_mode_poll(), which
305 * wait_event_timeout() implicitly provides.
307 if (mcdi
->mode
== MCDI_MODE_POLL
)
308 return efx_mcdi_poll(efx
);
313 /* If the interface is RUNNING_SYNC, switch to COMPLETED and wake the
314 * requester. Return whether this was done. Does not take any locks.
316 static bool efx_mcdi_complete_sync(struct efx_mcdi_iface
*mcdi
)
318 if (cmpxchg(&mcdi
->state
,
319 MCDI_STATE_RUNNING_SYNC
, MCDI_STATE_COMPLETED
) ==
320 MCDI_STATE_RUNNING_SYNC
) {
328 static void efx_mcdi_release(struct efx_mcdi_iface
*mcdi
)
330 if (mcdi
->mode
== MCDI_MODE_EVENTS
) {
331 struct efx_mcdi_async_param
*async
;
332 struct efx_nic
*efx
= mcdi
->efx
;
334 /* Process the asynchronous request queue */
335 spin_lock_bh(&mcdi
->async_lock
);
336 async
= list_first_entry_or_null(
337 &mcdi
->async_list
, struct efx_mcdi_async_param
, list
);
339 mcdi
->state
= MCDI_STATE_RUNNING_ASYNC
;
340 efx_mcdi_send_request(efx
, async
->cmd
,
341 (const efx_dword_t
*)(async
+ 1),
343 mod_timer(&mcdi
->async_timer
,
344 jiffies
+ MCDI_RPC_TIMEOUT
);
346 spin_unlock_bh(&mcdi
->async_lock
);
352 mcdi
->state
= MCDI_STATE_QUIESCENT
;
356 /* If the interface is RUNNING_ASYNC, switch to COMPLETED, call the
357 * asynchronous completion function, and release the interface.
358 * Return whether this was done. Must be called in bh-disabled
359 * context. Will take iface_lock and async_lock.
361 static bool efx_mcdi_complete_async(struct efx_mcdi_iface
*mcdi
, bool timeout
)
363 struct efx_nic
*efx
= mcdi
->efx
;
364 struct efx_mcdi_async_param
*async
;
365 size_t hdr_len
, data_len
;
369 if (cmpxchg(&mcdi
->state
,
370 MCDI_STATE_RUNNING_ASYNC
, MCDI_STATE_COMPLETED
) !=
371 MCDI_STATE_RUNNING_ASYNC
)
374 spin_lock(&mcdi
->iface_lock
);
376 /* Ensure that if the completion event arrives later,
377 * the seqno check in efx_mcdi_ev_cpl() will fail
386 hdr_len
= mcdi
->resp_hdr_len
;
387 data_len
= mcdi
->resp_data_len
;
389 spin_unlock(&mcdi
->iface_lock
);
391 /* Stop the timer. In case the timer function is running, we
392 * must wait for it to return so that there is no possibility
393 * of it aborting the next request.
396 del_timer_sync(&mcdi
->async_timer
);
398 spin_lock(&mcdi
->async_lock
);
399 async
= list_first_entry(&mcdi
->async_list
,
400 struct efx_mcdi_async_param
, list
);
401 list_del(&async
->list
);
402 spin_unlock(&mcdi
->async_lock
);
404 outbuf
= (efx_dword_t
*)(async
+ 1);
405 efx
->type
->mcdi_read_response(efx
, outbuf
, hdr_len
,
406 min(async
->outlen
, data_len
));
407 async
->complete(efx
, async
->cookie
, rc
, outbuf
, data_len
);
410 efx_mcdi_release(mcdi
);
415 static void efx_mcdi_ev_cpl(struct efx_nic
*efx
, unsigned int seqno
,
416 unsigned int datalen
, unsigned int mcdi_err
)
418 struct efx_mcdi_iface
*mcdi
= efx_mcdi(efx
);
421 spin_lock(&mcdi
->iface_lock
);
423 if ((seqno
^ mcdi
->seqno
) & SEQ_MASK
) {
425 /* The request has been cancelled */
428 netif_err(efx
, hw
, efx
->net_dev
,
429 "MC response mismatch tx seq 0x%x rx "
430 "seq 0x%x\n", seqno
, mcdi
->seqno
);
432 if (efx
->type
->mcdi_max_ver
>= 2) {
433 /* MCDI v2 responses don't fit in an event */
434 efx_mcdi_read_response_header(efx
);
436 mcdi
->resprc
= efx_mcdi_errno(mcdi_err
);
437 mcdi
->resp_hdr_len
= 4;
438 mcdi
->resp_data_len
= datalen
;
444 spin_unlock(&mcdi
->iface_lock
);
447 if (!efx_mcdi_complete_async(mcdi
, false))
448 (void) efx_mcdi_complete_sync(mcdi
);
450 /* If the interface isn't RUNNING_ASYNC or
451 * RUNNING_SYNC then we've received a duplicate
452 * completion after we've already transitioned back to
453 * QUIESCENT. [A subsequent invocation would increment
454 * seqno, so would have failed the seqno check].
459 static void efx_mcdi_timeout_async(unsigned long context
)
461 struct efx_mcdi_iface
*mcdi
= (struct efx_mcdi_iface
*)context
;
463 efx_mcdi_complete_async(mcdi
, true);
467 efx_mcdi_check_supported(struct efx_nic
*efx
, unsigned int cmd
, size_t inlen
)
469 if (efx
->type
->mcdi_max_ver
< 0 ||
470 (efx
->type
->mcdi_max_ver
< 2 &&
471 cmd
> MC_CMD_CMD_SPACE_ESCAPE_7
))
474 if (inlen
> MCDI_CTL_SDU_LEN_MAX_V2
||
475 (efx
->type
->mcdi_max_ver
< 2 &&
476 inlen
> MCDI_CTL_SDU_LEN_MAX_V1
))
482 int efx_mcdi_rpc(struct efx_nic
*efx
, unsigned cmd
,
483 const efx_dword_t
*inbuf
, size_t inlen
,
484 efx_dword_t
*outbuf
, size_t outlen
,
485 size_t *outlen_actual
)
489 rc
= efx_mcdi_rpc_start(efx
, cmd
, inbuf
, inlen
);
492 return efx_mcdi_rpc_finish(efx
, cmd
, inlen
,
493 outbuf
, outlen
, outlen_actual
);
496 int efx_mcdi_rpc_start(struct efx_nic
*efx
, unsigned cmd
,
497 const efx_dword_t
*inbuf
, size_t inlen
)
499 struct efx_mcdi_iface
*mcdi
= efx_mcdi(efx
);
502 rc
= efx_mcdi_check_supported(efx
, cmd
, inlen
);
506 efx_mcdi_acquire_sync(mcdi
);
507 efx_mcdi_send_request(efx
, cmd
, inbuf
, inlen
);
512 * efx_mcdi_rpc_async - Schedule an MCDI command to run asynchronously
513 * @efx: NIC through which to issue the command
514 * @cmd: Command type number
515 * @inbuf: Command parameters
516 * @inlen: Length of command parameters, in bytes
517 * @outlen: Length to allocate for response buffer, in bytes
518 * @complete: Function to be called on completion or cancellation.
519 * @cookie: Arbitrary value to be passed to @complete.
521 * This function does not sleep and therefore may be called in atomic
522 * context. It will fail if event queues are disabled or if MCDI
523 * event completions have been disabled due to an error.
525 * If it succeeds, the @complete function will be called exactly once
526 * in atomic context, when one of the following occurs:
527 * (a) the completion event is received (in NAPI context)
528 * (b) event queues are disabled (in the process that disables them)
529 * (c) the request times-out (in timer context)
532 efx_mcdi_rpc_async(struct efx_nic
*efx
, unsigned int cmd
,
533 const efx_dword_t
*inbuf
, size_t inlen
, size_t outlen
,
534 efx_mcdi_async_completer
*complete
, unsigned long cookie
)
536 struct efx_mcdi_iface
*mcdi
= efx_mcdi(efx
);
537 struct efx_mcdi_async_param
*async
;
540 rc
= efx_mcdi_check_supported(efx
, cmd
, inlen
);
544 async
= kmalloc(sizeof(*async
) + ALIGN(max(inlen
, outlen
), 4),
550 async
->inlen
= inlen
;
551 async
->outlen
= outlen
;
552 async
->complete
= complete
;
553 async
->cookie
= cookie
;
554 memcpy(async
+ 1, inbuf
, inlen
);
556 spin_lock_bh(&mcdi
->async_lock
);
558 if (mcdi
->mode
== MCDI_MODE_EVENTS
) {
559 list_add_tail(&async
->list
, &mcdi
->async_list
);
561 /* If this is at the front of the queue, try to start it
564 if (mcdi
->async_list
.next
== &async
->list
&&
565 efx_mcdi_acquire_async(mcdi
)) {
566 efx_mcdi_send_request(efx
, cmd
, inbuf
, inlen
);
567 mod_timer(&mcdi
->async_timer
,
568 jiffies
+ MCDI_RPC_TIMEOUT
);
575 spin_unlock_bh(&mcdi
->async_lock
);
580 int efx_mcdi_rpc_finish(struct efx_nic
*efx
, unsigned cmd
, size_t inlen
,
581 efx_dword_t
*outbuf
, size_t outlen
,
582 size_t *outlen_actual
)
584 struct efx_mcdi_iface
*mcdi
= efx_mcdi(efx
);
587 if (mcdi
->mode
== MCDI_MODE_POLL
)
588 rc
= efx_mcdi_poll(efx
);
590 rc
= efx_mcdi_await_completion(efx
);
593 /* Close the race with efx_mcdi_ev_cpl() executing just too late
594 * and completing a request we've just cancelled, by ensuring
595 * that the seqno check therein fails.
597 spin_lock_bh(&mcdi
->iface_lock
);
600 spin_unlock_bh(&mcdi
->iface_lock
);
602 netif_err(efx
, hw
, efx
->net_dev
,
603 "MC command 0x%x inlen %d mode %d timed out\n",
604 cmd
, (int)inlen
, mcdi
->mode
);
606 size_t hdr_len
, data_len
;
608 /* At the very least we need a memory barrier here to ensure
609 * we pick up changes from efx_mcdi_ev_cpl(). Protect against
610 * a spurious efx_mcdi_ev_cpl() running concurrently by
611 * acquiring the iface_lock. */
612 spin_lock_bh(&mcdi
->iface_lock
);
614 hdr_len
= mcdi
->resp_hdr_len
;
615 data_len
= mcdi
->resp_data_len
;
616 spin_unlock_bh(&mcdi
->iface_lock
);
621 efx
->type
->mcdi_read_response(efx
, outbuf
, hdr_len
,
622 min(outlen
, data_len
));
623 if (outlen_actual
!= NULL
)
624 *outlen_actual
= data_len
;
625 } else if (cmd
== MC_CMD_REBOOT
&& rc
== -EIO
)
626 ; /* Don't reset if MC_CMD_REBOOT returns EIO */
627 else if (rc
== -EIO
|| rc
== -EINTR
) {
628 netif_err(efx
, hw
, efx
->net_dev
, "MC fatal error %d\n",
630 efx_schedule_reset(efx
, RESET_TYPE_MC_FAILURE
);
632 netif_dbg(efx
, hw
, efx
->net_dev
,
633 "MC command 0x%x inlen %d failed rc=%d\n",
634 cmd
, (int)inlen
, -rc
);
636 if (rc
== -EIO
|| rc
== -EINTR
) {
637 msleep(MCDI_STATUS_SLEEP_MS
);
638 efx_mcdi_poll_reboot(efx
);
639 mcdi
->new_epoch
= true;
643 efx_mcdi_release(mcdi
);
647 /* Switch to polled MCDI completions. This can be called in various
648 * error conditions with various locks held, so it must be lockless.
649 * Caller is responsible for flushing asynchronous requests later.
651 void efx_mcdi_mode_poll(struct efx_nic
*efx
)
653 struct efx_mcdi_iface
*mcdi
;
658 mcdi
= efx_mcdi(efx
);
659 if (mcdi
->mode
== MCDI_MODE_POLL
)
662 /* We can switch from event completion to polled completion, because
663 * mcdi requests are always completed in shared memory. We do this by
664 * switching the mode to POLL'd then completing the request.
665 * efx_mcdi_await_completion() will then call efx_mcdi_poll().
667 * We need an smp_wmb() to synchronise with efx_mcdi_await_completion(),
668 * which efx_mcdi_complete_sync() provides for us.
670 mcdi
->mode
= MCDI_MODE_POLL
;
672 efx_mcdi_complete_sync(mcdi
);
675 /* Flush any running or queued asynchronous requests, after event processing
678 void efx_mcdi_flush_async(struct efx_nic
*efx
)
680 struct efx_mcdi_async_param
*async
, *next
;
681 struct efx_mcdi_iface
*mcdi
;
686 mcdi
= efx_mcdi(efx
);
688 /* We must be in polling mode so no more requests can be queued */
689 BUG_ON(mcdi
->mode
!= MCDI_MODE_POLL
);
691 del_timer_sync(&mcdi
->async_timer
);
693 /* If a request is still running, make sure we give the MC
694 * time to complete it so that the response won't overwrite our
697 if (mcdi
->state
== MCDI_STATE_RUNNING_ASYNC
) {
699 mcdi
->state
= MCDI_STATE_QUIESCENT
;
702 /* Nothing else will access the async list now, so it is safe
703 * to walk it without holding async_lock. If we hold it while
704 * calling a completer then lockdep may warn that we have
705 * acquired locks in the wrong order.
707 list_for_each_entry_safe(async
, next
, &mcdi
->async_list
, list
) {
708 async
->complete(efx
, async
->cookie
, -ENETDOWN
, NULL
, 0);
709 list_del(&async
->list
);
714 void efx_mcdi_mode_event(struct efx_nic
*efx
)
716 struct efx_mcdi_iface
*mcdi
;
721 mcdi
= efx_mcdi(efx
);
723 if (mcdi
->mode
== MCDI_MODE_EVENTS
)
726 /* We can't switch from polled to event completion in the middle of a
727 * request, because the completion method is specified in the request.
728 * So acquire the interface to serialise the requestors. We don't need
729 * to acquire the iface_lock to change the mode here, but we do need a
730 * write memory barrier ensure that efx_mcdi_rpc() sees it, which
731 * efx_mcdi_acquire() provides.
733 efx_mcdi_acquire_sync(mcdi
);
734 mcdi
->mode
= MCDI_MODE_EVENTS
;
735 efx_mcdi_release(mcdi
);
738 static void efx_mcdi_ev_death(struct efx_nic
*efx
, int rc
)
740 struct efx_mcdi_iface
*mcdi
= efx_mcdi(efx
);
742 /* If there is an outstanding MCDI request, it has been terminated
743 * either by a BADASSERT or REBOOT event. If the mcdi interface is
744 * in polled mode, then do nothing because the MC reboot handler will
745 * set the header correctly. However, if the mcdi interface is waiting
746 * for a CMDDONE event it won't receive it [and since all MCDI events
747 * are sent to the same queue, we can't be racing with
750 * If there is an outstanding asynchronous request, we can't
751 * complete it now (efx_mcdi_complete() would deadlock). The
752 * reset process will take care of this.
754 * There's a race here with efx_mcdi_send_request(), because
755 * we might receive a REBOOT event *before* the request has
756 * been copied out. In polled mode (during startup) this is
757 * irrelevant, because efx_mcdi_complete_sync() is ignored. In
758 * event mode, this condition is just an edge-case of
759 * receiving a REBOOT event after posting the MCDI
760 * request. Did the mc reboot before or after the copyout? The
761 * best we can do always is just return failure.
763 spin_lock(&mcdi
->iface_lock
);
764 if (efx_mcdi_complete_sync(mcdi
)) {
765 if (mcdi
->mode
== MCDI_MODE_EVENTS
) {
767 mcdi
->resp_hdr_len
= 0;
768 mcdi
->resp_data_len
= 0;
774 /* Nobody was waiting for an MCDI request, so trigger a reset */
775 efx_schedule_reset(efx
, RESET_TYPE_MC_FAILURE
);
777 /* Consume the status word since efx_mcdi_rpc_finish() won't */
778 for (count
= 0; count
< MCDI_STATUS_DELAY_COUNT
; ++count
) {
779 if (efx_mcdi_poll_reboot(efx
))
781 udelay(MCDI_STATUS_DELAY_US
);
783 mcdi
->new_epoch
= true;
786 spin_unlock(&mcdi
->iface_lock
);
789 /* Called from falcon_process_eventq for MCDI events */
790 void efx_mcdi_process_event(struct efx_channel
*channel
,
793 struct efx_nic
*efx
= channel
->efx
;
794 int code
= EFX_QWORD_FIELD(*event
, MCDI_EVENT_CODE
);
795 u32 data
= EFX_QWORD_FIELD(*event
, MCDI_EVENT_DATA
);
798 case MCDI_EVENT_CODE_BADSSERT
:
799 netif_err(efx
, hw
, efx
->net_dev
,
800 "MC watchdog or assertion failure at 0x%x\n", data
);
801 efx_mcdi_ev_death(efx
, -EINTR
);
804 case MCDI_EVENT_CODE_PMNOTICE
:
805 netif_info(efx
, wol
, efx
->net_dev
, "MCDI PM event.\n");
808 case MCDI_EVENT_CODE_CMDDONE
:
810 MCDI_EVENT_FIELD(*event
, CMDDONE_SEQ
),
811 MCDI_EVENT_FIELD(*event
, CMDDONE_DATALEN
),
812 MCDI_EVENT_FIELD(*event
, CMDDONE_ERRNO
));
815 case MCDI_EVENT_CODE_LINKCHANGE
:
816 efx_mcdi_process_link_change(efx
, event
);
818 case MCDI_EVENT_CODE_SENSOREVT
:
819 efx_mcdi_sensor_event(efx
, event
);
821 case MCDI_EVENT_CODE_SCHEDERR
:
822 netif_info(efx
, hw
, efx
->net_dev
,
823 "MC Scheduler error address=0x%x\n", data
);
825 case MCDI_EVENT_CODE_REBOOT
:
826 netif_info(efx
, hw
, efx
->net_dev
, "MC Reboot\n");
827 efx_mcdi_ev_death(efx
, -EIO
);
829 case MCDI_EVENT_CODE_MAC_STATS_DMA
:
830 /* MAC stats are gather lazily. We can ignore this. */
832 case MCDI_EVENT_CODE_FLR
:
833 efx_sriov_flr(efx
, MCDI_EVENT_FIELD(*event
, FLR_VF
));
835 case MCDI_EVENT_CODE_PTP_RX
:
836 case MCDI_EVENT_CODE_PTP_FAULT
:
837 case MCDI_EVENT_CODE_PTP_PPS
:
838 efx_ptp_event(efx
, event
);
841 case MCDI_EVENT_CODE_TX_ERR
:
842 case MCDI_EVENT_CODE_RX_ERR
:
843 netif_err(efx
, hw
, efx
->net_dev
,
844 "%s DMA error (event: "EFX_QWORD_FMT
")\n",
845 code
== MCDI_EVENT_CODE_TX_ERR
? "TX" : "RX",
846 EFX_QWORD_VAL(*event
));
847 efx_schedule_reset(efx
, RESET_TYPE_DMA_ERROR
);
850 netif_err(efx
, hw
, efx
->net_dev
, "Unknown MCDI event 0x%x\n",
855 /**************************************************************************
857 * Specific request functions
859 **************************************************************************
862 void efx_mcdi_print_fwver(struct efx_nic
*efx
, char *buf
, size_t len
)
864 MCDI_DECLARE_BUF(outbuf
, MC_CMD_GET_VERSION_OUT_LEN
);
866 const __le16
*ver_words
;
869 BUILD_BUG_ON(MC_CMD_GET_VERSION_IN_LEN
!= 0);
871 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_VERSION
, NULL
, 0,
872 outbuf
, sizeof(outbuf
), &outlength
);
876 if (outlength
< MC_CMD_GET_VERSION_OUT_LEN
) {
881 ver_words
= (__le16
*)MCDI_PTR(outbuf
, GET_VERSION_OUT_VERSION
);
882 snprintf(buf
, len
, "%u.%u.%u.%u",
883 le16_to_cpu(ver_words
[0]), le16_to_cpu(ver_words
[1]),
884 le16_to_cpu(ver_words
[2]), le16_to_cpu(ver_words
[3]));
888 netif_err(efx
, probe
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
892 int efx_mcdi_drv_attach(struct efx_nic
*efx
, bool driver_operating
,
895 MCDI_DECLARE_BUF(inbuf
, MC_CMD_DRV_ATTACH_IN_LEN
);
896 MCDI_DECLARE_BUF(outbuf
, MC_CMD_DRV_ATTACH_OUT_LEN
);
900 MCDI_SET_DWORD(inbuf
, DRV_ATTACH_IN_NEW_STATE
,
901 driver_operating
? 1 : 0);
902 MCDI_SET_DWORD(inbuf
, DRV_ATTACH_IN_UPDATE
, 1);
903 MCDI_SET_DWORD(inbuf
, DRV_ATTACH_IN_FIRMWARE_ID
, MC_CMD_FW_LOW_LATENCY
);
905 rc
= efx_mcdi_rpc(efx
, MC_CMD_DRV_ATTACH
, inbuf
, sizeof(inbuf
),
906 outbuf
, sizeof(outbuf
), &outlen
);
909 if (outlen
< MC_CMD_DRV_ATTACH_OUT_LEN
) {
914 if (was_attached
!= NULL
)
915 *was_attached
= MCDI_DWORD(outbuf
, DRV_ATTACH_OUT_OLD_STATE
);
919 netif_err(efx
, probe
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
923 int efx_mcdi_get_board_cfg(struct efx_nic
*efx
, u8
*mac_address
,
924 u16
*fw_subtype_list
, u32
*capabilities
)
926 MCDI_DECLARE_BUF(outbuf
, MC_CMD_GET_BOARD_CFG_OUT_LENMAX
);
928 int port_num
= efx_port_num(efx
);
931 BUILD_BUG_ON(MC_CMD_GET_BOARD_CFG_IN_LEN
!= 0);
933 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_BOARD_CFG
, NULL
, 0,
934 outbuf
, sizeof(outbuf
), &outlen
);
938 if (outlen
< MC_CMD_GET_BOARD_CFG_OUT_LENMIN
) {
946 MCDI_PTR(outbuf
, GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT1
) :
947 MCDI_PTR(outbuf
, GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT0
),
949 if (fw_subtype_list
) {
951 i
< MCDI_VAR_ARRAY_LEN(outlen
,
952 GET_BOARD_CFG_OUT_FW_SUBTYPE_LIST
);
954 fw_subtype_list
[i
] = MCDI_ARRAY_WORD(
955 outbuf
, GET_BOARD_CFG_OUT_FW_SUBTYPE_LIST
, i
);
956 for (; i
< MC_CMD_GET_BOARD_CFG_OUT_FW_SUBTYPE_LIST_MAXNUM
; i
++)
957 fw_subtype_list
[i
] = 0;
961 *capabilities
= MCDI_DWORD(outbuf
,
962 GET_BOARD_CFG_OUT_CAPABILITIES_PORT1
);
964 *capabilities
= MCDI_DWORD(outbuf
,
965 GET_BOARD_CFG_OUT_CAPABILITIES_PORT0
);
971 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d len=%d\n",
972 __func__
, rc
, (int)outlen
);
977 int efx_mcdi_log_ctrl(struct efx_nic
*efx
, bool evq
, bool uart
, u32 dest_evq
)
979 MCDI_DECLARE_BUF(inbuf
, MC_CMD_LOG_CTRL_IN_LEN
);
984 dest
|= MC_CMD_LOG_CTRL_IN_LOG_DEST_UART
;
986 dest
|= MC_CMD_LOG_CTRL_IN_LOG_DEST_EVQ
;
988 MCDI_SET_DWORD(inbuf
, LOG_CTRL_IN_LOG_DEST
, dest
);
989 MCDI_SET_DWORD(inbuf
, LOG_CTRL_IN_LOG_DEST_EVQ
, dest_evq
);
991 BUILD_BUG_ON(MC_CMD_LOG_CTRL_OUT_LEN
!= 0);
993 rc
= efx_mcdi_rpc(efx
, MC_CMD_LOG_CTRL
, inbuf
, sizeof(inbuf
),
1001 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
1005 int efx_mcdi_nvram_types(struct efx_nic
*efx
, u32
*nvram_types_out
)
1007 MCDI_DECLARE_BUF(outbuf
, MC_CMD_NVRAM_TYPES_OUT_LEN
);
1011 BUILD_BUG_ON(MC_CMD_NVRAM_TYPES_IN_LEN
!= 0);
1013 rc
= efx_mcdi_rpc(efx
, MC_CMD_NVRAM_TYPES
, NULL
, 0,
1014 outbuf
, sizeof(outbuf
), &outlen
);
1017 if (outlen
< MC_CMD_NVRAM_TYPES_OUT_LEN
) {
1022 *nvram_types_out
= MCDI_DWORD(outbuf
, NVRAM_TYPES_OUT_TYPES
);
1026 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n",
1031 int efx_mcdi_nvram_info(struct efx_nic
*efx
, unsigned int type
,
1032 size_t *size_out
, size_t *erase_size_out
,
1033 bool *protected_out
)
1035 MCDI_DECLARE_BUF(inbuf
, MC_CMD_NVRAM_INFO_IN_LEN
);
1036 MCDI_DECLARE_BUF(outbuf
, MC_CMD_NVRAM_INFO_OUT_LEN
);
1040 MCDI_SET_DWORD(inbuf
, NVRAM_INFO_IN_TYPE
, type
);
1042 rc
= efx_mcdi_rpc(efx
, MC_CMD_NVRAM_INFO
, inbuf
, sizeof(inbuf
),
1043 outbuf
, sizeof(outbuf
), &outlen
);
1046 if (outlen
< MC_CMD_NVRAM_INFO_OUT_LEN
) {
1051 *size_out
= MCDI_DWORD(outbuf
, NVRAM_INFO_OUT_SIZE
);
1052 *erase_size_out
= MCDI_DWORD(outbuf
, NVRAM_INFO_OUT_ERASESIZE
);
1053 *protected_out
= !!(MCDI_DWORD(outbuf
, NVRAM_INFO_OUT_FLAGS
) &
1054 (1 << MC_CMD_NVRAM_INFO_OUT_PROTECTED_LBN
));
1058 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
1062 static int efx_mcdi_nvram_test(struct efx_nic
*efx
, unsigned int type
)
1064 MCDI_DECLARE_BUF(inbuf
, MC_CMD_NVRAM_TEST_IN_LEN
);
1065 MCDI_DECLARE_BUF(outbuf
, MC_CMD_NVRAM_TEST_OUT_LEN
);
1068 MCDI_SET_DWORD(inbuf
, NVRAM_TEST_IN_TYPE
, type
);
1070 rc
= efx_mcdi_rpc(efx
, MC_CMD_NVRAM_TEST
, inbuf
, sizeof(inbuf
),
1071 outbuf
, sizeof(outbuf
), NULL
);
1075 switch (MCDI_DWORD(outbuf
, NVRAM_TEST_OUT_RESULT
)) {
1076 case MC_CMD_NVRAM_TEST_PASS
:
1077 case MC_CMD_NVRAM_TEST_NOTSUPP
:
1084 int efx_mcdi_nvram_test_all(struct efx_nic
*efx
)
1090 rc
= efx_mcdi_nvram_types(efx
, &nvram_types
);
1095 while (nvram_types
!= 0) {
1096 if (nvram_types
& 1) {
1097 rc
= efx_mcdi_nvram_test(efx
, type
);
1108 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed type=%u\n",
1111 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
1115 static int efx_mcdi_read_assertion(struct efx_nic
*efx
)
1117 MCDI_DECLARE_BUF(inbuf
, MC_CMD_GET_ASSERTS_IN_LEN
);
1118 MCDI_DECLARE_BUF(outbuf
, MC_CMD_GET_ASSERTS_OUT_LEN
);
1119 unsigned int flags
, index
;
1125 /* Attempt to read any stored assertion state before we reboot
1126 * the mcfw out of the assertion handler. Retry twice, once
1127 * because a boot-time assertion might cause this command to fail
1128 * with EINTR. And once again because GET_ASSERTS can race with
1129 * MC_CMD_REBOOT running on the other port. */
1132 MCDI_SET_DWORD(inbuf
, GET_ASSERTS_IN_CLEAR
, 1);
1133 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_ASSERTS
,
1134 inbuf
, MC_CMD_GET_ASSERTS_IN_LEN
,
1135 outbuf
, sizeof(outbuf
), &outlen
);
1136 } while ((rc
== -EINTR
|| rc
== -EIO
) && retry
-- > 0);
1140 if (outlen
< MC_CMD_GET_ASSERTS_OUT_LEN
)
1143 /* Print out any recorded assertion state */
1144 flags
= MCDI_DWORD(outbuf
, GET_ASSERTS_OUT_GLOBAL_FLAGS
);
1145 if (flags
== MC_CMD_GET_ASSERTS_FLAGS_NO_FAILS
)
1148 reason
= (flags
== MC_CMD_GET_ASSERTS_FLAGS_SYS_FAIL
)
1149 ? "system-level assertion"
1150 : (flags
== MC_CMD_GET_ASSERTS_FLAGS_THR_FAIL
)
1151 ? "thread-level assertion"
1152 : (flags
== MC_CMD_GET_ASSERTS_FLAGS_WDOG_FIRED
)
1154 : "unknown assertion";
1155 netif_err(efx
, hw
, efx
->net_dev
,
1156 "MCPU %s at PC = 0x%.8x in thread 0x%.8x\n", reason
,
1157 MCDI_DWORD(outbuf
, GET_ASSERTS_OUT_SAVED_PC_OFFS
),
1158 MCDI_DWORD(outbuf
, GET_ASSERTS_OUT_THREAD_OFFS
));
1160 /* Print out the registers */
1162 index
< MC_CMD_GET_ASSERTS_OUT_GP_REGS_OFFS_NUM
;
1164 netif_err(efx
, hw
, efx
->net_dev
, "R%.2d (?): 0x%.8x\n",
1166 MCDI_ARRAY_DWORD(outbuf
, GET_ASSERTS_OUT_GP_REGS_OFFS
,
1172 static void efx_mcdi_exit_assertion(struct efx_nic
*efx
)
1174 MCDI_DECLARE_BUF(inbuf
, MC_CMD_REBOOT_IN_LEN
);
1176 /* If the MC is running debug firmware, it might now be
1177 * waiting for a debugger to attach, but we just want it to
1178 * reboot. We set a flag that makes the command a no-op if it
1179 * has already done so. We don't know what return code to
1180 * expect (0 or -EIO), so ignore it.
1182 BUILD_BUG_ON(MC_CMD_REBOOT_OUT_LEN
!= 0);
1183 MCDI_SET_DWORD(inbuf
, REBOOT_IN_FLAGS
,
1184 MC_CMD_REBOOT_FLAGS_AFTER_ASSERTION
);
1185 (void) efx_mcdi_rpc(efx
, MC_CMD_REBOOT
, inbuf
, MC_CMD_REBOOT_IN_LEN
,
1189 int efx_mcdi_handle_assertion(struct efx_nic
*efx
)
1193 rc
= efx_mcdi_read_assertion(efx
);
1197 efx_mcdi_exit_assertion(efx
);
1202 void efx_mcdi_set_id_led(struct efx_nic
*efx
, enum efx_led_mode mode
)
1204 MCDI_DECLARE_BUF(inbuf
, MC_CMD_SET_ID_LED_IN_LEN
);
1207 BUILD_BUG_ON(EFX_LED_OFF
!= MC_CMD_LED_OFF
);
1208 BUILD_BUG_ON(EFX_LED_ON
!= MC_CMD_LED_ON
);
1209 BUILD_BUG_ON(EFX_LED_DEFAULT
!= MC_CMD_LED_DEFAULT
);
1211 BUILD_BUG_ON(MC_CMD_SET_ID_LED_OUT_LEN
!= 0);
1213 MCDI_SET_DWORD(inbuf
, SET_ID_LED_IN_STATE
, mode
);
1215 rc
= efx_mcdi_rpc(efx
, MC_CMD_SET_ID_LED
, inbuf
, sizeof(inbuf
),
1218 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n",
1222 static int efx_mcdi_reset_port(struct efx_nic
*efx
)
1224 int rc
= efx_mcdi_rpc(efx
, MC_CMD_ENTITY_RESET
, NULL
, 0, NULL
, 0, NULL
);
1226 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n",
1231 static int efx_mcdi_reset_mc(struct efx_nic
*efx
)
1233 MCDI_DECLARE_BUF(inbuf
, MC_CMD_REBOOT_IN_LEN
);
1236 BUILD_BUG_ON(MC_CMD_REBOOT_OUT_LEN
!= 0);
1237 MCDI_SET_DWORD(inbuf
, REBOOT_IN_FLAGS
, 0);
1238 rc
= efx_mcdi_rpc(efx
, MC_CMD_REBOOT
, inbuf
, sizeof(inbuf
),
1240 /* White is black, and up is down */
1245 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
1249 enum reset_type
efx_mcdi_map_reset_reason(enum reset_type reason
)
1251 return RESET_TYPE_RECOVER_OR_ALL
;
1254 int efx_mcdi_reset(struct efx_nic
*efx
, enum reset_type method
)
1258 /* Recover from a failed assertion pre-reset */
1259 rc
= efx_mcdi_handle_assertion(efx
);
1263 if (method
== RESET_TYPE_WORLD
)
1264 return efx_mcdi_reset_mc(efx
);
1266 return efx_mcdi_reset_port(efx
);
1269 static int efx_mcdi_wol_filter_set(struct efx_nic
*efx
, u32 type
,
1270 const u8
*mac
, int *id_out
)
1272 MCDI_DECLARE_BUF(inbuf
, MC_CMD_WOL_FILTER_SET_IN_LEN
);
1273 MCDI_DECLARE_BUF(outbuf
, MC_CMD_WOL_FILTER_SET_OUT_LEN
);
1277 MCDI_SET_DWORD(inbuf
, WOL_FILTER_SET_IN_WOL_TYPE
, type
);
1278 MCDI_SET_DWORD(inbuf
, WOL_FILTER_SET_IN_FILTER_MODE
,
1279 MC_CMD_FILTER_MODE_SIMPLE
);
1280 memcpy(MCDI_PTR(inbuf
, WOL_FILTER_SET_IN_MAGIC_MAC
), mac
, ETH_ALEN
);
1282 rc
= efx_mcdi_rpc(efx
, MC_CMD_WOL_FILTER_SET
, inbuf
, sizeof(inbuf
),
1283 outbuf
, sizeof(outbuf
), &outlen
);
1287 if (outlen
< MC_CMD_WOL_FILTER_SET_OUT_LEN
) {
1292 *id_out
= (int)MCDI_DWORD(outbuf
, WOL_FILTER_SET_OUT_FILTER_ID
);
1298 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
1305 efx_mcdi_wol_filter_set_magic(struct efx_nic
*efx
, const u8
*mac
, int *id_out
)
1307 return efx_mcdi_wol_filter_set(efx
, MC_CMD_WOL_TYPE_MAGIC
, mac
, id_out
);
1311 int efx_mcdi_wol_filter_get_magic(struct efx_nic
*efx
, int *id_out
)
1313 MCDI_DECLARE_BUF(outbuf
, MC_CMD_WOL_FILTER_GET_OUT_LEN
);
1317 rc
= efx_mcdi_rpc(efx
, MC_CMD_WOL_FILTER_GET
, NULL
, 0,
1318 outbuf
, sizeof(outbuf
), &outlen
);
1322 if (outlen
< MC_CMD_WOL_FILTER_GET_OUT_LEN
) {
1327 *id_out
= (int)MCDI_DWORD(outbuf
, WOL_FILTER_GET_OUT_FILTER_ID
);
1333 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
1338 int efx_mcdi_wol_filter_remove(struct efx_nic
*efx
, int id
)
1340 MCDI_DECLARE_BUF(inbuf
, MC_CMD_WOL_FILTER_REMOVE_IN_LEN
);
1343 MCDI_SET_DWORD(inbuf
, WOL_FILTER_REMOVE_IN_FILTER_ID
, (u32
)id
);
1345 rc
= efx_mcdi_rpc(efx
, MC_CMD_WOL_FILTER_REMOVE
, inbuf
, sizeof(inbuf
),
1353 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
1357 int efx_mcdi_flush_rxqs(struct efx_nic
*efx
)
1359 struct efx_channel
*channel
;
1360 struct efx_rx_queue
*rx_queue
;
1361 MCDI_DECLARE_BUF(inbuf
,
1362 MC_CMD_FLUSH_RX_QUEUES_IN_LEN(EFX_MAX_CHANNELS
));
1365 BUILD_BUG_ON(EFX_MAX_CHANNELS
>
1366 MC_CMD_FLUSH_RX_QUEUES_IN_QID_OFST_MAXNUM
);
1369 efx_for_each_channel(channel
, efx
) {
1370 efx_for_each_channel_rx_queue(rx_queue
, channel
) {
1371 if (rx_queue
->flush_pending
) {
1372 rx_queue
->flush_pending
= false;
1373 atomic_dec(&efx
->rxq_flush_pending
);
1374 MCDI_SET_ARRAY_DWORD(
1375 inbuf
, FLUSH_RX_QUEUES_IN_QID_OFST
,
1376 count
, efx_rx_queue_index(rx_queue
));
1382 rc
= efx_mcdi_rpc(efx
, MC_CMD_FLUSH_RX_QUEUES
, inbuf
,
1383 MC_CMD_FLUSH_RX_QUEUES_IN_LEN(count
), NULL
, 0, NULL
);
1389 int efx_mcdi_wol_filter_reset(struct efx_nic
*efx
)
1393 rc
= efx_mcdi_rpc(efx
, MC_CMD_WOL_FILTER_RESET
, NULL
, 0, NULL
, 0, NULL
);
1400 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
1404 #ifdef CONFIG_SFC_MTD
1406 #define EFX_MCDI_NVRAM_LEN_MAX 128
1408 static int efx_mcdi_nvram_update_start(struct efx_nic
*efx
, unsigned int type
)
1410 MCDI_DECLARE_BUF(inbuf
, MC_CMD_NVRAM_UPDATE_START_IN_LEN
);
1413 MCDI_SET_DWORD(inbuf
, NVRAM_UPDATE_START_IN_TYPE
, type
);
1415 BUILD_BUG_ON(MC_CMD_NVRAM_UPDATE_START_OUT_LEN
!= 0);
1417 rc
= efx_mcdi_rpc(efx
, MC_CMD_NVRAM_UPDATE_START
, inbuf
, sizeof(inbuf
),
1425 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
1429 static int efx_mcdi_nvram_read(struct efx_nic
*efx
, unsigned int type
,
1430 loff_t offset
, u8
*buffer
, size_t length
)
1432 MCDI_DECLARE_BUF(inbuf
, MC_CMD_NVRAM_READ_IN_LEN
);
1433 MCDI_DECLARE_BUF(outbuf
,
1434 MC_CMD_NVRAM_READ_OUT_LEN(EFX_MCDI_NVRAM_LEN_MAX
));
1438 MCDI_SET_DWORD(inbuf
, NVRAM_READ_IN_TYPE
, type
);
1439 MCDI_SET_DWORD(inbuf
, NVRAM_READ_IN_OFFSET
, offset
);
1440 MCDI_SET_DWORD(inbuf
, NVRAM_READ_IN_LENGTH
, length
);
1442 rc
= efx_mcdi_rpc(efx
, MC_CMD_NVRAM_READ
, inbuf
, sizeof(inbuf
),
1443 outbuf
, sizeof(outbuf
), &outlen
);
1447 memcpy(buffer
, MCDI_PTR(outbuf
, NVRAM_READ_OUT_READ_BUFFER
), length
);
1451 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
1455 static int efx_mcdi_nvram_write(struct efx_nic
*efx
, unsigned int type
,
1456 loff_t offset
, const u8
*buffer
, size_t length
)
1458 MCDI_DECLARE_BUF(inbuf
,
1459 MC_CMD_NVRAM_WRITE_IN_LEN(EFX_MCDI_NVRAM_LEN_MAX
));
1462 MCDI_SET_DWORD(inbuf
, NVRAM_WRITE_IN_TYPE
, type
);
1463 MCDI_SET_DWORD(inbuf
, NVRAM_WRITE_IN_OFFSET
, offset
);
1464 MCDI_SET_DWORD(inbuf
, NVRAM_WRITE_IN_LENGTH
, length
);
1465 memcpy(MCDI_PTR(inbuf
, NVRAM_WRITE_IN_WRITE_BUFFER
), buffer
, length
);
1467 BUILD_BUG_ON(MC_CMD_NVRAM_WRITE_OUT_LEN
!= 0);
1469 rc
= efx_mcdi_rpc(efx
, MC_CMD_NVRAM_WRITE
, inbuf
,
1470 ALIGN(MC_CMD_NVRAM_WRITE_IN_LEN(length
), 4),
1478 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
1482 static int efx_mcdi_nvram_erase(struct efx_nic
*efx
, unsigned int type
,
1483 loff_t offset
, size_t length
)
1485 MCDI_DECLARE_BUF(inbuf
, MC_CMD_NVRAM_ERASE_IN_LEN
);
1488 MCDI_SET_DWORD(inbuf
, NVRAM_ERASE_IN_TYPE
, type
);
1489 MCDI_SET_DWORD(inbuf
, NVRAM_ERASE_IN_OFFSET
, offset
);
1490 MCDI_SET_DWORD(inbuf
, NVRAM_ERASE_IN_LENGTH
, length
);
1492 BUILD_BUG_ON(MC_CMD_NVRAM_ERASE_OUT_LEN
!= 0);
1494 rc
= efx_mcdi_rpc(efx
, MC_CMD_NVRAM_ERASE
, inbuf
, sizeof(inbuf
),
1502 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
1506 static int efx_mcdi_nvram_update_finish(struct efx_nic
*efx
, unsigned int type
)
1508 MCDI_DECLARE_BUF(inbuf
, MC_CMD_NVRAM_UPDATE_FINISH_IN_LEN
);
1511 MCDI_SET_DWORD(inbuf
, NVRAM_UPDATE_FINISH_IN_TYPE
, type
);
1513 BUILD_BUG_ON(MC_CMD_NVRAM_UPDATE_FINISH_OUT_LEN
!= 0);
1515 rc
= efx_mcdi_rpc(efx
, MC_CMD_NVRAM_UPDATE_FINISH
, inbuf
, sizeof(inbuf
),
1523 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
1527 int efx_mcdi_mtd_read(struct mtd_info
*mtd
, loff_t start
,
1528 size_t len
, size_t *retlen
, u8
*buffer
)
1530 struct efx_mcdi_mtd_partition
*part
= to_efx_mcdi_mtd_partition(mtd
);
1531 struct efx_nic
*efx
= mtd
->priv
;
1532 loff_t offset
= start
;
1533 loff_t end
= min_t(loff_t
, start
+ len
, mtd
->size
);
1537 while (offset
< end
) {
1538 chunk
= min_t(size_t, end
- offset
, EFX_MCDI_NVRAM_LEN_MAX
);
1539 rc
= efx_mcdi_nvram_read(efx
, part
->nvram_type
, offset
,
1547 *retlen
= offset
- start
;
1551 int efx_mcdi_mtd_erase(struct mtd_info
*mtd
, loff_t start
, size_t len
)
1553 struct efx_mcdi_mtd_partition
*part
= to_efx_mcdi_mtd_partition(mtd
);
1554 struct efx_nic
*efx
= mtd
->priv
;
1555 loff_t offset
= start
& ~((loff_t
)(mtd
->erasesize
- 1));
1556 loff_t end
= min_t(loff_t
, start
+ len
, mtd
->size
);
1557 size_t chunk
= part
->common
.mtd
.erasesize
;
1560 if (!part
->updating
) {
1561 rc
= efx_mcdi_nvram_update_start(efx
, part
->nvram_type
);
1564 part
->updating
= true;
1567 /* The MCDI interface can in fact do multiple erase blocks at once;
1568 * but erasing may be slow, so we make multiple calls here to avoid
1569 * tripping the MCDI RPC timeout. */
1570 while (offset
< end
) {
1571 rc
= efx_mcdi_nvram_erase(efx
, part
->nvram_type
, offset
,
1581 int efx_mcdi_mtd_write(struct mtd_info
*mtd
, loff_t start
,
1582 size_t len
, size_t *retlen
, const u8
*buffer
)
1584 struct efx_mcdi_mtd_partition
*part
= to_efx_mcdi_mtd_partition(mtd
);
1585 struct efx_nic
*efx
= mtd
->priv
;
1586 loff_t offset
= start
;
1587 loff_t end
= min_t(loff_t
, start
+ len
, mtd
->size
);
1591 if (!part
->updating
) {
1592 rc
= efx_mcdi_nvram_update_start(efx
, part
->nvram_type
);
1595 part
->updating
= true;
1598 while (offset
< end
) {
1599 chunk
= min_t(size_t, end
- offset
, EFX_MCDI_NVRAM_LEN_MAX
);
1600 rc
= efx_mcdi_nvram_write(efx
, part
->nvram_type
, offset
,
1608 *retlen
= offset
- start
;
1612 int efx_mcdi_mtd_sync(struct mtd_info
*mtd
)
1614 struct efx_mcdi_mtd_partition
*part
= to_efx_mcdi_mtd_partition(mtd
);
1615 struct efx_nic
*efx
= mtd
->priv
;
1618 if (part
->updating
) {
1619 part
->updating
= false;
1620 rc
= efx_mcdi_nvram_update_finish(efx
, part
->nvram_type
);
1626 void efx_mcdi_mtd_rename(struct efx_mtd_partition
*part
)
1628 struct efx_mcdi_mtd_partition
*mcdi_part
=
1629 container_of(part
, struct efx_mcdi_mtd_partition
, common
);
1630 struct efx_nic
*efx
= part
->mtd
.priv
;
1632 snprintf(part
->name
, sizeof(part
->name
), "%s %s:%02x",
1633 efx
->name
, part
->type_name
, mcdi_part
->fw_subtype
);
1636 #endif /* CONFIG_SFC_MTD */