Re: [PATCH 3/5] qla1280: use lower_32_bits and upper_32_bits instead of reinventing them

2018-10-18 Thread Bart Van Assche

On 10/18/18 9:47 PM, Bart Van Assche wrote:

On 10/18/18 6:03 AM, Christoph Hellwig wrote:

@@ -1790,8 +1783,8 @@ qla1280_load_firmware_dma(struct scsi_qla_host *ha)
  mb[4] = cnt;
  mb[3] = ha->request_dma & 0x;
  mb[2] = (ha->request_dma >> 16) & 0x;
-    mb[7] = pci_dma_hi32(ha->request_dma) & 0x;
-    mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
+    mb[7] = upper_32_bits(ha->request_dma) & 0x;
+    mb[6] = upper_32_bits(ha->request_dma) >> 16;


Have you considered to use put_unaligned_be32()?


Answering my own question: put_unaligned_be32() is inappropriate here 
because it stores each pair of bytes in the opposite order of the 
current code on little endian systems.


Bart.


Re: [PATCH 3/5] qla1280: use lower_32_bits and upper_32_bits instead of reinventing them

2018-10-18 Thread Bart Van Assche

On 10/18/18 6:03 AM, Christoph Hellwig wrote:

@@ -1790,8 +1783,8 @@ qla1280_load_firmware_dma(struct scsi_qla_host *ha)
mb[4] = cnt;
mb[3] = ha->request_dma & 0x;
mb[2] = (ha->request_dma >> 16) & 0x;
-   mb[7] = pci_dma_hi32(ha->request_dma) & 0x;
-   mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
+   mb[7] = upper_32_bits(ha->request_dma) & 0x;
+   mb[6] = upper_32_bits(ha->request_dma) >> 16;


Hi Christoph,

Have you considered to use put_unaligned_be32()?

Thanks,

Bart.


Re: [PATCH 5/5] qla2xxx: use lower_32_bits and upper_32_bits instead of reinventing them

2018-10-18 Thread Bart Van Assche

On 10/18/18 6:03 AM, Christoph Hellwig wrote:

This also moves the optimization for builds with 32-bit dma_addr_t to
the compiler (where it belongs) instead of opencoding it based on
incorrect assumptions.

Signed-off-by: Christoph Hellwig 
---
  drivers/scsi/qla2xxx/qla_target.c | 8 
  drivers/scsi/qla2xxx/qla_target.h | 8 
  2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index 39828207bc1d..443711238c0e 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -2660,9 +2660,9 @@ static void qlt_load_cont_data_segments(struct 
qla_tgt_prm *prm)
cnt < QLA_TGT_DATASEGS_PER_CONT_24XX && prm->seg_cnt;
cnt++, prm->seg_cnt--) {
*dword_ptr++ =
-   cpu_to_le32(pci_dma_lo32
+   cpu_to_le32(lower_32_bits
(sg_dma_address(prm->sg)));
-   *dword_ptr++ = cpu_to_le32(pci_dma_hi32
+   *dword_ptr++ = cpu_to_le32(upper_32_bits
(sg_dma_address(prm->sg)));
*dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg));
  
@@ -2704,9 +2704,9 @@ static void qlt_load_data_segments(struct qla_tgt_prm *prm)

(cnt < QLA_TGT_DATASEGS_PER_CMD_24XX) && prm->seg_cnt;
cnt++, prm->seg_cnt--) {
*dword_ptr++ =
-   cpu_to_le32(pci_dma_lo32(sg_dma_address(prm->sg)));
+   cpu_to_le32(lower_32_bits(sg_dma_address(prm->sg)));
  
-		*dword_ptr++ = cpu_to_le32(pci_dma_hi32(

+   *dword_ptr++ = cpu_to_le32(upper_32_bits(
sg_dma_address(prm->sg)));


Hi Christoph,

Have you considered to use put_unaligned_le64() instead of storing the 
lower and upper 32 bits separately?


Thanks,

Bart.


Re: [PATCH 0/7] qla2xxx patches for kernel v4.20

2018-10-18 Thread Madhani, Himanshu
Hello Bart, 

> On Oct 18, 2018, at 3:45 PM, Bart Van Assche  wrote:
> 
> External Email
> 
> Hi Martin,
> 
> This is a series with mostly trivial patches for the qla2xxx driver. These
> patches address warnings reported by gcc and by the smatch and sparse static
> analyzers. Please consider these patches for kernel v4.20.
> 
> Thanks,
> 
> Bart.
> 
> Bart Van Assche (7):
>  qla2xxx: Modify fall-through annotations
>  qla2xxx: Improve several kernel-doc headers
>  qla2xxx: Declare local functions 'static'
>  qla2xxx: Make qla2x00_sysfs_write_nvram() easier to analyze
>  qla2xxx: Remove a set-but-not-used variable
>  qla2xxx: Make sure that qlafx00_ioctl_iosb_entry() initializes 'res'
>  qla2xxx: Remove two arguments from qlafx00_error_entry()
> 
> drivers/scsi/qla2xxx/qla_attr.c   |  2 +-
> drivers/scsi/qla2xxx/qla_init.c   |  7 ---
> drivers/scsi/qla2xxx/qla_iocb.c   |  4 ++--
> drivers/scsi/qla2xxx/qla_isr.c|  6 +++---
> drivers/scsi/qla2xxx/qla_mbx.c|  6 +++---
> drivers/scsi/qla2xxx/qla_mr.c | 21 +
> drivers/scsi/qla2xxx/qla_nx.c |  2 +-
> drivers/scsi/qla2xxx/qla_nx2.c|  2 +-
> drivers/scsi/qla2xxx/qla_os.c |  6 +++---
> drivers/scsi/qla2xxx/qla_sup.c|  2 +-
> drivers/scsi/qla2xxx/qla_target.c |  8 
> 11 files changed, 32 insertions(+), 34 deletions(-)
> 
> --
> 2.19.1.568.g152ad8e336-goog
> 

Looks good. 

For the Series

Acked-by: Himanshu Madhani 


Thanks,
- Himanshu



Re: [PATCH v3 0/5] qla2xxx: Add FC-NVMe Target support

2018-10-18 Thread Madhani, Himanshu
Hello All, 

> On Sep 28, 2018, at 3:46 PM, Himanshu Madhani  
> wrote:
> 
> Hi Martin, 
> 
> This series adds support for FC-NVMe Target.
> 
> Patch #1 adds infrastructure to support FC-NVMeT Link Service processing. 
> Patch #2 adds addes new qla_nvmet.[ch] files for FC-NVMe Target support.
> Patch #3 has bulk of changes to add hooks into common code infrastucture and 
> adds support for FC-NVMe Target LS4 processing via Purex path.
> Patch #4 adds SysFS hook to enable NVMe Target for the port.
> 
> Please apply them to 4.20/scsi-queue at your earliest convenience.
> 
> Changes from v2 -> v3
> o Reordered patches so that each patch compiles individually and is 
> bisectable.
> 
> Changes from v1 -> v2
> o Addressed all comments from Bart.
> o Consolidated Patch 1 and Patch 2 into single patch.
> o Fixed smatch warning reported by kbuild autommation.
> o NVMe Target mode is exclusive at the moment. Cavium driver does not support 
> both
>  FCP Target and NVMe Target at the same time. This will be fixed in later 
> updates.
> 
> Thanks,
> Himanshu 
> 
> Anil Gurumurthy (4):
>  qla2xxx_nvmet: Add FC-NVMe Target Link Service request handling
>  qla2xxx_nvmet: Add files for FC-NVMe Target support
>  qla2xxx_nvmet: Add FC-NVMe Target handling
>  qla2xxx_nvmet: Add SysFS node for FC-NVMe Target
> 
> Himanshu Madhani (1):
>  qla2xxx: Update driver version to 11.00.00.00-k
> 
> drivers/scsi/qla2xxx/Makefile  |   3 +-
> drivers/scsi/qla2xxx/qla_attr.c|  33 ++
> drivers/scsi/qla2xxx/qla_dbg.c |   1 +
> drivers/scsi/qla2xxx/qla_dbg.h |   2 +
> drivers/scsi/qla2xxx/qla_def.h |  35 +-
> drivers/scsi/qla2xxx/qla_fw.h  | 263 ++
> drivers/scsi/qla2xxx/qla_gbl.h |  24 +-
> drivers/scsi/qla2xxx/qla_gs.c  |  16 +-
> drivers/scsi/qla2xxx/qla_init.c|  49 +-
> drivers/scsi/qla2xxx/qla_iocb.c|   8 +-
> drivers/scsi/qla2xxx/qla_isr.c | 112 -
> drivers/scsi/qla2xxx/qla_mbx.c | 101 +++-
> drivers/scsi/qla2xxx/qla_nvme.h|  33 --
> drivers/scsi/qla2xxx/qla_nvmet.c   | 833 +++
> drivers/scsi/qla2xxx/qla_nvmet.h   | 129 +
> drivers/scsi/qla2xxx/qla_os.c  |  75 ++-
> drivers/scsi/qla2xxx/qla_target.c  | 977 -
> drivers/scsi/qla2xxx/qla_target.h  |  90 
> drivers/scsi/qla2xxx/qla_version.h |   4 +-
> 19 files changed, 2713 insertions(+), 75 deletions(-)
> create mode 100644 drivers/scsi/qla2xxx/qla_nvmet.c
> create mode 100644 drivers/scsi/qla2xxx/qla_nvmet.h
> 
> -- 
> 2.12.0
> 

Any review comments? 

Thanks,
- Himanshu



[PATCH] scsi: myrs: fix build failure on 32 bit

2018-10-18 Thread James Bottomley
For 32 bit versions we have to be careful about divisions of 64 bit
quantities so use do_div() instead of a direct division.  This fixes a
warning about _uldivmod being undefined in certain configurations

Fixes: 77266186397c ("scsi: myrs: Add Mylex RAID controller")
Reported-by: kbuild test robot 
Signed-off-by: James Bottomley 
---
 drivers/scsi/myrs.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/myrs.c b/drivers/scsi/myrs.c
index b02ee0b0dd55..a9f9c77e889f 100644
--- a/drivers/scsi/myrs.c
+++ b/drivers/scsi/myrs.c
@@ -1978,7 +1978,8 @@ myrs_get_resync(struct device *dev)
struct scsi_device *sdev = to_scsi_device(dev);
struct myrs_hba *cs = shost_priv(sdev->host);
struct myrs_ldev_info *ldev_info = sdev->hostdata;
-   u8 percent_complete = 0, status;
+   u64 percent_complete = 0;
+   u8 status;
 
if (sdev->channel < cs->ctlr_info->physchan_present || !ldev_info)
return;
@@ -1986,8 +1987,8 @@ myrs_get_resync(struct device *dev)
unsigned short ldev_num = ldev_info->ldev_num;
 
status = myrs_get_ldev_info(cs, ldev_num, ldev_info);
-   percent_complete = ldev_info->rbld_lba * 100 /
-   ldev_info->cfg_devsize;
+   percent_complete = ldev_info->rbld_lba * 100;
+   do_div(percent_complete, ldev_info->cfg_devsize);
}
raid_set_resync(myrs_raid_template, dev, percent_complete);
 }
-- 
2.16.4



Re: [scsi:misc 194/233] ERROR: "__aeabi_uldivmod" [drivers/scsi/myrs.ko] undefined!

2018-10-18 Thread James Bottomley
On Thu, 2018-10-18 at 10:28 -0700, James Bottomley wrote:
> On Fri, 2018-10-19 at 01:18 +0800, kbuild test robot wrote:
> > tree:   https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.g
> > it
> >  misc
> > head:   4d5b4ac1eae471bcd0fa381ab4099cc33e94e15d
> > commit: 77266186397c6c782a3f670d32808a9671806ec5 [194/233] scsi:
> > myrs: Add Mylex RAID controller (SCSI interface)
> > config: arm-allmodconfig (attached as .config)
> > compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0
> > reproduce:
> > wget https://raw.githubusercontent.com/intel/lkp-tests/mast
> > er
> > /sbin/make.cross -O ~/bin/make.cross
> > chmod +x ~/bin/make.cross
> > git checkout 77266186397c6c782a3f670d32808a9671806ec5
> > # save the attached .config to linux build tree
> > GCC_VERSION=7.2.0 make.cross ARCH=arm 
> > 
> > All errors (new ones prefixed by >>):
> > 
> > > > ERROR: "__aeabi_uldivmod" [drivers/scsi/myrs.ko] undefined!
> 
> I think this is the fix, can someone with an arm build check?

This fix turned out to be bogus, but now I've dusted off my arm32 build
environment (had to fix a bug with arm32 emulation in qemu 2.11.2 would
you believe) and actually tried compiling it, the next patch is the fix
(build tested but not boot tested).

James



[PATCH 5/7] qla2xxx: Remove a set-but-not-used variable

2018-10-18 Thread Bart Van Assche
This patch does not change any functionality.

Cc: Himanshu Madhani 
Signed-off-by: Bart Van Assche 
---
 drivers/scsi/qla2xxx/qla_os.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index dba672f87cb2..01607d2f2c34 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -1749,7 +1749,7 @@ qla2x00_loop_reset(scsi_qla_host_t *vha)
 static void
 __qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
 {
-   int cnt, status;
+   int cnt;
unsigned long flags;
srb_t *sp;
scsi_qla_host_t *vha = qp->vha;
@@ -1799,8 +1799,8 @@ __qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
if (!sp_get(sp)) {
spin_unlock_irqrestore
(qp->qp_lock_ptr, 
flags);
-   status = qla2xxx_eh_abort(
-   GET_CMD_SP(sp));
+   qla2xxx_eh_abort(
+   GET_CMD_SP(sp));
spin_lock_irqsave
(qp->qp_lock_ptr, 
flags);
}
-- 
2.19.1.568.g152ad8e336-goog



[PATCH 6/7] qla2xxx: Make sure that qlafx00_ioctl_iosb_entry() initializes 'res'

2018-10-18 Thread Bart Van Assche
Only one of the two code paths in qlafx00_ioctl_iosb_entry() initializes
the variable 'res'. Make sure that 'res' is initialized before
sp->done(sp, res) is called.

Cc: Himanshu Madhani 
Signed-off-by: Bart Van Assche 
---
 drivers/scsi/qla2xxx/qla_mr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_mr.c b/drivers/scsi/qla2xxx/qla_mr.c
index 2d96f3b7e3e3..b8f967e61891 100644
--- a/drivers/scsi/qla2xxx/qla_mr.c
+++ b/drivers/scsi/qla2xxx/qla_mr.c
@@ -2212,7 +2212,7 @@ qlafx00_ioctl_iosb_entry(scsi_qla_host_t *vha, struct 
req_que *req,
struct bsg_job *bsg_job;
struct fc_bsg_reply *bsg_reply;
struct srb_iocb *iocb_job;
-   int res;
+   int res = 0;
struct qla_mt_iocb_rsp_fx00 fstatus;
uint8_t *fw_sts_ptr;
 
-- 
2.19.1.568.g152ad8e336-goog



[PATCH 4/7] qla2xxx: Make qla2x00_sysfs_write_nvram() easier to analyze

2018-10-18 Thread Bart Van Assche
Modify the unlock statement such that it becomes easier for static
analyzers to analyze it. This patch does not change any functionality.

Cc: Himanshu Madhani 
Signed-off-by: Bart Van Assche 
---
 drivers/scsi/qla2xxx/qla_attr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index b28f159fdaee..0bb9ac6ece92 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -218,7 +218,7 @@ qla2x00_sysfs_write_nvram(struct file *filp, struct kobject 
*kobj,
 
mutex_lock(>optrom_mutex);
if (qla2x00_chip_is_down(vha)) {
-   mutex_unlock(>hw->optrom_mutex);
+   mutex_unlock(>optrom_mutex);
return -EAGAIN;
}
 
-- 
2.19.1.568.g152ad8e336-goog



[PATCH 7/7] qla2xxx: Remove two arguments from qlafx00_error_entry()

2018-10-18 Thread Bart Van Assche
Move a debug statement from qlafx00_error_entry() into its caller. Remove
one unused argument from that function. This patch does not change the
behavior of the qla2xxx driver.

Cc: Himanshu Madhani 
Signed-off-by: Bart Van Assche 
---
 drivers/scsi/qla2xxx/qla_mr.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_mr.c b/drivers/scsi/qla2xxx/qla_mr.c
index b8f967e61891..60f964c53c01 100644
--- a/drivers/scsi/qla2xxx/qla_mr.c
+++ b/drivers/scsi/qla2xxx/qla_mr.c
@@ -2681,12 +2681,10 @@ qlafx00_multistatus_entry(struct scsi_qla_host *vha,
  * @vha: SCSI driver HA context
  * @rsp: response queue
  * @pkt: Entry pointer
- * @estatus:
- * @etype:
  */
 static void
 qlafx00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp,
-   struct sts_entry_fx00 *pkt, uint8_t estatus, uint8_t etype)
+   struct sts_entry_fx00 *pkt)
 {
srb_t *sp;
struct qla_hw_data *ha = vha->hw;
@@ -2695,9 +2693,6 @@ qlafx00_error_entry(scsi_qla_host_t *vha, struct rsp_que 
*rsp,
struct req_que *req = NULL;
int res = DID_ERROR << 16;
 
-   ql_dbg(ql_dbg_async, vha, 0x507f,
-   "type of error status in response: 0x%x\n", estatus);
-
req = ha->req_q_map[que];
 
sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
@@ -2745,9 +2740,11 @@ qlafx00_process_response_queue(struct scsi_qla_host *vha,
 
if (pkt->entry_status != 0 &&
pkt->entry_type != IOCTL_IOSB_TYPE_FX00) {
+   ql_dbg(ql_dbg_async, vha, 0x507f,
+  "type of error status in response: 0x%x\n",
+  pkt->entry_status);
qlafx00_error_entry(vha, rsp,
-   (struct sts_entry_fx00 *)pkt, pkt->entry_status,
-   pkt->entry_type);
+   (struct sts_entry_fx00 *)pkt);
continue;
}
 
-- 
2.19.1.568.g152ad8e336-goog



[PATCH 1/7] qla2xxx: Modify fall-through annotations

2018-10-18 Thread Bart Van Assche
This patch avoids that the compiler complains about missing fall-through
annotations when building with W=1.

Cc: Himanshu Madhani 
Signed-off-by: Bart Van Assche 
---
 drivers/scsi/qla2xxx/qla_init.c   | 2 +-
 drivers/scsi/qla2xxx/qla_target.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index c72d8012fe2a..2ccf9f190c68 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -680,7 +680,7 @@ static void qla24xx_handle_gnl_done_event(scsi_qla_host_t 
*vha,
fcport);
break;
}
-   /* drop through */
+   /* fall through */
default:
if (fcport_is_smaller(fcport)) {
/* local adapter is bigger */
diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index 3015f1bbcf1a..902f9c25da2e 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -4540,7 +4540,7 @@ static int qlt_issue_task_mgmt(struct fc_port *sess, u64 
lun,
case QLA_TGT_CLEAR_TS:
case QLA_TGT_ABORT_TS:
abort_cmds_for_lun(vha, lun, a->u.isp24.fcp_hdr.s_id);
-   /* drop through */
+   /* fall through */
case QLA_TGT_CLEAR_ACA:
h = qlt_find_qphint(vha, mcmd->unpacked_lun);
mcmd->qpair = h->qpair;
-- 
2.19.1.568.g152ad8e336-goog



[PATCH 3/7] qla2xxx: Declare local functions 'static'

2018-10-18 Thread Bart Van Assche
This patch avoids that the compiler complains about missing declarations
when building with W=1.

Cc: Himanshu Madhani 
Signed-off-by: Bart Van Assche 
---
 drivers/scsi/qla2xxx/qla_init.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 2ccf9f190c68..6fe20c27acc1 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -425,7 +425,7 @@ void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, 
struct event_arg *ea)
__qla24xx_handle_gpdb_event(vha, ea);
 }
 
-int qla_post_els_plogi_work(struct scsi_qla_host *vha, fc_port_t *fcport)
+static int qla_post_els_plogi_work(struct scsi_qla_host *vha, fc_port_t 
*fcport)
 {
struct qla_work_evt *e;
 
@@ -1551,7 +1551,8 @@ void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
 }
 
 
-void qla_handle_els_plogi_done(scsi_qla_host_t *vha, struct event_arg *ea)
+static void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
+ struct event_arg *ea)
 {
ql_dbg(ql_dbg_disc, vha, 0x2118,
"%s %d %8phC post PRLI\n",
-- 
2.19.1.568.g152ad8e336-goog



[PATCH 2/7] qla2xxx: Improve several kernel-doc headers

2018-10-18 Thread Bart Van Assche
This patch avoids that complaints about kernel-doc headers are reported
when building with W=1.

Cc: Himanshu Madhani 
Signed-off-by: Bart Van Assche 
---
 drivers/scsi/qla2xxx/qla_iocb.c   | 4 ++--
 drivers/scsi/qla2xxx/qla_isr.c| 6 +++---
 drivers/scsi/qla2xxx/qla_mbx.c| 6 +++---
 drivers/scsi/qla2xxx/qla_mr.c | 6 +++---
 drivers/scsi/qla2xxx/qla_nx.c | 2 +-
 drivers/scsi/qla2xxx/qla_nx2.c| 2 +-
 drivers/scsi/qla2xxx/qla_sup.c| 2 +-
 drivers/scsi/qla2xxx/qla_target.c | 6 +++---
 8 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_iocb.c b/drivers/scsi/qla2xxx/qla_iocb.c
index 86fb8b21aa71..032635321ad6 100644
--- a/drivers/scsi/qla2xxx/qla_iocb.c
+++ b/drivers/scsi/qla2xxx/qla_iocb.c
@@ -1195,8 +1195,8 @@ qla24xx_walk_and_build_prot_sglist(struct qla_hw_data 
*ha, srb_t *sp,
  * @sp: SRB command to process
  * @cmd_pkt: Command type 3 IOCB
  * @tot_dsds: Total number of segments to transfer
- * @tot_prot_dsds:
- * @fw_prot_opts:
+ * @tot_prot_dsds: Total number of segments with protection information
+ * @fw_prot_opts: Protection options to be passed to firmware
  */
 inline int
 qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt,
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index d73b04e40590..30d3090842f8 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -25,7 +25,7 @@ static int qla2x00_error_entry(scsi_qla_host_t *, struct 
rsp_que *,
 
 /**
  * qla2100_intr_handler() - Process interrupts for the ISP2100 and ISP2200.
- * @irq:
+ * @irq: interrupt number
  * @dev_id: SCSI driver HA context
  *
  * Called by system whenever the host adapter generates an interrupt.
@@ -144,7 +144,7 @@ qla2x00_check_reg16_for_disconnect(scsi_qla_host_t *vha, 
uint16_t reg)
 
 /**
  * qla2300_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
- * @irq:
+ * @irq: interrupt number
  * @dev_id: SCSI driver HA context
  *
  * Called by system whenever the host adapter generates an interrupt.
@@ -3109,7 +3109,7 @@ qla2xxx_check_risc_status(scsi_qla_host_t *vha)
 
 /**
  * qla24xx_intr_handler() - Process interrupts for the ISP23xx and ISP24xx.
- * @irq:
+ * @irq: interrupt number
  * @dev_id: SCSI driver HA context
  *
  * Called by system whenever the host adapter generates an interrupt.
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index bd8c86aeccc2..38ef06d613ba 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -3479,9 +3479,9 @@ qla8044_read_serdes_word(scsi_qla_host_t *vha, uint32_t 
addr, uint32_t *data)
 /**
  * qla2x00_set_serdes_params() -
  * @vha: HA context
- * @sw_em_1g:
- * @sw_em_2g:
- * @sw_em_4g:
+ * @sw_em_1g: serial link options
+ * @sw_em_2g: serial link options
+ * @sw_em_4g: serial link options
  *
  * Returns
  */
diff --git a/drivers/scsi/qla2xxx/qla_mr.c b/drivers/scsi/qla2xxx/qla_mr.c
index 521a51370554..2d96f3b7e3e3 100644
--- a/drivers/scsi/qla2xxx/qla_mr.c
+++ b/drivers/scsi/qla2xxx/qla_mr.c
@@ -2624,7 +2624,7 @@ qlafx00_status_cont_entry(struct rsp_que *rsp, 
sts_cont_entry_t *pkt)
  * qlafx00_multistatus_entry() - Process Multi response queue entries.
  * @vha: SCSI driver HA context
  * @rsp: response queue
- * @pkt:
+ * @pkt: received packet
  */
 static void
 qlafx00_multistatus_entry(struct scsi_qla_host *vha,
@@ -2867,7 +2867,7 @@ qlafx00_async_event(scsi_qla_host_t *vha)
 /**
  * qlafx00x_mbx_completion() - Process mailbox command completions.
  * @vha: SCSI driver HA context
- * @mb0:
+ * @mb0: value to be written into mailbox register 0
  */
 static void
 qlafx00_mbx_completion(scsi_qla_host_t *vha, uint32_t mb0)
@@ -2893,7 +2893,7 @@ qlafx00_mbx_completion(scsi_qla_host_t *vha, uint32_t mb0)
 
 /**
  * qlafx00_intr_handler() - Process interrupts for the ISPFX00.
- * @irq:
+ * @irq: interrupt number
  * @dev_id: SCSI driver HA context
  *
  * Called by system whenever the host adapter generates an interrupt.
diff --git a/drivers/scsi/qla2xxx/qla_nx.c b/drivers/scsi/qla2xxx/qla_nx.c
index de2bc78449e7..8dbe94c52f65 100644
--- a/drivers/scsi/qla2xxx/qla_nx.c
+++ b/drivers/scsi/qla2xxx/qla_nx.c
@@ -2010,7 +2010,7 @@ qla82xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
 
 /**
  * qla82xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
- * @irq:
+ * @irq: interrupt number
  * @dev_id: SCSI driver HA context
  *
  * Called by system whenever the host adapter generates an interrupt.
diff --git a/drivers/scsi/qla2xxx/qla_nx2.c b/drivers/scsi/qla2xxx/qla_nx2.c
index 3a2b0282df14..fe856b602e03 100644
--- a/drivers/scsi/qla2xxx/qla_nx2.c
+++ b/drivers/scsi/qla2xxx/qla_nx2.c
@@ -3878,7 +3878,7 @@ qla8044_write_optrom_data(struct scsi_qla_host *vha, 
uint8_t *buf,
 #define PF_BITS_MASK   (0xF << 16)
 /**
  * qla8044_intr_handler() - Process interrupts for the ISP8044
- * @irq:
+ * @irq: interrupt number
  * @dev_id: SCSI driver HA context
  *
  

[PATCH 0/7] qla2xxx patches for kernel v4.20

2018-10-18 Thread Bart Van Assche
Hi Martin,

This is a series with mostly trivial patches for the qla2xxx driver. These
patches address warnings reported by gcc and by the smatch and sparse static
analyzers. Please consider these patches for kernel v4.20.

Thanks,

Bart.

Bart Van Assche (7):
  qla2xxx: Modify fall-through annotations
  qla2xxx: Improve several kernel-doc headers
  qla2xxx: Declare local functions 'static'
  qla2xxx: Make qla2x00_sysfs_write_nvram() easier to analyze
  qla2xxx: Remove a set-but-not-used variable
  qla2xxx: Make sure that qlafx00_ioctl_iosb_entry() initializes 'res'
  qla2xxx: Remove two arguments from qlafx00_error_entry()

 drivers/scsi/qla2xxx/qla_attr.c   |  2 +-
 drivers/scsi/qla2xxx/qla_init.c   |  7 ---
 drivers/scsi/qla2xxx/qla_iocb.c   |  4 ++--
 drivers/scsi/qla2xxx/qla_isr.c|  6 +++---
 drivers/scsi/qla2xxx/qla_mbx.c|  6 +++---
 drivers/scsi/qla2xxx/qla_mr.c | 21 +
 drivers/scsi/qla2xxx/qla_nx.c |  2 +-
 drivers/scsi/qla2xxx/qla_nx2.c|  2 +-
 drivers/scsi/qla2xxx/qla_os.c |  6 +++---
 drivers/scsi/qla2xxx/qla_sup.c|  2 +-
 drivers/scsi/qla2xxx/qla_target.c |  8 
 11 files changed, 32 insertions(+), 34 deletions(-)

-- 
2.19.1.568.g152ad8e336-goog



Re: [PATCH 1/4] gdth: refactor ioc_general

2018-10-18 Thread Finn Thain
On Thu, 18 Oct 2018, Christoph Hellwig wrote:

> +
> +static int ioc_general(void __user *arg, char *cmnd)
> +{
> + gdth_ioctl_general gen;
> + gdth_ha_str *ha;
> + char *buf = NULL;
> + u64 paddr;
> + int rval;
> +
> + if (copy_from_user(, arg, sizeof(gdth_ioctl_general)))
> + return -EFAULT;
> + ha = gdth_find_ha(gen.ionode);
> + if (!ha)
> + return -EFAULT;
> +
> + if (gen.data_len > INT_MAX)
> + return -EINVAL;
> + if (gen.sense_len > INT_MAX)
> + return -EINVAL;
> + if (gen.data_len + gen.sense_len > INT_MAX)
> + return -EINVAL;
> +
> + if (gen.data_len + gen.sense_len == 0)
> + goto execute;
> +
> + buf = gdth_ioctl_alloc(ha, gen.data_len + gen.sense_len, FALSE, );
> + if (!buf)
> + return -EFAULT;
> +
> + rval = -EFAULT;
> + if (copy_from_user(buf, arg + sizeof(gdth_ioctl_general),
> +gen.data_len + gen.sense_len))
> + goto out_free_buf;
> +
> + switch (gen.command.OpCode) {
> + case GDT_IOCTL:
> + gen.command.u.ioctl.p_param = paddr;
> + break;
> + case CACHESERVICE:
> + gdth_ioc_cacheservice(ha, , paddr);
> + break;
> + case SCSIRAWSERVICE:
> + gdth_ioc_scsiraw(ha, , paddr);
> + break;
> + default:
> + goto out_free_buf;
>  }
> -}

AFAICT, CACHESERVICE never gets assigned to command.OpCode.

That means your switch() is not equivalent to the original construction --

if (gen.command.OpCode == GDT_IOCTL) {

} else if (gen.command.Service == CACHESERVICE) {

} else if (gen.command.Service == SCSIRAWSERVICE) {

} else {

}

>  
> -rval = __gdth_execute(ha->sdev, , cmnd, gen.timeout, 
> );
> -if (rval < 0) {
> +execute:
> + rval = __gdth_execute(ha->sdev, , cmnd, gen.timeout,
> + );
> + if (rval < 0)
> + goto out_free_buf;
> + gen.status = rval;
> +
> + rval = -EFAULT;
> + if (copy_to_user(arg + sizeof(gdth_ioctl_general), buf,
> +  gen.data_len + gen.sense_len))
> + goto out_free_buf;
> + if (copy_to_user(arg, ,
> + sizeof(gdth_ioctl_general) - sizeof(gdth_cmd_str)))
> + goto out_free_buf;
> +
> + rval = 0;
> +out_free_buf:
>   gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr);
> -return rval;
> -}
> -gen.status = rval;
> -
> -if (copy_to_user(arg + sizeof(gdth_ioctl_general), buf, 
> - gen.data_len + gen.sense_len)) {
> -gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr);
> -return -EFAULT; 
> -} 
> -if (copy_to_user(arg, , 
> -sizeof(gdth_ioctl_general) - sizeof(gdth_cmd_str))) {
> -gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr);
> -return -EFAULT;
> -}
> -gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr);
> -return 0;
> + return 0;

This appears to be wrong also. I think you wanted,
return rval;

-- 

>  }
>   
>  static int ioc_hdrlist(void __user *arg, char *cmnd)
> 


Re: [PATCH 4/4] gdth: use generic DMA API

2018-10-18 Thread Finn Thain
On Thu, 18 Oct 2018, Christoph Hellwig wrote:

> Switch from the legacy PCI DMA API to the generic DMA API.  Also switch
> to dma_map_single from pci_map_page in one case where this makes the code
> simpler.
> 
> Signed-off-by: Christoph Hellwig 
> ---
>  drivers/scsi/gdth.c  | 111 +++
>  drivers/scsi/gdth_proc.c |   4 +-
>  2 files changed, 56 insertions(+), 59 deletions(-)
> 
> diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
> index 7274d09b2a6c..3d856554b1b1 100644
> --- a/drivers/scsi/gdth.c
> +++ b/drivers/scsi/gdth.c
> @@ -2518,9 +2518,9 @@ static int gdth_fill_cache_cmd(gdth_ha_str *ha, struct 
> scsi_cmnd *scp,
>  
>  if (scsi_bufflen(scp)) {
>  cmndinfo->dma_dir = (read_write == 1 ?
> -PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);   
> -sgcnt = pci_map_sg(ha->pdev, scsi_sglist(scp), 
> scsi_sg_count(scp),
> -   cmndinfo->dma_dir);
> +DMA_TO_DEVICE : DMA_FROM_DEVICE);   
> +sgcnt = dma_map_sg(>pdev->dev, scsi_sglist(scp),
> +scsi_sg_count(scp), cmndinfo->dma_dir);
>  if (mode64) {
>  struct scatterlist *sl;
>  
> @@ -2603,8 +2603,6 @@ static int gdth_fill_raw_cmd(gdth_ha_str *ha, struct 
> scsi_cmnd *scp, u8 b)
>  dma_addr_t sense_paddr;
>  int cmd_index, sgcnt, mode64;
>  u8 t,l;
> -struct page *page;
> -unsigned long offset;
>  struct gdth_cmndinfo *cmndinfo;
>  
>  t = scp->device->id;
> @@ -2649,10 +2647,8 @@ static int gdth_fill_raw_cmd(gdth_ha_str *ha, struct 
> scsi_cmnd *scp, u8 b)
>  }
>  
>  } else {
> -page = virt_to_page(scp->sense_buffer);
> -offset = (unsigned long)scp->sense_buffer & ~PAGE_MASK;
> -sense_paddr = pci_map_page(ha->pdev,page,offset,
> -   16,PCI_DMA_FROMDEVICE);
> +sense_paddr = dma_map_single(>pdev->dev, scp->sense_buffer, 16,
> +  DMA_FROM_DEVICE);
>  
>   cmndinfo->sense_paddr  = sense_paddr;
>  cmdp->OpCode   = GDT_WRITE; /* always */
> @@ -2693,9 +2689,9 @@ static int gdth_fill_raw_cmd(gdth_ha_str *ha, struct 
> scsi_cmnd *scp, u8 b)
>  }
>  
>  if (scsi_bufflen(scp)) {
> -cmndinfo->dma_dir = PCI_DMA_BIDIRECTIONAL;
> -sgcnt = pci_map_sg(ha->pdev, scsi_sglist(scp), 
> scsi_sg_count(scp),
> -   cmndinfo->dma_dir);
> +cmndinfo->dma_dir = DMA_BIDIRECTIONAL;
> +sgcnt = dma_map_sg(>pdev->dev, scsi_sglist(scp),
> +scsi_sg_count(scp), cmndinfo->dma_dir);
>  if (mode64) {
>  struct scatterlist *sl;
>  
> @@ -3313,12 +3309,12 @@ static int gdth_sync_event(gdth_ha_str *ha, int 
> service, u8 index,
>  return 2;
>  }
>  if (scsi_bufflen(scp))
> -pci_unmap_sg(ha->pdev, scsi_sglist(scp), scsi_sg_count(scp),
> +dma_unmap_sg(>pdev->dev, scsi_sglist(scp), 
> scsi_sg_count(scp),
>   cmndinfo->dma_dir);
>  
>  if (cmndinfo->sense_paddr)
> -pci_unmap_page(ha->pdev, cmndinfo->sense_paddr, 16,
> -   
> PCI_DMA_FROMDEVICE);
> +dma_unmap_page(>pdev->dev, cmndinfo->sense_paddr, 16,
> +DMA_FROM_DEVICE);
>  
>  if (ha->status == S_OK) {
>  cmndinfo->status = S_OK;
> @@ -4251,8 +4247,8 @@ static int ioc_general(void __user *arg, char *cmnd)
>   if (gen.data_len + gen.sense_len == 0)
>   goto execute;
>  
> -buf = pci_alloc_consistent(ha->pdev, gen.data_len + gen.sense_len,
> - );
> +buf = dma_alloc_coherent(>pdev->dev, gen.data_len + 
> gen.sense_len,
> + , GFP_KERNEL);
>   if (!buf)
>   return -EFAULT;
>  
> @@ -4292,7 +4288,8 @@ static int ioc_general(void __user *arg, char *cmnd)
>  
>   rval = 0;
>  out_free_buf:
> - pci_free_consistent(ha->pdev, gen.data_len + gen.sense_len, buf, paddr);
> + dma_free_coherent(>pdev->dev, gen.data_len + gen.sense_len, buf,
> + paddr);
>   return 0;
>  }
>   
> @@ -4749,22 +4746,22 @@ static int __init gdth_isa_probe_one(u32 isa_bios)
>  
>   error = -ENOMEM;
>  
> - ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
> - _dma_handle);
> + ha->pscratch = dma_alloc_coherent(>pdev->dev, GDTH_SCRATCH,
> + _dma_handle, GFP_KERNEL);
>   if (!ha->pscratch)
>   goto out_dec_counters;
>   ha->scratch_phys = scratch_dma_handle;
>  
> - ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
> - _dma_handle);
> + ha->pmsg = dma_alloc_coherent(>pdev->dev, 

Re: [PATCH 2/4] gdth: reuse dma coherent allocation in gdth_show_info

2018-10-18 Thread Finn Thain
On Thu, 18 Oct 2018, Christoph Hellwig wrote:

> gdth_show_info currently allocs and frees a dma buffer four times,
> which isn't very efficient. Reuse a single allocation instead.
> 
> Signed-off-by: Christoph Hellwig 
> ---
>  drivers/scsi/gdth_proc.c | 18 +-
>  1 file changed, 5 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/scsi/gdth_proc.c b/drivers/scsi/gdth_proc.c
> index 3a9751a80225..63d851398e38 100644
> --- a/drivers/scsi/gdth_proc.c
> +++ b/drivers/scsi/gdth_proc.c
> @@ -226,11 +226,13 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
> *host)
>  #endif
>  
>  if (ha->more_proc) {
> +size_t size = max(GDTH_SCRATCH, sizeof(gdth_hget_str));
> +
>  /* more information: 2. about physical devices */
>  seq_puts(m, "\nPhysical Devices:");
>  flag = FALSE;
>  
> -buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, );
> +buf = gdth_ioctl_alloc(ha, size, FALSE, );
>  if (!buf) 
>  goto stop_output;
>  for (i = 0; i < ha->bus_cnt; ++i) {
> @@ -323,7 +325,6 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
> *host)
>  }
>  }
>  }
> -gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
>  
>  if (!flag)
>  seq_puts(m, "\n --\n");
> @@ -332,7 +333,6 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
> *host)
>  seq_puts(m, "\nLogical Drives:");
>  flag = FALSE;
>  
> -buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, );
>  if (!buf) 
>  goto stop_output;

I think this !buf test is redundant.

-- 

>  for (i = 0; i < MAX_LDRIVES; ++i) {
> @@ -408,7 +408,6 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
> *host)
>  seq_printf(m,
> " To Array Drv.:\t%s\n", hrec);
>  }   
> -gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
>  
>  if (!flag)
>  seq_puts(m, "\n --\n");
> @@ -417,9 +416,6 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
> *host)
>  seq_puts(m, "\nArray Drives:");
>  flag = FALSE;
>  
> -buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, );
> -if (!buf) 
> -goto stop_output;
>  for (i = 0; i < MAX_LDRIVES; ++i) {
>  if (!(ha->hdr[i].is_arraydrv && ha->hdr[i].is_master))
>  continue;
> @@ -468,8 +464,7 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
> *host)
> hrec);
>  }
>  }
> -gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
> -
> +
>  if (!flag)
>  seq_puts(m, "\n --\n");
>  
> @@ -477,9 +472,6 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
> *host)
>  seq_puts(m, "\nHost Drives:");
>  flag = FALSE;
>  
> -buf = gdth_ioctl_alloc(ha, sizeof(gdth_hget_str), FALSE, );
> -if (!buf) 
> -goto stop_output;
>  for (i = 0; i < MAX_LDRIVES; ++i) {
>  if (!ha->hdr[i].is_logdrv || 
>  (ha->hdr[i].is_arraydrv && !ha->hdr[i].is_master))
> @@ -510,7 +502,7 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
> *host)
>  }
>  }
>  }
> -gdth_ioctl_free(ha, sizeof(gdth_hget_str), buf, paddr);
> +gdth_ioctl_free(ha, size, buf, paddr);
>  
>  for (i = 0; i < MAX_HDRIVES; ++i) {
>  if (!(ha->hdr[i].present))
> 


Re: [PATCH RESEND] scsi: qla2xxx: I/Os timing out on surprise removal of

2018-10-18 Thread Madhani, Himanshu
Martin, Bill, 

> On Oct 17, 2018, at 5:51 PM, Martin K. Petersen  
> wrote:
> 
> External Email
> 
> Himanshu,
> 
>> When doing a surprise removal of an adapter, some in flight I/Os can get
>> stuck and take a while to complete (they actually timeout and are
>> retried). We are not handling an early error exit from
>> qla2xxx_eh_abort properly.
>> 
>> Fixes: 45235022da99 ("scsi: qla2xxx: Fix driver unload by shutting down 
>> chip")
>> Signed-off-by: Bill Kuzeja 
> 
> Please review. Thanks!
> 
> --
> Martin K. Petersen  Oracle Linux Engineering

Thanks for the patience. 

This patch Looks good to me

Acked-by: Himanshu Madhani 

Thanks,
- Himanshu



Re: SCSI qla2xxx: tcm_qla2xxx target server code regession

2018-10-18 Thread Laurence Oberman
On Wed, 2018-10-17 at 16:42 -0400, Laurence Oberman wrote:
> On Mon, 2018-10-15 at 08:51 -0400, Laurence Oberman wrote:
> > On Sat, 2018-10-13 at 10:42 -0400, Laurence Oberman wrote:
> > > On Fri, 2018-10-12 at 17:51 -0700, Bart Van Assche wrote:
> > > > On 10/12/18 1:36 PM, Laurence Oberman wrote:
> > > >  > While I have for the longest time used 4.5 as a base for my
> > > > F/C
> > > > jammer
> > > >  > that I use every day here in our lab I recently added more
> > > > jammer
> > > > code
> > > >  > so I decided to test this all on latest upstream.
> > > >  >
> > > >  > Booting the target server on my 4.5 kernel with jammer code
> > > > is
> > > >  > flawless and serves LUNS with no issues and handles the
> > > > jamming
> > > > also
> > > >  > fine.
> > > >  >
> > > >  > However just building a 4.19.0_rc7+-1 (I left the jammer
> > > > stuff
> > > > out)
> > > >  > its pretty broken.
> > > > 
> > > > A large number of patches went upstream between these two
> > > > kernel 
> > > > versions for both the QLogic initiator and target drivers. From
> > > > the
> > > > logs 
> > > > it seems like you were using QLogic hardware at both the
> > > > initiator
> > > > and 
> > > > target side? If so, which kernel version was running at the
> > > > initiator 
> > > > side during these tests? 4.5, 4.19-rc7+ or yet another version?
> > > > 
> > > > Thanks,
> > > > 
> > > > Bart.
> > > > 
> > > > 
> > > 
> > > I had only replied to Bart, this was my reply, reply all now
> > > 
> > > Hi Bart
> > > Thank you for always being helpful.
> > > 
> > > I am using at the moment RHEL 7.5 for the initiator (based on
> > > kernel
> > > 3.10 but of course lots of backports)
> > > The exact same initiator is working fine with the 4.5 and I would
> > > not
> > > expect the target to  require the same kernel level.
> > > Of course I will try latest upstream on the initiator later and
> > > reply
> > > back.
> > > 
> > > I was thinking the target should adhere to the standards and
> > > support
> > > many types of kernels within reason for the initiator.
> > > 
> > > Thanks
> > 
> > Changed the Subject to match regression
> > 
> > I tested the following:
> > Target 
> > upstream 4.19_rc4
> > 
> > Inititiator
> > qla2xxx RHEL7.5 
> > lpfc RHEL7.5
> > qla2xxx Upstream 4.19_rc4 matching initiatior
> > 
> > All 3 are unstable and fail, with tag errors and aborts
> > 
> > I am not sure when the issue started so will work on a bisect
> > 
> > Oct 15 07:29:52 ml150 kernel: print_req_error: I/O error, dev sdj,
> > sector 128
> > Oct 15 07:29:52 ml150 kernel: print_req_error: I/O error, dev sds,
> > sector 16
> > ..
> > ..
> > Oct 15 07:30:11 ml150 kernel: sd 5:0:0:0: [sdi] tag#0 FAILED
> > Result:
> > hostbyte=DID_ERROR driverbyte=DRIVER_OK
> > Oct 15 07:30:11 ml150 kernel: sd 5:0:0:0: [sdi] tag#0 CDB: Read(10)
> > 28
> > 00 00 00 03 00 00 01 00 00
> > Oct 15 07:30:16 ml150 kernel: sd 5:0:0:0: [sdi] tag#1 FAILED
> > Result:
> > hostbyte=DID_ERROR driverbyte=DRIVER_OK
> > Oct 15 07:30:16 ml150 kernel: sd 5:0:0:0: [sdi] tag#1 CDB: Read(10)
> > 28
> > 00 00 00 00 40 00 00 38 00
> > Oct 15 07:30:17 ml150 kernel: sd 5:0:1:0: [sdp] tag#0 FAILED
> > Result: 
> 
> Following up here
> 
> I started with 4.9 and it was stable
> 
> I then tested 4.10 and its immediately broken and logs these when
> restoring the target configuration.
> This is a different failure to the upstream latest which takes the
> configuration but fails the I/O servicing.
> 
> This is logged on the target when restoring the target configuration
> for 4.10
> 
> Perhaps in this case its a target config mismatch. I did not manually
> add targets on 4.10 but I can certainly try it.
> Note that 4.18 for example takes the config with no complaints so I
> doubt its a mismatch.
> 
> [   95.668210] qla2xxx [:07:00.0]-5030:0: Error entry - invalid
> handle/queue (1c01).
> [   95.706773] qla2xxx [:07:00.0]-5030:0: Error entry - invalid
> handle/queue (0002).
> [   95.745912] qla2xxx [:07:00.0]-5030:0: Error entry - invalid
> handle/queue (5838).
> 
> This comes from
> 
> /**
>  * qla2x00_error_entry() - Process an error entry.
>  * @ha: SCSI driver HA context
>  * @pkt: Entry pointer
>  */
> static void
> qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp,
> sts_entry_t *pkt)
> {
> srb_t *sp;
> struct qla_hw_data *ha = vha->hw;
> const char func[] = "ERROR-IOCB";
> uint16_t que = MSW(pkt->handle);
> struct req_que *req = NULL;
> int res = DID_ERROR << 16;
> 
> ql_dbg(ql_dbg_async, vha, 0x502a,
> "type of error status in response: 0x%x\n", pkt-
> > entry_status);
> 
> if (que >= ha->max_req_queues || !ha->req_q_map[que])
> goto fatal;
> 
> req = ha->req_q_map[que];
> 
> if (pkt->entry_status & RF_BUSY)
> res = DID_BUS_BUSY << 16;
> 
> if (pkt->entry_type == NOTIFY_ACK_TYPE &&
> pkt->handle == QLA_TGT_SKIP_HANDLE)
>  

Re: dma related cleanups for wd719x

2018-10-18 Thread Ondrej Zary
On Thursday 18 October 2018 15:01:14 Christoph Hellwig wrote:
> Hi Ondrej,
> 
> can you look over this series, which cleans up a few dma-related
> bits in the wd719x driver?
> 

Looks nice but does not work. The first patch works, but the 2nd one causes
hang on modprobe:
[  408.350359] wd719x :00:0c.0: RISC initialized with firmware version 03.10
[  408.949225] wd719x :00:0c.0: WD7193 at I/O 0xe800, IRQ 5, SCSI ID 7
[  408.954450] scsi host2: Western Digital 719x
[  409.263961] wd719x :00:0c.0: invalid SCSI phase
[  409.297203] wd719x :00:0c.0: invalid SCSI phase
[  409.325714] scsi 2:0:1:0: Direct-Access QUANTUM  LP240S GM240S01X 4.6  
PQ: 0 ANSI: 2 CCS
[  409.346106] wd719x :00:0c.0: invalid SCSI phase
[  409.380731] wd719x :00:0c.0: invalid SCSI phase
[  410.748579] sd 2:0:1:0: Attached scsi generic sg1 type 0


-- 
Ondrej Zary


Re: [scsi:misc 194/233] ERROR: "__aeabi_uldivmod" [drivers/scsi/myrs.ko] undefined!

2018-10-18 Thread James Bottomley
On Fri, 2018-10-19 at 01:18 +0800, kbuild test robot wrote:
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git
>  misc
> head:   4d5b4ac1eae471bcd0fa381ab4099cc33e94e15d
> commit: 77266186397c6c782a3f670d32808a9671806ec5 [194/233] scsi:
> myrs: Add Mylex RAID controller (SCSI interface)
> config: arm-allmodconfig (attached as .config)
> compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0
> reproduce:
> wget https://raw.githubusercontent.com/intel/lkp-tests/master
> /sbin/make.cross -O ~/bin/make.cross
> chmod +x ~/bin/make.cross
> git checkout 77266186397c6c782a3f670d32808a9671806ec5
> # save the attached .config to linux build tree
> GCC_VERSION=7.2.0 make.cross ARCH=arm 
> 
> All errors (new ones prefixed by >>):
> 
> > > ERROR: "__aeabi_uldivmod" [drivers/scsi/myrs.ko] undefined!

I think this is the fix, can someone with an arm build check?

Thanks,

James

---

diff --git a/drivers/scsi/myrs.c b/drivers/scsi/myrs.c
index b02ee0b0dd55..6bf3cb416505 100644
--- a/drivers/scsi/myrs.c
+++ b/drivers/scsi/myrs.c
@@ -1986,8 +1986,8 @@ myrs_get_resync(struct device *dev)
unsigned short ldev_num = ldev_info->ldev_num;
 
status = myrs_get_ldev_info(cs, ldev_num, ldev_info);
-   percent_complete = ldev_info->rbld_lba * 100 /
-   ldev_info->cfg_devsize;
+   percent_complete = do_div(ldev_info->rbld_lba * 100,
+ ldev_info->cfg_devsize);
}
raid_set_resync(myrs_raid_template, dev, percent_complete);
 }


Re: [PATCH v2 3/7] drivers/base: Probe devices concurrently if requested by the driver

2018-10-18 Thread Alexander Duyck




On 10/18/2018 10:15 AM, Greg KH wrote:

On Thu, Oct 18, 2018 at 09:51:03AM -0700, Alexander Duyck wrote:

On 10/18/2018 9:46 AM, Bart Van Assche wrote:

On Thu, 2018-10-18 at 08:25 -0700, Alexander Duyck wrote:

On 10/17/2018 5:54 PM, Dan Williams wrote:

On Wed, Oct 17, 2018 at 4:41 PM Bart Van Assche  wrote:


Instead of probing devices sequentially in the PROBE_PREFER_ASYNCHRONOUS
mode, scan devices concurrently. This helps when the wall clock time for
a single probe is significantly above the CPU time needed for a single
probe, e.g. when scanning SCSI LUNs over a storage network.


Alex had a similar patch here [1] that I don't think has been accepted
yet, in any event some collaboration is needed:

[1]: https://lkml.org/lkml/2018/9/27/14


The patch set referenced is a little out of date. The latest set is:
https://lore.kernel.org/lkml/20181015150305.29520.86363.stgit@localhost.localdomain/

I'm also not quite sure what the point of this patch is. I don't think
it is doing what it says it is doing. From what I can tell it is just
allowing the driver init code to ignore if the driver wants to be probed
asynchronously or not. Further comments inline below.


Hi Alexander,

Thanks for the pointer to the latest version of your patch series. I was not
yet aware of your work when I posted this patch series. Now that I have had a
look at your patch series I like your approach better than what I did in this
patch. Since it could take a while before agreement is reached about the async
domain patches in the same patch series, how about you submitting patches 3/6
and 4/6 from your patch series to Greg for kernel version v4.20? If I drop
the driver core patches from my patch series and replace these with your
driver core patches I achieve the same results. If you Cc me when you resubmit
these patches I will review them.

Thanks,

Bart.


Actually the async and workqueue patches have already been reviewed and last
I knew they were okay with the workqueue guys. These patches are already
submitted to Greg for 4.20.


It's too late for 4.20 now, sorry.  They will have to wait.  Given that
4.19-final could have come out last weekend, this shouldn't be a
supprise.

They are in my review queue and I'll get to them after 4.20-rc1 is out.

thanks,

greg k-h


Well I was hoping for 4.20 anyway. :-/

Thanks for letting me know.

- Alex


[scsi:misc 194/233] ERROR: "__aeabi_uldivmod" [drivers/scsi/myrs.ko] undefined!

2018-10-18 Thread kbuild test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git misc
head:   4d5b4ac1eae471bcd0fa381ab4099cc33e94e15d
commit: 77266186397c6c782a3f670d32808a9671806ec5 [194/233] scsi: myrs: Add 
Mylex RAID controller (SCSI interface)
config: arm-allmodconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
git checkout 77266186397c6c782a3f670d32808a9671806ec5
# save the attached .config to linux build tree
GCC_VERSION=7.2.0 make.cross ARCH=arm 

All errors (new ones prefixed by >>):

>> ERROR: "__aeabi_uldivmod" [drivers/scsi/myrs.ko] undefined!

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


Re: [PATCH v2 3/7] drivers/base: Probe devices concurrently if requested by the driver

2018-10-18 Thread Greg KH
On Thu, Oct 18, 2018 at 09:51:03AM -0700, Alexander Duyck wrote:
> On 10/18/2018 9:46 AM, Bart Van Assche wrote:
> > On Thu, 2018-10-18 at 08:25 -0700, Alexander Duyck wrote:
> > > On 10/17/2018 5:54 PM, Dan Williams wrote:
> > > > On Wed, Oct 17, 2018 at 4:41 PM Bart Van Assche  
> > > > wrote:
> > > > > 
> > > > > Instead of probing devices sequentially in the 
> > > > > PROBE_PREFER_ASYNCHRONOUS
> > > > > mode, scan devices concurrently. This helps when the wall clock time 
> > > > > for
> > > > > a single probe is significantly above the CPU time needed for a single
> > > > > probe, e.g. when scanning SCSI LUNs over a storage network.
> > > > 
> > > > Alex had a similar patch here [1] that I don't think has been accepted
> > > > yet, in any event some collaboration is needed:
> > > > 
> > > > [1]: https://lkml.org/lkml/2018/9/27/14
> > > 
> > > The patch set referenced is a little out of date. The latest set is:
> > > https://lore.kernel.org/lkml/20181015150305.29520.86363.stgit@localhost.localdomain/
> > > 
> > > I'm also not quite sure what the point of this patch is. I don't think
> > > it is doing what it says it is doing. From what I can tell it is just
> > > allowing the driver init code to ignore if the driver wants to be probed
> > > asynchronously or not. Further comments inline below.
> > 
> > Hi Alexander,
> > 
> > Thanks for the pointer to the latest version of your patch series. I was not
> > yet aware of your work when I posted this patch series. Now that I have had 
> > a
> > look at your patch series I like your approach better than what I did in 
> > this
> > patch. Since it could take a while before agreement is reached about the 
> > async
> > domain patches in the same patch series, how about you submitting patches 
> > 3/6
> > and 4/6 from your patch series to Greg for kernel version v4.20? If I drop
> > the driver core patches from my patch series and replace these with your
> > driver core patches I achieve the same results. If you Cc me when you 
> > resubmit
> > these patches I will review them.
> > 
> > Thanks,
> > 
> > Bart.
> 
> Actually the async and workqueue patches have already been reviewed and last
> I knew they were okay with the workqueue guys. These patches are already
> submitted to Greg for 4.20.

It's too late for 4.20 now, sorry.  They will have to wait.  Given that
4.19-final could have come out last weekend, this shouldn't be a
supprise.

They are in my review queue and I'll get to them after 4.20-rc1 is out.

thanks,

greg k-h


Re: [PATCH v2 3/7] drivers/base: Probe devices concurrently if requested by the driver

2018-10-18 Thread Alexander Duyck

On 10/18/2018 9:46 AM, Bart Van Assche wrote:

On Thu, 2018-10-18 at 08:25 -0700, Alexander Duyck wrote:

On 10/17/2018 5:54 PM, Dan Williams wrote:

On Wed, Oct 17, 2018 at 4:41 PM Bart Van Assche  wrote:


Instead of probing devices sequentially in the PROBE_PREFER_ASYNCHRONOUS
mode, scan devices concurrently. This helps when the wall clock time for
a single probe is significantly above the CPU time needed for a single
probe, e.g. when scanning SCSI LUNs over a storage network.


Alex had a similar patch here [1] that I don't think has been accepted
yet, in any event some collaboration is needed:

[1]: https://lkml.org/lkml/2018/9/27/14


The patch set referenced is a little out of date. The latest set is:
https://lore.kernel.org/lkml/20181015150305.29520.86363.stgit@localhost.localdomain/

I'm also not quite sure what the point of this patch is. I don't think
it is doing what it says it is doing. From what I can tell it is just
allowing the driver init code to ignore if the driver wants to be probed
asynchronously or not. Further comments inline below.


Hi Alexander,

Thanks for the pointer to the latest version of your patch series. I was not
yet aware of your work when I posted this patch series. Now that I have had a
look at your patch series I like your approach better than what I did in this
patch. Since it could take a while before agreement is reached about the async
domain patches in the same patch series, how about you submitting patches 3/6
and 4/6 from your patch series to Greg for kernel version v4.20? If I drop
the driver core patches from my patch series and replace these with your
driver core patches I achieve the same results. If you Cc me when you resubmit
these patches I will review them.

Thanks,

Bart.


Actually the async and workqueue patches have already been reviewed and 
last I knew they were okay with the workqueue guys. These patches are 
already submitted to Greg for 4.20.


The only bits that I had left were the patches for driver-core and I am 
already working those through with Rafael Wysocki and Greg KH in terms 
of addressing their review comments.


Thanks.

- Alex


Re: [PATCH v2 1/7] drivers/base: Fix a race condition in the device probing code

2018-10-18 Thread Bart Van Assche
On Thu, 2018-10-18 at 07:10 +0200, Greg Kroah-Hartman wrote:
> > diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> > index edfc9f0b1180..b4212154a94b 100644
> > --- a/drivers/base/dd.c
> > +++ b/drivers/base/dd.c
> > @@ -645,6 +645,14 @@ int driver_probe_device(struct device_driver *drv, 
> > struct device *dev)
> >  {
> > int ret = 0;
> >  
> > +   /*
> > +* Several callers check the driver pointer without holding the
> > +* device mutex. Hence check the driver pointer again while holding
> > +* the device mutex.
> > +*/
> > +   if (dev->driver)
> > +   return dev->driver == drv;
> 
> I do not understand, who is calling probe twice?  What is the sequence
> of events that is causing that error message being printed out?  Wh is
> not grabbing the mutex properly?

Hi Greg,

If I drop patch 3/7 from my patch series and use Alexander Duyck's patches
instead I don't need this patch anymore. So I don't think we have to spend
more time on this patch.

Thanks,

Bart.



Re: [PATCH v2 3/7] drivers/base: Probe devices concurrently if requested by the driver

2018-10-18 Thread Bart Van Assche
On Thu, 2018-10-18 at 08:25 -0700, Alexander Duyck wrote:
> On 10/17/2018 5:54 PM, Dan Williams wrote:
> > On Wed, Oct 17, 2018 at 4:41 PM Bart Van Assche  wrote:
> > > 
> > > Instead of probing devices sequentially in the PROBE_PREFER_ASYNCHRONOUS
> > > mode, scan devices concurrently. This helps when the wall clock time for
> > > a single probe is significantly above the CPU time needed for a single
> > > probe, e.g. when scanning SCSI LUNs over a storage network.
> > 
> > Alex had a similar patch here [1] that I don't think has been accepted
> > yet, in any event some collaboration is needed:
> > 
> > [1]: https://lkml.org/lkml/2018/9/27/14
> 
> The patch set referenced is a little out of date. The latest set is:
> https://lore.kernel.org/lkml/20181015150305.29520.86363.stgit@localhost.localdomain/
> 
> I'm also not quite sure what the point of this patch is. I don't think 
> it is doing what it says it is doing. From what I can tell it is just 
> allowing the driver init code to ignore if the driver wants to be probed 
> asynchronously or not. Further comments inline below.

Hi Alexander,

Thanks for the pointer to the latest version of your patch series. I was not
yet aware of your work when I posted this patch series. Now that I have had a
look at your patch series I like your approach better than what I did in this
patch. Since it could take a while before agreement is reached about the async
domain patches in the same patch series, how about you submitting patches 3/6
and 4/6 from your patch series to Greg for kernel version v4.20? If I drop
the driver core patches from my patch series and replace these with your
driver core patches I achieve the same results. If you Cc me when you resubmit
these patches I will review them.

Thanks,

Bart.



[scsi:misc 194/233] ERROR: "__udivdi3" [drivers/scsi/myrs.ko] undefined!

2018-10-18 Thread kbuild test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git misc
head:   4d5b4ac1eae471bcd0fa381ab4099cc33e94e15d
commit: 77266186397c6c782a3f670d32808a9671806ec5 [194/233] scsi: myrs: Add 
Mylex RAID controller (SCSI interface)
config: i386-allmodconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
git checkout 77266186397c6c782a3f670d32808a9671806ec5
# save the attached .config to linux build tree
make ARCH=i386 

All errors (new ones prefixed by >>):

>> ERROR: "__udivdi3" [drivers/scsi/myrs.ko] undefined!

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


Re: [PATCH v2 2/7] drivers/base: Verify struct device locking requirements at runtime

2018-10-18 Thread Bart Van Assche
On Thu, 2018-10-18 at 07:11 +0200, Greg Kroah-Hartman wrote:
> On Wed, Oct 17, 2018 at 04:40:01PM -0700, Bart Van Assche wrote:
> > Make sure that a complaint appears in the kernel log if the driver core
> > locking assumptions are violated.
> > 
> > Cc: Lee Duncan 
> > Cc: Hannes Reinecke 
> > Cc: Luis Chamberlain 
> > Cc: Johannes Thumshirn 
> > Cc: Christoph Hellwig 
> > Cc: Greg Kroah-Hartman 
> > Signed-off-by: Bart Van Assche 
> > ---
> >  drivers/base/dd.c | 16 
> >  drivers/base/memory.c |  4 
> >  2 files changed, 20 insertions(+)
> > 
> > diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> > index b4212154a94b..033382421351 100644
> > --- a/drivers/base/dd.c
> > +++ b/drivers/base/dd.c
> > @@ -315,11 +315,15 @@ __exitcall(deferred_probe_exit);
> >   */
> >  bool device_is_bound(struct device *dev)
> >  {
> > +   lockdep_assert_held(>mutex);
> 
> With this patch applied, are you seeing lockdep messages anywhere?

No lockdep complaints appeared in my tests with this patch applied. I have
checked whether all callers of the modified functions hold dev->mutex. This
patch is most useful to check new callers of the modified functions. I came
up with this patch to verify the new code I added myself in the drivers/base
directory.

Bart.


Re: [PATCH v2 3/7] drivers/base: Probe devices concurrently if requested by the driver

2018-10-18 Thread Alexander Duyck

On 10/17/2018 5:54 PM, Dan Williams wrote:

On Wed, Oct 17, 2018 at 4:41 PM Bart Van Assche  wrote:


Instead of probing devices sequentially in the PROBE_PREFER_ASYNCHRONOUS
mode, scan devices concurrently. This helps when the wall clock time for
a single probe is significantly above the CPU time needed for a single
probe, e.g. when scanning SCSI LUNs over a storage network.


Alex had a similar patch here [1] that I don't think has been accepted
yet, in any event some collaboration is needed:

[1]: https://lkml.org/lkml/2018/9/27/14


The patch set referenced is a little out of date. The latest set is:
https://lore.kernel.org/lkml/20181015150305.29520.86363.stgit@localhost.localdomain/

I'm also not quite sure what the point of this patch is. I don't think 
it is doing what it says it is doing. From what I can tell it is just 
allowing the driver init code to ignore if the driver wants to be probed 
asynchronously or not. Further comments inline below.






Cc: Lee Duncan 
Cc: Hannes Reinecke 
Cc: Luis Chamberlain 
Cc: Johannes Thumshirn 
Cc: Christoph Hellwig 
Cc: Greg Kroah-Hartman 
Cc: Dan Williams 
Signed-off-by: Bart Van Assche 
---
  drivers/base/bus.c |  3 +--
  drivers/base/dd.c  | 49 ++
  2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 8bfd27ec73d6..18ca1178821f 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -696,8 +696,7 @@ int bus_add_driver(struct device_driver *drv)

  out_unregister:
 kobject_put(>kobj);
-   /* drv->p is freed in driver_release()  */
-   drv->p = NULL;
+
  out_put_bus:
 bus_put(bus);
 return error;
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 033382421351..f8d645aa09be 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -27,6 +27,7 @@
  #include 
  #include 
  #include 
+#include 

  #include "base.h"
  #include "power/power.h"
@@ -691,6 +692,49 @@ int driver_probe_device(struct device_driver *drv, struct 
device *dev)
 return ret;
  }

+struct driver_and_dev {
+   struct device_driver*drv;
+   struct device   *dev;
+};
+
+static void __driver_probe_device_async(void *data, async_cookie_t cookie)
+{
+   struct driver_and_dev *dd = data;
+   struct device_driver *drv = dd->drv;
+   struct device *dev = dd->dev;
+
+   device_lock(dev);
+   driver_probe_device(drv, dev);
+   device_unlock(dev);
+   kobject_put(>p->kobj);
+   module_put(drv->owner);
+   kfree(dd);
+}
+
+static void driver_probe_device_async(struct device_driver *drv,
+ struct device *dev)
+{
+   struct driver_and_dev *dd;
+
+   if (!try_module_get(drv->owner))
+   return;
+   dd = kmalloc(sizeof(*dd), GFP_KERNEL);
+   if (!dd) {
+   /* If out of memory, scan synchronously. */
+   device_lock(dev);
+   driver_probe_device(drv, dev);
+   device_unlock(dev);
+   module_put(drv->owner);
+   return;
+   }
+   *dd = (struct driver_and_dev){
+   .drv = drv,
+   .dev = dev,
+   };
+   kobject_get(>p->kobj);
+   async_schedule(__driver_probe_device_async, dd);
+}
+


So this piece is similar to what I had, but the functionality is being 
used in a completely different spot. I'm not entirely convinced this 
isn't redundant.



  bool driver_allows_async_probing(struct device_driver *drv)
  {
 switch (drv->probe_type) {
@@ -777,6 +821,11 @@ static int __device_attach_driver(struct device_driver 
*drv, void *_data)
 if (data->check_async && async_allowed != data->want_async)
 return 0;

+   if (data->check_async) {
+   driver_probe_device_async(drv, dev);
+   return 0;
+   }
+


So this code path assumes the driver is already loaded before the device 
is added, and from what I can tell it looks like it is forcing 
everything to asynchronously probe isn't it? Wasn't that the purpose of 
the async_allowed != data->want_async check?


Also this seems redundant since the return 0 case here is supposed to 
have us attach the device asynchronously. So it seems like we are just 
adding another layer of aysnc init. It seems like the most direct way of 
doing this would be to just force data->want_async to always be true by 
passing that instead of false in device_attach?



 return driver_probe_device(drv, dev);
  }

--
2.19.1.568.g152ad8e336-goog



Re: [PATCH 05/12] hisi_sas: use dma_set_mask_and_coherent

2018-10-18 Thread John Garry

On 18/10/2018 14:10, Christoph Hellwig wrote:

The driver currently uses pci_set_dma_mask despite otherwise using
the generic DMA API.  Switch it over to the better generic DMA API.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c 
b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
index bd4ce38b98d2..73bf45e52a0a 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
@@ -2201,14 +2201,11 @@ hisi_sas_v3_probe(struct pci_dev *pdev, const struct 
pci_device_id *id)
if (rc)
goto err_out_disable_device;

-   if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) ||
-   (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)) {
-   if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) ||
-  (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)) {
-   dev_err(dev, "No usable DMA addressing method\n");
-   rc = -EIO;
-   goto err_out_regions;
-   }
+   if (dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(64)) ||
+   dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(32))) {
+   dev_err(dev, "No usable DMA addressing method\n");
+   rc = -EIO;
+   goto err_out_regions;
}



We already do the same thing as your change for the platform driver 
probe, here:
static struct Scsi_Host *hisi_sas_shost_alloc(struct platform_device 
*pdev, ...)

{
struct resource *res;
struct Scsi_Host *shost;
struct hisi_hba *hisi_hba;
struct device *dev = >dev;
...

if (hisi_sas_get_fw_info(hisi_hba) < 0)
goto err_out;

if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) &&
dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32))) {
dev_err(dev, "No usable DMA addressing method\n");
goto err_out;
}

...
}

So I could make a common helper function in the driver to factor this 
out, but prob not worth it. Having said that, I think lots of drivers 
have this same pattern...


Acked-by: John Garry 


shost = hisi_sas_shost_alloc_pci(pdev);






use dma_set_mask and dma_set_mask_and_coherent

2018-10-18 Thread Christoph Hellwig
Various SCSI drivers that otherwise use the generic DMA API
still use pci_set_dma_mask, so switch them over to dma_set_mask
and dma_set_mask_and_coherent.


[PATCH 03/12] dpt_i2o: use dma_set_mask

2018-10-18 Thread Christoph Hellwig
The driver currently uses pci_set_dma_mask despite otherwise using
the generic DMA API.  Also move the dma_get_required_mask check
before actually setting the dma mask, so that we don't end up with
inconsistent settings in corner cases.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/dpt_i2o.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
index 37de8fb186d7..d5a474d1434f 100644
--- a/drivers/scsi/dpt_i2o.c
+++ b/drivers/scsi/dpt_i2o.c
@@ -934,15 +934,15 @@ static int adpt_install_hba(struct scsi_host_template* 
sht, struct pci_dev* pDev
 *  See if we should enable dma64 mode.
 */
if (sizeof(dma_addr_t) > 4 &&
-   pci_set_dma_mask(pDev, DMA_BIT_MASK(64)) == 0) {
-   if (dma_get_required_mask(>dev) > DMA_BIT_MASK(32))
-   dma64 = 1;
-   }
-   if (!dma64 && pci_set_dma_mask(pDev, DMA_BIT_MASK(32)) != 0)
+   dma_get_required_mask(>dev) > DMA_BIT_MASK(32) &&
+   dma_set_mask(>dev, DMA_BIT_MASK(64)) == 0)
+   dma64 = 1;
+
+   if (!dma64 && dma_set_mask(>dev, DMA_BIT_MASK(32)) != 0)
return -EINVAL;
 
/* adapter only supports message blocks below 4GB */
-   pci_set_consistent_dma_mask(pDev, DMA_BIT_MASK(32));
+   dma_set_coherent_mask(>dev, DMA_BIT_MASK(32));
 
base_addr0_phys = pci_resource_start(pDev,0);
hba_map0_area_size = pci_resource_len(pDev,0);
-- 
2.19.1



[PATCH 12/12] sym53c8xx: use dma_set_mask

2018-10-18 Thread Christoph Hellwig
The driver currently uses pci_set_dma_mask despite otherwise using
the generic DMA API.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/sym53c8xx_2/sym_glue.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c 
b/drivers/scsi/sym53c8xx_2/sym_glue.c
index 5f10aa9bad9b..6e9b54061d7e 100644
--- a/drivers/scsi/sym53c8xx_2/sym_glue.c
+++ b/drivers/scsi/sym53c8xx_2/sym_glue.c
@@ -1312,9 +1312,9 @@ static struct Scsi_Host *sym_attach(struct 
scsi_host_template *tpnt, int unit,
sprintf(np->s.inst_name, "sym%d", np->s.unit);
 
if ((SYM_CONF_DMA_ADDRESSING_MODE > 0) && (np->features & FE_DAC) &&
-   !pci_set_dma_mask(pdev, DMA_DAC_MASK)) {
+   !dma_set_mask(>dev, DMA_DAC_MASK)) {
set_dac(np);
-   } else if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
+   } else if (dma_set_mask(>dev, DMA_BIT_MASK(32))) {
printf_warning("%s: No suitable DMA available\n", sym_name(np));
goto attach_failed;
}
-- 
2.19.1



[PATCH 01/12] arcmsr: use dma_set_mask

2018-10-18 Thread Christoph Hellwig
The driver currently uses pci_set_dma_mask despite otherwise using
the generic DMA API.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/arcmsr/arcmsr_hba.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index d4404eea24fb..11e8e6df50b1 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -903,9 +903,9 @@ static int arcmsr_probe(struct pci_dev *pdev, const struct 
pci_device_id *id)
if(!host){
goto pci_disable_dev;
}
-   error = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
+   error = dma_set_mask(>dev, DMA_BIT_MASK(64));
if(error){
-   error = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
+   error = dma_set_mask(>dev, DMA_BIT_MASK(32));
if(error){
printk(KERN_WARNING
   "scsi%d: No suitable DMA mask available\n",
@@ -1049,9 +1049,9 @@ static int arcmsr_resume(struct pci_dev *pdev)
pr_warn("%s: pci_enable_device error\n", __func__);
return -ENODEV;
}
-   error = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
+   error = dma_set_mask(>dev, DMA_BIT_MASK(64));
if (error) {
-   error = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
+   error = dma_set_mask(>dev, DMA_BIT_MASK(32));
if (error) {
pr_warn("scsi%d: No suitable DMA mask available\n",
   host->host_no);
-- 
2.19.1



[PATCH 02/12] bfa: use dma_set_mask_and_coherent

2018-10-18 Thread Christoph Hellwig
The driver currently uses pci_set_dma_mask despite otherwise using
the generic DMA API.  Switch it over to the better generic DMA API
helper and also ensure we set the coherent mask as well in the resume
path.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/bfa/bfad.c | 18 +++---
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/drivers/scsi/bfa/bfad.c b/drivers/scsi/bfa/bfad.c
index bd7e6a6fc1f1..8ebaf0693098 100644
--- a/drivers/scsi/bfa/bfad.c
+++ b/drivers/scsi/bfa/bfad.c
@@ -739,14 +739,10 @@ bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad)
 
pci_set_master(pdev);
 
-
-   if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) ||
-   (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)) {
-   if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) ||
-  (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)) {
-   printk(KERN_ERR "pci_set_dma_mask fail %p\n", pdev);
-   goto out_release_region;
-   }
+   if (dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(64)) ||
+   dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(32))) {
+   printk(KERN_ERR "dma_set_mask_and_coherent fail %p\n", pdev);
+   goto out_release_region;
}
 
/* Enable PCIE Advanced Error Recovery (AER) if kernel supports */
@@ -1565,9 +1561,9 @@ bfad_pci_slot_reset(struct pci_dev *pdev)
pci_save_state(pdev);
pci_set_master(pdev);
 
-   if (pci_set_dma_mask(bfad->pcidev, DMA_BIT_MASK(64)) != 0)
-   if (pci_set_dma_mask(bfad->pcidev, DMA_BIT_MASK(32)) != 0)
-   goto out_disable_device;
+   if (dma_set_mask_and_coherent(>pcidev->dev, DMA_BIT_MASK(64)) ||
+   dma_set_mask_and_coherent(>pcidev->dev, DMA_BIT_MASK(32)))
+   goto out_disable_device;
 
pci_cleanup_aer_uncorrect_error_status(pdev);
 
-- 
2.19.1



[PATCH 11/12] stex: use dma_set_mask_and_coherent

2018-10-18 Thread Christoph Hellwig
The driver currently uses pci_set_dma_mask despite otherwise using
the generic DMA API.  Switch it over to the better generic DMA API.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/stex.c | 17 +++--
 1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c
index 9b20643ab49d..95f370ad05e0 100644
--- a/drivers/scsi/stex.c
+++ b/drivers/scsi/stex.c
@@ -1617,19 +1617,6 @@ static struct st_card_info stex_card_info[] = {
},
 };
 
-static int stex_set_dma_mask(struct pci_dev * pdev)
-{
-   int ret;
-
-   if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))
-   && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
-   return 0;
-   ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
-   if (!ret)
-   ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
-   return ret;
-}
-
 static int stex_request_irq(struct st_hba *hba)
 {
struct pci_dev *pdev = hba->pdev;
@@ -1710,7 +1697,9 @@ static int stex_probe(struct pci_dev *pdev, const struct 
pci_device_id *id)
goto out_release_regions;
}
 
-   err = stex_set_dma_mask(pdev);
+   err = dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(64));
+   if (err)
+   err = dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(32));
if (err) {
printk(KERN_ERR DRV_NAME "(%s): set dma mask failed\n",
pci_name(pdev));
-- 
2.19.1



[PATCH 10/12] mvumi: use dma_set_mask

2018-10-18 Thread Christoph Hellwig
The driver currently uses pci_set_dma_mask despite otherwise using
the generic DMA API.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/mvumi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 2458974d1af6..3d2d026d1ccf 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -2620,7 +2620,7 @@ static int __maybe_unused mvumi_resume(struct pci_dev 
*pdev)
}
 
ret = mvumi_pci_set_master(pdev);
-   ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
+   ret = dma_set_mask(>dev, DMA_BIT_MASK(32));
if (ret)
goto fail;
ret = pci_request_regions(mhba->pdev, MV_DRIVER_NAME);
-- 
2.19.1



[PATCH 05/12] hisi_sas: use dma_set_mask_and_coherent

2018-10-18 Thread Christoph Hellwig
The driver currently uses pci_set_dma_mask despite otherwise using
the generic DMA API.  Switch it over to the better generic DMA API.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c 
b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
index bd4ce38b98d2..73bf45e52a0a 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
@@ -2201,14 +2201,11 @@ hisi_sas_v3_probe(struct pci_dev *pdev, const struct 
pci_device_id *id)
if (rc)
goto err_out_disable_device;
 
-   if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) ||
-   (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)) {
-   if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) ||
-  (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)) {
-   dev_err(dev, "No usable DMA addressing method\n");
-   rc = -EIO;
-   goto err_out_regions;
-   }
+   if (dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(64)) ||
+   dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(32))) {
+   dev_err(dev, "No usable DMA addressing method\n");
+   rc = -EIO;
+   goto err_out_regions;
}
 
shost = hisi_sas_shost_alloc_pci(pdev);
-- 
2.19.1



[PATCH 08/12] iscsi: use dma_set_mask_and_coherent

2018-10-18 Thread Christoph Hellwig
The driver currently uses pci_set_dma_mask despite otherwise using
the generic DMA API.  Switch it over to the better generic DMA API.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/isci/init.c | 19 ---
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/drivers/scsi/isci/init.c b/drivers/scsi/isci/init.c
index 08c7b1e25fe4..d72edbcbb7c6 100644
--- a/drivers/scsi/isci/init.c
+++ b/drivers/scsi/isci/init.c
@@ -304,21 +304,10 @@ static int isci_pci_init(struct pci_dev *pdev)
 
pci_set_master(pdev);
 
-   err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
-   if (err) {
-   err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
-   if (err)
-   return err;
-   }
-
-   err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
-   if (err) {
-   err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
-   if (err)
-   return err;
-   }
-
-   return 0;
+   err = dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(64));
+   if (err)
+   err = dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(32));
+   return err;
 }
 
 static int num_controllers(struct pci_dev *pdev)
-- 
2.19.1



[PATCH 06/12] hptiop: use dma_set_mask

2018-10-18 Thread Christoph Hellwig
The driver currently uses pci_set_dma_mask despite otherwise using
the generic DMA API.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/hptiop.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/hptiop.c b/drivers/scsi/hptiop.c
index 2fad7f03aa02..dc52b37a0df8 100644
--- a/drivers/scsi/hptiop.c
+++ b/drivers/scsi/hptiop.c
@@ -1309,11 +1309,11 @@ static int hptiop_probe(struct pci_dev *pcidev, const 
struct pci_device_id *id)
 
/* Enable 64bit DMA if possible */
iop_ops = (struct hptiop_adapter_ops *)id->driver_data;
-   if (pci_set_dma_mask(pcidev, DMA_BIT_MASK(iop_ops->hw_dma_bit_mask))) {
-   if (pci_set_dma_mask(pcidev, DMA_BIT_MASK(32))) {
-   printk(KERN_ERR "hptiop: fail to set dma_mask\n");
-   goto disable_pci_device;
-   }
+   if (dma_set_mask(>dev,
+DMA_BIT_MASK(iop_ops->hw_dma_bit_mask)) ||
+   dma_set_mask(>dev, DMA_BIT_MASK(32))) {
+   printk(KERN_ERR "hptiop: fail to set dma_mask\n");
+   goto disable_pci_device;
}
 
if (pci_request_regions(pcidev, driver_name)) {
-- 
2.19.1



[PATCH 04/12] esas2r: use dma_set_mask_and_coherent

2018-10-18 Thread Christoph Hellwig
The driver currently uses pci_set_dma_mask despite otherwise using
the generic DMA API.  Also move the dma_get_required_mask check
before actually setting the dma mask, so that we don't end up with
inconsistent settings in corner cases.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/esas2r/esas2r_init.c | 49 +--
 1 file changed, 14 insertions(+), 35 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r_init.c 
b/drivers/scsi/esas2r/esas2r_init.c
index bbe77db8938d..46b2c83ba21f 100644
--- a/drivers/scsi/esas2r/esas2r_init.c
+++ b/drivers/scsi/esas2r/esas2r_init.c
@@ -266,6 +266,7 @@ int esas2r_init_adapter(struct Scsi_Host *host, struct 
pci_dev *pcid,
int i;
void *next_uncached;
struct esas2r_request *first_request, *last_request;
+   bool dma64 = false;
 
if (index >= MAX_ADAPTERS) {
esas2r_log(ESAS2R_LOG_CRIT,
@@ -286,42 +287,20 @@ int esas2r_init_adapter(struct Scsi_Host *host, struct 
pci_dev *pcid,
a->pcid = pcid;
a->host = host;
 
-   if (sizeof(dma_addr_t) > 4) {
-   const uint64_t required_mask = dma_get_required_mask
-  (>dev);
-   if (required_mask > DMA_BIT_MASK(32)
-   && !pci_set_dma_mask(pcid, DMA_BIT_MASK(64))
-   && !pci_set_consistent_dma_mask(pcid,
-   DMA_BIT_MASK(64))) {
-   esas2r_log_dev(ESAS2R_LOG_INFO,
-  &(a->pcid->dev),
-  "64-bit PCI addressing enabled\n");
-   } else if (!pci_set_dma_mask(pcid, DMA_BIT_MASK(32))
-  && !pci_set_consistent_dma_mask(pcid,
-  DMA_BIT_MASK(32))) {
-   esas2r_log_dev(ESAS2R_LOG_INFO,
-  &(a->pcid->dev),
-  "32-bit PCI addressing enabled\n");
-   } else {
-   esas2r_log(ESAS2R_LOG_CRIT,
-  "failed to set DMA mask");
-   esas2r_kill_adapter(index);
-   return 0;
-   }
-   } else {
-   if (!pci_set_dma_mask(pcid, DMA_BIT_MASK(32))
-   && !pci_set_consistent_dma_mask(pcid,
-   DMA_BIT_MASK(32))) {
-   esas2r_log_dev(ESAS2R_LOG_INFO,
-  &(a->pcid->dev),
-  "32-bit PCI addressing enabled\n");
-   } else {
-   esas2r_log(ESAS2R_LOG_CRIT,
-  "failed to set DMA mask");
-   esas2r_kill_adapter(index);
-   return 0;
-   }
+   if (sizeof(dma_addr_t) > 4 &&
+   dma_get_required_mask(>dev) > DMA_BIT_MASK(32) &&
+   !dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(64)))
+   dma64 = true;
+
+   if (!dma64 && dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(32))) {
+   esas2r_log(ESAS2R_LOG_CRIT, "failed to set DMA mask");
+   esas2r_kill_adapter(index);
+   return 0;
}
+
+   esas2r_log_dev(ESAS2R_LOG_INFO, >dev,
+  "%s-bit PCI addressing enabled\n", dma64 ? "64" : "32");
+
esas2r_adapters[index] = a;
sprintf(a->name, ESAS2R_DRVR_NAME "_%02d", index);
esas2r_debug("new adapter %p, name %s", a, a->name);
-- 
2.19.1



[PATCH 09/12] lpfc: use dma_set_mask_and_coherent

2018-10-18 Thread Christoph Hellwig
The driver currently uses pci_set_dma_mask despite otherwise using
the generic DMA API.  Switch it over to the better generic DMA API.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/lpfc/lpfc_init.c | 34 ++
 1 file changed, 10 insertions(+), 24 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 323a32e87258..21e4aaf55170 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -7177,26 +7177,19 @@ lpfc_post_init_setup(struct lpfc_hba *phba)
 static int
 lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
 {
-   struct pci_dev *pdev;
+   struct pci_dev *pdev = phba->pcidev;
unsigned long bar0map_len, bar2map_len;
int i, hbq_count;
void *ptr;
int error = -ENODEV;
 
-   /* Obtain PCI device reference */
-   if (!phba->pcidev)
+   if (!pdev)
return error;
-   else
-   pdev = phba->pcidev;
 
/* Set the device DMA mask size */
-   if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
-|| pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
-   if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
-|| pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
-   return error;
-   }
-   }
+   if (dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(64)) ||
+   dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(32)))
+   return error;
 
/* Get the bus address of Bar0 and Bar2 and the number of bytes
 * required by each mapping.
@@ -9558,25 +9551,18 @@ lpfc_pci_function_reset(struct lpfc_hba *phba)
 static int
 lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
 {
-   struct pci_dev *pdev;
+   struct pci_dev *pdev = phba->pcidev;
unsigned long bar0map_len, bar1map_len, bar2map_len;
int error = -ENODEV;
uint32_t if_type;
 
-   /* Obtain PCI device reference */
-   if (!phba->pcidev)
+   if (!pdev)
return error;
-   else
-   pdev = phba->pcidev;
 
/* Set the device DMA mask size */
-   if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
-|| pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
-   if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
-|| pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
-   return error;
-   }
-   }
+   if (dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(64)) ||
+   dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(32)))
+   return error;
 
/*
 * The BARs and register set definitions and offset locations are
-- 
2.19.1



[PATCH 07/12] initio: use dma_set_mask

2018-10-18 Thread Christoph Hellwig
The driver currently uses pci_set_dma_mask despite otherwise using
the generic DMA API.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/initio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/initio.c b/drivers/scsi/initio.c
index 7a91cf3ff173..0a8d786c84ed 100644
--- a/drivers/scsi/initio.c
+++ b/drivers/scsi/initio.c
@@ -2840,7 +2840,7 @@ static int initio_probe_one(struct pci_dev *pdev,
reg = 0;
bios_seg = (bios_seg << 8) + ((u16) ((reg & 0xFF00) >> 8));
 
-   if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
+   if (dma_set_mask(>dev, DMA_BIT_MASK(32))) {
printk(KERN_WARNING  "i91u: Could not set 32 bit DMA mask\n");
error = -ENODEV;
goto out_disable_device;
-- 
2.19.1



[PATCH 3/4] gdth: remove gdth_{alloc,free}_ioctl

2018-10-18 Thread Christoph Hellwig
Out of the three callers once insists on the scratch buffer, and the
others are fine with a new allocation.  Switch those two to juse use
pci_alloc_consistent directly, and open code the scratch buffer
allocation in the remaining one.  This avoids a case where we might
be doing a memory allocation under a spinlock with irqs disabled.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/gdth.c  |  7 ++--
 drivers/scsi/gdth_proc.c | 71 
 drivers/scsi/gdth_proc.h |  3 --
 3 files changed, 25 insertions(+), 56 deletions(-)

diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index 2bec840018ad..7274d09b2a6c 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -4232,7 +4232,7 @@ static int ioc_general(void __user *arg, char *cmnd)
gdth_ioctl_general gen;
gdth_ha_str *ha;
char *buf = NULL;
-   u64 paddr;
+   dma_addr_t paddr;
int rval;
 
if (copy_from_user(, arg, sizeof(gdth_ioctl_general)))
@@ -4251,7 +4251,8 @@ static int ioc_general(void __user *arg, char *cmnd)
if (gen.data_len + gen.sense_len == 0)
goto execute;
 
-   buf = gdth_ioctl_alloc(ha, gen.data_len + gen.sense_len, FALSE, );
+buf = pci_alloc_consistent(ha->pdev, gen.data_len + gen.sense_len,
+   );
if (!buf)
return -EFAULT;
 
@@ -4291,7 +4292,7 @@ static int ioc_general(void __user *arg, char *cmnd)
 
rval = 0;
 out_free_buf:
-   gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr);
+   pci_free_consistent(ha->pdev, gen.data_len + gen.sense_len, buf, paddr);
return 0;
 }
  
diff --git a/drivers/scsi/gdth_proc.c b/drivers/scsi/gdth_proc.c
index 63d851398e38..6a6bdab748df 100644
--- a/drivers/scsi/gdth_proc.c
+++ b/drivers/scsi/gdth_proc.c
@@ -31,7 +31,6 @@ static int gdth_set_asc_info(struct Scsi_Host *host, char 
*buffer,
 int i, found;
 gdth_cmd_strgdtcmd;
 gdth_cpar_str   *pcpar;
-u64 paddr;
 
 charcmnd[MAX_COMMAND_SIZE];
 memset(cmnd, 0xff, 12);
@@ -113,13 +112,23 @@ static int gdth_set_asc_info(struct Scsi_Host *host, char 
*buffer,
 }
 
 if (wb_mode) {
-if (!gdth_ioctl_alloc(ha, sizeof(gdth_cpar_str), TRUE, ))
-return(-EBUSY);
+   unsigned long flags;
+
+   BUILD_BUG_ON(sizeof(gdth_cpar_str) > GDTH_SCRATCH);
+
+   spin_lock_irqsave(>smp_lock, flags);
+   if (ha->scratch_busy) {
+   spin_unlock_irqrestore(>smp_lock, flags);
+return -EBUSY;
+   }
+   ha->scratch_busy = TRUE;
+   spin_unlock_irqrestore(>smp_lock, flags);
+
 pcpar = (gdth_cpar_str *)ha->pscratch;
 memcpy( pcpar, >cpar, sizeof(gdth_cpar_str) );
 gdtcmd.Service = CACHESERVICE;
 gdtcmd.OpCode = GDT_IOCTL;
-gdtcmd.u.ioctl.p_param = paddr;
+gdtcmd.u.ioctl.p_param = ha->scratch_phys;
 gdtcmd.u.ioctl.param_size = sizeof(gdth_cpar_str);
 gdtcmd.u.ioctl.subfunc = CACHE_CONFIG;
 gdtcmd.u.ioctl.channel = INVALID_CHANNEL;
@@ -127,7 +136,10 @@ static int gdth_set_asc_info(struct Scsi_Host *host, char 
*buffer,
 
 gdth_execute(host, , cmnd, 30, NULL);
 
-gdth_ioctl_free(ha, GDTH_SCRATCH, ha->pscratch, paddr);
+   spin_lock_irqsave(>smp_lock, flags);
+   ha->scratch_busy = FALSE;
+   spin_unlock_irqrestore(>smp_lock, flags);
+
 printk("Done.\n");
 return(orig_length);
 }
@@ -143,7 +155,7 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
*host)
 int id, i, j, k, sec, flag;
 int no_mdrv = 0, drv_no, is_mirr;
 u32 cnt;
-u64 paddr;
+dma_addr_t paddr;
 int rc = -ENOMEM;
 
 gdth_cmd_str *gdtcmd;
@@ -232,7 +244,7 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
*host)
 seq_puts(m, "\nPhysical Devices:");
 flag = FALSE;
 
-buf = gdth_ioctl_alloc(ha, size, FALSE, );
+buf = pci_alloc_consistent(ha->pdev, size, );
 if (!buf) 
 goto stop_output;
 for (i = 0; i < ha->bus_cnt; ++i) {
@@ -408,7 +420,7 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
*host)
 seq_printf(m,
" To Array Drv.:\t%s\n", hrec);
 }   
-
+
 if (!flag)
 seq_puts(m, "\n --\n");
 
@@ -502,7 +514,7 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
*host)
 }
 }
 }
-gdth_ioctl_free(ha, size, buf, paddr);
+   pci_free_consistent(ha->pdev, size, buf, paddr);
 
 for (i = 0; i < MAX_HDRIVES; ++i) {
 if (!(ha->hdr[i].present))
@@ -555,47 +567,6 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
*host)
 return rc;
 }
 
-static char *gdth_ioctl_alloc(gdth_ha_str *ha, int size, int scratch,
-  u64 *paddr)
-{
-unsigned long flags;
-char *ret_val;
-
-if (size == 0)

[PATCH 4/4] gdth: use generic DMA API

2018-10-18 Thread Christoph Hellwig
Switch from the legacy PCI DMA API to the generic DMA API.  Also switch
to dma_map_single from pci_map_page in one case where this makes the code
simpler.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/gdth.c  | 111 +++
 drivers/scsi/gdth_proc.c |   4 +-
 2 files changed, 56 insertions(+), 59 deletions(-)

diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index 7274d09b2a6c..3d856554b1b1 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -2518,9 +2518,9 @@ static int gdth_fill_cache_cmd(gdth_ha_str *ha, struct 
scsi_cmnd *scp,
 
 if (scsi_bufflen(scp)) {
 cmndinfo->dma_dir = (read_write == 1 ?
-PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);   
-sgcnt = pci_map_sg(ha->pdev, scsi_sglist(scp), scsi_sg_count(scp),
-   cmndinfo->dma_dir);
+DMA_TO_DEVICE : DMA_FROM_DEVICE);   
+sgcnt = dma_map_sg(>pdev->dev, scsi_sglist(scp),
+  scsi_sg_count(scp), cmndinfo->dma_dir);
 if (mode64) {
 struct scatterlist *sl;
 
@@ -2603,8 +2603,6 @@ static int gdth_fill_raw_cmd(gdth_ha_str *ha, struct 
scsi_cmnd *scp, u8 b)
 dma_addr_t sense_paddr;
 int cmd_index, sgcnt, mode64;
 u8 t,l;
-struct page *page;
-unsigned long offset;
 struct gdth_cmndinfo *cmndinfo;
 
 t = scp->device->id;
@@ -2649,10 +2647,8 @@ static int gdth_fill_raw_cmd(gdth_ha_str *ha, struct 
scsi_cmnd *scp, u8 b)
 }
 
 } else {
-page = virt_to_page(scp->sense_buffer);
-offset = (unsigned long)scp->sense_buffer & ~PAGE_MASK;
-sense_paddr = pci_map_page(ha->pdev,page,offset,
-   16,PCI_DMA_FROMDEVICE);
+sense_paddr = dma_map_single(>pdev->dev, scp->sense_buffer, 16,
+DMA_FROM_DEVICE);
 
cmndinfo->sense_paddr  = sense_paddr;
 cmdp->OpCode   = GDT_WRITE; /* always */
@@ -2693,9 +2689,9 @@ static int gdth_fill_raw_cmd(gdth_ha_str *ha, struct 
scsi_cmnd *scp, u8 b)
 }
 
 if (scsi_bufflen(scp)) {
-cmndinfo->dma_dir = PCI_DMA_BIDIRECTIONAL;
-sgcnt = pci_map_sg(ha->pdev, scsi_sglist(scp), scsi_sg_count(scp),
-   cmndinfo->dma_dir);
+cmndinfo->dma_dir = DMA_BIDIRECTIONAL;
+sgcnt = dma_map_sg(>pdev->dev, scsi_sglist(scp),
+  scsi_sg_count(scp), cmndinfo->dma_dir);
 if (mode64) {
 struct scatterlist *sl;
 
@@ -3313,12 +3309,12 @@ static int gdth_sync_event(gdth_ha_str *ha, int 
service, u8 index,
 return 2;
 }
 if (scsi_bufflen(scp))
-pci_unmap_sg(ha->pdev, scsi_sglist(scp), scsi_sg_count(scp),
+dma_unmap_sg(>pdev->dev, scsi_sglist(scp), scsi_sg_count(scp),
  cmndinfo->dma_dir);
 
 if (cmndinfo->sense_paddr)
-pci_unmap_page(ha->pdev, cmndinfo->sense_paddr, 16,
-   PCI_DMA_FROMDEVICE);
+dma_unmap_page(>pdev->dev, cmndinfo->sense_paddr, 16,
+  DMA_FROM_DEVICE);
 
 if (ha->status == S_OK) {
 cmndinfo->status = S_OK;
@@ -4251,8 +4247,8 @@ static int ioc_general(void __user *arg, char *cmnd)
if (gen.data_len + gen.sense_len == 0)
goto execute;
 
-buf = pci_alloc_consistent(ha->pdev, gen.data_len + gen.sense_len,
-   );
+buf = dma_alloc_coherent(>pdev->dev, gen.data_len + gen.sense_len,
+   , GFP_KERNEL);
if (!buf)
return -EFAULT;
 
@@ -4292,7 +4288,8 @@ static int ioc_general(void __user *arg, char *cmnd)
 
rval = 0;
 out_free_buf:
-   pci_free_consistent(ha->pdev, gen.data_len + gen.sense_len, buf, paddr);
+   dma_free_coherent(>pdev->dev, gen.data_len + gen.sense_len, buf,
+   paddr);
return 0;
 }
  
@@ -4749,22 +4746,22 @@ static int __init gdth_isa_probe_one(u32 isa_bios)
 
error = -ENOMEM;
 
-   ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
-   _dma_handle);
+   ha->pscratch = dma_alloc_coherent(>pdev->dev, GDTH_SCRATCH,
+   _dma_handle, GFP_KERNEL);
if (!ha->pscratch)
goto out_dec_counters;
ha->scratch_phys = scratch_dma_handle;
 
-   ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
-   _dma_handle);
+   ha->pmsg = dma_alloc_coherent(>pdev->dev, sizeof(gdth_msg_str),
+   _dma_handle, GFP_KERNEL);
if (!ha->pmsg)
goto out_free_pscratch;
ha->msg_phys = scratch_dma_handle;
 
 #ifdef INT_COAL
-   ha->coal_stat = 

[PATCH 1/4] gdth: refactor ioc_general

2018-10-18 Thread Christoph Hellwig
This function is a huge mess with duplicated error handling.  Split out
a few useful helpers and use goto labels to untangle the error handling
and no-data ioctl handling.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/gdth.c | 247 +++-
 1 file changed, 130 insertions(+), 117 deletions(-)

diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index 16709735b546..2bec840018ad 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -4155,131 +4155,144 @@ static int ioc_resetdrv(void __user *arg, char *cmnd)
 return 0;
 }
 
-static int ioc_general(void __user *arg, char *cmnd)
+static void gdth_ioc_addr32(gdth_ha_str *ha, gdth_ioctl_general *gen,
+   u64 paddr)
 {
-gdth_ioctl_general gen;
-char *buf = NULL;
-u64 paddr; 
-gdth_ha_str *ha;
-int rval;
+   if (ha->cache_feat & SCATTER_GATHER) {
+   gen->command.u.cache.DestAddr = 0x;
+   gen->command.u.cache.sg_canz = 1;
+   gen->command.u.cache.sg_lst[0].sg_ptr = (u32)paddr;
+   gen->command.u.cache.sg_lst[0].sg_len = gen->data_len;
+   gen->command.u.cache.sg_lst[1].sg_len = 0;
+   } else {
+   gen->command.u.cache.DestAddr = paddr;
+   gen->command.u.cache.sg_canz = 0;
+   }
+}
 
-if (copy_from_user(, arg, sizeof(gdth_ioctl_general)))
-return -EFAULT;
-ha = gdth_find_ha(gen.ionode);
-if (!ha)
-return -EFAULT;
+static void gdth_ioc_addr64(gdth_ha_str *ha, gdth_ioctl_general *gen,
+   u64 paddr)
+{
+   if (ha->cache_feat & SCATTER_GATHER) {
+   gen->command.u.cache64.DestAddr = (u64)-1;
+   gen->command.u.cache64.sg_canz = 1;
+   gen->command.u.cache64.sg_lst[0].sg_ptr = paddr;
+   gen->command.u.cache64.sg_lst[0].sg_len = gen->data_len;
+   gen->command.u.cache64.sg_lst[1].sg_len = 0;
+   } else {
+   gen->command.u.cache64.DestAddr = paddr;
+   gen->command.u.cache64.sg_canz = 0;
+   }
+}
 
-if (gen.data_len > INT_MAX)
-return -EINVAL;
-if (gen.sense_len > INT_MAX)
-return -EINVAL;
-if (gen.data_len + gen.sense_len > INT_MAX)
-return -EINVAL;
+static void gdth_ioc_cacheservice(gdth_ha_str *ha, gdth_ioctl_general *gen,
+   u64 paddr)
+{
+   if (ha->cache_feat & GDT_64BIT) {
+   /* copy elements from 32-bit IOCTL structure */
+   gen->command.u.cache64.BlockCnt = gen->command.u.cache.BlockCnt;
+   gen->command.u.cache64.BlockNo = gen->command.u.cache.BlockNo;
+   gen->command.u.cache64.DeviceNo = gen->command.u.cache.DeviceNo;
 
-if (gen.data_len + gen.sense_len != 0) {
-if (!(buf = gdth_ioctl_alloc(ha, gen.data_len + gen.sense_len,
- FALSE, )))
-return -EFAULT;
-if (copy_from_user(buf, arg + sizeof(gdth_ioctl_general),  
-   gen.data_len + gen.sense_len)) {
-gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr);
-return -EFAULT;
-}
+   gdth_ioc_addr64(ha, gen, paddr);
+   } else {
+   gdth_ioc_addr32(ha, gen, paddr);
+   }
+}
 
-if (gen.command.OpCode == GDT_IOCTL) {
-gen.command.u.ioctl.p_param = paddr;
-} else if (gen.command.Service == CACHESERVICE) {
-if (ha->cache_feat & GDT_64BIT) {
-/* copy elements from 32-bit IOCTL structure */
-gen.command.u.cache64.BlockCnt = gen.command.u.cache.BlockCnt;
-gen.command.u.cache64.BlockNo = gen.command.u.cache.BlockNo;
-gen.command.u.cache64.DeviceNo = gen.command.u.cache.DeviceNo;
-/* addresses */
-if (ha->cache_feat & SCATTER_GATHER) {
-gen.command.u.cache64.DestAddr = (u64)-1;
-gen.command.u.cache64.sg_canz = 1;
-gen.command.u.cache64.sg_lst[0].sg_ptr = paddr;
-gen.command.u.cache64.sg_lst[0].sg_len = gen.data_len;
-gen.command.u.cache64.sg_lst[1].sg_len = 0;
-} else {
-gen.command.u.cache64.DestAddr = paddr;
-gen.command.u.cache64.sg_canz = 0;
-}
-} else {
-if (ha->cache_feat & SCATTER_GATHER) {
-gen.command.u.cache.DestAddr = 0x;
-gen.command.u.cache.sg_canz = 1;
-gen.command.u.cache.sg_lst[0].sg_ptr = (u32)paddr;
-gen.command.u.cache.sg_lst[0].sg_len = gen.data_len;
-gen.command.u.cache.sg_lst[1].sg_len = 0;
-} else {
-gen.command.u.cache.DestAddr = paddr;
-gen.command.u.cache.sg_canz = 0;
-}
-}
-} else if 

dma related cleanups for gdth

2018-10-18 Thread Christoph Hellwig
Cleans up various oddities found during a code audit.


[PATCH 2/4] gdth: reuse dma coherent allocation in gdth_show_info

2018-10-18 Thread Christoph Hellwig
gdth_show_info currently allocs and frees a dma buffer four times,
which isn't very efficient. Reuse a single allocation instead.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/gdth_proc.c | 18 +-
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/scsi/gdth_proc.c b/drivers/scsi/gdth_proc.c
index 3a9751a80225..63d851398e38 100644
--- a/drivers/scsi/gdth_proc.c
+++ b/drivers/scsi/gdth_proc.c
@@ -226,11 +226,13 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
*host)
 #endif
 
 if (ha->more_proc) {
+size_t size = max(GDTH_SCRATCH, sizeof(gdth_hget_str));
+
 /* more information: 2. about physical devices */
 seq_puts(m, "\nPhysical Devices:");
 flag = FALSE;
 
-buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, );
+buf = gdth_ioctl_alloc(ha, size, FALSE, );
 if (!buf) 
 goto stop_output;
 for (i = 0; i < ha->bus_cnt; ++i) {
@@ -323,7 +325,6 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
*host)
 }
 }
 }
-gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
 
 if (!flag)
 seq_puts(m, "\n --\n");
@@ -332,7 +333,6 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
*host)
 seq_puts(m, "\nLogical Drives:");
 flag = FALSE;
 
-buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, );
 if (!buf) 
 goto stop_output;
 for (i = 0; i < MAX_LDRIVES; ++i) {
@@ -408,7 +408,6 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
*host)
 seq_printf(m,
" To Array Drv.:\t%s\n", hrec);
 }   
-gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
 
 if (!flag)
 seq_puts(m, "\n --\n");
@@ -417,9 +416,6 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
*host)
 seq_puts(m, "\nArray Drives:");
 flag = FALSE;
 
-buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, );
-if (!buf) 
-goto stop_output;
 for (i = 0; i < MAX_LDRIVES; ++i) {
 if (!(ha->hdr[i].is_arraydrv && ha->hdr[i].is_master))
 continue;
@@ -468,8 +464,7 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
*host)
hrec);
 }
 }
-gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
-
+
 if (!flag)
 seq_puts(m, "\n --\n");
 
@@ -477,9 +472,6 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
*host)
 seq_puts(m, "\nHost Drives:");
 flag = FALSE;
 
-buf = gdth_ioctl_alloc(ha, sizeof(gdth_hget_str), FALSE, );
-if (!buf) 
-goto stop_output;
 for (i = 0; i < MAX_LDRIVES; ++i) {
 if (!ha->hdr[i].is_logdrv || 
 (ha->hdr[i].is_arraydrv && !ha->hdr[i].is_master))
@@ -510,7 +502,7 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
*host)
 }
 }
 }
-gdth_ioctl_free(ha, sizeof(gdth_hget_str), buf, paddr);
+gdth_ioctl_free(ha, size, buf, paddr);
 
 for (i = 0; i < MAX_HDRIVES; ++i) {
 if (!(ha->hdr[i].present))
-- 
2.19.1



dma related cleanups for pmcraid

2018-10-18 Thread Christoph Hellwig
Cleans up various oddities found during a code audit.


[PATCH 3/3] pmcraid: use generic DMA API

2018-10-18 Thread Christoph Hellwig
Switch from the legacy PCI DMA API to the generic DMA API.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/pmcraid.c | 79 +++---
 1 file changed, 36 insertions(+), 43 deletions(-)

diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index 401e543f1723..707d766c1ee9 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -3514,7 +3514,7 @@ static int pmcraid_build_passthrough_ioadls(
return -ENOMEM;
}
 
-   sglist->num_dma_sg = pci_map_sg(cmd->drv_inst->pdev,
+   sglist->num_dma_sg = dma_map_sg(>drv_inst->pdev->dev,
sglist->scatterlist,
sglist->num_sg, direction);
 
@@ -3563,7 +3563,7 @@ static void pmcraid_release_passthrough_ioadls(
struct pmcraid_sglist *sglist = cmd->sglist;
 
if (buflen > 0) {
-   pci_unmap_sg(cmd->drv_inst->pdev,
+   dma_unmap_sg(>drv_inst->pdev->dev,
 sglist->scatterlist,
 sglist->num_sg,
 direction);
@@ -4699,9 +4699,9 @@ static void
 pmcraid_release_host_rrqs(struct pmcraid_instance *pinstance, int maxindex)
 {
int i;
-   for (i = 0; i < maxindex; i++) {
 
-   pci_free_consistent(pinstance->pdev,
+   for (i = 0; i < maxindex; i++) {
+   dma_free_coherent(>pdev->dev,
HRRQ_ENTRY_SIZE * PMCRAID_MAX_CMD,
pinstance->hrrq_start[i],
pinstance->hrrq_start_bus_addr[i]);
@@ -4728,11 +4728,9 @@ static int pmcraid_allocate_host_rrqs(struct 
pmcraid_instance *pinstance)
 
for (i = 0; i < pinstance->num_hrrq; i++) {
pinstance->hrrq_start[i] =
-   pci_alloc_consistent(
-   pinstance->pdev,
-   buffer_size,
-   &(pinstance->hrrq_start_bus_addr[i]));
-
+   dma_alloc_coherent(>pdev->dev, buffer_size,
+  >hrrq_start_bus_addr[i],
+  GFP_KERNEL);
if (!pinstance->hrrq_start[i]) {
pmcraid_err("pci_alloc failed for hrrq vector : %d\n",
i);
@@ -4761,7 +4759,7 @@ static int pmcraid_allocate_host_rrqs(struct 
pmcraid_instance *pinstance)
 static void pmcraid_release_hcams(struct pmcraid_instance *pinstance)
 {
if (pinstance->ccn.msg != NULL) {
-   pci_free_consistent(pinstance->pdev,
+   dma_free_coherent(>pdev->dev,
PMCRAID_AEN_HDR_SIZE +
sizeof(struct pmcraid_hcam_ccn_ext),
pinstance->ccn.msg,
@@ -4773,7 +4771,7 @@ static void pmcraid_release_hcams(struct pmcraid_instance 
*pinstance)
}
 
if (pinstance->ldn.msg != NULL) {
-   pci_free_consistent(pinstance->pdev,
+   dma_free_coherent(>pdev->dev,
PMCRAID_AEN_HDR_SIZE +
sizeof(struct pmcraid_hcam_ldn),
pinstance->ldn.msg,
@@ -4794,17 +4792,15 @@ static void pmcraid_release_hcams(struct 
pmcraid_instance *pinstance)
  */
 static int pmcraid_allocate_hcams(struct pmcraid_instance *pinstance)
 {
-   pinstance->ccn.msg = pci_alloc_consistent(
-   pinstance->pdev,
+   pinstance->ccn.msg = dma_alloc_coherent(>pdev->dev,
PMCRAID_AEN_HDR_SIZE +
sizeof(struct pmcraid_hcam_ccn_ext),
-   &(pinstance->ccn.baddr));
+   >ccn.baddr, GFP_KERNEL);
 
-   pinstance->ldn.msg = pci_alloc_consistent(
-   pinstance->pdev,
+   pinstance->ldn.msg = dma_alloc_coherent(>pdev->dev,
PMCRAID_AEN_HDR_SIZE +
sizeof(struct pmcraid_hcam_ldn),
-   &(pinstance->ldn.baddr));
+   >ldn.baddr, GFP_KERNEL);
 
if (pinstance->ldn.msg == NULL || pinstance->ccn.msg == NULL) {
pmcraid_release_hcams(pinstance);
@@ -4832,7 +4828,7 @@ static void pmcraid_release_config_buffers(struct 
pmcraid_instance *pinstance)
 {
if (pinstance->cfg_table != NULL &&
pinstance->cfg_table_bus_addr != 0) {
-   pci_free_consistent(pinstance->pdev,
+   dma_free_coherent(>pdev->dev,
sizeof(struct pmcraid_config_table),
pinstance->cfg_table,
   

[PATCH 1/3] pmcraid: simplify pmcraid_cancel_all a bit

2018-10-18 Thread Christoph Hellwig
No need for a local cmd_done variable, and pass boolean values as bool
type instead of u32.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/pmcraid.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index 4e86994e10e8..3ba606420247 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -2491,17 +2491,15 @@ static void pmcraid_request_sense(struct pmcraid_cmd 
*cmd)
 /**
  * pmcraid_cancel_all - cancel all outstanding IOARCBs as part of error 
recovery
  * @cmd: command that failed
- * @sense: true if request_sense is required after cancel all
+ * @need_sense: true if request_sense is required after cancel all
  *
  * This function sends a cancel all to a device to clear the queue.
  */
-static void pmcraid_cancel_all(struct pmcraid_cmd *cmd, u32 sense)
+static void pmcraid_cancel_all(struct pmcraid_cmd *cmd, bool need_sense)
 {
struct scsi_cmnd *scsi_cmd = cmd->scsi_cmd;
struct pmcraid_ioarcb *ioarcb = >ioa_cb->ioarcb;
struct pmcraid_resource_entry *res = scsi_cmd->device->hostdata;
-   void (*cmd_done) (struct pmcraid_cmd *) = sense ? pmcraid_erp_done
-   : pmcraid_request_sense;
 
memset(ioarcb->cdb, 0, PMCRAID_MAX_CDB_LEN);
ioarcb->request_flags0 = SYNC_OVERRIDE;
@@ -2519,7 +2517,8 @@ static void pmcraid_cancel_all(struct pmcraid_cmd *cmd, 
u32 sense)
/* writing to IOARRIN must be protected by host_lock, as mid-layer
 * schedule queuecommand while we are doing this
 */
-   pmcraid_send_cmd(cmd, cmd_done,
+   pmcraid_send_cmd(cmd, need_sense ?
+pmcraid_erp_done : pmcraid_request_sense,
 PMCRAID_REQUEST_SENSE_TIMEOUT,
 pmcraid_timeout_handler);
 }
@@ -2612,7 +2611,7 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
struct pmcraid_ioasa *ioasa = >ioa_cb->ioasa;
u32 ioasc = le32_to_cpu(ioasa->ioasc);
u32 masked_ioasc = ioasc & PMCRAID_IOASC_SENSE_MASK;
-   u32 sense_copied = 0;
+   bool sense_copied = false;
 
if (!res) {
pmcraid_info("resource pointer is NULL\n");
@@ -2684,7 +2683,7 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
memcpy(scsi_cmd->sense_buffer,
   ioasa->sense_data,
   data_size);
-   sense_copied = 1;
+   sense_copied = true;
}
 
if (RES_IS_GSCSI(res->cfg_entry))
-- 
2.19.1



[PATCH 2/3] pmcraid: don't allocate a dma coherent buffer for sense data

2018-10-18 Thread Christoph Hellwig
We can just dma map the sense buffer passed with the scsi command,
and that gets us out of the nasty business of doing dma coherent
allocations from irq context.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/pmcraid.c | 24 
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index 3ba606420247..401e543f1723 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -846,16 +846,9 @@ static void pmcraid_erp_done(struct pmcraid_cmd *cmd)
cmd->ioa_cb->ioarcb.cdb[0], ioasc);
}
 
-   /* if we had allocated sense buffers for request sense, copy the sense
-* release the buffers
-*/
-   if (cmd->sense_buffer != NULL) {
-   memcpy(scsi_cmd->sense_buffer,
-  cmd->sense_buffer,
-  SCSI_SENSE_BUFFERSIZE);
-   pci_free_consistent(pinstance->pdev,
-   SCSI_SENSE_BUFFERSIZE,
-   cmd->sense_buffer, cmd->sense_buffer_dma);
+   if (cmd->sense_buffer) {
+   dma_unmap_single(>pdev->dev, cmd->sense_buffer_dma,
+SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
cmd->sense_buffer = NULL;
cmd->sense_buffer_dma = 0;
}
@@ -2444,13 +2437,12 @@ static void pmcraid_request_sense(struct pmcraid_cmd 
*cmd)
 {
struct pmcraid_ioarcb *ioarcb = >ioa_cb->ioarcb;
struct pmcraid_ioadl_desc *ioadl = ioarcb->add_data.u.ioadl;
+   struct device *dev = >drv_inst->pdev->dev;
 
-   /* allocate DMAable memory for sense buffers */
-   cmd->sense_buffer = pci_alloc_consistent(cmd->drv_inst->pdev,
-SCSI_SENSE_BUFFERSIZE,
->sense_buffer_dma);
-
-   if (cmd->sense_buffer == NULL) {
+   cmd->sense_buffer = cmd->scsi_cmd->sense_buffer;
+   cmd->sense_buffer_dma = dma_map_single(dev, cmd->sense_buffer,
+   SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
+   if (dma_mapping_error(dev, cmd->sense_buffer_dma)) {
pmcraid_err
("couldn't allocate sense buffer for request sense\n");
pmcraid_erp_done(cmd);
-- 
2.19.1



[PATCH 5/5] qla2xxx: use lower_32_bits and upper_32_bits instead of reinventing them

2018-10-18 Thread Christoph Hellwig
This also moves the optimization for builds with 32-bit dma_addr_t to
the compiler (where it belongs) instead of opencoding it based on
incorrect assumptions.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/qla2xxx/qla_target.c | 8 
 drivers/scsi/qla2xxx/qla_target.h | 8 
 2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index 39828207bc1d..443711238c0e 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -2660,9 +2660,9 @@ static void qlt_load_cont_data_segments(struct 
qla_tgt_prm *prm)
cnt < QLA_TGT_DATASEGS_PER_CONT_24XX && prm->seg_cnt;
cnt++, prm->seg_cnt--) {
*dword_ptr++ =
-   cpu_to_le32(pci_dma_lo32
+   cpu_to_le32(lower_32_bits
(sg_dma_address(prm->sg)));
-   *dword_ptr++ = cpu_to_le32(pci_dma_hi32
+   *dword_ptr++ = cpu_to_le32(upper_32_bits
(sg_dma_address(prm->sg)));
*dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg));
 
@@ -2704,9 +2704,9 @@ static void qlt_load_data_segments(struct qla_tgt_prm 
*prm)
(cnt < QLA_TGT_DATASEGS_PER_CMD_24XX) && prm->seg_cnt;
cnt++, prm->seg_cnt--) {
*dword_ptr++ =
-   cpu_to_le32(pci_dma_lo32(sg_dma_address(prm->sg)));
+   cpu_to_le32(lower_32_bits(sg_dma_address(prm->sg)));
 
-   *dword_ptr++ = cpu_to_le32(pci_dma_hi32(
+   *dword_ptr++ = cpu_to_le32(upper_32_bits(
sg_dma_address(prm->sg)));
 
*dword_ptr++ = cpu_to_le32(sg_dma_len(prm->sg));
diff --git a/drivers/scsi/qla2xxx/qla_target.h 
b/drivers/scsi/qla2xxx/qla_target.h
index 91403269b204..085782db911c 100644
--- a/drivers/scsi/qla2xxx/qla_target.h
+++ b/drivers/scsi/qla2xxx/qla_target.h
@@ -771,14 +771,6 @@ int qla2x00_wait_for_hba_online(struct scsi_qla_host *);
 #defineFC_TM_REJECT4
 #define FC_TM_FAILED5
 
-#if (BITS_PER_LONG > 32) || defined(CONFIG_HIGHMEM64G)
-#define pci_dma_lo32(a) (a & 0x)
-#define pci_dma_hi32(a) a) >> 16)>>16) & 0x)
-#else
-#define pci_dma_lo32(a) (a & 0x)
-#define pci_dma_hi32(a) 0
-#endif
-
 #define QLA_TGT_SENSE_VALID(sense)  ((sense != NULL) && \
(((const uint8_t *)(sense))[0] & 0x70) == 0x70)
 
-- 
2.19.1



[PATCH 4/5] qla1280: properly handle 64-bit DMA

2018-10-18 Thread Christoph Hellwig
CONFIG_HIGHMEM is not in fact an indicator for > 32-bit dma addressing
Given that the driver is a bit weird and wants a compile time selection
switch to checking CONFIG_ARCH_DMA_ADDR_T_64BIT instead.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/qla1280.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index f19e8d192d36..9c5b67304a76 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -383,10 +383,7 @@
 
 #include "qla1280.h"
 
-#ifndef BITS_PER_LONG
-#error "BITS_PER_LONG not defined!"
-#endif
-#if (BITS_PER_LONG == 64) || defined CONFIG_HIGHMEM
+#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
 #define QLA_64BIT_PTR  1
 #endif
 
-- 
2.19.1



fix up a few drivers for 64-bit dma addresses

2018-10-18 Thread Christoph Hellwig
Some drivers make very odd decisions on when to use support for
64-bit addressing.  Fix this up a bit.


[PATCH 2/5] ips: properly handle 64-bit DMA

2018-10-18 Thread Christoph Hellwig
CONFIG_HIGHMEM64 is only one (and these days unusual) way to indicate
that > 32-bit dma address are possible.  Replace it with a check of the
dma_addr_t size.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/ips.c | 2 +-
 drivers/scsi/ips.h | 6 --
 2 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c
index 679321e96a86..70a776dc0a02 100644
--- a/drivers/scsi/ips.c
+++ b/drivers/scsi/ips.c
@@ -6926,7 +6926,7 @@ ips_init_phase1(struct pci_dev *pci_dev, int *indexPtr)
 * it!  Also, don't use 64bit addressing if dma addresses
 * are guaranteed to be < 4G.
 */
-   if (IPS_ENABLE_DMA64 && IPS_HAS_ENH_SGLIST(ha) &&
+   if (sizeof(dma_addr_t) > 4 && IPS_HAS_ENH_SGLIST(ha) &&
!dma_set_mask(>pcidev->dev, DMA_BIT_MASK(64))) {
(ha)->flags |= IPS_HA_ENH_SG;
} else {
diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
index 42c180e3938b..6c0678fb9a67 100644
--- a/drivers/scsi/ips.h
+++ b/drivers/scsi/ips.h
@@ -96,12 +96,6 @@
   #define __iomem
#endif
 
-   #if (BITS_PER_LONG > 32) || defined(CONFIG_HIGHMEM64G)
-  #define IPS_ENABLE_DMA64(1)
-   #else
-  #define IPS_ENABLE_DMA64(0)
-   #endif
-
/*
 * Adapter address map equates
 */
-- 
2.19.1



[PATCH 1/5] ips: use lower_32_bits and upper_32_bits instead of reinventing them

2018-10-18 Thread Christoph Hellwig
Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/ips.c | 6 +++---
 drivers/scsi/ips.h | 3 ---
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c
index ee8a1ecd58fd..679321e96a86 100644
--- a/drivers/scsi/ips.c
+++ b/drivers/scsi/ips.c
@@ -1801,13 +1801,13 @@ ips_fill_scb_sg_single(ips_ha_t * ha, dma_addr_t 
busaddr,
}
if (IPS_USE_ENH_SGLIST(ha)) {
scb->sg_list.enh_list[indx].address_lo =
-   cpu_to_le32(pci_dma_lo32(busaddr));
+   cpu_to_le32(lower_32_bits(busaddr));
scb->sg_list.enh_list[indx].address_hi =
-   cpu_to_le32(pci_dma_hi32(busaddr));
+   cpu_to_le32(upper_32_bits(busaddr));
scb->sg_list.enh_list[indx].length = cpu_to_le32(e_len);
} else {
scb->sg_list.std_list[indx].address =
-   cpu_to_le32(pci_dma_lo32(busaddr));
+   cpu_to_le32(lower_32_bits(busaddr));
scb->sg_list.std_list[indx].length = cpu_to_le32(e_len);
}
 
diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
index db546171e97f..42c180e3938b 100644
--- a/drivers/scsi/ips.h
+++ b/drivers/scsi/ips.h
@@ -96,9 +96,6 @@
   #define __iomem
#endif
 
-   #define pci_dma_hi32(a) ((a >> 16) >> 16)
-   #define pci_dma_lo32(a) (a & 0x)
-
#if (BITS_PER_LONG > 32) || defined(CONFIG_HIGHMEM64G)
   #define IPS_ENABLE_DMA64(1)
#else
-- 
2.19.1



[PATCH 3/5] qla1280: use lower_32_bits and upper_32_bits instead of reinventing them

2018-10-18 Thread Christoph Hellwig
This also moves the optimization for builds with 32-bit dma_addr_t to
the compiler (where it belongs) instead of opencoding it.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/qla1280.c | 47 ++
 1 file changed, 20 insertions(+), 27 deletions(-)

diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index 15a50cc7e4b3..f19e8d192d36 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -390,13 +390,6 @@
 #define QLA_64BIT_PTR  1
 #endif
 
-#ifdef QLA_64BIT_PTR
-#define pci_dma_hi32(a)((a >> 16) >> 16)
-#else
-#define pci_dma_hi32(a)0
-#endif
-#define pci_dma_lo32(a)(a & 0x)
-
 #define NVRAM_DELAY()  udelay(500) /* 2 microseconds */
 
 #if defined(__ia64__) && !defined(ia64_platform_is)
@@ -1790,8 +1783,8 @@ qla1280_load_firmware_dma(struct scsi_qla_host *ha)
mb[4] = cnt;
mb[3] = ha->request_dma & 0x;
mb[2] = (ha->request_dma >> 16) & 0x;
-   mb[7] = pci_dma_hi32(ha->request_dma) & 0x;
-   mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
+   mb[7] = upper_32_bits(ha->request_dma) & 0x;
+   mb[6] = upper_32_bits(ha->request_dma) >> 16;
dprintk(2, "%s: op=%d  0x%p = 0x%4x,0x%4x,0x%4x,0x%4x\n",
__func__, mb[0],
(void *)(long)ha->request_dma,
@@ -1810,8 +1803,8 @@ qla1280_load_firmware_dma(struct scsi_qla_host *ha)
mb[4] = cnt;
mb[3] = p_tbuf & 0x;
mb[2] = (p_tbuf >> 16) & 0x;
-   mb[7] = pci_dma_hi32(p_tbuf) & 0x;
-   mb[6] = pci_dma_hi32(p_tbuf) >> 16;
+   mb[7] = upper_32_bits(p_tbuf) & 0x;
+   mb[6] = upper_32_bits(p_tbuf) >> 16;
 
err = qla1280_mailbox_command(ha, BIT_4 | BIT_3 | BIT_2 |
BIT_1 | BIT_0, mb);
@@ -1933,8 +1926,8 @@ qla1280_init_rings(struct scsi_qla_host *ha)
mb[3] = ha->request_dma & 0x;
mb[2] = (ha->request_dma >> 16) & 0x;
mb[4] = 0;
-   mb[7] = pci_dma_hi32(ha->request_dma) & 0x;
-   mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
+   mb[7] = upper_32_bits(ha->request_dma) & 0x;
+   mb[6] = upper_32_bits(ha->request_dma) >> 16;
if (!(status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_4 |
   BIT_3 | BIT_2 | BIT_1 | BIT_0,
   [0]))) {
@@ -1947,8 +1940,8 @@ qla1280_init_rings(struct scsi_qla_host *ha)
mb[3] = ha->response_dma & 0x;
mb[2] = (ha->response_dma >> 16) & 0x;
mb[5] = 0;
-   mb[7] = pci_dma_hi32(ha->response_dma) & 0x;
-   mb[6] = pci_dma_hi32(ha->response_dma) >> 16;
+   mb[7] = upper_32_bits(ha->response_dma) & 0x;
+   mb[6] = upper_32_bits(ha->response_dma) >> 16;
status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_5 |
 BIT_3 | BIT_2 | BIT_1 | BIT_0,
 [0]);
@@ -2914,13 +2907,13 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, 
struct srb * sp)
 SCSI_BUS_32(cmd));
 #endif
*dword_ptr++ =
-   cpu_to_le32(pci_dma_lo32(dma_handle));
+   cpu_to_le32(lower_32_bits(dma_handle));
*dword_ptr++ =
-   cpu_to_le32(pci_dma_hi32(dma_handle));
+   cpu_to_le32(upper_32_bits(dma_handle));
*dword_ptr++ = cpu_to_le32(sg_dma_len(s));
dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n",
-   cpu_to_le32(pci_dma_hi32(dma_handle)),
-   cpu_to_le32(pci_dma_lo32(dma_handle)),
+   cpu_to_le32(upper_32_bits(dma_handle)),
+   cpu_to_le32(lower_32_bits(dma_handle)),
cpu_to_le32(sg_dma_len(sg_next(s;
remseg--;
}
@@ -2976,14 +2969,14 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, 
struct srb * sp)
 SCSI_BUS_32(cmd));
 #endif
*dword_ptr++ =
-   cpu_to_le32(pci_dma_lo32(dma_handle));
+   cpu_to_le32(lower_32_bits(dma_handle));
*dword_ptr++ =
-   cpu_to_le32(pci_dma_hi32(dma_handle));
+   cpu_to_le32(upper_32_bits(dma_handle));

[PATCH 2/3] wd719x: use per-command private data

2018-10-18 Thread Christoph Hellwig
Add the SCB onto the scsi command allocation and use dma streaming
mappings for it only when in use.  This avoid possibly calling
dma_alloc_coherent under a lock or even in irq context, while also
making the code simpler.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/wd719x.c | 95 ++-
 drivers/scsi/wd719x.h |  1 -
 2 files changed, 39 insertions(+), 57 deletions(-)

diff --git a/drivers/scsi/wd719x.c b/drivers/scsi/wd719x.c
index 7b05bbcfb186..d47190f08ed6 100644
--- a/drivers/scsi/wd719x.c
+++ b/drivers/scsi/wd719x.c
@@ -153,8 +153,6 @@ static int wd719x_direct_cmd(struct wd719x *wd, u8 opcode, 
u8 dev, u8 lun,
 
 static void wd719x_destroy(struct wd719x *wd)
 {
-   struct wd719x_scb *scb;
-
/* stop the RISC */
if (wd719x_direct_cmd(wd, WD719X_CMD_SLEEP, 0, 0, 0, 0,
  WD719X_WAIT_FOR_RISC))
@@ -164,10 +162,6 @@ static void wd719x_destroy(struct wd719x *wd)
 
WARN_ON_ONCE(!list_empty(>active_scbs));
 
-   /* free all SCBs */
-   list_for_each_entry(scb, >free_scbs, list)
-   pci_free_consistent(wd->pdev, sizeof(struct wd719x_scb), scb,
-   scb->phys);
/* free internal buffers */
pci_free_consistent(wd->pdev, wd->fw_size, wd->fw_virt, wd->fw_phys);
wd->fw_virt = NULL;
@@ -180,18 +174,20 @@ static void wd719x_destroy(struct wd719x *wd)
free_irq(wd->pdev->irq, wd);
 }
 
-/* finish a SCSI command, mark SCB (if any) as free, unmap buffers */
-static void wd719x_finish_cmd(struct scsi_cmnd *cmd, int result)
+/* finish a SCSI command, unmap buffers */
+static void wd719x_finish_cmd(struct wd719x_scb *scb, int result)
 {
+   struct scsi_cmnd *cmd = scb->cmd;
struct wd719x *wd = shost_priv(cmd->device->host);
-   struct wd719x_scb *scb = (struct wd719x_scb *) cmd->host_scribble;
 
-   if (scb) {
-   list_move(>list, >free_scbs);
-   dma_unmap_single(>pdev->dev, cmd->SCp.dma_handle,
-SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
-   scsi_dma_unmap(cmd);
-   }
+   list_del(>list);
+
+   dma_unmap_single(>pdev->dev, scb->phys,
+   sizeof(struct wd719x_scb), DMA_TO_DEVICE);
+   scsi_dma_unmap(cmd);
+   dma_unmap_single(>pdev->dev, cmd->SCp.dma_handle,
+SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
+
cmd->result = result << 16;
cmd->scsi_done(cmd);
 }
@@ -201,36 +197,10 @@ static int wd719x_queuecommand(struct Scsi_Host *sh, 
struct scsi_cmnd *cmd)
 {
int i, count_sg;
unsigned long flags;
-   struct wd719x_scb *scb;
+   struct wd719x_scb *scb = scsi_cmd_priv(cmd);
struct wd719x *wd = shost_priv(sh);
-   dma_addr_t phys;
-
-   cmd->host_scribble = NULL;
 
-   /* get a free SCB - either from existing ones or allocate a new one */
-   spin_lock_irqsave(wd->sh->host_lock, flags);
-   scb = list_first_entry_or_null(>free_scbs, struct wd719x_scb, list);
-   if (scb) {
-   list_del(>list);
-   phys = scb->phys;
-   } else {
-   spin_unlock_irqrestore(wd->sh->host_lock, flags);
-   scb = pci_alloc_consistent(wd->pdev, sizeof(struct wd719x_scb),
-  );
-   spin_lock_irqsave(wd->sh->host_lock, flags);
-   if (!scb) {
-   dev_err(>pdev->dev, "unable to allocate SCB\n");
-   wd719x_finish_cmd(cmd, DID_ERROR);
-   spin_unlock_irqrestore(wd->sh->host_lock, flags);
-   return 0;
-   }
-   }
-   memset(scb, 0, sizeof(struct wd719x_scb));
-   list_add(>list, >active_scbs);
-
-   scb->phys = phys;
scb->cmd = cmd;
-   cmd->host_scribble = (char *) scb;
 
scb->CDB_tag = 0;   /* Tagged queueing not supported yet */
scb->devid = cmd->device->id;
@@ -243,6 +213,8 @@ static int wd719x_queuecommand(struct Scsi_Host *sh, struct 
scsi_cmnd *cmd)
scb->sense_buf_length = SCSI_SENSE_BUFFERSIZE;
cmd->SCp.dma_handle = dma_map_single(>pdev->dev, cmd->sense_buffer,
SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
+   if (dma_mapping_error(>pdev->dev, cmd->SCp.dma_handle))
+   goto out_error;
scb->sense_buf = cpu_to_le32(cmd->SCp.dma_handle);
 
/* request autosense */
@@ -257,11 +229,8 @@ static int wd719x_queuecommand(struct Scsi_Host *sh, 
struct scsi_cmnd *cmd)
 
/* Scather/gather */
count_sg = scsi_dma_map(cmd);
-   if (count_sg < 0) {
-   wd719x_finish_cmd(cmd, DID_ERROR);
-   spin_unlock_irqrestore(wd->sh->host_lock, flags);
-   return 0;
-   }
+   if (count_sg < 0)
+   goto out_unmap_sense;
BUG_ON(count_sg > WD719X_SG);
 
if (count_sg) {
@@ -277,24 

[PATCH 3/3] wd719x: always use generic DMA API

2018-10-18 Thread Christoph Hellwig
The wd719x driver currently uses a mix of the legacy PCI DMA and
the generic DMA APIs.  Switch it over to the generic DMA API entirely.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/wd719x.c | 32 +---
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/drivers/scsi/wd719x.c b/drivers/scsi/wd719x.c
index d47190f08ed6..76442abef2e3 100644
--- a/drivers/scsi/wd719x.c
+++ b/drivers/scsi/wd719x.c
@@ -163,13 +163,14 @@ static void wd719x_destroy(struct wd719x *wd)
WARN_ON_ONCE(!list_empty(>active_scbs));
 
/* free internal buffers */
-   pci_free_consistent(wd->pdev, wd->fw_size, wd->fw_virt, wd->fw_phys);
+   dma_free_coherent(>pdev->dev, wd->fw_size, wd->fw_virt,
+ wd->fw_phys);
wd->fw_virt = NULL;
-   pci_free_consistent(wd->pdev, WD719X_HASH_TABLE_SIZE, wd->hash_virt,
-   wd->hash_phys);
+   dma_free_coherent(>pdev->dev, WD719X_HASH_TABLE_SIZE, wd->hash_virt,
+ wd->hash_phys);
wd->hash_virt = NULL;
-   pci_free_consistent(wd->pdev, sizeof(struct wd719x_host_param),
-   wd->params, wd->params_phys);
+   dma_free_coherent(>pdev->dev, sizeof(struct wd719x_host_param),
+ wd->params, wd->params_phys);
wd->params = NULL;
free_irq(wd->pdev->irq, wd);
 }
@@ -313,8 +314,8 @@ static int wd719x_chip_init(struct wd719x *wd)
wd->fw_size = ALIGN(fw_wcs->size, 4) + fw_risc->size;
 
if (!wd->fw_virt)
-   wd->fw_virt = pci_alloc_consistent(wd->pdev, wd->fw_size,
-  >fw_phys);
+   wd->fw_virt = dma_alloc_coherent(>pdev->dev, wd->fw_size,
+>fw_phys, GFP_KERNEL);
if (!wd->fw_virt) {
ret = -ENOMEM;
goto wd719x_init_end;
@@ -801,17 +802,18 @@ static int wd719x_board_found(struct Scsi_Host *sh)
wd->fw_virt = NULL;
 
/* memory area for host (EEPROM) parameters */
-   wd->params = pci_alloc_consistent(wd->pdev,
- sizeof(struct wd719x_host_param),
- >params_phys);
+   wd->params = dma_alloc_coherent(>pdev->dev,
+   sizeof(struct wd719x_host_param),
+   >params_phys, GFP_KERNEL);
if (!wd->params) {
dev_warn(>pdev->dev, "unable to allocate parameter 
buffer\n");
return -ENOMEM;
}
 
/* memory area for the RISC for hash table of outstanding requests */
-   wd->hash_virt = pci_alloc_consistent(wd->pdev, WD719X_HASH_TABLE_SIZE,
->hash_phys);
+   wd->hash_virt = dma_alloc_coherent(>pdev->dev,
+  WD719X_HASH_TABLE_SIZE,
+  >hash_phys, GFP_KERNEL);
if (!wd->hash_virt) {
dev_warn(>pdev->dev, "unable to allocate hash buffer\n");
ret = -ENOMEM;
@@ -843,10 +845,10 @@ static int wd719x_board_found(struct Scsi_Host *sh)
 fail_free_irq:
free_irq(wd->pdev->irq, wd);
 fail_free_hash:
-   pci_free_consistent(wd->pdev, WD719X_HASH_TABLE_SIZE, wd->hash_virt,
+   dma_free_coherent(>pdev->dev, WD719X_HASH_TABLE_SIZE, wd->hash_virt,
wd->hash_phys);
 fail_free_params:
-   pci_free_consistent(wd->pdev, sizeof(struct wd719x_host_param),
+   dma_free_coherent(>pdev->dev, sizeof(struct wd719x_host_param),
wd->params, wd->params_phys);
 
return ret;
@@ -879,7 +881,7 @@ static int wd719x_pci_probe(struct pci_dev *pdev, const 
struct pci_device_id *d)
if (err)
goto fail;
 
-   if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
+   if (dma_set_mask(>dev, DMA_BIT_MASK(32))) {
dev_warn(>dev, "Unable to set 32-bit DMA mask\n");
goto disable_device;
}
-- 
2.19.1



[PATCH 1/3] wd719x: there should be no active SCBs on removal

2018-10-18 Thread Christoph Hellwig
So warn on that case instead of trying to free them, which would be fatal
in case we actuall had active ones.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/wd719x.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/wd719x.c b/drivers/scsi/wd719x.c
index 974bfb3f30f4..7b05bbcfb186 100644
--- a/drivers/scsi/wd719x.c
+++ b/drivers/scsi/wd719x.c
@@ -162,10 +162,9 @@ static void wd719x_destroy(struct wd719x *wd)
/* disable RISC */
wd719x_writeb(wd, WD719X_PCI_MODE_SELECT, 0);
 
+   WARN_ON_ONCE(!list_empty(>active_scbs));
+
/* free all SCBs */
-   list_for_each_entry(scb, >active_scbs, list)
-   pci_free_consistent(wd->pdev, sizeof(struct wd719x_scb), scb,
-   scb->phys);
list_for_each_entry(scb, >free_scbs, list)
pci_free_consistent(wd->pdev, sizeof(struct wd719x_scb), scb,
scb->phys);
-- 
2.19.1



dma related cleanups for wd719x

2018-10-18 Thread Christoph Hellwig
Hi Ondrej,

can you look over this series, which cleans up a few dma-related
bits in the wd719x driver?


Re: [PATCH -next] scsi: hisi_sas: Fix missing unlock on error in hisi_sas_phy_read32()

2018-10-18 Thread John Garry

On 18/10/2018 04:58, Wei Yongjun wrote:

Add the missing unlock before return from function hisi_sas_phy_read32()
in the error handling case.

Fixes: 784b46b7cba0 ("scsi: hisi_sas: Use block layer tag instead for IPTT")
Signed-off-by: Wei Yongjun 
---
 drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c 
b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c
index 70d6b28..cc36b64 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c
@@ -806,8 +806,10 @@ static u32 hisi_sas_phy_read32(struct hisi_hba *hisi_hba,
while (1) {
start = find_next_zero_bit(bitmap,
hisi_hba->slot_index_count, start);
-   if (start >= end)
+   if (start >= end) {
+   spin_unlock_irqrestore(_hba->lock, flags);
return -SAS_QUEUE_FULL;
+   }
/*
  * SAS IPTT bit0 should be 1, and SATA IPTT bit0 should be 0.
  */




This has already been fixed

thanks