ibmvfc.h 17 KB

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