2018-01-08 13:35:35 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2017-03-16 12:41:08 +00:00
|
|
|
*
|
2018-01-08 13:35:35 +00:00
|
|
|
* Copyright (c) 2016-2018 Solarflare Communications Inc.
|
2016-11-29 16:19:03 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was jointly developed between OKTET Labs (under contract
|
|
|
|
* for Solarflare) and Solarflare Communications, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rte_cycles.h>
|
|
|
|
|
|
|
|
#include "efx.h"
|
|
|
|
#include "efx_mcdi.h"
|
|
|
|
#include "efx_regs_mcdi.h"
|
|
|
|
|
|
|
|
#include "sfc.h"
|
|
|
|
#include "sfc_log.h"
|
2017-03-09 17:23:02 +00:00
|
|
|
#include "sfc_ev.h"
|
2016-11-29 16:19:03 +00:00
|
|
|
|
|
|
|
#define SFC_MCDI_POLL_INTERVAL_MIN_US 10 /* 10us in 1us units */
|
|
|
|
#define SFC_MCDI_POLL_INTERVAL_MAX_US (US_PER_S / 10) /* 100ms in 1us units */
|
|
|
|
#define SFC_MCDI_WATCHDOG_INTERVAL_US (10 * US_PER_S) /* 10s in 1us units */
|
|
|
|
|
|
|
|
static void
|
|
|
|
sfc_mcdi_timeout(struct sfc_adapter *sa)
|
|
|
|
{
|
|
|
|
sfc_warn(sa, "MC TIMEOUT");
|
|
|
|
|
|
|
|
sfc_panic(sa, "MCDI timeout handling is not implemented\n");
|
|
|
|
}
|
|
|
|
|
2017-03-09 17:23:02 +00:00
|
|
|
static inline boolean_t
|
|
|
|
sfc_mcdi_proxy_event_available(struct sfc_adapter *sa)
|
|
|
|
{
|
|
|
|
struct sfc_mcdi *mcdi = &sa->mcdi;
|
|
|
|
|
|
|
|
mcdi->proxy_handle = 0;
|
|
|
|
mcdi->proxy_result = ETIMEDOUT;
|
|
|
|
sfc_ev_mgmt_qpoll(sa);
|
|
|
|
if (mcdi->proxy_result != ETIMEDOUT)
|
|
|
|
return B_TRUE;
|
|
|
|
|
|
|
|
return B_FALSE;
|
|
|
|
}
|
|
|
|
|
2016-11-29 16:19:03 +00:00
|
|
|
static void
|
2017-03-09 17:23:02 +00:00
|
|
|
sfc_mcdi_poll(struct sfc_adapter *sa, boolean_t proxy)
|
2016-11-29 16:19:03 +00:00
|
|
|
{
|
|
|
|
efx_nic_t *enp;
|
|
|
|
unsigned int delay_total;
|
|
|
|
unsigned int delay_us;
|
|
|
|
boolean_t aborted __rte_unused;
|
|
|
|
|
|
|
|
delay_total = 0;
|
|
|
|
delay_us = SFC_MCDI_POLL_INTERVAL_MIN_US;
|
|
|
|
enp = sa->nic;
|
|
|
|
|
|
|
|
do {
|
2017-03-09 17:23:02 +00:00
|
|
|
boolean_t poll_completed;
|
|
|
|
|
|
|
|
poll_completed = (proxy) ? sfc_mcdi_proxy_event_available(sa) :
|
|
|
|
efx_mcdi_request_poll(enp);
|
|
|
|
if (poll_completed)
|
2016-11-29 16:19:03 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (delay_total > SFC_MCDI_WATCHDOG_INTERVAL_US) {
|
2017-03-09 17:23:02 +00:00
|
|
|
if (!proxy) {
|
|
|
|
aborted = efx_mcdi_request_abort(enp);
|
|
|
|
SFC_ASSERT(aborted);
|
|
|
|
sfc_mcdi_timeout(sa);
|
|
|
|
}
|
|
|
|
|
2016-11-29 16:19:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rte_delay_us(delay_us);
|
|
|
|
|
|
|
|
delay_total += delay_us;
|
|
|
|
|
|
|
|
/* Exponentially back off the poll frequency */
|
|
|
|
RTE_BUILD_BUG_ON(SFC_MCDI_POLL_INTERVAL_MAX_US > UINT_MAX / 2);
|
|
|
|
delay_us *= 2;
|
|
|
|
if (delay_us > SFC_MCDI_POLL_INTERVAL_MAX_US)
|
|
|
|
delay_us = SFC_MCDI_POLL_INTERVAL_MAX_US;
|
|
|
|
|
|
|
|
} while (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sfc_mcdi_execute(void *arg, efx_mcdi_req_t *emrp)
|
|
|
|
{
|
|
|
|
struct sfc_adapter *sa = (struct sfc_adapter *)arg;
|
|
|
|
struct sfc_mcdi *mcdi = &sa->mcdi;
|
2017-03-09 17:23:02 +00:00
|
|
|
uint32_t proxy_handle;
|
2016-11-29 16:19:03 +00:00
|
|
|
|
|
|
|
rte_spinlock_lock(&mcdi->lock);
|
|
|
|
|
|
|
|
SFC_ASSERT(mcdi->state == SFC_MCDI_INITIALIZED);
|
|
|
|
|
|
|
|
efx_mcdi_request_start(sa->nic, emrp, B_FALSE);
|
2017-03-09 17:23:02 +00:00
|
|
|
sfc_mcdi_poll(sa, B_FALSE);
|
|
|
|
|
|
|
|
if (efx_mcdi_get_proxy_handle(sa->nic, emrp, &proxy_handle) == 0) {
|
|
|
|
/*
|
|
|
|
* Authorization is required for the MCDI request;
|
|
|
|
* wait for an MCDI proxy response event to bring
|
|
|
|
* a non-zero proxy handle (should be the same as
|
|
|
|
* the value obtained above) and operation status
|
|
|
|
*/
|
|
|
|
sfc_mcdi_poll(sa, B_TRUE);
|
|
|
|
|
|
|
|
if ((mcdi->proxy_handle != 0) &&
|
|
|
|
(mcdi->proxy_handle != proxy_handle)) {
|
|
|
|
sfc_err(sa, "Unexpected MCDI proxy event");
|
|
|
|
emrp->emr_rc = EFAULT;
|
|
|
|
} else if (mcdi->proxy_result == 0) {
|
|
|
|
/*
|
|
|
|
* Authorization succeeded; re-issue the original
|
|
|
|
* request and poll for an ordinary MCDI response
|
|
|
|
*/
|
|
|
|
efx_mcdi_request_start(sa->nic, emrp, B_FALSE);
|
|
|
|
sfc_mcdi_poll(sa, B_FALSE);
|
|
|
|
} else {
|
|
|
|
emrp->emr_rc = mcdi->proxy_result;
|
|
|
|
sfc_err(sa, "MCDI proxy authorization failed "
|
|
|
|
"(handle=%08x, result=%d)",
|
|
|
|
proxy_handle, mcdi->proxy_result);
|
|
|
|
}
|
|
|
|
}
|
2016-11-29 16:19:03 +00:00
|
|
|
|
|
|
|
rte_spinlock_unlock(&mcdi->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sfc_mcdi_ev_cpl(void *arg)
|
|
|
|
{
|
|
|
|
struct sfc_adapter *sa = (struct sfc_adapter *)arg;
|
|
|
|
struct sfc_mcdi *mcdi __rte_unused;
|
|
|
|
|
|
|
|
mcdi = &sa->mcdi;
|
|
|
|
SFC_ASSERT(mcdi->state == SFC_MCDI_INITIALIZED);
|
|
|
|
|
|
|
|
/* MCDI is polled, completions are not expected */
|
|
|
|
SFC_ASSERT(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sfc_mcdi_exception(void *arg, efx_mcdi_exception_t eme)
|
|
|
|
{
|
|
|
|
struct sfc_adapter *sa = (struct sfc_adapter *)arg;
|
|
|
|
|
|
|
|
sfc_warn(sa, "MC %s",
|
|
|
|
(eme == EFX_MCDI_EXCEPTION_MC_REBOOT) ? "REBOOT" :
|
|
|
|
(eme == EFX_MCDI_EXCEPTION_MC_BADASSERT) ? "BADASSERT" : "UNKNOWN");
|
|
|
|
|
2017-12-24 10:46:33 +00:00
|
|
|
sfc_schedule_restart(sa);
|
2016-11-29 16:19:03 +00:00
|
|
|
}
|
|
|
|
|
2016-12-15 12:50:52 +00:00
|
|
|
#define SFC_MCDI_LOG_BUF_SIZE 128
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
sfc_mcdi_do_log(const struct sfc_adapter *sa,
|
|
|
|
char *buffer, void *data, size_t data_size,
|
|
|
|
size_t pfxsize, size_t position)
|
|
|
|
{
|
|
|
|
uint32_t *words = data;
|
|
|
|
/* Space separator plus 2 characters per byte */
|
|
|
|
const size_t word_str_space = 1 + 2 * sizeof(*words);
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < data_size; i += sizeof(*words)) {
|
|
|
|
if (position + word_str_space >=
|
|
|
|
SFC_MCDI_LOG_BUF_SIZE) {
|
|
|
|
/* Flush at SFC_MCDI_LOG_BUF_SIZE with backslash
|
|
|
|
* at the end which is required by netlogdecode.
|
|
|
|
*/
|
|
|
|
buffer[position] = '\0';
|
2018-03-21 11:28:21 +00:00
|
|
|
sfc_log_mcdi(sa, "%s \\", buffer);
|
2016-12-15 12:50:52 +00:00
|
|
|
/* Preserve prefix for the next log message */
|
|
|
|
position = pfxsize;
|
|
|
|
}
|
|
|
|
position += snprintf(buffer + position,
|
|
|
|
SFC_MCDI_LOG_BUF_SIZE - position,
|
|
|
|
" %08x", *words);
|
|
|
|
words++;
|
|
|
|
}
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sfc_mcdi_logger(void *arg, efx_log_msg_t type,
|
|
|
|
void *header, size_t header_size,
|
|
|
|
void *data, size_t data_size)
|
|
|
|
{
|
|
|
|
struct sfc_adapter *sa = (struct sfc_adapter *)arg;
|
|
|
|
char buffer[SFC_MCDI_LOG_BUF_SIZE];
|
|
|
|
size_t pfxsize;
|
|
|
|
size_t start;
|
|
|
|
|
2018-03-21 11:28:21 +00:00
|
|
|
/*
|
|
|
|
* Unlike the other cases, MCDI logging implies more onerous work
|
|
|
|
* needed to produce a message. If the dynamic log level prevents
|
|
|
|
* the end result from being printed, the CPU time will be wasted.
|
|
|
|
*
|
|
|
|
* To avoid wasting time, the actual level is examined in advance.
|
|
|
|
*/
|
|
|
|
if (rte_log_get_level(sa->mcdi.logtype) < (int)SFC_LOG_LEVEL_MCDI)
|
2016-12-15 12:50:52 +00:00
|
|
|
return;
|
|
|
|
|
2018-03-21 11:28:21 +00:00
|
|
|
/* The format including prefix added by sfc_log_mcdi() is the format
|
2016-12-15 12:50:52 +00:00
|
|
|
* consumed by the Solarflare netlogdecode tool.
|
|
|
|
*/
|
|
|
|
pfxsize = snprintf(buffer, sizeof(buffer), "MCDI RPC %s:",
|
|
|
|
type == EFX_LOG_MCDI_REQUEST ? "REQ" :
|
|
|
|
type == EFX_LOG_MCDI_RESPONSE ? "RESP" : "???");
|
|
|
|
start = sfc_mcdi_do_log(sa, buffer, header, header_size,
|
|
|
|
pfxsize, pfxsize);
|
|
|
|
start = sfc_mcdi_do_log(sa, buffer, data, data_size, pfxsize, start);
|
|
|
|
if (start != pfxsize) {
|
|
|
|
buffer[start] = '\0';
|
2018-03-21 11:28:21 +00:00
|
|
|
sfc_log_mcdi(sa, "%s", buffer);
|
2016-12-15 12:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-09 17:23:02 +00:00
|
|
|
static void
|
|
|
|
sfc_mcdi_ev_proxy_response(void *arg, uint32_t handle, efx_rc_t result)
|
|
|
|
{
|
|
|
|
struct sfc_adapter *sa = (struct sfc_adapter *)arg;
|
|
|
|
struct sfc_mcdi *mcdi = &sa->mcdi;
|
|
|
|
|
|
|
|
mcdi->proxy_handle = handle;
|
|
|
|
mcdi->proxy_result = result;
|
|
|
|
}
|
|
|
|
|
2016-11-29 16:19:03 +00:00
|
|
|
int
|
|
|
|
sfc_mcdi_init(struct sfc_adapter *sa)
|
|
|
|
{
|
|
|
|
struct sfc_mcdi *mcdi;
|
|
|
|
size_t max_msg_size;
|
|
|
|
efx_mcdi_transport_t *emtp;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
sfc_log_init(sa, "entry");
|
|
|
|
|
|
|
|
mcdi = &sa->mcdi;
|
|
|
|
|
|
|
|
SFC_ASSERT(mcdi->state == SFC_MCDI_UNINITIALIZED);
|
|
|
|
|
|
|
|
rte_spinlock_init(&mcdi->lock);
|
|
|
|
|
|
|
|
mcdi->state = SFC_MCDI_INITIALIZED;
|
|
|
|
|
|
|
|
max_msg_size = sizeof(uint32_t) + MCDI_CTL_SDU_LEN_MAX_V2;
|
|
|
|
rc = sfc_dma_alloc(sa, "mcdi", 0, max_msg_size, sa->socket_id,
|
|
|
|
&mcdi->mem);
|
|
|
|
if (rc != 0)
|
|
|
|
goto fail_dma_alloc;
|
|
|
|
|
2019-02-07 12:17:44 +00:00
|
|
|
mcdi->logtype = sfc_register_logtype(&sa->priv.shared->pci_addr,
|
2019-02-07 12:17:26 +00:00
|
|
|
SFC_LOGTYPE_MCDI_STR,
|
2018-03-21 11:28:21 +00:00
|
|
|
RTE_LOG_NOTICE);
|
2016-12-15 12:50:52 +00:00
|
|
|
|
2016-11-29 16:19:03 +00:00
|
|
|
emtp = &mcdi->transport;
|
|
|
|
emtp->emt_context = sa;
|
|
|
|
emtp->emt_dma_mem = &mcdi->mem;
|
|
|
|
emtp->emt_execute = sfc_mcdi_execute;
|
|
|
|
emtp->emt_ev_cpl = sfc_mcdi_ev_cpl;
|
|
|
|
emtp->emt_exception = sfc_mcdi_exception;
|
2016-12-15 12:50:52 +00:00
|
|
|
emtp->emt_logger = sfc_mcdi_logger;
|
2017-03-09 17:23:02 +00:00
|
|
|
emtp->emt_ev_proxy_response = sfc_mcdi_ev_proxy_response;
|
2016-11-29 16:19:03 +00:00
|
|
|
|
|
|
|
sfc_log_init(sa, "init MCDI");
|
|
|
|
rc = efx_mcdi_init(sa->nic, emtp);
|
|
|
|
if (rc != 0)
|
|
|
|
goto fail_mcdi_init;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_mcdi_init:
|
|
|
|
memset(emtp, 0, sizeof(*emtp));
|
|
|
|
sfc_dma_free(sa, &mcdi->mem);
|
|
|
|
|
|
|
|
fail_dma_alloc:
|
|
|
|
mcdi->state = SFC_MCDI_UNINITIALIZED;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sfc_mcdi_fini(struct sfc_adapter *sa)
|
|
|
|
{
|
|
|
|
struct sfc_mcdi *mcdi;
|
|
|
|
efx_mcdi_transport_t *emtp;
|
|
|
|
|
|
|
|
sfc_log_init(sa, "entry");
|
|
|
|
|
|
|
|
mcdi = &sa->mcdi;
|
|
|
|
emtp = &mcdi->transport;
|
|
|
|
|
|
|
|
rte_spinlock_lock(&mcdi->lock);
|
|
|
|
|
|
|
|
SFC_ASSERT(mcdi->state == SFC_MCDI_INITIALIZED);
|
|
|
|
mcdi->state = SFC_MCDI_UNINITIALIZED;
|
|
|
|
|
|
|
|
sfc_log_init(sa, "fini MCDI");
|
|
|
|
efx_mcdi_fini(sa->nic);
|
|
|
|
memset(emtp, 0, sizeof(*emtp));
|
|
|
|
|
|
|
|
rte_spinlock_unlock(&mcdi->lock);
|
|
|
|
|
|
|
|
sfc_dma_free(sa, &mcdi->mem);
|
|
|
|
}
|