ibmvfc.h 19 KB

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