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 <asm/system.h>
35 #include <scsi/scsi.h>
36 #include <scsi/scsi_cmnd.h>
37 #include <scsi/scsi_device.h>
38 #include <scsi/scsi_host.h>
42 static struct scsi_host_template atp870u_template
;
43 static void send_s870(struct atp_unit
*dev
,unsigned char c
);
44 static void is885(struct atp_unit
*dev
, unsigned int wkport
,unsigned char c
);
45 static void tscam_885(void);
47 static irqreturn_t
atp870u_intr_handle(int irq
, void *dev_id
)
50 unsigned short int tmpcip
, id
;
51 unsigned char i
, j
, c
, target_id
, lun
,cmdp
;
53 struct scsi_cmnd
*workreq
;
54 unsigned int workport
, tmport
, tmport1
;
55 unsigned long adrcnt
, k
;
60 struct Scsi_Host
*host
= dev_id
;
61 struct atp_unit
*dev
= (struct atp_unit
*)&host
->hostdata
;
63 for (c
= 0; c
< 2; c
++) {
64 tmport
= dev
->ioport
[c
] + 0x1f;
75 printk("atp870u_intr_handle enter\n");
78 cmdp
= inb(dev
->ioport
[c
] + 0x10);
79 workport
= dev
->ioport
[c
];
80 if (dev
->working
[c
] != 0) {
81 if (dev
->dev_id
== ATP885_DEVID
) {
82 tmport1
= workport
+ 0x16;
83 if ((inb(tmport1
) & 0x80) == 0)
84 outb((inb(tmport1
) | 0x80), tmport1
);
86 tmpcip
= dev
->pciport
[c
];
87 if ((inb(tmpcip
) & 0x08) != 0)
90 for (k
=0; k
< 1000; k
++) {
91 if ((inb(tmpcip
) & 0x08) == 0) {
94 if ((inb(tmpcip
) & 0x01) == 0) {
100 tmpcip
= dev
->pciport
[c
];
106 if (dev
->dev_id
== ATP885_DEVID
) {
113 target_id
= inb(tmport
);
117 * Remap wide devices onto id numbers
120 if ((target_id
& 0x40) != 0) {
121 target_id
= (target_id
& 0x07) | 0x08;
126 if ((j
& 0x40) != 0) {
127 if (dev
->last_cmd
[c
] == 0xff) {
128 dev
->last_cmd
[c
] = target_id
;
130 dev
->last_cmd
[c
] |= 0x40;
132 if (dev
->dev_id
== ATP885_DEVID
)
133 dev
->r1f
[c
][target_id
] |= j
;
135 printk("atp870u_intr_handle status = %x\n",i
);
138 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
139 dev
->last_cmd
[c
] = 0xff;
141 if (dev
->dev_id
== ATP885_DEVID
) {
144 ((unsigned char *) &adrcnt
)[2] = inb(tmport
++);
145 ((unsigned char *) &adrcnt
)[1] = inb(tmport
++);
146 ((unsigned char *) &adrcnt
)[0] = inb(tmport
);
147 if (dev
->id
[c
][target_id
].last_len
!= adrcnt
)
149 k
= dev
->id
[c
][target_id
].last_len
;
151 dev
->id
[c
][target_id
].tran_len
= k
;
152 dev
->id
[c
][target_id
].last_len
= adrcnt
;
155 printk("tmport = %x dev->id[c][target_id].last_len = %d dev->id[c][target_id].tran_len = %d\n",tmport
,dev
->id
[c
][target_id
].last_len
,dev
->id
[c
][target_id
].tran_len
);
162 if (dev
->wide_id
[c
] != 0) {
163 tmport
= workport
+ 0x1b;
165 while ((inb(tmport
) & 0x01) != 0x01) {
170 * Issue more commands
172 spin_lock_irqsave(dev
->host
->host_lock
, flags
);
173 if (((dev
->quhd
[c
] != dev
->quend
[c
]) || (dev
->last_cmd
[c
] != 0xff)) &&
174 (dev
->in_snd
[c
] == 0)) {
176 printk("Call sent_s870\n");
180 spin_unlock_irqrestore(dev
->host
->host_lock
, flags
);
186 printk("Status 0x85 return\n");
192 dev
->last_cmd
[c
] |= 0x40;
198 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
199 dev
->last_cmd
[c
] = 0xff;
203 ((unsigned char *) &adrcnt
)[2] = inb(tmport
++);
204 ((unsigned char *) &adrcnt
)[1] = inb(tmport
++);
205 ((unsigned char *) &adrcnt
)[0] = inb(tmport
);
206 k
= dev
->id
[c
][target_id
].last_len
;
208 dev
->id
[c
][target_id
].tran_len
= k
;
209 dev
->id
[c
][target_id
].last_len
= adrcnt
;
218 if (dev
->dev_id
== ATP885_DEVID
) {
219 if ((i
== 0x4c) || (i
== 0x4d) || (i
== 0x8c) || (i
== 0x8d)) {
220 if ((i
== 0x4c) || (i
== 0x8c))
227 if ((i
== 0x80) || (i
== 0x8f)) {
229 printk(KERN_DEBUG
"Device reselect\n");
233 if (cmdp
== 0x44 || i
==0x80) {
235 lun
= inb(tmport
) & 0x07;
237 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
238 dev
->last_cmd
[c
] = 0xff;
242 printk("cmdp = 0x41\n");
246 ((unsigned char *) &adrcnt
)[2] = inb(tmport
++);
247 ((unsigned char *) &adrcnt
)[1] = inb(tmport
++);
248 ((unsigned char *) &adrcnt
)[0] = inb(tmport
);
249 k
= dev
->id
[c
][target_id
].last_len
;
251 dev
->id
[c
][target_id
].tran_len
= k
;
252 dev
->id
[c
][target_id
].last_len
= adrcnt
;
259 printk("cmdp != 0x41\n");
262 dev
->id
[c
][target_id
].dirct
= 0x00;
264 outb(0x00, tmport
++);
265 outb(0x00, tmport
++);
266 outb(0x00, tmport
++);
273 if (dev
->last_cmd
[c
] != 0xff) {
274 dev
->last_cmd
[c
] |= 0x40;
276 if (dev
->dev_id
== ATP885_DEVID
) {
277 j
= inb(dev
->baseport
+ 0x29) & 0xfe;
278 outb(j
, dev
->baseport
+ 0x29);
279 tmport
= workport
+ 0x16;
281 tmport
= workport
+ 0x10;
286 target_id
= inb(tmport
);
288 * Remap wide identifiers
290 if ((target_id
& 0x10) != 0) {
291 target_id
= (target_id
& 0x07) | 0x08;
295 if (dev
->dev_id
== ATP885_DEVID
) {
296 tmport
= workport
+ 0x10;
299 workreq
= dev
->id
[c
][target_id
].curr_req
;
301 scmd_printk(KERN_DEBUG
, workreq
, "CDB");
302 for (l
= 0; l
< workreq
->cmd_len
; l
++)
303 printk(KERN_DEBUG
" %x",workreq
->cmnd
[l
]);
307 tmport
= workport
+ 0x0f;
310 outb(dev
->id
[c
][target_id
].devsp
, tmport
++);
311 adrcnt
= dev
->id
[c
][target_id
].tran_len
;
312 k
= dev
->id
[c
][target_id
].last_len
;
314 outb(((unsigned char *) &k
)[2], tmport
++);
315 outb(((unsigned char *) &k
)[1], tmport
++);
316 outb(((unsigned char *) &k
)[0], tmport
++);
318 printk("k %x, k[0] 0x%x k[1] 0x%x k[2] 0x%x\n", k
, inb(tmport
-1), inb(tmport
-2), inb(tmport
-3));
323 j
= (j
& 0x07) | 0x40;
326 j
|= dev
->id
[c
][target_id
].dirct
;
330 /* enable 32 bit fifo transfer */
331 if (dev
->dev_id
== ATP885_DEVID
) {
332 tmpcip
= dev
->pciport
[c
] + 1;
333 i
=inb(tmpcip
) & 0xf3;
334 //j=workreq->cmnd[0];
335 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
339 } else if ((dev
->dev_id
== ATP880_DEVID1
) ||
340 (dev
->dev_id
== ATP880_DEVID2
) ) {
341 tmport
= workport
- 0x05;
342 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
343 outb((unsigned char) ((inb(tmport
) & 0x3f) | 0xc0), tmport
);
345 outb((unsigned char) (inb(tmport
) & 0x3f), tmport
);
348 tmport
= workport
+ 0x3a;
349 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
350 outb((unsigned char) ((inb(tmport
) & 0xf3) | 0x08), tmport
);
352 outb((unsigned char) (inb(tmport
) & 0xf3), tmport
);
355 tmport
= workport
+ 0x1b;
358 id
= id
<< target_id
;
360 * Is this a wide device
362 if ((id
& dev
->wide_id
[c
]) != 0) {
366 while ((inb(tmport
) & 0x01) != j
) {
369 if (dev
->id
[c
][target_id
].last_len
== 0) {
370 tmport
= workport
+ 0x18;
374 printk("dev->id[c][target_id].last_len = 0\n");
379 printk("target_id = %d adrcnt = %d\n",target_id
,adrcnt
);
381 prd
= dev
->id
[c
][target_id
].prd_pos
;
382 while (adrcnt
!= 0) {
383 id
= ((unsigned short int *)prd
)[2];
390 ((unsigned short int *)prd
)[2] = (unsigned short int)
392 ((unsigned long *)prd
)[0] += adrcnt
;
394 dev
->id
[c
][target_id
].prd_pos
= prd
;
397 dev
->id
[c
][target_id
].prdaddr
+= 0x08;
400 dev
->id
[c
][target_id
].prd_pos
= prd
;
404 tmpcip
= dev
->pciport
[c
] + 0x04;
405 outl(dev
->id
[c
][target_id
].prdaddr
, tmpcip
);
407 printk("dev->id[%d][%d].prdaddr 0x%8x\n", c
, target_id
, dev
->id
[c
][target_id
].prdaddr
);
409 if (dev
->dev_id
== ATP885_DEVID
) {
417 tmport
= workport
+ 0x18;
419 * Check transfer direction
421 if (dev
->id
[c
][target_id
].dirct
!= 0) {
426 printk("status 0x80 return dirct != 0\n");
434 printk("status 0x80 return dirct = 0\n");
440 * Current scsi request on this target
443 workreq
= dev
->id
[c
][target_id
].curr_req
;
446 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40)
448 dev
->last_cmd
[c
] = 0xff;
451 workreq
->result
= errstus
;
455 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
456 dev
->last_cmd
[c
] = 0xff;
460 errstus
= inb(tmport
);
461 if (((dev
->r1f
[c
][target_id
] & 0x10) != 0)&&(dev
->dev_id
==ATP885_DEVID
)) {
462 printk(KERN_WARNING
"AEC67162 CRC ERROR !\n");
465 workreq
->result
= errstus
;
467 if (dev
->dev_id
== ATP885_DEVID
) {
468 j
= inb(dev
->baseport
+ 0x29) | 0x01;
469 outb(j
, dev
->baseport
+ 0x29);
472 * Complete the command
474 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(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");
697 * send_s870 - send a command to the controller
700 * On entry there is work queued to be done. We move some of that work to the
703 * Caller holds the host lock.
705 static void send_s870(struct atp_unit
*dev
,unsigned char c
)
708 struct scsi_cmnd
*workreq
;
710 unsigned char j
, target_id
;
712 unsigned short int tmpcip
, w
;
713 unsigned long l
, bttl
= 0;
714 unsigned int workport
;
715 unsigned long sg_count
;
717 if (dev
->in_snd
[c
] != 0) {
719 printk("cmnd in_snd\n");
724 printk("Sent_s870 enter\n");
727 if ((dev
->last_cmd
[c
] != 0xff) && ((dev
->last_cmd
[c
] & 0x40) != 0)) {
728 dev
->last_cmd
[c
] &= 0x0f;
729 workreq
= dev
->id
[c
][dev
->last_cmd
[c
]].curr_req
;
730 if (workreq
!= NULL
) { /* check NULL pointer */
733 dev
->last_cmd
[c
] = 0xff;
734 if (dev
->quhd
[c
] == dev
->quend
[c
]) {
739 if ((dev
->last_cmd
[c
] != 0xff) && (dev
->working
[c
] != 0)) {
746 if (dev
->quhd
[c
] >= qcnt
) {
749 workreq
= dev
->quereq
[c
][dev
->quhd
[c
]];
750 if (dev
->id
[c
][scmd_id(workreq
)].curr_req
== NULL
) {
751 dev
->id
[c
][scmd_id(workreq
)].curr_req
= workreq
;
752 dev
->last_cmd
[c
] = scmd_id(workreq
);
760 workport
= dev
->ioport
[c
];
761 tmport
= workport
+ 0x1f;
762 if ((inb(tmport
) & 0xb0) != 0) {
765 tmport
= workport
+ 0x1c;
766 if (inb(tmport
) == 0) {
771 printk("Abort to Send\n");
773 dev
->last_cmd
[c
] |= 0x40;
778 printk("OK to Send\n");
779 scmd_printk(KERN_DEBUG
, workreq
, "CDB");
780 for(i
=0;i
<workreq
->cmd_len
;i
++) {
781 printk(" %x",workreq
->cmnd
[i
]);
785 l
= scsi_bufflen(workreq
);
787 if (dev
->dev_id
== ATP885_DEVID
) {
788 j
= inb(dev
->baseport
+ 0x29) & 0xfe;
789 outb(j
, dev
->baseport
+ 0x29);
790 dev
->r1f
[c
][scmd_id(workreq
)] = 0;
793 if (workreq
->cmnd
[0] == READ_CAPACITY
) {
797 if (workreq
->cmnd
[0] == 0x00) {
801 tmport
= workport
+ 0x1b;
803 target_id
= scmd_id(workreq
);
810 if ((w
& dev
->wide_id
[c
]) != 0) {
814 while ((inb(tmport
) & 0x01) != j
) {
817 printk("send_s870 while loop 1\n");
825 outb(workreq
->cmd_len
, tmport
++);
826 outb(0x2c, tmport
++);
827 if (dev
->dev_id
== ATP885_DEVID
) {
828 outb(0x7f, tmport
++);
830 outb(0xcf, tmport
++);
832 for (i
= 0; i
< workreq
->cmd_len
; i
++) {
833 outb(workreq
->cmnd
[i
], tmport
++);
835 tmport
= workport
+ 0x0f;
836 outb(workreq
->device
->lun
, tmport
);
841 outb(dev
->id
[c
][target_id
].devsp
, tmport
++);
843 printk("dev->id[%d][%d].devsp = %2x\n",c
,target_id
,dev
->id
[c
][target_id
].devsp
);
846 sg_count
= scsi_dma_map(workreq
);
848 * Write transfer size
850 outb((unsigned char) (((unsigned char *) (&l
))[2]), tmport
++);
851 outb((unsigned char) (((unsigned char *) (&l
))[1]), tmport
++);
852 outb((unsigned char) (((unsigned char *) (&l
))[0]), tmport
++);
854 dev
->id
[c
][j
].last_len
= l
;
855 dev
->id
[c
][j
].tran_len
= 0;
857 printk("dev->id[%2d][%2d].last_len = %d\n",c
,j
,dev
->id
[c
][j
].last_len
);
862 if ((j
& 0x08) != 0) {
863 j
= (j
& 0x07) | 0x40;
866 * Check transfer direction
868 if (workreq
->sc_data_direction
== DMA_TO_DEVICE
) {
869 outb((unsigned char) (j
| 0x20), tmport
++);
873 outb((unsigned char) (inb(tmport
) | 0x80), tmport
);
875 tmport
= workport
+ 0x1c;
876 dev
->id
[c
][target_id
].dirct
= 0;
878 if (inb(tmport
) == 0) {
879 tmport
= workport
+ 0x18;
881 printk("change SCSI_CMD_REG 0x08\n");
885 dev
->last_cmd
[c
] |= 0x40;
890 tmpcip
= dev
->pciport
[c
];
891 prd
= dev
->id
[c
][target_id
].prd_table
;
892 dev
->id
[c
][target_id
].prd_pos
= prd
;
895 * Now write the request list. Either as scatter/gather or as
900 struct scatterlist
*sgpnt
;
902 scsi_for_each_sg(workreq
, sgpnt
, sg_count
, j
) {
903 bttl
= sg_dma_address(sgpnt
);
906 printk("1. bttl %x, l %x\n",bttl
, l
);
908 while (l
> 0x10000) {
909 (((u16
*) (prd
))[i
+ 3]) = 0x0000;
910 (((u16
*) (prd
))[i
+ 2]) = 0x0000;
911 (((u32
*) (prd
))[i
>> 1]) = cpu_to_le32(bttl
);
916 (((u32
*) (prd
))[i
>> 1]) = cpu_to_le32(bttl
);
917 (((u16
*) (prd
))[i
+ 2]) = cpu_to_le16(l
);
918 (((u16
*) (prd
))[i
+ 3]) = 0;
921 (((u16
*) (prd
))[i
- 1]) = cpu_to_le16(0x8000);
923 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]));
924 printk("2. bttl %x, l %x\n",bttl
, l
);
929 printk("send_s870: prdaddr_2 0x%8x tmpcip %x target_id %d\n", dev
->id
[c
][target_id
].prdaddr
,tmpcip
,target_id
);
931 dev
->id
[c
][target_id
].prdaddr
= dev
->id
[c
][target_id
].prd_bus
;
932 outl(dev
->id
[c
][target_id
].prdaddr
, tmpcip
);
936 if (dev
->dev_id
== ATP885_DEVID
) {
938 j
=inb(tmpcip
) & 0xf3;
939 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) ||
940 (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
945 } else if ((dev
->dev_id
== ATP880_DEVID1
) ||
946 (dev
->dev_id
== ATP880_DEVID2
)) {
948 tmport
= workport
- 0x05;
949 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
950 outb((unsigned char) ((inb(tmport
) & 0x3f) | 0xc0), tmport
);
952 outb((unsigned char) (inb(tmport
) & 0x3f), tmport
);
956 tmport
= workport
+ 0x3a;
957 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
958 outb((inb(tmport
) & 0xf3) | 0x08, tmport
);
960 outb(inb(tmport
) & 0xf3, tmport
);
963 tmport
= workport
+ 0x1c;
965 if(workreq
->sc_data_direction
== DMA_TO_DEVICE
) {
966 dev
->id
[c
][target_id
].dirct
= 0x20;
967 if (inb(tmport
) == 0) {
968 tmport
= workport
+ 0x18;
972 printk( "start DMA(to target)\n");
975 dev
->last_cmd
[c
] |= 0x40;
980 if (inb(tmport
) == 0) {
981 tmport
= workport
+ 0x18;
985 printk( "start DMA(to host)\n");
988 dev
->last_cmd
[c
] |= 0x40;
995 static unsigned char fun_scam(struct atp_unit
*dev
, unsigned short int *val
)
998 unsigned short int i
, k
;
1001 tmport
= dev
->ioport
[0] + 0x1c;
1004 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
1006 j
= (unsigned char) (k
>> 8);
1007 if ((k
& 0x8000) != 0) { /* DB7 all release? */
1011 *val
|= 0x4000; /* assert DB6 */
1013 *val
&= 0xdfff; /* assert DB5 */
1016 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
1017 if ((inw(tmport
) & 0x2000) != 0) { /* DB5 all release? */
1021 *val
|= 0x8000; /* no DB4-0, assert DB7 */
1024 *val
&= 0xbfff; /* release DB6 */
1027 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
1028 if ((inw(tmport
) & 0x4000) != 0) { /* DB6 all release? */
1036 static void tscam(struct Scsi_Host
*host
)
1039 unsigned int tmport
;
1040 unsigned char i
, j
, k
;
1042 unsigned short int m
, assignid_map
, val
;
1043 unsigned char mbuf
[33], quintet
[2];
1044 struct atp_unit
*dev
= (struct atp_unit
*)&host
->hostdata
;
1045 static unsigned char g2q_tab
[8] = {
1046 0x38, 0x31, 0x32, 0x2b, 0x34, 0x2d, 0x2e, 0x27
1049 /* I can't believe we need this before we've even done anything. Remove it
1050 * and see if anyone bitches.
1051 for (i = 0; i < 0x10; i++) {
1056 tmport
= dev
->ioport
[0] + 1;
1057 outb(0x08, tmport
++);
1059 tmport
= dev
->ioport
[0] + 0x11;
1062 if ((dev
->scam_on
& 0x40) == 0) {
1066 m
<<= dev
->host_id
[0];
1068 if (dev
->chip_ver
< 4) {
1073 tmport
= dev
->ioport
[0] + 0x02;
1074 outb(0x02, tmport
++); /* 2*2=4ms,3EH 2/32*3E=3.9ms */
1082 for (i
= 0; i
< j
; i
++) {
1085 if ((m
& assignid_map
) != 0) {
1088 tmport
= dev
->ioport
[0] + 0x0f;
1095 k
= (i
& 0x07) | 0x40;
1100 tmport
= dev
->ioport
[0] + 0x1b;
1101 if (dev
->chip_ver
== 4) {
1107 tmport
= dev
->ioport
[0] + 0x18;
1111 while ((inb(tmport
) & 0x80) == 0x00)
1116 if ((k
== 0x85) || (k
== 0x42)) {
1119 tmport
= dev
->ioport
[0] + 0x10;
1126 tmport
= dev
->ioport
[0] + 0x02;
1128 tmport
= dev
->ioport
[0] + 0x1b;
1133 val
= 0x0080; /* bsy */
1134 tmport
= dev
->ioport
[0] + 0x1c;
1136 val
|= 0x0040; /* sel */
1138 val
|= 0x0004; /* msg */
1140 inb(0x80); /* 2 deskew delay(45ns*2=90ns) */
1141 val
&= 0x007f; /* no bsy */
1144 val
&= 0x00fb; /* after 1ms no msg */
1147 if ((inb(tmport
) & 0x04) != 0) {
1152 for (n
= 0; n
< 0x30000; n
++) {
1153 if ((inb(tmport
) & 0x80) != 0) { /* bsy ? */
1159 for (n
= 0; n
< 0x30000; n
++) {
1160 if ((inb(tmport
) & 0x81) == 0x0081) {
1167 val
|= 0x8003; /* io,cd,db7 */
1170 val
&= 0x00bf; /* no sel */
1175 if ((inb(tmport
) & 0x80) == 0x00) { /* bsy ? */
1178 tmport
= dev
->ioport
[0] + 0x15;
1183 while ((inb(tmport
) & 0x80) == 0)
1189 val
&= 0x00ff; /* synchronization */
1191 fun_scam(dev
, &val
);
1193 val
&= 0x00ff; /* isolation */
1195 fun_scam(dev
, &val
);
1200 if ((inw(tmport
) & 0x2000) == 0) {
1204 val
&= 0x00ff; /* get ID_STRING */
1206 k
= fun_scam(dev
, &val
);
1207 if ((k
& 0x03) == 0) {
1212 if ((k
& 0x02) != 0) {
1223 TCM_5
: /* isolation complete.. */
1225 printk(" \n%x %x %x %s\n ",assignid_map,mbuf[0],mbuf[1],&mbuf[2]); */
1228 if ((j
& 0x20) != 0) { /* bit5=1:ID upto 7 */
1231 if ((j
& 0x06) == 0) { /* IDvalid? */
1238 if ((m
& assignid_map
) == 0) {
1245 G2Q5
: /* srch from max acceptable ID# */
1246 k
= i
; /* max acceptable ID# */
1250 if ((m
& assignid_map
) == 0) {
1257 G2Q_QUIN
: /* k=binID#, */
1260 quintet
[0] = 0x38; /* 1st dft ID<8 */
1262 quintet
[0] = 0x31; /* 1st ID>=8 */
1265 quintet
[1] = g2q_tab
[k
];
1267 val
&= 0x00ff; /* AssignID 1stQuintet,AH=001xxxxx */
1268 m
= quintet
[0] << 8;
1270 fun_scam(dev
, &val
);
1271 val
&= 0x00ff; /* AssignID 2ndQuintet,AH=001xxxxx */
1272 m
= quintet
[1] << 8;
1274 fun_scam(dev
, &val
);
1280 static void is870(struct atp_unit
*dev
, unsigned int wkport
)
1282 unsigned int tmport
;
1283 unsigned char i
, j
, k
, rmb
, n
;
1284 unsigned short int m
;
1285 static unsigned char mbuf
[512];
1286 static unsigned char satn
[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
1287 static unsigned char inqd
[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
1288 static unsigned char synn
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1289 static unsigned char synu
[6] = { 0x80, 1, 3, 1, 0x0c, 0x0e };
1290 static unsigned char synw
[6] = { 0x80, 1, 3, 1, 0x0c, 0x07 };
1291 static unsigned char wide
[6] = { 0x80, 1, 2, 3, 1, 0 };
1293 tmport
= wkport
+ 0x3a;
1294 outb((unsigned char) (inb(tmport
) | 0x10), tmport
);
1296 for (i
= 0; i
< 16; i
++) {
1297 if ((dev
->chip_ver
!= 4) && (i
> 7)) {
1302 if ((m
& dev
->active_id
[0]) != 0) {
1305 if (i
== dev
->host_id
[0]) {
1306 printk(KERN_INFO
" ID: %2d Host Adapter\n", dev
->host_id
[0]);
1309 tmport
= wkport
+ 0x1b;
1310 if (dev
->chip_ver
== 4) {
1315 tmport
= wkport
+ 1;
1316 outb(0x08, tmport
++);
1317 outb(0x7f, tmport
++);
1318 outb(satn
[0], tmport
++);
1319 outb(satn
[1], tmport
++);
1320 outb(satn
[2], tmport
++);
1321 outb(satn
[3], tmport
++);
1322 outb(satn
[4], tmport
++);
1323 outb(satn
[5], tmport
++);
1327 outb(dev
->id
[0][i
].devsp
, tmport
++);
1329 outb(satn
[6], tmport
++);
1330 outb(satn
[7], tmport
++);
1332 if ((j
& 0x08) != 0) {
1333 j
= (j
& 0x07) | 0x40;
1337 outb(satn
[8], tmport
);
1340 while ((inb(tmport
) & 0x80) == 0x00)
1344 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1347 while (inb(tmport
) != 0x8e)
1350 dev
->active_id
[0] |= m
;
1352 tmport
= wkport
+ 0x10;
1354 tmport
= wkport
+ 0x04;
1358 tmport
= wkport
+ 0x18;
1361 while ((inb(tmport
) & 0x80) == 0x00)
1366 tmport
= wkport
+ 0x10;
1371 tmport
= wkport
+ 3;
1372 outb(inqd
[0], tmport
++);
1373 outb(inqd
[1], tmport
++);
1374 outb(inqd
[2], tmport
++);
1375 outb(inqd
[3], tmport
++);
1376 outb(inqd
[4], tmport
++);
1377 outb(inqd
[5], tmport
);
1381 outb(dev
->id
[0][i
].devsp
, tmport
++);
1383 outb(inqd
[6], tmport
++);
1384 outb(inqd
[7], tmport
++);
1386 outb(inqd
[8], tmport
);
1389 while ((inb(tmport
) & 0x80) == 0x00)
1393 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1396 while (inb(tmport
) != 0x8e)
1399 tmport
= wkport
+ 0x1b;
1400 if (dev
->chip_ver
== 4)
1403 tmport
= wkport
+ 0x18;
1409 if ((k
& 0x01) != 0) {
1411 mbuf
[j
++] = inb(tmport
);
1415 if ((k
& 0x80) == 0) {
1423 tmport
= wkport
+ 0x10;
1433 while ((inb(tmport
) & 0x80) == 0x00)
1437 if (inb(tmport
) != 0x16) {
1442 printk(KERN_INFO
" ID: %2d %s\n", i
, &mbuf
[8]);
1443 dev
->id
[0][i
].devtype
= mbuf
[0];
1446 if (dev
->chip_ver
!= 4) {
1449 if ((mbuf
[7] & 0x60) == 0) {
1452 if ((dev
->global_map
[0] & 0x20) == 0) {
1455 tmport
= wkport
+ 0x1b;
1457 tmport
= wkport
+ 3;
1458 outb(satn
[0], tmport
++);
1459 outb(satn
[1], tmport
++);
1460 outb(satn
[2], tmport
++);
1461 outb(satn
[3], tmport
++);
1462 outb(satn
[4], tmport
++);
1463 outb(satn
[5], tmport
++);
1467 outb(dev
->id
[0][i
].devsp
, tmport
++);
1469 outb(satn
[6], tmport
++);
1470 outb(satn
[7], tmport
++);
1472 outb(satn
[8], tmport
);
1475 while ((inb(tmport
) & 0x80) == 0x00)
1479 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1482 while (inb(tmport
) != 0x8e)
1487 tmport
= wkport
+ 0x14;
1493 while ((inb(tmport
) & 0x80) == 0) {
1494 if ((inb(tmport
) & 0x01) != 0) {
1496 outb(wide
[j
++], tmport
);
1502 while ((inb(tmport
) & 0x80) == 0x00)
1505 j
= inb(tmport
) & 0x0f;
1517 tmport
= wkport
+ 0x18;
1520 while ((inb(tmport
) & 0x80) == 0) {
1521 if ((inb(tmport
) & 0x01) != 0) {
1528 j
= inb(tmport
) & 0x0f;
1540 tmport
= wkport
+ 0x14;
1548 if ((j
& 0x01) != 0) {
1550 mbuf
[k
++] = inb(tmport
);
1554 if ((j
& 0x80) == 0x00) {
1558 j
= inb(tmport
) & 0x0f;
1570 tmport
= wkport
+ 0x10;
1572 tmport
= wkport
+ 0x14;
1578 while ((inb(tmport
) & 0x80) == 0x00)
1589 if (mbuf
[0] != 0x01) {
1592 if (mbuf
[1] != 0x02) {
1595 if (mbuf
[2] != 0x03) {
1598 if (mbuf
[3] != 0x01) {
1603 dev
->wide_id
[0] |= m
;
1605 if ((dev
->id
[0][i
].devtype
== 0x00) || (dev
->id
[0][i
].devtype
== 0x07) || ((dev
->id
[0][i
].devtype
== 0x05) && ((n
& 0x10) != 0))) {
1610 tmport
= wkport
+ 0x1b;
1612 if ((m
& dev
->wide_id
[0]) != 0) {
1616 tmport
= wkport
+ 3;
1617 outb(satn
[0], tmport
++);
1618 outb(satn
[1], tmport
++);
1619 outb(satn
[2], tmport
++);
1620 outb(satn
[3], tmport
++);
1621 outb(satn
[4], tmport
++);
1622 outb(satn
[5], tmport
++);
1626 outb(dev
->id
[0][i
].devsp
, tmport
++);
1628 outb(satn
[6], tmport
++);
1629 outb(satn
[7], tmport
++);
1631 outb(satn
[8], tmport
);
1634 while ((inb(tmport
) & 0x80) == 0x00)
1638 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1641 while (inb(tmport
) != 0x8e)
1646 tmport
= wkport
+ 0x14;
1652 while ((inb(tmport
) & 0x80) == 0) {
1653 if ((inb(tmport
) & 0x01) != 0) {
1655 if ((m
& dev
->wide_id
[0]) != 0) {
1656 outb(synw
[j
++], tmport
);
1658 if ((m
& dev
->ultra_map
[0]) != 0) {
1659 outb(synu
[j
++], tmport
);
1661 outb(synn
[j
++], tmport
);
1669 while ((inb(tmport
) & 0x80) == 0x00)
1672 j
= inb(tmport
) & 0x0f;
1684 tmport
= wkport
+ 0x18;
1687 while ((inb(tmport
) & 0x80) == 0x00) {
1688 if ((inb(tmport
) & 0x01) != 0x00) {
1711 tmport
= wkport
+ 0x14;
1719 if ((j
& 0x01) != 0x00) {
1721 mbuf
[k
++] = inb(tmport
);
1725 if ((j
& 0x80) == 0x00) {
1730 while ((inb(tmport
) & 0x80) == 0x00)
1749 tmport
= wkport
+ 0x10;
1752 tmport
= wkport
+ 0x14;
1758 while ((inb(tmport
) & 0x80) == 0x00)
1766 if (mbuf
[0] != 0x01) {
1769 if (mbuf
[1] != 0x03) {
1772 if (mbuf
[4] == 0x00) {
1775 if (mbuf
[3] > 0x64) {
1778 if (mbuf
[4] > 0x0c) {
1781 dev
->id
[0][i
].devsp
= mbuf
[4];
1782 if ((mbuf
[3] < 0x0d) && (rmb
== 0)) {
1786 if (mbuf
[3] < 0x1a) {
1790 if (mbuf
[3] < 0x33) {
1794 if (mbuf
[3] < 0x4c) {
1800 dev
->id
[0][i
].devsp
= (dev
->id
[0][i
].devsp
& 0x0f) | j
;
1802 tmport
= wkport
+ 0x3a;
1803 outb((unsigned char) (inb(tmport
) & 0xef), tmport
);
1806 static void is880(struct atp_unit
*dev
, unsigned int wkport
)
1808 unsigned int tmport
;
1809 unsigned char i
, j
, k
, rmb
, n
, lvdmode
;
1810 unsigned short int m
;
1811 static unsigned char mbuf
[512];
1812 static unsigned char satn
[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
1813 static unsigned char inqd
[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
1814 static unsigned char synn
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1815 unsigned char synu
[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
1816 static unsigned char synw
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1817 unsigned char synuw
[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
1818 static unsigned char wide
[6] = { 0x80, 1, 2, 3, 1, 0 };
1819 static unsigned char u3
[9] = { 0x80, 1, 6, 4, 0x09, 00, 0x0e, 0x01, 0x02 };
1821 lvdmode
= inb(wkport
+ 0x3f) & 0x40;
1823 for (i
= 0; i
< 16; i
++) {
1826 if ((m
& dev
->active_id
[0]) != 0) {
1829 if (i
== dev
->host_id
[0]) {
1830 printk(KERN_INFO
" ID: %2d Host Adapter\n", dev
->host_id
[0]);
1833 tmport
= wkport
+ 0x5b;
1835 tmport
= wkport
+ 0x41;
1836 outb(0x08, tmport
++);
1837 outb(0x7f, tmport
++);
1838 outb(satn
[0], tmport
++);
1839 outb(satn
[1], tmport
++);
1840 outb(satn
[2], tmport
++);
1841 outb(satn
[3], tmport
++);
1842 outb(satn
[4], tmport
++);
1843 outb(satn
[5], tmport
++);
1847 outb(dev
->id
[0][i
].devsp
, tmport
++);
1849 outb(satn
[6], tmport
++);
1850 outb(satn
[7], tmport
++);
1852 if ((j
& 0x08) != 0) {
1853 j
= (j
& 0x07) | 0x40;
1857 outb(satn
[8], tmport
);
1860 while ((inb(tmport
) & 0x80) == 0x00)
1864 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1867 while (inb(tmport
) != 0x8e)
1870 dev
->active_id
[0] |= m
;
1872 tmport
= wkport
+ 0x50;
1874 tmport
= wkport
+ 0x54;
1878 tmport
= wkport
+ 0x58;
1882 while ((inb(tmport
) & 0x80) == 0x00)
1888 tmport
= wkport
+ 0x50;
1893 tmport
= wkport
+ 0x43;
1894 outb(inqd
[0], tmport
++);
1895 outb(inqd
[1], tmport
++);
1896 outb(inqd
[2], tmport
++);
1897 outb(inqd
[3], tmport
++);
1898 outb(inqd
[4], tmport
++);
1899 outb(inqd
[5], tmport
);
1903 outb(dev
->id
[0][i
].devsp
, tmport
++);
1905 outb(inqd
[6], tmport
++);
1906 outb(inqd
[7], tmport
++);
1908 outb(inqd
[8], tmport
);
1911 while ((inb(tmport
) & 0x80) == 0x00)
1915 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1918 while (inb(tmport
) != 0x8e)
1921 tmport
= wkport
+ 0x5b;
1923 tmport
= wkport
+ 0x58;
1929 if ((k
& 0x01) != 0) {
1931 mbuf
[j
++] = inb(tmport
);
1935 if ((k
& 0x80) == 0) {
1943 tmport
= wkport
+ 0x50;
1952 while ((inb(tmport
) & 0x80) == 0x00)
1956 if (inb(tmport
) != 0x16)
1961 printk(KERN_INFO
" ID: %2d %s\n", i
, &mbuf
[8]);
1962 dev
->id
[0][i
].devtype
= mbuf
[0];
1965 if ((mbuf
[7] & 0x60) == 0) {
1968 if ((i
< 8) && ((dev
->global_map
[0] & 0x20) == 0)) {
1974 if (dev
->sp
[0][i
] != 0x04) // force u2
1979 tmport
= wkport
+ 0x5b;
1981 tmport
= wkport
+ 0x43;
1982 outb(satn
[0], tmport
++);
1983 outb(satn
[1], tmport
++);
1984 outb(satn
[2], tmport
++);
1985 outb(satn
[3], tmport
++);
1986 outb(satn
[4], tmport
++);
1987 outb(satn
[5], tmport
++);
1991 outb(dev
->id
[0][i
].devsp
, tmport
++);
1993 outb(satn
[6], tmport
++);
1994 outb(satn
[7], tmport
++);
1996 outb(satn
[8], tmport
);
1999 while ((inb(tmport
) & 0x80) == 0x00)
2004 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
2007 while (inb(tmport
) != 0x8e)
2012 tmport
= wkport
+ 0x54;
2018 while ((inb(tmport
) & 0x80) == 0) {
2019 if ((inb(tmport
) & 0x01) != 0) {
2021 outb(u3
[j
++], tmport
);
2027 while ((inb(tmport
) & 0x80) == 0x00)
2030 j
= inb(tmport
) & 0x0f;
2042 tmport
= wkport
+ 0x58;
2045 while ((inb(tmport
) & 0x80) == 0) {
2046 if ((inb(tmport
) & 0x01) != 0) {
2053 j
= inb(tmport
) & 0x0f;
2065 tmport
= wkport
+ 0x54;
2073 if ((j
& 0x01) != 0) {
2075 mbuf
[k
++] = inb(tmport
);
2079 if ((j
& 0x80) == 0x00) {
2083 j
= inb(tmport
) & 0x0f;
2095 tmport
= wkport
+ 0x50;
2097 tmport
= wkport
+ 0x54;
2103 while ((inb(tmport
) & 0x80) == 0x00)
2114 if (mbuf
[0] != 0x01) {
2117 if (mbuf
[1] != 0x06) {
2120 if (mbuf
[2] != 0x04) {
2123 if (mbuf
[3] == 0x09) {
2126 dev
->wide_id
[0] |= m
;
2127 dev
->id
[0][i
].devsp
= 0xce;
2131 tmport
= wkport
+ 0x5b;
2133 tmport
= wkport
+ 0x43;
2134 outb(satn
[0], tmport
++);
2135 outb(satn
[1], tmport
++);
2136 outb(satn
[2], tmport
++);
2137 outb(satn
[3], tmport
++);
2138 outb(satn
[4], tmport
++);
2139 outb(satn
[5], tmport
++);
2143 outb(dev
->id
[0][i
].devsp
, tmport
++);
2145 outb(satn
[6], tmport
++);
2146 outb(satn
[7], tmport
++);
2148 outb(satn
[8], tmport
);
2151 while ((inb(tmport
) & 0x80) == 0x00)
2155 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
2158 while (inb(tmport
) != 0x8e)
2163 tmport
= wkport
+ 0x54;
2169 while ((inb(tmport
) & 0x80) == 0) {
2170 if ((inb(tmport
) & 0x01) != 0) {
2172 outb(wide
[j
++], tmport
);
2177 while ((inb(tmport
) & 0x80) == 0x00)
2180 j
= inb(tmport
) & 0x0f;
2192 tmport
= wkport
+ 0x58;
2195 while ((inb(tmport
) & 0x80) == 0) {
2196 if ((inb(tmport
) & 0x01) != 0) {
2203 j
= inb(tmport
) & 0x0f;
2215 tmport
= wkport
+ 0x54;
2223 if ((j
& 0x01) != 0) {
2225 mbuf
[k
++] = inb(tmport
);
2229 if ((j
& 0x80) == 0x00) {
2233 j
= inb(tmport
) & 0x0f;
2245 tmport
= wkport
+ 0x50;
2247 tmport
= wkport
+ 0x54;
2253 while ((inb(tmport
) & 0x80) == 0x00)
2264 if (mbuf
[0] != 0x01) {
2267 if (mbuf
[1] != 0x02) {
2270 if (mbuf
[2] != 0x03) {
2273 if (mbuf
[3] != 0x01) {
2278 dev
->wide_id
[0] |= m
;
2280 if ((dev
->id
[0][i
].devtype
== 0x00) || (dev
->id
[0][i
].devtype
== 0x07) || ((dev
->id
[0][i
].devtype
== 0x05) && ((n
& 0x10) != 0))) {
2283 if ((dev
->async
[0] & m
) != 0) {
2289 if (dev
->sp
[0][i
] == 0x02) {
2293 if (dev
->sp
[0][i
] >= 0x03) {
2298 tmport
= wkport
+ 0x5b;
2300 if ((m
& dev
->wide_id
[0]) != 0) {
2304 tmport
= wkport
+ 0x43;
2305 outb(satn
[0], tmport
++);
2306 outb(satn
[1], tmport
++);
2307 outb(satn
[2], tmport
++);
2308 outb(satn
[3], tmport
++);
2309 outb(satn
[4], tmport
++);
2310 outb(satn
[5], tmport
++);
2314 outb(dev
->id
[0][i
].devsp
, tmport
++);
2316 outb(satn
[6], tmport
++);
2317 outb(satn
[7], tmport
++);
2319 outb(satn
[8], tmport
);
2322 while ((inb(tmport
) & 0x80) == 0x00)
2326 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
2329 while (inb(tmport
) != 0x8e)
2334 tmport
= wkport
+ 0x54;
2340 while ((inb(tmport
) & 0x80) == 0) {
2341 if ((inb(tmport
) & 0x01) != 0) {
2343 if ((m
& dev
->wide_id
[0]) != 0) {
2344 if ((m
& dev
->ultra_map
[0]) != 0) {
2345 outb(synuw
[j
++], tmport
);
2347 outb(synw
[j
++], tmport
);
2350 if ((m
& dev
->ultra_map
[0]) != 0) {
2351 outb(synu
[j
++], tmport
);
2353 outb(synn
[j
++], tmport
);
2361 while ((inb(tmport
) & 0x80) == 0x00)
2364 j
= inb(tmport
) & 0x0f;
2376 tmport
= wkport
+ 0x58;
2379 while ((inb(tmport
) & 0x80) == 0x00) {
2380 if ((inb(tmport
) & 0x01) != 0x00) {
2403 tmport
= wkport
+ 0x54;
2411 if ((j
& 0x01) != 0x00) {
2413 mbuf
[k
++] = inb(tmport
);
2417 if ((j
& 0x80) == 0x00) {
2422 while ((inb(tmport
) & 0x80) == 0x00)
2441 tmport
= wkport
+ 0x50;
2444 tmport
= wkport
+ 0x54;
2450 while ((inb(tmport
) & 0x80) == 0x00)
2458 if (mbuf
[0] != 0x01) {
2461 if (mbuf
[1] != 0x03) {
2464 if (mbuf
[4] == 0x00) {
2467 if (mbuf
[3] > 0x64) {
2470 if (mbuf
[4] > 0x0e) {
2473 dev
->id
[0][i
].devsp
= mbuf
[4];
2474 if (mbuf
[3] < 0x0c) {
2478 if ((mbuf
[3] < 0x0d) && (rmb
== 0)) {
2482 if (mbuf
[3] < 0x1a) {
2486 if (mbuf
[3] < 0x33) {
2490 if (mbuf
[3] < 0x4c) {
2496 dev
->id
[0][i
].devsp
= (dev
->id
[0][i
].devsp
& 0x0f) | j
;
2500 static void atp870u_free_tables(struct Scsi_Host
*host
)
2502 struct atp_unit
*atp_dev
= (struct atp_unit
*)&host
->hostdata
;
2504 for (j
=0; j
< 2; j
++) {
2505 for (k
= 0; k
< 16; k
++) {
2506 if (!atp_dev
->id
[j
][k
].prd_table
)
2508 pci_free_consistent(atp_dev
->pdev
, 1024, atp_dev
->id
[j
][k
].prd_table
, atp_dev
->id
[j
][k
].prd_bus
);
2509 atp_dev
->id
[j
][k
].prd_table
= NULL
;
2514 static int atp870u_init_tables(struct Scsi_Host
*host
)
2516 struct atp_unit
*atp_dev
= (struct atp_unit
*)&host
->hostdata
;
2518 for(c
=0;c
< 2;c
++) {
2520 atp_dev
->id
[c
][k
].prd_table
= pci_alloc_consistent(atp_dev
->pdev
, 1024, &(atp_dev
->id
[c
][k
].prd_bus
));
2521 if (!atp_dev
->id
[c
][k
].prd_table
) {
2522 printk("atp870u_init_tables fail\n");
2523 atp870u_free_tables(host
);
2526 atp_dev
->id
[c
][k
].prdaddr
= atp_dev
->id
[c
][k
].prd_bus
;
2527 atp_dev
->id
[c
][k
].devsp
=0x20;
2528 atp_dev
->id
[c
][k
].devtype
= 0x7f;
2529 atp_dev
->id
[c
][k
].curr_req
= NULL
;
2532 atp_dev
->active_id
[c
] = 0;
2533 atp_dev
->wide_id
[c
] = 0;
2534 atp_dev
->host_id
[c
] = 0x07;
2535 atp_dev
->quhd
[c
] = 0;
2536 atp_dev
->quend
[c
] = 0;
2537 atp_dev
->last_cmd
[c
] = 0xff;
2538 atp_dev
->in_snd
[c
] = 0;
2539 atp_dev
->in_int
[c
] = 0;
2541 for (k
= 0; k
< qcnt
; k
++) {
2542 atp_dev
->quereq
[c
][k
] = NULL
;
2544 for (k
= 0; k
< 16; k
++) {
2545 atp_dev
->id
[c
][k
].curr_req
= NULL
;
2546 atp_dev
->sp
[c
][k
] = 0x04;
2552 /* return non-zero on detection */
2553 static int atp870u_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
2555 unsigned char k
, m
, c
;
2556 unsigned long flags
;
2557 unsigned int base_io
, tmport
, error
,n
;
2558 unsigned char host_id
;
2559 struct Scsi_Host
*shpnt
= NULL
;
2560 struct atp_unit
*atpdev
, *p
;
2561 unsigned char setupdata
[2][16];
2564 atpdev
= kzalloc(sizeof(*atpdev
), GFP_KERNEL
);
2568 if (pci_enable_device(pdev
))
2571 if (!pci_set_dma_mask(pdev
, DMA_32BIT_MASK
)) {
2572 printk(KERN_INFO
"atp870u: use 32bit DMA mask.\n");
2574 printk(KERN_ERR
"atp870u: DMA mask required but not available.\n");
2579 * It's probably easier to weed out some revisions like
2580 * this than via the PCI device table
2582 if (ent
->device
== PCI_DEVICE_ID_ARTOP_AEC7610
) {
2583 error
= pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &atpdev
->chip_ver
);
2584 if (atpdev
->chip_ver
< 2)
2588 switch (ent
->device
) {
2589 case PCI_DEVICE_ID_ARTOP_AEC7612UW
:
2590 case PCI_DEVICE_ID_ARTOP_AEC7612SUW
:
2594 atpdev
->chip_ver
= 0x04;
2598 base_io
= pci_resource_start(pdev
, 0);
2599 base_io
&= 0xfffffff8;
2601 if ((ent
->device
== ATP880_DEVID1
)||(ent
->device
== ATP880_DEVID2
)) {
2602 error
= pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &atpdev
->chip_ver
);
2603 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, 0x80);//JCC082803
2605 host_id
= inb(base_io
+ 0x39);
2608 printk(KERN_INFO
" ACARD AEC-67160 PCI Ultra3 LVD Host Adapter: %d"
2609 " IO:%x, IRQ:%d.\n", count
, base_io
, pdev
->irq
);
2610 atpdev
->ioport
[0] = base_io
+ 0x40;
2611 atpdev
->pciport
[0] = base_io
+ 0x28;
2612 atpdev
->dev_id
= ent
->device
;
2613 atpdev
->host_id
[0] = host_id
;
2615 tmport
= base_io
+ 0x22;
2616 atpdev
->scam_on
= inb(tmport
);
2618 atpdev
->global_map
[0] = inb(tmport
);
2620 atpdev
->ultra_map
[0] = inw(tmport
);
2628 outw(n
, base_io
+ 0x34);
2630 if (inb(base_io
+ 0x30) == 0xff)
2633 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x30);
2634 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x31);
2635 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x32);
2636 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x33);
2637 outw(n
, base_io
+ 0x34);
2639 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x30);
2640 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x31);
2641 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x32);
2642 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x33);
2643 outw(n
, base_io
+ 0x34);
2645 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x30);
2646 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x31);
2647 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x32);
2648 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x33);
2649 outw(n
, base_io
+ 0x34);
2651 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x30);
2652 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x31);
2653 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x32);
2654 atpdev
->sp
[0][m
++] = inb(base_io
+ 0x33);
2658 outw(0, base_io
+ 0x34);
2659 atpdev
->ultra_map
[0] = 0;
2660 atpdev
->async
[0] = 0;
2661 for (k
= 0; k
< 16; k
++) {
2664 if (atpdev
->sp
[0][k
] > 1) {
2665 atpdev
->ultra_map
[0] |= n
;
2667 if (atpdev
->sp
[0][k
] == 0)
2668 atpdev
->async
[0] |= n
;
2671 atpdev
->async
[0] = ~(atpdev
->async
[0]);
2672 outb(atpdev
->global_map
[0], base_io
+ 0x35);
2674 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
2678 p
= (struct atp_unit
*)&shpnt
->hostdata
;
2680 atpdev
->host
= shpnt
;
2681 atpdev
->pdev
= pdev
;
2682 pci_set_drvdata(pdev
, p
);
2683 memcpy(p
, atpdev
, sizeof(*atpdev
));
2684 if (atp870u_init_tables(shpnt
) < 0) {
2685 printk(KERN_ERR
"Unable to allocate tables for Acard controller\n");
2689 if (request_irq(pdev
->irq
, atp870u_intr_handle
, IRQF_SHARED
, "atp880i", shpnt
)) {
2690 printk(KERN_ERR
"Unable to allocate IRQ%d for Acard controller.\n", pdev
->irq
);
2694 spin_lock_irqsave(shpnt
->host_lock
, flags
);
2695 tmport
= base_io
+ 0x38;
2696 k
= inb(tmport
) & 0x80;
2703 tmport
= base_io
+ 0x5b;
2707 tmport
= base_io
+ 0x40;
2708 outb((host_id
| 0x08), tmport
);
2712 while ((inb(tmport
) & 0x80) == 0)
2716 tmport
= base_io
+ 0x41;
2719 tmport
= base_io
+ 0x51;
2724 tmport
= base_io
+ 0x38;
2727 shpnt
->this_id
= host_id
;
2728 shpnt
->unique_id
= base_io
;
2729 shpnt
->io_port
= base_io
;
2730 shpnt
->n_io_port
= 0x60; /* Number of bytes of I/O space used */
2731 shpnt
->irq
= pdev
->irq
;
2732 } else if (ent
->device
== ATP885_DEVID
) {
2733 printk(KERN_INFO
" ACARD AEC-67162 PCI Ultra3 LVD Host Adapter: IO:%x, IRQ:%d.\n"
2734 , base_io
, pdev
->irq
);
2736 atpdev
->pdev
= pdev
;
2737 atpdev
->dev_id
= ent
->device
;
2738 atpdev
->baseport
= base_io
;
2739 atpdev
->ioport
[0] = base_io
+ 0x80;
2740 atpdev
->ioport
[1] = base_io
+ 0xc0;
2741 atpdev
->pciport
[0] = base_io
+ 0x40;
2742 atpdev
->pciport
[1] = base_io
+ 0x50;
2744 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
2748 p
= (struct atp_unit
*)&shpnt
->hostdata
;
2750 atpdev
->host
= shpnt
;
2751 atpdev
->pdev
= pdev
;
2752 pci_set_drvdata(pdev
, p
);
2753 memcpy(p
, atpdev
, sizeof(struct atp_unit
));
2754 if (atp870u_init_tables(shpnt
) < 0)
2758 printk("request_irq() shpnt %p hostdata %p\n", shpnt
, p
);
2760 if (request_irq(pdev
->irq
, atp870u_intr_handle
, IRQF_SHARED
, "atp870u", shpnt
)) {
2761 printk(KERN_ERR
"Unable to allocate IRQ for Acard controller.\n");
2765 spin_lock_irqsave(shpnt
->host_lock
, flags
);
2767 c
=inb(base_io
+ 0x29);
2768 outb((c
| 0x04),base_io
+ 0x29);
2775 outw(n
,base_io
+ 0x3c);
2776 if (inl(base_io
+ 0x38) == 0xffffffff) {
2779 for (m
=0; m
< 2; m
++) {
2780 p
->global_map
[m
]= 0;
2781 for (k
=0; k
< 4; k
++) {
2782 outw(n
++,base_io
+ 0x3c);
2783 ((unsigned long *)&setupdata
[m
][0])[k
]=inl(base_io
+ 0x38);
2785 for (k
=0; k
< 4; k
++) {
2786 outw(n
++,base_io
+ 0x3c);
2787 ((unsigned long *)&p
->sp
[m
][0])[k
]=inl(base_io
+ 0x38);
2794 printk( "Flash Read OK\n");
2796 c
=inb(base_io
+ 0x29);
2797 outb((c
& 0xfb),base_io
+ 0x29);
2798 for (c
=0;c
< 2;c
++) {
2801 for (k
=0; k
< 16; k
++) {
2804 if (p
->sp
[c
][k
] > 1) {
2805 p
->ultra_map
[c
] |= n
;
2807 if (p
->sp
[c
][k
] == 0) {
2812 p
->async
[c
] = ~(p
->async
[c
]);
2814 if (p
->global_map
[c
] == 0) {
2816 if ((k
& 0x40) != 0)
2817 p
->global_map
[c
] |= 0x20;
2819 p
->global_map
[c
] |= k
;
2820 if ((setupdata
[c
][2] & 0x04) != 0)
2821 p
->global_map
[c
] |= 0x08;
2822 p
->host_id
[c
] = setupdata
[c
][0] & 0x07;
2826 k
= inb(base_io
+ 0x28) & 0x8f;
2828 outb(k
, base_io
+ 0x28);
2829 outb(0x80, base_io
+ 0x41);
2830 outb(0x80, base_io
+ 0x51);
2832 outb(0, base_io
+ 0x41);
2833 outb(0, base_io
+ 0x51);
2835 inb(base_io
+ 0x9b);
2836 inb(base_io
+ 0x97);
2837 inb(base_io
+ 0xdb);
2838 inb(base_io
+ 0xd7);
2839 tmport
= base_io
+ 0x80;
2842 k
= (k
& 0x07) | 0x40;
2849 while ((inb(tmport
) & 0x80) == 0)
2854 tmport
= base_io
+ 0x81;
2857 tmport
= base_io
+ 0x91;
2860 tmport
= base_io
+ 0xc0;
2863 k
= (k
& 0x07) | 0x40;
2870 while ((inb(tmport
) & 0x80) == 0)
2875 tmport
= base_io
+ 0xc1;
2878 tmport
= base_io
+ 0xd1;
2882 printk(KERN_INFO
" Scanning Channel A SCSI Device ...\n");
2883 is885(p
, base_io
+ 0x80, 0);
2884 printk(KERN_INFO
" Scanning Channel B SCSI Device ...\n");
2885 is885(p
, base_io
+ 0xc0, 1);
2887 k
= inb(base_io
+ 0x28) & 0xcf;
2889 outb(k
, base_io
+ 0x28);
2890 k
= inb(base_io
+ 0x1f) | 0x80;
2891 outb(k
, base_io
+ 0x1f);
2892 k
= inb(base_io
+ 0x29) | 0x01;
2893 outb(k
, base_io
+ 0x29);
2895 //printk("atp885: atp_host[0] 0x%p\n", atp_host[0]);
2898 shpnt
->max_lun
= (p
->global_map
[0] & 0x07) + 1;
2899 shpnt
->max_channel
= 1;
2900 shpnt
->this_id
= p
->host_id
[0];
2901 shpnt
->unique_id
= base_io
;
2902 shpnt
->io_port
= base_io
;
2903 shpnt
->n_io_port
= 0xff; /* Number of bytes of I/O space used */
2904 shpnt
->irq
= pdev
->irq
;
2907 error
= pci_read_config_byte(pdev
, 0x49, &host_id
);
2909 printk(KERN_INFO
" ACARD AEC-671X PCI Ultra/W SCSI-2/3 Host Adapter: %d "
2910 "IO:%x, IRQ:%d.\n", count
, base_io
, pdev
->irq
);
2912 atpdev
->ioport
[0] = base_io
;
2913 atpdev
->pciport
[0] = base_io
+ 0x20;
2914 atpdev
->dev_id
= ent
->device
;
2916 atpdev
->host_id
[0] = host_id
;
2917 tmport
= base_io
+ 0x22;
2918 atpdev
->scam_on
= inb(tmport
);
2920 atpdev
->global_map
[0] = inb(tmport
++);
2921 atpdev
->ultra_map
[0] = inw(tmport
);
2923 if (atpdev
->ultra_map
[0] == 0) {
2924 atpdev
->scam_on
= 0x00;
2925 atpdev
->global_map
[0] = 0x20;
2926 atpdev
->ultra_map
[0] = 0xffff;
2929 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
2933 p
= (struct atp_unit
*)&shpnt
->hostdata
;
2935 atpdev
->host
= shpnt
;
2936 atpdev
->pdev
= pdev
;
2937 pci_set_drvdata(pdev
, p
);
2938 memcpy(p
, atpdev
, sizeof(*atpdev
));
2939 if (atp870u_init_tables(shpnt
) < 0)
2942 if (request_irq(pdev
->irq
, atp870u_intr_handle
, IRQF_SHARED
, "atp870i", shpnt
)) {
2943 printk(KERN_ERR
"Unable to allocate IRQ%d for Acard controller.\n", pdev
->irq
);
2947 spin_lock_irqsave(shpnt
->host_lock
, flags
);
2948 if (atpdev
->chip_ver
> 0x07) { /* check if atp876 chip then enable terminator */
2949 tmport
= base_io
+ 0x3e;
2953 tmport
= base_io
+ 0x3a;
2954 k
= (inb(tmport
) & 0xf3) | 0x10;
2956 outb((k
& 0xdf), tmport
);
2961 outb((host_id
| 0x08), tmport
);
2965 while ((inb(tmport
) & 0x80) == 0)
2970 tmport
= base_io
+ 1;
2973 tmport
= base_io
+ 0x11;
2978 tmport
= base_io
+ 0x3a;
2979 outb((inb(tmport
) & 0xef), tmport
);
2981 outb((inb(tmport
) | 0x20), tmport
);
2982 if (atpdev
->chip_ver
== 4)
2986 shpnt
->this_id
= host_id
;
2987 shpnt
->unique_id
= base_io
;
2988 shpnt
->io_port
= base_io
;
2989 shpnt
->n_io_port
= 0x40; /* Number of bytes of I/O space used */
2990 shpnt
->irq
= pdev
->irq
;
2992 spin_unlock_irqrestore(shpnt
->host_lock
, flags
);
2993 if(ent
->device
==ATP885_DEVID
) {
2994 if(!request_region(base_io
, 0xff, "atp870u")) /* Register the IO ports that we use */
2995 goto request_io_fail
;
2996 } else if((ent
->device
==ATP880_DEVID1
)||(ent
->device
==ATP880_DEVID2
)) {
2997 if(!request_region(base_io
, 0x60, "atp870u")) /* Register the IO ports that we use */
2998 goto request_io_fail
;
3000 if(!request_region(base_io
, 0x40, "atp870u")) /* Register the IO ports that we use */
3001 goto request_io_fail
;
3004 if (scsi_add_host(shpnt
, &pdev
->dev
))
3006 scsi_scan_host(shpnt
);
3008 printk("atp870u_prob : exit\n");
3013 printk("atp870u_prob:scsi_add_fail\n");
3014 if(ent
->device
==ATP885_DEVID
) {
3015 release_region(base_io
, 0xff);
3016 } else if((ent
->device
==ATP880_DEVID1
)||(ent
->device
==ATP880_DEVID2
)) {
3017 release_region(base_io
, 0x60);
3019 release_region(base_io
, 0x40);
3022 printk("atp870u_prob:request_io_fail\n");
3023 free_irq(pdev
->irq
, shpnt
);
3025 printk("atp870u_prob:free_table\n");
3026 atp870u_free_tables(shpnt
);
3028 printk("atp870u_prob:unregister\n");
3029 scsi_host_put(shpnt
);
3039 /* The abort command does not leave the device in a clean state where
3040 it is available to be used again. Until this gets worked out, we will
3041 leave it commented out. */
3043 static int atp870u_abort(struct scsi_cmnd
* SCpnt
)
3045 unsigned char j
, k
, c
;
3046 struct scsi_cmnd
*workrequ
;
3047 unsigned int tmport
;
3048 struct atp_unit
*dev
;
3049 struct Scsi_Host
*host
;
3050 host
= SCpnt
->device
->host
;
3052 dev
= (struct atp_unit
*)&host
->hostdata
;
3053 c
= scmd_channel(SCpnt
);
3054 printk(" atp870u: abort Channel = %x \n", c
);
3055 printk("working=%x last_cmd=%x ", dev
->working
[c
], dev
->last_cmd
[c
]);
3056 printk(" quhdu=%x quendu=%x ", dev
->quhd
[c
], dev
->quend
[c
]);
3057 tmport
= dev
->ioport
[c
];
3058 for (j
= 0; j
< 0x18; j
++) {
3059 printk(" r%2x=%2x", j
, inb(tmport
++));
3062 printk(" r1c=%2x", inb(tmport
));
3064 printk(" r1f=%2x in_snd=%2x ", inb(tmport
), dev
->in_snd
[c
]);
3065 tmport
= dev
->pciport
[c
];
3066 printk(" d00=%2x", inb(tmport
));
3068 printk(" d02=%2x", inb(tmport
));
3070 if (dev
->id
[c
][j
].curr_req
!= NULL
) {
3071 workrequ
= dev
->id
[c
][j
].curr_req
;
3072 printk("\n que cdb= ");
3073 for (k
=0; k
< workrequ
->cmd_len
; k
++) {
3074 printk(" %2x ",workrequ
->cmnd
[k
]);
3076 printk(" last_lenu= %x ",(unsigned int)dev
->id
[c
][j
].last_len
);
3082 static const char *atp870u_info(struct Scsi_Host
*notused
)
3084 static char buffer
[128];
3086 strcpy(buffer
, "ACARD AEC-6710/6712/67160 PCI Ultra/W/LVD SCSI-3 Adapter Driver V2.6+ac ");
3091 #define BLS buffer + len + size
3092 static int atp870u_proc_info(struct Scsi_Host
*HBAptr
, char *buffer
,
3093 char **start
, off_t offset
, int length
, int inout
)
3095 static u8 buff
[512];
3104 memset(buff
, 0, sizeof(buff
));
3105 size
+= sprintf(BLS
, "ACARD AEC-671X Driver Version: 2.6+ac\n");
3110 size
+= sprintf(BLS
, "\n");
3111 size
+= sprintf(BLS
, "Adapter Configuration:\n");
3112 size
+= sprintf(BLS
, " Base IO: %#.4lx\n", HBAptr
->io_port
);
3113 size
+= sprintf(BLS
, " IRQ: %d\n", HBAptr
->irq
);
3117 *start
= buffer
+ (offset
- begin
); /* Start of wanted data */
3118 len
-= (offset
- begin
); /* Start slop */
3120 len
= length
; /* Ending slop */
3126 static int atp870u_biosparam(struct scsi_device
*disk
, struct block_device
*dev
,
3127 sector_t capacity
, int *ip
)
3129 int heads
, sectors
, cylinders
;
3133 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
3134 if (cylinders
> 1024) {
3137 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
3146 static void atp870u_remove (struct pci_dev
*pdev
)
3148 struct atp_unit
*devext
= pci_get_drvdata(pdev
);
3149 struct Scsi_Host
*pshost
= devext
->host
;
3152 scsi_remove_host(pshost
);
3153 printk(KERN_INFO
"free_irq : %d\n",pshost
->irq
);
3154 free_irq(pshost
->irq
, pshost
);
3155 release_region(pshost
->io_port
, pshost
->n_io_port
);
3156 printk(KERN_INFO
"atp870u_free_tables : %p\n",pshost
);
3157 atp870u_free_tables(pshost
);
3158 printk(KERN_INFO
"scsi_host_put : %p\n",pshost
);
3159 scsi_host_put(pshost
);
3160 printk(KERN_INFO
"pci_set_drvdata : %p\n",pdev
);
3161 pci_set_drvdata(pdev
, NULL
);
3163 MODULE_LICENSE("GPL");
3165 static struct scsi_host_template atp870u_template
= {
3166 .module
= THIS_MODULE
,
3167 .name
= "atp870u" /* name */,
3168 .proc_name
= "atp870u",
3169 .proc_info
= atp870u_proc_info
,
3170 .info
= atp870u_info
/* info */,
3171 .queuecommand
= atp870u_queuecommand
/* queuecommand */,
3172 .eh_abort_handler
= atp870u_abort
/* abort */,
3173 .bios_param
= atp870u_biosparam
/* biosparm */,
3174 .can_queue
= qcnt
/* can_queue */,
3175 .this_id
= 7 /* SCSI ID */,
3176 .sg_tablesize
= ATP870U_SCATTER
/*SG_ALL*/ /*SG_NONE*/,
3177 .cmd_per_lun
= ATP870U_CMDLUN
/* commands per lun */,
3178 .use_clustering
= ENABLE_CLUSTERING
,
3179 .max_sectors
= ATP870U_MAX_SECTORS
,
3182 static struct pci_device_id atp870u_id_table
[] = {
3183 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP885_DEVID
) },
3184 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP880_DEVID1
) },
3185 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP880_DEVID2
) },
3186 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7610
) },
3187 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612UW
) },
3188 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612U
) },
3189 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612S
) },
3190 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612D
) },
3191 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612SUW
) },
3192 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_8060
) },
3196 MODULE_DEVICE_TABLE(pci
, atp870u_id_table
);
3198 static struct pci_driver atp870u_driver
= {
3199 .id_table
= atp870u_id_table
,
3201 .probe
= atp870u_probe
,
3202 .remove
= __devexit_p(atp870u_remove
),
3205 static int __init
atp870u_init(void)
3208 printk("atp870u_init: Entry\n");
3210 return pci_register_driver(&atp870u_driver
);
3213 static void __exit
atp870u_exit(void)
3216 printk("atp870u_exit: Entry\n");
3218 pci_unregister_driver(&atp870u_driver
);
3221 static void tscam_885(void)
3225 for (i
= 0; i
< 0x2; i
++) {
3233 static void is885(struct atp_unit
*dev
, unsigned int wkport
,unsigned char c
)
3235 unsigned int tmport
;
3236 unsigned char i
, j
, k
, rmb
, n
, lvdmode
;
3237 unsigned short int m
;
3238 static unsigned char mbuf
[512];
3239 static unsigned char satn
[9] = {0, 0, 0, 0, 0, 0, 0, 6, 6};
3240 static unsigned char inqd
[9] = {0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6};
3241 static unsigned char synn
[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
3242 unsigned char synu
[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
3243 static unsigned char synw
[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
3244 unsigned char synuw
[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
3245 static unsigned char wide
[6] = {0x80, 1, 2, 3, 1, 0};
3246 static unsigned char u3
[9] = { 0x80,1,6,4,0x09,00,0x0e,0x01,0x02 };
3248 lvdmode
=inb(wkport
+ 0x1b) >> 7;
3250 for (i
= 0; i
< 16; i
++) {
3253 if ((m
& dev
->active_id
[c
]) != 0) {
3256 if (i
== dev
->host_id
[c
]) {
3257 printk(KERN_INFO
" ID: %2d Host Adapter\n", dev
->host_id
[c
]);
3260 tmport
= wkport
+ 0x1b;
3262 tmport
= wkport
+ 0x01;
3263 outb(0x08, tmport
++);
3264 outb(0x7f, tmport
++);
3265 outb(satn
[0], tmport
++);
3266 outb(satn
[1], tmport
++);
3267 outb(satn
[2], tmport
++);
3268 outb(satn
[3], tmport
++);
3269 outb(satn
[4], tmport
++);
3270 outb(satn
[5], tmport
++);
3274 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3277 outb(satn
[6], tmport
++);
3278 outb(satn
[7], tmport
++);
3280 if ((j
& 0x08) != 0) {
3281 j
= (j
& 0x07) | 0x40;
3285 outb(satn
[8], tmport
);
3288 while ((inb(tmport
) & 0x80) == 0x00)
3291 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3294 while (inb(tmport
) != 0x8e)
3296 dev
->active_id
[c
] |= m
;
3298 tmport
= wkport
+ 0x10;
3300 tmport
= wkport
+ 0x14;
3304 tmport
= wkport
+ 0x18;
3307 while ((inb(tmport
) & 0x80) == 0x00)
3312 tmport
= wkport
+ 0x10;
3317 tmport
= wkport
+ 0x03;
3318 outb(inqd
[0], tmport
++);
3319 outb(inqd
[1], tmport
++);
3320 outb(inqd
[2], tmport
++);
3321 outb(inqd
[3], tmport
++);
3322 outb(inqd
[4], tmport
++);
3323 outb(inqd
[5], tmport
);
3327 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3329 outb(inqd
[6], tmport
++);
3330 outb(inqd
[7], tmport
++);
3332 outb(inqd
[8], tmport
);
3334 while ((inb(tmport
) & 0x80) == 0x00)
3337 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3340 while (inb(tmport
) != 0x8e)
3342 tmport
= wkport
+ 0x1b;
3344 tmport
= wkport
+ 0x18;
3350 if ((k
& 0x01) != 0) {
3352 mbuf
[j
++] = inb(tmport
);
3356 if ((k
& 0x80) == 0) {
3364 tmport
= wkport
+ 0x10;
3373 while ((inb(tmport
) & 0x80) == 0x00)
3376 if (inb(tmport
) != 0x16) {
3381 printk( KERN_INFO
" ID: %2d %s\n", i
, &mbuf
[8]);
3382 dev
->id
[c
][i
].devtype
= mbuf
[0];
3385 if ((mbuf
[7] & 0x60) == 0) {
3388 if ((i
< 8) && ((dev
->global_map
[c
] & 0x20) == 0)) {
3394 if (dev
->sp
[c
][i
] != 0x04) { // force u2
3398 tmport
= wkport
+ 0x1b;
3400 tmport
= wkport
+ 0x03;
3401 outb(satn
[0], tmport
++);
3402 outb(satn
[1], tmport
++);
3403 outb(satn
[2], tmport
++);
3404 outb(satn
[3], tmport
++);
3405 outb(satn
[4], tmport
++);
3406 outb(satn
[5], tmport
++);
3410 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3412 outb(satn
[6], tmport
++);
3413 outb(satn
[7], tmport
++);
3415 outb(satn
[8], tmport
);
3418 while ((inb(tmport
) & 0x80) == 0x00)
3421 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3424 while (inb(tmport
) != 0x8e)
3428 tmport
= wkport
+ 0x14;
3434 while ((inb(tmport
) & 0x80) == 0) {
3435 if ((inb(tmport
) & 0x01) != 0) {
3437 outb(u3
[j
++], tmport
);
3443 while ((inb(tmport
) & 0x80) == 0x00)
3445 j
= inb(tmport
) & 0x0f;
3457 tmport
= wkport
+ 0x18;
3460 while ((inb(tmport
) & 0x80) == 0) {
3461 if ((inb(tmport
) & 0x01) != 0) {
3469 j
= inb(tmport
) & 0x0f;
3481 tmport
= wkport
+ 0x14;
3489 if ((j
& 0x01) != 0) {
3491 mbuf
[k
++] = inb(tmport
);
3495 if ((j
& 0x80) == 0x00) {
3499 j
= inb(tmport
) & 0x0f;
3511 tmport
= wkport
+ 0x10;
3513 tmport
= wkport
+ 0x14;
3518 while ((inb(tmport
) & 0x80) == 0x00);
3527 if (mbuf
[0] != 0x01) {
3530 if (mbuf
[1] != 0x06) {
3533 if (mbuf
[2] != 0x04) {
3536 if (mbuf
[3] == 0x09) {
3539 dev
->wide_id
[c
] |= m
;
3540 dev
->id
[c
][i
].devsp
= 0xce;
3542 printk("dev->id[%2d][%2d].devsp = %2x\n",c
,i
,dev
->id
[c
][i
].devsp
);
3547 tmport
= wkport
+ 0x1b;
3549 tmport
= wkport
+ 0x03;
3550 outb(satn
[0], tmport
++);
3551 outb(satn
[1], tmport
++);
3552 outb(satn
[2], tmport
++);
3553 outb(satn
[3], tmport
++);
3554 outb(satn
[4], tmport
++);
3555 outb(satn
[5], tmport
++);
3559 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3561 outb(satn
[6], tmport
++);
3562 outb(satn
[7], tmport
++);
3564 outb(satn
[8], tmport
);
3567 while ((inb(tmport
) & 0x80) == 0x00)
3570 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3573 while (inb(tmport
) != 0x8e)
3577 tmport
= wkport
+ 0x14;
3583 while ((inb(tmport
) & 0x80) == 0) {
3584 if ((inb(tmport
) & 0x01) != 0) {
3586 outb(wide
[j
++], tmport
);
3592 while ((inb(tmport
) & 0x80) == 0x00)
3594 j
= inb(tmport
) & 0x0f;
3606 tmport
= wkport
+ 0x18;
3609 while ((inb(tmport
) & 0x80) == 0) {
3610 if ((inb(tmport
) & 0x01) != 0) {
3618 j
= inb(tmport
) & 0x0f;
3630 tmport
= wkport
+ 0x14;
3638 if ((j
& 0x01) != 0) {
3640 mbuf
[k
++] = inb(tmport
);
3644 if ((j
& 0x80) == 0x00) {
3648 j
= inb(tmport
) & 0x0f;
3660 tmport
= wkport
+ 0x10;
3662 tmport
= wkport
+ 0x14;
3667 while ((inb(tmport
) & 0x80) == 0x00)
3677 if (mbuf
[0] != 0x01) {
3680 if (mbuf
[1] != 0x02) {
3683 if (mbuf
[2] != 0x03) {
3686 if (mbuf
[3] != 0x01) {
3691 dev
->wide_id
[c
] |= m
;
3693 if ((dev
->id
[c
][i
].devtype
== 0x00) || (dev
->id
[c
][i
].devtype
== 0x07) ||
3694 ((dev
->id
[c
][i
].devtype
== 0x05) && ((n
& 0x10) != 0))) {
3697 if ((dev
->async
[c
] & m
) != 0) {
3703 if (dev
->sp
[c
][i
] == 0x02) {
3707 if (dev
->sp
[c
][i
] >= 0x03) {
3712 tmport
= wkport
+ 0x1b;
3714 if ((m
& dev
->wide_id
[c
]) != 0) {
3718 tmport
= wkport
+ 0x03;
3719 outb(satn
[0], tmport
++);
3720 outb(satn
[1], tmport
++);
3721 outb(satn
[2], tmport
++);
3722 outb(satn
[3], tmport
++);
3723 outb(satn
[4], tmport
++);
3724 outb(satn
[5], tmport
++);
3728 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3730 outb(satn
[6], tmport
++);
3731 outb(satn
[7], tmport
++);
3733 outb(satn
[8], tmport
);
3736 while ((inb(tmport
) & 0x80) == 0x00)
3739 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3742 while (inb(tmport
) != 0x8e)
3746 tmport
= wkport
+ 0x14;
3752 while ((inb(tmport
) & 0x80) == 0) {
3753 if ((inb(tmport
) & 0x01) != 0) {
3755 if ((m
& dev
->wide_id
[c
]) != 0) {
3756 if ((m
& dev
->ultra_map
[c
]) != 0) {
3757 outb(synuw
[j
++], tmport
);
3759 outb(synw
[j
++], tmport
);
3762 if ((m
& dev
->ultra_map
[c
]) != 0) {
3763 outb(synu
[j
++], tmport
);
3765 outb(synn
[j
++], tmport
);
3772 while ((inb(tmport
) & 0x80) == 0x00)
3774 j
= inb(tmport
) & 0x0f;
3786 tmport
= wkport
+ 0x18;
3789 while ((inb(tmport
) & 0x80) == 0x00) {
3790 if ((inb(tmport
) & 0x01) != 0x00) {
3814 tmport
= wkport
+ 0x14;
3822 if ((j
& 0x01) != 0x00) {
3824 mbuf
[k
++] = inb(tmport
);
3828 if ((j
& 0x80) == 0x00) {
3832 while ((inb(tmport
) & 0x80) == 0x00);
3849 tmport
= wkport
+ 0x10;
3852 tmport
= wkport
+ 0x14;
3857 while ((inb(tmport
) & 0x80) == 0x00)
3864 if (mbuf
[0] != 0x01) {
3867 if (mbuf
[1] != 0x03) {
3870 if (mbuf
[4] == 0x00) {
3873 if (mbuf
[3] > 0x64) {
3876 if (mbuf
[4] > 0x0e) {
3879 dev
->id
[c
][i
].devsp
= mbuf
[4];
3880 if (mbuf
[3] < 0x0c){
3884 if ((mbuf
[3] < 0x0d) && (rmb
== 0)) {
3888 if (mbuf
[3] < 0x1a) {
3892 if (mbuf
[3] < 0x33) {
3896 if (mbuf
[3] < 0x4c) {
3902 dev
->id
[c
][i
].devsp
= (dev
->id
[c
][i
].devsp
& 0x0f) | j
;
3904 printk("dev->id[%2d][%2d].devsp = %2x\n",c
,i
,dev
->id
[c
][i
].devsp
);
3907 tmport
= wkport
+ 0x16;
3911 module_init(atp870u_init
);
3912 module_exit(atp870u_exit
);