Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * ibmvfc.h -- driver for IBM Power Virtual Fibre Channel Adapter
0004  *
0005  * Written By: Brian King <brking@linux.vnet.ibm.com>, IBM Corporation
0006  *
0007  * Copyright (C) IBM Corporation, 2008
0008  */
0009 
0010 #ifndef _IBMVFC_H
0011 #define _IBMVFC_H
0012 
0013 #include <linux/list.h>
0014 #include <linux/types.h>
0015 #include <scsi/viosrp.h>
0016 
0017 #define IBMVFC_NAME "ibmvfc"
0018 #define IBMVFC_DRIVER_VERSION       "1.0.11"
0019 #define IBMVFC_DRIVER_DATE      "(April 12, 2013)"
0020 
0021 #define IBMVFC_DEFAULT_TIMEOUT  60
0022 #define IBMVFC_ADISC_CANCEL_TIMEOUT 45
0023 #define IBMVFC_ADISC_TIMEOUT        15
0024 #define IBMVFC_ADISC_PLUS_CANCEL_TIMEOUT    \
0025         (IBMVFC_ADISC_TIMEOUT + IBMVFC_ADISC_CANCEL_TIMEOUT)
0026 #define IBMVFC_INIT_TIMEOUT     120
0027 #define IBMVFC_ABORT_TIMEOUT        8
0028 #define IBMVFC_ABORT_WAIT_TIMEOUT   40
0029 #define IBMVFC_MAX_REQUESTS_DEFAULT 100
0030 
0031 #define IBMVFC_DEBUG            0
0032 #define IBMVFC_MAX_TARGETS      1024
0033 #define IBMVFC_MAX_LUN          0xffffffff
0034 #define IBMVFC_MAX_SECTORS      0xffffu
0035 #define IBMVFC_MAX_DISC_THREADS 4
0036 #define IBMVFC_TGT_MEMPOOL_SZ       64
0037 #define IBMVFC_MAX_CMDS_PER_LUN 64
0038 #define IBMVFC_MAX_HOST_INIT_RETRIES    6
0039 #define IBMVFC_MAX_TGT_INIT_RETRIES     3
0040 #define IBMVFC_DEV_LOSS_TMO     (5 * 60)
0041 #define IBMVFC_DEFAULT_LOG_LEVEL    2
0042 #define IBMVFC_MAX_CDB_LEN      16
0043 #define IBMVFC_CLS3_ERROR       0
0044 #define IBMVFC_MQ           1
0045 #define IBMVFC_SCSI_CHANNELS        8
0046 #define IBMVFC_MAX_SCSI_QUEUES      16
0047 #define IBMVFC_SCSI_HW_QUEUES       8
0048 #define IBMVFC_MIG_NO_SUB_TO_CRQ    0
0049 #define IBMVFC_MIG_NO_N_TO_M        0
0050 
0051 /*
0052  * Ensure we have resources for ERP and initialization:
0053  * 1 for ERP
0054  * 1 for initialization
0055  * 1 for NPIV Logout
0056  * 2 for BSG passthru
0057  * 2 for each discovery thread
0058  */
0059 #define IBMVFC_NUM_INTERNAL_REQ (1 + 1 + 1 + 2 + (disc_threads * 2))
0060 
0061 #define IBMVFC_MAD_SUCCESS      0x00
0062 #define IBMVFC_MAD_NOT_SUPPORTED    0xF1
0063 #define IBMVFC_MAD_VERSION_NOT_SUPP 0xF2
0064 #define IBMVFC_MAD_FAILED       0xF7
0065 #define IBMVFC_MAD_DRIVER_FAILED    0xEE
0066 #define IBMVFC_MAD_CRQ_ERROR        0xEF
0067 
0068 enum ibmvfc_crq_valid {
0069     IBMVFC_CRQ_CMD_RSP      = 0x80,
0070     IBMVFC_CRQ_INIT_RSP     = 0xC0,
0071     IBMVFC_CRQ_XPORT_EVENT      = 0xFF,
0072 };
0073 
0074 enum ibmvfc_crq_init_msg {
0075     IBMVFC_CRQ_INIT         = 0x01,
0076     IBMVFC_CRQ_INIT_COMPLETE    = 0x02,
0077 };
0078 
0079 enum ibmvfc_crq_xport_evts {
0080     IBMVFC_PARTNER_FAILED       = 0x01,
0081     IBMVFC_PARTNER_DEREGISTER   = 0x02,
0082     IBMVFC_PARTITION_MIGRATED   = 0x06,
0083 };
0084 
0085 enum ibmvfc_cmd_status_flags {
0086     IBMVFC_FABRIC_MAPPED        = 0x0001,
0087     IBMVFC_VIOS_FAILURE     = 0x0002,
0088     IBMVFC_FC_FAILURE           = 0x0004,
0089     IBMVFC_FC_SCSI_ERROR        = 0x0008,
0090     IBMVFC_HW_EVENT_LOGGED      = 0x0010,
0091     IBMVFC_VIOS_LOGGED      = 0x0020,
0092 };
0093 
0094 enum ibmvfc_fabric_mapped_errors {
0095     IBMVFC_UNABLE_TO_ESTABLISH  = 0x0001,
0096     IBMVFC_XPORT_FAULT      = 0x0002,
0097     IBMVFC_CMD_TIMEOUT      = 0x0003,
0098     IBMVFC_ENETDOWN         = 0x0004,
0099     IBMVFC_HW_FAILURE           = 0x0005,
0100     IBMVFC_LINK_DOWN_ERR        = 0x0006,
0101     IBMVFC_LINK_DEAD_ERR        = 0x0007,
0102     IBMVFC_UNABLE_TO_REGISTER   = 0x0008,
0103     IBMVFC_XPORT_BUSY           = 0x000A,
0104     IBMVFC_XPORT_DEAD           = 0x000B,
0105     IBMVFC_CONFIG_ERROR     = 0x000C,
0106     IBMVFC_NAME_SERVER_FAIL     = 0x000D,
0107     IBMVFC_LINK_HALTED      = 0x000E,
0108     IBMVFC_XPORT_GENERAL        = 0x8000,
0109 };
0110 
0111 enum ibmvfc_vios_errors {
0112     IBMVFC_CRQ_FAILURE          = 0x0001,
0113     IBMVFC_SW_FAILURE               = 0x0002,
0114     IBMVFC_INVALID_PARAMETER        = 0x0003,
0115     IBMVFC_MISSING_PARAMETER        = 0x0004,
0116     IBMVFC_HOST_IO_BUS          = 0x0005,
0117     IBMVFC_TRANS_CANCELLED          = 0x0006,
0118     IBMVFC_TRANS_CANCELLED_IMPLICIT = 0x0007,
0119     IBMVFC_INSUFFICIENT_RESOURCE        = 0x0008,
0120     IBMVFC_PLOGI_REQUIRED           = 0x0010,
0121     IBMVFC_COMMAND_FAILED           = 0x8000,
0122 };
0123 
0124 enum ibmvfc_mad_types {
0125     IBMVFC_NPIV_LOGIN       = 0x0001,
0126     IBMVFC_DISC_TARGETS = 0x0002,
0127     IBMVFC_PORT_LOGIN       = 0x0004,
0128     IBMVFC_PROCESS_LOGIN    = 0x0008,
0129     IBMVFC_QUERY_TARGET = 0x0010,
0130     IBMVFC_MOVE_LOGIN       = 0x0020,
0131     IBMVFC_IMPLICIT_LOGOUT  = 0x0040,
0132     IBMVFC_PASSTHRU     = 0x0200,
0133     IBMVFC_TMF_MAD      = 0x0100,
0134     IBMVFC_NPIV_LOGOUT  = 0x0800,
0135     IBMVFC_CHANNEL_ENQUIRY  = 0x1000,
0136     IBMVFC_CHANNEL_SETUP    = 0x2000,
0137     IBMVFC_CONNECTION_INFO  = 0x4000,
0138 };
0139 
0140 struct ibmvfc_mad_common {
0141     __be32 version;
0142     __be32 reserved;
0143     __be32 opcode;
0144     __be16 status;
0145     __be16 length;
0146     __be64 tag;
0147 } __packed __aligned(8);
0148 
0149 struct ibmvfc_npiv_login_mad {
0150     struct ibmvfc_mad_common common;
0151     struct srp_direct_buf buffer;
0152 } __packed __aligned(8);
0153 
0154 struct ibmvfc_npiv_logout_mad {
0155     struct ibmvfc_mad_common common;
0156 } __packed __aligned(8);
0157 
0158 #define IBMVFC_MAX_NAME 256
0159 
0160 struct ibmvfc_npiv_login {
0161     __be32 ostype;
0162 #define IBMVFC_OS_LINUX 0x02
0163     __be32 pad;
0164     __be64 max_dma_len;
0165     __be32 max_payload;
0166     __be32 max_response;
0167     __be32 partition_num;
0168     __be32 vfc_frame_version;
0169     __be16 fcp_version;
0170     __be16 flags;
0171 #define IBMVFC_CLIENT_MIGRATED  0x01
0172 #define IBMVFC_FLUSH_ON_HALT        0x02
0173     __be32 max_cmds;
0174     __be64 capabilities;
0175 #define IBMVFC_CAN_MIGRATE      0x01
0176 #define IBMVFC_CAN_USE_CHANNELS     0x02
0177 #define IBMVFC_CAN_HANDLE_FPIN      0x04
0178 #define IBMVFC_CAN_USE_MAD_VERSION  0x08
0179 #define IBMVFC_CAN_SEND_VF_WWPN     0x10
0180     __be64 node_name;
0181     struct srp_direct_buf async;
0182     u8 partition_name[IBMVFC_MAX_NAME];
0183     u8 device_name[IBMVFC_MAX_NAME];
0184     u8 drc_name[IBMVFC_MAX_NAME];
0185     __be64 reserved2[2];
0186 } __packed __aligned(8);
0187 
0188 struct ibmvfc_common_svc_parms {
0189     __be16 fcph_version;
0190     __be16 b2b_credit;
0191     __be16 features;
0192     __be16 bb_rcv_sz; /* upper nibble is BB_SC_N */
0193     __be32 ratov;
0194     __be32 edtov;
0195 } __packed __aligned(4);
0196 
0197 struct ibmvfc_service_parms {
0198     struct ibmvfc_common_svc_parms common;
0199     u8 port_name[8];
0200     u8 node_name[8];
0201     __be32 class1_parms[4];
0202     __be32 class2_parms[4];
0203     __be32 class3_parms[4];
0204     __be32 obsolete[4];
0205     __be32 vendor_version[4];
0206     __be32 services_avail[2];
0207     __be32 ext_len;
0208     __be32 reserved[30];
0209     __be32 clk_sync_qos[2];
0210     __be32 reserved2;
0211 } __packed __aligned(4);
0212 
0213 struct ibmvfc_npiv_login_resp {
0214     __be32 version;
0215     __be16 status;
0216     __be16 error;
0217     __be32 flags;
0218 #define IBMVFC_NATIVE_FC        0x01
0219     __be32 reserved;
0220     __be64 capabilities;
0221 #define IBMVFC_CAN_FLUSH_ON_HALT    0x08
0222 #define IBMVFC_CAN_SUPPRESS_ABTS    0x10
0223 #define IBMVFC_MAD_VERSION_CAP      0x20
0224 #define IBMVFC_HANDLE_VF_WWPN       0x40
0225 #define IBMVFC_CAN_SUPPORT_CHANNELS 0x80
0226     __be32 max_cmds;
0227     __be32 scsi_id_sz;
0228     __be64 max_dma_len;
0229     __be64 scsi_id;
0230     __be64 port_name;
0231     __be64 node_name;
0232     __be64 link_speed;
0233     u8 partition_name[IBMVFC_MAX_NAME];
0234     u8 device_name[IBMVFC_MAX_NAME];
0235     u8 port_loc_code[IBMVFC_MAX_NAME];
0236     u8 drc_name[IBMVFC_MAX_NAME];
0237     struct ibmvfc_service_parms service_parms;
0238     __be64 reserved2;
0239 } __packed __aligned(8);
0240 
0241 union ibmvfc_npiv_login_data {
0242     struct ibmvfc_npiv_login login;
0243     struct ibmvfc_npiv_login_resp resp;
0244 } __packed __aligned(8);
0245 
0246 struct ibmvfc_discover_targets_entry {
0247     __be32 scsi_id;
0248     __be32 pad;
0249     __be64 wwpn;
0250 #define IBMVFC_DISC_TGT_SCSI_ID_MASK    0x00ffffff
0251 } __packed __aligned(8);
0252 
0253 struct ibmvfc_discover_targets {
0254     struct ibmvfc_mad_common common;
0255     struct srp_direct_buf buffer;
0256     __be32 flags;
0257 #define IBMVFC_DISC_TGT_PORT_ID_WWPN_LIST   0x02
0258     __be16 status;
0259     __be16 error;
0260     __be32 bufflen;
0261     __be32 num_avail;
0262     __be32 num_written;
0263     __be64 reserved[2];
0264 } __packed __aligned(8);
0265 
0266 enum ibmvfc_fc_reason {
0267     IBMVFC_INVALID_ELS_CMD_CODE = 0x01,
0268     IBMVFC_INVALID_VERSION      = 0x02,
0269     IBMVFC_LOGICAL_ERROR        = 0x03,
0270     IBMVFC_INVALID_CT_IU_SIZE   = 0x04,
0271     IBMVFC_LOGICAL_BUSY     = 0x05,
0272     IBMVFC_PROTOCOL_ERROR       = 0x07,
0273     IBMVFC_UNABLE_TO_PERFORM_REQ    = 0x09,
0274     IBMVFC_CMD_NOT_SUPPORTED    = 0x0B,
0275     IBMVFC_SERVER_NOT_AVAIL     = 0x0D,
0276     IBMVFC_CMD_IN_PROGRESS      = 0x0E,
0277     IBMVFC_VENDOR_SPECIFIC      = 0xFF,
0278 };
0279 
0280 enum ibmvfc_fc_type {
0281     IBMVFC_FABRIC_REJECT    = 0x01,
0282     IBMVFC_PORT_REJECT  = 0x02,
0283     IBMVFC_LS_REJECT        = 0x03,
0284     IBMVFC_FABRIC_BUSY  = 0x04,
0285     IBMVFC_PORT_BUSY        = 0x05,
0286     IBMVFC_BASIC_REJECT = 0x06,
0287 };
0288 
0289 enum ibmvfc_gs_explain {
0290     IBMVFC_PORT_NAME_NOT_REG    = 0x02,
0291 };
0292 
0293 struct ibmvfc_port_login {
0294     struct ibmvfc_mad_common common;
0295     __be64 scsi_id;
0296     __be16 reserved;
0297     __be16 fc_service_class;
0298     __be32 blksz;
0299     __be32 hdr_per_blk;
0300     __be16 status;
0301     __be16 error;       /* also fc_reason */
0302     __be16 fc_explain;
0303     __be16 fc_type;
0304     __be32 reserved2;
0305     struct ibmvfc_service_parms service_parms;
0306     struct ibmvfc_service_parms service_parms_change;
0307     __be64 target_wwpn;
0308     __be64 reserved3[2];
0309 } __packed __aligned(8);
0310 
0311 struct ibmvfc_move_login {
0312     struct ibmvfc_mad_common common;
0313     __be64 old_scsi_id;
0314     __be64 new_scsi_id;
0315     __be64 wwpn;
0316     __be64 node_name;
0317     __be32 flags;
0318 #define IBMVFC_MOVE_LOGIN_IMPLICIT_OLD_FAILED   0x01
0319 #define IBMVFC_MOVE_LOGIN_IMPLICIT_NEW_FAILED   0x02
0320 #define IBMVFC_MOVE_LOGIN_PORT_LOGIN_FAILED 0x04
0321     __be32 reserved;
0322     struct ibmvfc_service_parms service_parms;
0323     struct ibmvfc_service_parms service_parms_change;
0324     __be32 reserved2;
0325     __be16 service_class;
0326     __be16 vios_flags;
0327 #define IBMVFC_MOVE_LOGIN_VF_NOT_SENT_ADAPTER   0x01
0328     __be64 reserved3;
0329 } __packed __aligned(8);
0330 
0331 struct ibmvfc_prli_svc_parms {
0332     u8 type;
0333 #define IBMVFC_SCSI_FCP_TYPE        0x08
0334     u8 type_ext;
0335     __be16 flags;
0336 #define IBMVFC_PRLI_ORIG_PA_VALID           0x8000
0337 #define IBMVFC_PRLI_RESP_PA_VALID           0x4000
0338 #define IBMVFC_PRLI_EST_IMG_PAIR            0x2000
0339     __be32 orig_pa;
0340     __be32 resp_pa;
0341     __be32 service_parms;
0342 #define IBMVFC_PRLI_TASK_RETRY          0x00000200
0343 #define IBMVFC_PRLI_RETRY               0x00000100
0344 #define IBMVFC_PRLI_DATA_OVERLAY            0x00000040
0345 #define IBMVFC_PRLI_INITIATOR_FUNC          0x00000020
0346 #define IBMVFC_PRLI_TARGET_FUNC         0x00000010
0347 #define IBMVFC_PRLI_READ_FCP_XFER_RDY_DISABLED  0x00000002
0348 #define IBMVFC_PRLI_WR_FCP_XFER_RDY_DISABLED    0x00000001
0349 } __packed __aligned(4);
0350 
0351 struct ibmvfc_process_login {
0352     struct ibmvfc_mad_common common;
0353     __be64 scsi_id;
0354     struct ibmvfc_prli_svc_parms parms;
0355     u8 reserved[48];
0356     __be16 status;
0357     __be16 error;           /* also fc_reason */
0358     __be32 reserved2;
0359     __be64 target_wwpn;
0360     __be64 reserved3[2];
0361 } __packed __aligned(8);
0362 
0363 struct ibmvfc_query_tgt {
0364     struct ibmvfc_mad_common common;
0365     __be64 wwpn;
0366     __be64 scsi_id;
0367     __be16 status;
0368     __be16 error;
0369     __be16 fc_explain;
0370     __be16 fc_type;
0371     __be64 reserved[2];
0372 } __packed __aligned(8);
0373 
0374 struct ibmvfc_implicit_logout {
0375     struct ibmvfc_mad_common common;
0376     __be64 old_scsi_id;
0377     __be64 reserved[2];
0378 } __packed __aligned(8);
0379 
0380 struct ibmvfc_tmf {
0381     struct ibmvfc_mad_common common;
0382     __be64 scsi_id;
0383     struct scsi_lun lun;
0384     __be32 flags;
0385 #define IBMVFC_TMF_ABORT_TASK       0x02
0386 #define IBMVFC_TMF_ABORT_TASK_SET   0x04
0387 #define IBMVFC_TMF_LUN_RESET        0x10
0388 #define IBMVFC_TMF_TGT_RESET        0x20
0389 #define IBMVFC_TMF_LUA_VALID        0x40
0390 #define IBMVFC_TMF_SUPPRESS_ABTS    0x80
0391     __be32 cancel_key;
0392     __be32 my_cancel_key;
0393     __be32 pad;
0394     __be64 target_wwpn;
0395     __be64 task_tag;
0396     __be64 reserved[2];
0397 } __packed __aligned(8);
0398 
0399 enum ibmvfc_fcp_rsp_info_codes {
0400     RSP_NO_FAILURE      = 0x00,
0401     RSP_TMF_REJECTED        = 0x04,
0402     RSP_TMF_FAILED      = 0x05,
0403     RSP_TMF_INVALID_LUN = 0x09,
0404 };
0405 
0406 struct ibmvfc_fcp_rsp_info {
0407     u8 reserved[3];
0408     u8 rsp_code;
0409     u8 reserved2[4];
0410 } __packed __aligned(2);
0411 
0412 enum ibmvfc_fcp_rsp_flags {
0413     FCP_BIDI_RSP            = 0x80,
0414     FCP_BIDI_READ_RESID_UNDER   = 0x40,
0415     FCP_BIDI_READ_RESID_OVER    = 0x20,
0416     FCP_CONF_REQ            = 0x10,
0417     FCP_RESID_UNDER         = 0x08,
0418     FCP_RESID_OVER          = 0x04,
0419     FCP_SNS_LEN_VALID           = 0x02,
0420     FCP_RSP_LEN_VALID           = 0x01,
0421 };
0422 
0423 union ibmvfc_fcp_rsp_data {
0424     struct ibmvfc_fcp_rsp_info info;
0425     u8 sense[SCSI_SENSE_BUFFERSIZE + sizeof(struct ibmvfc_fcp_rsp_info)];
0426 } __packed __aligned(8);
0427 
0428 struct ibmvfc_fcp_rsp {
0429     __be64 reserved;
0430     __be16 retry_delay_timer;
0431     u8 flags;
0432     u8 scsi_status;
0433     __be32 fcp_resid;
0434     __be32 fcp_sense_len;
0435     __be32 fcp_rsp_len;
0436     union ibmvfc_fcp_rsp_data data;
0437 } __packed __aligned(8);
0438 
0439 enum ibmvfc_cmd_flags {
0440     IBMVFC_SCATTERLIST  = 0x0001,
0441     IBMVFC_NO_MEM_DESC  = 0x0002,
0442     IBMVFC_READ         = 0x0004,
0443     IBMVFC_WRITE        = 0x0008,
0444     IBMVFC_TMF          = 0x0080,
0445     IBMVFC_CLASS_3_ERR  = 0x0100,
0446 };
0447 
0448 enum ibmvfc_fc_task_attr {
0449     IBMVFC_SIMPLE_TASK  = 0x00,
0450     IBMVFC_HEAD_OF_QUEUE    = 0x01,
0451     IBMVFC_ORDERED_TASK = 0x02,
0452     IBMVFC_ACA_TASK     = 0x04,
0453 };
0454 
0455 enum ibmvfc_fc_tmf_flags {
0456     IBMVFC_ABORT_TASK_SET   = 0x02,
0457     IBMVFC_LUN_RESET        = 0x10,
0458     IBMVFC_TARGET_RESET = 0x20,
0459 };
0460 
0461 struct ibmvfc_fcp_cmd_iu {
0462     struct scsi_lun lun;
0463     u8 crn;
0464     u8 pri_task_attr;
0465     u8 tmf_flags;
0466     u8 add_cdb_len;
0467 #define IBMVFC_RDDATA       0x02
0468 #define IBMVFC_WRDATA       0x01
0469     u8 cdb[IBMVFC_MAX_CDB_LEN];
0470     __be32 xfer_len;
0471 } __packed __aligned(4);
0472 
0473 struct ibmvfc_cmd {
0474     __be64 task_tag;
0475     __be32 frame_type;
0476     __be32 payload_len;
0477     __be32 resp_len;
0478     __be32 adapter_resid;
0479     __be16 status;
0480     __be16 error;
0481     __be16 flags;
0482     __be16 response_flags;
0483 #define IBMVFC_ADAPTER_RESID_VALID  0x01
0484     __be32 cancel_key;
0485     __be32 exchange_id;
0486     struct srp_direct_buf ext_func;
0487     struct srp_direct_buf ioba;
0488     struct srp_direct_buf resp;
0489     __be64 correlation;
0490     __be64 tgt_scsi_id;
0491     __be64 tag;
0492     __be64 target_wwpn;
0493     __be64 reserved3;
0494     union {
0495         struct {
0496             struct ibmvfc_fcp_cmd_iu iu;
0497             struct ibmvfc_fcp_rsp rsp;
0498         } v1;
0499         struct {
0500             __be64 reserved4;
0501             struct ibmvfc_fcp_cmd_iu iu;
0502             struct ibmvfc_fcp_rsp rsp;
0503         } v2;
0504     };
0505 } __packed __aligned(8);
0506 
0507 struct ibmvfc_passthru_fc_iu {
0508     __be32 payload[7];
0509 #define IBMVFC_ADISC    0x52000000
0510     __be32 response[7];
0511 };
0512 
0513 struct ibmvfc_passthru_iu {
0514     __be64 task_tag;
0515     __be32 cmd_len;
0516     __be32 rsp_len;
0517     __be16 status;
0518     __be16 error;
0519     __be32 flags;
0520 #define IBMVFC_FC_ELS       0x01
0521 #define IBMVFC_FC_CT_IU     0x02
0522     __be32 cancel_key;
0523 #define IBMVFC_PASSTHRU_CANCEL_KEY  0x80000000
0524 #define IBMVFC_INTERNAL_CANCEL_KEY  0x80000001
0525     __be32 reserved;
0526     struct srp_direct_buf cmd;
0527     struct srp_direct_buf rsp;
0528     __be64 correlation;
0529     __be64 scsi_id;
0530     __be64 tag;
0531     __be64 target_wwpn;
0532     __be64 reserved2[2];
0533 } __packed __aligned(8);
0534 
0535 struct ibmvfc_passthru_mad {
0536     struct ibmvfc_mad_common common;
0537     struct srp_direct_buf cmd_ioba;
0538     struct ibmvfc_passthru_iu iu;
0539     struct ibmvfc_passthru_fc_iu fc_iu;
0540 } __packed __aligned(8);
0541 
0542 struct ibmvfc_channel_enquiry {
0543     struct ibmvfc_mad_common common;
0544     __be32 flags;
0545 #define IBMVFC_NO_CHANNELS_TO_CRQ_SUPPORT   0x01
0546 #define IBMVFC_SUPPORT_VARIABLE_SUBQ_MSG    0x02
0547 #define IBMVFC_NO_N_TO_M_CHANNELS_SUPPORT   0x04
0548     __be32 num_scsi_subq_channels;
0549     __be32 num_nvmeof_subq_channels;
0550     __be32 num_scsi_vas_channels;
0551     __be32 num_nvmeof_vas_channels;
0552 } __packed __aligned(8);
0553 
0554 struct ibmvfc_channel_setup_mad {
0555     struct ibmvfc_mad_common common;
0556     struct srp_direct_buf buffer;
0557 } __packed __aligned(8);
0558 
0559 #define IBMVFC_MAX_CHANNELS 502
0560 
0561 struct ibmvfc_channel_setup {
0562     __be32 flags;
0563 #define IBMVFC_CANCEL_CHANNELS      0x01
0564 #define IBMVFC_USE_BUFFER       0x02
0565 #define IBMVFC_CHANNELS_CANCELED    0x04
0566     __be32 reserved;
0567     __be32 num_scsi_subq_channels;
0568     __be32 num_nvmeof_subq_channels;
0569     __be32 num_scsi_vas_channels;
0570     __be32 num_nvmeof_vas_channels;
0571     struct srp_direct_buf buffer;
0572     __be64 reserved2[5];
0573     __be64 channel_handles[IBMVFC_MAX_CHANNELS];
0574 } __packed __aligned(8);
0575 
0576 struct ibmvfc_connection_info {
0577     struct ibmvfc_mad_common common;
0578     __be64 information_bits;
0579 #define IBMVFC_NO_FC_IO_CHANNEL     0x01
0580 #define IBMVFC_NO_PHYP_VAS      0x02
0581 #define IBMVFC_NO_PHYP_SUBQ     0x04
0582 #define IBMVFC_PHYP_DEPRECATED_SUBQ 0x08
0583 #define IBMVFC_PHYP_PRESERVED_SUBQ  0x10
0584 #define IBMVFC_PHYP_FULL_SUBQ       0x20
0585     __be64 reserved[16];
0586 } __packed __aligned(8);
0587 
0588 struct ibmvfc_trace_start_entry {
0589     u32 xfer_len;
0590 } __packed;
0591 
0592 struct ibmvfc_trace_end_entry {
0593     u16 status;
0594     u16 error;
0595     u8 fcp_rsp_flags;
0596     u8 rsp_code;
0597     u8 scsi_status;
0598     u8 reserved;
0599 } __packed;
0600 
0601 struct ibmvfc_trace_entry {
0602     struct ibmvfc_event *evt;
0603     u32 time;
0604     u32 scsi_id;
0605     u32 lun;
0606     u8 fmt;
0607     u8 op_code;
0608     u8 tmf_flags;
0609     u8 type;
0610 #define IBMVFC_TRC_START    0x00
0611 #define IBMVFC_TRC_END      0xff
0612     union {
0613         struct ibmvfc_trace_start_entry start;
0614         struct ibmvfc_trace_end_entry end;
0615     } u;
0616 } __packed __aligned(8);
0617 
0618 enum ibmvfc_crq_formats {
0619     IBMVFC_CMD_FORMAT       = 0x01,
0620     IBMVFC_ASYNC_EVENT  = 0x02,
0621     IBMVFC_MAD_FORMAT       = 0x04,
0622 };
0623 
0624 enum ibmvfc_async_event {
0625     IBMVFC_AE_ELS_PLOGI     = 0x0001,
0626     IBMVFC_AE_ELS_LOGO      = 0x0002,
0627     IBMVFC_AE_ELS_PRLO      = 0x0004,
0628     IBMVFC_AE_SCN_NPORT     = 0x0008,
0629     IBMVFC_AE_SCN_GROUP     = 0x0010,
0630     IBMVFC_AE_SCN_DOMAIN        = 0x0020,
0631     IBMVFC_AE_SCN_FABRIC        = 0x0040,
0632     IBMVFC_AE_LINK_UP           = 0x0080,
0633     IBMVFC_AE_LINK_DOWN     = 0x0100,
0634     IBMVFC_AE_LINK_DEAD     = 0x0200,
0635     IBMVFC_AE_HALT          = 0x0400,
0636     IBMVFC_AE_RESUME            = 0x0800,
0637     IBMVFC_AE_ADAPTER_FAILED    = 0x1000,
0638     IBMVFC_AE_FPIN          = 0x2000,
0639 };
0640 
0641 struct ibmvfc_async_desc {
0642     const char *desc;
0643     enum ibmvfc_async_event ae;
0644     int log_level;
0645 };
0646 
0647 struct ibmvfc_crq {
0648     volatile u8 valid;
0649     volatile u8 format;
0650     u8 reserved[6];
0651     volatile __be64 ioba;
0652 } __packed __aligned(8);
0653 
0654 struct ibmvfc_sub_crq {
0655     struct ibmvfc_crq crq;
0656     __be64 reserved[2];
0657 } __packed __aligned(8);
0658 
0659 enum ibmvfc_ae_link_state {
0660     IBMVFC_AE_LS_LINK_UP        = 0x01,
0661     IBMVFC_AE_LS_LINK_BOUNCED   = 0x02,
0662     IBMVFC_AE_LS_LINK_DOWN      = 0x04,
0663     IBMVFC_AE_LS_LINK_DEAD      = 0x08,
0664 };
0665 
0666 enum ibmvfc_ae_fpin_status {
0667     IBMVFC_AE_FPIN_LINK_CONGESTED   = 0x1,
0668     IBMVFC_AE_FPIN_PORT_CONGESTED   = 0x2,
0669     IBMVFC_AE_FPIN_PORT_CLEARED = 0x3,
0670     IBMVFC_AE_FPIN_PORT_DEGRADED    = 0x4,
0671 };
0672 
0673 struct ibmvfc_async_crq {
0674     volatile u8 valid;
0675     u8 link_state;
0676     u8 fpin_status;
0677     u8 pad;
0678     __be32 pad2;
0679     volatile __be64 event;
0680     volatile __be64 scsi_id;
0681     volatile __be64 wwpn;
0682     volatile __be64 node_name;
0683     __be64 reserved;
0684 } __packed __aligned(8);
0685 
0686 union ibmvfc_iu {
0687     struct ibmvfc_mad_common mad_common;
0688     struct ibmvfc_npiv_login_mad npiv_login;
0689     struct ibmvfc_npiv_logout_mad npiv_logout;
0690     struct ibmvfc_discover_targets discover_targets;
0691     struct ibmvfc_port_login plogi;
0692     struct ibmvfc_process_login prli;
0693     struct ibmvfc_move_login move_login;
0694     struct ibmvfc_query_tgt query_tgt;
0695     struct ibmvfc_implicit_logout implicit_logout;
0696     struct ibmvfc_tmf tmf;
0697     struct ibmvfc_cmd cmd;
0698     struct ibmvfc_passthru_mad passthru;
0699     struct ibmvfc_channel_enquiry channel_enquiry;
0700     struct ibmvfc_channel_setup_mad channel_setup;
0701     struct ibmvfc_connection_info connection_info;
0702 } __packed __aligned(8);
0703 
0704 enum ibmvfc_target_action {
0705     IBMVFC_TGT_ACTION_NONE = 0,
0706     IBMVFC_TGT_ACTION_INIT,
0707     IBMVFC_TGT_ACTION_INIT_WAIT,
0708     IBMVFC_TGT_ACTION_LOGOUT_RPORT,
0709     IBMVFC_TGT_ACTION_LOGOUT_RPORT_WAIT,
0710     IBMVFC_TGT_ACTION_DEL_RPORT,
0711     IBMVFC_TGT_ACTION_DELETED_RPORT,
0712     IBMVFC_TGT_ACTION_DEL_AND_LOGOUT_RPORT,
0713     IBMVFC_TGT_ACTION_LOGOUT_DELETED_RPORT,
0714 };
0715 
0716 struct ibmvfc_target {
0717     struct list_head queue;
0718     struct ibmvfc_host *vhost;
0719     u64 scsi_id;
0720     u64 wwpn;
0721     u64 new_scsi_id;
0722     struct fc_rport *rport;
0723     int target_id;
0724     enum ibmvfc_target_action action;
0725     int need_login;
0726     int add_rport;
0727     int init_retries;
0728     int logo_rcvd;
0729     int move_login;
0730     u32 cancel_key;
0731     struct ibmvfc_service_parms service_parms;
0732     struct ibmvfc_service_parms service_parms_change;
0733     struct fc_rport_identifiers ids;
0734     void (*job_step) (struct ibmvfc_target *);
0735     struct timer_list timer;
0736     struct kref kref;
0737 };
0738 
0739 /* a unit of work for the hosting partition */
0740 struct ibmvfc_event {
0741     struct list_head queue_list;
0742     struct list_head cancel;
0743     struct ibmvfc_host *vhost;
0744     struct ibmvfc_queue *queue;
0745     struct ibmvfc_target *tgt;
0746     struct scsi_cmnd *cmnd;
0747     atomic_t free;
0748     atomic_t active;
0749     union ibmvfc_iu *xfer_iu;
0750     void (*done)(struct ibmvfc_event *evt);
0751     void (*_done)(struct ibmvfc_event *evt);
0752     struct ibmvfc_crq crq;
0753     union ibmvfc_iu iu;
0754     union ibmvfc_iu *sync_iu;
0755     struct srp_direct_buf *ext_list;
0756     dma_addr_t ext_list_token;
0757     struct completion comp;
0758     struct completion *eh_comp;
0759     struct timer_list timer;
0760     u16 hwq;
0761 };
0762 
0763 /* a pool of event structs for use */
0764 struct ibmvfc_event_pool {
0765     struct ibmvfc_event *events;
0766     u32 size;
0767     union ibmvfc_iu *iu_storage;
0768     dma_addr_t iu_token;
0769 };
0770 
0771 enum ibmvfc_msg_fmt {
0772     IBMVFC_CRQ_FMT = 0,
0773     IBMVFC_ASYNC_FMT,
0774     IBMVFC_SUB_CRQ_FMT,
0775 };
0776 
0777 union ibmvfc_msgs {
0778     void *handle;
0779     struct ibmvfc_crq *crq;
0780     struct ibmvfc_async_crq *async;
0781     struct ibmvfc_sub_crq *scrq;
0782 };
0783 
0784 struct ibmvfc_queue {
0785     union ibmvfc_msgs msgs;
0786     dma_addr_t msg_token;
0787     enum ibmvfc_msg_fmt fmt;
0788     int size, cur;
0789     spinlock_t _lock;
0790     spinlock_t *q_lock;
0791 
0792     struct ibmvfc_host *vhost;
0793     struct ibmvfc_event_pool evt_pool;
0794     struct list_head sent;
0795     struct list_head free;
0796     spinlock_t l_lock;
0797 
0798     union ibmvfc_iu cancel_rsp;
0799 
0800     /* Sub-CRQ fields */
0801     unsigned long cookie;
0802     unsigned long vios_cookie;
0803     unsigned long hw_irq;
0804     unsigned long irq;
0805     unsigned long hwq_id;
0806     char name[32];
0807 };
0808 
0809 struct ibmvfc_scsi_channels {
0810     struct ibmvfc_queue *scrqs;
0811     unsigned int active_queues;
0812 };
0813 
0814 enum ibmvfc_host_action {
0815     IBMVFC_HOST_ACTION_NONE = 0,
0816     IBMVFC_HOST_ACTION_RESET,
0817     IBMVFC_HOST_ACTION_REENABLE,
0818     IBMVFC_HOST_ACTION_LOGO,
0819     IBMVFC_HOST_ACTION_LOGO_WAIT,
0820     IBMVFC_HOST_ACTION_INIT,
0821     IBMVFC_HOST_ACTION_INIT_WAIT,
0822     IBMVFC_HOST_ACTION_QUERY,
0823     IBMVFC_HOST_ACTION_QUERY_TGTS,
0824     IBMVFC_HOST_ACTION_TGT_DEL,
0825     IBMVFC_HOST_ACTION_ALLOC_TGTS,
0826     IBMVFC_HOST_ACTION_TGT_INIT,
0827     IBMVFC_HOST_ACTION_TGT_DEL_FAILED,
0828 };
0829 
0830 enum ibmvfc_host_state {
0831     IBMVFC_NO_CRQ = 0,
0832     IBMVFC_INITIALIZING,
0833     IBMVFC_ACTIVE,
0834     IBMVFC_HALTED,
0835     IBMVFC_LINK_DOWN,
0836     IBMVFC_LINK_DEAD,
0837     IBMVFC_HOST_OFFLINE,
0838 };
0839 
0840 struct ibmvfc_host {
0841     char name[8];
0842     struct list_head queue;
0843     struct Scsi_Host *host;
0844     enum ibmvfc_host_state state;
0845     enum ibmvfc_host_action action;
0846 #define IBMVFC_NUM_TRACE_INDEX_BITS     8
0847 #define IBMVFC_NUM_TRACE_ENTRIES        (1 << IBMVFC_NUM_TRACE_INDEX_BITS)
0848 #define IBMVFC_TRACE_INDEX_MASK         (IBMVFC_NUM_TRACE_ENTRIES - 1)
0849 #define IBMVFC_TRACE_SIZE   (sizeof(struct ibmvfc_trace_entry) * IBMVFC_NUM_TRACE_ENTRIES)
0850     struct ibmvfc_trace_entry *trace;
0851     atomic_t trace_index;
0852     int num_targets;
0853     struct list_head targets;
0854     struct list_head purge;
0855     struct device *dev;
0856     struct dma_pool *sg_pool;
0857     mempool_t *tgt_pool;
0858     struct ibmvfc_queue crq;
0859     struct ibmvfc_queue async_crq;
0860     struct ibmvfc_scsi_channels scsi_scrqs;
0861     struct ibmvfc_npiv_login login_info;
0862     union ibmvfc_npiv_login_data *login_buf;
0863     dma_addr_t login_buf_dma;
0864     struct ibmvfc_channel_setup *channel_setup_buf;
0865     dma_addr_t channel_setup_dma;
0866     int disc_buf_sz;
0867     int log_level;
0868     struct ibmvfc_discover_targets_entry *disc_buf;
0869     struct mutex passthru_mutex;
0870     int max_vios_scsi_channels;
0871     int task_set;
0872     int init_retries;
0873     int discovery_threads;
0874     int abort_threads;
0875     int client_migrated;
0876     int reinit;
0877     int delay_init;
0878     int scan_complete;
0879     int scan_timeout;
0880     int logged_in;
0881     int mq_enabled;
0882     int using_channels;
0883     int do_enquiry;
0884     int client_scsi_channels;
0885     int aborting_passthru;
0886     int events_to_log;
0887 #define IBMVFC_AE_LINKUP    0x0001
0888 #define IBMVFC_AE_LINKDOWN  0x0002
0889 #define IBMVFC_AE_RSCN      0x0004
0890     dma_addr_t disc_buf_dma;
0891     unsigned int partition_number;
0892     char partition_name[97];
0893     void (*job_step) (struct ibmvfc_host *);
0894     struct task_struct *work_thread;
0895     struct tasklet_struct tasklet;
0896     struct work_struct rport_add_work_q;
0897     wait_queue_head_t init_wait_q;
0898     wait_queue_head_t work_wait_q;
0899 };
0900 
0901 #define DBG_CMD(CMD) do { if (ibmvfc_debug) CMD; } while (0)
0902 
0903 #define tgt_dbg(t, fmt, ...)            \
0904     DBG_CMD(dev_info((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__))
0905 
0906 #define tgt_info(t, fmt, ...)       \
0907     dev_info((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
0908 
0909 #define tgt_err(t, fmt, ...)        \
0910     dev_err((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
0911 
0912 #define tgt_log(t, level, fmt, ...) \
0913     do { \
0914         if ((t)->vhost->log_level >= level) \
0915             tgt_err(t, fmt, ##__VA_ARGS__); \
0916     } while (0)
0917 
0918 #define ibmvfc_dbg(vhost, ...) \
0919     DBG_CMD(dev_info((vhost)->dev, ##__VA_ARGS__))
0920 
0921 #define ibmvfc_log(vhost, level, ...) \
0922     do { \
0923         if ((vhost)->log_level >= level) \
0924             dev_err((vhost)->dev, ##__VA_ARGS__); \
0925     } while (0)
0926 
0927 #define ENTER DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Entering %s\n", __func__))
0928 #define LEAVE DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Leaving %s\n", __func__))
0929 
0930 #ifdef CONFIG_SCSI_IBMVFC_TRACE
0931 #define ibmvfc_create_trace_file(kobj, attr) sysfs_create_bin_file(kobj, attr)
0932 #define ibmvfc_remove_trace_file(kobj, attr) sysfs_remove_bin_file(kobj, attr)
0933 #else
0934 #define ibmvfc_create_trace_file(kobj, attr) 0
0935 #define ibmvfc_remove_trace_file(kobj, attr) do { } while (0)
0936 #endif
0937 
0938 #endif