zfcp_def.h 33 KB

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