zfcp_def.h 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  1. /*
  2. * This file is part of the zfcp device driver for
  3. * FCP adapters for IBM System z9 and zSeries.
  4. *
  5. * (C) Copyright IBM Corp. 2002, 2006
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #ifndef ZFCP_DEF_H
  22. #define ZFCP_DEF_H
  23. /*************************** INCLUDES *****************************************/
  24. #include <linux/init.h>
  25. #include <linux/moduleparam.h>
  26. #include <linux/major.h>
  27. #include <linux/blkdev.h>
  28. #include <linux/delay.h>
  29. #include <linux/timer.h>
  30. #include <linux/slab.h>
  31. #include <linux/mempool.h>
  32. #include <linux/syscalls.h>
  33. #include <linux/scatterlist.h>
  34. #include <linux/ioctl.h>
  35. #include <scsi/scsi.h>
  36. #include <scsi/scsi_tcq.h>
  37. #include <scsi/scsi_cmnd.h>
  38. #include <scsi/scsi_device.h>
  39. #include <scsi/scsi_host.h>
  40. #include <scsi/scsi_transport.h>
  41. #include <scsi/scsi_transport_fc.h>
  42. #include <asm/ccwdev.h>
  43. #include <asm/qdio.h>
  44. #include <asm/debug.h>
  45. #include <asm/ebcdic.h>
  46. #include "zfcp_dbf.h"
  47. #include "zfcp_fsf.h"
  48. /********************* GENERAL DEFINES *********************************/
  49. /* zfcp version number, it consists of major, minor, and patch-level number */
  50. #define ZFCP_VERSION "4.8.0"
  51. /**
  52. * zfcp_sg_to_address - determine kernel address from struct scatterlist
  53. * @list: struct scatterlist
  54. * Return: kernel address
  55. */
  56. static inline void *
  57. zfcp_sg_to_address(struct scatterlist *list)
  58. {
  59. return sg_virt(list);
  60. }
  61. /**
  62. * zfcp_address_to_sg - set up struct scatterlist from kernel address
  63. * @address: kernel address
  64. * @list: struct scatterlist
  65. * @size: buffer size
  66. */
  67. static inline void
  68. zfcp_address_to_sg(void *address, struct scatterlist *list, unsigned int size)
  69. {
  70. sg_set_buf(list, address, size);
  71. }
  72. #define REQUEST_LIST_SIZE 128
  73. /********************* SCSI SPECIFIC DEFINES *********************************/
  74. #define ZFCP_SCSI_ER_TIMEOUT (10*HZ)
  75. /********************* CIO/QDIO SPECIFIC DEFINES *****************************/
  76. /* Adapter Identification Parameters */
  77. #define ZFCP_CONTROL_UNIT_TYPE 0x1731
  78. #define ZFCP_CONTROL_UNIT_MODEL 0x03
  79. #define ZFCP_DEVICE_TYPE 0x1732
  80. #define ZFCP_DEVICE_MODEL 0x03
  81. #define ZFCP_DEVICE_MODEL_PRIV 0x04
  82. /* allow as many chained SBALs as are supported by hardware */
  83. #define ZFCP_MAX_SBALS_PER_REQ FSF_MAX_SBALS_PER_REQ
  84. #define ZFCP_MAX_SBALS_PER_CT_REQ FSF_MAX_SBALS_PER_REQ
  85. #define ZFCP_MAX_SBALS_PER_ELS_REQ FSF_MAX_SBALS_PER_ELS_REQ
  86. /* DMQ bug workaround: don't use last SBALE */
  87. #define ZFCP_MAX_SBALES_PER_SBAL (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)
  88. /* index of last SBALE (with respect to DMQ bug workaround) */
  89. #define ZFCP_LAST_SBALE_PER_SBAL (ZFCP_MAX_SBALES_PER_SBAL - 1)
  90. /* max. number of (data buffer) SBALEs in largest SBAL chain */
  91. #define ZFCP_MAX_SBALES_PER_REQ \
  92. (ZFCP_MAX_SBALS_PER_REQ * ZFCP_MAX_SBALES_PER_SBAL - 2)
  93. /* request ID + QTCB in SBALE 0 + 1 of first SBAL in chain */
  94. #define ZFCP_MAX_SECTORS (ZFCP_MAX_SBALES_PER_REQ * 8)
  95. /* max. number of (data buffer) SBALEs in largest SBAL chain
  96. multiplied with number of sectors per 4k block */
  97. /* FIXME(tune): free space should be one max. SBAL chain plus what? */
  98. #define ZFCP_QDIO_PCI_INTERVAL (QDIO_MAX_BUFFERS_PER_Q \
  99. - (ZFCP_MAX_SBALS_PER_REQ + 4))
  100. #define ZFCP_SBAL_TIMEOUT (5*HZ)
  101. #define ZFCP_TYPE2_RECOVERY_TIME 8 /* seconds */
  102. /* queue polling (values in microseconds) */
  103. #define ZFCP_MAX_INPUT_THRESHOLD 5000 /* FIXME: tune */
  104. #define ZFCP_MAX_OUTPUT_THRESHOLD 1000 /* FIXME: tune */
  105. #define ZFCP_MIN_INPUT_THRESHOLD 1 /* ignored by QDIO layer */
  106. #define ZFCP_MIN_OUTPUT_THRESHOLD 1 /* ignored by QDIO layer */
  107. #define QDIO_SCSI_QFMT 1 /* 1 for FSF */
  108. #define QBUFF_PER_PAGE (PAGE_SIZE / sizeof(struct qdio_buffer))
  109. /********************* FSF SPECIFIC DEFINES *********************************/
  110. #define ZFCP_ULP_INFO_VERSION 26
  111. #define ZFCP_QTCB_VERSION FSF_QTCB_CURRENT_VERSION
  112. /* ATTENTION: value must not be used by hardware */
  113. #define FSF_QTCB_UNSOLICITED_STATUS 0x6305
  114. #define ZFCP_STATUS_READS_RECOM FSF_STATUS_READS_RECOM
  115. /* Do 1st retry in 1 second, then double the timeout for each following retry */
  116. #define ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP 1
  117. #define ZFCP_EXCHANGE_CONFIG_DATA_RETRIES 7
  118. /* timeout value for "default timer" for fsf requests */
  119. #define ZFCP_FSF_REQUEST_TIMEOUT (60*HZ)
  120. /*************** FIBRE CHANNEL PROTOCOL SPECIFIC DEFINES ********************/
  121. typedef unsigned long long wwn_t;
  122. typedef unsigned long long fcp_lun_t;
  123. /* data length field may be at variable position in FCP-2 FCP_CMND IU */
  124. typedef unsigned int fcp_dl_t;
  125. #define ZFCP_FC_SERVICE_CLASS_DEFAULT FSF_CLASS_3
  126. /* timeout for name-server lookup (in seconds) */
  127. #define ZFCP_NS_GID_PN_TIMEOUT 10
  128. /* largest SCSI command we can process */
  129. /* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */
  130. #define ZFCP_MAX_SCSI_CMND_LENGTH 255
  131. /* maximum number of commands in LUN queue (tagged queueing) */
  132. #define ZFCP_CMND_PER_LUN 32
  133. /* task attribute values in FCP-2 FCP_CMND IU */
  134. #define SIMPLE_Q 0
  135. #define HEAD_OF_Q 1
  136. #define ORDERED_Q 2
  137. #define ACA_Q 4
  138. #define UNTAGGED 5
  139. /* task management flags in FCP-2 FCP_CMND IU */
  140. #define FCP_CLEAR_ACA 0x40
  141. #define FCP_TARGET_RESET 0x20
  142. #define FCP_LOGICAL_UNIT_RESET 0x10
  143. #define FCP_CLEAR_TASK_SET 0x04
  144. #define FCP_ABORT_TASK_SET 0x02
  145. #define FCP_CDB_LENGTH 16
  146. #define ZFCP_DID_MASK 0x00FFFFFF
  147. /* FCP(-2) FCP_CMND IU */
  148. struct fcp_cmnd_iu {
  149. fcp_lun_t fcp_lun; /* FCP logical unit number */
  150. u8 crn; /* command reference number */
  151. u8 reserved0:5; /* reserved */
  152. u8 task_attribute:3; /* task attribute */
  153. u8 task_management_flags; /* task management flags */
  154. u8 add_fcp_cdb_length:6; /* additional FCP_CDB length */
  155. u8 rddata:1; /* read data */
  156. u8 wddata:1; /* write data */
  157. u8 fcp_cdb[FCP_CDB_LENGTH];
  158. } __attribute__((packed));
  159. /* FCP(-2) FCP_RSP IU */
  160. struct fcp_rsp_iu {
  161. u8 reserved0[10];
  162. union {
  163. struct {
  164. u8 reserved1:3;
  165. u8 fcp_conf_req:1;
  166. u8 fcp_resid_under:1;
  167. u8 fcp_resid_over:1;
  168. u8 fcp_sns_len_valid:1;
  169. u8 fcp_rsp_len_valid:1;
  170. } bits;
  171. u8 value;
  172. } validity;
  173. u8 scsi_status;
  174. u32 fcp_resid;
  175. u32 fcp_sns_len;
  176. u32 fcp_rsp_len;
  177. } __attribute__((packed));
  178. #define RSP_CODE_GOOD 0
  179. #define RSP_CODE_LENGTH_MISMATCH 1
  180. #define RSP_CODE_FIELD_INVALID 2
  181. #define RSP_CODE_RO_MISMATCH 3
  182. #define RSP_CODE_TASKMAN_UNSUPP 4
  183. #define RSP_CODE_TASKMAN_FAILED 5
  184. /* see fc-fs */
  185. #define LS_RSCN 0x61
  186. #define LS_LOGO 0x05
  187. #define LS_PLOGI 0x03
  188. struct fcp_rscn_head {
  189. u8 command;
  190. u8 page_length; /* always 0x04 */
  191. u16 payload_len;
  192. } __attribute__((packed));
  193. struct fcp_rscn_element {
  194. u8 reserved:2;
  195. u8 event_qual:4;
  196. u8 addr_format:2;
  197. u32 nport_did:24;
  198. } __attribute__((packed));
  199. #define ZFCP_PORT_ADDRESS 0x0
  200. #define ZFCP_AREA_ADDRESS 0x1
  201. #define ZFCP_DOMAIN_ADDRESS 0x2
  202. #define ZFCP_FABRIC_ADDRESS 0x3
  203. #define ZFCP_PORTS_RANGE_PORT 0xFFFFFF
  204. #define ZFCP_PORTS_RANGE_AREA 0xFFFF00
  205. #define ZFCP_PORTS_RANGE_DOMAIN 0xFF0000
  206. #define ZFCP_PORTS_RANGE_FABRIC 0x000000
  207. #define ZFCP_NO_PORTS_PER_AREA 0x100
  208. #define ZFCP_NO_PORTS_PER_DOMAIN 0x10000
  209. #define ZFCP_NO_PORTS_PER_FABRIC 0x1000000
  210. /* see fc-ph */
  211. struct fcp_logo {
  212. u32 command;
  213. u32 nport_did;
  214. wwn_t nport_wwpn;
  215. } __attribute__((packed));
  216. /*
  217. * FC-FS stuff
  218. */
  219. #define R_A_TOV 10 /* seconds */
  220. #define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
  221. #define ZFCP_LS_RLS 0x0f
  222. #define ZFCP_LS_ADISC 0x52
  223. #define ZFCP_LS_RPS 0x56
  224. #define ZFCP_LS_RSCN 0x61
  225. #define ZFCP_LS_RNID 0x78
  226. struct zfcp_ls_rjt_par {
  227. u8 action;
  228. u8 reason_code;
  229. u8 reason_expl;
  230. u8 vendor_unique;
  231. } __attribute__ ((packed));
  232. struct zfcp_ls_adisc {
  233. u8 code;
  234. u8 field[3];
  235. u32 hard_nport_id;
  236. u64 wwpn;
  237. u64 wwnn;
  238. u32 nport_id;
  239. } __attribute__ ((packed));
  240. struct zfcp_ls_adisc_acc {
  241. u8 code;
  242. u8 field[3];
  243. u32 hard_nport_id;
  244. u64 wwpn;
  245. u64 wwnn;
  246. u32 nport_id;
  247. } __attribute__ ((packed));
  248. struct zfcp_rc_entry {
  249. u8 code;
  250. const char *description;
  251. };
  252. /*
  253. * FC-GS-2 stuff
  254. */
  255. #define ZFCP_CT_REVISION 0x01
  256. #define ZFCP_CT_DIRECTORY_SERVICE 0xFC
  257. #define ZFCP_CT_NAME_SERVER 0x02
  258. #define ZFCP_CT_SYNCHRONOUS 0x00
  259. #define ZFCP_CT_GID_PN 0x0121
  260. #define ZFCP_CT_MAX_SIZE 0x1020
  261. #define ZFCP_CT_ACCEPT 0x8002
  262. #define ZFCP_CT_REJECT 0x8001
  263. /*
  264. * FC-GS-4 stuff
  265. */
  266. #define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
  267. /******************** LOGGING MACROS AND DEFINES *****************************/
  268. /*
  269. * Logging may be applied on certain kinds of driver operations
  270. * independently. Additionally, different log-levels are supported for
  271. * each of these areas.
  272. */
  273. #define ZFCP_NAME "zfcp"
  274. /* independent log areas */
  275. #define ZFCP_LOG_AREA_OTHER 0
  276. #define ZFCP_LOG_AREA_SCSI 1
  277. #define ZFCP_LOG_AREA_FSF 2
  278. #define ZFCP_LOG_AREA_CONFIG 3
  279. #define ZFCP_LOG_AREA_CIO 4
  280. #define ZFCP_LOG_AREA_QDIO 5
  281. #define ZFCP_LOG_AREA_ERP 6
  282. #define ZFCP_LOG_AREA_FC 7
  283. /* log level values*/
  284. #define ZFCP_LOG_LEVEL_NORMAL 0
  285. #define ZFCP_LOG_LEVEL_INFO 1
  286. #define ZFCP_LOG_LEVEL_DEBUG 2
  287. #define ZFCP_LOG_LEVEL_TRACE 3
  288. /*
  289. * this allows removal of logging code by the preprocessor
  290. * (the most detailed log level still to be compiled in is specified,
  291. * higher log levels are removed)
  292. */
  293. #define ZFCP_LOG_LEVEL_LIMIT ZFCP_LOG_LEVEL_TRACE
  294. /* get "loglevel" nibble assignment */
  295. #define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \
  296. ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF)
  297. /* set "loglevel" nibble */
  298. #define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \
  299. (value << (zfcp_lognibble << 2))
  300. /* all log-level defaults are combined to generate initial log-level */
  301. #define ZFCP_LOG_LEVEL_DEFAULTS \
  302. (ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_OTHER) | \
  303. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_SCSI) | \
  304. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FSF) | \
  305. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CONFIG) | \
  306. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CIO) | \
  307. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_QDIO) | \
  308. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_ERP) | \
  309. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FC))
  310. /* check whether we have the right level for logging */
  311. #define ZFCP_LOG_CHECK(level) \
  312. ((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level)
  313. /* logging routine for zfcp */
  314. #define _ZFCP_LOG(fmt, args...) \
  315. printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __func__, \
  316. __LINE__ , ##args)
  317. #define ZFCP_LOG(level, fmt, args...) \
  318. do { \
  319. if (ZFCP_LOG_CHECK(level)) \
  320. _ZFCP_LOG(fmt, ##args); \
  321. } while (0)
  322. #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL
  323. # define ZFCP_LOG_NORMAL(fmt, args...) do { } while (0)
  324. #else
  325. # define ZFCP_LOG_NORMAL(fmt, args...) \
  326. do { \
  327. if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \
  328. printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
  329. } while (0)
  330. #endif
  331. #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO
  332. # define ZFCP_LOG_INFO(fmt, args...) do { } while (0)
  333. #else
  334. # define ZFCP_LOG_INFO(fmt, args...) \
  335. do { \
  336. if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \
  337. printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
  338. } while (0)
  339. #endif
  340. #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG
  341. # define ZFCP_LOG_DEBUG(fmt, args...) do { } while (0)
  342. #else
  343. # define ZFCP_LOG_DEBUG(fmt, args...) \
  344. ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args)
  345. #endif
  346. #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE
  347. # define ZFCP_LOG_TRACE(fmt, args...) do { } while (0)
  348. #else
  349. # define ZFCP_LOG_TRACE(fmt, args...) \
  350. ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args)
  351. #endif
  352. /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
  353. /*
  354. * Note, the leftmost status byte is common among adapter, port
  355. * and unit
  356. */
  357. #define ZFCP_COMMON_FLAGS 0xfff00000
  358. /* common status bits */
  359. #define ZFCP_STATUS_COMMON_REMOVE 0x80000000
  360. #define ZFCP_STATUS_COMMON_RUNNING 0x40000000
  361. #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
  362. #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
  363. #define ZFCP_STATUS_COMMON_OPENING 0x08000000
  364. #define ZFCP_STATUS_COMMON_OPEN 0x04000000
  365. #define ZFCP_STATUS_COMMON_CLOSING 0x02000000
  366. #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
  367. #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
  368. #define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
  369. /* adapter status */
  370. #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
  371. #define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
  372. #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
  373. #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
  374. #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
  375. #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
  376. #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
  377. #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
  378. #define ZFCP_STATUS_ADAPTER_XPORT_OK 0x00000800
  379. /* FC-PH/FC-GS well-known address identifiers for generic services */
  380. #define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
  381. #define ZFCP_DID_TIME_SERVICE 0xFFFFFB
  382. #define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
  383. #define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
  384. #define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
  385. /* remote port status */
  386. #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
  387. #define ZFCP_STATUS_PORT_DID_DID 0x00000002
  388. #define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
  389. #define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
  390. #define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
  391. #define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
  392. /* for ports with well known addresses */
  393. #define ZFCP_STATUS_PORT_WKA \
  394. (ZFCP_STATUS_PORT_NO_WWPN | \
  395. ZFCP_STATUS_PORT_NO_SCSI_ID)
  396. /* logical unit status */
  397. #define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
  398. #define ZFCP_STATUS_UNIT_SHARED 0x00000004
  399. #define ZFCP_STATUS_UNIT_READONLY 0x00000008
  400. #define ZFCP_STATUS_UNIT_REGISTERED 0x00000010
  401. #define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING 0x00000020
  402. /* FSF request status (this does not have a common part) */
  403. #define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
  404. #define ZFCP_STATUS_FSFREQ_POOL 0x00000001
  405. #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
  406. #define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
  407. #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
  408. #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
  409. #define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
  410. #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
  411. #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
  412. #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
  413. #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
  414. #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
  415. #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
  416. #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
  417. /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
  418. #define ZFCP_MAX_ERPS 3
  419. #define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
  420. #define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
  421. #define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
  422. #define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
  423. #define ZFCP_STATUS_ERP_DISMISSING 0x00100000
  424. #define ZFCP_STATUS_ERP_DISMISSED 0x00200000
  425. #define ZFCP_STATUS_ERP_LOWMEM 0x00400000
  426. #define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
  427. #define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
  428. #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
  429. #define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
  430. #define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
  431. #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
  432. #define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
  433. #define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
  434. #define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
  435. /* Ordered by escalation level (necessary for proper erp-code operation) */
  436. #define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
  437. #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
  438. #define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
  439. #define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
  440. #define ZFCP_ERP_ACTION_RUNNING 0x1
  441. #define ZFCP_ERP_ACTION_READY 0x2
  442. #define ZFCP_ERP_SUCCEEDED 0x0
  443. #define ZFCP_ERP_FAILED 0x1
  444. #define ZFCP_ERP_CONTINUES 0x2
  445. #define ZFCP_ERP_EXIT 0x3
  446. #define ZFCP_ERP_DISMISSED 0x4
  447. #define ZFCP_ERP_NOMEM 0x5
  448. /************************* STRUCTURE DEFINITIONS *****************************/
  449. struct zfcp_fsf_req;
  450. /* holds various memory pools of an adapter */
  451. struct zfcp_adapter_mempool {
  452. mempool_t *fsf_req_erp;
  453. mempool_t *fsf_req_scsi;
  454. mempool_t *fsf_req_abort;
  455. mempool_t *fsf_req_status_read;
  456. mempool_t *data_status_read;
  457. mempool_t *data_gid_pn;
  458. };
  459. /*
  460. * header for CT_IU
  461. */
  462. struct ct_hdr {
  463. u8 revision; // 0x01
  464. u8 in_id[3]; // 0x00
  465. u8 gs_type; // 0xFC Directory Service
  466. u8 gs_subtype; // 0x02 Name Server
  467. u8 options; // 0x00 single bidirectional exchange
  468. u8 reserved0;
  469. u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
  470. u16 max_res_size; // <= (4096 - 16) / 4
  471. u8 reserved1;
  472. u8 reason_code;
  473. u8 reason_code_expl;
  474. u8 vendor_unique;
  475. } __attribute__ ((packed));
  476. /* nameserver request CT_IU -- for requests where
  477. * a port name is required */
  478. struct ct_iu_gid_pn_req {
  479. struct ct_hdr header;
  480. wwn_t wwpn;
  481. } __attribute__ ((packed));
  482. /* FS_ACC IU and data unit for GID_PN nameserver request */
  483. struct ct_iu_gid_pn_resp {
  484. struct ct_hdr header;
  485. u32 d_id;
  486. } __attribute__ ((packed));
  487. typedef void (*zfcp_send_ct_handler_t)(unsigned long);
  488. /**
  489. * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
  490. * @port: port where the request is sent to
  491. * @req: scatter-gather list for request
  492. * @resp: scatter-gather list for response
  493. * @req_count: number of elements in request scatter-gather list
  494. * @resp_count: number of elements in response scatter-gather list
  495. * @handler: handler function (called for response to the request)
  496. * @handler_data: data passed to handler function
  497. * @timeout: FSF timeout for this request
  498. * @completion: completion for synchronization purposes
  499. * @status: used to pass error status to calling function
  500. */
  501. struct zfcp_send_ct {
  502. struct zfcp_port *port;
  503. struct scatterlist *req;
  504. struct scatterlist *resp;
  505. unsigned int req_count;
  506. unsigned int resp_count;
  507. zfcp_send_ct_handler_t handler;
  508. unsigned long handler_data;
  509. int timeout;
  510. struct completion *completion;
  511. int status;
  512. };
  513. /* used for name server requests in error recovery */
  514. struct zfcp_gid_pn_data {
  515. struct zfcp_send_ct ct;
  516. struct scatterlist req;
  517. struct scatterlist resp;
  518. struct ct_iu_gid_pn_req ct_iu_req;
  519. struct ct_iu_gid_pn_resp ct_iu_resp;
  520. struct zfcp_port *port;
  521. };
  522. typedef void (*zfcp_send_els_handler_t)(unsigned long);
  523. /**
  524. * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
  525. * @adapter: adapter where request is sent from
  526. * @port: port where ELS is destinated (port reference count has to be increased)
  527. * @d_id: destiniation id of port where request is sent to
  528. * @req: scatter-gather list for request
  529. * @resp: scatter-gather list for response
  530. * @req_count: number of elements in request scatter-gather list
  531. * @resp_count: number of elements in response scatter-gather list
  532. * @handler: handler function (called for response to the request)
  533. * @handler_data: data passed to handler function
  534. * @completion: completion for synchronization purposes
  535. * @ls_code: hex code of ELS command
  536. * @status: used to pass error status to calling function
  537. */
  538. struct zfcp_send_els {
  539. struct zfcp_adapter *adapter;
  540. struct zfcp_port *port;
  541. u32 d_id;
  542. struct scatterlist *req;
  543. struct scatterlist *resp;
  544. unsigned int req_count;
  545. unsigned int resp_count;
  546. zfcp_send_els_handler_t handler;
  547. unsigned long handler_data;
  548. struct completion *completion;
  549. int ls_code;
  550. int status;
  551. };
  552. struct zfcp_qdio_queue {
  553. struct qdio_buffer *buffer[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
  554. u8 free_index; /* index of next free bfr
  555. in queue (free_count>0) */
  556. atomic_t free_count; /* number of free buffers
  557. in queue */
  558. rwlock_t queue_lock; /* lock for operations on queue */
  559. int distance_from_int; /* SBALs used since PCI indication
  560. was last set */
  561. };
  562. struct zfcp_erp_action {
  563. struct list_head list;
  564. int action; /* requested action code */
  565. struct zfcp_adapter *adapter; /* device which should be recovered */
  566. struct zfcp_port *port;
  567. struct zfcp_unit *unit;
  568. volatile u32 status; /* recovery status */
  569. u32 step; /* active step of this erp action */
  570. struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
  571. for this action */
  572. struct timer_list timer;
  573. };
  574. struct fsf_latency_record {
  575. u32 min;
  576. u32 max;
  577. u64 sum;
  578. };
  579. struct latency_cont {
  580. struct fsf_latency_record channel;
  581. struct fsf_latency_record fabric;
  582. u64 counter;
  583. };
  584. struct zfcp_latencies {
  585. struct latency_cont read;
  586. struct latency_cont write;
  587. struct latency_cont cmd;
  588. spinlock_t lock;
  589. };
  590. struct zfcp_adapter {
  591. struct list_head list; /* list of adapters */
  592. atomic_t refcount; /* reference count */
  593. wait_queue_head_t remove_wq; /* can be used to wait for
  594. refcount drop to zero */
  595. wwn_t peer_wwnn; /* P2P peer WWNN */
  596. wwn_t peer_wwpn; /* P2P peer WWPN */
  597. u32 peer_d_id; /* P2P peer D_ID */
  598. struct ccw_device *ccw_device; /* S/390 ccw device */
  599. u32 hydra_version; /* Hydra version */
  600. u32 fsf_lic_version;
  601. u32 adapter_features; /* FCP channel features */
  602. u32 connection_features; /* host connection features */
  603. u32 hardware_version; /* of FCP channel */
  604. u16 timer_ticks; /* time int for a tick */
  605. struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
  606. struct list_head port_list_head; /* remote port list */
  607. struct list_head port_remove_lh; /* head of ports to be
  608. removed */
  609. u32 ports; /* number of remote ports */
  610. atomic_t reqs_active; /* # active FSF reqs */
  611. unsigned long req_no; /* unique FSF req number */
  612. struct list_head *req_list; /* list of pending reqs */
  613. spinlock_t req_list_lock; /* request list lock */
  614. struct zfcp_qdio_queue request_queue; /* request queue */
  615. u32 fsf_req_seq_no; /* FSF cmnd seq number */
  616. wait_queue_head_t request_wq; /* can be used to wait for
  617. more avaliable SBALs */
  618. struct zfcp_qdio_queue response_queue; /* response queue */
  619. rwlock_t abort_lock; /* Protects against SCSI
  620. stack abort/command
  621. completion races */
  622. atomic_t stat_miss; /* # missing status reads*/
  623. struct work_struct stat_work;
  624. atomic_t status; /* status of this adapter */
  625. struct list_head erp_ready_head; /* error recovery for this
  626. adapter/devices */
  627. struct list_head erp_running_head;
  628. rwlock_t erp_lock;
  629. struct semaphore erp_ready_sem;
  630. wait_queue_head_t erp_thread_wqh;
  631. wait_queue_head_t erp_done_wqh;
  632. struct zfcp_erp_action erp_action; /* pending error recovery */
  633. atomic_t erp_counter;
  634. u32 erp_total_count; /* total nr of enqueued erp
  635. actions */
  636. u32 erp_low_mem_count; /* nr of erp actions waiting
  637. for memory */
  638. struct zfcp_port *nameserver_port; /* adapter's nameserver */
  639. debug_info_t *rec_dbf;
  640. debug_info_t *hba_dbf;
  641. debug_info_t *san_dbf; /* debug feature areas */
  642. debug_info_t *scsi_dbf;
  643. spinlock_t rec_dbf_lock;
  644. spinlock_t hba_dbf_lock;
  645. spinlock_t san_dbf_lock;
  646. spinlock_t scsi_dbf_lock;
  647. struct zfcp_rec_dbf_record rec_dbf_buf;
  648. struct zfcp_hba_dbf_record hba_dbf_buf;
  649. struct zfcp_san_dbf_record san_dbf_buf;
  650. struct zfcp_scsi_dbf_record scsi_dbf_buf;
  651. struct zfcp_adapter_mempool pool; /* Adapter memory pools */
  652. struct qdio_initialize qdio_init_data; /* for qdio_establish */
  653. struct device generic_services; /* directory for WKA ports */
  654. struct fc_host_statistics *fc_stats;
  655. struct fsf_qtcb_bottom_port *stats_reset_data;
  656. unsigned long stats_reset;
  657. };
  658. /*
  659. * the struct device sysfs_device must be at the beginning of this structure.
  660. * pointer to struct device is used to free port structure in release function
  661. * of the device. don't change!
  662. */
  663. struct zfcp_port {
  664. struct device sysfs_device; /* sysfs device */
  665. struct fc_rport *rport; /* rport of fc transport class */
  666. struct list_head list; /* list of remote ports */
  667. atomic_t refcount; /* reference count */
  668. wait_queue_head_t remove_wq; /* can be used to wait for
  669. refcount drop to zero */
  670. struct zfcp_adapter *adapter; /* adapter used to access port */
  671. struct list_head unit_list_head; /* head of logical unit list */
  672. struct list_head unit_remove_lh; /* head of luns to be removed
  673. list */
  674. u32 units; /* # of logical units in list */
  675. atomic_t status; /* status of this remote port */
  676. wwn_t wwnn; /* WWNN if known */
  677. wwn_t wwpn; /* WWPN */
  678. u32 d_id; /* D_ID */
  679. u32 handle; /* handle assigned by FSF */
  680. struct zfcp_erp_action erp_action; /* pending error recovery */
  681. atomic_t erp_counter;
  682. u32 maxframe_size;
  683. u32 supported_classes;
  684. };
  685. /* the struct device sysfs_device must be at the beginning of this structure.
  686. * pointer to struct device is used to free unit structure in release function
  687. * of the device. don't change!
  688. */
  689. struct zfcp_unit {
  690. struct device sysfs_device; /* sysfs device */
  691. struct list_head list; /* list of logical units */
  692. atomic_t refcount; /* reference count */
  693. wait_queue_head_t remove_wq; /* can be used to wait for
  694. refcount drop to zero */
  695. struct zfcp_port *port; /* remote port of unit */
  696. atomic_t status; /* status of this logical unit */
  697. unsigned int scsi_lun; /* own SCSI LUN */
  698. fcp_lun_t fcp_lun; /* own FCP_LUN */
  699. u32 handle; /* handle assigned by FSF */
  700. struct scsi_device *device; /* scsi device struct pointer */
  701. struct zfcp_erp_action erp_action; /* pending error recovery */
  702. atomic_t erp_counter;
  703. struct zfcp_latencies latencies;
  704. };
  705. /* FSF request */
  706. struct zfcp_fsf_req {
  707. struct list_head list; /* list of FSF requests */
  708. unsigned long req_id; /* unique request ID */
  709. struct zfcp_adapter *adapter; /* adapter request belongs to */
  710. u8 sbal_number; /* nr of SBALs free for use */
  711. u8 sbal_first; /* first SBAL for this request */
  712. u8 sbal_last; /* last SBAL for this request */
  713. u8 sbal_limit; /* last possible SBAL for
  714. this reuest */
  715. u8 sbale_curr; /* current SBALE during creation
  716. of request */
  717. u8 sbal_response; /* SBAL used in interrupt */
  718. wait_queue_head_t completion_wq; /* can be used by a routine
  719. to wait for completion */
  720. volatile u32 status; /* status of this request */
  721. u32 fsf_command; /* FSF Command copy */
  722. struct fsf_qtcb *qtcb; /* address of associated QTCB */
  723. u32 seq_no; /* Sequence number of request */
  724. unsigned long data; /* private data of request */
  725. struct timer_list timer; /* used for erp or scsi er */
  726. struct zfcp_erp_action *erp_action; /* used if this request is
  727. issued on behalf of erp */
  728. mempool_t *pool; /* used if request was alloacted
  729. from emergency pool */
  730. unsigned long long issued; /* request sent time (STCK) */
  731. struct zfcp_unit *unit;
  732. };
  733. typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
  734. /* driver data */
  735. struct zfcp_data {
  736. struct scsi_host_template scsi_host_template;
  737. struct scsi_transport_template *scsi_transport_template;
  738. atomic_t status; /* Module status flags */
  739. struct list_head adapter_list_head; /* head of adapter list */
  740. struct list_head adapter_remove_lh; /* head of adapters to be
  741. removed */
  742. u32 adapters; /* # of adapters in list */
  743. rwlock_t config_lock; /* serialises changes
  744. to adapter/port/unit
  745. lists */
  746. struct semaphore config_sema; /* serialises configuration
  747. changes */
  748. atomic_t loglevel; /* current loglevel */
  749. char init_busid[BUS_ID_SIZE];
  750. wwn_t init_wwpn;
  751. fcp_lun_t init_fcp_lun;
  752. char *driver_version;
  753. struct kmem_cache *fsf_req_qtcb_cache;
  754. struct kmem_cache *sr_buffer_cache;
  755. struct kmem_cache *gid_pn_cache;
  756. };
  757. /* number of elements for various memory pools */
  758. #define ZFCP_POOL_FSF_REQ_ERP_NR 1
  759. #define ZFCP_POOL_FSF_REQ_SCSI_NR 1
  760. #define ZFCP_POOL_FSF_REQ_ABORT_NR 1
  761. #define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM
  762. #define ZFCP_POOL_DATA_GID_PN_NR 1
  763. /* struct used by memory pools for fsf_requests */
  764. struct zfcp_fsf_req_qtcb {
  765. struct zfcp_fsf_req fsf_req;
  766. struct fsf_qtcb qtcb;
  767. };
  768. /********************** ZFCP SPECIFIC DEFINES ********************************/
  769. #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
  770. #define ZFCP_WAIT_FOR_SBAL 0x00000004
  771. #define ZFCP_REQ_NO_QTCB 0x00000008
  772. #define ZFCP_SET 0x00000100
  773. #define ZFCP_CLEAR 0x00000200
  774. #ifndef atomic_test_mask
  775. #define atomic_test_mask(mask, target) \
  776. ((atomic_read(target) & mask) == mask)
  777. #endif
  778. extern void _zfcp_hex_dump(char *, int);
  779. #define ZFCP_HEX_DUMP(level, addr, count) \
  780. if (ZFCP_LOG_CHECK(level)) { \
  781. _zfcp_hex_dump(addr, count); \
  782. }
  783. #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
  784. #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
  785. #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
  786. /*
  787. * Helper functions for request ID management.
  788. */
  789. static inline int zfcp_reqlist_hash(unsigned long req_id)
  790. {
  791. return req_id % REQUEST_LIST_SIZE;
  792. }
  793. static inline void zfcp_reqlist_add(struct zfcp_adapter *adapter,
  794. struct zfcp_fsf_req *fsf_req)
  795. {
  796. unsigned int idx;
  797. idx = zfcp_reqlist_hash(fsf_req->req_id);
  798. list_add_tail(&fsf_req->list, &adapter->req_list[idx]);
  799. }
  800. static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
  801. struct zfcp_fsf_req *fsf_req)
  802. {
  803. list_del(&fsf_req->list);
  804. }
  805. static inline struct zfcp_fsf_req *
  806. zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
  807. {
  808. struct zfcp_fsf_req *request;
  809. unsigned int idx;
  810. idx = zfcp_reqlist_hash(req_id);
  811. list_for_each_entry(request, &adapter->req_list[idx], list)
  812. if (request->req_id == req_id)
  813. return request;
  814. return NULL;
  815. }
  816. static inline struct zfcp_fsf_req *
  817. zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
  818. {
  819. struct zfcp_fsf_req *request;
  820. unsigned int idx;
  821. for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
  822. list_for_each_entry(request, &adapter->req_list[idx], list)
  823. if (request == req)
  824. return request;
  825. }
  826. return NULL;
  827. }
  828. /*
  829. * functions needed for reference/usage counting
  830. */
  831. static inline void
  832. zfcp_unit_get(struct zfcp_unit *unit)
  833. {
  834. atomic_inc(&unit->refcount);
  835. }
  836. static inline void
  837. zfcp_unit_put(struct zfcp_unit *unit)
  838. {
  839. if (atomic_dec_return(&unit->refcount) == 0)
  840. wake_up(&unit->remove_wq);
  841. }
  842. static inline void
  843. zfcp_unit_wait(struct zfcp_unit *unit)
  844. {
  845. wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
  846. }
  847. static inline void
  848. zfcp_port_get(struct zfcp_port *port)
  849. {
  850. atomic_inc(&port->refcount);
  851. }
  852. static inline void
  853. zfcp_port_put(struct zfcp_port *port)
  854. {
  855. if (atomic_dec_return(&port->refcount) == 0)
  856. wake_up(&port->remove_wq);
  857. }
  858. static inline void
  859. zfcp_port_wait(struct zfcp_port *port)
  860. {
  861. wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
  862. }
  863. static inline void
  864. zfcp_adapter_get(struct zfcp_adapter *adapter)
  865. {
  866. atomic_inc(&adapter->refcount);
  867. }
  868. static inline void
  869. zfcp_adapter_put(struct zfcp_adapter *adapter)
  870. {
  871. if (atomic_dec_return(&adapter->refcount) == 0)
  872. wake_up(&adapter->remove_wq);
  873. }
  874. static inline void
  875. zfcp_adapter_wait(struct zfcp_adapter *adapter)
  876. {
  877. wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
  878. }
  879. #endif /* ZFCP_DEF_H */