ibmvfc.h 17 KB

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