From patchwork Tue Jul 12 13:38:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chas Williams <3chas3@gmail.com> X-Patchwork-Id: 14793 X-Patchwork-Delegate: bruce.richardson@intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 03F283990; Tue, 12 Jul 2016 15:38:36 +0200 (CEST) Received: from mail-qk0-f193.google.com (mail-qk0-f193.google.com [209.85.220.193]) by dpdk.org (Postfix) with ESMTP id 241563794 for ; Tue, 12 Jul 2016 15:38:34 +0200 (CEST) Received: by mail-qk0-f193.google.com with SMTP id r68so960441qka.3 for ; Tue, 12 Jul 2016 06:38:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZeNaDj7PAXSj0rR65ww/mnethw69rv054me0/b2H/Wk=; b=QKdnpzxhVFnRsDwT9ubdiMHs/51LjogUifDbPafxZe4PtA+NdWxHAXLVIRUzaiFSWX QH/axcqYCOuIKg8Ygay3NqUy8sy+BYZquo7vspSl91xhVfDSeB2kQSGX//ygGSZaO8w3 EVHu3FaB0UZlCDccxhl9IC9CHADLLcjpn3qBYI0PtaDHqBEa3lEVVijks3S8rLMfHJ/w JDyZHzaA1DwefGilxvvS+brUqr7hhTmrcXH4KC2EVBrz/byhFBHBpqQmnnFtElZTEF5Q L/2w/NZUuCrJuditPFhH2NXElmQ7QTyRCj3HDiF41W36V9ClKOWju/pmhOqzGkX6gxv2 XIJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZeNaDj7PAXSj0rR65ww/mnethw69rv054me0/b2H/Wk=; b=cMEhr/ojjWeFfV18NmyPFJyZRlAufwiFAve90+ta8lN8esUwscmXcEX4dMFvlYCij+ wz/MfmkzAoBsBEo3MzgVwbOcqeJrCuvSa/UcOEmlD8mmsZWRLYdWaKr+UOa/J/q5+V96 +sopsmgt2Y8mnNd2ffc1zzzSilkM0Cw679b7l8Br/97I8GGxqTk/Hmr667fm62RIZhPR RampQyujMVfmNtyR5JUhJhPoyxDxAVsbjI/KVg7PdYBDwMZN93lUY4uyDIR35wlMqnJw 8zhko5/KEIM3COausEfnjS2aUdtvJfaLGrJUg6VHSh2+D+VfcFo0iBVg9uLm2DdeXCEc 35MQ== X-Gm-Message-State: ALyK8tLR6qadrKVrRdhyqh5SQIzxdPH2/thDv3/2C2tUABXLOwksDUJNWrbxsgvl1zTRuQ== X-Received: by 10.55.31.33 with SMTP id f33mr3283919qkf.38.1468330713562; Tue, 12 Jul 2016 06:38:33 -0700 (PDT) Received: from monolith.home (pool-173-79-169-182.washdc.fios.verizon.net. [173.79.169.182]) by smtp.gmail.com with ESMTPSA id 23sm1244397qty.40.2016.07.12.06.38.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jul 2016 06:38:33 -0700 (PDT) From: Chas Williams <3chas3@gmail.com> To: dev@dpdk.org Cc: harish.patil@qlogic.com, Chas Williams <3chas3@gmail.com> Date: Tue, 12 Jul 2016 09:38:11 -0400 Message-Id: <1468330694-383-7-git-send-email-3chas3@gmail.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1468330694-383-2-git-send-email-3chas3@gmail.com> References: <1468330694-383-2-git-send-email-3chas3@gmail.com> Subject: [dpdk-dev] [PATCH 07/10] bnx2x: Serialize access to pf2vf mailbox X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The pf2vf mailbox can only be used by one thread at a time. Fixes: 540a211084a7 ("bnx2x: driver core") Signed-off-by: Chas Williams <3chas3@gmail.com> --- drivers/net/bnx2x/bnx2x.h | 12 +++-- drivers/net/bnx2x/bnx2x_ethdev.c | 2 + drivers/net/bnx2x/bnx2x_vfpf.c | 113 +++++++++++++++++++++++++++------------ 3 files changed, 88 insertions(+), 39 deletions(-) diff --git a/drivers/net/bnx2x/bnx2x.h b/drivers/net/bnx2x/bnx2x.h index 2746562..d0d5b65 100644 --- a/drivers/net/bnx2x/bnx2x.h +++ b/drivers/net/bnx2x/bnx2x.h @@ -17,6 +17,7 @@ #define __BNX2X_H__ #include +#include #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN #ifndef __LITTLE_ENDIAN @@ -1026,12 +1027,13 @@ struct bnx2x_softc { struct bnx2x_mac_ops mac_ops; /* structures for VF mbox/response/bulletin */ - struct bnx2x_vf_mbx_msg *vf2pf_mbox; - struct bnx2x_dma vf2pf_mbox_mapping; - struct vf_acquire_resp_tlv acquire_resp; + struct bnx2x_vf_mbx_msg *vf2pf_mbox; + struct bnx2x_dma vf2pf_mbox_mapping; + struct vf_acquire_resp_tlv acquire_resp; struct bnx2x_vf_bulletin *pf2vf_bulletin; - struct bnx2x_dma pf2vf_bulletin_mapping; - struct bnx2x_vf_bulletin old_bulletin; + struct bnx2x_dma pf2vf_bulletin_mapping; + struct bnx2x_vf_bulletin old_bulletin; + rte_spinlock_t vf2pf_lock; int media; diff --git a/drivers/net/bnx2x/bnx2x_ethdev.c b/drivers/net/bnx2x/bnx2x_ethdev.c index 047b782..88be036 100644 --- a/drivers/net/bnx2x/bnx2x_ethdev.c +++ b/drivers/net/bnx2x/bnx2x_ethdev.c @@ -460,6 +460,8 @@ bnx2x_common_dev_init(struct rte_eth_dev *eth_dev, int is_vf) eth_dev->data->port_id, pci_dev->id.vendor_id, pci_dev->id.device_id); if (IS_VF(sc)) { + rte_spinlock_init(&sc->vf2pf_lock); + if (bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_mbx_msg), &sc->vf2pf_mbox_mapping, "vf2pf_mbox", RTE_CACHE_LINE_SIZE) != 0) diff --git a/drivers/net/bnx2x/bnx2x_vfpf.c b/drivers/net/bnx2x/bnx2x_vfpf.c index 46bf739..46b56b4 100644 --- a/drivers/net/bnx2x/bnx2x_vfpf.c +++ b/drivers/net/bnx2x/bnx2x_vfpf.c @@ -78,10 +78,13 @@ bnx2x_add_tlv(__rte_unused struct bnx2x_softc *sc, void *tlvs_list, /* Initiliaze header of the first tlv and clear mailbox*/ static void -bnx2x_init_first_tlv(struct bnx2x_softc *sc, struct vf_first_tlv *first_tlv, - uint16_t type, uint16_t length) +bnx2x_vf_prep(struct bnx2x_softc *sc, struct vf_first_tlv *first_tlv, + uint16_t type, uint16_t length) { struct bnx2x_vf_mbx_msg *mbox = sc->vf2pf_mbox; + + rte_spinlock_lock(&sc->vf2pf_lock); + PMD_DRV_LOG(DEBUG, "Preparing %d tlv for sending", type); memset(mbox, 0, sizeof(struct bnx2x_vf_mbx_msg)); @@ -92,6 +95,17 @@ bnx2x_init_first_tlv(struct bnx2x_softc *sc, struct vf_first_tlv *first_tlv, first_tlv->reply_offset = sizeof(mbox->query); } +/* releases the mailbox */ +static void +bnx2x_vf_finalize(struct bnx2x_softc *sc, + __rte_unused struct vf_first_tlv *first_tlv) +{ + PMD_DRV_LOG(DEBUG, "done sending [%d] tlv over vf pf channel", + first_tlv->tl.type); + + rte_spinlock_unlock(&sc->vf2pf_lock); +} + #define BNX2X_VF_CMD_ADDR_LO PXP_VF_ADDR_CSDM_GLOBAL_START #define BNX2X_VF_CMD_ADDR_HI BNX2X_VF_CMD_ADDR_LO + 4 #define BNX2X_VF_CMD_TRIGGER BNX2X_VF_CMD_ADDR_HI + 4 @@ -244,13 +258,16 @@ int bnx2x_vf_get_resources(struct bnx2x_softc *sc, uint8_t tx_count, uint8_t rx_ struct vf_acquire_tlv *acq = &sc->vf2pf_mbox->query[0].acquire; int vf_id; struct bnx2x_obtain_status obtain_status; + int rc = 0; bnx2x_vf_close(sc); - bnx2x_init_first_tlv(sc, &acq->first_tlv, BNX2X_VF_TLV_ACQUIRE, sizeof(*acq)); + bnx2x_vf_prep(sc, &acq->first_tlv, BNX2X_VF_TLV_ACQUIRE, sizeof(*acq)); vf_id = bnx2x_read_vf_id(sc); - if (vf_id < 0) - return -EAGAIN; + if (vf_id < 0) { + rc = -EAGAIN; + goto out; + } acq->vf_id = vf_id; @@ -274,8 +291,10 @@ int bnx2x_vf_get_resources(struct bnx2x_softc *sc, uint8_t tx_count, uint8_t rx_ /* requesting the resources in loop */ obtain_status = bnx2x_loop_obtain_resources(sc); - if (!obtain_status.success) - return obtain_status.err_code; + if (!obtain_status.success) { + rc = obtain_status.err_code; + goto out; + } struct vf_acquire_resp_tlv sc_resp = sc->acquire_resp; @@ -305,7 +324,10 @@ int bnx2x_vf_get_resources(struct bnx2x_softc *sc, uint8_t tx_count, uint8_t rx_ sc_resp.resc.current_mac_addr, ETH_ALEN); - return 0; +out: + bnx2x_vf_finalize(sc, &acq->first_tlv); + + return rc; } /* Ask PF to release VF's resources */ @@ -318,8 +340,8 @@ bnx2x_vf_close(struct bnx2x_softc *sc) if (vf_id >= 0) { query = &sc->vf2pf_mbox->query[0].release; - bnx2x_init_first_tlv(sc, &query->first_tlv, BNX2X_VF_TLV_RELEASE, - sizeof(*query)); + bnx2x_vf_prep(sc, &query->first_tlv, BNX2X_VF_TLV_RELEASE, + sizeof(*query)); query->vf_id = vf_id; bnx2x_add_tlv(sc, query, query->first_tlv.tl.length, @@ -329,6 +351,8 @@ bnx2x_vf_close(struct bnx2x_softc *sc) bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr); if (reply->status != BNX2X_VF_STATUS_SUCCESS) PMD_DRV_LOG(ERR, "Failed to release VF"); + + bnx2x_vf_finalize(sc, &query->first_tlv); } } @@ -338,11 +362,11 @@ bnx2x_vf_init(struct bnx2x_softc *sc) { struct vf_init_tlv *query; struct vf_common_reply_tlv *reply = &sc->vf2pf_mbox->resp.common_reply; - int i; + int i, rc = 0; query = &sc->vf2pf_mbox->query[0].init; - bnx2x_init_first_tlv(sc, &query->first_tlv, BNX2X_VF_TLV_INIT, - sizeof(*query)); + bnx2x_vf_prep(sc, &query->first_tlv, BNX2X_VF_TLV_INIT, + sizeof(*query)); FOR_EACH_QUEUE(sc, i) { query->sb_addr[i] = (unsigned long)(sc->fp[i].sb_dma.paddr); @@ -359,11 +383,14 @@ bnx2x_vf_init(struct bnx2x_softc *sc) bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr); if (reply->status != BNX2X_VF_STATUS_SUCCESS) { PMD_DRV_LOG(ERR, "Failed to init VF"); - return -EINVAL; + rc = -EINVAL; + goto out; } PMD_DRV_LOG(DEBUG, "VF was initialized"); - return 0; +out: + bnx2x_vf_finalize(sc, &query->first_tlv); + return rc; } void @@ -378,9 +405,9 @@ bnx2x_vf_unload(struct bnx2x_softc *sc) if (vf_id > 0) { FOR_EACH_QUEUE(sc, i) { query_op = &sc->vf2pf_mbox->query[0].q_op; - bnx2x_init_first_tlv(sc, &query_op->first_tlv, - BNX2X_VF_TLV_TEARDOWN_Q, - sizeof(*query_op)); + bnx2x_vf_prep(sc, &query_op->first_tlv, + BNX2X_VF_TLV_TEARDOWN_Q, + sizeof(*query_op)); query_op->vf_qid = i; @@ -393,13 +420,15 @@ bnx2x_vf_unload(struct bnx2x_softc *sc) if (reply->status != BNX2X_VF_STATUS_SUCCESS) PMD_DRV_LOG(ERR, "Bad reply for vf_q %d teardown", i); + + bnx2x_vf_finalize(sc, &query->first_tlv); } bnx2x_vf_set_mac(sc, false); query = &sc->vf2pf_mbox->query[0].close; - bnx2x_init_first_tlv(sc, &query->first_tlv, BNX2X_VF_TLV_CLOSE, - sizeof(*query)); + bnx2x_vf_prep(sc, &query->first_tlv, BNX2X_VF_TLV_CLOSE, + sizeof(*query)); query->vf_id = vf_id; @@ -411,6 +440,8 @@ bnx2x_vf_unload(struct bnx2x_softc *sc) if (reply->status != BNX2X_VF_STATUS_SUCCESS) PMD_DRV_LOG(ERR, "Bad reply from PF for close message"); + + bnx2x_vf_finalize(sc, &query->first_tlv); } } @@ -475,10 +506,11 @@ bnx2x_vf_setup_queue(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp, int lead struct vf_setup_q_tlv *query; struct vf_common_reply_tlv *reply = &sc->vf2pf_mbox->resp.common_reply; uint16_t flags = bnx2x_vf_q_flags(leading); + int rc = 0; query = &sc->vf2pf_mbox->query[0].setup_q; - bnx2x_init_first_tlv(sc, &query->first_tlv, BNX2X_VF_TLV_SETUP_Q, - sizeof(*query)); + bnx2x_vf_prep(sc, &query->first_tlv, BNX2X_VF_TLV_SETUP_Q, + sizeof(*query)); query->vf_qid = fp->index; query->param_valid = VF_RXQ_VALID | VF_TXQ_VALID; @@ -494,10 +526,12 @@ bnx2x_vf_setup_queue(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp, int lead if (reply->status != BNX2X_VF_STATUS_SUCCESS) { PMD_DRV_LOG(ERR, "Failed to setup VF queue[%d]", fp->index); - return -EINVAL; + rc = -EINVAL; } - return 0; + bnx2x_vf_finalize(sc, &query->first_tlv); + + return rc; } int @@ -505,9 +539,10 @@ bnx2x_vf_set_mac(struct bnx2x_softc *sc, int set) { struct vf_set_q_filters_tlv *query; struct vf_common_reply_tlv *reply; + int rc = 0; query = &sc->vf2pf_mbox->query[0].set_q_filters; - bnx2x_init_first_tlv(sc, &query->first_tlv, BNX2X_VF_TLV_SET_Q_FILTERS, + bnx2x_vf_prep(sc, &query->first_tlv, BNX2X_VF_TLV_SET_Q_FILTERS, sizeof(*query)); query->vf_qid = sc->fp->index; @@ -542,10 +577,12 @@ bnx2x_vf_set_mac(struct bnx2x_softc *sc, int set) if (BNX2X_VF_STATUS_SUCCESS != reply->status) { PMD_DRV_LOG(ERR, "Bad reply from PF for SET MAC message: %d", reply->status); - return -EINVAL; + rc = -EINVAL; } - return 0; + bnx2x_vf_finalize(sc, &query->first_tlv); + + return rc; } int @@ -554,10 +591,11 @@ bnx2x_vf_config_rss(struct bnx2x_softc *sc, { struct vf_rss_tlv *query; struct vf_common_reply_tlv *reply = &sc->vf2pf_mbox->resp.common_reply; + int rc = 0; query = &sc->vf2pf_mbox->query[0].update_rss; - bnx2x_init_first_tlv(sc, &query->first_tlv, BNX2X_VF_TLV_UPDATE_RSS, + bnx2x_vf_prep(sc, &query->first_tlv, BNX2X_VF_TLV_UPDATE_RSS, sizeof(*query)); /* add list termination tlv */ @@ -577,10 +615,12 @@ bnx2x_vf_config_rss(struct bnx2x_softc *sc, bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr); if (reply->status != BNX2X_VF_STATUS_SUCCESS) { PMD_DRV_LOG(ERR, "Failed to configure RSS"); - return -EINVAL; + rc = -EINVAL; } - return 0; + bnx2x_vf_finalize(sc, &query->first_tlv); + + return rc; } int @@ -588,9 +628,10 @@ bnx2x_vf_set_rx_mode(struct bnx2x_softc *sc) { struct vf_set_q_filters_tlv *query; struct vf_common_reply_tlv *reply = &sc->vf2pf_mbox->resp.common_reply; + int rc = 0; query = &sc->vf2pf_mbox->query[0].set_q_filters; - bnx2x_init_first_tlv(sc, &query->first_tlv, BNX2X_VF_TLV_SET_Q_FILTERS, + bnx2x_vf_prep(sc, &query->first_tlv, BNX2X_VF_TLV_SET_Q_FILTERS, sizeof(*query)); query->vf_qid = 0; @@ -617,7 +658,8 @@ bnx2x_vf_set_rx_mode(struct bnx2x_softc *sc) break; default: PMD_DRV_LOG(ERR, "BAD rx mode (%d)", mode); - return -EINVAL; + rc = -EINVAL; + goto out; } bnx2x_add_tlv(sc, query, query->first_tlv.tl.length, @@ -627,8 +669,11 @@ bnx2x_vf_set_rx_mode(struct bnx2x_softc *sc) bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr); if (reply->status != BNX2X_VF_STATUS_SUCCESS) { PMD_DRV_LOG(ERR, "Failed to set RX mode"); - return -EINVAL; + rc = -EINVAL; } - return 0; +out: + bnx2x_vf_finalize(sc, &query->first_tlv); + + return rc; }