Skip to content

Commit 68a4f84

Browse files
alexhenriemartinkpetersen
authored andcommitted
scsi: ppa: Add a module parameter for the transfer mode
I have an Iomega Z100P2 zip drive, but it does not work with my StarTech PEX1P2 AX99100 PCIe parallel port, which evidently does not support 16-bit or 32-bit EPP. Currently the only way to tell the PPA driver to use 8-bit EPP is to write 'mode=3' to /proc/scsi/ppa/*, but the driver doesn't actually distinguish between the three EPP modes and still tries to use 16-bit or 32-bit EPP. And even if writing to that file did make the driver use 8-bit EPP, it still wouldn't do me any good because by the time that file exists, the drive has already failed to initialize. Add a new parameter /sys/module/ppa/mode to set the transfer mode before initializing the drive. This parameter replaces the use of CONFIG_SCSI_IZIP_EPP16 in the PPA driver. At the same time, default to 8-bit EPP. 16-bit and 32-bit EPP are not necessary for the drive to function, nor are they part of the IEEE 1284 standard, so the driver should not assume that they are available. Signed-off-by: Alex Henrie <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent b68442e commit 68a4f84

File tree

3 files changed

+43
-45
lines changed

3 files changed

+43
-45
lines changed

drivers/scsi/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ config SCSI_IMM
836836

837837
config SCSI_IZIP_EPP16
838838
bool "ppa/imm option - Use slow (but safe) EPP-16"
839-
depends on SCSI_PPA || SCSI_IMM
839+
depends on SCSI_IMM
840840
help
841841
EPP (Enhanced Parallel Port) is a standard for parallel ports which
842842
allows them to act as expansion buses that can handle up to 64

drivers/scsi/ppa.c

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ typedef struct {
4545

4646
#include "ppa.h"
4747

48+
static unsigned int mode = PPA_AUTODETECT;
49+
module_param(mode, uint, 0644);
50+
MODULE_PARM_DESC(mode, "Transfer mode (0 = Autodetect, 1 = SPP 4-bit, "
51+
"2 = SPP 8-bit, 3 = EPP 8-bit, 4 = EPP 16-bit, 5 = EPP 32-bit");
52+
4853
static struct scsi_pointer *ppa_scsi_pointer(struct scsi_cmnd *cmd)
4954
{
5055
return scsi_cmd_priv(cmd);
@@ -157,7 +162,7 @@ static int ppa_show_info(struct seq_file *m, struct Scsi_Host *host)
157162
return 0;
158163
}
159164

160-
static int device_check(ppa_struct *dev);
165+
static int device_check(ppa_struct *dev, bool autodetect);
161166

162167
#if PPA_DEBUG > 0
163168
#define ppa_fail(x,y) printk("ppa: ppa_fail(%i) from %s at line %d\n",\
@@ -302,13 +307,10 @@ static int ppa_out(ppa_struct *dev, char *buffer, int len)
302307
case PPA_EPP_8:
303308
epp_reset(ppb);
304309
w_ctr(ppb, 0x4);
305-
#ifdef CONFIG_SCSI_IZIP_EPP16
306-
if (!(((long) buffer | len) & 0x01))
307-
outsw(ppb + 4, buffer, len >> 1);
308-
#else
309-
if (!(((long) buffer | len) & 0x03))
310+
if (dev->mode == PPA_EPP_32 && !(((long) buffer | len) & 0x01))
310311
outsl(ppb + 4, buffer, len >> 2);
311-
#endif
312+
else if (dev->mode == PPA_EPP_16 && !(((long) buffer | len) & 0x03))
313+
outsw(ppb + 4, buffer, len >> 1);
312314
else
313315
outsb(ppb + 4, buffer, len);
314316
w_ctr(ppb, 0xc);
@@ -355,13 +357,10 @@ static int ppa_in(ppa_struct *dev, char *buffer, int len)
355357
case PPA_EPP_8:
356358
epp_reset(ppb);
357359
w_ctr(ppb, 0x24);
358-
#ifdef CONFIG_SCSI_IZIP_EPP16
359-
if (!(((long) buffer | len) & 0x01))
360-
insw(ppb + 4, buffer, len >> 1);
361-
#else
362-
if (!(((long) buffer | len) & 0x03))
360+
if (dev->mode == PPA_EPP_32 && !(((long) buffer | len) & 0x03))
363361
insl(ppb + 4, buffer, len >> 2);
364-
#endif
362+
else if (dev->mode == PPA_EPP_16 && !(((long) buffer | len) & 0x01))
363+
insw(ppb + 4, buffer, len >> 1);
365364
else
366365
insb(ppb + 4, buffer, len);
367366
w_ctr(ppb, 0x2c);
@@ -469,6 +468,27 @@ static int ppa_init(ppa_struct *dev)
469468
{
470469
int retv;
471470
unsigned short ppb = dev->base;
471+
bool autodetect = dev->mode == PPA_AUTODETECT;
472+
473+
if (autodetect) {
474+
int modes = dev->dev->port->modes;
475+
int ppb_hi = dev->dev->port->base_hi;
476+
477+
/* Mode detection works up the chain of speed
478+
* This avoids a nasty if-then-else-if-... tree
479+
*/
480+
dev->mode = PPA_NIBBLE;
481+
482+
if (modes & PARPORT_MODE_TRISTATE)
483+
dev->mode = PPA_PS2;
484+
485+
if (modes & PARPORT_MODE_ECP) {
486+
w_ecr(ppb_hi, 0x20);
487+
dev->mode = PPA_PS2;
488+
}
489+
if ((modes & PARPORT_MODE_EPP) && (modes & PARPORT_MODE_ECP))
490+
w_ecr(ppb_hi, 0x80);
491+
}
472492

473493
ppa_disconnect(dev);
474494
ppa_connect(dev, CONNECT_NORMAL);
@@ -492,7 +512,7 @@ static int ppa_init(ppa_struct *dev)
492512
if (retv)
493513
return -EIO;
494514

495-
return device_check(dev);
515+
return device_check(dev, autodetect);
496516
}
497517

498518
static inline int ppa_send_command(struct scsi_cmnd *cmd)
@@ -883,7 +903,7 @@ static int ppa_reset(struct scsi_cmnd *cmd)
883903
return SUCCESS;
884904
}
885905

886-
static int device_check(ppa_struct *dev)
906+
static int device_check(ppa_struct *dev, bool autodetect)
887907
{
888908
/* This routine looks for a device and then attempts to use EPP
889909
to send a command. If all goes as planned then EPP is available. */
@@ -895,8 +915,8 @@ static int device_check(ppa_struct *dev)
895915
old_mode = dev->mode;
896916
for (loop = 0; loop < 8; loop++) {
897917
/* Attempt to use EPP for Test Unit Ready */
898-
if ((ppb & 0x0007) == 0x0000)
899-
dev->mode = PPA_EPP_32;
918+
if (autodetect && (ppb & 0x0007) == 0x0000)
919+
dev->mode = PPA_EPP_8;
900920

901921
second_pass:
902922
ppa_connect(dev, CONNECT_EPP_MAYBE);
@@ -924,7 +944,7 @@ static int device_check(ppa_struct *dev)
924944
udelay(1000);
925945
ppa_disconnect(dev);
926946
udelay(1000);
927-
if (dev->mode == PPA_EPP_32) {
947+
if (dev->mode != old_mode) {
928948
dev->mode = old_mode;
929949
goto second_pass;
930950
}
@@ -947,7 +967,7 @@ static int device_check(ppa_struct *dev)
947967
udelay(1000);
948968
ppa_disconnect(dev);
949969
udelay(1000);
950-
if (dev->mode == PPA_EPP_32) {
970+
if (dev->mode != old_mode) {
951971
dev->mode = old_mode;
952972
goto second_pass;
953973
}
@@ -1026,15 +1046,14 @@ static int __ppa_attach(struct parport *pb)
10261046
DEFINE_WAIT(wait);
10271047
ppa_struct *dev, *temp;
10281048
int ports;
1029-
int modes, ppb, ppb_hi;
10301049
int err = -ENOMEM;
10311050
struct pardev_cb ppa_cb;
10321051

10331052
dev = kzalloc(sizeof(ppa_struct), GFP_KERNEL);
10341053
if (!dev)
10351054
return -ENOMEM;
10361055
dev->base = -1;
1037-
dev->mode = PPA_AUTODETECT;
1056+
dev->mode = mode < PPA_UNKNOWN ? mode : PPA_AUTODETECT;
10381057
dev->recon_tmo = PPA_RECON_TMO;
10391058
init_waitqueue_head(&waiting);
10401059
temp = find_parent();
@@ -1069,25 +1088,8 @@ static int __ppa_attach(struct parport *pb)
10691088
}
10701089
dev->waiting = NULL;
10711090
finish_wait(&waiting, &wait);
1072-
ppb = dev->base = dev->dev->port->base;
1073-
ppb_hi = dev->dev->port->base_hi;
1074-
w_ctr(ppb, 0x0c);
1075-
modes = dev->dev->port->modes;
1076-
1077-
/* Mode detection works up the chain of speed
1078-
* This avoids a nasty if-then-else-if-... tree
1079-
*/
1080-
dev->mode = PPA_NIBBLE;
1081-
1082-
if (modes & PARPORT_MODE_TRISTATE)
1083-
dev->mode = PPA_PS2;
1084-
1085-
if (modes & PARPORT_MODE_ECP) {
1086-
w_ecr(ppb_hi, 0x20);
1087-
dev->mode = PPA_PS2;
1088-
}
1089-
if ((modes & PARPORT_MODE_EPP) && (modes & PARPORT_MODE_ECP))
1090-
w_ecr(ppb_hi, 0x80);
1091+
dev->base = dev->dev->port->base;
1092+
w_ctr(dev->base, 0x0c);
10911093

10921094
/* Done configuration */
10931095

drivers/scsi/ppa.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,7 @@ static char *PPA_MODE_STRING[] =
107107
"PS/2",
108108
"EPP 8 bit",
109109
"EPP 16 bit",
110-
#ifdef CONFIG_SCSI_IZIP_EPP16
111-
"EPP 16 bit",
112-
#else
113110
"EPP 32 bit",
114-
#endif
115111
"Unknown"};
116112

117113
/* other options */

0 commit comments

Comments
 (0)