Re: [PATCH v1] sg3_utils: sg_write_buffer: convert string to integer while reading from stdio

2018-11-09 Thread Douglas Gilbert

On 2018-11-09 7:18 p.m., Bean Huo (beanhuo) wrote:

This patch is to convert inputted string to the integer when
read data from stdin. While entering data, the data between bytes
can be separated by space, or by ',' or by '.'.


Could you send me this patch against sg_write_buffer.c as found
in the recently released version 1.44 . In there the version
string for sg_write_buffer.c is: "1.28 20180628"


Signed-off-by: Bean Huo 
---
  src/sg_write_buffer.c | 31 +++
  1 file changed, 31 insertions(+)

diff --git a/src/sg_write_buffer.c b/src/sg_write_buffer.c
index 7560e7e..902bc5d 100644
--- a/src/sg_write_buffer.c
+++ b/src/sg_write_buffer.c
@@ -195,6 +195,7 @@ main(int argc, char * argv[])
  const char * device_name = NULL;
  const char * file_name = NULL;
  unsigned char * dop = NULL;
+unsigned char * read_buf= NULL;


For example the above 2 lines now use uint8_t


  char * cp;
  const struct mode_s * mp;
  char ebuff[EBUFF_SZ];
@@ -394,6 +395,33 @@ main(int argc, char * argv[])
  }
  }
  }
+   if (infd == STDIN_FILENO) {
+   if (NULL == (read_buf = (unsigned char *)malloc(DEF_XFER_LEN))) 
{
+   pr2serr(ME "out of memory\n");
+   ret = SG_LIB_SYNTAX_ERROR;
+   goto err_out;
+   }
+   res = read(infd, read_buf, DEF_XFER_LEN);
+   if (res < 0) {
+   snprintf(ebuff, EBUFF_SZ, ME "couldn't read from 
STDIN");
+   perror(ebuff);
+   ret = SG_LIB_FILE_ERROR;
+   goto err_out;
+   }
+   char * pch;
+   int val = 0;
+   res = 0;
+   pch = strtok(read_buf, ",. ");
+   while (pch != NULL) {
+   printf("read %s ", pch);
+   val = sg_get_num_nomult(pch);
+   if (val > 0 && val < 255) {


Hmm, perhaps:
if (val >= 0 && val < 256)

else



+   dop[res] = val;
+   res++;
+   }
+   pch = strtok(NULL, ",. ");
+   }
+   } else {
  res = read(infd, dop, wb_len);
  if (res < 0) {
  snprintf(ebuff, EBUFF_SZ, ME "couldn't read from %s",
@@ -404,6 +432,7 @@ main(int argc, char * argv[])
  ret = SG_LIB_FILE_ERROR;
  goto err_out;
  }
+   }


Tabbing looks a little off here.

Thanks
Doug Gilbert


  if (res < wb_len) {
  if (wb_len_given) {
  pr2serr("tried to read %d bytes from %s, got %d bytes\n",
@@ -472,6 +501,8 @@ main(int argc, char * argv[])
  err_out:
  if (dop)
  free(dop);
+if (read_buf)
+   free(read_buf);
  res = sg_cmds_close_device(sg_fd);
  if (res < 0) {
  pr2serr("close error: %s\n", safe_strerror(-res));





[PATCH v2] mpt3sas: Display message on Configurable secure HBA

2018-11-09 Thread Sreekanth Reddy
Display below warning message only up on detection of
Configurable secure type controllers.

"HBA is in Configurable Secure mode"

v2 change set:
Replaced dev_warn() with dev_info() function while
displaying above message.

Signed-off-by: Sreekanth Reddy 
---
 drivers/scsi/mpt3sas/mpt3sas_scsih.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c 
b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 104413e..5b9806d 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -10366,6 +10366,10 @@ static void pcie_device_make_active(struct 
MPT3SAS_ADAPTER *ioc,
ioc->id = mpt3_ids++;
sprintf(ioc->driver_name, "%s", MPT3SAS_DRIVER_NAME);
switch (pdev->device) {
+   case MPI26_MFGPAGE_DEVID_CFG_SEC_3816:
+   case MPI26_MFGPAGE_DEVID_CFG_SEC_3916:
+   dev_info(>dev,
+   "HBA is in Configurable Secure mode\n");
case MPI26_MFGPAGE_DEVID_SAS3508:
case MPI26_MFGPAGE_DEVID_SAS3508_1:
case MPI26_MFGPAGE_DEVID_SAS3408:
@@ -10373,9 +10377,6 @@ static void pcie_device_make_active(struct 
MPT3SAS_ADAPTER *ioc,
case MPI26_MFGPAGE_DEVID_SAS3516_1:
case MPI26_MFGPAGE_DEVID_SAS3416:
case MPI26_MFGPAGE_DEVID_SAS3616:
-   case MPI26_MFGPAGE_DEVID_CFG_SEC_3816:
-   case MPI26_MFGPAGE_DEVID_CFG_SEC_3916:
-   ioc_warn(ioc, "HBA is in Configurable Secure mode\n");
case MPI26_MFGPAGE_DEVID_HARD_SEC_3816:
case MPI26_MFGPAGE_DEVID_HARD_SEC_3916:
ioc->is_gen35_ioc = 1;
-- 
1.8.3.1



Re: [PATCH 01/23] zfcp: make DIX experimental, disabled, and independent of DIF

2018-11-09 Thread Steffen Maier

Hi Martin,

On 11/09/2018 03:07 AM, Martin K. Petersen wrote:

There are too many unresolved issues with DIX outside of zfcp such as
wrong protection data on writesame/discard (over device-mapper)


We don't configure protected transfers for anything but read and write
commands. There is currently no protection information generated for
WRITE SAME.



So if you guys are seeing failures, it must be due to zfcp
not handling the scsi_cmnd prot_op/prot_flags or the command PROTECT bit
correctly.


I think we're good since
("scsi: zfcp: fix queuecommand for scsi_eh commands when DIX enabled")
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/s390/scsi?id=71b8e45da51a7b64a23378221c0a5868bd79da4f.

Previously, at least regular (non-recovery) I/O should have been good by 
having checked at least scsi_prot_sg_count().



or due to unstable page writes.


BDI_CAP_STABLE_WRITES should take care of this. What's the configuration
that fails?


Apologies, if the commit description sounds unfair. I did not mean to 
blame anyone. It's just the collection of issues we saw in distros over 
the years. Some of the old issues might be fixed with above zfcp patch 
or common code changes. Unfortunately, I could not handle the DIX things 
we saw. I think, DIF by itself provides a lot of the protection benefit 
and was not affected by the encountered issues. We would like to give 
users an easy way to operate in such setup.



--
Mit freundlichen Gruessen / Kind regards
Steffen Maier

Linux on IBM Z Development

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



[PATCH] aha1542: convert to DMA mapping API

2018-11-09 Thread Christoph Hellwig
aha1542 is one of the last users of the legacy isa_*_to_bus APIs, which
also isn't portable enough.  Convert it to the proper DMA mapping API.

Thanks to Ondrej Zary for testing and finding and fixing a crucial
bug.

Signed-off-by: Christoph Hellwig 
Tested-by: Ondrej Zary 
---
 drivers/scsi/aha1542.c | 126 +
 1 file changed, 91 insertions(+), 35 deletions(-)

diff --git a/drivers/scsi/aha1542.c b/drivers/scsi/aha1542.c
index 41add33e3f1f..398fcdc6f4c9 100644
--- a/drivers/scsi/aha1542.c
+++ b/drivers/scsi/aha1542.c
@@ -58,8 +58,15 @@ struct aha1542_hostdata {
int aha1542_last_mbi_used;
int aha1542_last_mbo_used;
struct scsi_cmnd *int_cmds[AHA1542_MAILBOXES];
-   struct mailbox mb[2 * AHA1542_MAILBOXES];
-   struct ccb ccb[AHA1542_MAILBOXES];
+   struct mailbox *mb;
+   dma_addr_t mb_handle;
+   struct ccb *ccb;
+   dma_addr_t ccb_handle;
+};
+
+struct aha1542_cmd {
+   struct chain *chain;
+   dma_addr_t chain_handle;
 };
 
 static inline void aha1542_intr_reset(u16 base)
@@ -233,6 +240,21 @@ static int aha1542_test_port(struct Scsi_Host *sh)
return 1;
 }
 
+static void aha1542_free_cmd(struct scsi_cmnd *cmd)
+{
+   struct aha1542_cmd *acmd = scsi_cmd_priv(cmd);
+   struct device *dev = cmd->device->host->dma_dev;
+   size_t len = scsi_sg_count(cmd) * sizeof(struct chain);
+
+   if (acmd->chain) {
+   dma_unmap_single(dev, acmd->chain_handle, len, DMA_TO_DEVICE);
+   kfree(acmd->chain);
+   }
+
+   acmd->chain = NULL;
+   scsi_dma_unmap(cmd);
+}
+
 static irqreturn_t aha1542_interrupt(int irq, void *dev_id)
 {
struct Scsi_Host *sh = dev_id;
@@ -303,7 +325,7 @@ static irqreturn_t aha1542_interrupt(int irq, void *dev_id)
return IRQ_HANDLED;
};
 
-   mbo = (scsi2int(mb[mbi].ccbptr) - (isa_virt_to_bus([0]))) / 
sizeof(struct ccb);
+   mbo = (scsi2int(mb[mbi].ccbptr) - aha1542->ccb_handle) / 
sizeof(struct ccb);
mbistatus = mb[mbi].status;
mb[mbi].status = 0;
aha1542->aha1542_last_mbi_used = mbi;
@@ -331,8 +353,7 @@ static irqreturn_t aha1542_interrupt(int irq, void *dev_id)
return IRQ_HANDLED;
}
my_done = tmp_cmd->scsi_done;
-   kfree(tmp_cmd->host_scribble);
-   tmp_cmd->host_scribble = NULL;
+   aha1542_free_cmd(tmp_cmd);
/* Fetch the sense data, and tuck it away, in the required 
slot.  The
   Adaptec automatically fetches it, and there is no guarantee 
that
   we will still have it in the cdb when we come back */
@@ -369,6 +390,7 @@ static irqreturn_t aha1542_interrupt(int irq, void *dev_id)
 
 static int aha1542_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *cmd)
 {
+   struct aha1542_cmd *acmd = scsi_cmd_priv(cmd);
struct aha1542_hostdata *aha1542 = shost_priv(sh);
u8 direction;
u8 target = cmd->device->id;
@@ -378,7 +400,6 @@ static int aha1542_queuecommand(struct Scsi_Host *sh, 
struct scsi_cmnd *cmd)
int mbo, sg_count;
struct mailbox *mb = aha1542->mb;
struct ccb *ccb = aha1542->ccb;
-   struct chain *cptr;
 
if (*cmd->cmnd == REQUEST_SENSE) {
/* Don't do the command - we have the sense data already */
@@ -398,15 +419,17 @@ static int aha1542_queuecommand(struct Scsi_Host *sh, 
struct scsi_cmnd *cmd)
print_hex_dump_bytes("command: ", DUMP_PREFIX_NONE, cmd->cmnd, 
cmd->cmd_len);
}
 #endif
-   if (bufflen) {  /* allocate memory before taking host_lock */
-   sg_count = scsi_sg_count(cmd);
-   cptr = kmalloc_array(sg_count, sizeof(*cptr),
-GFP_KERNEL | GFP_DMA);
-   if (!cptr)
-   return SCSI_MLQUEUE_HOST_BUSY;
-   } else {
-   sg_count = 0;
-   cptr = NULL;
+   sg_count = scsi_dma_map(cmd);
+   if (sg_count) {
+   size_t len = sg_count * sizeof(struct chain);
+
+   acmd->chain = kmalloc(len, GFP_DMA);
+   if (!acmd->chain)
+   goto out_unmap;
+   acmd->chain_handle = dma_map_single(sh->dma_dev, acmd->chain,
+   len, DMA_TO_DEVICE);
+   if (dma_mapping_error(sh->dma_dev, acmd->chain_handle))
+   goto out_free_chain;
}
 
/* Use the outgoing mailboxes in a round-robin fashion, because this
@@ -437,7 +460,8 @@ static int aha1542_queuecommand(struct Scsi_Host *sh, 
struct scsi_cmnd *cmd)
shost_printk(KERN_DEBUG, sh, "Sending command (%d %p)...", mbo, 
cmd->scsi_done);
 #endif
 
-   any2scsi(mb[mbo].ccbptr, isa_virt_to_bus([mbo]));   /* This gets 
trashed for some reason */
+   /* This gets trashed for 

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

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

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

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

Thanks to Ondrej Zary for testing and various bug fixes.

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

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

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

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

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

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



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

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

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

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



dma related cleanups for wd719x v2

2018-11-09 Thread Christoph Hellwig
Various dma relates cleanups

Changes since v1:
 - include important fixes from Ondrej


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

2018-11-09 Thread Christoph Hellwig
> > +   switch (gen.command.OpCode) {
> > +   case GDT_IOCTL:
> > +   gen.command.u.ioctl.p_param = paddr;
> > +   break;
> > +   case CACHESERVICE:
> > +   gdth_ioc_cacheservice(ha, , paddr);
> > +   break;
> > +   case SCSIRAWSERVICE:
> > +   gdth_ioc_scsiraw(ha, , paddr);
> > +   break;
> > +   default:
> > +   goto out_free_buf;
> >  }
> > -}
> 
> AFAICT, CACHESERVICE never gets assigned to command.OpCode.

Thanks, fixed.

> > -}
> > -gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr);
> > -return 0;
> > +   return 0;
> 
> This appears to be wrong also. I think you wanted,
>   return rval;

Also fixed.


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

2018-11-09 Thread Christoph Hellwig
> >  
> > -buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, );
> >  if (!buf) 
> >  goto stop_output;
> 
> I think this !buf test is redundant.

Thanks,

fixed.


Hello My Beloved One

2018-11-09 Thread Aisha Gaddafi
Assalamu alaikum,
I came across your e-mail contact prior a private search while in need 
of a 
trusted person. My name is Mrs. Aisha Gaddafi, a single Mother and a 
Widow 
with three Children. I am the only biological Daughter of late Libyan 
President (Late Colonel Muammar Gaddafi)I have a business Proposal for 
you 
worth $5.8Million dollars and I need mutual respect, trust, honesty, 
transparency, adequate support and assistance, Hope to hear from you 
for 
more details.
Warmest regards
Mrs Aisha Gaddafi



[PATCH v1] sg3_utils: sg_write_buffer: convert string to integer while reading from stdio

2018-11-09 Thread Bean Huo (beanhuo)
This patch is to convert inputted string to the integer when
read data from stdin. While entering data, the data between bytes
can be separated by space, or by ',' or by '.'.

Signed-off-by: Bean Huo 
---
 src/sg_write_buffer.c | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/src/sg_write_buffer.c b/src/sg_write_buffer.c
index 7560e7e..902bc5d 100644
--- a/src/sg_write_buffer.c
+++ b/src/sg_write_buffer.c
@@ -195,6 +195,7 @@ main(int argc, char * argv[])
 const char * device_name = NULL;
 const char * file_name = NULL;
 unsigned char * dop = NULL;
+unsigned char * read_buf= NULL;
 char * cp;
 const struct mode_s * mp;
 char ebuff[EBUFF_SZ];
@@ -394,6 +395,33 @@ main(int argc, char * argv[])
 }
 }
 }
+   if (infd == STDIN_FILENO) {
+   if (NULL == (read_buf = (unsigned char *)malloc(DEF_XFER_LEN))) 
{
+   pr2serr(ME "out of memory\n");
+   ret = SG_LIB_SYNTAX_ERROR;
+   goto err_out;
+   }
+   res = read(infd, read_buf, DEF_XFER_LEN);
+   if (res < 0) {
+   snprintf(ebuff, EBUFF_SZ, ME "couldn't read from 
STDIN");
+   perror(ebuff);
+   ret = SG_LIB_FILE_ERROR;
+   goto err_out;
+   }
+   char * pch;
+   int val = 0;
+   res = 0;
+   pch = strtok(read_buf, ",. ");
+   while (pch != NULL) {
+   printf("read %s ", pch);
+   val = sg_get_num_nomult(pch);
+   if (val > 0 && val < 255) {
+   dop[res] = val;
+   res++;
+   }
+   pch = strtok(NULL, ",. ");
+   }
+   } else {
 res = read(infd, dop, wb_len);
 if (res < 0) {
 snprintf(ebuff, EBUFF_SZ, ME "couldn't read from %s",
@@ -404,6 +432,7 @@ main(int argc, char * argv[])
 ret = SG_LIB_FILE_ERROR;
 goto err_out;
 }
+   }
 if (res < wb_len) {
 if (wb_len_given) {
 pr2serr("tried to read %d bytes from %s, got %d bytes\n",
@@ -472,6 +501,8 @@ main(int argc, char * argv[])
 err_out:
 if (dop)
 free(dop);
+if (read_buf)
+   free(read_buf);
 res = sg_cmds_close_device(sg_fd);
 if (res < 0) {
 pr2serr("close error: %s\n", safe_strerror(-res));
-- 
2.7.4


Re: [PATCH] aha1542: convert to DMA mapping API

2018-11-09 Thread Ondrej Zary
On Friday 09 November 2018 16:45:54 Christoph Hellwig wrote:
> aha1542 is one of the last users of the legacy isa_*_to_bus APIs, which
> also isn't portable enough.  Convert it to the proper DMA mapping API.
> 
> Thanks to Ondrej Zary for testing and finding and fixing a crucial
> bug.
> 
> Signed-off-by: Christoph Hellwig 
> Tested-by: Ondrej Zary 
> ---
>  drivers/scsi/aha1542.c | 126 +
>  1 file changed, 91 insertions(+), 35 deletions(-)
> 
> diff --git a/drivers/scsi/aha1542.c b/drivers/scsi/aha1542.c
> index 41add33e3f1f..398fcdc6f4c9 100644
> --- a/drivers/scsi/aha1542.c
> +++ b/drivers/scsi/aha1542.c
> @@ -58,8 +58,15 @@ struct aha1542_hostdata {
>   int aha1542_last_mbi_used;
>   int aha1542_last_mbo_used;
>   struct scsi_cmnd *int_cmds[AHA1542_MAILBOXES];
> - struct mailbox mb[2 * AHA1542_MAILBOXES];
> - struct ccb ccb[AHA1542_MAILBOXES];
> + struct mailbox *mb;
> + dma_addr_t mb_handle;
> + struct ccb *ccb;
> + dma_addr_t ccb_handle;
> +};
> +
> +struct aha1542_cmd {
> + struct chain *chain;
> + dma_addr_t chain_handle;
>  };
>  
>  static inline void aha1542_intr_reset(u16 base)
> @@ -233,6 +240,21 @@ static int aha1542_test_port(struct Scsi_Host *sh)
>   return 1;
>  }
>  
> +static void aha1542_free_cmd(struct scsi_cmnd *cmd)
> +{
> + struct aha1542_cmd *acmd = scsi_cmd_priv(cmd);
> + struct device *dev = cmd->device->host->dma_dev;
> + size_t len = scsi_sg_count(cmd) * sizeof(struct chain);
> +
> + if (acmd->chain) {
> + dma_unmap_single(dev, acmd->chain_handle, len, DMA_TO_DEVICE);
> + kfree(acmd->chain);
> + }
> +
> + acmd->chain = NULL;
> + scsi_dma_unmap(cmd);
> +}
> +
>  static irqreturn_t aha1542_interrupt(int irq, void *dev_id)
>  {
>   struct Scsi_Host *sh = dev_id;
> @@ -303,7 +325,7 @@ static irqreturn_t aha1542_interrupt(int irq, void 
> *dev_id)
>   return IRQ_HANDLED;
>   };
>  
> - mbo = (scsi2int(mb[mbi].ccbptr) - (isa_virt_to_bus([0]))) / 
> sizeof(struct ccb);
> + mbo = (scsi2int(mb[mbi].ccbptr) - aha1542->ccb_handle) / 
> sizeof(struct ccb);
>   mbistatus = mb[mbi].status;
>   mb[mbi].status = 0;
>   aha1542->aha1542_last_mbi_used = mbi;
> @@ -331,8 +353,7 @@ static irqreturn_t aha1542_interrupt(int irq, void 
> *dev_id)
>   return IRQ_HANDLED;
>   }
>   my_done = tmp_cmd->scsi_done;
> - kfree(tmp_cmd->host_scribble);
> - tmp_cmd->host_scribble = NULL;
> + aha1542_free_cmd(tmp_cmd);
>   /* Fetch the sense data, and tuck it away, in the required 
> slot.  The
>  Adaptec automatically fetches it, and there is no guarantee 
> that
>  we will still have it in the cdb when we come back */
> @@ -369,6 +390,7 @@ static irqreturn_t aha1542_interrupt(int irq, void 
> *dev_id)
>  
>  static int aha1542_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *cmd)
>  {
> + struct aha1542_cmd *acmd = scsi_cmd_priv(cmd);
>   struct aha1542_hostdata *aha1542 = shost_priv(sh);
>   u8 direction;
>   u8 target = cmd->device->id;
> @@ -378,7 +400,6 @@ static int aha1542_queuecommand(struct Scsi_Host *sh, 
> struct scsi_cmnd *cmd)
>   int mbo, sg_count;
>   struct mailbox *mb = aha1542->mb;
>   struct ccb *ccb = aha1542->ccb;
> - struct chain *cptr;
>  
>   if (*cmd->cmnd == REQUEST_SENSE) {
>   /* Don't do the command - we have the sense data already */
> @@ -398,15 +419,17 @@ static int aha1542_queuecommand(struct Scsi_Host *sh, 
> struct scsi_cmnd *cmd)
>   print_hex_dump_bytes("command: ", DUMP_PREFIX_NONE, cmd->cmnd, 
> cmd->cmd_len);
>   }
>  #endif
> - if (bufflen) {  /* allocate memory before taking host_lock */
> - sg_count = scsi_sg_count(cmd);
> - cptr = kmalloc_array(sg_count, sizeof(*cptr),
> -  GFP_KERNEL | GFP_DMA);
> - if (!cptr)
> - return SCSI_MLQUEUE_HOST_BUSY;
> - } else {
> - sg_count = 0;
> - cptr = NULL;
> + sg_count = scsi_dma_map(cmd);
> + if (sg_count) {
> + size_t len = sg_count * sizeof(struct chain);
> +
> + acmd->chain = kmalloc(len, GFP_DMA);
> + if (!acmd->chain)
> + goto out_unmap;
> + acmd->chain_handle = dma_map_single(sh->dma_dev, acmd->chain,
> + len, DMA_TO_DEVICE);
> + if (dma_mapping_error(sh->dma_dev, acmd->chain_handle))
> + goto out_free_chain;
>   }
>  
>   /* Use the outgoing mailboxes in a round-robin fashion, because this
> @@ -437,7 +460,8 @@ static int aha1542_queuecommand(struct Scsi_Host *sh, 
> struct scsi_cmnd *cmd)
>   shost_printk(KERN_DEBUG, sh, "Sending command 

[PATCH v2] megaraid_sas: Add support for MegaRAID Aero controllers

2018-11-09 Thread Shivasharan S
This patch adds support for MegaRAID Aero controller PCI IDs.
Throw a message when a Configurable secure type controller is
encountered.

Signed-off-by: Shivasharan S 
---
Changes in v2:
Change dev_warn to dev_info.

 drivers/scsi/megaraid/megaraid_sas.h  |  4 
 drivers/scsi/megaraid/megaraid_sas_base.c | 15 +++
 2 files changed, 19 insertions(+)

diff --git a/drivers/scsi/megaraid/megaraid_sas.h 
b/drivers/scsi/megaraid/megaraid_sas.h
index 8edba2227cd3..55f6662ceb55 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -60,6 +60,10 @@
 #define PCI_DEVICE_ID_LSI_TOMCAT   0x0017
 #define PCI_DEVICE_ID_LSI_VENTURA_4PORT0x001B
 #define PCI_DEVICE_ID_LSI_CRUSADER_4PORT   0x001C
+#define PCI_DEVICE_ID_LSI_AERO_10E10x10e1
+#define PCI_DEVICE_ID_LSI_AERO_10E20x10e2
+#define PCI_DEVICE_ID_LSI_AERO_10E50x10e5
+#define PCI_DEVICE_ID_LSI_AERO_10E60x10e6
 
 /*
  * Intel HBA SSDIDs
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index 27fab13c55ea..bc8e4d91d34b 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -162,6 +162,10 @@ static struct pci_device_id megasas_pci_table[] = {
{PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_TOMCAT)},
{PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VENTURA_4PORT)},
{PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CRUSADER_4PORT)},
+   {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E1)},
+   {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E2)},
+   {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E5)},
+   {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E6)},
{}
 };
 
@@ -6235,6 +6239,10 @@ static inline void megasas_set_adapter_type(struct 
megasas_instance *instance)
instance->adapter_type = MFI_SERIES;
} else {
switch (instance->pdev->device) {
+   case PCI_DEVICE_ID_LSI_AERO_10E1:
+   case PCI_DEVICE_ID_LSI_AERO_10E2:
+   case PCI_DEVICE_ID_LSI_AERO_10E5:
+   case PCI_DEVICE_ID_LSI_AERO_10E6:
case PCI_DEVICE_ID_LSI_VENTURA:
case PCI_DEVICE_ID_LSI_CRUSADER:
case PCI_DEVICE_ID_LSI_HARPOON:
@@ -6598,6 +6606,13 @@ static int megasas_probe_one(struct pci_dev *pdev,
struct megasas_instance *instance;
u16 control = 0;
 
+   switch (pdev->device) {
+   case PCI_DEVICE_ID_LSI_AERO_10E1:
+   case PCI_DEVICE_ID_LSI_AERO_10E5:
+   dev_info(>dev, "Adapter is in configurable secure 
mode\n");
+   break;
+   }
+
/* Reset MSI-X in the kdump kernel */
if (reset_devices) {
pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
-- 
2.16.1



Re: [PATCH] megaraid_sas: Add support for MegaRAID Aero controllers

2018-11-09 Thread Shivasharan Srikanteshwara
On Fri, Nov 9, 2018 at 7:43 AM Martin K. Petersen
 wrote:
> Shivasharan,
>
> > This patch adds support for MegaRAID Aero controller PCI IDs.
> > Throw a warning message when a Configurable secure type controller is
> > encountered.
>
> > + dev_warn(>dev, "Adapter is in configurable secure 
> > mode\n");
>
> Why warn and not info?

Hi Martin,
Agree that a dev_info would be the better choice here instead of warn.
Will send out v2 of this patch with the change.

Thanks,
Shivasharan
>
> --
> Martin K. Petersen  Oracle Linux Engineering