qla_target.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  1. /*
  2. * Copyright (C) 2004 - 2010 Vladislav Bolkhovitin <vst@vlnb.net>
  3. * Copyright (C) 2004 - 2005 Leonid Stoljar
  4. * Copyright (C) 2006 Nathaniel Clark <nate@misrule.us>
  5. * Copyright (C) 2007 - 2010 ID7 Ltd.
  6. *
  7. * Forward port and refactoring to modern qla2xxx and target/configfs
  8. *
  9. * Copyright (C) 2010-2011 Nicholas A. Bellinger <nab@kernel.org>
  10. *
  11. * Additional file for the target driver support.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License
  15. * as published by the Free Software Foundation; either version 2
  16. * of the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. */
  23. /*
  24. * This is the global def file that is useful for including from the
  25. * target portion.
  26. */
  27. #ifndef __QLA_TARGET_H
  28. #define __QLA_TARGET_H
  29. #include "qla_def.h"
  30. /*
  31. * Must be changed on any change in any initiator visible interfaces or
  32. * data in the target add-on
  33. */
  34. #define QLA2XXX_TARGET_MAGIC 269
  35. /*
  36. * Must be changed on any change in any target visible interfaces or
  37. * data in the initiator
  38. */
  39. #define QLA2XXX_INITIATOR_MAGIC 57222
  40. #define QLA2XXX_INI_MODE_STR_EXCLUSIVE "exclusive"
  41. #define QLA2XXX_INI_MODE_STR_DISABLED "disabled"
  42. #define QLA2XXX_INI_MODE_STR_ENABLED "enabled"
  43. #define QLA2XXX_INI_MODE_EXCLUSIVE 0
  44. #define QLA2XXX_INI_MODE_DISABLED 1
  45. #define QLA2XXX_INI_MODE_ENABLED 2
  46. #define QLA2XXX_COMMAND_COUNT_INIT 250
  47. #define QLA2XXX_IMMED_NOTIFY_COUNT_INIT 250
  48. /*
  49. * Used to mark which completion handles (for RIO Status's) are for CTIO's
  50. * vs. regular (non-target) info. This is checked for in
  51. * qla2x00_process_response_queue() to see if a handle coming back in a
  52. * multi-complete should come to the tgt driver or be handled there by qla2xxx
  53. */
  54. #define CTIO_COMPLETION_HANDLE_MARK BIT_29
  55. #if (CTIO_COMPLETION_HANDLE_MARK <= DEFAULT_OUTSTANDING_COMMANDS)
  56. #error "CTIO_COMPLETION_HANDLE_MARK not larger than "
  57. "DEFAULT_OUTSTANDING_COMMANDS"
  58. #endif
  59. #define HANDLE_IS_CTIO_COMP(h) (h & CTIO_COMPLETION_HANDLE_MARK)
  60. /* Used to mark CTIO as intermediate */
  61. #define CTIO_INTERMEDIATE_HANDLE_MARK BIT_30
  62. #ifndef OF_SS_MODE_0
  63. /*
  64. * ISP target entries - Flags bit definitions.
  65. */
  66. #define OF_SS_MODE_0 0
  67. #define OF_SS_MODE_1 1
  68. #define OF_SS_MODE_2 2
  69. #define OF_SS_MODE_3 3
  70. #define OF_EXPL_CONF BIT_5 /* Explicit Confirmation Requested */
  71. #define OF_DATA_IN BIT_6 /* Data in to initiator */
  72. /* (data from target to initiator) */
  73. #define OF_DATA_OUT BIT_7 /* Data out from initiator */
  74. /* (data from initiator to target) */
  75. #define OF_NO_DATA (BIT_7 | BIT_6)
  76. #define OF_INC_RC BIT_8 /* Increment command resource count */
  77. #define OF_FAST_POST BIT_9 /* Enable mailbox fast posting. */
  78. #define OF_CONF_REQ BIT_13 /* Confirmation Requested */
  79. #define OF_TERM_EXCH BIT_14 /* Terminate exchange */
  80. #define OF_SSTS BIT_15 /* Send SCSI status */
  81. #endif
  82. #ifndef QLA_TGT_DATASEGS_PER_CMD32
  83. #define QLA_TGT_DATASEGS_PER_CMD32 3
  84. #define QLA_TGT_DATASEGS_PER_CONT32 7
  85. #define QLA_TGT_MAX_SG32(ql) \
  86. (((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD32 + \
  87. QLA_TGT_DATASEGS_PER_CONT32*((ql) - 1)) : 0)
  88. #define QLA_TGT_DATASEGS_PER_CMD64 2
  89. #define QLA_TGT_DATASEGS_PER_CONT64 5
  90. #define QLA_TGT_MAX_SG64(ql) \
  91. (((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD64 + \
  92. QLA_TGT_DATASEGS_PER_CONT64*((ql) - 1)) : 0)
  93. #endif
  94. #ifndef QLA_TGT_DATASEGS_PER_CMD_24XX
  95. #define QLA_TGT_DATASEGS_PER_CMD_24XX 1
  96. #define QLA_TGT_DATASEGS_PER_CONT_24XX 5
  97. #define QLA_TGT_MAX_SG_24XX(ql) \
  98. (min(1270, ((ql) > 0) ? (QLA_TGT_DATASEGS_PER_CMD_24XX + \
  99. QLA_TGT_DATASEGS_PER_CONT_24XX*((ql) - 1)) : 0))
  100. #endif
  101. #endif
  102. #define GET_TARGET_ID(ha, iocb) ((HAS_EXTENDED_IDS(ha)) \
  103. ? le16_to_cpu((iocb)->u.isp2x.target.extended) \
  104. : (uint16_t)(iocb)->u.isp2x.target.id.standard)
  105. #ifndef IMMED_NOTIFY_TYPE
  106. #define IMMED_NOTIFY_TYPE 0x0D /* Immediate notify entry. */
  107. /*
  108. * ISP queue - immediate notify entry structure definition.
  109. * This is sent by the ISP to the Target driver.
  110. * This IOCB would have report of events sent by the
  111. * initiator, that needs to be handled by the target
  112. * driver immediately.
  113. */
  114. struct imm_ntfy_from_isp {
  115. uint8_t entry_type; /* Entry type. */
  116. uint8_t entry_count; /* Entry count. */
  117. uint8_t sys_define; /* System defined. */
  118. uint8_t entry_status; /* Entry Status. */
  119. union {
  120. struct {
  121. uint32_t sys_define_2; /* System defined. */
  122. target_id_t target;
  123. uint16_t lun;
  124. uint8_t target_id;
  125. uint8_t reserved_1;
  126. uint16_t status_modifier;
  127. uint16_t status;
  128. uint16_t task_flags;
  129. uint16_t seq_id;
  130. uint16_t srr_rx_id;
  131. uint32_t srr_rel_offs;
  132. uint16_t srr_ui;
  133. #define SRR_IU_DATA_IN 0x1
  134. #define SRR_IU_DATA_OUT 0x5
  135. #define SRR_IU_STATUS 0x7
  136. uint16_t srr_ox_id;
  137. uint8_t reserved_2[28];
  138. } isp2x;
  139. struct {
  140. uint32_t reserved;
  141. uint16_t nport_handle;
  142. uint16_t reserved_2;
  143. uint16_t flags;
  144. #define NOTIFY24XX_FLAGS_GLOBAL_TPRLO BIT_1
  145. #define NOTIFY24XX_FLAGS_PUREX_IOCB BIT_0
  146. uint16_t srr_rx_id;
  147. uint16_t status;
  148. uint8_t status_subcode;
  149. uint8_t fw_handle;
  150. uint32_t exchange_address;
  151. uint32_t srr_rel_offs;
  152. uint16_t srr_ui;
  153. uint16_t srr_ox_id;
  154. union {
  155. struct {
  156. uint8_t node_name[8];
  157. } plogi; /* PLOGI/ADISC/PDISC */
  158. struct {
  159. /* PRLI word 3 bit 0-15 */
  160. uint16_t wd3_lo;
  161. uint8_t resv0[6];
  162. } prli;
  163. struct {
  164. uint8_t port_id[3];
  165. uint8_t resv1;
  166. uint16_t nport_handle;
  167. uint16_t resv2;
  168. } req_els;
  169. } u;
  170. uint8_t port_name[8];
  171. uint8_t resv3[3];
  172. uint8_t vp_index;
  173. uint32_t reserved_5;
  174. uint8_t port_id[3];
  175. uint8_t reserved_6;
  176. } isp24;
  177. } u;
  178. uint16_t reserved_7;
  179. uint16_t ox_id;
  180. } __packed;
  181. #endif
  182. #ifndef NOTIFY_ACK_TYPE
  183. #define NOTIFY_ACK_TYPE 0x0E /* Notify acknowledge entry. */
  184. /*
  185. * ISP queue - notify acknowledge entry structure definition.
  186. * This is sent to the ISP from the target driver.
  187. */
  188. struct nack_to_isp {
  189. uint8_t entry_type; /* Entry type. */
  190. uint8_t entry_count; /* Entry count. */
  191. uint8_t sys_define; /* System defined. */
  192. uint8_t entry_status; /* Entry Status. */
  193. union {
  194. struct {
  195. uint32_t sys_define_2; /* System defined. */
  196. target_id_t target;
  197. uint8_t target_id;
  198. uint8_t reserved_1;
  199. uint16_t flags;
  200. uint16_t resp_code;
  201. uint16_t status;
  202. uint16_t task_flags;
  203. uint16_t seq_id;
  204. uint16_t srr_rx_id;
  205. uint32_t srr_rel_offs;
  206. uint16_t srr_ui;
  207. uint16_t srr_flags;
  208. uint16_t srr_reject_code;
  209. uint8_t srr_reject_vendor_uniq;
  210. uint8_t srr_reject_code_expl;
  211. uint8_t reserved_2[24];
  212. } isp2x;
  213. struct {
  214. uint32_t handle;
  215. uint16_t nport_handle;
  216. uint16_t reserved_1;
  217. uint16_t flags;
  218. uint16_t srr_rx_id;
  219. uint16_t status;
  220. uint8_t status_subcode;
  221. uint8_t fw_handle;
  222. uint32_t exchange_address;
  223. uint32_t srr_rel_offs;
  224. uint16_t srr_ui;
  225. uint16_t srr_flags;
  226. uint8_t reserved_4[19];
  227. uint8_t vp_index;
  228. uint8_t srr_reject_vendor_uniq;
  229. uint8_t srr_reject_code_expl;
  230. uint8_t srr_reject_code;
  231. uint8_t reserved_5[5];
  232. } isp24;
  233. } u;
  234. uint8_t reserved[2];
  235. uint16_t ox_id;
  236. } __packed;
  237. #define NOTIFY_ACK_FLAGS_TERMINATE BIT_3
  238. #define NOTIFY_ACK_SRR_FLAGS_ACCEPT 0
  239. #define NOTIFY_ACK_SRR_FLAGS_REJECT 1
  240. #define NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM 0x9
  241. #define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL 0
  242. #define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_UNABLE_TO_SUPPLY_DATA 0x2a
  243. #define NOTIFY_ACK_SUCCESS 0x01
  244. #endif
  245. #ifndef ACCEPT_TGT_IO_TYPE
  246. #define ACCEPT_TGT_IO_TYPE 0x16 /* Accept target I/O entry. */
  247. #endif
  248. #ifndef CONTINUE_TGT_IO_TYPE
  249. #define CONTINUE_TGT_IO_TYPE 0x17
  250. /*
  251. * ISP queue - Continue Target I/O (CTIO) entry for status mode 0 structure.
  252. * This structure is sent to the ISP 2xxx from target driver.
  253. */
  254. struct ctio_to_2xxx {
  255. uint8_t entry_type; /* Entry type. */
  256. uint8_t entry_count; /* Entry count. */
  257. uint8_t sys_define; /* System defined. */
  258. uint8_t entry_status; /* Entry Status. */
  259. uint32_t handle; /* System defined handle */
  260. target_id_t target;
  261. uint16_t rx_id;
  262. uint16_t flags;
  263. uint16_t status;
  264. uint16_t timeout; /* 0 = 30 seconds, 0xFFFF = disable */
  265. uint16_t dseg_count; /* Data segment count. */
  266. uint32_t relative_offset;
  267. uint32_t residual;
  268. uint16_t reserved_1[3];
  269. uint16_t scsi_status;
  270. uint32_t transfer_length;
  271. uint32_t dseg_0_address; /* Data segment 0 address. */
  272. uint32_t dseg_0_length; /* Data segment 0 length. */
  273. uint32_t dseg_1_address; /* Data segment 1 address. */
  274. uint32_t dseg_1_length; /* Data segment 1 length. */
  275. uint32_t dseg_2_address; /* Data segment 2 address. */
  276. uint32_t dseg_2_length; /* Data segment 2 length. */
  277. } __packed;
  278. #define ATIO_PATH_INVALID 0x07
  279. #define ATIO_CANT_PROV_CAP 0x16
  280. #define ATIO_CDB_VALID 0x3D
  281. #define ATIO_EXEC_READ BIT_1
  282. #define ATIO_EXEC_WRITE BIT_0
  283. #endif
  284. #ifndef CTIO_A64_TYPE
  285. #define CTIO_A64_TYPE 0x1F
  286. #define CTIO_SUCCESS 0x01
  287. #define CTIO_ABORTED 0x02
  288. #define CTIO_INVALID_RX_ID 0x08
  289. #define CTIO_TIMEOUT 0x0B
  290. #define CTIO_DIF_ERROR 0x0C /* DIF error detected */
  291. #define CTIO_LIP_RESET 0x0E
  292. #define CTIO_TARGET_RESET 0x17
  293. #define CTIO_PORT_UNAVAILABLE 0x28
  294. #define CTIO_PORT_LOGGED_OUT 0x29
  295. #define CTIO_PORT_CONF_CHANGED 0x2A
  296. #define CTIO_SRR_RECEIVED 0x45
  297. #endif
  298. #ifndef CTIO_RET_TYPE
  299. #define CTIO_RET_TYPE 0x17 /* CTIO return entry */
  300. #define ATIO_TYPE7 0x06 /* Accept target I/O entry for 24xx */
  301. struct fcp_hdr {
  302. uint8_t r_ctl;
  303. uint8_t d_id[3];
  304. uint8_t cs_ctl;
  305. uint8_t s_id[3];
  306. uint8_t type;
  307. uint8_t f_ctl[3];
  308. uint8_t seq_id;
  309. uint8_t df_ctl;
  310. uint16_t seq_cnt;
  311. __be16 ox_id;
  312. uint16_t rx_id;
  313. uint32_t parameter;
  314. } __packed;
  315. struct fcp_hdr_le {
  316. uint8_t d_id[3];
  317. uint8_t r_ctl;
  318. uint8_t s_id[3];
  319. uint8_t cs_ctl;
  320. uint8_t f_ctl[3];
  321. uint8_t type;
  322. uint16_t seq_cnt;
  323. uint8_t df_ctl;
  324. uint8_t seq_id;
  325. uint16_t rx_id;
  326. uint16_t ox_id;
  327. uint32_t parameter;
  328. } __packed;
  329. #define F_CTL_EXCH_CONTEXT_RESP BIT_23
  330. #define F_CTL_SEQ_CONTEXT_RESIP BIT_22
  331. #define F_CTL_LAST_SEQ BIT_20
  332. #define F_CTL_END_SEQ BIT_19
  333. #define F_CTL_SEQ_INITIATIVE BIT_16
  334. #define R_CTL_BASIC_LINK_SERV 0x80
  335. #define R_CTL_B_ACC 0x4
  336. #define R_CTL_B_RJT 0x5
  337. struct atio7_fcp_cmnd {
  338. uint64_t lun;
  339. uint8_t cmnd_ref;
  340. uint8_t task_attr:3;
  341. uint8_t reserved:5;
  342. uint8_t task_mgmt_flags;
  343. #define FCP_CMND_TASK_MGMT_CLEAR_ACA 6
  344. #define FCP_CMND_TASK_MGMT_TARGET_RESET 5
  345. #define FCP_CMND_TASK_MGMT_LU_RESET 4
  346. #define FCP_CMND_TASK_MGMT_CLEAR_TASK_SET 2
  347. #define FCP_CMND_TASK_MGMT_ABORT_TASK_SET 1
  348. uint8_t wrdata:1;
  349. uint8_t rddata:1;
  350. uint8_t add_cdb_len:6;
  351. uint8_t cdb[16];
  352. /*
  353. * add_cdb is optional and can absent from struct atio7_fcp_cmnd. Size 4
  354. * only to make sizeof(struct atio7_fcp_cmnd) be as expected by
  355. * BUILD_BUG_ON in qlt_init().
  356. */
  357. uint8_t add_cdb[4];
  358. /* uint32_t data_length; */
  359. } __packed;
  360. /*
  361. * ISP queue - Accept Target I/O (ATIO) type entry IOCB structure.
  362. * This is sent from the ISP to the target driver.
  363. */
  364. struct atio_from_isp {
  365. union {
  366. struct {
  367. uint16_t entry_hdr;
  368. uint8_t sys_define; /* System defined. */
  369. uint8_t entry_status; /* Entry Status. */
  370. uint32_t sys_define_2; /* System defined. */
  371. target_id_t target;
  372. uint16_t rx_id;
  373. uint16_t flags;
  374. uint16_t status;
  375. uint8_t command_ref;
  376. uint8_t task_codes;
  377. uint8_t task_flags;
  378. uint8_t execution_codes;
  379. uint8_t cdb[MAX_CMDSZ];
  380. uint32_t data_length;
  381. uint16_t lun;
  382. uint8_t initiator_port_name[WWN_SIZE]; /* on qla23xx */
  383. uint16_t reserved_32[6];
  384. uint16_t ox_id;
  385. } isp2x;
  386. struct {
  387. uint16_t entry_hdr;
  388. uint8_t fcp_cmnd_len_low;
  389. uint8_t fcp_cmnd_len_high:4;
  390. uint8_t attr:4;
  391. uint32_t exchange_addr;
  392. #define ATIO_EXCHANGE_ADDRESS_UNKNOWN 0xFFFFFFFF
  393. struct fcp_hdr fcp_hdr;
  394. struct atio7_fcp_cmnd fcp_cmnd;
  395. } isp24;
  396. struct {
  397. uint8_t entry_type; /* Entry type. */
  398. uint8_t entry_count; /* Entry count. */
  399. __le16 attr_n_length;
  400. #define FCP_CMD_LENGTH_MASK 0x0fff
  401. #define FCP_CMD_LENGTH_MIN 0x38
  402. uint8_t data[56];
  403. uint32_t signature;
  404. #define ATIO_PROCESSED 0xDEADDEAD /* Signature */
  405. } raw;
  406. } u;
  407. } __packed;
  408. static inline int fcpcmd_is_corrupted(struct atio *atio)
  409. {
  410. if (atio->entry_type == ATIO_TYPE7 &&
  411. (le16_to_cpu(atio->attr_n_length & FCP_CMD_LENGTH_MASK) <
  412. FCP_CMD_LENGTH_MIN))
  413. return 1;
  414. else
  415. return 0;
  416. }
  417. /* adjust corrupted atio so we won't trip over the same entry again. */
  418. static inline void adjust_corrupted_atio(struct atio_from_isp *atio)
  419. {
  420. atio->u.raw.attr_n_length = cpu_to_le16(FCP_CMD_LENGTH_MIN);
  421. atio->u.isp24.fcp_cmnd.add_cdb_len = 0;
  422. }
  423. #define CTIO_TYPE7 0x12 /* Continue target I/O entry (for 24xx) */
  424. /*
  425. * ISP queue - Continue Target I/O (ATIO) type 7 entry (for 24xx) structure.
  426. * This structure is sent to the ISP 24xx from the target driver.
  427. */
  428. struct ctio7_to_24xx {
  429. uint8_t entry_type; /* Entry type. */
  430. uint8_t entry_count; /* Entry count. */
  431. uint8_t sys_define; /* System defined. */
  432. uint8_t entry_status; /* Entry Status. */
  433. uint32_t handle; /* System defined handle */
  434. uint16_t nport_handle;
  435. #define CTIO7_NHANDLE_UNRECOGNIZED 0xFFFF
  436. uint16_t timeout;
  437. uint16_t dseg_count; /* Data segment count. */
  438. uint8_t vp_index;
  439. uint8_t add_flags;
  440. uint8_t initiator_id[3];
  441. uint8_t reserved;
  442. uint32_t exchange_addr;
  443. union {
  444. struct {
  445. uint16_t reserved1;
  446. __le16 flags;
  447. uint32_t residual;
  448. __le16 ox_id;
  449. uint16_t scsi_status;
  450. uint32_t relative_offset;
  451. uint32_t reserved2;
  452. uint32_t transfer_length;
  453. uint32_t reserved3;
  454. /* Data segment 0 address. */
  455. uint32_t dseg_0_address[2];
  456. /* Data segment 0 length. */
  457. uint32_t dseg_0_length;
  458. } status0;
  459. struct {
  460. uint16_t sense_length;
  461. uint16_t flags;
  462. uint32_t residual;
  463. __le16 ox_id;
  464. uint16_t scsi_status;
  465. uint16_t response_len;
  466. uint16_t reserved;
  467. uint8_t sense_data[24];
  468. } status1;
  469. } u;
  470. } __packed;
  471. /*
  472. * ISP queue - CTIO type 7 from ISP 24xx to target driver
  473. * returned entry structure.
  474. */
  475. struct ctio7_from_24xx {
  476. uint8_t entry_type; /* Entry type. */
  477. uint8_t entry_count; /* Entry count. */
  478. uint8_t sys_define; /* System defined. */
  479. uint8_t entry_status; /* Entry Status. */
  480. uint32_t handle; /* System defined handle */
  481. uint16_t status;
  482. uint16_t timeout;
  483. uint16_t dseg_count; /* Data segment count. */
  484. uint8_t vp_index;
  485. uint8_t reserved1[5];
  486. uint32_t exchange_address;
  487. uint16_t reserved2;
  488. uint16_t flags;
  489. uint32_t residual;
  490. uint16_t ox_id;
  491. uint16_t reserved3;
  492. uint32_t relative_offset;
  493. uint8_t reserved4[24];
  494. } __packed;
  495. /* CTIO7 flags values */
  496. #define CTIO7_FLAGS_SEND_STATUS BIT_15
  497. #define CTIO7_FLAGS_TERMINATE BIT_14
  498. #define CTIO7_FLAGS_CONFORM_REQ BIT_13
  499. #define CTIO7_FLAGS_DONT_RET_CTIO BIT_8
  500. #define CTIO7_FLAGS_STATUS_MODE_0 0
  501. #define CTIO7_FLAGS_STATUS_MODE_1 BIT_6
  502. #define CTIO7_FLAGS_STATUS_MODE_2 BIT_7
  503. #define CTIO7_FLAGS_EXPLICIT_CONFORM BIT_5
  504. #define CTIO7_FLAGS_CONFIRM_SATISF BIT_4
  505. #define CTIO7_FLAGS_DSD_PTR BIT_2
  506. #define CTIO7_FLAGS_DATA_IN BIT_1 /* data to initiator */
  507. #define CTIO7_FLAGS_DATA_OUT BIT_0 /* data from initiator */
  508. #define ELS_PLOGI 0x3
  509. #define ELS_FLOGI 0x4
  510. #define ELS_LOGO 0x5
  511. #define ELS_PRLI 0x20
  512. #define ELS_PRLO 0x21
  513. #define ELS_TPRLO 0x24
  514. #define ELS_PDISC 0x50
  515. #define ELS_ADISC 0x52
  516. /*
  517. *CTIO Type CRC_2 IOCB
  518. */
  519. struct ctio_crc2_to_fw {
  520. uint8_t entry_type; /* Entry type. */
  521. #define CTIO_CRC2 0x7A
  522. uint8_t entry_count; /* Entry count. */
  523. uint8_t sys_define; /* System defined. */
  524. uint8_t entry_status; /* Entry Status. */
  525. uint32_t handle; /* System handle. */
  526. uint16_t nport_handle; /* N_PORT handle. */
  527. __le16 timeout; /* Command timeout. */
  528. uint16_t dseg_count; /* Data segment count. */
  529. uint8_t vp_index;
  530. uint8_t add_flags; /* additional flags */
  531. #define CTIO_CRC2_AF_DIF_DSD_ENA BIT_3
  532. uint8_t initiator_id[3]; /* initiator ID */
  533. uint8_t reserved1;
  534. uint32_t exchange_addr; /* rcv exchange address */
  535. uint16_t reserved2;
  536. __le16 flags; /* refer to CTIO7 flags values */
  537. uint32_t residual;
  538. __le16 ox_id;
  539. uint16_t scsi_status;
  540. __le32 relative_offset;
  541. uint32_t reserved5;
  542. __le32 transfer_length; /* total fc transfer length */
  543. uint32_t reserved6;
  544. __le32 crc_context_address[2];/* Data segment address. */
  545. uint16_t crc_context_len; /* Data segment length. */
  546. uint16_t reserved_1; /* MUST be set to 0. */
  547. } __packed;
  548. /* CTIO Type CRC_x Status IOCB */
  549. struct ctio_crc_from_fw {
  550. uint8_t entry_type; /* Entry type. */
  551. uint8_t entry_count; /* Entry count. */
  552. uint8_t sys_define; /* System defined. */
  553. uint8_t entry_status; /* Entry Status. */
  554. uint32_t handle; /* System handle. */
  555. uint16_t status;
  556. uint16_t timeout; /* Command timeout. */
  557. uint16_t dseg_count; /* Data segment count. */
  558. uint32_t reserved1;
  559. uint16_t state_flags;
  560. #define CTIO_CRC_SF_DIF_CHOPPED BIT_4
  561. uint32_t exchange_address; /* rcv exchange address */
  562. uint16_t reserved2;
  563. uint16_t flags;
  564. uint32_t resid_xfer_length;
  565. uint16_t ox_id;
  566. uint8_t reserved3[12];
  567. uint16_t runt_guard; /* reported runt blk guard */
  568. uint8_t actual_dif[8];
  569. uint8_t expected_dif[8];
  570. } __packed;
  571. /*
  572. * ISP queue - ABTS received/response entries structure definition for 24xx.
  573. */
  574. #define ABTS_RECV_24XX 0x54 /* ABTS received (for 24xx) */
  575. #define ABTS_RESP_24XX 0x55 /* ABTS responce (for 24xx) */
  576. /*
  577. * ISP queue - ABTS received IOCB entry structure definition for 24xx.
  578. * The ABTS BLS received from the wire is sent to the
  579. * target driver by the ISP 24xx.
  580. * The IOCB is placed on the response queue.
  581. */
  582. struct abts_recv_from_24xx {
  583. uint8_t entry_type; /* Entry type. */
  584. uint8_t entry_count; /* Entry count. */
  585. uint8_t sys_define; /* System defined. */
  586. uint8_t entry_status; /* Entry Status. */
  587. uint8_t reserved_1[6];
  588. uint16_t nport_handle;
  589. uint8_t reserved_2[2];
  590. uint8_t vp_index;
  591. uint8_t reserved_3:4;
  592. uint8_t sof_type:4;
  593. uint32_t exchange_address;
  594. struct fcp_hdr_le fcp_hdr_le;
  595. uint8_t reserved_4[16];
  596. uint32_t exchange_addr_to_abort;
  597. } __packed;
  598. #define ABTS_PARAM_ABORT_SEQ BIT_0
  599. struct ba_acc_le {
  600. uint16_t reserved;
  601. uint8_t seq_id_last;
  602. uint8_t seq_id_valid;
  603. #define SEQ_ID_VALID 0x80
  604. #define SEQ_ID_INVALID 0x00
  605. uint16_t rx_id;
  606. uint16_t ox_id;
  607. uint16_t high_seq_cnt;
  608. uint16_t low_seq_cnt;
  609. } __packed;
  610. struct ba_rjt_le {
  611. uint8_t vendor_uniq;
  612. uint8_t reason_expl;
  613. uint8_t reason_code;
  614. #define BA_RJT_REASON_CODE_INVALID_COMMAND 0x1
  615. #define BA_RJT_REASON_CODE_UNABLE_TO_PERFORM 0x9
  616. uint8_t reserved;
  617. } __packed;
  618. /*
  619. * ISP queue - ABTS Response IOCB entry structure definition for 24xx.
  620. * The ABTS response to the ABTS received is sent by the
  621. * target driver to the ISP 24xx.
  622. * The IOCB is placed on the request queue.
  623. */
  624. struct abts_resp_to_24xx {
  625. uint8_t entry_type; /* Entry type. */
  626. uint8_t entry_count; /* Entry count. */
  627. uint8_t sys_define; /* System defined. */
  628. uint8_t entry_status; /* Entry Status. */
  629. uint32_t handle;
  630. uint16_t reserved_1;
  631. uint16_t nport_handle;
  632. uint16_t control_flags;
  633. #define ABTS_CONTR_FLG_TERM_EXCHG BIT_0
  634. uint8_t vp_index;
  635. uint8_t reserved_3:4;
  636. uint8_t sof_type:4;
  637. uint32_t exchange_address;
  638. struct fcp_hdr_le fcp_hdr_le;
  639. union {
  640. struct ba_acc_le ba_acct;
  641. struct ba_rjt_le ba_rjt;
  642. } __packed payload;
  643. uint32_t reserved_4;
  644. uint32_t exchange_addr_to_abort;
  645. } __packed;
  646. /*
  647. * ISP queue - ABTS Response IOCB from ISP24xx Firmware entry structure.
  648. * The ABTS response with completion status to the ABTS response
  649. * (sent by the target driver to the ISP 24xx) is sent by the
  650. * ISP24xx firmware to the target driver.
  651. * The IOCB is placed on the response queue.
  652. */
  653. struct abts_resp_from_24xx_fw {
  654. uint8_t entry_type; /* Entry type. */
  655. uint8_t entry_count; /* Entry count. */
  656. uint8_t sys_define; /* System defined. */
  657. uint8_t entry_status; /* Entry Status. */
  658. uint32_t handle;
  659. uint16_t compl_status;
  660. #define ABTS_RESP_COMPL_SUCCESS 0
  661. #define ABTS_RESP_COMPL_SUBCODE_ERROR 0x31
  662. uint16_t nport_handle;
  663. uint16_t reserved_1;
  664. uint8_t reserved_2;
  665. uint8_t reserved_3:4;
  666. uint8_t sof_type:4;
  667. uint32_t exchange_address;
  668. struct fcp_hdr_le fcp_hdr_le;
  669. uint8_t reserved_4[8];
  670. uint32_t error_subcode1;
  671. #define ABTS_RESP_SUBCODE_ERR_ABORTED_EXCH_NOT_TERM 0x1E
  672. uint32_t error_subcode2;
  673. uint32_t exchange_addr_to_abort;
  674. } __packed;
  675. /********************************************************************\
  676. * Type Definitions used by initiator & target halves
  677. \********************************************************************/
  678. struct qla_tgt_mgmt_cmd;
  679. struct qla_tgt_sess;
  680. /*
  681. * This structure provides a template of function calls that the
  682. * target driver (from within qla_target.c) can issue to the
  683. * target module (tcm_qla2xxx).
  684. */
  685. struct qla_tgt_func_tmpl {
  686. int (*handle_cmd)(struct scsi_qla_host *, struct qla_tgt_cmd *,
  687. unsigned char *, uint32_t, int, int, int);
  688. void (*handle_data)(struct qla_tgt_cmd *);
  689. void (*handle_dif_err)(struct qla_tgt_cmd *);
  690. int (*handle_tmr)(struct qla_tgt_mgmt_cmd *, uint32_t, uint8_t,
  691. uint32_t);
  692. void (*free_cmd)(struct qla_tgt_cmd *);
  693. void (*free_mcmd)(struct qla_tgt_mgmt_cmd *);
  694. void (*free_session)(struct qla_tgt_sess *);
  695. int (*check_initiator_node_acl)(struct scsi_qla_host *, unsigned char *,
  696. struct qla_tgt_sess *);
  697. void (*update_sess)(struct qla_tgt_sess *, port_id_t, uint16_t, bool);
  698. struct qla_tgt_sess *(*find_sess_by_loop_id)(struct scsi_qla_host *,
  699. const uint16_t);
  700. struct qla_tgt_sess *(*find_sess_by_s_id)(struct scsi_qla_host *,
  701. const uint8_t *);
  702. void (*clear_nacl_from_fcport_map)(struct qla_tgt_sess *);
  703. void (*shutdown_sess)(struct qla_tgt_sess *);
  704. };
  705. int qla2x00_wait_for_hba_online(struct scsi_qla_host *);
  706. #include <target/target_core_base.h>
  707. #define QLA_TGT_TIMEOUT 10 /* in seconds */
  708. #define QLA_TGT_MAX_HW_PENDING_TIME 60 /* in seconds */
  709. /* Immediate notify status constants */
  710. #define IMM_NTFY_LIP_RESET 0x000E
  711. #define IMM_NTFY_LIP_LINK_REINIT 0x000F
  712. #define IMM_NTFY_IOCB_OVERFLOW 0x0016
  713. #define IMM_NTFY_ABORT_TASK 0x0020
  714. #define IMM_NTFY_PORT_LOGOUT 0x0029
  715. #define IMM_NTFY_PORT_CONFIG 0x002A
  716. #define IMM_NTFY_GLBL_TPRLO 0x002D
  717. #define IMM_NTFY_GLBL_LOGO 0x002E
  718. #define IMM_NTFY_RESOURCE 0x0034
  719. #define IMM_NTFY_MSG_RX 0x0036
  720. #define IMM_NTFY_SRR 0x0045
  721. #define IMM_NTFY_ELS 0x0046
  722. /* Immediate notify task flags */
  723. #define IMM_NTFY_TASK_MGMT_SHIFT 8
  724. #define QLA_TGT_CLEAR_ACA 0x40
  725. #define QLA_TGT_TARGET_RESET 0x20
  726. #define QLA_TGT_LUN_RESET 0x10
  727. #define QLA_TGT_CLEAR_TS 0x04
  728. #define QLA_TGT_ABORT_TS 0x02
  729. #define QLA_TGT_ABORT_ALL_SESS 0xFFFF
  730. #define QLA_TGT_ABORT_ALL 0xFFFE
  731. #define QLA_TGT_NEXUS_LOSS_SESS 0xFFFD
  732. #define QLA_TGT_NEXUS_LOSS 0xFFFC
  733. /* Notify Acknowledge flags */
  734. #define NOTIFY_ACK_RES_COUNT BIT_8
  735. #define NOTIFY_ACK_CLEAR_LIP_RESET BIT_5
  736. #define NOTIFY_ACK_TM_RESP_CODE_VALID BIT_4
  737. /* Command's states */
  738. #define QLA_TGT_STATE_NEW 0 /* New command + target processing */
  739. #define QLA_TGT_STATE_NEED_DATA 1 /* target needs data to continue */
  740. #define QLA_TGT_STATE_DATA_IN 2 /* Data arrived + target processing */
  741. #define QLA_TGT_STATE_PROCESSED 3 /* target done processing */
  742. /* Special handles */
  743. #define QLA_TGT_NULL_HANDLE 0
  744. #define QLA_TGT_SKIP_HANDLE (0xFFFFFFFF & ~CTIO_COMPLETION_HANDLE_MARK)
  745. /* ATIO task_codes field */
  746. #define ATIO_SIMPLE_QUEUE 0
  747. #define ATIO_HEAD_OF_QUEUE 1
  748. #define ATIO_ORDERED_QUEUE 2
  749. #define ATIO_ACA_QUEUE 4
  750. #define ATIO_UNTAGGED 5
  751. /* TM failed response codes, see FCP (9.4.11 FCP_RSP_INFO) */
  752. #define FC_TM_SUCCESS 0
  753. #define FC_TM_BAD_FCP_DATA 1
  754. #define FC_TM_BAD_CMD 2
  755. #define FC_TM_FCP_DATA_MISMATCH 3
  756. #define FC_TM_REJECT 4
  757. #define FC_TM_FAILED 5
  758. #if (BITS_PER_LONG > 32) || defined(CONFIG_HIGHMEM64G)
  759. #define pci_dma_lo32(a) (a & 0xffffffff)
  760. #define pci_dma_hi32(a) ((((a) >> 16)>>16) & 0xffffffff)
  761. #else
  762. #define pci_dma_lo32(a) (a & 0xffffffff)
  763. #define pci_dma_hi32(a) 0
  764. #endif
  765. #define QLA_TGT_SENSE_VALID(sense) ((sense != NULL) && \
  766. (((const uint8_t *)(sense))[0] & 0x70) == 0x70)
  767. struct qla_port_24xx_data {
  768. uint8_t port_name[WWN_SIZE];
  769. uint16_t loop_id;
  770. uint16_t reserved;
  771. };
  772. struct qla_tgt {
  773. struct scsi_qla_host *vha;
  774. struct qla_hw_data *ha;
  775. /*
  776. * To sync between IRQ handlers and qlt_target_release(). Needed,
  777. * because req_pkt() can drop/reaquire HW lock inside. Protected by
  778. * HW lock.
  779. */
  780. int irq_cmd_count;
  781. int atio_irq_cmd_count;
  782. int datasegs_per_cmd, datasegs_per_cont, sg_tablesize;
  783. /* Target's flags, serialized by pha->hardware_lock */
  784. unsigned int tgt_enable_64bit_addr:1; /* 64-bits PCI addr enabled */
  785. unsigned int link_reinit_iocb_pending:1;
  786. /*
  787. * Protected by tgt_mutex AND hardware_lock for writing and tgt_mutex
  788. * OR hardware_lock for reading.
  789. */
  790. int tgt_stop; /* the target mode driver is being stopped */
  791. int tgt_stopped; /* the target mode driver has been stopped */
  792. /* Count of sessions refering qla_tgt. Protected by hardware_lock. */
  793. int sess_count;
  794. /* Protected by hardware_lock. Addition also protected by tgt_mutex. */
  795. struct list_head sess_list;
  796. /* Protected by hardware_lock */
  797. struct list_head del_sess_list;
  798. struct delayed_work sess_del_work;
  799. spinlock_t sess_work_lock;
  800. struct list_head sess_works_list;
  801. struct work_struct sess_work;
  802. struct imm_ntfy_from_isp link_reinit_iocb;
  803. wait_queue_head_t waitQ;
  804. int notify_ack_expected;
  805. int abts_resp_expected;
  806. int modify_lun_expected;
  807. int ctio_srr_id;
  808. int imm_srr_id;
  809. spinlock_t srr_lock;
  810. struct list_head srr_ctio_list;
  811. struct list_head srr_imm_list;
  812. struct work_struct srr_work;
  813. atomic_t tgt_global_resets_count;
  814. struct list_head tgt_list_entry;
  815. };
  816. struct qla_tgt_sess_op {
  817. struct scsi_qla_host *vha;
  818. uint32_t chip_reset;
  819. struct atio_from_isp atio;
  820. struct work_struct work;
  821. struct list_head cmd_list;
  822. bool aborted;
  823. };
  824. enum qla_sess_deletion {
  825. QLA_SESS_DELETION_NONE = 0,
  826. QLA_SESS_DELETION_PENDING = 1, /* hopefully we can get rid of
  827. * this one */
  828. QLA_SESS_DELETION_IN_PROGRESS = 2,
  829. };
  830. typedef enum {
  831. QLT_PLOGI_LINK_SAME_WWN,
  832. QLT_PLOGI_LINK_CONFLICT,
  833. QLT_PLOGI_LINK_MAX
  834. } qlt_plogi_link_t;
  835. typedef struct {
  836. struct list_head list;
  837. struct imm_ntfy_from_isp iocb;
  838. port_id_t id;
  839. int ref_count;
  840. } qlt_plogi_ack_t;
  841. /*
  842. * Equivilant to IT Nexus (Initiator-Target)
  843. */
  844. struct qla_tgt_sess {
  845. uint16_t loop_id;
  846. port_id_t s_id;
  847. unsigned int conf_compl_supported:1;
  848. unsigned int deleted:2;
  849. unsigned int local:1;
  850. unsigned int logout_on_delete:1;
  851. unsigned int keep_nport_handle:1;
  852. unsigned int send_els_logo:1;
  853. unsigned char logout_completed;
  854. int generation;
  855. struct se_session *se_sess;
  856. struct kref sess_kref;
  857. struct scsi_qla_host *vha;
  858. struct qla_tgt *tgt;
  859. struct list_head sess_list_entry;
  860. unsigned long expires;
  861. struct list_head del_list_entry;
  862. uint8_t port_name[WWN_SIZE];
  863. struct work_struct free_work;
  864. qlt_plogi_ack_t *plogi_link[QLT_PLOGI_LINK_MAX];
  865. };
  866. typedef enum {
  867. /*
  868. * BIT_0 - Atio Arrival / schedule to work
  869. * BIT_1 - qlt_do_work
  870. * BIT_2 - qlt_do work failed
  871. * BIT_3 - xfer rdy/tcm_qla2xxx_write_pending
  872. * BIT_4 - read respond/tcm_qla2xx_queue_data_in
  873. * BIT_5 - status respond / tcm_qla2xx_queue_status
  874. * BIT_6 - tcm request to abort/Term exchange.
  875. * pre_xmit_response->qlt_send_term_exchange
  876. * BIT_7 - SRR received (qlt_handle_srr->qlt_xmit_response)
  877. * BIT_8 - SRR received (qlt_handle_srr->qlt_rdy_to_xfer)
  878. * BIT_9 - SRR received (qla_handle_srr->qlt_send_term_exchange)
  879. * BIT_10 - Data in - hanlde_data->tcm_qla2xxx_handle_data
  880. * BIT_12 - good completion - qlt_ctio_do_completion -->free_cmd
  881. * BIT_13 - Bad completion -
  882. * qlt_ctio_do_completion --> qlt_term_ctio_exchange
  883. * BIT_14 - Back end data received/sent.
  884. * BIT_15 - SRR prepare ctio
  885. * BIT_16 - complete free
  886. * BIT_17 - flush - qlt_abort_cmd_on_host_reset
  887. * BIT_18 - completion w/abort status
  888. * BIT_19 - completion w/unknown status
  889. * BIT_20 - tcm_qla2xxx_free_cmd
  890. */
  891. CMD_FLAG_DATA_WORK = BIT_11,
  892. CMD_FLAG_DATA_WORK_FREE = BIT_21,
  893. } cmd_flags_t;
  894. struct qla_tgt_cmd {
  895. struct se_cmd se_cmd;
  896. struct qla_tgt_sess *sess;
  897. int state;
  898. struct work_struct free_work;
  899. struct work_struct work;
  900. /* Sense buffer that will be mapped into outgoing status */
  901. unsigned char sense_buffer[TRANSPORT_SENSE_BUFFER];
  902. spinlock_t cmd_lock;
  903. /* to save extra sess dereferences */
  904. unsigned int conf_compl_supported:1;
  905. unsigned int sg_mapped:1;
  906. unsigned int free_sg:1;
  907. unsigned int write_data_transferred:1;
  908. unsigned int ctx_dsd_alloced:1;
  909. unsigned int q_full:1;
  910. unsigned int term_exchg:1;
  911. unsigned int cmd_sent_to_fw:1;
  912. unsigned int cmd_in_wq:1;
  913. unsigned int aborted:1;
  914. struct scatterlist *sg; /* cmd data buffer SG vector */
  915. int sg_cnt; /* SG segments count */
  916. int bufflen; /* cmd buffer length */
  917. int offset;
  918. uint32_t unpacked_lun;
  919. enum dma_data_direction dma_data_direction;
  920. uint32_t reset_count;
  921. uint16_t loop_id; /* to save extra sess dereferences */
  922. struct qla_tgt *tgt; /* to save extra sess dereferences */
  923. struct scsi_qla_host *vha;
  924. struct list_head cmd_list;
  925. struct atio_from_isp atio;
  926. /* t10dif */
  927. struct scatterlist *prot_sg;
  928. uint32_t prot_sg_cnt;
  929. uint32_t blk_sz;
  930. struct crc_context *ctx;
  931. uint64_t jiffies_at_alloc;
  932. uint64_t jiffies_at_free;
  933. cmd_flags_t cmd_flags;
  934. };
  935. struct qla_tgt_sess_work_param {
  936. struct list_head sess_works_list_entry;
  937. #define QLA_TGT_SESS_WORK_ABORT 1
  938. #define QLA_TGT_SESS_WORK_TM 2
  939. int type;
  940. union {
  941. struct abts_recv_from_24xx abts;
  942. struct imm_ntfy_from_isp tm_iocb;
  943. struct atio_from_isp tm_iocb2;
  944. };
  945. };
  946. struct qla_tgt_mgmt_cmd {
  947. uint8_t tmr_func;
  948. uint8_t fc_tm_rsp;
  949. struct qla_tgt_sess *sess;
  950. struct se_cmd se_cmd;
  951. struct work_struct free_work;
  952. unsigned int flags;
  953. uint32_t reset_count;
  954. #define QLA24XX_MGMT_SEND_NACK 1
  955. union {
  956. struct atio_from_isp atio;
  957. struct imm_ntfy_from_isp imm_ntfy;
  958. struct abts_recv_from_24xx abts;
  959. } __packed orig_iocb;
  960. };
  961. struct qla_tgt_prm {
  962. struct qla_tgt_cmd *cmd;
  963. struct qla_tgt *tgt;
  964. void *pkt;
  965. struct scatterlist *sg; /* cmd data buffer SG vector */
  966. unsigned char *sense_buffer;
  967. int seg_cnt;
  968. int req_cnt;
  969. uint16_t rq_result;
  970. uint16_t scsi_status;
  971. int sense_buffer_len;
  972. int residual;
  973. int add_status_pkt;
  974. /* dif */
  975. struct scatterlist *prot_sg;
  976. uint16_t prot_seg_cnt;
  977. uint16_t tot_dsds;
  978. };
  979. struct qla_tgt_srr_imm {
  980. struct list_head srr_list_entry;
  981. int srr_id;
  982. struct imm_ntfy_from_isp imm_ntfy;
  983. };
  984. struct qla_tgt_srr_ctio {
  985. struct list_head srr_list_entry;
  986. int srr_id;
  987. struct qla_tgt_cmd *cmd;
  988. };
  989. /* Check for Switch reserved address */
  990. #define IS_SW_RESV_ADDR(_s_id) \
  991. ((_s_id.b.domain == 0xff) && (_s_id.b.area == 0xfc))
  992. #define QLA_TGT_XMIT_DATA 1
  993. #define QLA_TGT_XMIT_STATUS 2
  994. #define QLA_TGT_XMIT_ALL (QLA_TGT_XMIT_STATUS|QLA_TGT_XMIT_DATA)
  995. extern struct qla_tgt_data qla_target;
  996. /*
  997. * Function prototypes for qla_target.c logic used by qla2xxx LLD code.
  998. */
  999. extern int qlt_add_target(struct qla_hw_data *, struct scsi_qla_host *);
  1000. extern int qlt_remove_target(struct qla_hw_data *, struct scsi_qla_host *);
  1001. extern int qlt_lport_register(void *, u64, u64, u64,
  1002. int (*callback)(struct scsi_qla_host *, void *, u64, u64));
  1003. extern void qlt_lport_deregister(struct scsi_qla_host *);
  1004. void qlt_put_sess(struct qla_tgt_sess *sess);
  1005. extern void qlt_fc_port_added(struct scsi_qla_host *, fc_port_t *);
  1006. extern void qlt_fc_port_deleted(struct scsi_qla_host *, fc_port_t *, int);
  1007. extern int __init qlt_init(void);
  1008. extern void qlt_exit(void);
  1009. extern void qlt_update_vp_map(struct scsi_qla_host *, int);
  1010. /*
  1011. * This macro is used during early initializations when host->active_mode
  1012. * is not set. Right now, ha value is ignored.
  1013. */
  1014. #define QLA_TGT_MODE_ENABLED() (ql2x_ini_mode != QLA2XXX_INI_MODE_ENABLED)
  1015. extern int ql2x_ini_mode;
  1016. static inline bool qla_tgt_mode_enabled(struct scsi_qla_host *ha)
  1017. {
  1018. return ha->host->active_mode & MODE_TARGET;
  1019. }
  1020. static inline bool qla_ini_mode_enabled(struct scsi_qla_host *ha)
  1021. {
  1022. return ha->host->active_mode & MODE_INITIATOR;
  1023. }
  1024. static inline void qla_reverse_ini_mode(struct scsi_qla_host *ha)
  1025. {
  1026. if (ha->host->active_mode & MODE_INITIATOR)
  1027. ha->host->active_mode &= ~MODE_INITIATOR;
  1028. else
  1029. ha->host->active_mode |= MODE_INITIATOR;
  1030. }
  1031. static inline uint32_t sid_to_key(const uint8_t *s_id)
  1032. {
  1033. uint32_t key;
  1034. key = (((unsigned long)s_id[0] << 16) |
  1035. ((unsigned long)s_id[1] << 8) |
  1036. (unsigned long)s_id[2]);
  1037. return key;
  1038. }
  1039. static inline void sid_to_portid(const uint8_t *s_id, port_id_t *p)
  1040. {
  1041. memset(p, 0, sizeof(*p));
  1042. p->b.domain = s_id[0];
  1043. p->b.area = s_id[1];
  1044. p->b.al_pa = s_id[2];
  1045. }
  1046. /*
  1047. * Exported symbols from qla_target.c LLD logic used by qla2xxx code..
  1048. */
  1049. extern void qlt_response_pkt_all_vps(struct scsi_qla_host *, response_t *);
  1050. extern int qlt_rdy_to_xfer(struct qla_tgt_cmd *);
  1051. extern int qlt_xmit_response(struct qla_tgt_cmd *, int, uint8_t);
  1052. extern int qlt_abort_cmd(struct qla_tgt_cmd *);
  1053. extern void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *);
  1054. extern void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *);
  1055. extern void qlt_free_cmd(struct qla_tgt_cmd *cmd);
  1056. extern void qlt_async_event(uint16_t, struct scsi_qla_host *, uint16_t *);
  1057. extern void qlt_enable_vha(struct scsi_qla_host *);
  1058. extern void qlt_vport_create(struct scsi_qla_host *, struct qla_hw_data *);
  1059. extern void qlt_rff_id(struct scsi_qla_host *, struct ct_sns_req *);
  1060. extern void qlt_init_atio_q_entries(struct scsi_qla_host *);
  1061. extern void qlt_24xx_process_atio_queue(struct scsi_qla_host *, uint8_t);
  1062. extern void qlt_24xx_config_rings(struct scsi_qla_host *);
  1063. extern void qlt_24xx_config_nvram_stage1(struct scsi_qla_host *,
  1064. struct nvram_24xx *);
  1065. extern void qlt_24xx_config_nvram_stage2(struct scsi_qla_host *,
  1066. struct init_cb_24xx *);
  1067. extern void qlt_81xx_config_nvram_stage2(struct scsi_qla_host *,
  1068. struct init_cb_81xx *);
  1069. extern void qlt_81xx_config_nvram_stage1(struct scsi_qla_host *,
  1070. struct nvram_81xx *);
  1071. extern int qlt_24xx_process_response_error(struct scsi_qla_host *,
  1072. struct sts_entry_24xx *);
  1073. extern void qlt_modify_vp_config(struct scsi_qla_host *,
  1074. struct vp_config_entry_24xx *);
  1075. extern void qlt_probe_one_stage1(struct scsi_qla_host *, struct qla_hw_data *);
  1076. extern int qlt_mem_alloc(struct qla_hw_data *);
  1077. extern void qlt_mem_free(struct qla_hw_data *);
  1078. extern int qlt_stop_phase1(struct qla_tgt *);
  1079. extern void qlt_stop_phase2(struct qla_tgt *);
  1080. extern irqreturn_t qla83xx_msix_atio_q(int, void *);
  1081. extern void qlt_83xx_iospace_config(struct qla_hw_data *);
  1082. extern int qlt_free_qfull_cmds(struct scsi_qla_host *);
  1083. extern void qlt_logo_completion_handler(fc_port_t *, int);
  1084. extern void qlt_do_generation_tick(struct scsi_qla_host *, int *);
  1085. #endif /* __QLA_TARGET_H */