2 * Copyright (C) 1997 Wu Ching Chen
3 * 2.1.x update (C) 1998 Krzysztof G. Baranowski
4 * 2.5.x update (C) 2002 Red Hat <alan@redhat.com>
5 * 2.6.x update (C) 2004 Red Hat <alan@redhat.com>
7 * Marcelo Tosatti <marcelo@conectiva.com.br> : SMP fixes
9 * Wu Ching Chen : NULL pointer fixes 2000/06/02
11 * enable 32 bit fifo transfer
12 * support cdrom & remove device run ultra speed
13 * fix disconnect bug 2000/12/21
14 * support atp880 chip lvd u160 2001/05/15
15 * fix prd table bug 2001/09/12 (7.1)
17 * atp885 support add by ACARD Hao Ping Lian 2005/01/05
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/interrupt.h>
22 #include <linux/kernel.h>
23 #include <linux/types.h>
24 #include <linux/string.h>
25 #include <linux/ioport.h>
26 #include <linux/delay.h>
27 #include <linux/proc_fs.h>
28 #include <linux/spinlock.h>
29 #include <linux/pci.h>
30 #include <linux/blkdev.h>
31 #include <asm/system.h>
34 #include <scsi/scsi.h>
35 #include <scsi/scsi_cmnd.h>
36 #include <scsi/scsi_device.h>
37 #include <scsi/scsi_host.h>
41 static struct scsi_host_template atp870u_template
;
42 static void send_s870(struct atp_unit
*dev
,unsigned char c
);
43 static void is885(struct atp_unit
*dev
, unsigned int wkport
,unsigned char c
);
44 static void tscam_885(void);
46 static irqreturn_t
atp870u_intr_handle(int irq
, void *dev_id
, struct pt_regs
*regs
)
49 unsigned short int tmpcip
, id
;
50 unsigned char i
, j
, c
, target_id
, lun
,cmdp
;
52 struct scsi_cmnd
*workreq
;
53 unsigned int workport
, tmport
, tmport1
;
54 unsigned long adrcnt
, k
;
59 struct Scsi_Host
*host
= dev_id
;
60 struct atp_unit
*dev
= (struct atp_unit
*)&host
->hostdata
;
62 for (c
= 0; c
< 2; c
++) {
63 tmport
= dev
->ioport
[c
] + 0x1f;
74 printk("atp870u_intr_handle enter\n");
77 cmdp
= inb(dev
->ioport
[c
] + 0x10);
78 workport
= dev
->ioport
[c
];
79 if (dev
->working
[c
] != 0) {
80 if (dev
->dev_id
== ATP885_DEVID
) {
81 tmport1
= workport
+ 0x16;
82 if ((inb(tmport1
) & 0x80) == 0)
83 outb((inb(tmport1
) | 0x80), tmport1
);
85 tmpcip
= dev
->pciport
[c
];
86 if ((inb(tmpcip
) & 0x08) != 0)
89 for (k
=0; k
< 1000; k
++) {
90 if ((inb(tmpcip
) & 0x08) == 0) {
93 if ((inb(tmpcip
) & 0x01) == 0) {
99 tmpcip
= dev
->pciport
[c
];
105 if (dev
->dev_id
== ATP885_DEVID
) {
112 target_id
= inb(tmport
);
116 * Remap wide devices onto id numbers
119 if ((target_id
& 0x40) != 0) {
120 target_id
= (target_id
& 0x07) | 0x08;
125 if ((j
& 0x40) != 0) {
126 if (dev
->last_cmd
[c
] == 0xff) {
127 dev
->last_cmd
[c
] = target_id
;
129 dev
->last_cmd
[c
] |= 0x40;
131 if (dev
->dev_id
== ATP885_DEVID
)
132 dev
->r1f
[c
][target_id
] |= j
;
134 printk("atp870u_intr_handle status = %x\n",i
);
137 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
138 dev
->last_cmd
[c
] = 0xff;
140 if (dev
->dev_id
== ATP885_DEVID
) {
143 ((unsigned char *) &adrcnt
)[2] = inb(tmport
++);
144 ((unsigned char *) &adrcnt
)[1] = inb(tmport
++);
145 ((unsigned char *) &adrcnt
)[0] = inb(tmport
);
146 if (dev
->id
[c
][target_id
].last_len
!= adrcnt
)
148 k
= dev
->id
[c
][target_id
].last_len
;
150 dev
->id
[c
][target_id
].tran_len
= k
;
151 dev
->id
[c
][target_id
].last_len
= adrcnt
;
154 printk("tmport = %x dev->id[c][target_id].last_len = %d dev->id[c][target_id].tran_len = %d\n",tmport
,dev
->id
[c
][target_id
].last_len
,dev
->id
[c
][target_id
].tran_len
);
161 if (dev
->wide_id
[c
] != 0) {
162 tmport
= workport
+ 0x1b;
164 while ((inb(tmport
) & 0x01) != 0x01) {
169 * Issue more commands
171 spin_lock_irqsave(dev
->host
->host_lock
, flags
);
172 if (((dev
->quhd
[c
] != dev
->quend
[c
]) || (dev
->last_cmd
[c
] != 0xff)) &&
173 (dev
->in_snd
[c
] == 0)) {
175 printk("Call sent_s870\n");
179 spin_unlock_irqrestore(dev
->host
->host_lock
, flags
);
185 printk("Status 0x85 return\n");
191 dev
->last_cmd
[c
] |= 0x40;
197 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
198 dev
->last_cmd
[c
] = 0xff;
202 ((unsigned char *) &adrcnt
)[2] = inb(tmport
++);
203 ((unsigned char *) &adrcnt
)[1] = inb(tmport
++);
204 ((unsigned char *) &adrcnt
)[0] = inb(tmport
);
205 k
= dev
->id
[c
][target_id
].last_len
;
207 dev
->id
[c
][target_id
].tran_len
= k
;
208 dev
->id
[c
][target_id
].last_len
= adrcnt
;
217 if (dev
->dev_id
== ATP885_DEVID
) {
218 if ((i
== 0x4c) || (i
== 0x4d) || (i
== 0x8c) || (i
== 0x8d)) {
219 if ((i
== 0x4c) || (i
== 0x8c))
226 if ((i
== 0x80) || (i
== 0x8f)) {
228 printk(KERN_DEBUG
"Device reselect\n");
232 if (cmdp
== 0x44 || i
==0x80) {
234 lun
= inb(tmport
) & 0x07;
236 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
237 dev
->last_cmd
[c
] = 0xff;
241 printk("cmdp = 0x41\n");
245 ((unsigned char *) &adrcnt
)[2] = inb(tmport
++);
246 ((unsigned char *) &adrcnt
)[1] = inb(tmport
++);
247 ((unsigned char *) &adrcnt
)[0] = inb(tmport
);
248 k
= dev
->id
[c
][target_id
].last_len
;
250 dev
->id
[c
][target_id
].tran_len
= k
;
251 dev
->id
[c
][target_id
].last_len
= adrcnt
;
258 printk("cmdp != 0x41\n");
261 dev
->id
[c
][target_id
].dirct
= 0x00;
263 outb(0x00, tmport
++);
264 outb(0x00, tmport
++);
265 outb(0x00, tmport
++);
272 if (dev
->last_cmd
[c
] != 0xff) {
273 dev
->last_cmd
[c
] |= 0x40;
275 if (dev
->dev_id
== ATP885_DEVID
) {
276 j
= inb(dev
->baseport
+ 0x29) & 0xfe;
277 outb(j
, dev
->baseport
+ 0x29);
278 tmport
= workport
+ 0x16;
280 tmport
= workport
+ 0x10;
285 target_id
= inb(tmport
);
287 * Remap wide identifiers
289 if ((target_id
& 0x10) != 0) {
290 target_id
= (target_id
& 0x07) | 0x08;
294 if (dev
->dev_id
== ATP885_DEVID
) {
295 tmport
= workport
+ 0x10;
298 workreq
= dev
->id
[c
][target_id
].curr_req
;
300 scmd_printk(KERN_DEBUG
, workreq
, "CDB");
301 for (l
= 0; l
< workreq
->cmd_len
; l
++)
302 printk(KERN_DEBUG
" %x",workreq
->cmnd
[l
]);
306 tmport
= workport
+ 0x0f;
309 outb(dev
->id
[c
][target_id
].devsp
, tmport
++);
310 adrcnt
= dev
->id
[c
][target_id
].tran_len
;
311 k
= dev
->id
[c
][target_id
].last_len
;
313 outb(((unsigned char *) &k
)[2], tmport
++);
314 outb(((unsigned char *) &k
)[1], tmport
++);
315 outb(((unsigned char *) &k
)[0], tmport
++);
317 printk("k %x, k[0] 0x%x k[1] 0x%x k[2] 0x%x\n", k
, inb(tmport
-1), inb(tmport
-2), inb(tmport
-3));
322 j
= (j
& 0x07) | 0x40;
325 j
|= dev
->id
[c
][target_id
].dirct
;
329 /* enable 32 bit fifo transfer */
330 if (dev
->dev_id
== ATP885_DEVID
) {
331 tmpcip
= dev
->pciport
[c
] + 1;
332 i
=inb(tmpcip
) & 0xf3;
333 //j=workreq->cmnd[0];
334 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
338 } else if ((dev
->dev_id
== ATP880_DEVID1
) ||
339 (dev
->dev_id
== ATP880_DEVID2
) ) {
340 tmport
= workport
- 0x05;
341 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
342 outb((unsigned char) ((inb(tmport
) & 0x3f) | 0xc0), tmport
);
344 outb((unsigned char) (inb(tmport
) & 0x3f), tmport
);
347 tmport
= workport
+ 0x3a;
348 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
349 outb((unsigned char) ((inb(tmport
) & 0xf3) | 0x08), tmport
);
351 outb((unsigned char) (inb(tmport
) & 0xf3), tmport
);
354 tmport
= workport
+ 0x1b;
357 id
= id
<< target_id
;
359 * Is this a wide device
361 if ((id
& dev
->wide_id
[c
]) != 0) {
365 while ((inb(tmport
) & 0x01) != j
) {
368 if (dev
->id
[c
][target_id
].last_len
== 0) {
369 tmport
= workport
+ 0x18;
373 printk("dev->id[c][target_id].last_len = 0\n");
378 printk("target_id = %d adrcnt = %d\n",target_id
,adrcnt
);
380 prd
= dev
->id
[c
][target_id
].prd_pos
;
381 while (adrcnt
!= 0) {
382 id
= ((unsigned short int *)prd
)[2];
389 ((unsigned short int *)prd
)[2] = (unsigned short int)
391 ((unsigned long *)prd
)[0] += adrcnt
;
393 dev
->id
[c
][target_id
].prd_pos
= prd
;
396 dev
->id
[c
][target_id
].prdaddr
+= 0x08;
399 dev
->id
[c
][target_id
].prd_pos
= prd
;
403 tmpcip
= dev
->pciport
[c
] + 0x04;
404 outl(dev
->id
[c
][target_id
].prdaddr
, tmpcip
);
406 printk("dev->id[%d][%d].prdaddr 0x%8x\n", c
, target_id
, dev
->id
[c
][target_id
].prdaddr
);
408 if (dev
->dev_id
== ATP885_DEVID
) {
416 tmport
= workport
+ 0x18;
418 * Check transfer direction
420 if (dev
->id
[c
][target_id
].dirct
!= 0) {
425 printk("status 0x80 return dirct != 0\n");
433 printk("status 0x80 return dirct = 0\n");
439 * Current scsi request on this target
442 workreq
= dev
->id
[c
][target_id
].curr_req
;
445 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40)
447 dev
->last_cmd
[c
] = 0xff;
450 workreq
->result
= errstus
;
454 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
455 dev
->last_cmd
[c
] = 0xff;
459 errstus
= inb(tmport
);
460 if (((dev
->r1f
[c
][target_id
] & 0x10) != 0)&&(dev
->dev_id
==ATP885_DEVID
)) {
461 printk(KERN_WARNING
"AEC67162 CRC ERROR !\n");
464 workreq
->result
= errstus
;
466 if (dev
->dev_id
== ATP885_DEVID
) {
467 j
= inb(dev
->baseport
+ 0x29) | 0x01;
468 outb(j
, dev
->baseport
+ 0x29);
471 * Complete the command
473 if (workreq
->use_sg
) {
474 pci_unmap_sg(dev
->pdev
,
475 (struct scatterlist
*)workreq
->buffer
,
477 workreq
->sc_data_direction
);
478 } else if (workreq
->request_bufflen
&&
479 workreq
->sc_data_direction
!= DMA_NONE
) {
480 pci_unmap_single(dev
->pdev
,
481 workreq
->SCp
.dma_handle
,
482 workreq
->request_bufflen
,
483 workreq
->sc_data_direction
);
485 spin_lock_irqsave(dev
->host
->host_lock
, flags
);
486 (*workreq
->scsi_done
) (workreq
);
488 printk("workreq->scsi_done\n");
491 * Clear it off the queue
493 dev
->id
[c
][target_id
].curr_req
= NULL
;
495 spin_unlock_irqrestore(dev
->host
->host_lock
, flags
);
499 if (dev
->wide_id
[c
] != 0) {
500 tmport
= workport
+ 0x1b;
502 while ((inb(tmport
) & 0x01) != 0x01) {
507 * If there is stuff to send and nothing going then send it
509 spin_lock_irqsave(dev
->host
->host_lock
, flags
);
510 if (((dev
->last_cmd
[c
] != 0xff) || (dev
->quhd
[c
] != dev
->quend
[c
])) &&
511 (dev
->in_snd
[c
] == 0)) {
513 printk("Call sent_s870(scsi_done)\n");
517 spin_unlock_irqrestore(dev
->host
->host_lock
, flags
);
521 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
522 dev
->last_cmd
[c
] = 0xff;
530 outl(dev
->id
[c
][target_id
].prdaddr
, tmpcip
);
535 tmport
= workport
+ 0x10;
537 if (dev
->dev_id
== ATP885_DEVID
) {
539 k
= dev
->id
[c
][target_id
].last_len
;
540 outb((unsigned char) (((unsigned char *) (&k
))[2]), tmport
++);
541 outb((unsigned char) (((unsigned char *) (&k
))[1]), tmport
++);
542 outb((unsigned char) (((unsigned char *) (&k
))[0]), tmport
);
543 dev
->id
[c
][target_id
].dirct
= 0x00;
546 dev
->id
[c
][target_id
].dirct
= 0x00;
556 outl(dev
->id
[c
][target_id
].prdaddr
, tmpcip
);
561 tmport
= workport
+ 0x10;
563 if (dev
->dev_id
== ATP885_DEVID
) {
565 k
= dev
->id
[c
][target_id
].last_len
;
566 outb((unsigned char) (((unsigned char *) (&k
))[2]), tmport
++);
567 outb((unsigned char) (((unsigned char *) (&k
))[1]), tmport
++);
568 outb((unsigned char) (((unsigned char *) (&k
))[0]), tmport
++);
572 outb((unsigned char) (inb(tmport
) | 0x20), tmport
);
573 dev
->id
[c
][target_id
].dirct
= 0x20;
586 dev
->id
[c
][target_id
].dirct
= 0x00;
588 outb(0x00, tmport
++);
589 outb(0x00, tmport
++);
590 outb(0x00, tmport
++);
596 // tmport = workport + 0x17;
598 // dev->working[c] = 0;
605 printk("atp870u_intr_handle exit\n");
610 * atp870u_queuecommand - Queue SCSI command
611 * @req_p: request block
612 * @done: completion function
614 * Queue a command to the ATP queue. Called with the host lock held.
616 static int atp870u_queuecommand(struct scsi_cmnd
* req_p
,
617 void (*done
) (struct scsi_cmnd
*))
620 unsigned int tmport
,m
;
621 struct atp_unit
*dev
;
622 struct Scsi_Host
*host
;
624 c
= scmd_channel(req_p
);
625 req_p
->sense_buffer
[0]=0;
627 if (scmd_channel(req_p
) > 1) {
628 req_p
->result
= 0x00040000;
631 printk("atp870u_queuecommand : req_p->device->channel > 1\n");
636 host
= req_p
->device
->host
;
637 dev
= (struct atp_unit
*)&host
->hostdata
;
642 m
= m
<< scmd_id(req_p
);
645 * Fake a timeout for missing targets
648 if ((m
& dev
->active_id
[c
]) == 0) {
649 req_p
->result
= 0x00040000;
655 req_p
->scsi_done
= done
;
658 printk( "atp870u_queuecommand: done can't be NULL\n");
669 if (dev
->quend
[c
] >= qcnt
) {
676 if (dev
->quhd
[c
] == dev
->quend
[c
]) {
677 if (dev
->quend
[c
] == 0) {
678 dev
->quend
[c
] = qcnt
;
681 printk("atp870u_queuecommand : dev->quhd[c] == dev->quend[c]\n");
684 req_p
->result
= 0x00020000;
688 dev
->quereq
[c
][dev
->quend
[c
]] = req_p
;
689 tmport
= dev
->ioport
[c
] + 0x1c;
691 printk("dev->ioport[c] = %x inb(tmport) = %x dev->in_int[%d] = %d dev->in_snd[%d] = %d\n",dev
->ioport
[c
],inb(tmport
),c
,dev
->in_int
[c
],c
,dev
->in_snd
[c
]);
693 if ((inb(tmport
) == 0) && (dev
->in_int
[c
] == 0) && (dev
->in_snd
[c
] == 0)) {
695 printk("Call sent_s870(atp870u_queuecommand)\n");
700 printk("atp870u_queuecommand : exit\n");
706 * send_s870 - send a command to the controller
709 * On entry there is work queued to be done. We move some of that work to the
712 * Caller holds the host lock.
714 static void send_s870(struct atp_unit
*dev
,unsigned char c
)
717 struct scsi_cmnd
*workreq
;
719 unsigned char j
, target_id
;
721 unsigned short int tmpcip
, w
;
722 unsigned long l
, bttl
= 0;
723 unsigned int workport
;
724 struct scatterlist
*sgpnt
;
725 unsigned long sg_count
;
727 if (dev
->in_snd
[c
] != 0) {
729 printk("cmnd in_snd\n");
734 printk("Sent_s870 enter\n");
737 if ((dev
->last_cmd
[c
] != 0xff) && ((dev
->last_cmd
[c
] & 0x40) != 0)) {
738 dev
->last_cmd
[c
] &= 0x0f;
739 workreq
= dev
->id
[c
][dev
->last_cmd
[c
]].curr_req
;
740 if (workreq
!= NULL
) { /* check NULL pointer */
743 dev
->last_cmd
[c
] = 0xff;
744 if (dev
->quhd
[c
] == dev
->quend
[c
]) {
749 if ((dev
->last_cmd
[c
] != 0xff) && (dev
->working
[c
] != 0)) {
756 if (dev
->quhd
[c
] >= qcnt
) {
759 workreq
= dev
->quereq
[c
][dev
->quhd
[c
]];
760 if (dev
->id
[c
][scmd_id(workreq
)].curr_req
== 0) {
761 dev
->id
[c
][scmd_id(workreq
)].curr_req
= workreq
;
762 dev
->last_cmd
[c
] = scmd_id(workreq
);
770 workport
= dev
->ioport
[c
];
771 tmport
= workport
+ 0x1f;
772 if ((inb(tmport
) & 0xb0) != 0) {
775 tmport
= workport
+ 0x1c;
776 if (inb(tmport
) == 0) {
781 printk("Abort to Send\n");
783 dev
->last_cmd
[c
] |= 0x40;
788 printk("OK to Send\n");
789 scmd_printk(KERN_DEBUG
, workreq
, "CDB");
790 for(i
=0;i
<workreq
->cmd_len
;i
++) {
791 printk(" %x",workreq
->cmnd
[i
]);
795 if (dev
->dev_id
== ATP885_DEVID
) {
796 j
= inb(dev
->baseport
+ 0x29) & 0xfe;
797 outb(j
, dev
->baseport
+ 0x29);
798 dev
->r1f
[c
][scmd_id(workreq
)] = 0;
801 if (workreq
->cmnd
[0] == READ_CAPACITY
) {
802 if (workreq
->request_bufflen
> 8) {
803 workreq
->request_bufflen
= 0x08;
806 if (workreq
->cmnd
[0] == 0x00) {
807 workreq
->request_bufflen
= 0;
810 tmport
= workport
+ 0x1b;
812 target_id
= scmd_id(workreq
);
819 if ((w
& dev
->wide_id
[c
]) != 0) {
823 while ((inb(tmport
) & 0x01) != j
) {
826 printk("send_s870 while loop 1\n");
834 outb(workreq
->cmd_len
, tmport
++);
835 outb(0x2c, tmport
++);
836 if (dev
->dev_id
== ATP885_DEVID
) {
837 outb(0x7f, tmport
++);
839 outb(0xcf, tmport
++);
841 for (i
= 0; i
< workreq
->cmd_len
; i
++) {
842 outb(workreq
->cmnd
[i
], tmport
++);
844 tmport
= workport
+ 0x0f;
845 outb(workreq
->device
->lun
, tmport
);
850 outb(dev
->id
[c
][target_id
].devsp
, tmport
++);
852 printk("dev->id[%d][%d].devsp = %2x\n",c
,target_id
,dev
->id
[c
][target_id
].devsp
);
855 * Figure out the transfer size
857 if (workreq
->use_sg
) {
859 printk("Using SGL\n");
863 sgpnt
= (struct scatterlist
*) workreq
->request_buffer
;
864 sg_count
= pci_map_sg(dev
->pdev
, sgpnt
, workreq
->use_sg
,
865 workreq
->sc_data_direction
);
867 for (i
= 0; i
< workreq
->use_sg
; i
++) {
868 if (sgpnt
[i
].length
== 0 || workreq
->use_sg
> ATP870U_SCATTER
) {
869 panic("Foooooooood fight!");
871 l
+= sgpnt
[i
].length
;
874 printk( "send_s870: workreq->use_sg %d, sg_count %d l %8ld\n", workreq
->use_sg
, sg_count
, l
);
876 } else if(workreq
->request_bufflen
&& workreq
->sc_data_direction
!= PCI_DMA_NONE
) {
878 printk("Not using SGL\n");
880 workreq
->SCp
.dma_handle
= pci_map_single(dev
->pdev
, workreq
->request_buffer
,
881 workreq
->request_bufflen
,
882 workreq
->sc_data_direction
);
883 l
= workreq
->request_bufflen
;
885 printk( "send_s870: workreq->use_sg %d, l %8ld\n", workreq
->use_sg
, l
);
889 * Write transfer size
891 outb((unsigned char) (((unsigned char *) (&l
))[2]), tmport
++);
892 outb((unsigned char) (((unsigned char *) (&l
))[1]), tmport
++);
893 outb((unsigned char) (((unsigned char *) (&l
))[0]), tmport
++);
895 dev
->id
[c
][j
].last_len
= l
;
896 dev
->id
[c
][j
].tran_len
= 0;
898 printk("dev->id[%2d][%2d].last_len = %d\n",c
,j
,dev
->id
[c
][j
].last_len
);
903 if ((j
& 0x08) != 0) {
904 j
= (j
& 0x07) | 0x40;
907 * Check transfer direction
909 if (workreq
->sc_data_direction
== DMA_TO_DEVICE
) {
910 outb((unsigned char) (j
| 0x20), tmport
++);
914 outb((unsigned char) (inb(tmport
) | 0x80), tmport
);
916 tmport
= workport
+ 0x1c;
917 dev
->id
[c
][target_id
].dirct
= 0;
919 if (inb(tmport
) == 0) {
920 tmport
= workport
+ 0x18;
922 printk("change SCSI_CMD_REG 0x08\n");
926 dev
->last_cmd
[c
] |= 0x40;
931 tmpcip
= dev
->pciport
[c
];
932 prd
= dev
->id
[c
][target_id
].prd_table
;
933 dev
->id
[c
][target_id
].prd_pos
= prd
;
936 * Now write the request list. Either as scatter/gather or as
940 if (workreq
->use_sg
) {
941 sgpnt
= (struct scatterlist
*) workreq
->request_buffer
;
943 for (j
= 0; j
< workreq
->use_sg
; j
++) {
944 bttl
= sg_dma_address(&sgpnt
[j
]);
945 l
=sg_dma_len(&sgpnt
[j
]);
947 printk("1. bttl %x, l %x\n",bttl
, l
);
949 while (l
> 0x10000) {
950 (((u16
*) (prd
))[i
+ 3]) = 0x0000;
951 (((u16
*) (prd
))[i
+ 2]) = 0x0000;
952 (((u32
*) (prd
))[i
>> 1]) = cpu_to_le32(bttl
);
957 (((u32
*) (prd
))[i
>> 1]) = cpu_to_le32(bttl
);
958 (((u16
*) (prd
))[i
+ 2]) = cpu_to_le16(l
);
959 (((u16
*) (prd
))[i
+ 3]) = 0;
962 (((u16
*) (prd
))[i
- 1]) = cpu_to_le16(0x8000);
964 printk("prd %4x %4x %4x %4x\n",(((unsigned short int *)prd
)[0]),(((unsigned short int *)prd
)[1]),(((unsigned short int *)prd
)[2]),(((unsigned short int *)prd
)[3]));
965 printk("2. bttl %x, l %x\n",bttl
, l
);
969 * For a linear request write a chain of blocks
971 bttl
= workreq
->SCp
.dma_handle
;
972 l
= workreq
->request_bufflen
;
975 printk("3. bttl %x, l %x\n",bttl
, l
);
977 while (l
> 0x10000) {
978 (((u16
*) (prd
))[i
+ 3]) = 0x0000;
979 (((u16
*) (prd
))[i
+ 2]) = 0x0000;
980 (((u32
*) (prd
))[i
>> 1]) = cpu_to_le32(bttl
);
985 (((u16
*) (prd
))[i
+ 3]) = cpu_to_le16(0x8000);
986 (((u16
*) (prd
))[i
+ 2]) = cpu_to_le16(l
);
987 (((u32
*) (prd
))[i
>> 1]) = cpu_to_le32(bttl
);
989 printk("prd %4x %4x %4x %4x\n",(((unsigned short int *)prd
)[0]),(((unsigned short int *)prd
)[1]),(((unsigned short int *)prd
)[2]),(((unsigned short int *)prd
)[3]));
990 printk("4. bttl %x, l %x\n",bttl
, l
);
996 printk("send_s870: prdaddr_2 0x%8x tmpcip %x target_id %d\n", dev
->id
[c
][target_id
].prdaddr
,tmpcip
,target_id
);
998 dev
->id
[c
][target_id
].prdaddr
= dev
->id
[c
][target_id
].prd_bus
;
999 outl(dev
->id
[c
][target_id
].prdaddr
, tmpcip
);
1000 tmpcip
= tmpcip
- 2;
1003 if (dev
->dev_id
== ATP885_DEVID
) {
1005 j
=inb(tmpcip
) & 0xf3;
1006 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) ||
1007 (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
1012 } else if ((dev
->dev_id
== ATP880_DEVID1
) ||
1013 (dev
->dev_id
== ATP880_DEVID2
)) {
1015 tmport
= workport
- 0x05;
1016 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
1017 outb((unsigned char) ((inb(tmport
) & 0x3f) | 0xc0), tmport
);
1019 outb((unsigned char) (inb(tmport
) & 0x3f), tmport
);
1023 tmport
= workport
+ 0x3a;
1024 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
1025 outb((inb(tmport
) & 0xf3) | 0x08, tmport
);
1027 outb(inb(tmport
) & 0xf3, tmport
);
1030 tmport
= workport
+ 0x1c;
1032 if(workreq
->sc_data_direction
== DMA_TO_DEVICE
) {
1033 dev
->id
[c
][target_id
].dirct
= 0x20;
1034 if (inb(tmport
) == 0) {
1035 tmport
= workport
+ 0x18;
1039 printk( "start DMA(to target)\n");
1042 dev
->last_cmd
[c
] |= 0x40;
1047 if (inb(tmport
) == 0) {
1048 tmport
= workport
+ 0x18;
1052 printk( "start DMA(to host)\n");
1055 dev
->last_cmd
[c
] |= 0x40;
1062 static unsigned char fun_scam(struct atp_unit
*dev
, unsigned short int *val
)
1064 unsigned int tmport
;
1065 unsigned short int i
, k
;
1068 tmport
= dev
->ioport
[0] + 0x1c;
1071 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
1073 j
= (unsigned char) (k
>> 8);
1074 if ((k
& 0x8000) != 0) { /* DB7 all release? */
1078 *val
|= 0x4000; /* assert DB6 */
1080 *val
&= 0xdfff; /* assert DB5 */
1083 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
1084 if ((inw(tmport
) & 0x2000) != 0) { /* DB5 all release? */
1088 *val
|= 0x8000; /* no DB4-0, assert DB7 */
1091 *val
&= 0xbfff; /* release DB6 */
1094 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
1095 if ((inw(tmport
) & 0x4000) != 0) { /* DB6 all release? */
1103 static void tscam(struct Scsi_Host
*host
)
1106 unsigned int tmport
;
1107 unsigned char i
, j
, k
;
1109 unsigned short int m
, assignid_map
, val
;
1110 unsigned char mbuf
[33], quintet
[2];
1111 struct atp_unit
*dev
= (struct atp_unit
*)&host
->hostdata
;
1112 static unsigned char g2q_tab
[8] = {
1113 0x38, 0x31, 0x32, 0x2b, 0x34, 0x2d, 0x2e, 0x27
1116 /* I can't believe we need this before we've even done anything. Remove it
1117 * and see if anyone bitches.
1118 for (i = 0; i < 0x10; i++) {
1123 tmport
= dev
->ioport
[0] + 1;
1124 outb(0x08, tmport
++);
1126 tmport
= dev
->ioport
[0] + 0x11;
1129 if ((dev
->scam_on
& 0x40) == 0) {
1133 m
<<= dev
->host_id
[0];
1135 if (dev
->chip_ver
< 4) {
1140 tmport
= dev
->ioport
[0] + 0x02;
1141 outb(0x02, tmport
++); /* 2*2=4ms,3EH 2/32*3E=3.9ms */
1149 for (i
= 0; i
< j
; i
++) {
1152 if ((m
& assignid_map
) != 0) {
1155 tmport
= dev
->ioport
[0] + 0x0f;
1162 k
= (i
& 0x07) | 0x40;
1167 tmport
= dev
->ioport
[0] + 0x1b;
1168 if (dev
->chip_ver
== 4) {
1174 tmport
= dev
->ioport
[0] + 0x18;
1178 while ((inb(tmport
) & 0x80) == 0x00)
1183 if ((k
== 0x85) || (k
== 0x42)) {
1186 tmport
= dev
->ioport
[0] + 0x10;
1193 tmport
= dev
->ioport
[0] + 0x02;
1195 tmport
= dev
->ioport
[0] + 0x1b;
1200 val
= 0x0080; /* bsy */
1201 tmport
= dev
->ioport
[0] + 0x1c;
1203 val
|= 0x0040; /* sel */
1205 val
|= 0x0004; /* msg */
1207 inb(0x80); /* 2 deskew delay(45ns*2=90ns) */
1208 val
&= 0x007f; /* no bsy */
1211 val
&= 0x00fb; /* after 1ms no msg */
1214 if ((inb(tmport
) & 0x04) != 0) {
1219 for (n
= 0; n
< 0x30000; n
++) {
1220 if ((inb(tmport
) & 0x80) != 0) { /* bsy ? */
1226 for (n
= 0; n
< 0x30000; n
++) {
1227 if ((inb(tmport
) & 0x81) == 0x0081) {
1234 val
|= 0x8003; /* io,cd,db7 */
1237 val
&= 0x00bf; /* no sel */
1242 if ((inb(tmport
) & 0x80) == 0x00) { /* bsy ? */
1245 tmport
= dev
->ioport
[0] + 0x15;
1250 while ((inb(tmport
) & 0x80) == 0)
1256 val
&= 0x00ff; /* synchronization */
1258 fun_scam(dev
, &val
);
1260 val
&= 0x00ff; /* isolation */
1262 fun_scam(dev
, &val
);
1267 if ((inw(tmport
) & 0x2000) == 0) {
1271 val
&= 0x00ff; /* get ID_STRING */
1273 k
= fun_scam(dev
, &val
);
1274 if ((k
& 0x03) == 0) {
1279 if ((k
& 0x02) != 0) {
1290 TCM_5
: /* isolation complete.. */
1292 printk(" \n%x %x %x %s\n ",assignid_map,mbuf[0],mbuf[1],&mbuf[2]); */
1295 if ((j
& 0x20) != 0) { /* bit5=1:ID upto 7 */
1298 if ((j
& 0x06) == 0) { /* IDvalid? */
1305 if ((m
& assignid_map
) == 0) {
1312 G2Q5
: /* srch from max acceptable ID# */
1313 k
= i
; /* max acceptable ID# */
1317 if ((m
& assignid_map
) == 0) {
1324 G2Q_QUIN
: /* k=binID#, */
1327 quintet
[0] = 0x38; /* 1st dft ID<8 */
1329 quintet
[0] = 0x31; /* 1st ID>=8 */
1332 quintet
[1] = g2q_tab
[k
];
1334 val
&= 0x00ff; /* AssignID 1stQuintet,AH=001xxxxx */
1335 m
= quintet
[0] << 8;
1337 fun_scam(dev
, &val
);
1338 val
&= 0x00ff; /* AssignID 2ndQuintet,AH=001xxxxx */
1339 m
= quintet
[1] << 8;
1341 fun_scam(dev
, &val
);
1347 static void is870(struct atp_unit
*dev
, unsigned int wkport
)
1349 unsigned int tmport
;
1350 unsigned char i
, j
, k
, rmb
, n
;
1351 unsigned short int m
;
1352 static unsigned char mbuf
[512];
1353 static unsigned char satn
[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
1354 static unsigned char inqd
[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
1355 static unsigned char synn
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1356 static unsigned char synu
[6] = { 0x80, 1, 3, 1, 0x0c, 0x0e };
1357 static unsigned char synw
[6] = { 0x80, 1, 3, 1, 0x0c, 0x07 };
1358 static unsigned char wide
[6] = { 0x80, 1, 2, 3, 1, 0 };
1360 tmport
= wkport
+ 0x3a;
1361 outb((unsigned char) (inb(tmport
) | 0x10), tmport
);
1363 for (i
= 0; i
< 16; i
++) {
1364 if ((dev
->chip_ver
!= 4) && (i
> 7)) {
1369 if ((m
& dev
->active_id
[0]) != 0) {
1372 if (i
== dev
->host_id
[0]) {
1373 printk(KERN_INFO
" ID: %2d Host Adapter\n", dev
->host_id
[0]);
1376 tmport
= wkport
+ 0x1b;
1377 if (dev
->chip_ver
== 4) {
1382 tmport
= wkport
+ 1;
1383 outb(0x08, tmport
++);
1384 outb(0x7f, tmport
++);
1385 outb(satn
[0], tmport
++);
1386 outb(satn
[1], tmport
++);
1387 outb(satn
[2], tmport
++);
1388 outb(satn
[3], tmport
++);
1389 outb(satn
[4], tmport
++);
1390 outb(satn
[5], tmport
++);
1394 outb(dev
->id
[0][i
].devsp
, tmport
++);
1396 outb(satn
[6], tmport
++);
1397 outb(satn
[7], tmport
++);
1399 if ((j
& 0x08) != 0) {
1400 j
= (j
& 0x07) | 0x40;
1404 outb(satn
[8], tmport
);
1407 while ((inb(tmport
) & 0x80) == 0x00)
1411 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1414 while (inb(tmport
) != 0x8e)
1417 dev
->active_id
[0] |= m
;
1419 tmport
= wkport
+ 0x10;
1421 tmport
= wkport
+ 0x04;
1425 tmport
= wkport
+ 0x18;
1428 while ((inb(tmport
) & 0x80) == 0x00)
1433 tmport
= wkport
+ 0x10;
1438 tmport
= wkport
+ 3;
1439 outb(inqd
[0], tmport
++);
1440 outb(inqd
[1], tmport
++);
1441 outb(inqd
[2], tmport
++);
1442 outb(inqd
[3], tmport
++);
1443 outb(inqd
[4], tmport
++);
1444 outb(inqd
[5], tmport
);
1448 outb(dev
->id
[0][i
].devsp
, tmport
++);
1450 outb(inqd
[6], tmport
++);
1451 outb(inqd
[7], tmport
++);
1453 outb(inqd
[8], tmport
);
1456 while ((inb(tmport
) & 0x80) == 0x00)
1460 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1463 while (inb(tmport
) != 0x8e)
1466 tmport
= wkport
+ 0x1b;
1467 if (dev
->chip_ver
== 4)
1470 tmport
= wkport
+ 0x18;
1476 if ((k
& 0x01) != 0) {
1478 mbuf
[j
++] = inb(tmport
);
1482 if ((k
& 0x80) == 0) {
1490 tmport
= wkport
+ 0x10;
1500 while ((inb(tmport
) & 0x80) == 0x00)
1504 if (inb(tmport
) != 0x16) {
1509 printk(KERN_INFO
" ID: %2d %s\n", i
, &mbuf
[8]);
1510 dev
->id
[0][i
].devtype
= mbuf
[0];
1513 if (dev
->chip_ver
!= 4) {
1516 if ((mbuf
[7] & 0x60) == 0) {
1519 if ((dev
->global_map
[0] & 0x20) == 0) {
1522 tmport
= wkport
+ 0x1b;
1524 tmport
= wkport
+ 3;
1525 outb(satn
[0], tmport
++);
1526 outb(satn
[1], tmport
++);
1527 outb(satn
[2], tmport
++);
1528 outb(satn
[3], tmport
++);
1529 outb(satn
[4], tmport
++);
1530 outb(satn
[5], tmport
++);
1534 outb(dev
->id
[0][i
].devsp
, tmport
++);
1536 outb(satn
[6], tmport
++);
1537 outb(satn
[7], tmport
++);
1539 outb(satn
[8], tmport
);
1542 while ((inb(tmport
) & 0x80) == 0x00)
1546 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1549 while (inb(tmport
) != 0x8e)
1554 tmport
= wkport
+ 0x14;
1560 while ((inb(tmport
) & 0x80) == 0) {
1561 if ((inb(tmport
) & 0x01) != 0) {
1563 outb(wide
[j
++], tmport
);
1569 while ((inb(tmport
) & 0x80) == 0x00)
1572 j
= inb(tmport
) & 0x0f;
1584 tmport
= wkport
+ 0x18;
1587 while ((inb(tmport
) & 0x80) == 0) {
1588 if ((inb(tmport
) & 0x01) != 0) {
1595 j
= inb(tmport
) & 0x0f;
1607 tmport
= wkport
+ 0x14;
1615 if ((j
& 0x01) != 0) {
1617 mbuf
[k
++] = inb(tmport
);
1621 if ((j
& 0x80) == 0x00) {
1625 j
= inb(tmport
) & 0x0f;
1637 tmport
= wkport
+ 0x10;
1639 tmport
= wkport
+ 0x14;
1645 while ((inb(tmport
) & 0x80) == 0x00)
1656 if (mbuf
[0] != 0x01) {
1659 if (mbuf
[1] != 0x02) {
1662 if (mbuf
[2] != 0x03) {
1665 if (mbuf
[3] != 0x01) {
1670 dev
->wide_id
[0] |= m
;
1672 if ((dev
->id
[0][i
].devtype
== 0x00) || (dev
->id
[0][i
].devtype
== 0x07) || ((dev
->id
[0][i
].devtype
== 0x05) && ((n
& 0x10) != 0))) {
1677 tmport
= wkport
+ 0x1b;
1679 if ((m
& dev
->wide_id
[0]) != 0) {
1683 tmport
= wkport
+ 3;
1684 outb(satn
[0], tmport
++);
1685 outb(satn
[1], tmport
++);
1686 outb(satn
[2], tmport
++);
1687 outb(satn
[3], tmport
++);
1688 outb(satn
[4], tmport
++);
1689 outb(satn
[5], tmport
++);
1693 outb(dev
->id
[0][i
].devsp
, tmport
++);
1695 outb(satn
[6], tmport
++);
1696 outb(satn
[7], tmport
++);
1698 outb(satn
[8], tmport
);
1701 while ((inb(tmport
) & 0x80) == 0x00)
1705 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1708 while (inb(tmport
) != 0x8e)
1713 tmport
= wkport
+ 0x14;
1719 while ((inb(tmport
) & 0x80) == 0) {
1720 if ((inb(tmport
) & 0x01) != 0) {
1722 if ((m
& dev
->wide_id
[0]) != 0) {
1723 outb(synw
[j
++], tmport
);
1725 if ((m
& dev
->ultra_map
[0]) != 0) {
1726 outb(synu
[j
++], tmport
);
1728 outb(synn
[j
++], tmport
);
1736 while ((inb(tmport
) & 0x80) == 0x00)
1739 j
= inb(tmport
) & 0x0f;
1751 tmport
= wkport
+ 0x18;
1754 while ((inb(tmport
) & 0x80) == 0x00) {
1755 if ((inb(tmport
) & 0x01) != 0x00) {
1778 tmport
= wkport
+ 0x14;
1786 if ((j
& 0x01) != 0x00) {
1788 mbuf
[k
++] = inb(tmport
);
1792 if ((j
& 0x80) == 0x00) {
1797 while ((inb(tmport
) & 0x80) == 0x00)
1816 tmport
= wkport
+ 0x10;
1819 tmport
= wkport
+ 0x14;
1825 while ((inb(tmport
) & 0x80) == 0x00)
1833 if (mbuf
[0] != 0x01) {
1836 if (mbuf
[1] != 0x03) {
1839 if (mbuf
[4] == 0x00) {
1842 if (mbuf
[3] > 0x64) {
1845 if (mbuf
[4] > 0x0c) {
1848 dev
->id
[0][i
].devsp
= mbuf
[4];
1849 if ((mbuf
[3] < 0x0d) && (rmb
== 0)) {
1853 if (mbuf
[3] < 0x1a) {
1857 if (mbuf
[3] < 0x33) {
1861 if (mbuf
[3] < 0x4c) {
1867 dev
->id
[0][i
].devsp
= (dev
->id
[0][i
].devsp
& 0x0f) | j
;
1869 tmport
= wkport
+ 0x3a;
1870 outb((unsigned char) (inb(tmport
) & 0xef), tmport
);
1873 static void is880(struct atp_unit
*dev
, unsigned int wkport
)
1875 unsigned int tmport
;
1876 unsigned char i
, j
, k
, rmb
, n
, lvdmode
;
1877 unsigned short int m
;
1878 static unsigned char mbuf
[512];
1879 static unsigned char satn
[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
1880 static unsigned char inqd
[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
1881 static unsigned char synn
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1882 unsigned char synu
[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
1883 static unsigned char synw
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1884 unsigned char synuw
[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
1885 static unsigned char wide
[6] = { 0x80, 1, 2, 3, 1, 0 };
1886 static unsigned char u3
[9] = { 0x80, 1, 6, 4, 0x09, 00, 0x0e, 0x01, 0x02 };
1888 lvdmode
= inb(wkport
+ 0x3f) & 0x40;
1890 for (i
= 0; i
< 16; i
++) {
1893 if ((m
& dev
->active_id
[0]) != 0) {
1896 if (i
== dev
->host_id
[0]) {
1897 printk(KERN_INFO
" ID: %2d Host Adapter\n", dev
->host_id
[0]);
1900 tmport
= wkport
+ 0x5b;
1902 tmport
= wkport
+ 0x41;
1903 outb(0x08, tmport
++);
1904 outb(0x7f, tmport
++);
1905 outb(satn
[0], tmport
++);
1906 outb(satn
[1], tmport
++);
1907 outb(satn
[2], tmport
++);
1908 outb(satn
[3], tmport
++);
1909 outb(satn
[4], tmport
++);
1910 outb(satn
[5], tmport
++);
1914 outb(dev
->id
[0][i
].devsp
, tmport
++);
1916 outb(satn
[6], tmport
++);
1917 outb(satn
[7], tmport
++);
1919 if ((j
& 0x08) != 0) {
1920 j
= (j
& 0x07) | 0x40;
1924 outb(satn
[8], tmport
);
1927 while ((inb(tmport
) & 0x80) == 0x00)
1931 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1934 while (inb(tmport
) != 0x8e)
1937 dev
->active_id
[0] |= m
;
1939 tmport
= wkport
+ 0x50;
1941 tmport
= wkport
+ 0x54;
1945 tmport
= wkport
+ 0x58;
1949 while ((inb(tmport
) & 0x80) == 0x00)
1955 tmport
= wkport
+ 0x50;
1960 tmport
= wkport
+ 0x43;
1961 outb(inqd
[0], tmport
++);
1962 outb(inqd
[1], tmport
++);
1963 outb(inqd
[2], tmport
++);
1964 outb(inqd
[3], tmport
++);
1965 outb(inqd
[4], tmport
++);
1966 outb(inqd
[5], tmport
);
1970 outb(dev
->id
[0][i
].devsp
, tmport
++);
1972 outb(inqd
[6], tmport
++);
1973 outb(inqd
[7], tmport
++);
1975 outb(inqd
[8], tmport
);
1978 while ((inb(tmport
) & 0x80) == 0x00)
1982 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1985 while (inb(tmport
) != 0x8e)
1988 tmport
= wkport
+ 0x5b;
1990 tmport
= wkport
+ 0x58;
1996 if ((k
& 0x01) != 0) {
1998 mbuf
[j
++] = inb(tmport
);
2002 if ((k
& 0x80) == 0) {
2010 tmport
= wkport
+ 0x50;
2019 while ((inb(tmport
) & 0x80) == 0x00)
2023 if (inb(tmport
) != 0x16)
2028 printk(KERN_INFO
" ID: %2d %s\n", i
, &mbuf
[8]);
2029 dev
->id
[0][i
].devtype
= mbuf
[0];
2032 if ((mbuf
[7] & 0x60) == 0) {
2035 if ((i
< 8) && ((dev
->global_map
[0] & 0x20) == 0)) {
2041 if (dev
->sp
[0][i
] != 0x04) // force u2
2046 tmport
= wkport
+ 0x5b;
2048 tmport
= wkport
+ 0x43;
2049 outb(satn
[0], tmport
++);
2050 outb(satn
[1], tmport
++);
2051 outb(satn
[2], tmport
++);
2052 outb(satn
[3], tmport
++);
2053 outb(satn
[4], tmport
++);
2054 outb(satn
[5], tmport
++);
2058 outb(dev
->id
[0][i
].devsp
, tmport
++);
2060 outb(satn
[6], tmport
++);
2061 outb(satn
[7], tmport
++);
2063 outb(satn
[8], tmport
);
2066 while ((inb(tmport
) & 0x80) == 0x00)
2071 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
2074 while (inb(tmport
) != 0x8e)
2079 tmport
= wkport
+ 0x54;
2085 while ((inb(tmport
) & 0x80) == 0) {
2086 if ((inb(tmport
) & 0x01) != 0) {
2088 outb(u3
[j
++], tmport
);
2094 while ((inb(tmport
) & 0x80) == 0x00)
2097 j
= inb(tmport
) & 0x0f;
2109 tmport
= wkport
+ 0x58;
2112 while ((inb(tmport
) & 0x80) == 0) {
2113 if ((inb(tmport
) & 0x01) != 0) {
2120 j
= inb(tmport
) & 0x0f;
2132 tmport
= wkport
+ 0x54;
2140 if ((j
& 0x01) != 0) {
2142 mbuf
[k
++] = inb(tmport
);
2146 if ((j
& 0x80) == 0x00) {
2150 j
= inb(tmport
) & 0x0f;
2162 tmport
= wkport
+ 0x50;
2164 tmport
= wkport
+ 0x54;
2170 while ((inb(tmport
) & 0x80) == 0x00)
2181 if (mbuf
[0] != 0x01) {
2184 if (mbuf
[1] != 0x06) {
2187 if (mbuf
[2] != 0x04) {
2190 if (mbuf
[3] == 0x09) {
2193 dev
->wide_id
[0] |= m
;
2194 dev
->id
[0][i
].devsp
= 0xce;
2198 tmport
= wkport
+ 0x5b;
2200 tmport
= wkport
+ 0x43;
2201 outb(satn
[0], tmport
++);
2202 outb(satn
[1], tmport
++);
2203 outb(satn
[2], tmport
++);
2204 outb(satn
[3], tmport
++);
2205 outb(satn
[4], tmport
++);
2206 outb(satn
[5], tmport
++);
2210 outb(dev
->id
[0][i
].devsp
, tmport
++);
2212 outb(satn
[6], tmport
++);
2213 outb(satn
[7], tmport
++);
2215 outb(satn
[8], tmport
);
2218 while ((inb(tmport
) & 0x80) == 0x00)
2222 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
2225 while (inb(tmport
) != 0x8e)
2230 tmport
= wkport
+ 0x54;
2236 while ((inb(tmport
) & 0x80) == 0) {
2237 if ((inb(tmport
) & 0x01) != 0) {
2239 outb(wide
[j
++], tmport
);
2244 while ((inb(tmport
) & 0x80) == 0x00)
2247 j
= inb(tmport
) & 0x0f;
2259 tmport
= wkport
+ 0x58;
2262 while ((inb(tmport
) & 0x80) == 0) {
2263 if ((inb(tmport
) & 0x01) != 0) {
2270 j
= inb(tmport
) & 0x0f;
2282 tmport
= wkport
+ 0x54;
2290 if ((j
& 0x01) != 0) {
2292 mbuf
[k
++] = inb(tmport
);
2296 if ((j
& 0x80) == 0x00) {
2300 j
= inb(tmport
) & 0x0f;
2312 tmport
= wkport
+ 0x50;
2314 tmport
= wkport
+ 0x54;
2320 while ((inb(tmport
) & 0x80) == 0x00)
2331 if (mbuf
[0] != 0x01) {
2334 if (mbuf
[1] != 0x02) {
2337 if (mbuf
[2] != 0x03) {
2340 if (mbuf
[3] != 0x01) {
2345 dev
->wide_id
[0] |= m
;
2347 if ((dev
->id
[0][i
].devtype
== 0x00) || (dev
->id
[0][i
].devtype
== 0x07) || ((dev
->id
[0][i
].devtype
== 0x05) && ((n
& 0x10) != 0))) {
2350 if ((dev
->async
[0] & m
) != 0) {
2356 if (dev
->sp
[0][i
] == 0x02) {
2360 if (dev
->sp
[0][i
] >= 0x03) {
2365 tmport
= wkport
+ 0x5b;
2367 if ((m
& dev
->wide_id
[0]) != 0) {
2371 tmport
= wkport
+ 0x43;
2372 outb(satn
[0], tmport
++);
2373 outb(satn
[1], tmport
++);
2374 outb(satn
[2], tmport
++);
2375 outb(satn
[3], tmport
++);
2376 outb(satn
[4], tmport
++);
2377 outb(satn
[5], tmport
++);
2381 outb(dev
->id
[0][i
].devsp
, tmport
++);
2383 outb(satn
[6], tmport
++);
2384 outb(satn
[7], tmport
++);
2386 outb(satn
[8], tmport
);
2389 while ((inb(tmport
) & 0x80) == 0x00)
2393 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
2396 while (inb(tmport
) != 0x8e)
2401 tmport
= wkport
+ 0x54;
2407 while ((inb(tmport
) & 0x80) == 0) {
2408 if ((inb(tmport
) & 0x01) != 0) {
2410 if ((m
& dev
->wide_id
[0]) != 0) {
2411 if ((m
& dev
->ultra_map
[0]) != 0) {
2412 outb(synuw
[j
++], tmport
);
2414 outb(synw
[j
++], tmport
);
2417 if ((m
& dev
->ultra_map
[0]) != 0) {
2418 outb(synu
[j
++], tmport
);
2420 outb(synn
[j
++], tmport
);
2428 while ((inb(tmport
) & 0x80) == 0x00)
2431 j
= inb(tmport
) & 0x0f;
2443 tmport
= wkport
+ 0x58;
2446 while ((inb(tmport
) & 0x80) == 0x00) {
2447 if ((inb(tmport
) & 0x01) != 0x00) {
2470 tmport
= wkport
+ 0x54;
2478 if ((j
& 0x01) != 0x00) {
2480 mbuf
[k
++] = inb(tmport
);
2484 if ((j
& 0x80) == 0x00) {
2489 while ((inb(tmport
) & 0x80) == 0x00)
2508 tmport
= wkport
+ 0x50;
2511 tmport
= wkport
+ 0x54;
2517 while ((inb(tmport
) & 0x80) == 0x00)
2525 if (mbuf
[0] != 0x01) {
2528 if (mbuf
[1] != 0x03) {
2531 if (mbuf
[4] == 0x00) {
2534 if (mbuf
[3] > 0x64) {
2537 if (mbuf
[4] > 0x0e) {
2540 dev
->id
[0][i
].devsp
= mbuf
[4];
2541 if (mbuf
[3] < 0x0c) {
2545 if ((mbuf
[3] < 0x0d) && (rmb
== 0)) {
2549 if (mbuf
[3] < 0x1a) {
2553 if (mbuf
[3] < 0x33) {
2557 if (mbuf
[3] < 0x4c) {
2563 dev
->id
[0][i
].devsp
= (dev
->id
[0][i
].devsp
& 0x0f) | j
;
2567 static void atp870u_free_tables(struct Scsi_Host
*host
)
2569 struct atp_unit
*atp_dev
= (struct atp_unit
*)&host
->hostdata
;
2571 for (j
=0; j
< 2; j
++) {
2572 for (k
= 0; k
< 16; k
++) {
2573 if (!atp_dev
->id
[j
][k
].prd_table
)
2575 pci_free_consistent(atp_dev
->pdev
, 1024, atp_dev
->id
[j
][k
].prd_table
, atp_dev
->id
[j
][k
].prd_bus
);
2576 atp_dev
->id
[j
][k
].prd_table
= NULL
;
2581 static int atp870u_init_tables(struct Scsi_Host
*host
)
2583 struct atp_unit
*atp_dev
= (struct atp_unit
*)&host
->hostdata
;
2585 for(c
=0;c
< 2;c
++) {
2587 atp_dev
->id
[c
][k
].prd_table
= pci_alloc_consistent(atp_dev
->pdev
, 1024, &(atp_dev
->id
[c
][k
].prd_bus
));
2588 if (!atp_dev
->id
[c
][k
].prd_table
) {
2589 printk("atp870u_init_tables fail\n");
2590 atp870u_free_tables(host
);
2593 atp_dev
->id
[c
][k
].prdaddr
= atp_dev
->id
[c
][k
].prd_bus
;
2594 atp_dev
->id
[c
][k
].devsp
=0x20;
2595 atp_dev
->id
[c
][k
].devtype
= 0x7f;
2596 atp_dev
->id
[c
][k
].curr_req
= NULL
;
2599 atp_dev
->active_id
[c
] = 0;
2600 atp_dev
->wide_id
[c
] = 0;
2601 atp_dev
->host_id
[c
] = 0x07;
2602 atp_dev
->quhd
[c
] = 0;
2603 atp_dev
->quend
[c
] = 0;
2604 atp_dev
->last_cmd
[c
] = 0xff;
2605 atp_dev
->in_snd
[c
] = 0;
2606 atp_dev
->in_int
[c
] = 0;
2608 for (k
= 0; k
< qcnt
; k
++) {
2609 atp_dev
->quereq
[c
][k
] = NULL
;
2611 for (k
= 0; k
< 16; k
++) {
2612 atp_dev
->id
[c
][k
].curr_req
= NULL
;
2613 atp_dev
->sp
[c
][k
] = 0x04;
2619 /* return non-zero on detection */
2620 static int atp870u_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
2622 unsigned char k
, m
, c
;
2623 unsigned long flags
;
2624 unsigned int base_io
, tmport
, error
,n
;
2625 unsigned char host_id
;
2626 struct Scsi_Host
*shpnt
= NULL
;
2627 struct atp_unit atp_dev
, *p
;
2628 unsigned char setupdata
[2][16];
2631 if (pci_enable_device(pdev
))
2634 if (!pci_set_dma_mask(pdev
, 0xFFFFFFFFUL
)) {
2635 printk(KERN_INFO
"atp870u: use 32bit DMA mask.\n");
2637 printk(KERN_ERR
"atp870u: DMA mask required but not available.\n");
2641 memset(&atp_dev
, 0, sizeof atp_dev
);
2643 * It's probably easier to weed out some revisions like
2644 * this than via the PCI device table
2646 if (ent
->device
== PCI_DEVICE_ID_ARTOP_AEC7610
) {
2647 error
= pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &atp_dev
.chip_ver
);
2648 if (atp_dev
.chip_ver
< 2)
2652 switch (ent
->device
) {
2653 case PCI_DEVICE_ID_ARTOP_AEC7612UW
:
2654 case PCI_DEVICE_ID_ARTOP_AEC7612SUW
:
2658 atp_dev
.chip_ver
= 0x04;
2662 base_io
= pci_resource_start(pdev
, 0);
2663 base_io
&= 0xfffffff8;
2665 if ((ent
->device
== ATP880_DEVID1
)||(ent
->device
== ATP880_DEVID2
)) {
2666 error
= pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &atp_dev
.chip_ver
);
2667 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, 0x80);//JCC082803
2669 host_id
= inb(base_io
+ 0x39);
2672 printk(KERN_INFO
" ACARD AEC-67160 PCI Ultra3 LVD Host Adapter: %d"
2673 " IO:%x, IRQ:%d.\n", count
, base_io
, pdev
->irq
);
2674 atp_dev
.ioport
[0] = base_io
+ 0x40;
2675 atp_dev
.pciport
[0] = base_io
+ 0x28;
2676 atp_dev
.dev_id
= ent
->device
;
2677 atp_dev
.host_id
[0] = host_id
;
2679 tmport
= base_io
+ 0x22;
2680 atp_dev
.scam_on
= inb(tmport
);
2682 atp_dev
.global_map
[0] = inb(tmport
);
2684 atp_dev
.ultra_map
[0] = inw(tmport
);
2692 outw(n
, base_io
+ 0x34);
2694 if (inb(base_io
+ 0x30) == 0xff)
2697 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x30);
2698 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x31);
2699 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x32);
2700 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x33);
2701 outw(n
, base_io
+ 0x34);
2703 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x30);
2704 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x31);
2705 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x32);
2706 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x33);
2707 outw(n
, base_io
+ 0x34);
2709 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x30);
2710 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x31);
2711 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x32);
2712 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x33);
2713 outw(n
, base_io
+ 0x34);
2715 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x30);
2716 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x31);
2717 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x32);
2718 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x33);
2722 outw(0, base_io
+ 0x34);
2723 atp_dev
.ultra_map
[0] = 0;
2724 atp_dev
.async
[0] = 0;
2725 for (k
= 0; k
< 16; k
++) {
2728 if (atp_dev
.sp
[0][k
] > 1) {
2729 atp_dev
.ultra_map
[0] |= n
;
2731 if (atp_dev
.sp
[0][k
] == 0)
2732 atp_dev
.async
[0] |= n
;
2735 atp_dev
.async
[0] = ~(atp_dev
.async
[0]);
2736 outb(atp_dev
.global_map
[0], base_io
+ 0x35);
2738 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
2742 p
= (struct atp_unit
*)&shpnt
->hostdata
;
2744 atp_dev
.host
= shpnt
;
2745 atp_dev
.pdev
= pdev
;
2746 pci_set_drvdata(pdev
, p
);
2747 memcpy(p
, &atp_dev
, sizeof atp_dev
);
2748 if (atp870u_init_tables(shpnt
) < 0) {
2749 printk(KERN_ERR
"Unable to allocate tables for Acard controller\n");
2753 if (request_irq(pdev
->irq
, atp870u_intr_handle
, SA_SHIRQ
, "atp880i", shpnt
)) {
2754 printk(KERN_ERR
"Unable to allocate IRQ%d for Acard controller.\n", pdev
->irq
);
2758 spin_lock_irqsave(shpnt
->host_lock
, flags
);
2759 tmport
= base_io
+ 0x38;
2760 k
= inb(tmport
) & 0x80;
2767 tmport
= base_io
+ 0x5b;
2771 tmport
= base_io
+ 0x40;
2772 outb((host_id
| 0x08), tmport
);
2776 while ((inb(tmport
) & 0x80) == 0)
2780 tmport
= base_io
+ 0x41;
2783 tmport
= base_io
+ 0x51;
2788 tmport
= base_io
+ 0x38;
2791 shpnt
->this_id
= host_id
;
2792 shpnt
->unique_id
= base_io
;
2793 shpnt
->io_port
= base_io
;
2794 shpnt
->n_io_port
= 0x60; /* Number of bytes of I/O space used */
2795 shpnt
->irq
= pdev
->irq
;
2796 } else if (ent
->device
== ATP885_DEVID
) {
2797 printk(KERN_INFO
" ACARD AEC-67162 PCI Ultra3 LVD Host Adapter: IO:%x, IRQ:%d.\n"
2798 , base_io
, pdev
->irq
);
2800 atp_dev
.pdev
= pdev
;
2801 atp_dev
.dev_id
= ent
->device
;
2802 atp_dev
.baseport
= base_io
;
2803 atp_dev
.ioport
[0] = base_io
+ 0x80;
2804 atp_dev
.ioport
[1] = base_io
+ 0xc0;
2805 atp_dev
.pciport
[0] = base_io
+ 0x40;
2806 atp_dev
.pciport
[1] = base_io
+ 0x50;
2808 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
2812 p
= (struct atp_unit
*)&shpnt
->hostdata
;
2814 atp_dev
.host
= shpnt
;
2815 atp_dev
.pdev
= pdev
;
2816 pci_set_drvdata(pdev
, p
);
2817 memcpy(p
, &atp_dev
, sizeof(struct atp_unit
));
2818 if (atp870u_init_tables(shpnt
) < 0)
2822 printk("request_irq() shpnt %p hostdata %p\n", shpnt
, p
);
2824 if (request_irq(pdev
->irq
, atp870u_intr_handle
, SA_SHIRQ
, "atp870u", shpnt
)) {
2825 printk(KERN_ERR
"Unable to allocate IRQ for Acard controller.\n");
2829 spin_lock_irqsave(shpnt
->host_lock
, flags
);
2831 c
=inb(base_io
+ 0x29);
2832 outb((c
| 0x04),base_io
+ 0x29);
2839 outw(n
,base_io
+ 0x3c);
2840 if (inl(base_io
+ 0x38) == 0xffffffff) {
2843 for (m
=0; m
< 2; m
++) {
2844 p
->global_map
[m
]= 0;
2845 for (k
=0; k
< 4; k
++) {
2846 outw(n
++,base_io
+ 0x3c);
2847 ((unsigned long *)&setupdata
[m
][0])[k
]=inl(base_io
+ 0x38);
2849 for (k
=0; k
< 4; k
++) {
2850 outw(n
++,base_io
+ 0x3c);
2851 ((unsigned long *)&p
->sp
[m
][0])[k
]=inl(base_io
+ 0x38);
2858 printk( "Flash Read OK\n");
2860 c
=inb(base_io
+ 0x29);
2861 outb((c
& 0xfb),base_io
+ 0x29);
2862 for (c
=0;c
< 2;c
++) {
2865 for (k
=0; k
< 16; k
++) {
2868 if (p
->sp
[c
][k
] > 1) {
2869 p
->ultra_map
[c
] |= n
;
2871 if (p
->sp
[c
][k
] == 0) {
2876 p
->async
[c
] = ~(p
->async
[c
]);
2878 if (p
->global_map
[c
] == 0) {
2880 if ((k
& 0x40) != 0)
2881 p
->global_map
[c
] |= 0x20;
2883 p
->global_map
[c
] |= k
;
2884 if ((setupdata
[c
][2] & 0x04) != 0)
2885 p
->global_map
[c
] |= 0x08;
2886 p
->host_id
[c
] = setupdata
[c
][0] & 0x07;
2890 k
= inb(base_io
+ 0x28) & 0x8f;
2892 outb(k
, base_io
+ 0x28);
2893 outb(0x80, base_io
+ 0x41);
2894 outb(0x80, base_io
+ 0x51);
2896 outb(0, base_io
+ 0x41);
2897 outb(0, base_io
+ 0x51);
2899 inb(base_io
+ 0x9b);
2900 inb(base_io
+ 0x97);
2901 inb(base_io
+ 0xdb);
2902 inb(base_io
+ 0xd7);
2903 tmport
= base_io
+ 0x80;
2906 k
= (k
& 0x07) | 0x40;
2913 while ((inb(tmport
) & 0x80) == 0)
2918 tmport
= base_io
+ 0x81;
2921 tmport
= base_io
+ 0x91;
2924 tmport
= base_io
+ 0xc0;
2927 k
= (k
& 0x07) | 0x40;
2934 while ((inb(tmport
) & 0x80) == 0)
2939 tmport
= base_io
+ 0xc1;
2942 tmport
= base_io
+ 0xd1;
2946 printk(KERN_INFO
" Scanning Channel A SCSI Device ...\n");
2947 is885(p
, base_io
+ 0x80, 0);
2948 printk(KERN_INFO
" Scanning Channel B SCSI Device ...\n");
2949 is885(p
, base_io
+ 0xc0, 1);
2951 k
= inb(base_io
+ 0x28) & 0xcf;
2953 outb(k
, base_io
+ 0x28);
2954 k
= inb(base_io
+ 0x1f) | 0x80;
2955 outb(k
, base_io
+ 0x1f);
2956 k
= inb(base_io
+ 0x29) | 0x01;
2957 outb(k
, base_io
+ 0x29);
2959 //printk("atp885: atp_host[0] 0x%p\n", atp_host[0]);
2962 shpnt
->max_lun
= (p
->global_map
[0] & 0x07) + 1;
2963 shpnt
->max_channel
= 1;
2964 shpnt
->this_id
= p
->host_id
[0];
2965 shpnt
->unique_id
= base_io
;
2966 shpnt
->io_port
= base_io
;
2967 shpnt
->n_io_port
= 0xff; /* Number of bytes of I/O space used */
2968 shpnt
->irq
= pdev
->irq
;
2971 error
= pci_read_config_byte(pdev
, 0x49, &host_id
);
2973 printk(KERN_INFO
" ACARD AEC-671X PCI Ultra/W SCSI-2/3 Host Adapter: %d "
2974 "IO:%x, IRQ:%d.\n", count
, base_io
, pdev
->irq
);
2976 atp_dev
.ioport
[0] = base_io
;
2977 atp_dev
.pciport
[0] = base_io
+ 0x20;
2978 atp_dev
.dev_id
= ent
->device
;
2980 atp_dev
.host_id
[0] = host_id
;
2981 tmport
= base_io
+ 0x22;
2982 atp_dev
.scam_on
= inb(tmport
);
2984 atp_dev
.global_map
[0] = inb(tmport
++);
2985 atp_dev
.ultra_map
[0] = inw(tmport
);
2987 if (atp_dev
.ultra_map
[0] == 0) {
2988 atp_dev
.scam_on
= 0x00;
2989 atp_dev
.global_map
[0] = 0x20;
2990 atp_dev
.ultra_map
[0] = 0xffff;
2993 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
2997 p
= (struct atp_unit
*)&shpnt
->hostdata
;
2999 atp_dev
.host
= shpnt
;
3000 atp_dev
.pdev
= pdev
;
3001 pci_set_drvdata(pdev
, p
);
3002 memcpy(p
, &atp_dev
, sizeof atp_dev
);
3003 if (atp870u_init_tables(shpnt
) < 0)
3006 if (request_irq(pdev
->irq
, atp870u_intr_handle
, SA_SHIRQ
, "atp870i", shpnt
)) {
3007 printk(KERN_ERR
"Unable to allocate IRQ%d for Acard controller.\n", pdev
->irq
);
3011 spin_lock_irqsave(shpnt
->host_lock
, flags
);
3012 if (atp_dev
.chip_ver
> 0x07) { /* check if atp876 chip then enable terminator */
3013 tmport
= base_io
+ 0x3e;
3017 tmport
= base_io
+ 0x3a;
3018 k
= (inb(tmport
) & 0xf3) | 0x10;
3020 outb((k
& 0xdf), tmport
);
3025 outb((host_id
| 0x08), tmport
);
3029 while ((inb(tmport
) & 0x80) == 0)
3034 tmport
= base_io
+ 1;
3037 tmport
= base_io
+ 0x11;
3042 tmport
= base_io
+ 0x3a;
3043 outb((inb(tmport
) & 0xef), tmport
);
3045 outb((inb(tmport
) | 0x20), tmport
);
3046 if (atp_dev
.chip_ver
== 4)
3050 shpnt
->this_id
= host_id
;
3051 shpnt
->unique_id
= base_io
;
3052 shpnt
->io_port
= base_io
;
3053 shpnt
->n_io_port
= 0x40; /* Number of bytes of I/O space used */
3054 shpnt
->irq
= pdev
->irq
;
3056 spin_unlock_irqrestore(shpnt
->host_lock
, flags
);
3057 if(ent
->device
==ATP885_DEVID
) {
3058 if(!request_region(base_io
, 0xff, "atp870u")) /* Register the IO ports that we use */
3059 goto request_io_fail
;
3060 } else if((ent
->device
==ATP880_DEVID1
)||(ent
->device
==ATP880_DEVID2
)) {
3061 if(!request_region(base_io
, 0x60, "atp870u")) /* Register the IO ports that we use */
3062 goto request_io_fail
;
3064 if(!request_region(base_io
, 0x40, "atp870u")) /* Register the IO ports that we use */
3065 goto request_io_fail
;
3068 if (scsi_add_host(shpnt
, &pdev
->dev
))
3070 scsi_scan_host(shpnt
);
3072 printk("atp870u_prob : exit\n");
3077 printk("atp870u_prob:scsi_add_fail\n");
3078 if(ent
->device
==ATP885_DEVID
) {
3079 release_region(base_io
, 0xff);
3080 } else if((ent
->device
==ATP880_DEVID1
)||(ent
->device
==ATP880_DEVID2
)) {
3081 release_region(base_io
, 0x60);
3083 release_region(base_io
, 0x40);
3086 printk("atp870u_prob:request_io_fail\n");
3087 free_irq(pdev
->irq
, shpnt
);
3089 printk("atp870u_prob:free_table\n");
3090 atp870u_free_tables(shpnt
);
3092 printk("atp870u_prob:unregister\n");
3093 scsi_host_put(shpnt
);
3097 /* The abort command does not leave the device in a clean state where
3098 it is available to be used again. Until this gets worked out, we will
3099 leave it commented out. */
3101 static int atp870u_abort(struct scsi_cmnd
* SCpnt
)
3103 unsigned char j
, k
, c
;
3104 struct scsi_cmnd
*workrequ
;
3105 unsigned int tmport
;
3106 struct atp_unit
*dev
;
3107 struct Scsi_Host
*host
;
3108 host
= SCpnt
->device
->host
;
3110 dev
= (struct atp_unit
*)&host
->hostdata
;
3111 c
= scmd_channel(SCpnt
);
3112 printk(" atp870u: abort Channel = %x \n", c
);
3113 printk("working=%x last_cmd=%x ", dev
->working
[c
], dev
->last_cmd
[c
]);
3114 printk(" quhdu=%x quendu=%x ", dev
->quhd
[c
], dev
->quend
[c
]);
3115 tmport
= dev
->ioport
[c
];
3116 for (j
= 0; j
< 0x18; j
++) {
3117 printk(" r%2x=%2x", j
, inb(tmport
++));
3120 printk(" r1c=%2x", inb(tmport
));
3122 printk(" r1f=%2x in_snd=%2x ", inb(tmport
), dev
->in_snd
[c
]);
3123 tmport
= dev
->pciport
[c
];
3124 printk(" d00=%2x", inb(tmport
));
3126 printk(" d02=%2x", inb(tmport
));
3128 if (dev
->id
[c
][j
].curr_req
!= NULL
) {
3129 workrequ
= dev
->id
[c
][j
].curr_req
;
3130 printk("\n que cdb= ");
3131 for (k
=0; k
< workrequ
->cmd_len
; k
++) {
3132 printk(" %2x ",workrequ
->cmnd
[k
]);
3134 printk(" last_lenu= %x ",(unsigned int)dev
->id
[c
][j
].last_len
);
3140 static const char *atp870u_info(struct Scsi_Host
*notused
)
3142 static char buffer
[128];
3144 strcpy(buffer
, "ACARD AEC-6710/6712/67160 PCI Ultra/W/LVD SCSI-3 Adapter Driver V2.6+ac ");
3149 #define BLS buffer + len + size
3150 static int atp870u_proc_info(struct Scsi_Host
*HBAptr
, char *buffer
,
3151 char **start
, off_t offset
, int length
, int inout
)
3153 static u8 buff
[512];
3162 memset(buff
, 0, sizeof(buff
));
3163 size
+= sprintf(BLS
, "ACARD AEC-671X Driver Version: 2.6+ac\n");
3168 size
+= sprintf(BLS
, "\n");
3169 size
+= sprintf(BLS
, "Adapter Configuration:\n");
3170 size
+= sprintf(BLS
, " Base IO: %#.4lx\n", HBAptr
->io_port
);
3171 size
+= sprintf(BLS
, " IRQ: %d\n", HBAptr
->irq
);
3175 *start
= buffer
+ (offset
- begin
); /* Start of wanted data */
3176 len
-= (offset
- begin
); /* Start slop */
3178 len
= length
; /* Ending slop */
3184 static int atp870u_biosparam(struct scsi_device
*disk
, struct block_device
*dev
,
3185 sector_t capacity
, int *ip
)
3187 int heads
, sectors
, cylinders
;
3191 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
3192 if (cylinders
> 1024) {
3195 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
3204 static void atp870u_remove (struct pci_dev
*pdev
)
3206 struct atp_unit
*devext
= pci_get_drvdata(pdev
);
3207 struct Scsi_Host
*pshost
= devext
->host
;
3210 scsi_remove_host(pshost
);
3211 printk(KERN_INFO
"free_irq : %d\n",pshost
->irq
);
3212 free_irq(pshost
->irq
, pshost
);
3213 release_region(pshost
->io_port
, pshost
->n_io_port
);
3214 printk(KERN_INFO
"atp870u_free_tables : %p\n",pshost
);
3215 atp870u_free_tables(pshost
);
3216 printk(KERN_INFO
"scsi_host_put : %p\n",pshost
);
3217 scsi_host_put(pshost
);
3218 printk(KERN_INFO
"pci_set_drvdata : %p\n",pdev
);
3219 pci_set_drvdata(pdev
, NULL
);
3221 MODULE_LICENSE("GPL");
3223 static struct scsi_host_template atp870u_template
= {
3224 .module
= THIS_MODULE
,
3225 .name
= "atp870u" /* name */,
3226 .proc_name
= "atp870u",
3227 .proc_info
= atp870u_proc_info
,
3228 .info
= atp870u_info
/* info */,
3229 .queuecommand
= atp870u_queuecommand
/* queuecommand */,
3230 .eh_abort_handler
= atp870u_abort
/* abort */,
3231 .bios_param
= atp870u_biosparam
/* biosparm */,
3232 .can_queue
= qcnt
/* can_queue */,
3233 .this_id
= 7 /* SCSI ID */,
3234 .sg_tablesize
= ATP870U_SCATTER
/*SG_ALL*/ /*SG_NONE*/,
3235 .cmd_per_lun
= ATP870U_CMDLUN
/* commands per lun */,
3236 .use_clustering
= ENABLE_CLUSTERING
,
3237 .max_sectors
= ATP870U_MAX_SECTORS
,
3240 static struct pci_device_id atp870u_id_table
[] = {
3241 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP885_DEVID
) },
3242 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP880_DEVID1
) },
3243 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP880_DEVID2
) },
3244 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7610
) },
3245 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612UW
) },
3246 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612U
) },
3247 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612S
) },
3248 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612D
) },
3249 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612SUW
) },
3250 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_8060
) },
3254 MODULE_DEVICE_TABLE(pci
, atp870u_id_table
);
3256 static struct pci_driver atp870u_driver
= {
3257 .id_table
= atp870u_id_table
,
3259 .probe
= atp870u_probe
,
3260 .remove
= __devexit_p(atp870u_remove
),
3263 static int __init
atp870u_init(void)
3266 printk("atp870u_init: Entry\n");
3268 return pci_register_driver(&atp870u_driver
);
3271 static void __exit
atp870u_exit(void)
3274 printk("atp870u_exit: Entry\n");
3276 pci_unregister_driver(&atp870u_driver
);
3279 static void tscam_885(void)
3283 for (i
= 0; i
< 0x2; i
++) {
3291 static void is885(struct atp_unit
*dev
, unsigned int wkport
,unsigned char c
)
3293 unsigned int tmport
;
3294 unsigned char i
, j
, k
, rmb
, n
, lvdmode
;
3295 unsigned short int m
;
3296 static unsigned char mbuf
[512];
3297 static unsigned char satn
[9] = {0, 0, 0, 0, 0, 0, 0, 6, 6};
3298 static unsigned char inqd
[9] = {0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6};
3299 static unsigned char synn
[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
3300 unsigned char synu
[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
3301 static unsigned char synw
[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
3302 unsigned char synuw
[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
3303 static unsigned char wide
[6] = {0x80, 1, 2, 3, 1, 0};
3304 static unsigned char u3
[9] = { 0x80,1,6,4,0x09,00,0x0e,0x01,0x02 };
3306 lvdmode
=inb(wkport
+ 0x1b) >> 7;
3308 for (i
= 0; i
< 16; i
++) {
3311 if ((m
& dev
->active_id
[c
]) != 0) {
3314 if (i
== dev
->host_id
[c
]) {
3315 printk(KERN_INFO
" ID: %2d Host Adapter\n", dev
->host_id
[c
]);
3318 tmport
= wkport
+ 0x1b;
3320 tmport
= wkport
+ 0x01;
3321 outb(0x08, tmport
++);
3322 outb(0x7f, tmport
++);
3323 outb(satn
[0], tmport
++);
3324 outb(satn
[1], tmport
++);
3325 outb(satn
[2], tmport
++);
3326 outb(satn
[3], tmport
++);
3327 outb(satn
[4], tmport
++);
3328 outb(satn
[5], tmport
++);
3332 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3335 outb(satn
[6], tmport
++);
3336 outb(satn
[7], tmport
++);
3338 if ((j
& 0x08) != 0) {
3339 j
= (j
& 0x07) | 0x40;
3343 outb(satn
[8], tmport
);
3346 while ((inb(tmport
) & 0x80) == 0x00)
3349 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3352 while (inb(tmport
) != 0x8e)
3354 dev
->active_id
[c
] |= m
;
3356 tmport
= wkport
+ 0x10;
3358 tmport
= wkport
+ 0x14;
3362 tmport
= wkport
+ 0x18;
3365 while ((inb(tmport
) & 0x80) == 0x00)
3370 tmport
= wkport
+ 0x10;
3375 tmport
= wkport
+ 0x03;
3376 outb(inqd
[0], tmport
++);
3377 outb(inqd
[1], tmport
++);
3378 outb(inqd
[2], tmport
++);
3379 outb(inqd
[3], tmport
++);
3380 outb(inqd
[4], tmport
++);
3381 outb(inqd
[5], tmport
);
3385 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3387 outb(inqd
[6], tmport
++);
3388 outb(inqd
[7], tmport
++);
3390 outb(inqd
[8], tmport
);
3392 while ((inb(tmport
) & 0x80) == 0x00)
3395 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3398 while (inb(tmport
) != 0x8e)
3400 tmport
= wkport
+ 0x1b;
3402 tmport
= wkport
+ 0x18;
3408 if ((k
& 0x01) != 0) {
3410 mbuf
[j
++] = inb(tmport
);
3414 if ((k
& 0x80) == 0) {
3422 tmport
= wkport
+ 0x10;
3431 while ((inb(tmport
) & 0x80) == 0x00)
3434 if (inb(tmport
) != 0x16) {
3439 printk( KERN_INFO
" ID: %2d %s\n", i
, &mbuf
[8]);
3440 dev
->id
[c
][i
].devtype
= mbuf
[0];
3443 if ((mbuf
[7] & 0x60) == 0) {
3446 if ((i
< 8) && ((dev
->global_map
[c
] & 0x20) == 0)) {
3452 if (dev
->sp
[c
][i
] != 0x04) { // force u2
3456 tmport
= wkport
+ 0x1b;
3458 tmport
= wkport
+ 0x03;
3459 outb(satn
[0], tmport
++);
3460 outb(satn
[1], tmport
++);
3461 outb(satn
[2], tmport
++);
3462 outb(satn
[3], tmport
++);
3463 outb(satn
[4], tmport
++);
3464 outb(satn
[5], tmport
++);
3468 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3470 outb(satn
[6], tmport
++);
3471 outb(satn
[7], tmport
++);
3473 outb(satn
[8], tmport
);
3476 while ((inb(tmport
) & 0x80) == 0x00)
3479 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3482 while (inb(tmport
) != 0x8e)
3486 tmport
= wkport
+ 0x14;
3492 while ((inb(tmport
) & 0x80) == 0) {
3493 if ((inb(tmport
) & 0x01) != 0) {
3495 outb(u3
[j
++], tmport
);
3501 while ((inb(tmport
) & 0x80) == 0x00)
3503 j
= inb(tmport
) & 0x0f;
3515 tmport
= wkport
+ 0x18;
3518 while ((inb(tmport
) & 0x80) == 0) {
3519 if ((inb(tmport
) & 0x01) != 0) {
3527 j
= inb(tmport
) & 0x0f;
3539 tmport
= wkport
+ 0x14;
3547 if ((j
& 0x01) != 0) {
3549 mbuf
[k
++] = inb(tmport
);
3553 if ((j
& 0x80) == 0x00) {
3557 j
= inb(tmport
) & 0x0f;
3569 tmport
= wkport
+ 0x10;
3571 tmport
= wkport
+ 0x14;
3576 while ((inb(tmport
) & 0x80) == 0x00);
3585 if (mbuf
[0] != 0x01) {
3588 if (mbuf
[1] != 0x06) {
3591 if (mbuf
[2] != 0x04) {
3594 if (mbuf
[3] == 0x09) {
3597 dev
->wide_id
[c
] |= m
;
3598 dev
->id
[c
][i
].devsp
= 0xce;
3600 printk("dev->id[%2d][%2d].devsp = %2x\n",c
,i
,dev
->id
[c
][i
].devsp
);
3605 tmport
= wkport
+ 0x1b;
3607 tmport
= wkport
+ 0x03;
3608 outb(satn
[0], tmport
++);
3609 outb(satn
[1], tmport
++);
3610 outb(satn
[2], tmport
++);
3611 outb(satn
[3], tmport
++);
3612 outb(satn
[4], tmport
++);
3613 outb(satn
[5], tmport
++);
3617 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3619 outb(satn
[6], tmport
++);
3620 outb(satn
[7], tmport
++);
3622 outb(satn
[8], tmport
);
3625 while ((inb(tmport
) & 0x80) == 0x00)
3628 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3631 while (inb(tmport
) != 0x8e)
3635 tmport
= wkport
+ 0x14;
3641 while ((inb(tmport
) & 0x80) == 0) {
3642 if ((inb(tmport
) & 0x01) != 0) {
3644 outb(wide
[j
++], tmport
);
3650 while ((inb(tmport
) & 0x80) == 0x00)
3652 j
= inb(tmport
) & 0x0f;
3664 tmport
= wkport
+ 0x18;
3667 while ((inb(tmport
) & 0x80) == 0) {
3668 if ((inb(tmport
) & 0x01) != 0) {
3676 j
= inb(tmport
) & 0x0f;
3688 tmport
= wkport
+ 0x14;
3696 if ((j
& 0x01) != 0) {
3698 mbuf
[k
++] = inb(tmport
);
3702 if ((j
& 0x80) == 0x00) {
3706 j
= inb(tmport
) & 0x0f;
3718 tmport
= wkport
+ 0x10;
3720 tmport
= wkport
+ 0x14;
3725 while ((inb(tmport
) & 0x80) == 0x00)
3735 if (mbuf
[0] != 0x01) {
3738 if (mbuf
[1] != 0x02) {
3741 if (mbuf
[2] != 0x03) {
3744 if (mbuf
[3] != 0x01) {
3749 dev
->wide_id
[c
] |= m
;
3751 if ((dev
->id
[c
][i
].devtype
== 0x00) || (dev
->id
[c
][i
].devtype
== 0x07) ||
3752 ((dev
->id
[c
][i
].devtype
== 0x05) && ((n
& 0x10) != 0))) {
3755 if ((dev
->async
[c
] & m
) != 0) {
3761 if (dev
->sp
[c
][i
] == 0x02) {
3765 if (dev
->sp
[c
][i
] >= 0x03) {
3770 tmport
= wkport
+ 0x1b;
3772 if ((m
& dev
->wide_id
[c
]) != 0) {
3776 tmport
= wkport
+ 0x03;
3777 outb(satn
[0], tmport
++);
3778 outb(satn
[1], tmport
++);
3779 outb(satn
[2], tmport
++);
3780 outb(satn
[3], tmport
++);
3781 outb(satn
[4], tmport
++);
3782 outb(satn
[5], tmport
++);
3786 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3788 outb(satn
[6], tmport
++);
3789 outb(satn
[7], tmport
++);
3791 outb(satn
[8], tmport
);
3794 while ((inb(tmport
) & 0x80) == 0x00)
3797 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3800 while (inb(tmport
) != 0x8e)
3804 tmport
= wkport
+ 0x14;
3810 while ((inb(tmport
) & 0x80) == 0) {
3811 if ((inb(tmport
) & 0x01) != 0) {
3813 if ((m
& dev
->wide_id
[c
]) != 0) {
3814 if ((m
& dev
->ultra_map
[c
]) != 0) {
3815 outb(synuw
[j
++], tmport
);
3817 outb(synw
[j
++], tmport
);
3820 if ((m
& dev
->ultra_map
[c
]) != 0) {
3821 outb(synu
[j
++], tmport
);
3823 outb(synn
[j
++], tmport
);
3830 while ((inb(tmport
) & 0x80) == 0x00)
3832 j
= inb(tmport
) & 0x0f;
3844 tmport
= wkport
+ 0x18;
3847 while ((inb(tmport
) & 0x80) == 0x00) {
3848 if ((inb(tmport
) & 0x01) != 0x00) {
3872 tmport
= wkport
+ 0x14;
3880 if ((j
& 0x01) != 0x00) {
3882 mbuf
[k
++] = inb(tmport
);
3886 if ((j
& 0x80) == 0x00) {
3890 while ((inb(tmport
) & 0x80) == 0x00);
3907 tmport
= wkport
+ 0x10;
3910 tmport
= wkport
+ 0x14;
3915 while ((inb(tmport
) & 0x80) == 0x00)
3922 if (mbuf
[0] != 0x01) {
3925 if (mbuf
[1] != 0x03) {
3928 if (mbuf
[4] == 0x00) {
3931 if (mbuf
[3] > 0x64) {
3934 if (mbuf
[4] > 0x0e) {
3937 dev
->id
[c
][i
].devsp
= mbuf
[4];
3938 if (mbuf
[3] < 0x0c){
3942 if ((mbuf
[3] < 0x0d) && (rmb
== 0)) {
3946 if (mbuf
[3] < 0x1a) {
3950 if (mbuf
[3] < 0x33) {
3954 if (mbuf
[3] < 0x4c) {
3960 dev
->id
[c
][i
].devsp
= (dev
->id
[c
][i
].devsp
& 0x0f) | j
;
3962 printk("dev->id[%2d][%2d].devsp = %2x\n",c
,i
,dev
->id
[c
][i
].devsp
);
3965 tmport
= wkport
+ 0x16;
3969 module_init(atp870u_init
);
3970 module_exit(atp870u_exit
);