1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42#ifndef _AIC79XX_LINUX_H_
43#define _AIC79XX_LINUX_H_
44
45#include <linux/types.h>
46#include <linux/blk.h>
47#include <linux/blkdev.h>
48#include <linux/delay.h>
49#include <linux/ioport.h>
50#include <linux/pci.h>
51#include <linux/smp_lock.h>
52#include <linux/version.h>
53#include <linux/module.h>
54#include <asm/byteorder.h>
55#include <asm/io.h>
56
57#ifndef KERNEL_VERSION
58#define KERNEL_VERSION(x,y,z) (((x)<<16)+((y)<<8)+(z))
59#endif
60
61#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
62#include <linux/interrupt.h>
63#include <linux/config.h>
64#include <linux/slab.h>
65#else
66#include <linux/malloc.h>
67#endif
68
69
70#define AIC_LIB_PREFIX ahd
71#include "scsi.h"
72#include "hosts.h"
73
74
75#ifdef LIST_HEAD
76#undef LIST_HEAD
77#endif
78
79#include "cam.h"
80#include "queue.h"
81#include "scsi_message.h"
82#include "scsi_iu.h"
83#include "aiclib.h"
84
85
86#ifdef CONFIG_AIC79XX_DEBUG_ENABLE
87#ifdef CONFIG_AIC79XX_DEBUG_MASK
88#define AHD_DEBUG 1
89#define AHD_DEBUG_OPTS CONFIG_AIC79XX_DEBUG_MASK
90#else
91
92
93
94#define AHD_DEBUG 1
95#define AHD_DEBUG_OPTS 0
96#endif
97
98#endif
99
100
101#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
102#define powerof2(x) ((((x)-1)&(x))==0)
103
104
105struct ahd_softc;
106typedef struct pci_dev *ahd_dev_softc_t;
107typedef Scsi_Cmnd *ahd_io_ctx_t;
108
109
110#define ahd_htobe16(x) cpu_to_be16(x)
111#define ahd_htobe32(x) cpu_to_be32(x)
112#define ahd_htobe64(x) cpu_to_be64(x)
113#define ahd_htole16(x) cpu_to_le16(x)
114#define ahd_htole32(x) cpu_to_le32(x)
115#define ahd_htole64(x) cpu_to_le64(x)
116
117#define ahd_be16toh(x) be16_to_cpu(x)
118#define ahd_be32toh(x) be32_to_cpu(x)
119#define ahd_be64toh(x) be64_to_cpu(x)
120#define ahd_le16toh(x) le16_to_cpu(x)
121#define ahd_le32toh(x) le32_to_cpu(x)
122#define ahd_le64toh(x) le64_to_cpu(x)
123
124#ifndef LITTLE_ENDIAN
125#define LITTLE_ENDIAN 1234
126#endif
127
128#ifndef BIG_ENDIAN
129#define BIG_ENDIAN 4321
130#endif
131
132#ifndef BYTE_ORDER
133#if defined(__BIG_ENDIAN)
134#define BYTE_ORDER BIG_ENDIAN
135#endif
136#if defined(__LITTLE_ENDIAN)
137#define BYTE_ORDER LITTLE_ENDIAN
138#endif
139#endif
140
141
142extern uint32_t aic79xx_allow_memio;
143extern int aic79xx_detect_complete;
144extern Scsi_Host_Template aic79xx_driver_template;
145
146
147
148#if LINUX_VERSION_CODE > KERNEL_VERSION(2,2,17)
149typedef dma_addr_t bus_addr_t;
150#else
151typedef uint32_t bus_addr_t;
152#endif
153typedef uint32_t bus_size_t;
154
155typedef enum {
156 BUS_SPACE_MEMIO,
157 BUS_SPACE_PIO
158} bus_space_tag_t;
159
160typedef union {
161 u_long ioport;
162 volatile uint8_t *maddr;
163} bus_space_handle_t;
164
165typedef struct bus_dma_segment
166{
167 bus_addr_t ds_addr;
168 bus_size_t ds_len;
169} bus_dma_segment_t;
170
171struct ahd_linux_dma_tag
172{
173 bus_size_t alignment;
174 bus_size_t boundary;
175 bus_size_t maxsize;
176};
177typedef struct ahd_linux_dma_tag* bus_dma_tag_t;
178
179struct ahd_linux_dmamap
180{
181 bus_addr_t bus_addr;
182};
183typedef struct ahd_linux_dmamap* bus_dmamap_t;
184
185typedef int bus_dma_filter_t(void*, bus_addr_t);
186typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
187
188#define BUS_DMA_WAITOK 0x0
189#define BUS_DMA_NOWAIT 0x1
190#define BUS_DMA_ALLOCNOW 0x2
191#define BUS_DMA_LOAD_SEGS 0x4
192
193
194
195
196#define BUS_SPACE_MAXADDR 0xFFFFFFFF
197#define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
198#define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
199
200int ahd_dma_tag_create(struct ahd_softc *, bus_dma_tag_t ,
201 bus_size_t , bus_size_t ,
202 bus_addr_t , bus_addr_t ,
203 bus_dma_filter_t*, void *,
204 bus_size_t , int ,
205 bus_size_t , int ,
206 bus_dma_tag_t *);
207
208void ahd_dma_tag_destroy(struct ahd_softc *, bus_dma_tag_t );
209
210int ahd_dmamem_alloc(struct ahd_softc *, bus_dma_tag_t ,
211 void** , int ,
212 bus_dmamap_t* );
213
214void ahd_dmamem_free(struct ahd_softc *, bus_dma_tag_t ,
215 void* , bus_dmamap_t );
216
217void ahd_dmamap_destroy(struct ahd_softc *, bus_dma_tag_t ,
218 bus_dmamap_t );
219
220int ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t ,
221 bus_dmamap_t , void * ,
222 bus_size_t , bus_dmamap_callback_t *,
223 void *, int );
224
225int ahd_dmamap_unload(struct ahd_softc *, bus_dma_tag_t, bus_dmamap_t);
226
227
228
229
230#define BUS_DMASYNC_PREREAD 0x01
231#define BUS_DMASYNC_POSTREAD 0x02
232#define BUS_DMASYNC_PREWRITE 0x04
233#define BUS_DMASYNC_POSTWRITE 0x08
234
235
236
237
238
239
240
241
242
243#define ahd_dmamap_sync(ahd, dma_tag, dmamap, offset, len, op)
244
245
246typedef struct timer_list ahd_timer_t;
247
248
249#ifdef CONFIG_AIC79XX_REG_PRETTY_PRINT
250#define AIC_DEBUG_REGISTERS 1
251#else
252#define AIC_DEBUG_REGISTERS 0
253#endif
254#include "aic79xx.h"
255
256
257#define ahd_timer_init init_timer
258#define ahd_timer_stop del_timer_sync
259typedef void ahd_linux_callback_t (u_long);
260static __inline void ahd_timer_reset(ahd_timer_t *timer, u_int usec,
261 ahd_callback_t *func, void *arg);
262static __inline void ahd_scb_timer_reset(struct scb *scb, u_int usec);
263
264static __inline void
265ahd_timer_reset(ahd_timer_t *timer, u_int usec, ahd_callback_t *func, void *arg)
266{
267 struct ahd_softc *ahd;
268
269 ahd = (struct ahd_softc *)arg;
270 del_timer(timer);
271 timer->data = (u_long)arg;
272 timer->expires = jiffies + (usec * HZ)/1000000;
273 timer->function = (ahd_linux_callback_t*)func;
274 add_timer(timer);
275}
276
277static __inline void
278ahd_scb_timer_reset(struct scb *scb, u_int usec)
279{
280 mod_timer(&scb->io_ctx->eh_timeout, jiffies + (usec * HZ)/1000000);
281}
282
283
284#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,17)
285#include <linux/spinlock.h>
286#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,93)
287#include <linux/smp.h>
288#endif
289
290#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) || defined(SCSI_HAS_HOST_LOCK))
291#define AHD_SCSI_HAS_HOST_LOCK 1
292#else
293#define AHD_SCSI_HAS_HOST_LOCK 0
294#endif
295
296#define AIC79XX_DRIVER_VERSION "1.3.10"
297
298
299
300
301
302
303
304
305struct ahd_cmd_internal {
306
307 uint8_t private[offsetof(struct scsi_cmnd, SCp.Status)];
308 union {
309 STAILQ_ENTRY(ahd_cmd) ste;
310 LIST_ENTRY(ahd_cmd) le;
311 TAILQ_ENTRY(ahd_cmd) tqe;
312 } links;
313 uint32_t end;
314};
315
316struct ahd_cmd {
317 union {
318 struct ahd_cmd_internal icmd;
319 struct scsi_cmnd scsi_cmd;
320 } un;
321};
322
323#define acmd_icmd(cmd) ((cmd)->un.icmd)
324#define acmd_scsi_cmd(cmd) ((cmd)->un.scsi_cmd)
325#define acmd_links un.icmd.links
326
327
328
329
330
331
332
333
334
335TAILQ_HEAD(ahd_busyq, ahd_cmd);
336typedef enum {
337 AHD_DEV_UNCONFIGURED = 0x01,
338 AHD_DEV_FREEZE_TIL_EMPTY = 0x02,
339 AHD_DEV_TIMER_ACTIVE = 0x04,
340 AHD_DEV_ON_RUN_LIST = 0x08,
341 AHD_DEV_Q_BASIC = 0x10,
342 AHD_DEV_Q_TAGGED = 0x20,
343 AHD_DEV_PERIODIC_OTAG = 0x40,
344 AHD_DEV_SLAVE_CONFIGURED = 0x80
345} ahd_linux_dev_flags;
346
347struct ahd_linux_target;
348struct ahd_linux_device {
349 TAILQ_ENTRY(ahd_linux_device) links;
350 struct ahd_busyq busyq;
351
352
353
354
355
356 int active;
357
358
359
360
361
362
363
364
365
366 int openings;
367
368
369
370
371
372 u_int qfrozen;
373
374
375
376
377 u_long commands_issued;
378
379
380
381
382
383
384
385 u_int tag_success_count;
386#define AHD_TAG_SUCCESS_INTERVAL 50
387
388 ahd_linux_dev_flags flags;
389
390
391
392
393 struct timer_list timer;
394
395
396
397
398 u_int maxtags;
399
400
401
402
403
404 u_int tags_on_last_queuefull;
405
406
407
408
409
410
411
412 u_int last_queuefull_same_count;
413#define AHD_LOCK_TAGS_COUNT 50
414
415
416
417
418
419
420
421
422
423
424 u_int commands_since_idle_or_otag;
425#define AHD_OTAG_THRESH 500
426
427 int lun;
428 Scsi_Device *scsi_device;
429 struct ahd_linux_target *target;
430};
431
432typedef enum {
433 AHD_DV_REQUIRED = 0x01,
434 AHD_INQ_VALID = 0x02,
435 AHD_BASIC_DV = 0x04,
436 AHD_ENHANCED_DV = 0x08
437} ahd_linux_targ_flags;
438
439
440typedef enum {
441 AHD_DV_STATE_EXIT = 0,
442 AHD_DV_STATE_INQ_SHORT_ASYNC,
443 AHD_DV_STATE_INQ_ASYNC,
444 AHD_DV_STATE_INQ_ASYNC_VERIFY,
445 AHD_DV_STATE_TUR,
446 AHD_DV_STATE_REBD,
447 AHD_DV_STATE_INQ_VERIFY,
448 AHD_DV_STATE_WEB,
449 AHD_DV_STATE_REB,
450 AHD_DV_STATE_SU,
451 AHD_DV_STATE_BUSY
452} ahd_dv_state;
453
454struct ahd_linux_target {
455 struct ahd_linux_device *devices[AHD_NUM_LUNS];
456 int channel;
457 int target;
458 int refcount;
459 struct ahd_transinfo last_tinfo;
460 struct ahd_softc *ahd;
461 ahd_linux_targ_flags flags;
462 struct scsi_inquiry_data *inq_data;
463
464
465
466 uint8_t dv_next_narrow_period;
467 uint8_t dv_next_wide_period;
468 uint8_t dv_max_width;
469 uint8_t dv_max_ppr_options;
470 uint8_t dv_last_ppr_options;
471 u_int dv_echo_size;
472 ahd_dv_state dv_state;
473 u_int dv_state_retry;
474 uint8_t *dv_buffer;
475 uint8_t *dv_buffer1;
476
477
478
479
480 u_long errors_detected;
481 u_long cmds_since_error;
482};
483
484
485
486
487
488
489
490
491#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
492
493
494
495
496
497extern u_int ahd_linux_nseg;
498#define AHD_NSEG ahd_linux_nseg
499#define AHD_LINUX_MIN_NSEG 64
500#else
501#define AHD_NSEG 128
502#endif
503
504
505
506
507typedef enum {
508 AHD_SCB_UP_EH_SEM = 0x1
509} ahd_linux_scb_flags;
510
511struct scb_platform_data {
512 struct ahd_linux_device *dev;
513 bus_addr_t buf_busaddr;
514 uint32_t xfer_len;
515#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
516 uint32_t resid;
517#endif
518 uint32_t sense_resid;
519 ahd_linux_scb_flags flags;
520};
521
522
523
524
525
526
527
528typedef enum {
529 AHD_DV_WAIT_SIMQ_EMPTY = 0x01,
530 AHD_DV_WAIT_SIMQ_RELEASE = 0x02,
531 AHD_DV_ACTIVE = 0x04,
532 AHD_DV_SHUTDOWN = 0x08,
533 AHD_RUN_CMPLT_Q_TIMER = 0x10
534} ahd_linux_softc_flags;
535
536TAILQ_HEAD(ahd_completeq, ahd_cmd);
537
538struct ahd_platform_data {
539
540
541
542 struct ahd_linux_target *targets[AHD_NUM_TARGETS];
543 TAILQ_HEAD(, ahd_linux_device) device_runq;
544 struct ahd_completeq completeq;
545
546 spinlock_t spin_lock;
547#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
548 struct tasklet_struct runq_tasklet;
549#endif
550 u_int qfrozen;
551 pid_t dv_pid;
552 struct timer_list completeq_timer;
553 struct timer_list reset_timer;
554 struct timer_list stats_timer;
555 struct semaphore eh_sem;
556 struct semaphore dv_sem;
557 struct semaphore dv_cmd_sem;
558
559
560 struct scsi_device *dv_scsi_dev;
561 struct Scsi_Host *host;
562#define AHD_LINUX_NOIRQ ((uint32_t)~0)
563 uint32_t irq;
564 uint32_t bios_address;
565 uint32_t mem_busaddr;
566 bus_addr_t hw_dma_mask;
567 ahd_linux_softc_flags flags;
568};
569
570
571#define printf printk
572#define M_NOWAIT GFP_ATOMIC
573#define M_WAITOK 0
574#define malloc(size, type, flags) kmalloc(size, flags)
575#define free(ptr, type) kfree(ptr)
576
577static __inline void ahd_delay(long);
578static __inline void
579ahd_delay(long usec)
580{
581
582
583
584
585
586 while (usec > 0) {
587 udelay(usec % 1024);
588 usec -= 1024;
589 }
590}
591
592
593
594#if defined(__powerpc__) || defined(__i386__) || defined(__ia64__)
595#define MMAPIO
596#endif
597
598static __inline uint8_t ahd_inb(struct ahd_softc * ahd, long port);
599static __inline uint16_t ahd_inw_atomic(struct ahd_softc * ahd, long port);
600static __inline void ahd_outb(struct ahd_softc * ahd, long port, uint8_t val);
601static __inline void ahd_outw_atomic(struct ahd_softc * ahd,
602 long port, uint16_t val);
603static __inline void ahd_outsb(struct ahd_softc * ahd, long port,
604 uint8_t *, int count);
605static __inline void ahd_insb(struct ahd_softc * ahd, long port,
606 uint8_t *, int count);
607
608static __inline uint8_t
609ahd_inb(struct ahd_softc * ahd, long port)
610{
611 uint8_t x;
612#ifdef MMAPIO
613
614 if (ahd->tags[0] == BUS_SPACE_MEMIO) {
615 x = readb(ahd->bshs[0].maddr + port);
616 } else {
617 x = inb(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
618 }
619#else
620 x = inb(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
621#endif
622 mb();
623 return (x);
624}
625
626static __inline uint16_t
627ahd_inw_atomic(struct ahd_softc * ahd, long port)
628{
629 uint8_t x;
630#ifdef MMAPIO
631
632 if (ahd->tags[0] == BUS_SPACE_MEMIO) {
633 x = readw(ahd->bshs[0].maddr + port);
634 } else {
635 x = inw(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
636 }
637#else
638 x = inw(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
639#endif
640 mb();
641 return (x);
642}
643
644static __inline void
645ahd_outb(struct ahd_softc * ahd, long port, uint8_t val)
646{
647#ifdef MMAPIO
648 if (ahd->tags[0] == BUS_SPACE_MEMIO) {
649 writeb(val, ahd->bshs[0].maddr + port);
650 } else {
651 outb(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
652 }
653#else
654 outb(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
655#endif
656 mb();
657}
658
659static __inline void
660ahd_outw_atomic(struct ahd_softc * ahd, long port, uint16_t val)
661{
662#ifdef MMAPIO
663 if (ahd->tags[0] == BUS_SPACE_MEMIO) {
664 writew(val, ahd->bshs[0].maddr + port);
665 } else {
666 outw(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
667 }
668#else
669 outw(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
670#endif
671 mb();
672}
673
674static __inline void
675ahd_outsb(struct ahd_softc * ahd, long port, uint8_t *array, int count)
676{
677 int i;
678
679
680
681
682
683
684 for (i = 0; i < count; i++)
685 ahd_outb(ahd, port, *array++);
686}
687
688static __inline void
689ahd_insb(struct ahd_softc * ahd, long port, uint8_t *array, int count)
690{
691 int i;
692
693
694
695
696
697
698 for (i = 0; i < count; i++)
699 *array++ = ahd_inb(ahd, port);
700}
701
702
703int ahd_linux_register_host(struct ahd_softc *,
704 Scsi_Host_Template *);
705
706uint64_t ahd_linux_get_memsize(void);
707
708
709struct info_str {
710 char *buffer;
711 int length;
712 off_t offset;
713 int pos;
714};
715
716void ahd_format_transinfo(struct info_str *info,
717 struct ahd_transinfo *tinfo);
718
719
720
721static __inline void ahd_lockinit(struct ahd_softc *);
722static __inline void ahd_lock(struct ahd_softc *, unsigned long *flags);
723static __inline void ahd_unlock(struct ahd_softc *, unsigned long *flags);
724
725
726static __inline void ahd_midlayer_entrypoint_lock(struct ahd_softc *,
727 unsigned long *flags);
728static __inline void ahd_midlayer_entrypoint_unlock(struct ahd_softc *,
729 unsigned long *flags);
730
731
732static __inline void ahd_done_lockinit(struct ahd_softc *);
733static __inline void ahd_done_lock(struct ahd_softc *, unsigned long *flags);
734static __inline void ahd_done_unlock(struct ahd_softc *, unsigned long *flags);
735
736
737extern spinlock_t ahd_list_spinlock;
738static __inline void ahd_list_lockinit(void);
739static __inline void ahd_list_lock(unsigned long *flags);
740static __inline void ahd_list_unlock(unsigned long *flags);
741
742static __inline void
743ahd_lockinit(struct ahd_softc *ahd)
744{
745 spin_lock_init(&ahd->platform_data->spin_lock);
746}
747
748static __inline void
749ahd_lock(struct ahd_softc *ahd, unsigned long *flags)
750{
751 spin_lock_irqsave(&ahd->platform_data->spin_lock, *flags);
752}
753
754static __inline void
755ahd_unlock(struct ahd_softc *ahd, unsigned long *flags)
756{
757 spin_unlock_irqrestore(&ahd->platform_data->spin_lock, *flags);
758}
759
760static __inline void
761ahd_midlayer_entrypoint_lock(struct ahd_softc *ahd, unsigned long *flags)
762{
763
764
765
766
767
768
769
770#if AHD_SCSI_HAS_HOST_LOCK == 0
771 spin_unlock(&io_request_lock);
772 spin_lock(&ahd->platform_data->spin_lock);
773#endif
774}
775
776static __inline void
777ahd_midlayer_entrypoint_unlock(struct ahd_softc *ahd, unsigned long *flags)
778{
779#if AHD_SCSI_HAS_HOST_LOCK == 0
780 spin_unlock(&ahd->platform_data->spin_lock);
781 spin_lock(&io_request_lock);
782#endif
783}
784
785static __inline void
786ahd_done_lockinit(struct ahd_softc *ahd)
787{
788
789
790
791
792
793}
794
795static __inline void
796ahd_done_lock(struct ahd_softc *ahd, unsigned long *flags)
797{
798#if AHD_SCSI_HAS_HOST_LOCK == 0
799 spin_lock(&io_request_lock);
800#endif
801}
802
803static __inline void
804ahd_done_unlock(struct ahd_softc *ahd, unsigned long *flags)
805{
806#if AHD_SCSI_HAS_HOST_LOCK == 0
807 spin_unlock(&io_request_lock);
808#endif
809}
810
811static __inline void
812ahd_list_lockinit()
813{
814 spin_lock_init(&ahd_list_spinlock);
815}
816
817static __inline void
818ahd_list_lock(unsigned long *flags)
819{
820 spin_lock_irqsave(&ahd_list_spinlock, *flags);
821}
822
823static __inline void
824ahd_list_unlock(unsigned long *flags)
825{
826 spin_unlock_irqrestore(&ahd_list_spinlock, *flags);
827}
828
829
830
831
832
833
834
835
836
837
838
839#define PCIR_DEVVENDOR 0x00
840#define PCIR_VENDOR 0x00
841#define PCIR_DEVICE 0x02
842#define PCIR_COMMAND 0x04
843#define PCIM_CMD_PORTEN 0x0001
844#define PCIM_CMD_MEMEN 0x0002
845#define PCIM_CMD_BUSMASTEREN 0x0004
846#define PCIM_CMD_MWRICEN 0x0010
847#define PCIM_CMD_PERRESPEN 0x0040
848#define PCIM_CMD_SERRESPEN 0x0100
849#define PCIR_STATUS 0x06
850#define PCIR_REVID 0x08
851#define PCIR_PROGIF 0x09
852#define PCIR_SUBCLASS 0x0a
853#define PCIR_CLASS 0x0b
854#define PCIR_CACHELNSZ 0x0c
855#define PCIR_LATTIMER 0x0d
856#define PCIR_HEADERTYPE 0x0e
857#define PCIM_MFDEV 0x80
858#define PCIR_BIST 0x0f
859#define PCIR_CAP_PTR 0x34
860
861
862#define PCIR_MAPS 0x10
863#define PCIR_SUBVEND_0 0x2c
864#define PCIR_SUBDEV_0 0x2e
865
866
867#define PCIXR_COMMAND 0x96
868#define PCIXR_DEVADDR 0x98
869#define PCIXM_DEVADDR_FNUM 0x0003
870#define PCIXM_DEVADDR_DNUM 0x00F8
871#define PCIXM_DEVADDR_BNUM 0xFF00
872#define PCIXR_STATUS 0x9A
873#define PCIXM_STATUS_64BIT 0x0001
874#define PCIXM_STATUS_133CAP 0x0002
875#define PCIXM_STATUS_SCDISC 0x0004
876#define PCIXM_STATUS_UNEXPSC 0x0008
877#define PCIXM_STATUS_CMPLEXDEV 0x0010
878#define PCIXM_STATUS_MAXMRDBC 0x0060
879#define PCIXM_STATUS_MAXSPLITS 0x0380
880#define PCIXM_STATUS_MAXCRDS 0x1C00
881#define PCIXM_STATUS_RCVDSCEM 0x2000
882
883#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
884extern struct pci_driver aic79xx_pci_driver;
885#endif
886
887typedef enum
888{
889 AHD_POWER_STATE_D0,
890 AHD_POWER_STATE_D1,
891 AHD_POWER_STATE_D2,
892 AHD_POWER_STATE_D3
893} ahd_power_state;
894
895void ahd_power_state_change(struct ahd_softc *ahd,
896 ahd_power_state new_state);
897
898
899int ahd_linux_pci_init(void);
900void ahd_linux_pci_exit(void);
901int ahd_pci_map_registers(struct ahd_softc *ahd);
902int ahd_pci_map_int(struct ahd_softc *ahd);
903
904static __inline uint32_t ahd_pci_read_config(ahd_dev_softc_t pci,
905 int reg, int width);
906
907static __inline uint32_t
908ahd_pci_read_config(ahd_dev_softc_t pci, int reg, int width)
909{
910 switch (width) {
911 case 1:
912 {
913 uint8_t retval;
914
915 pci_read_config_byte(pci, reg, &retval);
916 return (retval);
917 }
918 case 2:
919 {
920 uint16_t retval;
921 pci_read_config_word(pci, reg, &retval);
922 return (retval);
923 }
924 case 4:
925 {
926 uint32_t retval;
927 pci_read_config_dword(pci, reg, &retval);
928 return (retval);
929 }
930 default:
931 panic("ahd_pci_read_config: Read size too big");
932
933 return (0);
934 }
935}
936
937static __inline void ahd_pci_write_config(ahd_dev_softc_t pci,
938 int reg, uint32_t value,
939 int width);
940
941static __inline void
942ahd_pci_write_config(ahd_dev_softc_t pci, int reg, uint32_t value, int width)
943{
944 switch (width) {
945 case 1:
946 pci_write_config_byte(pci, reg, value);
947 break;
948 case 2:
949 pci_write_config_word(pci, reg, value);
950 break;
951 case 4:
952 pci_write_config_dword(pci, reg, value);
953 break;
954 default:
955 panic("ahd_pci_write_config: Write size too big");
956
957 }
958}
959
960static __inline int ahd_get_pci_function(ahd_dev_softc_t);
961static __inline int
962ahd_get_pci_function(ahd_dev_softc_t pci)
963{
964 return (PCI_FUNC(pci->devfn));
965}
966
967static __inline int ahd_get_pci_slot(ahd_dev_softc_t);
968static __inline int
969ahd_get_pci_slot(ahd_dev_softc_t pci)
970{
971 return (PCI_SLOT(pci->devfn));
972}
973
974static __inline int ahd_get_pci_bus(ahd_dev_softc_t);
975static __inline int
976ahd_get_pci_bus(ahd_dev_softc_t pci)
977{
978 return (pci->bus->number);
979}
980
981static __inline void ahd_flush_device_writes(struct ahd_softc *);
982static __inline void
983ahd_flush_device_writes(struct ahd_softc *ahd)
984{
985
986 ahd_inb(ahd, INTSTAT);
987}
988
989#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,0)
990#define pci_map_sg(pdev, sg_list, nseg, direction) (nseg)
991#define pci_unmap_sg(pdev, sg_list, nseg, direction)
992#define sg_dma_address(sg) (VIRT_TO_BUS((sg)->address))
993#define sg_dma_len(sg) ((sg)->length)
994#define pci_map_single(pdev, buffer, bufflen, direction) \
995 (VIRT_TO_BUS(buffer))
996#define pci_unmap_single(pdev, buffer, buflen, direction)
997#endif
998
999#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,3)
1000#define ahd_pci_set_dma_mask pci_set_dma_mask
1001#else
1002
1003
1004
1005#define ahd_pci_set_dma_mask(dev_softc, mask) \
1006 (((dev_softc)->dma_mask = mask) && 0)
1007#endif
1008
1009#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1010int ahd_linux_proc_info(char *, char **, off_t, int, int, int);
1011#else
1012int ahd_linux_proc_info(struct Scsi_Host *, char *, char **,
1013 off_t, int, int);
1014#endif
1015
1016
1017#define AHD_DV_CMD(cmd) ((cmd)->scsi_done == ahd_linux_dv_complete)
1018#define AHD_DV_SIMQ_FROZEN(ahd) \
1019 ((((ahd)->platform_data->flags & AHD_DV_ACTIVE) != 0) \
1020 && (ahd)->platform_data->qfrozen == 1)
1021
1022
1023static __inline void ahd_cmd_set_transaction_status(Scsi_Cmnd *, uint32_t);
1024static __inline void ahd_set_transaction_status(struct scb *, uint32_t);
1025static __inline void ahd_cmd_set_scsi_status(Scsi_Cmnd *, uint32_t);
1026static __inline void ahd_set_scsi_status(struct scb *, uint32_t);
1027static __inline uint32_t ahd_cmd_get_transaction_status(Scsi_Cmnd *cmd);
1028static __inline uint32_t ahd_get_transaction_status(struct scb *);
1029static __inline uint32_t ahd_cmd_get_scsi_status(Scsi_Cmnd *cmd);
1030static __inline uint32_t ahd_get_scsi_status(struct scb *);
1031static __inline void ahd_set_transaction_tag(struct scb *, int, u_int);
1032static __inline u_long ahd_get_transfer_length(struct scb *);
1033static __inline int ahd_get_transfer_dir(struct scb *);
1034static __inline void ahd_set_residual(struct scb *, u_long);
1035static __inline void ahd_set_sense_residual(struct scb *scb, u_long resid);
1036static __inline u_long ahd_get_residual(struct scb *);
1037static __inline u_long ahd_get_sense_residual(struct scb *);
1038static __inline int ahd_perform_autosense(struct scb *);
1039static __inline uint32_t ahd_get_sense_bufsize(struct ahd_softc *,
1040 struct scb *);
1041static __inline void ahd_notify_xfer_settings_change(struct ahd_softc *,
1042 struct ahd_devinfo *);
1043static __inline void ahd_platform_scb_free(struct ahd_softc *ahd,
1044 struct scb *scb);
1045static __inline void ahd_freeze_scb(struct scb *scb);
1046
1047static __inline
1048void ahd_cmd_set_transaction_status(Scsi_Cmnd *cmd, uint32_t status)
1049{
1050 cmd->result &= ~(CAM_STATUS_MASK << 16);
1051 cmd->result |= status << 16;
1052}
1053
1054static __inline
1055void ahd_set_transaction_status(struct scb *scb, uint32_t status)
1056{
1057 ahd_cmd_set_transaction_status(scb->io_ctx,status);
1058}
1059
1060static __inline
1061void ahd_cmd_set_scsi_status(Scsi_Cmnd *cmd, uint32_t status)
1062{
1063 cmd->result &= ~0xFFFF;
1064 cmd->result |= status;
1065}
1066
1067static __inline
1068void ahd_set_scsi_status(struct scb *scb, uint32_t status)
1069{
1070 ahd_cmd_set_scsi_status(scb->io_ctx, status);
1071}
1072
1073static __inline
1074uint32_t ahd_cmd_get_transaction_status(Scsi_Cmnd *cmd)
1075{
1076 return ((cmd->result >> 16) & CAM_STATUS_MASK);
1077}
1078
1079static __inline
1080uint32_t ahd_get_transaction_status(struct scb *scb)
1081{
1082 return (ahd_cmd_get_transaction_status(scb->io_ctx));
1083}
1084
1085static __inline
1086uint32_t ahd_cmd_get_scsi_status(Scsi_Cmnd *cmd)
1087{
1088 return (cmd->result & 0xFFFF);
1089}
1090
1091static __inline
1092uint32_t ahd_get_scsi_status(struct scb *scb)
1093{
1094 return (ahd_cmd_get_scsi_status(scb->io_ctx));
1095}
1096
1097static __inline
1098void ahd_set_transaction_tag(struct scb *scb, int enabled, u_int type)
1099{
1100
1101
1102
1103
1104}
1105
1106static __inline
1107u_long ahd_get_transfer_length(struct scb *scb)
1108{
1109 return (scb->platform_data->xfer_len);
1110}
1111
1112static __inline
1113int ahd_get_transfer_dir(struct scb *scb)
1114{
1115#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,40)
1116 return (scb->io_ctx->sc_data_direction);
1117#else
1118 if (scb->io_ctx->bufflen == 0)
1119 return (CAM_DIR_NONE);
1120
1121 switch(scb->io_ctx->cmnd[0]) {
1122 case 0x08:
1123 case 0x28:
1124 case 0xA8:
1125 return (CAM_DIR_IN);
1126 case 0x0A:
1127 case 0x2A:
1128 case 0xAA:
1129 return (CAM_DIR_OUT);
1130 default:
1131 return (CAM_DIR_NONE);
1132 }
1133#endif
1134}
1135
1136static __inline
1137void ahd_set_residual(struct scb *scb, u_long resid)
1138{
1139#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
1140 scb->io_ctx->resid = resid;
1141#else
1142 scb->platform_data->resid = resid;
1143#endif
1144}
1145
1146static __inline
1147void ahd_set_sense_residual(struct scb *scb, u_long resid)
1148{
1149 scb->platform_data->sense_resid = resid;
1150}
1151
1152static __inline
1153u_long ahd_get_residual(struct scb *scb)
1154{
1155#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
1156 return (scb->io_ctx->resid);
1157#else
1158 return (scb->platform_data->resid);
1159#endif
1160}
1161
1162static __inline
1163u_long ahd_get_sense_residual(struct scb *scb)
1164{
1165 return (scb->platform_data->sense_resid);
1166}
1167
1168static __inline
1169int ahd_perform_autosense(struct scb *scb)
1170{
1171
1172
1173
1174
1175
1176 return (1);
1177}
1178
1179static __inline uint32_t
1180ahd_get_sense_bufsize(struct ahd_softc *ahd, struct scb *scb)
1181{
1182 return (sizeof(struct scsi_sense_data));
1183}
1184
1185static __inline void
1186ahd_notify_xfer_settings_change(struct ahd_softc *ahd,
1187 struct ahd_devinfo *devinfo)
1188{
1189
1190}
1191
1192static __inline void
1193ahd_platform_scb_free(struct ahd_softc *ahd, struct scb *scb)
1194{
1195 ahd->flags &= ~AHD_RESOURCE_SHORTAGE;
1196}
1197
1198int ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg);
1199void ahd_platform_free(struct ahd_softc *ahd);
1200void ahd_platform_init(struct ahd_softc *ahd);
1201void ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb);
1202void ahd_freeze_simq(struct ahd_softc *ahd);
1203void ahd_release_simq(struct ahd_softc *ahd);
1204
1205static __inline void
1206ahd_freeze_scb(struct scb *scb)
1207{
1208 if ((scb->io_ctx->result & (CAM_DEV_QFRZN << 16)) == 0) {
1209 scb->io_ctx->result |= CAM_DEV_QFRZN << 16;
1210 scb->platform_data->dev->qfrozen++;
1211 }
1212}
1213
1214void ahd_platform_set_tags(struct ahd_softc *ahd,
1215 struct ahd_devinfo *devinfo, ahd_queue_alg);
1216int ahd_platform_abort_scbs(struct ahd_softc *ahd, int target,
1217 char channel, int lun, u_int tag,
1218 role_t role, uint32_t status);
1219irqreturn_t
1220 ahd_linux_isr(int irq, void *dev_id, struct pt_regs * regs);
1221void ahd_platform_flushwork(struct ahd_softc *ahd);
1222int ahd_softc_comp(struct ahd_softc *, struct ahd_softc *);
1223void ahd_done(struct ahd_softc*, struct scb*);
1224void ahd_send_async(struct ahd_softc *, char channel,
1225 u_int target, u_int lun, ac_code, void *);
1226void ahd_print_path(struct ahd_softc *, struct scb *);
1227void ahd_platform_dump_card_state(struct ahd_softc *ahd);
1228
1229#ifdef CONFIG_PCI
1230#define AHD_PCI_CONFIG 1
1231#else
1232#define AHD_PCI_CONFIG 0
1233#endif
1234#define bootverbose aic79xx_verbose
1235extern uint32_t aic79xx_verbose;
1236#endif
1237