12 #include <linux/kernel.h>
13 #include <linux/module.h>
15 #include <linux/parport.h>
18 #include <linux/slab.h>
21 #include <scsi/scsi.h>
27 #define IMM_PROBE_SPP 0x0001
28 #define IMM_PROBE_PS2 0x0002
29 #define IMM_PROBE_ECR 0x0010
30 #define IMM_PROBE_EPP17 0x0100
31 #define IMM_PROBE_EPP19 0x0200
51 static void imm_reset_pulse(
unsigned int base);
65 dev->
base = dev->
dev->port->base;
72 static void imm_wakeup(
void *ref)
83 spin_unlock_irqrestore(&arbitration_lock, flags);
96 spin_unlock_irqrestore(&arbitration_lock, flags);
107 spin_unlock_irqrestore(&arbitration_lock, flags);
112 static inline void imm_pb_release(
imm_struct *dev)
128 if ((length > 5) && (
strncmp(buffer,
"mode=", 5) == 0)) {
133 printk(
"imm /proc: invalid variable\n");
144 return imm_proc_write(dev, buffer, length);
148 sprintf(buffer + len,
"Parport : %s\n",
149 dev->
dev->port->name);
151 sprintf(buffer + len,
"Mode : %s\n",
152 IMM_MODE_STRING[dev->
mode]);
166 #define imm_fail(x,y) printk("imm: imm_fail(%i) from %s at line %d\n",\
167 y, __func__, __LINE__); imm_fail_func(x,y);
177 dev->
cur_cmd->result = error_code << 16;
189 static unsigned char imm_wait(
imm_struct *dev)
192 unsigned short ppb = dev->
base;
203 while (!(r & 0x80) && (k));
230 printk(
"imm timeout in imm_wait\n");
249 unsigned char a,
mode;
268 a = (
r_str(base) & 0x20) ? 0 : 1;
276 (
"IMM: IEEE1284 negotiate indicates no data available.\n");
285 static inline void epp_reset(
unsigned short ppb)
291 w_str(ppb, i & 0xfe);
304 if ((
r_ecr(ppb_hi) & 0xe0) == 0x60) {
305 for (i = 0; i < 100; i++) {
306 if (
r_ecr(ppb_hi) & 0x01)
310 printk(
"imm: ECP sync failed as data still present in FIFO.\n");
314 static int imm_byte_out(
unsigned short base,
const char *buffer,
int len)
319 for (i = len >> 1;
i; i--) {
320 w_dtr(base, *buffer++);
322 w_dtr(base, *buffer++);
329 static int imm_nibble_in(
unsigned short base,
char *buffer,
int len)
338 for (i = len;
i; i--) {
340 l = (
r_str(base) & 0xf0) >> 4;
342 *buffer++ = (
r_str(base) & 0xf0) | l;
348 static int imm_byte_in(
unsigned short base,
char *buffer,
int len)
356 for (i = len;
i; i--) {
358 *buffer++ =
r_dtr(base);
364 static int imm_out(
imm_struct *dev,
char *buffer,
int len)
366 unsigned short ppb = dev->
base;
367 int r = imm_wait(dev);
374 if ((r & 0x18) != 0x08) {
376 printk(
"IMM: returned SCSI status %2x\n", r);
385 #ifdef CONFIG_SCSI_IZIP_EPP16
386 if (!(((
long) buffer | len) & 0x01))
387 outsw(ppb + 4, buffer, len >> 1);
389 if (!(((
long) buffer | len) & 0x03))
390 outsl(ppb + 4, buffer, len >> 2);
393 outsb(ppb + 4, buffer, len);
395 r = !(
r_str(ppb) & 0x01);
403 r = imm_byte_out(ppb, buffer, len);
407 printk(
"IMM: bug in imm_out()\n");
413 static int imm_in(
imm_struct *dev,
char *buffer,
int len)
415 unsigned short ppb = dev->
base;
416 int r = imm_wait(dev);
423 if ((r & 0x18) != 0x18) {
430 r = imm_nibble_in(ppb, buffer, len);
436 r = imm_byte_in(ppb, buffer, len);
445 #ifdef CONFIG_SCSI_IZIP_EPP16
446 if (!(((
long) buffer | len) & 0x01))
447 insw(ppb + 4, buffer, len >> 1);
449 if (!(((
long) buffer | len) & 0x03))
450 insl(ppb + 4, buffer, len >> 2);
453 insb(ppb + 4, buffer, len);
455 r = !(
r_str(ppb) & 0x01);
461 printk(
"IMM: bug in imm_ins()\n");
468 static int imm_cpp(
unsigned short ppb,
unsigned char b)
486 s1 =
r_str(ppb) & 0xb8;
489 s2 =
r_str(ppb) & 0xb8;
492 s3 =
r_str(ppb) & 0x38;
530 if ((s1 == 0xb8) && (s2 == 0x18) && (s3 == 0x30))
532 if ((s1 == 0xb8) && (s2 == 0x18) && (s3 == 0x38))
540 unsigned short ppb = dev->
base;
548 return imm_cpp(ppb, 0x28);
549 return imm_cpp(ppb, 0xe0);
554 imm_cpp(dev->
base, 0x30);
560 unsigned short ppb = dev->
base;
571 }
while ((
r_str(ppb) & 0x08) && (k));
580 w_dtr(ppb, 0x80 | (1 << target));
597 while (!(
r_str(ppb) & 0x08) && (k));
608 if (imm_connect(dev, 0) != 1)
610 imm_reset_pulse(dev->
base);
614 return device_check(dev);
617 static inline int imm_send_command(
struct scsi_cmnd *
cmd)
623 for (k = 0; k < cmd->
cmd_len; k += 2)
624 if (!imm_out(dev, &cmd->
cmnd[k], 2))
637 static int imm_completion(
struct scsi_cmnd *cmd)
645 unsigned short ppb = dev->
base;
646 unsigned long start_jiffies =
jiffies;
660 r = (
r_str(ppb) & 0xb8);
666 while (r != (
unsigned char) 0xb8) {
679 if (((r & 0x88) != 0x88) || (cmd->
SCp.this_residual <= 0)) {
686 && (cmd->
SCp.this_residual >=
688 status = imm_out(dev, cmd->
SCp.ptr, fast);
691 && (cmd->
SCp.this_residual >=
693 status = imm_in(dev, cmd->
SCp.ptr, fast);
697 cmd->
SCp.this_residual -=
fast;
703 if (cmd->
SCp.buffer && !cmd->
SCp.this_residual) {
705 if (cmd->
SCp.buffers_residual--) {
707 cmd->
SCp.this_residual =
708 cmd->
SCp.buffer->length;
709 cmd->
SCp.ptr = sg_virt(cmd->
SCp.buffer);
715 if (cmd->
SCp.this_residual & 0x01)
716 cmd->
SCp.this_residual++;
721 r = (
r_str(ppb) & 0xb8);
742 if (imm_engine(dev, cmd)) {
748 switch ((cmd->
result >> 16) & 0xff) {
752 printk(
"imm: no device at SCSI ID %i\n", cmd->
device->id);
755 printk(
"imm: BUS BUSY - EPP timeout detected\n");
758 printk(
"imm: unknown timeout\n");
761 printk(
"imm: told to abort\n");
764 printk(
"imm: parity error (???)\n");
767 printk(
"imm: internal driver error\n");
770 printk(
"imm: told to reset device\n");
773 printk(
"imm: bad interrupt (???)\n");
776 printk(
"imm: bad return code (%02x)\n",
777 (cmd->
result >> 16) & 0xff);
781 if (cmd->
SCp.phase > 1)
789 spin_unlock_irqrestore(host->
host_lock, flags);
795 unsigned short ppb = dev->
base;
796 unsigned char l = 0,
h = 0;
805 switch (cmd->
SCp.phase) {
823 if (!imm_select(dev,
scmd_id(cmd))) {
832 if (!(
r_str(ppb) & 0x80))
835 if (!imm_send_command(cmd))
841 if (scsi_bufflen(cmd)) {
842 cmd->
SCp.buffer = scsi_sglist(cmd);
843 cmd->
SCp.this_residual = cmd->
SCp.buffer->length;
844 cmd->
SCp.ptr = sg_virt(cmd->
SCp.buffer);
847 cmd->
SCp.this_residual = 0;
850 cmd->
SCp.buffers_residual = scsi_sg_count(cmd) - 1;
852 if (cmd->
SCp.this_residual & 0x01)
853 cmd->
SCp.this_residual++;
858 if (!(
r_str(ppb) & 0x80))
862 x = (
r_str(ppb) & 0xb8);
863 dev->
rd = (x & 0x10) ? 1 : 0;
864 dev->
dp = (x & 0x20) ? 0 : 1;
866 if ((dev->
dp) && (dev->
rd))
867 if (imm_negotiate(dev))
875 if (!(
r_str(ppb) & 0x80))
879 retv = imm_completion(cmd);
889 if ((dev->
dp) && (dev->
rd)) {
902 if (imm_wait(dev) != (
unsigned char) 0xb8) {
906 if (imm_negotiate(dev))
908 if (imm_in(dev, &l, 1)) {
910 if (imm_wait(dev) == (
unsigned char) 0xb8)
924 printk(
"imm: Invalid scsi phase\n");
929 static int imm_queuecommand_lck(
struct scsi_cmnd *cmd,
935 printk(
"IMM: bug in imm_queuecommand\n");
965 ip[2] = ((
unsigned long) capacity + 1) / (ip[0] * ip[1]);
969 ip[2] = ((
unsigned long) capacity + 1) / (ip[0] * ip[1]);
974 static int imm_abort(
struct scsi_cmnd *cmd)
982 switch (cmd->
SCp.phase) {
994 static void imm_reset_pulse(
unsigned int base)
1006 static int imm_reset(
struct scsi_cmnd *cmd)
1011 imm_disconnect(dev);
1015 imm_reset_pulse(dev->
base);
1017 imm_disconnect(dev);
1027 static char cmd[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1031 old_mode = dev->
mode;
1032 for (loop = 0; loop < 8; loop++) {
1034 if ((ppb & 0x0007) == 0x0000)
1040 if (!imm_select(dev, loop)) {
1041 imm_disconnect(dev);
1044 printk(
"imm: Found device at ID %i, Attempting to use %s\n",
1045 loop, IMM_MODE_STRING[dev->
mode]);
1050 for (l = 0; (l < 3) && (status); l++)
1051 status = imm_out(dev, &cmd[l << 1], 2);
1054 imm_disconnect(dev);
1056 imm_reset_pulse(dev->
base);
1058 imm_disconnect(dev);
1061 dev->
mode = old_mode;
1064 printk(
"imm: Unable to establish communication\n");
1074 }
while (!(l & 0x80) && (k));
1079 imm_disconnect(dev);
1081 imm_reset_pulse(dev->
base);
1083 imm_disconnect(dev);
1086 dev->
mode = old_mode;
1090 (
"imm: Unable to establish communication\n");
1093 imm_disconnect(dev);
1095 (
"imm: Communication established at 0x%x with ID %i using %s\n",
1096 ppb, loop, IMM_MODE_STRING[dev->
mode]);
1098 imm_reset_pulse(dev->
base);
1100 imm_disconnect(dev);
1104 printk(
"imm: No devices found\n");
1121 .proc_info = imm_proc_info,
1122 .name =
"Iomega VPI2 (imm) interface",
1123 .queuecommand = imm_queuecommand,
1124 .eh_abort_handler = imm_abort,
1125 .eh_bus_reset_handler = imm_reset,
1126 .eh_host_reset_handler = imm_reset,
1127 .bios_param = imm_biosparam,
1133 .slave_alloc = imm_adjust_queue,
1142 static int __imm_attach(
struct parport *pb)
1161 INIT_LIST_HEAD(&dev->
list);
1176 if (imm_pb_claim(dev))
1180 "a pardevice is owning the port for too long "
1182 imm_pb_dismiss(dev);
1189 ppb = dev->
base = dev->
dev->port->base;
1192 modes = dev->
dev->port->modes;
1204 err = imm_init(dev);
1206 imm_pb_release(dev);
1230 err = scsi_add_host(host,
NULL);
1237 list_del_init(&dev->
list);
1246 static void imm_attach(
struct parport *pb)
1251 static void imm_detach(
struct parport *pb)
1255 if (dev->
dev->port == pb) {
1256 list_del_init(&dev->
list);
1268 .attach = imm_attach,
1269 .detach = imm_detach,
1272 static int __init imm_driver_init(
void)
1278 static void __exit imm_driver_exit(
void)