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 <linux/dma-mapping.h>
32 #include <asm/system.h>
35 #include <scsi/scsi.h>
36 #include <scsi/scsi_cmnd.h>
37 #include <scsi/scsi_device.h>
38 #include <scsi/scsi_host.h>
42 static struct scsi_host_template atp870u_template
;
43 static void send_s870(struct atp_unit
*dev
,unsigned char c
);
44 static void is885(struct atp_unit
*dev
, unsigned int wkport
,unsigned char c
);
45 static void tscam_885(void);
47 static irqreturn_t
atp870u_intr_handle(int irq
, void *dev_id
)
50 unsigned short int tmpcip
, id
;
51 unsigned char i
, j
, c
, target_id
, lun
,cmdp
;
53 struct scsi_cmnd
*workreq
;
54 unsigned int workport
, tmport
, tmport1
;
55 unsigned long adrcnt
, k
;
60 struct Scsi_Host
*host
= dev_id
;
61 struct atp_unit
*dev
= (struct atp_unit
*)&host
->hostdata
;
63 for (c
= 0; c
< 2; c
++) {
64 tmport
= dev
->ioport
[c
] + 0x1f;
75 printk("atp870u_intr_handle enter\n");
78 cmdp
= inb(dev
->ioport
[c
] + 0x10);
79 workport
= dev
->ioport
[c
];
80 if (dev
->working
[c
] != 0) {
81 if (dev
->dev_id
== ATP885_DEVID
) {
82 tmport1
= workport
+ 0x16;
83 if ((inb(tmport1
) & 0x80) == 0)
84 outb((inb(tmport1
) | 0x80), tmport1
);
86 tmpcip
= dev
->pciport
[c
];
87 if ((inb(tmpcip
) & 0x08) != 0)
90 for (k
=0; k
< 1000; k
++) {
91 if ((inb(tmpcip
) & 0x08) == 0) {
94 if ((inb(tmpcip
) & 0x01) == 0) {
100 tmpcip
= dev
->pciport
[c
];
106 if (dev
->dev_id
== ATP885_DEVID
) {
113 target_id
= inb(tmport
);
117 * Remap wide devices onto id numbers
120 if ((target_id
& 0x40) != 0) {
121 target_id
= (target_id
& 0x07) | 0x08;
126 if ((j
& 0x40) != 0) {
127 if (dev
->last_cmd
[c
] == 0xff) {
128 dev
->last_cmd
[c
] = target_id
;
130 dev
->last_cmd
[c
] |= 0x40;
132 if (dev
->dev_id
== ATP885_DEVID
)
133 dev
->r1f
[c
][target_id
] |= j
;
135 printk("atp870u_intr_handle status = %x\n",i
);
138 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
139 dev
->last_cmd
[c
] = 0xff;
141 if (dev
->dev_id
== ATP885_DEVID
) {
144 ((unsigned char *) &adrcnt
)[2] = inb(tmport
++);
145 ((unsigned char *) &adrcnt
)[1] = inb(tmport
++);
146 ((unsigned char *) &adrcnt
)[0] = inb(tmport
);
147 if (dev
->id
[c
][target_id
].last_len
!= adrcnt
)
149 k
= dev
->id
[c
][target_id
].last_len
;
151 dev
->id
[c
][target_id
].tran_len
= k
;
152 dev
->id
[c
][target_id
].last_len
= adrcnt
;
155 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
);
162 if (dev
->wide_id
[c
] != 0) {
163 tmport
= workport
+ 0x1b;
165 while ((inb(tmport
) & 0x01) != 0x01) {
170 * Issue more commands
172 spin_lock_irqsave(dev
->host
->host_lock
, flags
);
173 if (((dev
->quhd
[c
] != dev
->quend
[c
]) || (dev
->last_cmd
[c
] != 0xff)) &&
174 (dev
->in_snd
[c
] == 0)) {
176 printk("Call sent_s870\n");
180 spin_unlock_irqrestore(dev
->host
->host_lock
, flags
);
186 printk("Status 0x85 return\n");
192 dev
->last_cmd
[c
] |= 0x40;
198 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
199 dev
->last_cmd
[c
] = 0xff;
203 ((unsigned char *) &adrcnt
)[2] = inb(tmport
++);
204 ((unsigned char *) &adrcnt
)[1] = inb(tmport
++);
205 ((unsigned char *) &adrcnt
)[0] = inb(tmport
);
206 k
= dev
->id
[c
][target_id
].last_len
;
208 dev
->id
[c
][target_id
].tran_len
= k
;
209 dev
->id
[c
][target_id
].last_len
= adrcnt
;
218 if (dev
->dev_id
== ATP885_DEVID
) {
219 if ((i
== 0x4c) || (i
== 0x4d) || (i
== 0x8c) || (i
== 0x8d)) {
220 if ((i
== 0x4c) || (i
== 0x8c))
227 if ((i
== 0x80) || (i
== 0x8f)) {
229 printk(KERN_DEBUG
"Device reselect\n");
233 if (cmdp
== 0x44 || i
==0x80) {
235 lun
= inb(tmport
) & 0x07;
237 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
238 dev
->last_cmd
[c
] = 0xff;
242 printk("cmdp = 0x41\n");
246 ((unsigned char *) &adrcnt
)[2] = inb(tmport
++);
247 ((unsigned char *) &adrcnt
)[1] = inb(tmport
++);
248 ((unsigned char *) &adrcnt
)[0] = inb(tmport
);
249 k
= dev
->id
[c
][target_id
].last_len
;
251 dev
->id
[c
][target_id
].tran_len
= k
;
252 dev
->id
[c
][target_id
].last_len
= adrcnt
;
259 printk("cmdp != 0x41\n");
262 dev
->id
[c
][target_id
].dirct
= 0x00;
264 outb(0x00, tmport
++);
265 outb(0x00, tmport
++);
266 outb(0x00, tmport
++);
273 if (dev
->last_cmd
[c
] != 0xff) {
274 dev
->last_cmd
[c
] |= 0x40;
276 if (dev
->dev_id
== ATP885_DEVID
) {
277 j
= inb(dev
->baseport
+ 0x29) & 0xfe;
278 outb(j
, dev
->baseport
+ 0x29);
279 tmport
= workport
+ 0x16;
281 tmport
= workport
+ 0x10;
286 target_id
= inb(tmport
);
288 * Remap wide identifiers
290 if ((target_id
& 0x10) != 0) {
291 target_id
= (target_id
& 0x07) | 0x08;
295 if (dev
->dev_id
== ATP885_DEVID
) {
296 tmport
= workport
+ 0x10;
299 workreq
= dev
->id
[c
][target_id
].curr_req
;
301 scmd_printk(KERN_DEBUG
, workreq
, "CDB");
302 for (l
= 0; l
< workreq
->cmd_len
; l
++)
303 printk(KERN_DEBUG
" %x",workreq
->cmnd
[l
]);
307 tmport
= workport
+ 0x0f;
310 outb(dev
->id
[c
][target_id
].devsp
, tmport
++);
311 adrcnt
= dev
->id
[c
][target_id
].tran_len
;
312 k
= dev
->id
[c
][target_id
].last_len
;
314 outb(((unsigned char *) &k
)[2], tmport
++);
315 outb(((unsigned char *) &k
)[1], tmport
++);
316 outb(((unsigned char *) &k
)[0], tmport
++);
318 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));
323 j
= (j
& 0x07) | 0x40;
326 j
|= dev
->id
[c
][target_id
].dirct
;
330 /* enable 32 bit fifo transfer */
331 if (dev
->dev_id
== ATP885_DEVID
) {
332 tmpcip
= dev
->pciport
[c
] + 1;
333 i
=inb(tmpcip
) & 0xf3;
334 //j=workreq->cmnd[0];
335 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
339 } else if ((dev
->dev_id
== ATP880_DEVID1
) ||
340 (dev
->dev_id
== ATP880_DEVID2
) ) {
341 tmport
= workport
- 0x05;
342 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
343 outb((unsigned char) ((inb(tmport
) & 0x3f) | 0xc0), tmport
);
345 outb((unsigned char) (inb(tmport
) & 0x3f), tmport
);
348 tmport
= workport
+ 0x3a;
349 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
350 outb((unsigned char) ((inb(tmport
) & 0xf3) | 0x08), tmport
);
352 outb((unsigned char) (inb(tmport
) & 0xf3), tmport
);
355 tmport
= workport
+ 0x1b;
358 id
= id
<< target_id
;
360 * Is this a wide device
362 if ((id
& dev
->wide_id
[c
]) != 0) {
366 while ((inb(tmport
) & 0x01) != j
) {
369 if (dev
->id
[c
][target_id
].last_len
== 0) {
370 tmport
= workport
+ 0x18;
374 printk("dev->id[c][target_id].last_len = 0\n");
379 printk("target_id = %d adrcnt = %d\n",target_id
,adrcnt
);
381 prd
= dev
->id
[c
][target_id
].prd_pos
;
382 while (adrcnt
!= 0) {
383 id
= ((unsigned short int *)prd
)[2];
390 ((unsigned short int *)prd
)[2] = (unsigned short int)
392 ((unsigned long *)prd
)[0] += adrcnt
;
394 dev
->id
[c
][target_id
].prd_pos
= prd
;
397 dev
->id
[c
][target_id
].prdaddr
+= 0x08;
400 dev
->id
[c
][target_id
].prd_pos
= prd
;
404 tmpcip
= dev
->pciport
[c
] + 0x04;
405 outl(dev
->id
[c
][target_id
].prdaddr
, tmpcip
);
407 printk("dev->id[%d][%d].prdaddr 0x%8x\n", c
, target_id
, dev
->id
[c
][target_id
].prdaddr
);
409 if (dev
->dev_id
== ATP885_DEVID
) {
417 tmport
= workport
+ 0x18;
419 * Check transfer direction
421 if (dev
->id
[c
][target_id
].dirct
!= 0) {
426 printk("status 0x80 return dirct != 0\n");
434 printk("status 0x80 return dirct = 0\n");
440 * Current scsi request on this target
443 workreq
= dev
->id
[c
][target_id
].curr_req
;
446 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40)
448 dev
->last_cmd
[c
] = 0xff;
451 workreq
->result
= errstus
;
455 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
456 dev
->last_cmd
[c
] = 0xff;
460 errstus
= inb(tmport
);
461 if (((dev
->r1f
[c
][target_id
] & 0x10) != 0)&&(dev
->dev_id
==ATP885_DEVID
)) {
462 printk(KERN_WARNING
"AEC67162 CRC ERROR !\n");
465 workreq
->result
= errstus
;
467 if (dev
->dev_id
== ATP885_DEVID
) {
468 j
= inb(dev
->baseport
+ 0x29) | 0x01;
469 outb(j
, dev
->baseport
+ 0x29);
472 * Complete the command
474 if (workreq
->use_sg
) {
475 pci_unmap_sg(dev
->pdev
,
476 (struct scatterlist
*)workreq
->request_buffer
,
478 workreq
->sc_data_direction
);
479 } else if (workreq
->request_bufflen
&&
480 workreq
->sc_data_direction
!= DMA_NONE
) {
481 pci_unmap_single(dev
->pdev
,
482 workreq
->SCp
.dma_handle
,
483 workreq
->request_bufflen
,
484 workreq
->sc_data_direction
);
486 spin_lock_irqsave(dev
->host
->host_lock
, flags
);
487 (*workreq
->scsi_done
) (workreq
);
489 printk("workreq->scsi_done\n");
492 * Clear it off the queue
494 dev
->id
[c
][target_id
].curr_req
= NULL
;
496 spin_unlock_irqrestore(dev
->host
->host_lock
, flags
);
500 if (dev
->wide_id
[c
] != 0) {
501 tmport
= workport
+ 0x1b;
503 while ((inb(tmport
) & 0x01) != 0x01) {
508 * If there is stuff to send and nothing going then send it
510 spin_lock_irqsave(dev
->host
->host_lock
, flags
);
511 if (((dev
->last_cmd
[c
] != 0xff) || (dev
->quhd
[c
] != dev
->quend
[c
])) &&
512 (dev
->in_snd
[c
] == 0)) {
514 printk("Call sent_s870(scsi_done)\n");
518 spin_unlock_irqrestore(dev
->host
->host_lock
, flags
);
522 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
523 dev
->last_cmd
[c
] = 0xff;
531 outl(dev
->id
[c
][target_id
].prdaddr
, tmpcip
);
536 tmport
= workport
+ 0x10;
538 if (dev
->dev_id
== ATP885_DEVID
) {
540 k
= dev
->id
[c
][target_id
].last_len
;
541 outb((unsigned char) (((unsigned char *) (&k
))[2]), tmport
++);
542 outb((unsigned char) (((unsigned char *) (&k
))[1]), tmport
++);
543 outb((unsigned char) (((unsigned char *) (&k
))[0]), tmport
);
544 dev
->id
[c
][target_id
].dirct
= 0x00;
547 dev
->id
[c
][target_id
].dirct
= 0x00;
557 outl(dev
->id
[c
][target_id
].prdaddr
, tmpcip
);
562 tmport
= workport
+ 0x10;
564 if (dev
->dev_id
== ATP885_DEVID
) {
566 k
= dev
->id
[c
][target_id
].last_len
;
567 outb((unsigned char) (((unsigned char *) (&k
))[2]), tmport
++);
568 outb((unsigned char) (((unsigned char *) (&k
))[1]), tmport
++);
569 outb((unsigned char) (((unsigned char *) (&k
))[0]), tmport
++);
573 outb((unsigned char) (inb(tmport
) | 0x20), tmport
);
574 dev
->id
[c
][target_id
].dirct
= 0x20;
587 dev
->id
[c
][target_id
].dirct
= 0x00;
589 outb(0x00, tmport
++);
590 outb(0x00, tmport
++);
591 outb(0x00, tmport
++);
597 // tmport = workport + 0x17;
599 // dev->working[c] = 0;
606 printk("atp870u_intr_handle exit\n");
611 * atp870u_queuecommand - Queue SCSI command
612 * @req_p: request block
613 * @done: completion function
615 * Queue a command to the ATP queue. Called with the host lock held.
617 static int atp870u_queuecommand(struct scsi_cmnd
* req_p
,
618 void (*done
) (struct scsi_cmnd
*))
621 unsigned int tmport
,m
;
622 struct atp_unit
*dev
;
623 struct Scsi_Host
*host
;
625 c
= scmd_channel(req_p
);
626 req_p
->sense_buffer
[0]=0;
628 if (scmd_channel(req_p
) > 1) {
629 req_p
->result
= 0x00040000;
632 printk("atp870u_queuecommand : req_p->device->channel > 1\n");
637 host
= req_p
->device
->host
;
638 dev
= (struct atp_unit
*)&host
->hostdata
;
643 m
= m
<< scmd_id(req_p
);
646 * Fake a timeout for missing targets
649 if ((m
& dev
->active_id
[c
]) == 0) {
650 req_p
->result
= 0x00040000;
656 req_p
->scsi_done
= done
;
659 printk( "atp870u_queuecommand: done can't be NULL\n");
670 if (dev
->quend
[c
] >= qcnt
) {
677 if (dev
->quhd
[c
] == dev
->quend
[c
]) {
678 if (dev
->quend
[c
] == 0) {
679 dev
->quend
[c
] = qcnt
;
682 printk("atp870u_queuecommand : dev->quhd[c] == dev->quend[c]\n");
685 req_p
->result
= 0x00020000;
689 dev
->quereq
[c
][dev
->quend
[c
]] = req_p
;
690 tmport
= dev
->ioport
[c
] + 0x1c;
692 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
]);
694 if ((inb(tmport
) == 0) && (dev
->in_int
[c
] == 0) && (dev
->in_snd
[c
] == 0)) {
696 printk("Call sent_s870(atp870u_queuecommand)\n");
701 printk("atp870u_queuecommand : exit\n");
707 * send_s870 - send a command to the controller
710 * On entry there is work queued to be done. We move some of that work to the
713 * Caller holds the host lock.
715 static void send_s870(struct atp_unit
*dev
,unsigned char c
)
718 struct scsi_cmnd
*workreq
;
720 unsigned char j
, target_id
;
722 unsigned short int tmpcip
, w
;
723 unsigned long l
, bttl
= 0;
724 unsigned int workport
;
725 struct scatterlist
*sgpnt
;
726 unsigned long sg_count
;
728 if (dev
->in_snd
[c
] != 0) {
730 printk("cmnd in_snd\n");
735 printk("Sent_s870 enter\n");
738 if ((dev
->last_cmd
[c
] != 0xff) && ((dev
->last_cmd
[c
] & 0x40) != 0)) {
739 dev
->last_cmd
[c
] &= 0x0f;
740 workreq
= dev
->id
[c
][dev
->last_cmd
[c
]].curr_req
;
741 if (workreq
!= NULL
) { /* check NULL pointer */
744 dev
->last_cmd
[c
] = 0xff;
745 if (dev
->quhd
[c
] == dev
->quend
[c
]) {
750 if ((dev
->last_cmd
[c
] != 0xff) && (dev
->working
[c
] != 0)) {
757 if (dev
->quhd
[c
] >= qcnt
) {
760 workreq
= dev
->quereq
[c
][dev
->quhd
[c
]];
761 if (dev
->id
[c
][scmd_id(workreq
)].curr_req
== 0) {
762 dev
->id
[c
][scmd_id(workreq
)].curr_req
= workreq
;
763 dev
->last_cmd
[c
] = scmd_id(workreq
);
771 workport
= dev
->ioport
[c
];
772 tmport
= workport
+ 0x1f;
773 if ((inb(tmport
) & 0xb0) != 0) {
776 tmport
= workport
+ 0x1c;
777 if (inb(tmport
) == 0) {
782 printk("Abort to Send\n");
784 dev
->last_cmd
[c
] |= 0x40;
789 printk("OK to Send\n");
790 scmd_printk(KERN_DEBUG
, workreq
, "CDB");
791 for(i
=0;i
<workreq
->cmd_len
;i
++) {
792 printk(" %x",workreq
->cmnd
[i
]);
796 if (dev
->dev_id
== ATP885_DEVID
) {
797 j
= inb(dev
->baseport
+ 0x29) & 0xfe;
798 outb(j
, dev
->baseport
+ 0x29);
799 dev
->r1f
[c
][scmd_id(workreq
)] = 0;
802 if (workreq
->cmnd
[0] == READ_CAPACITY
) {
803 if (workreq
->request_bufflen
> 8) {
804 workreq
->request_bufflen
= 0x08;
807 if (workreq
->cmnd
[0] == 0x00) {
808 workreq
->request_bufflen
= 0;
811 tmport
= workport
+ 0x1b;
813 target_id
= scmd_id(workreq
);
820 if ((w
& dev
->wide_id
[c
]) != 0) {
824 while ((inb(tmport
) & 0x01) != j
) {
827 printk("send_s870 while loop 1\n");
835 outb(workreq
->cmd_len
, tmport
++);
836 outb(0x2c, tmport
++);
837 if (dev
->dev_id
== ATP885_DEVID
) {
838 outb(0x7f, tmport
++);
840 outb(0xcf, tmport
++);
842 for (i
= 0; i
< workreq
->cmd_len
; i
++) {
843 outb(workreq
->cmnd
[i
], tmport
++);
845 tmport
= workport
+ 0x0f;
846 outb(workreq
->device
->lun
, tmport
);
851 outb(dev
->id
[c
][target_id
].devsp
, tmport
++);
853 printk("dev->id[%d][%d].devsp = %2x\n",c
,target_id
,dev
->id
[c
][target_id
].devsp
);
856 * Figure out the transfer size
858 if (workreq
->use_sg
) {
860 printk("Using SGL\n");
864 sgpnt
= (struct scatterlist
*) workreq
->request_buffer
;
865 sg_count
= pci_map_sg(dev
->pdev
, sgpnt
, workreq
->use_sg
,
866 workreq
->sc_data_direction
);
868 for (i
= 0; i
< workreq
->use_sg
; i
++) {
869 if (sgpnt
[i
].length
== 0 || workreq
->use_sg
> ATP870U_SCATTER
) {
870 panic("Foooooooood fight!");
872 l
+= sgpnt
[i
].length
;
875 printk( "send_s870: workreq->use_sg %d, sg_count %d l %8ld\n", workreq
->use_sg
, sg_count
, l
);
877 } else if(workreq
->request_bufflen
&& workreq
->sc_data_direction
!= PCI_DMA_NONE
) {
879 printk("Not using SGL\n");
881 workreq
->SCp
.dma_handle
= pci_map_single(dev
->pdev
, workreq
->request_buffer
,
882 workreq
->request_bufflen
,
883 workreq
->sc_data_direction
);
884 l
= workreq
->request_bufflen
;
886 printk( "send_s870: workreq->use_sg %d, l %8ld\n", workreq
->use_sg
, l
);
890 * Write transfer size
892 outb((unsigned char) (((unsigned char *) (&l
))[2]), tmport
++);
893 outb((unsigned char) (((unsigned char *) (&l
))[1]), tmport
++);
894 outb((unsigned char) (((unsigned char *) (&l
))[0]), tmport
++);
896 dev
->id
[c
][j
].last_len
= l
;
897 dev
->id
[c
][j
].tran_len
= 0;
899 printk("dev->id[%2d][%2d].last_len = %d\n",c
,j
,dev
->id
[c
][j
].last_len
);
904 if ((j
& 0x08) != 0) {
905 j
= (j
& 0x07) | 0x40;
908 * Check transfer direction
910 if (workreq
->sc_data_direction
== DMA_TO_DEVICE
) {
911 outb((unsigned char) (j
| 0x20), tmport
++);
915 outb((unsigned char) (inb(tmport
) | 0x80), tmport
);
917 tmport
= workport
+ 0x1c;
918 dev
->id
[c
][target_id
].dirct
= 0;
920 if (inb(tmport
) == 0) {
921 tmport
= workport
+ 0x18;
923 printk("change SCSI_CMD_REG 0x08\n");
927 dev
->last_cmd
[c
] |= 0x40;
932 tmpcip
= dev
->pciport
[c
];
933 prd
= dev
->id
[c
][target_id
].prd_table
;
934 dev
->id
[c
][target_id
].prd_pos
= prd
;
937 * Now write the request list. Either as scatter/gather or as
941 if (workreq
->use_sg
) {
942 sgpnt
= (struct scatterlist
*) workreq
->request_buffer
;
944 for (j
= 0; j
< workreq
->use_sg
; j
++) {
945 bttl
= sg_dma_address(&sgpnt
[j
]);
946 l
=sg_dma_len(&sgpnt
[j
]);
948 printk("1. bttl %x, l %x\n",bttl
, l
);
950 while (l
> 0x10000) {
951 (((u16
*) (prd
))[i
+ 3]) = 0x0000;
952 (((u16
*) (prd
))[i
+ 2]) = 0x0000;
953 (((u32
*) (prd
))[i
>> 1]) = cpu_to_le32(bttl
);
958 (((u32
*) (prd
))[i
>> 1]) = cpu_to_le32(bttl
);
959 (((u16
*) (prd
))[i
+ 2]) = cpu_to_le16(l
);
960 (((u16
*) (prd
))[i
+ 3]) = 0;
963 (((u16
*) (prd
))[i
- 1]) = cpu_to_le16(0x8000);
965 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]));
966 printk("2. bttl %x, l %x\n",bttl
, l
);
970 * For a linear request write a chain of blocks
972 bttl
= workreq
->SCp
.dma_handle
;
973 l
= workreq
->request_bufflen
;
976 printk("3. bttl %x, l %x\n",bttl
, l
);
978 while (l
> 0x10000) {
979 (((u16
*) (prd
))[i
+ 3]) = 0x0000;
980 (((u16
*) (prd
))[i
+ 2]) = 0x0000;
981 (((u32
*) (prd
))[i
>> 1]) = cpu_to_le32(bttl
);
986 (((u16
*) (prd
))[i
+ 3]) = cpu_to_le16(0x8000);
987 (((u16
*) (prd
))[i
+ 2]) = cpu_to_le16(l
);
988 (((u32
*) (prd
))[i
>> 1]) = cpu_to_le32(bttl
);
990 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]));
991 printk("4. bttl %x, l %x\n",bttl
, l
);
997 printk("send_s870: prdaddr_2 0x%8x tmpcip %x target_id %d\n", dev
->id
[c
][target_id
].prdaddr
,tmpcip
,target_id
);
999 dev
->id
[c
][target_id
].prdaddr
= dev
->id
[c
][target_id
].prd_bus
;
1000 outl(dev
->id
[c
][target_id
].prdaddr
, tmpcip
);
1001 tmpcip
= tmpcip
- 2;
1004 if (dev
->dev_id
== ATP885_DEVID
) {
1006 j
=inb(tmpcip
) & 0xf3;
1007 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) ||
1008 (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
1013 } else if ((dev
->dev_id
== ATP880_DEVID1
) ||
1014 (dev
->dev_id
== ATP880_DEVID2
)) {
1016 tmport
= workport
- 0x05;
1017 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
1018 outb((unsigned char) ((inb(tmport
) & 0x3f) | 0xc0), tmport
);
1020 outb((unsigned char) (inb(tmport
) & 0x3f), tmport
);
1024 tmport
= workport
+ 0x3a;
1025 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
1026 outb((inb(tmport
) & 0xf3) | 0x08, tmport
);
1028 outb(inb(tmport
) & 0xf3, tmport
);
1031 tmport
= workport
+ 0x1c;
1033 if(workreq
->sc_data_direction
== DMA_TO_DEVICE
) {
1034 dev
->id
[c
][target_id
].dirct
= 0x20;
1035 if (inb(tmport
) == 0) {
1036 tmport
= workport
+ 0x18;
1040 printk( "start DMA(to target)\n");
1043 dev
->last_cmd
[c
] |= 0x40;
1048 if (inb(tmport
) == 0) {
1049 tmport
= workport
+ 0x18;
1053 printk( "start DMA(to host)\n");
1056 dev
->last_cmd
[c
] |= 0x40;
1063 static unsigned char fun_scam(struct atp_unit
*dev
, unsigned short int *val
)
1065 unsigned int tmport
;
1066 unsigned short int i
, k
;
1069 tmport
= dev
->ioport
[0] + 0x1c;
1072 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
1074 j
= (unsigned char) (k
>> 8);
1075 if ((k
& 0x8000) != 0) { /* DB7 all release? */
1079 *val
|= 0x4000; /* assert DB6 */
1081 *val
&= 0xdfff; /* assert DB5 */
1084 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
1085 if ((inw(tmport
) & 0x2000) != 0) { /* DB5 all release? */
1089 *val
|= 0x8000; /* no DB4-0, assert DB7 */
1092 *val
&= 0xbfff; /* release DB6 */
1095 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
1096 if ((inw(tmport
) & 0x4000) != 0) { /* DB6 all release? */
1104 static void tscam(struct Scsi_Host
*host
)
1107 unsigned int tmport
;
1108 unsigned char i
, j
, k
;
1110 unsigned short int m
, assignid_map
, val
;
1111 unsigned char mbuf
[33], quintet
[2];
1112 struct atp_unit
*dev
= (struct atp_unit
*)&host
->hostdata
;
1113 static unsigned char g2q_tab
[8] = {
1114 0x38, 0x31, 0x32, 0x2b, 0x34, 0x2d, 0x2e, 0x27
1117 /* I can't believe we need this before we've even done anything. Remove it
1118 * and see if anyone bitches.
1119 for (i = 0; i < 0x10; i++) {
1124 tmport
= dev
->ioport
[0] + 1;
1125 outb(0x08, tmport
++);
1127 tmport
= dev
->ioport
[0] + 0x11;
1130 if ((dev
->scam_on
& 0x40) == 0) {
1134 m
<<= dev
->host_id
[0];
1136 if (dev
->chip_ver
< 4) {
1141 tmport
= dev
->ioport
[0] + 0x02;
1142 outb(0x02, tmport
++); /* 2*2=4ms,3EH 2/32*3E=3.9ms */
1150 for (i
= 0; i
< j
; i
++) {
1153 if ((m
& assignid_map
) != 0) {
1156 tmport
= dev
->ioport
[0] + 0x0f;
1163 k
= (i
& 0x07) | 0x40;
1168 tmport
= dev
->ioport
[0] + 0x1b;
1169 if (dev
->chip_ver
== 4) {
1175 tmport
= dev
->ioport
[0] + 0x18;
1179 while ((inb(tmport
) & 0x80) == 0x00)
1184 if ((k
== 0x85) || (k
== 0x42)) {
1187 tmport
= dev
->ioport
[0] + 0x10;
1194 tmport
= dev
->ioport
[0] + 0x02;
1196 tmport
= dev
->ioport
[0] + 0x1b;
1201 val
= 0x0080; /* bsy */
1202 tmport
= dev
->ioport
[0] + 0x1c;
1204 val
|= 0x0040; /* sel */
1206 val
|= 0x0004; /* msg */
1208 inb(0x80); /* 2 deskew delay(45ns*2=90ns) */
1209 val
&= 0x007f; /* no bsy */
1212 val
&= 0x00fb; /* after 1ms no msg */
1215 if ((inb(tmport
) & 0x04) != 0) {
1220 for (n
= 0; n
< 0x30000; n
++) {
1221 if ((inb(tmport
) & 0x80) != 0) { /* bsy ? */
1227 for (n
= 0; n
< 0x30000; n
++) {
1228 if ((inb(tmport
) & 0x81) == 0x0081) {
1235 val
|= 0x8003; /* io,cd,db7 */
1238 val
&= 0x00bf; /* no sel */
1243 if ((inb(tmport
) & 0x80) == 0x00) { /* bsy ? */
1246 tmport
= dev
->ioport
[0] + 0x15;
1251 while ((inb(tmport
) & 0x80) == 0)
1257 val
&= 0x00ff; /* synchronization */
1259 fun_scam(dev
, &val
);
1261 val
&= 0x00ff; /* isolation */
1263 fun_scam(dev
, &val
);
1268 if ((inw(tmport
) & 0x2000) == 0) {
1272 val
&= 0x00ff; /* get ID_STRING */
1274 k
= fun_scam(dev
, &val
);
1275 if ((k
& 0x03) == 0) {
1280 if ((k
& 0x02) != 0) {
1291 TCM_5
: /* isolation complete.. */
1293 printk(" \n%x %x %x %s\n ",assignid_map,mbuf[0],mbuf[1],&mbuf[2]); */
1296 if ((j
& 0x20) != 0) { /* bit5=1:ID upto 7 */
1299 if ((j
& 0x06) == 0) { /* IDvalid? */
1306 if ((m
& assignid_map
) == 0) {
1313 G2Q5
: /* srch from max acceptable ID# */
1314 k
= i
; /* max acceptable ID# */
1318 if ((m
& assignid_map
) == 0) {
1325 G2Q_QUIN
: /* k=binID#, */
1328 quintet
[0] = 0x38; /* 1st dft ID<8 */
1330 quintet
[0] = 0x31; /* 1st ID>=8 */
1333 quintet
[1] = g2q_tab
[k
];
1335 val
&= 0x00ff; /* AssignID 1stQuintet,AH=001xxxxx */
1336 m
= quintet
[0] << 8;
1338 fun_scam(dev
, &val
);
1339 val
&= 0x00ff; /* AssignID 2ndQuintet,AH=001xxxxx */
1340 m
= quintet
[1] << 8;
1342 fun_scam(dev
, &val
);
1348 static void is870(struct atp_unit
*dev
, unsigned int wkport
)
1350 unsigned int tmport
;
1351 unsigned char i
, j
, k
, rmb
, n
;
1352 unsigned short int m
;
1353 static unsigned char mbuf
[512];
1354 static unsigned char satn
[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
1355 static unsigned char inqd
[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
1356 static unsigned char synn
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1357 static unsigned char synu
[6] = { 0x80, 1, 3, 1, 0x0c, 0x0e };
1358 static unsigned char synw
[6] = { 0x80, 1, 3, 1, 0x0c, 0x07 };
1359 static unsigned char wide
[6] = { 0x80, 1, 2, 3, 1, 0 };
1361 tmport
= wkport
+ 0x3a;
1362 outb((unsigned char) (inb(tmport
) | 0x10), tmport
);
1364 for (i
= 0; i
< 16; i
++) {
1365 if ((dev
->chip_ver
!= 4) && (i
> 7)) {
1370 if ((m
& dev
->active_id
[0]) != 0) {
1373 if (i
== dev
->host_id
[0]) {
1374 printk(KERN_INFO
" ID: %2d Host Adapter\n", dev
->host_id
[0]);
1377 tmport
= wkport
+ 0x1b;
1378 if (dev
->chip_ver
== 4) {
1383 tmport
= wkport
+ 1;
1384 outb(0x08, tmport
++);
1385 outb(0x7f, tmport
++);
1386 outb(satn
[0], tmport
++);
1387 outb(satn
[1], tmport
++);
1388 outb(satn
[2], tmport
++);
1389 outb(satn
[3], tmport
++);
1390 outb(satn
[4], tmport
++);
1391 outb(satn
[5], tmport
++);
1395 outb(dev
->id
[0][i
].devsp
, tmport
++);
1397 outb(satn
[6], tmport
++);
1398 outb(satn
[7], tmport
++);
1400 if ((j
& 0x08) != 0) {
1401 j
= (j
& 0x07) | 0x40;
1405 outb(satn
[8], tmport
);
1408 while ((inb(tmport
) & 0x80) == 0x00)
1412 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1415 while (inb(tmport
) != 0x8e)
1418 dev
->active_id
[0] |= m
;
1420 tmport
= wkport
+ 0x10;
1422 tmport
= wkport
+ 0x04;
1426 tmport
= wkport
+ 0x18;
1429 while ((inb(tmport
) & 0x80) == 0x00)
1434 tmport
= wkport
+ 0x10;
1439 tmport
= wkport
+ 3;
1440 outb(inqd
[0], tmport
++);
1441 outb(inqd
[1], tmport
++);
1442 outb(inqd
[2], tmport
++);
1443 outb(inqd
[3], tmport
++);
1444 outb(inqd
[4], tmport
++);
1445 outb(inqd
[5], tmport
);
1449 outb(dev
->id
[0][i
].devsp
, tmport
++);
1451 outb(inqd
[6], tmport
++);
1452 outb(inqd
[7], tmport
++);
1454 outb(inqd
[8], tmport
);
1457 while ((inb(tmport
) & 0x80) == 0x00)
1461 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1464 while (inb(tmport
) != 0x8e)
1467 tmport
= wkport
+ 0x1b;
1468 if (dev
->chip_ver
== 4)
1471 tmport
= wkport
+ 0x18;
1477 if ((k
& 0x01) != 0) {
1479 mbuf
[j
++] = inb(tmport
);
1483 if ((k
& 0x80) == 0) {
1491 tmport
= wkport
+ 0x10;
1501 while ((inb(tmport
) & 0x80) == 0x00)
1505 if (inb(tmport
) != 0x16) {
1510 printk(KERN_INFO
" ID: %2d %s\n", i
, &mbuf
[8]);
1511 dev
->id
[0][i
].devtype
= mbuf
[0];
1514 if (dev
->chip_ver
!= 4) {
1517 if ((mbuf
[7] & 0x60) == 0) {
1520 if ((dev
->global_map
[0] & 0x20) == 0) {
1523 tmport
= wkport
+ 0x1b;
1525 tmport
= wkport
+ 3;
1526 outb(satn
[0], tmport
++);
1527 outb(satn
[1], tmport
++);
1528 outb(satn
[2], tmport
++);
1529 outb(satn
[3], tmport
++);
1530 outb(satn
[4], tmport
++);
1531 outb(satn
[5], tmport
++);
1535 outb(dev
->id
[0][i
].devsp
, tmport
++);
1537 outb(satn
[6], tmport
++);
1538 outb(satn
[7], tmport
++);
1540 outb(satn
[8], tmport
);
1543 while ((inb(tmport
) & 0x80) == 0x00)
1547 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1550 while (inb(tmport
) != 0x8e)
1555 tmport
= wkport
+ 0x14;
1561 while ((inb(tmport
) & 0x80) == 0) {
1562 if ((inb(tmport
) & 0x01) != 0) {
1564 outb(wide
[j
++], tmport
);
1570 while ((inb(tmport
) & 0x80) == 0x00)
1573 j
= inb(tmport
) & 0x0f;
1585 tmport
= wkport
+ 0x18;
1588 while ((inb(tmport
) & 0x80) == 0) {
1589 if ((inb(tmport
) & 0x01) != 0) {
1596 j
= inb(tmport
) & 0x0f;
1608 tmport
= wkport
+ 0x14;
1616 if ((j
& 0x01) != 0) {
1618 mbuf
[k
++] = inb(tmport
);
1622 if ((j
& 0x80) == 0x00) {
1626 j
= inb(tmport
) & 0x0f;
1638 tmport
= wkport
+ 0x10;
1640 tmport
= wkport
+ 0x14;
1646 while ((inb(tmport
) & 0x80) == 0x00)
1657 if (mbuf
[0] != 0x01) {
1660 if (mbuf
[1] != 0x02) {
1663 if (mbuf
[2] != 0x03) {
1666 if (mbuf
[3] != 0x01) {
1671 dev
->wide_id
[0] |= m
;
1673 if ((dev
->id
[0][i
].devtype
== 0x00) || (dev
->id
[0][i
].devtype
== 0x07) || ((dev
->id
[0][i
].devtype
== 0x05) && ((n
& 0x10) != 0))) {
1678 tmport
= wkport
+ 0x1b;
1680 if ((m
& dev
->wide_id
[0]) != 0) {
1684 tmport
= wkport
+ 3;
1685 outb(satn
[0], tmport
++);
1686 outb(satn
[1], tmport
++);
1687 outb(satn
[2], tmport
++);
1688 outb(satn
[3], tmport
++);
1689 outb(satn
[4], tmport
++);
1690 outb(satn
[5], tmport
++);
1694 outb(dev
->id
[0][i
].devsp
, tmport
++);
1696 outb(satn
[6], tmport
++);
1697 outb(satn
[7], tmport
++);
1699 outb(satn
[8], tmport
);
1702 while ((inb(tmport
) & 0x80) == 0x00)
1706 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1709 while (inb(tmport
) != 0x8e)
1714 tmport
= wkport
+ 0x14;
1720 while ((inb(tmport
) & 0x80) == 0) {
1721 if ((inb(tmport
) & 0x01) != 0) {
1723 if ((m
& dev
->wide_id
[0]) != 0) {
1724 outb(synw
[j
++], tmport
);
1726 if ((m
& dev
->ultra_map
[0]) != 0) {
1727 outb(synu
[j
++], tmport
);
1729 outb(synn
[j
++], tmport
);
1737 while ((inb(tmport
) & 0x80) == 0x00)
1740 j
= inb(tmport
) & 0x0f;
1752 tmport
= wkport
+ 0x18;
1755 while ((inb(tmport
) & 0x80) == 0x00) {
1756 if ((inb(tmport
) & 0x01) != 0x00) {
1779 tmport
= wkport
+ 0x14;
1787 if ((j
& 0x01) != 0x00) {
1789 mbuf
[k
++] = inb(tmport
);
1793 if ((j
& 0x80) == 0x00) {
1798 while ((inb(tmport
) & 0x80) == 0x00)
1817 tmport
= wkport
+ 0x10;
1820 tmport
= wkport
+ 0x14;
1826 while ((inb(tmport
) & 0x80) == 0x00)
1834 if (mbuf
[0] != 0x01) {
1837 if (mbuf
[1] != 0x03) {
1840 if (mbuf
[4] == 0x00) {
1843 if (mbuf
[3] > 0x64) {
1846 if (mbuf
[4] > 0x0c) {
1849 dev
->id
[0][i
].devsp
= mbuf
[4];
1850 if ((mbuf
[3] < 0x0d) && (rmb
== 0)) {
1854 if (mbuf
[3] < 0x1a) {
1858 if (mbuf
[3] < 0x33) {
1862 if (mbuf
[3] < 0x4c) {
1868 dev
->id
[0][i
].devsp
= (dev
->id
[0][i
].devsp
& 0x0f) | j
;
1870 tmport
= wkport
+ 0x3a;
1871 outb((unsigned char) (inb(tmport
) & 0xef), tmport
);
1874 static void is880(struct atp_unit
*dev
, unsigned int wkport
)
1876 unsigned int tmport
;
1877 unsigned char i
, j
, k
, rmb
, n
, lvdmode
;
1878 unsigned short int m
;
1879 static unsigned char mbuf
[512];
1880 static unsigned char satn
[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
1881 static unsigned char inqd
[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
1882 static unsigned char synn
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1883 unsigned char synu
[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
1884 static unsigned char synw
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1885 unsigned char synuw
[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
1886 static unsigned char wide
[6] = { 0x80, 1, 2, 3, 1, 0 };
1887 static unsigned char u3
[9] = { 0x80, 1, 6, 4, 0x09, 00, 0x0e, 0x01, 0x02 };
1889 lvdmode
= inb(wkport
+ 0x3f) & 0x40;
1891 for (i
= 0; i
< 16; i
++) {
1894 if ((m
& dev
->active_id
[0]) != 0) {
1897 if (i
== dev
->host_id
[0]) {
1898 printk(KERN_INFO
" ID: %2d Host Adapter\n", dev
->host_id
[0]);
1901 tmport
= wkport
+ 0x5b;
1903 tmport
= wkport
+ 0x41;
1904 outb(0x08, tmport
++);
1905 outb(0x7f, tmport
++);
1906 outb(satn
[0], tmport
++);
1907 outb(satn
[1], tmport
++);
1908 outb(satn
[2], tmport
++);
1909 outb(satn
[3], tmport
++);
1910 outb(satn
[4], tmport
++);
1911 outb(satn
[5], tmport
++);
1915 outb(dev
->id
[0][i
].devsp
, tmport
++);
1917 outb(satn
[6], tmport
++);
1918 outb(satn
[7], tmport
++);
1920 if ((j
& 0x08) != 0) {
1921 j
= (j
& 0x07) | 0x40;
1925 outb(satn
[8], tmport
);
1928 while ((inb(tmport
) & 0x80) == 0x00)
1932 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1935 while (inb(tmport
) != 0x8e)
1938 dev
->active_id
[0] |= m
;
1940 tmport
= wkport
+ 0x50;
1942 tmport
= wkport
+ 0x54;
1946 tmport
= wkport
+ 0x58;
1950 while ((inb(tmport
) & 0x80) == 0x00)
1956 tmport
= wkport
+ 0x50;
1961 tmport
= wkport
+ 0x43;
1962 outb(inqd
[0], tmport
++);
1963 outb(inqd
[1], tmport
++);
1964 outb(inqd
[2], tmport
++);
1965 outb(inqd
[3], tmport
++);
1966 outb(inqd
[4], tmport
++);
1967 outb(inqd
[5], tmport
);
1971 outb(dev
->id
[0][i
].devsp
, tmport
++);
1973 outb(inqd
[6], tmport
++);
1974 outb(inqd
[7], tmport
++);
1976 outb(inqd
[8], tmport
);
1979 while ((inb(tmport
) & 0x80) == 0x00)
1983 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1986 while (inb(tmport
) != 0x8e)
1989 tmport
= wkport
+ 0x5b;
1991 tmport
= wkport
+ 0x58;
1997 if ((k
& 0x01) != 0) {
1999 mbuf
[j
++] = inb(tmport
);
2003 if ((k
& 0x80) == 0) {
2011 tmport
= wkport
+ 0x50;
2020 while ((inb(tmport
) & 0x80) == 0x00)
2024 if (inb(tmport
) != 0x16)
2029 printk(KERN_INFO
" ID: %2d %s\n", i
, &mbuf
[8]);
2030 dev
->id
[0][i
].devtype
= mbuf
[0];
2033 if ((mbuf
[7] & 0x60) == 0) {
2036 if ((i
< 8) && ((dev
->global_map
[0] & 0x20) == 0)) {
2042 if (dev
->sp
[0][i
] != 0x04) // force u2
2047 tmport
= wkport
+ 0x5b;
2049 tmport
= wkport
+ 0x43;
2050 outb(satn
[0], tmport
++);
2051 outb(satn
[1], tmport
++);
2052 outb(satn
[2], tmport
++);
2053 outb(satn
[3], tmport
++);
2054 outb(satn
[4], tmport
++);
2055 outb(satn
[5], tmport
++);
2059 outb(dev
->id
[0][i
].devsp
, tmport
++);
2061 outb(satn
[6], tmport
++);
2062 outb(satn
[7], tmport
++);
2064 outb(satn
[8], tmport
);
2067 while ((inb(tmport
) & 0x80) == 0x00)
2072 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
2075 while (inb(tmport
) != 0x8e)
2080 tmport
= wkport
+ 0x54;
2086 while ((inb(tmport
) & 0x80) == 0) {
2087 if ((inb(tmport
) & 0x01) != 0) {
2089 outb(u3
[j
++], tmport
);
2095 while ((inb(tmport
) & 0x80) == 0x00)
2098 j
= inb(tmport
) & 0x0f;
2110 tmport
= wkport
+ 0x58;
2113 while ((inb(tmport
) & 0x80) == 0) {
2114 if ((inb(tmport
) & 0x01) != 0) {
2121 j
= inb(tmport
) & 0x0f;
2133 tmport
= wkport
+ 0x54;
2141 if ((j
& 0x01) != 0) {
2143 mbuf
[k
++] = inb(tmport
);
2147 if ((j
& 0x80) == 0x00) {
2151 j
= inb(tmport
) & 0x0f;
2163 tmport
= wkport
+ 0x50;
2165 tmport
= wkport
+ 0x54;
2171 while ((inb(tmport
) & 0x80) == 0x00)
2182 if (mbuf
[0] != 0x01) {
2185 if (mbuf
[1] != 0x06) {
2188 if (mbuf
[2] != 0x04) {
2191 if (mbuf
[3] == 0x09) {
2194 dev
->wide_id
[0] |= m
;
2195 dev
->id
[0][i
].devsp
= 0xce;
2199 tmport
= wkport
+ 0x5b;
2201 tmport
= wkport
+ 0x43;
2202 outb(satn
[0], tmport
++);
2203 outb(satn
[1], tmport
++);
2204 outb(satn
[2], tmport
++);
2205 outb(satn
[3], tmport
++);
2206 outb(satn
[4], tmport
++);
2207 outb(satn
[5], tmport
++);
2211 outb(dev
->id
[0][i
].devsp
, tmport
++);
2213 outb(satn
[6], tmport
++);
2214 outb(satn
[7], tmport
++);
2216 outb(satn
[8], tmport
);
2219 while ((inb(tmport
) & 0x80) == 0x00)
2223 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
2226 while (inb(tmport
) != 0x8e)
2231 tmport
= wkport
+ 0x54;
2237 while ((inb(tmport
) & 0x80) == 0) {
2238 if ((inb(tmport
) & 0x01) != 0) {
2240 outb(wide
[j
++], tmport
);
2245 while ((inb(tmport
) & 0x80) == 0x00)
2248 j
= inb(tmport
) & 0x0f;
2260 tmport
= wkport
+ 0x58;
2263 while ((inb(tmport
) & 0x80) == 0) {
2264 if ((inb(tmport
) & 0x01) != 0) {
2271 j
= inb(tmport
) & 0x0f;
2283 tmport
= wkport
+ 0x54;
2291 if ((j
& 0x01) != 0) {
2293 mbuf
[k
++] = inb(tmport
);
2297 if ((j
& 0x80) == 0x00) {
2301 j
= inb(tmport
) & 0x0f;
2313 tmport
= wkport
+ 0x50;
2315 tmport
= wkport
+ 0x54;
2321 while ((inb(tmport
) & 0x80) == 0x00)
2332 if (mbuf
[0] != 0x01) {
2335 if (mbuf
[1] != 0x02) {
2338 if (mbuf
[2] != 0x03) {
2341 if (mbuf
[3] != 0x01) {
2346 dev
->wide_id
[0] |= m
;
2348 if ((dev
->id
[0][i
].devtype
== 0x00) || (dev
->id
[0][i
].devtype
== 0x07) || ((dev
->id
[0][i
].devtype
== 0x05) && ((n
& 0x10) != 0))) {
2351 if ((dev
->async
[0] & m
) != 0) {
2357 if (dev
->sp
[0][i
] == 0x02) {
2361 if (dev
->sp
[0][i
] >= 0x03) {
2366 tmport
= wkport
+ 0x5b;
2368 if ((m
& dev
->wide_id
[0]) != 0) {
2372 tmport
= wkport
+ 0x43;
2373 outb(satn
[0], tmport
++);
2374 outb(satn
[1], tmport
++);
2375 outb(satn
[2], tmport
++);
2376 outb(satn
[3], tmport
++);
2377 outb(satn
[4], tmport
++);
2378 outb(satn
[5], tmport
++);
2382 outb(dev
->id
[0][i
].devsp
, tmport
++);
2384 outb(satn
[6], tmport
++);
2385 outb(satn
[7], tmport
++);
2387 outb(satn
[8], tmport
);
2390 while ((inb(tmport
) & 0x80) == 0x00)
2394 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
2397 while (inb(tmport
) != 0x8e)
2402 tmport
= wkport
+ 0x54;
2408 while ((inb(tmport
) & 0x80) == 0) {
2409 if ((inb(tmport
) & 0x01) != 0) {
2411 if ((m
& dev
->wide_id
[0]) != 0) {
2412 if ((m
& dev
->ultra_map
[0]) != 0) {
2413 outb(synuw
[j
++], tmport
);
2415 outb(synw
[j
++], tmport
);
2418 if ((m
& dev
->ultra_map
[0]) != 0) {
2419 outb(synu
[j
++], tmport
);
2421 outb(synn
[j
++], tmport
);
2429 while ((inb(tmport
) & 0x80) == 0x00)
2432 j
= inb(tmport
) & 0x0f;
2444 tmport
= wkport
+ 0x58;
2447 while ((inb(tmport
) & 0x80) == 0x00) {
2448 if ((inb(tmport
) & 0x01) != 0x00) {
2471 tmport
= wkport
+ 0x54;
2479 if ((j
& 0x01) != 0x00) {
2481 mbuf
[k
++] = inb(tmport
);
2485 if ((j
& 0x80) == 0x00) {
2490 while ((inb(tmport
) & 0x80) == 0x00)
2509 tmport
= wkport
+ 0x50;
2512 tmport
= wkport
+ 0x54;
2518 while ((inb(tmport
) & 0x80) == 0x00)
2526 if (mbuf
[0] != 0x01) {
2529 if (mbuf
[1] != 0x03) {
2532 if (mbuf
[4] == 0x00) {
2535 if (mbuf
[3] > 0x64) {
2538 if (mbuf
[4] > 0x0e) {
2541 dev
->id
[0][i
].devsp
= mbuf
[4];
2542 if (mbuf
[3] < 0x0c) {
2546 if ((mbuf
[3] < 0x0d) && (rmb
== 0)) {
2550 if (mbuf
[3] < 0x1a) {
2554 if (mbuf
[3] < 0x33) {
2558 if (mbuf
[3] < 0x4c) {
2564 dev
->id
[0][i
].devsp
= (dev
->id
[0][i
].devsp
& 0x0f) | j
;
2568 static void atp870u_free_tables(struct Scsi_Host
*host
)
2570 struct atp_unit
*atp_dev
= (struct atp_unit
*)&host
->hostdata
;
2572 for (j
=0; j
< 2; j
++) {
2573 for (k
= 0; k
< 16; k
++) {
2574 if (!atp_dev
->id
[j
][k
].prd_table
)
2576 pci_free_consistent(atp_dev
->pdev
, 1024, atp_dev
->id
[j
][k
].prd_table
, atp_dev
->id
[j
][k
].prd_bus
);
2577 atp_dev
->id
[j
][k
].prd_table
= NULL
;
2582 static int atp870u_init_tables(struct Scsi_Host
*host
)
2584 struct atp_unit
*atp_dev
= (struct atp_unit
*)&host
->hostdata
;
2586 for(c
=0;c
< 2;c
++) {
2588 atp_dev
->id
[c
][k
].prd_table
= pci_alloc_consistent(atp_dev
->pdev
, 1024, &(atp_dev
->id
[c
][k
].prd_bus
));
2589 if (!atp_dev
->id
[c
][k
].prd_table
) {
2590 printk("atp870u_init_tables fail\n");
2591 atp870u_free_tables(host
);
2594 atp_dev
->id
[c
][k
].prdaddr
= atp_dev
->id
[c
][k
].prd_bus
;
2595 atp_dev
->id
[c
][k
].devsp
=0x20;
2596 atp_dev
->id
[c
][k
].devtype
= 0x7f;
2597 atp_dev
->id
[c
][k
].curr_req
= NULL
;
2600 atp_dev
->active_id
[c
] = 0;
2601 atp_dev
->wide_id
[c
] = 0;
2602 atp_dev
->host_id
[c
] = 0x07;
2603 atp_dev
->quhd
[c
] = 0;
2604 atp_dev
->quend
[c
] = 0;
2605 atp_dev
->last_cmd
[c
] = 0xff;
2606 atp_dev
->in_snd
[c
] = 0;
2607 atp_dev
->in_int
[c
] = 0;
2609 for (k
= 0; k
< qcnt
; k
++) {
2610 atp_dev
->quereq
[c
][k
] = NULL
;
2612 for (k
= 0; k
< 16; k
++) {
2613 atp_dev
->id
[c
][k
].curr_req
= NULL
;
2614 atp_dev
->sp
[c
][k
] = 0x04;
2620 /* return non-zero on detection */
2621 static int atp870u_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
2623 unsigned char k
, m
, c
;
2624 unsigned long flags
;
2625 unsigned int base_io
, tmport
, error
,n
;
2626 unsigned char host_id
;
2627 struct Scsi_Host
*shpnt
= NULL
;
2628 struct atp_unit
*atpdev
, *p
;
2629 unsigned char setupdata
[2][16];
2632 atpdev
= kzalloc(sizeof(*atpdev
), GFP_KERNEL
);
2636 if (pci_enable_device(pdev
))
2639 if (!pci_set_dma_mask(pdev
, DMA_32BIT_MASK
)) {
2640 printk(KERN_INFO
"atp870u: use 32bit DMA mask.\n");
2642 printk(KERN_ERR
"atp870u: DMA mask required but not available.\n");
2647 * It's probably easier to weed out some revisions like
2648 * this than via the PCI device table
2650 if (ent
->device
== PCI_DEVICE_ID_ARTOP_AEC7610
) {
2651 error
= pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &atpdev
->chip_ver
);
2652 if (atpdev
->chip_ver
< 2)
2656 switch (ent
->device
) {
2657 case PCI_DEVICE_ID_ARTOP_AEC7612UW
:
2658 case PCI_DEVICE_ID_ARTOP_AEC7612SUW
:
2662 atpdev
->chip_ver
= 0x04;
2666 base_io
= pci_resource_start(pdev
, 0);
2667 base_io
&= 0xfffffff8;
2669 if ((ent
->device
== ATP880_DEVID1
)||(ent
->device
== ATP880_DEVID2
)) {
2670 error
= pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &atpdev
->chip_ver
);
2671 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, 0x80);//JCC082803
2673 host_id
= inb(base_io
+ 0x39);
2676 printk(KERN_INFO
" ACARD AEC-67160 PCI Ultra3 LVD Host Adapter: %d"
2677 " IO:%x, IRQ:%d.\n", count
, base_io
, pdev
->irq
);
2678 atpdev
->ioport
[0] = base_io
+ 0x40;
2679 atpdev
->pciport
[0] = base_io
+ 0x28;
2680 atpdev
->dev_id
= ent
->device
;
2681 atpdev
->host_id
[0] = host_id
;
2683 tmport
= base_io
+ 0x22;
2684 atpdev
->scam_on
= inb(tmport
);
2686 atpdev
->global_map
[0] = inb(tmport
);
2688 atpdev
->ultra_map
[0] = inw(tmport
);
2696 outw(n
, base_io
+ 0x34);
2698 if (inb(base_io
+ 0x30) == 0xff)
2701 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x30);
2702 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x31);
2703 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x32);
2704 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x33);
2705 outw(n
, base_io
+ 0x34);
2707 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x30);
2708 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x31);
2709 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x32);
2710 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x33);
2711 outw(n
, base_io
+ 0x34);
2713 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x30);
2714 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x31);
2715 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x32);
2716 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x33);
2717 outw(n
, base_io
+ 0x34);
2719 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x30);
2720 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x31);
2721 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x32);
2722 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x33);
2726 outw(0, base_io
+ 0x34);
2727 atpdev
->ultra_map
[0] = 0;
2728 atpdev
->async
[0] = 0;
2729 for (k
= 0; k
< 16; k
++) {
2732 if (atpdev
->sp
[0][k
] > 1) {
2733 atpdev
->ultra_map
[0] |= n
;
2735 if (atpdev
->sp
[0][k
] == 0)
2736 atpdev
->async
[0] |= n
;
2739 atpdev
->async
[0] = ~(atpdev
->async
[0]);
2740 outb(atpdev
->global_map
[0], base_io
+ 0x35);
2742 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
2746 p
= (struct atp_unit
*)&shpnt
->hostdata
;
2748 atpdev
->host
= shpnt
;
2749 atpdev
->pdev
= pdev
;
2750 pci_set_drvdata(pdev
, p
);
2751 memcpy(p
, atpdev
, sizeof(*atpdev
));
2752 if (atp870u_init_tables(shpnt
) < 0) {
2753 printk(KERN_ERR
"Unable to allocate tables for Acard controller\n");
2757 if (request_irq(pdev
->irq
, atp870u_intr_handle
, IRQF_SHARED
, "atp880i", shpnt
)) {
2758 printk(KERN_ERR
"Unable to allocate IRQ%d for Acard controller.\n", pdev
->irq
);
2762 spin_lock_irqsave(shpnt
->host_lock
, flags
);
2763 tmport
= base_io
+ 0x38;
2764 k
= inb(tmport
) & 0x80;
2771 tmport
= base_io
+ 0x5b;
2775 tmport
= base_io
+ 0x40;
2776 outb((host_id
| 0x08), tmport
);
2780 while ((inb(tmport
) & 0x80) == 0)
2784 tmport
= base_io
+ 0x41;
2787 tmport
= base_io
+ 0x51;
2792 tmport
= base_io
+ 0x38;
2795 shpnt
->this_id
= host_id
;
2796 shpnt
->unique_id
= base_io
;
2797 shpnt
->io_port
= base_io
;
2798 shpnt
->n_io_port
= 0x60; /* Number of bytes of I/O space used */
2799 shpnt
->irq
= pdev
->irq
;
2800 } else if (ent
->device
== ATP885_DEVID
) {
2801 printk(KERN_INFO
" ACARD AEC-67162 PCI Ultra3 LVD Host Adapter: IO:%x, IRQ:%d.\n"
2802 , base_io
, pdev
->irq
);
2804 atpdev
->pdev
= pdev
;
2805 atpdev
->dev_id
= ent
->device
;
2806 atpdev
->baseport
= base_io
;
2807 atpdev
->ioport
[0] = base_io
+ 0x80;
2808 atpdev
->ioport
[1] = base_io
+ 0xc0;
2809 atpdev
->pciport
[0] = base_io
+ 0x40;
2810 atpdev
->pciport
[1] = base_io
+ 0x50;
2812 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
2816 p
= (struct atp_unit
*)&shpnt
->hostdata
;
2818 atpdev
->host
= shpnt
;
2819 atpdev
->pdev
= pdev
;
2820 pci_set_drvdata(pdev
, p
);
2821 memcpy(p
, atpdev
, sizeof(struct atp_unit
));
2822 if (atp870u_init_tables(shpnt
) < 0)
2826 printk("request_irq() shpnt %p hostdata %p\n", shpnt
, p
);
2828 if (request_irq(pdev
->irq
, atp870u_intr_handle
, IRQF_SHARED
, "atp870u", shpnt
)) {
2829 printk(KERN_ERR
"Unable to allocate IRQ for Acard controller.\n");
2833 spin_lock_irqsave(shpnt
->host_lock
, flags
);
2835 c
=inb(base_io
+ 0x29);
2836 outb((c
| 0x04),base_io
+ 0x29);
2843 outw(n
,base_io
+ 0x3c);
2844 if (inl(base_io
+ 0x38) == 0xffffffff) {
2847 for (m
=0; m
< 2; m
++) {
2848 p
->global_map
[m
]= 0;
2849 for (k
=0; k
< 4; k
++) {
2850 outw(n
++,base_io
+ 0x3c);
2851 ((unsigned long *)&setupdata
[m
][0])[k
]=inl(base_io
+ 0x38);
2853 for (k
=0; k
< 4; k
++) {
2854 outw(n
++,base_io
+ 0x3c);
2855 ((unsigned long *)&p
->sp
[m
][0])[k
]=inl(base_io
+ 0x38);
2862 printk( "Flash Read OK\n");
2864 c
=inb(base_io
+ 0x29);
2865 outb((c
& 0xfb),base_io
+ 0x29);
2866 for (c
=0;c
< 2;c
++) {
2869 for (k
=0; k
< 16; k
++) {
2872 if (p
->sp
[c
][k
] > 1) {
2873 p
->ultra_map
[c
] |= n
;
2875 if (p
->sp
[c
][k
] == 0) {
2880 p
->async
[c
] = ~(p
->async
[c
]);
2882 if (p
->global_map
[c
] == 0) {
2884 if ((k
& 0x40) != 0)
2885 p
->global_map
[c
] |= 0x20;
2887 p
->global_map
[c
] |= k
;
2888 if ((setupdata
[c
][2] & 0x04) != 0)
2889 p
->global_map
[c
] |= 0x08;
2890 p
->host_id
[c
] = setupdata
[c
][0] & 0x07;
2894 k
= inb(base_io
+ 0x28) & 0x8f;
2896 outb(k
, base_io
+ 0x28);
2897 outb(0x80, base_io
+ 0x41);
2898 outb(0x80, base_io
+ 0x51);
2900 outb(0, base_io
+ 0x41);
2901 outb(0, base_io
+ 0x51);
2903 inb(base_io
+ 0x9b);
2904 inb(base_io
+ 0x97);
2905 inb(base_io
+ 0xdb);
2906 inb(base_io
+ 0xd7);
2907 tmport
= base_io
+ 0x80;
2910 k
= (k
& 0x07) | 0x40;
2917 while ((inb(tmport
) & 0x80) == 0)
2922 tmport
= base_io
+ 0x81;
2925 tmport
= base_io
+ 0x91;
2928 tmport
= base_io
+ 0xc0;
2931 k
= (k
& 0x07) | 0x40;
2938 while ((inb(tmport
) & 0x80) == 0)
2943 tmport
= base_io
+ 0xc1;
2946 tmport
= base_io
+ 0xd1;
2950 printk(KERN_INFO
" Scanning Channel A SCSI Device ...\n");
2951 is885(p
, base_io
+ 0x80, 0);
2952 printk(KERN_INFO
" Scanning Channel B SCSI Device ...\n");
2953 is885(p
, base_io
+ 0xc0, 1);
2955 k
= inb(base_io
+ 0x28) & 0xcf;
2957 outb(k
, base_io
+ 0x28);
2958 k
= inb(base_io
+ 0x1f) | 0x80;
2959 outb(k
, base_io
+ 0x1f);
2960 k
= inb(base_io
+ 0x29) | 0x01;
2961 outb(k
, base_io
+ 0x29);
2963 //printk("atp885: atp_host[0] 0x%p\n", atp_host[0]);
2966 shpnt
->max_lun
= (p
->global_map
[0] & 0x07) + 1;
2967 shpnt
->max_channel
= 1;
2968 shpnt
->this_id
= p
->host_id
[0];
2969 shpnt
->unique_id
= base_io
;
2970 shpnt
->io_port
= base_io
;
2971 shpnt
->n_io_port
= 0xff; /* Number of bytes of I/O space used */
2972 shpnt
->irq
= pdev
->irq
;
2975 error
= pci_read_config_byte(pdev
, 0x49, &host_id
);
2977 printk(KERN_INFO
" ACARD AEC-671X PCI Ultra/W SCSI-2/3 Host Adapter: %d "
2978 "IO:%x, IRQ:%d.\n", count
, base_io
, pdev
->irq
);
2980 atpdev
->ioport
[0] = base_io
;
2981 atpdev
->pciport
[0] = base_io
+ 0x20;
2982 atpdev
->dev_id
= ent
->device
;
2984 atpdev
->host_id
[0] = host_id
;
2985 tmport
= base_io
+ 0x22;
2986 atpdev
->scam_on
= inb(tmport
);
2988 atpdev
->global_map
[0] = inb(tmport
++);
2989 atpdev
->ultra_map
[0] = inw(tmport
);
2991 if (atpdev
->ultra_map
[0] == 0) {
2992 atpdev
->scam_on
= 0x00;
2993 atpdev
->global_map
[0] = 0x20;
2994 atpdev
->ultra_map
[0] = 0xffff;
2997 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
3001 p
= (struct atp_unit
*)&shpnt
->hostdata
;
3003 atpdev
->host
= shpnt
;
3004 atpdev
->pdev
= pdev
;
3005 pci_set_drvdata(pdev
, p
);
3006 memcpy(p
, atpdev
, sizeof(*atpdev
));
3007 if (atp870u_init_tables(shpnt
) < 0)
3010 if (request_irq(pdev
->irq
, atp870u_intr_handle
, IRQF_SHARED
, "atp870i", shpnt
)) {
3011 printk(KERN_ERR
"Unable to allocate IRQ%d for Acard controller.\n", pdev
->irq
);
3015 spin_lock_irqsave(shpnt
->host_lock
, flags
);
3016 if (atpdev
->chip_ver
> 0x07) { /* check if atp876 chip then enable terminator */
3017 tmport
= base_io
+ 0x3e;
3021 tmport
= base_io
+ 0x3a;
3022 k
= (inb(tmport
) & 0xf3) | 0x10;
3024 outb((k
& 0xdf), tmport
);
3029 outb((host_id
| 0x08), tmport
);
3033 while ((inb(tmport
) & 0x80) == 0)
3038 tmport
= base_io
+ 1;
3041 tmport
= base_io
+ 0x11;
3046 tmport
= base_io
+ 0x3a;
3047 outb((inb(tmport
) & 0xef), tmport
);
3049 outb((inb(tmport
) | 0x20), tmport
);
3050 if (atpdev
->chip_ver
== 4)
3054 shpnt
->this_id
= host_id
;
3055 shpnt
->unique_id
= base_io
;
3056 shpnt
->io_port
= base_io
;
3057 shpnt
->n_io_port
= 0x40; /* Number of bytes of I/O space used */
3058 shpnt
->irq
= pdev
->irq
;
3060 spin_unlock_irqrestore(shpnt
->host_lock
, flags
);
3061 if(ent
->device
==ATP885_DEVID
) {
3062 if(!request_region(base_io
, 0xff, "atp870u")) /* Register the IO ports that we use */
3063 goto request_io_fail
;
3064 } else if((ent
->device
==ATP880_DEVID1
)||(ent
->device
==ATP880_DEVID2
)) {
3065 if(!request_region(base_io
, 0x60, "atp870u")) /* Register the IO ports that we use */
3066 goto request_io_fail
;
3068 if(!request_region(base_io
, 0x40, "atp870u")) /* Register the IO ports that we use */
3069 goto request_io_fail
;
3072 if (scsi_add_host(shpnt
, &pdev
->dev
))
3074 scsi_scan_host(shpnt
);
3076 printk("atp870u_prob : exit\n");
3081 printk("atp870u_prob:scsi_add_fail\n");
3082 if(ent
->device
==ATP885_DEVID
) {
3083 release_region(base_io
, 0xff);
3084 } else if((ent
->device
==ATP880_DEVID1
)||(ent
->device
==ATP880_DEVID2
)) {
3085 release_region(base_io
, 0x60);
3087 release_region(base_io
, 0x40);
3090 printk("atp870u_prob:request_io_fail\n");
3091 free_irq(pdev
->irq
, shpnt
);
3093 printk("atp870u_prob:free_table\n");
3094 atp870u_free_tables(shpnt
);
3096 printk("atp870u_prob:unregister\n");
3097 scsi_host_put(shpnt
);
3107 /* The abort command does not leave the device in a clean state where
3108 it is available to be used again. Until this gets worked out, we will
3109 leave it commented out. */
3111 static int atp870u_abort(struct scsi_cmnd
* SCpnt
)
3113 unsigned char j
, k
, c
;
3114 struct scsi_cmnd
*workrequ
;
3115 unsigned int tmport
;
3116 struct atp_unit
*dev
;
3117 struct Scsi_Host
*host
;
3118 host
= SCpnt
->device
->host
;
3120 dev
= (struct atp_unit
*)&host
->hostdata
;
3121 c
= scmd_channel(SCpnt
);
3122 printk(" atp870u: abort Channel = %x \n", c
);
3123 printk("working=%x last_cmd=%x ", dev
->working
[c
], dev
->last_cmd
[c
]);
3124 printk(" quhdu=%x quendu=%x ", dev
->quhd
[c
], dev
->quend
[c
]);
3125 tmport
= dev
->ioport
[c
];
3126 for (j
= 0; j
< 0x18; j
++) {
3127 printk(" r%2x=%2x", j
, inb(tmport
++));
3130 printk(" r1c=%2x", inb(tmport
));
3132 printk(" r1f=%2x in_snd=%2x ", inb(tmport
), dev
->in_snd
[c
]);
3133 tmport
= dev
->pciport
[c
];
3134 printk(" d00=%2x", inb(tmport
));
3136 printk(" d02=%2x", inb(tmport
));
3138 if (dev
->id
[c
][j
].curr_req
!= NULL
) {
3139 workrequ
= dev
->id
[c
][j
].curr_req
;
3140 printk("\n que cdb= ");
3141 for (k
=0; k
< workrequ
->cmd_len
; k
++) {
3142 printk(" %2x ",workrequ
->cmnd
[k
]);
3144 printk(" last_lenu= %x ",(unsigned int)dev
->id
[c
][j
].last_len
);
3150 static const char *atp870u_info(struct Scsi_Host
*notused
)
3152 static char buffer
[128];
3154 strcpy(buffer
, "ACARD AEC-6710/6712/67160 PCI Ultra/W/LVD SCSI-3 Adapter Driver V2.6+ac ");
3159 #define BLS buffer + len + size
3160 static int atp870u_proc_info(struct Scsi_Host
*HBAptr
, char *buffer
,
3161 char **start
, off_t offset
, int length
, int inout
)
3163 static u8 buff
[512];
3172 memset(buff
, 0, sizeof(buff
));
3173 size
+= sprintf(BLS
, "ACARD AEC-671X Driver Version: 2.6+ac\n");
3178 size
+= sprintf(BLS
, "\n");
3179 size
+= sprintf(BLS
, "Adapter Configuration:\n");
3180 size
+= sprintf(BLS
, " Base IO: %#.4lx\n", HBAptr
->io_port
);
3181 size
+= sprintf(BLS
, " IRQ: %d\n", HBAptr
->irq
);
3185 *start
= buffer
+ (offset
- begin
); /* Start of wanted data */
3186 len
-= (offset
- begin
); /* Start slop */
3188 len
= length
; /* Ending slop */
3194 static int atp870u_biosparam(struct scsi_device
*disk
, struct block_device
*dev
,
3195 sector_t capacity
, int *ip
)
3197 int heads
, sectors
, cylinders
;
3201 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
3202 if (cylinders
> 1024) {
3205 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
3214 static void atp870u_remove (struct pci_dev
*pdev
)
3216 struct atp_unit
*devext
= pci_get_drvdata(pdev
);
3217 struct Scsi_Host
*pshost
= devext
->host
;
3220 scsi_remove_host(pshost
);
3221 printk(KERN_INFO
"free_irq : %d\n",pshost
->irq
);
3222 free_irq(pshost
->irq
, pshost
);
3223 release_region(pshost
->io_port
, pshost
->n_io_port
);
3224 printk(KERN_INFO
"atp870u_free_tables : %p\n",pshost
);
3225 atp870u_free_tables(pshost
);
3226 printk(KERN_INFO
"scsi_host_put : %p\n",pshost
);
3227 scsi_host_put(pshost
);
3228 printk(KERN_INFO
"pci_set_drvdata : %p\n",pdev
);
3229 pci_set_drvdata(pdev
, NULL
);
3231 MODULE_LICENSE("GPL");
3233 static struct scsi_host_template atp870u_template
= {
3234 .module
= THIS_MODULE
,
3235 .name
= "atp870u" /* name */,
3236 .proc_name
= "atp870u",
3237 .proc_info
= atp870u_proc_info
,
3238 .info
= atp870u_info
/* info */,
3239 .queuecommand
= atp870u_queuecommand
/* queuecommand */,
3240 .eh_abort_handler
= atp870u_abort
/* abort */,
3241 .bios_param
= atp870u_biosparam
/* biosparm */,
3242 .can_queue
= qcnt
/* can_queue */,
3243 .this_id
= 7 /* SCSI ID */,
3244 .sg_tablesize
= ATP870U_SCATTER
/*SG_ALL*/ /*SG_NONE*/,
3245 .cmd_per_lun
= ATP870U_CMDLUN
/* commands per lun */,
3246 .use_clustering
= ENABLE_CLUSTERING
,
3247 .max_sectors
= ATP870U_MAX_SECTORS
,
3250 static struct pci_device_id atp870u_id_table
[] = {
3251 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP885_DEVID
) },
3252 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP880_DEVID1
) },
3253 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP880_DEVID2
) },
3254 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7610
) },
3255 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612UW
) },
3256 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612U
) },
3257 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612S
) },
3258 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612D
) },
3259 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612SUW
) },
3260 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_8060
) },
3264 MODULE_DEVICE_TABLE(pci
, atp870u_id_table
);
3266 static struct pci_driver atp870u_driver
= {
3267 .id_table
= atp870u_id_table
,
3269 .probe
= atp870u_probe
,
3270 .remove
= __devexit_p(atp870u_remove
),
3273 static int __init
atp870u_init(void)
3276 printk("atp870u_init: Entry\n");
3278 return pci_register_driver(&atp870u_driver
);
3281 static void __exit
atp870u_exit(void)
3284 printk("atp870u_exit: Entry\n");
3286 pci_unregister_driver(&atp870u_driver
);
3289 static void tscam_885(void)
3293 for (i
= 0; i
< 0x2; i
++) {
3301 static void is885(struct atp_unit
*dev
, unsigned int wkport
,unsigned char c
)
3303 unsigned int tmport
;
3304 unsigned char i
, j
, k
, rmb
, n
, lvdmode
;
3305 unsigned short int m
;
3306 static unsigned char mbuf
[512];
3307 static unsigned char satn
[9] = {0, 0, 0, 0, 0, 0, 0, 6, 6};
3308 static unsigned char inqd
[9] = {0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6};
3309 static unsigned char synn
[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
3310 unsigned char synu
[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
3311 static unsigned char synw
[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
3312 unsigned char synuw
[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
3313 static unsigned char wide
[6] = {0x80, 1, 2, 3, 1, 0};
3314 static unsigned char u3
[9] = { 0x80,1,6,4,0x09,00,0x0e,0x01,0x02 };
3316 lvdmode
=inb(wkport
+ 0x1b) >> 7;
3318 for (i
= 0; i
< 16; i
++) {
3321 if ((m
& dev
->active_id
[c
]) != 0) {
3324 if (i
== dev
->host_id
[c
]) {
3325 printk(KERN_INFO
" ID: %2d Host Adapter\n", dev
->host_id
[c
]);
3328 tmport
= wkport
+ 0x1b;
3330 tmport
= wkport
+ 0x01;
3331 outb(0x08, tmport
++);
3332 outb(0x7f, tmport
++);
3333 outb(satn
[0], tmport
++);
3334 outb(satn
[1], tmport
++);
3335 outb(satn
[2], tmport
++);
3336 outb(satn
[3], tmport
++);
3337 outb(satn
[4], tmport
++);
3338 outb(satn
[5], tmport
++);
3342 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3345 outb(satn
[6], tmport
++);
3346 outb(satn
[7], tmport
++);
3348 if ((j
& 0x08) != 0) {
3349 j
= (j
& 0x07) | 0x40;
3353 outb(satn
[8], tmport
);
3356 while ((inb(tmport
) & 0x80) == 0x00)
3359 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3362 while (inb(tmport
) != 0x8e)
3364 dev
->active_id
[c
] |= m
;
3366 tmport
= wkport
+ 0x10;
3368 tmport
= wkport
+ 0x14;
3372 tmport
= wkport
+ 0x18;
3375 while ((inb(tmport
) & 0x80) == 0x00)
3380 tmport
= wkport
+ 0x10;
3385 tmport
= wkport
+ 0x03;
3386 outb(inqd
[0], tmport
++);
3387 outb(inqd
[1], tmport
++);
3388 outb(inqd
[2], tmport
++);
3389 outb(inqd
[3], tmport
++);
3390 outb(inqd
[4], tmport
++);
3391 outb(inqd
[5], tmport
);
3395 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3397 outb(inqd
[6], tmport
++);
3398 outb(inqd
[7], tmport
++);
3400 outb(inqd
[8], tmport
);
3402 while ((inb(tmport
) & 0x80) == 0x00)
3405 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3408 while (inb(tmport
) != 0x8e)
3410 tmport
= wkport
+ 0x1b;
3412 tmport
= wkport
+ 0x18;
3418 if ((k
& 0x01) != 0) {
3420 mbuf
[j
++] = inb(tmport
);
3424 if ((k
& 0x80) == 0) {
3432 tmport
= wkport
+ 0x10;
3441 while ((inb(tmport
) & 0x80) == 0x00)
3444 if (inb(tmport
) != 0x16) {
3449 printk( KERN_INFO
" ID: %2d %s\n", i
, &mbuf
[8]);
3450 dev
->id
[c
][i
].devtype
= mbuf
[0];
3453 if ((mbuf
[7] & 0x60) == 0) {
3456 if ((i
< 8) && ((dev
->global_map
[c
] & 0x20) == 0)) {
3462 if (dev
->sp
[c
][i
] != 0x04) { // force u2
3466 tmport
= wkport
+ 0x1b;
3468 tmport
= wkport
+ 0x03;
3469 outb(satn
[0], tmport
++);
3470 outb(satn
[1], tmport
++);
3471 outb(satn
[2], tmport
++);
3472 outb(satn
[3], tmport
++);
3473 outb(satn
[4], tmport
++);
3474 outb(satn
[5], tmport
++);
3478 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3480 outb(satn
[6], tmport
++);
3481 outb(satn
[7], tmport
++);
3483 outb(satn
[8], tmport
);
3486 while ((inb(tmport
) & 0x80) == 0x00)
3489 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3492 while (inb(tmport
) != 0x8e)
3496 tmport
= wkport
+ 0x14;
3502 while ((inb(tmport
) & 0x80) == 0) {
3503 if ((inb(tmport
) & 0x01) != 0) {
3505 outb(u3
[j
++], tmport
);
3511 while ((inb(tmport
) & 0x80) == 0x00)
3513 j
= inb(tmport
) & 0x0f;
3525 tmport
= wkport
+ 0x18;
3528 while ((inb(tmport
) & 0x80) == 0) {
3529 if ((inb(tmport
) & 0x01) != 0) {
3537 j
= inb(tmport
) & 0x0f;
3549 tmport
= wkport
+ 0x14;
3557 if ((j
& 0x01) != 0) {
3559 mbuf
[k
++] = inb(tmport
);
3563 if ((j
& 0x80) == 0x00) {
3567 j
= inb(tmport
) & 0x0f;
3579 tmport
= wkport
+ 0x10;
3581 tmport
= wkport
+ 0x14;
3586 while ((inb(tmport
) & 0x80) == 0x00);
3595 if (mbuf
[0] != 0x01) {
3598 if (mbuf
[1] != 0x06) {
3601 if (mbuf
[2] != 0x04) {
3604 if (mbuf
[3] == 0x09) {
3607 dev
->wide_id
[c
] |= m
;
3608 dev
->id
[c
][i
].devsp
= 0xce;
3610 printk("dev->id[%2d][%2d].devsp = %2x\n",c
,i
,dev
->id
[c
][i
].devsp
);
3615 tmport
= wkport
+ 0x1b;
3617 tmport
= wkport
+ 0x03;
3618 outb(satn
[0], tmport
++);
3619 outb(satn
[1], tmport
++);
3620 outb(satn
[2], tmport
++);
3621 outb(satn
[3], tmport
++);
3622 outb(satn
[4], tmport
++);
3623 outb(satn
[5], tmport
++);
3627 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3629 outb(satn
[6], tmport
++);
3630 outb(satn
[7], tmport
++);
3632 outb(satn
[8], tmport
);
3635 while ((inb(tmport
) & 0x80) == 0x00)
3638 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3641 while (inb(tmport
) != 0x8e)
3645 tmport
= wkport
+ 0x14;
3651 while ((inb(tmport
) & 0x80) == 0) {
3652 if ((inb(tmport
) & 0x01) != 0) {
3654 outb(wide
[j
++], tmport
);
3660 while ((inb(tmport
) & 0x80) == 0x00)
3662 j
= inb(tmport
) & 0x0f;
3674 tmport
= wkport
+ 0x18;
3677 while ((inb(tmport
) & 0x80) == 0) {
3678 if ((inb(tmport
) & 0x01) != 0) {
3686 j
= inb(tmport
) & 0x0f;
3698 tmport
= wkport
+ 0x14;
3706 if ((j
& 0x01) != 0) {
3708 mbuf
[k
++] = inb(tmport
);
3712 if ((j
& 0x80) == 0x00) {
3716 j
= inb(tmport
) & 0x0f;
3728 tmport
= wkport
+ 0x10;
3730 tmport
= wkport
+ 0x14;
3735 while ((inb(tmport
) & 0x80) == 0x00)
3745 if (mbuf
[0] != 0x01) {
3748 if (mbuf
[1] != 0x02) {
3751 if (mbuf
[2] != 0x03) {
3754 if (mbuf
[3] != 0x01) {
3759 dev
->wide_id
[c
] |= m
;
3761 if ((dev
->id
[c
][i
].devtype
== 0x00) || (dev
->id
[c
][i
].devtype
== 0x07) ||
3762 ((dev
->id
[c
][i
].devtype
== 0x05) && ((n
& 0x10) != 0))) {
3765 if ((dev
->async
[c
] & m
) != 0) {
3771 if (dev
->sp
[c
][i
] == 0x02) {
3775 if (dev
->sp
[c
][i
] >= 0x03) {
3780 tmport
= wkport
+ 0x1b;
3782 if ((m
& dev
->wide_id
[c
]) != 0) {
3786 tmport
= wkport
+ 0x03;
3787 outb(satn
[0], tmport
++);
3788 outb(satn
[1], tmport
++);
3789 outb(satn
[2], tmport
++);
3790 outb(satn
[3], tmport
++);
3791 outb(satn
[4], tmport
++);
3792 outb(satn
[5], tmport
++);
3796 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3798 outb(satn
[6], tmport
++);
3799 outb(satn
[7], tmport
++);
3801 outb(satn
[8], tmport
);
3804 while ((inb(tmport
) & 0x80) == 0x00)
3807 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3810 while (inb(tmport
) != 0x8e)
3814 tmport
= wkport
+ 0x14;
3820 while ((inb(tmport
) & 0x80) == 0) {
3821 if ((inb(tmport
) & 0x01) != 0) {
3823 if ((m
& dev
->wide_id
[c
]) != 0) {
3824 if ((m
& dev
->ultra_map
[c
]) != 0) {
3825 outb(synuw
[j
++], tmport
);
3827 outb(synw
[j
++], tmport
);
3830 if ((m
& dev
->ultra_map
[c
]) != 0) {
3831 outb(synu
[j
++], tmport
);
3833 outb(synn
[j
++], tmport
);
3840 while ((inb(tmport
) & 0x80) == 0x00)
3842 j
= inb(tmport
) & 0x0f;
3854 tmport
= wkport
+ 0x18;
3857 while ((inb(tmport
) & 0x80) == 0x00) {
3858 if ((inb(tmport
) & 0x01) != 0x00) {
3882 tmport
= wkport
+ 0x14;
3890 if ((j
& 0x01) != 0x00) {
3892 mbuf
[k
++] = inb(tmport
);
3896 if ((j
& 0x80) == 0x00) {
3900 while ((inb(tmport
) & 0x80) == 0x00);
3917 tmport
= wkport
+ 0x10;
3920 tmport
= wkport
+ 0x14;
3925 while ((inb(tmport
) & 0x80) == 0x00)
3932 if (mbuf
[0] != 0x01) {
3935 if (mbuf
[1] != 0x03) {
3938 if (mbuf
[4] == 0x00) {
3941 if (mbuf
[3] > 0x64) {
3944 if (mbuf
[4] > 0x0e) {
3947 dev
->id
[c
][i
].devsp
= mbuf
[4];
3948 if (mbuf
[3] < 0x0c){
3952 if ((mbuf
[3] < 0x0d) && (rmb
== 0)) {
3956 if (mbuf
[3] < 0x1a) {
3960 if (mbuf
[3] < 0x33) {
3964 if (mbuf
[3] < 0x4c) {
3970 dev
->id
[c
][i
].devsp
= (dev
->id
[c
][i
].devsp
& 0x0f) | j
;
3972 printk("dev->id[%2d][%2d].devsp = %2x\n",c
,i
,dev
->id
[c
][i
].devsp
);
3975 tmport
= wkport
+ 0x16;
3979 module_init(atp870u_init
);
3980 module_exit(atp870u_exit
);