xref: /openbmc/linux/drivers/s390/scsi/zfcp_def.h (revision 553448f6)
11da177e4SLinus Torvalds /*
2553448f6SChristof Schmitt  * zfcp device driver
31da177e4SLinus Torvalds  *
4553448f6SChristof Schmitt  * Global definitions for the zfcp device driver.
51da177e4SLinus Torvalds  *
6553448f6SChristof Schmitt  * Copyright IBM Corporation 2002, 2008
71da177e4SLinus Torvalds  */
81da177e4SLinus Torvalds 
91da177e4SLinus Torvalds #ifndef ZFCP_DEF_H
101da177e4SLinus Torvalds #define ZFCP_DEF_H
111da177e4SLinus Torvalds 
121da177e4SLinus Torvalds /*************************** INCLUDES *****************************************/
131da177e4SLinus Torvalds 
141da177e4SLinus Torvalds #include <linux/init.h>
151da177e4SLinus Torvalds #include <linux/moduleparam.h>
161da177e4SLinus Torvalds #include <linux/major.h>
171da177e4SLinus Torvalds #include <linux/blkdev.h>
181da177e4SLinus Torvalds #include <linux/delay.h>
191da177e4SLinus Torvalds #include <linux/timer.h>
20dd52e0eaSHeiko Carstens #include <linux/slab.h>
21dd52e0eaSHeiko Carstens #include <linux/mempool.h>
22dd52e0eaSHeiko Carstens #include <linux/syscalls.h>
23f1346372SFUJITA Tomonori #include <linux/scatterlist.h>
24dd52e0eaSHeiko Carstens #include <linux/ioctl.h>
251da177e4SLinus Torvalds #include <scsi/scsi.h>
261da177e4SLinus Torvalds #include <scsi/scsi_tcq.h>
271da177e4SLinus Torvalds #include <scsi/scsi_cmnd.h>
281da177e4SLinus Torvalds #include <scsi/scsi_device.h>
291da177e4SLinus Torvalds #include <scsi/scsi_host.h>
301da177e4SLinus Torvalds #include <scsi/scsi_transport.h>
311da177e4SLinus Torvalds #include <scsi/scsi_transport_fc.h>
321da177e4SLinus Torvalds #include <asm/ccwdev.h>
331da177e4SLinus Torvalds #include <asm/qdio.h>
341da177e4SLinus Torvalds #include <asm/debug.h>
351da177e4SLinus Torvalds #include <asm/ebcdic.h>
362b604c9bSChristof Schmitt #include "zfcp_dbf.h"
37dd52e0eaSHeiko Carstens #include "zfcp_fsf.h"
381da177e4SLinus Torvalds 
391da177e4SLinus Torvalds 
401da177e4SLinus Torvalds /********************* GENERAL DEFINES *********************************/
411da177e4SLinus Torvalds 
421da177e4SLinus Torvalds /**
431da177e4SLinus Torvalds  * zfcp_sg_to_address - determine kernel address from struct scatterlist
441da177e4SLinus Torvalds  * @list: struct scatterlist
451da177e4SLinus Torvalds  * Return: kernel address
461da177e4SLinus Torvalds  */
471da177e4SLinus Torvalds static inline void *
481da177e4SLinus Torvalds zfcp_sg_to_address(struct scatterlist *list)
491da177e4SLinus Torvalds {
5073fc4f0dSJens Axboe 	return sg_virt(list);
511da177e4SLinus Torvalds }
521da177e4SLinus Torvalds 
531da177e4SLinus Torvalds /**
541da177e4SLinus Torvalds  * zfcp_address_to_sg - set up struct scatterlist from kernel address
551da177e4SLinus Torvalds  * @address: kernel address
561da177e4SLinus Torvalds  * @list: struct scatterlist
5793354329SJens Axboe  * @size: buffer size
581da177e4SLinus Torvalds  */
591da177e4SLinus Torvalds static inline void
6093354329SJens Axboe zfcp_address_to_sg(void *address, struct scatterlist *list, unsigned int size)
611da177e4SLinus Torvalds {
6293354329SJens Axboe 	sg_set_buf(list, address, size);
631da177e4SLinus Torvalds }
641da177e4SLinus Torvalds 
6506506d00SAndreas Herrmann #define REQUEST_LIST_SIZE 128
6606506d00SAndreas Herrmann 
671da177e4SLinus Torvalds /********************* SCSI SPECIFIC DEFINES *********************************/
68f6c0e7a7SAndreas Herrmann #define ZFCP_SCSI_ER_TIMEOUT                    (10*HZ)
691da177e4SLinus Torvalds 
701da177e4SLinus Torvalds /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
711da177e4SLinus Torvalds 
721da177e4SLinus Torvalds /* Adapter Identification Parameters */
731da177e4SLinus Torvalds #define ZFCP_CONTROL_UNIT_TYPE  0x1731
741da177e4SLinus Torvalds #define ZFCP_CONTROL_UNIT_MODEL 0x03
751da177e4SLinus Torvalds #define ZFCP_DEVICE_TYPE        0x1732
761da177e4SLinus Torvalds #define ZFCP_DEVICE_MODEL       0x03
771da177e4SLinus Torvalds #define ZFCP_DEVICE_MODEL_PRIV	0x04
781da177e4SLinus Torvalds 
791da177e4SLinus Torvalds /* allow as many chained SBALs as are supported by hardware */
801da177e4SLinus Torvalds #define ZFCP_MAX_SBALS_PER_REQ		FSF_MAX_SBALS_PER_REQ
811da177e4SLinus Torvalds #define ZFCP_MAX_SBALS_PER_CT_REQ	FSF_MAX_SBALS_PER_REQ
821da177e4SLinus Torvalds #define ZFCP_MAX_SBALS_PER_ELS_REQ	FSF_MAX_SBALS_PER_ELS_REQ
831da177e4SLinus Torvalds 
841da177e4SLinus Torvalds /* DMQ bug workaround: don't use last SBALE */
851da177e4SLinus Torvalds #define ZFCP_MAX_SBALES_PER_SBAL	(QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
861da177e4SLinus Torvalds 
871da177e4SLinus Torvalds /* index of last SBALE (with respect to DMQ bug workaround) */
881da177e4SLinus Torvalds #define ZFCP_LAST_SBALE_PER_SBAL	(ZFCP_MAX_SBALES_PER_SBAL - 1)
891da177e4SLinus Torvalds 
901da177e4SLinus Torvalds /* max. number of (data buffer) SBALEs in largest SBAL chain */
911da177e4SLinus Torvalds #define ZFCP_MAX_SBALES_PER_REQ		\
921da177e4SLinus Torvalds 	(ZFCP_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
931da177e4SLinus Torvalds         /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
941da177e4SLinus Torvalds 
958d1a0060SSwen Schillig #define ZFCP_MAX_SECTORS (ZFCP_MAX_SBALES_PER_REQ * 8)
968d1a0060SSwen Schillig         /* max. number of (data buffer) SBALEs in largest SBAL chain
978d1a0060SSwen Schillig            multiplied with number of sectors per 4k block */
988d1a0060SSwen Schillig 
991da177e4SLinus Torvalds #define ZFCP_SBAL_TIMEOUT               (5*HZ)
1001da177e4SLinus Torvalds 
10118edcdbdSChristof Schmitt #define ZFCP_TYPE2_RECOVERY_TIME        8	/* seconds */
1021da177e4SLinus Torvalds 
103b4e44590SSwen Schillig #define QBUFF_PER_PAGE			(PAGE_SIZE / sizeof(struct qdio_buffer))
1041da177e4SLinus Torvalds 
1051da177e4SLinus Torvalds /********************* FSF SPECIFIC DEFINES *********************************/
1061da177e4SLinus Torvalds 
1071da177e4SLinus Torvalds #define ZFCP_ULP_INFO_VERSION                   26
1081da177e4SLinus Torvalds #define ZFCP_QTCB_VERSION	FSF_QTCB_CURRENT_VERSION
1091da177e4SLinus Torvalds /* ATTENTION: value must not be used by hardware */
1101da177e4SLinus Torvalds #define FSF_QTCB_UNSOLICITED_STATUS		0x6305
1111da177e4SLinus Torvalds #define ZFCP_STATUS_READS_RECOM		        FSF_STATUS_READS_RECOM
11222753fa5SAndreas Herrmann 
11322753fa5SAndreas Herrmann /* Do 1st retry in 1 second, then double the timeout for each following retry */
11418edcdbdSChristof Schmitt #define ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP	1
11522753fa5SAndreas Herrmann #define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES	7
1161da177e4SLinus Torvalds 
1171da177e4SLinus Torvalds /* timeout value for "default timer" for fsf requests */
1182abbe866SAndreas Herrmann #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
1191da177e4SLinus Torvalds 
1201da177e4SLinus Torvalds /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
1211da177e4SLinus Torvalds 
1221da177e4SLinus Torvalds typedef unsigned long long wwn_t;
1231da177e4SLinus Torvalds typedef unsigned long long fcp_lun_t;
1241da177e4SLinus Torvalds /* data length field may be at variable position in FCP-2 FCP_CMND IU */
1251da177e4SLinus Torvalds typedef unsigned int       fcp_dl_t;
1261da177e4SLinus Torvalds 
1271da177e4SLinus Torvalds #define ZFCP_FC_SERVICE_CLASS_DEFAULT	FSF_CLASS_3
1281da177e4SLinus Torvalds 
1291da177e4SLinus Torvalds /* timeout for name-server lookup (in seconds) */
1301da177e4SLinus Torvalds #define ZFCP_NS_GID_PN_TIMEOUT		10
1311da177e4SLinus Torvalds 
1321da177e4SLinus Torvalds /* largest SCSI command we can process */
1331da177e4SLinus Torvalds /* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */
1341da177e4SLinus Torvalds #define ZFCP_MAX_SCSI_CMND_LENGTH	255
1351da177e4SLinus Torvalds /* maximum number of commands in LUN queue (tagged queueing) */
1361da177e4SLinus Torvalds #define ZFCP_CMND_PER_LUN               32
1371da177e4SLinus Torvalds 
1381da177e4SLinus Torvalds /* task attribute values in FCP-2 FCP_CMND IU */
1391da177e4SLinus Torvalds #define SIMPLE_Q	0
1401da177e4SLinus Torvalds #define HEAD_OF_Q	1
1411da177e4SLinus Torvalds #define ORDERED_Q	2
1421da177e4SLinus Torvalds #define ACA_Q		4
1431da177e4SLinus Torvalds #define UNTAGGED	5
1441da177e4SLinus Torvalds 
1451da177e4SLinus Torvalds /* task management flags in FCP-2 FCP_CMND IU */
1461da177e4SLinus Torvalds #define FCP_CLEAR_ACA		0x40
1471da177e4SLinus Torvalds #define FCP_TARGET_RESET	0x20
1481da177e4SLinus Torvalds #define FCP_LOGICAL_UNIT_RESET	0x10
1491da177e4SLinus Torvalds #define FCP_CLEAR_TASK_SET	0x04
1501da177e4SLinus Torvalds #define FCP_ABORT_TASK_SET	0x02
1511da177e4SLinus Torvalds 
1521da177e4SLinus Torvalds #define FCP_CDB_LENGTH		16
1531da177e4SLinus Torvalds 
1541da177e4SLinus Torvalds #define ZFCP_DID_MASK           0x00FFFFFF
1551da177e4SLinus Torvalds 
1561da177e4SLinus Torvalds /* FCP(-2) FCP_CMND IU */
1571da177e4SLinus Torvalds struct fcp_cmnd_iu {
1581da177e4SLinus Torvalds 	fcp_lun_t fcp_lun;	   /* FCP logical unit number */
1591da177e4SLinus Torvalds 	u8  crn;	           /* command reference number */
1601da177e4SLinus Torvalds 	u8  reserved0:5;	   /* reserved */
1611da177e4SLinus Torvalds 	u8  task_attribute:3;	   /* task attribute */
1621da177e4SLinus Torvalds 	u8  task_management_flags; /* task management flags */
1631da177e4SLinus Torvalds 	u8  add_fcp_cdb_length:6;  /* additional FCP_CDB length */
1641da177e4SLinus Torvalds 	u8  rddata:1;              /* read data */
1651da177e4SLinus Torvalds 	u8  wddata:1;              /* write data */
1661da177e4SLinus Torvalds 	u8  fcp_cdb[FCP_CDB_LENGTH];
1671da177e4SLinus Torvalds } __attribute__((packed));
1681da177e4SLinus Torvalds 
1691da177e4SLinus Torvalds /* FCP(-2) FCP_RSP IU */
1701da177e4SLinus Torvalds struct fcp_rsp_iu {
1711da177e4SLinus Torvalds 	u8  reserved0[10];
1721da177e4SLinus Torvalds 	union {
1731da177e4SLinus Torvalds 		struct {
1741da177e4SLinus Torvalds 			u8 reserved1:3;
1751da177e4SLinus Torvalds 			u8 fcp_conf_req:1;
1761da177e4SLinus Torvalds 			u8 fcp_resid_under:1;
1771da177e4SLinus Torvalds 			u8 fcp_resid_over:1;
1781da177e4SLinus Torvalds 			u8 fcp_sns_len_valid:1;
1791da177e4SLinus Torvalds 			u8 fcp_rsp_len_valid:1;
1801da177e4SLinus Torvalds 		} bits;
1811da177e4SLinus Torvalds 		u8 value;
1821da177e4SLinus Torvalds 	} validity;
1831da177e4SLinus Torvalds 	u8  scsi_status;
1841da177e4SLinus Torvalds 	u32 fcp_resid;
1851da177e4SLinus Torvalds 	u32 fcp_sns_len;
1861da177e4SLinus Torvalds 	u32 fcp_rsp_len;
1871da177e4SLinus Torvalds } __attribute__((packed));
1881da177e4SLinus Torvalds 
1891da177e4SLinus Torvalds 
1901da177e4SLinus Torvalds #define RSP_CODE_GOOD		 0
1911da177e4SLinus Torvalds #define RSP_CODE_LENGTH_MISMATCH 1
1921da177e4SLinus Torvalds #define RSP_CODE_FIELD_INVALID	 2
1931da177e4SLinus Torvalds #define RSP_CODE_RO_MISMATCH	 3
1941da177e4SLinus Torvalds #define RSP_CODE_TASKMAN_UNSUPP	 4
1951da177e4SLinus Torvalds #define RSP_CODE_TASKMAN_FAILED	 5
1961da177e4SLinus Torvalds 
1971da177e4SLinus Torvalds /* see fc-fs */
19824073b47SChristof Schmitt #define LS_RSCN  0x61
19924073b47SChristof Schmitt #define LS_LOGO  0x05
20024073b47SChristof Schmitt #define LS_PLOGI 0x03
2011da177e4SLinus Torvalds 
2021da177e4SLinus Torvalds struct fcp_rscn_head {
2031da177e4SLinus Torvalds         u8  command;
2041da177e4SLinus Torvalds         u8  page_length; /* always 0x04 */
2051da177e4SLinus Torvalds         u16 payload_len;
2061da177e4SLinus Torvalds } __attribute__((packed));
2071da177e4SLinus Torvalds 
2081da177e4SLinus Torvalds struct fcp_rscn_element {
2091da177e4SLinus Torvalds         u8  reserved:2;
2101da177e4SLinus Torvalds         u8  event_qual:4;
2111da177e4SLinus Torvalds         u8  addr_format:2;
2121da177e4SLinus Torvalds         u32 nport_did:24;
2131da177e4SLinus Torvalds } __attribute__((packed));
2141da177e4SLinus Torvalds 
2151da177e4SLinus Torvalds #define ZFCP_PORT_ADDRESS   0x0
2161da177e4SLinus Torvalds #define ZFCP_AREA_ADDRESS   0x1
2171da177e4SLinus Torvalds #define ZFCP_DOMAIN_ADDRESS 0x2
2181da177e4SLinus Torvalds #define ZFCP_FABRIC_ADDRESS 0x3
2191da177e4SLinus Torvalds 
2201da177e4SLinus Torvalds #define ZFCP_PORTS_RANGE_PORT   0xFFFFFF
2211da177e4SLinus Torvalds #define ZFCP_PORTS_RANGE_AREA   0xFFFF00
2221da177e4SLinus Torvalds #define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
2231da177e4SLinus Torvalds #define ZFCP_PORTS_RANGE_FABRIC 0x000000
2241da177e4SLinus Torvalds 
2251da177e4SLinus Torvalds #define ZFCP_NO_PORTS_PER_AREA    0x100
2261da177e4SLinus Torvalds #define ZFCP_NO_PORTS_PER_DOMAIN  0x10000
2271da177e4SLinus Torvalds #define ZFCP_NO_PORTS_PER_FABRIC  0x1000000
2281da177e4SLinus Torvalds 
2291da177e4SLinus Torvalds /* see fc-ph */
2301da177e4SLinus Torvalds struct fcp_logo {
2311da177e4SLinus Torvalds         u32 command;
2321da177e4SLinus Torvalds         u32 nport_did;
2331da177e4SLinus Torvalds         wwn_t nport_wwpn;
2341da177e4SLinus Torvalds } __attribute__((packed));
2351da177e4SLinus Torvalds 
2361da177e4SLinus Torvalds /*
2371da177e4SLinus Torvalds  * FC-FS stuff
2381da177e4SLinus Torvalds  */
2391da177e4SLinus Torvalds #define R_A_TOV				10 /* seconds */
2401da177e4SLinus Torvalds #define ZFCP_ELS_TIMEOUT		(2 * R_A_TOV)
2411da177e4SLinus Torvalds 
2421da177e4SLinus Torvalds #define ZFCP_LS_RLS			0x0f
2431da177e4SLinus Torvalds #define ZFCP_LS_ADISC			0x52
2441da177e4SLinus Torvalds #define ZFCP_LS_RPS			0x56
2451da177e4SLinus Torvalds #define ZFCP_LS_RSCN			0x61
2461da177e4SLinus Torvalds #define ZFCP_LS_RNID			0x78
2471da177e4SLinus Torvalds 
2481da177e4SLinus Torvalds struct zfcp_ls_rjt_par {
2491da177e4SLinus Torvalds 	u8 action;
2501da177e4SLinus Torvalds  	u8 reason_code;
2511da177e4SLinus Torvalds  	u8 reason_expl;
2521da177e4SLinus Torvalds  	u8 vendor_unique;
2531da177e4SLinus Torvalds } __attribute__ ((packed));
2541da177e4SLinus Torvalds 
2551da177e4SLinus Torvalds struct zfcp_ls_adisc {
2561da177e4SLinus Torvalds 	u8		code;
2571da177e4SLinus Torvalds 	u8		field[3];
2581da177e4SLinus Torvalds 	u32		hard_nport_id;
2591da177e4SLinus Torvalds 	u64		wwpn;
2601da177e4SLinus Torvalds 	u64		wwnn;
2611da177e4SLinus Torvalds 	u32		nport_id;
2621da177e4SLinus Torvalds } __attribute__ ((packed));
2631da177e4SLinus Torvalds 
2641da177e4SLinus Torvalds struct zfcp_ls_adisc_acc {
2651da177e4SLinus Torvalds 	u8		code;
2661da177e4SLinus Torvalds 	u8		field[3];
2671da177e4SLinus Torvalds 	u32		hard_nport_id;
2681da177e4SLinus Torvalds 	u64		wwpn;
2691da177e4SLinus Torvalds 	u64		wwnn;
2701da177e4SLinus Torvalds 	u32		nport_id;
2711da177e4SLinus Torvalds } __attribute__ ((packed));
2721da177e4SLinus Torvalds 
2731da177e4SLinus Torvalds struct zfcp_rc_entry {
2741da177e4SLinus Torvalds 	u8 code;
2751da177e4SLinus Torvalds 	const char *description;
2761da177e4SLinus Torvalds };
2771da177e4SLinus Torvalds 
2781da177e4SLinus Torvalds /*
2791da177e4SLinus Torvalds  * FC-GS-2 stuff
2801da177e4SLinus Torvalds  */
2811da177e4SLinus Torvalds #define ZFCP_CT_REVISION		0x01
2821da177e4SLinus Torvalds #define ZFCP_CT_DIRECTORY_SERVICE	0xFC
2831da177e4SLinus Torvalds #define ZFCP_CT_NAME_SERVER		0x02
2841da177e4SLinus Torvalds #define ZFCP_CT_SYNCHRONOUS		0x00
2851da177e4SLinus Torvalds #define ZFCP_CT_GID_PN			0x0121
2861da177e4SLinus Torvalds #define ZFCP_CT_MAX_SIZE		0x1020
2871da177e4SLinus Torvalds #define ZFCP_CT_ACCEPT			0x8002
2881da177e4SLinus Torvalds #define ZFCP_CT_REJECT			0x8001
2891da177e4SLinus Torvalds 
2901da177e4SLinus Torvalds /*
2911da177e4SLinus Torvalds  * FC-GS-4 stuff
2921da177e4SLinus Torvalds  */
2931da177e4SLinus Torvalds #define ZFCP_CT_TIMEOUT			(3 * R_A_TOV)
2941da177e4SLinus Torvalds 
2951da177e4SLinus Torvalds /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
2961da177e4SLinus Torvalds 
2971da177e4SLinus Torvalds /*
2981da177e4SLinus Torvalds  * Note, the leftmost status byte is common among adapter, port
2991da177e4SLinus Torvalds  * and unit
3001da177e4SLinus Torvalds  */
3011da177e4SLinus Torvalds #define ZFCP_COMMON_FLAGS			0xfff00000
3021da177e4SLinus Torvalds 
3031da177e4SLinus Torvalds /* common status bits */
3041da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_REMOVE		0x80000000
3051da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_RUNNING		0x40000000
3061da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_ERP_FAILED		0x20000000
3071da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_UNBLOCKED		0x10000000
3081da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_OPENING              0x08000000
3091da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_OPEN                 0x04000000
3101da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_CLOSING              0x02000000
3111da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_ERP_INUSE		0x01000000
3121da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_ACCESS_DENIED	0x00800000
313d736a27bSAndreas Herrmann #define ZFCP_STATUS_COMMON_ACCESS_BOXED		0x00400000
3141da177e4SLinus Torvalds 
3151da177e4SLinus Torvalds /* adapter status */
3161da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_QDIOUP		0x00000002
3171da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_REGISTERED		0x00000004
3181da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_XCONFIG_OK		0x00000008
3191da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT	0x00000010
3201da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP	0x00000020
3211da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL	0x00000080
3221da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_ERP_PENDING		0x00000100
3231da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED	0x00000200
324aef4a983SMaxim Shchetynin #define ZFCP_STATUS_ADAPTER_XPORT_OK		0x00000800
3251da177e4SLinus Torvalds 
3261da177e4SLinus Torvalds /* FC-PH/FC-GS well-known address identifiers for generic services */
3271da177e4SLinus Torvalds #define ZFCP_DID_MANAGEMENT_SERVICE		0xFFFFFA
3281da177e4SLinus Torvalds #define ZFCP_DID_TIME_SERVICE			0xFFFFFB
3291da177e4SLinus Torvalds #define ZFCP_DID_DIRECTORY_SERVICE		0xFFFFFC
3301da177e4SLinus Torvalds #define ZFCP_DID_ALIAS_SERVICE			0xFFFFF8
3311da177e4SLinus Torvalds #define ZFCP_DID_KEY_DISTRIBUTION_SERVICE	0xFFFFF7
3321da177e4SLinus Torvalds 
3331da177e4SLinus Torvalds /* remote port status */
3341da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_PHYS_OPEN		0x00000001
3351da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_DID_DID		0x00000002
3361da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_PHYS_CLOSING		0x00000004
3371da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_NO_WWPN		0x00000008
3381da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_NO_SCSI_ID		0x00000010
3391da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_INVALID_WWPN		0x00000020
3401da177e4SLinus Torvalds 
3411da177e4SLinus Torvalds /* for ports with well known addresses */
3421da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_WKA \
3431da177e4SLinus Torvalds 		(ZFCP_STATUS_PORT_NO_WWPN | \
3441da177e4SLinus Torvalds 		 ZFCP_STATUS_PORT_NO_SCSI_ID)
3451da177e4SLinus Torvalds 
3461da177e4SLinus Torvalds /* logical unit status */
3471da177e4SLinus Torvalds #define ZFCP_STATUS_UNIT_TEMPORARY		0x00000002
3481da177e4SLinus Torvalds #define ZFCP_STATUS_UNIT_SHARED			0x00000004
3491da177e4SLinus Torvalds #define ZFCP_STATUS_UNIT_READONLY		0x00000008
350ad58f7dbSAndreas Herrmann #define ZFCP_STATUS_UNIT_REGISTERED		0x00000010
3515f852be9SChristof Schmitt #define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING	0x00000020
3521da177e4SLinus Torvalds 
3531da177e4SLinus Torvalds /* FSF request status (this does not have a common part) */
3541da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_NOT_INIT		0x00000000
3551da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_POOL  		0x00000001
3561da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT	0x00000002
3571da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_COMPLETED		0x00000004
3581da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_ERROR		0x00000008
3591da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_CLEANUP		0x00000010
3601da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_ABORTING		0x00000020
3611da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED	0x00000040
3621da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED       0x00000080
3631da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_ABORTED              0x00000100
3641da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED         0x00000200
3651da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP        0x00000400
3661da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_RETRY                0x00000800
3671da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_DISMISSED            0x00001000
3681da177e4SLinus Torvalds 
3691da177e4SLinus Torvalds /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
3701da177e4SLinus Torvalds 
3711da177e4SLinus Torvalds #define ZFCP_MAX_ERPS                   3
3721da177e4SLinus Torvalds 
3731da177e4SLinus Torvalds #define ZFCP_ERP_FSFREQ_TIMEOUT		(30 * HZ)
3741da177e4SLinus Torvalds #define ZFCP_ERP_MEMWAIT_TIMEOUT	HZ
3751da177e4SLinus Torvalds 
3761da177e4SLinus Torvalds #define ZFCP_STATUS_ERP_TIMEDOUT	0x10000000
3771da177e4SLinus Torvalds #define ZFCP_STATUS_ERP_CLOSE_ONLY	0x01000000
3781da177e4SLinus Torvalds #define ZFCP_STATUS_ERP_DISMISSING	0x00100000
3791da177e4SLinus Torvalds #define ZFCP_STATUS_ERP_DISMISSED	0x00200000
3801da177e4SLinus Torvalds #define ZFCP_STATUS_ERP_LOWMEM		0x00400000
3811da177e4SLinus Torvalds 
3821da177e4SLinus Torvalds #define ZFCP_ERP_STEP_UNINITIALIZED	0x00000000
3831da177e4SLinus Torvalds #define ZFCP_ERP_STEP_FSF_XCONFIG	0x00000001
3841da177e4SLinus Torvalds #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING	0x00000010
3851da177e4SLinus Torvalds #define ZFCP_ERP_STEP_PORT_CLOSING	0x00000100
3861da177e4SLinus Torvalds #define ZFCP_ERP_STEP_NAMESERVER_OPEN	0x00000200
3871da177e4SLinus Torvalds #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP	0x00000400
3881da177e4SLinus Torvalds #define ZFCP_ERP_STEP_PORT_OPENING	0x00000800
3891da177e4SLinus Torvalds #define ZFCP_ERP_STEP_UNIT_CLOSING	0x00001000
3901da177e4SLinus Torvalds #define ZFCP_ERP_STEP_UNIT_OPENING	0x00002000
3911da177e4SLinus Torvalds 
3921da177e4SLinus Torvalds /* Ordered by escalation level (necessary for proper erp-code operation) */
3931da177e4SLinus Torvalds #define ZFCP_ERP_ACTION_REOPEN_ADAPTER		0x4
3941da177e4SLinus Torvalds #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED	0x3
3951da177e4SLinus Torvalds #define ZFCP_ERP_ACTION_REOPEN_PORT		0x2
3961da177e4SLinus Torvalds #define ZFCP_ERP_ACTION_REOPEN_UNIT		0x1
3971da177e4SLinus Torvalds 
3981da177e4SLinus Torvalds #define ZFCP_ERP_ACTION_RUNNING			0x1
3991da177e4SLinus Torvalds #define ZFCP_ERP_ACTION_READY			0x2
4001da177e4SLinus Torvalds 
4011da177e4SLinus Torvalds #define ZFCP_ERP_SUCCEEDED	0x0
4021da177e4SLinus Torvalds #define ZFCP_ERP_FAILED		0x1
4031da177e4SLinus Torvalds #define ZFCP_ERP_CONTINUES	0x2
4041da177e4SLinus Torvalds #define ZFCP_ERP_EXIT		0x3
4051da177e4SLinus Torvalds #define ZFCP_ERP_DISMISSED	0x4
4061da177e4SLinus Torvalds #define ZFCP_ERP_NOMEM		0x5
4071da177e4SLinus Torvalds 
4081da177e4SLinus Torvalds /************************* STRUCTURE DEFINITIONS *****************************/
4091da177e4SLinus Torvalds 
4101da177e4SLinus Torvalds struct zfcp_fsf_req;
4111da177e4SLinus Torvalds 
4121da177e4SLinus Torvalds /* holds various memory pools of an adapter */
4131da177e4SLinus Torvalds struct zfcp_adapter_mempool {
4141da177e4SLinus Torvalds 	mempool_t *fsf_req_erp;
4151da177e4SLinus Torvalds 	mempool_t *fsf_req_scsi;
4161da177e4SLinus Torvalds 	mempool_t *fsf_req_abort;
4171da177e4SLinus Torvalds 	mempool_t *fsf_req_status_read;
4181da177e4SLinus Torvalds 	mempool_t *data_status_read;
4191da177e4SLinus Torvalds 	mempool_t *data_gid_pn;
4201da177e4SLinus Torvalds };
4211da177e4SLinus Torvalds 
4221da177e4SLinus Torvalds /*
4231da177e4SLinus Torvalds  * header for CT_IU
4241da177e4SLinus Torvalds  */
4251da177e4SLinus Torvalds struct ct_hdr {
4261da177e4SLinus Torvalds 	u8 revision;		// 0x01
4271da177e4SLinus Torvalds 	u8 in_id[3];		// 0x00
4281da177e4SLinus Torvalds 	u8 gs_type;		// 0xFC	Directory Service
4291da177e4SLinus Torvalds 	u8 gs_subtype;		// 0x02	Name Server
4301da177e4SLinus Torvalds 	u8 options;		// 0x00 single bidirectional exchange
4311da177e4SLinus Torvalds 	u8 reserved0;
4321da177e4SLinus Torvalds 	u16 cmd_rsp_code;	// 0x0121 GID_PN, or 0x0100 GA_NXT
4331da177e4SLinus Torvalds 	u16 max_res_size;	// <= (4096 - 16) / 4
4341da177e4SLinus Torvalds 	u8 reserved1;
4351da177e4SLinus Torvalds 	u8 reason_code;
4361da177e4SLinus Torvalds 	u8 reason_code_expl;
4371da177e4SLinus Torvalds 	u8 vendor_unique;
4381da177e4SLinus Torvalds } __attribute__ ((packed));
4391da177e4SLinus Torvalds 
4401da177e4SLinus Torvalds /* nameserver request CT_IU -- for requests where
4411da177e4SLinus Torvalds  * a port name is required */
4421da177e4SLinus Torvalds struct ct_iu_gid_pn_req {
4431da177e4SLinus Torvalds 	struct ct_hdr header;
4441da177e4SLinus Torvalds 	wwn_t wwpn;
4451da177e4SLinus Torvalds } __attribute__ ((packed));
4461da177e4SLinus Torvalds 
4471da177e4SLinus Torvalds /* FS_ACC IU and data unit for GID_PN nameserver request */
4481da177e4SLinus Torvalds struct ct_iu_gid_pn_resp {
4491da177e4SLinus Torvalds 	struct ct_hdr header;
45013e1e1f0SAndreas Herrmann 	u32 d_id;
4511da177e4SLinus Torvalds } __attribute__ ((packed));
4521da177e4SLinus Torvalds 
4531da177e4SLinus Torvalds typedef void (*zfcp_send_ct_handler_t)(unsigned long);
4541da177e4SLinus Torvalds 
4551da177e4SLinus Torvalds /**
4561da177e4SLinus Torvalds  * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
4571da177e4SLinus Torvalds  * @port: port where the request is sent to
4581da177e4SLinus Torvalds  * @req: scatter-gather list for request
4591da177e4SLinus Torvalds  * @resp: scatter-gather list for response
4601da177e4SLinus Torvalds  * @req_count: number of elements in request scatter-gather list
4611da177e4SLinus Torvalds  * @resp_count: number of elements in response scatter-gather list
4621da177e4SLinus Torvalds  * @handler: handler function (called for response to the request)
4631da177e4SLinus Torvalds  * @handler_data: data passed to handler function
4641da177e4SLinus Torvalds  * @timeout: FSF timeout for this request
4651da177e4SLinus Torvalds  * @completion: completion for synchronization purposes
4661da177e4SLinus Torvalds  * @status: used to pass error status to calling function
4671da177e4SLinus Torvalds  */
4681da177e4SLinus Torvalds struct zfcp_send_ct {
4691da177e4SLinus Torvalds 	struct zfcp_port *port;
4701da177e4SLinus Torvalds 	struct scatterlist *req;
4711da177e4SLinus Torvalds 	struct scatterlist *resp;
4721da177e4SLinus Torvalds 	unsigned int req_count;
4731da177e4SLinus Torvalds 	unsigned int resp_count;
4741da177e4SLinus Torvalds 	zfcp_send_ct_handler_t handler;
4751da177e4SLinus Torvalds 	unsigned long handler_data;
4761da177e4SLinus Torvalds 	int timeout;
4771da177e4SLinus Torvalds 	struct completion *completion;
4781da177e4SLinus Torvalds 	int status;
4791da177e4SLinus Torvalds };
4801da177e4SLinus Torvalds 
4811da177e4SLinus Torvalds /* used for name server requests in error recovery */
4821da177e4SLinus Torvalds struct zfcp_gid_pn_data {
4831da177e4SLinus Torvalds 	struct zfcp_send_ct ct;
4841da177e4SLinus Torvalds 	struct scatterlist req;
4851da177e4SLinus Torvalds 	struct scatterlist resp;
4861da177e4SLinus Torvalds 	struct ct_iu_gid_pn_req ct_iu_req;
4871da177e4SLinus Torvalds 	struct ct_iu_gid_pn_resp ct_iu_resp;
4881da177e4SLinus Torvalds         struct zfcp_port *port;
4891da177e4SLinus Torvalds };
4901da177e4SLinus Torvalds 
4911da177e4SLinus Torvalds typedef void (*zfcp_send_els_handler_t)(unsigned long);
4921da177e4SLinus Torvalds 
4931da177e4SLinus Torvalds /**
4941da177e4SLinus Torvalds  * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
4951da177e4SLinus Torvalds  * @adapter: adapter where request is sent from
49664b29a13SAndreas Herrmann  * @port: port where ELS is destinated (port reference count has to be increased)
4971da177e4SLinus Torvalds  * @d_id: destiniation id of port where request is sent to
4981da177e4SLinus Torvalds  * @req: scatter-gather list for request
4991da177e4SLinus Torvalds  * @resp: scatter-gather list for response
5001da177e4SLinus Torvalds  * @req_count: number of elements in request scatter-gather list
5011da177e4SLinus Torvalds  * @resp_count: number of elements in response scatter-gather list
5021da177e4SLinus Torvalds  * @handler: handler function (called for response to the request)
5031da177e4SLinus Torvalds  * @handler_data: data passed to handler function
5041da177e4SLinus Torvalds  * @completion: completion for synchronization purposes
5051da177e4SLinus Torvalds  * @ls_code: hex code of ELS command
5061da177e4SLinus Torvalds  * @status: used to pass error status to calling function
5071da177e4SLinus Torvalds  */
5081da177e4SLinus Torvalds struct zfcp_send_els {
5091da177e4SLinus Torvalds 	struct zfcp_adapter *adapter;
51064b29a13SAndreas Herrmann 	struct zfcp_port *port;
51113e1e1f0SAndreas Herrmann 	u32 d_id;
5121da177e4SLinus Torvalds 	struct scatterlist *req;
5131da177e4SLinus Torvalds 	struct scatterlist *resp;
5141da177e4SLinus Torvalds 	unsigned int req_count;
5151da177e4SLinus Torvalds 	unsigned int resp_count;
5161da177e4SLinus Torvalds 	zfcp_send_els_handler_t handler;
5171da177e4SLinus Torvalds 	unsigned long handler_data;
5181da177e4SLinus Torvalds 	struct completion *completion;
5191da177e4SLinus Torvalds 	int ls_code;
5201da177e4SLinus Torvalds 	int status;
5211da177e4SLinus Torvalds };
5221da177e4SLinus Torvalds 
5231da177e4SLinus Torvalds struct zfcp_qdio_queue {
52400bab910SSwen Schillig 	struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
52500bab910SSwen Schillig 	u8		   first;	      /* index of next free bfr
5261da177e4SLinus Torvalds 						 in queue (free_count>0) */
52700bab910SSwen Schillig 	atomic_t           count;	      /* number of free buffers
5281da177e4SLinus Torvalds 						 in queue */
52900bab910SSwen Schillig 	rwlock_t	   lock;	      /* lock for operations on queue */
53000bab910SSwen Schillig 	int                pci_batch;	      /* SBALs since PCI indication
5311da177e4SLinus Torvalds 						 was last set */
5321da177e4SLinus Torvalds };
5331da177e4SLinus Torvalds 
5341da177e4SLinus Torvalds struct zfcp_erp_action {
5351da177e4SLinus Torvalds 	struct list_head list;
5361da177e4SLinus Torvalds 	int action;	              /* requested action code */
5371da177e4SLinus Torvalds 	struct zfcp_adapter *adapter; /* device which should be recovered */
5381da177e4SLinus Torvalds 	struct zfcp_port *port;
5391da177e4SLinus Torvalds 	struct zfcp_unit *unit;
5401da177e4SLinus Torvalds 	volatile u32 status;	      /* recovery status */
5411da177e4SLinus Torvalds 	u32 step;	              /* active step of this erp action */
5421da177e4SLinus Torvalds 	struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
5431da177e4SLinus Torvalds 					 for this action */
5441da177e4SLinus Torvalds 	struct timer_list timer;
5451da177e4SLinus Torvalds };
5461da177e4SLinus Torvalds 
547c9615858SChristof Schmitt struct fsf_latency_record {
548c9615858SChristof Schmitt 	u32 min;
549c9615858SChristof Schmitt 	u32 max;
550c9615858SChristof Schmitt 	u64 sum;
551c9615858SChristof Schmitt };
552c9615858SChristof Schmitt 
553c9615858SChristof Schmitt struct latency_cont {
554c9615858SChristof Schmitt 	struct fsf_latency_record channel;
555c9615858SChristof Schmitt 	struct fsf_latency_record fabric;
556c9615858SChristof Schmitt 	u64 counter;
557c9615858SChristof Schmitt };
558c9615858SChristof Schmitt 
559c9615858SChristof Schmitt struct zfcp_latencies {
560c9615858SChristof Schmitt 	struct latency_cont read;
561c9615858SChristof Schmitt 	struct latency_cont write;
562c9615858SChristof Schmitt 	struct latency_cont cmd;
563c9615858SChristof Schmitt 	spinlock_t lock;
564c9615858SChristof Schmitt };
5651da177e4SLinus Torvalds 
5661da177e4SLinus Torvalds struct zfcp_adapter {
5671da177e4SLinus Torvalds 	struct list_head	list;              /* list of adapters */
5681da177e4SLinus Torvalds 	atomic_t                refcount;          /* reference count */
5691da177e4SLinus Torvalds 	wait_queue_head_t	remove_wq;         /* can be used to wait for
5701da177e4SLinus Torvalds 						      refcount drop to zero */
5716f71d9bcS 	wwn_t			peer_wwnn;	   /* P2P peer WWNN */
5726f71d9bcS 	wwn_t			peer_wwpn;	   /* P2P peer WWPN */
57313e1e1f0SAndreas Herrmann 	u32			peer_d_id;	   /* P2P peer D_ID */
5741da177e4SLinus Torvalds 	struct ccw_device       *ccw_device;	   /* S/390 ccw device */
5751da177e4SLinus Torvalds 	u32			hydra_version;	   /* Hydra version */
5761da177e4SLinus Torvalds 	u32			fsf_lic_version;
577aef4a983SMaxim Shchetynin 	u32			adapter_features;  /* FCP channel features */
578aef4a983SMaxim Shchetynin 	u32			connection_features; /* host connection features */
5791da177e4SLinus Torvalds         u32			hardware_version;  /* of FCP channel */
580c9615858SChristof Schmitt 	u16			timer_ticks;       /* time int for a tick */
5811da177e4SLinus Torvalds 	struct Scsi_Host	*scsi_host;	   /* Pointer to mid-layer */
5821da177e4SLinus Torvalds 	struct list_head	port_list_head;	   /* remote port list */
5831da177e4SLinus Torvalds 	struct list_head        port_remove_lh;    /* head of ports to be
5841da177e4SLinus Torvalds 						      removed */
5851da177e4SLinus Torvalds 	u32			ports;	           /* number of remote ports */
586fea9d6c7SVolker Sameske 	unsigned long		req_no;		   /* unique FSF req number */
587fea9d6c7SVolker Sameske 	struct list_head	*req_list;	   /* list of pending reqs */
588fea9d6c7SVolker Sameske 	spinlock_t		req_list_lock;	   /* request list lock */
58900bab910SSwen Schillig 	struct zfcp_qdio_queue	req_q;		   /* request queue */
5901da177e4SLinus Torvalds 	u32			fsf_req_seq_no;	   /* FSF cmnd seq number */
5911da177e4SLinus Torvalds 	wait_queue_head_t	request_wq;	   /* can be used to wait for
5921da177e4SLinus Torvalds 						      more avaliable SBALs */
59300bab910SSwen Schillig 	struct zfcp_qdio_queue	resp_q;	   /* response queue */
5941da177e4SLinus Torvalds 	rwlock_t		abort_lock;        /* Protects against SCSI
5951da177e4SLinus Torvalds 						      stack abort/command
5961da177e4SLinus Torvalds 						      completion races */
597d26ab06eSSwen Schillig 	atomic_t		stat_miss;	   /* # missing status reads*/
598d26ab06eSSwen Schillig 	struct work_struct	stat_work;
5991da177e4SLinus Torvalds 	atomic_t		status;	           /* status of this adapter */
6001da177e4SLinus Torvalds 	struct list_head	erp_ready_head;	   /* error recovery for this
6011da177e4SLinus Torvalds 						      adapter/devices */
6021da177e4SLinus Torvalds 	struct list_head	erp_running_head;
6031da177e4SLinus Torvalds 	rwlock_t		erp_lock;
6041da177e4SLinus Torvalds 	struct semaphore	erp_ready_sem;
6051da177e4SLinus Torvalds 	wait_queue_head_t	erp_thread_wqh;
6061da177e4SLinus Torvalds 	wait_queue_head_t	erp_done_wqh;
6071da177e4SLinus Torvalds 	struct zfcp_erp_action	erp_action;	   /* pending error recovery */
6081da177e4SLinus Torvalds         atomic_t                erp_counter;
6091da177e4SLinus Torvalds 	u32			erp_total_count;   /* total nr of enqueued erp
6101da177e4SLinus Torvalds 						      actions */
6111da177e4SLinus Torvalds 	u32			erp_low_mem_count; /* nr of erp actions waiting
6121da177e4SLinus Torvalds 						      for memory */
6131da177e4SLinus Torvalds 	struct zfcp_port	*nameserver_port;  /* adapter's nameserver */
614d79a83dbSMartin Peschke 	debug_info_t		*rec_dbf;
6158a36e453SMaxim Shchetynin 	debug_info_t		*hba_dbf;
6168a36e453SMaxim Shchetynin 	debug_info_t		*san_dbf;          /* debug feature areas */
6178a36e453SMaxim Shchetynin 	debug_info_t		*scsi_dbf;
618d79a83dbSMartin Peschke 	spinlock_t		rec_dbf_lock;
6198a36e453SMaxim Shchetynin 	spinlock_t		hba_dbf_lock;
6208a36e453SMaxim Shchetynin 	spinlock_t		san_dbf_lock;
6218a36e453SMaxim Shchetynin 	spinlock_t		scsi_dbf_lock;
622d79a83dbSMartin Peschke 	struct zfcp_rec_dbf_record	rec_dbf_buf;
6238a36e453SMaxim Shchetynin 	struct zfcp_hba_dbf_record	hba_dbf_buf;
6248a36e453SMaxim Shchetynin 	struct zfcp_san_dbf_record	san_dbf_buf;
6258a36e453SMaxim Shchetynin 	struct zfcp_scsi_dbf_record	scsi_dbf_buf;
6261da177e4SLinus Torvalds 	struct zfcp_adapter_mempool	pool;      /* Adapter memory pools */
6271da177e4SLinus Torvalds 	struct qdio_initialize  qdio_init_data;    /* for qdio_establish */
6281da177e4SLinus Torvalds 	struct device           generic_services;  /* directory for WKA ports */
629f6cd94b1SAndreas Herrmann 	struct fc_host_statistics *fc_stats;
630f6cd94b1SAndreas Herrmann 	struct fsf_qtcb_bottom_port *stats_reset_data;
631f6cd94b1SAndreas Herrmann 	unsigned long		stats_reset;
6321da177e4SLinus Torvalds };
6331da177e4SLinus Torvalds 
6341da177e4SLinus Torvalds /*
6351da177e4SLinus Torvalds  * the struct device sysfs_device must be at the beginning of this structure.
6361da177e4SLinus Torvalds  * pointer to struct device is used to free port structure in release function
6371da177e4SLinus Torvalds  * of the device. don't change!
6381da177e4SLinus Torvalds  */
6391da177e4SLinus Torvalds struct zfcp_port {
6401da177e4SLinus Torvalds 	struct device          sysfs_device;   /* sysfs device */
6413859f6a2SAndreas Herrmann 	struct fc_rport        *rport;         /* rport of fc transport class */
6421da177e4SLinus Torvalds 	struct list_head       list;	       /* list of remote ports */
6431da177e4SLinus Torvalds 	atomic_t               refcount;       /* reference count */
6441da177e4SLinus Torvalds 	wait_queue_head_t      remove_wq;      /* can be used to wait for
6451da177e4SLinus Torvalds 						  refcount drop to zero */
6461da177e4SLinus Torvalds 	struct zfcp_adapter    *adapter;       /* adapter used to access port */
6471da177e4SLinus Torvalds 	struct list_head       unit_list_head; /* head of logical unit list */
6481da177e4SLinus Torvalds 	struct list_head       unit_remove_lh; /* head of luns to be removed
6491da177e4SLinus Torvalds 						  list */
6501da177e4SLinus Torvalds 	u32		       units;	       /* # of logical units in list */
6511da177e4SLinus Torvalds 	atomic_t	       status;	       /* status of this remote port */
6521da177e4SLinus Torvalds 	wwn_t		       wwnn;	       /* WWNN if known */
6531da177e4SLinus Torvalds 	wwn_t		       wwpn;	       /* WWPN */
65413e1e1f0SAndreas Herrmann 	u32		       d_id;	       /* D_ID */
6551da177e4SLinus Torvalds 	u32		       handle;	       /* handle assigned by FSF */
6561da177e4SLinus Torvalds 	struct zfcp_erp_action erp_action;     /* pending error recovery */
6571da177e4SLinus Torvalds         atomic_t               erp_counter;
65875bfc283SRalph Wuerthner 	u32                    maxframe_size;
65975bfc283SRalph Wuerthner 	u32                    supported_classes;
6601da177e4SLinus Torvalds };
6611da177e4SLinus Torvalds 
6621da177e4SLinus Torvalds /* the struct device sysfs_device must be at the beginning of this structure.
6631da177e4SLinus Torvalds  * pointer to struct device is used to free unit structure in release function
6641da177e4SLinus Torvalds  * of the device. don't change!
6651da177e4SLinus Torvalds  */
6661da177e4SLinus Torvalds struct zfcp_unit {
6671da177e4SLinus Torvalds 	struct device          sysfs_device;   /* sysfs device */
6681da177e4SLinus Torvalds 	struct list_head       list;	       /* list of logical units */
6691da177e4SLinus Torvalds 	atomic_t               refcount;       /* reference count */
6701da177e4SLinus Torvalds 	wait_queue_head_t      remove_wq;      /* can be used to wait for
6711da177e4SLinus Torvalds 						  refcount drop to zero */
6721da177e4SLinus Torvalds 	struct zfcp_port       *port;	       /* remote port of unit */
6731da177e4SLinus Torvalds 	atomic_t	       status;	       /* status of this logical unit */
67406506d00SAndreas Herrmann 	unsigned int	       scsi_lun;       /* own SCSI LUN */
6751da177e4SLinus Torvalds 	fcp_lun_t	       fcp_lun;	       /* own FCP_LUN */
6761da177e4SLinus Torvalds 	u32		       handle;	       /* handle assigned by FSF */
6771da177e4SLinus Torvalds         struct scsi_device     *device;        /* scsi device struct pointer */
6781da177e4SLinus Torvalds 	struct zfcp_erp_action erp_action;     /* pending error recovery */
6791da177e4SLinus Torvalds         atomic_t               erp_counter;
680c9615858SChristof Schmitt 	struct zfcp_latencies	latencies;
6811da177e4SLinus Torvalds };
6821da177e4SLinus Torvalds 
6831da177e4SLinus Torvalds /* FSF request */
6841da177e4SLinus Torvalds struct zfcp_fsf_req {
6851da177e4SLinus Torvalds 	struct list_head       list;	       /* list of FSF requests */
686fea9d6c7SVolker Sameske 	unsigned long	       req_id;	       /* unique request ID */
6871da177e4SLinus Torvalds 	struct zfcp_adapter    *adapter;       /* adapter request belongs to */
6881da177e4SLinus Torvalds 	u8		       sbal_number;    /* nr of SBALs free for use */
6891da177e4SLinus Torvalds 	u8		       sbal_first;     /* first SBAL for this request */
690e891bffeSMartin Peschke 	u8		       sbal_last;      /* last SBAL for this request */
691d01d51beSMartin Peschke 	u8		       sbal_limit;      /* last possible SBAL for
6921da177e4SLinus Torvalds 						  this reuest */
6931da177e4SLinus Torvalds 	u8		       sbale_curr;     /* current SBALE during creation
6941da177e4SLinus Torvalds 						  of request */
695c3baa9a2SMartin Peschke 	u8			sbal_response;	/* SBAL used in interrupt */
6961da177e4SLinus Torvalds 	wait_queue_head_t      completion_wq;  /* can be used by a routine
6971da177e4SLinus Torvalds 						  to wait for completion */
6981da177e4SLinus Torvalds 	volatile u32	       status;	       /* status of this request */
6991da177e4SLinus Torvalds 	u32		       fsf_command;    /* FSF Command copy */
7001da177e4SLinus Torvalds 	struct fsf_qtcb	       *qtcb;	       /* address of associated QTCB */
7011da177e4SLinus Torvalds 	u32		       seq_no;         /* Sequence number of request */
702059c97d0SAndreas Herrmann 	unsigned long	       data;           /* private data of request */
7032abbe866SAndreas Herrmann 	struct timer_list     timer;	       /* used for erp or scsi er */
7041da177e4SLinus Torvalds 	struct zfcp_erp_action *erp_action;    /* used if this request is
7051da177e4SLinus Torvalds 						  issued on behalf of erp */
7061da177e4SLinus Torvalds 	mempool_t	       *pool;	       /* used if request was alloacted
7071da177e4SLinus Torvalds 						  from emergency pool */
7088a36e453SMaxim Shchetynin 	unsigned long long     issued;         /* request sent time (STCK) */
709059c97d0SAndreas Herrmann 	struct zfcp_unit       *unit;
7101da177e4SLinus Torvalds };
7111da177e4SLinus Torvalds 
7121da177e4SLinus Torvalds typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
7131da177e4SLinus Torvalds 
7141da177e4SLinus Torvalds /* driver data */
7151da177e4SLinus Torvalds struct zfcp_data {
7161da177e4SLinus Torvalds 	struct scsi_host_template scsi_host_template;
717dd52e0eaSHeiko Carstens 	struct scsi_transport_template *scsi_transport_template;
7181da177e4SLinus Torvalds         atomic_t                status;             /* Module status flags */
7191da177e4SLinus Torvalds 	struct list_head	adapter_list_head;  /* head of adapter list */
7201da177e4SLinus Torvalds 	struct list_head	adapter_remove_lh;  /* head of adapters to be
7211da177e4SLinus Torvalds 						       removed */
7221da177e4SLinus Torvalds 	u32			adapters;	    /* # of adapters in list */
7231da177e4SLinus Torvalds 	rwlock_t                config_lock;        /* serialises changes
7241da177e4SLinus Torvalds 						       to adapter/port/unit
7251da177e4SLinus Torvalds 						       lists */
7261da177e4SLinus Torvalds 	struct semaphore        config_sema;        /* serialises configuration
7271da177e4SLinus Torvalds 						       changes */
7281da177e4SLinus Torvalds 	atomic_t		loglevel;            /* current loglevel */
7291da177e4SLinus Torvalds 	char                    init_busid[BUS_ID_SIZE];
7301da177e4SLinus Torvalds 	wwn_t                   init_wwpn;
7311da177e4SLinus Torvalds 	fcp_lun_t               init_fcp_lun;
732e18b890bSChristoph Lameter 	struct kmem_cache		*fsf_req_qtcb_cache;
733e18b890bSChristoph Lameter 	struct kmem_cache		*sr_buffer_cache;
734e18b890bSChristoph Lameter 	struct kmem_cache		*gid_pn_cache;
7351da177e4SLinus Torvalds };
7361da177e4SLinus Torvalds 
7371da177e4SLinus Torvalds /* number of elements for various memory pools */
7381da177e4SLinus Torvalds #define ZFCP_POOL_FSF_REQ_ERP_NR	1
7391da177e4SLinus Torvalds #define ZFCP_POOL_FSF_REQ_SCSI_NR	1
7401da177e4SLinus Torvalds #define ZFCP_POOL_FSF_REQ_ABORT_NR	1
7411da177e4SLinus Torvalds #define ZFCP_POOL_STATUS_READ_NR	ZFCP_STATUS_READS_RECOM
7421da177e4SLinus Torvalds #define ZFCP_POOL_DATA_GID_PN_NR	1
7431da177e4SLinus Torvalds 
7441da177e4SLinus Torvalds /* struct used by memory pools for fsf_requests */
745dd52e0eaSHeiko Carstens struct zfcp_fsf_req_qtcb {
7461da177e4SLinus Torvalds 	struct zfcp_fsf_req fsf_req;
7471da177e4SLinus Torvalds 	struct fsf_qtcb qtcb;
7481da177e4SLinus Torvalds };
7491da177e4SLinus Torvalds 
7501da177e4SLinus Torvalds /********************** ZFCP SPECIFIC DEFINES ********************************/
7511da177e4SLinus Torvalds 
7521da177e4SLinus Torvalds #define ZFCP_REQ_AUTO_CLEANUP	0x00000002
7531da177e4SLinus Torvalds #define ZFCP_WAIT_FOR_SBAL	0x00000004
7541da177e4SLinus Torvalds #define ZFCP_REQ_NO_QTCB	0x00000008
7551da177e4SLinus Torvalds 
7561da177e4SLinus Torvalds #define ZFCP_SET                0x00000100
7571da177e4SLinus Torvalds #define ZFCP_CLEAR              0x00000200
7581da177e4SLinus Torvalds 
7591da177e4SLinus Torvalds #ifndef atomic_test_mask
7601da177e4SLinus Torvalds #define atomic_test_mask(mask, target) \
7611da177e4SLinus Torvalds            ((atomic_read(target) & mask) == mask)
7621da177e4SLinus Torvalds #endif
7631da177e4SLinus Torvalds 
7641da177e4SLinus Torvalds extern void _zfcp_hex_dump(char *, int);
7651da177e4SLinus Torvalds #define ZFCP_HEX_DUMP(level, addr, count) \
7661da177e4SLinus Torvalds 		if (ZFCP_LOG_CHECK(level)) { \
7671da177e4SLinus Torvalds 			_zfcp_hex_dump(addr, count); \
7681da177e4SLinus Torvalds 		}
7691da177e4SLinus Torvalds 
7701da177e4SLinus Torvalds #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
7711da177e4SLinus Torvalds #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
7721da177e4SLinus Torvalds #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
7731da177e4SLinus Torvalds 
7741da177e4SLinus Torvalds /*
775ca2d02c2SHeiko Carstens  * Helper functions for request ID management.
776ca2d02c2SHeiko Carstens  */
777ca2d02c2SHeiko Carstens static inline int zfcp_reqlist_hash(unsigned long req_id)
778ca2d02c2SHeiko Carstens {
779ca2d02c2SHeiko Carstens 	return req_id % REQUEST_LIST_SIZE;
780ca2d02c2SHeiko Carstens }
781ca2d02c2SHeiko Carstens 
782ca2d02c2SHeiko Carstens static inline void zfcp_reqlist_add(struct zfcp_adapter *adapter,
783ca2d02c2SHeiko Carstens 				    struct zfcp_fsf_req *fsf_req)
784ca2d02c2SHeiko Carstens {
785ca2d02c2SHeiko Carstens 	unsigned int idx;
786ca2d02c2SHeiko Carstens 
787ca2d02c2SHeiko Carstens 	idx = zfcp_reqlist_hash(fsf_req->req_id);
788ca2d02c2SHeiko Carstens 	list_add_tail(&fsf_req->list, &adapter->req_list[idx]);
789ca2d02c2SHeiko Carstens }
790ca2d02c2SHeiko Carstens 
791ca2d02c2SHeiko Carstens static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
792ca2d02c2SHeiko Carstens 				       struct zfcp_fsf_req *fsf_req)
793ca2d02c2SHeiko Carstens {
794ca2d02c2SHeiko Carstens 	list_del(&fsf_req->list);
795ca2d02c2SHeiko Carstens }
796ca2d02c2SHeiko Carstens 
797ca2d02c2SHeiko Carstens static inline struct zfcp_fsf_req *
798ca2d02c2SHeiko Carstens zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
799ca2d02c2SHeiko Carstens {
800ca2d02c2SHeiko Carstens 	struct zfcp_fsf_req *request;
801ca2d02c2SHeiko Carstens 	unsigned int idx;
802ca2d02c2SHeiko Carstens 
803ca2d02c2SHeiko Carstens 	idx = zfcp_reqlist_hash(req_id);
804ca2d02c2SHeiko Carstens 	list_for_each_entry(request, &adapter->req_list[idx], list)
805ca2d02c2SHeiko Carstens 		if (request->req_id == req_id)
806ca2d02c2SHeiko Carstens 			return request;
807ca2d02c2SHeiko Carstens 	return NULL;
808ca2d02c2SHeiko Carstens }
809ca2d02c2SHeiko Carstens 
810d1ad09dbSHeiko Carstens static inline struct zfcp_fsf_req *
811d1ad09dbSHeiko Carstens zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
812d1ad09dbSHeiko Carstens {
813d1ad09dbSHeiko Carstens 	struct zfcp_fsf_req *request;
814d1ad09dbSHeiko Carstens 	unsigned int idx;
815d1ad09dbSHeiko Carstens 
816d1ad09dbSHeiko Carstens 	for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
817d1ad09dbSHeiko Carstens 		list_for_each_entry(request, &adapter->req_list[idx], list)
818d1ad09dbSHeiko Carstens 			if (request == req)
819d1ad09dbSHeiko Carstens 				return request;
820d1ad09dbSHeiko Carstens 	}
821d1ad09dbSHeiko Carstens 	return NULL;
822d1ad09dbSHeiko Carstens }
823d1ad09dbSHeiko Carstens 
824ca2d02c2SHeiko Carstens /*
8251da177e4SLinus Torvalds  *  functions needed for reference/usage counting
8261da177e4SLinus Torvalds  */
8271da177e4SLinus Torvalds 
8281da177e4SLinus Torvalds static inline void
8291da177e4SLinus Torvalds zfcp_unit_get(struct zfcp_unit *unit)
8301da177e4SLinus Torvalds {
8311da177e4SLinus Torvalds 	atomic_inc(&unit->refcount);
8321da177e4SLinus Torvalds }
8331da177e4SLinus Torvalds 
8341da177e4SLinus Torvalds static inline void
8351da177e4SLinus Torvalds zfcp_unit_put(struct zfcp_unit *unit)
8361da177e4SLinus Torvalds {
8371da177e4SLinus Torvalds 	if (atomic_dec_return(&unit->refcount) == 0)
8381da177e4SLinus Torvalds 		wake_up(&unit->remove_wq);
8391da177e4SLinus Torvalds }
8401da177e4SLinus Torvalds 
8411da177e4SLinus Torvalds static inline void
8421da177e4SLinus Torvalds zfcp_unit_wait(struct zfcp_unit *unit)
8431da177e4SLinus Torvalds {
8441da177e4SLinus Torvalds 	wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
8451da177e4SLinus Torvalds }
8461da177e4SLinus Torvalds 
8471da177e4SLinus Torvalds static inline void
8481da177e4SLinus Torvalds zfcp_port_get(struct zfcp_port *port)
8491da177e4SLinus Torvalds {
8501da177e4SLinus Torvalds 	atomic_inc(&port->refcount);
8511da177e4SLinus Torvalds }
8521da177e4SLinus Torvalds 
8531da177e4SLinus Torvalds static inline void
8541da177e4SLinus Torvalds zfcp_port_put(struct zfcp_port *port)
8551da177e4SLinus Torvalds {
8561da177e4SLinus Torvalds 	if (atomic_dec_return(&port->refcount) == 0)
8571da177e4SLinus Torvalds 		wake_up(&port->remove_wq);
8581da177e4SLinus Torvalds }
8591da177e4SLinus Torvalds 
8601da177e4SLinus Torvalds static inline void
8611da177e4SLinus Torvalds zfcp_port_wait(struct zfcp_port *port)
8621da177e4SLinus Torvalds {
8631da177e4SLinus Torvalds 	wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
8641da177e4SLinus Torvalds }
8651da177e4SLinus Torvalds 
8661da177e4SLinus Torvalds static inline void
8671da177e4SLinus Torvalds zfcp_adapter_get(struct zfcp_adapter *adapter)
8681da177e4SLinus Torvalds {
8691da177e4SLinus Torvalds 	atomic_inc(&adapter->refcount);
8701da177e4SLinus Torvalds }
8711da177e4SLinus Torvalds 
8721da177e4SLinus Torvalds static inline void
8731da177e4SLinus Torvalds zfcp_adapter_put(struct zfcp_adapter *adapter)
8741da177e4SLinus Torvalds {
8751da177e4SLinus Torvalds 	if (atomic_dec_return(&adapter->refcount) == 0)
8761da177e4SLinus Torvalds 		wake_up(&adapter->remove_wq);
8771da177e4SLinus Torvalds }
8781da177e4SLinus Torvalds 
8791da177e4SLinus Torvalds static inline void
8801da177e4SLinus Torvalds zfcp_adapter_wait(struct zfcp_adapter *adapter)
8811da177e4SLinus Torvalds {
8821da177e4SLinus Torvalds 	wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
8831da177e4SLinus Torvalds }
8841da177e4SLinus Torvalds 
8851da177e4SLinus Torvalds #endif /* ZFCP_DEF_H */
886