From: Brian King <brking@us.ibm.com>
To: brking@us.ibm.com
Cc: linux-ide@vger.kernel.org
Subject: [RFC 2/2] libata: support SATA devices on SAS HBAs
Date: Mon, 03 Oct 2005 16:58:49 -0500 [thread overview]
Message-ID: <4341A999.3030807@us.ibm.com> (raw)
In-Reply-To: <4341A91A.3020000@us.ibm.com>
[-- Attachment #1: Type: text/plain, Size: 0 bytes --]
[-- Attachment #2: libata_sas.patch --]
[-- Type: text/plain, Size: 12553 bytes --]
The following patch enhances libata to allow SAS device drivers
to utilize libata to talk to SATA devices. It introduces some
new APIs which allow libata to be used without allocating a
virtual scsi host. This is just a snapshot of what I've
come up with at this point and I figured I would post it to
see if I was heading in a reasonable direction or not, so
don't expect the code below to do anything useful at this point
as it is untested.
New APIs:
ata_sas_port_alloc - Allocate an ata_port
ata_sas_port_init - Initialize an ata_port (probe bus, etc)
ata_sas_port_destroy - Free an ata_port allocated by ata_sas_port_alloc
ata_sas_slave_configure - configure scsi device
ata_sas_queuecmd - queue a scsi command, similar to ata_scsi_queuecomand
These new APIs can be used either directly by a SAS LLDD or could be used
by the SAS transport class.
Possible usage for a SAS LLDD would be:
scsi_scan_host
slave_alloc
ata_sas_port_alloc
ata_sas_port_init
slave_configure
ata_sas_slave_configure
Commands received by the LLDD for SATA devices would call ata_sas_queuecmd.
Device teardown would occur with:
slave_destroy
ata_sas_port_destroy
Signed-off-by: Brian King <brking@us.ibm.com>
---
linux-2.6-bjking1/drivers/scsi/libata-core.c | 32 ++--
linux-2.6-bjking1/drivers/scsi/libata-scsi.c | 213 +++++++++++++++++++++++----
linux-2.6-bjking1/drivers/scsi/libata.h | 7
linux-2.6-bjking1/include/linux/libata.h | 8 +
4 files changed, 222 insertions(+), 38 deletions(-)
diff -puN drivers/scsi/libata-scsi.c~libata_sas drivers/scsi/libata-scsi.c
--- linux-2.6/drivers/scsi/libata-scsi.c~libata_sas 2005-09-26 14:23:01.000000000 -0500
+++ linux-2.6-bjking1/drivers/scsi/libata-scsi.c 2005-09-26 14:23:01.000000000 -0500
@@ -325,6 +325,30 @@ void ata_to_sense_error(struct ata_queue
}
}
+static void ata_scsi_sdev_config(struct scsi_device *sdev)
+{
+ sdev->use_10_for_rw = 1;
+ sdev->use_10_for_ms = 1;
+}
+
+static void ata_scsi_dev_config(struct scsi_device *sdev,
+ struct ata_device *dev)
+{
+ /* TODO: 1024 is an arbitrary number, not the
+ * hardware maximum. This should be increased to
+ * 65534 when Jens Axboe's patch for dynamically
+ * determining max_sectors is merged.
+ */
+ if ((dev->flags & ATA_DFLAG_LBA48) &&
+ ((dev->flags & ATA_DFLAG_LOCK_SECTORS) == 0)) {
+ /*
+ * do not overwrite sdev->host->max_sectors, since
+ * other drives on this host may not support LBA48
+ */
+ blk_queue_max_sectors(sdev->request_queue, 2048);
+ }
+}
+
/**
* ata_scsi_slave_config - Set SCSI device attributes
* @sdev: SCSI device to examine
@@ -339,9 +363,7 @@ void ata_to_sense_error(struct ata_queue
int ata_scsi_slave_config(struct scsi_device *sdev)
{
- sdev->use_10_for_rw = 1;
- sdev->use_10_for_ms = 1;
-
+ ata_scsi_sdev_config(sdev);
blk_queue_max_phys_segments(sdev->request_queue, LIBATA_MAX_PRD);
if (sdev->id < ATA_MAX_DEVICES) {
@@ -351,19 +373,7 @@ int ata_scsi_slave_config(struct scsi_de
ap = (struct ata_port *) &sdev->host->hostdata[0];
dev = &ap->device[sdev->id];
- /* TODO: 1024 is an arbitrary number, not the
- * hardware maximum. This should be increased to
- * 65534 when Jens Axboe's patch for dynamically
- * determining max_sectors is merged.
- */
- if ((dev->flags & ATA_DFLAG_LBA48) &&
- ((dev->flags & ATA_DFLAG_LOCK_SECTORS) == 0)) {
- /*
- * do not overwrite sdev->host->max_sectors, since
- * other drives on this host may not support LBA48
- */
- blk_queue_max_sectors(sdev->request_queue, 2048);
- }
+ ata_scsi_dev_config(sdev, dev);
}
return 0; /* scsi layer doesn't check return value, sigh */
@@ -1541,6 +1551,21 @@ static inline void ata_scsi_dump_cdb(str
#endif
}
+static void __ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *),
+ struct ata_port *ap, struct ata_device *dev)
+{
+ if (dev->class == ATA_DEV_ATA) {
+ ata_xlat_func_t xlat_func = ata_get_xlat_func(dev,
+ cmd->cmnd[0]);
+
+ if (xlat_func)
+ ata_scsi_translate(ap, dev, cmd, done, xlat_func);
+ else
+ ata_scsi_simulate(dev->id, cmd, done);
+ } else
+ ata_scsi_translate(ap, dev, cmd, done, atapi_xlat);
+}
+
/**
* ata_scsi_queuecmd - Issue SCSI cdb to libata-managed device
* @cmd: SCSI command to be sent
@@ -1577,16 +1602,7 @@ int ata_scsi_queuecmd(struct scsi_cmnd *
goto out_unlock;
}
- if (dev->class == ATA_DEV_ATA) {
- ata_xlat_func_t xlat_func = ata_get_xlat_func(dev,
- cmd->cmnd[0]);
-
- if (xlat_func)
- ata_scsi_translate(ap, dev, cmd, done, xlat_func);
- else
- ata_scsi_simulate(dev->id, cmd, done);
- } else
- ata_scsi_translate(ap, dev, cmd, done, atapi_xlat);
+ __ata_scsi_queuecmd(cmd, done, ap, dev);
out_unlock:
return 0;
@@ -1678,3 +1694,148 @@ void ata_scsi_simulate(u16 *id,
}
}
+/**
+ * ata_sas_port_alloc - Allocate port for a SAS attached SATA device
+ * @sdev: SCSI device to allocate port for
+ * @pdev: PCI device that the scsi device is attached to
+ * @port_info: Information from low-level host driver
+ *
+ * LOCKING:
+ * PCI/etc. bus probe sem.
+ *
+ * RETURNS:
+ * ata_port pointer on success / NULL on failure.
+ */
+
+struct ata_port *ata_sas_port_alloc(struct scsi_device *sdev,
+ struct pci_dev *pdev,
+ struct ata_port_info *port_info)
+{
+ struct ata_port *ap = kzalloc(sizeof(*ap) + sizeof(void *), GFP_KERNEL);
+ struct ata_host_set *host_set = kzalloc(sizeof(*host_set), GFP_KERNEL);
+
+ if (!ap || !host_set) {
+ kfree(ap);
+ kfree(host_set);
+ return NULL;
+ }
+
+ host_set->dev = &pdev->dev;
+ host_set->n_ports = 1;
+ host_set->ops = port_info->port_ops;
+ host_set->ports[0] = ap;
+ ata_assign_lock(host_set, sdev->host->host_lock);
+
+ ap->host_set = host_set;
+ ap->ops = port_info->port_ops;
+ ap->flags = port_info->host_flags;
+ ap->pio_mask = port_info->pio_mask;
+ ap->mwdma_mask = port_info->mwdma_mask;
+ ap->udma_mask = port_info->udma_mask;
+ ap->cbl = ATA_CBL_SATA;
+ ap->active_tag = ATA_TAG_POISON;
+ ap->last_ctl = 0xFF;
+ return ap;
+}
+EXPORT_SYMBOL_GPL(ata_sas_port_alloc);
+
+static void ata_sas_port_free(struct ata_port *ap)
+{
+ kfree(ap->host_set);
+ kfree(ap);
+}
+
+/**
+ * ata_sas_port_init - Initialize a SATA device
+ * @ap: SATA port to initialize
+ *
+ * LOCKING:
+ * PCI/etc. bus probe sem.
+ *
+ * RETURNS:
+ * Zero on success, non-zero on error.
+ */
+
+int ata_sas_port_init(struct ata_port *ap)
+{
+ int rc = ap->ops->port_start(ap);
+
+ if (!rc)
+ rc = ata_bus_probe(ap);
+
+ return rc;
+}
+EXPORT_SYMBOL_GPL(ata_sas_port_init);
+
+/**
+ * ata_sas_port_destroy - Destroy a SATA port allocated by ata_sas_port_alloc
+ * @ap: SATA port to destroy
+ *
+ * LOCKING:
+ * spin_lock_irqsave(host_set lock)
+ *
+ */
+
+void ata_sas_port_destroy(struct ata_port *ap)
+{
+ if (ap) {
+ ap->ops->port_stop(ap);
+ ata_sas_port_free(ap);
+ }
+}
+EXPORT_SYMBOL_GPL(ata_sas_port_destroy);
+
+/**
+ * ata_sas_slave_configure - Default slave_config routine for libata devices
+ * @sdev: SCSI device to configure
+ * @ap: ATA port to which SCSI device is attached
+ *
+ * LOCKING:
+ * spin_lock_irqsave(host_set lock)
+ *
+ * RETURNS:
+ * Zero.
+ */
+
+int ata_sas_slave_configure(struct scsi_device *sdev, struct ata_port *ap)
+{
+ ata_scsi_sdev_config(sdev);
+ ata_scsi_dev_config(sdev, ap->device);
+ if (ata_dev_knobble(ap))
+ blk_queue_max_sectors(sdev->request_queue, ATA_MAX_SECTORS);
+ return 0;
+}
+EXPORT_SYMBOL_GPL(ata_sas_slave_configure);
+
+/**
+ * ata_sas_queuecmd - Issue SCSI cdb to libata-managed device
+ * @cmd: SCSI command to be sent
+ * @done: Completion function, called when command is complete
+ * @ap: ATA port to which the command is being sent
+ *
+ * LOCKING:
+ * spin_lock_irqsave(host_set lock)
+ *
+ * RETURNS:
+ * Zero.
+ */
+
+int ata_sas_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *),
+ struct ata_port *ap)
+{
+ if (unlikely(!ata_dev_present(ap->device))) {
+ cmd->result = (DID_BAD_TARGET << 16);
+ done(cmd);
+ return 0;
+ }
+
+ if (cmd->cmd_len > ap->cdb_len) {
+ cmd->result = (DID_ABORT << 16);
+ done(cmd);
+ return 0;
+ }
+
+ __ata_scsi_queuecmd(cmd, done, ap, ap->device);
+ return 0;
+}
+EXPORT_SYMBOL_GPL(ata_sas_queuecmd);
diff -puN drivers/scsi/libata-core.c~libata_sas drivers/scsi/libata-core.c
--- linux-2.6/drivers/scsi/libata-core.c~libata_sas 2005-09-26 14:23:01.000000000 -0500
+++ linux-2.6-bjking1/drivers/scsi/libata-core.c 2005-09-26 14:23:01.000000000 -0500
@@ -1106,6 +1106,21 @@ static inline void ata_dump_id(struct at
dev->id[93]);
}
+static void ata_set_cdb_len(struct ata_port *ap, unsigned int cdb_len)
+{
+ ap->cdb_len = cdb_len;
+ if (ap->host)
+ ap->host->max_cmd_len = cdb_len;
+}
+
+static void ata_set_max_sectors(struct ata_port *ap, unsigned int max_sectors)
+{
+ if (ap->host) {
+ ap->host->max_sectors = ATA_MAX_SECTORS;
+ ap->host->hostt->max_sectors = ATA_MAX_SECTORS;
+ }
+}
+
/**
* ata_dev_identify - obtain IDENTIFY x DEVICE page
* @ap: port on which device we wish to probe resides
@@ -1269,7 +1284,7 @@ retry:
dev->n_sectors = ata_id_u32(dev->id, 60);
}
- ap->host->max_cmd_len = 16;
+ ata_set_cdb_len(ap, 16);
/* print device info to dmesg */
printk(KERN_INFO "ata%u: dev %u ATA, max %s, %Lu sectors:%s\n",
@@ -1289,8 +1304,8 @@ retry:
printk(KERN_WARNING "ata%u: unsupported CDB len\n", ap->id);
goto err_out_nosup;
}
- ap->cdb_len = (unsigned int) rc;
- ap->host->max_cmd_len = (unsigned char) ap->cdb_len;
+
+ ata_set_cdb_len(ap, rc);
/* print device info to dmesg */
printk(KERN_INFO "ata%u: dev %u ATAPI, max %s\n",
@@ -1309,12 +1324,6 @@ err_out:
DPRINTK("EXIT, err\n");
}
-
-static inline u8 ata_dev_knobble(struct ata_port *ap)
-{
- return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(ap->device->id)));
-}
-
/**
* ata_dev_config - Run device specific handlers and check for
* SATA->PATA bridges
@@ -1331,8 +1340,7 @@ void ata_dev_config(struct ata_port *ap,
printk(KERN_INFO "ata%u(%u): applying bridge limits\n",
ap->id, ap->device->devno);
ap->udma_mask &= ATA_UDMA5;
- ap->host->max_sectors = ATA_MAX_SECTORS;
- ap->host->hostt->max_sectors = ATA_MAX_SECTORS;
+ ata_set_max_sectors(ap, ATA_MAX_SECTORS);
ap->device->flags |= ATA_DFLAG_LOCK_SECTORS;
}
@@ -1355,7 +1363,7 @@ void ata_dev_config(struct ata_port *ap,
* Zero on success, non-zero on error.
*/
-static int ata_bus_probe(struct ata_port *ap)
+int ata_bus_probe(struct ata_port *ap)
{
unsigned int i, found = 0;
diff -puN drivers/scsi/libata.h~libata_sas drivers/scsi/libata.h
--- linux-2.6/drivers/scsi/libata.h~libata_sas 2005-09-26 14:23:01.000000000 -0500
+++ linux-2.6-bjking1/drivers/scsi/libata.h 2005-09-26 14:23:01.000000000 -0500
@@ -79,6 +79,8 @@ extern void ata_scsi_badcmd(struct scsi_
extern void ata_scsi_rbuf_fill(struct ata_scsi_args *args,
unsigned int (*actor) (struct ata_scsi_args *args,
u8 *rbuf, unsigned int buflen));
+extern int ata_bus_probe(struct ata_port *ap);
+extern int ata_sas_port_init(struct ata_port *ap);
static inline void ata_bad_scsiop(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
{
@@ -90,4 +92,9 @@ static inline void ata_bad_cdb(struct sc
ata_scsi_badcmd(cmd, done, 0x24, 0x00);
}
+static inline u8 ata_dev_knobble(struct ata_port *ap)
+{
+ return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(ap->device->id)));
+}
+
#endif /* __LIBATA_H__ */
diff -puN include/linux/libata.h~libata_sas include/linux/libata.h
--- linux-2.6/include/linux/libata.h~libata_sas 2005-09-26 14:23:01.000000000 -0500
+++ linux-2.6-bjking1/include/linux/libata.h 2005-09-26 14:23:01.000000000 -0500
@@ -400,6 +400,14 @@ extern int ata_scsi_ioctl(struct scsi_de
extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *));
extern int ata_scsi_error(struct Scsi_Host *host);
extern int ata_scsi_release(struct Scsi_Host *host);
+extern void ata_sas_port_destroy(struct ata_port *ap);
+extern struct ata_port *ata_sas_port_alloc(struct scsi_device *sdev,
+ struct pci_dev *pdev,
+ struct ata_port_info *port_info);
+extern int ata_sas_port_init(struct ata_port *ap);
+extern int ata_sas_slave_configure(struct scsi_device *sdev, struct ata_port *ap);
+extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *),
+ struct ata_port *ap);
extern unsigned int ata_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc);
/*
* Default driver ops implementations
_
next prev parent reply other threads:[~2005-10-03 21:58 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-03 21:56 [RFC 0/2] libata: support SATA devices on SAS HBAs Brian King
2005-10-03 21:58 ` [RFC 1/2] libata: configurable host_set lock Brian King
2005-10-03 21:58 ` Brian King [this message]
2005-10-04 9:56 ` [RFC 0/2] libata: support SATA devices on SAS HBAs Jeff Garzik
2005-10-04 10:22 ` Bartlomiej Zolnierkiewicz
2005-10-04 20:56 ` Bartlomiej Zolnierkiewicz
2005-10-05 20:59 ` Jeff Garzik
2005-10-24 22:17 ` [PATCH " Brian King
2005-10-24 22:19 ` [PATCH 1/2] libata: Remove dependence on host_set->dev for SAS Brian King
2005-10-25 17:53 ` Jeff Garzik
2005-10-25 19:30 ` Brian King
2005-10-25 19:43 ` Jeff Garzik
2005-10-25 22:48 ` Luben Tuikov
2005-10-27 16:05 ` Brian King
2005-10-27 20:15 ` Luben Tuikov
2005-11-24 0:53 ` Douglas Gilbert
2005-11-24 1:07 ` Jeff Garzik
2005-11-24 8:12 ` Bartlomiej Zolnierkiewicz
2005-12-02 2:05 ` Jeff Garzik
2005-12-02 8:07 ` Bartlomiej Zolnierkiewicz
2005-12-02 10:28 ` Douglas Gilbert
2005-12-02 10:48 ` Jeff Garzik
2005-11-29 22:13 ` Brian King
2005-10-24 22:20 ` [PATCH 2/2] libata: Add support for SATA attachment to SAS adapters Brian King
2005-10-25 17:58 ` Jeff Garzik
2005-10-25 12:59 ` [PATCH 0/2] libata: support SATA devices on SAS HBAs Luben Tuikov
2005-10-25 13:39 ` Brian King
2005-10-25 13:40 ` Luben Tuikov
2005-10-25 13:53 ` Brian King
2005-10-25 14:08 ` Luben Tuikov
2005-10-25 14:27 ` Brian King
2005-10-25 17:51 ` Jeff Garzik
2005-10-25 17:57 ` [RFC " Brian King
2005-10-25 18:07 ` Jeff Garzik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4341A999.3030807@us.ibm.com \
--to=brking@us.ibm.com \
--cc=linux-ide@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).