Commit | Line | Data |
---|---|---|
072b91f9 BK |
1 | /* |
2 | * ibmvfc.c -- driver for IBM Power Virtual Fibre Channel Adapter | |
3 | * | |
4 | * Written By: Brian King <brking@linux.vnet.ibm.com>, IBM Corporation | |
5 | * | |
6 | * Copyright (C) IBM Corporation, 2008 | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | * | |
22 | */ | |
23 | ||
24 | #include <linux/module.h> | |
25 | #include <linux/moduleparam.h> | |
26 | #include <linux/dma-mapping.h> | |
27 | #include <linux/dmapool.h> | |
28 | #include <linux/delay.h> | |
29 | #include <linux/interrupt.h> | |
30 | #include <linux/kthread.h> | |
31 | #include <linux/of.h> | |
32 | #include <linux/stringify.h> | |
33 | #include <asm/firmware.h> | |
34 | #include <asm/irq.h> | |
35 | #include <asm/vio.h> | |
36 | #include <scsi/scsi.h> | |
37 | #include <scsi/scsi_cmnd.h> | |
38 | #include <scsi/scsi_host.h> | |
39 | #include <scsi/scsi_device.h> | |
40 | #include <scsi/scsi_tcq.h> | |
41 | #include <scsi/scsi_transport_fc.h> | |
42 | #include "ibmvfc.h" | |
43 | ||
44 | static unsigned int init_timeout = IBMVFC_INIT_TIMEOUT; | |
45 | static unsigned int default_timeout = IBMVFC_DEFAULT_TIMEOUT; | |
46 | static unsigned int max_lun = IBMVFC_MAX_LUN; | |
47 | static unsigned int max_targets = IBMVFC_MAX_TARGETS; | |
48 | static unsigned int max_requests = IBMVFC_MAX_REQUESTS_DEFAULT; | |
49 | static unsigned int disc_threads = IBMVFC_MAX_DISC_THREADS; | |
50 | static unsigned int dev_loss_tmo = IBMVFC_DEV_LOSS_TMO; | |
51 | static unsigned int ibmvfc_debug = IBMVFC_DEBUG; | |
52 | static unsigned int log_level = IBMVFC_DEFAULT_LOG_LEVEL; | |
53 | static LIST_HEAD(ibmvfc_head); | |
54 | static DEFINE_SPINLOCK(ibmvfc_driver_lock); | |
55 | static struct scsi_transport_template *ibmvfc_transport_template; | |
56 | ||
57 | MODULE_DESCRIPTION("IBM Virtual Fibre Channel Driver"); | |
58 | MODULE_AUTHOR("Brian King <brking@linux.vnet.ibm.com>"); | |
59 | MODULE_LICENSE("GPL"); | |
60 | MODULE_VERSION(IBMVFC_DRIVER_VERSION); | |
61 | ||
62 | module_param_named(init_timeout, init_timeout, uint, S_IRUGO | S_IWUSR); | |
63 | MODULE_PARM_DESC(init_timeout, "Initialization timeout in seconds. " | |
64 | "[Default=" __stringify(IBMVFC_INIT_TIMEOUT) "]"); | |
65 | module_param_named(default_timeout, default_timeout, uint, S_IRUGO | S_IWUSR); | |
66 | MODULE_PARM_DESC(default_timeout, | |
67 | "Default timeout in seconds for initialization and EH commands. " | |
68 | "[Default=" __stringify(IBMVFC_DEFAULT_TIMEOUT) "]"); | |
69 | module_param_named(max_requests, max_requests, uint, S_IRUGO); | |
70 | MODULE_PARM_DESC(max_requests, "Maximum requests for this adapter. " | |
71 | "[Default=" __stringify(IBMVFC_MAX_REQUESTS_DEFAULT) "]"); | |
72 | module_param_named(max_lun, max_lun, uint, S_IRUGO); | |
73 | MODULE_PARM_DESC(max_lun, "Maximum allowed LUN. " | |
74 | "[Default=" __stringify(IBMVFC_MAX_LUN) "]"); | |
75 | module_param_named(max_targets, max_targets, uint, S_IRUGO); | |
76 | MODULE_PARM_DESC(max_targets, "Maximum allowed targets. " | |
77 | "[Default=" __stringify(IBMVFC_MAX_TARGETS) "]"); | |
78 | module_param_named(disc_threads, disc_threads, uint, S_IRUGO | S_IWUSR); | |
79 | MODULE_PARM_DESC(disc_threads, "Number of device discovery threads to use. " | |
80 | "[Default=" __stringify(IBMVFC_MAX_DISC_THREADS) "]"); | |
81 | module_param_named(debug, ibmvfc_debug, uint, S_IRUGO | S_IWUSR); | |
82 | MODULE_PARM_DESC(debug, "Enable driver debug information. " | |
83 | "[Default=" __stringify(IBMVFC_DEBUG) "]"); | |
84 | module_param_named(dev_loss_tmo, dev_loss_tmo, uint, S_IRUGO | S_IWUSR); | |
85 | MODULE_PARM_DESC(dev_loss_tmo, "Maximum number of seconds that the FC " | |
86 | "transport should insulate the loss of a remote port. Once this " | |
87 | "value is exceeded, the scsi target is removed. " | |
88 | "[Default=" __stringify(IBMVFC_DEV_LOSS_TMO) "]"); | |
89 | module_param_named(log_level, log_level, uint, 0); | |
90 | MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver. " | |
91 | "[Default=" __stringify(IBMVFC_DEFAULT_LOG_LEVEL) "]"); | |
92 | ||
93 | static const struct { | |
94 | u16 status; | |
95 | u16 error; | |
96 | u8 result; | |
97 | u8 retry; | |
98 | int log; | |
99 | char *name; | |
100 | } cmd_status [] = { | |
101 | { IBMVFC_FABRIC_MAPPED, IBMVFC_UNABLE_TO_ESTABLISH, DID_ERROR, 1, 1, "unable to establish" }, | |
102 | { IBMVFC_FABRIC_MAPPED, IBMVFC_XPORT_FAULT, DID_OK, 1, 0, "transport fault" }, | |
103 | { IBMVFC_FABRIC_MAPPED, IBMVFC_CMD_TIMEOUT, DID_TIME_OUT, 1, 1, "command timeout" }, | |
104 | { IBMVFC_FABRIC_MAPPED, IBMVFC_ENETDOWN, DID_NO_CONNECT, 1, 1, "network down" }, | |
105 | { IBMVFC_FABRIC_MAPPED, IBMVFC_HW_FAILURE, DID_ERROR, 1, 1, "hardware failure" }, | |
106 | { IBMVFC_FABRIC_MAPPED, IBMVFC_LINK_DOWN_ERR, DID_REQUEUE, 0, 0, "link down" }, | |
107 | { IBMVFC_FABRIC_MAPPED, IBMVFC_LINK_DEAD_ERR, DID_ERROR, 0, 0, "link dead" }, | |
108 | { IBMVFC_FABRIC_MAPPED, IBMVFC_UNABLE_TO_REGISTER, DID_ERROR, 1, 1, "unable to register" }, | |
109 | { IBMVFC_FABRIC_MAPPED, IBMVFC_XPORT_BUSY, DID_BUS_BUSY, 1, 0, "transport busy" }, | |
110 | { IBMVFC_FABRIC_MAPPED, IBMVFC_XPORT_DEAD, DID_ERROR, 0, 1, "transport dead" }, | |
111 | { IBMVFC_FABRIC_MAPPED, IBMVFC_CONFIG_ERROR, DID_ERROR, 1, 1, "configuration error" }, | |
112 | { IBMVFC_FABRIC_MAPPED, IBMVFC_NAME_SERVER_FAIL, DID_ERROR, 1, 1, "name server failure" }, | |
113 | { IBMVFC_FABRIC_MAPPED, IBMVFC_LINK_HALTED, DID_REQUEUE, 0, 0, "link halted" }, | |
114 | { IBMVFC_FABRIC_MAPPED, IBMVFC_XPORT_GENERAL, DID_OK, 1, 0, "general transport error" }, | |
115 | ||
116 | { IBMVFC_VIOS_FAILURE, IBMVFC_CRQ_FAILURE, DID_REQUEUE, 1, 1, "CRQ failure" }, | |
117 | { IBMVFC_VIOS_FAILURE, IBMVFC_SW_FAILURE, DID_ERROR, 0, 1, "software failure" }, | |
118 | { IBMVFC_VIOS_FAILURE, IBMVFC_INVALID_PARAMETER, DID_ABORT, 0, 1, "invalid parameter" }, | |
119 | { IBMVFC_VIOS_FAILURE, IBMVFC_MISSING_PARAMETER, DID_ABORT, 0, 1, "missing parameter" }, | |
120 | { IBMVFC_VIOS_FAILURE, IBMVFC_HOST_IO_BUS, DID_ERROR, 1, 1, "host I/O bus failure" }, | |
121 | { IBMVFC_VIOS_FAILURE, IBMVFC_TRANS_CANCELLED, DID_ABORT, 0, 1, "transaction cancelled" }, | |
122 | { IBMVFC_VIOS_FAILURE, IBMVFC_TRANS_CANCELLED_IMPLICIT, DID_ABORT, 0, 1, "transaction cancelled implicit" }, | |
123 | { IBMVFC_VIOS_FAILURE, IBMVFC_INSUFFICIENT_RESOURCE, DID_REQUEUE, 1, 1, "insufficient resources" }, | |
124 | { IBMVFC_VIOS_FAILURE, IBMVFC_COMMAND_FAILED, DID_ERROR, 1, 1, "command failed" }, | |
125 | ||
126 | { IBMVFC_FC_FAILURE, IBMVFC_INVALID_ELS_CMD_CODE, DID_ERROR, 0, 1, "invalid ELS command code" }, | |
127 | { IBMVFC_FC_FAILURE, IBMVFC_INVALID_VERSION, DID_ERROR, 0, 1, "invalid version level" }, | |
128 | { IBMVFC_FC_FAILURE, IBMVFC_LOGICAL_ERROR, DID_ERROR, 1, 1, "logical error" }, | |
129 | { IBMVFC_FC_FAILURE, IBMVFC_INVALID_CT_IU_SIZE, DID_ERROR, 0, 1, "invalid CT_IU size" }, | |
130 | { IBMVFC_FC_FAILURE, IBMVFC_LOGICAL_BUSY, DID_REQUEUE, 1, 0, "logical busy" }, | |
131 | { IBMVFC_FC_FAILURE, IBMVFC_PROTOCOL_ERROR, DID_ERROR, 1, 1, "protocol error" }, | |
132 | { IBMVFC_FC_FAILURE, IBMVFC_UNABLE_TO_PERFORM_REQ, DID_ERROR, 1, 1, "unable to perform request" }, | |
133 | { IBMVFC_FC_FAILURE, IBMVFC_CMD_NOT_SUPPORTED, DID_ERROR, 0, 0, "command not supported" }, | |
134 | { IBMVFC_FC_FAILURE, IBMVFC_SERVER_NOT_AVAIL, DID_ERROR, 0, 1, "server not available" }, | |
135 | { IBMVFC_FC_FAILURE, IBMVFC_CMD_IN_PROGRESS, DID_ERROR, 0, 1, "command already in progress" }, | |
136 | { IBMVFC_FC_FAILURE, IBMVFC_VENDOR_SPECIFIC, DID_ERROR, 1, 1, "vendor specific" }, | |
137 | ||
138 | { IBMVFC_FC_SCSI_ERROR, 0, DID_OK, 1, 0, "SCSI error" }, | |
139 | }; | |
140 | ||
141 | static void ibmvfc_npiv_login(struct ibmvfc_host *); | |
142 | static void ibmvfc_tgt_send_prli(struct ibmvfc_target *); | |
143 | static void ibmvfc_tgt_send_plogi(struct ibmvfc_target *); | |
144 | static void ibmvfc_tgt_query_target(struct ibmvfc_target *); | |
145 | ||
146 | static const char *unknown_error = "unknown error"; | |
147 | ||
148 | #ifdef CONFIG_SCSI_IBMVFC_TRACE | |
149 | /** | |
150 | * ibmvfc_trc_start - Log a start trace entry | |
151 | * @evt: ibmvfc event struct | |
152 | * | |
153 | **/ | |
154 | static void ibmvfc_trc_start(struct ibmvfc_event *evt) | |
155 | { | |
156 | struct ibmvfc_host *vhost = evt->vhost; | |
157 | struct ibmvfc_cmd *vfc_cmd = &evt->iu.cmd; | |
158 | struct ibmvfc_mad_common *mad = &evt->iu.mad_common; | |
159 | struct ibmvfc_trace_entry *entry; | |
160 | ||
161 | entry = &vhost->trace[vhost->trace_index++]; | |
162 | entry->evt = evt; | |
163 | entry->time = jiffies; | |
164 | entry->fmt = evt->crq.format; | |
165 | entry->type = IBMVFC_TRC_START; | |
166 | ||
167 | switch (entry->fmt) { | |
168 | case IBMVFC_CMD_FORMAT: | |
169 | entry->op_code = vfc_cmd->iu.cdb[0]; | |
170 | entry->scsi_id = vfc_cmd->tgt_scsi_id; | |
171 | entry->lun = scsilun_to_int(&vfc_cmd->iu.lun); | |
172 | entry->tmf_flags = vfc_cmd->iu.tmf_flags; | |
173 | entry->u.start.xfer_len = vfc_cmd->iu.xfer_len; | |
174 | break; | |
175 | case IBMVFC_MAD_FORMAT: | |
176 | entry->op_code = mad->opcode; | |
177 | break; | |
178 | default: | |
179 | break; | |
180 | }; | |
181 | } | |
182 | ||
183 | /** | |
184 | * ibmvfc_trc_end - Log an end trace entry | |
185 | * @evt: ibmvfc event struct | |
186 | * | |
187 | **/ | |
188 | static void ibmvfc_trc_end(struct ibmvfc_event *evt) | |
189 | { | |
190 | struct ibmvfc_host *vhost = evt->vhost; | |
191 | struct ibmvfc_cmd *vfc_cmd = &evt->xfer_iu->cmd; | |
192 | struct ibmvfc_mad_common *mad = &evt->xfer_iu->mad_common; | |
193 | struct ibmvfc_trace_entry *entry = &vhost->trace[vhost->trace_index++]; | |
194 | ||
195 | entry->evt = evt; | |
196 | entry->time = jiffies; | |
197 | entry->fmt = evt->crq.format; | |
198 | entry->type = IBMVFC_TRC_END; | |
199 | ||
200 | switch (entry->fmt) { | |
201 | case IBMVFC_CMD_FORMAT: | |
202 | entry->op_code = vfc_cmd->iu.cdb[0]; | |
203 | entry->scsi_id = vfc_cmd->tgt_scsi_id; | |
204 | entry->lun = scsilun_to_int(&vfc_cmd->iu.lun); | |
205 | entry->tmf_flags = vfc_cmd->iu.tmf_flags; | |
206 | entry->u.end.status = vfc_cmd->status; | |
207 | entry->u.end.error = vfc_cmd->error; | |
208 | entry->u.end.fcp_rsp_flags = vfc_cmd->rsp.flags; | |
209 | entry->u.end.rsp_code = vfc_cmd->rsp.data.info.rsp_code; | |
210 | entry->u.end.scsi_status = vfc_cmd->rsp.scsi_status; | |
211 | break; | |
212 | case IBMVFC_MAD_FORMAT: | |
213 | entry->op_code = mad->opcode; | |
214 | entry->u.end.status = mad->status; | |
215 | break; | |
216 | default: | |
217 | break; | |
218 | ||
219 | }; | |
220 | } | |
221 | ||
222 | #else | |
223 | #define ibmvfc_trc_start(evt) do { } while (0) | |
224 | #define ibmvfc_trc_end(evt) do { } while (0) | |
225 | #endif | |
226 | ||
227 | /** | |
228 | * ibmvfc_get_err_index - Find the index into cmd_status for the fcp response | |
229 | * @status: status / error class | |
230 | * @error: error | |
231 | * | |
232 | * Return value: | |
233 | * index into cmd_status / -EINVAL on failure | |
234 | **/ | |
235 | static int ibmvfc_get_err_index(u16 status, u16 error) | |
236 | { | |
237 | int i; | |
238 | ||
239 | for (i = 0; i < ARRAY_SIZE(cmd_status); i++) | |
240 | if ((cmd_status[i].status & status) == cmd_status[i].status && | |
241 | cmd_status[i].error == error) | |
242 | return i; | |
243 | ||
244 | return -EINVAL; | |
245 | } | |
246 | ||
247 | /** | |
248 | * ibmvfc_get_cmd_error - Find the error description for the fcp response | |
249 | * @status: status / error class | |
250 | * @error: error | |
251 | * | |
252 | * Return value: | |
253 | * error description string | |
254 | **/ | |
255 | static const char *ibmvfc_get_cmd_error(u16 status, u16 error) | |
256 | { | |
257 | int rc = ibmvfc_get_err_index(status, error); | |
258 | if (rc >= 0) | |
259 | return cmd_status[rc].name; | |
260 | return unknown_error; | |
261 | } | |
262 | ||
263 | /** | |
264 | * ibmvfc_get_err_result - Find the scsi status to return for the fcp response | |
265 | * @vfc_cmd: ibmvfc command struct | |
266 | * | |
267 | * Return value: | |
268 | * SCSI result value to return for completed command | |
269 | **/ | |
270 | static int ibmvfc_get_err_result(struct ibmvfc_cmd *vfc_cmd) | |
271 | { | |
272 | int err; | |
273 | struct ibmvfc_fcp_rsp *rsp = &vfc_cmd->rsp; | |
274 | int fc_rsp_len = rsp->fcp_rsp_len; | |
275 | ||
276 | if ((rsp->flags & FCP_RSP_LEN_VALID) && | |
277 | ((!fc_rsp_len && fc_rsp_len != 4 && fc_rsp_len != 8) || | |
278 | rsp->data.info.rsp_code)) | |
279 | return DID_ERROR << 16; | |
280 | ||
281 | if (!vfc_cmd->status) { | |
282 | if (rsp->flags & FCP_RESID_OVER) | |
283 | return rsp->scsi_status | (DID_ERROR << 16); | |
284 | else | |
285 | return rsp->scsi_status | (DID_OK << 16); | |
286 | } | |
287 | ||
288 | err = ibmvfc_get_err_index(vfc_cmd->status, vfc_cmd->error); | |
289 | if (err >= 0) | |
290 | return rsp->scsi_status | (cmd_status[err].result << 16); | |
291 | return rsp->scsi_status | (DID_ERROR << 16); | |
292 | } | |
293 | ||
294 | /** | |
295 | * ibmvfc_retry_cmd - Determine if error status is retryable | |
296 | * @status: status / error class | |
297 | * @error: error | |
298 | * | |
299 | * Return value: | |
300 | * 1 if error should be retried / 0 if it should not | |
301 | **/ | |
302 | static int ibmvfc_retry_cmd(u16 status, u16 error) | |
303 | { | |
304 | int rc = ibmvfc_get_err_index(status, error); | |
305 | ||
306 | if (rc >= 0) | |
307 | return cmd_status[rc].retry; | |
308 | return 1; | |
309 | } | |
310 | ||
311 | static const char *unknown_fc_explain = "unknown fc explain"; | |
312 | ||
313 | static const struct { | |
314 | u16 fc_explain; | |
315 | char *name; | |
316 | } ls_explain [] = { | |
317 | { 0x00, "no additional explanation" }, | |
318 | { 0x01, "service parameter error - options" }, | |
319 | { 0x03, "service parameter error - initiator control" }, | |
320 | { 0x05, "service parameter error - recipient control" }, | |
321 | { 0x07, "service parameter error - received data field size" }, | |
322 | { 0x09, "service parameter error - concurrent seq" }, | |
323 | { 0x0B, "service parameter error - credit" }, | |
324 | { 0x0D, "invalid N_Port/F_Port_Name" }, | |
325 | { 0x0E, "invalid node/Fabric Name" }, | |
326 | { 0x0F, "invalid common service parameters" }, | |
327 | { 0x11, "invalid association header" }, | |
328 | { 0x13, "association header required" }, | |
329 | { 0x15, "invalid originator S_ID" }, | |
330 | { 0x17, "invalid OX_ID-RX-ID combination" }, | |
331 | { 0x19, "command (request) already in progress" }, | |
332 | { 0x1E, "N_Port Login requested" }, | |
333 | { 0x1F, "Invalid N_Port_ID" }, | |
334 | }; | |
335 | ||
336 | static const struct { | |
337 | u16 fc_explain; | |
338 | char *name; | |
339 | } gs_explain [] = { | |
340 | { 0x00, "no additional explanation" }, | |
341 | { 0x01, "port identifier not registered" }, | |
342 | { 0x02, "port name not registered" }, | |
343 | { 0x03, "node name not registered" }, | |
344 | { 0x04, "class of service not registered" }, | |
345 | { 0x06, "initial process associator not registered" }, | |
346 | { 0x07, "FC-4 TYPEs not registered" }, | |
347 | { 0x08, "symbolic port name not registered" }, | |
348 | { 0x09, "symbolic node name not registered" }, | |
349 | { 0x0A, "port type not registered" }, | |
350 | { 0xF0, "authorization exception" }, | |
351 | { 0xF1, "authentication exception" }, | |
352 | { 0xF2, "data base full" }, | |
353 | { 0xF3, "data base empty" }, | |
354 | { 0xF4, "processing request" }, | |
355 | { 0xF5, "unable to verify connection" }, | |
356 | { 0xF6, "devices not in a common zone" }, | |
357 | }; | |
358 | ||
359 | /** | |
360 | * ibmvfc_get_ls_explain - Return the FC Explain description text | |
361 | * @status: FC Explain status | |
362 | * | |
363 | * Returns: | |
364 | * error string | |
365 | **/ | |
366 | static const char *ibmvfc_get_ls_explain(u16 status) | |
367 | { | |
368 | int i; | |
369 | ||
370 | for (i = 0; i < ARRAY_SIZE(ls_explain); i++) | |
371 | if (ls_explain[i].fc_explain == status) | |
372 | return ls_explain[i].name; | |
373 | ||
374 | return unknown_fc_explain; | |
375 | } | |
376 | ||
377 | /** | |
378 | * ibmvfc_get_gs_explain - Return the FC Explain description text | |
379 | * @status: FC Explain status | |
380 | * | |
381 | * Returns: | |
382 | * error string | |
383 | **/ | |
384 | static const char *ibmvfc_get_gs_explain(u16 status) | |
385 | { | |
386 | int i; | |
387 | ||
388 | for (i = 0; i < ARRAY_SIZE(gs_explain); i++) | |
389 | if (gs_explain[i].fc_explain == status) | |
390 | return gs_explain[i].name; | |
391 | ||
392 | return unknown_fc_explain; | |
393 | } | |
394 | ||
395 | static const struct { | |
396 | enum ibmvfc_fc_type fc_type; | |
397 | char *name; | |
398 | } fc_type [] = { | |
399 | { IBMVFC_FABRIC_REJECT, "fabric reject" }, | |
400 | { IBMVFC_PORT_REJECT, "port reject" }, | |
401 | { IBMVFC_LS_REJECT, "ELS reject" }, | |
402 | { IBMVFC_FABRIC_BUSY, "fabric busy" }, | |
403 | { IBMVFC_PORT_BUSY, "port busy" }, | |
404 | { IBMVFC_BASIC_REJECT, "basic reject" }, | |
405 | }; | |
406 | ||
407 | static const char *unknown_fc_type = "unknown fc type"; | |
408 | ||
409 | /** | |
410 | * ibmvfc_get_fc_type - Return the FC Type description text | |
411 | * @status: FC Type error status | |
412 | * | |
413 | * Returns: | |
414 | * error string | |
415 | **/ | |
416 | static const char *ibmvfc_get_fc_type(u16 status) | |
417 | { | |
418 | int i; | |
419 | ||
420 | for (i = 0; i < ARRAY_SIZE(fc_type); i++) | |
421 | if (fc_type[i].fc_type == status) | |
422 | return fc_type[i].name; | |
423 | ||
424 | return unknown_fc_type; | |
425 | } | |
426 | ||
427 | /** | |
428 | * ibmvfc_set_tgt_action - Set the next init action for the target | |
429 | * @tgt: ibmvfc target struct | |
430 | * @action: action to perform | |
431 | * | |
432 | **/ | |
433 | static void ibmvfc_set_tgt_action(struct ibmvfc_target *tgt, | |
434 | enum ibmvfc_target_action action) | |
435 | { | |
436 | switch (tgt->action) { | |
437 | case IBMVFC_TGT_ACTION_DEL_RPORT: | |
438 | break; | |
439 | default: | |
440 | tgt->action = action; | |
441 | break; | |
442 | } | |
443 | } | |
444 | ||
445 | /** | |
446 | * ibmvfc_set_host_state - Set the state for the host | |
447 | * @vhost: ibmvfc host struct | |
448 | * @state: state to set host to | |
449 | * | |
450 | * Returns: | |
451 | * 0 if state changed / non-zero if not changed | |
452 | **/ | |
453 | static int ibmvfc_set_host_state(struct ibmvfc_host *vhost, | |
454 | enum ibmvfc_host_state state) | |
455 | { | |
456 | int rc = 0; | |
457 | ||
458 | switch (vhost->state) { | |
459 | case IBMVFC_HOST_OFFLINE: | |
460 | rc = -EINVAL; | |
461 | break; | |
462 | default: | |
463 | vhost->state = state; | |
464 | break; | |
465 | }; | |
466 | ||
467 | return rc; | |
468 | } | |
469 | ||
470 | /** | |
471 | * ibmvfc_set_host_action - Set the next init action for the host | |
472 | * @vhost: ibmvfc host struct | |
473 | * @action: action to perform | |
474 | * | |
475 | **/ | |
476 | static void ibmvfc_set_host_action(struct ibmvfc_host *vhost, | |
477 | enum ibmvfc_host_action action) | |
478 | { | |
479 | switch (action) { | |
480 | case IBMVFC_HOST_ACTION_ALLOC_TGTS: | |
481 | if (vhost->action == IBMVFC_HOST_ACTION_INIT_WAIT) | |
482 | vhost->action = action; | |
483 | break; | |
484 | case IBMVFC_HOST_ACTION_INIT_WAIT: | |
485 | if (vhost->action == IBMVFC_HOST_ACTION_INIT) | |
486 | vhost->action = action; | |
487 | break; | |
488 | case IBMVFC_HOST_ACTION_QUERY: | |
489 | switch (vhost->action) { | |
490 | case IBMVFC_HOST_ACTION_INIT_WAIT: | |
491 | case IBMVFC_HOST_ACTION_NONE: | |
492 | case IBMVFC_HOST_ACTION_TGT_ADD: | |
493 | vhost->action = action; | |
494 | break; | |
495 | default: | |
496 | break; | |
497 | }; | |
498 | break; | |
499 | case IBMVFC_HOST_ACTION_TGT_INIT: | |
500 | if (vhost->action == IBMVFC_HOST_ACTION_ALLOC_TGTS) | |
501 | vhost->action = action; | |
502 | break; | |
503 | case IBMVFC_HOST_ACTION_INIT: | |
504 | case IBMVFC_HOST_ACTION_TGT_DEL: | |
505 | case IBMVFC_HOST_ACTION_QUERY_TGTS: | |
506 | case IBMVFC_HOST_ACTION_TGT_ADD: | |
507 | case IBMVFC_HOST_ACTION_NONE: | |
508 | default: | |
509 | vhost->action = action; | |
510 | break; | |
511 | }; | |
512 | } | |
513 | ||
514 | /** | |
515 | * ibmvfc_reinit_host - Re-start host initialization (no NPIV Login) | |
516 | * @vhost: ibmvfc host struct | |
517 | * | |
518 | * Return value: | |
519 | * nothing | |
520 | **/ | |
521 | static void ibmvfc_reinit_host(struct ibmvfc_host *vhost) | |
522 | { | |
523 | if (vhost->action == IBMVFC_HOST_ACTION_NONE) { | |
2d0da2a4 BK |
524 | if (!ibmvfc_set_host_state(vhost, IBMVFC_INITIALIZING)) { |
525 | scsi_block_requests(vhost->host); | |
526 | ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_QUERY); | |
527 | } | |
072b91f9 BK |
528 | } else |
529 | vhost->reinit = 1; | |
530 | ||
531 | wake_up(&vhost->work_wait_q); | |
532 | } | |
533 | ||
534 | /** | |
535 | * ibmvfc_link_down - Handle a link down event from the adapter | |
536 | * @vhost: ibmvfc host struct | |
537 | * @state: ibmvfc host state to enter | |
538 | * | |
539 | **/ | |
540 | static void ibmvfc_link_down(struct ibmvfc_host *vhost, | |
541 | enum ibmvfc_host_state state) | |
542 | { | |
543 | struct ibmvfc_target *tgt; | |
544 | ||
545 | ENTER; | |
546 | scsi_block_requests(vhost->host); | |
547 | list_for_each_entry(tgt, &vhost->targets, queue) | |
548 | ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_DEL_RPORT); | |
549 | ibmvfc_set_host_state(vhost, state); | |
550 | ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_TGT_DEL); | |
551 | vhost->events_to_log |= IBMVFC_AE_LINKDOWN; | |
552 | wake_up(&vhost->work_wait_q); | |
553 | LEAVE; | |
554 | } | |
555 | ||
556 | /** | |
557 | * ibmvfc_init_host - Start host initialization | |
558 | * @vhost: ibmvfc host struct | |
559 | * | |
560 | * Return value: | |
561 | * nothing | |
562 | **/ | |
563 | static void ibmvfc_init_host(struct ibmvfc_host *vhost) | |
564 | { | |
565 | struct ibmvfc_target *tgt; | |
566 | ||
567 | if (vhost->action == IBMVFC_HOST_ACTION_INIT_WAIT) { | |
568 | if (++vhost->init_retries > IBMVFC_MAX_INIT_RETRIES) { | |
569 | dev_err(vhost->dev, | |
570 | "Host initialization retries exceeded. Taking adapter offline\n"); | |
571 | ibmvfc_link_down(vhost, IBMVFC_HOST_OFFLINE); | |
572 | return; | |
573 | } | |
574 | } | |
575 | ||
576 | if (!ibmvfc_set_host_state(vhost, IBMVFC_INITIALIZING)) { | |
577 | list_for_each_entry(tgt, &vhost->targets, queue) | |
578 | tgt->need_login = 1; | |
579 | scsi_block_requests(vhost->host); | |
580 | ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT); | |
581 | vhost->job_step = ibmvfc_npiv_login; | |
582 | wake_up(&vhost->work_wait_q); | |
583 | } | |
584 | } | |
585 | ||
586 | /** | |
587 | * ibmvfc_send_crq - Send a CRQ | |
588 | * @vhost: ibmvfc host struct | |
589 | * @word1: the first 64 bits of the data | |
590 | * @word2: the second 64 bits of the data | |
591 | * | |
592 | * Return value: | |
593 | * 0 on success / other on failure | |
594 | **/ | |
595 | static int ibmvfc_send_crq(struct ibmvfc_host *vhost, u64 word1, u64 word2) | |
596 | { | |
597 | struct vio_dev *vdev = to_vio_dev(vhost->dev); | |
598 | return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address, word1, word2); | |
599 | } | |
600 | ||
601 | /** | |
602 | * ibmvfc_send_crq_init - Send a CRQ init message | |
603 | * @vhost: ibmvfc host struct | |
604 | * | |
605 | * Return value: | |
606 | * 0 on success / other on failure | |
607 | **/ | |
608 | static int ibmvfc_send_crq_init(struct ibmvfc_host *vhost) | |
609 | { | |
610 | ibmvfc_dbg(vhost, "Sending CRQ init\n"); | |
611 | return ibmvfc_send_crq(vhost, 0xC001000000000000LL, 0); | |
612 | } | |
613 | ||
614 | /** | |
615 | * ibmvfc_send_crq_init_complete - Send a CRQ init complete message | |
616 | * @vhost: ibmvfc host struct | |
617 | * | |
618 | * Return value: | |
619 | * 0 on success / other on failure | |
620 | **/ | |
621 | static int ibmvfc_send_crq_init_complete(struct ibmvfc_host *vhost) | |
622 | { | |
623 | ibmvfc_dbg(vhost, "Sending CRQ init complete\n"); | |
624 | return ibmvfc_send_crq(vhost, 0xC002000000000000LL, 0); | |
625 | } | |
626 | ||
627 | /** | |
628 | * ibmvfc_release_crq_queue - Deallocates data and unregisters CRQ | |
629 | * @vhost: ibmvfc host struct | |
630 | * | |
631 | * Frees irq, deallocates a page for messages, unmaps dma, and unregisters | |
632 | * the crq with the hypervisor. | |
633 | **/ | |
634 | static void ibmvfc_release_crq_queue(struct ibmvfc_host *vhost) | |
635 | { | |
636 | long rc; | |
637 | struct vio_dev *vdev = to_vio_dev(vhost->dev); | |
638 | struct ibmvfc_crq_queue *crq = &vhost->crq; | |
639 | ||
640 | ibmvfc_dbg(vhost, "Releasing CRQ\n"); | |
641 | free_irq(vdev->irq, vhost); | |
642 | do { | |
643 | rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); | |
644 | } while (rc == H_BUSY || H_IS_LONG_BUSY(rc)); | |
645 | ||
646 | vhost->state = IBMVFC_NO_CRQ; | |
647 | dma_unmap_single(vhost->dev, crq->msg_token, PAGE_SIZE, DMA_BIDIRECTIONAL); | |
648 | free_page((unsigned long)crq->msgs); | |
649 | } | |
650 | ||
651 | /** | |
652 | * ibmvfc_reenable_crq_queue - reenables the CRQ | |
653 | * @vhost: ibmvfc host struct | |
654 | * | |
655 | * Return value: | |
656 | * 0 on success / other on failure | |
657 | **/ | |
658 | static int ibmvfc_reenable_crq_queue(struct ibmvfc_host *vhost) | |
659 | { | |
660 | int rc; | |
661 | struct vio_dev *vdev = to_vio_dev(vhost->dev); | |
662 | ||
663 | /* Re-enable the CRQ */ | |
664 | do { | |
665 | rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address); | |
666 | } while (rc == H_IN_PROGRESS || rc == H_BUSY || H_IS_LONG_BUSY(rc)); | |
667 | ||
668 | if (rc) | |
669 | dev_err(vhost->dev, "Error enabling adapter (rc=%d)\n", rc); | |
670 | ||
671 | return rc; | |
672 | } | |
673 | ||
674 | /** | |
675 | * ibmvfc_reset_crq - resets a crq after a failure | |
676 | * @vhost: ibmvfc host struct | |
677 | * | |
678 | * Return value: | |
679 | * 0 on success / other on failure | |
680 | **/ | |
681 | static int ibmvfc_reset_crq(struct ibmvfc_host *vhost) | |
682 | { | |
683 | int rc; | |
684 | struct vio_dev *vdev = to_vio_dev(vhost->dev); | |
685 | struct ibmvfc_crq_queue *crq = &vhost->crq; | |
686 | ||
687 | /* Close the CRQ */ | |
688 | do { | |
689 | rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); | |
690 | } while (rc == H_BUSY || H_IS_LONG_BUSY(rc)); | |
691 | ||
692 | vhost->state = IBMVFC_NO_CRQ; | |
693 | ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_NONE); | |
694 | ||
695 | /* Clean out the queue */ | |
696 | memset(crq->msgs, 0, PAGE_SIZE); | |
697 | crq->cur = 0; | |
698 | ||
699 | /* And re-open it again */ | |
700 | rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address, | |
701 | crq->msg_token, PAGE_SIZE); | |
702 | ||
703 | if (rc == H_CLOSED) | |
704 | /* Adapter is good, but other end is not ready */ | |
705 | dev_warn(vhost->dev, "Partner adapter not ready\n"); | |
706 | else if (rc != 0) | |
707 | dev_warn(vhost->dev, "Couldn't register crq (rc=%d)\n", rc); | |
708 | ||
709 | return rc; | |
710 | } | |
711 | ||
712 | /** | |
713 | * ibmvfc_valid_event - Determines if event is valid. | |
714 | * @pool: event_pool that contains the event | |
715 | * @evt: ibmvfc event to be checked for validity | |
716 | * | |
717 | * Return value: | |
718 | * 1 if event is valid / 0 if event is not valid | |
719 | **/ | |
720 | static int ibmvfc_valid_event(struct ibmvfc_event_pool *pool, | |
721 | struct ibmvfc_event *evt) | |
722 | { | |
723 | int index = evt - pool->events; | |
724 | if (index < 0 || index >= pool->size) /* outside of bounds */ | |
725 | return 0; | |
726 | if (evt != pool->events + index) /* unaligned */ | |
727 | return 0; | |
728 | return 1; | |
729 | } | |
730 | ||
731 | /** | |
732 | * ibmvfc_free_event - Free the specified event | |
733 | * @evt: ibmvfc_event to be freed | |
734 | * | |
735 | **/ | |
736 | static void ibmvfc_free_event(struct ibmvfc_event *evt) | |
737 | { | |
738 | struct ibmvfc_host *vhost = evt->vhost; | |
739 | struct ibmvfc_event_pool *pool = &vhost->pool; | |
740 | ||
741 | BUG_ON(!ibmvfc_valid_event(pool, evt)); | |
742 | BUG_ON(atomic_inc_return(&evt->free) != 1); | |
743 | list_add_tail(&evt->queue, &vhost->free); | |
744 | } | |
745 | ||
746 | /** | |
747 | * ibmvfc_scsi_eh_done - EH done function for queuecommand commands | |
748 | * @evt: ibmvfc event struct | |
749 | * | |
750 | * This function does not setup any error status, that must be done | |
751 | * before this function gets called. | |
752 | **/ | |
753 | static void ibmvfc_scsi_eh_done(struct ibmvfc_event *evt) | |
754 | { | |
755 | struct scsi_cmnd *cmnd = evt->cmnd; | |
756 | ||
757 | if (cmnd) { | |
758 | scsi_dma_unmap(cmnd); | |
759 | cmnd->scsi_done(cmnd); | |
760 | } | |
761 | ||
762 | ibmvfc_free_event(evt); | |
763 | } | |
764 | ||
765 | /** | |
766 | * ibmvfc_fail_request - Fail request with specified error code | |
767 | * @evt: ibmvfc event struct | |
768 | * @error_code: error code to fail request with | |
769 | * | |
770 | * Return value: | |
771 | * none | |
772 | **/ | |
773 | static void ibmvfc_fail_request(struct ibmvfc_event *evt, int error_code) | |
774 | { | |
775 | if (evt->cmnd) { | |
776 | evt->cmnd->result = (error_code << 16); | |
777 | evt->done = ibmvfc_scsi_eh_done; | |
778 | } else | |
779 | evt->xfer_iu->mad_common.status = IBMVFC_MAD_DRIVER_FAILED; | |
780 | ||
781 | list_del(&evt->queue); | |
782 | del_timer(&evt->timer); | |
783 | ibmvfc_trc_end(evt); | |
784 | evt->done(evt); | |
785 | } | |
786 | ||
787 | /** | |
788 | * ibmvfc_purge_requests - Our virtual adapter just shut down. Purge any sent requests | |
789 | * @vhost: ibmvfc host struct | |
790 | * @error_code: error code to fail requests with | |
791 | * | |
792 | * Return value: | |
793 | * none | |
794 | **/ | |
795 | static void ibmvfc_purge_requests(struct ibmvfc_host *vhost, int error_code) | |
796 | { | |
797 | struct ibmvfc_event *evt, *pos; | |
798 | ||
799 | ibmvfc_dbg(vhost, "Purging all requests\n"); | |
800 | list_for_each_entry_safe(evt, pos, &vhost->sent, queue) | |
801 | ibmvfc_fail_request(evt, error_code); | |
802 | } | |
803 | ||
804 | /** | |
805 | * __ibmvfc_reset_host - Reset the connection to the server (no locking) | |
806 | * @vhost: struct ibmvfc host to reset | |
807 | **/ | |
808 | static void __ibmvfc_reset_host(struct ibmvfc_host *vhost) | |
809 | { | |
810 | int rc; | |
811 | ||
812 | scsi_block_requests(vhost->host); | |
813 | ibmvfc_purge_requests(vhost, DID_ERROR); | |
814 | if ((rc = ibmvfc_reset_crq(vhost)) || | |
815 | (rc = ibmvfc_send_crq_init(vhost)) || | |
816 | (rc = vio_enable_interrupts(to_vio_dev(vhost->dev)))) { | |
817 | dev_err(vhost->dev, "Error after reset rc=%d\n", rc); | |
818 | ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD); | |
819 | } else | |
820 | ibmvfc_link_down(vhost, IBMVFC_LINK_DOWN); | |
821 | } | |
822 | ||
823 | /** | |
824 | * ibmvfc_reset_host - Reset the connection to the server | |
825 | * @vhost: struct ibmvfc host to reset | |
826 | **/ | |
827 | static void ibmvfc_reset_host(struct ibmvfc_host *vhost) | |
828 | { | |
829 | unsigned long flags; | |
830 | ||
831 | spin_lock_irqsave(vhost->host->host_lock, flags); | |
832 | __ibmvfc_reset_host(vhost); | |
833 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
834 | } | |
835 | ||
836 | /** | |
837 | * ibmvfc_retry_host_init - Retry host initialization if allowed | |
838 | * @vhost: ibmvfc host struct | |
839 | * | |
840 | **/ | |
841 | static void ibmvfc_retry_host_init(struct ibmvfc_host *vhost) | |
842 | { | |
843 | if (vhost->action == IBMVFC_HOST_ACTION_INIT_WAIT) { | |
844 | if (++vhost->init_retries > IBMVFC_MAX_INIT_RETRIES) { | |
845 | dev_err(vhost->dev, | |
846 | "Host initialization retries exceeded. Taking adapter offline\n"); | |
847 | ibmvfc_link_down(vhost, IBMVFC_HOST_OFFLINE); | |
848 | } else if (vhost->init_retries == IBMVFC_MAX_INIT_RETRIES) | |
849 | __ibmvfc_reset_host(vhost); | |
850 | else | |
851 | ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT); | |
852 | } | |
853 | ||
854 | wake_up(&vhost->work_wait_q); | |
855 | } | |
856 | ||
857 | /** | |
b3c10489 | 858 | * __ibmvfc_get_target - Find the specified scsi_target (no locking) |
072b91f9 BK |
859 | * @starget: scsi target struct |
860 | * | |
861 | * Return value: | |
862 | * ibmvfc_target struct / NULL if not found | |
863 | **/ | |
b3c10489 | 864 | static struct ibmvfc_target *__ibmvfc_get_target(struct scsi_target *starget) |
072b91f9 BK |
865 | { |
866 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); | |
867 | struct ibmvfc_host *vhost = shost_priv(shost); | |
868 | struct ibmvfc_target *tgt; | |
869 | ||
870 | list_for_each_entry(tgt, &vhost->targets, queue) | |
b3c10489 BK |
871 | if (tgt->target_id == starget->id) { |
872 | kref_get(&tgt->kref); | |
072b91f9 | 873 | return tgt; |
b3c10489 | 874 | } |
072b91f9 BK |
875 | return NULL; |
876 | } | |
877 | ||
878 | /** | |
b3c10489 | 879 | * ibmvfc_get_target - Find the specified scsi_target |
072b91f9 BK |
880 | * @starget: scsi target struct |
881 | * | |
882 | * Return value: | |
883 | * ibmvfc_target struct / NULL if not found | |
884 | **/ | |
b3c10489 | 885 | static struct ibmvfc_target *ibmvfc_get_target(struct scsi_target *starget) |
072b91f9 BK |
886 | { |
887 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); | |
888 | struct ibmvfc_target *tgt; | |
889 | unsigned long flags; | |
890 | ||
891 | spin_lock_irqsave(shost->host_lock, flags); | |
b3c10489 | 892 | tgt = __ibmvfc_get_target(starget); |
072b91f9 BK |
893 | spin_unlock_irqrestore(shost->host_lock, flags); |
894 | return tgt; | |
895 | } | |
896 | ||
897 | /** | |
898 | * ibmvfc_get_host_speed - Get host port speed | |
899 | * @shost: scsi host struct | |
900 | * | |
901 | * Return value: | |
902 | * none | |
903 | **/ | |
904 | static void ibmvfc_get_host_speed(struct Scsi_Host *shost) | |
905 | { | |
906 | struct ibmvfc_host *vhost = shost_priv(shost); | |
907 | unsigned long flags; | |
908 | ||
909 | spin_lock_irqsave(shost->host_lock, flags); | |
910 | if (vhost->state == IBMVFC_ACTIVE) { | |
911 | switch (vhost->login_buf->resp.link_speed / 100) { | |
912 | case 1: | |
913 | fc_host_speed(shost) = FC_PORTSPEED_1GBIT; | |
914 | break; | |
915 | case 2: | |
916 | fc_host_speed(shost) = FC_PORTSPEED_2GBIT; | |
917 | break; | |
918 | case 4: | |
919 | fc_host_speed(shost) = FC_PORTSPEED_4GBIT; | |
920 | break; | |
921 | case 8: | |
922 | fc_host_speed(shost) = FC_PORTSPEED_8GBIT; | |
923 | break; | |
924 | case 10: | |
925 | fc_host_speed(shost) = FC_PORTSPEED_10GBIT; | |
926 | break; | |
927 | case 16: | |
928 | fc_host_speed(shost) = FC_PORTSPEED_16GBIT; | |
929 | break; | |
930 | default: | |
931 | ibmvfc_log(vhost, 3, "Unknown port speed: %ld Gbit\n", | |
932 | vhost->login_buf->resp.link_speed / 100); | |
933 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; | |
934 | break; | |
935 | } | |
936 | } else | |
937 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; | |
938 | spin_unlock_irqrestore(shost->host_lock, flags); | |
939 | } | |
940 | ||
941 | /** | |
942 | * ibmvfc_get_host_port_state - Get host port state | |
943 | * @shost: scsi host struct | |
944 | * | |
945 | * Return value: | |
946 | * none | |
947 | **/ | |
948 | static void ibmvfc_get_host_port_state(struct Scsi_Host *shost) | |
949 | { | |
950 | struct ibmvfc_host *vhost = shost_priv(shost); | |
951 | unsigned long flags; | |
952 | ||
953 | spin_lock_irqsave(shost->host_lock, flags); | |
954 | switch (vhost->state) { | |
955 | case IBMVFC_INITIALIZING: | |
956 | case IBMVFC_ACTIVE: | |
957 | fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; | |
958 | break; | |
959 | case IBMVFC_LINK_DOWN: | |
960 | fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; | |
961 | break; | |
962 | case IBMVFC_LINK_DEAD: | |
963 | case IBMVFC_HOST_OFFLINE: | |
964 | fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; | |
965 | break; | |
966 | case IBMVFC_HALTED: | |
967 | fc_host_port_state(shost) = FC_PORTSTATE_BLOCKED; | |
968 | break; | |
0ae808e0 BK |
969 | case IBMVFC_NO_CRQ: |
970 | fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; | |
971 | break; | |
072b91f9 BK |
972 | default: |
973 | ibmvfc_log(vhost, 3, "Unknown port state: %d\n", vhost->state); | |
974 | fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; | |
975 | break; | |
976 | } | |
977 | spin_unlock_irqrestore(shost->host_lock, flags); | |
978 | } | |
979 | ||
980 | /** | |
981 | * ibmvfc_set_rport_dev_loss_tmo - Set rport's device loss timeout | |
982 | * @rport: rport struct | |
983 | * @timeout: timeout value | |
984 | * | |
985 | * Return value: | |
986 | * none | |
987 | **/ | |
988 | static void ibmvfc_set_rport_dev_loss_tmo(struct fc_rport *rport, u32 timeout) | |
989 | { | |
990 | if (timeout) | |
991 | rport->dev_loss_tmo = timeout; | |
992 | else | |
993 | rport->dev_loss_tmo = 1; | |
994 | } | |
995 | ||
b3c10489 BK |
996 | /** |
997 | * ibmvfc_release_tgt - Free memory allocated for a target | |
998 | * @kref: kref struct | |
999 | * | |
1000 | **/ | |
1001 | static void ibmvfc_release_tgt(struct kref *kref) | |
1002 | { | |
1003 | struct ibmvfc_target *tgt = container_of(kref, struct ibmvfc_target, kref); | |
1004 | kfree(tgt); | |
1005 | } | |
1006 | ||
072b91f9 BK |
1007 | /** |
1008 | * ibmvfc_get_starget_node_name - Get SCSI target's node name | |
1009 | * @starget: scsi target struct | |
1010 | * | |
1011 | * Return value: | |
1012 | * none | |
1013 | **/ | |
1014 | static void ibmvfc_get_starget_node_name(struct scsi_target *starget) | |
1015 | { | |
b3c10489 | 1016 | struct ibmvfc_target *tgt = ibmvfc_get_target(starget); |
072b91f9 | 1017 | fc_starget_port_name(starget) = tgt ? tgt->ids.node_name : 0; |
b3c10489 BK |
1018 | if (tgt) |
1019 | kref_put(&tgt->kref, ibmvfc_release_tgt); | |
072b91f9 BK |
1020 | } |
1021 | ||
1022 | /** | |
1023 | * ibmvfc_get_starget_port_name - Get SCSI target's port name | |
1024 | * @starget: scsi target struct | |
1025 | * | |
1026 | * Return value: | |
1027 | * none | |
1028 | **/ | |
1029 | static void ibmvfc_get_starget_port_name(struct scsi_target *starget) | |
1030 | { | |
b3c10489 | 1031 | struct ibmvfc_target *tgt = ibmvfc_get_target(starget); |
072b91f9 | 1032 | fc_starget_port_name(starget) = tgt ? tgt->ids.port_name : 0; |
b3c10489 BK |
1033 | if (tgt) |
1034 | kref_put(&tgt->kref, ibmvfc_release_tgt); | |
072b91f9 BK |
1035 | } |
1036 | ||
1037 | /** | |
1038 | * ibmvfc_get_starget_port_id - Get SCSI target's port ID | |
1039 | * @starget: scsi target struct | |
1040 | * | |
1041 | * Return value: | |
1042 | * none | |
1043 | **/ | |
1044 | static void ibmvfc_get_starget_port_id(struct scsi_target *starget) | |
1045 | { | |
b3c10489 | 1046 | struct ibmvfc_target *tgt = ibmvfc_get_target(starget); |
072b91f9 | 1047 | fc_starget_port_id(starget) = tgt ? tgt->scsi_id : -1; |
b3c10489 BK |
1048 | if (tgt) |
1049 | kref_put(&tgt->kref, ibmvfc_release_tgt); | |
072b91f9 BK |
1050 | } |
1051 | ||
1052 | /** | |
1053 | * ibmvfc_wait_while_resetting - Wait while the host resets | |
1054 | * @vhost: ibmvfc host struct | |
1055 | * | |
1056 | * Return value: | |
1057 | * 0 on success / other on failure | |
1058 | **/ | |
1059 | static int ibmvfc_wait_while_resetting(struct ibmvfc_host *vhost) | |
1060 | { | |
1061 | long timeout = wait_event_timeout(vhost->init_wait_q, | |
1062 | (vhost->state == IBMVFC_ACTIVE || | |
1063 | vhost->state == IBMVFC_HOST_OFFLINE || | |
1064 | vhost->state == IBMVFC_LINK_DEAD), | |
1065 | (init_timeout * HZ)); | |
1066 | ||
1067 | return timeout ? 0 : -EIO; | |
1068 | } | |
1069 | ||
1070 | /** | |
1071 | * ibmvfc_issue_fc_host_lip - Re-initiate link initialization | |
1072 | * @shost: scsi host struct | |
1073 | * | |
1074 | * Return value: | |
1075 | * 0 on success / other on failure | |
1076 | **/ | |
1077 | static int ibmvfc_issue_fc_host_lip(struct Scsi_Host *shost) | |
1078 | { | |
1079 | struct ibmvfc_host *vhost = shost_priv(shost); | |
1080 | ||
1081 | dev_err(vhost->dev, "Initiating host LIP. Resetting connection\n"); | |
1082 | ibmvfc_reset_host(vhost); | |
1083 | return ibmvfc_wait_while_resetting(vhost); | |
1084 | } | |
1085 | ||
1086 | /** | |
1087 | * ibmvfc_gather_partition_info - Gather info about the LPAR | |
1088 | * | |
1089 | * Return value: | |
1090 | * none | |
1091 | **/ | |
1092 | static void ibmvfc_gather_partition_info(struct ibmvfc_host *vhost) | |
1093 | { | |
1094 | struct device_node *rootdn; | |
1095 | const char *name; | |
1096 | const unsigned int *num; | |
1097 | ||
1098 | rootdn = of_find_node_by_path("/"); | |
1099 | if (!rootdn) | |
1100 | return; | |
1101 | ||
1102 | name = of_get_property(rootdn, "ibm,partition-name", NULL); | |
1103 | if (name) | |
1104 | strncpy(vhost->partition_name, name, sizeof(vhost->partition_name)); | |
1105 | num = of_get_property(rootdn, "ibm,partition-no", NULL); | |
1106 | if (num) | |
1107 | vhost->partition_number = *num; | |
1108 | of_node_put(rootdn); | |
1109 | } | |
1110 | ||
1111 | /** | |
1112 | * ibmvfc_set_login_info - Setup info for NPIV login | |
1113 | * @vhost: ibmvfc host struct | |
1114 | * | |
1115 | * Return value: | |
1116 | * none | |
1117 | **/ | |
1118 | static void ibmvfc_set_login_info(struct ibmvfc_host *vhost) | |
1119 | { | |
1120 | struct ibmvfc_npiv_login *login_info = &vhost->login_info; | |
1121 | struct device_node *of_node = vhost->dev->archdata.of_node; | |
1122 | const char *location; | |
1123 | ||
1124 | memset(login_info, 0, sizeof(*login_info)); | |
1125 | ||
1126 | login_info->ostype = IBMVFC_OS_LINUX; | |
1127 | login_info->max_dma_len = IBMVFC_MAX_SECTORS << 9; | |
1128 | login_info->max_payload = sizeof(struct ibmvfc_fcp_cmd_iu); | |
1129 | login_info->max_response = sizeof(struct ibmvfc_fcp_rsp); | |
1130 | login_info->partition_num = vhost->partition_number; | |
1131 | login_info->vfc_frame_version = 1; | |
1132 | login_info->fcp_version = 3; | |
1133 | if (vhost->client_migrated) | |
1134 | login_info->flags = IBMVFC_CLIENT_MIGRATED; | |
1135 | ||
1136 | login_info->max_cmds = max_requests + IBMVFC_NUM_INTERNAL_REQ; | |
1137 | login_info->capabilities = IBMVFC_CAN_MIGRATE; | |
1138 | login_info->async.va = vhost->async_crq.msg_token; | |
1139 | login_info->async.len = vhost->async_crq.size; | |
1140 | strncpy(login_info->partition_name, vhost->partition_name, IBMVFC_MAX_NAME); | |
1141 | strncpy(login_info->device_name, | |
1142 | vhost->host->shost_gendev.bus_id, IBMVFC_MAX_NAME); | |
1143 | ||
1144 | location = of_get_property(of_node, "ibm,loc-code", NULL); | |
1145 | location = location ? location : vhost->dev->bus_id; | |
1146 | strncpy(login_info->drc_name, location, IBMVFC_MAX_NAME); | |
1147 | } | |
1148 | ||
1149 | /** | |
1150 | * ibmvfc_init_event_pool - Allocates and initializes the event pool for a host | |
1151 | * @vhost: ibmvfc host who owns the event pool | |
1152 | * | |
1153 | * Returns zero on success. | |
1154 | **/ | |
1155 | static int ibmvfc_init_event_pool(struct ibmvfc_host *vhost) | |
1156 | { | |
1157 | int i; | |
1158 | struct ibmvfc_event_pool *pool = &vhost->pool; | |
1159 | ||
1160 | ENTER; | |
1161 | pool->size = max_requests + IBMVFC_NUM_INTERNAL_REQ; | |
1162 | pool->events = kcalloc(pool->size, sizeof(*pool->events), GFP_KERNEL); | |
1163 | if (!pool->events) | |
1164 | return -ENOMEM; | |
1165 | ||
1166 | pool->iu_storage = dma_alloc_coherent(vhost->dev, | |
1167 | pool->size * sizeof(*pool->iu_storage), | |
1168 | &pool->iu_token, 0); | |
1169 | ||
1170 | if (!pool->iu_storage) { | |
1171 | kfree(pool->events); | |
1172 | return -ENOMEM; | |
1173 | } | |
1174 | ||
1175 | for (i = 0; i < pool->size; ++i) { | |
1176 | struct ibmvfc_event *evt = &pool->events[i]; | |
1177 | atomic_set(&evt->free, 1); | |
1178 | evt->crq.valid = 0x80; | |
1179 | evt->crq.ioba = pool->iu_token + (sizeof(*evt->xfer_iu) * i); | |
1180 | evt->xfer_iu = pool->iu_storage + i; | |
1181 | evt->vhost = vhost; | |
1182 | evt->ext_list = NULL; | |
1183 | list_add_tail(&evt->queue, &vhost->free); | |
1184 | } | |
1185 | ||
1186 | LEAVE; | |
1187 | return 0; | |
1188 | } | |
1189 | ||
1190 | /** | |
1191 | * ibmvfc_free_event_pool - Frees memory of the event pool of a host | |
1192 | * @vhost: ibmvfc host who owns the event pool | |
1193 | * | |
1194 | **/ | |
1195 | static void ibmvfc_free_event_pool(struct ibmvfc_host *vhost) | |
1196 | { | |
1197 | int i; | |
1198 | struct ibmvfc_event_pool *pool = &vhost->pool; | |
1199 | ||
1200 | ENTER; | |
1201 | for (i = 0; i < pool->size; ++i) { | |
1202 | list_del(&pool->events[i].queue); | |
1203 | BUG_ON(atomic_read(&pool->events[i].free) != 1); | |
1204 | if (pool->events[i].ext_list) | |
1205 | dma_pool_free(vhost->sg_pool, | |
1206 | pool->events[i].ext_list, | |
1207 | pool->events[i].ext_list_token); | |
1208 | } | |
1209 | ||
1210 | kfree(pool->events); | |
1211 | dma_free_coherent(vhost->dev, | |
1212 | pool->size * sizeof(*pool->iu_storage), | |
1213 | pool->iu_storage, pool->iu_token); | |
1214 | LEAVE; | |
1215 | } | |
1216 | ||
1217 | /** | |
1218 | * ibmvfc_get_event - Gets the next free event in pool | |
1219 | * @vhost: ibmvfc host struct | |
1220 | * | |
1221 | * Returns a free event from the pool. | |
1222 | **/ | |
1223 | static struct ibmvfc_event *ibmvfc_get_event(struct ibmvfc_host *vhost) | |
1224 | { | |
1225 | struct ibmvfc_event *evt; | |
1226 | ||
1227 | BUG_ON(list_empty(&vhost->free)); | |
1228 | evt = list_entry(vhost->free.next, struct ibmvfc_event, queue); | |
1229 | atomic_set(&evt->free, 0); | |
1230 | list_del(&evt->queue); | |
1231 | return evt; | |
1232 | } | |
1233 | ||
1234 | /** | |
1235 | * ibmvfc_init_event - Initialize fields in an event struct that are always | |
1236 | * required. | |
1237 | * @evt: The event | |
1238 | * @done: Routine to call when the event is responded to | |
1239 | * @format: SRP or MAD format | |
1240 | **/ | |
1241 | static void ibmvfc_init_event(struct ibmvfc_event *evt, | |
1242 | void (*done) (struct ibmvfc_event *), u8 format) | |
1243 | { | |
1244 | evt->cmnd = NULL; | |
1245 | evt->sync_iu = NULL; | |
1246 | evt->crq.format = format; | |
1247 | evt->done = done; | |
1248 | } | |
1249 | ||
1250 | /** | |
1251 | * ibmvfc_map_sg_list - Initialize scatterlist | |
1252 | * @scmd: scsi command struct | |
1253 | * @nseg: number of scatterlist segments | |
1254 | * @md: memory descriptor list to initialize | |
1255 | **/ | |
1256 | static void ibmvfc_map_sg_list(struct scsi_cmnd *scmd, int nseg, | |
1257 | struct srp_direct_buf *md) | |
1258 | { | |
1259 | int i; | |
1260 | struct scatterlist *sg; | |
1261 | ||
1262 | scsi_for_each_sg(scmd, sg, nseg, i) { | |
1263 | md[i].va = sg_dma_address(sg); | |
1264 | md[i].len = sg_dma_len(sg); | |
1265 | md[i].key = 0; | |
1266 | } | |
1267 | } | |
1268 | ||
1269 | /** | |
1270 | * ibmvfc_map_sg_data - Maps dma for a scatterlist and initializes decriptor fields | |
1271 | * @scmd: Scsi_Cmnd with the scatterlist | |
1272 | * @evt: ibmvfc event struct | |
1273 | * @vfc_cmd: vfc_cmd that contains the memory descriptor | |
1274 | * @dev: device for which to map dma memory | |
1275 | * | |
1276 | * Returns: | |
1277 | * 0 on success / non-zero on failure | |
1278 | **/ | |
1279 | static int ibmvfc_map_sg_data(struct scsi_cmnd *scmd, | |
1280 | struct ibmvfc_event *evt, | |
1281 | struct ibmvfc_cmd *vfc_cmd, struct device *dev) | |
1282 | { | |
1283 | ||
1284 | int sg_mapped; | |
1285 | struct srp_direct_buf *data = &vfc_cmd->ioba; | |
1286 | struct ibmvfc_host *vhost = dev_get_drvdata(dev); | |
1287 | ||
1288 | sg_mapped = scsi_dma_map(scmd); | |
1289 | if (!sg_mapped) { | |
1290 | vfc_cmd->flags |= IBMVFC_NO_MEM_DESC; | |
1291 | return 0; | |
1292 | } else if (unlikely(sg_mapped < 0)) { | |
1293 | if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL) | |
1294 | scmd_printk(KERN_ERR, scmd, "Failed to map DMA buffer for command\n"); | |
1295 | return sg_mapped; | |
1296 | } | |
1297 | ||
1298 | if (scmd->sc_data_direction == DMA_TO_DEVICE) { | |
1299 | vfc_cmd->flags |= IBMVFC_WRITE; | |
1300 | vfc_cmd->iu.add_cdb_len |= IBMVFC_WRDATA; | |
1301 | } else { | |
1302 | vfc_cmd->flags |= IBMVFC_READ; | |
1303 | vfc_cmd->iu.add_cdb_len |= IBMVFC_RDDATA; | |
1304 | } | |
1305 | ||
1306 | if (sg_mapped == 1) { | |
1307 | ibmvfc_map_sg_list(scmd, sg_mapped, data); | |
1308 | return 0; | |
1309 | } | |
1310 | ||
1311 | vfc_cmd->flags |= IBMVFC_SCATTERLIST; | |
1312 | ||
1313 | if (!evt->ext_list) { | |
1314 | evt->ext_list = dma_pool_alloc(vhost->sg_pool, GFP_ATOMIC, | |
1315 | &evt->ext_list_token); | |
1316 | ||
1317 | if (!evt->ext_list) { | |
1318 | scmd_printk(KERN_ERR, scmd, "Can't allocate memory for scatterlist\n"); | |
1319 | return -ENOMEM; | |
1320 | } | |
1321 | } | |
1322 | ||
1323 | ibmvfc_map_sg_list(scmd, sg_mapped, evt->ext_list); | |
1324 | ||
1325 | data->va = evt->ext_list_token; | |
1326 | data->len = sg_mapped * sizeof(struct srp_direct_buf); | |
1327 | data->key = 0; | |
1328 | return 0; | |
1329 | } | |
1330 | ||
1331 | /** | |
1332 | * ibmvfc_timeout - Internal command timeout handler | |
1333 | * @evt: struct ibmvfc_event that timed out | |
1334 | * | |
1335 | * Called when an internally generated command times out | |
1336 | **/ | |
1337 | static void ibmvfc_timeout(struct ibmvfc_event *evt) | |
1338 | { | |
1339 | struct ibmvfc_host *vhost = evt->vhost; | |
1340 | dev_err(vhost->dev, "Command timed out (%p). Resetting connection\n", evt); | |
1341 | ibmvfc_reset_host(vhost); | |
1342 | } | |
1343 | ||
1344 | /** | |
1345 | * ibmvfc_send_event - Transforms event to u64 array and calls send_crq() | |
1346 | * @evt: event to be sent | |
1347 | * @vhost: ibmvfc host struct | |
1348 | * @timeout: timeout in seconds - 0 means do not time command | |
1349 | * | |
1350 | * Returns the value returned from ibmvfc_send_crq(). (Zero for success) | |
1351 | **/ | |
1352 | static int ibmvfc_send_event(struct ibmvfc_event *evt, | |
1353 | struct ibmvfc_host *vhost, unsigned long timeout) | |
1354 | { | |
1355 | u64 *crq_as_u64 = (u64 *) &evt->crq; | |
1356 | int rc; | |
1357 | ||
1358 | /* Copy the IU into the transfer area */ | |
1359 | *evt->xfer_iu = evt->iu; | |
1360 | if (evt->crq.format == IBMVFC_CMD_FORMAT) | |
1361 | evt->xfer_iu->cmd.tag = (u64)evt; | |
1362 | else if (evt->crq.format == IBMVFC_MAD_FORMAT) | |
1363 | evt->xfer_iu->mad_common.tag = (u64)evt; | |
1364 | else | |
1365 | BUG(); | |
1366 | ||
1367 | list_add_tail(&evt->queue, &vhost->sent); | |
1368 | init_timer(&evt->timer); | |
1369 | ||
1370 | if (timeout) { | |
1371 | evt->timer.data = (unsigned long) evt; | |
1372 | evt->timer.expires = jiffies + (timeout * HZ); | |
1373 | evt->timer.function = (void (*)(unsigned long))ibmvfc_timeout; | |
1374 | add_timer(&evt->timer); | |
1375 | } | |
1376 | ||
1377 | if ((rc = ibmvfc_send_crq(vhost, crq_as_u64[0], crq_as_u64[1]))) { | |
1378 | list_del(&evt->queue); | |
1379 | del_timer(&evt->timer); | |
1380 | ||
1381 | /* If send_crq returns H_CLOSED, return SCSI_MLQUEUE_HOST_BUSY. | |
1382 | * Firmware will send a CRQ with a transport event (0xFF) to | |
1383 | * tell this client what has happened to the transport. This | |
1384 | * will be handled in ibmvfc_handle_crq() | |
1385 | */ | |
1386 | if (rc == H_CLOSED) { | |
1387 | if (printk_ratelimit()) | |
1388 | dev_warn(vhost->dev, "Send warning. Receive queue closed, will retry.\n"); | |
1389 | if (evt->cmnd) | |
1390 | scsi_dma_unmap(evt->cmnd); | |
1391 | ibmvfc_free_event(evt); | |
1392 | return SCSI_MLQUEUE_HOST_BUSY; | |
1393 | } | |
1394 | ||
1395 | dev_err(vhost->dev, "Send error (rc=%d)\n", rc); | |
1396 | if (evt->cmnd) { | |
1397 | evt->cmnd->result = DID_ERROR << 16; | |
1398 | evt->done = ibmvfc_scsi_eh_done; | |
1399 | } else | |
1400 | evt->xfer_iu->mad_common.status = IBMVFC_MAD_CRQ_ERROR; | |
1401 | ||
1402 | evt->done(evt); | |
1403 | } else | |
1404 | ibmvfc_trc_start(evt); | |
1405 | ||
1406 | return 0; | |
1407 | } | |
1408 | ||
1409 | /** | |
1410 | * ibmvfc_log_error - Log an error for the failed command if appropriate | |
1411 | * @evt: ibmvfc event to log | |
1412 | * | |
1413 | **/ | |
1414 | static void ibmvfc_log_error(struct ibmvfc_event *evt) | |
1415 | { | |
1416 | struct ibmvfc_cmd *vfc_cmd = &evt->xfer_iu->cmd; | |
1417 | struct ibmvfc_host *vhost = evt->vhost; | |
1418 | struct ibmvfc_fcp_rsp *rsp = &vfc_cmd->rsp; | |
1419 | struct scsi_cmnd *cmnd = evt->cmnd; | |
1420 | const char *err = unknown_error; | |
1421 | int index = ibmvfc_get_err_index(vfc_cmd->status, vfc_cmd->error); | |
1422 | int logerr = 0; | |
1423 | int rsp_code = 0; | |
1424 | ||
1425 | if (index >= 0) { | |
1426 | logerr = cmd_status[index].log; | |
1427 | err = cmd_status[index].name; | |
1428 | } | |
1429 | ||
0ae808e0 | 1430 | if (!logerr && (vhost->log_level <= (IBMVFC_DEFAULT_LOG_LEVEL + 1))) |
072b91f9 BK |
1431 | return; |
1432 | ||
1433 | if (rsp->flags & FCP_RSP_LEN_VALID) | |
1434 | rsp_code = rsp->data.info.rsp_code; | |
1435 | ||
1436 | scmd_printk(KERN_ERR, cmnd, "Command (%02X) failed: %s (%x:%x) " | |
1437 | "flags: %x fcp_rsp: %x, resid=%d, scsi_status: %x\n", | |
1438 | cmnd->cmnd[0], err, vfc_cmd->status, vfc_cmd->error, | |
1439 | rsp->flags, rsp_code, scsi_get_resid(cmnd), rsp->scsi_status); | |
1440 | } | |
1441 | ||
1442 | /** | |
1443 | * ibmvfc_scsi_done - Handle responses from commands | |
1444 | * @evt: ibmvfc event to be handled | |
1445 | * | |
1446 | * Used as a callback when sending scsi cmds. | |
1447 | **/ | |
1448 | static void ibmvfc_scsi_done(struct ibmvfc_event *evt) | |
1449 | { | |
1450 | struct ibmvfc_cmd *vfc_cmd = &evt->xfer_iu->cmd; | |
1451 | struct ibmvfc_fcp_rsp *rsp = &vfc_cmd->rsp; | |
1452 | struct scsi_cmnd *cmnd = evt->cmnd; | |
1453 | int rsp_len = 0; | |
1454 | int sense_len = rsp->fcp_sense_len; | |
1455 | ||
1456 | if (cmnd) { | |
1457 | if (vfc_cmd->response_flags & IBMVFC_ADAPTER_RESID_VALID) | |
1458 | scsi_set_resid(cmnd, vfc_cmd->adapter_resid); | |
1459 | else if (rsp->flags & FCP_RESID_UNDER) | |
1460 | scsi_set_resid(cmnd, rsp->fcp_resid); | |
1461 | else | |
1462 | scsi_set_resid(cmnd, 0); | |
1463 | ||
1464 | if (vfc_cmd->status) { | |
1465 | cmnd->result = ibmvfc_get_err_result(vfc_cmd); | |
1466 | ||
1467 | if (rsp->flags & FCP_RSP_LEN_VALID) | |
1468 | rsp_len = rsp->fcp_rsp_len; | |
1469 | if ((sense_len + rsp_len) > SCSI_SENSE_BUFFERSIZE) | |
1470 | sense_len = SCSI_SENSE_BUFFERSIZE - rsp_len; | |
1471 | if ((rsp->flags & FCP_SNS_LEN_VALID) && rsp->fcp_sense_len) | |
1472 | memcpy(cmnd->sense_buffer, rsp->data.sense + rsp_len, sense_len); | |
1473 | ||
1474 | ibmvfc_log_error(evt); | |
1475 | } | |
1476 | ||
1477 | if (!cmnd->result && | |
1478 | (scsi_bufflen(cmnd) - scsi_get_resid(cmnd) < cmnd->underflow)) | |
1479 | cmnd->result = (DID_ERROR << 16); | |
1480 | ||
1481 | scsi_dma_unmap(cmnd); | |
1482 | cmnd->scsi_done(cmnd); | |
1483 | } | |
1484 | ||
1485 | ibmvfc_free_event(evt); | |
1486 | } | |
1487 | ||
1488 | /** | |
1489 | * ibmvfc_host_chkready - Check if the host can accept commands | |
1490 | * @vhost: struct ibmvfc host | |
1491 | * | |
1492 | * Returns: | |
1493 | * 1 if host can accept command / 0 if not | |
1494 | **/ | |
1495 | static inline int ibmvfc_host_chkready(struct ibmvfc_host *vhost) | |
1496 | { | |
1497 | int result = 0; | |
1498 | ||
1499 | switch (vhost->state) { | |
1500 | case IBMVFC_LINK_DEAD: | |
1501 | case IBMVFC_HOST_OFFLINE: | |
1502 | result = DID_NO_CONNECT << 16; | |
1503 | break; | |
1504 | case IBMVFC_NO_CRQ: | |
1505 | case IBMVFC_INITIALIZING: | |
1506 | case IBMVFC_HALTED: | |
1507 | case IBMVFC_LINK_DOWN: | |
1508 | result = DID_REQUEUE << 16; | |
1509 | break; | |
1510 | case IBMVFC_ACTIVE: | |
1511 | result = 0; | |
1512 | break; | |
1513 | }; | |
1514 | ||
1515 | return result; | |
1516 | } | |
1517 | ||
1518 | /** | |
1519 | * ibmvfc_queuecommand - The queuecommand function of the scsi template | |
1520 | * @cmnd: struct scsi_cmnd to be executed | |
1521 | * @done: Callback function to be called when cmnd is completed | |
1522 | * | |
1523 | * Returns: | |
1524 | * 0 on success / other on failure | |
1525 | **/ | |
1526 | static int ibmvfc_queuecommand(struct scsi_cmnd *cmnd, | |
1527 | void (*done) (struct scsi_cmnd *)) | |
1528 | { | |
1529 | struct ibmvfc_host *vhost = shost_priv(cmnd->device->host); | |
1530 | struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); | |
1531 | struct ibmvfc_cmd *vfc_cmd; | |
1532 | struct ibmvfc_event *evt; | |
1533 | u8 tag[2]; | |
1534 | int rc; | |
1535 | ||
1536 | if (unlikely((rc = fc_remote_port_chkready(rport))) || | |
1537 | unlikely((rc = ibmvfc_host_chkready(vhost)))) { | |
1538 | cmnd->result = rc; | |
1539 | done(cmnd); | |
1540 | return 0; | |
1541 | } | |
1542 | ||
1543 | cmnd->result = (DID_OK << 16); | |
1544 | evt = ibmvfc_get_event(vhost); | |
1545 | ibmvfc_init_event(evt, ibmvfc_scsi_done, IBMVFC_CMD_FORMAT); | |
1546 | evt->cmnd = cmnd; | |
1547 | cmnd->scsi_done = done; | |
1548 | vfc_cmd = &evt->iu.cmd; | |
1549 | memset(vfc_cmd, 0, sizeof(*vfc_cmd)); | |
1550 | vfc_cmd->resp.va = (u64)evt->crq.ioba + offsetof(struct ibmvfc_cmd, rsp); | |
1551 | vfc_cmd->resp.len = sizeof(vfc_cmd->rsp); | |
1552 | vfc_cmd->frame_type = IBMVFC_SCSI_FCP_TYPE; | |
1553 | vfc_cmd->payload_len = sizeof(vfc_cmd->iu); | |
1554 | vfc_cmd->resp_len = sizeof(vfc_cmd->rsp); | |
1555 | vfc_cmd->cancel_key = (unsigned long)cmnd->device->hostdata; | |
1556 | vfc_cmd->tgt_scsi_id = rport->port_id; | |
1557 | if ((rport->supported_classes & FC_COS_CLASS3) && | |
1558 | (fc_host_supported_classes(vhost->host) & FC_COS_CLASS3)) | |
1559 | vfc_cmd->flags = IBMVFC_CLASS_3_ERR; | |
1560 | vfc_cmd->iu.xfer_len = scsi_bufflen(cmnd); | |
1561 | int_to_scsilun(cmnd->device->lun, &vfc_cmd->iu.lun); | |
1562 | memcpy(vfc_cmd->iu.cdb, cmnd->cmnd, cmnd->cmd_len); | |
1563 | ||
1564 | if (scsi_populate_tag_msg(cmnd, tag)) { | |
1565 | vfc_cmd->task_tag = tag[1]; | |
1566 | switch (tag[0]) { | |
1567 | case MSG_SIMPLE_TAG: | |
1568 | vfc_cmd->iu.pri_task_attr = IBMVFC_SIMPLE_TASK; | |
1569 | break; | |
1570 | case MSG_HEAD_TAG: | |
1571 | vfc_cmd->iu.pri_task_attr = IBMVFC_HEAD_OF_QUEUE; | |
1572 | break; | |
1573 | case MSG_ORDERED_TAG: | |
1574 | vfc_cmd->iu.pri_task_attr = IBMVFC_ORDERED_TASK; | |
1575 | break; | |
1576 | }; | |
1577 | } | |
1578 | ||
1579 | if (likely(!(rc = ibmvfc_map_sg_data(cmnd, evt, vfc_cmd, vhost->dev)))) | |
1580 | return ibmvfc_send_event(evt, vhost, 0); | |
1581 | ||
1582 | ibmvfc_free_event(evt); | |
1583 | if (rc == -ENOMEM) | |
1584 | return SCSI_MLQUEUE_HOST_BUSY; | |
1585 | ||
1586 | if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL) | |
1587 | scmd_printk(KERN_ERR, cmnd, | |
1588 | "Failed to map DMA buffer for command. rc=%d\n", rc); | |
1589 | ||
1590 | cmnd->result = DID_ERROR << 16; | |
1591 | done(cmnd); | |
1592 | return 0; | |
1593 | } | |
1594 | ||
1595 | /** | |
1596 | * ibmvfc_sync_completion - Signal that a synchronous command has completed | |
1597 | * @evt: ibmvfc event struct | |
1598 | * | |
1599 | **/ | |
1600 | static void ibmvfc_sync_completion(struct ibmvfc_event *evt) | |
1601 | { | |
1602 | /* copy the response back */ | |
1603 | if (evt->sync_iu) | |
1604 | *evt->sync_iu = *evt->xfer_iu; | |
1605 | ||
1606 | complete(&evt->comp); | |
1607 | } | |
1608 | ||
1609 | /** | |
1610 | * ibmvfc_reset_device - Reset the device with the specified reset type | |
1611 | * @sdev: scsi device to reset | |
1612 | * @type: reset type | |
1613 | * @desc: reset type description for log messages | |
1614 | * | |
1615 | * Returns: | |
1616 | * 0 on success / other on failure | |
1617 | **/ | |
1618 | static int ibmvfc_reset_device(struct scsi_device *sdev, int type, char *desc) | |
1619 | { | |
1620 | struct ibmvfc_host *vhost = shost_priv(sdev->host); | |
1621 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); | |
1622 | struct ibmvfc_cmd *tmf; | |
1623 | struct ibmvfc_event *evt; | |
1624 | union ibmvfc_iu rsp_iu; | |
1625 | struct ibmvfc_fcp_rsp *fc_rsp = &rsp_iu.cmd.rsp; | |
1626 | int rsp_rc = -EBUSY; | |
1627 | unsigned long flags; | |
1628 | int rsp_code = 0; | |
1629 | ||
1630 | spin_lock_irqsave(vhost->host->host_lock, flags); | |
1631 | if (vhost->state == IBMVFC_ACTIVE) { | |
1632 | evt = ibmvfc_get_event(vhost); | |
1633 | ibmvfc_init_event(evt, ibmvfc_sync_completion, IBMVFC_CMD_FORMAT); | |
1634 | ||
1635 | tmf = &evt->iu.cmd; | |
1636 | memset(tmf, 0, sizeof(*tmf)); | |
1637 | tmf->resp.va = (u64)evt->crq.ioba + offsetof(struct ibmvfc_cmd, rsp); | |
1638 | tmf->resp.len = sizeof(tmf->rsp); | |
1639 | tmf->frame_type = IBMVFC_SCSI_FCP_TYPE; | |
1640 | tmf->payload_len = sizeof(tmf->iu); | |
1641 | tmf->resp_len = sizeof(tmf->rsp); | |
1642 | tmf->cancel_key = (unsigned long)sdev->hostdata; | |
1643 | tmf->tgt_scsi_id = rport->port_id; | |
1644 | int_to_scsilun(sdev->lun, &tmf->iu.lun); | |
1645 | tmf->flags = (IBMVFC_NO_MEM_DESC | IBMVFC_TMF); | |
1646 | tmf->iu.tmf_flags = type; | |
1647 | evt->sync_iu = &rsp_iu; | |
1648 | ||
1649 | init_completion(&evt->comp); | |
1650 | rsp_rc = ibmvfc_send_event(evt, vhost, default_timeout); | |
1651 | } | |
1652 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
1653 | ||
1654 | if (rsp_rc != 0) { | |
1655 | sdev_printk(KERN_ERR, sdev, "Failed to send %s reset event. rc=%d\n", | |
1656 | desc, rsp_rc); | |
1657 | return -EIO; | |
1658 | } | |
1659 | ||
1660 | sdev_printk(KERN_INFO, sdev, "Resetting %s\n", desc); | |
1661 | wait_for_completion(&evt->comp); | |
1662 | ||
1663 | if (rsp_iu.cmd.status) { | |
1664 | if (fc_rsp->flags & FCP_RSP_LEN_VALID) | |
1665 | rsp_code = fc_rsp->data.info.rsp_code; | |
1666 | ||
1667 | sdev_printk(KERN_ERR, sdev, "%s reset failed: %s (%x:%x) " | |
1668 | "flags: %x fcp_rsp: %x, scsi_status: %x\n", | |
1669 | desc, ibmvfc_get_cmd_error(rsp_iu.cmd.status, rsp_iu.cmd.error), | |
1670 | rsp_iu.cmd.status, rsp_iu.cmd.error, fc_rsp->flags, rsp_code, | |
1671 | fc_rsp->scsi_status); | |
1672 | rsp_rc = -EIO; | |
1673 | } else | |
1674 | sdev_printk(KERN_INFO, sdev, "%s reset successful\n", desc); | |
1675 | ||
1676 | spin_lock_irqsave(vhost->host->host_lock, flags); | |
1677 | ibmvfc_free_event(evt); | |
1678 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
1679 | return rsp_rc; | |
1680 | } | |
1681 | ||
1682 | /** | |
1683 | * ibmvfc_abort_task_set - Abort outstanding commands to the device | |
1684 | * @sdev: scsi device to abort commands | |
1685 | * | |
1686 | * This sends an Abort Task Set to the VIOS for the specified device. This does | |
1687 | * NOT send any cancel to the VIOS. That must be done separately. | |
1688 | * | |
1689 | * Returns: | |
1690 | * 0 on success / other on failure | |
1691 | **/ | |
1692 | static int ibmvfc_abort_task_set(struct scsi_device *sdev) | |
1693 | { | |
1694 | struct ibmvfc_host *vhost = shost_priv(sdev->host); | |
1695 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); | |
1696 | struct ibmvfc_cmd *tmf; | |
1697 | struct ibmvfc_event *evt, *found_evt; | |
1698 | union ibmvfc_iu rsp_iu; | |
1699 | struct ibmvfc_fcp_rsp *fc_rsp = &rsp_iu.cmd.rsp; | |
1700 | int rsp_rc = -EBUSY; | |
1701 | unsigned long flags; | |
1702 | int rsp_code = 0; | |
1703 | ||
1704 | spin_lock_irqsave(vhost->host->host_lock, flags); | |
1705 | found_evt = NULL; | |
1706 | list_for_each_entry(evt, &vhost->sent, queue) { | |
1707 | if (evt->cmnd && evt->cmnd->device == sdev) { | |
1708 | found_evt = evt; | |
1709 | break; | |
1710 | } | |
1711 | } | |
1712 | ||
1713 | if (!found_evt) { | |
1714 | if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL) | |
1715 | sdev_printk(KERN_INFO, sdev, "No events found to abort\n"); | |
1716 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
1717 | return 0; | |
1718 | } | |
1719 | ||
1720 | if (vhost->state == IBMVFC_ACTIVE) { | |
1721 | evt = ibmvfc_get_event(vhost); | |
1722 | ibmvfc_init_event(evt, ibmvfc_sync_completion, IBMVFC_CMD_FORMAT); | |
1723 | ||
1724 | tmf = &evt->iu.cmd; | |
1725 | memset(tmf, 0, sizeof(*tmf)); | |
1726 | tmf->resp.va = (u64)evt->crq.ioba + offsetof(struct ibmvfc_cmd, rsp); | |
1727 | tmf->resp.len = sizeof(tmf->rsp); | |
1728 | tmf->frame_type = IBMVFC_SCSI_FCP_TYPE; | |
1729 | tmf->payload_len = sizeof(tmf->iu); | |
1730 | tmf->resp_len = sizeof(tmf->rsp); | |
1731 | tmf->cancel_key = (unsigned long)sdev->hostdata; | |
1732 | tmf->tgt_scsi_id = rport->port_id; | |
1733 | int_to_scsilun(sdev->lun, &tmf->iu.lun); | |
1734 | tmf->flags = (IBMVFC_NO_MEM_DESC | IBMVFC_TMF); | |
1735 | tmf->iu.tmf_flags = IBMVFC_ABORT_TASK_SET; | |
1736 | evt->sync_iu = &rsp_iu; | |
1737 | ||
1738 | init_completion(&evt->comp); | |
1739 | rsp_rc = ibmvfc_send_event(evt, vhost, default_timeout); | |
1740 | } | |
1741 | ||
1742 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
1743 | ||
1744 | if (rsp_rc != 0) { | |
1745 | sdev_printk(KERN_ERR, sdev, "Failed to send abort. rc=%d\n", rsp_rc); | |
1746 | return -EIO; | |
1747 | } | |
1748 | ||
1749 | sdev_printk(KERN_INFO, sdev, "Aborting outstanding commands\n"); | |
1750 | wait_for_completion(&evt->comp); | |
1751 | ||
1752 | if (rsp_iu.cmd.status) { | |
1753 | if (fc_rsp->flags & FCP_RSP_LEN_VALID) | |
1754 | rsp_code = fc_rsp->data.info.rsp_code; | |
1755 | ||
1756 | sdev_printk(KERN_ERR, sdev, "Abort failed: %s (%x:%x) " | |
1757 | "flags: %x fcp_rsp: %x, scsi_status: %x\n", | |
1758 | ibmvfc_get_cmd_error(rsp_iu.cmd.status, rsp_iu.cmd.error), | |
1759 | rsp_iu.cmd.status, rsp_iu.cmd.error, fc_rsp->flags, rsp_code, | |
1760 | fc_rsp->scsi_status); | |
1761 | rsp_rc = -EIO; | |
1762 | } else | |
1763 | sdev_printk(KERN_INFO, sdev, "Abort successful\n"); | |
1764 | ||
1765 | spin_lock_irqsave(vhost->host->host_lock, flags); | |
1766 | ibmvfc_free_event(evt); | |
1767 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
1768 | return rsp_rc; | |
1769 | } | |
1770 | ||
1771 | /** | |
1772 | * ibmvfc_cancel_all - Cancel all outstanding commands to the device | |
1773 | * @sdev: scsi device to cancel commands | |
1774 | * @type: type of error recovery being performed | |
1775 | * | |
1776 | * This sends a cancel to the VIOS for the specified device. This does | |
1777 | * NOT send any abort to the actual device. That must be done separately. | |
1778 | * | |
1779 | * Returns: | |
1780 | * 0 on success / other on failure | |
1781 | **/ | |
1782 | static int ibmvfc_cancel_all(struct scsi_device *sdev, int type) | |
1783 | { | |
1784 | struct ibmvfc_host *vhost = shost_priv(sdev->host); | |
1785 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); | |
1786 | struct ibmvfc_tmf *tmf; | |
1787 | struct ibmvfc_event *evt, *found_evt; | |
1788 | union ibmvfc_iu rsp; | |
1789 | int rsp_rc = -EBUSY; | |
1790 | unsigned long flags; | |
1791 | u16 status; | |
1792 | ||
1793 | ENTER; | |
1794 | spin_lock_irqsave(vhost->host->host_lock, flags); | |
1795 | found_evt = NULL; | |
1796 | list_for_each_entry(evt, &vhost->sent, queue) { | |
1797 | if (evt->cmnd && evt->cmnd->device == sdev) { | |
1798 | found_evt = evt; | |
1799 | break; | |
1800 | } | |
1801 | } | |
1802 | ||
1803 | if (!found_evt) { | |
1804 | if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL) | |
1805 | sdev_printk(KERN_INFO, sdev, "No events found to cancel\n"); | |
1806 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
1807 | return 0; | |
1808 | } | |
1809 | ||
1810 | if (vhost->state == IBMVFC_ACTIVE) { | |
1811 | evt = ibmvfc_get_event(vhost); | |
1812 | ibmvfc_init_event(evt, ibmvfc_sync_completion, IBMVFC_MAD_FORMAT); | |
1813 | ||
1814 | tmf = &evt->iu.tmf; | |
1815 | memset(tmf, 0, sizeof(*tmf)); | |
1816 | tmf->common.version = 1; | |
1817 | tmf->common.opcode = IBMVFC_TMF_MAD; | |
1818 | tmf->common.length = sizeof(*tmf); | |
1819 | tmf->scsi_id = rport->port_id; | |
1820 | int_to_scsilun(sdev->lun, &tmf->lun); | |
1821 | tmf->flags = (type | IBMVFC_TMF_LUA_VALID); | |
1822 | tmf->cancel_key = (unsigned long)sdev->hostdata; | |
1823 | tmf->my_cancel_key = (IBMVFC_TMF_CANCEL_KEY | (unsigned long)sdev->hostdata); | |
1824 | ||
1825 | evt->sync_iu = &rsp; | |
1826 | init_completion(&evt->comp); | |
1827 | rsp_rc = ibmvfc_send_event(evt, vhost, default_timeout); | |
1828 | } | |
1829 | ||
1830 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
1831 | ||
1832 | if (rsp_rc != 0) { | |
1833 | sdev_printk(KERN_ERR, sdev, "Failed to send cancel event. rc=%d\n", rsp_rc); | |
1834 | return -EIO; | |
1835 | } | |
1836 | ||
1837 | sdev_printk(KERN_INFO, sdev, "Cancelling outstanding commands.\n"); | |
1838 | ||
1839 | wait_for_completion(&evt->comp); | |
1840 | status = rsp.mad_common.status; | |
1841 | spin_lock_irqsave(vhost->host->host_lock, flags); | |
1842 | ibmvfc_free_event(evt); | |
1843 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
1844 | ||
1845 | if (status != IBMVFC_MAD_SUCCESS) { | |
1846 | sdev_printk(KERN_WARNING, sdev, "Cancel failed with rc=%x\n", status); | |
1847 | return -EIO; | |
1848 | } | |
1849 | ||
1850 | sdev_printk(KERN_INFO, sdev, "Successfully cancelled outstanding commands\n"); | |
1851 | return 0; | |
1852 | } | |
1853 | ||
1854 | /** | |
1855 | * ibmvfc_eh_abort_handler - Abort a command | |
1856 | * @cmd: scsi command to abort | |
1857 | * | |
1858 | * Returns: | |
1859 | * SUCCESS / FAILED | |
1860 | **/ | |
1861 | static int ibmvfc_eh_abort_handler(struct scsi_cmnd *cmd) | |
1862 | { | |
1863 | struct ibmvfc_host *vhost = shost_priv(cmd->device->host); | |
1864 | struct ibmvfc_event *evt, *pos; | |
1865 | int cancel_rc, abort_rc; | |
1866 | unsigned long flags; | |
1867 | ||
1868 | ENTER; | |
1869 | ibmvfc_wait_while_resetting(vhost); | |
1870 | cancel_rc = ibmvfc_cancel_all(cmd->device, IBMVFC_TMF_ABORT_TASK_SET); | |
1871 | abort_rc = ibmvfc_abort_task_set(cmd->device); | |
1872 | ||
1873 | if (!cancel_rc && !abort_rc) { | |
1874 | spin_lock_irqsave(vhost->host->host_lock, flags); | |
1875 | list_for_each_entry_safe(evt, pos, &vhost->sent, queue) { | |
1876 | if (evt->cmnd && evt->cmnd->device == cmd->device) | |
1877 | ibmvfc_fail_request(evt, DID_ABORT); | |
1878 | } | |
1879 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
1880 | LEAVE; | |
1881 | return SUCCESS; | |
1882 | } | |
1883 | ||
1884 | LEAVE; | |
1885 | return FAILED; | |
1886 | } | |
1887 | ||
1888 | /** | |
1889 | * ibmvfc_eh_device_reset_handler - Reset a single LUN | |
1890 | * @cmd: scsi command struct | |
1891 | * | |
1892 | * Returns: | |
1893 | * SUCCESS / FAILED | |
1894 | **/ | |
1895 | static int ibmvfc_eh_device_reset_handler(struct scsi_cmnd *cmd) | |
1896 | { | |
1897 | struct ibmvfc_host *vhost = shost_priv(cmd->device->host); | |
1898 | struct ibmvfc_event *evt, *pos; | |
1899 | int cancel_rc, reset_rc; | |
1900 | unsigned long flags; | |
1901 | ||
1902 | ENTER; | |
1903 | ibmvfc_wait_while_resetting(vhost); | |
1904 | cancel_rc = ibmvfc_cancel_all(cmd->device, IBMVFC_TMF_LUN_RESET); | |
1905 | reset_rc = ibmvfc_reset_device(cmd->device, IBMVFC_LUN_RESET, "LUN"); | |
1906 | ||
1907 | if (!cancel_rc && !reset_rc) { | |
1908 | spin_lock_irqsave(vhost->host->host_lock, flags); | |
1909 | list_for_each_entry_safe(evt, pos, &vhost->sent, queue) { | |
1910 | if (evt->cmnd && evt->cmnd->device == cmd->device) | |
1911 | ibmvfc_fail_request(evt, DID_ABORT); | |
1912 | } | |
1913 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
1914 | LEAVE; | |
1915 | return SUCCESS; | |
1916 | } | |
1917 | ||
1918 | LEAVE; | |
1919 | return FAILED; | |
1920 | } | |
1921 | ||
1922 | /** | |
1923 | * ibmvfc_dev_cancel_all - Device iterated cancel all function | |
1924 | * @sdev: scsi device struct | |
1925 | * @data: return code | |
1926 | * | |
1927 | **/ | |
1928 | static void ibmvfc_dev_cancel_all(struct scsi_device *sdev, void *data) | |
1929 | { | |
1930 | unsigned long *rc = data; | |
1931 | *rc |= ibmvfc_cancel_all(sdev, IBMVFC_TMF_TGT_RESET); | |
1932 | } | |
1933 | ||
1934 | /** | |
1935 | * ibmvfc_dev_abort_all - Device iterated abort task set function | |
1936 | * @sdev: scsi device struct | |
1937 | * @data: return code | |
1938 | * | |
1939 | **/ | |
1940 | static void ibmvfc_dev_abort_all(struct scsi_device *sdev, void *data) | |
1941 | { | |
1942 | unsigned long *rc = data; | |
1943 | *rc |= ibmvfc_abort_task_set(sdev); | |
1944 | } | |
1945 | ||
1946 | /** | |
1947 | * ibmvfc_eh_target_reset_handler - Reset the target | |
1948 | * @cmd: scsi command struct | |
1949 | * | |
1950 | * Returns: | |
1951 | * SUCCESS / FAILED | |
1952 | **/ | |
1953 | static int ibmvfc_eh_target_reset_handler(struct scsi_cmnd *cmd) | |
1954 | { | |
1955 | struct ibmvfc_host *vhost = shost_priv(cmd->device->host); | |
1956 | struct scsi_target *starget = scsi_target(cmd->device); | |
1957 | struct ibmvfc_event *evt, *pos; | |
1958 | int reset_rc; | |
1959 | unsigned long cancel_rc = 0; | |
1960 | unsigned long flags; | |
1961 | ||
1962 | ENTER; | |
1963 | ibmvfc_wait_while_resetting(vhost); | |
1964 | starget_for_each_device(starget, &cancel_rc, ibmvfc_dev_cancel_all); | |
1965 | reset_rc = ibmvfc_reset_device(cmd->device, IBMVFC_TARGET_RESET, "target"); | |
1966 | ||
1967 | if (!cancel_rc && !reset_rc) { | |
1968 | spin_lock_irqsave(vhost->host->host_lock, flags); | |
1969 | list_for_each_entry_safe(evt, pos, &vhost->sent, queue) { | |
1970 | if (evt->cmnd && scsi_target(evt->cmnd->device) == starget) | |
1971 | ibmvfc_fail_request(evt, DID_ABORT); | |
1972 | } | |
1973 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
1974 | LEAVE; | |
1975 | return SUCCESS; | |
1976 | } | |
1977 | ||
1978 | LEAVE; | |
1979 | return FAILED; | |
1980 | } | |
1981 | ||
1982 | /** | |
1983 | * ibmvfc_eh_host_reset_handler - Reset the connection to the server | |
1984 | * @cmd: struct scsi_cmnd having problems | |
1985 | * | |
1986 | **/ | |
1987 | static int ibmvfc_eh_host_reset_handler(struct scsi_cmnd *cmd) | |
1988 | { | |
1989 | int rc; | |
1990 | struct ibmvfc_host *vhost = shost_priv(cmd->device->host); | |
1991 | ||
1992 | dev_err(vhost->dev, "Resetting connection due to error recovery\n"); | |
1993 | rc = ibmvfc_issue_fc_host_lip(vhost->host); | |
1994 | return rc ? FAILED : SUCCESS; | |
1995 | } | |
1996 | ||
1997 | /** | |
1998 | * ibmvfc_terminate_rport_io - Terminate all pending I/O to the rport. | |
1999 | * @rport: rport struct | |
2000 | * | |
2001 | * Return value: | |
2002 | * none | |
2003 | **/ | |
2004 | static void ibmvfc_terminate_rport_io(struct fc_rport *rport) | |
2005 | { | |
2006 | struct scsi_target *starget = to_scsi_target(&rport->dev); | |
2007 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); | |
2008 | struct ibmvfc_host *vhost = shost_priv(shost); | |
2009 | struct ibmvfc_event *evt, *pos; | |
2010 | unsigned long cancel_rc = 0; | |
2011 | unsigned long abort_rc = 0; | |
2012 | unsigned long flags; | |
2013 | ||
2014 | ENTER; | |
2015 | starget_for_each_device(starget, &cancel_rc, ibmvfc_dev_cancel_all); | |
2016 | starget_for_each_device(starget, &abort_rc, ibmvfc_dev_abort_all); | |
2017 | ||
2018 | if (!cancel_rc && !abort_rc) { | |
2019 | spin_lock_irqsave(shost->host_lock, flags); | |
2020 | list_for_each_entry_safe(evt, pos, &vhost->sent, queue) { | |
2021 | if (evt->cmnd && scsi_target(evt->cmnd->device) == starget) | |
2022 | ibmvfc_fail_request(evt, DID_ABORT); | |
2023 | } | |
2024 | spin_unlock_irqrestore(shost->host_lock, flags); | |
2025 | } else | |
2026 | ibmvfc_issue_fc_host_lip(shost); | |
2027 | ||
2028 | scsi_target_unblock(&rport->dev); | |
2029 | LEAVE; | |
2030 | } | |
2031 | ||
2032 | static const struct { | |
2033 | enum ibmvfc_async_event ae; | |
2034 | const char *desc; | |
2035 | } ae_desc [] = { | |
2036 | { IBMVFC_AE_ELS_PLOGI, "PLOGI" }, | |
2037 | { IBMVFC_AE_ELS_LOGO, "LOGO" }, | |
2038 | { IBMVFC_AE_ELS_PRLO, "PRLO" }, | |
2039 | { IBMVFC_AE_SCN_NPORT, "N-Port SCN" }, | |
2040 | { IBMVFC_AE_SCN_GROUP, "Group SCN" }, | |
2041 | { IBMVFC_AE_SCN_DOMAIN, "Domain SCN" }, | |
2042 | { IBMVFC_AE_SCN_FABRIC, "Fabric SCN" }, | |
2043 | { IBMVFC_AE_LINK_UP, "Link Up" }, | |
2044 | { IBMVFC_AE_LINK_DOWN, "Link Down" }, | |
2045 | { IBMVFC_AE_LINK_DEAD, "Link Dead" }, | |
2046 | { IBMVFC_AE_HALT, "Halt" }, | |
2047 | { IBMVFC_AE_RESUME, "Resume" }, | |
2048 | { IBMVFC_AE_ADAPTER_FAILED, "Adapter Failed" }, | |
2049 | }; | |
2050 | ||
2051 | static const char *unknown_ae = "Unknown async"; | |
2052 | ||
2053 | /** | |
2054 | * ibmvfc_get_ae_desc - Get text description for async event | |
2055 | * @ae: async event | |
2056 | * | |
2057 | **/ | |
2058 | static const char *ibmvfc_get_ae_desc(u64 ae) | |
2059 | { | |
2060 | int i; | |
2061 | ||
2062 | for (i = 0; i < ARRAY_SIZE(ae_desc); i++) | |
2063 | if (ae_desc[i].ae == ae) | |
2064 | return ae_desc[i].desc; | |
2065 | ||
2066 | return unknown_ae; | |
2067 | } | |
2068 | ||
2069 | /** | |
2070 | * ibmvfc_handle_async - Handle an async event from the adapter | |
2071 | * @crq: crq to process | |
2072 | * @vhost: ibmvfc host struct | |
2073 | * | |
2074 | **/ | |
2075 | static void ibmvfc_handle_async(struct ibmvfc_async_crq *crq, | |
2076 | struct ibmvfc_host *vhost) | |
2077 | { | |
2078 | const char *desc = ibmvfc_get_ae_desc(crq->event); | |
2079 | ||
0ae808e0 | 2080 | ibmvfc_log(vhost, 3, "%s event received\n", desc); |
072b91f9 BK |
2081 | |
2082 | switch (crq->event) { | |
2083 | case IBMVFC_AE_LINK_UP: | |
2084 | case IBMVFC_AE_RESUME: | |
2085 | vhost->events_to_log |= IBMVFC_AE_LINKUP; | |
2086 | ibmvfc_init_host(vhost); | |
2087 | break; | |
2088 | case IBMVFC_AE_SCN_FABRIC: | |
2089 | vhost->events_to_log |= IBMVFC_AE_RSCN; | |
2090 | ibmvfc_init_host(vhost); | |
2091 | break; | |
2092 | case IBMVFC_AE_SCN_NPORT: | |
2093 | case IBMVFC_AE_SCN_GROUP: | |
2094 | case IBMVFC_AE_SCN_DOMAIN: | |
2095 | vhost->events_to_log |= IBMVFC_AE_RSCN; | |
2096 | case IBMVFC_AE_ELS_LOGO: | |
2097 | case IBMVFC_AE_ELS_PRLO: | |
2098 | case IBMVFC_AE_ELS_PLOGI: | |
2099 | ibmvfc_reinit_host(vhost); | |
2100 | break; | |
2101 | case IBMVFC_AE_LINK_DOWN: | |
2102 | case IBMVFC_AE_ADAPTER_FAILED: | |
2103 | ibmvfc_link_down(vhost, IBMVFC_LINK_DOWN); | |
2104 | break; | |
2105 | case IBMVFC_AE_LINK_DEAD: | |
2106 | ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD); | |
2107 | break; | |
2108 | case IBMVFC_AE_HALT: | |
2109 | ibmvfc_link_down(vhost, IBMVFC_HALTED); | |
2110 | break; | |
2111 | default: | |
2112 | dev_err(vhost->dev, "Unknown async event received: %ld\n", crq->event); | |
2113 | break; | |
2114 | }; | |
2115 | } | |
2116 | ||
2117 | /** | |
2118 | * ibmvfc_handle_crq - Handles and frees received events in the CRQ | |
2119 | * @crq: Command/Response queue | |
2120 | * @vhost: ibmvfc host struct | |
2121 | * | |
2122 | **/ | |
2123 | static void ibmvfc_handle_crq(struct ibmvfc_crq *crq, struct ibmvfc_host *vhost) | |
2124 | { | |
2125 | long rc; | |
2126 | struct ibmvfc_event *evt = (struct ibmvfc_event *)crq->ioba; | |
2127 | ||
2128 | switch (crq->valid) { | |
2129 | case IBMVFC_CRQ_INIT_RSP: | |
2130 | switch (crq->format) { | |
2131 | case IBMVFC_CRQ_INIT: | |
2132 | dev_info(vhost->dev, "Partner initialized\n"); | |
2133 | /* Send back a response */ | |
2134 | rc = ibmvfc_send_crq_init_complete(vhost); | |
2135 | if (rc == 0) | |
2136 | ibmvfc_init_host(vhost); | |
2137 | else | |
2138 | dev_err(vhost->dev, "Unable to send init rsp. rc=%ld\n", rc); | |
2139 | break; | |
2140 | case IBMVFC_CRQ_INIT_COMPLETE: | |
2141 | dev_info(vhost->dev, "Partner initialization complete\n"); | |
2142 | ibmvfc_init_host(vhost); | |
2143 | break; | |
2144 | default: | |
2145 | dev_err(vhost->dev, "Unknown crq message type: %d\n", crq->format); | |
2146 | } | |
2147 | return; | |
2148 | case IBMVFC_CRQ_XPORT_EVENT: | |
2149 | vhost->state = IBMVFC_NO_CRQ; | |
2150 | ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_NONE); | |
2151 | if (crq->format == IBMVFC_PARTITION_MIGRATED) { | |
2152 | /* We need to re-setup the interpartition connection */ | |
2153 | dev_info(vhost->dev, "Re-enabling adapter\n"); | |
2154 | vhost->client_migrated = 1; | |
2155 | ibmvfc_purge_requests(vhost, DID_REQUEUE); | |
2156 | if ((rc = ibmvfc_reenable_crq_queue(vhost)) || | |
2157 | (rc = ibmvfc_send_crq_init(vhost))) { | |
2158 | ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD); | |
2159 | dev_err(vhost->dev, "Error after enable (rc=%ld)\n", rc); | |
2160 | } else | |
2161 | ibmvfc_link_down(vhost, IBMVFC_LINK_DOWN); | |
2162 | } else { | |
2163 | dev_err(vhost->dev, "Virtual adapter failed (rc=%d)\n", crq->format); | |
2164 | ||
2165 | ibmvfc_purge_requests(vhost, DID_ERROR); | |
2166 | if ((rc = ibmvfc_reset_crq(vhost)) || | |
2167 | (rc = ibmvfc_send_crq_init(vhost))) { | |
2168 | ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD); | |
2169 | dev_err(vhost->dev, "Error after reset (rc=%ld)\n", rc); | |
2170 | } else | |
2171 | ibmvfc_link_down(vhost, IBMVFC_LINK_DOWN); | |
2172 | } | |
2173 | return; | |
2174 | case IBMVFC_CRQ_CMD_RSP: | |
2175 | break; | |
2176 | default: | |
2177 | dev_err(vhost->dev, "Got an invalid message type 0x%02x\n", crq->valid); | |
2178 | return; | |
2179 | } | |
2180 | ||
2181 | if (crq->format == IBMVFC_ASYNC_EVENT) | |
2182 | return; | |
2183 | ||
2184 | /* The only kind of payload CRQs we should get are responses to | |
2185 | * things we send. Make sure this response is to something we | |
2186 | * actually sent | |
2187 | */ | |
2188 | if (unlikely(!ibmvfc_valid_event(&vhost->pool, evt))) { | |
2189 | dev_err(vhost->dev, "Returned correlation_token 0x%08lx is invalid!\n", | |
2190 | crq->ioba); | |
2191 | return; | |
2192 | } | |
2193 | ||
2194 | if (unlikely(atomic_read(&evt->free))) { | |
2195 | dev_err(vhost->dev, "Received duplicate correlation_token 0x%08lx!\n", | |
2196 | crq->ioba); | |
2197 | return; | |
2198 | } | |
2199 | ||
2200 | del_timer(&evt->timer); | |
2201 | list_del(&evt->queue); | |
2202 | ibmvfc_trc_end(evt); | |
2203 | evt->done(evt); | |
2204 | } | |
2205 | ||
2206 | /** | |
2207 | * ibmvfc_scan_finished - Check if the device scan is done. | |
2208 | * @shost: scsi host struct | |
2209 | * @time: current elapsed time | |
2210 | * | |
2211 | * Returns: | |
2212 | * 0 if scan is not done / 1 if scan is done | |
2213 | **/ | |
2214 | static int ibmvfc_scan_finished(struct Scsi_Host *shost, unsigned long time) | |
2215 | { | |
2216 | unsigned long flags; | |
2217 | struct ibmvfc_host *vhost = shost_priv(shost); | |
2218 | int done = 0; | |
2219 | ||
2220 | spin_lock_irqsave(shost->host_lock, flags); | |
2221 | if (time >= (init_timeout * HZ)) { | |
2222 | dev_info(vhost->dev, "Scan taking longer than %d seconds, " | |
2223 | "continuing initialization\n", init_timeout); | |
2224 | done = 1; | |
2225 | } | |
2226 | ||
2227 | if (vhost->state != IBMVFC_NO_CRQ && vhost->action == IBMVFC_HOST_ACTION_NONE) | |
2228 | done = 1; | |
2229 | spin_unlock_irqrestore(shost->host_lock, flags); | |
2230 | return done; | |
2231 | } | |
2232 | ||
2233 | /** | |
2234 | * ibmvfc_slave_alloc - Setup the device's task set value | |
2235 | * @sdev: struct scsi_device device to configure | |
2236 | * | |
2237 | * Set the device's task set value so that error handling works as | |
2238 | * expected. | |
2239 | * | |
2240 | * Returns: | |
2241 | * 0 on success / -ENXIO if device does not exist | |
2242 | **/ | |
2243 | static int ibmvfc_slave_alloc(struct scsi_device *sdev) | |
2244 | { | |
2245 | struct Scsi_Host *shost = sdev->host; | |
2246 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); | |
2247 | struct ibmvfc_host *vhost = shost_priv(shost); | |
2248 | unsigned long flags = 0; | |
2249 | ||
2250 | if (!rport || fc_remote_port_chkready(rport)) | |
2251 | return -ENXIO; | |
2252 | ||
2253 | spin_lock_irqsave(shost->host_lock, flags); | |
2254 | sdev->hostdata = (void *)(unsigned long)vhost->task_set++; | |
2255 | spin_unlock_irqrestore(shost->host_lock, flags); | |
2256 | return 0; | |
2257 | } | |
2258 | ||
2259 | /** | |
2260 | * ibmvfc_slave_configure - Configure the device | |
2261 | * @sdev: struct scsi_device device to configure | |
2262 | * | |
2263 | * Enable allow_restart for a device if it is a disk. Adjust the | |
2264 | * queue_depth here also. | |
2265 | * | |
2266 | * Returns: | |
2267 | * 0 | |
2268 | **/ | |
2269 | static int ibmvfc_slave_configure(struct scsi_device *sdev) | |
2270 | { | |
2271 | struct Scsi_Host *shost = sdev->host; | |
2272 | struct fc_rport *rport = starget_to_rport(sdev->sdev_target); | |
2273 | unsigned long flags = 0; | |
2274 | ||
2275 | spin_lock_irqsave(shost->host_lock, flags); | |
2276 | if (sdev->type == TYPE_DISK) | |
2277 | sdev->allow_restart = 1; | |
2278 | ||
2279 | if (sdev->tagged_supported) { | |
2280 | scsi_set_tag_type(sdev, MSG_SIMPLE_TAG); | |
2281 | scsi_activate_tcq(sdev, sdev->queue_depth); | |
2282 | } else | |
2283 | scsi_deactivate_tcq(sdev, sdev->queue_depth); | |
2284 | ||
2285 | rport->dev_loss_tmo = dev_loss_tmo; | |
2286 | spin_unlock_irqrestore(shost->host_lock, flags); | |
2287 | return 0; | |
2288 | } | |
2289 | ||
2290 | /** | |
2291 | * ibmvfc_change_queue_depth - Change the device's queue depth | |
2292 | * @sdev: scsi device struct | |
2293 | * @qdepth: depth to set | |
2294 | * | |
2295 | * Return value: | |
2296 | * actual depth set | |
2297 | **/ | |
2298 | static int ibmvfc_change_queue_depth(struct scsi_device *sdev, int qdepth) | |
2299 | { | |
2300 | if (qdepth > IBMVFC_MAX_CMDS_PER_LUN) | |
2301 | qdepth = IBMVFC_MAX_CMDS_PER_LUN; | |
2302 | ||
2303 | scsi_adjust_queue_depth(sdev, 0, qdepth); | |
2304 | return sdev->queue_depth; | |
2305 | } | |
2306 | ||
2307 | /** | |
2308 | * ibmvfc_change_queue_type - Change the device's queue type | |
2309 | * @sdev: scsi device struct | |
2310 | * @tag_type: type of tags to use | |
2311 | * | |
2312 | * Return value: | |
2313 | * actual queue type set | |
2314 | **/ | |
2315 | static int ibmvfc_change_queue_type(struct scsi_device *sdev, int tag_type) | |
2316 | { | |
2317 | if (sdev->tagged_supported) { | |
2318 | scsi_set_tag_type(sdev, tag_type); | |
2319 | ||
2320 | if (tag_type) | |
2321 | scsi_activate_tcq(sdev, sdev->queue_depth); | |
2322 | else | |
2323 | scsi_deactivate_tcq(sdev, sdev->queue_depth); | |
2324 | } else | |
2325 | tag_type = 0; | |
2326 | ||
2327 | return tag_type; | |
2328 | } | |
2329 | ||
2330 | static ssize_t ibmvfc_show_host_partition_name(struct device *dev, | |
2331 | struct device_attribute *attr, char *buf) | |
2332 | { | |
2333 | struct Scsi_Host *shost = class_to_shost(dev); | |
2334 | struct ibmvfc_host *vhost = shost_priv(shost); | |
2335 | ||
2336 | return snprintf(buf, PAGE_SIZE, "%s\n", | |
2337 | vhost->login_buf->resp.partition_name); | |
2338 | } | |
2339 | ||
2340 | static struct device_attribute ibmvfc_host_partition_name = { | |
2341 | .attr = { | |
2342 | .name = "partition_name", | |
2343 | .mode = S_IRUGO, | |
2344 | }, | |
2345 | .show = ibmvfc_show_host_partition_name, | |
2346 | }; | |
2347 | ||
2348 | static ssize_t ibmvfc_show_host_device_name(struct device *dev, | |
2349 | struct device_attribute *attr, char *buf) | |
2350 | { | |
2351 | struct Scsi_Host *shost = class_to_shost(dev); | |
2352 | struct ibmvfc_host *vhost = shost_priv(shost); | |
2353 | ||
2354 | return snprintf(buf, PAGE_SIZE, "%s\n", | |
2355 | vhost->login_buf->resp.device_name); | |
2356 | } | |
2357 | ||
2358 | static struct device_attribute ibmvfc_host_device_name = { | |
2359 | .attr = { | |
2360 | .name = "device_name", | |
2361 | .mode = S_IRUGO, | |
2362 | }, | |
2363 | .show = ibmvfc_show_host_device_name, | |
2364 | }; | |
2365 | ||
2366 | static ssize_t ibmvfc_show_host_loc_code(struct device *dev, | |
2367 | struct device_attribute *attr, char *buf) | |
2368 | { | |
2369 | struct Scsi_Host *shost = class_to_shost(dev); | |
2370 | struct ibmvfc_host *vhost = shost_priv(shost); | |
2371 | ||
2372 | return snprintf(buf, PAGE_SIZE, "%s\n", | |
2373 | vhost->login_buf->resp.port_loc_code); | |
2374 | } | |
2375 | ||
2376 | static struct device_attribute ibmvfc_host_loc_code = { | |
2377 | .attr = { | |
2378 | .name = "port_loc_code", | |
2379 | .mode = S_IRUGO, | |
2380 | }, | |
2381 | .show = ibmvfc_show_host_loc_code, | |
2382 | }; | |
2383 | ||
2384 | static ssize_t ibmvfc_show_host_drc_name(struct device *dev, | |
2385 | struct device_attribute *attr, char *buf) | |
2386 | { | |
2387 | struct Scsi_Host *shost = class_to_shost(dev); | |
2388 | struct ibmvfc_host *vhost = shost_priv(shost); | |
2389 | ||
2390 | return snprintf(buf, PAGE_SIZE, "%s\n", | |
2391 | vhost->login_buf->resp.drc_name); | |
2392 | } | |
2393 | ||
2394 | static struct device_attribute ibmvfc_host_drc_name = { | |
2395 | .attr = { | |
2396 | .name = "drc_name", | |
2397 | .mode = S_IRUGO, | |
2398 | }, | |
2399 | .show = ibmvfc_show_host_drc_name, | |
2400 | }; | |
2401 | ||
2402 | static ssize_t ibmvfc_show_host_npiv_version(struct device *dev, | |
2403 | struct device_attribute *attr, char *buf) | |
2404 | { | |
2405 | struct Scsi_Host *shost = class_to_shost(dev); | |
2406 | struct ibmvfc_host *vhost = shost_priv(shost); | |
2407 | return snprintf(buf, PAGE_SIZE, "%d\n", vhost->login_buf->resp.version); | |
2408 | } | |
2409 | ||
2410 | static struct device_attribute ibmvfc_host_npiv_version = { | |
2411 | .attr = { | |
2412 | .name = "npiv_version", | |
2413 | .mode = S_IRUGO, | |
2414 | }, | |
2415 | .show = ibmvfc_show_host_npiv_version, | |
2416 | }; | |
2417 | ||
2418 | /** | |
2419 | * ibmvfc_show_log_level - Show the adapter's error logging level | |
2420 | * @dev: class device struct | |
2421 | * @buf: buffer | |
2422 | * | |
2423 | * Return value: | |
2424 | * number of bytes printed to buffer | |
2425 | **/ | |
2426 | static ssize_t ibmvfc_show_log_level(struct device *dev, | |
2427 | struct device_attribute *attr, char *buf) | |
2428 | { | |
2429 | struct Scsi_Host *shost = class_to_shost(dev); | |
2430 | struct ibmvfc_host *vhost = shost_priv(shost); | |
2431 | unsigned long flags = 0; | |
2432 | int len; | |
2433 | ||
2434 | spin_lock_irqsave(shost->host_lock, flags); | |
2435 | len = snprintf(buf, PAGE_SIZE, "%d\n", vhost->log_level); | |
2436 | spin_unlock_irqrestore(shost->host_lock, flags); | |
2437 | return len; | |
2438 | } | |
2439 | ||
2440 | /** | |
2441 | * ibmvfc_store_log_level - Change the adapter's error logging level | |
2442 | * @dev: class device struct | |
2443 | * @buf: buffer | |
2444 | * | |
2445 | * Return value: | |
2446 | * number of bytes printed to buffer | |
2447 | **/ | |
2448 | static ssize_t ibmvfc_store_log_level(struct device *dev, | |
2449 | struct device_attribute *attr, | |
2450 | const char *buf, size_t count) | |
2451 | { | |
2452 | struct Scsi_Host *shost = class_to_shost(dev); | |
2453 | struct ibmvfc_host *vhost = shost_priv(shost); | |
2454 | unsigned long flags = 0; | |
2455 | ||
2456 | spin_lock_irqsave(shost->host_lock, flags); | |
2457 | vhost->log_level = simple_strtoul(buf, NULL, 10); | |
2458 | spin_unlock_irqrestore(shost->host_lock, flags); | |
2459 | return strlen(buf); | |
2460 | } | |
2461 | ||
2462 | static struct device_attribute ibmvfc_log_level_attr = { | |
2463 | .attr = { | |
2464 | .name = "log_level", | |
2465 | .mode = S_IRUGO | S_IWUSR, | |
2466 | }, | |
2467 | .show = ibmvfc_show_log_level, | |
2468 | .store = ibmvfc_store_log_level | |
2469 | }; | |
2470 | ||
2471 | #ifdef CONFIG_SCSI_IBMVFC_TRACE | |
2472 | /** | |
2473 | * ibmvfc_read_trace - Dump the adapter trace | |
2474 | * @kobj: kobject struct | |
2475 | * @bin_attr: bin_attribute struct | |
2476 | * @buf: buffer | |
2477 | * @off: offset | |
2478 | * @count: buffer size | |
2479 | * | |
2480 | * Return value: | |
2481 | * number of bytes printed to buffer | |
2482 | **/ | |
2483 | static ssize_t ibmvfc_read_trace(struct kobject *kobj, | |
2484 | struct bin_attribute *bin_attr, | |
2485 | char *buf, loff_t off, size_t count) | |
2486 | { | |
2487 | struct device *dev = container_of(kobj, struct device, kobj); | |
2488 | struct Scsi_Host *shost = class_to_shost(dev); | |
2489 | struct ibmvfc_host *vhost = shost_priv(shost); | |
2490 | unsigned long flags = 0; | |
2491 | int size = IBMVFC_TRACE_SIZE; | |
2492 | char *src = (char *)vhost->trace; | |
2493 | ||
2494 | if (off > size) | |
2495 | return 0; | |
2496 | if (off + count > size) { | |
2497 | size -= off; | |
2498 | count = size; | |
2499 | } | |
2500 | ||
2501 | spin_lock_irqsave(shost->host_lock, flags); | |
2502 | memcpy(buf, &src[off], count); | |
2503 | spin_unlock_irqrestore(shost->host_lock, flags); | |
2504 | return count; | |
2505 | } | |
2506 | ||
2507 | static struct bin_attribute ibmvfc_trace_attr = { | |
2508 | .attr = { | |
2509 | .name = "trace", | |
2510 | .mode = S_IRUGO, | |
2511 | }, | |
2512 | .size = 0, | |
2513 | .read = ibmvfc_read_trace, | |
2514 | }; | |
2515 | #endif | |
2516 | ||
2517 | static struct device_attribute *ibmvfc_attrs[] = { | |
2518 | &ibmvfc_host_partition_name, | |
2519 | &ibmvfc_host_device_name, | |
2520 | &ibmvfc_host_loc_code, | |
2521 | &ibmvfc_host_drc_name, | |
2522 | &ibmvfc_host_npiv_version, | |
2523 | &ibmvfc_log_level_attr, | |
2524 | NULL | |
2525 | }; | |
2526 | ||
2527 | static struct scsi_host_template driver_template = { | |
2528 | .module = THIS_MODULE, | |
2529 | .name = "IBM POWER Virtual FC Adapter", | |
2530 | .proc_name = IBMVFC_NAME, | |
2531 | .queuecommand = ibmvfc_queuecommand, | |
2532 | .eh_abort_handler = ibmvfc_eh_abort_handler, | |
2533 | .eh_device_reset_handler = ibmvfc_eh_device_reset_handler, | |
2534 | .eh_target_reset_handler = ibmvfc_eh_target_reset_handler, | |
2535 | .eh_host_reset_handler = ibmvfc_eh_host_reset_handler, | |
2536 | .slave_alloc = ibmvfc_slave_alloc, | |
2537 | .slave_configure = ibmvfc_slave_configure, | |
2538 | .scan_finished = ibmvfc_scan_finished, | |
2539 | .change_queue_depth = ibmvfc_change_queue_depth, | |
2540 | .change_queue_type = ibmvfc_change_queue_type, | |
2541 | .cmd_per_lun = 16, | |
2542 | .can_queue = IBMVFC_MAX_REQUESTS_DEFAULT, | |
2543 | .this_id = -1, | |
2544 | .sg_tablesize = SG_ALL, | |
2545 | .max_sectors = IBMVFC_MAX_SECTORS, | |
2546 | .use_clustering = ENABLE_CLUSTERING, | |
2547 | .shost_attrs = ibmvfc_attrs, | |
2548 | }; | |
2549 | ||
2550 | /** | |
2551 | * ibmvfc_next_async_crq - Returns the next entry in async queue | |
2552 | * @vhost: ibmvfc host struct | |
2553 | * | |
2554 | * Returns: | |
2555 | * Pointer to next entry in queue / NULL if empty | |
2556 | **/ | |
2557 | static struct ibmvfc_async_crq *ibmvfc_next_async_crq(struct ibmvfc_host *vhost) | |
2558 | { | |
2559 | struct ibmvfc_async_crq_queue *async_crq = &vhost->async_crq; | |
2560 | struct ibmvfc_async_crq *crq; | |
2561 | ||
2562 | crq = &async_crq->msgs[async_crq->cur]; | |
2563 | if (crq->valid & 0x80) { | |
2564 | if (++async_crq->cur == async_crq->size) | |
2565 | async_crq->cur = 0; | |
2566 | } else | |
2567 | crq = NULL; | |
2568 | ||
2569 | return crq; | |
2570 | } | |
2571 | ||
2572 | /** | |
2573 | * ibmvfc_next_crq - Returns the next entry in message queue | |
2574 | * @vhost: ibmvfc host struct | |
2575 | * | |
2576 | * Returns: | |
2577 | * Pointer to next entry in queue / NULL if empty | |
2578 | **/ | |
2579 | static struct ibmvfc_crq *ibmvfc_next_crq(struct ibmvfc_host *vhost) | |
2580 | { | |
2581 | struct ibmvfc_crq_queue *queue = &vhost->crq; | |
2582 | struct ibmvfc_crq *crq; | |
2583 | ||
2584 | crq = &queue->msgs[queue->cur]; | |
2585 | if (crq->valid & 0x80) { | |
2586 | if (++queue->cur == queue->size) | |
2587 | queue->cur = 0; | |
2588 | } else | |
2589 | crq = NULL; | |
2590 | ||
2591 | return crq; | |
2592 | } | |
2593 | ||
2594 | /** | |
2595 | * ibmvfc_interrupt - Interrupt handler | |
2596 | * @irq: number of irq to handle, not used | |
2597 | * @dev_instance: ibmvfc_host that received interrupt | |
2598 | * | |
2599 | * Returns: | |
2600 | * IRQ_HANDLED | |
2601 | **/ | |
2602 | static irqreturn_t ibmvfc_interrupt(int irq, void *dev_instance) | |
2603 | { | |
2604 | struct ibmvfc_host *vhost = (struct ibmvfc_host *)dev_instance; | |
2605 | struct vio_dev *vdev = to_vio_dev(vhost->dev); | |
2606 | struct ibmvfc_crq *crq; | |
2607 | struct ibmvfc_async_crq *async; | |
2608 | unsigned long flags; | |
2609 | int done = 0; | |
2610 | ||
2611 | spin_lock_irqsave(vhost->host->host_lock, flags); | |
2612 | vio_disable_interrupts(to_vio_dev(vhost->dev)); | |
2613 | while (!done) { | |
2614 | /* Pull all the valid messages off the CRQ */ | |
2615 | while ((crq = ibmvfc_next_crq(vhost)) != NULL) { | |
2616 | ibmvfc_handle_crq(crq, vhost); | |
2617 | crq->valid = 0; | |
2618 | } | |
2619 | ||
2620 | /* Pull all the valid messages off the async CRQ */ | |
2621 | while ((async = ibmvfc_next_async_crq(vhost)) != NULL) { | |
2622 | ibmvfc_handle_async(async, vhost); | |
2623 | async->valid = 0; | |
2624 | } | |
2625 | ||
2626 | vio_enable_interrupts(vdev); | |
2627 | if ((crq = ibmvfc_next_crq(vhost)) != NULL) { | |
2628 | vio_disable_interrupts(vdev); | |
2629 | ibmvfc_handle_crq(crq, vhost); | |
2630 | crq->valid = 0; | |
2631 | } else if ((async = ibmvfc_next_async_crq(vhost)) != NULL) { | |
2632 | vio_disable_interrupts(vdev); | |
2633 | ibmvfc_handle_async(async, vhost); | |
2634 | crq->valid = 0; | |
2635 | } else | |
2636 | done = 1; | |
2637 | } | |
2638 | ||
2639 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
2640 | return IRQ_HANDLED; | |
2641 | } | |
2642 | ||
2643 | /** | |
2644 | * ibmvfc_init_tgt - Set the next init job step for the target | |
2645 | * @tgt: ibmvfc target struct | |
2646 | * @job_step: job step to perform | |
2647 | * | |
2648 | **/ | |
2649 | static void ibmvfc_init_tgt(struct ibmvfc_target *tgt, | |
2650 | void (*job_step) (struct ibmvfc_target *)) | |
2651 | { | |
2652 | ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_INIT); | |
2653 | tgt->job_step = job_step; | |
2654 | wake_up(&tgt->vhost->work_wait_q); | |
2655 | } | |
2656 | ||
2657 | /** | |
2658 | * ibmvfc_retry_tgt_init - Attempt to retry a step in target initialization | |
2659 | * @tgt: ibmvfc target struct | |
2660 | * @job_step: initialization job step | |
2661 | * | |
2662 | **/ | |
2663 | static void ibmvfc_retry_tgt_init(struct ibmvfc_target *tgt, | |
2664 | void (*job_step) (struct ibmvfc_target *)) | |
2665 | { | |
2666 | if (++tgt->init_retries > IBMVFC_MAX_INIT_RETRIES) { | |
2667 | ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_DEL_RPORT); | |
2668 | wake_up(&tgt->vhost->work_wait_q); | |
2669 | } else | |
2670 | ibmvfc_init_tgt(tgt, job_step); | |
2671 | } | |
2672 | ||
072b91f9 BK |
2673 | /** |
2674 | * ibmvfc_tgt_prli_done - Completion handler for Process Login | |
2675 | * @evt: ibmvfc event struct | |
2676 | * | |
2677 | **/ | |
2678 | static void ibmvfc_tgt_prli_done(struct ibmvfc_event *evt) | |
2679 | { | |
2680 | struct ibmvfc_target *tgt = evt->tgt; | |
2681 | struct ibmvfc_host *vhost = evt->vhost; | |
2682 | struct ibmvfc_process_login *rsp = &evt->xfer_iu->prli; | |
2683 | u32 status = rsp->common.status; | |
2684 | ||
2685 | vhost->discovery_threads--; | |
2686 | ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE); | |
2687 | switch (status) { | |
2688 | case IBMVFC_MAD_SUCCESS: | |
2689 | tgt_dbg(tgt, "Process Login succeeded\n"); | |
2690 | tgt->need_login = 0; | |
2691 | ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_ADD_RPORT); | |
2692 | break; | |
2693 | case IBMVFC_MAD_DRIVER_FAILED: | |
2694 | break; | |
2695 | case IBMVFC_MAD_CRQ_ERROR: | |
2696 | ibmvfc_retry_tgt_init(tgt, ibmvfc_tgt_send_prli); | |
2697 | break; | |
2698 | case IBMVFC_MAD_FAILED: | |
2699 | default: | |
2700 | tgt_err(tgt, "Process Login failed: %s (%x:%x) rc=0x%02X\n", | |
2701 | ibmvfc_get_cmd_error(rsp->status, rsp->error), | |
2702 | rsp->status, rsp->error, status); | |
2703 | if (ibmvfc_retry_cmd(rsp->status, rsp->error)) | |
2704 | ibmvfc_retry_tgt_init(tgt, ibmvfc_tgt_send_prli); | |
2705 | break; | |
2706 | }; | |
2707 | ||
2708 | kref_put(&tgt->kref, ibmvfc_release_tgt); | |
2709 | ibmvfc_free_event(evt); | |
2710 | wake_up(&vhost->work_wait_q); | |
2711 | } | |
2712 | ||
2713 | /** | |
2714 | * ibmvfc_tgt_send_prli - Send a process login | |
2715 | * @tgt: ibmvfc target struct | |
2716 | * | |
2717 | **/ | |
2718 | static void ibmvfc_tgt_send_prli(struct ibmvfc_target *tgt) | |
2719 | { | |
2720 | struct ibmvfc_process_login *prli; | |
2721 | struct ibmvfc_host *vhost = tgt->vhost; | |
2722 | struct ibmvfc_event *evt; | |
2723 | ||
2724 | if (vhost->discovery_threads >= disc_threads) | |
2725 | return; | |
2726 | ||
2727 | kref_get(&tgt->kref); | |
2728 | evt = ibmvfc_get_event(vhost); | |
2729 | vhost->discovery_threads++; | |
2730 | ibmvfc_init_event(evt, ibmvfc_tgt_prli_done, IBMVFC_MAD_FORMAT); | |
2731 | evt->tgt = tgt; | |
2732 | prli = &evt->iu.prli; | |
2733 | memset(prli, 0, sizeof(*prli)); | |
2734 | prli->common.version = 1; | |
2735 | prli->common.opcode = IBMVFC_PROCESS_LOGIN; | |
2736 | prli->common.length = sizeof(*prli); | |
2737 | prli->scsi_id = tgt->scsi_id; | |
2738 | ||
2739 | prli->parms.type = IBMVFC_SCSI_FCP_TYPE; | |
2740 | prli->parms.flags = IBMVFC_PRLI_EST_IMG_PAIR; | |
2741 | prli->parms.service_parms = IBMVFC_PRLI_INITIATOR_FUNC; | |
2742 | ||
2743 | ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_INIT_WAIT); | |
2744 | if (ibmvfc_send_event(evt, vhost, default_timeout)) { | |
2745 | vhost->discovery_threads--; | |
2746 | ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE); | |
2747 | kref_put(&tgt->kref, ibmvfc_release_tgt); | |
2748 | } else | |
2749 | tgt_dbg(tgt, "Sent process login\n"); | |
2750 | } | |
2751 | ||
2752 | /** | |
2753 | * ibmvfc_tgt_plogi_done - Completion handler for Port Login | |
2754 | * @evt: ibmvfc event struct | |
2755 | * | |
2756 | **/ | |
2757 | static void ibmvfc_tgt_plogi_done(struct ibmvfc_event *evt) | |
2758 | { | |
2759 | struct ibmvfc_target *tgt = evt->tgt; | |
2760 | struct ibmvfc_host *vhost = evt->vhost; | |
2761 | struct ibmvfc_port_login *rsp = &evt->xfer_iu->plogi; | |
2762 | u32 status = rsp->common.status; | |
2763 | ||
2764 | vhost->discovery_threads--; | |
2765 | ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE); | |
2766 | switch (status) { | |
2767 | case IBMVFC_MAD_SUCCESS: | |
2768 | tgt_dbg(tgt, "Port Login succeeded\n"); | |
2769 | if (tgt->ids.port_name && | |
2770 | tgt->ids.port_name != wwn_to_u64(rsp->service_parms.port_name)) { | |
2771 | vhost->reinit = 1; | |
2772 | tgt_dbg(tgt, "Port re-init required\n"); | |
2773 | break; | |
2774 | } | |
2775 | tgt->ids.node_name = wwn_to_u64(rsp->service_parms.node_name); | |
2776 | tgt->ids.port_name = wwn_to_u64(rsp->service_parms.port_name); | |
2777 | tgt->ids.port_id = tgt->scsi_id; | |
2778 | tgt->ids.roles = FC_PORT_ROLE_FCP_TARGET; | |
2779 | memcpy(&tgt->service_parms, &rsp->service_parms, | |
2780 | sizeof(tgt->service_parms)); | |
2781 | memcpy(&tgt->service_parms_change, &rsp->service_parms_change, | |
2782 | sizeof(tgt->service_parms_change)); | |
2783 | ibmvfc_init_tgt(tgt, ibmvfc_tgt_send_prli); | |
2784 | break; | |
2785 | case IBMVFC_MAD_DRIVER_FAILED: | |
2786 | break; | |
2787 | case IBMVFC_MAD_CRQ_ERROR: | |
2788 | ibmvfc_retry_tgt_init(tgt, ibmvfc_tgt_send_plogi); | |
2789 | break; | |
2790 | case IBMVFC_MAD_FAILED: | |
2791 | default: | |
2792 | tgt_err(tgt, "Port Login failed: %s (%x:%x) %s (%x) %s (%x) rc=0x%02X\n", | |
2793 | ibmvfc_get_cmd_error(rsp->status, rsp->error), rsp->status, rsp->error, | |
2794 | ibmvfc_get_fc_type(rsp->fc_type), rsp->fc_type, | |
2795 | ibmvfc_get_ls_explain(rsp->fc_explain), rsp->fc_explain, status); | |
2796 | ||
2797 | if (ibmvfc_retry_cmd(rsp->status, rsp->error)) | |
2798 | ibmvfc_retry_tgt_init(tgt, ibmvfc_tgt_send_plogi); | |
2799 | break; | |
2800 | }; | |
2801 | ||
2802 | kref_put(&tgt->kref, ibmvfc_release_tgt); | |
2803 | ibmvfc_free_event(evt); | |
2804 | wake_up(&vhost->work_wait_q); | |
2805 | } | |
2806 | ||
2807 | /** | |
2808 | * ibmvfc_tgt_send_plogi - Send PLOGI to the specified target | |
2809 | * @tgt: ibmvfc target struct | |
2810 | * | |
2811 | **/ | |
2812 | static void ibmvfc_tgt_send_plogi(struct ibmvfc_target *tgt) | |
2813 | { | |
2814 | struct ibmvfc_port_login *plogi; | |
2815 | struct ibmvfc_host *vhost = tgt->vhost; | |
2816 | struct ibmvfc_event *evt; | |
2817 | ||
2818 | if (vhost->discovery_threads >= disc_threads) | |
2819 | return; | |
2820 | ||
2821 | kref_get(&tgt->kref); | |
2822 | evt = ibmvfc_get_event(vhost); | |
2823 | vhost->discovery_threads++; | |
2824 | ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_INIT_WAIT); | |
2825 | ibmvfc_init_event(evt, ibmvfc_tgt_plogi_done, IBMVFC_MAD_FORMAT); | |
2826 | evt->tgt = tgt; | |
2827 | plogi = &evt->iu.plogi; | |
2828 | memset(plogi, 0, sizeof(*plogi)); | |
2829 | plogi->common.version = 1; | |
2830 | plogi->common.opcode = IBMVFC_PORT_LOGIN; | |
2831 | plogi->common.length = sizeof(*plogi); | |
2832 | plogi->scsi_id = tgt->scsi_id; | |
2833 | ||
2834 | if (ibmvfc_send_event(evt, vhost, default_timeout)) { | |
2835 | vhost->discovery_threads--; | |
2836 | ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE); | |
2837 | kref_put(&tgt->kref, ibmvfc_release_tgt); | |
2838 | } else | |
2839 | tgt_dbg(tgt, "Sent port login\n"); | |
2840 | } | |
2841 | ||
2842 | /** | |
2843 | * ibmvfc_tgt_implicit_logout_done - Completion handler for Implicit Logout MAD | |
2844 | * @evt: ibmvfc event struct | |
2845 | * | |
2846 | **/ | |
2847 | static void ibmvfc_tgt_implicit_logout_done(struct ibmvfc_event *evt) | |
2848 | { | |
2849 | struct ibmvfc_target *tgt = evt->tgt; | |
2850 | struct ibmvfc_host *vhost = evt->vhost; | |
2851 | struct ibmvfc_implicit_logout *rsp = &evt->xfer_iu->implicit_logout; | |
2852 | u32 status = rsp->common.status; | |
2853 | ||
2854 | vhost->discovery_threads--; | |
2855 | ibmvfc_free_event(evt); | |
2856 | ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE); | |
2857 | ||
2858 | switch (status) { | |
2859 | case IBMVFC_MAD_SUCCESS: | |
2860 | tgt_dbg(tgt, "Implicit Logout succeeded\n"); | |
2861 | break; | |
2862 | case IBMVFC_MAD_DRIVER_FAILED: | |
2863 | kref_put(&tgt->kref, ibmvfc_release_tgt); | |
2864 | wake_up(&vhost->work_wait_q); | |
2865 | return; | |
2866 | case IBMVFC_MAD_FAILED: | |
2867 | default: | |
2868 | tgt_err(tgt, "Implicit Logout failed: rc=0x%02X\n", status); | |
2869 | break; | |
2870 | }; | |
2871 | ||
2872 | if (vhost->action == IBMVFC_HOST_ACTION_TGT_INIT) | |
2873 | ibmvfc_init_tgt(tgt, ibmvfc_tgt_send_plogi); | |
2874 | else if (vhost->action == IBMVFC_HOST_ACTION_QUERY_TGTS && | |
2875 | tgt->scsi_id != tgt->new_scsi_id) | |
2876 | ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_DEL_RPORT); | |
2877 | kref_put(&tgt->kref, ibmvfc_release_tgt); | |
2878 | wake_up(&vhost->work_wait_q); | |
2879 | } | |
2880 | ||
2881 | /** | |
2882 | * ibmvfc_tgt_implicit_logout - Initiate an Implicit Logout for specified target | |
2883 | * @tgt: ibmvfc target struct | |
2884 | * | |
2885 | **/ | |
2886 | static void ibmvfc_tgt_implicit_logout(struct ibmvfc_target *tgt) | |
2887 | { | |
2888 | struct ibmvfc_implicit_logout *mad; | |
2889 | struct ibmvfc_host *vhost = tgt->vhost; | |
2890 | struct ibmvfc_event *evt; | |
2891 | ||
2892 | if (vhost->discovery_threads >= disc_threads) | |
2893 | return; | |
2894 | ||
2895 | kref_get(&tgt->kref); | |
2896 | evt = ibmvfc_get_event(vhost); | |
2897 | vhost->discovery_threads++; | |
2898 | ibmvfc_init_event(evt, ibmvfc_tgt_implicit_logout_done, IBMVFC_MAD_FORMAT); | |
2899 | evt->tgt = tgt; | |
2900 | mad = &evt->iu.implicit_logout; | |
2901 | memset(mad, 0, sizeof(*mad)); | |
2902 | mad->common.version = 1; | |
2903 | mad->common.opcode = IBMVFC_IMPLICIT_LOGOUT; | |
2904 | mad->common.length = sizeof(*mad); | |
2905 | mad->old_scsi_id = tgt->scsi_id; | |
2906 | ||
2907 | ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_INIT_WAIT); | |
2908 | if (ibmvfc_send_event(evt, vhost, default_timeout)) { | |
2909 | vhost->discovery_threads--; | |
2910 | ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE); | |
2911 | kref_put(&tgt->kref, ibmvfc_release_tgt); | |
2912 | } else | |
2913 | tgt_dbg(tgt, "Sent Implicit Logout\n"); | |
2914 | } | |
2915 | ||
2916 | /** | |
2917 | * ibmvfc_tgt_query_target_done - Completion handler for Query Target MAD | |
2918 | * @evt: ibmvfc event struct | |
2919 | * | |
2920 | **/ | |
2921 | static void ibmvfc_tgt_query_target_done(struct ibmvfc_event *evt) | |
2922 | { | |
2923 | struct ibmvfc_target *tgt = evt->tgt; | |
2924 | struct ibmvfc_host *vhost = evt->vhost; | |
2925 | struct ibmvfc_query_tgt *rsp = &evt->xfer_iu->query_tgt; | |
2926 | u32 status = rsp->common.status; | |
2927 | ||
2928 | vhost->discovery_threads--; | |
2929 | ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE); | |
2930 | switch (status) { | |
2931 | case IBMVFC_MAD_SUCCESS: | |
2932 | tgt_dbg(tgt, "Query Target succeeded\n"); | |
2933 | tgt->new_scsi_id = rsp->scsi_id; | |
2934 | if (rsp->scsi_id != tgt->scsi_id) | |
2935 | ibmvfc_init_tgt(tgt, ibmvfc_tgt_implicit_logout); | |
2936 | break; | |
2937 | case IBMVFC_MAD_DRIVER_FAILED: | |
2938 | break; | |
2939 | case IBMVFC_MAD_CRQ_ERROR: | |
2940 | ibmvfc_retry_tgt_init(tgt, ibmvfc_tgt_query_target); | |
2941 | break; | |
2942 | case IBMVFC_MAD_FAILED: | |
2943 | default: | |
2944 | tgt_err(tgt, "Query Target failed: %s (%x:%x) %s (%x) %s (%x) rc=0x%02X\n", | |
2945 | ibmvfc_get_cmd_error(rsp->status, rsp->error), rsp->status, rsp->error, | |
2946 | ibmvfc_get_fc_type(rsp->fc_type), rsp->fc_type, | |
2947 | ibmvfc_get_gs_explain(rsp->fc_explain), rsp->fc_explain, status); | |
2948 | ||
2949 | if ((rsp->status & IBMVFC_FABRIC_MAPPED) == IBMVFC_FABRIC_MAPPED && | |
2950 | rsp->error == IBMVFC_UNABLE_TO_PERFORM_REQ && | |
2951 | rsp->fc_explain == IBMVFC_PORT_NAME_NOT_REG) | |
2952 | ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_DEL_RPORT); | |
2953 | else if (ibmvfc_retry_cmd(rsp->status, rsp->error)) | |
2954 | ibmvfc_retry_tgt_init(tgt, ibmvfc_tgt_query_target); | |
2955 | break; | |
2956 | }; | |
2957 | ||
2958 | kref_put(&tgt->kref, ibmvfc_release_tgt); | |
2959 | ibmvfc_free_event(evt); | |
2960 | wake_up(&vhost->work_wait_q); | |
2961 | } | |
2962 | ||
2963 | /** | |
2964 | * ibmvfc_tgt_query_target - Initiate a Query Target for specified target | |
2965 | * @tgt: ibmvfc target struct | |
2966 | * | |
2967 | **/ | |
2968 | static void ibmvfc_tgt_query_target(struct ibmvfc_target *tgt) | |
2969 | { | |
2970 | struct ibmvfc_query_tgt *query_tgt; | |
2971 | struct ibmvfc_host *vhost = tgt->vhost; | |
2972 | struct ibmvfc_event *evt; | |
2973 | ||
2974 | if (vhost->discovery_threads >= disc_threads) | |
2975 | return; | |
2976 | ||
2977 | kref_get(&tgt->kref); | |
2978 | evt = ibmvfc_get_event(vhost); | |
2979 | vhost->discovery_threads++; | |
2980 | evt->tgt = tgt; | |
2981 | ibmvfc_init_event(evt, ibmvfc_tgt_query_target_done, IBMVFC_MAD_FORMAT); | |
2982 | query_tgt = &evt->iu.query_tgt; | |
2983 | memset(query_tgt, 0, sizeof(*query_tgt)); | |
2984 | query_tgt->common.version = 1; | |
2985 | query_tgt->common.opcode = IBMVFC_QUERY_TARGET; | |
2986 | query_tgt->common.length = sizeof(*query_tgt); | |
2987 | query_tgt->wwpn = tgt->ids.port_name; | |
2988 | ||
2989 | ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_INIT_WAIT); | |
2990 | if (ibmvfc_send_event(evt, vhost, default_timeout)) { | |
2991 | vhost->discovery_threads--; | |
2992 | ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE); | |
2993 | kref_put(&tgt->kref, ibmvfc_release_tgt); | |
2994 | } else | |
2995 | tgt_dbg(tgt, "Sent Query Target\n"); | |
2996 | } | |
2997 | ||
2998 | /** | |
2999 | * ibmvfc_alloc_target - Allocate and initialize an ibmvfc target | |
3000 | * @vhost: ibmvfc host struct | |
3001 | * @scsi_id: SCSI ID to allocate target for | |
3002 | * | |
3003 | * Returns: | |
3004 | * 0 on success / other on failure | |
3005 | **/ | |
3006 | static int ibmvfc_alloc_target(struct ibmvfc_host *vhost, u64 scsi_id) | |
3007 | { | |
3008 | struct ibmvfc_target *tgt; | |
3009 | unsigned long flags; | |
3010 | ||
3011 | spin_lock_irqsave(vhost->host->host_lock, flags); | |
3012 | list_for_each_entry(tgt, &vhost->targets, queue) { | |
3013 | if (tgt->scsi_id == scsi_id) { | |
3014 | if (tgt->need_login) | |
3015 | ibmvfc_init_tgt(tgt, ibmvfc_tgt_implicit_logout); | |
3016 | goto unlock_out; | |
3017 | } | |
3018 | } | |
3019 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
3020 | ||
3021 | tgt = mempool_alloc(vhost->tgt_pool, GFP_KERNEL); | |
3022 | if (!tgt) { | |
3023 | dev_err(vhost->dev, "Target allocation failure for scsi id %08lx\n", | |
3024 | scsi_id); | |
3025 | return -ENOMEM; | |
3026 | } | |
3027 | ||
3028 | tgt->scsi_id = scsi_id; | |
3029 | tgt->new_scsi_id = scsi_id; | |
3030 | tgt->vhost = vhost; | |
3031 | tgt->need_login = 1; | |
3032 | kref_init(&tgt->kref); | |
3033 | ibmvfc_init_tgt(tgt, ibmvfc_tgt_implicit_logout); | |
3034 | spin_lock_irqsave(vhost->host->host_lock, flags); | |
3035 | list_add_tail(&tgt->queue, &vhost->targets); | |
3036 | ||
3037 | unlock_out: | |
3038 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
3039 | return 0; | |
3040 | } | |
3041 | ||
3042 | /** | |
3043 | * ibmvfc_alloc_targets - Allocate and initialize ibmvfc targets | |
3044 | * @vhost: ibmvfc host struct | |
3045 | * | |
3046 | * Returns: | |
3047 | * 0 on success / other on failure | |
3048 | **/ | |
3049 | static int ibmvfc_alloc_targets(struct ibmvfc_host *vhost) | |
3050 | { | |
3051 | int i, rc; | |
3052 | ||
3053 | for (i = 0, rc = 0; !rc && i < vhost->num_targets; i++) | |
3054 | rc = ibmvfc_alloc_target(vhost, | |
3055 | vhost->disc_buf->scsi_id[i] & IBMVFC_DISC_TGT_SCSI_ID_MASK); | |
3056 | ||
3057 | return rc; | |
3058 | } | |
3059 | ||
3060 | /** | |
3061 | * ibmvfc_discover_targets_done - Completion handler for discover targets MAD | |
3062 | * @evt: ibmvfc event struct | |
3063 | * | |
3064 | **/ | |
3065 | static void ibmvfc_discover_targets_done(struct ibmvfc_event *evt) | |
3066 | { | |
3067 | struct ibmvfc_host *vhost = evt->vhost; | |
3068 | struct ibmvfc_discover_targets *rsp = &evt->xfer_iu->discover_targets; | |
3069 | u32 mad_status = rsp->common.status; | |
3070 | ||
3071 | switch (mad_status) { | |
3072 | case IBMVFC_MAD_SUCCESS: | |
3073 | ibmvfc_dbg(vhost, "Discover Targets succeeded\n"); | |
3074 | vhost->num_targets = rsp->num_written; | |
3075 | ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_ALLOC_TGTS); | |
3076 | break; | |
3077 | case IBMVFC_MAD_FAILED: | |
3078 | dev_err(vhost->dev, "Discover Targets failed: %s (%x:%x)\n", | |
3079 | ibmvfc_get_cmd_error(rsp->status, rsp->error), rsp->status, rsp->error); | |
3080 | ibmvfc_retry_host_init(vhost); | |
3081 | break; | |
3082 | case IBMVFC_MAD_DRIVER_FAILED: | |
3083 | break; | |
3084 | default: | |
3085 | dev_err(vhost->dev, "Invalid Discover Targets response: 0x%x\n", mad_status); | |
3086 | ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD); | |
3087 | break; | |
3088 | } | |
3089 | ||
3090 | ibmvfc_free_event(evt); | |
3091 | wake_up(&vhost->work_wait_q); | |
3092 | } | |
3093 | ||
3094 | /** | |
3095 | * ibmvfc_discover_targets - Send Discover Targets MAD | |
3096 | * @vhost: ibmvfc host struct | |
3097 | * | |
3098 | **/ | |
3099 | static void ibmvfc_discover_targets(struct ibmvfc_host *vhost) | |
3100 | { | |
3101 | struct ibmvfc_discover_targets *mad; | |
3102 | struct ibmvfc_event *evt = ibmvfc_get_event(vhost); | |
3103 | ||
3104 | ibmvfc_init_event(evt, ibmvfc_discover_targets_done, IBMVFC_MAD_FORMAT); | |
3105 | mad = &evt->iu.discover_targets; | |
3106 | memset(mad, 0, sizeof(*mad)); | |
3107 | mad->common.version = 1; | |
3108 | mad->common.opcode = IBMVFC_DISC_TARGETS; | |
3109 | mad->common.length = sizeof(*mad); | |
3110 | mad->bufflen = vhost->disc_buf_sz; | |
3111 | mad->buffer.va = vhost->disc_buf_dma; | |
3112 | mad->buffer.len = vhost->disc_buf_sz; | |
3113 | ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT_WAIT); | |
3114 | ||
3115 | if (!ibmvfc_send_event(evt, vhost, default_timeout)) | |
3116 | ibmvfc_dbg(vhost, "Sent discover targets\n"); | |
3117 | else | |
3118 | ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD); | |
3119 | } | |
3120 | ||
3121 | /** | |
3122 | * ibmvfc_npiv_login_done - Completion handler for NPIV Login | |
3123 | * @evt: ibmvfc event struct | |
3124 | * | |
3125 | **/ | |
3126 | static void ibmvfc_npiv_login_done(struct ibmvfc_event *evt) | |
3127 | { | |
3128 | struct ibmvfc_host *vhost = evt->vhost; | |
3129 | u32 mad_status = evt->xfer_iu->npiv_login.common.status; | |
3130 | struct ibmvfc_npiv_login_resp *rsp = &vhost->login_buf->resp; | |
3131 | unsigned int npiv_max_sectors; | |
3132 | ||
3133 | switch (mad_status) { | |
3134 | case IBMVFC_MAD_SUCCESS: | |
3135 | ibmvfc_free_event(evt); | |
3136 | break; | |
3137 | case IBMVFC_MAD_FAILED: | |
3138 | dev_err(vhost->dev, "NPIV Login failed: %s (%x:%x)\n", | |
3139 | ibmvfc_get_cmd_error(rsp->status, rsp->error), rsp->status, rsp->error); | |
3140 | if (ibmvfc_retry_cmd(rsp->status, rsp->error)) | |
3141 | ibmvfc_retry_host_init(vhost); | |
3142 | else | |
3143 | ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD); | |
3144 | ibmvfc_free_event(evt); | |
3145 | return; | |
3146 | case IBMVFC_MAD_CRQ_ERROR: | |
3147 | ibmvfc_retry_host_init(vhost); | |
3148 | case IBMVFC_MAD_DRIVER_FAILED: | |
3149 | ibmvfc_free_event(evt); | |
3150 | return; | |
3151 | default: | |
3152 | dev_err(vhost->dev, "Invalid NPIV Login response: 0x%x\n", mad_status); | |
3153 | ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD); | |
3154 | ibmvfc_free_event(evt); | |
3155 | return; | |
3156 | } | |
3157 | ||
3158 | vhost->client_migrated = 0; | |
3159 | ||
3160 | if (!(rsp->flags & IBMVFC_NATIVE_FC)) { | |
3161 | dev_err(vhost->dev, "Virtual adapter does not support FC. %x\n", | |
3162 | rsp->flags); | |
3163 | ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD); | |
3164 | wake_up(&vhost->work_wait_q); | |
3165 | return; | |
3166 | } | |
3167 | ||
3168 | if (rsp->max_cmds <= IBMVFC_NUM_INTERNAL_REQ) { | |
3169 | dev_err(vhost->dev, "Virtual adapter supported queue depth too small: %d\n", | |
3170 | rsp->max_cmds); | |
3171 | ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD); | |
3172 | wake_up(&vhost->work_wait_q); | |
3173 | return; | |
3174 | } | |
3175 | ||
3176 | npiv_max_sectors = min((uint)(rsp->max_dma_len >> 9), IBMVFC_MAX_SECTORS); | |
3177 | dev_info(vhost->dev, "Host partition: %s, device: %s %s %s max sectors %u\n", | |
3178 | rsp->partition_name, rsp->device_name, rsp->port_loc_code, | |
3179 | rsp->drc_name, npiv_max_sectors); | |
3180 | ||
3181 | fc_host_fabric_name(vhost->host) = rsp->node_name; | |
3182 | fc_host_node_name(vhost->host) = rsp->node_name; | |
3183 | fc_host_port_name(vhost->host) = rsp->port_name; | |
3184 | fc_host_port_id(vhost->host) = rsp->scsi_id; | |
3185 | fc_host_port_type(vhost->host) = FC_PORTTYPE_NPIV; | |
3186 | fc_host_supported_classes(vhost->host) = 0; | |
3187 | if (rsp->service_parms.class1_parms[0] & 0x80000000) | |
3188 | fc_host_supported_classes(vhost->host) |= FC_COS_CLASS1; | |
3189 | if (rsp->service_parms.class2_parms[0] & 0x80000000) | |
3190 | fc_host_supported_classes(vhost->host) |= FC_COS_CLASS2; | |
3191 | if (rsp->service_parms.class3_parms[0] & 0x80000000) | |
3192 | fc_host_supported_classes(vhost->host) |= FC_COS_CLASS3; | |
3193 | fc_host_maxframe_size(vhost->host) = | |
3194 | rsp->service_parms.common.bb_rcv_sz & 0x0fff; | |
3195 | ||
3196 | vhost->host->can_queue = rsp->max_cmds - IBMVFC_NUM_INTERNAL_REQ; | |
3197 | vhost->host->max_sectors = npiv_max_sectors; | |
3198 | ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_QUERY); | |
3199 | wake_up(&vhost->work_wait_q); | |
3200 | } | |
3201 | ||
3202 | /** | |
3203 | * ibmvfc_npiv_login - Sends NPIV login | |
3204 | * @vhost: ibmvfc host struct | |
3205 | * | |
3206 | **/ | |
3207 | static void ibmvfc_npiv_login(struct ibmvfc_host *vhost) | |
3208 | { | |
3209 | struct ibmvfc_npiv_login_mad *mad; | |
3210 | struct ibmvfc_event *evt = ibmvfc_get_event(vhost); | |
3211 | ||
3212 | ibmvfc_gather_partition_info(vhost); | |
3213 | ibmvfc_set_login_info(vhost); | |
3214 | ibmvfc_init_event(evt, ibmvfc_npiv_login_done, IBMVFC_MAD_FORMAT); | |
3215 | ||
3216 | memcpy(vhost->login_buf, &vhost->login_info, sizeof(vhost->login_info)); | |
3217 | mad = &evt->iu.npiv_login; | |
3218 | memset(mad, 0, sizeof(struct ibmvfc_npiv_login_mad)); | |
3219 | mad->common.version = 1; | |
3220 | mad->common.opcode = IBMVFC_NPIV_LOGIN; | |
3221 | mad->common.length = sizeof(struct ibmvfc_npiv_login_mad); | |
3222 | mad->buffer.va = vhost->login_buf_dma; | |
3223 | mad->buffer.len = sizeof(*vhost->login_buf); | |
3224 | ||
3225 | memset(vhost->async_crq.msgs, 0, PAGE_SIZE); | |
3226 | vhost->async_crq.cur = 0; | |
3227 | ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT_WAIT); | |
3228 | ||
3229 | if (!ibmvfc_send_event(evt, vhost, default_timeout)) | |
3230 | ibmvfc_dbg(vhost, "Sent NPIV login\n"); | |
3231 | else | |
3232 | ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD); | |
3233 | }; | |
3234 | ||
3235 | /** | |
3236 | * ibmvfc_dev_init_to_do - Is there target initialization work to do? | |
3237 | * @vhost: ibmvfc host struct | |
3238 | * | |
3239 | * Returns: | |
3240 | * 1 if work to do / 0 if not | |
3241 | **/ | |
3242 | static int ibmvfc_dev_init_to_do(struct ibmvfc_host *vhost) | |
3243 | { | |
3244 | struct ibmvfc_target *tgt; | |
3245 | ||
3246 | list_for_each_entry(tgt, &vhost->targets, queue) { | |
3247 | if (tgt->action == IBMVFC_TGT_ACTION_INIT || | |
3248 | tgt->action == IBMVFC_TGT_ACTION_INIT_WAIT) | |
3249 | return 1; | |
3250 | } | |
3251 | ||
3252 | return 0; | |
3253 | } | |
3254 | ||
3255 | /** | |
3256 | * __ibmvfc_work_to_do - Is there task level work to do? (no locking) | |
3257 | * @vhost: ibmvfc host struct | |
3258 | * | |
3259 | * Returns: | |
3260 | * 1 if work to do / 0 if not | |
3261 | **/ | |
3262 | static int __ibmvfc_work_to_do(struct ibmvfc_host *vhost) | |
3263 | { | |
3264 | struct ibmvfc_target *tgt; | |
3265 | ||
3266 | if (kthread_should_stop()) | |
3267 | return 1; | |
3268 | switch (vhost->action) { | |
3269 | case IBMVFC_HOST_ACTION_NONE: | |
3270 | case IBMVFC_HOST_ACTION_INIT_WAIT: | |
3271 | return 0; | |
3272 | case IBMVFC_HOST_ACTION_TGT_INIT: | |
3273 | case IBMVFC_HOST_ACTION_QUERY_TGTS: | |
3274 | if (vhost->discovery_threads == disc_threads) | |
3275 | return 0; | |
3276 | list_for_each_entry(tgt, &vhost->targets, queue) | |
3277 | if (tgt->action == IBMVFC_TGT_ACTION_INIT) | |
3278 | return 1; | |
3279 | list_for_each_entry(tgt, &vhost->targets, queue) | |
3280 | if (tgt->action == IBMVFC_TGT_ACTION_INIT_WAIT) | |
3281 | return 0; | |
3282 | return 1; | |
3283 | case IBMVFC_HOST_ACTION_INIT: | |
3284 | case IBMVFC_HOST_ACTION_ALLOC_TGTS: | |
3285 | case IBMVFC_HOST_ACTION_TGT_ADD: | |
3286 | case IBMVFC_HOST_ACTION_TGT_DEL: | |
3287 | case IBMVFC_HOST_ACTION_QUERY: | |
3288 | default: | |
3289 | break; | |
3290 | }; | |
3291 | ||
3292 | return 1; | |
3293 | } | |
3294 | ||
3295 | /** | |
3296 | * ibmvfc_work_to_do - Is there task level work to do? | |
3297 | * @vhost: ibmvfc host struct | |
3298 | * | |
3299 | * Returns: | |
3300 | * 1 if work to do / 0 if not | |
3301 | **/ | |
3302 | static int ibmvfc_work_to_do(struct ibmvfc_host *vhost) | |
3303 | { | |
3304 | unsigned long flags; | |
3305 | int rc; | |
3306 | ||
3307 | spin_lock_irqsave(vhost->host->host_lock, flags); | |
3308 | rc = __ibmvfc_work_to_do(vhost); | |
3309 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
3310 | return rc; | |
3311 | } | |
3312 | ||
3313 | /** | |
3314 | * ibmvfc_log_ae - Log async events if necessary | |
3315 | * @vhost: ibmvfc host struct | |
3316 | * @events: events to log | |
3317 | * | |
3318 | **/ | |
3319 | static void ibmvfc_log_ae(struct ibmvfc_host *vhost, int events) | |
3320 | { | |
3321 | if (events & IBMVFC_AE_RSCN) | |
3322 | fc_host_post_event(vhost->host, fc_get_event_number(), FCH_EVT_RSCN, 0); | |
3323 | if ((events & IBMVFC_AE_LINKDOWN) && | |
3324 | vhost->state >= IBMVFC_HALTED) | |
3325 | fc_host_post_event(vhost->host, fc_get_event_number(), FCH_EVT_LINKDOWN, 0); | |
3326 | if ((events & IBMVFC_AE_LINKUP) && | |
3327 | vhost->state == IBMVFC_INITIALIZING) | |
3328 | fc_host_post_event(vhost->host, fc_get_event_number(), FCH_EVT_LINKUP, 0); | |
3329 | } | |
3330 | ||
3331 | /** | |
3332 | * ibmvfc_tgt_add_rport - Tell the FC transport about a new remote port | |
3333 | * @tgt: ibmvfc target struct | |
3334 | * | |
3335 | **/ | |
3336 | static void ibmvfc_tgt_add_rport(struct ibmvfc_target *tgt) | |
3337 | { | |
3338 | struct ibmvfc_host *vhost = tgt->vhost; | |
3339 | struct fc_rport *rport; | |
3340 | unsigned long flags; | |
3341 | ||
3342 | tgt_dbg(tgt, "Adding rport\n"); | |
3343 | rport = fc_remote_port_add(vhost->host, 0, &tgt->ids); | |
3344 | spin_lock_irqsave(vhost->host->host_lock, flags); | |
3345 | tgt->rport = rport; | |
3346 | ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE); | |
3347 | if (rport) { | |
3348 | tgt_dbg(tgt, "rport add succeeded\n"); | |
3349 | rport->maxframe_size = tgt->service_parms.common.bb_rcv_sz & 0x0fff; | |
3350 | rport->supported_classes = 0; | |
3351 | if (tgt->service_parms.class1_parms[0] & 0x80000000) | |
3352 | rport->supported_classes |= FC_COS_CLASS1; | |
3353 | if (tgt->service_parms.class2_parms[0] & 0x80000000) | |
3354 | rport->supported_classes |= FC_COS_CLASS2; | |
3355 | if (tgt->service_parms.class3_parms[0] & 0x80000000) | |
3356 | rport->supported_classes |= FC_COS_CLASS3; | |
3357 | } else | |
3358 | tgt_dbg(tgt, "rport add failed\n"); | |
3359 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
3360 | } | |
3361 | ||
3362 | /** | |
3363 | * ibmvfc_do_work - Do task level work | |
3364 | * @vhost: ibmvfc host struct | |
3365 | * | |
3366 | **/ | |
3367 | static void ibmvfc_do_work(struct ibmvfc_host *vhost) | |
3368 | { | |
3369 | struct ibmvfc_target *tgt; | |
3370 | unsigned long flags; | |
3371 | struct fc_rport *rport; | |
3372 | ||
3373 | ibmvfc_log_ae(vhost, vhost->events_to_log); | |
3374 | spin_lock_irqsave(vhost->host->host_lock, flags); | |
3375 | vhost->events_to_log = 0; | |
3376 | switch (vhost->action) { | |
3377 | case IBMVFC_HOST_ACTION_NONE: | |
3378 | case IBMVFC_HOST_ACTION_INIT_WAIT: | |
3379 | break; | |
3380 | case IBMVFC_HOST_ACTION_INIT: | |
3381 | BUG_ON(vhost->state != IBMVFC_INITIALIZING); | |
3382 | vhost->job_step(vhost); | |
3383 | break; | |
3384 | case IBMVFC_HOST_ACTION_QUERY: | |
3385 | list_for_each_entry(tgt, &vhost->targets, queue) | |
3386 | ibmvfc_init_tgt(tgt, ibmvfc_tgt_query_target); | |
3387 | ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_QUERY_TGTS); | |
3388 | break; | |
3389 | case IBMVFC_HOST_ACTION_QUERY_TGTS: | |
3390 | list_for_each_entry(tgt, &vhost->targets, queue) { | |
3391 | if (tgt->action == IBMVFC_TGT_ACTION_INIT) { | |
3392 | tgt->job_step(tgt); | |
3393 | break; | |
3394 | } | |
3395 | } | |
3396 | ||
3397 | if (!ibmvfc_dev_init_to_do(vhost)) | |
3398 | ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_TGT_DEL); | |
3399 | break; | |
3400 | case IBMVFC_HOST_ACTION_TGT_DEL: | |
3401 | list_for_each_entry(tgt, &vhost->targets, queue) { | |
3402 | if (tgt->action == IBMVFC_TGT_ACTION_DEL_RPORT) { | |
3403 | tgt_dbg(tgt, "Deleting rport\n"); | |
3404 | rport = tgt->rport; | |
3405 | tgt->rport = NULL; | |
3406 | list_del(&tgt->queue); | |
3407 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
3408 | if (rport) | |
3409 | fc_remote_port_delete(rport); | |
3410 | kref_put(&tgt->kref, ibmvfc_release_tgt); | |
3411 | return; | |
3412 | } | |
3413 | } | |
3414 | ||
3415 | if (vhost->state == IBMVFC_INITIALIZING) { | |
3416 | ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT); | |
3417 | vhost->job_step = ibmvfc_discover_targets; | |
3418 | } else { | |
3419 | ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_NONE); | |
3420 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
3421 | scsi_unblock_requests(vhost->host); | |
3422 | wake_up(&vhost->init_wait_q); | |
3423 | return; | |
3424 | } | |
3425 | break; | |
3426 | case IBMVFC_HOST_ACTION_ALLOC_TGTS: | |
3427 | ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_TGT_INIT); | |
3428 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
3429 | ibmvfc_alloc_targets(vhost); | |
3430 | spin_lock_irqsave(vhost->host->host_lock, flags); | |
3431 | break; | |
3432 | case IBMVFC_HOST_ACTION_TGT_INIT: | |
3433 | list_for_each_entry(tgt, &vhost->targets, queue) { | |
3434 | if (tgt->action == IBMVFC_TGT_ACTION_INIT) { | |
3435 | tgt->job_step(tgt); | |
3436 | break; | |
3437 | } | |
3438 | } | |
3439 | ||
3440 | if (!ibmvfc_dev_init_to_do(vhost)) { | |
3441 | ibmvfc_set_host_state(vhost, IBMVFC_ACTIVE); | |
3442 | ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_TGT_ADD); | |
3443 | vhost->init_retries = 0; | |
3444 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
3445 | scsi_unblock_requests(vhost->host); | |
3446 | return; | |
3447 | } | |
3448 | break; | |
3449 | case IBMVFC_HOST_ACTION_TGT_ADD: | |
3450 | list_for_each_entry(tgt, &vhost->targets, queue) { | |
3451 | if (tgt->action == IBMVFC_TGT_ACTION_ADD_RPORT) { | |
3452 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
3453 | ibmvfc_tgt_add_rport(tgt); | |
3454 | return; | |
3455 | } else if (tgt->action == IBMVFC_TGT_ACTION_DEL_RPORT) { | |
3456 | tgt_dbg(tgt, "Deleting rport\n"); | |
3457 | rport = tgt->rport; | |
3458 | tgt->rport = NULL; | |
3459 | list_del(&tgt->queue); | |
3460 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
3461 | if (rport) | |
3462 | fc_remote_port_delete(rport); | |
3463 | kref_put(&tgt->kref, ibmvfc_release_tgt); | |
3464 | return; | |
3465 | } | |
3466 | } | |
3467 | ||
3468 | if (vhost->reinit) { | |
3469 | vhost->reinit = 0; | |
3470 | ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_QUERY); | |
3471 | } else { | |
3472 | ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_NONE); | |
3473 | wake_up(&vhost->init_wait_q); | |
3474 | } | |
3475 | break; | |
3476 | default: | |
3477 | break; | |
3478 | }; | |
3479 | ||
3480 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
3481 | } | |
3482 | ||
3483 | /** | |
3484 | * ibmvfc_work - Do task level work | |
3485 | * @data: ibmvfc host struct | |
3486 | * | |
3487 | * Returns: | |
3488 | * zero | |
3489 | **/ | |
3490 | static int ibmvfc_work(void *data) | |
3491 | { | |
3492 | struct ibmvfc_host *vhost = data; | |
3493 | int rc; | |
3494 | ||
3495 | set_user_nice(current, -20); | |
3496 | ||
3497 | while (1) { | |
3498 | rc = wait_event_interruptible(vhost->work_wait_q, | |
3499 | ibmvfc_work_to_do(vhost)); | |
3500 | ||
3501 | BUG_ON(rc); | |
3502 | ||
3503 | if (kthread_should_stop()) | |
3504 | break; | |
3505 | ||
3506 | ibmvfc_do_work(vhost); | |
3507 | } | |
3508 | ||
3509 | ibmvfc_dbg(vhost, "ibmvfc kthread exiting...\n"); | |
3510 | return 0; | |
3511 | } | |
3512 | ||
3513 | /** | |
3514 | * ibmvfc_init_crq - Initializes and registers CRQ with hypervisor | |
3515 | * @vhost: ibmvfc host struct | |
3516 | * | |
3517 | * Allocates a page for messages, maps it for dma, and registers | |
3518 | * the crq with the hypervisor. | |
3519 | * | |
3520 | * Return value: | |
3521 | * zero on success / other on failure | |
3522 | **/ | |
3523 | static int ibmvfc_init_crq(struct ibmvfc_host *vhost) | |
3524 | { | |
3525 | int rc, retrc = -ENOMEM; | |
3526 | struct device *dev = vhost->dev; | |
3527 | struct vio_dev *vdev = to_vio_dev(dev); | |
3528 | struct ibmvfc_crq_queue *crq = &vhost->crq; | |
3529 | ||
3530 | ENTER; | |
3531 | crq->msgs = (struct ibmvfc_crq *)get_zeroed_page(GFP_KERNEL); | |
3532 | ||
3533 | if (!crq->msgs) | |
3534 | return -ENOMEM; | |
3535 | ||
3536 | crq->size = PAGE_SIZE / sizeof(*crq->msgs); | |
3537 | crq->msg_token = dma_map_single(dev, crq->msgs, | |
3538 | PAGE_SIZE, DMA_BIDIRECTIONAL); | |
3539 | ||
3540 | if (dma_mapping_error(crq->msg_token)) | |
3541 | goto map_failed; | |
3542 | ||
3543 | retrc = rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address, | |
3544 | crq->msg_token, PAGE_SIZE); | |
3545 | ||
3546 | if (rc == H_RESOURCE) | |
3547 | /* maybe kexecing and resource is busy. try a reset */ | |
3548 | retrc = rc = ibmvfc_reset_crq(vhost); | |
3549 | ||
3550 | if (rc == H_CLOSED) | |
3551 | dev_warn(dev, "Partner adapter not ready\n"); | |
3552 | else if (rc) { | |
3553 | dev_warn(dev, "Error %d opening adapter\n", rc); | |
3554 | goto reg_crq_failed; | |
3555 | } | |
3556 | ||
3557 | retrc = 0; | |
3558 | ||
3559 | if ((rc = request_irq(vdev->irq, ibmvfc_interrupt, 0, IBMVFC_NAME, vhost))) { | |
3560 | dev_err(dev, "Couldn't register irq 0x%x. rc=%d\n", vdev->irq, rc); | |
3561 | goto req_irq_failed; | |
3562 | } | |
3563 | ||
3564 | if ((rc = vio_enable_interrupts(vdev))) { | |
3565 | dev_err(dev, "Error %d enabling interrupts\n", rc); | |
3566 | goto req_irq_failed; | |
3567 | } | |
3568 | ||
3569 | crq->cur = 0; | |
3570 | LEAVE; | |
3571 | return retrc; | |
3572 | ||
3573 | req_irq_failed: | |
3574 | do { | |
3575 | rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); | |
3576 | } while (rc == H_BUSY || H_IS_LONG_BUSY(rc)); | |
3577 | reg_crq_failed: | |
3578 | dma_unmap_single(dev, crq->msg_token, PAGE_SIZE, DMA_BIDIRECTIONAL); | |
3579 | map_failed: | |
3580 | free_page((unsigned long)crq->msgs); | |
3581 | return retrc; | |
3582 | } | |
3583 | ||
3584 | /** | |
3585 | * ibmvfc_free_mem - Free memory for vhost | |
3586 | * @vhost: ibmvfc host struct | |
3587 | * | |
3588 | * Return value: | |
3589 | * none | |
3590 | **/ | |
3591 | static void ibmvfc_free_mem(struct ibmvfc_host *vhost) | |
3592 | { | |
3593 | struct ibmvfc_async_crq_queue *async_q = &vhost->async_crq; | |
3594 | ||
3595 | ENTER; | |
3596 | mempool_destroy(vhost->tgt_pool); | |
3597 | kfree(vhost->trace); | |
3598 | dma_free_coherent(vhost->dev, vhost->disc_buf_sz, vhost->disc_buf, | |
3599 | vhost->disc_buf_dma); | |
3600 | dma_free_coherent(vhost->dev, sizeof(*vhost->login_buf), | |
3601 | vhost->login_buf, vhost->login_buf_dma); | |
3602 | dma_pool_destroy(vhost->sg_pool); | |
3603 | dma_unmap_single(vhost->dev, async_q->msg_token, | |
3604 | async_q->size * sizeof(*async_q->msgs), DMA_BIDIRECTIONAL); | |
3605 | free_page((unsigned long)async_q->msgs); | |
3606 | LEAVE; | |
3607 | } | |
3608 | ||
3609 | /** | |
3610 | * ibmvfc_alloc_mem - Allocate memory for vhost | |
3611 | * @vhost: ibmvfc host struct | |
3612 | * | |
3613 | * Return value: | |
3614 | * 0 on success / non-zero on failure | |
3615 | **/ | |
3616 | static int ibmvfc_alloc_mem(struct ibmvfc_host *vhost) | |
3617 | { | |
3618 | struct ibmvfc_async_crq_queue *async_q = &vhost->async_crq; | |
3619 | struct device *dev = vhost->dev; | |
3620 | ||
3621 | ENTER; | |
3622 | async_q->msgs = (struct ibmvfc_async_crq *)get_zeroed_page(GFP_KERNEL); | |
3623 | if (!async_q->msgs) { | |
3624 | dev_err(dev, "Couldn't allocate async queue.\n"); | |
3625 | goto nomem; | |
3626 | } | |
3627 | ||
3628 | async_q->size = PAGE_SIZE / sizeof(struct ibmvfc_async_crq); | |
3629 | async_q->msg_token = dma_map_single(dev, async_q->msgs, | |
3630 | async_q->size * sizeof(*async_q->msgs), | |
3631 | DMA_BIDIRECTIONAL); | |
3632 | ||
3633 | if (dma_mapping_error(async_q->msg_token)) { | |
3634 | dev_err(dev, "Failed to map async queue\n"); | |
3635 | goto free_async_crq; | |
3636 | } | |
3637 | ||
3638 | vhost->sg_pool = dma_pool_create(IBMVFC_NAME, dev, | |
3639 | SG_ALL * sizeof(struct srp_direct_buf), | |
3640 | sizeof(struct srp_direct_buf), 0); | |
3641 | ||
3642 | if (!vhost->sg_pool) { | |
3643 | dev_err(dev, "Failed to allocate sg pool\n"); | |
3644 | goto unmap_async_crq; | |
3645 | } | |
3646 | ||
3647 | vhost->login_buf = dma_alloc_coherent(dev, sizeof(*vhost->login_buf), | |
3648 | &vhost->login_buf_dma, GFP_KERNEL); | |
3649 | ||
3650 | if (!vhost->login_buf) { | |
3651 | dev_err(dev, "Couldn't allocate NPIV login buffer\n"); | |
3652 | goto free_sg_pool; | |
3653 | } | |
3654 | ||
3655 | vhost->disc_buf_sz = sizeof(vhost->disc_buf->scsi_id[0]) * max_targets; | |
3656 | vhost->disc_buf = dma_alloc_coherent(dev, vhost->disc_buf_sz, | |
3657 | &vhost->disc_buf_dma, GFP_KERNEL); | |
3658 | ||
3659 | if (!vhost->disc_buf) { | |
3660 | dev_err(dev, "Couldn't allocate Discover Targets buffer\n"); | |
3661 | goto free_login_buffer; | |
3662 | } | |
3663 | ||
3664 | vhost->trace = kcalloc(IBMVFC_NUM_TRACE_ENTRIES, | |
3665 | sizeof(struct ibmvfc_trace_entry), GFP_KERNEL); | |
3666 | ||
3667 | if (!vhost->trace) | |
3668 | goto free_disc_buffer; | |
3669 | ||
3670 | vhost->tgt_pool = mempool_create_kzalloc_pool(IBMVFC_TGT_MEMPOOL_SZ, | |
3671 | sizeof(struct ibmvfc_target)); | |
3672 | ||
3673 | if (!vhost->tgt_pool) { | |
3674 | dev_err(dev, "Couldn't allocate target memory pool\n"); | |
3675 | goto free_trace; | |
3676 | } | |
3677 | ||
3678 | LEAVE; | |
3679 | return 0; | |
3680 | ||
3681 | free_trace: | |
3682 | kfree(vhost->trace); | |
3683 | free_disc_buffer: | |
3684 | dma_free_coherent(dev, vhost->disc_buf_sz, vhost->disc_buf, | |
3685 | vhost->disc_buf_dma); | |
3686 | free_login_buffer: | |
3687 | dma_free_coherent(dev, sizeof(*vhost->login_buf), | |
3688 | vhost->login_buf, vhost->login_buf_dma); | |
3689 | free_sg_pool: | |
3690 | dma_pool_destroy(vhost->sg_pool); | |
3691 | unmap_async_crq: | |
3692 | dma_unmap_single(dev, async_q->msg_token, | |
3693 | async_q->size * sizeof(*async_q->msgs), DMA_BIDIRECTIONAL); | |
3694 | free_async_crq: | |
3695 | free_page((unsigned long)async_q->msgs); | |
3696 | nomem: | |
3697 | LEAVE; | |
3698 | return -ENOMEM; | |
3699 | } | |
3700 | ||
3701 | /** | |
3702 | * ibmvfc_probe - Adapter hot plug add entry point | |
3703 | * @vdev: vio device struct | |
3704 | * @id: vio device id struct | |
3705 | * | |
3706 | * Return value: | |
3707 | * 0 on success / non-zero on failure | |
3708 | **/ | |
3709 | static int ibmvfc_probe(struct vio_dev *vdev, const struct vio_device_id *id) | |
3710 | { | |
3711 | struct ibmvfc_host *vhost; | |
3712 | struct Scsi_Host *shost; | |
3713 | struct device *dev = &vdev->dev; | |
3714 | int rc = -ENOMEM; | |
3715 | ||
3716 | ENTER; | |
3717 | shost = scsi_host_alloc(&driver_template, sizeof(*vhost)); | |
3718 | if (!shost) { | |
3719 | dev_err(dev, "Couldn't allocate host data\n"); | |
3720 | goto out; | |
3721 | } | |
3722 | ||
3723 | shost->transportt = ibmvfc_transport_template; | |
3724 | shost->can_queue = max_requests; | |
3725 | shost->max_lun = max_lun; | |
3726 | shost->max_id = max_targets; | |
3727 | shost->max_sectors = IBMVFC_MAX_SECTORS; | |
3728 | shost->max_cmd_len = IBMVFC_MAX_CDB_LEN; | |
3729 | shost->unique_id = shost->host_no; | |
3730 | ||
3731 | vhost = shost_priv(shost); | |
3732 | INIT_LIST_HEAD(&vhost->sent); | |
3733 | INIT_LIST_HEAD(&vhost->free); | |
3734 | INIT_LIST_HEAD(&vhost->targets); | |
3735 | sprintf(vhost->name, IBMVFC_NAME); | |
3736 | vhost->host = shost; | |
3737 | vhost->dev = dev; | |
3738 | vhost->partition_number = -1; | |
3739 | vhost->log_level = log_level; | |
3740 | strcpy(vhost->partition_name, "UNKNOWN"); | |
3741 | init_waitqueue_head(&vhost->work_wait_q); | |
3742 | init_waitqueue_head(&vhost->init_wait_q); | |
3743 | ||
3744 | if ((rc = ibmvfc_alloc_mem(vhost))) | |
3745 | goto free_scsi_host; | |
3746 | ||
3747 | vhost->work_thread = kthread_run(ibmvfc_work, vhost, "%s_%d", IBMVFC_NAME, | |
3748 | shost->host_no); | |
3749 | ||
3750 | if (IS_ERR(vhost->work_thread)) { | |
3751 | dev_err(dev, "Couldn't create kernel thread: %ld\n", | |
3752 | PTR_ERR(vhost->work_thread)); | |
3753 | goto free_host_mem; | |
3754 | } | |
3755 | ||
3756 | if ((rc = ibmvfc_init_crq(vhost))) { | |
3757 | dev_err(dev, "Couldn't initialize crq. rc=%d\n", rc); | |
3758 | goto kill_kthread; | |
3759 | } | |
3760 | ||
3761 | if ((rc = ibmvfc_init_event_pool(vhost))) { | |
3762 | dev_err(dev, "Couldn't initialize event pool. rc=%d\n", rc); | |
3763 | goto release_crq; | |
3764 | } | |
3765 | ||
3766 | if ((rc = scsi_add_host(shost, dev))) | |
3767 | goto release_event_pool; | |
3768 | ||
3769 | if ((rc = ibmvfc_create_trace_file(&shost->shost_dev.kobj, | |
3770 | &ibmvfc_trace_attr))) { | |
3771 | dev_err(dev, "Failed to create trace file. rc=%d\n", rc); | |
3772 | goto remove_shost; | |
3773 | } | |
3774 | ||
3775 | dev_set_drvdata(dev, vhost); | |
3776 | spin_lock(&ibmvfc_driver_lock); | |
3777 | list_add_tail(&vhost->queue, &ibmvfc_head); | |
3778 | spin_unlock(&ibmvfc_driver_lock); | |
3779 | ||
3780 | ibmvfc_send_crq_init(vhost); | |
3781 | scsi_scan_host(shost); | |
3782 | return 0; | |
3783 | ||
3784 | remove_shost: | |
3785 | scsi_remove_host(shost); | |
3786 | release_event_pool: | |
3787 | ibmvfc_free_event_pool(vhost); | |
3788 | release_crq: | |
3789 | ibmvfc_release_crq_queue(vhost); | |
3790 | kill_kthread: | |
3791 | kthread_stop(vhost->work_thread); | |
3792 | free_host_mem: | |
3793 | ibmvfc_free_mem(vhost); | |
3794 | free_scsi_host: | |
3795 | scsi_host_put(shost); | |
3796 | out: | |
3797 | LEAVE; | |
3798 | return rc; | |
3799 | } | |
3800 | ||
3801 | /** | |
3802 | * ibmvfc_remove - Adapter hot plug remove entry point | |
3803 | * @vdev: vio device struct | |
3804 | * | |
3805 | * Return value: | |
3806 | * 0 | |
3807 | **/ | |
3808 | static int ibmvfc_remove(struct vio_dev *vdev) | |
3809 | { | |
3810 | struct ibmvfc_host *vhost = dev_get_drvdata(&vdev->dev); | |
3811 | unsigned long flags; | |
3812 | ||
3813 | ENTER; | |
3814 | ibmvfc_remove_trace_file(&vhost->host->shost_dev.kobj, &ibmvfc_trace_attr); | |
2d0da2a4 BK |
3815 | ibmvfc_link_down(vhost, IBMVFC_HOST_OFFLINE); |
3816 | ibmvfc_wait_while_resetting(vhost); | |
3817 | ibmvfc_release_crq_queue(vhost); | |
072b91f9 BK |
3818 | kthread_stop(vhost->work_thread); |
3819 | fc_remove_host(vhost->host); | |
3820 | scsi_remove_host(vhost->host); | |
072b91f9 BK |
3821 | |
3822 | spin_lock_irqsave(vhost->host->host_lock, flags); | |
3823 | ibmvfc_purge_requests(vhost, DID_ERROR); | |
3824 | ibmvfc_free_event_pool(vhost); | |
3825 | spin_unlock_irqrestore(vhost->host->host_lock, flags); | |
3826 | ||
3827 | ibmvfc_free_mem(vhost); | |
3828 | spin_lock(&ibmvfc_driver_lock); | |
3829 | list_del(&vhost->queue); | |
3830 | spin_unlock(&ibmvfc_driver_lock); | |
3831 | scsi_host_put(vhost->host); | |
3832 | LEAVE; | |
3833 | return 0; | |
3834 | } | |
3835 | ||
39c1ffec BK |
3836 | /** |
3837 | * ibmvfc_get_desired_dma - Calculate DMA resources needed by the driver | |
3838 | * @vdev: vio device struct | |
3839 | * | |
3840 | * Return value: | |
3841 | * Number of bytes the driver will need to DMA map at the same time in | |
3842 | * order to perform well. | |
3843 | */ | |
3844 | static unsigned long ibmvfc_get_desired_dma(struct vio_dev *vdev) | |
3845 | { | |
3846 | unsigned long pool_dma = max_requests * sizeof(union ibmvfc_iu); | |
3847 | return pool_dma + ((512 * 1024) * driver_template.cmd_per_lun); | |
3848 | } | |
3849 | ||
072b91f9 BK |
3850 | static struct vio_device_id ibmvfc_device_table[] __devinitdata = { |
3851 | {"fcp", "IBM,vfc-client"}, | |
3852 | { "", "" } | |
3853 | }; | |
3854 | MODULE_DEVICE_TABLE(vio, ibmvfc_device_table); | |
3855 | ||
3856 | static struct vio_driver ibmvfc_driver = { | |
3857 | .id_table = ibmvfc_device_table, | |
3858 | .probe = ibmvfc_probe, | |
3859 | .remove = ibmvfc_remove, | |
39c1ffec | 3860 | .get_desired_dma = ibmvfc_get_desired_dma, |
072b91f9 BK |
3861 | .driver = { |
3862 | .name = IBMVFC_NAME, | |
3863 | .owner = THIS_MODULE, | |
3864 | } | |
3865 | }; | |
3866 | ||
3867 | static struct fc_function_template ibmvfc_transport_functions = { | |
3868 | .show_host_fabric_name = 1, | |
3869 | .show_host_node_name = 1, | |
3870 | .show_host_port_name = 1, | |
3871 | .show_host_supported_classes = 1, | |
3872 | .show_host_port_type = 1, | |
3873 | .show_host_port_id = 1, | |
3874 | ||
3875 | .get_host_port_state = ibmvfc_get_host_port_state, | |
3876 | .show_host_port_state = 1, | |
3877 | ||
3878 | .get_host_speed = ibmvfc_get_host_speed, | |
3879 | .show_host_speed = 1, | |
3880 | ||
3881 | .issue_fc_host_lip = ibmvfc_issue_fc_host_lip, | |
3882 | .terminate_rport_io = ibmvfc_terminate_rport_io, | |
3883 | ||
3884 | .show_rport_maxframe_size = 1, | |
3885 | .show_rport_supported_classes = 1, | |
3886 | ||
3887 | .set_rport_dev_loss_tmo = ibmvfc_set_rport_dev_loss_tmo, | |
3888 | .show_rport_dev_loss_tmo = 1, | |
3889 | ||
3890 | .get_starget_node_name = ibmvfc_get_starget_node_name, | |
3891 | .show_starget_node_name = 1, | |
3892 | ||
3893 | .get_starget_port_name = ibmvfc_get_starget_port_name, | |
3894 | .show_starget_port_name = 1, | |
3895 | ||
3896 | .get_starget_port_id = ibmvfc_get_starget_port_id, | |
3897 | .show_starget_port_id = 1, | |
3898 | }; | |
3899 | ||
3900 | /** | |
3901 | * ibmvfc_module_init - Initialize the ibmvfc module | |
3902 | * | |
3903 | * Return value: | |
3904 | * 0 on success / other on failure | |
3905 | **/ | |
3906 | static int __init ibmvfc_module_init(void) | |
3907 | { | |
3908 | int rc; | |
3909 | ||
3910 | if (!firmware_has_feature(FW_FEATURE_VIO)) | |
3911 | return -ENODEV; | |
3912 | ||
3913 | printk(KERN_INFO IBMVFC_NAME": IBM Virtual Fibre Channel Driver version: %s %s\n", | |
3914 | IBMVFC_DRIVER_VERSION, IBMVFC_DRIVER_DATE); | |
3915 | ||
3916 | ibmvfc_transport_template = fc_attach_transport(&ibmvfc_transport_functions); | |
3917 | if (!ibmvfc_transport_template) | |
3918 | return -ENOMEM; | |
3919 | ||
3920 | rc = vio_register_driver(&ibmvfc_driver); | |
3921 | if (rc) | |
3922 | fc_release_transport(ibmvfc_transport_template); | |
3923 | return rc; | |
3924 | } | |
3925 | ||
3926 | /** | |
3927 | * ibmvfc_module_exit - Teardown the ibmvfc module | |
3928 | * | |
3929 | * Return value: | |
3930 | * nothing | |
3931 | **/ | |
3932 | static void __exit ibmvfc_module_exit(void) | |
3933 | { | |
3934 | vio_unregister_driver(&ibmvfc_driver); | |
3935 | fc_release_transport(ibmvfc_transport_template); | |
3936 | } | |
3937 | ||
3938 | module_init(ibmvfc_module_init); | |
3939 | module_exit(ibmvfc_module_exit); |