1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 21da177e4SLinus Torvalds /* 3553448f6SChristof Schmitt * zfcp device driver 41da177e4SLinus Torvalds * 5553448f6SChristof Schmitt * Global definitions for the zfcp device driver. 61da177e4SLinus Torvalds * 7c24635acSSteffen Maier * Copyright IBM Corp. 2002, 2017 81da177e4SLinus Torvalds */ 91da177e4SLinus Torvalds 101da177e4SLinus Torvalds #ifndef ZFCP_DEF_H 111da177e4SLinus Torvalds #define ZFCP_DEF_H 121da177e4SLinus Torvalds 131da177e4SLinus Torvalds /*************************** INCLUDES *****************************************/ 141da177e4SLinus Torvalds 151da177e4SLinus Torvalds #include <linux/init.h> 161da177e4SLinus Torvalds #include <linux/moduleparam.h> 171da177e4SLinus Torvalds #include <linux/major.h> 181da177e4SLinus Torvalds #include <linux/blkdev.h> 191da177e4SLinus Torvalds #include <linux/delay.h> 201da177e4SLinus Torvalds #include <linux/timer.h> 21dd52e0eaSHeiko Carstens #include <linux/slab.h> 22dd52e0eaSHeiko Carstens #include <linux/mempool.h> 23dd52e0eaSHeiko Carstens #include <linux/syscalls.h> 24f1346372SFUJITA Tomonori #include <linux/scatterlist.h> 25dd52e0eaSHeiko Carstens #include <linux/ioctl.h> 269d544f2bSSven Schuetz #include <scsi/fc/fc_fs.h> 279d544f2bSSven Schuetz #include <scsi/fc/fc_gs.h> 281da177e4SLinus Torvalds #include <scsi/scsi.h> 291da177e4SLinus Torvalds #include <scsi/scsi_tcq.h> 301da177e4SLinus Torvalds #include <scsi/scsi_cmnd.h> 311da177e4SLinus Torvalds #include <scsi/scsi_device.h> 321da177e4SLinus Torvalds #include <scsi/scsi_host.h> 331da177e4SLinus Torvalds #include <scsi/scsi_transport.h> 341da177e4SLinus Torvalds #include <scsi/scsi_transport_fc.h> 359d544f2bSSven Schuetz #include <scsi/scsi_bsg_fc.h> 361da177e4SLinus Torvalds #include <asm/ccwdev.h> 371da177e4SLinus Torvalds #include <asm/debug.h> 381da177e4SLinus Torvalds #include <asm/ebcdic.h> 39bd43a42bSChristof Schmitt #include <asm/sysinfo.h> 40dd52e0eaSHeiko Carstens #include "zfcp_fsf.h" 412d1e547fSSven Schuetz #include "zfcp_fc.h" 4234c2b712SChristof Schmitt #include "zfcp_qdio.h" 431da177e4SLinus Torvalds 441da177e4SLinus Torvalds /********************* FSF SPECIFIC DEFINES *********************************/ 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds /* ATTENTION: value must not be used by hardware */ 471da177e4SLinus Torvalds #define FSF_QTCB_UNSOLICITED_STATUS 0x6305 4822753fa5SAndreas Herrmann 491da177e4SLinus Torvalds /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/ 501da177e4SLinus Torvalds 511da177e4SLinus Torvalds /* 52e0c1da39SSteffen Maier * Note, the leftmost 12 status bits (3 nibbles) are common among adapter, port 53e0c1da39SSteffen Maier * and unit. This is a mask for bitwise 'and' with status values. 541da177e4SLinus Torvalds */ 551da177e4SLinus Torvalds #define ZFCP_COMMON_FLAGS 0xfff00000 561da177e4SLinus Torvalds 571da177e4SLinus Torvalds /* common status bits */ 581da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_RUNNING 0x40000000 591da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000 601da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000 611da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_OPEN 0x04000000 621da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000 631da177e4SLinus Torvalds #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000 64d736a27bSAndreas Herrmann #define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000 65cc8c2829SSwen Schillig #define ZFCP_STATUS_COMMON_NOESC 0x00200000 661da177e4SLinus Torvalds 671da177e4SLinus Torvalds /* adapter status */ 6886a9668aSSwen Schillig #define ZFCP_STATUS_ADAPTER_MB_ACT 0x00000001 691da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002 70339f4f4eSChristof Schmitt #define ZFCP_STATUS_ADAPTER_SIOSL_ISSUED 0x00000004 711da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008 721da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010 73cb452149SSteffen Maier #define ZFCP_STATUS_ADAPTER_SUSPENDED 0x00000040 741da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100 751da177e4SLinus Torvalds #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200 76dcc18f48SChristof Schmitt #define ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED 0x00000400 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds /* remote port status */ 791da177e4SLinus Torvalds #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001 8014e242eaSChristof Schmitt #define ZFCP_STATUS_PORT_LINK_TEST 0x00000002 811da177e4SLinus Torvalds 821da177e4SLinus Torvalds /* FSF request status (this does not have a common part) */ 831da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008 841da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010 851da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040 861da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080 871da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200 881da177e4SLinus Torvalds #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000 891da177e4SLinus Torvalds 901da177e4SLinus Torvalds /************************* STRUCTURE DEFINITIONS *****************************/ 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds struct zfcp_fsf_req; 931da177e4SLinus Torvalds 941da177e4SLinus Torvalds struct zfcp_erp_action { 951da177e4SLinus Torvalds struct list_head list; 961da177e4SLinus Torvalds int action; /* requested action code */ 971da177e4SLinus Torvalds struct zfcp_adapter *adapter; /* device which should be recovered */ 981da177e4SLinus Torvalds struct zfcp_port *port; 99b62a8d9bSChristof Schmitt struct scsi_device *sdev; 10044cc76f2SSwen Schillig u32 status; /* recovery status */ 1011da177e4SLinus Torvalds u32 step; /* active step of this erp action */ 102e60a6d69SChristof Schmitt unsigned long fsf_req_id; 1031da177e4SLinus Torvalds struct timer_list timer; 1041da177e4SLinus Torvalds }; 1051da177e4SLinus Torvalds 10621cb0bccSSteffen Maier /* holds various memory pools of an adapter */ 10721cb0bccSSteffen Maier struct zfcp_adapter_mempool { 10821cb0bccSSteffen Maier mempool_t *erp_req; 10921cb0bccSSteffen Maier mempool_t *gid_pn_req; 11021cb0bccSSteffen Maier mempool_t *scsi_req; 11121cb0bccSSteffen Maier mempool_t *scsi_abort; 11221cb0bccSSteffen Maier mempool_t *status_read_req; 11321cb0bccSSteffen Maier mempool_t *sr_data; 11421cb0bccSSteffen Maier mempool_t *gid_pn; 11521cb0bccSSteffen Maier mempool_t *qtcb_pool; 116c9615858SChristof Schmitt }; 1171da177e4SLinus Torvalds 1181da177e4SLinus Torvalds struct zfcp_adapter { 119f3450c7bSSwen Schillig struct kref ref; 1207ba58c9cSSwen Schillig u64 peer_wwnn; /* P2P peer WWNN */ 1217ba58c9cSSwen Schillig u64 peer_wwpn; /* P2P peer WWPN */ 12213e1e1f0SAndreas Herrmann u32 peer_d_id; /* P2P peer D_ID */ 1231da177e4SLinus Torvalds struct ccw_device *ccw_device; /* S/390 ccw device */ 124564e1c86SSwen Schillig struct zfcp_qdio *qdio; 1251da177e4SLinus Torvalds u32 hydra_version; /* Hydra version */ 1261da177e4SLinus Torvalds u32 fsf_lic_version; 127aef4a983SMaxim Shchetynin u32 adapter_features; /* FCP channel features */ 128aef4a983SMaxim Shchetynin u32 connection_features; /* host connection features */ 1291da177e4SLinus Torvalds u32 hardware_version; /* of FCP channel */ 130c9615858SChristof Schmitt u16 timer_ticks; /* time int for a tick */ 1311da177e4SLinus Torvalds struct Scsi_Host *scsi_host; /* Pointer to mid-layer */ 132ecf0c772SSwen Schillig struct list_head port_list; /* remote port list */ 133ecf0c772SSwen Schillig rwlock_t port_list_lock; /* port list lock */ 134fea9d6c7SVolker Sameske unsigned long req_no; /* unique FSF req number */ 135b6bd2fb9SChristof Schmitt struct zfcp_reqlist *req_list; 1361da177e4SLinus Torvalds u32 fsf_req_seq_no; /* FSF cmnd seq number */ 1371da177e4SLinus Torvalds rwlock_t abort_lock; /* Protects against SCSI 1381da177e4SLinus Torvalds stack abort/command 1391da177e4SLinus Torvalds completion races */ 140d26ab06eSSwen Schillig atomic_t stat_miss; /* # missing status reads*/ 14164deb6efSChristof Schmitt unsigned int stat_read_buf_num; 142d26ab06eSSwen Schillig struct work_struct stat_work; 1431da177e4SLinus Torvalds atomic_t status; /* status of this adapter */ 1441da177e4SLinus Torvalds struct list_head erp_ready_head; /* error recovery for this 1451da177e4SLinus Torvalds adapter/devices */ 146347c6a96SChristof Schmitt wait_queue_head_t erp_ready_wq; 1471da177e4SLinus Torvalds struct list_head erp_running_head; 1481da177e4SLinus Torvalds rwlock_t erp_lock; 1491da177e4SLinus Torvalds wait_queue_head_t erp_done_wqh; 1501da177e4SLinus Torvalds struct zfcp_erp_action erp_action; /* pending error recovery */ 1511da177e4SLinus Torvalds atomic_t erp_counter; 1521da177e4SLinus Torvalds u32 erp_total_count; /* total nr of enqueued erp 1531da177e4SLinus Torvalds actions */ 1541da177e4SLinus Torvalds u32 erp_low_mem_count; /* nr of erp actions waiting 1551da177e4SLinus Torvalds for memory */ 156347c6a96SChristof Schmitt struct task_struct *erp_thread; 157bd0072ecSChristof Schmitt struct zfcp_fc_wka_ports *gs; /* generic services */ 158d46f384aSChristof Schmitt struct zfcp_dbf *dbf; /* debug traces */ 1591da177e4SLinus Torvalds struct zfcp_adapter_mempool pool; /* Adapter memory pools */ 160f6cd94b1SAndreas Herrmann struct fc_host_statistics *fc_stats; 161f6cd94b1SAndreas Herrmann struct fsf_qtcb_bottom_port *stats_reset_data; 162f6cd94b1SAndreas Herrmann unsigned long stats_reset; 16318f87a67SMartin Peschke struct delayed_work scan_work; 164038d9446SChristof Schmitt struct work_struct ns_up_work; 165bd43a42bSChristof Schmitt struct service_level service_level; 1664544683aSSwen Schillig struct workqueue_struct *work_queue; 16768322984SChristof Schmitt struct device_dma_parameters dma_parms; 1682d1e547fSSven Schuetz struct zfcp_fc_events events; 16918f87a67SMartin Peschke unsigned long next_port_scan; 1701da177e4SLinus Torvalds }; 1711da177e4SLinus Torvalds 1721da177e4SLinus Torvalds struct zfcp_port { 173615f59e0SChristof Schmitt struct device dev; 1743859f6a2SAndreas Herrmann struct fc_rport *rport; /* rport of fc transport class */ 1751da177e4SLinus Torvalds struct list_head list; /* list of remote ports */ 1761da177e4SLinus Torvalds struct zfcp_adapter *adapter; /* adapter used to access port */ 177ecf0c772SSwen Schillig struct list_head unit_list; /* head of logical unit list */ 178ecf0c772SSwen Schillig rwlock_t unit_list_lock; /* unit list lock */ 179d99b601bSSteffen Maier atomic_t units; /* zfcp_unit count */ 1801da177e4SLinus Torvalds atomic_t status; /* status of this remote port */ 1817ba58c9cSSwen Schillig u64 wwnn; /* WWNN if known */ 1827ba58c9cSSwen Schillig u64 wwpn; /* WWPN */ 18313e1e1f0SAndreas Herrmann u32 d_id; /* D_ID */ 1841da177e4SLinus Torvalds u32 handle; /* handle assigned by FSF */ 1851da177e4SLinus Torvalds struct zfcp_erp_action erp_action; /* pending error recovery */ 1861da177e4SLinus Torvalds atomic_t erp_counter; 18775bfc283SRalph Wuerthner u32 maxframe_size; 18875bfc283SRalph Wuerthner u32 supported_classes; 1895ab944f9SSwen Schillig struct work_struct gid_pn_work; 1908fdf30d5SChristof Schmitt struct work_struct test_link_work; 191a2fa0aedSChristof Schmitt struct work_struct rport_work; 192a2fa0aedSChristof Schmitt enum { RPORT_NONE, RPORT_ADD, RPORT_DEL } rport_task; 1931bf3ff02SChristof Schmitt unsigned int starget_id; 1941da177e4SLinus Torvalds }; 1951da177e4SLinus Torvalds 19621cb0bccSSteffen Maier struct zfcp_latency_record { 19721cb0bccSSteffen Maier u32 min; 19821cb0bccSSteffen Maier u32 max; 19921cb0bccSSteffen Maier u64 sum; 20021cb0bccSSteffen Maier }; 20121cb0bccSSteffen Maier 20221cb0bccSSteffen Maier struct zfcp_latency_cont { 20321cb0bccSSteffen Maier struct zfcp_latency_record channel; 20421cb0bccSSteffen Maier struct zfcp_latency_record fabric; 20521cb0bccSSteffen Maier u64 counter; 20621cb0bccSSteffen Maier }; 20721cb0bccSSteffen Maier 20821cb0bccSSteffen Maier struct zfcp_latencies { 20921cb0bccSSteffen Maier struct zfcp_latency_cont read; 21021cb0bccSSteffen Maier struct zfcp_latency_cont write; 21121cb0bccSSteffen Maier struct zfcp_latency_cont cmd; 21221cb0bccSSteffen Maier spinlock_t lock; 21321cb0bccSSteffen Maier }; 21421cb0bccSSteffen Maier 215b62a8d9bSChristof Schmitt /** 216b62a8d9bSChristof Schmitt * struct zfcp_unit - LUN configured via zfcp sysfs 217b62a8d9bSChristof Schmitt * @dev: struct device for sysfs representation and reference counting 218b62a8d9bSChristof Schmitt * @list: entry in LUN/unit list per zfcp_port 219b62a8d9bSChristof Schmitt * @port: reference to zfcp_port where this LUN is configured 220b62a8d9bSChristof Schmitt * @fcp_lun: 64 bit LUN value 221b62a8d9bSChristof Schmitt * @scsi_work: for running scsi_scan_target 222b62a8d9bSChristof Schmitt * 223b62a8d9bSChristof Schmitt * This is the representation of a LUN that has been configured for 224b62a8d9bSChristof Schmitt * usage. The main data here is the 64 bit LUN value, data for 225b62a8d9bSChristof Schmitt * running I/O and recovery is in struct zfcp_scsi_dev. 226b62a8d9bSChristof Schmitt */ 2271da177e4SLinus Torvalds struct zfcp_unit { 228615f59e0SChristof Schmitt struct device dev; 229b62a8d9bSChristof Schmitt struct list_head list; 230b62a8d9bSChristof Schmitt struct zfcp_port *port; 231b62a8d9bSChristof Schmitt u64 fcp_lun; 23292d5193bSSwen Schillig struct work_struct scsi_work; 2331da177e4SLinus Torvalds }; 2341da177e4SLinus Torvalds 23542428f74SSwen Schillig /** 23657c23773SChristof Schmitt * struct zfcp_scsi_dev - zfcp data per SCSI device 23757c23773SChristof Schmitt * @status: zfcp internal status flags 23857c23773SChristof Schmitt * @lun_handle: handle from "open lun" for issuing FSF requests 23957c23773SChristof Schmitt * @erp_action: zfcp erp data for opening and recovering this LUN 24057c23773SChristof Schmitt * @erp_counter: zfcp erp counter for this LUN 24157c23773SChristof Schmitt * @latencies: FSF channel and fabric latencies 24257c23773SChristof Schmitt * @port: zfcp_port where this LUN belongs to 24357c23773SChristof Schmitt */ 24457c23773SChristof Schmitt struct zfcp_scsi_dev { 24557c23773SChristof Schmitt atomic_t status; 24657c23773SChristof Schmitt u32 lun_handle; 24757c23773SChristof Schmitt struct zfcp_erp_action erp_action; 24857c23773SChristof Schmitt atomic_t erp_counter; 24957c23773SChristof Schmitt struct zfcp_latencies latencies; 25057c23773SChristof Schmitt struct zfcp_port *port; 25157c23773SChristof Schmitt }; 25257c23773SChristof Schmitt 25357c23773SChristof Schmitt /** 25457c23773SChristof Schmitt * sdev_to_zfcp - Access zfcp LUN data for SCSI device 25557c23773SChristof Schmitt * @sdev: scsi_device where to get the zfcp_scsi_dev pointer 25657c23773SChristof Schmitt */ 25757c23773SChristof Schmitt static inline struct zfcp_scsi_dev *sdev_to_zfcp(struct scsi_device *sdev) 25857c23773SChristof Schmitt { 25957c23773SChristof Schmitt return scsi_transport_device_data(sdev); 26057c23773SChristof Schmitt } 26157c23773SChristof Schmitt 26257c23773SChristof Schmitt /** 26357c23773SChristof Schmitt * zfcp_scsi_dev_lun - Return SCSI device LUN as 64 bit FCP LUN 26457c23773SChristof Schmitt * @sdev: SCSI device where to get the LUN from 26557c23773SChristof Schmitt */ 26657c23773SChristof Schmitt static inline u64 zfcp_scsi_dev_lun(struct scsi_device *sdev) 26757c23773SChristof Schmitt { 26857c23773SChristof Schmitt u64 fcp_lun; 26957c23773SChristof Schmitt 27057c23773SChristof Schmitt int_to_scsilun(sdev->lun, (struct scsi_lun *)&fcp_lun); 27157c23773SChristof Schmitt return fcp_lun; 27257c23773SChristof Schmitt } 27357c23773SChristof Schmitt 27457c23773SChristof Schmitt /** 27542428f74SSwen Schillig * struct zfcp_fsf_req - basic FSF request structure 27642428f74SSwen Schillig * @list: list of FSF requests 27742428f74SSwen Schillig * @req_id: unique request ID 27842428f74SSwen Schillig * @adapter: adapter this request belongs to 27934c2b712SChristof Schmitt * @qdio_req: qdio queue related values 28042428f74SSwen Schillig * @completion: used to signal the completion of the request 28142428f74SSwen Schillig * @status: status of the request 28242428f74SSwen Schillig * @fsf_command: FSF command issued 28342428f74SSwen Schillig * @qtcb: associated QTCB 28442428f74SSwen Schillig * @seq_no: sequence number of this request 28542428f74SSwen Schillig * @data: private data 28642428f74SSwen Schillig * @timer: timer data of this request 28742428f74SSwen Schillig * @erp_action: reference to erp action if request issued on behalf of ERP 28842428f74SSwen Schillig * @pool: reference to memory pool if used for this request 28942428f74SSwen Schillig * @issued: time when request was send (STCK) 29042428f74SSwen Schillig * @handler: handler which should be called to process response 29142428f74SSwen Schillig */ 2921da177e4SLinus Torvalds struct zfcp_fsf_req { 29342428f74SSwen Schillig struct list_head list; 29442428f74SSwen Schillig unsigned long req_id; 29542428f74SSwen Schillig struct zfcp_adapter *adapter; 29634c2b712SChristof Schmitt struct zfcp_qdio_req qdio_req; 29742428f74SSwen Schillig struct completion completion; 29842428f74SSwen Schillig u32 status; 29942428f74SSwen Schillig u32 fsf_command; 30042428f74SSwen Schillig struct fsf_qtcb *qtcb; 30142428f74SSwen Schillig u32 seq_no; 30242428f74SSwen Schillig void *data; 30342428f74SSwen Schillig struct timer_list timer; 30442428f74SSwen Schillig struct zfcp_erp_action *erp_action; 30542428f74SSwen Schillig mempool_t *pool; 30642428f74SSwen Schillig unsigned long long issued; 307c41f8cbdSSwen Schillig void (*handler)(struct zfcp_fsf_req *); 3081da177e4SLinus Torvalds }; 3091da177e4SLinus Torvalds 31086a9668aSSwen Schillig static inline 31186a9668aSSwen Schillig int zfcp_adapter_multi_buffer_active(struct zfcp_adapter *adapter) 31286a9668aSSwen Schillig { 31386a9668aSSwen Schillig return atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_MB_ACT; 31486a9668aSSwen Schillig } 31586a9668aSSwen Schillig 3161da177e4SLinus Torvalds #endif /* ZFCP_DEF_H */ 317