From patchwork Tue Sep 19 21:18:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 9960341 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 17D42601E9 for ; Tue, 19 Sep 2017 21:19:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08C3A28EF8 for ; Tue, 19 Sep 2017 21:19:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1FBE28EF9; 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 7DCC128F0E for ; Tue, 19 Sep 2017 21:19:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751374AbdISVTX (ORCPT ); Tue, 19 Sep 2017 17:19:23 -0400 Received: from quartz.orcorp.ca ([184.70.90.242]:40332 "EHLO quartz.orcorp.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751457AbdISVTW (ORCPT ); Tue, 19 Sep 2017 17:19:22 -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=d5y9cgTeTKLOkjHzCFH7otWJX+vwGoxStxc5DvhkaJc=; b=VD+eHdm8Op5KOTGPdEVZi1P5rtS9/11QOeULyvy1oDvTQN7t62gg8tcklEflwMD7BL1nRztkoW9ODJWuYCZTV3MSWlZY3FQPttblZ+eTiNSEKpDwMbgKOsvASI9pI+ABIhwM31fYwNo33TI6qOHK6u/bfujprj59iQamg0kUtWY=; 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-V3; Tue, 19 Sep 2017 15:19:20 -0600 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Lijun Ou , "Wei Hu(Xavier)" Subject: [PATCH rdma-core 09/10] hns: Use the generic modalias matcher Date: Tue, 19 Sep 2017 15:18:50 -0600 Message-Id: <1505855931-4956-10-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 Use the new verbs infrastructure to match providers against modalias files. This changes the parse of the compatible string to one that is based on modalias instead of directly reading the compatible string. Signed-off-by: Jason Gunthorpe Acked-by: Lijun Ou --- providers/hns/hns_roce_u.c | 52 +++++++--------------------------------- providers/hns/hns_roce_u.h | 1 + providers/hns/hns_roce_u_hw_v1.c | 1 + 3 files changed, 10 insertions(+), 44 deletions(-) diff --git a/providers/hns/hns_roce_u.c b/providers/hns/hns_roce_u.c index 88389721811fce..c27212ac7fb603 100644 --- a/providers/hns/hns_roce_u.c +++ b/providers/hns/hns_roce_u.c @@ -44,20 +44,11 @@ #define HID_LEN 15 #define DEV_MATCH_LEN 128 -struct hca_ent { - const char *str; - struct hns_roce_u_hw *data; - int version; -}; - -static const struct hca_ent acpi_table[] = { - {"acpi:HISI00D1:", &hns_roce_u_hw_v1, HNS_ROCE_HW_VER1}, - {}, -}; - -static const struct hca_ent dt_table[] = { - {"hisilicon,hns-roce-v1", &hns_roce_u_hw_v1, HNS_ROCE_HW_VER1}, - {}, +static const struct verbs_match_ent hca_table[] = { + VERBS_MODALIAS_MATCH("acpi*:HISI00D1:*", &hns_roce_u_hw_v1), + VERBS_MODALIAS_MATCH("of:N*T*Chisilicon,hns-roce-v1C*", &hns_roce_u_hw_v1), + VERBS_MODALIAS_MATCH("of:N*T*Chisilicon,hns-roce-v1", &hns_roce_u_hw_v1), + {} }; static struct ibv_context *hns_roce_alloc_context(struct ibv_device *ibdev, @@ -178,43 +169,16 @@ static void hns_uninit_device(struct verbs_device *verbs_device) free(dev); } -static bool hns_device_match(struct verbs_sysfs_dev *sysfs_dev) -{ - const char *uverbs_sys_path = sysfs_dev->sysfs_path; - char value[128]; - int i; - - if (ibv_read_sysfs_file(uverbs_sys_path, "device/modalias", - value, sizeof(value)) > 0) - for (i = 0; i < sizeof(acpi_table) / sizeof(acpi_table[0]); ++i) - if (!strcmp(value, acpi_table[i].str)) { - sysfs_dev->provider_data = - (void *)&acpi_table[i]; - return true; - } - - if (ibv_read_sysfs_file(uverbs_sys_path, "device/of_node/compatible", - value, sizeof(value)) > 0) - for (i = 0; i < sizeof(dt_table) / sizeof(dt_table[0]); ++i) - if (!strcmp(value, dt_table[i].str)) { - sysfs_dev->provider_data = (void *)&dt_table[i]; - return true; - } - - return false; -} - static struct verbs_device *hns_device_alloc(struct verbs_sysfs_dev *sysfs_dev) { struct hns_roce_device *dev; - const struct hca_ent *hca_ent = sysfs_dev->provider_data; dev = calloc(1, sizeof(*dev)); if (!dev) return NULL; - dev->u_hw = hca_ent->data; - dev->hw_version = hca_ent->version; + dev->u_hw = sysfs_dev->match->driver_data; + dev->hw_version = dev->u_hw->hw_version; dev->page_size = sysconf(_SC_PAGESIZE); return &dev->ibv_dev; } @@ -223,7 +187,7 @@ static const struct verbs_device_ops hns_roce_dev_ops = { .name = "hns", .match_min_abi_version = 0, .match_max_abi_version = INT_MAX, - .match_device = hns_device_match, + .match_table = hca_table, .alloc_device = hns_device_alloc, .uninit_device = hns_uninit_device, .alloc_context = hns_roce_alloc_context, diff --git a/providers/hns/hns_roce_u.h b/providers/hns/hns_roce_u.h index dc8956af4f8fae..d0e2351fc7fc4c 100644 --- a/providers/hns/hns_roce_u.h +++ b/providers/hns/hns_roce_u.h @@ -170,6 +170,7 @@ struct hns_roce_qp { }; struct hns_roce_u_hw { + uint32_t hw_version; int (*poll_cq)(struct ibv_cq *ibvcq, int ne, struct ibv_wc *wc); int (*arm_cq)(struct ibv_cq *ibvcq, int solicited); int (*post_send)(struct ibv_qp *ibvqp, struct ibv_send_wr *wr, diff --git a/providers/hns/hns_roce_u_hw_v1.c b/providers/hns/hns_roce_u_hw_v1.c index 0de94e1fabd3d9..482eac90df2183 100644 --- a/providers/hns/hns_roce_u_hw_v1.c +++ b/providers/hns/hns_roce_u_hw_v1.c @@ -829,6 +829,7 @@ out: } struct hns_roce_u_hw hns_roce_u_hw_v1 = { + .hw_version = HNS_ROCE_HW_VER1, .poll_cq = hns_roce_u_v1_poll_cq, .arm_cq = hns_roce_u_v1_arm_cq, .post_send = hns_roce_u_v1_post_send,