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
5 * 2.6.x update (C) 2004 Red Hat
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 <linux/slab.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 scsi_dma_unmap(workreq
);
476 spin_lock_irqsave(dev
->host
->host_lock
, flags
);
477 (*workreq
->scsi_done
) (workreq
);
479 printk("workreq->scsi_done\n");
482 * Clear it off the queue
484 dev
->id
[c
][target_id
].curr_req
= NULL
;
486 spin_unlock_irqrestore(dev
->host
->host_lock
, flags
);
490 if (dev
->wide_id
[c
] != 0) {
491 tmport
= workport
+ 0x1b;
493 while ((inb(tmport
) & 0x01) != 0x01) {
498 * If there is stuff to send and nothing going then send it
500 spin_lock_irqsave(dev
->host
->host_lock
, flags
);
501 if (((dev
->last_cmd
[c
] != 0xff) || (dev
->quhd
[c
] != dev
->quend
[c
])) &&
502 (dev
->in_snd
[c
] == 0)) {
504 printk("Call sent_s870(scsi_done)\n");
508 spin_unlock_irqrestore(dev
->host
->host_lock
, flags
);
512 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
513 dev
->last_cmd
[c
] = 0xff;
521 outl(dev
->id
[c
][target_id
].prdaddr
, tmpcip
);
526 tmport
= workport
+ 0x10;
528 if (dev
->dev_id
== ATP885_DEVID
) {
530 k
= dev
->id
[c
][target_id
].last_len
;
531 outb((unsigned char) (((unsigned char *) (&k
))[2]), tmport
++);
532 outb((unsigned char) (((unsigned char *) (&k
))[1]), tmport
++);
533 outb((unsigned char) (((unsigned char *) (&k
))[0]), tmport
);
534 dev
->id
[c
][target_id
].dirct
= 0x00;
537 dev
->id
[c
][target_id
].dirct
= 0x00;
547 outl(dev
->id
[c
][target_id
].prdaddr
, tmpcip
);
552 tmport
= workport
+ 0x10;
554 if (dev
->dev_id
== ATP885_DEVID
) {
556 k
= dev
->id
[c
][target_id
].last_len
;
557 outb((unsigned char) (((unsigned char *) (&k
))[2]), tmport
++);
558 outb((unsigned char) (((unsigned char *) (&k
))[1]), tmport
++);
559 outb((unsigned char) (((unsigned char *) (&k
))[0]), tmport
++);
563 outb((unsigned char) (inb(tmport
) | 0x20), tmport
);
564 dev
->id
[c
][target_id
].dirct
= 0x20;
577 dev
->id
[c
][target_id
].dirct
= 0x00;
579 outb(0x00, tmport
++);
580 outb(0x00, tmport
++);
581 outb(0x00, tmport
++);
587 // tmport = workport + 0x17;
589 // dev->working[c] = 0;
596 printk("atp870u_intr_handle exit\n");
601 * atp870u_queuecommand - Queue SCSI command
602 * @req_p: request block
603 * @done: completion function
605 * Queue a command to the ATP queue. Called with the host lock held.
607 static int atp870u_queuecommand_lck(struct scsi_cmnd
*req_p
,
608 void (*done
) (struct scsi_cmnd
*))
611 unsigned int tmport
,m
;
612 struct atp_unit
*dev
;
613 struct Scsi_Host
*host
;
615 c
= scmd_channel(req_p
);
616 req_p
->sense_buffer
[0]=0;
617 scsi_set_resid(req_p
, 0);
618 if (scmd_channel(req_p
) > 1) {
619 req_p
->result
= 0x00040000;
622 printk("atp870u_queuecommand : req_p->device->channel > 1\n");
627 host
= req_p
->device
->host
;
628 dev
= (struct atp_unit
*)&host
->hostdata
;
633 m
= m
<< scmd_id(req_p
);
636 * Fake a timeout for missing targets
639 if ((m
& dev
->active_id
[c
]) == 0) {
640 req_p
->result
= 0x00040000;
646 req_p
->scsi_done
= done
;
649 printk( "atp870u_queuecommand: done can't be NULL\n");
660 if (dev
->quend
[c
] >= qcnt
) {
667 if (dev
->quhd
[c
] == dev
->quend
[c
]) {
668 if (dev
->quend
[c
] == 0) {
669 dev
->quend
[c
] = qcnt
;
672 printk("atp870u_queuecommand : dev->quhd[c] == dev->quend[c]\n");
675 req_p
->result
= 0x00020000;
679 dev
->quereq
[c
][dev
->quend
[c
]] = req_p
;
680 tmport
= dev
->ioport
[c
] + 0x1c;
682 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
]);
684 if ((inb(tmport
) == 0) && (dev
->in_int
[c
] == 0) && (dev
->in_snd
[c
] == 0)) {
686 printk("Call sent_s870(atp870u_queuecommand)\n");
691 printk("atp870u_queuecommand : exit\n");
696 static DEF_SCSI_QCMD(atp870u_queuecommand
)
699 * send_s870 - send a command to the controller
702 * On entry there is work queued to be done. We move some of that work to the
705 * Caller holds the host lock.
707 static void send_s870(struct atp_unit
*dev
,unsigned char c
)
710 struct scsi_cmnd
*workreq
;
712 unsigned char j
, target_id
;
714 unsigned short int tmpcip
, w
;
715 unsigned long l
, bttl
= 0;
716 unsigned int workport
;
717 unsigned long sg_count
;
719 if (dev
->in_snd
[c
] != 0) {
721 printk("cmnd in_snd\n");
726 printk("Sent_s870 enter\n");
729 if ((dev
->last_cmd
[c
] != 0xff) && ((dev
->last_cmd
[c
] & 0x40) != 0)) {
730 dev
->last_cmd
[c
] &= 0x0f;
731 workreq
= dev
->id
[c
][dev
->last_cmd
[c
]].curr_req
;
732 if (workreq
!= NULL
) { /* check NULL pointer */
735 dev
->last_cmd
[c
] = 0xff;
736 if (dev
->quhd
[c
] == dev
->quend
[c
]) {
741 if ((dev
->last_cmd
[c
] != 0xff) && (dev
->working
[c
] != 0)) {
748 if (dev
->quhd
[c
] >= qcnt
) {
751 workreq
= dev
->quereq
[c
][dev
->quhd
[c
]];
752 if (dev
->id
[c
][scmd_id(workreq
)].curr_req
== NULL
) {
753 dev
->id
[c
][scmd_id(workreq
)].curr_req
= workreq
;
754 dev
->last_cmd
[c
] = scmd_id(workreq
);
762 workport
= dev
->ioport
[c
];
763 tmport
= workport
+ 0x1f;
764 if ((inb(tmport
) & 0xb0) != 0) {
767 tmport
= workport
+ 0x1c;
768 if (inb(tmport
) == 0) {
773 printk("Abort to Send\n");
775 dev
->last_cmd
[c
] |= 0x40;
780 printk("OK to Send\n");
781 scmd_printk(KERN_DEBUG
, workreq
, "CDB");
782 for(i
=0;i
<workreq
->cmd_len
;i
++) {
783 printk(" %x",workreq
->cmnd
[i
]);
787 l
= scsi_bufflen(workreq
);
789 if (dev
->dev_id
== ATP885_DEVID
) {
790 j
= inb(dev
->baseport
+ 0x29) & 0xfe;
791 outb(j
, dev
->baseport
+ 0x29);
792 dev
->r1f
[c
][scmd_id(workreq
)] = 0;
795 if (workreq
->cmnd
[0] == READ_CAPACITY
) {
799 if (workreq
->cmnd
[0] == 0x00) {
803 tmport
= workport
+ 0x1b;
805 target_id
= scmd_id(workreq
);
812 if ((w
& dev
->wide_id
[c
]) != 0) {
816 while ((inb(tmport
) & 0x01) != j
) {
819 printk("send_s870 while loop 1\n");
827 outb(workreq
->cmd_len
, tmport
++);
828 outb(0x2c, tmport
++);
829 if (dev
->dev_id
== ATP885_DEVID
) {
830 outb(0x7f, tmport
++);
832 outb(0xcf, tmport
++);
834 for (i
= 0; i
< workreq
->cmd_len
; i
++) {
835 outb(workreq
->cmnd
[i
], tmport
++);
837 tmport
= workport
+ 0x0f;
838 outb(workreq
->device
->lun
, tmport
);
843 outb(dev
->id
[c
][target_id
].devsp
, tmport
++);
845 printk("dev->id[%d][%d].devsp = %2x\n",c
,target_id
,dev
->id
[c
][target_id
].devsp
);
848 sg_count
= scsi_dma_map(workreq
);
850 * Write transfer size
852 outb((unsigned char) (((unsigned char *) (&l
))[2]), tmport
++);
853 outb((unsigned char) (((unsigned char *) (&l
))[1]), tmport
++);
854 outb((unsigned char) (((unsigned char *) (&l
))[0]), tmport
++);
856 dev
->id
[c
][j
].last_len
= l
;
857 dev
->id
[c
][j
].tran_len
= 0;
859 printk("dev->id[%2d][%2d].last_len = %d\n",c
,j
,dev
->id
[c
][j
].last_len
);
864 if ((j
& 0x08) != 0) {
865 j
= (j
& 0x07) | 0x40;
868 * Check transfer direction
870 if (workreq
->sc_data_direction
== DMA_TO_DEVICE
) {
871 outb((unsigned char) (j
| 0x20), tmport
++);
875 outb((unsigned char) (inb(tmport
) | 0x80), tmport
);
877 tmport
= workport
+ 0x1c;
878 dev
->id
[c
][target_id
].dirct
= 0;
880 if (inb(tmport
) == 0) {
881 tmport
= workport
+ 0x18;
883 printk("change SCSI_CMD_REG 0x08\n");
887 dev
->last_cmd
[c
] |= 0x40;
892 tmpcip
= dev
->pciport
[c
];
893 prd
= dev
->id
[c
][target_id
].prd_table
;
894 dev
->id
[c
][target_id
].prd_pos
= prd
;
897 * Now write the request list. Either as scatter/gather or as
902 struct scatterlist
*sgpnt
;
904 scsi_for_each_sg(workreq
, sgpnt
, sg_count
, j
) {
905 bttl
= sg_dma_address(sgpnt
);
908 printk("1. bttl %x, l %x\n",bttl
, l
);
910 while (l
> 0x10000) {
911 (((u16
*) (prd
))[i
+ 3]) = 0x0000;
912 (((u16
*) (prd
))[i
+ 2]) = 0x0000;
913 (((u32
*) (prd
))[i
>> 1]) = cpu_to_le32(bttl
);
918 (((u32
*) (prd
))[i
>> 1]) = cpu_to_le32(bttl
);
919 (((u16
*) (prd
))[i
+ 2]) = cpu_to_le16(l
);
920 (((u16
*) (prd
))[i
+ 3]) = 0;
923 (((u16
*) (prd
))[i
- 1]) = cpu_to_le16(0x8000);
925 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]));
926 printk("2. bttl %x, l %x\n",bttl
, l
);
931 printk("send_s870: prdaddr_2 0x%8x tmpcip %x target_id %d\n", dev
->id
[c
][target_id
].prdaddr
,tmpcip
,target_id
);
933 dev
->id
[c
][target_id
].prdaddr
= dev
->id
[c
][target_id
].prd_bus
;
934 outl(dev
->id
[c
][target_id
].prdaddr
, tmpcip
);
938 if (dev
->dev_id
== ATP885_DEVID
) {
940 j
=inb(tmpcip
) & 0xf3;
941 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) ||
942 (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
947 } else if ((dev
->dev_id
== ATP880_DEVID1
) ||
948 (dev
->dev_id
== ATP880_DEVID2
)) {
950 tmport
= workport
- 0x05;
951 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
952 outb((unsigned char) ((inb(tmport
) & 0x3f) | 0xc0), tmport
);
954 outb((unsigned char) (inb(tmport
) & 0x3f), tmport
);
958 tmport
= workport
+ 0x3a;
959 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
960 outb((inb(tmport
) & 0xf3) | 0x08, tmport
);
962 outb(inb(tmport
) & 0xf3, tmport
);
965 tmport
= workport
+ 0x1c;
967 if(workreq
->sc_data_direction
== DMA_TO_DEVICE
) {
968 dev
->id
[c
][target_id
].dirct
= 0x20;
969 if (inb(tmport
) == 0) {
970 tmport
= workport
+ 0x18;
974 printk( "start DMA(to target)\n");
977 dev
->last_cmd
[c
] |= 0x40;
982 if (inb(tmport
) == 0) {
983 tmport
= workport
+ 0x18;
987 printk( "start DMA(to host)\n");
990 dev
->last_cmd
[c
] |= 0x40;
997 static unsigned char fun_scam(struct atp_unit
*dev
, unsigned short int *val
)
1000 unsigned short int i
, k
;
1003 tmport
= dev
->ioport
[0] + 0x1c;
1006 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
1008 j
= (unsigned char) (k
>> 8);
1009 if ((k
& 0x8000) != 0) { /* DB7 all release? */
1013 *val
|= 0x4000; /* assert DB6 */
1015 *val
&= 0xdfff; /* assert DB5 */
1018 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
1019 if ((inw(tmport
) & 0x2000) != 0) { /* DB5 all release? */
1023 *val
|= 0x8000; /* no DB4-0, assert DB7 */
1026 *val
&= 0xbfff; /* release DB6 */
1029 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
1030 if ((inw(tmport
) & 0x4000) != 0) { /* DB6 all release? */
1038 static void tscam(struct Scsi_Host
*host
)
1041 unsigned int tmport
;
1042 unsigned char i
, j
, k
;
1044 unsigned short int m
, assignid_map
, val
;
1045 unsigned char mbuf
[33], quintet
[2];
1046 struct atp_unit
*dev
= (struct atp_unit
*)&host
->hostdata
;
1047 static unsigned char g2q_tab
[8] = {
1048 0x38, 0x31, 0x32, 0x2b, 0x34, 0x2d, 0x2e, 0x27
1051 /* I can't believe we need this before we've even done anything. Remove it
1052 * and see if anyone bitches.
1053 for (i = 0; i < 0x10; i++) {
1058 tmport
= dev
->ioport
[0] + 1;
1059 outb(0x08, tmport
++);
1061 tmport
= dev
->ioport
[0] + 0x11;
1064 if ((dev
->scam_on
& 0x40) == 0) {
1068 m
<<= dev
->host_id
[0];
1070 if (dev
->chip_ver
< 4) {
1075 tmport
= dev
->ioport
[0] + 0x02;
1076 outb(0x02, tmport
++); /* 2*2=4ms,3EH 2/32*3E=3.9ms */
1084 for (i
= 0; i
< j
; i
++) {
1087 if ((m
& assignid_map
) != 0) {
1090 tmport
= dev
->ioport
[0] + 0x0f;
1097 k
= (i
& 0x07) | 0x40;
1102 tmport
= dev
->ioport
[0] + 0x1b;
1103 if (dev
->chip_ver
== 4) {
1109 tmport
= dev
->ioport
[0] + 0x18;
1113 while ((inb(tmport
) & 0x80) == 0x00)
1118 if ((k
== 0x85) || (k
== 0x42)) {
1121 tmport
= dev
->ioport
[0] + 0x10;
1128 tmport
= dev
->ioport
[0] + 0x02;
1130 tmport
= dev
->ioport
[0] + 0x1b;
1135 val
= 0x0080; /* bsy */
1136 tmport
= dev
->ioport
[0] + 0x1c;
1138 val
|= 0x0040; /* sel */
1140 val
|= 0x0004; /* msg */
1142 inb(0x80); /* 2 deskew delay(45ns*2=90ns) */
1143 val
&= 0x007f; /* no bsy */
1146 val
&= 0x00fb; /* after 1ms no msg */
1149 if ((inb(tmport
) & 0x04) != 0) {
1154 for (n
= 0; n
< 0x30000; n
++) {
1155 if ((inb(tmport
) & 0x80) != 0) { /* bsy ? */
1161 for (n
= 0; n
< 0x30000; n
++) {
1162 if ((inb(tmport
) & 0x81) == 0x0081) {
1169 val
|= 0x8003; /* io,cd,db7 */
1172 val
&= 0x00bf; /* no sel */
1177 * The funny division into multiple delays is to accomodate
1178 * arches like ARM where udelay() multiplies its argument by
1179 * a large number to initialize a loop counter. To avoid
1180 * overflow, the maximum supported udelay is 2000 microseconds.
1182 * XXX it would be more polite to find a way to use msleep()
1186 if ((inb(tmport
) & 0x80) == 0x00) { /* bsy ? */
1189 tmport
= dev
->ioport
[0] + 0x15;
1194 while ((inb(tmport
) & 0x80) == 0)
1200 val
&= 0x00ff; /* synchronization */
1202 fun_scam(dev
, &val
);
1204 val
&= 0x00ff; /* isolation */
1206 fun_scam(dev
, &val
);
1211 if ((inw(tmport
) & 0x2000) == 0) {
1215 val
&= 0x00ff; /* get ID_STRING */
1217 k
= fun_scam(dev
, &val
);
1218 if ((k
& 0x03) == 0) {
1223 if ((k
& 0x02) != 0) {
1234 TCM_5
: /* isolation complete.. */
1236 printk(" \n%x %x %x %s\n ",assignid_map,mbuf[0],mbuf[1],&mbuf[2]); */
1239 if ((j
& 0x20) != 0) { /* bit5=1:ID up to 7 */
1242 if ((j
& 0x06) == 0) { /* IDvalid? */
1249 if ((m
& assignid_map
) == 0) {
1256 G2Q5
: /* srch from max acceptable ID# */
1257 k
= i
; /* max acceptable ID# */
1261 if ((m
& assignid_map
) == 0) {
1268 G2Q_QUIN
: /* k=binID#, */
1271 quintet
[0] = 0x38; /* 1st dft ID<8 */
1273 quintet
[0] = 0x31; /* 1st ID>=8 */
1276 quintet
[1] = g2q_tab
[k
];
1278 val
&= 0x00ff; /* AssignID 1stQuintet,AH=001xxxxx */
1279 m
= quintet
[0] << 8;
1281 fun_scam(dev
, &val
);
1282 val
&= 0x00ff; /* AssignID 2ndQuintet,AH=001xxxxx */
1283 m
= quintet
[1] << 8;
1285 fun_scam(dev
, &val
);
1291 static void is870(struct atp_unit
*dev
, unsigned int wkport
)
1293 unsigned int tmport
;
1294 unsigned char i
, j
, k
, rmb
, n
;
1295 unsigned short int m
;
1296 static unsigned char mbuf
[512];
1297 static unsigned char satn
[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
1298 static unsigned char inqd
[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
1299 static unsigned char synn
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1300 static unsigned char synu
[6] = { 0x80, 1, 3, 1, 0x0c, 0x0e };
1301 static unsigned char synw
[6] = { 0x80, 1, 3, 1, 0x0c, 0x07 };
1302 static unsigned char wide
[6] = { 0x80, 1, 2, 3, 1, 0 };
1304 tmport
= wkport
+ 0x3a;
1305 outb((unsigned char) (inb(tmport
) | 0x10), tmport
);
1307 for (i
= 0; i
< 16; i
++) {
1308 if ((dev
->chip_ver
!= 4) && (i
> 7)) {
1313 if ((m
& dev
->active_id
[0]) != 0) {
1316 if (i
== dev
->host_id
[0]) {
1317 printk(KERN_INFO
" ID: %2d Host Adapter\n", dev
->host_id
[0]);
1320 tmport
= wkport
+ 0x1b;
1321 if (dev
->chip_ver
== 4) {
1326 tmport
= wkport
+ 1;
1327 outb(0x08, tmport
++);
1328 outb(0x7f, tmport
++);
1329 outb(satn
[0], tmport
++);
1330 outb(satn
[1], tmport
++);
1331 outb(satn
[2], tmport
++);
1332 outb(satn
[3], tmport
++);
1333 outb(satn
[4], tmport
++);
1334 outb(satn
[5], tmport
++);
1338 outb(dev
->id
[0][i
].devsp
, tmport
++);
1340 outb(satn
[6], tmport
++);
1341 outb(satn
[7], tmport
++);
1343 if ((j
& 0x08) != 0) {
1344 j
= (j
& 0x07) | 0x40;
1348 outb(satn
[8], tmport
);
1351 while ((inb(tmport
) & 0x80) == 0x00)
1355 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1358 while (inb(tmport
) != 0x8e)
1361 dev
->active_id
[0] |= m
;
1363 tmport
= wkport
+ 0x10;
1365 tmport
= wkport
+ 0x04;
1369 tmport
= wkport
+ 0x18;
1372 while ((inb(tmport
) & 0x80) == 0x00)
1377 tmport
= wkport
+ 0x10;
1382 tmport
= wkport
+ 3;
1383 outb(inqd
[0], tmport
++);
1384 outb(inqd
[1], tmport
++);
1385 outb(inqd
[2], tmport
++);
1386 outb(inqd
[3], tmport
++);
1387 outb(inqd
[4], tmport
++);
1388 outb(inqd
[5], tmport
);
1392 outb(dev
->id
[0][i
].devsp
, tmport
++);
1394 outb(inqd
[6], tmport
++);
1395 outb(inqd
[7], tmport
++);
1397 outb(inqd
[8], tmport
);
1400 while ((inb(tmport
) & 0x80) == 0x00)
1404 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1407 while (inb(tmport
) != 0x8e)
1410 tmport
= wkport
+ 0x1b;
1411 if (dev
->chip_ver
== 4)
1414 tmport
= wkport
+ 0x18;
1420 if ((k
& 0x01) != 0) {
1422 mbuf
[j
++] = inb(tmport
);
1426 if ((k
& 0x80) == 0) {
1434 tmport
= wkport
+ 0x10;
1444 while ((inb(tmport
) & 0x80) == 0x00)
1448 if (inb(tmport
) != 0x16) {
1453 printk(KERN_INFO
" ID: %2d %s\n", i
, &mbuf
[8]);
1454 dev
->id
[0][i
].devtype
= mbuf
[0];
1457 if (dev
->chip_ver
!= 4) {
1460 if ((mbuf
[7] & 0x60) == 0) {
1463 if ((dev
->global_map
[0] & 0x20) == 0) {
1466 tmport
= wkport
+ 0x1b;
1468 tmport
= wkport
+ 3;
1469 outb(satn
[0], tmport
++);
1470 outb(satn
[1], tmport
++);
1471 outb(satn
[2], tmport
++);
1472 outb(satn
[3], tmport
++);
1473 outb(satn
[4], tmport
++);
1474 outb(satn
[5], tmport
++);
1478 outb(dev
->id
[0][i
].devsp
, tmport
++);
1480 outb(satn
[6], tmport
++);
1481 outb(satn
[7], tmport
++);
1483 outb(satn
[8], tmport
);
1486 while ((inb(tmport
) & 0x80) == 0x00)
1490 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1493 while (inb(tmport
) != 0x8e)
1498 tmport
= wkport
+ 0x14;
1504 while ((inb(tmport
) & 0x80) == 0) {
1505 if ((inb(tmport
) & 0x01) != 0) {
1507 outb(wide
[j
++], tmport
);
1513 while ((inb(tmport
) & 0x80) == 0x00)
1516 j
= inb(tmport
) & 0x0f;
1528 tmport
= wkport
+ 0x18;
1531 while ((inb(tmport
) & 0x80) == 0) {
1532 if ((inb(tmport
) & 0x01) != 0) {
1539 j
= inb(tmport
) & 0x0f;
1551 tmport
= wkport
+ 0x14;
1559 if ((j
& 0x01) != 0) {
1561 mbuf
[k
++] = inb(tmport
);
1565 if ((j
& 0x80) == 0x00) {
1569 j
= inb(tmport
) & 0x0f;
1581 tmport
= wkport
+ 0x10;
1583 tmport
= wkport
+ 0x14;
1589 while ((inb(tmport
) & 0x80) == 0x00)
1600 if (mbuf
[0] != 0x01) {
1603 if (mbuf
[1] != 0x02) {
1606 if (mbuf
[2] != 0x03) {
1609 if (mbuf
[3] != 0x01) {
1614 dev
->wide_id
[0] |= m
;
1616 if ((dev
->id
[0][i
].devtype
== 0x00) || (dev
->id
[0][i
].devtype
== 0x07) || ((dev
->id
[0][i
].devtype
== 0x05) && ((n
& 0x10) != 0))) {
1621 tmport
= wkport
+ 0x1b;
1623 if ((m
& dev
->wide_id
[0]) != 0) {
1627 tmport
= wkport
+ 3;
1628 outb(satn
[0], tmport
++);
1629 outb(satn
[1], tmport
++);
1630 outb(satn
[2], tmport
++);
1631 outb(satn
[3], tmport
++);
1632 outb(satn
[4], tmport
++);
1633 outb(satn
[5], tmport
++);
1637 outb(dev
->id
[0][i
].devsp
, tmport
++);
1639 outb(satn
[6], tmport
++);
1640 outb(satn
[7], tmport
++);
1642 outb(satn
[8], tmport
);
1645 while ((inb(tmport
) & 0x80) == 0x00)
1649 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1652 while (inb(tmport
) != 0x8e)
1657 tmport
= wkport
+ 0x14;
1663 while ((inb(tmport
) & 0x80) == 0) {
1664 if ((inb(tmport
) & 0x01) != 0) {
1666 if ((m
& dev
->wide_id
[0]) != 0) {
1667 outb(synw
[j
++], tmport
);
1669 if ((m
& dev
->ultra_map
[0]) != 0) {
1670 outb(synu
[j
++], tmport
);
1672 outb(synn
[j
++], tmport
);
1680 while ((inb(tmport
) & 0x80) == 0x00)
1683 j
= inb(tmport
) & 0x0f;
1695 tmport
= wkport
+ 0x18;
1698 while ((inb(tmport
) & 0x80) == 0x00) {
1699 if ((inb(tmport
) & 0x01) != 0x00) {
1722 tmport
= wkport
+ 0x14;
1730 if ((j
& 0x01) != 0x00) {
1732 mbuf
[k
++] = inb(tmport
);
1736 if ((j
& 0x80) == 0x00) {
1741 while ((inb(tmport
) & 0x80) == 0x00)
1760 tmport
= wkport
+ 0x10;
1763 tmport
= wkport
+ 0x14;
1769 while ((inb(tmport
) & 0x80) == 0x00)
1777 if (mbuf
[0] != 0x01) {
1780 if (mbuf
[1] != 0x03) {
1783 if (mbuf
[4] == 0x00) {
1786 if (mbuf
[3] > 0x64) {
1789 if (mbuf
[4] > 0x0c) {
1792 dev
->id
[0][i
].devsp
= mbuf
[4];
1793 if ((mbuf
[3] < 0x0d) && (rmb
== 0)) {
1797 if (mbuf
[3] < 0x1a) {
1801 if (mbuf
[3] < 0x33) {
1805 if (mbuf
[3] < 0x4c) {
1811 dev
->id
[0][i
].devsp
= (dev
->id
[0][i
].devsp
& 0x0f) | j
;
1813 tmport
= wkport
+ 0x3a;
1814 outb((unsigned char) (inb(tmport
) & 0xef), tmport
);
1817 static void is880(struct atp_unit
*dev
, unsigned int wkport
)
1819 unsigned int tmport
;
1820 unsigned char i
, j
, k
, rmb
, n
, lvdmode
;
1821 unsigned short int m
;
1822 static unsigned char mbuf
[512];
1823 static unsigned char satn
[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
1824 static unsigned char inqd
[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
1825 static unsigned char synn
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1826 unsigned char synu
[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
1827 static unsigned char synw
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1828 unsigned char synuw
[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
1829 static unsigned char wide
[6] = { 0x80, 1, 2, 3, 1, 0 };
1830 static unsigned char u3
[9] = { 0x80, 1, 6, 4, 0x09, 00, 0x0e, 0x01, 0x02 };
1832 lvdmode
= inb(wkport
+ 0x3f) & 0x40;
1834 for (i
= 0; i
< 16; i
++) {
1837 if ((m
& dev
->active_id
[0]) != 0) {
1840 if (i
== dev
->host_id
[0]) {
1841 printk(KERN_INFO
" ID: %2d Host Adapter\n", dev
->host_id
[0]);
1844 tmport
= wkport
+ 0x5b;
1846 tmport
= wkport
+ 0x41;
1847 outb(0x08, tmport
++);
1848 outb(0x7f, tmport
++);
1849 outb(satn
[0], tmport
++);
1850 outb(satn
[1], tmport
++);
1851 outb(satn
[2], tmport
++);
1852 outb(satn
[3], tmport
++);
1853 outb(satn
[4], tmport
++);
1854 outb(satn
[5], tmport
++);
1858 outb(dev
->id
[0][i
].devsp
, tmport
++);
1860 outb(satn
[6], tmport
++);
1861 outb(satn
[7], tmport
++);
1863 if ((j
& 0x08) != 0) {
1864 j
= (j
& 0x07) | 0x40;
1868 outb(satn
[8], tmport
);
1871 while ((inb(tmport
) & 0x80) == 0x00)
1875 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1878 while (inb(tmport
) != 0x8e)
1881 dev
->active_id
[0] |= m
;
1883 tmport
= wkport
+ 0x50;
1885 tmport
= wkport
+ 0x54;
1889 tmport
= wkport
+ 0x58;
1893 while ((inb(tmport
) & 0x80) == 0x00)
1899 tmport
= wkport
+ 0x50;
1904 tmport
= wkport
+ 0x43;
1905 outb(inqd
[0], tmport
++);
1906 outb(inqd
[1], tmport
++);
1907 outb(inqd
[2], tmport
++);
1908 outb(inqd
[3], tmport
++);
1909 outb(inqd
[4], tmport
++);
1910 outb(inqd
[5], tmport
);
1914 outb(dev
->id
[0][i
].devsp
, tmport
++);
1916 outb(inqd
[6], tmport
++);
1917 outb(inqd
[7], tmport
++);
1919 outb(inqd
[8], tmport
);
1922 while ((inb(tmport
) & 0x80) == 0x00)
1926 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1929 while (inb(tmport
) != 0x8e)
1932 tmport
= wkport
+ 0x5b;
1934 tmport
= wkport
+ 0x58;
1940 if ((k
& 0x01) != 0) {
1942 mbuf
[j
++] = inb(tmport
);
1946 if ((k
& 0x80) == 0) {
1954 tmport
= wkport
+ 0x50;
1963 while ((inb(tmport
) & 0x80) == 0x00)
1967 if (inb(tmport
) != 0x16)
1972 printk(KERN_INFO
" ID: %2d %s\n", i
, &mbuf
[8]);
1973 dev
->id
[0][i
].devtype
= mbuf
[0];
1976 if ((mbuf
[7] & 0x60) == 0) {
1979 if ((i
< 8) && ((dev
->global_map
[0] & 0x20) == 0)) {
1985 if (dev
->sp
[0][i
] != 0x04) // force u2
1990 tmport
= wkport
+ 0x5b;
1992 tmport
= wkport
+ 0x43;
1993 outb(satn
[0], tmport
++);
1994 outb(satn
[1], tmport
++);
1995 outb(satn
[2], tmport
++);
1996 outb(satn
[3], tmport
++);
1997 outb(satn
[4], tmport
++);
1998 outb(satn
[5], tmport
++);
2002 outb(dev
->id
[0][i
].devsp
, tmport
++);
2004 outb(satn
[6], tmport
++);
2005 outb(satn
[7], tmport
++);
2007 outb(satn
[8], tmport
);
2010 while ((inb(tmport
) & 0x80) == 0x00)
2015 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
2018 while (inb(tmport
) != 0x8e)
2023 tmport
= wkport
+ 0x54;
2029 while ((inb(tmport
) & 0x80) == 0) {
2030 if ((inb(tmport
) & 0x01) != 0) {
2032 outb(u3
[j
++], tmport
);
2038 while ((inb(tmport
) & 0x80) == 0x00)
2041 j
= inb(tmport
) & 0x0f;
2053 tmport
= wkport
+ 0x58;
2056 while ((inb(tmport
) & 0x80) == 0) {
2057 if ((inb(tmport
) & 0x01) != 0) {
2064 j
= inb(tmport
) & 0x0f;
2076 tmport
= wkport
+ 0x54;
2084 if ((j
& 0x01) != 0) {
2086 mbuf
[k
++] = inb(tmport
);
2090 if ((j
& 0x80) == 0x00) {
2094 j
= inb(tmport
) & 0x0f;
2106 tmport
= wkport
+ 0x50;
2108 tmport
= wkport
+ 0x54;
2114 while ((inb(tmport
) & 0x80) == 0x00)
2125 if (mbuf
[0] != 0x01) {
2128 if (mbuf
[1] != 0x06) {
2131 if (mbuf
[2] != 0x04) {
2134 if (mbuf
[3] == 0x09) {
2137 dev
->wide_id
[0] |= m
;
2138 dev
->id
[0][i
].devsp
= 0xce;
2142 tmport
= wkport
+ 0x5b;
2144 tmport
= wkport
+ 0x43;
2145 outb(satn
[0], tmport
++);
2146 outb(satn
[1], tmport
++);
2147 outb(satn
[2], tmport
++);
2148 outb(satn
[3], tmport
++);
2149 outb(satn
[4], tmport
++);
2150 outb(satn
[5], tmport
++);
2154 outb(dev
->id
[0][i
].devsp
, tmport
++);
2156 outb(satn
[6], tmport
++);
2157 outb(satn
[7], tmport
++);
2159 outb(satn
[8], tmport
);
2162 while ((inb(tmport
) & 0x80) == 0x00)
2166 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
2169 while (inb(tmport
) != 0x8e)
2174 tmport
= wkport
+ 0x54;
2180 while ((inb(tmport
) & 0x80) == 0) {
2181 if ((inb(tmport
) & 0x01) != 0) {
2183 outb(wide
[j
++], tmport
);
2188 while ((inb(tmport
) & 0x80) == 0x00)
2191 j
= inb(tmport
) & 0x0f;
2203 tmport
= wkport
+ 0x58;
2206 while ((inb(tmport
) & 0x80) == 0) {
2207 if ((inb(tmport
) & 0x01) != 0) {
2214 j
= inb(tmport
) & 0x0f;
2226 tmport
= wkport
+ 0x54;
2234 if ((j
& 0x01) != 0) {
2236 mbuf
[k
++] = inb(tmport
);
2240 if ((j
& 0x80) == 0x00) {
2244 j
= inb(tmport
) & 0x0f;
2256 tmport
= wkport
+ 0x50;
2258 tmport
= wkport
+ 0x54;
2264 while ((inb(tmport
) & 0x80) == 0x00)
2275 if (mbuf
[0] != 0x01) {
2278 if (mbuf
[1] != 0x02) {
2281 if (mbuf
[2] != 0x03) {
2284 if (mbuf
[3] != 0x01) {
2289 dev
->wide_id
[0] |= m
;
2291 if ((dev
->id
[0][i
].devtype
== 0x00) || (dev
->id
[0][i
].devtype
== 0x07) || ((dev
->id
[0][i
].devtype
== 0x05) && ((n
& 0x10) != 0))) {
2294 if ((dev
->async
[0] & m
) != 0) {
2300 if (dev
->sp
[0][i
] == 0x02) {
2304 if (dev
->sp
[0][i
] >= 0x03) {
2309 tmport
= wkport
+ 0x5b;
2311 if ((m
& dev
->wide_id
[0]) != 0) {
2315 tmport
= wkport
+ 0x43;
2316 outb(satn
[0], tmport
++);
2317 outb(satn
[1], tmport
++);
2318 outb(satn
[2], tmport
++);
2319 outb(satn
[3], tmport
++);
2320 outb(satn
[4], tmport
++);
2321 outb(satn
[5], tmport
++);
2325 outb(dev
->id
[0][i
].devsp
, tmport
++);
2327 outb(satn
[6], tmport
++);
2328 outb(satn
[7], tmport
++);
2330 outb(satn
[8], tmport
);
2333 while ((inb(tmport
) & 0x80) == 0x00)
2337 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
2340 while (inb(tmport
) != 0x8e)
2345 tmport
= wkport
+ 0x54;
2351 while ((inb(tmport
) & 0x80) == 0) {
2352 if ((inb(tmport
) & 0x01) != 0) {
2354 if ((m
& dev
->wide_id
[0]) != 0) {
2355 if ((m
& dev
->ultra_map
[0]) != 0) {
2356 outb(synuw
[j
++], tmport
);
2358 outb(synw
[j
++], tmport
);
2361 if ((m
& dev
->ultra_map
[0]) != 0) {
2362 outb(synu
[j
++], tmport
);
2364 outb(synn
[j
++], tmport
);
2372 while ((inb(tmport
) & 0x80) == 0x00)
2375 j
= inb(tmport
) & 0x0f;
2387 tmport
= wkport
+ 0x58;
2390 while ((inb(tmport
) & 0x80) == 0x00) {
2391 if ((inb(tmport
) & 0x01) != 0x00) {
2414 tmport
= wkport
+ 0x54;
2422 if ((j
& 0x01) != 0x00) {
2424 mbuf
[k
++] = inb(tmport
);
2428 if ((j
& 0x80) == 0x00) {
2433 while ((inb(tmport
) & 0x80) == 0x00)
2452 tmport
= wkport
+ 0x50;
2455 tmport
= wkport
+ 0x54;
2461 while ((inb(tmport
) & 0x80) == 0x00)
2469 if (mbuf
[0] != 0x01) {
2472 if (mbuf
[1] != 0x03) {
2475 if (mbuf
[4] == 0x00) {
2478 if (mbuf
[3] > 0x64) {
2481 if (mbuf
[4] > 0x0e) {
2484 dev
->id
[0][i
].devsp
= mbuf
[4];
2485 if (mbuf
[3] < 0x0c) {
2489 if ((mbuf
[3] < 0x0d) && (rmb
== 0)) {
2493 if (mbuf
[3] < 0x1a) {
2497 if (mbuf
[3] < 0x33) {
2501 if (mbuf
[3] < 0x4c) {
2507 dev
->id
[0][i
].devsp
= (dev
->id
[0][i
].devsp
& 0x0f) | j
;
2511 static void atp870u_free_tables(struct Scsi_Host
*host
)
2513 struct atp_unit
*atp_dev
= (struct atp_unit
*)&host
->hostdata
;
2515 for (j
=0; j
< 2; j
++) {
2516 for (k
= 0; k
< 16; k
++) {
2517 if (!atp_dev
->id
[j
][k
].prd_table
)
2519 pci_free_consistent(atp_dev
->pdev
, 1024, atp_dev
->id
[j
][k
].prd_table
, atp_dev
->id
[j
][k
].prd_bus
);
2520 atp_dev
->id
[j
][k
].prd_table
= NULL
;
2525 static int atp870u_init_tables(struct Scsi_Host
*host
)
2527 struct atp_unit
*atp_dev
= (struct atp_unit
*)&host
->hostdata
;
2529 for(c
=0;c
< 2;c
++) {
2531 atp_dev
->id
[c
][k
].prd_table
= pci_alloc_consistent(atp_dev
->pdev
, 1024, &(atp_dev
->id
[c
][k
].prd_bus
));
2532 if (!atp_dev
->id
[c
][k
].prd_table
) {
2533 printk("atp870u_init_tables fail\n");
2534 atp870u_free_tables(host
);
2537 atp_dev
->id
[c
][k
].prdaddr
= atp_dev
->id
[c
][k
].prd_bus
;
2538 atp_dev
->id
[c
][k
].devsp
=0x20;
2539 atp_dev
->id
[c
][k
].devtype
= 0x7f;
2540 atp_dev
->id
[c
][k
].curr_req
= NULL
;
2543 atp_dev
->active_id
[c
] = 0;
2544 atp_dev
->wide_id
[c
] = 0;
2545 atp_dev
->host_id
[c
] = 0x07;
2546 atp_dev
->quhd
[c
] = 0;
2547 atp_dev
->quend
[c
] = 0;
2548 atp_dev
->last_cmd
[c
] = 0xff;
2549 atp_dev
->in_snd
[c
] = 0;
2550 atp_dev
->in_int
[c
] = 0;
2552 for (k
= 0; k
< qcnt
; k
++) {
2553 atp_dev
->quereq
[c
][k
] = NULL
;
2555 for (k
= 0; k
< 16; k
++) {
2556 atp_dev
->id
[c
][k
].curr_req
= NULL
;
2557 atp_dev
->sp
[c
][k
] = 0x04;
2563 /* return non-zero on detection */
2564 static int atp870u_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
2566 unsigned char k
, m
, c
;
2567 unsigned long flags
;
2568 unsigned int base_io
, tmport
, error
,n
;
2569 unsigned char host_id
;
2570 struct Scsi_Host
*shpnt
= NULL
;
2571 struct atp_unit
*atpdev
, *p
;
2572 unsigned char setupdata
[2][16];
2575 atpdev
= kzalloc(sizeof(*atpdev
), GFP_KERNEL
);
2579 if (pci_enable_device(pdev
))
2582 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))) {
2583 printk(KERN_INFO
"atp870u: use 32bit DMA mask.\n");
2585 printk(KERN_ERR
"atp870u: DMA mask required but not available.\n");
2590 * It's probably easier to weed out some revisions like
2591 * this than via the PCI device table
2593 if (ent
->device
== PCI_DEVICE_ID_ARTOP_AEC7610
) {
2594 atpdev
->chip_ver
= pdev
->revision
;
2595 if (atpdev
->chip_ver
< 2)
2599 switch (ent
->device
) {
2600 case PCI_DEVICE_ID_ARTOP_AEC7612UW
:
2601 case PCI_DEVICE_ID_ARTOP_AEC7612SUW
:
2605 atpdev
->chip_ver
= 0x04;
2609 base_io
= pci_resource_start(pdev
, 0);
2610 base_io
&= 0xfffffff8;
2612 if ((ent
->device
== ATP880_DEVID1
)||(ent
->device
== ATP880_DEVID2
)) {
2613 atpdev
->chip_ver
= pdev
->revision
;
2614 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, 0x80);//JCC082803
2616 host_id
= inb(base_io
+ 0x39);
2619 printk(KERN_INFO
" ACARD AEC-67160 PCI Ultra3 LVD Host Adapter: %d"
2620 " IO:%x, IRQ:%d.\n", count
, base_io
, pdev
->irq
);
2621 atpdev
->ioport
[0] = base_io
+ 0x40;
2622 atpdev
->pciport
[0] = base_io
+ 0x28;
2623 atpdev
->dev_id
= ent
->device
;
2624 atpdev
->host_id
[0] = host_id
;
2626 tmport
= base_io
+ 0x22;
2627 atpdev
->scam_on
= inb(tmport
);
2629 atpdev
->global_map
[0] = inb(tmport
);
2631 atpdev
->ultra_map
[0] = inw(tmport
);
2639 outw(n
, base_io
+ 0x34);
2641 if (inb(base_io
+ 0x30) == 0xff)
2644 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x30);
2645 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x31);
2646 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x32);
2647 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x33);
2648 outw(n
, base_io
+ 0x34);
2650 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x30);
2651 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x31);
2652 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x32);
2653 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x33);
2654 outw(n
, base_io
+ 0x34);
2656 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x30);
2657 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x31);
2658 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x32);
2659 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x33);
2660 outw(n
, base_io
+ 0x34);
2662 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x30);
2663 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x31);
2664 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x32);
2665 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x33);
2669 outw(0, base_io
+ 0x34);
2670 atpdev
->ultra_map
[0] = 0;
2671 atpdev
->async
[0] = 0;
2672 for (k
= 0; k
< 16; k
++) {
2675 if (atpdev
->sp
[0][k
] > 1) {
2676 atpdev
->ultra_map
[0] |= n
;
2678 if (atpdev
->sp
[0][k
] == 0)
2679 atpdev
->async
[0] |= n
;
2682 atpdev
->async
[0] = ~(atpdev
->async
[0]);
2683 outb(atpdev
->global_map
[0], base_io
+ 0x35);
2685 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
2689 p
= (struct atp_unit
*)&shpnt
->hostdata
;
2691 atpdev
->host
= shpnt
;
2692 atpdev
->pdev
= pdev
;
2693 pci_set_drvdata(pdev
, p
);
2694 memcpy(p
, atpdev
, sizeof(*atpdev
));
2695 if (atp870u_init_tables(shpnt
) < 0) {
2696 printk(KERN_ERR
"Unable to allocate tables for Acard controller\n");
2700 if (request_irq(pdev
->irq
, atp870u_intr_handle
, IRQF_SHARED
, "atp880i", shpnt
)) {
2701 printk(KERN_ERR
"Unable to allocate IRQ%d for Acard controller.\n", pdev
->irq
);
2705 spin_lock_irqsave(shpnt
->host_lock
, flags
);
2706 tmport
= base_io
+ 0x38;
2707 k
= inb(tmport
) & 0x80;
2714 tmport
= base_io
+ 0x5b;
2718 tmport
= base_io
+ 0x40;
2719 outb((host_id
| 0x08), tmport
);
2723 while ((inb(tmport
) & 0x80) == 0)
2727 tmport
= base_io
+ 0x41;
2730 tmport
= base_io
+ 0x51;
2735 tmport
= base_io
+ 0x38;
2738 shpnt
->this_id
= host_id
;
2739 shpnt
->unique_id
= base_io
;
2740 shpnt
->io_port
= base_io
;
2741 shpnt
->n_io_port
= 0x60; /* Number of bytes of I/O space used */
2742 shpnt
->irq
= pdev
->irq
;
2743 } else if (ent
->device
== ATP885_DEVID
) {
2744 printk(KERN_INFO
" ACARD AEC-67162 PCI Ultra3 LVD Host Adapter: IO:%x, IRQ:%d.\n"
2745 , base_io
, pdev
->irq
);
2747 atpdev
->pdev
= pdev
;
2748 atpdev
->dev_id
= ent
->device
;
2749 atpdev
->baseport
= base_io
;
2750 atpdev
->ioport
[0] = base_io
+ 0x80;
2751 atpdev
->ioport
[1] = base_io
+ 0xc0;
2752 atpdev
->pciport
[0] = base_io
+ 0x40;
2753 atpdev
->pciport
[1] = base_io
+ 0x50;
2755 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
2759 p
= (struct atp_unit
*)&shpnt
->hostdata
;
2761 atpdev
->host
= shpnt
;
2762 atpdev
->pdev
= pdev
;
2763 pci_set_drvdata(pdev
, p
);
2764 memcpy(p
, atpdev
, sizeof(struct atp_unit
));
2765 if (atp870u_init_tables(shpnt
) < 0)
2769 printk("request_irq() shpnt %p hostdata %p\n", shpnt
, p
);
2771 if (request_irq(pdev
->irq
, atp870u_intr_handle
, IRQF_SHARED
, "atp870u", shpnt
)) {
2772 printk(KERN_ERR
"Unable to allocate IRQ for Acard controller.\n");
2776 spin_lock_irqsave(shpnt
->host_lock
, flags
);
2778 c
=inb(base_io
+ 0x29);
2779 outb((c
| 0x04),base_io
+ 0x29);
2786 outw(n
,base_io
+ 0x3c);
2787 if (inl(base_io
+ 0x38) == 0xffffffff) {
2790 for (m
=0; m
< 2; m
++) {
2791 p
->global_map
[m
]= 0;
2792 for (k
=0; k
< 4; k
++) {
2793 outw(n
++,base_io
+ 0x3c);
2794 ((unsigned long *)&setupdata
[m
][0])[k
]=inl(base_io
+ 0x38);
2796 for (k
=0; k
< 4; k
++) {
2797 outw(n
++,base_io
+ 0x3c);
2798 ((unsigned long *)&p
->sp
[m
][0])[k
]=inl(base_io
+ 0x38);
2805 printk( "Flash Read OK\n");
2807 c
=inb(base_io
+ 0x29);
2808 outb((c
& 0xfb),base_io
+ 0x29);
2809 for (c
=0;c
< 2;c
++) {
2812 for (k
=0; k
< 16; k
++) {
2815 if (p
->sp
[c
][k
] > 1) {
2816 p
->ultra_map
[c
] |= n
;
2818 if (p
->sp
[c
][k
] == 0) {
2823 p
->async
[c
] = ~(p
->async
[c
]);
2825 if (p
->global_map
[c
] == 0) {
2827 if ((k
& 0x40) != 0)
2828 p
->global_map
[c
] |= 0x20;
2830 p
->global_map
[c
] |= k
;
2831 if ((setupdata
[c
][2] & 0x04) != 0)
2832 p
->global_map
[c
] |= 0x08;
2833 p
->host_id
[c
] = setupdata
[c
][0] & 0x07;
2837 k
= inb(base_io
+ 0x28) & 0x8f;
2839 outb(k
, base_io
+ 0x28);
2840 outb(0x80, base_io
+ 0x41);
2841 outb(0x80, base_io
+ 0x51);
2843 outb(0, base_io
+ 0x41);
2844 outb(0, base_io
+ 0x51);
2846 inb(base_io
+ 0x9b);
2847 inb(base_io
+ 0x97);
2848 inb(base_io
+ 0xdb);
2849 inb(base_io
+ 0xd7);
2850 tmport
= base_io
+ 0x80;
2853 k
= (k
& 0x07) | 0x40;
2860 while ((inb(tmport
) & 0x80) == 0)
2865 tmport
= base_io
+ 0x81;
2868 tmport
= base_io
+ 0x91;
2871 tmport
= base_io
+ 0xc0;
2874 k
= (k
& 0x07) | 0x40;
2881 while ((inb(tmport
) & 0x80) == 0)
2886 tmport
= base_io
+ 0xc1;
2889 tmport
= base_io
+ 0xd1;
2893 printk(KERN_INFO
" Scanning Channel A SCSI Device ...\n");
2894 is885(p
, base_io
+ 0x80, 0);
2895 printk(KERN_INFO
" Scanning Channel B SCSI Device ...\n");
2896 is885(p
, base_io
+ 0xc0, 1);
2898 k
= inb(base_io
+ 0x28) & 0xcf;
2900 outb(k
, base_io
+ 0x28);
2901 k
= inb(base_io
+ 0x1f) | 0x80;
2902 outb(k
, base_io
+ 0x1f);
2903 k
= inb(base_io
+ 0x29) | 0x01;
2904 outb(k
, base_io
+ 0x29);
2906 //printk("atp885: atp_host[0] 0x%p\n", atp_host[0]);
2909 shpnt
->max_lun
= (p
->global_map
[0] & 0x07) + 1;
2910 shpnt
->max_channel
= 1;
2911 shpnt
->this_id
= p
->host_id
[0];
2912 shpnt
->unique_id
= base_io
;
2913 shpnt
->io_port
= base_io
;
2914 shpnt
->n_io_port
= 0xff; /* Number of bytes of I/O space used */
2915 shpnt
->irq
= pdev
->irq
;
2918 error
= pci_read_config_byte(pdev
, 0x49, &host_id
);
2920 printk(KERN_INFO
" ACARD AEC-671X PCI Ultra/W SCSI-2/3 Host Adapter: %d "
2921 "IO:%x, IRQ:%d.\n", count
, base_io
, pdev
->irq
);
2923 atpdev
->ioport
[0] = base_io
;
2924 atpdev
->pciport
[0] = base_io
+ 0x20;
2925 atpdev
->dev_id
= ent
->device
;
2927 atpdev
->host_id
[0] = host_id
;
2928 tmport
= base_io
+ 0x22;
2929 atpdev
->scam_on
= inb(tmport
);
2931 atpdev
->global_map
[0] = inb(tmport
++);
2932 atpdev
->ultra_map
[0] = inw(tmport
);
2934 if (atpdev
->ultra_map
[0] == 0) {
2935 atpdev
->scam_on
= 0x00;
2936 atpdev
->global_map
[0] = 0x20;
2937 atpdev
->ultra_map
[0] = 0xffff;
2940 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
2944 p
= (struct atp_unit
*)&shpnt
->hostdata
;
2946 atpdev
->host
= shpnt
;
2947 atpdev
->pdev
= pdev
;
2948 pci_set_drvdata(pdev
, p
);
2949 memcpy(p
, atpdev
, sizeof(*atpdev
));
2950 if (atp870u_init_tables(shpnt
) < 0)
2953 if (request_irq(pdev
->irq
, atp870u_intr_handle
, IRQF_SHARED
, "atp870i", shpnt
)) {
2954 printk(KERN_ERR
"Unable to allocate IRQ%d for Acard controller.\n", pdev
->irq
);
2958 spin_lock_irqsave(shpnt
->host_lock
, flags
);
2959 if (atpdev
->chip_ver
> 0x07) { /* check if atp876 chip then enable terminator */
2960 tmport
= base_io
+ 0x3e;
2964 tmport
= base_io
+ 0x3a;
2965 k
= (inb(tmport
) & 0xf3) | 0x10;
2967 outb((k
& 0xdf), tmport
);
2972 outb((host_id
| 0x08), tmport
);
2976 while ((inb(tmport
) & 0x80) == 0)
2981 tmport
= base_io
+ 1;
2984 tmport
= base_io
+ 0x11;
2989 tmport
= base_io
+ 0x3a;
2990 outb((inb(tmport
) & 0xef), tmport
);
2992 outb((inb(tmport
) | 0x20), tmport
);
2993 if (atpdev
->chip_ver
== 4)
2997 shpnt
->this_id
= host_id
;
2998 shpnt
->unique_id
= base_io
;
2999 shpnt
->io_port
= base_io
;
3000 shpnt
->n_io_port
= 0x40; /* Number of bytes of I/O space used */
3001 shpnt
->irq
= pdev
->irq
;
3003 spin_unlock_irqrestore(shpnt
->host_lock
, flags
);
3004 if(ent
->device
==ATP885_DEVID
) {
3005 if(!request_region(base_io
, 0xff, "atp870u")) /* Register the IO ports that we use */
3006 goto request_io_fail
;
3007 } else if((ent
->device
==ATP880_DEVID1
)||(ent
->device
==ATP880_DEVID2
)) {
3008 if(!request_region(base_io
, 0x60, "atp870u")) /* Register the IO ports that we use */
3009 goto request_io_fail
;
3011 if(!request_region(base_io
, 0x40, "atp870u")) /* Register the IO ports that we use */
3012 goto request_io_fail
;
3015 if (scsi_add_host(shpnt
, &pdev
->dev
))
3017 scsi_scan_host(shpnt
);
3019 printk("atp870u_prob : exit\n");
3024 printk("atp870u_prob:scsi_add_fail\n");
3025 if(ent
->device
==ATP885_DEVID
) {
3026 release_region(base_io
, 0xff);
3027 } else if((ent
->device
==ATP880_DEVID1
)||(ent
->device
==ATP880_DEVID2
)) {
3028 release_region(base_io
, 0x60);
3030 release_region(base_io
, 0x40);
3033 printk("atp870u_prob:request_io_fail\n");
3034 free_irq(pdev
->irq
, shpnt
);
3036 printk("atp870u_prob:free_table\n");
3037 atp870u_free_tables(shpnt
);
3039 printk("atp870u_prob:unregister\n");
3040 scsi_host_put(shpnt
);
3050 /* The abort command does not leave the device in a clean state where
3051 it is available to be used again. Until this gets worked out, we will
3052 leave it commented out. */
3054 static int atp870u_abort(struct scsi_cmnd
* SCpnt
)
3056 unsigned char j
, k
, c
;
3057 struct scsi_cmnd
*workrequ
;
3058 unsigned int tmport
;
3059 struct atp_unit
*dev
;
3060 struct Scsi_Host
*host
;
3061 host
= SCpnt
->device
->host
;
3063 dev
= (struct atp_unit
*)&host
->hostdata
;
3064 c
= scmd_channel(SCpnt
);
3065 printk(" atp870u: abort Channel = %x \n", c
);
3066 printk("working=%x last_cmd=%x ", dev
->working
[c
], dev
->last_cmd
[c
]);
3067 printk(" quhdu=%x quendu=%x ", dev
->quhd
[c
], dev
->quend
[c
]);
3068 tmport
= dev
->ioport
[c
];
3069 for (j
= 0; j
< 0x18; j
++) {
3070 printk(" r%2x=%2x", j
, inb(tmport
++));
3073 printk(" r1c=%2x", inb(tmport
));
3075 printk(" r1f=%2x in_snd=%2x ", inb(tmport
), dev
->in_snd
[c
]);
3076 tmport
= dev
->pciport
[c
];
3077 printk(" d00=%2x", inb(tmport
));
3079 printk(" d02=%2x", inb(tmport
));
3081 if (dev
->id
[c
][j
].curr_req
!= NULL
) {
3082 workrequ
= dev
->id
[c
][j
].curr_req
;
3083 printk("\n que cdb= ");
3084 for (k
=0; k
< workrequ
->cmd_len
; k
++) {
3085 printk(" %2x ",workrequ
->cmnd
[k
]);
3087 printk(" last_lenu= %x ",(unsigned int)dev
->id
[c
][j
].last_len
);
3093 static const char *atp870u_info(struct Scsi_Host
*notused
)
3095 static char buffer
[128];
3097 strcpy(buffer
, "ACARD AEC-6710/6712/67160 PCI Ultra/W/LVD SCSI-3 Adapter Driver V2.6+ac ");
3102 static int atp870u_show_info(struct seq_file
*m
, struct Scsi_Host
*HBAptr
)
3104 seq_printf(m
, "ACARD AEC-671X Driver Version: 2.6+ac\n");
3105 seq_printf(m
, "\n");
3106 seq_printf(m
, "Adapter Configuration:\n");
3107 seq_printf(m
, " Base IO: %#.4lx\n", HBAptr
->io_port
);
3108 seq_printf(m
, " IRQ: %d\n", HBAptr
->irq
);
3113 static int atp870u_biosparam(struct scsi_device
*disk
, struct block_device
*dev
,
3114 sector_t capacity
, int *ip
)
3116 int heads
, sectors
, cylinders
;
3120 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
3121 if (cylinders
> 1024) {
3124 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
3133 static void atp870u_remove (struct pci_dev
*pdev
)
3135 struct atp_unit
*devext
= pci_get_drvdata(pdev
);
3136 struct Scsi_Host
*pshost
= devext
->host
;
3139 scsi_remove_host(pshost
);
3140 printk(KERN_INFO
"free_irq : %d\n",pshost
->irq
);
3141 free_irq(pshost
->irq
, pshost
);
3142 release_region(pshost
->io_port
, pshost
->n_io_port
);
3143 printk(KERN_INFO
"atp870u_free_tables : %p\n",pshost
);
3144 atp870u_free_tables(pshost
);
3145 printk(KERN_INFO
"scsi_host_put : %p\n",pshost
);
3146 scsi_host_put(pshost
);
3147 printk(KERN_INFO
"pci_set_drvdata : %p\n",pdev
);
3148 pci_set_drvdata(pdev
, NULL
);
3150 MODULE_LICENSE("GPL");
3152 static struct scsi_host_template atp870u_template
= {
3153 .module
= THIS_MODULE
,
3154 .name
= "atp870u" /* name */,
3155 .proc_name
= "atp870u",
3156 .show_info
= atp870u_show_info
,
3157 .info
= atp870u_info
/* info */,
3158 .queuecommand
= atp870u_queuecommand
/* queuecommand */,
3159 .eh_abort_handler
= atp870u_abort
/* abort */,
3160 .bios_param
= atp870u_biosparam
/* biosparm */,
3161 .can_queue
= qcnt
/* can_queue */,
3162 .this_id
= 7 /* SCSI ID */,
3163 .sg_tablesize
= ATP870U_SCATTER
/*SG_ALL*/ /*SG_NONE*/,
3164 .cmd_per_lun
= ATP870U_CMDLUN
/* commands per lun */,
3165 .use_clustering
= ENABLE_CLUSTERING
,
3166 .max_sectors
= ATP870U_MAX_SECTORS
,
3169 static struct pci_device_id atp870u_id_table
[] = {
3170 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP885_DEVID
) },
3171 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP880_DEVID1
) },
3172 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP880_DEVID2
) },
3173 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7610
) },
3174 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612UW
) },
3175 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612U
) },
3176 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612S
) },
3177 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612D
) },
3178 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612SUW
) },
3179 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_8060
) },
3183 MODULE_DEVICE_TABLE(pci
, atp870u_id_table
);
3185 static struct pci_driver atp870u_driver
= {
3186 .id_table
= atp870u_id_table
,
3188 .probe
= atp870u_probe
,
3189 .remove
= atp870u_remove
,
3192 static int __init
atp870u_init(void)
3195 printk("atp870u_init: Entry\n");
3197 return pci_register_driver(&atp870u_driver
);
3200 static void __exit
atp870u_exit(void)
3203 printk("atp870u_exit: Entry\n");
3205 pci_unregister_driver(&atp870u_driver
);
3208 static void tscam_885(void)
3212 for (i
= 0; i
< 0x2; i
++) {
3220 static void is885(struct atp_unit
*dev
, unsigned int wkport
,unsigned char c
)
3222 unsigned int tmport
;
3223 unsigned char i
, j
, k
, rmb
, n
, lvdmode
;
3224 unsigned short int m
;
3225 static unsigned char mbuf
[512];
3226 static unsigned char satn
[9] = {0, 0, 0, 0, 0, 0, 0, 6, 6};
3227 static unsigned char inqd
[9] = {0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6};
3228 static unsigned char synn
[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
3229 unsigned char synu
[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
3230 static unsigned char synw
[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
3231 unsigned char synuw
[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
3232 static unsigned char wide
[6] = {0x80, 1, 2, 3, 1, 0};
3233 static unsigned char u3
[9] = { 0x80,1,6,4,0x09,00,0x0e,0x01,0x02 };
3235 lvdmode
=inb(wkport
+ 0x1b) >> 7;
3237 for (i
= 0; i
< 16; i
++) {
3240 if ((m
& dev
->active_id
[c
]) != 0) {
3243 if (i
== dev
->host_id
[c
]) {
3244 printk(KERN_INFO
" ID: %2d Host Adapter\n", dev
->host_id
[c
]);
3247 tmport
= wkport
+ 0x1b;
3249 tmport
= wkport
+ 0x01;
3250 outb(0x08, tmport
++);
3251 outb(0x7f, tmport
++);
3252 outb(satn
[0], tmport
++);
3253 outb(satn
[1], tmport
++);
3254 outb(satn
[2], tmport
++);
3255 outb(satn
[3], tmport
++);
3256 outb(satn
[4], tmport
++);
3257 outb(satn
[5], tmport
++);
3261 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3264 outb(satn
[6], tmport
++);
3265 outb(satn
[7], tmport
++);
3267 if ((j
& 0x08) != 0) {
3268 j
= (j
& 0x07) | 0x40;
3272 outb(satn
[8], tmport
);
3275 while ((inb(tmport
) & 0x80) == 0x00)
3278 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3281 while (inb(tmport
) != 0x8e)
3283 dev
->active_id
[c
] |= m
;
3285 tmport
= wkport
+ 0x10;
3287 tmport
= wkport
+ 0x14;
3291 tmport
= wkport
+ 0x18;
3294 while ((inb(tmport
) & 0x80) == 0x00)
3299 tmport
= wkport
+ 0x10;
3304 tmport
= wkport
+ 0x03;
3305 outb(inqd
[0], tmport
++);
3306 outb(inqd
[1], tmport
++);
3307 outb(inqd
[2], tmport
++);
3308 outb(inqd
[3], tmport
++);
3309 outb(inqd
[4], tmport
++);
3310 outb(inqd
[5], tmport
);
3314 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3316 outb(inqd
[6], tmport
++);
3317 outb(inqd
[7], tmport
++);
3319 outb(inqd
[8], tmport
);
3321 while ((inb(tmport
) & 0x80) == 0x00)
3324 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3327 while (inb(tmport
) != 0x8e)
3329 tmport
= wkport
+ 0x1b;
3331 tmport
= wkport
+ 0x18;
3337 if ((k
& 0x01) != 0) {
3339 mbuf
[j
++] = inb(tmport
);
3343 if ((k
& 0x80) == 0) {
3351 tmport
= wkport
+ 0x10;
3360 while ((inb(tmport
) & 0x80) == 0x00)
3363 if (inb(tmport
) != 0x16) {
3368 printk( KERN_INFO
" ID: %2d %s\n", i
, &mbuf
[8]);
3369 dev
->id
[c
][i
].devtype
= mbuf
[0];
3372 if ((mbuf
[7] & 0x60) == 0) {
3375 if ((i
< 8) && ((dev
->global_map
[c
] & 0x20) == 0)) {
3381 if (dev
->sp
[c
][i
] != 0x04) { // force u2
3385 tmport
= wkport
+ 0x1b;
3387 tmport
= wkport
+ 0x03;
3388 outb(satn
[0], tmport
++);
3389 outb(satn
[1], tmport
++);
3390 outb(satn
[2], tmport
++);
3391 outb(satn
[3], tmport
++);
3392 outb(satn
[4], tmport
++);
3393 outb(satn
[5], tmport
++);
3397 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3399 outb(satn
[6], tmport
++);
3400 outb(satn
[7], tmport
++);
3402 outb(satn
[8], tmport
);
3405 while ((inb(tmport
) & 0x80) == 0x00)
3408 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3411 while (inb(tmport
) != 0x8e)
3415 tmport
= wkport
+ 0x14;
3421 while ((inb(tmport
) & 0x80) == 0) {
3422 if ((inb(tmport
) & 0x01) != 0) {
3424 outb(u3
[j
++], tmport
);
3430 while ((inb(tmport
) & 0x80) == 0x00)
3432 j
= inb(tmport
) & 0x0f;
3444 tmport
= wkport
+ 0x18;
3447 while ((inb(tmport
) & 0x80) == 0) {
3448 if ((inb(tmport
) & 0x01) != 0) {
3456 j
= inb(tmport
) & 0x0f;
3468 tmport
= wkport
+ 0x14;
3476 if ((j
& 0x01) != 0) {
3478 mbuf
[k
++] = inb(tmport
);
3482 if ((j
& 0x80) == 0x00) {
3486 j
= inb(tmport
) & 0x0f;
3498 tmport
= wkport
+ 0x10;
3500 tmport
= wkport
+ 0x14;
3505 while ((inb(tmport
) & 0x80) == 0x00);
3514 if (mbuf
[0] != 0x01) {
3517 if (mbuf
[1] != 0x06) {
3520 if (mbuf
[2] != 0x04) {
3523 if (mbuf
[3] == 0x09) {
3526 dev
->wide_id
[c
] |= m
;
3527 dev
->id
[c
][i
].devsp
= 0xce;
3529 printk("dev->id[%2d][%2d].devsp = %2x\n",c
,i
,dev
->id
[c
][i
].devsp
);
3534 tmport
= wkport
+ 0x1b;
3536 tmport
= wkport
+ 0x03;
3537 outb(satn
[0], tmport
++);
3538 outb(satn
[1], tmport
++);
3539 outb(satn
[2], tmport
++);
3540 outb(satn
[3], tmport
++);
3541 outb(satn
[4], tmport
++);
3542 outb(satn
[5], tmport
++);
3546 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3548 outb(satn
[6], tmport
++);
3549 outb(satn
[7], tmport
++);
3551 outb(satn
[8], tmport
);
3554 while ((inb(tmport
) & 0x80) == 0x00)
3557 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3560 while (inb(tmport
) != 0x8e)
3564 tmport
= wkport
+ 0x14;
3570 while ((inb(tmport
) & 0x80) == 0) {
3571 if ((inb(tmport
) & 0x01) != 0) {
3573 outb(wide
[j
++], tmport
);
3579 while ((inb(tmport
) & 0x80) == 0x00)
3581 j
= inb(tmport
) & 0x0f;
3593 tmport
= wkport
+ 0x18;
3596 while ((inb(tmport
) & 0x80) == 0) {
3597 if ((inb(tmport
) & 0x01) != 0) {
3605 j
= inb(tmport
) & 0x0f;
3617 tmport
= wkport
+ 0x14;
3625 if ((j
& 0x01) != 0) {
3627 mbuf
[k
++] = inb(tmport
);
3631 if ((j
& 0x80) == 0x00) {
3635 j
= inb(tmport
) & 0x0f;
3647 tmport
= wkport
+ 0x10;
3649 tmport
= wkport
+ 0x14;
3654 while ((inb(tmport
) & 0x80) == 0x00)
3664 if (mbuf
[0] != 0x01) {
3667 if (mbuf
[1] != 0x02) {
3670 if (mbuf
[2] != 0x03) {
3673 if (mbuf
[3] != 0x01) {
3678 dev
->wide_id
[c
] |= m
;
3680 if ((dev
->id
[c
][i
].devtype
== 0x00) || (dev
->id
[c
][i
].devtype
== 0x07) ||
3681 ((dev
->id
[c
][i
].devtype
== 0x05) && ((n
& 0x10) != 0))) {
3684 if ((dev
->async
[c
] & m
) != 0) {
3690 if (dev
->sp
[c
][i
] == 0x02) {
3694 if (dev
->sp
[c
][i
] >= 0x03) {
3699 tmport
= wkport
+ 0x1b;
3701 if ((m
& dev
->wide_id
[c
]) != 0) {
3705 tmport
= wkport
+ 0x03;
3706 outb(satn
[0], tmport
++);
3707 outb(satn
[1], tmport
++);
3708 outb(satn
[2], tmport
++);
3709 outb(satn
[3], tmport
++);
3710 outb(satn
[4], tmport
++);
3711 outb(satn
[5], tmport
++);
3715 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3717 outb(satn
[6], tmport
++);
3718 outb(satn
[7], tmport
++);
3720 outb(satn
[8], tmport
);
3723 while ((inb(tmport
) & 0x80) == 0x00)
3726 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3729 while (inb(tmport
) != 0x8e)
3733 tmport
= wkport
+ 0x14;
3739 while ((inb(tmport
) & 0x80) == 0) {
3740 if ((inb(tmport
) & 0x01) != 0) {
3742 if ((m
& dev
->wide_id
[c
]) != 0) {
3743 if ((m
& dev
->ultra_map
[c
]) != 0) {
3744 outb(synuw
[j
++], tmport
);
3746 outb(synw
[j
++], tmport
);
3749 if ((m
& dev
->ultra_map
[c
]) != 0) {
3750 outb(synu
[j
++], tmport
);
3752 outb(synn
[j
++], tmport
);
3759 while ((inb(tmport
) & 0x80) == 0x00)
3761 j
= inb(tmport
) & 0x0f;
3773 tmport
= wkport
+ 0x18;
3776 while ((inb(tmport
) & 0x80) == 0x00) {
3777 if ((inb(tmport
) & 0x01) != 0x00) {
3801 tmport
= wkport
+ 0x14;
3809 if ((j
& 0x01) != 0x00) {
3811 mbuf
[k
++] = inb(tmport
);
3815 if ((j
& 0x80) == 0x00) {
3819 while ((inb(tmport
) & 0x80) == 0x00);
3836 tmport
= wkport
+ 0x10;
3839 tmport
= wkport
+ 0x14;
3844 while ((inb(tmport
) & 0x80) == 0x00)
3851 if (mbuf
[0] != 0x01) {
3854 if (mbuf
[1] != 0x03) {
3857 if (mbuf
[4] == 0x00) {
3860 if (mbuf
[3] > 0x64) {
3863 if (mbuf
[4] > 0x0e) {
3866 dev
->id
[c
][i
].devsp
= mbuf
[4];
3867 if (mbuf
[3] < 0x0c){
3871 if ((mbuf
[3] < 0x0d) && (rmb
== 0)) {
3875 if (mbuf
[3] < 0x1a) {
3879 if (mbuf
[3] < 0x33) {
3883 if (mbuf
[3] < 0x4c) {
3889 dev
->id
[c
][i
].devsp
= (dev
->id
[c
][i
].devsp
& 0x0f) | j
;
3891 printk("dev->id[%2d][%2d].devsp = %2x\n",c
,i
,dev
->id
[c
][i
].devsp
);
3894 tmport
= wkport
+ 0x16;
3898 module_init(atp870u_init
);
3899 module_exit(atp870u_exit
);