blob: 9cfb46b4b15f2d0dd882a2660735a1e1bfac3c70 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Adaptec AIC7xxx device driver for Linux.
3 *
4 * Copyright (c) 1994 John Aycock
5 * The University of Calgary Department of Computer Science.
6 *
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)
10 * any later version.
11 *
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.
16 *
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.
20 *
21 * Copyright (c) 2000-2003 Adaptec Inc.
22 * All rights reserved.
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 * 1. Redistributions of source code must retain the above copyright
28 * notice, this list of conditions, and the following disclaimer,
29 * without modification.
30 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
31 * substantially similar to the "NO WARRANTY" disclaimer below
32 * ("Disclaimer") and any redistribution must be conditioned upon
33 * including a substantially similar Disclaimer requirement for further
34 * binary redistribution.
35 * 3. Neither the names of the above-listed copyright holders nor the names
36 * of any contributors may be used to endorse or promote products derived
37 * from this software without specific prior written permission.
38 *
39 * Alternatively, this software may be distributed under the terms of the
40 * GNU General Public License ("GPL") version 2 as published by the Free
41 * Software Foundation.
42 *
43 * NO WARRANTY
44 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
45 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
46 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
47 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
48 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
52 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
53 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
54 * POSSIBILITY OF SUCH DAMAGES.
55 *
56 * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_osm.h#151 $
57 *
58 */
59#ifndef _AIC7XXX_LINUX_H_
60#define _AIC7XXX_LINUX_H_
61
62#include <linux/types.h>
63#include <linux/blkdev.h>
64#include <linux/delay.h>
65#include <linux/ioport.h>
66#include <linux/pci.h>
67#include <linux/smp_lock.h>
68#include <linux/version.h>
James Bottomley e4e360c2005-05-16 16:39:38 -050069#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#include <linux/module.h>
71#include <asm/byteorder.h>
72#include <asm/io.h>
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074#include <linux/config.h>
75#include <linux/slab.h>
76
77/* Core SCSI definitions */
78#define AIC_LIB_PREFIX ahc
79#include "scsi.h"
80#include <scsi/scsi_host.h>
81
82/* Name space conflict with BSD queue macros */
83#ifdef LIST_HEAD
84#undef LIST_HEAD
85#endif
86
87#include "cam.h"
88#include "queue.h"
89#include "scsi_message.h"
90#include "aiclib.h"
91
92/*********************************** Debugging ********************************/
93#ifdef CONFIG_AIC7XXX_DEBUG_ENABLE
94#ifdef CONFIG_AIC7XXX_DEBUG_MASK
95#define AHC_DEBUG 1
96#define AHC_DEBUG_OPTS CONFIG_AIC7XXX_DEBUG_MASK
97#else
98/*
99 * Compile in debugging code, but do not enable any printfs.
100 */
101#define AHC_DEBUG 1
102#endif
103/* No debugging code. */
104#endif
105
106/************************* Forward Declarations *******************************/
107struct ahc_softc;
108typedef struct pci_dev *ahc_dev_softc_t;
109typedef Scsi_Cmnd *ahc_io_ctx_t;
110
111/******************************* Byte Order ***********************************/
112#define ahc_htobe16(x) cpu_to_be16(x)
113#define ahc_htobe32(x) cpu_to_be32(x)
114#define ahc_htobe64(x) cpu_to_be64(x)
115#define ahc_htole16(x) cpu_to_le16(x)
116#define ahc_htole32(x) cpu_to_le32(x)
117#define ahc_htole64(x) cpu_to_le64(x)
118
119#define ahc_be16toh(x) be16_to_cpu(x)
120#define ahc_be32toh(x) be32_to_cpu(x)
121#define ahc_be64toh(x) be64_to_cpu(x)
122#define ahc_le16toh(x) le16_to_cpu(x)
123#define ahc_le32toh(x) le32_to_cpu(x)
124#define ahc_le64toh(x) le64_to_cpu(x)
125
126#ifndef LITTLE_ENDIAN
127#define LITTLE_ENDIAN 1234
128#endif
129
130#ifndef BIG_ENDIAN
131#define BIG_ENDIAN 4321
132#endif
133
134#ifndef BYTE_ORDER
135#if defined(__BIG_ENDIAN)
136#define BYTE_ORDER BIG_ENDIAN
137#endif
138#if defined(__LITTLE_ENDIAN)
139#define BYTE_ORDER LITTLE_ENDIAN
140#endif
141#endif /* BYTE_ORDER */
142
143/************************* Configuration Data *********************************/
144extern u_int aic7xxx_no_probe;
145extern u_int aic7xxx_allow_memio;
146extern int aic7xxx_detect_complete;
147extern Scsi_Host_Template aic7xxx_driver_template;
148
149/***************************** Bus Space/DMA **********************************/
150
151typedef uint32_t bus_size_t;
152
153typedef enum {
154 BUS_SPACE_MEMIO,
155 BUS_SPACE_PIO
156} bus_space_tag_t;
157
158typedef union {
159 u_long ioport;
160 volatile uint8_t __iomem *maddr;
161} bus_space_handle_t;
162
163typedef struct bus_dma_segment
164{
165 dma_addr_t ds_addr;
166 bus_size_t ds_len;
167} bus_dma_segment_t;
168
169struct ahc_linux_dma_tag
170{
171 bus_size_t alignment;
172 bus_size_t boundary;
173 bus_size_t maxsize;
174};
175typedef struct ahc_linux_dma_tag* bus_dma_tag_t;
176
Christoph Hellwig 7dfa0f22005-05-16 18:54:12 +0200177typedef dma_addr_t bus_dmamap_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
179typedef int bus_dma_filter_t(void*, dma_addr_t);
180typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
181
182#define BUS_DMA_WAITOK 0x0
183#define BUS_DMA_NOWAIT 0x1
184#define BUS_DMA_ALLOCNOW 0x2
185#define BUS_DMA_LOAD_SEGS 0x4 /*
186 * Argument is an S/G list not
187 * a single buffer.
188 */
189
190#define BUS_SPACE_MAXADDR 0xFFFFFFFF
191#define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
192#define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
193
194int ahc_dma_tag_create(struct ahc_softc *, bus_dma_tag_t /*parent*/,
195 bus_size_t /*alignment*/, bus_size_t /*boundary*/,
196 dma_addr_t /*lowaddr*/, dma_addr_t /*highaddr*/,
197 bus_dma_filter_t*/*filter*/, void */*filterarg*/,
198 bus_size_t /*maxsize*/, int /*nsegments*/,
199 bus_size_t /*maxsegsz*/, int /*flags*/,
200 bus_dma_tag_t */*dma_tagp*/);
201
202void ahc_dma_tag_destroy(struct ahc_softc *, bus_dma_tag_t /*tag*/);
203
204int ahc_dmamem_alloc(struct ahc_softc *, bus_dma_tag_t /*dmat*/,
205 void** /*vaddr*/, int /*flags*/,
206 bus_dmamap_t* /*mapp*/);
207
208void ahc_dmamem_free(struct ahc_softc *, bus_dma_tag_t /*dmat*/,
209 void* /*vaddr*/, bus_dmamap_t /*map*/);
210
211void ahc_dmamap_destroy(struct ahc_softc *, bus_dma_tag_t /*tag*/,
212 bus_dmamap_t /*map*/);
213
214int ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t /*dmat*/,
215 bus_dmamap_t /*map*/, void * /*buf*/,
216 bus_size_t /*buflen*/, bus_dmamap_callback_t *,
217 void */*callback_arg*/, int /*flags*/);
218
219int ahc_dmamap_unload(struct ahc_softc *, bus_dma_tag_t, bus_dmamap_t);
220
221/*
222 * Operations performed by ahc_dmamap_sync().
223 */
224#define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
225#define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
226#define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
227#define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
228
229/*
230 * XXX
231 * ahc_dmamap_sync is only used on buffers allocated with
232 * the pci_alloc_consistent() API. Although I'm not sure how
233 * this works on architectures with a write buffer, Linux does
234 * not have an API to sync "coherent" memory. Perhaps we need
235 * to do an mb()?
236 */
237#define ahc_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op)
238
239/************************** Timer DataStructures ******************************/
240typedef struct timer_list ahc_timer_t;
241
242/********************************** Includes **********************************/
243#ifdef CONFIG_AIC7XXX_REG_PRETTY_PRINT
244#define AIC_DEBUG_REGISTERS 1
245#else
246#define AIC_DEBUG_REGISTERS 0
247#endif
248#include "aic7xxx.h"
249
250/***************************** Timer Facilities *******************************/
251#define ahc_timer_init init_timer
252#define ahc_timer_stop del_timer_sync
253typedef void ahc_linux_callback_t (u_long);
254static __inline void ahc_timer_reset(ahc_timer_t *timer, int usec,
255 ahc_callback_t *func, void *arg);
256static __inline void ahc_scb_timer_reset(struct scb *scb, u_int usec);
257
258static __inline void
259ahc_timer_reset(ahc_timer_t *timer, int usec, ahc_callback_t *func, void *arg)
260{
261 struct ahc_softc *ahc;
262
263 ahc = (struct ahc_softc *)arg;
264 del_timer(timer);
265 timer->data = (u_long)arg;
266 timer->expires = jiffies + (usec * HZ)/1000000;
267 timer->function = (ahc_linux_callback_t*)func;
268 add_timer(timer);
269}
270
271static __inline void
272ahc_scb_timer_reset(struct scb *scb, u_int usec)
273{
274 mod_timer(&scb->io_ctx->eh_timeout, jiffies + (usec * HZ)/1000000);
275}
276
277/***************************** SMP support ************************************/
278#include <linux/spinlock.h>
279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280#define AIC7XXX_DRIVER_VERSION "6.2.36"
281
282/**************************** Front End Queues ********************************/
283/*
284 * Data structure used to cast the Linux struct scsi_cmnd to something
285 * that allows us to use the queue macros. The linux structure has
286 * plenty of space to hold the links fields as required by the queue
287 * macros, but the queue macors require them to have the correct type.
288 */
289struct ahc_cmd_internal {
290 /* Area owned by the Linux scsi layer. */
291 uint8_t private[offsetof(struct scsi_cmnd, SCp.Status)];
292 union {
293 STAILQ_ENTRY(ahc_cmd) ste;
294 LIST_ENTRY(ahc_cmd) le;
295 TAILQ_ENTRY(ahc_cmd) tqe;
296 } links;
297 uint32_t end;
298};
299
300struct ahc_cmd {
301 union {
302 struct ahc_cmd_internal icmd;
303 struct scsi_cmnd scsi_cmd;
304 } un;
305};
306
307#define acmd_icmd(cmd) ((cmd)->un.icmd)
308#define acmd_scsi_cmd(cmd) ((cmd)->un.scsi_cmd)
309#define acmd_links un.icmd.links
310
311/*************************** Device Data Structures ***************************/
312/*
313 * A per probed device structure used to deal with some error recovery
314 * scenarios that the Linux mid-layer code just doesn't know how to
315 * handle. The structure allocated for a device only becomes persistent
316 * after a successfully completed inquiry command to the target when
317 * that inquiry data indicates a lun is present.
318 */
319TAILQ_HEAD(ahc_busyq, ahc_cmd);
320typedef enum {
321 AHC_DEV_UNCONFIGURED = 0x01,
322 AHC_DEV_FREEZE_TIL_EMPTY = 0x02, /* Freeze queue until active == 0 */
323 AHC_DEV_TIMER_ACTIVE = 0x04, /* Our timer is active */
324 AHC_DEV_ON_RUN_LIST = 0x08, /* Queued to be run later */
325 AHC_DEV_Q_BASIC = 0x10, /* Allow basic device queuing */
326 AHC_DEV_Q_TAGGED = 0x20, /* Allow full SCSI2 command queueing */
327 AHC_DEV_PERIODIC_OTAG = 0x40, /* Send OTAG to prevent starvation */
328 AHC_DEV_SLAVE_CONFIGURED = 0x80 /* slave_configure() has been called */
329} ahc_linux_dev_flags;
330
331struct ahc_linux_target;
332struct ahc_linux_device {
333 TAILQ_ENTRY(ahc_linux_device) links;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
335 /*
336 * The number of transactions currently
337 * queued to the device.
338 */
339 int active;
340
341 /*
342 * The currently allowed number of
343 * transactions that can be queued to
344 * the device. Must be signed for
345 * conversion from tagged to untagged
346 * mode where the device may have more
347 * than one outstanding active transaction.
348 */
349 int openings;
350
351 /*
352 * A positive count indicates that this
353 * device's queue is halted.
354 */
355 u_int qfrozen;
356
357 /*
358 * Cumulative command counter.
359 */
360 u_long commands_issued;
361
362 /*
363 * The number of tagged transactions when
364 * running at our current opening level
365 * that have been successfully received by
366 * this device since the last QUEUE FULL.
367 */
368 u_int tag_success_count;
369#define AHC_TAG_SUCCESS_INTERVAL 50
370
371 ahc_linux_dev_flags flags;
372
373 /*
374 * Per device timer.
375 */
376 struct timer_list timer;
377
378 /*
379 * The high limit for the tags variable.
380 */
381 u_int maxtags;
382
383 /*
384 * The computed number of tags outstanding
385 * at the time of the last QUEUE FULL event.
386 */
387 u_int tags_on_last_queuefull;
388
389 /*
390 * How many times we have seen a queue full
391 * with the same number of tags. This is used
392 * to stop our adaptive queue depth algorithm
393 * on devices with a fixed number of tags.
394 */
395 u_int last_queuefull_same_count;
396#define AHC_LOCK_TAGS_COUNT 50
397
398 /*
399 * How many transactions have been queued
400 * without the device going idle. We use
401 * this statistic to determine when to issue
402 * an ordered tag to prevent transaction
403 * starvation. This statistic is only updated
404 * if the AHC_DEV_PERIODIC_OTAG flag is set
405 * on this device.
406 */
407 u_int commands_since_idle_or_otag;
408#define AHC_OTAG_THRESH 500
409
410 int lun;
411 Scsi_Device *scsi_device;
412 struct ahc_linux_target *target;
413};
414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415struct ahc_linux_target {
416 struct ahc_linux_device *devices[AHC_NUM_LUNS];
417 int channel;
418 int target;
419 int refcount;
420 struct ahc_transinfo last_tinfo;
421 struct ahc_softc *ahc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422};
423
424/********************* Definitions Required by the Core ***********************/
425/*
426 * Number of SG segments we require. So long as the S/G segments for
427 * a particular transaction are allocated in a physically contiguous
428 * manner and are allocated below 4GB, the number of S/G segments is
429 * unrestricted.
430 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#define AHC_NSEG 128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433/*
434 * Per-SCB OSM storage.
435 */
436typedef enum {
437 AHC_UP_EH_SEMAPHORE = 0x1
438} ahc_linux_scb_flags;
439
440struct scb_platform_data {
441 struct ahc_linux_device *dev;
442 dma_addr_t buf_busaddr;
443 uint32_t xfer_len;
444 uint32_t sense_resid; /* Auto-Sense residual */
445 ahc_linux_scb_flags flags;
446};
447
448/*
449 * Define a structure used for each host adapter. All members are
450 * aligned on a boundary >= the size of the member to honor the
451 * alignment restrictions of the various platforms supported by
452 * this driver.
453 */
454typedef enum {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 AHC_RUN_CMPLT_Q_TIMER = 0x10
456} ahc_linux_softc_flags;
457
458TAILQ_HEAD(ahc_completeq, ahc_cmd);
459
460struct ahc_platform_data {
461 /*
462 * Fields accessed from interrupt context.
463 */
464 struct ahc_linux_target *targets[AHC_NUM_TARGETS];
465 TAILQ_HEAD(, ahc_linux_device) device_runq;
466 struct ahc_completeq completeq;
467
468 spinlock_t spin_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 u_int qfrozen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 struct timer_list completeq_timer;
471 struct timer_list reset_timer;
472 struct semaphore eh_sem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 struct Scsi_Host *host; /* pointer to scsi host */
474#define AHC_LINUX_NOIRQ ((uint32_t)~0)
475 uint32_t irq; /* IRQ for this adapter */
476 uint32_t bios_address;
477 uint32_t mem_busaddr; /* Mem Base Addr */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 ahc_linux_softc_flags flags;
479};
480
481/************************** OS Utility Wrappers *******************************/
482#define printf printk
483#define M_NOWAIT GFP_ATOMIC
484#define M_WAITOK 0
485#define malloc(size, type, flags) kmalloc(size, flags)
486#define free(ptr, type) kfree(ptr)
487
488static __inline void ahc_delay(long);
489static __inline void
490ahc_delay(long usec)
491{
492 /*
493 * udelay on Linux can have problems for
494 * multi-millisecond waits. Wait at most
495 * 1024us per call.
496 */
497 while (usec > 0) {
498 udelay(usec % 1024);
499 usec -= 1024;
500 }
501}
502
503
504/***************************** Low Level I/O **********************************/
505static __inline uint8_t ahc_inb(struct ahc_softc * ahc, long port);
506static __inline void ahc_outb(struct ahc_softc * ahc, long port, uint8_t val);
507static __inline void ahc_outsb(struct ahc_softc * ahc, long port,
508 uint8_t *, int count);
509static __inline void ahc_insb(struct ahc_softc * ahc, long port,
510 uint8_t *, int count);
511
512static __inline uint8_t
513ahc_inb(struct ahc_softc * ahc, long port)
514{
515 uint8_t x;
516
517 if (ahc->tag == BUS_SPACE_MEMIO) {
518 x = readb(ahc->bsh.maddr + port);
519 } else {
520 x = inb(ahc->bsh.ioport + port);
521 }
522 mb();
523 return (x);
524}
525
526static __inline void
527ahc_outb(struct ahc_softc * ahc, long port, uint8_t val)
528{
529 if (ahc->tag == BUS_SPACE_MEMIO) {
530 writeb(val, ahc->bsh.maddr + port);
531 } else {
532 outb(val, ahc->bsh.ioport + port);
533 }
534 mb();
535}
536
537static __inline void
538ahc_outsb(struct ahc_softc * ahc, long port, uint8_t *array, int count)
539{
540 int i;
541
542 /*
543 * There is probably a more efficient way to do this on Linux
544 * but we don't use this for anything speed critical and this
545 * should work.
546 */
547 for (i = 0; i < count; i++)
548 ahc_outb(ahc, port, *array++);
549}
550
551static __inline void
552ahc_insb(struct ahc_softc * ahc, long port, uint8_t *array, int count)
553{
554 int i;
555
556 /*
557 * There is probably a more efficient way to do this on Linux
558 * but we don't use this for anything speed critical and this
559 * should work.
560 */
561 for (i = 0; i < count; i++)
562 *array++ = ahc_inb(ahc, port);
563}
564
565/**************************** Initialization **********************************/
566int ahc_linux_register_host(struct ahc_softc *,
567 Scsi_Host_Template *);
568
569uint64_t ahc_linux_get_memsize(void);
570
571/*************************** Pretty Printing **********************************/
572struct info_str {
573 char *buffer;
574 int length;
575 off_t offset;
576 int pos;
577};
578
579void ahc_format_transinfo(struct info_str *info,
580 struct ahc_transinfo *tinfo);
581
582/******************************** Locking *************************************/
583/* Lock protecting internal data structures */
584static __inline void ahc_lockinit(struct ahc_softc *);
585static __inline void ahc_lock(struct ahc_softc *, unsigned long *flags);
586static __inline void ahc_unlock(struct ahc_softc *, unsigned long *flags);
587
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588/* Lock held during ahc_list manipulation and ahc softc frees */
589extern spinlock_t ahc_list_spinlock;
590static __inline void ahc_list_lockinit(void);
591static __inline void ahc_list_lock(unsigned long *flags);
592static __inline void ahc_list_unlock(unsigned long *flags);
593
594static __inline void
595ahc_lockinit(struct ahc_softc *ahc)
596{
597 spin_lock_init(&ahc->platform_data->spin_lock);
598}
599
600static __inline void
601ahc_lock(struct ahc_softc *ahc, unsigned long *flags)
602{
603 spin_lock_irqsave(&ahc->platform_data->spin_lock, *flags);
604}
605
606static __inline void
607ahc_unlock(struct ahc_softc *ahc, unsigned long *flags)
608{
609 spin_unlock_irqrestore(&ahc->platform_data->spin_lock, *flags);
610}
611
612static __inline void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613ahc_list_lockinit(void)
614{
615 spin_lock_init(&ahc_list_spinlock);
616}
617
618static __inline void
619ahc_list_lock(unsigned long *flags)
620{
621 spin_lock_irqsave(&ahc_list_spinlock, *flags);
622}
623
624static __inline void
625ahc_list_unlock(unsigned long *flags)
626{
627 spin_unlock_irqrestore(&ahc_list_spinlock, *flags);
628}
629
630/******************************* PCI Definitions ******************************/
631/*
632 * PCIM_xxx: mask to locate subfield in register
633 * PCIR_xxx: config register offset
634 * PCIC_xxx: device class
635 * PCIS_xxx: device subclass
636 * PCIP_xxx: device programming interface
637 * PCIV_xxx: PCI vendor ID (only required to fixup ancient devices)
638 * PCID_xxx: device ID
639 */
640#define PCIR_DEVVENDOR 0x00
641#define PCIR_VENDOR 0x00
642#define PCIR_DEVICE 0x02
643#define PCIR_COMMAND 0x04
644#define PCIM_CMD_PORTEN 0x0001
645#define PCIM_CMD_MEMEN 0x0002
646#define PCIM_CMD_BUSMASTEREN 0x0004
647#define PCIM_CMD_MWRICEN 0x0010
648#define PCIM_CMD_PERRESPEN 0x0040
649#define PCIM_CMD_SERRESPEN 0x0100
650#define PCIR_STATUS 0x06
651#define PCIR_REVID 0x08
652#define PCIR_PROGIF 0x09
653#define PCIR_SUBCLASS 0x0a
654#define PCIR_CLASS 0x0b
655#define PCIR_CACHELNSZ 0x0c
656#define PCIR_LATTIMER 0x0d
657#define PCIR_HEADERTYPE 0x0e
658#define PCIM_MFDEV 0x80
659#define PCIR_BIST 0x0f
660#define PCIR_CAP_PTR 0x34
661
662/* config registers for header type 0 devices */
663#define PCIR_MAPS 0x10
664#define PCIR_SUBVEND_0 0x2c
665#define PCIR_SUBDEV_0 0x2e
666
667extern struct pci_driver aic7xxx_pci_driver;
668
669typedef enum
670{
671 AHC_POWER_STATE_D0,
672 AHC_POWER_STATE_D1,
673 AHC_POWER_STATE_D2,
674 AHC_POWER_STATE_D3
675} ahc_power_state;
676
677/**************************** VL/EISA Routines ********************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678#ifdef CONFIG_EISA
679extern uint32_t aic7xxx_probe_eisa_vl;
680int ahc_linux_eisa_init(void);
681void ahc_linux_eisa_exit(void);
682int aic7770_map_registers(struct ahc_softc *ahc,
683 u_int port);
684int aic7770_map_int(struct ahc_softc *ahc, u_int irq);
685#else
686static inline int ahc_linux_eisa_init(void) {
687 return -ENODEV;
688}
689static inline void ahc_linux_eisa_exit(void) {
690}
691#endif
692
693/******************************* PCI Routines *********************************/
694#ifdef CONFIG_PCI
695int ahc_linux_pci_init(void);
696void ahc_linux_pci_exit(void);
697int ahc_pci_map_registers(struct ahc_softc *ahc);
698int ahc_pci_map_int(struct ahc_softc *ahc);
699
700static __inline uint32_t ahc_pci_read_config(ahc_dev_softc_t pci,
701 int reg, int width);
702
703static __inline uint32_t
704ahc_pci_read_config(ahc_dev_softc_t pci, int reg, int width)
705{
706 switch (width) {
707 case 1:
708 {
709 uint8_t retval;
710
711 pci_read_config_byte(pci, reg, &retval);
712 return (retval);
713 }
714 case 2:
715 {
716 uint16_t retval;
717 pci_read_config_word(pci, reg, &retval);
718 return (retval);
719 }
720 case 4:
721 {
722 uint32_t retval;
723 pci_read_config_dword(pci, reg, &retval);
724 return (retval);
725 }
726 default:
727 panic("ahc_pci_read_config: Read size too big");
728 /* NOTREACHED */
729 return (0);
730 }
731}
732
733static __inline void ahc_pci_write_config(ahc_dev_softc_t pci,
734 int reg, uint32_t value,
735 int width);
736
737static __inline void
738ahc_pci_write_config(ahc_dev_softc_t pci, int reg, uint32_t value, int width)
739{
740 switch (width) {
741 case 1:
742 pci_write_config_byte(pci, reg, value);
743 break;
744 case 2:
745 pci_write_config_word(pci, reg, value);
746 break;
747 case 4:
748 pci_write_config_dword(pci, reg, value);
749 break;
750 default:
751 panic("ahc_pci_write_config: Write size too big");
752 /* NOTREACHED */
753 }
754}
755
756static __inline int ahc_get_pci_function(ahc_dev_softc_t);
757static __inline int
758ahc_get_pci_function(ahc_dev_softc_t pci)
759{
760 return (PCI_FUNC(pci->devfn));
761}
762
763static __inline int ahc_get_pci_slot(ahc_dev_softc_t);
764static __inline int
765ahc_get_pci_slot(ahc_dev_softc_t pci)
766{
767 return (PCI_SLOT(pci->devfn));
768}
769
770static __inline int ahc_get_pci_bus(ahc_dev_softc_t);
771static __inline int
772ahc_get_pci_bus(ahc_dev_softc_t pci)
773{
774 return (pci->bus->number);
775}
776#else
777static inline int ahc_linux_pci_init(void) {
778 return 0;
779}
780static inline void ahc_linux_pci_exit(void) {
781}
782#endif
783
784static __inline void ahc_flush_device_writes(struct ahc_softc *);
785static __inline void
786ahc_flush_device_writes(struct ahc_softc *ahc)
787{
788 /* XXX Is this sufficient for all architectures??? */
789 ahc_inb(ahc, INTSTAT);
790}
791
792/**************************** Proc FS Support *********************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793int ahc_linux_proc_info(struct Scsi_Host *, char *, char **,
794 off_t, int, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
796/*************************** Domain Validation ********************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797/*********************** Transaction Access Wrappers *************************/
798static __inline void ahc_cmd_set_transaction_status(Scsi_Cmnd *, uint32_t);
799static __inline void ahc_set_transaction_status(struct scb *, uint32_t);
800static __inline void ahc_cmd_set_scsi_status(Scsi_Cmnd *, uint32_t);
801static __inline void ahc_set_scsi_status(struct scb *, uint32_t);
802static __inline uint32_t ahc_cmd_get_transaction_status(Scsi_Cmnd *cmd);
803static __inline uint32_t ahc_get_transaction_status(struct scb *);
804static __inline uint32_t ahc_cmd_get_scsi_status(Scsi_Cmnd *cmd);
805static __inline uint32_t ahc_get_scsi_status(struct scb *);
806static __inline void ahc_set_transaction_tag(struct scb *, int, u_int);
807static __inline u_long ahc_get_transfer_length(struct scb *);
808static __inline int ahc_get_transfer_dir(struct scb *);
809static __inline void ahc_set_residual(struct scb *, u_long);
810static __inline void ahc_set_sense_residual(struct scb *scb, u_long resid);
811static __inline u_long ahc_get_residual(struct scb *);
812static __inline u_long ahc_get_sense_residual(struct scb *);
813static __inline int ahc_perform_autosense(struct scb *);
814static __inline uint32_t ahc_get_sense_bufsize(struct ahc_softc *,
815 struct scb *);
816static __inline void ahc_notify_xfer_settings_change(struct ahc_softc *,
817 struct ahc_devinfo *);
818static __inline void ahc_platform_scb_free(struct ahc_softc *ahc,
819 struct scb *scb);
820static __inline void ahc_freeze_scb(struct scb *scb);
821
822static __inline
823void ahc_cmd_set_transaction_status(Scsi_Cmnd *cmd, uint32_t status)
824{
825 cmd->result &= ~(CAM_STATUS_MASK << 16);
826 cmd->result |= status << 16;
827}
828
829static __inline
830void ahc_set_transaction_status(struct scb *scb, uint32_t status)
831{
832 ahc_cmd_set_transaction_status(scb->io_ctx,status);
833}
834
835static __inline
836void ahc_cmd_set_scsi_status(Scsi_Cmnd *cmd, uint32_t status)
837{
838 cmd->result &= ~0xFFFF;
839 cmd->result |= status;
840}
841
842static __inline
843void ahc_set_scsi_status(struct scb *scb, uint32_t status)
844{
845 ahc_cmd_set_scsi_status(scb->io_ctx, status);
846}
847
848static __inline
849uint32_t ahc_cmd_get_transaction_status(Scsi_Cmnd *cmd)
850{
851 return ((cmd->result >> 16) & CAM_STATUS_MASK);
852}
853
854static __inline
855uint32_t ahc_get_transaction_status(struct scb *scb)
856{
857 return (ahc_cmd_get_transaction_status(scb->io_ctx));
858}
859
860static __inline
861uint32_t ahc_cmd_get_scsi_status(Scsi_Cmnd *cmd)
862{
863 return (cmd->result & 0xFFFF);
864}
865
866static __inline
867uint32_t ahc_get_scsi_status(struct scb *scb)
868{
869 return (ahc_cmd_get_scsi_status(scb->io_ctx));
870}
871
872static __inline
873void ahc_set_transaction_tag(struct scb *scb, int enabled, u_int type)
874{
875 /*
876 * Nothing to do for linux as the incoming transaction
877 * has no concept of tag/non tagged, etc.
878 */
879}
880
881static __inline
882u_long ahc_get_transfer_length(struct scb *scb)
883{
884 return (scb->platform_data->xfer_len);
885}
886
887static __inline
888int ahc_get_transfer_dir(struct scb *scb)
889{
890 return (scb->io_ctx->sc_data_direction);
891}
892
893static __inline
894void ahc_set_residual(struct scb *scb, u_long resid)
895{
896 scb->io_ctx->resid = resid;
897}
898
899static __inline
900void ahc_set_sense_residual(struct scb *scb, u_long resid)
901{
902 scb->platform_data->sense_resid = resid;
903}
904
905static __inline
906u_long ahc_get_residual(struct scb *scb)
907{
908 return (scb->io_ctx->resid);
909}
910
911static __inline
912u_long ahc_get_sense_residual(struct scb *scb)
913{
914 return (scb->platform_data->sense_resid);
915}
916
917static __inline
918int ahc_perform_autosense(struct scb *scb)
919{
920 /*
921 * We always perform autosense in Linux.
922 * On other platforms this is set on a
923 * per-transaction basis.
924 */
925 return (1);
926}
927
928static __inline uint32_t
929ahc_get_sense_bufsize(struct ahc_softc *ahc, struct scb *scb)
930{
931 return (sizeof(struct scsi_sense_data));
932}
933
934static __inline void
935ahc_notify_xfer_settings_change(struct ahc_softc *ahc,
936 struct ahc_devinfo *devinfo)
937{
938 /* Nothing to do here for linux */
939}
940
941static __inline void
942ahc_platform_scb_free(struct ahc_softc *ahc, struct scb *scb)
943{
944 ahc->flags &= ~AHC_RESOURCE_SHORTAGE;
945}
946
947int ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg);
948void ahc_platform_free(struct ahc_softc *ahc);
949void ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb);
950
951static __inline void
952ahc_freeze_scb(struct scb *scb)
953{
954 if ((scb->io_ctx->result & (CAM_DEV_QFRZN << 16)) == 0) {
955 scb->io_ctx->result |= CAM_DEV_QFRZN << 16;
956 scb->platform_data->dev->qfrozen++;
957 }
958}
959
960void ahc_platform_set_tags(struct ahc_softc *ahc,
961 struct ahc_devinfo *devinfo, ahc_queue_alg);
962int ahc_platform_abort_scbs(struct ahc_softc *ahc, int target,
963 char channel, int lun, u_int tag,
964 role_t role, uint32_t status);
965irqreturn_t
966 ahc_linux_isr(int irq, void *dev_id, struct pt_regs * regs);
967void ahc_platform_flushwork(struct ahc_softc *ahc);
968int ahc_softc_comp(struct ahc_softc *, struct ahc_softc *);
969void ahc_done(struct ahc_softc*, struct scb*);
970void ahc_send_async(struct ahc_softc *, char channel,
971 u_int target, u_int lun, ac_code, void *);
972void ahc_print_path(struct ahc_softc *, struct scb *);
973void ahc_platform_dump_card_state(struct ahc_softc *ahc);
974
975#ifdef CONFIG_PCI
976#define AHC_PCI_CONFIG 1
977#else
978#define AHC_PCI_CONFIG 0
979#endif
980#define bootverbose aic7xxx_verbose
981extern u_int aic7xxx_verbose;
982#endif /* _AIC7XXX_LINUX_H_ */