xref: /freebsd/contrib/ofed/libibmad/smp.c (revision 87181516ef48be852d5e5fee53c6e0dbfc62f21e)
1*d6b92ffaSHans Petter Selasky /*
2*d6b92ffaSHans Petter Selasky  * Copyright (c) 2004-2009 Voltaire Inc.  All rights reserved.
3*d6b92ffaSHans Petter Selasky  * Copyright (c) 2011 Mellanox Technologies LTD.  All rights reserved.
4*d6b92ffaSHans Petter Selasky  *
5*d6b92ffaSHans Petter Selasky  * This software is available to you under a choice of one of two
6*d6b92ffaSHans Petter Selasky  * licenses.  You may choose to be licensed under the terms of the GNU
7*d6b92ffaSHans Petter Selasky  * General Public License (GPL) Version 2, available from the file
8*d6b92ffaSHans Petter Selasky  * COPYING in the main directory of this source tree, or the
9*d6b92ffaSHans Petter Selasky  * OpenIB.org BSD license below:
10*d6b92ffaSHans Petter Selasky  *
11*d6b92ffaSHans Petter Selasky  *     Redistribution and use in source and binary forms, with or
12*d6b92ffaSHans Petter Selasky  *     without modification, are permitted provided that the following
13*d6b92ffaSHans Petter Selasky  *     conditions are met:
14*d6b92ffaSHans Petter Selasky  *
15*d6b92ffaSHans Petter Selasky  *      - Redistributions of source code must retain the above
16*d6b92ffaSHans Petter Selasky  *        copyright notice, this list of conditions and the following
17*d6b92ffaSHans Petter Selasky  *        disclaimer.
18*d6b92ffaSHans Petter Selasky  *
19*d6b92ffaSHans Petter Selasky  *      - Redistributions in binary form must reproduce the above
20*d6b92ffaSHans Petter Selasky  *        copyright notice, this list of conditions and the following
21*d6b92ffaSHans Petter Selasky  *        disclaimer in the documentation and/or other materials
22*d6b92ffaSHans Petter Selasky  *        provided with the distribution.
23*d6b92ffaSHans Petter Selasky  *
24*d6b92ffaSHans Petter Selasky  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25*d6b92ffaSHans Petter Selasky  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26*d6b92ffaSHans Petter Selasky  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27*d6b92ffaSHans Petter Selasky  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28*d6b92ffaSHans Petter Selasky  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29*d6b92ffaSHans Petter Selasky  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30*d6b92ffaSHans Petter Selasky  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31*d6b92ffaSHans Petter Selasky  * SOFTWARE.
32*d6b92ffaSHans Petter Selasky  *
33*d6b92ffaSHans Petter Selasky  */
34*d6b92ffaSHans Petter Selasky 
35*d6b92ffaSHans Petter Selasky #if HAVE_CONFIG_H
36*d6b92ffaSHans Petter Selasky #  include <config.h>
37*d6b92ffaSHans Petter Selasky #endif				/* HAVE_CONFIG_H */
38*d6b92ffaSHans Petter Selasky 
39*d6b92ffaSHans Petter Selasky #include <stdio.h>
40*d6b92ffaSHans Petter Selasky #include <stdlib.h>
41*d6b92ffaSHans Petter Selasky #include <string.h>
42*d6b92ffaSHans Petter Selasky 
43*d6b92ffaSHans Petter Selasky #include <infiniband/umad.h>
44*d6b92ffaSHans Petter Selasky #include <infiniband/mad.h>
45*d6b92ffaSHans Petter Selasky #include "mad_internal.h"
46*d6b92ffaSHans Petter Selasky 
47*d6b92ffaSHans Petter Selasky #undef DEBUG
48*d6b92ffaSHans Petter Selasky #define DEBUG 	if (ibdebug)	IBWARN
49*d6b92ffaSHans Petter Selasky 
smp_mkey_set(struct ibmad_port * srcport,uint64_t mkey)50*d6b92ffaSHans Petter Selasky void smp_mkey_set(struct ibmad_port *srcport, uint64_t mkey)
51*d6b92ffaSHans Petter Selasky {
52*d6b92ffaSHans Petter Selasky 	srcport->smp_mkey = mkey;
53*d6b92ffaSHans Petter Selasky }
54*d6b92ffaSHans Petter Selasky 
smp_mkey_get(const struct ibmad_port * srcport)55*d6b92ffaSHans Petter Selasky uint64_t smp_mkey_get(const struct ibmad_port *srcport)
56*d6b92ffaSHans Petter Selasky {
57*d6b92ffaSHans Petter Selasky 	return srcport->smp_mkey;
58*d6b92ffaSHans Petter Selasky }
59*d6b92ffaSHans Petter Selasky 
smp_set_status_via(void * data,ib_portid_t * portid,unsigned attrid,unsigned mod,unsigned timeout,int * rstatus,const struct ibmad_port * srcport)60*d6b92ffaSHans Petter Selasky uint8_t *smp_set_status_via(void *data, ib_portid_t * portid, unsigned attrid,
61*d6b92ffaSHans Petter Selasky 			    unsigned mod, unsigned timeout, int *rstatus,
62*d6b92ffaSHans Petter Selasky 			    const struct ibmad_port *srcport)
63*d6b92ffaSHans Petter Selasky {
64*d6b92ffaSHans Petter Selasky 	ib_rpc_t rpc = { 0 };
65*d6b92ffaSHans Petter Selasky 	uint8_t *res;
66*d6b92ffaSHans Petter Selasky 
67*d6b92ffaSHans Petter Selasky 	DEBUG("attr 0x%x mod 0x%x route %s", attrid, mod, portid2str(portid));
68*d6b92ffaSHans Petter Selasky 	if ((portid->lid <= 0) ||
69*d6b92ffaSHans Petter Selasky 	    (portid->drpath.drslid == 0xffff) ||
70*d6b92ffaSHans Petter Selasky 	    (portid->drpath.drdlid == 0xffff))
71*d6b92ffaSHans Petter Selasky 		rpc.mgtclass = IB_SMI_DIRECT_CLASS;	/* direct SMI */
72*d6b92ffaSHans Petter Selasky 	else
73*d6b92ffaSHans Petter Selasky 		rpc.mgtclass = IB_SMI_CLASS;	/* Lid routed SMI */
74*d6b92ffaSHans Petter Selasky 
75*d6b92ffaSHans Petter Selasky 	rpc.method = IB_MAD_METHOD_SET;
76*d6b92ffaSHans Petter Selasky 	rpc.attr.id = attrid;
77*d6b92ffaSHans Petter Selasky 	rpc.attr.mod = mod;
78*d6b92ffaSHans Petter Selasky 	rpc.timeout = timeout;
79*d6b92ffaSHans Petter Selasky 	rpc.datasz = IB_SMP_DATA_SIZE;
80*d6b92ffaSHans Petter Selasky 	rpc.dataoffs = IB_SMP_DATA_OFFS;
81*d6b92ffaSHans Petter Selasky 	rpc.mkey = srcport->smp_mkey;
82*d6b92ffaSHans Petter Selasky 
83*d6b92ffaSHans Petter Selasky 	portid->sl = 0;
84*d6b92ffaSHans Petter Selasky 	portid->qp = 0;
85*d6b92ffaSHans Petter Selasky 
86*d6b92ffaSHans Petter Selasky 	res = mad_rpc(srcport, &rpc, portid, data, data);
87*d6b92ffaSHans Petter Selasky 	if (rstatus)
88*d6b92ffaSHans Petter Selasky 		*rstatus = rpc.rstatus;
89*d6b92ffaSHans Petter Selasky 	return res;
90*d6b92ffaSHans Petter Selasky }
91*d6b92ffaSHans Petter Selasky 
smp_set_via(void * data,ib_portid_t * portid,unsigned attrid,unsigned mod,unsigned timeout,const struct ibmad_port * srcport)92*d6b92ffaSHans Petter Selasky uint8_t *smp_set_via(void *data, ib_portid_t * portid, unsigned attrid,
93*d6b92ffaSHans Petter Selasky 		     unsigned mod, unsigned timeout,
94*d6b92ffaSHans Petter Selasky 		     const struct ibmad_port *srcport)
95*d6b92ffaSHans Petter Selasky {
96*d6b92ffaSHans Petter Selasky 	return smp_set_status_via(data, portid, attrid, mod, timeout, NULL,
97*d6b92ffaSHans Petter Selasky 				  srcport);
98*d6b92ffaSHans Petter Selasky }
99*d6b92ffaSHans Petter Selasky 
smp_set(void * data,ib_portid_t * portid,unsigned attrid,unsigned mod,unsigned timeout)100*d6b92ffaSHans Petter Selasky uint8_t *smp_set(void *data, ib_portid_t * portid, unsigned attrid,
101*d6b92ffaSHans Petter Selasky 		 unsigned mod, unsigned timeout)
102*d6b92ffaSHans Petter Selasky {
103*d6b92ffaSHans Petter Selasky 	return smp_set_via(data, portid, attrid, mod, timeout, ibmp);
104*d6b92ffaSHans Petter Selasky }
105*d6b92ffaSHans Petter Selasky 
smp_query_status_via(void * rcvbuf,ib_portid_t * portid,unsigned attrid,unsigned mod,unsigned timeout,int * rstatus,const struct ibmad_port * srcport)106*d6b92ffaSHans Petter Selasky uint8_t *smp_query_status_via(void *rcvbuf, ib_portid_t * portid,
107*d6b92ffaSHans Petter Selasky 			      unsigned attrid, unsigned mod, unsigned timeout,
108*d6b92ffaSHans Petter Selasky 			      int *rstatus, const struct ibmad_port * srcport)
109*d6b92ffaSHans Petter Selasky {
110*d6b92ffaSHans Petter Selasky 	ib_rpc_t rpc = { 0 };
111*d6b92ffaSHans Petter Selasky 	uint8_t *res;
112*d6b92ffaSHans Petter Selasky 
113*d6b92ffaSHans Petter Selasky 	DEBUG("attr 0x%x mod 0x%x route %s", attrid, mod, portid2str(portid));
114*d6b92ffaSHans Petter Selasky 	rpc.method = IB_MAD_METHOD_GET;
115*d6b92ffaSHans Petter Selasky 	rpc.attr.id = attrid;
116*d6b92ffaSHans Petter Selasky 	rpc.attr.mod = mod;
117*d6b92ffaSHans Petter Selasky 	rpc.timeout = timeout;
118*d6b92ffaSHans Petter Selasky 	rpc.datasz = IB_SMP_DATA_SIZE;
119*d6b92ffaSHans Petter Selasky 	rpc.dataoffs = IB_SMP_DATA_OFFS;
120*d6b92ffaSHans Petter Selasky 	rpc.mkey = srcport->smp_mkey;
121*d6b92ffaSHans Petter Selasky 
122*d6b92ffaSHans Petter Selasky 	if ((portid->lid <= 0) ||
123*d6b92ffaSHans Petter Selasky 	    (portid->drpath.drslid == 0xffff) ||
124*d6b92ffaSHans Petter Selasky 	    (portid->drpath.drdlid == 0xffff))
125*d6b92ffaSHans Petter Selasky 		rpc.mgtclass = IB_SMI_DIRECT_CLASS;	/* direct SMI */
126*d6b92ffaSHans Petter Selasky 	else
127*d6b92ffaSHans Petter Selasky 		rpc.mgtclass = IB_SMI_CLASS;	/* Lid routed SMI */
128*d6b92ffaSHans Petter Selasky 
129*d6b92ffaSHans Petter Selasky 	portid->sl = 0;
130*d6b92ffaSHans Petter Selasky 	portid->qp = 0;
131*d6b92ffaSHans Petter Selasky 
132*d6b92ffaSHans Petter Selasky 	res = mad_rpc(srcport, &rpc, portid, rcvbuf, rcvbuf);
133*d6b92ffaSHans Petter Selasky 	if (rstatus)
134*d6b92ffaSHans Petter Selasky 		*rstatus = rpc.rstatus;
135*d6b92ffaSHans Petter Selasky 	return res;
136*d6b92ffaSHans Petter Selasky }
137*d6b92ffaSHans Petter Selasky 
smp_query_via(void * rcvbuf,ib_portid_t * portid,unsigned attrid,unsigned mod,unsigned timeout,const struct ibmad_port * srcport)138*d6b92ffaSHans Petter Selasky uint8_t *smp_query_via(void *rcvbuf, ib_portid_t * portid, unsigned attrid,
139*d6b92ffaSHans Petter Selasky 		       unsigned mod, unsigned timeout,
140*d6b92ffaSHans Petter Selasky 		       const struct ibmad_port * srcport)
141*d6b92ffaSHans Petter Selasky {
142*d6b92ffaSHans Petter Selasky 	return smp_query_status_via(rcvbuf, portid, attrid, mod, timeout, NULL,
143*d6b92ffaSHans Petter Selasky 				    srcport);
144*d6b92ffaSHans Petter Selasky }
145*d6b92ffaSHans Petter Selasky 
smp_query(void * rcvbuf,ib_portid_t * portid,unsigned attrid,unsigned mod,unsigned timeout)146*d6b92ffaSHans Petter Selasky uint8_t *smp_query(void *rcvbuf, ib_portid_t * portid, unsigned attrid,
147*d6b92ffaSHans Petter Selasky 		   unsigned mod, unsigned timeout)
148*d6b92ffaSHans Petter Selasky {
149*d6b92ffaSHans Petter Selasky 	return smp_query_via(rcvbuf, portid, attrid, mod, timeout, ibmp);
150*d6b92ffaSHans Petter Selasky }
151