xref: /openbmc/linux/drivers/s390/scsi/zfcp_def.h (revision 22753fa5)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *
31da177e4SLinus Torvalds  * linux/drivers/s390/scsi/zfcp_def.h
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  * FCP adapter driver for IBM eServer zSeries
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  * (C) Copyright IBM Corp. 2002, 2004
81da177e4SLinus Torvalds  *
91da177e4SLinus Torvalds  * Author(s): Martin Peschke <mpeschke@de.ibm.com>
101da177e4SLinus Torvalds  *            Raimund Schroeder <raimund.schroeder@de.ibm.com>
111da177e4SLinus Torvalds  *            Aron Zeh
121da177e4SLinus Torvalds  *            Wolfgang Taphorn
131da177e4SLinus Torvalds  *            Stefan Bader <stefan.bader@de.ibm.com>
141da177e4SLinus Torvalds  *            Heiko Carstens <heiko.carstens@de.ibm.com>
151da177e4SLinus Torvalds  *            Andreas Herrmann <aherrman@de.ibm.com>
161da177e4SLinus Torvalds  *            Volker Sameske <sameske@de.ibm.com>
171da177e4SLinus Torvalds  *
181da177e4SLinus Torvalds  * This program is free software; you can redistribute it and/or modify
191da177e4SLinus Torvalds  * it under the terms of the GNU General Public License as published by
201da177e4SLinus Torvalds  * the Free Software Foundation; either version 2, or (at your option)
211da177e4SLinus Torvalds  * any later version.
221da177e4SLinus Torvalds  *
231da177e4SLinus Torvalds  * This program is distributed in the hope that it will be useful,
241da177e4SLinus Torvalds  * but WITHOUT ANY WARRANTY; without even the implied warranty of
251da177e4SLinus Torvalds  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
261da177e4SLinus Torvalds  * GNU General Public License for more details.
271da177e4SLinus Torvalds  *
281da177e4SLinus Torvalds  * You should have received a copy of the GNU General Public License
291da177e4SLinus Torvalds  * along with this program; if not, write to the Free Software
301da177e4SLinus Torvalds  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
311da177e4SLinus Torvalds  */
321da177e4SLinus Torvalds 
331da177e4SLinus Torvalds 
341da177e4SLinus Torvalds #ifndef ZFCP_DEF_H
351da177e4SLinus Torvalds #define ZFCP_DEF_H
361da177e4SLinus Torvalds 
371da177e4SLinus Torvalds #define ZFCP_DEF_REVISION "$Revision: 1.111 $"
381da177e4SLinus Torvalds 
391da177e4SLinus Torvalds /*************************** INCLUDES *****************************************/
401da177e4SLinus Torvalds 
411da177e4SLinus Torvalds #include <linux/init.h>
421da177e4SLinus Torvalds #include <linux/moduleparam.h>
431da177e4SLinus Torvalds #include <linux/miscdevice.h>
441da177e4SLinus Torvalds #include <linux/major.h>
451da177e4SLinus Torvalds #include <linux/blkdev.h>
461da177e4SLinus Torvalds #include <linux/delay.h>
471da177e4SLinus Torvalds #include <linux/timer.h>
481da177e4SLinus Torvalds #include <scsi/scsi.h>
491da177e4SLinus Torvalds #include <scsi/scsi_tcq.h>
501da177e4SLinus Torvalds #include <scsi/scsi_cmnd.h>
511da177e4SLinus Torvalds #include <scsi/scsi_device.h>
521da177e4SLinus Torvalds #include <scsi/scsi_host.h>
531da177e4SLinus Torvalds #include <scsi/scsi_transport.h>
541da177e4SLinus Torvalds #include <scsi/scsi_transport_fc.h>
551da177e4SLinus Torvalds #include "../../fc4/fc.h"
561da177e4SLinus Torvalds #include "zfcp_fsf.h"
571da177e4SLinus Torvalds #include <asm/ccwdev.h>
581da177e4SLinus Torvalds #include <asm/qdio.h>
591da177e4SLinus Torvalds #include <asm/debug.h>
601da177e4SLinus Torvalds #include <asm/ebcdic.h>
611da177e4SLinus Torvalds #include <linux/mempool.h>
621da177e4SLinus Torvalds #include <linux/syscalls.h>
631da177e4SLinus Torvalds #include <linux/ioctl.h>
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds 
661da177e4SLinus Torvalds /********************* GENERAL DEFINES *********************************/
671da177e4SLinus Torvalds 
681da177e4SLinus Torvalds /* zfcp version number, it consists of major, minor, and patch-level number */
696f71d9bcS #define ZFCP_VERSION		"4.3.0"
701da177e4SLinus Torvalds 
711da177e4SLinus Torvalds /**
721da177e4SLinus Torvalds  * zfcp_sg_to_address - determine kernel address from struct scatterlist
731da177e4SLinus Torvalds  * @list: struct scatterlist
741da177e4SLinus Torvalds  * Return: kernel address
751da177e4SLinus Torvalds  */
761da177e4SLinus Torvalds static inline void *
771da177e4SLinus Torvalds zfcp_sg_to_address(struct scatterlist *list)
781da177e4SLinus Torvalds {
791da177e4SLinus Torvalds 	return (void *) (page_address(list->page) + list->offset);
801da177e4SLinus Torvalds }
811da177e4SLinus Torvalds 
821da177e4SLinus Torvalds /**
831da177e4SLinus Torvalds  * zfcp_address_to_sg - set up struct scatterlist from kernel address
841da177e4SLinus Torvalds  * @address: kernel address
851da177e4SLinus Torvalds  * @list: struct scatterlist
861da177e4SLinus Torvalds  */
871da177e4SLinus Torvalds static inline void
881da177e4SLinus Torvalds zfcp_address_to_sg(void *address, struct scatterlist *list)
891da177e4SLinus Torvalds {
901da177e4SLinus Torvalds 	list->page = virt_to_page(address);
911da177e4SLinus Torvalds 	list->offset = ((unsigned long) address) & (PAGE_SIZE - 1);
921da177e4SLinus Torvalds }
931da177e4SLinus Torvalds 
941da177e4SLinus Torvalds /********************* SCSI SPECIFIC DEFINES *********************************/
951da177e4SLinus Torvalds 
961da177e4SLinus Torvalds /* 32 bit for SCSI ID and LUN as long as the SCSI stack uses this type */
971da177e4SLinus Torvalds typedef u32 scsi_id_t;
981da177e4SLinus Torvalds typedef u32 scsi_lun_t;
991da177e4SLinus Torvalds 
1001da177e4SLinus Torvalds #define ZFCP_ERP_SCSI_LOW_MEM_TIMEOUT           (100*HZ)
1011da177e4SLinus Torvalds #define ZFCP_SCSI_ER_TIMEOUT                    (100*HZ)
1021da177e4SLinus Torvalds 
1031da177e4SLinus Torvalds /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
1041da177e4SLinus Torvalds 
1051da177e4SLinus Torvalds /* Adapter Identification Parameters */
1061da177e4SLinus Torvalds #define ZFCP_CONTROL_UNIT_TYPE  0x1731
1071da177e4SLinus Torvalds #define ZFCP_CONTROL_UNIT_MODEL 0x03
1081da177e4SLinus Torvalds #define ZFCP_DEVICE_TYPE        0x1732
1091da177e4SLinus Torvalds #define ZFCP_DEVICE_MODEL       0x03
1101da177e4SLinus Torvalds #define ZFCP_DEVICE_MODEL_PRIV	0x04
1111da177e4SLinus Torvalds 
1121da177e4SLinus Torvalds /* allow as many chained SBALs as are supported by hardware */
1131da177e4SLinus Torvalds #define ZFCP_MAX_SBALS_PER_REQ		FSF_MAX_SBALS_PER_REQ
1141da177e4SLinus Torvalds #define ZFCP_MAX_SBALS_PER_CT_REQ	FSF_MAX_SBALS_PER_REQ
1151da177e4SLinus Torvalds #define ZFCP_MAX_SBALS_PER_ELS_REQ	FSF_MAX_SBALS_PER_ELS_REQ
1161da177e4SLinus Torvalds 
1171da177e4SLinus Torvalds /* DMQ bug workaround: don't use last SBALE */
1181da177e4SLinus Torvalds #define ZFCP_MAX_SBALES_PER_SBAL	(QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
1191da177e4SLinus Torvalds 
1201da177e4SLinus Torvalds /* index of last SBALE (with respect to DMQ bug workaround) */
1211da177e4SLinus Torvalds #define ZFCP_LAST_SBALE_PER_SBAL	(ZFCP_MAX_SBALES_PER_SBAL - 1)
1221da177e4SLinus Torvalds 
1231da177e4SLinus Torvalds /* max. number of (data buffer) SBALEs in largest SBAL chain */
1241da177e4SLinus Torvalds #define ZFCP_MAX_SBALES_PER_REQ		\
1251da177e4SLinus Torvalds 	(ZFCP_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
1261da177e4SLinus Torvalds         /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
1271da177e4SLinus Torvalds 
1281da177e4SLinus Torvalds /* FIXME(tune): free space should be one max. SBAL chain plus what? */
1291da177e4SLinus Torvalds #define ZFCP_QDIO_PCI_INTERVAL		(QDIO_MAX_BUFFERS_PER_Q \
1301da177e4SLinus Torvalds                                          - (ZFCP_MAX_SBALS_PER_REQ + 4))
1311da177e4SLinus Torvalds 
1321da177e4SLinus Torvalds #define ZFCP_SBAL_TIMEOUT               (5*HZ)
1331da177e4SLinus Torvalds 
1341da177e4SLinus Torvalds #define ZFCP_TYPE2_RECOVERY_TIME        (8*HZ)
1351da177e4SLinus Torvalds 
1361da177e4SLinus Torvalds /* queue polling (values in microseconds) */
1371da177e4SLinus Torvalds #define ZFCP_MAX_INPUT_THRESHOLD 	5000	/* FIXME: tune */
1381da177e4SLinus Torvalds #define ZFCP_MAX_OUTPUT_THRESHOLD 	1000	/* FIXME: tune */
1391da177e4SLinus Torvalds #define ZFCP_MIN_INPUT_THRESHOLD 	1	/* ignored by QDIO layer */
1401da177e4SLinus Torvalds #define ZFCP_MIN_OUTPUT_THRESHOLD 	1	/* ignored by QDIO layer */
1411da177e4SLinus Torvalds 
1421da177e4SLinus Torvalds #define QDIO_SCSI_QFMT			1	/* 1 for FSF */
1431da177e4SLinus Torvalds 
1441da177e4SLinus Torvalds /********************* FSF SPECIFIC DEFINES *********************************/
1451da177e4SLinus Torvalds 
1461da177e4SLinus Torvalds #define ZFCP_ULP_INFO_VERSION                   26
1471da177e4SLinus Torvalds #define ZFCP_QTCB_VERSION	FSF_QTCB_CURRENT_VERSION
1481da177e4SLinus Torvalds /* ATTENTION: value must not be used by hardware */
1491da177e4SLinus Torvalds #define FSF_QTCB_UNSOLICITED_STATUS		0x6305
1501da177e4SLinus Torvalds #define ZFCP_STATUS_READ_FAILED_THRESHOLD	3
1511da177e4SLinus Torvalds #define ZFCP_STATUS_READS_RECOM		        FSF_STATUS_READS_RECOM
15222753fa5SAndreas Herrmann 
15322753fa5SAndreas Herrmann /* Do 1st retry in 1 second, then double the timeout for each following retry */
15422753fa5SAndreas Herrmann #define ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP	100
15522753fa5SAndreas Herrmann #define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES	7
1561da177e4SLinus Torvalds 
1571da177e4SLinus Torvalds /* timeout value for "default timer" for fsf requests */
1581da177e4SLinus Torvalds #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ);
1591da177e4SLinus Torvalds 
1601da177e4SLinus Torvalds /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
1611da177e4SLinus Torvalds 
1621da177e4SLinus Torvalds typedef unsigned long long wwn_t;
1631da177e4SLinus Torvalds typedef unsigned int       fc_id_t;
1641da177e4SLinus Torvalds typedef unsigned long long fcp_lun_t;
1651da177e4SLinus Torvalds /* data length field may be at variable position in FCP-2 FCP_CMND IU */
1661da177e4SLinus Torvalds typedef unsigned int       fcp_dl_t;
1671da177e4SLinus Torvalds 
1681da177e4SLinus Torvalds #define ZFCP_FC_SERVICE_CLASS_DEFAULT	FSF_CLASS_3
1691da177e4SLinus Torvalds 
1701da177e4SLinus Torvalds /* timeout for name-server lookup (in seconds) */
1711da177e4SLinus Torvalds #define ZFCP_NS_GID_PN_TIMEOUT		10
1721da177e4SLinus Torvalds 
1731da177e4SLinus Torvalds /* largest SCSI command we can process */
1741da177e4SLinus Torvalds /* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */
1751da177e4SLinus Torvalds #define ZFCP_MAX_SCSI_CMND_LENGTH	255
1761da177e4SLinus Torvalds /* maximum number of commands in LUN queue (tagged queueing) */
1771da177e4SLinus Torvalds #define ZFCP_CMND_PER_LUN               32
1781da177e4SLinus Torvalds 
1791da177e4SLinus Torvalds /* task attribute values in FCP-2 FCP_CMND IU */
1801da177e4SLinus Torvalds #define SIMPLE_Q	0
1811da177e4SLinus Torvalds #define HEAD_OF_Q	1
1821da177e4SLinus Torvalds #define ORDERED_Q	2
1831da177e4SLinus Torvalds #define ACA_Q		4
1841da177e4SLinus Torvalds #define UNTAGGED	5
1851da177e4SLinus Torvalds 
1861da177e4SLinus Torvalds /* task management flags in FCP-2 FCP_CMND IU */
1871da177e4SLinus Torvalds #define FCP_CLEAR_ACA		0x40
1881da177e4SLinus Torvalds #define FCP_TARGET_RESET	0x20
1891da177e4SLinus Torvalds #define FCP_LOGICAL_UNIT_RESET	0x10
1901da177e4SLinus Torvalds #define FCP_CLEAR_TASK_SET	0x04
1911da177e4SLinus Torvalds #define FCP_ABORT_TASK_SET	0x02
1921da177e4SLinus Torvalds 
1931da177e4SLinus Torvalds #define FCP_CDB_LENGTH		16
1941da177e4SLinus Torvalds 
1951da177e4SLinus Torvalds #define ZFCP_DID_MASK           0x00FFFFFF
1961da177e4SLinus Torvalds 
1971da177e4SLinus Torvalds /* FCP(-2) FCP_CMND IU */
1981da177e4SLinus Torvalds struct fcp_cmnd_iu {
1991da177e4SLinus Torvalds 	fcp_lun_t fcp_lun;	   /* FCP logical unit number */
2001da177e4SLinus Torvalds 	u8  crn;	           /* command reference number */
2011da177e4SLinus Torvalds 	u8  reserved0:5;	   /* reserved */
2021da177e4SLinus Torvalds 	u8  task_attribute:3;	   /* task attribute */
2031da177e4SLinus Torvalds 	u8  task_management_flags; /* task management flags */
2041da177e4SLinus Torvalds 	u8  add_fcp_cdb_length:6;  /* additional FCP_CDB length */
2051da177e4SLinus Torvalds 	u8  rddata:1;              /* read data */
2061da177e4SLinus Torvalds 	u8  wddata:1;              /* write data */
2071da177e4SLinus Torvalds 	u8  fcp_cdb[FCP_CDB_LENGTH];
2081da177e4SLinus Torvalds } __attribute__((packed));
2091da177e4SLinus Torvalds 
2101da177e4SLinus Torvalds /* FCP(-2) FCP_RSP IU */
2111da177e4SLinus Torvalds struct fcp_rsp_iu {
2121da177e4SLinus Torvalds 	u8  reserved0[10];
2131da177e4SLinus Torvalds 	union {
2141da177e4SLinus Torvalds 		struct {
2151da177e4SLinus Torvalds 			u8 reserved1:3;
2161da177e4SLinus Torvalds 			u8 fcp_conf_req:1;
2171da177e4SLinus Torvalds 			u8 fcp_resid_under:1;
2181da177e4SLinus Torvalds 			u8 fcp_resid_over:1;
2191da177e4SLinus Torvalds 			u8 fcp_sns_len_valid:1;
2201da177e4SLinus Torvalds 			u8 fcp_rsp_len_valid:1;
2211da177e4SLinus Torvalds 		} bits;
2221da177e4SLinus Torvalds 		u8 value;
2231da177e4SLinus Torvalds 	} validity;
2241da177e4SLinus Torvalds 	u8  scsi_status;
2251da177e4SLinus Torvalds 	u32 fcp_resid;
2261da177e4SLinus Torvalds 	u32 fcp_sns_len;
2271da177e4SLinus Torvalds 	u32 fcp_rsp_len;
2281da177e4SLinus Torvalds } __attribute__((packed));
2291da177e4SLinus Torvalds 
2301da177e4SLinus Torvalds 
2311da177e4SLinus Torvalds #define RSP_CODE_GOOD		 0
2321da177e4SLinus Torvalds #define RSP_CODE_LENGTH_MISMATCH 1
2331da177e4SLinus Torvalds #define RSP_CODE_FIELD_INVALID	 2
2341da177e4SLinus Torvalds #define RSP_CODE_RO_MISMATCH	 3
2351da177e4SLinus Torvalds #define RSP_CODE_TASKMAN_UNSUPP	 4
2361da177e4SLinus Torvalds #define RSP_CODE_TASKMAN_FAILED	 5
2371da177e4SLinus Torvalds 
2381da177e4SLinus Torvalds /* see fc-fs */
2391da177e4SLinus Torvalds #define LS_FAN 0x60000000
2401da177e4SLinus Torvalds #define LS_RSCN 0x61040000
2411da177e4SLinus Torvalds 
2421da177e4SLinus Torvalds struct fcp_rscn_head {
2431da177e4SLinus Torvalds         u8  command;
2441da177e4SLinus Torvalds         u8  page_length; /* always 0x04 */
2451da177e4SLinus Torvalds         u16 payload_len;
2461da177e4SLinus Torvalds } __attribute__((packed));
2471da177e4SLinus Torvalds 
2481da177e4SLinus Torvalds struct fcp_rscn_element {
2491da177e4SLinus Torvalds         u8  reserved:2;
2501da177e4SLinus Torvalds         u8  event_qual:4;
2511da177e4SLinus Torvalds         u8  addr_format:2;
2521da177e4SLinus Torvalds         u32 nport_did:24;
2531da177e4SLinus Torvalds } __attribute__((packed));
2541da177e4SLinus Torvalds 
2551da177e4SLinus Torvalds #define ZFCP_PORT_ADDRESS   0x0
2561da177e4SLinus Torvalds #define ZFCP_AREA_ADDRESS   0x1
2571da177e4SLinus Torvalds #define ZFCP_DOMAIN_ADDRESS 0x2
2581da177e4SLinus Torvalds #define ZFCP_FABRIC_ADDRESS 0x3
2591da177e4SLinus Torvalds 
2601da177e4SLinus Torvalds #define ZFCP_PORTS_RANGE_PORT   0xFFFFFF
2611da177e4SLinus Torvalds #define ZFCP_PORTS_RANGE_AREA   0xFFFF00
2621da177e4SLinus Torvalds #define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
2631da177e4SLinus Torvalds #define ZFCP_PORTS_RANGE_FABRIC 0x000000
2641da177e4SLinus Torvalds 
2651da177e4SLinus Torvalds #define ZFCP_NO_PORTS_PER_AREA    0x100
2661da177e4SLinus Torvalds #define ZFCP_NO_PORTS_PER_DOMAIN  0x10000
2671da177e4SLinus Torvalds #define ZFCP_NO_PORTS_PER_FABRIC  0x1000000
2681da177e4SLinus Torvalds 
2691da177e4SLinus Torvalds struct fcp_fan {
2701da177e4SLinus Torvalds         u32 command;
2711da177e4SLinus Torvalds         u32 fport_did;
2721da177e4SLinus Torvalds         wwn_t fport_wwpn;
2731da177e4SLinus Torvalds         wwn_t fport_wwname;
2741da177e4SLinus Torvalds } __attribute__((packed));
2751da177e4SLinus Torvalds 
2761da177e4SLinus Torvalds /* see fc-ph */
2771da177e4SLinus Torvalds struct fcp_logo {
2781da177e4SLinus Torvalds         u32 command;
2791da177e4SLinus Torvalds         u32 nport_did;
2801da177e4SLinus Torvalds         wwn_t nport_wwpn;
2811da177e4SLinus Torvalds } __attribute__((packed));
2821da177e4SLinus Torvalds 
2831da177e4SLinus Torvalds /*
2841da177e4SLinus Torvalds  * FC-FS stuff
2851da177e4SLinus Torvalds  */
2861da177e4SLinus Torvalds #define R_A_TOV				10 /* seconds */
2871da177e4SLinus Torvalds #define ZFCP_ELS_TIMEOUT		(2 * R_A_TOV)
2881da177e4SLinus Torvalds 
2891da177e4SLinus Torvalds #define ZFCP_LS_RLS			0x0f
2901da177e4SLinus Torvalds #define ZFCP_LS_ADISC			0x52
2911da177e4SLinus Torvalds #define ZFCP_LS_RPS			0x56
2921da177e4SLinus Torvalds #define ZFCP_LS_RSCN			0x61
2931da177e4SLinus Torvalds #define ZFCP_LS_RNID			0x78
2941da177e4SLinus Torvalds 
2951da177e4SLinus Torvalds struct zfcp_ls_rjt_par {
2961da177e4SLinus Torvalds 	u8 action;
2971da177e4SLinus Torvalds  	u8 reason_code;
2981da177e4SLinus Torvalds  	u8 reason_expl;
2991da177e4SLinus Torvalds  	u8 vendor_unique;
3001da177e4SLinus Torvalds } __attribute__ ((packed));
3011da177e4SLinus Torvalds 
3021da177e4SLinus Torvalds struct zfcp_ls_adisc {
3031da177e4SLinus Torvalds 	u8		code;
3041da177e4SLinus Torvalds 	u8		field[3];
3051da177e4SLinus Torvalds 	u32		hard_nport_id;
3061da177e4SLinus Torvalds 	u64		wwpn;
3071da177e4SLinus Torvalds 	u64		wwnn;
3081da177e4SLinus Torvalds 	u32		nport_id;
3091da177e4SLinus Torvalds } __attribute__ ((packed));
3101da177e4SLinus Torvalds 
3111da177e4SLinus Torvalds struct zfcp_ls_adisc_acc {
3121da177e4SLinus Torvalds 	u8		code;
3131da177e4SLinus Torvalds 	u8		field[3];
3141da177e4SLinus Torvalds 	u32		hard_nport_id;
3151da177e4SLinus Torvalds 	u64		wwpn;
3161da177e4SLinus Torvalds 	u64		wwnn;
3171da177e4SLinus Torvalds 	u32		nport_id;
3181da177e4SLinus Torvalds } __attribute__ ((packed));
3191da177e4SLinus Torvalds 
3201da177e4SLinus Torvalds struct zfcp_rc_entry {
3211da177e4SLinus Torvalds 	u8 code;
3221da177e4SLinus Torvalds 	const char *description;
3231da177e4SLinus Torvalds };
3241da177e4SLinus Torvalds 
3251da177e4SLinus Torvalds /*
3261da177e4SLinus Torvalds  * FC-GS-2 stuff
3271da177e4SLinus Torvalds  */
3281da177e4SLinus Torvalds #define ZFCP_CT_REVISION		0x01
3291da177e4SLinus Torvalds #define ZFCP_CT_DIRECTORY_SERVICE	0xFC
3301da177e4SLinus Torvalds #define ZFCP_CT_NAME_SERVER		0x02
3311da177e4SLinus Torvalds #define ZFCP_CT_SYNCHRONOUS		0x00
3321da177e4SLinus Torvalds #define ZFCP_CT_GID_PN			0x0121
3331da177e4SLinus Torvalds #define ZFCP_CT_MAX_SIZE		0x1020
3341da177e4SLinus Torvalds #define ZFCP_CT_ACCEPT			0x8002
3351da177e4SLinus Torvalds #define ZFCP_CT_REJECT			0x8001
3361da177e4SLinus Torvalds 
3371da177e4SLinus Torvalds /*
3381da177e4SLinus Torvalds  * FC-GS-4 stuff
3391da177e4SLinus Torvalds  */
3401da177e4SLinus Torvalds #define ZFCP_CT_TIMEOUT			(3 * R_A_TOV)
3411da177e4SLinus Torvalds 
3421da177e4SLinus Torvalds 
3431da177e4SLinus Torvalds /***************** S390 DEBUG FEATURE SPECIFIC DEFINES ***********************/
3441da177e4SLinus Torvalds 
3451da177e4SLinus Torvalds /* debug feature entries per adapter */
3461da177e4SLinus Torvalds #define ZFCP_ERP_DBF_INDEX     1
3471da177e4SLinus Torvalds #define ZFCP_ERP_DBF_AREAS     2
3481da177e4SLinus Torvalds #define ZFCP_ERP_DBF_LENGTH    16
3491da177e4SLinus Torvalds #define ZFCP_ERP_DBF_LEVEL     3
3501da177e4SLinus Torvalds #define ZFCP_ERP_DBF_NAME      "zfcperp"
3511da177e4SLinus Torvalds 
3521da177e4SLinus Torvalds #define ZFCP_CMD_DBF_INDEX     2
3531da177e4SLinus Torvalds #define ZFCP_CMD_DBF_AREAS     1
3541da177e4SLinus Torvalds #define ZFCP_CMD_DBF_LENGTH    8
3551da177e4SLinus Torvalds #define ZFCP_CMD_DBF_LEVEL     3
3561da177e4SLinus Torvalds #define ZFCP_CMD_DBF_NAME      "zfcpcmd"
3571da177e4SLinus Torvalds 
3581da177e4SLinus Torvalds #define ZFCP_ABORT_DBF_INDEX   2
3591da177e4SLinus Torvalds #define ZFCP_ABORT_DBF_AREAS   1
3601da177e4SLinus Torvalds #define ZFCP_ABORT_DBF_LENGTH  8
3611da177e4SLinus Torvalds #define ZFCP_ABORT_DBF_LEVEL   6
3621da177e4SLinus Torvalds #define ZFCP_ABORT_DBF_NAME    "zfcpabt"
3631da177e4SLinus Torvalds 
3641da177e4SLinus Torvalds #define ZFCP_IN_ELS_DBF_INDEX  2
3651da177e4SLinus Torvalds #define ZFCP_IN_ELS_DBF_AREAS  1
3661da177e4SLinus Torvalds #define ZFCP_IN_ELS_DBF_LENGTH 8
3671da177e4SLinus Torvalds #define ZFCP_IN_ELS_DBF_LEVEL  6
3681da177e4SLinus Torvalds #define ZFCP_IN_ELS_DBF_NAME   "zfcpels"
3691da177e4SLinus Torvalds 
3701da177e4SLinus Torvalds /******************** LOGGING MACROS AND DEFINES *****************************/
3711da177e4SLinus Torvalds 
3721da177e4SLinus Torvalds /*
3731da177e4SLinus Torvalds  * Logging may be applied on certain kinds of driver operations
3741da177e4SLinus Torvalds  * independently. Additionally, different log-levels are supported for
3751da177e4SLinus Torvalds  * each of these areas.
3761da177e4SLinus Torvalds  */
3771da177e4SLinus Torvalds 
3781da177e4SLinus Torvalds #define ZFCP_NAME               "zfcp"
3791da177e4SLinus Torvalds 
3801da177e4SLinus Torvalds /* read-only LUN sharing switch initial value */
3811da177e4SLinus Torvalds #define ZFCP_RO_LUN_SHARING_DEFAULTS 0
3821da177e4SLinus Torvalds 
3831da177e4SLinus Torvalds /* independent log areas */
3841da177e4SLinus Torvalds #define ZFCP_LOG_AREA_OTHER	0
3851da177e4SLinus Torvalds #define ZFCP_LOG_AREA_SCSI	1
3861da177e4SLinus Torvalds #define ZFCP_LOG_AREA_FSF	2
3871da177e4SLinus Torvalds #define ZFCP_LOG_AREA_CONFIG	3
3881da177e4SLinus Torvalds #define ZFCP_LOG_AREA_CIO	4
3891da177e4SLinus Torvalds #define ZFCP_LOG_AREA_QDIO	5
3901da177e4SLinus Torvalds #define ZFCP_LOG_AREA_ERP	6
3911da177e4SLinus Torvalds #define ZFCP_LOG_AREA_FC	7
3921da177e4SLinus Torvalds 
3931da177e4SLinus Torvalds /* log level values*/
3941da177e4SLinus Torvalds #define ZFCP_LOG_LEVEL_NORMAL	0
3951da177e4SLinus Torvalds #define ZFCP_LOG_LEVEL_INFO	1
3961da177e4SLinus Torvalds #define ZFCP_LOG_LEVEL_DEBUG	2
3971da177e4SLinus Torvalds #define ZFCP_LOG_LEVEL_TRACE	3
3981da177e4SLinus Torvalds 
3991da177e4SLinus Torvalds /*
4001da177e4SLinus Torvalds  * this allows removal of logging code by the preprocessor
4011da177e4SLinus Torvalds  * (the most detailed log level still to be compiled in is specified,
4021da177e4SLinus Torvalds  * higher log levels are removed)
4031da177e4SLinus Torvalds  */
4041da177e4SLinus Torvalds #define ZFCP_LOG_LEVEL_LIMIT	ZFCP_LOG_LEVEL_TRACE
4051da177e4SLinus Torvalds 
4061da177e4SLinus Torvalds /* get "loglevel" nibble assignment */
4071da177e4SLinus Torvalds #define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \
4081da177e4SLinus Torvalds 	       ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF)
4091da177e4SLinus Torvalds 
4101da177e4SLinus Torvalds /* set "loglevel" nibble */
4111da177e4SLinus Torvalds #define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \
4121da177e4SLinus Torvalds 	       (value << (zfcp_lognibble << 2))
4131da177e4SLinus Torvalds 
4141da177e4SLinus Torvalds /* all log-level defaults are combined to generate initial log-level */
4151da177e4SLinus Torvalds #define ZFCP_LOG_LEVEL_DEFAULTS \
4161da177e4SLinus Torvalds 	(ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_OTHER) | \
4171da177e4SLinus Torvalds 	 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_SCSI) | \
4181da177e4SLinus Torvalds 	 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FSF) | \
4191da177e4SLinus Torvalds 	 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CONFIG) | \
4201da177e4SLinus Torvalds 	 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CIO) | \
4211da177e4SLinus Torvalds 	 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_QDIO) | \
4221da177e4SLinus Torvalds 	 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_ERP) | \
4231da177e4SLinus Torvalds 	 ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FC))
4241da177e4SLinus Torvalds 
4251da177e4SLinus Torvalds /* check whether we have the right level for logging */
4261da177e4SLinus Torvalds #define ZFCP_LOG_CHECK(level) \
4271da177e4SLinus Torvalds 	((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level)
4281da177e4SLinus Torvalds 
4291da177e4SLinus Torvalds /* logging routine for zfcp */
4301da177e4SLinus Torvalds #define _ZFCP_LOG(fmt, args...) \
4311da177e4SLinus Torvalds 	printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __FUNCTION__, \
4321da177e4SLinus Torvalds 	       __LINE__ , ##args)
4331da177e4SLinus Torvalds 
4341da177e4SLinus Torvalds #define ZFCP_LOG(level, fmt, args...) \
4351da177e4SLinus Torvalds do { \
4361da177e4SLinus Torvalds 	if (ZFCP_LOG_CHECK(level)) \
4371da177e4SLinus Torvalds 		_ZFCP_LOG(fmt, ##args); \
4381da177e4SLinus Torvalds } while (0)
4391da177e4SLinus Torvalds 
4401da177e4SLinus Torvalds #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL
4411da177e4SLinus Torvalds # define ZFCP_LOG_NORMAL(fmt, args...)
4421da177e4SLinus Torvalds #else
4431da177e4SLinus Torvalds # define ZFCP_LOG_NORMAL(fmt, args...) \
4441da177e4SLinus Torvalds do { \
4451da177e4SLinus Torvalds 	if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \
4461da177e4SLinus Torvalds 		printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
4471da177e4SLinus Torvalds } while (0)
4481da177e4SLinus Torvalds #endif
4491da177e4SLinus Torvalds 
4501da177e4SLinus Torvalds #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO
4511da177e4SLinus Torvalds # define ZFCP_LOG_INFO(fmt, args...)
4521da177e4SLinus Torvalds #else
4531da177e4SLinus Torvalds # define ZFCP_LOG_INFO(fmt, args...) \
4541da177e4SLinus Torvalds do { \
4551da177e4SLinus Torvalds 	if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \
4561da177e4SLinus Torvalds 		printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
4571da177e4SLinus Torvalds } while (0)
4581da177e4SLinus Torvalds #endif
4591da177e4SLinus Torvalds 
4601da177e4SLinus Torvalds #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG
4611da177e4SLinus Torvalds # define ZFCP_LOG_DEBUG(fmt, args...)
4621da177e4SLinus Torvalds #else
4631da177e4SLinus Torvalds # define ZFCP_LOG_DEBUG(fmt, args...) \
4641da177e4SLinus Torvalds 	ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args)
4651da177e4SLinus Torvalds #endif
4661da177e4SLinus Torvalds 
4671da177e4SLinus Torvalds #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE
4681da177e4SLinus Torvalds # define ZFCP_LOG_TRACE(fmt, args...)
4691da177e4SLinus Torvalds #else
4701da177e4SLinus Torvalds # define ZFCP_LOG_TRACE(fmt, args...) \
4711da177e4SLinus Torvalds 	ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args)
4721da177e4SLinus Torvalds #endif
4731da177e4SLinus Torvalds 
4741da177e4SLinus Torvalds /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
4751da177e4SLinus Torvalds 
4761da177e4SLinus Torvalds /*
4771da177e4SLinus Torvalds  * Note, the leftmost status byte is common among adapter, port
4781da177e4SLinus Torvalds  * and unit
4791da177e4SLinus Torvalds  */
4801da177e4SLinus Torvalds #define ZFCP_COMMON_FLAGS			0xfff00000
4811da177e4SLinus Torvalds #define ZFCP_SPECIFIC_FLAGS			0x000fffff
4821da177e4SLinus Torvalds 
4831da177e4SLinus Torvalds /* common status bits */
4841da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_REMOVE		0x80000000
4851da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_RUNNING		0x40000000
4861da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_ERP_FAILED		0x20000000
4871da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_UNBLOCKED		0x10000000
4881da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_OPENING              0x08000000
4891da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_OPEN                 0x04000000
4901da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_CLOSING              0x02000000
4911da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_ERP_INUSE		0x01000000
4921da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_ACCESS_DENIED	0x00800000
4931da177e4SLinus Torvalds 
4941da177e4SLinus Torvalds /* adapter status */
4951da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_QDIOUP		0x00000002
4961da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_REGISTERED		0x00000004
4971da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_XCONFIG_OK		0x00000008
4981da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT	0x00000010
4991da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP	0x00000020
5001da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL	0x00000080
5011da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_ERP_PENDING		0x00000100
5021da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED	0x00000200
5031da177e4SLinus Torvalds 
5041da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_SCSI_UP			\
5051da177e4SLinus Torvalds 		(ZFCP_STATUS_COMMON_UNBLOCKED |	\
5061da177e4SLinus Torvalds 		 ZFCP_STATUS_ADAPTER_REGISTERED)
5071da177e4SLinus Torvalds 
5081da177e4SLinus Torvalds 
5091da177e4SLinus Torvalds /* FC-PH/FC-GS well-known address identifiers for generic services */
5101da177e4SLinus Torvalds #define ZFCP_DID_MANAGEMENT_SERVICE		0xFFFFFA
5111da177e4SLinus Torvalds #define ZFCP_DID_TIME_SERVICE			0xFFFFFB
5121da177e4SLinus Torvalds #define ZFCP_DID_DIRECTORY_SERVICE		0xFFFFFC
5131da177e4SLinus Torvalds #define ZFCP_DID_ALIAS_SERVICE			0xFFFFF8
5141da177e4SLinus Torvalds #define ZFCP_DID_KEY_DISTRIBUTION_SERVICE	0xFFFFF7
5151da177e4SLinus Torvalds 
5161da177e4SLinus Torvalds /* remote port status */
5171da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_PHYS_OPEN		0x00000001
5181da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_DID_DID		0x00000002
5191da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_PHYS_CLOSING		0x00000004
5201da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_NO_WWPN		0x00000008
5211da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_NO_SCSI_ID		0x00000010
5221da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_INVALID_WWPN		0x00000020
5231da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_ACCESS_DENIED		0x00000040
5241da177e4SLinus Torvalds 
5251da177e4SLinus Torvalds /* for ports with well known addresses */
5261da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_WKA \
5271da177e4SLinus Torvalds 		(ZFCP_STATUS_PORT_NO_WWPN | \
5281da177e4SLinus Torvalds 		 ZFCP_STATUS_PORT_NO_SCSI_ID)
5291da177e4SLinus Torvalds 
5301da177e4SLinus Torvalds /* logical unit status */
5311da177e4SLinus Torvalds #define ZFCP_STATUS_UNIT_NOTSUPPUNITRESET	0x00000001
5321da177e4SLinus Torvalds #define ZFCP_STATUS_UNIT_TEMPORARY		0x00000002
5331da177e4SLinus Torvalds #define ZFCP_STATUS_UNIT_SHARED			0x00000004
5341da177e4SLinus Torvalds #define ZFCP_STATUS_UNIT_READONLY		0x00000008
5351da177e4SLinus Torvalds 
5361da177e4SLinus Torvalds /* FSF request status (this does not have a common part) */
5371da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_NOT_INIT		0x00000000
5381da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_POOL  		0x00000001
5391da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT	0x00000002
5401da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_COMPLETED		0x00000004
5411da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_ERROR		0x00000008
5421da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_CLEANUP		0x00000010
5431da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_ABORTING		0x00000020
5441da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED	0x00000040
5451da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED       0x00000080
5461da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_ABORTED              0x00000100
5471da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED         0x00000200
5481da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP        0x00000400
5491da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_RETRY                0x00000800
5501da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_DISMISSED            0x00001000
5511da177e4SLinus Torvalds 
5521da177e4SLinus Torvalds /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
5531da177e4SLinus Torvalds 
5541da177e4SLinus Torvalds #define ZFCP_MAX_ERPS                   3
5551da177e4SLinus Torvalds 
5561da177e4SLinus Torvalds #define ZFCP_ERP_FSFREQ_TIMEOUT		(30 * HZ)
5571da177e4SLinus Torvalds #define ZFCP_ERP_MEMWAIT_TIMEOUT	HZ
5581da177e4SLinus Torvalds 
5591da177e4SLinus Torvalds #define ZFCP_STATUS_ERP_TIMEDOUT	0x10000000
5601da177e4SLinus Torvalds #define ZFCP_STATUS_ERP_CLOSE_ONLY	0x01000000
5611da177e4SLinus Torvalds #define ZFCP_STATUS_ERP_DISMISSING	0x00100000
5621da177e4SLinus Torvalds #define ZFCP_STATUS_ERP_DISMISSED	0x00200000
5631da177e4SLinus Torvalds #define ZFCP_STATUS_ERP_LOWMEM		0x00400000
5641da177e4SLinus Torvalds 
5651da177e4SLinus Torvalds #define ZFCP_ERP_STEP_UNINITIALIZED	0x00000000
5661da177e4SLinus Torvalds #define ZFCP_ERP_STEP_FSF_XCONFIG	0x00000001
5671da177e4SLinus Torvalds #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING	0x00000010
5681da177e4SLinus Torvalds #define ZFCP_ERP_STEP_PORT_CLOSING	0x00000100
5691da177e4SLinus Torvalds #define ZFCP_ERP_STEP_NAMESERVER_OPEN	0x00000200
5701da177e4SLinus Torvalds #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP	0x00000400
5711da177e4SLinus Torvalds #define ZFCP_ERP_STEP_PORT_OPENING	0x00000800
5721da177e4SLinus Torvalds #define ZFCP_ERP_STEP_UNIT_CLOSING	0x00001000
5731da177e4SLinus Torvalds #define ZFCP_ERP_STEP_UNIT_OPENING	0x00002000
5741da177e4SLinus Torvalds 
5751da177e4SLinus Torvalds /* Ordered by escalation level (necessary for proper erp-code operation) */
5761da177e4SLinus Torvalds #define ZFCP_ERP_ACTION_REOPEN_ADAPTER		0x4
5771da177e4SLinus Torvalds #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED	0x3
5781da177e4SLinus Torvalds #define ZFCP_ERP_ACTION_REOPEN_PORT		0x2
5791da177e4SLinus Torvalds #define ZFCP_ERP_ACTION_REOPEN_UNIT		0x1
5801da177e4SLinus Torvalds 
5811da177e4SLinus Torvalds #define ZFCP_ERP_ACTION_RUNNING			0x1
5821da177e4SLinus Torvalds #define ZFCP_ERP_ACTION_READY			0x2
5831da177e4SLinus Torvalds 
5841da177e4SLinus Torvalds #define ZFCP_ERP_SUCCEEDED	0x0
5851da177e4SLinus Torvalds #define ZFCP_ERP_FAILED		0x1
5861da177e4SLinus Torvalds #define ZFCP_ERP_CONTINUES	0x2
5871da177e4SLinus Torvalds #define ZFCP_ERP_EXIT		0x3
5881da177e4SLinus Torvalds #define ZFCP_ERP_DISMISSED	0x4
5891da177e4SLinus Torvalds #define ZFCP_ERP_NOMEM		0x5
5901da177e4SLinus Torvalds 
5911da177e4SLinus Torvalds 
5921da177e4SLinus Torvalds /******************** CFDC SPECIFIC STUFF *****************************/
5931da177e4SLinus Torvalds 
5941da177e4SLinus Torvalds /* Firewall data channel sense data record */
5951da177e4SLinus Torvalds struct zfcp_cfdc_sense_data {
5961da177e4SLinus Torvalds 	u32 signature;           /* Request signature */
5971da177e4SLinus Torvalds 	u32 devno;               /* FCP adapter device number */
5981da177e4SLinus Torvalds 	u32 command;             /* Command code */
5991da177e4SLinus Torvalds 	u32 fsf_status;          /* FSF request status and status qualifier */
6001da177e4SLinus Torvalds 	u8  fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
6011da177e4SLinus Torvalds 	u8  payloads[256];       /* Access conflicts list */
6021da177e4SLinus Torvalds 	u8  control_file[0];     /* Access control table */
6031da177e4SLinus Torvalds };
6041da177e4SLinus Torvalds 
6051da177e4SLinus Torvalds #define ZFCP_CFDC_SIGNATURE			0xCFDCACDF
6061da177e4SLinus Torvalds 
6071da177e4SLinus Torvalds #define ZFCP_CFDC_CMND_DOWNLOAD_NORMAL		0x00010001
6081da177e4SLinus Torvalds #define ZFCP_CFDC_CMND_DOWNLOAD_FORCE		0x00010101
6091da177e4SLinus Torvalds #define ZFCP_CFDC_CMND_FULL_ACCESS		0x00000201
6101da177e4SLinus Torvalds #define ZFCP_CFDC_CMND_RESTRICTED_ACCESS	0x00000401
6111da177e4SLinus Torvalds #define ZFCP_CFDC_CMND_UPLOAD			0x00010002
6121da177e4SLinus Torvalds 
6131da177e4SLinus Torvalds #define ZFCP_CFDC_DOWNLOAD			0x00000001
6141da177e4SLinus Torvalds #define ZFCP_CFDC_UPLOAD			0x00000002
6151da177e4SLinus Torvalds #define ZFCP_CFDC_WITH_CONTROL_FILE		0x00010000
6161da177e4SLinus Torvalds 
6171da177e4SLinus Torvalds #define ZFCP_CFDC_DEV_NAME			"zfcp_cfdc"
6181da177e4SLinus Torvalds #define ZFCP_CFDC_DEV_MAJOR			MISC_MAJOR
6191da177e4SLinus Torvalds #define ZFCP_CFDC_DEV_MINOR			MISC_DYNAMIC_MINOR
6201da177e4SLinus Torvalds 
6211da177e4SLinus Torvalds #define ZFCP_CFDC_MAX_CONTROL_FILE_SIZE		127 * 1024
6221da177e4SLinus Torvalds 
6231da177e4SLinus Torvalds /************************* STRUCTURE DEFINITIONS *****************************/
6241da177e4SLinus Torvalds 
6251da177e4SLinus Torvalds struct zfcp_fsf_req;
6261da177e4SLinus Torvalds 
6271da177e4SLinus Torvalds /* holds various memory pools of an adapter */
6281da177e4SLinus Torvalds struct zfcp_adapter_mempool {
6291da177e4SLinus Torvalds 	mempool_t *fsf_req_erp;
6301da177e4SLinus Torvalds 	mempool_t *fsf_req_scsi;
6311da177e4SLinus Torvalds 	mempool_t *fsf_req_abort;
6321da177e4SLinus Torvalds 	mempool_t *fsf_req_status_read;
6331da177e4SLinus Torvalds 	mempool_t *data_status_read;
6341da177e4SLinus Torvalds 	mempool_t *data_gid_pn;
6351da177e4SLinus Torvalds };
6361da177e4SLinus Torvalds 
6371da177e4SLinus Torvalds struct  zfcp_exchange_config_data{
6381da177e4SLinus Torvalds };
6391da177e4SLinus Torvalds 
6401da177e4SLinus Torvalds struct zfcp_open_port {
6411da177e4SLinus Torvalds         struct zfcp_port *port;
6421da177e4SLinus Torvalds };
6431da177e4SLinus Torvalds 
6441da177e4SLinus Torvalds struct zfcp_close_port {
6451da177e4SLinus Torvalds 	struct zfcp_port *port;
6461da177e4SLinus Torvalds };
6471da177e4SLinus Torvalds 
6481da177e4SLinus Torvalds struct zfcp_open_unit {
6491da177e4SLinus Torvalds 	struct zfcp_unit *unit;
6501da177e4SLinus Torvalds };
6511da177e4SLinus Torvalds 
6521da177e4SLinus Torvalds struct zfcp_close_unit {
6531da177e4SLinus Torvalds 	struct zfcp_unit *unit;
6541da177e4SLinus Torvalds };
6551da177e4SLinus Torvalds 
6561da177e4SLinus Torvalds struct zfcp_close_physical_port {
6571da177e4SLinus Torvalds         struct zfcp_port *port;
6581da177e4SLinus Torvalds };
6591da177e4SLinus Torvalds 
6601da177e4SLinus Torvalds struct zfcp_send_fcp_command_task {
6611da177e4SLinus Torvalds 	struct zfcp_fsf_req *fsf_req;
6621da177e4SLinus Torvalds 	struct zfcp_unit *unit;
6631da177e4SLinus Torvalds  	struct scsi_cmnd *scsi_cmnd;
6641da177e4SLinus Torvalds 	unsigned long start_jiffies;
6651da177e4SLinus Torvalds };
6661da177e4SLinus Torvalds 
6671da177e4SLinus Torvalds struct zfcp_send_fcp_command_task_management {
6681da177e4SLinus Torvalds 	struct zfcp_unit *unit;
6691da177e4SLinus Torvalds };
6701da177e4SLinus Torvalds 
6711da177e4SLinus Torvalds struct zfcp_abort_fcp_command {
6721da177e4SLinus Torvalds 	struct zfcp_fsf_req *fsf_req;
6731da177e4SLinus Torvalds 	struct zfcp_unit *unit;
6741da177e4SLinus Torvalds };
6751da177e4SLinus Torvalds 
6761da177e4SLinus Torvalds /*
6771da177e4SLinus Torvalds  * header for CT_IU
6781da177e4SLinus Torvalds  */
6791da177e4SLinus Torvalds struct ct_hdr {
6801da177e4SLinus Torvalds 	u8 revision;		// 0x01
6811da177e4SLinus Torvalds 	u8 in_id[3];		// 0x00
6821da177e4SLinus Torvalds 	u8 gs_type;		// 0xFC	Directory Service
6831da177e4SLinus Torvalds 	u8 gs_subtype;		// 0x02	Name Server
6841da177e4SLinus Torvalds 	u8 options;		// 0x00 single bidirectional exchange
6851da177e4SLinus Torvalds 	u8 reserved0;
6861da177e4SLinus Torvalds 	u16 cmd_rsp_code;	// 0x0121 GID_PN, or 0x0100 GA_NXT
6871da177e4SLinus Torvalds 	u16 max_res_size;	// <= (4096 - 16) / 4
6881da177e4SLinus Torvalds 	u8 reserved1;
6891da177e4SLinus Torvalds 	u8 reason_code;
6901da177e4SLinus Torvalds 	u8 reason_code_expl;
6911da177e4SLinus Torvalds 	u8 vendor_unique;
6921da177e4SLinus Torvalds } __attribute__ ((packed));
6931da177e4SLinus Torvalds 
6941da177e4SLinus Torvalds /* nameserver request CT_IU -- for requests where
6951da177e4SLinus Torvalds  * a port name is required */
6961da177e4SLinus Torvalds struct ct_iu_gid_pn_req {
6971da177e4SLinus Torvalds 	struct ct_hdr header;
6981da177e4SLinus Torvalds 	wwn_t wwpn;
6991da177e4SLinus Torvalds } __attribute__ ((packed));
7001da177e4SLinus Torvalds 
7011da177e4SLinus Torvalds /* FS_ACC IU and data unit for GID_PN nameserver request */
7021da177e4SLinus Torvalds struct ct_iu_gid_pn_resp {
7031da177e4SLinus Torvalds 	struct ct_hdr header;
7041da177e4SLinus Torvalds 	fc_id_t d_id;
7051da177e4SLinus Torvalds } __attribute__ ((packed));
7061da177e4SLinus Torvalds 
7071da177e4SLinus Torvalds typedef void (*zfcp_send_ct_handler_t)(unsigned long);
7081da177e4SLinus Torvalds 
7091da177e4SLinus Torvalds /**
7101da177e4SLinus Torvalds  * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
7111da177e4SLinus Torvalds  * @port: port where the request is sent to
7121da177e4SLinus Torvalds  * @req: scatter-gather list for request
7131da177e4SLinus Torvalds  * @resp: scatter-gather list for response
7141da177e4SLinus Torvalds  * @req_count: number of elements in request scatter-gather list
7151da177e4SLinus Torvalds  * @resp_count: number of elements in response scatter-gather list
7161da177e4SLinus Torvalds  * @handler: handler function (called for response to the request)
7171da177e4SLinus Torvalds  * @handler_data: data passed to handler function
7181da177e4SLinus Torvalds  * @pool: pointer to memory pool for ct request structure
7191da177e4SLinus Torvalds  * @timeout: FSF timeout for this request
7201da177e4SLinus Torvalds  * @timer: timer (e.g. for request initiated by erp)
7211da177e4SLinus Torvalds  * @completion: completion for synchronization purposes
7221da177e4SLinus Torvalds  * @status: used to pass error status to calling function
7231da177e4SLinus Torvalds  */
7241da177e4SLinus Torvalds struct zfcp_send_ct {
7251da177e4SLinus Torvalds 	struct zfcp_port *port;
7261da177e4SLinus Torvalds 	struct scatterlist *req;
7271da177e4SLinus Torvalds 	struct scatterlist *resp;
7281da177e4SLinus Torvalds 	unsigned int req_count;
7291da177e4SLinus Torvalds 	unsigned int resp_count;
7301da177e4SLinus Torvalds 	zfcp_send_ct_handler_t handler;
7311da177e4SLinus Torvalds 	unsigned long handler_data;
7321da177e4SLinus Torvalds 	mempool_t *pool;
7331da177e4SLinus Torvalds 	int timeout;
7341da177e4SLinus Torvalds 	struct timer_list *timer;
7351da177e4SLinus Torvalds 	struct completion *completion;
7361da177e4SLinus Torvalds 	int status;
7371da177e4SLinus Torvalds };
7381da177e4SLinus Torvalds 
7391da177e4SLinus Torvalds /* used for name server requests in error recovery */
7401da177e4SLinus Torvalds struct zfcp_gid_pn_data {
7411da177e4SLinus Torvalds 	struct zfcp_send_ct ct;
7421da177e4SLinus Torvalds 	struct scatterlist req;
7431da177e4SLinus Torvalds 	struct scatterlist resp;
7441da177e4SLinus Torvalds 	struct ct_iu_gid_pn_req ct_iu_req;
7451da177e4SLinus Torvalds 	struct ct_iu_gid_pn_resp ct_iu_resp;
7461da177e4SLinus Torvalds         struct zfcp_port *port;
7471da177e4SLinus Torvalds };
7481da177e4SLinus Torvalds 
7491da177e4SLinus Torvalds typedef void (*zfcp_send_els_handler_t)(unsigned long);
7501da177e4SLinus Torvalds 
7511da177e4SLinus Torvalds /**
7521da177e4SLinus Torvalds  * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
7531da177e4SLinus Torvalds  * @adapter: adapter where request is sent from
7541da177e4SLinus Torvalds  * @d_id: destiniation id of port where request is sent to
7551da177e4SLinus Torvalds  * @req: scatter-gather list for request
7561da177e4SLinus Torvalds  * @resp: scatter-gather list for response
7571da177e4SLinus Torvalds  * @req_count: number of elements in request scatter-gather list
7581da177e4SLinus Torvalds  * @resp_count: number of elements in response scatter-gather list
7591da177e4SLinus Torvalds  * @handler: handler function (called for response to the request)
7601da177e4SLinus Torvalds  * @handler_data: data passed to handler function
7611da177e4SLinus Torvalds  * @timer: timer (e.g. for request initiated by erp)
7621da177e4SLinus Torvalds  * @completion: completion for synchronization purposes
7631da177e4SLinus Torvalds  * @ls_code: hex code of ELS command
7641da177e4SLinus Torvalds  * @status: used to pass error status to calling function
7651da177e4SLinus Torvalds  */
7661da177e4SLinus Torvalds struct zfcp_send_els {
7671da177e4SLinus Torvalds 	struct zfcp_adapter *adapter;
7681da177e4SLinus Torvalds 	fc_id_t d_id;
7691da177e4SLinus Torvalds 	struct scatterlist *req;
7701da177e4SLinus Torvalds 	struct scatterlist *resp;
7711da177e4SLinus Torvalds 	unsigned int req_count;
7721da177e4SLinus Torvalds 	unsigned int resp_count;
7731da177e4SLinus Torvalds 	zfcp_send_els_handler_t handler;
7741da177e4SLinus Torvalds 	unsigned long handler_data;
7751da177e4SLinus Torvalds 	struct timer_list *timer;
7761da177e4SLinus Torvalds 	struct completion *completion;
7771da177e4SLinus Torvalds 	int ls_code;
7781da177e4SLinus Torvalds 	int status;
7791da177e4SLinus Torvalds };
7801da177e4SLinus Torvalds 
7811da177e4SLinus Torvalds struct zfcp_status_read {
7821da177e4SLinus Torvalds 	struct fsf_status_read_buffer *buffer;
7831da177e4SLinus Torvalds };
7841da177e4SLinus Torvalds 
7851da177e4SLinus Torvalds struct zfcp_fsf_done {
7861da177e4SLinus Torvalds 	struct completion *complete;
7871da177e4SLinus Torvalds 	int status;
7881da177e4SLinus Torvalds };
7891da177e4SLinus Torvalds 
7901da177e4SLinus Torvalds /* request specific data */
7911da177e4SLinus Torvalds union zfcp_req_data {
7921da177e4SLinus Torvalds 	struct zfcp_exchange_config_data exchange_config_data;
7931da177e4SLinus Torvalds 	struct zfcp_open_port		  open_port;
7941da177e4SLinus Torvalds 	struct zfcp_close_port		  close_port;
7951da177e4SLinus Torvalds 	struct zfcp_open_unit		  open_unit;
7961da177e4SLinus Torvalds 	struct zfcp_close_unit		  close_unit;
7971da177e4SLinus Torvalds 	struct zfcp_close_physical_port	  close_physical_port;
7981da177e4SLinus Torvalds 	struct zfcp_send_fcp_command_task send_fcp_command_task;
7991da177e4SLinus Torvalds         struct zfcp_send_fcp_command_task_management
8001da177e4SLinus Torvalds 					  send_fcp_command_task_management;
8011da177e4SLinus Torvalds 	struct zfcp_abort_fcp_command	  abort_fcp_command;
8021da177e4SLinus Torvalds 	struct zfcp_send_ct *send_ct;
8031da177e4SLinus Torvalds 	struct zfcp_send_els *send_els;
8041da177e4SLinus Torvalds 	struct zfcp_status_read 	  status_read;
8051da177e4SLinus Torvalds 	struct fsf_qtcb_bottom_port *port_data;
8061da177e4SLinus Torvalds };
8071da177e4SLinus Torvalds 
8081da177e4SLinus Torvalds struct zfcp_qdio_queue {
8091da177e4SLinus Torvalds 	struct qdio_buffer *buffer[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
8101da177e4SLinus Torvalds 	u8		   free_index;	      /* index of next free bfr
8111da177e4SLinus Torvalds 						 in queue (free_count>0) */
8121da177e4SLinus Torvalds 	atomic_t           free_count;	      /* number of free buffers
8131da177e4SLinus Torvalds 						 in queue */
8141da177e4SLinus Torvalds 	rwlock_t	   queue_lock;	      /* lock for operations on queue */
8151da177e4SLinus Torvalds         int                distance_from_int; /* SBALs used since PCI indication
8161da177e4SLinus Torvalds 						 was last set */
8171da177e4SLinus Torvalds };
8181da177e4SLinus Torvalds 
8191da177e4SLinus Torvalds struct zfcp_erp_action {
8201da177e4SLinus Torvalds 	struct list_head list;
8211da177e4SLinus Torvalds 	int action;	              /* requested action code */
8221da177e4SLinus Torvalds 	struct zfcp_adapter *adapter; /* device which should be recovered */
8231da177e4SLinus Torvalds 	struct zfcp_port *port;
8241da177e4SLinus Torvalds 	struct zfcp_unit *unit;
8251da177e4SLinus Torvalds 	volatile u32 status;	      /* recovery status */
8261da177e4SLinus Torvalds 	u32 step;	              /* active step of this erp action */
8271da177e4SLinus Torvalds 	struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
8281da177e4SLinus Torvalds 					 for this action */
8291da177e4SLinus Torvalds 	struct timer_list timer;
8301da177e4SLinus Torvalds };
8311da177e4SLinus Torvalds 
8321da177e4SLinus Torvalds 
8331da177e4SLinus Torvalds struct zfcp_adapter {
8341da177e4SLinus Torvalds 	struct list_head	list;              /* list of adapters */
8351da177e4SLinus Torvalds 	atomic_t                refcount;          /* reference count */
8361da177e4SLinus Torvalds 	wait_queue_head_t	remove_wq;         /* can be used to wait for
8371da177e4SLinus Torvalds 						      refcount drop to zero */
8381da177e4SLinus Torvalds 	wwn_t			wwnn;	           /* WWNN */
8391da177e4SLinus Torvalds 	wwn_t			wwpn;	           /* WWPN */
8401da177e4SLinus Torvalds 	fc_id_t			s_id;	           /* N_Port ID */
8416f71d9bcS 	wwn_t			peer_wwnn;	   /* P2P peer WWNN */
8426f71d9bcS 	wwn_t			peer_wwpn;	   /* P2P peer WWPN */
8436f71d9bcS 	fc_id_t			peer_d_id;	   /* P2P peer D_ID */
8441da177e4SLinus Torvalds 	struct ccw_device       *ccw_device;	   /* S/390 ccw device */
8451da177e4SLinus Torvalds 	u8			fc_service_class;
8461da177e4SLinus Torvalds 	u32			fc_topology;	   /* FC topology */
8471da177e4SLinus Torvalds 	u32			fc_link_speed;	   /* FC interface speed */
8481da177e4SLinus Torvalds 	u32			hydra_version;	   /* Hydra version */
8491da177e4SLinus Torvalds 	u32			fsf_lic_version;
8501da177e4SLinus Torvalds         u32			supported_features;/* of FCP channel */
8511da177e4SLinus Torvalds         u32			hardware_version;  /* of FCP channel */
8521da177e4SLinus Torvalds         u8			serial_number[32]; /* of hardware */
8531da177e4SLinus Torvalds 	struct Scsi_Host	*scsi_host;	   /* Pointer to mid-layer */
8541da177e4SLinus Torvalds 	unsigned short          scsi_host_no;      /* Assigned host number */
8551da177e4SLinus Torvalds 	unsigned char		name[9];
8561da177e4SLinus Torvalds 	struct list_head	port_list_head;	   /* remote port list */
8571da177e4SLinus Torvalds 	struct list_head        port_remove_lh;    /* head of ports to be
8581da177e4SLinus Torvalds 						      removed */
8591da177e4SLinus Torvalds 	u32			ports;	           /* number of remote ports */
8601da177e4SLinus Torvalds         struct timer_list       scsi_er_timer;     /* SCSI err recovery watch */
8611da177e4SLinus Torvalds 	struct list_head	fsf_req_list_head; /* head of FSF req list */
8621da177e4SLinus Torvalds 	rwlock_t		fsf_req_list_lock; /* lock for ops on list of
8631da177e4SLinus Torvalds 						      FSF requests */
8641da177e4SLinus Torvalds         atomic_t       		fsf_reqs_active;   /* # active FSF reqs */
8651da177e4SLinus Torvalds 	struct zfcp_qdio_queue	request_queue;	   /* request queue */
8661da177e4SLinus Torvalds 	u32			fsf_req_seq_no;	   /* FSF cmnd seq number */
8671da177e4SLinus Torvalds 	wait_queue_head_t	request_wq;	   /* can be used to wait for
8681da177e4SLinus Torvalds 						      more avaliable SBALs */
8691da177e4SLinus Torvalds 	struct zfcp_qdio_queue	response_queue;	   /* response queue */
8701da177e4SLinus Torvalds 	rwlock_t		abort_lock;        /* Protects against SCSI
8711da177e4SLinus Torvalds 						      stack abort/command
8721da177e4SLinus Torvalds 						      completion races */
8731da177e4SLinus Torvalds 	u16			status_read_failed; /* # failed status reads */
8741da177e4SLinus Torvalds 	atomic_t		status;	           /* status of this adapter */
8751da177e4SLinus Torvalds 	struct list_head	erp_ready_head;	   /* error recovery for this
8761da177e4SLinus Torvalds 						      adapter/devices */
8771da177e4SLinus Torvalds 	struct list_head	erp_running_head;
8781da177e4SLinus Torvalds 	rwlock_t		erp_lock;
8791da177e4SLinus Torvalds 	struct semaphore	erp_ready_sem;
8801da177e4SLinus Torvalds 	wait_queue_head_t	erp_thread_wqh;
8811da177e4SLinus Torvalds 	wait_queue_head_t	erp_done_wqh;
8821da177e4SLinus Torvalds 	struct zfcp_erp_action	erp_action;	   /* pending error recovery */
8831da177e4SLinus Torvalds         atomic_t                erp_counter;
8841da177e4SLinus Torvalds 	u32			erp_total_count;   /* total nr of enqueued erp
8851da177e4SLinus Torvalds 						      actions */
8861da177e4SLinus Torvalds 	u32			erp_low_mem_count; /* nr of erp actions waiting
8871da177e4SLinus Torvalds 						      for memory */
8881da177e4SLinus Torvalds 	struct zfcp_port	*nameserver_port;  /* adapter's nameserver */
8891da177e4SLinus Torvalds         debug_info_t            *erp_dbf;          /* S/390 debug features */
8901da177e4SLinus Torvalds 	debug_info_t            *abort_dbf;
8911da177e4SLinus Torvalds 	debug_info_t            *in_els_dbf;
8921da177e4SLinus Torvalds 	debug_info_t            *cmd_dbf;
8931da177e4SLinus Torvalds 	spinlock_t              dbf_lock;
8941da177e4SLinus Torvalds 	struct zfcp_adapter_mempool	pool;      /* Adapter memory pools */
8951da177e4SLinus Torvalds 	struct qdio_initialize  qdio_init_data;    /* for qdio_establish */
8961da177e4SLinus Torvalds 	struct device           generic_services;  /* directory for WKA ports */
8971da177e4SLinus Torvalds };
8981da177e4SLinus Torvalds 
8991da177e4SLinus Torvalds /*
9001da177e4SLinus Torvalds  * the struct device sysfs_device must be at the beginning of this structure.
9011da177e4SLinus Torvalds  * pointer to struct device is used to free port structure in release function
9021da177e4SLinus Torvalds  * of the device. don't change!
9031da177e4SLinus Torvalds  */
9041da177e4SLinus Torvalds struct zfcp_port {
9051da177e4SLinus Torvalds 	struct device          sysfs_device;   /* sysfs device */
9061da177e4SLinus Torvalds 	struct list_head       list;	       /* list of remote ports */
9071da177e4SLinus Torvalds 	atomic_t               refcount;       /* reference count */
9081da177e4SLinus Torvalds 	wait_queue_head_t      remove_wq;      /* can be used to wait for
9091da177e4SLinus Torvalds 						  refcount drop to zero */
9101da177e4SLinus Torvalds 	struct zfcp_adapter    *adapter;       /* adapter used to access port */
9111da177e4SLinus Torvalds 	struct list_head       unit_list_head; /* head of logical unit list */
9121da177e4SLinus Torvalds 	struct list_head       unit_remove_lh; /* head of luns to be removed
9131da177e4SLinus Torvalds 						  list */
9141da177e4SLinus Torvalds 	u32		       units;	       /* # of logical units in list */
9151da177e4SLinus Torvalds 	atomic_t	       status;	       /* status of this remote port */
9161da177e4SLinus Torvalds 	scsi_id_t	       scsi_id;	       /* own SCSI ID */
9171da177e4SLinus Torvalds 	wwn_t		       wwnn;	       /* WWNN if known */
9181da177e4SLinus Torvalds 	wwn_t		       wwpn;	       /* WWPN */
9191da177e4SLinus Torvalds 	fc_id_t		       d_id;	       /* D_ID */
9201da177e4SLinus Torvalds 	u32		       handle;	       /* handle assigned by FSF */
9211da177e4SLinus Torvalds 	struct zfcp_erp_action erp_action;     /* pending error recovery */
9221da177e4SLinus Torvalds         atomic_t               erp_counter;
9231da177e4SLinus Torvalds };
9241da177e4SLinus Torvalds 
9251da177e4SLinus Torvalds /* the struct device sysfs_device must be at the beginning of this structure.
9261da177e4SLinus Torvalds  * pointer to struct device is used to free unit structure in release function
9271da177e4SLinus Torvalds  * of the device. don't change!
9281da177e4SLinus Torvalds  */
9291da177e4SLinus Torvalds struct zfcp_unit {
9301da177e4SLinus Torvalds 	struct device          sysfs_device;   /* sysfs device */
9311da177e4SLinus Torvalds 	struct list_head       list;	       /* list of logical units */
9321da177e4SLinus Torvalds 	atomic_t               refcount;       /* reference count */
9331da177e4SLinus Torvalds 	wait_queue_head_t      remove_wq;      /* can be used to wait for
9341da177e4SLinus Torvalds 						  refcount drop to zero */
9351da177e4SLinus Torvalds 	struct zfcp_port       *port;	       /* remote port of unit */
9361da177e4SLinus Torvalds 	atomic_t	       status;	       /* status of this logical unit */
9371da177e4SLinus Torvalds 	scsi_lun_t	       scsi_lun;       /* own SCSI LUN */
9381da177e4SLinus Torvalds 	fcp_lun_t	       fcp_lun;	       /* own FCP_LUN */
9391da177e4SLinus Torvalds 	u32		       handle;	       /* handle assigned by FSF */
9401da177e4SLinus Torvalds         struct scsi_device     *device;        /* scsi device struct pointer */
9411da177e4SLinus Torvalds 	struct zfcp_erp_action erp_action;     /* pending error recovery */
9421da177e4SLinus Torvalds         atomic_t               erp_counter;
9431da177e4SLinus Torvalds };
9441da177e4SLinus Torvalds 
9451da177e4SLinus Torvalds /* FSF request */
9461da177e4SLinus Torvalds struct zfcp_fsf_req {
9471da177e4SLinus Torvalds 	struct list_head       list;	       /* list of FSF requests */
9481da177e4SLinus Torvalds 	struct zfcp_adapter    *adapter;       /* adapter request belongs to */
9491da177e4SLinus Torvalds 	u8		       sbal_number;    /* nr of SBALs free for use */
9501da177e4SLinus Torvalds 	u8		       sbal_first;     /* first SBAL for this request */
9511da177e4SLinus Torvalds 	u8		       sbal_last;      /* last possible SBAL for
9521da177e4SLinus Torvalds 						  this reuest */
9531da177e4SLinus Torvalds 	u8		       sbal_curr;      /* current SBAL during creation
9541da177e4SLinus Torvalds 						  of request */
9551da177e4SLinus Torvalds 	u8		       sbale_curr;     /* current SBALE during creation
9561da177e4SLinus Torvalds 						  of request */
9571da177e4SLinus Torvalds 	wait_queue_head_t      completion_wq;  /* can be used by a routine
9581da177e4SLinus Torvalds 						  to wait for completion */
9591da177e4SLinus Torvalds 	volatile u32	       status;	       /* status of this request */
9601da177e4SLinus Torvalds 	u32		       fsf_command;    /* FSF Command copy */
9611da177e4SLinus Torvalds 	struct fsf_qtcb	       *qtcb;	       /* address of associated QTCB */
9621da177e4SLinus Torvalds 	u32		       seq_no;         /* Sequence number of request */
9631da177e4SLinus Torvalds         union zfcp_req_data    data;           /* Info fields of request */
9641da177e4SLinus Torvalds 	struct zfcp_erp_action *erp_action;    /* used if this request is
9651da177e4SLinus Torvalds 						  issued on behalf of erp */
9661da177e4SLinus Torvalds 	mempool_t	       *pool;	       /* used if request was alloacted
9671da177e4SLinus Torvalds 						  from emergency pool */
9681da177e4SLinus Torvalds };
9691da177e4SLinus Torvalds 
9701da177e4SLinus Torvalds typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
9711da177e4SLinus Torvalds 
9721da177e4SLinus Torvalds /* driver data */
9731da177e4SLinus Torvalds struct zfcp_data {
9741da177e4SLinus Torvalds 	struct scsi_host_template scsi_host_template;
9751da177e4SLinus Torvalds         atomic_t                status;             /* Module status flags */
9761da177e4SLinus Torvalds 	struct list_head	adapter_list_head;  /* head of adapter list */
9771da177e4SLinus Torvalds 	struct list_head	adapter_remove_lh;  /* head of adapters to be
9781da177e4SLinus Torvalds 						       removed */
9791da177e4SLinus Torvalds         rwlock_t                status_read_lock;   /* for status read thread */
9801da177e4SLinus Torvalds         struct list_head        status_read_receive_head;
9811da177e4SLinus Torvalds         struct list_head        status_read_send_head;
9821da177e4SLinus Torvalds         struct semaphore        status_read_sema;
9831da177e4SLinus Torvalds 	wait_queue_head_t	status_read_thread_wqh;
9841da177e4SLinus Torvalds 	u32			adapters;	    /* # of adapters in list */
9851da177e4SLinus Torvalds 	rwlock_t                config_lock;        /* serialises changes
9861da177e4SLinus Torvalds 						       to adapter/port/unit
9871da177e4SLinus Torvalds 						       lists */
9881da177e4SLinus Torvalds 	struct semaphore        config_sema;        /* serialises configuration
9891da177e4SLinus Torvalds 						       changes */
9901da177e4SLinus Torvalds 	atomic_t		loglevel;            /* current loglevel */
9911da177e4SLinus Torvalds 	char                    init_busid[BUS_ID_SIZE];
9921da177e4SLinus Torvalds 	wwn_t                   init_wwpn;
9931da177e4SLinus Torvalds 	fcp_lun_t               init_fcp_lun;
9941da177e4SLinus Torvalds 	char 			*driver_version;
9951da177e4SLinus Torvalds };
9961da177e4SLinus Torvalds 
9971da177e4SLinus Torvalds /**
9981da177e4SLinus Torvalds  * struct zfcp_sg_list - struct describing a scatter-gather list
9991da177e4SLinus Torvalds  * @sg: pointer to array of (struct scatterlist)
10001da177e4SLinus Torvalds  * @count: number of elements in scatter-gather list
10011da177e4SLinus Torvalds  */
10021da177e4SLinus Torvalds struct zfcp_sg_list {
10031da177e4SLinus Torvalds 	struct scatterlist *sg;
10041da177e4SLinus Torvalds 	unsigned int count;
10051da177e4SLinus Torvalds };
10061da177e4SLinus Torvalds 
10071da177e4SLinus Torvalds /* number of elements for various memory pools */
10081da177e4SLinus Torvalds #define ZFCP_POOL_FSF_REQ_ERP_NR	1
10091da177e4SLinus Torvalds #define ZFCP_POOL_FSF_REQ_SCSI_NR	1
10101da177e4SLinus Torvalds #define ZFCP_POOL_FSF_REQ_ABORT_NR	1
10111da177e4SLinus Torvalds #define ZFCP_POOL_STATUS_READ_NR	ZFCP_STATUS_READS_RECOM
10121da177e4SLinus Torvalds #define ZFCP_POOL_DATA_GID_PN_NR	1
10131da177e4SLinus Torvalds 
10141da177e4SLinus Torvalds /* struct used by memory pools for fsf_requests */
10151da177e4SLinus Torvalds struct zfcp_fsf_req_pool_element {
10161da177e4SLinus Torvalds 	struct zfcp_fsf_req fsf_req;
10171da177e4SLinus Torvalds 	struct fsf_qtcb qtcb;
10181da177e4SLinus Torvalds };
10191da177e4SLinus Torvalds 
10201da177e4SLinus Torvalds /********************** ZFCP SPECIFIC DEFINES ********************************/
10211da177e4SLinus Torvalds 
10221da177e4SLinus Torvalds #define ZFCP_FSFREQ_CLEANUP_TIMEOUT	HZ/10
10231da177e4SLinus Torvalds 
10241da177e4SLinus Torvalds #define ZFCP_KNOWN              0x00000001
10251da177e4SLinus Torvalds #define ZFCP_REQ_AUTO_CLEANUP	0x00000002
10261da177e4SLinus Torvalds #define ZFCP_WAIT_FOR_SBAL	0x00000004
10271da177e4SLinus Torvalds #define ZFCP_REQ_NO_QTCB	0x00000008
10281da177e4SLinus Torvalds 
10291da177e4SLinus Torvalds #define ZFCP_SET                0x00000100
10301da177e4SLinus Torvalds #define ZFCP_CLEAR              0x00000200
10311da177e4SLinus Torvalds 
10321da177e4SLinus Torvalds #define ZFCP_INTERRUPTIBLE	1
10331da177e4SLinus Torvalds #define ZFCP_UNINTERRUPTIBLE	0
10341da177e4SLinus Torvalds 
10351da177e4SLinus Torvalds #ifndef atomic_test_mask
10361da177e4SLinus Torvalds #define atomic_test_mask(mask, target) \
10371da177e4SLinus Torvalds            ((atomic_read(target) & mask) == mask)
10381da177e4SLinus Torvalds #endif
10391da177e4SLinus Torvalds 
10401da177e4SLinus Torvalds extern void _zfcp_hex_dump(char *, int);
10411da177e4SLinus Torvalds #define ZFCP_HEX_DUMP(level, addr, count) \
10421da177e4SLinus Torvalds 		if (ZFCP_LOG_CHECK(level)) { \
10431da177e4SLinus Torvalds 			_zfcp_hex_dump(addr, count); \
10441da177e4SLinus Torvalds 		}
10451da177e4SLinus Torvalds 
10461da177e4SLinus Torvalds #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
10471da177e4SLinus Torvalds #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
10481da177e4SLinus Torvalds #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
10491da177e4SLinus Torvalds 
10501da177e4SLinus Torvalds /*
10511da177e4SLinus Torvalds  *  functions needed for reference/usage counting
10521da177e4SLinus Torvalds  */
10531da177e4SLinus Torvalds 
10541da177e4SLinus Torvalds static inline void
10551da177e4SLinus Torvalds zfcp_unit_get(struct zfcp_unit *unit)
10561da177e4SLinus Torvalds {
10571da177e4SLinus Torvalds 	atomic_inc(&unit->refcount);
10581da177e4SLinus Torvalds }
10591da177e4SLinus Torvalds 
10601da177e4SLinus Torvalds static inline void
10611da177e4SLinus Torvalds zfcp_unit_put(struct zfcp_unit *unit)
10621da177e4SLinus Torvalds {
10631da177e4SLinus Torvalds 	if (atomic_dec_return(&unit->refcount) == 0)
10641da177e4SLinus Torvalds 		wake_up(&unit->remove_wq);
10651da177e4SLinus Torvalds }
10661da177e4SLinus Torvalds 
10671da177e4SLinus Torvalds static inline void
10681da177e4SLinus Torvalds zfcp_unit_wait(struct zfcp_unit *unit)
10691da177e4SLinus Torvalds {
10701da177e4SLinus Torvalds 	wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
10711da177e4SLinus Torvalds }
10721da177e4SLinus Torvalds 
10731da177e4SLinus Torvalds static inline void
10741da177e4SLinus Torvalds zfcp_port_get(struct zfcp_port *port)
10751da177e4SLinus Torvalds {
10761da177e4SLinus Torvalds 	atomic_inc(&port->refcount);
10771da177e4SLinus Torvalds }
10781da177e4SLinus Torvalds 
10791da177e4SLinus Torvalds static inline void
10801da177e4SLinus Torvalds zfcp_port_put(struct zfcp_port *port)
10811da177e4SLinus Torvalds {
10821da177e4SLinus Torvalds 	if (atomic_dec_return(&port->refcount) == 0)
10831da177e4SLinus Torvalds 		wake_up(&port->remove_wq);
10841da177e4SLinus Torvalds }
10851da177e4SLinus Torvalds 
10861da177e4SLinus Torvalds static inline void
10871da177e4SLinus Torvalds zfcp_port_wait(struct zfcp_port *port)
10881da177e4SLinus Torvalds {
10891da177e4SLinus Torvalds 	wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
10901da177e4SLinus Torvalds }
10911da177e4SLinus Torvalds 
10921da177e4SLinus Torvalds static inline void
10931da177e4SLinus Torvalds zfcp_adapter_get(struct zfcp_adapter *adapter)
10941da177e4SLinus Torvalds {
10951da177e4SLinus Torvalds 	atomic_inc(&adapter->refcount);
10961da177e4SLinus Torvalds }
10971da177e4SLinus Torvalds 
10981da177e4SLinus Torvalds static inline void
10991da177e4SLinus Torvalds zfcp_adapter_put(struct zfcp_adapter *adapter)
11001da177e4SLinus Torvalds {
11011da177e4SLinus Torvalds 	if (atomic_dec_return(&adapter->refcount) == 0)
11021da177e4SLinus Torvalds 		wake_up(&adapter->remove_wq);
11031da177e4SLinus Torvalds }
11041da177e4SLinus Torvalds 
11051da177e4SLinus Torvalds static inline void
11061da177e4SLinus Torvalds zfcp_adapter_wait(struct zfcp_adapter *adapter)
11071da177e4SLinus Torvalds {
11081da177e4SLinus Torvalds 	wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
11091da177e4SLinus Torvalds }
11101da177e4SLinus Torvalds 
11111da177e4SLinus Torvalds #endif /* ZFCP_DEF_H */
1112