-
Notifications
You must be signed in to change notification settings - Fork 0
/
scsi.c
203 lines (174 loc) · 4.89 KB
/
scsi.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
/*
* Copyright (c) 2008, Intel Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU Lesser General Public License,
* version 2.1, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include "utils.h"
#include "api_lib.h"
#include "adapt_impl.h"
#include "bind_impl.h"
#include "fc_scsi.h"
/*
* Inquiry V1.
*/
HBA_STATUS
scsi_inquiry_v1(HBA_HANDLE handle, HBA_WWN disc_wwpn, HBA_UINT64 fc_lun,
HBA_UINT8 evpd, HBA_UINT32 page_code, void *resp,
HBA_UINT32 resp_len, void *sense, HBA_UINT32 sense_len)
{
struct port_info *pp;
char sg_name[50];
HBA_UINT8 stat;
HBA_STATUS status;
/*
* Find port.
*/
pp = adapter_get_port(handle, 0);
if (pp == NULL)
return HBA_STATUS_ERROR_INVALID_HANDLE;
if (get_binding_sg_name(
pp, disc_wwpn, fc_lun, sg_name, sizeof(sg_name)) != 0)
return HBA_STATUS_ERROR_TARGET_LUN;
status = sg_issue_inquiry(sg_name, evpd ? SCSI_INQF_EVPD : 0, page_code,
resp, &resp_len, &stat, sense, &sense_len);
if (status == HBA_STATUS_OK && stat == SCSI_ST_CHECK)
status = HBA_STATUS_SCSI_CHECK_CONDITION;
return status;
}
/*
* Inquiry V2.
*/
HBA_STATUS
scsi_inquiry_v2(HBA_HANDLE handle, HBA_WWN wwpn, HBA_WWN disc_wwpn,
HBA_UINT64 fc_lun, HBA_UINT8 cdb_byte1,
HBA_UINT8 cdb_byte2, void *resp, HBA_UINT32 *resp_lenp,
HBA_UINT8 *statp, void *sense, HBA_UINT32 *sense_lenp)
{
struct port_info *pp;
char sg_name[50];
/*
* Find port.
*/
pp = adapter_get_port_by_wwn(handle, wwpn, NULL);
if (pp == NULL)
return HBA_STATUS_ERROR_ILLEGAL_WWN;
if (get_binding_sg_name(
pp, disc_wwpn, fc_lun, sg_name, sizeof(sg_name)) != 0)
return HBA_STATUS_ERROR_TARGET_LUN;
return sg_issue_inquiry(sg_name, cdb_byte1, cdb_byte2,
resp, resp_lenp, statp, sense, sense_lenp);
}
/*
* Read capacity V1.
*/
HBA_STATUS
scsi_read_capacity_v1(HBA_HANDLE handle, HBA_WWN disc_wwpn,
HBA_UINT64 fc_lun, void *resp,
HBA_UINT32 resp_len, void *sense,
HBA_UINT32 sense_len)
{
struct port_info *pp;
char sg_name[50];
HBA_UINT8 stat;
HBA_STATUS status;
/*
* Find port.
*/
pp = adapter_get_port(handle, 0);
if (pp == NULL)
return HBA_STATUS_ERROR_INVALID_HANDLE;
if (get_binding_sg_name(
pp, disc_wwpn, fc_lun, sg_name, sizeof(sg_name)) != 0)
return HBA_STATUS_ERROR_TARGET_LUN;
status = sg_issue_read_capacity(sg_name, resp, &resp_len,
&stat, sense, &sense_len);
if (status == HBA_STATUS_OK && stat == SCSI_ST_CHECK)
status = HBA_STATUS_SCSI_CHECK_CONDITION;
return status;
}
/*
* Read capacity V2.
*/
HBA_STATUS
scsi_read_capacity_v2(HBA_HANDLE handle, HBA_WWN wwpn,
HBA_WWN disc_wwpn, HBA_UINT64 fc_lun,
void *resp, HBA_UINT32 *resp_lenp,
HBA_UINT8 *statp, void *sense,
HBA_UINT32 *sense_lenp)
{
struct port_info *pp;
char sg_name[50];
/*
* Find port.
*/
pp = adapter_get_port_by_wwn(handle, wwpn, NULL);
if (pp == NULL)
return HBA_STATUS_ERROR_ILLEGAL_WWN;
if (get_binding_sg_name(
pp, disc_wwpn, fc_lun, sg_name, sizeof(sg_name)) != 0)
return HBA_STATUS_ERROR_TARGET_LUN;
return sg_issue_read_capacity(sg_name, resp, resp_lenp,
statp, sense, sense_lenp);
}
/*
* Report LUNS V1.
*/
HBA_STATUS
scsi_report_luns_v1(HBA_HANDLE handle, HBA_WWN disc_wwpn,
void *resp, HBA_UINT32 resp_len,
void *sense, HBA_UINT32 sense_len)
{
struct port_info *pp;
char sg_name[50];
HBA_UINT8 stat;
HBA_STATUS status;
/*
* Find port.
*/
pp = adapter_get_port(handle, 0);
if (pp == NULL)
return HBA_STATUS_ERROR_INVALID_HANDLE;
if (get_binding_sg_name(
pp, disc_wwpn, 0, sg_name, sizeof(sg_name)) != 0)
return HBA_STATUS_ERROR_TARGET_PORT_WWN;
status = sg_issue_report_luns(sg_name, resp, &resp_len,
&stat, sense, &sense_len);
if (status == HBA_STATUS_OK && stat == SCSI_ST_CHECK)
status = HBA_STATUS_SCSI_CHECK_CONDITION;
return status;
}
/*
* Report LUNS V2.
*/
HBA_STATUS
scsi_report_luns_v2(HBA_HANDLE handle, HBA_WWN wwpn,
HBA_WWN disc_wwpn, void *resp,
HBA_UINT32 *resp_lenp, HBA_UINT8 *statp,
void *sense, HBA_UINT32 *sense_lenp)
{
struct port_info *pp;
char sg_name[50];
/*
* Find port.
*/
pp = adapter_get_port_by_wwn(handle, wwpn, NULL);
if (pp == NULL)
return HBA_STATUS_ERROR_ILLEGAL_WWN;
if (get_binding_sg_name(
pp, disc_wwpn, 0, sg_name, sizeof(sg_name)) != 0)
return HBA_STATUS_ERROR_TARGET_PORT_WWN;
return sg_issue_report_luns(sg_name, resp, resp_lenp,
statp, sense, sense_lenp);
}