1*9684SSusan.Gleeson@Sun.COM /*
2*9684SSusan.Gleeson@Sun.COM * CDDL HEADER START
3*9684SSusan.Gleeson@Sun.COM *
4*9684SSusan.Gleeson@Sun.COM * The contents of this file are subject to the terms of the
5*9684SSusan.Gleeson@Sun.COM * Common Development and Distribution License (the "License").
6*9684SSusan.Gleeson@Sun.COM * You may not use this file except in compliance with the License.
7*9684SSusan.Gleeson@Sun.COM *
8*9684SSusan.Gleeson@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*9684SSusan.Gleeson@Sun.COM * or http://www.opensolaris.org/os/licensing.
10*9684SSusan.Gleeson@Sun.COM * See the License for the specific language governing permissions
11*9684SSusan.Gleeson@Sun.COM * and limitations under the License.
12*9684SSusan.Gleeson@Sun.COM *
13*9684SSusan.Gleeson@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each
14*9684SSusan.Gleeson@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*9684SSusan.Gleeson@Sun.COM * If applicable, add the following below this CDDL HEADER, with the
16*9684SSusan.Gleeson@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying
17*9684SSusan.Gleeson@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner]
18*9684SSusan.Gleeson@Sun.COM *
19*9684SSusan.Gleeson@Sun.COM * CDDL HEADER END
20*9684SSusan.Gleeson@Sun.COM */
21*9684SSusan.Gleeson@Sun.COM /*
22*9684SSusan.Gleeson@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23*9684SSusan.Gleeson@Sun.COM * Use is subject to license terms.
24*9684SSusan.Gleeson@Sun.COM */
25*9684SSusan.Gleeson@Sun.COM
26*9684SSusan.Gleeson@Sun.COM #include <sys/dditypes.h>
27*9684SSusan.Gleeson@Sun.COM #include <sys/mdb_modapi.h>
28*9684SSusan.Gleeson@Sun.COM #include <sys/modctl.h>
29*9684SSusan.Gleeson@Sun.COM #include <sys/sunddi.h>
30*9684SSusan.Gleeson@Sun.COM #include <sys/sysmacros.h>
31*9684SSusan.Gleeson@Sun.COM #include <sys/lpif.h>
32*9684SSusan.Gleeson@Sun.COM #include <srp.h>
33*9684SSusan.Gleeson@Sun.COM #include <srpt_impl.h>
34*9684SSusan.Gleeson@Sun.COM
35*9684SSusan.Gleeson@Sun.COM /*
36*9684SSusan.Gleeson@Sun.COM * byteswap macros since ntohl not available in kernel mdb
37*9684SSusan.Gleeson@Sun.COM */
38*9684SSusan.Gleeson@Sun.COM #if defined(_LITTLE_ENDIAN)
39*9684SSusan.Gleeson@Sun.COM #define SRPT_BSWAP_32(x) (((uint32_t)(x) << 24) | \
40*9684SSusan.Gleeson@Sun.COM (((uint32_t)(x) << 8) & 0xff0000) | \
41*9684SSusan.Gleeson@Sun.COM (((uint32_t)(x) >> 8) & 0xff00) | \
42*9684SSusan.Gleeson@Sun.COM ((uint32_t)(x) >> 24))
43*9684SSusan.Gleeson@Sun.COM #define SRPT_BSWAP_16(x) ((((x) & 0xff) << 8) | ((x) >> 8))
44*9684SSusan.Gleeson@Sun.COM #else
45*9684SSusan.Gleeson@Sun.COM #define SRPT_BSWAP_32(x) (x)
46*9684SSusan.Gleeson@Sun.COM #define SRPT_BSWAP_16(x) (x)
47*9684SSusan.Gleeson@Sun.COM #endif /* _LITTLE_ENDIAN */
48*9684SSusan.Gleeson@Sun.COM
49*9684SSusan.Gleeson@Sun.COM /*
50*9684SSusan.Gleeson@Sun.COM * Walker to list the addresses of all the active I/O Controllers
51*9684SSusan.Gleeson@Sun.COM */
52*9684SSusan.Gleeson@Sun.COM static int
srpt_ioc_walk_init(mdb_walk_state_t * wsp)53*9684SSusan.Gleeson@Sun.COM srpt_ioc_walk_init(mdb_walk_state_t *wsp)
54*9684SSusan.Gleeson@Sun.COM {
55*9684SSusan.Gleeson@Sun.COM srpt_ctxt_t *srpt;
56*9684SSusan.Gleeson@Sun.COM uintptr_t srpt_global_addr, list_addr;
57*9684SSusan.Gleeson@Sun.COM
58*9684SSusan.Gleeson@Sun.COM if (mdb_readvar(&srpt, "srpt_ctxt") == -1) {
59*9684SSusan.Gleeson@Sun.COM mdb_warn("failed to read srpt soft state");
60*9684SSusan.Gleeson@Sun.COM return (WALK_ERR);
61*9684SSusan.Gleeson@Sun.COM }
62*9684SSusan.Gleeson@Sun.COM
63*9684SSusan.Gleeson@Sun.COM srpt_global_addr = (uintptr_t)srpt;
64*9684SSusan.Gleeson@Sun.COM
65*9684SSusan.Gleeson@Sun.COM list_addr = srpt_global_addr + offsetof(srpt_ctxt_t, sc_ioc_list);
66*9684SSusan.Gleeson@Sun.COM
67*9684SSusan.Gleeson@Sun.COM wsp->walk_addr = list_addr;
68*9684SSusan.Gleeson@Sun.COM
69*9684SSusan.Gleeson@Sun.COM if (mdb_layered_walk("list", wsp) == -1) {
70*9684SSusan.Gleeson@Sun.COM mdb_warn("list walk failed");
71*9684SSusan.Gleeson@Sun.COM return (WALK_ERR);
72*9684SSusan.Gleeson@Sun.COM }
73*9684SSusan.Gleeson@Sun.COM return (WALK_NEXT);
74*9684SSusan.Gleeson@Sun.COM }
75*9684SSusan.Gleeson@Sun.COM
76*9684SSusan.Gleeson@Sun.COM static int
srpt_list_walk_step(mdb_walk_state_t * wsp)77*9684SSusan.Gleeson@Sun.COM srpt_list_walk_step(mdb_walk_state_t *wsp)
78*9684SSusan.Gleeson@Sun.COM {
79*9684SSusan.Gleeson@Sun.COM if (wsp->walk_addr == NULL) {
80*9684SSusan.Gleeson@Sun.COM return (WALK_DONE);
81*9684SSusan.Gleeson@Sun.COM }
82*9684SSusan.Gleeson@Sun.COM return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
83*9684SSusan.Gleeson@Sun.COM wsp->walk_cbdata));
84*9684SSusan.Gleeson@Sun.COM }
85*9684SSusan.Gleeson@Sun.COM
86*9684SSusan.Gleeson@Sun.COM /*
87*9684SSusan.Gleeson@Sun.COM * Walker to list the target services per I/O Controller. The I/O Controller is
88*9684SSusan.Gleeson@Sun.COM * provided as input.
89*9684SSusan.Gleeson@Sun.COM */
90*9684SSusan.Gleeson@Sun.COM static int
srpt_tgt_walk_init(mdb_walk_state_t * wsp)91*9684SSusan.Gleeson@Sun.COM srpt_tgt_walk_init(mdb_walk_state_t *wsp)
92*9684SSusan.Gleeson@Sun.COM {
93*9684SSusan.Gleeson@Sun.COM srpt_ioc_t srpt_ioc;
94*9684SSusan.Gleeson@Sun.COM
95*9684SSusan.Gleeson@Sun.COM /*
96*9684SSusan.Gleeson@Sun.COM * Input should be a srpt_ioc_t, read it to get the
97*9684SSusan.Gleeson@Sun.COM * srpt_target_port_t
98*9684SSusan.Gleeson@Sun.COM */
99*9684SSusan.Gleeson@Sun.COM if (wsp->walk_addr == NULL) {
100*9684SSusan.Gleeson@Sun.COM mdb_warn("<srpt_ioc_t addr>::walk srpt_target\n");
101*9684SSusan.Gleeson@Sun.COM return (WALK_ERR);
102*9684SSusan.Gleeson@Sun.COM }
103*9684SSusan.Gleeson@Sun.COM
104*9684SSusan.Gleeson@Sun.COM if (mdb_vread(&srpt_ioc, sizeof (srpt_ioc_t), wsp->walk_addr) == -1) {
105*9684SSusan.Gleeson@Sun.COM mdb_warn("failed to read in the srpt_ioc\n ");
106*9684SSusan.Gleeson@Sun.COM return (WALK_ERR);
107*9684SSusan.Gleeson@Sun.COM }
108*9684SSusan.Gleeson@Sun.COM
109*9684SSusan.Gleeson@Sun.COM wsp->walk_addr = (uintptr_t)srpt_ioc.ioc_tgt_port;
110*9684SSusan.Gleeson@Sun.COM wsp->walk_data = mdb_alloc(sizeof (srpt_target_port_t), UM_SLEEP);
111*9684SSusan.Gleeson@Sun.COM return (WALK_NEXT);
112*9684SSusan.Gleeson@Sun.COM }
113*9684SSusan.Gleeson@Sun.COM
114*9684SSusan.Gleeson@Sun.COM static int
srpt_tgt_walk_step(mdb_walk_state_t * wsp)115*9684SSusan.Gleeson@Sun.COM srpt_tgt_walk_step(mdb_walk_state_t *wsp)
116*9684SSusan.Gleeson@Sun.COM {
117*9684SSusan.Gleeson@Sun.COM if (wsp->walk_addr == NULL) {
118*9684SSusan.Gleeson@Sun.COM return (WALK_DONE);
119*9684SSusan.Gleeson@Sun.COM }
120*9684SSusan.Gleeson@Sun.COM
121*9684SSusan.Gleeson@Sun.COM (void) wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
122*9684SSusan.Gleeson@Sun.COM wsp->walk_cbdata);
123*9684SSusan.Gleeson@Sun.COM
124*9684SSusan.Gleeson@Sun.COM /* Currently there is only one target per IOC */
125*9684SSusan.Gleeson@Sun.COM return (WALK_DONE);
126*9684SSusan.Gleeson@Sun.COM
127*9684SSusan.Gleeson@Sun.COM }
128*9684SSusan.Gleeson@Sun.COM
129*9684SSusan.Gleeson@Sun.COM static void
srpt_tgt_walk_fini(mdb_walk_state_t * wsp)130*9684SSusan.Gleeson@Sun.COM srpt_tgt_walk_fini(mdb_walk_state_t *wsp)
131*9684SSusan.Gleeson@Sun.COM {
132*9684SSusan.Gleeson@Sun.COM mdb_free(wsp->walk_data, sizeof (srpt_target_port_t));
133*9684SSusan.Gleeson@Sun.COM }
134*9684SSusan.Gleeson@Sun.COM
135*9684SSusan.Gleeson@Sun.COM /*
136*9684SSusan.Gleeson@Sun.COM * Walker to list the channels per SRP target service. The target port is
137*9684SSusan.Gleeson@Sun.COM * provided as input.
138*9684SSusan.Gleeson@Sun.COM */
139*9684SSusan.Gleeson@Sun.COM static int
srpt_channel_walk_init(mdb_walk_state_t * wsp)140*9684SSusan.Gleeson@Sun.COM srpt_channel_walk_init(mdb_walk_state_t *wsp)
141*9684SSusan.Gleeson@Sun.COM {
142*9684SSusan.Gleeson@Sun.COM /*
143*9684SSusan.Gleeson@Sun.COM * Input should be a srpt_target_port_t, read it to get the
144*9684SSusan.Gleeson@Sun.COM * list of channels
145*9684SSusan.Gleeson@Sun.COM */
146*9684SSusan.Gleeson@Sun.COM if (wsp->walk_addr == NULL) {
147*9684SSusan.Gleeson@Sun.COM mdb_warn("<srpt_target_port_t addr>::walk srpt_channel\n");
148*9684SSusan.Gleeson@Sun.COM return (WALK_ERR);
149*9684SSusan.Gleeson@Sun.COM }
150*9684SSusan.Gleeson@Sun.COM
151*9684SSusan.Gleeson@Sun.COM wsp->walk_addr += offsetof(srpt_target_port_t, tp_ch_list);
152*9684SSusan.Gleeson@Sun.COM
153*9684SSusan.Gleeson@Sun.COM if (mdb_layered_walk("list", wsp) == -1) {
154*9684SSusan.Gleeson@Sun.COM mdb_warn("Could not walk tp_ch_list");
155*9684SSusan.Gleeson@Sun.COM return (WALK_ERR);
156*9684SSusan.Gleeson@Sun.COM }
157*9684SSusan.Gleeson@Sun.COM return (WALK_NEXT);
158*9684SSusan.Gleeson@Sun.COM }
159*9684SSusan.Gleeson@Sun.COM
160*9684SSusan.Gleeson@Sun.COM /*
161*9684SSusan.Gleeson@Sun.COM * Walker to list the SCSI sessions per target. The target is
162*9684SSusan.Gleeson@Sun.COM * provided as input.
163*9684SSusan.Gleeson@Sun.COM */
164*9684SSusan.Gleeson@Sun.COM static int
srpt_scsi_session_walk_init(mdb_walk_state_t * wsp)165*9684SSusan.Gleeson@Sun.COM srpt_scsi_session_walk_init(mdb_walk_state_t *wsp)
166*9684SSusan.Gleeson@Sun.COM {
167*9684SSusan.Gleeson@Sun.COM /*
168*9684SSusan.Gleeson@Sun.COM * Input should be a srpt_target_port_t, read it to get the
169*9684SSusan.Gleeson@Sun.COM * srpt_session_t
170*9684SSusan.Gleeson@Sun.COM */
171*9684SSusan.Gleeson@Sun.COM if (wsp->walk_addr == NULL) {
172*9684SSusan.Gleeson@Sun.COM mdb_warn("<srpt_target_port_t addr>::walk srpt_scsi_session\n");
173*9684SSusan.Gleeson@Sun.COM return (WALK_ERR);
174*9684SSusan.Gleeson@Sun.COM }
175*9684SSusan.Gleeson@Sun.COM
176*9684SSusan.Gleeson@Sun.COM wsp->walk_addr += offsetof(srpt_target_port_t, tp_sess_list);
177*9684SSusan.Gleeson@Sun.COM
178*9684SSusan.Gleeson@Sun.COM if (mdb_layered_walk("list", wsp) == -1) {
179*9684SSusan.Gleeson@Sun.COM mdb_warn("target session list walk failed");
180*9684SSusan.Gleeson@Sun.COM return (WALK_ERR);
181*9684SSusan.Gleeson@Sun.COM }
182*9684SSusan.Gleeson@Sun.COM return (WALK_NEXT);
183*9684SSusan.Gleeson@Sun.COM }
184*9684SSusan.Gleeson@Sun.COM
185*9684SSusan.Gleeson@Sun.COM /*
186*9684SSusan.Gleeson@Sun.COM * Walker to list the tasks in a session. The session is
187*9684SSusan.Gleeson@Sun.COM * provided as input.
188*9684SSusan.Gleeson@Sun.COM */
189*9684SSusan.Gleeson@Sun.COM static int
srpt_task_walk_init(mdb_walk_state_t * wsp)190*9684SSusan.Gleeson@Sun.COM srpt_task_walk_init(mdb_walk_state_t *wsp)
191*9684SSusan.Gleeson@Sun.COM {
192*9684SSusan.Gleeson@Sun.COM if (wsp->walk_addr == NULL) {
193*9684SSusan.Gleeson@Sun.COM mdb_warn("<srpt_session_t addr>::walk srpt_tasks\n");
194*9684SSusan.Gleeson@Sun.COM return (WALK_ERR);
195*9684SSusan.Gleeson@Sun.COM }
196*9684SSusan.Gleeson@Sun.COM
197*9684SSusan.Gleeson@Sun.COM wsp->walk_addr += offsetof(srpt_session_t, ss_task_list);
198*9684SSusan.Gleeson@Sun.COM
199*9684SSusan.Gleeson@Sun.COM if (mdb_layered_walk("list", wsp) == -1) {
200*9684SSusan.Gleeson@Sun.COM mdb_warn("session task list walk failed");
201*9684SSusan.Gleeson@Sun.COM return (WALK_ERR);
202*9684SSusan.Gleeson@Sun.COM }
203*9684SSusan.Gleeson@Sun.COM return (WALK_NEXT);
204*9684SSusan.Gleeson@Sun.COM }
205*9684SSusan.Gleeson@Sun.COM
206*9684SSusan.Gleeson@Sun.COM /* ARGSUSED */
207*9684SSusan.Gleeson@Sun.COM static int
srpt_print_ioc(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)208*9684SSusan.Gleeson@Sun.COM srpt_print_ioc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
209*9684SSusan.Gleeson@Sun.COM {
210*9684SSusan.Gleeson@Sun.COM srpt_ioc_t ioc;
211*9684SSusan.Gleeson@Sun.COM char mask[9];
212*9684SSusan.Gleeson@Sun.COM int i;
213*9684SSusan.Gleeson@Sun.COM
214*9684SSusan.Gleeson@Sun.COM if (addr == NULL) {
215*9684SSusan.Gleeson@Sun.COM mdb_warn("address of srpt_ioc should be specified\n");
216*9684SSusan.Gleeson@Sun.COM return (DCMD_ERR);
217*9684SSusan.Gleeson@Sun.COM }
218*9684SSusan.Gleeson@Sun.COM
219*9684SSusan.Gleeson@Sun.COM if (mdb_vread(&ioc, sizeof (srpt_ioc_t), addr) == -1) {
220*9684SSusan.Gleeson@Sun.COM mdb_warn("failed to read srpt_ioc at %p", addr);
221*9684SSusan.Gleeson@Sun.COM return (DCMD_ERR);
222*9684SSusan.Gleeson@Sun.COM }
223*9684SSusan.Gleeson@Sun.COM
224*9684SSusan.Gleeson@Sun.COM mdb_printf("IOC %p\n", addr);
225*9684SSusan.Gleeson@Sun.COM mdb_printf(" guid: %x\n", ioc.ioc_guid);
226*9684SSusan.Gleeson@Sun.COM mdb_printf(" target port: %p\n", ioc.ioc_tgt_port);
227*9684SSusan.Gleeson@Sun.COM mdb_printf(" srq handle: %p\n", ioc.ioc_srq_hdl);
228*9684SSusan.Gleeson@Sun.COM mdb_printf(" current srq size: %u\n", ioc.ioc_num_iu_entries);
229*9684SSusan.Gleeson@Sun.COM mdb_printf(" max srq size: %d\n", ioc.ioc_srq_attr.srq_wr_sz);
230*9684SSusan.Gleeson@Sun.COM mdb_printf(" iu pool: %p\n", ioc.ioc_iu_pool);
231*9684SSusan.Gleeson@Sun.COM mdb_printf(" profile send qdepth: %d\n",
232*9684SSusan.Gleeson@Sun.COM SRPT_BSWAP_16(ioc.ioc_profile.ioc_send_msg_qdepth));
233*9684SSusan.Gleeson@Sun.COM mdb_printf(" profile rmda read qdepth: %d\n",
234*9684SSusan.Gleeson@Sun.COM ioc.ioc_profile.ioc_rdma_read_qdepth);
235*9684SSusan.Gleeson@Sun.COM mdb_printf(" profile send msg size: %d\n",
236*9684SSusan.Gleeson@Sun.COM SRPT_BSWAP_32(ioc.ioc_profile.ioc_send_msg_sz));
237*9684SSusan.Gleeson@Sun.COM mdb_printf(" profile rmda xfer size: %d\n",
238*9684SSusan.Gleeson@Sun.COM SRPT_BSWAP_32(ioc.ioc_profile.ioc_rdma_xfer_sz));
239*9684SSusan.Gleeson@Sun.COM for (i = 0; i < 8; i++) {
240*9684SSusan.Gleeson@Sun.COM if (ioc.ioc_profile.ioc_ctrl_opcap_mask & 1<<i) {
241*9684SSusan.Gleeson@Sun.COM mask[i] = 'x';
242*9684SSusan.Gleeson@Sun.COM } else {
243*9684SSusan.Gleeson@Sun.COM mask[i] = '-';
244*9684SSusan.Gleeson@Sun.COM }
245*9684SSusan.Gleeson@Sun.COM }
246*9684SSusan.Gleeson@Sun.COM mask[i] = '\0';
247*9684SSusan.Gleeson@Sun.COM mdb_printf(" profile opcap mask: %s\n", mask);
248*9684SSusan.Gleeson@Sun.COM
249*9684SSusan.Gleeson@Sun.COM return (DCMD_OK);
250*9684SSusan.Gleeson@Sun.COM }
251*9684SSusan.Gleeson@Sun.COM
252*9684SSusan.Gleeson@Sun.COM static const mdb_dcmd_t dcmds[] = {
253*9684SSusan.Gleeson@Sun.COM { "srpt_print_ioc", ":", "Print information about an SRPT IOC",
254*9684SSusan.Gleeson@Sun.COM srpt_print_ioc, NULL},
255*9684SSusan.Gleeson@Sun.COM { NULL }
256*9684SSusan.Gleeson@Sun.COM };
257*9684SSusan.Gleeson@Sun.COM
258*9684SSusan.Gleeson@Sun.COM static const mdb_walker_t walkers[] = {
259*9684SSusan.Gleeson@Sun.COM { "srpt_ioc", "Walk active IO controllers",
260*9684SSusan.Gleeson@Sun.COM srpt_ioc_walk_init, srpt_list_walk_step, NULL},
261*9684SSusan.Gleeson@Sun.COM { "srpt_tgt", "Walk the targets",
262*9684SSusan.Gleeson@Sun.COM srpt_tgt_walk_init, srpt_tgt_walk_step, srpt_tgt_walk_fini},
263*9684SSusan.Gleeson@Sun.COM { "srpt_channel", "Walk the channels",
264*9684SSusan.Gleeson@Sun.COM srpt_channel_walk_init, srpt_list_walk_step, NULL},
265*9684SSusan.Gleeson@Sun.COM { "srpt_scsi_session", "Walk the scsi sessions",
266*9684SSusan.Gleeson@Sun.COM srpt_scsi_session_walk_init, srpt_list_walk_step, NULL},
267*9684SSusan.Gleeson@Sun.COM { "srpt_tasks", "Walk the tasks in a scsi session",
268*9684SSusan.Gleeson@Sun.COM srpt_task_walk_init, srpt_list_walk_step, NULL},
269*9684SSusan.Gleeson@Sun.COM { NULL }
270*9684SSusan.Gleeson@Sun.COM };
271*9684SSusan.Gleeson@Sun.COM
272*9684SSusan.Gleeson@Sun.COM static const mdb_modinfo_t modinfo = {
273*9684SSusan.Gleeson@Sun.COM MDB_API_VERSION, dcmds, walkers
274*9684SSusan.Gleeson@Sun.COM };
275*9684SSusan.Gleeson@Sun.COM
276*9684SSusan.Gleeson@Sun.COM const mdb_modinfo_t *
_mdb_init(void)277*9684SSusan.Gleeson@Sun.COM _mdb_init(void)
278*9684SSusan.Gleeson@Sun.COM {
279*9684SSusan.Gleeson@Sun.COM return (&modinfo);
280*9684SSusan.Gleeson@Sun.COM }
281