2 * Adaptec AIC7xxx device driver for Linux.
4 * Copyright (c) 1994 John Aycock
5 * The University of Calgary Department of Computer Science.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_linux.h#72 $
23 * Copyright (c) 2000-2001 Adaptec Inc.
24 * All rights reserved.
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
29 * 1. Redistributions of source code must retain the above copyright
30 * notice, this list of conditions, and the following disclaimer,
31 * without modification.
32 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
33 * substantially similar to the "NO WARRANTY" disclaimer below
34 * ("Disclaimer") and any redistribution must be conditioned upon
35 * including a substantially similar Disclaimer requirement for further
36 * binary redistribution.
37 * 3. Neither the names of the above-listed copyright holders nor the names
38 * of any contributors may be used to endorse or promote products derived
39 * from this software without specific prior written permission.
41 * Alternatively, this software may be distributed under the terms of the
42 * GNU General Public License ("GPL") version 2 as published by the Free
43 * Software Foundation.
46 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
47 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
48 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
49 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
50 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
54 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
55 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
56 * POSSIBILITY OF SUCH DAMAGES.
58 * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_linux.h#72 $
61 #ifndef _AIC7XXX_LINUX_H_
62 #define _AIC7XXX_LINUX_H_
64 #include <linux/types.h>
65 #include <linux/blk.h>
66 #include <linux/blkdev.h>
67 #include <linux/delay.h>
68 #include <linux/interrupt.h>
69 #include <linux/ioport.h>
70 #include <linux/slab.h>
71 #include <linux/pci.h>
72 #include <linux/version.h>
73 #include <linux/module.h>
74 #include <asm/byteorder.h>
76 #ifndef KERNEL_VERSION
77 #define KERNEL_VERSION(x,y,z) (((x)<<16)+((y)<<8)+(z))
80 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
81 #include <linux/config.h>
84 /* Core SCSI definitions */
88 /* Name space conflict with BSD queue macros */
95 #include "scsi_message.h"
97 /************************* Forward Declarations *******************************/
99 typedef struct pci_dev
*ahc_dev_softc_t
;
100 typedef Scsi_Cmnd
*ahc_io_ctx_t
;
102 /******************************* Byte Order ***********************************/
103 #define ahc_htobe16(x) cpu_to_be16(x)
104 #define ahc_htobe32(x) cpu_to_be32(x)
105 #define ahc_htobe64(x) cpu_to_be64(x)
106 #define ahc_htole16(x) cpu_to_le16(x)
107 #define ahc_htole32(x) cpu_to_le32(x)
108 #define ahc_htole64(x) cpu_to_le64(x)
110 #define ahc_be16toh(x) be16_to_cpu(x)
111 #define ahc_be32toh(x) be32_to_cpu(x)
112 #define ahc_be64toh(x) be64_to_cpu(x)
113 #define ahc_le16toh(x) le16_to_cpu(x)
114 #define ahc_le32toh(x) le32_to_cpu(x)
115 #define ahc_le64toh(x) le64_to_cpu(x)
117 #ifndef LITTLE_ENDIAN
118 #define LITTLE_ENDIAN 1234
122 #define BIG_ENDIAN 4321
126 #if defined(__BIG_ENDIAN)
127 #define BYTE_ORDER BIG_ENDIAN
129 #if defined(__LITTLE_ENDIAN)
130 #define BYTE_ORDER LITTLE_ENDIAN
132 #endif /* BYTE_ORDER */
134 /************************* Configuration Data *********************************/
135 extern int aic7xxx_no_probe
;
136 extern int aic7xxx_detect_complete
;
137 extern Scsi_Host_Template
* aic7xxx_driver_template
;
139 /***************************** Bus Space/DMA **********************************/
141 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,2,17)
142 typedef dma_addr_t bus_addr_t
;
144 typedef uint32_t bus_addr_t
;
146 typedef uint32_t bus_size_t
;
155 volatile uint8_t *maddr
;
156 } bus_space_handle_t
;
158 typedef struct bus_dma_segment
164 struct ahc_linux_dma_tag
166 bus_size_t alignment
;
170 typedef struct ahc_linux_dma_tag
* bus_dma_tag_t
;
172 struct ahc_linux_dmamap
176 typedef struct ahc_linux_dmamap
* bus_dmamap_t
;
178 typedef int bus_dma_filter_t(void*, bus_addr_t
);
179 typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t
*, int, int);
181 #define BUS_DMA_WAITOK 0x0
182 #define BUS_DMA_NOWAIT 0x1
183 #define BUS_DMA_ALLOCNOW 0x2
184 #define BUS_DMA_LOAD_SEGS 0x4 /*
185 * Argument is an S/G list not
189 #define BUS_SPACE_MAXADDR 0xFFFFFFFF
190 #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
191 #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
193 int ahc_dma_tag_create(struct ahc_softc
*, bus_dma_tag_t
/*parent*/,
194 bus_size_t
/*alignment*/, bus_size_t
/*boundary*/,
195 bus_addr_t
/*lowaddr*/, bus_addr_t
/*highaddr*/,
196 bus_dma_filter_t*/
*filter*/
, void */
*filterarg*/
,
197 bus_size_t
/*maxsize*/, int /*nsegments*/,
198 bus_size_t
/*maxsegsz*/, int /*flags*/,
199 bus_dma_tag_t */
*dma_tagp*/
);
201 void ahc_dma_tag_destroy(struct ahc_softc
*, bus_dma_tag_t
/*tag*/);
203 int ahc_dmamem_alloc(struct ahc_softc
*, bus_dma_tag_t
/*dmat*/,
204 void** /*vaddr*/, int /*flags*/,
205 bus_dmamap_t
* /*mapp*/);
207 void ahc_dmamem_free(struct ahc_softc
*, bus_dma_tag_t
/*dmat*/,
208 void* /*vaddr*/, bus_dmamap_t
/*map*/);
210 void ahc_dmamap_destroy(struct ahc_softc
*, bus_dma_tag_t
/*tag*/,
211 bus_dmamap_t
/*map*/);
213 int ahc_dmamap_load(struct ahc_softc
*ahc
, bus_dma_tag_t
/*dmat*/,
214 bus_dmamap_t
/*map*/, void * /*buf*/,
215 bus_size_t
/*buflen*/, bus_dmamap_callback_t
*,
216 void */
*callback_arg*/
, int /*flags*/);
218 int ahc_dmamap_unload(struct ahc_softc
*, bus_dma_tag_t
, bus_dmamap_t
);
221 * Operations performed by ahc_dmamap_sync().
223 #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
224 #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
225 #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
226 #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
230 * ahc_dmamap_sync is only used on buffers allocated with
231 * the pci_alloc_consistent() API. Although I'm not sure how
232 * this works on architectures with a write buffer, Linux does
233 * not have an API to sync "coherent" memory. Perhaps we need
236 #define ahc_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op)
238 /************************** SCSI Constants/Structures *************************/
240 #define SCSI_STATUS_OK 0x00
241 #define SCSI_STATUS_CHECK_COND 0x02
242 #define SCSI_STATUS_COND_MET 0x04
243 #define SCSI_STATUS_BUSY 0x08
244 #define SCSI_STATUS_INTERMED 0x10
245 #define SCSI_STATUS_INTERMED_COND_MET 0x14
246 #define SCSI_STATUS_RESERV_CONFLICT 0x18
247 #define SCSI_STATUS_CMD_TERMINATED 0x22
248 #define SCSI_STATUS_QUEUE_FULL 0x28
251 * 6 byte request sense CDB format.
262 struct scsi_sense_data
269 uint8_t cmd_spec_info
[4];
270 uint8_t add_sense_code
;
271 uint8_t add_sense_code_qual
;
273 uint8_t sense_key_spec
[3];
274 uint8_t extra_bytes
[14];
288 struct scsi_inquiry_data
291 #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
292 #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
293 #define SID_QUAL_LU_CONNECTED 0x00 /*
294 * The specified peripheral device
295 * type is currently connected to
296 * logical unit. If the target cannot
297 * determine whether or not a physical
298 * device is currently connected, it
299 * shall also use this peripheral
300 * qualifier when returning the INQUIRY
301 * data. This peripheral qualifier
302 * does not mean that the device is
303 * ready for access by the initiator.
305 #define SID_QUAL_LU_OFFLINE 0x01 /*
306 * The target is capable of supporting
307 * the specified peripheral device type
308 * on this logical unit; however, the
309 * physical device is not currently
310 * connected to this logical unit.
312 #define SID_QUAL_RSVD 0x02
313 #define SID_QUAL_BAD_LU 0x03 /*
314 * The target is not capable of
315 * supporting a physical device on
316 * this logical unit. For this
317 * peripheral qualifier the peripheral
318 * device type shall be set to 1Fh to
319 * provide compatibility with previous
320 * versions of SCSI. All other
321 * peripheral device type values are
322 * reserved for this peripheral
325 #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0)
327 #define SID_QUAL2 0x7F
328 #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0)
330 #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
332 #define SCSI_REV_CCS 1
334 #define SCSI_REV_SPC 3
335 #define SCSI_REV_SPC2 4
337 #define SID_ECMA 0x38
339 uint8_t response_format
;
340 #define SID_AENC 0x80
341 #define SID_TrmIOP 0x40
342 uint8_t additional_length
;
345 #define SID_SftRe 0x01
346 #define SID_CmdQue 0x02
347 #define SID_Linked 0x08
348 #define SID_Sync 0x10
349 #define SID_WBus16 0x20
350 #define SID_WBus32 0x40
351 #define SID_RelAdr 0x80
352 #define SID_VENDOR_SIZE 8
353 char vendor
[SID_VENDOR_SIZE
];
354 #define SID_PRODUCT_SIZE 16
355 char product
[SID_PRODUCT_SIZE
];
356 #define SID_REVISION_SIZE 4
357 char revision
[SID_REVISION_SIZE
];
359 * The following fields were taken from SCSI Primary Commands - 2
360 * (SPC-2) Revision 14, Dated 11 November 1999
362 #define SID_VENDOR_SPECIFIC_0_SIZE 20
363 u_int8_t vendor_specific0
[SID_VENDOR_SPECIFIC_0_SIZE
];
365 * An extension of SCSI Parallel Specific Values
367 #define SID_SPI_IUS 0x01
368 #define SID_SPI_QAS 0x02
369 #define SID_SPI_CLOCK_ST 0x00
370 #define SID_SPI_CLOCK_DT 0x04
371 #define SID_SPI_CLOCK_DT_ST 0x0C
372 #define SID_SPI_MASK 0x0F
376 * Version Descriptors, stored 2 byte values.
387 uint8_t reserved3
[22];
389 #define SID_VENDOR_SPECIFIC_1_SIZE 160
390 uint8_t vendor_specific1
[SID_VENDOR_SPECIFIC_1_SIZE
];
393 /********************************** Includes **********************************/
394 /* Host template and function declarations referenced by the template. */
395 #include "aic7xxx_linux_host.h"
397 /* Core driver definitions */
401 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,17)
402 #include <linux/spinlock.h>
403 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,93)
404 #include <linux/smp.h>
407 #define AIC7XXX_DRIVER_VERSION "6.2.4"
409 /**************************** Front End Queues ********************************/
411 * Data structure used to cast the Linux struct scsi_cmnd to something
412 * that allows us to use the queue macros. The linux structure has
413 * plenty of space to hold the links fields as required by the queue
414 * macros, but the queue macors require them to have the correct type.
416 struct ahc_cmd_internal
{
417 /* Area owned by the Linux scsi layer. */
418 uint8_t private[offsetof(struct scsi_cmnd
, SCp
.Status
)];
420 STAILQ_ENTRY(ahc_cmd
) ste
;
421 LIST_ENTRY(ahc_cmd
) le
;
422 TAILQ_ENTRY(ahc_cmd
) tqe
;
429 struct ahc_cmd_internal icmd
;
430 struct scsi_cmnd scsi_cmd
;
434 #define acmd_icmd(cmd) ((cmd)->un.icmd)
435 #define acmd_scsi_cmd(cmd) ((cmd)->un.scsi_cmd)
436 #define acmd_links un.icmd.links
438 /*************************** Device Data Structures ***************************/
440 * A per probed device structure used to deal with some error recovery
441 * scenarios that the Linux mid-layer code just doesn't know how to
442 * handle. The structure allocated for a device only becomes persistant
443 * after a successfully completed inquiry command to the target when
444 * that inquiry data indicates a lun is present.
446 TAILQ_HEAD(ahc_busyq
, ahc_cmd
);
448 AHC_DEV_UNCONFIGURED
= 0x01,
449 AHC_DEV_FREEZE_TIL_EMPTY
= 0x02, /* Freeze queue until active == 0 */
450 AHC_DEV_TIMER_ACTIVE
= 0x04, /* Our timer is active */
451 AHC_DEV_ON_RUN_LIST
= 0x08, /* Queued to be run later */
452 AHC_DEV_Q_BASIC
= 0x10, /* Allow basic device queuing */
453 AHC_DEV_Q_TAGGED
= 0x20, /* Allow full SCSI2 command queueing */
454 AHC_DEV_PERIODIC_OTAG
= 0x40 /* Send OTAG to prevent starvation */
457 struct ahc_linux_target
;
458 struct ahc_linux_device
{
459 TAILQ_ENTRY(ahc_linux_device
) links
;
460 struct ahc_busyq busyq
;
463 * The number of transactions currently
464 * queued to the device.
469 * The currently allowed number of
470 * transactions that can be queued to
471 * the device. Must be signed for
472 * conversion from tagged to untagged
473 * mode where the device may have more
474 * than one outstanding active transaction.
479 * A positive count indicates that this
480 * device's queue is halted.
485 * Cumulative command counter.
487 u_long commands_issued
;
490 * The number of tagged transactions when
491 * running at our current opening level
492 * that have been successfully received by
493 * this device since the last QUEUE FULL.
495 u_int tag_success_count
;
496 #define AHC_TAG_SUCCESS_INTERVAL 50
501 * The high limit for the tags variable.
506 * The computed number of tags outstanding
507 * at the time of the last QUEUE FULL event.
509 u_int tags_on_last_queuefull
;
512 * How many times we have seen a queue full
513 * with the same number of tags. This is used
514 * to stop our adaptive queue depth algorithm
515 * on devices with a fixed number of tags.
517 u_int last_queuefull_same_count
;
518 #define AHC_LOCK_TAGS_COUNT 50
521 * How many transactions have been queued
522 * without the device going idle. We use
523 * this statistic to determine when to issue
524 * an ordered tag to prevent transaction
525 * starvation. This statistic is only updated
526 * if the AHC_DEV_PERIODIC_OTAG flag is set
529 u_int commands_since_idle_or_otag
;
530 #define AHC_OTAG_THRESH 500
533 struct ahc_linux_target
*target
;
536 struct ahc_linux_target
{
537 struct ahc_linux_device
*devices
[AHC_NUM_LUNS
];
541 struct ahc_transinfo last_tinfo
;
544 /********************* Definitions Required by the Core ***********************/
546 * Number of SG segments we require. So long as the S/G segments for
547 * a particular transaction are allocated in a physically contiguous
548 * manner and are allocated below 4GB, the number of S/G segments is
554 * Per-SCB OSM storage.
556 struct scb_platform_data
{
557 struct ahc_linux_device
*dev
;
559 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
560 uint32_t resid
; /* Transfer residual */
565 * Define a structure used for each host adapter. All members are
566 * aligned on a boundary >= the size of the member to honor the
567 * alignment restrictions of the various platforms supported by
570 TAILQ_HEAD(ahc_completeq
, ahc_cmd
);
571 struct ahc_platform_data
{
573 * Fields accessed from interrupt context.
575 struct ahc_linux_target
*targets
[AHC_NUM_TARGETS
];
576 TAILQ_HEAD(, ahc_linux_device
) device_runq
;
577 struct ahc_completeq completeq
;
580 struct timer_list reset_timer
;
581 struct semaphore eh_sem
;
582 struct Scsi_Host
*host
; /* pointer to scsi host */
583 uint32_t irq
; /* IRQ for this adapter */
584 uint32_t bios_address
;
585 uint32_t mem_busaddr
; /* Mem Base Addr */
586 bus_addr_t hw_dma_mask
;
589 /************************** OS Utility Wrappers *******************************/
590 #define printf printk
591 #define M_NOWAIT GFP_ATOMIC
593 #define malloc(size, type, flags) kmalloc(size, flags)
594 #define free(ptr, type) kfree(ptr)
596 static __inline
void ahc_delay(long);
601 * udelay on Linux can have problems for
602 * multi-millisecond waits. Wait at most
612 /***************************** Low Level I/O **********************************/
613 #if defined(__powerpc__) || defined(__i386__) || defined(__ia64__)
617 static __inline
uint8_t ahc_inb(struct ahc_softc
* ahc
, long port
);
618 static __inline
void ahc_outb(struct ahc_softc
* ahc
, long port
, uint8_t val
);
619 static __inline
void ahc_outsb(struct ahc_softc
* ahc
, long port
,
620 uint8_t *, int count
);
621 static __inline
void ahc_insb(struct ahc_softc
* ahc
, long port
,
622 uint8_t *, int count
);
624 static __inline
uint8_t
625 ahc_inb(struct ahc_softc
* ahc
, long port
)
630 if (ahc
->tag
== BUS_SPACE_MEMIO
) {
631 x
= readb(ahc
->bsh
.maddr
+ port
);
633 x
= inb(ahc
->bsh
.ioport
+ port
);
636 x
= inb(ahc
->bsh
.ioport
+ port
);
643 ahc_outb(struct ahc_softc
* ahc
, long port
, uint8_t val
)
646 if (ahc
->tag
== BUS_SPACE_MEMIO
) {
647 writeb(val
, ahc
->bsh
.maddr
+ port
);
649 outb(val
, ahc
->bsh
.ioport
+ port
);
652 outb(val
, ahc
->bsh
.ioport
+ port
);
658 ahc_outsb(struct ahc_softc
* ahc
, long port
, uint8_t *array
, int count
)
663 * There is probably a more efficient way to do this on Linux
664 * but we don't use this for anything speed critical and this
667 for (i
= 0; i
< count
; i
++)
668 ahc_outb(ahc
, port
, *array
++);
672 ahc_insb(struct ahc_softc
* ahc
, long port
, uint8_t *array
, int count
)
677 * There is probably a more efficient way to do this on Linux
678 * but we don't use this for anything speed critical and this
681 for (i
= 0; i
< count
; i
++)
682 *array
++ = ahc_inb(ahc
, port
);
685 /**************************** Initialization **********************************/
686 int ahc_linux_register_host(struct ahc_softc
*,
687 Scsi_Host_Template
*);
689 uint64_t ahc_linux_get_memsize(void);
691 /*************************** Pretty Printing **********************************/
699 void ahc_format_transinfo(struct info_str
*info
,
700 struct ahc_transinfo
*tinfo
);
702 /******************************** Locking *************************************/
703 /* Lock protecting internal data structures */
704 static __inline
void ahc_lockinit(struct ahc_softc
*);
705 static __inline
void ahc_lock(struct ahc_softc
*, unsigned long *flags
);
706 static __inline
void ahc_unlock(struct ahc_softc
*, unsigned long *flags
);
708 /* Lock held during command compeletion to the upper layer */
709 static __inline
void ahc_done_lockinit(struct ahc_softc
*);
710 static __inline
void ahc_done_lock(struct ahc_softc
*, unsigned long *flags
);
711 static __inline
void ahc_done_unlock(struct ahc_softc
*, unsigned long *flags
);
713 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,93)
715 ahc_lockinit(struct ahc_softc
*ahc
)
717 spin_lock_init(ahc
->platform_data
->host
->host_lock
);
721 ahc_lock(struct ahc_softc
*ahc
, unsigned long *flags
)
724 spin_lock_irqsave(ahc
->platform_data
->host
->host_lock
, *flags
);
728 ahc_unlock(struct ahc_softc
*ahc
, unsigned long *flags
)
730 spin_unlock_irqrestore(ahc
->platform_data
->host
->host_lock
, *flags
);
734 ahc_done_lockinit(struct ahc_softc
*ahc
)
736 /* We don't own the iorequest lock, so we don't initialize it. */
740 ahc_done_lock(struct ahc_softc
*ahc
, unsigned long *flags
)
742 struct Scsi_Host
*host
= ahc
->platform_data
->host
;
745 spin_lock_irqsave(host
->host_lock
, *flags
);
749 ahc_done_unlock(struct ahc_softc
*ahc
, unsigned long *flags
)
751 struct Scsi_Host
*host
= ahc
->platform_data
->host
;
753 spin_unlock_irqrestore(host
->host_lock
, *flags
);
756 #else /* LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0) */
758 ahc_lockinit(struct ahc_softc
*ahc
)
763 ahc_lock(struct ahc_softc
*ahc
, unsigned long *flags
)
771 ahc_unlock(struct ahc_softc
*ahc
, unsigned long *flags
)
773 restore_flags(*flags
);
776 ahc_done_lockinit(struct ahc_softc
*ahc
)
781 ahc_done_lock(struct ahc_softc
*ahc
, unsigned long *flags
)
784 * The done lock is always held while
785 * the ahc lock is held so blocking
786 * interrupts again would have no effect.
791 ahc_done_unlock(struct ahc_softc
*ahc
, unsigned long *flags
)
794 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0) */
796 /******************************* PCI Definitions ******************************/
798 * PCIM_xxx: mask to locate subfield in register
799 * PCIR_xxx: config register offset
800 * PCIC_xxx: device class
801 * PCIS_xxx: device subclass
802 * PCIP_xxx: device programming interface
803 * PCIV_xxx: PCI vendor ID (only required to fixup ancient devices)
804 * PCID_xxx: device ID
806 #define PCIR_DEVVENDOR 0x00
807 #define PCIR_VENDOR 0x00
808 #define PCIR_DEVICE 0x02
809 #define PCIR_COMMAND 0x04
810 #define PCIM_CMD_PORTEN 0x0001
811 #define PCIM_CMD_MEMEN 0x0002
812 #define PCIM_CMD_BUSMASTEREN 0x0004
813 #define PCIM_CMD_MWRICEN 0x0010
814 #define PCIM_CMD_PERRESPEN 0x0040
815 #define PCIR_STATUS 0x06
816 #define PCIR_REVID 0x08
817 #define PCIR_PROGIF 0x09
818 #define PCIR_SUBCLASS 0x0a
819 #define PCIR_CLASS 0x0b
820 #define PCIR_CACHELNSZ 0x0c
821 #define PCIR_LATTIMER 0x0d
822 #define PCIR_HEADERTYPE 0x0e
823 #define PCIM_MFDEV 0x80
824 #define PCIR_BIST 0x0f
825 #define PCIR_CAP_PTR 0x34
827 /* config registers for header type 0 devices */
828 #define PCIR_MAPS 0x10
829 #define PCIR_SUBVEND_0 0x2c
830 #define PCIR_SUBDEV_0 0x2e
832 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
833 extern struct pci_driver aic7xxx_pci_driver
;
844 void ahc_power_state_change(struct ahc_softc
*ahc
,
845 ahc_power_state new_state
);
846 /**************************** VL/EISA Routines ********************************/
847 int aic7770_linux_probe(Scsi_Host_Template
*);
848 int aic7770_map_registers(struct ahc_softc
*ahc
);
849 int aic7770_map_int(struct ahc_softc
*ahc
, u_int irq
);
851 /******************************* PCI Routines *********************************/
853 * We need to use the bios32.h routines if we are kernel version 2.1.92 or less.
855 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,1,92)
856 #if defined(__sparc_v9__) || defined(__powerpc__)
857 #error "PPC and Sparc platforms are only support under 2.1.92 and above"
859 #include <linux/bios32.h>
862 int ahc_linux_pci_probe(Scsi_Host_Template
*);
863 int ahc_pci_map_registers(struct ahc_softc
*ahc
);
864 int ahc_pci_map_int(struct ahc_softc
*ahc
);
866 static __inline
uint32_t ahc_pci_read_config(ahc_dev_softc_t pci
,
869 static __inline
uint32_t
870 ahc_pci_read_config(ahc_dev_softc_t pci
, int reg
, int width
)
877 pci_read_config_byte(pci
, reg
, &retval
);
883 pci_read_config_word(pci
, reg
, &retval
);
889 pci_read_config_dword(pci
, reg
, &retval
);
893 panic("ahc_pci_read_config: Read size too big");
899 static __inline
void ahc_pci_write_config(ahc_dev_softc_t pci
,
900 int reg
, uint32_t value
,
904 ahc_pci_write_config(ahc_dev_softc_t pci
, int reg
, uint32_t value
, int width
)
908 pci_write_config_byte(pci
, reg
, value
);
911 pci_write_config_word(pci
, reg
, value
);
914 pci_write_config_dword(pci
, reg
, value
);
917 panic("ahc_pci_write_config: Write size too big");
922 static __inline
int ahc_get_pci_function(ahc_dev_softc_t
);
924 ahc_get_pci_function(ahc_dev_softc_t pci
)
926 return (PCI_FUNC(pci
->devfn
));
929 static __inline
int ahc_get_pci_slot(ahc_dev_softc_t
);
931 ahc_get_pci_slot(ahc_dev_softc_t pci
)
933 return (PCI_SLOT(pci
->devfn
));
936 static __inline
int ahc_get_pci_bus(ahc_dev_softc_t
);
938 ahc_get_pci_bus(ahc_dev_softc_t pci
)
940 return (pci
->bus
->number
);
943 static __inline
void ahc_flush_device_writes(struct ahc_softc
*);
945 ahc_flush_device_writes(struct ahc_softc
*ahc
)
947 /* XXX Is this sufficient for all architectures??? */
948 ahc_inb(ahc
, INTSTAT
);
951 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,0)
952 #define pci_map_sg(pdev, sg_list, nseg, direction) (nseg)
953 #define pci_unmap_sg(pdev, sg_list, nseg, direction)
954 #define sg_dma_address(sg) (VIRT_TO_BUS((sg)->address))
955 #define sg_dma_len(sg) ((sg)->length)
956 #define pci_map_single(pdev, buffer, bufflen, direction) \
957 (VIRT_TO_BUS(buffer))
958 #define pci_unmap_single(pdev, buffer, buflen, direction)
961 /*********************** Transaction Access Wrappers **************************/
962 static __inline
void ahc_set_transaction_status(struct scb
*, uint32_t);
964 void ahc_set_transaction_status(struct scb
*scb
, uint32_t status
)
966 scb
->io_ctx
->result
&= ~(CAM_STATUS_MASK
<< 16);
967 scb
->io_ctx
->result
|= status
<< 16;
970 static __inline
void ahc_set_scsi_status(struct scb
*, uint32_t);
972 void ahc_set_scsi_status(struct scb
*scb
, uint32_t status
)
974 scb
->io_ctx
->result
&= ~0xFFFF;
975 scb
->io_ctx
->result
|= status
;
978 static __inline
uint32_t ahc_get_transaction_status(struct scb
*);
980 uint32_t ahc_get_transaction_status(struct scb
*scb
)
982 return ((scb
->io_ctx
->result
>> 16) & CAM_STATUS_MASK
);
985 static __inline
uint32_t ahc_get_scsi_status(struct scb
*);
987 uint32_t ahc_get_scsi_status(struct scb
*scb
)
989 return (scb
->io_ctx
->result
& 0xFFFF);
992 static __inline
void ahc_set_transaction_tag(struct scb
*, int, u_int
);
994 void ahc_set_transaction_tag(struct scb
*scb
, int enabled
, u_int type
)
997 * Nothing to do for linux as the incoming transaction
998 * has no concept of tag/non tagged, etc.
1002 static __inline u_long
ahc_get_transfer_length(struct scb
*);
1004 u_long
ahc_get_transfer_length(struct scb
*scb
)
1006 return (scb
->platform_data
->xfer_len
);
1009 static __inline
int ahc_get_transfer_dir(struct scb
*);
1011 int ahc_get_transfer_dir(struct scb
*scb
)
1013 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,40)
1014 return (scb
->io_ctx
->sc_data_direction
);
1016 if (scb
->io_ctx
->bufflen
== 0)
1017 return (CAM_DIR_NONE
);
1019 switch(scb
->io_ctx
->cmnd
[0]) {
1020 case 0x08: /* READ(6) */
1021 case 0x28: /* READ(10) */
1022 case 0xA8: /* READ(12) */
1023 return (CAM_DIR_IN
);
1024 case 0x0A: /* WRITE(6) */
1025 case 0x2A: /* WRITE(10) */
1026 case 0xAA: /* WRITE(12) */
1027 return (CAM_DIR_OUT
);
1029 return (CAM_DIR_NONE
);
1034 static __inline
void ahc_set_residual(struct scb
*, u_long
);
1036 void ahc_set_residual(struct scb
*scb
, u_long resid
)
1038 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
1039 scb
->io_ctx
->resid
= resid
;
1041 scb
->platform_data
->resid
= resid
;
1045 static __inline
void ahc_set_sense_residual(struct scb
*, u_long
);
1047 void ahc_set_sense_residual(struct scb
*scb
, u_long resid
)
1049 /* This can't be reported in Linux */
1052 static __inline u_long
ahc_get_residual(struct scb
*);
1054 u_long
ahc_get_residual(struct scb
*scb
)
1056 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
1057 return (scb
->io_ctx
->resid
);
1059 return (scb
->platform_data
->resid
);
1063 static __inline
int ahc_perform_autosense(struct scb
*);
1065 int ahc_perform_autosense(struct scb
*scb
)
1068 * We always perform autosense in Linux.
1069 * On other platforms this is set on a
1070 * per-transaction basis.
1075 static __inline
uint32_t
1076 ahc_get_sense_bufsize(struct ahc_softc
*ahc
, struct scb
*scb
)
1078 return (sizeof(struct scsi_sense_data
));
1081 static __inline
void ahc_notify_xfer_settings_change(struct ahc_softc
*,
1082 struct ahc_devinfo
*);
1083 static __inline
void
1084 ahc_notify_xfer_settings_change(struct ahc_softc
*ahc
,
1085 struct ahc_devinfo
*devinfo
)
1087 /* Nothing to do here for linux */
1090 static __inline
void ahc_platform_scb_free(struct ahc_softc
*ahc
,
1092 static __inline
void
1093 ahc_platform_scb_free(struct ahc_softc
*ahc
, struct scb
*scb
)
1095 ahc
->flags
&= ~AHC_RESOURCE_SHORTAGE
;
1098 int ahc_platform_alloc(struct ahc_softc
*ahc
, void *platform_arg
);
1099 void ahc_platform_free(struct ahc_softc
*ahc
);
1100 void ahc_platform_freeze_devq(struct ahc_softc
*ahc
, struct scb
*scb
);
1101 static __inline
void ahc_freeze_scb(struct scb
*scb
);
1102 static __inline
void
1103 ahc_freeze_scb(struct scb
*scb
)
1105 /* Noting to do here for linux */
1108 void ahc_platform_set_tags(struct ahc_softc
*ahc
,
1109 struct ahc_devinfo
*devinfo
, ahc_queue_alg
);
1110 int ahc_platform_abort_scbs(struct ahc_softc
*ahc
, int target
,
1111 char channel
, int lun
, u_int tag
,
1112 role_t role
, uint32_t status
);
1113 void ahc_linux_isr(int irq
, void *dev_id
, struct pt_regs
* regs
);
1114 void ahc_platform_flushwork(struct ahc_softc
*ahc
);
1115 int ahc_softc_comp(struct ahc_softc
*, struct ahc_softc
*);
1116 void ahc_done(struct ahc_softc
*, struct scb
*);
1117 void ahc_send_async(struct ahc_softc
*, char channel
,
1118 u_int target
, u_int lun
, ac_code
, void *);
1119 void ahc_print_path(struct ahc_softc
*, struct scb
*);
1120 void ahc_platform_dump_card_state(struct ahc_softc
*ahc
);
1123 #define AHC_PCI_CONFIG 1
1125 #define AHC_PCI_CONFIG 0
1127 #define bootverbose aic7xxx_verbose
1128 extern int aic7xxx_verbose
;
1129 #endif /* _AIC7XXX_LINUX_H_ */