15 #include <linux/kernel.h>
17 #include <linux/types.h>
18 #include <linux/string.h>
22 #include <linux/stat.h>
26 #include <linux/module.h>
33 #include <asm/byteorder.h>
38 #include <asm/ptrace.h>
39 #include <asm/pgtable.h>
40 #include <asm/oplib.h>
44 #include <scsi/scsi.h>
51 #define MAX_TARGETS 16
54 #define DEFAULT_LOOP_COUNT 10000
59 #define PACKB(a, b) (((a)<<4)|(b))
61 static const u_char mbox_param[] = {
131 #define MAX_MBOX_COMMAND ARRAY_SIZE(mbox_param)
134 #define QUEUE_DEPTH(in, out, ql) ((in - out) & (ql))
135 #define REQ_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, \
136 QLOGICPTI_REQ_QUEUE_LEN)
137 #define RES_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, RES_QUEUE_LEN)
139 static inline void qlogicpti_enable_irqs(
struct qlogicpti *qpti)
145 static inline void qlogicpti_disable_irqs(
struct qlogicpti *qpti)
150 static inline void set_sbus_cfg1(
struct qlogicpti *qpti)
160 if (sbus_can_burst64() && (bursts &
DMA_BURST64)) {
181 if (mbox_param[param[0]] == 0)
200 switch (mbox_param[param[0]] >> 4) {
224 while (--loop_count &&
233 while (--loop_count &&
254 switch (mbox_param[param[0]] & 0xf) {
277 static inline void qlogicpti_set_hostdev_defaults(
struct qlogicpti *qpti)
287 qpti->
host_param.data_line_active_negation = 1;
289 qpti->
host_param.command_dma_burst_enable = 1;
319 unsigned short risc_code_addr;
323 risc_code_addr = 0x1000;
349 qlogicpti_enable_irqs(qpti);
363 qlogicpti_set_hostdev_defaults(qpti);
370 param[1] = risc_code_addr;
371 if (qlogicpti_mbox_command(qpti, param, 1)) {
380 param[1] = qpti->
host_param.initiator_scsi_id;
381 if (qlogicpti_mbox_command(qpti, param, 1) ||
396 param[4] = param[5] = 0;
397 if (qlogicpti_mbox_command(qpti, param, 1)) {
408 param[4] = param[5] = 0;
409 if (qlogicpti_mbox_command(qpti, param, 1)) {
419 qlogicpti_mbox_command(qpti, param, 0);
423 qlogicpti_mbox_command(qpti, param, 0);
428 qlogicpti_mbox_command(qpti, param, 0);
432 qlogicpti_mbox_command(qpti, param, 0);
435 param[1] = qpti->
host_param.selection_timeout;
436 qlogicpti_mbox_command(qpti, param, 0);
441 param[2] = (qpti->
dev_param[
i].device_flags << 8);
447 qlogicpti_mbox_command(qpti, param, 0);
455 qlogicpti_mbox_command(qpti, param, 0);
462 #define PTI_RESET_LIMIT 400
467 const char fwname[] =
"qlogic/isp1000.bin";
470 unsigned short csum = 0;
471 unsigned short param[6];
472 unsigned short risc_code_addr, risc_code_length;
490 risc_code_addr = 0x1000;
491 risc_code_length = fw->
size / 2;
498 for (i = 0; i < risc_code_length; i++)
549 param[1] = param[2] = param[3] = param[4] = param[5] = 0;
550 if (qlogicpti_mbox_command(qpti, param, 1)) {
558 for (i = 0; i < risc_code_length; i++) {
560 param[1] = risc_code_addr +
i;
562 if (qlogicpti_mbox_command(qpti, param, 1) ||
564 printk(
"qlogicpti%d: Firmware dload failed, I'm bolixed!\n",
575 qlogicpti_enable_irqs(qpti);
581 param[1] = risc_code_addr;
582 if (qlogicpti_mbox_command(qpti, param, 1) ||
592 param[1] = risc_code_addr;
593 qlogicpti_mbox_command(qpti, param, 1);
596 if (qlogicpti_mbox_command(qpti, param, 1) ||
611 param[1] = qpti->
clock;
612 if (qlogicpti_mbox_command(qpti, param, 1) ||
625 qlogicpti_mbox_command(qpti, param, 1);
629 param[2] = (
unsigned short) 3;
630 qlogicpti_mbox_command(qpti, param, 1);
634 spin_unlock_irqrestore(host->
host_lock, flags);
640 static int qlogicpti_verify_tmon(
struct qlogicpti *qpti)
646 printk(
"qlogicpti%d: Fuse returned to normal state.\n", qpti->
qpti_id);
648 printk(
"qlogicpti%d: termpwr back to normal state.\n", qpti->
qpti_id);
649 if (curstat != qpti->
swsreg) {
651 if (curstat & SREG_FUSE) {
655 if (curstat & SREG_TPOWER) {
662 printk(
"qlogicpti%d: You have a single ended device on a "
663 "differential bus! Please fix!\n", qpti->
qpti_id);
675 spin_lock_irq(&qptichain_lock);
676 if (qptichain !=
NULL) {
686 spin_unlock_irq(&qptichain_lock);
691 spin_lock_irq(&qptichain_lock);
692 if (qptichain == qpti) {
693 qptichain = qpti->
next;
696 while(qlink->
next != qpti)
701 spin_unlock_irq(&qptichain_lock);
712 printk(
"PTI: Qlogic/ISP registers are unmappable\n");
717 sizeof(
unsigned char),
718 "PTI Qlogic/ISP statreg");
720 printk(
"PTI: Qlogic/ISP status register is unmappable\n");
748 printk(
"qlogicpti%d: Cannot acquire irq line\n", qpti->
qpti_id);
757 dp = op->
dev.of_node;
766 "scsi-initiator-id", 7);
768 qpti->
qhost->max_sectors = 64;
773 static void qpti_get_bursts(
struct qlogicpti *qpti)
782 if (bursts == 0xff ||
783 (bursts & DMA_BURST16) == 0 ||
784 (bursts & DMA_BURST32) == 0)
785 bursts = (DMA_BURST32 - 1);
790 static void qpti_get_clock(
struct qlogicpti *qpti)
798 qpti->
clock = (cfreq + 500000)/1000000;
799 if (qpti->
clock == 0)
810 #define QSIZE(entries) (((entries) + 1) * QUEUE_ENTRY_LEN)
816 printk(
"QPTI: Cannot map response queue.\n");
827 printk(
"QPTI: Cannot map request queue.\n");
840 sprintf(buf,
"PTI Qlogic,ISP SBUS SCSI irq %d regs at %p",
851 marker->
hdr.entry_cnt = 1;
861 cmd->
hdr.entry_cnt = 1;
867 if (Cmnd->
device->tagged_supported) {
894 if (scsi_bufflen(Cmnd)) {
897 sg = scsi_sglist(Cmnd);
915 while (sg_count > 0) {
918 ++cmd->
hdr.entry_cnt;
921 if (in_ptr == out_ptr)
925 cont->
hdr.entry_cnt = 0;
926 cont->
hdr.sys_def_1 = 0;
966 static int qlogicpti_slave_configure(
struct scsi_device *sdev)
975 qpti->
dev_param[tgt].device_flags |= 0x10;
977 qpti->
dev_param[tgt].synchronous_offset = 0;
978 qpti->
dev_param[tgt].synchronous_period = 0;
982 qpti->
dev_param[tgt].device_flags |= 0x20;
985 param[1] = (tgt << 8);
986 param[2] = (qpti->
dev_param[tgt].device_flags << 8);
987 if (qpti->
dev_param[tgt].device_flags & 0x10) {
988 param[3] = (qpti->
dev_param[tgt].synchronous_offset << 8) |
993 qlogicpti_mbox_command(qpti, param, 0);
1019 if (in_ptr == out_ptr)
1033 cmd_frob(cmd, Cmnd, qpti);
1034 if ((in_ptr = load_cmd(Cmnd, cmd, qpti, in_ptr, out_ptr)) == -1)
1037 update_can_queue(host, in_ptr, out_ptr);
1060 switch (sts->completion_status) {
1112 id, sts->completion_status);
1117 return (sts->scsi_status &
STATUS_MASK) | (host_status << 16);
1124 u_int in_ptr, out_ptr;
1148 while (out_ptr != in_ptr) {
1173 qlogicpti_return_status(sts, qpti->
qpti_id);
1177 if (scsi_bufflen(Cmnd))
1179 scsi_sglist(Cmnd), scsi_sg_count(Cmnd),
1195 unsigned long flags;
1199 dq = qlogicpti_intr_handler(qpti);
1208 }
while (dq !=
NULL);
1210 spin_unlock_irqrestore(qpti->
qhost->host_lock, flags);
1215 static int qlogicpti_abort(
struct scsi_cmnd *Cmnd)
1227 qlogicpti_disable_irqs(qpti);
1239 param[2] = cmd_cookie >> 16;
1240 param[3] = cmd_cookie & 0xffff;
1241 if (qlogicpti_mbox_command(qpti, param, 0) ||
1248 qlogicpti_enable_irqs(qpti);
1250 return return_status;
1253 static int qlogicpti_reset(
struct scsi_cmnd *Cmnd)
1263 qlogicpti_disable_irqs(qpti);
1267 if (qlogicpti_mbox_command(qpti, param, 0) ||
1274 qlogicpti_enable_irqs(qpti);
1276 return return_status;
1281 .name =
"qlogicpti",
1283 .queuecommand = qlogicpti_queuecommand,
1284 .slave_configure = qlogicpti_slave_configure,
1285 .eh_abort_handler = qlogicpti_abort,
1286 .eh_bus_reset_handler = qlogicpti_reset,
1313 qpti = shost_priv(host);
1322 if (qpti_map_regs(qpti) < 0)
1325 if (qpti_register_irq(qpti) < 0)
1326 goto fail_unmap_regs;
1328 qpti_get_scsi_id(qpti);
1329 qpti_get_bursts(qpti);
1330 qpti_get_clock(qpti);
1335 if (qpti_map_queues(qpti) < 0)
1339 if (qlogicpti_load_firmware(qpti))
1340 goto fail_unmap_queues;
1343 if (qlogicpti_verify_tmon(qpti))
1344 goto fail_unmap_queues;
1348 if (qlogicpti_reset_hardware(host))
1349 goto fail_unmap_queues;
1355 if (fcode && fcode[0])
1356 printk(
"(FCode %s)", fcode);
1360 printk(
"\nqlogicpti%d: [%s Wide, using %s interface]\n",
1362 (qpti->
ultra ?
"Ultra" :
"Fast"),
1363 (qpti->
differential ?
"differential" :
"single ended"));
1365 if (scsi_add_host(host, &op->
dev)) {
1366 printk(
"qlogicpti%d: Failed scsi_add_host\n", qpti->
qpti_id);
1367 goto fail_unmap_queues;
1372 qpti_chain_add(qpti);
1380 #define QSIZE(entries) (((entries) + 1) * QUEUE_ENTRY_LEN)
1385 QSIZE(QLOGICPTI_REQ_QUEUE_LEN),
1394 sizeof(
unsigned char));
1409 qpti_chain_del(qpti);
1419 #define QSIZE(entries) (((entries) + 1) * QUEUE_ENTRY_LEN)
1424 QSIZE(QLOGICPTI_REQ_QUEUE_LEN),
1443 .name =
"PTI,ptisp",
1459 .of_match_table = qpti_match,
1461 .probe = qpti_sbus_probe,
1465 static int __init qpti_init(
void)
1470 static void __exit qpti_exit(
void)