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; /* Convert negative error to positive used in the driver */ rc = sfc_kvargs_process(sa, SFC_KVARG_MCDI_LOGGING, sfc_kvarg_bool_handler, &mcdi->logging); if (rc != 0) goto fail_kvargs_process; 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; emtp->emt_logger = sfc_mcdi_logger; 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)); fail_kvargs_process: sfc_dma_free(sa, &mcdi->mem); fail_dma_alloc: mcdi->state = SFC_MCDI_UNINITIALIZED; return rc; }
int sfc_ev_qinit(struct sfc_adapter *sa, enum sfc_evq_type type, unsigned int type_index, unsigned int entries, int socket_id, struct sfc_evq **evqp) { struct sfc_evq *evq; int rc; sfc_log_init(sa, "type=%s type_index=%u", sfc_evq_type2str(type), type_index); SFC_ASSERT(rte_is_power_of_2(entries)); rc = ENOMEM; evq = rte_zmalloc_socket("sfc-evq", sizeof(*evq), RTE_CACHE_LINE_SIZE, socket_id); if (evq == NULL) goto fail_evq_alloc; evq->sa = sa; evq->type = type; evq->entries = entries; /* Allocate DMA space */ rc = sfc_dma_alloc(sa, sfc_evq_type2str(type), type_index, EFX_EVQ_SIZE(evq->entries), socket_id, &evq->mem); if (rc != 0) goto fail_dma_alloc; evq->init_state = SFC_EVQ_INITIALIZED; sa->evq_count++; *evqp = evq; return 0; fail_dma_alloc: rte_free(evq); fail_evq_alloc: sfc_log_init(sa, "failed %d", rc); return rc; }
int sfc_tx_qinit(struct sfc_adapter *sa, unsigned int sw_index, uint16_t nb_tx_desc, unsigned int socket_id, const struct rte_eth_txconf *tx_conf) { const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic); struct sfc_txq_info *txq_info; struct sfc_evq *evq; struct sfc_txq *txq; int rc = 0; struct sfc_dp_tx_qcreate_info info; sfc_log_init(sa, "TxQ = %u", sw_index); rc = sfc_tx_qcheck_conf(sa, nb_tx_desc, tx_conf); if (rc != 0) goto fail_bad_conf; SFC_ASSERT(sw_index < sa->txq_count); txq_info = &sa->txq_info[sw_index]; SFC_ASSERT(nb_tx_desc <= sa->txq_max_entries); txq_info->entries = nb_tx_desc; rc = sfc_ev_qinit(sa, SFC_EVQ_TYPE_TX, sw_index, txq_info->entries, socket_id, &evq); if (rc != 0) goto fail_ev_qinit; rc = ENOMEM; txq = rte_zmalloc_socket("sfc-txq", sizeof(*txq), 0, socket_id); if (txq == NULL) goto fail_txq_alloc; txq_info->txq = txq; txq->hw_index = sw_index; txq->evq = evq; txq->free_thresh = (tx_conf->tx_free_thresh) ? tx_conf->tx_free_thresh : SFC_TX_DEFAULT_FREE_THRESH; txq->flags = tx_conf->txq_flags; rc = sfc_dma_alloc(sa, "txq", sw_index, EFX_TXQ_SIZE(txq_info->entries), socket_id, &txq->mem); if (rc != 0) goto fail_dma_alloc; memset(&info, 0, sizeof(info)); info.free_thresh = txq->free_thresh; info.flags = tx_conf->txq_flags; info.txq_entries = txq_info->entries; info.dma_desc_size_max = encp->enc_tx_dma_desc_size_max; info.txq_hw_ring = txq->mem.esm_base; info.evq_entries = txq_info->entries; info.evq_hw_ring = evq->mem.esm_base; info.hw_index = txq->hw_index; info.mem_bar = sa->mem_bar.esb_base; rc = sa->dp_tx->qcreate(sa->eth_dev->data->port_id, sw_index, &SFC_DEV_TO_PCI(sa->eth_dev)->addr, socket_id, &info, &txq->dp); if (rc != 0) goto fail_dp_tx_qinit; evq->dp_txq = txq->dp; txq->state = SFC_TXQ_INITIALIZED; txq_info->deferred_start = (tx_conf->tx_deferred_start != 0); return 0; fail_dp_tx_qinit: sfc_dma_free(sa, &txq->mem); fail_dma_alloc: txq_info->txq = NULL; rte_free(txq); fail_txq_alloc: sfc_ev_qfini(evq); fail_ev_qinit: txq_info->entries = 0; fail_bad_conf: sfc_log_init(sa, "failed (TxQ = %u, rc = %d)", sw_index, rc); return rc; }