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
, struct pt_regs
*regs
)
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 atp_dev
, *p
;
2629 unsigned char setupdata
[2][16];
2632 if (pci_enable_device(pdev
))
2635 if (!pci_set_dma_mask(pdev
, DMA_32BIT_MASK
)) {
2636 printk(KERN_INFO
"atp870u: use 32bit DMA mask.\n");
2638 printk(KERN_ERR
"atp870u: DMA mask required but not available.\n");
2642 memset(&atp_dev
, 0, sizeof atp_dev
);
2644 * It's probably easier to weed out some revisions like
2645 * this than via the PCI device table
2647 if (ent
->device
== PCI_DEVICE_ID_ARTOP_AEC7610
) {
2648 error
= pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &atp_dev
.chip_ver
);
2649 if (atp_dev
.chip_ver
< 2)
2653 switch (ent
->device
) {
2654 case PCI_DEVICE_ID_ARTOP_AEC7612UW
:
2655 case PCI_DEVICE_ID_ARTOP_AEC7612SUW
:
2659 atp_dev
.chip_ver
= 0x04;
2663 base_io
= pci_resource_start(pdev
, 0);
2664 base_io
&= 0xfffffff8;
2666 if ((ent
->device
== ATP880_DEVID1
)||(ent
->device
== ATP880_DEVID2
)) {
2667 error
= pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &atp_dev
.chip_ver
);
2668 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, 0x80);//JCC082803
2670 host_id
= inb(base_io
+ 0x39);
2673 printk(KERN_INFO
" ACARD AEC-67160 PCI Ultra3 LVD Host Adapter: %d"
2674 " IO:%x, IRQ:%d.\n", count
, base_io
, pdev
->irq
);
2675 atp_dev
.ioport
[0] = base_io
+ 0x40;
2676 atp_dev
.pciport
[0] = base_io
+ 0x28;
2677 atp_dev
.dev_id
= ent
->device
;
2678 atp_dev
.host_id
[0] = host_id
;
2680 tmport
= base_io
+ 0x22;
2681 atp_dev
.scam_on
= inb(tmport
);
2683 atp_dev
.global_map
[0] = inb(tmport
);
2685 atp_dev
.ultra_map
[0] = inw(tmport
);
2693 outw(n
, base_io
+ 0x34);
2695 if (inb(base_io
+ 0x30) == 0xff)
2698 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x30);
2699 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x31);
2700 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x32);
2701 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x33);
2702 outw(n
, base_io
+ 0x34);
2704 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x30);
2705 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x31);
2706 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x32);
2707 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x33);
2708 outw(n
, base_io
+ 0x34);
2710 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x30);
2711 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x31);
2712 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x32);
2713 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x33);
2714 outw(n
, base_io
+ 0x34);
2716 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x30);
2717 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x31);
2718 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x32);
2719 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x33);
2723 outw(0, base_io
+ 0x34);
2724 atp_dev
.ultra_map
[0] = 0;
2725 atp_dev
.async
[0] = 0;
2726 for (k
= 0; k
< 16; k
++) {
2729 if (atp_dev
.sp
[0][k
] > 1) {
2730 atp_dev
.ultra_map
[0] |= n
;
2732 if (atp_dev
.sp
[0][k
] == 0)
2733 atp_dev
.async
[0] |= n
;
2736 atp_dev
.async
[0] = ~(atp_dev
.async
[0]);
2737 outb(atp_dev
.global_map
[0], base_io
+ 0x35);
2739 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
2743 p
= (struct atp_unit
*)&shpnt
->hostdata
;
2745 atp_dev
.host
= shpnt
;
2746 atp_dev
.pdev
= pdev
;
2747 pci_set_drvdata(pdev
, p
);
2748 memcpy(p
, &atp_dev
, sizeof atp_dev
);
2749 if (atp870u_init_tables(shpnt
) < 0) {
2750 printk(KERN_ERR
"Unable to allocate tables for Acard controller\n");
2754 if (request_irq(pdev
->irq
, atp870u_intr_handle
, SA_SHIRQ
, "atp880i", shpnt
)) {
2755 printk(KERN_ERR
"Unable to allocate IRQ%d for Acard controller.\n", pdev
->irq
);
2759 spin_lock_irqsave(shpnt
->host_lock
, flags
);
2760 tmport
= base_io
+ 0x38;
2761 k
= inb(tmport
) & 0x80;
2768 tmport
= base_io
+ 0x5b;
2772 tmport
= base_io
+ 0x40;
2773 outb((host_id
| 0x08), tmport
);
2777 while ((inb(tmport
) & 0x80) == 0)
2781 tmport
= base_io
+ 0x41;
2784 tmport
= base_io
+ 0x51;
2789 tmport
= base_io
+ 0x38;
2792 shpnt
->this_id
= host_id
;
2793 shpnt
->unique_id
= base_io
;
2794 shpnt
->io_port
= base_io
;
2795 shpnt
->n_io_port
= 0x60; /* Number of bytes of I/O space used */
2796 shpnt
->irq
= pdev
->irq
;
2797 } else if (ent
->device
== ATP885_DEVID
) {
2798 printk(KERN_INFO
" ACARD AEC-67162 PCI Ultra3 LVD Host Adapter: IO:%x, IRQ:%d.\n"
2799 , base_io
, pdev
->irq
);
2801 atp_dev
.pdev
= pdev
;
2802 atp_dev
.dev_id
= ent
->device
;
2803 atp_dev
.baseport
= base_io
;
2804 atp_dev
.ioport
[0] = base_io
+ 0x80;
2805 atp_dev
.ioport
[1] = base_io
+ 0xc0;
2806 atp_dev
.pciport
[0] = base_io
+ 0x40;
2807 atp_dev
.pciport
[1] = base_io
+ 0x50;
2809 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
2813 p
= (struct atp_unit
*)&shpnt
->hostdata
;
2815 atp_dev
.host
= shpnt
;
2816 atp_dev
.pdev
= pdev
;
2817 pci_set_drvdata(pdev
, p
);
2818 memcpy(p
, &atp_dev
, sizeof(struct atp_unit
));
2819 if (atp870u_init_tables(shpnt
) < 0)
2823 printk("request_irq() shpnt %p hostdata %p\n", shpnt
, p
);
2825 if (request_irq(pdev
->irq
, atp870u_intr_handle
, SA_SHIRQ
, "atp870u", shpnt
)) {
2826 printk(KERN_ERR
"Unable to allocate IRQ for Acard controller.\n");
2830 spin_lock_irqsave(shpnt
->host_lock
, flags
);
2832 c
=inb(base_io
+ 0x29);
2833 outb((c
| 0x04),base_io
+ 0x29);
2840 outw(n
,base_io
+ 0x3c);
2841 if (inl(base_io
+ 0x38) == 0xffffffff) {
2844 for (m
=0; m
< 2; m
++) {
2845 p
->global_map
[m
]= 0;
2846 for (k
=0; k
< 4; k
++) {
2847 outw(n
++,base_io
+ 0x3c);
2848 ((unsigned long *)&setupdata
[m
][0])[k
]=inl(base_io
+ 0x38);
2850 for (k
=0; k
< 4; k
++) {
2851 outw(n
++,base_io
+ 0x3c);
2852 ((unsigned long *)&p
->sp
[m
][0])[k
]=inl(base_io
+ 0x38);
2859 printk( "Flash Read OK\n");
2861 c
=inb(base_io
+ 0x29);
2862 outb((c
& 0xfb),base_io
+ 0x29);
2863 for (c
=0;c
< 2;c
++) {
2866 for (k
=0; k
< 16; k
++) {
2869 if (p
->sp
[c
][k
] > 1) {
2870 p
->ultra_map
[c
] |= n
;
2872 if (p
->sp
[c
][k
] == 0) {
2877 p
->async
[c
] = ~(p
->async
[c
]);
2879 if (p
->global_map
[c
] == 0) {
2881 if ((k
& 0x40) != 0)
2882 p
->global_map
[c
] |= 0x20;
2884 p
->global_map
[c
] |= k
;
2885 if ((setupdata
[c
][2] & 0x04) != 0)
2886 p
->global_map
[c
] |= 0x08;
2887 p
->host_id
[c
] = setupdata
[c
][0] & 0x07;
2891 k
= inb(base_io
+ 0x28) & 0x8f;
2893 outb(k
, base_io
+ 0x28);
2894 outb(0x80, base_io
+ 0x41);
2895 outb(0x80, base_io
+ 0x51);
2897 outb(0, base_io
+ 0x41);
2898 outb(0, base_io
+ 0x51);
2900 inb(base_io
+ 0x9b);
2901 inb(base_io
+ 0x97);
2902 inb(base_io
+ 0xdb);
2903 inb(base_io
+ 0xd7);
2904 tmport
= base_io
+ 0x80;
2907 k
= (k
& 0x07) | 0x40;
2914 while ((inb(tmport
) & 0x80) == 0)
2919 tmport
= base_io
+ 0x81;
2922 tmport
= base_io
+ 0x91;
2925 tmport
= base_io
+ 0xc0;
2928 k
= (k
& 0x07) | 0x40;
2935 while ((inb(tmport
) & 0x80) == 0)
2940 tmport
= base_io
+ 0xc1;
2943 tmport
= base_io
+ 0xd1;
2947 printk(KERN_INFO
" Scanning Channel A SCSI Device ...\n");
2948 is885(p
, base_io
+ 0x80, 0);
2949 printk(KERN_INFO
" Scanning Channel B SCSI Device ...\n");
2950 is885(p
, base_io
+ 0xc0, 1);
2952 k
= inb(base_io
+ 0x28) & 0xcf;
2954 outb(k
, base_io
+ 0x28);
2955 k
= inb(base_io
+ 0x1f) | 0x80;
2956 outb(k
, base_io
+ 0x1f);
2957 k
= inb(base_io
+ 0x29) | 0x01;
2958 outb(k
, base_io
+ 0x29);
2960 //printk("atp885: atp_host[0] 0x%p\n", atp_host[0]);
2963 shpnt
->max_lun
= (p
->global_map
[0] & 0x07) + 1;
2964 shpnt
->max_channel
= 1;
2965 shpnt
->this_id
= p
->host_id
[0];
2966 shpnt
->unique_id
= base_io
;
2967 shpnt
->io_port
= base_io
;
2968 shpnt
->n_io_port
= 0xff; /* Number of bytes of I/O space used */
2969 shpnt
->irq
= pdev
->irq
;
2972 error
= pci_read_config_byte(pdev
, 0x49, &host_id
);
2974 printk(KERN_INFO
" ACARD AEC-671X PCI Ultra/W SCSI-2/3 Host Adapter: %d "
2975 "IO:%x, IRQ:%d.\n", count
, base_io
, pdev
->irq
);
2977 atp_dev
.ioport
[0] = base_io
;
2978 atp_dev
.pciport
[0] = base_io
+ 0x20;
2979 atp_dev
.dev_id
= ent
->device
;
2981 atp_dev
.host_id
[0] = host_id
;
2982 tmport
= base_io
+ 0x22;
2983 atp_dev
.scam_on
= inb(tmport
);
2985 atp_dev
.global_map
[0] = inb(tmport
++);
2986 atp_dev
.ultra_map
[0] = inw(tmport
);
2988 if (atp_dev
.ultra_map
[0] == 0) {
2989 atp_dev
.scam_on
= 0x00;
2990 atp_dev
.global_map
[0] = 0x20;
2991 atp_dev
.ultra_map
[0] = 0xffff;
2994 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
2998 p
= (struct atp_unit
*)&shpnt
->hostdata
;
3000 atp_dev
.host
= shpnt
;
3001 atp_dev
.pdev
= pdev
;
3002 pci_set_drvdata(pdev
, p
);
3003 memcpy(p
, &atp_dev
, sizeof atp_dev
);
3004 if (atp870u_init_tables(shpnt
) < 0)
3007 if (request_irq(pdev
->irq
, atp870u_intr_handle
, SA_SHIRQ
, "atp870i", shpnt
)) {
3008 printk(KERN_ERR
"Unable to allocate IRQ%d for Acard controller.\n", pdev
->irq
);
3012 spin_lock_irqsave(shpnt
->host_lock
, flags
);
3013 if (atp_dev
.chip_ver
> 0x07) { /* check if atp876 chip then enable terminator */
3014 tmport
= base_io
+ 0x3e;
3018 tmport
= base_io
+ 0x3a;
3019 k
= (inb(tmport
) & 0xf3) | 0x10;
3021 outb((k
& 0xdf), tmport
);
3026 outb((host_id
| 0x08), tmport
);
3030 while ((inb(tmport
) & 0x80) == 0)
3035 tmport
= base_io
+ 1;
3038 tmport
= base_io
+ 0x11;
3043 tmport
= base_io
+ 0x3a;
3044 outb((inb(tmport
) & 0xef), tmport
);
3046 outb((inb(tmport
) | 0x20), tmport
);
3047 if (atp_dev
.chip_ver
== 4)
3051 shpnt
->this_id
= host_id
;
3052 shpnt
->unique_id
= base_io
;
3053 shpnt
->io_port
= base_io
;
3054 shpnt
->n_io_port
= 0x40; /* Number of bytes of I/O space used */
3055 shpnt
->irq
= pdev
->irq
;
3057 spin_unlock_irqrestore(shpnt
->host_lock
, flags
);
3058 if(ent
->device
==ATP885_DEVID
) {
3059 if(!request_region(base_io
, 0xff, "atp870u")) /* Register the IO ports that we use */
3060 goto request_io_fail
;
3061 } else if((ent
->device
==ATP880_DEVID1
)||(ent
->device
==ATP880_DEVID2
)) {
3062 if(!request_region(base_io
, 0x60, "atp870u")) /* Register the IO ports that we use */
3063 goto request_io_fail
;
3065 if(!request_region(base_io
, 0x40, "atp870u")) /* Register the IO ports that we use */
3066 goto request_io_fail
;
3069 if (scsi_add_host(shpnt
, &pdev
->dev
))
3071 scsi_scan_host(shpnt
);
3073 printk("atp870u_prob : exit\n");
3078 printk("atp870u_prob:scsi_add_fail\n");
3079 if(ent
->device
==ATP885_DEVID
) {
3080 release_region(base_io
, 0xff);
3081 } else if((ent
->device
==ATP880_DEVID1
)||(ent
->device
==ATP880_DEVID2
)) {
3082 release_region(base_io
, 0x60);
3084 release_region(base_io
, 0x40);
3087 printk("atp870u_prob:request_io_fail\n");
3088 free_irq(pdev
->irq
, shpnt
);
3090 printk("atp870u_prob:free_table\n");
3091 atp870u_free_tables(shpnt
);
3093 printk("atp870u_prob:unregister\n");
3094 scsi_host_put(shpnt
);
3098 /* The abort command does not leave the device in a clean state where
3099 it is available to be used again. Until this gets worked out, we will
3100 leave it commented out. */
3102 static int atp870u_abort(struct scsi_cmnd
* SCpnt
)
3104 unsigned char j
, k
, c
;
3105 struct scsi_cmnd
*workrequ
;
3106 unsigned int tmport
;
3107 struct atp_unit
*dev
;
3108 struct Scsi_Host
*host
;
3109 host
= SCpnt
->device
->host
;
3111 dev
= (struct atp_unit
*)&host
->hostdata
;
3112 c
= scmd_channel(SCpnt
);
3113 printk(" atp870u: abort Channel = %x \n", c
);
3114 printk("working=%x last_cmd=%x ", dev
->working
[c
], dev
->last_cmd
[c
]);
3115 printk(" quhdu=%x quendu=%x ", dev
->quhd
[c
], dev
->quend
[c
]);
3116 tmport
= dev
->ioport
[c
];
3117 for (j
= 0; j
< 0x18; j
++) {
3118 printk(" r%2x=%2x", j
, inb(tmport
++));
3121 printk(" r1c=%2x", inb(tmport
));
3123 printk(" r1f=%2x in_snd=%2x ", inb(tmport
), dev
->in_snd
[c
]);
3124 tmport
= dev
->pciport
[c
];
3125 printk(" d00=%2x", inb(tmport
));
3127 printk(" d02=%2x", inb(tmport
));
3129 if (dev
->id
[c
][j
].curr_req
!= NULL
) {
3130 workrequ
= dev
->id
[c
][j
].curr_req
;
3131 printk("\n que cdb= ");
3132 for (k
=0; k
< workrequ
->cmd_len
; k
++) {
3133 printk(" %2x ",workrequ
->cmnd
[k
]);
3135 printk(" last_lenu= %x ",(unsigned int)dev
->id
[c
][j
].last_len
);
3141 static const char *atp870u_info(struct Scsi_Host
*notused
)
3143 static char buffer
[128];
3145 strcpy(buffer
, "ACARD AEC-6710/6712/67160 PCI Ultra/W/LVD SCSI-3 Adapter Driver V2.6+ac ");
3150 #define BLS buffer + len + size
3151 static int atp870u_proc_info(struct Scsi_Host
*HBAptr
, char *buffer
,
3152 char **start
, off_t offset
, int length
, int inout
)
3154 static u8 buff
[512];
3163 memset(buff
, 0, sizeof(buff
));
3164 size
+= sprintf(BLS
, "ACARD AEC-671X Driver Version: 2.6+ac\n");
3169 size
+= sprintf(BLS
, "\n");
3170 size
+= sprintf(BLS
, "Adapter Configuration:\n");
3171 size
+= sprintf(BLS
, " Base IO: %#.4lx\n", HBAptr
->io_port
);
3172 size
+= sprintf(BLS
, " IRQ: %d\n", HBAptr
->irq
);
3176 *start
= buffer
+ (offset
- begin
); /* Start of wanted data */
3177 len
-= (offset
- begin
); /* Start slop */
3179 len
= length
; /* Ending slop */
3185 static int atp870u_biosparam(struct scsi_device
*disk
, struct block_device
*dev
,
3186 sector_t capacity
, int *ip
)
3188 int heads
, sectors
, cylinders
;
3192 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
3193 if (cylinders
> 1024) {
3196 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
3205 static void atp870u_remove (struct pci_dev
*pdev
)
3207 struct atp_unit
*devext
= pci_get_drvdata(pdev
);
3208 struct Scsi_Host
*pshost
= devext
->host
;
3211 scsi_remove_host(pshost
);
3212 printk(KERN_INFO
"free_irq : %d\n",pshost
->irq
);
3213 free_irq(pshost
->irq
, pshost
);
3214 release_region(pshost
->io_port
, pshost
->n_io_port
);
3215 printk(KERN_INFO
"atp870u_free_tables : %p\n",pshost
);
3216 atp870u_free_tables(pshost
);
3217 printk(KERN_INFO
"scsi_host_put : %p\n",pshost
);
3218 scsi_host_put(pshost
);
3219 printk(KERN_INFO
"pci_set_drvdata : %p\n",pdev
);
3220 pci_set_drvdata(pdev
, NULL
);
3222 MODULE_LICENSE("GPL");
3224 static struct scsi_host_template atp870u_template
= {
3225 .module
= THIS_MODULE
,
3226 .name
= "atp870u" /* name */,
3227 .proc_name
= "atp870u",
3228 .proc_info
= atp870u_proc_info
,
3229 .info
= atp870u_info
/* info */,
3230 .queuecommand
= atp870u_queuecommand
/* queuecommand */,
3231 .eh_abort_handler
= atp870u_abort
/* abort */,
3232 .bios_param
= atp870u_biosparam
/* biosparm */,
3233 .can_queue
= qcnt
/* can_queue */,
3234 .this_id
= 7 /* SCSI ID */,
3235 .sg_tablesize
= ATP870U_SCATTER
/*SG_ALL*/ /*SG_NONE*/,
3236 .cmd_per_lun
= ATP870U_CMDLUN
/* commands per lun */,
3237 .use_clustering
= ENABLE_CLUSTERING
,
3238 .max_sectors
= ATP870U_MAX_SECTORS
,
3241 static struct pci_device_id atp870u_id_table
[] = {
3242 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP885_DEVID
) },
3243 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP880_DEVID1
) },
3244 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP880_DEVID2
) },
3245 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7610
) },
3246 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612UW
) },
3247 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612U
) },
3248 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612S
) },
3249 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612D
) },
3250 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612SUW
) },
3251 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_8060
) },
3255 MODULE_DEVICE_TABLE(pci
, atp870u_id_table
);
3257 static struct pci_driver atp870u_driver
= {
3258 .id_table
= atp870u_id_table
,
3260 .probe
= atp870u_probe
,
3261 .remove
= __devexit_p(atp870u_remove
),
3264 static int __init
atp870u_init(void)
3267 printk("atp870u_init: Entry\n");
3269 return pci_register_driver(&atp870u_driver
);
3272 static void __exit
atp870u_exit(void)
3275 printk("atp870u_exit: Entry\n");
3277 pci_unregister_driver(&atp870u_driver
);
3280 static void tscam_885(void)
3284 for (i
= 0; i
< 0x2; i
++) {
3292 static void is885(struct atp_unit
*dev
, unsigned int wkport
,unsigned char c
)
3294 unsigned int tmport
;
3295 unsigned char i
, j
, k
, rmb
, n
, lvdmode
;
3296 unsigned short int m
;
3297 static unsigned char mbuf
[512];
3298 static unsigned char satn
[9] = {0, 0, 0, 0, 0, 0, 0, 6, 6};
3299 static unsigned char inqd
[9] = {0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6};
3300 static unsigned char synn
[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
3301 unsigned char synu
[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
3302 static unsigned char synw
[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
3303 unsigned char synuw
[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
3304 static unsigned char wide
[6] = {0x80, 1, 2, 3, 1, 0};
3305 static unsigned char u3
[9] = { 0x80,1,6,4,0x09,00,0x0e,0x01,0x02 };
3307 lvdmode
=inb(wkport
+ 0x1b) >> 7;
3309 for (i
= 0; i
< 16; i
++) {
3312 if ((m
& dev
->active_id
[c
]) != 0) {
3315 if (i
== dev
->host_id
[c
]) {
3316 printk(KERN_INFO
" ID: %2d Host Adapter\n", dev
->host_id
[c
]);
3319 tmport
= wkport
+ 0x1b;
3321 tmport
= wkport
+ 0x01;
3322 outb(0x08, tmport
++);
3323 outb(0x7f, tmport
++);
3324 outb(satn
[0], tmport
++);
3325 outb(satn
[1], tmport
++);
3326 outb(satn
[2], tmport
++);
3327 outb(satn
[3], tmport
++);
3328 outb(satn
[4], tmport
++);
3329 outb(satn
[5], tmport
++);
3333 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3336 outb(satn
[6], tmport
++);
3337 outb(satn
[7], tmport
++);
3339 if ((j
& 0x08) != 0) {
3340 j
= (j
& 0x07) | 0x40;
3344 outb(satn
[8], tmport
);
3347 while ((inb(tmport
) & 0x80) == 0x00)
3350 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3353 while (inb(tmport
) != 0x8e)
3355 dev
->active_id
[c
] |= m
;
3357 tmport
= wkport
+ 0x10;
3359 tmport
= wkport
+ 0x14;
3363 tmport
= wkport
+ 0x18;
3366 while ((inb(tmport
) & 0x80) == 0x00)
3371 tmport
= wkport
+ 0x10;
3376 tmport
= wkport
+ 0x03;
3377 outb(inqd
[0], tmport
++);
3378 outb(inqd
[1], tmport
++);
3379 outb(inqd
[2], tmport
++);
3380 outb(inqd
[3], tmport
++);
3381 outb(inqd
[4], tmport
++);
3382 outb(inqd
[5], tmport
);
3386 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3388 outb(inqd
[6], tmport
++);
3389 outb(inqd
[7], tmport
++);
3391 outb(inqd
[8], tmport
);
3393 while ((inb(tmport
) & 0x80) == 0x00)
3396 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3399 while (inb(tmport
) != 0x8e)
3401 tmport
= wkport
+ 0x1b;
3403 tmport
= wkport
+ 0x18;
3409 if ((k
& 0x01) != 0) {
3411 mbuf
[j
++] = inb(tmport
);
3415 if ((k
& 0x80) == 0) {
3423 tmport
= wkport
+ 0x10;
3432 while ((inb(tmport
) & 0x80) == 0x00)
3435 if (inb(tmport
) != 0x16) {
3440 printk( KERN_INFO
" ID: %2d %s\n", i
, &mbuf
[8]);
3441 dev
->id
[c
][i
].devtype
= mbuf
[0];
3444 if ((mbuf
[7] & 0x60) == 0) {
3447 if ((i
< 8) && ((dev
->global_map
[c
] & 0x20) == 0)) {
3453 if (dev
->sp
[c
][i
] != 0x04) { // force u2
3457 tmport
= wkport
+ 0x1b;
3459 tmport
= wkport
+ 0x03;
3460 outb(satn
[0], tmport
++);
3461 outb(satn
[1], tmport
++);
3462 outb(satn
[2], tmport
++);
3463 outb(satn
[3], tmport
++);
3464 outb(satn
[4], tmport
++);
3465 outb(satn
[5], tmport
++);
3469 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3471 outb(satn
[6], tmport
++);
3472 outb(satn
[7], tmport
++);
3474 outb(satn
[8], tmport
);
3477 while ((inb(tmport
) & 0x80) == 0x00)
3480 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3483 while (inb(tmport
) != 0x8e)
3487 tmport
= wkport
+ 0x14;
3493 while ((inb(tmport
) & 0x80) == 0) {
3494 if ((inb(tmport
) & 0x01) != 0) {
3496 outb(u3
[j
++], tmport
);
3502 while ((inb(tmport
) & 0x80) == 0x00)
3504 j
= inb(tmport
) & 0x0f;
3516 tmport
= wkport
+ 0x18;
3519 while ((inb(tmport
) & 0x80) == 0) {
3520 if ((inb(tmport
) & 0x01) != 0) {
3528 j
= inb(tmport
) & 0x0f;
3540 tmport
= wkport
+ 0x14;
3548 if ((j
& 0x01) != 0) {
3550 mbuf
[k
++] = inb(tmport
);
3554 if ((j
& 0x80) == 0x00) {
3558 j
= inb(tmport
) & 0x0f;
3570 tmport
= wkport
+ 0x10;
3572 tmport
= wkport
+ 0x14;
3577 while ((inb(tmport
) & 0x80) == 0x00);
3586 if (mbuf
[0] != 0x01) {
3589 if (mbuf
[1] != 0x06) {
3592 if (mbuf
[2] != 0x04) {
3595 if (mbuf
[3] == 0x09) {
3598 dev
->wide_id
[c
] |= m
;
3599 dev
->id
[c
][i
].devsp
= 0xce;
3601 printk("dev->id[%2d][%2d].devsp = %2x\n",c
,i
,dev
->id
[c
][i
].devsp
);
3606 tmport
= wkport
+ 0x1b;
3608 tmport
= wkport
+ 0x03;
3609 outb(satn
[0], tmport
++);
3610 outb(satn
[1], tmport
++);
3611 outb(satn
[2], tmport
++);
3612 outb(satn
[3], tmport
++);
3613 outb(satn
[4], tmport
++);
3614 outb(satn
[5], tmport
++);
3618 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3620 outb(satn
[6], tmport
++);
3621 outb(satn
[7], tmport
++);
3623 outb(satn
[8], tmport
);
3626 while ((inb(tmport
) & 0x80) == 0x00)
3629 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3632 while (inb(tmport
) != 0x8e)
3636 tmport
= wkport
+ 0x14;
3642 while ((inb(tmport
) & 0x80) == 0) {
3643 if ((inb(tmport
) & 0x01) != 0) {
3645 outb(wide
[j
++], tmport
);
3651 while ((inb(tmport
) & 0x80) == 0x00)
3653 j
= inb(tmport
) & 0x0f;
3665 tmport
= wkport
+ 0x18;
3668 while ((inb(tmport
) & 0x80) == 0) {
3669 if ((inb(tmport
) & 0x01) != 0) {
3677 j
= inb(tmport
) & 0x0f;
3689 tmport
= wkport
+ 0x14;
3697 if ((j
& 0x01) != 0) {
3699 mbuf
[k
++] = inb(tmport
);
3703 if ((j
& 0x80) == 0x00) {
3707 j
= inb(tmport
) & 0x0f;
3719 tmport
= wkport
+ 0x10;
3721 tmport
= wkport
+ 0x14;
3726 while ((inb(tmport
) & 0x80) == 0x00)
3736 if (mbuf
[0] != 0x01) {
3739 if (mbuf
[1] != 0x02) {
3742 if (mbuf
[2] != 0x03) {
3745 if (mbuf
[3] != 0x01) {
3750 dev
->wide_id
[c
] |= m
;
3752 if ((dev
->id
[c
][i
].devtype
== 0x00) || (dev
->id
[c
][i
].devtype
== 0x07) ||
3753 ((dev
->id
[c
][i
].devtype
== 0x05) && ((n
& 0x10) != 0))) {
3756 if ((dev
->async
[c
] & m
) != 0) {
3762 if (dev
->sp
[c
][i
] == 0x02) {
3766 if (dev
->sp
[c
][i
] >= 0x03) {
3771 tmport
= wkport
+ 0x1b;
3773 if ((m
& dev
->wide_id
[c
]) != 0) {
3777 tmport
= wkport
+ 0x03;
3778 outb(satn
[0], tmport
++);
3779 outb(satn
[1], tmport
++);
3780 outb(satn
[2], tmport
++);
3781 outb(satn
[3], tmport
++);
3782 outb(satn
[4], tmport
++);
3783 outb(satn
[5], tmport
++);
3787 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3789 outb(satn
[6], tmport
++);
3790 outb(satn
[7], tmport
++);
3792 outb(satn
[8], tmport
);
3795 while ((inb(tmport
) & 0x80) == 0x00)
3798 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3801 while (inb(tmport
) != 0x8e)
3805 tmport
= wkport
+ 0x14;
3811 while ((inb(tmport
) & 0x80) == 0) {
3812 if ((inb(tmport
) & 0x01) != 0) {
3814 if ((m
& dev
->wide_id
[c
]) != 0) {
3815 if ((m
& dev
->ultra_map
[c
]) != 0) {
3816 outb(synuw
[j
++], tmport
);
3818 outb(synw
[j
++], tmport
);
3821 if ((m
& dev
->ultra_map
[c
]) != 0) {
3822 outb(synu
[j
++], tmport
);
3824 outb(synn
[j
++], tmport
);
3831 while ((inb(tmport
) & 0x80) == 0x00)
3833 j
= inb(tmport
) & 0x0f;
3845 tmport
= wkport
+ 0x18;
3848 while ((inb(tmport
) & 0x80) == 0x00) {
3849 if ((inb(tmport
) & 0x01) != 0x00) {
3873 tmport
= wkport
+ 0x14;
3881 if ((j
& 0x01) != 0x00) {
3883 mbuf
[k
++] = inb(tmport
);
3887 if ((j
& 0x80) == 0x00) {
3891 while ((inb(tmport
) & 0x80) == 0x00);
3908 tmport
= wkport
+ 0x10;
3911 tmport
= wkport
+ 0x14;
3916 while ((inb(tmport
) & 0x80) == 0x00)
3923 if (mbuf
[0] != 0x01) {
3926 if (mbuf
[1] != 0x03) {
3929 if (mbuf
[4] == 0x00) {
3932 if (mbuf
[3] > 0x64) {
3935 if (mbuf
[4] > 0x0e) {
3938 dev
->id
[c
][i
].devsp
= mbuf
[4];
3939 if (mbuf
[3] < 0x0c){
3943 if ((mbuf
[3] < 0x0d) && (rmb
== 0)) {
3947 if (mbuf
[3] < 0x1a) {
3951 if (mbuf
[3] < 0x33) {
3955 if (mbuf
[3] < 0x4c) {
3961 dev
->id
[c
][i
].devsp
= (dev
->id
[c
][i
].devsp
& 0x0f) | j
;
3963 printk("dev->id[%2d][%2d].devsp = %2x\n",c
,i
,dev
->id
[c
][i
].devsp
);
3966 tmport
= wkport
+ 0x16;
3970 module_init(atp870u_init
);
3971 module_exit(atp870u_exit
);