zfcp_def.h 35 KB

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