1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * FC Transport BSG Interface 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * Copyright (C) 2008 James Smart, Emulex Corporation 6*4882a593Smuzhiyun */ 7*4882a593Smuzhiyun 8*4882a593Smuzhiyun #ifndef SCSI_BSG_FC_H 9*4882a593Smuzhiyun #define SCSI_BSG_FC_H 10*4882a593Smuzhiyun 11*4882a593Smuzhiyun #include <linux/types.h> 12*4882a593Smuzhiyun 13*4882a593Smuzhiyun /* 14*4882a593Smuzhiyun * This file intended to be included by both kernel and user space 15*4882a593Smuzhiyun */ 16*4882a593Smuzhiyun 17*4882a593Smuzhiyun /* 18*4882a593Smuzhiyun * FC Transport SGIO v4 BSG Message Support 19*4882a593Smuzhiyun */ 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun /* Default BSG request timeout (in seconds) */ 22*4882a593Smuzhiyun #define FC_DEFAULT_BSG_TIMEOUT (10 * HZ) 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun /* 26*4882a593Smuzhiyun * Request Message Codes supported by the FC Transport 27*4882a593Smuzhiyun */ 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun /* define the class masks for the message codes */ 30*4882a593Smuzhiyun #define FC_BSG_CLS_MASK 0xF0000000 /* find object class */ 31*4882a593Smuzhiyun #define FC_BSG_HST_MASK 0x80000000 /* fc host class */ 32*4882a593Smuzhiyun #define FC_BSG_RPT_MASK 0x40000000 /* fc rport class */ 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun /* fc_host Message Codes */ 35*4882a593Smuzhiyun #define FC_BSG_HST_ADD_RPORT (FC_BSG_HST_MASK | 0x00000001) 36*4882a593Smuzhiyun #define FC_BSG_HST_DEL_RPORT (FC_BSG_HST_MASK | 0x00000002) 37*4882a593Smuzhiyun #define FC_BSG_HST_ELS_NOLOGIN (FC_BSG_HST_MASK | 0x00000003) 38*4882a593Smuzhiyun #define FC_BSG_HST_CT (FC_BSG_HST_MASK | 0x00000004) 39*4882a593Smuzhiyun #define FC_BSG_HST_VENDOR (FC_BSG_HST_MASK | 0x000000FF) 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun /* fc_rport Message Codes */ 42*4882a593Smuzhiyun #define FC_BSG_RPT_ELS (FC_BSG_RPT_MASK | 0x00000001) 43*4882a593Smuzhiyun #define FC_BSG_RPT_CT (FC_BSG_RPT_MASK | 0x00000002) 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun /* 48*4882a593Smuzhiyun * FC Address Identifiers in Message Structures : 49*4882a593Smuzhiyun * 50*4882a593Smuzhiyun * Whenever a command payload contains a FC Address Identifier 51*4882a593Smuzhiyun * (aka port_id), the value is effectively in big-endian 52*4882a593Smuzhiyun * order, thus the array elements are decoded as follows: 53*4882a593Smuzhiyun * element [0] is bits 23:16 of the FC Address Identifier 54*4882a593Smuzhiyun * element [1] is bits 15:8 of the FC Address Identifier 55*4882a593Smuzhiyun * element [2] is bits 7:0 of the FC Address Identifier 56*4882a593Smuzhiyun */ 57*4882a593Smuzhiyun 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun /* 60*4882a593Smuzhiyun * FC Host Messages 61*4882a593Smuzhiyun */ 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun /* FC_BSG_HST_ADDR_PORT : */ 64*4882a593Smuzhiyun 65*4882a593Smuzhiyun /* Request: 66*4882a593Smuzhiyun * This message requests the FC host to login to the remote port 67*4882a593Smuzhiyun * at the specified N_Port_Id. The remote port is to be enumerated 68*4882a593Smuzhiyun * with the transport upon completion of the login. 69*4882a593Smuzhiyun */ 70*4882a593Smuzhiyun struct fc_bsg_host_add_rport { 71*4882a593Smuzhiyun __u8 reserved; 72*4882a593Smuzhiyun 73*4882a593Smuzhiyun /* FC Address Identier of the remote port to login to */ 74*4882a593Smuzhiyun __u8 port_id[3]; 75*4882a593Smuzhiyun }; 76*4882a593Smuzhiyun 77*4882a593Smuzhiyun /* Response: 78*4882a593Smuzhiyun * There is no additional response data - fc_bsg_reply->result is sufficient 79*4882a593Smuzhiyun */ 80*4882a593Smuzhiyun 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun /* FC_BSG_HST_DEL_RPORT : */ 83*4882a593Smuzhiyun 84*4882a593Smuzhiyun /* Request: 85*4882a593Smuzhiyun * This message requests the FC host to remove an enumerated 86*4882a593Smuzhiyun * remote port and to terminate the login to it. 87*4882a593Smuzhiyun * 88*4882a593Smuzhiyun * Note: The driver is free to reject this request if it desires to 89*4882a593Smuzhiyun * remain logged in with the remote port. 90*4882a593Smuzhiyun */ 91*4882a593Smuzhiyun struct fc_bsg_host_del_rport { 92*4882a593Smuzhiyun __u8 reserved; 93*4882a593Smuzhiyun 94*4882a593Smuzhiyun /* FC Address Identier of the remote port to logout of */ 95*4882a593Smuzhiyun __u8 port_id[3]; 96*4882a593Smuzhiyun }; 97*4882a593Smuzhiyun 98*4882a593Smuzhiyun /* Response: 99*4882a593Smuzhiyun * There is no additional response data - fc_bsg_reply->result is sufficient 100*4882a593Smuzhiyun */ 101*4882a593Smuzhiyun 102*4882a593Smuzhiyun 103*4882a593Smuzhiyun /* FC_BSG_HST_ELS_NOLOGIN : */ 104*4882a593Smuzhiyun 105*4882a593Smuzhiyun /* Request: 106*4882a593Smuzhiyun * This message requests the FC_Host to send an ELS to a specific 107*4882a593Smuzhiyun * N_Port_ID. The host does not need to log into the remote port, 108*4882a593Smuzhiyun * nor does it need to enumerate the rport for further traffic 109*4882a593Smuzhiyun * (although, the FC host is free to do so if it desires). 110*4882a593Smuzhiyun */ 111*4882a593Smuzhiyun struct fc_bsg_host_els { 112*4882a593Smuzhiyun /* 113*4882a593Smuzhiyun * ELS Command Code being sent (must be the same as byte 0 114*4882a593Smuzhiyun * of the payload) 115*4882a593Smuzhiyun */ 116*4882a593Smuzhiyun __u8 command_code; 117*4882a593Smuzhiyun 118*4882a593Smuzhiyun /* FC Address Identier of the remote port to send the ELS to */ 119*4882a593Smuzhiyun __u8 port_id[3]; 120*4882a593Smuzhiyun }; 121*4882a593Smuzhiyun 122*4882a593Smuzhiyun /* Response: 123*4882a593Smuzhiyun */ 124*4882a593Smuzhiyun /* fc_bsg_ctels_reply->status values */ 125*4882a593Smuzhiyun #define FC_CTELS_STATUS_OK 0x00000000 126*4882a593Smuzhiyun #define FC_CTELS_STATUS_REJECT 0x00000001 127*4882a593Smuzhiyun #define FC_CTELS_STATUS_P_RJT 0x00000002 128*4882a593Smuzhiyun #define FC_CTELS_STATUS_F_RJT 0x00000003 129*4882a593Smuzhiyun #define FC_CTELS_STATUS_P_BSY 0x00000004 130*4882a593Smuzhiyun #define FC_CTELS_STATUS_F_BSY 0x00000006 131*4882a593Smuzhiyun struct fc_bsg_ctels_reply { 132*4882a593Smuzhiyun /* 133*4882a593Smuzhiyun * Note: An ELS LS_RJT may be reported in 2 ways: 134*4882a593Smuzhiyun * a) A status of FC_CTELS_STATUS_OK is returned. The caller 135*4882a593Smuzhiyun * is to look into the ELS receive payload to determine 136*4882a593Smuzhiyun * LS_ACC or LS_RJT (by contents of word 0). The reject 137*4882a593Smuzhiyun * data will be in word 1. 138*4882a593Smuzhiyun * b) A status of FC_CTELS_STATUS_REJECT is returned, The 139*4882a593Smuzhiyun * rjt_data field will contain valid data. 140*4882a593Smuzhiyun * 141*4882a593Smuzhiyun * Note: ELS LS_ACC is determined by an FC_CTELS_STATUS_OK, and 142*4882a593Smuzhiyun * the receive payload word 0 indicates LS_ACC 143*4882a593Smuzhiyun * (e.g. value is 0x02xxxxxx). 144*4882a593Smuzhiyun * 145*4882a593Smuzhiyun * Note: Similarly, a CT Reject may be reported in 2 ways: 146*4882a593Smuzhiyun * a) A status of FC_CTELS_STATUS_OK is returned. The caller 147*4882a593Smuzhiyun * is to look into the CT receive payload to determine 148*4882a593Smuzhiyun * Accept or Reject (by contents of word 2). The reject 149*4882a593Smuzhiyun * data will be in word 3. 150*4882a593Smuzhiyun * b) A status of FC_CTELS_STATUS_REJECT is returned, The 151*4882a593Smuzhiyun * rjt_data field will contain valid data. 152*4882a593Smuzhiyun * 153*4882a593Smuzhiyun * Note: x_RJT/BSY status will indicae that the rjt_data field 154*4882a593Smuzhiyun * is valid and contains the reason/explanation values. 155*4882a593Smuzhiyun */ 156*4882a593Smuzhiyun __u32 status; /* See FC_CTELS_STATUS_xxx */ 157*4882a593Smuzhiyun 158*4882a593Smuzhiyun /* valid if status is not FC_CTELS_STATUS_OK */ 159*4882a593Smuzhiyun struct { 160*4882a593Smuzhiyun __u8 action; /* fragment_id for CT REJECT */ 161*4882a593Smuzhiyun __u8 reason_code; 162*4882a593Smuzhiyun __u8 reason_explanation; 163*4882a593Smuzhiyun __u8 vendor_unique; 164*4882a593Smuzhiyun } rjt_data; 165*4882a593Smuzhiyun }; 166*4882a593Smuzhiyun 167*4882a593Smuzhiyun 168*4882a593Smuzhiyun /* FC_BSG_HST_CT : */ 169*4882a593Smuzhiyun 170*4882a593Smuzhiyun /* Request: 171*4882a593Smuzhiyun * This message requests that a CT Request be performed with the 172*4882a593Smuzhiyun * indicated N_Port_ID. The driver is responsible for logging in with 173*4882a593Smuzhiyun * the fabric and/or N_Port_ID, etc as per FC rules. This request does 174*4882a593Smuzhiyun * not mandate that the driver must enumerate the destination in the 175*4882a593Smuzhiyun * transport. The driver is allowed to decide whether to enumerate it, 176*4882a593Smuzhiyun * and whether to tear it down after the request. 177*4882a593Smuzhiyun */ 178*4882a593Smuzhiyun struct fc_bsg_host_ct { 179*4882a593Smuzhiyun __u8 reserved; 180*4882a593Smuzhiyun 181*4882a593Smuzhiyun /* FC Address Identier of the remote port to send the ELS to */ 182*4882a593Smuzhiyun __u8 port_id[3]; 183*4882a593Smuzhiyun 184*4882a593Smuzhiyun /* 185*4882a593Smuzhiyun * We need words 0-2 of the generic preamble for the LLD's 186*4882a593Smuzhiyun */ 187*4882a593Smuzhiyun __u32 preamble_word0; /* revision & IN_ID */ 188*4882a593Smuzhiyun __u32 preamble_word1; /* GS_Type, GS_SubType, Options, Rsvd */ 189*4882a593Smuzhiyun __u32 preamble_word2; /* Cmd Code, Max Size */ 190*4882a593Smuzhiyun 191*4882a593Smuzhiyun }; 192*4882a593Smuzhiyun /* Response: 193*4882a593Smuzhiyun * 194*4882a593Smuzhiyun * The reply structure is an fc_bsg_ctels_reply structure 195*4882a593Smuzhiyun */ 196*4882a593Smuzhiyun 197*4882a593Smuzhiyun 198*4882a593Smuzhiyun /* FC_BSG_HST_VENDOR : */ 199*4882a593Smuzhiyun 200*4882a593Smuzhiyun /* Request: 201*4882a593Smuzhiyun * Note: When specifying vendor_id, be sure to read the Vendor Type and ID 202*4882a593Smuzhiyun * formatting requirements specified in scsi_netlink.h 203*4882a593Smuzhiyun */ 204*4882a593Smuzhiyun struct fc_bsg_host_vendor { 205*4882a593Smuzhiyun /* 206*4882a593Smuzhiyun * Identifies the vendor that the message is formatted for. This 207*4882a593Smuzhiyun * should be the recipient of the message. 208*4882a593Smuzhiyun */ 209*4882a593Smuzhiyun __u64 vendor_id; 210*4882a593Smuzhiyun 211*4882a593Smuzhiyun /* start of vendor command area */ 212*4882a593Smuzhiyun __u32 vendor_cmd[0]; 213*4882a593Smuzhiyun }; 214*4882a593Smuzhiyun 215*4882a593Smuzhiyun /* Response: 216*4882a593Smuzhiyun */ 217*4882a593Smuzhiyun struct fc_bsg_host_vendor_reply { 218*4882a593Smuzhiyun /* start of vendor response area */ 219*4882a593Smuzhiyun __u32 vendor_rsp[0]; 220*4882a593Smuzhiyun }; 221*4882a593Smuzhiyun 222*4882a593Smuzhiyun 223*4882a593Smuzhiyun 224*4882a593Smuzhiyun /* 225*4882a593Smuzhiyun * FC Remote Port Messages 226*4882a593Smuzhiyun */ 227*4882a593Smuzhiyun 228*4882a593Smuzhiyun /* FC_BSG_RPT_ELS : */ 229*4882a593Smuzhiyun 230*4882a593Smuzhiyun /* Request: 231*4882a593Smuzhiyun * This message requests that an ELS be performed with the rport. 232*4882a593Smuzhiyun */ 233*4882a593Smuzhiyun struct fc_bsg_rport_els { 234*4882a593Smuzhiyun /* 235*4882a593Smuzhiyun * ELS Command Code being sent (must be the same as 236*4882a593Smuzhiyun * byte 0 of the payload) 237*4882a593Smuzhiyun */ 238*4882a593Smuzhiyun __u8 els_code; 239*4882a593Smuzhiyun }; 240*4882a593Smuzhiyun 241*4882a593Smuzhiyun /* Response: 242*4882a593Smuzhiyun * 243*4882a593Smuzhiyun * The reply structure is an fc_bsg_ctels_reply structure 244*4882a593Smuzhiyun */ 245*4882a593Smuzhiyun 246*4882a593Smuzhiyun 247*4882a593Smuzhiyun /* FC_BSG_RPT_CT : */ 248*4882a593Smuzhiyun 249*4882a593Smuzhiyun /* Request: 250*4882a593Smuzhiyun * This message requests that a CT Request be performed with the rport. 251*4882a593Smuzhiyun */ 252*4882a593Smuzhiyun struct fc_bsg_rport_ct { 253*4882a593Smuzhiyun /* 254*4882a593Smuzhiyun * We need words 0-2 of the generic preamble for the LLD's 255*4882a593Smuzhiyun */ 256*4882a593Smuzhiyun __u32 preamble_word0; /* revision & IN_ID */ 257*4882a593Smuzhiyun __u32 preamble_word1; /* GS_Type, GS_SubType, Options, Rsvd */ 258*4882a593Smuzhiyun __u32 preamble_word2; /* Cmd Code, Max Size */ 259*4882a593Smuzhiyun }; 260*4882a593Smuzhiyun /* Response: 261*4882a593Smuzhiyun * 262*4882a593Smuzhiyun * The reply structure is an fc_bsg_ctels_reply structure 263*4882a593Smuzhiyun */ 264*4882a593Smuzhiyun 265*4882a593Smuzhiyun 266*4882a593Smuzhiyun 267*4882a593Smuzhiyun 268*4882a593Smuzhiyun /* request (CDB) structure of the sg_io_v4 */ 269*4882a593Smuzhiyun struct fc_bsg_request { 270*4882a593Smuzhiyun __u32 msgcode; 271*4882a593Smuzhiyun union { 272*4882a593Smuzhiyun struct fc_bsg_host_add_rport h_addrport; 273*4882a593Smuzhiyun struct fc_bsg_host_del_rport h_delrport; 274*4882a593Smuzhiyun struct fc_bsg_host_els h_els; 275*4882a593Smuzhiyun struct fc_bsg_host_ct h_ct; 276*4882a593Smuzhiyun struct fc_bsg_host_vendor h_vendor; 277*4882a593Smuzhiyun 278*4882a593Smuzhiyun struct fc_bsg_rport_els r_els; 279*4882a593Smuzhiyun struct fc_bsg_rport_ct r_ct; 280*4882a593Smuzhiyun } rqst_data; 281*4882a593Smuzhiyun } __attribute__((packed)); 282*4882a593Smuzhiyun 283*4882a593Smuzhiyun 284*4882a593Smuzhiyun /* response (request sense data) structure of the sg_io_v4 */ 285*4882a593Smuzhiyun struct fc_bsg_reply { 286*4882a593Smuzhiyun /* 287*4882a593Smuzhiyun * The completion result. Result exists in two forms: 288*4882a593Smuzhiyun * if negative, it is an -Exxx system errno value. There will 289*4882a593Smuzhiyun * be no further reply information supplied. 290*4882a593Smuzhiyun * else, it's the 4-byte scsi error result, with driver, host, 291*4882a593Smuzhiyun * msg and status fields. The per-msgcode reply structure 292*4882a593Smuzhiyun * will contain valid data. 293*4882a593Smuzhiyun */ 294*4882a593Smuzhiyun __u32 result; 295*4882a593Smuzhiyun 296*4882a593Smuzhiyun /* If there was reply_payload, how much was recevied ? */ 297*4882a593Smuzhiyun __u32 reply_payload_rcv_len; 298*4882a593Smuzhiyun 299*4882a593Smuzhiyun union { 300*4882a593Smuzhiyun struct fc_bsg_host_vendor_reply vendor_reply; 301*4882a593Smuzhiyun 302*4882a593Smuzhiyun struct fc_bsg_ctels_reply ctels_reply; 303*4882a593Smuzhiyun } reply_data; 304*4882a593Smuzhiyun }; 305*4882a593Smuzhiyun 306*4882a593Smuzhiyun 307*4882a593Smuzhiyun #endif /* SCSI_BSG_FC_H */ 308*4882a593Smuzhiyun 309