From patchwork Tue Aug 2 11:32:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil Kovvuri X-Patchwork-Id: 9255801 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4717A6077C for ; Tue, 2 Aug 2016 11:34:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35A07284EF for ; Tue, 2 Aug 2016 11:34:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29FEE284F6; Tue, 2 Aug 2016 11:34:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7A041284EF for ; Tue, 2 Aug 2016 11:34:50 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bUXwo-0000GI-B8; Tue, 02 Aug 2016 11:33:22 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bUXwj-0008U6-Nz for linux-arm-kernel@lists.infradead.org; Tue, 02 Aug 2016 11:33:19 +0000 Received: by mail-wm0-x242.google.com with SMTP id o80so30180169wme.0 for ; Tue, 02 Aug 2016 04:32:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=K3XdNTgpsOhQgTTR+B3+KNrlM0/me60T+ekgvbmQH9U=; b=bPZNGTWKMj7V1bhVt49icvP+Tak6rGO4TEnJuX+poAowVOp7QXaqzt/JyHjd4SmGGn Er4u2BawFlSQ/HTFq/mui6wgVZSCBCmw68Hc291tDTMl/QN7nesEelQN85nzAgtU0MN2 irHP+PebrSmfwy2UXaEDIFsfbta2uqAOBpyDkzylFB4uxoeLHy6bH88LD7gp1BuVwLzM OlkL8Y/whnCCVhXPlAiBtlOXvkMNXvmCAxFnSjdVQU18XymuBAGSJPbwKpAU6bFbPnEm 2yo/EfLvSpib4gVtAXzw0Zj/yb9PRScKV/EnCWxiAol8A41cEBbIEP6REeWcQrl6xUVt fgrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=K3XdNTgpsOhQgTTR+B3+KNrlM0/me60T+ekgvbmQH9U=; b=aEo/NcrJ5CphH4sCl2vG6MG6SQ26lysv+FU48dYjWM444uEgQ0pbPNdX2VvB9B8nvG VWjYFFnDXLGGPXtvwLdCKmgucdaTRPiq1gfzftvyzaqnY04QqN7vAbE3ZjFqe2Xao25o dZLNHPINQZNT+eA81GX3+ahNhlkx/XQwDZal5iXruap4QBjuzJXfdoTgITqqJBs6p+v+ 9blYfBa3kN1IIbnNfZt4FZLMre6PjWlMCwZNx2lGGi8jCMpsApg39pMEgLrXIIGVEbLM QESEiok5cSij0NmVN4NMsBbsdFb4SURFR4wsUNARULQO8DH4cnkq0nMAg3PeNDJROFkG C9MQ== X-Gm-Message-State: AEkoouuIcgbmIafRmlzcJp3PkerssPXlYULl+JRMF1o98HHobp9BhGk/Zih0ZKGpci3z1R1Z8xtDkjkNwJDYCw== X-Received: by 10.28.236.24 with SMTP id k24mr47232692wmh.47.1470137575582; Tue, 02 Aug 2016 04:32:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.68.232 with HTTP; Tue, 2 Aug 2016 04:32:54 -0700 (PDT) In-Reply-To: <6b86fd8a-e97a-8b71-1786-50aa9e667873@verizon.com> References: <1469933384-16827-1-git-send-email-alexander.levin@verizon.com> <6b86fd8a-e97a-8b71-1786-50aa9e667873@verizon.com> From: Sunil Kovvuri Date: Tue, 2 Aug 2016 17:02:54 +0530 Message-ID: Subject: Re: [PATCH] net: thunderx: correct bound check in nic_config_loopback To: "Levin, Alexander" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160802_043318_117944_F62D723B X-CRM114-Status: GOOD ( 24.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "netdev@vger.kernel.org" , "sgoutham@cavium.com" , "rric@kernel.org" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Yes, it's incorrect at other places as well. That went in the very early stages of development and didn't change it because that out of bounds issue will never happen as no of logical interfaces will never be morethan MAX_LMAC i.e 8, so max vf_id will be 7. But with addition of support for newer platforms with different set HW capabilities we are slowly getting rid of most of the macros i.e static info. Attached is the patch which will get rid of MAX_LMAC and also allows support for 16LMACs (supported on newer platforms) or more. I hope currently you are not facing any issue with below check. >>> if (lbk->vf_id > MAX_LMAC) I will submit the attached patch along with other patches when net-next is open. https://lkml.org/lkml/2016/7/15/362 Thanks, Sunil. On Mon, Aug 1, 2016 at 9:27 PM, Levin, Alexander wrote: > On 07/31/2016 12:41 PM, Sunil Kovvuri wrote: >> Thanks for finding. >> A much better fix would be, >> >> - if (lbk->vf_id > MAX_LMAC) >> + if (lbk->vf_id >= nic->num_vf_en) >> return -1; >> >> where 'num_vf_en' reflects the exact number of physical interfaces or >> LMACs on the system. > > Right. I see quite a few more places that compare to MAX_LMAC vs > num_vf_en. What was the reasoning behind it then? > > > Thanks, > Sasha From cab9aff8c76fd34fdc252eba90ee1bb016c5829b Mon Sep 17 00:00:00 2001 From: Sunil Goutham Date: Tue, 2 Aug 2016 16:56:12 +0530 Subject: [PATCH] net: thunderx: Add support for 16 LMACs of 83xx 83xx will have 4 BGX blocks i.e 16 LMACs, to avoid changing the same with every platform, nicpf struct elements which track LMAC related info are now allocated runtime based on platform's max possible BGX count. Signed-off-by: Sunil Goutham --- drivers/net/ethernet/cavium/thunder/nic_main.c | 61 ++++++++++++++++++----- drivers/net/ethernet/cavium/thunder/thunder_bgx.h | 2 - 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/cavium/thunder/nic_main.c b/drivers/net/ethernet/cavium/thunder/nic_main.c index 74bb811..0139186 100644 --- a/drivers/net/ethernet/cavium/thunder/nic_main.c +++ b/drivers/net/ethernet/cavium/thunder/nic_main.c @@ -53,12 +53,12 @@ struct nicpf { #define NIC_SET_VF_LMAC_MAP(bgx, lmac) (((bgx & 0xF) << 4) | (lmac & 0xF)) #define NIC_GET_BGX_FROM_VF_LMAC_MAP(map) ((map >> 4) & 0xF) #define NIC_GET_LMAC_FROM_VF_LMAC_MAP(map) (map & 0xF) - u8 vf_lmac_map[MAX_LMAC]; + u8 *vf_lmac_map; struct delayed_work dwork; struct workqueue_struct *check_link; - u8 link[MAX_LMAC]; - u8 duplex[MAX_LMAC]; - u32 speed[MAX_LMAC]; + u8 *link; + u8 *duplex; + u32 *speed; u16 cpi_base[MAX_NUM_VFS_SUPPORTED]; u16 rssi_base[MAX_NUM_VFS_SUPPORTED]; bool mbx_lock[MAX_NUM_VFS_SUPPORTED]; @@ -185,7 +185,7 @@ static void nic_mbx_send_ready(struct nicpf *nic, int vf) mbx.nic_cfg.sqs_mode = (vf >= nic->num_vf_en) ? true : false; mbx.nic_cfg.node_id = nic->node; - mbx.nic_cfg.loopback_supported = vf < MAX_LMAC; + mbx.nic_cfg.loopback_supported = vf < nic->num_vf_en; nic_send_msg_to_vf(nic, vf, &mbx); } @@ -336,8 +336,17 @@ static void nic_set_lmac_vf_mapping(struct nicpf *nic) } } -static void nic_get_hw_info(struct nicpf *nic) +static void nic_free_lmacmem(struct nicpf *nic) { + kfree(nic->vf_lmac_map); + kfree(nic->link); + kfree(nic->duplex); + kfree(nic->speed); +} + +static int nic_get_hw_info(struct nicpf *nic) +{ + u8 max_lmac; u16 sdevid; struct hw_info *hw = nic->hw; @@ -385,18 +394,40 @@ static void nic_get_hw_info(struct nicpf *nic) break; } hw->tl4_cnt = MAX_QUEUES_PER_QSET * pci_sriov_get_totalvfs(nic->pdev); + + /* Allocate memory for LMAC tracking elements */ + max_lmac = hw->bgx_cnt * MAX_LMAC_PER_BGX; + nic->vf_lmac_map = kmalloc_array(max_lmac, sizeof(u8), GFP_KERNEL); + if (!nic->vf_lmac_map) + goto error; + nic->link = kmalloc_array(max_lmac, sizeof(u8), GFP_KERNEL); + if (!nic->link) + goto error; + nic->duplex = kmalloc_array(max_lmac, sizeof(u8), GFP_KERNEL); + if (!nic->duplex) + goto error; + nic->speed = kmalloc_array(max_lmac, sizeof(u32), GFP_KERNEL); + if (!nic->speed) + goto error; + return 0; + +error: + nic_free_lmacmem(nic); + return -ENOMEM; } #define BGX0_BLOCK 8 #define BGX1_BLOCK 9 -static void nic_init_hw(struct nicpf *nic) +static int nic_init_hw(struct nicpf *nic) { - int i; + int i, err; u64 cqm_cfg; /* Get HW capability info */ - nic_get_hw_info(nic); + err = nic_get_hw_info(nic); + if (err) + return err; /* Enable NIC HW block */ nic_reg_write(nic, NIC_PF_CFG, 0x3); @@ -442,6 +473,8 @@ static void nic_init_hw(struct nicpf *nic) cqm_cfg = nic_reg_read(nic, NIC_PF_CQM_CFG); if (cqm_cfg < NICPF_CQM_MIN_DROP_LEVEL) nic_reg_write(nic, NIC_PF_CQM_CFG, NICPF_CQM_MIN_DROP_LEVEL); + + return 0; } /* Channel parse index configuration */ @@ -741,7 +774,7 @@ static int nic_config_loopback(struct nicpf *nic, struct set_loopback *lbk) { int bgx_idx, lmac_idx; - if (lbk->vf_id > MAX_LMAC) + if (lbk->vf_id >= nic->num_vf_en) return -1; bgx_idx = NIC_GET_BGX_FROM_VF_LMAC_MAP(nic->vf_lmac_map[lbk->vf_id]); @@ -837,7 +870,7 @@ static void nic_handle_mbx_intr(struct nicpf *nic, int vf) switch (mbx.msg.msg) { case NIC_MBOX_MSG_READY: nic_mbx_send_ready(nic, vf); - if (vf < MAX_LMAC) { + if (vf < nic->num_vf_en) { nic->link[vf] = 0; nic->duplex[vf] = 0; nic->speed[vf] = 0; @@ -1240,7 +1273,9 @@ static int nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) nic->node = nic_get_node_id(pdev); /* Initialize hardware */ - nic_init_hw(nic); + err = nic_init_hw(nic); + if (err) + goto err_release_regions; nic_set_lmac_vf_mapping(nic); @@ -1275,6 +1310,7 @@ err_unregister_interrupts: err_release_regions: pci_release_regions(pdev); err_disable_device: + nic_free_lmacmem(nic); devm_kfree(dev, nic->hw); devm_kfree(dev, nic); pci_disable_device(pdev); @@ -1298,6 +1334,7 @@ static void nic_remove(struct pci_dev *pdev) nic_unregister_interrupts(nic); pci_release_regions(pdev); + nic_free_lmacmem(nic); devm_kfree(&pdev->dev, nic->hw); devm_kfree(&pdev->dev, nic); diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.h b/drivers/net/ethernet/cavium/thunder/thunder_bgx.h index 6225ff4..c7d7cc6 100644 --- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.h +++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.h @@ -29,8 +29,6 @@ #define MAX_DMAC_PER_LMAC_TNS_BYPASS_MODE 2 -#define MAX_LMAC (MAX_BGX_PER_CN88XX * MAX_LMAC_PER_BGX) - /* Registers */ #define BGX_CMRX_CFG 0x00 #define CMR_PKT_TX_EN BIT_ULL(13) -- 2.7.4