Loading...
1/*
2 * ibmvfc.h -- driver for IBM Power Virtual Fibre Channel Adapter
3 *
4 * Written By: Brian King <brking@linux.vnet.ibm.com>, IBM Corporation
5 *
6 * Copyright (C) IBM Corporation, 2008
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24#ifndef _IBMVFC_H
25#define _IBMVFC_H
26
27#include <linux/list.h>
28#include <linux/types.h>
29#include "viosrp.h"
30
31#define IBMVFC_NAME "ibmvfc"
32#define IBMVFC_DRIVER_VERSION "1.0.9"
33#define IBMVFC_DRIVER_DATE "(August 5, 2010)"
34
35#define IBMVFC_DEFAULT_TIMEOUT 60
36#define IBMVFC_ADISC_CANCEL_TIMEOUT 45
37#define IBMVFC_ADISC_TIMEOUT 15
38#define IBMVFC_ADISC_PLUS_CANCEL_TIMEOUT \
39 (IBMVFC_ADISC_TIMEOUT + IBMVFC_ADISC_CANCEL_TIMEOUT)
40#define IBMVFC_INIT_TIMEOUT 120
41#define IBMVFC_ABORT_TIMEOUT 8
42#define IBMVFC_ABORT_WAIT_TIMEOUT 40
43#define IBMVFC_MAX_REQUESTS_DEFAULT 100
44
45#define IBMVFC_DEBUG 0
46#define IBMVFC_MAX_TARGETS 1024
47#define IBMVFC_MAX_LUN 0xffffffff
48#define IBMVFC_MAX_SECTORS 0xffffu
49#define IBMVFC_MAX_DISC_THREADS 4
50#define IBMVFC_TGT_MEMPOOL_SZ 64
51#define IBMVFC_MAX_CMDS_PER_LUN 64
52#define IBMVFC_MAX_HOST_INIT_RETRIES 6
53#define IBMVFC_MAX_TGT_INIT_RETRIES 3
54#define IBMVFC_DEV_LOSS_TMO (5 * 60)
55#define IBMVFC_DEFAULT_LOG_LEVEL 2
56#define IBMVFC_MAX_CDB_LEN 16
57
58/*
59 * Ensure we have resources for ERP and initialization:
60 * 1 for ERP
61 * 1 for initialization
62 * 1 for NPIV Logout
63 * 2 for BSG passthru
64 * 2 for each discovery thread
65 */
66#define IBMVFC_NUM_INTERNAL_REQ (1 + 1 + 1 + 2 + (disc_threads * 2))
67
68#define IBMVFC_MAD_SUCCESS 0x00
69#define IBMVFC_MAD_NOT_SUPPORTED 0xF1
70#define IBMVFC_MAD_FAILED 0xF7
71#define IBMVFC_MAD_DRIVER_FAILED 0xEE
72#define IBMVFC_MAD_CRQ_ERROR 0xEF
73
74enum ibmvfc_crq_valid {
75 IBMVFC_CRQ_CMD_RSP = 0x80,
76 IBMVFC_CRQ_INIT_RSP = 0xC0,
77 IBMVFC_CRQ_XPORT_EVENT = 0xFF,
78};
79
80enum ibmvfc_crq_format {
81 IBMVFC_CRQ_INIT = 0x01,
82 IBMVFC_CRQ_INIT_COMPLETE = 0x02,
83 IBMVFC_PARTITION_MIGRATED = 0x06,
84};
85
86enum ibmvfc_cmd_status_flags {
87 IBMVFC_FABRIC_MAPPED = 0x0001,
88 IBMVFC_VIOS_FAILURE = 0x0002,
89 IBMVFC_FC_FAILURE = 0x0004,
90 IBMVFC_FC_SCSI_ERROR = 0x0008,
91 IBMVFC_HW_EVENT_LOGGED = 0x0010,
92 IBMVFC_VIOS_LOGGED = 0x0020,
93};
94
95enum ibmvfc_fabric_mapped_errors {
96 IBMVFC_UNABLE_TO_ESTABLISH = 0x0001,
97 IBMVFC_XPORT_FAULT = 0x0002,
98 IBMVFC_CMD_TIMEOUT = 0x0003,
99 IBMVFC_ENETDOWN = 0x0004,
100 IBMVFC_HW_FAILURE = 0x0005,
101 IBMVFC_LINK_DOWN_ERR = 0x0006,
102 IBMVFC_LINK_DEAD_ERR = 0x0007,
103 IBMVFC_UNABLE_TO_REGISTER = 0x0008,
104 IBMVFC_XPORT_BUSY = 0x000A,
105 IBMVFC_XPORT_DEAD = 0x000B,
106 IBMVFC_CONFIG_ERROR = 0x000C,
107 IBMVFC_NAME_SERVER_FAIL = 0x000D,
108 IBMVFC_LINK_HALTED = 0x000E,
109 IBMVFC_XPORT_GENERAL = 0x8000,
110};
111
112enum ibmvfc_vios_errors {
113 IBMVFC_CRQ_FAILURE = 0x0001,
114 IBMVFC_SW_FAILURE = 0x0002,
115 IBMVFC_INVALID_PARAMETER = 0x0003,
116 IBMVFC_MISSING_PARAMETER = 0x0004,
117 IBMVFC_HOST_IO_BUS = 0x0005,
118 IBMVFC_TRANS_CANCELLED = 0x0006,
119 IBMVFC_TRANS_CANCELLED_IMPLICIT = 0x0007,
120 IBMVFC_INSUFFICIENT_RESOURCE = 0x0008,
121 IBMVFC_PLOGI_REQUIRED = 0x0010,
122 IBMVFC_COMMAND_FAILED = 0x8000,
123};
124
125enum ibmvfc_mad_types {
126 IBMVFC_NPIV_LOGIN = 0x0001,
127 IBMVFC_DISC_TARGETS = 0x0002,
128 IBMVFC_PORT_LOGIN = 0x0004,
129 IBMVFC_PROCESS_LOGIN = 0x0008,
130 IBMVFC_QUERY_TARGET = 0x0010,
131 IBMVFC_IMPLICIT_LOGOUT = 0x0040,
132 IBMVFC_PASSTHRU = 0x0200,
133 IBMVFC_TMF_MAD = 0x0100,
134 IBMVFC_NPIV_LOGOUT = 0x0800,
135};
136
137struct ibmvfc_mad_common {
138 u32 version;
139 u32 reserved;
140 u32 opcode;
141 u16 status;
142 u16 length;
143 u64 tag;
144}__attribute__((packed, aligned (8)));
145
146struct ibmvfc_npiv_login_mad {
147 struct ibmvfc_mad_common common;
148 struct srp_direct_buf buffer;
149}__attribute__((packed, aligned (8)));
150
151struct ibmvfc_npiv_logout_mad {
152 struct ibmvfc_mad_common common;
153}__attribute__((packed, aligned (8)));
154
155#define IBMVFC_MAX_NAME 256
156
157struct ibmvfc_npiv_login {
158 u32 ostype;
159#define IBMVFC_OS_LINUX 0x02
160 u32 pad;
161 u64 max_dma_len;
162 u32 max_payload;
163 u32 max_response;
164 u32 partition_num;
165 u32 vfc_frame_version;
166 u16 fcp_version;
167 u16 flags;
168#define IBMVFC_CLIENT_MIGRATED 0x01
169#define IBMVFC_FLUSH_ON_HALT 0x02
170 u32 max_cmds;
171 u64 capabilities;
172#define IBMVFC_CAN_MIGRATE 0x01
173 u64 node_name;
174 struct srp_direct_buf async;
175 u8 partition_name[IBMVFC_MAX_NAME];
176 u8 device_name[IBMVFC_MAX_NAME];
177 u8 drc_name[IBMVFC_MAX_NAME];
178 u64 reserved2[2];
179}__attribute__((packed, aligned (8)));
180
181struct ibmvfc_common_svc_parms {
182 u16 fcph_version;
183 u16 b2b_credit;
184 u16 features;
185 u16 bb_rcv_sz; /* upper nibble is BB_SC_N */
186 u32 ratov;
187 u32 edtov;
188}__attribute__((packed, aligned (4)));
189
190struct ibmvfc_service_parms {
191 struct ibmvfc_common_svc_parms common;
192 u8 port_name[8];
193 u8 node_name[8];
194 u32 class1_parms[4];
195 u32 class2_parms[4];
196 u32 class3_parms[4];
197 u32 obsolete[4];
198 u32 vendor_version[4];
199 u32 services_avail[2];
200 u32 ext_len;
201 u32 reserved[30];
202 u32 clk_sync_qos[2];
203}__attribute__((packed, aligned (4)));
204
205struct ibmvfc_npiv_login_resp {
206 u32 version;
207 u16 status;
208 u16 error;
209 u32 flags;
210#define IBMVFC_NATIVE_FC 0x01
211#define IBMVFC_CAN_FLUSH_ON_HALT 0x08
212 u32 reserved;
213 u64 capabilities;
214#define IBMVFC_CAN_FLUSH_ON_HALT 0x08
215 u32 max_cmds;
216 u32 scsi_id_sz;
217 u64 max_dma_len;
218 u64 scsi_id;
219 u64 port_name;
220 u64 node_name;
221 u64 link_speed;
222 u8 partition_name[IBMVFC_MAX_NAME];
223 u8 device_name[IBMVFC_MAX_NAME];
224 u8 port_loc_code[IBMVFC_MAX_NAME];
225 u8 drc_name[IBMVFC_MAX_NAME];
226 struct ibmvfc_service_parms service_parms;
227 u64 reserved2;
228}__attribute__((packed, aligned (8)));
229
230union ibmvfc_npiv_login_data {
231 struct ibmvfc_npiv_login login;
232 struct ibmvfc_npiv_login_resp resp;
233}__attribute__((packed, aligned (8)));
234
235struct ibmvfc_discover_targets_buf {
236 u32 scsi_id[1];
237#define IBMVFC_DISC_TGT_SCSI_ID_MASK 0x00ffffff
238};
239
240struct ibmvfc_discover_targets {
241 struct ibmvfc_mad_common common;
242 struct srp_direct_buf buffer;
243 u32 flags;
244 u16 status;
245 u16 error;
246 u32 bufflen;
247 u32 num_avail;
248 u32 num_written;
249 u64 reserved[2];
250}__attribute__((packed, aligned (8)));
251
252enum ibmvfc_fc_reason {
253 IBMVFC_INVALID_ELS_CMD_CODE = 0x01,
254 IBMVFC_INVALID_VERSION = 0x02,
255 IBMVFC_LOGICAL_ERROR = 0x03,
256 IBMVFC_INVALID_CT_IU_SIZE = 0x04,
257 IBMVFC_LOGICAL_BUSY = 0x05,
258 IBMVFC_PROTOCOL_ERROR = 0x07,
259 IBMVFC_UNABLE_TO_PERFORM_REQ = 0x09,
260 IBMVFC_CMD_NOT_SUPPORTED = 0x0B,
261 IBMVFC_SERVER_NOT_AVAIL = 0x0D,
262 IBMVFC_CMD_IN_PROGRESS = 0x0E,
263 IBMVFC_VENDOR_SPECIFIC = 0xFF,
264};
265
266enum ibmvfc_fc_type {
267 IBMVFC_FABRIC_REJECT = 0x01,
268 IBMVFC_PORT_REJECT = 0x02,
269 IBMVFC_LS_REJECT = 0x03,
270 IBMVFC_FABRIC_BUSY = 0x04,
271 IBMVFC_PORT_BUSY = 0x05,
272 IBMVFC_BASIC_REJECT = 0x06,
273};
274
275enum ibmvfc_gs_explain {
276 IBMVFC_PORT_NAME_NOT_REG = 0x02,
277};
278
279struct ibmvfc_port_login {
280 struct ibmvfc_mad_common common;
281 u64 scsi_id;
282 u16 reserved;
283 u16 fc_service_class;
284 u32 blksz;
285 u32 hdr_per_blk;
286 u16 status;
287 u16 error; /* also fc_reason */
288 u16 fc_explain;
289 u16 fc_type;
290 u32 reserved2;
291 struct ibmvfc_service_parms service_parms;
292 struct ibmvfc_service_parms service_parms_change;
293 u64 reserved3[2];
294}__attribute__((packed, aligned (8)));
295
296struct ibmvfc_prli_svc_parms {
297 u8 type;
298#define IBMVFC_SCSI_FCP_TYPE 0x08
299 u8 type_ext;
300 u16 flags;
301#define IBMVFC_PRLI_ORIG_PA_VALID 0x8000
302#define IBMVFC_PRLI_RESP_PA_VALID 0x4000
303#define IBMVFC_PRLI_EST_IMG_PAIR 0x2000
304 u32 orig_pa;
305 u32 resp_pa;
306 u32 service_parms;
307#define IBMVFC_PRLI_TASK_RETRY 0x00000200
308#define IBMVFC_PRLI_RETRY 0x00000100
309#define IBMVFC_PRLI_DATA_OVERLAY 0x00000040
310#define IBMVFC_PRLI_INITIATOR_FUNC 0x00000020
311#define IBMVFC_PRLI_TARGET_FUNC 0x00000010
312#define IBMVFC_PRLI_READ_FCP_XFER_RDY_DISABLED 0x00000002
313#define IBMVFC_PRLI_WR_FCP_XFER_RDY_DISABLED 0x00000001
314}__attribute__((packed, aligned (4)));
315
316struct ibmvfc_process_login {
317 struct ibmvfc_mad_common common;
318 u64 scsi_id;
319 struct ibmvfc_prli_svc_parms parms;
320 u8 reserved[48];
321 u16 status;
322 u16 error; /* also fc_reason */
323 u32 reserved2;
324 u64 reserved3[2];
325}__attribute__((packed, aligned (8)));
326
327struct ibmvfc_query_tgt {
328 struct ibmvfc_mad_common common;
329 u64 wwpn;
330 u64 scsi_id;
331 u16 status;
332 u16 error;
333 u16 fc_explain;
334 u16 fc_type;
335 u64 reserved[2];
336}__attribute__((packed, aligned (8)));
337
338struct ibmvfc_implicit_logout {
339 struct ibmvfc_mad_common common;
340 u64 old_scsi_id;
341 u64 reserved[2];
342}__attribute__((packed, aligned (8)));
343
344struct ibmvfc_tmf {
345 struct ibmvfc_mad_common common;
346 u64 scsi_id;
347 struct scsi_lun lun;
348 u32 flags;
349#define IBMVFC_TMF_ABORT_TASK 0x02
350#define IBMVFC_TMF_ABORT_TASK_SET 0x04
351#define IBMVFC_TMF_LUN_RESET 0x10
352#define IBMVFC_TMF_TGT_RESET 0x20
353#define IBMVFC_TMF_LUA_VALID 0x40
354 u32 cancel_key;
355 u32 my_cancel_key;
356 u32 pad;
357 u64 reserved[2];
358}__attribute__((packed, aligned (8)));
359
360enum ibmvfc_fcp_rsp_info_codes {
361 RSP_NO_FAILURE = 0x00,
362 RSP_TMF_REJECTED = 0x04,
363 RSP_TMF_FAILED = 0x05,
364 RSP_TMF_INVALID_LUN = 0x09,
365};
366
367struct ibmvfc_fcp_rsp_info {
368 u16 reserved;
369 u8 rsp_code;
370 u8 reserved2[4];
371}__attribute__((packed, aligned (2)));
372
373enum ibmvfc_fcp_rsp_flags {
374 FCP_BIDI_RSP = 0x80,
375 FCP_BIDI_READ_RESID_UNDER = 0x40,
376 FCP_BIDI_READ_RESID_OVER = 0x20,
377 FCP_CONF_REQ = 0x10,
378 FCP_RESID_UNDER = 0x08,
379 FCP_RESID_OVER = 0x04,
380 FCP_SNS_LEN_VALID = 0x02,
381 FCP_RSP_LEN_VALID = 0x01,
382};
383
384union ibmvfc_fcp_rsp_data {
385 struct ibmvfc_fcp_rsp_info info;
386 u8 sense[SCSI_SENSE_BUFFERSIZE + sizeof(struct ibmvfc_fcp_rsp_info)];
387}__attribute__((packed, aligned (8)));
388
389struct ibmvfc_fcp_rsp {
390 u64 reserved;
391 u16 retry_delay_timer;
392 u8 flags;
393 u8 scsi_status;
394 u32 fcp_resid;
395 u32 fcp_sense_len;
396 u32 fcp_rsp_len;
397 union ibmvfc_fcp_rsp_data data;
398}__attribute__((packed, aligned (8)));
399
400enum ibmvfc_cmd_flags {
401 IBMVFC_SCATTERLIST = 0x0001,
402 IBMVFC_NO_MEM_DESC = 0x0002,
403 IBMVFC_READ = 0x0004,
404 IBMVFC_WRITE = 0x0008,
405 IBMVFC_TMF = 0x0080,
406 IBMVFC_CLASS_3_ERR = 0x0100,
407};
408
409enum ibmvfc_fc_task_attr {
410 IBMVFC_SIMPLE_TASK = 0x00,
411 IBMVFC_HEAD_OF_QUEUE = 0x01,
412 IBMVFC_ORDERED_TASK = 0x02,
413 IBMVFC_ACA_TASK = 0x04,
414};
415
416enum ibmvfc_fc_tmf_flags {
417 IBMVFC_ABORT_TASK_SET = 0x02,
418 IBMVFC_LUN_RESET = 0x10,
419 IBMVFC_TARGET_RESET = 0x20,
420};
421
422struct ibmvfc_fcp_cmd_iu {
423 struct scsi_lun lun;
424 u8 crn;
425 u8 pri_task_attr;
426 u8 tmf_flags;
427 u8 add_cdb_len;
428#define IBMVFC_RDDATA 0x02
429#define IBMVFC_WRDATA 0x01
430 u8 cdb[IBMVFC_MAX_CDB_LEN];
431 u32 xfer_len;
432}__attribute__((packed, aligned (4)));
433
434struct ibmvfc_cmd {
435 u64 task_tag;
436 u32 frame_type;
437 u32 payload_len;
438 u32 resp_len;
439 u32 adapter_resid;
440 u16 status;
441 u16 error;
442 u16 flags;
443 u16 response_flags;
444#define IBMVFC_ADAPTER_RESID_VALID 0x01
445 u32 cancel_key;
446 u32 exchange_id;
447 struct srp_direct_buf ext_func;
448 struct srp_direct_buf ioba;
449 struct srp_direct_buf resp;
450 u64 correlation;
451 u64 tgt_scsi_id;
452 u64 tag;
453 u64 reserved3[2];
454 struct ibmvfc_fcp_cmd_iu iu;
455 struct ibmvfc_fcp_rsp rsp;
456}__attribute__((packed, aligned (8)));
457
458struct ibmvfc_passthru_fc_iu {
459 u32 payload[7];
460#define IBMVFC_ADISC 0x52000000
461 u32 response[7];
462};
463
464struct ibmvfc_passthru_iu {
465 u64 task_tag;
466 u32 cmd_len;
467 u32 rsp_len;
468 u16 status;
469 u16 error;
470 u32 flags;
471#define IBMVFC_FC_ELS 0x01
472#define IBMVFC_FC_CT_IU 0x02
473 u32 cancel_key;
474#define IBMVFC_PASSTHRU_CANCEL_KEY 0x80000000
475#define IBMVFC_INTERNAL_CANCEL_KEY 0x80000001
476 u32 reserved;
477 struct srp_direct_buf cmd;
478 struct srp_direct_buf rsp;
479 u64 correlation;
480 u64 scsi_id;
481 u64 tag;
482 u64 reserved2[2];
483}__attribute__((packed, aligned (8)));
484
485struct ibmvfc_passthru_mad {
486 struct ibmvfc_mad_common common;
487 struct srp_direct_buf cmd_ioba;
488 struct ibmvfc_passthru_iu iu;
489 struct ibmvfc_passthru_fc_iu fc_iu;
490}__attribute__((packed, aligned (8)));
491
492struct ibmvfc_trace_start_entry {
493 u32 xfer_len;
494}__attribute__((packed));
495
496struct ibmvfc_trace_end_entry {
497 u16 status;
498 u16 error;
499 u8 fcp_rsp_flags;
500 u8 rsp_code;
501 u8 scsi_status;
502 u8 reserved;
503}__attribute__((packed));
504
505struct ibmvfc_trace_entry {
506 struct ibmvfc_event *evt;
507 u32 time;
508 u32 scsi_id;
509 u32 lun;
510 u8 fmt;
511 u8 op_code;
512 u8 tmf_flags;
513 u8 type;
514#define IBMVFC_TRC_START 0x00
515#define IBMVFC_TRC_END 0xff
516 union {
517 struct ibmvfc_trace_start_entry start;
518 struct ibmvfc_trace_end_entry end;
519 } u;
520}__attribute__((packed, aligned (8)));
521
522enum ibmvfc_crq_formats {
523 IBMVFC_CMD_FORMAT = 0x01,
524 IBMVFC_ASYNC_EVENT = 0x02,
525 IBMVFC_MAD_FORMAT = 0x04,
526};
527
528enum ibmvfc_async_event {
529 IBMVFC_AE_ELS_PLOGI = 0x0001,
530 IBMVFC_AE_ELS_LOGO = 0x0002,
531 IBMVFC_AE_ELS_PRLO = 0x0004,
532 IBMVFC_AE_SCN_NPORT = 0x0008,
533 IBMVFC_AE_SCN_GROUP = 0x0010,
534 IBMVFC_AE_SCN_DOMAIN = 0x0020,
535 IBMVFC_AE_SCN_FABRIC = 0x0040,
536 IBMVFC_AE_LINK_UP = 0x0080,
537 IBMVFC_AE_LINK_DOWN = 0x0100,
538 IBMVFC_AE_LINK_DEAD = 0x0200,
539 IBMVFC_AE_HALT = 0x0400,
540 IBMVFC_AE_RESUME = 0x0800,
541 IBMVFC_AE_ADAPTER_FAILED = 0x1000,
542};
543
544struct ibmvfc_async_desc {
545 const char *desc;
546 enum ibmvfc_async_event ae;
547 int log_level;
548};
549
550struct ibmvfc_crq {
551 volatile u8 valid;
552 volatile u8 format;
553 u8 reserved[6];
554 volatile u64 ioba;
555}__attribute__((packed, aligned (8)));
556
557struct ibmvfc_crq_queue {
558 struct ibmvfc_crq *msgs;
559 int size, cur;
560 dma_addr_t msg_token;
561};
562
563enum ibmvfc_ae_link_state {
564 IBMVFC_AE_LS_LINK_UP = 0x01,
565 IBMVFC_AE_LS_LINK_BOUNCED = 0x02,
566 IBMVFC_AE_LS_LINK_DOWN = 0x04,
567 IBMVFC_AE_LS_LINK_DEAD = 0x08,
568};
569
570struct ibmvfc_async_crq {
571 volatile u8 valid;
572 u8 link_state;
573 u8 pad[2];
574 u32 pad2;
575 volatile u64 event;
576 volatile u64 scsi_id;
577 volatile u64 wwpn;
578 volatile u64 node_name;
579 u64 reserved;
580}__attribute__((packed, aligned (8)));
581
582struct ibmvfc_async_crq_queue {
583 struct ibmvfc_async_crq *msgs;
584 int size, cur;
585 dma_addr_t msg_token;
586};
587
588union ibmvfc_iu {
589 struct ibmvfc_mad_common mad_common;
590 struct ibmvfc_npiv_login_mad npiv_login;
591 struct ibmvfc_npiv_logout_mad npiv_logout;
592 struct ibmvfc_discover_targets discover_targets;
593 struct ibmvfc_port_login plogi;
594 struct ibmvfc_process_login prli;
595 struct ibmvfc_query_tgt query_tgt;
596 struct ibmvfc_implicit_logout implicit_logout;
597 struct ibmvfc_tmf tmf;
598 struct ibmvfc_cmd cmd;
599 struct ibmvfc_passthru_mad passthru;
600}__attribute__((packed, aligned (8)));
601
602enum ibmvfc_target_action {
603 IBMVFC_TGT_ACTION_NONE = 0,
604 IBMVFC_TGT_ACTION_INIT,
605 IBMVFC_TGT_ACTION_INIT_WAIT,
606 IBMVFC_TGT_ACTION_DEL_RPORT,
607 IBMVFC_TGT_ACTION_DELETED_RPORT,
608};
609
610struct ibmvfc_target {
611 struct list_head queue;
612 struct ibmvfc_host *vhost;
613 u64 scsi_id;
614 u64 new_scsi_id;
615 struct fc_rport *rport;
616 int target_id;
617 enum ibmvfc_target_action action;
618 int need_login;
619 int add_rport;
620 int init_retries;
621 int logo_rcvd;
622 u32 cancel_key;
623 struct ibmvfc_service_parms service_parms;
624 struct ibmvfc_service_parms service_parms_change;
625 struct fc_rport_identifiers ids;
626 void (*job_step) (struct ibmvfc_target *);
627 struct timer_list timer;
628 struct kref kref;
629};
630
631/* a unit of work for the hosting partition */
632struct ibmvfc_event {
633 struct list_head queue;
634 struct ibmvfc_host *vhost;
635 struct ibmvfc_target *tgt;
636 struct scsi_cmnd *cmnd;
637 atomic_t free;
638 union ibmvfc_iu *xfer_iu;
639 void (*done) (struct ibmvfc_event *);
640 struct ibmvfc_crq crq;
641 union ibmvfc_iu iu;
642 union ibmvfc_iu *sync_iu;
643 struct srp_direct_buf *ext_list;
644 dma_addr_t ext_list_token;
645 struct completion comp;
646 struct completion *eh_comp;
647 struct timer_list timer;
648};
649
650/* a pool of event structs for use */
651struct ibmvfc_event_pool {
652 struct ibmvfc_event *events;
653 u32 size;
654 union ibmvfc_iu *iu_storage;
655 dma_addr_t iu_token;
656};
657
658enum ibmvfc_host_action {
659 IBMVFC_HOST_ACTION_NONE = 0,
660 IBMVFC_HOST_ACTION_RESET,
661 IBMVFC_HOST_ACTION_REENABLE,
662 IBMVFC_HOST_ACTION_LOGO,
663 IBMVFC_HOST_ACTION_LOGO_WAIT,
664 IBMVFC_HOST_ACTION_INIT,
665 IBMVFC_HOST_ACTION_INIT_WAIT,
666 IBMVFC_HOST_ACTION_QUERY,
667 IBMVFC_HOST_ACTION_QUERY_TGTS,
668 IBMVFC_HOST_ACTION_TGT_DEL,
669 IBMVFC_HOST_ACTION_ALLOC_TGTS,
670 IBMVFC_HOST_ACTION_TGT_INIT,
671 IBMVFC_HOST_ACTION_TGT_DEL_FAILED,
672};
673
674enum ibmvfc_host_state {
675 IBMVFC_NO_CRQ = 0,
676 IBMVFC_INITIALIZING,
677 IBMVFC_ACTIVE,
678 IBMVFC_HALTED,
679 IBMVFC_LINK_DOWN,
680 IBMVFC_LINK_DEAD,
681 IBMVFC_HOST_OFFLINE,
682};
683
684struct ibmvfc_host {
685 char name[8];
686 struct list_head queue;
687 struct Scsi_Host *host;
688 enum ibmvfc_host_state state;
689 enum ibmvfc_host_action action;
690#define IBMVFC_NUM_TRACE_INDEX_BITS 8
691#define IBMVFC_NUM_TRACE_ENTRIES (1 << IBMVFC_NUM_TRACE_INDEX_BITS)
692#define IBMVFC_TRACE_SIZE (sizeof(struct ibmvfc_trace_entry) * IBMVFC_NUM_TRACE_ENTRIES)
693 struct ibmvfc_trace_entry *trace;
694 u32 trace_index:IBMVFC_NUM_TRACE_INDEX_BITS;
695 int num_targets;
696 struct list_head targets;
697 struct list_head sent;
698 struct list_head free;
699 struct device *dev;
700 struct ibmvfc_event_pool pool;
701 struct dma_pool *sg_pool;
702 mempool_t *tgt_pool;
703 struct ibmvfc_crq_queue crq;
704 struct ibmvfc_async_crq_queue async_crq;
705 struct ibmvfc_npiv_login login_info;
706 union ibmvfc_npiv_login_data *login_buf;
707 dma_addr_t login_buf_dma;
708 int disc_buf_sz;
709 int log_level;
710 struct ibmvfc_discover_targets_buf *disc_buf;
711 struct mutex passthru_mutex;
712 int task_set;
713 int init_retries;
714 int discovery_threads;
715 int abort_threads;
716 int client_migrated;
717 int reinit;
718 int delay_init;
719 int scan_complete;
720 int logged_in;
721 int aborting_passthru;
722 int events_to_log;
723#define IBMVFC_AE_LINKUP 0x0001
724#define IBMVFC_AE_LINKDOWN 0x0002
725#define IBMVFC_AE_RSCN 0x0004
726 dma_addr_t disc_buf_dma;
727 unsigned int partition_number;
728 char partition_name[97];
729 void (*job_step) (struct ibmvfc_host *);
730 struct task_struct *work_thread;
731 struct tasklet_struct tasklet;
732 struct work_struct rport_add_work_q;
733 wait_queue_head_t init_wait_q;
734 wait_queue_head_t work_wait_q;
735};
736
737#define DBG_CMD(CMD) do { if (ibmvfc_debug) CMD; } while (0)
738
739#define tgt_dbg(t, fmt, ...) \
740 DBG_CMD(dev_info((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__))
741
742#define tgt_info(t, fmt, ...) \
743 dev_info((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
744
745#define tgt_err(t, fmt, ...) \
746 dev_err((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
747
748#define tgt_log(t, level, fmt, ...) \
749 do { \
750 if ((t)->vhost->log_level >= level) \
751 tgt_err(t, fmt, ##__VA_ARGS__); \
752 } while (0)
753
754#define ibmvfc_dbg(vhost, ...) \
755 DBG_CMD(dev_info((vhost)->dev, ##__VA_ARGS__))
756
757#define ibmvfc_log(vhost, level, ...) \
758 do { \
759 if ((vhost)->log_level >= level) \
760 dev_err((vhost)->dev, ##__VA_ARGS__); \
761 } while (0)
762
763#define ENTER DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Entering %s\n", __func__))
764#define LEAVE DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Leaving %s\n", __func__))
765
766#ifdef CONFIG_SCSI_IBMVFC_TRACE
767#define ibmvfc_create_trace_file(kobj, attr) sysfs_create_bin_file(kobj, attr)
768#define ibmvfc_remove_trace_file(kobj, attr) sysfs_remove_bin_file(kobj, attr)
769#else
770#define ibmvfc_create_trace_file(kobj, attr) 0
771#define ibmvfc_remove_trace_file(kobj, attr) do { } while (0)
772#endif
773
774#endif
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * ibmvfc.h -- driver for IBM Power Virtual Fibre Channel Adapter
4 *
5 * Written By: Brian King <brking@linux.vnet.ibm.com>, IBM Corporation
6 *
7 * Copyright (C) IBM Corporation, 2008
8 */
9
10#ifndef _IBMVFC_H
11#define _IBMVFC_H
12
13#include <linux/list.h>
14#include <linux/types.h>
15#include <scsi/viosrp.h>
16
17#define IBMVFC_NAME "ibmvfc"
18#define IBMVFC_DRIVER_VERSION "1.0.11"
19#define IBMVFC_DRIVER_DATE "(April 12, 2013)"
20
21#define IBMVFC_DEFAULT_TIMEOUT 60
22#define IBMVFC_ADISC_CANCEL_TIMEOUT 45
23#define IBMVFC_ADISC_TIMEOUT 15
24#define IBMVFC_ADISC_PLUS_CANCEL_TIMEOUT \
25 (IBMVFC_ADISC_TIMEOUT + IBMVFC_ADISC_CANCEL_TIMEOUT)
26#define IBMVFC_INIT_TIMEOUT 120
27#define IBMVFC_ABORT_TIMEOUT 8
28#define IBMVFC_ABORT_WAIT_TIMEOUT 40
29#define IBMVFC_MAX_REQUESTS_DEFAULT 100
30#define IBMVFC_SCSI_QDEPTH 128
31
32#define IBMVFC_DEBUG 0
33#define IBMVFC_MAX_TARGETS 1024
34#define IBMVFC_MAX_LUN 0xffffffff
35#define IBMVFC_MAX_SECTORS 0xffffu
36#define IBMVFC_MAX_DISC_THREADS 4
37#define IBMVFC_TGT_MEMPOOL_SZ 64
38#define IBMVFC_MAX_CMDS_PER_LUN 64
39#define IBMVFC_MAX_HOST_INIT_RETRIES 6
40#define IBMVFC_MAX_TGT_INIT_RETRIES 3
41#define IBMVFC_DEV_LOSS_TMO (5 * 60)
42#define IBMVFC_DEFAULT_LOG_LEVEL 2
43#define IBMVFC_MAX_CDB_LEN 16
44#define IBMVFC_CLS3_ERROR 0
45#define IBMVFC_MQ 1
46#define IBMVFC_SCSI_CHANNELS 8
47#define IBMVFC_MAX_SCSI_QUEUES 16
48#define IBMVFC_SCSI_HW_QUEUES 8
49#define IBMVFC_MIG_NO_SUB_TO_CRQ 0
50#define IBMVFC_MIG_NO_N_TO_M 0
51
52/*
53 * Ensure we have resources for ERP and initialization:
54 * 1 for ERP
55 * 1 for initialization
56 * 1 for NPIV Logout
57 * 2 for BSG passthru
58 * 2 for each discovery thread
59 */
60#define IBMVFC_NUM_INTERNAL_REQ (1 + 1 + 1 + 2 + (disc_threads * 2))
61/* Reserved suset of events for cancelling channelized IO commands */
62#define IBMVFC_NUM_INTERNAL_SUBQ_REQ 4
63
64#define IBMVFC_MAD_SUCCESS 0x00
65#define IBMVFC_MAD_NOT_SUPPORTED 0xF1
66#define IBMVFC_MAD_VERSION_NOT_SUPP 0xF2
67#define IBMVFC_MAD_FAILED 0xF7
68#define IBMVFC_MAD_DRIVER_FAILED 0xEE
69#define IBMVFC_MAD_CRQ_ERROR 0xEF
70
71enum ibmvfc_crq_valid {
72 IBMVFC_CRQ_CMD_RSP = 0x80,
73 IBMVFC_CRQ_INIT_RSP = 0xC0,
74 IBMVFC_CRQ_XPORT_EVENT = 0xFF,
75};
76
77enum ibmvfc_crq_init_msg {
78 IBMVFC_CRQ_INIT = 0x01,
79 IBMVFC_CRQ_INIT_COMPLETE = 0x02,
80};
81
82enum ibmvfc_crq_xport_evts {
83 IBMVFC_PARTNER_FAILED = 0x01,
84 IBMVFC_PARTNER_DEREGISTER = 0x02,
85 IBMVFC_PARTITION_MIGRATED = 0x06,
86};
87
88enum ibmvfc_cmd_status_flags {
89 IBMVFC_FABRIC_MAPPED = 0x0001,
90 IBMVFC_VIOS_FAILURE = 0x0002,
91 IBMVFC_FC_FAILURE = 0x0004,
92 IBMVFC_FC_SCSI_ERROR = 0x0008,
93 IBMVFC_HW_EVENT_LOGGED = 0x0010,
94 IBMVFC_VIOS_LOGGED = 0x0020,
95};
96
97enum ibmvfc_fabric_mapped_errors {
98 IBMVFC_UNABLE_TO_ESTABLISH = 0x0001,
99 IBMVFC_XPORT_FAULT = 0x0002,
100 IBMVFC_CMD_TIMEOUT = 0x0003,
101 IBMVFC_ENETDOWN = 0x0004,
102 IBMVFC_HW_FAILURE = 0x0005,
103 IBMVFC_LINK_DOWN_ERR = 0x0006,
104 IBMVFC_LINK_DEAD_ERR = 0x0007,
105 IBMVFC_UNABLE_TO_REGISTER = 0x0008,
106 IBMVFC_XPORT_BUSY = 0x000A,
107 IBMVFC_XPORT_DEAD = 0x000B,
108 IBMVFC_CONFIG_ERROR = 0x000C,
109 IBMVFC_NAME_SERVER_FAIL = 0x000D,
110 IBMVFC_LINK_HALTED = 0x000E,
111 IBMVFC_XPORT_GENERAL = 0x8000,
112};
113
114enum ibmvfc_vios_errors {
115 IBMVFC_CRQ_FAILURE = 0x0001,
116 IBMVFC_SW_FAILURE = 0x0002,
117 IBMVFC_INVALID_PARAMETER = 0x0003,
118 IBMVFC_MISSING_PARAMETER = 0x0004,
119 IBMVFC_HOST_IO_BUS = 0x0005,
120 IBMVFC_TRANS_CANCELLED = 0x0006,
121 IBMVFC_TRANS_CANCELLED_IMPLICIT = 0x0007,
122 IBMVFC_INSUFFICIENT_RESOURCE = 0x0008,
123 IBMVFC_PLOGI_REQUIRED = 0x0010,
124 IBMVFC_COMMAND_FAILED = 0x8000,
125};
126
127enum ibmvfc_mad_types {
128 IBMVFC_NPIV_LOGIN = 0x0001,
129 IBMVFC_DISC_TARGETS = 0x0002,
130 IBMVFC_PORT_LOGIN = 0x0004,
131 IBMVFC_PROCESS_LOGIN = 0x0008,
132 IBMVFC_QUERY_TARGET = 0x0010,
133 IBMVFC_MOVE_LOGIN = 0x0020,
134 IBMVFC_IMPLICIT_LOGOUT = 0x0040,
135 IBMVFC_PASSTHRU = 0x0200,
136 IBMVFC_TMF_MAD = 0x0100,
137 IBMVFC_NPIV_LOGOUT = 0x0800,
138 IBMVFC_CHANNEL_ENQUIRY = 0x1000,
139 IBMVFC_CHANNEL_SETUP = 0x2000,
140 IBMVFC_CONNECTION_INFO = 0x4000,
141};
142
143struct ibmvfc_mad_common {
144 __be32 version;
145 __be32 reserved;
146 __be32 opcode;
147 __be16 status;
148 __be16 length;
149 __be64 tag;
150} __packed __aligned(8);
151
152struct ibmvfc_npiv_login_mad {
153 struct ibmvfc_mad_common common;
154 struct srp_direct_buf buffer;
155} __packed __aligned(8);
156
157struct ibmvfc_npiv_logout_mad {
158 struct ibmvfc_mad_common common;
159} __packed __aligned(8);
160
161#define IBMVFC_MAX_NAME 256
162
163struct ibmvfc_npiv_login {
164 __be32 ostype;
165#define IBMVFC_OS_LINUX 0x02
166 __be32 pad;
167 __be64 max_dma_len;
168 __be32 max_payload;
169 __be32 max_response;
170 __be32 partition_num;
171 __be32 vfc_frame_version;
172 __be16 fcp_version;
173 __be16 flags;
174#define IBMVFC_CLIENT_MIGRATED 0x01
175#define IBMVFC_FLUSH_ON_HALT 0x02
176 __be32 max_cmds;
177 __be64 capabilities;
178#define IBMVFC_CAN_MIGRATE 0x01
179#define IBMVFC_CAN_USE_CHANNELS 0x02
180#define IBMVFC_CAN_HANDLE_FPIN 0x04
181#define IBMVFC_CAN_USE_MAD_VERSION 0x08
182#define IBMVFC_CAN_SEND_VF_WWPN 0x10
183 __be64 node_name;
184 struct srp_direct_buf async;
185 u8 partition_name[IBMVFC_MAX_NAME];
186 u8 device_name[IBMVFC_MAX_NAME];
187 u8 drc_name[IBMVFC_MAX_NAME];
188 __be64 reserved2[2];
189} __packed __aligned(8);
190
191struct ibmvfc_common_svc_parms {
192 __be16 fcph_version;
193 __be16 b2b_credit;
194 __be16 features;
195 __be16 bb_rcv_sz; /* upper nibble is BB_SC_N */
196 __be32 ratov;
197 __be32 edtov;
198} __packed __aligned(4);
199
200struct ibmvfc_service_parms {
201 struct ibmvfc_common_svc_parms common;
202 u8 port_name[8];
203 u8 node_name[8];
204 __be32 class1_parms[4];
205 __be32 class2_parms[4];
206 __be32 class3_parms[4];
207 __be32 obsolete[4];
208 __be32 vendor_version[4];
209 __be32 services_avail[2];
210 __be32 ext_len;
211 __be32 reserved[30];
212 __be32 clk_sync_qos[2];
213 __be32 reserved2;
214} __packed __aligned(4);
215
216struct ibmvfc_npiv_login_resp {
217 __be32 version;
218 __be16 status;
219 __be16 error;
220 __be32 flags;
221#define IBMVFC_NATIVE_FC 0x01
222 __be32 reserved;
223 __be64 capabilities;
224#define IBMVFC_CAN_FLUSH_ON_HALT 0x08
225#define IBMVFC_CAN_SUPPRESS_ABTS 0x10
226#define IBMVFC_MAD_VERSION_CAP 0x20
227#define IBMVFC_HANDLE_VF_WWPN 0x40
228#define IBMVFC_CAN_SUPPORT_CHANNELS 0x80
229 __be32 max_cmds;
230 __be32 scsi_id_sz;
231 __be64 max_dma_len;
232 __be64 scsi_id;
233 __be64 port_name;
234 __be64 node_name;
235 __be64 link_speed;
236 u8 partition_name[IBMVFC_MAX_NAME];
237 u8 device_name[IBMVFC_MAX_NAME];
238 u8 port_loc_code[IBMVFC_MAX_NAME];
239 u8 drc_name[IBMVFC_MAX_NAME];
240 struct ibmvfc_service_parms service_parms;
241 __be64 reserved2;
242} __packed __aligned(8);
243
244union ibmvfc_npiv_login_data {
245 struct ibmvfc_npiv_login login;
246 struct ibmvfc_npiv_login_resp resp;
247} __packed __aligned(8);
248
249struct ibmvfc_discover_targets_entry {
250 __be32 scsi_id;
251 __be32 pad;
252 __be64 wwpn;
253#define IBMVFC_DISC_TGT_SCSI_ID_MASK 0x00ffffff
254} __packed __aligned(8);
255
256struct ibmvfc_discover_targets {
257 struct ibmvfc_mad_common common;
258 struct srp_direct_buf buffer;
259 __be32 flags;
260#define IBMVFC_DISC_TGT_PORT_ID_WWPN_LIST 0x02
261 __be16 status;
262 __be16 error;
263 __be32 bufflen;
264 __be32 num_avail;
265 __be32 num_written;
266 __be64 reserved[2];
267} __packed __aligned(8);
268
269enum ibmvfc_fc_reason {
270 IBMVFC_INVALID_ELS_CMD_CODE = 0x01,
271 IBMVFC_INVALID_VERSION = 0x02,
272 IBMVFC_LOGICAL_ERROR = 0x03,
273 IBMVFC_INVALID_CT_IU_SIZE = 0x04,
274 IBMVFC_LOGICAL_BUSY = 0x05,
275 IBMVFC_PROTOCOL_ERROR = 0x07,
276 IBMVFC_UNABLE_TO_PERFORM_REQ = 0x09,
277 IBMVFC_CMD_NOT_SUPPORTED = 0x0B,
278 IBMVFC_SERVER_NOT_AVAIL = 0x0D,
279 IBMVFC_CMD_IN_PROGRESS = 0x0E,
280 IBMVFC_VENDOR_SPECIFIC = 0xFF,
281};
282
283enum ibmvfc_fc_type {
284 IBMVFC_FABRIC_REJECT = 0x01,
285 IBMVFC_PORT_REJECT = 0x02,
286 IBMVFC_LS_REJECT = 0x03,
287 IBMVFC_FABRIC_BUSY = 0x04,
288 IBMVFC_PORT_BUSY = 0x05,
289 IBMVFC_BASIC_REJECT = 0x06,
290};
291
292enum ibmvfc_gs_explain {
293 IBMVFC_PORT_NAME_NOT_REG = 0x02,
294};
295
296struct ibmvfc_port_login {
297 struct ibmvfc_mad_common common;
298 __be64 scsi_id;
299 __be16 reserved;
300 __be16 fc_service_class;
301 __be32 blksz;
302 __be32 hdr_per_blk;
303 __be16 status;
304 __be16 error; /* also fc_reason */
305 __be16 fc_explain;
306 __be16 fc_type;
307 __be32 reserved2;
308 struct ibmvfc_service_parms service_parms;
309 struct ibmvfc_service_parms service_parms_change;
310 __be64 target_wwpn;
311 __be64 reserved3[2];
312} __packed __aligned(8);
313
314struct ibmvfc_move_login {
315 struct ibmvfc_mad_common common;
316 __be64 old_scsi_id;
317 __be64 new_scsi_id;
318 __be64 wwpn;
319 __be64 node_name;
320 __be32 flags;
321#define IBMVFC_MOVE_LOGIN_IMPLICIT_OLD_FAILED 0x01
322#define IBMVFC_MOVE_LOGIN_IMPLICIT_NEW_FAILED 0x02
323#define IBMVFC_MOVE_LOGIN_PORT_LOGIN_FAILED 0x04
324 __be32 reserved;
325 struct ibmvfc_service_parms service_parms;
326 struct ibmvfc_service_parms service_parms_change;
327 __be32 reserved2;
328 __be16 service_class;
329 __be16 vios_flags;
330#define IBMVFC_MOVE_LOGIN_VF_NOT_SENT_ADAPTER 0x01
331 __be64 reserved3;
332} __packed __aligned(8);
333
334struct ibmvfc_prli_svc_parms {
335 u8 type;
336#define IBMVFC_SCSI_FCP_TYPE 0x08
337 u8 type_ext;
338 __be16 flags;
339#define IBMVFC_PRLI_ORIG_PA_VALID 0x8000
340#define IBMVFC_PRLI_RESP_PA_VALID 0x4000
341#define IBMVFC_PRLI_EST_IMG_PAIR 0x2000
342 __be32 orig_pa;
343 __be32 resp_pa;
344 __be32 service_parms;
345#define IBMVFC_PRLI_TASK_RETRY 0x00000200
346#define IBMVFC_PRLI_RETRY 0x00000100
347#define IBMVFC_PRLI_DATA_OVERLAY 0x00000040
348#define IBMVFC_PRLI_INITIATOR_FUNC 0x00000020
349#define IBMVFC_PRLI_TARGET_FUNC 0x00000010
350#define IBMVFC_PRLI_READ_FCP_XFER_RDY_DISABLED 0x00000002
351#define IBMVFC_PRLI_WR_FCP_XFER_RDY_DISABLED 0x00000001
352} __packed __aligned(4);
353
354struct ibmvfc_process_login {
355 struct ibmvfc_mad_common common;
356 __be64 scsi_id;
357 struct ibmvfc_prli_svc_parms parms;
358 u8 reserved[48];
359 __be16 status;
360 __be16 error; /* also fc_reason */
361 __be32 reserved2;
362 __be64 target_wwpn;
363 __be64 reserved3[2];
364} __packed __aligned(8);
365
366struct ibmvfc_query_tgt {
367 struct ibmvfc_mad_common common;
368 __be64 wwpn;
369 __be64 scsi_id;
370 __be16 status;
371 __be16 error;
372 __be16 fc_explain;
373 __be16 fc_type;
374 __be64 reserved[2];
375} __packed __aligned(8);
376
377struct ibmvfc_implicit_logout {
378 struct ibmvfc_mad_common common;
379 __be64 old_scsi_id;
380 __be64 reserved[2];
381} __packed __aligned(8);
382
383struct ibmvfc_tmf {
384 struct ibmvfc_mad_common common;
385 __be64 scsi_id;
386 struct scsi_lun lun;
387 __be32 flags;
388#define IBMVFC_TMF_ABORT_TASK 0x02
389#define IBMVFC_TMF_ABORT_TASK_SET 0x04
390#define IBMVFC_TMF_LUN_RESET 0x10
391#define IBMVFC_TMF_TGT_RESET 0x20
392#define IBMVFC_TMF_LUA_VALID 0x40
393#define IBMVFC_TMF_SUPPRESS_ABTS 0x80
394 __be32 cancel_key;
395 __be32 my_cancel_key;
396 __be32 pad;
397 __be64 target_wwpn;
398 __be64 task_tag;
399 __be64 reserved[2];
400} __packed __aligned(8);
401
402enum ibmvfc_fcp_rsp_info_codes {
403 RSP_NO_FAILURE = 0x00,
404 RSP_TMF_REJECTED = 0x04,
405 RSP_TMF_FAILED = 0x05,
406 RSP_TMF_INVALID_LUN = 0x09,
407};
408
409struct ibmvfc_fcp_rsp_info {
410 u8 reserved[3];
411 u8 rsp_code;
412 u8 reserved2[4];
413} __packed __aligned(2);
414
415enum ibmvfc_fcp_rsp_flags {
416 FCP_BIDI_RSP = 0x80,
417 FCP_BIDI_READ_RESID_UNDER = 0x40,
418 FCP_BIDI_READ_RESID_OVER = 0x20,
419 FCP_CONF_REQ = 0x10,
420 FCP_RESID_UNDER = 0x08,
421 FCP_RESID_OVER = 0x04,
422 FCP_SNS_LEN_VALID = 0x02,
423 FCP_RSP_LEN_VALID = 0x01,
424};
425
426union ibmvfc_fcp_rsp_data {
427 struct ibmvfc_fcp_rsp_info info;
428 u8 sense[SCSI_SENSE_BUFFERSIZE + sizeof(struct ibmvfc_fcp_rsp_info)];
429} __packed __aligned(8);
430
431struct ibmvfc_fcp_rsp {
432 __be64 reserved;
433 __be16 retry_delay_timer;
434 u8 flags;
435 u8 scsi_status;
436 __be32 fcp_resid;
437 __be32 fcp_sense_len;
438 __be32 fcp_rsp_len;
439 union ibmvfc_fcp_rsp_data data;
440} __packed __aligned(8);
441
442enum ibmvfc_cmd_flags {
443 IBMVFC_SCATTERLIST = 0x0001,
444 IBMVFC_NO_MEM_DESC = 0x0002,
445 IBMVFC_READ = 0x0004,
446 IBMVFC_WRITE = 0x0008,
447 IBMVFC_TMF = 0x0080,
448 IBMVFC_CLASS_3_ERR = 0x0100,
449};
450
451enum ibmvfc_fc_task_attr {
452 IBMVFC_SIMPLE_TASK = 0x00,
453 IBMVFC_HEAD_OF_QUEUE = 0x01,
454 IBMVFC_ORDERED_TASK = 0x02,
455 IBMVFC_ACA_TASK = 0x04,
456};
457
458enum ibmvfc_fc_tmf_flags {
459 IBMVFC_ABORT_TASK_SET = 0x02,
460 IBMVFC_LUN_RESET = 0x10,
461 IBMVFC_TARGET_RESET = 0x20,
462};
463
464struct ibmvfc_fcp_cmd_iu {
465 struct scsi_lun lun;
466 u8 crn;
467 u8 pri_task_attr;
468 u8 tmf_flags;
469 u8 add_cdb_len;
470#define IBMVFC_RDDATA 0x02
471#define IBMVFC_WRDATA 0x01
472 u8 cdb[IBMVFC_MAX_CDB_LEN];
473 __be32 xfer_len;
474} __packed __aligned(4);
475
476struct ibmvfc_cmd {
477 __be64 task_tag;
478 __be32 frame_type;
479 __be32 payload_len;
480 __be32 resp_len;
481 __be32 adapter_resid;
482 __be16 status;
483 __be16 error;
484 __be16 flags;
485 __be16 response_flags;
486#define IBMVFC_ADAPTER_RESID_VALID 0x01
487 __be32 cancel_key;
488 __be32 exchange_id;
489 struct srp_direct_buf ext_func;
490 struct srp_direct_buf ioba;
491 struct srp_direct_buf resp;
492 __be64 correlation;
493 __be64 tgt_scsi_id;
494 __be64 tag;
495 __be64 target_wwpn;
496 __be64 reserved3;
497 union {
498 struct {
499 struct ibmvfc_fcp_cmd_iu iu;
500 struct ibmvfc_fcp_rsp rsp;
501 } v1;
502 struct {
503 __be64 reserved4;
504 struct ibmvfc_fcp_cmd_iu iu;
505 struct ibmvfc_fcp_rsp rsp;
506 } v2;
507 };
508} __packed __aligned(8);
509
510struct ibmvfc_passthru_fc_iu {
511 __be32 payload[7];
512#define IBMVFC_ADISC 0x52000000
513 __be32 response[7];
514};
515
516struct ibmvfc_passthru_iu {
517 __be64 task_tag;
518 __be32 cmd_len;
519 __be32 rsp_len;
520 __be16 status;
521 __be16 error;
522 __be32 flags;
523#define IBMVFC_FC_ELS 0x01
524#define IBMVFC_FC_CT_IU 0x02
525 __be32 cancel_key;
526#define IBMVFC_PASSTHRU_CANCEL_KEY 0x80000000
527#define IBMVFC_INTERNAL_CANCEL_KEY 0x80000001
528 __be32 reserved;
529 struct srp_direct_buf cmd;
530 struct srp_direct_buf rsp;
531 __be64 correlation;
532 __be64 scsi_id;
533 __be64 tag;
534 __be64 target_wwpn;
535 __be64 reserved2[2];
536} __packed __aligned(8);
537
538struct ibmvfc_passthru_mad {
539 struct ibmvfc_mad_common common;
540 struct srp_direct_buf cmd_ioba;
541 struct ibmvfc_passthru_iu iu;
542 struct ibmvfc_passthru_fc_iu fc_iu;
543} __packed __aligned(8);
544
545struct ibmvfc_channel_enquiry {
546 struct ibmvfc_mad_common common;
547 __be32 flags;
548#define IBMVFC_NO_CHANNELS_TO_CRQ_SUPPORT 0x01
549#define IBMVFC_SUPPORT_VARIABLE_SUBQ_MSG 0x02
550#define IBMVFC_NO_N_TO_M_CHANNELS_SUPPORT 0x04
551 __be32 num_scsi_subq_channels;
552 __be32 num_nvmeof_subq_channels;
553 __be32 num_scsi_vas_channels;
554 __be32 num_nvmeof_vas_channels;
555} __packed __aligned(8);
556
557struct ibmvfc_channel_setup_mad {
558 struct ibmvfc_mad_common common;
559 struct srp_direct_buf buffer;
560} __packed __aligned(8);
561
562#define IBMVFC_MAX_CHANNELS 502
563
564struct ibmvfc_channel_setup {
565 __be32 flags;
566#define IBMVFC_CANCEL_CHANNELS 0x01
567#define IBMVFC_USE_BUFFER 0x02
568#define IBMVFC_CHANNELS_CANCELED 0x04
569 __be32 reserved;
570 __be32 num_scsi_subq_channels;
571 __be32 num_nvmeof_subq_channels;
572 __be32 num_scsi_vas_channels;
573 __be32 num_nvmeof_vas_channels;
574 struct srp_direct_buf buffer;
575 __be64 reserved2[5];
576 __be64 channel_handles[IBMVFC_MAX_CHANNELS];
577} __packed __aligned(8);
578
579struct ibmvfc_connection_info {
580 struct ibmvfc_mad_common common;
581 __be64 information_bits;
582#define IBMVFC_NO_FC_IO_CHANNEL 0x01
583#define IBMVFC_NO_PHYP_VAS 0x02
584#define IBMVFC_NO_PHYP_SUBQ 0x04
585#define IBMVFC_PHYP_DEPRECATED_SUBQ 0x08
586#define IBMVFC_PHYP_PRESERVED_SUBQ 0x10
587#define IBMVFC_PHYP_FULL_SUBQ 0x20
588 __be64 reserved[16];
589} __packed __aligned(8);
590
591struct ibmvfc_trace_start_entry {
592 u32 xfer_len;
593} __packed;
594
595struct ibmvfc_trace_end_entry {
596 u16 status;
597 u16 error;
598 u8 fcp_rsp_flags;
599 u8 rsp_code;
600 u8 scsi_status;
601 u8 reserved;
602} __packed;
603
604struct ibmvfc_trace_entry {
605 struct ibmvfc_event *evt;
606 u32 time;
607 u32 scsi_id;
608 u32 lun;
609 u8 fmt;
610 u8 op_code;
611 u8 tmf_flags;
612 u8 type;
613#define IBMVFC_TRC_START 0x00
614#define IBMVFC_TRC_END 0xff
615 union {
616 struct ibmvfc_trace_start_entry start;
617 struct ibmvfc_trace_end_entry end;
618 } u;
619} __packed __aligned(8);
620
621enum ibmvfc_crq_formats {
622 IBMVFC_CMD_FORMAT = 0x01,
623 IBMVFC_ASYNC_EVENT = 0x02,
624 IBMVFC_MAD_FORMAT = 0x04,
625};
626
627enum ibmvfc_async_event {
628 IBMVFC_AE_ELS_PLOGI = 0x0001,
629 IBMVFC_AE_ELS_LOGO = 0x0002,
630 IBMVFC_AE_ELS_PRLO = 0x0004,
631 IBMVFC_AE_SCN_NPORT = 0x0008,
632 IBMVFC_AE_SCN_GROUP = 0x0010,
633 IBMVFC_AE_SCN_DOMAIN = 0x0020,
634 IBMVFC_AE_SCN_FABRIC = 0x0040,
635 IBMVFC_AE_LINK_UP = 0x0080,
636 IBMVFC_AE_LINK_DOWN = 0x0100,
637 IBMVFC_AE_LINK_DEAD = 0x0200,
638 IBMVFC_AE_HALT = 0x0400,
639 IBMVFC_AE_RESUME = 0x0800,
640 IBMVFC_AE_ADAPTER_FAILED = 0x1000,
641 IBMVFC_AE_FPIN = 0x2000,
642};
643
644struct ibmvfc_async_desc {
645 const char *desc;
646 enum ibmvfc_async_event ae;
647 int log_level;
648};
649
650struct ibmvfc_crq {
651 volatile u8 valid;
652 volatile u8 format;
653 u8 reserved[6];
654 volatile __be64 ioba;
655} __packed __aligned(8);
656
657struct ibmvfc_sub_crq {
658 struct ibmvfc_crq crq;
659 __be64 reserved[2];
660} __packed __aligned(8);
661
662enum ibmvfc_ae_link_state {
663 IBMVFC_AE_LS_LINK_UP = 0x01,
664 IBMVFC_AE_LS_LINK_BOUNCED = 0x02,
665 IBMVFC_AE_LS_LINK_DOWN = 0x04,
666 IBMVFC_AE_LS_LINK_DEAD = 0x08,
667};
668
669enum ibmvfc_ae_fpin_status {
670 IBMVFC_AE_FPIN_LINK_CONGESTED = 0x1,
671 IBMVFC_AE_FPIN_PORT_CONGESTED = 0x2,
672 IBMVFC_AE_FPIN_PORT_CLEARED = 0x3,
673 IBMVFC_AE_FPIN_PORT_DEGRADED = 0x4,
674};
675
676struct ibmvfc_async_crq {
677 volatile u8 valid;
678 u8 link_state;
679 u8 fpin_status;
680 u8 pad;
681 __be32 pad2;
682 volatile __be64 event;
683 volatile __be64 scsi_id;
684 volatile __be64 wwpn;
685 volatile __be64 node_name;
686 __be64 reserved;
687} __packed __aligned(8);
688
689union ibmvfc_iu {
690 struct ibmvfc_mad_common mad_common;
691 struct ibmvfc_npiv_login_mad npiv_login;
692 struct ibmvfc_npiv_logout_mad npiv_logout;
693 struct ibmvfc_discover_targets discover_targets;
694 struct ibmvfc_port_login plogi;
695 struct ibmvfc_process_login prli;
696 struct ibmvfc_move_login move_login;
697 struct ibmvfc_query_tgt query_tgt;
698 struct ibmvfc_implicit_logout implicit_logout;
699 struct ibmvfc_tmf tmf;
700 struct ibmvfc_cmd cmd;
701 struct ibmvfc_passthru_mad passthru;
702 struct ibmvfc_channel_enquiry channel_enquiry;
703 struct ibmvfc_channel_setup_mad channel_setup;
704 struct ibmvfc_connection_info connection_info;
705} __packed __aligned(8);
706
707enum ibmvfc_target_action {
708 IBMVFC_TGT_ACTION_NONE = 0,
709 IBMVFC_TGT_ACTION_INIT,
710 IBMVFC_TGT_ACTION_INIT_WAIT,
711 IBMVFC_TGT_ACTION_LOGOUT_RPORT,
712 IBMVFC_TGT_ACTION_LOGOUT_RPORT_WAIT,
713 IBMVFC_TGT_ACTION_DEL_RPORT,
714 IBMVFC_TGT_ACTION_DELETED_RPORT,
715 IBMVFC_TGT_ACTION_DEL_AND_LOGOUT_RPORT,
716 IBMVFC_TGT_ACTION_LOGOUT_DELETED_RPORT,
717};
718
719enum ibmvfc_protocol {
720 IBMVFC_PROTO_SCSI = 0,
721 IBMVFC_PROTO_NVME = 1,
722};
723
724struct ibmvfc_target {
725 struct list_head queue;
726 struct ibmvfc_host *vhost;
727 enum ibmvfc_protocol protocol;
728 u64 scsi_id;
729 u64 wwpn;
730 u64 new_scsi_id;
731 struct fc_rport *rport;
732 int target_id;
733 enum ibmvfc_target_action action;
734 int need_login;
735 int add_rport;
736 int init_retries;
737 int logo_rcvd;
738 int move_login;
739 u32 cancel_key;
740 struct ibmvfc_service_parms service_parms;
741 struct ibmvfc_service_parms service_parms_change;
742 struct fc_rport_identifiers ids;
743 void (*job_step) (struct ibmvfc_target *);
744 struct timer_list timer;
745 struct kref kref;
746};
747
748/* a unit of work for the hosting partition */
749struct ibmvfc_event {
750 struct list_head queue_list;
751 struct list_head cancel;
752 struct ibmvfc_host *vhost;
753 struct ibmvfc_queue *queue;
754 struct ibmvfc_target *tgt;
755 struct scsi_cmnd *cmnd;
756 atomic_t free;
757 atomic_t active;
758 union ibmvfc_iu *xfer_iu;
759 void (*done)(struct ibmvfc_event *evt);
760 void (*_done)(struct ibmvfc_event *evt);
761 struct ibmvfc_crq crq;
762 union ibmvfc_iu iu;
763 union ibmvfc_iu *sync_iu;
764 struct srp_direct_buf *ext_list;
765 dma_addr_t ext_list_token;
766 struct completion comp;
767 struct completion *eh_comp;
768 struct timer_list timer;
769 u16 hwq;
770 u8 reserved;
771};
772
773/* a pool of event structs for use */
774struct ibmvfc_event_pool {
775 struct ibmvfc_event *events;
776 u32 size;
777 union ibmvfc_iu *iu_storage;
778 dma_addr_t iu_token;
779};
780
781enum ibmvfc_msg_fmt {
782 IBMVFC_CRQ_FMT = 0,
783 IBMVFC_ASYNC_FMT,
784 IBMVFC_SUB_CRQ_FMT,
785};
786
787union ibmvfc_msgs {
788 void *handle;
789 struct ibmvfc_crq *crq;
790 struct ibmvfc_async_crq *async;
791 struct ibmvfc_sub_crq *scrq;
792};
793
794struct ibmvfc_queue {
795 union ibmvfc_msgs msgs;
796 dma_addr_t msg_token;
797 enum ibmvfc_msg_fmt fmt;
798 int size, cur;
799 spinlock_t _lock;
800 spinlock_t *q_lock;
801
802 struct ibmvfc_host *vhost;
803 struct ibmvfc_event_pool evt_pool;
804 struct list_head sent;
805 struct list_head free;
806 u16 total_depth;
807 u16 evt_depth;
808 u16 reserved_depth;
809 u16 evt_free;
810 u16 reserved_free;
811 spinlock_t l_lock;
812
813 union ibmvfc_iu cancel_rsp;
814
815 /* Sub-CRQ fields */
816 unsigned long cookie;
817 unsigned long vios_cookie;
818 unsigned long hw_irq;
819 unsigned long irq;
820 unsigned long hwq_id;
821 char name[32];
822 irq_handler_t handler;
823};
824
825struct ibmvfc_channels {
826 struct ibmvfc_queue *scrqs;
827 enum ibmvfc_protocol protocol;
828 unsigned int active_queues;
829 unsigned int desired_queues;
830 unsigned int max_queues;
831 int disc_buf_sz;
832 struct ibmvfc_discover_targets_entry *disc_buf;
833 dma_addr_t disc_buf_dma;
834};
835
836enum ibmvfc_host_action {
837 IBMVFC_HOST_ACTION_NONE = 0,
838 IBMVFC_HOST_ACTION_RESET,
839 IBMVFC_HOST_ACTION_REENABLE,
840 IBMVFC_HOST_ACTION_LOGO,
841 IBMVFC_HOST_ACTION_LOGO_WAIT,
842 IBMVFC_HOST_ACTION_INIT,
843 IBMVFC_HOST_ACTION_INIT_WAIT,
844 IBMVFC_HOST_ACTION_QUERY,
845 IBMVFC_HOST_ACTION_QUERY_TGTS,
846 IBMVFC_HOST_ACTION_TGT_DEL,
847 IBMVFC_HOST_ACTION_ALLOC_TGTS,
848 IBMVFC_HOST_ACTION_TGT_INIT,
849 IBMVFC_HOST_ACTION_TGT_DEL_FAILED,
850};
851
852enum ibmvfc_host_state {
853 IBMVFC_NO_CRQ = 0,
854 IBMVFC_INITIALIZING,
855 IBMVFC_ACTIVE,
856 IBMVFC_HALTED,
857 IBMVFC_LINK_DOWN,
858 IBMVFC_LINK_DEAD,
859 IBMVFC_HOST_OFFLINE,
860};
861
862struct ibmvfc_host {
863 char name[8];
864 struct list_head queue;
865 struct Scsi_Host *host;
866 enum ibmvfc_host_state state;
867 enum ibmvfc_host_action action;
868#define IBMVFC_NUM_TRACE_INDEX_BITS 8
869#define IBMVFC_NUM_TRACE_ENTRIES (1 << IBMVFC_NUM_TRACE_INDEX_BITS)
870#define IBMVFC_TRACE_INDEX_MASK (IBMVFC_NUM_TRACE_ENTRIES - 1)
871#define IBMVFC_TRACE_SIZE (sizeof(struct ibmvfc_trace_entry) * IBMVFC_NUM_TRACE_ENTRIES)
872 struct ibmvfc_trace_entry *trace;
873 atomic_t trace_index;
874 int num_targets;
875 struct list_head targets;
876 struct list_head purge;
877 struct device *dev;
878 struct dma_pool *sg_pool;
879 mempool_t *tgt_pool;
880 struct ibmvfc_queue crq;
881 struct ibmvfc_queue async_crq;
882 struct ibmvfc_channels scsi_scrqs;
883 struct ibmvfc_npiv_login login_info;
884 union ibmvfc_npiv_login_data *login_buf;
885 dma_addr_t login_buf_dma;
886 struct ibmvfc_channel_setup *channel_setup_buf;
887 dma_addr_t channel_setup_dma;
888 int log_level;
889 struct mutex passthru_mutex;
890 unsigned int max_vios_scsi_channels;
891 int task_set;
892 int init_retries;
893 int discovery_threads;
894 int abort_threads;
895 unsigned int client_migrated:1;
896 unsigned int reinit:1;
897 unsigned int delay_init:1;
898 unsigned int logged_in:1;
899 unsigned int mq_enabled:1;
900 unsigned int using_channels:1;
901 unsigned int do_enquiry:1;
902 unsigned int aborting_passthru:1;
903 unsigned int scan_complete:1;
904 int scan_timeout;
905 int events_to_log;
906#define IBMVFC_AE_LINKUP 0x0001
907#define IBMVFC_AE_LINKDOWN 0x0002
908#define IBMVFC_AE_RSCN 0x0004
909 unsigned int partition_number;
910 char partition_name[97];
911 void (*job_step) (struct ibmvfc_host *);
912 struct task_struct *work_thread;
913 struct tasklet_struct tasklet;
914 struct work_struct rport_add_work_q;
915 wait_queue_head_t init_wait_q;
916 wait_queue_head_t work_wait_q;
917};
918
919#define DBG_CMD(CMD) do { if (ibmvfc_debug) CMD; } while (0)
920
921#define tgt_dbg(t, fmt, ...) \
922 DBG_CMD(dev_info((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__))
923
924#define tgt_info(t, fmt, ...) \
925 dev_info((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
926
927#define tgt_err(t, fmt, ...) \
928 dev_err((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
929
930#define tgt_log(t, level, fmt, ...) \
931 do { \
932 if ((t)->vhost->log_level >= level) \
933 tgt_err(t, fmt, ##__VA_ARGS__); \
934 } while (0)
935
936#define ibmvfc_dbg(vhost, ...) \
937 DBG_CMD(dev_info((vhost)->dev, ##__VA_ARGS__))
938
939#define ibmvfc_log(vhost, level, ...) \
940 do { \
941 if ((vhost)->log_level >= level) \
942 dev_err((vhost)->dev, ##__VA_ARGS__); \
943 } while (0)
944
945#define ENTER DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Entering %s\n", __func__))
946#define LEAVE DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Leaving %s\n", __func__))
947
948#ifdef CONFIG_SCSI_IBMVFC_TRACE
949#define ibmvfc_create_trace_file(kobj, attr) sysfs_create_bin_file(kobj, attr)
950#define ibmvfc_remove_trace_file(kobj, attr) sysfs_remove_bin_file(kobj, attr)
951#else
952#define ibmvfc_create_trace_file(kobj, attr) 0
953#define ibmvfc_remove_trace_file(kobj, attr) do { } while (0)
954#endif
955
956#endif