-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvlib_sg_io.c
243 lines (195 loc) · 5.68 KB
/
vlib_sg_io.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
// SPDX-License-Identifier: EPL-1.0
/*
* Copyright IBM Corp. 2003,2010
*
* Authors: Sven Schuetz <[email protected]>
*
* File: vlib_sg_io.c
*
* Description:
* All functions performing sg_io related stuff.
*
*/
#include "vlib.h"
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <scsi/scsi.h>
#include <scsi/sg.h>
#include <linux/bsg.h>
#include <scsi/fc/fc_els.h>
#include <scsi/fc/fc_gs.h>
#include <scsi/fc/fc_ns.h>
#include <scsi/scsi_bsg_fc.h>
struct gid_pn_req_frame {
struct fc_ct_hdr hdr;
struct fc_ns_gid_pn gid_pn_req;
};
struct gid_pn_rsp_frame {
struct fc_ct_hdr hdr;
struct fc_gid_pn_resp gid_pn_rsp;
};
static int sg_io_performSGIO(char *devName, struct sg_io_v4 *sg_io)
{
int fd;
int status;
int i;
fd = open(devName, O_RDWR);
if (fd < 0)
return fd;
status = ioctl(fd, SG_IO, sg_io);
if (status < 0)
return status;
status = close(fd);
if (status < 0)
return status;
return 0;
}
HBA_STATUS sg_io_performCTPassThru(struct vlib_adapter *adapter,
void* req, int reqSize, void* rsp, int rspSize)
{
char devName[PATH_MAX];
struct fc_bsg_request cdb;
struct sg_io_v4 sg_io;
bzero(&cdb, sizeof(cdb));
bzero(&sg_io, sizeof(sg_io));
snprintf(devName, PATH_MAX, "/dev/bsg/fc_host%d", adapter->ident.host);
cdb.msgcode = FC_BSG_HST_CT;
memcpy(&cdb.rqst_data.r_ct, req, sizeof(struct fc_bsg_rport_ct));
/* copy the preamble into the
request header for the LLD */
sg_io.guard = 'Q';
sg_io.protocol = BSG_PROTOCOL_SCSI;
sg_io.subprotocol = BSG_SUB_PROTOCOL_SCSI_TRANSPORT;
sg_io.request_len = sizeof(cdb);
sg_io.request = (__u64) &cdb;
sg_io.dout_xfer_len = reqSize;
sg_io.dout_xferp = (__u64) req;
sg_io.din_xfer_len = rspSize;
sg_io.din_xferp = (__u64) rsp;
sg_io.timeout = 9000; /* TODO */
if (sg_io_performSGIO(devName, &sg_io))
return HBA_STATUS_ERROR;
return HBA_STATUS_OK;
}
static HBA_STATUS sg_io_performGIDPN(struct vlib_adapter *adapter,
wwn_t portwwn, void *rsp)
{
char devName[PATH_MAX];
struct fc_bsg_request cdb;
struct gid_pn_req_frame ct;
struct sg_io_v4 sg_io;
snprintf(devName, PATH_MAX, "/dev/bsg/fc_host%d", adapter->ident.host);
memset(&ct, 0, sizeof(struct gid_pn_req_frame));
ct.hdr.ct_rev = 1;
ct.hdr.ct_fs_type = 0xFC;
ct.hdr.ct_fs_subtype = 0x02;
ct.hdr.ct_cmd = 0x0121; /* gid_pn = 0x0112 */
ct.hdr.ct_mr_size = 0x1; /* response should be one word */
memcpy(&ct.gid_pn_req.fn_wwpn, &portwwn, sizeof(wwn_t));
cdb.msgcode = FC_BSG_HST_CT;
memcpy(&cdb.rqst_data.r_ct, &ct, sizeof(struct fc_bsg_rport_ct));
/* copy the preamble into the
request header for the LLD */
sg_io.guard = 'Q';
sg_io.protocol = BSG_PROTOCOL_SCSI;
sg_io.subprotocol = BSG_SUB_PROTOCOL_SCSI_TRANSPORT;
sg_io.request_len = sizeof(cdb);
sg_io.request = (__u64) &cdb;
sg_io.dout_xfer_len = sizeof(ct);
sg_io.dout_xferp = (__u64) &ct;
sg_io.din_xfer_len = CT_GIDPN_RESPONSE_LENGTH;
sg_io.din_xferp = (__u64) rsp;
sg_io.timeout = 2000; /* TODO */
if (sg_io_performSGIO(devName, &sg_io))
return HBA_STATUS_ERROR;
return HBA_STATUS_OK;
}
static fc_id_t getDidFromWWN(struct vlib_adapter *adapter, wwn_t portwwn)
{
struct gid_pn_rsp_frame rsp;
fc_id_t d_id;
if (sg_io_performGIDPN(adapter, portwwn, &rsp))
;
if (rsp.hdr.ct_cmd == 0x8002) {
/* accept CT */
/* convert from u8[3] to 32bit number*/
return *((fc_id_t*)&rsp.gid_pn_rsp.fp_fid);
}
/* all other cases including reject ct */
return 0;
}
HBA_STATUS sg_io_sendRNID(struct vlib_adapter *adapter, wwn_t portwwn,
void *rsp, int rspSize)
{
char devName[PATH_MAX];
struct fc_bsg_request cdb;
struct fc_els_rnid rnid;
struct sg_io_v4 sg_io;
fc_id_t d_id;
int i;
d_id = getDidFromWWN(adapter, portwwn);
if (d_id == 0)
return HBA_STATUS_ERROR;
memset(&rnid, 0, sizeof(struct fc_els_rnid));
memset(&cdb, 0, sizeof(struct fc_bsg_request));
rnid.rnid_cmd = ELS_RNID;
rnid.rnid_fmt = ELS_RNIDF_GEN;
cdb.msgcode = FC_BSG_HST_ELS_NOLOGIN;
cdb.rqst_data.h_els.command_code = 0x78;
memcpy(cdb.rqst_data.h_els.port_id, (char *)&d_id,
sizeof(cdb.rqst_data.h_els.port_id));
sg_io.guard = 'Q';
sg_io.protocol = BSG_PROTOCOL_SCSI;
sg_io.subprotocol = BSG_SUB_PROTOCOL_SCSI_TRANSPORT;
sg_io.request_len = sizeof(cdb);
sg_io.request = (__u64) &cdb;
sg_io.dout_xfer_len = sizeof(struct fc_els_rnid);
sg_io.dout_xferp = (__u64) &rnid;
sg_io.din_xfer_len = rspSize; /* common node-identification data + 4 */
sg_io.din_xferp = (__u64) rsp;
sg_io.timeout = 5000;
sprintf(devName, "/dev/bsg/fc_host%d", adapter->ident.host);
memset(rsp, 0, rspSize);
if (sg_io_performSGIO(devName, &sg_io))
return HBA_STATUS_ERROR;
return HBA_STATUS_OK;
}
#if 0
static void prepareRPS(wwn_t *port_selection, char *flag, fc_id_t *d_id,
wwn_t agent_wwn, HBA_UINT32 agent_domain,
wwn_t object_wwn, HBA_UINT32 object_port_number)
{
if (agent_wwn)
/* there is a target port */
*d_id = getDidFromWWN(adapter, agent_wwn);
else
/* no target port, so we pick the domain controller */
*d_id = 0xFFFC00 | agent_domain;
if (object_wwn) {
/* the port in question is identified by a wwpn */
*flag = 0x02;
*port_selection = object_wwn;
} else {
/* the port in question is identified by a physical port no */
*flag = 0x01;
*port_selection = object_port_number;
}
}
#endif
/*HBA_STATUS sg_io_sendRPS(struct vlib_adapter *adapter,
wwn_t agent_wwn, HBA_UINT32 agent_domain,
wwn_t object_wwn, HBA_UINT32 object_port_number,
void *pRspBuffer, HBA_UINT32 *pRspBufferSize)
{
fc_id_t d_id;
wwn_t port_selection;
char flag;
prepareRPS(&port_selection, &flag, &d_id, agent_wwn, agent_domain,
object_wwn, object_port_number);
}*/