From patchwork Tue Sep 19 21:18:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 9960337 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 233106056D for ; Tue, 19 Sep 2017 21:19:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 117BA28F0D for ; Tue, 19 Sep 2017 21:19:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 05E0C28F0C; Tue, 19 Sep 2017 21:19:30 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31A7428F07 for ; Tue, 19 Sep 2017 21:19:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751450AbdISVTW (ORCPT ); Tue, 19 Sep 2017 17:19:22 -0400 Received: from quartz.orcorp.ca ([184.70.90.242]:41369 "EHLO quartz.orcorp.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751361AbdISVTV (ORCPT ); Tue, 19 Sep 2017 17:19:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=obsidianresearch.com; s=rsa1; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=5kDk6uCFu3BmhqbwyJzVNfi6Y3o96acTBzgKceq4zDM=; b=kh9dftdxY3d0GLE93f4A266PHGR7qZNfuTQoX1Vf1VOpPsArY61j1c6m8DWYHyHKbK70yOSka2TO3paDc/TvlB/gLFBb1k+dgbtieWj9SHn/fGKKW8P6mtDFHS8WHzhtYmLUXBFJJEDbbnh/7afpFvdtrW3+s7hD9+hdl8StIKs=; Received: from [10.0.0.156] (helo=jggl.edm.orcorp.ca) by quartz.orcorp.ca with esmtps (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1duPvM-0000On-Td; Tue, 19 Sep 2017 15:19:20 -0600 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Steve Wise Subject: [PATCH rdma-core 08/10] cxgb: Use the new common PCI matching infrastructure Date: Tue, 19 Sep 2017 15:18:49 -0600 Message-Id: <1505855931-4956-9-git-send-email-jgunthorpe@obsidianresearch.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505855931-4956-1-git-send-email-jgunthorpe@obsidianresearch.com> References: <1505855931-4956-1-git-send-email-jgunthorpe@obsidianresearch.com> X-Broken-Reverse-DNS: no host name found for IP address 10.0.0.156 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP cxgb has an additional check for firmware version that will still be handled by the matching function, after the core code has setup the match pointer. Signed-off-by: Jason Gunthorpe Acked-by: Steve Wise --- providers/cxgb3/iwch.c | 43 +++++++++---------------------------------- providers/cxgb4/dev.c | 44 ++++++++++---------------------------------- 2 files changed, 19 insertions(+), 68 deletions(-) diff --git a/providers/cxgb3/iwch.c b/providers/cxgb3/iwch.c index 7eb283bd9a89e1..3cc1d4c185e97e 100644 --- a/providers/cxgb3/iwch.c +++ b/providers/cxgb3/iwch.c @@ -56,16 +56,10 @@ #define PCI_DEVICE_ID_CHELSIO_T3C20 0x0035 #define PCI_DEVICE_ID_CHELSIO_S320E 0x0036 -#define HCA(v, d, t) \ - { .vendor = PCI_VENDOR_ID_##v, \ - .device = PCI_DEVICE_ID_CHELSIO_##d, \ - .type = CHELSIO_##t } - -static struct hca_ent { - unsigned vendor; - unsigned device; - enum iwch_hca_type type; -} hca_table[] = { +#define HCA(v, d, t) \ + VERBS_PCI_MATCH(PCI_VENDOR_ID_##v, PCI_DEVICE_ID_CHELSIO_##d, \ + (void *)(CHELSIO_##t)) +static const struct verbs_match_ent hca_table[] = { HCA(CHELSIO, PE9000_2C, T3B), HCA(CHELSIO, T302E, T3A), HCA(CHELSIO, T302X, T3A), @@ -175,31 +169,12 @@ static void iwch_uninit_device(struct verbs_device *verbs_device) static bool iwch_device_match(struct verbs_sysfs_dev *sysfs_dev) { - const char *uverbs_sys_path = sysfs_dev->sysfs_path; char value[32], *cp; - unsigned vendor, device, fw_maj, fw_min; - int i; + unsigned int fw_maj, fw_min; - if (ibv_read_sysfs_file(uverbs_sys_path, "device/vendor", - value, sizeof value) < 0) + /* Rely on the core code to match PCI devices */ + if (!sysfs_dev->match) return false; - sscanf(value, "%i", &vendor); - - if (ibv_read_sysfs_file(uverbs_sys_path, "device/device", - value, sizeof value) < 0) - return false; - sscanf(value, "%i", &device); - - for (i = 0; i < sizeof hca_table / sizeof hca_table[0]; ++i) - if (vendor == hca_table[i].vendor && - device == hca_table[i].device) { - sysfs_dev->provider_data = &hca_table[i]; - goto found; - } - - return false; - -found: /* * Verify that the firmware major number matches. Major number @@ -237,14 +212,13 @@ found: static struct verbs_device *iwch_device_alloc(struct verbs_sysfs_dev *sysfs_dev) { struct iwch_device *dev; - struct hca_ent *hca_ent = sysfs_dev->provider_data; dev = calloc(1, sizeof(*dev)); if (!dev) return NULL; pthread_spin_init(&dev->lock, PTHREAD_PROCESS_PRIVATE); - dev->hca_type = hca_ent->type; + dev->hca_type = (uintptr_t)sysfs_dev->match->driver_data; dev->abi_version = sysfs_dev->abi_ver; iwch_page_size = sysconf(_SC_PAGESIZE); @@ -278,6 +252,7 @@ static const struct verbs_device_ops iwch_dev_ops = { .name = "cxgb3", .match_min_abi_version = 0, .match_max_abi_version = ABI_VERS, + .match_table = hca_table, .match_device = iwch_device_match, .alloc_device = iwch_device_alloc, .uninit_device = iwch_uninit_device, diff --git a/providers/cxgb4/dev.c b/providers/cxgb4/dev.c index 43c5a3c97bc864..c99b9e35515f89 100644 --- a/providers/cxgb4/dev.c +++ b/providers/cxgb4/dev.c @@ -48,23 +48,17 @@ /* * Macros needed to support the PCI Device ID Table ... */ -#define CH_PCI_DEVICE_ID_TABLE_DEFINE_BEGIN \ - static struct hca_ent { \ - unsigned vendor; \ - unsigned device; \ - } hca_table[] = { +#define CH_PCI_DEVICE_ID_TABLE_DEFINE_BEGIN \ + static const struct verbs_match_ent hca_table[] = { #define CH_PCI_DEVICE_ID_FUNCTION \ 0x4 -#define CH_PCI_ID_TABLE_ENTRY(__DeviceID) \ - { \ - .vendor = PCI_VENDOR_ID_CHELSIO, \ - .device = (__DeviceID), \ - } +#define CH_PCI_ID_TABLE_ENTRY(__DeviceID) \ + VERBS_PCI_MATCH(PCI_VENDOR_ID_CHELSIO, __DeviceID, NULL) #define CH_PCI_DEVICE_ID_TABLE_DEFINE_END \ - } + {} } #include "t4_chip_type.h" #include "t4_pci_id_tbl.h" @@ -401,31 +395,13 @@ int c4iw_abi_version = 1; static bool c4iw_device_match(struct verbs_sysfs_dev *sysfs_dev) { - const char *uverbs_sys_path = sysfs_dev->sysfs_path; char value[32], *cp; - unsigned vendor, device, fw_maj, fw_min; - int i; - - if (ibv_read_sysfs_file(uverbs_sys_path, "device/vendor", - value, sizeof value) < 0) - return false; - sscanf(value, "%i", &vendor); + unsigned int fw_maj, fw_min; - if (ibv_read_sysfs_file(uverbs_sys_path, "device/device", - value, sizeof value) < 0) + /* Rely on the core code to match PCI devices */ + if (!sysfs_dev->match) return false; - sscanf(value, "%i", &device); - - for (i = 0; i < sizeof hca_table / sizeof hca_table[0]; ++i) - if (vendor == hca_table[i].vendor && - device == hca_table[i].device) { - sysfs_dev->provider_data = &hca_table[i]; - goto found; - } - - return false; -found: /* * Verify that the firmware major number matches. Major number * mismatches are fatal. Minor number mismatches are tolerated. @@ -461,7 +437,6 @@ found: static struct verbs_device *c4iw_device_alloc(struct verbs_sysfs_dev *sysfs_dev) { struct c4iw_dev *dev; - struct hca_ent *hca_ent = sysfs_dev->provider_data; c4iw_page_size = sysconf(_SC_PAGESIZE); c4iw_page_shift = long_log2(c4iw_page_size); @@ -477,7 +452,7 @@ static struct verbs_device *c4iw_device_alloc(struct verbs_sysfs_dev *sysfs_dev) pthread_spin_init(&dev->lock, PTHREAD_PROCESS_PRIVATE); c4iw_abi_version = sysfs_dev->abi_ver; - dev->chip_version = CHELSIO_CHIP_VERSION(hca_ent->device >> 8); + dev->chip_version = CHELSIO_CHIP_VERSION(sysfs_dev->match->device >> 8); dev->abi_version = sysfs_dev->abi_ver; list_node_init(&dev->list); @@ -517,6 +492,7 @@ static const struct verbs_device_ops c4iw_dev_ops = { .name = "cxgb4", .match_min_abi_version = 0, .match_max_abi_version = INT_MAX, + .match_table = hca_table, .match_device = c4iw_device_match, .alloc_device = c4iw_device_alloc, .uninit_device = c4iw_uninit_device,