libata: support SATA devices on SAS HBAs
Subsystems (3)
Brian King
maintainercover libata: support SATA devices on SAS HBAs
The following patches enhance 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_portata_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
Signature · 3 lines
Brian King eServer Storage I/O IBM Linux Technology Center
Brian King
maintainerRFC 1/2 libata: configurable host_set lock
Allow the spinlock used by libata to be overridden.
---
linux-2.6-bjking1/drivers/scsi/libata-core.c | 41 +++++++++++++-------------- linux-2.6-bjking1/include/linux/libata.h | 8 ++++- 2 files changed, 28 insertions(+), 21 deletions(-)
include/linux/libata.h renamed from include/linux/libata.h~libata_lock_change +7 -1
@@ -214,7 +214,8 @@ struct ata_probe_ent { };struct ata_host_set { -spinlock_t lock; +spinlock_t *lock; +spinlock_t default_lock;struct device *dev;unsigned long irq;void __iomem *mmio_base;
@@ -669,4 +670,9 @@ static inline int ata_try_flush_cache(st ata_id_has_flush_ext(dev->id); } +static inline void ata_assign_lock (struct ata_host_set *host_set,spinlock_t *lock) +{ + host_set->lock = lock; +} +#endif /* __LINUX_LIBATA_H__ */
drivers/scsi/libata-core.c renamed from drivers/scsi/libata-core.c~libata_lock_change +21 -20
131 lines not on this page · raw message
_
Brian King
maintainerRFC 2/2 libata: support SATA devices on SAS HBAs
In reply to Brian KingThe 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_portata_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
---
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(-)
drivers/scsi/libata-scsi.c renamed from drivers/scsi/libata-scsi.c~libata_sas +187 -26
@@ -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_queueint 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);
drivers/scsi/libata-core.c renamed from drivers/scsi/libata-core.c~libata_sas +20 -12
@@ -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 ;
drivers/scsi/libata.h renamed from drivers/scsi/libata.h~libata_sas +7 -0
@@ -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__ */
include/linux/libata.h renamed from include/linux/libata.h~libata_sas +8 -0
@@ -400,6 +400,14 @@ extern int ata_scsi_ioctl(struct scsi_deextern 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
_
Quoted 8 lines · Brian King
The following patches enhance 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.
hmmmm, neat. My gut feeling feeling says a slightly better direction might be warranted, but I'll have to think a bit to put that feeling towords.
* One thought is the desire to allocate a single ata_host_set for the HBA, rather than avoiding ata_host_set.
* Another thought is the locking scheme -- Christoph once poked me about libata's use of scsi_assign_lock(), which I rather like but he didn't :) So by the transitive(?) property, if libata's locking is useful, then
your solution is probably OK. And vice versa.
* I also wonder if there isn't any severe leakage or oops somewhere, because you don't really use ata_host_set, just ata_port.
But note again, these are 6am thoughts, not in-depth analysis.
Jeff
Quoted 10 lines · Jeff Garzik
Quoted 8 lines · Brian King
The following patches enhance 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.
Quoted 6 lines
hmmmm, neat. My gut feeling feeling says a slightly better direction might be warranted, but I'll have to think a bit to put that feeling towords.
* One thought is the desire to allocate a single
ata_host_setfor the HBA, rather than avoidingata_host_set.
For SAS we should definitely avoid ata_host_set.
Quoted 4 lines
* Another thought is the locking scheme -- Christoph once poked me about libata's use of
scsi_assign_lock(), which I rather like but he didn't :) So by the transitive(?) property, if libata's locking is useful, then
your solution is probably OK. And vice versa.
host_set->lock is not useful for SAS et all and libata can be easily fixed to not require it for SAS (I'll make a patch later).
Quoted 4 lines
* I also wonder if there isn't any severe leakage or oops somewhere, because you don't really use
ata_host_set, justata_port.But note again, these are 6am thoughts, not in-depth analysis.
:)
Bartlomiej
Quoted 20 lines · Bartlomiej Zolnierkiewicz
Quoted 10 lines · Jeff Garzik
Quoted 8 lines · Brian King
The following patches enhance 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.
Quoted 6 lines
hmmmm, neat. My gut feeling feeling says a slightly better direction might be warranted, but I'll have to think a bit to put that feeling towords.
* One thought is the desire to allocate a single
ata_host_setfor the HBA, rather than avoidingata_host_set.For SAS we should definitely avoid
ata_host_set.
Quoted 7 lines
Quoted 4 lines
* Another thought is the locking scheme -- Christoph once poked me about libata's use of
scsi_assign_lock(), which I rather like but he didn't :) So by the transitive(?) property, if libata's locking is useful, then
your solution is probably OK. And vice versa.
host_set->lockis not useful for SAS et all and libata can be easily fixed to not require it for SAS (I'll make a patch later).
Attached (sorry for that but I needed to push it through gmail).
Please note that all other usages of host_set->lock are dependent on existence of hardware (S)ATA port which is simply not a case for SAS. We can also avoid using host_set entirely by allowing SAS layer to only register struct ata_port.
Thanks,
Bartlomiej
[PATCH] libata: add ops->qc_transport for SAS
* add ->qc_transport to struct ata_port_operations
* add default ata_qc_transport() and update all host drivers
Thanks to this change we won't have to depend on host_set and host_set->lock for devices attached to SAS HBAs.
drivers/scsi/libata-core.c +27 -12
@@ -1138,7 +1138,6 @@ static void ata_dev_identify(struct ata_unsigned int using_edd;DECLARE_COMPLETION (wait);struct ata_queued_cmd *qc; -unsigned long flags;int rc;if (!ata_dev_present (dev)) {
@@ -1179,9 +1178,7 @@ retry: qc->waiting = &wait; qc->complete_fn = ata_qc_complete_noop; -spin_lock_irqsave (&ap->host_set->lock, flags); - rc =ata_qc_issue (qc); -spin_unlock_irqrestore (&ap->host_set->lock, flags); + rc = ap->ops->qc_transport (qc);if (rc) goto err_out;
@@ -2114,7 +2111,6 @@ static void ata_dev_set_xfermode(structDECLARE_COMPLETION (wait);struct ata_queued_cmd *qc;int rc; -unsigned long flags;/* set up set-features taskfile */ DPRINTK ("set features - xfer mode\n" );
@@ -2131,9 +2127,7 @@ static void ata_dev_set_xfermode(struct qc->waiting = &wait; qc->complete_fn = ata_qc_complete_noop; -spin_lock_irqsave (&ap->host_set->lock, flags); - rc =ata_qc_issue (qc); -spin_unlock_irqrestore (&ap->host_set->lock, flags); + rc = ap->ops->qc_transport (qc);if (rc)ata_port_disable (ap);
@@ -2933,7 +2927,6 @@ static void atapi_request_sense(struct a {DECLARE_COMPLETION (wait);struct ata_queued_cmd *qc; -unsigned long flags;int rc;DPRINTK ("ATAPI request sense\n" );
@@ -2962,9 +2955,7 @@ static void atapi_request_sense(struct a qc->waiting = &wait; qc->complete_fn = ata_qc_complete_noop; -spin_lock_irqsave (&ap->host_set->lock, flags); - rc =ata_qc_issue (qc); -spin_unlock_irqrestore (&ap->host_set->lock, flags); + rc = ap->ops->qc_transport (qc);if (rc)ata_port_disable (ap);
@@ -3321,6 +3312,29 @@ err_out:return -1 ; } +/** +* ata_qc_transport - transport taskfile to device +* @qc: command to issue to device +* +* LOCKING: +* Obtains host_set lock. +* +* RETURNS: +* Zero on success, negative on error. +*/ + +int ata_qc_transport (struct ata_queued_cmd *qc) +{ +struct ata_port *ap = qc->ap; +unsigned long flags; +int rc; + +spin_lock_irqsave (&ap->host_set->lock, flags); + rc =ata_qc_issue (qc); +spin_unlock_irqrestore (&ap->host_set->lock, flags); + +return rc; +}/** * ata_qc_issue_prot - issue taskfile to device in proto-dependent manner
@@ -4593,6 +4607,7 @@ EXPORT_SYMBOL_GPL(ata_host_set_remove);EXPORT_SYMBOL_GPL (ata_sg_init);EXPORT_SYMBOL_GPL (ata_sg_init_one);EXPORT_SYMBOL_GPL (ata_qc_complete); +EXPORT_SYMBOL_GPL (ata_qc_transport);EXPORT_SYMBOL_GPL (ata_qc_issue_prot);EXPORT_SYMBOL_GPL (ata_eng_timeout);EXPORT_SYMBOL_GPL (ata_tf_load);
include/linux/libata.h +2 -0
@@ -352,6 +352,7 @@ struct ata_port_operations {void (*qc_prep) (struct ata_queued_cmd *qc);int (*qc_issue) (struct ata_queued_cmd *qc); +int (*qc_transport) (struct ata_queued_cmd *qc);void (*eng_timeout) (struct ata_port *ap);
@@ -419,6 +420,7 @@ extern void ata_host_stop (struct ata_hoextern irqreturn_t ata_interrupt (int irq,void *dev_instance,struct pt_regs *regs);extern void ata_qc_prep (struct ata_queued_cmd *qc);extern int ata_qc_issue_prot (struct ata_queued_cmd *qc); +extern int ata_qc_transport (struct ata_queued_cmd *qc);extern void ata_sg_init_one (struct ata_queued_cmd *qc,void *buf,unsigned int buflen); extern void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,
drivers/scsi/ahci.c +1 -0
@@ -230,6 +230,7 @@ static struct ata_port_operations ahci_o .qc_prep = ahci_qc_prep, .qc_issue = ahci_qc_issue, + .qc_transport = ata_qc_transport, .eng_timeout = ahci_eng_timeout,
drivers/scsi/ata_piix.c +2 -0
@@ -166,6 +166,7 @@ static struct ata_port_operations piix_p .bmdma_status = ata_bmdma_status, .qc_prep = ata_qc_prep, .qc_issue = ata_qc_issue_prot, + .qc_transport = ata_qc_transport, .eng_timeout = ata_eng_timeout,
@@ -194,6 +195,7 @@ static struct ata_port_operations piix_s .bmdma_status = ata_bmdma_status, .qc_prep = ata_qc_prep, .qc_issue = ata_qc_issue_prot, + .qc_transport = ata_qc_transport, .eng_timeout = ata_eng_timeout,
drivers/scsi/sata_mv.c +1 -0
@@ -223,6 +223,7 @@ static struct ata_port_operations mv_ops .qc_prep = ata_qc_prep, .qc_issue = ata_qc_issue_prot, + .qc_transport = ata_qc_transport, .eng_timeout = ata_eng_timeout,
drivers/scsi/sata_nv.c +1 -0
@@ -252,6 +252,7 @@ static struct ata_port_operations nv_ops .bmdma_status = ata_bmdma_status, .qc_prep = ata_qc_prep, .qc_issue = ata_qc_issue_prot, + .qc_transport = ata_qc_transport, .eng_timeout = ata_eng_timeout, .irq_handler = nv_interrupt, .irq_clear = ata_bmdma_irq_clear,
drivers/scsi/sata_promise.c +2 -0
@@ -125,6 +125,7 @@ static struct ata_port_operations pdc_sa .qc_prep = pdc_qc_prep, .qc_issue = pdc_qc_issue_prot, + .qc_transport = ata_qc_transport, .eng_timeout = pdc_eng_timeout, .irq_handler = pdc_interrupt, .irq_clear = pdc_irq_clear,
@@ -148,6 +149,7 @@ static struct ata_port_operations pdc_pa .qc_prep = pdc_qc_prep, .qc_issue = pdc_qc_issue_prot, + .qc_transport = ata_qc_transport, .eng_timeout = pdc_eng_timeout, .irq_handler = pdc_interrupt, .irq_clear = pdc_irq_clear,
drivers/scsi/sata_qstor.c +1 -0
@@ -156,6 +156,7 @@ static struct ata_port_operations qs_ata .phy_reset = qs_phy_reset, .qc_prep = qs_qc_prep, .qc_issue = qs_qc_issue, + .qc_transport = ata_qc_transport, .eng_timeout = qs_eng_timeout, .irq_handler = qs_intr, .irq_clear = qs_irq_clear,
drivers/scsi/sata_sil.c +1 -0
@@ -166,6 +166,7 @@ static struct ata_port_operations sil_op .bmdma_status = ata_bmdma_status, .qc_prep = ata_qc_prep, .qc_issue = ata_qc_issue_prot, + .qc_transport = ata_qc_transport, .eng_timeout = ata_eng_timeout, .irq_handler = ata_interrupt, .irq_clear = ata_bmdma_irq_clear,
drivers/scsi/sata_sis.c +1 -0
@@ -116,6 +116,7 @@ static struct ata_port_operations sis_op .bmdma_status = ata_bmdma_status, .qc_prep = ata_qc_prep, .qc_issue = ata_qc_issue_prot, + .qc_transport = ata_qc_transport, .eng_timeout = ata_eng_timeout, .irq_handler = ata_interrupt, .irq_clear = ata_bmdma_irq_clear,
drivers/scsi/sata_svw.c +1 -0
@@ -311,6 +311,7 @@ static struct ata_port_operations k2_sat .bmdma_status = ata_bmdma_status, .qc_prep = ata_qc_prep, .qc_issue = ata_qc_issue_prot, + .qc_transport = ata_qc_transport, .eng_timeout = ata_eng_timeout, .irq_handler = ata_interrupt, .irq_clear = ata_bmdma_irq_clear,
drivers/scsi/sata_sx4.c +1 -0
@@ -206,6 +206,7 @@ static struct ata_port_operations pdc_20 .phy_reset = pdc_20621_phy_reset, .qc_prep = pdc20621_qc_prep, .qc_issue = pdc20621_qc_issue_prot, + .qc_transport = ata_qc_transport, .eng_timeout = pdc_eng_timeout, .irq_handler = pdc20621_interrupt, .irq_clear = pdc20621_irq_clear,
drivers/scsi/sata_uli.c +1 -0
@@ -107,6 +107,7 @@ static struct ata_port_operations uli_op .bmdma_status = ata_bmdma_status, .qc_prep = ata_qc_prep, .qc_issue = ata_qc_issue_prot, + .qc_transport = ata_qc_transport, .eng_timeout = ata_eng_timeout,
drivers/scsi/sata_via.c +1 -0
@@ -127,6 +127,7 @@ static struct ata_port_operations svia_s .qc_prep = ata_qc_prep, .qc_issue = ata_qc_issue_prot, + .qc_transport = ata_qc_transport, .eng_timeout = ata_eng_timeout,
drivers/scsi/sata_vsc.c +1 -0
@@ -245,6 +245,7 @@ static struct ata_port_operations vsc_sa .bmdma_status = ata_bmdma_status, .qc_prep = ata_qc_prep, .qc_issue = ata_qc_issue_prot, + .qc_transport = ata_qc_transport, .eng_timeout = ata_eng_timeout, .irq_handler = vsc_sata_interrupt, .irq_clear = ata_bmdma_irq_clear,
Quoted 9 lines · Bartlomiej Zolnierkiewicz
[PATCH] libata: add
ops->qc_transportfor SAS* add ->qc_transport to struct
ata_port_operations
* add defaultata_qc_transport()and update all host driversThanks to this change we won't have to depend on
host_setandhost_set->lockfor devices attached to SAS HBAs.Signed-off-by Bartlomiej Zolnierkiewicz <[email protected]>
Seems sane at a quick glance, though I'm a bit disappointed we have to add yet another level of indirection to the hot path.
You made a good point, though, by pointing out that all the ata_qc_xxx stuff is essentially completely inside a single lock domain.
Other notes: There may be other dependencies such as wanting to reference the struct device pointer in host_set and similar details that need handling. Also, I was planning to move some of the ata_port_ops into a separate host_set ops, since they (hooks such as ->irq_clear or ->host_stop) are really host-wide hooks, not per-port hooks.
Jeff
Brian King
maintainercover libata: support SATA devices on SAS HBAs
The following patches enhance 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. In the context of SAS, a struct ata_port is not a physical port, but rather becomes a virtual construct.
Since my last post, I have removed the dependence on the host_set struct. The following two patches depend on the qc_transport patch:
http://marc.theaimsgroup.com/?l=linux-ide&m=112845939215286&w=2
The API is the same as the last time I posted it to linux-ide, but here is the description again:
New APIs:
ata_sas_port_alloc - Allocate an ata_portata_sas_port_init - Initialize an ata_port (probe device, 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
Signature · 3 lines
Brian King eServer Storage I/O IBM Linux Technology Center
Brian King
maintainerPATCH 1/2 libata: Remove dependence on host_set->dev for SAS
Remove some of the dependence on the host_set struct in preparation for supporting SAS HBAs. Adds a struct device pointer to the ata_port struct.
This patch depends on the qc_transport patch:
http://marc.theaimsgroup.com/?l=linux-ide&m=112845939215286&w=2
---
linux-2.6-bjking1/drivers/scsi/libata-core.c | 13 +++++++------ linux-2.6-bjking1/include/linux/libata.h | 1 + 2 files changed, 8 insertions(+), 6 deletions(-)
include/linux/libata.h renamed from include/linux/libata.h~libata_host_set_dev +1 -0
@@ -315,6 +315,7 @@ struct ata_port {struct ata_host_stats stats;struct ata_host_set *host_set; +struct device *dev;struct work_struct packet_task;
drivers/scsi/libata-core.c renamed from drivers/scsi/libata-core.c~libata_host_set_dev +7 -6
@@ -2162,9 +2162,9 @@ static void ata_sg_clean(struct ata_queuDPRINTK ("unmapping %u sg elements\n" , qc->n_elem);if (qc->flags &ATA_QCFLAG_SG ) -dma_unmap_sg (ap->host_set->dev, sg, qc->n_elem, dir); +dma_unmap_sg (ap->dev, sg, qc->n_elem, dir);else -dma_unmap_single (ap->host_set->dev,sg_dma_address (&sg[0 ]), +dma_unmap_single (ap->dev,sg_dma_address (&sg[0 ]),sg_dma_len (&sg[0 ]), dir); qc->flags &= ~ATA_QCFLAG_DMAMAP ;
@@ -2335,7 +2335,7 @@ static int ata_sg_setup_one(struct ata_qstruct scatterlist *sg = qc->sg;dma_addr_t dma_address; - dma_address =dma_map_single (ap->host_set->dev, qc->buf_virt, + dma_address =dma_map_single (ap->dev, qc->buf_virt, sg->length, dir);if (dma_mapping_error (dma_address))return -1 ;
@@ -2373,7 +2373,7 @@ static int ata_sg_setup(struct ata_queueassert (qc->flags &ATA_QCFLAG_SG ); dir = qc->dma_dir; - n_elem =dma_map_sg (ap->host_set->dev, sg, qc->n_elem, dir); + n_elem =dma_map_sg (ap->dev, sg, qc->n_elem, dir);if (n_elem <1 )return -1 ;
@@ -3845,7 +3845,7 @@ err_out:int ata_port_start (struct ata_port *ap) { -struct device *dev = ap->host_set->dev; +struct device *dev = ap->dev; ap->prd =dma_alloc_coherent (dev,ATA_PRD_TBL_SZ , &ap->prd_dma,GFP_KERNEL );if (!ap->prd)
@@ -3870,7 +3870,7 @@ int ata_port_start (struct ata_port *ap)void ata_port_stop (struct ata_port *ap) { -struct device *dev = ap->host_set->dev; +struct device *dev = ap->dev;dma_free_coherent (dev,ATA_PRD_TBL_SZ , ap->prd, ap->prd_dma); }
@@ -3937,6 +3937,7 @@ static void ata_host_init(struct ata_por ap->host = host; ap->ctl =ATA_DEVCTL_OBS ; ap->host_set = host_set; + ap->dev = ent->dev; ap->port_no = port_no; ap->hard_port_no = ent->legacy_mode ? ent->hard_port_no : port_no;
_
Re: [PATCH 1/2] libata: Remove dependence on host_set->dev for SAS
Quoted 19 lines · Brian King
Remove some of the dependence on the
host_setstruct in preparation for supporting SAS HBAs. Adds a struct device pointer to theata_portstruct.This patch depends on the
qc_transportpatch:http://marc.theaimsgroup.com/?l=linux-ide&m=112845939215286&w=2
Signed-off-by Brian King <[email protected]>---
linux-2.6-bjking1/drivers/scsi/libata-core.c | 13 +++++++------ linux-2.6-bjking1/include/linux/libata.h | 1 + 2 files changed, 8 insertions(+), 6 deletions(-)diff -puN
include/linux/libata.h~libata_host_set_devinclude/linux/libata.h
include/linux/libata.h struct ata_port { · line 321
Quoted 7 lines
include/linux/libata.h renamed from include/linux/libata.h~libata_host_set_dev +1
-0@@ -315,6 +315,7 @@ struct ata_port {struct ata_host_stats stats;struct ata_host_set *host_set; +struct device *dev;struct work_struct packet_task;
Patch seems basically OK. But taking this patch to its conclusion means deleting 'dev' from struct ata_host_set too... I wonder what breakage will result from that?
Jeff
Brian King
maintainerRe: [PATCH 1/2] libata: Remove dependence on host_set->dev for SAS
Quoted 26 lines · Jeff Garzik
Quoted 24 lines · Brian King
Remove some of the dependence on the
host_setstruct in preparation for supporting SAS HBAs. Adds a struct device pointer to theata_portstruct.This patch depends on the
qc_transportpatch:http://marc.theaimsgroup.com/?l=linux-ide&m=112845939215286&w=2
Signed-off-by Brian King <[email protected]>---
linux-2.6-bjking1/drivers/scsi/libata-core.c| 13 +++++++------linux-2.6-bjking1/include/linux/libata.h| 1 +2 files changed, 8 insertions(+), 6 deletions(-)diff -puN
include/linux/libata.h~libata_host_set_devinclude/linux/libata.hinclude/linux/libata.h renamed from include/linux/libata.h~libata_host_set_dev +1
-0@@ -315,6 +315,7 @@ struct ata_port {struct ata_host_stats stats;struct ata_host_set *host_set; +struct device *dev;
Quoted 7 lines
include/linux/libata.h struct ata_port { · line 321
Quoted 2 lines
include/linux/libata.h renamed from include/linux/libata.h~libata_host_set_dev +0
-0struct work_struct packet_task;Patch seems basically OK. But taking this patch to its conclusion means deleting 'dev' from struct
ata_host_settoo... I wonder what breakage will result from that?
It breaks ata_pci_host_stop:
void ata_pci_host_stop (struct ata_host_set *host_set)
{
struct pci_dev *pdev = to_pci_dev(host_set->dev);
pci_iounmap(pdev, host_set->mmio_base);
}I could poke into the first port here to get the 'dev', but I didn't particularly like that.
I also thought about changing the prototype for host_set to pass in the 'dev' pointer, but wasn't sure that would work for the non PCI case.
Or, we just live with the duplication...
Signature · 3 lines
Brian King eServer Storage I/O IBM Linux Technology Center
Re: [PATCH 1/2] libata: Remove dependence on host_set->dev for SAS
Quoted 1 line · Brian King
Or, we just live with the duplication...
That may be the best practical solution.
I wonder, additionally, if we need to be getting a reference each time we store the pointer. Traditionally the struct device object lifetime has always been entirely within the bus device lifetime, but with this new work that may need rethinking.
Jeff
Re: [PATCH 1/2] libata: Remove dependence on host_set->dev for SAS
Quoted 11 lines · Jeff Garzik
Quoted 1 line · Brian King
Or, we just live with the duplication...
That may be the best practical solution.
I wonder, additionally, if we need to be getting a reference each time we store the pointer. Traditionally the struct device object lifetime has always been entirely within the bus device lifetime, but with this new work that may need rethinking.
Would it be a good idea to abstract most of this in say something like
struct satl_device_struct {
-- data... ;
/* The registering entity calls this for SATL to translate
to an ATA task(s) and execute. Filled in by the SATL Layer. */
int (*execute_scsi_task)(struct satl_device_struct *, struct scsi_cmnd *);
/* SATL layer calls this to send an ata_task to the device.
Filled in by the registering entity. */
int (*execute_ata_task)(struct satl_device_struct *, struct ata_task *);
-- recovery methods common to SATA-over-anything; filled in by registering
\ entity
};(ata task to be properly constructed: FIS, sg lists, etc.)
Then libata-scsi would only have to export two (2) functions:
int satl_register_device(struct satl_device_struct *); void satl_unregister_device(struct satl_device_struct *);
EXPORT_SYMBOL_GPL(satl_register_device);EXPORT_SYMBOL_GPL(satl_unregister_device);
And the rest are in the struct satl_device_struct for which translation is being provided.
Thus, error handling can also be "commonalized" as per the entity registering for the service.
The whole point is to have this at device level as opposed to libata's port level. Plus it simplifies the code of entities registering for this service.
<I was going to draw ascii art, but ran out of time>
Luben
Signature · 2 lines
http://linux.adaptec.com/sas/ http://www.adaptec.com/sas/
Brian King
maintainerRe: [PATCH 1/2] libata: Remove dependence on host_set->dev for SAS
Quoted 20 lines · Luben Tuikov
Would it be a good idea to abstract most of this in say something like
struct satl_device_struct { -- data... ; /* The registering entity calls this for SATL to translate to an ATA task(s) and execute. Filled in by the SATL Layer. */ int (*execute_scsi_task)(struct satl_device_struct *, struct scsi_cmnd *); /* SATL layer calls this to send an ata_task to the device. Filled in by the registering entity. */ int (*execute_ata_task)(struct satl_device_struct *, struct ata_task *); -- recovery methods common to SATA-over-anything; filled in by registering \ entity };(ata task to be properly constructed: FIS, sg lists, etc.)
Quoted 7 lines
Then libata-scsi would only have to export two (2) functions:
int
satl_register_device(struct satl_device_struct *); voidsatl_unregister_device(struct satl_device_struct *);
EXPORT_SYMBOL_GPL(satl_register_device);EXPORT_SYMBOL_GPL(satl_unregister_device);
Where would you be calling satl_register_device in your SAS class?
It looks like this would force libata to be the one to attach the ULD, which would also force it to create a separate scsi_host for each device, which is something I wanted to avoid. I think you really need a libata API that the LLDD can call from its queuecommand function to translate and send a command, which then calls back into the LLDD to send the FIS to the hardware. This allows for all SAS/SATA devices under the same HBA to show up under the same scsi_host.
Brian
Signature · 3 lines
Brian King eServer Storage I/O IBM Linux Technology Center
Re: [PATCH 1/2] libata: Remove dependence on host_set->dev for SAS
Quoted 24 lines · Brian King
Quoted 22 lines · Luben Tuikov
Would it be a good idea to abstract most of this in say something like
struct satl_device_struct { -- data... ; /* The registering entity calls this for SATL to translate to an ATA task(s) and execute. Filled in by the SATL Layer. */ int (*execute_scsi_task)(struct satl_device_struct *, struct scsi_cmnd *); /* SATL layer calls this to send an ata_task to the device. Filled in by the registering entity. */ int (*execute_ata_task)(struct satl_device_struct *, struct ata_task *); -- recovery methods common to SATA-over-anything; filled in by registering \ entity };(ata task to be properly constructed: FIS, sg lists, etc.)
Then libata-scsi would only have to export two (2) functions:
Quoted 8 lines
Quoted 5 lines
int
satl_register_device(struct satl_device_struct *); voidsatl_unregister_device(struct satl_device_struct *);
EXPORT_SYMBOL_GPL(satl_register_device);EXPORT_SYMBOL_GPL(satl_unregister_device);Where would you be calling
satl_register_devicein your SAS class?
Just before you register the device with SCSI Core.
Quoted 3 lines
It looks like this would force libata to be the one to attach the ULD, which would also force it to create a separate
scsi_hostfor each device, which is something I wanted to avoid. I think you really need a
The opposite. The service provided by SATL would be just translation, similarly to the SAT spec. It happens at device level, not port level as it is done in libata. It doesn't care about hosts, etc.
There will be only one host.
The whole point of all this is that neither SATL nor the entity registering for service care about hosts or what-not. Translation is done at device level. It goes like this:
"Here is a scsi command to be executed, and here is how you send tasks to the ATA device. Translate for me please."
Quoted 4 lines
libata API that the LLDD can call from its queuecommand function to translate and send a command, which then calls back into the LLDD to send the FIS to the hardware. This allows for all SAS/SATA devices under the same HBA to show up under the same
scsi_host.
You'd also be able to do the same thing using this infrastructure, since translation happens at device level. How and where it is represented "above" is the caller's (the one who registers with the service) responsibility.
So, for example, using the SAS Transport Layer/Stack, when SCSI Core calls the queuecommand() method, we check if it is a SATA device and if it is we call execute_scsi_task() which was filled in by SATL upon registration (satl_register_device()). SATL does whatever is necessary to simulate this command, calling execute_ata_task() one or more times. execute_ata_task() was filled in by the entity registering for this service (say, the SAS Transport Layer). Like so:
struct satl_device_struct *satl_dev = xalloc(one); satl_dev->execute_ata_task = our_execute_ata_task_func; satl_dev->... = ...; satl_register_device(satl_dev); /* Now satl_dev->execute_scsi_task was filled in by SATL, and points to a SATL function which would do translation for the device regsitered.*/
In queuecommand():
if (dev->dev_type == SATA_DEV) dev->satl_dev->execute_scsi_task(dev->satl_dev, scsi_cmnd); else /* dispatch to SAS layer -- current code */
One thing which may change is that execute_scsi_task() may want to take something more abstracted like say satl_scsi_task, whereby the completion method is in the struct -- similarly to the way it is done in struct sas_task in include/scsi/sas/sas_task.h::178.
Notice how object oriented this is. Other function stubs which would live in struct satl_device_struct is the two device resets (depending on the type of device) and a few more, so that recovery is abstracted away similarly. Then the entity registering for the service fills those in if it has them or if it can implement them.
Luben
Signature · 2 lines
http://linux.adaptec.com/sas/ http://www.adaptec.com/sas/
Re: [PATCH 1/2] libata: Remove dependence on host_set->dev for SAS
In reply to Brian KingQuoted 33 lines · Brian King
Quoted 20 lines · Luben Tuikov
Would it be a good idea to abstract most of this in say something like
struct satl_device_struct { -- data... ; /* The registering entity calls this for SATL to translate to an ATA task(s) and execute. Filled in by the SATL Layer. */ int (*execute_scsi_task)(struct satl_device_struct *, struct scsi_cmnd *); /* SATL layer calls this to send an ata_task to the device. Filled in by the registering entity. */ int (*execute_ata_task)(struct satl_device_struct *, struct ata_task *); -- recovery methods common to SATA-over-anything; filled in by registering \ entity };(ata task to be properly constructed: FIS, sg lists, etc.)
Quoted 7 lines
Then libata-scsi would only have to export two (2) functions:
int
satl_register_device(struct satl_device_struct *); voidsatl_unregister_device(struct satl_device_struct *);
EXPORT_SYMBOL_GPL(satl_register_device);EXPORT_SYMBOL_GPL(satl_unregister_device);Where would you be calling
satl_register_devicein your SAS class?
Quoted 7 lines
It looks like this would force libata to be the one to attach the ULD, which would also force it to create a separate
scsi_hostfor each device, which is something I wanted to avoid. I think you really need a libata API that the LLDD can call from its queuecommand function to translate and send a command, which then calls back into the LLDD to send the FIS to the hardware. This allows for all SAS/SATA devices under the same HBA to show up under the samescsi_host.
Brian,
I don't think a SATL is that easy. One SCSI command can translate into zero or more ATA commands. If it translates to multiple commands, then there is the possibility of an error prior to the last in the sequence of ATA commands (how to report; rollback needed ?). The SATL needs to hold state and needs a service thread if it is to support the IMMED bit on some commands (e.g. START STOP UNIT).
libata still has a ways to go to catch up to SAT rev 7 but has made some good progress lately with the addition of the ATA pass through commands (lk 2.6.15-rc1 and onward). smartmontools (just prior to 5.34) now works with '-d ata' on libata-connected SATA disks. The '-d ata' ** overrides the guess of a SCSI disk based on the device node (e.g. /dev/sda) and uses the HDIO_DRIVE_CMD and HDIO_DRIVE_TASK ioctls. The absence of support for the HDIO_DRIVE_TASKFILE ioctl means that "selective" self-test can't be done. I'm not sure if moving smartmontools to the ATA PASS THROUGH SCSI commands will win back the "selective" self-test capability. Anyway, going to those ATA PASS THROUGH SCSI commands seems the correct way to go for smartmontools.
** smartmontools has some magic in the device detection area for 3ware controllers, which amounts to a proprietary ATA command pass through (plus some device addressing).
Doug Gilbert
Re: [PATCH 1/2] libata: Remove dependence on host_set->dev for SAS
Quoted 7 lines · Douglas Gilbert
I don't think a SATL is that easy. One SCSI command can translate into zero or more ATA commands. If it translates to multiple commands, then there is the possibility of an error prior to the last in the sequence of ATA commands (how to report; rollback needed ?). The SATL needs to hold state and needs a service thread if it is to support the IMMED bit on some commands (e.g. START STOP UNIT).
It needs a conceptual service thread, not necessarily an explicit one.
With REQUEST SENSE, I've demonstrated how to report errors with each step in the sequence. With demo patches I've posted, I've demonstrated (using qc->private_data) how to hold state.
Quoted 4 lines
libata still has a ways to go to catch up to SAT rev 7 but has made some good progress lately with the addition of the ATA pass through commands (lk 2.6.15-rc1 and onward). smartmontools (just prior to 5.34) now works with '-d ata'
Quoted 8 lines
on libata-connected SATA disks. The '-d ata' ** overrides the guess of a SCSI disk based on the device node (e.g.
/dev/sda) and uses theHDIO_DRIVE_CMDandHDIO_DRIVE_TASKioctls. The absence of support for theHDIO_DRIVE_TASKFILEioctl means that "selective" self-test can't be done. I'm not sure if moving smartmontools to the ATA PASS THROUGH SCSI commands will win back the "selective" self-test capability. Anyway, going to those ATA PASS THROUGH SCSI
ATA passthru can do anything the legacy IDE ioctls can do (and more).
Jeff
Re: [PATCH 1/2] libata: Remove dependence on host_set->dev for SAS
Quoted 29 lines · Jeff Garzik
Quoted 7 lines · Douglas Gilbert
I don't think a SATL is that easy. One SCSI command can translate into zero or more ATA commands. If it translates to multiple commands, then there is the possibility of an error prior to the last in the sequence of ATA commands (how to report; rollback needed ?). The SATL needs to hold state and needs a service thread if it is to support the IMMED bit on some commands (e.g. START STOP UNIT).
It needs a conceptual service thread, not necessarily an explicit one.
With REQUEST SENSE, I've demonstrated how to report errors with each step in the sequence. With demo patches I've posted, I've demonstrated (using
qc->private_data) how to hold state.Quoted 4 lines
libata still has a ways to go to catch up to SAT rev 7 but has made some good progress lately with the addition of the ATA pass through commands (lk 2.6.15-rc1 and onward). smartmontools (just prior to 5.34) now works with '-d ata'
Quoted 8 lines
on libata-connected SATA disks. The '-d ata' ** overrides the guess of a SCSI disk based on the device node (e.g.
/dev/sda) and uses theHDIO_DRIVE_CMDandHDIO_DRIVE_TASKioctls. The absence of support for theHDIO_DRIVE_TASKFILEioctl means that "selective" self-test can't be done. I'm not sure if moving smartmontools to the ATA PASS THROUGH SCSI commands will win back the "selective" self-test capability. Anyway, going to those ATA PASS THROUGH SCSI
Quoted 1 line
ATA passthru can do anything the legacy IDE ioctls can do (and more).
[ definitely ATA passthru is the way to go but... ]
discrete taskfiles?
multi-PIO?
setting transfer speed?
and if you are talking about IDE ioctls there is (unfortunately) much more than HDIO_DRIVE_[CMD,TASK,TASKFILE]
Quoted 1 line
From extra things that it can do I see support
for LBA48 transfers, is there anything more?
Bartlomiej
Re: [PATCH 1/2] libata: Remove dependence on host_set->dev for SAS
Quoted 33 lines · Bartlomiej Zolnierkiewicz
Quoted 31 lines · Jeff Garzik
Quoted 7 lines · Douglas Gilbert
I don't think a SATL is that easy. One SCSI command can translate into zero or more ATA commands. If it translates to multiple commands, then there is the possibility of an error prior to the last in the sequence of ATA commands (how to report; rollback needed ?). The SATL needs to hold state and needs a service thread if it is to support the IMMED bit on some commands (e.g. START STOP UNIT).
It needs a conceptual service thread, not necessarily an explicit one.
With REQUEST SENSE, I've demonstrated how to report errors with each step in the sequence. With demo patches I've posted, I've demonstrated (using
qc->private_data) how to hold state.Quoted 12 lines
libata still has a ways to go to catch up to SAT rev 7 but has made some good progress lately with the addition of the ATA pass through commands (lk 2.6.15-rc1 and onward). smartmontools (just prior to 5.34) now works with '-d ata' on libata-connected SATA disks. The '-d ata' ** overrides the guess of a SCSI disk based on the device node (e.g.
/dev/sda) and uses theHDIO_DRIVE_CMDandHDIO_DRIVE_TASKioctls. The absence of support for theHDIO_DRIVE_TASKFILEioctl means that "selective" self-test can't be done. I'm not sure if moving smartmontools to the ATA PASS THROUGH SCSI commands will win back the "selective" self-test capability. Anyway, going to those ATA PASS THROUGH SCSI
Quoted 6 lines
Quoted 1 line
ATA passthru can do anything the legacy IDE ioctls can do (and more).
[ definitely ATA passthru is the way to go but... ]
discrete taskfiles?
what is this?
Quoted 1 line
multi-PIO?
what is this? multi-sector PIO, such as READ MULTIPLE SECTORS? ATA passthru can do that.
Quoted 1 line
setting transfer speed?
That's not a limitation of passthru, but a limitation of the driver. I don't yet see the value...
Jeff
Re: [PATCH 1/2] libata: Remove dependence on host_set->dev for SAS
Quoted 34 lines · Jeff Garzik
Quoted 33 lines · Bartlomiej Zolnierkiewicz
Quoted 31 lines · Jeff Garzik
Quoted 7 lines · Douglas Gilbert
I don't think a SATL is that easy. One SCSI command can translate into zero or more ATA commands. If it translates to multiple commands, then there is the possibility of an error prior to the last in the sequence of ATA commands (how to report; rollback needed ?). The SATL needs to hold state and needs a service thread if it is to support the IMMED bit on some commands (e.g. START STOP UNIT).
It needs a conceptual service thread, not necessarily an explicit one.
With REQUEST SENSE, I've demonstrated how to report errors with each step in the sequence. With demo patches I've posted, I've demonstrated (using
qc->private_data) how to hold state.Quoted 12 lines
libata still has a ways to go to catch up to SAT rev 7 but has made some good progress lately with the addition of the ATA pass through commands (lk 2.6.15-rc1 and onward). smartmontools (just prior to 5.34) now works with '-d ata' on libata-connected SATA disks. The '-d ata' ** overrides the guess of a SCSI disk based on the device node (e.g.
/dev/sda) and uses theHDIO_DRIVE_CMDandHDIO_DRIVE_TASKioctls. The absence of support for theHDIO_DRIVE_TASKFILEioctl means that "selective" self-test can't be done. I'm not sure if moving smartmontools to the ATA PASS THROUGH SCSI commands will win back the "selective" self-test capability. Anyway, going to those ATA PASS THROUGH SCSI
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
ATA passthru can do anything the legacy IDE ioctls can do (and more).
[ definitely ATA passthru is the way to go but... ]
discrete taskfiles?
what is this?
flagged taskfiles
yes, this is a low priority but your statement is oversimplification and I don't even mentioned other "IDE ioctl", so:
ATA passthru can do anything _important_ that legacy IDE ioctls can do (write cache [dis,en]abling?)
Quoted 3 lines
Quoted 1 line
multi-PIO?
what is this? multi-sector PIO, such as READ MULTIPLE SECTORS? ATA
short for multi sector-sector PIO
Quoted 1 line
passthru can do that.
not in the mainline, I've just checked libata-dev and it is OK
Quoted 4 lines
Quoted 1 line
setting transfer speed?
That's not a limitation of passthru, but a limitation of the driver. I don't yet see the value...
Same for me...
Bartlomiej
Re: [PATCH 1/2] libata: Remove dependence on host_set->dev for SAS
Quoted 73 lines · Bartlomiej Zolnierkiewicz
Quoted 38 lines · Jeff Garzik
Quoted 36 lines · Bartlomiej Zolnierkiewicz
Quoted 33 lines · Jeff Garzik
Quoted 7 lines · Douglas Gilbert
I don't think a SATL is that easy. One SCSI command can translate into zero or more ATA commands. If it translates to multiple commands, then there is the possibility of an error prior to the last in the sequence of ATA commands (how to report; rollback needed ?). The SATL needs to hold state and needs a service thread if it is to support the IMMED bit on some commands (e.g. START STOP UNIT).
It needs a conceptual service thread, not necessarily an explicit one.
With REQUEST SENSE, I've demonstrated how to report errors with each step in the sequence. With demo patches I've posted, I've demonstrated (using
qc->private_data) how to hold state.Quoted 12 lines
libata still has a ways to go to catch up to SAT rev 7 but has made some good progress lately with the addition of the ATA pass through commands (lk 2.6.15-rc1 and onward). smartmontools (just prior to 5.34) now works with '-d ata' on libata-connected SATA disks. The '-d ata' ** overrides the guess of a SCSI disk based on the device node (e.g.
/dev/sda) and uses theHDIO_DRIVE_CMDandHDIO_DRIVE_TASKioctls. The absence of support for theHDIO_DRIVE_TASKFILEioctl means that "selective" self-test can't be done. I'm not sure if moving smartmontools to the ATA PASS THROUGH SCSI commands will win back the "selective" self-test capability. Anyway, going to those ATA PASS THROUGH SCSIQuoted 8 lines
Quoted 6 lines
Quoted 1 line
ATA passthru can do anything the legacy IDE ioctls can do (and more).
[ definitely ATA passthru is the way to go but... ]
discrete taskfiles?
what is this?
flagged taskfiles
yes, this is a low priority but your statement is oversimplification and I don't even mentioned other "IDE ioctl", so:
ATA passthru can do anything _important_ that legacy IDE ioctls can do (write cache [dis,en]abling?)
Quoted 3 lines
Quoted 1 line
multi-PIO?
what is this? multi-sector PIO, such as READ MULTIPLE SECTORS? ATA
short for multi sector-sector PIO
Quoted 1 line
passthru can do that.
not in the mainline, I've just checked libata-dev and it is OK
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
setting transfer speed?
That's not a limitation of passthru, but a limitation of the driver. I don't yet see the value...
Same for me...
I noticed that the protocol field in the ATA_12 and ATA_16 pass through commands included hard reset, SRST and device reset. Would it be useful to implement these?
Doug Gilbert
Re: [PATCH 1/2] libata: Remove dependence on host_set->dev for SAS
Quoted 4 lines · Douglas Gilbert
I noticed that the protocol field in the
ATA_12andATA_16pass through commands included hard reset, SRST and device reset. Would it be useful to implement these?
Yes, at least SRST should be implemented.
Jeff
Brian King
maintainerRe: [PATCH 1/2] libata: Remove dependence on host_set->dev for SAS
In reply to Douglas GilbertQuoted 9 lines · Douglas Gilbert
Quoted 5 lines · Brian King
I think you really need a
libata API that the LLDD can call from its queuecommand function to translate and send a command, which then calls back into the LLDD to send the FIS to the hardware. This allows for all SAS/SATA devices under the same HBA to show up under the samescsi_host.Brian,
I don't think a SATL is that easy.
That is essentially the API that libata has today. Existing SATA drivers have a queuecommand routine that invokes a libata API to send a taskfile to the hardware.
Quoted 7 lines
One SCSI command can
translate into zero or more ATA commands. If it translates to multiple commands, then there is the possibility of an error prior to the last in the sequence of ATA commands (how to report; rollback needed ?). The SATL needs to hold state and needs a service thread if it is to support the IMMED bit on some commands (e.g. START STOP UNIT).
I guess I don't see these problems as unique to SATA drives attached via a SAS adapter, which is what my patchset is trying to implement, but rather general libata issues. Reading Jeff's response, it sounds like the service thread issue is already being worked in another manner.
Brian
Signature · 3 lines
Brian King eServer Storage I/O IBM Linux Technology Center
Brian King
maintainerPATCH 2/2 libata: Add support for SATA attachment to SAS adapters
In reply to Brian KingThe 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.
Since the last time I posted this code, I have removed all dependence on the ata_host_set struct.
New APIs:
ata_sas_port_alloc - Allocate an ata_portata_sas_port_init - Initialize an ata_port (probe device, 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
---
linux-2.6-bjking1/drivers/scsi/libata-core.c | 32 ++-- linux-2.6-bjking1/drivers/scsi/libata-scsi.c | 191 +++++++++++++++++++++++---- linux-2.6-bjking1/drivers/scsi/libata.h | 7 linux-2.6-bjking1/include/linux/libata.h | 7 4 files changed, 199 insertions(+), 38 deletions(-)
drivers/scsi/libata-scsi.c renamed from drivers/scsi/libata-scsi.c~libata_sas +165 -26
@@ -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_queueint 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,126 @@ void ata_scsi_simulate(u16 *id, } } +/** +* ata_sas_port_alloc - Allocate port for a SAS attached SATA device +* @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 pci_dev *pdev, +struct ata_port_info *port_info) +{ +struct ata_port *ap =kzalloc (sizeof (*ap),GFP_KERNEL ); + +if (!ap) +return NULL ; + + ap->dev = &pdev->dev; + 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); +} + +/** +* 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 +* +*/ + +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 +* +* 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 +* +* 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);
drivers/scsi/libata-core.c renamed from drivers/scsi/libata-core.c~libata_sas +20 -12
@@ -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
@@ -1266,7 +1281,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",
@@ -1286,8 +1301,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",
@@ -1306,12 +1321,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
@@ -1328,8 +1337,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 ; }
@@ -1352,7 +1360,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 ;
drivers/scsi/libata.h renamed from drivers/scsi/libata.h~libata_sas +7 -0
@@ -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__ */
include/linux/libata.h renamed from include/linux/libata.h~libata_sas +7 -0
@@ -401,6 +401,13 @@ extern int ata_scsi_ioctl(struct scsi_deextern 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 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
_
Re: [PATCH 2/2] libata: Add support for SATA attachment to SAS adapters
Quoted 112 lines · Brian King
drivers/scsi/libata-scsi.c renamed from drivers/scsi/libata-scsi.c~libata_sas +112
-0+/** +* ata_sas_port_alloc - Allocate port for a SAS attached SATA device +* @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 pci_dev *pdev, +struct ata_port_info *port_info) +{ +struct ata_port *ap =kzalloc (sizeof (*ap),GFP_KERNEL ); + +if (!ap) +return NULL ; + + ap->dev = &pdev->dev; + 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); +} + +/** +* 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 +* +*/ + +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 +* +* 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 +* +* 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 ; + }
drivers/scsi/libata-scsi.c void ata_scsi_simulate(u16 *id, · line 1818
Quoted 10 lines
drivers/scsi/libata-scsi.c renamed from drivers/scsi/libata-scsi.c~libata_sas +10
-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 ; +}
I'm still thinking about these functions, so it would be nice to split them up into a third patch. That would allow me to apply the other cleanups in this patch.
Jeff
Quoted 34 lines · Brian King
The following patches enhance 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. In the context of SAS, a struct
ata_portis not a physical port, but rather becomes a virtual construct.Since my last post, I have removed the dependence on the
host_setstruct. The following two patches depend on theqc_transportpatch:http://marc.theaimsgroup.com/?l=linux-ide&m=112845939215286&w=2
The API is the same as the last time I posted it to linux-ide, but here is the description again:
New APIs:
ata_sas_port_alloc- Allocate anata_portata_sas_port_init- Initialize anata_port(probe device, etc)ata_sas_port_destroy- Free anata_portallocated byata_sas_port_allocata_sas_slave_configure- configure scsi deviceata_sas_queuecmd- queue a scsi command, similar toata_scsi_queuecomandThese 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
Quoted 6 lines
Commands received by the LLDD for SATA devices would call
ata_sas_queuecmd.Device teardown would occur with:
slave_destroy
ata_sas_port_destroy
Hey Brian,
That's admireable effort. Is there a git tree I can pull from which has these patches? (I don't mind using the patches themselves as well.)
I'll take a look indepth and comment further.
Thanks,
Luben
Signature · 2 lines
http://linux.adaptec.com/sas/ http://www.adaptec.com/sas/
Brian King
maintainerQuoted 46 lines · Luben Tuikov
Quoted 34 lines · Brian King
The following patches enhance 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. In the context of SAS, a struct
ata_portis not a physical port, but rather becomes a virtual construct.Since my last post, I have removed the dependence on the
host_setstruct. The following two patches depend on theqc_transportpatch:http://marc.theaimsgroup.com/?l=linux-ide&m=112845939215286&w=2
The API is the same as the last time I posted it to linux-ide, but here is the description again:
New APIs:
ata_sas_port_alloc- Allocate anata_portata_sas_port_init- Initialize anata_port(probe device, etc)ata_sas_port_destroy- Free anata_portallocated byata_sas_port_allocata_sas_slave_configure- configure scsi deviceata_sas_queuecmd- queue a scsi command, similar toata_scsi_queuecomandThese 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_configureQuoted 6 lines
Commands received by the LLDD for SATA devices would call
ata_sas_queuecmd.Device teardown would occur with:
slave_destroy
ata_sas_port_destroyHey Brian,
Quoted 7 lines
That's admireable effort. Is there a git tree I can pull from which has these patches? (I don't mind using the patches themselves as well.)
I'll take a look indepth and comment further.
Thanks,
Luben
Hey Luben,
I don't have a git tree setup, just the three patches.
Brian
Signature · 3 lines
Brian King eServer Storage I/O IBM Linux Technology Center
Quoted 54 lines · Brian King
Quoted 52 lines · Luben Tuikov
Quoted 34 lines · Brian King
The following patches enhance 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. In the context of SAS, a struct
ata_portis not a physical port, but rather becomes a virtual construct.Since my last post, I have removed the dependence on the
host_setstruct. The following two patches depend on theqc_transportpatch:http://marc.theaimsgroup.com/?l=linux-ide&m=112845939215286&w=2
The API is the same as the last time I posted it to linux-ide, but here is the description again:
New APIs:
ata_sas_port_alloc- Allocate anata_portata_sas_port_init- Initialize anata_port(probe device, etc)ata_sas_port_destroy- Free anata_portallocated byata_sas_port_allocata_sas_slave_configure- configure scsi deviceata_sas_queuecmd- queue a scsi command, similar toata_scsi_queuecomandThese 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_configureQuoted 6 lines
Commands received by the LLDD for SATA devices would call
ata_sas_queuecmd.Device teardown would occur with:
slave_destroy
ata_sas_port_destroyHey Brian,
That's admireable effort. Is there a git tree I can pull from which has these patches? (I don't mind using the patches themselves as well.)
I'll take a look indepth and comment further.
Quoted 7 lines
Quoted 2 lines
Thanks,
LubenHey Luben,
I don't have a git tree setup, just the three patches.
I assume you've tested them already on the SAS Transport Layer?
Luben
Signature · 2 lines
http://linux.adaptec.com/sas/ http://www.adaptec.com/sas/
Brian King
maintainerQuoted 11 lines · Luben Tuikov
Quoted 11 lines
Quoted 9 lines
Hey Brian,
That's admireable effort. Is there a git tree I can pull from which has these patches? (I don't mind using the patches themselves as well.)
I'll take a look indepth and comment further.
Thanks,
Luben
Quoted 6 lines
Quoted 3 lines
Hey Luben,
I don't have a git tree setup, just the three patches.
I assume you've tested them already on the SAS Transport Layer?
Unfortunately, no. My primary goal is to have an API I can use in the ipr LLDD, which is a RAID adapter which will talk SPI, SAS, and SATA. I am still trying to get the patches tested in my environment, but since there has been some discussion on the list about others needing the same function I figured I would share what I have with a wider audience.
Thanks,
Brian
Signature · 3 lines
Brian King eServer Storage I/O IBM Linux Technology Center
Quoted 3 lines · Brian King
Unfortunately, no. My primary goal is to have an API I can use in the ipr LLDD, which is a RAID adapter which will talk SPI, SAS, and SATA.
Hm, that's very cool.
Quoted 4 lines
I am still trying to get the patches tested
in my environment, but since there has been some discussion on the list about others needing the same function I figured I would share what I have with a wider audience.
That's great. Keep me posted on how it fares in your environment. I'll also give them a try.
I think that there will be quite a few things that the ipr driver and the SAS Transport Layer would set in exactly the same way, like say, the device id, DMA (rate), etc. Those commonalities can be abstracted away later I guess.
If you have a patch introducing this patch to ipr, send it to me please.
Thanks,
Luben
Signature · 2 lines
http://linux.adaptec.com/sas/ http://www.adaptec.com/sas/
Brian King
maintainerQuoted 10 lines · Luben Tuikov
Quoted 4 lines · Brian King
I am still trying to get the patches tested
in my environment, but since there has been some discussion on the list about others needing the same function I figured I would share what I have with a wider audience.That's great. Keep me posted on how it fares in your environment. I'll also give them a try.
Quoted 6 lines
I think that there will be quite a few things that the ipr driver and the SAS Transport Layer would set in exactly the same way, like say, the device id, DMA (rate), etc. Those commonalities can be abstracted away later I guess.
If you have a patch introducing this patch to ipr, send it to me please.
Here is the ipr patch. Its queued up behind a bunch of other ipr patches I'm getting ready to push, and it won't apply without them.
I uploaded the whole patchset to sourceforge, so you can just apply the whole set and have a working tree.
http://prdownloads.sourceforge.net/iprdd/ipr-sas-patches.tgz?download
Thanks
Brian
Signature · 3 lines
Brian King eServer Storage I/O IBM Linux Technology Center
Adds support to attach SATA devices to SAS adapters.
---
linux-2.6-bjking1/drivers/scsi/Kconfig | 1 linux-2.6-bjking1/drivers/scsi/Makefile | 2 linux-2.6-bjking1/drivers/scsi/ipr.c | 477 ++++++++++++++++++++++++++++---- linux-2.6-bjking1/drivers/scsi/ipr.h | 85 +++++ 4 files changed, 516 insertions(+), 49 deletions(-)
drivers/scsi/ipr.h renamed from drivers/scsi/ipr.h~ipr_sata_with_libata_changes +83 -2
@@ -45,6 +45,7 @@* This can be adjusted at runtime through sysfs device attributes. */ #define IPR_MAX_CMD_PER_LUN 6 +#define IPR_MAX_CMD_PER_ATA_LUN 1/* * IPR_NUM_BASE_CMD_BLKS: This defines the maximum number of
@@ -144,6 +145,7 @@#define IPR_LUN_RESET 0x40#define IPR_TARGET_RESET 0x20#define IPR_BUS_RESET 0x10 +#define IPR_HARDWARE_RESET 0x80#define IPR_ID_HOST_RR_Q 0xC4#define IPR_QUERY_IOA_CONFIG 0xC5#define IPR_CANCEL_ALL_REQUESTS 0xCE
@@ -294,7 +296,13 @@ struct ipr_std_inq_data { }__attribute__ ((packed));struct ipr_config_table_entry { -u8 service_level; +u8 proto; +#define IPR_PROTO_SPI 0x00 +#define IPR_PROTO_SATA 0x02 +#define IPR_PROTO_SATA_ATAPI 0x03 +#define IPR_PROTO_SAS 0x04 +#define IPR_PROTO_SAS_STP 0x06 +#define IPR_PROTO_SAS_STP_ATAPI 0x07u8 array_id;u8 flags;#define IPR_IS_IOA_RESOURCE 0x80
@@ -306,6 +314,7 @@ struct ipr_config_table_entry {#define IPR_SUBTYPE_AF_DASD 0#define IPR_SUBTYPE_GENERIC_SCSI 1#define IPR_SUBTYPE_VOLUME_SET 2 +#define IPR_SUBTYPE_GENERIC_ATA 4#define IPR_QUEUEING_MODEL (res) ((((res)->cfgte.flags) & 0x70) >> 4)#define IPR_QUEUE_FROZEN_MODEL 0
@@ -372,6 +381,37 @@ struct ipr_cmd_pkt {__be16 timeout; }__attribute__ ((packed, aligned(4))); +struct ipr_ioarcb_ata_regs { +u8 flags; +#define IPR_ATA_FLAG_PACKET_CMD 0x80 +#define IPR_ATA_FLAG_XFER_TYPE_DMA 0x40 +#define IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION 0x20 +u8 reserved[3 ]; + +__be16 data; +u8 feature; +u8 nsect; +u8 lbal; +u8 lbam; +u8 lbah; +u8 device; +u8 command; +u8 reserved2[3 ]; +u8 hob_feature; +u8 hob_nsect; +u8 hob_lbal; +u8 hob_lbam; +u8 hob_lbah; +u8 ctl; +}__attribute__ ((packed,aligned (4 ))); + +struct ipr_ioarcb_add_data { +union { +struct ipr_ioarcb_ata_regs regs; +__be32 add_cmd_parms[10 ]; + }u; +}__attribute__ ((packed,aligned (4 ))); +/* IOA Request Control Block 128 bytes */ struct ipr_ioarcb {__be32 ioarcb_host_pci_addr;
@@ -396,7 +436,7 @@ struct ipr_ioarcb {struct ipr_cmd_pkt cmd_pkt;__be32 add_cmd_parms_len; -__be32 add_cmd_parms[10 ]; +struct ipr_ioarcb_add_data add_data;; }__attribute__((packed, aligned (4)));struct ipr_ioadl_desc {
@@ -432,6 +472,21 @@ struct ipr_ioasa_gpdd {__be32 ioa_data[2 ]; }__attribute__((packed, aligned (4))); +struct ipr_ioasa_gata { +u8 error; +u8 nsect;/* Interrupt reason */ +u8 lbal; +u8 lbam; +u8 lbah; +u8 device; +u8 status; +u8 alt_status;/* ATA CTL */ +u8 hob_nsect; +u8 hob_lbal; +u8 hob_lbam; +u8 hob_lbah; +}__attribute__((packed,aligned (4 ))); +struct ipr_auto_sense {__be16 auto_sense_len;__be16 ioa_data_len;
@@ -473,6 +528,7 @@ struct ipr_ioasa {struct ipr_ioasa_vset vset;struct ipr_ioasa_af_dasd dasd;struct ipr_ioasa_gpdd gpdd; +struct ipr_ioasa_gata gata; } u;struct ipr_auto_sense auto_sense;
@@ -789,6 +845,13 @@ struct ipr_bus_attributes {u32 max_xfer_rate; }; +struct ipr_sata_port { +struct ata_port *ap; +struct ipr_resource_entry *res; +struct ipr_ioa_cfg *ioa_cfg; +struct ipr_ioasa_gata ioasa; +}; +struct ipr_resource_entry {struct ipr_config_table_entry cfgte;u8 needs_sync_complete:1 ;
@@ -798,6 +861,7 @@ struct ipr_resource_entry { u8 resetting_device:1;struct scsi_device *sdev; +struct ipr_sata_port *sata_port;struct list_head queue; };
@@ -1025,6 +1089,7 @@ struct ipr_cmnd {struct ipr_ioadl_desc ioadl[IPR_NUM_IOADL_ENTRIES ];struct list_head queue;struct scsi_cmnd *scsi_cmd; +struct ata_queued_cmd *qc;struct completion completion;struct timer_list timer;void (*done) (struct ipr_cmnd *);
@@ -1302,6 +1367,22 @@ static inline int ipr_is_gscsi(struct ip }/** +* ipr_is_gata - Determine if a resource is a generic ATA resource +* @res: resource entry struct +* +* Return value: +* 1 if GATA / 0 if not GATA +**/ +static inline int ipr_is_gata (struct ipr_resource_entry *res) +{ +if (!ipr_is_ioa_resource (res) && +IPR_RES_SUBTYPE (res) ==IPR_SUBTYPE_GENERIC_ATA ) +return 1 ; +else +return 0 ; +} + +/** * ipr_is_naca_model - Determine if a resource is using NACA queueing model * @res: resource entry struct *
drivers/scsi/ipr.c renamed from drivers/scsi/ipr.c~ipr_sata_with_libata_changes +431 -46
594 lines not on this page · raw message
drivers/scsi/Kconfig renamed from drivers/scsi/Kconfig~ipr_sata_with_libata_changes +1 -0
@@ -1071,6 +1071,7 @@ config SCSI_IPR tristate "IBM Power Linux RAID adapter support" depends on PCI && SCSI select FW_LOADER + select SCSI_SATA ---help--- This driver supports the IBM Power Linux family RAID adapters. This includes IBM pSeries 5712, 5703, 5709, and 570A, as well
drivers/scsi/Makefile renamed from drivers/scsi/Makefile~ipr_sata_with_libata_changes +1 -1
@@ -122,7 +122,7 @@ obj-$(CONFIG_SCSI_FCAL) += fcal.o obj-$(CONFIG_SCSI_CPQFCTS) += cpqfc.o obj-$(CONFIG_SCSI_LASI700) += 53c700.o lasi700.o obj-$(CONFIG_SCSI_NSP32) += nsp32.o -obj-$(CONFIG_SCSI_IPR) += ipr.o +obj-$(CONFIG_SCSI_IPR) += libata.o ipr.o obj-$(CONFIG_SCSI_IBMVSCSI) += ibmvscsi/ obj-$(CONFIG_SCSI_SATA_AHCI) += libata.o ahci.o obj-$(CONFIG_SCSI_SATA_SVW) += libata.o sata_svw.o
_
Quoted 5 lines · Brian King
Here is the ipr patch. Its queued up behind a bunch of other ipr patches I'm getting ready to push, and it won't apply without them. I uploaded the whole patchset to sourceforge, so you can just apply the whole
set and have a working tree.http://prdownloads.sourceforge.net/iprdd/ipr-sas-patches.tgz?download
Looks pretty sane to me...
Jeff
Brian King
maintainerQuoted 17 lines · Jeff Garzik
Quoted 9 lines · Bartlomiej Zolnierkiewicz
[PATCH] libata: add
ops->qc_transportfor SAS* add ->qc_transport to struct
ata_port_operations
* add defaultata_qc_transport()and update all host driversThanks to this change we won't have to depend on
host_setandhost_set->lockfor devices attached to SAS HBAs.Signed-off-by Bartlomiej Zolnierkiewicz <[email protected]>Seems sane at a quick glance, though I'm a bit disappointed we have to add yet another level of indirection to the hot path.
Quoted 8 lines
You made a good point, though, by pointing out that all the
ata_qc_xxxstuff is essentially completely inside a single lock domain.Other notes: There may be other dependencies such as wanting to reference the struct device pointer in
host_setand similar details that need handling. Also, I was planning to move some of theata_port_opsinto a separatehost_setops, since they (hooks such as ->irq_clear or ->host_stop) are really host-wide hooks, not per-port hooks.
Jeff,
Is this patch on its way into one of your trees, or should I just pick it up add it to my libata SAS patchset so you can just grab the whole patchset once it is ready?
Brian
Signature · 3 lines
Brian King eServer Storage I/O IBM Linux Technology Center
Quoted 3 lines · Brian King
Is this patch on its way into one of your trees, or should I just pick it up add it to my libata SAS patchset so you can just grab the whole patchset once it is ready?
For now let's let it live in your patchset...
Jeff