zfcp_def.h 10 KB

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