zfcp_def.h 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  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. #define ZFCP_MAX_SECTORS (ZFCP_MAX_SBALES_PER_REQ * 8)
  94. /* max. number of (data buffer) SBALEs in largest SBAL chain
  95. multiplied with number of sectors per 4k block */
  96. /* FIXME(tune): free space should be one max. SBAL chain plus what? */
  97. #define ZFCP_QDIO_PCI_INTERVAL (QDIO_MAX_BUFFERS_PER_Q \
  98. - (ZFCP_MAX_SBALS_PER_REQ + 4))
  99. #define ZFCP_SBAL_TIMEOUT (5*HZ)
  100. #define ZFCP_TYPE2_RECOVERY_TIME (8*HZ)
  101. /* queue polling (values in microseconds) */
  102. #define ZFCP_MAX_INPUT_THRESHOLD 5000 /* FIXME: tune */
  103. #define ZFCP_MAX_OUTPUT_THRESHOLD 1000 /* FIXME: tune */
  104. #define ZFCP_MIN_INPUT_THRESHOLD 1 /* ignored by QDIO layer */
  105. #define ZFCP_MIN_OUTPUT_THRESHOLD 1 /* ignored by QDIO layer */
  106. #define QDIO_SCSI_QFMT 1 /* 1 for FSF */
  107. #define QBUFF_PER_PAGE (PAGE_SIZE / sizeof(struct qdio_buffer))
  108. /********************* FSF SPECIFIC DEFINES *********************************/
  109. #define ZFCP_ULP_INFO_VERSION 26
  110. #define ZFCP_QTCB_VERSION FSF_QTCB_CURRENT_VERSION
  111. /* ATTENTION: value must not be used by hardware */
  112. #define FSF_QTCB_UNSOLICITED_STATUS 0x6305
  113. #define ZFCP_STATUS_READ_FAILED_THRESHOLD 3
  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 100
  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 0x61040000
  186. #define LS_LOGO 0x05000000
  187. #define LS_PLOGI 0x03000000
  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. * DBF stuff
  218. */
  219. #define ZFCP_DBF_TAG_SIZE 4
  220. struct zfcp_dbf_dump {
  221. u8 tag[ZFCP_DBF_TAG_SIZE];
  222. u32 total_size; /* size of total dump data */
  223. u32 offset; /* how much data has being already dumped */
  224. u32 size; /* how much data comes with this record */
  225. u8 data[]; /* dump data */
  226. } __attribute__ ((packed));
  227. /* FIXME: to be inflated when reworking the erp dbf */
  228. struct zfcp_erp_dbf_record {
  229. u8 dummy[16];
  230. } __attribute__ ((packed));
  231. struct zfcp_hba_dbf_record_response {
  232. u32 fsf_command;
  233. u64 fsf_reqid;
  234. u32 fsf_seqno;
  235. u64 fsf_issued;
  236. u32 fsf_prot_status;
  237. u32 fsf_status;
  238. u8 fsf_prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE];
  239. u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
  240. u32 fsf_req_status;
  241. u8 sbal_first;
  242. u8 sbal_curr;
  243. u8 sbal_last;
  244. u8 pool;
  245. u64 erp_action;
  246. union {
  247. struct {
  248. u64 scsi_cmnd;
  249. u64 scsi_serial;
  250. } send_fcp;
  251. struct {
  252. u64 wwpn;
  253. u32 d_id;
  254. u32 port_handle;
  255. } port;
  256. struct {
  257. u64 wwpn;
  258. u64 fcp_lun;
  259. u32 port_handle;
  260. u32 lun_handle;
  261. } unit;
  262. struct {
  263. u32 d_id;
  264. u8 ls_code;
  265. } send_els;
  266. } data;
  267. } __attribute__ ((packed));
  268. struct zfcp_hba_dbf_record_status {
  269. u8 failed;
  270. u32 status_type;
  271. u32 status_subtype;
  272. struct fsf_queue_designator
  273. queue_designator;
  274. u32 payload_size;
  275. #define ZFCP_DBF_UNSOL_PAYLOAD 80
  276. #define ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL 32
  277. #define ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD 56
  278. #define ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT 2 * sizeof(u32)
  279. u8 payload[ZFCP_DBF_UNSOL_PAYLOAD];
  280. } __attribute__ ((packed));
  281. struct zfcp_hba_dbf_record_qdio {
  282. u32 status;
  283. u32 qdio_error;
  284. u32 siga_error;
  285. u8 sbal_index;
  286. u8 sbal_count;
  287. } __attribute__ ((packed));
  288. struct zfcp_hba_dbf_record {
  289. u8 tag[ZFCP_DBF_TAG_SIZE];
  290. u8 tag2[ZFCP_DBF_TAG_SIZE];
  291. union {
  292. struct zfcp_hba_dbf_record_response response;
  293. struct zfcp_hba_dbf_record_status status;
  294. struct zfcp_hba_dbf_record_qdio qdio;
  295. } type;
  296. } __attribute__ ((packed));
  297. struct zfcp_san_dbf_record_ct {
  298. union {
  299. struct {
  300. u16 cmd_req_code;
  301. u8 revision;
  302. u8 gs_type;
  303. u8 gs_subtype;
  304. u8 options;
  305. u16 max_res_size;
  306. } request;
  307. struct {
  308. u16 cmd_rsp_code;
  309. u8 revision;
  310. u8 reason_code;
  311. u8 reason_code_expl;
  312. u8 vendor_unique;
  313. } response;
  314. } type;
  315. u32 payload_size;
  316. #define ZFCP_DBF_CT_PAYLOAD 24
  317. u8 payload[ZFCP_DBF_CT_PAYLOAD];
  318. } __attribute__ ((packed));
  319. struct zfcp_san_dbf_record_els {
  320. u8 ls_code;
  321. u32 payload_size;
  322. #define ZFCP_DBF_ELS_PAYLOAD 32
  323. #define ZFCP_DBF_ELS_MAX_PAYLOAD 1024
  324. u8 payload[ZFCP_DBF_ELS_PAYLOAD];
  325. } __attribute__ ((packed));
  326. struct zfcp_san_dbf_record {
  327. u8 tag[ZFCP_DBF_TAG_SIZE];
  328. u64 fsf_reqid;
  329. u32 fsf_seqno;
  330. u32 s_id;
  331. u32 d_id;
  332. union {
  333. struct zfcp_san_dbf_record_ct ct;
  334. struct zfcp_san_dbf_record_els els;
  335. } type;
  336. } __attribute__ ((packed));
  337. struct zfcp_scsi_dbf_record {
  338. u8 tag[ZFCP_DBF_TAG_SIZE];
  339. u8 tag2[ZFCP_DBF_TAG_SIZE];
  340. u32 scsi_id;
  341. u32 scsi_lun;
  342. u32 scsi_result;
  343. u64 scsi_cmnd;
  344. u64 scsi_serial;
  345. #define ZFCP_DBF_SCSI_OPCODE 16
  346. u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE];
  347. u8 scsi_retries;
  348. u8 scsi_allowed;
  349. u64 fsf_reqid;
  350. u32 fsf_seqno;
  351. u64 fsf_issued;
  352. union {
  353. u64 old_fsf_reqid;
  354. struct {
  355. u8 rsp_validity;
  356. u8 rsp_scsi_status;
  357. u32 rsp_resid;
  358. u8 rsp_code;
  359. #define ZFCP_DBF_SCSI_FCP_SNS_INFO 16
  360. #define ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO 256
  361. u32 sns_info_len;
  362. u8 sns_info[ZFCP_DBF_SCSI_FCP_SNS_INFO];
  363. } fcp;
  364. } type;
  365. } __attribute__ ((packed));
  366. /*
  367. * FC-FS stuff
  368. */
  369. #define R_A_TOV 10 /* seconds */
  370. #define ZFCP_ELS_TIMEOUT (2 * R_A_TOV)
  371. #define ZFCP_LS_RLS 0x0f
  372. #define ZFCP_LS_ADISC 0x52
  373. #define ZFCP_LS_RPS 0x56
  374. #define ZFCP_LS_RSCN 0x61
  375. #define ZFCP_LS_RNID 0x78
  376. struct zfcp_ls_rjt_par {
  377. u8 action;
  378. u8 reason_code;
  379. u8 reason_expl;
  380. u8 vendor_unique;
  381. } __attribute__ ((packed));
  382. struct zfcp_ls_adisc {
  383. u8 code;
  384. u8 field[3];
  385. u32 hard_nport_id;
  386. u64 wwpn;
  387. u64 wwnn;
  388. u32 nport_id;
  389. } __attribute__ ((packed));
  390. struct zfcp_ls_adisc_acc {
  391. u8 code;
  392. u8 field[3];
  393. u32 hard_nport_id;
  394. u64 wwpn;
  395. u64 wwnn;
  396. u32 nport_id;
  397. } __attribute__ ((packed));
  398. struct zfcp_rc_entry {
  399. u8 code;
  400. const char *description;
  401. };
  402. /*
  403. * FC-GS-2 stuff
  404. */
  405. #define ZFCP_CT_REVISION 0x01
  406. #define ZFCP_CT_DIRECTORY_SERVICE 0xFC
  407. #define ZFCP_CT_NAME_SERVER 0x02
  408. #define ZFCP_CT_SYNCHRONOUS 0x00
  409. #define ZFCP_CT_GID_PN 0x0121
  410. #define ZFCP_CT_MAX_SIZE 0x1020
  411. #define ZFCP_CT_ACCEPT 0x8002
  412. #define ZFCP_CT_REJECT 0x8001
  413. /*
  414. * FC-GS-4 stuff
  415. */
  416. #define ZFCP_CT_TIMEOUT (3 * R_A_TOV)
  417. /******************** LOGGING MACROS AND DEFINES *****************************/
  418. /*
  419. * Logging may be applied on certain kinds of driver operations
  420. * independently. Additionally, different log-levels are supported for
  421. * each of these areas.
  422. */
  423. #define ZFCP_NAME "zfcp"
  424. /* independent log areas */
  425. #define ZFCP_LOG_AREA_OTHER 0
  426. #define ZFCP_LOG_AREA_SCSI 1
  427. #define ZFCP_LOG_AREA_FSF 2
  428. #define ZFCP_LOG_AREA_CONFIG 3
  429. #define ZFCP_LOG_AREA_CIO 4
  430. #define ZFCP_LOG_AREA_QDIO 5
  431. #define ZFCP_LOG_AREA_ERP 6
  432. #define ZFCP_LOG_AREA_FC 7
  433. /* log level values*/
  434. #define ZFCP_LOG_LEVEL_NORMAL 0
  435. #define ZFCP_LOG_LEVEL_INFO 1
  436. #define ZFCP_LOG_LEVEL_DEBUG 2
  437. #define ZFCP_LOG_LEVEL_TRACE 3
  438. /*
  439. * this allows removal of logging code by the preprocessor
  440. * (the most detailed log level still to be compiled in is specified,
  441. * higher log levels are removed)
  442. */
  443. #define ZFCP_LOG_LEVEL_LIMIT ZFCP_LOG_LEVEL_TRACE
  444. /* get "loglevel" nibble assignment */
  445. #define ZFCP_GET_LOG_VALUE(zfcp_lognibble) \
  446. ((atomic_read(&zfcp_data.loglevel) >> (zfcp_lognibble<<2)) & 0xF)
  447. /* set "loglevel" nibble */
  448. #define ZFCP_SET_LOG_NIBBLE(value, zfcp_lognibble) \
  449. (value << (zfcp_lognibble << 2))
  450. /* all log-level defaults are combined to generate initial log-level */
  451. #define ZFCP_LOG_LEVEL_DEFAULTS \
  452. (ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_OTHER) | \
  453. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_SCSI) | \
  454. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FSF) | \
  455. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CONFIG) | \
  456. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_CIO) | \
  457. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_QDIO) | \
  458. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_ERP) | \
  459. ZFCP_SET_LOG_NIBBLE(ZFCP_LOG_LEVEL_NORMAL, ZFCP_LOG_AREA_FC))
  460. /* check whether we have the right level for logging */
  461. #define ZFCP_LOG_CHECK(level) \
  462. ((ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA)) >= level)
  463. /* logging routine for zfcp */
  464. #define _ZFCP_LOG(fmt, args...) \
  465. printk(KERN_ERR ZFCP_NAME": %s(%d): " fmt, __FUNCTION__, \
  466. __LINE__ , ##args)
  467. #define ZFCP_LOG(level, fmt, args...) \
  468. do { \
  469. if (ZFCP_LOG_CHECK(level)) \
  470. _ZFCP_LOG(fmt, ##args); \
  471. } while (0)
  472. #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_NORMAL
  473. # define ZFCP_LOG_NORMAL(fmt, args...) do { } while (0)
  474. #else
  475. # define ZFCP_LOG_NORMAL(fmt, args...) \
  476. do { \
  477. if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_NORMAL)) \
  478. printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
  479. } while (0)
  480. #endif
  481. #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_INFO
  482. # define ZFCP_LOG_INFO(fmt, args...) do { } while (0)
  483. #else
  484. # define ZFCP_LOG_INFO(fmt, args...) \
  485. do { \
  486. if (ZFCP_LOG_CHECK(ZFCP_LOG_LEVEL_INFO)) \
  487. printk(KERN_ERR ZFCP_NAME": " fmt, ##args); \
  488. } while (0)
  489. #endif
  490. #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_DEBUG
  491. # define ZFCP_LOG_DEBUG(fmt, args...) do { } while (0)
  492. #else
  493. # define ZFCP_LOG_DEBUG(fmt, args...) \
  494. ZFCP_LOG(ZFCP_LOG_LEVEL_DEBUG, fmt , ##args)
  495. #endif
  496. #if ZFCP_LOG_LEVEL_LIMIT < ZFCP_LOG_LEVEL_TRACE
  497. # define ZFCP_LOG_TRACE(fmt, args...) do { } while (0)
  498. #else
  499. # define ZFCP_LOG_TRACE(fmt, args...) \
  500. ZFCP_LOG(ZFCP_LOG_LEVEL_TRACE, fmt , ##args)
  501. #endif
  502. /*************** ADAPTER/PORT/UNIT AND FSF_REQ STATUS FLAGS ******************/
  503. /*
  504. * Note, the leftmost status byte is common among adapter, port
  505. * and unit
  506. */
  507. #define ZFCP_COMMON_FLAGS 0xfff00000
  508. /* common status bits */
  509. #define ZFCP_STATUS_COMMON_REMOVE 0x80000000
  510. #define ZFCP_STATUS_COMMON_RUNNING 0x40000000
  511. #define ZFCP_STATUS_COMMON_ERP_FAILED 0x20000000
  512. #define ZFCP_STATUS_COMMON_UNBLOCKED 0x10000000
  513. #define ZFCP_STATUS_COMMON_OPENING 0x08000000
  514. #define ZFCP_STATUS_COMMON_OPEN 0x04000000
  515. #define ZFCP_STATUS_COMMON_CLOSING 0x02000000
  516. #define ZFCP_STATUS_COMMON_ERP_INUSE 0x01000000
  517. #define ZFCP_STATUS_COMMON_ACCESS_DENIED 0x00800000
  518. #define ZFCP_STATUS_COMMON_ACCESS_BOXED 0x00400000
  519. /* adapter status */
  520. #define ZFCP_STATUS_ADAPTER_QDIOUP 0x00000002
  521. #define ZFCP_STATUS_ADAPTER_REGISTERED 0x00000004
  522. #define ZFCP_STATUS_ADAPTER_XCONFIG_OK 0x00000008
  523. #define ZFCP_STATUS_ADAPTER_HOST_CON_INIT 0x00000010
  524. #define ZFCP_STATUS_ADAPTER_ERP_THREAD_UP 0x00000020
  525. #define ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL 0x00000080
  526. #define ZFCP_STATUS_ADAPTER_ERP_PENDING 0x00000100
  527. #define ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED 0x00000200
  528. #define ZFCP_STATUS_ADAPTER_XPORT_OK 0x00000800
  529. /* FC-PH/FC-GS well-known address identifiers for generic services */
  530. #define ZFCP_DID_MANAGEMENT_SERVICE 0xFFFFFA
  531. #define ZFCP_DID_TIME_SERVICE 0xFFFFFB
  532. #define ZFCP_DID_DIRECTORY_SERVICE 0xFFFFFC
  533. #define ZFCP_DID_ALIAS_SERVICE 0xFFFFF8
  534. #define ZFCP_DID_KEY_DISTRIBUTION_SERVICE 0xFFFFF7
  535. /* remote port status */
  536. #define ZFCP_STATUS_PORT_PHYS_OPEN 0x00000001
  537. #define ZFCP_STATUS_PORT_DID_DID 0x00000002
  538. #define ZFCP_STATUS_PORT_PHYS_CLOSING 0x00000004
  539. #define ZFCP_STATUS_PORT_NO_WWPN 0x00000008
  540. #define ZFCP_STATUS_PORT_NO_SCSI_ID 0x00000010
  541. #define ZFCP_STATUS_PORT_INVALID_WWPN 0x00000020
  542. /* for ports with well known addresses */
  543. #define ZFCP_STATUS_PORT_WKA \
  544. (ZFCP_STATUS_PORT_NO_WWPN | \
  545. ZFCP_STATUS_PORT_NO_SCSI_ID)
  546. /* logical unit status */
  547. #define ZFCP_STATUS_UNIT_NOTSUPPUNITRESET 0x00000001
  548. #define ZFCP_STATUS_UNIT_TEMPORARY 0x00000002
  549. #define ZFCP_STATUS_UNIT_SHARED 0x00000004
  550. #define ZFCP_STATUS_UNIT_READONLY 0x00000008
  551. #define ZFCP_STATUS_UNIT_REGISTERED 0x00000010
  552. #define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING 0x00000020
  553. /* FSF request status (this does not have a common part) */
  554. #define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
  555. #define ZFCP_STATUS_FSFREQ_POOL 0x00000001
  556. #define ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT 0x00000002
  557. #define ZFCP_STATUS_FSFREQ_COMPLETED 0x00000004
  558. #define ZFCP_STATUS_FSFREQ_ERROR 0x00000008
  559. #define ZFCP_STATUS_FSFREQ_CLEANUP 0x00000010
  560. #define ZFCP_STATUS_FSFREQ_ABORTING 0x00000020
  561. #define ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED 0x00000040
  562. #define ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED 0x00000080
  563. #define ZFCP_STATUS_FSFREQ_ABORTED 0x00000100
  564. #define ZFCP_STATUS_FSFREQ_TMFUNCFAILED 0x00000200
  565. #define ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP 0x00000400
  566. #define ZFCP_STATUS_FSFREQ_RETRY 0x00000800
  567. #define ZFCP_STATUS_FSFREQ_DISMISSED 0x00001000
  568. /*********************** ERROR RECOVERY PROCEDURE DEFINES ********************/
  569. #define ZFCP_MAX_ERPS 3
  570. #define ZFCP_ERP_FSFREQ_TIMEOUT (30 * HZ)
  571. #define ZFCP_ERP_MEMWAIT_TIMEOUT HZ
  572. #define ZFCP_STATUS_ERP_TIMEDOUT 0x10000000
  573. #define ZFCP_STATUS_ERP_CLOSE_ONLY 0x01000000
  574. #define ZFCP_STATUS_ERP_DISMISSING 0x00100000
  575. #define ZFCP_STATUS_ERP_DISMISSED 0x00200000
  576. #define ZFCP_STATUS_ERP_LOWMEM 0x00400000
  577. #define ZFCP_ERP_STEP_UNINITIALIZED 0x00000000
  578. #define ZFCP_ERP_STEP_FSF_XCONFIG 0x00000001
  579. #define ZFCP_ERP_STEP_PHYS_PORT_CLOSING 0x00000010
  580. #define ZFCP_ERP_STEP_PORT_CLOSING 0x00000100
  581. #define ZFCP_ERP_STEP_NAMESERVER_OPEN 0x00000200
  582. #define ZFCP_ERP_STEP_NAMESERVER_LOOKUP 0x00000400
  583. #define ZFCP_ERP_STEP_PORT_OPENING 0x00000800
  584. #define ZFCP_ERP_STEP_UNIT_CLOSING 0x00001000
  585. #define ZFCP_ERP_STEP_UNIT_OPENING 0x00002000
  586. /* Ordered by escalation level (necessary for proper erp-code operation) */
  587. #define ZFCP_ERP_ACTION_REOPEN_ADAPTER 0x4
  588. #define ZFCP_ERP_ACTION_REOPEN_PORT_FORCED 0x3
  589. #define ZFCP_ERP_ACTION_REOPEN_PORT 0x2
  590. #define ZFCP_ERP_ACTION_REOPEN_UNIT 0x1
  591. #define ZFCP_ERP_ACTION_RUNNING 0x1
  592. #define ZFCP_ERP_ACTION_READY 0x2
  593. #define ZFCP_ERP_SUCCEEDED 0x0
  594. #define ZFCP_ERP_FAILED 0x1
  595. #define ZFCP_ERP_CONTINUES 0x2
  596. #define ZFCP_ERP_EXIT 0x3
  597. #define ZFCP_ERP_DISMISSED 0x4
  598. #define ZFCP_ERP_NOMEM 0x5
  599. /******************** CFDC SPECIFIC STUFF *****************************/
  600. /* Firewall data channel sense data record */
  601. struct zfcp_cfdc_sense_data {
  602. u32 signature; /* Request signature */
  603. u32 devno; /* FCP adapter device number */
  604. u32 command; /* Command code */
  605. u32 fsf_status; /* FSF request status and status qualifier */
  606. u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
  607. u8 payloads[256]; /* Access conflicts list */
  608. u8 control_file[0]; /* Access control table */
  609. };
  610. #define ZFCP_CFDC_SIGNATURE 0xCFDCACDF
  611. #define ZFCP_CFDC_CMND_DOWNLOAD_NORMAL 0x00010001
  612. #define ZFCP_CFDC_CMND_DOWNLOAD_FORCE 0x00010101
  613. #define ZFCP_CFDC_CMND_FULL_ACCESS 0x00000201
  614. #define ZFCP_CFDC_CMND_RESTRICTED_ACCESS 0x00000401
  615. #define ZFCP_CFDC_CMND_UPLOAD 0x00010002
  616. #define ZFCP_CFDC_DOWNLOAD 0x00000001
  617. #define ZFCP_CFDC_UPLOAD 0x00000002
  618. #define ZFCP_CFDC_WITH_CONTROL_FILE 0x00010000
  619. #define ZFCP_CFDC_DEV_NAME "zfcp_cfdc"
  620. #define ZFCP_CFDC_DEV_MAJOR MISC_MAJOR
  621. #define ZFCP_CFDC_DEV_MINOR MISC_DYNAMIC_MINOR
  622. #define ZFCP_CFDC_MAX_CONTROL_FILE_SIZE 127 * 1024
  623. /************************* STRUCTURE DEFINITIONS *****************************/
  624. struct zfcp_fsf_req;
  625. /* holds various memory pools of an adapter */
  626. struct zfcp_adapter_mempool {
  627. mempool_t *fsf_req_erp;
  628. mempool_t *fsf_req_scsi;
  629. mempool_t *fsf_req_abort;
  630. mempool_t *fsf_req_status_read;
  631. mempool_t *data_status_read;
  632. mempool_t *data_gid_pn;
  633. };
  634. /*
  635. * header for CT_IU
  636. */
  637. struct ct_hdr {
  638. u8 revision; // 0x01
  639. u8 in_id[3]; // 0x00
  640. u8 gs_type; // 0xFC Directory Service
  641. u8 gs_subtype; // 0x02 Name Server
  642. u8 options; // 0x00 single bidirectional exchange
  643. u8 reserved0;
  644. u16 cmd_rsp_code; // 0x0121 GID_PN, or 0x0100 GA_NXT
  645. u16 max_res_size; // <= (4096 - 16) / 4
  646. u8 reserved1;
  647. u8 reason_code;
  648. u8 reason_code_expl;
  649. u8 vendor_unique;
  650. } __attribute__ ((packed));
  651. /* nameserver request CT_IU -- for requests where
  652. * a port name is required */
  653. struct ct_iu_gid_pn_req {
  654. struct ct_hdr header;
  655. wwn_t wwpn;
  656. } __attribute__ ((packed));
  657. /* FS_ACC IU and data unit for GID_PN nameserver request */
  658. struct ct_iu_gid_pn_resp {
  659. struct ct_hdr header;
  660. u32 d_id;
  661. } __attribute__ ((packed));
  662. typedef void (*zfcp_send_ct_handler_t)(unsigned long);
  663. /**
  664. * struct zfcp_send_ct - used to pass parameters to function zfcp_fsf_send_ct
  665. * @port: port where the request is sent to
  666. * @req: scatter-gather list for request
  667. * @resp: scatter-gather list for response
  668. * @req_count: number of elements in request scatter-gather list
  669. * @resp_count: number of elements in response scatter-gather list
  670. * @handler: handler function (called for response to the request)
  671. * @handler_data: data passed to handler function
  672. * @pool: pointer to memory pool for ct request structure
  673. * @timeout: FSF timeout for this request
  674. * @completion: completion for synchronization purposes
  675. * @status: used to pass error status to calling function
  676. */
  677. struct zfcp_send_ct {
  678. struct zfcp_port *port;
  679. struct scatterlist *req;
  680. struct scatterlist *resp;
  681. unsigned int req_count;
  682. unsigned int resp_count;
  683. zfcp_send_ct_handler_t handler;
  684. unsigned long handler_data;
  685. mempool_t *pool;
  686. int timeout;
  687. struct completion *completion;
  688. int status;
  689. };
  690. /* used for name server requests in error recovery */
  691. struct zfcp_gid_pn_data {
  692. struct zfcp_send_ct ct;
  693. struct scatterlist req;
  694. struct scatterlist resp;
  695. struct ct_iu_gid_pn_req ct_iu_req;
  696. struct ct_iu_gid_pn_resp ct_iu_resp;
  697. struct zfcp_port *port;
  698. };
  699. typedef void (*zfcp_send_els_handler_t)(unsigned long);
  700. /**
  701. * struct zfcp_send_els - used to pass parameters to function zfcp_fsf_send_els
  702. * @adapter: adapter where request is sent from
  703. * @port: port where ELS is destinated (port reference count has to be increased)
  704. * @d_id: destiniation id of port where request is sent to
  705. * @req: scatter-gather list for request
  706. * @resp: scatter-gather list for response
  707. * @req_count: number of elements in request scatter-gather list
  708. * @resp_count: number of elements in response scatter-gather list
  709. * @handler: handler function (called for response to the request)
  710. * @handler_data: data passed to handler function
  711. * @completion: completion for synchronization purposes
  712. * @ls_code: hex code of ELS command
  713. * @status: used to pass error status to calling function
  714. */
  715. struct zfcp_send_els {
  716. struct zfcp_adapter *adapter;
  717. struct zfcp_port *port;
  718. u32 d_id;
  719. struct scatterlist *req;
  720. struct scatterlist *resp;
  721. unsigned int req_count;
  722. unsigned int resp_count;
  723. zfcp_send_els_handler_t handler;
  724. unsigned long handler_data;
  725. struct completion *completion;
  726. int ls_code;
  727. int status;
  728. };
  729. struct zfcp_qdio_queue {
  730. struct qdio_buffer *buffer[QDIO_MAX_BUFFERS_PER_Q]; /* SBALs */
  731. u8 free_index; /* index of next free bfr
  732. in queue (free_count>0) */
  733. atomic_t free_count; /* number of free buffers
  734. in queue */
  735. rwlock_t queue_lock; /* lock for operations on queue */
  736. int distance_from_int; /* SBALs used since PCI indication
  737. was last set */
  738. };
  739. struct zfcp_erp_action {
  740. struct list_head list;
  741. int action; /* requested action code */
  742. struct zfcp_adapter *adapter; /* device which should be recovered */
  743. struct zfcp_port *port;
  744. struct zfcp_unit *unit;
  745. volatile u32 status; /* recovery status */
  746. u32 step; /* active step of this erp action */
  747. struct zfcp_fsf_req *fsf_req; /* fsf request currently pending
  748. for this action */
  749. struct timer_list timer;
  750. };
  751. struct zfcp_adapter {
  752. struct list_head list; /* list of adapters */
  753. atomic_t refcount; /* reference count */
  754. wait_queue_head_t remove_wq; /* can be used to wait for
  755. refcount drop to zero */
  756. wwn_t peer_wwnn; /* P2P peer WWNN */
  757. wwn_t peer_wwpn; /* P2P peer WWPN */
  758. u32 peer_d_id; /* P2P peer D_ID */
  759. struct ccw_device *ccw_device; /* S/390 ccw device */
  760. u32 hydra_version; /* Hydra version */
  761. u32 fsf_lic_version;
  762. u32 adapter_features; /* FCP channel features */
  763. u32 connection_features; /* host connection features */
  764. u32 hardware_version; /* of FCP channel */
  765. struct Scsi_Host *scsi_host; /* Pointer to mid-layer */
  766. struct list_head port_list_head; /* remote port list */
  767. struct list_head port_remove_lh; /* head of ports to be
  768. removed */
  769. u32 ports; /* number of remote ports */
  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. wait_queue_head_t scsi_scan_wq; /* can be used to wait until
  863. all scsi_scan_target
  864. requests have been
  865. completed. */
  866. };
  867. /* FSF request */
  868. struct zfcp_fsf_req {
  869. struct list_head list; /* list of FSF requests */
  870. unsigned long req_id; /* unique request ID */
  871. struct zfcp_adapter *adapter; /* adapter request belongs to */
  872. u8 sbal_number; /* nr of SBALs free for use */
  873. u8 sbal_first; /* first SBAL for this request */
  874. u8 sbal_last; /* last possible SBAL for
  875. this reuest */
  876. u8 sbal_curr; /* current SBAL during creation
  877. of request */
  878. u8 sbale_curr; /* current SBALE during creation
  879. of request */
  880. wait_queue_head_t completion_wq; /* can be used by a routine
  881. to wait for completion */
  882. volatile u32 status; /* status of this request */
  883. u32 fsf_command; /* FSF Command copy */
  884. struct fsf_qtcb *qtcb; /* address of associated QTCB */
  885. u32 seq_no; /* Sequence number of request */
  886. unsigned long data; /* private data of request */
  887. struct timer_list timer; /* used for erp or scsi er */
  888. struct zfcp_erp_action *erp_action; /* used if this request is
  889. issued on behalf of erp */
  890. mempool_t *pool; /* used if request was alloacted
  891. from emergency pool */
  892. unsigned long long issued; /* request sent time (STCK) */
  893. struct zfcp_unit *unit;
  894. };
  895. typedef void zfcp_fsf_req_handler_t(struct zfcp_fsf_req*);
  896. /* driver data */
  897. struct zfcp_data {
  898. struct scsi_host_template scsi_host_template;
  899. struct scsi_transport_template *scsi_transport_template;
  900. atomic_t status; /* Module status flags */
  901. struct list_head adapter_list_head; /* head of adapter list */
  902. struct list_head adapter_remove_lh; /* head of adapters to be
  903. removed */
  904. u32 adapters; /* # of adapters in list */
  905. rwlock_t config_lock; /* serialises changes
  906. to adapter/port/unit
  907. lists */
  908. struct semaphore config_sema; /* serialises configuration
  909. changes */
  910. atomic_t loglevel; /* current loglevel */
  911. char init_busid[BUS_ID_SIZE];
  912. wwn_t init_wwpn;
  913. fcp_lun_t init_fcp_lun;
  914. char *driver_version;
  915. struct kmem_cache *fsf_req_qtcb_cache;
  916. struct kmem_cache *sr_buffer_cache;
  917. struct kmem_cache *gid_pn_cache;
  918. };
  919. /**
  920. * struct zfcp_sg_list - struct describing a scatter-gather list
  921. * @sg: pointer to array of (struct scatterlist)
  922. * @count: number of elements in scatter-gather list
  923. */
  924. struct zfcp_sg_list {
  925. struct scatterlist *sg;
  926. unsigned int count;
  927. };
  928. /* number of elements for various memory pools */
  929. #define ZFCP_POOL_FSF_REQ_ERP_NR 1
  930. #define ZFCP_POOL_FSF_REQ_SCSI_NR 1
  931. #define ZFCP_POOL_FSF_REQ_ABORT_NR 1
  932. #define ZFCP_POOL_STATUS_READ_NR ZFCP_STATUS_READS_RECOM
  933. #define ZFCP_POOL_DATA_GID_PN_NR 1
  934. /* struct used by memory pools for fsf_requests */
  935. struct zfcp_fsf_req_qtcb {
  936. struct zfcp_fsf_req fsf_req;
  937. struct fsf_qtcb qtcb;
  938. };
  939. /********************** ZFCP SPECIFIC DEFINES ********************************/
  940. #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
  941. #define ZFCP_WAIT_FOR_SBAL 0x00000004
  942. #define ZFCP_REQ_NO_QTCB 0x00000008
  943. #define ZFCP_SET 0x00000100
  944. #define ZFCP_CLEAR 0x00000200
  945. #ifndef atomic_test_mask
  946. #define atomic_test_mask(mask, target) \
  947. ((atomic_read(target) & mask) == mask)
  948. #endif
  949. extern void _zfcp_hex_dump(char *, int);
  950. #define ZFCP_HEX_DUMP(level, addr, count) \
  951. if (ZFCP_LOG_CHECK(level)) { \
  952. _zfcp_hex_dump(addr, count); \
  953. }
  954. #define zfcp_get_busid_by_adapter(adapter) (adapter->ccw_device->dev.bus_id)
  955. #define zfcp_get_busid_by_port(port) (zfcp_get_busid_by_adapter(port->adapter))
  956. #define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
  957. /*
  958. * Helper functions for request ID management.
  959. */
  960. static inline int zfcp_reqlist_hash(unsigned long req_id)
  961. {
  962. return req_id % REQUEST_LIST_SIZE;
  963. }
  964. static inline void zfcp_reqlist_add(struct zfcp_adapter *adapter,
  965. struct zfcp_fsf_req *fsf_req)
  966. {
  967. unsigned int idx;
  968. idx = zfcp_reqlist_hash(fsf_req->req_id);
  969. list_add_tail(&fsf_req->list, &adapter->req_list[idx]);
  970. }
  971. static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
  972. struct zfcp_fsf_req *fsf_req)
  973. {
  974. list_del(&fsf_req->list);
  975. }
  976. static inline struct zfcp_fsf_req *
  977. zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
  978. {
  979. struct zfcp_fsf_req *request;
  980. unsigned int idx;
  981. idx = zfcp_reqlist_hash(req_id);
  982. list_for_each_entry(request, &adapter->req_list[idx], list)
  983. if (request->req_id == req_id)
  984. return request;
  985. return NULL;
  986. }
  987. /*
  988. * functions needed for reference/usage counting
  989. */
  990. static inline void
  991. zfcp_unit_get(struct zfcp_unit *unit)
  992. {
  993. atomic_inc(&unit->refcount);
  994. }
  995. static inline void
  996. zfcp_unit_put(struct zfcp_unit *unit)
  997. {
  998. if (atomic_dec_return(&unit->refcount) == 0)
  999. wake_up(&unit->remove_wq);
  1000. }
  1001. static inline void
  1002. zfcp_unit_wait(struct zfcp_unit *unit)
  1003. {
  1004. wait_event(unit->remove_wq, atomic_read(&unit->refcount) == 0);
  1005. }
  1006. static inline void
  1007. zfcp_port_get(struct zfcp_port *port)
  1008. {
  1009. atomic_inc(&port->refcount);
  1010. }
  1011. static inline void
  1012. zfcp_port_put(struct zfcp_port *port)
  1013. {
  1014. if (atomic_dec_return(&port->refcount) == 0)
  1015. wake_up(&port->remove_wq);
  1016. }
  1017. static inline void
  1018. zfcp_port_wait(struct zfcp_port *port)
  1019. {
  1020. wait_event(port->remove_wq, atomic_read(&port->refcount) == 0);
  1021. }
  1022. static inline void
  1023. zfcp_adapter_get(struct zfcp_adapter *adapter)
  1024. {
  1025. atomic_inc(&adapter->refcount);
  1026. }
  1027. static inline void
  1028. zfcp_adapter_put(struct zfcp_adapter *adapter)
  1029. {
  1030. if (atomic_dec_return(&adapter->refcount) == 0)
  1031. wake_up(&adapter->remove_wq);
  1032. }
  1033. static inline void
  1034. zfcp_adapter_wait(struct zfcp_adapter *adapter)
  1035. {
  1036. wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
  1037. }
  1038. #endif /* ZFCP_DEF_H */