]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/ofed/management/libibmad/include/infiniband/mad.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / ofed / management / libibmad / include / infiniband / mad.h
1 /*
2  * Copyright (c) 2004-2007 Voltaire Inc.  All rights reserved.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and/or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  *
32  */
33 #ifndef _MAD_H_
34 #define _MAD_H_
35
36 #include <stdint.h>
37 #include <string.h>
38
39 #ifdef __cplusplus
40 #  define BEGIN_C_DECLS extern "C" {
41 #  define END_C_DECLS   }
42 #else /* !__cplusplus */
43 #  define BEGIN_C_DECLS
44 #  define END_C_DECLS
45 #endif /* __cplusplus */
46
47 BEGIN_C_DECLS
48
49 #define IB_SUBNET_PATH_HOPS_MAX 64
50 #define IB_DEFAULT_SUBN_PREFIX  0xfe80000000000000llu
51 #define IB_DEFAULT_QP1_QKEY     0x80010000
52
53 #define IB_MAD_SIZE             256
54
55 #define IB_SMP_DATA_OFFS        64
56 #define IB_SMP_DATA_SIZE        64
57
58 #define IB_VENDOR_RANGE1_DATA_OFFS      24
59 #define IB_VENDOR_RANGE1_DATA_SIZE      (IB_MAD_SIZE - IB_VENDOR_RANGE1_DATA_OFFS)
60
61 #define IB_VENDOR_RANGE2_DATA_OFFS      40
62 #define IB_VENDOR_RANGE2_DATA_SIZE      (IB_MAD_SIZE - IB_VENDOR_RANGE2_DATA_OFFS)
63
64 #define IB_SA_DATA_SIZE         200
65 #define IB_SA_DATA_OFFS         56
66
67 #define IB_PC_DATA_OFFS         64
68 #define IB_PC_DATA_SZ           (IB_MAD_SIZE - IB_PC_DATA_OFFS)
69
70 #define IB_SA_MCM_RECSZ         53
71 #define IB_SA_PR_RECSZ          64
72
73 enum MAD_CLASSES {
74         IB_SMI_CLASS =          0x1,
75         IB_SMI_DIRECT_CLASS =   0x81,
76         IB_SA_CLASS =           0x3,
77         IB_PERFORMANCE_CLASS =  0x4,
78         IB_BOARD_MGMT_CLASS =   0x5,
79         IB_DEVICE_MGMT_CLASS =  0x6,
80         IB_CM_CLASS =           0x7,
81         IB_SNMP_CLASS =         0x8,
82         IB_VENDOR_RANGE1_START_CLASS = 0x9,
83         IB_VENDOR_RANGE1_END_CLASS = 0x0f,
84         IB_CC_CLASS =           0x21,
85         IB_VENDOR_RANGE2_START_CLASS = 0x30,
86         IB_VENDOR_RANGE2_END_CLASS = 0x4f,
87 };
88
89 enum MAD_METHODS {
90         IB_MAD_METHOD_GET =             0x1,
91         IB_MAD_METHOD_SET =             0x2,
92         IB_MAD_METHOD_GET_RESPONSE =    0x81,
93
94         IB_MAD_METHOD_SEND =            0x3,
95         IB_MAD_METHOD_TRAP =            0x5,
96         IB_MAD_METHOD_TRAP_REPRESS =    0x7,
97
98         IB_MAD_METHOD_REPORT =          0x6,
99         IB_MAD_METHOD_REPORT_RESPONSE = 0x86,
100         IB_MAD_METHOD_GET_TABLE =       0x12,
101         IB_MAD_METHOD_GET_TABLE_RESPONSE = 0x92,
102         IB_MAD_METHOD_GET_TRACE_TABLE = 0x13,
103         IB_MAD_METHOD_GET_TRACE_TABLE_RESPONSE = 0x93,
104         IB_MAD_METHOD_GETMULTI =        0x14,
105         IB_MAD_METHOD_GETMULTI_RESPONSE = 0x94,
106         IB_MAD_METHOD_DELETE =          0x15,
107         IB_MAD_METHOD_DELETE_RESPONSE = 0x95,
108
109         IB_MAD_RESPONSE =               0x80,
110 };
111
112 enum MAD_ATTR_ID {
113         CLASS_PORT_INFO = 0x1,
114         NOTICE = 0x2,
115         INFORM_INFO = 0x3,
116 };
117
118 enum SMI_ATTR_ID {
119         IB_ATTR_NODE_DESC = 0x10,
120         IB_ATTR_NODE_INFO = 0x11,
121         IB_ATTR_SWITCH_INFO = 0x12,
122         IB_ATTR_GUID_INFO = 0x14,
123         IB_ATTR_PORT_INFO = 0x15,
124         IB_ATTR_PKEY_TBL = 0x16,
125         IB_ATTR_SLVL_TABLE = 0x17,
126         IB_ATTR_VL_ARBITRATION = 0x18,
127         IB_ATTR_LINEARFORWTBL = 0x19,
128         IB_ATTR_MULTICASTFORWTBL = 0x1b,
129         IB_ATTR_SMINFO = 0x20,
130
131         IB_ATTR_LAST
132 };
133
134 enum SA_ATTR_ID {
135         IB_SA_ATTR_NOTICE = 0x02,
136         IB_SA_ATTR_INFORMINFO = 0x03,
137         IB_SA_ATTR_PORTINFORECORD = 0x12,
138         IB_SA_ATTR_LINKRECORD = 0x20,
139         IB_SA_ATTR_SERVICERECORD = 0x31,
140         IB_SA_ATTR_PATHRECORD = 0x35,
141         IB_SA_ATTR_MCRECORD = 0x38,
142         IB_SA_ATTR_MULTIPATH = 0x3a,
143
144         IB_SA_ATTR_LAST
145 };
146
147 enum GSI_ATTR_ID {
148         IB_GSI_PORT_SAMPLES_CONTROL = 0x10,
149         IB_GSI_PORT_SAMPLES_RESULT = 0x11,
150         IB_GSI_PORT_COUNTERS = 0x12,
151         IB_GSI_PORT_COUNTERS_EXT = 0x1D,
152
153         IB_GSI_ATTR_LAST
154 };
155
156 #define IB_VENDOR_OPENIB_PING_CLASS     (IB_VENDOR_RANGE2_START_CLASS + 2)
157 #define IB_VENDOR_OPENIB_SYSSTAT_CLASS  (IB_VENDOR_RANGE2_START_CLASS + 3)
158 #define IB_OPENIB_OUI                   (0x001405)
159
160 typedef uint8_t ibmad_gid_t[16];
161 #ifdef USE_DEPRECATED_IB_GID_T
162 typedef ibmad_gid_t ib_gid_t __attribute__((deprecated));
163 #endif
164
165 typedef struct {
166         int cnt;
167         uint8_t p[IB_SUBNET_PATH_HOPS_MAX];
168         uint16_t drslid;
169         uint16_t drdlid;
170 } ib_dr_path_t;
171
172 typedef struct {
173         unsigned id;
174         unsigned mod;
175 } ib_attr_t;
176
177 typedef struct {
178         int mgtclass;
179         int method;
180         ib_attr_t attr;
181         uint32_t rstatus;       /* return status */
182         int dataoffs;
183         int datasz;
184         uint64_t mkey;
185         uint64_t trid;  /* used for out mad if nonzero, return real val */
186         uint64_t mask;  /* for sa mads */
187         unsigned recsz; /* for sa mads (attribute offset) */
188         int timeout;
189         uint32_t oui;   /* for vendor range 2 mads */
190 } ib_rpc_t;
191
192 typedef struct portid {
193         int lid;                /* lid or 0 if directed route */
194         ib_dr_path_t drpath;
195         int grh_present;        /* flag */
196         ibmad_gid_t gid;
197         uint32_t qp;
198         uint32_t qkey;
199         uint8_t sl;
200         unsigned pkey_idx;
201 } ib_portid_t;
202
203 typedef void (ib_mad_dump_fn)(char *buf, int bufsz, void *val, int valsz);
204
205 #define IB_FIELD_NAME_LEN       32
206
207 typedef struct ib_field {
208         int bitoffs;
209         int bitlen;
210         char name[IB_FIELD_NAME_LEN];
211         ib_mad_dump_fn *def_dump_fn;
212 } ib_field_t;
213
214 enum MAD_FIELDS {
215         IB_NO_FIELD,
216
217         IB_GID_PREFIX_F,
218         IB_GID_GUID_F,
219
220         /* first MAD word (0-3 bytes) */
221         IB_MAD_METHOD_F,
222         IB_MAD_RESPONSE_F,
223         IB_MAD_CLASSVER_F,
224         IB_MAD_MGMTCLASS_F,
225         IB_MAD_BASEVER_F,
226
227         /* second MAD word (4-7 bytes) */
228         IB_MAD_STATUS_F,
229
230         /* DRSMP only */
231         IB_DRSMP_HOPCNT_F,
232         IB_DRSMP_HOPPTR_F,
233         IB_DRSMP_STATUS_F,
234         IB_DRSMP_DIRECTION_F,
235
236         /* words 3,4,5,6 (8-23 bytes) */
237         IB_MAD_TRID_F,
238         IB_MAD_ATTRID_F,
239         IB_MAD_ATTRMOD_F,
240
241         /* word 7,8 (24-31 bytes) */
242         IB_MAD_MKEY_F,
243
244         /* word 9 (32-37 bytes) */
245         IB_DRSMP_DRSLID_F,
246         IB_DRSMP_DRDLID_F,
247
248         /* word 10,11 (36-43 bytes) */
249         IB_SA_MKEY_F,
250
251         /* word 12 (44-47 bytes) */
252         IB_SA_ATTROFFS_F,
253
254         /* word 13,14 (48-55 bytes) */
255         IB_SA_COMPMASK_F,
256
257         /* word 13,14 (56-255 bytes) */
258         IB_SA_DATA_F,
259
260         /* bytes 64 - 127 */
261         IB_SM_DATA_F,
262
263         /* bytes 64 - 256 */
264         IB_GS_DATA_F,
265
266         /* bytes 128 - 191 */
267         IB_DRSMP_PATH_F,
268
269         /* bytes 192 - 255 */
270         IB_DRSMP_RPATH_F,
271
272         /*
273          * PortInfo fields:
274          */
275         IB_PORT_FIRST_F,
276         IB_PORT_MKEY_F = IB_PORT_FIRST_F,
277         IB_PORT_GID_PREFIX_F,
278         IB_PORT_LID_F,
279         IB_PORT_SMLID_F,
280         IB_PORT_CAPMASK_F,
281         IB_PORT_DIAG_F,
282         IB_PORT_MKEY_LEASE_F,
283         IB_PORT_LOCAL_PORT_F,
284         IB_PORT_LINK_WIDTH_ENABLED_F,
285         IB_PORT_LINK_WIDTH_SUPPORTED_F,
286         IB_PORT_LINK_WIDTH_ACTIVE_F,
287         IB_PORT_LINK_SPEED_SUPPORTED_F,
288         IB_PORT_STATE_F,
289         IB_PORT_PHYS_STATE_F,
290         IB_PORT_LINK_DOWN_DEF_F,
291         IB_PORT_MKEY_PROT_BITS_F,
292         IB_PORT_LMC_F,
293         IB_PORT_LINK_SPEED_ACTIVE_F,
294         IB_PORT_LINK_SPEED_ENABLED_F,
295         IB_PORT_NEIGHBOR_MTU_F,
296         IB_PORT_SMSL_F,
297         IB_PORT_VL_CAP_F,
298         IB_PORT_INIT_TYPE_F,
299         IB_PORT_VL_HIGH_LIMIT_F,
300         IB_PORT_VL_ARBITRATION_HIGH_CAP_F,
301         IB_PORT_VL_ARBITRATION_LOW_CAP_F,
302         IB_PORT_INIT_TYPE_REPLY_F,
303         IB_PORT_MTU_CAP_F,
304         IB_PORT_VL_STALL_COUNT_F,
305         IB_PORT_HOQ_LIFE_F,
306         IB_PORT_OPER_VLS_F,
307         IB_PORT_PART_EN_INB_F,
308         IB_PORT_PART_EN_OUTB_F,
309         IB_PORT_FILTER_RAW_INB_F,
310         IB_PORT_FILTER_RAW_OUTB_F,
311         IB_PORT_MKEY_VIOL_F,
312         IB_PORT_PKEY_VIOL_F,
313         IB_PORT_QKEY_VIOL_F,
314         IB_PORT_GUID_CAP_F,
315         IB_PORT_CLIENT_REREG_F,
316         IB_PORT_SUBN_TIMEOUT_F,
317         IB_PORT_RESP_TIME_VAL_F,
318         IB_PORT_LOCAL_PHYS_ERR_F,
319         IB_PORT_OVERRUN_ERR_F,
320         IB_PORT_MAX_CREDIT_HINT_F,
321         IB_PORT_LINK_ROUND_TRIP_F,
322         IB_PORT_LAST_F,
323
324         /*
325          * NodeInfo fields:
326          */
327         IB_NODE_FIRST_F,
328         IB_NODE_BASE_VERS_F = IB_NODE_FIRST_F,
329         IB_NODE_CLASS_VERS_F,
330         IB_NODE_TYPE_F,
331         IB_NODE_NPORTS_F,
332         IB_NODE_SYSTEM_GUID_F,
333         IB_NODE_GUID_F,
334         IB_NODE_PORT_GUID_F,
335         IB_NODE_PARTITION_CAP_F,
336         IB_NODE_DEVID_F,
337         IB_NODE_REVISION_F,
338         IB_NODE_LOCAL_PORT_F,
339         IB_NODE_VENDORID_F,
340         IB_NODE_LAST_F,
341
342         /*
343          * SwitchInfo fields:
344          */
345         IB_SW_FIRST_F,
346         IB_SW_LINEAR_FDB_CAP_F = IB_SW_FIRST_F,
347         IB_SW_RANDOM_FDB_CAP_F,
348         IB_SW_MCAST_FDB_CAP_F,
349         IB_SW_LINEAR_FDB_TOP_F,
350         IB_SW_DEF_PORT_F,
351         IB_SW_DEF_MCAST_PRIM_F,
352         IB_SW_DEF_MCAST_NOT_PRIM_F,
353         IB_SW_LIFE_TIME_F,
354         IB_SW_STATE_CHANGE_F,
355         IB_SW_LIDS_PER_PORT_F,
356         IB_SW_PARTITION_ENFORCE_CAP_F,
357         IB_SW_PARTITION_ENF_INB_F,
358         IB_SW_PARTITION_ENF_OUTB_F,
359         IB_SW_FILTER_RAW_INB_F,
360         IB_SW_FILTER_RAW_OUTB_F,
361         IB_SW_ENHANCED_PORT0_F,
362         IB_SW_LAST_F,
363
364         /*
365          * SwitchLinearForwardingTable fields:
366          */
367         IB_LINEAR_FORW_TBL_F,
368
369         /*
370          * SwitchMulticastForwardingTable fields:
371          */
372         IB_MULTICAST_FORW_TBL_F,
373
374         /*
375          * NodeDescription fields:
376          */
377         IB_NODE_DESC_F,
378
379         /*
380          * Notice/Trap fields
381          */
382         IB_NOTICE_IS_GENERIC_F,
383         IB_NOTICE_TYPE_F,
384         IB_NOTICE_PRODUCER_F,
385         IB_NOTICE_TRAP_NUMBER_F,
386         IB_NOTICE_ISSUER_LID_F,
387         IB_NOTICE_TOGGLE_F,
388         IB_NOTICE_COUNT_F,
389         IB_NOTICE_DATA_DETAILS_F,
390         IB_NOTICE_DATA_LID_F,
391         IB_NOTICE_DATA_144_LID_F,
392         IB_NOTICE_DATA_144_CAPMASK_F,
393
394         /*
395          * GS Performance
396          */
397         IB_PC_FIRST_F,
398         IB_PC_PORT_SELECT_F = IB_PC_FIRST_F,
399         IB_PC_COUNTER_SELECT_F,
400         IB_PC_ERR_SYM_F,
401         IB_PC_LINK_RECOVERS_F,
402         IB_PC_LINK_DOWNED_F,
403         IB_PC_ERR_RCV_F,
404         IB_PC_ERR_PHYSRCV_F,
405         IB_PC_ERR_SWITCH_REL_F,
406         IB_PC_XMT_DISCARDS_F,
407         IB_PC_ERR_XMTCONSTR_F,
408         IB_PC_ERR_RCVCONSTR_F,
409         IB_PC_ERR_LOCALINTEG_F,
410         IB_PC_ERR_EXCESS_OVR_F,
411         IB_PC_VL15_DROPPED_F,
412         IB_PC_XMT_BYTES_F,
413         IB_PC_RCV_BYTES_F,
414         IB_PC_XMT_PKTS_F,
415         IB_PC_RCV_PKTS_F,
416         IB_PC_LAST_F,
417
418         /*
419          * SMInfo
420          */
421         IB_SMINFO_GUID_F,
422         IB_SMINFO_KEY_F,
423         IB_SMINFO_ACT_F,
424         IB_SMINFO_PRIO_F,
425         IB_SMINFO_STATE_F,
426
427         /*
428          * SA RMPP
429          */
430         IB_SA_RMPP_VERS_F,
431         IB_SA_RMPP_TYPE_F,
432         IB_SA_RMPP_RESP_F,
433         IB_SA_RMPP_FLAGS_F,
434         IB_SA_RMPP_STATUS_F,
435
436         /* data1 */
437         IB_SA_RMPP_D1_F,
438         IB_SA_RMPP_SEGNUM_F,
439         /* data2 */
440         IB_SA_RMPP_D2_F,
441         IB_SA_RMPP_LEN_F,               /* DATA: Payload len */
442         IB_SA_RMPP_NEWWIN_F,            /* ACK: new window last */
443
444         /*
445          * SA Multi Path rec
446          */
447         IB_SA_MP_NPATH_F,
448         IB_SA_MP_NSRC_F,
449         IB_SA_MP_NDEST_F,
450         IB_SA_MP_GID0_F,
451
452         /*
453          * SA Path rec
454          */
455         IB_SA_PR_DGID_F,
456         IB_SA_PR_SGID_F,
457         IB_SA_PR_DLID_F,
458         IB_SA_PR_SLID_F,
459         IB_SA_PR_NPATH_F,
460
461         /*
462          * MC Member rec
463          */
464         IB_SA_MCM_MGID_F,
465         IB_SA_MCM_PORTGID_F,
466         IB_SA_MCM_QKEY_F,
467         IB_SA_MCM_MLID_F,
468         IB_SA_MCM_SL_F,
469         IB_SA_MCM_MTU_F,
470         IB_SA_MCM_RATE_F,
471         IB_SA_MCM_TCLASS_F,
472         IB_SA_MCM_PKEY_F,
473         IB_SA_MCM_FLOW_LABEL_F,
474         IB_SA_MCM_JOIN_STATE_F,
475         IB_SA_MCM_PROXY_JOIN_F,
476
477         /*
478          * Service record
479          */
480         IB_SA_SR_ID_F,
481         IB_SA_SR_GID_F,
482         IB_SA_SR_PKEY_F,
483         IB_SA_SR_LEASE_F,
484         IB_SA_SR_KEY_F,
485         IB_SA_SR_NAME_F,
486         IB_SA_SR_DATA_F,
487
488         /*
489          * ATS SM record - within SA_SR_DATA
490          */
491         IB_ATS_SM_NODE_ADDR_F,
492         IB_ATS_SM_MAGIC_KEY_F,
493         IB_ATS_SM_NODE_TYPE_F,
494         IB_ATS_SM_NODE_NAME_F,
495
496         /*
497          * SLTOVL MAPPING TABLE
498          */
499         IB_SLTOVL_MAPPING_TABLE_F,
500
501         /*
502          * VL ARBITRATION TABLE
503          */
504         IB_VL_ARBITRATION_TABLE_F,
505
506         /*
507          * IB vendor class range 2
508          */
509         IB_VEND2_OUI_F,
510         IB_VEND2_DATA_F,
511
512         /*
513          * PortCountersExtended
514          */
515         IB_PC_EXT_FIRST_F,
516         IB_PC_EXT_PORT_SELECT_F = IB_PC_EXT_FIRST_F,
517         IB_PC_EXT_COUNTER_SELECT_F,
518         IB_PC_EXT_XMT_BYTES_F,
519         IB_PC_EXT_RCV_BYTES_F,
520         IB_PC_EXT_XMT_PKTS_F,
521         IB_PC_EXT_RCV_PKTS_F,
522         IB_PC_EXT_XMT_UPKTS_F,
523         IB_PC_EXT_RCV_UPKTS_F,
524         IB_PC_EXT_XMT_MPKTS_F,
525         IB_PC_EXT_RCV_MPKTS_F,
526         IB_PC_EXT_LAST_F,
527
528         /*
529          * GUIDInfo fields
530          */
531         IB_GUID_GUID0_F,
532
533         IB_FIELD_LAST_  /* must be last */
534 };
535
536 /*
537  * SA RMPP section
538  */
539 enum RMPP_TYPE_ENUM {
540         IB_RMPP_TYPE_NONE,
541         IB_RMPP_TYPE_DATA,
542         IB_RMPP_TYPE_ACK,
543         IB_RMPP_TYPE_STOP,
544         IB_RMPP_TYPE_ABORT,
545 };
546
547 enum RMPP_FLAGS_ENUM {
548         IB_RMPP_FLAG_ACTIVE = 1 << 0,
549         IB_RMPP_FLAG_FIRST = 1 << 1,
550         IB_RMPP_FLAG_LAST = 1 << 2,
551 };
552
553 typedef struct {
554         int type;
555         int flags;
556         int status;
557         union {
558                 uint32_t u;
559                 uint32_t segnum;
560         } d1;
561         union {
562                 uint32_t u;
563                 uint32_t len;
564                 uint32_t newwin;
565         } d2;
566 } ib_rmpp_hdr_t;
567
568 enum SA_SIZES_ENUM {
569         SA_HEADER_SZ = 20,
570 };
571
572 typedef struct ib_sa_call {
573         unsigned attrid;
574         unsigned mod;
575         uint64_t mask;
576         unsigned method;
577
578         uint64_t trid;  /* used for out mad if nonzero, return real val */
579         unsigned recsz; /* return field */
580         ib_rmpp_hdr_t rmpp;
581 } ib_sa_call_t;
582
583 typedef struct ib_vendor_call {
584         unsigned method;
585         unsigned mgmt_class;
586         unsigned attrid;
587         unsigned mod;
588         uint32_t oui;
589         unsigned timeout;
590         ib_rmpp_hdr_t rmpp;
591 } ib_vendor_call_t;
592
593 #define IB_MIN_UCAST_LID        1
594 #define IB_MAX_UCAST_LID        (0xc000-1)
595 #define IB_MIN_MCAST_LID        0xc000
596 #define IB_MAX_MCAST_LID        (0xffff-1)
597
598 #define IB_LID_VALID(lid)       ((lid) >= IB_MIN_UCAST_LID && lid <= IB_MAX_UCAST_LID)
599 #define IB_MLID_VALID(lid)      ((lid) >= IB_MIN_MCAST_LID && lid <= IB_MAX_MCAST_LID)
600
601 #define MAD_DEF_RETRIES         3
602 #define MAD_DEF_TIMEOUT_MS      1000
603
604 enum {
605         IB_DEST_LID,
606         IB_DEST_DRPATH,
607         IB_DEST_GUID,
608         IB_DEST_DRSLID,
609 };
610
611 enum {
612         IB_NODE_CA = 1,
613         IB_NODE_SWITCH,
614         IB_NODE_ROUTER,
615         NODE_RNIC,
616
617         IB_NODE_MAX = NODE_RNIC
618 };
619
620 /******************************************************************************/
621
622 /* portid.c */
623 char *  portid2str(ib_portid_t *portid);
624 int     portid2portnum(ib_portid_t *portid);
625 int     str2drpath(ib_dr_path_t *path, char *routepath, int drslid, int drdlid);
626 char *  drpath2str(ib_dr_path_t *path, char *dstr, size_t dstr_size);
627
628 static inline int
629 ib_portid_set(ib_portid_t *portid, int lid, int qp, int qkey)
630 {
631         portid->lid = lid;
632         portid->qp = qp;
633         portid->qkey = qkey;
634         portid->grh_present = 0;
635
636         return 0;
637 }
638
639 /* fields.c */
640 extern ib_field_t ib_mad_f[];
641
642 void    _set_field(void *buf, int base_offs, ib_field_t *f, uint32_t val);
643 uint32_t _get_field(void *buf, int base_offs, ib_field_t *f);
644 void    _set_array(void *buf, int base_offs, ib_field_t *f, void *val);
645 void    _get_array(void *buf, int base_offs, ib_field_t *f, void *val);
646 void    _set_field64(void *buf, int base_offs, ib_field_t *f, uint64_t val);
647 uint64_t _get_field64(void *buf, int base_offs, ib_field_t *f);
648
649 /* mad.c */
650 static inline uint32_t
651 mad_get_field(void *buf, int base_offs, int field)
652 {
653         return _get_field(buf, base_offs, ib_mad_f + field);
654 }
655
656 static inline void
657 mad_set_field(void *buf, int base_offs, int field, uint32_t val)
658 {
659         _set_field(buf, base_offs, ib_mad_f + field, val);
660 }
661
662 /* field must be byte aligned */
663 static inline uint64_t
664 mad_get_field64(void *buf, int base_offs, int field)
665 {
666         return _get_field64(buf, base_offs, ib_mad_f + field);
667 }
668
669 static inline void
670 mad_set_field64(void *buf, int base_offs, int field, uint64_t val)
671 {
672         _set_field64(buf, base_offs, ib_mad_f + field, val);
673 }
674
675 static inline void
676 mad_set_array(void *buf, int base_offs, int field, void *val)
677 {
678         _set_array(buf, base_offs, ib_mad_f + field, val);
679 }
680
681 static inline void
682 mad_get_array(void *buf, int base_offs, int field, void *val)
683 {
684         _get_array(buf, base_offs, ib_mad_f + field, val);
685 }
686
687 void    mad_decode_field(uint8_t *buf, int field, void *val);
688 void    mad_encode_field(uint8_t *buf, int field, void *val);
689 void *  mad_encode(void *buf, ib_rpc_t *rpc, ib_dr_path_t *drpath, void *data);
690 uint64_t mad_trid(void);
691 int     mad_build_pkt(void *umad, ib_rpc_t *rpc, ib_portid_t *dport, ib_rmpp_hdr_t *rmpp, void *data);
692
693 /* register.c */
694 int     mad_register_port_client(int port_id, int mgmt, uint8_t rmpp_version);
695 int     mad_register_client(int mgmt, uint8_t rmpp_version);
696 int     mad_register_server(int mgmt, uint8_t rmpp_version,
697                             long method_mask[16/sizeof(long)],
698                             uint32_t class_oui);
699 int     mad_class_agent(int mgmt);
700 int     mad_agent_class(int agent);
701
702 /* serv.c */
703 int     mad_send(ib_rpc_t *rpc, ib_portid_t *dport, ib_rmpp_hdr_t *rmpp,
704                  void *data);
705 void *  mad_receive(void *umad, int timeout);
706 int     mad_respond(void *umad, ib_portid_t *portid, uint32_t rstatus);
707 void *  mad_alloc(void);
708 void    mad_free(void *umad);
709
710 /* vendor.c */
711 uint8_t *ib_vendor_call(void *data, ib_portid_t *portid,
712                         ib_vendor_call_t *call);
713
714 static inline int
715 mad_is_vendor_range1(int mgmt)
716 {
717         return mgmt >= 0x9 && mgmt <= 0xf;
718 }
719
720 static inline int
721 mad_is_vendor_range2(int mgmt)
722 {
723         return mgmt >= 0x30 && mgmt <= 0x4f;
724 }
725
726 /* rpc.c */
727 int     madrpc_portid(void);
728 int     madrpc_set_retries(int retries);
729 int     madrpc_set_timeout(int timeout);
730 void *  madrpc(ib_rpc_t *rpc, ib_portid_t *dport, void *payload, void *rcvdata);
731 void *  madrpc_rmpp(ib_rpc_t *rpc, ib_portid_t *dport, ib_rmpp_hdr_t *rmpp,
732                     void *data);
733 void    madrpc_init(char *dev_name, int dev_port, int *mgmt_classes,
734                     int num_classes);
735 void    madrpc_save_mad(void *madbuf, int len);
736 void    madrpc_lock(void);
737 void    madrpc_unlock(void);
738 void    madrpc_show_errors(int set);
739
740 void *  mad_rpc_open_port(char *dev_name, int dev_port, int *mgmt_classes,
741                           int num_classes);
742 void    mad_rpc_close_port(void *ibmad_port);
743 void *  mad_rpc(const void *ibmad_port, ib_rpc_t *rpc, ib_portid_t *dport,
744                 void *payload, void *rcvdata);
745 void *  mad_rpc_rmpp(const void *ibmad_port, ib_rpc_t *rpc, ib_portid_t *dport,
746                      ib_rmpp_hdr_t *rmpp, void *data);
747
748 /* smp.c */
749 uint8_t * smp_query(void *buf, ib_portid_t *id, unsigned attrid, unsigned mod,
750                     unsigned timeout);
751 uint8_t * smp_set(void *buf, ib_portid_t *id, unsigned attrid, unsigned mod,
752                   unsigned timeout);
753 uint8_t * smp_query_via(void *buf, ib_portid_t *id, unsigned attrid,
754                         unsigned mod, unsigned timeout, const void *srcport);
755 uint8_t * smp_set_via(void *buf, ib_portid_t *id, unsigned attrid, unsigned mod,
756                       unsigned timeout, const void *srcport);
757
758 inline static uint8_t *
759 safe_smp_query(void *rcvbuf, ib_portid_t *portid, unsigned attrid, unsigned mod,
760                unsigned timeout)
761 {
762         uint8_t *p;
763
764         madrpc_lock();
765         p = smp_query(rcvbuf, portid, attrid, mod, timeout);
766         madrpc_unlock();
767
768         return p;
769 }
770
771 inline static uint8_t *
772 safe_smp_set(void *rcvbuf, ib_portid_t *portid, unsigned attrid, unsigned mod,
773              unsigned timeout)
774 {
775         uint8_t *p;
776
777         madrpc_lock();
778         p = smp_set(rcvbuf, portid, attrid, mod, timeout);
779         madrpc_unlock();
780
781         return p;
782 }
783
784 /* sa.c */
785 uint8_t * sa_call(void *rcvbuf, ib_portid_t *portid, ib_sa_call_t *sa,
786                   unsigned timeout);
787 uint8_t * sa_rpc_call(const void *ibmad_port, void *rcvbuf, ib_portid_t *portid,
788                       ib_sa_call_t *sa, unsigned timeout);
789 int     ib_path_query(ibmad_gid_t srcgid, ibmad_gid_t destgid, ib_portid_t *sm_id,
790                       void *buf);       /* returns lid */
791 int     ib_path_query_via(const void *srcport, ibmad_gid_t srcgid,
792                           ibmad_gid_t destgid, ib_portid_t *sm_id, void *buf);
793
794 inline static uint8_t *
795 safe_sa_call(void *rcvbuf, ib_portid_t *portid, ib_sa_call_t *sa,
796              unsigned timeout)
797 {
798         uint8_t *p;
799
800         madrpc_lock();
801         p = sa_call(rcvbuf, portid, sa, timeout);
802         madrpc_unlock();
803
804         return p;
805 }
806
807 /* resolve.c */
808 int     ib_resolve_smlid(ib_portid_t *sm_id, int timeout);
809 int     ib_resolve_guid(ib_portid_t *portid, uint64_t *guid,
810                         ib_portid_t *sm_id, int timeout);
811 int     ib_resolve_portid_str(ib_portid_t *portid, char *addr_str,
812                               int dest_type, ib_portid_t *sm_id);
813 int     ib_resolve_self(ib_portid_t *portid, int *portnum, ibmad_gid_t *gid);
814
815 int     ib_resolve_smlid_via(ib_portid_t *sm_id, int timeout,
816                              const void *srcport);
817 int     ib_resolve_guid_via(ib_portid_t *portid, uint64_t *guid,
818                             ib_portid_t *sm_id, int timeout,
819                             const void *srcport);
820 int     ib_resolve_portid_str_via(ib_portid_t *portid, char *addr_str,
821                                   int dest_type, ib_portid_t *sm_id,
822                                   const void *srcport);
823 int     ib_resolve_self_via(ib_portid_t *portid, int *portnum, ibmad_gid_t *gid,
824                             const void *srcport);
825
826 /* gs.c */
827 uint8_t *perf_classportinfo_query(void *rcvbuf, ib_portid_t *dest, int port,
828                                   unsigned timeout);
829 uint8_t *port_performance_query(void *rcvbuf, ib_portid_t *dest, int port,
830                                 unsigned timeout);
831 uint8_t *port_performance_reset(void *rcvbuf, ib_portid_t *dest, int port,
832                                 unsigned mask, unsigned timeout);
833 uint8_t *port_performance_ext_query(void *rcvbuf, ib_portid_t *dest, int port,
834                                     unsigned timeout);
835 uint8_t *port_performance_ext_reset(void *rcvbuf, ib_portid_t *dest, int port,
836                                     unsigned mask, unsigned timeout);
837 uint8_t *port_samples_control_query(void *rcvbuf, ib_portid_t *dest, int port,
838                                     unsigned timeout);
839 uint8_t *port_samples_result_query(void *rcvbuf, ib_portid_t *dest, int port,
840                                    unsigned timeout);
841
842 uint8_t *perf_classportinfo_query_via(void *rcvbuf, ib_portid_t *dest, int port,
843                                   unsigned timeout, const void *srcport);
844 uint8_t *port_performance_query_via(void *rcvbuf, ib_portid_t *dest, int port,
845                                 unsigned timeout, const void *srcport);
846 uint8_t *port_performance_reset_via(void *rcvbuf, ib_portid_t *dest, int port,
847                                 unsigned mask, unsigned timeout, const void *srcport);
848 uint8_t *port_performance_ext_query_via(void *rcvbuf, ib_portid_t *dest, int port,
849                                     unsigned timeout, const void *srcport);
850 uint8_t *port_performance_ext_reset_via(void *rcvbuf, ib_portid_t *dest, int port,
851                                     unsigned mask, unsigned timeout, const void *srcport);
852 uint8_t *port_samples_control_query_via(void *rcvbuf, ib_portid_t *dest, int port,
853                                     unsigned timeout, const void *srcport);
854 uint8_t *port_samples_result_query_via(void *rcvbuf, ib_portid_t *dest, int port,
855                                    unsigned timeout, const void *srcport);
856 /* dump.c */
857 ib_mad_dump_fn
858         mad_dump_int, mad_dump_uint, mad_dump_hex, mad_dump_rhex,
859         mad_dump_bitfield, mad_dump_array, mad_dump_string,
860         mad_dump_linkwidth, mad_dump_linkwidthsup, mad_dump_linkwidthen,
861         mad_dump_linkdowndefstate,
862         mad_dump_linkspeed, mad_dump_linkspeedsup, mad_dump_linkspeeden,
863         mad_dump_portstate, mad_dump_portstates,
864         mad_dump_physportstate, mad_dump_portcapmask,
865         mad_dump_mtu, mad_dump_vlcap, mad_dump_opervls,
866         mad_dump_node_type,
867         mad_dump_sltovl, mad_dump_vlarbitration,
868         mad_dump_nodedesc, mad_dump_nodeinfo, mad_dump_portinfo, mad_dump_switchinfo,
869         mad_dump_perfcounters, mad_dump_perfcounters_ext;
870
871 int     _mad_dump(ib_mad_dump_fn *fn, char *name, void *val, int valsz);
872 char *  _mad_dump_field(ib_field_t *f, char *name, char *buf, int bufsz,
873                         void *val);
874 int     _mad_print_field(ib_field_t *f, char *name, void *val, int valsz);
875 char *  _mad_dump_val(ib_field_t *f, char *buf, int bufsz, void *val);
876
877 static inline int
878 mad_print_field(int field, char *name, void *val)
879 {
880         if (field <= IB_NO_FIELD || field >= IB_FIELD_LAST_)
881                 return -1;
882         return _mad_print_field(ib_mad_f + field, name, val, 0);
883 }
884
885 static inline char *
886 mad_dump_field(int field, char *buf, int bufsz, void *val)
887 {
888         if (field <= IB_NO_FIELD || field >= IB_FIELD_LAST_)
889                 return 0;
890         return _mad_dump_field(ib_mad_f + field, 0, buf, bufsz, val);
891 }
892
893 static inline char *
894 mad_dump_val(int field, char *buf, int bufsz, void *val)
895 {
896         if (field <= IB_NO_FIELD || field >= IB_FIELD_LAST_)
897                 return 0;
898         return _mad_dump_val(ib_mad_f + field, buf, bufsz, val);
899 }
900
901 extern int ibdebug;
902
903 END_C_DECLS
904
905 #endif /* _MAD_H_ */