1 /* imm.c -- low level driver for the IOMEGA MatchMaker 2 * parallel port SCSI host adapter. 4 * (The IMM is the embedded controller in the ZIP Plus drive.) 6 * Current Maintainer: David Campbell (Perth, Western Australia) 9 * My unoffical company acronym list is 21 pages long: 10 * FLA: Four letter acronym with built in facility for 11 * future expansion to five letters. 14 #include <linux/config.h> 16 /* The following #define is to avoid a clash with hosts.c */ 18 #define IMM_PROBE_SPP 0x0001 19 #define IMM_PROBE_PS2 0x0002 20 #define IMM_PROBE_ECR 0x0010 21 #define IMM_PROBE_EPP17 0x0100 22 #define IMM_PROBE_EPP19 0x0200 24 voidimm_reset_pulse(unsigned int base
); 25 static intdevice_check(int host_no
); 27 #include <linux/blk.h> 29 #include <linux/parport.h> 33 struct pardevice
*dev
;/* Parport device entry */ 34 int base
;/* Actual port address */ 35 int mode
;/* Transfer mode */ 36 int host
;/* Host number (for proc) */ 37 Scsi_Cmnd
*cur_cmd
;/* Current queued command */ 38 struct tq_struct imm_tq
;/* Polling interupt stuff */ 39 unsigned long jstart
;/* Jiffies at start */ 40 unsigned failed
:1;/* Failure flag */ 41 unsigned dp
:1;/* Data phase present */ 42 unsigned rd
:1;/* Read data in data phase */ 43 unsigned p_busy
:1;/* Parport sharing busy flag */ 49 mode: IMM_AUTODETECT, \ 52 imm_tq: {0, 0, imm_interrupt, NULL}, \ 62 static imm_struct imm_hosts
[NO_HOSTS
] = 63 {IMM_EMPTY
, IMM_EMPTY
, IMM_EMPTY
, IMM_EMPTY
}; 65 #define IMM_BASE(x) imm_hosts[(x)].base 67 int parbus_base
[NO_HOSTS
] = 68 {0x03bc,0x0378,0x0278,0x0000}; 70 voidimm_wakeup(void*ref
) 72 imm_struct
*imm_dev
= (imm_struct
*) ref
; 77 if(parport_claim(imm_dev
->dev
)) { 78 printk("imm: bug in imm_wakeup\n"); 82 imm_dev
->base
= imm_dev
->dev
->port
->base
; 84 imm_dev
->cur_cmd
->SCp
.phase
++; 88 intimm_release(struct Scsi_Host
*host
) 90 int host_no
= host
->unique_id
; 92 printk("Releasing imm%i\n", host_no
); 93 parport_unregister_device(imm_hosts
[host_no
].dev
); 97 static intimm_pb_claim(int host_no
) 99 if(parport_claim(imm_hosts
[host_no
].dev
)) { 100 imm_hosts
[host_no
].p_busy
=1; 103 if(imm_hosts
[host_no
].cur_cmd
) 104 imm_hosts
[host_no
].cur_cmd
->SCp
.phase
++; 108 #define imm_pb_release(x) parport_release(imm_hosts[(x)].dev) 110 /*************************************************************************** 111 * Parallel port probing routines * 112 ***************************************************************************/ 115 Scsi_Host_Template driver_template
= IMM
; 116 #include"scsi_module.c" 119 intimm_detect(Scsi_Host_Template
* host
) 121 struct Scsi_Host
*hreg
; 123 int i
, nhosts
, try_again
; 124 struct parport
*pb
=parport_enumerate(); 126 printk("imm: Version %s\n", IMM_VERSION
); 131 printk("imm: parport reports no devices.\n"); 135 for(i
=0; pb
; i
++, pb
= pb
->next
) { 139 parport_register_device(pb
,"imm", NULL
, imm_wakeup
, 140 NULL
,0, (void*) &imm_hosts
[i
]); 142 if(!imm_hosts
[i
].dev
) 145 /* Claim the bus so it remembers what we do to the control 146 * registers. [ CTR and ECP ] 148 if(imm_pb_claim(i
)) { 149 unsigned long now
= jiffies
; 150 while(imm_hosts
[i
].p_busy
) { 151 schedule();/* We are safe to schedule here */ 152 if(time_after(jiffies
, now
+3* HZ
)) { 153 printk(KERN_ERR
"imm%d: failed to claim parport because a " 154 "pardevice is owning the port for too longtime!\n", 160 ppb
=IMM_BASE(i
) = imm_hosts
[i
].dev
->port
->base
; 162 modes
= imm_hosts
[i
].dev
->port
->modes
; 164 /* Mode detection works up the chain of speed 165 * This avoids a nasty if-then-else-if-... tree 167 imm_hosts
[i
].mode
= IMM_NIBBLE
; 169 if(modes
& PARPORT_MODE_PCPS2
) 170 imm_hosts
[i
].mode
= IMM_PS2
; 172 if(modes
& PARPORT_MODE_PCECPPS2
) { 174 imm_hosts
[i
].mode
= IMM_PS2
; 176 if(modes
& PARPORT_MODE_PCECPEPP
) 179 /* Done configuration */ 183 parport_unregister_device(imm_hosts
[i
].dev
); 186 /* now the glue ... */ 187 switch(imm_hosts
[i
].mode
) { 199 default:/* Never gets here */ 203 host
->can_queue
= IMM_CAN_QUEUE
; 204 host
->sg_tablesize
= imm_sg
; 205 hreg
=scsi_register(host
,0); 206 hreg
->io_port
= pb
->base
; 207 hreg
->n_io_port
= ports
; 208 hreg
->dma_channel
= -1; 210 imm_hosts
[i
].host
= hreg
->host_no
; 219 return1;/* return number of hosts detected */ 222 /* This is to give the imm driver a way to modify the timings (and other 223 * parameters) by writing to the /proc/scsi/imm/0 file. 224 * Very simple method really... (To simple, no error checking :( ) 225 * Reason: Kernel hackers HATE having to unload and reload modules for 227 * Also gives a method to use a script to obtain optimum timings (TODO) 229 staticinlineintimm_proc_write(int hostno
,char*buffer
,int length
) 233 if((length
>5) && (strncmp(buffer
,"mode=",5) ==0)) { 234 x
=simple_strtoul(buffer
+5, NULL
,0); 235 imm_hosts
[hostno
].mode
= x
; 238 printk("imm /proc: invalid variable\n"); 242 intimm_proc_info(char*buffer
,char**start
, off_t offset
, 243 int length
,int hostno
,int inout
) 249 if(imm_hosts
[i
].host
== hostno
) 253 returnimm_proc_write(i
, buffer
, length
); 255 len
+=sprintf(buffer
+ len
,"Version : %s\n", IMM_VERSION
); 256 len
+=sprintf(buffer
+ len
,"Parport : %s\n", imm_hosts
[i
].dev
->port
->name
); 257 len
+=sprintf(buffer
+ len
,"Mode : %s\n", IMM_MODE_STRING
[imm_hosts
[i
].mode
]); 259 /* Request for beyond end of buffer */ 263 *start
= buffer
+ offset
; 271 #define imm_fail(x,y) printk("imm: imm_fail(%i) from %s at line %d\n",\ 272 y, __FUNCTION__, __LINE__); imm_fail_func(x,y); 273 staticinlinevoidimm_fail_func(int host_no
,int error_code
) 275 staticinlinevoidimm_fail(int host_no
,int error_code
) 278 /* If we fail a device then we trash status / message bytes */ 279 if(imm_hosts
[host_no
].cur_cmd
) { 280 imm_hosts
[host_no
].cur_cmd
->result
= error_code
<<16; 281 imm_hosts
[host_no
].failed
=1; 286 * Wait for the high bit to be set. 288 * In principle, this could be tied to an interrupt, but the adapter 289 * doesn't appear to be designed to support interrupts. We spin on 290 * the 0x80 ready bit. 292 static unsigned charimm_wait(int host_no
) 295 unsigned short ppb
=IMM_BASE(host_no
); 306 while(!(r
&0x80) && (k
)); 309 * STR register (LPT base+1) to SCSI mapping: 312 * =================================== 320 * ================================== 322 * 0xc0 0x88 ZIP wants more data 323 * 0xd0 0x98 ZIP wants to send more data 324 * 0xe0 0xa8 ZIP is expecting SCSI command data 325 * 0xf0 0xb8 end of transfer, ZIP is sending status 331 /* Counter expired - Time out occurred */ 332 imm_fail(host_no
, DID_TIME_OUT
); 333 printk("imm timeout in imm_wait\n"); 334 return0;/* command timed out */ 337 static intimm_negotiate(imm_struct
* tmp
) 340 * The following is supposedly the IEEE 1248-1994 negotiate 341 * sequence. I have yet to obtain a copy of the above standard 342 * so this is a bit of a guess... 344 * A fair chunk of this is based on the Linux parport implementation 347 * Return 0 if data available 348 * 1 if no data available 351 unsigned short base
= tmp
->base
; 352 unsigned char a
, mode
; 371 a
= (r_str(base
) &0x20) ?0:1; 378 printk("IMM: IEEE1284 negotiate indicates no data available.\n"); 379 imm_fail(tmp
->host
, DID_ERROR
); 384 staticinlinevoidepp_reset(unsigned short ppb
) 393 staticinlinevoidecp_sync(unsigned short ppb
) 397 if((r_ecr(ppb
) &0xe0) !=0x80) 400 for(i
=0; i
<100; i
++) { 405 printk("imm: ECP sync failed as data still present in FIFO.\n"); 408 static intimm_byte_out(unsigned short base
,const char*buffer
,int len
) 412 w_ctr(base
,0x4);/* apparently a sane mode */ 413 for(i
= len
>>1; i
; i
--) { 414 w_dtr(base
, *buffer
++); 415 w_ctr(base
,0x5);/* Drop STROBE low */ 416 w_dtr(base
, *buffer
++); 417 w_ctr(base
,0x0);/* STROBE high + INIT low */ 419 w_ctr(base
,0x4);/* apparently a sane mode */ 420 return1;/* All went well - we hope! */ 423 static intimm_nibble_in(unsigned short base
,char*buffer
,int len
) 429 * The following is based on documented timing signals 432 for(i
= len
; i
; i
--) { 434 l
= (r_str(base
) &0xf0) >>4; 436 *buffer
++ = (r_str(base
) &0xf0) | l
; 439 return1;/* All went well - we hope! */ 442 static intimm_byte_in(unsigned short base
,char*buffer
,int len
) 447 * The following is based on documented timing signals 450 for(i
= len
; i
; i
--) { 452 *buffer
++ =r_dtr(base
); 455 return1;/* All went well - we hope! */ 458 static intimm_out(int host_no
,char*buffer
,int len
) 461 unsigned short ppb
=IMM_BASE(host_no
); 463 r
=imm_wait(host_no
); 467 * a) the SCSI bus is BUSY (device still listening) 468 * b) the device is listening 470 if((r
&0x18) !=0x08) { 471 imm_fail(host_no
, DID_ERROR
); 472 printk("IMM: returned SCSI status %2x\n", r
); 475 switch(imm_hosts
[host_no
].mode
) { 481 #ifdef CONFIG_SCSI_IZIP_EPP16 482 if(!(((long) buffer
| len
) &0x01)) 483 outsw(ppb
+4, buffer
, len
>>1); 485 if(!(((long) buffer
| len
) &0x03)) 486 outsl(ppb
+4, buffer
, len
>>2); 489 outsb(ppb
+4, buffer
, len
); 491 r
= !(r_str(ppb
) &0x01); 498 /* 8 bit output, with a loop */ 499 r
=imm_byte_out(ppb
, buffer
, len
); 503 printk("IMM: bug in imm_out()\n"); 509 static intimm_in(int host_no
,char*buffer
,int len
) 512 unsigned short ppb
=IMM_BASE(host_no
); 514 r
=imm_wait(host_no
); 518 * a) the SCSI bus is BUSY (device still listening) 519 * b) the device is sending data 521 if((r
&0x18) !=0x18) { 522 imm_fail(host_no
, DID_ERROR
); 525 switch(imm_hosts
[host_no
].mode
) { 527 /* 4 bit input, with a loop */ 528 r
=imm_nibble_in(ppb
, buffer
, len
); 533 /* 8 bit input, with a loop */ 534 r
=imm_byte_in(ppb
, buffer
, len
); 543 #ifdef CONFIG_SCSI_IZIP_EPP16 544 if(!(((long) buffer
| len
) &0x01)) 545 insw(ppb
+4, buffer
, len
>>1); 547 if(!(((long) buffer
| len
) &0x03)) 548 insl(ppb
+4, buffer
, len
>>2); 551 insb(ppb
+4, buffer
, len
); 553 r
= !(r_str(ppb
) &0x01); 559 printk("IMM: bug in imm_ins()\n"); 566 static intimm_cpp(unsigned short ppb
,unsigned char b
) 569 * Comments on udelay values refer to the 570 * Command Packet Protocol (CPP) timing diagram. 573 unsigned char s1
, s2
, s3
; 575 udelay(2);/* 1 usec - infinite */ 577 udelay(10);/* 7 usec - infinite */ 579 udelay(10);/* 7 usec - infinite */ 581 udelay(10);/* 7 usec - infinite */ 583 udelay(10);/* 7 usec - infinite */ 584 s1
=r_str(ppb
) &0xb8; 586 udelay(10);/* 7 usec - infinite */ 587 s2
=r_str(ppb
) &0xb8; 589 udelay(10);/* 7 usec - infinite */ 590 s3
=r_str(ppb
) &0x38; 593 * 0000 00aa Assign address aa to current device 594 * 0010 00aa Select device aa in EPP Winbond mode 595 * 0010 10aa Select device aa in EPP mode 596 * 0011 xxxx Deselect all devices 597 * 0110 00aa Test device aa 598 * 1101 00aa Select device aa in ECP mode 599 * 1110 00aa Select device aa in Compatible mode 602 udelay(2);/* 1 usec - infinite */ 604 udelay(10);/* 7 usec - infinite */ 606 udelay(2);/* 1 usec - infinite */ 608 udelay(10);/* 7 usec - infinite */ 610 udelay(10);/* 7 usec - infinite */ 613 * The following table is electrical pin values. 614 * (BSY is inverted at the CTR register) 616 * BSY ACK POut SEL Fault 621 * L => Last device in chain 624 * Observered values for S1,S2,S3 are: 625 * Disconnect => f8/58/78 626 * Connect => f8/58/70 628 if((s1
==0xb8) && (s2
==0x18) && (s3
==0x30)) 629 return1;/* Connected */ 630 if((s1
==0xb8) && (s2
==0x18) && (s3
==0x38)) 631 return0;/* Disconnected */ 633 return-1;/* No device present */ 636 staticinlineintimm_connect(int host_no
,int flag
) 638 unsigned short ppb
=IMM_BASE(host_no
); 640 imm_cpp(ppb
,0xe0);/* Select device 0 in compatible mode */ 641 imm_cpp(ppb
,0x30);/* Disconnect all devices */ 643 if((imm_hosts
[host_no
].mode
== IMM_EPP_8
) || 644 (imm_hosts
[host_no
].mode
== IMM_EPP_16
) || 645 (imm_hosts
[host_no
].mode
== IMM_EPP_32
)) 646 returnimm_cpp(ppb
,0x28);/* Select device 0 in EPP mode */ 647 returnimm_cpp(ppb
,0xe0);/* Select device 0 in compatible mode */ 650 static voidimm_disconnect(int host_no
) 652 unsigned short ppb
=IMM_BASE(host_no
); 654 imm_cpp(ppb
,0x30);/* Disconnect all devices */ 657 static intimm_select(int host_no
,int target
) 660 unsigned short ppb
=IMM_BASE(host_no
); 663 * Firstly we want to make sure there is nothing 664 * holding onto the SCSI bus. 671 }while((r_str(ppb
) &0x08) && (k
)); 677 * Now assert the SCSI ID (HOST and TARGET) on the data bus 680 w_dtr(ppb
,0x80| (1<< target
)); 684 * Deassert SELIN first followed by STROBE 690 * ACK should drop low while SELIN is deasserted. 691 * FAULT should drop low when the SCSI device latches the bus. 697 while(!(r_str(ppb
) &0x08) && (k
)); 700 * Place the interface back into a sane state (status mode) 706 static intimm_init(int host_no
) 710 #if defined(CONFIG_PARPORT) || defined(CONFIG_PARPORT_MODULE) 711 if(imm_pb_claim(host_no
)) 712 while(imm_hosts
[host_no
].p_busy
) 713 schedule();/* We can safe schedule here */ 715 retv
=imm_connect(host_no
,0); 718 imm_reset_pulse(IMM_BASE(host_no
)); 719 udelay(1000);/* Delay to allow devices to settle */ 720 imm_disconnect(host_no
); 721 udelay(1000);/* Another delay to allow devices to settle */ 722 retv
=device_check(host_no
); 723 imm_pb_release(host_no
); 726 imm_pb_release(host_no
); 730 staticinlineintimm_send_command(Scsi_Cmnd
* cmd
) 732 int host_no
= cmd
->host
->unique_id
; 735 /* NOTE: IMM uses byte pairs */ 736 for(k
=0; k
< cmd
->cmd_len
; k
+=2) 737 if(!imm_out(host_no
, &cmd
->cmnd
[k
],2)) 743 * The bulk flag enables some optimisations in the data transfer loops, 744 * it should be true for any command that transfers data in integral 745 * numbers of sectors. 747 * The driver appears to remain stable if we speed up the parallel port 748 * i/o in this function, but not elsewhere. 750 static intimm_completion(Scsi_Cmnd
* cmd
) 755 * 1 Finished data transfer 757 int host_no
= cmd
->host
->unique_id
; 758 unsigned short ppb
=IMM_BASE(host_no
); 759 unsigned long start_jiffies
= jiffies
; 762 int fast
, bulk
, status
; 765 bulk
= ((v
== READ_6
) || 771 * We only get here if the drive is ready to comunicate, 772 * hence no need for a full imm_wait. 775 r
= (r_str(ppb
) &0xb8); 778 * while (device is not ready to send status byte) 781 while(r
!= (unsigned char)0xb8) { 783 * If we have been running for more than a full timer tick 786 if(time_after(jiffies
, start_jiffies
+1)) 791 * a) Drive status is screwy (!ready && !present) 792 * b) Drive is requesting/sending more data than expected 794 if(((r
&0x88) !=0x88) || (cmd
->SCp
.this_residual
<=0)) { 795 imm_fail(host_no
, DID_ERROR
); 796 return-1;/* ERROR_RETURN */ 798 /* determine if we should use burst I/O */ 799 if(imm_hosts
[host_no
].rd
==0) { 800 fast
= (bulk
&& (cmd
->SCp
.this_residual
>= IMM_BURST_SIZE
)) ? IMM_BURST_SIZE
:2; 801 status
=imm_out(host_no
, cmd
->SCp
.ptr
, fast
); 803 fast
= (bulk
&& (cmd
->SCp
.this_residual
>= IMM_BURST_SIZE
)) ? IMM_BURST_SIZE
:1; 804 status
=imm_in(host_no
, cmd
->SCp
.ptr
, fast
); 807 cmd
->SCp
.ptr
+= fast
; 808 cmd
->SCp
.this_residual
-= fast
; 811 imm_fail(host_no
, DID_BUS_BUSY
); 812 return-1;/* ERROR_RETURN */ 814 if(cmd
->SCp
.buffer
&& !cmd
->SCp
.this_residual
) { 815 /* if scatter/gather, advance to the next segment */ 816 if(cmd
->SCp
.buffers_residual
--) { 818 cmd
->SCp
.this_residual
= cmd
->SCp
.buffer
->length
; 819 cmd
->SCp
.ptr
= cmd
->SCp
.buffer
->address
; 822 * Make sure that we transfer even number of bytes 823 * otherwise it makes imm_byte_out() messy. 825 if(cmd
->SCp
.this_residual
&0x01) { 826 cmd
->SCp
.this_residual
++; 827 printk("IMM: adjusted buffer for 16 bit transfer\n"); 831 /* Now check to see if the drive is ready to comunicate */ 833 r
= (r_str(ppb
) &0xb8); 835 /* If not, drop back down to the scheduler and wait a timer tick */ 839 return1;/* FINISH_RETURN */ 842 /* deprecated synchronous interface */ 843 intimm_command(Scsi_Cmnd
* cmd
) 845 static int first_pass
=1; 846 int host_no
= cmd
->host
->unique_id
; 849 printk("imm: using non-queuing interface\n"); 852 if(imm_hosts
[host_no
].cur_cmd
) { 853 printk("IMM: bug in imm_command\n"); 856 imm_hosts
[host_no
].failed
=0; 857 imm_hosts
[host_no
].jstart
= jiffies
; 858 imm_hosts
[host_no
].cur_cmd
= cmd
; 859 cmd
->result
= DID_ERROR
<<16;/* default return code */ 862 imm_pb_claim(host_no
); 864 while(imm_engine(&imm_hosts
[host_no
], cmd
)) 867 if(cmd
->SCp
.phase
)/* Only disconnect if we have connected */ 868 imm_disconnect(cmd
->host
->unique_id
); 870 imm_pb_release(host_no
); 871 imm_hosts
[host_no
].cur_cmd
=0; 876 * Since the IMM itself doesn't generate interrupts, we use 877 * the scheduler's task queue to generate a stream of call-backs and 878 * complete the request when the drive is ready. 880 static voidimm_interrupt(void*data
) 882 imm_struct
*tmp
= (imm_struct
*) data
; 883 Scsi_Cmnd
*cmd
= tmp
->cur_cmd
; 887 printk("IMM: bug in imm_interrupt\n"); 890 if(imm_engine(tmp
, cmd
)) { 891 tmp
->imm_tq
.data
= (void*) tmp
; 893 queue_task(&tmp
->imm_tq
, &tq_timer
); 896 /* Command must of completed hence it is safe to let go... */ 898 switch((cmd
->result
>>16) &0xff) { 902 printk("imm: no device at SCSI ID %i\n", cmd
->target
); 905 printk("imm: BUS BUSY - EPP timeout detected\n"); 908 printk("imm: unknown timeout\n"); 911 printk("imm: told to abort\n"); 914 printk("imm: parity error (???)\n"); 917 printk("imm: internal driver error\n"); 920 printk("imm: told to reset device\n"); 923 printk("imm: bad interrupt (???)\n"); 926 printk("imm: bad return code (%02x)\n", (cmd
->result
>>16) &0xff); 930 if(cmd
->SCp
.phase
>1) 931 imm_disconnect(cmd
->host
->unique_id
); 932 if(cmd
->SCp
.phase
>0) 933 imm_pb_release(cmd
->host
->unique_id
); 935 spin_lock_irqsave(&io_request_lock
, flags
); 938 spin_unlock_irqrestore(&io_request_lock
, flags
); 942 static intimm_engine(imm_struct
* tmp
, Scsi_Cmnd
* cmd
) 944 int host_no
= cmd
->host
->unique_id
; 945 unsigned short ppb
=IMM_BASE(host_no
); 946 unsigned char l
=0, h
=0; 949 /* First check for any errors that may of occurred 950 * Here we check for internal errors 955 switch(cmd
->SCp
.phase
) { 956 case0:/* Phase 0 - Waiting for parport */ 957 if((jiffies
- tmp
->jstart
) > HZ
) { 959 * We waited more than a second 960 * for parport to call us 962 imm_fail(host_no
, DID_BUS_BUSY
); 965 return1;/* wait until imm_wakeup claims parport */ 966 /* Phase 1 - Connected */ 968 imm_connect(host_no
, CONNECT_EPP_MAYBE
); 971 /* Phase 2 - We are now talking to the scsi bus */ 973 if(!imm_select(host_no
, cmd
->target
)) { 974 imm_fail(host_no
, DID_NO_CONNECT
); 979 /* Phase 3 - Ready to accept a command */ 982 if(!(r_str(ppb
) &0x80)) 985 if(!imm_send_command(cmd
)) 989 /* Phase 4 - Setup scatter/gather buffers */ 992 /* if many buffers are available, start filling the first */ 993 cmd
->SCp
.buffer
= (struct scatterlist
*) cmd
->request_buffer
; 994 cmd
->SCp
.this_residual
= cmd
->SCp
.buffer
->length
; 995 cmd
->SCp
.ptr
= cmd
->SCp
.buffer
->address
; 997 /* else fill the only available buffer */ 998 cmd
->SCp
.buffer
= NULL
; 999 cmd
->SCp
.this_residual
= cmd
->request_bufflen
; 1000 cmd
->SCp
.ptr
= cmd
->request_buffer
; 1002 cmd
->SCp
.buffers_residual
= cmd
->use_sg
; 1004 if(cmd
->SCp
.this_residual
&0x01) { 1005 cmd
->SCp
.this_residual
++; 1006 printk("IMM: adjusted buffer for 16 bit transfer\n"); 1008 /* Phase 5 - Pre-Data transfer stage */ 1010 /* Spin lock for BUSY */ 1012 if(!(r_str(ppb
) &0x80)) 1015 /* Require negotiation for read requests */ 1016 x
= (r_str(ppb
) &0xb8); 1017 tmp
->rd
= (x
&0x10) ?1:0; 1018 tmp
->dp
= (x
&0x20) ?0:1; 1020 if((tmp
->dp
) && (tmp
->rd
)) 1021 if(imm_negotiate(tmp
)) 1025 /* Phase 6 - Data transfer stage */ 1027 /* Spin lock for BUSY */ 1029 if(!(r_str(ppb
) &0x80)) 1033 retv
=imm_completion(cmd
); 1041 /* Phase 7 - Post data transfer stage */ 1043 if((tmp
->dp
) && (tmp
->rd
)) { 1044 if((tmp
->mode
== IMM_NIBBLE
) || (tmp
->mode
== IMM_PS2
)) { 1053 /* Phase 8 - Read status/message */ 1055 /* Check for data overrun */ 1056 if(imm_wait(host_no
) != (unsigned char)0xb8) { 1057 imm_fail(host_no
, DID_ERROR
); 1060 if(imm_negotiate(tmp
)) 1062 if(imm_in(host_no
, &l
,1)) {/* read status byte */ 1063 /* Check for optional message byte */ 1064 if(imm_wait(host_no
) == (unsigned char)0xb8) 1065 imm_in(host_no
, &h
,1); 1066 cmd
->result
= (DID_OK
<<16) + (l
& STATUS_MASK
); 1068 if((tmp
->mode
== IMM_NIBBLE
) || (tmp
->mode
== IMM_PS2
)) { 1074 return0;/* Finished */ 1078 printk("imm: Invalid scsi phase\n"); 1083 intimm_queuecommand(Scsi_Cmnd
* cmd
,void(*done
) (Scsi_Cmnd
*)) 1085 int host_no
= cmd
->host
->unique_id
; 1087 if(imm_hosts
[host_no
].cur_cmd
) { 1088 printk("IMM: bug in imm_queuecommand\n"); 1091 imm_hosts
[host_no
].failed
=0; 1092 imm_hosts
[host_no
].jstart
= jiffies
; 1093 imm_hosts
[host_no
].cur_cmd
= cmd
; 1094 cmd
->scsi_done
= done
; 1095 cmd
->result
= DID_ERROR
<<16;/* default return code */ 1096 cmd
->SCp
.phase
=0;/* bus free */ 1098 imm_pb_claim(host_no
); 1100 imm_hosts
[host_no
].imm_tq
.data
= imm_hosts
+ host_no
; 1101 imm_hosts
[host_no
].imm_tq
.sync
=0; 1102 queue_task(&imm_hosts
[host_no
].imm_tq
, &tq_immediate
); 1103 mark_bh(IMMEDIATE_BH
); 1109 * Aimmrently the the disk->capacity attribute is off by 1 sector 1110 * for all disk drives. We add the one here, but it should really 1111 * be done in sd.c. Even if it gets fixed there, this will still 1114 intimm_biosparam(Disk
* disk
, kdev_t dev
,int ip
[]) 1118 ip
[2] = (disk
->capacity
+1) / (ip
[0] * ip
[1]); 1122 ip
[2] = (disk
->capacity
+1) / (ip
[0] * ip
[1]); 1129 intimm_abort(Scsi_Cmnd
* cmd
) 1131 int host_no
= cmd
->host
->unique_id
; 1133 * There is no method for aborting commands since Iomega 1134 * have tied the SCSI_MESSAGE line high in the interface 1137 switch(cmd
->SCp
.phase
) { 1138 case0:/* Do not have access to parport */ 1139 case1:/* Have not connected to interface */ 1140 imm_hosts
[host_no
].cur_cmd
= NULL
;/* Forget the problem */ 1143 default:/* SCSI command sent, can not abort */ 1149 voidimm_reset_pulse(unsigned int base
) 1161 intimm_reset(Scsi_Cmnd
* cmd
) 1163 int host_no
= cmd
->host
->unique_id
; 1166 imm_disconnect(host_no
); 1167 imm_hosts
[host_no
].cur_cmd
= NULL
;/* Forget the problem */ 1169 imm_connect(host_no
, CONNECT_NORMAL
); 1170 imm_reset_pulse(IMM_BASE(host_no
)); 1171 udelay(1000);/* device settle delay */ 1172 imm_disconnect(host_no
); 1173 udelay(1000);/* device settle delay */ 1177 static intdevice_check(int host_no
) 1179 /* This routine looks for a device and then attempts to use EPP 1180 to send a command. If all goes as planned then EPP is available. */ 1182 static char cmd
[6] = 1183 {0x00,0x00,0x00,0x00,0x00,0x00}; 1184 int loop
, old_mode
, status
, k
, ppb
=IMM_BASE(host_no
); 1187 old_mode
= imm_hosts
[host_no
].mode
; 1188 for(loop
=0; loop
<8; loop
++) { 1189 /* Attempt to use EPP for Test Unit Ready */ 1190 if((ppb
&0x0007) ==0x0000) 1191 imm_hosts
[host_no
].mode
= IMM_EPP_32
; 1194 imm_connect(host_no
, CONNECT_EPP_MAYBE
); 1195 /* Select SCSI device */ 1196 if(!imm_select(host_no
, loop
)) { 1197 imm_disconnect(host_no
); 1200 printk("imm: Found device at ID %i, Attempting to use %s\n", loop
, 1201 IMM_MODE_STRING
[imm_hosts
[host_no
].mode
]); 1203 /* Send SCSI command */ 1206 for(l
=0; (l
<3) && (status
); l
++) 1207 status
=imm_out(host_no
, &cmd
[l
<<1],2); 1210 imm_disconnect(host_no
); 1211 imm_connect(host_no
, CONNECT_EPP_MAYBE
); 1212 imm_reset_pulse(IMM_BASE(host_no
)); 1214 imm_disconnect(host_no
); 1216 if(imm_hosts
[host_no
].mode
== IMM_EPP_32
) { 1217 imm_hosts
[host_no
].mode
= old_mode
; 1220 printk("imm: Unable to establish communication, aborting driver load.\n"); 1225 k
=1000000;/* 1 Second */ 1230 }while(!(l
&0x80) && (k
)); 1235 imm_disconnect(host_no
); 1236 imm_connect(host_no
, CONNECT_EPP_MAYBE
); 1237 imm_reset_pulse(IMM_BASE(host_no
)); 1239 imm_disconnect(host_no
); 1241 if(imm_hosts
[host_no
].mode
== IMM_EPP_32
) { 1242 imm_hosts
[host_no
].mode
= old_mode
; 1245 printk("imm: Unable to establish communication, aborting driver load.\n"); 1248 imm_disconnect(host_no
); 1249 printk("imm: Communication established with ID %i using %s\n", loop
, 1250 IMM_MODE_STRING
[imm_hosts
[host_no
].mode
]); 1251 imm_connect(host_no
, CONNECT_EPP_MAYBE
); 1252 imm_reset_pulse(IMM_BASE(host_no
)); 1254 imm_disconnect(host_no
); 1258 printk("imm: No devices found, aborting driver load.\n");