zfcp_def.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. /*
  2. * zfcp device driver
  3. *
  4. * Global definitions for the zfcp device driver.
  5. *
  6. * Copyright IBM Corporation 2002, 2009
  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/qdio.h>
  34. #include <asm/debug.h>
  35. #include <asm/ebcdic.h>
  36. #include <asm/sysinfo.h>
  37. #include "zfcp_fsf.h"
  38. /********************* GENERAL DEFINES *********************************/
  39. #define REQUEST_LIST_SIZE 128
  40. /********************* SCSI SPECIFIC DEFINES *********************************/
  41. #define ZFCP_SCSI_ER_TIMEOUT (10*HZ)
  42. /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
  43. /* DMQ bug workaround: don't use last SBALE */
  44. #define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
  45. /* index of last SBALE (with respect to DMQ bug workaround) */
  46. #define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
  47. /* max. number of (data buffer) SBALEs in largest SBAL chain */
  48. #define ZFCP_MAX_SBALES_PER_REQ \
  49. (FSF_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
  50. /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
  51. #define ZFCP_MAX_SECTORS (ZFCP_MAX_SBALES_PER_REQ * 8)
  52. /* max. number of (data buffer) SBALEs in largest SBAL chain
  53. multiplied with number of sectors per 4k block */
  54. /********************* FSF SPECIFIC DEFINES *********************************/
  55. /* ATTENTION: value must not be used by hardware */
  56. #define FSF_QTCB_UNSOLICITED_STATUS 0x6305
  57. /* timeout value for "default timer" for fsf requests */
  58. #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
  59. /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
  60. #define ZFCP_DID_MASK 0x00FFFFFF
  61. /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
  62. /*
  63. * Note, the leftmost status byte is common among adapter, port
  64. * and unit
  65. */
  66. #define ZFCP_COMMON_FLAGS 0xfff00000
  67. /* common status bits */
  68. #define ZFCP_STATUS_COMMON_RUNNING 0x40000000
  69. #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
  70. #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
  71. #define ZFCP_STATUS_COMMON_OPEN 0x04000000
  72. #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
  73. #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
  74. #define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
  75. #define ZFCP_STATUS_COMMON_NOESC 0x00200000
  76. /* adapter status */
  77. #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
  78. #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
  79. #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
  80. #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
  81. #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
  82. /* remote port status */
  83. #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
  84. #define ZFCP_STATUS_PORT_LINK_TEST 0x00000002
  85. /* well known address (WKA) port status*/
  86. enum zfcp_wka_status {
  87. ZFCP_WKA_PORT_OFFLINE,
  88. ZFCP_WKA_PORT_CLOSING,
  89. ZFCP_WKA_PORT_OPENING,
  90. ZFCP_WKA_PORT_ONLINE,
  91. };
  92. /* logical unit status */
  93. #define ZFCP_STATUS_UNIT_SHARED 0x00000004
  94. #define ZFCP_STATUS_UNIT_READONLY 0x00000008
  95. /* FSF request status (this does not have a common part) */
  96. #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
  97. #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
  98. #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
  99. #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
  100. #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
  101. #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
  102. #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
  103. #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
  104. #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
  105. #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
  106. /************************* STRUCTURE DEFINITIONS *****************************/
  107. struct zfcp_fsf_req;
  108. /* holds various memory pools of an adapter */
  109. struct zfcp_adapter_mempool {
  110. mempool_t *erp_req;
  111. mempool_t *gid_pn_req;
  112. mempool_t *scsi_req;
  113. mempool_t *scsi_abort;
  114. mempool_t *status_read_req;
  115. mempool_t *status_read_data;
  116. mempool_t *gid_pn;
  117. mempool_t *qtcb_pool;
  118. };
  119. /**
  120. * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
  121. * @wka_port: port where the request is sent to
  122. * @req: scatter-gather list for request
  123. * @resp: scatter-gather list for response
  124. * @handler: handler function (called for response to the request)
  125. * @handler_data: data passed to handler function
  126. * @completion: completion for synchronization purposes
  127. * @status: used to pass error status to calling function
  128. */
  129. struct zfcp_send_ct {
  130. struct zfcp_wka_port *wka_port;
  131. struct scatterlist *req;
  132. struct scatterlist *resp;
  133. void (*handler)(unsigned long);
  134. unsigned long handler_data;
  135. struct completion *completion;
  136. int status;
  137. };
  138. /**
  139. * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
  140. * @adapter: adapter where request is sent from
  141. * @port: port where ELS is destinated (port reference count has to be increased)
  142. * @d_id: destiniation id of port where request is sent to
  143. * @req: scatter-gather list for request
  144. * @resp: scatter-gather list for response
  145. * @handler: handler function (called for response to the request)
  146. * @handler_data: data passed to handler function
  147. * @completion: completion for synchronization purposes
  148. * @ls_code: hex code of ELS command
  149. * @status: used to pass error status to calling function
  150. */
  151. struct zfcp_send_els {
  152. struct zfcp_adapter *adapter;
  153. struct zfcp_port *port;
  154. u32 d_id;
  155. struct scatterlist *req;
  156. struct scatterlist *resp;
  157. void (*handler)(unsigned long);
  158. unsigned long handler_data;
  159. struct completion *completion;
  160. int ls_code;
  161. int status;
  162. };
  163. struct zfcp_wka_port {
  164. struct zfcp_adapter *adapter;
  165. wait_queue_head_t completion_wq;
  166. enum zfcp_wka_status status;
  167. atomic_t refcount;
  168. u32 d_id;
  169. u32 handle;
  170. struct mutex mutex;
  171. struct delayed_work work;
  172. };
  173. struct zfcp_wka_ports {
  174. struct zfcp_wka_port ms; /* management service */
  175. struct zfcp_wka_port ts; /* time service */
  176. struct zfcp_wka_port ds; /* directory service */
  177. struct zfcp_wka_port as; /* alias service */
  178. struct zfcp_wka_port ks; /* key distribution service */
  179. };
  180. struct zfcp_qdio_queue {
  181. struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q];
  182. u8 first; /* index of next free bfr in queue */
  183. atomic_t count; /* number of free buffers in queue */
  184. };
  185. struct zfcp_erp_action {
  186. struct list_head list;
  187. int action; /* requested action code */
  188. struct zfcp_adapter *adapter; /* device which should be recovered */
  189. struct zfcp_port *port;
  190. struct zfcp_unit *unit;
  191. u32 status; /* recovery status */
  192. u32 step; /* active step of this erp action */
  193. struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
  194. for this action */
  195. struct timer_list timer;
  196. };
  197. struct fsf_latency_record {
  198. u32 min;
  199. u32 max;
  200. u64 sum;
  201. };
  202. struct latency_cont {
  203. struct fsf_latency_record channel;
  204. struct fsf_latency_record fabric;
  205. u64 counter;
  206. };
  207. struct zfcp_latencies {
  208. struct latency_cont read;
  209. struct latency_cont write;
  210. struct latency_cont cmd;
  211. spinlock_t lock;
  212. };
  213. /** struct zfcp_qdio - basic QDIO data structure
  214. * @resp_q: response queue
  215. * @req_q: request queue
  216. * @stat_lock: lock to protect req_q_util and req_q_time
  217. * @req_q_lock; lock to serialize access to request queue
  218. * @req_q_time: time of last fill level change
  219. * @req_q_util: used for accounting
  220. * @req_q_full: queue full incidents
  221. * @req_q_wq: used to wait for SBAL availability
  222. * @adapter: adapter used in conjunction with this QDIO structure
  223. */
  224. struct zfcp_qdio {
  225. struct zfcp_qdio_queue resp_q;
  226. struct zfcp_qdio_queue req_q;
  227. spinlock_t stat_lock;
  228. spinlock_t req_q_lock;
  229. unsigned long long req_q_time;
  230. u64 req_q_util;
  231. atomic_t req_q_full;
  232. wait_queue_head_t req_q_wq;
  233. struct zfcp_adapter *adapter;
  234. };
  235. struct zfcp_adapter {
  236. struct kref ref;
  237. u64 peer_wwnn; /* P2P peer WWNN */
  238. u64 peer_wwpn; /* P2P peer WWPN */
  239. u32 peer_d_id; /* P2P peer D_ID */
  240. struct ccw_device *ccw_device; /* S/390 ccw device */
  241. struct zfcp_qdio *qdio;
  242. u32 hydra_version; /* Hydra version */
  243. u32 fsf_lic_version;
  244. u32 adapter_features; /* FCP channel features */
  245. u32 connection_features; /* host connection features */
  246. u32 hardware_version; /* of FCP channel */
  247. u16 timer_ticks; /* time int for a tick */
  248. struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
  249. struct list_head port_list; /* remote port list */
  250. rwlock_t port_list_lock; /* port list lock */
  251. unsigned long req_no; /* unique FSF req number */
  252. struct list_head *req_list; /* list of pending reqs */
  253. spinlock_t req_list_lock; /* request list lock */
  254. u32 fsf_req_seq_no; /* FSF cmnd seq number */
  255. rwlock_t abort_lock; /* Protects against SCSI
  256. stack abort/command
  257. completion races */
  258. atomic_t stat_miss; /* # missing status reads*/
  259. struct work_struct stat_work;
  260. atomic_t status; /* status of this adapter */
  261. struct list_head erp_ready_head; /* error recovery for this
  262. adapter/devices */
  263. wait_queue_head_t erp_ready_wq;
  264. struct list_head erp_running_head;
  265. rwlock_t erp_lock;
  266. wait_queue_head_t erp_done_wqh;
  267. struct zfcp_erp_action erp_action; /* pending error recovery */
  268. atomic_t erp_counter;
  269. u32 erp_total_count; /* total nr of enqueued erp
  270. actions */
  271. u32 erp_low_mem_count; /* nr of erp actions waiting
  272. for memory */
  273. struct task_struct *erp_thread;
  274. struct zfcp_wka_ports *gs; /* generic services */
  275. struct zfcp_dbf *dbf; /* debug traces */
  276. struct zfcp_adapter_mempool pool; /* Adapter memory pools */
  277. struct fc_host_statistics *fc_stats;
  278. struct fsf_qtcb_bottom_port *stats_reset_data;
  279. unsigned long stats_reset;
  280. struct work_struct scan_work;
  281. struct service_level service_level;
  282. struct workqueue_struct *work_queue;
  283. };
  284. struct zfcp_port {
  285. struct device sysfs_device; /* sysfs device */
  286. struct fc_rport *rport; /* rport of fc transport class */
  287. struct list_head list; /* list of remote ports */
  288. struct zfcp_adapter *adapter; /* adapter used to access port */
  289. struct list_head unit_list; /* head of logical unit list */
  290. rwlock_t unit_list_lock; /* unit list lock */
  291. atomic_t status; /* status of this remote port */
  292. u64 wwnn; /* WWNN if known */
  293. u64 wwpn; /* WWPN */
  294. u32 d_id; /* D_ID */
  295. u32 handle; /* handle assigned by FSF */
  296. struct zfcp_erp_action erp_action; /* pending error recovery */
  297. atomic_t erp_counter;
  298. u32 maxframe_size;
  299. u32 supported_classes;
  300. struct work_struct gid_pn_work;
  301. struct work_struct test_link_work;
  302. struct work_struct rport_work;
  303. enum { RPORT_NONE, RPORT_ADD, RPORT_DEL } rport_task;
  304. };
  305. struct zfcp_unit {
  306. struct device sysfs_device; /* sysfs device */
  307. struct list_head list; /* list of logical units */
  308. struct zfcp_port *port; /* remote port of unit */
  309. atomic_t status; /* status of this logical unit */
  310. u64 fcp_lun; /* own FCP_LUN */
  311. u32 handle; /* handle assigned by FSF */
  312. struct scsi_device *device; /* scsi device struct pointer */
  313. struct zfcp_erp_action erp_action; /* pending error recovery */
  314. atomic_t erp_counter;
  315. struct zfcp_latencies latencies;
  316. struct work_struct scsi_work;
  317. };
  318. /**
  319. * struct zfcp_queue_req - queue related values for a request
  320. * @sbal_number: number of free SBALs
  321. * @sbal_first: first SBAL for this request
  322. * @sbal_last: last SBAL for this request
  323. * @sbal_limit: last possible SBAL for this request
  324. * @sbale_curr: current SBALE at creation of this request
  325. * @sbal_response: SBAL used in interrupt
  326. * @qdio_outb_usage: usage of outbound queue
  327. * @qdio_inb_usage: usage of inbound queue
  328. */
  329. struct zfcp_queue_req {
  330. u8 sbal_number;
  331. u8 sbal_first;
  332. u8 sbal_last;
  333. u8 sbal_limit;
  334. u8 sbale_curr;
  335. u8 sbal_response;
  336. u16 qdio_outb_usage;
  337. u16 qdio_inb_usage;
  338. };
  339. /**
  340. * struct zfcp_fsf_req - basic FSF request structure
  341. * @list: list of FSF requests
  342. * @req_id: unique request ID
  343. * @adapter: adapter this request belongs to
  344. * @queue_req: queue related values
  345. * @completion: used to signal the completion of the request
  346. * @status: status of the request
  347. * @fsf_command: FSF command issued
  348. * @qtcb: associated QTCB
  349. * @seq_no: sequence number of this request
  350. * @data: private data
  351. * @timer: timer data of this request
  352. * @erp_action: reference to erp action if request issued on behalf of ERP
  353. * @pool: reference to memory pool if used for this request
  354. * @issued: time when request was send (STCK)
  355. * @unit: reference to unit if this request is a SCSI request
  356. * @handler: handler which should be called to process response
  357. */
  358. struct zfcp_fsf_req {
  359. struct list_head list;
  360. unsigned long req_id;
  361. struct zfcp_adapter *adapter;
  362. struct zfcp_queue_req queue_req;
  363. struct completion completion;
  364. u32 status;
  365. u32 fsf_command;
  366. struct fsf_qtcb *qtcb;
  367. u32 seq_no;
  368. void *data;
  369. struct timer_list timer;
  370. struct zfcp_erp_action *erp_action;
  371. mempool_t *pool;
  372. unsigned long long issued;
  373. struct zfcp_unit *unit;
  374. void (*handler)(struct zfcp_fsf_req *);
  375. };
  376. /* driver data */
  377. struct zfcp_data {
  378. struct scsi_host_template scsi_host_template;
  379. struct scsi_transport_template *scsi_transport_template;
  380. struct kmem_cache *gpn_ft_cache;
  381. struct kmem_cache *qtcb_cache;
  382. struct kmem_cache *sr_buffer_cache;
  383. struct kmem_cache *gid_pn_cache;
  384. };
  385. /********************** ZFCP SPECIFIC DEFINES ********************************/
  386. #define ZFCP_SET 0x00000100
  387. #define ZFCP_CLEAR 0x00000200
  388. /*
  389. * Helper functions for request ID management.
  390. */
  391. static inline int zfcp_reqlist_hash(unsigned long req_id)
  392. {
  393. return req_id % REQUEST_LIST_SIZE;
  394. }
  395. static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
  396. struct zfcp_fsf_req *fsf_req)
  397. {
  398. list_del(&fsf_req->list);
  399. }
  400. static inline struct zfcp_fsf_req *
  401. zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
  402. {
  403. struct zfcp_fsf_req *request;
  404. unsigned int idx;
  405. idx = zfcp_reqlist_hash(req_id);
  406. list_for_each_entry(request, &adapter->req_list[idx], list)
  407. if (request->req_id == req_id)
  408. return request;
  409. return NULL;
  410. }
  411. static inline struct zfcp_fsf_req *
  412. zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
  413. {
  414. struct zfcp_fsf_req *request;
  415. unsigned int idx;
  416. for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
  417. list_for_each_entry(request, &adapter->req_list[idx], list)
  418. if (request == req)
  419. return request;
  420. }
  421. return NULL;
  422. }
  423. #endif /* ZFCP_DEF_H */