Skip to contentSkip to conversation

for 53c700 chip and NCR_D700 card against 2.4.4

NEW SCSI DRIVER James Bottomley 2 participants 3 messages May 12, 2001 – May 15, 2001

lore
Share & tools
lore
#0 lore raw

Hi All,

Attached is a driver for the NCR Dual 700 Microchannel card. Since the chip engine of this card is the 53c700-66, which appeared in quite a few other SCSI cards as well, I've abstracted the chip function (in much the same way as the 8390 chip function is abstracted in network cards) so that it should be easy to link it into any other SCSI card using it. As you can see, the actual board specific code is about 150 lines.

The chip driver is full featured (sync (where supported), disconnects and tag command queueing). It will drive both single ended and differential interfaces and uses the new SCSI error handler.

I know we have two drivers that claim to do these chips (53c7xx and 53c7,8xx) but if you actually compile them for this chip, they are completely broken. The chip itself is extremely primitive (not having the table indirect mode, which is the backbone of most of the later drivers) so it makes much more sense to give it its own driver.

The chip driver is currently I/O mapped (because the only cards I know using the chip are I/O mapped), but could easily be made memory mapped as well, just let me know.

James Bottomley
Hansen Partnership.

Index: linux/2.4/MAINTAINERS

2.4/MAINTAINERS renamed from 2.4/MAINTAINERS:1.1.1.13 +12 -0
diff -u linux/2.4/MAINTAINERS:1.1.1.13 linux/2.4/MAINTAINERS:1.1.1.13.4.1
@@ -81,6 +81,12 @@
 L:	[email protected]
 S:	Maintained
 
+53C700 AND 53C700-66 SCSI DRIVER
+P:	James E.J. Bottomley
+M:	[email protected]
+L:	[email protected]
+S:	Maintained
+
 6PACK NETWORK DRIVER FOR AX.25
 P:	Andreas Koensgen
 M:	[email protected]
@@ -877,6 +883,12 @@
 P:	Volker Lendecke
 M:	[email protected]
 L:	[email protected]
+S:	Maintained
+
+NCR DUAL 700 SCSI DRIVER (MICROCHANNEL)
+P:	James E.J. Bottomley
+M:	[email protected]
+L:	[email protected]
 S:	Maintained
 
 NETFILTER

Index: linux/2.4/Documentation/Configure.help

2.4/Documentation/Configure.help renamed from 2.4/Documentation/Configure.help:1.1.1.13 +9 -0
diff -u linux/2.4/Documentation/Configure.help:1.1.1.13 linux/2.4/Documentation/Configure.help:1.1.1.13.4.1
@@ -5934,6 +5934,15 @@
   port or memory mapped. You should know what you have. The most
   common card, Trantor T130B, uses port mapped mode.
 
+NCR Dual 700 MCA SCSI support
+CONFIG_SCSI_NCR_D700
+  This is a driver for the Microchannel Dual 700 card produced by
+  NCR and commonly used in 345x/35xx/4100 class machines.  It always
+  tries to negotiate sync and uses tag command queueing.
+
+  Unless you have an NCR manufactured machine, the chances are that you do
+  not have this SCSI card, so say N.
+
 NCR53c7,8xx SCSI support
 CONFIG_SCSI_NCR53C7xx
   This is a driver for the 53c7 and 8xx NCR family of SCSI

Index: linux/2.4/drivers/scsi/53c700.c

2.4/drivers/scsi/53c700.c new file +1749 -0

1,749 lines not on this page · raw message

Index: linux/2.4/drivers/scsi/53c700.h

2.4/drivers/scsi/53c700.h new file +391 -0

391 lines not on this page · raw message

Index: linux/2.4/drivers/scsi/53c700.scr

2.4/drivers/scsi/53c700.scr new file +404 -0

404 lines not on this page · raw message

Index: linux/2.4/drivers/scsi/Config.in

2.4/drivers/scsi/Config.in renamed from 2.4/drivers/scsi/Config.in:1.1.1.8 +1 -0
diff -u linux/2.4/drivers/scsi/Config.in:1.1.1.8 linux/2.4/drivers/scsi/Config.in:1.1.1.8.4.1
@@ -114,6 +114,7 @@
    fi
 fi
 dep_tristate 'NCR53c406a SCSI support' CONFIG_SCSI_NCR53C406A $CONFIG_SCSI
+dep_tristate 'NCR Dual 700 MCA SCSI support' CONFIG_SCSI_NCR_D700 $CONFIG_SCSI $CONFIG_MCA
 dep_tristate 'NCR53c7,8xx SCSI support'  CONFIG_SCSI_NCR53C7xx $CONFIG_SCSI $CONFIG_PCI
 if [ "$CONFIG_SCSI_NCR53C7xx" != "n" ]; then
    bool '  always negotiate synchronous transfers' CONFIG_SCSI_NCR53C7xx_sync

Index: linux/2.4/drivers/scsi/Makefile

2.4/drivers/scsi/Makefile renamed from 2.4/drivers/scsi/Makefile:1.1.1.8 +9 -1
diff -u linux/2.4/drivers/scsi/Makefile:1.1.1.8 linux/2.4/drivers/scsi/Makefile:1.1.1.8.4.1
@@ -25,7 +25,7 @@
   endif
 endif
 
-export-objs	:= scsi_syms.o
+export-objs	:= scsi_syms.o 53c700.o
 
 CFLAGS_aha152x.o =   -DAHA152X_STAT -DAUTOCONF
 CFLAGS_gdth.o    = # -DDEBUG_GDTH=2 -D__SERIAL__ -D__COM2__ -DGDTH_STATISTICS
@@ -71,6 +71,7 @@
 obj-$(CONFIG_SCSI_IN2000)	+= in2000.o
 obj-$(CONFIG_SCSI_GENERIC_NCR5380) += g_NCR5380.o
 obj-$(CONFIG_SCSI_NCR53C406A)	+= NCR53c406a.o
+obj-$(CONFIG_SCSI_NCR_D700)	+= NCR_D700.o 53c700.o
 obj-$(CONFIG_SCSI_SYM53C416)	+= sym53c416.o
 obj-$(CONFIG_SCSI_QLOGIC_FAS)	+= qlogicfas.o
 obj-$(CONFIG_SCSI_QLOGIC_ISP)	+= qlogicisp.o 
@@ -184,3 +185,10 @@
 sim710_u.h: sim710_d.h
 
 sim710.o : sim710_d.h
+
+53c700_d.h: 53c700.scr script_asm.pl
+	$(PERL) -s script_asm.pl -ncr7x0_family < 53c700.scr
+	mv script.h 53c700_d.h
+	mv scriptu.h 53c700_u.h
+
+53c700.o: 53c700_d.h

Index: linux/2.4/drivers/scsi/NCR_D700.c

2.4/drivers/scsi/NCR_D700.c new file +327 -0

327 lines not on this page · raw message

Index: linux/2.4/drivers/scsi/NCR_D700.h

2.4/drivers/scsi/NCR_D700.h new file +45 -0

45 lines not on this page · raw message

Index: linux/2.4/drivers/scsi/README.53c700

2.4/drivers/scsi/README.53c700 new file +17 -0
diff -u /dev/null linux/2.4/drivers/scsi/README.53c700:1.1.4.2
@@ -0,0 +1,17 @@
+This driver supports the 53c700 and 53c700-66 chips only.  It is full
+featured and does sync (-66 only), disconnects and tag command
+queueing.
+
+Since the 53c700 must be interfaced to a bus, you need to wrapper the
+card detector around this driver.  For an example, see the
+NCR_D700.[ch] files.
+
+The comments in the 53c700.[ch] files tell you which parts you need to
+fill in to get the driver working.
+
+The driver is currently I/O mapped only, but it should be easy enough
+to memory map (just make the port reads #defines with MEM_MAPPED for
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#1 lore raw

Disclaimer: I know nothing of this device/hw, the scsi protocol or anything remotely applicable the functioning of this driver. The stuff below is just nit-picking and PITA-ing :) Pro-active kernel janitoring, if you like.

On Sat, May 12, 2001 at 11:43:04AM -0500, James Bottomley wrote:
[...]

Quoted 10 lines
2.4/drivers/scsi/53c700.c new file +10 -0
+struct Scsi_Host * __init
+NCR_700_detect(Scsi_Host_Template *tpnt,
+	       struct NCR_700_Host_Parameters *hostdata)
+{
+	__u32 *script = kmalloc(sizeof(SCRIPT), GFP_KERNEL);
+	__u32 pScript;
+	struct Scsi_Host *host;
+	static int banner = 0;
+	int j;
+

[...]

2.4/drivers/scsi/53c700.c line 212

Quoted 7 lines
2.4/drivers/scsi/53c700.c new file +7 -0
+
+	host = scsi_register(tpnt, 4);
+	if(script == NULL) {
+		printk(KERN_ERR "53c700: Failed to allocate script, detatching\n");
+		scsi_unregister(host);
+		return NULL;
+	}

You are not checking if the scsi_register went ok or not.

[...]

Quoted 4 lines
2.4/drivers/scsi/53c700.c new file +4 -0
+STATIC void 
+free_slot(struct NCR_700_command_slot *slot,
+	  struct NCR_700_Host_Parameters *hostdata)
+{

2.4/drivers/scsi/53c700.c line 403

Quoted 10 lines
2.4/drivers/scsi/53c700.c new file +10 -0
+	int hash;
+	struct NCR_700_command_slot **forw, **back;
+
+
+	if((slot->state & NCR_700_SLOT_MASK) != NCR_700_SLOT_MAGIC) {
+		printk(" SLOT %p is not MAGIC!!!\n", slot);
+	}
+	if(slot->state == NCR_700_SLOT_FREE) {
+		printk(" SLOT %p is FREE!!!\n", slot);
+	}

Could you be persuaded to add KERN_SOMETHING to the printks above?

[...]

Quoted 14 lines
2.4/drivers/scsi/53c700.c new file +14 -0
+STATIC __u32
+process_extended_message(struct Scsi_Host *host, 
+			 struct NCR_700_Host_Parameters *hostdata,
+			 Scsi_Cmnd *SCp, __u32 dsp, __u32 dsps)
+{
+	__u32 resume_offset = dsp, temp = dsp + 8;
+	__u8 pun = 0xff, lun = 0xff;
+
+	if(SCp != NULL) {
+		pun = SCp->target;
+		lun = SCp->lun;
+	}
+
+	switch(hostdata->msgin[2]) {

[...]

2.4/drivers/scsi/53c700.c line 691

Quoted 7 lines
2.4/drivers/scsi/53c700.c new file +7 -0
+
+	default:
+		printk(KERN_INFO "scsi%d (%d:%d): Unexpected message %s: ",
+		       host->host_no, pun, lun,
+		       NCR_700_phase[(dsps & 0xf00) >> 8]);
+		print_msg(hostdata->msgin);
+		printk("\n");

It would be nice with a KERN_XX before "\n" (yes, I recognize that print_msg does not do this :( )

[...]

Quoted 5 lines
2.4/drivers/scsi/53c700.c new file +5 -0
+STATIC __u32
+process_script_interrupt(__u32 dsps, __u32 dsp, Scsi_Cmnd *SCp,
+			 struct Scsi_Host *host,
+			 struct NCR_700_Host_Parameters *hostdata)
+{

[...]

2.4/drivers/scsi/53c700.c line 846

Quoted 8 lines
2.4/drivers/scsi/53c700.c new file +8 -0
+	} else if((dsps & 0xfffff0f0) == A_UNEXPECTED_PHASE) {
+		__u8 i = (dsps & 0xf00) >> 8;
+
+		printk(KERN_ERR "scsi%d: (%d:%d), UNEXPECTED PHASE %s (%s)\n",
+		       host->host_no, pun, lun,
+		       NCR_700_phase[i],
+		       sbcl_to_string(inb(host->base + SBCL_REG)));
+		printk("         len = %d, cmd =", SCp->cmd_len);

A KERN_ERR prefix?

[...]

2.4/drivers/scsi/53c700.c line 896

Quoted 12 lines
2.4/drivers/scsi/53c700.c new file +12 -0
+	retry:
+		if(slot == NULL) {
+			struct NCR_700_command_slot *s = find_ITL_Nexus(hostdata, reselection_id, lun);
+			printk(KERN_ERR "scsi%d: (%d:%d) RESELECTED but no saved command (MSG = %02x %02x %02x)!!\n",
+			       host->host_no, reselection_id, lun,
+			       hostdata->msgin[0], hostdata->msgin[1],
+			       hostdata->msgin[2]);
+			printk(KERN_ERR " OUTSTANDING TAGS:");
+			while(s != NULL) {
+				if(s->cmnd->target == reselection_id &&
+				   s->cmnd->lun == lun) {
+					printk("%d ", s->tag);

KERN_ERR?

2.4/drivers/scsi/53c700.c line 898

Quoted 2 lines
2.4/drivers/scsi/53c700.c new file +2 -0
+					if(s->tag == hostdata->msgin[2]) {
+						printk(" ***FOUND*** \n");

As above.

2.4/drivers/scsi/53c700.c line 906

Quoted 8 lines
2.4/drivers/scsi/53c700.c new file +8 -0
+						slot = s;
+						goto retry;
+					}
+						
+				}
+				s = s->ITL_back;
+			}
+			printk("\n");

KERN_ERR?

[...]

Quoted 3 lines
2.4/drivers/scsi/53c700.c new file +3 -0
+void
+NCR_700_intr(int irq, void *dev_id, struct pt_regs *regs)
+{

[...]

2.4/drivers/scsi/53c700.c line 1313

Quoted 7 lines
2.4/drivers/scsi/53c700.c new file +7 -0
+			if(dsp == Ent_SendMessage + 8 + hostdata->pScript) {
+				/* It wants to reply to some part of
+				 * our message */
+				__u32 temp = inl(host->base + TEMP_REG);
+
+				int count = (hostdata->script[Ent_SendMessage/4] & 0xffffff) - ((inl(host->base + DBC_REG) & 0xffffff) + NCR_700_data_residual(host));
+				printk("scsi%d (%d:%d) PHASE MISMATCH IN SEND MESSAGE %d remain, return %p[%04x], phase %s\n", host->host_no, pun, lun, count, (void *)temp, temp - hostdata->pScript, sbcl_to_string(inb(host->base + SBCL_REG)));

KERN_ERR?

Also, some places you have KERN_ERR on debug output and some places not. If you could be persuaded to put KERN_XX on the debug output too, it would be nice (but not crucial).

[...]

2.4/drivers/scsi/53c700.c line 1687

Quoted 10 lines
2.4/drivers/scsi/53c700.c new file +10 -0
+
+STATIC int
+NCR_700_abort(Scsi_Cmnd * SCp)
+{
+	struct NCR_700_command_slot *slot;
+	struct NCR_700_Host_Parameters *hostdata = 
+		(struct NCR_700_Host_Parameters *)SCp->host->hostdata[0];
+
+	printk("scsi%d (%d:%d) New error handler wants to abort command\n\t",
+	       SCp->host->host_no, SCp->target, SCp->lun);

KERN_XX?

[...]

2.4/drivers/scsi/53c700.c line 1719

Quoted 6 lines
2.4/drivers/scsi/53c700.c new file +6 -0
+
+STATIC int
+NCR_700_bus_reset(Scsi_Cmnd * SCp)
+{
+	printk("scsi%d (%d:%d) New error handler wants BUS reset, cmd %p\n\t",
+	       SCp->host->host_no, SCp->target, SCp->lun, SCp);

KERN_XX?

2.4/drivers/scsi/53c700.c line 1729

Quoted 10 lines
2.4/drivers/scsi/53c700.c new file +10 -0
+	print_command(SCp->cmnd);
+	NCR_700_internal_bus_reset(SCp->host);
+	return SUCCESS;
+}
+
+STATIC int
+NCR_700_dev_reset(Scsi_Cmnd * SCp)
+{
+	printk("scsi%d (%d:%d) New error handler wants device reset\n\t",
+	       SCp->host->host_no, SCp->target, SCp->lun);

KERN_XX?

2.4/drivers/scsi/53c700.c line 1739

Quoted 10 lines
2.4/drivers/scsi/53c700.c new file +10 -0
+	print_command(SCp->cmnd);
+	
+	return FAILED;
+}
+
+STATIC int
+NCR_700_host_reset(Scsi_Cmnd * SCp)
+{
+	printk("scsi%d (%d:%d) New error handler wants HOST reset\n\t",
+	       SCp->host->host_no, SCp->target, SCp->lun);

KERN_XX?

2.4/drivers/scsi/53c700.c line 1745

Quoted 6 lines
2.4/drivers/scsi/53c700.c new file +6 -0
+	print_command(SCp->cmnd);
+
+	NCR_700_internal_bus_reset(SCp->host);
+	NCR_700_chip_reset(SCp->host);
+	return SUCCESS;
+}

[...]
+STATIC int __init
+D700_detect(Scsi_Host_Template *tpnt)
+{

+       int slot = 0;
+       int found = 0;
+       int differential;
+       int banner = 1;

[...]
+ if(hostdata == NULL) {
+ printk(KERN_ERR "NCR D700: Failed to allocate
+host data for channel %d, detatching\n", i);
+ continue;
+ }
+ memset(hostdata, 0, sizeof(struct
+NCR_700_Host_Parameters));
+ request_region(region, 64, "NCR_D700");

Would you be kind enough to check the return code of the request_region?

+                       /* Fill in the three required pieces of hostdata */
+                       hostdata->base = region;
+                       hostdata->differential = (((1<<i) & differential) != 0);+                       hostdata->clock = NCR_D700_CLOCK_MHZ;
+                       /* and register the chip */
+                       if((host = NCR_700_detect(tpnt, hostdata)) == NULL) {

+ kfree(hostdata);
+ continue;
+ }

...and to release it in your error paths?

+                       host->irq = irq;
+                       /* FIXME: Read this from SUS */
+                       host->this_id = id_array[slot * 2 + i];
+                       printk(KERN_NOTICE "NCR D700: SIOP%d, SCSI id is %d\n",

+ i, host->this_id);
+ if(request_irq(irq, NCR_700_intr, SA_SHIRQ, "NCR_D700",
+host)) {
+ printk(KERN_ERR "NCR D700, channel %d: irq
+problem, detatching\n", i);

+                               NCR_700_release(host);
+                               release_region(host->base, 64);
+                               continue;

+ }

You need to kfree(hostdata) here. I would also recommend putting a scsi_unregister into NCR_700_release since you need to balance the scsi_register done in NCR_700_detect.

I recommend using forward gotos in your error paths for sanity. There can be used with loops&continues as well and will help you not have these resource leaks (across local scope anyway) since you have two function exit points: The normal one and the error one (you can collapse these to one exit path if you care strongly about this).

Signature · 5 lines
Regards,
        Rasmus([email protected])

Which is worse: Ignorance or Apathy?
Who knows? Who cares?
#2 lore raw

I've implemented most of these as you suggest, with these exceptions:

Quoted 9 lines

2.4/drivers/scsi/53c700.c line 691

Quoted 6 lines
2.4/drivers/scsi/53c700.c new file +6 -0
+	default:
+		printk(KERN_INFO "scsi%d (%d:%d): Unexpected message %s: ",
+		       host->host_no, pun, lun,
+		       NCR_700_phase[(dsps & 0xf00) >> 8]);
+		print_msg(hostdata->msgin);
+		printk("\n");

It would be nice with a KERN_XX before "\n" (yes, I recognize that print_msg does not do this :( )

The KERN_XX only go at the beginning of an output line (otherwise you see rather annoying <n> embedded in the log---the smc-mca driver has a hugely irritating example of this). print_msg doesn't do a carriage return by itself, so these three prints are really only one line (and hence all done under the KERN_INFO).

The "OUTSTANDING TAGS.." message is another one of these---it prints a list of tags all on one line.

Quoted 9 lines · [email protected] said:
2.4/drivers/scsi/NCR_D700.c new file +8 -0
+                       if(request_irq(irq, NCR_700_intr, SA_SHIRQ, "NCR_D700",
+host)) {
+                               printk(KERN_ERR "NCR D700, channel %d: irq
+problem, detatching\n", i);
+                               NCR_700_release(host);
+                               release_region(host->base, 64);
+                               continue;
+                       }
Quoted 3 lines

You need to kfree(hostdata) here. I would also recommend putting a scsi_unregister into NCR_700_release since you need to balance the scsi_register done in NCR_700_detect.

Actually, I need to remove the release_region here (since it's done in NCR_700_release) and add a scsi_unregister.

There's no need to do a scsi_unregister in _release; scsi_unregister is only really used to tell the mid layer to relinquish a host after an error. In _release, the mid layer is telling you that it has released the host and we need to clean up.

Thanks for the updates, I'll post another patch once I've got a few other people's suggestions rolled in.

James