1 /* qlogicpti.c: Performance Technologies QlogicISP sbus card driver. 3 * Copyright (C) 1996 David S. Miller (davem@caipfs.rutgers.edu) 5 * A lot of this driver was directly stolen from Erik H. Moe's PCI 6 * Qlogic ISP driver. Mucho kudos to him for this code. 8 * An even bigger kudos to John Grana at Performance Technologies 9 * for providing me with the hardware to write this driver, you rule 13 #include <linux/kernel.h> 14 #include <linux/delay.h> 15 #include <linux/types.h> 16 #include <linux/string.h> 17 #include <linux/malloc.h> 18 #include <linux/blk.h> 19 #include <linux/proc_fs.h> 20 #include <linux/stat.h> 22 #include <asm/byteorder.h> 30 #include <asm/system.h> 31 #include <asm/machines.h> 32 #include <asm/ptrace.h> 33 #include <asm/pgtable.h> 34 #include <asm/oplib.h> 35 #include <asm/vaddrs.h> 38 #include <linux/module.h> 40 #define MAX_TARGETS 16 43 #define DEFAULT_LOOP_COUNT 1000000 45 #include"qlogicpti_asm.c" 47 static struct qlogicpti
*qptichain
; 48 static int qptis_running
=0; 50 #define PACKB(a, b) (((a)<<4)|(b)) 52 const u_char mbox_param
[] = { 53 PACKB(1,1),/* MBOX_NO_OP */ 54 PACKB(5,5),/* MBOX_LOAD_RAM */ 55 PACKB(2,0),/* MBOX_EXEC_FIRMWARE */ 56 PACKB(5,5),/* MBOX_DUMP_RAM */ 57 PACKB(3,3),/* MBOX_WRITE_RAM_WORD */ 58 PACKB(2,3),/* MBOX_READ_RAM_WORD */ 59 PACKB(6,6),/* MBOX_MAILBOX_REG_TEST */ 60 PACKB(2,3),/* MBOX_VERIFY_CHECKSUM */ 61 PACKB(1,3),/* MBOX_ABOUT_FIRMWARE */ 62 PACKB(0,0),/* 0x0009 */ 63 PACKB(0,0),/* 0x000a */ 64 PACKB(0,0),/* 0x000b */ 65 PACKB(0,0),/* 0x000c */ 66 PACKB(0,0),/* 0x000d */ 67 PACKB(1,2),/* MBOX_CHECK_FIRMWARE */ 68 PACKB(0,0),/* 0x000f */ 69 PACKB(5,5),/* MBOX_INIT_REQ_QUEUE */ 70 PACKB(6,6),/* MBOX_INIT_RES_QUEUE */ 71 PACKB(4,4),/* MBOX_EXECUTE_IOCB */ 72 PACKB(2,2),/* MBOX_WAKE_UP */ 73 PACKB(1,6),/* MBOX_STOP_FIRMWARE */ 74 PACKB(4,4),/* MBOX_ABORT */ 75 PACKB(2,2),/* MBOX_ABORT_DEVICE */ 76 PACKB(3,3),/* MBOX_ABORT_TARGET */ 77 PACKB(2,2),/* MBOX_BUS_RESET */ 78 PACKB(2,3),/* MBOX_STOP_QUEUE */ 79 PACKB(2,3),/* MBOX_START_QUEUE */ 80 PACKB(2,3),/* MBOX_SINGLE_STEP_QUEUE */ 81 PACKB(2,3),/* MBOX_ABORT_QUEUE */ 82 PACKB(2,4),/* MBOX_GET_DEV_QUEUE_STATUS */ 83 PACKB(0,0),/* 0x001e */ 84 PACKB(1,3),/* MBOX_GET_FIRMWARE_STATUS */ 85 PACKB(1,2),/* MBOX_GET_INIT_SCSI_ID */ 86 PACKB(1,2),/* MBOX_GET_SELECT_TIMEOUT */ 87 PACKB(1,3),/* MBOX_GET_RETRY_COUNT */ 88 PACKB(1,2),/* MBOX_GET_TAG_AGE_LIMIT */ 89 PACKB(1,2),/* MBOX_GET_CLOCK_RATE */ 90 PACKB(1,2),/* MBOX_GET_ACT_NEG_STATE */ 91 PACKB(1,2),/* MBOX_GET_ASYNC_DATA_SETUP_TIME */ 92 PACKB(1,3),/* MBOX_GET_SBUS_PARAMS */ 93 PACKB(2,4),/* MBOX_GET_TARGET_PARAMS */ 94 PACKB(2,4),/* MBOX_GET_DEV_QUEUE_PARAMS */ 95 PACKB(0,0),/* 0x002a */ 96 PACKB(0,0),/* 0x002b */ 97 PACKB(0,0),/* 0x002c */ 98 PACKB(0,0),/* 0x002d */ 99 PACKB(0,0),/* 0x002e */ 100 PACKB(0,0),/* 0x002f */ 101 PACKB(2,2),/* MBOX_SET_INIT_SCSI_ID */ 102 PACKB(2,2),/* MBOX_SET_SELECT_TIMEOUT */ 103 PACKB(3,3),/* MBOX_SET_RETRY_COUNT */ 104 PACKB(2,2),/* MBOX_SET_TAG_AGE_LIMIT */ 105 PACKB(2,2),/* MBOX_SET_CLOCK_RATE */ 106 PACKB(2,2),/* MBOX_SET_ACTIVE_NEG_STATE */ 107 PACKB(2,2),/* MBOX_SET_ASYNC_DATA_SETUP_TIME */ 108 PACKB(3,3),/* MBOX_SET_SBUS_CONTROL_PARAMS */ 109 PACKB(4,4),/* MBOX_SET_TARGET_PARAMS */ 110 PACKB(4,4),/* MBOX_SET_DEV_QUEUE_PARAMS */ 111 PACKB(0,0),/* 0x003a */ 112 PACKB(0,0),/* 0x003b */ 113 PACKB(0,0),/* 0x003c */ 114 PACKB(0,0),/* 0x003d */ 115 PACKB(0,0),/* 0x003e */ 116 PACKB(0,0),/* 0x003f */ 117 PACKB(0,0),/* 0x0040 */ 118 PACKB(0,0),/* 0x0041 */ 119 PACKB(0,0)/* 0x0042 */ 122 #define MAX_MBOX_COMMAND (sizeof(mbox_param)/sizeof(u_short)) 124 /* queue length's _must_ be power of two: */ 125 #define QUEUE_DEPTH(in, out, ql) ((in - out) & (ql)) 126 #define REQ_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, \ 127 QLOGICISP_REQ_QUEUE_LEN) 128 #define RES_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, RES_QUEUE_LEN) 130 static struct proc_dir_entry proc_scsi_qlogicpti
= { 131 PROC_SCSI_QLOGICPTI
,7,"qlogicpti", 132 S_IFDIR
| S_IRUGO
| S_IXUGO
,2 135 staticinlinevoidqlogicpti_enable_irqs(struct qlogicpti_regs
*qregs
) 137 qregs
->sbus_ctrl
= SBUS_CTRL_ERIRQ
| SBUS_CTRL_GENAB
; 141 staticinlinevoidqlogicpti_disable_irqs(struct qlogicpti_regs
*qregs
) 146 staticinlinevoidset_sbus_cfg1(struct qlogicpti_regs
*qregs
,unsigned char bursts
) 148 if(bursts
& DMA_BURST32
) { 149 qregs
->sbus_cfg1
= (SBUS_CFG1_BENAB
| SBUS_CFG1_B32
); 150 }else if(bursts
& DMA_BURST16
) { 151 qregs
->sbus_cfg1
= (SBUS_CFG1_BENAB
| SBUS_CFG1_B16
); 152 }else if(bursts
& DMA_BURST8
) { 153 qregs
->sbus_cfg1
= (SBUS_CFG1_BENAB
| SBUS_CFG1_B8
); 155 qregs
->sbus_cfg1
=0;/* No sbus bursts for you... */ 159 static intqlogicpti_mbox_command(struct qlogicpti
*qpti
, u_short param
[],int force
) 161 struct qlogicpti_regs
*qregs
= qpti
->qregs
; 164 if(mbox_param
[param
[0]] ==0) 167 loop_count
= DEFAULT_LOOP_COUNT
; 168 while(--loop_count
&& (qregs
->hcctrl
& HCCTRL_HIRQ
)) 171 printk(KERN_EMERG
"qlogicpti: mbox_command loop timeout #1\n"); 173 switch(mbox_param
[param
[0]] >>4) { 174 case6: qregs
->mbox5
= param
[5]; 175 case5: qregs
->mbox4
= param
[4]; 176 case4: qregs
->mbox3
= param
[3]; 177 case3: qregs
->mbox2
= param
[2]; 178 case2: qregs
->mbox1
= param
[1]; 179 case1: qregs
->mbox0
= param
[0]; 182 qregs
->hcctrl
|= HCCTRL_SHIRQ
; 184 loop_count
= DEFAULT_LOOP_COUNT
; 185 while(--loop_count
&& !(qregs
->sbus_semaphore
& SBUS_SEMAPHORE_LCK
)) 188 printk(KERN_EMERG
"qlogicpti: mbox_command loop timeout #2\n"); 190 loop_count
= DEFAULT_LOOP_COUNT
; 191 while(--loop_count
&& (qregs
->mbox0
==0x04)) 194 printk(KERN_EMERG
"qlogicpti: mbox_command loop timeout #3\n"); 197 qregs
->hcctrl
= HCCTRL_CRIRQ
; 199 if((qregs
->mbox5
- qpti
->res_out_ptr
) ==0) 200 qregs
->hcctrl
= HCCTRL_CRIRQ
; 203 switch(mbox_param
[param
[0]] &0xf) { 204 case6: param
[5] = qregs
->mbox5
; 205 case5: param
[4] = qregs
->mbox4
; 206 case4: param
[3] = qregs
->mbox3
; 207 case3: param
[2] = qregs
->mbox2
; 208 case2: param
[1] = qregs
->mbox1
; 209 case1: param
[0] = qregs
->mbox0
; 212 qregs
->sbus_semaphore
&= ~(SBUS_SEMAPHORE_LCK
); 216 static intqlogicpti_reset_hardware(struct Scsi_Host
*host
) 218 struct qlogicpti
*qpti
= (struct qlogicpti
*) host
->hostdata
; 219 struct qlogicpti_regs
*qregs
= qpti
->qregs
; 224 save_flags(flags
);cli(); 226 qregs
->hcctrl
= HCCTRL_PAUSE
; 228 /* Only reset the scsi bus if it is not free. */ 229 if(qregs
->cpu_pctrl
& CPU_PCTRL_BSY
) { 230 qregs
->cpu_oride
= CPU_ORIDE_RMOD
; 231 qregs
->cpu_cmd
= CPU_CMD_BRESET
; 235 qregs
->sbus_ctrl
= SBUS_CTRL_RESET
; 236 qregs
->cmd_dma_ctrl
= (DMA_CTRL_CCLEAR
| DMA_CTRL_CIRQ
); 237 qregs
->data_dma_ctrl
= (DMA_CTRL_CCLEAR
| DMA_CTRL_CIRQ
); 239 loop_count
= DEFAULT_LOOP_COUNT
; 240 while(--loop_count
&& ((qregs
->mbox0
&0xff) ==0x04)) 243 printk(KERN_EMERG
"qlogicpti: reset_hardware loop timeout\n"); 245 qregs
->hcctrl
= HCCTRL_PAUSE
; 246 set_sbus_cfg1(qregs
, qpti
->bursts
); 247 qlogicpti_enable_irqs(qregs
); 249 if(qregs
->risc_psr
& RISC_PSR_ULTRA
) { 251 qregs
->risc_mtreg
= (RISC_MTREG_P0ULTRA
| RISC_MTREG_P1ULTRA
); 254 qregs
->risc_mtreg
= (RISC_MTREG_P0DFLT
| RISC_MTREG_P1DFLT
); 257 /* Release the RISC processor. */ 258 qregs
->hcctrl
= HCCTRL_REL
; 260 /* Get RISC to start executing the firmware code. */ 261 param
[0] = MBOX_EXEC_FIRMWARE
; 262 param
[1] = risc_code_addr01
; 263 if(qlogicpti_mbox_command(qpti
, param
,1)) { 264 printk(KERN_EMERG
"qlogicpti%d: Cannot execute ISP firmware.\n", 266 restore_flags(flags
); 270 /* Set initiator scsi ID. */ 271 param
[0] = MBOX_SET_INIT_SCSI_ID
; 272 param
[1] = qpti
->host_param
.initiator_scsi_id
; 273 if(qlogicpti_mbox_command(qpti
, param
,1) || 274 (param
[0] != MBOX_COMMAND_COMPLETE
)) { 275 printk(KERN_EMERG
"qlogicpti%d: Cannot set initiator SCSI ID.\n", 277 restore_flags(flags
); 281 /* Initialize state of the queues, both hw and sw. */ 282 qpti
->req_in_ptr
= qpti
->res_out_ptr
=0; 284 param
[0] = MBOX_INIT_RES_QUEUE
; 285 param
[1] = RES_QUEUE_LEN
+1; 286 param
[2] = (u_short
) (qpti
->res_dvma
>>16); 287 param
[3] = (u_short
) (qpti
->res_dvma
&0xffff); 288 param
[4] = param
[5] =0; 289 if(qlogicpti_mbox_command(qpti
, param
,1)) { 290 printk(KERN_EMERG
"qlogicpti%d: Cannot init response queue.\n", 292 restore_flags(flags
); 296 param
[0] = MBOX_INIT_REQ_QUEUE
; 297 param
[1] = QLOGICISP_REQ_QUEUE_LEN
+1; 298 param
[2] = (u_short
) (qpti
->req_dvma
>>16); 299 param
[3] = (u_short
) (qpti
->req_dvma
&0xffff); 300 param
[4] = param
[5] =0; 301 if(qlogicpti_mbox_command(qpti
, param
,1)) { 302 printk(KERN_EMERG
"qlogicpti%d: Cannot init request queue.\n", 304 restore_flags(flags
); 308 param
[0] = MBOX_SET_RETRY_COUNT
; 309 param
[1] = qpti
->host_param
.retry_count
; 310 param
[2] = qpti
->host_param
.retry_delay
; 311 qlogicpti_mbox_command(qpti
, param
,0); 313 param
[0] = MBOX_SET_TAG_AGE_LIMIT
; 314 param
[1] = qpti
->host_param
.tag_aging
; 315 qlogicpti_mbox_command(qpti
, param
,0); 317 for(i
=0; i
< MAX_TARGETS
; i
++) { 318 param
[0] = MBOX_GET_DEV_QUEUE_PARAMS
; 320 qlogicpti_mbox_command(qpti
, param
,0); 323 param
[0] = MBOX_GET_FIRMWARE_STATUS
; 324 qlogicpti_mbox_command(qpti
, param
,0); 326 param
[0] = MBOX_SET_SELECT_TIMEOUT
; 327 param
[1] = qpti
->host_param
.selection_timeout
; 328 qlogicpti_mbox_command(qpti
, param
,0); 330 for(i
=0; i
< MAX_TARGETS
; i
++) { 331 param
[0] = MBOX_SET_TARGET_PARAMS
; 333 param
[2] = (qpti
->dev_param
[i
].device_flags
<<8); 334 param
[3] = (qpti
->dev_param
[i
].synchronous_offset
<<8) | 335 qpti
->dev_param
[i
].synchronous_period
; 336 qlogicpti_mbox_command(qpti
, param
,0); 339 restore_flags(flags
); 343 #define PTI_RESET_LIMIT 400 345 static intqlogicpti_load_firmware(struct qlogicpti
*qpti
) 347 struct qlogicpti_regs
*qregs
= qpti
->qregs
; 348 unsigned short csum
=0; 349 unsigned short param
[6]; 352 unsigned long dvma_addr
; 356 save_flags(flags
);cli(); 358 /* Verify the checksum twice, one before loading it, and once 359 * afterwards via the mailbox commands. 361 for(i
=0; i
< risc_code_length01
; i
++) 362 csum
+= risc_code01
[i
]; 364 printk(KERN_EMERG
"qlogicpti%d: AIeee, firmware checksum failed!", 368 qregs
->sbus_ctrl
= SBUS_CTRL_RESET
; 369 qregs
->cmd_dma_ctrl
= (DMA_CTRL_CCLEAR
| DMA_CTRL_CIRQ
); 370 qregs
->data_dma_ctrl
= (DMA_CTRL_CCLEAR
| DMA_CTRL_CIRQ
); 371 timeout
= PTI_RESET_LIMIT
; 372 while(--timeout
&& (qregs
->sbus_ctrl
& SBUS_CTRL_RESET
)) 375 printk(KERN_EMERG
"qlogicpti%d: Cannot reset the ISP.", qpti
->qpti_id
); 379 qregs
->hcctrl
= HCCTRL_RESET
; 382 qregs
->sbus_ctrl
= (SBUS_CTRL_GENAB
| SBUS_CTRL_ERIRQ
); 383 set_sbus_cfg1(qregs
, qpti
->bursts
); 384 qregs
->sbus_semaphore
=0; 386 if(qregs
->risc_psr
& RISC_PSR_ULTRA
) { 388 qregs
->risc_mtreg
= (RISC_MTREG_P0ULTRA
| RISC_MTREG_P1ULTRA
); 391 qregs
->risc_mtreg
= (RISC_MTREG_P0DFLT
| RISC_MTREG_P1DFLT
); 394 qregs
->hcctrl
= HCCTRL_REL
; 396 /* Pin lines are only stable while RISC is paused. */ 397 qregs
->hcctrl
= HCCTRL_PAUSE
; 398 if(qregs
->cpu_pdiff
& CPU_PDIFF_MODE
) 399 qpti
->differential
=1; 401 qpti
->differential
=0; 402 qregs
->hcctrl
= HCCTRL_REL
; 404 /* XXX Talk to PTI engineer about the following, ISP always 405 * XXX returns 0x4001 return status for stop firmware command, 406 * XXX documentation claims this means the cmd is unsupported 407 * XXX on this ISP. I think something fishy is going on. 409 param
[0] = MBOX_STOP_FIRMWARE
; 410 param
[1] = param
[2] = param
[3] = param
[4] = param
[5] =0; 411 if(qlogicpti_mbox_command(qpti
, param
,1)) { 412 printk(KERN_EMERG
"qlogicpti%d: Cannot stop firmware for reload.\n", 414 restore_flags(flags
); 418 /* Load the firmware. */ 420 /* XXX THIS SHIT DOES NOT WORK ON ULTRA... FIXME -DaveM */ 421 dvma_addr
= (unsigned long)mmu_lockarea((char*)&risc_code01
[0], 422 (sizeof(u_short
) * risc_code_length01
)); 423 param
[0] = MBOX_LOAD_RAM
; 424 param
[1] = risc_code_addr01
; 425 param
[2] = (dvma_addr
>>16); 426 param
[3] = (dvma_addr
&0xffff); 427 param
[4] = (sizeof(u_short
) * risc_code_length01
); 428 if(qlogicpti_mbox_command(qpti
, param
,1) || 429 (param
[0] != MBOX_COMMAND_COMPLETE
)) { 430 printk(KERN_EMERG
"qlogicpti%d: Firmware dload failed, I'm bolixed!\n", 432 restore_flags(flags
); 435 /* XXX THIS SHIT DOES NOT WORK ON ULTRA... FIXME -DaveM */ 436 mmu_unlockarea((char*)dvma_addr
, (sizeof(u_short
) * risc_code_length01
)); 438 for(i
=0; i
< risc_code_length01
; i
++) { 439 param
[0] = MBOX_WRITE_RAM_WORD
; 440 param
[1] = risc_code_addr01
+ i
; 441 param
[2] = risc_code01
[i
]; 442 if(qlogicpti_mbox_command(qpti
, param
,1) || 443 param
[0] != MBOX_COMMAND_COMPLETE
) { 444 printk("qlogicpti%d: Firmware dload failed, I'm bolixed!\n", 446 restore_flags(flags
); 452 /* Reset the ISP again. */ 453 qregs
->hcctrl
= HCCTRL_RESET
; 456 qlogicpti_enable_irqs(qregs
); 457 qregs
->sbus_semaphore
=0; 458 qregs
->hcctrl
= HCCTRL_REL
; 460 /* Ask ISP to verify the checksum of the new code. */ 461 param
[0] = MBOX_VERIFY_CHECKSUM
; 462 param
[1] = risc_code_addr01
; 463 if(qlogicpti_mbox_command(qpti
, param
,1) || 464 (param
[0] != MBOX_COMMAND_COMPLETE
)) { 465 printk(KERN_EMERG
"qlogicpti%d: New firmware csum failure!\n", 467 restore_flags(flags
); 471 /* Start using newly downloaded firmware. */ 472 param
[0] = MBOX_EXEC_FIRMWARE
; 473 param
[1] = risc_code_addr01
; 474 qlogicpti_mbox_command(qpti
, param
,1); 476 param
[0] = MBOX_ABOUT_FIRMWARE
; 477 if(qlogicpti_mbox_command(qpti
, param
,1) || 478 (param
[0] != MBOX_COMMAND_COMPLETE
)) { 479 printk(KERN_EMERG
"qlogicpti%d: AboutFirmware cmd fails.\n", 481 restore_flags(flags
); 485 /* Snag the major and minor revisions from the result. */ 486 qpti
->fware_majrev
= param
[1]; 487 qpti
->fware_minrev
= param
[2]; 489 /* Load scsi initiator ID and interrupt level into sbus static ram. */ 490 param
[0] = MBOX_WRITE_RAM_WORD
; 492 param
[2] = (unsigned short) qpti
->scsi_id
; 493 qlogicpti_mbox_command(qpti
, param
,1); 495 param
[0] = MBOX_WRITE_RAM_WORD
; 497 param
[2] = (unsigned short)3; 498 qlogicpti_mbox_command(qpti
, param
,1); 500 restore_flags(flags
); 504 static intqlogicpti_verify_tmon(struct qlogicpti
*qpti
) 506 int curstat
= *qpti
->sreg
; 509 if(!(curstat
& SREG_FUSE
) && (qpti
->swsreg
& SREG_FUSE
)) 510 printk("qlogicpti%d: Fuse returned to normal state.\n", qpti
->qpti_id
); 511 if(!(curstat
& SREG_TPOWER
) && (qpti
->swsreg
& SREG_TPOWER
)) 512 printk("qlogicpti%d: termpwr back to normal state.\n", qpti
->qpti_id
); 513 if(curstat
!= qpti
->swsreg
) { 515 if(curstat
& SREG_FUSE
) { 517 printk("qlogicpti%d: Fuse is open!\n", qpti
->qpti_id
); 519 if(curstat
& SREG_TPOWER
) { 521 printk("qlogicpti%d: termpwr failure\n", qpti
->qpti_id
); 523 if(qpti
->differential
&& 524 (curstat
& SREG_DSENSE
) != SREG_DSENSE
) { 526 printk("qlogicpti%d: You have a single ended device on a " 527 "differential bus! Please fix!\n", qpti
->qpti_id
); 529 qpti
->swsreg
= curstat
; 535 staticinlinevoidqlogicpti_set_hostdev_defaults(struct qlogicpti
*qpti
) 539 qpti
->host_param
.initiator_scsi_id
= qpti
->scsi_id
; 540 qpti
->host_param
.bus_reset_delay
=3; 541 qpti
->host_param
.retry_count
=0; 542 qpti
->host_param
.retry_delay
=5; 543 qpti
->host_param
.async_data_setup_time
=3; 544 qpti
->host_param
.req_ack_active_negation
=1; 545 qpti
->host_param
.data_line_active_negation
=1; 546 qpti
->host_param
.data_dma_burst_enable
=1; 547 qpti
->host_param
.command_dma_burst_enable
=1; 548 qpti
->host_param
.tag_aging
=8; 549 qpti
->host_param
.selection_timeout
=250; 550 qpti
->host_param
.max_queue_depth
=256; 552 for(i
=0; i
< MAX_TARGETS
; i
++) { 553 qpti
->dev_param
[i
].device_flags
=0xf9; 554 qpti
->dev_param
[i
].execution_throttle
=16; 555 qpti
->dev_param
[i
].synchronous_period
=16; 556 qpti
->dev_param
[i
].synchronous_offset
=12; 557 qpti
->dev_param
[i
].device_enable
=1; 561 static voidqlogicpti_intr_handler(int irq
,void*dev_id
,struct pt_regs
*regs
); 563 /* Detect all PTI Qlogic ISP's in the machine. */ 564 intqlogicpti_detect(Scsi_Host_Template
*tpnt
) 566 struct qlogicpti
*qpti
, *qlink
; 567 struct Scsi_Host
*qpti_host
; 568 struct linux_sbus
*sbus
; 569 struct linux_sbus_device
*qpti_dev
, *sbdev_iter
; 570 struct qlogicpti_regs
*qregs
; 571 volatileunsigned char*sreg
; 572 unsigned char bsizes
, bsizes_more
; 573 int nqptis
=0, nqptis_in_use
=0; 576 tpnt
->proc_dir
= &proc_scsi_qlogicpti
; 579 panic("No SBUS in qlogicpti_detect()"); 580 for_each_sbus(sbus
) { 581 for_each_sbusdev(sbdev_iter
, sbus
) { 582 qpti_dev
= sbdev_iter
; 584 /* Is this a red snapper? */ 585 if(strcmp(qpti_dev
->prom_name
,"ptisp") && 586 strcmp(qpti_dev
->prom_name
,"PTI,ptisp")) 589 /* Yep, register and allocate software state. */ 590 qpti_host
=scsi_register(tpnt
,sizeof(struct qlogicpti
)); 592 panic("Cannot register PTI Qlogic ISP SCSI host"); 593 qpti
= (struct qlogicpti
*) qpti_host
->hostdata
; 595 panic("No qpti in hostdata"); 597 /* We are wide capable, 16 targets. */ 598 qpti_host
->max_id
= MAX_TARGETS
; 600 /* Setup back pointers and misc. state. */ 601 qpti
->qhost
= qpti_host
; 602 qpti
->qdev
= qpti_dev
; 603 qpti
->qpti_id
= nqptis
++; 605 /* Insert this one into the global interrupt service chain. */ 608 while(qlink
->next
) qlink
= qlink
->next
; 615 /* More misc. prom information. */ 616 qpti_node
= qpti_dev
->prom_node
; 617 prom_getstring(qpti_node
,"name", qpti
->prom_name
, 618 sizeof(qpti
->prom_name
)); 619 qpti
->prom_node
= qpti_node
; 621 /* Setup the reg property for this device. */ 622 prom_apply_sbus_ranges(qpti
->qdev
->my_bus
, 623 qpti
->qdev
->reg_addrs
, 626 /* Map in Qlogic,ISP regs and the PTI status reg. */ 627 qpti
->qregs
= qregs
= (struct qlogicpti_regs
*) 628 sparc_alloc_io(qpti
->qdev
->reg_addrs
[0].phys_addr
,0, 629 qpti
->qdev
->reg_addrs
[0].reg_size
, 630 "PTI Qlogic/ISP Registers", 631 qpti
->qdev
->reg_addrs
[0].which_io
,0x0); 633 panic("PTI Qlogic/ISP registers unmappable"); 635 /* Map this one read only. */ 636 qpti
->sreg
= sreg
= (volatileunsigned char*) 637 sparc_alloc_io((qpti
->qdev
->reg_addrs
[0].phys_addr
+ 639 sizeof(unsigned char), 640 "PTI Qlogic/ISP Status Reg", 641 qpti
->qdev
->reg_addrs
[0].which_io
,1); 643 panic("PTI Qlogic/ISP status reg unmappable"); 646 qpti_host
->base
= (unsigned char*)qregs
; 647 qpti_host
->io_port
= (unsigned int) qregs
; 648 qpti_host
->n_io_port
= (unsigned char) 649 qpti
->qdev
->reg_addrs
[0].reg_size
; 651 qpti_host
->irq
= qpti
->irq
= qpti
->qdev
->irqs
[0].pri
; 653 /* Allocate the irq only if necessary. */ 654 for_each_qlogicpti(qlink
) { 655 if((qlink
!= qpti
) && (qpti
->irq
== qlink
->irq
)) { 656 goto qpti_irq_acquired
;/* BASIC rulez */ 659 if(request_irq(qpti
->qhost
->irq
, qlogicpti_intr_handler
, 660 SA_SHIRQ
,"PTI Qlogic/ISP SCSI", NULL
)) { 661 printk("Cannot acquire PTI Qlogic/ISP irq line\n"); 662 /* XXX Unmap regs, unregister scsi host, free things. */ 666 printk("qpti%d: IRQ %d ", qpti
->qpti_id
, qpti
->qhost
->irq
); 668 /* Figure out our scsi ID on the bus */ 669 qpti
->scsi_id
=prom_getintdefault(qpti
->prom_node
, 672 if(qpti
->scsi_id
== -1) 673 qpti
->scsi_id
=prom_getintdefault(qpti
->prom_node
, 676 if(qpti
->scsi_id
== -1) 678 prom_getintdefault(qpti
->qdev
->my_bus
->prom_node
, 679 "scsi-initiator-id",7); 680 qpti
->qhost
->this_id
= qpti
->scsi_id
; 681 printk("SCSI ID %d ", qpti
->scsi_id
); 683 /* Check for what the best SBUS burst we can use happens 684 * to be on this machine. 686 bsizes
=prom_getintdefault(qpti
->prom_node
,"burst-sizes",0xff); 688 bsizes_more
=prom_getintdefault(qpti
->qdev
->my_bus
->prom_node
, 690 if(bsizes_more
!=0xff) 691 bsizes
&= bsizes_more
; 692 if(bsizes
==0xff|| (bsizes
& DMA_BURST16
)==0|| 693 (bsizes
& DMA_BURST32
) ==0) 694 bsizes
= (DMA_BURST32
-1); 695 qpti
->bursts
= bsizes
; 697 /* The request and response queues must each be aligned 701 #define QSIZE(entries) (((entries) + 1) * QUEUE_ENTRY_LEN) 703 qpti
->res_cpu
=sparc_dvma_malloc(QSIZE(RES_QUEUE_LEN
), 704 "PTISP Response Queue", 706 qpti
->req_cpu
=sparc_dvma_malloc(QSIZE(QLOGICISP_REQ_QUEUE_LEN
), 707 "PTISP Request Queue", 713 /* Set adapter and per-device default values. */ 714 qlogicpti_set_hostdev_defaults(qpti
); 716 /* Load the firmware. */ 717 if(qlogicpti_load_firmware(qpti
)) 718 panic("PTI Qlogic/ISP firmware load failed"); 720 /* Check the PTI status reg. */ 721 if(qlogicpti_verify_tmon(qpti
)) 722 panic("PTI Qlogic/ISP tmon verification failed"); 724 /* Reset the ISP and init res/req queues. */ 725 if(qlogicpti_reset_hardware(qpti_host
)) 726 panic("PTI Qlogic/ISP cannot be reset"); 728 printk("(Firmware v%d.%d) [%s Wide, using %s interface]\n", 729 qpti
->fware_majrev
, qpti
->fware_minrev
, 730 (qpti
->ultra
?"Ultra":"Fast"), 731 (qpti
->differential
?"differential":"single ended")); 736 printk("QPTI: Total of %d PTI Qlogic/ISP hosts found, %d actually in use.\n", 737 nqptis
, nqptis_in_use
); 738 qptis_running
= nqptis_in_use
; 742 intqlogicpti_release(struct Scsi_Host
*host
) 744 struct qlogicpti
*qpti
= (struct qlogicpti
*) host
->hostdata
; 745 struct qlogicpti_regs
*qregs
= qpti
->qregs
; 747 /* Shut up the card. */ 750 /* Free IRQ handler and unmap Qlogic,ISP and PTI status regs. */ 751 free_irq(host
->irq
, NULL
); 752 unmapioaddr((unsigned long)qregs
); 753 unmapioaddr((unsigned long)qpti
->sreg
); 758 const char*qlogicpti_info(struct Scsi_Host
*host
) 761 struct qlogicpti
*qpti
= (struct qlogicpti
*) host
->hostdata
; 763 sprintf(buf
,"PTI Qlogic,ISP SBUS SCSI irq %d regs at %08lx", 764 host
->irq
, (unsigned long) qpti
->qregs
); 768 /* I am a certified frobtronicist. */ 769 staticinlinevoidmarker_frob(struct Command_Entry
*cmd
) 771 struct Marker_Entry
*marker
= (struct Marker_Entry
*) cmd
; 773 memset(marker
,0,sizeof(struct Marker_Entry
)); 774 marker
->hdr
.entry_cnt
=1; 775 marker
->hdr
.entry_type
= ENTRY_MARKER
; 776 marker
->modifier
= SYNC_ALL
; 780 staticinlinevoidcmd_frob(struct Command_Entry
*cmd
, Scsi_Cmnd
*Cmnd
, 781 struct qlogicpti
*qpti
) 783 memset(cmd
,0,sizeof(struct Command_Entry
)); 784 cmd
->hdr
.entry_cnt
=1; 785 cmd
->hdr
.entry_type
= ENTRY_COMMAND
; 786 cmd
->handle
= (u_int
) Cmnd
;/* magic mushroom */ 787 cmd
->target_id
= Cmnd
->target
; 788 cmd
->target_lun
= Cmnd
->lun
; 789 cmd
->cdb_length
= Cmnd
->cmd_len
; 790 cmd
->control_flags
=0; 791 if(Cmnd
->device
->tagged_supported
) { 792 if(qpti
->cmd_count
[Cmnd
->target
] ==0) 793 qpti
->tag_ages
[Cmnd
->target
] = jiffies
; 794 if((jiffies
- qpti
->tag_ages
[Cmnd
->target
]) > (5*HZ
)) { 795 cmd
->control_flags
= CFLAG_ORDERED_TAG
; 796 qpti
->tag_ages
[Cmnd
->target
] = jiffies
; 798 cmd
->control_flags
= CFLAG_SIMPLE_TAG
; 800 if((Cmnd
->cmnd
[0] == WRITE_6
) || 801 (Cmnd
->cmnd
[0] == WRITE_10
) || 802 (Cmnd
->cmnd
[0] == WRITE_12
)) 803 cmd
->control_flags
|= CFLAG_WRITE
; 805 cmd
->control_flags
|= CFLAG_READ
; 807 memcpy(cmd
->cdb
, Cmnd
->cmnd
, Cmnd
->cmd_len
); 810 /* Do it to it baby. */ 811 staticinline u_int
load_cmd(Scsi_Cmnd
*Cmnd
,struct Command_Entry
*cmd
, 812 struct qlogicpti
*qpti
,struct qlogicpti_regs
*qregs
, 813 u_int in_ptr
, u_int out_ptr
) 816 struct scatterlist
*sg
; 817 int sg_count
= Cmnd
->use_sg
; 821 mmu_get_scsi_sgl((struct mmu_sglist
*)Cmnd
->buffer
, (Cmnd
->use_sg
-1), 824 cmd
->segment_cnt
= sg_count
; 825 sg
= (struct scatterlist
*) Cmnd
->request_buffer
; 828 /* Fill in first four sg entries: */ 832 for(i
=0; i
< n
; i
++, sg
++) { 833 ds
[i
].d_base
= (u_int
) sg
->dvma_address
; 834 ds
[i
].d_count
= (u_int
) sg
->length
; 838 struct Continuation_Entry
*cont
; 840 ++cmd
->hdr
.entry_cnt
; 841 cont
= (struct Continuation_Entry
*) &qpti
->req_cpu
[in_ptr
]; 842 in_ptr
=NEXT_REQ_PTR(in_ptr
); 843 if(in_ptr
== out_ptr
) { 844 printk(KERN_EMERG
"qlogicpti: Unexpected request queue overflow\n"); 847 cont
->hdr
.entry_type
= ENTRY_CONTINUATION
; 848 cont
->hdr
.entry_cnt
=0; 849 cont
->hdr
.sys_def_1
=0; 856 for(i
=0; i
< n
; i
++, sg
++) { 857 ds
[i
].d_base
= (u_int
) sg
->dvma_address
; 858 ds
[i
].d_count
= (u_int
) sg
->length
; 863 /* XXX Casts are extremely gross, but with 64-bit cpu addresses 864 * XXX and 32-bit SBUS DVMA addresses what am I to do? -DaveM 866 Cmnd
->SCp
.ptr
= (char*)((unsigned long) 867 mmu_get_scsi_one((char*)Cmnd
->request_buffer
, 868 Cmnd
->request_bufflen
, 869 qpti
->qdev
->my_bus
)); 871 cmd
->dataseg
[0].d_base
= (u_int
) Cmnd
->SCp
.ptr
; 872 cmd
->dataseg
[0].d_count
= Cmnd
->request_bufflen
; 875 qpti
->cmd_count
[Cmnd
->target
]++; 876 qregs
->mbox4
= in_ptr
; 877 qpti
->req_in_ptr
= in_ptr
; 881 staticinlinevoidupdate_can_queue(struct Scsi_Host
*host
, u_int in_ptr
, u_int out_ptr
) 883 int num_free
= QLOGICISP_REQ_QUEUE_LEN
-REQ_QUEUE_DEPTH(in_ptr
, out_ptr
); 884 host
->can_queue
= host
->host_busy
+ num_free
; 885 host
->sg_tablesize
=QLOGICISP_MAX_SG(num_free
); 889 * The middle SCSI layer ensures that queuecommand never gets invoked 890 * concurrently with itself or the interrupt handler (though the 891 * interrupt handler may call this routine as part of 892 * request-completion handling). 894 * "This code must fly." -davem 896 intqlogicpti_queuecommand(Scsi_Cmnd
*Cmnd
,void(*done
)(Scsi_Cmnd
*)) 898 struct Scsi_Host
*host
= Cmnd
->host
; 899 struct qlogicpti
*qpti
= (struct qlogicpti
*) host
->hostdata
; 900 struct qlogicpti_regs
*qregs
= qpti
->qregs
; 901 u_int in_ptr
= qpti
->req_in_ptr
; 902 u_int out_ptr
= qregs
->mbox4
; 903 struct Command_Entry
*cmd
= (struct Command_Entry
*) &qpti
->req_cpu
[in_ptr
]; 905 Cmnd
->scsi_done
= done
; 906 in_ptr
=NEXT_REQ_PTR(in_ptr
); 907 if(in_ptr
== out_ptr
) { 908 printk(KERN_EMERG
"qlogicpti%d: request queue overflow\n", qpti
->qpti_id
); 911 if(qpti
->send_marker
) { 913 qpti
->send_marker
=0; 914 if(NEXT_REQ_PTR(in_ptr
) == out_ptr
) { 915 qregs
->mbox4
= in_ptr
; 916 qpti
->req_in_ptr
= in_ptr
; 917 printk(KERN_EMERG
"qlogicpti%d: request queue overflow\n", qpti
->qpti_id
); 920 cmd
= (struct Command_Entry
*) &qpti
->req_cpu
[in_ptr
]; 921 in_ptr
=NEXT_REQ_PTR(in_ptr
); 923 cmd_frob(cmd
, Cmnd
, qpti
); 924 if((in_ptr
=load_cmd(Cmnd
, cmd
, qpti
, qregs
, in_ptr
, out_ptr
)) == -1) 926 update_can_queue(host
, in_ptr
, out_ptr
); 930 static intqlogicpti_return_status(struct Status_Entry
*sts
) 932 int host_status
= DID_ERROR
; 934 switch(sts
->completion_status
) { 936 host_status
= DID_OK
; 939 if(!(sts
->state_flags
& SF_GOT_BUS
)) 940 host_status
= DID_NO_CONNECT
; 941 else if(!(sts
->state_flags
& SF_GOT_TARGET
)) 942 host_status
= DID_BAD_TARGET
; 943 else if(!(sts
->state_flags
& SF_SENT_CDB
)) 944 host_status
= DID_ERROR
; 945 else if(!(sts
->state_flags
& SF_TRANSFERRED_DATA
)) 946 host_status
= DID_ERROR
; 947 else if(!(sts
->state_flags
& SF_GOT_STATUS
)) 948 host_status
= DID_ERROR
; 949 else if(!(sts
->state_flags
& SF_GOT_SENSE
)) 950 host_status
= DID_ERROR
; 953 case CS_TRANSPORT_ERROR
: 954 host_status
= DID_ERROR
; 956 case CS_RESET_OCCURRED
: 957 host_status
= DID_RESET
; 960 host_status
= DID_ABORT
; 963 host_status
= DID_TIME_OUT
; 965 case CS_DATA_OVERRUN
: 966 case CS_COMMAND_OVERRUN
: 967 case CS_STATUS_OVERRUN
: 969 case CS_NO_MESSAGE_OUT
: 970 case CS_EXT_ID_FAILED
: 971 case CS_IDE_MSG_FAILED
: 972 case CS_ABORT_MSG_FAILED
: 973 case CS_NOP_MSG_FAILED
: 974 case CS_PARITY_ERROR_MSG_FAILED
: 975 case CS_DEVICE_RESET_MSG_FAILED
: 976 case CS_ID_MSG_FAILED
: 977 case CS_UNEXP_BUS_FREE
: 978 host_status
= DID_ERROR
; 980 case CS_DATA_UNDERRUN
: 981 host_status
= DID_OK
; 984 printk(KERN_EMERG
"qlogicpti : unknown completion status 0x%04x\n", 985 sts
->completion_status
); 986 host_status
= DID_ERROR
; 990 return(sts
->scsi_status
& STATUS_MASK
) | (host_status
<<16); 993 static voidqlogicpti_intr_handler(int irq
,void*dev_id
,struct pt_regs
*regs
) 995 static int running
=0; 997 struct Status_Entry
*sts
; 998 struct qlogicpti
*qpti
; 999 u_int in_ptr
, out_ptr
; 1002 /* It is ok to take irq's on one qpti while the other 1003 * is amidst the processing of a reset. 1007 #if 0/* XXX Investigate why resets cause this with one controller. */ 1008 if(running
> qptis_running
) 1009 printk("qlogicpti_intr_handler: yieee, recursive interrupt!\n"); 1012 /* Handle all ISP interrupts showing */ 1015 for_each_qlogicpti(qpti
) { 1016 if(qpti
->qregs
->sbus_stat
& SBUS_STAT_RINT
) { 1017 struct qlogicpti_regs
*qregs
= qpti
->qregs
; 1020 in_ptr
= qregs
->mbox5
; 1021 qregs
->hcctrl
= HCCTRL_CRIRQ
; 1022 if(qregs
->sbus_semaphore
& SBUS_SEMAPHORE_LCK
) { 1023 switch(qregs
->mbox0
) { 1024 case ASYNC_SCSI_BUS_RESET
: 1025 case EXECUTION_TIMEOUT_RESET
: 1026 qpti
->send_marker
=1; 1028 case INVALID_COMMAND
: 1029 case HOST_INTERFACE_ERROR
: 1031 case COMMAND_PARAM_ERROR
: 1034 qregs
->sbus_semaphore
=0; 1037 /* This looks like a network driver! */ 1038 out_ptr
= qpti
->res_out_ptr
; 1039 while(out_ptr
!= in_ptr
) { 1040 sts
= (struct Status_Entry
*) &qpti
->res_cpu
[out_ptr
]; 1041 out_ptr
=NEXT_RES_PTR(out_ptr
); 1042 Cmnd
= (Scsi_Cmnd
*) sts
->handle
;/* but_to_virt?!?! */ 1043 if(sts
->completion_status
== CS_RESET_OCCURRED
|| 1044 sts
->completion_status
== CS_ABORTED
|| 1045 (sts
->status_flags
& STF_BUS_RESET
)) 1046 qpti
->send_marker
=1; 1048 if(sts
->state_flags
& SF_GOT_SENSE
) 1049 memcpy(Cmnd
->sense_buffer
, sts
->req_sense_data
, 1050 sizeof(Cmnd
->sense_buffer
)); 1052 if(sts
->hdr
.entry_type
== ENTRY_STATUS
) 1053 Cmnd
->result
=qlogicpti_return_status(sts
); 1055 Cmnd
->result
= DID_ERROR
<<16; 1058 mmu_release_scsi_sgl((struct mmu_sglist
*) 1061 qpti
->qdev
->my_bus
); 1063 mmu_release_scsi_one((__u32
)Cmnd
->SCp
.ptr
, 1064 Cmnd
->request_bufflen
, 1065 qpti
->qdev
->my_bus
); 1067 qpti
->cmd_count
[Cmnd
->target
]--; 1068 qregs
->mbox5
= out_ptr
; 1069 Cmnd
->scsi_done(Cmnd
); 1071 qpti
->res_out_ptr
= out_ptr
; 1079 intqlogicpti_abort(Scsi_Cmnd
*Cmnd
) 1082 struct Scsi_Host
*host
= Cmnd
->host
; 1083 struct qlogicpti
*qpti
= (struct qlogicpti
*) host
->hostdata
; 1084 int return_status
= SCSI_ABORT_SUCCESS
; 1086 printk(KERN_EMERG
"qlogicpti : Aborting cmd for tgt[%d] lun[%d]\n", 1087 (int)Cmnd
->target
, (int)Cmnd
->lun
); 1088 qlogicpti_disable_irqs(qpti
->qregs
); 1089 param
[0] = MBOX_ABORT
; 1090 param
[1] = (((u_short
) Cmnd
->target
) <<8) | Cmnd
->lun
; 1091 param
[2] = ((unsigned int)Cmnd
) >>16; 1092 param
[3] = ((unsigned int)Cmnd
) &0xffff; 1093 if(qlogicpti_mbox_command(qpti
, param
,0) || 1094 (param
[0] != MBOX_COMMAND_COMPLETE
)) { 1095 printk(KERN_EMERG
"qlogicpti : scsi abort failure: %x\n", param
[0]); 1096 return_status
= SCSI_ABORT_ERROR
; 1098 qlogicpti_enable_irqs(qpti
->qregs
); 1099 return return_status
; 1102 intqlogicpti_reset(Scsi_Cmnd
*Cmnd
,unsigned int reset_flags
) 1105 struct Scsi_Host
*host
= Cmnd
->host
; 1106 struct qlogicpti
*qpti
= (struct qlogicpti
*) host
->hostdata
; 1107 int return_status
= SCSI_RESET_SUCCESS
; 1109 printk(KERN_EMERG
"qlogicpti : Resetting SCSI bus!\n"); 1110 qlogicpti_disable_irqs(qpti
->qregs
); 1111 param
[0] = MBOX_BUS_RESET
; 1112 param
[1] = qpti
->host_param
.bus_reset_delay
; 1113 if(qlogicpti_mbox_command(qpti
, param
,0) || 1114 (param
[0] != MBOX_COMMAND_COMPLETE
)) { 1115 printk(KERN_EMERG
"qlogicisp : scsi bus reset failure: %x\n", param
[0]); 1116 return_status
= SCSI_RESET_ERROR
; 1118 qlogicpti_enable_irqs(qpti
->qregs
); 1119 return return_status
; 1123 Scsi_Host_Template driver_template
= QLOGICPTI
; 1125 #include"scsi_module.c"