xref: /openbmc/linux/drivers/s390/scsi/zfcp_def.h (revision c9615858)
11da177e4SLinus Torvalds /*
24a9d2d8bSAndreas Herrmann  * This file is part of the zfcp device driver for
34a9d2d8bSAndreas Herrmann  * FCP adapters for IBM System z9 and zSeries.
41da177e4SLinus Torvalds  *
54a9d2d8bSAndreas Herrmann  * (C) Copyright IBM Corp. 2002, 2006
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  * This program is free software; you can redistribute it and/or modify
81da177e4SLinus Torvalds  * it under the terms of the GNU General Public License as published by
91da177e4SLinus Torvalds  * the Free Software Foundation; either version 2, or (at your option)
101da177e4SLinus Torvalds  * any later version.
111da177e4SLinus Torvalds  *
121da177e4SLinus Torvalds  * This program is distributed in the hope that it will be useful,
131da177e4SLinus Torvalds  * but WITHOUT ANY WARRANTY; without even the implied warranty of
141da177e4SLinus Torvalds  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
151da177e4SLinus Torvalds  * GNU General Public License for more details.
161da177e4SLinus Torvalds  *
171da177e4SLinus Torvalds  * You should have received a copy of the GNU General Public License
181da177e4SLinus Torvalds  * along with this program; if not, write to the Free Software
191da177e4SLinus Torvalds  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
201da177e4SLinus Torvalds  */
211da177e4SLinus Torvalds 
221da177e4SLinus Torvalds #ifndef ZFCP_DEF_H
231da177e4SLinus Torvalds #define ZFCP_DEF_H
241da177e4SLinus Torvalds 
251da177e4SLinus Torvalds /*************************** INCLUDES *****************************************/
261da177e4SLinus Torvalds 
271da177e4SLinus Torvalds #include <linux/init.h>
281da177e4SLinus Torvalds #include <linux/moduleparam.h>
291da177e4SLinus Torvalds #include <linux/miscdevice.h>
301da177e4SLinus Torvalds #include <linux/major.h>
311da177e4SLinus Torvalds #include <linux/blkdev.h>
321da177e4SLinus Torvalds #include <linux/delay.h>
331da177e4SLinus Torvalds #include <linux/timer.h>
34dd52e0eaSHeiko Carstens #include <linux/slab.h>
35dd52e0eaSHeiko Carstens #include <linux/mempool.h>
36dd52e0eaSHeiko Carstens #include <linux/syscalls.h>
37f1346372SFUJITA Tomonori #include <linux/scatterlist.h>
38dd52e0eaSHeiko Carstens #include <linux/ioctl.h>
391da177e4SLinus Torvalds #include <scsi/scsi.h>
401da177e4SLinus Torvalds #include <scsi/scsi_tcq.h>
411da177e4SLinus Torvalds #include <scsi/scsi_cmnd.h>
421da177e4SLinus Torvalds #include <scsi/scsi_device.h>
431da177e4SLinus Torvalds #include <scsi/scsi_host.h>
441da177e4SLinus Torvalds #include <scsi/scsi_transport.h>
451da177e4SLinus Torvalds #include <scsi/scsi_transport_fc.h>
461da177e4SLinus Torvalds #include <asm/ccwdev.h>
471da177e4SLinus Torvalds #include <asm/qdio.h>
481da177e4SLinus Torvalds #include <asm/debug.h>
491da177e4SLinus Torvalds #include <asm/ebcdic.h>
502b604c9bSChristof Schmitt #include "zfcp_dbf.h"
51dd52e0eaSHeiko Carstens #include "zfcp_fsf.h"
521da177e4SLinus Torvalds 
531da177e4SLinus Torvalds 
541da177e4SLinus Torvalds /********************* GENERAL DEFINES *********************************/
551da177e4SLinus Torvalds 
561da177e4SLinus Torvalds /* zfcp version number, it consists of major, minor, and patch-level number */
5758b3ac07SAndreas Herrmann #define ZFCP_VERSION		"4.8.0"
581da177e4SLinus Torvalds 
591da177e4SLinus Torvalds /**
601da177e4SLinus Torvalds  * zfcp_sg_to_address - determine kernel address from struct scatterlist
611da177e4SLinus Torvalds  * @list: struct scatterlist
621da177e4SLinus Torvalds  * Return: kernel address
631da177e4SLinus Torvalds  */
641da177e4SLinus Torvalds static inline void *
651da177e4SLinus Torvalds zfcp_sg_to_address(struct scatterlist *list)
661da177e4SLinus Torvalds {
6773fc4f0dSJens Axboe 	return sg_virt(list);
681da177e4SLinus Torvalds }
691da177e4SLinus Torvalds 
701da177e4SLinus Torvalds /**
711da177e4SLinus Torvalds  * zfcp_address_to_sg - set up struct scatterlist from kernel address
721da177e4SLinus Torvalds  * @address: kernel address
731da177e4SLinus Torvalds  * @list: struct scatterlist
7493354329SJens Axboe  * @size: buffer size
751da177e4SLinus Torvalds  */
761da177e4SLinus Torvalds static inline void
7793354329SJens Axboe zfcp_address_to_sg(void *address, struct scatterlist *list, unsigned int size)
781da177e4SLinus Torvalds {
7993354329SJens Axboe 	sg_set_buf(list, address, size);
801da177e4SLinus Torvalds }
811da177e4SLinus Torvalds 
8206506d00SAndreas Herrmann #define REQUEST_LIST_SIZE 128
8306506d00SAndreas Herrmann 
841da177e4SLinus Torvalds /********************* SCSI SPECIFIC DEFINES *********************************/
85f6c0e7a7SAndreas Herrmann #define ZFCP_SCSI_ER_TIMEOUT                    (10*HZ)
861da177e4SLinus Torvalds 
871da177e4SLinus Torvalds /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
881da177e4SLinus Torvalds 
891da177e4SLinus Torvalds /* Adapter Identification Parameters */
901da177e4SLinus Torvalds #define ZFCP_CONTROL_UNIT_TYPE  0x1731
911da177e4SLinus Torvalds #define ZFCP_CONTROL_UNIT_MODEL 0x03
921da177e4SLinus Torvalds #define ZFCP_DEVICE_TYPE        0x1732
931da177e4SLinus Torvalds #define ZFCP_DEVICE_MODEL       0x03
941da177e4SLinus Torvalds #define ZFCP_DEVICE_MODEL_PRIV	0x04
951da177e4SLinus Torvalds 
961da177e4SLinus Torvalds /* allow as many chained SBALs as are supported by hardware */
971da177e4SLinus Torvalds #define ZFCP_MAX_SBALS_PER_REQ		FSF_MAX_SBALS_PER_REQ
981da177e4SLinus Torvalds #define ZFCP_MAX_SBALS_PER_CT_REQ	FSF_MAX_SBALS_PER_REQ
991da177e4SLinus Torvalds #define ZFCP_MAX_SBALS_PER_ELS_REQ	FSF_MAX_SBALS_PER_ELS_REQ
1001da177e4SLinus Torvalds 
1011da177e4SLinus Torvalds /* DMQ bug workaround: don't use last SBALE */
1021da177e4SLinus Torvalds #define ZFCP_MAX_SBALES_PER_SBAL	(QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
1031da177e4SLinus Torvalds 
1041da177e4SLinus Torvalds /* index of last SBALE (with respect to DMQ bug workaround) */
1051da177e4SLinus Torvalds #define ZFCP_LAST_SBALE_PER_SBAL	(ZFCP_MAX_SBALES_PER_SBAL - 1)
1061da177e4SLinus Torvalds 
1071da177e4SLinus Torvalds /* max. number of (data buffer) SBALEs in largest SBAL chain */
1081da177e4SLinus Torvalds #define ZFCP_MAX_SBALES_PER_REQ		\
1091da177e4SLinus Torvalds 	(ZFCP_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
1101da177e4SLinus Torvalds         /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
1111da177e4SLinus Torvalds 
1128d1a0060SSwen Schillig #define ZFCP_MAX_SECTORS (ZFCP_MAX_SBALES_PER_REQ * 8)
1138d1a0060SSwen Schillig         /* max. number of (data buffer) SBALEs in largest SBAL chain
1148d1a0060SSwen Schillig            multiplied with number of sectors per 4k block */
1158d1a0060SSwen Schillig 
1161da177e4SLinus Torvalds /* FIXME(tune): free space should be one max. SBAL chain plus what? */
1171da177e4SLinus Torvalds #define ZFCP_QDIO_PCI_INTERVAL		(QDIO_MAX_BUFFERS_PER_Q \
1181da177e4SLinus Torvalds                                          - (ZFCP_MAX_SBALS_PER_REQ + 4))
1191da177e4SLinus Torvalds 
1201da177e4SLinus Torvalds #define ZFCP_SBAL_TIMEOUT               (5*HZ)
1211da177e4SLinus Torvalds 
12218edcdbdSChristof Schmitt #define ZFCP_TYPE2_RECOVERY_TIME        8	/* seconds */
1231da177e4SLinus Torvalds 
1241da177e4SLinus Torvalds /* queue polling (values in microseconds) */
1251da177e4SLinus Torvalds #define ZFCP_MAX_INPUT_THRESHOLD 	5000	/* FIXME: tune */
1261da177e4SLinus Torvalds #define ZFCP_MAX_OUTPUT_THRESHOLD 	1000	/* FIXME: tune */
1271da177e4SLinus Torvalds #define ZFCP_MIN_INPUT_THRESHOLD 	1	/* ignored by QDIO layer */
1281da177e4SLinus Torvalds #define ZFCP_MIN_OUTPUT_THRESHOLD 	1	/* ignored by QDIO layer */
1291da177e4SLinus Torvalds 
1301da177e4SLinus Torvalds #define QDIO_SCSI_QFMT			1	/* 1 for FSF */
131b4e44590SSwen Schillig #define QBUFF_PER_PAGE			(PAGE_SIZE / sizeof(struct qdio_buffer))
1321da177e4SLinus Torvalds 
1331da177e4SLinus Torvalds /********************* FSF SPECIFIC DEFINES *********************************/
1341da177e4SLinus Torvalds 
1351da177e4SLinus Torvalds #define ZFCP_ULP_INFO_VERSION                   26
1361da177e4SLinus Torvalds #define ZFCP_QTCB_VERSION	FSF_QTCB_CURRENT_VERSION
1371da177e4SLinus Torvalds /* ATTENTION: value must not be used by hardware */
1381da177e4SLinus Torvalds #define FSF_QTCB_UNSOLICITED_STATUS		0x6305
1391da177e4SLinus Torvalds #define ZFCP_STATUS_READ_FAILED_THRESHOLD	3
1401da177e4SLinus Torvalds #define ZFCP_STATUS_READS_RECOM		        FSF_STATUS_READS_RECOM
14122753fa5SAndreas Herrmann 
14222753fa5SAndreas Herrmann /* Do 1st retry in 1 second, then double the timeout for each following retry */
14318edcdbdSChristof Schmitt #define ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP	1
14422753fa5SAndreas Herrmann #define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES	7
1451da177e4SLinus Torvalds 
1461da177e4SLinus Torvalds /* timeout value for "default timer" for fsf requests */
1472abbe866SAndreas Herrmann #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
1481da177e4SLinus Torvalds 
1491da177e4SLinus Torvalds /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
1501da177e4SLinus Torvalds 
1511da177e4SLinus Torvalds typedef unsigned long long wwn_t;
1521da177e4SLinus Torvalds typedef unsigned long long fcp_lun_t;
1531da177e4SLinus Torvalds /* data length field may be at variable position in FCP-2 FCP_CMND IU */
1541da177e4SLinus Torvalds typedef unsigned int       fcp_dl_t;
1551da177e4SLinus Torvalds 
1561da177e4SLinus Torvalds #define ZFCP_FC_SERVICE_CLASS_DEFAULT	FSF_CLASS_3
1571da177e4SLinus Torvalds 
1581da177e4SLinus Torvalds /* timeout for name-server lookup (in seconds) */
1591da177e4SLinus Torvalds #define ZFCP_NS_GID_PN_TIMEOUT		10
1601da177e4SLinus Torvalds 
1611da177e4SLinus Torvalds /* largest SCSI command we can process */
1621da177e4SLinus Torvalds /* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */
1631da177e4SLinus Torvalds #define ZFCP_MAX_SCSI_CMND_LENGTH	255
1641da177e4SLinus Torvalds /* maximum number of commands in LUN queue (tagged queueing) */
1651da177e4SLinus Torvalds #define ZFCP_CMND_PER_LUN               32
1661da177e4SLinus Torvalds 
1671da177e4SLinus Torvalds /* task attribute values in FCP-2 FCP_CMND IU */
1681da177e4SLinus Torvalds #define SIMPLE_Q	0
1691da177e4SLinus Torvalds #define HEAD_OF_Q	1
1701da177e4SLinus Torvalds #define ORDERED_Q	2
1711da177e4SLinus Torvalds #define ACA_Q		4
1721da177e4SLinus Torvalds #define UNTAGGED	5
1731da177e4SLinus Torvalds 
1741da177e4SLinus Torvalds /* task management flags in FCP-2 FCP_CMND IU */
1751da177e4SLinus Torvalds #define FCP_CLEAR_ACA		0x40
1761da177e4SLinus Torvalds #define FCP_TARGET_RESET	0x20
1771da177e4SLinus Torvalds #define FCP_LOGICAL_UNIT_RESET	0x10
1781da177e4SLinus Torvalds #define FCP_CLEAR_TASK_SET	0x04
1791da177e4SLinus Torvalds #define FCP_ABORT_TASK_SET	0x02
1801da177e4SLinus Torvalds 
1811da177e4SLinus Torvalds #define FCP_CDB_LENGTH		16
1821da177e4SLinus Torvalds 
1831da177e4SLinus Torvalds #define ZFCP_DID_MASK           0x00FFFFFF
1841da177e4SLinus Torvalds 
1851da177e4SLinus Torvalds /* FCP(-2) FCP_CMND IU */
1861da177e4SLinus Torvalds struct fcp_cmnd_iu {
1871da177e4SLinus Torvalds 	fcp_lun_t fcp_lun;	   /* FCP logical unit number */
1881da177e4SLinus Torvalds 	u8  crn;	           /* command reference number */
1891da177e4SLinus Torvalds 	u8  reserved0:5;	   /* reserved */
1901da177e4SLinus Torvalds 	u8  task_attribute:3;	   /* task attribute */
1911da177e4SLinus Torvalds 	u8  task_management_flags; /* task management flags */
1921da177e4SLinus Torvalds 	u8  add_fcp_cdb_length:6;  /* additional FCP_CDB length */
1931da177e4SLinus Torvalds 	u8  rddata:1;              /* read data */
1941da177e4SLinus Torvalds 	u8  wddata:1;              /* write data */
1951da177e4SLinus Torvalds 	u8  fcp_cdb[FCP_CDB_LENGTH];
1961da177e4SLinus Torvalds } __attribute__((packed));
1971da177e4SLinus Torvalds 
1981da177e4SLinus Torvalds /* FCP(-2) FCP_RSP IU */
1991da177e4SLinus Torvalds struct fcp_rsp_iu {
2001da177e4SLinus Torvalds 	u8  reserved0[10];
2011da177e4SLinus Torvalds 	union {
2021da177e4SLinus Torvalds 		struct {
2031da177e4SLinus Torvalds 			u8 reserved1:3;
2041da177e4SLinus Torvalds 			u8 fcp_conf_req:1;
2051da177e4SLinus Torvalds 			u8 fcp_resid_under:1;
2061da177e4SLinus Torvalds 			u8 fcp_resid_over:1;
2071da177e4SLinus Torvalds 			u8 fcp_sns_len_valid:1;
2081da177e4SLinus Torvalds 			u8 fcp_rsp_len_valid:1;
2091da177e4SLinus Torvalds 		} bits;
2101da177e4SLinus Torvalds 		u8 value;
2111da177e4SLinus Torvalds 	} validity;
2121da177e4SLinus Torvalds 	u8  scsi_status;
2131da177e4SLinus Torvalds 	u32 fcp_resid;
2141da177e4SLinus Torvalds 	u32 fcp_sns_len;
2151da177e4SLinus Torvalds 	u32 fcp_rsp_len;
2161da177e4SLinus Torvalds } __attribute__((packed));
2171da177e4SLinus Torvalds 
2181da177e4SLinus Torvalds 
2191da177e4SLinus Torvalds #define RSP_CODE_GOOD		 0
2201da177e4SLinus Torvalds #define RSP_CODE_LENGTH_MISMATCH 1
2211da177e4SLinus Torvalds #define RSP_CODE_FIELD_INVALID	 2
2221da177e4SLinus Torvalds #define RSP_CODE_RO_MISMATCH	 3
2231da177e4SLinus Torvalds #define RSP_CODE_TASKMAN_UNSUPP	 4
2241da177e4SLinus Torvalds #define RSP_CODE_TASKMAN_FAILED	 5
2251da177e4SLinus Torvalds 
2261da177e4SLinus Torvalds /* see fc-fs */
2271da177e4SLinus Torvalds #define LS_RSCN  0x61040000
22806506d00SAndreas Herrmann #define LS_LOGO  0x05000000
22906506d00SAndreas Herrmann #define LS_PLOGI 0x03000000
2301da177e4SLinus Torvalds 
2311da177e4SLinus Torvalds struct fcp_rscn_head {
2321da177e4SLinus Torvalds         u8  command;
2331da177e4SLinus Torvalds         u8  page_length; /* always 0x04 */
2341da177e4SLinus Torvalds         u16 payload_len;
2351da177e4SLinus Torvalds } __attribute__((packed));
2361da177e4SLinus Torvalds 
2371da177e4SLinus Torvalds struct fcp_rscn_element {
2381da177e4SLinus Torvalds         u8  reserved:2;
2391da177e4SLinus Torvalds         u8  event_qual:4;
2401da177e4SLinus Torvalds         u8  addr_format:2;
2411da177e4SLinus Torvalds         u32 nport_did:24;
2421da177e4SLinus Torvalds } __attribute__((packed));
2431da177e4SLinus Torvalds 
2441da177e4SLinus Torvalds #define ZFCP_PORT_ADDRESS   0x0
2451da177e4SLinus Torvalds #define ZFCP_AREA_ADDRESS   0x1
2461da177e4SLinus Torvalds #define ZFCP_DOMAIN_ADDRESS 0x2
2471da177e4SLinus Torvalds #define ZFCP_FABRIC_ADDRESS 0x3
2481da177e4SLinus Torvalds 
2491da177e4SLinus Torvalds #define ZFCP_PORTS_RANGE_PORT   0xFFFFFF
2501da177e4SLinus Torvalds #define ZFCP_PORTS_RANGE_AREA   0xFFFF00
2511da177e4SLinus Torvalds #define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
2521da177e4SLinus Torvalds #define ZFCP_PORTS_RANGE_FABRIC 0x000000
2531da177e4SLinus Torvalds 
2541da177e4SLinus Torvalds #define ZFCP_NO_PORTS_PER_AREA    0x100
2551da177e4SLinus Torvalds #define ZFCP_NO_PORTS_PER_DOMAIN  0x10000
2561da177e4SLinus Torvalds #define ZFCP_NO_PORTS_PER_FABRIC  0x1000000
2571da177e4SLinus Torvalds 
2581da177e4SLinus Torvalds /* see fc-ph */
2591da177e4SLinus Torvalds struct fcp_logo {
2601da177e4SLinus Torvalds         u32 command;
2611da177e4SLinus Torvalds         u32 nport_did;
2621da177e4SLinus Torvalds         wwn_t nport_wwpn;
2631da177e4SLinus Torvalds } __attribute__((packed));
2641da177e4SLinus Torvalds 
2651da177e4SLinus Torvalds /*
2661da177e4SLinus Torvalds  * FC-FS stuff
2671da177e4SLinus Torvalds  */
2681da177e4SLinus Torvalds #define R_A_TOV				10 /* seconds */
2691da177e4SLinus Torvalds #define ZFCP_ELS_TIMEOUT		(2 * R_A_TOV)
2701da177e4SLinus Torvalds 
2711da177e4SLinus Torvalds #define ZFCP_LS_RLS			0x0f
2721da177e4SLinus Torvalds #define ZFCP_LS_ADISC			0x52
2731da177e4SLinus Torvalds #define ZFCP_LS_RPS			0x56
2741da177e4SLinus Torvalds #define ZFCP_LS_RSCN			0x61
2751da177e4SLinus Torvalds #define ZFCP_LS_RNID			0x78
2761da177e4SLinus Torvalds 
2771da177e4SLinus Torvalds struct zfcp_ls_rjt_par {
2781da177e4SLinus Torvalds 	u8 action;
2791da177e4SLinus Torvalds  	u8 reason_code;
2801da177e4SLinus Torvalds  	u8 reason_expl;
2811da177e4SLinus Torvalds  	u8 vendor_unique;
2821da177e4SLinus Torvalds } __attribute__ ((packed));
2831da177e4SLinus Torvalds 
2841da177e4SLinus Torvalds struct zfcp_ls_adisc {
2851da177e4SLinus Torvalds 	u8		code;
2861da177e4SLinus Torvalds 	u8		field[3];
2871da177e4SLinus Torvalds 	u32		hard_nport_id;
2881da177e4SLinus Torvalds 	u64		wwpn;
2891da177e4SLinus Torvalds 	u64		wwnn;
2901da177e4SLinus Torvalds 	u32		nport_id;
2911da177e4SLinus Torvalds } __attribute__ ((packed));
2921da177e4SLinus Torvalds 
2931da177e4SLinus Torvalds struct zfcp_ls_adisc_acc {
2941da177e4SLinus Torvalds 	u8		code;
2951da177e4SLinus Torvalds 	u8		field[3];
2961da177e4SLinus Torvalds 	u32		hard_nport_id;
2971da177e4SLinus Torvalds 	u64		wwpn;
2981da177e4SLinus Torvalds 	u64		wwnn;
2991da177e4SLinus Torvalds 	u32		nport_id;
3001da177e4SLinus Torvalds } __attribute__ ((packed));
3011da177e4SLinus Torvalds 
3021da177e4SLinus Torvalds struct zfcp_rc_entry {
3031da177e4SLinus Torvalds 	u8 code;
3041da177e4SLinus Torvalds 	const char *description;
3051da177e4SLinus Torvalds };
3061da177e4SLinus Torvalds 
3071da177e4SLinus Torvalds /*
3081da177e4SLinus Torvalds  * FC-GS-2 stuff
3091da177e4SLinus Torvalds  */
3101da177e4SLinus Torvalds #define ZFCP_CT_REVISION		0x01
3111da177e4SLinus Torvalds #define ZFCP_CT_DIRECTORY_SERVICE	0xFC
3121da177e4SLinus Torvalds #define ZFCP_CT_NAME_SERVER		0x02
3131da177e4SLinus Torvalds #define ZFCP_CT_SYNCHRONOUS		0x00
3141da177e4SLinus Torvalds #define ZFCP_CT_GID_PN			0x0121
3151da177e4SLinus Torvalds #define ZFCP_CT_MAX_SIZE		0x1020
3161da177e4SLinus Torvalds #define ZFCP_CT_ACCEPT			0x8002
3171da177e4SLinus Torvalds #define ZFCP_CT_REJECT			0x8001
3181da177e4SLinus Torvalds 
3191da177e4SLinus Torvalds /*
3201da177e4SLinus Torvalds  * FC-GS-4 stuff
3211da177e4SLinus Torvalds  */
3221da177e4SLinus Torvalds #define ZFCP_CT_TIMEOUT			(3 * R_A_TOV)
3231da177e4SLinus Torvalds 
3241da177e4SLinus Torvalds /******************** LOGGING MACROS AND DEFINES *****************************/
3251da177e4SLinus Torvalds 
3261da177e4SLinus Torvalds /*
3271da177e4SLinus Torvalds  * Logging may be applied on certain kinds of driver operations
3281da177e4SLinus Torvalds  * independently. Additionally, different log-levels are supported for
3291da177e4SLinus Torvalds  * each of these areas.
3301da177e4SLinus Torvalds  */
3311da177e4SLinus Torvalds 
3321da177e4SLinus Torvalds #define ZFCP_NAME               "zfcp"
3331da177e4SLinus Torvalds 
3341da177e4SLinus Torvalds /* independent log areas */
3351da177e4SLinus Torvalds #define ZFCP_LOG_AREA_OTHER	0
3361da177e4SLinus Torvalds #define ZFCP_LOG_AREA_SCSI	1
3371da177e4SLinus Torvalds #define ZFCP_LOG_AREA_FSF	2
3381da177e4SLinus Torvalds #define ZFCP_LOG_AREA_CONFIG	3
3391da177e4SLinus Torvalds #define ZFCP_LOG_AREA_CIO	4
3401da177e4SLinus Torvalds #define ZFCP_LOG_AREA_QDIO	5
3411da177e4SLinus Torvalds #define ZFCP_LOG_AREA_ERP	6
3421da177e4SLinus Torvalds #define ZFCP_LOG_AREA_FC	7
3431da177e4SLinus Torvalds 
3441da177e4SLinus Torvalds /* log level values*/
3451da177e4SLinus Torvalds #define ZFCP_LOG_LEVEL_NORMAL	0
3461da177e4SLinus Torvalds #define ZFCP_LOG_LEVEL_INFO	1
3471da177e4SLinus Torvalds #define ZFCP_LOG_LEVEL_DEBUG	2
3481da177e4SLinus Torvalds #define ZFCP_LOG_LEVEL_TRACE	3
3491da177e4SLinus Torvalds 
3501da177e4SLinus Torvalds /*
3511da177e4SLinus Torvalds  * this allows removal of logging code by the preprocessor
3521da177e4SLinus Torvalds  * (the most detailed log level still to be compiled in is specified,
3531da177e4SLinus Torvalds  * higher log levels are removed)
3541da177e4SLinus Torvalds  */
3551da177e4SLinus Torvalds #define ZFCP_LOG_LEVEL_LIMIT	ZFCP_LOG_LEVEL_TRACE
3561da177e4SLinus Torvalds 
3571da177e4SLinus Torvalds /* get "loglevel" nibble assignment */
3581da177e4SLinus Torvalds #define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \
3591da177e4SLinus Torvalds 	       ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF)
3601da177e4SLinus Torvalds 
3611da177e4SLinus Torvalds /* set "loglevel" nibble */
3621da177e4SLinus Torvalds #define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \
3631da177e4SLinus Torvalds 	       (value << (zfcp_lognibble << 2))
3641da177e4SLinus Torvalds 
3651da177e4SLinus Torvalds /* all log-level defaults are combined to generate initial log-level */
3661da177e4SLinus Torvalds #define ZFCP_LOG_LEVEL_DEFAULTS \
3671da177e4SLinus Torvalds 	(ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_OTHER) | \
3681da177e4SLinus Torvalds 	 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_SCSI) | \
3691da177e4SLinus Torvalds 	 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FSF) | \
3701da177e4SLinus Torvalds 	 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CONFIG) | \
3711da177e4SLinus Torvalds 	 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CIO) | \
3721da177e4SLinus Torvalds 	 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_QDIO) | \
3731da177e4SLinus Torvalds 	 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_ERP) | \
3741da177e4SLinus Torvalds 	 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FC))
3751da177e4SLinus Torvalds 
3761da177e4SLinus Torvalds /* check whether we have the right level for logging */
3771da177e4SLinus Torvalds #define ZFCP_LOG_CHECK(level) \
3781da177e4SLinus Torvalds 	((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level)
3791da177e4SLinus Torvalds 
3801da177e4SLinus Torvalds /* logging routine for zfcp */
3811da177e4SLinus Torvalds #define _ZFCP_LOG(fmt, args...) \
3822a2cf6b1SHarvey Harrison 	printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __func__, \
3831da177e4SLinus Torvalds 	       __LINE__ , ##args)
3841da177e4SLinus Torvalds 
3851da177e4SLinus Torvalds #define ZFCP_LOG(level, fmt, args...) \
3861da177e4SLinus Torvalds do { \
3871da177e4SLinus Torvalds 	if (ZFCP_LOG_CHECK(level)) \
3881da177e4SLinus Torvalds 		_ZFCP_LOG(fmt, ##args); \
3891da177e4SLinus Torvalds } while (0)
3901da177e4SLinus Torvalds 
3911da177e4SLinus Torvalds #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL
39239b083feSHeiko Carstens # define ZFCP_LOG_NORMAL(fmt, args...)	do { } while (0)
3931da177e4SLinus Torvalds #else
3941da177e4SLinus Torvalds # define ZFCP_LOG_NORMAL(fmt, args...) \
3951da177e4SLinus Torvalds do { \
3961da177e4SLinus Torvalds 	if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \
3971da177e4SLinus Torvalds 		printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
3981da177e4SLinus Torvalds } while (0)
3991da177e4SLinus Torvalds #endif
4001da177e4SLinus Torvalds 
4011da177e4SLinus Torvalds #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO
40239b083feSHeiko Carstens # define ZFCP_LOG_INFO(fmt, args...)	do { } while (0)
4031da177e4SLinus Torvalds #else
4041da177e4SLinus Torvalds # define ZFCP_LOG_INFO(fmt, args...) \
4051da177e4SLinus Torvalds do { \
4061da177e4SLinus Torvalds 	if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \
4071da177e4SLinus Torvalds 		printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
4081da177e4SLinus Torvalds } while (0)
4091da177e4SLinus Torvalds #endif
4101da177e4SLinus Torvalds 
4111da177e4SLinus Torvalds #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG
41239b083feSHeiko Carstens # define ZFCP_LOG_DEBUG(fmt, args...)	do { } while (0)
4131da177e4SLinus Torvalds #else
4141da177e4SLinus Torvalds # define ZFCP_LOG_DEBUG(fmt, args...) \
4151da177e4SLinus Torvalds 	ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args)
4161da177e4SLinus Torvalds #endif
4171da177e4SLinus Torvalds 
4181da177e4SLinus Torvalds #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE
41939b083feSHeiko Carstens # define ZFCP_LOG_TRACE(fmt, args...)	do { } while (0)
4201da177e4SLinus Torvalds #else
4211da177e4SLinus Torvalds # define ZFCP_LOG_TRACE(fmt, args...) \
4221da177e4SLinus Torvalds 	ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args)
4231da177e4SLinus Torvalds #endif
4241da177e4SLinus Torvalds 
4251da177e4SLinus Torvalds /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
4261da177e4SLinus Torvalds 
4271da177e4SLinus Torvalds /*
4281da177e4SLinus Torvalds  * Note, the leftmost status byte is common among adapter, port
4291da177e4SLinus Torvalds  * and unit
4301da177e4SLinus Torvalds  */
4311da177e4SLinus Torvalds #define ZFCP_COMMON_FLAGS			0xfff00000
4321da177e4SLinus Torvalds 
4331da177e4SLinus Torvalds /* common status bits */
4341da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_REMOVE		0x80000000
4351da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_RUNNING		0x40000000
4361da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_ERP_FAILED		0x20000000
4371da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_UNBLOCKED		0x10000000
4381da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_OPENING              0x08000000
4391da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_OPEN                 0x04000000
4401da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_CLOSING              0x02000000
4411da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_ERP_INUSE		0x01000000
4421da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_ACCESS_DENIED	0x00800000
443d736a27bSAndreas Herrmann #define ZFCP_STATUS_COMMON_ACCESS_BOXED		0x00400000
4441da177e4SLinus Torvalds 
4451da177e4SLinus Torvalds /* adapter status */
4461da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_QDIOUP		0x00000002
4471da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_REGISTERED		0x00000004
4481da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_XCONFIG_OK		0x00000008
4491da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT	0x00000010
4501da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP	0x00000020
4511da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL	0x00000080
4521da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_ERP_PENDING		0x00000100
4531da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED	0x00000200
454aef4a983SMaxim Shchetynin #define ZFCP_STATUS_ADAPTER_XPORT_OK		0x00000800
4551da177e4SLinus Torvalds 
4561da177e4SLinus Torvalds /* FC-PH/FC-GS well-known address identifiers for generic services */
4571da177e4SLinus Torvalds #define ZFCP_DID_MANAGEMENT_SERVICE		0xFFFFFA
4581da177e4SLinus Torvalds #define ZFCP_DID_TIME_SERVICE			0xFFFFFB
4591da177e4SLinus Torvalds #define ZFCP_DID_DIRECTORY_SERVICE		0xFFFFFC
4601da177e4SLinus Torvalds #define ZFCP_DID_ALIAS_SERVICE			0xFFFFF8
4611da177e4SLinus Torvalds #define ZFCP_DID_KEY_DISTRIBUTION_SERVICE	0xFFFFF7
4621da177e4SLinus Torvalds 
4631da177e4SLinus Torvalds /* remote port status */
4641da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_PHYS_OPEN		0x00000001
4651da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_DID_DID		0x00000002
4661da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_PHYS_CLOSING		0x00000004
4671da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_NO_WWPN		0x00000008
4681da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_NO_SCSI_ID		0x00000010
4691da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_INVALID_WWPN		0x00000020
4701da177e4SLinus Torvalds 
4711da177e4SLinus Torvalds /* for ports with well known addresses */
4721da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_WKA \
4731da177e4SLinus Torvalds 		(ZFCP_STATUS_PORT_NO_WWPN | \
4741da177e4SLinus Torvalds 		 ZFCP_STATUS_PORT_NO_SCSI_ID)
4751da177e4SLinus Torvalds 
4761da177e4SLinus Torvalds /* logical unit status */
4771da177e4SLinus Torvalds #define ZFCP_STATUS_UNIT_TEMPORARY		0x00000002
4781da177e4SLinus Torvalds #define ZFCP_STATUS_UNIT_SHARED			0x00000004
4791da177e4SLinus Torvalds #define ZFCP_STATUS_UNIT_READONLY		0x00000008
480ad58f7dbSAndreas Herrmann #define ZFCP_STATUS_UNIT_REGISTERED		0x00000010
4815f852be9SChristof Schmitt #define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING	0x00000020
4821da177e4SLinus Torvalds 
4831da177e4SLinus Torvalds /* FSF request status (this does not have a common part) */
4841da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_NOT_INIT		0x00000000
4851da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_POOL  		0x00000001
4861da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT	0x00000002
4871da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_COMPLETED		0x00000004
4881da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_ERROR		0x00000008
4891da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_CLEANUP		0x00000010
4901da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_ABORTING		0x00000020
4911da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED	0x00000040
4921da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED       0x00000080
4931da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_ABORTED              0x00000100
4941da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED         0x00000200
4951da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP        0x00000400
4961da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_RETRY                0x00000800
4971da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_DISMISSED            0x00001000
4981da177e4SLinus Torvalds 
4991da177e4SLinus Torvalds /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
5001da177e4SLinus Torvalds 
5011da177e4SLinus Torvalds #define ZFCP_MAX_ERPS                   3
5021da177e4SLinus Torvalds 
5031da177e4SLinus Torvalds #define ZFCP_ERP_FSFREQ_TIMEOUT		(30 * HZ)
5041da177e4SLinus Torvalds #define ZFCP_ERP_MEMWAIT_TIMEOUT	HZ
5051da177e4SLinus Torvalds 
5061da177e4SLinus Torvalds #define ZFCP_STATUS_ERP_TIMEDOUT	0x10000000
5071da177e4SLinus Torvalds #define ZFCP_STATUS_ERP_CLOSE_ONLY	0x01000000
5081da177e4SLinus Torvalds #define ZFCP_STATUS_ERP_DISMISSING	0x00100000
5091da177e4SLinus Torvalds #define ZFCP_STATUS_ERP_DISMISSED	0x00200000
5101da177e4SLinus Torvalds #define ZFCP_STATUS_ERP_LOWMEM		0x00400000
5111da177e4SLinus Torvalds 
5121da177e4SLinus Torvalds #define ZFCP_ERP_STEP_UNINITIALIZED	0x00000000
5131da177e4SLinus Torvalds #define ZFCP_ERP_STEP_FSF_XCONFIG	0x00000001
5141da177e4SLinus Torvalds #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING	0x00000010
5151da177e4SLinus Torvalds #define ZFCP_ERP_STEP_PORT_CLOSING	0x00000100
5161da177e4SLinus Torvalds #define ZFCP_ERP_STEP_NAMESERVER_OPEN	0x00000200
5171da177e4SLinus Torvalds #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP	0x00000400
5181da177e4SLinus Torvalds #define ZFCP_ERP_STEP_PORT_OPENING	0x00000800
5191da177e4SLinus Torvalds #define ZFCP_ERP_STEP_UNIT_CLOSING	0x00001000
5201da177e4SLinus Torvalds #define ZFCP_ERP_STEP_UNIT_OPENING	0x00002000
5211da177e4SLinus Torvalds 
5221da177e4SLinus Torvalds /* Ordered by escalation level (necessary for proper erp-code operation) */
5231da177e4SLinus Torvalds #define ZFCP_ERP_ACTION_REOPEN_ADAPTER		0x4
5241da177e4SLinus Torvalds #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED	0x3
5251da177e4SLinus Torvalds #define ZFCP_ERP_ACTION_REOPEN_PORT		0x2
5261da177e4SLinus Torvalds #define ZFCP_ERP_ACTION_REOPEN_UNIT		0x1
5271da177e4SLinus Torvalds 
5281da177e4SLinus Torvalds #define ZFCP_ERP_ACTION_RUNNING			0x1
5291da177e4SLinus Torvalds #define ZFCP_ERP_ACTION_READY			0x2
5301da177e4SLinus Torvalds 
5311da177e4SLinus Torvalds #define ZFCP_ERP_SUCCEEDED	0x0
5321da177e4SLinus Torvalds #define ZFCP_ERP_FAILED		0x1
5331da177e4SLinus Torvalds #define ZFCP_ERP_CONTINUES	0x2
5341da177e4SLinus Torvalds #define ZFCP_ERP_EXIT		0x3
5351da177e4SLinus Torvalds #define ZFCP_ERP_DISMISSED	0x4
5361da177e4SLinus Torvalds #define ZFCP_ERP_NOMEM		0x5
5371da177e4SLinus Torvalds 
5381da177e4SLinus Torvalds 
5391da177e4SLinus Torvalds /******************** CFDC SPECIFIC STUFF *****************************/
5401da177e4SLinus Torvalds 
5411da177e4SLinus Torvalds /* Firewall data channel sense data record */
5421da177e4SLinus Torvalds struct zfcp_cfdc_sense_data {
5431da177e4SLinus Torvalds 	u32 signature;           /* Request signature */
5441da177e4SLinus Torvalds 	u32 devno;               /* FCP adapter device number */
5451da177e4SLinus Torvalds 	u32 command;             /* Command code */
5461da177e4SLinus Torvalds 	u32 fsf_status;          /* FSF request status and status qualifier */
5471da177e4SLinus Torvalds 	u8  fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
5481da177e4SLinus Torvalds 	u8  payloads[256];       /* Access conflicts list */
5491da177e4SLinus Torvalds 	u8  control_file[0];     /* Access control table */
5501da177e4SLinus Torvalds };
5511da177e4SLinus Torvalds 
5521da177e4SLinus Torvalds #define ZFCP_CFDC_SIGNATURE			0xCFDCACDF
5531da177e4SLinus Torvalds 
5541da177e4SLinus Torvalds #define ZFCP_CFDC_CMND_DOWNLOAD_NORMAL		0x00010001
5551da177e4SLinus Torvalds #define ZFCP_CFDC_CMND_DOWNLOAD_FORCE		0x00010101
5561da177e4SLinus Torvalds #define ZFCP_CFDC_CMND_FULL_ACCESS		0x00000201
5571da177e4SLinus Torvalds #define ZFCP_CFDC_CMND_RESTRICTED_ACCESS	0x00000401
5581da177e4SLinus Torvalds #define ZFCP_CFDC_CMND_UPLOAD			0x00010002
5591da177e4SLinus Torvalds 
5601da177e4SLinus Torvalds #define ZFCP_CFDC_DOWNLOAD			0x00000001
5611da177e4SLinus Torvalds #define ZFCP_CFDC_UPLOAD			0x00000002
5621da177e4SLinus Torvalds #define ZFCP_CFDC_WITH_CONTROL_FILE		0x00010000
5631da177e4SLinus Torvalds 
5641da177e4SLinus Torvalds #define ZFCP_CFDC_DEV_NAME			"zfcp_cfdc"
5651da177e4SLinus Torvalds #define ZFCP_CFDC_DEV_MAJOR			MISC_MAJOR
5661da177e4SLinus Torvalds #define ZFCP_CFDC_DEV_MINOR			MISC_DYNAMIC_MINOR
5671da177e4SLinus Torvalds 
5681da177e4SLinus Torvalds #define ZFCP_CFDC_MAX_CONTROL_FILE_SIZE		127 * 1024
5691da177e4SLinus Torvalds 
5701da177e4SLinus Torvalds /************************* STRUCTURE DEFINITIONS *****************************/
5711da177e4SLinus Torvalds 
5721da177e4SLinus Torvalds struct zfcp_fsf_req;
5731da177e4SLinus Torvalds 
5741da177e4SLinus Torvalds /* holds various memory pools of an adapter */
5751da177e4SLinus Torvalds struct zfcp_adapter_mempool {
5761da177e4SLinus Torvalds 	mempool_t *fsf_req_erp;
5771da177e4SLinus Torvalds 	mempool_t *fsf_req_scsi;
5781da177e4SLinus Torvalds 	mempool_t *fsf_req_abort;
5791da177e4SLinus Torvalds 	mempool_t *fsf_req_status_read;
5801da177e4SLinus Torvalds 	mempool_t *data_status_read;
5811da177e4SLinus Torvalds 	mempool_t *data_gid_pn;
5821da177e4SLinus Torvalds };
5831da177e4SLinus Torvalds 
5841da177e4SLinus Torvalds /*
5851da177e4SLinus Torvalds  * header for CT_IU
5861da177e4SLinus Torvalds  */
5871da177e4SLinus Torvalds struct ct_hdr {
5881da177e4SLinus Torvalds 	u8 revision;		// 0x01
5891da177e4SLinus Torvalds 	u8 in_id[3];		// 0x00
5901da177e4SLinus Torvalds 	u8 gs_type;		// 0xFC	Directory Service
5911da177e4SLinus Torvalds 	u8 gs_subtype;		// 0x02	Name Server
5921da177e4SLinus Torvalds 	u8 options;		// 0x00 single bidirectional exchange
5931da177e4SLinus Torvalds 	u8 reserved0;
5941da177e4SLinus Torvalds 	u16 cmd_rsp_code;	// 0x0121 GID_PN, or 0x0100 GA_NXT
5951da177e4SLinus Torvalds 	u16 max_res_size;	// <= (4096 - 16) / 4
5961da177e4SLinus Torvalds 	u8 reserved1;
5971da177e4SLinus Torvalds 	u8 reason_code;
5981da177e4SLinus Torvalds 	u8 reason_code_expl;
5991da177e4SLinus Torvalds 	u8 vendor_unique;
6001da177e4SLinus Torvalds } __attribute__ ((packed));
6011da177e4SLinus Torvalds 
6021da177e4SLinus Torvalds /* nameserver request CT_IU -- for requests where
6031da177e4SLinus Torvalds  * a port name is required */
6041da177e4SLinus Torvalds struct ct_iu_gid_pn_req {
6051da177e4SLinus Torvalds 	struct ct_hdr header;
6061da177e4SLinus Torvalds 	wwn_t wwpn;
6071da177e4SLinus Torvalds } __attribute__ ((packed));
6081da177e4SLinus Torvalds 
6091da177e4SLinus Torvalds /* FS_ACC IU and data unit for GID_PN nameserver request */
6101da177e4SLinus Torvalds struct ct_iu_gid_pn_resp {
6111da177e4SLinus Torvalds 	struct ct_hdr header;
61213e1e1f0SAndreas Herrmann 	u32 d_id;
6131da177e4SLinus Torvalds } __attribute__ ((packed));
6141da177e4SLinus Torvalds 
6151da177e4SLinus Torvalds typedef void (*zfcp_send_ct_handler_t)(unsigned long);
6161da177e4SLinus Torvalds 
6171da177e4SLinus Torvalds /**
6181da177e4SLinus Torvalds  * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
6191da177e4SLinus Torvalds  * @port: port where the request is sent to
6201da177e4SLinus Torvalds  * @req: scatter-gather list for request
6211da177e4SLinus Torvalds  * @resp: scatter-gather list for response
6221da177e4SLinus Torvalds  * @req_count: number of elements in request scatter-gather list
6231da177e4SLinus Torvalds  * @resp_count: number of elements in response scatter-gather list
6241da177e4SLinus Torvalds  * @handler: handler function (called for response to the request)
6251da177e4SLinus Torvalds  * @handler_data: data passed to handler function
6261da177e4SLinus Torvalds  * @pool: pointer to memory pool for ct request structure
6271da177e4SLinus Torvalds  * @timeout: FSF timeout for this request
6281da177e4SLinus Torvalds  * @completion: completion for synchronization purposes
6291da177e4SLinus Torvalds  * @status: used to pass error status to calling function
6301da177e4SLinus Torvalds  */
6311da177e4SLinus Torvalds struct zfcp_send_ct {
6321da177e4SLinus Torvalds 	struct zfcp_port *port;
6331da177e4SLinus Torvalds 	struct scatterlist *req;
6341da177e4SLinus Torvalds 	struct scatterlist *resp;
6351da177e4SLinus Torvalds 	unsigned int req_count;
6361da177e4SLinus Torvalds 	unsigned int resp_count;
6371da177e4SLinus Torvalds 	zfcp_send_ct_handler_t handler;
6381da177e4SLinus Torvalds 	unsigned long handler_data;
6391da177e4SLinus Torvalds 	mempool_t *pool;
6401da177e4SLinus Torvalds 	int timeout;
6411da177e4SLinus Torvalds 	struct completion *completion;
6421da177e4SLinus Torvalds 	int status;
6431da177e4SLinus Torvalds };
6441da177e4SLinus Torvalds 
6451da177e4SLinus Torvalds /* used for name server requests in error recovery */
6461da177e4SLinus Torvalds struct zfcp_gid_pn_data {
6471da177e4SLinus Torvalds 	struct zfcp_send_ct ct;
6481da177e4SLinus Torvalds 	struct scatterlist req;
6491da177e4SLinus Torvalds 	struct scatterlist resp;
6501da177e4SLinus Torvalds 	struct ct_iu_gid_pn_req ct_iu_req;
6511da177e4SLinus Torvalds 	struct ct_iu_gid_pn_resp ct_iu_resp;
6521da177e4SLinus Torvalds         struct zfcp_port *port;
6531da177e4SLinus Torvalds };
6541da177e4SLinus Torvalds 
6551da177e4SLinus Torvalds typedef void (*zfcp_send_els_handler_t)(unsigned long);
6561da177e4SLinus Torvalds 
6571da177e4SLinus Torvalds /**
6581da177e4SLinus Torvalds  * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
6591da177e4SLinus Torvalds  * @adapter: adapter where request is sent from
66064b29a13SAndreas Herrmann  * @port: port where ELS is destinated (port reference count has to be increased)
6611da177e4SLinus Torvalds  * @d_id: destiniation id of port where request is sent to
6621da177e4SLinus Torvalds  * @req: scatter-gather list for request
6631da177e4SLinus Torvalds  * @resp: scatter-gather list for response
6641da177e4SLinus Torvalds  * @req_count: number of elements in request scatter-gather list
6651da177e4SLinus Torvalds  * @resp_count: number of elements in response scatter-gather list
6661da177e4SLinus Torvalds  * @handler: handler function (called for response to the request)
6671da177e4SLinus Torvalds  * @handler_data: data passed to handler function
6681da177e4SLinus Torvalds  * @completion: completion for synchronization purposes
6691da177e4SLinus Torvalds  * @ls_code: hex code of ELS command
6701da177e4SLinus Torvalds  * @status: used to pass error status to calling function
6711da177e4SLinus Torvalds  */
6721da177e4SLinus Torvalds struct zfcp_send_els {
6731da177e4SLinus Torvalds 	struct zfcp_adapter *adapter;
67464b29a13SAndreas Herrmann 	struct zfcp_port *port;
67513e1e1f0SAndreas Herrmann 	u32 d_id;
6761da177e4SLinus Torvalds 	struct scatterlist *req;
6771da177e4SLinus Torvalds 	struct scatterlist *resp;
6781da177e4SLinus Torvalds 	unsigned int req_count;
6791da177e4SLinus Torvalds 	unsigned int resp_count;
6801da177e4SLinus Torvalds 	zfcp_send_els_handler_t handler;
6811da177e4SLinus Torvalds 	unsigned long handler_data;
6821da177e4SLinus Torvalds 	struct completion *completion;
6831da177e4SLinus Torvalds 	int ls_code;
6841da177e4SLinus Torvalds 	int status;
6851da177e4SLinus Torvalds };
6861da177e4SLinus Torvalds 
6871da177e4SLinus Torvalds struct zfcp_qdio_queue {
6881da177e4SLinus Torvalds 	struct qdio_buffer *buffer[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
6891da177e4SLinus Torvalds 	u8		   free_index;	      /* index of next free bfr
6901da177e4SLinus Torvalds 						 in queue (free_count>0) */
6911da177e4SLinus Torvalds 	atomic_t           free_count;	      /* number of free buffers
6921da177e4SLinus Torvalds 						 in queue */
6931da177e4SLinus Torvalds 	rwlock_t	   queue_lock;	      /* lock for operations on queue */
6941da177e4SLinus Torvalds         int                distance_from_int; /* SBALs used since PCI indication
6951da177e4SLinus Torvalds 						 was last set */
6961da177e4SLinus Torvalds };
6971da177e4SLinus Torvalds 
6981da177e4SLinus Torvalds struct zfcp_erp_action {
6991da177e4SLinus Torvalds 	struct list_head list;
7001da177e4SLinus Torvalds 	int action;	              /* requested action code */
7011da177e4SLinus Torvalds 	struct zfcp_adapter *adapter; /* device which should be recovered */
7021da177e4SLinus Torvalds 	struct zfcp_port *port;
7031da177e4SLinus Torvalds 	struct zfcp_unit *unit;
7041da177e4SLinus Torvalds 	volatile u32 status;	      /* recovery status */
7051da177e4SLinus Torvalds 	u32 step;	              /* active step of this erp action */
7061da177e4SLinus Torvalds 	struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
7071da177e4SLinus Torvalds 					 for this action */
7081da177e4SLinus Torvalds 	struct timer_list timer;
7091da177e4SLinus Torvalds };
7101da177e4SLinus Torvalds 
711c9615858SChristof Schmitt struct fsf_latency_record {
712c9615858SChristof Schmitt 	u32 min;
713c9615858SChristof Schmitt 	u32 max;
714c9615858SChristof Schmitt 	u64 sum;
715c9615858SChristof Schmitt };
716c9615858SChristof Schmitt 
717c9615858SChristof Schmitt struct latency_cont {
718c9615858SChristof Schmitt 	struct fsf_latency_record channel;
719c9615858SChristof Schmitt 	struct fsf_latency_record fabric;
720c9615858SChristof Schmitt 	u64 counter;
721c9615858SChristof Schmitt };
722c9615858SChristof Schmitt 
723c9615858SChristof Schmitt struct zfcp_latencies {
724c9615858SChristof Schmitt 	struct latency_cont read;
725c9615858SChristof Schmitt 	struct latency_cont write;
726c9615858SChristof Schmitt 	struct latency_cont cmd;
727c9615858SChristof Schmitt 	spinlock_t lock;
728c9615858SChristof Schmitt };
7291da177e4SLinus Torvalds 
7301da177e4SLinus Torvalds struct zfcp_adapter {
7311da177e4SLinus Torvalds 	struct list_head	list;              /* list of adapters */
7321da177e4SLinus Torvalds 	atomic_t                refcount;          /* reference count */
7331da177e4SLinus Torvalds 	wait_queue_head_t	remove_wq;         /* can be used to wait for
7341da177e4SLinus Torvalds 						      refcount drop to zero */
7356f71d9bcS 	wwn_t			peer_wwnn;	   /* P2P peer WWNN */
7366f71d9bcS 	wwn_t			peer_wwpn;	   /* P2P peer WWPN */
73713e1e1f0SAndreas Herrmann 	u32			peer_d_id;	   /* P2P peer D_ID */
7381da177e4SLinus Torvalds 	struct ccw_device       *ccw_device;	   /* S/390 ccw device */
7391da177e4SLinus Torvalds 	u32			hydra_version;	   /* Hydra version */
7401da177e4SLinus Torvalds 	u32			fsf_lic_version;
741aef4a983SMaxim Shchetynin 	u32			adapter_features;  /* FCP channel features */
742aef4a983SMaxim Shchetynin 	u32			connection_features; /* host connection features */
7431da177e4SLinus Torvalds         u32			hardware_version;  /* of FCP channel */
744c9615858SChristof Schmitt 	u16			timer_ticks;       /* time int for a tick */
7451da177e4SLinus Torvalds 	struct Scsi_Host	*scsi_host;	   /* Pointer to mid-layer */
7461da177e4SLinus Torvalds 	struct list_head	port_list_head;	   /* remote port list */
7471da177e4SLinus Torvalds 	struct list_head        port_remove_lh;    /* head of ports to be
7481da177e4SLinus Torvalds 						      removed */
7491da177e4SLinus Torvalds 	u32			ports;	           /* number of remote ports */
750fea9d6c7SVolker Sameske 	atomic_t		reqs_active;	   /* # active FSF reqs */
751fea9d6c7SVolker Sameske 	unsigned long		req_no;		   /* unique FSF req number */
752fea9d6c7SVolker Sameske 	struct list_head	*req_list;	   /* list of pending reqs */
753fea9d6c7SVolker Sameske 	spinlock_t		req_list_lock;	   /* request list lock */
7541da177e4SLinus Torvalds 	struct zfcp_qdio_queue	request_queue;	   /* request queue */
7551da177e4SLinus Torvalds 	u32			fsf_req_seq_no;	   /* FSF cmnd seq number */
7561da177e4SLinus Torvalds 	wait_queue_head_t	request_wq;	   /* can be used to wait for
7571da177e4SLinus Torvalds 						      more avaliable SBALs */
7581da177e4SLinus Torvalds 	struct zfcp_qdio_queue	response_queue;	   /* response queue */
7591da177e4SLinus Torvalds 	rwlock_t		abort_lock;        /* Protects against SCSI
7601da177e4SLinus Torvalds 						      stack abort/command
7611da177e4SLinus Torvalds 						      completion races */
7621da177e4SLinus Torvalds 	u16			status_read_failed; /* # failed status reads */
7631da177e4SLinus Torvalds 	atomic_t		status;	           /* status of this adapter */
7641da177e4SLinus Torvalds 	struct list_head	erp_ready_head;	   /* error recovery for this
7651da177e4SLinus Torvalds 						      adapter/devices */
7661da177e4SLinus Torvalds 	struct list_head	erp_running_head;
7671da177e4SLinus Torvalds 	rwlock_t		erp_lock;
7681da177e4SLinus Torvalds 	struct semaphore	erp_ready_sem;
7691da177e4SLinus Torvalds 	wait_queue_head_t	erp_thread_wqh;
7701da177e4SLinus Torvalds 	wait_queue_head_t	erp_done_wqh;
7711da177e4SLinus Torvalds 	struct zfcp_erp_action	erp_action;	   /* pending error recovery */
7721da177e4SLinus Torvalds         atomic_t                erp_counter;
7731da177e4SLinus Torvalds 	u32			erp_total_count;   /* total nr of enqueued erp
7741da177e4SLinus Torvalds 						      actions */
7751da177e4SLinus Torvalds 	u32			erp_low_mem_count; /* nr of erp actions waiting
7761da177e4SLinus Torvalds 						      for memory */
7771da177e4SLinus Torvalds 	struct zfcp_port	*nameserver_port;  /* adapter's nameserver */
778d79a83dbSMartin Peschke 	debug_info_t		*rec_dbf;
7798a36e453SMaxim Shchetynin 	debug_info_t		*hba_dbf;
7808a36e453SMaxim Shchetynin 	debug_info_t		*san_dbf;          /* debug feature areas */
7818a36e453SMaxim Shchetynin 	debug_info_t		*scsi_dbf;
782d79a83dbSMartin Peschke 	spinlock_t		rec_dbf_lock;
7838a36e453SMaxim Shchetynin 	spinlock_t		hba_dbf_lock;
7848a36e453SMaxim Shchetynin 	spinlock_t		san_dbf_lock;
7858a36e453SMaxim Shchetynin 	spinlock_t		scsi_dbf_lock;
786d79a83dbSMartin Peschke 	struct zfcp_rec_dbf_record	rec_dbf_buf;
7878a36e453SMaxim Shchetynin 	struct zfcp_hba_dbf_record	hba_dbf_buf;
7888a36e453SMaxim Shchetynin 	struct zfcp_san_dbf_record	san_dbf_buf;
7898a36e453SMaxim Shchetynin 	struct zfcp_scsi_dbf_record	scsi_dbf_buf;
7901da177e4SLinus Torvalds 	struct zfcp_adapter_mempool	pool;      /* Adapter memory pools */
7911da177e4SLinus Torvalds 	struct qdio_initialize  qdio_init_data;    /* for qdio_establish */
7921da177e4SLinus Torvalds 	struct device           generic_services;  /* directory for WKA ports */
793f6cd94b1SAndreas Herrmann 	struct fc_host_statistics *fc_stats;
794f6cd94b1SAndreas Herrmann 	struct fsf_qtcb_bottom_port *stats_reset_data;
795f6cd94b1SAndreas Herrmann 	unsigned long		stats_reset;
7961da177e4SLinus Torvalds };
7971da177e4SLinus Torvalds 
7981da177e4SLinus Torvalds /*
7991da177e4SLinus Torvalds  * the struct device sysfs_device must be at the beginning of this structure.
8001da177e4SLinus Torvalds  * pointer to struct device is used to free port structure in release function
8011da177e4SLinus Torvalds  * of the device. don't change!
8021da177e4SLinus Torvalds  */
8031da177e4SLinus Torvalds struct zfcp_port {
8041da177e4SLinus Torvalds 	struct device          sysfs_device;   /* sysfs device */
8053859f6a2SAndreas Herrmann 	struct fc_rport        *rport;         /* rport of fc transport class */
8061da177e4SLinus Torvalds 	struct list_head       list;	       /* list of remote ports */
8071da177e4SLinus Torvalds 	atomic_t               refcount;       /* reference count */
8081da177e4SLinus Torvalds 	wait_queue_head_t      remove_wq;      /* can be used to wait for
8091da177e4SLinus Torvalds 						  refcount drop to zero */
8101da177e4SLinus Torvalds 	struct zfcp_adapter    *adapter;       /* adapter used to access port */
8111da177e4SLinus Torvalds 	struct list_head       unit_list_head; /* head of logical unit list */
8121da177e4SLinus Torvalds 	struct list_head       unit_remove_lh; /* head of luns to be removed
8131da177e4SLinus Torvalds 						  list */
8141da177e4SLinus Torvalds 	u32		       units;	       /* # of logical units in list */
8151da177e4SLinus Torvalds 	atomic_t	       status;	       /* status of this remote port */
8161da177e4SLinus Torvalds 	wwn_t		       wwnn;	       /* WWNN if known */
8171da177e4SLinus Torvalds 	wwn_t		       wwpn;	       /* WWPN */
81813e1e1f0SAndreas Herrmann 	u32		       d_id;	       /* D_ID */
8191da177e4SLinus Torvalds 	u32		       handle;	       /* handle assigned by FSF */
8201da177e4SLinus Torvalds 	struct zfcp_erp_action erp_action;     /* pending error recovery */
8211da177e4SLinus Torvalds         atomic_t               erp_counter;
82275bfc283SRalph Wuerthner 	u32                    maxframe_size;
82375bfc283SRalph Wuerthner 	u32                    supported_classes;
8241da177e4SLinus Torvalds };
8251da177e4SLinus Torvalds 
8261da177e4SLinus Torvalds /* the struct device sysfs_device must be at the beginning of this structure.
8271da177e4SLinus Torvalds  * pointer to struct device is used to free unit structure in release function
8281da177e4SLinus Torvalds  * of the device. don't change!
8291da177e4SLinus Torvalds  */
8301da177e4SLinus Torvalds struct zfcp_unit {
8311da177e4SLinus Torvalds 	struct device          sysfs_device;   /* sysfs device */
8321da177e4SLinus Torvalds 	struct list_head       list;	       /* list of logical units */
8331da177e4SLinus Torvalds 	atomic_t               refcount;       /* reference count */
8341da177e4SLinus Torvalds 	wait_queue_head_t      remove_wq;      /* can be used to wait for
8351da177e4SLinus Torvalds 						  refcount drop to zero */
8361da177e4SLinus Torvalds 	struct zfcp_port       *port;	       /* remote port of unit */
8371da177e4SLinus Torvalds 	atomic_t	       status;	       /* status of this logical unit */
83806506d00SAndreas Herrmann 	unsigned int	       scsi_lun;       /* own SCSI LUN */
8391da177e4SLinus Torvalds 	fcp_lun_t	       fcp_lun;	       /* own FCP_LUN */
8401da177e4SLinus Torvalds 	u32		       handle;	       /* handle assigned by FSF */
8411da177e4SLinus Torvalds         struct scsi_device     *device;        /* scsi device struct pointer */
8421da177e4SLinus Torvalds 	struct zfcp_erp_action erp_action;     /* pending error recovery */
8431da177e4SLinus Torvalds         atomic_t               erp_counter;
844c9615858SChristof Schmitt 	struct zfcp_latencies	latencies;
8451da177e4SLinus Torvalds };
8461da177e4SLinus Torvalds 
8471da177e4SLinus Torvalds /* FSF request */
8481da177e4SLinus Torvalds struct zfcp_fsf_req {
8491da177e4SLinus Torvalds 	struct list_head       list;	       /* list of FSF requests */
850fea9d6c7SVolker Sameske 	unsigned long	       req_id;	       /* unique request ID */
8511da177e4SLinus Torvalds 	struct zfcp_adapter    *adapter;       /* adapter request belongs to */
8521da177e4SLinus Torvalds 	u8		       sbal_number;    /* nr of SBALs free for use */
8531da177e4SLinus Torvalds 	u8		       sbal_first;     /* first SBAL for this request */
8541da177e4SLinus Torvalds 	u8		       sbal_last;      /* last possible SBAL for
8551da177e4SLinus Torvalds 						  this reuest */
8561da177e4SLinus Torvalds 	u8		       sbal_curr;      /* current SBAL during creation
8571da177e4SLinus Torvalds 						  of request */
8581da177e4SLinus Torvalds 	u8		       sbale_curr;     /* current SBALE during creation
8591da177e4SLinus Torvalds 						  of request */
8601da177e4SLinus Torvalds 	wait_queue_head_t      completion_wq;  /* can be used by a routine
8611da177e4SLinus Torvalds 						  to wait for completion */
8621da177e4SLinus Torvalds 	volatile u32	       status;	       /* status of this request */
8631da177e4SLinus Torvalds 	u32		       fsf_command;    /* FSF Command copy */
8641da177e4SLinus Torvalds 	struct fsf_qtcb	       *qtcb;	       /* address of associated QTCB */
8651da177e4SLinus Torvalds 	u32		       seq_no;         /* Sequence number of request */
866059c97d0SAndreas Herrmann 	unsigned long	       data;           /* private data of request */
8672abbe866SAndreas Herrmann 	struct timer_list     timer;	       /* used for erp or scsi er */
8681da177e4SLinus Torvalds 	struct zfcp_erp_action *erp_action;    /* used if this request is
8691da177e4SLinus Torvalds 						  issued on behalf of erp */
8701da177e4SLinus Torvalds 	mempool_t	       *pool;	       /* used if request was alloacted
8711da177e4SLinus Torvalds 						  from emergency pool */
8728a36e453SMaxim Shchetynin 	unsigned long long     issued;         /* request sent time (STCK) */
873059c97d0SAndreas Herrmann 	struct zfcp_unit       *unit;
8741da177e4SLinus Torvalds };
8751da177e4SLinus Torvalds 
8761da177e4SLinus Torvalds typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
8771da177e4SLinus Torvalds 
8781da177e4SLinus Torvalds /* driver data */
8791da177e4SLinus Torvalds struct zfcp_data {
8801da177e4SLinus Torvalds 	struct scsi_host_template scsi_host_template;
881dd52e0eaSHeiko Carstens 	struct scsi_transport_template *scsi_transport_template;
8821da177e4SLinus Torvalds         atomic_t                status;             /* Module status flags */
8831da177e4SLinus Torvalds 	struct list_head	adapter_list_head;  /* head of adapter list */
8841da177e4SLinus Torvalds 	struct list_head	adapter_remove_lh;  /* head of adapters to be
8851da177e4SLinus Torvalds 						       removed */
8861da177e4SLinus Torvalds 	u32			adapters;	    /* # of adapters in list */
8871da177e4SLinus Torvalds 	rwlock_t                config_lock;        /* serialises changes
8881da177e4SLinus Torvalds 						       to adapter/port/unit
8891da177e4SLinus Torvalds 						       lists */
8901da177e4SLinus Torvalds 	struct semaphore        config_sema;        /* serialises configuration
8911da177e4SLinus Torvalds 						       changes */
8921da177e4SLinus Torvalds 	atomic_t		loglevel;            /* current loglevel */
8931da177e4SLinus Torvalds 	char                    init_busid[BUS_ID_SIZE];
8941da177e4SLinus Torvalds 	wwn_t                   init_wwpn;
8951da177e4SLinus Torvalds 	fcp_lun_t               init_fcp_lun;
8961da177e4SLinus Torvalds 	char 			*driver_version;
897e18b890bSChristoph Lameter 	struct kmem_cache		*fsf_req_qtcb_cache;
898e18b890bSChristoph Lameter 	struct kmem_cache		*sr_buffer_cache;
899e18b890bSChristoph Lameter 	struct kmem_cache		*gid_pn_cache;
9001da177e4SLinus Torvalds };
9011da177e4SLinus Torvalds 
9021da177e4SLinus Torvalds /**
9031da177e4SLinus Torvalds  * struct zfcp_sg_list - struct describing a scatter-gather list
9041da177e4SLinus Torvalds  * @sg: pointer to array of (struct scatterlist)
9051da177e4SLinus Torvalds  * @count: number of elements in scatter-gather list
9061da177e4SLinus Torvalds  */
9071da177e4SLinus Torvalds struct zfcp_sg_list {
9081da177e4SLinus Torvalds 	struct scatterlist *sg;
9091da177e4SLinus Torvalds 	unsigned int count;
9101da177e4SLinus Torvalds };
9111da177e4SLinus Torvalds 
9121da177e4SLinus Torvalds /* number of elements for various memory pools */
9131da177e4SLinus Torvalds #define ZFCP_POOL_FSF_REQ_ERP_NR	1
9141da177e4SLinus Torvalds #define ZFCP_POOL_FSF_REQ_SCSI_NR	1
9151da177e4SLinus Torvalds #define ZFCP_POOL_FSF_REQ_ABORT_NR	1
9161da177e4SLinus Torvalds #define ZFCP_POOL_STATUS_READ_NR	ZFCP_STATUS_READS_RECOM
9171da177e4SLinus Torvalds #define ZFCP_POOL_DATA_GID_PN_NR	1
9181da177e4SLinus Torvalds 
9191da177e4SLinus Torvalds /* struct used by memory pools for fsf_requests */
920dd52e0eaSHeiko Carstens struct zfcp_fsf_req_qtcb {
9211da177e4SLinus Torvalds 	struct zfcp_fsf_req fsf_req;
9221da177e4SLinus Torvalds 	struct fsf_qtcb qtcb;
9231da177e4SLinus Torvalds };
9241da177e4SLinus Torvalds 
9251da177e4SLinus Torvalds /********************** ZFCP SPECIFIC DEFINES ********************************/
9261da177e4SLinus Torvalds 
9271da177e4SLinus Torvalds #define ZFCP_REQ_AUTO_CLEANUP	0x00000002
9281da177e4SLinus Torvalds #define ZFCP_WAIT_FOR_SBAL	0x00000004
9291da177e4SLinus Torvalds #define ZFCP_REQ_NO_QTCB	0x00000008
9301da177e4SLinus Torvalds 
9311da177e4SLinus Torvalds #define ZFCP_SET                0x00000100
9321da177e4SLinus Torvalds #define ZFCP_CLEAR              0x00000200
9331da177e4SLinus Torvalds 
9341da177e4SLinus Torvalds #ifndef atomic_test_mask
9351da177e4SLinus Torvalds #define atomic_test_mask(mask, target) \
9361da177e4SLinus Torvalds            ((atomic_read(target) & mask) == mask)
9371da177e4SLinus Torvalds #endif
9381da177e4SLinus Torvalds 
9391da177e4SLinus Torvalds extern void _zfcp_hex_dump(char *, int);
9401da177e4SLinus Torvalds #define ZFCP_HEX_DUMP(level, addr, count) \
9411da177e4SLinus Torvalds 		if (ZFCP_LOG_CHECK(level)) { \
9421da177e4SLinus Torvalds 			_zfcp_hex_dump(addr, count); \
9431da177e4SLinus Torvalds 		}
9441da177e4SLinus Torvalds 
9451da177e4SLinus Torvalds #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
9461da177e4SLinus Torvalds #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
9471da177e4SLinus Torvalds #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
9481da177e4SLinus Torvalds 
9491da177e4SLinus Torvalds /*
950ca2d02c2SHeiko Carstens  * Helper functions for request ID management.
951ca2d02c2SHeiko Carstens  */
952ca2d02c2SHeiko Carstens static inline int zfcp_reqlist_hash(unsigned long req_id)
953ca2d02c2SHeiko Carstens {
954ca2d02c2SHeiko Carstens 	return req_id % REQUEST_LIST_SIZE;
955ca2d02c2SHeiko Carstens }
956ca2d02c2SHeiko Carstens 
957ca2d02c2SHeiko Carstens static inline void zfcp_reqlist_add(struct zfcp_adapter *adapter,
958ca2d02c2SHeiko Carstens 				    struct zfcp_fsf_req *fsf_req)
959ca2d02c2SHeiko Carstens {
960ca2d02c2SHeiko Carstens 	unsigned int idx;
961ca2d02c2SHeiko Carstens 
962ca2d02c2SHeiko Carstens 	idx = zfcp_reqlist_hash(fsf_req->req_id);
963ca2d02c2SHeiko Carstens 	list_add_tail(&fsf_req->list, &adapter->req_list[idx]);
964ca2d02c2SHeiko Carstens }
965ca2d02c2SHeiko Carstens 
966ca2d02c2SHeiko Carstens static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
967ca2d02c2SHeiko Carstens 				       struct zfcp_fsf_req *fsf_req)
968ca2d02c2SHeiko Carstens {
969ca2d02c2SHeiko Carstens 	list_del(&fsf_req->list);
970ca2d02c2SHeiko Carstens }
971ca2d02c2SHeiko Carstens 
972ca2d02c2SHeiko Carstens static inline struct zfcp_fsf_req *
973ca2d02c2SHeiko Carstens zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
974ca2d02c2SHeiko Carstens {
975ca2d02c2SHeiko Carstens 	struct zfcp_fsf_req *request;
976ca2d02c2SHeiko Carstens 	unsigned int idx;
977ca2d02c2SHeiko Carstens 
978ca2d02c2SHeiko Carstens 	idx = zfcp_reqlist_hash(req_id);
979ca2d02c2SHeiko Carstens 	list_for_each_entry(request, &adapter->req_list[idx], list)
980ca2d02c2SHeiko Carstens 		if (request->req_id == req_id)
981ca2d02c2SHeiko Carstens 			return request;
982ca2d02c2SHeiko Carstens 	return NULL;
983ca2d02c2SHeiko Carstens }
984ca2d02c2SHeiko Carstens 
985d1ad09dbSHeiko Carstens static inline struct zfcp_fsf_req *
986d1ad09dbSHeiko Carstens zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
987d1ad09dbSHeiko Carstens {
988d1ad09dbSHeiko Carstens 	struct zfcp_fsf_req *request;
989d1ad09dbSHeiko Carstens 	unsigned int idx;
990d1ad09dbSHeiko Carstens 
991d1ad09dbSHeiko Carstens 	for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
992d1ad09dbSHeiko Carstens 		list_for_each_entry(request, &adapter->req_list[idx], list)
993d1ad09dbSHeiko Carstens 			if (request == req)
994d1ad09dbSHeiko Carstens 				return request;
995d1ad09dbSHeiko Carstens 	}
996d1ad09dbSHeiko Carstens 	return NULL;
997d1ad09dbSHeiko Carstens }
998d1ad09dbSHeiko Carstens 
999ca2d02c2SHeiko Carstens /*
10001da177e4SLinus Torvalds  *  functions needed for reference/usage counting
10011da177e4SLinus Torvalds  */
10021da177e4SLinus Torvalds 
10031da177e4SLinus Torvalds static inline void
10041da177e4SLinus Torvalds zfcp_unit_get(struct zfcp_unit *unit)
10051da177e4SLinus Torvalds {
10061da177e4SLinus Torvalds 	atomic_inc(&unit->refcount);
10071da177e4SLinus Torvalds }
10081da177e4SLinus Torvalds 
10091da177e4SLinus Torvalds static inline void
10101da177e4SLinus Torvalds zfcp_unit_put(struct zfcp_unit *unit)
10111da177e4SLinus Torvalds {
10121da177e4SLinus Torvalds 	if (atomic_dec_return(&unit->refcount) == 0)
10131da177e4SLinus Torvalds 		wake_up(&unit->remove_wq);
10141da177e4SLinus Torvalds }
10151da177e4SLinus Torvalds 
10161da177e4SLinus Torvalds static inline void
10171da177e4SLinus Torvalds zfcp_unit_wait(struct zfcp_unit *unit)
10181da177e4SLinus Torvalds {
10191da177e4SLinus Torvalds 	wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
10201da177e4SLinus Torvalds }
10211da177e4SLinus Torvalds 
10221da177e4SLinus Torvalds static inline void
10231da177e4SLinus Torvalds zfcp_port_get(struct zfcp_port *port)
10241da177e4SLinus Torvalds {
10251da177e4SLinus Torvalds 	atomic_inc(&port->refcount);
10261da177e4SLinus Torvalds }
10271da177e4SLinus Torvalds 
10281da177e4SLinus Torvalds static inline void
10291da177e4SLinus Torvalds zfcp_port_put(struct zfcp_port *port)
10301da177e4SLinus Torvalds {
10311da177e4SLinus Torvalds 	if (atomic_dec_return(&port->refcount) == 0)
10321da177e4SLinus Torvalds 		wake_up(&port->remove_wq);
10331da177e4SLinus Torvalds }
10341da177e4SLinus Torvalds 
10351da177e4SLinus Torvalds static inline void
10361da177e4SLinus Torvalds zfcp_port_wait(struct zfcp_port *port)
10371da177e4SLinus Torvalds {
10381da177e4SLinus Torvalds 	wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
10391da177e4SLinus Torvalds }
10401da177e4SLinus Torvalds 
10411da177e4SLinus Torvalds static inline void
10421da177e4SLinus Torvalds zfcp_adapter_get(struct zfcp_adapter *adapter)
10431da177e4SLinus Torvalds {
10441da177e4SLinus Torvalds 	atomic_inc(&adapter->refcount);
10451da177e4SLinus Torvalds }
10461da177e4SLinus Torvalds 
10471da177e4SLinus Torvalds static inline void
10481da177e4SLinus Torvalds zfcp_adapter_put(struct zfcp_adapter *adapter)
10491da177e4SLinus Torvalds {
10501da177e4SLinus Torvalds 	if (atomic_dec_return(&adapter->refcount) == 0)
10511da177e4SLinus Torvalds 		wake_up(&adapter->remove_wq);
10521da177e4SLinus Torvalds }
10531da177e4SLinus Torvalds 
10541da177e4SLinus Torvalds static inline void
10551da177e4SLinus Torvalds zfcp_adapter_wait(struct zfcp_adapter *adapter)
10561da177e4SLinus Torvalds {
10571da177e4SLinus Torvalds 	wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
10581da177e4SLinus Torvalds }
10591da177e4SLinus Torvalds 
10601da177e4SLinus Torvalds #endif /* ZFCP_DEF_H */
1061