From patchwork Fri Mar 28 05:49:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hefty, Sean" X-Patchwork-Id: 3900911 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 44478BF540 for ; Fri, 28 Mar 2014 05:50:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 58920202EC for ; Fri, 28 Mar 2014 05:50:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5C8C7202E6 for ; Fri, 28 Mar 2014 05:50:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751238AbaC1Fu1 (ORCPT ); Fri, 28 Mar 2014 01:50:27 -0400 Received: from mga01.intel.com ([192.55.52.88]:3126 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751190AbaC1FuS (ORCPT ); Fri, 28 Mar 2014 01:50:18 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 27 Mar 2014 22:50:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,748,1389772800"; d="scan'208";a="501476354" Received: from cst-linux.jf.intel.com ([10.23.221.72]) by fmsmga001.fm.intel.com with ESMTP; 27 Mar 2014 22:50:16 -0700 From: sean.hefty@intel.com To: linux-rdma@vger.kernel.org Cc: Ira Weiny Subject: [PATCH 05/16] ibacm: Move calling of helper functions out of get_devaddr Date: Thu, 27 Mar 2014 22:49:59 -0700 Message-Id: <1395985810-23822-6-git-send-email-sean.hefty@intel.com> X-Mailer: git-send-email 1.7.3 In-Reply-To: <1395985810-23822-1-git-send-email-sean.hefty@intel.com> References: <1395985810-23822-1-git-send-email-sean.hefty@intel.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ira Weiny Again this is in prep for sharing this code with ibacm and ib_acme get_devaddr uses globals which are specific to ib_acme. Move toward this function being ib_acme specific while the code in get_addr_ip becomes generic. Signed-off-by: Ira Weiny --- linux/acme_linux.c | 64 ++++++++++++++++++++++++++++++++++------------------ src/acm_util.h | 5 ++++ 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/linux/acme_linux.c b/linux/acme_linux.c index b246a9c..187507d 100644 --- a/linux/acme_linux.c +++ b/linux/acme_linux.c @@ -47,25 +47,13 @@ extern int dev_cnt; extern int verbose; static int -get_devaddr(char *ifname, int *dev_index, uint8_t *port, uint16_t *pkey) +get_devaddr(union ibv_gid *sgid, int *dev_index, uint8_t *port) { struct ibv_device_attr dev_attr; struct ibv_port_attr port_attr; - union ibv_gid sgid, gid; + union ibv_gid gid; int ret, i; - ret = acm_if_get_sgid(ifname, &sgid); - if (ret) { - printf("unable to get sgid\n"); - return ret; - } - - ret = acm_if_get_pkey(ifname, pkey); - if (ret) { - printf("unable to get pkey\n"); - return ret; - } - for (*dev_index = 0; *dev_index < dev_cnt; (*dev_index)++) { ret = ibv_query_device(verbs[*dev_index], &dev_attr); if (ret) @@ -81,7 +69,7 @@ get_devaddr(char *ifname, int *dev_index, uint8_t *port, uint16_t *pkey) if (ret || !gid.global.interface_id) break; - if (!memcmp(sgid.raw, gid.raw, sizeof gid)) + if (!memcmp(sgid->raw, gid.raw, sizeof gid)) return 0; } } @@ -89,14 +77,39 @@ get_devaddr(char *ifname, int *dev_index, uint8_t *port, uint16_t *pkey) return -1; } +static void iter_cb(char *ifname, union ibv_gid *gid, uint16_t pkey, + uint8_t addr_type, uint8_t *addr, size_t addr_len, + char *addr_name, void *ctx) +{ + FILE *f = (FILE *)ctx; + int ret; + int dev_index; + uint8_t port; + + ret = get_devaddr(gid, &dev_index, &port); + if (ret) { + printf("Failed to find verbs device for %s\n", ifname); + return; + } + + if (verbose) + printf("%s %s %d 0x%x\n", addr_name, verbs[dev_index]->device->name, port, pkey); + fprintf(f, "%s %s %d 0x%x\n", addr_name, verbs[dev_index]->device->name, port, pkey); +} + int gen_addr_ip(FILE *f) { + return acm_if_iter_sys(iter_cb, (void *)f); +} + +int acm_if_iter_sys(acm_if_iter_cb cb, void *ctx) +{ struct ifconf *ifc; struct ifreq *ifr; char ip[INET6_ADDRSTRLEN]; - int s, ret, dev_index, i, len; + int s, ret, i, len; uint16_t pkey; - uint8_t port; + union ibv_gid sgid; s = socket(AF_INET6, SOCK_DGRAM, 0); if (!s) @@ -137,13 +150,19 @@ int gen_addr_ip(FILE *f) if (!acm_if_is_ib(ifr[i].ifr_name)) continue; - ret = get_devaddr(ifr[i].ifr_name, &dev_index, &port, &pkey); - if (ret) + ret = acm_if_get_sgid(ifr[i].ifr_name, &sgid); + if (ret) { + printf("unable to get sgid\n"); + continue; + } + + ret = acm_if_get_pkey(ifr[i].ifr_name, &pkey); + if (ret) { + printf("unable to get pkey\n"); continue; + } - if (verbose) - printf("%s %s %d 0x%x\n", ip, verbs[dev_index]->device->name, port, pkey); - fprintf(f, "%s %s %d 0x%x\n", ip, verbs[dev_index]->device->name, port, pkey); + cb(ifr[i].ifr_name, &sgid, pkey, 0, NULL, 0, ip, ctx); } ret = 0; @@ -152,4 +171,5 @@ out2: out1: close(s); return ret; + } diff --git a/src/acm_util.h b/src/acm_util.h index 94aac9d..ea86133 100644 --- a/src/acm_util.h +++ b/src/acm_util.h @@ -36,4 +36,9 @@ int acm_if_is_ib(char *ifname); int acm_if_get_pkey(char *ifname, uint16_t *pkey); int acm_if_get_sgid(char *ifname, union ibv_gid *sgid); +typedef void (*acm_if_iter_cb)(char *ifname, union ibv_gid *gid, uint16_t pkey, + uint8_t addr_type, uint8_t *addr, size_t addr_len, + char *addr_name, void *ctx); +int acm_if_iter_sys(acm_if_iter_cb cb, void *ctx); + #endif /* ACM_IF_H */