2 * ibmvfc.h -- 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
27 #include <linux/list.h>
28 #include <linux/types.h>
31 #define IBMVFC_NAME "ibmvfc"
32 #define IBMVFC_DRIVER_VERSION "1.0.1"
33 #define IBMVFC_DRIVER_DATE "(July 11, 2008)"
35 #define IBMVFC_DEFAULT_TIMEOUT 15
36 #define IBMVFC_INIT_TIMEOUT 30
37 #define IBMVFC_MAX_REQUESTS_DEFAULT 100
39 #define IBMVFC_DEBUG 0
40 #define IBMVFC_MAX_TARGETS 1024
41 #define IBMVFC_MAX_LUN 0xffffffff
42 #define IBMVFC_MAX_SECTORS 0xffffu
43 #define IBMVFC_MAX_DISC_THREADS 4
44 #define IBMVFC_TGT_MEMPOOL_SZ 64
45 #define IBMVFC_MAX_CMDS_PER_LUN 64
46 #define IBMVFC_MAX_INIT_RETRIES 3
47 #define IBMVFC_DEV_LOSS_TMO (5 * 60)
48 #define IBMVFC_DEFAULT_LOG_LEVEL 2
49 #define IBMVFC_MAX_CDB_LEN 16
52 * Ensure we have resources for ERP and initialization:
54 * 1 for initialization
55 * 1 for each discovery thread
57 #define IBMVFC_NUM_INTERNAL_REQ (1 + 1 + disc_threads)
59 #define IBMVFC_MAD_SUCCESS 0x00
60 #define IBMVFC_MAD_NOT_SUPPORTED 0xF1
61 #define IBMVFC_MAD_FAILED 0xF7
62 #define IBMVFC_MAD_DRIVER_FAILED 0xEE
63 #define IBMVFC_MAD_CRQ_ERROR 0xEF
65 enum ibmvfc_crq_valid {
66 IBMVFC_CRQ_CMD_RSP = 0x80,
67 IBMVFC_CRQ_INIT_RSP = 0xC0,
68 IBMVFC_CRQ_XPORT_EVENT = 0xFF,
71 enum ibmvfc_crq_format {
72 IBMVFC_CRQ_INIT = 0x01,
73 IBMVFC_CRQ_INIT_COMPLETE = 0x02,
74 IBMVFC_PARTITION_MIGRATED = 0x06,
77 enum ibmvfc_cmd_status_flags {
78 IBMVFC_FABRIC_MAPPED = 0x0001,
79 IBMVFC_VIOS_FAILURE = 0x0002,
80 IBMVFC_FC_FAILURE = 0x0004,
81 IBMVFC_FC_SCSI_ERROR = 0x0008,
82 IBMVFC_HW_EVENT_LOGGED = 0x0010,
83 IBMVFC_VIOS_LOGGED = 0x0020,
86 enum ibmvfc_fabric_mapped_errors {
87 IBMVFC_UNABLE_TO_ESTABLISH = 0x0001,
88 IBMVFC_XPORT_FAULT = 0x0002,
89 IBMVFC_CMD_TIMEOUT = 0x0003,
90 IBMVFC_ENETDOWN = 0x0004,
91 IBMVFC_HW_FAILURE = 0x0005,
92 IBMVFC_LINK_DOWN_ERR = 0x0006,
93 IBMVFC_LINK_DEAD_ERR = 0x0007,
94 IBMVFC_UNABLE_TO_REGISTER = 0x0008,
95 IBMVFC_XPORT_BUSY = 0x000A,
96 IBMVFC_XPORT_DEAD = 0x000B,
97 IBMVFC_CONFIG_ERROR = 0x000C,
98 IBMVFC_NAME_SERVER_FAIL = 0x000D,
99 IBMVFC_LINK_HALTED = 0x000E,
100 IBMVFC_XPORT_GENERAL = 0x8000,
103 enum ibmvfc_vios_errors {
104 IBMVFC_CRQ_FAILURE = 0x0001,
105 IBMVFC_SW_FAILURE = 0x0002,
106 IBMVFC_INVALID_PARAMETER = 0x0003,
107 IBMVFC_MISSING_PARAMETER = 0x0004,
108 IBMVFC_HOST_IO_BUS = 0x0005,
109 IBMVFC_TRANS_CANCELLED = 0x0006,
110 IBMVFC_TRANS_CANCELLED_IMPLICIT = 0x0007,
111 IBMVFC_INSUFFICIENT_RESOURCE = 0x0008,
112 IBMVFC_COMMAND_FAILED = 0x8000,
115 enum ibmvfc_mad_types {
116 IBMVFC_NPIV_LOGIN = 0x0001,
117 IBMVFC_DISC_TARGETS = 0x0002,
118 IBMVFC_PORT_LOGIN = 0x0004,
119 IBMVFC_PROCESS_LOGIN = 0x0008,
120 IBMVFC_QUERY_TARGET = 0x0010,
121 IBMVFC_IMPLICIT_LOGOUT = 0x0040,
122 IBMVFC_PASSTHRU = 0x0200,
123 IBMVFC_TMF_MAD = 0x0100,
126 struct ibmvfc_mad_common {
133 }__attribute__((packed, aligned (8)));
135 struct ibmvfc_npiv_login_mad {
136 struct ibmvfc_mad_common common;
137 struct srp_direct_buf buffer;
138 }__attribute__((packed, aligned (8)));
140 #define IBMVFC_MAX_NAME 256
142 struct ibmvfc_npiv_login {
144 #define IBMVFC_OS_LINUX 0x02
150 u32 vfc_frame_version;
153 #define IBMVFC_CLIENT_MIGRATED 0x01
154 #define IBMVFC_FLUSH_ON_HALT 0x02
157 #define IBMVFC_CAN_MIGRATE 0x01
159 struct srp_direct_buf async;
160 u8 partition_name[IBMVFC_MAX_NAME];
161 u8 device_name[IBMVFC_MAX_NAME];
162 u8 drc_name[IBMVFC_MAX_NAME];
164 }__attribute__((packed, aligned (8)));
166 struct ibmvfc_common_svc_parms {
170 u16 bb_rcv_sz; /* upper nibble is BB_SC_N */
173 }__attribute__((packed, aligned (4)));
175 struct ibmvfc_service_parms {
176 struct ibmvfc_common_svc_parms common;
183 u32 vendor_version[4];
184 u32 services_avail[2];
188 }__attribute__((packed, aligned (4)));
190 struct ibmvfc_npiv_login_resp {
195 #define IBMVFC_NATIVE_FC 0x01
196 #define IBMVFC_CAN_FLUSH_ON_HALT 0x08
206 u8 partition_name[IBMVFC_MAX_NAME];
207 u8 device_name[IBMVFC_MAX_NAME];
208 u8 port_loc_code[IBMVFC_MAX_NAME];
209 u8 drc_name[IBMVFC_MAX_NAME];
210 struct ibmvfc_service_parms service_parms;
212 }__attribute__((packed, aligned (8)));
214 union ibmvfc_npiv_login_data {
215 struct ibmvfc_npiv_login login;
216 struct ibmvfc_npiv_login_resp resp;
217 }__attribute__((packed, aligned (8)));
219 struct ibmvfc_discover_targets_buf {
221 #define IBMVFC_DISC_TGT_SCSI_ID_MASK 0x00ffffff
224 struct ibmvfc_discover_targets {
225 struct ibmvfc_mad_common common;
226 struct srp_direct_buf buffer;
234 }__attribute__((packed, aligned (8)));
236 enum ibmvfc_fc_reason {
237 IBMVFC_INVALID_ELS_CMD_CODE = 0x01,
238 IBMVFC_INVALID_VERSION = 0x02,
239 IBMVFC_LOGICAL_ERROR = 0x03,
240 IBMVFC_INVALID_CT_IU_SIZE = 0x04,
241 IBMVFC_LOGICAL_BUSY = 0x05,
242 IBMVFC_PROTOCOL_ERROR = 0x07,
243 IBMVFC_UNABLE_TO_PERFORM_REQ = 0x09,
244 IBMVFC_CMD_NOT_SUPPORTED = 0x0B,
245 IBMVFC_SERVER_NOT_AVAIL = 0x0D,
246 IBMVFC_CMD_IN_PROGRESS = 0x0E,
247 IBMVFC_VENDOR_SPECIFIC = 0xFF,
250 enum ibmvfc_fc_type {
251 IBMVFC_FABRIC_REJECT = 0x01,
252 IBMVFC_PORT_REJECT = 0x02,
253 IBMVFC_LS_REJECT = 0x03,
254 IBMVFC_FABRIC_BUSY = 0x04,
255 IBMVFC_PORT_BUSY = 0x05,
256 IBMVFC_BASIC_REJECT = 0x06,
259 enum ibmvfc_gs_explain {
260 IBMVFC_PORT_NAME_NOT_REG = 0x02,
263 struct ibmvfc_port_login {
264 struct ibmvfc_mad_common common;
267 u16 fc_service_class;
271 u16 error; /* also fc_reason */
275 struct ibmvfc_service_parms service_parms;
276 struct ibmvfc_service_parms service_parms_change;
278 }__attribute__((packed, aligned (8)));
280 struct ibmvfc_prli_svc_parms {
282 #define IBMVFC_SCSI_FCP_TYPE 0x08
285 #define IBMVFC_PRLI_ORIG_PA_VALID 0x8000
286 #define IBMVFC_PRLI_RESP_PA_VALID 0x4000
287 #define IBMVFC_PRLI_EST_IMG_PAIR 0x2000
291 #define IBMVFC_PRLI_TASK_RETRY 0x00000200
292 #define IBMVFC_PRLI_RETRY 0x00000100
293 #define IBMVFC_PRLI_DATA_OVERLAY 0x00000040
294 #define IBMVFC_PRLI_INITIATOR_FUNC 0x00000020
295 #define IBMVFC_PRLI_TARGET_FUNC 0x00000010
296 #define IBMVFC_PRLI_READ_FCP_XFER_RDY_DISABLED 0x00000002
297 #define IBMVFC_PRLI_WR_FCP_XFER_RDY_DISABLED 0x00000001
298 }__attribute__((packed, aligned (4)));
300 struct ibmvfc_process_login {
301 struct ibmvfc_mad_common common;
303 struct ibmvfc_prli_svc_parms parms;
306 u16 error; /* also fc_reason */
309 }__attribute__((packed, aligned (8)));
311 struct ibmvfc_query_tgt {
312 struct ibmvfc_mad_common common;
320 }__attribute__((packed, aligned (8)));
322 struct ibmvfc_implicit_logout {
323 struct ibmvfc_mad_common common;
326 }__attribute__((packed, aligned (8)));
329 struct ibmvfc_mad_common common;
333 #define IBMVFC_TMF_ABORT_TASK 0x02
334 #define IBMVFC_TMF_ABORT_TASK_SET 0x04
335 #define IBMVFC_TMF_LUN_RESET 0x10
336 #define IBMVFC_TMF_TGT_RESET 0x20
337 #define IBMVFC_TMF_LUA_VALID 0x40
340 #define IBMVFC_TMF_CANCEL_KEY 0x80000000
343 }__attribute__((packed, aligned (8)));
345 enum ibmvfc_fcp_rsp_info_codes {
346 RSP_NO_FAILURE = 0x00,
347 RSP_TMF_REJECTED = 0x04,
348 RSP_TMF_FAILED = 0x05,
349 RSP_TMF_INVALID_LUN = 0x09,
352 struct ibmvfc_fcp_rsp_info {
356 }__attribute__((packed, aligned (2)));
358 enum ibmvfc_fcp_rsp_flags {
360 FCP_BIDI_READ_RESID_UNDER = 0x40,
361 FCP_BIDI_READ_RESID_OVER = 0x20,
363 FCP_RESID_UNDER = 0x08,
364 FCP_RESID_OVER = 0x04,
365 FCP_SNS_LEN_VALID = 0x02,
366 FCP_RSP_LEN_VALID = 0x01,
369 union ibmvfc_fcp_rsp_data {
370 struct ibmvfc_fcp_rsp_info info;
371 u8 sense[SCSI_SENSE_BUFFERSIZE + sizeof(struct ibmvfc_fcp_rsp_info)];
372 }__attribute__((packed, aligned (8)));
374 struct ibmvfc_fcp_rsp {
376 u16 retry_delay_timer;
382 union ibmvfc_fcp_rsp_data data;
383 }__attribute__((packed, aligned (8)));
385 enum ibmvfc_cmd_flags {
386 IBMVFC_SCATTERLIST = 0x0001,
387 IBMVFC_NO_MEM_DESC = 0x0002,
388 IBMVFC_READ = 0x0004,
389 IBMVFC_WRITE = 0x0008,
391 IBMVFC_CLASS_3_ERR = 0x0100,
394 enum ibmvfc_fc_task_attr {
395 IBMVFC_SIMPLE_TASK = 0x00,
396 IBMVFC_HEAD_OF_QUEUE = 0x01,
397 IBMVFC_ORDERED_TASK = 0x02,
398 IBMVFC_ACA_TASK = 0x04,
401 enum ibmvfc_fc_tmf_flags {
402 IBMVFC_ABORT_TASK_SET = 0x02,
403 IBMVFC_LUN_RESET = 0x10,
404 IBMVFC_TARGET_RESET = 0x20,
407 struct ibmvfc_fcp_cmd_iu {
413 #define IBMVFC_RDDATA 0x02
414 #define IBMVFC_WRDATA 0x01
415 u8 cdb[IBMVFC_MAX_CDB_LEN];
417 }__attribute__((packed, aligned (4)));
429 #define IBMVFC_ADAPTER_RESID_VALID 0x01
432 struct srp_direct_buf ext_func;
433 struct srp_direct_buf ioba;
434 struct srp_direct_buf resp;
439 struct ibmvfc_fcp_cmd_iu iu;
440 struct ibmvfc_fcp_rsp rsp;
441 }__attribute__((packed, aligned (8)));
443 struct ibmvfc_passthru_fc_iu {
445 #define IBMVFC_ADISC 0x52000000
449 struct ibmvfc_passthru_iu {
456 #define IBMVFC_FC_ELS 0x01
459 struct srp_direct_buf cmd;
460 struct srp_direct_buf rsp;
465 }__attribute__((packed, aligned (8)));
467 struct ibmvfc_passthru_mad {
468 struct ibmvfc_mad_common common;
469 struct srp_direct_buf cmd_ioba;
470 struct ibmvfc_passthru_iu iu;
471 struct ibmvfc_passthru_fc_iu fc_iu;
472 }__attribute__((packed, aligned (8)));
474 struct ibmvfc_trace_start_entry {
476 }__attribute__((packed));
478 struct ibmvfc_trace_end_entry {
485 }__attribute__((packed));
487 struct ibmvfc_trace_entry {
488 struct ibmvfc_event *evt;
496 #define IBMVFC_TRC_START 0x00
497 #define IBMVFC_TRC_END 0xff
499 struct ibmvfc_trace_start_entry start;
500 struct ibmvfc_trace_end_entry end;
502 }__attribute__((packed, aligned (8)));
504 enum ibmvfc_crq_formats {
505 IBMVFC_CMD_FORMAT = 0x01,
506 IBMVFC_ASYNC_EVENT = 0x02,
507 IBMVFC_MAD_FORMAT = 0x04,
510 enum ibmvfc_async_event {
511 IBMVFC_AE_ELS_PLOGI = 0x0001,
512 IBMVFC_AE_ELS_LOGO = 0x0002,
513 IBMVFC_AE_ELS_PRLO = 0x0004,
514 IBMVFC_AE_SCN_NPORT = 0x0008,
515 IBMVFC_AE_SCN_GROUP = 0x0010,
516 IBMVFC_AE_SCN_DOMAIN = 0x0020,
517 IBMVFC_AE_SCN_FABRIC = 0x0040,
518 IBMVFC_AE_LINK_UP = 0x0080,
519 IBMVFC_AE_LINK_DOWN = 0x0100,
520 IBMVFC_AE_LINK_DEAD = 0x0200,
521 IBMVFC_AE_HALT = 0x0400,
522 IBMVFC_AE_RESUME = 0x0800,
523 IBMVFC_AE_ADAPTER_FAILED = 0x1000,
531 }__attribute__((packed, aligned (8)));
533 struct ibmvfc_crq_queue {
534 struct ibmvfc_crq *msgs;
536 dma_addr_t msg_token;
539 struct ibmvfc_async_crq {
548 }__attribute__((packed, aligned (8)));
550 struct ibmvfc_async_crq_queue {
551 struct ibmvfc_async_crq *msgs;
553 dma_addr_t msg_token;
557 struct ibmvfc_mad_common mad_common;
558 struct ibmvfc_npiv_login_mad npiv_login;
559 struct ibmvfc_discover_targets discover_targets;
560 struct ibmvfc_port_login plogi;
561 struct ibmvfc_process_login prli;
562 struct ibmvfc_query_tgt query_tgt;
563 struct ibmvfc_implicit_logout implicit_logout;
564 struct ibmvfc_tmf tmf;
565 struct ibmvfc_cmd cmd;
566 struct ibmvfc_passthru_mad passthru;
567 }__attribute__((packed, aligned (8)));
569 enum ibmvfc_target_action {
570 IBMVFC_TGT_ACTION_NONE = 0,
571 IBMVFC_TGT_ACTION_INIT,
572 IBMVFC_TGT_ACTION_INIT_WAIT,
573 IBMVFC_TGT_ACTION_ADD_RPORT,
574 IBMVFC_TGT_ACTION_DEL_RPORT,
577 struct ibmvfc_target {
578 struct list_head queue;
579 struct ibmvfc_host *vhost;
582 struct fc_rport *rport;
584 enum ibmvfc_target_action action;
587 struct ibmvfc_service_parms service_parms;
588 struct ibmvfc_service_parms service_parms_change;
589 struct fc_rport_identifiers ids;
590 void (*job_step) (struct ibmvfc_target *);
594 /* a unit of work for the hosting partition */
595 struct ibmvfc_event {
596 struct list_head queue;
597 struct ibmvfc_host *vhost;
598 struct ibmvfc_target *tgt;
599 struct scsi_cmnd *cmnd;
601 union ibmvfc_iu *xfer_iu;
602 void (*done) (struct ibmvfc_event *);
603 struct ibmvfc_crq crq;
605 union ibmvfc_iu *sync_iu;
606 struct srp_direct_buf *ext_list;
607 dma_addr_t ext_list_token;
608 struct completion comp;
609 struct timer_list timer;
612 /* a pool of event structs for use */
613 struct ibmvfc_event_pool {
614 struct ibmvfc_event *events;
616 union ibmvfc_iu *iu_storage;
620 enum ibmvfc_host_action {
621 IBMVFC_HOST_ACTION_NONE = 0,
622 IBMVFC_HOST_ACTION_INIT,
623 IBMVFC_HOST_ACTION_INIT_WAIT,
624 IBMVFC_HOST_ACTION_QUERY,
625 IBMVFC_HOST_ACTION_QUERY_TGTS,
626 IBMVFC_HOST_ACTION_TGT_DEL,
627 IBMVFC_HOST_ACTION_ALLOC_TGTS,
628 IBMVFC_HOST_ACTION_TGT_INIT,
629 IBMVFC_HOST_ACTION_TGT_ADD,
632 enum ibmvfc_host_state {
644 struct list_head queue;
645 struct Scsi_Host *host;
646 enum ibmvfc_host_state state;
647 enum ibmvfc_host_action action;
648 #define IBMVFC_NUM_TRACE_INDEX_BITS 8
649 #define IBMVFC_NUM_TRACE_ENTRIES (1 << IBMVFC_NUM_TRACE_INDEX_BITS)
650 #define IBMVFC_TRACE_SIZE (sizeof(struct ibmvfc_trace_entry) * IBMVFC_NUM_TRACE_ENTRIES)
651 struct ibmvfc_trace_entry *trace;
652 u32 trace_index:IBMVFC_NUM_TRACE_INDEX_BITS;
654 struct list_head targets;
655 struct list_head sent;
656 struct list_head free;
658 struct ibmvfc_event_pool pool;
659 struct dma_pool *sg_pool;
661 struct ibmvfc_crq_queue crq;
662 struct ibmvfc_async_crq_queue async_crq;
663 struct ibmvfc_npiv_login login_info;
664 union ibmvfc_npiv_login_data *login_buf;
665 dma_addr_t login_buf_dma;
668 struct ibmvfc_discover_targets_buf *disc_buf;
671 int discovery_threads;
675 #define IBMVFC_AE_LINKUP 0x0001
676 #define IBMVFC_AE_LINKDOWN 0x0002
677 #define IBMVFC_AE_RSCN 0x0004
678 dma_addr_t disc_buf_dma;
679 unsigned int partition_number;
680 char partition_name[97];
681 void (*job_step) (struct ibmvfc_host *);
682 struct task_struct *work_thread;
683 wait_queue_head_t init_wait_q;
684 wait_queue_head_t work_wait_q;
687 #define DBG_CMD(CMD) do { if (ibmvfc_debug) CMD; } while (0)
689 #define tgt_dbg(t, fmt, ...) \
690 DBG_CMD(dev_info((t)->vhost->dev, "%lX: " fmt, (t)->scsi_id, ##__VA_ARGS__))
692 #define tgt_info(t, fmt, ...) \
693 dev_info((t)->vhost->dev, "%lX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
695 #define tgt_err(t, fmt, ...) \
696 dev_err((t)->vhost->dev, "%lX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
698 #define ibmvfc_dbg(vhost, ...) \
699 DBG_CMD(dev_info((vhost)->dev, ##__VA_ARGS__))
701 #define ibmvfc_log(vhost, level, ...) \
703 if (level >= (vhost)->log_level) \
704 dev_err((vhost)->dev, ##__VA_ARGS__); \
707 #define ENTER DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Entering %s\n", __func__))
708 #define LEAVE DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Leaving %s\n", __func__))
710 #ifdef CONFIG_SCSI_IBMVFC_TRACE
711 #define ibmvfc_create_trace_file(kobj, attr) sysfs_create_bin_file(kobj, attr)
712 #define ibmvfc_remove_trace_file(kobj, attr) sysfs_remove_bin_file(kobj, attr)
714 #define ibmvfc_create_trace_file(kobj, attr) 0
715 #define ibmvfc_remove_trace_file(kobj, attr) do { } while (0)