Re: [PATCH v3] target: split out helper for cxn timeout error stashing

2018-10-14 Thread kbuild test robot
Hi David,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on target/master]
[also build test ERROR on v4.19-rc7 next-20181012]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/David-Disseldorp/target-split-out-helper-for-cxn-timeout-error-stashing/20181014-111810
base:   https://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending.git 
master
config: i386-randconfig-s1-201841 (attached as .config)
compiler: gcc-6 (Debian 6.4.0-9) 6.4.0 20171026
reproduce:
# save the attached .config to linux build tree
make ARCH=i386 

All errors (new ones prefixed by >>):

   drivers/target/iscsi/iscsi_target_util.c: In function 
'iscsit_handle_nopin_response_timeout':
>> drivers/target/iscsi/iscsi_target_util.c:902:36: error: 'sess' undeclared 
>> (first use in this function)
 iscsit_fill_cxn_timeout_err_stats(sess);
   ^~~~
   drivers/target/iscsi/iscsi_target_util.c:902:36: note: each undeclared 
identifier is reported only once for each function it appears in

vim +/sess +902 drivers/target/iscsi/iscsi_target_util.c

   882  
   883  static void iscsit_handle_nopin_response_timeout(unsigned long data)
   884  {
   885  struct iscsi_conn *conn = (struct iscsi_conn *) data;
   886  
   887  iscsit_inc_conn_usage_count(conn);
   888  
   889  spin_lock_bh(&conn->nopin_timer_lock);
   890  if (conn->nopin_response_timer_flags & ISCSI_TF_STOP) {
   891  spin_unlock_bh(&conn->nopin_timer_lock);
   892  iscsit_dec_conn_usage_count(conn);
   893  return;
   894  }
   895  
   896  pr_debug("Did not receive response to NOPIN on CID: %hu on"
   897  " SID: %u, failing connection.\n", conn->cid,
   898  conn->sess->sid);
   899  conn->nopin_response_timer_flags &= ~ISCSI_TF_RUNNING;
   900  spin_unlock_bh(&conn->nopin_timer_lock);
   901  
 > 902  iscsit_fill_cxn_timeout_err_stats(sess);
   903  iscsit_cause_connection_reinstatement(conn, 0);
   904  iscsit_dec_conn_usage_count(conn);
   905  }
   906  

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


.config.gz
Description: application/gzip


Re: [PATCH v3 4/5] target: split out helper for cxn timeout error stashing

2018-10-14 Thread David Disseldorp
On Sun, 14 Oct 2018 11:43:34 +0800, kbuild test robot wrote:

> Thank you for the patch! Yet something to improve:
> 
> [auto build test ERROR on target/master]
> [also build test ERROR on v4.19-rc7 next-20181012]
> [if your patch is applied to the wrong git tree, please drop us a note to 
> help improve the system]
...
>drivers/target/iscsi/iscsi_target_util.c: In function 
> 'iscsit_handle_nopin_response_timeout':
> >> drivers/target/iscsi/iscsi_target_util.c:902:36: error: 'sess' undeclared 
> >> (first use in this function)

This patch is a v3 respin of an individual patch within the series:
[PATCH v2 0/5] target: improve Data-Out and NOP timeout error reporting
The sess declaration is provided in [PATCH v2 3/5].

I guess I'll resend entire series in future to avoid false kbuild
reports.

Cheers, David


Re: [PATCH 02/19] megaraid_sas: Add support for FW snap dump

2018-10-14 Thread Christoph Hellwig
> +
> + instance->snapdump_prop =
> + pci_alloc_consistent(pdev,
> +  sizeof(struct 
> MR_SNAPDUMP_PROPERTIES),
> +  &instance->snapdump_prop_h);

No new calls to the PCI DMA API please.

Please also review my patch titled
"[PATCH 13/28] megaraid_sas: switch to generic DMA API" that I sent to
the list earlier this week and preferably rebase on top of it.


switch most scsi drivers to the generic DMA API v2

2018-10-14 Thread Christoph Hellwig
A lot of SCSI drivers still use the legacy PCI DMA API.  While a few of
them have various oddities that should be deal with separately, most of
them can be very trivially converted over.

Two interesting things to look out for:

  - pci_(z)alloc_consistent forced GFP_ATOMIC allocations, which is a bad
idea almost all the time.  All these patches switch over to GFP_KERNEL.
The few drivers were we can't do this will be deal with separately.
  - a lot of odd things were going on when setting the dma mask.  This
series switches to use dma_set_mask_and_coherent where possible.

Change since v1:
 - minor indentation and comment fixups
 - collected various reviewed-by/acked-by/tested-by tags


[PATCH 04/28] 3w-sas: fully convert to the generic DMA API

2018-10-14 Thread Christoph Hellwig
The driver is currently using an odd mix of legacy PCI DMA API and
generic DMA API calls, switch it over to the generic API entirely.

Signed-off-by: Christoph Hellwig 
Acked-by: Adam Radford 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/3w-sas.c | 38 +-
 1 file changed, 17 insertions(+), 21 deletions(-)

diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c
index 40c1e6e64f58..266bdac75304 100644
--- a/drivers/scsi/3w-sas.c
+++ b/drivers/scsi/3w-sas.c
@@ -644,8 +644,8 @@ static int twl_allocate_memory(TW_Device_Extension *tw_dev, 
int size, int which)
unsigned long *cpu_addr;
int retval = 1;
 
-   cpu_addr = pci_zalloc_consistent(tw_dev->tw_pci_dev, size * TW_Q_LENGTH,
-&dma_handle);
+   cpu_addr = dma_zalloc_coherent(&tw_dev->tw_pci_dev->dev,
+   size * TW_Q_LENGTH, &dma_handle, GFP_KERNEL);
if (!cpu_addr) {
TW_PRINTK(tw_dev->host, TW_DRIVER, 0x5, "Memory allocation 
failed");
goto out;
@@ -899,19 +899,19 @@ static int twl_fill_sense(TW_Device_Extension *tw_dev, 
int i, int request_id, in
 static void twl_free_device_extension(TW_Device_Extension *tw_dev)
 {
if (tw_dev->command_packet_virt[0])
-   pci_free_consistent(tw_dev->tw_pci_dev,
+   dma_free_coherent(&tw_dev->tw_pci_dev->dev,
sizeof(TW_Command_Full)*TW_Q_LENGTH,
tw_dev->command_packet_virt[0],
tw_dev->command_packet_phys[0]);
 
if (tw_dev->generic_buffer_virt[0])
-   pci_free_consistent(tw_dev->tw_pci_dev,
+   dma_free_coherent(&tw_dev->tw_pci_dev->dev,
TW_SECTOR_SIZE*TW_Q_LENGTH,
tw_dev->generic_buffer_virt[0],
tw_dev->generic_buffer_phys[0]);
 
if (tw_dev->sense_buffer_virt[0])
-   pci_free_consistent(tw_dev->tw_pci_dev,
+   dma_free_coherent(&tw_dev->tw_pci_dev->dev,
sizeof(TW_Command_Apache_Header)*
TW_Q_LENGTH,
tw_dev->sense_buffer_virt[0],
@@ -1571,14 +1571,12 @@ static int twl_probe(struct pci_dev *pdev, const struct 
pci_device_id *dev_id)
pci_set_master(pdev);
pci_try_set_mwi(pdev);
 
-   if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64))
-   || pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
-   if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
-   || pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
-   TW_PRINTK(host, TW_DRIVER, 0x18, "Failed to set dma 
mask");
-   retval = -ENODEV;
-   goto out_disable_device;
-   }
+   if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) ||
+   dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32))) {
+   TW_PRINTK(host, TW_DRIVER, 0x18, "Failed to set dma mask");
+   retval = -ENODEV;
+   goto out_disable_device;
+   }
 
host = scsi_host_alloc(&driver_template, sizeof(TW_Device_Extension));
if (!host) {
@@ -1805,14 +1803,12 @@ static int twl_resume(struct pci_dev *pdev)
pci_set_master(pdev);
pci_try_set_mwi(pdev);
 
-   if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64))
-   || pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
-   if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
-   || pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
-   TW_PRINTK(host, TW_DRIVER, 0x25, "Failed to set dma 
mask during resume");
-   retval = -ENODEV;
-   goto out_disable_device;
-   }
+   if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) ||
+   dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32))) {
+   TW_PRINTK(host, TW_DRIVER, 0x25, "Failed to set dma mask during 
resume");
+   retval = -ENODEV;
+   goto out_disable_device;
+   }
 
/* Initialize the card */
if (twl_reset_sequence(tw_dev, 0)) {
-- 
2.19.1



[PATCH 06/28] a100u2w: switch to generic DMA API

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

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/a100u2w.c | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/a100u2w.c b/drivers/scsi/a100u2w.c
index 23b17621b6d2..00072ed9540b 100644
--- a/drivers/scsi/a100u2w.c
+++ b/drivers/scsi/a100u2w.c
@@ -1094,7 +1094,7 @@ static int inia100_probe_one(struct pci_dev *pdev,
 
if (pci_enable_device(pdev))
goto out;
-   if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
+   if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
printk(KERN_WARNING "Unable to set 32bit DMA "
"on inia100 adapter, ignoring.\n");
goto out_disable_device;
@@ -1124,7 +1124,8 @@ static int inia100_probe_one(struct pci_dev *pdev,
 
/* Get total memory needed for SCB */
sz = ORC_MAXQUEUE * sizeof(struct orc_scb);
-   host->scb_virt = pci_zalloc_consistent(pdev, sz, &host->scb_phys);
+   host->scb_virt = dma_zalloc_coherent(&pdev->dev, sz, &host->scb_phys,
+GFP_KERNEL);
if (!host->scb_virt) {
printk("inia100: SCB memory allocation error\n");
goto out_host_put;
@@ -1132,7 +1133,8 @@ static int inia100_probe_one(struct pci_dev *pdev,
 
/* Get total memory needed for ESCB */
sz = ORC_MAXQUEUE * sizeof(struct orc_extended_scb);
-   host->escb_virt = pci_zalloc_consistent(pdev, sz, &host->escb_phys);
+   host->escb_virt = dma_zalloc_coherent(&pdev->dev, sz, &host->escb_phys,
+ GFP_KERNEL);
if (!host->escb_virt) {
printk("inia100: ESCB memory allocation error\n");
goto out_free_scb_array;
@@ -1177,10 +1179,12 @@ static int inia100_probe_one(struct pci_dev *pdev,
 out_free_irq:
 free_irq(shost->irq, shost);
 out_free_escb_array:
-   pci_free_consistent(pdev, ORC_MAXQUEUE * sizeof(struct 
orc_extended_scb),
+   dma_free_coherent(&pdev->dev,
+   ORC_MAXQUEUE * sizeof(struct orc_extended_scb),
host->escb_virt, host->escb_phys);
 out_free_scb_array:
-   pci_free_consistent(pdev, ORC_MAXQUEUE * sizeof(struct orc_scb),
+   dma_free_coherent(&pdev->dev,
+   ORC_MAXQUEUE * sizeof(struct orc_scb),
host->scb_virt, host->scb_phys);
 out_host_put:
scsi_host_put(shost);
@@ -1200,9 +1204,11 @@ static void inia100_remove_one(struct pci_dev *pdev)
scsi_remove_host(shost);
 
 free_irq(shost->irq, shost);
-   pci_free_consistent(pdev, ORC_MAXQUEUE * sizeof(struct 
orc_extended_scb),
+   dma_free_coherent(&pdev->dev,
+   ORC_MAXQUEUE * sizeof(struct orc_extended_scb),
host->escb_virt, host->escb_phys);
-   pci_free_consistent(pdev, ORC_MAXQUEUE * sizeof(struct orc_scb),
+   dma_free_coherent(&pdev->dev,
+   ORC_MAXQUEUE * sizeof(struct orc_scb),
host->scb_virt, host->scb_phys);
 release_region(shost->io_port, 256);
 
-- 
2.19.1



[PATCH 18/28] pm8001: switch to generic DMA API

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

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
Reviewed-by: Jack Wang 
---
 drivers/scsi/pm8001/pm8001_hwi.c  | 22 +++---
 drivers/scsi/pm8001/pm8001_init.c | 28 +---
 drivers/scsi/pm8001/pm8001_sas.c  |  8 
 drivers/scsi/pm8001/pm80xx_hwi.c  | 22 +++---
 4 files changed, 31 insertions(+), 49 deletions(-)

diff --git a/drivers/scsi/pm8001/pm8001_hwi.c b/drivers/scsi/pm8001/pm8001_hwi.c
index e37ab9789ba6..d0bb357034d8 100644
--- a/drivers/scsi/pm8001/pm8001_hwi.c
+++ b/drivers/scsi/pm8001/pm8001_hwi.c
@@ -2420,7 +2420,7 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, 
void *piomb)
sata_resp = &psataPayload->sata_resp[0];
resp = (struct ata_task_resp *)ts->buf;
if (t->ata_task.dma_xfer == 0 &&
-   t->data_dir == PCI_DMA_FROMDEVICE) {
+   t->data_dir == DMA_FROM_DEVICE) {
len = sizeof(struct pio_setup_fis);
PM8001_IO_DBG(pm8001_ha,
pm8001_printk("PIO read len = %d\n", len));
@@ -4203,12 +4203,12 @@ static int process_oq(struct pm8001_hba_info 
*pm8001_ha, u8 vec)
return ret;
 }
 
-/* PCI_DMA_... to our direction translation. */
+/* DMA_... to our direction translation. */
 static const u8 data_dir_flags[] = {
-   [PCI_DMA_BIDIRECTIONAL] = DATA_DIR_BYRECIPIENT,/* UNSPECIFIED */
-   [PCI_DMA_TODEVICE]  = DATA_DIR_OUT,/* OUTBOUND */
-   [PCI_DMA_FROMDEVICE]= DATA_DIR_IN,/* INBOUND */
-   [PCI_DMA_NONE]  = DATA_DIR_NONE,/* NO TRANSFER */
+   [DMA_BIDIRECTIONAL] = DATA_DIR_BYRECIPIENT, /* UNSPECIFIED */
+   [DMA_TO_DEVICE] = DATA_DIR_OUT, /* OUTBOUND */
+   [DMA_FROM_DEVICE]   = DATA_DIR_IN,  /* INBOUND */
+   [DMA_NONE]  = DATA_DIR_NONE,/* NO TRANSFER */
 };
 void
 pm8001_chip_make_sg(struct scatterlist *scatter, int nr, void *prd)
@@ -4255,13 +4255,13 @@ static int pm8001_chip_smp_req(struct pm8001_hba_info 
*pm8001_ha,
 * DMA-map SMP request, response buffers
 */
sg_req = &task->smp_task.smp_req;
-   elem = dma_map_sg(pm8001_ha->dev, sg_req, 1, PCI_DMA_TODEVICE);
+   elem = dma_map_sg(pm8001_ha->dev, sg_req, 1, DMA_TO_DEVICE);
if (!elem)
return -ENOMEM;
req_len = sg_dma_len(sg_req);
 
sg_resp = &task->smp_task.smp_resp;
-   elem = dma_map_sg(pm8001_ha->dev, sg_resp, 1, PCI_DMA_FROMDEVICE);
+   elem = dma_map_sg(pm8001_ha->dev, sg_resp, 1, DMA_FROM_DEVICE);
if (!elem) {
rc = -ENOMEM;
goto err_out;
@@ -4294,10 +4294,10 @@ static int pm8001_chip_smp_req(struct pm8001_hba_info 
*pm8001_ha,
 
 err_out_2:
dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_resp, 1,
-   PCI_DMA_FROMDEVICE);
+   DMA_FROM_DEVICE);
 err_out:
dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_req, 1,
-   PCI_DMA_TODEVICE);
+   DMA_TO_DEVICE);
return rc;
 }
 
@@ -4376,7 +4376,7 @@ static int pm8001_chip_sata_req(struct pm8001_hba_info 
*pm8001_ha,
u32  opc = OPC_INB_SATA_HOST_OPSTART;
memset(&sata_cmd, 0, sizeof(sata_cmd));
circularQ = &pm8001_ha->inbnd_q_tbl[0];
-   if (task->data_dir == PCI_DMA_NONE) {
+   if (task->data_dir == DMA_NONE) {
ATAP = 0x04;  /* no data*/
PM8001_IO_DBG(pm8001_ha, pm8001_printk("no data\n"));
} else if (likely(!task->ata_task.device_control_reg_update)) {
diff --git a/drivers/scsi/pm8001/pm8001_init.c 
b/drivers/scsi/pm8001/pm8001_init.c
index 501830caba21..d71e7e4ec29c 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -152,7 +152,7 @@ static void pm8001_free(struct pm8001_hba_info *pm8001_ha)
 
for (i = 0; i < USI_MAX_MEMCNT; i++) {
if (pm8001_ha->memoryMap.region[i].virt_ptr != NULL) {
-   pci_free_consistent(pm8001_ha->pdev,
+   dma_free_coherent(&pm8001_ha->pdev->dev,
(pm8001_ha->memoryMap.region[i].total_len +
pm8001_ha->memoryMap.region[i].alignment),
pm8001_ha->memoryMap.region[i].virt_ptr,
@@ -501,30 +501,12 @@ static int pci_go_44(struct pci_dev *pdev)
 {
int rc;
 
-   if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(44))) {
-   rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(44));
-   if (rc) {
-   rc = pci_set_consistent_dma_mask(pdev,
-   DMA_BIT_MASK(32));
-   if (rc) {
-   dev_printk(KERN_ERR, &pdev->dev,
-

[PATCH 05/28] BusLogic: switch to generic DMA API

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

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/BusLogic.c | 36 +++-
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
index 0d4ffe0ae306..9cee941f97d6 100644
--- a/drivers/scsi/BusLogic.c
+++ b/drivers/scsi/BusLogic.c
@@ -201,8 +201,8 @@ static bool __init blogic_create_initccbs(struct 
blogic_adapter *adapter)
dma_addr_t blkp;
 
while (adapter->alloc_ccbs < adapter->initccbs) {
-   blk_pointer = pci_alloc_consistent(adapter->pci_device,
-   blk_size, &blkp);
+   blk_pointer = dma_alloc_coherent(&adapter->pci_device->dev,
+   blk_size, &blkp, GFP_KERNEL);
if (blk_pointer == NULL) {
blogic_err("UNABLE TO ALLOCATE CCB GROUP - DETACHING\n",
adapter);
@@ -227,15 +227,16 @@ static void blogic_destroy_ccbs(struct blogic_adapter 
*adapter)
next_ccb = ccb->next_all;
if (ccb->allocgrp_head) {
if (lastccb)
-   pci_free_consistent(adapter->pci_device,
+   dma_free_coherent(&adapter->pci_device->dev,
lastccb->allocgrp_size, lastccb,
lastccb->allocgrp_head);
lastccb = ccb;
}
}
if (lastccb)
-   pci_free_consistent(adapter->pci_device, lastccb->allocgrp_size,
-   lastccb, lastccb->allocgrp_head);
+   dma_free_coherent(&adapter->pci_device->dev,
+   lastccb->allocgrp_size, lastccb,
+   lastccb->allocgrp_head);
 }
 
 
@@ -256,8 +257,8 @@ static void blogic_create_addlccbs(struct blogic_adapter 
*adapter,
if (addl_ccbs <= 0)
return;
while (adapter->alloc_ccbs - prev_alloc < addl_ccbs) {
-   blk_pointer = pci_alloc_consistent(adapter->pci_device,
-   blk_size, &blkp);
+   blk_pointer = dma_alloc_coherent(&adapter->pci_device->dev,
+   blk_size, &blkp, GFP_KERNEL);
if (blk_pointer == NULL)
break;
blogic_init_ccbs(adapter, blk_pointer, blk_size, blkp);
@@ -318,8 +319,8 @@ static void blogic_dealloc_ccb(struct blogic_ccb *ccb, int 
dma_unmap)
if (ccb->command != NULL)
scsi_dma_unmap(ccb->command);
if (dma_unmap)
-   pci_unmap_single(adapter->pci_device, ccb->sensedata,
-ccb->sense_datalen, PCI_DMA_FROMDEVICE);
+   dma_unmap_single(&adapter->pci_device->dev, ccb->sensedata,
+ccb->sense_datalen, DMA_FROM_DEVICE);
 
ccb->command = NULL;
ccb->status = BLOGIC_CCB_FREE;
@@ -712,7 +713,7 @@ static int __init blogic_init_mm_probeinfo(struct 
blogic_adapter *adapter)
if (pci_enable_device(pci_device))
continue;
 
-   if (pci_set_dma_mask(pci_device, DMA_BIT_MASK(32)))
+   if (dma_set_mask(&pci_device->dev, DMA_BIT_MASK(32)))
continue;
 
bus = pci_device->bus->number;
@@ -895,7 +896,7 @@ static int __init blogic_init_mm_probeinfo(struct 
blogic_adapter *adapter)
if (pci_enable_device(pci_device))
continue;
 
-   if (pci_set_dma_mask(pci_device, DMA_BIT_MASK(32)))
+   if (dma_set_mask(&pci_device->dev, DMA_BIT_MASK(32)))
continue;
 
bus = pci_device->bus->number;
@@ -952,7 +953,7 @@ static int __init blogic_init_fp_probeinfo(struct 
blogic_adapter *adapter)
if (pci_enable_device(pci_device))
continue;
 
-   if (pci_set_dma_mask(pci_device, DMA_BIT_MASK(32)))
+   if (dma_set_mask(&pci_device->dev, DMA_BIT_MASK(32)))
continue;
 
bus = pci_device->bus->number;
@@ -2040,7 +2041,7 @@ static void blogic_relres(struct blogic_adapter *adapter)
   Release any allocated memory structs not released elsewhere
 */
if (adapter->mbox_space)
-   pci_free_consistent(adapter->pci_device, adapter->mbox_sz,
+   dma_free_coherent(&adapter->pci_device->dev, adapter->mbox_sz,
adapter->mbox_space, adapter->mbox_space_handle);
pci_dev_put(adapter->pci_device);
adapter->mbox_space = NULL;
@@ -2092,8 +2093,9 @@ static bool blogic_initadapter(struct blogic_adapter 
*adapter)
   Initialize the Outgoin

[PATCH 15/28] mvumi: switch to generic DMA API

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

Also reuse an existing helper (after fixing the error return) to set the
DMA mask instead of having three copies of the code.

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/mvumi.c | 89 ++--
 1 file changed, 36 insertions(+), 53 deletions(-)

diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index b3cd9a6b1d30..2458974d1af6 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -143,8 +143,8 @@ static struct mvumi_res *mvumi_alloc_mem_resource(struct 
mvumi_hba *mhba,
 
case RESOURCE_UNCACHED_MEMORY:
size = round_up(size, 8);
-   res->virt_addr = pci_zalloc_consistent(mhba->pdev, size,
-  &res->bus_addr);
+   res->virt_addr = dma_zalloc_coherent(&mhba->pdev->dev, size,
+   &res->bus_addr, GFP_KERNEL);
if (!res->virt_addr) {
dev_err(&mhba->pdev->dev,
"unable to allocate consistent mem,"
@@ -175,7 +175,7 @@ static void mvumi_release_mem_resource(struct mvumi_hba 
*mhba)
list_for_each_entry_safe(res, tmp, &mhba->res_list, entry) {
switch (res->type) {
case RESOURCE_UNCACHED_MEMORY:
-   pci_free_consistent(mhba->pdev, res->size,
+   dma_free_coherent(&mhba->pdev->dev, res->size,
res->virt_addr, res->bus_addr);
break;
case RESOURCE_CACHED_MEMORY:
@@ -211,14 +211,14 @@ static int mvumi_make_sgl(struct mvumi_hba *mhba, struct 
scsi_cmnd *scmd,
dma_addr_t busaddr;
 
sg = scsi_sglist(scmd);
-   *sg_count = pci_map_sg(mhba->pdev, sg, sgnum,
-  (int) scmd->sc_data_direction);
+   *sg_count = dma_map_sg(&mhba->pdev->dev, sg, sgnum,
+  scmd->sc_data_direction);
if (*sg_count > mhba->max_sge) {
dev_err(&mhba->pdev->dev,
"sg count[0x%x] is bigger than max sg[0x%x].\n",
*sg_count, mhba->max_sge);
-   pci_unmap_sg(mhba->pdev, sg, sgnum,
-(int) scmd->sc_data_direction);
+   dma_unmap_sg(&mhba->pdev->dev, sg, sgnum,
+scmd->sc_data_direction);
return -1;
}
for (i = 0; i < *sg_count; i++) {
@@ -246,7 +246,8 @@ static int mvumi_internal_cmd_sgl(struct mvumi_hba *mhba, 
struct mvumi_cmd *cmd,
if (size == 0)
return 0;
 
-   virt_addr = pci_zalloc_consistent(mhba->pdev, size, &phy_addr);
+   virt_addr = dma_zalloc_coherent(&mhba->pdev->dev, size, &phy_addr,
+   GFP_KERNEL);
if (!virt_addr)
return -1;
 
@@ -274,8 +275,8 @@ static struct mvumi_cmd *mvumi_create_internal_cmd(struct 
mvumi_hba *mhba,
}
INIT_LIST_HEAD(&cmd->queue_pointer);
 
-   cmd->frame = pci_alloc_consistent(mhba->pdev,
-   mhba->ib_max_size, &cmd->frame_phys);
+   cmd->frame = dma_alloc_coherent(&mhba->pdev->dev, mhba->ib_max_size,
+   &cmd->frame_phys, GFP_KERNEL);
if (!cmd->frame) {
dev_err(&mhba->pdev->dev, "failed to allocate memory for FW"
" frame,size = %d.\n", mhba->ib_max_size);
@@ -287,7 +288,7 @@ static struct mvumi_cmd *mvumi_create_internal_cmd(struct 
mvumi_hba *mhba,
if (mvumi_internal_cmd_sgl(mhba, cmd, buf_size)) {
dev_err(&mhba->pdev->dev, "failed to allocate memory"
" for internal frame\n");
-   pci_free_consistent(mhba->pdev, mhba->ib_max_size,
+   dma_free_coherent(&mhba->pdev->dev, mhba->ib_max_size,
cmd->frame, cmd->frame_phys);
kfree(cmd);
return NULL;
@@ -313,10 +314,10 @@ static void mvumi_delete_internal_cmd(struct mvumi_hba 
*mhba,
phy_addr = (dma_addr_t) m_sg->baseaddr_l |
(dma_addr_t) ((m_sg->baseaddr_h << 16) << 16);
 
-   pci_free_consistent(mhba->pdev, size, cmd->data_buf,
+   dma_free_coherent(&mhba->pdev->dev, size, cmd->data_buf,
phy_addr);
}
-   pci_free_consistent(mhba->pdev, mhba->ib_max_size,
+   dma_free_coherent(&mhba->pdev->dev, mhba->ib_max_size,
cmd->frame, cmd->frame_phys);
kfree(cmd);
}
@@ -663,16 +664,17 @@ static void mvumi_restore_bar_addr(struct mvumi_hba *mhba)
}
 }
 
-st

[PATCH 02/28] 3w-9xxx: fully convert to the generic DMA API

2018-10-14 Thread Christoph Hellwig
The driver is currently using an odd mix of legacy PCI DMA API and
generic DMA API calls, switch it over to the generic API entirely.

Signed-off-by: Christoph Hellwig 
Acked-by: Adam Radford 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/3w-9xxx.c | 50 --
 1 file changed, 24 insertions(+), 26 deletions(-)

diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index 27521fc3ef5a..05293babb031 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -518,7 +518,8 @@ static int twa_allocate_memory(TW_Device_Extension *tw_dev, 
int size, int which)
unsigned long *cpu_addr;
int retval = 1;
 
-   cpu_addr = pci_alloc_consistent(tw_dev->tw_pci_dev, size*TW_Q_LENGTH, 
&dma_handle);
+   cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev,
+   size * TW_Q_LENGTH, &dma_handle, GFP_KERNEL);
if (!cpu_addr) {
TW_PRINTK(tw_dev->host, TW_DRIVER, 0x5, "Memory allocation 
failed");
goto out;
@@ -526,7 +527,8 @@ static int twa_allocate_memory(TW_Device_Extension *tw_dev, 
int size, int which)
 
if ((unsigned long)cpu_addr % (TW_ALIGNMENT_9000)) {
TW_PRINTK(tw_dev->host, TW_DRIVER, 0x6, "Failed to allocate 
correctly aligned memory");
-   pci_free_consistent(tw_dev->tw_pci_dev, size*TW_Q_LENGTH, 
cpu_addr, dma_handle);
+   dma_free_coherent(&tw_dev->tw_pci_dev->dev, size * TW_Q_LENGTH,
+   cpu_addr, dma_handle);
goto out;
}
 
@@ -1027,16 +1029,16 @@ static int twa_fill_sense(TW_Device_Extension *tw_dev, 
int request_id, int copy_
 static void twa_free_device_extension(TW_Device_Extension *tw_dev)
 {
if (tw_dev->command_packet_virt[0])
-   pci_free_consistent(tw_dev->tw_pci_dev,
-   sizeof(TW_Command_Full)*TW_Q_LENGTH,
-   tw_dev->command_packet_virt[0],
-   tw_dev->command_packet_phys[0]);
+   dma_free_coherent(&tw_dev->tw_pci_dev->dev,
+   sizeof(TW_Command_Full) * TW_Q_LENGTH,
+   tw_dev->command_packet_virt[0],
+   tw_dev->command_packet_phys[0]);
 
if (tw_dev->generic_buffer_virt[0])
-   pci_free_consistent(tw_dev->tw_pci_dev,
-   TW_SECTOR_SIZE*TW_Q_LENGTH,
-   tw_dev->generic_buffer_virt[0],
-   tw_dev->generic_buffer_phys[0]);
+   dma_free_coherent(&tw_dev->tw_pci_dev->dev,
+   TW_SECTOR_SIZE * TW_Q_LENGTH,
+   tw_dev->generic_buffer_virt[0],
+   tw_dev->generic_buffer_phys[0]);
 
kfree(tw_dev->event_queue[0]);
 } /* End twa_free_device_extension() */
@@ -2015,14 +2017,12 @@ static int twa_probe(struct pci_dev *pdev, const struct 
pci_device_id *dev_id)
pci_set_master(pdev);
pci_try_set_mwi(pdev);
 
-   if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64))
-   || pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
-   if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
-   || pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
-   TW_PRINTK(host, TW_DRIVER, 0x23, "Failed to set dma 
mask");
-   retval = -ENODEV;
-   goto out_disable_device;
-   }
+   if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) ||
+   dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32))) {
+   TW_PRINTK(host, TW_DRIVER, 0x23, "Failed to set dma mask");
+   retval = -ENODEV;
+   goto out_disable_device;
+   }
 
host = scsi_host_alloc(&driver_template, sizeof(TW_Device_Extension));
if (!host) {
@@ -2237,14 +2237,12 @@ static int twa_resume(struct pci_dev *pdev)
pci_set_master(pdev);
pci_try_set_mwi(pdev);
 
-   if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64))
-   || pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
-   if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
-   || pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
-   TW_PRINTK(host, TW_DRIVER, 0x40, "Failed to set dma 
mask during resume");
-   retval = -ENODEV;
-   goto out_disable_device;
-   }
+   if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) ||
+   dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32))) {
+   TW_PRINTK(host, TW_DRIVER, 0x40, "Failed to set dma mask during 
resume");
+   retval = -ENODEV;
+   goto out_disable_device;
+   }
 
/* Initialize the card */
if (twa_reset_sequence(tw_dev, 0)) {
-- 
2.19.1



[PATCH 16/28] mvsas: fully convert to the generic DMA API

2018-10-14 Thread Christoph Hellwig
The driver is currently using an odd mix of legacy PCI DMA API and
generic DMA API calls, switch it over to the generic API entirely.

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/mvsas/mv_init.c | 21 +++--
 drivers/scsi/mvsas/mv_sas.c  | 12 ++--
 2 files changed, 9 insertions(+), 24 deletions(-)

diff --git a/drivers/scsi/mvsas/mv_init.c b/drivers/scsi/mvsas/mv_init.c
index 8c91637cd598..3ac34373746c 100644
--- a/drivers/scsi/mvsas/mv_init.c
+++ b/drivers/scsi/mvsas/mv_init.c
@@ -403,29 +403,14 @@ static int pci_go_64(struct pci_dev *pdev)
 {
int rc;
 
-   if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
-   rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
-   if (rc) {
-   rc = pci_set_consistent_dma_mask(pdev, 
DMA_BIT_MASK(32));
-   if (rc) {
-   dev_printk(KERN_ERR, &pdev->dev,
-  "64-bit DMA enable failed\n");
-   return rc;
-   }
-   }
-   } else {
-   rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
+   rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
+   if (rc) {
+   rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
if (rc) {
dev_printk(KERN_ERR, &pdev->dev,
   "32-bit DMA enable failed\n");
return rc;
}
-   rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
-   if (rc) {
-   dev_printk(KERN_ERR, &pdev->dev,
-  "32-bit consistent DMA enable failed\n");
-   return rc;
-   }
}
 
return rc;
diff --git a/drivers/scsi/mvsas/mv_sas.c b/drivers/scsi/mvsas/mv_sas.c
index cff43bd9f675..3df1428df317 100644
--- a/drivers/scsi/mvsas/mv_sas.c
+++ b/drivers/scsi/mvsas/mv_sas.c
@@ -336,13 +336,13 @@ static int mvs_task_prep_smp(struct mvs_info *mvi,
 * DMA-map SMP request, response buffers
 */
sg_req = &task->smp_task.smp_req;
-   elem = dma_map_sg(mvi->dev, sg_req, 1, PCI_DMA_TODEVICE);
+   elem = dma_map_sg(mvi->dev, sg_req, 1, DMA_TO_DEVICE);
if (!elem)
return -ENOMEM;
req_len = sg_dma_len(sg_req);
 
sg_resp = &task->smp_task.smp_resp;
-   elem = dma_map_sg(mvi->dev, sg_resp, 1, PCI_DMA_FROMDEVICE);
+   elem = dma_map_sg(mvi->dev, sg_resp, 1, DMA_FROM_DEVICE);
if (!elem) {
rc = -ENOMEM;
goto err_out;
@@ -416,10 +416,10 @@ static int mvs_task_prep_smp(struct mvs_info *mvi,
 
 err_out_2:
dma_unmap_sg(mvi->dev, &tei->task->smp_task.smp_resp, 1,
-PCI_DMA_FROMDEVICE);
+DMA_FROM_DEVICE);
 err_out:
dma_unmap_sg(mvi->dev, &tei->task->smp_task.smp_req, 1,
-PCI_DMA_TODEVICE);
+DMA_TO_DEVICE);
return rc;
 }
 
@@ -904,9 +904,9 @@ static void mvs_slot_task_free(struct mvs_info *mvi, struct 
sas_task *task,
switch (task->task_proto) {
case SAS_PROTOCOL_SMP:
dma_unmap_sg(mvi->dev, &task->smp_task.smp_resp, 1,
-PCI_DMA_FROMDEVICE);
+DMA_FROM_DEVICE);
dma_unmap_sg(mvi->dev, &task->smp_task.smp_req, 1,
-PCI_DMA_TODEVICE);
+DMA_TO_DEVICE);
break;
 
case SAS_PROTOCOL_SATA:
-- 
2.19.1



[PATCH 08/28] be2iscsi: switch to generic DMA API

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

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/be2iscsi/be_cmds.c  | 10 ++---
 drivers/scsi/be2iscsi/be_iscsi.c | 13 +++---
 drivers/scsi/be2iscsi/be_main.c  | 72 ++--
 drivers/scsi/be2iscsi/be_mgmt.c  | 27 ++--
 4 files changed, 58 insertions(+), 64 deletions(-)

diff --git a/drivers/scsi/be2iscsi/be_cmds.c b/drivers/scsi/be2iscsi/be_cmds.c
index c10aac4dbc5e..0a6972ee94d7 100644
--- a/drivers/scsi/be2iscsi/be_cmds.c
+++ b/drivers/scsi/be2iscsi/be_cmds.c
@@ -520,7 +520,7 @@ int beiscsi_process_mcc_compl(struct be_ctrl_info *ctrl,
 **/
tag_mem = &ctrl->ptag_state[tag].tag_mem_state;
if (tag_mem->size) {
-   pci_free_consistent(ctrl->pdev, tag_mem->size,
+   dma_free_coherent(&ctrl->pdev->dev, tag_mem->size,
tag_mem->va, tag_mem->dma);
tag_mem->size = 0;
}
@@ -1269,12 +1269,12 @@ int beiscsi_check_supported_fw(struct be_ctrl_info 
*ctrl,
struct be_sge *sge = nonembedded_sgl(wrb);
int status = 0;
 
-   nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev,
+   nonemb_cmd.va = dma_alloc_coherent(&ctrl->pdev->dev,
sizeof(struct be_mgmt_controller_attributes),
-   &nonemb_cmd.dma);
+   &nonemb_cmd.dma, GFP_KERNEL);
if (nonemb_cmd.va == NULL) {
beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
-   "BG_%d : pci_alloc_consistent failed in %s\n",
+   "BG_%d : dma_alloc_coherent failed in %s\n",
__func__);
return -ENOMEM;
}
@@ -1314,7 +1314,7 @@ int beiscsi_check_supported_fw(struct be_ctrl_info *ctrl,
"BG_%d :  Failed in beiscsi_check_supported_fw\n");
mutex_unlock(&ctrl->mbox_lock);
if (nonemb_cmd.va)
-   pci_free_consistent(ctrl->pdev, nonemb_cmd.size,
+   dma_free_coherent(&ctrl->pdev->dev, nonemb_cmd.size,
nonemb_cmd.va, nonemb_cmd.dma);
 
return status;
diff --git a/drivers/scsi/be2iscsi/be_iscsi.c b/drivers/scsi/be2iscsi/be_iscsi.c
index c8f0a2144b44..913290378afb 100644
--- a/drivers/scsi/be2iscsi/be_iscsi.c
+++ b/drivers/scsi/be2iscsi/be_iscsi.c
@@ -1071,9 +1071,9 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep,
else
req_memsize = sizeof(struct tcp_connect_and_offload_in_v1);
 
-   nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
+   nonemb_cmd.va = dma_alloc_coherent(&phba->ctrl.pdev->dev,
req_memsize,
-   &nonemb_cmd.dma);
+   &nonemb_cmd.dma, GFP_KERNEL);
if (nonemb_cmd.va == NULL) {
 
beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
@@ -1091,7 +1091,7 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep,
"BS_%d : mgmt_open_connection Failed for cid=%d\n",
beiscsi_ep->ep_cid);
 
-   pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
+   dma_free_coherent(&phba->ctrl.pdev->dev, nonemb_cmd.size,
nonemb_cmd.va, nonemb_cmd.dma);
beiscsi_free_ep(beiscsi_ep);
return -EAGAIN;
@@ -1104,8 +1104,9 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep,
"BS_%d : mgmt_open_connection Failed");
 
if (ret != -EBUSY)
-   pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
-   nonemb_cmd.va, nonemb_cmd.dma);
+   dma_free_coherent(&phba->ctrl.pdev->dev,
+   nonemb_cmd.size, nonemb_cmd.va,
+   nonemb_cmd.dma);
 
beiscsi_free_ep(beiscsi_ep);
return ret;
@@ -1118,7 +1119,7 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep,
beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
"BS_%d : mgmt_open_connection Success\n");
 
-   pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
+   dma_free_coherent(&phba->ctrl.pdev->dev, nonemb_cmd.size,
nonemb_cmd.va, nonemb_cmd.dma);
return 0;
 }
diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index d544453aa466..5278fdc2c52d 100644
--- a/drivers/scsi/be2iscsi/be_main.c
+++ b/drivers/scsi/be2iscsi/be_main.c
@@ -511,18 +511,9 @@ static int beiscsi_enable_pci(struct pci_dev *pcidev)
}
 
pci_set_master(pcidev);
-   ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(64));
+   ret = dma_set_mask_and_coherent(

[PATCH 17/28] nsp32: switch to generic DMA API

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

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/nsp32.c | 18 ++
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/nsp32.c b/drivers/scsi/nsp32.c
index 8620ac5d6e41..5aac3e801903 100644
--- a/drivers/scsi/nsp32.c
+++ b/drivers/scsi/nsp32.c
@@ -2638,7 +2638,7 @@ static int nsp32_detect(struct pci_dev *pdev)
/*
 * setup DMA 
 */
-   if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) {
+   if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)) != 0) {
nsp32_msg (KERN_ERR, "failed to set PCI DMA mask");
goto scsi_unregister;
}
@@ -2646,7 +2646,9 @@ static int nsp32_detect(struct pci_dev *pdev)
/*
 * allocate autoparam DMA resource.
 */
-   data->autoparam = pci_alloc_consistent(pdev, sizeof(nsp32_autoparam), 
&(data->auto_paddr));
+   data->autoparam = dma_alloc_coherent(&pdev->dev,
+   sizeof(nsp32_autoparam), &(data->auto_paddr),
+   GFP_KERNEL);
if (data->autoparam == NULL) {
nsp32_msg(KERN_ERR, "failed to allocate DMA memory");
goto scsi_unregister;
@@ -2655,8 +2657,8 @@ static int nsp32_detect(struct pci_dev *pdev)
/*
 * allocate scatter-gather DMA resource.
 */
-   data->sg_list = pci_alloc_consistent(pdev, NSP32_SG_TABLE_SIZE,
-&(data->sg_paddr));
+   data->sg_list = dma_alloc_coherent(&pdev->dev, NSP32_SG_TABLE_SIZE,
+   &data->sg_paddr, GFP_KERNEL);
if (data->sg_list == NULL) {
nsp32_msg(KERN_ERR, "failed to allocate DMA memory");
goto free_autoparam;
@@ -2761,11 +2763,11 @@ static int nsp32_detect(struct pci_dev *pdev)
free_irq(host->irq, data);
 
  free_sg_list:
-   pci_free_consistent(pdev, NSP32_SG_TABLE_SIZE,
+   dma_free_coherent(&pdev->dev, NSP32_SG_TABLE_SIZE,
data->sg_list, data->sg_paddr);
 
  free_autoparam:
-   pci_free_consistent(pdev, sizeof(nsp32_autoparam),
+   dma_free_coherent(&pdev->dev, sizeof(nsp32_autoparam),
data->autoparam, data->auto_paddr);

  scsi_unregister:
@@ -2780,12 +2782,12 @@ static int nsp32_release(struct Scsi_Host *host)
nsp32_hw_data *data = (nsp32_hw_data *)host->hostdata;
 
if (data->autoparam) {
-   pci_free_consistent(data->Pci, sizeof(nsp32_autoparam),
+   dma_free_coherent(&data->Pci->dev, sizeof(nsp32_autoparam),
data->autoparam, data->auto_paddr);
}
 
if (data->sg_list) {
-   pci_free_consistent(data->Pci, NSP32_SG_TABLE_SIZE,
+   dma_free_coherent(&data->Pci->dev, NSP32_SG_TABLE_SIZE,
data->sg_list, data->sg_paddr);
}
 
-- 
2.19.1



[PATCH 12/28] megaraid_mbox: switch to generic DMA API

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

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/megaraid/megaraid_mbox.c | 51 +--
 1 file changed, 25 insertions(+), 26 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_mbox.c 
b/drivers/scsi/megaraid/megaraid_mbox.c
index 89c85a5a47af..fbae1d88a29b 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -457,10 +457,9 @@ megaraid_probe_one(struct pci_dev *pdev, const struct 
pci_device_id *id)
 
// Setup the default DMA mask. This would be changed later on
// depending on hardware capabilities
-   if (pci_set_dma_mask(adapter->pdev, DMA_BIT_MASK(32)) != 0) {
-
+   if (dma_set_mask(&adapter->pdev->dev, DMA_BIT_MASK(32))) {
con_log(CL_ANN, (KERN_WARNING
-   "megaraid: pci_set_dma_mask failed:%d\n", __LINE__));
+   "megaraid: dma_set_mask failed:%d\n", __LINE__));
 
goto out_free_adapter;
}
@@ -878,11 +877,12 @@ megaraid_init_mbox(adapter_t *adapter)
adapter->pdev->device == PCI_DEVICE_ID_PERC4_DI_EVERGLADES) ||
(adapter->pdev->vendor == PCI_VENDOR_ID_DELL &&
adapter->pdev->device == PCI_DEVICE_ID_PERC4E_DI_KOBUK)) {
-   if (pci_set_dma_mask(adapter->pdev, DMA_BIT_MASK(64))) {
+   if (dma_set_mask(&adapter->pdev->dev, DMA_BIT_MASK(64))) {
con_log(CL_ANN, (KERN_WARNING
"megaraid: DMA mask for 64-bit failed\n"));
 
-   if (pci_set_dma_mask (adapter->pdev, DMA_BIT_MASK(32))) 
{
+   if (dma_set_mask(&adapter->pdev->dev,
+   DMA_BIT_MASK(32))) {
con_log(CL_ANN, (KERN_WARNING
"megaraid: 32-bit DMA mask failed\n"));
goto out_free_sysfs_res;
@@ -975,9 +975,9 @@ megaraid_alloc_cmd_packets(adapter_t *adapter)
 * Allocate the common 16-byte aligned memory for the handshake
 * mailbox.
 */
-   raid_dev->una_mbox64 = pci_zalloc_consistent(adapter->pdev,
-sizeof(mbox64_t),
-&raid_dev->una_mbox64_dma);
+   raid_dev->una_mbox64 = dma_zalloc_coherent(&adapter->pdev->dev,
+   sizeof(mbox64_t), &raid_dev->una_mbox64_dma,
+   GFP_KERNEL);
 
if (!raid_dev->una_mbox64) {
con_log(CL_ANN, (KERN_WARNING
@@ -1003,8 +1003,8 @@ megaraid_alloc_cmd_packets(adapter_t *adapter)
align;
 
// Allocate memory for commands issued internally
-   adapter->ibuf = pci_zalloc_consistent(pdev, MBOX_IBUF_SIZE,
- &adapter->ibuf_dma_h);
+   adapter->ibuf = dma_zalloc_coherent(&pdev->dev, MBOX_IBUF_SIZE,
+   &adapter->ibuf_dma_h, GFP_KERNEL);
if (!adapter->ibuf) {
 
con_log(CL_ANN, (KERN_WARNING
@@ -1082,7 +1082,7 @@ megaraid_alloc_cmd_packets(adapter_t *adapter)
 
scb->scp= NULL;
scb->state  = SCB_FREE;
-   scb->dma_direction  = PCI_DMA_NONE;
+   scb->dma_direction  = DMA_NONE;
scb->dma_type   = MRAID_DMA_NONE;
scb->dev_channel= -1;
scb->dev_target = -1;
@@ -1098,10 +1098,10 @@ megaraid_alloc_cmd_packets(adapter_t *adapter)
 out_free_scb_list:
kfree(adapter->kscb_list);
 out_free_ibuf:
-   pci_free_consistent(pdev, MBOX_IBUF_SIZE, (void *)adapter->ibuf,
+   dma_free_coherent(&pdev->dev, MBOX_IBUF_SIZE, (void *)adapter->ibuf,
adapter->ibuf_dma_h);
 out_free_common_mbox:
-   pci_free_consistent(adapter->pdev, sizeof(mbox64_t),
+   dma_free_coherent(&adapter->pdev->dev, sizeof(mbox64_t),
(caddr_t)raid_dev->una_mbox64, raid_dev->una_mbox64_dma);
 
return -1;
@@ -1123,10 +1123,10 @@ megaraid_free_cmd_packets(adapter_t *adapter)
 
kfree(adapter->kscb_list);
 
-   pci_free_consistent(adapter->pdev, MBOX_IBUF_SIZE,
+   dma_free_coherent(&adapter->pdev->dev, MBOX_IBUF_SIZE,
(void *)adapter->ibuf, adapter->ibuf_dma_h);
 
-   pci_free_consistent(adapter->pdev, sizeof(mbox64_t),
+   dma_free_coherent(&adapter->pdev->dev, sizeof(mbox64_t),
(caddr_t)raid_dev->una_mbox64, raid_dev->una_mbox64_dma);
return;
 }
@@ -2915,9 +2915,8 @@ megaraid_mbox_product_info(adapter_t *adapter)
 * Issue an ENQUIRY3 command to find out certain adapter parameters,
 * e.g., max channels, max commands etc.
 */
-   pinfo = pci_zalloc_consistent(adapter->pdev, sizeof(mraid_pi

[PATCH 13/28] megaraid_sas: switch to generic DMA API

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

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/megaraid/megaraid_sas_base.c   | 150 ++--
 drivers/scsi/megaraid/megaraid_sas_fusion.c |  16 +--
 2 files changed, 83 insertions(+), 83 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index 9aa9590c5373..f35deb109905 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -1330,11 +1330,11 @@ megasas_build_dcdb(struct megasas_instance *instance, 
struct scsi_cmnd *scp,
device_id = MEGASAS_DEV_INDEX(scp);
pthru = (struct megasas_pthru_frame *)cmd->frame;
 
-   if (scp->sc_data_direction == PCI_DMA_TODEVICE)
+   if (scp->sc_data_direction == DMA_TO_DEVICE)
flags = MFI_FRAME_DIR_WRITE;
-   else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE)
+   else if (scp->sc_data_direction == DMA_FROM_DEVICE)
flags = MFI_FRAME_DIR_READ;
-   else if (scp->sc_data_direction == PCI_DMA_NONE)
+   else if (scp->sc_data_direction == DMA_NONE)
flags = MFI_FRAME_DIR_NONE;
 
if (instance->flag_ieee == 1) {
@@ -1428,9 +1428,9 @@ megasas_build_ldio(struct megasas_instance *instance, 
struct scsi_cmnd *scp,
device_id = MEGASAS_DEV_INDEX(scp);
ldio = (struct megasas_io_frame *)cmd->frame;
 
-   if (scp->sc_data_direction == PCI_DMA_TODEVICE)
+   if (scp->sc_data_direction == DMA_TO_DEVICE)
flags = MFI_FRAME_DIR_WRITE;
-   else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE)
+   else if (scp->sc_data_direction == DMA_FROM_DEVICE)
flags = MFI_FRAME_DIR_READ;
 
if (instance->flag_ieee == 1) {
@@ -2240,9 +2240,9 @@ static int megasas_get_ld_vf_affiliation_111(struct 
megasas_instance *instance,
   sizeof(struct MR_LD_VF_AFFILIATION_111));
else {
new_affiliation_111 =
-   pci_zalloc_consistent(instance->pdev,
+   dma_zalloc_coherent(&instance->pdev->dev,
  sizeof(struct 
MR_LD_VF_AFFILIATION_111),
- &new_affiliation_111_h);
+ &new_affiliation_111_h, 
GFP_KERNEL);
if (!new_affiliation_111) {
dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: 
Couldn't allocate "
   "memory for new affiliation for scsi%d\n",
@@ -2302,7 +2302,7 @@ static int megasas_get_ld_vf_affiliation_111(struct 
megasas_instance *instance,
}
 out:
if (new_affiliation_111) {
-   pci_free_consistent(instance->pdev,
+   dma_free_coherent(&instance->pdev->dev,
sizeof(struct MR_LD_VF_AFFILIATION_111),
new_affiliation_111,
new_affiliation_111_h);
@@ -2347,10 +2347,10 @@ static int megasas_get_ld_vf_affiliation_12(struct 
megasas_instance *instance,
   sizeof(struct MR_LD_VF_AFFILIATION));
else {
new_affiliation =
-   pci_zalloc_consistent(instance->pdev,
+   dma_zalloc_coherent(&instance->pdev->dev,
  (MAX_LOGICAL_DRIVES + 1) *
  sizeof(struct 
MR_LD_VF_AFFILIATION),
- &new_affiliation_h);
+ &new_affiliation_h, GFP_KERNEL);
if (!new_affiliation) {
dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: 
Couldn't allocate "
   "memory for new affiliation for scsi%d\n",
@@ -2470,7 +2470,7 @@ static int megasas_get_ld_vf_affiliation_12(struct 
megasas_instance *instance,
}
 
if (new_affiliation)
-   pci_free_consistent(instance->pdev,
+   dma_free_coherent(&instance->pdev->dev,
(MAX_LOGICAL_DRIVES + 1) *
sizeof(struct MR_LD_VF_AFFILIATION),
new_affiliation, new_affiliation_h);
@@ -2513,9 +2513,9 @@ int megasas_sriov_start_heartbeat(struct megasas_instance 
*instance,
 
if (initial) {
instance->hb_host_mem =
-   pci_zalloc_consistent(instance->pdev,
+   dma_zalloc_coherent(&instance->pdev->dev,
  sizeof(struct 
MR_CTRL_HB_HOST_MEM),
- &instance->hb_host_mem_h);
+ &instance->hb_host_mem_h, 
GFP_KERNEL);
if (!instance->hb_host_mem) {
  

[PATCH 14/28] mpt3sas: switch to generic DMA API

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

Also simplify setting the DMA mask a bit.

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/mpt3sas/mpt3sas_base.c  | 67 
 drivers/scsi/mpt3sas/mpt3sas_ctl.c   | 34 ++--
 drivers/scsi/mpt3sas/mpt3sas_transport.c | 18 ---
 3 files changed, 61 insertions(+), 58 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c 
b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 166b607690a1..2500377d0723 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -2259,7 +2259,7 @@ _base_build_sg_scmd(struct MPT3SAS_ADAPTER *ioc,
sges_left = scsi_dma_map(scmd);
if (sges_left < 0) {
sdev_printk(KERN_ERR, scmd->device,
-"pci_map_sg failed: request for %d bytes!\n",
+"scsi_dma_map failed: request for %d bytes!\n",
 scsi_bufflen(scmd));
return -ENOMEM;
}
@@ -2407,7 +2407,7 @@ _base_build_sg_scmd_ieee(struct MPT3SAS_ADAPTER *ioc,
sges_left = scsi_dma_map(scmd);
if (sges_left < 0) {
sdev_printk(KERN_ERR, scmd->device,
-   "pci_map_sg failed: request for %d bytes!\n",
+   "scsi_dma_map failed: request for %d bytes!\n",
scsi_bufflen(scmd));
return -ENOMEM;
}
@@ -2552,39 +2552,37 @@ _base_build_sg_ieee(struct MPT3SAS_ADAPTER *ioc, void 
*psge,
 static int
 _base_config_dma_addressing(struct MPT3SAS_ADAPTER *ioc, struct pci_dev *pdev)
 {
+   u64 required_mask, coherent_mask;
struct sysinfo s;
-   u64 consistent_dma_mask;
 
if (ioc->is_mcpu_endpoint)
goto try_32bit;
 
+   required_mask = dma_get_required_mask(&pdev->dev);
+   if (sizeof(dma_addr_t) == 4 || required_mask == 32)
+   goto try_32bit;
+
if (ioc->dma_mask)
-   consistent_dma_mask = DMA_BIT_MASK(64);
+   coherent_mask = DMA_BIT_MASK(64);
else
-   consistent_dma_mask = DMA_BIT_MASK(32);
-
-   if (sizeof(dma_addr_t) > 4) {
-   const uint64_t required_mask =
-   dma_get_required_mask(&pdev->dev);
-   if ((required_mask > DMA_BIT_MASK(32)) &&
-   !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
-   !pci_set_consistent_dma_mask(pdev, consistent_dma_mask)) {
-   ioc->base_add_sg_single = &_base_add_sg_single_64;
-   ioc->sge_size = sizeof(Mpi2SGESimple64_t);
-   ioc->dma_mask = 64;
-   goto out;
-   }
-   }
+   coherent_mask = DMA_BIT_MASK(32);
+
+   if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) ||
+   dma_set_coherent_mask(&pdev->dev, coherent_mask))
+   goto try_32bit;
+
+   ioc->base_add_sg_single = &_base_add_sg_single_64;
+   ioc->sge_size = sizeof(Mpi2SGESimple64_t);
+   ioc->dma_mask = 64;
+   goto out;
 
  try_32bit:
-   if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
-   && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
-   ioc->base_add_sg_single = &_base_add_sg_single_32;
-   ioc->sge_size = sizeof(Mpi2SGESimple32_t);
-   ioc->dma_mask = 32;
-   } else
+   if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)))
return -ENODEV;
 
+   ioc->base_add_sg_single = &_base_add_sg_single_32;
+   ioc->sge_size = sizeof(Mpi2SGESimple32_t);
+   ioc->dma_mask = 32;
  out:
si_meminfo(&s);
ioc_info(ioc, "%d BIT PCI BUS DMA ADDRESSING SUPPORTED, total mem (%ld 
kB)\n",
@@ -3777,8 +3775,8 @@ _base_display_fwpkg_version(struct MPT3SAS_ADAPTER *ioc)
}
 
data_length = sizeof(Mpi2FWImageHeader_t);
-   fwpkg_data = pci_alloc_consistent(ioc->pdev, data_length,
-   &fwpkg_data_dma);
+   fwpkg_data = dma_alloc_coherent(&ioc->pdev->dev, data_length,
+   &fwpkg_data_dma, GFP_KERNEL);
if (!fwpkg_data) {
ioc_err(ioc, "failure at %s:%d/%s()!\n",
__FILE__, __LINE__, __func__);
@@ -3837,7 +3835,7 @@ _base_display_fwpkg_version(struct MPT3SAS_ADAPTER *ioc)
ioc->base_cmds.status = MPT3_CMD_NOT_USED;
 out:
if (fwpkg_data)
-   pci_free_consistent(ioc->pdev, data_length, fwpkg_data,
+   dma_free_coherent(&ioc->pdev->dev, data_length, fwpkg_data,
fwpkg_data_dma);
return r;
 }
@@ -4146,7 +4144,7 @@ _base_release_memory_pools(struct MPT3SAS_ADAPTER *ioc)
dexitprintk(ioc, ioc_info(ioc, "%s\n", __func__));
 
if (ioc->request) {
-   pci_free_consistent(ioc->pdev, ioc->request_dma_sz,
+   dma_free_coherent(&ioc->pdev->dev, ioc->request_dma_sz,
  

[PATCH 19/28] qedf: fully convert to the generic DMA API

2018-10-14 Thread Christoph Hellwig
The driver is currently using an odd mix of legacy PCI DMA API and
generic DMA API calls, switch it over to the generic API entirely.

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/qedf/qedf_main.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/qedf/qedf_main.c b/drivers/scsi/qedf/qedf_main.c
index 0a5dd5595dd3..d5a4f17fce51 100644
--- a/drivers/scsi/qedf/qedf_main.c
+++ b/drivers/scsi/qedf/qedf_main.c
@@ -2855,12 +2855,12 @@ static int qedf_set_fcoe_pf_param(struct qedf_ctx *qedf)
QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, "Number of CQs is %d.\n",
   qedf->num_queues);
 
-   qedf->p_cpuq = pci_alloc_consistent(qedf->pdev,
+   qedf->p_cpuq = dma_alloc_coherent(&qedf->pdev->dev,
qedf->num_queues * sizeof(struct qedf_glbl_q_params),
-   &qedf->hw_p_cpuq);
+   &qedf->hw_p_cpuq, GFP_KERNEL);
 
if (!qedf->p_cpuq) {
-   QEDF_ERR(&(qedf->dbg_ctx), "pci_alloc_consistent failed.\n");
+   QEDF_ERR(&(qedf->dbg_ctx), "dma_alloc_coherent failed.\n");
return 1;
}
 
@@ -2929,7 +2929,7 @@ static void qedf_free_fcoe_pf_param(struct qedf_ctx *qedf)
 
if (qedf->p_cpuq) {
size = qedf->num_queues * sizeof(struct qedf_glbl_q_params);
-   pci_free_consistent(qedf->pdev, size, qedf->p_cpuq,
+   dma_free_coherent(&qedf->pdev->dev, size, qedf->p_cpuq,
qedf->hw_p_cpuq);
}
 
-- 
2.19.1



[PATCH 09/28] csiostor: switch to generic DMA API

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

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/csiostor/csio_init.c  |  7 ++-
 drivers/scsi/csiostor/csio_lnode.c |  6 +++---
 drivers/scsi/csiostor/csio_scsi.c  | 12 ++--
 drivers/scsi/csiostor/csio_wr.c| 17 +
 4 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/drivers/scsi/csiostor/csio_init.c 
b/drivers/scsi/csiostor/csio_init.c
index ed2dae657964..aa04e4a7aed5 100644
--- a/drivers/scsi/csiostor/csio_init.c
+++ b/drivers/scsi/csiostor/csio_init.c
@@ -210,11 +210,8 @@ csio_pci_init(struct pci_dev *pdev, int *bars)
pci_set_master(pdev);
pci_try_set_mwi(pdev);
 
-   if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
-   pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
-   } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
-   pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
-   } else {
+   if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) ||
+   dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32))) {
dev_err(&pdev->dev, "No suitable DMA available.\n");
goto err_release_regions;
}
diff --git a/drivers/scsi/csiostor/csio_lnode.c 
b/drivers/scsi/csiostor/csio_lnode.c
index cc5611efc7a9..66e58f0a75dc 100644
--- a/drivers/scsi/csiostor/csio_lnode.c
+++ b/drivers/scsi/csiostor/csio_lnode.c
@@ -1845,8 +1845,8 @@ csio_ln_fdmi_init(struct csio_lnode *ln)
/* Allocate Dma buffers for FDMI response Payload */
dma_buf = &ln->mgmt_req->dma_buf;
dma_buf->len = 2048;
-   dma_buf->vaddr = pci_alloc_consistent(hw->pdev, dma_buf->len,
-   &dma_buf->paddr);
+   dma_buf->vaddr = dma_alloc_coherent(&hw->pdev->dev, dma_buf->len,
+   &dma_buf->paddr, GFP_KERNEL);
if (!dma_buf->vaddr) {
csio_err(hw, "Failed to alloc DMA buffer for FDMI!\n");
kfree(ln->mgmt_req);
@@ -1873,7 +1873,7 @@ csio_ln_fdmi_exit(struct csio_lnode *ln)
 
dma_buf = &ln->mgmt_req->dma_buf;
if (dma_buf->vaddr)
-   pci_free_consistent(hw->pdev, dma_buf->len, dma_buf->vaddr,
+   dma_free_coherent(&hw->pdev->dev, dma_buf->len, dma_buf->vaddr,
dma_buf->paddr);
 
kfree(ln->mgmt_req);
diff --git a/drivers/scsi/csiostor/csio_scsi.c 
b/drivers/scsi/csiostor/csio_scsi.c
index dab0d3f9bee1..8c15b7acb4b7 100644
--- a/drivers/scsi/csiostor/csio_scsi.c
+++ b/drivers/scsi/csiostor/csio_scsi.c
@@ -2349,8 +2349,8 @@ csio_scsi_alloc_ddp_bufs(struct csio_scsim *scm, struct 
csio_hw *hw,
}
 
/* Allocate Dma buffers for DDP */
-   ddp_desc->vaddr = pci_alloc_consistent(hw->pdev, unit_size,
-   &ddp_desc->paddr);
+   ddp_desc->vaddr = dma_alloc_coherent(&hw->pdev->dev, unit_size,
+   &ddp_desc->paddr, GFP_KERNEL);
if (!ddp_desc->vaddr) {
csio_err(hw,
 "SCSI response DMA buffer (ddp) allocation"
@@ -2372,8 +2372,8 @@ csio_scsi_alloc_ddp_bufs(struct csio_scsim *scm, struct 
csio_hw *hw,
list_for_each(tmp, &scm->ddp_freelist) {
ddp_desc = (struct csio_dma_buf *) tmp;
tmp = csio_list_prev(tmp);
-   pci_free_consistent(hw->pdev, ddp_desc->len, ddp_desc->vaddr,
-   ddp_desc->paddr);
+   dma_free_coherent(&hw->pdev->dev, ddp_desc->len,
+ ddp_desc->vaddr, ddp_desc->paddr);
list_del_init(&ddp_desc->list);
kfree(ddp_desc);
}
@@ -2399,8 +2399,8 @@ csio_scsi_free_ddp_bufs(struct csio_scsim *scm, struct 
csio_hw *hw)
list_for_each(tmp, &scm->ddp_freelist) {
ddp_desc = (struct csio_dma_buf *) tmp;
tmp = csio_list_prev(tmp);
-   pci_free_consistent(hw->pdev, ddp_desc->len, ddp_desc->vaddr,
-   ddp_desc->paddr);
+   dma_free_coherent(&hw->pdev->dev, ddp_desc->len,
+ ddp_desc->vaddr, ddp_desc->paddr);
list_del_init(&ddp_desc->list);
kfree(ddp_desc);
}
diff --git a/drivers/scsi/csiostor/csio_wr.c b/drivers/scsi/csiostor/csio_wr.c
index 5022e82ccc4f..dc12933533d5 100644
--- a/drivers/scsi/csiostor/csio_wr.c
+++ b/drivers/scsi/csiostor/csio_wr.c
@@ -124,8 +124,8 @@ csio_wr_fill_fl(struct csio_hw *hw, struct csio_q *flq)
 
while (n--) {
buf->len = sge->sge_fl_buf_size[sreg];
-   buf->vaddr = pci_alloc_consistent(hw->pdev, buf->len,
- &buf->paddr);
+   buf->vaddr = dma_

[PATCH 11/28] hpsa: switch to generic DMA API

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

Signed-off-by: Christoph Hellwig 
Tested-by: Don Brace 
Acked-by: Don Brace 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/hpsa.c | 136 ++--
 1 file changed, 69 insertions(+), 67 deletions(-)

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index 666ba09e5f42..758ffd6419b4 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -2240,8 +2240,8 @@ static int hpsa_map_ioaccel2_sg_chain_block(struct 
ctlr_info *h,
 
chain_block = h->ioaccel2_cmd_sg_list[c->cmdindex];
chain_size = le32_to_cpu(cp->sg[0].length);
-   temp64 = pci_map_single(h->pdev, chain_block, chain_size,
-   PCI_DMA_TODEVICE);
+   temp64 = dma_map_single(&h->pdev->dev, chain_block, chain_size,
+   DMA_TO_DEVICE);
if (dma_mapping_error(&h->pdev->dev, temp64)) {
/* prevent subsequent unmapping */
cp->sg->address = 0;
@@ -2261,7 +2261,7 @@ static void hpsa_unmap_ioaccel2_sg_chain_block(struct 
ctlr_info *h,
chain_sg = cp->sg;
temp64 = le64_to_cpu(chain_sg->address);
chain_size = le32_to_cpu(cp->sg[0].length);
-   pci_unmap_single(h->pdev, temp64, chain_size, PCI_DMA_TODEVICE);
+   dma_unmap_single(&h->pdev->dev, temp64, chain_size, DMA_TO_DEVICE);
 }
 
 static int hpsa_map_sg_chain_block(struct ctlr_info *h,
@@ -2277,8 +2277,8 @@ static int hpsa_map_sg_chain_block(struct ctlr_info *h,
chain_len = sizeof(*chain_sg) *
(le16_to_cpu(c->Header.SGTotal) - h->max_cmd_sg_entries);
chain_sg->Len = cpu_to_le32(chain_len);
-   temp64 = pci_map_single(h->pdev, chain_block, chain_len,
-   PCI_DMA_TODEVICE);
+   temp64 = dma_map_single(&h->pdev->dev, chain_block, chain_len,
+   DMA_TO_DEVICE);
if (dma_mapping_error(&h->pdev->dev, temp64)) {
/* prevent subsequent unmapping */
chain_sg->Addr = cpu_to_le64(0);
@@ -2297,8 +2297,8 @@ static void hpsa_unmap_sg_chain_block(struct ctlr_info *h,
return;
 
chain_sg = &c->SG[h->max_cmd_sg_entries - 1];
-   pci_unmap_single(h->pdev, le64_to_cpu(chain_sg->Addr),
-   le32_to_cpu(chain_sg->Len), PCI_DMA_TODEVICE);
+   dma_unmap_single(&h->pdev->dev, le64_to_cpu(chain_sg->Addr),
+   le32_to_cpu(chain_sg->Len), DMA_TO_DEVICE);
 }
 
 
@@ -2759,13 +2759,13 @@ static void complete_scsi_command(struct CommandList 
*cp)
return hpsa_cmd_free_and_done(h, cp, cmd);
 }
 
-static void hpsa_pci_unmap(struct pci_dev *pdev,
-   struct CommandList *c, int sg_used, int data_direction)
+static void hpsa_pci_unmap(struct pci_dev *pdev, struct CommandList *c,
+   int sg_used, enum dma_data_direction data_direction)
 {
int i;
 
for (i = 0; i < sg_used; i++)
-   pci_unmap_single(pdev, (dma_addr_t) le64_to_cpu(c->SG[i].Addr),
+   dma_unmap_single(&pdev->dev, le64_to_cpu(c->SG[i].Addr),
le32_to_cpu(c->SG[i].Len),
data_direction);
 }
@@ -2774,17 +2774,17 @@ static int hpsa_map_one(struct pci_dev *pdev,
struct CommandList *cp,
unsigned char *buf,
size_t buflen,
-   int data_direction)
+   enum dma_data_direction data_direction)
 {
u64 addr64;
 
-   if (buflen == 0 || data_direction == PCI_DMA_NONE) {
+   if (buflen == 0 || data_direction == DMA_NONE) {
cp->Header.SGList = 0;
cp->Header.SGTotal = cpu_to_le16(0);
return 0;
}
 
-   addr64 = pci_map_single(pdev, buf, buflen, data_direction);
+   addr64 = dma_map_single(&pdev->dev, buf, buflen, data_direction);
if (dma_mapping_error(&pdev->dev, addr64)) {
/* Prevent subsequent unmap of something never mapped */
cp->Header.SGList = 0;
@@ -2845,7 +2845,8 @@ static u32 lockup_detected(struct ctlr_info *h)
 
 #define MAX_DRIVER_CMD_RETRIES 25
 static int hpsa_scsi_do_simple_cmd_with_retry(struct ctlr_info *h,
-   struct CommandList *c, int data_direction, unsigned long timeout_msecs)
+   struct CommandList *c, enum dma_data_direction data_direction,
+   unsigned long timeout_msecs)
 {
int backoff_time = 10, retry_count = 0;
int rc;
@@ -2969,8 +2970,8 @@ static int hpsa_do_receive_diagnostic(struct ctlr_info 
*h, u8 *scsi3addr,
rc = -1;
goto out;
}
-   rc = hpsa_scsi_do_simple_cmd_with_retry(h, c,
-   PCI_DMA_FROMDEVICE, NO_TIMEOUT);
+   rc = hpsa_scsi_do_simple_cmd_with_retry(h, c, DMA_FROM_DEVICE,
+   NO_TIMEOUT);
if (rc)
goto out;
ei = c->err_info;
@@ -3022,8 +3023,8 @@ 

[PATCH 10/28] fnic: switch to generic DMA API

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

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/fnic/fnic_fcs.c  | 41 +++
 drivers/scsi/fnic/fnic_main.c | 19 ++--
 drivers/scsi/fnic/fnic_scsi.c | 38 ++--
 drivers/scsi/fnic/vnic_dev.c  | 26 +++---
 4 files changed, 49 insertions(+), 75 deletions(-)

diff --git a/drivers/scsi/fnic/fnic_fcs.c b/drivers/scsi/fnic/fnic_fcs.c
index c7bf316d8e83..844ef688fa91 100644
--- a/drivers/scsi/fnic/fnic_fcs.c
+++ b/drivers/scsi/fnic/fnic_fcs.c
@@ -836,8 +836,8 @@ static void fnic_rq_cmpl_frame_recv(struct vnic_rq *rq, 
struct cq_desc
u32 fcp_bytes_written = 0;
unsigned long flags;
 
-   pci_unmap_single(fnic->pdev, buf->dma_addr, buf->len,
-PCI_DMA_FROMDEVICE);
+   dma_unmap_single(&fnic->pdev->dev, buf->dma_addr, buf->len,
+DMA_FROM_DEVICE);
skb = buf->os_buf;
fp = (struct fc_frame *)skb;
buf->os_buf = NULL;
@@ -977,9 +977,8 @@ int fnic_alloc_rq_frame(struct vnic_rq *rq)
skb_reset_transport_header(skb);
skb_reset_network_header(skb);
skb_put(skb, len);
-   pa = pci_map_single(fnic->pdev, skb->data, len, PCI_DMA_FROMDEVICE);
-
-   if (pci_dma_mapping_error(fnic->pdev, pa)) {
+   pa = dma_map_single(&fnic->pdev->dev, skb->data, len, DMA_FROM_DEVICE);
+   if (dma_mapping_error(&fnic->pdev->dev, pa)) {
r = -ENOMEM;
printk(KERN_ERR "PCI mapping failed with error %d\n", r);
goto free_skb;
@@ -998,8 +997,8 @@ void fnic_free_rq_buf(struct vnic_rq *rq, struct 
vnic_rq_buf *buf)
struct fc_frame *fp = buf->os_buf;
struct fnic *fnic = vnic_dev_priv(rq->vdev);
 
-   pci_unmap_single(fnic->pdev, buf->dma_addr, buf->len,
-PCI_DMA_FROMDEVICE);
+   dma_unmap_single(&fnic->pdev->dev, buf->dma_addr, buf->len,
+DMA_FROM_DEVICE);
 
dev_kfree_skb(fp_skb(fp));
buf->os_buf = NULL;
@@ -1018,7 +1017,6 @@ void fnic_eth_send(struct fcoe_ctlr *fip, struct sk_buff 
*skb)
struct ethhdr *eth_hdr;
struct vlan_ethhdr *vlan_hdr;
unsigned long flags;
-   int r;
 
if (!fnic->vlan_hw_insert) {
eth_hdr = (struct ethhdr *)skb_mac_header(skb);
@@ -1038,11 +1036,10 @@ void fnic_eth_send(struct fcoe_ctlr *fip, struct 
sk_buff *skb)
}
}
 
-   pa = pci_map_single(fnic->pdev, skb->data, skb->len, PCI_DMA_TODEVICE);
-
-   r = pci_dma_mapping_error(fnic->pdev, pa);
-   if (r) {
-   printk(KERN_ERR "PCI mapping failed with error %d\n", r);
+   pa = dma_map_single(&fnic->pdev->dev, skb->data, skb->len,
+   DMA_TO_DEVICE);
+   if (dma_mapping_error(&fnic->pdev->dev, pa)) {
+   printk(KERN_ERR "DMA mapping failed\n");
goto free_skb;
}
 
@@ -1058,7 +1055,7 @@ void fnic_eth_send(struct fcoe_ctlr *fip, struct sk_buff 
*skb)
 
 irq_restore:
spin_unlock_irqrestore(&fnic->wq_lock[0], flags);
-   pci_unmap_single(fnic->pdev, pa, skb->len, PCI_DMA_TODEVICE);
+   dma_unmap_single(&fnic->pdev->dev, pa, skb->len, DMA_TO_DEVICE);
 free_skb:
kfree_skb(skb);
 }
@@ -1115,9 +1112,8 @@ static int fnic_send_frame(struct fnic *fnic, struct 
fc_frame *fp)
if (FC_FCOE_VER)
FC_FCOE_ENCAPS_VER(fcoe_hdr, FC_FCOE_VER);
 
-   pa = pci_map_single(fnic->pdev, eth_hdr, tot_len, PCI_DMA_TODEVICE);
-
-   if (pci_dma_mapping_error(fnic->pdev, pa)) {
+   pa = dma_map_single(&fnic->pdev->dev, eth_hdr, tot_len, DMA_TO_DEVICE);
+   if (dma_mapping_error(&fnic->pdev->dev, pa)) {
ret = -ENOMEM;
printk(KERN_ERR "DMA map failed with error %d\n", ret);
goto free_skb_on_err;
@@ -1131,8 +1127,7 @@ static int fnic_send_frame(struct fnic *fnic, struct 
fc_frame *fp)
spin_lock_irqsave(&fnic->wq_lock[0], flags);
 
if (!vnic_wq_desc_avail(wq)) {
-   pci_unmap_single(fnic->pdev, pa,
-tot_len, PCI_DMA_TODEVICE);
+   dma_unmap_single(&fnic->pdev->dev, pa, tot_len, DMA_TO_DEVICE);
ret = -1;
goto irq_restore;
}
@@ -1247,8 +1242,8 @@ static void fnic_wq_complete_frame_send(struct vnic_wq 
*wq,
struct fc_frame *fp = (struct fc_frame *)skb;
struct fnic *fnic = vnic_dev_priv(wq->vdev);
 
-   pci_unmap_single(fnic->pdev, buf->dma_addr,
-buf->len, PCI_DMA_TODEVICE);
+   dma_unmap_single(&fnic->pdev->dev, buf->dma_addr, buf->len,
+DMA_TO_DEVICE);
dev_kfree_skb_irq(fp_skb(fp));
buf->os_buf = NULL;
 }
@@ -1290,8 +1285,8 @@ void fnic_free_wq_buf(struct vnic_wq *wq, struct 
vnic_wq_buf *buf)
struct fc_frame *

[PATCH 20/28] qedi: fully convert to the generic DMA API

2018-10-14 Thread Christoph Hellwig
The driver is currently using an odd mix of legacy PCI DMA API and
generic DMA API calls, switch it over to the generic API entirely.

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/qedi/qedi_main.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c
index aa96bccb5a96..95d3fce994f6 100644
--- a/drivers/scsi/qedi/qedi_main.c
+++ b/drivers/scsi/qedi/qedi_main.c
@@ -806,11 +806,11 @@ static int qedi_set_iscsi_pf_param(struct qedi_ctx *qedi)
memset(&qedi->pf_params.iscsi_pf_params, 0,
   sizeof(qedi->pf_params.iscsi_pf_params));
 
-   qedi->p_cpuq = pci_alloc_consistent(qedi->pdev,
+   qedi->p_cpuq = dma_alloc_coherent(&qedi->pdev->dev,
qedi->num_queues * sizeof(struct qedi_glbl_q_params),
-   &qedi->hw_p_cpuq);
+   &qedi->hw_p_cpuq, GFP_KERNEL);
if (!qedi->p_cpuq) {
-   QEDI_ERR(&qedi->dbg_ctx, "pci_alloc_consistent fail\n");
+   QEDI_ERR(&qedi->dbg_ctx, "pci_alloc_coherent fail\n");
rval = -1;
goto err_alloc_mem;
}
@@ -871,7 +871,7 @@ static void qedi_free_iscsi_pf_param(struct qedi_ctx *qedi)
 
if (qedi->p_cpuq) {
size = qedi->num_queues * sizeof(struct qedi_glbl_q_params);
-   pci_free_consistent(qedi->pdev, size, qedi->p_cpuq,
+   dma_free_coherent(&qedi->pdev->dev, size, qedi->p_cpuq,
qedi->hw_p_cpuq);
}
 
-- 
2.19.1



[PATCH 03/28] 3w-xxx: fully convert to the generic DMA API

2018-10-14 Thread Christoph Hellwig
The driver is currently using an odd mix of legacy PCI DMA API and
generic DMA API calls, switch it over to the generic API entirely.

Signed-off-by: Christoph Hellwig 
Acked-by: Adam Radford 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/3w-.c | 20 ++--
 drivers/scsi/3w-.h |  1 -
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/3w-.c b/drivers/scsi/3w-.c
index 471366945bd4..a58257645e94 100644
--- a/drivers/scsi/3w-.c
+++ b/drivers/scsi/3w-.c
@@ -834,15 +834,17 @@ static int tw_allocate_memory(TW_Device_Extension 
*tw_dev, int size, int which)
 
dprintk(KERN_NOTICE "3w-: tw_allocate_memory()\n");
 
-   cpu_addr = pci_alloc_consistent(tw_dev->tw_pci_dev, size*TW_Q_LENGTH, 
&dma_handle);
+   cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev,
+   size * TW_Q_LENGTH, &dma_handle, GFP_KERNEL);
if (cpu_addr == NULL) {
-   printk(KERN_WARNING "3w-: pci_alloc_consistent() 
failed.\n");
+   printk(KERN_WARNING "3w-: dma_alloc_coherent() failed.\n");
return 1;
}
 
if ((unsigned long)cpu_addr % (tw_dev->tw_pci_dev->device == 
TW_DEVICE_ID ? TW_ALIGNMENT_6000 : TW_ALIGNMENT_7000)) {
printk(KERN_WARNING "3w-: Couldn't allocate correctly 
aligned memory.\n");
-   pci_free_consistent(tw_dev->tw_pci_dev, size*TW_Q_LENGTH, 
cpu_addr, dma_handle);
+   dma_free_coherent(&tw_dev->tw_pci_dev->dev, size * TW_Q_LENGTH,
+   cpu_addr, dma_handle);
return 1;
}
 
@@ -1062,10 +1064,16 @@ static void 
tw_free_device_extension(TW_Device_Extension *tw_dev)
 
/* Free command packet and generic buffer memory */
if (tw_dev->command_packet_virtual_address[0])
-   pci_free_consistent(tw_dev->tw_pci_dev, 
sizeof(TW_Command)*TW_Q_LENGTH, tw_dev->command_packet_virtual_address[0], 
tw_dev->command_packet_physical_address[0]);
+   dma_free_coherent(&tw_dev->tw_pci_dev->dev,
+   sizeof(TW_Command) * TW_Q_LENGTH,
+   tw_dev->command_packet_virtual_address[0],
+   tw_dev->command_packet_physical_address[0]);
 
if (tw_dev->alignment_virtual_address[0])
-   pci_free_consistent(tw_dev->tw_pci_dev, 
sizeof(TW_Sector)*TW_Q_LENGTH, tw_dev->alignment_virtual_address[0], 
tw_dev->alignment_physical_address[0]);
+   dma_free_coherent(&tw_dev->tw_pci_dev->dev,
+   sizeof(TW_Sector) * TW_Q_LENGTH,
+   tw_dev->alignment_virtual_address[0],
+   tw_dev->alignment_physical_address[0]);
 } /* End tw_free_device_extension() */
 
 /* This function will send an initconnection command to controller */
@@ -2260,7 +2268,7 @@ static int tw_probe(struct pci_dev *pdev, const struct 
pci_device_id *dev_id)
 
pci_set_master(pdev);
 
-   retval = pci_set_dma_mask(pdev, TW_DMA_MASK);
+   retval = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
if (retval) {
printk(KERN_WARNING "3w-: Failed to set dma mask.");
goto out_disable_device;
diff --git a/drivers/scsi/3w-.h b/drivers/scsi/3w-.h
index 69e80c1ed1ca..bd87fbacfbc7 100644
--- a/drivers/scsi/3w-.h
+++ b/drivers/scsi/3w-.h
@@ -230,7 +230,6 @@ static unsigned char tw_sense_table[][4] =
 #define TW_IOCTL_TIMEOUT  25 /* 25 seconds */
 #define TW_IOCTL_CHRDEV_TIMEOUT   60 /* 60 seconds */
 #define TW_IOCTL_CHRDEV_FREE  -1
-#define TW_DMA_MASK  DMA_BIT_MASK(32)
 #define TW_MAX_CDB_LEN   16
 
 /* Bitmask macros to eliminate bitfields */
-- 
2.19.1



[PATCH 07/28] atp870u: switch to generic DMA API

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

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/atp870u.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/atp870u.c b/drivers/scsi/atp870u.c
index 8996d2329e11..802d15018ec0 100644
--- a/drivers/scsi/atp870u.c
+++ b/drivers/scsi/atp870u.c
@@ -1193,7 +1193,7 @@ static void atp870u_free_tables(struct Scsi_Host *host)
for (k = 0; k < 16; k++) {
if (!atp_dev->id[j][k].prd_table)
continue;
-   pci_free_consistent(atp_dev->pdev, 1024, 
atp_dev->id[j][k].prd_table, atp_dev->id[j][k].prd_bus);
+   dma_free_coherent(&atp_dev->pdev->dev, 1024, 
atp_dev->id[j][k].prd_table, atp_dev->id[j][k].prd_bus);
atp_dev->id[j][k].prd_table = NULL;
}
}
@@ -1205,7 +1205,7 @@ static int atp870u_init_tables(struct Scsi_Host *host)
int c,k;
for(c=0;c < 2;c++) {
for(k=0;k<16;k++) {
-   atp_dev->id[c][k].prd_table = 
pci_alloc_consistent(atp_dev->pdev, 1024, &(atp_dev->id[c][k].prd_bus));
+   atp_dev->id[c][k].prd_table = 
dma_alloc_coherent(&atp_dev->pdev->dev, 1024, &(atp_dev->id[c][k].prd_bus), 
GFP_KERNEL);
if (!atp_dev->id[c][k].prd_table) {
printk("atp870u_init_tables fail\n");
atp870u_free_tables(host);
@@ -1509,7 +1509,7 @@ static int atp870u_probe(struct pci_dev *pdev, const 
struct pci_device_id *ent)
if (err)
goto fail;
 
-   if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
+   if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
 printk(KERN_ERR "atp870u: DMA mask required but not 
available.\n");
 err = -EIO;
 goto disable_device;
-- 
2.19.1



[PATCH 01/28] aic94xx: fully convert to the generic DMA API

2018-10-14 Thread Christoph Hellwig
The driver is currently using an odd mix of legacy PCI DMA API and
generic DMA API calls, switch it over to the generic API entirely.

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/aic94xx/aic94xx_init.c |  9 ++
 drivers/scsi/aic94xx/aic94xx_task.c | 46 ++---
 2 files changed, 25 insertions(+), 30 deletions(-)

diff --git a/drivers/scsi/aic94xx/aic94xx_init.c 
b/drivers/scsi/aic94xx/aic94xx_init.c
index 1391e5f35918..41c4d8abdd4a 100644
--- a/drivers/scsi/aic94xx/aic94xx_init.c
+++ b/drivers/scsi/aic94xx/aic94xx_init.c
@@ -771,13 +771,8 @@ static int asd_pci_probe(struct pci_dev *dev, const struct 
pci_device_id *id)
goto Err_remove;
 
err = -ENODEV;
-   if (!pci_set_dma_mask(dev, DMA_BIT_MASK(64))
-   && !pci_set_consistent_dma_mask(dev, DMA_BIT_MASK(64)))
-   ;
-   else if (!pci_set_dma_mask(dev, DMA_BIT_MASK(32))
-&& !pci_set_consistent_dma_mask(dev, DMA_BIT_MASK(32)))
-   ;
-   else {
+   if (dma_set_mask_and_coherent(&dev->dev, DMA_BIT_MASK(64)) ||
+   dma_set_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32))) {
asd_printk("no suitable DMA mask for %s\n", pci_name(dev));
goto Err_remove;
}
diff --git a/drivers/scsi/aic94xx/aic94xx_task.c 
b/drivers/scsi/aic94xx/aic94xx_task.c
index cdd4ab683be9..7fea344531f6 100644
--- a/drivers/scsi/aic94xx/aic94xx_task.c
+++ b/drivers/scsi/aic94xx/aic94xx_task.c
@@ -42,13 +42,13 @@ static void asd_can_dequeue(struct asd_ha_struct *asd_ha, 
int num)
spin_unlock_irqrestore(&asd_ha->seq.pend_q_lock, flags);
 }
 
-/* PCI_DMA_... to our direction translation.
+/* DMA_... to our direction translation.
  */
 static const u8 data_dir_flags[] = {
-   [PCI_DMA_BIDIRECTIONAL] = DATA_DIR_BYRECIPIENT, /* UNSPECIFIED */
-   [PCI_DMA_TODEVICE]  = DATA_DIR_OUT, /* OUTBOUND */
-   [PCI_DMA_FROMDEVICE]= DATA_DIR_IN, /* INBOUND */
-   [PCI_DMA_NONE]  = DATA_DIR_NONE, /* NO TRANSFER */
+   [DMA_BIDIRECTIONAL] = DATA_DIR_BYRECIPIENT, /* UNSPECIFIED */
+   [DMA_TO_DEVICE] = DATA_DIR_OUT, /* OUTBOUND */
+   [DMA_FROM_DEVICE]   = DATA_DIR_IN,  /* INBOUND */
+   [DMA_NONE]  = DATA_DIR_NONE,/* NO TRANSFER */
 };
 
 static int asd_map_scatterlist(struct sas_task *task,
@@ -60,12 +60,12 @@ static int asd_map_scatterlist(struct sas_task *task,
struct scatterlist *sc;
int num_sg, res;
 
-   if (task->data_dir == PCI_DMA_NONE)
+   if (task->data_dir == DMA_NONE)
return 0;
 
if (task->num_scatter == 0) {
void *p = task->scatter;
-   dma_addr_t dma = pci_map_single(asd_ha->pcidev, p,
+   dma_addr_t dma = dma_map_single(&asd_ha->pcidev->dev, p,
task->total_xfer_len,
task->data_dir);
sg_arr[0].bus_addr = cpu_to_le64((u64)dma);
@@ -79,7 +79,7 @@ static int asd_map_scatterlist(struct sas_task *task,
if (sas_protocol_ata(task->task_proto))
num_sg = task->num_scatter;
else
-   num_sg = pci_map_sg(asd_ha->pcidev, task->scatter,
+   num_sg = dma_map_sg(&asd_ha->pcidev->dev, task->scatter,
task->num_scatter, task->data_dir);
if (num_sg == 0)
return -ENOMEM;
@@ -126,8 +126,8 @@ static int asd_map_scatterlist(struct sas_task *task,
return 0;
 err_unmap:
if (sas_protocol_ata(task->task_proto))
-   pci_unmap_sg(asd_ha->pcidev, task->scatter, task->num_scatter,
-task->data_dir);
+   dma_unmap_sg(&asd_ha->pcidev->dev, task->scatter,
+task->num_scatter, task->data_dir);
return res;
 }
 
@@ -136,21 +136,21 @@ static void asd_unmap_scatterlist(struct asd_ascb *ascb)
struct asd_ha_struct *asd_ha = ascb->ha;
struct sas_task *task = ascb->uldd_task;
 
-   if (task->data_dir == PCI_DMA_NONE)
+   if (task->data_dir == DMA_NONE)
return;
 
if (task->num_scatter == 0) {
dma_addr_t dma = (dma_addr_t)
   le64_to_cpu(ascb->scb->ssp_task.sg_element[0].bus_addr);
-   pci_unmap_single(ascb->ha->pcidev, dma, task->total_xfer_len,
-task->data_dir);
+   dma_unmap_single(&ascb->ha->pcidev->dev, dma,
+task->total_xfer_len, task->data_dir);
return;
}
 
asd_free_coherent(asd_ha, ascb->sg_arr);
if (task->task_proto != SAS_PROTOCOL_STP)
-   pci_unmap_sg(asd_ha->pcidev, task->scatter, task->num_scatter,
-task->data_dir);
+   dma_unmap_sg(&asd_ha->pcidev->dev, task->s

[PATCH 21/28] qla1280: switch to generic DMA API

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

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/qla1280.c | 26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index 390775d5c918..15a50cc7e4b3 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -1750,7 +1750,7 @@ qla1280_load_firmware_dma(struct scsi_qla_host *ha)
uint8_t *sp, *tbuf;
dma_addr_t p_tbuf;
 
-   tbuf = pci_alloc_consistent(ha->pdev, 8000, &p_tbuf);
+   tbuf = dma_alloc_coherent(&ha->pdev->dev, 8000, &p_tbuf, GFP_KERNEL);
if (!tbuf)
return -ENOMEM;
 #endif
@@ -1841,7 +1841,7 @@ qla1280_load_firmware_dma(struct scsi_qla_host *ha)
 
  out:
 #if DUMP_IT_BACK
-   pci_free_consistent(ha->pdev, 8000, tbuf, p_tbuf);
+   dma_free_coherent(&ha->pdev->dev, 8000, tbuf, p_tbuf);
 #endif
return err;
 }
@@ -4259,8 +4259,8 @@ qla1280_probe_one(struct pci_dev *pdev, const struct 
pci_device_id *id)
ha->devnum = devnum;/* specifies microcode load address */
 
 #ifdef QLA_64BIT_PTR
-   if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
-   if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32))) {
+   if (dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
+   if (dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32))) {
printk(KERN_WARNING "scsi(%li): Unable to set a "
   "suitable DMA mask - aborting\n", ha->host_no);
error = -ENODEV;
@@ -4270,7 +4270,7 @@ qla1280_probe_one(struct pci_dev *pdev, const struct 
pci_device_id *id)
dprintk(2, "scsi(%li): 64 Bit PCI Addressing Enabled\n",
ha->host_no);
 #else
-   if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32))) {
+   if (dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32))) {
printk(KERN_WARNING "scsi(%li): Unable to set a "
   "suitable DMA mask - aborting\n", ha->host_no);
error = -ENODEV;
@@ -4278,17 +4278,17 @@ qla1280_probe_one(struct pci_dev *pdev, const struct 
pci_device_id *id)
}
 #endif
 
-   ha->request_ring = pci_alloc_consistent(ha->pdev,
+   ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
((REQUEST_ENTRY_CNT + 1) * sizeof(request_t)),
-   &ha->request_dma);
+   &ha->request_dma, GFP_KERNEL);
if (!ha->request_ring) {
printk(KERN_INFO "qla1280: Failed to get request memory\n");
goto error_put_host;
}
 
-   ha->response_ring = pci_alloc_consistent(ha->pdev,
+   ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
((RESPONSE_ENTRY_CNT + 1) * sizeof(struct response)),
-   &ha->response_dma);
+   &ha->response_dma, GFP_KERNEL);
if (!ha->response_ring) {
printk(KERN_INFO "qla1280: Failed to get response memory\n");
goto error_free_request_ring;
@@ -4370,11 +4370,11 @@ qla1280_probe_one(struct pci_dev *pdev, const struct 
pci_device_id *id)
release_region(host->io_port, 0xff);
 #endif
  error_free_response_ring:
-   pci_free_consistent(ha->pdev,
+   dma_free_coherent(&ha->pdev->dev,
((RESPONSE_ENTRY_CNT + 1) * sizeof(struct response)),
ha->response_ring, ha->response_dma);
  error_free_request_ring:
-   pci_free_consistent(ha->pdev,
+   dma_free_coherent(&ha->pdev->dev,
((REQUEST_ENTRY_CNT + 1) * sizeof(request_t)),
ha->request_ring, ha->request_dma);
  error_put_host:
@@ -4404,10 +4404,10 @@ qla1280_remove_one(struct pci_dev *pdev)
release_region(host->io_port, 0xff);
 #endif
 
-   pci_free_consistent(ha->pdev,
+   dma_free_coherent(&ha->pdev->dev,
((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
ha->request_ring, ha->request_dma);
-   pci_free_consistent(ha->pdev,
+   dma_free_coherent(&ha->pdev->dev,
((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
ha->response_ring, ha->response_dma);
 
-- 
2.19.1



[PATCH 24/28] snic: switch to generic DMA API

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

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/snic/snic_disc.c |  7 ---
 drivers/scsi/snic/snic_io.c   | 25 +
 drivers/scsi/snic/snic_main.c | 24 ++--
 drivers/scsi/snic/snic_scsi.c | 11 +--
 drivers/scsi/snic/vnic_dev.c  | 29 ++---
 5 files changed, 38 insertions(+), 58 deletions(-)

diff --git a/drivers/scsi/snic/snic_disc.c b/drivers/scsi/snic/snic_disc.c
index b106596cc0cf..e9ccfb97773f 100644
--- a/drivers/scsi/snic/snic_disc.c
+++ b/drivers/scsi/snic/snic_disc.c
@@ -111,8 +111,8 @@ snic_queue_report_tgt_req(struct snic *snic)
 
SNIC_BUG_ONunsigned long)buf) % SNIC_SG_DESC_ALIGN) != 0);
 
-   pa = pci_map_single(snic->pdev, buf, buf_len, PCI_DMA_FROMDEVICE);
-   if (pci_dma_mapping_error(snic->pdev, pa)) {
+   pa = dma_map_single(&snic->pdev->dev, buf, buf_len, DMA_FROM_DEVICE);
+   if (dma_mapping_error(&snic->pdev->dev, pa)) {
SNIC_HOST_ERR(snic->shost,
  "Rpt-tgt rspbuf %p: PCI DMA Mapping Failed\n",
  buf);
@@ -138,7 +138,8 @@ snic_queue_report_tgt_req(struct snic *snic)
 
ret = snic_queue_wq_desc(snic, rqi->req, rqi->req_len);
if (ret) {
-   pci_unmap_single(snic->pdev, pa, buf_len, PCI_DMA_FROMDEVICE);
+   dma_unmap_single(&snic->pdev->dev, pa, buf_len,
+DMA_FROM_DEVICE);
kfree(buf);
rqi->sge_va = 0;
snic_release_untagged_req(snic, rqi);
diff --git a/drivers/scsi/snic/snic_io.c b/drivers/scsi/snic/snic_io.c
index 8e69548395b9..159ee94d2a55 100644
--- a/drivers/scsi/snic/snic_io.c
+++ b/drivers/scsi/snic/snic_io.c
@@ -102,7 +102,8 @@ snic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf 
*buf)
struct snic_req_info *rqi = NULL;
unsigned long flags;
 
-   pci_unmap_single(snic->pdev, buf->dma_addr, buf->len, PCI_DMA_TODEVICE);
+   dma_unmap_single(&snic->pdev->dev, buf->dma_addr, buf->len,
+DMA_TO_DEVICE);
 
rqi = req_to_rqi(req);
spin_lock_irqsave(&snic->spl_cmd_lock, flags);
@@ -172,8 +173,8 @@ snic_queue_wq_desc(struct snic *snic, void *os_buf, u16 len)
snic_print_desc(__func__, os_buf, len);
 
/* Map request buffer */
-   pa = pci_map_single(snic->pdev, os_buf, len, PCI_DMA_TODEVICE);
-   if (pci_dma_mapping_error(snic->pdev, pa)) {
+   pa = dma_map_single(&snic->pdev->dev, os_buf, len, DMA_TO_DEVICE);
+   if (dma_mapping_error(&snic->pdev->dev, pa)) {
SNIC_HOST_ERR(snic->shost, "qdesc: PCI DMA Mapping Fail.\n");
 
return -ENOMEM;
@@ -186,7 +187,7 @@ snic_queue_wq_desc(struct snic *snic, void *os_buf, u16 len)
spin_lock_irqsave(&snic->wq_lock[q_num], flags);
desc_avail = snic_wqdesc_avail(snic, q_num, req->hdr.type);
if (desc_avail <= 0) {
-   pci_unmap_single(snic->pdev, pa, len, PCI_DMA_TODEVICE);
+   dma_unmap_single(&snic->pdev->dev, pa, len, DMA_TO_DEVICE);
req->req_pa = 0;
spin_unlock_irqrestore(&snic->wq_lock[q_num], flags);
atomic64_inc(&snic->s_stats.misc.wq_alloc_fail);
@@ -350,29 +351,29 @@ snic_req_free(struct snic *snic, struct snic_req_info 
*rqi)
 
if (rqi->abort_req) {
if (rqi->abort_req->req_pa)
-   pci_unmap_single(snic->pdev,
+   dma_unmap_single(&snic->pdev->dev,
 rqi->abort_req->req_pa,
 sizeof(struct snic_host_req),
-PCI_DMA_TODEVICE);
+DMA_TO_DEVICE);
 
mempool_free(rqi->abort_req, snic->req_pool[SNIC_REQ_TM_CACHE]);
}
 
if (rqi->dr_req) {
if (rqi->dr_req->req_pa)
-   pci_unmap_single(snic->pdev,
+   dma_unmap_single(&snic->pdev->dev,
 rqi->dr_req->req_pa,
 sizeof(struct snic_host_req),
-PCI_DMA_TODEVICE);
+DMA_TO_DEVICE);
 
mempool_free(rqi->dr_req, snic->req_pool[SNIC_REQ_TM_CACHE]);
}
 
if (rqi->req->req_pa)
-   pci_unmap_single(snic->pdev,
+   dma_unmap_single(&snic->pdev->dev,
 rqi->req->req_pa,
 rqi->req_len,
-PCI_DMA_TODEVICE);
+DMA_TO_DEVICE);
 
mempool_free(rqi, snic->req_pool[rqi->rq_pool_type]);
 }
@@ -384,10 +385,10 @@ snic_pci_unmap_rsp_buf(struct snic *snic, struct 
snic_req_info *rqi)
 
  

[PATCH 26/28] smartpqi: fully convert to the generic DMA API

2018-10-14 Thread Christoph Hellwig
The driver is currently using an odd mix of legacy PCI DMA API and
generic DMA API calls, switch it over to the generic API entirely.

Signed-off-by: Christoph Hellwig 
Tested-by: Don Brace 
Acked-by: Don Brace 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/smartpqi/smartpqi_init.c | 100 +++---
 drivers/scsi/smartpqi/smartpqi_sis.c  |  11 ++-
 2 files changed, 47 insertions(+), 64 deletions(-)

diff --git a/drivers/scsi/smartpqi/smartpqi_init.c 
b/drivers/scsi/smartpqi/smartpqi_init.c
index 2112ea6723c6..a25a07a0b7f0 100644
--- a/drivers/scsi/smartpqi/smartpqi_init.c
+++ b/drivers/scsi/smartpqi/smartpqi_init.c
@@ -349,16 +349,16 @@ static inline u32 pqi_read_heartbeat_counter(struct 
pqi_ctrl_info *ctrl_info)
 
 static int pqi_map_single(struct pci_dev *pci_dev,
struct pqi_sg_descriptor *sg_descriptor, void *buffer,
-   size_t buffer_length, int data_direction)
+   size_t buffer_length, enum dma_data_direction data_direction)
 {
dma_addr_t bus_address;
 
-   if (!buffer || buffer_length == 0 || data_direction == PCI_DMA_NONE)
+   if (!buffer || buffer_length == 0 || data_direction == DMA_NONE)
return 0;
 
-   bus_address = pci_map_single(pci_dev, buffer, buffer_length,
+   bus_address = dma_map_single(&pci_dev->dev, buffer, buffer_length,
data_direction);
-   if (pci_dma_mapping_error(pci_dev, bus_address))
+   if (dma_mapping_error(&pci_dev->dev, bus_address))
return -ENOMEM;
 
put_unaligned_le64((u64)bus_address, &sg_descriptor->address);
@@ -370,15 +370,15 @@ static int pqi_map_single(struct pci_dev *pci_dev,
 
 static void pqi_pci_unmap(struct pci_dev *pci_dev,
struct pqi_sg_descriptor *descriptors, int num_descriptors,
-   int data_direction)
+   enum dma_data_direction data_direction)
 {
int i;
 
-   if (data_direction == PCI_DMA_NONE)
+   if (data_direction == DMA_NONE)
return;
 
for (i = 0; i < num_descriptors; i++)
-   pci_unmap_single(pci_dev,
+   dma_unmap_single(&pci_dev->dev,
(dma_addr_t)get_unaligned_le64(&descriptors[i].address),
get_unaligned_le32(&descriptors[i].length),
data_direction);
@@ -387,10 +387,9 @@ static void pqi_pci_unmap(struct pci_dev *pci_dev,
 static int pqi_build_raid_path_request(struct pqi_ctrl_info *ctrl_info,
struct pqi_raid_path_request *request, u8 cmd,
u8 *scsi3addr, void *buffer, size_t buffer_length,
-   u16 vpd_page, int *pci_direction)
+   u16 vpd_page, enum dma_data_direction *dir)
 {
u8 *cdb;
-   int pci_dir;
 
memset(request, 0, sizeof(*request));
 
@@ -458,23 +457,21 @@ static int pqi_build_raid_path_request(struct 
pqi_ctrl_info *ctrl_info,
 
switch (request->data_direction) {
case SOP_READ_FLAG:
-   pci_dir = PCI_DMA_FROMDEVICE;
+   *dir = DMA_FROM_DEVICE;
break;
case SOP_WRITE_FLAG:
-   pci_dir = PCI_DMA_TODEVICE;
+   *dir = DMA_TO_DEVICE;
break;
case SOP_NO_DIRECTION_FLAG:
-   pci_dir = PCI_DMA_NONE;
+   *dir = DMA_NONE;
break;
default:
-   pci_dir = PCI_DMA_BIDIRECTIONAL;
+   *dir = DMA_BIDIRECTIONAL;
break;
}
 
-   *pci_direction = pci_dir;
-
return pqi_map_single(ctrl_info->pci_dev, &request->sg_descriptors[0],
-   buffer, buffer_length, pci_dir);
+   buffer, buffer_length, *dir);
 }
 
 static inline void pqi_reinit_io_request(struct pqi_io_request *io_request)
@@ -516,21 +513,19 @@ static int pqi_identify_controller(struct pqi_ctrl_info 
*ctrl_info,
struct bmic_identify_controller *buffer)
 {
int rc;
-   int pci_direction;
+   enum dma_data_direction dir;
struct pqi_raid_path_request request;
 
rc = pqi_build_raid_path_request(ctrl_info, &request,
BMIC_IDENTIFY_CONTROLLER, RAID_CTLR_LUNID, buffer,
-   sizeof(*buffer), 0, &pci_direction);
+   sizeof(*buffer), 0, &dir);
if (rc)
return rc;
 
rc = pqi_submit_raid_request_synchronous(ctrl_info, &request.header, 0,
NULL, NO_TIMEOUT);
 
-   pqi_pci_unmap(ctrl_info->pci_dev, request.sg_descriptors, 1,
-   pci_direction);
-
+   pqi_pci_unmap(ctrl_info->pci_dev, request.sg_descriptors, 1, dir);
return rc;
 }
 
@@ -538,21 +533,19 @@ static int pqi_scsi_inquiry(struct pqi_ctrl_info 
*ctrl_info,
u8 *scsi3addr, u16 vpd_page, void *buffer, size_t buffer_length)
 {
int rc;
-   int pci_direction;
+   enum dma_data_direction dir;
struct pqi_raid_path_request request;
 
rc = pqi_build_raid_path_request(ctrl_info, &request,
INQUIRY, scsi3addr, buffer, bu

[PATCH 28/28] mesh: switch to generic DMA API

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

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

diff --git a/drivers/scsi/mesh.c b/drivers/scsi/mesh.c
index 82e01dbe90af..ec6940f2fcb3 100644
--- a/drivers/scsi/mesh.c
+++ b/drivers/scsi/mesh.c
@@ -1915,8 +1915,8 @@ static int mesh_probe(struct macio_dev *mdev, const 
struct of_device_id *match)
/* We use the PCI APIs for now until the generic one gets fixed
 * enough or until we get some macio-specific versions
 */
-   dma_cmd_space = pci_zalloc_consistent(macio_get_pci_dev(mdev),
- ms->dma_cmd_size, &dma_cmd_bus);
+   dma_cmd_space = dma_zalloc_coherent(&macio_get_pci_dev(mdev)->dev,
+   ms->dma_cmd_size, &dma_cmd_bus, GFP_KERNEL);
if (dma_cmd_space == NULL) {
printk(KERN_ERR "mesh: can't allocate DMA table\n");
goto out_unmap;
@@ -1974,7 +1974,7 @@ static int mesh_probe(struct macio_dev *mdev, const 
struct of_device_id *match)
 */
mesh_shutdown(mdev);
set_mesh_power(ms, 0);
-   pci_free_consistent(macio_get_pci_dev(mdev), ms->dma_cmd_size,
+   dma_free_coherent(&macio_get_pci_dev(mdev)->dev, ms->dma_cmd_size,
ms->dma_cmd_space, ms->dma_cmd_bus);
  out_unmap:
iounmap(ms->dma);
@@ -2007,7 +2007,7 @@ static int mesh_remove(struct macio_dev *mdev)
iounmap(ms->dma);
 
/* Free DMA commands memory */
-   pci_free_consistent(macio_get_pci_dev(mdev), ms->dma_cmd_size,
+   dma_free_coherent(&macio_get_pci_dev(mdev)->dev, ms->dma_cmd_size,
ms->dma_cmd_space, ms->dma_cmd_bus);
 
/* Release memory resources */
-- 
2.19.1



[PATCH 27/28] ips: switch to generic DMA API

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

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/ips.c | 80 --
 1 file changed, 41 insertions(+), 39 deletions(-)

diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c
index bd6ac6b5980a..378b6f37b613 100644
--- a/drivers/scsi/ips.c
+++ b/drivers/scsi/ips.c
@@ -208,7 +208,7 @@ module_param(ips, charp, 0);
 
 #define IPS_DMA_DIR(scb) ((!scb->scsi_cmd || ips_is_passthru(scb->scsi_cmd) || 
\
  DMA_NONE == scb->scsi_cmd->sc_data_direction) ? \
- PCI_DMA_BIDIRECTIONAL : \
+ DMA_BIDIRECTIONAL : \
  scb->scsi_cmd->sc_data_direction)
 
 #ifdef IPS_DEBUG
@@ -1529,11 +1529,12 @@ ips_alloc_passthru_buffer(ips_ha_t * ha, int length)
if (ha->ioctl_data && length <= ha->ioctl_len)
return 0;
/* there is no buffer or it's not big enough, allocate a new one */
-   bigger_buf = pci_alloc_consistent(ha->pcidev, length, &dma_busaddr);
+   bigger_buf = dma_alloc_coherent(&ha->pcidev->dev, length, &dma_busaddr,
+   GFP_KERNEL);
if (bigger_buf) {
/* free the old memory */
-   pci_free_consistent(ha->pcidev, ha->ioctl_len, ha->ioctl_data,
-   ha->ioctl_busaddr);
+   dma_free_coherent(&ha->pcidev->dev, ha->ioctl_len,
+ ha->ioctl_data, ha->ioctl_busaddr);
/* use the new memory */
ha->ioctl_data = (char *) bigger_buf;
ha->ioctl_len = length;
@@ -1678,9 +1679,8 @@ ips_flash_copperhead(ips_ha_t * ha, ips_passthru_t * pt, 
ips_scb_t * scb)
} else if (!ha->flash_data) {
datasize = pt->CoppCP.cmd.flashfw.total_packets *
pt->CoppCP.cmd.flashfw.count;
-   ha->flash_data = pci_alloc_consistent(ha->pcidev,
- datasize,
- 
&ha->flash_busaddr);
+   ha->flash_data = dma_alloc_coherent(&ha->pcidev->dev,
+   datasize, &ha->flash_busaddr, 
GFP_KERNEL);
if (!ha->flash_data){
printk(KERN_WARNING "Unable to allocate a flash 
buffer\n");
return IPS_FAILURE;
@@ -1858,7 +1858,7 @@ ips_flash_firmware(ips_ha_t * ha, ips_passthru_t * pt, 
ips_scb_t * scb)
 
scb->data_len = ha->flash_datasize;
scb->data_busaddr =
-   pci_map_single(ha->pcidev, ha->flash_data, scb->data_len,
+   dma_map_single(&ha->pcidev->dev, ha->flash_data, scb->data_len,
   IPS_DMA_DIR(scb));
scb->flags |= IPS_SCB_MAP_SINGLE;
scb->cmd.flashfw.command_id = IPS_COMMAND_ID(ha, scb);
@@ -1880,8 +1880,8 @@ ips_free_flash_copperhead(ips_ha_t * ha)
if (ha->flash_data == ips_FlashData)
test_and_clear_bit(0, &ips_FlashDataInUse);
else if (ha->flash_data)
-   pci_free_consistent(ha->pcidev, ha->flash_len, ha->flash_data,
-   ha->flash_busaddr);
+   dma_free_coherent(&ha->pcidev->dev, ha->flash_len,
+ ha->flash_data, ha->flash_busaddr);
ha->flash_data = NULL;
 }
 
@@ -4212,7 +4212,7 @@ ips_free(ips_ha_t * ha)
 
if (ha) {
if (ha->enq) {
-   pci_free_consistent(ha->pcidev, sizeof(IPS_ENQ),
+   dma_free_coherent(&ha->pcidev->dev, sizeof(IPS_ENQ),
ha->enq, ha->enq_busaddr);
ha->enq = NULL;
}
@@ -4221,7 +4221,7 @@ ips_free(ips_ha_t * ha)
ha->conf = NULL;
 
if (ha->adapt) {
-   pci_free_consistent(ha->pcidev,
+   dma_free_coherent(&ha->pcidev->dev,
sizeof (IPS_ADAPTER) +
sizeof (IPS_IO_CMD), ha->adapt,
ha->adapt->hw_status_start);
@@ -4229,7 +4229,7 @@ ips_free(ips_ha_t * ha)
}
 
if (ha->logical_drive_info) {
-   pci_free_consistent(ha->pcidev,
+   dma_free_coherent(&ha->pcidev->dev,
sizeof (IPS_LD_INFO),
ha->logical_drive_info,
ha->logical_drive_info_dma_addr);
@@ -4243,7 +4243,7 @@ ips_free(ips_ha_t * ha)
ha->subsys = NULL;
 
if (ha->ioctl_data) {
-   pci_free_consistent(ha->pcidev, ha->ioctl_len,
+

[PATCH 23/28] qla4xxx: fully convert to the generic DMA API

2018-10-14 Thread Christoph Hellwig
The driver is currently using an odd mix of legacy PCI DMA API and
generic DMA API calls, switch it over to the generic API entirely.

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/qla4xxx/ql4_os.c | 25 -
 1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index 0e13349dce57..662c033f428d 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -3382,7 +3382,7 @@ static int qla4xxx_alloc_pdu(struct iscsi_task *task, 
uint8_t opcode)
if (task->data_count) {
task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
 task->data_count,
-PCI_DMA_TODEVICE);
+DMA_TO_DEVICE);
}
 
DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
@@ -3437,7 +3437,7 @@ static void qla4xxx_task_cleanup(struct iscsi_task *task)
 
if (task->data_count) {
dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
-task->data_count, PCI_DMA_TODEVICE);
+task->data_count, DMA_TO_DEVICE);
}
 
DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
@@ -9020,25 +9020,16 @@ static void qla4xxx_remove_adapter(struct pci_dev *pdev)
 /**
  * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
  * @ha: HA context
- *
- * At exit, the @ha's flags.enable_64bit_addressing set to indicated
- * supported addressing method.
  */
 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
 {
-   int retval;
-
/* Update our PCI device dma_mask for full 64 bit mask */
-   if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
-   if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
-   dev_dbg(&ha->pdev->dev,
- "Failed to set 64 bit PCI consistent mask; "
-  "using 32 bit.\n");
-   retval = pci_set_consistent_dma_mask(ha->pdev,
-DMA_BIT_MASK(32));
-   }
-   } else
-   retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
+   if (dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(64))) {
+   dev_dbg(&ha->pdev->dev,
+ "Failed to set 64 bit PCI consistent mask; "
+  "using 32 bit.\n");
+   dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(32));
+   }
 }
 
 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
-- 
2.19.1



[PATCH 22/28] qla2xxx: fully convert to the generic DMA API

2018-10-14 Thread Christoph Hellwig
The driver is currently using an odd mix of legacy PCI DMA API and
generic DMA API calls, switch it over to the generic API entirely.

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/qla2xxx/qla_target.c  | 8 
 drivers/scsi/qla2xxx/tcm_qla2xxx.c | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index 3015f1bbcf1a..39828207bc1d 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -2425,7 +2425,7 @@ static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm)
BUG_ON(cmd->sg_cnt == 0);
 
prm->sg = (struct scatterlist *)cmd->sg;
-   prm->seg_cnt = pci_map_sg(cmd->qpair->pdev, cmd->sg,
+   prm->seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev, cmd->sg,
cmd->sg_cnt, cmd->dma_data_direction);
if (unlikely(prm->seg_cnt == 0))
goto out_err;
@@ -2452,7 +2452,7 @@ static int qlt_pci_map_calc_cnt(struct qla_tgt_prm *prm)
 
if (cmd->prot_sg_cnt) {
prm->prot_sg  = cmd->prot_sg;
-   prm->prot_seg_cnt = pci_map_sg(cmd->qpair->pdev,
+   prm->prot_seg_cnt = dma_map_sg(&cmd->qpair->pdev->dev,
cmd->prot_sg, cmd->prot_sg_cnt,
cmd->dma_data_direction);
if (unlikely(prm->prot_seg_cnt == 0))
@@ -2487,12 +2487,12 @@ static void qlt_unmap_sg(struct scsi_qla_host *vha, 
struct qla_tgt_cmd *cmd)
 
qpair = cmd->qpair;
 
-   pci_unmap_sg(qpair->pdev, cmd->sg, cmd->sg_cnt,
+   dma_unmap_sg(&qpair->pdev->dev, cmd->sg, cmd->sg_cnt,
cmd->dma_data_direction);
cmd->sg_mapped = 0;
 
if (cmd->prot_sg_cnt)
-   pci_unmap_sg(qpair->pdev, cmd->prot_sg, cmd->prot_sg_cnt,
+   dma_unmap_sg(&qpair->pdev->dev, cmd->prot_sg, cmd->prot_sg_cnt,
cmd->dma_data_direction);
 
if (!cmd->ctx)
diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c 
b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
index 731a094d2386..65053c066680 100644
--- a/drivers/scsi/qla2xxx/tcm_qla2xxx.c
+++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
@@ -424,7 +424,7 @@ static int tcm_qla2xxx_write_pending(struct se_cmd *se_cmd)
se_cmd->pi_err = 0;
 
/*
-* qla_target.c:qlt_rdy_to_xfer() will call pci_map_sg() to setup
+* qla_target.c:qlt_rdy_to_xfer() will call dma_map_sg() to setup
 * the SGL mappings into PCIe memory for incoming FCP WRITE data.
 */
return qlt_rdy_to_xfer(cmd);
-- 
2.19.1



[PATCH 25/28] vmw_pscsi: switch to generic DMA API

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

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/vmw_pvscsi.c | 77 +++
 1 file changed, 38 insertions(+), 39 deletions(-)

diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
index 0cd947f78b5b..6e491023fdd8 100644
--- a/drivers/scsi/vmw_pvscsi.c
+++ b/drivers/scsi/vmw_pvscsi.c
@@ -372,9 +372,9 @@ static int pvscsi_map_buffers(struct pvscsi_adapter 
*adapter,
pvscsi_create_sg(ctx, sg, segs);
 
e->flags |= PVSCSI_FLAG_CMD_WITH_SG_LIST;
-   ctx->sglPA = pci_map_single(adapter->dev, ctx->sgl,
-   SGL_SIZE, PCI_DMA_TODEVICE);
-   if (pci_dma_mapping_error(adapter->dev, ctx->sglPA)) {
+   ctx->sglPA = dma_map_single(&adapter->dev->dev,
+   ctx->sgl, SGL_SIZE, DMA_TO_DEVICE);
+   if (dma_mapping_error(&adapter->dev->dev, ctx->sglPA)) {
scmd_printk(KERN_ERR, cmd,
"vmw_pvscsi: Failed to map ctx 
sglist for DMA.\n");
scsi_dma_unmap(cmd);
@@ -389,9 +389,9 @@ static int pvscsi_map_buffers(struct pvscsi_adapter 
*adapter,
 * In case there is no S/G list, scsi_sglist points
 * directly to the buffer.
 */
-   ctx->dataPA = pci_map_single(adapter->dev, sg, bufflen,
+   ctx->dataPA = dma_map_single(&adapter->dev->dev, sg, bufflen,
 cmd->sc_data_direction);
-   if (pci_dma_mapping_error(adapter->dev, ctx->dataPA)) {
+   if (dma_mapping_error(&adapter->dev->dev, ctx->dataPA)) {
scmd_printk(KERN_ERR, cmd,
"vmw_pvscsi: Failed to map direct data 
buffer for DMA.\n");
return -ENOMEM;
@@ -417,23 +417,23 @@ static void pvscsi_unmap_buffers(const struct 
pvscsi_adapter *adapter,
if (count != 0) {
scsi_dma_unmap(cmd);
if (ctx->sglPA) {
-   pci_unmap_single(adapter->dev, ctx->sglPA,
-SGL_SIZE, PCI_DMA_TODEVICE);
+   dma_unmap_single(&adapter->dev->dev, ctx->sglPA,
+SGL_SIZE, DMA_TO_DEVICE);
ctx->sglPA = 0;
}
} else
-   pci_unmap_single(adapter->dev, ctx->dataPA, bufflen,
-cmd->sc_data_direction);
+   dma_unmap_single(&adapter->dev->dev, ctx->dataPA,
+bufflen, cmd->sc_data_direction);
}
if (cmd->sense_buffer)
-   pci_unmap_single(adapter->dev, ctx->sensePA,
-SCSI_SENSE_BUFFERSIZE, PCI_DMA_FROMDEVICE);
+   dma_unmap_single(&adapter->dev->dev, ctx->sensePA,
+SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
 }
 
 static int pvscsi_allocate_rings(struct pvscsi_adapter *adapter)
 {
-   adapter->rings_state = pci_alloc_consistent(adapter->dev, PAGE_SIZE,
-   &adapter->ringStatePA);
+   adapter->rings_state = dma_alloc_coherent(&adapter->dev->dev, PAGE_SIZE,
+   &adapter->ringStatePA, GFP_KERNEL);
if (!adapter->rings_state)
return -ENOMEM;
 
@@ -441,17 +441,17 @@ static int pvscsi_allocate_rings(struct pvscsi_adapter 
*adapter)
 pvscsi_ring_pages);
adapter->req_depth = adapter->req_pages
* PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE;
-   adapter->req_ring = pci_alloc_consistent(adapter->dev,
-adapter->req_pages * PAGE_SIZE,
-&adapter->reqRingPA);
+   adapter->req_ring = dma_alloc_coherent(&adapter->dev->dev,
+   adapter->req_pages * PAGE_SIZE, &adapter->reqRingPA,
+   GFP_KERNEL);
if (!adapter->req_ring)
return -ENOMEM;
 
adapter->cmp_pages = min(PVSCSI_MAX_NUM_PAGES_CMP_RING,
 pvscsi_ring_pages);
-   adapter->cmp_ring = pci_alloc_consistent(adapter->dev,
-adapter->cmp_pages * PAGE_SIZE,
-&adapter->cmpRingPA);
+   adapter->cmp_ring = dma_alloc_coherent(&adapter->dev->dev,
+   adapter->cmp_pages * PAGE_SIZE, &adapter->cmpRingPA,
+   GFP_KERNEL);
if

Re: [PATCH 0/3] sd: Rely on the driver core for asynchronous probing

2018-10-14 Thread Bart Van Assche

On 10/2/18 2:52 PM, Bart Van Assche wrote:

During the 2018 edition of LSF/MM there was a session about increasing SCSI
disk probing concurrency. This patch series implements what has been proposed
during that session, namely:
- Make sure that the driver core is aware of asynchronous SCSI LUN probing.
- Avoid unnecessary serialization between sd_probe() and sd_remove() because
   this could lead to a deadlock.


Has anyone already had the time to have a closer look at this patch series?

Thanks,

Bart.



Re: [PATCH v2 1/6] zorro_esp: Limit DMA transfers to 65535 bytes

2018-10-14 Thread Michael Schmitz

Hi Finn,

thanks for spotting this!

Am 14.10.2018 um 19:12 schrieb Finn Thain:

The core driver, esp_scsi, does not use the ESP_CONFIG2_FENAB bit, so
the chip's Transfer Counter register is only 16 bits wide (not 24).
A larger transfer cannot work and will theoretically result in a failed
command and a "DMA length is zero" error.

Fixes: 3109e5ae0311
Signed-off-by: Finn Thain 
Cc: Michael Schmitz 
Tested-by: Michael Schmitz 


Reviewed-by: Michael Schmitz 


---
 drivers/scsi/zorro_esp.c | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/scsi/zorro_esp.c b/drivers/scsi/zorro_esp.c
index bb70882e6b56..be79127db594 100644
--- a/drivers/scsi/zorro_esp.c
+++ b/drivers/scsi/zorro_esp.c
@@ -245,7 +245,7 @@ static int fastlane_esp_irq_pending(struct esp *esp)
 static u32 zorro_esp_dma_length_limit(struct esp *esp, u32 dma_addr,
u32 dma_len)
 {
-   return dma_len > 0xFF ? 0xFF : dma_len;
+   return dma_len > 0x ? 0x : dma_len;
 }

 static void zorro_esp_reset_dma(struct esp *esp)
@@ -484,7 +484,6 @@ static void zorro_esp_send_blz1230_dma_cmd(struct esp *esp, 
u32 addr,
scsi_esp_cmd(esp, ESP_CMD_DMA);
zorro_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
zorro_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
-   zorro_esp_write8(esp, (esp_count >> 16) & 0xff, ESP_TCHI);

scsi_esp_cmd(esp, cmd);
 }
@@ -529,7 +528,6 @@ static void zorro_esp_send_blz1230II_dma_cmd(struct esp 
*esp, u32 addr,
scsi_esp_cmd(esp, ESP_CMD_DMA);
zorro_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
zorro_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
-   zorro_esp_write8(esp, (esp_count >> 16) & 0xff, ESP_TCHI);

scsi_esp_cmd(esp, cmd);
 }
@@ -574,7 +572,6 @@ static void zorro_esp_send_blz2060_dma_cmd(struct esp *esp, 
u32 addr,
scsi_esp_cmd(esp, ESP_CMD_DMA);
zorro_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
zorro_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
-   zorro_esp_write8(esp, (esp_count >> 16) & 0xff, ESP_TCHI);

scsi_esp_cmd(esp, cmd);
 }
@@ -599,7 +596,6 @@ static void zorro_esp_send_cyber_dma_cmd(struct esp *esp, 
u32 addr,

zorro_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
zorro_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
-   zorro_esp_write8(esp, (esp_count >> 16) & 0xff, ESP_TCHI);

if (write) {
/* DMA receive */
@@ -649,7 +645,6 @@ static void zorro_esp_send_cyberII_dma_cmd(struct esp *esp, 
u32 addr,

zorro_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
zorro_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
-   zorro_esp_write8(esp, (esp_count >> 16) & 0xff, ESP_TCHI);

if (write) {
/* DMA receive */
@@ -691,7 +686,6 @@ static void zorro_esp_send_fastlane_dma_cmd(struct esp 
*esp, u32 addr,

zorro_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
zorro_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
-   zorro_esp_write8(esp, (esp_count >> 16) & 0xff, ESP_TCHI);

if (write) {
/* DMA receive */



Re: [PATCH 5/8] pcmcia: allow PCMCIA support independent of the architecture

2018-10-14 Thread Christoph Hellwig
On Sun, Oct 14, 2018 at 07:42:52AM +0200, Dominik Brodowski wrote:
> On Sat, Oct 13, 2018 at 05:10:13PM +0200, Christoph Hellwig wrote:
> > There is nothing architecture specific in the PCMCIA core, so allow
> > building it everywhere.  The actual host controllers will depend on ISA,
> > PCI or a specific SOC.
> > 
> > Signed-off-by: Christoph Hellwig 
> 
> Looks good to me, though I'm interested on any subtle (build) breakage when
> this gets exposure in -next. Will you push this patch upstream directly, or
> should it go in via the pcmcia tree? If it is the former, feel free to add

The patches in the series depend on each other (just in terms of
context).  I suspect the best would be to get it into the kbuild tree.

It has survived the build bot, which found some interesting issues in
the other patches (as well as the !UML dependency), but if more issues
show I can keep you in the loop.


Re: [PATCH v2 1/6] zorro_esp: Limit DMA transfers to 65535 bytes

2018-10-14 Thread Geert Uytterhoeven
Hi Finn,

On Sun, Oct 14, 2018 at 8:36 AM Finn Thain  wrote:
> The core driver, esp_scsi, does not use the ESP_CONFIG2_FENAB bit, so
> the chip's Transfer Counter register is only 16 bits wide (not 24).
> A larger transfer cannot work and will theoretically result in a failed
> command and a "DMA length is zero" error.

Thanks for your patch!

> Fixes: 3109e5ae0311

Fixes: 3109e5ae0311 ("scsi: zorro_esp: New driver for Amiga Zorro
NCR53C9x boards")

$ git help fixes
'fixes' is aliased to 'show --format='Fixes: %h ("%s")' -s'

BTW, if you use vim, add

noremap ;gs "zyiw:exe "new \| setlocal buftype=nofile
bufhidden=hide noswapfile syntax=git \| 0r ! git show ".@z."" \|
:0

to .vimrc, and type ";gs" when the cursor is positioned on a commit ID.

> Signed-off-by: Finn Thain 
> Cc: Michael Schmitz 
> Tested-by: Michael Schmitz 

> --- a/drivers/scsi/zorro_esp.c
> +++ b/drivers/scsi/zorro_esp.c
> @@ -245,7 +245,7 @@ static int fastlane_esp_irq_pending(struct esp *esp)
>  static u32 zorro_esp_dma_length_limit(struct esp *esp, u32 dma_addr,
> u32 dma_len)
>  {
> -   return dma_len > 0xFF ? 0xFF : dma_len;
> +   return dma_len > 0x ? 0x : dma_len;
>  }
>
>  static void zorro_esp_reset_dma(struct esp *esp)
> @@ -484,7 +484,6 @@ static void zorro_esp_send_blz1230_dma_cmd(struct esp 
> *esp, u32 addr,
> scsi_esp_cmd(esp, ESP_CMD_DMA);
> zorro_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
> zorro_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
> -   zorro_esp_write8(esp, (esp_count >> 16) & 0xff, ESP_TCHI);

Since all these sub-drivers seem to support 24-bit transfers, perhaps this is
something to be fixed in the esp_scsi core?

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


Re: [PATCH v2 2/6] esp_scsi: Track residual for PIO transfers

2018-10-14 Thread Geert Uytterhoeven
Hi Finn,

On Sun, Oct 14, 2018 at 8:36 AM Finn Thain  wrote:
> If a target disconnects during a PIO data transfer the command may
> fail when the target reconnects:
>
> scsi host1: DMA length is zero!
> scsi host1: cur adr[0438] len[]
>
> The scsi bus is then reset. This happens because the residual reached
> zero before the transfer was completed.
>
> The usual residual calculation relies on the Transfer Count registers
> which works for DMA transfers but not for PIO transfers. Fix the problem
> by storing the PIO transfer residual and using that to correctly
> calculate bytes_sent.

Thanks for yur patch!

> Fixes: 6fe07aaffbf0

Fixes: 6fe07aaffbf0 ("[SCSI] m68k: new mac_esp scsi driver")

> Tested-by: Stan Johnson 
> Signed-off-by: Finn Thain 
> Tested-by: Michael Schmitz 

> --- a/drivers/scsi/esp_scsi.h
> +++ b/drivers/scsi/esp_scsi.h
> @@ -540,6 +540,8 @@ struct esp {
>
> void*dma;
> int dmarev;
> +
> +   int send_cmd_residual;

unsigned int?

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


Re: [PATCH v2 5/6] esp_scsi: De-duplicate PIO routines

2018-10-14 Thread Geert Uytterhoeven
Hi Finn,

On Sun, Oct 14, 2018 at 8:35 AM Finn Thain  wrote:
> As a temporary measure, the code to implement PIO transfers was
> duplicated in zorro_esp and mac_esp. Now that it has stabilized
> move the common code into the core driver but don't build it unless
> needed.
>
> This replaces the inline assembler with more portable writesb() calls.
> Optimizing the m68k writesb() implementation is a separate patch.
>
> Tested-by: Stan Johnson 
> Signed-off-by: Finn Thain 
> Tested-by: Michael Schmitz 

Thanks for your patch!

> --- a/drivers/scsi/Kconfig
> +++ b/drivers/scsi/Kconfig
> @@ -42,6 +42,10 @@ config SCSI_DMA
> bool
> default n
>
> +config SCSI_ESP_PIO
> +   bool
> +   default n

"default n" is the default, so please drop this line.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


Re: [PATCH v2 3/6] esp_scsi: Grant disconnect privilege for untagged commands

2018-10-14 Thread Christoph Hellwig
> + *p++ = IDENTIFY(lp && (tp->flags & ESP_TGT_DISCONNECT), lun);

I think lp should always be non-NULL here.


Re: [PATCH v2 3/6] esp_scsi: Grant disconnect privilege for untagged commands

2018-10-14 Thread Michael Schmitz

On 15/10/18 04:47, Christoph Hellwig wrote:


+   *p++ = IDENTIFY(lp && (tp->flags & ESP_TGT_DISCONNECT), lun);

I think lp should always be non-NULL here.


That indeed appears to be the case these days.

So we can't rely on !lp to detect when probing the bus any longer. What 
else would be available? Do commands used for device probing also have a 
tag these days by default?


Do we really need to make that distinction?

Cheers,

    Michael





Re: [PATCH v2 1/6] zorro_esp: Limit DMA transfers to 65535 bytes

2018-10-14 Thread Finn Thain
On Sun, 14 Oct 2018, Geert Uytterhoeven wrote:

> 
> > Fixes: 3109e5ae0311
> 
> Fixes: 3109e5ae0311 ("scsi: zorro_esp: New driver for Amiga Zorro
> NCR53C9x boards")
> 

OK.

> $ git help fixes
> 'fixes' is aliased to 'show --format='Fixes: %h ("%s")' -s'
> 
> BTW, if you use vim, add
> 
> noremap ;gs "zyiw:exe "new \| setlocal buftype=nofile
> bufhidden=hide noswapfile syntax=git \| 0r ! git show ".@z."" \|
> :0
> 
> to .vimrc, and type ";gs" when the cursor is positioned on a commit ID.
> 

Thanks.

> > Signed-off-by: Finn Thain 
> > Cc: Michael Schmitz 
> > Tested-by: Michael Schmitz 
> 
> > --- a/drivers/scsi/zorro_esp.c
> > +++ b/drivers/scsi/zorro_esp.c
> > @@ -245,7 +245,7 @@ static int fastlane_esp_irq_pending(struct esp *esp)
> >  static u32 zorro_esp_dma_length_limit(struct esp *esp, u32 dma_addr,
> > u32 dma_len)
> >  {
> > -   return dma_len > 0xFF ? 0xFF : dma_len;
> > +   return dma_len > 0x ? 0x : dma_len;
> >  }
> >
> >  static void zorro_esp_reset_dma(struct esp *esp)
> > @@ -484,7 +484,6 @@ static void zorro_esp_send_blz1230_dma_cmd(struct esp 
> > *esp, u32 addr,
> > scsi_esp_cmd(esp, ESP_CMD_DMA);
> > zorro_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
> > zorro_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
> > -   zorro_esp_write8(esp, (esp_count >> 16) & 0xff, ESP_TCHI);
> 
> Since all these sub-drivers seem to support 24-bit transfers, perhaps this is
> something to be fixed in the esp_scsi core?
> 

I don't think there is anything to fix in the esp_scsi core. The fact that 
no-one saw the error indicates that large transfers don't occur in 
practice.

If you said there is an opportunity for an enhancement, I could agree, 
assuming that you also found a way to produce large IO requests. But I 
doubt that such an enhancement would make a measurable improvement.

Even if the benefit was measurable, the fix under review would still be 
needed for stable kernels.

BTW, Michael and I already discussed all this (it probably should have 
happened on the linux-m68k list).

Please see,

$ grep -lr ESP_CONFIG2_FENAB drivers/scsi/
drivers/scsi/am53c974.c
drivers/scsi/esp_scsi.c
drivers/scsi/esp_scsi.h

The authors of am53c974.c obviously decided it wasn't wise to make this 
feature mandatory (which suggests that perhaps it shouldn't go into common 
code).

The comments in esp_scsi.c say that ESP_CONFIG2_FENAB has undesirable 
consequences. There is information in the datasheets on this point but I 
didn't follow it up because I don't see a performance issue.

-- 


Re: [PATCH v2 2/6] esp_scsi: Track residual for PIO transfers

2018-10-14 Thread Finn Thain
On Sun, 14 Oct 2018, Geert Uytterhoeven wrote:

> 
> > Fixes: 6fe07aaffbf0
> 
> Fixes: 6fe07aaffbf0 ("[SCSI] m68k: new mac_esp scsi driver")
> 

Fixed.

> > Tested-by: Stan Johnson 
> > Signed-off-by: Finn Thain 
> > Tested-by: Michael Schmitz 
> 
> > --- a/drivers/scsi/esp_scsi.h
> > +++ b/drivers/scsi/esp_scsi.h
> > @@ -540,6 +540,8 @@ struct esp {
> >
> > void*dma;
> > int dmarev;
> > +
> > +   int send_cmd_residual;
> 
> unsigned int?
> 

My first thought was to use u32, same as esp_count. But it turns out that 
the end result really is an int --

static int esp_data_bytes_sent(struct esp *esp, struct esp_cmd_entry *ent,
   struct scsi_cmnd *cmd)
{
int fifo_cnt, ecount, bytes_sent, flush_fifo;

...
bytes_sent = esp->data_dma_len;
bytes_sent -= ecount;
bytes_sent -= esp->send_cmd_residual;
...
return bytes_sent;
}

Apparently over/underflow is a real possibility, because there is a test 
for this in esp_process_event().

-- 

> Gr{oetje,eeting}s,
> 
> Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- 
> ge...@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like 
> that.
> -- Linus Torvalds
> 


Re: [PATCH v2 3/6] esp_scsi: Grant disconnect privilege for untagged commands

2018-10-14 Thread Finn Thain
On Mon, 15 Oct 2018, Michael Schmitz wrote:

> 
> Do we really need to make that distinction?
> 

esp_reconnect() dereferences lp, so !lp has to inhibit disconnection.

At least, that's my reading. I can't see any other reason for the lp 
conditional.

-- 


Re: [PATCH v2 3/6] esp_scsi: Grant disconnect privilege for untagged commands

2018-10-14 Thread Finn Thain
On Sun, 14 Oct 2018, Christoph Hellwig wrote:

> > +   *p++ = IDENTIFY(lp && (tp->flags & ESP_TGT_DISCONNECT), lun);
> 
> I think lp should always be non-NULL here.
> 

It's not clear from Documentation/scsi/scsi_mid_low_api.txt, but I guess 
that's true for scanning of targets.

Is it true in general that queuecommand for a device will not occur before 
its slave_alloc and not after its slave_destroy invocation?

(I'm thinking of queuecommand via the other command submission paths, like 
ioctl.)

-- 


Re: [PATCH v4 00/11] Zoned block device support improvements

2018-10-14 Thread Damien Le Moal
Jens,

On 2018/10/14 7:43, Jens Axboe wrote:
> On 10/12/18 4:08 AM, Damien Le Moal wrote:
>> This series improves zoned block device support (reduce overhead) and
>> introduces many simplifications to the code (overall, there are more 
>> deletions
>> than insertions).
>>
>> In more details:
>> * Patches 1 to 3 are SCSI side (sd driver) cleanups and improvements reducing
>>   the overhead of report zones command execution during disk scan and
>>   revalidation.
>> * Patches 4 to 9 improve the useability and user API of zoned block devices.
>> * Patch 10 is the main part of this series. This patch replaces the
>>   REQ_OP_ZONE_REPORT BIO/request operation for executing report zones 
>> commands
>>   with a block device file operation, removing the need for the command reply
>>   payload in-place rewriting in the BIO buffer. This leads to major
>>   simplification of the code in many places.
>> * Patch 11 further simplifies the code of low level drivers by providing a
>>   generic implementation of zoned block device request queue zone bitmaps
>>   initialization and revalidation.
>>
>> Please consider the addition of these patches in 4.20.
>> Comments are as always welcome.
> 
> How do we want to funnel this series? 1-3 look separate, so perhaps they
> should go through the scsi tree. Then I can take the rest. Or do some
> of the later ones depend on 1-3 being in, in terms of applying cleanly?
> I can also take all of them, looks like only #3 needs a SCSI ack.

Patch 10 and 11 will not apply cleanly for the scsi part without 1-3 in first.
1-3, 10 and 11 would need an ack/review from Martin (SCSI).
And 10-11 also probably need an ack/review from Mike for the DM changes.

Best regards.

-- 
Damien Le Moal
Western Digital Research


Re: [PATCH v2 5/6] esp_scsi: De-duplicate PIO routines

2018-10-14 Thread Finn Thain
On Sun, 14 Oct 2018, Geert Uytterhoeven wrote:

> 
> > --- a/drivers/scsi/Kconfig
> > +++ b/drivers/scsi/Kconfig
> > @@ -42,6 +42,10 @@ config SCSI_DMA
> > bool
> > default n
> >
> > +config SCSI_ESP_PIO
> > +   bool
> > +   default n
> 
> "default n" is the default, so please drop this line.
> 

Done. Thanks.

-- 


Re: [PATCH v2 3/6] esp_scsi: Grant disconnect privilege for untagged commands

2018-10-14 Thread Finn Thain
On Mon, 15 Oct 2018, Finn Thain wrote:

> On Sun, 14 Oct 2018, Christoph Hellwig wrote:
> 
> > > + *p++ = IDENTIFY(lp && (tp->flags & ESP_TGT_DISCONNECT), lun);
> > 
> > I think lp should always be non-NULL here.
> > 
> 
> It's not clear from Documentation/scsi/scsi_mid_low_api.txt, but I guess 
> that's true for scanning of targets.
> 
> Is it true in general that queuecommand for a device will not occur 
> before its slave_alloc and not after its slave_destroy invocation?
> 
> (I'm thinking of queuecommand via the other command submission paths, 
> like ioctl.)
> 

Nevermind. From a closer reading of the Documentation, I see that it is 
true in general.

-- 


Re: [PATCH v2 3/6] esp_scsi: Grant disconnect privilege for untagged commands

2018-10-14 Thread Christoph Hellwig
On Mon, Oct 15, 2018 at 10:13:37AM +1100, Finn Thain wrote:
> On Sun, 14 Oct 2018, Christoph Hellwig wrote:
> 
> > > + *p++ = IDENTIFY(lp && (tp->flags & ESP_TGT_DISCONNECT), lun);
> > 
> > I think lp should always be non-NULL here.
> > 
> 
> It's not clear from Documentation/scsi/scsi_mid_low_api.txt, but I guess 
> that's true for scanning of targets.
> 
> Is it true in general that queuecommand for a device will not occur before 
> its slave_alloc and not after its slave_destroy invocation?

Yes.


Re: [PATCH 5/6] esp_scsi: De-duplicate PIO routines

2018-10-14 Thread Hannes Reinecke

On 10/13/18 2:51 AM, Finn Thain wrote:

As a temporary measure, the code to implement PIO transfers was
duplicated in zorro_esp and mac_esp. Now that this code has stabilized,
move it into the core driver to eliminate the duplication.

This replaces the inline assembler with more portable writesb() calls.
Optimizing the m68k writesb() implementation is a separate patch.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
---
  drivers/scsi/esp_scsi.c  | 126 +
  drivers/scsi/esp_scsi.h  |   5 +
  drivers/scsi/mac_esp.c   | 173 ++-
  drivers/scsi/zorro_esp.c | 232 +++
  4 files changed, 171 insertions(+), 365 deletions(-)

diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
index 6ccaf818357e..646701fc22a4 100644
--- a/drivers/scsi/esp_scsi.c
+++ b/drivers/scsi/esp_scsi.c
@@ -2776,3 +2776,129 @@ MODULE_PARM_DESC(esp_debug,
  
  module_init(esp_init);

  module_exit(esp_exit);
+
+#if IS_ENABLED(CONFIG_SCSI_MAC_ESP) || IS_ENABLED(CONFIG_SCSI_ZORRO_ESP)
+static inline unsigned int esp_wait_for_fifo(struct esp *esp)
+{
+   int i = 50;
+
+   do {
+   unsigned int fbytes = esp_read8(ESP_FFLAGS) & ESP_FF_FBYTES;
+
+   if (fbytes)
+   return fbytes;
+
+   udelay(2);
+   } while (--i);
+
+   pr_err("FIFO is empty (sreg %02x)\n", esp_read8(ESP_STATUS));
+   return 0;
+}
+
+static inline int esp_wait_for_intr(struct esp *esp)
+{
+   int i = 50;
+
+   do {
+   esp->sreg = esp_read8(ESP_STATUS);
+   if (esp->sreg & ESP_STAT_INTR)
+   return 0;
+
+   udelay(2);
+   } while (--i);
+
+   pr_err("IRQ timeout (sreg %02x)\n", esp->sreg);
+   return 1;
+}
+
+#define ESP_FIFO_SIZE 16
+
+void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
+ u32 dma_count, int write, u8 cmd)
+{
+   u8 phase = esp->sreg & ESP_STAT_PMASK;
+
+   cmd &= ~ESP_CMD_DMA;
+   esp->send_cmd_error = 0;
+
+   if (write) {
+   u8 *dst = (u8 *)addr;
+   u8 mask = ~(phase == ESP_MIP ? ESP_INTR_FDONE : ESP_INTR_BSERV);
+
+   scsi_esp_cmd(esp, cmd);
+
+   while (1) {
+   if (!esp_wait_for_fifo(esp))
+   break;
+
+   *dst++ = esp_read8(ESP_FDATA);
+   --esp_count;
+
+   if (!esp_count)
+   break;
+
+   if (esp_wait_for_intr(esp)) {
+   esp->send_cmd_error = 1;
+   break;
+   }
+
+   if ((esp->sreg & ESP_STAT_PMASK) != phase)
+   break;
+
+   esp->ireg = esp_read8(ESP_INTRPT);
+   if (esp->ireg & mask) {
+   esp->send_cmd_error = 1;
+   break;
+   }
+
+   if (phase == ESP_MIP)
+   scsi_esp_cmd(esp, ESP_CMD_MOK);
+
+   scsi_esp_cmd(esp, ESP_CMD_TI);
+   }
+   } else {
+   unsigned int n = ESP_FIFO_SIZE;
+   u8 *src = (u8 *)addr;
+
+   scsi_esp_cmd(esp, ESP_CMD_FLUSH);
+
+   if (n > esp_count)
+   n = esp_count;
+   writesb(esp->fifo_reg, src, n);
+   src += n;
+   esp_count -= n;
+
+   scsi_esp_cmd(esp, cmd);
+
+   while (esp_count) {
+   if (esp_wait_for_intr(esp)) {
+   esp->send_cmd_error = 1;
+   break;
+   }
+
+   if ((esp->sreg & ESP_STAT_PMASK) != phase)
+   break;
+
+   esp->ireg = esp_read8(ESP_INTRPT);
+   if (esp->ireg & ~ESP_INTR_BSERV) {
+   esp->send_cmd_error = 1;
+   break;
+   }
+
+   n = ESP_FIFO_SIZE -
+   (esp_read8(ESP_FFLAGS) & ESP_FF_FBYTES);
+
+   if (n > esp_count)
+   n = esp_count;
+   writesb(esp->fifo_reg, src, n);
+   src += n;
+   esp_count -= n;
+
+   scsi_esp_cmd(esp, ESP_CMD_TI);
+   }
+   }
+
+   esp->send_cmd_residual = esp_count;
+}
+EXPORT_SYMBOL(esp_send_pio_cmd);
+#endif


These function are conditional, but


diff --git a/drivers/scsi/esp_scsi.h b/drivers/scsi/esp_scsi.h
index d0c032803749..2590e5eda595 100644
--- a/drivers/scsi/esp_scsi.h
+++ b/drivers/scsi/esp_scsi.h
@@ -431,6 +431,7 @@ struct esp_driver_ops {
  struct esp 

Re: [PATCH v2 5/6] esp_scsi: De-duplicate PIO routines

2018-10-14 Thread Hannes Reinecke

On 10/14/18 8:12 AM, Finn Thain wrote:

As a temporary measure, the code to implement PIO transfers was
duplicated in zorro_esp and mac_esp. Now that it has stabilized
move the common code into the core driver but don't build it unless
needed.

This replaces the inline assembler with more portable writesb() calls.
Optimizing the m68k writesb() implementation is a separate patch.

Tested-by: Stan Johnson 
Signed-off-by: Finn Thain 
Tested-by: Michael Schmitz 
---
Changed since v1:
  - Use shost_printk() instead of pr_err().
  - Add new symbol CONFIG_SCSI_ESP_PIO to Kconfig.
---
  drivers/scsi/Kconfig |   6 +
  drivers/scsi/esp_scsi.c  | 128 +
  drivers/scsi/esp_scsi.h  |   5 +
  drivers/scsi/mac_esp.c   | 173 +
  drivers/scsi/zorro_esp.c | 232 ++-
  5 files changed, 179 insertions(+), 365 deletions(-)

diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 35c909bbf8ba..81c6872f24f8 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -42,6 +42,10 @@ config SCSI_DMA
bool
default n
  
+config SCSI_ESP_PIO

+   bool
+   default n
+
  config SCSI_NETLINK
bool
default n
@@ -1355,6 +1359,7 @@ config SCSI_ZORRO_ESP
tristate "Zorro ESP SCSI support"
depends on ZORRO && SCSI
select SCSI_SPI_ATTRS
+   select SCSI_ESP_PIO
help
  Support for various NCR53C9x (ESP) based SCSI controllers on Zorro
  expansion boards for the Amiga.
@@ -1397,6 +1402,7 @@ config SCSI_MAC_ESP
tristate "Macintosh NCR53c9[46] SCSI"
depends on MAC && SCSI
select SCSI_SPI_ATTRS
+   select SCSI_ESP_PIO
help
  This is the NCR 53c9x SCSI controller found on most of the 68040
  based Macintoshes.
diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
index 6ccaf818357e..305a322ad13c 100644
--- a/drivers/scsi/esp_scsi.c
+++ b/drivers/scsi/esp_scsi.c
@@ -2776,3 +2776,131 @@ MODULE_PARM_DESC(esp_debug,
  
  module_init(esp_init);

  module_exit(esp_exit);
+
+#ifdef CONFIG_SCSI_ESP_PIO
+static inline unsigned int esp_wait_for_fifo(struct esp *esp)
+{
+   int i = 50;
+
+   do {
+   unsigned int fbytes = esp_read8(ESP_FFLAGS) & ESP_FF_FBYTES;
+
+   if (fbytes)
+   return fbytes;
+
+   udelay(2);
+   } while (--i);
+
+   shost_printk(KERN_ERR, esp->host, "FIFO is empty (sreg %02x)\n",
+esp_read8(ESP_STATUS));
+   return 0;
+}
+
+static inline int esp_wait_for_intr(struct esp *esp)
+{
+   int i = 50;
+
+   do {
+   esp->sreg = esp_read8(ESP_STATUS);
+   if (esp->sreg & ESP_STAT_INTR)
+   return 0;
+
+   udelay(2);
+   } while (--i);
+
+   shost_printk(KERN_ERR, esp->host, "IRQ timeout (sreg %02x)\n",
+esp->sreg);
+   return 1;
+}
+
+#define ESP_FIFO_SIZE 16
+
+void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
+ u32 dma_count, int write, u8 cmd)
+{
+   u8 phase = esp->sreg & ESP_STAT_PMASK;
+
+   cmd &= ~ESP_CMD_DMA;
+   esp->send_cmd_error = 0;
+
+   if (write) {
+   u8 *dst = (u8 *)addr;
+   u8 mask = ~(phase == ESP_MIP ? ESP_INTR_FDONE : ESP_INTR_BSERV);
+
+   scsi_esp_cmd(esp, cmd);
+
+   while (1) {
+   if (!esp_wait_for_fifo(esp))
+   break;
+
+   *dst++ = esp_read8(ESP_FDATA);
+   --esp_count;
+
+   if (!esp_count)
+   break;
+
+   if (esp_wait_for_intr(esp)) {
+   esp->send_cmd_error = 1;
+   break;
+   }
+
+   if ((esp->sreg & ESP_STAT_PMASK) != phase)
+   break;
+
+   esp->ireg = esp_read8(ESP_INTRPT);
+   if (esp->ireg & mask) {
+   esp->send_cmd_error = 1;
+   break;
+   }
+
+   if (phase == ESP_MIP)
+   scsi_esp_cmd(esp, ESP_CMD_MOK);
+
+   scsi_esp_cmd(esp, ESP_CMD_TI);
+   }
+   } else {
+   unsigned int n = ESP_FIFO_SIZE;
+   u8 *src = (u8 *)addr;
+
+   scsi_esp_cmd(esp, ESP_CMD_FLUSH);
+
+   if (n > esp_count)
+   n = esp_count;
+   writesb(esp->fifo_reg, src, n);
+   src += n;
+   esp_count -= n;
+
+   scsi_esp_cmd(esp, cmd);
+
+   while (esp_count) {
+   if (esp_wait_for_intr(esp)) {
+   esp->send_cmd_error = 1;
+   brea

Re: [PATCH 5/6] esp_scsi: De-duplicate PIO routines

2018-10-14 Thread Finn Thain



On Mon, 15 Oct 2018, Hannes Reinecke wrote:

> On 10/13/18 2:51 AM, Finn Thain wrote:
> > As a temporary measure, the code to implement PIO transfers was
> > duplicated in zorro_esp and mac_esp. Now that this code has stabilized,
> > move it into the core driver to eliminate the duplication.
> > 
> > This replaces the inline assembler with more portable writesb() calls.
> > Optimizing the m68k writesb() implementation is a separate patch.
> > 
> > Tested-by: Stan Johnson 
> > Signed-off-by: Finn Thain 
> > ---
> >   drivers/scsi/esp_scsi.c  | 126 +
> >   drivers/scsi/esp_scsi.h  |   5 +
> >   drivers/scsi/mac_esp.c   | 173 ++-
> >   drivers/scsi/zorro_esp.c | 232 
> > +++
> >   4 files changed, 171 insertions(+), 365 deletions(-)
> > 
> > diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
> > index 6ccaf818357e..646701fc22a4 100644
> > --- a/drivers/scsi/esp_scsi.c
> > +++ b/drivers/scsi/esp_scsi.c
> > @@ -2776,3 +2776,129 @@ MODULE_PARM_DESC(esp_debug,
> >   
> >   module_init(esp_init);
> >   module_exit(esp_exit);
> > +
> > +#if IS_ENABLED(CONFIG_SCSI_MAC_ESP) || IS_ENABLED(CONFIG_SCSI_ZORRO_ESP)
> > +static inline unsigned int esp_wait_for_fifo(struct esp *esp)
> > +{
> > +   int i = 50;
> > +
> > +   do {
> > +   unsigned int fbytes = esp_read8(ESP_FFLAGS) & ESP_FF_FBYTES;
> > +
> > +   if (fbytes)
> > +   return fbytes;
> > +
> > +   udelay(2);
> > +   } while (--i);
> > +
> > +   pr_err("FIFO is empty (sreg %02x)\n", esp_read8(ESP_STATUS));
> > +   return 0;
> > +}
> > +
> > +static inline int esp_wait_for_intr(struct esp *esp)
> > +{
> > +   int i = 50;
> > +
> > +   do {
> > +   esp->sreg = esp_read8(ESP_STATUS);
> > +   if (esp->sreg & ESP_STAT_INTR)
> > +   return 0;
> > +
> > +   udelay(2);
> > +   } while (--i);
> > +
> > +   pr_err("IRQ timeout (sreg %02x)\n", esp->sreg);
> > +   return 1;
> > +}
> > +
> > +#define ESP_FIFO_SIZE 16
> > +
> > +void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
> > + u32 dma_count, int write, u8 cmd)
> > +{
> > +   u8 phase = esp->sreg & ESP_STAT_PMASK;
> > +
> > +   cmd &= ~ESP_CMD_DMA;
> > +   esp->send_cmd_error = 0;
> > +
> > +   if (write) {
> > +   u8 *dst = (u8 *)addr;
> > +   u8 mask = ~(phase == ESP_MIP ? ESP_INTR_FDONE : ESP_INTR_BSERV);
> > +
> > +   scsi_esp_cmd(esp, cmd);
> > +
> > +   while (1) {
> > +   if (!esp_wait_for_fifo(esp))
> > +   break;
> > +
> > +   *dst++ = esp_read8(ESP_FDATA);
> > +   --esp_count;
> > +
> > +   if (!esp_count)
> > +   break;
> > +
> > +   if (esp_wait_for_intr(esp)) {
> > +   esp->send_cmd_error = 1;
> > +   break;
> > +   }
> > +
> > +   if ((esp->sreg & ESP_STAT_PMASK) != phase)
> > +   break;
> > +
> > +   esp->ireg = esp_read8(ESP_INTRPT);
> > +   if (esp->ireg & mask) {
> > +   esp->send_cmd_error = 1;
> > +   break;
> > +   }
> > +
> > +   if (phase == ESP_MIP)
> > +   scsi_esp_cmd(esp, ESP_CMD_MOK);
> > +
> > +   scsi_esp_cmd(esp, ESP_CMD_TI);
> > +   }
> > +   } else {
> > +   unsigned int n = ESP_FIFO_SIZE;
> > +   u8 *src = (u8 *)addr;
> > +
> > +   scsi_esp_cmd(esp, ESP_CMD_FLUSH);
> > +
> > +   if (n > esp_count)
> > +   n = esp_count;
> > +   writesb(esp->fifo_reg, src, n);
> > +   src += n;
> > +   esp_count -= n;
> > +
> > +   scsi_esp_cmd(esp, cmd);
> > +
> > +   while (esp_count) {
> > +   if (esp_wait_for_intr(esp)) {
> > +   esp->send_cmd_error = 1;
> > +   break;
> > +   }
> > +
> > +   if ((esp->sreg & ESP_STAT_PMASK) != phase)
> > +   break;
> > +
> > +   esp->ireg = esp_read8(ESP_INTRPT);
> > +   if (esp->ireg & ~ESP_INTR_BSERV) {
> > +   esp->send_cmd_error = 1;
> > +   break;
> > +   }
> > +
> > +   n = ESP_FIFO_SIZE -
> > +   (esp_read8(ESP_FFLAGS) & ESP_FF_FBYTES);
> > +
> > +   if (n > esp_count)
> > +   n = esp_count;
> > +   writesb(esp->fifo_reg, src, n);
> > +   src += n;
> > +   esp_count -= n;
> > +
> > +   scsi_esp_cmd(esp, ESP_CMD_TI);
> > +   }
> > +   }
> > +
> > +   esp->send_cmd_residual = 

Re: [PATCH v2 5/6] esp_scsi: De-duplicate PIO routines

2018-10-14 Thread Finn Thain
On Mon, 15 Oct 2018, Hannes Reinecke wrote:

> On 10/14/18 8:12 AM, Finn Thain wrote:
> > As a temporary measure, the code to implement PIO transfers was
> > duplicated in zorro_esp and mac_esp. Now that it has stabilized
> > move the common code into the core driver but don't build it unless
> > needed.
> > 
> > This replaces the inline assembler with more portable writesb() calls.
> > Optimizing the m68k writesb() implementation is a separate patch.
> > 
> > Tested-by: Stan Johnson 
> > Signed-off-by: Finn Thain 
> > Tested-by: Michael Schmitz 
> > ---
> > Changed since v1:
> >   - Use shost_printk() instead of pr_err().
> >   - Add new symbol CONFIG_SCSI_ESP_PIO to Kconfig.
> > ---
> >   drivers/scsi/Kconfig |   6 +
> >   drivers/scsi/esp_scsi.c  | 128 +
> >   drivers/scsi/esp_scsi.h  |   5 +
> >   drivers/scsi/mac_esp.c   | 173 +
> >   drivers/scsi/zorro_esp.c | 232 ++-
> >   5 files changed, 179 insertions(+), 365 deletions(-)
> > 
> > diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
> > index 35c909bbf8ba..81c6872f24f8 100644
> > --- a/drivers/scsi/Kconfig
> > +++ b/drivers/scsi/Kconfig
> > @@ -42,6 +42,10 @@ config SCSI_DMA
> > bool
> > default n
> >   +config SCSI_ESP_PIO
> > +   bool
> > +   default n
> > +
> >   config SCSI_NETLINK
> > bool
> > default n
> > @@ -1355,6 +1359,7 @@ config SCSI_ZORRO_ESP
> > tristate "Zorro ESP SCSI support"
> > depends on ZORRO && SCSI
> > select SCSI_SPI_ATTRS
> > +   select SCSI_ESP_PIO
> > help
> >   Support for various NCR53C9x (ESP) based SCSI controllers on Zorro
> >   expansion boards for the Amiga.
> > @@ -1397,6 +1402,7 @@ config SCSI_MAC_ESP
> > tristate "Macintosh NCR53c9[46] SCSI"
> > depends on MAC && SCSI
> > select SCSI_SPI_ATTRS
> > +   select SCSI_ESP_PIO
> > help
> >   This is the NCR 53c9x SCSI controller found on most of the 68040
> >   based Macintoshes.
> > diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
> > index 6ccaf818357e..305a322ad13c 100644
> > --- a/drivers/scsi/esp_scsi.c
> > +++ b/drivers/scsi/esp_scsi.c
> > @@ -2776,3 +2776,131 @@ MODULE_PARM_DESC(esp_debug,
> > module_init(esp_init);
> >   module_exit(esp_exit);
> > +
> > +#ifdef CONFIG_SCSI_ESP_PIO
> > +static inline unsigned int esp_wait_for_fifo(struct esp *esp)
> > +{
> > +   int i = 50;
> > +
> > +   do {
> > +   unsigned int fbytes = esp_read8(ESP_FFLAGS) & ESP_FF_FBYTES;
> > +
> > +   if (fbytes)
> > +   return fbytes;
> > +
> > +   udelay(2);
> > +   } while (--i);
> > +
> > +   shost_printk(KERN_ERR, esp->host, "FIFO is empty (sreg %02x)\n",
> > +esp_read8(ESP_STATUS));
> > +   return 0;
> > +}
> > +
> > +static inline int esp_wait_for_intr(struct esp *esp)
> > +{
> > +   int i = 50;
> > +
> > +   do {
> > +   esp->sreg = esp_read8(ESP_STATUS);
> > +   if (esp->sreg & ESP_STAT_INTR)
> > +   return 0;
> > +
> > +   udelay(2);
> > +   } while (--i);
> > +
> > +   shost_printk(KERN_ERR, esp->host, "IRQ timeout (sreg %02x)\n",
> > +esp->sreg);
> > +   return 1;
> > +}
> > +
> > +#define ESP_FIFO_SIZE 16
> > +
> > +void esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
> > + u32 dma_count, int write, u8 cmd)
> > +{
> > +   u8 phase = esp->sreg & ESP_STAT_PMASK;
> > +
> > +   cmd &= ~ESP_CMD_DMA;
> > +   esp->send_cmd_error = 0;
> > +
> > +   if (write) {
> > +   u8 *dst = (u8 *)addr;
> > +   u8 mask = ~(phase == ESP_MIP ? ESP_INTR_FDONE :
> > ESP_INTR_BSERV);
> > +
> > +   scsi_esp_cmd(esp, cmd);
> > +
> > +   while (1) {
> > +   if (!esp_wait_for_fifo(esp))
> > +   break;
> > +
> > +   *dst++ = esp_read8(ESP_FDATA);
> > +   --esp_count;
> > +
> > +   if (!esp_count)
> > +   break;
> > +
> > +   if (esp_wait_for_intr(esp)) {
> > +   esp->send_cmd_error = 1;
> > +   break;
> > +   }
> > +
> > +   if ((esp->sreg & ESP_STAT_PMASK) != phase)
> > +   break;
> > +
> > +   esp->ireg = esp_read8(ESP_INTRPT);
> > +   if (esp->ireg & mask) {
> > +   esp->send_cmd_error = 1;
> > +   break;
> > +   }
> > +
> > +   if (phase == ESP_MIP)
> > +   scsi_esp_cmd(esp, ESP_CMD_MOK);
> > +
> > +   scsi_esp_cmd(esp, ESP_CMD_TI);
> > +   }
> > +   } else {
> > +   unsigned int n = ESP_FIFO_SIZE;
> > +   u8 *src = (u8 *)addr;
> > +
> > +   scsi_esp_cmd(esp, ESP_CMD_FLUSH);
> > +
> > +   if (n > esp_count)
> > +   n = esp

Re: [PATCH 4/8] pci: consolidate PCI config entry in drivers/pci

2018-10-14 Thread Masahiro Yamada
On Sun, Oct 14, 2018 at 12:11 AM Christoph Hellwig  wrote:
>
> There is no good reason to duplicate the PCI menu in every architecture.
> Instead provide a selectable HAS_PCI symbol that indicates availability
> of PCI support and the handle the rest in drivers/pci.


I think HAVE_ is a preferred prefix in this case according to this doc:
https://github.com/masahir0y/linux/blob/v4.19-rc4/Documentation/kbuild/kconfig-language.txt#L448


It is true we have some options with HAS_ prefix,
but the majority is HAVE_.

masahiro@pug:~/ref/linux$ find . -name 'Kconfig*' | xargs grep 'config
HAS_' | wc
  9  18 355
masahiro@pug:~/ref/linux$ find . -name 'Kconfig*' | xargs grep 'config
HAVE_' | wc
177 3548182





> Note that for powerpc we now select HAS_PCI globally instead of the
> convoluted mess of conditional or or non-conditional support per board,
> similar to what we do e.g. on x86.  For alpha PCI is selected for the
> non-jensen configs as it was the default before, and a lot of code does
> not compile without PCI enabled.  On other architectures with limited
> PCI support that wasn't as complicated I've left the selection as-is.
>
> Signed-off-by: Christoph Hellwig 
> ---



> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index 6fa6f92edb7f..0713375e1127 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -168,10 +168,16 @@ config PPC
> select GENERIC_CPU_VULNERABILITIES  if PPC_BARRIER_NOSPEC
> select GENERIC_IRQ_SHOW
> select GENERIC_IRQ_SHOW_LEVEL
> +   select GENERIC_PCI_IOMAPif PCI
> select GENERIC_SMP_IDLE_THREAD
> select GENERIC_STRNCPY_FROM_USER
> select GENERIC_STRNLEN_USER
> select GENERIC_TIME_VSYSCALL
> +   # Platforms that what PCI turned unconditionally just do select PCI
> +   # in their config node, otherwise allow the user to enable it.
> +   # This means we can enable PCI even on platforms that don't support
> +   # it, which is harmless except for wasted memory.
> +   select HAS_PCI


If you do this for entire powerpc,
the other 'select HAS_PCI' addtions to
arch/powerpc/platforms/*/Kconfig look redundant.





> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index a344980287a5..6eb31a0698ac 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -38,6 +38,7 @@ config RISCV
> select RISCV_ISA_A if SMP
> select SPARSE_IRQ
> select SYSCTL_EXCEPTION_TRACE
> +   select HAS_PCI
> select HAVE_ARCH_TRACEHOOK
> select MODULES_USE_ELF_RELA if MODULES
> select THREAD_INFO_IN_TASK
> @@ -216,28 +217,12 @@ source "kernel/Kconfig.hz"
>
>  endmenu
>
> -menu "Bus support"
> -
> -config PCI
> -   bool "PCI support"
> -   select PCI_MSI


I think this 'select PCI_MSI' for riscv was lost.




> -   help
> - This feature enables support for PCI bus system. If you say Y
> - here, the kernel will include drivers and infrastructure code
> - to support PCI bus devices.
> -
> - If you don't know what to do here, say Y.
> -
>  config PCI_DOMAINS
> def_bool PCI
>
>  config PCI_DOMAINS_GENERIC
> def_bool PCI
>
> -source "drivers/pci/Kconfig"
> -
> -endmenu
> -
>  menu "Power management options"
>
>  source kernel/power/Kconfig



> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index 1a0be022f91d..7cbc656f47e7 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -113,6 +113,7 @@ config X86
> select GENERIC_STRNLEN_USER
> select GENERIC_TIME_VSYSCALL
> select HARDLOCKUP_CHECK_TIMESTAMP   if X86_64
> +   select HAS_PCI
> select HAVE_ACPI_APEI   if ACPI
> select HAVE_ACPI_APEI_NMI   if ACPI
> select HAVE_ALIGNED_STRUCT_PAGE if SLUB
> @@ -2567,15 +2568,6 @@ endmenu
>
>  menu "Bus options (PCI etc.)"
>
> -config PCI
> -   bool "PCI support"
> -   default y


The default is y for x86 (and xtensa as well).

With this patch, the default will be flipped.

I think most of people want to use PCI for x86,
and this change will make people upset.

Will you update arch/{x86,xtensa}/configs/*_defconfig?






> -   ---help---
> - Find out whether you have a PCI motherboard. PCI is the name of a
> - bus system, i.e. the way the CPU talks to the other stuff inside
> - your box. Other bus systems are ISA, EISA, MicroChannel (MCA) or
> - VESA. If you have PCI, say Y, otherwise N.
> -
>  choice
> prompt "PCI access mode"
> depends on X86_32 && PCI
> @@ -2658,8 +2650,6 @@ config PCI_CNB20LE_QUIRK
>
>   You should say N unless you know you need this.
>
> -source "drivers/pci/Kconfig"
> -
>  config ISA_BUS
> bool "ISA bus support on modern systems" if EXPERT
> help
> diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig
> index b9ad83a0ee5d..22abeb236863 100644
> --- a/arch/

Re: [PATCH 2/8] powerpc: simplify CONFIG_PCI_QSPAN Kconfig magic

2018-10-14 Thread Masahiro Yamada
On Sun, Oct 14, 2018 at 12:11 AM Christoph Hellwig  wrote:
>
> The way how CONFIG_PCI_QSPAN selects the CONFIG_PCI default is highly
> unusual and gets in the way of moving CONFIG_PCI into
> drivers/pci/Kconfig.  Simplify it by just having it depend on
> CONFIG_PCI.
>
> Signed-off-by: Christoph Hellwig 
> ---
>  arch/powerpc/Kconfig | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index a80669209155..6fa6f92edb7f 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -955,7 +955,6 @@ config PCI
> bool "PCI support" if PPC_PCI_CHOICE
> default y if !40x && !CPM2 && !PPC_8xx && !PPC_83xx \
> && !PPC_85xx && !PPC_86xx && !GAMECUBE_COMMON
> -   default PCI_QSPAN if PPC_8xx
> select GENERIC_PCI_IOMAP
> help
>   Find out whether your system includes a PCI bus. PCI is the name of
> @@ -971,7 +970,7 @@ config PCI_SYSCALL
>
>  config PCI_QSPAN
> bool "QSpan PCI"
> -   depends on PPC_8xx
> +   depends on PPC_8xx && PCI
> select PPC_I8259
> help
>   Say Y here if you have a system based on a Motorola 8xx-series
> --
> 2.19.1
>



'git grep' did not get any other hit.

masahiro@pug:~/ref/linux$ git grep PCI_QSPAN
arch/powerpc/Kconfig:   default PCI_QSPAN if PPC_8xx
arch/powerpc/Kconfig:config PCI_QSPAN

With your patch, PCI_QSPAN will become
a dead config option.

How about removing it entirely?



--
Best Regards
Masahiro Yamada


Re: [PATCH 7/8] eisa: consolidate EISA Kconfig entry in drivers/eisa

2018-10-14 Thread Masahiro Yamada
On Sun, Oct 14, 2018 at 12:11 AM Christoph Hellwig  wrote:
>
> Let architectures opt into EISA support by selecting HAS_EISA and
> handle everything else in drivers/eisa.
>
> Signed-off-by: Christoph Hellwig 
> ---


How about HAVE_EISA ?


You forgot to add
source "drivers/eisa/Kconfig" to drivers/Kconfig


You forgot to delete the one
from arch/alpha/Kconfig


>  arch/alpha/Kconfig |  8 +++-
>  arch/arm/Kconfig   | 16 +---
>  arch/mips/Kconfig  | 31 +--
>  arch/powerpc/Kconfig   |  3 ---
>  arch/x86/Kconfig   | 19 +--
>  drivers/eisa/Kconfig   | 21 -
>  drivers/parisc/Kconfig | 11 +--
>  7 files changed, 31 insertions(+), 78 deletions(-)
>
> diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig
> index 73a7558c71bd..6a9be9cb74e6 100644
> --- a/arch/alpha/Kconfig
> +++ b/arch/alpha/Kconfig
> @@ -6,6 +6,9 @@ config ALPHA
> select ARCH_MIGHT_HAVE_PC_SERIO
> select ARCH_NO_PREEMPT
> select ARCH_USE_CMPXCHG_LOCKREF
> +   select HAS_EISA if ALPHA_GENERIC || ALPHA_JENSEN || ALPHA_ALCOR || \
> +   ALPHA_MIKASA || ALPHA_SABLE || ALPHA_LYNX || \
> +   ALPHA_NORITAKE || ALPHA_RAWHIDE
> select HAS_PCI if !ALPHA_JENSEN
> select PCI if !ALPHA_JENSEN
> select HAVE_AOUT
> @@ -518,11 +521,6 @@ config ALPHA_SRM
>
>   If unsure, say N.
>
> -config EISA
> -   bool
> -   depends on ALPHA_GENERIC || ALPHA_JENSEN || ALPHA_ALCOR || 
> ALPHA_MIKASA || ALPHA_SABLE || ALPHA_LYNX || ALPHA_NORITAKE || ALPHA_RAWHIDE
> -   default y
> -


Better to add CONFIG_EISA=y to arch/alpha/defconfig
to not flip the default?



--
Best Regards
Masahiro Yamada


Re: move bus (PCI, PCMCIA, EISA, rapdio) config to drivers/

2018-10-14 Thread Masahiro Yamada
On Sun, Oct 14, 2018 at 12:10 AM Christoph Hellwig  wrote:
>
> Hi all,
>
> currently every architecture that wants to provide on of the common
> periphal busses needs to add some boilerplate code and include the
> right Kconfig files.   This series instead just selects the presence
> (when needed) and then handles everything in the bus-specific
> Kconfig file under drivers/.
>

Thanks for great work again.

However, I suspect some breakages
(not testing yet, just quick review by my eyes.)

I left some comments in individual patches.



--
Best Regards
Masahiro Yamada