ibmvfc.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. /*
  2. * ibmvfc.h -- driver for IBM Power Virtual Fibre Channel Adapter
  3. *
  4. * Written By: Brian King <brking@linux.vnet.ibm.com>, IBM Corporation
  5. *
  6. * Copyright (C) IBM Corporation, 2008
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #ifndef _IBMVFC_H
  24. #define _IBMVFC_H
  25. #include <linux/list.h>
  26. #include <linux/types.h>
  27. #include "viosrp.h"
  28. #define IBMVFC_NAME "ibmvfc"
  29. #define IBMVFC_DRIVER_VERSION "1.0.5"
  30. #define IBMVFC_DRIVER_DATE "(March 19, 2009)"
  31. #define IBMVFC_DEFAULT_TIMEOUT 60
  32. #define IBMVFC_ADISC_CANCEL_TIMEOUT 45
  33. #define IBMVFC_ADISC_TIMEOUT 15
  34. #define IBMVFC_ADISC_PLUS_CANCEL_TIMEOUT \
  35. (IBMVFC_ADISC_TIMEOUT + IBMVFC_ADISC_CANCEL_TIMEOUT)
  36. #define IBMVFC_INIT_TIMEOUT 120
  37. #define IBMVFC_MAX_REQUESTS_DEFAULT 100
  38. #define IBMVFC_DEBUG 0
  39. #define IBMVFC_MAX_TARGETS 1024
  40. #define IBMVFC_MAX_LUN 0xffffffff
  41. #define IBMVFC_MAX_SECTORS 0xffffu
  42. #define IBMVFC_MAX_DISC_THREADS 4
  43. #define IBMVFC_TGT_MEMPOOL_SZ 64
  44. #define IBMVFC_MAX_CMDS_PER_LUN 64
  45. #define IBMVFC_MAX_HOST_INIT_RETRIES 6
  46. #define IBMVFC_MAX_TGT_INIT_RETRIES 3
  47. #define IBMVFC_DEV_LOSS_TMO (5 * 60)
  48. #define IBMVFC_DEFAULT_LOG_LEVEL 2
  49. #define IBMVFC_MAX_CDB_LEN 16
  50. /*
  51. * Ensure we have resources for ERP and initialization:
  52. * 1 for ERP
  53. * 1 for initialization
  54. * 2 for each discovery thread
  55. */
  56. #define IBMVFC_NUM_INTERNAL_REQ (1 + 1 + (disc_threads * 2))
  57. #define IBMVFC_MAD_SUCCESS 0x00
  58. #define IBMVFC_MAD_NOT_SUPPORTED 0xF1
  59. #define IBMVFC_MAD_FAILED 0xF7
  60. #define IBMVFC_MAD_DRIVER_FAILED 0xEE
  61. #define IBMVFC_MAD_CRQ_ERROR 0xEF
  62. enum ibmvfc_crq_valid {
  63. IBMVFC_CRQ_CMD_RSP = 0x80,
  64. IBMVFC_CRQ_INIT_RSP = 0xC0,
  65. IBMVFC_CRQ_XPORT_EVENT = 0xFF,
  66. };
  67. enum ibmvfc_crq_format {
  68. IBMVFC_CRQ_INIT = 0x01,
  69. IBMVFC_CRQ_INIT_COMPLETE = 0x02,
  70. IBMVFC_PARTITION_MIGRATED = 0x06,
  71. };
  72. enum ibmvfc_cmd_status_flags {
  73. IBMVFC_FABRIC_MAPPED = 0x0001,
  74. IBMVFC_VIOS_FAILURE = 0x0002,
  75. IBMVFC_FC_FAILURE = 0x0004,
  76. IBMVFC_FC_SCSI_ERROR = 0x0008,
  77. IBMVFC_HW_EVENT_LOGGED = 0x0010,
  78. IBMVFC_VIOS_LOGGED = 0x0020,
  79. };
  80. enum ibmvfc_fabric_mapped_errors {
  81. IBMVFC_UNABLE_TO_ESTABLISH = 0x0001,
  82. IBMVFC_XPORT_FAULT = 0x0002,
  83. IBMVFC_CMD_TIMEOUT = 0x0003,
  84. IBMVFC_ENETDOWN = 0x0004,
  85. IBMVFC_HW_FAILURE = 0x0005,
  86. IBMVFC_LINK_DOWN_ERR = 0x0006,
  87. IBMVFC_LINK_DEAD_ERR = 0x0007,
  88. IBMVFC_UNABLE_TO_REGISTER = 0x0008,
  89. IBMVFC_XPORT_BUSY = 0x000A,
  90. IBMVFC_XPORT_DEAD = 0x000B,
  91. IBMVFC_CONFIG_ERROR = 0x000C,
  92. IBMVFC_NAME_SERVER_FAIL = 0x000D,
  93. IBMVFC_LINK_HALTED = 0x000E,
  94. IBMVFC_XPORT_GENERAL = 0x8000,
  95. };
  96. enum ibmvfc_vios_errors {
  97. IBMVFC_CRQ_FAILURE = 0x0001,
  98. IBMVFC_SW_FAILURE = 0x0002,
  99. IBMVFC_INVALID_PARAMETER = 0x0003,
  100. IBMVFC_MISSING_PARAMETER = 0x0004,
  101. IBMVFC_HOST_IO_BUS = 0x0005,
  102. IBMVFC_TRANS_CANCELLED = 0x0006,
  103. IBMVFC_TRANS_CANCELLED_IMPLICIT = 0x0007,
  104. IBMVFC_INSUFFICIENT_RESOURCE = 0x0008,
  105. IBMVFC_PLOGI_REQUIRED = 0x0010,
  106. IBMVFC_COMMAND_FAILED = 0x8000,
  107. };
  108. enum ibmvfc_mad_types {
  109. IBMVFC_NPIV_LOGIN = 0x0001,
  110. IBMVFC_DISC_TARGETS = 0x0002,
  111. IBMVFC_PORT_LOGIN = 0x0004,
  112. IBMVFC_PROCESS_LOGIN = 0x0008,
  113. IBMVFC_QUERY_TARGET = 0x0010,
  114. IBMVFC_IMPLICIT_LOGOUT = 0x0040,
  115. IBMVFC_PASSTHRU = 0x0200,
  116. IBMVFC_TMF_MAD = 0x0100,
  117. };
  118. struct ibmvfc_mad_common {
  119. u32 version;
  120. u32 reserved;
  121. u32 opcode;
  122. u16 status;
  123. u16 length;
  124. u64 tag;
  125. }__attribute__((packed, aligned (8)));
  126. struct ibmvfc_npiv_login_mad {
  127. struct ibmvfc_mad_common common;
  128. struct srp_direct_buf buffer;
  129. }__attribute__((packed, aligned (8)));
  130. #define IBMVFC_MAX_NAME 256
  131. struct ibmvfc_npiv_login {
  132. u32 ostype;
  133. #define IBMVFC_OS_LINUX 0x02
  134. u32 pad;
  135. u64 max_dma_len;
  136. u32 max_payload;
  137. u32 max_response;
  138. u32 partition_num;
  139. u32 vfc_frame_version;
  140. u16 fcp_version;
  141. u16 flags;
  142. #define IBMVFC_CLIENT_MIGRATED 0x01
  143. #define IBMVFC_FLUSH_ON_HALT 0x02
  144. u32 max_cmds;
  145. u64 capabilities;
  146. #define IBMVFC_CAN_MIGRATE 0x01
  147. u64 node_name;
  148. struct srp_direct_buf async;
  149. u8 partition_name[IBMVFC_MAX_NAME];
  150. u8 device_name[IBMVFC_MAX_NAME];
  151. u8 drc_name[IBMVFC_MAX_NAME];
  152. u64 reserved2[2];
  153. }__attribute__((packed, aligned (8)));
  154. struct ibmvfc_common_svc_parms {
  155. u16 fcph_version;
  156. u16 b2b_credit;
  157. u16 features;
  158. u16 bb_rcv_sz; /* upper nibble is BB_SC_N */
  159. u32 ratov;
  160. u32 edtov;
  161. }__attribute__((packed, aligned (4)));
  162. struct ibmvfc_service_parms {
  163. struct ibmvfc_common_svc_parms common;
  164. u8 port_name[8];
  165. u8 node_name[8];
  166. u32 class1_parms[4];
  167. u32 class2_parms[4];
  168. u32 class3_parms[4];
  169. u32 obsolete[4];
  170. u32 vendor_version[4];
  171. u32 services_avail[2];
  172. u32 ext_len;
  173. u32 reserved[30];
  174. u32 clk_sync_qos[2];
  175. }__attribute__((packed, aligned (4)));
  176. struct ibmvfc_npiv_login_resp {
  177. u32 version;
  178. u16 status;
  179. u16 error;
  180. u32 flags;
  181. #define IBMVFC_NATIVE_FC 0x01
  182. #define IBMVFC_CAN_FLUSH_ON_HALT 0x08
  183. u32 reserved;
  184. u64 capabilites;
  185. u32 max_cmds;
  186. u32 scsi_id_sz;
  187. u64 max_dma_len;
  188. u64 scsi_id;
  189. u64 port_name;
  190. u64 node_name;
  191. u64 link_speed;
  192. u8 partition_name[IBMVFC_MAX_NAME];
  193. u8 device_name[IBMVFC_MAX_NAME];
  194. u8 port_loc_code[IBMVFC_MAX_NAME];
  195. u8 drc_name[IBMVFC_MAX_NAME];
  196. struct ibmvfc_service_parms service_parms;
  197. u64 reserved2;
  198. }__attribute__((packed, aligned (8)));
  199. union ibmvfc_npiv_login_data {
  200. struct ibmvfc_npiv_login login;
  201. struct ibmvfc_npiv_login_resp resp;
  202. }__attribute__((packed, aligned (8)));
  203. struct ibmvfc_discover_targets_buf {
  204. u32 scsi_id[1];
  205. #define IBMVFC_DISC_TGT_SCSI_ID_MASK 0x00ffffff
  206. };
  207. struct ibmvfc_discover_targets {
  208. struct ibmvfc_mad_common common;
  209. struct srp_direct_buf buffer;
  210. u32 flags;
  211. u16 status;
  212. u16 error;
  213. u32 bufflen;
  214. u32 num_avail;
  215. u32 num_written;
  216. u64 reserved[2];
  217. }__attribute__((packed, aligned (8)));
  218. enum ibmvfc_fc_reason {
  219. IBMVFC_INVALID_ELS_CMD_CODE = 0x01,
  220. IBMVFC_INVALID_VERSION = 0x02,
  221. IBMVFC_LOGICAL_ERROR = 0x03,
  222. IBMVFC_INVALID_CT_IU_SIZE = 0x04,
  223. IBMVFC_LOGICAL_BUSY = 0x05,
  224. IBMVFC_PROTOCOL_ERROR = 0x07,
  225. IBMVFC_UNABLE_TO_PERFORM_REQ = 0x09,
  226. IBMVFC_CMD_NOT_SUPPORTED = 0x0B,
  227. IBMVFC_SERVER_NOT_AVAIL = 0x0D,
  228. IBMVFC_CMD_IN_PROGRESS = 0x0E,
  229. IBMVFC_VENDOR_SPECIFIC = 0xFF,
  230. };
  231. enum ibmvfc_fc_type {
  232. IBMVFC_FABRIC_REJECT = 0x01,
  233. IBMVFC_PORT_REJECT = 0x02,
  234. IBMVFC_LS_REJECT = 0x03,
  235. IBMVFC_FABRIC_BUSY = 0x04,
  236. IBMVFC_PORT_BUSY = 0x05,
  237. IBMVFC_BASIC_REJECT = 0x06,
  238. };
  239. enum ibmvfc_gs_explain {
  240. IBMVFC_PORT_NAME_NOT_REG = 0x02,
  241. };
  242. struct ibmvfc_port_login {
  243. struct ibmvfc_mad_common common;
  244. u64 scsi_id;
  245. u16 reserved;
  246. u16 fc_service_class;
  247. u32 blksz;
  248. u32 hdr_per_blk;
  249. u16 status;
  250. u16 error; /* also fc_reason */
  251. u16 fc_explain;
  252. u16 fc_type;
  253. u32 reserved2;
  254. struct ibmvfc_service_parms service_parms;
  255. struct ibmvfc_service_parms service_parms_change;
  256. u64 reserved3[2];
  257. }__attribute__((packed, aligned (8)));
  258. struct ibmvfc_prli_svc_parms {
  259. u8 type;
  260. #define IBMVFC_SCSI_FCP_TYPE 0x08
  261. u8 type_ext;
  262. u16 flags;
  263. #define IBMVFC_PRLI_ORIG_PA_VALID 0x8000
  264. #define IBMVFC_PRLI_RESP_PA_VALID 0x4000
  265. #define IBMVFC_PRLI_EST_IMG_PAIR 0x2000
  266. u32 orig_pa;
  267. u32 resp_pa;
  268. u32 service_parms;
  269. #define IBMVFC_PRLI_TASK_RETRY 0x00000200
  270. #define IBMVFC_PRLI_RETRY 0x00000100
  271. #define IBMVFC_PRLI_DATA_OVERLAY 0x00000040
  272. #define IBMVFC_PRLI_INITIATOR_FUNC 0x00000020
  273. #define IBMVFC_PRLI_TARGET_FUNC 0x00000010
  274. #define IBMVFC_PRLI_READ_FCP_XFER_RDY_DISABLED 0x00000002
  275. #define IBMVFC_PRLI_WR_FCP_XFER_RDY_DISABLED 0x00000001
  276. }__attribute__((packed, aligned (4)));
  277. struct ibmvfc_process_login {
  278. struct ibmvfc_mad_common common;
  279. u64 scsi_id;
  280. struct ibmvfc_prli_svc_parms parms;
  281. u8 reserved[48];
  282. u16 status;
  283. u16 error; /* also fc_reason */
  284. u32 reserved2;
  285. u64 reserved3[2];
  286. }__attribute__((packed, aligned (8)));
  287. struct ibmvfc_query_tgt {
  288. struct ibmvfc_mad_common common;
  289. u64 wwpn;
  290. u64 scsi_id;
  291. u16 status;
  292. u16 error;
  293. u16 fc_explain;
  294. u16 fc_type;
  295. u64 reserved[2];
  296. }__attribute__((packed, aligned (8)));
  297. struct ibmvfc_implicit_logout {
  298. struct ibmvfc_mad_common common;
  299. u64 old_scsi_id;
  300. u64 reserved[2];
  301. }__attribute__((packed, aligned (8)));
  302. struct ibmvfc_tmf {
  303. struct ibmvfc_mad_common common;
  304. u64 scsi_id;
  305. struct scsi_lun lun;
  306. u32 flags;
  307. #define IBMVFC_TMF_ABORT_TASK 0x02
  308. #define IBMVFC_TMF_ABORT_TASK_SET 0x04
  309. #define IBMVFC_TMF_LUN_RESET 0x10
  310. #define IBMVFC_TMF_TGT_RESET 0x20
  311. #define IBMVFC_TMF_LUA_VALID 0x40
  312. u32 cancel_key;
  313. u32 my_cancel_key;
  314. u32 pad;
  315. u64 reserved[2];
  316. }__attribute__((packed, aligned (8)));
  317. enum ibmvfc_fcp_rsp_info_codes {
  318. RSP_NO_FAILURE = 0x00,
  319. RSP_TMF_REJECTED = 0x04,
  320. RSP_TMF_FAILED = 0x05,
  321. RSP_TMF_INVALID_LUN = 0x09,
  322. };
  323. struct ibmvfc_fcp_rsp_info {
  324. u16 reserved;
  325. u8 rsp_code;
  326. u8 reserved2[4];
  327. }__attribute__((packed, aligned (2)));
  328. enum ibmvfc_fcp_rsp_flags {
  329. FCP_BIDI_RSP = 0x80,
  330. FCP_BIDI_READ_RESID_UNDER = 0x40,
  331. FCP_BIDI_READ_RESID_OVER = 0x20,
  332. FCP_CONF_REQ = 0x10,
  333. FCP_RESID_UNDER = 0x08,
  334. FCP_RESID_OVER = 0x04,
  335. FCP_SNS_LEN_VALID = 0x02,
  336. FCP_RSP_LEN_VALID = 0x01,
  337. };
  338. union ibmvfc_fcp_rsp_data {
  339. struct ibmvfc_fcp_rsp_info info;
  340. u8 sense[SCSI_SENSE_BUFFERSIZE + sizeof(struct ibmvfc_fcp_rsp_info)];
  341. }__attribute__((packed, aligned (8)));
  342. struct ibmvfc_fcp_rsp {
  343. u64 reserved;
  344. u16 retry_delay_timer;
  345. u8 flags;
  346. u8 scsi_status;
  347. u32 fcp_resid;
  348. u32 fcp_sense_len;
  349. u32 fcp_rsp_len;
  350. union ibmvfc_fcp_rsp_data data;
  351. }__attribute__((packed, aligned (8)));
  352. enum ibmvfc_cmd_flags {
  353. IBMVFC_SCATTERLIST = 0x0001,
  354. IBMVFC_NO_MEM_DESC = 0x0002,
  355. IBMVFC_READ = 0x0004,
  356. IBMVFC_WRITE = 0x0008,
  357. IBMVFC_TMF = 0x0080,
  358. IBMVFC_CLASS_3_ERR = 0x0100,
  359. };
  360. enum ibmvfc_fc_task_attr {
  361. IBMVFC_SIMPLE_TASK = 0x00,
  362. IBMVFC_HEAD_OF_QUEUE = 0x01,
  363. IBMVFC_ORDERED_TASK = 0x02,
  364. IBMVFC_ACA_TASK = 0x04,
  365. };
  366. enum ibmvfc_fc_tmf_flags {
  367. IBMVFC_ABORT_TASK_SET = 0x02,
  368. IBMVFC_LUN_RESET = 0x10,
  369. IBMVFC_TARGET_RESET = 0x20,
  370. };
  371. struct ibmvfc_fcp_cmd_iu {
  372. struct scsi_lun lun;
  373. u8 crn;
  374. u8 pri_task_attr;
  375. u8 tmf_flags;
  376. u8 add_cdb_len;
  377. #define IBMVFC_RDDATA 0x02
  378. #define IBMVFC_WRDATA 0x01
  379. u8 cdb[IBMVFC_MAX_CDB_LEN];
  380. u32 xfer_len;
  381. }__attribute__((packed, aligned (4)));
  382. struct ibmvfc_cmd {
  383. u64 task_tag;
  384. u32 frame_type;
  385. u32 payload_len;
  386. u32 resp_len;
  387. u32 adapter_resid;
  388. u16 status;
  389. u16 error;
  390. u16 flags;
  391. u16 response_flags;
  392. #define IBMVFC_ADAPTER_RESID_VALID 0x01
  393. u32 cancel_key;
  394. u32 exchange_id;
  395. struct srp_direct_buf ext_func;
  396. struct srp_direct_buf ioba;
  397. struct srp_direct_buf resp;
  398. u64 correlation;
  399. u64 tgt_scsi_id;
  400. u64 tag;
  401. u64 reserved3[2];
  402. struct ibmvfc_fcp_cmd_iu iu;
  403. struct ibmvfc_fcp_rsp rsp;
  404. }__attribute__((packed, aligned (8)));
  405. struct ibmvfc_passthru_fc_iu {
  406. u32 payload[7];
  407. #define IBMVFC_ADISC 0x52000000
  408. u32 response[7];
  409. };
  410. struct ibmvfc_passthru_iu {
  411. u64 task_tag;
  412. u32 cmd_len;
  413. u32 rsp_len;
  414. u16 status;
  415. u16 error;
  416. u32 flags;
  417. #define IBMVFC_FC_ELS 0x01
  418. u32 cancel_key;
  419. u32 reserved;
  420. struct srp_direct_buf cmd;
  421. struct srp_direct_buf rsp;
  422. u64 correlation;
  423. u64 scsi_id;
  424. u64 tag;
  425. u64 reserved2[2];
  426. }__attribute__((packed, aligned (8)));
  427. struct ibmvfc_passthru_mad {
  428. struct ibmvfc_mad_common common;
  429. struct srp_direct_buf cmd_ioba;
  430. struct ibmvfc_passthru_iu iu;
  431. struct ibmvfc_passthru_fc_iu fc_iu;
  432. }__attribute__((packed, aligned (8)));
  433. struct ibmvfc_trace_start_entry {
  434. u32 xfer_len;
  435. }__attribute__((packed));
  436. struct ibmvfc_trace_end_entry {
  437. u16 status;
  438. u16 error;
  439. u8 fcp_rsp_flags;
  440. u8 rsp_code;
  441. u8 scsi_status;
  442. u8 reserved;
  443. }__attribute__((packed));
  444. struct ibmvfc_trace_entry {
  445. struct ibmvfc_event *evt;
  446. u32 time;
  447. u32 scsi_id;
  448. u32 lun;
  449. u8 fmt;
  450. u8 op_code;
  451. u8 tmf_flags;
  452. u8 type;
  453. #define IBMVFC_TRC_START 0x00
  454. #define IBMVFC_TRC_END 0xff
  455. union {
  456. struct ibmvfc_trace_start_entry start;
  457. struct ibmvfc_trace_end_entry end;
  458. } u;
  459. }__attribute__((packed, aligned (8)));
  460. enum ibmvfc_crq_formats {
  461. IBMVFC_CMD_FORMAT = 0x01,
  462. IBMVFC_ASYNC_EVENT = 0x02,
  463. IBMVFC_MAD_FORMAT = 0x04,
  464. };
  465. enum ibmvfc_async_event {
  466. IBMVFC_AE_ELS_PLOGI = 0x0001,
  467. IBMVFC_AE_ELS_LOGO = 0x0002,
  468. IBMVFC_AE_ELS_PRLO = 0x0004,
  469. IBMVFC_AE_SCN_NPORT = 0x0008,
  470. IBMVFC_AE_SCN_GROUP = 0x0010,
  471. IBMVFC_AE_SCN_DOMAIN = 0x0020,
  472. IBMVFC_AE_SCN_FABRIC = 0x0040,
  473. IBMVFC_AE_LINK_UP = 0x0080,
  474. IBMVFC_AE_LINK_DOWN = 0x0100,
  475. IBMVFC_AE_LINK_DEAD = 0x0200,
  476. IBMVFC_AE_HALT = 0x0400,
  477. IBMVFC_AE_RESUME = 0x0800,
  478. IBMVFC_AE_ADAPTER_FAILED = 0x1000,
  479. };
  480. struct ibmvfc_crq {
  481. volatile u8 valid;
  482. volatile u8 format;
  483. u8 reserved[6];
  484. volatile u64 ioba;
  485. }__attribute__((packed, aligned (8)));
  486. struct ibmvfc_crq_queue {
  487. struct ibmvfc_crq *msgs;
  488. int size, cur;
  489. dma_addr_t msg_token;
  490. };
  491. struct ibmvfc_async_crq {
  492. volatile u8 valid;
  493. u8 pad[3];
  494. u32 pad2;
  495. volatile u64 event;
  496. volatile u64 scsi_id;
  497. volatile u64 wwpn;
  498. volatile u64 node_name;
  499. u64 reserved;
  500. }__attribute__((packed, aligned (8)));
  501. struct ibmvfc_async_crq_queue {
  502. struct ibmvfc_async_crq *msgs;
  503. int size, cur;
  504. dma_addr_t msg_token;
  505. };
  506. union ibmvfc_iu {
  507. struct ibmvfc_mad_common mad_common;
  508. struct ibmvfc_npiv_login_mad npiv_login;
  509. struct ibmvfc_discover_targets discover_targets;
  510. struct ibmvfc_port_login plogi;
  511. struct ibmvfc_process_login prli;
  512. struct ibmvfc_query_tgt query_tgt;
  513. struct ibmvfc_implicit_logout implicit_logout;
  514. struct ibmvfc_tmf tmf;
  515. struct ibmvfc_cmd cmd;
  516. struct ibmvfc_passthru_mad passthru;
  517. }__attribute__((packed, aligned (8)));
  518. enum ibmvfc_target_action {
  519. IBMVFC_TGT_ACTION_NONE = 0,
  520. IBMVFC_TGT_ACTION_INIT,
  521. IBMVFC_TGT_ACTION_INIT_WAIT,
  522. IBMVFC_TGT_ACTION_ADD_RPORT,
  523. IBMVFC_TGT_ACTION_DEL_RPORT,
  524. };
  525. struct ibmvfc_target {
  526. struct list_head queue;
  527. struct ibmvfc_host *vhost;
  528. u64 scsi_id;
  529. u64 new_scsi_id;
  530. struct fc_rport *rport;
  531. int target_id;
  532. enum ibmvfc_target_action action;
  533. int need_login;
  534. int init_retries;
  535. u32 cancel_key;
  536. struct ibmvfc_service_parms service_parms;
  537. struct ibmvfc_service_parms service_parms_change;
  538. struct fc_rport_identifiers ids;
  539. void (*job_step) (struct ibmvfc_target *);
  540. struct timer_list timer;
  541. struct kref kref;
  542. };
  543. /* a unit of work for the hosting partition */
  544. struct ibmvfc_event {
  545. struct list_head queue;
  546. struct ibmvfc_host *vhost;
  547. struct ibmvfc_target *tgt;
  548. struct scsi_cmnd *cmnd;
  549. atomic_t free;
  550. union ibmvfc_iu *xfer_iu;
  551. void (*done) (struct ibmvfc_event *);
  552. struct ibmvfc_crq crq;
  553. union ibmvfc_iu iu;
  554. union ibmvfc_iu *sync_iu;
  555. struct srp_direct_buf *ext_list;
  556. dma_addr_t ext_list_token;
  557. struct completion comp;
  558. struct completion *eh_comp;
  559. struct timer_list timer;
  560. };
  561. /* a pool of event structs for use */
  562. struct ibmvfc_event_pool {
  563. struct ibmvfc_event *events;
  564. u32 size;
  565. union ibmvfc_iu *iu_storage;
  566. dma_addr_t iu_token;
  567. };
  568. enum ibmvfc_host_action {
  569. IBMVFC_HOST_ACTION_NONE = 0,
  570. IBMVFC_HOST_ACTION_INIT,
  571. IBMVFC_HOST_ACTION_INIT_WAIT,
  572. IBMVFC_HOST_ACTION_QUERY,
  573. IBMVFC_HOST_ACTION_QUERY_TGTS,
  574. IBMVFC_HOST_ACTION_TGT_DEL,
  575. IBMVFC_HOST_ACTION_ALLOC_TGTS,
  576. IBMVFC_HOST_ACTION_TGT_INIT,
  577. IBMVFC_HOST_ACTION_TGT_DEL_FAILED,
  578. IBMVFC_HOST_ACTION_TGT_ADD,
  579. };
  580. enum ibmvfc_host_state {
  581. IBMVFC_NO_CRQ = 0,
  582. IBMVFC_INITIALIZING,
  583. IBMVFC_ACTIVE,
  584. IBMVFC_HALTED,
  585. IBMVFC_LINK_DOWN,
  586. IBMVFC_LINK_DEAD,
  587. IBMVFC_HOST_OFFLINE,
  588. };
  589. struct ibmvfc_host {
  590. char name[8];
  591. struct list_head queue;
  592. struct Scsi_Host *host;
  593. enum ibmvfc_host_state state;
  594. enum ibmvfc_host_action action;
  595. #define IBMVFC_NUM_TRACE_INDEX_BITS 8
  596. #define IBMVFC_NUM_TRACE_ENTRIES (1 << IBMVFC_NUM_TRACE_INDEX_BITS)
  597. #define IBMVFC_TRACE_SIZE (sizeof(struct ibmvfc_trace_entry) * IBMVFC_NUM_TRACE_ENTRIES)
  598. struct ibmvfc_trace_entry *trace;
  599. u32 trace_index:IBMVFC_NUM_TRACE_INDEX_BITS;
  600. int num_targets;
  601. struct list_head targets;
  602. struct list_head sent;
  603. struct list_head free;
  604. struct device *dev;
  605. struct ibmvfc_event_pool pool;
  606. struct dma_pool *sg_pool;
  607. mempool_t *tgt_pool;
  608. struct ibmvfc_crq_queue crq;
  609. struct ibmvfc_async_crq_queue async_crq;
  610. struct ibmvfc_npiv_login login_info;
  611. union ibmvfc_npiv_login_data *login_buf;
  612. dma_addr_t login_buf_dma;
  613. int disc_buf_sz;
  614. int log_level;
  615. struct ibmvfc_discover_targets_buf *disc_buf;
  616. int task_set;
  617. int init_retries;
  618. int discovery_threads;
  619. int abort_threads;
  620. int client_migrated;
  621. int reinit;
  622. int delay_init;
  623. int events_to_log;
  624. #define IBMVFC_AE_LINKUP 0x0001
  625. #define IBMVFC_AE_LINKDOWN 0x0002
  626. #define IBMVFC_AE_RSCN 0x0004
  627. dma_addr_t disc_buf_dma;
  628. unsigned int partition_number;
  629. char partition_name[97];
  630. void (*job_step) (struct ibmvfc_host *);
  631. struct task_struct *work_thread;
  632. struct tasklet_struct tasklet;
  633. wait_queue_head_t init_wait_q;
  634. wait_queue_head_t work_wait_q;
  635. };
  636. #define DBG_CMD(CMD) do { if (ibmvfc_debug) CMD; } while (0)
  637. #define tgt_dbg(t, fmt, ...) \
  638. DBG_CMD(dev_info((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__))
  639. #define tgt_info(t, fmt, ...) \
  640. dev_info((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
  641. #define tgt_err(t, fmt, ...) \
  642. dev_err((t)->vhost->dev, "%llX: " fmt, (t)->scsi_id, ##__VA_ARGS__)
  643. #define ibmvfc_dbg(vhost, ...) \
  644. DBG_CMD(dev_info((vhost)->dev, ##__VA_ARGS__))
  645. #define ibmvfc_log(vhost, level, ...) \
  646. do { \
  647. if ((vhost)->log_level >= level) \
  648. dev_err((vhost)->dev, ##__VA_ARGS__); \
  649. } while (0)
  650. #define ENTER DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Entering %s\n", __func__))
  651. #define LEAVE DBG_CMD(printk(KERN_INFO IBMVFC_NAME": Leaving %s\n", __func__))
  652. #ifdef CONFIG_SCSI_IBMVFC_TRACE
  653. #define ibmvfc_create_trace_file(kobj, attr) sysfs_create_bin_file(kobj, attr)
  654. #define ibmvfc_remove_trace_file(kobj, attr) sysfs_remove_bin_file(kobj, attr)
  655. #else
  656. #define ibmvfc_create_trace_file(kobj, attr) 0
  657. #define ibmvfc_remove_trace_file(kobj, attr) do { } while (0)
  658. #endif
  659. #endif