ibmvfc.h 18 KB

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