blob: 2cfdbef447db6ba7c4f7b774fcce47fe5f53e409 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Core definitions and data structures shareable across OS platforms.
3 *
4 * Copyright (c) 1994-2002 Justin T. Gibbs.
5 * Copyright (c) 2000-2002 Adaptec Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification.
14 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
15 * substantially similar to the "NO WARRANTY" disclaimer below
16 * ("Disclaimer") and any redistribution must be conditioned upon
17 * including a substantially similar Disclaimer requirement for further
18 * binary redistribution.
19 * 3. Neither the names of the above-listed copyright holders nor the names
20 * of any contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * Alternatively, this software may be distributed under the terms of the
24 * GNU General Public License ("GPL") version 2 as published by the Free
25 * Software Foundation.
26 *
27 * NO WARRANTY
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
37 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGES.
39 *
Hannes Reinecke66a06832006-01-12 12:05:46 +010040 * $Id: //depot/aic7xxx/aic7xxx/aic79xx.h#108 $
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 *
42 * $FreeBSD$
43 */
44
45#ifndef _AIC79XX_H_
46#define _AIC79XX_H_
47
48/* Register Definitions */
49#include "aic79xx_reg.h"
50
51/************************* Forward Declarations *******************************/
52struct ahd_platform_data;
53struct scb_platform_data;
54
55/****************************** Useful Macros *********************************/
56#ifndef MAX
57#define MAX(a,b) (((a) > (b)) ? (a) : (b))
58#endif
59
60#ifndef MIN
61#define MIN(a,b) (((a) < (b)) ? (a) : (b))
62#endif
63
64#ifndef TRUE
65#define TRUE 1
66#endif
67#ifndef FALSE
68#define FALSE 0
69#endif
70
71#define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array))
72
73#define ALL_CHANNELS '\0'
74#define ALL_TARGETS_MASK 0xFFFF
75#define INITIATOR_WILDCARD (~0)
76#define SCB_LIST_NULL 0xFF00
77#define SCB_LIST_NULL_LE (ahd_htole16(SCB_LIST_NULL))
Hannes Reinecke11668bb2006-01-12 12:08:06 +010078#define QOUTFIFO_ENTRY_VALID 0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#define SCBID_IS_NULL(scbid) (((scbid) & 0xFF00 ) == SCB_LIST_NULL)
80
81#define SCSIID_TARGET(ahd, scsiid) \
82 (((scsiid) & TID) >> TID_SHIFT)
83#define SCSIID_OUR_ID(scsiid) \
84 ((scsiid) & OID)
85#define SCSIID_CHANNEL(ahd, scsiid) ('A')
86#define SCB_IS_SCSIBUS_B(ahd, scb) (0)
87#define SCB_GET_OUR_ID(scb) \
88 SCSIID_OUR_ID((scb)->hscb->scsiid)
89#define SCB_GET_TARGET(ahd, scb) \
90 SCSIID_TARGET((ahd), (scb)->hscb->scsiid)
91#define SCB_GET_CHANNEL(ahd, scb) \
92 SCSIID_CHANNEL(ahd, (scb)->hscb->scsiid)
93#define SCB_GET_LUN(scb) \
94 ((scb)->hscb->lun)
95#define SCB_GET_TARGET_OFFSET(ahd, scb) \
96 SCB_GET_TARGET(ahd, scb)
97#define SCB_GET_TARGET_MASK(ahd, scb) \
98 (0x01 << (SCB_GET_TARGET_OFFSET(ahd, scb)))
99#ifdef AHD_DEBUG
100#define SCB_IS_SILENT(scb) \
101 ((ahd_debug & AHD_SHOW_MASKED_ERRORS) == 0 \
102 && (((scb)->flags & SCB_SILENT) != 0))
103#else
104#define SCB_IS_SILENT(scb) \
105 (((scb)->flags & SCB_SILENT) != 0)
106#endif
107/*
108 * TCLs have the following format: TTTTLLLLLLLL
109 */
110#define TCL_TARGET_OFFSET(tcl) \
111 ((((tcl) >> 4) & TID) >> 4)
112#define TCL_LUN(tcl) \
113 (tcl & (AHD_NUM_LUNS - 1))
114#define BUILD_TCL(scsiid, lun) \
115 ((lun) | (((scsiid) & TID) << 4))
116#define BUILD_TCL_RAW(target, channel, lun) \
117 ((lun) | ((target) << 8))
118
119#define SCB_GET_TAG(scb) \
120 ahd_le16toh(scb->hscb->tag)
121
122#ifndef AHD_TARGET_MODE
123#undef AHD_TMODE_ENABLE
124#define AHD_TMODE_ENABLE 0
125#endif
126
127#define AHD_BUILD_COL_IDX(target, lun) \
128 (((lun) << 4) | target)
129
130#define AHD_GET_SCB_COL_IDX(ahd, scb) \
131 ((SCB_GET_LUN(scb) << 4) | SCB_GET_TARGET(ahd, scb))
132
133#define AHD_SET_SCB_COL_IDX(scb, col_idx) \
134do { \
135 (scb)->hscb->scsiid = ((col_idx) << TID_SHIFT) & TID; \
136 (scb)->hscb->lun = ((col_idx) >> 4) & (AHD_NUM_LUNS_NONPKT-1); \
137} while (0)
138
139#define AHD_COPY_SCB_COL_IDX(dst, src) \
140do { \
141 dst->hscb->scsiid = src->hscb->scsiid; \
142 dst->hscb->lun = src->hscb->lun; \
143} while (0)
144
145#define AHD_NEVER_COL_IDX 0xFFFF
146
147/**************************** Driver Constants ********************************/
148/*
149 * The maximum number of supported targets.
150 */
151#define AHD_NUM_TARGETS 16
152
153/*
154 * The maximum number of supported luns.
155 * The identify message only supports 64 luns in non-packetized transfers.
156 * You can have 2^64 luns when information unit transfers are enabled,
157 * but until we see a need to support that many, we support 256.
158 */
159#define AHD_NUM_LUNS_NONPKT 64
160#define AHD_NUM_LUNS 256
161
162/*
163 * The maximum transfer per S/G segment.
164 */
165#define AHD_MAXTRANSFER_SIZE 0x00ffffff /* limited by 24bit counter */
166
167/*
168 * The maximum amount of SCB storage in hardware on a controller.
169 * This value represents an upper bound. Due to software design,
170 * we may not be able to use this number.
171 */
172#define AHD_SCB_MAX 512
173
174/*
175 * The maximum number of concurrent transactions supported per driver instance.
176 * Sequencer Control Blocks (SCBs) store per-transaction information.
177 */
178#define AHD_MAX_QUEUE AHD_SCB_MAX
179
180/*
181 * Define the size of our QIN and QOUT FIFOs. They must be a power of 2
182 * in size and accommodate as many transactions as can be queued concurrently.
183 */
184#define AHD_QIN_SIZE AHD_MAX_QUEUE
185#define AHD_QOUT_SIZE AHD_MAX_QUEUE
186
187#define AHD_QIN_WRAP(x) ((x) & (AHD_QIN_SIZE-1))
188/*
189 * The maximum amount of SCB storage we allocate in host memory.
190 */
191#define AHD_SCB_MAX_ALLOC AHD_MAX_QUEUE
192
193/*
194 * Ring Buffer of incoming target commands.
195 * We allocate 256 to simplify the logic in the sequencer
196 * by using the natural wrap point of an 8bit counter.
197 */
198#define AHD_TMODE_CMDS 256
199
200/* Reset line assertion time in us */
201#define AHD_BUSRESET_DELAY 25
202
203/******************* Chip Characteristics/Operating Settings *****************/
204/*
205 * Chip Type
206 * The chip order is from least sophisticated to most sophisticated.
207 */
208typedef enum {
209 AHD_NONE = 0x0000,
210 AHD_CHIPID_MASK = 0x00FF,
211 AHD_AIC7901 = 0x0001,
212 AHD_AIC7902 = 0x0002,
213 AHD_AIC7901A = 0x0003,
214 AHD_PCI = 0x0100, /* Bus type PCI */
215 AHD_PCIX = 0x0200, /* Bus type PCIX */
216 AHD_BUS_MASK = 0x0F00
217} ahd_chip;
218
219/*
220 * Features available in each chip type.
221 */
222typedef enum {
223 AHD_FENONE = 0x00000,
224 AHD_WIDE = 0x00001,/* Wide Channel */
225 AHD_MULTI_FUNC = 0x00100,/* Multi-Function/Channel Device */
226 AHD_TARGETMODE = 0x01000,/* Has tested target mode support */
227 AHD_MULTIROLE = 0x02000,/* Space for two roles at a time */
228 AHD_RTI = 0x04000,/* Retained Training Support */
229 AHD_NEW_IOCELL_OPTS = 0x08000,/* More Signal knobs in the IOCELL */
230 AHD_NEW_DFCNTRL_OPTS = 0x10000,/* SCSIENWRDIS bit */
231 AHD_FAST_CDB_DELIVERY = 0x20000,/* CDB acks released to Output Sync */
232 AHD_REMOVABLE = 0x00000,/* Hot-Swap supported - None so far*/
233 AHD_AIC7901_FE = AHD_FENONE,
234 AHD_AIC7901A_FE = AHD_FENONE,
235 AHD_AIC7902_FE = AHD_MULTI_FUNC
236} ahd_feature;
237
238/*
239 * Bugs in the silicon that we work around in software.
240 */
241typedef enum {
242 AHD_BUGNONE = 0x0000,
243 /*
244 * Rev A hardware fails to update LAST/CURR/NEXTSCB
245 * correctly in certain packetized selection cases.
246 */
247 AHD_SENT_SCB_UPDATE_BUG = 0x0001,
248 /* The wrong SCB is accessed to check the abort pending bit. */
249 AHD_ABORT_LQI_BUG = 0x0002,
250 /* Packetized bitbucket crosses packet boundaries. */
251 AHD_PKT_BITBUCKET_BUG = 0x0004,
252 /* The selection timer runs twice as long as its setting. */
253 AHD_LONG_SETIMO_BUG = 0x0008,
254 /* The Non-LQ CRC error status is delayed until phase change. */
255 AHD_NLQICRC_DELAYED_BUG = 0x0010,
256 /* The chip must be reset for all outgoing bus resets. */
257 AHD_SCSIRST_BUG = 0x0020,
258 /* Some PCIX fields must be saved and restored across chip reset. */
259 AHD_PCIX_CHIPRST_BUG = 0x0040,
260 /* MMAPIO is not functional in PCI-X mode. */
261 AHD_PCIX_MMAPIO_BUG = 0x0080,
262 /* Reads to SCBRAM fail to reset the discard timer. */
263 AHD_PCIX_SCBRAM_RD_BUG = 0x0100,
264 /* Bug workarounds that can be disabled on non-PCIX busses. */
265 AHD_PCIX_BUG_MASK = AHD_PCIX_CHIPRST_BUG
266 | AHD_PCIX_MMAPIO_BUG
267 | AHD_PCIX_SCBRAM_RD_BUG,
268 /*
269 * LQOSTOP0 status set even for forced selections with ATN
270 * to perform non-packetized message delivery.
271 */
272 AHD_LQO_ATNO_BUG = 0x0200,
273 /* FIFO auto-flush does not always trigger. */
274 AHD_AUTOFLUSH_BUG = 0x0400,
275 /* The CLRLQO registers are not self-clearing. */
276 AHD_CLRLQO_AUTOCLR_BUG = 0x0800,
277 /* The PACKETIZED status bit refers to the previous connection. */
278 AHD_PKTIZED_STATUS_BUG = 0x1000,
279 /* "Short Luns" are not placed into outgoing LQ packets correctly. */
280 AHD_PKT_LUN_BUG = 0x2000,
281 /*
282 * Only the FIFO allocated to the non-packetized connection may
283 * be in use during a non-packetzied connection.
284 */
285 AHD_NONPACKFIFO_BUG = 0x4000,
286 /*
287 * Writing to a DFF SCBPTR register may fail if concurent with
288 * a hardware write to the other DFF SCBPTR register. This is
289 * not currently a concern in our sequencer since all chips with
290 * this bug have the AHD_NONPACKFIFO_BUG and all writes of concern
291 * occur in non-packetized connections.
292 */
293 AHD_MDFF_WSCBPTR_BUG = 0x8000,
294 /* SGHADDR updates are slow. */
295 AHD_REG_SLOW_SETTLE_BUG = 0x10000,
296 /*
297 * Changing the MODE_PTR coincident with an interrupt that
298 * switches to a different mode will cause the interrupt to
299 * be in the mode written outside of interrupt context.
300 */
301 AHD_SET_MODE_BUG = 0x20000,
302 /* Non-packetized busfree revision does not work. */
303 AHD_BUSFREEREV_BUG = 0x40000,
304 /*
305 * Paced transfers are indicated with a non-standard PPR
306 * option bit in the neg table, 160MHz is indicated by
307 * sync factor 0x7, and the offset if off by a factor of 2.
308 */
309 AHD_PACED_NEGTABLE_BUG = 0x80000,
310 /* LQOOVERRUN false positives. */
311 AHD_LQOOVERRUN_BUG = 0x100000,
312 /*
313 * Controller write to INTSTAT will lose to a host
314 * write to CLRINT.
315 */
316 AHD_INTCOLLISION_BUG = 0x200000,
317 /*
318 * The GEM318 violates the SCSI spec by not waiting
319 * the mandated bus settle delay between phase changes
320 * in some situations. Some aic79xx chip revs. are more
321 * strict in this regard and will treat REQ assertions
322 * that fall within the bus settle delay window as
323 * glitches. This flag tells the firmware to tolerate
324 * early REQ assertions.
325 */
326 AHD_EARLY_REQ_BUG = 0x400000,
327 /*
328 * The LED does not stay on long enough in packetized modes.
329 */
330 AHD_FAINT_LED_BUG = 0x800000
331} ahd_bug;
332
333/*
334 * Configuration specific settings.
335 * The driver determines these settings by probing the
336 * chip/controller's configuration.
337 */
338typedef enum {
339 AHD_FNONE = 0x00000,
340 AHD_BOOT_CHANNEL = 0x00001,/* We were set as the boot channel. */
341 AHD_USEDEFAULTS = 0x00004,/*
342 * For cards without an seeprom
343 * or a BIOS to initialize the chip's
344 * SRAM, we use the default target
345 * settings.
346 */
347 AHD_SEQUENCER_DEBUG = 0x00008,
348 AHD_RESET_BUS_A = 0x00010,
349 AHD_EXTENDED_TRANS_A = 0x00020,
350 AHD_TERM_ENB_A = 0x00040,
351 AHD_SPCHK_ENB_A = 0x00080,
352 AHD_STPWLEVEL_A = 0x00100,
353 AHD_INITIATORROLE = 0x00200,/*
354 * Allow initiator operations on
355 * this controller.
356 */
357 AHD_TARGETROLE = 0x00400,/*
358 * Allow target operations on this
359 * controller.
360 */
361 AHD_RESOURCE_SHORTAGE = 0x00800,
362 AHD_TQINFIFO_BLOCKED = 0x01000,/* Blocked waiting for ATIOs */
363 AHD_INT50_SPEEDFLEX = 0x02000,/*
364 * Internal 50pin connector
365 * sits behind an aic3860
366 */
367 AHD_BIOS_ENABLED = 0x04000,
368 AHD_ALL_INTERRUPTS = 0x08000,
369 AHD_39BIT_ADDRESSING = 0x10000,/* Use 39 bit addressing scheme. */
370 AHD_64BIT_ADDRESSING = 0x20000,/* Use 64 bit addressing scheme. */
371 AHD_CURRENT_SENSING = 0x40000,
372 AHD_SCB_CONFIG_USED = 0x80000,/* No SEEPROM but SCB had info. */
373 AHD_HP_BOARD = 0x100000,
374 AHD_RESET_POLL_ACTIVE = 0x200000,
375 AHD_UPDATE_PEND_CMDS = 0x400000,
376 AHD_RUNNING_QOUTFIFO = 0x800000,
377 AHD_HAD_FIRST_SEL = 0x1000000
378} ahd_flag;
379
380/************************* Hardware SCB Definition ***************************/
381
382/*
383 * The driver keeps up to MAX_SCB scb structures per card in memory. The SCB
384 * consists of a "hardware SCB" mirroring the fields available on the card
385 * and additional information the kernel stores for each transaction.
386 *
387 * To minimize space utilization, a portion of the hardware scb stores
388 * different data during different portions of a SCSI transaction.
389 * As initialized by the host driver for the initiator role, this area
390 * contains the SCSI cdb (or a pointer to the cdb) to be executed. After
391 * the cdb has been presented to the target, this area serves to store
392 * residual transfer information and the SCSI status byte.
393 * For the target role, the contents of this area do not change, but
394 * still serve a different purpose than for the initiator role. See
395 * struct target_data for details.
396 */
397
398/*
399 * Status information embedded in the shared poriton of
400 * an SCB after passing the cdb to the target. The kernel
401 * driver will only read this data for transactions that
402 * complete abnormally.
403 */
404struct initiator_status {
405 uint32_t residual_datacnt; /* Residual in the current S/G seg */
406 uint32_t residual_sgptr; /* The next S/G for this transfer */
407 uint8_t scsi_status; /* Standard SCSI status byte */
408};
409
410struct target_status {
411 uint32_t residual_datacnt; /* Residual in the current S/G seg */
412 uint32_t residual_sgptr; /* The next S/G for this transfer */
413 uint8_t scsi_status; /* SCSI status to give to initiator */
414 uint8_t target_phases; /* Bitmap of phases to execute */
415 uint8_t data_phase; /* Data-In or Data-Out */
416 uint8_t initiator_tag; /* Initiator's transaction tag */
417};
418
419/*
420 * Initiator mode SCB shared data area.
421 * If the embedded CDB is 12 bytes or less, we embed
422 * the sense buffer address in the SCB. This allows
423 * us to retrieve sense information without interrupting
424 * the host in packetized mode.
425 */
426typedef uint32_t sense_addr_t;
427#define MAX_CDB_LEN 16
428#define MAX_CDB_LEN_WITH_SENSE_ADDR (MAX_CDB_LEN - sizeof(sense_addr_t))
429union initiator_data {
430 struct {
431 uint64_t cdbptr;
432 uint8_t cdblen;
433 } cdb_from_host;
434 uint8_t cdb[MAX_CDB_LEN];
435 struct {
436 uint8_t cdb[MAX_CDB_LEN_WITH_SENSE_ADDR];
437 sense_addr_t sense_addr;
438 } cdb_plus_saddr;
439};
440
441/*
442 * Target mode version of the shared data SCB segment.
443 */
444struct target_data {
445 uint32_t spare[2];
446 uint8_t scsi_status; /* SCSI status to give to initiator */
447 uint8_t target_phases; /* Bitmap of phases to execute */
448 uint8_t data_phase; /* Data-In or Data-Out */
449 uint8_t initiator_tag; /* Initiator's transaction tag */
450};
451
452struct hardware_scb {
453/*0*/ union {
454 union initiator_data idata;
455 struct target_data tdata;
456 struct initiator_status istatus;
457 struct target_status tstatus;
458 } shared_data;
459/*
460 * A word about residuals.
461 * The scb is presented to the sequencer with the dataptr and datacnt
462 * fields initialized to the contents of the first S/G element to
463 * transfer. The sgptr field is initialized to the bus address for
464 * the S/G element that follows the first in the in core S/G array
465 * or'ed with the SG_FULL_RESID flag. Sgptr may point to an invalid
466 * S/G entry for this transfer (single S/G element transfer with the
467 * first elements address and length preloaded in the dataptr/datacnt
468 * fields). If no transfer is to occur, sgptr is set to SG_LIST_NULL.
469 * The SG_FULL_RESID flag ensures that the residual will be correctly
470 * noted even if no data transfers occur. Once the data phase is entered,
471 * the residual sgptr and datacnt are loaded from the sgptr and the
472 * datacnt fields. After each S/G element's dataptr and length are
473 * loaded into the hardware, the residual sgptr is advanced. After
474 * each S/G element is expired, its datacnt field is checked to see
475 * if the LAST_SEG flag is set. If so, SG_LIST_NULL is set in the
476 * residual sg ptr and the transfer is considered complete. If the
477 * sequencer determines that there is a residual in the tranfer, or
478 * there is non-zero status, it will set the SG_STATUS_VALID flag in
479 * sgptr and dma the scb back into host memory. To sumarize:
480 *
481 * Sequencer:
482 * o A residual has occurred if SG_FULL_RESID is set in sgptr,
483 * or residual_sgptr does not have SG_LIST_NULL set.
484 *
485 * o We are transfering the last segment if residual_datacnt has
486 * the SG_LAST_SEG flag set.
487 *
488 * Host:
489 * o A residual can only have occurred if a completed scb has the
490 * SG_STATUS_VALID flag set. Inspection of the SCSI status field,
491 * the residual_datacnt, and the residual_sgptr field will tell
492 * for sure.
493 *
494 * o residual_sgptr and sgptr refer to the "next" sg entry
495 * and so may point beyond the last valid sg entry for the
496 * transfer.
497 */
498#define SG_PTR_MASK 0xFFFFFFF8
499/*16*/ uint16_t tag; /* Reused by Sequencer. */
500/*18*/ uint8_t control; /* See SCB_CONTROL in aic79xx.reg for details */
501/*19*/ uint8_t scsiid; /*
502 * Selection out Id
503 * Our Id (bits 0-3) Their ID (bits 4-7)
504 */
505/*20*/ uint8_t lun;
506/*21*/ uint8_t task_attribute;
507/*22*/ uint8_t cdb_len;
508/*23*/ uint8_t task_management;
509/*24*/ uint64_t dataptr;
510/*32*/ uint32_t datacnt; /* Byte 3 is spare. */
511/*36*/ uint32_t sgptr;
512/*40*/ uint32_t hscb_busaddr;
513/*44*/ uint32_t next_hscb_busaddr;
514/********** Long lun field only downloaded for full 8 byte lun support ********/
515/*48*/ uint8_t pkt_long_lun[8];
516/******* Fields below are not Downloaded (Sequencer may use for scratch) ******/
517/*56*/ uint8_t spare[8];
518};
519
520/************************ Kernel SCB Definitions ******************************/
521/*
522 * Some fields of the SCB are OS dependent. Here we collect the
523 * definitions for elements that all OS platforms need to include
524 * in there SCB definition.
525 */
526
527/*
528 * Definition of a scatter/gather element as transfered to the controller.
529 * The aic7xxx chips only support a 24bit length. We use the top byte of
530 * the length to store additional address bits and a flag to indicate
531 * that a given segment terminates the transfer. This gives us an
532 * addressable range of 512GB on machines with 64bit PCI or with chips
533 * that can support dual address cycles on 32bit PCI busses.
534 */
535struct ahd_dma_seg {
536 uint32_t addr;
537 uint32_t len;
538#define AHD_DMA_LAST_SEG 0x80000000
539#define AHD_SG_HIGH_ADDR_MASK 0x7F000000
540#define AHD_SG_LEN_MASK 0x00FFFFFF
541};
542
543struct ahd_dma64_seg {
544 uint64_t addr;
545 uint32_t len;
546 uint32_t pad;
547};
548
549struct map_node {
550 bus_dmamap_t dmamap;
551 dma_addr_t physaddr;
552 uint8_t *vaddr;
553 SLIST_ENTRY(map_node) links;
554};
555
556/*
557 * The current state of this SCB.
558 */
559typedef enum {
560 SCB_FLAG_NONE = 0x00000,
561 SCB_TRANSMISSION_ERROR = 0x00001,/*
562 * We detected a parity or CRC
563 * error that has effected the
564 * payload of the command. This
565 * flag is checked when normal
566 * status is returned to catch
567 * the case of a target not
568 * responding to our attempt
569 * to report the error.
570 */
571 SCB_OTHERTCL_TIMEOUT = 0x00002,/*
572 * Another device was active
573 * during the first timeout for
574 * this SCB so we gave ourselves
575 * an additional timeout period
576 * in case it was hogging the
577 * bus.
578 */
579 SCB_DEVICE_RESET = 0x00004,
580 SCB_SENSE = 0x00008,
581 SCB_CDB32_PTR = 0x00010,
582 SCB_RECOVERY_SCB = 0x00020,
583 SCB_AUTO_NEGOTIATE = 0x00040,/* Negotiate to achieve goal. */
584 SCB_NEGOTIATE = 0x00080,/* Negotiation forced for command. */
585 SCB_ABORT = 0x00100,
586 SCB_ACTIVE = 0x00200,
587 SCB_TARGET_IMMEDIATE = 0x00400,
588 SCB_PACKETIZED = 0x00800,
589 SCB_EXPECT_PPR_BUSFREE = 0x01000,
590 SCB_PKT_SENSE = 0x02000,
591 SCB_CMDPHASE_ABORT = 0x04000,
592 SCB_ON_COL_LIST = 0x08000,
593 SCB_SILENT = 0x10000 /*
594 * Be quiet about transmission type
595 * errors. They are expected and we
596 * don't want to upset the user. This
597 * flag is typically used during DV.
598 */
599} scb_flag;
600
601struct scb {
602 struct hardware_scb *hscb;
603 union {
604 SLIST_ENTRY(scb) sle;
605 LIST_ENTRY(scb) le;
606 TAILQ_ENTRY(scb) tqe;
607 } links;
608 union {
609 SLIST_ENTRY(scb) sle;
610 LIST_ENTRY(scb) le;
611 TAILQ_ENTRY(scb) tqe;
612 } links2;
613#define pending_links links2.le
614#define collision_links links2.le
615 struct scb *col_scb;
616 ahd_io_ctx_t io_ctx;
617 struct ahd_softc *ahd_softc;
618 scb_flag flags;
619#ifndef __linux__
620 bus_dmamap_t dmamap;
621#endif
622 struct scb_platform_data *platform_data;
623 struct map_node *hscb_map;
624 struct map_node *sg_map;
625 struct map_node *sense_map;
626 void *sg_list;
627 uint8_t *sense_data;
628 dma_addr_t sg_list_busaddr;
629 dma_addr_t sense_busaddr;
630 u_int sg_count;/* How full ahd_dma_seg is */
631#define AHD_MAX_LQ_CRC_ERRORS 5
632 u_int crc_retry_count;
633};
634
635TAILQ_HEAD(scb_tailq, scb);
636LIST_HEAD(scb_list, scb);
637
638struct scb_data {
639 /*
640 * TAILQ of lists of free SCBs grouped by device
641 * collision domains.
642 */
643 struct scb_tailq free_scbs;
644
645 /*
646 * Per-device lists of SCBs whose tag ID would collide
647 * with an already active tag on the device.
648 */
649 struct scb_list free_scb_lists[AHD_NUM_TARGETS * AHD_NUM_LUNS_NONPKT];
650
651 /*
652 * SCBs that will not collide with any active device.
653 */
654 struct scb_list any_dev_free_scb_list;
655
656 /*
657 * Mapping from tag to SCB.
658 */
659 struct scb *scbindex[AHD_SCB_MAX];
660
661 /*
662 * "Bus" addresses of our data structures.
663 */
664 bus_dma_tag_t hscb_dmat; /* dmat for our hardware SCB array */
665 bus_dma_tag_t sg_dmat; /* dmat for our sg segments */
666 bus_dma_tag_t sense_dmat; /* dmat for our sense buffers */
667 SLIST_HEAD(, map_node) hscb_maps;
668 SLIST_HEAD(, map_node) sg_maps;
669 SLIST_HEAD(, map_node) sense_maps;
670 int scbs_left; /* unallocated scbs in head map_node */
671 int sgs_left; /* unallocated sgs in head map_node */
672 int sense_left; /* unallocated sense in head map_node */
673 uint16_t numscbs;
674 uint16_t maxhscbs; /* Number of SCBs on the card */
675 uint8_t init_level; /*
676 * How far we've initialized
677 * this structure.
678 */
679};
680
681/************************ Target Mode Definitions *****************************/
682
683/*
684 * Connection desciptor for select-in requests in target mode.
685 */
686struct target_cmd {
687 uint8_t scsiid; /* Our ID and the initiator's ID */
688 uint8_t identify; /* Identify message */
689 uint8_t bytes[22]; /*
690 * Bytes contains any additional message
691 * bytes terminated by 0xFF. The remainder
692 * is the cdb to execute.
693 */
694 uint8_t cmd_valid; /*
695 * When a command is complete, the firmware
696 * will set cmd_valid to all bits set.
697 * After the host has seen the command,
698 * the bits are cleared. This allows us
699 * to just peek at host memory to determine
700 * if more work is complete. cmd_valid is on
701 * an 8 byte boundary to simplify setting
702 * it on aic7880 hardware which only has
703 * limited direct access to the DMA FIFO.
704 */
705 uint8_t pad[7];
706};
707
708/*
709 * Number of events we can buffer up if we run out
710 * of immediate notify ccbs.
711 */
712#define AHD_TMODE_EVENT_BUFFER_SIZE 8
713struct ahd_tmode_event {
714 uint8_t initiator_id;
715 uint8_t event_type; /* MSG type or EVENT_TYPE_BUS_RESET */
716#define EVENT_TYPE_BUS_RESET 0xFF
717 uint8_t event_arg;
718};
719
720/*
721 * Per enabled lun target mode state.
722 * As this state is directly influenced by the host OS'es target mode
723 * environment, we let the OS module define it. Forward declare the
724 * structure here so we can store arrays of them, etc. in OS neutral
725 * data structures.
726 */
727#ifdef AHD_TARGET_MODE
728struct ahd_tmode_lstate {
729 struct cam_path *path;
730 struct ccb_hdr_slist accept_tios;
731 struct ccb_hdr_slist immed_notifies;
732 struct ahd_tmode_event event_buffer[AHD_TMODE_EVENT_BUFFER_SIZE];
733 uint8_t event_r_idx;
734 uint8_t event_w_idx;
735};
736#else
737struct ahd_tmode_lstate;
738#endif
739
740/******************** Transfer Negotiation Datastructures *********************/
741#define AHD_TRANS_CUR 0x01 /* Modify current neogtiation status */
742#define AHD_TRANS_ACTIVE 0x03 /* Assume this target is on the bus */
743#define AHD_TRANS_GOAL 0x04 /* Modify negotiation goal */
744#define AHD_TRANS_USER 0x08 /* Modify user negotiation settings */
745#define AHD_PERIOD_10MHz 0x19
746
747#define AHD_WIDTH_UNKNOWN 0xFF
748#define AHD_PERIOD_UNKNOWN 0xFF
749#define AHD_OFFSET_UNKNOWN 0xFF
750#define AHD_PPR_OPTS_UNKNOWN 0xFF
751
752/*
753 * Transfer Negotiation Information.
754 */
755struct ahd_transinfo {
756 uint8_t protocol_version; /* SCSI Revision level */
757 uint8_t transport_version; /* SPI Revision level */
758 uint8_t width; /* Bus width */
759 uint8_t period; /* Sync rate factor */
760 uint8_t offset; /* Sync offset */
761 uint8_t ppr_options; /* Parallel Protocol Request options */
762};
763
764/*
765 * Per-initiator current, goal and user transfer negotiation information. */
766struct ahd_initiator_tinfo {
767 struct ahd_transinfo curr;
768 struct ahd_transinfo goal;
769 struct ahd_transinfo user;
770};
771
772/*
773 * Per enabled target ID state.
774 * Pointers to lun target state as well as sync/wide negotiation information
775 * for each initiator<->target mapping. For the initiator role we pretend
776 * that we are the target and the targets are the initiators since the
777 * negotiation is the same regardless of role.
778 */
779struct ahd_tmode_tstate {
780 struct ahd_tmode_lstate* enabled_luns[AHD_NUM_LUNS];
781 struct ahd_initiator_tinfo transinfo[AHD_NUM_TARGETS];
782
783 /*
784 * Per initiator state bitmasks.
785 */
786 uint16_t auto_negotiate;/* Auto Negotiation Required */
787 uint16_t discenable; /* Disconnection allowed */
788 uint16_t tagenable; /* Tagged Queuing allowed */
789};
790
791/*
792 * Points of interest along the negotiated transfer scale.
793 */
794#define AHD_SYNCRATE_160 0x8
795#define AHD_SYNCRATE_PACED 0x8
796#define AHD_SYNCRATE_DT 0x9
797#define AHD_SYNCRATE_ULTRA2 0xa
798#define AHD_SYNCRATE_ULTRA 0xc
799#define AHD_SYNCRATE_FAST 0x19
800#define AHD_SYNCRATE_MIN_DT AHD_SYNCRATE_FAST
801#define AHD_SYNCRATE_SYNC 0x32
802#define AHD_SYNCRATE_MIN 0x60
803#define AHD_SYNCRATE_ASYNC 0xFF
804#define AHD_SYNCRATE_MAX AHD_SYNCRATE_160
805
806/* Safe and valid period for async negotiations. */
807#define AHD_ASYNC_XFER_PERIOD 0x44
808
809/*
810 * In RevA, the synctable uses a 120MHz rate for the period
811 * factor 8 and 160MHz for the period factor 7. The 120MHz
812 * rate never made it into the official SCSI spec, so we must
813 * compensate when setting the negotiation table for Rev A
814 * parts.
815 */
816#define AHD_SYNCRATE_REVA_120 0x8
817#define AHD_SYNCRATE_REVA_160 0x7
818
819/***************************** Lookup Tables **********************************/
820/*
821 * Phase -> name and message out response
822 * to parity errors in each phase table.
823 */
824struct ahd_phase_table_entry {
825 uint8_t phase;
826 uint8_t mesg_out; /* Message response to parity errors */
827 char *phasemsg;
828};
829
830/************************** Serial EEPROM Format ******************************/
831
832struct seeprom_config {
833/*
834 * Per SCSI ID Configuration Flags
835 */
836 uint16_t device_flags[16]; /* words 0-15 */
837#define CFXFER 0x003F /* synchronous transfer rate */
838#define CFXFER_ASYNC 0x3F
839#define CFQAS 0x0040 /* Negotiate QAS */
840#define CFPACKETIZED 0x0080 /* Negotiate Packetized Transfers */
841#define CFSTART 0x0100 /* send start unit SCSI command */
842#define CFINCBIOS 0x0200 /* include in BIOS scan */
843#define CFDISC 0x0400 /* enable disconnection */
844#define CFMULTILUNDEV 0x0800 /* Probe multiple luns in BIOS scan */
845#define CFWIDEB 0x1000 /* wide bus device */
846#define CFHOSTMANAGED 0x8000 /* Managed by a RAID controller */
847
848/*
849 * BIOS Control Bits
850 */
851 uint16_t bios_control; /* word 16 */
852#define CFSUPREM 0x0001 /* support all removeable drives */
853#define CFSUPREMB 0x0002 /* support removeable boot drives */
854#define CFBIOSSTATE 0x000C /* BIOS Action State */
855#define CFBS_DISABLED 0x00
856#define CFBS_ENABLED 0x04
857#define CFBS_DISABLED_SCAN 0x08
858#define CFENABLEDV 0x0010 /* Perform Domain Validation */
859#define CFCTRL_A 0x0020 /* BIOS displays Ctrl-A message */
860#define CFSPARITY 0x0040 /* SCSI parity */
861#define CFEXTEND 0x0080 /* extended translation enabled */
862#define CFBOOTCD 0x0100 /* Support Bootable CD-ROM */
863#define CFMSG_LEVEL 0x0600 /* BIOS Message Level */
864#define CFMSG_VERBOSE 0x0000
865#define CFMSG_SILENT 0x0200
866#define CFMSG_DIAG 0x0400
867#define CFRESETB 0x0800 /* reset SCSI bus at boot */
868/* UNUSED 0xf000 */
869
870/*
871 * Host Adapter Control Bits
872 */
873 uint16_t adapter_control; /* word 17 */
874#define CFAUTOTERM 0x0001 /* Perform Auto termination */
875#define CFSTERM 0x0002 /* SCSI low byte termination */
876#define CFWSTERM 0x0004 /* SCSI high byte termination */
877#define CFSEAUTOTERM 0x0008 /* Ultra2 Perform secondary Auto Term*/
878#define CFSELOWTERM 0x0010 /* Ultra2 secondary low term */
879#define CFSEHIGHTERM 0x0020 /* Ultra2 secondary high term */
880#define CFSTPWLEVEL 0x0040 /* Termination level control */
881#define CFBIOSAUTOTERM 0x0080 /* Perform Auto termination */
882#define CFTERM_MENU 0x0100 /* BIOS displays termination menu */
883#define CFCLUSTERENB 0x8000 /* Cluster Enable */
884
885/*
886 * Bus Release Time, Host Adapter ID
887 */
888 uint16_t brtime_id; /* word 18 */
889#define CFSCSIID 0x000f /* host adapter SCSI ID */
890/* UNUSED 0x00f0 */
891#define CFBRTIME 0xff00 /* bus release time/PCI Latency Time */
892
893/*
894 * Maximum targets
895 */
896 uint16_t max_targets; /* word 19 */
897#define CFMAXTARG 0x00ff /* maximum targets */
898#define CFBOOTLUN 0x0f00 /* Lun to boot from */
899#define CFBOOTID 0xf000 /* Target to boot from */
900 uint16_t res_1[10]; /* words 20-29 */
901 uint16_t signature; /* BIOS Signature */
902#define CFSIGNATURE 0x400
903 uint16_t checksum; /* word 31 */
904};
905
906/*
907 * Vital Product Data used during POST and by the BIOS.
908 */
909struct vpd_config {
910 uint8_t bios_flags;
911#define VPDMASTERBIOS 0x0001
912#define VPDBOOTHOST 0x0002
913 uint8_t reserved_1[21];
914 uint8_t resource_type;
915 uint8_t resource_len[2];
916 uint8_t resource_data[8];
917 uint8_t vpd_tag;
918 uint16_t vpd_len;
919 uint8_t vpd_keyword[2];
920 uint8_t length;
921 uint8_t revision;
922 uint8_t device_flags;
923 uint8_t termnation_menus[2];
924 uint8_t fifo_threshold;
925 uint8_t end_tag;
926 uint8_t vpd_checksum;
927 uint16_t default_target_flags;
928 uint16_t default_bios_flags;
929 uint16_t default_ctrl_flags;
930 uint8_t default_irq;
931 uint8_t pci_lattime;
932 uint8_t max_target;
933 uint8_t boot_lun;
934 uint16_t signature;
935 uint8_t reserved_2;
936 uint8_t checksum;
937 uint8_t reserved_3[4];
938};
939
940/****************************** Flexport Logic ********************************/
941#define FLXADDR_TERMCTL 0x0
942#define FLX_TERMCTL_ENSECHIGH 0x8
943#define FLX_TERMCTL_ENSECLOW 0x4
944#define FLX_TERMCTL_ENPRIHIGH 0x2
945#define FLX_TERMCTL_ENPRILOW 0x1
946#define FLXADDR_ROMSTAT_CURSENSECTL 0x1
947#define FLX_ROMSTAT_SEECFG 0xF0
948#define FLX_ROMSTAT_EECFG 0x0F
949#define FLX_ROMSTAT_SEE_93C66 0x00
950#define FLX_ROMSTAT_SEE_NONE 0xF0
951#define FLX_ROMSTAT_EE_512x8 0x0
952#define FLX_ROMSTAT_EE_1MBx8 0x1
953#define FLX_ROMSTAT_EE_2MBx8 0x2
954#define FLX_ROMSTAT_EE_4MBx8 0x3
955#define FLX_ROMSTAT_EE_16MBx8 0x4
956#define CURSENSE_ENB 0x1
957#define FLXADDR_FLEXSTAT 0x2
958#define FLX_FSTAT_BUSY 0x1
959#define FLXADDR_CURRENT_STAT 0x4
960#define FLX_CSTAT_SEC_HIGH 0xC0
961#define FLX_CSTAT_SEC_LOW 0x30
962#define FLX_CSTAT_PRI_HIGH 0x0C
963#define FLX_CSTAT_PRI_LOW 0x03
964#define FLX_CSTAT_MASK 0x03
965#define FLX_CSTAT_SHIFT 2
966#define FLX_CSTAT_OKAY 0x0
967#define FLX_CSTAT_OVER 0x1
968#define FLX_CSTAT_UNDER 0x2
969#define FLX_CSTAT_INVALID 0x3
970
971int ahd_read_seeprom(struct ahd_softc *ahd, uint16_t *buf,
972 u_int start_addr, u_int count, int bstream);
973
974int ahd_write_seeprom(struct ahd_softc *ahd, uint16_t *buf,
975 u_int start_addr, u_int count);
976int ahd_wait_seeprom(struct ahd_softc *ahd);
977int ahd_verify_vpd_cksum(struct vpd_config *vpd);
978int ahd_verify_cksum(struct seeprom_config *sc);
979int ahd_acquire_seeprom(struct ahd_softc *ahd);
980void ahd_release_seeprom(struct ahd_softc *ahd);
981
982/**************************** Message Buffer *********************************/
983typedef enum {
984 MSG_FLAG_NONE = 0x00,
985 MSG_FLAG_EXPECT_PPR_BUSFREE = 0x01,
986 MSG_FLAG_IU_REQ_CHANGED = 0x02,
987 MSG_FLAG_EXPECT_IDE_BUSFREE = 0x04,
988 MSG_FLAG_EXPECT_QASREJ_BUSFREE = 0x08,
989 MSG_FLAG_PACKETIZED = 0x10
990} ahd_msg_flags;
991
992typedef enum {
993 MSG_TYPE_NONE = 0x00,
994 MSG_TYPE_INITIATOR_MSGOUT = 0x01,
995 MSG_TYPE_INITIATOR_MSGIN = 0x02,
996 MSG_TYPE_TARGET_MSGOUT = 0x03,
997 MSG_TYPE_TARGET_MSGIN = 0x04
998} ahd_msg_type;
999
1000typedef enum {
1001 MSGLOOP_IN_PROG,
1002 MSGLOOP_MSGCOMPLETE,
1003 MSGLOOP_TERMINATED
1004} msg_loop_stat;
1005
1006/*********************** Software Configuration Structure *********************/
1007struct ahd_suspend_channel_state {
1008 uint8_t scsiseq;
1009 uint8_t sxfrctl0;
1010 uint8_t sxfrctl1;
1011 uint8_t simode0;
1012 uint8_t simode1;
1013 uint8_t seltimer;
1014 uint8_t seqctl;
1015};
1016
1017struct ahd_suspend_state {
1018 struct ahd_suspend_channel_state channel[2];
1019 uint8_t optionmode;
1020 uint8_t dscommand0;
1021 uint8_t dspcistatus;
1022 /* hsmailbox */
1023 uint8_t crccontrol1;
1024 uint8_t scbbaddr;
1025 /* Host and sequencer SCB counts */
1026 uint8_t dff_thrsh;
1027 uint8_t *scratch_ram;
1028 uint8_t *btt;
1029};
1030
1031typedef void (*ahd_bus_intr_t)(struct ahd_softc *);
1032
1033typedef enum {
1034 AHD_MODE_DFF0,
1035 AHD_MODE_DFF1,
1036 AHD_MODE_CCHAN,
1037 AHD_MODE_SCSI,
1038 AHD_MODE_CFG,
1039 AHD_MODE_UNKNOWN
1040} ahd_mode;
1041
1042#define AHD_MK_MSK(x) (0x01 << (x))
1043#define AHD_MODE_DFF0_MSK AHD_MK_MSK(AHD_MODE_DFF0)
1044#define AHD_MODE_DFF1_MSK AHD_MK_MSK(AHD_MODE_DFF1)
1045#define AHD_MODE_CCHAN_MSK AHD_MK_MSK(AHD_MODE_CCHAN)
1046#define AHD_MODE_SCSI_MSK AHD_MK_MSK(AHD_MODE_SCSI)
1047#define AHD_MODE_CFG_MSK AHD_MK_MSK(AHD_MODE_CFG)
1048#define AHD_MODE_UNKNOWN_MSK AHD_MK_MSK(AHD_MODE_UNKNOWN)
1049#define AHD_MODE_ANY_MSK (~0)
1050
1051typedef uint8_t ahd_mode_state;
1052
1053typedef void ahd_callback_t (void *);
1054
Hannes Reinecke11668bb2006-01-12 12:08:06 +01001055struct ahd_completion
1056{
1057 uint16_t tag;
1058 uint8_t sg_status;
1059 uint8_t valid_tag;
1060};
1061
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062struct ahd_softc {
1063 bus_space_tag_t tags[2];
1064 bus_space_handle_t bshs[2];
1065#ifndef __linux__
1066 bus_dma_tag_t buffer_dmat; /* dmat for buffer I/O */
1067#endif
1068 struct scb_data scb_data;
1069
1070 struct hardware_scb *next_queued_hscb;
Hannes Reinecke66a06832006-01-12 12:05:46 +01001071 struct map_node *next_queued_hscb_map;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
1073 /*
1074 * SCBs that have been sent to the controller
1075 */
1076 LIST_HEAD(, scb) pending_scbs;
1077
1078 /*
1079 * Current register window mode information.
1080 */
1081 ahd_mode dst_mode;
1082 ahd_mode src_mode;
1083
1084 /*
1085 * Saved register window mode information
1086 * used for restore on next unpause.
1087 */
1088 ahd_mode saved_dst_mode;
1089 ahd_mode saved_src_mode;
1090
1091 /*
1092 * Platform specific data.
1093 */
1094 struct ahd_platform_data *platform_data;
1095
1096 /*
1097 * Platform specific device information.
1098 */
1099 ahd_dev_softc_t dev_softc;
1100
1101 /*
1102 * Bus specific device information.
1103 */
1104 ahd_bus_intr_t bus_intr;
1105
1106 /*
1107 * Target mode related state kept on a per enabled lun basis.
1108 * Targets that are not enabled will have null entries.
1109 * As an initiator, we keep one target entry for our initiator
1110 * ID to store our sync/wide transfer settings.
1111 */
1112 struct ahd_tmode_tstate *enabled_targets[AHD_NUM_TARGETS];
1113
1114 /*
1115 * The black hole device responsible for handling requests for
1116 * disabled luns on enabled targets.
1117 */
1118 struct ahd_tmode_lstate *black_hole;
1119
1120 /*
1121 * Device instance currently on the bus awaiting a continue TIO
1122 * for a command that was not given the disconnect priveledge.
1123 */
1124 struct ahd_tmode_lstate *pending_device;
1125
1126 /*
1127 * Timer handles for timer driven callbacks.
1128 */
1129 ahd_timer_t reset_timer;
1130 ahd_timer_t stat_timer;
1131
1132 /*
1133 * Statistics.
1134 */
1135#define AHD_STAT_UPDATE_US 250000 /* 250ms */
1136#define AHD_STAT_BUCKETS 4
1137 u_int cmdcmplt_bucket;
1138 uint32_t cmdcmplt_counts[AHD_STAT_BUCKETS];
1139 uint32_t cmdcmplt_total;
1140
1141 /*
1142 * Card characteristics
1143 */
1144 ahd_chip chip;
1145 ahd_feature features;
1146 ahd_bug bugs;
1147 ahd_flag flags;
1148 struct seeprom_config *seep_config;
1149
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 /* Command Queues */
Hannes Reinecke11668bb2006-01-12 12:08:06 +01001151 struct ahd_completion *qoutfifo;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 uint16_t qoutfifonext;
1153 uint16_t qoutfifonext_valid_tag;
1154 uint16_t qinfifonext;
1155 uint16_t qinfifo[AHD_SCB_MAX];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
Hannes Reinecke66a06832006-01-12 12:05:46 +01001157 /*
1158 * Our qfreeze count. The sequencer compares
1159 * this value with its own counter to determine
1160 * whether to allow selections to occur.
1161 */
1162 uint16_t qfreeze_cnt;
1163
1164 /* Values to store in the SEQCTL register for pause and unpause */
1165 uint8_t unpause;
1166 uint8_t pause;
1167
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 /* Critical Section Data */
1169 struct cs *critical_sections;
1170 u_int num_critical_sections;
1171
1172 /* Buffer for handling packetized bitbucket. */
1173 uint8_t *overrun_buf;
1174
1175 /* Links for chaining softcs */
1176 TAILQ_ENTRY(ahd_softc) links;
1177
1178 /* Channel Names ('A', 'B', etc.) */
1179 char channel;
1180
1181 /* Initiator Bus ID */
1182 uint8_t our_id;
1183
1184 /*
1185 * Target incoming command FIFO.
1186 */
1187 struct target_cmd *targetcmds;
1188 uint8_t tqinfifonext;
1189
1190 /*
1191 * Cached verson of the hs_mailbox so we can avoid
1192 * pausing the sequencer during mailbox updates.
1193 */
1194 uint8_t hs_mailbox;
1195
1196 /*
1197 * Incoming and outgoing message handling.
1198 */
1199 uint8_t send_msg_perror;
1200 ahd_msg_flags msg_flags;
1201 ahd_msg_type msg_type;
1202 uint8_t msgout_buf[12];/* Message we are sending */
1203 uint8_t msgin_buf[12];/* Message we are receiving */
1204 u_int msgout_len; /* Length of message to send */
1205 u_int msgout_index; /* Current index in msgout */
1206 u_int msgin_index; /* Current index in msgin */
1207
1208 /*
1209 * Mapping information for data structures shared
1210 * between the sequencer and kernel.
1211 */
1212 bus_dma_tag_t parent_dmat;
1213 bus_dma_tag_t shared_data_dmat;
Hannes Reinecke66a06832006-01-12 12:05:46 +01001214 struct map_node shared_data_map;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215
1216 /* Information saved through suspend/resume cycles */
1217 struct ahd_suspend_state suspend_state;
1218
1219 /* Number of enabled target mode device on this card */
1220 u_int enabled_luns;
1221
1222 /* Initialization level of this data structure */
1223 u_int init_level;
1224
1225 /* PCI cacheline size. */
1226 u_int pci_cachesize;
1227
1228 /* IO Cell Parameters */
1229 uint8_t iocell_opts[AHD_NUM_PER_DEV_ANNEXCOLS];
1230
1231 u_int stack_size;
1232 uint16_t *saved_stack;
1233
1234 /* Per-Unit descriptive information */
1235 const char *description;
1236 const char *bus_description;
1237 char *name;
1238 int unit;
1239
1240 /* Selection Timer settings */
1241 int seltime;
1242
1243 /*
1244 * Interrupt coalescing settings.
1245 */
1246#define AHD_INT_COALESCING_TIMER_DEFAULT 250 /*us*/
1247#define AHD_INT_COALESCING_MAXCMDS_DEFAULT 10
1248#define AHD_INT_COALESCING_MAXCMDS_MAX 127
1249#define AHD_INT_COALESCING_MINCMDS_DEFAULT 5
1250#define AHD_INT_COALESCING_MINCMDS_MAX 127
1251#define AHD_INT_COALESCING_THRESHOLD_DEFAULT 2000
1252#define AHD_INT_COALESCING_STOP_THRESHOLD_DEFAULT 1000
1253 u_int int_coalescing_timer;
1254 u_int int_coalescing_maxcmds;
1255 u_int int_coalescing_mincmds;
1256 u_int int_coalescing_threshold;
1257 u_int int_coalescing_stop_threshold;
1258
1259 uint16_t user_discenable;/* Disconnection allowed */
1260 uint16_t user_tagenable;/* Tagged Queuing allowed */
1261};
1262
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263/*************************** IO Cell Configuration ****************************/
1264#define AHD_PRECOMP_SLEW_INDEX \
1265 (AHD_ANNEXCOL_PRECOMP_SLEW - AHD_ANNEXCOL_PER_DEV0)
1266
1267#define AHD_AMPLITUDE_INDEX \
1268 (AHD_ANNEXCOL_AMPLITUDE - AHD_ANNEXCOL_PER_DEV0)
1269
1270#define AHD_SET_SLEWRATE(ahd, new_slew) \
1271do { \
1272 (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] &= ~AHD_SLEWRATE_MASK; \
1273 (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] |= \
1274 (((new_slew) << AHD_SLEWRATE_SHIFT) & AHD_SLEWRATE_MASK); \
1275} while (0)
1276
1277#define AHD_SET_PRECOMP(ahd, new_pcomp) \
1278do { \
1279 (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] &= ~AHD_PRECOMP_MASK; \
1280 (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] |= \
1281 (((new_pcomp) << AHD_PRECOMP_SHIFT) & AHD_PRECOMP_MASK); \
1282} while (0)
1283
1284#define AHD_SET_AMPLITUDE(ahd, new_amp) \
1285do { \
1286 (ahd)->iocell_opts[AHD_AMPLITUDE_INDEX] &= ~AHD_AMPLITUDE_MASK; \
1287 (ahd)->iocell_opts[AHD_AMPLITUDE_INDEX] |= \
1288 (((new_amp) << AHD_AMPLITUDE_SHIFT) & AHD_AMPLITUDE_MASK); \
1289} while (0)
1290
1291/************************ Active Device Information ***************************/
1292typedef enum {
1293 ROLE_UNKNOWN,
1294 ROLE_INITIATOR,
1295 ROLE_TARGET
1296} role_t;
1297
1298struct ahd_devinfo {
1299 int our_scsiid;
1300 int target_offset;
1301 uint16_t target_mask;
1302 u_int target;
1303 u_int lun;
1304 char channel;
1305 role_t role; /*
1306 * Only guaranteed to be correct if not
1307 * in the busfree state.
1308 */
1309};
1310
1311/****************************** PCI Structures ********************************/
Hannes Reinecke66a06832006-01-12 12:05:46 +01001312#define AHD_PCI_IOADDR0 PCIR_BAR(0) /* I/O BAR*/
1313#define AHD_PCI_MEMADDR PCIR_BAR(1) /* Memory BAR */
1314#define AHD_PCI_IOADDR1 PCIR_BAR(3) /* Second I/O BAR */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
1316typedef int (ahd_device_setup_t)(struct ahd_softc *);
1317
1318struct ahd_pci_identity {
1319 uint64_t full_id;
1320 uint64_t id_mask;
1321 char *name;
1322 ahd_device_setup_t *setup;
1323};
1324extern struct ahd_pci_identity ahd_pci_ident_table [];
1325extern const u_int ahd_num_pci_devs;
1326
1327/***************************** VL/EISA Declarations ***************************/
1328struct aic7770_identity {
1329 uint32_t full_id;
1330 uint32_t id_mask;
1331 char *name;
1332 ahd_device_setup_t *setup;
1333};
1334extern struct aic7770_identity aic7770_ident_table [];
1335extern const int ahd_num_aic7770_devs;
1336
1337#define AHD_EISA_SLOT_OFFSET 0xc00
1338#define AHD_EISA_IOSIZE 0x100
1339
1340/*************************** Function Declarations ****************************/
1341/******************************************************************************/
1342void ahd_reset_cmds_pending(struct ahd_softc *ahd);
1343u_int ahd_find_busy_tcl(struct ahd_softc *ahd, u_int tcl);
1344void ahd_busy_tcl(struct ahd_softc *ahd,
1345 u_int tcl, u_int busyid);
1346static __inline void ahd_unbusy_tcl(struct ahd_softc *ahd, u_int tcl);
1347static __inline void
1348ahd_unbusy_tcl(struct ahd_softc *ahd, u_int tcl)
1349{
1350 ahd_busy_tcl(ahd, tcl, SCB_LIST_NULL);
1351}
1352
1353/***************************** PCI Front End *********************************/
1354struct ahd_pci_identity *ahd_find_pci_device(ahd_dev_softc_t);
1355int ahd_pci_config(struct ahd_softc *,
1356 struct ahd_pci_identity *);
1357int ahd_pci_test_register_access(struct ahd_softc *);
1358
1359/************************** SCB and SCB queue management **********************/
1360int ahd_probe_scbs(struct ahd_softc *);
1361void ahd_qinfifo_requeue_tail(struct ahd_softc *ahd,
1362 struct scb *scb);
1363int ahd_match_scb(struct ahd_softc *ahd, struct scb *scb,
1364 int target, char channel, int lun,
1365 u_int tag, role_t role);
1366
1367/****************************** Initialization ********************************/
1368struct ahd_softc *ahd_alloc(void *platform_arg, char *name);
1369int ahd_softc_init(struct ahd_softc *);
1370void ahd_controller_info(struct ahd_softc *ahd, char *buf);
1371int ahd_init(struct ahd_softc *ahd);
1372int ahd_default_config(struct ahd_softc *ahd);
1373int ahd_parse_vpddata(struct ahd_softc *ahd,
1374 struct vpd_config *vpd);
1375int ahd_parse_cfgdata(struct ahd_softc *ahd,
1376 struct seeprom_config *sc);
1377void ahd_intr_enable(struct ahd_softc *ahd, int enable);
1378void ahd_update_coalescing_values(struct ahd_softc *ahd,
1379 u_int timer,
1380 u_int maxcmds,
1381 u_int mincmds);
1382void ahd_enable_coalescing(struct ahd_softc *ahd,
1383 int enable);
1384void ahd_pause_and_flushwork(struct ahd_softc *ahd);
1385int ahd_suspend(struct ahd_softc *ahd);
1386int ahd_resume(struct ahd_softc *ahd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387void ahd_set_unit(struct ahd_softc *, int);
1388void ahd_set_name(struct ahd_softc *, char *);
1389struct scb *ahd_get_scb(struct ahd_softc *ahd, u_int col_idx);
1390void ahd_free_scb(struct ahd_softc *ahd, struct scb *scb);
1391void ahd_alloc_scbs(struct ahd_softc *ahd);
1392void ahd_free(struct ahd_softc *ahd);
1393int ahd_reset(struct ahd_softc *ahd, int reinit);
1394void ahd_shutdown(void *arg);
1395int ahd_write_flexport(struct ahd_softc *ahd,
1396 u_int addr, u_int value);
1397int ahd_read_flexport(struct ahd_softc *ahd, u_int addr,
1398 uint8_t *value);
1399int ahd_wait_flexport(struct ahd_softc *ahd);
1400
1401/*************************** Interrupt Services *******************************/
1402void ahd_pci_intr(struct ahd_softc *ahd);
1403void ahd_clear_intstat(struct ahd_softc *ahd);
1404void ahd_flush_qoutfifo(struct ahd_softc *ahd);
1405void ahd_run_qoutfifo(struct ahd_softc *ahd);
1406#ifdef AHD_TARGET_MODE
1407void ahd_run_tqinfifo(struct ahd_softc *ahd, int paused);
1408#endif
1409void ahd_handle_hwerrint(struct ahd_softc *ahd);
1410void ahd_handle_seqint(struct ahd_softc *ahd, u_int intstat);
1411void ahd_handle_scsiint(struct ahd_softc *ahd,
1412 u_int intstat);
1413void ahd_clear_critical_section(struct ahd_softc *ahd);
1414
1415/***************************** Error Recovery *********************************/
1416typedef enum {
1417 SEARCH_COMPLETE,
1418 SEARCH_COUNT,
1419 SEARCH_REMOVE,
1420 SEARCH_PRINT
1421} ahd_search_action;
1422int ahd_search_qinfifo(struct ahd_softc *ahd, int target,
1423 char channel, int lun, u_int tag,
1424 role_t role, uint32_t status,
1425 ahd_search_action action);
1426int ahd_search_disc_list(struct ahd_softc *ahd, int target,
1427 char channel, int lun, u_int tag,
1428 int stop_on_first, int remove,
1429 int save_state);
1430void ahd_freeze_devq(struct ahd_softc *ahd, struct scb *scb);
1431int ahd_reset_channel(struct ahd_softc *ahd, char channel,
1432 int initiate_reset);
1433int ahd_abort_scbs(struct ahd_softc *ahd, int target,
1434 char channel, int lun, u_int tag,
1435 role_t role, uint32_t status);
1436void ahd_restart(struct ahd_softc *ahd);
1437void ahd_clear_fifo(struct ahd_softc *ahd, u_int fifo);
1438void ahd_handle_scb_status(struct ahd_softc *ahd,
1439 struct scb *scb);
1440void ahd_handle_scsi_status(struct ahd_softc *ahd,
1441 struct scb *scb);
1442void ahd_calc_residual(struct ahd_softc *ahd,
1443 struct scb *scb);
1444/*************************** Utility Functions ********************************/
1445struct ahd_phase_table_entry*
1446 ahd_lookup_phase_entry(int phase);
1447void ahd_compile_devinfo(struct ahd_devinfo *devinfo,
1448 u_int our_id, u_int target,
1449 u_int lun, char channel,
1450 role_t role);
1451/************************** Transfer Negotiation ******************************/
1452void ahd_find_syncrate(struct ahd_softc *ahd, u_int *period,
1453 u_int *ppr_options, u_int maxsync);
1454void ahd_validate_offset(struct ahd_softc *ahd,
1455 struct ahd_initiator_tinfo *tinfo,
1456 u_int period, u_int *offset,
1457 int wide, role_t role);
1458void ahd_validate_width(struct ahd_softc *ahd,
1459 struct ahd_initiator_tinfo *tinfo,
1460 u_int *bus_width,
1461 role_t role);
1462/*
1463 * Negotiation types. These are used to qualify if we should renegotiate
1464 * even if our goal and current transport parameters are identical.
1465 */
1466typedef enum {
1467 AHD_NEG_TO_GOAL, /* Renegotiate only if goal and curr differ. */
1468 AHD_NEG_IF_NON_ASYNC, /* Renegotiate so long as goal is non-async. */
1469 AHD_NEG_ALWAYS /* Renegotiat even if goal is async. */
1470} ahd_neg_type;
1471int ahd_update_neg_request(struct ahd_softc*,
1472 struct ahd_devinfo*,
1473 struct ahd_tmode_tstate*,
1474 struct ahd_initiator_tinfo*,
1475 ahd_neg_type);
1476void ahd_set_width(struct ahd_softc *ahd,
1477 struct ahd_devinfo *devinfo,
1478 u_int width, u_int type, int paused);
1479void ahd_set_syncrate(struct ahd_softc *ahd,
1480 struct ahd_devinfo *devinfo,
1481 u_int period, u_int offset,
1482 u_int ppr_options,
1483 u_int type, int paused);
1484typedef enum {
1485 AHD_QUEUE_NONE,
1486 AHD_QUEUE_BASIC,
1487 AHD_QUEUE_TAGGED
1488} ahd_queue_alg;
1489
1490void ahd_set_tags(struct ahd_softc *ahd,
1491 struct ahd_devinfo *devinfo,
1492 ahd_queue_alg alg);
1493
1494/**************************** Target Mode *************************************/
1495#ifdef AHD_TARGET_MODE
1496void ahd_send_lstate_events(struct ahd_softc *,
1497 struct ahd_tmode_lstate *);
1498void ahd_handle_en_lun(struct ahd_softc *ahd,
1499 struct cam_sim *sim, union ccb *ccb);
1500cam_status ahd_find_tmode_devs(struct ahd_softc *ahd,
1501 struct cam_sim *sim, union ccb *ccb,
1502 struct ahd_tmode_tstate **tstate,
1503 struct ahd_tmode_lstate **lstate,
1504 int notfound_failure);
1505#ifndef AHD_TMODE_ENABLE
1506#define AHD_TMODE_ENABLE 0
1507#endif
1508#endif
1509/******************************* Debug ***************************************/
1510#ifdef AHD_DEBUG
1511extern uint32_t ahd_debug;
1512#define AHD_SHOW_MISC 0x00001
1513#define AHD_SHOW_SENSE 0x00002
1514#define AHD_SHOW_RECOVERY 0x00004
1515#define AHD_DUMP_SEEPROM 0x00008
1516#define AHD_SHOW_TERMCTL 0x00010
1517#define AHD_SHOW_MEMORY 0x00020
1518#define AHD_SHOW_MESSAGES 0x00040
1519#define AHD_SHOW_MODEPTR 0x00080
1520#define AHD_SHOW_SELTO 0x00100
1521#define AHD_SHOW_FIFOS 0x00200
1522#define AHD_SHOW_QFULL 0x00400
1523#define AHD_SHOW_DV 0x00800
1524#define AHD_SHOW_MASKED_ERRORS 0x01000
1525#define AHD_SHOW_QUEUE 0x02000
1526#define AHD_SHOW_TQIN 0x04000
1527#define AHD_SHOW_SG 0x08000
1528#define AHD_SHOW_INT_COALESCING 0x10000
1529#define AHD_DEBUG_SEQUENCER 0x20000
1530#endif
1531void ahd_print_scb(struct scb *scb);
1532void ahd_print_devinfo(struct ahd_softc *ahd,
1533 struct ahd_devinfo *devinfo);
1534void ahd_dump_sglist(struct scb *scb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535void ahd_dump_card_state(struct ahd_softc *ahd);
1536int ahd_print_register(ahd_reg_parse_entry_t *table,
1537 u_int num_entries,
1538 const char *name,
1539 u_int address,
1540 u_int value,
1541 u_int *cur_column,
1542 u_int wrap_point);
1543void ahd_dump_scbs(struct ahd_softc *ahd);
1544#endif /* _AIC79XX_H_ */