Skip to contentSkip to conversation

Promise 'stex' driver

PATCH In review Jeff Garzik 4 participants 13 messages Jun 10, 2006 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Promise 'stex' driver

Please review, and queue in scsi-misc for 2.6.18 if acceptable.

The 'stex' branch of
git://git.kernel.org/pub/scm/linux/kernel/git/jgarzik/misc-2.6.git

contains the following updates:

 drivers/scsi/Kconfig  |    7 
 drivers/scsi/Makefile |    1 
 drivers/scsi/stex.c   | 1219 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1227 insertions(+)

Jeff Garzik:
[SCSI] Add Promise SuperTrak 'shasta' driver.
Rename drivers/scsi/shasta.c to stex.c ("SuperTrak EX"). [SCSI] stex: update with community comments from 'Promise SuperTrak' thread [SCSI] stex: Fix warning, trim trailing whitespace.
[SCSI] stex: remove last remnants of "shasta" project code name

drivers/scsi/Kconfig +7 -0
index a480a37..5ead499 100644
@@ -1043,6 +1043,13 @@ config 53C700_LE_ON_BE
 	depends on SCSI_LASI700
 	default y
 
+config SCSI_STEX
+	tristate "Promise SuperTrak EX8350/8300/16350/16300 support"
+	depends on PCI && SCSI
+	---help---
+	  This driver supports Promise SuperTrak EX8350/8300/16350/16300
+	  Storage controllers.
+
 config SCSI_SYM53C8XX_2
 	tristate "SYM53C8XX Version 2 SCSI support"
 	depends on PCI && SCSI
drivers/scsi/Makefile +1 -0
index 81803a1..6a382e5 100644
@@ -121,6 +121,7 @@ obj-$(CONFIG_SCSI_LASI700)	+= 53c700.o l
 obj-$(CONFIG_SCSI_NSP32)	+= nsp32.o
 obj-$(CONFIG_SCSI_IPR)		+= ipr.o
 obj-$(CONFIG_SCSI_IBMVSCSI)	+= ibmvscsi/
+obj-$(CONFIG_SCSI_STEX)		+= stex.o
 obj-$(CONFIG_SCSI_SATA_AHCI)	+= libata.o ahci.o
 obj-$(CONFIG_SCSI_SATA_SVW)	+= libata.o sata_svw.o
 obj-$(CONFIG_SCSI_ATA_PIIX)	+= libata.o ata_piix.o
drivers/scsi/stex.c new file +1219 -0

1,219 lines not on this page · raw message

#1 lore raw
Quoted 2 lines · Jeff Garzik

Please review, and queue in scsi-misc for 2.6.18 if acceptable.

The driver is not for scsi hardware. Please implement it as block driver.

#2 lore raw
Quoted 5 lines · Christoph Hellwig
Quoted 1 line · Jeff Garzik

Please review, and queue in scsi-misc for 2.6.18 if acceptable.

The driver is not for scsi hardware. Please implement it as block driver.

That's a new requirement. The interface to the hardware is clearly SCSI.

Jeff

#3 lore raw
In reply to Christoph Hellwig
Quoted 2 lines · Christoph Hellwig

The driver is not for scsi hardware. Please implement it as block driver.

Actually, I'm afraid it is ... look at the mailbox path ... it's one of these increasingly prevalent raid HBAs that speaks SCSI at the firmware level. Most commands are direct passthroughs, only INQUIRY and MODE_SENSE are actually emulated in the driver.

James

#4 lore raw
Quoted 8 lines · James Bottomley
Quoted 2 lines · Christoph Hellwig

The driver is not for scsi hardware. Please implement it as block driver.

Actually, I'm afraid it is ... look at the mailbox path ... it's one of these increasingly prevalent raid HBAs that speaks SCSI at the firmware level. Most commands are direct passthroughs, only INQUIRY and MODE_SENSE are actually emulated in the driver.

Oops, you're right. It emulates READ/WRITE6 at the top of the queuecommand routine which made me thing it'll emulate more below.

So removing the READ/WRITE6 emulation and setting the flag so the midlayer only uses READ/WRITE10+ is on top of the TODO list. Right after that is using the scsi_kmap_atomic_sg/scsi_kunmap_atomic_sg for the remaining emulated commands. More comments later.

#5 lore raw
Quoted 2 lines · Christoph Hellwig

So removing the READ/WRITE6 emulation and setting the flag so the midlayer only uses READ/WRITE10+ is on top of the TODO list. Right after that is

Done and checked into 'stex' branch at URL given. I also removed 6-byte MODE SENSE.

Quoted 2 lines

using the scsi_kmap_atomic_sg/scsi_kunmap_atomic_sg for the remaining emulated commands. More comments later.

These functions don't appear to be in upstream yet.

Jeff

#6 lore raw
Quoted 4 lines · Jeff Garzik
Quoted 2 lines

using the scsi_kmap_atomic_sg/scsi_kunmap_atomic_sg for the remaining emulated commands. More comments later.

These functions don't appear to be in upstream yet.

It's in scsi-misc, against which new scsi drivers should be submitted. It's fine if you delay that conversion and non-sg path removal until you send it to James for scsi-misc.

#7 lore raw
In reply to Jeff Garzik
Quoted 1 line

+#include <linux/config.h>

including config.h isn't needed anymore.

Quoted 1 line

+enum{

enum {

drivers/scsi/stex.c line 314

Quoted 8 lines
drivers/scsi/stex.c new file +8 -0
+static inline u16 stex_alloc_tag(unsigned long *bitmap)
+{
+	int i;
+	i = find_first_zero_bit(bitmap, TAG_BITMAP_LENGTH);
+	if (i < TAG_BITMAP_LENGTH)
+		__set_bit(i, bitmap);
+	return (u16)i;
+}

Please use the block layer tag helpers from block/ll_rw_blk.c:

extern int blk_queue_start_tag(request_queue_t *, struct request *); extern struct request *blk_queue_find_tag(request_queue_t *, int); extern void blk_queue_end_tag(request_queue_t *, struct request *); extern int blk_queue_init_tags(request_queue_t *, int, struct blk_queue_tag *); extern void blk_queue_free_tags(request_queue_t *);
extern int blk_queue_resize_tags(request_queue_t *, int);
extern void blk_queue_invalidate_tags(request_queue_t *);

Quoted 1 line

+static inline struct req_msg *stex_alloc_req(struct st_hba *hba)

There's far too many inline functions here. In doubt I'd just remove all the inline attributes and let the copiler handle it. Given the functions in the driver are already in natural order even a current gcc will do a pretty good job at that.

drivers/scsi/stex.c line 359

Quoted 5 lines
drivers/scsi/stex.c new file +5 -0
+
+	if (cmd->use_sg) {
+		src = (struct scatterlist *) cmd->request_buffer;
+		dst->sg_count = cpu_to_le16((u16)pci_map_sg(pdev, src,
+			cmd->use_sg, cmd->sc_data_direction));

You need to handle an error return from pci_map_sg and bail out if it returns zero segments.

drivers/scsi/stex.c line 375

Quoted 6 lines
drivers/scsi/stex.c new file +6 -0
+		dst->table[--i].ctrl |= SG_CF_EOT;
+		return;
+	}
+	dma_handle = pci_map_single(pdev, cmd->request_buffer,
+		cmd->request_bufflen, cmd->sc_data_direction);
+	cmd->SCp.dma_handle = dma_handle;

I've just posted a patch to kill the last non-sg codepath so this should't be needed anymore.

Quoted 10 lines
drivers/scsi/stex.c new file +10 -0
+static int stex_direct_cp(struct scsi_cmnd *cmd,
+	const void *src, unsigned int len)
+{
+	void *dest;
+	unsigned int cp_len;
+	struct scatterlist *sg = cmd->request_buffer;
+
+	if (cmd->use_sg) {
+		dest = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
+		cp_len = min(sg->length, len);

drivers/scsi/stex.c line 403

Quoted 10 lines
drivers/scsi/stex.c new file +10 -0
+	} else {
+		dest = cmd->request_buffer;
+		cp_len = min(cmd->request_bufflen, len);
+	}
+
+	memcpy(dest, src, cp_len);
+
+	if (cmd->use_sg)
+		kunmap_atomic(dest - sg->offset, KM_IRQ0);
+	return cp_len == len;

As mentioned before this should use scsi_kmap_atomic_sg/scsi_kunmap_atomic_sg.

drivers/scsi/stex.c line 454

Quoted 3 lines
drivers/scsi/stex.c new file +3 -0
+static int
+stex_queuecommand(struct scsi_cmnd *cmd, void (* fn)(struct scsi_cmnd *))
+{

The callback argument to ->queuecommand is called one in almost every driver. It would help to understand your driver more easily if it followed that convention.

drivers/scsi/stex.c line 462

Quoted 8 lines
drivers/scsi/stex.c new file +8 -0
+	struct st_hba *hba;
+	struct Scsi_Host *host;
+	unsigned int id,lun;
+	struct req_msg *req;
+	u16 tag;
+	host = cmd->device->host;
+	id = cmd->device->id;
+	lun = cmd->device->channel; /* firmware lun issue work around */

Please explain the firmware issue in more detail, this looks rather odd.

Quoted 6 lines
drivers/scsi/stex.c new file +6 -0
+	hba = (struct st_hba *) &host->hostdata[0];
+
+	switch (cmd->cmnd[0]) {
+	case READ_6:
+	case WRITE_6:
+		cmd->cmnd[9] = 0;

drivers/scsi/stex.c line 478

Quoted 10 lines
drivers/scsi/stex.c new file +10 -0
+		cmd->cmnd[8] = cmd->cmnd[4];
+		cmd->cmnd[7] = 0;
+		cmd->cmnd[6] = 0;
+		cmd->cmnd[5] = cmd->cmnd[3];
+		cmd->cmnd[4] = cmd->cmnd[2];
+		cmd->cmnd[3] = cmd->cmnd[1] & 0x1f;
+		cmd->cmnd[2] = 0;
+		cmd->cmnd[1] &= 0xe0;
+		cmd->cmnd[0] += READ_10 - READ_6;
+		break;

Please remove this emulation and set sdev->use_10_for_rw in ->slave_configure.

drivers/scsi/stex.c line 487

Quoted 9 lines
drivers/scsi/stex.c new file +9 -0
+	case MODE_SENSE:
+	{
+		static char mode_sense[4] = { 3, 0, 0, 0 };
+
+		stex_direct_cp(cmd, mode_sense, sizeof(mode_sense));
+		cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
+		fn(cmd);
+		return 0;
+	}

I'd kill this aswell and set use_10_for_ms in slave_configure.

Quoted 10 lines
drivers/scsi/stex.c new file +10 -0
+	case MODE_SENSE_10:
+	{
+		static char mode_sense10[8] = { 0, 6, 0, 0, 0, 0, 0, 0 };
+
+		stex_direct_cp(cmd, mode_sense10, sizeof(mode_sense10));
+		cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
+		fn(cmd);
+		return 0;
+	}
+	case INQUIRY:

drivers/scsi/stex.c line 507

Quoted 10 lines
drivers/scsi/stex.c new file +10 -0
+		if (id != ST_MAX_ARRAY_SUPPORTED || lun != 0)
+			break;
+		if((cmd->cmnd[1] & INQUIRY_EVPD) == 0) {
+			stex_direct_cp(cmd, console_inq_page,
+				sizeof(console_inq_page));
+			cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
+		} else
+			cmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
+		fn(cmd);
+		return 0;

I'd suggest to kill INQUIRY completely

Quoted 6 lines
drivers/scsi/stex.c new file +6 -0
+	case PASSTHRU_CMD:
+		if (cmd->cmnd[1] == PASSTHRU_GET_DRVVER) {
+			struct st_drvver ver;
+			ver.major = ST_VER_MAJOR;
+			ver.minor = ST_VER_MINOR;
+			ver.oem = ST_OEM;

drivers/scsi/stex.c line 523

Quoted 10 lines
drivers/scsi/stex.c new file +10 -0
+			ver.build = ST_BUILD_VER;
+			ver.signature[0] = PASSTHRU_SIGNATURE;
+			ver.console_id = ST_MAX_ARRAY_SUPPORTED;
+			ver.host_no = hba->host->host_no;
+			cmd->result = stex_direct_cp(cmd, &ver, sizeof(ver)) ?
+				DID_OK << 16 | COMMAND_COMPLETE << 8 :
+				DID_ERROR << 16 | COMMAND_COMPLETE << 8;
+			fn(cmd);
+			return 0;
+		}

Please don't abuse passthru commands to expose driver data. Add a few sysfs attributes instead respectively a MODULE_VERSION tag for the version.

drivers/scsi/stex.c line 552

Quoted 9 lines
drivers/scsi/stex.c new file +9 -0
+	hba->ccb[tag].cmd = cmd;
+	hba->ccb[tag].sense_bufflen = SCSI_SENSE_BUFFERSIZE;
+	hba->ccb[tag].sense_buffer = cmd->sense_buffer;
+	if (cmd->use_sg) {
+		hba->ccb[tag].page_offset =
+			((struct scatterlist *)cmd->request_buffer)->offset;
+		hba->ccb[tag].page =
+			((struct scatterlist *)cmd->request_buffer)->page;
+	}

How does this work? The driver claims to accept sg lists up to 32 entries but we only add the first here?

Quoted 3 lines
drivers/scsi/stex.c new file +3 -0
+static void stex_init_hba(struct st_hba *hba,
+	struct Scsi_Host * host, struct pci_dev *pdev)
+{

...

Quoted 4 lines
drivers/scsi/stex.c new file +4 -0
+}
+
+static int stex_init_shm(struct st_hba *hba, struct pci_dev *pdev)
+{

...

Quoted 1 line

+

Could you just merge these two functions into it's only caller so the initialization path is easier to read without hopping forth and back?

drivers/scsi/stex.c line 1098

Quoted 1 line
drivers/scsi/stex.c new file +1 -0
+	scsi_scan_host(host);

Any chance you could add the targets directly using scsi_add_device or scsi_scan_target instead of trying to emulate a SPI scanning sequence?

drivers/scsi/stex.c line 1158

Quoted 11 lines
drivers/scsi/stex.c new file +11 -0
+static void stex_hba_free(struct st_hba *hba)
+{
+	free_irq(hba->pdev->irq, hba);
+
+	iounmap(hba->mmio_base);
+
+	pci_release_regions(hba->pdev);
+
+	if (hba->dma_mem)
+		pci_free_consistent(hba->pdev, MU_BUFFER_SIZE,
+			hba->dma_mem, hba->dma_handle);

this check is not needed. stex_hba_free is never called with a NULL hba->dma_mem. I'd also merge this function into it's only caller, as that would increase readability.

Overall a very nice driver, thanks a lot!

#8 lore raw

Thanks, just did several of these and checked it into 'stex' branch.

commit 1b6f2a81e789ebef27107765656d425ab44a2f44

Author: Jeff Garzik <[email protected]>
Date:   Sat Jun 10 13:36:54 2006 -0400

[SCSI] stex: minor cleanups

- fix endian bug found in s/g code (used a fixed-endian value as a loop-terminating variable)

From a list of changes suggested by Christoph:

- don't include linux/config.h
- whitespace fix
- let compiler choose whether or not to inline
- eliminate unnecessary NULL test on hba->dma_mem
- handle pci_map_sg() error

#9 lore raw
Quoted 1 line · Jeff Garzik

Thanks, just did several of these and checked it into 'stex' branch.

You forgot to attach the diff.

Thanks,

James

#10 lore raw
Quoted 4 lines · James Bottomley
Quoted 1 line · Jeff Garzik

Thanks, just did several of these and checked it into 'stex' branch.

You forgot to attach the diff.

No, I'm just waiting for further comments, rather than posting a diff for each comment.

The diff is public if people want to grab it.

Jeff

#11 lore raw
In reply to Christoph Hellwig
Quoted 2 lines · Christoph Hellwig

I've just posted a patch to kill the last non-sg codepath so this should't be needed anymore.

BTW, thanks for this. This will allow me to kill some libata-scsi code.

Jeff

#12 lore raw
In reply to Jeff Garzik

drivers/scsi/stex.c

Quoted 4 lines · Jeff Garzik
drivers/scsi/stex.c new file +1 -0
 
+static inline void stex_gettime(u32 *time)

__le32 *time

Quoted 5 lines
drivers/scsi/stex.c new file +5 -0
+{
+	struct timeval tv;
+	do_gettimeofday(&tv);
+
+	*time = cpu_to_le32(tv.tv_sec & 0xffffffff);

drivers/scsi/stex.c

Quoted 10 lines
drivers/scsi/stex.c new file +9 -0
+	*(time + 1) = cpu_to_le32((tv.tv_sec >> 16) >> 16);
+}
 
+static void
+stex_send_cmd(struct st_hba *hba, struct req_msg *req, u16 tag)
+{
+	req->tag = cpu_to_le16(tag);
+	req->task_attr = TASK_ATTRIBUTE_SIMPLE;
+	req->task_manage = 0; /* not supported yet */
+	req->payload_sz = (u8)(sizeof(struct req_msg)/sizeof(u32));

sparse warns here. Is this OK?

drivers/scsi/stex.c:442:47: warning: cast truncates bits from constant value (106 becomes 6)