Re: [PATCH 02/17 v2] lpfc: Correct embedded io wq element size

2016-10-13 Thread Johannes Thumshirn
On Wed, Oct 12, 2016 at 01:14:05PM -0700, James Smart wrote:
> 
> Correct embedded io wq element size. Embedded element sizes are
> 128 byte elements
> 
> Modified per review:
> change style of selecting wqesize using local variable

This should go below the "---" line after the Signed-off-bys.
> 
> Signed-off-by: Dick Kennedy 
> Signed-off-by: James Smart 
> ---

Otherwise,
Reviewed-by: Johannes Thumshirn 

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+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
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 03/17 v2] lpfc: Fix sg_reset on SCSI device causing kernel crash

2016-10-13 Thread Johannes Thumshirn
On Wed, Oct 12, 2016 at 01:14:06PM -0700, James Smart wrote:
> 
> Fix sg_reset on SCSI device causing kernel crash
> 
> Driver could reference stale node pointers in task mgmt call.
> Changed to use resetting cmd and look up node pointer in task mgmt
> function.
> 
> Modified per review:
> Revised lpfc_send_taskmgmt() to check rdata
> 
> Signed-off-by: Dick Kennedy 
> Signed-off-by: James Smart 
> ---
>  drivers/scsi/lpfc/lpfc_scsi.c | 22 +-
>  1 file changed, 13 insertions(+), 9 deletions(-)
> 

Looks good,
Reviewed-by: Johannes Thumshirn 

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+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
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 01/17 v2] Fix few small typos in lpfc_scsi.c

2016-10-13 Thread Johannes Thumshirn
On Wed, Oct 12, 2016 at 01:14:04PM -0700, James Smart wrote:
> 
> From: "Milan P. Gandhi" 
> 
> This patch does a cleanup and fixes few small typos in lpfc_scsi.c
> 
> Signed-off-by: Milan P. Gandhi 
> Signed-off-by: James Smart 
> ---
>  

Looks good,
Reviewed-by: Johannes Thumshirn 

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+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
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 15/17 v2] lpfc: Synchronize link speed with boot driver

2016-10-13 Thread Johannes Thumshirn
On Wed, Oct 12, 2016 at 01:14:18PM -0700, James Smart wrote:
> 
> Synchronize link speed with boot driver
> 
> Link speed settings set by the boot driver are reported by the hw.
> Driver will attempt to read them, and if set, will respect their
> values.
> The driver can override the settings with its own if instructed by
> user space (via bsg), with the new values being picked up by the
> boot driver.
> 
> Signed-off-by: Dick Kennedy 
> Signed-off-by: James Smart 
> ---
>  drivers/scsi/lpfc/lpfc.h  |  4 
>  drivers/scsi/lpfc/lpfc_attr.c |  7 +-
>  drivers/scsi/lpfc/lpfc_bsg.c  | 44 +++
>  drivers/scsi/lpfc/lpfc_bsg.h  | 10 
>  drivers/scsi/lpfc/lpfc_hw4.h  |  3 +++
>  drivers/scsi/lpfc/lpfc_init.c | 54 
> +++
>  6 files changed, 121 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
> index debba5e..8a20b4e 100644
> --- a/drivers/scsi/lpfc/lpfc.h
> +++ b/drivers/scsi/lpfc/lpfc.h
> @@ -648,6 +648,10 @@ struct lpfc_hba {
>  #define HBA_FCP_IOQ_FLUSH0x8000 /* FCP I/O queues being flushed */
>  #define HBA_FW_DUMP_OP   0x1 /* Skips fn reset before FW 
> dump */
>  #define HBA_RECOVERABLE_UE   0x2 /* Firmware supports recoverable UE */
> +#define HBA_FORCED_LINK_SPEED0x4 /*
> +  * Firmware supports Forced Link Speed
> +  * capability
> +  */
>   uint32_t fcp_ring_in_use; /* When polling test if intr-hndlr active*/
>   struct lpfc_dmabuf slim2p;
>  
> diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
> index 3740e5d..39ba01a 100644
> --- a/drivers/scsi/lpfc/lpfc_attr.c
> +++ b/drivers/scsi/lpfc/lpfc_attr.c
> @@ -3668,7 +3668,12 @@ lpfc_link_speed_store(struct device *dev, struct 
> device_attribute *attr,
>   int nolip = 0;
>   const char *val_buf = buf;
>   int err;
> - uint32_t prev_val;
> + uint32_t prev_val, if_type;
> +
> + if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
> + if ((if_type == LPFC_SLI_INTF_IF_TYPE_2) &&
> + (phba->hba_flag & HBA_FORCED_LINK_SPEED))

The parentheses aren't needed here.

> + return -EPERM;
>  
>   if (!strncmp(buf, "nolip ", strlen("nolip "))) {
>   nolip = 1;
> diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
> index 05dcc2a..f9f5972 100644
> --- a/drivers/scsi/lpfc/lpfc_bsg.c
> +++ b/drivers/scsi/lpfc/lpfc_bsg.c
> @@ -5185,6 +5185,47 @@ no_dd_data:
>   return rc;
>  }
>  
> +static int
> +lpfc_forced_link_speed(struct fc_bsg_job *job)

This has an unfortunate collision with my bsg rewrite series. Please remind me
of that fact when your patches are merged and mine aren't yet. But it's a
nice test case :-).

> +{
> + struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;

Please use shost_priv() here, or if you want to make my live easy 
struct Scsi_Host *shost = job->shost;
struct lpfc_vport *vport = shost_priv(shost);

Other than that,
Reviewed-by: Johannes Thumshirn 

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+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
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 14/17 v2] lpfc: Correct panics with eh_timeout and eh_deadline

2016-10-13 Thread Johannes Thumshirn
On Wed, Oct 12, 2016 at 01:14:17PM -0700, James Smart wrote:
> 
> Correct panics with eh_timeout and eh_deadline
> 
> We were having double completions on our SLI-3 version of adapters.
> Solved by clearing our command pointer before calling scsi_done.
> 
> The eh paths potentially ran simulatenously and would see the non-null
> value and invoke scsi_done again.
> 
> Signed-off-by: Dick Kennedy 
> Signed-off-by: James Smart 
> ---
>  drivers/scsi/lpfc/lpfc_scsi.c |  6 +++---
>  drivers/scsi/lpfc/lpfc_sli.c  | 12 
>  2 files changed, 11 insertions(+), 7 deletions(-)


Looks good,
Reviewed-by: Johannes Thumshirn 

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+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
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 16/17 v2] lpfc: Fix fw download on SLI-4 FC adapters

2016-10-13 Thread Johannes Thumshirn
On Wed, Oct 12, 2016 at 01:14:19PM -0700, James Smart wrote:
> 
> Fix fw download on SLI-4 FC adapters
> 
> Driver performs a quick validation of magic numbers in the fw
> download image. Driver needed to be updated for more recent
> magic numbers.
> 
> Signed-off-by: Dick Kennedy 
> Signed-off-by: James Smart 
> ---
>  drivers/scsi/lpfc/lpfc_hw4.h  |  3 ++-
>  drivers/scsi/lpfc/lpfc_init.c | 15 ---
>  2 files changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/scsi/lpfc/lpfc_hw4.h b/drivers/scsi/lpfc/lpfc_hw4.h
> index bbdcb5a..5646699 100644
> --- a/drivers/scsi/lpfc/lpfc_hw4.h
> +++ b/drivers/scsi/lpfc/lpfc_hw4.h
> @@ -3996,7 +3996,8 @@ union lpfc_wqe128 {
>   struct gen_req64_wqe gen_req;
>  };
>  
> -#define LPFC_GROUP_OJECT_MAGIC_NUM   0xfeaa0001
> +#define LPFC_GROUP_OJECT_MAGIC_G50xfeaa0001
> +#define LPFC_GROUP_OJECT_MAGIC_G60xfeaa0003
>  #define LPFC_FILE_TYPE_GROUP 0xf7
>  #define LPFC_FILE_ID_GROUP   0xa2
>  struct lpfc_grp_hdr {
> diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
> index 53227e5..442bbb8 100644
> --- a/drivers/scsi/lpfc/lpfc_init.c
> +++ b/drivers/scsi/lpfc/lpfc_init.c
> @@ -10321,17 +10321,18 @@ lpfc_write_firmware(const struct firmware *fw, void 
> *context)
>   image = (struct lpfc_grp_hdr *)fw->data;
>  
>   INIT_LIST_HEAD(&dma_buffer_list);
> - if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) ||
> - (bf_get_be32(lpfc_grp_hdr_file_type, image) !=
> -  LPFC_FILE_TYPE_GROUP) ||
> - (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) ||
> - (be32_to_cpu(image->size) != fw->size)) {
> + if (((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_G5) &&
> +  (be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_G6)) ||
> +(bf_get_be32(lpfc_grp_hdr_file_type, image) !=
> + LPFC_FILE_TYPE_GROUP) ||
> +(be32_to_cpu(image->size) != fw->size)) {
>   lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
>   "3022 Invalid FW image found. "
> - "Magic:%x Type:%x ID:%x\n",
> + "Magic:%x Type:%x ID:%x Size %d %ld\n",
>   be32_to_cpu(image->magic_number),
>   bf_get_be32(lpfc_grp_hdr_file_type, image),
> - bf_get_be32(lpfc_grp_hdr_id, image));
> + bf_get_be32(lpfc_grp_hdr_id, image),
> + be32_to_cpu(image->size), fw->size);
>   rc = -EINVAL;
>   goto release_out;
>   }

Maybe:
u32 magic_number = be32_to_cpu(image->magic_number);
u32 lpfc_grp_hdr_file_type = bf_get_be32(lpfc_grp_hdr_file_type,
 image);
u32 lpfc_grp_hdr_id = bf_get_be32(lpfc_grp_hdr_id, image);
u32 size = be32_to_cpu(image->size);

if ((magic_number != LPFC_GROUP_OJECT_MAGIC_G5 &&
 magic_number != LPFC_GROUP_OJECT_MAGIC_G6) ||
 lpfc_grp_hdr_file_type != LPFC_FILE_TYPE_GROUP ||
 size != fw->size) {
 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
 "3022 Invalid FW image found. "
 "Magic:%x Type:%x ID:%x Size %d %ld\n", 
 lpfc_grp_hdr_file_type,
 lpfc_grp_hdr_id, size, fw->size);
 rc = -EINVAL;
 goto release_out;
}


-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+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
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 00/16] Convert FibreChannel bsg code to use bsg-lib

2016-10-13 Thread Johannes Thumshirn
On Wed, Oct 12, 2016 at 05:54:45PM +0200, Steffen Maier wrote:
> Hi Johannes,
> 
> On 10/12/2016 03:06 PM, Johannes Thumshirn wrote:
> > This series converts the current bsg usage in the FibreChannel drivers over
> > to use bsg-lib. SAS will follow once FC is in a good enough shape.
> > 
> > I did take some inspiration from a similar patchset from Mike Christie
> > dating back to 2011 but it's not a 1:1 copy. Patch 15/16 is heavily based
> > on his series and attribution is given to him in the commit message.
> > 
> > It is currently regression tested on FCoE using the 'fcns' and
> > 'fcrls' utilities.  I'm still trying to figure out how to test the other
> > LLDDs. So any pointer from the respective maintainers are appreciated
> 
> The first thing that comes to mind for zfcp is libzfcphbaapi and simply run
> its tools for starters. They issue a few different CT GLS requests.
> http://www.ibm.com/support/knowledgecenter/linuxonibm/com.ibm.linux.z.lhdd/lhdd_t_fcp_api_runappl.html
> or
> http://www.ibm.com/support/knowledgecenter/linuxonibm/com.ibm.linux.z.lgdd/lgdd_t_fcp_api_runappl.html
> (upstream:
> http://www.ibm.com/developerworks/linux/linux390/zfcp-hbaapi.html)

I'll give it a try, thanks. zfcp_show was the 1st hit on Google as well, when
I was looking for a way to test it.

> 
> Theoretically above tools could be built against libHBAAPI on other
> architectures.
> Currently I don't have anything handy for ELS requests.
> 
> Maybe there is some common code tool (possibly building directly on BSG
> IOCTL) to exercise more code paths?

Yes this is something I had in mind as well and it could become handy later on
anyways.

> 
> Just as a heads up the result of my example run (need to dig deeper why it
> crashed):
> 
> # zfcp_show -n
> 
> Local Port List:
> <<>>
> > [  799.640378] Oops: 0038 ilc:3 [#1] [  799.640387] PREEMPT  SMP [  
> > 799.640393]
> > [  799.640399] Modules linked in: nf_log_ipv6 xt_pkttype nf_log_ipv4 
> > nf_log_common xt_LOG xt_limit ip6t_REJECT nf_reject_ipv6 xt_tcpudp 
> > nf_conntrack_ipv6 nf_defrag_ipv6 ip6table_raw ipt_REJECT nf_reject_ipv4 
> > iptable_raw xt_CT iptable_filter ip6table_mangle nf_conntrack_netbios_ns 
> > nf_conntrack_broadcast nf_conntrack_ipv4 nf_defrag_ipv4 ip_tables 
> > xt_conntrack nf_conntrack ip6table_filter ip6_tables x_tables ghash_s390 
> > prng ecb aes_s390 des_s390 dm_mod des_generic sha512_s390 sha256_s390 
> > qeth_l2 sha1_s390 qeth zfcp sha_common ccwgroup qdio autofs4
> > [  799.640542] CPU: 1 PID: 2210 Comm: zfcp_show Not tainted 4.8.0fcbsg+ #6
> > [  799.640550] Hardware name: IBM  2964 N96  702
> >   (z/VM)
> > [  799.640558] task: 47b60008 task.stack: 62428000
> > [  799.640567] Krnl PSW : 0404e0018000 001b125c[  799.640581]  
> > (__lock_acquire+0x104/0x7d8)
> > [  799.640590]
> > [  799.640599]R:0 T:1 IO:0 EX:0 Key:0 M:1 W:0 P:0 AS:3 CC:2 
> > PM:0[  799.640618]  RI:0 EA:3
> > [  799.640621]
> > [  799.640621] Krnl GPRS:  0008 
> > 07f40707c004 
> > [  799.640624]  
> > 0001 
> > [  799.640627] 00355cb4 
> >  47b60008
> > [  799.640630]0300 009b17b0 
> > 6242b800 6242b778
> > [  799.640643] Krnl Code: 001b124c: b9040029lgr 
> > %r2,%r9
> > [  799.640648]001b1250: c0e5d6a4brasl   
> > %r14,1abf98
> >  #001b1256: ec28ffad007c   cgij
> > %r2,0,8,1b11b0
> > [  799.640659]   >001b125c: eb012198006aasi 
> > 408(%r2,1
> >   001b1262: 5830ba10   l   
> > %r3,2576(%r11)
> > [  799.640669]001b1266: 5030f0a4st  
> > %r3,164(%r15)
> >   001b126a: c01000e3f9db   larl
> > %r1,1e30620
> > [  799.640678]001b1270: e3101012lt  
> > %r1,0(%r1)
> > [  799.640682]
> > [  799.640684] Call Trace:
> > [  799.640687] ([] 0x)
> > [  799.640691] ([<001b21f4>] lock_acquire+0x30c/0x358)
> > [  799.640699] ([<0099fdae>] 
> > mutex_lock_interruptible_nested+0x7e/0x4f8)
> > [  799.640717] ([<03ff8047a090>] zfcp_fc_wka_port_get+0x40/0x128 [zfcp])
> > [  799.640724] ([<03ff8047bd54>] zfcp_fc_exec_bsg_job+0x244/0x2d8 
> > [zfcp])
> > [  799.640732] ([<007c8b1e>] fc_bsg_dispatch+0x20e/0x280)
> > [  799.640739] ([<006dea1a>] bsg_request_fn+0x132/0x1e0)
> > [  799.640746] ([<006b8e0a>] __blk_run_queue+0x52/0x68)
> > [  799.640751] ([<006c549a>] blk_execute_rq_nowait+0xf2/0x110)
> > [  799.640754] ([<006c557a>] blk_execute_rq+0xa2/0x110)
> > [  799.640757] ([<006de0ee>] bsg_ioctl+0x1f6/0x268)
> > [  799.640763] ([<00

[PATCH] mptscsih: remove bogus interpretation of request->ioprio

2016-10-13 Thread Christoph Hellwig
Having an I/O priority does not mean we should send all requests as
HEAD OF QUEUE tags.

Reported-by: Adam Manzanares 
Signed-off-by: Christoph Hellwig 
---
 drivers/message/fusion/mptscsih.c | 11 +++
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/message/fusion/mptscsih.c 
b/drivers/message/fusion/mptscsih.c
index 6c9fc11..08a807d 100644
--- a/drivers/message/fusion/mptscsih.c
+++ b/drivers/message/fusion/mptscsih.c
@@ -1366,15 +1366,10 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt)
/* Default to untagged. Once a target structure has been allocated,
 * use the Inquiry data to determine if device supports tagged.
 */
-   if ((vdevice->vtarget->tflags & MPT_TARGET_FLAGS_Q_YES)
-   && (SCpnt->device->tagged_supported)) {
+   if ((vdevice->vtarget->tflags & MPT_TARGET_FLAGS_Q_YES) &&
+   SCpnt->device->tagged_supported)
scsictl = scsidir | MPI_SCSIIO_CONTROL_SIMPLEQ;
-   if (SCpnt->request && SCpnt->request->ioprio) {
-   if (((SCpnt->request->ioprio & 0x7) == 1) ||
-   !(SCpnt->request->ioprio & 0x7))
-   scsictl |= MPI_SCSIIO_CONTROL_HEADOFQ;
-   }
-   } else
+   else
scsictl = scsidir | MPI_SCSIIO_CONTROL_UNTAGGED;
 
 
-- 
2.10.1.382.ga23ca1b

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] mptscsih: remove bogus interpretation of request->ioprio

2016-10-13 Thread Hannes Reinecke
On 10/13/2016 10:46 AM, Christoph Hellwig wrote:
> Having an I/O priority does not mean we should send all requests as
> HEAD OF QUEUE tags.
> 
> Reported-by: Adam Manzanares 
> Signed-off-by: Christoph Hellwig 
> ---
>  drivers/message/fusion/mptscsih.c | 11 +++
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/message/fusion/mptscsih.c 
> b/drivers/message/fusion/mptscsih.c
> index 6c9fc11..08a807d 100644
> --- a/drivers/message/fusion/mptscsih.c
> +++ b/drivers/message/fusion/mptscsih.c
> @@ -1366,15 +1366,10 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt)
>   /* Default to untagged. Once a target structure has been allocated,
>* use the Inquiry data to determine if device supports tagged.
>*/
> - if ((vdevice->vtarget->tflags & MPT_TARGET_FLAGS_Q_YES)
> - && (SCpnt->device->tagged_supported)) {
> + if ((vdevice->vtarget->tflags & MPT_TARGET_FLAGS_Q_YES) &&
> + SCpnt->device->tagged_supported)
>   scsictl = scsidir | MPI_SCSIIO_CONTROL_SIMPLEQ;
> - if (SCpnt->request && SCpnt->request->ioprio) {
> - if (((SCpnt->request->ioprio & 0x7) == 1) ||
> - !(SCpnt->request->ioprio & 0x7))
> - scsictl |= MPI_SCSIIO_CONTROL_HEADOFQ;
> - }
> - } else
> + else
>   scsictl = scsidir | MPI_SCSIIO_CONTROL_UNTAGGED;
>  
>  
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 01/16] scsi: Get rid of struct fc_bsg_buffer

2016-10-13 Thread Hannes Reinecke
On 10/12/2016 03:06 PM, Johannes Thumshirn wrote:
> struct fc_bsg_buffer is just a clone of struct bsg_buffer from bsg-lib,
> so use this one instead.
> 
> Signed-off-by: Johannes Thumshirn 
> ---
>  drivers/scsi/lpfc/lpfc_bsg.c |  3 ++-
>  drivers/scsi/scsi_transport_fc.c |  2 +-
>  include/scsi/scsi_transport_fc.h | 12 +++-
>  3 files changed, 6 insertions(+), 11 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [patch] zfcp: spin_lock_irqsave() is not nestable

2016-10-13 Thread Steffen Maier
Dan, many thanks for catching this! Sparse did not notice, is there 
other tooling that would find such things?


James, Martin, could you please queue this as fix for one of my patches 
that went into the 4.9 merge window, so for 4.9-rc I guess?

https://lkml.kernel.org/r/20161013085358.GH16198@mwanda
or
https://lkml.org/lkml/2016/10/13/94

On 10/13/2016 10:53 AM, Dan Carpenter wrote:

We accidentally overwrite the original saved value of "flags" so that
we can't re-enable IRQs at the end of the function.  Presumably this
function is mostly called with IRQs disabled or it would be obvious in
testing.

Fixes: aceeffbb59bb ("zfcp: trace full payload of all SAN records 
(req,resp,iels)")


Cc:  #2.6.38+


Signed-off-by: Dan Carpenter 


Signed-off-by: Steffen Maier 



diff --git a/drivers/s390/scsi/zfcp_dbf.c b/drivers/s390/scsi/zfcp_dbf.c
index 637cf89..5810019 100644
--- a/drivers/s390/scsi/zfcp_dbf.c
+++ b/drivers/s390/scsi/zfcp_dbf.c
@@ -384,7 +384,7 @@ void zfcp_dbf_san(char *tag, struct zfcp_dbf *dbf,
/* if (len > rec_len):
 * dump data up to cap_len ignoring small duplicate in rec->payload
 */
-   spin_lock_irqsave(&dbf->pay_lock, flags);
+   spin_lock(&dbf->pay_lock);
memset(payload, 0, sizeof(*payload));
memcpy(payload->area, paytag, ZFCP_DBF_TAG_LEN);
payload->fsf_req_id = req_id;



--
Mit freundlichen Grüßen / Kind regards
Steffen Maier

Linux on z Systems Development

IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 02/16] scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-10-13 Thread Hannes Reinecke
On 10/12/2016 03:06 PM, Johannes Thumshirn wrote:
> Don't use fc_bsg_job::request and fc_bsg_job::reply directly, but use
> helper variables bsg_request and bsg_reply. This will be helpfull  when
> transitioning to bsg-lib.
> 
> Signed-off-by: Johannes Thumshirn 
> ---
>  drivers/s390/scsi/zfcp_fc.c  |   9 +-
>  drivers/scsi/bfa/bfad_bsg.c  |  40 +++---
>  drivers/scsi/ibmvscsi/ibmvfc.c   |  22 ++--
>  drivers/scsi/libfc/fc_lport.c|  23 ++--
>  drivers/scsi/lpfc/lpfc_bsg.c | 194 +---
>  drivers/scsi/qla2xxx/qla_bsg.c   | 264 
> ++-
>  drivers/scsi/qla2xxx/qla_iocb.c  |   5 +-
>  drivers/scsi/qla2xxx/qla_isr.c   |  46 ---
>  drivers/scsi/qla2xxx/qla_mr.c|  10 +-
>  drivers/scsi/scsi_transport_fc.c |  37 +++---
>  10 files changed, 387 insertions(+), 263 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [patch] zfcp: spin_lock_irqsave() is not nestable

2016-10-13 Thread Dan Carpenter
On Thu, Oct 13, 2016 at 12:49:18PM +0200, Steffen Maier wrote:
> Dan, many thanks for catching this! Sparse did not notice, is there
> other tooling that would find such things?

This was a Smatch warning.

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 03/16] scsi: fc: Export fc_bsg_jobdone and use it in FC drivers

2016-10-13 Thread Hannes Reinecke
On 10/12/2016 03:06 PM, Johannes Thumshirn wrote:
> Export fc_bsg_jobdone so drivers can use it directly instead of doing
> the round-trip via struct fc_bsg_job::job_done() and use it in the LLDDs.
> 
> As we've converted all LLDDs over to use fc_bsg_jobdone() directly,
> we can remove the function pointer from struct fc_bsg_job as well.
> 
> Signed-off-by: Johannes Thumshirn 
> ---
>  drivers/s390/scsi/zfcp_fc.c  |  2 +-
>  drivers/scsi/bfa/bfad_bsg.c  |  4 ++--
>  drivers/scsi/ibmvscsi/ibmvfc.c   |  2 +-
>  drivers/scsi/libfc/fc_lport.c|  4 ++--
>  drivers/scsi/lpfc/lpfc_bsg.c | 38 +-
>  drivers/scsi/qla2xxx/qla_bsg.c   | 44 
> 
>  drivers/scsi/scsi_transport_fc.c |  5 ++---
>  include/scsi/scsi_transport_fc.h |  2 +-
>  8 files changed, 50 insertions(+), 51 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 04/16] scsi: Unify interfaces of fc_bsg_jobdone and bsg_job_done

2016-10-13 Thread Hannes Reinecke
On 10/12/2016 03:06 PM, Johannes Thumshirn wrote:
> Unify the interfaces of fc_bsg_jobdone and bsg_job_done. This will reduce the
> diff when moving from 'struct fc_bsg_job' to a plain 'struct bsg_job' later
> on.
> 
> Signed-off-by: Johannes Thumshirn 
> ---
>  drivers/s390/scsi/zfcp_fc.c  |  2 +-
>  drivers/scsi/bfa/bfad_bsg.c  |  6 ++--
>  drivers/scsi/ibmvscsi/ibmvfc.c   |  3 +-
>  drivers/scsi/libfc/fc_lport.c|  6 ++--
>  drivers/scsi/lpfc/lpfc_bsg.c | 68 
> +++-
>  drivers/scsi/qla2xxx/qla_bsg.c   | 66 +-
>  drivers/scsi/scsi_transport_fc.c | 22 +++--
>  include/scsi/scsi_transport_fc.h |  3 +-
>  8 files changed, 116 insertions(+), 60 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 06/16] scsi: fc: provide fc_bsg_to_rport() helper

2016-10-13 Thread Hannes Reinecke
On 10/12/2016 03:06 PM, Johannes Thumshirn wrote:
> Provide fc_bsg_to_rport() helper that will become handy when we're moving
> from struct fc_bsg_job to a plain struct bsg_job. Also move all LLDDs to use
> the new helper.
> 
> Signed-off-by: Johannes Thumshirn 
> ---
>  drivers/s390/scsi/zfcp_fc.c  | 5 +++--
>  drivers/scsi/ibmvscsi/ibmvfc.c   | 2 +-
>  drivers/scsi/libfc/fc_lport.c| 4 ++--
>  drivers/scsi/lpfc/lpfc_bsg.c | 4 ++--
>  drivers/scsi/qla2xxx/qla_bsg.c   | 4 ++--
>  drivers/scsi/scsi_transport_fc.c | 3 ++-
>  include/scsi/scsi_transport_fc.h | 5 +
>  7 files changed, 17 insertions(+), 10 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 07/16] scsi: libfc: don't set FC_RQST_STATE_DONE before calling fc_bsg_jobdone()

2016-10-13 Thread Hannes Reinecke
On 10/12/2016 03:06 PM, Johannes Thumshirn wrote:
> Don't set FC_RQST_STATE_DONE before calling fc_bsg_jobdone() as
> fc_bsg_jobdone() calls blk_complete_requeust() which raises a soft-IRQ that
> ends up in fc_bsg_sofirq_done() and fc_bsg_softirq_done() sets the
> FC_RQST_STATE_DONE flag.
> 
> Signed-off-by: Johannes Thumshirn 
> ---
>  drivers/scsi/libfc/fc_lport.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
> index 156708a..53d13721 100644
> --- a/drivers/scsi/libfc/fc_lport.c
> +++ b/drivers/scsi/libfc/fc_lport.c
> @@ -1911,7 +1911,6 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
> fc_frame *fp,
>   bsg_reply->result = (PTR_ERR(fp) == -FC_EX_CLOSED) ?
>   -ECONNABORTED : -ETIMEDOUT;
>   job->reply_len = sizeof(uint32_t);
> - job->state_flags |= FC_RQST_STATE_DONE;
>   fc_bsg_jobdone(job, bsg_reply->result,
>  bsg_reply->reply_payload_rcv_len);
>   kfree(info);
> @@ -1947,7 +1946,6 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
> fc_frame *fp,
>   bsg_reply->reply_payload_rcv_len =
>   job->reply_payload.payload_len;
>   bsg_reply->result = 0;
> - job->state_flags |= FC_RQST_STATE_DONE;
>   fc_bsg_jobdone(job, bsg_reply->result,
>  bsg_reply->reply_payload_rcv_len);
>   kfree(info);
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 08/16] scsi: fc: implement kref backed reference counting

2016-10-13 Thread Hannes Reinecke
On 10/12/2016 03:06 PM, Johannes Thumshirn wrote:
> Implement kref backed reference counting instead of rolling our own. This
> elimnates the need of the following fields in 'struct fc_bsg_job':
> * ref_cnt
> * state_flags
> * job_lock
> bringing us close to unification of 'struct fc_bsg_job' and 'struct bsg_job'.
> 
> Signed-off-by: Johannes Thumshirn 
> ---
>  drivers/scsi/scsi_transport_fc.c | 38 +-
>  include/scsi/scsi_transport_fc.h |  4 +---
>  2 files changed, 10 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/scsi/scsi_transport_fc.c 
> b/drivers/scsi/scsi_transport_fc.c
> index 96b3a2e..b0e28af 100644
> --- a/drivers/scsi/scsi_transport_fc.c
> +++ b/drivers/scsi/scsi_transport_fc.c
> @@ -3560,16 +3560,9 @@ fc_vport_sched_delete(struct work_struct *work)
>   * @job: fc_bsg_job that is to be torn down
>   */
>  static void
> -fc_destroy_bsgjob(struct fc_bsg_job *job)
> +fc_destroy_bsgjob(struct kref *kref)
>  {
> - unsigned long flags;
> -
> - spin_lock_irqsave(&job->job_lock, flags);
> - if (job->ref_cnt) {
> - spin_unlock_irqrestore(&job->job_lock, flags);
> - return;
> - }
> - spin_unlock_irqrestore(&job->job_lock, flags);
> + struct fc_bsg_job *job = container_of(kref, struct fc_bsg_job, kref);
>  
>   put_device(job->dev);   /* release reference for the request */
>  
> @@ -3620,15 +3613,9 @@ EXPORT_SYMBOL_GPL(fc_bsg_jobdone);
>  static void fc_bsg_softirq_done(struct request *rq)
>  {
>   struct fc_bsg_job *job = rq->special;
> - unsigned long flags;
> -
> - spin_lock_irqsave(&job->job_lock, flags);
> - job->state_flags |= FC_RQST_STATE_DONE;
> - job->ref_cnt--;
> - spin_unlock_irqrestore(&job->job_lock, flags);
>  
>   blk_end_request_all(rq, rq->errors);
> - fc_destroy_bsgjob(job);
> + kref_put(&job->kref, fc_destroy_bsgjob);
>  }
>  
>  /**
Hmm. blk_end_request_all() (potentially) triggers a recursion into all
.end_io callbacks, which might end up doing god-knows-what.
With some delays in doing so
During that time we have no idea that bsg_softirq_done() is actually
running, and we might clash with eg. timeouts or somesuch.

Maybe it's an idea to move blk_end_request_all into the kref destroy
callback; that way we're guaranteed to call it only once and would avoid
this situation.

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 09/16] block: add reference counting for struct bsg_job

2016-10-13 Thread Hannes Reinecke
On 10/12/2016 03:06 PM, Johannes Thumshirn wrote:
> Add reference counting to 'struct bsg_job' so we can implement a reuqest
> timeout handler for bsg_jobs, which is needed for Fibre Channel.
> 
> Signed-off-by: Johannes Thumshirn 
> ---
>  block/bsg-lib.c | 7 +--
>  include/linux/bsg-lib.h | 2 ++
>  2 files changed, 7 insertions(+), 2 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 10/16] scsi: change FC drivers to use 'struct bsg_job'

2016-10-13 Thread Hannes Reinecke
On 10/12/2016 03:06 PM, Johannes Thumshirn wrote:
> Change FC drivers to use 'struct bsg_job' from bsg-lib.h instead of 'struct
> fc_bsg_job' from scsi_transport_fc.h and remove 'struct fc_bsg_job'.
> 
> Signed-off-by: Johannes Thumshirn 
> ---
>  drivers/s390/scsi/zfcp_ext.h |  4 +--
>  drivers/s390/scsi/zfcp_fc.c  | 15 
>  drivers/scsi/bfa/bfad_bsg.c  | 10 +++---
>  drivers/scsi/bfa/bfad_im.h   |  4 +--
>  drivers/scsi/ibmvscsi/ibmvfc.c   |  9 ++---
>  drivers/scsi/libfc/fc_lport.c| 10 +++---
>  drivers/scsi/lpfc/lpfc_bsg.c | 74 
> 
>  drivers/scsi/lpfc/lpfc_crtn.h|  4 +--
>  drivers/scsi/qla2xxx/qla_bsg.c   | 61 +
>  drivers/scsi/qla2xxx/qla_def.h   |  2 +-
>  drivers/scsi/qla2xxx/qla_gbl.h   |  4 +--
>  drivers/scsi/qla2xxx/qla_iocb.c  |  8 ++---
>  drivers/scsi/qla2xxx/qla_isr.c   |  6 ++--
>  drivers/scsi/qla2xxx/qla_mr.c|  5 +--
>  drivers/scsi/scsi_transport_fc.c | 20 +--
>  include/scsi/libfc.h |  2 +-
>  include/scsi/scsi_transport_fc.h | 63 ++
>  17 files changed, 138 insertions(+), 163 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 11/16] scsi: fc: Use bsg_destroy_job

2016-10-13 Thread Hannes Reinecke
On 10/12/2016 03:06 PM, Johannes Thumshirn wrote:
> fc_destroy_bsgjob() and bsg_destroy_job() are now 1:1 copies, so use the
> later.
> 
> Signed-off-by: Johannes Thumshirn 
> ---
>  block/bsg-lib.c  |  3 ++-
>  drivers/scsi/scsi_transport_fc.c | 20 ++--
>  include/linux/bsg-lib.h  |  1 +
>  3 files changed, 5 insertions(+), 19 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 13/16] scsi: fc: use bsg_job_done

2016-10-13 Thread Hannes Reinecke
On 10/12/2016 03:06 PM, Johannes Thumshirn wrote:
> fc_bsg_jobdone() and bsg_job_done() are 1:1 copies now so use the bsg-lib one
> instead of the FC private implementation.
> 
> Signed-off-by: Johannes Thumshirn 
> ---
>  drivers/s390/scsi/zfcp_fc.c  |  2 +-
>  drivers/scsi/bfa/bfad_bsg.c  |  4 ++--
>  drivers/scsi/ibmvscsi/ibmvfc.c   |  2 +-
>  drivers/scsi/libfc/fc_lport.c|  4 ++--
>  drivers/scsi/lpfc/lpfc_bsg.c | 38 +-
>  drivers/scsi/qla2xxx/qla_bsg.c   | 44 
> 
>  drivers/scsi/scsi_transport_fc.c | 41 +++--
>  include/scsi/scsi_transport_fc.h |  2 --
>  8 files changed, 50 insertions(+), 87 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 14/16] block: add bsg_job_put() and bsg_job_get()

2016-10-13 Thread Hannes Reinecke
On 10/12/2016 03:06 PM, Johannes Thumshirn wrote:
> Add bsg_job_put() and bsg_job_get() so don't need to export
> bsg_destroy_job() any more.
> 
> Signed-off-by: Johannes Thumshirn 
> ---
>  block/bsg-lib.c  | 17 ++---
>  drivers/scsi/scsi_transport_fc.c |  4 ++--
>  include/linux/bsg-lib.h  |  3 ++-
>  3 files changed, 18 insertions(+), 6 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 15/16] scsi: fc: move FC transport's bsg code to bsg-lib

2016-10-13 Thread Hannes Reinecke
On 10/12/2016 03:06 PM, Johannes Thumshirn wrote:
> Now that all conversions are done, move the FibreChannel bsg code over to the
> bsg library. Note that CONFIG_SCSI_FC_ATTRS now needs to select BLK_DEV_BSGLIB
> in order to build correctly.
> 
> This patch is derived from work done by Mike Christie in 2011 [1] but only the
> iscsi parts got merged back then.
> 
> [1] http://marc.info/?l=linux-scsi&m=131149780921009&w=2
> 
> Signed-off-by: Johannes Thumshirn 
> ---
>  drivers/scsi/Kconfig |   1 +
>  drivers/scsi/scsi_transport_fc.c | 287 
> ++-
>  2 files changed, 44 insertions(+), 244 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 12/16] scsi: fc: use bsg_softirq_done

2016-10-13 Thread Hannes Reinecke
On 10/12/2016 03:06 PM, Johannes Thumshirn wrote:
> bsg_softirq_done() and fc_bsg_softirq_done() are copies of each other, so
> ditch the fc specific one.
> 
> Signed-off-by: Johannes Thumshirn 
> ---
>  block/bsg-lib.c  |  3 ++-
>  drivers/scsi/scsi_transport_fc.c | 16 ++--
>  include/linux/bsg-lib.h  |  1 +
>  3 files changed, 5 insertions(+), 15 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Patch: [Open-FCoE] Revert commit 3e22760d4db6fd89e0be46c3d132390a251da9c6 due to performance issues

2016-10-13 Thread Laurence Oberman


Hello

This patch reverts commit 3e22760d4db6fd89e0be46c3d132390a251da9c6.

This revert came about because of efforts by Ewan Milne, Curtis Taylor and I.
In researching this issue, significant performance issues were seen on large 
CPU count 
systems using the software FCOE stack.
Hannes also weighed in.

The same was not apparent on much smaller low count CPU systems.
The behavior introduced by commit 3e22760d4db6fd89e0be46c3d132390a251da9c6 
lands sup with large
count CPU systems seeing continual blk_requeue_request() calls due to 
ML_QUEUE_HOST_BUSY.

>From Ewan:

fc_exch_alloc() used to try all the available exchange managers in the
list for an available exchange id, but this was changed in 2010 so that
if the first matched exchange manager couldn't allocate one, it fails
and we end up returning host busy.  This was due to commit:

Setting the ddp_min module parameter to fcoe to 128MB prevents the ->match
function from permitting the use of the offload exchange manager for the frame,
and we no longer see the problem with host busy status, since it uses the
larger non-offloaded pool.

Reverting commit 3e22760d4db6fd89e0be46c3d132390a251da9c6 was tested to also
prevent the host busy issue due to failing allocations.

Suggested-by: Ewan Milne 
Suggested-by: Curtis Taylor 
Tested-by: Laurence Oberman 
Signed-off-by: Laurence Oberman 

diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
index e72673b..d5c4048 100644
--- a/drivers/scsi/libfc/fc_exch.c
+++ b/drivers/scsi/libfc/fc_exch.c
@@ -892,10 +892,15 @@ static inline struct fc_exch *fc_exch_alloc(struct 
fc_lport *lport,
struct fc_frame *fp)
 {
struct fc_exch_mgr_anchor *ema;
+   struct fc_exch *ep;
 
-   list_for_each_entry(ema, &lport->ema_list, ema_list)
-   if (!ema->match || ema->match(fp))
-   return fc_exch_em_alloc(lport, ema->mp);
+   list_for_each_entry(ema, &lport->ema_list, ema_list) {
+   if (!ema->match || ema->match(fp)) {
+   ep = fc_exch_em_alloc(lport, ema->mp);
+   if (ep)
+   return ep;
+   }
+   }
return NULL;
 }
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Patch: [Open-FCoE] Revert commit 3e22760d4db6fd89e0be46c3d132390a251da9c6 due to performance issues

2016-10-13 Thread Hannes Reinecke
On 10/13/2016 02:43 PM, Laurence Oberman wrote:
> 
> 
> Hello
> 
> This patch reverts commit 3e22760d4db6fd89e0be46c3d132390a251da9c6.
> 
> This revert came about because of efforts by Ewan Milne, Curtis Taylor and I.
> In researching this issue, significant performance issues were seen on large 
> CPU count 
> systems using the software FCOE stack.
> Hannes also weighed in.
> 
> The same was not apparent on much smaller low count CPU systems.
> The behavior introduced by commit 3e22760d4db6fd89e0be46c3d132390a251da9c6 
> lands sup with large
> count CPU systems seeing continual blk_requeue_request() calls due to 
> ML_QUEUE_HOST_BUSY.
> 
> From Ewan:
> 
> fc_exch_alloc() used to try all the available exchange managers in the
> list for an available exchange id, but this was changed in 2010 so that
> if the first matched exchange manager couldn't allocate one, it fails
> and we end up returning host busy.  This was due to commit:
> 
> Setting the ddp_min module parameter to fcoe to 128MB prevents the ->match
> function from permitting the use of the offload exchange manager for the 
> frame,
> and we no longer see the problem with host busy status, since it uses the
> larger non-offloaded pool.
> 
> Reverting commit 3e22760d4db6fd89e0be46c3d132390a251da9c6 was tested to also
> prevent the host busy issue due to failing allocations.
> 
> Suggested-by: Ewan Milne 
> Suggested-by: Curtis Taylor 
> Tested-by: Laurence Oberman 
> Signed-off-by: Laurence Oberman 
> 
> diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
> index e72673b..d5c4048 100644
> --- a/drivers/scsi/libfc/fc_exch.c
> +++ b/drivers/scsi/libfc/fc_exch.c
> @@ -892,10 +892,15 @@ static inline struct fc_exch *fc_exch_alloc(struct 
> fc_lport *lport,
>   struct fc_frame *fp)
>  {
>   struct fc_exch_mgr_anchor *ema;
> + struct fc_exch *ep;
>  
> - list_for_each_entry(ema, &lport->ema_list, ema_list)
> - if (!ema->match || ema->match(fp))
> - return fc_exch_em_alloc(lport, ema->mp);
> + list_for_each_entry(ema, &lport->ema_list, ema_list) {
> + if (!ema->match || ema->match(fp)) {
> + ep = fc_exch_em_alloc(lport, ema->mp);
> + if (ep)
> + return ep;
> + }
> + }
>   return NULL;
>  }
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 16/16] block: unexport bsg_softirq_done() again

2016-10-13 Thread Hannes Reinecke
On 10/12/2016 03:06 PM, Johannes Thumshirn wrote:
> Unexport bsg_softirq_done() again, we don't need it outside of bsg-lib.c
> anymore now that scsi_transport_fc is a pure bsg-lib client.
> 
> Signed-off-by: Johannes Thumshirn 
> ---
>  block/bsg-lib.c | 3 +--
>  include/linux/bsg-lib.h | 1 -
>  2 files changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/block/bsg-lib.c b/block/bsg-lib.c
> index 46a4fee..4ac0ade 100644
> --- a/block/bsg-lib.c
> +++ b/block/bsg-lib.c
> @@ -93,14 +93,13 @@ EXPORT_SYMBOL_GPL(bsg_job_done);
>   * bsg_softirq_done - softirq done routine for destroying the bsg requests
>   * @rq: BSG request that holds the job to be destroyed
>   */
> -void bsg_softirq_done(struct request *rq)
> +static void bsg_softirq_done(struct request *rq)
>  {
>   struct bsg_job *job = rq->special;
>  
>   blk_end_request_all(rq, rq->errors);
>   bsg_job_put(job);
>  }
> -EXPORT_SYMBOL_GPL(bsg_softirq_done);
>  
>  static int bsg_map_buffer(struct bsg_buffer *buf, struct request *req)
>  {
> diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
> index b708db9..657a718 100644
> --- a/include/linux/bsg-lib.h
> +++ b/include/linux/bsg-lib.h
> @@ -69,7 +69,6 @@ void bsg_job_done(struct bsg_job *job, int result,
>  int bsg_setup_queue(struct device *dev, struct request_queue *q, char *name,
>   bsg_job_fn *job_fn, int dd_job_size);
>  void bsg_request_fn(struct request_queue *q);
> -void bsg_softirq_done(struct request *rq);
>  void bsg_job_put(struct bsg_job *job);
>  int __must_check bsg_job_get(struct bsg_job *job);
>  
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 00/10] mm: adjust get_user_pages* functions to explicitly pass FOLL_* flags

2016-10-13 Thread Christian König

Am 13.10.2016 um 02:20 schrieb Lorenzo Stoakes:

This patch series adjusts functions in the get_user_pages* family such that
desired FOLL_* flags are passed as an argument rather than implied by flags.

The purpose of this change is to make the use of FOLL_FORCE explicit so it is
easier to grep for and clearer to callers that this flag is being used. The use
of FOLL_FORCE is an issue as it overrides missing VM_READ/VM_WRITE flags for the
VMA whose pages we are reading from/writing to, which can result in surprising
behaviour.

The patch series came out of the discussion around commit 38e0885, which
addressed a BUG_ON() being triggered when a page was faulted in with PROT_NONE
set but having been overridden by FOLL_FORCE. do_numa_page() was run on the
assumption the page _must_ be one marked for NUMA node migration as an actual
PROT_NONE page would have been dealt with prior to this code path, however
FOLL_FORCE introduced a situation where this assumption did not hold.

See https://marc.info/?l=linux-mm&m=147585445805166 for the patch proposal.

Lorenzo Stoakes (10):
   mm: remove write/force parameters from __get_user_pages_locked()
   mm: remove write/force parameters from __get_user_pages_unlocked()
   mm: replace get_user_pages_unlocked() write/force parameters with gup_flags
   mm: replace get_user_pages_locked() write/force parameters with gup_flags
   mm: replace get_vaddr_frames() write/force parameters with gup_flags
   mm: replace get_user_pages() write/force parameters with gup_flags
   mm: replace get_user_pages_remote() write/force parameters with gup_flags
   mm: replace __access_remote_vm() write parameter with gup_flags
   mm: replace access_remote_vm() write parameter with gup_flags
   mm: replace access_process_vm() write parameter with gup_flags


Patch number 6 in this series (which touches drivers I co-maintain) is 
Acked-by: Christian König .


In general looks like a very nice cleanup to me, but I'm not enlightened 
enough to full judge.


Regards,
Christian.



  arch/alpha/kernel/ptrace.c |  9 ++--
  arch/blackfin/kernel/ptrace.c  |  5 ++-
  arch/cris/arch-v32/drivers/cryptocop.c |  4 +-
  arch/cris/arch-v32/kernel/ptrace.c |  4 +-
  arch/ia64/kernel/err_inject.c  |  2 +-
  arch/ia64/kernel/ptrace.c  | 14 +++---
  arch/m32r/kernel/ptrace.c  | 15 ---
  arch/mips/kernel/ptrace32.c|  5 ++-
  arch/mips/mm/gup.c |  2 +-
  arch/powerpc/kernel/ptrace32.c |  5 ++-
  arch/s390/mm/gup.c |  3 +-
  arch/score/kernel/ptrace.c | 10 +++--
  arch/sh/mm/gup.c   |  3 +-
  arch/sparc/kernel/ptrace_64.c  | 24 +++
  arch/sparc/mm/gup.c|  3 +-
  arch/x86/kernel/step.c |  3 +-
  arch/x86/mm/gup.c  |  2 +-
  arch/x86/mm/mpx.c  |  5 +--
  arch/x86/um/ptrace_32.c|  3 +-
  arch/x86/um/ptrace_64.c|  3 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c|  7 ++-
  drivers/gpu/drm/etnaviv/etnaviv_gem.c  |  7 ++-
  drivers/gpu/drm/exynos/exynos_drm_g2d.c|  3 +-
  drivers/gpu/drm/i915/i915_gem_userptr.c|  6 ++-
  drivers/gpu/drm/radeon/radeon_ttm.c|  3 +-
  drivers/gpu/drm/via/via_dmablit.c  |  4 +-
  drivers/infiniband/core/umem.c |  6 ++-
  drivers/infiniband/core/umem_odp.c |  7 ++-
  drivers/infiniband/hw/mthca/mthca_memfree.c|  2 +-
  drivers/infiniband/hw/qib/qib_user_pages.c |  3 +-
  drivers/infiniband/hw/usnic/usnic_uiom.c   |  5 ++-
  drivers/media/pci/ivtv/ivtv-udma.c |  4 +-
  drivers/media/pci/ivtv/ivtv-yuv.c  |  5 ++-
  drivers/media/platform/omap/omap_vout.c|  2 +-
  drivers/media/v4l2-core/videobuf-dma-sg.c  |  7 ++-
  drivers/media/v4l2-core/videobuf2-memops.c |  6 ++-
  drivers/misc/mic/scif/scif_rma.c   |  3 +-
  drivers/misc/sgi-gru/grufault.c|  2 +-
  drivers/platform/goldfish/goldfish_pipe.c  |  3 +-
  drivers/rapidio/devices/rio_mport_cdev.c   |  3 +-
  drivers/scsi/st.c  |  5 +--
  .../interface/vchiq_arm/vchiq_2835_arm.c   |  3 +-
  .../vc04_services/interface/vchiq_arm/vchiq_arm.c  |  3 +-
  drivers/video/fbdev/pvr2fb.c   |  4 +-
  drivers/virt/fsl_hypervisor.c  |  4 +-
  fs/exec.c  |  9 +++-
  fs/proc/base.c | 19 +---
  include/linux/mm.h | 18 

[PATCH 04/24] libfc: use configured rport E_D_TOV

2016-10-13 Thread Hannes Reinecke
If fc_rport_error_retry() is attempting to retry the remote
port state we should be waiting for the configured e_d_tov
value rather than the default.

Signed-off-by: Hannes Reinecke 
Acked-by: Johannes Thumshirn 
---
 drivers/scsi/libfc/fc_rport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c
index bcd1cd3..bb7e9d9 100644
--- a/drivers/scsi/libfc/fc_rport.c
+++ b/drivers/scsi/libfc/fc_rport.c
@@ -662,7 +662,7 @@ static void fc_rport_error(struct fc_rport_priv *rdata, 
struct fc_frame *fp)
 static void fc_rport_error_retry(struct fc_rport_priv *rdata,
 struct fc_frame *fp)
 {
-   unsigned long delay = msecs_to_jiffies(FC_DEF_E_D_TOV);
+   unsigned long delay = msecs_to_jiffies(rdata->e_d_tov);
struct fc_lport *lport = rdata->local_port;
 
/* make sure this isn't an FC_EX_CLOSED error, never retry those */
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 03/24] libfc: use configured lport R_A_TOV

2016-10-13 Thread Hannes Reinecke
We should be using the configured R_A_TOV value when sending the
exchange.

Signed-off-by: Hannes Reinecke 
Acked-by: Johannes Thumshirn 
---
 drivers/scsi/libfc/fc_exch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
index b4bdc90..5e0a57f 100644
--- a/drivers/scsi/libfc/fc_exch.c
+++ b/drivers/scsi/libfc/fc_exch.c
@@ -2135,7 +2135,7 @@ static struct fc_seq *fc_exch_seq_send(struct fc_lport 
*lport,
ep->resp = resp;
ep->destructor = destructor;
ep->arg = arg;
-   ep->r_a_tov = FC_DEF_R_A_TOV;
+   ep->r_a_tov = lport->r_a_tov;
ep->lp = lport;
sp = &ep->seq;
 
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 00/24] FCoE VN2VN fixes, part two

2016-10-13 Thread Hannes Reinecke
Hi all,

here's now the second part of my FCoE VN2VN patchset.
The key points are:
- Configurable R_A_TOV/E_D_TOV
- Rework PRLI handling to fix a longstanding bug
- Correctly handle timed-out xids

Additionally there are some minor fixes to get things to work
when running with FCoE over virtio.

Patches are relative to mkp/4.10/scsi-queue.

As usual, comments and reviews are welcome.

Hannes Reinecke (24):
  libfc: additional debugging messages
  libfc: spurious I/O error under high load
  libfc: use configured lport R_A_TOV
  libfc: use configured rport E_D_TOV
  libfc: sanitize E_D_TOV and R_A_TOV setting
  fcoe: make R_A_TOV and E_D_TOV configurable
  libfc: do not overwrite DID_TIME_OUT status
  libfc: use error code for fc_rport_error()
  libfc: Implement RTV responder
  libfc: Rework PRLI handling
  libfc: Return LS_RJT_BUSY for PRLI in status PLOGI
  libfc: Clarify ramp-down messages
  libfc: safeguard against invalid exchange index
  libfc: quarantine timed out xids
  libfc: don't fail sequence abort for completed exchanges
  libfc: Do not drop out-of-order frames
  libfc: reset timeout on queue full
  libfc: wait for E_D_TOV when out-of-order sequence is received
  libfc: Check xid when looking up REC exchanges
  fcoe: set default TC priority
  fcoe: catch invalid values for the 'enabled' attribute
  fcoe: FIP debugging
  fcoe: correct sending FIP VLAN packets on VLAN 0
  fcoe: filter out frames from invalid vlans

 drivers/scsi/fcoe/fcoe.c   |  23 +++-
 drivers/scsi/fcoe/fcoe_ctlr.c  |  60 +-
 drivers/scsi/fcoe/fcoe_sysfs.c |  83 +-
 drivers/scsi/libfc/fc_exch.c   | 134 --
 drivers/scsi/libfc/fc_fcp.c| 196 ++--
 drivers/scsi/libfc/fc_lport.c  |   8 +-
 drivers/scsi/libfc/fc_rport.c  | 248 ++---
 include/scsi/libfc.h   |   9 +-
 8 files changed, 584 insertions(+), 177 deletions(-)

-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 05/24] libfc: sanitize E_D_TOV and R_A_TOV setting

2016-10-13 Thread Hannes Reinecke
When setting the FCP timeout we need to ensure a lower boundary
for E_D_TOV and R_A_TOV, otherwise we'd be getting spurious I/O
issues due to the fcp timer firing too early.

Signed-off-by: Hannes Reinecke 
---
 drivers/scsi/libfc/fc_fcp.c   | 9 +
 drivers/scsi/libfc/fc_lport.c | 8 +---
 drivers/scsi/libfc/fc_rport.c | 6 --
 3 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index 9f9eb7b..10faca2 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -1137,8 +1137,11 @@ static int fc_fcp_pkt_send(struct fc_lport *lport, 
struct fc_fcp_pkt *fsp)
 static inline unsigned int get_fsp_rec_tov(struct fc_fcp_pkt *fsp)
 {
struct fc_rport_libfc_priv *rpriv = fsp->rport->dd_data;
+   unsigned int e_d_tov = FC_DEF_E_D_TOV;
 
-   return msecs_to_jiffies(rpriv->e_d_tov) + HZ;
+   if (rpriv && rpriv->e_d_tov > e_d_tov)
+   e_d_tov = rpriv->e_d_tov;
+   return msecs_to_jiffies(e_d_tov) + HZ;
 }
 
 /**
@@ -1693,7 +1696,6 @@ static void fc_fcp_srr(struct fc_fcp_pkt *fsp, enum 
fc_rctl r_ctl, u32 offset)
struct fc_seq *seq;
struct fcp_srr *srr;
struct fc_frame *fp;
-   unsigned int rec_tov;
 
rport = fsp->rport;
rpriv = rport->dd_data;
@@ -1717,10 +1719,9 @@ static void fc_fcp_srr(struct fc_fcp_pkt *fsp, enum 
fc_rctl r_ctl, u32 offset)
   rpriv->local_port->port_id, FC_TYPE_FCP,
   FC_FCTL_REQ, 0);
 
-   rec_tov = get_fsp_rec_tov(fsp);
seq = lport->tt.exch_seq_send(lport, fp, fc_fcp_srr_resp,
  fc_fcp_pkt_destroy,
- fsp, jiffies_to_msecs(rec_tov));
+ fsp, get_fsp_rec_tov(fsp));
if (!seq)
goto retry;
 
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 4e11c90..81ad8ac 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -1777,7 +1777,7 @@ void fc_lport_flogi_resp(struct fc_seq *sp, struct 
fc_frame *fp,
if ((csp_flags & FC_SP_FT_FPORT) == 0) {
if (e_d_tov > lport->e_d_tov)
lport->e_d_tov = e_d_tov;
-   lport->r_a_tov = 2 * e_d_tov;
+   lport->r_a_tov = 2 * lport->e_d_tov;
fc_lport_set_port_id(lport, did, fp);
printk(KERN_INFO "host%d: libfc: "
   "Port (%6.6x) entered "
@@ -1789,8 +1789,10 @@ void fc_lport_flogi_resp(struct fc_seq *sp, struct 
fc_frame *fp,
   get_unaligned_be64(
   &flp->fl_wwnn));
} else {
-   lport->e_d_tov = e_d_tov;
-   lport->r_a_tov = r_a_tov;
+   if (e_d_tov > lport->e_d_tov)
+   lport->e_d_tov = e_d_tov;
+   if (r_a_tov > lport->r_a_tov)
+   lport->r_a_tov = r_a_tov;
fc_host_fabric_name(lport->host) =
get_unaligned_be64(&flp->fl_wwnn);
fc_lport_set_port_id(lport, did, fp);
diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c
index bb7e9d9..3d2baba 100644
--- a/drivers/scsi/libfc/fc_rport.c
+++ b/drivers/scsi/libfc/fc_rport.c
@@ -1296,13 +1296,15 @@ static void fc_rport_rtv_resp(struct fc_seq *sp, struct 
fc_frame *fp,
tov = ntohl(rtv->rtv_r_a_tov);
if (tov == 0)
tov = 1;
-   rdata->r_a_tov = tov;
+   if (tov > rdata->r_a_tov)
+   rdata->r_a_tov = tov;
tov = ntohl(rtv->rtv_e_d_tov);
if (toq & FC_ELS_RTV_EDRES)
tov /= 100;
if (tov == 0)
tov = 1;
-   rdata->e_d_tov = tov;
+   if (tov > rdata->e_d_tov)
+   rdata->e_d_tov = tov;
}
}
 
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 06/24] fcoe: make R_A_TOV and E_D_TOV configurable

2016-10-13 Thread Hannes Reinecke
The user might want to modify the values for R_A_TOV and E_D_TOV,
so add new module parameters 'e_d_tov' and 'r_a_tov' for the
'fcoe' modules and allow to modify them via sysfs attributes.

Signed-off-by: Hannes Reinecke 
Acked-by: Johannes Thumshirn 
---
 drivers/scsi/fcoe/fcoe.c   | 12 +--
 drivers/scsi/fcoe/fcoe_sysfs.c | 71 ++
 2 files changed, 81 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
index 9bd41a3..c907661 100644
--- a/drivers/scsi/fcoe/fcoe.c
+++ b/drivers/scsi/fcoe/fcoe.c
@@ -63,6 +63,14 @@
 module_param_named(debug_logging, fcoe_debug_logging, int, S_IRUGO|S_IWUSR);
 MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels");
 
+unsigned int fcoe_e_d_tov = 2 * 1000;
+module_param_named(e_d_tov, fcoe_e_d_tov, int, S_IRUGO|S_IWUSR);
+MODULE_PARM_DESC(e_d_tov, "E_D_TOV in ms, default 2000");
+
+unsigned int fcoe_r_a_tov = 2 * 2 * 1000;
+module_param_named(r_a_tov, fcoe_r_a_tov, int, S_IRUGO|S_IWUSR);
+MODULE_PARM_DESC(r_a_tov, "R_A_TOV in ms, default 4000");
+
 static DEFINE_MUTEX(fcoe_config_mutex);
 
 static struct workqueue_struct *fcoe_wq;
@@ -633,8 +641,8 @@ static int fcoe_lport_config(struct fc_lport *lport)
lport->qfull = 0;
lport->max_retry_count = 3;
lport->max_rport_retry_count = 3;
-   lport->e_d_tov = 2 * 1000;  /* FC-FS default */
-   lport->r_a_tov = 2 * 2 * 1000;
+   lport->e_d_tov = fcoe_e_d_tov;
+   lport->r_a_tov = fcoe_r_a_tov;
lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
lport->does_npiv = 1;
diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
index 0675fd1..9e6baac 100644
--- a/drivers/scsi/fcoe/fcoe_sysfs.c
+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
@@ -424,6 +424,75 @@ static FCOE_DEVICE_ATTR(ctlr, fip_vlan_responder, S_IRUGO 
| S_IWUSR,
store_ctlr_fip_resp);
 
 static ssize_t
+fcoe_ctlr_var_store(u32 *var, const char *buf, size_t count)
+{
+   int err;
+   unsigned long v;
+
+   err = kstrtoul(buf, 10, &v);
+   if (err || v > UINT_MAX)
+   return -EINVAL;
+
+   *var = v;
+
+   return count;
+}
+
+static ssize_t store_ctlr_r_a_tov(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+   struct fcoe_ctlr_device *ctlr_dev = dev_to_ctlr(dev);
+   struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
+
+   if (ctlr_dev->enabled == FCOE_CTLR_ENABLED)
+   return -EBUSY;
+   if (ctlr_dev->enabled == FCOE_CTLR_DISABLED)
+   return fcoe_ctlr_var_store(&ctlr->lp->r_a_tov, buf, count);
+   return -ENOTSUPP;
+}
+
+static ssize_t show_ctlr_r_a_tov(struct device *dev,
+struct device_attribute *attr,
+char *buf)
+{
+   struct fcoe_ctlr_device *ctlr_dev = dev_to_ctlr(dev);
+   struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
+
+   return sprintf(buf, "%d\n", ctlr->lp->r_a_tov);
+}
+
+static FCOE_DEVICE_ATTR(ctlr, r_a_tov, S_IRUGO | S_IWUSR,
+   show_ctlr_r_a_tov, store_ctlr_r_a_tov);
+
+static ssize_t store_ctlr_e_d_tov(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+   struct fcoe_ctlr_device *ctlr_dev = dev_to_ctlr(dev);
+   struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
+
+   if (ctlr_dev->enabled == FCOE_CTLR_ENABLED)
+   return -EBUSY;
+   if (ctlr_dev->enabled == FCOE_CTLR_DISABLED)
+   return fcoe_ctlr_var_store(&ctlr->lp->e_d_tov, buf, count);
+   return -ENOTSUPP;
+}
+
+static ssize_t show_ctlr_e_d_tov(struct device *dev,
+struct device_attribute *attr,
+char *buf)
+{
+   struct fcoe_ctlr_device *ctlr_dev = dev_to_ctlr(dev);
+   struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
+
+   return sprintf(buf, "%d\n", ctlr->lp->e_d_tov);
+}
+
+static FCOE_DEVICE_ATTR(ctlr, e_d_tov, S_IRUGO | S_IWUSR,
+   show_ctlr_e_d_tov, store_ctlr_e_d_tov);
+
+static ssize_t
 store_private_fcoe_ctlr_fcf_dev_loss_tmo(struct device *dev,
 struct device_attribute *attr,
 const char *buf, size_t count)
@@ -507,6 +576,8 @@ static FCOE_DEVICE_ATTR(fcf, dev_loss_tmo, S_IRUGO | 
S_IWUSR,
 static struct attribute *fcoe_ctlr_attrs[] = {
&device_attr_fcoe_ctlr_fip_vlan_responder.attr,
&device_attr_fcoe_ctlr_fcf_dev_loss_tmo.attr,
+   &device_attr_fcoe_ctlr_r_a_tov.attr,
+   &device_attr_fcoe_ctlr_e_d_tov.attr,
&device_attr_fcoe_ctlr_enabled.attr,
&devi

[PATCH 09/24] libfc: Implement RTV responder

2016-10-13 Thread Hannes Reinecke
The libfc stack generates an RTV request, so we should be implementing
an RTV responder, too.

Signed-off-by: Hannes Reinecke 
Acked-by: Johannes Thumshirn 
---
 drivers/scsi/libfc/fc_rport.c | 41 -
 1 file changed, 40 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c
index d2d8607..426c399 100644
--- a/drivers/scsi/libfc/fc_rport.c
+++ b/drivers/scsi/libfc/fc_rport.c
@@ -1268,7 +1268,7 @@ static void fc_rport_enter_prli(struct fc_rport_priv 
*rdata)
 }
 
 /**
- * fc_rport_els_rtv_resp() - Handler for Request Timeout Value (RTV) responses
+ * fc_rport_rtv_resp() - Handler for Request Timeout Value (RTV) responses
  * @sp:   The sequence the RTV was on
  * @fp:   The RTV response frame
  * @rdata_arg: The remote port that sent the RTV response
@@ -1374,6 +1374,41 @@ static void fc_rport_enter_rtv(struct fc_rport_priv 
*rdata)
 }
 
 /**
+ * fc_rport_recv_rtv_req() - Handler for Read Timeout Value (RTV) requests
+ * @rdata: The remote port that sent the RTV request
+ * @in_fp: The RTV request frame
+ *
+ * Locking Note:  Called with the lport and rport locks held.
+ */
+static void fc_rport_recv_rtv_req(struct fc_rport_priv *rdata,
+ struct fc_frame *in_fp)
+{
+   struct fc_lport *lport = rdata->local_port;
+   struct fc_frame *fp;
+   struct fc_els_rtv_acc *rtv;
+   struct fc_seq_els_data rjt_data;
+
+   FC_RPORT_DBG(rdata, "Received RTV request\n");
+
+   fp = fc_frame_alloc(lport, sizeof(*rtv));
+   if (!fp) {
+   rjt_data.reason = ELS_RJT_UNAB;
+   rjt_data.reason = ELS_EXPL_INSUF_RES;
+   lport->tt.seq_els_rsp_send(in_fp, ELS_LS_RJT, &rjt_data);
+   goto drop;
+   }
+   rtv = fc_frame_payload_get(fp, sizeof(*rtv));
+   rtv->rtv_cmd = ELS_LS_ACC;
+   rtv->rtv_r_a_tov = htonl(lport->r_a_tov);
+   rtv->rtv_e_d_tov = htonl(lport->e_d_tov);
+   rtv->rtv_toq = 0;
+   fc_fill_reply_hdr(fp, in_fp, FC_RCTL_ELS_REP, 0);
+   lport->tt.frame_send(lport, fp);
+drop:
+   fc_frame_free(in_fp);
+}
+
+/**
  * fc_rport_logo_resp() - Handler for logout (LOGO) responses
  * @sp:   The sequence the LOGO was on
  * @fp:   The LOGO response frame
@@ -1678,6 +1713,9 @@ static void fc_rport_recv_els_req(struct fc_lport *lport, 
struct fc_frame *fp)
case ELS_RLS:
fc_rport_recv_rls_req(rdata, fp);
break;
+   case ELS_RTV:
+   fc_rport_recv_rtv_req(rdata, fp);
+   break;
default:
fc_frame_free(fp);  /* can't happen */
break;
@@ -1729,6 +1767,7 @@ static void fc_rport_recv_req(struct fc_lport *lport, 
struct fc_frame *fp)
case ELS_RRQ:
case ELS_REC:
case ELS_RLS:
+   case ELS_RTV:
fc_rport_recv_els_req(lport, fp);
break;
default:
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 07/24] libfc: do not overwrite DID_TIME_OUT status

2016-10-13 Thread Hannes Reinecke
When a command is aborted it might already have the DID_TIME_OUT
status set, so we shouldn't be overwriting that.

Signed-off-by: Hannes Reinecke 
Acked-by: Johannes Thumshirn 
---
 drivers/scsi/libfc/fc_fcp.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index 10faca2..0e2a201 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -2008,9 +2008,15 @@ static void fc_io_compl(struct fc_fcp_pkt *fsp)
sc_cmd->result = (DID_ERROR << 16) | fsp->cdb_status;
break;
case FC_CMD_ABORTED:
-   FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml "
- "due to FC_CMD_ABORTED\n");
-   sc_cmd->result = (DID_ERROR << 16) | fsp->io_status;
+   if (host_byte(sc_cmd->result) == DID_TIME_OUT)
+   FC_FCP_DBG(fsp, "Returning DID_TIME_OUT to scsi-ml "
+  "due to FC_CMD_ABORTED\n");
+   else {
+   FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml "
+  "due to FC_CMD_ABORTED\n");
+   set_host_byte(sc_cmd, DID_ERROR);
+   }
+   sc_cmd->result |= fsp->io_status;
break;
case FC_CMD_RESET:
FC_FCP_DBG(fsp, "Returning DID_RESET to scsi-ml "
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 08/24] libfc: use error code for fc_rport_error()

2016-10-13 Thread Hannes Reinecke
We only ever use the 'fp' argument for fc_rport_error() to
encapsulate the error code, so we can as well do away with that
and pass the error directly.

Signed-off-by: Hannes Reinecke 
Acked-by: Johannes Thumshirn 
---
 drivers/scsi/libfc/fc_rport.c | 101 +-
 include/scsi/libfc.h  |   5 +++
 2 files changed, 66 insertions(+), 40 deletions(-)

diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c
index 3d2baba..d2d8607 100644
--- a/drivers/scsi/libfc/fc_rport.c
+++ b/drivers/scsi/libfc/fc_rport.c
@@ -87,8 +87,8 @@
 static void fc_rport_recv_prlo_req(struct fc_rport_priv *, struct fc_frame *);
 static void fc_rport_recv_logo_req(struct fc_lport *, struct fc_frame *);
 static void fc_rport_timeout(struct work_struct *);
-static void fc_rport_error(struct fc_rport_priv *, struct fc_frame *);
-static void fc_rport_error_retry(struct fc_rport_priv *, struct fc_frame *);
+static void fc_rport_error(struct fc_rport_priv *, int);
+static void fc_rport_error_retry(struct fc_rport_priv *, int);
 static void fc_rport_work(struct work_struct *);
 
 static const char *fc_rport_state_names[] = {
@@ -604,20 +604,19 @@ static void fc_rport_timeout(struct work_struct *work)
 /**
  * fc_rport_error() - Error handler, called once retries have been exhausted
  * @rdata: The remote port the error is happened on
- * @fp:   The error code encapsulated in a frame pointer
+ * @err:   The error code
  *
  * Locking Note: The rport lock is expected to be held before
  * calling this routine
  *
  * Reference counting: does not modify kref
  */
-static void fc_rport_error(struct fc_rport_priv *rdata, struct fc_frame *fp)
+static void fc_rport_error(struct fc_rport_priv *rdata, int err)
 {
struct fc_lport *lport = rdata->local_port;
 
-   FC_RPORT_DBG(rdata, "Error %ld in state %s, retries %d\n",
-IS_ERR(fp) ? -PTR_ERR(fp) : 0,
-fc_rport_state(rdata), rdata->retries);
+   FC_RPORT_DBG(rdata, "Error %d in state %s, retries %d\n",
+-err, fc_rport_state(rdata), rdata->retries);
 
switch (rdata->rp_state) {
case RPORT_ST_FLOGI:
@@ -649,7 +648,7 @@ static void fc_rport_error(struct fc_rport_priv *rdata, 
struct fc_frame *fp)
 /**
  * fc_rport_error_retry() - Handler for remote port state retries
  * @rdata: The remote port whose state is to be retried
- * @fp:   The error code encapsulated in a frame pointer
+ * @err:   The error code
  *
  * If the error was an exchange timeout retry immediately,
  * otherwise wait for E_D_TOV.
@@ -659,22 +658,21 @@ static void fc_rport_error(struct fc_rport_priv *rdata, 
struct fc_frame *fp)
  *
  * Reference counting: increments kref when scheduling retry_work
  */
-static void fc_rport_error_retry(struct fc_rport_priv *rdata,
-struct fc_frame *fp)
+static void fc_rport_error_retry(struct fc_rport_priv *rdata, int err)
 {
unsigned long delay = msecs_to_jiffies(rdata->e_d_tov);
struct fc_lport *lport = rdata->local_port;
 
/* make sure this isn't an FC_EX_CLOSED error, never retry those */
-   if (PTR_ERR(fp) == -FC_EX_CLOSED)
+   if (err == -FC_EX_CLOSED)
goto out;
 
if (rdata->retries < rdata->local_port->max_rport_retry_count) {
-   FC_RPORT_DBG(rdata, "Error %ld in state %s, retrying\n",
-PTR_ERR(fp), fc_rport_state(rdata));
+   FC_RPORT_DBG(rdata, "Error %d in state %s, retrying\n",
+err, fc_rport_state(rdata));
rdata->retries++;
/* no additional delay on exchange timeouts */
-   if (PTR_ERR(fp) == -FC_EX_TIMEOUT)
+   if (err == -FC_EX_TIMEOUT)
delay = 0;
kref_get(&rdata->kref);
if (!schedule_delayed_work(&rdata->retry_work, delay))
@@ -683,7 +681,7 @@ static void fc_rport_error_retry(struct fc_rport_priv 
*rdata,
}
 
 out:
-   fc_rport_error(rdata, fp);
+   fc_rport_error(rdata, err);
 }
 
 /**
@@ -743,8 +741,11 @@ static void fc_rport_flogi_resp(struct fc_seq *sp, struct 
fc_frame *fp,
struct fc_lport *lport = rdata->local_port;
struct fc_els_flogi *flogi;
unsigned int r_a_tov;
+   u8 opcode;
+   int err = 0;
 
-   FC_RPORT_DBG(rdata, "Received a FLOGI %s\n", fc_els_resp_type(fp));
+   FC_RPORT_DBG(rdata, "Received a FLOGI %s\n",
+IS_ERR(fp) ? "error" : fc_els_resp_type(fp));
 
if (fp == ERR_PTR(-FC_EX_CLOSED))
goto put;
@@ -760,18 +761,32 @@ static void fc_rport_flogi_resp(struct fc_seq *sp, struct 
fc_frame *fp,
}
 
if (IS_ERR(fp)) {
-   fc_rport_error(rdata, fp);
+   fc_rport_error(rdata, PTR_ERR(fp));
goto err;
}
+   opcode = fc_frame_payload_op(fp);
+   if (opcode == ELS_LS_RJ

[PATCH 10/24] libfc: Rework PRLI handling

2016-10-13 Thread Hannes Reinecke
PRLI is only required if the port is acting as an initiator; ports
which support target functionality only do not need to send PRLI.
At the same time the PRLI state is only used if the port initiated
a PRLI transfer; if we received a PRLI request we should _not_
change the state as this would cause our PRLI response to be dropped.
And when we receive a PRLI response we need to check if an image
pair has been established; if not the remote port cannot act as a
target for us and we need to disable target functionality.

Signed-off-by: Hannes Reinecke 
---
 drivers/scsi/libfc/fc_rport.c | 56 +--
 1 file changed, 38 insertions(+), 18 deletions(-)

diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c
index 426c399..2b8214f 100644
--- a/drivers/scsi/libfc/fc_rport.c
+++ b/drivers/scsi/libfc/fc_rport.c
@@ -1126,7 +1126,7 @@ static void fc_rport_prli_resp(struct fc_seq *sp, struct 
fc_frame *fp,
u32 roles = FC_RPORT_ROLE_UNKNOWN;
u32 fcp_parm = 0;
u8 op;
-   u8 resp_code = 0;
+   enum fc_els_spp_resp resp_code;
 
FC_RPORT_DBG(rdata, "Received a PRLI %s\n", fc_els_resp_type(fp));
 
@@ -1158,8 +1158,8 @@ static void fc_rport_prli_resp(struct fc_seq *sp, struct 
fc_frame *fp,
goto out;
 
resp_code = (pp->spp.spp_flags & FC_SPP_RESP_MASK);
-   FC_RPORT_DBG(rdata, "PRLI spp_flags = 0x%x\n",
-pp->spp.spp_flags);
+   FC_RPORT_DBG(rdata, "PRLI spp_flags = 0x%x spp_type 0x%x\n",
+pp->spp.spp_flags, pp->spp.spp_type);
rdata->spp_type = pp->spp.spp_type;
if (resp_code != FC_SPP_RESP_ACK) {
if (resp_code == FC_SPP_RESP_CONF)
@@ -1177,13 +1177,26 @@ static void fc_rport_prli_resp(struct fc_seq *sp, 
struct fc_frame *fp,
if (fcp_parm & FCP_SPPF_CONF_COMPL)
rdata->flags |= FC_RP_FLAGS_CONF_REQ;
 
-   prov = fc_passive_prov[FC_TYPE_FCP];
+   /*
+* Call prli provider if we should act as a target
+*/
+   prov = fc_passive_prov[rdata->spp_type];
if (prov) {
memset(&temp_spp, 0, sizeof(temp_spp));
prov->prli(rdata, pp->prli.prli_spp_len,
   &pp->spp, &temp_spp);
}
-
+   /*
+* Check if the image pair could be established
+*/
+   if (rdata->spp_type != FC_TYPE_FCP ||
+   resp_code != FC_SPP_RESP_ACK ||
+   !(pp->spp.spp_flags & FC_SPP_EST_IMG_PAIR)) {
+   /*
+* Nope; we can't use this port as a target.
+*/
+   fcp_parm &= ~FCP_SPPF_TARG_FCN;
+   }
rdata->supported_classes = FC_COS_CLASS3;
if (fcp_parm & FCP_SPPF_INIT_FCN)
roles |= FC_RPORT_ROLE_FCP_INITIATOR;
@@ -1236,6 +1249,15 @@ static void fc_rport_enter_prli(struct fc_rport_priv 
*rdata)
return;
}
 
+   /*
+* And if the local port does not support the initiator function
+* there's no need to send a PRLI, either.
+*/
+   if (!(lport->service_params & FCP_SPPF_INIT_FCN)) {
+   fc_rport_enter_ready(rdata);
+   return;
+   }
+
FC_RPORT_DBG(rdata, "Port entered PRLI state from %s state\n",
 fc_rport_state(rdata));
 
@@ -1926,7 +1948,6 @@ static void fc_rport_recv_prli_req(struct fc_rport_priv 
*rdata,
unsigned int len;
unsigned int plen;
enum fc_els_spp_resp resp;
-   enum fc_els_spp_resp passive;
struct fc_seq_els_data rjt_data;
struct fc4_prov *prov;
 
@@ -1976,15 +1997,21 @@ static void fc_rport_recv_prli_req(struct fc_rport_priv 
*rdata,
resp = 0;
 
if (rspp->spp_type < FC_FC4_PROV_SIZE) {
+   enum fc_els_spp_resp active = 0, passive = 0;
+
prov = fc_active_prov[rspp->spp_type];
if (prov)
-   resp = prov->prli(rdata, plen, rspp, spp);
+   active = prov->prli(rdata, plen, rspp, spp);
prov = fc_passive_prov[rspp->spp_type];
-   if (prov) {
+   if (prov)
passive = prov->prli(rdata, plen, rspp, spp);
-   if (!resp || passive == FC_SPP_RESP_ACK)
-   resp = passive;
-   }
+   if (!active || passive == FC_SPP_RESP_ACK)
+   resp = passive;
+   else
+   resp = active;
+ 

[PATCH 01/24] libfc: additional debugging messages

2016-10-13 Thread Hannes Reinecke
Signed-off-by: Hannes Reinecke 
Acked-by: Johannes Thumshirn 
---
 drivers/scsi/libfc/fc_exch.c  | 59 +++
 drivers/scsi/libfc/fc_fcp.c   | 41 --
 drivers/scsi/libfc/fc_rport.c | 25 ++
 3 files changed, 101 insertions(+), 24 deletions(-)

diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
index 16ca31a..b4bdc90 100644
--- a/drivers/scsi/libfc/fc_exch.c
+++ b/drivers/scsi/libfc/fc_exch.c
@@ -362,8 +362,10 @@ static inline void fc_exch_timer_set_locked(struct fc_exch 
*ep,
 
fc_exch_hold(ep);   /* hold for timer */
if (!queue_delayed_work(fc_exch_workqueue, &ep->timeout_work,
-   msecs_to_jiffies(timer_msec)))
+   msecs_to_jiffies(timer_msec))) {
+   FC_EXCH_DBG(ep, "Exchange already queued\n");
fc_exch_release(ep);
+   }
 }
 
 /**
@@ -632,9 +634,13 @@ static int fc_exch_abort_locked(struct fc_exch *ep,
struct fc_frame *fp;
int error;
 
+   FC_EXCH_DBG(ep, "exch: abort, time %d msecs\n", timer_msec);
if (ep->esb_stat & (ESB_ST_COMPLETE | ESB_ST_ABNORMAL) ||
-   ep->state & (FC_EX_DONE | FC_EX_RST_CLEANUP))
+   ep->state & (FC_EX_DONE | FC_EX_RST_CLEANUP)) {
+   FC_EXCH_DBG(ep, "exch: already completed esb %x state %x\n",
+   ep->esb_stat, ep->state);
return -ENXIO;
+   }
 
/*
 * Send the abort on a new sequence if possible.
@@ -758,7 +764,7 @@ static void fc_exch_timeout(struct work_struct *work)
u32 e_stat;
int rc = 1;
 
-   FC_EXCH_DBG(ep, "Exchange timed out\n");
+   FC_EXCH_DBG(ep, "Exchange timed out state %x\n", ep->state);
 
spin_lock_bh(&ep->ex_lock);
if (ep->state & (FC_EX_RST_CLEANUP | FC_EX_DONE))
@@ -1258,8 +1264,10 @@ static void fc_seq_send_ack(struct fc_seq *sp, const 
struct fc_frame *rx_fp)
 */
if (fc_sof_needs_ack(fr_sof(rx_fp))) {
fp = fc_frame_alloc(lport, 0);
-   if (!fp)
+   if (!fp) {
+   FC_EXCH_DBG(ep, "Drop ACK request, out of memory\n");
return;
+   }
 
fh = fc_frame_header_get(fp);
fh->fh_r_ctl = FC_RCTL_ACK_1;
@@ -1312,13 +1320,18 @@ static void fc_exch_send_ba_rjt(struct fc_frame *rx_fp,
struct fc_frame_header *rx_fh;
struct fc_frame_header *fh;
struct fc_ba_rjt *rp;
+   struct fc_seq *sp;
struct fc_lport *lport;
unsigned int f_ctl;
 
lport = fr_dev(rx_fp);
+   sp = fr_seq(rx_fp);
fp = fc_frame_alloc(lport, sizeof(*rp));
-   if (!fp)
+   if (!fp) {
+   FC_EXCH_DBG(fc_seq_exch(sp),
+"Drop BA_RJT request, out of memory\n");
return;
+   }
fh = fc_frame_header_get(fp);
rx_fh = fc_frame_header_get(rx_fp);
 
@@ -1383,14 +1396,17 @@ static void fc_exch_recv_abts(struct fc_exch *ep, 
struct fc_frame *rx_fp)
if (!ep)
goto reject;
 
+   FC_EXCH_DBG(ep, "exch: ABTS received\n");
fp = fc_frame_alloc(ep->lp, sizeof(*ap));
-   if (!fp)
+   if (!fp) {
+   FC_EXCH_DBG(ep, "Drop ABTS request, out of memory\n");
goto free;
+   }
 
spin_lock_bh(&ep->ex_lock);
if (ep->esb_stat & ESB_ST_COMPLETE) {
spin_unlock_bh(&ep->ex_lock);
-
+   FC_EXCH_DBG(ep, "exch: ABTS rejected, exchange complete\n");
fc_frame_free(fp);
goto reject;
}
@@ -1784,11 +1800,16 @@ static void fc_seq_ls_acc(struct fc_frame *rx_fp)
struct fc_lport *lport;
struct fc_els_ls_acc *acc;
struct fc_frame *fp;
+   struct fc_seq *sp;
 
lport = fr_dev(rx_fp);
+   sp = fr_seq(rx_fp);
fp = fc_frame_alloc(lport, sizeof(*acc));
-   if (!fp)
+   if (!fp) {
+   FC_EXCH_DBG(fc_seq_exch(sp),
+   "exch: drop LS_ACC, out of memory\n");
return;
+   }
acc = fc_frame_payload_get(fp, sizeof(*acc));
memset(acc, 0, sizeof(*acc));
acc->la_cmd = ELS_LS_ACC;
@@ -1811,11 +1832,16 @@ static void fc_seq_ls_rjt(struct fc_frame *rx_fp, enum 
fc_els_rjt_reason reason,
struct fc_lport *lport;
struct fc_els_ls_rjt *rjt;
struct fc_frame *fp;
+   struct fc_seq *sp;
 
lport = fr_dev(rx_fp);
+   sp = fr_seq(rx_fp);
fp = fc_frame_alloc(lport, sizeof(*rjt));
-   if (!fp)
+   if (!fp) {
+   FC_EXCH_DBG(fc_seq_exch(sp),
+   "exch: drop LS_ACC, out of memory\n");
return;
+   }
rjt = fc_frame_payload_get(fp, sizeof(*rjt));
memset(rjt, 0, sizeof(*rjt));
rjt->er_cmd = ELS_LS_RJT;
@@ -1975,15 +2001,23

[PATCH 13/24] libfc: safeguard against invalid exchange index

2016-10-13 Thread Hannes Reinecke
The cached exchange index might be invalid, in which case
we should drop down to allocate a new one.
And we should not try to access an invalid exchange when
responding to a BA_ABTS.

Signed-off-by: Hannes Reinecke 
---
 drivers/scsi/libfc/fc_exch.c | 21 ++---
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
index 5e0a57f..e8784a7 100644
--- a/drivers/scsi/libfc/fc_exch.c
+++ b/drivers/scsi/libfc/fc_exch.c
@@ -827,14 +827,18 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport 
*lport,
 
/* peek cache of free slot */
if (pool->left != FC_XID_UNKNOWN) {
-   index = pool->left;
-   pool->left = FC_XID_UNKNOWN;
-   goto hit;
+   if (!WARN_ON(fc_exch_ptr_get(pool, pool->left))) {
+   index = pool->left;
+   pool->left = FC_XID_UNKNOWN;
+   goto hit;
+   }
}
if (pool->right != FC_XID_UNKNOWN) {
-   index = pool->right;
-   pool->right = FC_XID_UNKNOWN;
-   goto hit;
+   if (!WARN_ON(fc_exch_ptr_get(pool, pool->right))) {
+   index = pool->right;
+   pool->right = FC_XID_UNKNOWN;
+   goto hit;
+   }
}
 
index = pool->next_index;
@@ -1777,7 +1781,10 @@ static void fc_exch_recv_bls(struct fc_exch_mgr *mp, 
struct fc_frame *fp)
fc_frame_free(fp);
break;
case FC_RCTL_BA_ABTS:
-   fc_exch_recv_abts(ep, fp);
+   if (ep)
+   fc_exch_recv_abts(ep, fp);
+   else
+   fc_frame_free(fp);
break;
default:/* ignore junk */
fc_frame_free(fp);
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 02/24] libfc: spurious I/O error under high load

2016-10-13 Thread Hannes Reinecke
If a command times out libfc is sending an REC, which also
might fail (due to frames being lost or something).
If no data has been transferred we can simply retry
the command, but the current code sets a state of FC_ERROR,
which then is being translated into DID_ERROR, resulting
in an I/O error.
So to handle this properly we need to set a separate
state FC_TRANS_RESET and mapping it onto DID_SOFT_RETRY.

Signed-off-by: Hannes Reinecke 
Acked-by: Johannes Thumshirn 
---
 drivers/scsi/libfc/fc_fcp.c | 23 +++
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index 5c6c73a..9f9eb7b 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -122,6 +122,7 @@ struct fc_fcp_internal {
 #define FC_HRD_ERROR   9
 #define FC_CRC_ERROR   10
 #define FC_TIMED_OUT   11
+#define FC_TRANS_RESET 12
 
 /*
  * Error recovery timeout values.
@@ -283,7 +284,7 @@ static int fc_fcp_send_abort(struct fc_fcp_pkt *fsp)
  * fc_io_compl() will notify the SCSI-ml that the I/O is done.
  * The SCSI-ml will retry the command.
  */
-static void fc_fcp_retry_cmd(struct fc_fcp_pkt *fsp)
+static void fc_fcp_retry_cmd(struct fc_fcp_pkt *fsp, int status_code)
 {
if (fsp->seq_ptr) {
fsp->lp->tt.exch_done(fsp->seq_ptr);
@@ -292,7 +293,7 @@ static void fc_fcp_retry_cmd(struct fc_fcp_pkt *fsp)
 
fsp->state &= ~FC_SRB_ABORT_PENDING;
fsp->io_status = 0;
-   fsp->status_code = FC_ERROR;
+   fsp->status_code = status_code;
fc_fcp_complete_locked(fsp);
 }
 
@@ -1208,7 +1209,7 @@ static void fc_fcp_error(struct fc_fcp_pkt *fsp, struct 
fc_frame *fp)
return;
 
if (error == -FC_EX_CLOSED) {
-   fc_fcp_retry_cmd(fsp);
+   fc_fcp_retry_cmd(fsp, FC_ERROR);
goto unlock;
}
 
@@ -1531,10 +1532,11 @@ static void fc_fcp_rec_resp(struct fc_seq *seq, struct 
fc_frame *fp, void *arg)
 */
if (rjt->er_explan == ELS_EXPL_OXID_RXID &&
fsp->xfer_len == 0) {
-   fc_fcp_retry_cmd(fsp);
+   fsp->state |= FC_SRB_ABORTED;
+   fc_fcp_retry_cmd(fsp, FC_TRANS_RESET);
break;
}
-   fc_fcp_recovery(fsp, FC_ERROR);
+   fc_fcp_recovery(fsp, FC_TRANS_RESET);
break;
}
} else if (opcode == ELS_LS_ACC) {
@@ -1630,7 +1632,7 @@ static void fc_fcp_rec_error(struct fc_fcp_pkt *fsp, 
struct fc_frame *fp)
case -FC_EX_CLOSED:
FC_FCP_DBG(fsp, "REC %p fid %6.6x exchange closed\n",
   fsp, fsp->rport->port_id);
-   fc_fcp_retry_cmd(fsp);
+   fc_fcp_retry_cmd(fsp, FC_ERROR);
break;
 
default:
@@ -1729,7 +1731,7 @@ static void fc_fcp_srr(struct fc_fcp_pkt *fsp, enum 
fc_rctl r_ctl, u32 offset)
fc_fcp_pkt_hold(fsp);   /* hold for outstanding SRR */
return;
 retry:
-   fc_fcp_retry_cmd(fsp);
+   fc_fcp_retry_cmd(fsp, FC_TRANS_RESET);
 }
 
 /**
@@ -1801,7 +1803,7 @@ static void fc_fcp_srr_error(struct fc_fcp_pkt *fsp, 
struct fc_frame *fp)
FC_FCP_DBG(fsp, "SRR error, exchange closed\n");
/* fall through */
default:
-   fc_fcp_retry_cmd(fsp);
+   fc_fcp_retry_cmd(fsp, FC_ERROR);
break;
}
fc_fcp_unlock_pkt(fsp);
@@ -2014,6 +2016,11 @@ static void fc_io_compl(struct fc_fcp_pkt *fsp)
   "due to FC_CMD_RESET\n");
sc_cmd->result = (DID_RESET << 16);
break;
+   case FC_TRANS_RESET:
+   FC_FCP_DBG(fsp, "Returning DID_SOFT_ERROR to scsi-ml "
+  "due to FC_TRANS_RESET\n");
+   sc_cmd->result = (DID_SOFT_ERROR << 16);
+   break;
case FC_HRD_ERROR:
FC_FCP_DBG(fsp, "Returning DID_NO_CONNECT to scsi-ml "
   "due to FC_HRD_ERROR\n");
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 12/24] libfc: Clarify ramp-down messages

2016-10-13 Thread Hannes Reinecke
When the queue depth is reduced we should print out the reason
for this; it might be due to a queue full condition.

Signed-off-by: Hannes Reinecke 
---
 drivers/scsi/libfc/fc_fcp.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index 0e2a201..f7700cc 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -403,8 +403,6 @@ static void fc_fcp_can_queue_ramp_down(struct fc_lport 
*lport)
if (!can_queue)
can_queue = 1;
lport->host->can_queue = can_queue;
-   shost_printk(KERN_ERR, lport->host, "libfc: Could not allocate frame.\n"
-"Reducing can_queue to %d.\n", can_queue);
 
 unlock:
spin_unlock_irqrestore(lport->host->host_lock, flags);
@@ -431,6 +429,9 @@ static inline struct fc_frame *fc_fcp_frame_alloc(struct 
fc_lport *lport,
put_cpu();
/* error case */
fc_fcp_can_queue_ramp_down(lport);
+   shost_printk(KERN_ERR, lport->host,
+"libfc: Could not allocate frame, "
+"reducing can_queue to %d.\n", lport->host->can_queue);
return NULL;
 }
 
@@ -1860,8 +1861,13 @@ int fc_queuecommand(struct Scsi_Host *shost, struct 
scsi_cmnd *sc_cmd)
rpriv = rport->dd_data;
 
if (!fc_fcp_lport_queue_ready(lport)) {
-   if (lport->qfull)
+   if (lport->qfull) {
fc_fcp_can_queue_ramp_down(lport);
+   shost_printk(KERN_ERR, lport->host,
+"libfc: queue full, "
+"reducing can_queue to %d.\n",
+lport->host->can_queue);
+   }
rc = SCSI_MLQUEUE_HOST_BUSY;
goto out;
}
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 11/24] libfc: Return LS_RJT_BUSY for PRLI in status PLOGI

2016-10-13 Thread Hannes Reinecke
Occasionally it might happen that we receive a PRLI while we're still
waiting for our PLOGI response. In that case we should return
'busy' LS status instead of 'plogi required' LS status.

Signed-off-by: Hannes Reinecke 
---
 drivers/scsi/libfc/fc_rport.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c
index 2b8214f..a867874 100644
--- a/drivers/scsi/libfc/fc_rport.c
+++ b/drivers/scsi/libfc/fc_rport.c
@@ -1705,6 +1705,15 @@ static void fc_rport_recv_els_req(struct fc_lport 
*lport, struct fc_frame *fp)
case RPORT_ST_READY:
case RPORT_ST_ADISC:
break;
+   case RPORT_ST_PLOGI:
+   if (fc_frame_payload_op(fp) == ELS_PRLI) {
+   FC_RPORT_DBG(rdata, "Reject ELS PRLI "
+"while in state %s\n",
+fc_rport_state(rdata));
+   mutex_unlock(&rdata->rp_mutex);
+   kref_put(&rdata->kref, lport->tt.rport_destroy);
+   goto busy;
+   }
default:
FC_RPORT_DBG(rdata,
 "Reject ELS 0x%02x while in state %s\n",
@@ -1752,6 +1761,14 @@ static void fc_rport_recv_els_req(struct fc_lport 
*lport, struct fc_frame *fp)
els_data.explan = ELS_EXPL_PLOGI_REQD;
lport->tt.seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
fc_frame_free(fp);
+   return;
+
+busy:
+   els_data.reason = ELS_RJT_BUSY;
+   els_data.explan = ELS_EXPL_NONE;
+   lport->tt.seq_els_rsp_send(fp, ELS_LS_RJT, &els_data);
+   fc_frame_free(fp);
+   return;
 }
 
 /**
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 05/16] scsi: fc: provide fc_bsg_to_shost() helper

2016-10-13 Thread Hannes Reinecke
On 10/12/2016 03:06 PM, Johannes Thumshirn wrote:
> Provide fc_bsg_to_shost() helper that will become handy when we're moving from
> struct fc_bsg_job to a plain struct bsg_job. Also use this little helper in
> the LLDDs.
> 
> Signed-off-by: Johannes Thumshirn 
> ---
>  drivers/s390/scsi/zfcp_fc.c  |  4 +--
>  drivers/scsi/bfa/bfad_bsg.c  |  6 ++---
>  drivers/scsi/ibmvscsi/ibmvfc.c   |  4 +--
>  drivers/scsi/libfc/fc_lport.c|  2 +-
>  drivers/scsi/lpfc/lpfc_bsg.c | 32 
>  drivers/scsi/qla2xxx/qla_bsg.c   | 54 
> 
>  drivers/scsi/scsi_transport_fc.c |  2 +-
>  include/scsi/scsi_transport_fc.h |  5 
>  8 files changed, 56 insertions(+), 53 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 14/24] libfc: quarantine timed out xids

2016-10-13 Thread Hannes Reinecke
When a sequence times out we have no idea what happened to the
frame. And we do not know if we will ever receive the frame.
Hence we cannot re-use the xid as we would risk data corruption
if the xid had been re-used and the timed out frame would be
received after that.
So we need to quarantine the xid until the lport is reset.
Yes, I know this will (eventually) deplete the xid pool.
But for now it's the safest method.

Signed-off-by: Hannes Reinecke 
---
 drivers/scsi/libfc/fc_exch.c | 33 ++---
 drivers/scsi/libfc/fc_fcp.c  | 13 +++--
 include/scsi/libfc.h |  1 +
 3 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
index e8784a7..5868824 100644
--- a/drivers/scsi/libfc/fc_exch.c
+++ b/drivers/scsi/libfc/fc_exch.c
@@ -94,6 +94,7 @@ struct fc_exch_pool {
 struct fc_exch_mgr {
struct fc_exch_pool __percpu *pool;
mempool_t   *ep_pool;
+   struct fc_lport *lport;
enum fc_class   class;
struct kref kref;
u16 min_xid;
@@ -408,6 +409,8 @@ static int fc_exch_done_locked(struct fc_exch *ep)
return rc;
 }
 
+static struct fc_exch fc_quarantine_exch;
+
 /**
  * fc_exch_ptr_get() - Return an exchange from an exchange pool
  * @pool:  Exchange Pool to get an exchange from
@@ -452,14 +455,17 @@ static void fc_exch_delete(struct fc_exch *ep)
 
/* update cache of free slot */
index = (ep->xid - ep->em->min_xid) >> fc_cpu_order;
-   if (pool->left == FC_XID_UNKNOWN)
-   pool->left = index;
-   else if (pool->right == FC_XID_UNKNOWN)
-   pool->right = index;
-   else
-   pool->next_index = index;
-
-   fc_exch_ptr_set(pool, index, NULL);
+   if (!(ep->state & FC_EX_QUARANTINE)) {
+   if (pool->left == FC_XID_UNKNOWN)
+   pool->left = index;
+   else if (pool->right == FC_XID_UNKNOWN)
+   pool->right = index;
+   else
+   pool->next_index = index;
+   fc_exch_ptr_set(pool, index, NULL);
+   } else {
+   fc_exch_ptr_set(pool, index, &fc_quarantine_exch);
+   }
list_del(&ep->ex_list);
spin_unlock_bh(&pool->lock);
fc_exch_release(ep);/* drop hold for exch in mp */
@@ -916,14 +922,14 @@ static inline struct fc_exch *fc_exch_alloc(struct 
fc_lport *lport,
  */
 static struct fc_exch *fc_exch_find(struct fc_exch_mgr *mp, u16 xid)
 {
+   struct fc_lport *lport = mp->lport;
struct fc_exch_pool *pool;
struct fc_exch *ep = NULL;
u16 cpu = xid & fc_cpu_mask;
 
if (cpu >= nr_cpu_ids || !cpu_possible(cpu)) {
-   printk_ratelimited(KERN_ERR
-   "libfc: lookup request for XID = %d, "
-   "indicates invalid CPU %d\n", xid, cpu);
+   pr_err("host%u: lport %6.6x: xid %d invalid CPU %d\n:",
+  lport->host->host_no, lport->port_id, xid, cpu);
return NULL;
}
 
@@ -931,6 +937,10 @@ static struct fc_exch *fc_exch_find(struct fc_exch_mgr 
*mp, u16 xid)
pool = per_cpu_ptr(mp->pool, cpu);
spin_lock_bh(&pool->lock);
ep = fc_exch_ptr_get(pool, (xid - mp->min_xid) >> fc_cpu_order);
+   if (ep == &fc_quarantine_exch) {
+   FC_LPORT_DBG(lport, "xid %x quarantined\n", xid);
+   ep = NULL;
+   }
if (ep) {
WARN_ON(ep->xid != xid);
fc_exch_hold(ep);
@@ -2429,6 +2439,7 @@ struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport 
*lport,
return NULL;
 
mp->class = class;
+   mp->lport = lport;
/* adjust em exch xid range for offload */
mp->min_xid = min_xid;
 
diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index f7700cc..780d9f0 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -1529,13 +1529,14 @@ static void fc_fcp_rec_resp(struct fc_seq *seq, struct 
fc_frame *fp, void *arg)
   fsp->rport->port_id, rjt->er_reason,
   rjt->er_explan);
/*
-* If no data transfer, the command frame got dropped
-* so we just retry.  If data was transferred, we
-* lost the response but the target has no record,
-* so we abort and retry.
+* If response got lost or is stuck in the
+* queue somewhere we have no idea if and when
+* the response will be received. So quarantine
+* the xid and retry the command.
 */
-   if (rjt->er_explan == ELS_EXPL_OXID_R

[PATCH 21/24] fcoe: catch invalid values for the 'enabled' attribute

2016-10-13 Thread Hannes Reinecke
The 'enabled' sysfs attribute only accepts the values '0' and '1',
so we should error out any other values.

Signed-off-by: Hannes Reinecke 
---
 drivers/scsi/fcoe/fcoe_sysfs.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
index 9e6baac..9cf3d56 100644
--- a/drivers/scsi/fcoe/fcoe_sysfs.c
+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
@@ -335,16 +335,24 @@ static ssize_t store_ctlr_enabled(struct device *dev,
  const char *buf, size_t count)
 {
struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev);
+   bool enabled;
int rc;
 
+   if (*buf == '1')
+   enabled = true;
+   else if (*buf == '0')
+   enabled = false;
+   else
+   return -EINVAL;
+
switch (ctlr->enabled) {
case FCOE_CTLR_ENABLED:
-   if (*buf == '1')
+   if (enabled)
return count;
ctlr->enabled = FCOE_CTLR_DISABLED;
break;
case FCOE_CTLR_DISABLED:
-   if (*buf == '0')
+   if (!enabled)
return count;
ctlr->enabled = FCOE_CTLR_ENABLED;
break;
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 17/24] libfc: reset timeout on queue full

2016-10-13 Thread Hannes Reinecke
When we're receiving a timeout we should be checking for queue
full status; if there are still some packets pending we should
be resetting the counter to ensure we're not missing out any
packets which are still queued.

Signed-off-by: Hannes Reinecke 
Acked-by: Johannes Thumshirn 
---
 drivers/scsi/libfc/fc_fcp.c | 20 +---
 include/scsi/libfc.h|  3 ++-
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index d43c925..fb2ebc7 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -254,8 +254,10 @@ static inline void fc_fcp_unlock_pkt(struct fc_fcp_pkt 
*fsp)
  */
 static void fc_fcp_timer_set(struct fc_fcp_pkt *fsp, unsigned long delay)
 {
-   if (!(fsp->state & FC_SRB_COMPL))
+   if (!(fsp->state & FC_SRB_COMPL)) {
mod_timer(&fsp->timer, jiffies + delay);
+   fsp->timer_delay = delay;
+   }
 }
 
 static void fc_fcp_abort_done(struct fc_fcp_pkt *fsp)
@@ -932,6 +934,11 @@ static void fc_fcp_resp(struct fc_fcp_pkt *fsp, struct 
fc_frame *fp)
 * Wait a at least one jiffy to see if it is delivered.
 * If this expires without data, we may do SRR.
 */
+   if (fsp->lp->qfull) {
+   FC_FCP_DBG(fsp, "tgt %6.6x queue busy retry\n",
+  fsp->rport->port_id);
+   return;
+   }
FC_FCP_DBG(fsp, "tgt %6.6x xfer len %zx data underrun "
   "len %x, data len %x\n",
   fsp->rport->port_id,
@@ -1434,8 +1441,15 @@ static void fc_fcp_timeout(unsigned long data)
if (fsp->cdb_cmd.fc_tm_flags)
goto unlock;
 
-   FC_FCP_DBG(fsp, "fcp timeout, flags %x state %x\n",
-  rpriv->flags, fsp->state);
+   if (fsp->lp->qfull) {
+   FC_FCP_DBG(fsp, "fcp timeout, resetting timer delay %d\n",
+  fsp->timer_delay);
+   setup_timer(&fsp->timer, fc_fcp_timeout, (unsigned long)fsp);
+   fc_fcp_timer_set(fsp, fsp->timer_delay);
+   goto unlock;
+   }
+   FC_FCP_DBG(fsp, "fcp timeout, delay %d flags %x state %x\n",
+  fsp->timer_delay, rpriv->flags, fsp->state);
fsp->state |= FC_SRB_FCP_PROCESSING_TMO;
 
if (rpriv->flags & FC_RP_FLAGS_REC_SUPPORTED)
diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
index 8cb752f..f5aa54b 100644
--- a/include/scsi/libfc.h
+++ b/include/scsi/libfc.h
@@ -355,7 +355,8 @@ struct fc_fcp_pkt {
 
/* Timeout/error related information */
struct timer_list timer;
-   int   wait_for_comp;
+   int   wait_for_comp;
+   int   timer_delay;
u32   recov_retry;
struct fc_seq *recov_seq;
struct completion tm_done;
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 18/24] libfc: wait for E_D_TOV when out-of-order sequence is received

2016-10-13 Thread Hannes Reinecke
When detecting an out-of-order sequence we should be waiting for
E_D_TOV before trying to abort the sequence.
The response might still be stuck in the queue somewhere.

Signed-off-by: Hannes Reinecke 
---
 drivers/scsi/libfc/fc_fcp.c | 38 --
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index fb2ebc7..c033946 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -460,6 +460,22 @@ static inline struct fc_frame *fc_fcp_frame_alloc(struct 
fc_lport *lport,
 }
 
 /**
+ * get_fsp_rec_tov() - Helper function to get REC_TOV
+ * @fsp: the FCP packet
+ *
+ * Returns rec tov in jiffies as rpriv->e_d_tov + 1 second
+ */
+static inline unsigned int get_fsp_rec_tov(struct fc_fcp_pkt *fsp)
+{
+   struct fc_rport_libfc_priv *rpriv = fsp->rport->dd_data;
+   unsigned int e_d_tov = FC_DEF_E_D_TOV;
+
+   if (rpriv && rpriv->e_d_tov > e_d_tov)
+   e_d_tov = rpriv->e_d_tov;
+   return msecs_to_jiffies(e_d_tov) + HZ;
+}
+
+/**
  * fc_fcp_recv_data() - Handler for receiving SCSI-FCP data from a target
  * @fsp: The FCP packet the data is on
  * @fp: The data frame
@@ -562,8 +578,10 @@ static void fc_fcp_recv_data(struct fc_fcp_pkt *fsp, 
struct fc_frame *fp)
 * and completes the transfer, call the completion handler.
 */
if (unlikely(fsp->state & FC_SRB_RCV_STATUS) &&
-   fsp->xfer_len == fsp->data_len - fsp->scsi_resid)
+   fsp->xfer_len == fsp->data_len - fsp->scsi_resid) {
+   FC_FCP_DBG( fsp, "complete out-of-order sequence\n" );
fc_fcp_complete_locked(fsp);
+   }
return;
 err:
fc_fcp_recovery(fsp, host_bcode);
@@ -943,7 +961,7 @@ static void fc_fcp_resp(struct fc_fcp_pkt *fsp, struct 
fc_frame *fp)
   "len %x, data len %x\n",
   fsp->rport->port_id,
   fsp->xfer_len, expected_len, fsp->data_len);
-   fc_fcp_timer_set(fsp, 2);
+   fc_fcp_timer_set(fsp, get_fsp_rec_tov(fsp));
return;
}
fsp->status_code = FC_DATA_OVRRUN;
@@ -1152,22 +1170,6 @@ static int fc_fcp_pkt_send(struct fc_lport *lport, 
struct fc_fcp_pkt *fsp)
 }
 
 /**
- * get_fsp_rec_tov() - Helper function to get REC_TOV
- * @fsp: the FCP packet
- *
- * Returns rec tov in jiffies as rpriv->e_d_tov + 1 second
- */
-static inline unsigned int get_fsp_rec_tov(struct fc_fcp_pkt *fsp)
-{
-   struct fc_rport_libfc_priv *rpriv = fsp->rport->dd_data;
-   unsigned int e_d_tov = FC_DEF_E_D_TOV;
-
-   if (rpriv && rpriv->e_d_tov > e_d_tov)
-   e_d_tov = rpriv->e_d_tov;
-   return msecs_to_jiffies(e_d_tov) + HZ;
-}
-
-/**
  * fc_fcp_cmd_send() - Send a FCP command
  * @lport: The local port to send the command on
  * @fsp:   The FCP packet the command is on
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 22/24] fcoe: FIP debugging

2016-10-13 Thread Hannes Reinecke
Add additional statements for debugging FIP frames.

Signed-off-by: Hannes Reinecke 
---
 drivers/scsi/fcoe/fcoe_ctlr.c | 48 +++
 1 file changed, 44 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/fcoe/fcoe_ctlr.c b/drivers/scsi/fcoe/fcoe_ctlr.c
index 05573c3..d773b46 100644
--- a/drivers/scsi/fcoe/fcoe_ctlr.c
+++ b/drivers/scsi/fcoe/fcoe_ctlr.c
@@ -801,6 +801,8 @@ int fcoe_ctlr_els_send(struct fcoe_ctlr *fip, struct 
fc_lport *lport,
return -EINPROGRESS;
 drop:
kfree_skb(skb);
+   LIBFCOE_FIP_DBG(fip, "drop els_send op %u d_id %x\n",
+   op, ntoh24(fh->fh_d_id));
return -EINVAL;
 }
 EXPORT_SYMBOL(fcoe_ctlr_els_send);
@@ -2428,6 +2430,8 @@ static void fcoe_ctlr_vn_probe_req(struct fcoe_ctlr *fip,
switch (fip->state) {
case FIP_ST_VNMP_CLAIM:
case FIP_ST_VNMP_UP:
+   LIBFCOE_FIP_DBG(fip, "vn_probe_req: send reply, state %x\n",
+   fip->state);
fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REP,
  frport->enode_mac, 0);
break;
@@ -2442,15 +2446,21 @@ static void fcoe_ctlr_vn_probe_req(struct fcoe_ctlr 
*fip,
 */
if (fip->lp->wwpn > rdata->ids.port_name &&
!(frport->flags & FIP_FL_REC_OR_P2P)) {
+   LIBFCOE_FIP_DBG(fip, "vn_probe_req: "
+   "port_id collision\n");
fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REP,
  frport->enode_mac, 0);
break;
}
/* fall through */
case FIP_ST_VNMP_START:
+   LIBFCOE_FIP_DBG(fip, "vn_probe_req: "
+   "restart VN2VN negotiation\n");
fcoe_ctlr_vn_restart(fip);
break;
default:
+   LIBFCOE_FIP_DBG(fip, "vn_probe_req: ignore state %x\n",
+   fip->state);
break;
}
 }
@@ -2472,9 +2482,12 @@ static void fcoe_ctlr_vn_probe_reply(struct fcoe_ctlr 
*fip,
case FIP_ST_VNMP_PROBE1:
case FIP_ST_VNMP_PROBE2:
case FIP_ST_VNMP_CLAIM:
+   LIBFCOE_FIP_DBG(fip, "vn_probe_reply: restart state %x\n",
+   fip->state);
fcoe_ctlr_vn_restart(fip);
break;
case FIP_ST_VNMP_UP:
+   LIBFCOE_FIP_DBG(fip, "vn_probe_reply: send claim notify\n");
fcoe_ctlr_vn_send_claim(fip);
break;
default:
@@ -2517,6 +2530,7 @@ static void fcoe_ctlr_vn_add(struct fcoe_ctlr *fip, 
struct fc_rport_priv *new)
if ((ids->port_name != -1 && ids->port_name != new->ids.port_name) ||
(ids->node_name != -1 && ids->node_name != new->ids.node_name)) {
mutex_unlock(&rdata->rp_mutex);
+   LIBFCOE_FIP_DBG(fip, "vn_add rport logoff %6.6x\n", port_id);
lport->tt.rport_logoff(rdata);
mutex_lock(&rdata->rp_mutex);
}
@@ -2525,8 +2539,9 @@ static void fcoe_ctlr_vn_add(struct fcoe_ctlr *fip, 
struct fc_rport_priv *new)
mutex_unlock(&rdata->rp_mutex);
 
frport = fcoe_ctlr_rport(rdata);
-   LIBFCOE_FIP_DBG(fip, "vn_add rport %6.6x %s\n",
-   port_id, frport->fcoe_len ? "old" : "new");
+   LIBFCOE_FIP_DBG(fip, "vn_add rport %6.6x %s state %d\n",
+   port_id, frport->fcoe_len ? "old" : "new",
+   rdata->rp_state);
*frport = *fcoe_ctlr_rport(new);
frport->time = 0;
 }
@@ -2569,6 +2584,7 @@ static void fcoe_ctlr_vn_claim_notify(struct fcoe_ctlr 
*fip,
struct fcoe_rport *frport = fcoe_ctlr_rport(new);
 
if (frport->flags & FIP_FL_REC_OR_P2P) {
+   LIBFCOE_FIP_DBG(fip, "send probe req for P2P/REC\n");
fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0);
return;
}
@@ -2576,25 +2592,37 @@ static void fcoe_ctlr_vn_claim_notify(struct fcoe_ctlr 
*fip,
case FIP_ST_VNMP_START:
case FIP_ST_VNMP_PROBE1:
case FIP_ST_VNMP_PROBE2:
-   if (new->ids.port_id == fip->port_id)
+   if (new->ids.port_id == fip->port_id) {
+   LIBFCOE_FIP_DBG(fip, "vn_claim_notify: "
+   "restart, state %d\n",
+   fip->state);
fcoe_ctlr_vn_restart(fip);
+   }
break;
case FIP_ST_VNMP_CLAIM:
case FIP_ST_VNMP_UP:
if (new->ids.port_id == fip->port_id) {
if (new->ids.port_name > fip->lp->wwpn) {
+   LIBFCOE_FIP_DBG(fip, "vn_claim_notify: "
+   "restart, port_id collision\n");
  

[PATCH 16/24] libfc: Do not drop out-of-order frames

2016-10-13 Thread Hannes Reinecke
When receiving packets from the network we cannot guarantee any
frame ordering, so we should be receiving all valid frames and
let the upper layers deal with it.

Signed-off-by: Hannes Reinecke 
Acked-by: Johannes Thumshirn 
---
 drivers/scsi/libfc/fc_exch.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
index 5868824..c62fc27 100644
--- a/drivers/scsi/libfc/fc_exch.c
+++ b/drivers/scsi/libfc/fc_exch.c
@@ -1592,9 +1592,6 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, 
struct fc_frame *fp)
if (fc_sof_is_init(sof)) {
sp->ssb_stat |= SSB_ST_RESP;
sp->id = fh->fh_seq_id;
-   } else if (sp->id != fh->fh_seq_id) {
-   atomic_inc(&mp->stats.seq_not_found);
-   goto rel;
}
 
f_ctl = ntoh24(fh->fh_f_ctl);
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 23/24] fcoe: correct sending FIP VLAN packets on VLAN 0

2016-10-13 Thread Hannes Reinecke
The FIP VLAN frame consists of an ethernet header followed
by the FIP VLAN frame, so we need to skip the ethernet header
if we want to check the FIP opcode.

Signed-off-by: Hannes Reinecke 
---
 drivers/scsi/fcoe/fcoe.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
index 9876fca..cf4adaa 100644
--- a/drivers/scsi/fcoe/fcoe.c
+++ b/drivers/scsi/fcoe/fcoe.c
@@ -590,7 +590,8 @@ static void fcoe_fip_send(struct fcoe_ctlr *fip, struct 
sk_buff *skb)
 * Use default VLAN for FIP VLAN discovery protocol
 */
frame = (struct fip_frame *)skb->data;
-   if (frame->fip.fip_op == ntohs(FIP_OP_VLAN) &&
+   if (ntohs(frame->eth.h_proto) == ETH_P_FIP &&
+   ntohs(frame->fip.fip_op) == FIP_OP_VLAN &&
fcoe->realdev != fcoe->netdev)
skb->dev = fcoe->realdev;
else
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 20/24] fcoe: set default TC priority

2016-10-13 Thread Hannes Reinecke
If DCB is not enabled or compiled in we still should be setting
a sane default priority. So put FCoE frames in priority class
'interactive' and FIP frames in priority class 'besteffort'.

Signed-off-by: Hannes Reinecke 
---
 drivers/scsi/fcoe/fcoe.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
index c907661..9876fca 100644
--- a/drivers/scsi/fcoe/fcoe.c
+++ b/drivers/scsi/fcoe/fcoe.c
@@ -2168,6 +2168,8 @@ static bool fcoe_match(struct net_device *netdev)
  */
 static void fcoe_dcb_create(struct fcoe_interface *fcoe)
 {
+   int ctlr_prio = TC_PRIO_BESTEFFORT;
+   int fcoe_prio = TC_PRIO_INTERACTIVE;
 #ifdef CONFIG_DCB
int dcbx;
u8 fup, up;
@@ -2194,10 +2196,12 @@ static void fcoe_dcb_create(struct fcoe_interface *fcoe)
fup = dcb_getapp(netdev, &app);
}
 
-   fcoe->priority = ffs(up) ? ffs(up) - 1 : 0;
-   ctlr->priority = ffs(fup) ? ffs(fup) - 1 : fcoe->priority;
+   fcoe_prio = ffs(up) ? ffs(up) - 1 : 0;
+   ctlr_prio = ffs(fup) ? ffs(fup) - 1 : fcoe_prio;
}
 #endif
+   fcoe->priority = fcoe_prio;
+   ctlr->priority = ctlr_prio;
 }
 
 enum fcoe_create_link_state {
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 19/24] libfc: Check xid when looking up REC exchanges

2016-10-13 Thread Hannes Reinecke
We currently can only lookup the local xid, so we need
to reject REC with empty rxid.

Signed-off-by: Hannes Reinecke 
---
 drivers/scsi/libfc/fc_exch.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
index c62fc27..4c69a99 100644
--- a/drivers/scsi/libfc/fc_exch.c
+++ b/drivers/scsi/libfc/fc_exch.c
@@ -2000,8 +2000,7 @@ static void fc_exch_els_rec(struct fc_frame *rfp)
enum fc_els_rjt_reason reason = ELS_RJT_LOGIC;
enum fc_els_rjt_explan explan;
u32 sid;
-   u16 rxid;
-   u16 oxid;
+   u16 xid, rxid, oxid;
 
lport = fr_dev(rfp);
rp = fc_frame_payload_get(rfp, sizeof(*rp));
@@ -2012,9 +2011,18 @@ static void fc_exch_els_rec(struct fc_frame *rfp)
rxid = ntohs(rp->rec_rx_id);
oxid = ntohs(rp->rec_ox_id);
 
-   ep = fc_exch_lookup(lport,
-   sid == fc_host_port_id(lport->host) ? oxid : rxid);
explan = ELS_EXPL_OXID_RXID;
+   if (sid == fc_host_port_id(lport->host))
+   xid = oxid;
+   else
+   xid = rxid;
+   if (xid == FC_XID_UNKNOWN) {
+   FC_LPORT_DBG(lport,
+"REC request from %x: invalid rxid %x oxid %x\n",
+sid, rxid, oxid);
+   goto reject;
+   }
+   ep = fc_exch_lookup(lport, xid);
if (!ep) {
FC_LPORT_DBG(lport,
 "REC request from %x: rxid %x oxid %x not found\n",
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 15/24] libfc: don't fail sequence abort for completed exchanges

2016-10-13 Thread Hannes Reinecke
If a sequence should be aborted the exchange might already
be completed (eg if the response is still queued in the rx
queue), so this shouldn't considered as an error.

Signed-off-by: Hannes Reinecke 
Acked-by: Johannes Thumshirn 
---
 drivers/scsi/libfc/fc_fcp.c | 40 ++--
 1 file changed, 30 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index 780d9f0..d43c925 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -258,6 +258,17 @@ static void fc_fcp_timer_set(struct fc_fcp_pkt *fsp, 
unsigned long delay)
mod_timer(&fsp->timer, jiffies + delay);
 }
 
+static void fc_fcp_abort_done(struct fc_fcp_pkt *fsp)
+{
+   fsp->state |= FC_SRB_ABORTED;
+   fsp->state &= ~FC_SRB_ABORT_PENDING;
+
+   if (fsp->wait_for_comp)
+   complete(&fsp->tm_done);
+   else
+   fc_fcp_complete_locked(fsp);
+}
+
 /**
  * fc_fcp_send_abort() - Send an abort for exchanges associated with a
  *  fcp_pkt
@@ -265,6 +276,8 @@ static void fc_fcp_timer_set(struct fc_fcp_pkt *fsp, 
unsigned long delay)
  */
 static int fc_fcp_send_abort(struct fc_fcp_pkt *fsp)
 {
+   int rc;
+
if (!fsp->seq_ptr)
return -EINVAL;
 
@@ -272,7 +285,16 @@ static int fc_fcp_send_abort(struct fc_fcp_pkt *fsp)
put_cpu();
 
fsp->state |= FC_SRB_ABORT_PENDING;
-   return fsp->lp->tt.seq_exch_abort(fsp->seq_ptr, 0);
+   rc = fsp->lp->tt.seq_exch_abort(fsp->seq_ptr, 0);
+   /*
+* ->seq_exch_abort() might return -ENXIO if
+* the sequence is already completed
+*/
+   if (rc == -ENXIO) {
+   fc_fcp_abort_done(fsp);
+   rc = 0;
+   }
+   return rc;
 }
 
 /**
@@ -729,15 +751,8 @@ static void fc_fcp_abts_resp(struct fc_fcp_pkt *fsp, 
struct fc_frame *fp)
ba_done = 0;
}
 
-   if (ba_done) {
-   fsp->state |= FC_SRB_ABORTED;
-   fsp->state &= ~FC_SRB_ABORT_PENDING;
-
-   if (fsp->wait_for_comp)
-   complete(&fsp->tm_done);
-   else
-   fc_fcp_complete_locked(fsp);
-   }
+   if (ba_done)
+   fc_fcp_abort_done(fsp);
 }
 
 /**
@@ -1245,6 +1260,11 @@ static int fc_fcp_pkt_abort(struct fc_fcp_pkt *fsp)
return FAILED;
}
 
+   if (fsp->state & FC_SRB_ABORTED) {
+   FC_FCP_DBG(fsp, "target abort cmd  completed\n");
+   return SUCCESS;
+   }
+
init_completion(&fsp->tm_done);
fsp->wait_for_comp = 1;
 
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 24/24] fcoe: filter out frames from invalid vlans

2016-10-13 Thread Hannes Reinecke
Any multicase address is set on all interfaces, the base interface
and any VLAN interfaces on top of this. So we might receive frames
which are not destined for us.

Signed-off-by: Hannes Reinecke 
---
 drivers/scsi/fcoe/fcoe_ctlr.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/fcoe/fcoe_ctlr.c b/drivers/scsi/fcoe/fcoe_ctlr.c
index d773b46..4aacd60 100644
--- a/drivers/scsi/fcoe/fcoe_ctlr.c
+++ b/drivers/scsi/fcoe/fcoe_ctlr.c
@@ -2754,11 +2754,21 @@ static int fcoe_ctlr_vn_recv(struct fcoe_ctlr *fip, 
struct sk_buff *skb)
struct fc_rport_priv rdata;
struct fcoe_rport frport;
} buf;
-   int rc;
+   int rc, vlan_id = 0;
 
fiph = (struct fip_header *)skb->data;
sub = fiph->fip_subcode;
 
+   if (fip->lp->vlan)
+   vlan_id = skb_vlan_tag_get_id(skb);
+
+   if (vlan_id && vlan_id != fip->lp->vlan) {
+   LIBFCOE_FIP_DBG(fip, "vn_recv drop frame sub %x vlan %d\n",
+   sub, vlan_id);
+   rc = -EAGAIN;
+   goto drop;
+   }
+
rc = fcoe_ctlr_vn_parse(fip, skb, &buf.rdata);
if (rc) {
LIBFCOE_FIP_DBG(fip, "vn_recv vn_parse error %d\n", rc);
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 21/24] fcoe: catch invalid values for the 'enabled' attribute

2016-10-13 Thread Johannes Thumshirn
On Thu, Oct 13, 2016 at 03:10:57PM +0200, Hannes Reinecke wrote:
> The 'enabled' sysfs attribute only accepts the values '0' and '1',
> so we should error out any other values.
> 
> Signed-off-by: Hannes Reinecke 
> ---

Acked-by: Johannes Thumshirn 

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+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
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 05/24] libfc: sanitize E_D_TOV and R_A_TOV setting

2016-10-13 Thread Johannes Thumshirn
On Thu, Oct 13, 2016 at 03:10:41PM +0200, Hannes Reinecke wrote:
> When setting the FCP timeout we need to ensure a lower boundary
> for E_D_TOV and R_A_TOV, otherwise we'd be getting spurious I/O
> issues due to the fcp timer firing too early.
> 
> Signed-off-by: Hannes Reinecke 
> ---

Acked-by: Johannes Thumshirn 
-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+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
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Patch: [Open-FCoE] Revert commit 3e22760d4db6fd89e0be46c3d132390a251da9c6 due to performance issues

2016-10-13 Thread Johannes Thumshirn
On Thu, Oct 13, 2016 at 08:43:30AM -0400, Laurence Oberman wrote:
> 
> 
> Hello
> 
> This patch reverts commit 3e22760d4db6fd89e0be46c3d132390a251da9c6.
> 
> This revert came about because of efforts by Ewan Milne, Curtis Taylor and I.
> In researching this issue, significant performance issues were seen on large 
> CPU count 
> systems using the software FCOE stack.
> Hannes also weighed in.
> 
> The same was not apparent on much smaller low count CPU systems.
> The behavior introduced by commit 3e22760d4db6fd89e0be46c3d132390a251da9c6 
> lands sup with large
> count CPU systems seeing continual blk_requeue_request() calls due to 
> ML_QUEUE_HOST_BUSY.
> 
> From Ewan:
> 
> fc_exch_alloc() used to try all the available exchange managers in the
> list for an available exchange id, but this was changed in 2010 so that
> if the first matched exchange manager couldn't allocate one, it fails
> and we end up returning host busy.  This was due to commit:
> 
> Setting the ddp_min module parameter to fcoe to 128MB prevents the ->match
> function from permitting the use of the offload exchange manager for the 
> frame,
> and we no longer see the problem with host busy status, since it uses the
> larger non-offloaded pool.
> 
> Reverting commit 3e22760d4db6fd89e0be46c3d132390a251da9c6 was tested to also
> prevent the host busy issue due to failing allocations.
> 
> Suggested-by: Ewan Milne 
> Suggested-by: Curtis Taylor 
> Tested-by: Laurence Oberman 
> Signed-off-by: Laurence Oberman 
> 

Acked-by: Johannes Thumshirn 

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+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
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 10/24] libfc: Rework PRLI handling

2016-10-13 Thread Johannes Thumshirn
On Thu, Oct 13, 2016 at 03:10:46PM +0200, Hannes Reinecke wrote:
> PRLI is only required if the port is acting as an initiator; ports
> which support target functionality only do not need to send PRLI.
> At the same time the PRLI state is only used if the port initiated
> a PRLI transfer; if we received a PRLI request we should _not_
> change the state as this would cause our PRLI response to be dropped.
> And when we receive a PRLI response we need to check if an image
> pair has been established; if not the remote port cannot act as a
> target for us and we need to disable target functionality.
> 
> Signed-off-by: Hannes Reinecke 
> ---

Acked-by: Johannes Thumshirn 
-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+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
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 12/24] libfc: Clarify ramp-down messages

2016-10-13 Thread Johannes Thumshirn
On Thu, Oct 13, 2016 at 03:10:48PM +0200, Hannes Reinecke wrote:
> When the queue depth is reduced we should print out the reason
> for this; it might be due to a queue full condition.
> 
> Signed-off-by: Hannes Reinecke 
> ---

Acked-by: Johannes Thumshirn 
-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+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
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 08/16] scsi: fc: implement kref backed reference counting

2016-10-13 Thread Johannes Thumshirn
On Thu, Oct 13, 2016 at 01:42:06PM +0200, Hannes Reinecke wrote:
> On 10/12/2016 03:06 PM, Johannes Thumshirn wrote:
> > Implement kref backed reference counting instead of rolling our own. This
> > elimnates the need of the following fields in 'struct fc_bsg_job':
> > * ref_cnt
> > * state_flags
> > * job_lock
> > bringing us close to unification of 'struct fc_bsg_job' and 'struct 
> > bsg_job'.
> > 
> > Signed-off-by: Johannes Thumshirn 
> > ---
> >  drivers/scsi/scsi_transport_fc.c | 38 
> > +-
> >  include/scsi/scsi_transport_fc.h |  4 +---
> >  2 files changed, 10 insertions(+), 32 deletions(-)
> > 
> > diff --git a/drivers/scsi/scsi_transport_fc.c 
> > b/drivers/scsi/scsi_transport_fc.c
> > index 96b3a2e..b0e28af 100644
> > --- a/drivers/scsi/scsi_transport_fc.c
> > +++ b/drivers/scsi/scsi_transport_fc.c
> > @@ -3560,16 +3560,9 @@ fc_vport_sched_delete(struct work_struct *work)
> >   * @job:   fc_bsg_job that is to be torn down
> >   */
> >  static void
> > -fc_destroy_bsgjob(struct fc_bsg_job *job)
> > +fc_destroy_bsgjob(struct kref *kref)
> >  {
> > -   unsigned long flags;
> > -
> > -   spin_lock_irqsave(&job->job_lock, flags);
> > -   if (job->ref_cnt) {
> > -   spin_unlock_irqrestore(&job->job_lock, flags);
> > -   return;
> > -   }
> > -   spin_unlock_irqrestore(&job->job_lock, flags);
> > +   struct fc_bsg_job *job = container_of(kref, struct fc_bsg_job, kref);
> >  
> > put_device(job->dev);   /* release reference for the request */
> >  
> > @@ -3620,15 +3613,9 @@ EXPORT_SYMBOL_GPL(fc_bsg_jobdone);
> >  static void fc_bsg_softirq_done(struct request *rq)
> >  {
> > struct fc_bsg_job *job = rq->special;
> > -   unsigned long flags;
> > -
> > -   spin_lock_irqsave(&job->job_lock, flags);
> > -   job->state_flags |= FC_RQST_STATE_DONE;
> > -   job->ref_cnt--;
> > -   spin_unlock_irqrestore(&job->job_lock, flags);
> >  
> > blk_end_request_all(rq, rq->errors);
> > -   fc_destroy_bsgjob(job);
> > +   kref_put(&job->kref, fc_destroy_bsgjob);
> >  }
> >  
> >  /**
> Hmm. blk_end_request_all() (potentially) triggers a recursion into all
> .end_io callbacks, which might end up doing god-knows-what.
> With some delays in doing so
> During that time we have no idea that bsg_softirq_done() is actually
> running, and we might clash with eg. timeouts or somesuch.
> 
> Maybe it's an idea to move blk_end_request_all into the kref destroy
> callback; that way we're guaranteed to call it only once and would avoid
> this situation.

This _could_ explain the panic with zfcp. Fixed that for v3.

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+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
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 07/16] scsi: libfc: don't set FC_RQST_STATE_DONE before calling fc_bsg_jobdone()

2016-10-13 Thread Johannes Thumshirn
Don't set FC_RQST_STATE_DONE before calling fc_bsg_jobdone() as
fc_bsg_jobdone() calls blk_complete_requeust() which raises a soft-IRQ that
ends up in fc_bsg_sofirq_done() and fc_bsg_softirq_done() sets the
FC_RQST_STATE_DONE flag.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 drivers/scsi/libfc/fc_lport.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 9ba340c..34570cf 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -1916,7 +1916,6 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
bsg_reply->result = (PTR_ERR(fp) == -FC_EX_CLOSED) ?
-ECONNABORTED : -ETIMEDOUT;
job->reply_len = sizeof(uint32_t);
-   job->state_flags |= FC_RQST_STATE_DONE;
fc_bsg_jobdone(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
kfree(info);
@@ -1952,7 +1951,6 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
bsg_reply->reply_payload_rcv_len =
job->reply_payload.payload_len;
bsg_reply->result = 0;
-   job->state_flags |= FC_RQST_STATE_DONE;
fc_bsg_jobdone(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
kfree(info);
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 15/16] scsi: fc: move FC transport's bsg code to bsg-lib

2016-10-13 Thread Johannes Thumshirn
Now that all conversions are done, move the FibreChannel bsg code over to the
bsg library.

This patch is derived from work done by Mike Christie in 2011 [1] but only the
iscsi parts got merged back then.

[1] http://marc.info/?l=linux-scsi&m=131149780921009&w=2

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 drivers/scsi/scsi_transport_fc.c | 287 ++-
 1 file changed, 43 insertions(+), 244 deletions(-)

diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 7fae045..916d488 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3591,111 +3591,12 @@ struct fc_vport *
return BLK_EH_HANDLED;
 }
 
-static int
-fc_bsg_map_buffer(struct bsg_buffer *buf, struct request *req)
-{
-   size_t sz = (sizeof(struct scatterlist) * req->nr_phys_segments);
-
-   BUG_ON(!req->nr_phys_segments);
-
-   buf->sg_list = kzalloc(sz, GFP_KERNEL);
-   if (!buf->sg_list)
-   return -ENOMEM;
-   sg_init_table(buf->sg_list, req->nr_phys_segments);
-   buf->sg_cnt = blk_rq_map_sg(req->q, req, buf->sg_list);
-   buf->payload_len = blk_rq_bytes(req);
-   return 0;
-}
-
-
-/**
- * fc_req_to_bsgjob - Allocate/create the fc_bsg_job structure for the
- *   bsg request
- * @shost: SCSI Host corresponding to the bsg object
- * @rport: (optional) FC Remote Port corresponding to the bsg object
- * @req:   BSG request that needs a job structure
- */
-static int
-fc_req_to_bsgjob(struct Scsi_Host *shost, struct fc_rport *rport,
-   struct request *req)
-{
-   struct fc_internal *i = to_fc_internal(shost->transportt);
-   struct request *rsp = req->next_rq;
-   struct bsg_job *job;
-   struct fc_bsg_request *bsg_request;
-   struct fc_bsg_reply *bsg_reply;
-   int ret;
-
-   BUG_ON(req->special);
-
-   job = kzalloc(sizeof(struct bsg_job) + i->f->dd_bsg_size,
-   GFP_KERNEL);
-   if (!job)
-   return -ENOMEM;
-
-   /*
-* Note: this is a bit silly.
-* The request gets formatted as a SGIO v4 ioctl request, which
-* then gets reformatted as a blk request, which then gets
-* reformatted as a fc bsg request. And on completion, we have
-* to wrap return results such that SGIO v4 thinks it was a scsi
-* status.  I hope this was all worth it.
-*/
-
-   req->special = job;
-   job->req = req;
-   if (i->f->dd_bsg_size)
-   job->dd_data = (void *)&job[1];
-   bsg_request = (struct fc_bsg_request *)req->cmd;
-   job->request_len = req->cmd_len;
-   bsg_reply = req->sense;
-   job->reply_len = SCSI_SENSE_BUFFERSIZE; /* Size of sense buffer
-* allocated */
-   if (req->bio) {
-   ret = fc_bsg_map_buffer(&job->request_payload, req);
-   if (ret)
-   goto failjob_rls_job;
-   }
-   if (rsp && rsp->bio) {
-   ret = fc_bsg_map_buffer(&job->reply_payload, rsp);
-   if (ret)
-   goto failjob_rls_rqst_payload;
-   }
-   if (rport)
-   job->dev = &rport->dev;
-   else
-   job->dev = &shost->shost_gendev;
-   get_device(job->dev);   /* take a reference for the request */
-
-   kref_init(&job->kref);
-
-   return 0;
-
-
-failjob_rls_rqst_payload:
-   kfree(job->request_payload.sg_list);
-failjob_rls_job:
-   kfree(job);
-   return -ENOMEM;
-}
-
-
-enum fc_dispatch_result {
-   FC_DISPATCH_BREAK,  /* on return, q is locked, break from q loop */
-   FC_DISPATCH_LOCKED, /* on return, q is locked, continue on */
-   FC_DISPATCH_UNLOCKED,   /* on return, q is unlocked, continue on */
-};
-
-
 /**
  * fc_bsg_host_dispatch - process fc host bsg requests and dispatch to LLDD
- * @q: fc host request queue
  * @shost: scsi host rport attached to
  * @job:   bsg job to be processed
  */
-static enum fc_dispatch_result
-fc_bsg_host_dispatch(struct request_queue *q, struct Scsi_Host *shost,
-struct bsg_job *job)
+static int fc_bsg_host_dispatch(struct Scsi_Host *shost, struct bsg_job *job)
 {
struct fc_internal *i = to_fc_internal(shost->transportt);
struct fc_bsg_request *bsg_request = job->request;
@@ -3756,7 +3657,7 @@ enum fc_dispatch_result {
 
ret = i->f->bsg_request(job);
if (!ret)
-   return FC_DISPATCH_UNLOCKED;
+   return 0;
 
 fail_host_msg:
/* return the errno failure code as the only status */
@@ -3766,7 +3667,7 @@ enum fc_dispatch_result {
job->reply_len = sizeof(uint32_t);
bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
-   return FC_DISPATCH_UNLOCKED;
+   return 0;
 }
 
 
@@ -3790,14 +36

[PATCH v3 16/16] block: unexport bsg_softirq_done() again

2016-10-13 Thread Johannes Thumshirn
Unexport bsg_softirq_done() again, we don't need it outside of bsg-lib.c
anymore now that scsi_transport_fc is a pure bsg-lib client.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 block/bsg-lib.c | 3 +--
 include/linux/bsg-lib.h | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 803ec40..2d1df5c 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -96,13 +96,12 @@ void bsg_job_done(struct bsg_job *job, int result,
  * bsg_softirq_done - softirq done routine for destroying the bsg requests
  * @rq: BSG request that holds the job to be destroyed
  */
-void bsg_softirq_done(struct request *rq)
+static void bsg_softirq_done(struct request *rq)
 {
struct bsg_job *job = rq->special;
 
bsg_job_put(job);
 }
-EXPORT_SYMBOL_GPL(bsg_softirq_done);
 
 static int bsg_map_buffer(struct bsg_buffer *buf, struct request *req)
 {
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index b708db9..657a718 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -69,7 +69,6 @@ void bsg_job_done(struct bsg_job *job, int result,
 int bsg_setup_queue(struct device *dev, struct request_queue *q, char *name,
bsg_job_fn *job_fn, int dd_job_size);
 void bsg_request_fn(struct request_queue *q);
-void bsg_softirq_done(struct request *rq);
 void bsg_job_put(struct bsg_job *job);
 int __must_check bsg_job_get(struct bsg_job *job);
 
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 11/16] scsi: fc: Use bsg_destroy_job

2016-10-13 Thread Johannes Thumshirn
fc_destroy_bsgjob() and bsg_destroy_job() are now 1:1 copies, so use the
later. As bsg_destroy_job() comes from bsg-lib we need to select it in Kconfig
once CONFOG_SCSI_FC_ATTRS is active.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 block/bsg-lib.c  |  7 +--
 drivers/scsi/Kconfig |  1 +
 drivers/scsi/scsi_transport_fc.c | 23 ++-
 include/linux/bsg-lib.h  |  1 +
 4 files changed, 9 insertions(+), 23 deletions(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 632fb40..9f1e8fd 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -32,9 +32,12 @@
  * bsg_destroy_job - routine to teardown/delete a bsg job
  * @job: bsg_job that is to be torn down
  */
-static void bsg_destroy_job(struct kref *kref)
+void bsg_destroy_job(struct kref *kref)
 {
struct bsg_job *job = container_of(kref, struct bsg_job, kref);
+   struct request *rq = job->req;
+
+   blk_end_request_all(rq, rq->errors);
 
put_device(job->dev);   /* release reference for the request */
 
@@ -42,6 +45,7 @@ static void bsg_destroy_job(struct kref *kref)
kfree(job->reply_payload.sg_list);
kfree(job);
 }
+EXPORT_SYMBOL_GPL(bsg_destroy_job);
 
 /**
  * bsg_job_done - completion routine for bsg requests
@@ -85,7 +89,6 @@ static void bsg_softirq_done(struct request *rq)
 {
struct bsg_job *job = rq->special;
 
-   blk_end_request_all(rq, rq->errors);
kref_put(&job->kref, bsg_destroy_job);
 }
 
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 3e2bdb9..2774756 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -263,6 +263,7 @@ config SCSI_SPI_ATTRS
 config SCSI_FC_ATTRS
tristate "FiberChannel Transport Attributes"
depends on SCSI && NET
+   select BLK_DEV_BSGLIB
select SCSI_NETLINK
help
  If you wish to export transport-specific information about
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index eadc80f..d2d0a27 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -3554,26 +3555,6 @@ struct fc_vport *
  * BSG support
  */
 
-
-/**
- * fc_destroy_bsgjob - routine to teardown/delete a fc bsg job
- * @job:   fc_bsg_job that is to be torn down
- */
-static void
-fc_destroy_bsgjob(struct kref *kref)
-{
-   struct bsg_job *job = container_of(kref, struct bsg_job, kref);
-   struct request *rq = job->req;
-
-   blk_end_request_all(rq, rq->errors);
-
-   put_device(job->dev);   /* release reference for the request */
-
-   kfree(job->request_payload.sg_list);
-   kfree(job->reply_payload.sg_list);
-   kfree(job);
-}
-
 /**
  * fc_bsg_jobdone - completion routine for bsg requests that the LLD has
  *  completed
@@ -3642,7 +3623,7 @@ static void fc_bsg_softirq_done(struct request *rq)
/* call LLDD to abort the i/o as it has timed out */
err = i->f->bsg_timeout(job);
if (err == -EAGAIN) {
-   kref_put(&job->kref, fc_destroy_bsgjob);
+   kref_put(&job->kref, bsg_destroy_job);
return BLK_EH_RESET_TIMER;
} else if (err)
printk(KERN_ERR "ERROR: FC BSG request timeout - LLD "
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index 58e0717..67f7de6 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -69,5 +69,6 @@ void bsg_job_done(struct bsg_job *job, int result,
 int bsg_setup_queue(struct device *dev, struct request_queue *q, char *name,
bsg_job_fn *job_fn, int dd_job_size);
 void bsg_request_fn(struct request_queue *q);
+void bsg_destroy_job(struct kref *kref);
 
 #endif
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 14/16] block: add bsg_job_put() and bsg_job_get()

2016-10-13 Thread Johannes Thumshirn
Add bsg_job_put() and bsg_job_get() so don't need to export
bsg_destroy_job() any more.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 block/bsg-lib.c  | 17 ++---
 drivers/scsi/scsi_transport_fc.c |  4 ++--
 include/linux/bsg-lib.h  |  3 ++-
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 6661f82..803ec40 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -32,7 +32,7 @@
  * bsg_destroy_job - routine to teardown/delete a bsg job
  * @job: bsg_job that is to be torn down
  */
-void bsg_destroy_job(struct kref *kref)
+static void bsg_destroy_job(struct kref *kref)
 {
struct bsg_job *job = container_of(kref, struct bsg_job, kref);
struct request *rq = job->req;
@@ -45,7 +45,18 @@ void bsg_destroy_job(struct kref *kref)
kfree(job->reply_payload.sg_list);
kfree(job);
 }
-EXPORT_SYMBOL_GPL(bsg_destroy_job);
+
+void bsg_job_put(struct bsg_job *job)
+{
+   kref_put(&job->kref, bsg_destroy_job);
+}
+EXPORT_SYMBOL_GPL(bsg_job_put);
+
+int bsg_job_get(struct bsg_job *job)
+{
+   return kref_get_unless_zero(&job->kref);
+}
+EXPORT_SYMBOL_GPL(bsg_job_get);
 
 /**
  * bsg_job_done - completion routine for bsg requests
@@ -89,7 +100,7 @@ void bsg_softirq_done(struct request *rq)
 {
struct bsg_job *job = rq->special;
 
-   kref_put(&job->kref, bsg_destroy_job);
+   bsg_job_put(job);
 }
 EXPORT_SYMBOL_GPL(bsg_softirq_done);
 
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 720ddc9..7fae045 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3571,13 +3571,13 @@ struct fc_vport *
if (rport && rport->port_state == FC_PORTSTATE_BLOCKED)
return BLK_EH_RESET_TIMER;
 
-   inflight = kref_get_unless_zero(&job->kref);
+   inflight = bsg_job_get(job);
 
if (inflight && i->f->bsg_timeout) {
/* call LLDD to abort the i/o as it has timed out */
err = i->f->bsg_timeout(job);
if (err == -EAGAIN) {
-   kref_put(&job->kref, bsg_destroy_job);
+   bsg_job_put(job);
return BLK_EH_RESET_TIMER;
} else if (err)
printk(KERN_ERR "ERROR: FC BSG request timeout - LLD "
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index 09f3044..b708db9 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -69,7 +69,8 @@ void bsg_job_done(struct bsg_job *job, int result,
 int bsg_setup_queue(struct device *dev, struct request_queue *q, char *name,
bsg_job_fn *job_fn, int dd_job_size);
 void bsg_request_fn(struct request_queue *q);
-void bsg_destroy_job(struct kref *kref);
 void bsg_softirq_done(struct request *rq);
+void bsg_job_put(struct bsg_job *job);
+int __must_check bsg_job_get(struct bsg_job *job);
 
 #endif
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 06/16] scsi: fc: provide fc_bsg_to_rport() helper

2016-10-13 Thread Johannes Thumshirn
Provide fc_bsg_to_rport() helper that will become handy when we're moving
from struct fc_bsg_job to a plain struct bsg_job. Also move all LLDDs to use
the new helper.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 drivers/s390/scsi/zfcp_fc.c  | 5 +++--
 drivers/scsi/ibmvscsi/ibmvfc.c   | 2 +-
 drivers/scsi/libfc/fc_lport.c| 4 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 4 ++--
 drivers/scsi/qla2xxx/qla_bsg.c   | 4 ++--
 drivers/scsi/scsi_transport_fc.c | 3 ++-
 include/scsi/scsi_transport_fc.h | 5 +
 7 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 813c286..1977a66 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -938,7 +938,7 @@ static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
struct zfcp_adapter *adapter)
 {
struct zfcp_fsf_ct_els *els = job->dd_data;
-   struct fc_rport *rport = job->rport;
+   struct fc_rport *rport = fc_bsg_to_rport(job);
struct fc_bsg_request *bsg_request = job->request;
struct zfcp_port *port;
u32 d_id;
@@ -986,8 +986,9 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
struct zfcp_adapter *adapter;
struct zfcp_fsf_ct_els *ct_els = job->dd_data;
struct fc_bsg_request *bsg_request = job->request;
+   struct fc_rport *rport = fc_bsg_to_rport(job);
 
-   shost = job->rport ? rport_to_shost(job->rport) : fc_bsg_to_shost(job);
+   shost = rport ? rport_to_shost(rport) : fc_bsg_to_shost(job);
adapter = (struct zfcp_adapter *)shost->hostdata[0];
 
if (!(atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN))
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index 02df1f1..4c73fc7 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1822,7 +1822,7 @@ static int ibmvfc_bsg_plogi(struct ibmvfc_host *vhost, 
unsigned int port_id)
 static int ibmvfc_bsg_request(struct fc_bsg_job *job)
 {
struct ibmvfc_host *vhost = shost_priv(fc_bsg_to_shost(job));
-   struct fc_rport *rport = job->rport;
+   struct fc_rport *rport = fc_bsg_to_rport(job);
struct ibmvfc_passthru_mad *mad;
struct ibmvfc_event *evt;
union ibmvfc_iu rsp_iu;
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index a3fb355..9ba340c 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -2107,7 +2107,7 @@ int fc_lport_bsg_request(struct fc_bsg_job *job)
 
switch (bsg_request->msgcode) {
case FC_BSG_RPT_ELS:
-   rport = job->rport;
+   rport = fc_bsg_to_rport(job);
if (!rport)
break;
 
@@ -2117,7 +2117,7 @@ int fc_lport_bsg_request(struct fc_bsg_job *job)
break;
 
case FC_BSG_RPT_CT:
-   rport = job->rport;
+   rport = fc_bsg_to_rport(job);
if (!rport)
break;
 
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index bfcc37d..dae7cc3 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -386,7 +386,7 @@ struct lpfc_dmabufext {
 {
struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
struct lpfc_hba *phba = vport->phba;
-   struct lpfc_rport_data *rdata = job->rport->dd_data;
+   struct lpfc_rport_data *rdata = fc_bsg_to_rport(job)->dd_data;
struct lpfc_nodelist *ndlp = rdata->pnode;
struct fc_bsg_reply *bsg_reply = job->reply;
struct ulp_bde64 *bpl = NULL;
@@ -660,7 +660,7 @@ struct lpfc_dmabufext {
 {
struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
struct lpfc_hba *phba = vport->phba;
-   struct lpfc_rport_data *rdata = job->rport->dd_data;
+   struct lpfc_rport_data *rdata = fc_bsg_to_rport(job)->dd_data;
struct lpfc_nodelist *ndlp = rdata->pnode;
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
index 109b852..917eafe 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.c
+++ b/drivers/scsi/qla2xxx/qla_bsg.c
@@ -264,7 +264,7 @@
uint16_t nextlid = 0;
 
if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
-   rport = bsg_job->rport;
+   rport = fc_bsg_to_rport(bsg_job);
fcport = *(fc_port_t **) rport->dd_data;
host = rport_to_shost(rport);
vha = shost_priv(host);
@@ -2485,7 +2485,7 @@
bsg_reply->reply_payload_rcv_len = 0;
 
if (bsg_request->msgcode == FC_BSG_RPT_ELS) {
-   rport = bsg_job->rport;
+   rport = fc_bsg_to_rport(bsg_job);
host = rport_to_shost(rport);
vha = shost_priv(host);
} else {
diff --git a/drivers/scsi/scs

[PATCH v3 09/16] block: add reference counting for struct bsg_job

2016-10-13 Thread Johannes Thumshirn
Add reference counting to 'struct bsg_job' so we can implement a reuqest
timeout handler for bsg_jobs, which is needed for Fibre Channel.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 block/bsg-lib.c | 7 +--
 include/linux/bsg-lib.h | 2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 650f427..632fb40 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -32,8 +32,10 @@
  * bsg_destroy_job - routine to teardown/delete a bsg job
  * @job: bsg_job that is to be torn down
  */
-static void bsg_destroy_job(struct bsg_job *job)
+static void bsg_destroy_job(struct kref *kref)
 {
+   struct bsg_job *job = container_of(kref, struct bsg_job, kref);
+
put_device(job->dev);   /* release reference for the request */
 
kfree(job->request_payload.sg_list);
@@ -84,7 +86,7 @@ static void bsg_softirq_done(struct request *rq)
struct bsg_job *job = rq->special;
 
blk_end_request_all(rq, rq->errors);
-   bsg_destroy_job(job);
+   kref_put(&job->kref, bsg_destroy_job);
 }
 
 static int bsg_map_buffer(struct bsg_buffer *buf, struct request *req)
@@ -142,6 +144,7 @@ static int bsg_create_job(struct device *dev, struct 
request *req)
job->dev = dev;
/* take a reference for the request */
get_device(job->dev);
+   kref_init(&job->kref);
return 0;
 
 failjob_rls_rqst_payload:
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index a226652..58e0717 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -40,6 +40,8 @@ struct bsg_job {
struct device *dev;
struct request *req;
 
+   struct kref kref;
+
/* Transport/driver specific request/reply structs */
void *request;
void *reply;
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 05/16] scsi: fc: provide fc_bsg_to_shost() helper

2016-10-13 Thread Johannes Thumshirn
Provide fc_bsg_to_shost() helper that will become handy when we're moving from
struct fc_bsg_job to a plain struct bsg_job. Also use this little helper in
the LLDDs.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 drivers/s390/scsi/zfcp_fc.c  |  4 +--
 drivers/scsi/bfa/bfad_bsg.c  |  6 ++---
 drivers/scsi/ibmvscsi/ibmvfc.c   |  4 +--
 drivers/scsi/libfc/fc_lport.c|  2 +-
 drivers/scsi/lpfc/lpfc_bsg.c | 32 
 drivers/scsi/qla2xxx/qla_bsg.c   | 54 
 drivers/scsi/scsi_transport_fc.c |  2 +-
 include/scsi/scsi_transport_fc.h |  5 
 8 files changed, 56 insertions(+), 53 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 87f6330..813c286 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -905,7 +905,7 @@ static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct 
fc_bsg_job *job)
preamble_word1 = bsg_request->rqst_data.r_ct.preamble_word1;
gs_type = (preamble_word1 & 0xff00) >> 24;
 
-   adapter = (struct zfcp_adapter *) job->shost->hostdata[0];
+   adapter = shost_priv(fc_bsg_to_shost(job));
 
switch (gs_type) {
case FC_FST_ALIAS:
@@ -987,7 +987,7 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
struct zfcp_fsf_ct_els *ct_els = job->dd_data;
struct fc_bsg_request *bsg_request = job->request;
 
-   shost = job->rport ? rport_to_shost(job->rport) : job->shost;
+   shost = job->rport ? rport_to_shost(job->rport) : fc_bsg_to_shost(job);
adapter = (struct zfcp_adapter *)shost->hostdata[0];
 
if (!(atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN))
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index e49a6c8..d3094270 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3135,8 +3135,7 @@
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
uint32_t vendor_cmd = bsg_request->rqst_data.h_vendor.vendor_cmd[0];
-   struct bfad_im_port_s *im_port =
-   (struct bfad_im_port_s *) job->shost->hostdata[0];
+   struct bfad_im_port_s *im_port = shost_priv(fc_bsg_to_shost(job));
struct bfad_s *bfad = im_port->bfad;
struct request_queue *request_q = job->req->q;
void *payload_kbuf;
@@ -3358,8 +3357,7 @@ struct bfad_buf_info *
 bfad_im_bsg_els_ct_request(struct fc_bsg_job *job)
 {
struct bfa_bsg_data *bsg_data;
-   struct bfad_im_port_s *im_port =
-   (struct bfad_im_port_s *) job->shost->hostdata[0];
+   struct bfad_im_port_s *im_port = shost_priv(fc_bsg_to_shost(job));
struct bfad_s *bfad = im_port->bfad;
bfa_bsg_fcpt_t *bsg_fcpt;
struct bfad_fcxp*drv_fcxp;
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index 6070361..02df1f1 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1708,7 +1708,7 @@ static void ibmvfc_bsg_timeout_done(struct ibmvfc_event 
*evt)
  **/
 static int ibmvfc_bsg_timeout(struct fc_bsg_job *job)
 {
-   struct ibmvfc_host *vhost = shost_priv(job->shost);
+   struct ibmvfc_host *vhost = shost_priv(fc_bsg_to_shost(job));
unsigned long port_id = (unsigned long)job->dd_data;
struct ibmvfc_event *evt;
struct ibmvfc_tmf *tmf;
@@ -1821,7 +1821,7 @@ static int ibmvfc_bsg_plogi(struct ibmvfc_host *vhost, 
unsigned int port_id)
  **/
 static int ibmvfc_bsg_request(struct fc_bsg_job *job)
 {
-   struct ibmvfc_host *vhost = shost_priv(job->shost);
+   struct ibmvfc_host *vhost = shost_priv(fc_bsg_to_shost(job));
struct fc_rport *rport = job->rport;
struct ibmvfc_passthru_mad *mad;
struct ibmvfc_event *evt;
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 000188f..a3fb355 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -2092,7 +2092,7 @@ int fc_lport_bsg_request(struct fc_bsg_job *job)
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
struct request *rsp = job->req->next_rq;
-   struct Scsi_Host *shost = job->shost;
+   struct Scsi_Host *shost = fc_bsg_to_shost(job);
struct fc_lport *lport = shost_priv(shost);
struct fc_rport *rport;
struct fc_rport_priv *rdata;
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index 447a7af..bfcc37d 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -384,7 +384,7 @@ struct lpfc_dmabufext {
 static int
 lpfc_bsg_send_mgmt_cmd(struct fc_bsg_job *job)
 {
-   struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
+   struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
struct lpfc_hba *phba = vport->phba;
struct l

[PATCH v3 13/16] scsi: fc: use bsg_job_done

2016-10-13 Thread Johannes Thumshirn
fc_bsg_jobdone() and bsg_job_done() are 1:1 copies now so use the bsg-lib one
instead of the FC private implementation.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 drivers/s390/scsi/zfcp_fc.c  |  2 +-
 drivers/scsi/bfa/bfad_bsg.c  |  4 ++--
 drivers/scsi/ibmvscsi/ibmvfc.c   |  2 +-
 drivers/scsi/libfc/fc_lport.c|  4 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 38 +-
 drivers/scsi/qla2xxx/qla_bsg.c   | 44 
 drivers/scsi/scsi_transport_fc.c | 41 +++--
 include/scsi/scsi_transport_fc.h |  2 --
 8 files changed, 50 insertions(+), 87 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index b1b4129..a0f9c82 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -893,7 +893,7 @@ static void zfcp_fc_ct_els_job_handler(void *data)
jr->reply_payload_rcv_len = job->reply_payload.payload_len;
jr->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
jr->result = zfcp_ct_els->status ? -EIO : 0;
-   fc_bsg_jobdone(job, jr->result, jr->reply_payload_rcv_len);
+   bsg_job_done(job, jr->result, jr->reply_payload_rcv_len);
 }
 
 static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct bsg_job *job)
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index cdc25e6..a9a0016 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3179,7 +3179,7 @@
bsg_reply->reply_payload_rcv_len = job->reply_payload.payload_len;
bsg_reply->result = rc;
 
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
return rc;
 error:
@@ -3555,7 +3555,7 @@ struct bfad_buf_info *
bsg_reply->result = rc;
 
if (rc == BFA_STATUS_OK)
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
 
return rc;
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index f59b0a1..78b72c2 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1946,7 +1946,7 @@ static int ibmvfc_bsg_request(struct bsg_job *job)
ibmvfc_free_event(evt);
spin_unlock_irqrestore(vhost->host->host_lock, flags);
bsg_reply->result = rc;
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
rc = 0;
 out:
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 9845667..518e3b0 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -1916,7 +1916,7 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
bsg_reply->result = (PTR_ERR(fp) == -FC_EX_CLOSED) ?
-ECONNABORTED : -ETIMEDOUT;
job->reply_len = sizeof(uint32_t);
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
kfree(info);
return;
@@ -1951,7 +1951,7 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
bsg_reply->reply_payload_rcv_len =
job->reply_payload.payload_len;
bsg_reply->result = 0;
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
kfree(info);
}
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index ca21f25..a862437 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -371,7 +371,7 @@ struct lpfc_dmabufext {
 
if (job) {
bsg_reply->result = rc;
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
}
return;
@@ -645,7 +645,7 @@ struct lpfc_dmabufext {
 
if (job) {
bsg_reply->result = rc;
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
}
return;
@@ -1138,7 +1138,7 @@ struct lpfc_dmabufext {
job->dd_data = NULL;
/* complete the job back to userspace */
spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_paylo

[PATCH v3 08/16] scsi: fc: implement kref backed reference counting

2016-10-13 Thread Johannes Thumshirn
Implement kref backed reference counting instead of rolling our own. This
elimnates the need of the following fields in 'struct fc_bsg_job':
* ref_cnt
* state_flags
* job_lock
bringing us close to unification of 'struct fc_bsg_job' and 'struct bsg_job'.

Signed-off-by: Johannes Thumshirn 
---
 drivers/scsi/scsi_transport_fc.c | 40 +++-
 include/scsi/scsi_transport_fc.h |  4 +---
 2 files changed, 12 insertions(+), 32 deletions(-)

diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 96b3a2e..610a985 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3560,16 +3560,12 @@ struct fc_vport *
  * @job:   fc_bsg_job that is to be torn down
  */
 static void
-fc_destroy_bsgjob(struct fc_bsg_job *job)
+fc_destroy_bsgjob(struct kref *kref)
 {
-   unsigned long flags;
+   struct fc_bsg_job *job = container_of(kref, struct fc_bsg_job, kref);
+   struct request *rq = job->req;
 
-   spin_lock_irqsave(&job->job_lock, flags);
-   if (job->ref_cnt) {
-   spin_unlock_irqrestore(&job->job_lock, flags);
-   return;
-   }
-   spin_unlock_irqrestore(&job->job_lock, flags);
+   blk_end_request_all(rq, rq->errors);
 
put_device(job->dev);   /* release reference for the request */
 
@@ -3620,15 +3616,8 @@ void fc_bsg_jobdone(struct fc_bsg_job *job, int result,
 static void fc_bsg_softirq_done(struct request *rq)
 {
struct fc_bsg_job *job = rq->special;
-   unsigned long flags;
 
-   spin_lock_irqsave(&job->job_lock, flags);
-   job->state_flags |= FC_RQST_STATE_DONE;
-   job->ref_cnt--;
-   spin_unlock_irqrestore(&job->job_lock, flags);
-
-   blk_end_request_all(rq, rq->errors);
-   fc_destroy_bsgjob(job);
+   kref_put(&job->kref, fc_destroy_bsgjob);
 }
 
 /**
@@ -3642,24 +3631,18 @@ static void fc_bsg_softirq_done(struct request *rq)
struct Scsi_Host *shost = fc_bsg_to_shost(job);
struct fc_rport *rport = fc_bsg_to_rport(job);
struct fc_internal *i = to_fc_internal(shost->transportt);
-   unsigned long flags;
-   int err = 0, done = 0;
+   int err = 0, inflight = 0;
 
if (rport && rport->port_state == FC_PORTSTATE_BLOCKED)
return BLK_EH_RESET_TIMER;
 
-   spin_lock_irqsave(&job->job_lock, flags);
-   if (job->state_flags & FC_RQST_STATE_DONE)
-   done = 1;
-   else
-   job->ref_cnt++;
-   spin_unlock_irqrestore(&job->job_lock, flags);
+   inflight = kref_get_unless_zero(&job->kref);
 
-   if (!done && i->f->bsg_timeout) {
+   if (inflight && i->f->bsg_timeout) {
/* call LLDD to abort the i/o as it has timed out */
err = i->f->bsg_timeout(job);
if (err == -EAGAIN) {
-   job->ref_cnt--;
+   kref_put(&job->kref, fc_destroy_bsgjob);
return BLK_EH_RESET_TIMER;
} else if (err)
printk(KERN_ERR "ERROR: FC BSG request timeout - LLD "
@@ -3667,7 +3650,7 @@ static void fc_bsg_softirq_done(struct request *rq)
}
 
/* the blk_end_sync_io() doesn't check the error */
-   if (done)
+   if (!inflight)
return BLK_EH_NOT_HANDLED;
else
return BLK_EH_HANDLED;
@@ -3730,7 +3713,6 @@ static void fc_bsg_softirq_done(struct request *rq)
job->req = req;
if (i->f->dd_bsg_size)
job->dd_data = (void *)&job[1];
-   spin_lock_init(&job->job_lock);
bsg_request = (struct fc_bsg_request *)req->cmd;
job->request_len = req->cmd_len;
bsg_reply = req->sense;
@@ -3752,7 +3734,7 @@ static void fc_bsg_softirq_done(struct request *rq)
job->dev = &shost->shost_gendev;
get_device(job->dev);   /* take a reference for the request */
 
-   job->ref_cnt = 1;
+   kref_init(&job->kref);
 
return 0;
 
diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
index 9f53fe3..8ae5680 100644
--- a/include/scsi/scsi_transport_fc.h
+++ b/include/scsi/scsi_transport_fc.h
@@ -634,9 +634,7 @@ struct fc_bsg_job {
struct fc_rport *rport;
struct device *dev;
struct request *req;
-   spinlock_t job_lock;
-   unsigned int state_flags;
-   unsigned int ref_cnt;
+   struct kref kref;
 
struct fc_bsg_request *request;
struct fc_bsg_reply *reply;
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 10/16] scsi: change FC drivers to use 'struct bsg_job'

2016-10-13 Thread Johannes Thumshirn
Change FC drivers to use 'struct bsg_job' from bsg-lib.h instead of 'struct
fc_bsg_job' from scsi_transport_fc.h and remove 'struct fc_bsg_job'.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 drivers/s390/scsi/zfcp_ext.h |  4 +--
 drivers/s390/scsi/zfcp_fc.c  | 15 
 drivers/scsi/bfa/bfad_bsg.c  | 10 +++---
 drivers/scsi/bfa/bfad_im.h   |  4 +--
 drivers/scsi/ibmvscsi/ibmvfc.c   |  9 ++---
 drivers/scsi/libfc/fc_lport.c| 10 +++---
 drivers/scsi/lpfc/lpfc_bsg.c | 74 
 drivers/scsi/lpfc/lpfc_crtn.h|  4 +--
 drivers/scsi/qla2xxx/qla_bsg.c   | 61 +
 drivers/scsi/qla2xxx/qla_def.h   |  2 +-
 drivers/scsi/qla2xxx/qla_gbl.h   |  4 +--
 drivers/scsi/qla2xxx/qla_iocb.c  |  8 ++---
 drivers/scsi/qla2xxx/qla_isr.c   |  6 ++--
 drivers/scsi/qla2xxx/qla_mr.c|  5 +--
 drivers/scsi/scsi_transport_fc.c | 20 +--
 include/scsi/libfc.h |  2 +-
 include/scsi/scsi_transport_fc.h | 63 ++
 17 files changed, 138 insertions(+), 163 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_ext.h b/drivers/s390/scsi/zfcp_ext.h
index c8fed9f..968a0ab 100644
--- a/drivers/s390/scsi/zfcp_ext.h
+++ b/drivers/s390/scsi/zfcp_ext.h
@@ -84,8 +84,8 @@ extern void zfcp_fc_enqueue_event(struct zfcp_adapter *,
 extern void zfcp_fc_wka_ports_force_offline(struct zfcp_fc_wka_ports *);
 extern int zfcp_fc_gs_setup(struct zfcp_adapter *);
 extern void zfcp_fc_gs_destroy(struct zfcp_adapter *);
-extern int zfcp_fc_exec_bsg_job(struct fc_bsg_job *);
-extern int zfcp_fc_timeout_bsg_job(struct fc_bsg_job *);
+extern int zfcp_fc_exec_bsg_job(struct bsg_job *);
+extern int zfcp_fc_timeout_bsg_job(struct bsg_job *);
 extern void zfcp_fc_sym_name_update(struct work_struct *);
 extern unsigned int zfcp_fc_port_scan_backoff(void);
 extern void zfcp_fc_conditional_port_scan(struct zfcp_adapter *);
diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 1977a66..b1b4129 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "zfcp_ext.h"
@@ -885,7 +886,7 @@ void zfcp_fc_sym_name_update(struct work_struct *work)
 
 static void zfcp_fc_ct_els_job_handler(void *data)
 {
-   struct fc_bsg_job *job = data;
+   struct bsg_job *job = data;
struct zfcp_fsf_ct_els *zfcp_ct_els = job->dd_data;
struct fc_bsg_reply *jr = job->reply;
 
@@ -895,7 +896,7 @@ static void zfcp_fc_ct_els_job_handler(void *data)
fc_bsg_jobdone(job, jr->result, jr->reply_payload_rcv_len);
 }
 
-static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct fc_bsg_job *job)
+static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct bsg_job *job)
 {
u32 preamble_word1;
u8 gs_type;
@@ -925,7 +926,7 @@ static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct 
fc_bsg_job *job)
 
 static void zfcp_fc_ct_job_handler(void *data)
 {
-   struct fc_bsg_job *job = data;
+   struct bsg_job *job = data;
struct zfcp_fc_wka_port *wka_port;
 
wka_port = zfcp_fc_job_wka_port(job);
@@ -934,7 +935,7 @@ static void zfcp_fc_ct_job_handler(void *data)
zfcp_fc_ct_els_job_handler(data);
 }
 
-static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
+static int zfcp_fc_exec_els_job(struct bsg_job *job,
struct zfcp_adapter *adapter)
 {
struct zfcp_fsf_ct_els *els = job->dd_data;
@@ -957,7 +958,7 @@ static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
return zfcp_fsf_send_els(adapter, d_id, els, job->req->timeout / HZ);
 }
 
-static int zfcp_fc_exec_ct_job(struct fc_bsg_job *job,
+static int zfcp_fc_exec_ct_job(struct bsg_job *job,
   struct zfcp_adapter *adapter)
 {
int ret;
@@ -980,7 +981,7 @@ static int zfcp_fc_exec_ct_job(struct fc_bsg_job *job,
return ret;
 }
 
-int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
+int zfcp_fc_exec_bsg_job(struct bsg_job *job)
 {
struct Scsi_Host *shost;
struct zfcp_adapter *adapter;
@@ -1010,7 +1011,7 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
}
 }
 
-int zfcp_fc_timeout_bsg_job(struct fc_bsg_job *job)
+int zfcp_fc_timeout_bsg_job(struct bsg_job *job)
 {
/* hardware tracks timeout, reset bsg timeout to not interfere */
return -EAGAIN;
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index d3094270..cdc25e6 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3130,7 +3130,7 @@
 }
 
 static int
-bfad_im_bsg_vendor_request(struct fc_bsg_job *job)
+bfad_im_bsg_vendor_request(struct bsg_job *job)
 {
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
@@ -3314,7 +3314,7 @@ struct bfad_buf_info *
 }
 
 int
-bfad_fcxp_bsg_send(struct fc_bsg_job *job, struct bfad_f

[PATCH v3 12/16] scsi: fc: use bsg_softirq_done

2016-10-13 Thread Johannes Thumshirn
bsg_softirq_done() and fc_bsg_softirq_done() are copies of each other, so
ditch the fc specific one.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 block/bsg-lib.c  |  3 ++-
 drivers/scsi/scsi_transport_fc.c | 15 ++-
 include/linux/bsg-lib.h  |  1 +
 3 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 9f1e8fd..6661f82 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -85,12 +85,13 @@ void bsg_job_done(struct bsg_job *job, int result,
  * bsg_softirq_done - softirq done routine for destroying the bsg requests
  * @rq: BSG request that holds the job to be destroyed
  */
-static void bsg_softirq_done(struct request *rq)
+void bsg_softirq_done(struct request *rq)
 {
struct bsg_job *job = rq->special;
 
kref_put(&job->kref, bsg_destroy_job);
 }
+EXPORT_SYMBOL_GPL(bsg_softirq_done);
 
 static int bsg_map_buffer(struct bsg_buffer *buf, struct request *req)
 {
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index d2d0a27..1ae6d86 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3591,17 +3591,6 @@ void fc_bsg_jobdone(struct bsg_job *job, int result,
 EXPORT_SYMBOL_GPL(fc_bsg_jobdone);
 
 /**
- * fc_bsg_softirq_done - softirq done routine for destroying the bsg requests
- * @rq:BSG request that holds the job to be destroyed
- */
-static void fc_bsg_softirq_done(struct request *rq)
-{
-   struct bsg_job *job = rq->special;
-
-   kref_put(&job->kref, fc_destroy_bsgjob);
-}
-
-/**
  * fc_bsg_job_timeout - handler for when a bsg request timesout
  * @req:   request that timed out
  */
@@ -4035,7 +4024,7 @@ enum fc_dispatch_result {
 
q->queuedata = shost;
queue_flag_set_unlocked(QUEUE_FLAG_BIDI, q);
-   blk_queue_softirq_done(q, fc_bsg_softirq_done);
+   blk_queue_softirq_done(q, bsg_softirq_done);
blk_queue_rq_timed_out(q, fc_bsg_job_timeout);
blk_queue_rq_timeout(q, FC_DEFAULT_BSG_TIMEOUT);
 
@@ -4081,7 +4070,7 @@ enum fc_dispatch_result {
 
q->queuedata = rport;
queue_flag_set_unlocked(QUEUE_FLAG_BIDI, q);
-   blk_queue_softirq_done(q, fc_bsg_softirq_done);
+   blk_queue_softirq_done(q, bsg_softirq_done);
blk_queue_rq_timed_out(q, fc_bsg_job_timeout);
blk_queue_rq_timeout(q, BLK_DEFAULT_SG_TIMEOUT);
 
diff --git a/include/linux/bsg-lib.h b/include/linux/bsg-lib.h
index 67f7de6..09f3044 100644
--- a/include/linux/bsg-lib.h
+++ b/include/linux/bsg-lib.h
@@ -70,5 +70,6 @@ int bsg_setup_queue(struct device *dev, struct request_queue 
*q, char *name,
bsg_job_fn *job_fn, int dd_job_size);
 void bsg_request_fn(struct request_queue *q);
 void bsg_destroy_job(struct kref *kref);
+void bsg_softirq_done(struct request *rq);
 
 #endif
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 03/16] scsi: fc: Export fc_bsg_jobdone and use it in FC drivers

2016-10-13 Thread Johannes Thumshirn
Export fc_bsg_jobdone so drivers can use it directly instead of doing
the round-trip via struct fc_bsg_job::job_done() and use it in the LLDDs.

As we've converted all LLDDs over to use fc_bsg_jobdone() directly,
we can remove the function pointer from struct fc_bsg_job as well.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 drivers/s390/scsi/zfcp_fc.c  |  2 +-
 drivers/scsi/bfa/bfad_bsg.c  |  4 ++--
 drivers/scsi/ibmvscsi/ibmvfc.c   |  2 +-
 drivers/scsi/libfc/fc_lport.c|  4 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 38 +-
 drivers/scsi/qla2xxx/qla_bsg.c   | 44 
 drivers/scsi/scsi_transport_fc.c |  5 ++---
 include/scsi/scsi_transport_fc.h |  2 +-
 8 files changed, 50 insertions(+), 51 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 4c4023f..40d8f06 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -892,7 +892,7 @@ static void zfcp_fc_ct_els_job_handler(void *data)
jr->reply_payload_rcv_len = job->reply_payload.payload_len;
jr->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
jr->result = zfcp_ct_els->status ? -EIO : 0;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
 }
 
 static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct fc_bsg_job *job)
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index 48366d8..25889b9 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3180,7 +3180,7 @@
bsg_reply->reply_payload_rcv_len = job->reply_payload.payload_len;
bsg_reply->result = rc;
 
-   job->job_done(job);
+   fc_bsg_jobdone(job);
return rc;
 error:
/* free the command buffer */
@@ -3556,7 +3556,7 @@ struct bfad_buf_info *
bsg_reply->result = rc;
 
if (rc == BFA_STATUS_OK)
-   job->job_done(job);
+   fc_bsg_jobdone(job);
 
return rc;
 }
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index 7c17a7e..f14e9c1 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1945,7 +1945,7 @@ static int ibmvfc_bsg_request(struct fc_bsg_job *job)
ibmvfc_free_event(evt);
spin_unlock_irqrestore(vhost->host->host_lock, flags);
bsg_reply->result = rc;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
rc = 0;
 out:
dma_unmap_sg(vhost->dev, job->request_payload.sg_list,
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 23bb114..33e2881 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -1917,7 +1917,7 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
-ECONNABORTED : -ETIMEDOUT;
job->reply_len = sizeof(uint32_t);
job->state_flags |= FC_RQST_STATE_DONE;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
kfree(info);
return;
}
@@ -1952,7 +1952,7 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
job->reply_payload.payload_len;
bsg_reply->result = 0;
job->state_flags |= FC_RQST_STATE_DONE;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
kfree(info);
}
fc_frame_free(fp);
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index 27b5930..1db9cca 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -371,7 +371,7 @@ struct lpfc_dmabufext {
 
if (job) {
bsg_reply->result = rc;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
}
return;
 }
@@ -644,7 +644,7 @@ struct lpfc_dmabufext {
 
if (job) {
bsg_reply->result = rc;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
}
return;
 }
@@ -1136,7 +1136,7 @@ struct lpfc_dmabufext {
job->dd_data = NULL;
/* complete the job back to userspace */
spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
-   job->job_done(job);
+   fc_bsg_jobdone(job);
spin_lock_irqsave(&phba->ct_ev_lock, flags);
}
}
@@ -1361,7 +1361,7 @@ struct lpfc_dmabufext {
spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
job->dd_data = NULL;
bsg_reply->result = 0;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
return 0;
 
 job_error:
@@ -1458,7 +1458,7 @@ struct lpfc_dmabufext {
 
if (job) {
bsg_reply->result = rc;
-   job->job_done(job);
+   fc_bsg_jobdone(job);
}
return;
 }
@@ -1886,7 +1886,7 @@ struct lpfc_dmabuf

[PATCH v3 00/16] Convert FibreChannel bsg code to use bsg-lib

2016-10-13 Thread Johannes Thumshirn
This series converts the current bsg usage in the FibreChannel drivers over
to use bsg-lib. SAS will follow once FC is in a good enough shape.

I did take some inspiration from a similar patchset from Mike Christie
dating back to 2011 but it's not a 1:1 copy. Patch 15/16 is heavily based
on his series and attribution is given to him in the commit message.

It is currently regression tested on FCoE using the 'fcns' and
'fcrls' utilities.  I'm still trying to figure out how to test the other
LLDDs. So any pointer from the respective maintainers are appreciated
although the LLDD changes are purely mechanical. All they do is change from
'struct fc_bsg_job' to 'struct bsg_job' and corresponding changes in order
to get the series bisectable.

The idea for this change arose when discussing racy sysfs handling the FC
bsg code with Christoph and is a next step in moving all bsg clients to
bsg-lib to eventually clean up the in kernel bsg API.

Changes to v1:
* Reduce the number of individual patches (44 -> 16)
* Fix s390 build failure (forgotten to kill fc_bsg_job from zfcp_ext.h)
* Fix build failure on configs without CONFIG_BLK_DEV_BSGLIB
* Make bsg_job_get() call kref_get_unless_zero() and use it in 
scsi_transport_fc.c

Changes to v2:
* Add Hannes' Reviewd-by tags
* Address Hannes' comment about kref handling in 8/16
* Move CONFIG_BLK_DEV_BSGLIB dependency to patch 12/16 as per 0day results

Johannes Thumshirn (16):
  scsi: Get rid of struct fc_bsg_buffer
  scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly
  scsi: fc: Export fc_bsg_jobdone and use it in FC drivers
  scsi: Unify interfaces of fc_bsg_jobdone and bsg_job_done
  scsi: fc: provide fc_bsg_to_shost() helper
  scsi: fc: provide fc_bsg_to_rport() helper
  scsi: libfc: don't set FC_RQST_STATE_DONE before calling
fc_bsg_jobdone()
  scsi: fc: implement kref backed reference counting
  block: add reference counting for struct bsg_job
  scsi: change FC drivers to use 'struct bsg_job'
  scsi: fc: Use bsg_destroy_job
  scsi: fc: use bsg_softirq_done
  scsi: fc: use bsg_job_done
  block: add bsg_job_put() and bsg_job_get()
  scsi: fc: move FC transport's bsg code to bsg-lib
  block: unexport bsg_softirq_done() again

 block/bsg-lib.c  |  23 +-
 drivers/s390/scsi/zfcp_ext.h |   4 +-
 drivers/s390/scsi/zfcp_fc.c  |  33 +--
 drivers/scsi/Kconfig |   1 +
 drivers/scsi/bfa/bfad_bsg.c  |  62 +++---
 drivers/scsi/bfa/bfad_im.h   |   4 +-
 drivers/scsi/ibmvscsi/ibmvfc.c   |  40 ++--
 drivers/scsi/libfc/fc_lport.c|  47 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 375 +++-
 drivers/scsi/lpfc/lpfc_crtn.h|   4 +-
 drivers/scsi/qla2xxx/qla_bsg.c   | 449 ++-
 drivers/scsi/qla2xxx/qla_def.h   |   2 +-
 drivers/scsi/qla2xxx/qla_gbl.h   |   4 +-
 drivers/scsi/qla2xxx/qla_iocb.c  |  13 +-
 drivers/scsi/qla2xxx/qla_isr.c   |  52 +++--
 drivers/scsi/qla2xxx/qla_mr.c|  15 +-
 drivers/scsi/scsi_transport_fc.c | 409 ++-
 include/linux/bsg-lib.h  |   4 +
 include/scsi/libfc.h |   2 +-
 include/scsi/scsi_transport_fc.h |  62 ++
 20 files changed, 748 insertions(+), 857 deletions(-)

-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 02/16] scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-10-13 Thread Johannes Thumshirn
Don't use fc_bsg_job::request and fc_bsg_job::reply directly, but use
helper variables bsg_request and bsg_reply. This will be helpfull  when
transitioning to bsg-lib.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 drivers/s390/scsi/zfcp_fc.c  |   9 +-
 drivers/scsi/bfa/bfad_bsg.c  |  40 +++---
 drivers/scsi/ibmvscsi/ibmvfc.c   |  22 ++--
 drivers/scsi/libfc/fc_lport.c|  23 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 194 +---
 drivers/scsi/qla2xxx/qla_bsg.c   | 264 ++-
 drivers/scsi/qla2xxx/qla_iocb.c  |   5 +-
 drivers/scsi/qla2xxx/qla_isr.c   |  46 ---
 drivers/scsi/qla2xxx/qla_mr.c|  10 +-
 drivers/scsi/scsi_transport_fc.c |  37 +++---
 10 files changed, 387 insertions(+), 263 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 237688a..4c4023f 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -900,8 +900,9 @@ static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct 
fc_bsg_job *job)
u32 preamble_word1;
u8 gs_type;
struct zfcp_adapter *adapter;
+   struct fc_bsg_request *bsg_request = job->request;
 
-   preamble_word1 = job->request->rqst_data.r_ct.preamble_word1;
+   preamble_word1 = bsg_request->rqst_data.r_ct.preamble_word1;
gs_type = (preamble_word1 & 0xff00) >> 24;
 
adapter = (struct zfcp_adapter *) job->shost->hostdata[0];
@@ -938,6 +939,7 @@ static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
 {
struct zfcp_fsf_ct_els *els = job->dd_data;
struct fc_rport *rport = job->rport;
+   struct fc_bsg_request *bsg_request = job->request;
struct zfcp_port *port;
u32 d_id;
 
@@ -949,7 +951,7 @@ static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
d_id = port->d_id;
put_device(&port->dev);
} else
-   d_id = ntoh24(job->request->rqst_data.h_els.port_id);
+   d_id = ntoh24(bsg_request->rqst_data.h_els.port_id);
 
els->handler = zfcp_fc_ct_els_job_handler;
return zfcp_fsf_send_els(adapter, d_id, els, job->req->timeout / HZ);
@@ -983,6 +985,7 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
struct Scsi_Host *shost;
struct zfcp_adapter *adapter;
struct zfcp_fsf_ct_els *ct_els = job->dd_data;
+   struct fc_bsg_request *bsg_request = job->request;
 
shost = job->rport ? rport_to_shost(job->rport) : job->shost;
adapter = (struct zfcp_adapter *)shost->hostdata[0];
@@ -994,7 +997,7 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
ct_els->resp = job->reply_payload.sg_list;
ct_els->handler_data = job;
 
-   switch (job->request->msgcode) {
+   switch (bsg_request->msgcode) {
case FC_BSG_RPT_ELS:
case FC_BSG_HST_ELS_NOLOGIN:
return zfcp_fc_exec_els_job(job, adapter);
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index d1ad020..48366d8 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3132,7 +3132,9 @@
 static int
 bfad_im_bsg_vendor_request(struct fc_bsg_job *job)
 {
-   uint32_t vendor_cmd = job->request->rqst_data.h_vendor.vendor_cmd[0];
+   struct fc_bsg_request *bsg_request = job->request;
+   struct fc_bsg_reply *bsg_reply = job->reply;
+   uint32_t vendor_cmd = bsg_request->rqst_data.h_vendor.vendor_cmd[0];
struct bfad_im_port_s *im_port =
(struct bfad_im_port_s *) job->shost->hostdata[0];
struct bfad_s *bfad = im_port->bfad;
@@ -3175,8 +3177,8 @@
 
/* Fill the BSG job reply data */
job->reply_len = job->reply_payload.payload_len;
-   job->reply->reply_payload_rcv_len = job->reply_payload.payload_len;
-   job->reply->result = rc;
+   bsg_reply->reply_payload_rcv_len = job->reply_payload.payload_len;
+   bsg_reply->result = rc;
 
job->job_done(job);
return rc;
@@ -3184,9 +3186,9 @@
/* free the command buffer */
kfree(payload_kbuf);
 out:
-   job->reply->result = rc;
+   bsg_reply->result = rc;
job->reply_len = sizeof(uint32_t);
-   job->reply->reply_payload_rcv_len = 0;
+   bsg_reply->reply_payload_rcv_len = 0;
return rc;
 }
 
@@ -3362,18 +3364,20 @@ struct bfad_buf_info *
struct bfad_fcxp*drv_fcxp;
struct bfa_fcs_lport_s *fcs_port;
struct bfa_fcs_rport_s *fcs_rport;
-   uint32_t command_type = job->request->msgcode;
+   struct fc_bsg_request *bsg_request = bsg_request;
+   struct fc_bsg_reply *bsg_reply = job->reply;
+   uint32_t command_type = bsg_request->msgcode;
unsigned long flags;
struct bfad_buf_info *rsp_buf_info;
void *req_kbuf = NULL, *rsp_kbuf = NULL;
int rc = -EINVAL;
 
job->reply_len  = sizeof(uint32_t); /* Atleast uint32_t reply_len */
-   job->reply->reply_pa

[PATCH v3 04/16] scsi: Unify interfaces of fc_bsg_jobdone and bsg_job_done

2016-10-13 Thread Johannes Thumshirn
Unify the interfaces of fc_bsg_jobdone and bsg_job_done. This will reduce the
diff when moving from 'struct fc_bsg_job' to a plain 'struct bsg_job' later
on.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 drivers/s390/scsi/zfcp_fc.c  |  2 +-
 drivers/scsi/bfa/bfad_bsg.c  |  6 ++--
 drivers/scsi/ibmvscsi/ibmvfc.c   |  3 +-
 drivers/scsi/libfc/fc_lport.c|  6 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 68 +++-
 drivers/scsi/qla2xxx/qla_bsg.c   | 66 +-
 drivers/scsi/scsi_transport_fc.c | 22 +++--
 include/scsi/scsi_transport_fc.h |  3 +-
 8 files changed, 116 insertions(+), 60 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 40d8f06..87f6330 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -892,7 +892,7 @@ static void zfcp_fc_ct_els_job_handler(void *data)
jr->reply_payload_rcv_len = job->reply_payload.payload_len;
jr->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
jr->result = zfcp_ct_els->status ? -EIO : 0;
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, jr->result, jr->reply_payload_rcv_len);
 }
 
 static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct fc_bsg_job *job)
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index 25889b9..e49a6c8 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3180,7 +3180,8 @@
bsg_reply->reply_payload_rcv_len = job->reply_payload.payload_len;
bsg_reply->result = rc;
 
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
return rc;
 error:
/* free the command buffer */
@@ -3556,7 +3557,8 @@ struct bfad_buf_info *
bsg_reply->result = rc;
 
if (rc == BFA_STATUS_OK)
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
 
return rc;
 }
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index f14e9c1..6070361 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1945,7 +1945,8 @@ static int ibmvfc_bsg_request(struct fc_bsg_job *job)
ibmvfc_free_event(evt);
spin_unlock_irqrestore(vhost->host->host_lock, flags);
bsg_reply->result = rc;
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
rc = 0;
 out:
dma_unmap_sg(vhost->dev, job->request_payload.sg_list,
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 33e2881..000188f 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -1917,7 +1917,8 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
-ECONNABORTED : -ETIMEDOUT;
job->reply_len = sizeof(uint32_t);
job->state_flags |= FC_RQST_STATE_DONE;
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
kfree(info);
return;
}
@@ -1952,7 +1953,8 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
job->reply_payload.payload_len;
bsg_reply->result = 0;
job->state_flags |= FC_RQST_STATE_DONE;
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
kfree(info);
}
fc_frame_free(fp);
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index 1db9cca..447a7af 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -371,7 +371,8 @@ struct lpfc_dmabufext {
 
if (job) {
bsg_reply->result = rc;
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
}
return;
 }
@@ -644,7 +645,8 @@ struct lpfc_dmabufext {
 
if (job) {
bsg_reply->result = rc;
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
}
return;
 }
@@ -1136,7 +1138,8 @@ struct lpfc_dmabufext {
job->dd_data = NULL;
/* complete the job back to userspace */
spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
-   fc_bsg_jobdone(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_le

[PATCH v3 01/16] scsi: Get rid of struct fc_bsg_buffer

2016-10-13 Thread Johannes Thumshirn
struct fc_bsg_buffer is just a clone of struct bsg_buffer from bsg-lib,
so use this one instead.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 drivers/scsi/lpfc/lpfc_bsg.c |  3 ++-
 drivers/scsi/scsi_transport_fc.c |  2 +-
 include/scsi/scsi_transport_fc.h | 12 +++-
 3 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index 05dcc2a..1002627 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -211,7 +212,7 @@ struct lpfc_dmabufext {
 
 static unsigned int
 lpfc_bsg_copy_data(struct lpfc_dmabuf *dma_buffers,
-  struct fc_bsg_buffer *bsg_buffers,
+  struct bsg_buffer *bsg_buffers,
   unsigned int bytes_to_transfer, int to_buffers)
 {
 
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 0f3a386..8ff2067 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -3671,7 +3671,7 @@ static void fc_bsg_softirq_done(struct request *rq)
 }
 
 static int
-fc_bsg_map_buffer(struct fc_bsg_buffer *buf, struct request *req)
+fc_bsg_map_buffer(struct bsg_buffer *buf, struct request *req)
 {
size_t sz = (sizeof(struct scatterlist) * req->nr_phys_segments);
 
diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
index bf66ea6..921b097 100644
--- a/include/scsi/scsi_transport_fc.h
+++ b/include/scsi/scsi_transport_fc.h
@@ -28,6 +28,7 @@
 #define SCSI_TRANSPORT_FC_H
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -624,13 +625,6 @@ struct fc_host_attrs {
 #define fc_host_dev_loss_tmo(x) \
(((struct fc_host_attrs *)(x)->shost_data)->dev_loss_tmo)
 
-
-struct fc_bsg_buffer {
-   unsigned int payload_len;
-   int sg_cnt;
-   struct scatterlist *sg_list;
-};
-
 /* Values for fc_bsg_job->state_flags (bitflags) */
 #define FC_RQST_STATE_INPROGRESS   0
 #define FC_RQST_STATE_DONE 1
@@ -659,8 +653,8 @@ struct fc_bsg_job {
 */
 
/* DMA payloads for the request/response */
-   struct fc_bsg_buffer request_payload;
-   struct fc_bsg_buffer reply_payload;
+   struct bsg_buffer request_payload;
+   struct bsg_buffer reply_payload;
 
void *dd_data;  /* Used for driver-specific storage */
 };
-- 
1.8.5.6

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 02/16] scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-10-13 Thread Steffen Maier

I'm puzzled.

$ git bisect start fc_bsg master
Bisecting: 8 revisions left to test after this (roughly 3 steps)
[005d51510eee6102636d5dbb06310531c5d46151] scsi: fc: implement kref 
backed reference counting

$ git bisect bad
Bisecting: 3 revisions left to test after this (roughly 2 steps)
[bef6da201de1bb81bb4d9511f9a155862efc251f] scsi: Unify interfaces of 
fc_bsg_jobdone and bsg_job_done

$ git bisect bad
Bisecting: 1 revision left to test after this (roughly 1 step)
[3087864ce3d7282f59021245d8a5f83ef1caef18] scsi: don't use 
fc_bsg_job::request and fc_bsg_job::reply directly

$ git bisect bad
Bisecting: 0 revisions left to test after this (roughly 0 steps)
[81aea44720d22d2e0c4a2613ae8b1c256ef6b0cb] scsi: Get rid of struct 
fc_bsg_buffer

$ git bisect good
3087864ce3d7282f59021245d8a5f83ef1caef18 is the first bad commit
commit 3087864ce3d7282f59021245d8a5f83ef1caef18
Author: Johannes Thumshirn 
Date:   Wed Oct 12 15:06:28 2016 +0200

scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly

Don't use fc_bsg_job::request and fc_bsg_job::reply directly, but use
helper variables bsg_request and bsg_reply. This will be helpfull  when
transitioning to bsg-lib.

Signed-off-by: Johannes Thumshirn 

:04 04 140c4b6829d5cfaec4079716e0795f63f8bc3bd2 
0d9fe225615679550be91fbd9f84c09ab1e280fc M  drivers


From there (on the reverse bisect path) I get the following Oops,
except for the full patch set having another stack trace as in my 
previous mail (dying in zfcp code).



[   46.942452] Oops: 0004 ilc:2 [#1] [   46.942460] PREEMPT  SMP [   46.942465]
[   46.942470] Modules linked in: nf_log_ipv6 xt_pkttype nf_log_ipv4 
nf_log_common xt_LOG xt_limit ip6t_REJECT nf_reject_ipv6 xt_tcpudp 
nf_conntrack_ipv6 nf_defrag_ipv6 ip6table_raw ipt_REJECT nf_reject_ipv4 
iptable_raw xt_CT iptable_filter ip6table_mangle nf_conntrack_netbios_ns 
nf_conntrack_broadcast nf_conntrack_ipv4 nf_defrag_ipv4 ip_tables xt_conntrack 
nf_conntrack ip6table_filter ip6_tables x_tables qeth_l2 ghash_s390 prng ecb 
aes_s390 des_s390 des_generic sha512_s390 sha256_s390 sha1_s390 sha_common 
dm_mod qeth ccwgroup zfcp qdio autofs4
[   46.942547] CPU: 1 PID: 1714 Comm: zfcp_ping Not tainted 4.8.0fcbsg+ #9
[   46.942550] Hardware name: IBM  2964 N96  702
  (z/VM)
[   46.942556] task: 5c988008 task.stack: 5d2ec000
[   46.942560] Krnl PSW : 0704e0018000 007c91ec[   46.942574]  
(fc_bsg_request_handler+0x404/0x4b0)
[   46.942579]
[   46.942583]R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:2 PM:000:
[   46.942598]  RI:0 EA:3
[   46.942601]
[   46.942601] Krnl GPRS:  ffcb  
8001
[   46.942603]007c8fe8 64398c68 69f967e8 
6a3d8008
[   46.942605]6a5e02c8 698b5490  

[   46.942607]6a9ef5f8 00a36840 007c8fe8 
5d2efa00
[   46.942619] Krnl Code: 007c91de: e55dc08c0003clfhsi  
140(%r12),3[   46.942622]
[   46.942622]007c91e4: a7240004brc 2,7c91ec
 #007c91e8: a7f40001   brc 
15,7c91ea[   46.942629]
[   46.942629]   >007c91ec: 5010b000st  
%r1,0(%r11)
  007c91f0: e54cb004   mvhi
4(%r11),0[   46.942635]
[   46.942635]007c91f6: e54cc08c0004mvhi
140(%r12),4
  007c91fc: b904002c   lgr 
%r2,%r12[   46.942643]
[   46.942643]007c9200: c0e5e2c0brasl   
%r14,7c5780
[   46.942646]
[   46.942647] Call Trace:
[   46.942650] ([<007c8fe8>] fc_bsg_request_handler+0x200/0x4b0)
[   46.942656] ([<006b8e0a>] __blk_run_queue+0x52/0x68)
[   46.942661] ([<006c549a>] blk_execute_rq_nowait+0xf2/0x110)
[   46.942664] ([<006c557a>] blk_execute_rq+0xa2/0x110)
[   46.942668] ([<006de0ee>] bsg_ioctl+0x1f6/0x268)
[   46.942675] ([<0036ca20>] do_vfs_ioctl+0x680/0x6d8)
[   46.942677] ([<0036caf4>] SyS_ioctl+0x7c/0xb0)
[   46.942685] ([<009a541e>] system_call+0xd6/0x270)
[   46.942687] INFO: lockdep is turned off.
[   46.942688] Last Breaking-Event-Address:
[   46.942692]  [<007c91e4>] fc_bsg_request_handler+0x3fc/0x4b0
[   46.942696]  [   46.942698] Kernel panic - not syncing: Fatal exception: 
panic_on_oops




On 10/12/2016 03:06 PM, Johannes Thumshirn wrote:

Don't use fc_bsg_job::request and fc_bsg_job::reply directly, but use
helper variables bsg_request and bsg_reply. This will be helpfull  when
transitioning to bsg-lib.

Signed-off-by: Johannes Thumshirn 
---
 drivers/s390/scsi/zfcp_fc.c  |   9 +-
 drivers/scsi/bfa/bfad_bsg.c  |  40 +++---
 drivers/scsi/ibmvscsi/ibmvfc.c   |  22 ++--
 drivers/scsi/libfc/fc_lport.c|  23

Re: [PATCH v3 02/16] scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-10-13 Thread Steffen Maier

Hm, still behaves for me like I reported for v2:
http://marc.info/?l=linux-scsi&m=147637177902937&w=2

On 10/13/2016 05:00 PM, Johannes Thumshirn wrote:

Don't use fc_bsg_job::request and fc_bsg_job::reply directly, but use
helper variables bsg_request and bsg_reply. This will be helpfull  when
transitioning to bsg-lib.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 drivers/s390/scsi/zfcp_fc.c  |   9 +-
 drivers/scsi/bfa/bfad_bsg.c  |  40 +++---
 drivers/scsi/ibmvscsi/ibmvfc.c   |  22 ++--
 drivers/scsi/libfc/fc_lport.c|  23 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 194 +---
 drivers/scsi/qla2xxx/qla_bsg.c   | 264 ++-
 drivers/scsi/qla2xxx/qla_iocb.c  |   5 +-
 drivers/scsi/qla2xxx/qla_isr.c   |  46 ---
 drivers/scsi/qla2xxx/qla_mr.c|  10 +-
 drivers/scsi/scsi_transport_fc.c |  37 +++---
 10 files changed, 387 insertions(+), 263 deletions(-)



diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 8ff2067..eafc7555 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c



@@ -3973,8 +3981,9 @@ enum fc_dispatch_result {
/* check if we have the msgcode value at least */
if (job->request_len < sizeof(uint32_t)) {
BUG_ON(job->reply_len < sizeof(uint32_t));
-   job->reply->reply_payload_rcv_len = 0;
-   job->reply->result = -ENOMSG;
+   bsg_reply = job->reply;
+   bsg_reply->reply_payload_rcv_len = 0;
+   bsg_reply->result = -ENOMSG;
job->reply_len = sizeof(uint32_t);
fc_bsg_jobdone(job);
spin_lock_irq(q->queue_lock);



--
Mit freundlichen Grüßen / Kind regards
Steffen Maier

Linux on z Systems Development

IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 3/6] ibmvscsis: Synchronize cmds at remove time

2016-10-13 Thread Michael Cyr
This patch adds code to disconnect from the client, which will make sure
any outstanding commands have been completed, before continuing on with
the remove operation.

Signed-off-by: Michael Cyr 
Signed-off-by: Bryant G. Ly 
---
 drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c | 39 
 drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.h |  3 +++
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c 
b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
index 2ce1d73..41af435 100644
--- a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
+++ b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
@@ -469,6 +469,18 @@ static void ibmvscsis_disconnect(struct work_struct *work)
 
case WAIT_ENABLED:
switch (new_state) {
+   case UNCONFIGURING:
+   vscsi->state = new_state;
+   vscsi->flags |= RESPONSE_Q_DOWN;
+   vscsi->flags &= ~(SCHEDULE_DISCONNECT |
+ DISCONNECT_SCHEDULED);
+   dma_rmb();
+   if (vscsi->flags & CFG_SLEEPING) {
+   vscsi->flags &= ~CFG_SLEEPING;
+   complete(&vscsi->unconfig);
+   }
+   break;
+
/* should never happen */
case ERR_DISCONNECT:
case ERR_DISCONNECT_RECONNECT:
@@ -481,6 +493,13 @@ static void ibmvscsis_disconnect(struct work_struct *work)
 
case WAIT_IDLE:
switch (new_state) {
+   case UNCONFIGURING:
+   vscsi->flags |= RESPONSE_Q_DOWN;
+   vscsi->state = new_state;
+   vscsi->flags &= ~(SCHEDULE_DISCONNECT |
+ DISCONNECT_SCHEDULED);
+   ibmvscsis_free_command_q(vscsi);
+   break;
case ERR_DISCONNECT:
case ERR_DISCONNECT_RECONNECT:
vscsi->state = new_state;
@@ -1186,6 +1205,15 @@ static void ibmvscsis_adapter_idle(struct scsi_info 
*vscsi)
free_qs = true;
 
switch (vscsi->state) {
+   case UNCONFIGURING:
+   ibmvscsis_free_command_q(vscsi);
+   dma_rmb();
+   isync();
+   if (vscsi->flags & CFG_SLEEPING) {
+   vscsi->flags &= ~CFG_SLEEPING;
+   complete(&vscsi->unconfig);
+   }
+   break;
case ERR_DISCONNECT_RECONNECT:
ibmvscsis_reset_queue(vscsi);
pr_debug("adapter_idle, disc_rec: flags 0x%x\n", vscsi->flags);
@@ -3338,6 +3366,7 @@ static int ibmvscsis_probe(struct vio_dev *vdev,
 (unsigned long)vscsi);
 
init_completion(&vscsi->wait_idle);
+   init_completion(&vscsi->unconfig);
 
snprintf(wq_name, 24, "ibmvscsis%s", dev_name(&vdev->dev));
vscsi->work_q = create_workqueue(wq_name);
@@ -3393,10 +3422,11 @@ static int ibmvscsis_remove(struct vio_dev *vdev)
 
pr_debug("remove (%s)\n", dev_name(&vscsi->dma_dev->dev));
 
-   /*
-* TBD: Need to handle if there are commands on the waiting_rsp q
-*  Actually, can there still be cmds outstanding to tcm?
-*/
+   spin_lock_bh(&vscsi->intr_lock);
+   ibmvscsis_post_disconnect(vscsi, UNCONFIGURING, 0);
+   vscsi->flags |= CFG_SLEEPING;
+   spin_unlock_bh(&vscsi->intr_lock);
+   wait_for_completion(&vscsi->unconfig);
 
vio_disable_interrupts(vdev);
free_irq(vdev->irq, vscsi);
@@ -3405,7 +3435,6 @@ static int ibmvscsis_remove(struct vio_dev *vdev)
 DMA_BIDIRECTIONAL);
kfree(vscsi->map_buf);
tasklet_kill(&vscsi->work_task);
-   ibmvscsis_unregister_command_q(vscsi);
ibmvscsis_destroy_command_q(vscsi);
ibmvscsis_freetimer(vscsi);
ibmvscsis_free_cmds(vscsi);
diff --git a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.h 
b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.h
index 17e0ef4..98b0ca7 100644
--- a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.h
+++ b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.h
@@ -257,6 +257,8 @@ struct scsi_info {
 #define SCHEDULE_DISCONNECT   0x00400
/* disconnect handler is scheduled */
 #define DISCONNECT_SCHEDULED  0x00800
+   /* remove function is sleeping */
+#define CFG_SLEEPING  0x01000
u32 flags;
/* adapter lock */
spinlock_t intr_lock;
@@ -285,6 +287,7 @@ struct scsi_info {
 
struct workqueue_struct *work_q;
struct completion wait_idle;
+   struct completion unconfig;
struct device dev;
struct vio_dev *dma_dev;
struct srp_target target;
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo inf

[PATCH v2 6/6] ibmvscsis: Issues from Dan Carpenter/Smatch

2016-10-13 Thread Michael Cyr
Signed-off-by: Michael Cyr 
Signed-off-by: Bryant G. Ly 
---
 drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c | 13 +++--
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c 
b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
index fe220a1..c9fa356 100644
--- a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
+++ b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
@@ -1896,14 +1896,7 @@ static long ibmvscsis_mad(struct scsi_info *vscsi, 
struct viosrp_crq *crq)
 
pr_debug("mad: type %d\n", be32_to_cpu(mad->type));
 
-   if (be16_to_cpu(mad->length) < 0) {
-   dev_err(&vscsi->dev, "mad: length is < 0\n");
-   ibmvscsis_post_disconnect(vscsi,
- ERR_DISCONNECT_RECONNECT, 0);
-   rc = SRP_VIOLATION;
-   } else {
-   rc = ibmvscsis_process_mad(vscsi, iue);
-   }
+   rc = ibmvscsis_process_mad(vscsi, iue);
 
pr_debug("mad: status %hd, rc %ld\n", be16_to_cpu(mad->status),
 rc);
@@ -2523,7 +2516,6 @@ static void ibmvscsis_parse_cmd(struct scsi_info *vscsi,
dev_err(&vscsi->dev, "0x%llx: parsing SRP descriptor table 
failed.\n",
srp->tag);
goto fail;
-   return;
}
 
cmd->rsp.sol_not = srp->sol_not;
@@ -3282,7 +3274,8 @@ static int ibmvscsis_probe(struct vio_dev *vdev,
INIT_LIST_HEAD(&vscsi->waiting_rsp);
INIT_LIST_HEAD(&vscsi->active_q);
 
-   snprintf(vscsi->tport.tport_name, 256, "%s", dev_name(&vdev->dev));
+   snprintf(vscsi->tport.tport_name, IBMVSCSIS_NAMELEN, "%s",
+dev_name(&vdev->dev));
 
pr_debug("probe tport_name: %s\n", vscsi->tport.tport_name);
 
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 4/6] ibmvscsis: Clean up properly if target_submit_cmd/tmr fails

2016-10-13 Thread Michael Cyr
Signed-off-by: Michael Cyr 
Signed-off-by: Bryant G. Ly 
---
 drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c 
b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
index 41af435..cd9f5c7 100644
--- a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
+++ b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
@@ -2560,6 +2560,10 @@ static void ibmvscsis_parse_cmd(struct scsi_info *vscsi,
   data_len, attr, dir, 0);
if (rc) {
dev_err(&vscsi->dev, "target_submit_cmd failed, rc %d\n", rc);
+   spin_lock_bh(&vscsi->intr_lock);
+   list_del(&cmd->list);
+   ibmvscsis_free_cmd_resources(vscsi, cmd);
+   spin_unlock_bh(&vscsi->intr_lock);
goto fail;
}
return;
@@ -2639,6 +2643,9 @@ static void ibmvscsis_parse_task(struct scsi_info *vscsi,
if (rc) {
dev_err(&vscsi->dev, "target_submit_tmr failed, rc 
%d\n",
rc);
+   spin_lock_bh(&vscsi->intr_lock);
+   list_del(&cmd->list);
+   spin_unlock_bh(&vscsi->intr_lock);
cmd->se_cmd.se_tmr_req->response =
TMR_FUNCTION_REJECTED;
}
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 5/6] ibmvscsis: Return correct partition name/# to client

2016-10-13 Thread Michael Cyr
Signed-off-by: Michael Cyr 
Signed-off-by: Bryant G. Ly 
---
 drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c 
b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
index cd9f5c7..fe220a1 100644
--- a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
+++ b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
@@ -3297,6 +3297,9 @@ static int ibmvscsis_probe(struct vio_dev *vdev,
strncat(vscsi->eye, vdev->name, MAX_EYE);
 
vscsi->dds.unit_id = vdev->unit_address;
+   strncpy(vscsi->dds.partition_name, partition_name,
+   sizeof(vscsi->dds.partition_name));
+   vscsi->dds.partition_num = partition_number;
 
spin_lock_bh(&ibmvscsis_dev_lock);
list_add_tail(&vscsi->list, &ibmvscsis_dev_list);
@@ -3495,7 +3498,7 @@ static int ibmvscsis_get_system_info(void)
 
num = of_get_property(rootdn, "ibm,partition-no", NULL);
if (num)
-   partition_number = *num;
+   partition_number = of_read_number(num, 1);
 
of_node_put(rootdn);
 
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: hpsa: remove unneeded void pointer cast

2016-10-13 Thread Javier Martinez Canillas
It's not necessary to cast the result of kmalloc, since void pointers are
promoted to any other type. This also fixes following coccinelle warning:

casting value returned by memory allocation function to 
(BIG_IOCTL_Command_struct *) is useless.

Signed-off-by: Javier Martinez Canillas 
---

 drivers/scsi/hpsa.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index d007ec18179a..4e82b692298e 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -6657,8 +6657,7 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, 
void __user *argp)
return -EINVAL;
if (!capable(CAP_SYS_RAWIO))
return -EPERM;
-   ioc = (BIG_IOCTL_Command_struct *)
-   kmalloc(sizeof(*ioc), GFP_KERNEL);
+   ioc = kmalloc(sizeof(*ioc), GFP_KERNEL);
if (!ioc) {
status = -ENOMEM;
goto cleanup1;
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] cciss: remove unneeded void pointer cast

2016-10-13 Thread Javier Martinez Canillas
It's not necessary to cast the result of kmalloc, since void pointers are
promoted to any other type. This also fixes following coccinelle warning:

casting value returned by memory allocation function to (struct 
cciss_scsi_adapter_data_t *) is useless.

Signed-off-by: Javier Martinez Canillas 
---

 drivers/block/cciss_scsi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/block/cciss_scsi.c b/drivers/block/cciss_scsi.c
index 1537302e56e3..06692f164f40 100644
--- a/drivers/block/cciss_scsi.c
+++ b/drivers/block/cciss_scsi.c
@@ -703,8 +703,7 @@ cciss_scsi_setup(ctlr_info_t *h)
struct cciss_scsi_adapter_data_t * shba;
 
ccissscsi[h->ctlr].ndevices = 0;
-   shba = (struct cciss_scsi_adapter_data_t *)
-   kmalloc(sizeof(*shba), GFP_KERNEL); 
+   shba = kmalloc(sizeof(*shba), GFP_KERNEL);
if (shba == NULL)
return;
shba->scsi_host = NULL;
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 02/16] scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-10-13 Thread Johannes Thumshirn
On Thu, Oct 13, 2016 at 05:15:25PM +0200, Steffen Maier wrote:
> I'm puzzled.
> 
> $ git bisect start fc_bsg master
> Bisecting: 8 revisions left to test after this (roughly 3 steps)
> [005d51510eee6102636d5dbb06310531c5d46151] scsi: fc: implement kref backed
> reference counting
> $ git bisect bad
> Bisecting: 3 revisions left to test after this (roughly 2 steps)
> [bef6da201de1bb81bb4d9511f9a155862efc251f] scsi: Unify interfaces of
> fc_bsg_jobdone and bsg_job_done
> $ git bisect bad
> Bisecting: 1 revision left to test after this (roughly 1 step)
> [3087864ce3d7282f59021245d8a5f83ef1caef18] scsi: don't use
> fc_bsg_job::request and fc_bsg_job::reply directly
> $ git bisect bad
> Bisecting: 0 revisions left to test after this (roughly 0 steps)
> [81aea44720d22d2e0c4a2613ae8b1c256ef6b0cb] scsi: Get rid of struct
> fc_bsg_buffer
> > $ git bisect good
> > 3087864ce3d7282f59021245d8a5f83ef1caef18 is the first bad commit
> > commit 3087864ce3d7282f59021245d8a5f83ef1caef18
> > Author: Johannes Thumshirn 
> > Date:   Wed Oct 12 15:06:28 2016 +0200
> > 
> > scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly
> > 
> > Don't use fc_bsg_job::request and fc_bsg_job::reply directly, but use
> > helper variables bsg_request and bsg_reply. This will be helpfull  when
> > transitioning to bsg-lib.
> > 
> > Signed-off-by: Johannes Thumshirn 
> > 
> > :04 04 140c4b6829d5cfaec4079716e0795f63f8bc3bd2 
> > 0d9fe225615679550be91fbd9f84c09ab1e280fc M  drivers
> 
> From there (on the reverse bisect path) I get the following Oops,
> except for the full patch set having another stack trace as in my previous
> mail (dying in zfcp code).
> 

[...]

> 
> > @@ -3937,6 +3944,7 @@ fc_bsg_request_handler(struct request_queue *q, 
> > struct Scsi_Host *shost,
> > struct request *req;
> > struct fc_bsg_job *job;
> > enum fc_dispatch_result ret;
> > +   struct fc_bsg_reply *bsg_reply;
> > 
> > if (!get_device(dev))
> > return;
> > @@ -3973,8 +3981,9 @@ fc_bsg_request_handler(struct request_queue *q, 
> > struct Scsi_Host *shost,
> > /* check if we have the msgcode value at least */
> > if (job->request_len < sizeof(uint32_t)) {
> > BUG_ON(job->reply_len < sizeof(uint32_t));
> > -   job->reply->reply_payload_rcv_len = 0;
> > -   job->reply->result = -ENOMSG;
> > +   bsg_reply = job->reply;
> > +   bsg_reply->reply_payload_rcv_len = 0;
> > +   bsg_reply->result = -ENOMSG;
> > job->reply_len = sizeof(uint32_t);
> > fc_bsg_jobdone(job);
> > spin_lock_irq(q->queue_lock);
> > 

Ahm and what exactly can break here? It's just assigning variables. Now
I'm puzzled too.

I'll have to look into it tomorrow.

Byte,
Johannes

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+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
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 02/16] scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-10-13 Thread Johannes Thumshirn
On Thu, Oct 13, 2016 at 05:55:11PM +0200, Steffen Maier wrote:
> Hm, still behaves for me like I reported for v2:
> http://marc.info/?l=linux-scsi&m=147637177902937&w=2
> 
Well given what you've wrote for v2 it's kinda expected.

Byte,
Johannes

-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+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
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] MAINTAINERS: remove defunct iss storage mailing list

2016-10-13 Thread Javier Martinez Canillas
It appears that the mailing list email address doesn't exist anymore:

: host smtp.hp.com[15.73.96.116] said: 550 5.1.1
: Recipient address rejected: User unknown in
virtual alias table (in reply to RCPT TO command)

Signed-off-by: Javier Martinez Canillas 

---

 MAINTAINERS | 2 --
 1 file changed, 2 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 19d8daab5b0d..56ff868dd7d2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5600,7 +5600,6 @@ F:drivers/watchdog/hpwdt.c
 
 HEWLETT-PACKARD SMART ARRAY RAID DRIVER (hpsa)
 M: Don Brace 
-L: iss_storage...@hp.com
 L: esc.storage...@microsemi.com
 L: linux-scsi@vger.kernel.org
 S: Supported
@@ -5611,7 +5610,6 @@ F:include/uapi/linux/cciss*.h
 
 HEWLETT-PACKARD SMART CISS RAID DRIVER (cciss)
 M: Don Brace 
-L: iss_storage...@hp.com
 L: esc.storage...@microsemi.com
 L: linux-scsi@vger.kernel.org
 S: Supported
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 0/6] Fixes for ibmvscsis driver

2016-10-13 Thread Michael Cyr
Various fixes and cleanups for the ibmvscsis driver.
The first is a sort of prequel to the second, which is the primary
change (and the biggest).  The rest are fairly small fixes.

Michael Cyr (6):
  ibmvscsis: Rearrange functions for future patches
  ibmvscsis: Synchronize cmds at tpg_enable_store time
  ibmvscsis: Synchronize cmds at remove time
  ibmvscsis: Clean up properly if target_submit_cmd/tmr fails
  ibmvscsis: Return correct partition name/# to client
  ibmvscsis: Issues from Dan Carpenter/Smatch

 drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c | 1096 +-
 drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.h |5 +-
 2 files changed, 494 insertions(+), 607 deletions(-)

-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] ufs: changing maintainer

2016-10-13 Thread Joao Pinto

Signed-off-by: Joao Pinto 
---
 MAINTAINERS | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 5ac91d8a..d9855b5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12084,7 +12084,8 @@ F:  Documentation/scsi/ufs.txt
 F: drivers/scsi/ufs/
 
 UNIVERSAL FLASH STORAGE HOST CONTROLLER DRIVER DWC HOOKS
-M: Joao Pinto 
+M: Manjunath M Bettegowda 
+M: Prabu Thangamuthu 
 L: linux-scsi@vger.kernel.org
 S: Supported
 F: drivers/scsi/ufs/*dwc*
-- 
1.8.1.5

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/6] ibmvscsis: Synchronize cmds at tpg_enable_store time

2016-10-13 Thread Michael Cyr
This patch changes the way the IBM vSCSI server driver manages its
Command/Response Queue (CRQ).  We used to register the CRQ with phyp at
probe time.  Now we wait until tpg_enable_store.  Similarly, when
tpg_enable_store is called to "disable" (i.e. the stored value is 0),
we unregister the queue with phyp.

One consquence to this is that we have no need for the PART_UP_WAIT_ENAB
state, since we can't get an Init Message from the client in our CRQ if
we're waiting to be enabled, since we haven't registered the queue yet.

Signed-off-by: Michael Cyr 
Signed-off-by: Bryant G. Ly 
---
 drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c | 224 ++-
 drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.h |   2 -
 2 files changed, 38 insertions(+), 188 deletions(-)

diff --git a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c 
b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
index 01a430c..2ce1d73 100644
--- a/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
+++ b/drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
@@ -61,8 +61,6 @@ static long ibmvscsis_parse_command(struct scsi_info *vscsi,
 
 static void ibmvscsis_adapter_idle(struct scsi_info *vscsi);
 
-static void ibmvscsis_reset_queue(struct scsi_info *vscsi, uint new_state);
-
 static void ibmvscsis_determine_resid(struct se_cmd *se_cmd,
  struct srp_rsp *rsp)
 {
@@ -417,7 +415,6 @@ static void ibmvscsis_disconnect(struct work_struct *work)
   proc_work);
u16 new_state;
bool wait_idle = false;
-   long rc = ADAPT_SUCCESS;
 
spin_lock_bh(&vscsi->intr_lock);
new_state = vscsi->new_state;
@@ -470,30 +467,12 @@ static void ibmvscsis_disconnect(struct work_struct *work)
vscsi->state = new_state;
break;
 
-   /*
-* If this is a transition into an error state.
-* a client is attempting to establish a connection
-* and has violated the RPA protocol.
-* There can be nothing pending on the adapter although
-* there can be requests in the command queue.
-*/
case WAIT_ENABLED:
-   case PART_UP_WAIT_ENAB:
switch (new_state) {
+   /* should never happen */
case ERR_DISCONNECT:
-   vscsi->flags |= RESPONSE_Q_DOWN;
-   vscsi->state = new_state;
-   vscsi->flags &= ~(SCHEDULE_DISCONNECT |
- DISCONNECT_SCHEDULED);
-   ibmvscsis_free_command_q(vscsi);
-   break;
case ERR_DISCONNECT_RECONNECT:
-   ibmvscsis_reset_queue(vscsi, WAIT_ENABLED);
-   break;
-
-   /* should never happen */
case WAIT_IDLE:
-   rc = ERROR;
dev_err(&vscsi->dev, "disconnect: invalid state %d for 
WAIT_IDLE\n",
vscsi->state);
break;
@@ -630,7 +609,6 @@ static void ibmvscsis_post_disconnect(struct scsi_info 
*vscsi, uint new_state,
break;
 
case WAIT_ENABLED:
-   case PART_UP_WAIT_ENAB:
case WAIT_IDLE:
case WAIT_CONNECTION:
case CONNECTED:
@@ -675,7 +653,6 @@ static long ibmvscsis_handle_init_compl_msg(struct 
scsi_info *vscsi)
case SRP_PROCESSING:
case CONNECTED:
case WAIT_ENABLED:
-   case PART_UP_WAIT_ENAB:
default:
rc = ERROR;
dev_err(&vscsi->dev, "init_msg: invalid state %d to get init 
compl msg\n",
@@ -698,10 +675,6 @@ static long ibmvscsis_handle_init_msg(struct scsi_info 
*vscsi)
long rc = ADAPT_SUCCESS;
 
switch (vscsi->state) {
-   case WAIT_ENABLED:
-   vscsi->state = PART_UP_WAIT_ENAB;
-   break;
-
case WAIT_CONNECTION:
rc = ibmvscsis_send_init_message(vscsi, INIT_COMPLETE_MSG);
switch (rc) {
@@ -737,7 +710,7 @@ static long ibmvscsis_handle_init_msg(struct scsi_info 
*vscsi)
case UNCONFIGURING:
break;
 
-   case PART_UP_WAIT_ENAB:
+   case WAIT_ENABLED:
case CONNECTED:
case SRP_PROCESSING:
case WAIT_IDLE:
@@ -800,11 +773,10 @@ static long ibmvscsis_init_msg(struct scsi_info *vscsi, 
struct viosrp_crq *crq)
 /**
  * ibmvscsis_establish_new_q() - Establish new CRQ queue
  * @vscsi: Pointer to our adapter structure
- * @new_state: New state being established after resetting the queue
  *
  * Must be called with interrupt lock held.
  */
-static long ibmvscsis_establish_new_q(struct scsi_info *vscsi, uint new_state)
+static long ibmvscsis_establish_new_q(struct scsi_info *vscsi)
 {
long rc = ADAPT_SUCCESS;
uint format;
@@ -816,19 +788,19 @@ static long ibmvscsis_establish_new_q(struct scsi_info 
*vscsi, uint new_state)
 
   

Re: [PATCH] ufs: changing maintainer

2016-10-13 Thread Subhash Jadavani

On 2016-10-13 10:23, Joao Pinto wrote:

Signed-off-by: Joao Pinto 
---
 MAINTAINERS | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 5ac91d8a..d9855b5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12084,7 +12084,8 @@ F:  Documentation/scsi/ufs.txt
 F: drivers/scsi/ufs/

 UNIVERSAL FLASH STORAGE HOST CONTROLLER DRIVER DWC HOOKS
-M: Joao Pinto 
+M: Manjunath M Bettegowda 
+M: Prabu Thangamuthu 
 L: linux-scsi@vger.kernel.org
 S: Supported
 F: drivers/scsi/ufs/*dwc*


Looking at the commit text, it gives the impression that we are changing 
the maintainer for whole UFS driver.
Can you make it specific? May be the commit text header should be "ufs: 
changing maintainer for DWC"?


--
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/2] scsi: sr: Drop custom handling of unit attention

2016-10-13 Thread Gabriel Krisman Bertazi
These custom handling are no longer necessary, since we always retry UA
in scsi_execute now.

Signed-off-by: Gabriel Krisman Bertazi 
---
 drivers/scsi/scsi_lib.c | 21 ++---
 drivers/scsi/sr_ioctl.c |  6 ++
 2 files changed, 8 insertions(+), 19 deletions(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 9c6623abf120..e9324a224b11 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2317,7 +2317,7 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int 
modepage,
unsigned char cmd[12];
int use_10_for_ms;
int header_length;
-   int result, retry_count = retries;
+   int result;
struct scsi_sense_hdr my_sshdr;
 
memset(data, 0, sizeof(*data));
@@ -2396,11 +2396,6 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int 
modepage,
data->block_descriptor_length = buffer[3];
}
data->header_length = header_length;
-   } else if ((status_byte(result) == CHECK_CONDITION) &&
-  scsi_sense_valid(sshdr) &&
-  sshdr->sense_key == UNIT_ATTENTION && retry_count) {
-   retry_count--;
-   goto retry;
}
 
return result;
@@ -2434,15 +2429,11 @@ scsi_test_unit_ready(struct scsi_device *sdev, int 
timeout, int retries,
else
sshdr = sshdr_external;
 
-   /* try to eat the UNIT_ATTENTION if there are enough retries */
-   do {
-   result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL, 0, sshdr,
- timeout, retries, NULL);
-   if (sdev->removable && scsi_sense_valid(sshdr) &&
-   sshdr->sense_key == UNIT_ATTENTION)
-   sdev->changed = 1;
-   } while (scsi_sense_valid(sshdr) &&
-sshdr->sense_key == UNIT_ATTENTION && --retries);
+   result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL, 0, sshdr,
+ timeout, retries, NULL);
+   if (sdev->removable && scsi_sense_valid(sshdr) &&
+   sshdr->sense_key == UNIT_ATTENTION)
+   sdev->changed = 1;
 
if (!sshdr_external)
kfree(sshdr);
diff --git a/drivers/scsi/sr_ioctl.c b/drivers/scsi/sr_ioctl.c
index 03054c0e7689..93b5544a5966 100644
--- a/drivers/scsi/sr_ioctl.c
+++ b/drivers/scsi/sr_ioctl.c
@@ -179,8 +179,8 @@ static int sr_play_trkind(struct cdrom_device_info *cdi,
 }
 
 /* We do our own retries because we want to know what the specific
-   error code is.  Normally the UNIT_ATTENTION code will automatically
-   clear after one error */
+   error code is.
+*/
 
 int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
 {
@@ -220,8 +220,6 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
if (!cgc->quiet)
sr_printk(KERN_INFO, cd,
  "disc change detected.\n");
-   if (retries++ < 10)
-   goto retry;
err = -ENOMEDIUM;
break;
case NOT_READY: /* This happens if there is no disc in drive */
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/2] scsi: Handle Unit Attention when issuing SCSI command

2016-10-13 Thread Gabriel Krisman Bertazi
Hi James,

Thanks for your review.  Please see the v2 below.

> OK, so really this isn't what you want, because blk_execute_req may
> have used several of your retries, so you now get a maximum possible
> set of retries at UNIT_ATTENTION_RETRIES*retries.  You need to start
> from the returned req->retries, which probably means this loop needs to
> be inside __scsi_execute.

Hmm, I was aware of that, but I saw there were other places that may
have run retries^2 times, like scsi_test_unit_ready and scsi_mode_sense,
if I read the code correctly.  But, I see your point and I fixed it on
v2.  I also updated the second patch to rework these cases.

Another thing that got me confused is where the blk layer updates
req->retries.

What do you think about the v2 below?

Thanks,

-- >8 --

Usually, re-sending the SCSI command is enough to recover from a Unit
Attention (UA).  This adds a generic retry code to the SCSI command path
in case of an UA, before giving up and returning the error condition to
the caller.

I added the UA verification into scsi_execute instead of
scsi_execute_req because there are at least a few callers that invoke
scsi_execute directly and would benefit from the internal UA retry.
Also, I didn't use scsi_normalize_sense to not duplicate functionality
with scsi_execute_req_flags.  Instead, scsi_execute uses a small helper
function that verifies only the UA condition directly from the raw sense
buffer.  If this design is not OK, I can refactor to use
scsi_normalize_sense.

This prevents us from duplicating the retry code in at least a few
places.  In particular, it fixes an issue found in some IBM enclosures,
in which the device may return an Unit Attention during probe, breaking
the bind with the ses module:

scsi 1:0:7:0: Failed to get diagnostic page 0x802
scsi 1:0:7:0: Failed to bind enclosure -19

Link: https://patchwork.kernel.org/patch/9336763/
Suggested-by: Brian King 
Suggested-by: James Bottomley 
Signed-off-by: Gabriel Krisman Bertazi 
---
 drivers/scsi/scsi_lib.c| 27 ---
 include/scsi/scsi_common.h |  9 +
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index c71344aebdbb..9c6623abf120 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -187,15 +187,24 @@ int scsi_execute(struct scsi_device *sdev, const unsigned 
char *cmd,
struct request *req;
int write = (data_direction == DMA_TO_DEVICE);
int ret = DRIVER_ERROR << 24;
+   bool priv_sense = false;
 
+   if (!sense) {
+   sense = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_NOIO);
+   if (!sense)
+   return ret;
+   priv_sense = true;
+   }
+
+ retry:
req = blk_get_request(sdev->request_queue, write, __GFP_RECLAIM);
if (IS_ERR(req))
-   return ret;
+   goto free_sense;
blk_rq_set_block_pc(req);
 
if (bufflen &&  blk_rq_map_kern(sdev->request_queue, req,
buffer, bufflen, __GFP_RECLAIM))
-   goto out;
+   goto put_req;
 
req->cmd_len = COMMAND_SIZE(cmd[0]);
memcpy(req->cmd, cmd, req->cmd_len);
@@ -210,6 +219,13 @@ int scsi_execute(struct scsi_device *sdev, const unsigned 
char *cmd,
 */
blk_execute_rq(req->q, NULL, req, 1);
 
+   if (scsi_sense_unit_attention(sense) && req->retries > 0) {
+   memset(sense, 0, SCSI_SENSE_BUFFERSIZE);
+   retries = req->retries - 1;
+   blk_put_request(req);
+   goto retry;
+   }
+
/*
 * Some devices (USB mass-storage in particular) may transfer
 * garbage data together with a residue indicating that the data
@@ -222,9 +238,14 @@ int scsi_execute(struct scsi_device *sdev, const unsigned 
char *cmd,
if (resid)
*resid = req->resid_len;
ret = req->errors;
- out:
+
+ put_req:
blk_put_request(req);
 
+ free_sense:
+   if (priv_sense)
+   kfree(sense);
+
return ret;
 }
 EXPORT_SYMBOL(scsi_execute);
diff --git a/include/scsi/scsi_common.h b/include/scsi/scsi_common.h
index 20bf7eaef05a..747b632d5b57 100644
--- a/include/scsi/scsi_common.h
+++ b/include/scsi/scsi_common.h
@@ -58,6 +58,15 @@ static inline bool scsi_sense_valid(const struct 
scsi_sense_hdr *sshdr)
return (sshdr->response_code & 0x70) == 0x70;
 }
 
+static inline bool scsi_sense_unit_attention(const char *sense)
+{
+   int resp = sense[0] & 0x7f;
+
+   return ((resp & 0x70) &&
+   ((resp >= 0x72 && (sense[1] & 0xf) == UNIT_ATTENTION) ||
+(resp < 0x72 && (sense[2] & 0xf) == UNIT_ATTENTION)));
+}
+
 extern bool scsi_normalize_sense(const u8 *sense_buffer, int sb_len,
 struct scsi_sense_hdr *sshdr);
 
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" 

[PATCH 1/1] [4.9-rc] ipr: Fix async error WARN_ON

2016-10-13 Thread Brian King

Commit afc3f83cb4a5 ("scsi: ipr: Add asynchronous error notification")
introduced the warn on shown below. To fix this, rather than attempting
to send the KOBJ_CHANGE uevent from interrupt context, which is what is
causing the WARN_ON, just wake the ipr worker thread which will send a
KOBJ_CHANGE uevent.

[  142.278120] WARNING: CPU: 15 PID: 0 at kernel/softirq.c:161 
__local_bh_enable_ip+0x7c/0xd0
[  142.278124] Modules linked in: ip6t_rpfilter ip6t_REJECT nf_reject_ipv6 
ipt_REJECT nf_reject_ipv4 xt_conntrack ebtable_nat ebtable_broute bridge stp 
llc ebtable_filter ebtables ip6table_nat nf_conntrack_ipv6 nf_defrag_ipv6 
nf_nat_ipv6 ip6table_mangle ip6table_security ip6table_raw ip6table_filter 
ip6_tables iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat 
nf_conntrack iptable_mangle iptable_security iptable_raw iptable_filter ses 
enclosure scsi_transport_sas sg pseries_rng nfsd auth_rpcgss nfs_acl lockd 
grace sunrpc ip_tables xfs libcrc32c sr_mod sd_mod cdrom ipr libata ibmvscsi 
scsi_transport_srp ibmveth dm_mirror dm_region_hash dm_log dm_mod
[  142.278208] CPU: 15 PID: 0 Comm: swapper/15 Not tainted 4.8.0.ipr+ #21
[  142.278213] task: c0010cf24480 task.stack: c0010cfec000
[  142.278217] NIP: c00c0c7c LR: c0881778 CTR: c03c5bf0
[  142.278221] REGS: c0010cfef080 TRAP: 0700   Not tainted  (4.8.0.ipr+)
[  142.278224] MSR: 80029033   CR: 28008022  XER: 
200f
[  142.278236] CFAR: c00c0c20 SOFTE: 0 
GPR00: c0706c78 c0010cfef300 c0f91d00 c0706c78 
GPR04: 0200 c0f7bc80  024000c0 
GPR08:  0001 c0ee1d00 c0a9bdd0 
GPR12: c03c5bf0 ceb22d00 c00100ca3880 c0020ed38400 
GPR16:   c00100940508  
GPR20:    024000c0 
GPR24: c04588e0 c0010863bd00 c0010863bd00 c13773f8 
GPR28: c0f7bc80   c0f7bcd8 
[  142.278290] NIP [c00c0c7c] __local_bh_enable_ip+0x7c/0xd0
[  142.278296] LR [c0881778] _raw_spin_unlock_bh+0x38/0x60
[  142.278299] Call Trace:
[  142.278303] [c0010cfef300] [c0f7bc80] init_net+0x0/0x1900 
(unreliable)
[  142.278310] [c0010cfef320] [c0706c78] peernet2id+0x58/0x80
[  142.278316] [c0010cfef370] [c075caec] 
netlink_broadcast_filtered+0x30c/0x550
[  142.278323] [c0010cfef430] [c0459078] 
kobject_uevent_env+0x588/0x780
[  142.278331] [c0010cfef510] [d3163a6c] 
ipr_process_error+0x11c/0x240 [ipr]
[  142.278337] [c0010cfef5c0] [d3152298] 
ipr_fail_all_ops+0x108/0x220 [ipr]
[  142.278343] [c0010cfef670] [d31643f8] 
ipr_reset_restore_cfg_space+0xa8/0x240 [ipr]
[  142.278350] [c0010cfef6f0] [d3158a00] 
ipr_reset_ioa_job+0x80/0xe0 [ipr]
[  142.278356] [c0010cfef720] [d3153f78] 
ipr_reset_timer_done+0xa8/0xe0 [ipr]
[  142.278363] [c0010cfef770] [c0149c88] call_timer_fn+0x58/0x1c0
[  142.278368] [c0010cfef800] [c0149f60] expire_timers+0x140/0x200
[  142.278373] [c0010cfef870] [c014a0e8] 
run_timer_softirq+0xc8/0x230
[  142.278379] [c0010cfef900] [c00c0844] __do_softirq+0x164/0x3c0
[  142.278384] [c0010cfef9f0] [c00c0f18] irq_exit+0x1a8/0x1c0
[  142.278389] [c0010cfefa20] [c0020b54] timer_interrupt+0xa4/0xe0
[  142.278394] [c0010cfefa50] [c0002414] 
decrementer_common+0x114/0x180


Signed-off-by: Brian King 
---

 drivers/scsi/ipr.c |3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff -puN drivers/scsi/ipr.c~ipr_async_err_fixup drivers/scsi/ipr.c
--- linux-2.6.git/drivers/scsi/ipr.c~ipr_async_err_fixup2016-10-13 
09:57:47.634920565 -0500
+++ linux-2.6.git-bjking1/drivers/scsi/ipr.c2016-10-13 14:42:25.654418345 
-0500
@@ -2586,7 +2586,6 @@ static void ipr_process_error(struct ipr
struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
u32 fd_ioasc;
-   char *envp[] = { "ASYNC_ERR_LOG=1", NULL };
 
if (ioa_cfg->sis64)
fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
@@ -2607,8 +2606,8 @@ static void ipr_process_error(struct ipr
}
 
list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_report_q);
+   schedule_work(&ioa_cfg->work_q);
hostrcb = ipr_get_free_hostrcb(ioa_cfg);
-   kobject_uevent_env(&ioa_cfg->host->shost_dev.kobj, KOBJ_CHANGE, envp);
 
ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
 }
_

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 0/4] Enabling ATA Command Priorities

2016-10-13 Thread Adam Manzanares
This patch builds ATA commands with high priority if the iocontext
of a process is set to real time. The goal of the patch is to
improve tail latencies of workloads that use higher queue depths.
This required setting the iocontext ioprio on the request when 
the request is initialized.

This patch has been tested with an Ultrastar HE8 HDD and cuts the 
the p99.99 tail latency of foreground IO from 2s down to 72ms when
using the deadline scheduler. This patch works independently of the
scheduler so it can be used with all of the currently available 
request based schedulers. 

Foreground IO, for the previously described results, is an async fio job 
submitting 4K read requests at a QD of 1 to the HDD. The foreground IO is set 
with the iopriority class of real time. The background workload is another fio
job submitting read requests at a QD of 32 to the same HDD with default 
iopriority.

This feature is enabled for ATA devices by setting the ata enable_prio device 
attribute to 1. An ATA device is also checked to see if the device supports per
command priority.

v4:
 - Added blk_rq_set_prio function to associate request prio with ioc prio
 - In init_request_from_bio use bio_prio if it is valid
 - Added ata enable_prio dev attribute to sysfs to enable prioritized commands

v3:
 - Removed null dereference issue in blk-core
 - Renamed queue sysfs entries for clarity
 - Added documentation for sysfs queue entry

v2:
 - Add queue flag to set iopriority going to the request
 - If queue flag set, send iopriority class to ata_build_rw_tf
 - Remove redundant code in ata_ncq_prio_enabled function.


Adam Manzanares (4):
  block: Add iocontext priority to request
  fusion: remove iopriority handling
  ata: Enabling ATA Command Priorities
  ata: ATA Command Priority Disabled By Default

 block/blk-core.c  |  4 ++-
 drivers/ata/libahci.c |  1 +
 drivers/ata/libata-core.c | 35 +-
 drivers/ata/libata-scsi.c | 74 ++-
 drivers/ata/libata.h  |  2 +-
 drivers/message/fusion/mptscsih.c |  5 ---
 include/linux/ata.h   |  6 
 include/linux/blkdev.h| 14 
 include/linux/libata.h| 26 ++
 9 files changed, 158 insertions(+), 9 deletions(-)

-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 2/4] fusion: remove iopriority handling

2016-10-13 Thread Adam Manzanares
The request priority is now by default coming from the ioc. It was not
clear what this code was trying to do based upon the iopriority class or
data. The driver should check that a device supports priorities and use
them according to the specificiations of ioprio.

Signed-off-by: Adam Manzanares 
---
 drivers/message/fusion/mptscsih.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/drivers/message/fusion/mptscsih.c 
b/drivers/message/fusion/mptscsih.c
index 6c9fc11..4740bb6 100644
--- a/drivers/message/fusion/mptscsih.c
+++ b/drivers/message/fusion/mptscsih.c
@@ -1369,11 +1369,6 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt)
if ((vdevice->vtarget->tflags & MPT_TARGET_FLAGS_Q_YES)
&& (SCpnt->device->tagged_supported)) {
scsictl = scsidir | MPI_SCSIIO_CONTROL_SIMPLEQ;
-   if (SCpnt->request && SCpnt->request->ioprio) {
-   if (((SCpnt->request->ioprio & 0x7) == 1) ||
-   !(SCpnt->request->ioprio & 0x7))
-   scsictl |= MPI_SCSIIO_CONTROL_HEADOFQ;
-   }
} else
scsictl = scsidir | MPI_SCSIIO_CONTROL_UNTAGGED;
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 1/4] block: Add iocontext priority to request

2016-10-13 Thread Adam Manzanares
Patch adds an association between iocontext ioprio and the ioprio of a
request. This value is set in blk_rq_set_prio which takes the request and
the ioc as arguments. If the ioc is valid in blk_rq_set_prio then the
iopriority of the request is set as the iopriority of the ioc. In
init_request_from_bio a check is made to see if the ioprio of the bio is
valid and if so then the request prio comes from the bio.

Signed-off-by: Adam Manzananares 
---
 block/blk-core.c   |  4 +++-
 include/linux/blkdev.h | 14 ++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index 14d7c07..361b1b9 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1153,6 +1153,7 @@ static struct request *__get_request(struct request_list 
*rl, int op,
 
blk_rq_init(q, rq);
blk_rq_set_rl(rq, rl);
+   blk_rq_set_prio(rq, ioc);
req_set_op_attrs(rq, op, op_flags | REQ_ALLOCED);
 
/* init elvpriv */
@@ -1656,7 +1657,8 @@ void init_request_from_bio(struct request *req, struct 
bio *bio)
 
req->errors = 0;
req->__sector = bio->bi_iter.bi_sector;
-   req->ioprio = bio_prio(bio);
+   if (ioprio_valid(bio_prio(bio)))
+   req->ioprio = bio_prio(bio);
blk_rq_bio_prep(req->q, req, bio);
 }
 
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index c47c358..9a0ceaa 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -934,6 +934,20 @@ static inline unsigned int blk_rq_count_bios(struct 
request *rq)
 }
 
 /*
+ * blk_rq_set_prio - associate a request with prio from ioc
+ * @rq: request of interest
+ * @ioc: target iocontext
+ *
+ * Assocate request prio with ioc prio so request based drivers
+ * can leverage priority information.
+ */
+static inline void blk_rq_set_prio(struct request *rq, struct io_context *ioc)
+{
+   if (ioc)
+   rq->ioprio = ioc->ioprio;
+}
+
+/*
  * Request issue related functions.
  */
 extern struct request *blk_peek_request(struct request_queue *q);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 3/4] ata: Enabling ATA Command Priorities

2016-10-13 Thread Adam Manzanares
This patch checks to see if an ATA device supports NCQ command priorities.
If so and the user has specified an iocontext that indicates IO_PRIO_CLASS_RT
then we build a tf with a high priority command.

Signed-off-by: Adam Manzanares 
---
 drivers/ata/libata-core.c | 35 ++-
 drivers/ata/libata-scsi.c |  6 +-
 drivers/ata/libata.h  |  2 +-
 include/linux/ata.h   |  6 ++
 include/linux/libata.h| 18 ++
 5 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 223a770..181b530 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -739,6 +739,7 @@ u64 ata_tf_read_block(const struct ata_taskfile *tf, struct 
ata_device *dev)
  * @n_block: Number of blocks
  * @tf_flags: RW/FUA etc...
  * @tag: tag
+ * @class: IO priority class
  *
  * LOCKING:
  * None.
@@ -753,7 +754,7 @@ u64 ata_tf_read_block(const struct ata_taskfile *tf, struct 
ata_device *dev)
  */
 int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
u64 block, u32 n_block, unsigned int tf_flags,
-   unsigned int tag)
+   unsigned int tag, int class)
 {
tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
tf->flags |= tf_flags;
@@ -785,6 +786,12 @@ int ata_build_rw_tf(struct ata_taskfile *tf, struct 
ata_device *dev,
tf->device = ATA_LBA;
if (tf->flags & ATA_TFLAG_FUA)
tf->device |= 1 << 7;
+
+   if (ata_ncq_prio_enabled(dev)) {
+   if (class == IOPRIO_CLASS_RT)
+   tf->hob_nsect |= ATA_PRIO_HIGH <<
+ATA_SHIFT_PRIO;
+   }
} else if (dev->flags & ATA_DFLAG_LBA) {
tf->flags |= ATA_TFLAG_LBA;
 
@@ -2156,6 +2163,30 @@ static void ata_dev_config_ncq_non_data(struct 
ata_device *dev)
}
 }
 
+static void ata_dev_config_ncq_prio(struct ata_device *dev)
+{
+   struct ata_port *ap = dev->link->ap;
+   unsigned int err_mask;
+
+   err_mask = ata_read_log_page(dev,
+ATA_LOG_SATA_ID_DEV_DATA,
+ATA_LOG_SATA_SETTINGS,
+ap->sector_buf,
+1);
+   if (err_mask) {
+   ata_dev_dbg(dev,
+   "failed to get Identify Device data, Emask 0x%x\n",
+   err_mask);
+   return;
+   }
+
+   if (ap->sector_buf[ATA_LOG_NCQ_PRIO_OFFSET] & BIT(3))
+   dev->flags |= ATA_DFLAG_NCQ_PRIO;
+   else
+   ata_dev_dbg(dev, "SATA page does not support priority\n");
+
+}
+
 static int ata_dev_config_ncq(struct ata_device *dev,
   char *desc, size_t desc_sz)
 {
@@ -2205,6 +2236,8 @@ static int ata_dev_config_ncq(struct ata_device *dev,
ata_dev_config_ncq_send_recv(dev);
if (ata_id_has_ncq_non_data(dev->id))
ata_dev_config_ncq_non_data(dev);
+   if (ata_id_has_ncq_prio(dev->id))
+   ata_dev_config_ncq_prio(dev);
}
 
return 0;
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index e207b33..18629e8 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -50,6 +50,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "libata.h"
 #include "libata-transport.h"
@@ -1757,6 +1758,8 @@ static unsigned int ata_scsi_rw_xlat(struct 
ata_queued_cmd *qc)
 {
struct scsi_cmnd *scmd = qc->scsicmd;
const u8 *cdb = scmd->cmnd;
+   struct request *rq = scmd->request;
+   int class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq));
unsigned int tf_flags = 0;
u64 block;
u32 n_block;
@@ -1823,7 +1826,8 @@ static unsigned int ata_scsi_rw_xlat(struct 
ata_queued_cmd *qc)
qc->nbytes = n_block * scmd->device->sector_size;
 
rc = ata_build_rw_tf(&qc->tf, qc->dev, block, n_block, tf_flags,
-qc->tag);
+qc->tag, class);
+
if (likely(rc == 0))
return 0;
 
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index 3b301a4..8f3a559 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -66,7 +66,7 @@ extern u64 ata_tf_to_lba48(const struct ata_taskfile *tf);
 extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag);
 extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
   u64 block, u32 n_block, unsigned int tf_flags,
-  unsigned int tag);
+  unsigned int tag, int class);
 extern u64 ata_tf_read_block(const struct ata_taskfile *tf,
 struct ata_device

  1   2   >