zfcp_def.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * zfcp device driver
  4. *
  5. * Global definitions for the zfcp device driver.
  6. *
  7. * Copyright IBM Corp. 2002, 2020
  8. */
  9. #ifndef ZFCP_DEF_H
  10. #define ZFCP_DEF_H
  11. /*************************** INCLUDES *****************************************/
  12. #include <linux/init.h>
  13. #include <linux/moduleparam.h>
  14. #include <linux/major.h>
  15. #include <linux/blkdev.h>
  16. #include <linux/delay.h>
  17. #include <linux/timer.h>
  18. #include <linux/slab.h>
  19. #include <linux/mempool.h>
  20. #include <linux/syscalls.h>
  21. #include <linux/scatterlist.h>
  22. #include <linux/ioctl.h>
  23. #include <scsi/fc/fc_fs.h>
  24. #include <scsi/fc/fc_gs.h>
  25. #include <scsi/scsi.h>
  26. #include <scsi/scsi_tcq.h>
  27. #include <scsi/scsi_cmnd.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport.h>
  31. #include <scsi/scsi_transport_fc.h>
  32. #include <scsi/scsi_bsg_fc.h>
  33. #include <asm/ccwdev.h>
  34. #include <asm/debug.h>
  35. #include <asm/ebcdic.h>
  36. #include <asm/sysinfo.h>
  37. #include "zfcp_fsf.h"
  38. #include "zfcp_fc.h"
  39. #include "zfcp_qdio.h"
  40. /********************* FSF SPECIFIC DEFINES *********************************/
  41. /* ATTENTION: value must not be used by hardware */
  42. #define FSF_QTCB_UNSOLICITED_STATUS 0x6305
  43. /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
  44. /*
  45. * Note, the leftmost 12 status bits (3 nibbles) are common among adapter, port
  46. * and unit. This is a mask for bitwise 'and' with status values.
  47. */
  48. #define ZFCP_COMMON_FLAGS 0xfff00000
  49. /* common status bits */
  50. #define ZFCP_STATUS_COMMON_RUNNING 0x40000000
  51. #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
  52. #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
  53. #define ZFCP_STATUS_COMMON_OPEN 0x04000000
  54. #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
  55. #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
  56. #define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
  57. #define ZFCP_STATUS_COMMON_NOESC 0x00200000
  58. /* adapter status */
  59. #define ZFCP_STATUS_ADAPTER_MB_ACT 0x00000001
  60. #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
  61. #define ZFCP_STATUS_ADAPTER_SIOSL_ISSUED 0x00000004
  62. #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
  63. #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
  64. #define ZFCP_STATUS_ADAPTER_SUSPENDED 0x00000040
  65. #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
  66. #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
  67. #define ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED 0x00000400
  68. /* remote port status */
  69. #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
  70. #define ZFCP_STATUS_PORT_LINK_TEST 0x00000002
  71. /* FSF request status (this does not have a common part) */
  72. #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
  73. #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
  74. #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
  75. #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
  76. #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
  77. #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
  78. #define ZFCP_STATUS_FSFREQ_XDATAINCOMPLETE 0x00020000
  79. /************************* STRUCTURE DEFINITIONS *****************************/
  80. /**
  81. * enum zfcp_erp_act_type - Type of ERP action object.
  82. * @ZFCP_ERP_ACTION_REOPEN_LUN: LUN recovery.
  83. * @ZFCP_ERP_ACTION_REOPEN_PORT: Port recovery.
  84. * @ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: Forced port recovery.
  85. * @ZFCP_ERP_ACTION_REOPEN_ADAPTER: Adapter recovery.
  86. *
  87. * Values must fit into u8 because of code dependencies:
  88. * zfcp_dbf_rec_trig(), &zfcp_dbf_rec_trigger.want, &zfcp_dbf_rec_trigger.need;
  89. * zfcp_dbf_rec_run_lvl(), zfcp_dbf_rec_run(), &zfcp_dbf_rec_running.rec_action.
  90. */
  91. enum zfcp_erp_act_type {
  92. ZFCP_ERP_ACTION_REOPEN_LUN = 1,
  93. ZFCP_ERP_ACTION_REOPEN_PORT = 2,
  94. ZFCP_ERP_ACTION_REOPEN_PORT_FORCED = 3,
  95. ZFCP_ERP_ACTION_REOPEN_ADAPTER = 4,
  96. };
  97. /*
  98. * Values must fit into u16 because of code dependencies:
  99. * zfcp_dbf_rec_run_lvl(), zfcp_dbf_rec_run(), zfcp_dbf_rec_run_wka(),
  100. * &zfcp_dbf_rec_running.rec_step.
  101. */
  102. enum zfcp_erp_steps {
  103. ZFCP_ERP_STEP_UNINITIALIZED = 0x0000,
  104. ZFCP_ERP_STEP_PHYS_PORT_CLOSING = 0x0010,
  105. ZFCP_ERP_STEP_PORT_CLOSING = 0x0100,
  106. ZFCP_ERP_STEP_PORT_OPENING = 0x0800,
  107. ZFCP_ERP_STEP_LUN_CLOSING = 0x1000,
  108. ZFCP_ERP_STEP_LUN_OPENING = 0x2000,
  109. };
  110. struct zfcp_erp_action {
  111. struct list_head list;
  112. enum zfcp_erp_act_type type; /* requested action code */
  113. struct zfcp_adapter *adapter; /* device which should be recovered */
  114. struct zfcp_port *port;
  115. struct scsi_device *sdev;
  116. u32 status; /* recovery status */
  117. enum zfcp_erp_steps step; /* active step of this erp action */
  118. unsigned long fsf_req_id;
  119. struct timer_list timer;
  120. };
  121. /* holds various memory pools of an adapter */
  122. struct zfcp_adapter_mempool {
  123. mempool_t *erp_req;
  124. mempool_t *gid_pn_req;
  125. mempool_t *scsi_req;
  126. mempool_t *scsi_abort;
  127. mempool_t *status_read_req;
  128. mempool_t *sr_data;
  129. mempool_t *gid_pn;
  130. mempool_t *qtcb_pool;
  131. };
  132. struct zfcp_adapter {
  133. struct kref ref;
  134. u64 peer_wwnn; /* P2P peer WWNN */
  135. u64 peer_wwpn; /* P2P peer WWPN */
  136. u32 peer_d_id; /* P2P peer D_ID */
  137. struct ccw_device *ccw_device; /* S/390 ccw device */
  138. struct zfcp_qdio *qdio;
  139. u32 hydra_version; /* Hydra version */
  140. u32 fsf_lic_version;
  141. u32 adapter_features; /* FCP channel features */
  142. u32 connection_features; /* host connection features */
  143. u32 hardware_version; /* of FCP channel */
  144. u32 fc_security_algorithms; /* of FCP channel */
  145. u32 fc_security_algorithms_old; /* of FCP channel */
  146. u16 timer_ticks; /* time int for a tick */
  147. struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
  148. struct list_head port_list; /* remote port list */
  149. rwlock_t port_list_lock; /* port list lock */
  150. unsigned long req_no; /* unique FSF req number */
  151. struct zfcp_reqlist *req_list;
  152. u32 fsf_req_seq_no; /* FSF cmnd seq number */
  153. rwlock_t abort_lock; /* Protects against SCSI
  154. stack abort/command
  155. completion races */
  156. atomic_t stat_miss; /* # missing status reads*/
  157. unsigned int stat_read_buf_num;
  158. struct work_struct stat_work;
  159. atomic_t status; /* status of this adapter */
  160. struct list_head erp_ready_head; /* error recovery for this
  161. adapter/devices */
  162. wait_queue_head_t erp_ready_wq;
  163. struct list_head erp_running_head;
  164. rwlock_t erp_lock;
  165. wait_queue_head_t erp_done_wqh;
  166. struct zfcp_erp_action erp_action; /* pending error recovery */
  167. atomic_t erp_counter;
  168. u32 erp_total_count; /* total nr of enqueued erp
  169. actions */
  170. u32 erp_low_mem_count; /* nr of erp actions waiting
  171. for memory */
  172. struct task_struct *erp_thread;
  173. struct zfcp_fc_wka_ports *gs; /* generic services */
  174. struct zfcp_dbf *dbf; /* debug traces */
  175. struct zfcp_adapter_mempool pool; /* Adapter memory pools */
  176. struct fc_host_statistics *fc_stats;
  177. struct fsf_qtcb_bottom_port *stats_reset_data;
  178. unsigned long stats_reset;
  179. struct delayed_work scan_work;
  180. struct work_struct ns_up_work;
  181. struct service_level service_level;
  182. struct workqueue_struct *work_queue;
  183. struct device_dma_parameters dma_parms;
  184. struct zfcp_fc_events events;
  185. unsigned long next_port_scan;
  186. struct zfcp_diag_adapter *diagnostics;
  187. };
  188. struct zfcp_port {
  189. struct device dev;
  190. struct fc_rport *rport; /* rport of fc transport class */
  191. struct list_head list; /* list of remote ports */
  192. struct zfcp_adapter *adapter; /* adapter used to access port */
  193. struct list_head unit_list; /* head of logical unit list */
  194. rwlock_t unit_list_lock; /* unit list lock */
  195. atomic_t units; /* zfcp_unit count */
  196. atomic_t status; /* status of this remote port */
  197. u64 wwnn; /* WWNN if known */
  198. u64 wwpn; /* WWPN */
  199. u32 d_id; /* D_ID */
  200. u32 handle; /* handle assigned by FSF */
  201. struct zfcp_erp_action erp_action; /* pending error recovery */
  202. atomic_t erp_counter;
  203. u32 maxframe_size;
  204. u32 supported_classes;
  205. u32 connection_info;
  206. u32 connection_info_old;
  207. struct work_struct gid_pn_work;
  208. struct work_struct test_link_work;
  209. struct work_struct rport_work;
  210. enum { RPORT_NONE, RPORT_ADD, RPORT_DEL } rport_task;
  211. unsigned int starget_id;
  212. };
  213. struct zfcp_latency_record {
  214. u32 min;
  215. u32 max;
  216. u64 sum;
  217. };
  218. struct zfcp_latency_cont {
  219. struct zfcp_latency_record channel;
  220. struct zfcp_latency_record fabric;
  221. u64 counter;
  222. };
  223. struct zfcp_latencies {
  224. struct zfcp_latency_cont read;
  225. struct zfcp_latency_cont write;
  226. struct zfcp_latency_cont cmd;
  227. spinlock_t lock;
  228. };
  229. /**
  230. * struct zfcp_unit - LUN configured via zfcp sysfs
  231. * @dev: struct device for sysfs representation and reference counting
  232. * @list: entry in LUN/unit list per zfcp_port
  233. * @port: reference to zfcp_port where this LUN is configured
  234. * @fcp_lun: 64 bit LUN value
  235. * @scsi_work: for running scsi_scan_target
  236. *
  237. * This is the representation of a LUN that has been configured for
  238. * usage. The main data here is the 64 bit LUN value, data for
  239. * running I/O and recovery is in struct zfcp_scsi_dev.
  240. */
  241. struct zfcp_unit {
  242. struct device dev;
  243. struct list_head list;
  244. struct zfcp_port *port;
  245. u64 fcp_lun;
  246. struct work_struct scsi_work;
  247. };
  248. /**
  249. * struct zfcp_scsi_dev - zfcp data per SCSI device
  250. * @status: zfcp internal status flags
  251. * @lun_handle: handle from "open lun" for issuing FSF requests
  252. * @erp_action: zfcp erp data for opening and recovering this LUN
  253. * @erp_counter: zfcp erp counter for this LUN
  254. * @latencies: FSF channel and fabric latencies
  255. * @port: zfcp_port where this LUN belongs to
  256. */
  257. struct zfcp_scsi_dev {
  258. atomic_t status;
  259. u32 lun_handle;
  260. struct zfcp_erp_action erp_action;
  261. atomic_t erp_counter;
  262. struct zfcp_latencies latencies;
  263. struct zfcp_port *port;
  264. };
  265. /**
  266. * sdev_to_zfcp - Access zfcp LUN data for SCSI device
  267. * @sdev: scsi_device where to get the zfcp_scsi_dev pointer
  268. */
  269. static inline struct zfcp_scsi_dev *sdev_to_zfcp(struct scsi_device *sdev)
  270. {
  271. return scsi_transport_device_data(sdev);
  272. }
  273. /**
  274. * zfcp_scsi_dev_lun - Return SCSI device LUN as 64 bit FCP LUN
  275. * @sdev: SCSI device where to get the LUN from
  276. */
  277. static inline u64 zfcp_scsi_dev_lun(struct scsi_device *sdev)
  278. {
  279. u64 fcp_lun;
  280. int_to_scsilun(sdev->lun, (struct scsi_lun *)&fcp_lun);
  281. return fcp_lun;
  282. }
  283. /**
  284. * struct zfcp_fsf_req - basic FSF request structure
  285. * @list: list of FSF requests
  286. * @req_id: unique request ID
  287. * @adapter: adapter this request belongs to
  288. * @qdio_req: qdio queue related values
  289. * @completion: used to signal the completion of the request
  290. * @status: status of the request
  291. * @qtcb: associated QTCB
  292. * @data: private data
  293. * @timer: timer data of this request
  294. * @erp_action: reference to erp action if request issued on behalf of ERP
  295. * @pool: reference to memory pool if used for this request
  296. * @issued: time when request was send (STCK)
  297. * @handler: handler which should be called to process response
  298. */
  299. struct zfcp_fsf_req {
  300. struct list_head list;
  301. unsigned long req_id;
  302. struct zfcp_adapter *adapter;
  303. struct zfcp_qdio_req qdio_req;
  304. struct completion completion;
  305. u32 status;
  306. struct fsf_qtcb *qtcb;
  307. void *data;
  308. struct timer_list timer;
  309. struct zfcp_erp_action *erp_action;
  310. mempool_t *pool;
  311. unsigned long long issued;
  312. void (*handler)(struct zfcp_fsf_req *);
  313. };
  314. static inline
  315. int zfcp_adapter_multi_buffer_active(struct zfcp_adapter *adapter)
  316. {
  317. return atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_MB_ACT;
  318. }
  319. static inline bool zfcp_fsf_req_is_status_read_buffer(struct zfcp_fsf_req *req)
  320. {
  321. return req->qtcb == NULL;
  322. }
  323. #endif /* ZFCP_DEF_H */