switch the SAS transport class to bsg-lib
Subsystems (7)
Hi Chaitra,
given that you have a SAS SMP passthrough test case and the code seems currently broken can you please try the patches below that rewrite the code? Chances are it still doesn't work, but I could help you to debug it.
The patches are against the latest block for-linus tree with a bsg-lib fix, so in doubt just use my branch below:
git://git.infradead.org/users/hch/block.git sas-bsg
Gitweb:
http://git.infradead.org/users/hch/block.git/shortlog/refs/heads/sas-bsg
PATCH 1/4 bsg-lib: pass the release callback through bsg_setup_queue
The SAS code will need it. Also mark the name argument const to match bsg_register_queue.
--- block/bsg-lib.c | 7 ++++--- drivers/scsi/scsi_transport_fc.c | 6 ++++-- drivers/scsi/scsi_transport_iscsi.c | 2 +- include/linux/bsg-lib.h | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-)
block/bsg-lib.c +4 -3
@@ -239,8 +239,9 @@ static void bsg_exit_rq(struct request_queue *q, struct request *req)* @job_fn: bsg job handler * @dd_job_size: size of LLD data needed for each job */ -struct request_queue *bsg_setup_queue (struct device *dev,char *name, -bsg_job_fn *job_fn,int dd_job_size) +struct request_queue *bsg_setup_queue (struct device *dev,const char *name, +bsg_job_fn *job_fn,int dd_job_size, +void (*release)(struct device *)) {struct request_queue *q;int ret;
@@ -264,7 +265,7 @@ struct request_queue *bsg_setup_queue(struct device *dev, char *name,blk_queue_softirq_done (q, bsg_softirq_done);blk_queue_rq_timeout (q,BLK_DEFAULT_SG_TIMEOUT ); - ret =bsg_register_queue (q, dev, name,NULL ); + ret =bsg_register_queue (q, dev, name, release);if (ret) {printk (KERN_ERR "%s: bsg interface failed to " "initialize - register queue\n" , dev->kobj.name);
drivers/scsi/scsi_transport_fc.c +4 -2
@@ -3763,7 +3763,8 @@ fc_bsg_hostadd(struct Scsi_Host *shost, struct fc_host_attrs *fc_host)snprintf (bsg_name,sizeof (bsg_name),"fc_host%d" , shost->host_no); - q =bsg_setup_queue (dev, bsg_name, fc_bsg_dispatch, i->f->dd_bsg_size); + q =bsg_setup_queue (dev, bsg_name, fc_bsg_dispatch, i->f->dd_bsg_size, +NULL );if (IS_ERR (q)) { dev_err(dev, "fc_host%d: bsg interface failed to initialize - setup queue\n",
@@ -3808,7 +3809,8 @@ fc_bsg_rportadd(struct Scsi_Host *shost, struct fc_rport *rport)if (!i->f->bsg_request)return -ENOTSUPP ; - q =bsg_setup_queue (dev,NULL , fc_bsg_dispatch, i->f->dd_bsg_size); + q =bsg_setup_queue (dev,NULL , fc_bsg_dispatch, i->f->dd_bsg_size, +NULL );if (IS_ERR (q)) {dev_err (dev,"failed to setup bsg queue\n" );return PTR_ERR (q);
drivers/scsi/scsi_transport_iscsi.c +1 -1
@@ -1542,7 +1542,7 @@ iscsi_bsg_host_add(struct Scsi_Host *shost, struct iscsi_cls_host *ihost)return -ENOTSUPP ;snprintf (bsg_name,sizeof (bsg_name),"iscsi_host%d" , shost->host_no); - q =bsg_setup_queue (dev, bsg_name, iscsi_bsg_host_dispatch,0 ); + q =bsg_setup_queue (dev, bsg_name, iscsi_bsg_host_dispatch,0 ,NULL );if (IS_ERR (q)) {shost_printk (KERN_ERR , shost,"bsg interface failed to " "initialize - no request queue\n" );
include/linux/bsg-lib.h +3 -2
@@ -68,8 +68,9 @@ struct bsg_job {void bsg_job_done (struct bsg_job *job,int result,unsigned int reply_payload_rcv_len); -struct request_queue *bsg_setup_queue (struct device *dev,char *name, -bsg_job_fn *job_fn,int dd_job_size); +struct request_queue *bsg_setup_queue (struct device *dev,const char *name, +bsg_job_fn *job_fn,int dd_job_size, +void (*release)(struct device *));void bsg_job_put (struct bsg_job *job);int __must_check bsg_job_get (struct bsg_job *job);
Signature · 1 line
2.11.0
PATCH 2/4 hpsa: remove the smp_handler stub
In reply to Christoph HellwigThe SAS transport class will do the right thing and not register the BSG node if now smp_handler method is present.
--- drivers/scsi/hpsa.c | 9 --------- 1 file changed, 9 deletions(-)
drivers/scsi/hpsa.c +0 -9
@@ -9443,14 +9443,6 @@ hpsa_sas_phy_speed(struct sas_phy *phy, struct sas_phy_linkrates *rates)return -EINVAL ; } -/* SMP = Serial Management Protocol */ -static int -hpsa_sas_smp_handler (struct Scsi_Host *shost,struct sas_rphy *rphy, -struct request *req) -{ -return -EINVAL ; -} -static struct sas_function_template hpsa_sas_transport_functions = { .get_linkerrors = hpsa_sas_get_linkerrors, .get_enclosure_identifier = hpsa_sas_get_enclosure_identifier,
@@ -9460,7 +9452,6 @@ static struct sas_function_template hpsa_sas_transport_functions = { .phy_setup = hpsa_sas_phy_setup, .phy_release = hpsa_sas_phy_release, .set_phy_speed = hpsa_sas_phy_speed, - .smp_handler = hpsa_sas_smp_handler, };/*
Signature · 1 line
2.11.0
PATCH 3/4 smartpqi: remove the smp_handler stub
In reply to Christoph HellwigThe SAS transport class will do the right thing and not register the BSG node if now smp_handler method is present.
--- drivers/scsi/smartpqi/smartpqi_sas_transport.c | 9 --------- 1 file changed, 9 deletions(-)
drivers/scsi/smartpqi/smartpqi_sas_transport.c +0 -9
@@ -329,14 +329,6 @@ static int pqi_sas_phy_speed(struct sas_phy *phy,return -EINVAL ; } -/* SMP = Serial Management Protocol */ - -static int pqi_sas_smp_handler (struct Scsi_Host *shost,struct sas_rphy *rphy, -struct request *req) -{ -return -EINVAL ; -} -struct sas_function_template pqi_sas_transport_functions = { .get_linkerrors = pqi_sas_get_linkerrors, .get_enclosure_identifier = pqi_sas_get_enclosure_identifier,
@@ -346,5 +338,4 @@ struct sas_function_template pqi_sas_transport_functions = { .phy_setup = pqi_sas_phy_setup, .phy_release = pqi_sas_phy_release, .set_phy_speed = pqi_sas_phy_speed, - .smp_handler = pqi_sas_smp_handler, };
Signature · 1 line
2.11.0
PATCH 4/4 scsi_transport_sas: switch to bsg-lib for SMP passthrough
In reply to Christoph HellwigSimplify the SMP passthrough code by switching it to the generic bsg-lib helpers that abstract away the details of the request code, and gets drivers out of seeing struct scsi_request.
For the libsas host SMP code there is a small behavior difference in that we now always clear the residual len for successfull commands, similar to the three other SMP handler implementations. Given that there is no partial command handling in the host SMP handler this should not matter in practice.
WARNING: completely untested.
--- drivers/message/fusion/mptsas.c | 79 +++++------ drivers/scsi/libsas/Kconfig | 1 + drivers/scsi/libsas/sas_expander.c | 70 +++++----- drivers/scsi/libsas/sas_host_smp.c | 106 ++++++-------- drivers/scsi/libsas/sas_internal.h | 12 +- drivers/scsi/mpt3sas/mpt3sas_transport.c | 230 ++++++++++++------------------- drivers/scsi/scsi_transport_sas.c | 118 ++++------------ include/scsi/libsas.h | 3 - include/scsi/scsi_transport_sas.h | 4 +- 9 files changed, 243 insertions(+), 380 deletions(-)
drivers/message/fusion/mptsas.c +37 -42
@@ -2210,33 +2210,26 @@ mptsas_get_bay_identifier(struct sas_rphy *rphy)return rc; } -static int mptsas_smp_handler (struct Scsi_Host *shost,struct sas_rphy *rphy, -struct request *req) +static void mptsas_smp_handler (struct bsg_job *job,struct Scsi_Host *shost, +struct sas_rphy *rphy) {MPT_ADAPTER *ioc = ((MPT_SCSI_HOST *) shost->hostdata)->ioc;MPT_FRAME_HDR *mf;SmpPassthroughRequest_t *smpreq; -struct request *rsp = req->next_rq; -int ret;int flagsLength;unsigned long timeleft;char *psge; -dma_addr_t dma_addr_in =0 ; -dma_addr_t dma_addr_out =0 ;u64 sas_address =0 ; - -if (!rsp) { -printk (MYIOC_s_ERR_FMT"%s: the smp response space is missing\n" , - ioc->name, __func__); -return -EINVAL ; - } +unsigned int reslen =0 ; +int ret = -EINVAL ;/* do we need to support multiple segments? */ -if (bio_multiple_segments (req->bio) || -bio_multiple_segments (rsp->bio)) { +if (job->request_payload.sg_cnt >1 || + job->reply_payload.sg_cnt >1 ) {printk (MYIOC_s_ERR_FMT"%s: multiple segments req %u, rsp %u\n" , - ioc->name, __func__,blk_rq_bytes (req),blk_rq_bytes (rsp)); -return -EINVAL ; + ioc->name, __func__, job->request_payload.payload_len, + job->reply_payload.payload_len); + goto out; } ret =mutex_lock_interruptible (&ioc->sas_mgmt.mutex);
@@ -2252,7 +2245,8 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, smpreq = (SmpPassthroughRequest_t *)mf;memset (smpreq,0 ,sizeof (*smpreq)); - smpreq->RequestDataLength =cpu_to_le16 (blk_rq_bytes (req) -4 ); + smpreq->RequestDataLength = +cpu_to_le16 (job->request_payload.payload_len -4 ); smpreq->Function =MPI_FUNCTION_SMP_PASSTHROUGH ;if (rphy)
@@ -2278,13 +2272,14 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,MPI_SGE_FLAGS_END_OF_BUFFER | MPI_SGE_FLAGS_DIRECTION) <<MPI_SGE_FLAGS_SHIFT ; - flagsLength |= (blk_rq_bytes (req) -4 ); - dma_addr_out =pci_map_single (ioc->pcidev,bio_data (req->bio), -blk_rq_bytes (req),PCI_DMA_BIDIRECTIONAL ); -if (pci_dma_mapping_error (ioc->pcidev, dma_addr_out)) +if (!dma_map_sg (&ioc->pcidev->dev, job->request_payload.sg_list, +1 ,PCI_DMA_BIDIRECTIONAL )) goto put_mf; - ioc->add_sge (psge, flagsLength, dma_addr_out); + + flagsLength |= (sg_dma_len (job->request_payload.sg_list) -4 ); + ioc->add_sge (psge, flagsLength, +sg_dma_address (job->request_payload.sg_list)); psge += ioc->SGE_size;/* response */
@@ -2294,12 +2289,13 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,MPI_SGE_FLAGS_END_OF_BUFFER ; flagsLength = flagsLength <<MPI_SGE_FLAGS_SHIFT ; - flagsLength |=blk_rq_bytes (rsp) +4 ; - dma_addr_in =pci_map_single (ioc->pcidev,bio_data (rsp->bio), -blk_rq_bytes (rsp),PCI_DMA_BIDIRECTIONAL ); -if (pci_dma_mapping_error (ioc->pcidev, dma_addr_in)) - goto unmap; - ioc->add_sge (psge, flagsLength, dma_addr_in); + +if (!dma_map_sg (&ioc->pcidev->dev, job->reply_payload.sg_list, +1 ,PCI_DMA_BIDIRECTIONAL )) + goto unmap_out; + flagsLength |=sg_dma_len (job->reply_payload.sg_list) +4 ; + ioc->add_sge (psge, flagsLength, +sg_dma_address (job->reply_payload.sg_list)); INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)mpt_put_msg_frame (mptsasMgmtCtx, ioc, mf);
@@ -2310,10 +2306,10 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,mpt_free_msg_frame (ioc, mf); mf =NULL ;if (ioc->sas_mgmt.status &MPT_MGMT_STATUS_DID_IOCRESET ) - goto unmap; + goto unmap_in;if (!timeleft)mpt_Soft_Hard_ResetHandler (ioc,CAN_SLEEP ); - goto unmap; + goto unmap_in; } mf =NULL ;
@@ -2321,23 +2317,22 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,SmpPassthroughReply_t *smprep; smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply; -memcpy (scsi_req (req)->sense, smprep,sizeof (*smprep)); -scsi_req (req)->sense_len =sizeof (*smprep); -scsi_req (req)->resid_len =0 ; -scsi_req (rsp)->resid_len -= smprep->ResponseDataLength; +memcpy (job->reply, smprep,sizeof (*smprep)); + job->reply_len =sizeof (*smprep); + reslen = smprep->ResponseDataLength; }else {printk (MYIOC_s_ERR_FMT"%s: smp passthru reply failed to be returned\n" , ioc->name, __func__); ret = -ENXIO ; } -unmap: -if (dma_addr_out) -pci_unmap_single (ioc->pcidev, dma_addr_out,blk_rq_bytes (req), -PCI_DMA_BIDIRECTIONAL ); -if (dma_addr_in) -pci_unmap_single (ioc->pcidev, dma_addr_in,blk_rq_bytes (rsp), -PCI_DMA_BIDIRECTIONAL ); + +unmap_in: +dma_unmap_sg (&ioc->pcidev->dev, job->reply_payload.sg_list,1 , +PCI_DMA_BIDIRECTIONAL ); +unmap_out: +dma_unmap_sg (&ioc->pcidev->dev, job->request_payload.sg_list,1 , +PCI_DMA_BIDIRECTIONAL ); put_mf:if (mf)mpt_free_msg_frame (ioc, mf);
@@ -2345,7 +2340,7 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy, CLEAR_MGMT_STATUS(ioc->sas_mgmt.status)mutex_unlock (&ioc->sas_mgmt.mutex); out: -return ret; +bsg_job_done (job, ret, reslen); }static struct sas_function_template mptsas_transport_functions = {
drivers/scsi/libsas/Kconfig +1 -0
@@ -26,6 +26,7 @@ config SCSI_SAS_LIBSAS tristate "SAS Domain Transport Attributes" depends on SCSI select SCSI_SAS_ATTRS + select BLK_DEV_BSGLIB help This provides transport specific helpers for SAS drivers which use the domain device construct (like the aic94xxx).
drivers/scsi/libsas/sas_expander.c +37 -33
116 lines not on this page · raw message
drivers/scsi/libsas/sas_host_smp.c +40 -66
182 lines not on this page · raw message
drivers/scsi/libsas/sas_internal.h +6 -6
@@ -81,6 +81,8 @@ int sas_queue_work(struct sas_ha_struct *ha, struct sas_work *sw);int sas_notify_lldd_dev_found (struct domain_device *);void sas_notify_lldd_dev_gone (struct domain_device *); +void sas_smp_handler (struct bsg_job *job,struct Scsi_Host *shost, +struct sas_rphy *rphy);int sas_smp_phy_control (struct domain_device *dev,int phy_id,enum phy_func phy_func,struct sas_phy_linkrates *);int sas_smp_get_phy_events (struct sas_phy *phy);
@@ -98,16 +100,14 @@ void sas_hae_reset(struct work_struct *work);void sas_free_device (struct kref *kref);#ifdef CONFIG_SCSI_SAS_HOST_SMP -extern int sas_smp_host_handler (struct Scsi_Host *shost,struct request *req, -struct request *rsp); +extern void sas_smp_host_handler (struct bsg_job *job,struct Scsi_Host *shost);#else -static inline int sas_smp_host_handler (struct Scsi_Host *shost, -struct request *req, -struct request *rsp) +static inline void sas_smp_host_handler (struct bsg_job *job, +struct Scsi_Host *shost) {shost_printk (KERN_ERR , shost,"Cannot send SMP to a sas host (not enabled in CONFIG)\n" ); -return -EINVAL ; +bsg_job_done (job, -EINVAL ,0 ); }#endif
drivers/scsi/mpt3sas/mpt3sas_transport.c +90 -140
308 lines not on this page · raw message
drivers/scsi/scsi_transport_sas.c +29 -89
165 lines not on this page · raw message
include/scsi/libsas.h +0 -3
@@ -721,9 +721,6 @@ extern int sas_slave_alloc(struct scsi_device *);extern int sas_ioctl (struct scsi_device *sdev,int cmd,void __user *arg);extern int sas_drain_work (struct sas_ha_struct *ha); -extern int sas_smp_handler (struct Scsi_Host *shost,struct sas_rphy *rphy, -struct request *req); -extern void sas_ssp_task_response (struct device *dev,struct sas_task *task,struct ssp_response_iu *iu);struct sas_phy *sas_get_local_phy (struct domain_device *dev);
include/scsi/scsi_transport_sas.h +3 -1
@@ -5,6 +5,7 @@#include <linux/types.h> #include <linux/mutex.h> #include <scsi/sas.h> +#include <linux/bsg-lib.h> struct scsi_transport_template ;struct sas_rphy ;
@@ -176,7 +177,8 @@ struct sas_function_template {int (*phy_setup)(struct sas_phy *);void (*phy_release)(struct sas_phy *);int (*set_phy_speed)(struct sas_phy *,struct sas_phy_linkrates *); -int (*smp_handler)(struct Scsi_Host *,struct sas_rphy *,struct request *); +void (*smp_handler)(struct bsg_job *,struct Scsi_Host *, +struct sas_rphy *); };
Signature · 1 line
2.11.0
RE: [PATCH 2/4] hpsa: remove the smp_handler stub
In reply to Christoph Hellwig________________________________________
From: [email protected] [[email protected]] on behalf of Christoph Hellwig [[email protected]]
Sent: Friday, August 25, 2017 8:37 AM
To: Chaitra Basappa; [email protected]
Cc: Bart Van Assche
Subject: [PATCH 2/4] hpsa: remove the smp_handler stub
EXTERNAL EMAIL
The SAS transport class will do the right thing and not register the BSG node if now smp_handler method is present.
Re: [PATCH 1/4] bsg-lib: pass the release callback through bsg_setup_queue
In reply to Christoph HellwigLooks good,
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH 2/4] hpsa: remove the smp_handler stub
In reply to Christoph HellwigLooks good,
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH 3/4] smartpqi: remove the smp_handler stub
In reply to Christoph HellwigLooks good,
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH 4/4] scsi_transport_sas: switch to bsg-lib for SMP passthrough
In reply to Christoph HellwigThe scsi_transport_sas.c part looks good, I have a nearly identical version (different remove part due to missing patch 1 of your series). For the other parts I can't tell.
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850