2 * ibmvfc.c -- driver for IBM Power Virtual Fibre Channel Adapter
4 * Written By: Brian King <brking@linux.vnet.ibm.com>, IBM Corporation
6 * Copyright (C) IBM Corporation, 2008
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.
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.
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
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>
32 #include <linux/stringify.h>
33 #include <asm/firmware.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>
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
;
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
);
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
);
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
) "]");
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_TRANSPORT_DISRUPTED
, 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" },
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_ERROR
, 0, 1, "invalid parameter" },
119 { IBMVFC_VIOS_FAILURE
, IBMVFC_MISSING_PARAMETER
, DID_ERROR
, 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_ERROR
, 0, 1, "transaction cancelled" },
122 { IBMVFC_VIOS_FAILURE
, IBMVFC_TRANS_CANCELLED_IMPLICIT
, DID_ERROR
, 0, 1, "transaction cancelled implicit" },
123 { IBMVFC_VIOS_FAILURE
, IBMVFC_INSUFFICIENT_RESOURCE
, DID_REQUEUE
, 1, 1, "insufficient resources" },
124 { IBMVFC_VIOS_FAILURE
, IBMVFC_PLOGI_REQUIRED
, DID_ERROR
, 0, 1, "port login required" },
125 { IBMVFC_VIOS_FAILURE
, IBMVFC_COMMAND_FAILED
, DID_ERROR
, 1, 1, "command failed" },
127 { IBMVFC_FC_FAILURE
, IBMVFC_INVALID_ELS_CMD_CODE
, DID_ERROR
, 0, 1, "invalid ELS command code" },
128 { IBMVFC_FC_FAILURE
, IBMVFC_INVALID_VERSION
, DID_ERROR
, 0, 1, "invalid version level" },
129 { IBMVFC_FC_FAILURE
, IBMVFC_LOGICAL_ERROR
, DID_ERROR
, 1, 1, "logical error" },
130 { IBMVFC_FC_FAILURE
, IBMVFC_INVALID_CT_IU_SIZE
, DID_ERROR
, 0, 1, "invalid CT_IU size" },
131 { IBMVFC_FC_FAILURE
, IBMVFC_LOGICAL_BUSY
, DID_REQUEUE
, 1, 0, "logical busy" },
132 { IBMVFC_FC_FAILURE
, IBMVFC_PROTOCOL_ERROR
, DID_ERROR
, 1, 1, "protocol error" },
133 { IBMVFC_FC_FAILURE
, IBMVFC_UNABLE_TO_PERFORM_REQ
, DID_ERROR
, 1, 1, "unable to perform request" },
134 { IBMVFC_FC_FAILURE
, IBMVFC_CMD_NOT_SUPPORTED
, DID_ERROR
, 0, 0, "command not supported" },
135 { IBMVFC_FC_FAILURE
, IBMVFC_SERVER_NOT_AVAIL
, DID_ERROR
, 0, 1, "server not available" },
136 { IBMVFC_FC_FAILURE
, IBMVFC_CMD_IN_PROGRESS
, DID_ERROR
, 0, 1, "command already in progress" },
137 { IBMVFC_FC_FAILURE
, IBMVFC_VENDOR_SPECIFIC
, DID_ERROR
, 1, 1, "vendor specific" },
139 { IBMVFC_FC_SCSI_ERROR
, 0, DID_OK
, 1, 0, "SCSI error" },
142 static void ibmvfc_npiv_login(struct ibmvfc_host
*);
143 static void ibmvfc_tgt_send_prli(struct ibmvfc_target
*);
144 static void ibmvfc_tgt_send_plogi(struct ibmvfc_target
*);
145 static void ibmvfc_tgt_query_target(struct ibmvfc_target
*);
147 static const char *unknown_error
= "unknown error";
149 #ifdef CONFIG_SCSI_IBMVFC_TRACE
151 * ibmvfc_trc_start - Log a start trace entry
152 * @evt: ibmvfc event struct
155 static void ibmvfc_trc_start(struct ibmvfc_event
*evt
)
157 struct ibmvfc_host
*vhost
= evt
->vhost
;
158 struct ibmvfc_cmd
*vfc_cmd
= &evt
->iu
.cmd
;
159 struct ibmvfc_mad_common
*mad
= &evt
->iu
.mad_common
;
160 struct ibmvfc_trace_entry
*entry
;
162 entry
= &vhost
->trace
[vhost
->trace_index
++];
164 entry
->time
= jiffies
;
165 entry
->fmt
= evt
->crq
.format
;
166 entry
->type
= IBMVFC_TRC_START
;
168 switch (entry
->fmt
) {
169 case IBMVFC_CMD_FORMAT
:
170 entry
->op_code
= vfc_cmd
->iu
.cdb
[0];
171 entry
->scsi_id
= vfc_cmd
->tgt_scsi_id
;
172 entry
->lun
= scsilun_to_int(&vfc_cmd
->iu
.lun
);
173 entry
->tmf_flags
= vfc_cmd
->iu
.tmf_flags
;
174 entry
->u
.start
.xfer_len
= vfc_cmd
->iu
.xfer_len
;
176 case IBMVFC_MAD_FORMAT
:
177 entry
->op_code
= mad
->opcode
;
185 * ibmvfc_trc_end - Log an end trace entry
186 * @evt: ibmvfc event struct
189 static void ibmvfc_trc_end(struct ibmvfc_event
*evt
)
191 struct ibmvfc_host
*vhost
= evt
->vhost
;
192 struct ibmvfc_cmd
*vfc_cmd
= &evt
->xfer_iu
->cmd
;
193 struct ibmvfc_mad_common
*mad
= &evt
->xfer_iu
->mad_common
;
194 struct ibmvfc_trace_entry
*entry
= &vhost
->trace
[vhost
->trace_index
++];
197 entry
->time
= jiffies
;
198 entry
->fmt
= evt
->crq
.format
;
199 entry
->type
= IBMVFC_TRC_END
;
201 switch (entry
->fmt
) {
202 case IBMVFC_CMD_FORMAT
:
203 entry
->op_code
= vfc_cmd
->iu
.cdb
[0];
204 entry
->scsi_id
= vfc_cmd
->tgt_scsi_id
;
205 entry
->lun
= scsilun_to_int(&vfc_cmd
->iu
.lun
);
206 entry
->tmf_flags
= vfc_cmd
->iu
.tmf_flags
;
207 entry
->u
.end
.status
= vfc_cmd
->status
;
208 entry
->u
.end
.error
= vfc_cmd
->error
;
209 entry
->u
.end
.fcp_rsp_flags
= vfc_cmd
->rsp
.flags
;
210 entry
->u
.end
.rsp_code
= vfc_cmd
->rsp
.data
.info
.rsp_code
;
211 entry
->u
.end
.scsi_status
= vfc_cmd
->rsp
.scsi_status
;
213 case IBMVFC_MAD_FORMAT
:
214 entry
->op_code
= mad
->opcode
;
215 entry
->u
.end
.status
= mad
->status
;
224 #define ibmvfc_trc_start(evt) do { } while (0)
225 #define ibmvfc_trc_end(evt) do { } while (0)
229 * ibmvfc_get_err_index - Find the index into cmd_status for the fcp response
230 * @status: status / error class
234 * index into cmd_status / -EINVAL on failure
236 static int ibmvfc_get_err_index(u16 status
, u16 error
)
240 for (i
= 0; i
< ARRAY_SIZE(cmd_status
); i
++)
241 if ((cmd_status
[i
].status
& status
) == cmd_status
[i
].status
&&
242 cmd_status
[i
].error
== error
)
249 * ibmvfc_get_cmd_error - Find the error description for the fcp response
250 * @status: status / error class
254 * error description string
256 static const char *ibmvfc_get_cmd_error(u16 status
, u16 error
)
258 int rc
= ibmvfc_get_err_index(status
, error
);
260 return cmd_status
[rc
].name
;
261 return unknown_error
;
265 * ibmvfc_get_err_result - Find the scsi status to return for the fcp response
266 * @vfc_cmd: ibmvfc command struct
269 * SCSI result value to return for completed command
271 static int ibmvfc_get_err_result(struct ibmvfc_cmd
*vfc_cmd
)
274 struct ibmvfc_fcp_rsp
*rsp
= &vfc_cmd
->rsp
;
275 int fc_rsp_len
= rsp
->fcp_rsp_len
;
277 if ((rsp
->flags
& FCP_RSP_LEN_VALID
) &&
278 ((fc_rsp_len
&& fc_rsp_len
!= 4 && fc_rsp_len
!= 8) ||
279 rsp
->data
.info
.rsp_code
))
280 return DID_ERROR
<< 16;
282 err
= ibmvfc_get_err_index(vfc_cmd
->status
, vfc_cmd
->error
);
284 return rsp
->scsi_status
| (cmd_status
[err
].result
<< 16);
285 return rsp
->scsi_status
| (DID_ERROR
<< 16);
289 * ibmvfc_retry_cmd - Determine if error status is retryable
290 * @status: status / error class
294 * 1 if error should be retried / 0 if it should not
296 static int ibmvfc_retry_cmd(u16 status
, u16 error
)
298 int rc
= ibmvfc_get_err_index(status
, error
);
301 return cmd_status
[rc
].retry
;
305 static const char *unknown_fc_explain
= "unknown fc explain";
307 static const struct {
311 { 0x00, "no additional explanation" },
312 { 0x01, "service parameter error - options" },
313 { 0x03, "service parameter error - initiator control" },
314 { 0x05, "service parameter error - recipient control" },
315 { 0x07, "service parameter error - received data field size" },
316 { 0x09, "service parameter error - concurrent seq" },
317 { 0x0B, "service parameter error - credit" },
318 { 0x0D, "invalid N_Port/F_Port_Name" },
319 { 0x0E, "invalid node/Fabric Name" },
320 { 0x0F, "invalid common service parameters" },
321 { 0x11, "invalid association header" },
322 { 0x13, "association header required" },
323 { 0x15, "invalid originator S_ID" },
324 { 0x17, "invalid OX_ID-RX-ID combination" },
325 { 0x19, "command (request) already in progress" },
326 { 0x1E, "N_Port Login requested" },
327 { 0x1F, "Invalid N_Port_ID" },
330 static const struct {
334 { 0x00, "no additional explanation" },
335 { 0x01, "port identifier not registered" },
336 { 0x02, "port name not registered" },
337 { 0x03, "node name not registered" },
338 { 0x04, "class of service not registered" },
339 { 0x06, "initial process associator not registered" },
340 { 0x07, "FC-4 TYPEs not registered" },
341 { 0x08, "symbolic port name not registered" },
342 { 0x09, "symbolic node name not registered" },
343 { 0x0A, "port type not registered" },
344 { 0xF0, "authorization exception" },
345 { 0xF1, "authentication exception" },
346 { 0xF2, "data base full" },
347 { 0xF3, "data base empty" },
348 { 0xF4, "processing request" },
349 { 0xF5, "unable to verify connection" },
350 { 0xF6, "devices not in a common zone" },
354 * ibmvfc_get_ls_explain - Return the FC Explain description text
355 * @status: FC Explain status
360 static const char *ibmvfc_get_ls_explain(u16 status
)
364 for (i
= 0; i
< ARRAY_SIZE(ls_explain
); i
++)
365 if (ls_explain
[i
].fc_explain
== status
)
366 return ls_explain
[i
].name
;
368 return unknown_fc_explain
;
372 * ibmvfc_get_gs_explain - Return the FC Explain description text
373 * @status: FC Explain status
378 static const char *ibmvfc_get_gs_explain(u16 status
)
382 for (i
= 0; i
< ARRAY_SIZE(gs_explain
); i
++)
383 if (gs_explain
[i
].fc_explain
== status
)
384 return gs_explain
[i
].name
;
386 return unknown_fc_explain
;
389 static const struct {
390 enum ibmvfc_fc_type fc_type
;
393 { IBMVFC_FABRIC_REJECT
, "fabric reject" },
394 { IBMVFC_PORT_REJECT
, "port reject" },
395 { IBMVFC_LS_REJECT
, "ELS reject" },
396 { IBMVFC_FABRIC_BUSY
, "fabric busy" },
397 { IBMVFC_PORT_BUSY
, "port busy" },
398 { IBMVFC_BASIC_REJECT
, "basic reject" },
401 static const char *unknown_fc_type
= "unknown fc type";
404 * ibmvfc_get_fc_type - Return the FC Type description text
405 * @status: FC Type error status
410 static const char *ibmvfc_get_fc_type(u16 status
)
414 for (i
= 0; i
< ARRAY_SIZE(fc_type
); i
++)
415 if (fc_type
[i
].fc_type
== status
)
416 return fc_type
[i
].name
;
418 return unknown_fc_type
;
422 * ibmvfc_set_tgt_action - Set the next init action for the target
423 * @tgt: ibmvfc target struct
424 * @action: action to perform
427 static void ibmvfc_set_tgt_action(struct ibmvfc_target
*tgt
,
428 enum ibmvfc_target_action action
)
430 switch (tgt
->action
) {
431 case IBMVFC_TGT_ACTION_DEL_RPORT
:
434 if (action
== IBMVFC_TGT_ACTION_DEL_RPORT
)
436 tgt
->action
= action
;
442 * ibmvfc_set_host_state - Set the state for the host
443 * @vhost: ibmvfc host struct
444 * @state: state to set host to
447 * 0 if state changed / non-zero if not changed
449 static int ibmvfc_set_host_state(struct ibmvfc_host
*vhost
,
450 enum ibmvfc_host_state state
)
454 switch (vhost
->state
) {
455 case IBMVFC_HOST_OFFLINE
:
459 vhost
->state
= state
;
467 * ibmvfc_set_host_action - Set the next init action for the host
468 * @vhost: ibmvfc host struct
469 * @action: action to perform
472 static void ibmvfc_set_host_action(struct ibmvfc_host
*vhost
,
473 enum ibmvfc_host_action action
)
476 case IBMVFC_HOST_ACTION_ALLOC_TGTS
:
477 if (vhost
->action
== IBMVFC_HOST_ACTION_INIT_WAIT
)
478 vhost
->action
= action
;
480 case IBMVFC_HOST_ACTION_INIT_WAIT
:
481 if (vhost
->action
== IBMVFC_HOST_ACTION_INIT
)
482 vhost
->action
= action
;
484 case IBMVFC_HOST_ACTION_QUERY
:
485 switch (vhost
->action
) {
486 case IBMVFC_HOST_ACTION_INIT_WAIT
:
487 case IBMVFC_HOST_ACTION_NONE
:
488 case IBMVFC_HOST_ACTION_TGT_DEL_FAILED
:
489 vhost
->action
= action
;
495 case IBMVFC_HOST_ACTION_TGT_INIT
:
496 if (vhost
->action
== IBMVFC_HOST_ACTION_ALLOC_TGTS
)
497 vhost
->action
= action
;
499 case IBMVFC_HOST_ACTION_INIT
:
500 case IBMVFC_HOST_ACTION_TGT_DEL
:
501 case IBMVFC_HOST_ACTION_QUERY_TGTS
:
502 case IBMVFC_HOST_ACTION_TGT_DEL_FAILED
:
503 case IBMVFC_HOST_ACTION_NONE
:
505 vhost
->action
= action
;
511 * ibmvfc_reinit_host - Re-start host initialization (no NPIV Login)
512 * @vhost: ibmvfc host struct
517 static void ibmvfc_reinit_host(struct ibmvfc_host
*vhost
)
519 if (vhost
->action
== IBMVFC_HOST_ACTION_NONE
) {
520 if (!ibmvfc_set_host_state(vhost
, IBMVFC_INITIALIZING
)) {
521 scsi_block_requests(vhost
->host
);
522 ibmvfc_set_host_action(vhost
, IBMVFC_HOST_ACTION_QUERY
);
527 wake_up(&vhost
->work_wait_q
);
531 * ibmvfc_link_down - Handle a link down event from the adapter
532 * @vhost: ibmvfc host struct
533 * @state: ibmvfc host state to enter
536 static void ibmvfc_link_down(struct ibmvfc_host
*vhost
,
537 enum ibmvfc_host_state state
)
539 struct ibmvfc_target
*tgt
;
542 scsi_block_requests(vhost
->host
);
543 list_for_each_entry(tgt
, &vhost
->targets
, queue
)
544 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_DEL_RPORT
);
545 ibmvfc_set_host_state(vhost
, state
);
546 ibmvfc_set_host_action(vhost
, IBMVFC_HOST_ACTION_TGT_DEL
);
547 vhost
->events_to_log
|= IBMVFC_AE_LINKDOWN
;
548 wake_up(&vhost
->work_wait_q
);
553 * ibmvfc_init_host - Start host initialization
554 * @vhost: ibmvfc host struct
555 * @relogin: is this a re-login?
560 static void ibmvfc_init_host(struct ibmvfc_host
*vhost
, int relogin
)
562 struct ibmvfc_target
*tgt
;
564 if (vhost
->action
== IBMVFC_HOST_ACTION_INIT_WAIT
) {
565 if (++vhost
->init_retries
> IBMVFC_MAX_HOST_INIT_RETRIES
) {
567 "Host initialization retries exceeded. Taking adapter offline\n");
568 ibmvfc_link_down(vhost
, IBMVFC_HOST_OFFLINE
);
573 if (!ibmvfc_set_host_state(vhost
, IBMVFC_INITIALIZING
)) {
575 memset(vhost
->async_crq
.msgs
, 0, PAGE_SIZE
);
576 vhost
->async_crq
.cur
= 0;
579 list_for_each_entry(tgt
, &vhost
->targets
, queue
)
581 scsi_block_requests(vhost
->host
);
582 ibmvfc_set_host_action(vhost
, IBMVFC_HOST_ACTION_INIT
);
583 vhost
->job_step
= ibmvfc_npiv_login
;
584 wake_up(&vhost
->work_wait_q
);
589 * ibmvfc_send_crq - Send a CRQ
590 * @vhost: ibmvfc host struct
591 * @word1: the first 64 bits of the data
592 * @word2: the second 64 bits of the data
595 * 0 on success / other on failure
597 static int ibmvfc_send_crq(struct ibmvfc_host
*vhost
, u64 word1
, u64 word2
)
599 struct vio_dev
*vdev
= to_vio_dev(vhost
->dev
);
600 return plpar_hcall_norets(H_SEND_CRQ
, vdev
->unit_address
, word1
, word2
);
604 * ibmvfc_send_crq_init - Send a CRQ init message
605 * @vhost: ibmvfc host struct
608 * 0 on success / other on failure
610 static int ibmvfc_send_crq_init(struct ibmvfc_host
*vhost
)
612 ibmvfc_dbg(vhost
, "Sending CRQ init\n");
613 return ibmvfc_send_crq(vhost
, 0xC001000000000000LL
, 0);
617 * ibmvfc_send_crq_init_complete - Send a CRQ init complete message
618 * @vhost: ibmvfc host struct
621 * 0 on success / other on failure
623 static int ibmvfc_send_crq_init_complete(struct ibmvfc_host
*vhost
)
625 ibmvfc_dbg(vhost
, "Sending CRQ init complete\n");
626 return ibmvfc_send_crq(vhost
, 0xC002000000000000LL
, 0);
630 * ibmvfc_release_crq_queue - Deallocates data and unregisters CRQ
631 * @vhost: ibmvfc host struct
633 * Frees irq, deallocates a page for messages, unmaps dma, and unregisters
634 * the crq with the hypervisor.
636 static void ibmvfc_release_crq_queue(struct ibmvfc_host
*vhost
)
639 struct vio_dev
*vdev
= to_vio_dev(vhost
->dev
);
640 struct ibmvfc_crq_queue
*crq
= &vhost
->crq
;
642 ibmvfc_dbg(vhost
, "Releasing CRQ\n");
643 free_irq(vdev
->irq
, vhost
);
644 tasklet_kill(&vhost
->tasklet
);
646 rc
= plpar_hcall_norets(H_FREE_CRQ
, vdev
->unit_address
);
647 } while (rc
== H_BUSY
|| H_IS_LONG_BUSY(rc
));
649 vhost
->state
= IBMVFC_NO_CRQ
;
650 dma_unmap_single(vhost
->dev
, crq
->msg_token
, PAGE_SIZE
, DMA_BIDIRECTIONAL
);
651 free_page((unsigned long)crq
->msgs
);
655 * ibmvfc_reenable_crq_queue - reenables the CRQ
656 * @vhost: ibmvfc host struct
659 * 0 on success / other on failure
661 static int ibmvfc_reenable_crq_queue(struct ibmvfc_host
*vhost
)
664 struct vio_dev
*vdev
= to_vio_dev(vhost
->dev
);
666 /* Re-enable the CRQ */
668 rc
= plpar_hcall_norets(H_ENABLE_CRQ
, vdev
->unit_address
);
669 } while (rc
== H_IN_PROGRESS
|| rc
== H_BUSY
|| H_IS_LONG_BUSY(rc
));
672 dev_err(vhost
->dev
, "Error enabling adapter (rc=%d)\n", rc
);
678 * ibmvfc_reset_crq - resets a crq after a failure
679 * @vhost: ibmvfc host struct
682 * 0 on success / other on failure
684 static int ibmvfc_reset_crq(struct ibmvfc_host
*vhost
)
687 struct vio_dev
*vdev
= to_vio_dev(vhost
->dev
);
688 struct ibmvfc_crq_queue
*crq
= &vhost
->crq
;
692 rc
= plpar_hcall_norets(H_FREE_CRQ
, vdev
->unit_address
);
693 } while (rc
== H_BUSY
|| H_IS_LONG_BUSY(rc
));
695 vhost
->state
= IBMVFC_NO_CRQ
;
696 ibmvfc_set_host_action(vhost
, IBMVFC_HOST_ACTION_NONE
);
698 /* Clean out the queue */
699 memset(crq
->msgs
, 0, PAGE_SIZE
);
702 /* And re-open it again */
703 rc
= plpar_hcall_norets(H_REG_CRQ
, vdev
->unit_address
,
704 crq
->msg_token
, PAGE_SIZE
);
707 /* Adapter is good, but other end is not ready */
708 dev_warn(vhost
->dev
, "Partner adapter not ready\n");
710 dev_warn(vhost
->dev
, "Couldn't register crq (rc=%d)\n", rc
);
716 * ibmvfc_valid_event - Determines if event is valid.
717 * @pool: event_pool that contains the event
718 * @evt: ibmvfc event to be checked for validity
721 * 1 if event is valid / 0 if event is not valid
723 static int ibmvfc_valid_event(struct ibmvfc_event_pool
*pool
,
724 struct ibmvfc_event
*evt
)
726 int index
= evt
- pool
->events
;
727 if (index
< 0 || index
>= pool
->size
) /* outside of bounds */
729 if (evt
!= pool
->events
+ index
) /* unaligned */
735 * ibmvfc_free_event - Free the specified event
736 * @evt: ibmvfc_event to be freed
739 static void ibmvfc_free_event(struct ibmvfc_event
*evt
)
741 struct ibmvfc_host
*vhost
= evt
->vhost
;
742 struct ibmvfc_event_pool
*pool
= &vhost
->pool
;
744 BUG_ON(!ibmvfc_valid_event(pool
, evt
));
745 BUG_ON(atomic_inc_return(&evt
->free
) != 1);
746 list_add_tail(&evt
->queue
, &vhost
->free
);
750 * ibmvfc_scsi_eh_done - EH done function for queuecommand commands
751 * @evt: ibmvfc event struct
753 * This function does not setup any error status, that must be done
754 * before this function gets called.
756 static void ibmvfc_scsi_eh_done(struct ibmvfc_event
*evt
)
758 struct scsi_cmnd
*cmnd
= evt
->cmnd
;
761 scsi_dma_unmap(cmnd
);
762 cmnd
->scsi_done(cmnd
);
766 complete(evt
->eh_comp
);
768 ibmvfc_free_event(evt
);
772 * ibmvfc_fail_request - Fail request with specified error code
773 * @evt: ibmvfc event struct
774 * @error_code: error code to fail request with
779 static void ibmvfc_fail_request(struct ibmvfc_event
*evt
, int error_code
)
782 evt
->cmnd
->result
= (error_code
<< 16);
783 evt
->done
= ibmvfc_scsi_eh_done
;
785 evt
->xfer_iu
->mad_common
.status
= IBMVFC_MAD_DRIVER_FAILED
;
787 list_del(&evt
->queue
);
788 del_timer(&evt
->timer
);
794 * ibmvfc_purge_requests - Our virtual adapter just shut down. Purge any sent requests
795 * @vhost: ibmvfc host struct
796 * @error_code: error code to fail requests with
801 static void ibmvfc_purge_requests(struct ibmvfc_host
*vhost
, int error_code
)
803 struct ibmvfc_event
*evt
, *pos
;
805 ibmvfc_dbg(vhost
, "Purging all requests\n");
806 list_for_each_entry_safe(evt
, pos
, &vhost
->sent
, queue
)
807 ibmvfc_fail_request(evt
, error_code
);
811 * __ibmvfc_reset_host - Reset the connection to the server (no locking)
812 * @vhost: struct ibmvfc host to reset
814 static void __ibmvfc_reset_host(struct ibmvfc_host
*vhost
)
818 scsi_block_requests(vhost
->host
);
819 ibmvfc_purge_requests(vhost
, DID_ERROR
);
820 if ((rc
= ibmvfc_reset_crq(vhost
)) ||
821 (rc
= ibmvfc_send_crq_init(vhost
)) ||
822 (rc
= vio_enable_interrupts(to_vio_dev(vhost
->dev
)))) {
823 dev_err(vhost
->dev
, "Error after reset rc=%d\n", rc
);
824 ibmvfc_link_down(vhost
, IBMVFC_LINK_DEAD
);
826 ibmvfc_link_down(vhost
, IBMVFC_LINK_DOWN
);
830 * ibmvfc_reset_host - Reset the connection to the server
831 * @vhost: struct ibmvfc host to reset
833 static void ibmvfc_reset_host(struct ibmvfc_host
*vhost
)
837 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
838 __ibmvfc_reset_host(vhost
);
839 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
843 * ibmvfc_retry_host_init - Retry host initialization if allowed
844 * @vhost: ibmvfc host struct
846 * Returns: 1 if init will be retried / 0 if not
849 static int ibmvfc_retry_host_init(struct ibmvfc_host
*vhost
)
853 if (vhost
->action
== IBMVFC_HOST_ACTION_INIT_WAIT
) {
854 vhost
->delay_init
= 1;
855 if (++vhost
->init_retries
> IBMVFC_MAX_HOST_INIT_RETRIES
) {
857 "Host initialization retries exceeded. Taking adapter offline\n");
858 ibmvfc_link_down(vhost
, IBMVFC_HOST_OFFLINE
);
859 } else if (vhost
->init_retries
== IBMVFC_MAX_HOST_INIT_RETRIES
)
860 __ibmvfc_reset_host(vhost
);
862 ibmvfc_set_host_action(vhost
, IBMVFC_HOST_ACTION_INIT
);
867 wake_up(&vhost
->work_wait_q
);
872 * __ibmvfc_get_target - Find the specified scsi_target (no locking)
873 * @starget: scsi target struct
876 * ibmvfc_target struct / NULL if not found
878 static struct ibmvfc_target
*__ibmvfc_get_target(struct scsi_target
*starget
)
880 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
881 struct ibmvfc_host
*vhost
= shost_priv(shost
);
882 struct ibmvfc_target
*tgt
;
884 list_for_each_entry(tgt
, &vhost
->targets
, queue
)
885 if (tgt
->target_id
== starget
->id
) {
886 kref_get(&tgt
->kref
);
893 * ibmvfc_get_target - Find the specified scsi_target
894 * @starget: scsi target struct
897 * ibmvfc_target struct / NULL if not found
899 static struct ibmvfc_target
*ibmvfc_get_target(struct scsi_target
*starget
)
901 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
902 struct ibmvfc_target
*tgt
;
905 spin_lock_irqsave(shost
->host_lock
, flags
);
906 tgt
= __ibmvfc_get_target(starget
);
907 spin_unlock_irqrestore(shost
->host_lock
, flags
);
912 * ibmvfc_get_host_speed - Get host port speed
913 * @shost: scsi host struct
918 static void ibmvfc_get_host_speed(struct Scsi_Host
*shost
)
920 struct ibmvfc_host
*vhost
= shost_priv(shost
);
923 spin_lock_irqsave(shost
->host_lock
, flags
);
924 if (vhost
->state
== IBMVFC_ACTIVE
) {
925 switch (vhost
->login_buf
->resp
.link_speed
/ 100) {
927 fc_host_speed(shost
) = FC_PORTSPEED_1GBIT
;
930 fc_host_speed(shost
) = FC_PORTSPEED_2GBIT
;
933 fc_host_speed(shost
) = FC_PORTSPEED_4GBIT
;
936 fc_host_speed(shost
) = FC_PORTSPEED_8GBIT
;
939 fc_host_speed(shost
) = FC_PORTSPEED_10GBIT
;
942 fc_host_speed(shost
) = FC_PORTSPEED_16GBIT
;
945 ibmvfc_log(vhost
, 3, "Unknown port speed: %lld Gbit\n",
946 vhost
->login_buf
->resp
.link_speed
/ 100);
947 fc_host_speed(shost
) = FC_PORTSPEED_UNKNOWN
;
951 fc_host_speed(shost
) = FC_PORTSPEED_UNKNOWN
;
952 spin_unlock_irqrestore(shost
->host_lock
, flags
);
956 * ibmvfc_get_host_port_state - Get host port state
957 * @shost: scsi host struct
962 static void ibmvfc_get_host_port_state(struct Scsi_Host
*shost
)
964 struct ibmvfc_host
*vhost
= shost_priv(shost
);
967 spin_lock_irqsave(shost
->host_lock
, flags
);
968 switch (vhost
->state
) {
969 case IBMVFC_INITIALIZING
:
971 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
973 case IBMVFC_LINK_DOWN
:
974 fc_host_port_state(shost
) = FC_PORTSTATE_LINKDOWN
;
976 case IBMVFC_LINK_DEAD
:
977 case IBMVFC_HOST_OFFLINE
:
978 fc_host_port_state(shost
) = FC_PORTSTATE_OFFLINE
;
981 fc_host_port_state(shost
) = FC_PORTSTATE_BLOCKED
;
984 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
987 ibmvfc_log(vhost
, 3, "Unknown port state: %d\n", vhost
->state
);
988 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
991 spin_unlock_irqrestore(shost
->host_lock
, flags
);
995 * ibmvfc_set_rport_dev_loss_tmo - Set rport's device loss timeout
996 * @rport: rport struct
997 * @timeout: timeout value
1002 static void ibmvfc_set_rport_dev_loss_tmo(struct fc_rport
*rport
, u32 timeout
)
1005 rport
->dev_loss_tmo
= timeout
;
1007 rport
->dev_loss_tmo
= 1;
1011 * ibmvfc_release_tgt - Free memory allocated for a target
1012 * @kref: kref struct
1015 static void ibmvfc_release_tgt(struct kref
*kref
)
1017 struct ibmvfc_target
*tgt
= container_of(kref
, struct ibmvfc_target
, kref
);
1022 * ibmvfc_get_starget_node_name - Get SCSI target's node name
1023 * @starget: scsi target struct
1028 static void ibmvfc_get_starget_node_name(struct scsi_target
*starget
)
1030 struct ibmvfc_target
*tgt
= ibmvfc_get_target(starget
);
1031 fc_starget_port_name(starget
) = tgt
? tgt
->ids
.node_name
: 0;
1033 kref_put(&tgt
->kref
, ibmvfc_release_tgt
);
1037 * ibmvfc_get_starget_port_name - Get SCSI target's port name
1038 * @starget: scsi target struct
1043 static void ibmvfc_get_starget_port_name(struct scsi_target
*starget
)
1045 struct ibmvfc_target
*tgt
= ibmvfc_get_target(starget
);
1046 fc_starget_port_name(starget
) = tgt
? tgt
->ids
.port_name
: 0;
1048 kref_put(&tgt
->kref
, ibmvfc_release_tgt
);
1052 * ibmvfc_get_starget_port_id - Get SCSI target's port ID
1053 * @starget: scsi target struct
1058 static void ibmvfc_get_starget_port_id(struct scsi_target
*starget
)
1060 struct ibmvfc_target
*tgt
= ibmvfc_get_target(starget
);
1061 fc_starget_port_id(starget
) = tgt
? tgt
->scsi_id
: -1;
1063 kref_put(&tgt
->kref
, ibmvfc_release_tgt
);
1067 * ibmvfc_wait_while_resetting - Wait while the host resets
1068 * @vhost: ibmvfc host struct
1071 * 0 on success / other on failure
1073 static int ibmvfc_wait_while_resetting(struct ibmvfc_host
*vhost
)
1075 long timeout
= wait_event_timeout(vhost
->init_wait_q
,
1076 ((vhost
->state
== IBMVFC_ACTIVE
||
1077 vhost
->state
== IBMVFC_HOST_OFFLINE
||
1078 vhost
->state
== IBMVFC_LINK_DEAD
) &&
1079 vhost
->action
== IBMVFC_HOST_ACTION_NONE
),
1080 (init_timeout
* HZ
));
1082 return timeout
? 0 : -EIO
;
1086 * ibmvfc_issue_fc_host_lip - Re-initiate link initialization
1087 * @shost: scsi host struct
1090 * 0 on success / other on failure
1092 static int ibmvfc_issue_fc_host_lip(struct Scsi_Host
*shost
)
1094 struct ibmvfc_host
*vhost
= shost_priv(shost
);
1096 dev_err(vhost
->dev
, "Initiating host LIP. Resetting connection\n");
1097 ibmvfc_reset_host(vhost
);
1098 return ibmvfc_wait_while_resetting(vhost
);
1102 * ibmvfc_gather_partition_info - Gather info about the LPAR
1107 static void ibmvfc_gather_partition_info(struct ibmvfc_host
*vhost
)
1109 struct device_node
*rootdn
;
1111 const unsigned int *num
;
1113 rootdn
= of_find_node_by_path("/");
1117 name
= of_get_property(rootdn
, "ibm,partition-name", NULL
);
1119 strncpy(vhost
->partition_name
, name
, sizeof(vhost
->partition_name
));
1120 num
= of_get_property(rootdn
, "ibm,partition-no", NULL
);
1122 vhost
->partition_number
= *num
;
1123 of_node_put(rootdn
);
1127 * ibmvfc_set_login_info - Setup info for NPIV login
1128 * @vhost: ibmvfc host struct
1133 static void ibmvfc_set_login_info(struct ibmvfc_host
*vhost
)
1135 struct ibmvfc_npiv_login
*login_info
= &vhost
->login_info
;
1136 struct device_node
*of_node
= vhost
->dev
->archdata
.of_node
;
1137 const char *location
;
1139 memset(login_info
, 0, sizeof(*login_info
));
1141 login_info
->ostype
= IBMVFC_OS_LINUX
;
1142 login_info
->max_dma_len
= IBMVFC_MAX_SECTORS
<< 9;
1143 login_info
->max_payload
= sizeof(struct ibmvfc_fcp_cmd_iu
);
1144 login_info
->max_response
= sizeof(struct ibmvfc_fcp_rsp
);
1145 login_info
->partition_num
= vhost
->partition_number
;
1146 login_info
->vfc_frame_version
= 1;
1147 login_info
->fcp_version
= 3;
1148 if (vhost
->client_migrated
)
1149 login_info
->flags
= IBMVFC_CLIENT_MIGRATED
;
1151 login_info
->max_cmds
= max_requests
+ IBMVFC_NUM_INTERNAL_REQ
;
1152 login_info
->capabilities
= IBMVFC_CAN_MIGRATE
;
1153 login_info
->async
.va
= vhost
->async_crq
.msg_token
;
1154 login_info
->async
.len
= vhost
->async_crq
.size
* sizeof(*vhost
->async_crq
.msgs
);
1155 strncpy(login_info
->partition_name
, vhost
->partition_name
, IBMVFC_MAX_NAME
);
1156 strncpy(login_info
->device_name
,
1157 dev_name(&vhost
->host
->shost_gendev
), IBMVFC_MAX_NAME
);
1159 location
= of_get_property(of_node
, "ibm,loc-code", NULL
);
1160 location
= location
? location
: dev_name(vhost
->dev
);
1161 strncpy(login_info
->drc_name
, location
, IBMVFC_MAX_NAME
);
1165 * ibmvfc_init_event_pool - Allocates and initializes the event pool for a host
1166 * @vhost: ibmvfc host who owns the event pool
1168 * Returns zero on success.
1170 static int ibmvfc_init_event_pool(struct ibmvfc_host
*vhost
)
1173 struct ibmvfc_event_pool
*pool
= &vhost
->pool
;
1176 pool
->size
= max_requests
+ IBMVFC_NUM_INTERNAL_REQ
;
1177 pool
->events
= kcalloc(pool
->size
, sizeof(*pool
->events
), GFP_KERNEL
);
1181 pool
->iu_storage
= dma_alloc_coherent(vhost
->dev
,
1182 pool
->size
* sizeof(*pool
->iu_storage
),
1183 &pool
->iu_token
, 0);
1185 if (!pool
->iu_storage
) {
1186 kfree(pool
->events
);
1190 for (i
= 0; i
< pool
->size
; ++i
) {
1191 struct ibmvfc_event
*evt
= &pool
->events
[i
];
1192 atomic_set(&evt
->free
, 1);
1193 evt
->crq
.valid
= 0x80;
1194 evt
->crq
.ioba
= pool
->iu_token
+ (sizeof(*evt
->xfer_iu
) * i
);
1195 evt
->xfer_iu
= pool
->iu_storage
+ i
;
1197 evt
->ext_list
= NULL
;
1198 list_add_tail(&evt
->queue
, &vhost
->free
);
1206 * ibmvfc_free_event_pool - Frees memory of the event pool of a host
1207 * @vhost: ibmvfc host who owns the event pool
1210 static void ibmvfc_free_event_pool(struct ibmvfc_host
*vhost
)
1213 struct ibmvfc_event_pool
*pool
= &vhost
->pool
;
1216 for (i
= 0; i
< pool
->size
; ++i
) {
1217 list_del(&pool
->events
[i
].queue
);
1218 BUG_ON(atomic_read(&pool
->events
[i
].free
) != 1);
1219 if (pool
->events
[i
].ext_list
)
1220 dma_pool_free(vhost
->sg_pool
,
1221 pool
->events
[i
].ext_list
,
1222 pool
->events
[i
].ext_list_token
);
1225 kfree(pool
->events
);
1226 dma_free_coherent(vhost
->dev
,
1227 pool
->size
* sizeof(*pool
->iu_storage
),
1228 pool
->iu_storage
, pool
->iu_token
);
1233 * ibmvfc_get_event - Gets the next free event in pool
1234 * @vhost: ibmvfc host struct
1236 * Returns a free event from the pool.
1238 static struct ibmvfc_event
*ibmvfc_get_event(struct ibmvfc_host
*vhost
)
1240 struct ibmvfc_event
*evt
;
1242 BUG_ON(list_empty(&vhost
->free
));
1243 evt
= list_entry(vhost
->free
.next
, struct ibmvfc_event
, queue
);
1244 atomic_set(&evt
->free
, 0);
1245 list_del(&evt
->queue
);
1250 * ibmvfc_init_event - Initialize fields in an event struct that are always
1253 * @done: Routine to call when the event is responded to
1254 * @format: SRP or MAD format
1256 static void ibmvfc_init_event(struct ibmvfc_event
*evt
,
1257 void (*done
) (struct ibmvfc_event
*), u8 format
)
1260 evt
->sync_iu
= NULL
;
1261 evt
->crq
.format
= format
;
1263 evt
->eh_comp
= NULL
;
1267 * ibmvfc_map_sg_list - Initialize scatterlist
1268 * @scmd: scsi command struct
1269 * @nseg: number of scatterlist segments
1270 * @md: memory descriptor list to initialize
1272 static void ibmvfc_map_sg_list(struct scsi_cmnd
*scmd
, int nseg
,
1273 struct srp_direct_buf
*md
)
1276 struct scatterlist
*sg
;
1278 scsi_for_each_sg(scmd
, sg
, nseg
, i
) {
1279 md
[i
].va
= sg_dma_address(sg
);
1280 md
[i
].len
= sg_dma_len(sg
);
1286 * ibmvfc_map_sg_data - Maps dma for a scatterlist and initializes decriptor fields
1287 * @scmd: Scsi_Cmnd with the scatterlist
1288 * @evt: ibmvfc event struct
1289 * @vfc_cmd: vfc_cmd that contains the memory descriptor
1290 * @dev: device for which to map dma memory
1293 * 0 on success / non-zero on failure
1295 static int ibmvfc_map_sg_data(struct scsi_cmnd
*scmd
,
1296 struct ibmvfc_event
*evt
,
1297 struct ibmvfc_cmd
*vfc_cmd
, struct device
*dev
)
1301 struct srp_direct_buf
*data
= &vfc_cmd
->ioba
;
1302 struct ibmvfc_host
*vhost
= dev_get_drvdata(dev
);
1304 sg_mapped
= scsi_dma_map(scmd
);
1306 vfc_cmd
->flags
|= IBMVFC_NO_MEM_DESC
;
1308 } else if (unlikely(sg_mapped
< 0)) {
1309 if (vhost
->log_level
> IBMVFC_DEFAULT_LOG_LEVEL
)
1310 scmd_printk(KERN_ERR
, scmd
, "Failed to map DMA buffer for command\n");
1314 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
) {
1315 vfc_cmd
->flags
|= IBMVFC_WRITE
;
1316 vfc_cmd
->iu
.add_cdb_len
|= IBMVFC_WRDATA
;
1318 vfc_cmd
->flags
|= IBMVFC_READ
;
1319 vfc_cmd
->iu
.add_cdb_len
|= IBMVFC_RDDATA
;
1322 if (sg_mapped
== 1) {
1323 ibmvfc_map_sg_list(scmd
, sg_mapped
, data
);
1327 vfc_cmd
->flags
|= IBMVFC_SCATTERLIST
;
1329 if (!evt
->ext_list
) {
1330 evt
->ext_list
= dma_pool_alloc(vhost
->sg_pool
, GFP_ATOMIC
,
1331 &evt
->ext_list_token
);
1333 if (!evt
->ext_list
) {
1334 scsi_dma_unmap(scmd
);
1335 if (vhost
->log_level
> IBMVFC_DEFAULT_LOG_LEVEL
)
1336 scmd_printk(KERN_ERR
, scmd
, "Can't allocate memory for scatterlist\n");
1341 ibmvfc_map_sg_list(scmd
, sg_mapped
, evt
->ext_list
);
1343 data
->va
= evt
->ext_list_token
;
1344 data
->len
= sg_mapped
* sizeof(struct srp_direct_buf
);
1350 * ibmvfc_timeout - Internal command timeout handler
1351 * @evt: struct ibmvfc_event that timed out
1353 * Called when an internally generated command times out
1355 static void ibmvfc_timeout(struct ibmvfc_event
*evt
)
1357 struct ibmvfc_host
*vhost
= evt
->vhost
;
1358 dev_err(vhost
->dev
, "Command timed out (%p). Resetting connection\n", evt
);
1359 ibmvfc_reset_host(vhost
);
1363 * ibmvfc_send_event - Transforms event to u64 array and calls send_crq()
1364 * @evt: event to be sent
1365 * @vhost: ibmvfc host struct
1366 * @timeout: timeout in seconds - 0 means do not time command
1368 * Returns the value returned from ibmvfc_send_crq(). (Zero for success)
1370 static int ibmvfc_send_event(struct ibmvfc_event
*evt
,
1371 struct ibmvfc_host
*vhost
, unsigned long timeout
)
1373 u64
*crq_as_u64
= (u64
*) &evt
->crq
;
1376 /* Copy the IU into the transfer area */
1377 *evt
->xfer_iu
= evt
->iu
;
1378 if (evt
->crq
.format
== IBMVFC_CMD_FORMAT
)
1379 evt
->xfer_iu
->cmd
.tag
= (u64
)evt
;
1380 else if (evt
->crq
.format
== IBMVFC_MAD_FORMAT
)
1381 evt
->xfer_iu
->mad_common
.tag
= (u64
)evt
;
1385 list_add_tail(&evt
->queue
, &vhost
->sent
);
1386 init_timer(&evt
->timer
);
1389 evt
->timer
.data
= (unsigned long) evt
;
1390 evt
->timer
.expires
= jiffies
+ (timeout
* HZ
);
1391 evt
->timer
.function
= (void (*)(unsigned long))ibmvfc_timeout
;
1392 add_timer(&evt
->timer
);
1397 if ((rc
= ibmvfc_send_crq(vhost
, crq_as_u64
[0], crq_as_u64
[1]))) {
1398 list_del(&evt
->queue
);
1399 del_timer(&evt
->timer
);
1401 /* If send_crq returns H_CLOSED, return SCSI_MLQUEUE_HOST_BUSY.
1402 * Firmware will send a CRQ with a transport event (0xFF) to
1403 * tell this client what has happened to the transport. This
1404 * will be handled in ibmvfc_handle_crq()
1406 if (rc
== H_CLOSED
) {
1407 if (printk_ratelimit())
1408 dev_warn(vhost
->dev
, "Send warning. Receive queue closed, will retry.\n");
1410 scsi_dma_unmap(evt
->cmnd
);
1411 ibmvfc_free_event(evt
);
1412 return SCSI_MLQUEUE_HOST_BUSY
;
1415 dev_err(vhost
->dev
, "Send error (rc=%d)\n", rc
);
1417 evt
->cmnd
->result
= DID_ERROR
<< 16;
1418 evt
->done
= ibmvfc_scsi_eh_done
;
1420 evt
->xfer_iu
->mad_common
.status
= IBMVFC_MAD_CRQ_ERROR
;
1424 ibmvfc_trc_start(evt
);
1430 * ibmvfc_log_error - Log an error for the failed command if appropriate
1431 * @evt: ibmvfc event to log
1434 static void ibmvfc_log_error(struct ibmvfc_event
*evt
)
1436 struct ibmvfc_cmd
*vfc_cmd
= &evt
->xfer_iu
->cmd
;
1437 struct ibmvfc_host
*vhost
= evt
->vhost
;
1438 struct ibmvfc_fcp_rsp
*rsp
= &vfc_cmd
->rsp
;
1439 struct scsi_cmnd
*cmnd
= evt
->cmnd
;
1440 const char *err
= unknown_error
;
1441 int index
= ibmvfc_get_err_index(vfc_cmd
->status
, vfc_cmd
->error
);
1446 logerr
= cmd_status
[index
].log
;
1447 err
= cmd_status
[index
].name
;
1450 if (!logerr
&& (vhost
->log_level
<= (IBMVFC_DEFAULT_LOG_LEVEL
+ 1)))
1453 if (rsp
->flags
& FCP_RSP_LEN_VALID
)
1454 rsp_code
= rsp
->data
.info
.rsp_code
;
1456 scmd_printk(KERN_ERR
, cmnd
, "Command (%02X) failed: %s (%x:%x) "
1457 "flags: %x fcp_rsp: %x, resid=%d, scsi_status: %x\n",
1458 cmnd
->cmnd
[0], err
, vfc_cmd
->status
, vfc_cmd
->error
,
1459 rsp
->flags
, rsp_code
, scsi_get_resid(cmnd
), rsp
->scsi_status
);
1463 * ibmvfc_scsi_done - Handle responses from commands
1464 * @evt: ibmvfc event to be handled
1466 * Used as a callback when sending scsi cmds.
1468 static void ibmvfc_scsi_done(struct ibmvfc_event
*evt
)
1470 struct ibmvfc_cmd
*vfc_cmd
= &evt
->xfer_iu
->cmd
;
1471 struct ibmvfc_fcp_rsp
*rsp
= &vfc_cmd
->rsp
;
1472 struct scsi_cmnd
*cmnd
= evt
->cmnd
;
1474 u32 sense_len
= rsp
->fcp_sense_len
;
1477 if (vfc_cmd
->response_flags
& IBMVFC_ADAPTER_RESID_VALID
)
1478 scsi_set_resid(cmnd
, vfc_cmd
->adapter_resid
);
1479 else if (rsp
->flags
& FCP_RESID_UNDER
)
1480 scsi_set_resid(cmnd
, rsp
->fcp_resid
);
1482 scsi_set_resid(cmnd
, 0);
1484 if (vfc_cmd
->status
) {
1485 cmnd
->result
= ibmvfc_get_err_result(vfc_cmd
);
1487 if (rsp
->flags
& FCP_RSP_LEN_VALID
)
1488 rsp_len
= rsp
->fcp_rsp_len
;
1489 if ((sense_len
+ rsp_len
) > SCSI_SENSE_BUFFERSIZE
)
1490 sense_len
= SCSI_SENSE_BUFFERSIZE
- rsp_len
;
1491 if ((rsp
->flags
& FCP_SNS_LEN_VALID
) && rsp
->fcp_sense_len
&& rsp_len
<= 8)
1492 memcpy(cmnd
->sense_buffer
, rsp
->data
.sense
+ rsp_len
, sense_len
);
1493 if ((vfc_cmd
->status
& IBMVFC_VIOS_FAILURE
) && (vfc_cmd
->error
== IBMVFC_PLOGI_REQUIRED
))
1494 ibmvfc_reinit_host(evt
->vhost
);
1496 if (!cmnd
->result
&& (!scsi_get_resid(cmnd
) || (rsp
->flags
& FCP_RESID_OVER
)))
1497 cmnd
->result
= (DID_ERROR
<< 16);
1499 ibmvfc_log_error(evt
);
1502 if (!cmnd
->result
&&
1503 (scsi_bufflen(cmnd
) - scsi_get_resid(cmnd
) < cmnd
->underflow
))
1504 cmnd
->result
= (DID_ERROR
<< 16);
1506 scsi_dma_unmap(cmnd
);
1507 cmnd
->scsi_done(cmnd
);
1511 complete(evt
->eh_comp
);
1513 ibmvfc_free_event(evt
);
1517 * ibmvfc_host_chkready - Check if the host can accept commands
1518 * @vhost: struct ibmvfc host
1521 * 1 if host can accept command / 0 if not
1523 static inline int ibmvfc_host_chkready(struct ibmvfc_host
*vhost
)
1527 switch (vhost
->state
) {
1528 case IBMVFC_LINK_DEAD
:
1529 case IBMVFC_HOST_OFFLINE
:
1530 result
= DID_NO_CONNECT
<< 16;
1533 case IBMVFC_INITIALIZING
:
1535 case IBMVFC_LINK_DOWN
:
1536 result
= DID_REQUEUE
<< 16;
1547 * ibmvfc_queuecommand - The queuecommand function of the scsi template
1548 * @cmnd: struct scsi_cmnd to be executed
1549 * @done: Callback function to be called when cmnd is completed
1552 * 0 on success / other on failure
1554 static int ibmvfc_queuecommand(struct scsi_cmnd
*cmnd
,
1555 void (*done
) (struct scsi_cmnd
*))
1557 struct ibmvfc_host
*vhost
= shost_priv(cmnd
->device
->host
);
1558 struct fc_rport
*rport
= starget_to_rport(scsi_target(cmnd
->device
));
1559 struct ibmvfc_cmd
*vfc_cmd
;
1560 struct ibmvfc_event
*evt
;
1564 if (unlikely((rc
= fc_remote_port_chkready(rport
))) ||
1565 unlikely((rc
= ibmvfc_host_chkready(vhost
)))) {
1571 cmnd
->result
= (DID_OK
<< 16);
1572 evt
= ibmvfc_get_event(vhost
);
1573 ibmvfc_init_event(evt
, ibmvfc_scsi_done
, IBMVFC_CMD_FORMAT
);
1575 cmnd
->scsi_done
= done
;
1576 vfc_cmd
= &evt
->iu
.cmd
;
1577 memset(vfc_cmd
, 0, sizeof(*vfc_cmd
));
1578 vfc_cmd
->resp
.va
= (u64
)evt
->crq
.ioba
+ offsetof(struct ibmvfc_cmd
, rsp
);
1579 vfc_cmd
->resp
.len
= sizeof(vfc_cmd
->rsp
);
1580 vfc_cmd
->frame_type
= IBMVFC_SCSI_FCP_TYPE
;
1581 vfc_cmd
->payload_len
= sizeof(vfc_cmd
->iu
);
1582 vfc_cmd
->resp_len
= sizeof(vfc_cmd
->rsp
);
1583 vfc_cmd
->cancel_key
= (unsigned long)cmnd
->device
->hostdata
;
1584 vfc_cmd
->tgt_scsi_id
= rport
->port_id
;
1585 vfc_cmd
->iu
.xfer_len
= scsi_bufflen(cmnd
);
1586 int_to_scsilun(cmnd
->device
->lun
, &vfc_cmd
->iu
.lun
);
1587 memcpy(vfc_cmd
->iu
.cdb
, cmnd
->cmnd
, cmnd
->cmd_len
);
1589 if (scsi_populate_tag_msg(cmnd
, tag
)) {
1590 vfc_cmd
->task_tag
= tag
[1];
1592 case MSG_SIMPLE_TAG
:
1593 vfc_cmd
->iu
.pri_task_attr
= IBMVFC_SIMPLE_TASK
;
1596 vfc_cmd
->iu
.pri_task_attr
= IBMVFC_HEAD_OF_QUEUE
;
1598 case MSG_ORDERED_TAG
:
1599 vfc_cmd
->iu
.pri_task_attr
= IBMVFC_ORDERED_TASK
;
1604 if (likely(!(rc
= ibmvfc_map_sg_data(cmnd
, evt
, vfc_cmd
, vhost
->dev
))))
1605 return ibmvfc_send_event(evt
, vhost
, 0);
1607 ibmvfc_free_event(evt
);
1609 return SCSI_MLQUEUE_HOST_BUSY
;
1611 if (vhost
->log_level
> IBMVFC_DEFAULT_LOG_LEVEL
)
1612 scmd_printk(KERN_ERR
, cmnd
,
1613 "Failed to map DMA buffer for command. rc=%d\n", rc
);
1615 cmnd
->result
= DID_ERROR
<< 16;
1621 * ibmvfc_sync_completion - Signal that a synchronous command has completed
1622 * @evt: ibmvfc event struct
1625 static void ibmvfc_sync_completion(struct ibmvfc_event
*evt
)
1627 /* copy the response back */
1629 *evt
->sync_iu
= *evt
->xfer_iu
;
1631 complete(&evt
->comp
);
1635 * ibmvfc_reset_device - Reset the device with the specified reset type
1636 * @sdev: scsi device to reset
1638 * @desc: reset type description for log messages
1641 * 0 on success / other on failure
1643 static int ibmvfc_reset_device(struct scsi_device
*sdev
, int type
, char *desc
)
1645 struct ibmvfc_host
*vhost
= shost_priv(sdev
->host
);
1646 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
1647 struct ibmvfc_cmd
*tmf
;
1648 struct ibmvfc_event
*evt
= NULL
;
1649 union ibmvfc_iu rsp_iu
;
1650 struct ibmvfc_fcp_rsp
*fc_rsp
= &rsp_iu
.cmd
.rsp
;
1651 int rsp_rc
= -EBUSY
;
1652 unsigned long flags
;
1655 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
1656 if (vhost
->state
== IBMVFC_ACTIVE
) {
1657 evt
= ibmvfc_get_event(vhost
);
1658 ibmvfc_init_event(evt
, ibmvfc_sync_completion
, IBMVFC_CMD_FORMAT
);
1661 memset(tmf
, 0, sizeof(*tmf
));
1662 tmf
->resp
.va
= (u64
)evt
->crq
.ioba
+ offsetof(struct ibmvfc_cmd
, rsp
);
1663 tmf
->resp
.len
= sizeof(tmf
->rsp
);
1664 tmf
->frame_type
= IBMVFC_SCSI_FCP_TYPE
;
1665 tmf
->payload_len
= sizeof(tmf
->iu
);
1666 tmf
->resp_len
= sizeof(tmf
->rsp
);
1667 tmf
->cancel_key
= (unsigned long)sdev
->hostdata
;
1668 tmf
->tgt_scsi_id
= rport
->port_id
;
1669 int_to_scsilun(sdev
->lun
, &tmf
->iu
.lun
);
1670 tmf
->flags
= (IBMVFC_NO_MEM_DESC
| IBMVFC_TMF
);
1671 tmf
->iu
.tmf_flags
= type
;
1672 evt
->sync_iu
= &rsp_iu
;
1674 init_completion(&evt
->comp
);
1675 rsp_rc
= ibmvfc_send_event(evt
, vhost
, default_timeout
);
1677 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
1680 sdev_printk(KERN_ERR
, sdev
, "Failed to send %s reset event. rc=%d\n",
1685 sdev_printk(KERN_INFO
, sdev
, "Resetting %s\n", desc
);
1686 wait_for_completion(&evt
->comp
);
1688 if (rsp_iu
.cmd
.status
) {
1689 if (fc_rsp
->flags
& FCP_RSP_LEN_VALID
)
1690 rsp_code
= fc_rsp
->data
.info
.rsp_code
;
1692 sdev_printk(KERN_ERR
, sdev
, "%s reset failed: %s (%x:%x) "
1693 "flags: %x fcp_rsp: %x, scsi_status: %x\n",
1694 desc
, ibmvfc_get_cmd_error(rsp_iu
.cmd
.status
, rsp_iu
.cmd
.error
),
1695 rsp_iu
.cmd
.status
, rsp_iu
.cmd
.error
, fc_rsp
->flags
, rsp_code
,
1696 fc_rsp
->scsi_status
);
1699 sdev_printk(KERN_INFO
, sdev
, "%s reset successful\n", desc
);
1701 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
1702 ibmvfc_free_event(evt
);
1703 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
1708 * ibmvfc_abort_task_set - Abort outstanding commands to the device
1709 * @sdev: scsi device to abort commands
1711 * This sends an Abort Task Set to the VIOS for the specified device. This does
1712 * NOT send any cancel to the VIOS. That must be done separately.
1715 * 0 on success / other on failure
1717 static int ibmvfc_abort_task_set(struct scsi_device
*sdev
)
1719 struct ibmvfc_host
*vhost
= shost_priv(sdev
->host
);
1720 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
1721 struct ibmvfc_cmd
*tmf
;
1722 struct ibmvfc_event
*evt
, *found_evt
;
1723 union ibmvfc_iu rsp_iu
;
1724 struct ibmvfc_fcp_rsp
*fc_rsp
= &rsp_iu
.cmd
.rsp
;
1725 int rsp_rc
= -EBUSY
;
1726 unsigned long flags
;
1729 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
1731 list_for_each_entry(evt
, &vhost
->sent
, queue
) {
1732 if (evt
->cmnd
&& evt
->cmnd
->device
== sdev
) {
1739 if (vhost
->log_level
> IBMVFC_DEFAULT_LOG_LEVEL
)
1740 sdev_printk(KERN_INFO
, sdev
, "No events found to abort\n");
1741 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
1745 if (vhost
->state
== IBMVFC_ACTIVE
) {
1746 evt
= ibmvfc_get_event(vhost
);
1747 ibmvfc_init_event(evt
, ibmvfc_sync_completion
, IBMVFC_CMD_FORMAT
);
1750 memset(tmf
, 0, sizeof(*tmf
));
1751 tmf
->resp
.va
= (u64
)evt
->crq
.ioba
+ offsetof(struct ibmvfc_cmd
, rsp
);
1752 tmf
->resp
.len
= sizeof(tmf
->rsp
);
1753 tmf
->frame_type
= IBMVFC_SCSI_FCP_TYPE
;
1754 tmf
->payload_len
= sizeof(tmf
->iu
);
1755 tmf
->resp_len
= sizeof(tmf
->rsp
);
1756 tmf
->cancel_key
= (unsigned long)sdev
->hostdata
;
1757 tmf
->tgt_scsi_id
= rport
->port_id
;
1758 int_to_scsilun(sdev
->lun
, &tmf
->iu
.lun
);
1759 tmf
->flags
= (IBMVFC_NO_MEM_DESC
| IBMVFC_TMF
);
1760 tmf
->iu
.tmf_flags
= IBMVFC_ABORT_TASK_SET
;
1761 evt
->sync_iu
= &rsp_iu
;
1763 init_completion(&evt
->comp
);
1764 rsp_rc
= ibmvfc_send_event(evt
, vhost
, default_timeout
);
1767 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
1770 sdev_printk(KERN_ERR
, sdev
, "Failed to send abort. rc=%d\n", rsp_rc
);
1774 sdev_printk(KERN_INFO
, sdev
, "Aborting outstanding commands\n");
1775 wait_for_completion(&evt
->comp
);
1777 if (rsp_iu
.cmd
.status
) {
1778 if (fc_rsp
->flags
& FCP_RSP_LEN_VALID
)
1779 rsp_code
= fc_rsp
->data
.info
.rsp_code
;
1781 sdev_printk(KERN_ERR
, sdev
, "Abort failed: %s (%x:%x) "
1782 "flags: %x fcp_rsp: %x, scsi_status: %x\n",
1783 ibmvfc_get_cmd_error(rsp_iu
.cmd
.status
, rsp_iu
.cmd
.error
),
1784 rsp_iu
.cmd
.status
, rsp_iu
.cmd
.error
, fc_rsp
->flags
, rsp_code
,
1785 fc_rsp
->scsi_status
);
1788 sdev_printk(KERN_INFO
, sdev
, "Abort successful\n");
1790 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
1791 ibmvfc_free_event(evt
);
1792 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
1797 * ibmvfc_cancel_all - Cancel all outstanding commands to the device
1798 * @sdev: scsi device to cancel commands
1799 * @type: type of error recovery being performed
1801 * This sends a cancel to the VIOS for the specified device. This does
1802 * NOT send any abort to the actual device. That must be done separately.
1805 * 0 on success / other on failure
1807 static int ibmvfc_cancel_all(struct scsi_device
*sdev
, int type
)
1809 struct ibmvfc_host
*vhost
= shost_priv(sdev
->host
);
1810 struct scsi_target
*starget
= scsi_target(sdev
);
1811 struct fc_rport
*rport
= starget_to_rport(starget
);
1812 struct ibmvfc_tmf
*tmf
;
1813 struct ibmvfc_event
*evt
, *found_evt
;
1814 union ibmvfc_iu rsp
;
1815 int rsp_rc
= -EBUSY
;
1816 unsigned long flags
;
1820 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
1822 list_for_each_entry(evt
, &vhost
->sent
, queue
) {
1823 if (evt
->cmnd
&& evt
->cmnd
->device
== sdev
) {
1830 if (vhost
->log_level
> IBMVFC_DEFAULT_LOG_LEVEL
)
1831 sdev_printk(KERN_INFO
, sdev
, "No events found to cancel\n");
1832 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
1836 if (vhost
->state
== IBMVFC_ACTIVE
) {
1837 evt
= ibmvfc_get_event(vhost
);
1838 ibmvfc_init_event(evt
, ibmvfc_sync_completion
, IBMVFC_MAD_FORMAT
);
1841 memset(tmf
, 0, sizeof(*tmf
));
1842 tmf
->common
.version
= 1;
1843 tmf
->common
.opcode
= IBMVFC_TMF_MAD
;
1844 tmf
->common
.length
= sizeof(*tmf
);
1845 tmf
->scsi_id
= rport
->port_id
;
1846 int_to_scsilun(sdev
->lun
, &tmf
->lun
);
1847 tmf
->flags
= (type
| IBMVFC_TMF_LUA_VALID
);
1848 tmf
->cancel_key
= (unsigned long)sdev
->hostdata
;
1849 tmf
->my_cancel_key
= (unsigned long)starget
->hostdata
;
1851 evt
->sync_iu
= &rsp
;
1852 init_completion(&evt
->comp
);
1853 rsp_rc
= ibmvfc_send_event(evt
, vhost
, default_timeout
);
1856 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
1859 sdev_printk(KERN_ERR
, sdev
, "Failed to send cancel event. rc=%d\n", rsp_rc
);
1863 sdev_printk(KERN_INFO
, sdev
, "Cancelling outstanding commands.\n");
1865 wait_for_completion(&evt
->comp
);
1866 status
= rsp
.mad_common
.status
;
1867 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
1868 ibmvfc_free_event(evt
);
1869 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
1871 if (status
!= IBMVFC_MAD_SUCCESS
) {
1872 sdev_printk(KERN_WARNING
, sdev
, "Cancel failed with rc=%x\n", status
);
1876 sdev_printk(KERN_INFO
, sdev
, "Successfully cancelled outstanding commands\n");
1881 * ibmvfc_match_target - Match function for specified target
1882 * @evt: ibmvfc event struct
1883 * @device: device to match (starget)
1886 * 1 if event matches starget / 0 if event does not match starget
1888 static int ibmvfc_match_target(struct ibmvfc_event
*evt
, void *device
)
1890 if (evt
->cmnd
&& scsi_target(evt
->cmnd
->device
) == device
)
1896 * ibmvfc_match_lun - Match function for specified LUN
1897 * @evt: ibmvfc event struct
1898 * @device: device to match (sdev)
1901 * 1 if event matches sdev / 0 if event does not match sdev
1903 static int ibmvfc_match_lun(struct ibmvfc_event
*evt
, void *device
)
1905 if (evt
->cmnd
&& evt
->cmnd
->device
== device
)
1911 * ibmvfc_wait_for_ops - Wait for ops to complete
1912 * @vhost: ibmvfc host struct
1913 * @device: device to match (starget or sdev)
1914 * @match: match function
1919 static int ibmvfc_wait_for_ops(struct ibmvfc_host
*vhost
, void *device
,
1920 int (*match
) (struct ibmvfc_event
*, void *))
1922 struct ibmvfc_event
*evt
;
1923 DECLARE_COMPLETION_ONSTACK(comp
);
1925 unsigned long flags
;
1926 signed long timeout
= init_timeout
* HZ
;
1931 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
1932 list_for_each_entry(evt
, &vhost
->sent
, queue
) {
1933 if (match(evt
, device
)) {
1934 evt
->eh_comp
= &comp
;
1938 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
1941 timeout
= wait_for_completion_timeout(&comp
, timeout
);
1945 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
1946 list_for_each_entry(evt
, &vhost
->sent
, queue
) {
1947 if (match(evt
, device
)) {
1948 evt
->eh_comp
= NULL
;
1952 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
1954 dev_err(vhost
->dev
, "Timed out waiting for aborted commands\n");
1956 return wait
? FAILED
: SUCCESS
;
1966 * ibmvfc_eh_abort_handler - Abort a command
1967 * @cmd: scsi command to abort
1972 static int ibmvfc_eh_abort_handler(struct scsi_cmnd
*cmd
)
1974 struct scsi_device
*sdev
= cmd
->device
;
1975 struct ibmvfc_host
*vhost
= shost_priv(sdev
->host
);
1976 int cancel_rc
, abort_rc
;
1980 ibmvfc_wait_while_resetting(vhost
);
1981 cancel_rc
= ibmvfc_cancel_all(sdev
, IBMVFC_TMF_ABORT_TASK_SET
);
1982 abort_rc
= ibmvfc_abort_task_set(sdev
);
1984 if (!cancel_rc
&& !abort_rc
)
1985 rc
= ibmvfc_wait_for_ops(vhost
, sdev
, ibmvfc_match_lun
);
1992 * ibmvfc_eh_device_reset_handler - Reset a single LUN
1993 * @cmd: scsi command struct
1998 static int ibmvfc_eh_device_reset_handler(struct scsi_cmnd
*cmd
)
2000 struct scsi_device
*sdev
= cmd
->device
;
2001 struct ibmvfc_host
*vhost
= shost_priv(sdev
->host
);
2002 int cancel_rc
, reset_rc
;
2006 ibmvfc_wait_while_resetting(vhost
);
2007 cancel_rc
= ibmvfc_cancel_all(sdev
, IBMVFC_TMF_LUN_RESET
);
2008 reset_rc
= ibmvfc_reset_device(sdev
, IBMVFC_LUN_RESET
, "LUN");
2010 if (!cancel_rc
&& !reset_rc
)
2011 rc
= ibmvfc_wait_for_ops(vhost
, sdev
, ibmvfc_match_lun
);
2018 * ibmvfc_dev_cancel_all - Device iterated cancel all function
2019 * @sdev: scsi device struct
2020 * @data: return code
2023 static void ibmvfc_dev_cancel_all(struct scsi_device
*sdev
, void *data
)
2025 unsigned long *rc
= data
;
2026 *rc
|= ibmvfc_cancel_all(sdev
, IBMVFC_TMF_TGT_RESET
);
2030 * ibmvfc_dev_abort_all - Device iterated abort task set function
2031 * @sdev: scsi device struct
2032 * @data: return code
2035 static void ibmvfc_dev_abort_all(struct scsi_device
*sdev
, void *data
)
2037 unsigned long *rc
= data
;
2038 *rc
|= ibmvfc_abort_task_set(sdev
);
2042 * ibmvfc_eh_target_reset_handler - Reset the target
2043 * @cmd: scsi command struct
2048 static int ibmvfc_eh_target_reset_handler(struct scsi_cmnd
*cmd
)
2050 struct scsi_device
*sdev
= cmd
->device
;
2051 struct ibmvfc_host
*vhost
= shost_priv(sdev
->host
);
2052 struct scsi_target
*starget
= scsi_target(sdev
);
2055 unsigned long cancel_rc
= 0;
2058 ibmvfc_wait_while_resetting(vhost
);
2059 starget_for_each_device(starget
, &cancel_rc
, ibmvfc_dev_cancel_all
);
2060 reset_rc
= ibmvfc_reset_device(sdev
, IBMVFC_TARGET_RESET
, "target");
2062 if (!cancel_rc
&& !reset_rc
)
2063 rc
= ibmvfc_wait_for_ops(vhost
, starget
, ibmvfc_match_target
);
2070 * ibmvfc_eh_host_reset_handler - Reset the connection to the server
2071 * @cmd: struct scsi_cmnd having problems
2074 static int ibmvfc_eh_host_reset_handler(struct scsi_cmnd
*cmd
)
2077 struct ibmvfc_host
*vhost
= shost_priv(cmd
->device
->host
);
2079 dev_err(vhost
->dev
, "Resetting connection due to error recovery\n");
2080 rc
= ibmvfc_issue_fc_host_lip(vhost
->host
);
2081 return rc
? FAILED
: SUCCESS
;
2085 * ibmvfc_terminate_rport_io - Terminate all pending I/O to the rport.
2086 * @rport: rport struct
2091 static void ibmvfc_terminate_rport_io(struct fc_rport
*rport
)
2093 struct scsi_target
*starget
= to_scsi_target(&rport
->dev
);
2094 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
2095 struct ibmvfc_host
*vhost
= shost_priv(shost
);
2096 unsigned long cancel_rc
= 0;
2097 unsigned long abort_rc
= 0;
2101 starget_for_each_device(starget
, &cancel_rc
, ibmvfc_dev_cancel_all
);
2102 starget_for_each_device(starget
, &abort_rc
, ibmvfc_dev_abort_all
);
2104 if (!cancel_rc
&& !abort_rc
)
2105 rc
= ibmvfc_wait_for_ops(vhost
, starget
, ibmvfc_match_target
);
2108 ibmvfc_issue_fc_host_lip(shost
);
2112 static const struct {
2113 enum ibmvfc_async_event ae
;
2116 { IBMVFC_AE_ELS_PLOGI
, "PLOGI" },
2117 { IBMVFC_AE_ELS_LOGO
, "LOGO" },
2118 { IBMVFC_AE_ELS_PRLO
, "PRLO" },
2119 { IBMVFC_AE_SCN_NPORT
, "N-Port SCN" },
2120 { IBMVFC_AE_SCN_GROUP
, "Group SCN" },
2121 { IBMVFC_AE_SCN_DOMAIN
, "Domain SCN" },
2122 { IBMVFC_AE_SCN_FABRIC
, "Fabric SCN" },
2123 { IBMVFC_AE_LINK_UP
, "Link Up" },
2124 { IBMVFC_AE_LINK_DOWN
, "Link Down" },
2125 { IBMVFC_AE_LINK_DEAD
, "Link Dead" },
2126 { IBMVFC_AE_HALT
, "Halt" },
2127 { IBMVFC_AE_RESUME
, "Resume" },
2128 { IBMVFC_AE_ADAPTER_FAILED
, "Adapter Failed" },
2131 static const char *unknown_ae
= "Unknown async";
2134 * ibmvfc_get_ae_desc - Get text description for async event
2138 static const char *ibmvfc_get_ae_desc(u64 ae
)
2142 for (i
= 0; i
< ARRAY_SIZE(ae_desc
); i
++)
2143 if (ae_desc
[i
].ae
== ae
)
2144 return ae_desc
[i
].desc
;
2150 * ibmvfc_handle_async - Handle an async event from the adapter
2151 * @crq: crq to process
2152 * @vhost: ibmvfc host struct
2155 static void ibmvfc_handle_async(struct ibmvfc_async_crq
*crq
,
2156 struct ibmvfc_host
*vhost
)
2158 const char *desc
= ibmvfc_get_ae_desc(crq
->event
);
2160 ibmvfc_log(vhost
, 3, "%s event received. scsi_id: %llx, wwpn: %llx,"
2161 " node_name: %llx\n", desc
, crq
->scsi_id
, crq
->wwpn
, crq
->node_name
);
2163 switch (crq
->event
) {
2164 case IBMVFC_AE_LINK_UP
:
2165 case IBMVFC_AE_RESUME
:
2166 vhost
->events_to_log
|= IBMVFC_AE_LINKUP
;
2167 vhost
->delay_init
= 1;
2168 __ibmvfc_reset_host(vhost
);
2170 case IBMVFC_AE_SCN_FABRIC
:
2171 case IBMVFC_AE_SCN_DOMAIN
:
2172 vhost
->events_to_log
|= IBMVFC_AE_RSCN
;
2173 vhost
->delay_init
= 1;
2174 __ibmvfc_reset_host(vhost
);
2176 case IBMVFC_AE_SCN_NPORT
:
2177 case IBMVFC_AE_SCN_GROUP
:
2178 vhost
->events_to_log
|= IBMVFC_AE_RSCN
;
2179 case IBMVFC_AE_ELS_LOGO
:
2180 case IBMVFC_AE_ELS_PRLO
:
2181 case IBMVFC_AE_ELS_PLOGI
:
2182 ibmvfc_reinit_host(vhost
);
2184 case IBMVFC_AE_LINK_DOWN
:
2185 case IBMVFC_AE_ADAPTER_FAILED
:
2186 ibmvfc_link_down(vhost
, IBMVFC_LINK_DOWN
);
2188 case IBMVFC_AE_LINK_DEAD
:
2189 ibmvfc_link_down(vhost
, IBMVFC_LINK_DEAD
);
2191 case IBMVFC_AE_HALT
:
2192 ibmvfc_link_down(vhost
, IBMVFC_HALTED
);
2195 dev_err(vhost
->dev
, "Unknown async event received: %lld\n", crq
->event
);
2201 * ibmvfc_handle_crq - Handles and frees received events in the CRQ
2202 * @crq: Command/Response queue
2203 * @vhost: ibmvfc host struct
2206 static void ibmvfc_handle_crq(struct ibmvfc_crq
*crq
, struct ibmvfc_host
*vhost
)
2209 struct ibmvfc_event
*evt
= (struct ibmvfc_event
*)crq
->ioba
;
2211 switch (crq
->valid
) {
2212 case IBMVFC_CRQ_INIT_RSP
:
2213 switch (crq
->format
) {
2214 case IBMVFC_CRQ_INIT
:
2215 dev_info(vhost
->dev
, "Partner initialized\n");
2216 /* Send back a response */
2217 rc
= ibmvfc_send_crq_init_complete(vhost
);
2219 ibmvfc_init_host(vhost
, 0);
2221 dev_err(vhost
->dev
, "Unable to send init rsp. rc=%ld\n", rc
);
2223 case IBMVFC_CRQ_INIT_COMPLETE
:
2224 dev_info(vhost
->dev
, "Partner initialization complete\n");
2225 ibmvfc_init_host(vhost
, 0);
2228 dev_err(vhost
->dev
, "Unknown crq message type: %d\n", crq
->format
);
2231 case IBMVFC_CRQ_XPORT_EVENT
:
2232 vhost
->state
= IBMVFC_NO_CRQ
;
2233 ibmvfc_set_host_action(vhost
, IBMVFC_HOST_ACTION_NONE
);
2234 if (crq
->format
== IBMVFC_PARTITION_MIGRATED
) {
2235 /* We need to re-setup the interpartition connection */
2236 dev_info(vhost
->dev
, "Re-enabling adapter\n");
2237 vhost
->client_migrated
= 1;
2238 ibmvfc_purge_requests(vhost
, DID_REQUEUE
);
2239 if ((rc
= ibmvfc_reenable_crq_queue(vhost
)) ||
2240 (rc
= ibmvfc_send_crq_init(vhost
))) {
2241 ibmvfc_link_down(vhost
, IBMVFC_LINK_DEAD
);
2242 dev_err(vhost
->dev
, "Error after enable (rc=%ld)\n", rc
);
2244 ibmvfc_link_down(vhost
, IBMVFC_LINK_DOWN
);
2246 dev_err(vhost
->dev
, "Virtual adapter failed (rc=%d)\n", crq
->format
);
2248 ibmvfc_purge_requests(vhost
, DID_ERROR
);
2249 if ((rc
= ibmvfc_reset_crq(vhost
)) ||
2250 (rc
= ibmvfc_send_crq_init(vhost
))) {
2251 ibmvfc_link_down(vhost
, IBMVFC_LINK_DEAD
);
2252 dev_err(vhost
->dev
, "Error after reset (rc=%ld)\n", rc
);
2254 ibmvfc_link_down(vhost
, IBMVFC_LINK_DOWN
);
2257 case IBMVFC_CRQ_CMD_RSP
:
2260 dev_err(vhost
->dev
, "Got an invalid message type 0x%02x\n", crq
->valid
);
2264 if (crq
->format
== IBMVFC_ASYNC_EVENT
)
2267 /* The only kind of payload CRQs we should get are responses to
2268 * things we send. Make sure this response is to something we
2271 if (unlikely(!ibmvfc_valid_event(&vhost
->pool
, evt
))) {
2272 dev_err(vhost
->dev
, "Returned correlation_token 0x%08llx is invalid!\n",
2277 if (unlikely(atomic_read(&evt
->free
))) {
2278 dev_err(vhost
->dev
, "Received duplicate correlation_token 0x%08llx!\n",
2283 del_timer(&evt
->timer
);
2284 list_del(&evt
->queue
);
2285 ibmvfc_trc_end(evt
);
2290 * ibmvfc_scan_finished - Check if the device scan is done.
2291 * @shost: scsi host struct
2292 * @time: current elapsed time
2295 * 0 if scan is not done / 1 if scan is done
2297 static int ibmvfc_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
2299 unsigned long flags
;
2300 struct ibmvfc_host
*vhost
= shost_priv(shost
);
2303 spin_lock_irqsave(shost
->host_lock
, flags
);
2304 if (time
>= (init_timeout
* HZ
)) {
2305 dev_info(vhost
->dev
, "Scan taking longer than %d seconds, "
2306 "continuing initialization\n", init_timeout
);
2310 if (vhost
->scan_complete
)
2312 spin_unlock_irqrestore(shost
->host_lock
, flags
);
2317 * ibmvfc_slave_alloc - Setup the device's task set value
2318 * @sdev: struct scsi_device device to configure
2320 * Set the device's task set value so that error handling works as
2324 * 0 on success / -ENXIO if device does not exist
2326 static int ibmvfc_slave_alloc(struct scsi_device
*sdev
)
2328 struct Scsi_Host
*shost
= sdev
->host
;
2329 struct fc_rport
*rport
= starget_to_rport(scsi_target(sdev
));
2330 struct ibmvfc_host
*vhost
= shost_priv(shost
);
2331 unsigned long flags
= 0;
2333 if (!rport
|| fc_remote_port_chkready(rport
))
2336 spin_lock_irqsave(shost
->host_lock
, flags
);
2337 sdev
->hostdata
= (void *)(unsigned long)vhost
->task_set
++;
2338 spin_unlock_irqrestore(shost
->host_lock
, flags
);
2343 * ibmvfc_target_alloc - Setup the target's task set value
2344 * @starget: struct scsi_target
2346 * Set the target's task set value so that error handling works as
2350 * 0 on success / -ENXIO if device does not exist
2352 static int ibmvfc_target_alloc(struct scsi_target
*starget
)
2354 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
2355 struct ibmvfc_host
*vhost
= shost_priv(shost
);
2356 unsigned long flags
= 0;
2358 spin_lock_irqsave(shost
->host_lock
, flags
);
2359 starget
->hostdata
= (void *)(unsigned long)vhost
->task_set
++;
2360 spin_unlock_irqrestore(shost
->host_lock
, flags
);
2365 * ibmvfc_slave_configure - Configure the device
2366 * @sdev: struct scsi_device device to configure
2368 * Enable allow_restart for a device if it is a disk. Adjust the
2369 * queue_depth here also.
2374 static int ibmvfc_slave_configure(struct scsi_device
*sdev
)
2376 struct Scsi_Host
*shost
= sdev
->host
;
2377 struct fc_rport
*rport
= starget_to_rport(sdev
->sdev_target
);
2378 unsigned long flags
= 0;
2380 spin_lock_irqsave(shost
->host_lock
, flags
);
2381 if (sdev
->type
== TYPE_DISK
)
2382 sdev
->allow_restart
= 1;
2384 if (sdev
->tagged_supported
) {
2385 scsi_set_tag_type(sdev
, MSG_SIMPLE_TAG
);
2386 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
2388 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
2390 rport
->dev_loss_tmo
= dev_loss_tmo
;
2391 spin_unlock_irqrestore(shost
->host_lock
, flags
);
2396 * ibmvfc_change_queue_depth - Change the device's queue depth
2397 * @sdev: scsi device struct
2398 * @qdepth: depth to set
2403 static int ibmvfc_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
2405 if (qdepth
> IBMVFC_MAX_CMDS_PER_LUN
)
2406 qdepth
= IBMVFC_MAX_CMDS_PER_LUN
;
2408 scsi_adjust_queue_depth(sdev
, 0, qdepth
);
2409 return sdev
->queue_depth
;
2413 * ibmvfc_change_queue_type - Change the device's queue type
2414 * @sdev: scsi device struct
2415 * @tag_type: type of tags to use
2418 * actual queue type set
2420 static int ibmvfc_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
2422 if (sdev
->tagged_supported
) {
2423 scsi_set_tag_type(sdev
, tag_type
);
2426 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
2428 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
2435 static ssize_t
ibmvfc_show_host_partition_name(struct device
*dev
,
2436 struct device_attribute
*attr
, char *buf
)
2438 struct Scsi_Host
*shost
= class_to_shost(dev
);
2439 struct ibmvfc_host
*vhost
= shost_priv(shost
);
2441 return snprintf(buf
, PAGE_SIZE
, "%s\n",
2442 vhost
->login_buf
->resp
.partition_name
);
2445 static ssize_t
ibmvfc_show_host_device_name(struct device
*dev
,
2446 struct device_attribute
*attr
, char *buf
)
2448 struct Scsi_Host
*shost
= class_to_shost(dev
);
2449 struct ibmvfc_host
*vhost
= shost_priv(shost
);
2451 return snprintf(buf
, PAGE_SIZE
, "%s\n",
2452 vhost
->login_buf
->resp
.device_name
);
2455 static ssize_t
ibmvfc_show_host_loc_code(struct device
*dev
,
2456 struct device_attribute
*attr
, char *buf
)
2458 struct Scsi_Host
*shost
= class_to_shost(dev
);
2459 struct ibmvfc_host
*vhost
= shost_priv(shost
);
2461 return snprintf(buf
, PAGE_SIZE
, "%s\n",
2462 vhost
->login_buf
->resp
.port_loc_code
);
2465 static ssize_t
ibmvfc_show_host_drc_name(struct device
*dev
,
2466 struct device_attribute
*attr
, char *buf
)
2468 struct Scsi_Host
*shost
= class_to_shost(dev
);
2469 struct ibmvfc_host
*vhost
= shost_priv(shost
);
2471 return snprintf(buf
, PAGE_SIZE
, "%s\n",
2472 vhost
->login_buf
->resp
.drc_name
);
2475 static ssize_t
ibmvfc_show_host_npiv_version(struct device
*dev
,
2476 struct device_attribute
*attr
, char *buf
)
2478 struct Scsi_Host
*shost
= class_to_shost(dev
);
2479 struct ibmvfc_host
*vhost
= shost_priv(shost
);
2480 return snprintf(buf
, PAGE_SIZE
, "%d\n", vhost
->login_buf
->resp
.version
);
2484 * ibmvfc_show_log_level - Show the adapter's error logging level
2485 * @dev: class device struct
2489 * number of bytes printed to buffer
2491 static ssize_t
ibmvfc_show_log_level(struct device
*dev
,
2492 struct device_attribute
*attr
, char *buf
)
2494 struct Scsi_Host
*shost
= class_to_shost(dev
);
2495 struct ibmvfc_host
*vhost
= shost_priv(shost
);
2496 unsigned long flags
= 0;
2499 spin_lock_irqsave(shost
->host_lock
, flags
);
2500 len
= snprintf(buf
, PAGE_SIZE
, "%d\n", vhost
->log_level
);
2501 spin_unlock_irqrestore(shost
->host_lock
, flags
);
2506 * ibmvfc_store_log_level - Change the adapter's error logging level
2507 * @dev: class device struct
2511 * number of bytes printed to buffer
2513 static ssize_t
ibmvfc_store_log_level(struct device
*dev
,
2514 struct device_attribute
*attr
,
2515 const char *buf
, size_t count
)
2517 struct Scsi_Host
*shost
= class_to_shost(dev
);
2518 struct ibmvfc_host
*vhost
= shost_priv(shost
);
2519 unsigned long flags
= 0;
2521 spin_lock_irqsave(shost
->host_lock
, flags
);
2522 vhost
->log_level
= simple_strtoul(buf
, NULL
, 10);
2523 spin_unlock_irqrestore(shost
->host_lock
, flags
);
2527 static DEVICE_ATTR(partition_name
, S_IRUGO
, ibmvfc_show_host_partition_name
, NULL
);
2528 static DEVICE_ATTR(device_name
, S_IRUGO
, ibmvfc_show_host_device_name
, NULL
);
2529 static DEVICE_ATTR(port_loc_code
, S_IRUGO
, ibmvfc_show_host_loc_code
, NULL
);
2530 static DEVICE_ATTR(drc_name
, S_IRUGO
, ibmvfc_show_host_drc_name
, NULL
);
2531 static DEVICE_ATTR(npiv_version
, S_IRUGO
, ibmvfc_show_host_npiv_version
, NULL
);
2532 static DEVICE_ATTR(log_level
, S_IRUGO
| S_IWUSR
,
2533 ibmvfc_show_log_level
, ibmvfc_store_log_level
);
2535 #ifdef CONFIG_SCSI_IBMVFC_TRACE
2537 * ibmvfc_read_trace - Dump the adapter trace
2538 * @kobj: kobject struct
2539 * @bin_attr: bin_attribute struct
2542 * @count: buffer size
2545 * number of bytes printed to buffer
2547 static ssize_t
ibmvfc_read_trace(struct kobject
*kobj
,
2548 struct bin_attribute
*bin_attr
,
2549 char *buf
, loff_t off
, size_t count
)
2551 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2552 struct Scsi_Host
*shost
= class_to_shost(dev
);
2553 struct ibmvfc_host
*vhost
= shost_priv(shost
);
2554 unsigned long flags
= 0;
2555 int size
= IBMVFC_TRACE_SIZE
;
2556 char *src
= (char *)vhost
->trace
;
2560 if (off
+ count
> size
) {
2565 spin_lock_irqsave(shost
->host_lock
, flags
);
2566 memcpy(buf
, &src
[off
], count
);
2567 spin_unlock_irqrestore(shost
->host_lock
, flags
);
2571 static struct bin_attribute ibmvfc_trace_attr
= {
2577 .read
= ibmvfc_read_trace
,
2581 static struct device_attribute
*ibmvfc_attrs
[] = {
2582 &dev_attr_partition_name
,
2583 &dev_attr_device_name
,
2584 &dev_attr_port_loc_code
,
2586 &dev_attr_npiv_version
,
2587 &dev_attr_log_level
,
2591 static struct scsi_host_template driver_template
= {
2592 .module
= THIS_MODULE
,
2593 .name
= "IBM POWER Virtual FC Adapter",
2594 .proc_name
= IBMVFC_NAME
,
2595 .queuecommand
= ibmvfc_queuecommand
,
2596 .eh_abort_handler
= ibmvfc_eh_abort_handler
,
2597 .eh_device_reset_handler
= ibmvfc_eh_device_reset_handler
,
2598 .eh_target_reset_handler
= ibmvfc_eh_target_reset_handler
,
2599 .eh_host_reset_handler
= ibmvfc_eh_host_reset_handler
,
2600 .slave_alloc
= ibmvfc_slave_alloc
,
2601 .slave_configure
= ibmvfc_slave_configure
,
2602 .target_alloc
= ibmvfc_target_alloc
,
2603 .scan_finished
= ibmvfc_scan_finished
,
2604 .change_queue_depth
= ibmvfc_change_queue_depth
,
2605 .change_queue_type
= ibmvfc_change_queue_type
,
2607 .can_queue
= IBMVFC_MAX_REQUESTS_DEFAULT
,
2609 .sg_tablesize
= SG_ALL
,
2610 .max_sectors
= IBMVFC_MAX_SECTORS
,
2611 .use_clustering
= ENABLE_CLUSTERING
,
2612 .shost_attrs
= ibmvfc_attrs
,
2616 * ibmvfc_next_async_crq - Returns the next entry in async queue
2617 * @vhost: ibmvfc host struct
2620 * Pointer to next entry in queue / NULL if empty
2622 static struct ibmvfc_async_crq
*ibmvfc_next_async_crq(struct ibmvfc_host
*vhost
)
2624 struct ibmvfc_async_crq_queue
*async_crq
= &vhost
->async_crq
;
2625 struct ibmvfc_async_crq
*crq
;
2627 crq
= &async_crq
->msgs
[async_crq
->cur
];
2628 if (crq
->valid
& 0x80) {
2629 if (++async_crq
->cur
== async_crq
->size
)
2638 * ibmvfc_next_crq - Returns the next entry in message queue
2639 * @vhost: ibmvfc host struct
2642 * Pointer to next entry in queue / NULL if empty
2644 static struct ibmvfc_crq
*ibmvfc_next_crq(struct ibmvfc_host
*vhost
)
2646 struct ibmvfc_crq_queue
*queue
= &vhost
->crq
;
2647 struct ibmvfc_crq
*crq
;
2649 crq
= &queue
->msgs
[queue
->cur
];
2650 if (crq
->valid
& 0x80) {
2651 if (++queue
->cur
== queue
->size
)
2660 * ibmvfc_interrupt - Interrupt handler
2661 * @irq: number of irq to handle, not used
2662 * @dev_instance: ibmvfc_host that received interrupt
2667 static irqreturn_t
ibmvfc_interrupt(int irq
, void *dev_instance
)
2669 struct ibmvfc_host
*vhost
= (struct ibmvfc_host
*)dev_instance
;
2670 unsigned long flags
;
2672 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
2673 vio_disable_interrupts(to_vio_dev(vhost
->dev
));
2674 tasklet_schedule(&vhost
->tasklet
);
2675 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
2680 * ibmvfc_tasklet - Interrupt handler tasklet
2681 * @data: ibmvfc host struct
2686 static void ibmvfc_tasklet(void *data
)
2688 struct ibmvfc_host
*vhost
= data
;
2689 struct vio_dev
*vdev
= to_vio_dev(vhost
->dev
);
2690 struct ibmvfc_crq
*crq
;
2691 struct ibmvfc_async_crq
*async
;
2692 unsigned long flags
;
2695 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
2697 /* Pull all the valid messages off the CRQ */
2698 while ((crq
= ibmvfc_next_crq(vhost
)) != NULL
) {
2699 ibmvfc_handle_crq(crq
, vhost
);
2703 /* Pull all the valid messages off the async CRQ */
2704 while ((async
= ibmvfc_next_async_crq(vhost
)) != NULL
) {
2705 ibmvfc_handle_async(async
, vhost
);
2709 vio_enable_interrupts(vdev
);
2710 if ((crq
= ibmvfc_next_crq(vhost
)) != NULL
) {
2711 vio_disable_interrupts(vdev
);
2712 ibmvfc_handle_crq(crq
, vhost
);
2714 } else if ((async
= ibmvfc_next_async_crq(vhost
)) != NULL
) {
2715 vio_disable_interrupts(vdev
);
2716 ibmvfc_handle_async(async
, vhost
);
2722 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
2726 * ibmvfc_init_tgt - Set the next init job step for the target
2727 * @tgt: ibmvfc target struct
2728 * @job_step: job step to perform
2731 static void ibmvfc_init_tgt(struct ibmvfc_target
*tgt
,
2732 void (*job_step
) (struct ibmvfc_target
*))
2734 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_INIT
);
2735 tgt
->job_step
= job_step
;
2736 wake_up(&tgt
->vhost
->work_wait_q
);
2740 * ibmvfc_retry_tgt_init - Attempt to retry a step in target initialization
2741 * @tgt: ibmvfc target struct
2742 * @job_step: initialization job step
2744 * Returns: 1 if step will be retried / 0 if not
2747 static int ibmvfc_retry_tgt_init(struct ibmvfc_target
*tgt
,
2748 void (*job_step
) (struct ibmvfc_target
*))
2750 if (++tgt
->init_retries
> IBMVFC_MAX_TGT_INIT_RETRIES
) {
2751 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_DEL_RPORT
);
2752 wake_up(&tgt
->vhost
->work_wait_q
);
2755 ibmvfc_init_tgt(tgt
, job_step
);
2759 /* Defined in FC-LS */
2760 static const struct {
2777 * ibmvfc_get_prli_rsp - Find PRLI response index
2778 * @flags: PRLI response flags
2781 static int ibmvfc_get_prli_rsp(u16 flags
)
2784 int code
= (flags
& 0x0f00) >> 8;
2786 for (i
= 0; i
< ARRAY_SIZE(prli_rsp
); i
++)
2787 if (prli_rsp
[i
].code
== code
)
2794 * ibmvfc_tgt_prli_done - Completion handler for Process Login
2795 * @evt: ibmvfc event struct
2798 static void ibmvfc_tgt_prli_done(struct ibmvfc_event
*evt
)
2800 struct ibmvfc_target
*tgt
= evt
->tgt
;
2801 struct ibmvfc_host
*vhost
= evt
->vhost
;
2802 struct ibmvfc_process_login
*rsp
= &evt
->xfer_iu
->prli
;
2803 struct ibmvfc_prli_svc_parms
*parms
= &rsp
->parms
;
2804 u32 status
= rsp
->common
.status
;
2805 int index
, level
= IBMVFC_DEFAULT_LOG_LEVEL
;
2807 vhost
->discovery_threads
--;
2808 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_NONE
);
2810 case IBMVFC_MAD_SUCCESS
:
2811 tgt_dbg(tgt
, "Process Login succeeded: %X %02X %04X\n",
2812 parms
->type
, parms
->flags
, parms
->service_parms
);
2814 if (parms
->type
== IBMVFC_SCSI_FCP_TYPE
) {
2815 index
= ibmvfc_get_prli_rsp(parms
->flags
);
2816 if (prli_rsp
[index
].logged_in
) {
2817 if (parms
->flags
& IBMVFC_PRLI_EST_IMG_PAIR
) {
2818 tgt
->need_login
= 0;
2820 if (parms
->service_parms
& IBMVFC_PRLI_TARGET_FUNC
)
2821 tgt
->ids
.roles
|= FC_PORT_ROLE_FCP_TARGET
;
2822 if (parms
->service_parms
& IBMVFC_PRLI_INITIATOR_FUNC
)
2823 tgt
->ids
.roles
|= FC_PORT_ROLE_FCP_INITIATOR
;
2826 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_DEL_RPORT
);
2827 } else if (prli_rsp
[index
].retry
)
2828 ibmvfc_retry_tgt_init(tgt
, ibmvfc_tgt_send_prli
);
2830 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_DEL_RPORT
);
2832 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_DEL_RPORT
);
2834 case IBMVFC_MAD_DRIVER_FAILED
:
2836 case IBMVFC_MAD_CRQ_ERROR
:
2837 ibmvfc_retry_tgt_init(tgt
, ibmvfc_tgt_send_prli
);
2839 case IBMVFC_MAD_FAILED
:
2841 if (ibmvfc_retry_cmd(rsp
->status
, rsp
->error
))
2842 level
+= ibmvfc_retry_tgt_init(tgt
, ibmvfc_tgt_send_prli
);
2844 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_DEL_RPORT
);
2846 tgt_log(tgt
, level
, "Process Login failed: %s (%x:%x) rc=0x%02X\n",
2847 ibmvfc_get_cmd_error(rsp
->status
, rsp
->error
),
2848 rsp
->status
, rsp
->error
, status
);
2852 kref_put(&tgt
->kref
, ibmvfc_release_tgt
);
2853 ibmvfc_free_event(evt
);
2854 wake_up(&vhost
->work_wait_q
);
2858 * ibmvfc_tgt_send_prli - Send a process login
2859 * @tgt: ibmvfc target struct
2862 static void ibmvfc_tgt_send_prli(struct ibmvfc_target
*tgt
)
2864 struct ibmvfc_process_login
*prli
;
2865 struct ibmvfc_host
*vhost
= tgt
->vhost
;
2866 struct ibmvfc_event
*evt
;
2868 if (vhost
->discovery_threads
>= disc_threads
)
2871 kref_get(&tgt
->kref
);
2872 evt
= ibmvfc_get_event(vhost
);
2873 vhost
->discovery_threads
++;
2874 ibmvfc_init_event(evt
, ibmvfc_tgt_prli_done
, IBMVFC_MAD_FORMAT
);
2876 prli
= &evt
->iu
.prli
;
2877 memset(prli
, 0, sizeof(*prli
));
2878 prli
->common
.version
= 1;
2879 prli
->common
.opcode
= IBMVFC_PROCESS_LOGIN
;
2880 prli
->common
.length
= sizeof(*prli
);
2881 prli
->scsi_id
= tgt
->scsi_id
;
2883 prli
->parms
.type
= IBMVFC_SCSI_FCP_TYPE
;
2884 prli
->parms
.flags
= IBMVFC_PRLI_EST_IMG_PAIR
;
2885 prli
->parms
.service_parms
= IBMVFC_PRLI_INITIATOR_FUNC
;
2887 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_INIT_WAIT
);
2888 if (ibmvfc_send_event(evt
, vhost
, default_timeout
)) {
2889 vhost
->discovery_threads
--;
2890 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_NONE
);
2891 kref_put(&tgt
->kref
, ibmvfc_release_tgt
);
2893 tgt_dbg(tgt
, "Sent process login\n");
2897 * ibmvfc_tgt_plogi_done - Completion handler for Port Login
2898 * @evt: ibmvfc event struct
2901 static void ibmvfc_tgt_plogi_done(struct ibmvfc_event
*evt
)
2903 struct ibmvfc_target
*tgt
= evt
->tgt
;
2904 struct ibmvfc_host
*vhost
= evt
->vhost
;
2905 struct ibmvfc_port_login
*rsp
= &evt
->xfer_iu
->plogi
;
2906 u32 status
= rsp
->common
.status
;
2907 int level
= IBMVFC_DEFAULT_LOG_LEVEL
;
2909 vhost
->discovery_threads
--;
2910 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_NONE
);
2912 case IBMVFC_MAD_SUCCESS
:
2913 tgt_dbg(tgt
, "Port Login succeeded\n");
2914 if (tgt
->ids
.port_name
&&
2915 tgt
->ids
.port_name
!= wwn_to_u64(rsp
->service_parms
.port_name
)) {
2917 tgt_dbg(tgt
, "Port re-init required\n");
2920 tgt
->ids
.node_name
= wwn_to_u64(rsp
->service_parms
.node_name
);
2921 tgt
->ids
.port_name
= wwn_to_u64(rsp
->service_parms
.port_name
);
2922 tgt
->ids
.port_id
= tgt
->scsi_id
;
2923 memcpy(&tgt
->service_parms
, &rsp
->service_parms
,
2924 sizeof(tgt
->service_parms
));
2925 memcpy(&tgt
->service_parms_change
, &rsp
->service_parms_change
,
2926 sizeof(tgt
->service_parms_change
));
2927 ibmvfc_init_tgt(tgt
, ibmvfc_tgt_send_prli
);
2929 case IBMVFC_MAD_DRIVER_FAILED
:
2931 case IBMVFC_MAD_CRQ_ERROR
:
2932 ibmvfc_retry_tgt_init(tgt
, ibmvfc_tgt_send_plogi
);
2934 case IBMVFC_MAD_FAILED
:
2936 if (ibmvfc_retry_cmd(rsp
->status
, rsp
->error
))
2937 level
+= ibmvfc_retry_tgt_init(tgt
, ibmvfc_tgt_send_plogi
);
2939 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_DEL_RPORT
);
2941 tgt_log(tgt
, level
, "Port Login failed: %s (%x:%x) %s (%x) %s (%x) rc=0x%02X\n",
2942 ibmvfc_get_cmd_error(rsp
->status
, rsp
->error
), rsp
->status
, rsp
->error
,
2943 ibmvfc_get_fc_type(rsp
->fc_type
), rsp
->fc_type
,
2944 ibmvfc_get_ls_explain(rsp
->fc_explain
), rsp
->fc_explain
, status
);
2948 kref_put(&tgt
->kref
, ibmvfc_release_tgt
);
2949 ibmvfc_free_event(evt
);
2950 wake_up(&vhost
->work_wait_q
);
2954 * ibmvfc_tgt_send_plogi - Send PLOGI to the specified target
2955 * @tgt: ibmvfc target struct
2958 static void ibmvfc_tgt_send_plogi(struct ibmvfc_target
*tgt
)
2960 struct ibmvfc_port_login
*plogi
;
2961 struct ibmvfc_host
*vhost
= tgt
->vhost
;
2962 struct ibmvfc_event
*evt
;
2964 if (vhost
->discovery_threads
>= disc_threads
)
2967 kref_get(&tgt
->kref
);
2968 evt
= ibmvfc_get_event(vhost
);
2969 vhost
->discovery_threads
++;
2970 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_INIT_WAIT
);
2971 ibmvfc_init_event(evt
, ibmvfc_tgt_plogi_done
, IBMVFC_MAD_FORMAT
);
2973 plogi
= &evt
->iu
.plogi
;
2974 memset(plogi
, 0, sizeof(*plogi
));
2975 plogi
->common
.version
= 1;
2976 plogi
->common
.opcode
= IBMVFC_PORT_LOGIN
;
2977 plogi
->common
.length
= sizeof(*plogi
);
2978 plogi
->scsi_id
= tgt
->scsi_id
;
2980 if (ibmvfc_send_event(evt
, vhost
, default_timeout
)) {
2981 vhost
->discovery_threads
--;
2982 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_NONE
);
2983 kref_put(&tgt
->kref
, ibmvfc_release_tgt
);
2985 tgt_dbg(tgt
, "Sent port login\n");
2989 * ibmvfc_tgt_implicit_logout_done - Completion handler for Implicit Logout MAD
2990 * @evt: ibmvfc event struct
2993 static void ibmvfc_tgt_implicit_logout_done(struct ibmvfc_event
*evt
)
2995 struct ibmvfc_target
*tgt
= evt
->tgt
;
2996 struct ibmvfc_host
*vhost
= evt
->vhost
;
2997 struct ibmvfc_implicit_logout
*rsp
= &evt
->xfer_iu
->implicit_logout
;
2998 u32 status
= rsp
->common
.status
;
3000 vhost
->discovery_threads
--;
3001 ibmvfc_free_event(evt
);
3002 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_NONE
);
3005 case IBMVFC_MAD_SUCCESS
:
3006 tgt_dbg(tgt
, "Implicit Logout succeeded\n");
3008 case IBMVFC_MAD_DRIVER_FAILED
:
3009 kref_put(&tgt
->kref
, ibmvfc_release_tgt
);
3010 wake_up(&vhost
->work_wait_q
);
3012 case IBMVFC_MAD_FAILED
:
3014 tgt_err(tgt
, "Implicit Logout failed: rc=0x%02X\n", status
);
3018 if (vhost
->action
== IBMVFC_HOST_ACTION_TGT_INIT
)
3019 ibmvfc_init_tgt(tgt
, ibmvfc_tgt_send_plogi
);
3020 else if (vhost
->action
== IBMVFC_HOST_ACTION_QUERY_TGTS
&&
3021 tgt
->scsi_id
!= tgt
->new_scsi_id
)
3022 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_DEL_RPORT
);
3023 kref_put(&tgt
->kref
, ibmvfc_release_tgt
);
3024 wake_up(&vhost
->work_wait_q
);
3028 * ibmvfc_tgt_implicit_logout - Initiate an Implicit Logout for specified target
3029 * @tgt: ibmvfc target struct
3032 static void ibmvfc_tgt_implicit_logout(struct ibmvfc_target
*tgt
)
3034 struct ibmvfc_implicit_logout
*mad
;
3035 struct ibmvfc_host
*vhost
= tgt
->vhost
;
3036 struct ibmvfc_event
*evt
;
3038 if (vhost
->discovery_threads
>= disc_threads
)
3041 kref_get(&tgt
->kref
);
3042 evt
= ibmvfc_get_event(vhost
);
3043 vhost
->discovery_threads
++;
3044 ibmvfc_init_event(evt
, ibmvfc_tgt_implicit_logout_done
, IBMVFC_MAD_FORMAT
);
3046 mad
= &evt
->iu
.implicit_logout
;
3047 memset(mad
, 0, sizeof(*mad
));
3048 mad
->common
.version
= 1;
3049 mad
->common
.opcode
= IBMVFC_IMPLICIT_LOGOUT
;
3050 mad
->common
.length
= sizeof(*mad
);
3051 mad
->old_scsi_id
= tgt
->scsi_id
;
3053 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_INIT_WAIT
);
3054 if (ibmvfc_send_event(evt
, vhost
, default_timeout
)) {
3055 vhost
->discovery_threads
--;
3056 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_NONE
);
3057 kref_put(&tgt
->kref
, ibmvfc_release_tgt
);
3059 tgt_dbg(tgt
, "Sent Implicit Logout\n");
3063 * ibmvfc_adisc_needs_plogi - Does device need PLOGI?
3064 * @mad: ibmvfc passthru mad struct
3065 * @tgt: ibmvfc target struct
3068 * 1 if PLOGI needed / 0 if PLOGI not needed
3070 static int ibmvfc_adisc_needs_plogi(struct ibmvfc_passthru_mad
*mad
,
3071 struct ibmvfc_target
*tgt
)
3073 if (memcmp(&mad
->fc_iu
.response
[2], &tgt
->ids
.port_name
,
3074 sizeof(tgt
->ids
.port_name
)))
3076 if (memcmp(&mad
->fc_iu
.response
[4], &tgt
->ids
.node_name
,
3077 sizeof(tgt
->ids
.node_name
)))
3079 if (mad
->fc_iu
.response
[6] != tgt
->scsi_id
)
3085 * ibmvfc_tgt_adisc_done - Completion handler for ADISC
3086 * @evt: ibmvfc event struct
3089 static void ibmvfc_tgt_adisc_done(struct ibmvfc_event
*evt
)
3091 struct ibmvfc_target
*tgt
= evt
->tgt
;
3092 struct ibmvfc_host
*vhost
= evt
->vhost
;
3093 struct ibmvfc_passthru_mad
*mad
= &evt
->xfer_iu
->passthru
;
3094 u32 status
= mad
->common
.status
;
3095 u8 fc_reason
, fc_explain
;
3097 vhost
->discovery_threads
--;
3098 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_NONE
);
3099 del_timer(&tgt
->timer
);
3102 case IBMVFC_MAD_SUCCESS
:
3103 tgt_dbg(tgt
, "ADISC succeeded\n");
3104 if (ibmvfc_adisc_needs_plogi(mad
, tgt
))
3105 tgt
->need_login
= 1;
3107 case IBMVFC_MAD_DRIVER_FAILED
:
3109 case IBMVFC_MAD_FAILED
:
3111 tgt
->need_login
= 1;
3112 fc_reason
= (mad
->fc_iu
.response
[1] & 0x00ff0000) >> 16;
3113 fc_explain
= (mad
->fc_iu
.response
[1] & 0x0000ff00) >> 8;
3114 tgt_info(tgt
, "ADISC failed: %s (%x:%x) %s (%x) %s (%x) rc=0x%02X\n",
3115 ibmvfc_get_cmd_error(mad
->iu
.status
, mad
->iu
.error
),
3116 mad
->iu
.status
, mad
->iu
.error
,
3117 ibmvfc_get_fc_type(fc_reason
), fc_reason
,
3118 ibmvfc_get_ls_explain(fc_explain
), fc_explain
, status
);
3122 kref_put(&tgt
->kref
, ibmvfc_release_tgt
);
3123 ibmvfc_free_event(evt
);
3124 wake_up(&vhost
->work_wait_q
);
3128 * ibmvfc_init_passthru - Initialize an event struct for FC passthru
3129 * @evt: ibmvfc event struct
3132 static void ibmvfc_init_passthru(struct ibmvfc_event
*evt
)
3134 struct ibmvfc_passthru_mad
*mad
= &evt
->iu
.passthru
;
3136 memset(mad
, 0, sizeof(*mad
));
3137 mad
->common
.version
= 1;
3138 mad
->common
.opcode
= IBMVFC_PASSTHRU
;
3139 mad
->common
.length
= sizeof(*mad
) - sizeof(mad
->fc_iu
) - sizeof(mad
->iu
);
3140 mad
->cmd_ioba
.va
= (u64
)evt
->crq
.ioba
+
3141 offsetof(struct ibmvfc_passthru_mad
, iu
);
3142 mad
->cmd_ioba
.len
= sizeof(mad
->iu
);
3143 mad
->iu
.cmd_len
= sizeof(mad
->fc_iu
.payload
);
3144 mad
->iu
.rsp_len
= sizeof(mad
->fc_iu
.response
);
3145 mad
->iu
.cmd
.va
= (u64
)evt
->crq
.ioba
+
3146 offsetof(struct ibmvfc_passthru_mad
, fc_iu
) +
3147 offsetof(struct ibmvfc_passthru_fc_iu
, payload
);
3148 mad
->iu
.cmd
.len
= sizeof(mad
->fc_iu
.payload
);
3149 mad
->iu
.rsp
.va
= (u64
)evt
->crq
.ioba
+
3150 offsetof(struct ibmvfc_passthru_mad
, fc_iu
) +
3151 offsetof(struct ibmvfc_passthru_fc_iu
, response
);
3152 mad
->iu
.rsp
.len
= sizeof(mad
->fc_iu
.response
);
3156 * ibmvfc_tgt_adisc_cancel_done - Completion handler when cancelling an ADISC
3157 * @evt: ibmvfc event struct
3159 * Just cleanup this event struct. Everything else is handled by
3160 * the ADISC completion handler. If the ADISC never actually comes
3161 * back, we still have the timer running on the ADISC event struct
3162 * which will fire and cause the CRQ to get reset.
3165 static void ibmvfc_tgt_adisc_cancel_done(struct ibmvfc_event
*evt
)
3167 struct ibmvfc_host
*vhost
= evt
->vhost
;
3168 struct ibmvfc_target
*tgt
= evt
->tgt
;
3170 tgt_dbg(tgt
, "ADISC cancel complete\n");
3171 vhost
->abort_threads
--;
3172 ibmvfc_free_event(evt
);
3173 kref_put(&tgt
->kref
, ibmvfc_release_tgt
);
3174 wake_up(&vhost
->work_wait_q
);
3178 * ibmvfc_adisc_timeout - Handle an ADISC timeout
3179 * @tgt: ibmvfc target struct
3181 * If an ADISC times out, send a cancel. If the cancel times
3182 * out, reset the CRQ. When the ADISC comes back as cancelled,
3183 * log back into the target.
3185 static void ibmvfc_adisc_timeout(struct ibmvfc_target
*tgt
)
3187 struct ibmvfc_host
*vhost
= tgt
->vhost
;
3188 struct ibmvfc_event
*evt
;
3189 struct ibmvfc_tmf
*tmf
;
3190 unsigned long flags
;
3193 tgt_dbg(tgt
, "ADISC timeout\n");
3194 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
3195 if (vhost
->abort_threads
>= disc_threads
||
3196 tgt
->action
!= IBMVFC_TGT_ACTION_INIT_WAIT
||
3197 vhost
->state
!= IBMVFC_INITIALIZING
||
3198 vhost
->action
!= IBMVFC_HOST_ACTION_QUERY_TGTS
) {
3199 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
3203 vhost
->abort_threads
++;
3204 kref_get(&tgt
->kref
);
3205 evt
= ibmvfc_get_event(vhost
);
3206 ibmvfc_init_event(evt
, ibmvfc_tgt_adisc_cancel_done
, IBMVFC_MAD_FORMAT
);
3210 memset(tmf
, 0, sizeof(*tmf
));
3211 tmf
->common
.version
= 1;
3212 tmf
->common
.opcode
= IBMVFC_TMF_MAD
;
3213 tmf
->common
.length
= sizeof(*tmf
);
3214 tmf
->scsi_id
= tgt
->scsi_id
;
3215 tmf
->cancel_key
= tgt
->cancel_key
;
3217 rc
= ibmvfc_send_event(evt
, vhost
, default_timeout
);
3220 tgt_err(tgt
, "Failed to send cancel event for ADISC. rc=%d\n", rc
);
3221 vhost
->abort_threads
--;
3222 kref_put(&tgt
->kref
, ibmvfc_release_tgt
);
3223 __ibmvfc_reset_host(vhost
);
3225 tgt_dbg(tgt
, "Attempting to cancel ADISC\n");
3226 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
3230 * ibmvfc_tgt_adisc - Initiate an ADISC for specified target
3231 * @tgt: ibmvfc target struct
3233 * When sending an ADISC we end up with two timers running. The
3234 * first timer is the timer in the ibmvfc target struct. If this
3235 * fires, we send a cancel to the target. The second timer is the
3236 * timer on the ibmvfc event for the ADISC, which is longer. If that
3237 * fires, it means the ADISC timed out and our attempt to cancel it
3238 * also failed, so we need to reset the CRQ.
3240 static void ibmvfc_tgt_adisc(struct ibmvfc_target
*tgt
)
3242 struct ibmvfc_passthru_mad
*mad
;
3243 struct ibmvfc_host
*vhost
= tgt
->vhost
;
3244 struct ibmvfc_event
*evt
;
3246 if (vhost
->discovery_threads
>= disc_threads
)
3249 kref_get(&tgt
->kref
);
3250 evt
= ibmvfc_get_event(vhost
);
3251 vhost
->discovery_threads
++;
3252 ibmvfc_init_event(evt
, ibmvfc_tgt_adisc_done
, IBMVFC_MAD_FORMAT
);
3255 ibmvfc_init_passthru(evt
);
3256 mad
= &evt
->iu
.passthru
;
3257 mad
->iu
.flags
= IBMVFC_FC_ELS
;
3258 mad
->iu
.scsi_id
= tgt
->scsi_id
;
3259 mad
->iu
.cancel_key
= tgt
->cancel_key
;
3261 mad
->fc_iu
.payload
[0] = IBMVFC_ADISC
;
3262 memcpy(&mad
->fc_iu
.payload
[2], &vhost
->login_buf
->resp
.port_name
,
3263 sizeof(vhost
->login_buf
->resp
.port_name
));
3264 memcpy(&mad
->fc_iu
.payload
[4], &vhost
->login_buf
->resp
.node_name
,
3265 sizeof(vhost
->login_buf
->resp
.node_name
));
3266 mad
->fc_iu
.payload
[6] = vhost
->login_buf
->resp
.scsi_id
& 0x00ffffff;
3268 if (timer_pending(&tgt
->timer
))
3269 mod_timer(&tgt
->timer
, jiffies
+ (IBMVFC_ADISC_TIMEOUT
* HZ
));
3271 tgt
->timer
.data
= (unsigned long) tgt
;
3272 tgt
->timer
.expires
= jiffies
+ (IBMVFC_ADISC_TIMEOUT
* HZ
);
3273 tgt
->timer
.function
= (void (*)(unsigned long))ibmvfc_adisc_timeout
;
3274 add_timer(&tgt
->timer
);
3277 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_INIT_WAIT
);
3278 if (ibmvfc_send_event(evt
, vhost
, IBMVFC_ADISC_PLUS_CANCEL_TIMEOUT
)) {
3279 vhost
->discovery_threads
--;
3280 del_timer(&tgt
->timer
);
3281 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_NONE
);
3282 kref_put(&tgt
->kref
, ibmvfc_release_tgt
);
3284 tgt_dbg(tgt
, "Sent ADISC\n");
3288 * ibmvfc_tgt_query_target_done - Completion handler for Query Target MAD
3289 * @evt: ibmvfc event struct
3292 static void ibmvfc_tgt_query_target_done(struct ibmvfc_event
*evt
)
3294 struct ibmvfc_target
*tgt
= evt
->tgt
;
3295 struct ibmvfc_host
*vhost
= evt
->vhost
;
3296 struct ibmvfc_query_tgt
*rsp
= &evt
->xfer_iu
->query_tgt
;
3297 u32 status
= rsp
->common
.status
;
3298 int level
= IBMVFC_DEFAULT_LOG_LEVEL
;
3300 vhost
->discovery_threads
--;
3301 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_NONE
);
3303 case IBMVFC_MAD_SUCCESS
:
3304 tgt_dbg(tgt
, "Query Target succeeded\n");
3305 tgt
->new_scsi_id
= rsp
->scsi_id
;
3306 if (rsp
->scsi_id
!= tgt
->scsi_id
)
3307 ibmvfc_init_tgt(tgt
, ibmvfc_tgt_implicit_logout
);
3309 ibmvfc_init_tgt(tgt
, ibmvfc_tgt_adisc
);
3311 case IBMVFC_MAD_DRIVER_FAILED
:
3313 case IBMVFC_MAD_CRQ_ERROR
:
3314 ibmvfc_retry_tgt_init(tgt
, ibmvfc_tgt_query_target
);
3316 case IBMVFC_MAD_FAILED
:
3318 if ((rsp
->status
& IBMVFC_FABRIC_MAPPED
) == IBMVFC_FABRIC_MAPPED
&&
3319 rsp
->error
== IBMVFC_UNABLE_TO_PERFORM_REQ
&&
3320 rsp
->fc_explain
== IBMVFC_PORT_NAME_NOT_REG
)
3321 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_DEL_RPORT
);
3322 else if (ibmvfc_retry_cmd(rsp
->status
, rsp
->error
))
3323 level
+= ibmvfc_retry_tgt_init(tgt
, ibmvfc_tgt_query_target
);
3325 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_DEL_RPORT
);
3327 tgt_log(tgt
, level
, "Query Target failed: %s (%x:%x) %s (%x) %s (%x) rc=0x%02X\n",
3328 ibmvfc_get_cmd_error(rsp
->status
, rsp
->error
), rsp
->status
, rsp
->error
,
3329 ibmvfc_get_fc_type(rsp
->fc_type
), rsp
->fc_type
,
3330 ibmvfc_get_gs_explain(rsp
->fc_explain
), rsp
->fc_explain
, status
);
3334 kref_put(&tgt
->kref
, ibmvfc_release_tgt
);
3335 ibmvfc_free_event(evt
);
3336 wake_up(&vhost
->work_wait_q
);
3340 * ibmvfc_tgt_query_target - Initiate a Query Target for specified target
3341 * @tgt: ibmvfc target struct
3344 static void ibmvfc_tgt_query_target(struct ibmvfc_target
*tgt
)
3346 struct ibmvfc_query_tgt
*query_tgt
;
3347 struct ibmvfc_host
*vhost
= tgt
->vhost
;
3348 struct ibmvfc_event
*evt
;
3350 if (vhost
->discovery_threads
>= disc_threads
)
3353 kref_get(&tgt
->kref
);
3354 evt
= ibmvfc_get_event(vhost
);
3355 vhost
->discovery_threads
++;
3357 ibmvfc_init_event(evt
, ibmvfc_tgt_query_target_done
, IBMVFC_MAD_FORMAT
);
3358 query_tgt
= &evt
->iu
.query_tgt
;
3359 memset(query_tgt
, 0, sizeof(*query_tgt
));
3360 query_tgt
->common
.version
= 1;
3361 query_tgt
->common
.opcode
= IBMVFC_QUERY_TARGET
;
3362 query_tgt
->common
.length
= sizeof(*query_tgt
);
3363 query_tgt
->wwpn
= tgt
->ids
.port_name
;
3365 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_INIT_WAIT
);
3366 if (ibmvfc_send_event(evt
, vhost
, default_timeout
)) {
3367 vhost
->discovery_threads
--;
3368 ibmvfc_set_tgt_action(tgt
, IBMVFC_TGT_ACTION_NONE
);
3369 kref_put(&tgt
->kref
, ibmvfc_release_tgt
);
3371 tgt_dbg(tgt
, "Sent Query Target\n");
3375 * ibmvfc_alloc_target - Allocate and initialize an ibmvfc target
3376 * @vhost: ibmvfc host struct
3377 * @scsi_id: SCSI ID to allocate target for
3380 * 0 on success / other on failure
3382 static int ibmvfc_alloc_target(struct ibmvfc_host
*vhost
, u64 scsi_id
)
3384 struct ibmvfc_target
*tgt
;
3385 unsigned long flags
;
3387 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
3388 list_for_each_entry(tgt
, &vhost
->targets
, queue
) {
3389 if (tgt
->scsi_id
== scsi_id
) {
3390 if (tgt
->need_login
)
3391 ibmvfc_init_tgt(tgt
, ibmvfc_tgt_implicit_logout
);
3395 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
3397 tgt
= mempool_alloc(vhost
->tgt_pool
, GFP_NOIO
);
3399 dev_err(vhost
->dev
, "Target allocation failure for scsi id %08llx\n",
3404 memset(tgt
, 0, sizeof(*tgt
));
3405 tgt
->scsi_id
= scsi_id
;
3406 tgt
->new_scsi_id
= scsi_id
;
3408 tgt
->need_login
= 1;
3409 tgt
->cancel_key
= vhost
->task_set
++;
3410 init_timer(&tgt
->timer
);
3411 kref_init(&tgt
->kref
);
3412 ibmvfc_init_tgt(tgt
, ibmvfc_tgt_implicit_logout
);
3413 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
3414 list_add_tail(&tgt
->queue
, &vhost
->targets
);
3417 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
3422 * ibmvfc_alloc_targets - Allocate and initialize ibmvfc targets
3423 * @vhost: ibmvfc host struct
3426 * 0 on success / other on failure
3428 static int ibmvfc_alloc_targets(struct ibmvfc_host
*vhost
)
3432 for (i
= 0, rc
= 0; !rc
&& i
< vhost
->num_targets
; i
++)
3433 rc
= ibmvfc_alloc_target(vhost
,
3434 vhost
->disc_buf
->scsi_id
[i
] & IBMVFC_DISC_TGT_SCSI_ID_MASK
);
3440 * ibmvfc_discover_targets_done - Completion handler for discover targets MAD
3441 * @evt: ibmvfc event struct
3444 static void ibmvfc_discover_targets_done(struct ibmvfc_event
*evt
)
3446 struct ibmvfc_host
*vhost
= evt
->vhost
;
3447 struct ibmvfc_discover_targets
*rsp
= &evt
->xfer_iu
->discover_targets
;
3448 u32 mad_status
= rsp
->common
.status
;
3449 int level
= IBMVFC_DEFAULT_LOG_LEVEL
;
3451 switch (mad_status
) {
3452 case IBMVFC_MAD_SUCCESS
:
3453 ibmvfc_dbg(vhost
, "Discover Targets succeeded\n");
3454 vhost
->num_targets
= rsp
->num_written
;
3455 ibmvfc_set_host_action(vhost
, IBMVFC_HOST_ACTION_ALLOC_TGTS
);
3457 case IBMVFC_MAD_FAILED
:
3458 level
+= ibmvfc_retry_host_init(vhost
);
3459 ibmvfc_log(vhost
, level
, "Discover Targets failed: %s (%x:%x)\n",
3460 ibmvfc_get_cmd_error(rsp
->status
, rsp
->error
), rsp
->status
, rsp
->error
);
3462 case IBMVFC_MAD_DRIVER_FAILED
:
3465 dev_err(vhost
->dev
, "Invalid Discover Targets response: 0x%x\n", mad_status
);
3466 ibmvfc_link_down(vhost
, IBMVFC_LINK_DEAD
);
3470 ibmvfc_free_event(evt
);
3471 wake_up(&vhost
->work_wait_q
);
3475 * ibmvfc_discover_targets - Send Discover Targets MAD
3476 * @vhost: ibmvfc host struct
3479 static void ibmvfc_discover_targets(struct ibmvfc_host
*vhost
)
3481 struct ibmvfc_discover_targets
*mad
;
3482 struct ibmvfc_event
*evt
= ibmvfc_get_event(vhost
);
3484 ibmvfc_init_event(evt
, ibmvfc_discover_targets_done
, IBMVFC_MAD_FORMAT
);
3485 mad
= &evt
->iu
.discover_targets
;
3486 memset(mad
, 0, sizeof(*mad
));
3487 mad
->common
.version
= 1;
3488 mad
->common
.opcode
= IBMVFC_DISC_TARGETS
;
3489 mad
->common
.length
= sizeof(*mad
);
3490 mad
->bufflen
= vhost
->disc_buf_sz
;
3491 mad
->buffer
.va
= vhost
->disc_buf_dma
;
3492 mad
->buffer
.len
= vhost
->disc_buf_sz
;
3493 ibmvfc_set_host_action(vhost
, IBMVFC_HOST_ACTION_INIT_WAIT
);
3495 if (!ibmvfc_send_event(evt
, vhost
, default_timeout
))
3496 ibmvfc_dbg(vhost
, "Sent discover targets\n");
3498 ibmvfc_link_down(vhost
, IBMVFC_LINK_DEAD
);
3502 * ibmvfc_npiv_login_done - Completion handler for NPIV Login
3503 * @evt: ibmvfc event struct
3506 static void ibmvfc_npiv_login_done(struct ibmvfc_event
*evt
)
3508 struct ibmvfc_host
*vhost
= evt
->vhost
;
3509 u32 mad_status
= evt
->xfer_iu
->npiv_login
.common
.status
;
3510 struct ibmvfc_npiv_login_resp
*rsp
= &vhost
->login_buf
->resp
;
3511 unsigned int npiv_max_sectors
;
3512 int level
= IBMVFC_DEFAULT_LOG_LEVEL
;
3514 switch (mad_status
) {
3515 case IBMVFC_MAD_SUCCESS
:
3516 ibmvfc_free_event(evt
);
3518 case IBMVFC_MAD_FAILED
:
3519 if (ibmvfc_retry_cmd(rsp
->status
, rsp
->error
))
3520 level
+= ibmvfc_retry_host_init(vhost
);
3522 ibmvfc_link_down(vhost
, IBMVFC_LINK_DEAD
);
3523 ibmvfc_log(vhost
, level
, "NPIV Login failed: %s (%x:%x)\n",
3524 ibmvfc_get_cmd_error(rsp
->status
, rsp
->error
), rsp
->status
, rsp
->error
);
3525 ibmvfc_free_event(evt
);
3527 case IBMVFC_MAD_CRQ_ERROR
:
3528 ibmvfc_retry_host_init(vhost
);
3529 case IBMVFC_MAD_DRIVER_FAILED
:
3530 ibmvfc_free_event(evt
);
3533 dev_err(vhost
->dev
, "Invalid NPIV Login response: 0x%x\n", mad_status
);
3534 ibmvfc_link_down(vhost
, IBMVFC_LINK_DEAD
);
3535 ibmvfc_free_event(evt
);
3539 vhost
->client_migrated
= 0;
3541 if (!(rsp
->flags
& IBMVFC_NATIVE_FC
)) {
3542 dev_err(vhost
->dev
, "Virtual adapter does not support FC. %x\n",
3544 ibmvfc_link_down(vhost
, IBMVFC_LINK_DEAD
);
3545 wake_up(&vhost
->work_wait_q
);
3549 if (rsp
->max_cmds
<= IBMVFC_NUM_INTERNAL_REQ
) {
3550 dev_err(vhost
->dev
, "Virtual adapter supported queue depth too small: %d\n",
3552 ibmvfc_link_down(vhost
, IBMVFC_LINK_DEAD
);
3553 wake_up(&vhost
->work_wait_q
);
3557 npiv_max_sectors
= min((uint
)(rsp
->max_dma_len
>> 9), IBMVFC_MAX_SECTORS
);
3558 dev_info(vhost
->dev
, "Host partition: %s, device: %s %s %s max sectors %u\n",
3559 rsp
->partition_name
, rsp
->device_name
, rsp
->port_loc_code
,
3560 rsp
->drc_name
, npiv_max_sectors
);
3562 fc_host_fabric_name(vhost
->host
) = rsp
->node_name
;
3563 fc_host_node_name(vhost
->host
) = rsp
->node_name
;
3564 fc_host_port_name(vhost
->host
) = rsp
->port_name
;
3565 fc_host_port_id(vhost
->host
) = rsp
->scsi_id
;
3566 fc_host_port_type(vhost
->host
) = FC_PORTTYPE_NPIV
;
3567 fc_host_supported_classes(vhost
->host
) = 0;
3568 if (rsp
->service_parms
.class1_parms
[0] & 0x80000000)
3569 fc_host_supported_classes(vhost
->host
) |= FC_COS_CLASS1
;
3570 if (rsp
->service_parms
.class2_parms
[0] & 0x80000000)
3571 fc_host_supported_classes(vhost
->host
) |= FC_COS_CLASS2
;
3572 if (rsp
->service_parms
.class3_parms
[0] & 0x80000000)
3573 fc_host_supported_classes(vhost
->host
) |= FC_COS_CLASS3
;
3574 fc_host_maxframe_size(vhost
->host
) =
3575 rsp
->service_parms
.common
.bb_rcv_sz
& 0x0fff;
3577 vhost
->host
->can_queue
= rsp
->max_cmds
- IBMVFC_NUM_INTERNAL_REQ
;
3578 vhost
->host
->max_sectors
= npiv_max_sectors
;
3579 ibmvfc_set_host_action(vhost
, IBMVFC_HOST_ACTION_QUERY
);
3580 wake_up(&vhost
->work_wait_q
);
3584 * ibmvfc_npiv_login - Sends NPIV login
3585 * @vhost: ibmvfc host struct
3588 static void ibmvfc_npiv_login(struct ibmvfc_host
*vhost
)
3590 struct ibmvfc_npiv_login_mad
*mad
;
3591 struct ibmvfc_event
*evt
= ibmvfc_get_event(vhost
);
3593 ibmvfc_gather_partition_info(vhost
);
3594 ibmvfc_set_login_info(vhost
);
3595 ibmvfc_init_event(evt
, ibmvfc_npiv_login_done
, IBMVFC_MAD_FORMAT
);
3597 memcpy(vhost
->login_buf
, &vhost
->login_info
, sizeof(vhost
->login_info
));
3598 mad
= &evt
->iu
.npiv_login
;
3599 memset(mad
, 0, sizeof(struct ibmvfc_npiv_login_mad
));
3600 mad
->common
.version
= 1;
3601 mad
->common
.opcode
= IBMVFC_NPIV_LOGIN
;
3602 mad
->common
.length
= sizeof(struct ibmvfc_npiv_login_mad
);
3603 mad
->buffer
.va
= vhost
->login_buf_dma
;
3604 mad
->buffer
.len
= sizeof(*vhost
->login_buf
);
3606 ibmvfc_set_host_action(vhost
, IBMVFC_HOST_ACTION_INIT_WAIT
);
3608 if (!ibmvfc_send_event(evt
, vhost
, default_timeout
))
3609 ibmvfc_dbg(vhost
, "Sent NPIV login\n");
3611 ibmvfc_link_down(vhost
, IBMVFC_LINK_DEAD
);
3615 * ibmvfc_dev_init_to_do - Is there target initialization work to do?
3616 * @vhost: ibmvfc host struct
3619 * 1 if work to do / 0 if not
3621 static int ibmvfc_dev_init_to_do(struct ibmvfc_host
*vhost
)
3623 struct ibmvfc_target
*tgt
;
3625 list_for_each_entry(tgt
, &vhost
->targets
, queue
) {
3626 if (tgt
->action
== IBMVFC_TGT_ACTION_INIT
||
3627 tgt
->action
== IBMVFC_TGT_ACTION_INIT_WAIT
)
3635 * __ibmvfc_work_to_do - Is there task level work to do? (no locking)
3636 * @vhost: ibmvfc host struct
3639 * 1 if work to do / 0 if not
3641 static int __ibmvfc_work_to_do(struct ibmvfc_host
*vhost
)
3643 struct ibmvfc_target
*tgt
;
3645 if (kthread_should_stop())
3647 switch (vhost
->action
) {
3648 case IBMVFC_HOST_ACTION_NONE
:
3649 case IBMVFC_HOST_ACTION_INIT_WAIT
:
3651 case IBMVFC_HOST_ACTION_TGT_INIT
:
3652 case IBMVFC_HOST_ACTION_QUERY_TGTS
:
3653 if (vhost
->discovery_threads
== disc_threads
)
3655 list_for_each_entry(tgt
, &vhost
->targets
, queue
)
3656 if (tgt
->action
== IBMVFC_TGT_ACTION_INIT
)
3658 list_for_each_entry(tgt
, &vhost
->targets
, queue
)
3659 if (tgt
->action
== IBMVFC_TGT_ACTION_INIT_WAIT
)
3662 case IBMVFC_HOST_ACTION_INIT
:
3663 case IBMVFC_HOST_ACTION_ALLOC_TGTS
:
3664 case IBMVFC_HOST_ACTION_TGT_DEL
:
3665 case IBMVFC_HOST_ACTION_TGT_DEL_FAILED
:
3666 case IBMVFC_HOST_ACTION_QUERY
:
3675 * ibmvfc_work_to_do - Is there task level work to do?
3676 * @vhost: ibmvfc host struct
3679 * 1 if work to do / 0 if not
3681 static int ibmvfc_work_to_do(struct ibmvfc_host
*vhost
)
3683 unsigned long flags
;
3686 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
3687 rc
= __ibmvfc_work_to_do(vhost
);
3688 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
3693 * ibmvfc_log_ae - Log async events if necessary
3694 * @vhost: ibmvfc host struct
3695 * @events: events to log
3698 static void ibmvfc_log_ae(struct ibmvfc_host
*vhost
, int events
)
3700 if (events
& IBMVFC_AE_RSCN
)
3701 fc_host_post_event(vhost
->host
, fc_get_event_number(), FCH_EVT_RSCN
, 0);
3702 if ((events
& IBMVFC_AE_LINKDOWN
) &&
3703 vhost
->state
>= IBMVFC_HALTED
)
3704 fc_host_post_event(vhost
->host
, fc_get_event_number(), FCH_EVT_LINKDOWN
, 0);
3705 if ((events
& IBMVFC_AE_LINKUP
) &&
3706 vhost
->state
== IBMVFC_INITIALIZING
)
3707 fc_host_post_event(vhost
->host
, fc_get_event_number(), FCH_EVT_LINKUP
, 0);
3711 * ibmvfc_tgt_add_rport - Tell the FC transport about a new remote port
3712 * @tgt: ibmvfc target struct
3715 static void ibmvfc_tgt_add_rport(struct ibmvfc_target
*tgt
)
3717 struct ibmvfc_host
*vhost
= tgt
->vhost
;
3718 struct fc_rport
*rport
;
3719 unsigned long flags
;
3721 tgt_dbg(tgt
, "Adding rport\n");
3722 rport
= fc_remote_port_add(vhost
->host
, 0, &tgt
->ids
);
3723 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
3725 if (rport
&& tgt
->action
== IBMVFC_TGT_ACTION_DEL_RPORT
) {
3726 tgt_dbg(tgt
, "Deleting rport\n");
3727 list_del(&tgt
->queue
);
3728 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
3729 fc_remote_port_delete(rport
);
3730 del_timer_sync(&tgt
->timer
);
3731 kref_put(&tgt
->kref
, ibmvfc_release_tgt
);
3736 tgt_dbg(tgt
, "rport add succeeded\n");
3738 rport
->maxframe_size
= tgt
->service_parms
.common
.bb_rcv_sz
& 0x0fff;
3739 rport
->supported_classes
= 0;
3740 tgt
->target_id
= rport
->scsi_target_id
;
3741 if (tgt
->service_parms
.class1_parms
[0] & 0x80000000)
3742 rport
->supported_classes
|= FC_COS_CLASS1
;
3743 if (tgt
->service_parms
.class2_parms
[0] & 0x80000000)
3744 rport
->supported_classes
|= FC_COS_CLASS2
;
3745 if (tgt
->service_parms
.class3_parms
[0] & 0x80000000)
3746 rport
->supported_classes
|= FC_COS_CLASS3
;
3748 tgt_dbg(tgt
, "rport add failed\n");
3749 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
3753 * ibmvfc_do_work - Do task level work
3754 * @vhost: ibmvfc host struct
3757 static void ibmvfc_do_work(struct ibmvfc_host
*vhost
)
3759 struct ibmvfc_target
*tgt
;
3760 unsigned long flags
;
3761 struct fc_rport
*rport
;
3763 ibmvfc_log_ae(vhost
, vhost
->events_to_log
);
3764 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
3765 vhost
->events_to_log
= 0;
3766 switch (vhost
->action
) {
3767 case IBMVFC_HOST_ACTION_NONE
:
3768 case IBMVFC_HOST_ACTION_INIT_WAIT
:
3770 case IBMVFC_HOST_ACTION_INIT
:
3771 BUG_ON(vhost
->state
!= IBMVFC_INITIALIZING
);
3772 if (vhost
->delay_init
) {
3773 vhost
->delay_init
= 0;
3774 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
3778 vhost
->job_step(vhost
);
3780 case IBMVFC_HOST_ACTION_QUERY
:
3781 list_for_each_entry(tgt
, &vhost
->targets
, queue
)
3782 ibmvfc_init_tgt(tgt
, ibmvfc_tgt_query_target
);
3783 ibmvfc_set_host_action(vhost
, IBMVFC_HOST_ACTION_QUERY_TGTS
);
3785 case IBMVFC_HOST_ACTION_QUERY_TGTS
:
3786 list_for_each_entry(tgt
, &vhost
->targets
, queue
) {
3787 if (tgt
->action
== IBMVFC_TGT_ACTION_INIT
) {
3793 if (!ibmvfc_dev_init_to_do(vhost
))
3794 ibmvfc_set_host_action(vhost
, IBMVFC_HOST_ACTION_TGT_DEL
);
3796 case IBMVFC_HOST_ACTION_TGT_DEL
:
3797 case IBMVFC_HOST_ACTION_TGT_DEL_FAILED
:
3798 list_for_each_entry(tgt
, &vhost
->targets
, queue
) {
3799 if (tgt
->action
== IBMVFC_TGT_ACTION_DEL_RPORT
) {
3800 tgt_dbg(tgt
, "Deleting rport\n");
3803 list_del(&tgt
->queue
);
3804 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
3806 fc_remote_port_delete(rport
);
3807 del_timer_sync(&tgt
->timer
);
3808 kref_put(&tgt
->kref
, ibmvfc_release_tgt
);
3813 if (vhost
->state
== IBMVFC_INITIALIZING
) {
3814 if (vhost
->action
== IBMVFC_HOST_ACTION_TGT_DEL_FAILED
) {
3815 if (vhost
->reinit
) {
3817 scsi_block_requests(vhost
->host
);
3818 ibmvfc_set_host_action(vhost
, IBMVFC_HOST_ACTION_QUERY
);
3819 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
3821 ibmvfc_set_host_state(vhost
, IBMVFC_ACTIVE
);
3822 ibmvfc_set_host_action(vhost
, IBMVFC_HOST_ACTION_NONE
);
3823 wake_up(&vhost
->init_wait_q
);
3824 schedule_work(&vhost
->rport_add_work_q
);
3825 vhost
->init_retries
= 0;
3826 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
3827 scsi_unblock_requests(vhost
->host
);
3832 ibmvfc_set_host_action(vhost
, IBMVFC_HOST_ACTION_INIT
);
3833 vhost
->job_step
= ibmvfc_discover_targets
;
3836 ibmvfc_set_host_action(vhost
, IBMVFC_HOST_ACTION_NONE
);
3837 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
3838 scsi_unblock_requests(vhost
->host
);
3839 wake_up(&vhost
->init_wait_q
);
3843 case IBMVFC_HOST_ACTION_ALLOC_TGTS
:
3844 ibmvfc_set_host_action(vhost
, IBMVFC_HOST_ACTION_TGT_INIT
);
3845 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
3846 ibmvfc_alloc_targets(vhost
);
3847 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
3849 case IBMVFC_HOST_ACTION_TGT_INIT
:
3850 list_for_each_entry(tgt
, &vhost
->targets
, queue
) {
3851 if (tgt
->action
== IBMVFC_TGT_ACTION_INIT
) {
3857 if (!ibmvfc_dev_init_to_do(vhost
))
3858 ibmvfc_set_host_action(vhost
, IBMVFC_HOST_ACTION_TGT_DEL_FAILED
);
3864 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
3868 * ibmvfc_work - Do task level work
3869 * @data: ibmvfc host struct
3874 static int ibmvfc_work(void *data
)
3876 struct ibmvfc_host
*vhost
= data
;
3879 set_user_nice(current
, -20);
3882 rc
= wait_event_interruptible(vhost
->work_wait_q
,
3883 ibmvfc_work_to_do(vhost
));
3887 if (kthread_should_stop())
3890 ibmvfc_do_work(vhost
);
3893 ibmvfc_dbg(vhost
, "ibmvfc kthread exiting...\n");
3898 * ibmvfc_init_crq - Initializes and registers CRQ with hypervisor
3899 * @vhost: ibmvfc host struct
3901 * Allocates a page for messages, maps it for dma, and registers
3902 * the crq with the hypervisor.
3905 * zero on success / other on failure
3907 static int ibmvfc_init_crq(struct ibmvfc_host
*vhost
)
3909 int rc
, retrc
= -ENOMEM
;
3910 struct device
*dev
= vhost
->dev
;
3911 struct vio_dev
*vdev
= to_vio_dev(dev
);
3912 struct ibmvfc_crq_queue
*crq
= &vhost
->crq
;
3915 crq
->msgs
= (struct ibmvfc_crq
*)get_zeroed_page(GFP_KERNEL
);
3920 crq
->size
= PAGE_SIZE
/ sizeof(*crq
->msgs
);
3921 crq
->msg_token
= dma_map_single(dev
, crq
->msgs
,
3922 PAGE_SIZE
, DMA_BIDIRECTIONAL
);
3924 if (dma_mapping_error(dev
, crq
->msg_token
))
3927 retrc
= rc
= plpar_hcall_norets(H_REG_CRQ
, vdev
->unit_address
,
3928 crq
->msg_token
, PAGE_SIZE
);
3930 if (rc
== H_RESOURCE
)
3931 /* maybe kexecing and resource is busy. try a reset */
3932 retrc
= rc
= ibmvfc_reset_crq(vhost
);
3935 dev_warn(dev
, "Partner adapter not ready\n");
3937 dev_warn(dev
, "Error %d opening adapter\n", rc
);
3938 goto reg_crq_failed
;
3943 tasklet_init(&vhost
->tasklet
, (void *)ibmvfc_tasklet
, (unsigned long)vhost
);
3945 if ((rc
= request_irq(vdev
->irq
, ibmvfc_interrupt
, 0, IBMVFC_NAME
, vhost
))) {
3946 dev_err(dev
, "Couldn't register irq 0x%x. rc=%d\n", vdev
->irq
, rc
);
3947 goto req_irq_failed
;
3950 if ((rc
= vio_enable_interrupts(vdev
))) {
3951 dev_err(dev
, "Error %d enabling interrupts\n", rc
);
3952 goto req_irq_failed
;
3960 tasklet_kill(&vhost
->tasklet
);
3962 rc
= plpar_hcall_norets(H_FREE_CRQ
, vdev
->unit_address
);
3963 } while (rc
== H_BUSY
|| H_IS_LONG_BUSY(rc
));
3965 dma_unmap_single(dev
, crq
->msg_token
, PAGE_SIZE
, DMA_BIDIRECTIONAL
);
3967 free_page((unsigned long)crq
->msgs
);
3972 * ibmvfc_free_mem - Free memory for vhost
3973 * @vhost: ibmvfc host struct
3978 static void ibmvfc_free_mem(struct ibmvfc_host
*vhost
)
3980 struct ibmvfc_async_crq_queue
*async_q
= &vhost
->async_crq
;
3983 mempool_destroy(vhost
->tgt_pool
);
3984 kfree(vhost
->trace
);
3985 dma_free_coherent(vhost
->dev
, vhost
->disc_buf_sz
, vhost
->disc_buf
,
3986 vhost
->disc_buf_dma
);
3987 dma_free_coherent(vhost
->dev
, sizeof(*vhost
->login_buf
),
3988 vhost
->login_buf
, vhost
->login_buf_dma
);
3989 dma_pool_destroy(vhost
->sg_pool
);
3990 dma_unmap_single(vhost
->dev
, async_q
->msg_token
,
3991 async_q
->size
* sizeof(*async_q
->msgs
), DMA_BIDIRECTIONAL
);
3992 free_page((unsigned long)async_q
->msgs
);
3997 * ibmvfc_alloc_mem - Allocate memory for vhost
3998 * @vhost: ibmvfc host struct
4001 * 0 on success / non-zero on failure
4003 static int ibmvfc_alloc_mem(struct ibmvfc_host
*vhost
)
4005 struct ibmvfc_async_crq_queue
*async_q
= &vhost
->async_crq
;
4006 struct device
*dev
= vhost
->dev
;
4009 async_q
->msgs
= (struct ibmvfc_async_crq
*)get_zeroed_page(GFP_KERNEL
);
4010 if (!async_q
->msgs
) {
4011 dev_err(dev
, "Couldn't allocate async queue.\n");
4015 async_q
->size
= PAGE_SIZE
/ sizeof(struct ibmvfc_async_crq
);
4016 async_q
->msg_token
= dma_map_single(dev
, async_q
->msgs
,
4017 async_q
->size
* sizeof(*async_q
->msgs
),
4020 if (dma_mapping_error(dev
, async_q
->msg_token
)) {
4021 dev_err(dev
, "Failed to map async queue\n");
4022 goto free_async_crq
;
4025 vhost
->sg_pool
= dma_pool_create(IBMVFC_NAME
, dev
,
4026 SG_ALL
* sizeof(struct srp_direct_buf
),
4027 sizeof(struct srp_direct_buf
), 0);
4029 if (!vhost
->sg_pool
) {
4030 dev_err(dev
, "Failed to allocate sg pool\n");
4031 goto unmap_async_crq
;
4034 vhost
->login_buf
= dma_alloc_coherent(dev
, sizeof(*vhost
->login_buf
),
4035 &vhost
->login_buf_dma
, GFP_KERNEL
);
4037 if (!vhost
->login_buf
) {
4038 dev_err(dev
, "Couldn't allocate NPIV login buffer\n");
4042 vhost
->disc_buf_sz
= sizeof(vhost
->disc_buf
->scsi_id
[0]) * max_targets
;
4043 vhost
->disc_buf
= dma_alloc_coherent(dev
, vhost
->disc_buf_sz
,
4044 &vhost
->disc_buf_dma
, GFP_KERNEL
);
4046 if (!vhost
->disc_buf
) {
4047 dev_err(dev
, "Couldn't allocate Discover Targets buffer\n");
4048 goto free_login_buffer
;
4051 vhost
->trace
= kcalloc(IBMVFC_NUM_TRACE_ENTRIES
,
4052 sizeof(struct ibmvfc_trace_entry
), GFP_KERNEL
);
4055 goto free_disc_buffer
;
4057 vhost
->tgt_pool
= mempool_create_kzalloc_pool(IBMVFC_TGT_MEMPOOL_SZ
,
4058 sizeof(struct ibmvfc_target
));
4060 if (!vhost
->tgt_pool
) {
4061 dev_err(dev
, "Couldn't allocate target memory pool\n");
4069 kfree(vhost
->trace
);
4071 dma_free_coherent(dev
, vhost
->disc_buf_sz
, vhost
->disc_buf
,
4072 vhost
->disc_buf_dma
);
4074 dma_free_coherent(dev
, sizeof(*vhost
->login_buf
),
4075 vhost
->login_buf
, vhost
->login_buf_dma
);
4077 dma_pool_destroy(vhost
->sg_pool
);
4079 dma_unmap_single(dev
, async_q
->msg_token
,
4080 async_q
->size
* sizeof(*async_q
->msgs
), DMA_BIDIRECTIONAL
);
4082 free_page((unsigned long)async_q
->msgs
);
4089 * ibmvfc_rport_add_thread - Worker thread for rport adds
4090 * @work: work struct
4093 static void ibmvfc_rport_add_thread(struct work_struct
*work
)
4095 struct ibmvfc_host
*vhost
= container_of(work
, struct ibmvfc_host
,
4097 struct ibmvfc_target
*tgt
;
4098 struct fc_rport
*rport
;
4099 unsigned long flags
;
4103 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
4106 if (vhost
->state
!= IBMVFC_ACTIVE
)
4109 list_for_each_entry(tgt
, &vhost
->targets
, queue
) {
4110 if (tgt
->add_rport
) {
4113 kref_get(&tgt
->kref
);
4116 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
4117 ibmvfc_tgt_add_rport(tgt
);
4118 } else if (get_device(&rport
->dev
)) {
4119 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
4120 tgt_dbg(tgt
, "Setting rport roles\n");
4121 fc_remote_port_rolechg(rport
, tgt
->ids
.roles
);
4122 put_device(&rport
->dev
);
4125 kref_put(&tgt
->kref
, ibmvfc_release_tgt
);
4126 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
4132 if (vhost
->state
== IBMVFC_ACTIVE
)
4133 vhost
->scan_complete
= 1;
4134 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
4139 * ibmvfc_probe - Adapter hot plug add entry point
4140 * @vdev: vio device struct
4141 * @id: vio device id struct
4144 * 0 on success / non-zero on failure
4146 static int ibmvfc_probe(struct vio_dev
*vdev
, const struct vio_device_id
*id
)
4148 struct ibmvfc_host
*vhost
;
4149 struct Scsi_Host
*shost
;
4150 struct device
*dev
= &vdev
->dev
;
4154 shost
= scsi_host_alloc(&driver_template
, sizeof(*vhost
));
4156 dev_err(dev
, "Couldn't allocate host data\n");
4160 shost
->transportt
= ibmvfc_transport_template
;
4161 shost
->can_queue
= max_requests
;
4162 shost
->max_lun
= max_lun
;
4163 shost
->max_id
= max_targets
;
4164 shost
->max_sectors
= IBMVFC_MAX_SECTORS
;
4165 shost
->max_cmd_len
= IBMVFC_MAX_CDB_LEN
;
4166 shost
->unique_id
= shost
->host_no
;
4168 vhost
= shost_priv(shost
);
4169 INIT_LIST_HEAD(&vhost
->sent
);
4170 INIT_LIST_HEAD(&vhost
->free
);
4171 INIT_LIST_HEAD(&vhost
->targets
);
4172 sprintf(vhost
->name
, IBMVFC_NAME
);
4173 vhost
->host
= shost
;
4175 vhost
->partition_number
= -1;
4176 vhost
->log_level
= log_level
;
4177 vhost
->task_set
= 1;
4178 strcpy(vhost
->partition_name
, "UNKNOWN");
4179 init_waitqueue_head(&vhost
->work_wait_q
);
4180 init_waitqueue_head(&vhost
->init_wait_q
);
4181 INIT_WORK(&vhost
->rport_add_work_q
, ibmvfc_rport_add_thread
);
4183 if ((rc
= ibmvfc_alloc_mem(vhost
)))
4184 goto free_scsi_host
;
4186 vhost
->work_thread
= kthread_run(ibmvfc_work
, vhost
, "%s_%d", IBMVFC_NAME
,
4189 if (IS_ERR(vhost
->work_thread
)) {
4190 dev_err(dev
, "Couldn't create kernel thread: %ld\n",
4191 PTR_ERR(vhost
->work_thread
));
4195 if ((rc
= ibmvfc_init_crq(vhost
))) {
4196 dev_err(dev
, "Couldn't initialize crq. rc=%d\n", rc
);
4200 if ((rc
= ibmvfc_init_event_pool(vhost
))) {
4201 dev_err(dev
, "Couldn't initialize event pool. rc=%d\n", rc
);
4205 if ((rc
= scsi_add_host(shost
, dev
)))
4206 goto release_event_pool
;
4208 if ((rc
= ibmvfc_create_trace_file(&shost
->shost_dev
.kobj
,
4209 &ibmvfc_trace_attr
))) {
4210 dev_err(dev
, "Failed to create trace file. rc=%d\n", rc
);
4214 dev_set_drvdata(dev
, vhost
);
4215 spin_lock(&ibmvfc_driver_lock
);
4216 list_add_tail(&vhost
->queue
, &ibmvfc_head
);
4217 spin_unlock(&ibmvfc_driver_lock
);
4219 ibmvfc_send_crq_init(vhost
);
4220 scsi_scan_host(shost
);
4224 scsi_remove_host(shost
);
4226 ibmvfc_free_event_pool(vhost
);
4228 ibmvfc_release_crq_queue(vhost
);
4230 kthread_stop(vhost
->work_thread
);
4232 ibmvfc_free_mem(vhost
);
4234 scsi_host_put(shost
);
4241 * ibmvfc_remove - Adapter hot plug remove entry point
4242 * @vdev: vio device struct
4247 static int ibmvfc_remove(struct vio_dev
*vdev
)
4249 struct ibmvfc_host
*vhost
= dev_get_drvdata(&vdev
->dev
);
4250 unsigned long flags
;
4253 ibmvfc_remove_trace_file(&vhost
->host
->shost_dev
.kobj
, &ibmvfc_trace_attr
);
4254 ibmvfc_link_down(vhost
, IBMVFC_HOST_OFFLINE
);
4255 ibmvfc_wait_while_resetting(vhost
);
4256 ibmvfc_release_crq_queue(vhost
);
4257 kthread_stop(vhost
->work_thread
);
4258 fc_remove_host(vhost
->host
);
4259 scsi_remove_host(vhost
->host
);
4261 spin_lock_irqsave(vhost
->host
->host_lock
, flags
);
4262 ibmvfc_purge_requests(vhost
, DID_ERROR
);
4263 ibmvfc_free_event_pool(vhost
);
4264 spin_unlock_irqrestore(vhost
->host
->host_lock
, flags
);
4266 ibmvfc_free_mem(vhost
);
4267 spin_lock(&ibmvfc_driver_lock
);
4268 list_del(&vhost
->queue
);
4269 spin_unlock(&ibmvfc_driver_lock
);
4270 scsi_host_put(vhost
->host
);
4276 * ibmvfc_get_desired_dma - Calculate DMA resources needed by the driver
4277 * @vdev: vio device struct
4280 * Number of bytes the driver will need to DMA map at the same time in
4281 * order to perform well.
4283 static unsigned long ibmvfc_get_desired_dma(struct vio_dev
*vdev
)
4285 unsigned long pool_dma
= max_requests
* sizeof(union ibmvfc_iu
);
4286 return pool_dma
+ ((512 * 1024) * driver_template
.cmd_per_lun
);
4289 static struct vio_device_id ibmvfc_device_table
[] __devinitdata
= {
4290 {"fcp", "IBM,vfc-client"},
4293 MODULE_DEVICE_TABLE(vio
, ibmvfc_device_table
);
4295 static struct vio_driver ibmvfc_driver
= {
4296 .id_table
= ibmvfc_device_table
,
4297 .probe
= ibmvfc_probe
,
4298 .remove
= ibmvfc_remove
,
4299 .get_desired_dma
= ibmvfc_get_desired_dma
,
4301 .name
= IBMVFC_NAME
,
4302 .owner
= THIS_MODULE
,
4306 static struct fc_function_template ibmvfc_transport_functions
= {
4307 .show_host_fabric_name
= 1,
4308 .show_host_node_name
= 1,
4309 .show_host_port_name
= 1,
4310 .show_host_supported_classes
= 1,
4311 .show_host_port_type
= 1,
4312 .show_host_port_id
= 1,
4313 .show_host_maxframe_size
= 1,
4315 .get_host_port_state
= ibmvfc_get_host_port_state
,
4316 .show_host_port_state
= 1,
4318 .get_host_speed
= ibmvfc_get_host_speed
,
4319 .show_host_speed
= 1,
4321 .issue_fc_host_lip
= ibmvfc_issue_fc_host_lip
,
4322 .terminate_rport_io
= ibmvfc_terminate_rport_io
,
4324 .show_rport_maxframe_size
= 1,
4325 .show_rport_supported_classes
= 1,
4327 .set_rport_dev_loss_tmo
= ibmvfc_set_rport_dev_loss_tmo
,
4328 .show_rport_dev_loss_tmo
= 1,
4330 .get_starget_node_name
= ibmvfc_get_starget_node_name
,
4331 .show_starget_node_name
= 1,
4333 .get_starget_port_name
= ibmvfc_get_starget_port_name
,
4334 .show_starget_port_name
= 1,
4336 .get_starget_port_id
= ibmvfc_get_starget_port_id
,
4337 .show_starget_port_id
= 1,
4341 * ibmvfc_module_init - Initialize the ibmvfc module
4344 * 0 on success / other on failure
4346 static int __init
ibmvfc_module_init(void)
4350 if (!firmware_has_feature(FW_FEATURE_VIO
))
4353 printk(KERN_INFO IBMVFC_NAME
": IBM Virtual Fibre Channel Driver version: %s %s\n",
4354 IBMVFC_DRIVER_VERSION
, IBMVFC_DRIVER_DATE
);
4356 ibmvfc_transport_template
= fc_attach_transport(&ibmvfc_transport_functions
);
4357 if (!ibmvfc_transport_template
)
4360 rc
= vio_register_driver(&ibmvfc_driver
);
4362 fc_release_transport(ibmvfc_transport_template
);
4367 * ibmvfc_module_exit - Teardown the ibmvfc module
4372 static void __exit
ibmvfc_module_exit(void)
4374 vio_unregister_driver(&ibmvfc_driver
);
4375 fc_release_transport(ibmvfc_transport_template
);
4378 module_init(ibmvfc_module_init
);
4379 module_exit(ibmvfc_module_exit
);