From patchwork Mon May 24 20:56:11 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Khapyorsky X-Patchwork-Id: 101949 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4OKtS3V020768 for ; Mon, 24 May 2010 20:55:28 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756157Ab0EXUz2 (ORCPT ); Mon, 24 May 2010 16:55:28 -0400 Received: from mail-fx0-f46.google.com ([209.85.161.46]:40767 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756007Ab0EXUz1 (ORCPT ); Mon, 24 May 2010 16:55:27 -0400 Received: by fxm5 with SMTP id 5so2638743fxm.19 for ; Mon, 24 May 2010 13:55:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:received:date:from:to :cc:subject:message-id:mime-version:content-type:content-disposition :user-agent; bh=X6TMrofrMKSAih0RHW2UZ0mXXfSBX1nCjyQHK6nS7dA=; b=lD3snE3oO71nGIye5EqwK6c4FvH7TC2qXWExd3ZXbwoLbewHnGPjv7eu9aR0fqN0s6 OmarMdyTvIu//UvjIpjVALtUciCYd/N8sunU4z4I4wVhQkMEpZ89JYXioKUz3RFWINVF DUW0MDzh5/FPgL85vCoy+V+0v53N2rBz7O4DU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; b=gQYQtpyRJ+bDr+KfwQtmx+qEN7uxHsZiajJRDeemF4lI7aCCTFPZX5g/euHqJWpOSV JFla+cUGrJBCOqII2EhYqw8WbVnOk9oW4jb3rgudNqoYpTv8+LSLyBRrBxZqI/fA4K54 SxPf3XNOLbqXeprANZodjWsat8PgRdZmtdLDk= Received: by 10.103.4.14 with SMTP id g14mr4413127mui.84.1274734525209; Mon, 24 May 2010 13:55:25 -0700 (PDT) Received: from me.localdomain (87.69.36.170.cable.012.net.il [87.69.36.170]) by mx.google.com with ESMTPS id i7sm16855998mue.4.2010.05.24.13.55.24 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 24 May 2010 13:55:24 -0700 (PDT) Received: by me.localdomain (Postfix, from userid 1000) id DEFEC11DF7; Mon, 24 May 2010 23:56:11 +0300 (IDT) Date: Mon, 24 May 2010 23:56:11 +0300 From: Sasha Khapyorsky To: linux-rdma Cc: Eli Dorfman Subject: [PATCH] infiniband-diags/vendstat: code simplifications Message-ID: <20100524205611.GJ28549@me> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Mon, 24 May 2010 20:55:28 +0000 (UTC) diff --git a/infiniband-diags/src/vendstat.c b/infiniband-diags/src/vendstat.c index abff83a..0de5722 100644 --- a/infiniband-diags/src/vendstat.c +++ b/infiniband-diags/src/vendstat.c @@ -97,14 +97,12 @@ typedef struct { } is3_general_info_t; typedef struct { - uint32_t address; - uint32_t data; - uint32_t mask; -} is3_record_t; - -typedef struct { uint8_t reserved[8]; - is3_record_t record[18]; + struct is3_record { + uint32_t address; + uint32_t data; + uint32_t mask; + } record[18]; } is3_config_space_t; #define COUNTER_GROUPS_NUM 2 @@ -127,23 +125,35 @@ typedef struct { is4_group_select_t group_selects[COUNTER_GROUPS_NUM]; } is4_config_counter_groups_t; -void counter_groups_info(ib_portid_t * portid, int port) +static int do_vendor(ib_portid_t *portid, struct ibmad_port *srcport, + uint8_t class, uint8_t method, uint16_t attr_id, + uint32_t attr_mod, void *data) { - char buf[1024]; ib_vendor_call_t call; - is4_counter_group_info_t *cg_info; - int i, num_cg; memset(&call, 0, sizeof(call)); - call.mgmt_class = IB_MLX_VENDOR_CLASS; - call.method = IB_MAD_METHOD_GET; + call.mgmt_class = class; + call.method = method; call.timeout = ibd_timeout; - call.attrid = IB_MLX_IS4_COUNTER_GROUP_INFO; - call.mod = port; + call.attrid = attr_id; + call.mod = attr_mod; + + if (!ib_vendor_call_via(data, portid, &call, srcport)) + IBERROR("vendstat: method %u, attribute %u", method, attr_id); + + return 0; +} + +static void counter_groups_info(ib_portid_t * portid, int port) +{ + char buf[1024]; + is4_counter_group_info_t *cg_info; + int i, num_cg; /* Counter Group Info */ memset(&buf, 0, sizeof(buf)); - if (!ib_vendor_call_via(&buf, portid, &call, srcport)) + if (do_vendor(portid, srcport, IB_MLX_VENDOR_CLASS, IB_MAD_METHOD_GET, + IB_MLX_IS4_COUNTER_GROUP_INFO, port, buf)) IBERROR("counter group info query"); cg_info = (is4_counter_group_info_t *) & buf; @@ -166,20 +176,12 @@ void counter_groups_info(ib_portid_t * portid, int port) static int cg0, cg1; -void config_counter_groups(ib_portid_t * portid, int port) +static void config_counter_groups(ib_portid_t * portid, int port) { char buf[1024]; - ib_vendor_call_t call; is4_config_counter_groups_t *cg_config; - memset(&call, 0, sizeof(call)); - call.mgmt_class = IB_MLX_VENDOR_CLASS; - call.attrid = IB_MLX_IS4_CONFIG_COUNTER_GROUP; - call.timeout = ibd_timeout; - call.mod = port; /* configure counter groups for groups 0 and 1 */ - call.method = IB_MAD_METHOD_SET; - memset(&buf, 0, sizeof(buf)); cg_config = (is4_config_counter_groups_t *) & buf; @@ -188,14 +190,15 @@ void config_counter_groups(ib_portid_t * portid, int port) cg_config->group_selects[0].group_select = (uint8_t) cg0; cg_config->group_selects[1].group_select = (uint8_t) cg1; - if (!ib_vendor_call_via(&buf, portid, &call, srcport)) + if (do_vendor(portid, srcport, IB_MLX_VENDOR_CLASS, IB_MAD_METHOD_SET, + IB_MLX_IS4_CONFIG_COUNTER_GROUP, port, buf)) IBERROR("config counter group set"); /* get config counter groups */ memset(&buf, 0, sizeof(buf)); - call.method = IB_MAD_METHOD_GET; - if (!ib_vendor_call_via(&buf, portid, &call, srcport)) + if (do_vendor(portid, srcport, IB_MLX_VENDOR_CLASS, IB_MAD_METHOD_GET, + IB_MLX_IS4_CONFIG_COUNTER_GROUP, port, buf)) IBERROR("config counter group query"); } @@ -234,10 +237,7 @@ int main(int argc, char **argv) ib_portid_t portid = { 0 }; int port = 0; char buf[1024]; - ib_vendor_call_t call; is3_general_info_t *gi; - is3_config_space_t *cs; - int i; const struct ibdiag_opt opts[] = { {"N", 'N', 0, NULL, "show IS3 or IS4 general information"}, @@ -299,22 +299,16 @@ int main(int argc, char **argv) /* Would need a list of these and it might not be complete */ /* so for right now, punt on this */ - memset(&call, 0, sizeof(call)); - call.mgmt_class = IB_MLX_VENDOR_CLASS; - call.method = IB_MAD_METHOD_GET; - call.timeout = ibd_timeout; - - memset(&buf, 0, sizeof(buf)); /* vendor ClassPortInfo is required attribute if class supported */ - call.attrid = CLASS_PORT_INFO; - if (!ib_vendor_call_via(&buf, &portid, &call, srcport)) + memset(&buf, 0, sizeof(buf)); + if (do_vendor(&portid, srcport, IB_MLX_VENDOR_CLASS, IB_MAD_METHOD_GET, + CLASS_PORT_INFO, 0, buf)) IBERROR("classportinfo query"); memset(&buf, 0, sizeof(buf)); - call.attrid = IB_MLX_IS3_GENERAL_INFO; - if (!ib_vendor_call_via(&buf, &portid, &call, srcport)) - IBERROR("vendstat"); gi = (is3_general_info_t *) & buf; + if (do_vendor(&portid, srcport, IB_MLX_VENDOR_CLASS, IB_MAD_METHOD_GET, + IB_MLX_IS3_GENERAL_INFO, 0, gi)) if (general_info) { /* dump IS3 or IS4 general info here */ @@ -336,20 +330,22 @@ int main(int argc, char **argv) } if (xmit_wait) { + is3_config_space_t *cs; + unsigned i; + if (ntohs(gi->hw_info.device_id) != IS3_DEVICE_ID) IBERROR("Unsupported device ID 0x%x", ntohs(gi->hw_info.device_id)); memset(&buf, 0, sizeof(buf)); - call.attrid = IB_MLX_IS3_CONFIG_SPACE_ACCESS; - /* Limit of 18 accesses per MAD ? */ - call.mod = 2 << 22 | 16 << 16; /* 16 records */ /* Set record addresses for each port */ cs = (is3_config_space_t *) & buf; for (i = 0; i < 16; i++) cs->record[i].address = htonl(IB_MLX_IS3_PORT_XMIT_WAIT + ((i + 1) << 12)); - if (!ib_vendor_call_via(&buf, &portid, &call, srcport)) + if (do_vendor(&portid, srcport, IB_MLX_VENDOR_CLASS, + IB_MAD_METHOD_GET, IB_MLX_IS3_CONFIG_SPACE_ACCESS, + 2 << 22 | 16 << 16, cs)) IBERROR("vendstat"); for (i = 0; i < 16; i++) @@ -358,14 +354,14 @@ int main(int argc, char **argv) /* Last 8 ports is another query */ memset(&buf, 0, sizeof(buf)); - call.attrid = IB_MLX_IS3_CONFIG_SPACE_ACCESS; - call.mod = 2 << 22 | 8 << 16; /* 8 records */ /* Set record addresses for each port */ cs = (is3_config_space_t *) & buf; for (i = 0; i < 8; i++) cs->record[i].address = htonl(IB_MLX_IS3_PORT_XMIT_WAIT + ((i + 17) << 12)); - if (!ib_vendor_call_via(&buf, &portid, &call, srcport)) + if (do_vendor(&portid, srcport, IB_MLX_VENDOR_CLASS, + IB_MAD_METHOD_GET, IB_MLX_IS3_CONFIG_SPACE_ACCESS, + 2 << 22 | 8 << 16, cs)) IBERROR("vendstat"); for (i = 0; i < 8; i++)