2 * Copyright (C) 1997 Wu Ching Chen
3 * 2.1.x update (C) 1998 Krzysztof G. Baranowski
4 * 2.5.x update (C) 2002 Red Hat <alan@redhat.com>
5 * 2.6.x update (C) 2004 Red Hat <alan@redhat.com>
7 * Marcelo Tosatti <marcelo@conectiva.com.br> : SMP fixes
9 * Wu Ching Chen : NULL pointer fixes 2000/06/02
11 * enable 32 bit fifo transfer
12 * support cdrom & remove device run ultra speed
13 * fix disconnect bug 2000/12/21
14 * support atp880 chip lvd u160 2001/05/15
15 * fix prd table bug 2001/09/12 (7.1)
17 * atp885 support add by ACARD Hao Ping Lian 2005/01/05
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/interrupt.h>
22 #include <linux/kernel.h>
23 #include <linux/types.h>
24 #include <linux/string.h>
25 #include <linux/ioport.h>
26 #include <linux/delay.h>
27 #include <linux/proc_fs.h>
28 #include <linux/spinlock.h>
29 #include <linux/pci.h>
30 #include <linux/blkdev.h>
31 #include <asm/system.h>
34 #include <scsi/scsi.h>
35 #include <scsi/scsi_cmnd.h>
36 #include <scsi/scsi_device.h>
37 #include <scsi/scsi_host.h>
41 static struct scsi_host_template atp870u_template
;
42 static void send_s870(struct atp_unit
*dev
,unsigned char c
);
43 static void is885(struct atp_unit
*dev
, unsigned int wkport
,unsigned char c
);
44 static void tscam_885(void);
46 static irqreturn_t
atp870u_intr_handle(int irq
, void *dev_id
, struct pt_regs
*regs
)
49 unsigned short int tmpcip
, id
;
50 unsigned char i
, j
, c
, target_id
, lun
,cmdp
;
52 struct scsi_cmnd
*workreq
;
53 unsigned int workport
, tmport
, tmport1
;
54 unsigned long adrcnt
, k
;
59 struct Scsi_Host
*host
= dev_id
;
60 struct atp_unit
*dev
= (struct atp_unit
*)&host
->hostdata
;
62 for (c
= 0; c
< 2; c
++) {
63 tmport
= dev
->ioport
[c
] + 0x1f;
74 printk("atp870u_intr_handle enter\n");
77 cmdp
= inb(dev
->ioport
[c
] + 0x10);
78 workport
= dev
->ioport
[c
];
79 if (dev
->working
[c
] != 0) {
80 if (dev
->dev_id
== ATP885_DEVID
) {
81 tmport1
= workport
+ 0x16;
82 if ((inb(tmport1
) & 0x80) == 0)
83 outb((inb(tmport1
) | 0x80), tmport1
);
85 tmpcip
= dev
->pciport
[c
];
86 if ((inb(tmpcip
) & 0x08) != 0)
89 for (k
=0; k
< 1000; k
++) {
90 if ((inb(tmpcip
) & 0x08) == 0) {
93 if ((inb(tmpcip
) & 0x01) == 0) {
99 tmpcip
= dev
->pciport
[c
];
105 if (dev
->dev_id
== ATP885_DEVID
) {
112 target_id
= inb(tmport
);
116 * Remap wide devices onto id numbers
119 if ((target_id
& 0x40) != 0) {
120 target_id
= (target_id
& 0x07) | 0x08;
125 if ((j
& 0x40) != 0) {
126 if (dev
->last_cmd
[c
] == 0xff) {
127 dev
->last_cmd
[c
] = target_id
;
129 dev
->last_cmd
[c
] |= 0x40;
131 if (dev
->dev_id
== ATP885_DEVID
)
132 dev
->r1f
[c
][target_id
] |= j
;
134 printk("atp870u_intr_handle status = %x\n",i
);
137 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
138 dev
->last_cmd
[c
] = 0xff;
140 if (dev
->dev_id
== ATP885_DEVID
) {
143 ((unsigned char *) &adrcnt
)[2] = inb(tmport
++);
144 ((unsigned char *) &adrcnt
)[1] = inb(tmport
++);
145 ((unsigned char *) &adrcnt
)[0] = inb(tmport
);
146 if (dev
->id
[c
][target_id
].last_len
!= adrcnt
)
148 k
= dev
->id
[c
][target_id
].last_len
;
150 dev
->id
[c
][target_id
].tran_len
= k
;
151 dev
->id
[c
][target_id
].last_len
= adrcnt
;
154 printk("tmport = %x dev->id[c][target_id].last_len = %d dev->id[c][target_id].tran_len = %d\n",tmport
,dev
->id
[c
][target_id
].last_len
,dev
->id
[c
][target_id
].tran_len
);
161 if (dev
->wide_id
[c
] != 0) {
162 tmport
= workport
+ 0x1b;
164 while ((inb(tmport
) & 0x01) != 0x01) {
169 * Issue more commands
171 spin_lock_irqsave(dev
->host
->host_lock
, flags
);
172 if (((dev
->quhd
[c
] != dev
->quend
[c
]) || (dev
->last_cmd
[c
] != 0xff)) &&
173 (dev
->in_snd
[c
] == 0)) {
175 printk("Call sent_s870\n");
179 spin_unlock_irqrestore(dev
->host
->host_lock
, flags
);
185 printk("Status 0x85 return\n");
191 dev
->last_cmd
[c
] |= 0x40;
197 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
198 dev
->last_cmd
[c
] = 0xff;
202 ((unsigned char *) &adrcnt
)[2] = inb(tmport
++);
203 ((unsigned char *) &adrcnt
)[1] = inb(tmport
++);
204 ((unsigned char *) &adrcnt
)[0] = inb(tmport
);
205 k
= dev
->id
[c
][target_id
].last_len
;
207 dev
->id
[c
][target_id
].tran_len
= k
;
208 dev
->id
[c
][target_id
].last_len
= adrcnt
;
217 if (dev
->dev_id
== ATP885_DEVID
) {
218 if ((i
== 0x4c) || (i
== 0x4d) || (i
== 0x8c) || (i
== 0x8d)) {
219 if ((i
== 0x4c) || (i
== 0x8c))
226 if ((i
== 0x80) || (i
== 0x8f)) {
228 printk(KERN_DEBUG
"Device reselect\n");
232 if (cmdp
== 0x44 || i
==0x80) {
234 lun
= inb(tmport
) & 0x07;
236 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
237 dev
->last_cmd
[c
] = 0xff;
241 printk("cmdp = 0x41\n");
245 ((unsigned char *) &adrcnt
)[2] = inb(tmport
++);
246 ((unsigned char *) &adrcnt
)[1] = inb(tmport
++);
247 ((unsigned char *) &adrcnt
)[0] = inb(tmport
);
248 k
= dev
->id
[c
][target_id
].last_len
;
250 dev
->id
[c
][target_id
].tran_len
= k
;
251 dev
->id
[c
][target_id
].last_len
= adrcnt
;
258 printk("cmdp != 0x41\n");
261 dev
->id
[c
][target_id
].dirct
= 0x00;
263 outb(0x00, tmport
++);
264 outb(0x00, tmport
++);
265 outb(0x00, tmport
++);
272 if (dev
->last_cmd
[c
] != 0xff) {
273 dev
->last_cmd
[c
] |= 0x40;
275 if (dev
->dev_id
== ATP885_DEVID
) {
276 j
= inb(dev
->baseport
+ 0x29) & 0xfe;
277 outb(j
, dev
->baseport
+ 0x29);
278 tmport
= workport
+ 0x16;
280 tmport
= workport
+ 0x10;
285 target_id
= inb(tmport
);
287 * Remap wide identifiers
289 if ((target_id
& 0x10) != 0) {
290 target_id
= (target_id
& 0x07) | 0x08;
294 if (dev
->dev_id
== ATP885_DEVID
) {
295 tmport
= workport
+ 0x10;
298 workreq
= dev
->id
[c
][target_id
].curr_req
;
300 printk(KERN_DEBUG
"Channel = %d ID = %d LUN = %d CDB",c
,workreq
->device
->id
,workreq
->device
->lun
);
301 for(l
=0;l
<workreq
->cmd_len
;l
++)
303 printk(KERN_DEBUG
" %x",workreq
->cmnd
[l
]);
307 tmport
= workport
+ 0x0f;
310 outb(dev
->id
[c
][target_id
].devsp
, tmport
++);
311 adrcnt
= dev
->id
[c
][target_id
].tran_len
;
312 k
= dev
->id
[c
][target_id
].last_len
;
314 outb(((unsigned char *) &k
)[2], tmport
++);
315 outb(((unsigned char *) &k
)[1], tmport
++);
316 outb(((unsigned char *) &k
)[0], tmport
++);
318 printk("k %x, k[0] 0x%x k[1] 0x%x k[2] 0x%x\n", k
, inb(tmport
-1), inb(tmport
-2), inb(tmport
-3));
323 j
= (j
& 0x07) | 0x40;
326 j
|= dev
->id
[c
][target_id
].dirct
;
330 /* enable 32 bit fifo transfer */
331 if (dev
->dev_id
== ATP885_DEVID
) {
332 tmpcip
= dev
->pciport
[c
] + 1;
333 i
=inb(tmpcip
) & 0xf3;
334 //j=workreq->cmnd[0];
335 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
339 } else if ((dev
->dev_id
== ATP880_DEVID1
) ||
340 (dev
->dev_id
== ATP880_DEVID2
) ) {
341 tmport
= workport
- 0x05;
342 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
343 outb((unsigned char) ((inb(tmport
) & 0x3f) | 0xc0), tmport
);
345 outb((unsigned char) (inb(tmport
) & 0x3f), tmport
);
348 tmport
= workport
+ 0x3a;
349 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
350 outb((unsigned char) ((inb(tmport
) & 0xf3) | 0x08), tmport
);
352 outb((unsigned char) (inb(tmport
) & 0xf3), tmport
);
355 tmport
= workport
+ 0x1b;
358 id
= id
<< target_id
;
360 * Is this a wide device
362 if ((id
& dev
->wide_id
[c
]) != 0) {
366 while ((inb(tmport
) & 0x01) != j
) {
369 if (dev
->id
[c
][target_id
].last_len
== 0) {
370 tmport
= workport
+ 0x18;
374 printk("dev->id[c][target_id].last_len = 0\n");
379 printk("target_id = %d adrcnt = %d\n",target_id
,adrcnt
);
381 prd
= dev
->id
[c
][target_id
].prd_pos
;
382 while (adrcnt
!= 0) {
383 id
= ((unsigned short int *)prd
)[2];
390 ((unsigned short int *)prd
)[2] = (unsigned short int)
392 ((unsigned long *)prd
)[0] += adrcnt
;
394 dev
->id
[c
][target_id
].prd_pos
= prd
;
397 dev
->id
[c
][target_id
].prdaddr
+= 0x08;
400 dev
->id
[c
][target_id
].prd_pos
= prd
;
404 tmpcip
= dev
->pciport
[c
] + 0x04;
405 outl(dev
->id
[c
][target_id
].prdaddr
, tmpcip
);
407 printk("dev->id[%d][%d].prdaddr 0x%8x\n", c
, target_id
, dev
->id
[c
][target_id
].prdaddr
);
409 if (dev
->dev_id
== ATP885_DEVID
) {
417 tmport
= workport
+ 0x18;
419 * Check transfer direction
421 if (dev
->id
[c
][target_id
].dirct
!= 0) {
426 printk("status 0x80 return dirct != 0\n");
434 printk("status 0x80 return dirct = 0\n");
440 * Current scsi request on this target
443 workreq
= dev
->id
[c
][target_id
].curr_req
;
446 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40)
448 dev
->last_cmd
[c
] = 0xff;
451 workreq
->result
= errstus
;
455 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
456 dev
->last_cmd
[c
] = 0xff;
460 errstus
= inb(tmport
);
461 if (((dev
->r1f
[c
][target_id
] & 0x10) != 0)&&(dev
->dev_id
==ATP885_DEVID
)) {
462 printk(KERN_WARNING
"AEC67162 CRC ERROR !\n");
465 workreq
->result
= errstus
;
467 if (dev
->dev_id
== ATP885_DEVID
) {
468 j
= inb(dev
->baseport
+ 0x29) | 0x01;
469 outb(j
, dev
->baseport
+ 0x29);
472 * Complete the command
474 if (workreq
->use_sg
) {
475 pci_unmap_sg(dev
->pdev
,
476 (struct scatterlist
*)workreq
->buffer
,
478 workreq
->sc_data_direction
);
479 } else if (workreq
->request_bufflen
&&
480 workreq
->sc_data_direction
!= DMA_NONE
) {
481 pci_unmap_single(dev
->pdev
,
482 workreq
->SCp
.dma_handle
,
483 workreq
->request_bufflen
,
484 workreq
->sc_data_direction
);
486 spin_lock_irqsave(dev
->host
->host_lock
, flags
);
487 (*workreq
->scsi_done
) (workreq
);
489 printk("workreq->scsi_done\n");
492 * Clear it off the queue
494 dev
->id
[c
][target_id
].curr_req
= NULL
;
496 spin_unlock_irqrestore(dev
->host
->host_lock
, flags
);
500 if (dev
->wide_id
[c
] != 0) {
501 tmport
= workport
+ 0x1b;
503 while ((inb(tmport
) & 0x01) != 0x01) {
508 * If there is stuff to send and nothing going then send it
510 spin_lock_irqsave(dev
->host
->host_lock
, flags
);
511 if (((dev
->last_cmd
[c
] != 0xff) || (dev
->quhd
[c
] != dev
->quend
[c
])) &&
512 (dev
->in_snd
[c
] == 0)) {
514 printk("Call sent_s870(scsi_done)\n");
518 spin_unlock_irqrestore(dev
->host
->host_lock
, flags
);
522 if ((dev
->last_cmd
[c
] & 0xf0) != 0x40) {
523 dev
->last_cmd
[c
] = 0xff;
531 outl(dev
->id
[c
][target_id
].prdaddr
, tmpcip
);
536 tmport
= workport
+ 0x10;
538 if (dev
->dev_id
== ATP885_DEVID
) {
540 k
= dev
->id
[c
][target_id
].last_len
;
541 outb((unsigned char) (((unsigned char *) (&k
))[2]), tmport
++);
542 outb((unsigned char) (((unsigned char *) (&k
))[1]), tmport
++);
543 outb((unsigned char) (((unsigned char *) (&k
))[0]), tmport
);
544 dev
->id
[c
][target_id
].dirct
= 0x00;
547 dev
->id
[c
][target_id
].dirct
= 0x00;
557 outl(dev
->id
[c
][target_id
].prdaddr
, tmpcip
);
562 tmport
= workport
+ 0x10;
564 if (dev
->dev_id
== ATP885_DEVID
) {
566 k
= dev
->id
[c
][target_id
].last_len
;
567 outb((unsigned char) (((unsigned char *) (&k
))[2]), tmport
++);
568 outb((unsigned char) (((unsigned char *) (&k
))[1]), tmport
++);
569 outb((unsigned char) (((unsigned char *) (&k
))[0]), tmport
++);
573 outb((unsigned char) (inb(tmport
) | 0x20), tmport
);
574 dev
->id
[c
][target_id
].dirct
= 0x20;
587 dev
->id
[c
][target_id
].dirct
= 0x00;
589 outb(0x00, tmport
++);
590 outb(0x00, tmport
++);
591 outb(0x00, tmport
++);
597 // tmport = workport + 0x17;
599 // dev->working[c] = 0;
606 printk("atp870u_intr_handle exit\n");
611 * atp870u_queuecommand - Queue SCSI command
612 * @req_p: request block
613 * @done: completion function
615 * Queue a command to the ATP queue. Called with the host lock held.
617 static int atp870u_queuecommand(struct scsi_cmnd
* req_p
,
618 void (*done
) (struct scsi_cmnd
*))
621 unsigned int tmport
,m
;
622 struct atp_unit
*dev
;
623 struct Scsi_Host
*host
;
625 c
= req_p
->device
->channel
;
626 req_p
->sense_buffer
[0]=0;
628 if (req_p
->device
->channel
> 1) {
629 req_p
->result
= 0x00040000;
632 printk("atp870u_queuecommand : req_p->device->channel > 1\n");
637 host
= req_p
->device
->host
;
638 dev
= (struct atp_unit
*)&host
->hostdata
;
643 m
= m
<< req_p
->device
->id
;
646 * Fake a timeout for missing targets
649 if ((m
& dev
->active_id
[c
]) == 0) {
650 req_p
->result
= 0x00040000;
656 req_p
->scsi_done
= done
;
659 printk( "atp870u_queuecommand: done can't be NULL\n");
670 if (dev
->quend
[c
] >= qcnt
) {
677 if (dev
->quhd
[c
] == dev
->quend
[c
]) {
678 if (dev
->quend
[c
] == 0) {
679 dev
->quend
[c
] = qcnt
;
682 printk("atp870u_queuecommand : dev->quhd[c] == dev->quend[c]\n");
685 req_p
->result
= 0x00020000;
689 dev
->quereq
[c
][dev
->quend
[c
]] = req_p
;
690 tmport
= dev
->ioport
[c
] + 0x1c;
692 printk("dev->ioport[c] = %x inb(tmport) = %x dev->in_int[%d] = %d dev->in_snd[%d] = %d\n",dev
->ioport
[c
],inb(tmport
),c
,dev
->in_int
[c
],c
,dev
->in_snd
[c
]);
694 if ((inb(tmport
) == 0) && (dev
->in_int
[c
] == 0) && (dev
->in_snd
[c
] == 0)) {
696 printk("Call sent_s870(atp870u_queuecommand)\n");
701 printk("atp870u_queuecommand : exit\n");
707 * send_s870 - send a command to the controller
710 * On entry there is work queued to be done. We move some of that work to the
713 * Caller holds the host lock.
715 static void send_s870(struct atp_unit
*dev
,unsigned char c
)
718 struct scsi_cmnd
*workreq
;
720 unsigned char j
, target_id
;
722 unsigned short int tmpcip
, w
;
723 unsigned long l
, bttl
= 0;
724 unsigned int workport
;
725 struct scatterlist
*sgpnt
;
726 unsigned long sg_count
;
728 if (dev
->in_snd
[c
] != 0) {
730 printk("cmnd in_snd\n");
735 printk("Sent_s870 enter\n");
738 if ((dev
->last_cmd
[c
] != 0xff) && ((dev
->last_cmd
[c
] & 0x40) != 0)) {
739 dev
->last_cmd
[c
] &= 0x0f;
740 workreq
= dev
->id
[c
][dev
->last_cmd
[c
]].curr_req
;
741 if (workreq
!= NULL
) { /* check NULL pointer */
744 dev
->last_cmd
[c
] = 0xff;
745 if (dev
->quhd
[c
] == dev
->quend
[c
]) {
750 if ((dev
->last_cmd
[c
] != 0xff) && (dev
->working
[c
] != 0)) {
757 if (dev
->quhd
[c
] >= qcnt
) {
760 workreq
= dev
->quereq
[c
][dev
->quhd
[c
]];
761 if (dev
->id
[c
][workreq
->device
->id
].curr_req
== 0) {
762 dev
->id
[c
][workreq
->device
->id
].curr_req
= workreq
;
763 dev
->last_cmd
[c
] = workreq
->device
->id
;
771 workport
= dev
->ioport
[c
];
772 tmport
= workport
+ 0x1f;
773 if ((inb(tmport
) & 0xb0) != 0) {
776 tmport
= workport
+ 0x1c;
777 if (inb(tmport
) == 0) {
782 printk("Abort to Send\n");
784 dev
->last_cmd
[c
] |= 0x40;
789 printk("OK to Send\n");
791 for(i
=0;i
<workreq
->cmd_len
;i
++) {
792 printk(" %x",workreq
->cmnd
[i
]);
794 printk("\nChannel = %d ID = %d LUN = %d\n",c
,workreq
->device
->id
,workreq
->device
->lun
);
796 if (dev
->dev_id
== ATP885_DEVID
) {
797 j
= inb(dev
->baseport
+ 0x29) & 0xfe;
798 outb(j
, dev
->baseport
+ 0x29);
799 dev
->r1f
[c
][workreq
->device
->id
] = 0;
802 if (workreq
->cmnd
[0] == READ_CAPACITY
) {
803 if (workreq
->request_bufflen
> 8) {
804 workreq
->request_bufflen
= 0x08;
807 if (workreq
->cmnd
[0] == 0x00) {
808 workreq
->request_bufflen
= 0;
811 tmport
= workport
+ 0x1b;
813 target_id
= workreq
->device
->id
;
820 if ((w
& dev
->wide_id
[c
]) != 0) {
824 while ((inb(tmport
) & 0x01) != j
) {
827 printk("send_s870 while loop 1\n");
835 outb(workreq
->cmd_len
, tmport
++);
836 outb(0x2c, tmport
++);
837 if (dev
->dev_id
== ATP885_DEVID
) {
838 outb(0x7f, tmport
++);
840 outb(0xcf, tmport
++);
842 for (i
= 0; i
< workreq
->cmd_len
; i
++) {
843 outb(workreq
->cmnd
[i
], tmport
++);
845 tmport
= workport
+ 0x0f;
846 outb(workreq
->device
->lun
, tmport
);
851 outb(dev
->id
[c
][target_id
].devsp
, tmport
++);
853 printk("dev->id[%d][%d].devsp = %2x\n",c
,target_id
,dev
->id
[c
][target_id
].devsp
);
856 * Figure out the transfer size
858 if (workreq
->use_sg
) {
860 printk("Using SGL\n");
864 sgpnt
= (struct scatterlist
*) workreq
->request_buffer
;
865 sg_count
= pci_map_sg(dev
->pdev
, sgpnt
, workreq
->use_sg
,
866 workreq
->sc_data_direction
);
868 for (i
= 0; i
< workreq
->use_sg
; i
++) {
869 if (sgpnt
[i
].length
== 0 || workreq
->use_sg
> ATP870U_SCATTER
) {
870 panic("Foooooooood fight!");
872 l
+= sgpnt
[i
].length
;
875 printk( "send_s870: workreq->use_sg %d, sg_count %d l %8ld\n", workreq
->use_sg
, sg_count
, l
);
877 } else if(workreq
->request_bufflen
&& workreq
->sc_data_direction
!= PCI_DMA_NONE
) {
879 printk("Not using SGL\n");
881 workreq
->SCp
.dma_handle
= pci_map_single(dev
->pdev
, workreq
->request_buffer
,
882 workreq
->request_bufflen
,
883 workreq
->sc_data_direction
);
884 l
= workreq
->request_bufflen
;
886 printk( "send_s870: workreq->use_sg %d, l %8ld\n", workreq
->use_sg
, l
);
890 * Write transfer size
892 outb((unsigned char) (((unsigned char *) (&l
))[2]), tmport
++);
893 outb((unsigned char) (((unsigned char *) (&l
))[1]), tmport
++);
894 outb((unsigned char) (((unsigned char *) (&l
))[0]), tmport
++);
896 dev
->id
[c
][j
].last_len
= l
;
897 dev
->id
[c
][j
].tran_len
= 0;
899 printk("dev->id[%2d][%2d].last_len = %d\n",c
,j
,dev
->id
[c
][j
].last_len
);
904 if ((j
& 0x08) != 0) {
905 j
= (j
& 0x07) | 0x40;
908 * Check transfer direction
910 if (workreq
->sc_data_direction
== DMA_TO_DEVICE
) {
911 outb((unsigned char) (j
| 0x20), tmport
++);
915 outb((unsigned char) (inb(tmport
) | 0x80), tmport
);
917 tmport
= workport
+ 0x1c;
918 dev
->id
[c
][target_id
].dirct
= 0;
920 if (inb(tmport
) == 0) {
921 tmport
= workport
+ 0x18;
923 printk("change SCSI_CMD_REG 0x08\n");
927 dev
->last_cmd
[c
] |= 0x40;
932 tmpcip
= dev
->pciport
[c
];
933 prd
= dev
->id
[c
][target_id
].prd_table
;
934 dev
->id
[c
][target_id
].prd_pos
= prd
;
937 * Now write the request list. Either as scatter/gather or as
941 if (workreq
->use_sg
) {
942 sgpnt
= (struct scatterlist
*) workreq
->request_buffer
;
944 for (j
= 0; j
< workreq
->use_sg
; j
++) {
945 bttl
= sg_dma_address(&sgpnt
[j
]);
946 l
=sg_dma_len(&sgpnt
[j
]);
948 printk("1. bttl %x, l %x\n",bttl
, l
);
950 while (l
> 0x10000) {
951 (((u16
*) (prd
))[i
+ 3]) = 0x0000;
952 (((u16
*) (prd
))[i
+ 2]) = 0x0000;
953 (((u32
*) (prd
))[i
>> 1]) = cpu_to_le32(bttl
);
958 (((u32
*) (prd
))[i
>> 1]) = cpu_to_le32(bttl
);
959 (((u16
*) (prd
))[i
+ 2]) = cpu_to_le16(l
);
960 (((u16
*) (prd
))[i
+ 3]) = 0;
963 (((u16
*) (prd
))[i
- 1]) = cpu_to_le16(0x8000);
965 printk("prd %4x %4x %4x %4x\n",(((unsigned short int *)prd
)[0]),(((unsigned short int *)prd
)[1]),(((unsigned short int *)prd
)[2]),(((unsigned short int *)prd
)[3]));
966 printk("2. bttl %x, l %x\n",bttl
, l
);
970 * For a linear request write a chain of blocks
972 bttl
= workreq
->SCp
.dma_handle
;
973 l
= workreq
->request_bufflen
;
976 printk("3. bttl %x, l %x\n",bttl
, l
);
978 while (l
> 0x10000) {
979 (((u16
*) (prd
))[i
+ 3]) = 0x0000;
980 (((u16
*) (prd
))[i
+ 2]) = 0x0000;
981 (((u32
*) (prd
))[i
>> 1]) = cpu_to_le32(bttl
);
986 (((u16
*) (prd
))[i
+ 3]) = cpu_to_le16(0x8000);
987 (((u16
*) (prd
))[i
+ 2]) = cpu_to_le16(l
);
988 (((u32
*) (prd
))[i
>> 1]) = cpu_to_le32(bttl
);
990 printk("prd %4x %4x %4x %4x\n",(((unsigned short int *)prd
)[0]),(((unsigned short int *)prd
)[1]),(((unsigned short int *)prd
)[2]),(((unsigned short int *)prd
)[3]));
991 printk("4. bttl %x, l %x\n",bttl
, l
);
997 printk("send_s870: prdaddr_2 0x%8x tmpcip %x target_id %d\n", dev
->id
[c
][target_id
].prdaddr
,tmpcip
,target_id
);
999 outl(dev
->id
[c
][target_id
].prdaddr
, tmpcip
);
1000 tmpcip
= tmpcip
- 2;
1003 if (dev
->dev_id
== ATP885_DEVID
) {
1005 j
=inb(tmpcip
) & 0xf3;
1006 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) ||
1007 (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
1012 } else if ((dev
->dev_id
== ATP880_DEVID1
) ||
1013 (dev
->dev_id
== ATP880_DEVID2
)) {
1015 tmport
= workport
- 0x05;
1016 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
1017 outb((unsigned char) ((inb(tmport
) & 0x3f) | 0xc0), tmport
);
1019 outb((unsigned char) (inb(tmport
) & 0x3f), tmport
);
1023 tmport
= workport
+ 0x3a;
1024 if ((workreq
->cmnd
[0] == 0x08) || (workreq
->cmnd
[0] == 0x28) || (workreq
->cmnd
[0] == 0x0a) || (workreq
->cmnd
[0] == 0x2a)) {
1025 outb((inb(tmport
) & 0xf3) | 0x08, tmport
);
1027 outb(inb(tmport
) & 0xf3, tmport
);
1030 tmport
= workport
+ 0x1c;
1032 if(workreq
->sc_data_direction
== DMA_TO_DEVICE
) {
1033 dev
->id
[c
][target_id
].dirct
= 0x20;
1034 if (inb(tmport
) == 0) {
1035 tmport
= workport
+ 0x18;
1039 printk( "start DMA(to target)\n");
1042 dev
->last_cmd
[c
] |= 0x40;
1047 if (inb(tmport
) == 0) {
1048 tmport
= workport
+ 0x18;
1052 printk( "start DMA(to host)\n");
1055 dev
->last_cmd
[c
] |= 0x40;
1062 static unsigned char fun_scam(struct atp_unit
*dev
, unsigned short int *val
)
1064 unsigned int tmport
;
1065 unsigned short int i
, k
;
1068 tmport
= dev
->ioport
[0] + 0x1c;
1071 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
1073 j
= (unsigned char) (k
>> 8);
1074 if ((k
& 0x8000) != 0) { /* DB7 all release? */
1078 *val
|= 0x4000; /* assert DB6 */
1080 *val
&= 0xdfff; /* assert DB5 */
1083 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
1084 if ((inw(tmport
) & 0x2000) != 0) { /* DB5 all release? */
1088 *val
|= 0x8000; /* no DB4-0, assert DB7 */
1091 *val
&= 0xbfff; /* release DB6 */
1094 for (i
= 0; i
< 10; i
++) { /* stable >= bus settle delay(400 ns) */
1095 if ((inw(tmport
) & 0x4000) != 0) { /* DB6 all release? */
1103 static void tscam(struct Scsi_Host
*host
)
1106 unsigned int tmport
;
1107 unsigned char i
, j
, k
;
1109 unsigned short int m
, assignid_map
, val
;
1110 unsigned char mbuf
[33], quintet
[2];
1111 struct atp_unit
*dev
= (struct atp_unit
*)&host
->hostdata
;
1112 static unsigned char g2q_tab
[8] = {
1113 0x38, 0x31, 0x32, 0x2b, 0x34, 0x2d, 0x2e, 0x27
1116 /* I can't believe we need this before we've even done anything. Remove it
1117 * and see if anyone bitches.
1118 for (i = 0; i < 0x10; i++) {
1123 tmport
= dev
->ioport
[0] + 1;
1124 outb(0x08, tmport
++);
1126 tmport
= dev
->ioport
[0] + 0x11;
1129 if ((dev
->scam_on
& 0x40) == 0) {
1133 m
<<= dev
->host_id
[0];
1135 if (dev
->chip_ver
< 4) {
1140 tmport
= dev
->ioport
[0] + 0x02;
1141 outb(0x02, tmport
++); /* 2*2=4ms,3EH 2/32*3E=3.9ms */
1149 for (i
= 0; i
< j
; i
++) {
1152 if ((m
& assignid_map
) != 0) {
1155 tmport
= dev
->ioport
[0] + 0x0f;
1162 k
= (i
& 0x07) | 0x40;
1167 tmport
= dev
->ioport
[0] + 0x1b;
1168 if (dev
->chip_ver
== 4) {
1174 tmport
= dev
->ioport
[0] + 0x18;
1178 while ((inb(tmport
) & 0x80) == 0x00)
1183 if ((k
== 0x85) || (k
== 0x42)) {
1186 tmport
= dev
->ioport
[0] + 0x10;
1193 tmport
= dev
->ioport
[0] + 0x02;
1195 tmport
= dev
->ioport
[0] + 0x1b;
1200 val
= 0x0080; /* bsy */
1201 tmport
= dev
->ioport
[0] + 0x1c;
1203 val
|= 0x0040; /* sel */
1205 val
|= 0x0004; /* msg */
1207 inb(0x80); /* 2 deskew delay(45ns*2=90ns) */
1208 val
&= 0x007f; /* no bsy */
1211 val
&= 0x00fb; /* after 1ms no msg */
1214 if ((inb(tmport
) & 0x04) != 0) {
1219 for (n
= 0; n
< 0x30000; n
++) {
1220 if ((inb(tmport
) & 0x80) != 0) { /* bsy ? */
1226 for (n
= 0; n
< 0x30000; n
++) {
1227 if ((inb(tmport
) & 0x81) == 0x0081) {
1234 val
|= 0x8003; /* io,cd,db7 */
1237 val
&= 0x00bf; /* no sel */
1242 if ((inb(tmport
) & 0x80) == 0x00) { /* bsy ? */
1245 tmport
= dev
->ioport
[0] + 0x15;
1250 while ((inb(tmport
) & 0x80) == 0)
1256 val
&= 0x00ff; /* synchronization */
1258 fun_scam(dev
, &val
);
1260 val
&= 0x00ff; /* isolation */
1262 fun_scam(dev
, &val
);
1267 if ((inw(tmport
) & 0x2000) == 0) {
1271 val
&= 0x00ff; /* get ID_STRING */
1273 k
= fun_scam(dev
, &val
);
1274 if ((k
& 0x03) == 0) {
1279 if ((k
& 0x02) != 0) {
1290 TCM_5
: /* isolation complete.. */
1292 printk(" \n%x %x %x %s\n ",assignid_map,mbuf[0],mbuf[1],&mbuf[2]); */
1295 if ((j
& 0x20) != 0) { /* bit5=1:ID upto 7 */
1298 if ((j
& 0x06) == 0) { /* IDvalid? */
1305 if ((m
& assignid_map
) == 0) {
1312 G2Q5
: /* srch from max acceptable ID# */
1313 k
= i
; /* max acceptable ID# */
1317 if ((m
& assignid_map
) == 0) {
1324 G2Q_QUIN
: /* k=binID#, */
1327 quintet
[0] = 0x38; /* 1st dft ID<8 */
1329 quintet
[0] = 0x31; /* 1st ID>=8 */
1332 quintet
[1] = g2q_tab
[k
];
1334 val
&= 0x00ff; /* AssignID 1stQuintet,AH=001xxxxx */
1335 m
= quintet
[0] << 8;
1337 fun_scam(dev
, &val
);
1338 val
&= 0x00ff; /* AssignID 2ndQuintet,AH=001xxxxx */
1339 m
= quintet
[1] << 8;
1341 fun_scam(dev
, &val
);
1347 static void is870(struct atp_unit
*dev
, unsigned int wkport
)
1349 unsigned int tmport
;
1350 unsigned char i
, j
, k
, rmb
, n
;
1351 unsigned short int m
;
1352 static unsigned char mbuf
[512];
1353 static unsigned char satn
[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
1354 static unsigned char inqd
[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
1355 static unsigned char synn
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1356 static unsigned char synu
[6] = { 0x80, 1, 3, 1, 0x0c, 0x0e };
1357 static unsigned char synw
[6] = { 0x80, 1, 3, 1, 0x0c, 0x07 };
1358 static unsigned char wide
[6] = { 0x80, 1, 2, 3, 1, 0 };
1360 tmport
= wkport
+ 0x3a;
1361 outb((unsigned char) (inb(tmport
) | 0x10), tmport
);
1363 for (i
= 0; i
< 16; i
++) {
1364 if ((dev
->chip_ver
!= 4) && (i
> 7)) {
1369 if ((m
& dev
->active_id
[0]) != 0) {
1372 if (i
== dev
->host_id
[0]) {
1373 printk(KERN_INFO
" ID: %2d Host Adapter\n", dev
->host_id
[0]);
1376 tmport
= wkport
+ 0x1b;
1377 if (dev
->chip_ver
== 4) {
1382 tmport
= wkport
+ 1;
1383 outb(0x08, tmport
++);
1384 outb(0x7f, tmport
++);
1385 outb(satn
[0], tmport
++);
1386 outb(satn
[1], tmport
++);
1387 outb(satn
[2], tmport
++);
1388 outb(satn
[3], tmport
++);
1389 outb(satn
[4], tmport
++);
1390 outb(satn
[5], tmport
++);
1394 outb(dev
->id
[0][i
].devsp
, tmport
++);
1396 outb(satn
[6], tmport
++);
1397 outb(satn
[7], tmport
++);
1399 if ((j
& 0x08) != 0) {
1400 j
= (j
& 0x07) | 0x40;
1404 outb(satn
[8], tmport
);
1407 while ((inb(tmport
) & 0x80) == 0x00)
1411 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1414 while (inb(tmport
) != 0x8e)
1417 dev
->active_id
[0] |= m
;
1419 tmport
= wkport
+ 0x10;
1421 tmport
= wkport
+ 0x04;
1425 tmport
= wkport
+ 0x18;
1428 while ((inb(tmport
) & 0x80) == 0x00)
1433 tmport
= wkport
+ 0x10;
1438 tmport
= wkport
+ 3;
1439 outb(inqd
[0], tmport
++);
1440 outb(inqd
[1], tmport
++);
1441 outb(inqd
[2], tmport
++);
1442 outb(inqd
[3], tmport
++);
1443 outb(inqd
[4], tmport
++);
1444 outb(inqd
[5], tmport
);
1448 outb(dev
->id
[0][i
].devsp
, tmport
++);
1450 outb(inqd
[6], tmport
++);
1451 outb(inqd
[7], tmport
++);
1453 outb(inqd
[8], tmport
);
1456 while ((inb(tmport
) & 0x80) == 0x00)
1460 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1463 while (inb(tmport
) != 0x8e)
1466 tmport
= wkport
+ 0x1b;
1467 if (dev
->chip_ver
== 4)
1470 tmport
= wkport
+ 0x18;
1476 if ((k
& 0x01) != 0) {
1478 mbuf
[j
++] = inb(tmport
);
1482 if ((k
& 0x80) == 0) {
1490 tmport
= wkport
+ 0x10;
1500 while ((inb(tmport
) & 0x80) == 0x00)
1504 if (inb(tmport
) != 0x16) {
1509 printk(KERN_INFO
" ID: %2d %s\n", i
, &mbuf
[8]);
1510 dev
->id
[0][i
].devtype
= mbuf
[0];
1513 if (dev
->chip_ver
!= 4) {
1516 if ((mbuf
[7] & 0x60) == 0) {
1519 if ((dev
->global_map
[0] & 0x20) == 0) {
1522 tmport
= wkport
+ 0x1b;
1524 tmport
= wkport
+ 3;
1525 outb(satn
[0], tmport
++);
1526 outb(satn
[1], tmport
++);
1527 outb(satn
[2], tmport
++);
1528 outb(satn
[3], tmport
++);
1529 outb(satn
[4], tmport
++);
1530 outb(satn
[5], tmport
++);
1534 outb(dev
->id
[0][i
].devsp
, tmport
++);
1536 outb(satn
[6], tmport
++);
1537 outb(satn
[7], tmport
++);
1539 outb(satn
[8], tmport
);
1542 while ((inb(tmport
) & 0x80) == 0x00)
1546 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1549 while (inb(tmport
) != 0x8e)
1554 tmport
= wkport
+ 0x14;
1560 while ((inb(tmport
) & 0x80) == 0) {
1561 if ((inb(tmport
) & 0x01) != 0) {
1563 outb(wide
[j
++], tmport
);
1569 while ((inb(tmport
) & 0x80) == 0x00)
1572 j
= inb(tmport
) & 0x0f;
1584 tmport
= wkport
+ 0x18;
1587 while ((inb(tmport
) & 0x80) == 0) {
1588 if ((inb(tmport
) & 0x01) != 0) {
1595 j
= inb(tmport
) & 0x0f;
1607 tmport
= wkport
+ 0x14;
1615 if ((j
& 0x01) != 0) {
1617 mbuf
[k
++] = inb(tmport
);
1621 if ((j
& 0x80) == 0x00) {
1625 j
= inb(tmport
) & 0x0f;
1637 tmport
= wkport
+ 0x10;
1639 tmport
= wkport
+ 0x14;
1645 while ((inb(tmport
) & 0x80) == 0x00)
1656 if (mbuf
[0] != 0x01) {
1659 if (mbuf
[1] != 0x02) {
1662 if (mbuf
[2] != 0x03) {
1665 if (mbuf
[3] != 0x01) {
1670 dev
->wide_id
[0] |= m
;
1672 if ((dev
->id
[0][i
].devtype
== 0x00) || (dev
->id
[0][i
].devtype
== 0x07) || ((dev
->id
[0][i
].devtype
== 0x05) && ((n
& 0x10) != 0))) {
1677 tmport
= wkport
+ 0x1b;
1679 if ((m
& dev
->wide_id
[0]) != 0) {
1683 tmport
= wkport
+ 3;
1684 outb(satn
[0], tmport
++);
1685 outb(satn
[1], tmport
++);
1686 outb(satn
[2], tmport
++);
1687 outb(satn
[3], tmport
++);
1688 outb(satn
[4], tmport
++);
1689 outb(satn
[5], tmport
++);
1693 outb(dev
->id
[0][i
].devsp
, tmport
++);
1695 outb(satn
[6], tmport
++);
1696 outb(satn
[7], tmport
++);
1698 outb(satn
[8], tmport
);
1701 while ((inb(tmport
) & 0x80) == 0x00)
1705 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1708 while (inb(tmport
) != 0x8e)
1713 tmport
= wkport
+ 0x14;
1719 while ((inb(tmport
) & 0x80) == 0) {
1720 if ((inb(tmport
) & 0x01) != 0) {
1722 if ((m
& dev
->wide_id
[0]) != 0) {
1723 outb(synw
[j
++], tmport
);
1725 if ((m
& dev
->ultra_map
[0]) != 0) {
1726 outb(synu
[j
++], tmport
);
1728 outb(synn
[j
++], tmport
);
1736 while ((inb(tmport
) & 0x80) == 0x00)
1739 j
= inb(tmport
) & 0x0f;
1751 tmport
= wkport
+ 0x18;
1754 while ((inb(tmport
) & 0x80) == 0x00) {
1755 if ((inb(tmport
) & 0x01) != 0x00) {
1778 tmport
= wkport
+ 0x14;
1786 if ((j
& 0x01) != 0x00) {
1788 mbuf
[k
++] = inb(tmport
);
1792 if ((j
& 0x80) == 0x00) {
1797 while ((inb(tmport
) & 0x80) == 0x00)
1816 tmport
= wkport
+ 0x10;
1819 tmport
= wkport
+ 0x14;
1825 while ((inb(tmport
) & 0x80) == 0x00)
1833 if (mbuf
[0] != 0x01) {
1836 if (mbuf
[1] != 0x03) {
1839 if (mbuf
[4] == 0x00) {
1842 if (mbuf
[3] > 0x64) {
1845 if (mbuf
[4] > 0x0c) {
1848 dev
->id
[0][i
].devsp
= mbuf
[4];
1849 if ((mbuf
[3] < 0x0d) && (rmb
== 0)) {
1853 if (mbuf
[3] < 0x1a) {
1857 if (mbuf
[3] < 0x33) {
1861 if (mbuf
[3] < 0x4c) {
1867 dev
->id
[0][i
].devsp
= (dev
->id
[0][i
].devsp
& 0x0f) | j
;
1869 tmport
= wkport
+ 0x3a;
1870 outb((unsigned char) (inb(tmport
) & 0xef), tmport
);
1873 static void is880(struct atp_unit
*dev
, unsigned int wkport
)
1875 unsigned int tmport
;
1876 unsigned char i
, j
, k
, rmb
, n
, lvdmode
;
1877 unsigned short int m
;
1878 static unsigned char mbuf
[512];
1879 static unsigned char satn
[9] = { 0, 0, 0, 0, 0, 0, 0, 6, 6 };
1880 static unsigned char inqd
[9] = { 0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6 };
1881 static unsigned char synn
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1882 unsigned char synu
[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
1883 static unsigned char synw
[6] = { 0x80, 1, 3, 1, 0x19, 0x0e };
1884 unsigned char synuw
[6] = { 0x80, 1, 3, 1, 0x0a, 0x0e };
1885 static unsigned char wide
[6] = { 0x80, 1, 2, 3, 1, 0 };
1886 static unsigned char u3
[9] = { 0x80, 1, 6, 4, 0x09, 00, 0x0e, 0x01, 0x02 };
1888 lvdmode
= inb(wkport
+ 0x3f) & 0x40;
1890 for (i
= 0; i
< 16; i
++) {
1893 if ((m
& dev
->active_id
[0]) != 0) {
1896 if (i
== dev
->host_id
[0]) {
1897 printk(KERN_INFO
" ID: %2d Host Adapter\n", dev
->host_id
[0]);
1900 tmport
= wkport
+ 0x5b;
1902 tmport
= wkport
+ 0x41;
1903 outb(0x08, tmport
++);
1904 outb(0x7f, tmport
++);
1905 outb(satn
[0], tmport
++);
1906 outb(satn
[1], tmport
++);
1907 outb(satn
[2], tmport
++);
1908 outb(satn
[3], tmport
++);
1909 outb(satn
[4], tmport
++);
1910 outb(satn
[5], tmport
++);
1914 outb(dev
->id
[0][i
].devsp
, tmport
++);
1916 outb(satn
[6], tmport
++);
1917 outb(satn
[7], tmport
++);
1919 if ((j
& 0x08) != 0) {
1920 j
= (j
& 0x07) | 0x40;
1924 outb(satn
[8], tmport
);
1927 while ((inb(tmport
) & 0x80) == 0x00)
1931 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1934 while (inb(tmport
) != 0x8e)
1937 dev
->active_id
[0] |= m
;
1939 tmport
= wkport
+ 0x50;
1941 tmport
= wkport
+ 0x54;
1945 tmport
= wkport
+ 0x58;
1949 while ((inb(tmport
) & 0x80) == 0x00)
1955 tmport
= wkport
+ 0x50;
1960 tmport
= wkport
+ 0x43;
1961 outb(inqd
[0], tmport
++);
1962 outb(inqd
[1], tmport
++);
1963 outb(inqd
[2], tmport
++);
1964 outb(inqd
[3], tmport
++);
1965 outb(inqd
[4], tmport
++);
1966 outb(inqd
[5], tmport
);
1970 outb(dev
->id
[0][i
].devsp
, tmport
++);
1972 outb(inqd
[6], tmport
++);
1973 outb(inqd
[7], tmport
++);
1975 outb(inqd
[8], tmport
);
1978 while ((inb(tmport
) & 0x80) == 0x00)
1982 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
1985 while (inb(tmport
) != 0x8e)
1988 tmport
= wkport
+ 0x5b;
1990 tmport
= wkport
+ 0x58;
1996 if ((k
& 0x01) != 0) {
1998 mbuf
[j
++] = inb(tmport
);
2002 if ((k
& 0x80) == 0) {
2010 tmport
= wkport
+ 0x50;
2019 while ((inb(tmport
) & 0x80) == 0x00)
2023 if (inb(tmport
) != 0x16)
2028 printk(KERN_INFO
" ID: %2d %s\n", i
, &mbuf
[8]);
2029 dev
->id
[0][i
].devtype
= mbuf
[0];
2032 if ((mbuf
[7] & 0x60) == 0) {
2035 if ((i
< 8) && ((dev
->global_map
[0] & 0x20) == 0)) {
2041 if (dev
->sp
[0][i
] != 0x04) // force u2
2046 tmport
= wkport
+ 0x5b;
2048 tmport
= wkport
+ 0x43;
2049 outb(satn
[0], tmport
++);
2050 outb(satn
[1], tmport
++);
2051 outb(satn
[2], tmport
++);
2052 outb(satn
[3], tmport
++);
2053 outb(satn
[4], tmport
++);
2054 outb(satn
[5], tmport
++);
2058 outb(dev
->id
[0][i
].devsp
, tmport
++);
2060 outb(satn
[6], tmport
++);
2061 outb(satn
[7], tmport
++);
2063 outb(satn
[8], tmport
);
2066 while ((inb(tmport
) & 0x80) == 0x00)
2071 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
2074 while (inb(tmport
) != 0x8e)
2079 tmport
= wkport
+ 0x54;
2085 while ((inb(tmport
) & 0x80) == 0) {
2086 if ((inb(tmport
) & 0x01) != 0) {
2088 outb(u3
[j
++], tmport
);
2094 while ((inb(tmport
) & 0x80) == 0x00)
2097 j
= inb(tmport
) & 0x0f;
2109 tmport
= wkport
+ 0x58;
2112 while ((inb(tmport
) & 0x80) == 0) {
2113 if ((inb(tmport
) & 0x01) != 0) {
2120 j
= inb(tmport
) & 0x0f;
2132 tmport
= wkport
+ 0x54;
2140 if ((j
& 0x01) != 0) {
2142 mbuf
[k
++] = inb(tmport
);
2146 if ((j
& 0x80) == 0x00) {
2150 j
= inb(tmport
) & 0x0f;
2162 tmport
= wkport
+ 0x50;
2164 tmport
= wkport
+ 0x54;
2170 while ((inb(tmport
) & 0x80) == 0x00)
2181 if (mbuf
[0] != 0x01) {
2184 if (mbuf
[1] != 0x06) {
2187 if (mbuf
[2] != 0x04) {
2190 if (mbuf
[3] == 0x09) {
2193 dev
->wide_id
[0] |= m
;
2194 dev
->id
[0][i
].devsp
= 0xce;
2198 tmport
= wkport
+ 0x5b;
2200 tmport
= wkport
+ 0x43;
2201 outb(satn
[0], tmport
++);
2202 outb(satn
[1], tmport
++);
2203 outb(satn
[2], tmport
++);
2204 outb(satn
[3], tmport
++);
2205 outb(satn
[4], tmport
++);
2206 outb(satn
[5], tmport
++);
2210 outb(dev
->id
[0][i
].devsp
, tmport
++);
2212 outb(satn
[6], tmport
++);
2213 outb(satn
[7], tmport
++);
2215 outb(satn
[8], tmport
);
2218 while ((inb(tmport
) & 0x80) == 0x00)
2222 if (inb(tmport
) != 0x11 && inb(tmport
) != 0x8e)
2225 while (inb(tmport
) != 0x8e)
2230 tmport
= wkport
+ 0x54;
2236 while ((inb(tmport
) & 0x80) == 0) {
2237 if ((inb(tmport
) & 0x01) != 0) {
2239 outb(wide
[j
++], tmport
);
2244 while ((inb(tmport
) & 0x80) == 0x00)
2247 j
= inb(tmport
) & 0x0f;
2259 tmport
= wkport
+ 0x58;
2262 while ((inb(tmport
) & 0x80) == 0) {
2263 if ((inb(tmport
) & 0x01) != 0) {
2270 j
= inb(tmport
) & 0x0f;
2282 tmport
= wkport
+ 0x54;
2290 if ((j
& 0x01) != 0) {
2292 mbuf
[k
++] = inb(tmport
);
2296 if ((j
& 0x80) == 0x00) {
2300 j
= inb(tmport
) & 0x0f;
2312 tmport
= wkport
+ 0x50;
2314 tmport
= wkport
+ 0x54;
2320 while ((inb(tmport
) & 0x80) == 0x00)
2331 if (mbuf
[0] != 0x01) {
2334 if (mbuf
[1] != 0x02) {
2337 if (mbuf
[2] != 0x03) {
2340 if (mbuf
[3] != 0x01) {
2345 dev
->wide_id
[0] |= m
;
2347 if ((dev
->id
[0][i
].devtype
== 0x00) || (dev
->id
[0][i
].devtype
== 0x07) || ((dev
->id
[0][i
].devtype
== 0x05) && ((n
& 0x10) != 0))) {
2350 if ((dev
->async
[0] & m
) != 0) {
2356 if (dev
->sp
[0][i
] == 0x02) {
2360 if (dev
->sp
[0][i
] >= 0x03) {
2365 tmport
= wkport
+ 0x5b;
2367 if ((m
& dev
->wide_id
[0]) != 0) {
2371 tmport
= wkport
+ 0x43;
2372 outb(satn
[0], tmport
++);
2373 outb(satn
[1], tmport
++);
2374 outb(satn
[2], tmport
++);
2375 outb(satn
[3], tmport
++);
2376 outb(satn
[4], tmport
++);
2377 outb(satn
[5], tmport
++);
2381 outb(dev
->id
[0][i
].devsp
, tmport
++);
2383 outb(satn
[6], tmport
++);
2384 outb(satn
[7], tmport
++);
2386 outb(satn
[8], tmport
);
2389 while ((inb(tmport
) & 0x80) == 0x00)
2393 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
2396 while (inb(tmport
) != 0x8e)
2401 tmport
= wkport
+ 0x54;
2407 while ((inb(tmport
) & 0x80) == 0) {
2408 if ((inb(tmport
) & 0x01) != 0) {
2410 if ((m
& dev
->wide_id
[0]) != 0) {
2411 if ((m
& dev
->ultra_map
[0]) != 0) {
2412 outb(synuw
[j
++], tmport
);
2414 outb(synw
[j
++], tmport
);
2417 if ((m
& dev
->ultra_map
[0]) != 0) {
2418 outb(synu
[j
++], tmport
);
2420 outb(synn
[j
++], tmport
);
2428 while ((inb(tmport
) & 0x80) == 0x00)
2431 j
= inb(tmport
) & 0x0f;
2443 tmport
= wkport
+ 0x58;
2446 while ((inb(tmport
) & 0x80) == 0x00) {
2447 if ((inb(tmport
) & 0x01) != 0x00) {
2470 tmport
= wkport
+ 0x54;
2478 if ((j
& 0x01) != 0x00) {
2480 mbuf
[k
++] = inb(tmport
);
2484 if ((j
& 0x80) == 0x00) {
2489 while ((inb(tmport
) & 0x80) == 0x00)
2508 tmport
= wkport
+ 0x50;
2511 tmport
= wkport
+ 0x54;
2517 while ((inb(tmport
) & 0x80) == 0x00)
2525 if (mbuf
[0] != 0x01) {
2528 if (mbuf
[1] != 0x03) {
2531 if (mbuf
[4] == 0x00) {
2534 if (mbuf
[3] > 0x64) {
2537 if (mbuf
[4] > 0x0e) {
2540 dev
->id
[0][i
].devsp
= mbuf
[4];
2541 if (mbuf
[3] < 0x0c) {
2545 if ((mbuf
[3] < 0x0d) && (rmb
== 0)) {
2549 if (mbuf
[3] < 0x1a) {
2553 if (mbuf
[3] < 0x33) {
2557 if (mbuf
[3] < 0x4c) {
2563 dev
->id
[0][i
].devsp
= (dev
->id
[0][i
].devsp
& 0x0f) | j
;
2567 static void atp870u_free_tables(struct Scsi_Host
*host
)
2569 struct atp_unit
*atp_dev
= (struct atp_unit
*)&host
->hostdata
;
2571 for (j
=0; j
< 2; j
++) {
2572 for (k
= 0; k
< 16; k
++) {
2573 if (!atp_dev
->id
[j
][k
].prd_table
)
2575 pci_free_consistent(atp_dev
->pdev
, 1024, atp_dev
->id
[j
][k
].prd_table
, atp_dev
->id
[j
][k
].prdaddr
);
2576 atp_dev
->id
[j
][k
].prd_table
= NULL
;
2581 static int atp870u_init_tables(struct Scsi_Host
*host
)
2583 struct atp_unit
*atp_dev
= (struct atp_unit
*)&host
->hostdata
;
2585 for(c
=0;c
< 2;c
++) {
2587 atp_dev
->id
[c
][k
].prd_table
= pci_alloc_consistent(atp_dev
->pdev
, 1024, &(atp_dev
->id
[c
][k
].prdaddr
));
2588 if (!atp_dev
->id
[c
][k
].prd_table
) {
2589 printk("atp870u_init_tables fail\n");
2590 atp870u_free_tables(host
);
2593 atp_dev
->id
[c
][k
].devsp
=0x20;
2594 atp_dev
->id
[c
][k
].devtype
= 0x7f;
2595 atp_dev
->id
[c
][k
].curr_req
= NULL
;
2598 atp_dev
->active_id
[c
] = 0;
2599 atp_dev
->wide_id
[c
] = 0;
2600 atp_dev
->host_id
[c
] = 0x07;
2601 atp_dev
->quhd
[c
] = 0;
2602 atp_dev
->quend
[c
] = 0;
2603 atp_dev
->last_cmd
[c
] = 0xff;
2604 atp_dev
->in_snd
[c
] = 0;
2605 atp_dev
->in_int
[c
] = 0;
2607 for (k
= 0; k
< qcnt
; k
++) {
2608 atp_dev
->quereq
[c
][k
] = NULL
;
2610 for (k
= 0; k
< 16; k
++) {
2611 atp_dev
->id
[c
][k
].curr_req
= NULL
;
2612 atp_dev
->sp
[c
][k
] = 0x04;
2618 /* return non-zero on detection */
2619 static int atp870u_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
2621 unsigned char k
, m
, c
;
2622 unsigned long flags
;
2623 unsigned int base_io
, tmport
, error
,n
;
2624 unsigned char host_id
;
2625 struct Scsi_Host
*shpnt
= NULL
;
2626 struct atp_unit atp_dev
, *p
;
2627 unsigned char setupdata
[2][16];
2630 if (pci_enable_device(pdev
))
2633 if (!pci_set_dma_mask(pdev
, 0xFFFFFFFFUL
)) {
2634 printk(KERN_INFO
"atp870u: use 32bit DMA mask.\n");
2636 printk(KERN_ERR
"atp870u: DMA mask required but not available.\n");
2640 memset(&atp_dev
, 0, sizeof atp_dev
);
2642 * It's probably easier to weed out some revisions like
2643 * this than via the PCI device table
2645 if (ent
->device
== PCI_DEVICE_ID_ARTOP_AEC7610
) {
2646 error
= pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &atp_dev
.chip_ver
);
2647 if (atp_dev
.chip_ver
< 2)
2651 switch (ent
->device
) {
2652 case PCI_DEVICE_ID_ARTOP_AEC7612UW
:
2653 case PCI_DEVICE_ID_ARTOP_AEC7612SUW
:
2657 atp_dev
.chip_ver
= 0x04;
2661 base_io
= pci_resource_start(pdev
, 0);
2662 base_io
&= 0xfffffff8;
2664 if ((ent
->device
== ATP880_DEVID1
)||(ent
->device
== ATP880_DEVID2
)) {
2665 error
= pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &atp_dev
.chip_ver
);
2666 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, 0x80);//JCC082803
2668 host_id
= inb(base_io
+ 0x39);
2671 printk(KERN_INFO
" ACARD AEC-67160 PCI Ultra3 LVD Host Adapter: %d"
2672 " IO:%x, IRQ:%d.\n", count
, base_io
, pdev
->irq
);
2673 atp_dev
.ioport
[0] = base_io
+ 0x40;
2674 atp_dev
.pciport
[0] = base_io
+ 0x28;
2675 atp_dev
.dev_id
= ent
->device
;
2676 atp_dev
.host_id
[0] = host_id
;
2678 tmport
= base_io
+ 0x22;
2679 atp_dev
.scam_on
= inb(tmport
);
2681 atp_dev
.global_map
[0] = inb(tmport
);
2683 atp_dev
.ultra_map
[0] = inw(tmport
);
2691 outw(n
, base_io
+ 0x34);
2693 if (inb(base_io
+ 0x30) == 0xff)
2696 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x30);
2697 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x31);
2698 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x32);
2699 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x33);
2700 outw(n
, base_io
+ 0x34);
2702 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x30);
2703 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x31);
2704 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x32);
2705 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x33);
2706 outw(n
, base_io
+ 0x34);
2708 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x30);
2709 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x31);
2710 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x32);
2711 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x33);
2712 outw(n
, base_io
+ 0x34);
2714 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x30);
2715 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x31);
2716 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x32);
2717 atp_dev
.sp
[0][m
++] = inb(base_io
+ 0x33);
2721 outw(0, base_io
+ 0x34);
2722 atp_dev
.ultra_map
[0] = 0;
2723 atp_dev
.async
[0] = 0;
2724 for (k
= 0; k
< 16; k
++) {
2727 if (atp_dev
.sp
[0][k
] > 1) {
2728 atp_dev
.ultra_map
[0] |= n
;
2730 if (atp_dev
.sp
[0][k
] == 0)
2731 atp_dev
.async
[0] |= n
;
2734 atp_dev
.async
[0] = ~(atp_dev
.async
[0]);
2735 outb(atp_dev
.global_map
[0], base_io
+ 0x35);
2737 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
2741 p
= (struct atp_unit
*)&shpnt
->hostdata
;
2743 atp_dev
.host
= shpnt
;
2744 atp_dev
.pdev
= pdev
;
2745 pci_set_drvdata(pdev
, p
);
2746 memcpy(p
, &atp_dev
, sizeof atp_dev
);
2747 if (atp870u_init_tables(shpnt
) < 0) {
2748 printk(KERN_ERR
"Unable to allocate tables for Acard controller\n");
2752 if (request_irq(pdev
->irq
, atp870u_intr_handle
, SA_SHIRQ
, "atp880i", shpnt
)) {
2753 printk(KERN_ERR
"Unable to allocate IRQ%d for Acard controller.\n", pdev
->irq
);
2757 spin_lock_irqsave(shpnt
->host_lock
, flags
);
2758 tmport
= base_io
+ 0x38;
2759 k
= inb(tmport
) & 0x80;
2766 tmport
= base_io
+ 0x5b;
2770 tmport
= base_io
+ 0x40;
2771 outb((host_id
| 0x08), tmport
);
2775 while ((inb(tmport
) & 0x80) == 0)
2779 tmport
= base_io
+ 0x41;
2782 tmport
= base_io
+ 0x51;
2787 tmport
= base_io
+ 0x38;
2790 shpnt
->this_id
= host_id
;
2791 shpnt
->unique_id
= base_io
;
2792 shpnt
->io_port
= base_io
;
2793 shpnt
->n_io_port
= 0x60; /* Number of bytes of I/O space used */
2794 shpnt
->irq
= pdev
->irq
;
2795 } else if (ent
->device
== ATP885_DEVID
) {
2796 printk(KERN_INFO
" ACARD AEC-67162 PCI Ultra3 LVD Host Adapter: IO:%x, IRQ:%d.\n"
2797 , base_io
, pdev
->irq
);
2799 atp_dev
.pdev
= pdev
;
2800 atp_dev
.dev_id
= ent
->device
;
2801 atp_dev
.baseport
= base_io
;
2802 atp_dev
.ioport
[0] = base_io
+ 0x80;
2803 atp_dev
.ioport
[1] = base_io
+ 0xc0;
2804 atp_dev
.pciport
[0] = base_io
+ 0x40;
2805 atp_dev
.pciport
[1] = base_io
+ 0x50;
2807 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
2811 p
= (struct atp_unit
*)&shpnt
->hostdata
;
2813 atp_dev
.host
= shpnt
;
2814 atp_dev
.pdev
= pdev
;
2815 pci_set_drvdata(pdev
, p
);
2816 memcpy(p
, &atp_dev
, sizeof(struct atp_unit
));
2817 if (atp870u_init_tables(shpnt
) < 0)
2821 printk("request_irq() shpnt %p hostdata %p\n", shpnt
, p
);
2823 if (request_irq(pdev
->irq
, atp870u_intr_handle
, SA_SHIRQ
, "atp870u", shpnt
)) {
2824 printk(KERN_ERR
"Unable to allocate IRQ for Acard controller.\n");
2828 spin_lock_irqsave(shpnt
->host_lock
, flags
);
2830 c
=inb(base_io
+ 0x29);
2831 outb((c
| 0x04),base_io
+ 0x29);
2838 outw(n
,base_io
+ 0x3c);
2839 if (inl(base_io
+ 0x38) == 0xffffffff) {
2842 for (m
=0; m
< 2; m
++) {
2843 p
->global_map
[m
]= 0;
2844 for (k
=0; k
< 4; k
++) {
2845 outw(n
++,base_io
+ 0x3c);
2846 ((unsigned long *)&setupdata
[m
][0])[k
]=inl(base_io
+ 0x38);
2848 for (k
=0; k
< 4; k
++) {
2849 outw(n
++,base_io
+ 0x3c);
2850 ((unsigned long *)&p
->sp
[m
][0])[k
]=inl(base_io
+ 0x38);
2857 printk( "Flash Read OK\n");
2859 c
=inb(base_io
+ 0x29);
2860 outb((c
& 0xfb),base_io
+ 0x29);
2861 for (c
=0;c
< 2;c
++) {
2864 for (k
=0; k
< 16; k
++) {
2867 if (p
->sp
[c
][k
] > 1) {
2868 p
->ultra_map
[c
] |= n
;
2870 if (p
->sp
[c
][k
] == 0) {
2875 p
->async
[c
] = ~(p
->async
[c
]);
2877 if (p
->global_map
[c
] == 0) {
2879 if ((k
& 0x40) != 0)
2880 p
->global_map
[c
] |= 0x20;
2882 p
->global_map
[c
] |= k
;
2883 if ((setupdata
[c
][2] & 0x04) != 0)
2884 p
->global_map
[c
] |= 0x08;
2885 p
->host_id
[c
] = setupdata
[c
][0] & 0x07;
2889 k
= inb(base_io
+ 0x28) & 0x8f;
2891 outb(k
, base_io
+ 0x28);
2892 outb(0x80, base_io
+ 0x41);
2893 outb(0x80, base_io
+ 0x51);
2895 outb(0, base_io
+ 0x41);
2896 outb(0, base_io
+ 0x51);
2898 inb(base_io
+ 0x9b);
2899 inb(base_io
+ 0x97);
2900 inb(base_io
+ 0xdb);
2901 inb(base_io
+ 0xd7);
2902 tmport
= base_io
+ 0x80;
2905 k
= (k
& 0x07) | 0x40;
2912 while ((inb(tmport
) & 0x80) == 0)
2917 tmport
= base_io
+ 0x81;
2920 tmport
= base_io
+ 0x91;
2923 tmport
= base_io
+ 0xc0;
2926 k
= (k
& 0x07) | 0x40;
2933 while ((inb(tmport
) & 0x80) == 0)
2938 tmport
= base_io
+ 0xc1;
2941 tmport
= base_io
+ 0xd1;
2945 printk(KERN_INFO
" Scanning Channel A SCSI Device ...\n");
2946 is885(p
, base_io
+ 0x80, 0);
2947 printk(KERN_INFO
" Scanning Channel B SCSI Device ...\n");
2948 is885(p
, base_io
+ 0xc0, 1);
2950 k
= inb(base_io
+ 0x28) & 0xcf;
2952 outb(k
, base_io
+ 0x28);
2953 k
= inb(base_io
+ 0x1f) | 0x80;
2954 outb(k
, base_io
+ 0x1f);
2955 k
= inb(base_io
+ 0x29) | 0x01;
2956 outb(k
, base_io
+ 0x29);
2958 //printk("atp885: atp_host[0] 0x%p\n", atp_host[0]);
2961 shpnt
->max_lun
= (p
->global_map
[0] & 0x07) + 1;
2962 shpnt
->max_channel
= 1;
2963 shpnt
->this_id
= p
->host_id
[0];
2964 shpnt
->unique_id
= base_io
;
2965 shpnt
->io_port
= base_io
;
2966 shpnt
->n_io_port
= 0xff; /* Number of bytes of I/O space used */
2967 shpnt
->irq
= pdev
->irq
;
2970 error
= pci_read_config_byte(pdev
, 0x49, &host_id
);
2972 printk(KERN_INFO
" ACARD AEC-671X PCI Ultra/W SCSI-2/3 Host Adapter: %d "
2973 "IO:%x, IRQ:%d.\n", count
, base_io
, pdev
->irq
);
2975 atp_dev
.ioport
[0] = base_io
;
2976 atp_dev
.pciport
[0] = base_io
+ 0x20;
2977 atp_dev
.dev_id
= ent
->device
;
2979 atp_dev
.host_id
[0] = host_id
;
2980 tmport
= base_io
+ 0x22;
2981 atp_dev
.scam_on
= inb(tmport
);
2983 atp_dev
.global_map
[0] = inb(tmport
++);
2984 atp_dev
.ultra_map
[0] = inw(tmport
);
2986 if (atp_dev
.ultra_map
[0] == 0) {
2987 atp_dev
.scam_on
= 0x00;
2988 atp_dev
.global_map
[0] = 0x20;
2989 atp_dev
.ultra_map
[0] = 0xffff;
2992 shpnt
= scsi_host_alloc(&atp870u_template
, sizeof(struct atp_unit
));
2996 p
= (struct atp_unit
*)&shpnt
->hostdata
;
2998 atp_dev
.host
= shpnt
;
2999 atp_dev
.pdev
= pdev
;
3000 pci_set_drvdata(pdev
, p
);
3001 memcpy(p
, &atp_dev
, sizeof atp_dev
);
3002 if (atp870u_init_tables(shpnt
) < 0)
3005 if (request_irq(pdev
->irq
, atp870u_intr_handle
, SA_SHIRQ
, "atp870i", shpnt
)) {
3006 printk(KERN_ERR
"Unable to allocate IRQ%d for Acard controller.\n", pdev
->irq
);
3010 spin_lock_irqsave(shpnt
->host_lock
, flags
);
3011 if (atp_dev
.chip_ver
> 0x07) { /* check if atp876 chip then enable terminator */
3012 tmport
= base_io
+ 0x3e;
3016 tmport
= base_io
+ 0x3a;
3017 k
= (inb(tmport
) & 0xf3) | 0x10;
3019 outb((k
& 0xdf), tmport
);
3024 outb((host_id
| 0x08), tmport
);
3028 while ((inb(tmport
) & 0x80) == 0)
3033 tmport
= base_io
+ 1;
3036 tmport
= base_io
+ 0x11;
3041 tmport
= base_io
+ 0x3a;
3042 outb((inb(tmport
) & 0xef), tmport
);
3044 outb((inb(tmport
) | 0x20), tmport
);
3045 if (atp_dev
.chip_ver
== 4)
3049 shpnt
->this_id
= host_id
;
3050 shpnt
->unique_id
= base_io
;
3051 shpnt
->io_port
= base_io
;
3052 shpnt
->n_io_port
= 0x40; /* Number of bytes of I/O space used */
3053 shpnt
->irq
= pdev
->irq
;
3055 spin_unlock_irqrestore(shpnt
->host_lock
, flags
);
3056 if(ent
->device
==ATP885_DEVID
) {
3057 if(!request_region(base_io
, 0xff, "atp870u")) /* Register the IO ports that we use */
3058 goto request_io_fail
;
3059 } else if((ent
->device
==ATP880_DEVID1
)||(ent
->device
==ATP880_DEVID2
)) {
3060 if(!request_region(base_io
, 0x60, "atp870u")) /* Register the IO ports that we use */
3061 goto request_io_fail
;
3063 if(!request_region(base_io
, 0x40, "atp870u")) /* Register the IO ports that we use */
3064 goto request_io_fail
;
3067 if (scsi_add_host(shpnt
, &pdev
->dev
))
3069 scsi_scan_host(shpnt
);
3071 printk("atp870u_prob : exit\n");
3076 printk("atp870u_prob:scsi_add_fail\n");
3077 if(ent
->device
==ATP885_DEVID
) {
3078 release_region(base_io
, 0xff);
3079 } else if((ent
->device
==ATP880_DEVID1
)||(ent
->device
==ATP880_DEVID2
)) {
3080 release_region(base_io
, 0x60);
3082 release_region(base_io
, 0x40);
3085 printk("atp870u_prob:request_io_fail\n");
3086 free_irq(pdev
->irq
, shpnt
);
3088 printk("atp870u_prob:free_table\n");
3089 atp870u_free_tables(shpnt
);
3091 printk("atp870u_prob:unregister\n");
3092 scsi_host_put(shpnt
);
3096 /* The abort command does not leave the device in a clean state where
3097 it is available to be used again. Until this gets worked out, we will
3098 leave it commented out. */
3100 static int atp870u_abort(struct scsi_cmnd
* SCpnt
)
3102 unsigned char j
, k
, c
;
3103 struct scsi_cmnd
*workrequ
;
3104 unsigned int tmport
;
3105 struct atp_unit
*dev
;
3106 struct Scsi_Host
*host
;
3107 host
= SCpnt
->device
->host
;
3109 dev
= (struct atp_unit
*)&host
->hostdata
;
3110 c
=SCpnt
->device
->channel
;
3111 printk(" atp870u: abort Channel = %x \n", c
);
3112 printk("working=%x last_cmd=%x ", dev
->working
[c
], dev
->last_cmd
[c
]);
3113 printk(" quhdu=%x quendu=%x ", dev
->quhd
[c
], dev
->quend
[c
]);
3114 tmport
= dev
->ioport
[c
];
3115 for (j
= 0; j
< 0x18; j
++) {
3116 printk(" r%2x=%2x", j
, inb(tmport
++));
3119 printk(" r1c=%2x", inb(tmport
));
3121 printk(" r1f=%2x in_snd=%2x ", inb(tmport
), dev
->in_snd
[c
]);
3122 tmport
= dev
->pciport
[c
];
3123 printk(" d00=%2x", inb(tmport
));
3125 printk(" d02=%2x", inb(tmport
));
3127 if (dev
->id
[c
][j
].curr_req
!= NULL
) {
3128 workrequ
= dev
->id
[c
][j
].curr_req
;
3129 printk("\n que cdb= ");
3130 for (k
=0; k
< workrequ
->cmd_len
; k
++) {
3131 printk(" %2x ",workrequ
->cmnd
[k
]);
3133 printk(" last_lenu= %x ",(unsigned int)dev
->id
[c
][j
].last_len
);
3139 static const char *atp870u_info(struct Scsi_Host
*notused
)
3141 static char buffer
[128];
3143 strcpy(buffer
, "ACARD AEC-6710/6712/67160 PCI Ultra/W/LVD SCSI-3 Adapter Driver V2.6+ac ");
3148 #define BLS buffer + len + size
3149 static int atp870u_proc_info(struct Scsi_Host
*HBAptr
, char *buffer
,
3150 char **start
, off_t offset
, int length
, int inout
)
3152 static u8 buff
[512];
3161 memset(buff
, 0, sizeof(buff
));
3162 size
+= sprintf(BLS
, "ACARD AEC-671X Driver Version: 2.6+ac\n");
3167 size
+= sprintf(BLS
, "\n");
3168 size
+= sprintf(BLS
, "Adapter Configuration:\n");
3169 size
+= sprintf(BLS
, " Base IO: %#.4lx\n", HBAptr
->io_port
);
3170 size
+= sprintf(BLS
, " IRQ: %d\n", HBAptr
->irq
);
3174 *start
= buffer
+ (offset
- begin
); /* Start of wanted data */
3175 len
-= (offset
- begin
); /* Start slop */
3177 len
= length
; /* Ending slop */
3183 static int atp870u_biosparam(struct scsi_device
*disk
, struct block_device
*dev
,
3184 sector_t capacity
, int *ip
)
3186 int heads
, sectors
, cylinders
;
3190 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
3191 if (cylinders
> 1024) {
3194 cylinders
= (unsigned long)capacity
/ (heads
* sectors
);
3203 static void atp870u_remove (struct pci_dev
*pdev
)
3205 struct atp_unit
*devext
= pci_get_drvdata(pdev
);
3206 struct Scsi_Host
*pshost
= devext
->host
;
3209 scsi_remove_host(pshost
);
3210 printk(KERN_INFO
"free_irq : %d\n",pshost
->irq
);
3211 free_irq(pshost
->irq
, pshost
);
3212 release_region(pshost
->io_port
, pshost
->n_io_port
);
3213 printk(KERN_INFO
"atp870u_free_tables : %p\n",pshost
);
3214 atp870u_free_tables(pshost
);
3215 printk(KERN_INFO
"scsi_host_put : %p\n",pshost
);
3216 scsi_host_put(pshost
);
3217 printk(KERN_INFO
"pci_set_drvdata : %p\n",pdev
);
3218 pci_set_drvdata(pdev
, NULL
);
3220 MODULE_LICENSE("GPL");
3222 static struct scsi_host_template atp870u_template
= {
3223 .module
= THIS_MODULE
,
3224 .name
= "atp870u" /* name */,
3225 .proc_name
= "atp870u",
3226 .proc_info
= atp870u_proc_info
,
3227 .info
= atp870u_info
/* info */,
3228 .queuecommand
= atp870u_queuecommand
/* queuecommand */,
3229 .eh_abort_handler
= atp870u_abort
/* abort */,
3230 .bios_param
= atp870u_biosparam
/* biosparm */,
3231 .can_queue
= qcnt
/* can_queue */,
3232 .this_id
= 7 /* SCSI ID */,
3233 .sg_tablesize
= ATP870U_SCATTER
/*SG_ALL*/ /*SG_NONE*/,
3234 .cmd_per_lun
= ATP870U_CMDLUN
/* commands per lun */,
3235 .use_clustering
= ENABLE_CLUSTERING
,
3236 .max_sectors
= ATP870U_MAX_SECTORS
,
3239 static struct pci_device_id atp870u_id_table
[] = {
3240 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP885_DEVID
) },
3241 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP880_DEVID1
) },
3242 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, ATP880_DEVID2
) },
3243 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7610
) },
3244 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612UW
) },
3245 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612U
) },
3246 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612S
) },
3247 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612D
) },
3248 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_AEC7612SUW
) },
3249 { PCI_DEVICE(PCI_VENDOR_ID_ARTOP
, PCI_DEVICE_ID_ARTOP_8060
) },
3253 MODULE_DEVICE_TABLE(pci
, atp870u_id_table
);
3255 static struct pci_driver atp870u_driver
= {
3256 .id_table
= atp870u_id_table
,
3258 .probe
= atp870u_probe
,
3259 .remove
= __devexit_p(atp870u_remove
),
3262 static int __init
atp870u_init(void)
3265 printk("atp870u_init: Entry\n");
3267 return pci_register_driver(&atp870u_driver
);
3270 static void __exit
atp870u_exit(void)
3273 printk("atp870u_exit: Entry\n");
3275 pci_unregister_driver(&atp870u_driver
);
3278 static void tscam_885(void)
3282 for (i
= 0; i
< 0x2; i
++) {
3290 static void is885(struct atp_unit
*dev
, unsigned int wkport
,unsigned char c
)
3292 unsigned int tmport
;
3293 unsigned char i
, j
, k
, rmb
, n
, lvdmode
;
3294 unsigned short int m
;
3295 static unsigned char mbuf
[512];
3296 static unsigned char satn
[9] = {0, 0, 0, 0, 0, 0, 0, 6, 6};
3297 static unsigned char inqd
[9] = {0x12, 0, 0, 0, 0x24, 0, 0, 0x24, 6};
3298 static unsigned char synn
[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
3299 unsigned char synu
[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
3300 static unsigned char synw
[6] = {0x80, 1, 3, 1, 0x19, 0x0e};
3301 unsigned char synuw
[6] = {0x80, 1, 3, 1, 0x0a, 0x0e};
3302 static unsigned char wide
[6] = {0x80, 1, 2, 3, 1, 0};
3303 static unsigned char u3
[9] = { 0x80,1,6,4,0x09,00,0x0e,0x01,0x02 };
3305 lvdmode
=inb(wkport
+ 0x1b) >> 7;
3307 for (i
= 0; i
< 16; i
++) {
3310 if ((m
& dev
->active_id
[c
]) != 0) {
3313 if (i
== dev
->host_id
[c
]) {
3314 printk(KERN_INFO
" ID: %2d Host Adapter\n", dev
->host_id
[c
]);
3317 tmport
= wkport
+ 0x1b;
3319 tmport
= wkport
+ 0x01;
3320 outb(0x08, tmport
++);
3321 outb(0x7f, tmport
++);
3322 outb(satn
[0], tmport
++);
3323 outb(satn
[1], tmport
++);
3324 outb(satn
[2], tmport
++);
3325 outb(satn
[3], tmport
++);
3326 outb(satn
[4], tmport
++);
3327 outb(satn
[5], tmport
++);
3331 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3334 outb(satn
[6], tmport
++);
3335 outb(satn
[7], tmport
++);
3337 if ((j
& 0x08) != 0) {
3338 j
= (j
& 0x07) | 0x40;
3342 outb(satn
[8], tmport
);
3345 while ((inb(tmport
) & 0x80) == 0x00)
3348 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3351 while (inb(tmport
) != 0x8e)
3353 dev
->active_id
[c
] |= m
;
3355 tmport
= wkport
+ 0x10;
3357 tmport
= wkport
+ 0x14;
3361 tmport
= wkport
+ 0x18;
3364 while ((inb(tmport
) & 0x80) == 0x00)
3369 tmport
= wkport
+ 0x10;
3374 tmport
= wkport
+ 0x03;
3375 outb(inqd
[0], tmport
++);
3376 outb(inqd
[1], tmport
++);
3377 outb(inqd
[2], tmport
++);
3378 outb(inqd
[3], tmport
++);
3379 outb(inqd
[4], tmport
++);
3380 outb(inqd
[5], tmport
);
3384 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3386 outb(inqd
[6], tmport
++);
3387 outb(inqd
[7], tmport
++);
3389 outb(inqd
[8], tmport
);
3391 while ((inb(tmport
) & 0x80) == 0x00)
3394 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3397 while (inb(tmport
) != 0x8e)
3399 tmport
= wkport
+ 0x1b;
3401 tmport
= wkport
+ 0x18;
3407 if ((k
& 0x01) != 0) {
3409 mbuf
[j
++] = inb(tmport
);
3413 if ((k
& 0x80) == 0) {
3421 tmport
= wkport
+ 0x10;
3430 while ((inb(tmport
) & 0x80) == 0x00)
3433 if (inb(tmport
) != 0x16) {
3438 printk( KERN_INFO
" ID: %2d %s\n", i
, &mbuf
[8]);
3439 dev
->id
[c
][i
].devtype
= mbuf
[0];
3442 if ((mbuf
[7] & 0x60) == 0) {
3445 if ((i
< 8) && ((dev
->global_map
[c
] & 0x20) == 0)) {
3451 if (dev
->sp
[c
][i
] != 0x04) { // force u2
3455 tmport
= wkport
+ 0x1b;
3457 tmport
= wkport
+ 0x03;
3458 outb(satn
[0], tmport
++);
3459 outb(satn
[1], tmport
++);
3460 outb(satn
[2], tmport
++);
3461 outb(satn
[3], tmport
++);
3462 outb(satn
[4], tmport
++);
3463 outb(satn
[5], tmport
++);
3467 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3469 outb(satn
[6], tmport
++);
3470 outb(satn
[7], tmport
++);
3472 outb(satn
[8], tmport
);
3475 while ((inb(tmport
) & 0x80) == 0x00)
3478 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3481 while (inb(tmport
) != 0x8e)
3485 tmport
= wkport
+ 0x14;
3491 while ((inb(tmport
) & 0x80) == 0) {
3492 if ((inb(tmport
) & 0x01) != 0) {
3494 outb(u3
[j
++], tmport
);
3500 while ((inb(tmport
) & 0x80) == 0x00)
3502 j
= inb(tmport
) & 0x0f;
3514 tmport
= wkport
+ 0x18;
3517 while ((inb(tmport
) & 0x80) == 0) {
3518 if ((inb(tmport
) & 0x01) != 0) {
3526 j
= inb(tmport
) & 0x0f;
3538 tmport
= wkport
+ 0x14;
3546 if ((j
& 0x01) != 0) {
3548 mbuf
[k
++] = inb(tmport
);
3552 if ((j
& 0x80) == 0x00) {
3556 j
= inb(tmport
) & 0x0f;
3568 tmport
= wkport
+ 0x10;
3570 tmport
= wkport
+ 0x14;
3575 while ((inb(tmport
) & 0x80) == 0x00);
3584 if (mbuf
[0] != 0x01) {
3587 if (mbuf
[1] != 0x06) {
3590 if (mbuf
[2] != 0x04) {
3593 if (mbuf
[3] == 0x09) {
3596 dev
->wide_id
[c
] |= m
;
3597 dev
->id
[c
][i
].devsp
= 0xce;
3599 printk("dev->id[%2d][%2d].devsp = %2x\n",c
,i
,dev
->id
[c
][i
].devsp
);
3604 tmport
= wkport
+ 0x1b;
3606 tmport
= wkport
+ 0x03;
3607 outb(satn
[0], tmport
++);
3608 outb(satn
[1], tmport
++);
3609 outb(satn
[2], tmport
++);
3610 outb(satn
[3], tmport
++);
3611 outb(satn
[4], tmport
++);
3612 outb(satn
[5], tmport
++);
3616 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3618 outb(satn
[6], tmport
++);
3619 outb(satn
[7], tmport
++);
3621 outb(satn
[8], tmport
);
3624 while ((inb(tmport
) & 0x80) == 0x00)
3627 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3630 while (inb(tmport
) != 0x8e)
3634 tmport
= wkport
+ 0x14;
3640 while ((inb(tmport
) & 0x80) == 0) {
3641 if ((inb(tmport
) & 0x01) != 0) {
3643 outb(wide
[j
++], tmport
);
3649 while ((inb(tmport
) & 0x80) == 0x00)
3651 j
= inb(tmport
) & 0x0f;
3663 tmport
= wkport
+ 0x18;
3666 while ((inb(tmport
) & 0x80) == 0) {
3667 if ((inb(tmport
) & 0x01) != 0) {
3675 j
= inb(tmport
) & 0x0f;
3687 tmport
= wkport
+ 0x14;
3695 if ((j
& 0x01) != 0) {
3697 mbuf
[k
++] = inb(tmport
);
3701 if ((j
& 0x80) == 0x00) {
3705 j
= inb(tmport
) & 0x0f;
3717 tmport
= wkport
+ 0x10;
3719 tmport
= wkport
+ 0x14;
3724 while ((inb(tmport
) & 0x80) == 0x00)
3734 if (mbuf
[0] != 0x01) {
3737 if (mbuf
[1] != 0x02) {
3740 if (mbuf
[2] != 0x03) {
3743 if (mbuf
[3] != 0x01) {
3748 dev
->wide_id
[c
] |= m
;
3750 if ((dev
->id
[c
][i
].devtype
== 0x00) || (dev
->id
[c
][i
].devtype
== 0x07) ||
3751 ((dev
->id
[c
][i
].devtype
== 0x05) && ((n
& 0x10) != 0))) {
3754 if ((dev
->async
[c
] & m
) != 0) {
3760 if (dev
->sp
[c
][i
] == 0x02) {
3764 if (dev
->sp
[c
][i
] >= 0x03) {
3769 tmport
= wkport
+ 0x1b;
3771 if ((m
& dev
->wide_id
[c
]) != 0) {
3775 tmport
= wkport
+ 0x03;
3776 outb(satn
[0], tmport
++);
3777 outb(satn
[1], tmport
++);
3778 outb(satn
[2], tmport
++);
3779 outb(satn
[3], tmport
++);
3780 outb(satn
[4], tmport
++);
3781 outb(satn
[5], tmport
++);
3785 outb(dev
->id
[c
][i
].devsp
, tmport
++);
3787 outb(satn
[6], tmport
++);
3788 outb(satn
[7], tmport
++);
3790 outb(satn
[8], tmport
);
3793 while ((inb(tmport
) & 0x80) == 0x00)
3796 if ((inb(tmport
) != 0x11) && (inb(tmport
) != 0x8e)) {
3799 while (inb(tmport
) != 0x8e)
3803 tmport
= wkport
+ 0x14;
3809 while ((inb(tmport
) & 0x80) == 0) {
3810 if ((inb(tmport
) & 0x01) != 0) {
3812 if ((m
& dev
->wide_id
[c
]) != 0) {
3813 if ((m
& dev
->ultra_map
[c
]) != 0) {
3814 outb(synuw
[j
++], tmport
);
3816 outb(synw
[j
++], tmport
);
3819 if ((m
& dev
->ultra_map
[c
]) != 0) {
3820 outb(synu
[j
++], tmport
);
3822 outb(synn
[j
++], tmport
);
3829 while ((inb(tmport
) & 0x80) == 0x00)
3831 j
= inb(tmport
) & 0x0f;
3843 tmport
= wkport
+ 0x18;
3846 while ((inb(tmport
) & 0x80) == 0x00) {
3847 if ((inb(tmport
) & 0x01) != 0x00) {
3871 tmport
= wkport
+ 0x14;
3879 if ((j
& 0x01) != 0x00) {
3881 mbuf
[k
++] = inb(tmport
);
3885 if ((j
& 0x80) == 0x00) {
3889 while ((inb(tmport
) & 0x80) == 0x00);
3906 tmport
= wkport
+ 0x10;
3909 tmport
= wkport
+ 0x14;
3914 while ((inb(tmport
) & 0x80) == 0x00)
3921 if (mbuf
[0] != 0x01) {
3924 if (mbuf
[1] != 0x03) {
3927 if (mbuf
[4] == 0x00) {
3930 if (mbuf
[3] > 0x64) {
3933 if (mbuf
[4] > 0x0e) {
3936 dev
->id
[c
][i
].devsp
= mbuf
[4];
3937 if (mbuf
[3] < 0x0c){
3941 if ((mbuf
[3] < 0x0d) && (rmb
== 0)) {
3945 if (mbuf
[3] < 0x1a) {
3949 if (mbuf
[3] < 0x33) {
3953 if (mbuf
[3] < 0x4c) {
3959 dev
->id
[c
][i
].devsp
= (dev
->id
[c
][i
].devsp
& 0x0f) | j
;
3961 printk("dev->id[%2d][%2d].devsp = %2x\n",c
,i
,dev
->id
[c
][i
].devsp
);
3964 tmport
= wkport
+ 0x16;
3968 module_init(atp870u_init
);
3969 module_exit(atp870u_exit
);