2 * Adaptec AIC79xx device driver for Linux.
4 * Copyright (c) 2000-2001 Adaptec Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification.
13 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14 * substantially similar to the "NO WARRANTY" disclaimer below
15 * ("Disclaimer") and any redistribution must be conditioned upon
16 * including a substantially similar Disclaimer requirement for further
17 * binary redistribution.
18 * 3. Neither the names of the above-listed copyright holders nor the names
19 * of any contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * Alternatively, this software may be distributed under the terms of the
23 * GNU General Public License ("GPL") version 2 as published by the Free
24 * Software Foundation.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
36 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGES.
39 * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic79xx_osm.h#137 $
42 #ifndef _AIC79XX_LINUX_H_
43 #define _AIC79XX_LINUX_H_
45 #include <linux/types.h>
46 #include <linux/blkdev.h>
47 #include <linux/delay.h>
48 #include <linux/ioport.h>
49 #include <linux/pci.h>
50 #include <linux/smp_lock.h>
51 #include <linux/version.h>
52 #include <linux/module.h>
53 #include <asm/byteorder.h>
56 #ifndef KERNEL_VERSION
57 #define KERNEL_VERSION(x,y,z) (((x)<<16)+((y)<<8)+(z))
60 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
61 #include <linux/interrupt.h> /* For tasklet support. */
62 #include <linux/config.h>
63 #include <linux/slab.h>
65 #include <linux/malloc.h>
68 /* Core SCSI definitions */
69 #define AIC_LIB_PREFIX ahd
71 #include <scsi/scsi_host.h>
73 /* Name space conflict with BSD queue macros */
80 #include "scsi_message.h"
84 /*********************************** Debugging ********************************/
85 #ifdef CONFIG_AIC79XX_DEBUG_ENABLE
86 #ifdef CONFIG_AIC79XX_DEBUG_MASK
88 #define AHD_DEBUG_OPTS CONFIG_AIC79XX_DEBUG_MASK
91 * Compile in debugging code, but do not enable any printfs.
94 #define AHD_DEBUG_OPTS 0
96 /* No debugging code. */
99 /********************************** Misc Macros *******************************/
100 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
101 #define powerof2(x) ((((x)-1)&(x))==0)
103 /************************* Forward Declarations *******************************/
105 typedef struct pci_dev
*ahd_dev_softc_t
;
106 typedef Scsi_Cmnd
*ahd_io_ctx_t
;
108 /******************************* Byte Order ***********************************/
109 #define ahd_htobe16(x) cpu_to_be16(x)
110 #define ahd_htobe32(x) cpu_to_be32(x)
111 #define ahd_htobe64(x) cpu_to_be64(x)
112 #define ahd_htole16(x) cpu_to_le16(x)
113 #define ahd_htole32(x) cpu_to_le32(x)
114 #define ahd_htole64(x) cpu_to_le64(x)
116 #define ahd_be16toh(x) be16_to_cpu(x)
117 #define ahd_be32toh(x) be32_to_cpu(x)
118 #define ahd_be64toh(x) be64_to_cpu(x)
119 #define ahd_le16toh(x) le16_to_cpu(x)
120 #define ahd_le32toh(x) le32_to_cpu(x)
121 #define ahd_le64toh(x) le64_to_cpu(x)
123 #ifndef LITTLE_ENDIAN
124 #define LITTLE_ENDIAN 1234
128 #define BIG_ENDIAN 4321
132 #if defined(__BIG_ENDIAN)
133 #define BYTE_ORDER BIG_ENDIAN
135 #if defined(__LITTLE_ENDIAN)
136 #define BYTE_ORDER LITTLE_ENDIAN
138 #endif /* BYTE_ORDER */
140 /************************* Configuration Data *********************************/
141 extern uint32_t aic79xx_allow_memio
;
142 extern int aic79xx_detect_complete
;
143 extern Scsi_Host_Template aic79xx_driver_template
;
145 /***************************** Bus Space/DMA **********************************/
147 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,2,17)
148 typedef dma_addr_t bus_addr_t
;
150 typedef uint32_t bus_addr_t
;
152 typedef uint32_t bus_size_t
;
161 volatile uint8_t *maddr
;
162 } bus_space_handle_t
;
164 typedef struct bus_dma_segment
170 struct ahd_linux_dma_tag
172 bus_size_t alignment
;
176 typedef struct ahd_linux_dma_tag
* bus_dma_tag_t
;
178 struct ahd_linux_dmamap
182 typedef struct ahd_linux_dmamap
* bus_dmamap_t
;
184 typedef int bus_dma_filter_t(void*, bus_addr_t
);
185 typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t
*, int, int);
187 #define BUS_DMA_WAITOK 0x0
188 #define BUS_DMA_NOWAIT 0x1
189 #define BUS_DMA_ALLOCNOW 0x2
190 #define BUS_DMA_LOAD_SEGS 0x4 /*
191 * Argument is an S/G list not
195 #define BUS_SPACE_MAXADDR 0xFFFFFFFF
196 #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
197 #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
199 int ahd_dma_tag_create(struct ahd_softc
*, bus_dma_tag_t
/*parent*/,
200 bus_size_t
/*alignment*/, bus_size_t
/*boundary*/,
201 bus_addr_t
/*lowaddr*/, bus_addr_t
/*highaddr*/,
202 bus_dma_filter_t*/
*filter*/
, void */
*filterarg*/
,
203 bus_size_t
/*maxsize*/, int /*nsegments*/,
204 bus_size_t
/*maxsegsz*/, int /*flags*/,
205 bus_dma_tag_t */
*dma_tagp*/
);
207 void ahd_dma_tag_destroy(struct ahd_softc
*, bus_dma_tag_t
/*tag*/);
209 int ahd_dmamem_alloc(struct ahd_softc
*, bus_dma_tag_t
/*dmat*/,
210 void** /*vaddr*/, int /*flags*/,
211 bus_dmamap_t
* /*mapp*/);
213 void ahd_dmamem_free(struct ahd_softc
*, bus_dma_tag_t
/*dmat*/,
214 void* /*vaddr*/, bus_dmamap_t
/*map*/);
216 void ahd_dmamap_destroy(struct ahd_softc
*, bus_dma_tag_t
/*tag*/,
217 bus_dmamap_t
/*map*/);
219 int ahd_dmamap_load(struct ahd_softc
*ahd
, bus_dma_tag_t
/*dmat*/,
220 bus_dmamap_t
/*map*/, void * /*buf*/,
221 bus_size_t
/*buflen*/, bus_dmamap_callback_t
*,
222 void */
*callback_arg*/
, int /*flags*/);
224 int ahd_dmamap_unload(struct ahd_softc
*, bus_dma_tag_t
, bus_dmamap_t
);
227 * Operations performed by ahd_dmamap_sync().
229 #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
230 #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
231 #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
232 #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
236 * ahd_dmamap_sync is only used on buffers allocated with
237 * the pci_alloc_consistent() API. Although I'm not sure how
238 * this works on architectures with a write buffer, Linux does
239 * not have an API to sync "coherent" memory. Perhaps we need
242 #define ahd_dmamap_sync(ahd, dma_tag, dmamap, offset, len, op)
244 /************************** Timer DataStructures ******************************/
245 typedef struct timer_list ahd_timer_t
;
247 /********************************** Includes **********************************/
248 #ifdef CONFIG_AIC79XX_REG_PRETTY_PRINT
249 #define AIC_DEBUG_REGISTERS 1
251 #define AIC_DEBUG_REGISTERS 0
255 /***************************** Timer Facilities *******************************/
256 #define ahd_timer_init init_timer
257 #define ahd_timer_stop del_timer_sync
258 typedef void ahd_linux_callback_t (u_long
);
259 static __inline
void ahd_timer_reset(ahd_timer_t
*timer
, u_int usec
,
260 ahd_callback_t
*func
, void *arg
);
261 static __inline
void ahd_scb_timer_reset(struct scb
*scb
, u_int usec
);
264 ahd_timer_reset(ahd_timer_t
*timer
, u_int usec
, ahd_callback_t
*func
, void *arg
)
266 struct ahd_softc
*ahd
;
268 ahd
= (struct ahd_softc
*)arg
;
270 timer
->data
= (u_long
)arg
;
271 timer
->expires
= jiffies
+ (usec
* HZ
)/1000000;
272 timer
->function
= (ahd_linux_callback_t
*)func
;
277 ahd_scb_timer_reset(struct scb
*scb
, u_int usec
)
279 mod_timer(&scb
->io_ctx
->eh_timeout
, jiffies
+ (usec
* HZ
)/1000000);
282 /***************************** SMP support ************************************/
283 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,17)
284 #include <linux/spinlock.h>
285 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,93)
286 #include <linux/smp.h>
289 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) || defined(SCSI_HAS_HOST_LOCK))
290 #define AHD_SCSI_HAS_HOST_LOCK 1
292 #define AHD_SCSI_HAS_HOST_LOCK 0
295 #define AIC79XX_DRIVER_VERSION "1.3.11"
297 /**************************** Front End Queues ********************************/
299 * Data structure used to cast the Linux struct scsi_cmnd to something
300 * that allows us to use the queue macros. The linux structure has
301 * plenty of space to hold the links fields as required by the queue
302 * macros, but the queue macors require them to have the correct type.
304 struct ahd_cmd_internal
{
305 /* Area owned by the Linux scsi layer. */
306 uint8_t private[offsetof(struct scsi_cmnd
, SCp
.Status
)];
308 STAILQ_ENTRY(ahd_cmd
) ste
;
309 LIST_ENTRY(ahd_cmd
) le
;
310 TAILQ_ENTRY(ahd_cmd
) tqe
;
317 struct ahd_cmd_internal icmd
;
318 struct scsi_cmnd scsi_cmd
;
322 #define acmd_icmd(cmd) ((cmd)->un.icmd)
323 #define acmd_scsi_cmd(cmd) ((cmd)->un.scsi_cmd)
324 #define acmd_links un.icmd.links
326 /*************************** Device Data Structures ***************************/
328 * A per probed device structure used to deal with some error recovery
329 * scenarios that the Linux mid-layer code just doesn't know how to
330 * handle. The structure allocated for a device only becomes persistent
331 * after a successfully completed inquiry command to the target when
332 * that inquiry data indicates a lun is present.
334 TAILQ_HEAD(ahd_busyq
, ahd_cmd
);
336 AHD_DEV_UNCONFIGURED
= 0x01,
337 AHD_DEV_FREEZE_TIL_EMPTY
= 0x02, /* Freeze queue until active == 0 */
338 AHD_DEV_TIMER_ACTIVE
= 0x04, /* Our timer is active */
339 AHD_DEV_ON_RUN_LIST
= 0x08, /* Queued to be run later */
340 AHD_DEV_Q_BASIC
= 0x10, /* Allow basic device queuing */
341 AHD_DEV_Q_TAGGED
= 0x20, /* Allow full SCSI2 command queueing */
342 AHD_DEV_PERIODIC_OTAG
= 0x40, /* Send OTAG to prevent starvation */
343 AHD_DEV_SLAVE_CONFIGURED
= 0x80 /* slave_configure() has been called */
344 } ahd_linux_dev_flags
;
346 struct ahd_linux_target
;
347 struct ahd_linux_device
{
348 TAILQ_ENTRY(ahd_linux_device
) links
;
349 struct ahd_busyq busyq
;
352 * The number of transactions currently
353 * queued to the device.
358 * The currently allowed number of
359 * transactions that can be queued to
360 * the device. Must be signed for
361 * conversion from tagged to untagged
362 * mode where the device may have more
363 * than one outstanding active transaction.
368 * A positive count indicates that this
369 * device's queue is halted.
374 * Cumulative command counter.
376 u_long commands_issued
;
379 * The number of tagged transactions when
380 * running at our current opening level
381 * that have been successfully received by
382 * this device since the last QUEUE FULL.
384 u_int tag_success_count
;
385 #define AHD_TAG_SUCCESS_INTERVAL 50
387 ahd_linux_dev_flags flags
;
392 struct timer_list timer
;
395 * The high limit for the tags variable.
400 * The computed number of tags outstanding
401 * at the time of the last QUEUE FULL event.
403 u_int tags_on_last_queuefull
;
406 * How many times we have seen a queue full
407 * with the same number of tags. This is used
408 * to stop our adaptive queue depth algorithm
409 * on devices with a fixed number of tags.
411 u_int last_queuefull_same_count
;
412 #define AHD_LOCK_TAGS_COUNT 50
415 * How many transactions have been queued
416 * without the device going idle. We use
417 * this statistic to determine when to issue
418 * an ordered tag to prevent transaction
419 * starvation. This statistic is only updated
420 * if the AHD_DEV_PERIODIC_OTAG flag is set
423 u_int commands_since_idle_or_otag
;
424 #define AHD_OTAG_THRESH 500
427 Scsi_Device
*scsi_device
;
428 struct ahd_linux_target
*target
;
432 AHD_DV_REQUIRED
= 0x01,
433 AHD_INQ_VALID
= 0x02,
435 AHD_ENHANCED_DV
= 0x08
436 } ahd_linux_targ_flags
;
440 AHD_DV_STATE_EXIT
= 0,
441 AHD_DV_STATE_INQ_SHORT_ASYNC
,
442 AHD_DV_STATE_INQ_ASYNC
,
443 AHD_DV_STATE_INQ_ASYNC_VERIFY
,
446 AHD_DV_STATE_INQ_VERIFY
,
453 struct ahd_linux_target
{
454 struct ahd_linux_device
*devices
[AHD_NUM_LUNS
];
458 struct ahd_transinfo last_tinfo
;
459 struct ahd_softc
*ahd
;
460 ahd_linux_targ_flags flags
;
461 struct scsi_inquiry_data
*inq_data
;
463 * The next "fallback" period to use for narrow/wide transfers.
465 uint8_t dv_next_narrow_period
;
466 uint8_t dv_next_wide_period
;
467 uint8_t dv_max_width
;
468 uint8_t dv_max_ppr_options
;
469 uint8_t dv_last_ppr_options
;
471 ahd_dv_state dv_state
;
472 u_int dv_state_retry
;
477 * Cumulative counter of errors.
479 u_long errors_detected
;
480 u_long cmds_since_error
;
483 /********************* Definitions Required by the Core ***********************/
485 * Number of SG segments we require. So long as the S/G segments for
486 * a particular transaction are allocated in a physically contiguous
487 * manner and are allocated below 4GB, the number of S/G segments is
490 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
492 * We dynamically adjust the number of segments in pre-2.5 kernels to
493 * avoid fragmentation issues in the SCSI mid-layer's private memory
494 * allocator. See aic79xx_osm.c ahd_linux_size_nseg() for details.
496 extern u_int ahd_linux_nseg
;
497 #define AHD_NSEG ahd_linux_nseg
498 #define AHD_LINUX_MIN_NSEG 64
504 * Per-SCB OSM storage.
507 AHD_SCB_UP_EH_SEM
= 0x1
508 } ahd_linux_scb_flags
;
510 struct scb_platform_data
{
511 struct ahd_linux_device
*dev
;
512 bus_addr_t buf_busaddr
;
514 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
515 uint32_t resid
; /* Transfer residual */
517 uint32_t sense_resid
; /* Auto-Sense residual */
518 ahd_linux_scb_flags flags
;
522 * Define a structure used for each host adapter. All members are
523 * aligned on a boundary >= the size of the member to honor the
524 * alignment restrictions of the various platforms supported by
528 AHD_DV_WAIT_SIMQ_EMPTY
= 0x01,
529 AHD_DV_WAIT_SIMQ_RELEASE
= 0x02,
530 AHD_DV_ACTIVE
= 0x04,
531 AHD_DV_SHUTDOWN
= 0x08,
532 AHD_RUN_CMPLT_Q_TIMER
= 0x10
533 } ahd_linux_softc_flags
;
535 TAILQ_HEAD(ahd_completeq
, ahd_cmd
);
537 struct ahd_platform_data
{
539 * Fields accessed from interrupt context.
541 struct ahd_linux_target
*targets
[AHD_NUM_TARGETS
];
542 TAILQ_HEAD(, ahd_linux_device
) device_runq
;
543 struct ahd_completeq completeq
;
545 spinlock_t spin_lock
;
546 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
547 struct tasklet_struct runq_tasklet
;
551 struct timer_list completeq_timer
;
552 struct timer_list reset_timer
;
553 struct timer_list stats_timer
;
554 struct semaphore eh_sem
;
555 struct semaphore dv_sem
;
556 struct semaphore dv_cmd_sem
; /* XXX This needs to be in
559 struct scsi_device
*dv_scsi_dev
;
560 struct Scsi_Host
*host
; /* pointer to scsi host */
561 #define AHD_LINUX_NOIRQ ((uint32_t)~0)
562 uint32_t irq
; /* IRQ for this adapter */
563 uint32_t bios_address
;
564 uint32_t mem_busaddr
; /* Mem Base Addr */
565 bus_addr_t hw_dma_mask
;
566 ahd_linux_softc_flags flags
;
569 /************************** OS Utility Wrappers *******************************/
570 #define printf printk
571 #define M_NOWAIT GFP_ATOMIC
573 #define malloc(size, type, flags) kmalloc(size, flags)
574 #define free(ptr, type) kfree(ptr)
576 static __inline
void ahd_delay(long);
581 * udelay on Linux can have problems for
582 * multi-millisecond waits. Wait at most
592 /***************************** Low Level I/O **********************************/
593 static __inline
uint8_t ahd_inb(struct ahd_softc
* ahd
, long port
);
594 static __inline
uint16_t ahd_inw_atomic(struct ahd_softc
* ahd
, long port
);
595 static __inline
void ahd_outb(struct ahd_softc
* ahd
, long port
, uint8_t val
);
596 static __inline
void ahd_outw_atomic(struct ahd_softc
* ahd
,
597 long port
, uint16_t val
);
598 static __inline
void ahd_outsb(struct ahd_softc
* ahd
, long port
,
599 uint8_t *, int count
);
600 static __inline
void ahd_insb(struct ahd_softc
* ahd
, long port
,
601 uint8_t *, int count
);
603 static __inline
uint8_t
604 ahd_inb(struct ahd_softc
* ahd
, long port
)
608 if (ahd
->tags
[0] == BUS_SPACE_MEMIO
) {
609 x
= readb(ahd
->bshs
[0].maddr
+ port
);
611 x
= inb(ahd
->bshs
[(port
) >> 8].ioport
+ ((port
) & 0xFF));
617 static __inline
uint16_t
618 ahd_inw_atomic(struct ahd_softc
* ahd
, long port
)
622 if (ahd
->tags
[0] == BUS_SPACE_MEMIO
) {
623 x
= readw(ahd
->bshs
[0].maddr
+ port
);
625 x
= inw(ahd
->bshs
[(port
) >> 8].ioport
+ ((port
) & 0xFF));
632 ahd_outb(struct ahd_softc
* ahd
, long port
, uint8_t val
)
634 if (ahd
->tags
[0] == BUS_SPACE_MEMIO
) {
635 writeb(val
, ahd
->bshs
[0].maddr
+ port
);
637 outb(val
, ahd
->bshs
[(port
) >> 8].ioport
+ (port
& 0xFF));
643 ahd_outw_atomic(struct ahd_softc
* ahd
, long port
, uint16_t val
)
645 if (ahd
->tags
[0] == BUS_SPACE_MEMIO
) {
646 writew(val
, ahd
->bshs
[0].maddr
+ port
);
648 outw(val
, ahd
->bshs
[(port
) >> 8].ioport
+ (port
& 0xFF));
654 ahd_outsb(struct ahd_softc
* ahd
, long port
, uint8_t *array
, int count
)
659 * There is probably a more efficient way to do this on Linux
660 * but we don't use this for anything speed critical and this
663 for (i
= 0; i
< count
; i
++)
664 ahd_outb(ahd
, port
, *array
++);
668 ahd_insb(struct ahd_softc
* ahd
, long port
, uint8_t *array
, int count
)
673 * There is probably a more efficient way to do this on Linux
674 * but we don't use this for anything speed critical and this
677 for (i
= 0; i
< count
; i
++)
678 *array
++ = ahd_inb(ahd
, port
);
681 /**************************** Initialization **********************************/
682 int ahd_linux_register_host(struct ahd_softc
*,
683 Scsi_Host_Template
*);
685 uint64_t ahd_linux_get_memsize(void);
687 /*************************** Pretty Printing **********************************/
695 void ahd_format_transinfo(struct info_str
*info
,
696 struct ahd_transinfo
*tinfo
);
698 /******************************** Locking *************************************/
699 /* Lock protecting internal data structures */
700 static __inline
void ahd_lockinit(struct ahd_softc
*);
701 static __inline
void ahd_lock(struct ahd_softc
*, unsigned long *flags
);
702 static __inline
void ahd_unlock(struct ahd_softc
*, unsigned long *flags
);
704 /* Lock acquisition and release of the above lock in midlayer entry points. */
705 static __inline
void ahd_midlayer_entrypoint_lock(struct ahd_softc
*,
706 unsigned long *flags
);
707 static __inline
void ahd_midlayer_entrypoint_unlock(struct ahd_softc
*,
708 unsigned long *flags
);
710 /* Lock held during command compeletion to the upper layer */
711 static __inline
void ahd_done_lockinit(struct ahd_softc
*);
712 static __inline
void ahd_done_lock(struct ahd_softc
*, unsigned long *flags
);
713 static __inline
void ahd_done_unlock(struct ahd_softc
*, unsigned long *flags
);
715 /* Lock held during ahd_list manipulation and ahd softc frees */
716 extern spinlock_t ahd_list_spinlock
;
717 static __inline
void ahd_list_lockinit(void);
718 static __inline
void ahd_list_lock(unsigned long *flags
);
719 static __inline
void ahd_list_unlock(unsigned long *flags
);
722 ahd_lockinit(struct ahd_softc
*ahd
)
724 spin_lock_init(&ahd
->platform_data
->spin_lock
);
728 ahd_lock(struct ahd_softc
*ahd
, unsigned long *flags
)
730 spin_lock_irqsave(&ahd
->platform_data
->spin_lock
, *flags
);
734 ahd_unlock(struct ahd_softc
*ahd
, unsigned long *flags
)
736 spin_unlock_irqrestore(&ahd
->platform_data
->spin_lock
, *flags
);
740 ahd_midlayer_entrypoint_lock(struct ahd_softc
*ahd
, unsigned long *flags
)
743 * In 2.5.X and some 2.4.X versions, the midlayer takes our
744 * lock just before calling us, so we avoid locking again.
745 * For other kernel versions, the io_request_lock is taken
746 * just before our entry point is called. In this case, we
747 * trade the io_request_lock for our per-softc lock.
749 #if AHD_SCSI_HAS_HOST_LOCK == 0
750 spin_unlock(&io_request_lock
);
751 spin_lock(&ahd
->platform_data
->spin_lock
);
756 ahd_midlayer_entrypoint_unlock(struct ahd_softc
*ahd
, unsigned long *flags
)
758 #if AHD_SCSI_HAS_HOST_LOCK == 0
759 spin_unlock(&ahd
->platform_data
->spin_lock
);
760 spin_lock(&io_request_lock
);
765 ahd_done_lockinit(struct ahd_softc
*ahd
)
768 * In 2.5.X, our own lock is held during completions.
769 * In previous versions, the io_request_lock is used.
770 * In either case, we can't initialize this lock again.
775 ahd_done_lock(struct ahd_softc
*ahd
, unsigned long *flags
)
777 #if AHD_SCSI_HAS_HOST_LOCK == 0
778 spin_lock(&io_request_lock
);
783 ahd_done_unlock(struct ahd_softc
*ahd
, unsigned long *flags
)
785 #if AHD_SCSI_HAS_HOST_LOCK == 0
786 spin_unlock(&io_request_lock
);
791 ahd_list_lockinit(void)
793 spin_lock_init(&ahd_list_spinlock
);
797 ahd_list_lock(unsigned long *flags
)
799 spin_lock_irqsave(&ahd_list_spinlock
, *flags
);
803 ahd_list_unlock(unsigned long *flags
)
805 spin_unlock_irqrestore(&ahd_list_spinlock
, *flags
);
808 /******************************* PCI Definitions ******************************/
810 * PCIM_xxx: mask to locate subfield in register
811 * PCIR_xxx: config register offset
812 * PCIC_xxx: device class
813 * PCIS_xxx: device subclass
814 * PCIP_xxx: device programming interface
815 * PCIV_xxx: PCI vendor ID (only required to fixup ancient devices)
816 * PCID_xxx: device ID
818 #define PCIR_DEVVENDOR 0x00
819 #define PCIR_VENDOR 0x00
820 #define PCIR_DEVICE 0x02
821 #define PCIR_COMMAND 0x04
822 #define PCIM_CMD_PORTEN 0x0001
823 #define PCIM_CMD_MEMEN 0x0002
824 #define PCIM_CMD_BUSMASTEREN 0x0004
825 #define PCIM_CMD_MWRICEN 0x0010
826 #define PCIM_CMD_PERRESPEN 0x0040
827 #define PCIM_CMD_SERRESPEN 0x0100
828 #define PCIR_STATUS 0x06
829 #define PCIR_REVID 0x08
830 #define PCIR_PROGIF 0x09
831 #define PCIR_SUBCLASS 0x0a
832 #define PCIR_CLASS 0x0b
833 #define PCIR_CACHELNSZ 0x0c
834 #define PCIR_LATTIMER 0x0d
835 #define PCIR_HEADERTYPE 0x0e
836 #define PCIM_MFDEV 0x80
837 #define PCIR_BIST 0x0f
838 #define PCIR_CAP_PTR 0x34
840 /* config registers for header type 0 devices */
841 #define PCIR_MAPS 0x10
842 #define PCIR_SUBVEND_0 0x2c
843 #define PCIR_SUBDEV_0 0x2e
845 /****************************** PCI-X definitions *****************************/
846 #define PCIXR_COMMAND 0x96
847 #define PCIXR_DEVADDR 0x98
848 #define PCIXM_DEVADDR_FNUM 0x0003 /* Function Number */
849 #define PCIXM_DEVADDR_DNUM 0x00F8 /* Device Number */
850 #define PCIXM_DEVADDR_BNUM 0xFF00 /* Bus Number */
851 #define PCIXR_STATUS 0x9A
852 #define PCIXM_STATUS_64BIT 0x0001 /* Active 64bit connection to device. */
853 #define PCIXM_STATUS_133CAP 0x0002 /* Device is 133MHz capable */
854 #define PCIXM_STATUS_SCDISC 0x0004 /* Split Completion Discarded */
855 #define PCIXM_STATUS_UNEXPSC 0x0008 /* Unexpected Split Completion */
856 #define PCIXM_STATUS_CMPLEXDEV 0x0010 /* Device Complexity (set == bridge) */
857 #define PCIXM_STATUS_MAXMRDBC 0x0060 /* Maximum Burst Read Count */
858 #define PCIXM_STATUS_MAXSPLITS 0x0380 /* Maximum Split Transactions */
859 #define PCIXM_STATUS_MAXCRDS 0x1C00 /* Maximum Cumulative Read Size */
860 #define PCIXM_STATUS_RCVDSCEM 0x2000 /* Received a Split Comp w/Error msg */
862 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
863 extern struct pci_driver aic79xx_pci_driver
;
874 void ahd_power_state_change(struct ahd_softc
*ahd
,
875 ahd_power_state new_state
);
877 /******************************* PCI Routines *********************************/
878 int ahd_linux_pci_init(void);
879 void ahd_linux_pci_exit(void);
880 int ahd_pci_map_registers(struct ahd_softc
*ahd
);
881 int ahd_pci_map_int(struct ahd_softc
*ahd
);
883 static __inline
uint32_t ahd_pci_read_config(ahd_dev_softc_t pci
,
886 static __inline
uint32_t
887 ahd_pci_read_config(ahd_dev_softc_t pci
, int reg
, int width
)
894 pci_read_config_byte(pci
, reg
, &retval
);
900 pci_read_config_word(pci
, reg
, &retval
);
906 pci_read_config_dword(pci
, reg
, &retval
);
910 panic("ahd_pci_read_config: Read size too big");
916 static __inline
void ahd_pci_write_config(ahd_dev_softc_t pci
,
917 int reg
, uint32_t value
,
921 ahd_pci_write_config(ahd_dev_softc_t pci
, int reg
, uint32_t value
, int width
)
925 pci_write_config_byte(pci
, reg
, value
);
928 pci_write_config_word(pci
, reg
, value
);
931 pci_write_config_dword(pci
, reg
, value
);
934 panic("ahd_pci_write_config: Write size too big");
939 static __inline
int ahd_get_pci_function(ahd_dev_softc_t
);
941 ahd_get_pci_function(ahd_dev_softc_t pci
)
943 return (PCI_FUNC(pci
->devfn
));
946 static __inline
int ahd_get_pci_slot(ahd_dev_softc_t
);
948 ahd_get_pci_slot(ahd_dev_softc_t pci
)
950 return (PCI_SLOT(pci
->devfn
));
953 static __inline
int ahd_get_pci_bus(ahd_dev_softc_t
);
955 ahd_get_pci_bus(ahd_dev_softc_t pci
)
957 return (pci
->bus
->number
);
960 static __inline
void ahd_flush_device_writes(struct ahd_softc
*);
962 ahd_flush_device_writes(struct ahd_softc
*ahd
)
964 /* XXX Is this sufficient for all architectures??? */
965 ahd_inb(ahd
, INTSTAT
);
968 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,0)
969 #define pci_map_sg(pdev, sg_list, nseg, direction) (nseg)
970 #define pci_unmap_sg(pdev, sg_list, nseg, direction)
971 #define sg_dma_address(sg) (VIRT_TO_BUS((sg)->address))
972 #define sg_dma_len(sg) ((sg)->length)
973 #define pci_map_single(pdev, buffer, bufflen, direction) \
974 (VIRT_TO_BUS(buffer))
975 #define pci_unmap_single(pdev, buffer, buflen, direction)
978 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,3)
979 #define ahd_pci_set_dma_mask pci_set_dma_mask
982 * Always "return" 0 for success.
984 #define ahd_pci_set_dma_mask(dev_softc, mask) \
985 (((dev_softc)->dma_mask = mask) && 0)
987 /**************************** Proc FS Support *********************************/
988 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
989 int ahd_linux_proc_info(char *, char **, off_t
, int, int, int);
991 int ahd_linux_proc_info(struct Scsi_Host
*, char *, char **,
995 /*************************** Domain Validation ********************************/
996 #define AHD_DV_CMD(cmd) ((cmd)->scsi_done == ahd_linux_dv_complete)
997 #define AHD_DV_SIMQ_FROZEN(ahd) \
998 ((((ahd)->platform_data->flags & AHD_DV_ACTIVE) != 0) \
999 && (ahd)->platform_data->qfrozen == 1)
1001 /*********************** Transaction Access Wrappers **************************/
1002 static __inline
void ahd_cmd_set_transaction_status(Scsi_Cmnd
*, uint32_t);
1003 static __inline
void ahd_set_transaction_status(struct scb
*, uint32_t);
1004 static __inline
void ahd_cmd_set_scsi_status(Scsi_Cmnd
*, uint32_t);
1005 static __inline
void ahd_set_scsi_status(struct scb
*, uint32_t);
1006 static __inline
uint32_t ahd_cmd_get_transaction_status(Scsi_Cmnd
*cmd
);
1007 static __inline
uint32_t ahd_get_transaction_status(struct scb
*);
1008 static __inline
uint32_t ahd_cmd_get_scsi_status(Scsi_Cmnd
*cmd
);
1009 static __inline
uint32_t ahd_get_scsi_status(struct scb
*);
1010 static __inline
void ahd_set_transaction_tag(struct scb
*, int, u_int
);
1011 static __inline u_long
ahd_get_transfer_length(struct scb
*);
1012 static __inline
int ahd_get_transfer_dir(struct scb
*);
1013 static __inline
void ahd_set_residual(struct scb
*, u_long
);
1014 static __inline
void ahd_set_sense_residual(struct scb
*scb
, u_long resid
);
1015 static __inline u_long
ahd_get_residual(struct scb
*);
1016 static __inline u_long
ahd_get_sense_residual(struct scb
*);
1017 static __inline
int ahd_perform_autosense(struct scb
*);
1018 static __inline
uint32_t ahd_get_sense_bufsize(struct ahd_softc
*,
1020 static __inline
void ahd_notify_xfer_settings_change(struct ahd_softc
*,
1021 struct ahd_devinfo
*);
1022 static __inline
void ahd_platform_scb_free(struct ahd_softc
*ahd
,
1024 static __inline
void ahd_freeze_scb(struct scb
*scb
);
1027 void ahd_cmd_set_transaction_status(Scsi_Cmnd
*cmd
, uint32_t status
)
1029 cmd
->result
&= ~(CAM_STATUS_MASK
<< 16);
1030 cmd
->result
|= status
<< 16;
1034 void ahd_set_transaction_status(struct scb
*scb
, uint32_t status
)
1036 ahd_cmd_set_transaction_status(scb
->io_ctx
,status
);
1040 void ahd_cmd_set_scsi_status(Scsi_Cmnd
*cmd
, uint32_t status
)
1042 cmd
->result
&= ~0xFFFF;
1043 cmd
->result
|= status
;
1047 void ahd_set_scsi_status(struct scb
*scb
, uint32_t status
)
1049 ahd_cmd_set_scsi_status(scb
->io_ctx
, status
);
1053 uint32_t ahd_cmd_get_transaction_status(Scsi_Cmnd
*cmd
)
1055 return ((cmd
->result
>> 16) & CAM_STATUS_MASK
);
1059 uint32_t ahd_get_transaction_status(struct scb
*scb
)
1061 return (ahd_cmd_get_transaction_status(scb
->io_ctx
));
1065 uint32_t ahd_cmd_get_scsi_status(Scsi_Cmnd
*cmd
)
1067 return (cmd
->result
& 0xFFFF);
1071 uint32_t ahd_get_scsi_status(struct scb
*scb
)
1073 return (ahd_cmd_get_scsi_status(scb
->io_ctx
));
1077 void ahd_set_transaction_tag(struct scb
*scb
, int enabled
, u_int type
)
1080 * Nothing to do for linux as the incoming transaction
1081 * has no concept of tag/non tagged, etc.
1086 u_long
ahd_get_transfer_length(struct scb
*scb
)
1088 return (scb
->platform_data
->xfer_len
);
1092 int ahd_get_transfer_dir(struct scb
*scb
)
1094 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,40)
1095 return (scb
->io_ctx
->sc_data_direction
);
1097 if (scb
->io_ctx
->bufflen
== 0)
1098 return (CAM_DIR_NONE
);
1100 switch(scb
->io_ctx
->cmnd
[0]) {
1101 case 0x08: /* READ(6) */
1102 case 0x28: /* READ(10) */
1103 case 0xA8: /* READ(12) */
1104 return (CAM_DIR_IN
);
1105 case 0x0A: /* WRITE(6) */
1106 case 0x2A: /* WRITE(10) */
1107 case 0xAA: /* WRITE(12) */
1108 return (CAM_DIR_OUT
);
1110 return (CAM_DIR_NONE
);
1116 void ahd_set_residual(struct scb
*scb
, u_long resid
)
1118 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
1119 scb
->io_ctx
->resid
= resid
;
1121 scb
->platform_data
->resid
= resid
;
1126 void ahd_set_sense_residual(struct scb
*scb
, u_long resid
)
1128 scb
->platform_data
->sense_resid
= resid
;
1132 u_long
ahd_get_residual(struct scb
*scb
)
1134 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
1135 return (scb
->io_ctx
->resid
);
1137 return (scb
->platform_data
->resid
);
1142 u_long
ahd_get_sense_residual(struct scb
*scb
)
1144 return (scb
->platform_data
->sense_resid
);
1148 int ahd_perform_autosense(struct scb
*scb
)
1151 * We always perform autosense in Linux.
1152 * On other platforms this is set on a
1153 * per-transaction basis.
1158 static __inline
uint32_t
1159 ahd_get_sense_bufsize(struct ahd_softc
*ahd
, struct scb
*scb
)
1161 return (sizeof(struct scsi_sense_data
));
1164 static __inline
void
1165 ahd_notify_xfer_settings_change(struct ahd_softc
*ahd
,
1166 struct ahd_devinfo
*devinfo
)
1168 /* Nothing to do here for linux */
1171 static __inline
void
1172 ahd_platform_scb_free(struct ahd_softc
*ahd
, struct scb
*scb
)
1174 ahd
->flags
&= ~AHD_RESOURCE_SHORTAGE
;
1177 int ahd_platform_alloc(struct ahd_softc
*ahd
, void *platform_arg
);
1178 void ahd_platform_free(struct ahd_softc
*ahd
);
1179 void ahd_platform_init(struct ahd_softc
*ahd
);
1180 void ahd_platform_freeze_devq(struct ahd_softc
*ahd
, struct scb
*scb
);
1181 void ahd_freeze_simq(struct ahd_softc
*ahd
);
1182 void ahd_release_simq(struct ahd_softc
*ahd
);
1184 static __inline
void
1185 ahd_freeze_scb(struct scb
*scb
)
1187 if ((scb
->io_ctx
->result
& (CAM_DEV_QFRZN
<< 16)) == 0) {
1188 scb
->io_ctx
->result
|= CAM_DEV_QFRZN
<< 16;
1189 scb
->platform_data
->dev
->qfrozen
++;
1193 void ahd_platform_set_tags(struct ahd_softc
*ahd
,
1194 struct ahd_devinfo
*devinfo
, ahd_queue_alg
);
1195 int ahd_platform_abort_scbs(struct ahd_softc
*ahd
, int target
,
1196 char channel
, int lun
, u_int tag
,
1197 role_t role
, uint32_t status
);
1199 ahd_linux_isr(int irq
, void *dev_id
, struct pt_regs
* regs
);
1200 void ahd_platform_flushwork(struct ahd_softc
*ahd
);
1201 int ahd_softc_comp(struct ahd_softc
*, struct ahd_softc
*);
1202 void ahd_done(struct ahd_softc
*, struct scb
*);
1203 void ahd_send_async(struct ahd_softc
*, char channel
,
1204 u_int target
, u_int lun
, ac_code
, void *);
1205 void ahd_print_path(struct ahd_softc
*, struct scb
*);
1206 void ahd_platform_dump_card_state(struct ahd_softc
*ahd
);
1209 #define AHD_PCI_CONFIG 1
1211 #define AHD_PCI_CONFIG 0
1213 #define bootverbose aic79xx_verbose
1214 extern uint32_t aic79xx_verbose
;
1215 #endif /* _AIC79XX_LINUX_H_ */