linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Steve Wise <swise-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW@public.gmane.org>
Subject: [PATCH rdma-core 08/10] cxgb: Use the new common PCI matching infrastructure
Date: Tue, 19 Sep 2017 15:18:49 -0600	[thread overview]
Message-ID: <1505855931-4956-9-git-send-email-jgunthorpe@obsidianresearch.com> (raw)
In-Reply-To: <1505855931-4956-1-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>

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 <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
 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,
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2017-09-19 21:18 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-19 21:18 [PATCH rdma-core 00/10] Rework the verb init scheme Jason Gunthorpe
     [not found] ` <1505855931-4956-1-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-09-19 21:18   ` [PATCH rdma-core 01/10] verbs: Change verbs_register_driver to accept the ops struct directly Jason Gunthorpe
     [not found]     ` <1505855931-4956-2-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-09-19 21:31       ` Steve Wise
2017-09-25  6:46         ` Devesh Sharma
2017-09-19 21:18   ` [PATCH rdma-core 02/10] cxgb4: Move sysconf up to driver_init Jason Gunthorpe
     [not found]     ` <1505855931-4956-3-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-09-19 21:23       ` Steve Wise
2017-09-19 21:18   ` [PATCH rdma-core 03/10] verbs: Split init_device into a match and alloc/bind step Jason Gunthorpe
     [not found]     ` <1505855931-4956-4-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-09-26 16:00       ` Yishai Hadas
     [not found]         ` <5a30e4a3-e22c-5d1a-435d-d3c5d94333fd-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2017-09-27  7:55           ` Leon Romanovsky
     [not found]             ` <20170927075552.GC2297-U/DQcQFIOTAAJjI8aNfphQ@public.gmane.org>
2017-09-27 13:49               ` Yishai Hadas
2017-09-28 15:56           ` Jason Gunthorpe
2017-09-19 21:18   ` [PATCH rdma-core 04/10] providers: Use the new match_device and allocate_device ops Jason Gunthorpe
     [not found]     ` <1505855931-4956-5-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-09-19 21:29       ` Steve Wise
2017-09-19 22:32         ` Jason Gunthorpe
2017-09-24 13:44       ` Amrani, Ram
     [not found]         ` <BN3PR07MB257813BD7D36694EBF97BA91F8650-EldUQEzkDQfpW3VS/XPqkOFPX92sqiQdvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-09-24 20:10           ` Jason Gunthorpe
     [not found]             ` <20170924201053.GA31652-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-09-25 12:52               ` Amrani, Ram
2017-09-25  7:41       ` Devesh Sharma
2017-09-19 21:18   ` [PATCH rdma-core 05/10] verbs: Remove the init_device entry point Jason Gunthorpe
2017-09-19 21:18   ` [PATCH rdma-core 06/10] verbs: Provide common code to match providers against kernel devices Jason Gunthorpe
2017-09-19 21:18   ` [PATCH rdma-core 07/10] providers: Use the new common PCI matching infrastructure Jason Gunthorpe
     [not found]     ` <1505855931-4956-8-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-09-24 13:29       ` Amrani, Ram
     [not found]         ` <BN3PR07MB2578333789DA041401297EC0F8650-EldUQEzkDQfpW3VS/XPqkOFPX92sqiQdvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-09-24 15:58           ` Jason Gunthorpe
     [not found]             ` <20170924155845.GB14796-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-09-25 12:52               ` Amrani, Ram
2017-09-25  7:48       ` Devesh Sharma
2017-09-19 21:18   ` Jason Gunthorpe [this message]
     [not found]     ` <1505855931-4956-9-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-09-19 21:24       ` [PATCH rdma-core 08/10] cxgb: " Steve Wise
2017-09-19 21:18   ` [PATCH rdma-core 09/10] hns: Use the generic modalias matcher Jason Gunthorpe
     [not found]     ` <1505855931-4956-10-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-09-20  3:28       ` oulijun
2017-09-19 21:18   ` [PATCH rdma-core 10/10] rxe: Use VERBS_NAME_MATCH to match the rxe device Jason Gunthorpe
2017-09-28 14:03   ` [PATCH rdma-core 00/10] Rework the verb init scheme Leon Romanovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1505855931-4956-9-git-send-email-jgunthorpe@obsidianresearch.com \
    --to=jgunthorpe-epgobjl8dl3ta4ec/59zmfatqe2ktcn/@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=swise-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).