Re: [PATCH 04/15] target/iscsi: move session_index to common se_session

2018-07-18 Thread Mike Christie
On 07/18/2018 07:15 PM, Mike Christie wrote:
> On 07/18/2018 05:19 PM, Bart Van Assche wrote:
>> On Sun, 2018-07-15 at 18:16 -0500, Mike Christie wrote:
>>> diff --git a/drivers/target/target_core_transport.c 
>>> b/drivers/target/target_core_transport.c
>>> index 75ddbbb..97a1ee5 100644
>>> --- a/drivers/target/target_core_transport.c
>>> +++ b/drivers/target/target_core_transport.c
>>> @@ -55,6 +55,8 @@
>>>  
>>>  static struct workqueue_struct *target_completion_wq;
>>>  static struct kmem_cache *se_sess_cache;
>>> +static DEFINE_SPINLOCK(se_sess_idr_lock);
>>> +static DEFINE_IDR(se_sess_idr);
>>
>> Is it necessary that se_sess_idr_lock and se_sess_idr are global? Could these
>> two data structures be members of the data structure associated with
>> /sys/kernel/config/target/iscsi/$port/$tpg (struct se_portal_group?)?
> 
> For tcmu we have a problem where we pass the scsi commands to userspace
> but then we need to know what I_T nexus it was sent through or what
> target port it was received on.
> 
> I thought I could reuse the sid for tcmu commands where I could embed
> the sid in the tcmu_cmd and then userspace can look up the sid and know
> what session the command came in on. If the device is exported through 2
> tpgs then we need the sid target wide in case sessions on different tpgs
> have the same sid. And, then I thought if you exported the device
> through 2 fabrics then I thought you need it set globally.
> 
> I am still working on that part with Bodo, so I can make it per tpg when
> I resend then do another path to change it later.

Hey Bart, I looked into this some more and this value is also being used
as the scsiAttIntrPortIndex. For that use, does it need to be unique
across a target when the target has multiple ports?

So I think it needs to be on the se_wwn right?




Re: [PATCH 11/15] target: export initiator port values for all sessions

2018-07-18 Thread Mike Christie
On 07/18/2018 06:04 PM, Mike Christie wrote:
> On 07/18/2018 05:41 PM, Bart Van Assche wrote:
>> On Sun, 2018-07-15 at 18:16 -0500, Mike Christie wrote:
>>> Export the initiator port info in configfs
>>
>> Does configfs support soft links? Can this information be exported as a
>> soft link from the session directory to the struct se_portal_group configfs
>> object?
>>
> 
> If you just needed to export the initiator name or if a single session
> per initiator can be connected to a tpg then it would work ok.
> 
> The problem is for iscsi the scsi initiator port / transport id, is the
> initiator name and isid. The isid is just a 48 bit number and the
> initiator will allocate a new value for every session. So on the
> initiator side if there are multiple nics, then it is common to create a
> session through nic and each session will have the same initiator name
> but different isids. So at some place you need to put multiple files to
> export the different isids or indicate to userspace tools that there is
> more than one session connected to that tpg.
>

Oh wait, I think I know what you mean. Did you want something like this
where the symlink name is the info in the initiator_port file like this:

[tpgt_1]# tree -L 2
.
`-- sessions
`-- 1
|   `-- iqn.2005-03.com.ceph:ini1,i,0x00023d01 -> ../../tpgt_1
 `--2
.   `-- iqn.2005-03.com.ceph:ini1,i,0x00023d02 -> ../../tpgt_1

If that is what you are asking about, I did not get why we want to link
to the tpg object, because we already know the tpg since it is the
parent of the session dir.


Re: [PATCH 02/15] target: fix isid copying and comparision

2018-07-18 Thread Mike Christie
On 07/18/2018 07:03 PM, Mike Christie wrote:
> On 07/18/2018 05:09 PM, Bart Van Assche wrote:
>> On Sun, 2018-07-15 at 18:16 -0500, Mike Christie wrote:
>>> The isid is 48 bits, and in hex string format it's 12 bytes.
>>> We are currently copying the 12 byte hex string to a u64
>>> so we can easily compare it, but this has the problem that
>>> only 8 bytes of the 12 bytes are copied.
>>>
>>> The next patches will want to print se_session sess_bin_isid
>>> so this has us use hex2bin to when converting from the hex
>>> sting to the bin value.
>>   ^
>>   string?
>>
>> Which spec defines that an ISID is 48 bits? All I know about SCSI 
>> registrations
> 
> The iscsi spec defines it as 48 bits.
> 
>> is that these involve a transport ID and that that transport ID can be up to 
>> 228
>> bytes long for iSCSI.
> 
> I am talking about the Initiator Session ID above. That along with the
> iscsi name make up the Initiator Port Transport ID. In spc4r37 checkout
> table 508 or in SAM 5r21 checkout table A.4.
> 
> So in the SCSI specs as part of the Initiator Port Transport ID we have
> this from that SAM table:
> 
> The Initiator Session Identifier (ISID) portion of the string is a UTF-8
> encoded hexadecimal representation of a six byte binary value.
> 
> ---
> 
> In the PR parts of SPC it sometimes mentions only "Transport ID" but
> then clarifies the initiator port so I am assuming in those cases it
> means "Initiator Port Transport ID" so it is both the name and isid for
> iscsi.

It looks like we are supposed to go by what the initiator specifies in
the TPID field, so it can be either the Transport ID or Initiator Port
Transport ID.


Re: [PATCH 12/15] target: add callout to test a session

2018-07-18 Thread Mike Christie
On 07/18/2018 05:46 PM, Bart Van Assche wrote:
> On Sun, 2018-07-15 at 18:16 -0500, Mike Christie wrote:
>> +   int (*test_session)(struct se_session *, u8 timeout);
> 
> Does any of the patches in this series define a test_session callback
> function?

Patch 14 does.

> 
> What is the unit of the timeout parameter? 1/HZ, ms or s?
> 

It is seconds.

I will add comments to document the callout requirements and arguments.

> Thanks,
> 
> Bart.
> 



Re: [PATCH 04/15] target/iscsi: move session_index to common se_session

2018-07-18 Thread Mike Christie
On 07/18/2018 05:19 PM, Bart Van Assche wrote:
> On Sun, 2018-07-15 at 18:16 -0500, Mike Christie wrote:
>> diff --git a/drivers/target/target_core_transport.c 
>> b/drivers/target/target_core_transport.c
>> index 75ddbbb..97a1ee5 100644
>> --- a/drivers/target/target_core_transport.c
>> +++ b/drivers/target/target_core_transport.c
>> @@ -55,6 +55,8 @@
>>  
>>  static struct workqueue_struct *target_completion_wq;
>>  static struct kmem_cache *se_sess_cache;
>> +static DEFINE_SPINLOCK(se_sess_idr_lock);
>> +static DEFINE_IDR(se_sess_idr);
> 
> Is it necessary that se_sess_idr_lock and se_sess_idr are global? Could these
> two data structures be members of the data structure associated with
> /sys/kernel/config/target/iscsi/$port/$tpg (struct se_portal_group?)?

For tcmu we have a problem where we pass the scsi commands to userspace
but then we need to know what I_T nexus it was sent through or what
target port it was received on.

I thought I could reuse the sid for tcmu commands where I could embed
the sid in the tcmu_cmd and then userspace can look up the sid and know
what session the command came in on. If the device is exported through 2
tpgs then we need the sid target wide in case sessions on different tpgs
have the same sid. And, then I thought if you exported the device
through 2 fabrics then I thought you need it set globally.

I am still working on that part with Bodo, so I can make it per tpg when
I resend then do another path to change it later.


Re: [PATCH 02/15] target: fix isid copying and comparision

2018-07-18 Thread Mike Christie
On 07/18/2018 05:09 PM, Bart Van Assche wrote:
> On Sun, 2018-07-15 at 18:16 -0500, Mike Christie wrote:
>> The isid is 48 bits, and in hex string format it's 12 bytes.
>> We are currently copying the 12 byte hex string to a u64
>> so we can easily compare it, but this has the problem that
>> only 8 bytes of the 12 bytes are copied.
>>
>> The next patches will want to print se_session sess_bin_isid
>> so this has us use hex2bin to when converting from the hex
>> sting to the bin value.
>   ^
>   string?
> 
> Which spec defines that an ISID is 48 bits? All I know about SCSI 
> registrations

The iscsi spec defines it as 48 bits.

> is that these involve a transport ID and that that transport ID can be up to 
> 228
> bytes long for iSCSI.

I am talking about the Initiator Session ID above. That along with the
iscsi name make up the Initiator Port Transport ID. In spc4r37 checkout
table 508 or in SAM 5r21 checkout table A.4.

So in the SCSI specs as part of the Initiator Port Transport ID we have
this from that SAM table:

The Initiator Session Identifier (ISID) portion of the string is a UTF-8
encoded hexadecimal representation of a six byte binary value.

---

In the PR parts of SPC it sometimes mentions only "Transport ID" but
then clarifies the initiator port so I am assuming in those cases it
means "Initiator Port Transport ID" so it is both the name and isid for
iscsi.


> 
>>  if (isid != NULL) {
>> -pr_reg->pr_reg_bin_isid = get_unaligned_be64(isid);
>> +if (hex2bin((u8 *)_reg->pr_reg_bin_isid, isid, 6)) {
>> +pr_err("Invalid isid %s\n", isid);
>> +goto free_reg;
>> +}
> 
> Why is it necessary to convert the ISID from hex to binary format? If this
> conversion is necessary, isn't that something that should be handled by the
> iSCSI target driver instead of the target core?
> 

The target drivers get the value as a 48 bit binary value.

The PR code gets it in the string format as describe above.

I had thought the code preferred to store it in the binary format
because it was easier to test than comparing strings or maybe for speed,
so I just fixed that code.

I think we can just keep it in string format in
__transport_register_session then just compare strings in target_core_pr.c.



Re: [PATCH 11/15] target: export initiator port values for all sessions

2018-07-18 Thread Mike Christie
On 07/18/2018 05:41 PM, Bart Van Assche wrote:
> On Sun, 2018-07-15 at 18:16 -0500, Mike Christie wrote:
>> Export the initiator port info in configfs
> 
> Does configfs support soft links? Can this information be exported as a
> soft link from the session directory to the struct se_portal_group configfs
> object?
> 

If you just needed to export the initiator name or if a single session
per initiator can be connected to a tpg then it would work ok.

The problem is for iscsi the scsi initiator port / transport id, is the
initiator name and isid. The isid is just a 48 bit number and the
initiator will allocate a new value for every session. So on the
initiator side if there are multiple nics, then it is common to create a
session through nic and each session will have the same initiator name
but different isids. So at some place you need to put multiple files to
export the different isids or indicate to userspace tools that there is
more than one session connected to that tpg.




Re: [PATCH 12/15] target: add callout to test a session

2018-07-18 Thread Bart Van Assche
On Sun, 2018-07-15 at 18:16 -0500, Mike Christie wrote:
> +   int (*test_session)(struct se_session *, u8 timeout);

Does any of the patches in this series define a test_session callback
function?

What is the unit of the timeout parameter? 1/HZ, ms or s?

Thanks,

Bart.

Re: [PATCH 11/15] target: export initiator port values for all sessions

2018-07-18 Thread Bart Van Assche
On Sun, 2018-07-15 at 18:16 -0500, Mike Christie wrote:
> Export the initiator port info in configfs

Does configfs support soft links? Can this information be exported as a
soft link from the session directory to the struct se_portal_group configfs
object?

Thanks,

Bart.


Re: [PATCH 09/15] target: add session dir in configfs

2018-07-18 Thread Bart Van Assche
On Sun, 2018-07-15 at 18:16 -0500, Mike Christie wrote:
> +static void target_fabric_session_release(struct config_item *item)
> +{
> + struct se_session *se_sess = container_of(to_config_group(item),
> +   struct se_session, group);
> + target_release_session(se_sess);
> +}

Please consider changing the target_fabric_ prefix into target_ for all new
functions. Otherwise this patch looks fine to me.

Bart.

Re: [PATCH 08/15] target: add session removal function

2018-07-18 Thread Bart Van Assche
On Sun, 2018-07-15 at 18:16 -0500, Mike Christie wrote:
> This adds a function to remove a session which should be used by
> drivers that use target_setup_session.
> 
> All the drivers but iscsi and tcm_fc were doing calling
> transport_deregister_session_configfs and then immediately calling
> transport_deregister_session or just calling
> transport_deregisteir_session.
  ^
  transport_deregister_session?

Anyway:

Reviewed-by: Bart Van Assche 


Re: [PATCH 07/15] target: rename target_alloc_session

2018-07-18 Thread Bart Van Assche
On Sun, 2018-07-15 at 18:16 -0500, Mike Christie wrote:
> Rename target_alloc_session to target_setup_session to avoid
> confusion with the other transport session allocation
> function that only allocates the session and because
> the target_alloc_session does so more. It allocates the
  ^
  much?
> session, sets up the nacl and egisters the session.
> 
> The next patch will then add a remove function to match the
> setup in this one, so it should make sense for all drivers,
> except iscsi, to just call those 2 functions to setup and remove
> a session.

Anyway:

Reviewed-by: Bart Van Assche 


Re: [PATCH 06/15] target: make transport_init_session_tags static

2018-07-18 Thread Bart Van Assche
On Sun, 2018-07-15 at 18:16 -0500, Mike Christie wrote:
> transport_init_session_tags is only called from target_core_transport.c
> so make it static.

Reviewed-by: Bart Van Assche 


Re: [PATCH 05/15] target: remove sess_get_index

2018-07-18 Thread Bart Van Assche
On Sun, 2018-07-15 at 18:16 -0500, Mike Christie wrote:
> sess_get_index is meaninless for most drivers. For iscsi, it
^^
meaningless?
> is the same as the se_session->sid now and for fcoe it was just
> the port id which would not work if multiple initiators
> connected to the same target port. So just use the se_session sid
> for all drivers and remove sess_get_index callout.

Anyway:

Reviewed-by: Bart Van Assche 


Re: [PATCH 04/15] target/iscsi: move session_index to common se_session

2018-07-18 Thread Bart Van Assche
On Sun, 2018-07-15 at 18:16 -0500, Mike Christie wrote:
> diff --git a/drivers/target/target_core_transport.c 
> b/drivers/target/target_core_transport.c
> index 75ddbbb..97a1ee5 100644
> --- a/drivers/target/target_core_transport.c
> +++ b/drivers/target/target_core_transport.c
> @@ -55,6 +55,8 @@
>  
>  static struct workqueue_struct *target_completion_wq;
>  static struct kmem_cache *se_sess_cache;
> +static DEFINE_SPINLOCK(se_sess_idr_lock);
> +static DEFINE_IDR(se_sess_idr);

Is it necessary that se_sess_idr_lock and se_sess_idr are global? Could these
two data structures be members of the data structure associated with
/sys/kernel/config/target/iscsi/$port/$tpg (struct se_portal_group?)?

Thanks,

Bart.

Re: [PATCH 03/15] target: fix __transport_register_session locking

2018-07-18 Thread Bart Van Assche
On Sun, 2018-07-15 at 18:16 -0500, Mike Christie wrote:
> When __transport_register_session is called from
> transport_register_session irqs will already have been disabled,
> so we do not want the unlock irq call to enable them until
> the higher level has done the final
> spin_unlock_irqrestore/spin_unlock_irq.
> 
> This has __transport_register_session use the save/restore
> call.

Reviewed-by: Bart Van Assche 




Re: [PATCH 02/15] target: fix isid copying and comparision

2018-07-18 Thread Bart Van Assche
On Sun, 2018-07-15 at 18:16 -0500, Mike Christie wrote:
> The isid is 48 bits, and in hex string format it's 12 bytes.
> We are currently copying the 12 byte hex string to a u64
> so we can easily compare it, but this has the problem that
> only 8 bytes of the 12 bytes are copied.
> 
> The next patches will want to print se_session sess_bin_isid
> so this has us use hex2bin to when converting from the hex
> sting to the bin value.
  ^
  string?

Which spec defines that an ISID is 48 bits? All I know about SCSI registrations
is that these involve a transport ID and that that transport ID can be up to 228
bytes long for iSCSI.

>   if (isid != NULL) {
> - pr_reg->pr_reg_bin_isid = get_unaligned_be64(isid);
> + if (hex2bin((u8 *)_reg->pr_reg_bin_isid, isid, 6)) {
> + pr_err("Invalid isid %s\n", isid);
> + goto free_reg;
> + }

Why is it necessary to convert the ISID from hex to binary format? If this
conversion is necessary, isn't that something that should be handled by the
iSCSI target driver instead of the target core?

Thanks,

Bart.

[PATCH 10/12] qla2xxx: Fix Management Server NPort handle reservation logic

2018-07-18 Thread Himanshu Madhani
From: Quinn Tran 

After selecting the NPort handle/loop_id, set a bit
in the loop_id_map to prevent others from selecting the same
NPort handle.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_gbl.h  |  1 +
 drivers/scsi/qla2xxx/qla_init.c | 27 +++
 drivers/scsi/qla2xxx/qla_mid.c  |  2 +-
 drivers/scsi/qla2xxx/qla_os.c   |  3 ++-
 4 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index f68eb6096559..00fbd49a9a7a 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -118,6 +118,7 @@ extern int qla2x00_post_async_prlo_done_work(struct 
scsi_qla_host *,
 fc_port_t *, uint16_t *);
 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport);
 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport);
+int qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *);
 /*
  * Global Data in qla_os.c source file.
  */
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index a08502eaa789..addfc53a7bb5 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -5723,6 +5723,33 @@ qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t 
*dev)
 }
 
 
+/* FW does not set aside Loop id for MGMT Server/FAh */
+int
+qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
+{
+   int loop_id = FC_NO_LOOP_ID;
+   int lid = NPH_MGMT_SERVER - vha->vp_idx;
+   unsigned long flags;
+   struct qla_hw_data *ha = vha->hw;
+
+   if (vha->vp_idx == 0) {
+   set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
+   return NPH_MGMT_SERVER;
+   }
+   /* pick id from high and work down to low */
+   spin_lock_irqsave(>vport_slock, flags);
+   for (; lid > 0; lid--) {
+   if (!test_bit(lid, vha->hw->loop_id_map)) {
+   set_bit(lid, vha->hw->loop_id_map);
+   loop_id = lid;
+   break;
+   }
+   }
+   spin_unlock_irqrestore(>vport_slock, flags);
+
+   return loop_id;
+}
+
 /*
  * qla2x00_fabric_login
  * Issue fabric login command.
diff --git a/drivers/scsi/qla2xxx/qla_mid.c b/drivers/scsi/qla2xxx/qla_mid.c
index f6f0a759a7c2..14bc88bc4a5a 100644
--- a/drivers/scsi/qla2xxx/qla_mid.c
+++ b/drivers/scsi/qla2xxx/qla_mid.c
@@ -485,7 +485,7 @@ qla24xx_create_vhost(struct fc_vport *fc_vport)
"Couldn't allocate vp_id.\n");
goto create_vhost_failed;
}
-   vha->mgmt_svr_loop_id = NPH_MGMT_SERVER;
+   vha->mgmt_svr_loop_id = qla2x00_reserve_mgmt_server_loop_id(vha);
 
vha->dpc_flags = 0L;
 
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 6bdb9cf38b77..74c0585c498d 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -3048,7 +3048,8 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct 
pci_device_id *id)
host = base_vha->host;
base_vha->req = req;
if (IS_QLA2XXX_MIDTYPE(ha))
-   base_vha->mgmt_svr_loop_id = NPH_MGMT_SERVER;
+   base_vha->mgmt_svr_loop_id =
+   qla2x00_reserve_mgmt_server_loop_id(base_vha);
else
base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
base_vha->vp_idx;
-- 
2.12.0



[PATCH 5/5] qla2xxx: Return error when TMF returns

2018-07-18 Thread Himanshu Madhani
From: Anil Gurumurthy 

Propagate the task management completion status properly to avoid
unnecessary waits for commands to complete.

Fixes: faef62d13463 ("[SCSI] qla2xxx: Fix Task Management command asynchronous 
handling")
Cc: 
Signed-off-by: Anil Gurumurthy 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_init.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index db0e3279e07a..1b19b954bbae 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -1489,11 +1489,10 @@ qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, 
uint32_t lun,
 
wait_for_completion(_iocb->u.tmf.comp);
 
-   rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ?
-   QLA_SUCCESS : QLA_FUNCTION_FAILED;
+   rval = tm_iocb->u.tmf.data;
 
-   if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) {
-   ql_dbg(ql_dbg_taskm, vha, 0x8030,
+   if (rval != QLA_SUCCESS) {
+   ql_log(ql_log_warn, vha, 0x8030,
"TM IOCB failed (%x).\n", rval);
}
 
-- 
2.12.0



[PATCH 0/5] qla2xxx: Bug fixes for the driver

2018-07-18 Thread Himanshu Madhani
Hi Martin,

This patch series fixes issues with load/unload of the driver in a loop. 

Please apply this series for 4.18/scsi-fixes at your earliest convenience
to be included in 4.18.0-rc6.

Thanks,
Himanshu


Anil Gurumurthy (1):
  qla2xxx: Return error when TMF returns

Quinn Tran (4):
  qla2xxx: Fix unintialized List head crash
  qla2xxx: Fix NPIV deletion by calling wait_for_sess_deletion
  qla2xxx: Fix driver unload by shutting down chip
  qla2xxx: Fix ISP recovery on unload

 drivers/scsi/qla2xxx/qla_attr.c   |  1 +
 drivers/scsi/qla2xxx/qla_gbl.h|  1 +
 drivers/scsi/qla2xxx/qla_gs.c |  4 +++
 drivers/scsi/qla2xxx/qla_init.c   |  7 +++---
 drivers/scsi/qla2xxx/qla_inline.h |  2 ++
 drivers/scsi/qla2xxx/qla_isr.c|  3 +++
 drivers/scsi/qla2xxx/qla_mbx.c|  6 +
 drivers/scsi/qla2xxx/qla_mid.c| 11 +++--
 drivers/scsi/qla2xxx/qla_os.c | 51 +--
 drivers/scsi/qla2xxx/qla_sup.c|  3 +++
 10 files changed, 54 insertions(+), 35 deletions(-)

-- 
2.12.0



[PATCH 06/12] qla2xxx: Fix redundant fc_rport registration

2018-07-18 Thread Himanshu Madhani
From: Quinn Tran 

Prevent multiple registration with transport layer for
the same remote port.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_init.c | 18 +-
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 0fae17d1aaea..530d6e72d974 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -5169,19 +5169,11 @@ qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t 
*fcport)
if (IS_SW_RESV_ADDR(fcport->d_id))
return;
 
-   ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
-   __func__, fcport->port_name);
-
-   if (IS_QLAFX00(vha->hw)) {
-   qla2x00_set_fcport_state(fcport, FCS_ONLINE);
-   } else {
-   fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
-   fcport->disc_state = DSC_LOGIN_COMPLETE;
-   fcport->deleted = 0;
-   fcport->logout_on_delete = 1;
-   fcport->login_retry = vha->hw->login_retry_count;
-   qla2x00_set_fcport_state(fcport, FCS_ONLINE);
-   }
+   fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
+   fcport->disc_state = DSC_LOGIN_COMPLETE;
+   fcport->deleted = 0;
+   fcport->logout_on_delete = 1;
+   fcport->login_retry = vha->hw->login_retry_count;
 
qla2x00_set_fcport_state(fcport, FCS_ONLINE);
qla2x00_iidma_fcport(vha, fcport);
-- 
2.12.0



[PATCH 3/5] qla2xxx: Fix driver unload by shutting down chip

2018-07-18 Thread Himanshu Madhani
From: Quinn Tran 

Use chip shutdown at the start of unload to stop all
DMA + traffics and bring down the laser. This prevents
any link activities from triggering the driver to be
re-engaged.

Fixes: 4b60c82736d0 ("scsi: qla2xxx: Add fw_started flags to qpair")
Cc:  #4.16
Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_isr.c |  3 +++
 drivers/scsi/qla2xxx/qla_mbx.c |  6 ++
 drivers/scsi/qla2xxx/qla_mid.c |  6 --
 drivers/scsi/qla2xxx/qla_os.c  | 44 +-
 drivers/scsi/qla2xxx/qla_sup.c |  3 +++
 5 files changed, 34 insertions(+), 28 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 9fa5a2557f2c..7756106d4555 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -631,6 +631,9 @@ qla2x00_async_event(scsi_qla_host_t *vha, struct rsp_que 
*rsp, uint16_t *mb)
unsigned long   flags;
fc_port_t   *fcport = NULL;
 
+   if (!vha->hw->flags.fw_started)
+   return;
+
/* Setup to process RIO completion. */
handle_cnt = 0;
if (IS_CNA_CAPABLE(ha))
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index 7e875f575229..f0ec13d48bf3 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -4220,6 +4220,9 @@ qla25xx_init_req_que(struct scsi_qla_host *vha, struct 
req_que *req)
mbx_cmd_t *mcp = 
struct qla_hw_data *ha = vha->hw;
 
+   if (!ha->flags.fw_started)
+   return QLA_SUCCESS;
+
ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d3,
"Entered %s.\n", __func__);
 
@@ -4289,6 +4292,9 @@ qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct 
rsp_que *rsp)
mbx_cmd_t *mcp = 
struct qla_hw_data *ha = vha->hw;
 
+   if (!ha->flags.fw_started)
+   return QLA_SUCCESS;
+
ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d6,
"Entered %s.\n", __func__);
 
diff --git a/drivers/scsi/qla2xxx/qla_mid.c b/drivers/scsi/qla2xxx/qla_mid.c
index 2c1aaf9b7a00..aa727d07b702 100644
--- a/drivers/scsi/qla2xxx/qla_mid.c
+++ b/drivers/scsi/qla2xxx/qla_mid.c
@@ -152,10 +152,12 @@ int
 qla24xx_disable_vp(scsi_qla_host_t *vha)
 {
unsigned long flags;
-   int ret;
+   int ret = QLA_SUCCESS;
fc_port_t *fcport;
 
-   ret = qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL);
+   if (vha->hw->flags.fw_started)
+   ret = qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL);
+
atomic_set(>loop_state, LOOP_DOWN);
atomic_set(>loop_down_timer, LOOP_DOWN_TIME);
list_for_each_entry(fcport, >vp_fcports, list)
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index acc27808963c..2cd2e5ccce15 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -303,6 +303,7 @@ static void qla2x00_free_device(scsi_qla_host_t *);
 static int qla2xxx_map_queues(struct Scsi_Host *shost);
 static void qla2x00_destroy_deferred_work(struct qla_hw_data *);
 
+
 struct scsi_host_template qla2xxx_driver_template = {
.module = THIS_MODULE,
.name   = QLA2XXX_DRIVER_NAME,
@@ -3603,6 +3604,8 @@ qla2x00_remove_one(struct pci_dev *pdev)
 
base_vha = pci_get_drvdata(pdev);
ha = base_vha->hw;
+   ql_log(ql_log_info, base_vha, 0xb079,
+   "Removing driver\n");
 
/* Indicate device removal to prevent future board_disable and wait
 * until any pending board_disable has completed. */
@@ -3625,6 +3628,21 @@ qla2x00_remove_one(struct pci_dev *pdev)
}
qla2x00_wait_for_hba_ready(base_vha);
 
+   if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
+   if (ha->flags.fw_started)
+   qla2x00_abort_isp_cleanup(base_vha);
+   } else if (!IS_QLAFX00(ha)) {
+   if (IS_QLA8031(ha)) {
+   ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
+   "Clearing fcoe driver presence.\n");
+   if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
+   ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
+   "Error while clearing DRV-Presence.\n");
+   }
+
+   qla2x00_try_to_stop_firmware(base_vha);
+   }
+
qla2x00_wait_for_sess_deletion(base_vha);
 
/*
@@ -3648,14 +3666,6 @@ qla2x00_remove_one(struct pci_dev *pdev)
 
qla2x00_delete_all_vps(ha, base_vha);
 
-   if (IS_QLA8031(ha)) {
-   ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
-   "Clearing fcoe driver presence.\n");
-   if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
-   ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
-   "Error while clearing DRV-Presence.\n");
-   }
-

[PATCH 4/5] qla2xxx: Fix ISP recovery on unload

2018-07-18 Thread Himanshu Madhani
From: Quinn Tran 

During unload process, the chip can encounter problem
where a FW dump would be captured. For this case, the
full reset sequence will be skip to bring the chip
back to full operational state.

Fixes: e315cd28b9ef ("[SCSI] qla2xxx: Code changes for qla data structure 
refactoring")
Cc: 
Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_os.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 2cd2e5ccce15..1fbd16c8c9a7 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -6020,8 +6020,9 @@ qla2x00_do_dpc(void *data)
set_bit(ISP_ABORT_NEEDED, _vha->dpc_flags);
}
 
-   if (test_and_clear_bit(ISP_ABORT_NEEDED,
-   _vha->dpc_flags)) {
+   if (test_and_clear_bit
+   (ISP_ABORT_NEEDED, _vha->dpc_flags) &&
+   !test_bit(UNLOADING, _vha->dpc_flags)) {
 
ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
"ISP abort scheduled.\n");
-- 
2.12.0



[PATCH 2/5] qla2xxx: Fix NPIV deletion by calling wait_for_sess_deletion

2018-07-18 Thread Himanshu Madhani
From: Quinn Tran 

Add wait for session deletion to finish before freeing
an NPIV scsi host.

Fixes: 726b85487067 ("qla2xxx: Add framework for async fabric discovery")
Cc: 
Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_attr.c | 1 +
 drivers/scsi/qla2xxx/qla_gbl.h  | 1 +
 drivers/scsi/qla2xxx/qla_mid.c  | 5 +
 drivers/scsi/qla2xxx/qla_os.c   | 2 +-
 4 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 89a4999fa631..c8731568f9c4 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -2141,6 +2141,7 @@ qla24xx_vport_delete(struct fc_vport *fc_vport)
msleep(1000);
 
qla24xx_disable_vp(vha);
+   qla2x00_wait_for_sess_deletion(vha);
 
vha->flags.delete_progress = 1;
 
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index f68eb6096559..2660a48d918a 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -214,6 +214,7 @@ void qla2x00_handle_login_done_event(struct scsi_qla_host 
*, fc_port_t *,
 int qla24xx_post_gnl_work(struct scsi_qla_host *, fc_port_t *);
 int qla24xx_async_abort_cmd(srb_t *);
 int qla24xx_post_relogin_work(struct scsi_qla_host *vha);
+void qla2x00_wait_for_sess_deletion(scsi_qla_host_t *);
 
 /*
  * Global Functions in qla_mid.c source file.
diff --git a/drivers/scsi/qla2xxx/qla_mid.c b/drivers/scsi/qla2xxx/qla_mid.c
index f6f0a759a7c2..2c1aaf9b7a00 100644
--- a/drivers/scsi/qla2xxx/qla_mid.c
+++ b/drivers/scsi/qla2xxx/qla_mid.c
@@ -153,10 +153,15 @@ qla24xx_disable_vp(scsi_qla_host_t *vha)
 {
unsigned long flags;
int ret;
+   fc_port_t *fcport;
 
ret = qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL);
atomic_set(>loop_state, LOOP_DOWN);
atomic_set(>loop_down_timer, LOOP_DOWN_TIME);
+   list_for_each_entry(fcport, >vp_fcports, list)
+   fcport->logout_on_delete = 0;
+
+   qla2x00_mark_all_devices_lost(vha, 0);
 
/* Remove port id from vp target map */
spin_lock_irqsave(>hw->hardware_lock, flags);
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 9f309e572be4..acc27808963c 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -1147,7 +1147,7 @@ static inline int test_fcport_count(scsi_qla_host_t *vha)
  * qla2x00_wait_for_sess_deletion can only be called from remove_one.
  * it has dependency on UNLOADING flag to stop device discovery
  */
-static void
+void
 qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
 {
qla2x00_mark_all_devices_lost(vha, 0);
-- 
2.12.0



[PATCH 1/5] qla2xxx: Fix unintialized List head crash

2018-07-18 Thread Himanshu Madhani
From: Quinn Tran 

In case of IOCB Queue full or system where memory is low and
driver receives large number of RSCN storm, the stale sp pointer
can stay on gpnid_list resulting in page_fault.

This patch fixes this issue by initializing the sp->elem list head
and removing sp->elem before memory is freed.

Following stack trace is seen

 9 [987b37d1bc60] page_fault at ad516768 [exception RIP: 
qla24xx_async_gpnid+496]
10 [987b37d1bd10] qla24xx_async_gpnid at c039866d [qla2xxx]
11 [987b37d1bd80] qla2x00_do_work at c036169c [qla2xxx]
12 [987b37d1be38] qla2x00_do_dpc_all_vps at c03adfed [qla2xxx]
13 [987b37d1be78] qla2x00_do_dpc at c036458a [qla2xxx]
14 [987b37d1bec8] kthread at acebae31

Fixes: 2d73ac6102d9 ("scsi: qla2xxx: Serialize GPNID for multiple RSCN")
Cc:  # v4.17+
Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_gs.c | 4 
 drivers/scsi/qla2xxx/qla_inline.h | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/drivers/scsi/qla2xxx/qla_gs.c b/drivers/scsi/qla2xxx/qla_gs.c
index 2c35b0b2baa0..7a3744006419 100644
--- a/drivers/scsi/qla2xxx/qla_gs.c
+++ b/drivers/scsi/qla2xxx/qla_gs.c
@@ -3708,6 +3708,10 @@ int qla24xx_async_gpnid(scsi_qla_host_t *vha, port_id_t 
*id)
return rval;
 
 done_free_sp:
+   spin_lock_irqsave(>hw->vport_slock, flags);
+   list_del(>elem);
+   spin_unlock_irqrestore(>hw->vport_slock, flags);
+
if (sp->u.iocb_cmd.u.ctarg.req) {
dma_free_coherent(>hw->pdev->dev,
sizeof(struct ct_sns_pkt),
diff --git a/drivers/scsi/qla2xxx/qla_inline.h 
b/drivers/scsi/qla2xxx/qla_inline.h
index bcbdf28bd7b9..735f122607f3 100644
--- a/drivers/scsi/qla2xxx/qla_inline.h
+++ b/drivers/scsi/qla2xxx/qla_inline.h
@@ -220,6 +220,8 @@ qla2xxx_get_qpair_sp(struct qla_qpair *qpair, fc_port_t 
*fcport, gfp_t flag)
sp->fcport = fcport;
sp->iocbs = 1;
sp->vha = qpair->vha;
+   INIT_LIST_HEAD(>elem);
+
 done:
if (!sp)
QLA_QPAIR_MARK_NOT_BUSY(qpair);
-- 
2.12.0



[PATCH 05/12] qla2xxx: Silent erroneous message

2018-07-18 Thread Himanshu Madhani
From: Quinn Tran 

Driver uses shadow pointer instead of Mirror pointer
for firmware dump collection. Skip those entries for
Mirror pointers for Request/Response queue from
firmware dump template reading.

Following messages are printed in log messages

 kernel: qla2xxx [:81:00.0]-d82b:19: qla27xx_fwdt_entry_t268: unknown 
buffer 4
 kernel: qla2xxx [:81:00.0]-d82b:19: qla27xx_fwdt_entry_t268: unknown 
buffer 5

This patch fixes these error message by adding skip_entry() to
not read them from template.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_tmpl.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/scsi/qla2xxx/qla_tmpl.c b/drivers/scsi/qla2xxx/qla_tmpl.c
index b170eb54aab5..0ccd06f11f12 100644
--- a/drivers/scsi/qla2xxx/qla_tmpl.c
+++ b/drivers/scsi/qla2xxx/qla_tmpl.c
@@ -571,6 +571,15 @@ qla27xx_fwdt_entry_t268(struct scsi_qla_host *vha,
}
break;
 
+   case T268_BUF_TYPE_REQ_MIRROR:
+   case T268_BUF_TYPE_RSP_MIRROR:
+   /*
+* Mirror pointers are not implemented in the
+* driver, instead shadow pointers are used by
+* the drier. Skip these entries.
+*/
+   qla27xx_skip_entry(ent, buf);
+   break;
default:
ql_dbg(ql_dbg_async, vha, 0xd02b,
"%s: unknown buffer %x\n", __func__, ent->t268.buf_type);
-- 
2.12.0



[PATCH 07/12] qla2xxx: Fix session state stuck in Get Port DB

2018-07-18 Thread Himanshu Madhani
From: Quinn Tran 

This patch sets discovery state back to GNL (Get
Name List) when session is stuck at GPDB (Get Port
DataBase). This will allow state machine to retry
login and move session state ahead in discovery.

Signed-off-by: Quinn Tran 
---
 drivers/scsi/qla2xxx/qla_init.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 530d6e72d974..78d9c96ffe78 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -1155,9 +1155,12 @@ void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, 
struct event_arg *ea)
case PDS_PLOGI_COMPLETE:
case PDS_PRLI_PENDING:
case PDS_PRLI2_PENDING:
-   ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC relogin needed\n",
-   __func__, __LINE__, fcport->port_name);
-   set_bit(RELOGIN_NEEDED, >dpc_flags);
+   /* Set discovery state back to GNL to Relogin attempt */
+   if (qla_dual_mode_enabled(vha) ||
+   qla_ini_mode_enabled(vha)) {
+   fcport->disc_state = DSC_GNL;
+   set_bit(RELOGIN_NEEDED, >dpc_flags);
+   }
return;
case PDS_LOGO_PENDING:
case PDS_PORT_UNAVAILABLE:
-- 
2.12.0



[PATCH 11/12] qla2xxx: Fix race between switch cmd completion and timeout

2018-07-18 Thread Himanshu Madhani
From: Quinn Tran 

Fix race condition between switch cmd completion and timeout
timer. Timer has popped triggers command free. On IOCB completion,
stale sp point was reused. Instead, an abort will be sent to FW
to nudge the command out of FW, where the normal completion
will take place.

RIP: 0010:qla2x00_chk_ms_status+0xf3/0x1b0 [qla2xxx]
Call Trace:

qla24xx_els_ct_entry.isra.15+0x1d4/0x2b0 [qla2xxx]
 qla24xx_msix_rsp_q+0x39/0xf0 [qla2xxx]
qla24xx_process_response_queue+0xbc/0x2b0 [qla2xxx]
qla24xx_msix_rsp_q+0x8a/0xf0 [qla2xxx]
__handle_irq_event_percpu+0xa0/0x1f0

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_def.h  |  1 +
 drivers/scsi/qla2xxx/qla_gbl.h  |  2 +-
 drivers/scsi/qla2xxx/qla_init.c | 75 ++---
 3 files changed, 58 insertions(+), 20 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 9a98f1c73f5e..416b5ac29666 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -313,6 +313,7 @@ struct srb_cmd {
 #define SRB_CRC_CTX_DMA_VALID  BIT_2   /* DIF: context DMA valid */
 #define SRB_CRC_PROT_DMA_VALID BIT_4   /* DIF: prot DMA valid */
 #define SRB_CRC_CTX_DSD_VALID  BIT_5   /* DIF: dsd_list valid */
+#define SRB_WAKEUP_ON_COMP BIT_6
 
 /* To identify if a srb is of T10-CRC type. @sp => srb_t pointer */
 #define IS_PROT_IO(sp) (sp->flags & SRB_CRC_CTX_DSD_VALID)
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index 00fbd49a9a7a..6f2a37220a55 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -213,7 +213,7 @@ extern int qla24xx_post_upd_fcport_work(struct 
scsi_qla_host *, fc_port_t *);
 void qla2x00_handle_login_done_event(struct scsi_qla_host *, fc_port_t *,
uint16_t *);
 int qla24xx_post_gnl_work(struct scsi_qla_host *, fc_port_t *);
-int qla24xx_async_abort_cmd(srb_t *);
+int qla24xx_async_abort_cmd(srb_t *, bool);
 int qla24xx_post_relogin_work(struct scsi_qla_host *vha);
 
 /*
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index addfc53a7bb5..f6211bd7c86e 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -50,16 +50,15 @@ qla2x00_sp_timeout(struct timer_list *t)
 {
srb_t *sp = from_timer(sp, t, u.iocb_cmd.timer);
struct srb_iocb *iocb;
-   scsi_qla_host_t *vha = sp->vha;
struct req_que *req;
unsigned long flags;
 
-   spin_lock_irqsave(>hw->hardware_lock, flags);
-   req = vha->hw->req_q_map[0];
+   spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
+   req = sp->qpair->req;
req->outstanding_cmds[sp->handle] = NULL;
iocb = >u.iocb_cmd;
+   spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
iocb->timeout(sp);
-   spin_unlock_irqrestore(>hw->hardware_lock, flags);
 }
 
 void
@@ -100,6 +99,8 @@ qla2x00_async_iocb_timeout(void *data)
srb_t *sp = data;
fc_port_t *fcport = sp->fcport;
struct srb_iocb *lio = >u.iocb_cmd;
+   int rc, h;
+   unsigned long flags;
 
if (fcport) {
ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
@@ -114,11 +115,26 @@ qla2x00_async_iocb_timeout(void *data)
 
switch (sp->type) {
case SRB_LOGIN_CMD:
-   /* Retry as needed. */
-   lio->u.logio.data[0] = MBS_COMMAND_ERROR;
-   lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
-   QLA_LOGIO_LOGIN_RETRIED : 0;
-   sp->done(sp, QLA_FUNCTION_TIMEOUT);
+   rc = qla24xx_async_abort_cmd(sp, false);
+   if (rc) {
+   /* Retry as needed. */
+   lio->u.logio.data[0] = MBS_COMMAND_ERROR;
+   lio->u.logio.data[1] =
+   lio->u.logio.flags & SRB_LOGIN_RETRIED ?
+   QLA_LOGIO_LOGIN_RETRIED : 0;
+   spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
+   for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
+   h++) {
+   if (sp->qpair->req->outstanding_cmds[h] ==
+   sp) {
+   sp->qpair->req->outstanding_cmds[h] =
+   NULL;
+   break;
+   }
+   }
+   spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
+   sp->done(sp, QLA_FUNCTION_TIMEOUT);
+   }
break;
case SRB_LOGOUT_CMD:
case SRB_CT_PTHRU_CMD:
@@ -127,7 +143,21 @@ qla2x00_async_iocb_timeout(void *data)
case SRB_NACK_PRLI:
case SRB_NACK_LOGO:
case SRB_CTRL_VP:
-   sp->done(sp, QLA_FUNCTION_TIMEOUT);
+   

[PATCH 08/12] qla2xxx: Fix unintended Logout

2018-07-18 Thread Himanshu Madhani
From: Quinn Tran 

During normal IO, FW can return IO with 'port unavailble' status.
Driver would send a LOGO to remote port for session resync.  On
an off chance, a PLOGI could arrive before sending the LOGO.
This patch will skip sendiing LOGO, if a PLOGI just came in.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_target.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index c5c96e698799..d144719a96d6 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -986,8 +986,9 @@ void qlt_free_session_done(struct work_struct *work)
 
logo.id = sess->d_id;
logo.cmd_count = 0;
+   if (!own)
+   qlt_send_first_logo(vha, );
sess->send_els_logo = 0;
-   qlt_send_first_logo(vha, );
}
 
if (sess->logout_on_delete && sess->loop_id != FC_NO_LOOP_ID) {
-- 
2.12.0



[PATCH 04/12] qla2xxx: Prevent SysFS access when chip is down

2018-07-18 Thread Himanshu Madhani
From: Quinn Tran 

Prevent user from sending commands through SysFS while
FW is not running or reset is in progress.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_attr.c   | 33 +++--
 drivers/scsi/qla2xxx/qla_init.c   |  2 +-
 drivers/scsi/qla2xxx/qla_inline.h |  6 ++
 3 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 89a4999fa631..cc04caf83bd3 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -518,6 +518,9 @@ qla2x00_sysfs_write_vpd(struct file *filp, struct kobject 
*kobj,
if (unlikely(pci_channel_offline(ha->pdev)))
return 0;
 
+   if (qla2x00_chip_is_down(vha))
+   return 0;
+
if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
!ha->isp_ops->write_nvram)
return 0;
@@ -570,7 +573,7 @@ qla2x00_sysfs_read_sfp(struct file *filp, struct kobject 
*kobj,
if (!capable(CAP_SYS_ADMIN) || off != 0 || count < SFP_DEV_SIZE)
return 0;
 
-   if (qla2x00_reset_active(vha))
+   if (qla2x00_chip_is_down(vha))
return 0;
 
rval = qla2x00_read_sfp_dev(vha, buf, count);
@@ -733,6 +736,15 @@ qla2x00_issue_logo(struct file *filp, struct kobject *kobj,
int type;
port_id_t did;
 
+   if (!capable(CAP_SYS_ADMIN))
+   return 0;
+
+   if (unlikely(pci_channel_offline(vha->hw->pdev)))
+   return 0;
+
+   if (qla2x00_chip_is_down(vha))
+   return 0;
+
type = simple_strtol(buf, NULL, 10);
 
did.b.domain = (type & 0x00ff) >> 16;
@@ -771,6 +783,12 @@ qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct 
kobject *kobj,
if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
return 0;
 
+   if (unlikely(pci_channel_offline(ha->pdev)))
+   return 0;
+
+   if (qla2x00_chip_is_down(vha))
+   return 0;
+
if (ha->xgmac_data)
goto do_read;
 
@@ -825,6 +843,9 @@ qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct 
kobject *kobj,
if (ha->dcbx_tlv)
goto do_read;
 
+   if (qla2x00_chip_is_down(vha))
+   return 0;
+
ha->dcbx_tlv = dma_alloc_coherent(>pdev->dev, DCBX_TLV_DATA_SIZE,
>dcbx_tlv_dma, GFP_KERNEL);
if (!ha->dcbx_tlv) {
@@ -1036,7 +1057,7 @@ qla2x00_link_state_show(struct device *dev, struct 
device_attribute *attr,
vha->device_flags & DFLG_NO_CABLE)
len = scnprintf(buf, PAGE_SIZE, "Link Down\n");
else if (atomic_read(>loop_state) != LOOP_READY ||
-   qla2x00_reset_active(vha))
+   qla2x00_chip_is_down(vha))
len = scnprintf(buf, PAGE_SIZE, "Unknown Link State\n");
else {
len = scnprintf(buf, PAGE_SIZE, "Link Up - ");
@@ -1163,7 +1184,7 @@ qla2x00_beacon_store(struct device *dev, struct 
device_attribute *attr,
if (IS_QLA2100(ha) || IS_QLA2200(ha))
return -EPERM;
 
-   if (test_bit(ABORT_ISP_ACTIVE, >dpc_flags)) {
+   if (qla2x00_chip_is_down(vha)) {
ql_log(ql_log_warn, vha, 0x707a,
"Abort ISP active -- ignoring beacon request.\n");
return -EBUSY;
@@ -1350,7 +1371,7 @@ qla2x00_thermal_temp_show(struct device *dev,
scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
uint16_t temp = 0;
 
-   if (qla2x00_reset_active(vha)) {
+   if (qla2x00_chip_is_down(vha)) {
ql_log(ql_log_warn, vha, 0x70dc, "ISP reset active.\n");
goto done;
}
@@ -1381,7 +1402,7 @@ qla2x00_fw_state_show(struct device *dev, struct 
device_attribute *attr,
return scnprintf(buf, PAGE_SIZE, "0x%x\n", pstate);
}
 
-   if (qla2x00_reset_active(vha))
+   if (qla2x00_chip_is_down(vha))
ql_log(ql_log_warn, vha, 0x707c,
"ISP reset active.\n");
else if (!vha->hw->flags.eeh_busy)
@@ -1840,7 +1861,7 @@ qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
if (unlikely(pci_channel_offline(ha->pdev)))
goto done;
 
-   if (qla2x00_reset_active(vha))
+   if (qla2x00_chip_is_down(vha))
goto done;
 
stats = dma_zalloc_coherent(>pdev->dev, sizeof(*stats),
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index c58a6886fc43..0fae17d1aaea 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -7129,7 +7129,7 @@ uint8_t qla27xx_find_valid_image(struct scsi_qla_host 
*vha)
ha->active_image = QLA27XX_SECONDARY_IMAGE;
}
 
-   ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n",
+   ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x018f, "%s image\n",
   

[PATCH 09/12] qla2xxx: Flush mailbox commands on chip reset

2018-07-18 Thread Himanshu Madhani
From: Quinn Tran 

Flush pending mailbox commands on chip reset.  Wake up
command that's waiting for an interrupt and wait for
mailbox counters to go to zero.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_def.h  |  4 
 drivers/scsi/qla2xxx/qla_init.c | 18 ++
 drivers/scsi/qla2xxx/qla_mbx.c  | 35 +--
 drivers/scsi/qla2xxx/qla_os.c   |  3 +++
 4 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index ee4d1f4fdf95..9a98f1c73f5e 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -3598,6 +3598,7 @@ struct qla_hw_data {
uint32_tdetected_lr_sfp:1;
uint32_tusing_lr_setting:1;
uint32_trida_fmt2:1;
+   uint32_tpurge_mbox:1;
} flags;
 
uint16_t max_exchg;
@@ -3843,6 +3844,9 @@ struct qla_hw_data {
int port_down_retry_count;
uint8_t mbx_count;
uint8_t aen_mbx_count;
+   atomic_tnum_pend_mbx_stage1;
+   atomic_tnum_pend_mbx_stage2;
+   atomic_tnum_pend_mbx_stage3;
 
uint32_tlogin_retry_count;
/* SNS command interfaces. */
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 78d9c96ffe78..a08502eaa789 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -6390,6 +6390,7 @@ qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
ql_log(ql_log_info, vha, 0x00af,
"Performing ISP error recovery - ha=%p.\n", ha);
 
+   ha->flags.purge_mbox = 1;
/* For ISP82XX, reset_chip is just disabling interrupts.
 * Driver waits for the completion of the commands.
 * the interrupts need to be enabled.
@@ -6411,6 +6412,23 @@ qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
ha->base_qpair->chip_reset;
}
 
+   /* purge MBox commands */
+   if (atomic_read(>num_pend_mbx_stage3)) {
+   clear_bit(MBX_INTR_WAIT, >mbx_cmd_flags);
+   complete(>mbx_intr_comp);
+   }
+
+   i = 0;
+   while (atomic_read(>num_pend_mbx_stage3) ||
+   atomic_read(>num_pend_mbx_stage2) ||
+   atomic_read(>num_pend_mbx_stage1)) {
+   msleep(20);
+   i++;
+   if (i > 50)
+   break;
+   }
+   ha->flags.purge_mbox = 0;
+
atomic_set(>loop_down_timer, LOOP_DOWN_TIME);
if (atomic_read(>loop_state) != LOOP_DOWN) {
atomic_set(>loop_state, LOOP_DOWN);
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index 6e80c9fe71fd..4fb2ca41d7b5 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -167,6 +167,7 @@ qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t 
*mcp)
return QLA_FUNCTION_TIMEOUT;
}
 
+   atomic_inc(>num_pend_mbx_stage1);
/*
 * Wait for active mailbox commands to finish by waiting at most tov
 * seconds. This is to serialize actual issuing of mailbox cmds during
@@ -177,8 +178,14 @@ qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t 
*mcp)
ql_log(ql_log_warn, vha, 0xd035,
"Cmd access timeout, cmd=0x%x, Exiting.\n",
mcp->mb[0]);
+   atomic_dec(>num_pend_mbx_stage1);
return QLA_FUNCTION_TIMEOUT;
}
+   atomic_dec(>num_pend_mbx_stage1);
+   if (ha->flags.purge_mbox) {
+   rval = QLA_ABORTED;
+   goto premature_exit;
+   }
 
ha->flags.mbox_busy = 1;
/* Save mailbox command for debug */
@@ -231,7 +238,7 @@ qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t 
*mcp)
"jiffies=%lx.\n", jiffies);
 
/* Wait for mbx cmd completion until timeout */
-
+   atomic_inc(>num_pend_mbx_stage2);
if ((!abort_active && io_lock_on) || IS_NOPOLLING_TYPE(ha)) {
set_bit(MBX_INTR_WAIT, >mbx_cmd_flags);
 
@@ -241,6 +248,7 @@ qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t 
*mcp)
spin_unlock_irqrestore(>hardware_lock,
flags);
ha->flags.mbox_busy = 0;
+   atomic_dec(>num_pend_mbx_stage2);
ql_dbg(ql_dbg_mbx, vha, 0x1010,
"Pending mailbox timeout, exiting.\n");
rval = QLA_FUNCTION_TIMEOUT;
@@ -254,6 +262,7 @@ qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t 
*mcp)
spin_unlock_irqrestore(>hardware_lock, flags);
 
wait_time = jiffies;
+   atomic_inc(>num_pend_mbx_stage3);
if 

[PATCH 12/12] qla2xxx: Update driver version to 10.00.00.08-k

2018-07-18 Thread Himanshu Madhani
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_version.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_version.h 
b/drivers/scsi/qla2xxx/qla_version.h
index 1ad7582220c3..3850b28518e5 100644
--- a/drivers/scsi/qla2xxx/qla_version.h
+++ b/drivers/scsi/qla2xxx/qla_version.h
@@ -7,7 +7,7 @@
 /*
  * Driver version
  */
-#define QLA2XXX_VERSION  "10.00.00.07-k"
+#define QLA2XXX_VERSION  "10.00.00.08-k"
 
 #define QLA_DRIVER_MAJOR_VER   10
 #define QLA_DRIVER_MINOR_VER   0
-- 
2.12.0



[PATCH 01/12] qla2xxx: Fix N2N link re-connect

2018-07-18 Thread Himanshu Madhani
From: Quinn Tran 

In case of N2N connect, when sg_regset for bus/device/host
was causing driver and firmware state to go out of sync.
This patch fixes this link instablity when reconnect is
attempted after link flap.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_def.h|   3 +-
 drivers/scsi/qla2xxx/qla_init.c   | 229 +-
 drivers/scsi/qla2xxx/qla_iocb.c   |  15 ++-
 drivers/scsi/qla2xxx/qla_isr.c|   3 +-
 drivers/scsi/qla2xxx/qla_mbx.c|  27 +
 drivers/scsi/qla2xxx/qla_os.c |   5 +
 drivers/scsi/qla2xxx/qla_target.c |   9 ++
 7 files changed, 183 insertions(+), 108 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 9442e18aef6f..ee4d1f4fdf95 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -377,6 +377,7 @@ struct srb_iocb {
 #define SRB_LOGIN_COND_PLOGI   BIT_1
 #define SRB_LOGIN_SKIP_PRLIBIT_2
 #define SRB_LOGIN_NVME_PRLIBIT_3
+#define SRB_LOGIN_PRLI_ONLYBIT_4
uint16_t data[2];
u32 iop[2];
} logio;
@@ -4236,7 +4237,7 @@ typedef struct scsi_qla_host {
 #define FCOE_CTX_RESET_NEEDED  18  /* Initiate FCoE context reset */
 #define MPI_RESET_NEEDED   19  /* Initiate MPI FW reset */
 #define ISP_QUIESCE_NEEDED 20  /* Driver need some quiescence */
-#define FREE_BIT 21
+#define N2N_LINK_RESET 21
 #define PORT_UPDATE_NEEDED 22
 #define FX00_RESET_RECOVERY23
 #define FX00_TARGET_SCAN   24
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index b0430a280ce6..b85c7d311376 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -160,6 +160,22 @@ qla2x00_async_login_sp_done(void *ptr, int res)
sp->free(sp);
 }
 
+static inline bool
+fcport_is_smaller(fc_port_t *fcport)
+{
+   if (wwn_to_u64(fcport->port_name) <
+   wwn_to_u64(fcport->vha->port_name))
+   return true;
+   else
+   return false;
+}
+
+static inline bool
+fcport_is_bigger(fc_port_t *fcport)
+{
+   return !fcport_is_smaller(fcport);
+}
+
 int
 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
 uint16_t *data)
@@ -189,13 +205,18 @@ qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t 
*fcport,
qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
 
sp->done = qla2x00_async_login_sp_done;
-   lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
+   if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport)) {
+   lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY;
+   } else {
+   lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
 
-   if (fcport->fc4f_nvme)
-   lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
+   if (fcport->fc4f_nvme)
+   lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
+
+   if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
+   lio->u.logio.flags |= SRB_LOGIN_RETRIED;
+   }
 
-   if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
-   lio->u.logio.flags |= SRB_LOGIN_RETRIED;
rval = qla2x00_start_sp(sp);
if (rval != QLA_SUCCESS) {
fcport->flags |= FCF_LOGIN_NEEDED;
@@ -497,15 +518,18 @@ static void qla24xx_handle_gnl_done_event(scsi_qla_host_t 
*vha,
for (i = 0; i < n; i++) {
e = >gnl.l[i];
wwn = wwn_to_u64(e->port_name);
+   id.b.domain = e->port_id[2];
+   id.b.area = e->port_id[1];
+   id.b.al_pa = e->port_id[0];
+   id.b.rsvd_1 = 0;
 
if (memcmp((u8 *), fcport->port_name, WWN_SIZE))
continue;
 
+   if (IS_SW_RESV_ADDR(id))
+   continue;
+
found = 1;
-   id.b.domain = e->port_id[2];
-   id.b.area = e->port_id[1];
-   id.b.al_pa = e->port_id[0];
-   id.b.rsvd_1 = 0;
 
loop_id = le16_to_cpu(e->nport_handle);
loop_id = (loop_id & 0x7fff);
@@ -518,14 +542,18 @@ static void qla24xx_handle_gnl_done_event(scsi_qla_host_t 
*vha,
fcport->d_id.b.domain, fcport->d_id.b.area,
fcport->d_id.b.al_pa, loop_id, fcport->loop_id);
 
-   if ((id.b24 != fcport->d_id.b24) ||
-   ((fcport->loop_id != FC_NO_LOOP_ID) &&
-   (fcport->loop_id != loop_id))) {
-   ql_dbg(ql_dbg_disc, vha, 0x20e3,
-   "%s %d %8phC post del sess\n",
-   __func__, __LINE__, fcport->port_name);
-   qlt_schedule_sess_for_deletion(fcport);
-   return;
+   switch (fcport->disc_state) {
+   case DSC_DELETE_PEND:
+   case DSC_DELETED:
+   

[PATCH 03/12] qla2xxx: Add longer window for Chip reset

2018-07-18 Thread Himanshu Madhani
From: Quinn Tran 

The qla2x00_reset_active only cover the window of
turning the chip off, add check to cover Chip on.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_dbg.c  | 3 +++
 drivers/scsi/qla2xxx/qla_tmpl.c | 4 +++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_dbg.c b/drivers/scsi/qla2xxx/qla_dbg.c
index 5fd44c50bbac..c7533fa7f46e 100644
--- a/drivers/scsi/qla2xxx/qla_dbg.c
+++ b/drivers/scsi/qla2xxx/qla_dbg.c
@@ -1130,6 +1130,7 @@ qla24xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
ha->fw_dump);
goto qla24xx_fw_dump_failed;
}
+   QLA_FW_STOPPED(ha);
fw = >fw_dump->isp.isp24;
qla2xxx_prep_dump(ha, ha->fw_dump);
 
@@ -1384,6 +1385,7 @@ qla25xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
ha->fw_dump);
goto qla25xx_fw_dump_failed;
}
+   QLA_FW_STOPPED(ha);
fw = >fw_dump->isp.isp25;
qla2xxx_prep_dump(ha, ha->fw_dump);
ha->fw_dump->version = htonl(2);
@@ -2036,6 +2038,7 @@ qla83xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
"request...\n", ha->fw_dump);
goto qla83xx_fw_dump_failed;
}
+   QLA_FW_STOPPED(ha);
fw = >fw_dump->isp.isp83;
qla2xxx_prep_dump(ha, ha->fw_dump);
 
diff --git a/drivers/scsi/qla2xxx/qla_tmpl.c b/drivers/scsi/qla2xxx/qla_tmpl.c
index 731ca0d8520a..b170eb54aab5 100644
--- a/drivers/scsi/qla2xxx/qla_tmpl.c
+++ b/drivers/scsi/qla2xxx/qla_tmpl.c
@@ -1028,8 +1028,10 @@ qla27xx_fwdump(scsi_qla_host_t *vha, int hardware_locked)
ql_log(ql_log_warn, vha, 0xd300,
"Firmware has been previously dumped (%p),"
" -- ignoring request\n", vha->hw->fw_dump);
-   else
+   else {
+   QLA_FW_STOPPED(vha->hw);
qla27xx_execute_fwdt_template(vha);
+   }
 
 #ifndef __CHECKER__
if (!hardware_locked)
-- 
2.12.0



[PATCH 02/12] qla2xxx: Fix login retry count

2018-07-18 Thread Himanshu Madhani
From: Quinn Tran 

Login retry count was not properly decrementing,
which lead to endless login retry.

Signed-off-by: Quinn Tran 
Signed-off-by: Himanshu Madhani 
---
 drivers/scsi/qla2xxx/qla_gs.c | 16 +++
 drivers/scsi/qla2xxx/qla_init.c   | 23 +++---
 drivers/scsi/qla2xxx/qla_mbx.c|  1 +
 drivers/scsi/qla2xxx/qla_os.c | 90 ---
 drivers/scsi/qla2xxx/qla_target.c |  3 +-
 5 files changed, 70 insertions(+), 63 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_gs.c b/drivers/scsi/qla2xxx/qla_gs.c
index 4bc2b66b299f..5139a3577bb3 100644
--- a/drivers/scsi/qla2xxx/qla_gs.c
+++ b/drivers/scsi/qla2xxx/qla_gs.c
@@ -3475,6 +3475,14 @@ void qla24xx_handle_gpnid_event(scsi_qla_host_t *vha, 
struct event_arg *ea)
fcport->rscn_gen++;
fcport->scan_state = QLA_FCPORT_FOUND;
fcport->flags |= FCF_FABRIC_DEVICE;
+   if (fcport->login_retry == 0) {
+   fcport->login_retry =
+   vha->hw->login_retry_count;
+   ql_dbg(ql_dbg_disc, vha, 0x,
+   "Port login retry %8phN, lid 0x%04x 
cnt=%d.\n",
+   fcport->port_name, fcport->loop_id,
+   fcport->login_retry);
+   }
switch (fcport->disc_state) {
case DSC_LOGIN_COMPLETE:
/* recheck session is still intact. */
@@ -3967,6 +3975,14 @@ void qla24xx_async_gnnft_done(scsi_qla_host_t *vha, 
srb_t *sp)
} else {
if (fcport->rscn_rcvd ||
fcport->disc_state != DSC_LOGIN_COMPLETE) {
+   if (fcport->login_retry == 0) {
+   fcport->login_retry =
+   vha->hw->login_retry_count;
+   ql_dbg(ql_dbg_disc, vha, 0x20a3,
+   "Port login retry %8phN, lid 0x%04x 
retry cnt=%d.\n",
+   fcport->port_name, fcport->loop_id,
+   fcport->login_retry);
+   }
fcport->rscn_rcvd = 0;
qla24xx_fcport_handle_login(vha, fcport);
}
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index b85c7d311376..c58a6886fc43 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -213,8 +213,6 @@ qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t 
*fcport,
if (fcport->fc4f_nvme)
lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
 
-   if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
-   lio->u.logio.flags |= SRB_LOGIN_RETRIED;
}
 
rval = qla2x00_start_sp(sp);
@@ -485,7 +483,6 @@ static void qla24xx_handle_gnl_done_event(scsi_qla_host_t 
*vha,
 
if (ea->rc) { /* rval */
if (fcport->login_retry == 0) {
-   fcport->login_retry = vha->hw->login_retry_count;
ql_dbg(ql_dbg_disc, vha, 0x20de,
"GNL failed Port login retry %8phN, retry 
cnt=%d.\n",
fcport->port_name, fcport->login_retry);
@@ -1258,11 +1255,10 @@ int qla24xx_fcport_handle_login(struct scsi_qla_host 
*vha, fc_port_t *fcport)
return 0;
}
 
-   if (fcport->login_retry > 0)
-   fcport->login_retry--;
 
switch (fcport->disc_state) {
case DSC_DELETED:
+   fcport->login_retry--;
wwn = wwn_to_u64(fcport->node_name);
if (wwn == 0) {
ql_dbg(ql_dbg_disc, vha, 0x,
@@ -1275,6 +1271,7 @@ int qla24xx_fcport_handle_login(struct scsi_qla_host 
*vha, fc_port_t *fcport)
__func__, __LINE__, fcport->port_name);
qla24xx_post_gnl_work(vha, fcport);
} else {
+   fcport->login_retry--;
qla_chk_n2n_b4_login(vha, fcport);
}
break;
@@ -1291,6 +1288,7 @@ int qla24xx_fcport_handle_login(struct scsi_qla_host 
*vha, fc_port_t *fcport)
break;
 
case DSC_LOGIN_FAILED:
+   fcport->login_retry--;
ql_dbg(ql_dbg_disc, vha, 0x20d0,
"%s %d %8phC post gidpn\n",
__func__, __LINE__, fcport->port_name);
@@ -1305,6 +1303,7 @@ int qla24xx_fcport_handle_login(struct scsi_qla_host 
*vha, fc_port_t *fcport)
ql_dbg(ql_dbg_disc, vha, 0x20d1,
"%s %d %8phC post adisc\n",
__func__, 

[PATCH 00/12] qla2xxx: Updates for driver

2018-07-18 Thread Himanshu Madhani
Hi Martin,

This series contains bug-fixes for driver mainly in the area of interaction
with switch and small patch for N2N link reconnect.

Please apply this serise to 4.19/scsi-queue at your earliest convenience.

Thanks,
Himanshu

Himanshu Madhani (1):
  qla2xxx: Update driver version to 10.00.00.08-k

Quinn Tran (11):
  qla2xxx: Fix N2N link re-connect
  qla2xxx: Fix login retry count
  qla2xxx: Add longer window for Chip reset
  qla2xxx: Prevent SysFS access when chip is down
  qla2xxx: Silent erroneous message
  qla2xxx: Fix redundant fc_rport registration
  qla2xxx: Fix session state stuck in Get Port DB
  qla2xxx: Fix unintended Logout
  qla2xxx: Flush mailbox commands on chip reset
  qla2xxx: Fix Management Server NPort handle reservation logic
  qla2xxx: Fix race between switch cmd completion and timeout

 drivers/scsi/qla2xxx/qla_attr.c|  33 +++-
 drivers/scsi/qla2xxx/qla_dbg.c |   3 +
 drivers/scsi/qla2xxx/qla_def.h |   8 +-
 drivers/scsi/qla2xxx/qla_gbl.h |   3 +-
 drivers/scsi/qla2xxx/qla_gs.c  |  16 ++
 drivers/scsi/qla2xxx/qla_init.c| 395 +
 drivers/scsi/qla2xxx/qla_inline.h  |   6 +
 drivers/scsi/qla2xxx/qla_iocb.c|  15 +-
 drivers/scsi/qla2xxx/qla_isr.c |   3 +-
 drivers/scsi/qla2xxx/qla_mbx.c |  63 +++---
 drivers/scsi/qla2xxx/qla_mid.c |   2 +-
 drivers/scsi/qla2xxx/qla_os.c  | 101 +-
 drivers/scsi/qla2xxx/qla_target.c  |  15 +-
 drivers/scsi/qla2xxx/qla_tmpl.c|  13 +-
 drivers/scsi/qla2xxx/qla_version.h |   2 +-
 15 files changed, 460 insertions(+), 218 deletions(-)

-- 
2.12.0



[Bug 199703] HPSA blocking boot on HP smart Array P400

2018-07-18 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=199703

Roberto M. (roby_program...@fastwebnet.it) changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |INVALID

--- Comment #29 from Roberto M. (roby_program...@fastwebnet.it) ---
Old FW card problem, 4.12 updated to 7.24, everything works

-- 
You are receiving this mail because:
You are the assignee for the bug.


[Bug 199703] HPSA blocking boot on HP smart Array P400

2018-07-18 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=199703

--- Comment #28 from Roberto M. (roby_program...@fastwebnet.it) ---
> Can you try to update your firmware on the disk controllers with HP SPP and
> see if it helps?

It solved my problem! thank you!, you are better than RHEL support, on their
faq is written no solution, please change the card with one compatible (I have
bought for less 30 euro a HP P410)

My FW was 4.12 now 7.24

bug, isn't a bug, my error, old FW not compatible with HPSA driver

-- 
You are receiving this mail because:
You are the assignee for the bug.


[Bug 199703] HPSA blocking boot on HP smart Array P400

2018-07-18 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=199703

--- Comment #27 from Roberto M. (roby_program...@fastwebnet.it) ---
(In reply to Don from comment #25)
> I was able to take the kernel.org driver and load over a P400, which I
> believe is older than your E200.
> 
> The E200 requires a working cache module for RAID 5 volumes. But you are
> using a  RAID 0...correct?
> 

No Raid 1-0, E200 isn't used, cable are connected to P400, I solved it, old FW
doesn't work with HPSA driver

-- 
You are receiving this mail because:
You are the assignee for the bug.


Re: st driver doesn't seem to grok LTO partitioning [coming back 2 and a half years later]

2018-07-18 Thread Emmanuel Florac
Le Fri, 15 Jan 2016 12:48:09 +0100
Emmanuel Florac  écrivait:

> Le Thu, 14 Jan 2016 15:12:53 -0500 (EST)
> Laurence Oberman  écrivait:
> 
> > All attempts to get my drive and changer firmware updated have
> > failed. So I wont be able to add another "tested by" to this thread
> > unless I can find another drive.  
> 
> Too bad, would have been good to test on a different brand. I have an
> IBM drive somewhere, but it's an LTO-4 alas. I know that IBM and HP
> drives may have some significant differences in behaviour.

I finally tested with an IBM LTO-6 drive, and as feared, it
doesn't behave like the HP LTO-6 drive.

I had previously found that partitioning an LTO-6 tape using an HP drive
like this worked just fine:

mt -f /dev/nst0 mkpartition 245

It actually silently rounds the value to the closest number. However,
the very same command fails with an IBM drive with an "input output
error", and the following output in dmesg ( st driver in debug mode):


[8329294.626574] st 7:0:2:0: [st0] Loading tape.
[8329294.631672] st 7:0:2:0: [st0] Block limits 1 - 8388608 bytes.
[8329294.632350] st 7:0:2:0: [st0] Mode sense. Length 11, medium 68, WBS 10, 
BLL 8
[8329294.632352] st 7:0:2:0: [st0] Density 5a, tape length: 0, drv buffer: 1
[8329294.632354] st 7:0:2:0: [st0] Block size: 0, buffer size: 4096 (1 blocks).
[8329294.633210] st 7:0:2:0: [st0] Partition page length is 16 bytes.
[8329294.633213] st 7:0:2:0: [st0] psd_cnt 2, max.parts 3, nbr_parts 0
[8329294.633214] st 7:0:2:0: [st0] Formatting tape with two partitions (1 = 
245 MB).
[8329294.635533] st 7:0:2:0: [st0] Error: 802, cmd: 15 10 0 0 18 0
[8329294.635536] st 7:0:2:0: [st0] Sense Key : Illegal Request [current] 
[8329294.635539] st 7:0:2:0: [st0] Add. Sense: Invalid field in parameter list
[8329294.635541] st 7:0:2:0: [st0] Partitioning of tape failed.

However with a slightly lower size it works:

root@srv-num-4:~# mt -f /dev/nst0 mkpartition 2426400

With the log output:

Jul 18 17:30:00 srv-num-4 kernel: st 7:0:2:0: [st0] Block limits 1 - 8388608 
bytes.
Jul 18 17:30:00 srv-num-4 kernel: st 7:0:2:0: [st0] Mode sense. Length 11, 
medium 68, WBS 10, BLL 8
Jul 18 17:30:00 srv-num-4 kernel: st 7:0:2:0: [st0] Density 5a, tape length: 0, 
drv buffer: 1
Jul 18 17:30:00 srv-num-4 kernel: st 7:0:2:0: [st0] Block size: 0, buffer size: 
4096 (1 blocks).
Jul 18 17:30:00 srv-num-4 kernel: st 7:0:2:0: [st0] Loading tape.
Jul 18 17:30:00 srv-num-4 kernel: st 7:0:2:0: [st0] Block limits 1 - 8388608 
bytes.
Jul 18 17:30:00 srv-num-4 kernel: st 7:0:2:0: [st0] Mode sense. Length 11, 
medium 68, WBS 10, BLL 8
Jul 18 17:30:00 srv-num-4 kernel: st 7:0:2:0: [st0] Density 5a, tape length: 0, 
drv buffer: 1
Jul 18 17:30:00 srv-num-4 kernel: st 7:0:2:0: [st0] Block size: 0, buffer size: 
4096 (1 blocks).
Jul 18 17:30:00 srv-num-4 kernel: st 7:0:2:0: [st0] Partition page length is 16 
bytes.
Jul 18 17:30:00 srv-num-4 kernel: st 7:0:2:0: [st0] psd_cnt 2, max.parts 3, 
nbr_parts 0
Jul 18 17:30:00 srv-num-4 kernel: st 7:0:2:0: [st0] Formatting tape with two 
partitions (1 = 2426000 MB).
Jul 18 17:30:00 srv-num-4 kernel: st 7:0:2:0: [st0] Error: 802, cmd: 15 10 
0 0 18 0
Jul 18 17:30:00 srv-num-4 kernel: st 7:0:2:0: [st0] Sense Key : Recovered Error 
[current]
Jul 18 17:30:00 srv-num-4 kernel: st 7:0:2:0: [st0] Add. Sense: Rounded 
parameter
Jul 18 17:30:00 srv-num-4 kernel: st 7:0:2:0: [st0] Recovered ioctl error (1).
Jul 18 17:30:00 srv-num-4 kernel: st 7:0:2:0: [st0] Sending FORMAT MEDIUM

Contrary to the HP drive, the IBM drive let us know that the parameter
we passed was slightly off and rounded to the nearest value, which is
the polite thing to do. Unfortunately, another difference with the HP
drive is that it only rounds to the *highest* nearest value, and
doesn't bother rounding down, so a slightly too high value will go
unnoticed with the HP drive, and will fail completely with the IBM one.

Isn't life wonderful?

Cheers,
-- 

Emmanuel Florac |   Direction technique
|   Intellique
|   
|   +33 1 78 94 84 02



pgpSV1FSBsRE6.pgp
Description: Signature digitale OpenPGP


Re: [PATCH] mpt3sas: correct reset of smid while clearing scsi tracker

2018-07-18 Thread Bart Van Assche
On Wed, 2018-07-18 at 01:22 -0400, Sreekanth Reddy wrote:
> In mpt3sas_base_clear_st() function smid value is reseted in wrong line,
> i.e. driver should reset smid value to zero after decrementing chain_offset
> counter in chain_lookup table but in current code, driver is resetting smid
> value before decrementing the chain_offset counter. which we are correcting
> with this patch.
> 
> Signed-off-by: Sreekanth Reddy 
> ---
>  drivers/scsi/mpt3sas/mpt3sas_base.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c 
> b/drivers/scsi/mpt3sas/mpt3sas_base.c
> index 902610d..94b939b 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_base.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
> @@ -3283,8 +3283,8 @@ void mpt3sas_base_clear_st(struct MPT3SAS_ADAPTER *ioc,
>   return;
>   st->cb_idx = 0xFF;
>   st->direct_io = 0;
> - st->smid = 0;
>   atomic_set(>chain_lookup[st->smid - 1].chain_offset, 0);
> + st->smid = 0;
>  }

How can this patch be correct without memory barrier between the atomic set and 
the
st->smid assignment?

Bart.




Re: [PATCH] mpt3sas: correct reset of smid while clearing scsi tracker

2018-07-18 Thread Tomas Henzl
On 07/18/2018 07:22 AM, Sreekanth Reddy wrote:
> In mpt3sas_base_clear_st() function smid value is reseted in wrong line,
> i.e. driver should reset smid value to zero after decrementing chain_offset
> counter in chain_lookup table but in current code, driver is resetting smid
> value before decrementing the chain_offset counter. which we are correcting
> with this patch.
>
> Signed-off-by: Sreekanth Reddy 

Fixes: 2b548dd3790f95c2e174d51c2c8ada71b6505b4e
scsi: mpt3sas: Fix calltrace observed while running IO & reset

Maybe both patches could be merged. 

Reviewed-by: Tomas Henzl 

Tomas

> ---
>  drivers/scsi/mpt3sas/mpt3sas_base.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c 
> b/drivers/scsi/mpt3sas/mpt3sas_base.c
> index 902610d..94b939b 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_base.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
> @@ -3283,8 +3283,8 @@ void mpt3sas_base_clear_st(struct MPT3SAS_ADAPTER *ioc,
>   return;
>   st->cb_idx = 0xFF;
>   st->direct_io = 0;
> - st->smid = 0;
>   atomic_set(>chain_lookup[st->smid - 1].chain_offset, 0);
> + st->smid = 0;
>  }
>  
>  /**