2 * Copyright (c) 2008 Lawrence Livermore National Security
3 * Copyright (c) 2008-2009 Voltaire Inc. All rights reserved.
4 * Copyright (c) 2009 HNR Consulting. All rights reserved.
5 * Copyright (c) 2011 Mellanox Technologies LTD. All rights reserved.
7 * Produced at Lawrence Livermore National Laboratory.
8 * Written by Ira Weiny <weiny2@llnl.gov>.
10 * This software is available to you under a choice of one of two
11 * licenses. You may choose to be licensed under the terms of the GNU
12 * General Public License (GPL) Version 2, available from the file
13 * COPYING in the main directory of this source tree, or the
14 * OpenIB.org BSD license below:
16 * Redistribution and use in source and binary forms, with or
17 * without modification, are permitted provided that the following
20 * - Redistributions of source code must retain the above
21 * copyright notice, this list of conditions and the following
24 * - Redistributions in binary form must reproduce the above
25 * copyright notice, this list of conditions and the following
26 * disclaimer in the documentation and/or other materials
27 * provided with the distribution.
29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
33 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
34 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
35 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
48 #include <infiniband/mad.h>
49 #include <iba/ib_types.h>
51 #include "ibdiag_common.h"
53 struct ibmad_port *srcport;
54 /* for local link integrity */
57 static uint16_t get_node_type(ib_portid_t * port)
59 uint16_t node_type = IB_NODE_TYPE_CA;
60 uint8_t data[IB_SMP_DATA_SIZE] = { 0 };
62 if (smp_query_via(data, port, IB_ATTR_NODE_INFO, 0, 0, srcport))
63 node_type = (uint16_t) mad_get_field(data, 0, IB_NODE_TYPE_F);
67 static uint32_t get_cap_mask(ib_portid_t * port)
69 uint8_t data[IB_SMP_DATA_SIZE] = { 0 };
70 uint32_t cap_mask = 0;
72 if (smp_query_via(data, port, IB_ATTR_PORT_INFO, 0, 0, srcport))
73 cap_mask = (uint32_t) mad_get_field(data, 0, IB_PORT_CAPMASK_F);
77 static void build_trap145(ib_mad_notice_attr_t * n, ib_portid_t * port)
79 n->generic_type = 0x80 | IB_NOTICE_TYPE_INFO;
80 n->g_or_v.generic.prod_type_lsb = cl_hton16(get_node_type(port));
81 n->g_or_v.generic.trap_num = cl_hton16(145);
82 n->issuer_lid = cl_hton16((uint16_t) port->lid);
83 n->data_details.ntc_145.new_sys_guid = cl_hton64(0x1234567812345678);
86 static void build_trap144_local(ib_mad_notice_attr_t * n, ib_portid_t * port)
88 n->generic_type = 0x80 | IB_NOTICE_TYPE_INFO;
89 n->g_or_v.generic.prod_type_lsb = cl_hton16(get_node_type(port));
90 n->g_or_v.generic.trap_num = cl_hton16(144);
91 n->issuer_lid = cl_hton16((uint16_t) port->lid);
92 n->data_details.ntc_144.lid = n->issuer_lid;
93 n->data_details.ntc_144.new_cap_mask = cl_hton32(get_cap_mask(port));
94 n->data_details.ntc_144.local_changes =
95 TRAP_144_MASK_OTHER_LOCAL_CHANGES;
98 static void build_trap144_nodedesc(ib_mad_notice_attr_t * n, ib_portid_t * port)
100 build_trap144_local(n, port);
101 n->data_details.ntc_144.change_flgs =
102 TRAP_144_MASK_NODE_DESCRIPTION_CHANGE;
105 static void build_trap144_linkspeed(ib_mad_notice_attr_t * n,
108 build_trap144_local(n, port);
109 n->data_details.ntc_144.change_flgs =
110 TRAP_144_MASK_LINK_SPEED_ENABLE_CHANGE;
113 static void build_trap129(ib_mad_notice_attr_t * n, ib_portid_t * port)
115 n->generic_type = 0x80 | IB_NOTICE_TYPE_URGENT;
116 n->g_or_v.generic.prod_type_lsb = cl_hton16(get_node_type(port));
117 n->g_or_v.generic.trap_num = cl_hton16(129);
118 n->issuer_lid = cl_hton16((uint16_t) port->lid);
119 n->data_details.ntc_129_131.lid = n->issuer_lid;
120 n->data_details.ntc_129_131.pad = 0;
121 n->data_details.ntc_129_131.port_num = (uint8_t) error_port;
124 static void build_trap256_local(ib_mad_notice_attr_t * n, ib_portid_t * port)
126 n->generic_type = 0x80 | IB_NOTICE_TYPE_SECURITY;
127 n->g_or_v.generic.prod_type_lsb = cl_hton16(get_node_type(port));
128 n->g_or_v.generic.trap_num = cl_hton16(256);
129 n->issuer_lid = cl_hton16((uint16_t) port->lid);
130 n->data_details.ntc_256.lid = n->issuer_lid;
131 n->data_details.ntc_256.dr_slid = 0xffff;
132 n->data_details.ntc_256.method = 1;
133 n->data_details.ntc_256.attr_id = cl_ntoh16(0x15);
134 n->data_details.ntc_256.attr_mod = cl_ntoh32(0x12);
135 n->data_details.ntc_256.mkey = cl_ntoh64(0x1234567812345678);
138 static void build_trap256_lid(ib_mad_notice_attr_t * n, ib_portid_t * port)
140 build_trap256_local(n, port);
141 n->data_details.ntc_256.dr_trunc_hop = 0;
144 static void build_trap256_dr(ib_mad_notice_attr_t * n, ib_portid_t * port)
146 build_trap256_local(n, port);
147 n->data_details.ntc_256.dr_trunc_hop = 0x80 | 0x4;
148 n->data_details.ntc_256.dr_rtn_path[0] = 5;
149 n->data_details.ntc_256.dr_rtn_path[1] = 6;
150 n->data_details.ntc_256.dr_rtn_path[2] = 7;
151 n->data_details.ntc_256.dr_rtn_path[3] = 8;
154 static void build_trap257_258(ib_mad_notice_attr_t * n, ib_portid_t * port,
157 n->generic_type = 0x80 | IB_NOTICE_TYPE_SECURITY;
158 n->g_or_v.generic.prod_type_lsb = cl_hton16(get_node_type(port));
159 n->g_or_v.generic.trap_num = cl_hton16(trap_num);
160 n->issuer_lid = cl_hton16((uint16_t) port->lid);
161 n->data_details.ntc_257_258.lid1 = cl_hton16(1);
162 n->data_details.ntc_257_258.lid2 = cl_hton16(2);
163 n->data_details.ntc_257_258.key = cl_hton32(0x12345678);
164 n->data_details.ntc_257_258.qp1 = cl_hton32(0x010101);
165 n->data_details.ntc_257_258.qp2 = cl_hton32(0x020202);
166 n->data_details.ntc_257_258.gid1.unicast.prefix = cl_ntoh64(0xf8c0000000000001);
167 n->data_details.ntc_257_258.gid1.unicast.interface_id = cl_ntoh64(0x1111222233334444);
168 n->data_details.ntc_257_258.gid2.unicast.prefix = cl_ntoh64(0xf8c0000000000001);
169 n->data_details.ntc_257_258.gid2.unicast.interface_id = cl_ntoh64(0x5678567812341234);
172 static void build_trap257(ib_mad_notice_attr_t * n, ib_portid_t * port)
174 build_trap257_258(n, port, 257);
177 static void build_trap258(ib_mad_notice_attr_t * n, ib_portid_t * port)
179 build_trap257_258(n, port, 258);
182 static int send_trap(void (*build) (ib_mad_notice_attr_t *, ib_portid_t *))
185 ib_portid_t selfportid;
188 ib_mad_notice_attr_t notice;
190 if (resolve_self(ibd_ca, ibd_ca_port, &selfportid, &selfport, NULL))
191 IBEXIT("can't resolve self");
193 if (resolve_sm_portid(ibd_ca, ibd_ca_port, &sm_port))
194 IBEXIT("can't resolve SM destination port");
196 memset(&trap_rpc, 0, sizeof(trap_rpc));
197 trap_rpc.mgtclass = IB_SMI_CLASS;
198 trap_rpc.method = IB_MAD_METHOD_TRAP;
199 trap_rpc.trid = mad_trid();
200 trap_rpc.attr.id = NOTICE;
201 trap_rpc.datasz = IB_SMP_DATA_SIZE;
202 trap_rpc.dataoffs = IB_SMP_DATA_OFFS;
204 memset(¬ice, 0, sizeof(notice));
205 build(¬ice, &selfportid);
207 return mad_send_via(&trap_rpc, &sm_port, NULL, ¬ice, srcport);
210 typedef struct _trap_def {
212 void (*build_func) (ib_mad_notice_attr_t *, ib_portid_t *);
215 static const trap_def_t traps[] = {
216 {"node_desc_change", build_trap144_nodedesc},
217 {"link_speed_enabled_change", build_trap144_linkspeed},
218 {"local_link_integrity", build_trap129},
219 {"sys_image_guid_change", build_trap145},
220 {"mkey_lid", build_trap256_lid},
221 {"mkey_dr", build_trap256_dr},
222 {"pkey", build_trap257},
223 {"qkey", build_trap258},
227 int process_send_trap(char *trap_name)
231 for (i = 0; traps[i].trap_name; i++)
232 if (strcmp(traps[i].trap_name, trap_name) == 0)
233 return send_trap(traps[i].build_func);
238 int main(int argc, char **argv)
240 char usage_args[1024];
241 int mgmt_classes[2] = { IB_SMI_CLASS, IB_SMI_DIRECT_CLASS };
242 char *trap_name = NULL;
245 n = sprintf(usage_args, "[<trap_name>] [<error_port>]\n"
246 "\nArgument <trap_name> can be one of the following:\n");
247 for (i = 0; traps[i].trap_name; i++) {
248 n += snprintf(usage_args + n, sizeof(usage_args) - n,
249 " %s\n", traps[i].trap_name);
250 if (n >= sizeof(usage_args))
253 snprintf(usage_args + n, sizeof(usage_args) - n,
254 "\n default behavior is to send \"%s\"", traps[0].trap_name);
256 ibdiag_process_opts(argc, argv, NULL, "DGKL", NULL, NULL,
262 trap_name = argv[0] ? argv[0] : traps[0].trap_name;
265 error_port = atoi(argv[1]);
267 madrpc_show_errors(1);
269 srcport = mad_rpc_open_port(ibd_ca, ibd_ca_port, mgmt_classes, 2);
271 IBEXIT("Failed to open '%s' port '%d'", ibd_ca, ibd_ca_port);
273 smp_mkey_set(srcport, ibd_mkey);
275 rc = process_send_trap(trap_name);
276 mad_rpc_close_port(srcport);