isp_tpublic.h revision 1.19 1 1.19 mjacob /* $NetBSD: isp_tpublic.h,v 1.19 2010/01/03 02:47:09 mjacob Exp $ */
2 1.16 mjacob /*-
3 1.16 mjacob * Copyright (c) 1997-2008 by Matthew Jacob
4 1.16 mjacob * All rights reserved.
5 1.16 mjacob *
6 1.16 mjacob * Redistribution and use in source and binary forms, with or without
7 1.16 mjacob * modification, are permitted provided that the following conditions
8 1.16 mjacob * are met:
9 1.15 mjacob *
10 1.16 mjacob * 1. Redistributions of source code must retain the above copyright
11 1.16 mjacob * notice, this list of conditions and the following disclaimer.
12 1.16 mjacob * 2. Redistributions in binary form must reproduce the above copyright
13 1.16 mjacob * notice, this list of conditions and the following disclaimer in the
14 1.16 mjacob * documentation and/or other materials provided with the distribution.
15 1.15 mjacob *
16 1.16 mjacob * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.16 mjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.16 mjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.16 mjacob * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.16 mjacob * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.16 mjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.16 mjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.16 mjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.16 mjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.16 mjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.16 mjacob * SUCH DAMAGE.
27 1.1 mjacob */
28 1.15 mjacob /*
29 1.15 mjacob * Host Adapter Public Target Interface Structures && Routines
30 1.15 mjacob */
31 1.16 mjacob /*
32 1.16 mjacob * A note about terminology:
33 1.16 mjacob *
34 1.16 mjacob * "Inner Layer" means this driver (isp and the isp_tpublic API).
35 1.16 mjacob *
36 1.16 mjacob * This module includes the both generic and platform specific pieces.
37 1.16 mjacob *
38 1.16 mjacob * "Outer Layer" means another (external) module.
39 1.16 mjacob *
40 1.16 mjacob * This is an additional module that actually implements SCSI target command
41 1.16 mjacob * decode and is the recipient of incoming commands and the source of the
42 1.16 mjacob * disposition for them.
43 1.16 mjacob */
44 1.15 mjacob
45 1.15 mjacob #ifndef _ISP_TPUBLIC_H
46 1.15 mjacob #define _ISP_TPUBLIC_H 1
47 1.18 mjacob /*
48 1.18 mjacob * Include general target definitions
49 1.18 mjacob */
50 1.18 mjacob #include "isp_target.h"
51 1.15 mjacob
52 1.15 mjacob /*
53 1.16 mjacob * Action codes set by the Inner Layer for the outer layer to figure out what to do with.
54 1.15 mjacob */
55 1.15 mjacob typedef enum {
56 1.15 mjacob QOUT_HBA_REG=0, /* the argument is a pointer to a hba_register_t */
57 1.15 mjacob QOUT_ENABLE, /* the argument is a pointer to a enadis_t */
58 1.15 mjacob QOUT_DISABLE, /* the argument is a pointer to a enadis_t */
59 1.15 mjacob QOUT_TMD_START, /* the argument is a pointer to a tmd_cmd_t */
60 1.16 mjacob QOUT_TMD_DONE, /* the argument is a pointer to a tmd_xact_t */
61 1.19 mjacob QOUT_NOTIFY, /* the argument is a pointer to a notify_t */
62 1.15 mjacob QOUT_HBA_UNREG /* the argument is a pointer to a hba_register_t */
63 1.15 mjacob } tact_e;
64 1.15 mjacob
65 1.15 mjacob /*
66 1.16 mjacob * Action codes set by the outer layer for the
67 1.16 mjacob * inner layer to figure out what to do with.
68 1.15 mjacob */
69 1.15 mjacob typedef enum {
70 1.15 mjacob QIN_HBA_REG=99, /* the argument is a pointer to a hba_register_t */
71 1.15 mjacob QIN_GETINFO, /* the argument is a pointer to a info_t */
72 1.15 mjacob QIN_SETINFO, /* the argument is a pointer to a info_t */
73 1.15 mjacob QIN_GETDLIST, /* the argument is a pointer to a fc_dlist_t */
74 1.15 mjacob QIN_ENABLE, /* the argument is a pointer to a enadis_t */
75 1.15 mjacob QIN_DISABLE, /* the argument is a pointer to a enadis_t */
76 1.16 mjacob QIN_TMD_CONT, /* the argument is a pointer to a tmd_xact_t */
77 1.15 mjacob QIN_TMD_FIN, /* the argument is a pointer to a tmd_cmd_t */
78 1.19 mjacob QIN_NOTIFY_ACK, /* the argument is a pointer to a notify_t */
79 1.15 mjacob QIN_HBA_UNREG, /* the argument is a pointer to a hba_register_t */
80 1.15 mjacob } qact_e;
81 1.15 mjacob
82 1.15 mjacob /*
83 1.16 mjacob * This structure is used to register to the outer layer the
84 1.15 mjacob * binding of an HBA identifier, driver name and instance and the
85 1.16 mjacob * lun width capapbilities of this inner layer. It's up to each
86 1.16 mjacob * platform to figure out how it wants to actually implement this.
87 1.16 mjacob * A typical sequence would be for the MD layer to find some external
88 1.16 mjacob * module's entry point and start by sending a QOUT_HBA_REG with info
89 1.16 mjacob * filled in, and the external module to call back with a QIN_HBA_REG
90 1.16 mjacob * that passes back the corresponding information.
91 1.16 mjacob *
92 1.16 mjacob * The r_version tag defines the version of this API.
93 1.15 mjacob */
94 1.17 mjacob #define QR_VERSION 20
95 1.15 mjacob typedef struct {
96 1.16 mjacob /* NB: structure tags from here to r_version must never change */
97 1.15 mjacob void * r_identity;
98 1.15 mjacob void (*r_action)(qact_e, void *);
99 1.15 mjacob char r_name[8];
100 1.15 mjacob int r_inst;
101 1.15 mjacob int r_version;
102 1.15 mjacob uint32_t r_locator;
103 1.15 mjacob uint32_t r_nchannels;
104 1.15 mjacob enum { R_FC, R_SPI } r_type;
105 1.15 mjacob void * r_private;
106 1.15 mjacob } hba_register_t;
107 1.1 mjacob
108 1.1 mjacob /*
109 1.15 mjacob * An information structure that is used to get or set per-channel transport layer parameters.
110 1.1 mjacob */
111 1.15 mjacob typedef struct {
112 1.15 mjacob void * i_identity;
113 1.15 mjacob enum { I_FC, I_SPI } i_type;
114 1.15 mjacob int i_channel;
115 1.15 mjacob int i_error;
116 1.15 mjacob union {
117 1.15 mjacob struct {
118 1.15 mjacob uint64_t wwnn_nvram;
119 1.15 mjacob uint64_t wwpn_nvram;
120 1.15 mjacob uint64_t wwnn;
121 1.15 mjacob uint64_t wwpn;
122 1.15 mjacob } fc;
123 1.15 mjacob struct {
124 1.15 mjacob int iid;
125 1.15 mjacob } spi;
126 1.15 mjacob } i_id;
127 1.15 mjacob } info_t;
128 1.1 mjacob
129 1.15 mjacob /*
130 1.15 mjacob * An information structure to return a list of logged in WWPNs. FC specific.
131 1.15 mjacob */
132 1.1 mjacob typedef struct {
133 1.15 mjacob void * d_identity;
134 1.15 mjacob int d_channel;
135 1.15 mjacob int d_error;
136 1.15 mjacob int d_count;
137 1.15 mjacob uint64_t * d_wwpns;
138 1.15 mjacob } fc_dlist_t;
139 1.16 mjacob
140 1.15 mjacob /*
141 1.16 mjacob * Lun ENABLE/DISABLE
142 1.16 mjacob *
143 1.15 mjacob * A word about ENABLE/DISABLE: the argument is a pointer to a enadis_t
144 1.16 mjacob * with en_hba, en_chan and en_lun filled out. We used to have an iid
145 1.16 mjacob * and target pair, but this just gets silly so we made initiator id
146 1.16 mjacob * and target id something you set, once, elsewhere.
147 1.15 mjacob *
148 1.15 mjacob * If an error occurs in either enabling or disabling the described lun
149 1.16 mjacob * en_error is set with an appropriate non-zero value.
150 1.15 mjacob */
151 1.1 mjacob typedef struct {
152 1.15 mjacob void * en_private; /* for outer layer usage */
153 1.15 mjacob void * en_hba; /* HBA tag */
154 1.15 mjacob uint16_t en_lun; /* logical unit */
155 1.15 mjacob uint16_t en_chan; /* channel on card */
156 1.15 mjacob int en_error;
157 1.15 mjacob } enadis_t;
158 1.1 mjacob
159 1.16 mjacob
160 1.16 mjacob
161 1.1 mjacob /*
162 1.16 mjacob * Data Transaction
163 1.1 mjacob *
164 1.16 mjacob * A tmd_xact_t is a structure used to describe a transaction within
165 1.16 mjacob * an overall command. It used to be part of the overall command,
166 1.16 mjacob * but it became desirable to allow for multiple simultaneous
167 1.16 mjacob * transfers for a command to happen. Generally these structures
168 1.16 mjacob * define data to be moved (along with the relative offset within
169 1.16 mjacob * the overall command) with the last structure containing status
170 1.16 mjacob * and sense (if needed) as well.
171 1.16 mjacob *
172 1.16 mjacob * The td_cmd tag points back to the owning command.
173 1.16 mjacob *
174 1.16 mjacob * The td_data tag points to the (platform specific) data descriptor.
175 1.16 mjacob *
176 1.16 mjacob * The td_lprivate is for use by the Inner Layer for private usage.
177 1.16 mjacob *
178 1.16 mjacob * The td_xfrlen says whether this transaction is moving data- if nonzero.
179 1.16 mjacob *
180 1.16 mjacob * The td_offset states what the relative offset within the comamnd the
181 1.16 mjacob * data transfer will start at. It is undefined if td_xfrlen is zero.
182 1.16 mjacob *
183 1.16 mjacob * The td_error flag will note any errors that occurred during an attempt
184 1.16 mjacob * to start this transaction. The inner layer is responsible for setting
185 1.16 mjacob * this.
186 1.16 mjacob *
187 1.16 mjacob * The td_hflags tag is set by the outer layer to indicate how the inner
188 1.16 mjacob * layer is supposed to treat this transaction.
189 1.16 mjacob *
190 1.16 mjacob * The td_lflags tag is set by the inner layer to indicate whether this
191 1.16 mjacob * transaction sent status and/or sense. Note that (much as it hurts),
192 1.16 mjacob * this API allows the inner layer to *fail* to send sense even if asked
193 1.16 mjacob * to- that is, AUTOSENSE is not a requirement of this API and the outer
194 1.16 mjacob * layer has to be prepared for this (unlikely) eventuality.
195 1.16 mjacob */
196 1.16 mjacob
197 1.16 mjacob typedef struct tmd_cmd tmd_cmd_t;
198 1.16 mjacob typedef struct tmd_xact {
199 1.16 mjacob tmd_cmd_t * td_cmd; /* cross-ref to tmd_cmd_t */
200 1.16 mjacob void * td_data; /* data descriptor */
201 1.16 mjacob void * td_lprivate; /* private for lower layer */
202 1.16 mjacob uint32_t td_xfrlen; /* size of this data load */
203 1.16 mjacob uint32_t td_offset; /* offset for this data load */
204 1.16 mjacob int td_error; /* error with this transfer */
205 1.16 mjacob uint8_t td_hflags; /* flags set by caller */
206 1.16 mjacob uint8_t td_lflags; /* flags set by callee */
207 1.16 mjacob } tmd_xact_t;
208 1.16 mjacob
209 1.16 mjacob #define TDFH_STSVALID 0x01 /* status is valid - include it */
210 1.16 mjacob #define TDFH_SNSVALID 0x02 /* sense data (from outer layer) good - include it */
211 1.16 mjacob #define TDFH_DATA_IN 0x04 /* target (us) -> initiator (them) */
212 1.16 mjacob #define TDFH_DATA_OUT 0x08 /* initiator (them) -> target (us) */
213 1.16 mjacob #define TDFH_DATA_MASK 0x0C /* mask to cover data direction */
214 1.16 mjacob #define TDFH_PRIVATE 0xF0 /* private outer layer usage */
215 1.16 mjacob
216 1.16 mjacob #define TDFL_SENTSTATUS 0x01 /* this transaction sent status */
217 1.16 mjacob #define TDFL_SENTSENSE 0x02 /* this transaction sent sense data */
218 1.16 mjacob #define TDFL_ERROR 0x04 /* this transaction had an error */
219 1.18 mjacob #define TDFL_SYNCERROR 0x08 /* ... and didn't even start because of it */
220 1.16 mjacob #define TDFL_PRIVATE 0xF0 /* private inner layer usage */
221 1.16 mjacob
222 1.16 mjacob /*
223 1.16 mjacob * The command structure below the SCSI Command structure that is
224 1.16 mjacob * is the whole point of this API. After a LUN is (or LUNS are)
225 1.16 mjacob * enabled, initiators who send commands addressed to the port,
226 1.16 mjacob * channel and lun that have been enabled cause an interrupt which
227 1.16 mjacob * causes the chip to receive the command and present it to the
228 1.16 mjacob * inner layer. The inner layer allocates one of this command
229 1.16 mjacob * structures and copies relevant information to it and sends it
230 1.16 mjacob * to the outer layer with the action QOUT_TMD_START.
231 1.16 mjacob *
232 1.16 mjacob * The outer layer is then responsible for command decode and is responsible
233 1.16 mjacob * for sending any transactions back (via a QIN_TMD_CONT) to the inner layer
234 1.16 mjacob * that (optionally) moves data and then sends closing status.
235 1.16 mjacob *
236 1.16 mjacob * The outer layer, when informed of the status of the final transaction
237 1.16 mjacob * then releases this structure by sending it back to the inner layer
238 1.16 mjacob * with the action QOUT_TMD_FIN.
239 1.3 he *
240 1.16 mjacob * The structure tag meanings are as described below.
241 1.3 he *
242 1.16 mjacob * The cd_hba tag is a tag that uniquely identifies the HBA this target
243 1.16 mjacob * mode command is coming from. The outer layer has to pass this back
244 1.16 mjacob * unchanged to avoid chaos. It is identical to the r_identity tag used
245 1.16 mjacob * by the inner layer to register with the outer layer.
246 1.3 he *
247 1.16 mjacob * The cd_iid, cd_channel, cd_tgt and cd_lun tags are used to identify the
248 1.16 mjacob * the initiator who sent us a command, the channel on the this particular
249 1.16 mjacob * hardware port we arrived on (for multiple channel devices), the target we
250 1.16 mjacob * claim to be, and the lun on that target.
251 1.16 mjacob *
252 1.16 mjacob * The cd_tagval field is a tag that uniquely describes this tag. It may
253 1.16 mjacob * or may not have any correspondence to an underying hardware tag. The
254 1.16 mjacob * outer layer must pass this back unchanged or chaos will result.
255 1.3 he *
256 1.16 mjacob * The tag cd_totlen is the total data amount expected to be moved
257 1.16 mjacob * for this command. This will be set to non-zero for transports
258 1.16 mjacob * that know this value from the transport level (e.g., Fibre Channel).
259 1.16 mjacob * If it shows up in the outer layers set to zero, the total data length
260 1.16 mjacob * must be inferred from the CDB.
261 1.16 mjacob *
262 1.16 mjacob * The tag cd_moved is the total amount of data moved so far. It is the
263 1.16 mjacob * responsibilty of the inner layer to set this for every transaction and
264 1.16 mjacob * to keep track of it so that transport level residuals may be correctly
265 1.16 mjacob * set.
266 1.1 mjacob *
267 1.16 mjacob * The cd_cdb contains storage for the passed in SCSI command.
268 1.1 mjacob *
269 1.15 mjacob * The cd_tagtype field specifies what kind of command tag type, if
270 1.16 mjacob * any, has been sent with this command.
271 1.1 mjacob *
272 1.16 mjacob * The tag cd_flags has some junk flags set but mostly has flags reserved for outer layer use.
273 1.1 mjacob *
274 1.16 mjacob * The tags cd_sense and cd_scsi_status are self-explanatory.
275 1.1 mjacob *
276 1.16 mjacob * The cd_xact tag is the first or only transaction structure related to this command.
277 1.1 mjacob *
278 1.16 mjacob * The tag cd_lreserved, cd_hreserved are scratch areas for use for the outer and inner layers respectively.
279 1.15 mjacob *
280 1.1 mjacob */
281 1.1 mjacob
282 1.16 mjacob #ifndef TMD_CDBLEN
283 1.16 mjacob #define TMD_CDBLEN 16
284 1.16 mjacob #endif
285 1.16 mjacob #ifndef TMD_SENSELEN
286 1.16 mjacob #define TMD_SENSELEN 18
287 1.10 mjacob #endif
288 1.16 mjacob #ifndef QCDS
289 1.16 mjacob #define QCDS (sizeof (uint64_t))
290 1.1 mjacob #endif
291 1.16 mjacob #ifndef TMD_PRIV_LO
292 1.16 mjacob #define TMD_PRIV_LO 4
293 1.16 mjacob #endif
294 1.16 mjacob #ifndef TMD_PRIV_HI
295 1.16 mjacob #define TMD_PRIV_HI 4
296 1.1 mjacob #endif
297 1.1 mjacob
298 1.16 mjacob struct tmd_cmd {
299 1.15 mjacob void * cd_hba; /* HBA tag */
300 1.15 mjacob uint64_t cd_iid; /* initiator ID */
301 1.15 mjacob uint64_t cd_tgt; /* target id */
302 1.16 mjacob uint64_t cd_tagval; /* tag value */
303 1.15 mjacob uint8_t cd_lun[8]; /* logical unit */
304 1.15 mjacob uint32_t cd_totlen; /* total data load */
305 1.16 mjacob uint32_t cd_moved; /* total data moved so far */
306 1.16 mjacob uint16_t cd_channel; /* channel index */
307 1.16 mjacob uint16_t cd_flags; /* flags */
308 1.16 mjacob uint16_t cd_req_cnt; /* how many tmd_xact_t's are active */
309 1.16 mjacob uint8_t cd_cdb[TMD_CDBLEN];
310 1.15 mjacob uint8_t cd_tagtype; /* tag type */
311 1.15 mjacob uint8_t cd_scsi_status;
312 1.15 mjacob uint8_t cd_sense[TMD_SENSELEN];
313 1.16 mjacob tmd_xact_t cd_xact; /* first or only transaction */
314 1.15 mjacob union {
315 1.16 mjacob void * ptrs[QCDS / sizeof (void *)]; /* (assume) one pointer */
316 1.16 mjacob uint64_t llongs[QCDS / sizeof (uint64_t)]; /* one long long */
317 1.16 mjacob uint32_t longs[QCDS / sizeof (uint32_t)]; /* two longs */
318 1.16 mjacob uint16_t shorts[QCDS / sizeof (uint16_t)]; /* four shorts */
319 1.16 mjacob uint8_t bytes[QCDS]; /* eight bytes */
320 1.16 mjacob } cd_lreserved[TMD_PRIV_LO], cd_hreserved[TMD_PRIV_HI];
321 1.16 mjacob };
322 1.16 mjacob
323 1.16 mjacob #define CDF_NODISC 0x0001 /* disconnects disabled */
324 1.16 mjacob #define CDF_DATA_IN 0x0002 /* target (us) -> initiator (them) */
325 1.16 mjacob #define CDF_DATA_OUT 0x0004 /* initiator (them) -> target (us) */
326 1.16 mjacob #define CDF_BIDIR 0x0006 /* bidirectional data */
327 1.16 mjacob #define CDF_SNSVALID 0x0008 /* sense is set on incoming command */
328 1.16 mjacob #define CDF_PRIVATE 0xff00 /* available for private use in outer layer */
329 1.1 mjacob
330 1.15 mjacob /* defined tags */
331 1.15 mjacob #define CD_UNTAGGED 0
332 1.15 mjacob #define CD_SIMPLE_TAG 1
333 1.15 mjacob #define CD_ORDERED_TAG 2
334 1.15 mjacob #define CD_HEAD_TAG 3
335 1.15 mjacob #define CD_ACA_TAG 4
336 1.15 mjacob
337 1.15 mjacob #ifndef TMD_SIZE
338 1.15 mjacob #define TMD_SIZE (sizeof (tmd_cmd_t))
339 1.10 mjacob #endif
340 1.10 mjacob
341 1.15 mjacob #define L0LUN_TO_FLATLUN(lptr) ((((lptr)[0] & 0x3f) << 8) | ((lptr)[1]))
342 1.15 mjacob #define FLATLUN_TO_L0LUN(lptr, lun) \
343 1.15 mjacob (lptr)[1] = lun & 0xff; \
344 1.15 mjacob if (sizeof (lun) == 1) { \
345 1.15 mjacob (lptr)[0] = 0; \
346 1.15 mjacob } else { \
347 1.15 mjacob uint16_t nl = lun; \
348 1.15 mjacob if (nl == LUN_ANY) { \
349 1.15 mjacob (lptr)[0] = (nl >> 8) & 0xff; \
350 1.15 mjacob } else if (nl < 256) { \
351 1.15 mjacob (lptr)[0] = 0; \
352 1.15 mjacob } else { \
353 1.15 mjacob (lptr)[0] = 0x40 | ((nl >> 8) & 0x3f); \
354 1.15 mjacob } \
355 1.15 mjacob } \
356 1.15 mjacob memset(&(lptr)[2], 0, 6)
357 1.15 mjacob
358 1.10 mjacob /*
359 1.16 mjacob * Inner Layer Handler Function.
360 1.10 mjacob *
361 1.16 mjacob * The inner layer target handler function (the outer layer calls this)
362 1.16 mjacob * should be be prototyped like so:
363 1.10 mjacob *
364 1.15 mjacob * void target_action(qact_e, void *arg)
365 1.10 mjacob *
366 1.16 mjacob * The outer layer target handler function (the inner layer calls this)
367 1.10 mjacob * should be be prototyped like:
368 1.10 mjacob *
369 1.15 mjacob * void scsi_target_handler(tact_e, void *arg)
370 1.15 mjacob */
371 1.18 mjacob
372 1.15 mjacob #endif /* _ISP_TPUBLIC_H */
373 1.15 mjacob /*
374 1.15 mjacob * vim:ts=4:sw=4:expandtab
375 1.10 mjacob */
376