From patchwork Fri Apr 1 11:19:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 12798191 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18B34C433EF for ; Fri, 1 Apr 2022 11:20:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233358AbiDALVs (ORCPT ); Fri, 1 Apr 2022 07:21:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232781AbiDALVr (ORCPT ); Fri, 1 Apr 2022 07:21:47 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2091.outbound.protection.outlook.com [40.107.92.91]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E47218DA95 for ; Fri, 1 Apr 2022 04:19:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dF7eENEXWmXmNWGrx/hJp8UdaI2Vb0IHKmitNt4hpBk+oO6uayP1sVs1J0jiiA+WLF1bWI3qrLoTArGsp9o3mtB9zH1+OxM2vjPN4YZbQfXfNQcyOKk59Ja9QgLrRIKZOj1T2MNWtBrIoXouSVrGePXmCE1GpCc5rrqh1M3SKvPlfHJ1opvI79CMSkFS4lg0jjKZX5ONSBPgfApngdwHr676xHhiHkZ+27T7beGBtMlXt/j+hzaPedvH5CWlAIdojb6PqSD762rNe2JXqCTYNaUj97KOqSS3+XRhCh+nn8E79eq9FaoVqavt2wg/XexuAUJIU4j/0EMSuGa8ALNsvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7ZziwLNX4shRnI1YVjJ47JlNKNCQoCjjUlRQW1vOnUo=; b=bwzDY0oR/LRM9DziUPSKX5C6qg0MjzW4WBg0g62LyUjsq9jMjCEfb9dh+ImRYlblAWxT12mILeWqxzYLWi2L9miVzLnky+9dk0Oo+F/22NVdya21aBxBOPYbrkde7UpLf+xXE9XGTM6mMkCCh+ujhUXNcO7zlnmq4+b71SLeiEl+gvMRvtmrQ47xLqJc5ZldGG9YVzHOkpw4IYIXPIzf9F3oo+LKd3itOG/eQasULd6CbuGqziluIC5QPo2Hgfro0VQsKFH5NRWfYcN3qanAxU/Fe5ML1JKhkVmY8fRuVuv5nSakHNo+j9f1BrngCG40HlWttcdOu/is227TJPXJJg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7ZziwLNX4shRnI1YVjJ47JlNKNCQoCjjUlRQW1vOnUo=; b=uE2Ky2DSiyXG7MRe7uHnfb6YrijjWEc2Qc8bwy0HuP7pLX5lt0iTeFnUfiuu6g70C8wVXr9cKyLDHhWI4qtrJn9z+9V7THAxxQOx7A3qagmhDFu7SdAZ677TLye255W3RoT1nSsRrUnlF79W3kDcxbdhPbPS3vLvN/wKINffpck= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by BLAPR13MB4625.namprd13.prod.outlook.com (2603:10b6:208:320::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.11; Fri, 1 Apr 2022 11:19:54 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::7077:d057:db6b:3113]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::7077:d057:db6b:3113%4]) with mapi id 15.20.5123.021; Fri, 1 Apr 2022 11:19:54 +0000 From: Simon Horman To: David Miller , Jakub Kicinski Cc: netdev@vger.kernel.org, oss-drivers@corigine.com, =?utf-8?q?Niklas_S?= =?utf-8?q?=C3=B6derlund?= , Danie du Toit Subject: [PATCH net] nfp: do not use driver_data to index device info Date: Fri, 1 Apr 2022 13:19:36 +0200 Message-Id: <20220401111936.92777-1-simon.horman@corigine.com> X-Mailer: git-send-email 2.30.2 X-ClientProxiedBy: AM4PR07CA0029.eurprd07.prod.outlook.com (2603:10a6:205:1::42) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 74a5374c-85b6-4b1c-6097-08da13d18bcc X-MS-TrafficTypeDiagnostic: BLAPR13MB4625:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X0DwS+5x78CVvzP9SVqPQPXrcXA1pRvYqHZSijP2OqiJLduwGuwQWHqSuIdG1ZGKuJT/1IwY2rQHQsTu5dnQWdOXoTK8LM2B2naheEl2w3hUlDrMGvV5Q2yLzvY22Pzuf1BgrnOB/e3zs1Uh/JD42R6516tW9HJ6omdI9R3E875SqeDRG2j5bnHhmyV/CJowDhPX95dVbxLkA3RkEUVnmX38he+7gISWxcFjcLXPQ7IxHMw/67WnHzlcBf97CN6jxDk3v34bievjuuW8ATdOp6ZYpRysO0HA5ZUjQFmAbxtno+7Ae7I6bqhinpHl5GWV5fjf3vWxt210IzQvJoZTZlHKQ5aYZAnb3tG8fv2ZrQmkPzkfvPbwfT8bSK1iMtn6maryYPvtRdD7wQ16W1Yt6Cws57xWvlQDblspYYhM21+sw6p28/e5DPGptQj7VpusG2gicaT6RxvfK9u+25exM7qO9BeL+0ER5Bu4/FkiSz03GIKOaNFv0jhNf98RYg2biHlvHYNpuxuSNRP5NRjwrajlLiy31tJ8X8goRHy9zu1XuQQRCDNwO7BayMUNJUmqz9KZnh5il0FCGNkqty3ZJAVXKvgddHx5Un+5PIU85C0SEOCs6eH5ljcUpLOFSB3oxg45i2/mKboiUFCYIBBofxoKQ+nPzCM/bPz7b7uFe+9cuFreIyO5CKj2CJtdS9o/kE57ql1Rp5YJutPzWnCOFDRGokP2qxf5rLBicrvILGp5L6WPAW10q349pq2DeOrm X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR13MB4842.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(396003)(346002)(376002)(136003)(39830400003)(6666004)(36756003)(54906003)(2906002)(8936002)(6486002)(6512007)(107886003)(38350700002)(508600001)(110136005)(83380400001)(8676002)(66476007)(44832011)(186003)(38100700002)(86362001)(1076003)(6506007)(2616005)(66556008)(4326008)(316002)(5660300002)(66946007)(26005)(52116002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?zLC+2t+GcQVNJCG1nu+h91IiSgEr?= =?utf-8?q?gQC/g3aEtSBQuSk8/WkFGLmDxZG4JORL3NjYKsUHlK7kB4+BG1I3vsforw+gspSll?= =?utf-8?q?Nb330sEr5/us7fnc3PN4I5441UyLyMZQKy05QnWqrXS3tD2wbXlHhVbB+QfS6TBc0?= =?utf-8?q?xyLV93tnWjAOyRQCeNRMFemm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mIMjn6bZSLdsMyNObf+iejAfCINbeO6Gkr0I74BH?= =?utf-8?q?LhnTGMsAt3s0Y7KkBckLB4gXLW4v8yEAub25QIxknlBxsd9imzvQvXNv3r//qzy7s?= =?utf-8?q?bzc+bk5JB+BmVwU1JCD8o/RLun+7qcGPafSEnzbeqZBR6nacp64H7pGSPfu2LG9UF?= =?utf-8?q?XZZ5v2z+r6wfBDh52+lls7swr6O3ClHT2zKCdEr8ov7Ja1KNAmTbU4LfJn/y9a5w2?= =?utf-8?q?tLHPhbicmHJaJOJpLANvkRF8rz5pPH+CXqyUfRXx9E111NSf1urjFKUJyaGhBWMKw?= =?utf-8?q?fp1yR72Dve+fYYFepRUsgZHWdHxHuAFVjW+YmTF8dyfZRXJ43CxGSkC0bHo1S8NhX?= =?utf-8?q?nhqZJW8YRMtpz027aqYBQBBCOQ9pqT9IYkeg=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 74a5374c-85b6-4b1c-6097-08da13d18bcc X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2022 11:19:54.2115 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: FUJeS5djzqcFZUMZMQm0+qjVP74/RYKqdP6JixUe0ar+uPYMfM9OU20fzUvKQxyZ2IdMHaDx1NaaSIMzuJnhYUSorbUB6xuzWuWp9JNpM9E= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR13MB4625 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Niklas Söderlund When adding support for multiple chips the struct pci_device_id driver_data field was used to hold a index to lookup chip device specific information from a table. This works but creates a regressions for users who uses /sys/bus/pci/drivers/nfp_netvf/new_id. For example, before the change writing "19ee 6003" to new_id was sufficient but after one needs to write enough fields to be able to also match on the driver_data field, "19ee 6003 19ee ffffffff ffffffff 0 1". The usage of driver_data field was only a convenience and in the belief the driver_data field was private to the driver and not exposed in anyway to users. Changing the device info lookup to a function that translates from struct pci_device_id device field instead works just as well and removes the user facing regression. As a bonus the enum and table with lookup information can be moved out from a shared header file to the only file where it's used. Reported-by: Danie du Toit Fixes: e900db704c8512bc ("nfp: parametrize QCP offset/size using dev_info") Signed-off-by: Niklas Söderlund Signed-off-by: Simon Horman --- drivers/net/ethernet/netronome/nfp/nfp_main.c | 12 ++++---- .../ethernet/netronome/nfp/nfp_netvf_main.c | 8 ++++-- .../ethernet/netronome/nfp/nfpcore/nfp_dev.c | 28 ++++++++++++++++++- .../ethernet/netronome/nfp/nfpcore/nfp_dev.h | 11 ++------ 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_main.c b/drivers/net/ethernet/netronome/nfp/nfp_main.c index eeda39e34f84..b60f2c8b6f4c 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_main.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_main.c @@ -35,19 +35,19 @@ static const char nfp_driver_name[] = "nfp"; static const struct pci_device_id nfp_pci_device_ids[] = { { PCI_VENDOR_ID_NETRONOME, PCI_DEVICE_ID_NETRONOME_NFP3800, PCI_VENDOR_ID_NETRONOME, PCI_ANY_ID, - PCI_ANY_ID, 0, NFP_DEV_NFP3800, + PCI_ANY_ID, 0, }, { PCI_VENDOR_ID_NETRONOME, PCI_DEVICE_ID_NETRONOME_NFP4000, PCI_VENDOR_ID_NETRONOME, PCI_ANY_ID, - PCI_ANY_ID, 0, NFP_DEV_NFP6000, + PCI_ANY_ID, 0, }, { PCI_VENDOR_ID_NETRONOME, PCI_DEVICE_ID_NETRONOME_NFP5000, PCI_VENDOR_ID_NETRONOME, PCI_ANY_ID, - PCI_ANY_ID, 0, NFP_DEV_NFP6000, + PCI_ANY_ID, 0, }, { PCI_VENDOR_ID_NETRONOME, PCI_DEVICE_ID_NETRONOME_NFP6000, PCI_VENDOR_ID_NETRONOME, PCI_ANY_ID, - PCI_ANY_ID, 0, NFP_DEV_NFP6000, + PCI_ANY_ID, 0, }, { 0, } /* Required last entry. */ }; @@ -685,7 +685,9 @@ static int nfp_pci_probe(struct pci_dev *pdev, pdev->device == PCI_DEVICE_ID_NETRONOME_NFP6000_VF) dev_warn(&pdev->dev, "Binding NFP VF device to the NFP PF driver, the VF driver is called 'nfp_netvf'\n"); - dev_info = &nfp_dev_info[pci_id->driver_data]; + dev_info = nfp_get_dev_info(pci_id); + if (!dev_info) + return -ENODEV; err = pci_enable_device(pdev); if (err < 0) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_netvf_main.c b/drivers/net/ethernet/netronome/nfp/nfp_netvf_main.c index a51eb26dd977..c14a76b6f5a0 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_netvf_main.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_netvf_main.c @@ -40,11 +40,11 @@ static const char nfp_net_driver_name[] = "nfp_netvf"; static const struct pci_device_id nfp_netvf_pci_device_ids[] = { { PCI_VENDOR_ID_NETRONOME, PCI_DEVICE_ID_NETRONOME_NFP3800_VF, PCI_VENDOR_ID_NETRONOME, PCI_ANY_ID, - PCI_ANY_ID, 0, NFP_DEV_NFP3800_VF, + PCI_ANY_ID, 0, }, { PCI_VENDOR_ID_NETRONOME, PCI_DEVICE_ID_NETRONOME_NFP6000_VF, PCI_VENDOR_ID_NETRONOME, PCI_ANY_ID, - PCI_ANY_ID, 0, NFP_DEV_NFP6000_VF, + PCI_ANY_ID, 0, }, { 0, } /* Required last entry. */ }; @@ -83,7 +83,9 @@ static int nfp_netvf_pci_probe(struct pci_dev *pdev, int stride; int err; - dev_info = &nfp_dev_info[pci_id->driver_data]; + dev_info = nfp_get_dev_info(pci_id); + if (!dev_info) + return -ENODEV; vf = kzalloc(sizeof(*vf), GFP_KERNEL); if (!vf) diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_dev.c b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_dev.c index 28384d6d1c6f..add14704c6e2 100644 --- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_dev.c +++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_dev.c @@ -3,11 +3,19 @@ #include #include +#include #include #include "nfp_dev.h" -const struct nfp_dev_info nfp_dev_info[NFP_DEV_CNT] = { +enum nfp_dev_id { + NFP_DEV_NFP3800, + NFP_DEV_NFP3800_VF, + NFP_DEV_NFP6000, + NFP_DEV_NFP6000_VF, +}; + +static const struct nfp_dev_info nfp_dev_infos[] = { [NFP_DEV_NFP3800] = { .dma_mask = DMA_BIT_MASK(40), .qc_idx_mask = GENMASK(8, 0), @@ -47,3 +55,21 @@ const struct nfp_dev_info nfp_dev_info[NFP_DEV_CNT] = { .max_qc_size = SZ_256K, }, }; + +const struct nfp_dev_info *nfp_get_dev_info(const struct pci_device_id *id) +{ + switch (id->device) { + case PCI_DEVICE_ID_NETRONOME_NFP3800: + return &nfp_dev_infos[NFP_DEV_NFP3800]; + case PCI_DEVICE_ID_NETRONOME_NFP3800_VF: + return &nfp_dev_infos[NFP_DEV_NFP3800_VF]; + case PCI_DEVICE_ID_NETRONOME_NFP4000: + case PCI_DEVICE_ID_NETRONOME_NFP5000: + case PCI_DEVICE_ID_NETRONOME_NFP6000: + return &nfp_dev_infos[NFP_DEV_NFP6000]; + case PCI_DEVICE_ID_NETRONOME_NFP6000_VF: + return &nfp_dev_infos[NFP_DEV_NFP6000_VF]; + default: + return NULL; + } +} diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_dev.h b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_dev.h index d4189869cf7b..b0ad581d5f38 100644 --- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_dev.h +++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_dev.h @@ -4,16 +4,9 @@ #ifndef _NFP_DEV_H_ #define _NFP_DEV_H_ +#include #include -enum nfp_dev_id { - NFP_DEV_NFP3800, - NFP_DEV_NFP3800_VF, - NFP_DEV_NFP6000, - NFP_DEV_NFP6000_VF, - NFP_DEV_CNT, -}; - struct nfp_dev_info { /* Required fields */ u64 dma_mask; @@ -29,6 +22,6 @@ struct nfp_dev_info { u32 qc_area_sz; }; -extern const struct nfp_dev_info nfp_dev_info[NFP_DEV_CNT]; +const struct nfp_dev_info *nfp_get_dev_info(const struct pci_device_id *id); #endif