[PATCH 3.16.y-ckt 116/170] scsi: Fix error handling in SCSI_IOCTL_SEND_COMMAND

2014-11-11 Thread Luis Henriques
3.16.7-ckt1 -stable review patch.  If anyone has any objections, please let me 
know.

--

From: Jan Kara j...@suse.cz

commit 84ce0f0e94ac97217398b3b69c21c7a62ebeed05 upstream.

When sg_scsi_ioctl() fails to prepare request to submit in
blk_rq_map_kern() we jump to a label where we just end up copying
(luckily zeroed-out) kernel buffer to userspace instead of reporting
error. Fix the problem by jumping to the right label.

CC: Jens Axboe ax...@kernel.dk
CC: linux-scsi@vger.kernel.org
Coverity-id: 1226871
Signed-off-by: Jan Kara j...@suse.cz

Fixed up the, now unused, out label.

Signed-off-by: Jens Axboe ax...@fb.com
Signed-off-by: Luis Henriques luis.henriq...@canonical.com
---
 block/scsi_ioctl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index 84ab119b6ffa..de3bd8287d81 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -490,7 +490,7 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk 
*disk, fmode_t mode,
 
if (bytes  blk_rq_map_kern(q, rq, buffer, bytes, __GFP_WAIT)) {
err = DRIVER_ERROR  24;
-   goto out;
+   goto error;
}
 
memset(sense, 0, sizeof(sense));
@@ -499,7 +499,6 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk 
*disk, fmode_t mode,
 
blk_execute_rq(q, disk, rq, 0);
 
-out:
err = rq-errors  0xff;/* only 8 bit SCSI status */
if (err) {
if (rq-sense_len  rq-sense) {
-- 
2.1.0

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


Re: [PATCH 1/1] be2iscsi: add block valid bit to iBFT flag

2014-11-11 Thread Vikas Chaudhary


On 10/11/14 11:37 pm, Minh Duc Tran minhduc.t...@emulex.com wrote:

Adding Vikas to verify if qla4xxx has the same issue.

On 11/10/2014 12:52 AM, Minh Duc Tran wrote:
 From: Minh Tran minhduc.t...@emulex.com
 mailto:minhduc.t...@emulex.com
 
We are starting to see problems with certain open-iscsi
 versions out there checking block valid bit.  Iscsi boot target login
 will not happen without this bit being set.
 

What versions of open-iscsi? Is it just the SUSE based versions?

Looking at latest changes in SUSE open-iscsi code, we require this patch
in qla4xxx also.


Yes, it's just the new SUSE open-iscsi for now.

I think we want to move SYSFS_FLAG_FW_SEL_BOOT from ql4_def.h to
include/linux/iscsi_boot_sysfs.h (also add a ISCSI_BOOT_ prefix), and
then have both drivers use it.

I agree.

Thanks,
Vikas.

attachment: winmail.dat

Re: [PATCH v2 06/36] ncr5380: Remove more useless prototypes

2014-11-11 Thread Hannes Reinecke
On 11/09/2014 01:19 PM, Finn Thain wrote:
 
 Ping...
 
Ok, disregard the .proc_name issue for now.

Reviewed-by: Hannes Reinecke h...@suse.de

Cheers,

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


Re: [PATCH 3/7] megaraid_sas : Do not process IOCTLs and SCSI commands during driver removal

2014-11-11 Thread Tomas Henzl
On 11/10/2014 01:21 PM, sumit.sax...@avagotech.com wrote:
 Do not process any SCSI and IOCTL command further(return them with 
 appropriate return values to callers),
 while driver removal is in progress/PCI shutdown is invoked. 

 Signed-off-by: Sumit Saxena sumit.sax...@avagotech.com
 Signed-off-by: Kashyap Desai kashyap.de...@avagotech.com
 ---
  drivers/scsi/megaraid/megaraid_sas_base.c |   20 
  1 files changed, 16 insertions(+), 4 deletions(-)

 diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
 b/drivers/scsi/megaraid/megaraid_sas_base.c
 index f6a69a3..7754eeb 100644
 --- a/drivers/scsi/megaraid/megaraid_sas_base.c
 +++ b/drivers/scsi/megaraid/megaraid_sas_base.c
 @@ -1572,6 +1572,12 @@ megasas_queue_command(struct Scsi_Host *shost, struct 
 scsi_cmnd *scmd)
   instance = (struct megasas_instance *)
   scmd-device-host-hostdata;
  
 + if (instance-unload == 1) {
 + scmd-result = DID_NO_CONNECT  16;
 + scmd-scsi_done(scmd);
 + return 0;
 + }
 +
   if (instance-issuepend_done == 0)
   return SCSI_MLQUEUE_HOST_BUSY;
  
 @@ -4957,10 +4963,6 @@ static int megasas_io_attach(struct megasas_instance 
 *instance)
   return -ENODEV;
   }
  
 - /*
 -  * Trigger SCSI to scan our drives
 -  */
 - scsi_scan_host(host);
   return 0;
  }
  
 @@ -5288,6 +5290,10 @@ retry_irq_register:
   goto fail_io_attach;
  
   instance-unload = 0;
 + /*
 +  * Trigger SCSI to scan our drives
 +  */
 + scsi_scan_host(host);
  
   /*
* Initiate AEN (Asynchronous Event Notification)
 @@ -6051,6 +6057,12 @@ megasas_mgmt_fw_ioctl(struct megasas_instance 
 *instance,
   megasas_issue_blocked_cmd(instance, cmd, 0);
   cmd-sync_cmd = 0;

I've expected that you'll not send the command to the card,
you first issue blocked command and after that test unload state.
Shouldn't it be reversed?

  
 + if (instance-unload == 1) {
 + dev_info(instance-pdev-dev, we are doing unload so no need
 + to submit data to application. This may be force exit
 + from driver\n);

I'm not a native speaker, so I'll not comment on the wording, but you should add
a space at the line breaks.
+   dev_info(instance-pdev-dev, we are doing unload so no need 
+   to submit data to application. This may be force exit 
+   from driver\n);

 + goto out;
 + }
   /*
* copy out the kernel buffers to user buffers
*/

Aren't there other ioctl paths too - for example 
megasas_mgmt_ioctl_aen - isn't a block needed there too?


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


Re: [PATCH 1/7] megaraid_sas : Driver version upgrade

2014-11-11 Thread Tomas Henzl
On 11/10/2014 01:21 PM, sumit.sax...@avagotech.com wrote:
 megaraid_sas driver version upgrade

 Signed-off-by: Sumit Saxena sumit.sax...@avagotech.com
 ---
  drivers/scsi/megaraid/megaraid_sas.h  | 2 +-
  drivers/scsi/megaraid/megaraid_sas_base.c | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)

 diff --git a/drivers/scsi/megaraid/megaraid_sas.h 
 b/drivers/scsi/megaraid/megaraid_sas.h
 index a49914d..f3eccf1 100644
 --- a/drivers/scsi/megaraid/megaraid_sas.h
 +++ b/drivers/scsi/megaraid/megaraid_sas.h
 @@ -33,7 +33,7 @@
  /*
   * MegaRAID SAS Driver meta data
   */
 -#define MEGASAS_VERSION  06.805.06.00-rc1
 +#define MEGASAS_VERSION  06.805.06.01-rc1
  #define MEGASAS_RELDATE  Sep. 4, 2014
  #define MEGASAS_EXT_VERSION  Thu. Sep. 4 17:00:00 PDT 2014

Usually you have changed the dates too, but this not important, feel free to 
ignore  it.

  
 diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
 b/drivers/scsi/megaraid/megaraid_sas_base.c
 index f6a69a3..36f463c 100644
 --- a/drivers/scsi/megaraid/megaraid_sas_base.c
 +++ b/drivers/scsi/megaraid/megaraid_sas_base.c
 @@ -18,7 +18,7 @@
   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
   *
   *  FILE: megaraid_sas_base.c
 - *  Version : 06.805.06.00-rc1
 + *  Version : 06.805.06.01-rc1
   *
   *  Authors: LSI Corporation
   *   Sreenivas Bagalkote

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


Re: [PATCH 4/7] megaraid_sas : Online Firmware upgrade suppport for Extended VD feature

2014-11-11 Thread Tomas Henzl
On 11/10/2014 01:21 PM, sumit.sax...@avagotech.com wrote:
 This patch provides driver compatibility for updating firmware online to 
 upgrade legacy(64 VD) firmware to Extended VD firmware
 and viceversa. Currently, at driver load time only, driver will check whether 
 Firmware is legacy or 240 VD. If legacy Firmware is
 upgraded to Extended VD firmware without unloading-loading driver, driver 
 will never come to know the underlying firmware is changed and
 it will always acts as firmware type is same, which was queried at driver 
 load time.
 Below is the descriptions of code changes done-

 1)This patch has added functionality to get controller information from 
 OCR(Online Controller Rest) path(which is called after
 firmware upgrade) and update the paramter of firmwware type flashed on 
 controller-Extended VD firmware or Legacy VD firmware.
 Driver will not change any other parameter except for this one.

 2)Also added few code optimizations/fixes[memset after get_free_pages, and 
 reduced redundant parameters in megasas_ctrl_info()
 function.

 Signed-off-by: Sumit Saxena sumit.sax...@avagotech.com
 Signed-off-by: Kashyap Desai kashyap.de...@avagotech.com
 ---
  drivers/scsi/megaraid/megaraid_sas.h|3 +-
  drivers/scsi/megaraid/megaraid_sas_base.c   |   80 
 +++
  drivers/scsi/megaraid/megaraid_sas_fusion.c |   55 +--
  3 files changed, 83 insertions(+), 55 deletions(-)

 diff --git a/drivers/scsi/megaraid/megaraid_sas.h 
 b/drivers/scsi/megaraid/megaraid_sas.h
 index a49914d..0408dda 100644
 --- a/drivers/scsi/megaraid/megaraid_sas.h
 +++ b/drivers/scsi/megaraid/megaraid_sas.h
 @@ -1931,8 +1931,7 @@ u16 get_updated_dev_handle(struct megasas_instance 
 *instance,
   struct LD_LOAD_BALANCE_INFO *lbInfo, struct IO_REQUEST_INFO *in_info);
  void mr_update_load_balance_params(struct MR_DRV_RAID_MAP_ALL *map,
   struct LD_LOAD_BALANCE_INFO *lbInfo);
 -int megasas_get_ctrl_info(struct megasas_instance *instance,
 - struct megasas_ctrl_info *ctrl_info);
 +int megasas_get_ctrl_info(struct megasas_instance *instance);
  int megasas_set_crash_dump_params(struct megasas_instance *instance,
   u8 crash_buf_state);
  void megasas_free_host_crash_buffer(struct megasas_instance *instance);
 diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
 b/drivers/scsi/megaraid/megaraid_sas_base.c
 index 7754eeb..9d5db5f 100644
 --- a/drivers/scsi/megaraid/megaraid_sas_base.c
 +++ b/drivers/scsi/megaraid/megaraid_sas_base.c
 @@ -4034,25 +4034,81 @@ megasas_ld_list_query(struct megasas_instance 
 *instance, u8 query_type)
   return ret;
  }
  
 +/*
 + * megasas_update_ext_vd_details : Update details w.r.t Extended VD
 + * instance   : Controller's instance
 +*/
 +static void megasas_update_ext_vd_details(struct megasas_instance *instance)
 +{
 + struct fusion_context *fusion;
 +
 + fusion = instance-ctrl_context;
 + /* For MFI based controllers return dummy success */
 + if (!fusion)
 + return;
 +
 + instance-supportmax256vd =
 + instance-ctrl_info-adapterOperations3.supportMaxExtLDs;
 + /* Below is additional check to address future FW enhancement */
 + if (instance-ctrl_info-max_lds  64)
 + instance-supportmax256vd = 1;
 +
 + instance-drv_supported_vd_count = MEGASAS_MAX_LD_CHANNELS
 + * MEGASAS_MAX_DEV_PER_CHANNEL;
 + instance-drv_supported_pd_count = MEGASAS_MAX_PD_CHANNELS
 + * MEGASAS_MAX_DEV_PER_CHANNEL;
 + if (instance-supportmax256vd) {
 + instance-fw_supported_vd_count = MAX_LOGICAL_DRIVES_EXT;
 + instance-fw_supported_pd_count = MAX_PHYSICAL_DEVICES;
 + } else {
 + instance-fw_supported_vd_count = MAX_LOGICAL_DRIVES;
 + instance-fw_supported_pd_count = MAX_PHYSICAL_DEVICES;
 + }
 + dev_info(instance-pdev-dev, Firmware supports %d VD %d PD\n,
 + instance-fw_supported_vd_count,
 + instance-fw_supported_pd_count);
 + dev_info(instance-pdev-dev, Driver supports %d VD  %d PD\n,
 + instance-drv_supported_vd_count,
 + instance-drv_supported_pd_count);
 +
 + fusion-old_map_sz =  sizeof(struct MR_FW_RAID_MAP) +
 + (sizeof(struct MR_LD_SPAN_MAP) *
 + (instance-fw_supported_vd_count - 1));
 + fusion-new_map_sz =  sizeof(struct MR_FW_RAID_MAP_EXT);
 + fusion-drv_map_sz =  sizeof(struct MR_DRV_RAID_MAP) +
 + (sizeof(struct MR_LD_SPAN_MAP) *
 + (instance-drv_supported_vd_count - 1));
 +
 + fusion-max_map_sz = max(fusion-old_map_sz, fusion-new_map_sz);

old_map_sz + new_map_sz are used only locally, no need to have it stored in 
fusion_context
what is the reason for max_map_sz ? It is used in some places outside this 
function,
but why do you not use 

Re: [PATCH 03/11] scsi: remove ordered_tags scsi_device field

2014-11-11 Thread Hannes Reinecke
On 11/10/2014 04:56 PM, Christoph Hellwig wrote:
 Remove the ordered_tags field, we haven't been issuing ordered tags based
 on it since the big barrier rework in 2010.
 
 Signed-off-by: Christoph Hellwig h...@lst.de
 Reviewed-by: Bart Van Assche bvanass...@acm.org
 Reviewed-by: Martin K. Petersen martin.peter...@oracle.com
Reviewed-by: Hannes Reinecke h...@suse.de

Cheers,

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


Re: [PATCH 05/11] scsi: remove abuses of scsi_populate_tag

2014-11-11 Thread Hannes Reinecke
On 11/10/2014 04:56 PM, Christoph Hellwig wrote:
 Unless we want to build a SPI tag message we should just check SCMD_TAGGED
 instead of reverse engineering a tag type through the use of
 scsi_populate_tag_msg.
 
 Also rename the function to spi_populate_tag_msg, make it behave like the
 other spi message helpers, and move it to the spi transport class.
 
 Signed-off-by: Christoph Hellwig h...@lst.de
Reviewed-by: Hannes Reinecke h...@suse.de

Cheers,

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


Re: [PATCH 09/11] scsi: don't set tagging state from scsi_adjust_queue_depth

2014-11-11 Thread Hannes Reinecke
On 11/10/2014 04:56 PM, Christoph Hellwig wrote:
 Remove the tagged argument from scsi_adjust_queue_depth, and just let it
 handle the queue depth.  For most drivers those two are fairly separate,
 given that most modern drivers don't care about the SCSI tagged status
 of a command at all, and many old drivers allow queuing of multiple
 untagged commands in the driver.
 
 Instead we start out with the -simple_tags flag set before calling
 -slave_configure, which is how all drivers actually looking at
 -simple_tags except for one worke anyway.  The one other case looks
 broken, but I've kept the behavior as-is for now.
 
 Except for that we only change -simple_tags from the -change_queue_type,
 and when rejecting a tag message in a single driver, so keeping this
 churn out of scsi_adjust_queue_depth is a clear win.
 
 Now that the usage of scsi_adjust_queue_depth is more obvious we can
 also remove all the trivial instances in -slave_alloc or -slave_configure
 that just set it to the cmd_per_lun default.
 
 Signed-off-by: Christoph Hellwig h...@lst.de
 Reviewed-by: Martin K. Petersen martin.peter...@oracle.com
Reviewed-by: Hannes Reinecke h...@suse.de

Cheers,

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


Re: [PATCH 10/11] scsi: don't force tagged_supported in drivers

2014-11-11 Thread Hannes Reinecke
On 11/10/2014 04:56 PM, Christoph Hellwig wrote:
 Now that we also get proper values in cmd-request-tag for untagged
 commands, there is no need to force tagged_supported to on in drivers
 that need host-wide tags.
 
 Signed-off-by: Christoph Hellwig h...@lst.de
Reviewed-by: Hannes Reinecke h...@suse.de

Cheers,

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


Re: [PATCH 11/11] ufs: remove spurious scsi_set_tag_type call

2014-11-11 Thread Hannes Reinecke
On 11/10/2014 04:56 PM, Christoph Hellwig wrote:
 ufs never looks at the tag type, so there is no need to set it either.
 
 Signed-off-by: Christoph Hellwig h...@lst.de
 ---
  drivers/scsi/ufs/ufshcd.c | 1 -
  1 file changed, 1 deletion(-)
 
 diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
 index 67e2280..362b818 100644
 --- a/drivers/scsi/ufs/ufshcd.c
 +++ b/drivers/scsi/ufs/ufshcd.c
 @@ -2768,7 +2768,6 @@ static int ufshcd_slave_alloc(struct scsi_device *sdev)
  
   /* Mode sense(6) is not supported by UFS, so use Mode sense(10) */
   sdev-use_10_for_ms = 1;
 - scsi_set_tag_type(sdev, MSG_SIMPLE_TAG);
  
   /* allow SCSI layer to restart the device in case of errors */
   sdev-allow_restart = 1;
 
Reviewed-by: Hannes Reinecke h...@suse.de

Cheers,

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


Re: [PATCH 2/6] scsi: remove scsi_next_command

2014-11-11 Thread Christoph Hellwig
On Thu, Nov 06, 2014 at 04:34:13PM +0100, Christoph Hellwig wrote:
 On Thu, Nov 06, 2014 at 09:21:05AM +0100, Hannes Reinecke wrote:
  Hmm? Isn't there a scsi_put_comand() too many?
  You dropped it from the 'if' branch, moved it out of
  the condition, but kept in in the 'else' branch ...
 
 The put_device for the 'else' branch was hidden inside scsi_next_command.

Is this a good enough explanation to get a Reviewed-by?

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


Re: [PATCH 2/2] virtio_scsi: support multi hw queue of blk-mq

2014-11-11 Thread Paolo Bonzini


On 10/11/2014 17:05, Christoph Hellwig wrote:
 
  a) there is no multiath support for it, and we simply can't break existing
 setups that use.
  b) there is no support for I/O schedulers at all.  This might be okay
 for virtio-scsi, where in general you have a host scheduler, but for
 real hardware that still has to deal with more spinning rust than
 solid state it's a blocker.  Fortuntely Jens is working on that one.

It is sort-of okay for virtio-scsi (and virtio-blk).  Deadline provides
a good speedup over noop for virtual disks, even in the presence of a
host scheduler---though nobody ever benchmarked why.

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


RE: [PATCH 01/10] scsi: Use real functions for logging

2014-11-11 Thread Elliott, Robert (Server Storage)


 -Original Message-
 From: Hannes Reinecke [mailto:h...@suse.de]
 Sent: Tuesday, 04 November, 2014 2:07 AM
...
 diff --git a/drivers/scsi/scsi_logging.c
 b/drivers/scsi/scsi_logging.c
...
 @@ -0,0 +1,119 @@
 +/*
 + * scsi_logging.c
 + *
 + * Copyright (C) 2014 SUSE Linux Products GmbH
 + * Copyright (C) 2014 Hannes Reinecke h...@suse.de
 + *
 + * This file is released under the GPLv2
 + */
 +
 +#include linux/kernel.h
 +#include linux/atomic.h
 +
 +#include scsi/scsi.h
 +#include scsi/scsi_cmnd.h
 +#include scsi/scsi_device.h
 +#include scsi/scsi_dbg.h
 +
 +#define SCSI_LOG_SPOOLSIZE 4096
 +#define SCSI_LOG_BUFSIZE 128
 +
 +struct scsi_log_buf {
 + char buffer[SCSI_LOG_SPOOLSIZE];
 + unsigned long map;
 +};
 +
 +static DEFINE_PER_CPU(struct scsi_log_buf, scsi_format_log);
 +
 +static char *scsi_log_reserve_buffer(size_t *len)
 +{
 + struct scsi_log_buf *buf;
 + unsigned long map_bits = SCSI_LOG_SPOOLSIZE / SCSI_LOG_BUFSIZE;
 + unsigned long idx = 0;
 +
 + WARN_ON(map_bits  BITS_PER_LONG);

Since SCSI_LOG_SPOOLSIZE, SCSI_LOG_BUFSIZE, and BITS_PER_LONG
are constants, that can be a compile-time check.

 + preempt_disable();
 + buf = this_cpu_ptr(scsi_format_log);
 + idx = find_first_zero_bit(buf-map, map_bits);

If this fails to find a bit, it returns map_bits.
This could result in the next test_and_set_bit call 
accessing an address that is outside the bounds of
buf-map.

A safety check seems prudent before the test_and_set_bit:
if (likely(idx  map_bits))

 + while (test_and_set_bit(idx, buf-map)) {
 + idx = find_next_zero_bit(buf-map, map_bits, idx);
 + if (idx = map_bits) {
 + break;
 + }

scripts/checkpatch.pl -f doesn't like the {} on that.

 + }
 + if (WARN_ON(idx = map_bits)) {
 + preempt_enable();
 + return NULL;
 + }
 + *len = SCSI_LOG_BUFSIZE;
 + return buf-buffer + idx * SCSI_LOG_BUFSIZE;
 +}
 +
 +static void scsi_log_release_buffer(char *bufptr)
 +{
 + struct scsi_log_buf *buf;
 + unsigned long idx;
 + int ret;
 +
 + buf = this_cpu_ptr(scsi_format_log);
 + if (bufptr  buf-buffer + SCSI_LOG_SPOOLSIZE) {

Should that also check that bufptr  buf-buffer?

 + idx = (bufptr - buf-buffer) / SCSI_LOG_BUFSIZE;
 + ret = test_and_clear_bit(idx, buf-map);
 + WARN_ON(!ret);
 + }
 + preempt_enable();
 +}
 +
 +int sdev_prefix_printk(const char *level, const struct scsi_device
 *sdev,
 +const char *name, const char *fmt, ...)
 +{
 + va_list args;
 + char *logbuf;
 + size_t off = 0, logbuf_len;
 + int ret;
 +
 + if (!sdev)
 + return 0;
 +
 + logbuf = scsi_log_reserve_buffer(logbuf_len);
 + if (!logbuf)
 + return 0;
 +
 + if (name)
 + off += scnprintf(logbuf + off, logbuf_len - off,
 +  [%s] , name);
 + va_start(args, fmt);
 + off += vscnprintf(logbuf + off, logbuf_len - off, fmt, args);
 + va_end(args);
 + ret = dev_printk(level, sdev-sdev_gendev, %s, logbuf);
 + scsi_log_release_buffer(logbuf);
 + return ret;
 +}
 +EXPORT_SYMBOL_GPL(sdev_prefix_printk);
 +
 +int scmd_printk(const char *level, const struct scsi_cmnd *scmd,
 + const char *fmt, ...)
 +{
 + struct gendisk *disk = scmd-request-rq_disk;
 + va_list args;
 + char *logbuf;
 + size_t off = 0, logbuf_len;
 + int ret;
 +
 + if (!scmd || scmd-cmnd == NULL)
 + return 0;

!scmd-cmnd seems more common in neighboring code.

 +
 + logbuf = scsi_log_reserve_buffer(logbuf_len);
 + if (!logbuf)
 + return 0;
 + if (disk)
 + off += scnprintf(logbuf + off, logbuf_len - off,
 +  [%s] , disk-disk_name);
 + va_start(args, fmt);
 + off += vscnprintf(logbuf + off, logbuf_len - off, fmt, args);
 + va_end(args);
 + ret = dev_printk(level, scmd-device-sdev_gendev, %s,
 logbuf);
 + scsi_log_release_buffer(logbuf);
 + return ret;
 +}
 +EXPORT_SYMBOL_GPL(scmd_printk);
...

dev_printk is EXPORT_SYMBOL.  The former macro versions of 
sdev_printk and scmd_printk just called dev_printk, and not
being symbols, did not change that.

So, I think these function versions should use EXPORT_SYMBOL, so 
the hated binary drivers can still call them.


---
Rob ElliottHP Server Storage



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


Re: [PATCH 2/6] scsi: remove scsi_next_command

2014-11-11 Thread Hannes Reinecke
On 11/11/2014 05:37 PM, Christoph Hellwig wrote:
 On Thu, Nov 06, 2014 at 04:34:13PM +0100, Christoph Hellwig wrote:
 On Thu, Nov 06, 2014 at 09:21:05AM +0100, Hannes Reinecke wrote:
 Hmm? Isn't there a scsi_put_comand() too many?
 You dropped it from the 'if' branch, moved it out of
 the condition, but kept in in the 'else' branch ...

 The put_device for the 'else' branch was hidden inside scsi_next_command.
 
 Is this a good enough explanation to get a Reviewed-by?
 
Yep.

Reviewed-by: Hannes Reinecke h...@suse.de

Cheers,

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


Re: [PATCH 01/10] scsi: Use real functions for logging

2014-11-11 Thread Hannes Reinecke
On 11/11/2014 06:38 PM, Elliott, Robert (Server Storage) wrote:
 
 
 -Original Message-
 From: Hannes Reinecke [mailto:h...@suse.de]
 Sent: Tuesday, 04 November, 2014 2:07 AM
 ...
 diff --git a/drivers/scsi/scsi_logging.c
 b/drivers/scsi/scsi_logging.c
 ...
 @@ -0,0 +1,119 @@
 +/*
 + * scsi_logging.c
 + *
 + * Copyright (C) 2014 SUSE Linux Products GmbH
 + * Copyright (C) 2014 Hannes Reinecke h...@suse.de
 + *
 + * This file is released under the GPLv2
 + */
 +
 +#include linux/kernel.h
 +#include linux/atomic.h
 +
 +#include scsi/scsi.h
 +#include scsi/scsi_cmnd.h
 +#include scsi/scsi_device.h
 +#include scsi/scsi_dbg.h
 +
 +#define SCSI_LOG_SPOOLSIZE 4096
 +#define SCSI_LOG_BUFSIZE 128
 +
 +struct scsi_log_buf {
 +char buffer[SCSI_LOG_SPOOLSIZE];
 +unsigned long map;
 +};
 +
 +static DEFINE_PER_CPU(struct scsi_log_buf, scsi_format_log);
 +
 +static char *scsi_log_reserve_buffer(size_t *len)
 +{
 +struct scsi_log_buf *buf;
 +unsigned long map_bits = SCSI_LOG_SPOOLSIZE / SCSI_LOG_BUFSIZE;
 +unsigned long idx = 0;
 +
 +WARN_ON(map_bits  BITS_PER_LONG);
 
 Since SCSI_LOG_SPOOLSIZE, SCSI_LOG_BUFSIZE, and BITS_PER_LONG
 are constants, that can be a compile-time check.
 
Ok.

 +preempt_disable();
 +buf = this_cpu_ptr(scsi_format_log);
 +idx = find_first_zero_bit(buf-map, map_bits);
 
 If this fails to find a bit, it returns map_bits.
 This could result in the next test_and_set_bit call 
 accessing an address that is outside the bounds of
 buf-map.
 
 A safety check seems prudent before the test_and_set_bit:
   if (likely(idx  map_bits))
 
Ah. I wasn't quite sure what find_first_zero_bit would return
on failure. But yeah, that check seems to be appropriate.

 +while (test_and_set_bit(idx, buf-map)) {
 +idx = find_next_zero_bit(buf-map, map_bits, idx);
 +if (idx = map_bits) {
 +break;
 +}
 
 scripts/checkpatch.pl -f doesn't like the {} on that.
 
Sigh.

 +}
 +if (WARN_ON(idx = map_bits)) {
 +preempt_enable();
 +return NULL;
 +}
 +*len = SCSI_LOG_BUFSIZE;
 +return buf-buffer + idx * SCSI_LOG_BUFSIZE;
 +}
 +
 +static void scsi_log_release_buffer(char *bufptr)
 +{
 +struct scsi_log_buf *buf;
 +unsigned long idx;
 +int ret;
 +
 +buf = this_cpu_ptr(scsi_format_log);
 +if (bufptr  buf-buffer + SCSI_LOG_SPOOLSIZE) {
 
 Should that also check that bufptr  buf-buffer?
 
Probably.

 +idx = (bufptr - buf-buffer) / SCSI_LOG_BUFSIZE;
 +ret = test_and_clear_bit(idx, buf-map);
 +WARN_ON(!ret);
 +}
 +preempt_enable();
 +}
 +
 +int sdev_prefix_printk(const char *level, const struct scsi_device
 *sdev,
 +   const char *name, const char *fmt, ...)
 +{
 +va_list args;
 +char *logbuf;
 +size_t off = 0, logbuf_len;
 +int ret;
 +
 +if (!sdev)
 +return 0;
 +
 +logbuf = scsi_log_reserve_buffer(logbuf_len);
 +if (!logbuf)
 +return 0;
 +
 +if (name)
 +off += scnprintf(logbuf + off, logbuf_len - off,
 + [%s] , name);
 +va_start(args, fmt);
 +off += vscnprintf(logbuf + off, logbuf_len - off, fmt, args);
 +va_end(args);
 +ret = dev_printk(level, sdev-sdev_gendev, %s, logbuf);
 +scsi_log_release_buffer(logbuf);
 +return ret;
 +}
 +EXPORT_SYMBOL_GPL(sdev_prefix_printk);
 +
 +int scmd_printk(const char *level, const struct scsi_cmnd *scmd,
 +const char *fmt, ...)
 +{
 +struct gendisk *disk = scmd-request-rq_disk;
 +va_list args;
 +char *logbuf;
 +size_t off = 0, logbuf_len;
 +int ret;
 +
 +if (!scmd || scmd-cmnd == NULL)
 +return 0;
 
 !scmd-cmnd seems more common in neighboring code.
 
Ok.

 +
 +logbuf = scsi_log_reserve_buffer(logbuf_len);
 +if (!logbuf)
 +return 0;
 +if (disk)
 +off += scnprintf(logbuf + off, logbuf_len - off,
 + [%s] , disk-disk_name);
 +va_start(args, fmt);
 +off += vscnprintf(logbuf + off, logbuf_len - off, fmt, args);
 +va_end(args);
 +ret = dev_printk(level, scmd-device-sdev_gendev, %s,
 logbuf);
 +scsi_log_release_buffer(logbuf);
 +return ret;
 +}
 +EXPORT_SYMBOL_GPL(scmd_printk);
 ...
 
 dev_printk is EXPORT_SYMBOL.  The former macro versions of 
 sdev_printk and scmd_printk just called dev_printk, and not
 being symbols, did not change that.
 
 So, I think these function versions should use EXPORT_SYMBOL, so 
 the hated binary drivers can still call them.
 
Okay, will be fixing things up for the next revision.

Thanks for the review.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke   zSeries  Storage
h...@suse.de  +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
--
To unsubscribe from this list: send the line unsubscribe 

Re: BUG in scsi_lib.c due to a bad commit

2014-11-11 Thread Bjorn Helgaas
[+cc Guenter, linux-scsi]

On Tue, Nov 11, 2014 at 4:33 PM, Barto mister.free...@laposte.net wrote:
 Hello everyone,

 I notice a bug since kernel 3.17 ( and also with 3.18 branch ), a random
 hang at boot on some PC configurations, I did a git bisect and I found
 that the culprit is  :

 [045065d8a300a37218c548e9aa7becd581c6a0e8] [SCSI] fix qemu boot hang problem

 http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=045065d8a300a37218c548e9aa7becd581c6a0e8

 the author of this commit has choosen to inverse the logic of the if
 statement in the file  drivers/scsi/scsi_lib.c in order to solve an
 issue with qemu :

 --- a/drivers/scsi/scsi_lib.c
 +++ b/drivers/scsi/scsi_lib.c
 @@ -1774,7 +1774,7 @@ static void scsi_request_fn(struct request_queue *q)
 blk_requeue_request(q, req);
 atomic_dec(sdev-device_busy);
 out_delay:
 - if (atomic_read(sdev-device_busy)  !scsi_device_blocked(sdev))
 + if (!atomic_read(sdev-device_busy)  !scsi_device_blocked(sdev))
 blk_delay_queue(q, SCSI_QUEUE_DELAY);
 }

 this change triggers a bug on my PC ( I don't have SCSI devices, but
 only 3 SATA harddisks and 2 IDE harddisks, SATA disks are on an ICH7
 sata controler on the motherboard gigabyte GA-P31-DS3L, and IDE disk on
 a JMicron JMB363/368 Sata/IDE PCIe card ), every 5~10 boots the boot
 stops suddenly because of this commit,

 If I revert this commit then the bug is gone, more details can be found
 here, where I created a patch who reverts commit 045065d8 :

 https://bugzilla.kernel.org/show_bug.cgi?id=87581

 my question: why Guenter Roeck ( the author of the bad commit ) has
 choosen to inverse the logic in the if statement ?
 before his commit the if statement was like this :

 if (atomic_read(sdev-device_busy)  !scsi_device_blocked(sdev))
 blk_delay_queue(q, SCSI_QUEUE_DELAY);

 if his decision to inverse the logic of
 atomic_read(sdev-device_busy) is acceptable then the real bug is
 probably located elsewhere in the scsi source code, and we must solve
 this mistery because there is obviously a bug regression in SCSI code
 because with older kernels ( 3.16.7 and lower ) I don't have the random
 hang boot bug with my configuration,

 another user in archlinux forums has also this bug and he has a more
 modern PC ( intel i7 core cpu, SSD device ), my fear is when linux
 distros will move to kernel 3.17 then more users will have this weird
 random bug who can occur only on boot and only with a specific PC
 configuration, if the boot step is passed despite the random bug then
 the bug will not occur, it occurs only during the boot process, which
 probably means that the faulty source code is only called during the
 boot process,

 thanks for anyone who wants to dig this problem with me
 --
 To unsubscribe from this list: send the line unsubscribe linux-kernel in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html
 Please read the FAQ at  http://www.tux.org/lkml/
--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3.10 098/123] scsi: Fix error handling in SCSI_IOCTL_SEND_COMMAND

2014-11-11 Thread Greg Kroah-Hartman
3.10-stable review patch.  If anyone has any objections, please let me know.

--

From: Jan Kara j...@suse.cz

commit 84ce0f0e94ac97217398b3b69c21c7a62ebeed05 upstream.

When sg_scsi_ioctl() fails to prepare request to submit in
blk_rq_map_kern() we jump to a label where we just end up copying
(luckily zeroed-out) kernel buffer to userspace instead of reporting
error. Fix the problem by jumping to the right label.

CC: Jens Axboe ax...@kernel.dk
CC: linux-scsi@vger.kernel.org
Coverity-id: 1226871
Signed-off-by: Jan Kara j...@suse.cz
Signed-off-by: Greg Kroah-Hartman gre...@linuxfoundation.org

Fixed up the, now unused, out label.

Signed-off-by: Jens Axboe ax...@fb.com

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

--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -506,7 +506,7 @@ int sg_scsi_ioctl(struct request_queue *
 
if (bytes  blk_rq_map_kern(q, rq, buffer, bytes, __GFP_WAIT)) {
err = DRIVER_ERROR  24;
-   goto out;
+   goto error;
}
 
memset(sense, 0, sizeof(sense));
@@ -516,7 +516,6 @@ int sg_scsi_ioctl(struct request_queue *
 
blk_execute_rq(q, disk, rq, 0);
 
-out:
err = rq-errors  0xff;/* only 8 bit SCSI status */
if (err) {
if (rq-sense_len  rq-sense) {


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


[PATCH 3.14 168/203] scsi: Fix error handling in SCSI_IOCTL_SEND_COMMAND

2014-11-11 Thread Greg Kroah-Hartman
3.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Jan Kara j...@suse.cz

commit 84ce0f0e94ac97217398b3b69c21c7a62ebeed05 upstream.

When sg_scsi_ioctl() fails to prepare request to submit in
blk_rq_map_kern() we jump to a label where we just end up copying
(luckily zeroed-out) kernel buffer to userspace instead of reporting
error. Fix the problem by jumping to the right label.

CC: Jens Axboe ax...@kernel.dk
CC: linux-scsi@vger.kernel.org
Coverity-id: 1226871
Signed-off-by: Jan Kara j...@suse.cz
Signed-off-by: Greg Kroah-Hartman gre...@linuxfoundation.org

Fixed up the, now unused, out label.

Signed-off-by: Jens Axboe ax...@fb.com

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

--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -489,7 +489,7 @@ int sg_scsi_ioctl(struct request_queue *
 
if (bytes  blk_rq_map_kern(q, rq, buffer, bytes, __GFP_WAIT)) {
err = DRIVER_ERROR  24;
-   goto out;
+   goto error;
}
 
memset(sense, 0, sizeof(sense));
@@ -499,7 +499,6 @@ int sg_scsi_ioctl(struct request_queue *
 
blk_execute_rq(q, disk, rq, 0);
 
-out:
err = rq-errors  0xff;/* only 8 bit SCSI status */
if (err) {
if (rq-sense_len  rq-sense) {


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


Re: BUG in scsi_lib.c due to a bad commit

2014-11-11 Thread Guenter Roeck

On 11/11/2014 04:17 PM, Bjorn Helgaas wrote:

[+cc Guenter, linux-scsi]

On Tue, Nov 11, 2014 at 4:33 PM, Barto mister.free...@laposte.net wrote:

Hello everyone,

I notice a bug since kernel 3.17 ( and also with 3.18 branch ), a random
hang at boot on some PC configurations, I did a git bisect and I found
that the culprit is  :

[045065d8a300a37218c548e9aa7becd581c6a0e8] [SCSI] fix qemu boot hang problem

http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=045065d8a300a37218c548e9aa7becd581c6a0e8

the author of this commit has choosen to inverse the logic of the if
statement in the file  drivers/scsi/scsi_lib.c in order to solve an
issue with qemu :

--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1774,7 +1774,7 @@ static void scsi_request_fn(struct request_queue *q)
blk_requeue_request(q, req);
atomic_dec(sdev-device_busy);
out_delay:
- if (atomic_read(sdev-device_busy)  !scsi_device_blocked(sdev))
+ if (!atomic_read(sdev-device_busy)  !scsi_device_blocked(sdev))
blk_delay_queue(q, SCSI_QUEUE_DELAY);
}



The above commit was a follow-up to commit 71e75c97f97a, which did the 
following:

-   if (sdev-device_busy == 0  !scsi_device_blocked(sdev))
+   if (atomic_read(sdev-device_busy)  !scsi_device_blocked(sdev))

meaning it reversed the polarity of the check in the original code.
Since that commit created problems as observed in qemu, I thought it
would be obvious that restoring the original polarity would make sense.
This is explained in my patch, so I am somewhat at loss why ...


this change triggers a bug on my PC ( I don't have SCSI devices, but
only 3 SATA harddisks and 2 IDE harddisks, SATA disks are on an ICH7
sata controler on the motherboard gigabyte GA-P31-DS3L, and IDE disk on
a JMicron JMB363/368 Sata/IDE PCIe card ), every 5~10 boots the boot
stops suddenly because of this commit,

If I revert this commit then the bug is gone, more details can be found
here, where I created a patch who reverts commit 045065d8 :

https://bugzilla.kernel.org/show_bug.cgi?id=87581

my question: why Guenter Roeck ( the author of the bad commit ) has
choosen to inverse the logic in the if statement ?


this question is asked.

Having said that, I don't really care one way or another. I am fine
with reverting my commit; if that is done, I'll simply remove the
related scsi tests from my qemu test runs.

Guenter


before his commit the if statement was like this :

if (atomic_read(sdev-device_busy)  !scsi_device_blocked(sdev))
blk_delay_queue(q, SCSI_QUEUE_DELAY);

if his decision to inverse the logic of
atomic_read(sdev-device_busy) is acceptable then the real bug is
probably located elsewhere in the scsi source code, and we must solve
this mistery because there is obviously a bug regression in SCSI code
because with older kernels ( 3.16.7 and lower ) I don't have the random
hang boot bug with my configuration,

another user in archlinux forums has also this bug and he has a more
modern PC ( intel i7 core cpu, SSD device ), my fear is when linux
distros will move to kernel 3.17 then more users will have this weird
random bug who can occur only on boot and only with a specific PC
configuration, if the boot step is passed despite the random bug then
the bug will not occur, it occurs only during the boot process, which
probably means that the faulty source code is only called during the
boot process,

thanks for anyone who wants to dig this problem with me
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/




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


[PATCH 3.17 249/319] scsi: Fix error handling in SCSI_IOCTL_SEND_COMMAND

2014-11-11 Thread Greg Kroah-Hartman
3.17-stable review patch.  If anyone has any objections, please let me know.

--

From: Jan Kara j...@suse.cz

commit 84ce0f0e94ac97217398b3b69c21c7a62ebeed05 upstream.

When sg_scsi_ioctl() fails to prepare request to submit in
blk_rq_map_kern() we jump to a label where we just end up copying
(luckily zeroed-out) kernel buffer to userspace instead of reporting
error. Fix the problem by jumping to the right label.

CC: Jens Axboe ax...@kernel.dk
CC: linux-scsi@vger.kernel.org
Coverity-id: 1226871
Signed-off-by: Jan Kara j...@suse.cz
Signed-off-by: Greg Kroah-Hartman gre...@linuxfoundation.org

Fixed up the, now unused, out label.

Signed-off-by: Jens Axboe ax...@fb.com

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

--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -509,7 +509,7 @@ int sg_scsi_ioctl(struct request_queue *
 
if (bytes  blk_rq_map_kern(q, rq, buffer, bytes, __GFP_WAIT)) {
err = DRIVER_ERROR  24;
-   goto out;
+   goto error;
}
 
memset(sense, 0, sizeof(sense));
@@ -518,7 +518,6 @@ int sg_scsi_ioctl(struct request_queue *
 
blk_execute_rq(q, disk, rq, 0);
 
-out:
err = rq-errors  0xff;/* only 8 bit SCSI status */
if (err) {
if (rq-sense_len  rq-sense) {


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


[V2 PATCH 1/4] scsi:stex.c Support to Pegasus series.

2014-11-11 Thread Charles Chiou


From 5fdb4203c09d6896e7b71a8f839e46e84234eeb9 Mon Sep 17 00:00:00 2001
From: Charles Chiou charles.ch...@tw.promise.com
Date: Wed, 5 Nov 2014 14:18:43 +0800
Subject: [PATCH 1/4] scsi:stex.c Support to Pegasus series.

Pegasus is a high performace hardware RAID solution designed to unleash
the raw power of Thunderbolt technology.

I add code to distinct SuperTrack and Pegasus series by subID.
It's needed for backward compatibility.

Change the driver version.
---
 drivers/scsi/stex.c | 24 +++-
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c
index 1aa4bef..f52f1de 100644
--- a/drivers/scsi/stex.c
+++ b/drivers/scsi/stex.c
@@ -37,11 +37,11 @@
 #include scsi/scsi_eh.h

 #define DRV_NAME stex
-#define ST_DRIVER_VERSION 4.6..4
-#define ST_VER_MAJOR   4
-#define ST_VER_MINOR   6
-#define ST_OEM 0
-#define ST_BUILD_VER   4
+#define ST_DRIVER_VERSION 5.00..01
+#define ST_VER_MAJOR   5
+#define ST_VER_MINOR   00
+#define ST_OEM 
+#define ST_BUILD_VER   01

 enum {
/* MU register offset */
@@ -327,6 +327,7 @@ struct st_hba {
u16 rq_count;
u16 rq_size;
u16 sts_count;
+   u8  yellowstone;
 };

 struct st_card_info {
@@ -1546,6 +1547,7 @@ static int stex_probe(struct pci_dev *pdev, const 
struct pci_device_id *id)

struct Scsi_Host *host;
const struct st_card_info *ci = NULL;
u32 sts_offset, cp_offset, scratch_offset;
+   u32 subID;
int err;

err = pci_enable_device(pdev);
@@ -1590,6 +1592,18 @@ static int stex_probe(struct pci_dev *pdev, const 
struct pci_device_id *id)


hba-cardtype = (unsigned int) id-driver_data;
ci = stex_card_info[hba-cardtype];
+   subID = id-subdevice;
+   if ((subID == 0x4221 || subID == 0x4222 ||
+   subID == 0x4223 || subID == 0x4224 ||
+   subID == 0x4225 || subID == 0x4226 ||
+   subID == 0x4227 || subID == 0x4261 ||
+   subID == 0x4262 || subID == 0x4263 ||
+   subID == 0x4264 || subID == 0x4265) 
+   (hba-cardtype == st_yel)) {
+   hba-yellowstone = 1;
+   } else if (hba-cardtype == st_yel) {
+   hba-yellowstone = 0;
+   }
sts_offset = scratch_offset = (ci-rq_count+1) * ci-rq_size;
if (hba-cardtype == st_yel)
sts_offset += (ci-sts_count+1) * sizeof(u32);
--
1.9.1

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


[PATCH 2/4] scsi:stex.c Add hotplug support

2014-11-11 Thread Charles Chiou


From 070dfd671f4cefb2d54563b77b9c80a8c82f260a Mon Sep 17 00:00:00 2001
From: Charles Chiou charles.ch...@tw.promise.com
Date: Wed, 5 Nov 2014 17:18:37 +0800
Subject: [PATCH 2/4] scsi:stex.c Add hotplut support

1. Add hotplug support. Pegasus support surprise remove. To this, I
   use return_abnormal_state function to return DID_NO_CONNECT for all
   commands which sent to driver.

2. Remove stex_hba_stop in stex_remove because we cannot send command to
   device after hotplug.

3. Add new device status:  MU_STATE_STOP, MU_STATE_NOCONNECT,
   MU_STATE_STOP is currently no use. MU_STATE_NOCONNECT represent that
   device is plug out from the host.

4  At function stex_do_reset, I replace the part of code by
   return_abnormal_state function.

Signed-off-by: Charles Chiou charles.ch...@tw.promise.com

---
 drivers/scsi/stex.c | 51 
+--

 1 file changed, 33 insertions(+), 18 deletions(-)

diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c
index f52f1de..c0d 100644
--- a/drivers/scsi/stex.c
+++ b/drivers/scsi/stex.c
@@ -83,6 +83,8 @@ enum {
MU_STATE_STARTED= 2,
MU_STATE_RESETTING  = 3,
MU_STATE_FAILED = 4,
+   MU_STATE_STOP   = 5,
+   MU_STATE_NOCONNECT  = 6,

MU_MAX_DELAY= 120,
MU_HANDSHAKE_SIGNATURE  = 0x5555,
@@ -544,6 +546,27 @@ stex_ss_send_cmd(struct st_hba *hba, struct req_msg 
*req, u16 tag)

readl(hba-mmio_base + YH2I_REQ); /* flush */
 }

+static void return_abnormal_state(struct st_hba *hba, int status)
+{
+   struct st_ccb *ccb;
+   unsigned long flags;
+   u16 tag;
+
+   spin_lock_irqsave(hba-host-host_lock, flags);
+   for (tag = 0; tag  hba-host-can_queue; tag++) {
+   ccb = hba-ccb[tag];
+   if (ccb-req == NULL)
+   continue;
+   ccb-req = NULL;
+   if (ccb-cmd) {
+   scsi_dma_unmap(ccb-cmd);
+   ccb-cmd-result = status  16;
+   ccb-cmd-scsi_done(ccb-cmd);
+   ccb-cmd = NULL;
+   }
+   }
+   spin_unlock_irqrestore(hba-host-host_lock, flags);
+}
 static int
 stex_slave_alloc(struct scsi_device *sdev)
 {
@@ -585,7 +608,11 @@ stex_queuecommand_lck(struct scsi_cmnd *cmd, void 
(*done)(struct scsi_cmnd *))

id = cmd-device-id;
lun = cmd-device-lun;
hba = (struct st_hba *) host-hostdata[0];
-
+   if (hba-mu_status == MU_STATE_NOCONNECT) {
+   cmd-result = DID_NO_CONNECT;
+   done(cmd);
+   return 0;
+   }
if (unlikely(hba-mu_status == MU_STATE_RESETTING))
return SCSI_MLQUEUE_HOST_BUSY;

@@ -1287,10 +1314,8 @@ static void stex_ss_reset(struct st_hba *hba)

 static int stex_do_reset(struct st_hba *hba)
 {
-   struct st_ccb *ccb;
unsigned long flags;
unsigned int mu_status = MU_STATE_RESETTING;
-   u16 tag;

spin_lock_irqsave(hba-host-host_lock, flags);
if (hba-mu_status == MU_STATE_STARTING) {
@@ -1324,20 +1349,8 @@ static int stex_do_reset(struct st_hba *hba)
else if (hba-cardtype == st_yel)
stex_ss_reset(hba);

-   spin_lock_irqsave(hba-host-host_lock, flags);
-   for (tag = 0; tag  hba-host-can_queue; tag++) {
-   ccb = hba-ccb[tag];
-   if (ccb-req == NULL)
-   continue;
-   ccb-req = NULL;
-   if (ccb-cmd) {
-   scsi_dma_unmap(ccb-cmd);
-   ccb-cmd-result = DID_RESET  16;
-   ccb-cmd-scsi_done(ccb-cmd);
-   ccb-cmd = NULL;
-   }
-   }
-   spin_unlock_irqrestore(hba-host-host_lock, flags);
+
+   return_abnormal_state(hba, DID_RESET);

if (stex_handshake(hba) == 0)
return 0;
@@ -1802,9 +1815,11 @@ static void stex_remove(struct pci_dev *pdev)
 {
struct st_hba *hba = pci_get_drvdata(pdev);

+   hba-mu_status = MU_STATE_NOCONNECT;
+   return_abnormal_state(hba, DID_NO_CONNECT);
scsi_remove_host(hba-host);

-   stex_hba_stop(hba);
+   scsi_block_requests(hba-host);

stex_hba_free(hba);

--
1.9.1

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


[V2 PATCH 3/4] scsi:stex.c Add reboot support

2014-11-11 Thread Charles Chiou

From 5eac0f3209e0857c983c986786a68eac0d67247b Mon Sep 17 00:00:00 2001
From: Charles Chiou charles.ch...@tw.promise.com
Date: Wed, 5 Nov 2014 19:29:46 +0800
Subject: [PATCH 3/4] scsi:stex.c Add reboot support

1. Add reboot support, Pegasus devices should be notified that
   the host is going to shutdown/reboot. I register reboot callback
   function to distinct host is going to shutdown or to reboot.

2. Pegasus FW shutdown flow is sensitive to host behavior
   (host is going to S3/S4/shutdown/reboot). To this, I add one
   argument in stex_hba_stop to support various stop command.

3. For backward compatibility, I used ST_IGNORED
   variable to specified shutdown should be the old flow.

4. Sometimes Pegasus need to more time to start. Expand
   delay time from 120 to 240.

Signed-off-by: Charles Chiou charles.ch...@tw.promise.com

---
 drivers/scsi/stex.c | 48 +++-
 1 file changed, 43 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c
index c0d..7a66a931 100644
--- a/drivers/scsi/stex.c
+++ b/drivers/scsi/stex.c
@@ -24,6 +24,7 @@
 #include linux/interrupt.h
 #include linux/types.h
 #include linux/module.h
+#include linux/reboot.h
 #include linux/spinlock.h
 #include asm/io.h
 #include asm/irq.h
@@ -86,7 +87,7 @@ enum {
MU_STATE_STOP   = 5,
MU_STATE_NOCONNECT  = 6,

-   MU_MAX_DELAY= 120,
+   MU_MAX_DELAY= 240,
MU_HANDSHAKE_SIGNATURE  = 0x5555,
MU_HANDSHAKE_SIGNATURE_HALF = 0x5a5a,
MU_HARD_RESET_WAIT  = 3,
@@ -166,6 +167,13 @@ enum {

ST_ADDITIONAL_MEM   = 0x20,
ST_ADDITIONAL_MEM_MIN   = 0x8,
+   PMIC_SHUTDOWN   = 0x0D,
+   PMIC_REUMSE = 0x10,
+   ST_IGNORED  = -1,
+   ST_S3   = 3,
+   ST_S4   = 4,
+   ST_S5   = 5,
+   ST_S6   = 6,
 };

 struct st_sgitem {
@@ -344,6 +352,7 @@ struct st_card_info {
u16 sts_count;
 };

+static int isRestart;
 static int msi;
 module_param(msi, int, 0);
 MODULE_PARM_DESC(msi, Enable Message Signaled Interrupts(0=off, 1=on));
@@ -364,6 +373,14 @@ MODULE_AUTHOR(Ed Lin);
 MODULE_DESCRIPTION(Promise Technology SuperTrak EX Controllers);
 MODULE_LICENSE(GPL);
 MODULE_VERSION(ST_DRIVER_VERSION);
+static int stex_reboot_callback(struct notifier_block *self,
+ unsigned long val,
+ void *data)
+{
+   if (val == SYS_RESTART)
+   isRestart = 1;
+   return NOTIFY_OK;
+}

 static void stex_gettime(__le64 *time)
 {
@@ -1563,6 +1580,7 @@ static int stex_probe(struct pci_dev *pdev, const 
struct pci_device_id *id)

u32 subID;
int err;

+   isRestart = 0;
err = pci_enable_device(pdev);
if (err)
return err;
@@ -1749,7 +1767,7 @@ out_disable:
return err;
 }

-static void stex_hba_stop(struct st_hba *hba)
+static void stex_hba_stop(struct st_hba *hba, int st_sleep_mic)
 {
struct req_msg *req;
struct st_msg_header *msg_h;
@@ -1765,11 +1783,18 @@ static void stex_hba_stop(struct st_hba *hba)
} else
memset(req, 0, hba-rq_size);

-   if (hba-cardtype == st_yosemite || hba-cardtype == st_yel) {
+   if ((hba-cardtype == st_yosemite || hba-cardtype == st_yel)
+st_sleep_mic == ST_IGNORED) {
req-cdb[0] = MGT_CMD;
req-cdb[1] = MGT_CMD_SIGNATURE;
req-cdb[2] = CTLR_CONFIG_CMD;
req-cdb[3] = CTLR_SHUTDOWN;
+   } else if (hba-cardtype == st_yel  st_sleep_mic != ST_IGNORED) {
+   req-cdb[0] = MGT_CMD;
+   req-cdb[1] = MGT_CMD_SIGNATURE;
+   req-cdb[2] = CTLR_CONFIG_CMD;
+   req-cdb[3] = PMIC_SHUTDOWN;
+   req-cdb[4] = st_sleep_mic;
} else {
req-cdb[0] = CONTROLLER_CMD;
req-cdb[1] = CTLR_POWER_STATE_CHANGE;
@@ -1789,10 +1814,12 @@ static void stex_hba_stop(struct st_hba *hba)
while (hba-ccb[tag].req_type  PASSTHRU_REQ_TYPE) {
if (time_after(jiffies, before + ST_INTERNAL_TIMEOUT * HZ)) {
hba-ccb[tag].req_type = 0;
+   hba-mu_status = MU_STATE_STOP;
return;
}
msleep(1);
}
+   hba-mu_status = MU_STATE_STOP;
 }

 static void stex_hba_free(struct st_hba *hba)
@@ -1832,7 +1859,14 @@ static void stex_shutdown(struct pci_dev *pdev)
 {
  

[V2 PATCH 4/4] scsi:stex.c Add S3/S4 support

2014-11-11 Thread Charles Chiou

From d0bc6b814e5a16bea639bbdfad992a5593bf3420 Mon Sep 17 00:00:00 2001
From: Charles Chiou charles.ch...@tw.promise.com
Date: Fri, 7 Nov 2014 10:15:18 +0800
Subject: [PATCH 4/4] scsi:stex.c Add S3/S4 support

1. Add S3/S4 support, add .suspend and .resume function in pci_driver.

2. Pegasus take some to init, I create one thread to finish handshake
   to make OS can start faster.

3. According to (2), OS might send command to driver before handshake.
   Return SCSI_MLQUEUE_HOST_BUSY.

Signed-off-by: Charles Chiou charles.ch...@tw.promise.com

---
 drivers/scsi/stex.c | 57 
-

 1 file changed, 56 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c
index 7a66a931..1e0b37e 100644
--- a/drivers/scsi/stex.c
+++ b/drivers/scsi/stex.c
@@ -369,6 +369,10 @@ static const char console_inq_page[] =
0x0C,0x20,0x20,0x20,0x20,0x20,0x20,0x20
 };

+struct hba_handshake_workstruct {
+   struct st_hba *hba;
+   struct work_struct handshake_work;
+};
 MODULE_AUTHOR(Ed Lin);
 MODULE_DESCRIPTION(Promise Technology SuperTrak EX Controllers);
 MODULE_LICENSE(GPL);
@@ -630,7 +634,7 @@ stex_queuecommand_lck(struct scsi_cmnd *cmd, void 
(*done)(struct scsi_cmnd *))

done(cmd);
return 0;
}
-   if (unlikely(hba-mu_status == MU_STATE_RESETTING))
+   if (unlikely(hba-mu_status != MU_STATE_STARTED))
return SCSI_MLQUEUE_HOST_BUSY;

switch (cmd-cmnd[0]) {
@@ -1396,6 +1400,17 @@ static void stex_reset_work(struct work_struct *work)

stex_do_reset(hba);
 }
+static void resume_handshake(struct work_struct *work)
+{
+   struct st_hba *hba;
+   struct hba_handshake_workstruct *hswork;
+
+   hswork = container_of(work,
+   struct hba_handshake_workstruct,
+   handshake_work);
+   hba = hswork-hba;
+   stex_handshake(hba);
+}

 static int stex_biosparam(struct scsi_device *sdev,
struct block_device *bdev, sector_t capacity, int geom[])
@@ -1869,6 +1884,44 @@ static void stex_shutdown(struct pci_dev *pdev)
}
 }

+static int stex_choice_sleep_MIC(pm_message_t state)
+{
+   switch (state.event) {
+   case PM_EVENT_SUSPEND:
+   return ST_S3;
+   case PM_EVENT_FREEZE:
+   case PM_EVENT_HIBERNATE:
+   return ST_S4;
+   default:
+   return ST_S4;
+   }
+}
+
+static int stex_suspend(struct pci_dev *pdev, pm_message_t state)
+{
+   struct st_hba *hba = pci_get_drvdata(pdev);
+
+   if (hba-cardtype == st_yel  hba-yellowstone == 0)
+   stex_hba_stop(hba, stex_choice_sleep_MIC(state));
+   else
+   stex_hba_stop(hba, ST_IGNORED);
+   return 0;
+}
+
+
+static int stex_resume(struct pci_dev *pdev)
+{
+   struct st_hba *hba = pci_get_drvdata(pdev);
+   struct hba_handshake_workstruct *hswork;
+   int sts;
+
+
+   hswork = kzalloc(sizeof(struct hba_handshake_workstruct), GFP_KERNEL);
+   INIT_WORK(hswork-handshake_work, resume_handshake);
+   hswork-hba = hba;
+   sts = schedule_work(hswork-handshake_work);
+   return 0;
+}
 MODULE_DEVICE_TABLE(pci, stex_pci_tbl);

 static struct pci_driver stex_pci_driver = {
@@ -1877,6 +1930,8 @@ static struct pci_driver stex_pci_driver = {
.probe  = stex_probe,
.remove = stex_remove,
.shutdown   = stex_shutdown,
+   .suspend= stex_suspend,
+   .resume = stex_resume,
 };

 static struct notifier_block stex_reboot_notifier = {
--
1.9.1

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


[PATCH] st: set owner in struct device_driver

2014-11-11 Thread Seymour, Shane M
After moving from from branch next-20141106 to next-2014 to pick up recent 
changes to the st driver I found that the following message was being logged by 
the kernel (for many other modules as well):

Driver 'st' needs an owner

There was a change in driver_register to check the struct module *owner and if 
it's not set complain about it, the code path for the st driver is:

static int __init init_st(void)
{
...
err = scsi_register_driver(st_template.gendrv);

Which calls:

int scsi_register_driver(struct device_driver *drv)
{
drv-bus = scsi_bus_type;

return driver_register(drv);
}
EXPORT_SYMBOL(scsi_register_driver);

Which calls:

int driver_register(struct device_driver *drv)
{
int ret;
struct device_driver *other;

BUG_ON(!drv-bus-p);

if (!drv-owner)
printk(KERN_WARNING Driver '%s' needs an owner, drv-name);
...

This patch sets the owner field in the struct device_driver contained in the 
struct scsi_driver for this module. Tested with kernel version 
3.18.0-rc4-next-2014. My assumption here is that the check added in 
driver_register() is correct and that forces this change and there's a lot of 
other modules that require a similar change (at least 72 including sd, sr, and 
osst).

Signed-off-by: Shane Seymour shane.seym...@hp.com
---
diff -up a/drivers/scsi/st.c b/drivers/scsi/st.c
--- a/drivers/scsi/st.c 2014-11-10 21:23:27.088567337 -0600
+++ b/drivers/scsi/st.c 2014-11-11 14:07:37.312721375 -0600
@@ -207,6 +207,7 @@ static struct scsi_driver st_template =
.name   = st,
.probe  = st_probe,
.remove = st_remove,
+   .owner  = THIS_MODULE,
},
 };
--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 04/37] ncr5380: Remove unused macros

2014-11-11 Thread Finn Thain
Some macros are never evaluated (i.e. FOO, USLEEP, SCSI2 and USE_WRAPPER;
and in some drivers, NCR5380_intr and NCR5380_proc_info). DRIVER_SETUP
serves no purpose anymore. Remove these macro definitions.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---
 drivers/scsi/NCR5380.c|2 +-
 drivers/scsi/arm/oak.c|1 -
 drivers/scsi/atari_scsi.h |1 -
 drivers/scsi/g_NCR5380.c  |5 -
 drivers/scsi/g_NCR5380.h  |1 -
 drivers/scsi/mac_scsi.c   |3 ---
 drivers/scsi/pas16.c  |5 -
 drivers/scsi/sun3_scsi.c  |   15 ---
 drivers/scsi/sun3_scsi.h  |1 -
 drivers/scsi/t128.c   |5 -
 10 files changed, 1 insertion(+), 38 deletions(-)

Index: linux/drivers/scsi/mac_scsi.c
===
--- linux.orig/drivers/scsi/mac_scsi.c  2014-11-12 16:10:46.0 +1100
+++ linux/drivers/scsi/mac_scsi.c   2014-11-12 16:10:49.0 +1100
@@ -55,7 +55,6 @@
 #include NCR5380.h
 
 #define RESET_BOOT
-#define DRIVER_SETUP
 
 extern void via_scsi_clear(void);
 
@@ -113,7 +112,6 @@ static __inline__ void macscsi_write(str
  */
 
 static int __init mac_scsi_setup(char *str) {
-#ifdef DRIVER_SETUP
int ints[7];

(void)get_options( str, ARRAY_SIZE(ints), ints);
@@ -166,7 +164,6 @@ static int __init mac_scsi_setup(char *s
}
 #endif /* SUPPORT_TAGS */

-#endif /* DRIVER_SETUP */
return 1;
 }
 
Index: linux/drivers/scsi/sun3_scsi.c
===
--- linux.orig/drivers/scsi/sun3_scsi.c 2014-11-12 16:10:46.0 +1100
+++ linux/drivers/scsi/sun3_scsi.c  2014-11-12 16:10:49.0 +1100
@@ -43,10 +43,6 @@
  * Options :
  *
  * PARITY - enable parity checking.  Not supported.
- *
- * SCSI2 - enable support for SCSI-II tagged queueing.  Untested.
- *
- * USLEEP - enable support for devices that don't disconnect.  Untested.
  */
 
 #define AUTOSENSE
@@ -79,18 +75,7 @@
 
 extern int sun3_map_test(unsigned long, char *);
 
-#define USE_WRAPPER
 /*#define RESET_BOOT */
-#define DRIVER_SETUP
-
-/*
- * BUG can be used to trigger a strange code-size related hang on 2.1 kernels
- */
-#ifdef BUG
-#undef RESET_BOOT
-#undef DRIVER_SETUP
-#endif
-
 /* #define SUPPORT_TAGS */
 
 #ifdef SUN3_SCSI_VME
Index: linux/drivers/scsi/NCR5380.c
===
--- linux.orig/drivers/scsi/NCR5380.c   2014-11-12 16:10:43.0 +1100
+++ linux/drivers/scsi/NCR5380.c2014-11-12 16:10:49.0 +1100
@@ -649,7 +649,7 @@ NCR5380_print_options(struct Scsi_Host *
UNSAFE 
 #endif
);
-   printk( USLEEP, USLEEP_POLL=%d USLEEP_SLEEP=%d, USLEEP_POLL, 
USLEEP_SLEEP);
+   printk( USLEEP_POLL=%d USLEEP_SLEEP=%d, USLEEP_POLL, USLEEP_SLEEP);
printk( generic release=%d, NCR5380_PUBLIC_RELEASE);
if (((struct NCR5380_hostdata *) instance-hostdata)-flags  
FLAG_NCR53C400) {
printk( ncr53c400 release=%d, NCR53C400_PUBLIC_RELEASE);
Index: linux/drivers/scsi/pas16.c
===
--- linux.orig/drivers/scsi/pas16.c 2014-11-12 16:10:48.0 +1100
+++ linux/drivers/scsi/pas16.c  2014-11-12 16:10:49.0 +1100
@@ -1,6 +1,5 @@
 #define AUTOSENSE
 #define PSEUDO_DMA
-#define FOO
 #define UNSAFE  /* Not unsafe for PAS16 -- use it */
 #define PDEBUG 0
 
@@ -52,8 +51,6 @@
  * increase compared to polled I/O.
  *
  * PARITY - enable parity checking.  Not supported.
- * 
- * SCSI2 - enable support for SCSI-II tagged queueing.  Untested.
  *
  * UNSAFE - leave interrupts enabled during pseudo-DMA transfers.  This
  * parameter comes from the NCR5380 code.  It is NOT unsafe with
@@ -63,8 +60,6 @@
  * want to use UNSAFE you can try defining LIMIT_TRANSFERSIZE or
  * twiddle with the transfer size in the high level code.
  *
- * USLEEP - enable support for devices that don't disconnect.  Untested.
- *
  * The card is detected and initialized in one of several ways : 
  * 1.  Autoprobe (default) - There are many different models of
  * the Pro Audio Spectrum/Studio 16, and I only have one of
Index: linux/drivers/scsi/g_NCR5380.c
===
--- linux.orig/drivers/scsi/g_NCR5380.c 2014-11-12 16:10:43.0 +1100
+++ linux/drivers/scsi/g_NCR5380.c  2014-11-12 16:10:49.0 +1100
@@ -44,10 +44,6 @@
  *
  * PARITY - enable parity checking.  Not supported.
  *
- * SCSI2 - enable support for SCSI-II tagged queueing.  Untested.
- *
- * USLEEP - enable support for devices that don't disconnect.  Untested.
- *
  * The card is detected and initialized in one of several ways : 
  * 1.  With command line overrides - NCR5380=port,irq may be 
  * used on the LILO command line to override 

[PATCH v3 03/37] ncr5380: Fix compiler warnings and __setup options

2014-11-11 Thread Finn Thain
Some __setup() options mentioned in Documentation/scsi don't work because
a few lines of code went missing sometime since Linux 2.4. Fix the options
and thus fix some compiler warnings for both the non-modular case,

CC  drivers/scsi/dtc.o
drivers/scsi/dtc.c:176:20: warning: 'dtc_setup' defined but not used 
[-Wunused-function]

and the modular case,

CC [M]  drivers/scsi/pas16.o
drivers/scsi/pas16.c:335:20: warning: 'pas16_setup' defined but not used 
[-Wunused-function]
CC [M]  drivers/scsi/t128.o
drivers/scsi/t128.c:147:20: warning: 't128_setup' defined but not used 
[-Wunused-function]

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de

---
 drivers/scsi/dtc.c   |8 +++-
 drivers/scsi/pas16.c |   10 +-
 drivers/scsi/t128.c  |   11 ++-
 3 files changed, 26 insertions(+), 3 deletions(-)

Index: linux/drivers/scsi/dtc.c
===
--- linux.orig/drivers/scsi/dtc.c   2014-11-12 16:10:43.0 +1100
+++ linux/drivers/scsi/dtc.c2014-11-12 16:10:48.0 +1100
@@ -173,10 +173,13 @@ static const struct signature {
  *
  */
 
-static void __init dtc_setup(char *str, int *ints)
+static int __init dtc_setup(char *str)
 {
static int commandline_current = 0;
int i;
+   int ints[10];
+
+   get_options(str, ARRAY_SIZE(ints), ints);
if (ints[0] != 2)
printk(dtc_setup: usage dtc=address,irq\n);
else if (commandline_current  NO_OVERRIDES) {
@@ -189,7 +192,10 @@ static void __init dtc_setup(char *str,
}
++commandline_current;
}
+   return 1;
 }
+
+__setup(dtc=, dtc_setup);
 #endif
 
 /* 
Index: linux/drivers/scsi/pas16.c
===
--- linux.orig/drivers/scsi/pas16.c 2014-11-12 16:10:43.0 +1100
+++ linux/drivers/scsi/pas16.c  2014-11-12 16:10:48.0 +1100
@@ -337,6 +337,7 @@ static int __init
 }
 
 
+#ifndef MODULE
 /*
  * Function : pas16_setup(char *str, int *ints)
  *
@@ -347,10 +348,13 @@ static int __init
  *
  */
 
-void __init pas16_setup(char *str, int *ints)
+static int __init pas16_setup(char *str)
 {
 static int commandline_current = 0;
 int i;
+int ints[10];
+
+get_options(str, ARRAY_SIZE(ints), ints);
 if (ints[0] != 2) 
printk(pas16_setup : usage pas16=io_port,irq\n);
 else 
@@ -364,8 +368,12 @@ void __init pas16_setup(char *str, int *
}
++commandline_current;
}
+return 1;
 }
 
+__setup(pas16=, pas16_setup);
+#endif
+
 /* 
  * Function : int pas16_detect(struct scsi_host_template * tpnt)
  *
Index: linux/drivers/scsi/t128.c
===
--- linux.orig/drivers/scsi/t128.c  2014-11-12 16:10:43.0 +1100
+++ linux/drivers/scsi/t128.c   2014-11-12 16:10:48.0 +1100
@@ -148,6 +148,7 @@ static struct signature {
 
 #define NO_SIGNATURES ARRAY_SIZE(signatures)
 
+#ifndef MODULE
 /*
  * Function : t128_setup(char *str, int *ints)
  *
@@ -158,9 +159,13 @@ static struct signature {
  *
  */
 
-void __init t128_setup(char *str, int *ints){
+static int __init t128_setup(char *str)
+{
 static int commandline_current = 0;
 int i;
+int ints[10];
+
+get_options(str, ARRAY_SIZE(ints), ints);
 if (ints[0] != 2) 
printk(t128_setup : usage t128=address,irq\n);
 else 
@@ -174,8 +179,12 @@ void __init t128_setup(char *str, int *i
}
++commandline_current;
}
+return 1;
 }
 
+__setup(t128=, t128_setup);
+#endif
+
 /* 
  * Function : int t128_detect(struct scsi_host_template * tpnt)
  *


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


[PATCH v3 00/37] Fixes, cleanups and modernization for NCR5380 drivers

2014-11-11 Thread Finn Thain

This patch series has fixes for bugs and compiler warnings as well as code
cleanup and modernization. It covers all ten NCR5380 drivers and the three
core NCR5380 drivers so it's fairly large.

These patches remove a lot of duplicated code and C pre-processor abuse.
There are also patches for scsi_add_host() conversion for atari_scsi,
mac_scsi and sun3_scsi.

Some steps are taken toward re-unification of the NCR5380 core driver forks
by reducing divergence between them. Also, the atari_NCR5380.c core driver
is generalized so it can be used by sun3_scsi.c (and others).

I have compile-tested all of the NCR5380 drivers (x86, ARM and m68k) and
executed mac_scsi and dmx3191d on suitable hardware. I found no regressions
but the core NCR5380 drivers have bugs unrelated to these patches.

Testing mac_scsi and dmx3191d provides only limited code coverage for these
patches. Some testing on Sun 3, Atari ST and/or Atari TT would be nice
(I don't have the hardware).

There are old bugs relating to exception handling and autosense in the
core NCR5380 drivers that can make testing difficult. I'm working on a
series of patches to address these bugs. Those patches are not yet ready
for submission but they were helpful for the testing I did and may be
helpful to other testers. Let me know if so.

Changes since v1:
- Re-based to v3.17.
- Addressed issues raised in code review (see relevant patches for details).
- Added patches 30 to 36, to remove sun3_NCR5380.c entirely and remove more
  static variables from atari_NCR5380.c.

This patch set stops short of parameterizing the drivers with platform_data
and/or ops struct. IMHO, it would be premature to do such refactoring before
drivers have been purged of static variables and certain #ifdefs. After
that is done, entire modules could be replaced with platform devices.

Several patches in this set address issues with the tagged command queueing
code (see patches 7, 33 and 34). I've since learned from recent discussions
on the linux-scsi list that use of the tag member in struct scsi_cmnd is
deprecated. If removal of the tag member is imminent then it may be better
to remove TCQ support from all of the NCR5380 drivers instead of this
cleanup. Or it could be done separately.

Removal of TCQ code might make re-unification easier, by bringing
atari_NCR5380.c closer to NCR5380.c and eliminating some #ifdefs.
Changes to the TCQ code would affect atari_scsi, being the only driver to
#define SUPPORT_TAGS.

Changes since v2:
- Addressed issues raised in code review (see relevant patches for details).
- Fixed a checkpatch warning in patch 22.
- Added patch 37 to fix a typo.

---
 MAINTAINERS |1 
 arch/m68k/atari/config.c|   27 
 arch/m68k/atari/stdma.c |   61 
 arch/m68k/include/asm/atari_stdma.h |4 
 arch/m68k/include/asm/macintosh.h   |4 
 arch/m68k/mac/config.c  |  146 +
 arch/m68k/sun3/config.c |   60 
 drivers/scsi/Kconfig|2 
 drivers/scsi/NCR5380.c  |  295 +--
 drivers/scsi/NCR5380.h  |   78 
 drivers/scsi/arm/cumana_1.c |   18 
 drivers/scsi/arm/oak.c  |   23 
 drivers/scsi/atari_NCR5380.c|  983 +---
 drivers/scsi/atari_scsi.c   |  673 +++-
 drivers/scsi/atari_scsi.h   |   60 
 drivers/scsi/dmx3191d.c |   31 
 drivers/scsi/dtc.c  |   85 -
 drivers/scsi/dtc.h  |   26 
 drivers/scsi/g_NCR5380.c|  224 --
 drivers/scsi/g_NCR5380.h|   26 
 drivers/scsi/mac_scsi.c |  542 ++
 drivers/scsi/mac_scsi.h |   74 
 drivers/scsi/pas16.c|  106 -
 drivers/scsi/pas16.h|   21 
 drivers/scsi/sun3_NCR5380.c | 2933 
 drivers/scsi/sun3_scsi.c|  512 ++
 drivers/scsi/sun3_scsi.h|   84 -
 drivers/scsi/t128.c |   83 -
 drivers/scsi/t128.h |   23 
 29 files changed, 1742 insertions(+), 5463 deletions(-)




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


[PATCH v3 02/37] ncr5380: Remove unused hostdata fields

2014-11-11 Thread Finn Thain
Remove unused fields from hostdata structs declared with the
NCR5380_implementation_fields macro.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de

---
 drivers/scsi/dmx3191d.c  |4 ++--
 drivers/scsi/mac_scsi.c  |   33 -
 drivers/scsi/mac_scsi.h  |3 +--
 drivers/scsi/sun3_scsi.c |2 --
 drivers/scsi/sun3_scsi.h |3 +--
 5 files changed, 4 insertions(+), 41 deletions(-)

Index: linux/drivers/scsi/dmx3191d.c
===
--- linux.orig/drivers/scsi/dmx3191d.c  2014-11-12 16:10:43.0 +1100
+++ linux/drivers/scsi/dmx3191d.c   2014-11-12 16:10:46.0 +1100
@@ -38,8 +38,8 @@
 #define NCR5380_read(reg)  inb(port + reg)
 #define NCR5380_write(reg, value)  outb(value, port + reg)
 
-#define NCR5380_implementation_fields  unsigned int port
-#define NCR5380_local_declare()NCR5380_implementation_fields
+#define NCR5380_implementation_fields  /* none */
+#define NCR5380_local_declare()unsigned int port
 #define NCR5380_setup(instance)port = instance-io_port
 
 /*
Index: linux/drivers/scsi/mac_scsi.c
===
--- linux.orig/drivers/scsi/mac_scsi.c  2014-11-12 16:10:43.0 +1100
+++ linux/drivers/scsi/mac_scsi.c   2014-11-12 16:10:46.0 +1100
@@ -93,35 +93,6 @@ static volatile unsigned char *mac_scsi_
  * NCR 5380 register access functions
  */
 
-#if 0
-/* Debug versions */
-#define CTRL(p,v) (*ctrl = (v))
-
-static char macscsi_read(struct Scsi_Host *instance, int reg)
-{
-  int iobase = instance-io_port;
-  int i;
-  int *ctrl = ((struct NCR5380_hostdata *)instance-hostdata)-ctrl;
-
-  CTRL(iobase, 0);
-  i = in_8(iobase + (reg4));
-  CTRL(iobase, 0x40);
-
-  return i;
-}
-
-static void macscsi_write(struct Scsi_Host *instance, int reg, int value)
-{
-  int iobase = instance-io_port;
-  int *ctrl = ((struct NCR5380_hostdata *)instance-hostdata)-ctrl;
-
-  CTRL(iobase, 0);
-  out_8(iobase + (reg4), value);
-  CTRL(iobase, 0x40);
-}
-#else
-
-/* Fast versions */
 static __inline__ char macscsi_read(struct Scsi_Host *instance, int reg)
 {
   return in_8(instance-io_port + (reg4));
@@ -131,8 +102,6 @@ static __inline__ void macscsi_write(str
 {
   out_8(instance-io_port + (reg4), value);
 }
-#endif
-
 
 /*
  * Function : mac_scsi_setup(char *str)
@@ -279,8 +248,6 @@ int __init macscsi_detect(struct scsi_ho
 
 instance-n_io_port = 255;
 
-((struct NCR5380_hostdata *)instance-hostdata)-ctrl = 0;
-
 if (instance-irq != SCSI_IRQ_NONE)
if (request_irq(instance-irq, NCR5380_intr, 0, ncr5380, instance)) {
printk(KERN_WARNING scsi%d: IRQ%d not free, interrupts disabled\n,
Index: linux/drivers/scsi/mac_scsi.h
===
--- linux.orig/drivers/scsi/mac_scsi.h  2014-11-12 16:10:43.0 +1100
+++ linux/drivers/scsi/mac_scsi.h   2014-11-12 16:10:46.0 +1100
@@ -47,8 +47,7 @@
 
 #include scsi/scsicam.h
 
-#define NCR5380_implementation_fields \
-int port, ctrl
+#define NCR5380_implementation_fields /* none */
 
 #define NCR5380_local_declare() \
 struct Scsi_Host *_instance
Index: linux/drivers/scsi/sun3_scsi.c
===
--- linux.orig/drivers/scsi/sun3_scsi.c 2014-11-12 16:10:43.0 +1100
+++ linux/drivers/scsi/sun3_scsi.c  2014-11-12 16:10:46.0 +1100
@@ -313,8 +313,6 @@ static int __init sun3scsi_detect(struct
 
instance-n_io_port = 32;
 
-((struct NCR5380_hostdata *)instance-hostdata)-ctrl = 0;
-
if (request_irq(instance-irq, scsi_sun3_intr,
 0, Sun3SCSI-5380, instance)) {
 #ifndef REAL_DMA
Index: linux/drivers/scsi/sun3_scsi.h
===
--- linux.orig/drivers/scsi/sun3_scsi.h 2014-11-12 16:10:43.0 +1100
+++ linux/drivers/scsi/sun3_scsi.h  2014-11-12 16:10:46.0 +1100
@@ -78,8 +78,7 @@ static int sun3scsi_release (struct Scsi
 #define SUN3_SCSI_NAME Sun3 NCR5380 SCSI
 #endif
 
-#define NCR5380_implementation_fields \
-int port, ctrl
+#define NCR5380_implementation_fields /* none */
 
 #define NCR5380_local_declare() \
 struct Scsi_Host *_instance


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


[PATCH v3 01/37] ncr5380: Use printk() not pr_debug()

2014-11-11 Thread Finn Thain
Having defined NDEBUG, and having set the console log level, I'd like to see
some output. Don't use pr_debug(), it's annoying to have to define DEBUG as
well.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---

Use of pr_debug() here was a bad idea of mine. Joe was right when
he questioned it.

---
 drivers/scsi/NCR5380.h |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Index: linux/drivers/scsi/NCR5380.h
===
--- linux.orig/drivers/scsi/NCR5380.h   2014-11-12 16:10:43.0 +1100
+++ linux/drivers/scsi/NCR5380.h2014-11-12 16:10:46.0 +1100
@@ -296,7 +296,8 @@ struct NCR5380_hostdata {
 #endif
 
 #define dprintk(flg, fmt, ...) \
-   do { if ((NDEBUG)  (flg)) pr_debug(fmt, ## __VA_ARGS__); } while (0)
+   do { if ((NDEBUG)  (flg)) \
+   printk(KERN_DEBUG fmt, ## __VA_ARGS__); } while (0)
 
 #if NDEBUG
 #define NCR5380_dprint(flg, arg) \


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


[PATCH v3 06/37] ncr5380: Remove more useless prototypes

2014-11-11 Thread Finn Thain
Make use of the host template static initializer instead of assigning
handlers at run-time. Move __maybe_unused qualifiers from declarations
to definitions. Move the atari_scsi_bus_reset() wrapper after the
definition of NCR5380_bus_reset(). All of the host template handler
prototypes are now redundant so remove them.

The write_info() handler is only relevant to drivers using PSEUDO_DMA so
this patch fixes the compiler warning in atari_NCR5380.c and sun3_NCR5380.c:

  CC  drivers/scsi/atari_scsi.o
  drivers/scsi/NCR5380.h:329: warning: 'NCR5380_write_info' declared 'static' 
but never defined

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Tested-by: Michael Schmitz schmitz...@gmail.com
Reviewed-by: Hannes Reinecke h...@suse.de

---
 drivers/scsi/NCR5380.h   |8 
 drivers/scsi/atari_NCR5380.c |3 +
 drivers/scsi/atari_scsi.c|   76 ---
 drivers/scsi/dtc.c   |7 +--
 drivers/scsi/pas16.c |7 +--
 drivers/scsi/sun3_NCR5380.c  |3 +
 drivers/scsi/t128.c  |7 +--
 7 files changed, 50 insertions(+), 61 deletions(-)

Index: linux/drivers/scsi/NCR5380.h
===
--- linux.orig/drivers/scsi/NCR5380.h   2014-11-12 16:10:46.0 +1100
+++ linux/drivers/scsi/NCR5380.h2014-11-12 16:10:54.0 +1100
@@ -322,14 +322,6 @@ static irqreturn_t NCR5380_intr(int irq,
 #endif
 static void NCR5380_main(struct work_struct *work);
 static void __maybe_unused NCR5380_print_options(struct Scsi_Host *instance);
-static int NCR5380_abort(Scsi_Cmnd * cmd);
-static int NCR5380_bus_reset(Scsi_Cmnd * cmd);
-static int NCR5380_queue_command(struct Scsi_Host *, struct scsi_cmnd *);
-static int __maybe_unused NCR5380_show_info(struct seq_file *,
-   struct Scsi_Host *);
-static int __maybe_unused NCR5380_write_info(struct Scsi_Host *instance,
-   char *buffer, int length);
-
 static void NCR5380_reselect(struct Scsi_Host *instance);
 static int NCR5380_select(struct Scsi_Host *instance, Scsi_Cmnd * cmd, int 
tag);
 #if defined(PSEUDO_DMA) || defined(REAL_DMA) || defined(REAL_DMA_POLL)
Index: linux/drivers/scsi/dtc.c
===
--- linux.orig/drivers/scsi/dtc.c   2014-11-12 16:10:48.0 +1100
+++ linux/drivers/scsi/dtc.c2014-11-12 16:10:54.0 +1100
@@ -219,10 +219,6 @@ static int __init dtc_detect(struct scsi
void __iomem *base;
int sig, count;
 
-   tpnt-proc_name = dtc3x80;
-   tpnt-show_info = dtc_show_info;
-   tpnt-write_info = dtc_write_info;
-
for (count = 0; current_override  NO_OVERRIDES; ++current_override) {
addr = 0;
base = NULL;
@@ -477,6 +473,9 @@ static struct scsi_host_template driver_
.name   = DTC 3180/3280 ,
.detect = dtc_detect,
.release= dtc_release,
+   .proc_name  = dtc3x80,
+   .show_info  = dtc_show_info,
+   .write_info = dtc_write_info,
.queuecommand   = dtc_queue_command,
.eh_abort_handler   = dtc_abort,
.eh_bus_reset_handler   = dtc_bus_reset,
Index: linux/drivers/scsi/pas16.c
===
--- linux.orig/drivers/scsi/pas16.c 2014-11-12 16:10:51.0 +1100
+++ linux/drivers/scsi/pas16.c  2014-11-12 16:10:54.0 +1100
@@ -390,10 +390,6 @@ static int __init pas16_detect(struct sc
 unsigned short io_port;
 int  count;
 
-tpnt-proc_name = pas16;
-tpnt-show_info = pas16_show_info;
-tpnt-write_info = pas16_write_info;
-
 if (pas16_addr != 0) {
overrides[0].io_port = pas16_addr;
/*
@@ -620,6 +616,9 @@ static struct scsi_host_template driver_
.name   = Pro Audio Spectrum-16 SCSI,
.detect = pas16_detect,
.release= pas16_release,
+   .proc_name  = pas16,
+   .show_info  = pas16_show_info,
+   .write_info = pas16_write_info,
.queuecommand   = pas16_queue_command,
.eh_abort_handler = pas16_abort,
.eh_bus_reset_handler = pas16_bus_reset,
Index: linux/drivers/scsi/t128.c
===
--- linux.orig/drivers/scsi/t128.c  2014-11-12 16:10:51.0 +1100
+++ linux/drivers/scsi/t128.c   2014-11-12 16:10:54.0 +1100
@@ -201,10 +201,6 @@ static int __init t128_detect(struct scs
 void __iomem *p;
 int sig, count;
 
-tpnt-proc_name = t128;
-tpnt-show_info = t128_show_info;
-tpnt-write_info = t128_write_info;
-
 for (count = 0; current_override  NO_OVERRIDES; ++current_override) {
base = 0;
p = NULL;
@@ -435,6 +431,9 @@ static struct scsi_host_template driver_
.name  

[PATCH v3 07/37] ncr5380: Cleanup TAG_NEXT and TAG_NONE macros

2014-11-11 Thread Finn Thain
Both atari_NCR5380.c and sun3_NCR5380.c core drivers #undef TAG_NONE and
then redefine it. But the original definition is unused because NCR5380.c
lacks support for tagged queueing. So just define it once.

The TAG_NEXT macro only appears in the arguments to NCR5380_select() calls.
But that routine doesn't use its tag argument as the tag was already
assigned in NCR5380_main(). So remove the unused argument and the macro.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---
 drivers/scsi/NCR5380.c   |   29 +
 drivers/scsi/NCR5380.h   |   11 ---
 drivers/scsi/atari_NCR5380.c |   19 +--
 drivers/scsi/sun3_NCR5380.c  |   19 +--
 4 files changed, 27 insertions(+), 51 deletions(-)

Index: linux/drivers/scsi/atari_NCR5380.c
===
--- linux.orig/drivers/scsi/atari_NCR5380.c 2014-11-12 16:10:54.0 
+1100
+++ linux/drivers/scsi/atari_NCR5380.c  2014-11-12 16:10:55.0 +1100
@@ -316,10 +316,6 @@ static struct scsi_host_template *the_te
  * important: the tag bit must be cleared before 'nr_allocated' is decreased.
  */
 
-/* -1 for TAG_NONE is not possible with unsigned char cmd-tag */
-#undef TAG_NONE
-#define TAG_NONE 0xff
-
 typedef struct {
DECLARE_BITMAP(allocated, MAX_TAGS);
int nr_allocated;
@@ -1118,9 +1114,7 @@ static void NCR5380_main(struct work_str
 #ifdef SUPPORT_TAGS
cmd_get_tag(tmp, tmp-cmnd[0] != 
REQUEST_SENSE);
 #endif
-   if (!NCR5380_select(instance, tmp,
-   (tmp-cmnd[0] == REQUEST_SENSE) ? 
TAG_NONE :
-   TAG_NEXT)) {
+   if (!NCR5380_select(instance, tmp)) {
falcon_dont_release--;
/* release if target did not 
response! */

falcon_release_lock_if_possible(hostdata);
@@ -1351,17 +1345,14 @@ static void collect_stats(struct NCR5380
 #endif
 
 /*
- * Function : int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd,
- * int tag);
+ * Function : int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd)
  *
  * Purpose : establishes I_T_L or I_T_L_Q nexus for new or existing command,
  * including ARBITRATION, SELECTION, and initial message out for
  * IDENTIFY and queue messages.
  *
  * Inputs : instance - instantiation of the 5380 driver on which this
- * target lives, cmd - SCSI command to execute, tag - set to TAG_NEXT for
- * new tag, TAG_NONE for untagged queueing, otherwise set to the tag for
- * the command that is presently connected.
+ * target lives, cmd - SCSI command to execute.
  *
  * Returns : -1 if selection could not execute for some reason,
  * 0 if selection succeeded or failed because the target
@@ -1381,7 +1372,7 @@ static void collect_stats(struct NCR5380
  * cmd-result host byte set to DID_BAD_TARGET.
  */
 
-static int NCR5380_select(struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag)
+static int NCR5380_select(struct Scsi_Host *instance, Scsi_Cmnd *cmd)
 {
SETUP_HOSTDATA(instance);
unsigned char tmp[3], phase;
@@ -2758,7 +2749,7 @@ int NCR5380_abort(Scsi_Cmnd *cmd)
local_irq_restore(flags);
dprintk(NDEBUG_ABORT, scsi%d: aborting disconnected 
command.\n, HOSTNO);
 
-   if (NCR5380_select(instance, cmd, (int)cmd-tag))
+   if (NCR5380_select(instance, cmd))
return FAILED;
 
dprintk(NDEBUG_ABORT, scsi%d: nexus reestablished.\n, 
HOSTNO);
Index: linux/drivers/scsi/sun3_NCR5380.c
===
--- linux.orig/drivers/scsi/sun3_NCR5380.c  2014-11-12 16:10:54.0 
+1100
+++ linux/drivers/scsi/sun3_NCR5380.c   2014-11-12 16:10:55.0 +1100
@@ -305,10 +305,6 @@ static struct scsi_host_template *the_te
  * important: the tag bit must be cleared before 'nr_allocated' is decreased.
  */
 
-/* -1 for TAG_NONE is not possible with unsigned char cmd-tag */
-#undef TAG_NONE
-#define TAG_NONE 0xff
-
 /* For the m68k, the number of bits in 'allocated' must be a multiple of 32! */
 #if (MAX_TAGS % 32) != 0
 #error MAX_TAGS must be a multiple of 32!
@@ -1057,9 +1053,7 @@ static void NCR5380_main (struct work_st
 #ifdef SUPPORT_TAGS
cmd_get_tag( tmp, tmp-cmnd[0] != REQUEST_SENSE );
 #endif
-   if (!NCR5380_select(instance, tmp, 
-   (tmp-cmnd[0] == REQUEST_SENSE) ? TAG_NONE : 
-   TAG_NEXT)) {
+   if 

[PATCH v3 08/37] ncr5380: Remove redundant AUTOSENSE macro

2014-11-11 Thread Finn Thain
Every NCR5380 driver sets AUTOSENSE so it need not be optional (and the
mid-layer expects it). Remove this redundant macro to improve readability.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---
 drivers/scsi/NCR5380.c   |   14 +-
 drivers/scsi/NCR5380.h   |5 -
 drivers/scsi/arm/cumana_1.c  |1 -
 drivers/scsi/arm/oak.c   |1 -
 drivers/scsi/atari_NCR5380.c |   15 +--
 drivers/scsi/atari_scsi.c|1 -
 drivers/scsi/dmx3191d.c  |1 -
 drivers/scsi/dtc.c   |4 
 drivers/scsi/g_NCR5380.c |2 --
 drivers/scsi/mac_scsi.c  |2 --
 drivers/scsi/pas16.c |4 
 drivers/scsi/sun3_NCR5380.c  |   16 +---
 drivers/scsi/sun3_scsi.c |2 --
 drivers/scsi/t128.c  |4 
 14 files changed, 3 insertions(+), 69 deletions(-)

Index: linux/drivers/scsi/NCR5380.c
===
--- linux.orig/drivers/scsi/NCR5380.c   2014-11-12 16:10:55.0 +1100
+++ linux/drivers/scsi/NCR5380.c2014-11-12 16:10:57.0 +1100
@@ -627,9 +627,6 @@ NCR5380_print_options(struct Scsi_Host *
 #ifdef AUTOPROBE_IRQ
AUTOPROBE_IRQ
 #endif
-#ifdef AUTOSENSE
-   AUTOSENSE
-#endif
 #ifdef DIFFERENTIAL
DIFFERENTIAL
 #endif
@@ -857,12 +854,6 @@ static int NCR5380_init(struct Scsi_Host
hostdata-host = instance;
hostdata-time_expires = 0;
 
-#ifndef AUTOSENSE
-   if ((instance-cmd_per_lun  1) || instance-can_queue  1)
-   printk(KERN_WARNING scsi%d : WARNING : support for 
multiple outstanding commands enabled\n  without AUTOSENSE option, 
contingent allegiance conditions may\n
-   be incorrectly cleared.\n, 
instance-host_no);
-#endif /* def AUTOSENSE */
-
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
NCR5380_write(MODE_REG, MR_BASE);
NCR5380_write(TARGET_COMMAND_REG, 0);
@@ -2260,7 +2251,6 @@ static void NCR5380_information_transfer
else if (status_byte(cmd-SCp.Status) 
!= GOOD)
cmd-result = (cmd-result  
0x00) | (DID_ERROR  16);
 
-#ifdef AUTOSENSE
if ((cmd-cmnd[0] == REQUEST_SENSE) 
hostdata-ses.cmd_len) {
scsi_eh_restore_cmnd(cmd, 
hostdata-ses);
@@ -2277,9 +2267,7 @@ static void NCR5380_information_transfer
hostdata-issue_queue;
hostdata-issue_queue = 
(Scsi_Cmnd *) cmd;
dprintk(NDEBUG_QUEUES, scsi%d 
: REQUEST SENSE added to head of issue queue\n, instance-host_no);
-   } else
-#endif /* def AUTOSENSE */
-   {
+   } else {
collect_stats(hostdata, cmd);
cmd-scsi_done(cmd);
}
Index: linux/drivers/scsi/NCR5380.h
===
--- linux.orig/drivers/scsi/NCR5380.h   2014-11-12 16:10:55.0 +1100
+++ linux/drivers/scsi/NCR5380.h2014-11-12 16:10:57.0 +1100
@@ -25,10 +25,7 @@
 #define NCR5380_H
 
 #include linux/interrupt.h
-
-#ifdef AUTOSENSE
 #include scsi/scsi_eh.h
-#endif
 
 #define NCR5380_PUBLIC_RELEASE 7
 #define NCR53C400_PUBLIC_RELEASE 2
@@ -281,9 +278,7 @@ struct NCR5380_hostdata {
unsigned pendingr;
unsigned pendingw;
 #endif
-#ifdef AUTOSENSE
struct scsi_eh_save ses;
-#endif
 };
 
 #ifdef __KERNEL__
Index: linux/drivers/scsi/arm/cumana_1.c
===
--- linux.orig/drivers/scsi/arm/cumana_1.c  2014-11-12 16:10:43.0 
+1100
+++ linux/drivers/scsi/arm/cumana_1.c   2014-11-12 16:10:57.0 +1100
@@ -18,7 +18,6 @@
 
 #include scsi/scsicam.h
 
-#define AUTOSENSE
 #define PSEUDO_DMA
 
 #define CUMANASCSI_PUBLIC_RELEASE 1
Index: linux/drivers/scsi/arm/oak.c
===
--- linux.orig/drivers/scsi/arm/oak.c   2014-11-12 16:10:49.0 +1100
+++ linux/drivers/scsi/arm/oak.c2014-11-12 16:10:57.0 +1100
@@ -17,7 +17,6 @@
 #include ../scsi.h
 #include scsi/scsi_host.h
 
-#define AUTOSENSE
 /*#define PSEUDO_DMA*/
 
 #define OAKSCSI_PUBLIC_RELEASE 1
Index: linux/drivers/scsi/atari_NCR5380.c
===
--- linux.orig/drivers/scsi/atari_NCR5380.c 2014-11-12 

[PATCH v3 21/37] mac_scsi: Convert to platform device

2014-11-11 Thread Finn Thain
Convert mac_scsi to platform device and eliminate scsi_register().

Platform resources for chip registers now follow the documentation. This
should fix issues with the Mac IIci (and possibly other models too).

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Acked-by: Geert Uytterhoeven ge...@linux-m68k.org

---

The new hwreg_present() call site is not protected by local_irq_save/restore.
This assumes Geert's patch, Disable/restore interrupts in
hwreg_present()/hwreg_write(), which is commit e4dc601bf99ccd1c in 3.18-rc1.

Changes since v1:
- Use NO_IRQ instead of IRQ_NONE.
- Drop unnecessary MACH_IS_MAC() test.
- Remove static platform_device structs and call
  platform_device_register_simple() instead of platform_device_register().
- Platform resources now const and __initconst.
- Add MAC_SCSI_LATE platform resources to avoid PDMA on certain models.

---
 arch/m68k/include/asm/macintosh.h |4 
 arch/m68k/mac/config.c|  146 --
 drivers/scsi/mac_scsi.c   |  245 +++---
 3 files changed, 262 insertions(+), 133 deletions(-)

Index: linux/drivers/scsi/mac_scsi.c
===
--- linux.orig/drivers/scsi/mac_scsi.c  2014-11-12 16:11:22.0 +1100
+++ linux/drivers/scsi/mac_scsi.c   2014-11-12 16:11:23.0 +1100
@@ -12,23 +12,18 @@
  */
 
 #include linux/types.h
-#include linux/stddef.h
-#include linux/ctype.h
 #include linux/delay.h
-
 #include linux/module.h
-#include linux/signal.h
 #include linux/ioport.h
 #include linux/init.h
 #include linux/blkdev.h
 #include linux/interrupt.h
+#include linux/platform_device.h
 
+#include asm/hwtest.h
 #include asm/io.h
-#include asm/irq.h
-
-#include asm/macintosh.h
 #include asm/macints.h
-#include asm/mac_via.h
+#include asm/setup.h
 
 #include scsi/scsi_host.h
 
@@ -36,7 +31,7 @@
 
 #define PSEUDO_DMA
 
-#define NCR5380_implementation_fields   /* none */
+#define NCR5380_implementation_fields   unsigned char *pdma_base
 #define NCR5380_local_declare() struct Scsi_Host *_instance
 #define NCR5380_setup(instance) _instance = instance
 
@@ -58,10 +53,6 @@
 
 #define RESET_BOOT
 
-#ifdef RESET_BOOT
-static void mac_scsi_reset_boot(struct Scsi_Host *instance);
-#endif
-
 static int setup_can_queue = -1;
 module_param(setup_can_queue, int, 0);
 static int setup_cmd_per_lun = -1;
@@ -86,23 +77,18 @@ module_param(setup_hostid, int, 0);
 #defineAFTER_RESET_DELAY   (HZ/2)
 #endif
 
-static unsigned char *mac_scsi_regp;
-static unsigned char *mac_scsi_drq;
-static unsigned char *mac_scsi_nodrq;
-
-
 /*
  * NCR 5380 register access functions
  */
 
-static __inline__ char macscsi_read(struct Scsi_Host *instance, int reg)
+static inline char macscsi_read(struct Scsi_Host *instance, int reg)
 {
-  return in_8(instance-io_port + (reg4));
+   return in_8(instance-base + (reg  4));
 }
 
-static __inline__ void macscsi_write(struct Scsi_Host *instance, int reg, int 
value)
+static inline void macscsi_write(struct Scsi_Host *instance, int reg, int 
value)
 {
-  out_8(instance-io_port + (reg4), value);
+   out_8(instance-base + (reg  4), value);
 }
 
 #ifndef MODULE
@@ -134,96 +120,6 @@ static int __init mac_scsi_setup(char *s
 __setup(mac5380=, mac_scsi_setup);
 #endif /* !MODULE */
 
-/*
- * Function : int macscsi_detect(struct scsi_host_template * tpnt)
- *
- * Purpose : initializes mac NCR5380 driver based on the
- * command line / compile time port and irq definitions.
- *
- * Inputs : tpnt - template for this SCSI adapter.
- *
- * Returns : 1 if a host adapter was found, 0 if not.
- *
- */
- 
-int __init macscsi_detect(struct scsi_host_template * tpnt)
-{
-static int called = 0;
-int flags = 0;
-struct Scsi_Host *instance;
-
-if (!MACH_IS_MAC || called)
-   return( 0 );
-
-if (macintosh_config-scsi_type != MAC_SCSI_OLD)
-   return( 0 );
-
-   if (setup_can_queue  0)
-   tpnt-can_queue = setup_can_queue;
-   if (setup_cmd_per_lun  0)
-   tpnt-cmd_per_lun = setup_cmd_per_lun;
-   if (setup_sg_tablesize = 0)
-   tpnt-sg_tablesize = setup_sg_tablesize;
-   if (setup_hostid = 0)
-   tpnt-this_id = setup_hostid  7;
-
-#ifdef SUPPORT_TAGS
-if (setup_use_tagged_queuing  0)
-   setup_use_tagged_queuing = 0;
-#endif
-
-/* Once we support multiple 5380s (e.g. DuoDock) we'll do
-   something different here */
-instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
-if (instance == NULL)
-   return 0;
-
-if (macintosh_config-ident == MAC_MODEL_IIFX) {
-   mac_scsi_regp  = (unsigned char *) VIA1_BASE + 0x8000;
-   mac_scsi_drq   = (unsigned char *) VIA1_BASE + 0xE000;
-   mac_scsi_nodrq = (unsigned char *) VIA1_BASE + 0xC000;
-   /* The IIFX should be able to do true DMA, but pseudo-dma doesn't work 
*/
-   flags = 

[PATCH v3 23/37] atari_scsi: Convert to platform device

2014-11-11 Thread Finn Thain
Convert atari_scsi to platform device and eliminate scsi_register().

Validate __setup options later on so that module options are checked as well.

Remove the comment about the scsi mid-layer disabling the host irq as it
is no longer true (AFAICT). Also remove the obsolete slow interrupt stuff
(IRQ_TYPE_SLOW == 0 anyway).

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com
Acked-by: Geert Uytterhoeven ge...@linux-m68k.org

---

Changes since v1:
- Remove unnecessary return -ENODEV branch.
- Move IRQ constants to platform resources.
- Always assign instance-irq so that the atari_NCR5380.c core driver
  can adopt the NCR5380.c interpretation of instance-irq.

---
 arch/m68k/atari/config.c  |   27 ++
 drivers/scsi/atari_scsi.c |  424 ++
 drivers/scsi/atari_scsi.h |   17 -
 3 files changed, 237 insertions(+), 231 deletions(-)

Index: linux/arch/m68k/atari/config.c
===
--- linux.orig/arch/m68k/atari/config.c 2014-11-12 16:10:43.0 +1100
+++ linux/arch/m68k/atari/config.c  2014-11-12 16:11:26.0 +1100
@@ -858,6 +858,24 @@ static struct platform_device *atari_net
 };
 #endif /* CONFIG_ATARI_ETHERNEC */
 
+#ifdef CONFIG_ATARI_SCSI
+static const struct resource atari_scsi_st_rsrc[] __initconst = {
+   {
+   .flags = IORESOURCE_IRQ,
+   .start = IRQ_MFP_FSCSI,
+   .end   = IRQ_MFP_FSCSI,
+   },
+};
+
+static const struct resource atari_scsi_tt_rsrc[] __initconst = {
+   {
+   .flags = IORESOURCE_IRQ,
+   .start = IRQ_TT_MFP_SCSI,
+   .end   = IRQ_TT_MFP_SCSI,
+   },
+};
+#endif
+
 int __init atari_platform_init(void)
 {
int rv = 0;
@@ -892,6 +910,15 @@ int __init atari_platform_init(void)
}
 #endif
 
+#ifdef CONFIG_ATARI_SCSI
+   if (ATARIHW_PRESENT(ST_SCSI))
+   platform_device_register_simple(atari_scsi, -1,
+   atari_scsi_st_rsrc, ARRAY_SIZE(atari_scsi_st_rsrc));
+   else if (ATARIHW_PRESENT(TT_SCSI))
+   platform_device_register_simple(atari_scsi, -1,
+   atari_scsi_tt_rsrc, ARRAY_SIZE(atari_scsi_tt_rsrc));
+#endif
+
return rv;
 }
 
Index: linux/drivers/scsi/atari_scsi.c
===
--- linux.orig/drivers/scsi/atari_scsi.c2014-11-12 16:11:25.0 
+1100
+++ linux/drivers/scsi/atari_scsi.c 2014-11-12 16:11:26.0 +1100
@@ -74,33 +74,26 @@
 #defineMAX_TAGS 32
 
 #include linux/types.h
-#include linux/stddef.h
-#include linux/ctype.h
 #include linux/delay.h
-#include linux/mm.h
 #include linux/blkdev.h
 #include linux/interrupt.h
 #include linux/init.h
 #include linux/nvram.h
 #include linux/bitops.h
 #include linux/wait.h
+#include linux/platform_device.h
 
 #include asm/setup.h
 #include asm/atarihw.h
 #include asm/atariints.h
-#include asm/page.h
-#include asm/pgtable.h
-#include asm/irq.h
-#include asm/traps.h
-
-#include scsi/scsi_host.h
-#include atari_scsi.h
-#include NCR5380.h
 #include asm/atari_stdma.h
 #include asm/atari_stram.h
 #include asm/io.h
 
-#include linux/stat.h
+#include scsi/scsi_host.h
+
+#include atari_scsi.h
+#include NCR5380.h
 
 #defineIS_A_TT()   ATARIHW_PRESENT(TT_SCSI)
 
@@ -176,25 +169,9 @@ static inline void DISABLE_IRQ(void)
 #defineAFTER_RESET_DELAY   (5*HZ/2)
 #endif
 
-/* Prototypes */
-
 #ifdef REAL_DMA
 static void atari_scsi_fetch_restbytes(void);
 #endif
-static irqreturn_t scsi_tt_intr(int irq, void *dummy);
-static irqreturn_t scsi_falcon_intr(int irq, void *dummy);
-static void falcon_release_lock_if_possible(struct NCR5380_hostdata *hostdata);
-static int falcon_get_lock(void);
-#ifdef CONFIG_ATARI_SCSI_RESET_BOOT
-static void atari_scsi_reset_boot(void);
-#endif
-static unsigned char atari_scsi_tt_reg_read(unsigned char reg);
-static void atari_scsi_tt_reg_write(unsigned char reg, unsigned char value);
-static unsigned char atari_scsi_falcon_reg_read(unsigned char reg);
-static void atari_scsi_falcon_reg_write(unsigned char reg, unsigned char 
value);
-
-/* End of Prototypes **/
-
 
 static struct Scsi_Host *atari_scsi_host;
 static unsigned char (*atari_scsi_reg_read)(unsigned char reg);
@@ -517,160 +494,12 @@ static int falcon_get_lock(void)
return 1;
 }
 
-
-static int __init atari_scsi_detect(struct scsi_host_template *host)
-{
-   static int called = 0;
-   struct Scsi_Host *instance;
-
-   if (!MACH_IS_ATARI ||
-   (!ATARIHW_PRESENT(ST_SCSI)  !ATARIHW_PRESENT(TT_SCSI)) ||
-   called)
-   return 0;
-
-   host-proc_name = Atari;
-
-   atari_scsi_reg_read  = IS_A_TT() ? atari_scsi_tt_reg_read :
-  

[PATCH v3 14/37] ncr5380: Remove pointless compiler command line override macros

2014-11-11 Thread Finn Thain
Compile-time override of scsi host defaults is pointless for drivers that
provide module parameters and __setup options for that. Too many macros make
the code hard to read so remove them.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---
 drivers/scsi/atari_scsi.c |2 +-
 drivers/scsi/atari_scsi.h |3 ---
 drivers/scsi/mac_scsi.c   |   19 +--
 drivers/scsi/mac_scsi.h   |   16 
 drivers/scsi/sun3_scsi.c  |   20 ++--
 drivers/scsi/sun3_scsi.h  |   18 --
 6 files changed, 20 insertions(+), 58 deletions(-)

Index: linux/drivers/scsi/mac_scsi.c
===
--- linux.orig/drivers/scsi/mac_scsi.c  2014-11-12 16:11:06.0 +1100
+++ linux/drivers/scsi/mac_scsi.c   2014-11-12 16:11:11.0 +1100
@@ -177,13 +177,12 @@ int __init macscsi_detect(struct scsi_ho
 if (macintosh_config-scsi_type != MAC_SCSI_OLD)
return( 0 );
 
-/* setup variables */
-tpnt-can_queue =
-   (setup_can_queue  0) ? setup_can_queue : CAN_QUEUE;
-tpnt-cmd_per_lun =
-   (setup_cmd_per_lun  0) ? setup_cmd_per_lun : CMD_PER_LUN;
-tpnt-sg_tablesize = 
-   (setup_sg_tablesize = 0) ? setup_sg_tablesize : SG_TABLESIZE;
+   if (setup_can_queue  0)
+   tpnt-can_queue = setup_can_queue;
+   if (setup_cmd_per_lun  0)
+   tpnt-cmd_per_lun = setup_cmd_per_lun;
+   if (setup_sg_tablesize = 0)
+   tpnt-sg_tablesize = setup_sg_tablesize;
 
 if (setup_hostid = 0)
tpnt-this_id = setup_hostid;
@@ -194,7 +193,7 @@ int __init macscsi_detect(struct scsi_ho
 
 #ifdef SUPPORT_TAGS
 if (setup_use_tagged_queuing  0)
-   setup_use_tagged_queuing = USE_TAGGED_QUEUING;
+   setup_use_tagged_queuing = 0;
 #endif
 
 /* Once we support multiple 5380s (e.g. DuoDock) we'll do
@@ -496,10 +495,10 @@ static struct scsi_host_template driver_
.queuecommand   = macscsi_queue_command,
.eh_abort_handler   = macscsi_abort,
.eh_bus_reset_handler   = macscsi_bus_reset,
-   .can_queue  = CAN_QUEUE,
+   .can_queue  = 16,
.this_id= 7,
.sg_tablesize   = SG_ALL,
-   .cmd_per_lun= CMD_PER_LUN,
+   .cmd_per_lun= 2,
.use_clustering = DISABLE_CLUSTERING
 };
 
Index: linux/drivers/scsi/mac_scsi.h
===
--- linux.orig/drivers/scsi/mac_scsi.h  2014-11-12 16:11:06.0 +1100
+++ linux/drivers/scsi/mac_scsi.h   2014-11-12 16:11:11.0 +1100
@@ -17,22 +17,6 @@
 
 #ifndef ASM
 
-#ifndef CMD_PER_LUN
-#define CMD_PER_LUN 2
-#endif
-
-#ifndef CAN_QUEUE
-#define CAN_QUEUE 16
-#endif
-
-#ifndef SG_TABLESIZE
-#define SG_TABLESIZE SG_NONE
-#endif
-
-#ifndef USE_TAGGED_QUEUING
-#defineUSE_TAGGED_QUEUING 0
-#endif
-
 #include scsi/scsicam.h
 
 #define NCR5380_implementation_fields /* none */
Index: linux/drivers/scsi/sun3_scsi.c
===
--- linux.orig/drivers/scsi/sun3_scsi.c 2014-11-12 16:11:06.0 +1100
+++ linux/drivers/scsi/sun3_scsi.c  2014-11-12 16:11:11.0 +1100
@@ -198,12 +198,12 @@ static int __init sun3scsi_detect(struct
 #endif
 
/* setup variables */
-   tpnt-can_queue =
-   (setup_can_queue  0) ? setup_can_queue : CAN_QUEUE;
-   tpnt-cmd_per_lun =
-   (setup_cmd_per_lun  0) ? setup_cmd_per_lun : CMD_PER_LUN;
-   tpnt-sg_tablesize = 
-   (setup_sg_tablesize = 0) ? setup_sg_tablesize : SG_TABLESIZE;
+   if (setup_can_queue  0)
+   tpnt-can_queue = setup_can_queue;
+   if (setup_cmd_per_lun  0)
+   tpnt-cmd_per_lun = setup_cmd_per_lun;
+   if (setup_sg_tablesize = 0)
+   tpnt-sg_tablesize = setup_sg_tablesize;
 
if (setup_hostid = 0)
tpnt-this_id = setup_hostid;
@@ -257,7 +257,7 @@ static int __init sun3scsi_detect(struct
 #endif
 #ifdef SUPPORT_TAGS
if (setup_use_tagged_queuing  0)
-   setup_use_tagged_queuing = USE_TAGGED_QUEUING;
+   setup_use_tagged_queuing = 1;
 #endif
 
instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
@@ -683,10 +683,10 @@ static struct scsi_host_template driver_
.queuecommand   = sun3scsi_queue_command,
.eh_abort_handler   = sun3scsi_abort,
.eh_bus_reset_handler   = sun3scsi_bus_reset,
-   .can_queue  = CAN_QUEUE,
+   .can_queue  = 16,
.this_id= 7,
-   .sg_tablesize   = SG_TABLESIZE,
-   .cmd_per_lun= CMD_PER_LUN,
+   .sg_tablesize

[PATCH v3 16/37] ncr5380: Drop legacy scsi.h include

2014-11-11 Thread Finn Thain
Convert Scsi_Cmnd to struct scsi_cmnd and drop the #include scsi.h.
The sun3_NCR5380.c core driver already uses struct scsi_cmnd so converting
the other core drivers reduces the diff which makes them easier to unify.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---

Line length issues have not been addressed here because comparison of the
three core drivers (NCR5380.c, atari_NCR5380.c and sun3_NCR5380.c) becomes
too messy. These lines get shorter once the type casting is fixed (work in
progress).

---
 drivers/scsi/NCR5380.c   |   70 +++--
 drivers/scsi/NCR5380.h   |   10 ++--
 drivers/scsi/arm/cumana_1.c  |1 
 drivers/scsi/arm/oak.c   |1 
 drivers/scsi/atari_NCR5380.c |  102 +--
 drivers/scsi/atari_scsi.c|5 --
 drivers/scsi/dmx3191d.c  |1 
 drivers/scsi/dtc.c   |1 
 drivers/scsi/g_NCR5380.c |1 
 drivers/scsi/mac_scsi.c  |1 
 drivers/scsi/pas16.c |1 
 drivers/scsi/sun3_NCR5380.c  |   20 
 drivers/scsi/sun3_scsi.c |1 
 drivers/scsi/t128.c  |1 
 14 files changed, 105 insertions(+), 111 deletions(-)

Index: linux/drivers/scsi/NCR5380.c
===
--- linux.orig/drivers/scsi/NCR5380.c   2014-11-12 16:11:13.0 +1100
+++ linux/drivers/scsi/NCR5380.c2014-11-12 16:11:16.0 +1100
@@ -277,7 +277,7 @@ static void do_reset(struct Scsi_Host *h
  * Set up the internal fields in the SCSI command.
  */
 
-static __inline__ void initialize_SCp(Scsi_Cmnd * cmd)
+static inline void initialize_SCp(struct scsi_cmnd *cmd)
 {
/* 
 * Initialize the Scsi Pointer field so that all of the commands in the 
@@ -719,7 +719,7 @@ static int __maybe_unused NCR5380_write_
 #undef SPRINTF
 #define SPRINTF(args...) seq_printf(m, ## args)
 static
-void lprint_Scsi_Cmnd(Scsi_Cmnd * cmd, struct seq_file *m);
+void lprint_Scsi_Cmnd(struct scsi_cmnd *cmd, struct seq_file *m);
 static
 void lprint_command(unsigned char *cmd, struct seq_file *m);
 static
@@ -729,7 +729,7 @@ static int __maybe_unused NCR5380_show_i
struct Scsi_Host *instance)
 {
struct NCR5380_hostdata *hostdata;
-   Scsi_Cmnd *ptr;
+   struct scsi_cmnd *ptr;
 
hostdata = (struct NCR5380_hostdata *) instance-hostdata;
 
@@ -741,19 +741,19 @@ static int __maybe_unused NCR5380_show_i
if (!hostdata-connected)
SPRINTF(scsi%d: no currently connected command\n, 
instance-host_no);
else
-   lprint_Scsi_Cmnd((Scsi_Cmnd *) hostdata-connected, m);
+   lprint_Scsi_Cmnd((struct scsi_cmnd *) hostdata-connected, m);
SPRINTF(scsi%d: issue_queue\n, instance-host_no);
-   for (ptr = (Scsi_Cmnd *) hostdata-issue_queue; ptr; ptr = (Scsi_Cmnd 
*) ptr-host_scribble)
+   for (ptr = (struct scsi_cmnd *) hostdata-issue_queue; ptr; ptr = 
(struct scsi_cmnd *) ptr-host_scribble)
lprint_Scsi_Cmnd(ptr, m);
 
SPRINTF(scsi%d: disconnected_queue\n, instance-host_no);
-   for (ptr = (Scsi_Cmnd *) hostdata-disconnected_queue; ptr; ptr = 
(Scsi_Cmnd *) ptr-host_scribble)
+   for (ptr = (struct scsi_cmnd *) hostdata-disconnected_queue; ptr; ptr 
= (struct scsi_cmnd *) ptr-host_scribble)
lprint_Scsi_Cmnd(ptr, m);
spin_unlock_irq(instance-host_lock);
return 0;
 }
 
-static void lprint_Scsi_Cmnd(Scsi_Cmnd * cmd, struct seq_file *m)
+static void lprint_Scsi_Cmnd(struct scsi_cmnd *cmd, struct seq_file *m)
 {
SPRINTF(scsi%d : destination target %d, lun %llu\n, 
cmd-device-host-host_no, cmd-device-id, cmd-device-lun);
SPRINTF(command = );
@@ -912,11 +912,11 @@ static void NCR5380_exit(struct Scsi_Hos
  * Locks: host lock taken by caller
  */
 
-static int NCR5380_queue_command_lck(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd 
*))
+static int NCR5380_queue_command_lck(struct scsi_cmnd *cmd, void (*done) 
(struct scsi_cmnd *))
 {
struct Scsi_Host *instance = cmd-device-host;
struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *) 
instance-hostdata;
-   Scsi_Cmnd *tmp;
+   struct scsi_cmnd *tmp;
 
 #if (NDEBUG  NDEBUG_NO_WRITE)
switch (cmd-cmnd[0]) {
@@ -950,7 +950,7 @@ static int NCR5380_queue_command_lck(Scs
cmd-host_scribble = (unsigned char *) hostdata-issue_queue;
hostdata-issue_queue = cmd;
} else {
-   for (tmp = (Scsi_Cmnd *) hostdata-issue_queue; 
tmp-host_scribble; tmp = (Scsi_Cmnd *) tmp-host_scribble);
+   for (tmp = (struct scsi_cmnd *) hostdata-issue_queue; 
tmp-host_scribble; tmp = (struct scsi_cmnd *) tmp-host_scribble);
LIST(cmd, tmp);
tmp-host_scribble = (unsigned char *) cmd;
}
@@ -981,7 +981,7 @@ static void 

[PATCH v3 05/37] ncr5380: Remove useless prototypes

2014-11-11 Thread Finn Thain
Add missing static qualifiers and remove the now pointless prototypes. The
NCR5380_* prototypes are all declared in NCR5380.h and renamed using macros.
Further declarations are redundant (some are completely unused). Remove
them.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---
 drivers/scsi/atari_scsi.c |5 -
 drivers/scsi/dtc.h|7 ---
 drivers/scsi/g_NCR5380.c  |6 +++---
 drivers/scsi/g_NCR5380.h  |6 --
 drivers/scsi/mac_scsi.c   |2 --
 drivers/scsi/pas16.c  |6 +++---
 drivers/scsi/pas16.h  |6 --
 drivers/scsi/sun3_scsi.c  |4 +---
 drivers/scsi/sun3_scsi.h  |7 ---
 drivers/scsi/t128.c   |7 ---
 drivers/scsi/t128.h   |6 --
 11 files changed, 11 insertions(+), 51 deletions(-)

Index: linux/drivers/scsi/g_NCR5380.c
===
--- linux.orig/drivers/scsi/g_NCR5380.c 2014-11-12 16:10:49.0 +1100
+++ linux/drivers/scsi/g_NCR5380.c  2014-11-12 16:10:51.0 +1100
@@ -272,7 +272,7 @@ static int __init do_DTC3181E_setup(char
  * Locks: none
  */
 
-int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
+static int __init generic_NCR5380_detect(struct scsi_host_template *tpnt)
 {
static int current_override = 0;
int count;
@@ -484,7 +484,7 @@ int __init generic_NCR5380_detect(struct
  * Report driver information for the NCR5380
  */

-const char *generic_NCR5380_info(struct Scsi_Host *host)
+static const char *generic_NCR5380_info(struct Scsi_Host *host)
 {
static const char string[] = Generic NCR5380/53C400 Driver;
return string;
@@ -499,7 +499,7 @@ const char *generic_NCR5380_info(struct
  * Locks: none
  */
  
-int generic_NCR5380_release_resources(struct Scsi_Host *instance)
+static int generic_NCR5380_release_resources(struct Scsi_Host *instance)
 {
NCR5380_local_declare();
NCR5380_setup(instance);
Index: linux/drivers/scsi/pas16.c
===
--- linux.orig/drivers/scsi/pas16.c 2014-11-12 16:10:49.0 +1100
+++ linux/drivers/scsi/pas16.c  2014-11-12 16:10:51.0 +1100
@@ -382,7 +382,7 @@ __setup(pas16=, pas16_setup);
  *
  */
 
-int __init pas16_detect(struct scsi_host_template * tpnt)
+static int __init pas16_detect(struct scsi_host_template *tpnt)
 {
 static int current_override = 0;
 static unsigned short current_base = 0;
@@ -512,8 +512,8 @@ int __init pas16_detect(struct scsi_host
  * and matching the H_C_S coordinates to what DOS uses.
  */
 
-int pas16_biosparam(struct scsi_device *sdev, struct block_device *dev,
-   sector_t capacity, int * ip)
+static int pas16_biosparam(struct scsi_device *sdev, struct block_device *dev,
+   sector_t capacity, int *ip)
 {
   int size = capacity;
   ip[0] = 64;
Index: linux/drivers/scsi/sun3_scsi.c
===
--- linux.orig/drivers/scsi/sun3_scsi.c 2014-11-12 16:10:49.0 +1100
+++ linux/drivers/scsi/sun3_scsi.c  2014-11-12 16:10:51.0 +1100
@@ -86,8 +86,6 @@ extern int sun3_map_test(unsigned long,
 
 
 static irqreturn_t scsi_sun3_intr(int irq, void *dummy);
-static inline unsigned char sun3scsi_read(int reg);
-static inline void sun3scsi_write(int reg, int value);
 
 static int setup_can_queue = -1;
 module_param(setup_can_queue, int, 0);
@@ -348,7 +346,7 @@ static int __init sun3scsi_detect(struct
return 1;
 }
 
-int sun3scsi_release (struct Scsi_Host *shpnt)
+static int sun3scsi_release(struct Scsi_Host *shpnt)
 {
if (shpnt-irq != SCSI_IRQ_NONE)
free_irq(shpnt-irq, shpnt);
Index: linux/drivers/scsi/t128.c
===
--- linux.orig/drivers/scsi/t128.c  2014-11-12 16:10:49.0 +1100
+++ linux/drivers/scsi/t128.c   2014-11-12 16:10:51.0 +1100
@@ -193,7 +193,8 @@ __setup(t128=, t128_setup);
  *
  */
 
-int __init t128_detect(struct scsi_host_template * tpnt){
+static int __init t128_detect(struct scsi_host_template *tpnt)
+{
 static int current_override = 0, current_base = 0;
 struct Scsi_Host *instance;
 unsigned long base;
@@ -325,8 +326,8 @@ static int t128_release(struct Scsi_Host
  * and matching the H_C_S coordinates to what DOS uses.
  */
 
-int t128_biosparam(struct scsi_device *sdev, struct block_device *bdev,
-   sector_t capacity, int * ip)
+static int t128_biosparam(struct scsi_device *sdev, struct block_device *bdev,
+  sector_t capacity, int *ip)
 {
   ip[0] = 64;
   ip[1] = 32;
Index: linux/drivers/scsi/dtc.h
===
--- linux.orig/drivers/scsi/dtc.h   2014-11-12 16:10:43.0 +1100
+++ 

[PATCH v3 29/37] atari_NCR5380: Refactor Falcon locking

2014-11-11 Thread Finn Thain
Simplify falcon_release_lock_if_possible() by making callers responsible for
disabling local IRQ's, which they must do anyway to correctly synchronize
the ST DMA lock with core driver data structures. Move this
synchronization logic to the core driver with which it is tightly coupled.

Other LLD's like sun3_scsi and mac_scsi that can make use of this core
driver can just stub out the NCR5380_acquire_dma_irq() and
NCR5380_release_dma_irq() calls so the compiler will eliminate the
ST DMA code.

Remove a redundant local_irq_save/restore pair (irq's are disabled for
interrupt handlers these days). Revise the locking for
atari_scsi_bus_reset(): use local_irq_save/restore() instead of
atari_turnoff/turnon_irq(). There is no guarantee that atari_scsi still
holds the ST DMA lock during EH, so atari_turnoff/turnon_irq() could
end up dropping an IDE or floppy interrupt.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Tested-by: Michael Schmitz schmitz...@gmail.com
Reviewed-by: Hannes Reinecke h...@suse.de

---
 drivers/scsi/atari_NCR5380.c |   72 ++-
 drivers/scsi/atari_scsi.c|   47 ++--
 2 files changed, 62 insertions(+), 57 deletions(-)

Index: linux/drivers/scsi/atari_NCR5380.c
===
--- linux.orig/drivers/scsi/atari_NCR5380.c 2014-11-12 16:11:32.0 
+1100
+++ linux/drivers/scsi/atari_NCR5380.c  2014-11-12 16:11:34.0 +1100
@@ -925,7 +925,7 @@ static int NCR5380_queue_command(struct
 * because also a timer int can trigger an abort or reset, which would
 * alter queues and touch the lock.
 */
-   if (!falcon_get_lock())
+   if (!NCR5380_acquire_dma_irq(instance))
return SCSI_MLQUEUE_HOST_BUSY;
 
local_irq_save(flags);
@@ -960,6 +960,18 @@ static int NCR5380_queue_command(struct
return 0;
 }
 
+static inline void maybe_release_dma_irq(struct Scsi_Host *instance)
+{
+   struct NCR5380_hostdata *hostdata = shost_priv(instance);
+
+   /* Caller does the locking needed to set  test these data atomically */
+   if (!hostdata-disconnected_queue 
+   !hostdata-issue_queue 
+   !hostdata-connected 
+   !hostdata-retain_dma_intr)
+   NCR5380_release_dma_irq(instance);
+}
+
 /*
  * Function : NCR5380_main (void)
  *
@@ -1082,9 +1094,11 @@ static void NCR5380_main(struct work_str
cmd_get_tag(tmp, tmp-cmnd[0] != 
REQUEST_SENSE);
 #endif
if (!NCR5380_select(instance, tmp)) {
+   local_irq_disable();
hostdata-retain_dma_intr--;
/* release if target did not 
response! */
-   
falcon_release_lock_if_possible(hostdata);
+   maybe_release_dma_irq(instance);
+   local_irq_restore(flags);
break;
} else {
local_irq_disable();
@@ -2083,11 +2097,12 @@ static void NCR5380_information_transfer
case COMMAND_COMPLETE:
/* Accept message by clearing ACK */
NCR5380_write(INITIATOR_COMMAND_REG, 
ICR_BASE);
-   /* ++guenther: possible race with 
Falcon locking */
-   hostdata-retain_dma_intr++;
-   hostdata-connected = NULL;
dprintk(NDEBUG_QUEUES, scsi%d: command 
for target %d, lun %llu 
  completed\n, HOSTNO, 
cmd-device-id, cmd-device-lun);
+
+   local_irq_save(flags);
+   hostdata-retain_dma_intr++;
+   hostdata-connected = NULL;
 #ifdef SUPPORT_TAGS
cmd_free_tag(cmd);
if (status_byte(cmd-SCp.Status) == 
QUEUE_FULL) {
@@ -2146,17 +2161,17 @@ static void NCR5380_information_transfer
 
dprintk(NDEBUG_AUTOSENSE, 
scsi%d: performing request sense\n, HOSTNO);
 
-   local_irq_save(flags);
LIST(cmd,hostdata-issue_queue);
SET_NEXT(cmd, 
hostdata-issue_queue);
hostdata-issue_queue = (struct 
scsi_cmnd *) cmd;
-   local_irq_restore(flags);

[PATCH v3 36/37] atari_NCR5380: Remove RESET_RUN_DONE macro

2014-11-11 Thread Finn Thain
There's no need to run the cmd-done callback for aborted commands. Remove
the old EH code and the RESET_RUN_DONE macro.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---
 drivers/scsi/atari_NCR5380.c |   88 ---
 drivers/scsi/sun3_scsi.c |1 
 2 files changed, 89 deletions(-)

Index: linux/drivers/scsi/atari_NCR5380.c
===
--- linux.orig/drivers/scsi/atari_NCR5380.c 2014-11-12 16:11:42.0 
+1100
+++ linux/drivers/scsi/atari_NCR5380.c  2014-11-12 16:11:43.0 +1100
@@ -2877,9 +2877,6 @@ static int NCR5380_bus_reset(struct scsi
struct NCR5380_hostdata *hostdata = shost_priv(instance);
int i;
unsigned long flags;
-#if defined(RESET_RUN_DONE)
-   struct scsi_cmnd *connected, *disconnected_queue;
-#endif
 
NCR5380_print_status(instance);
 
@@ -2898,89 +2895,6 @@ static int NCR5380_bus_reset(struct scsi
 * through anymore ... */
(void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
 
-   /* MSch 20140115 - looking at the generic NCR5380 driver, all of this
-* should go.
-* Catch-22: if we don't clear all queues, the SCSI driver lock will
-* not be reset by atari_scsi_reset()!
-*/
-
-#if defined(RESET_RUN_DONE)
-   /* XXX Should now be done by midlevel code, but it's broken XXX */
-   /* XXX see belowXXX */
-
-   /* MSch: old-style reset: actually abort all command processing here */
-
-   /* After the reset, there are no more connected or disconnected commands
-* and no busy units; to avoid problems with re-inserting the commands
-* into the issue_queue (via scsi_done()), the aborted commands are
-* remembered in local variables first.
-*/
-   local_irq_save(flags);
-   connected = (struct scsi_cmnd *)hostdata-connected;
-   hostdata-connected = NULL;
-   disconnected_queue = (struct scsi_cmnd *)hostdata-disconnected_queue;
-   hostdata-disconnected_queue = NULL;
-#ifdef SUPPORT_TAGS
-   free_all_tags();
-#endif
-   for (i = 0; i  8; ++i)
-   hostdata-busy[i] = 0;
-#ifdef REAL_DMA
-   hostdata-dma_len = 0;
-#endif
-   local_irq_restore(flags);
-
-   /* In order to tell the mid-level code which commands were aborted,
-* set the command status to DID_RESET and call scsi_done() !!!
-* This ultimately aborts processing of these commands in the mid-level.
-*/
-
-   if ((cmd = connected)) {
-   dprintk(NDEBUG_ABORT, scsi%d: reset aborted a connected 
command\n, H_NO(cmd));
-   cmd-result = (cmd-result  0x) | (DID_RESET  16);
-   cmd-scsi_done(cmd);
-   }
-
-   for (i = 0; (cmd = disconnected_queue); ++i) {
-   disconnected_queue = NEXT(cmd);
-   SET_NEXT(cmd, NULL);
-   cmd-result = (cmd-result  0x) | (DID_RESET  16);
-   cmd-scsi_done(cmd);
-   }
-   if (i  0)
-   dprintk(NDEBUG_ABORT, scsi: reset aborted %d disconnected 
command(s)\n, i);
-
-   /* The Falcon lock should be released after a reset...
-*/
-   /* ++guenther: moved to atari_scsi_reset(), to prevent a race between
-* unlocking and enabling dma interrupt.
-*/
-/* falcon_release_lock_if_possible( hostdata );*/
-
-   /* since all commands have been explicitly terminated, we need to tell
-* the midlevel code that the reset was SUCCESSFUL, and there is no
-* need to 'wake up' the commands by a request_sense
-*/
-   return SUCCESS;
-#else /* 1 */
-
-   /* MSch: new-style reset handling: let the mid-level do what it can */
-
-   /* ++guenther: MID-LEVEL IS STILL BROKEN.
-* Mid-level is supposed to requeue all commands that were active on the
-* various low-level queues. In fact it does this, but that's not enough
-* because all these commands are subject to timeout. And if a timeout
-* happens for any removed command, *_abort() is called but all queues
-* are now empty. Abort then gives up the falcon lock, which is fatal,
-* since the mid-level will queue more commands and must have the lock
-* (it's all happening inside timer interrupt handler!!).
-* Even worse, abort will return NOT_RUNNING for all those commands not
-* on any queue, so they won't be retried ...
-*
-* Conclusion: either scsi.c disables timeout for all resetted commands
-* immediately, or we lose!  As of linux-2.0.20 it doesn't.
-*/
-
/* After the reset, there are no more connected or disconnected commands
 * and no busy units; so clear the low-level status here to avoid
 * conflicts when the mid-level 

[PATCH v3 26/37] sun3_scsi: Move macro definitions

2014-11-11 Thread Finn Thain
The #defines in sun3_scsi.h are intended to influence subsequent #includes
in sun3_scsi.c. IMHO, that's too convoluted.

Move sun3_scsi.h macro definitions to sun3_scsi.c, consistent with other
NCR5380 drivers.

Omit the unused NCR5380_local_declare() and NCR5380_setup() macros.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de

---
 drivers/scsi/sun3_scsi.c |   45 -
 drivers/scsi/sun3_scsi.h |   25 -
 2 files changed, 32 insertions(+), 38 deletions(-)

Index: linux/drivers/scsi/sun3_scsi.c
===
--- linux.orig/drivers/scsi/sun3_scsi.c 2014-11-12 16:11:29.0 +1100
+++ linux/drivers/scsi/sun3_scsi.c  2014-11-12 16:11:30.0 +1100
@@ -33,18 +33,42 @@
 #include asm/io.h
 #include asm/dvma.h
 
-/* dma on! */
-#define REAL_DMA
-
 #include scsi/scsi_host.h
 #include sun3_scsi.h
-#include NCR5380.h
 
-extern int sun3_map_test(unsigned long, char *);
+/* Definitions for the core NCR5380 driver. */
 
-/*#define RESET_BOOT */
+#define REAL_DMA
+#define RESET_RUN_DONE
 /* #define SUPPORT_TAGS */
 
+/* #define MAX_TAGS 32 */
+
+#define NCR5380_implementation_fields   /* none */
+
+#define NCR5380_read(reg)   sun3scsi_read(reg)
+#define NCR5380_write(reg, value)   sun3scsi_write(reg, value)
+
+#define NCR5380_queue_command   sun3scsi_queue_command
+#define NCR5380_bus_reset   sun3scsi_bus_reset
+#define NCR5380_abort   sun3scsi_abort
+#define NCR5380_show_info   sun3scsi_show_info
+#define NCR5380_infosun3scsi_info
+
+#define NCR5380_dma_read_setup(instance, data, count) \
+sun3scsi_dma_setup(data, count, 0)
+#define NCR5380_dma_write_setup(instance, data, count) \
+sun3scsi_dma_setup(data, count, 1)
+#define NCR5380_dma_residual(instance) \
+sun3scsi_dma_residual(instance)
+#define NCR5380_dma_xfer_len(instance, cmd, phase) \
+sun3scsi_dma_xfer_len(cmd-SCp.this_residual, cmd, !((phase)  SR_IO))
+
+#include NCR5380.h
+
+
+extern int sun3_map_test(unsigned long, char *);
+
 #ifdef SUN3_SCSI_VME
 #define ENABLE_IRQ()
 #else
@@ -65,9 +89,7 @@ module_param(setup_use_tagged_queuing, i
 static int setup_hostid = -1;
 module_param(setup_hostid, int, 0);
 
-static struct scsi_cmnd *sun3_dma_setup_done = NULL;
-
-#defineRESET_RUN_DONE
+/* #define RESET_BOOT */
 
 #defineAFTER_RESET_DELAY   (HZ/2)
 
@@ -80,6 +102,7 @@ static struct scsi_cmnd *sun3_dma_setup_
 /* minimum number of bytes to do dma on */
 #define SUN3_DMA_MINSIZE 128
 
+static struct scsi_cmnd *sun3_dma_setup_done;
 static unsigned char *sun3_scsi_regp;
 static volatile struct sun3_dma_regs *dregs;
 static struct sun3_udc_regs *udc_regs;
@@ -131,9 +154,6 @@ static inline void sun3_udc_write(unsign
 static void sun3_scsi_reset_boot(struct Scsi_Host *instance)
 {
unsigned long end;
-
-   NCR5380_local_declare();
-   NCR5380_setup(instance);

/*
 * Do a SCSI reset to clean up the bus during initialization. No
@@ -210,7 +230,6 @@ static irqreturn_t scsi_sun3_intr(int ir
 void sun3_sun3_debug (void)
 {
unsigned long flags;
-   NCR5380_local_declare();
 
if (default_instance) {
local_irq_save(flags);
Index: linux/drivers/scsi/sun3_scsi.h
===
--- linux.orig/drivers/scsi/sun3_scsi.h 2014-11-12 16:11:29.0 +1100
+++ linux/drivers/scsi/sun3_scsi.h  2014-11-12 16:11:30.0 +1100
@@ -18,31 +18,6 @@
 #ifndef SUN3_SCSI_H
 #define SUN3_SCSI_H
 
-#define MAX_TAGS 32
-
-#define NCR5380_implementation_fields /* none */
-
-#define NCR5380_local_declare() \
-struct Scsi_Host *_instance
-
-#define NCR5380_setup(instance) \
-_instance = instance
-
-#define NCR5380_read(reg) sun3scsi_read(reg)
-#define NCR5380_write(reg, value) sun3scsi_write(reg, value)
-
-#define NCR5380_queue_command sun3scsi_queue_command
-#define NCR5380_bus_reset sun3scsi_bus_reset
-#define NCR5380_abort sun3scsi_abort
-#define NCR5380_show_info sun3scsi_show_info
-#define NCR5380_info sun3scsi_info
-#define NCR5380_dma_xfer_len(i, cmd, phase) \
-sun3scsi_dma_xfer_len(cmd-SCp.this_residual,cmd,((phase)  SR_IO) ? 0 
: 1)
-
-#define NCR5380_dma_write_setup(instance, data, count) 
sun3scsi_dma_setup(data, count, 1)
-#define NCR5380_dma_read_setup(instance, data, count) sun3scsi_dma_setup(data, 
count, 0)
-#define NCR5380_dma_residual sun3scsi_dma_residual
-
 /* additional registers - mainly DMA control regs */
 /* these start at regbase + 8 -- directly after the NCR regs */
 struct sun3_dma_regs {


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


[PATCH v3 12/37] ncr5380: Cleanup host info() methods

2014-11-11 Thread Finn Thain
If the host-info() method is not set, then host-name is used by default.
For atari_scsi, that is exactly the same text. So remove the redundant
info() method. Keep sun3_scsi.c in line with atari_scsi.

Some NCR5380 drivers return an empty string from the info() method
(arm/cumana_1.c arm/oak.c mac_scsi.c) while other drivers use the default
(dmx3191d dtc.c g_NCR5380.c pas16.c t128.c).

Implement a common info() method to replace a lot of duplicated code which
the various drivers use to announce the same information.

This replaces most of the (deprecated) show_info() output and all of the
NCR5380_print_info() output. This also eliminates a bunch of code in
g_NCR5380 which just duplicates functionality in the core driver.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---

Changes since v1:
- Dropped explicit NULL termination of snprintf() buffers.

---
 drivers/scsi/NCR5380.c   |   74 ++-
 drivers/scsi/NCR5380.h   |3 
 drivers/scsi/arm/cumana_1.c  |   14 
 drivers/scsi/arm/oak.c   |   14 
 drivers/scsi/atari_NCR5380.c |   57 +++---
 drivers/scsi/atari_scsi.c|   24 ---
 drivers/scsi/atari_scsi.h|1 
 drivers/scsi/dmx3191d.c  |1 
 drivers/scsi/dtc.c   |   10 ---
 drivers/scsi/dtc.h   |1 
 drivers/scsi/g_NCR5380.c |  135 ---
 drivers/scsi/g_NCR5380.h |2 
 drivers/scsi/mac_scsi.c  |   14 
 drivers/scsi/mac_scsi.h  |1 
 drivers/scsi/pas16.c |   12 ---
 drivers/scsi/pas16.h |1 
 drivers/scsi/sun3_NCR5380.c  |   59 +++---
 drivers/scsi/sun3_scsi.c |   18 -
 drivers/scsi/sun3_scsi.h |1 
 drivers/scsi/t128.c  |   11 ---
 drivers/scsi/t128.h  |1 
 21 files changed, 134 insertions(+), 320 deletions(-)

Index: linux/drivers/scsi/arm/cumana_1.c
===
--- linux.orig/drivers/scsi/arm/cumana_1.c  2014-11-12 16:10:57.0 
+1100
+++ linux/drivers/scsi/arm/cumana_1.c   2014-11-12 16:11:06.0 +1100
@@ -29,6 +29,7 @@
 #define NCR5380_write(reg, value)  cumanascsi_write(_instance, reg, value)
 #define NCR5380_intr   cumanascsi_intr
 #define NCR5380_queue_command  cumanascsi_queue_command
+#define NCR5380_info   cumanascsi_info
 
 #define NCR5380_implementation_fields  \
unsigned ctrl;  \
@@ -41,11 +42,6 @@ void cumanascsi_setup(char *str, int *in
 {
 }
 
-const char *cumanascsi_info(struct Scsi_Host *spnt)
-{
-   return ;
-}
-
 #define CTRL   0x16fc
 #define STAT   0x2004
 #define L(v)   (((v)16)|((v)  0x))
@@ -266,14 +262,6 @@ static int cumanascsi1_probe(struct expa
goto out_unmap;
}
 
-   printk(scsi%d: at port 0x%08lx irq %d,
-   host-host_no, host-io_port, host-irq);
-   printk( options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d,
-   host-can_queue, host-cmd_per_lun, CUMANASCSI_PUBLIC_RELEASE);
-   printk(\nscsi%d:, host-host_no);
-   NCR5380_print_options(host);
-   printk(\n);
-
ret = scsi_add_host(host, ec-dev);
if (ret)
goto out_free_irq;
Index: linux/drivers/scsi/arm/oak.c
===
--- linux.orig/drivers/scsi/arm/oak.c   2014-11-12 16:11:02.0 +1100
+++ linux/drivers/scsi/arm/oak.c2014-11-12 16:11:06.0 +1100
@@ -29,6 +29,7 @@
 #define NCR5380_read(reg)  readb(_base + ((reg)  2))
 #define NCR5380_write(reg, value)  writeb(value, _base + ((reg)  2))
 #define NCR5380_queue_command  oakscsi_queue_command
+#define NCR5380_info   oakscsi_info
 #define NCR5380_show_info  oakscsi_show_info
 #define NCR5380_write_info oakscsi_write_info
 
@@ -40,11 +41,6 @@
 #undef START_DMA_INITIATOR_RECEIVE_REG
 #define START_DMA_INITIATOR_RECEIVE_REG(128 + 7)
 
-const char * oakscsi_info (struct Scsi_Host *spnt)
-{
-   return ;
-}
-
 #define STAT   ((128 + 16)  2)
 #define DATA   ((128 + 8)  2)
 
@@ -153,14 +149,6 @@ static int oakscsi_probe(struct expansio
 
NCR5380_init(host, 0);
 
-   printk(scsi%d: at port 0x%08lx irqs disabled,
-   host-host_no, host-io_port);
-   printk( options CAN_QUEUE=%d  CMD_PER_LUN=%d release=%d,
-   host-can_queue, host-cmd_per_lun, OAKSCSI_PUBLIC_RELEASE);
-   printk(\nscsi%d:, host-host_no);
-   NCR5380_print_options(host);
-   printk(\n);
-
ret = scsi_add_host(host, ec-dev);
if (ret)
goto out_unmap;
Index: linux/drivers/scsi/atari_scsi.c
===
--- linux.orig/drivers/scsi/atari_scsi.c2014-11-12 16:10:57.0 
+1100
+++ 

[PATCH v3 11/37] ncr5380: Remove NCR5380_STATS

2014-11-11 Thread Finn Thain
The NCR5380_STATS option is only enabled by g_NCR5380 yet it adds
clutter to all three core drivers. The atari_NCR5380.c and sun3_NCR5380.c
core drivers have a slightly different implementation of the
NCR5380_STATS option.

Out of all ten NCR5380 drivers, only one of them (g_NCR5380) actually
has the code to report on the collected stats. Aside from being unreadable,
that code seems to be broken because there's no initialization of timebase.
sun3_NCR5380.c and atari_NCR5380.c have the timebase initialization but
lack the code to report the stats.

Remove all of this code to improve readability and reduce divergence
between the three core drivers.

This patch and the next one completely eliminate the PRINTP and ANDP
pre-processor abuse.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---
 drivers/scsi/NCR5380.c   |   64 ---
 drivers/scsi/NCR5380.h   |9 -
 drivers/scsi/atari_NCR5380.c |   65 
 drivers/scsi/g_NCR5380.c |   45 
 drivers/scsi/sun3_NCR5380.c  |   69 ---
 5 files changed, 252 deletions(-)

Index: linux/drivers/scsi/NCR5380.c
===
--- linux.orig/drivers/scsi/NCR5380.c   2014-11-12 16:11:02.0 +1100
+++ linux/drivers/scsi/NCR5380.c2014-11-12 16:11:04.0 +1100
@@ -833,18 +833,6 @@ static int NCR5380_init(struct Scsi_Host

INIT_DELAYED_WORK(hostdata-coroutine, NCR5380_main);

-#ifdef NCR5380_STATS
-   for (i = 0; i  8; ++i) {
-   hostdata-time_read[i] = 0;
-   hostdata-time_write[i] = 0;
-   hostdata-bytes_read[i] = 0;
-   hostdata-bytes_write[i] = 0;
-   }
-   hostdata-timebase = 0;
-   hostdata-pendingw = 0;
-   hostdata-pendingr = 0;
-#endif
-
/* The CHECK code seems to break the 53C400. Will check it later maybe 
*/
if (flags  FLAG_NCR53C400)
hostdata-flags = FLAG_HAS_LAST_BYTE_SENT | flags;
@@ -943,25 +931,6 @@ static int NCR5380_queue_command_lck(Scs
}
 #endif /* (NDEBUG  NDEBUG_NO_WRITE) */
 
-#ifdef NCR5380_STATS
-   switch (cmd-cmnd[0]) {
-   case WRITE:
-   case WRITE_6:
-   case WRITE_10:
-   hostdata-time_write[cmd-device-id] -= (jiffies - 
hostdata-timebase);
-   hostdata-bytes_write[cmd-device-id] += 
scsi_bufflen(cmd);
-   hostdata-pendingw++;
-   break;
-   case READ:
-   case READ_6:
-   case READ_10:
-   hostdata-time_read[cmd-device-id] -= (jiffies - 
hostdata-timebase);
-   hostdata-bytes_read[cmd-device-id] += 
scsi_bufflen(cmd);
-   hostdata-pendingr++;
-   break;
-   }
-#endif
-
/* 
 * We use the host_scribble field as a pointer to the next command  
 * in a queue 
@@ -1207,35 +1176,6 @@ static irqreturn_t NCR5380_intr(int dumm
 
 #endif 
 
-/**
- * collect_stats   -   collect stats on a scsi command
- * @hostdata: adapter 
- * @cmd: command being issued
- *
- * Update the statistical data by parsing the command in question
- */
- 
-static void collect_stats(struct NCR5380_hostdata *hostdata, Scsi_Cmnd * cmd) 
-{
-#ifdef NCR5380_STATS
-   switch (cmd-cmnd[0]) {
-   case WRITE:
-   case WRITE_6:
-   case WRITE_10:
-   hostdata-time_write[scmd_id(cmd)] += (jiffies - 
hostdata-timebase);
-   hostdata-pendingw--;
-   break;
-   case READ:
-   case READ_6:
-   case READ_10:
-   hostdata-time_read[scmd_id(cmd)] += (jiffies - 
hostdata-timebase);
-   hostdata-pendingr--;
-   break;
-   }
-#endif
-}
-
-
 /* 
  * Function : int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd)
  *
@@ -1464,7 +1404,6 @@ part2:
return -1;
}
cmd-result = DID_BAD_TARGET  16;
-   collect_stats(hostdata, cmd);
cmd-scsi_done(cmd);
NCR5380_write(SELECT_ENABLE_REG, hostdata-id_mask);
dprintk(NDEBUG_SELECTION, scsi%d : target did not respond 
within 250ms\n, instance-host_no);
@@ -2216,7 +2155,6 @@ static void NCR5380_information_transfer
cmd-next_link-tag = cmd-tag;
cmd-result = cmd-SCp.Status | 
(cmd-SCp.Message  8);
dprintk(NDEBUG_LINKED, scsi%d : target 
%d lun %llu linked request done, calling scsi_done().\n, instance-host_no, 
cmd-device-id, cmd-device-lun);
-  

[PATCH v3 33/37] atari_NCR5380: Introduce FLAG_TAGGED_QUEUING

2014-11-11 Thread Finn Thain
The static variable setup_use_tagged_queuing is declared in mac_scsi.c,
sun3_scsi.c and atari_scsi.c and doesn't belong in the core driver.
None of the other NCR5380 drivers suffer from this layering issue which
makes merging the core drivers more difficult and will likely hinder plans
for future use of platform data to configure the driver.

Replace the static variable with a host flag. This way it can be reported
along with the other flags.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---
 drivers/scsi/NCR5380.h   |1 +
 drivers/scsi/atari_NCR5380.c |   22 +-
 drivers/scsi/atari_scsi.c|8 
 drivers/scsi/mac_scsi.c  |8 
 drivers/scsi/sun3_scsi.c |   12 ++--
 5 files changed, 28 insertions(+), 23 deletions(-)

Index: linux/drivers/scsi/NCR5380.h
===
--- linux.orig/drivers/scsi/NCR5380.h   2014-11-12 16:11:32.0 +1100
+++ linux/drivers/scsi/NCR5380.h2014-11-12 16:11:39.0 +1100
@@ -242,6 +242,7 @@
 #define FLAG_NO_PSEUDO_DMA 8   /* Inhibit DMA */
 #define FLAG_DTC3181E  16  /* DTC3181E */
 #define FLAG_LATE_DMA_SETUP32  /* Setup NCR before DMA H/W */
+#define FLAG_TAGGED_QUEUING64  /* as X3T9.2 spelled it */
 
 #ifndef ASM
 struct NCR5380_hostdata {
Index: linux/drivers/scsi/atari_NCR5380.c
===
--- linux.orig/drivers/scsi/atari_NCR5380.c 2014-11-12 16:11:38.0 
+1100
+++ linux/drivers/scsi/atari_NCR5380.c  2014-11-12 16:11:39.0 +1100
@@ -283,12 +283,12 @@ typedef struct {
 static TAG_ALLOC TagAlloc[8][8];   /* 8 targets and 8 LUNs */
 
 
-static void __init init_tags(void)
+static void __init init_tags(struct NCR5380_hostdata *hostdata)
 {
int target, lun;
TAG_ALLOC *ta;
 
-   if (!setup_use_tagged_queuing)
+   if (!(hostdata-flags  FLAG_TAGGED_QUEUING))
return;
 
for (target = 0; target  8; ++target) {
@@ -321,7 +321,8 @@ static int is_lun_busy(struct scsi_cmnd
if (hostdata-busy[cmd-device-id]  (1  lun))
return 1;
if (!should_be_tagged ||
-   !setup_use_tagged_queuing || !cmd-device-tagged_supported)
+   !(hostdata-flags  FLAG_TAGGED_QUEUING) ||
+   !cmd-device-tagged_supported)
return 0;
if (TagAlloc[cmd-device-id][lun].nr_allocated =
TagAlloc[cmd-device-id][lun].queue_size) {
@@ -347,7 +348,8 @@ static void cmd_get_tag(struct scsi_cmnd
 * an untagged command.
 */
if (!should_be_tagged ||
-   !setup_use_tagged_queuing || !cmd-device-tagged_supported) {
+   !(hostdata-flags  FLAG_TAGGED_QUEUING) ||
+   !cmd-device-tagged_supported) {
cmd-tag = TAG_NONE;
hostdata-busy[cmd-device-id] |= (1  lun);
dprintk(NDEBUG_TAGS, scsi%d: target %d lun %d now allocated by 
untagged 
@@ -392,12 +394,12 @@ static void cmd_free_tag(struct scsi_cmn
 }
 
 
-static void free_all_tags(void)
+static void free_all_tags(struct NCR5380_hostdata *hostdata)
 {
int target, lun;
TAG_ALLOC *ta;
 
-   if (!setup_use_tagged_queuing)
+   if (!(hostdata-flags  FLAG_TAGGED_QUEUING))
return;
 
for (target = 0; target  8; ++target) {
@@ -653,11 +655,13 @@ static void prepare_info(struct Scsi_Hos
 base 0x%lx, irq %d, 
 can_queue %d, cmd_per_lun %d, 
 sg_tablesize %d, this_id %d, 
+flags { %s}, 
 options { %s} ,
 instance-hostt-name, instance-io_port, instance-n_io_port,
 instance-base, instance-irq,
 instance-can_queue, instance-cmd_per_lun,
 instance-sg_tablesize, instance-this_id,
+hostdata-flags  FLAG_TAGGED_QUEUING ? TAGGED_QUEUING  : ,
 #ifdef DIFFERENTIAL
 DIFFERENTIAL 
 #endif
@@ -799,7 +803,7 @@ static int __init NCR5380_init(struct Sc
for (i = 0; i  8; ++i)
hostdata-busy[i] = 0;
 #ifdef SUPPORT_TAGS
-   init_tags();
+   init_tags(hostdata);
 #endif
 #if defined (REAL_DMA)
hostdata-dma_len = 0;
@@ -2565,7 +2569,7 @@ static void NCR5380_reselect(struct Scsi
 * SIMPLE_QUEUE_TAG for the I_T_L_Q nexus.
 */
tag = TAG_NONE;
-   if (phase == PHASE_MSGIN  setup_use_tagged_queuing) {
+   if (phase == PHASE_MSGIN  (hostdata-flags  FLAG_TAGGED_QUEUING)) {
/* Accept previous IDENTIFY message by clearing ACK */
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
len = 2;
@@ -3021,7 +3025,7 @@ static int NCR5380_bus_reset(struct scsi
hostdata-connected = NULL;

[PATCH v3 37/37] atari_NCR5380: Fix transfered typo

2014-11-11 Thread Finn Thain
Signed-off-by: Finn Thain fth...@telegraphics.com.au

---
 drivers/scsi/atari_NCR5380.c |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

Index: linux/drivers/scsi/atari_NCR5380.c
===
--- linux.orig/drivers/scsi/atari_NCR5380.c 2014-11-12 16:11:43.0 
+1100
+++ linux/drivers/scsi/atari_NCR5380.c  2014-11-12 16:11:44.0 +1100
@@ -1105,7 +1105,7 @@ static void NCR5380_main(struct work_str
 static void NCR5380_dma_complete(struct Scsi_Host *instance)
 {
SETUP_HOSTDATA(instance);
-   int transfered;
+   int transferred;
unsigned char **data;
volatile int *count;
int saved_data = 0, overrun = 0;
@@ -1157,13 +1157,13 @@ static void NCR5380_dma_complete(struct
NCR5380_write(MODE_REG, MR_BASE);
NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
 
-   transfered = hostdata-dma_len - NCR5380_dma_residual(instance);
+   transferred = hostdata-dma_len - NCR5380_dma_residual(instance);
hostdata-dma_len = 0;
 
data = (unsigned char **)hostdata-connected-SCp.ptr;
count = hostdata-connected-SCp.this_residual;
-   *data += transfered;
-   *count -= transfered;
+   *data += transferred;
+   *count -= transferred;
 
if (hostdata-read_overruns) {
int cnt, toPIO;


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


[PATCH v3 24/37] atari_scsi: Remove header

2014-11-11 Thread Finn Thain
The #defines in atari_scsi.h are intended to influence subsequent #includes
in atari_scsi.c. IMHO, that's too convoluted.

Remove atari_scsi.h by moving those macro definitions to atari_scsi.c,
consistent with other NCR5380 drivers.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---
 drivers/scsi/atari_scsi.c |   35 ++-
 drivers/scsi/atari_scsi.h |   40 
 2 files changed, 26 insertions(+), 49 deletions(-)

Index: linux/drivers/scsi/atari_scsi.c
===
--- linux.orig/drivers/scsi/atari_scsi.c2014-11-12 16:11:26.0 
+1100
+++ linux/drivers/scsi/atari_scsi.c 2014-11-12 16:11:28.0 +1100
@@ -64,15 +64,7 @@
 /**/
 
 
-
 #include linux/module.h
-
-/* For the Atari version, use only polled IO or REAL_DMA */
-#defineREAL_DMA
-/* Support tagged queuing? (on devices that are able to... :-) */
-#defineSUPPORT_TAGS
-#defineMAX_TAGS 32
-
 #include linux/types.h
 #include linux/delay.h
 #include linux/blkdev.h
@@ -92,9 +84,34 @@
 
 #include scsi/scsi_host.h
 
-#include atari_scsi.h
+/* Definitions for the core NCR5380 driver. */
+
+#define REAL_DMA
+#define SUPPORT_TAGS
+#define MAX_TAGS32
+
+#define NCR5380_implementation_fields   /* none */
+
+#define NCR5380_read(reg)   atari_scsi_reg_read(reg)
+#define NCR5380_write(reg, value)   atari_scsi_reg_write(reg, value)
+
+#define NCR5380_queue_command   atari_scsi_queue_command
+#define NCR5380_abort   atari_scsi_abort
+#define NCR5380_show_info   atari_scsi_show_info
+#define NCR5380_infoatari_scsi_info
+
+#define NCR5380_dma_read_setup(instance, data, count) \
+atari_scsi_dma_setup(instance, data, count, 0)
+#define NCR5380_dma_write_setup(instance, data, count) \
+atari_scsi_dma_setup(instance, data, count, 1)
+#define NCR5380_dma_residual(instance) \
+atari_scsi_dma_residual(instance)
+#define NCR5380_dma_xfer_len(instance, cmd, phase) \
+atari_dma_xfer_len(cmd-SCp.this_residual, cmd, !((phase)  SR_IO))
+
 #include NCR5380.h
 
+
 #defineIS_A_TT()   ATARIHW_PRESENT(TT_SCSI)
 
 #defineSCSI_DMA_WRITE_P(elt,val)   \
Index: linux/drivers/scsi/atari_scsi.h
===
--- linux.orig/drivers/scsi/atari_scsi.h2014-11-12 16:11:26.0 
+1100
+++ /dev/null   1970-01-01 00:00:00.0 +
@@ -1,40 +0,0 @@
-/*
- * atari_scsi.h -- Header file for the Atari native SCSI driver
- *
- * Copyright 1994 Roman Hodek roman.ho...@informatik.uni-erlangen.de
- *
- * (Loosely based on the work of Robert De Vries' team)
- *
- * This file is subject to the terms and conditions of the GNU General Public
- * License.  See the file COPYING in the main directory of this archive
- * for more details.
- *
- */
-
-
-#ifndef ATARI_SCSI_H
-#define ATARI_SCSI_H
-
-/* (I_HAVE_OVERRUNS stuff removed) */
-
-#ifndef ASM
-
-#defineNCR5380_implementation_fields   /* none */
-
-#define NCR5380_read(reg)atari_scsi_reg_read( reg )
-#define NCR5380_write(reg, value) atari_scsi_reg_write( reg, value )
-
-#define NCR5380_queue_command atari_scsi_queue_command
-#define NCR5380_abort atari_scsi_abort
-#define NCR5380_show_info atari_scsi_show_info
-#define NCR5380_info atari_scsi_info
-#define NCR5380_dma_read_setup(inst,d,c) atari_scsi_dma_setup (inst, d, c, 0)
-#define NCR5380_dma_write_setup(inst,d,c) atari_scsi_dma_setup (inst, d, c, 1)
-#define NCR5380_dma_residual(inst) atari_scsi_dma_residual( inst )
-#defineNCR5380_dma_xfer_len(i,cmd,phase) \
-   atari_dma_xfer_len(cmd-SCp.this_residual,cmd,((phase)  SR_IO) ? 0 : 1)
-
-#endif /* ndef ASM */
-#endif /* ATARI_SCSI_H */
-
-


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


[PATCH v3 13/37] ncr5380: Move static PDMA spin counters to host data

2014-11-11 Thread Finn Thain
Static variables from dtc.c and pas16.c should not appear in the core
NCR5380.c driver. Aside from being a layering issue this worsens the
divergence between the three core driver variants (atari_NCR5380.c and
sun3_NCR5380.c don't support PSEUDO_DMA) and it can mean multiple hosts
share the same counters.

Fix this by making the pseudo DMA spin counters in the core more generic.
This also avoids the abuse of the {DTC,PAS16}_PUBLIC_RELEASE macros, so
they can be removed.

oak.c doesn't use PDMA and hence it doesn't use the counters and hence it
needs no write_info() method. Remove it.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---
 drivers/scsi/NCR5380.c |   22 ++
 drivers/scsi/NCR5380.h |4 
 drivers/scsi/arm/oak.c |2 --
 drivers/scsi/dtc.c |   13 ++---
 drivers/scsi/pas16.c   |   12 ++--
 5 files changed, 26 insertions(+), 27 deletions(-)

Index: linux/drivers/scsi/NCR5380.c
===
--- linux.orig/drivers/scsi/NCR5380.c   2014-11-12 16:11:06.0 +1100
+++ linux/drivers/scsi/NCR5380.c2014-11-12 16:11:10.0 +1100
@@ -692,6 +692,7 @@ static void NCR5380_print_status(struct
NCR5380_dprint_phase(NDEBUG_ANY, instance);
 }
 
+#ifdef PSEUDO_DMA
 /**/
 /*
  * /proc/scsi/[dtc pas16 t128 generic]/[0-ASC_NUM_BOARD_SUPPORTED]
@@ -709,14 +710,13 @@ static void NCR5380_print_status(struct
 static int __maybe_unused NCR5380_write_info(struct Scsi_Host *instance,
char *buffer, int length)
 {
-#ifdef DTC_PUBLIC_RELEASE
-   dtc_wmaxi = dtc_maxi = 0;
-#endif
-#ifdef PAS16_PUBLIC_RELEASE
-   pas_wmaxi = pas_maxi = 0;
-#endif
-   return (-ENOSYS);   /* Currently this is a no-op */
+   struct NCR5380_hostdata *hostdata = shost_priv(instance);
+
+   hostdata-spin_max_r = 0;
+   hostdata-spin_max_w = 0;
+   return 0;
 }
+#endif
 
 #undef SPRINTF
 #define SPRINTF(args...) seq_printf(m, ## args)
@@ -751,11 +751,9 @@ static int __maybe_unused NCR5380_show_i
SPRINTF(PAS16 release=%d, PAS16_PUBLIC_RELEASE);
 #endif
 
-#ifdef DTC_PUBLIC_RELEASE
-   SPRINTF(Highwater I/O busy_spin_counts -- write: %d  read: %d\n, 
dtc_wmaxi, dtc_maxi);
-#endif
-#ifdef PAS16_PUBLIC_RELEASE
-   SPRINTF(Highwater I/O busy_spin_counts -- write: %d  read: %d\n, 
pas_wmaxi, pas_maxi);
+#ifdef PSEUDO_DMA
+   SPRINTF(Highwater I/O busy spin counts: write %d, read %d\n,
+   hostdata-spin_max_w, hostdata-spin_max_r);
 #endif
spin_lock_irq(instance-host_lock);
if (!hostdata-connected)
Index: linux/drivers/scsi/NCR5380.h
===
--- linux.orig/drivers/scsi/NCR5380.h   2014-11-12 16:11:06.0 +1100
+++ linux/drivers/scsi/NCR5380.h2014-11-12 16:11:10.0 +1100
@@ -274,6 +274,10 @@ struct NCR5380_hostdata {
struct delayed_work coroutine;  /* our co-routine */
struct scsi_eh_save ses;
char info[256];
+#ifdef PSEUDO_DMA
+   unsigned spin_max_r;
+   unsigned spin_max_w;
+#endif
 };
 
 #ifdef __KERNEL__
Index: linux/drivers/scsi/dtc.c
===
--- linux.orig/drivers/scsi/dtc.c   2014-11-12 16:11:06.0 +1100
+++ linux/drivers/scsi/dtc.c2014-11-12 16:11:10.0 +1100
@@ -332,13 +332,11 @@ static int dtc_biosparam(struct scsi_dev
  * timeout.
 */
 
-static int dtc_maxi = 0;
-static int dtc_wmaxi = 0;
-
 static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char 
*dst, int len)
 {
unsigned char *d = dst;
int i;  /* For counting time spent in the poll-loop */
+   struct NCR5380_hostdata *hostdata = shost_priv(instance);
NCR5380_local_declare();
NCR5380_setup(instance);
 
@@ -369,8 +367,8 @@ static inline int NCR5380_pread(struct S
NCR5380_write(MODE_REG, 0); /* Clear the operating mode */
rtrc(0);
NCR5380_read(RESET_PARITY_INTERRUPT_REG);
-   if (i  dtc_maxi)
-   dtc_maxi = i;
+   if (i  hostdata-spin_max_r)
+   hostdata-spin_max_r = i;
return (0);
 }
 
@@ -390,6 +388,7 @@ static inline int NCR5380_pread(struct S
 static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char 
*src, int len)
 {
int i;
+   struct NCR5380_hostdata *hostdata = shost_priv(instance);
NCR5380_local_declare();
NCR5380_setup(instance);
 
@@ -422,8 +421,8 @@ static inline int NCR5380_pwrite(struct
/* Check for parity error here. fixme. */
NCR5380_write(MODE_REG, 0); /* Clear the operating mode */
rtrc(0);
-   if (i  dtc_wmaxi)
-   dtc_wmaxi = i;
+   if (i  hostdata-spin_max_w)
+   hostdata-spin_max_w = i;

[PATCH v3 17/37] dmx3191d: Use NO_IRQ

2014-11-11 Thread Finn Thain
Testing shows that the Domex 3191D card never asserts its IRQ. Hence it is
non-functional with Linux (worse, the EH bugs in the core driver are fatal
but that's a problem for another patch). Perhaps the DT-536 chip needs
special setup? I can't find documentation for it. The NetBSD driver uses
polling apparently because of this issue.

Set host-irq = NO_IRQ so the core driver will prevent targets from
disconnecting. Don't request host-irq.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de

---

Changes since v1:
- Use NO_IRQ instead of IRQ_NONE.

---
 drivers/scsi/dmx3191d.c |   25 -
 1 file changed, 8 insertions(+), 17 deletions(-)

Index: linux/drivers/scsi/dmx3191d.c
===
--- linux.orig/drivers/scsi/dmx3191d.c  2014-11-12 16:11:16.0 +1100
+++ linux/drivers/scsi/dmx3191d.c   2014-11-12 16:11:19.0 +1100
@@ -34,6 +34,8 @@
  * Definitions for the generic 5380 driver.
  */
 
+#define DONT_USE_INTR
+
 #define NCR5380_read(reg)  inb(port + reg)
 #define NCR5380_write(reg, value)  outb(value, port + reg)
 
@@ -89,32 +91,23 @@ static int dmx3191d_probe_one(struct pci
if (!shost)
goto out_release_region;   
shost-io_port = io;
-   shost-irq = pdev-irq;
 
-   NCR5380_init(shost, FLAG_NO_PSEUDO_DMA | FLAG_DTC3181E);
+   /* This card does not seem to raise an interrupt on pdev-irq.
+* Steam-powered SCSI controllers run without an IRQ anyway.
+*/
+   shost-irq = NO_IRQ;
 
-   if (request_irq(pdev-irq, NCR5380_intr, IRQF_SHARED,
-   DMX3191D_DRIVER_NAME, shost)) {
-   /*
-* Steam powered scsi controllers run without an IRQ anyway
-*/
-   printk(KERN_WARNING dmx3191: IRQ %d not available - 
-   switching to polled mode.\n, pdev-irq);
-   shost-irq = NO_IRQ;
-   }
+   NCR5380_init(shost, FLAG_NO_PSEUDO_DMA | FLAG_DTC3181E);
 
pci_set_drvdata(pdev, shost);
 
error = scsi_add_host(shost, pdev-dev);
if (error)
-   goto out_free_irq;
+   goto out_release_region;
 
scsi_scan_host(shost);
return 0;
 
- out_free_irq:
-   if (shost-irq != NO_IRQ)
-   free_irq(shost-irq, shost);
  out_release_region:
release_region(io, DMX3191D_REGION_LEN);
  out_disable_device:
@@ -131,8 +124,6 @@ static void dmx3191d_remove_one(struct p
 
NCR5380_exit(shost);
 
-   if (shost-irq != NO_IRQ)
-   free_irq(shost-irq, shost);
release_region(shost-io_port, DMX3191D_REGION_LEN);
pci_disable_device(pdev);
 


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


[PATCH v3 31/37] sun3_scsi: Adopt atari_NCR5380 core driver and remove sun3_NCR5380.c

2014-11-11 Thread Finn Thain
Given the preceding changes to atari_NCR5380.c, this patch should not change
behaviour of the sun3_scsi and sun3_scsi_vme modules.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de

---
 MAINTAINERS |1 
 drivers/scsi/sun3_NCR5380.c | 2849 
 drivers/scsi/sun3_scsi.c|   10 
 3 files changed, 6 insertions(+), 2854 deletions(-)

Index: linux/drivers/scsi/sun3_scsi.c
===
--- linux.orig/drivers/scsi/sun3_scsi.c 2014-11-12 16:11:31.0 +1100
+++ linux/drivers/scsi/sun3_scsi.c  2014-11-12 16:11:37.0 +1100
@@ -41,6 +41,8 @@
 #define REAL_DMA
 #define RESET_RUN_DONE
 /* #define SUPPORT_TAGS */
+/* minimum number of bytes to do dma on */
+#define DMA_MIN_SIZE129
 
 /* #define MAX_TAGS 32 */
 
@@ -64,6 +66,9 @@
 #define NCR5380_dma_xfer_len(instance, cmd, phase) \
 sun3scsi_dma_xfer_len(cmd-SCp.this_residual, cmd, !((phase)  SR_IO))
 
+#define NCR5380_acquire_dma_irq(instance)(1)
+#define NCR5380_release_dma_irq(instance)
+
 #include NCR5380.h
 
 
@@ -92,9 +97,6 @@ module_param(setup_hostid, int, 0);
 /* dvma buffer to allocate -- 32k should hopefully be more than sufficient */
 #define SUN3_DVMA_BUFSIZE 0xe000
 
-/* minimum number of bytes to do dma on */
-#define SUN3_DMA_MINSIZE 128
-
 static struct scsi_cmnd *sun3_dma_setup_done;
 static unsigned char *sun3_scsi_regp;
 static volatile struct sun3_dma_regs *dregs;
@@ -486,7 +488,7 @@ static int sun3scsi_dma_finish(int write
 
 }

-#include sun3_NCR5380.c
+#include atari_NCR5380.c
 
 #ifdef SUN3_SCSI_VME
 #define SUN3_SCSI_NAME  Sun3 NCR5380 VME SCSI
Index: linux/MAINTAINERS
===
--- linux.orig/MAINTAINERS  2014-11-12 16:10:42.0 +1100
+++ linux/MAINTAINERS   2014-11-12 16:11:37.0 +1100
@@ -6171,7 +6171,6 @@ F:drivers/scsi/g_NCR5380.*
 F: drivers/scsi/g_NCR5380_mmio.c
 F: drivers/scsi/mac_scsi.*
 F: drivers/scsi/pas16.*
-F: drivers/scsi/sun3_NCR5380.c
 F: drivers/scsi/sun3_scsi.*
 F: drivers/scsi/sun3_scsi_vme.c
 F: drivers/scsi/t128.*
Index: linux/drivers/scsi/sun3_NCR5380.c
===
--- linux.orig/drivers/scsi/sun3_NCR5380.c  2014-11-12 16:11:31.0 
+1100
+++ /dev/null   1970-01-01 00:00:00.0 +
@@ -1,2849 +0,0 @@
-/* sun3_NCR5380.c -- adapted from atari_NCR5380.c for the sun3 by 
-   Sam Creasey. */ 
-/* 
- * NCR 5380 generic driver routines.  These should make it *trivial*
- * to implement 5380 SCSI drivers under Linux with a non-trantor
- * architecture.
- *
- * Note that these routines also work with NR53c400 family chips.
- *
- * Copyright 1993, Drew Eckhardt
- * Visionary Computing 
- * (Unix and Linux consulting and custom programming)
- * d...@colorado.edu
- * +1 (303) 666-5836
- *
- * For more information, please consult 
- *
- * NCR 5380 Family
- * SCSI Protocol Controller
- * Databook
- *
- * NCR Microelectronics
- * 1635 Aeroplaza Drive
- * Colorado Springs, CO 80916
- * 1+ (719) 578-3400
- * 1+ (800) 334-5454
- */
-
-/*
- * ++roman: To port the 5380 driver to the Atari, I had to do some changes in
- * this file, too:
- *
- *  - Some of the debug statements were incorrect (undefined variables and the
- *like). I fixed that.
- *
- *  - In information_transfer(), I think a #ifdef was wrong. Looking at the
- *possible DMA transfer size should also happen for REAL_DMA. I added this
- *in the #if statement.
- *
- *  - When using real DMA, information_transfer() should return in a DATAOUT
- *phase after starting the DMA. It has nothing more to do.
- *
- *  - The interrupt service routine should run main after end of DMA, too (not
- *only after RESELECTION interrupts). Additionally, it should _not_ test
- *for more interrupts after running main, since a DMA process may have
- *been started and interrupts are turned on now. The new int could happen
- *inside the execution of NCR5380_intr(), leading to recursive
- *calls.
- *
- * - I've deleted all the stuff for AUTOPROBE_IRQ, REAL_DMA_POLL, PSEUDO_DMA
- *and USLEEP, because these were messing up readability and will never be
- *needed for Atari SCSI.
- * 
- * - I've revised the NCR5380_main() calling scheme (relax the 'main_running'
- *   stuff), and 'main' is executed in a bottom half if awoken by an
- *   interrupt.
- *
- * - The code was quite cluttered up by #if (NDEBUG  NDEBUG_*) printk...
- *   constructs. In my eyes, this made the source rather unreadable, so I
- *   finally replaced that by the *_PRINTK() macros.
- *
- */
-#include scsi/scsi_dbg.h
-#include scsi/scsi_transport_spi.h
-
-/*
- * Further development / testing that should be done : 
- * 1.  Test linked command 

[PATCH v3 19/37] mac_scsi: Add module option to Kconfig

2014-11-11 Thread Finn Thain
Allow mac_scsi to be built as a module. Replace the old validation of
__setup options with code that validates both module and __setup options.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de

---
 drivers/scsi/Kconfig|2 
 drivers/scsi/mac_scsi.c |  112 +++-
 2 files changed, 38 insertions(+), 76 deletions(-)

Index: linux/drivers/scsi/Kconfig
===
--- linux.orig/drivers/scsi/Kconfig 2014-11-12 16:10:43.0 +1100
+++ linux/drivers/scsi/Kconfig  2014-11-12 16:11:21.0 +1100
@@ -1595,7 +1595,7 @@ config ATARI_SCSI_RESET_BOOT
  that leave the devices with SCSI operations partway completed.
 
 config MAC_SCSI
-   bool Macintosh NCR5380 SCSI
+   tristate Macintosh NCR5380 SCSI
depends on MAC  SCSI=y
select SCSI_SPI_ATTRS
help
Index: linux/drivers/scsi/mac_scsi.c
===
--- linux.orig/drivers/scsi/mac_scsi.c  2014-11-12 16:11:20.0 +1100
+++ linux/drivers/scsi/mac_scsi.c   2014-11-12 16:11:21.0 +1100
@@ -62,15 +62,18 @@
 static void mac_scsi_reset_boot(struct Scsi_Host *instance);
 #endif
 
-static int setup_called = 0;
 static int setup_can_queue = -1;
+module_param(setup_can_queue, int, 0);
 static int setup_cmd_per_lun = -1;
+module_param(setup_cmd_per_lun, int, 0);
 static int setup_sg_tablesize = -1;
+module_param(setup_sg_tablesize, int, 0);
 static int setup_use_pdma = -1;
-#ifdef SUPPORT_TAGS
+module_param(setup_use_pdma, int, 0);
 static int setup_use_tagged_queuing = -1;
-#endif
+module_param(setup_use_tagged_queuing, int, 0);
 static int setup_hostid = -1;
+module_param(setup_hostid, int, 0);
 
 /* Time (in jiffies) to wait after a reset; the SCSI standard calls for 250ms,
  * we usually do 0.5s to be on the safe side. But Toshiba CD-ROMs once more
@@ -102,72 +105,34 @@ static __inline__ void macscsi_write(str
   out_8(instance-io_port + (reg4), value);
 }
 
-/*
- * Function : mac_scsi_setup(char *str)
- *
- * Purpose : booter command line initialization of the overrides array,
- *
- * Inputs : str - comma delimited list of options
- *
- */
-
-static int __init mac_scsi_setup(char *str) {
+#ifndef MODULE
+static int __init mac_scsi_setup(char *str)
+{
int ints[7];
-   
-   (void)get_options( str, ARRAY_SIZE(ints), ints);
-   
-   if (setup_called++ || ints[0]  1 || ints[0]  6) {
-   printk(KERN_WARNING scsi: mac5380
-Usage: 
mac5380=can_queue[,cmd_per_lun,sg_tablesize,hostid,use_tags,use_pdma]\n);
-   printk(KERN_ALERT scsi: mac5380 Bad Penguin parameters?\n);
-   return 0;
-   }
-   
-   if (ints[0] = 1) {
-   if (ints[1]  0)
-   /* no limits on this, just  0 */
-   setup_can_queue = ints[1];
-   }
-   if (ints[0] = 2) {
-   if (ints[2]  0)
-   setup_cmd_per_lun = ints[2];
-   }
-   if (ints[0] = 3) {
-   if (ints[3] = 0) {
-   setup_sg_tablesize = ints[3];
-   /* Must be = SG_ALL (255) */
-   if (setup_sg_tablesize  SG_ALL)
-   setup_sg_tablesize = SG_ALL;
-   }
-   }
-   if (ints[0] = 4) {
-   /* Must be between 0 and 7 */
-   if (ints[4] = 0  ints[4] = 7)
-   setup_hostid = ints[4];
-   else if (ints[4]  7)
-   printk(KERN_WARNING mac_scsi_setup: invalid host ID %d 
!\n, ints[4] );
-   }
-#ifdef SUPPORT_TAGS
-   if (ints[0] = 5) {
-   if (ints[5] = 0)
-   setup_use_tagged_queuing = !!ints[5];
+
+   (void)get_options(str, ARRAY_SIZE(ints), ints);
+
+   if (ints[0]  1 || ints[0]  6) {
+   pr_err(Usage: 
mac5380=can_queue[,cmd_per_lun[,sg_tablesize[,hostid[,use_tags[,use_pdma]\n);
+   return 0;
}
-   
-   if (ints[0] == 6) {
-   if (ints[6] = 0)
+   if (ints[0] = 1)
+   setup_can_queue = ints[1];
+   if (ints[0] = 2)
+   setup_cmd_per_lun = ints[2];
+   if (ints[0] = 3)
+   setup_sg_tablesize = ints[3];
+   if (ints[0] = 4)
+   setup_hostid = ints[4];
+   if (ints[0] = 5)
+   setup_use_tagged_queuing = ints[5];
+   if (ints[0] = 6)
setup_use_pdma = ints[6];
-   }
-#else
-   if (ints[0] == 5) {
-   if (ints[5] = 0)
-   setup_use_pdma = ints[5];
-   }
-#endif /* SUPPORT_TAGS */
-   
return 1;
 }
 
 __setup(mac5380=, mac_scsi_setup);
+#endif /* !MODULE */
 
 /*
  * Function : int macscsi_detect(struct scsi_host_template * tpnt)
@@ -199,13 +164,8 @@ int __init macscsi_detect(struct scsi_ho

[PATCH v3 25/37] sun3_scsi: Convert to platform device

2014-11-11 Thread Finn Thain
Convert sun3_scsi to platform device and eliminate scsi_register().

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Acked-by: Geert Uytterhoeven ge...@linux-m68k.org

---

Changes since v1:
- Use NO_IRQ instead of IRQ_NONE.
- Move device IRQ and address constants to platform resources.
- Test idprom-id_machtype before registering platform device instead of
  during platform driver probe.
- Omit pointless instance-n_io_port assignment.

Changes since v2:
- Give more precise addresses in platform resource initializers and
  move PAGE_SIZE back to ioremap() arguments.

---
 arch/m68k/sun3/config.c  |   60 +++
 drivers/scsi/sun3_scsi.c |  390 ++-
 drivers/scsi/sun3_scsi.h |   17 --
 3 files changed, 245 insertions(+), 222 deletions(-)

Index: linux/arch/m68k/sun3/config.c
===
--- linux.orig/arch/m68k/sun3/config.c  2014-11-12 16:10:43.0 +1100
+++ linux/arch/m68k/sun3/config.c   2014-11-12 16:11:29.0 +1100
@@ -16,6 +16,7 @@
 #include linux/console.h
 #include linux/init.h
 #include linux/bootmem.h
+#include linux/platform_device.h
 
 #include asm/oplib.h
 #include asm/setup.h
@@ -27,6 +28,7 @@
 #include asm/sun3mmu.h
 #include asm/rtc.h
 #include asm/machdep.h
+#include asm/machines.h
 #include asm/idprom.h
 #include asm/intersil.h
 #include asm/irq.h
@@ -169,3 +171,61 @@ static void __init sun3_sched_init(irq_h
 intersil_clear();
 }
 
+#ifdef CONFIG_SUN3_SCSI
+
+static const struct resource sun3_scsi_vme_rsrc[] __initconst = {
+   {
+   .flags = IORESOURCE_IRQ,
+   .start = SUN3_VEC_VMESCSI0,
+   .end   = SUN3_VEC_VMESCSI0,
+   }, {
+   .flags = IORESOURCE_MEM,
+   .start = 0xff20,
+   .end   = 0xff200021,
+   }, {
+   .flags = IORESOURCE_IRQ,
+   .start = SUN3_VEC_VMESCSI1,
+   .end   = SUN3_VEC_VMESCSI1,
+   }, {
+   .flags = IORESOURCE_MEM,
+   .start = 0xff204000,
+   .end   = 0xff204021,
+   },
+};
+
+/*
+ * Int: level 2 autovector
+ * IO: type 1, base 0x0014, 5 bits phys space: A4..0
+ */
+static const struct resource sun3_scsi_rsrc[] __initconst = {
+   {
+   .flags = IORESOURCE_IRQ,
+   .start = 2,
+   .end   = 2,
+   }, {
+   .flags = IORESOURCE_MEM,
+   .start = 0x0014,
+   .end   = 0x0014001f,
+   },
+};
+
+int __init sun3_platform_init(void)
+{
+   switch (idprom-id_machtype) {
+   case SM_SUN3 | SM_3_160:
+   case SM_SUN3 | SM_3_260:
+   platform_device_register_simple(sun3_scsi_vme, -1,
+   sun3_scsi_vme_rsrc, ARRAY_SIZE(sun3_scsi_vme_rsrc));
+   break;
+   case SM_SUN3 | SM_3_50:
+   case SM_SUN3 | SM_3_60:
+   platform_device_register_simple(sun3_scsi, -1,
+   sun3_scsi_rsrc, ARRAY_SIZE(sun3_scsi_rsrc));
+   break;
+   }
+   return 0;
+}
+
+arch_initcall(sun3_platform_init);
+
+#endif
Index: linux/drivers/scsi/sun3_scsi.c
===
--- linux.orig/drivers/scsi/sun3_scsi.c 2014-11-12 16:11:16.0 +1100
+++ linux/drivers/scsi/sun3_scsi.c  2014-11-12 16:11:29.0 +1100
@@ -23,22 +23,15 @@
  */
 
 #include linux/types.h
-#include linux/stddef.h
-#include linux/ctype.h
 #include linux/delay.h
-
 #include linux/module.h
-#include linux/signal.h
 #include linux/ioport.h
 #include linux/init.h
 #include linux/blkdev.h
+#include linux/platform_device.h
 
 #include asm/io.h
-
-#include asm/sun3ints.h
 #include asm/dvma.h
-#include asm/idprom.h
-#include asm/machines.h
 
 /* dma on! */
 #define REAL_DMA
@@ -59,8 +52,6 @@ extern int sun3_map_test(unsigned long,
 #endif
 
 
-static irqreturn_t scsi_sun3_intr(int irq, void *dummy);
-
 static int setup_can_queue = -1;
 module_param(setup_can_queue, int, 0);
 static int setup_cmd_per_lun = -1;
@@ -89,15 +80,14 @@ static struct scsi_cmnd *sun3_dma_setup_
 /* minimum number of bytes to do dma on */
 #define SUN3_DMA_MINSIZE 128
 
-static volatile unsigned char *sun3_scsi_regp;
+static unsigned char *sun3_scsi_regp;
 static volatile struct sun3_dma_regs *dregs;
-#ifndef SUN3_SCSI_VME
-static struct sun3_udc_regs *udc_regs = NULL;
-#endif
+static struct sun3_udc_regs *udc_regs;
 static unsigned char *sun3_dma_orig_addr = NULL;
 static unsigned long sun3_dma_orig_count = 0;
 static int sun3_dma_active = 0;
 static unsigned long last_residual = 0;
+static struct Scsi_Host *default_instance;
 
 /*
  * NCR 5380 register access functions
@@ -105,12 +95,12 @@ static unsigned long last_residual = 0;
 
 static inline unsigned char sun3scsi_read(int reg)
 {
-   return( sun3_scsi_regp[reg] );
+   return in_8(sun3_scsi_regp + reg);
 }
 
 

[PATCH v3 35/37] atari_NCR5380: Move static co-routine variables to host data

2014-11-11 Thread Finn Thain
Unlike NCR5380.c, the atari_NCR5380.c core driver is limited to a single
instance because co-routine state is stored globally.

Fix this by removing the static scsi host pointer. For the co-routine,
obtain this pointer from the work_struct pointer instead. For the interrupt
handler, obtain it from the dev_id argument.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---
 drivers/scsi/NCR5380.h   |2 +
 drivers/scsi/atari_NCR5380.c |   61 +++
 drivers/scsi/atari_scsi.c|8 ++---
 3 files changed, 28 insertions(+), 43 deletions(-)

Index: linux/drivers/scsi/NCR5380.h
===
--- linux.orig/drivers/scsi/NCR5380.h   2014-11-12 16:11:41.0 +1100
+++ linux/drivers/scsi/NCR5380.h2014-11-12 16:11:42.0 +1100
@@ -283,6 +283,8 @@ struct NCR5380_hostdata {
int read_overruns;/* number of bytes to cut from a
   * transfer to handle chip overruns */
int retain_dma_intr;
+   struct work_struct main_task;
+   volatile int main_running;
 #ifdef SUPPORT_TAGS
struct tag_alloc TagAlloc[8][8];/* 8 targets and 8 LUNs */
 #endif
Index: linux/drivers/scsi/atari_NCR5380.c
===
--- linux.orig/drivers/scsi/atari_NCR5380.c 2014-11-12 16:11:41.0 
+1100
+++ linux/drivers/scsi/atari_NCR5380.c  2014-11-12 16:11:42.0 +1100
@@ -221,9 +221,6 @@
  * possible) function may be used.
  */
 
-static struct Scsi_Host *first_instance = NULL;
-static struct scsi_host_template *the_template = NULL;
-
 /* Macros ease life... :-) */
 #defineSETUP_HOSTDATA(in)  \
 struct NCR5380_hostdata *hostdata =\
@@ -595,32 +592,19 @@ static void NCR5380_print_phase(struct S
 #include linux/workqueue.h
 #include linux/interrupt.h
 
-static volatile int main_running;
-static DECLARE_WORK(NCR5380_tqueue, NCR5380_main);
-
-static inline void queue_main(void)
+static inline void queue_main(struct NCR5380_hostdata *hostdata)
 {
-   if (!main_running) {
+   if (!hostdata-main_running) {
/* If in interrupt and NCR5380_main() not already running,
   queue it on the 'immediate' task queue, to be processed
   immediately after the current interrupt processing has
   finished. */
-   schedule_work(NCR5380_tqueue);
+   schedule_work(hostdata-main_task);
}
/* else: nothing to do: the running NCR5380_main() will pick up
   any newly queued command. */
 }
 
-
-static inline void NCR5380_all_init(void)
-{
-   static int done = 0;
-   if (!done) {
-   dprintk(NDEBUG_INIT, scsi : NCR5380_all_init()\n);
-   done = 1;
-   }
-}
-
 /**
  * NCR58380_info - report driver and host information
  * @instance: relevant scsi host instance
@@ -703,7 +687,7 @@ static void NCR5380_print_status(struct
 
local_irq_save(flags);
printk(NCR5380: coroutine is%s running.\n,
-   main_running ?  : n't);
+   hostdata-main_running ?  : n't);
if (!hostdata-connected)
printk(scsi%d: no currently connected command\n, HOSTNO);
else
@@ -746,7 +730,7 @@ static int __maybe_unused NCR5380_show_i
 
local_irq_save(flags);
seq_printf(m, NCR5380: coroutine is%s running.\n,
-   main_running ?  : n't);
+   hostdata-main_running ?  : n't);
if (!hostdata-connected)
seq_printf(m, scsi%d: no currently connected command\n, 
HOSTNO);
else
@@ -783,8 +767,7 @@ static int __init NCR5380_init(struct Sc
int i;
SETUP_HOSTDATA(instance);
 
-   NCR5380_all_init();
-
+   hostdata-host = instance;
hostdata-aborted = 0;
hostdata-id_mask = 1  instance-this_id;
hostdata-id_higher_mask = 0;
@@ -805,10 +788,7 @@ static int __init NCR5380_init(struct Sc
hostdata-disconnected_queue = NULL;
hostdata-flags = flags;
 
-   if (!the_template) {
-   the_template = instance-hostt;
-   first_instance = instance;
-   }
+   INIT_WORK(hostdata-main_task, NCR5380_main);
 
prepare_info(instance);
 
@@ -829,7 +809,9 @@ static int __init NCR5380_init(struct Sc
 
 static void NCR5380_exit(struct Scsi_Host *instance)
 {
-   cancel_work_sync(NCR5380_tqueue);
+   struct NCR5380_hostdata *hostdata = shost_priv(instance);
+
+   cancel_work_sync(hostdata-main_task);
 }
 
 /**
@@ -924,9 +906,9 @@ static int NCR5380_queue_command(struct
 * unconditionally, because it cannot be already running.
 */
if (in_interrupt() || irqs_disabled())
-   queue_main();

[PATCH v3 27/37] ncr5380: Remove ENABLE_IRQ/DISABLE_IRQ macros

2014-11-11 Thread Finn Thain
atari_NCR5380.c enables its IRQ when it is already enabled. Sun3 doesn't
use the ENABLE_IRQ/DISABLE_IRQ cruft. Remove it.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---
 drivers/scsi/atari_NCR5380.c |2 --
 drivers/scsi/atari_scsi.c|   21 -
 drivers/scsi/sun3_NCR5380.c  |2 --
 drivers/scsi/sun3_scsi.c |7 ---
 4 files changed, 32 deletions(-)

Index: linux/drivers/scsi/atari_NCR5380.c
===
--- linux.orig/drivers/scsi/atari_NCR5380.c 2014-11-12 16:11:25.0 
+1100
+++ linux/drivers/scsi/atari_NCR5380.c  2014-11-12 16:11:31.0 +1100
@@ -1227,7 +1227,6 @@ static irqreturn_t NCR5380_intr(int irq,
NCR5380_dprint(NDEBUG_INTR, instance);
if ((NCR5380_read(STATUS_REG)  (SR_SEL|SR_IO)) == 
(SR_SEL|SR_IO)) {
done = 0;
-   ENABLE_IRQ();
dprintk(NDEBUG_INTR, scsi%d: SEL interrupt\n, HOSTNO);
NCR5380_reselect(instance);
(void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
@@ -1257,7 +1256,6 @@ static irqreturn_t NCR5380_intr(int irq,
dprintk(NDEBUG_INTR, scsi%d: PHASE MISM or EOP 
interrupt\n, HOSTNO);
NCR5380_dma_complete( instance );
done = 0;
-   ENABLE_IRQ();
} else
 #endif /* REAL_DMA */
{
Index: linux/drivers/scsi/atari_scsi.c
===
--- linux.orig/drivers/scsi/atari_scsi.c2014-11-12 16:11:28.0 
+1100
+++ linux/drivers/scsi/atari_scsi.c 2014-11-12 16:11:31.0 +1100
@@ -157,23 +157,6 @@ static inline unsigned long SCSI_DMA_GET
return adr;
 }
 
-static inline void ENABLE_IRQ(void)
-{
-   if (IS_A_TT())
-   atari_enable_irq(IRQ_TT_MFP_SCSI);
-   else
-   atari_enable_irq(IRQ_MFP_FSCSI);
-}
-
-static inline void DISABLE_IRQ(void)
-{
-   if (IS_A_TT())
-   atari_disable_irq(IRQ_TT_MFP_SCSI);
-   else
-   atari_disable_irq(IRQ_MFP_FSCSI);
-}
-
-
 #define HOSTDATA_DMALEN(((struct NCR5380_hostdata *) \
(atari_scsi_host-hostdata))-dma_len)
 
@@ -373,10 +356,6 @@ static irqreturn_t scsi_tt_intr(int irq,
 
NCR5380_intr(irq, dummy);
 
-#if 0
-   /* To be sure the int is not masked */
-   atari_enable_irq(IRQ_TT_MFP_SCSI);
-#endif
return IRQ_HANDLED;
 }
 
Index: linux/drivers/scsi/sun3_NCR5380.c
===
--- linux.orig/drivers/scsi/sun3_NCR5380.c  2014-11-12 16:11:16.0 
+1100
+++ linux/drivers/scsi/sun3_NCR5380.c   2014-11-12 16:11:31.0 +1100
@@ -1155,7 +1155,6 @@ static irqreturn_t NCR5380_intr (int irq
NCR5380_dprint(NDEBUG_INTR, instance);
if ((NCR5380_read(STATUS_REG)  (SR_SEL|SR_IO)) == (SR_SEL|SR_IO)) {
done = 0;
-// ENABLE_IRQ();
dprintk(NDEBUG_INTR, scsi%d: SEL interrupt\n, HOSTNO);
NCR5380_reselect(instance);
(void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
@@ -1188,7 +1187,6 @@ static irqreturn_t NCR5380_intr (int irq
dprintk(NDEBUG_INTR, scsi%d: PHASE MISM or EOP interrupt\n, 
HOSTNO);
NCR5380_dma_complete( instance );
done = 0;
-// ENABLE_IRQ();
} else
 #endif /* REAL_DMA */
{
Index: linux/drivers/scsi/sun3_scsi.c
===
--- linux.orig/drivers/scsi/sun3_scsi.c 2014-11-12 16:11:30.0 +1100
+++ linux/drivers/scsi/sun3_scsi.c  2014-11-12 16:11:31.0 +1100
@@ -69,13 +69,6 @@
 
 extern int sun3_map_test(unsigned long, char *);
 
-#ifdef SUN3_SCSI_VME
-#define ENABLE_IRQ()
-#else
-#defineENABLE_IRQ()enable_irq( IRQ_SUN3_SCSI ); 
-#endif
-
-
 static int setup_can_queue = -1;
 module_param(setup_can_queue, int, 0);
 static int setup_cmd_per_lun = -1;


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


[PATCH v3 20/37] mac_scsi: Cleanup PDMA code

2014-11-11 Thread Finn Thain
Fix whitespace, remove pointless volatile qualifiers and improve code style
by use of INPUT_DATA_REG and OUTPUT_DATA_REG macros.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de

---
 drivers/scsi/mac_scsi.c |  122 
 1 file changed, 62 insertions(+), 60 deletions(-)

Index: linux/drivers/scsi/mac_scsi.c
===
--- linux.orig/drivers/scsi/mac_scsi.c  2014-11-12 16:11:21.0 +1100
+++ linux/drivers/scsi/mac_scsi.c   2014-11-12 16:11:22.0 +1100
@@ -86,9 +86,9 @@ module_param(setup_hostid, int, 0);
 #defineAFTER_RESET_DELAY   (HZ/2)
 #endif
 
-static volatile unsigned char *mac_scsi_regp = NULL;
-static volatile unsigned char *mac_scsi_drq  = NULL;
-static volatile unsigned char *mac_scsi_nodrq = NULL;
+static unsigned char *mac_scsi_regp;
+static unsigned char *mac_scsi_drq;
+static unsigned char *mac_scsi_nodrq;
 
 
 /*
@@ -262,6 +262,7 @@ static void mac_scsi_reset_boot(struct S
 }
 #endif
 
+#ifdef PSEUDO_DMA
 /* 
Pseudo-DMA: (Ove Edlund)
The code attempts to catch bus errors that occur if one for example
@@ -331,38 +332,38 @@ __asm__ __volatile__  
\
  : 0(s), 1(d), 2(len)\
  : d0)
 
-
-static int macscsi_pread (struct Scsi_Host *instance,
- unsigned char *dst, int len)
+static int macscsi_pread(struct Scsi_Host *instance,
+ unsigned char *dst, int len)
 {
-   unsigned char *d;
-   volatile unsigned char *s;
+   unsigned char *d;
+   unsigned char *s;
+
+   NCR5380_local_declare();
+   NCR5380_setup(instance);
+
+   s = mac_scsi_drq + (INPUT_DATA_REG  4);
+   d = dst;
 
-   NCR5380_local_declare();
-   NCR5380_setup(instance);
+   /* These conditions are derived from MacOS */
 
-   s = mac_scsi_drq+0x60;
-   d = dst;
+   while (!(NCR5380_read(BUS_AND_STATUS_REG)  BASR_DRQ) 
+  !(NCR5380_read(STATUS_REG)  SR_REQ))
+   ;
+
+   if (!(NCR5380_read(BUS_AND_STATUS_REG)  BASR_DRQ) 
+   (NCR5380_read(BUS_AND_STATUS_REG)  BASR_PHASE_MATCH)) {
+   pr_err(Error in macscsi_pread\n);
+   return -1;
+   }
 
-/* These conditions are derived from MacOS */
-
-   while (!(NCR5380_read(BUS_AND_STATUS_REG)  BASR_DRQ) 
-  !(NCR5380_read(STATUS_REG)  SR_REQ))
-  ;
-   if (!(NCR5380_read(BUS_AND_STATUS_REG)  BASR_DRQ) 
-  (NCR5380_read(BUS_AND_STATUS_REG)  BASR_PHASE_MATCH)) {
-  printk(KERN_ERR Error in macscsi_pread\n);
-  return -1;
-   }
-
-   CP_IO_TO_MEM(s, d, len);
-   
-   if (len != 0) {
-  printk(KERN_NOTICE Bus error in macscsi_pread\n);
-  return -1;
-   }
-   
-   return 0;
+   CP_IO_TO_MEM(s, d, len);
+
+   if (len != 0) {
+   pr_notice(Bus error in macscsi_pread\n);
+   return -1;
+   }
+
+   return 0;
 }
 
 
@@ -424,39 +425,40 @@ __asm__ __volatile__  
\
  : 0(s), 1(d), 2(len)\
  : d0)
 
-static int macscsi_pwrite (struct Scsi_Host *instance,
- unsigned char *src, int len)
+static int macscsi_pwrite(struct Scsi_Host *instance,
+  unsigned char *src, int len)
 {
-   unsigned char *s;
-   volatile unsigned char *d;
+   unsigned char *s;
+   unsigned char *d;
+
+   NCR5380_local_declare();
+   NCR5380_setup(instance);
 
-   NCR5380_local_declare();
-   NCR5380_setup(instance);
+   s = src;
+   d = mac_scsi_drq + (OUTPUT_DATA_REG  4);
 
-   s = src;
-   d = mac_scsi_drq;
-   
-/* These conditions are derived from MacOS */
-
-   while (!(NCR5380_read(BUS_AND_STATUS_REG)  BASR_DRQ) 
-  (!(NCR5380_read(STATUS_REG)  SR_REQ) 
-|| (NCR5380_read(BUS_AND_STATUS_REG)  BASR_PHASE_MATCH))) 
-  ;
-   if (!(NCR5380_read(BUS_AND_STATUS_REG)  BASR_DRQ)) {
-  printk(KERN_ERR Error in macscsi_pwrite\n);
-  return -1;
-   }
-
-   CP_MEM_TO_IO(s, d, len);   
-
-   if (len != 0) {
-  printk(KERN_NOTICE Bus error in macscsi_pwrite\n);
-  return -1;
-   }
-   
-   return 0;
-}
+   /* These conditions are derived from MacOS */
+
+   while (!(NCR5380_read(BUS_AND_STATUS_REG)  BASR_DRQ) 
+  (!(NCR5380_read(STATUS_REG)  SR_REQ) ||
+   (NCR5380_read(BUS_AND_STATUS_REG)  BASR_PHASE_MATCH)))
+   ;
+
+   if (!(NCR5380_read(BUS_AND_STATUS_REG)  BASR_DRQ)) {
+   pr_err(Error in macscsi_pwrite\n);
+   return -1;
+   }
+
+   CP_MEM_TO_IO(s, d, len);
 
+   if (len != 0) {
+   pr_notice(Bus error in macscsi_pwrite\n);
+   return -1;
+   }
+
+   return 0;
+}
+#endif
 
 #include NCR5380.c
 


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

[PATCH v3 32/37] atari_NCR5380: Merge from NCR5380.c

2014-11-11 Thread Finn Thain
The NCR5380.c core driver has moved on since the atari_NCR5380.c fork.
Some of those changes are also relevant to atari_NCR5380.c so apply them
there as well.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---
 drivers/scsi/atari_NCR5380.c |  209 +--
 1 file changed, 87 insertions(+), 122 deletions(-)

Index: linux/drivers/scsi/atari_NCR5380.c
===
--- linux.orig/drivers/scsi/atari_NCR5380.c 2014-11-12 16:11:35.0 
+1100
+++ linux/drivers/scsi/atari_NCR5380.c  2014-11-12 16:11:38.0 +1100
@@ -104,27 +104,7 @@
 
 /*
  * Design
- * Issues :
  *
- * The other Linux SCSI drivers were written when Linux was Intel PC-only,
- * and specifically for each board rather than each chip.  This makes their
- * adaptation to platforms like the Mac (Some of which use NCR5380's)
- * more difficult than it has to be.
- *
- * Also, many of the SCSI drivers were written before the command queuing
- * routines were implemented, meaning their implementations of queued
- * commands were hacked on rather than designed in from the start.
- *
- * When I designed the Linux SCSI drivers I figured that
- * while having two different SCSI boards in a system might be useful
- * for debugging things, two of the same type wouldn't be used.
- * Well, I was wrong and a number of users have mailed me about running
- * multiple high-performance SCSI boards in a server.
- *
- * Finally, when I get questions from users, I have no idea what
- * revision of my driver they are running.
- *
- * This driver attempts to address these problems :
  * This is a generic 5380 driver.  To use it on a different platform,
  * one simply writes appropriate system specific macros (ie, data
  * transfer - some PC's will use the I/O bus, 68K's must use
@@ -139,11 +119,6 @@
  * allowing multiple commands to propagate all the way to a SCSI-II device
  * while a command is already executing.
  *
- * To solve the multiple-boards-in-the-same-system problem,
- * there is a separate instance structure for each instance
- * of a 5380 in the system.  So, multiple NCR5380 drivers will
- * be able to coexist with appropriate changes to the high level
- * SCSI code.
  *
  * Issues specific to the NCR5380 :
  *
@@ -168,19 +143,17 @@
  * Architecture :
  *
  * At the heart of the design is a coroutine, NCR5380_main,
- * which is started when not running by the interrupt handler,
- * timer, and queue command function.  It attempts to establish
- * I_T_L or I_T_L_Q nexuses by removing the commands from the
- * issue queue and calling NCR5380_select() if a nexus
- * is not established.
+ * which is started from a workqueue for each NCR5380 host in the
+ * system.  It attempts to establish I_T_L or I_T_L_Q nexuses by
+ * removing the commands from the issue queue and calling
+ * NCR5380_select() if a nexus is not established.
  *
  * Once a nexus is established, the NCR5380_information_transfer()
  * phase goes through the various phases as instructed by the target.
  * if the target goes into MSG IN and sends a DISCONNECT message,
  * the command structure is placed into the per instance disconnected
- * queue, and NCR5380_main tries to find more work.  If USLEEP
- * was defined, and the target is idle for too long, the system
- * will try to sleep.
+ * queue, and NCR5380_main tries to find more work.  If the target is
+ * idle for too long, the system will try to sleep.
  *
  * If a command has disconnected, eventually an interrupt will trigger,
  * calling NCR5380_intr()  which will in turn call NCR5380_reselect
@@ -206,6 +179,9 @@
  * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically
  * for commands that return with a CHECK CONDITION status.
  *
+ * DIFFERENTIAL - if defined, NCR53c81 chips will use external differential
+ * transceivers.
+ *
  * LINKED - if defined, linked commands are supported.
  *
  * REAL_DMA - if defined, REAL DMA is used during the data transfer phases.
@@ -218,6 +194,9 @@
  *
  * NCR5380_write(register, value) - write to the specific register
  *
+ * NCR5380_implementation_fields  - additional fields needed for this
+ *  specific implementation of the NCR5380
+ *
  * Either real DMA *or* pseudo DMA may be implemented
  * REAL functions :
  * NCR5380_REAL_DMA should be defined if real DMA is to be used.
@@ -236,20 +215,6 @@
  * NCR5380_pwrite(instance, src, count)
  * NCR5380_pread(instance, dst, count);
  *
- * If nothing specific to this implementation needs doing (ie, with external
- * hardware), you must also define
- *
- * NCR5380_queue_command
- * NCR5380_reset
- * NCR5380_abort
- *
- * to be the global entry points into the specific driver, ie
- * #define NCR5380_queue_command t128_queue_command.
- *
- * If this is not done, the routines will be defined as static functions
- * with the NCR5380* 

[PATCH v3 30/37] atari_NCR5380: Merge from sun3_NCR5380.c

2014-11-11 Thread Finn Thain
There is very little difference between the sun3_NCR5380.c core driver
and atari_NCR5380.c. The former is a fork of the latter.

Merge the sun3_NCR5380.c core driver into atari_NCR5380.c so that
sun3_scsi.c can adopt the latter and the former can be deleted.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---

This patch brings some undesirable #ifdef's to atari_NCR5380. It's a small
price to pay for the elimination of so much duplication. Eventually, with
some testing, it should be possible to remove many of these.

Elimination of the SUN3_SCSI_VME macro is necessary to reach the goal of a
single platform driver to replace the {atari,mac,sun3,sun3_vme}_scsi modules.

Elimination of the #ifdef CONFIG_SUN3 tests is not necessary. But some of
these would go away if the sun3 driver followed the atari logic more
closely, such as use of PIO vs DMA for certain phases and transfer sizes.

After applying this patch it is easy to compare the new atari_NCR5380.c
with sun3_NCR5380.c, to check that they are equivalent. E.g.

$ cp drivers/scsi/{sun3,atari}_NCR5380.c /tmp
$ sed -i -e 's/  *$//'  /tmp/{sun3,atari}_NCR5380.c
$ scripts/Lindent -l96 -hnl /tmp/{sun3,atari}_NCR5380.c
$ meld  /tmp/{sun3,atari}_NCR5380.c

One can see that the two implementations of tagged command queueing have
diverged since the fork. The atari version has been updated and the sun3
implementation is unused as sun3_scsi.c does not define SUPPORT_TAGS.

The remaining differences are merge_contiguous_buffers() and the falcon
locking code. The falcon code disappears when suitable macro definitions are
provided in sun3_scsi.c. merge_contiguous_buffers() could be a problem
for sun3 (due to a DMA setup in an odd place) so it is #ifdef'd for sun3
until the DMA setup discrepancies can be reconciled or moved out of
the core driver.

Changes since v2:
- Remove email addresses from error messages.

---
 drivers/scsi/atari_NCR5380.c |  208 +++
 drivers/scsi/atari_scsi.c|1 
 2 files changed, 193 insertions(+), 16 deletions(-)

Index: linux/drivers/scsi/atari_NCR5380.c
===
--- linux.orig/drivers/scsi/atari_NCR5380.c 2014-11-12 16:11:34.0 
+1100
+++ linux/drivers/scsi/atari_NCR5380.c  2014-11-12 16:11:35.0 +1100
@@ -71,6 +71,9 @@
  * 1.  Test linked command handling code after Eric is ready with
  * the high level code.
  */
+
+/* Adapted for the sun3 by Sam Creasey. */
+
 #include scsi/scsi_dbg.h
 #include scsi/scsi_transport_spi.h
 
@@ -458,6 +461,7 @@ static void free_all_tags(void)
 
 static void merge_contiguous_buffers(struct scsi_cmnd *cmd)
 {
+#if !defined(CONFIG_SUN3)
unsigned long endaddr;
 #if (NDEBUG  NDEBUG_MERGING)
unsigned long oldlen = cmd-SCp.this_residual;
@@ -482,6 +486,7 @@ static void merge_contiguous_buffers(str
dprintk(NDEBUG_MERGING, merged %d buffers from %p, new length 
%08x\n,
   cnt, cmd-SCp.ptr, cmd-SCp.this_residual);
 #endif
+#endif /* !defined(CONFIG_SUN3) */
 }
 
 /*
@@ -1041,12 +1046,10 @@ static void NCR5380_main(struct work_str
 prev = NULL; tmp; prev = tmp, tmp = NEXT(tmp)) {
u8 lun = tmp-device-lun;
 
-#if (NDEBUG  NDEBUG_LISTS)
-   if (prev != tmp)
-   printk(MAIN tmp=%p   target=%d   
busy=%d lun=%llu\n,
-  tmp, tmp-device-id, 
hostdata-busy[tmp-device-id],
-  lun);
-#endif
+   dprintk(NDEBUG_LISTS,
+   MAIN tmp=%p target=%d busy=%d 
lun=%d\n,
+   tmp, scmd_id(tmp), 
hostdata-busy[scmd_id(tmp)],
+   lun);
/*  When we find one, remove it from the issue 
queue. */
/* ++guenther: possible race with Falcon 
locking */
if (
@@ -1155,9 +1158,11 @@ static void NCR5380_main(struct work_str
 static void NCR5380_dma_complete(struct Scsi_Host *instance)
 {
SETUP_HOSTDATA(instance);
-   int transfered, saved_data = 0, overrun = 0, cnt, toPIO;
-   unsigned char **data, p;
+   int transfered;
+   unsigned char **data;
volatile int *count;
+   int saved_data = 0, overrun = 0;
+   unsigned char p;
 
if (!hostdata-connected) {
printk(KERN_WARNING scsi%d: received end of DMA interrupt with 

@@ -1183,6 +1188,24 @@ static void NCR5380_dma_complete(struct
   HOSTNO, NCR5380_read(BUS_AND_STATUS_REG),
   NCR5380_read(STATUS_REG));
 
+#if defined(CONFIG_SUN3)
+   if 

[PATCH v3 09/37] ncr5380: Remove duplicate comments

2014-11-11 Thread Finn Thain
The LIMIT_TRANSFERSIZE, PSEUDO_DMA, PARITY and UNSAFE options are all
documented in the core drivers where they are used. The same goes for the
chip databook reference. Remove the duplicate comments.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de

---
 drivers/scsi/dtc.c   |   17 +
 drivers/scsi/dtc.h   |   16 
 drivers/scsi/g_NCR5380.c |   16 
 drivers/scsi/g_NCR5380.h |   12 
 drivers/scsi/mac_scsi.c  |   12 
 drivers/scsi/mac_scsi.h  |   12 
 drivers/scsi/pas16.c |   31 ---
 drivers/scsi/pas16.h |   12 
 drivers/scsi/sun3_scsi.c |   21 -
 drivers/scsi/sun3_scsi.h |   12 
 drivers/scsi/t128.c  |   23 ---
 drivers/scsi/t128.h  |   12 
 12 files changed, 1 insertion(+), 195 deletions(-)

Index: linux/drivers/scsi/dtc.c
===
--- linux.orig/drivers/scsi/dtc.c   2014-11-12 16:10:57.0 +1100
+++ linux/drivers/scsi/dtc.c2014-11-12 16:10:59.0 +1100
@@ -19,24 +19,9 @@
  *  +1 (303) 440-4894
  *
  * DISTRIBUTION RELEASE 1.
- *
- * For more information, please consult 
- *
- * NCR 5380 Family
- * SCSI Protocol Controller
- * Databook
-*/
+ */
 
 /*
- * Options : 
- * PSEUDO_DMA - enables PSEUDO-DMA hardware, should give a 3-4X performance
- * increase compared to polled I/O.
- *
- * PARITY - enable parity checking.  Not supported.
- *
- * UNSAFE - leave interrupts enabled during pseudo-DMA transfers. 
- * You probably want this.
- *
  * The card is detected and initialized in one of several ways : 
  * 1.  Autoprobe (default) - since the board is memory mapped, 
  * a BIOS signature is scanned for to locate the registers.
Index: linux/drivers/scsi/g_NCR5380.c
===
--- linux.orig/drivers/scsi/g_NCR5380.c 2014-11-12 16:10:57.0 +1100
+++ linux/drivers/scsi/g_NCR5380.c  2014-11-12 16:10:59.0 +1100
@@ -20,18 +20,6 @@
  * Thomas Sailer, sai...@ife.ee.ethz.ch
  *
  * ALPHA RELEASE 1. 
- *
- * For more information, please consult 
- *
- * NCR 5380 Family
- * SCSI Protocol Controller
- * Databook
- *
- * NCR Microelectronics
- * 1635 Aeroplaza Drive
- * Colorado Springs, CO 80916
- * 1+ (719) 578-3400
- * 1+ (800) 334-5454
  */
 
 /* 
@@ -40,10 +28,6 @@
  */
 
 /*
- * Options :
- *
- * PARITY - enable parity checking.  Not supported.
- *
  * The card is detected and initialized in one of several ways : 
  * 1.  With command line overrides - NCR5380=port,irq may be 
  * used on the LILO command line to override the defaults.
Index: linux/drivers/scsi/pas16.c
===
--- linux.orig/drivers/scsi/pas16.c 2014-11-12 16:10:57.0 +1100
+++ linux/drivers/scsi/pas16.c  2014-11-12 16:10:59.0 +1100
@@ -22,40 +22,9 @@
  * Media Vision
  * (510) 770-8600
  * (800) 348-7116
- * 
- * and 
- *
- * NCR 5380 Family
- * SCSI Protocol Controller
- * Databook
- *
- * NCR Microelectronics
- * 1635 Aeroplaza Drive
- * Colorado Springs, CO 80916
- * 1+ (719) 578-3400
- * 1+ (800) 334-5454
  */
 
 /*
- * Options : 
- * LIMIT_TRANSFERSIZE - if defined, limit the pseudo-dma transfers to 512
- *  bytes at a time.  Since interrupts are disabled by default during
- *  these transfers, we might need this to give reasonable interrupt
- *  service time if the transfer size gets too large.
- *
- * PSEUDO_DMA - enables PSEUDO-DMA hardware, should give a 3-4X performance
- * increase compared to polled I/O.
- *
- * PARITY - enable parity checking.  Not supported.
- *
- * UNSAFE - leave interrupts enabled during pseudo-DMA transfers.  This
- * parameter comes from the NCR5380 code.  It is NOT unsafe with
- * the PAS16 and you should use it.  If you don't you will have
- * a problem with dropped characters during high speed
- * communications during SCSI transfers.  If you really don't
- * want to use UNSAFE you can try defining LIMIT_TRANSFERSIZE or
- * twiddle with the transfer size in the high level code.
- *
  * The card is detected and initialized in one of several ways : 
  * 1.  Autoprobe (default) - There are many different models of
  * the Pro Audio Spectrum/Studio 16, and I only have one of
Index: linux/drivers/scsi/sun3_scsi.c
===
--- linux.orig/drivers/scsi/sun3_scsi.c 2014-11-12 16:10:57.0 +1100
+++ linux/drivers/scsi/sun3_scsi.c  2014-11-12 16:10:59.0 +1100
@@ -22,27 +22,6 @@
  * Copyright 1995, Russell King
  *
  * ALPHA RELEASE 1.
- *
- * For more information, please consult
- *
- * NCR 5380 Family
- * SCSI Protocol Controller
- * Databook
- *
- * NCR Microelectronics
- * 

[PATCH v3 15/37] ncr5380: Remove *_RELEASE macros

2014-11-11 Thread Finn Thain
The *_RELEASE macros don't tell me anything. In some cases the version in
the macro contradicts the version in the comments. Anyway, the Linux kernel
version is sufficient information. Remove these macros to improve readability.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---
 drivers/scsi/NCR5380.c   |   18 --
 drivers/scsi/NCR5380.h   |5 -
 drivers/scsi/arm/cumana_1.c  |2 --
 drivers/scsi/arm/oak.c   |2 --
 drivers/scsi/atari_NCR5380.c |4 
 drivers/scsi/dtc.c   |5 -
 drivers/scsi/dtc.h   |2 --
 drivers/scsi/g_NCR5380.c |2 --
 drivers/scsi/g_NCR5380.h |5 -
 drivers/scsi/mac_scsi.c  |2 --
 drivers/scsi/mac_scsi.h  |4 
 drivers/scsi/pas16.h |2 --
 drivers/scsi/sun3_NCR5380.c  |4 
 drivers/scsi/sun3_scsi.c |2 --
 drivers/scsi/sun3_scsi.h |4 
 drivers/scsi/t128.c  |2 --
 drivers/scsi/t128.h  |4 
 17 files changed, 69 deletions(-)

Index: linux/drivers/scsi/NCR5380.c
===
--- linux.orig/drivers/scsi/NCR5380.c   2014-11-12 16:11:10.0 +1100
+++ linux/drivers/scsi/NCR5380.c2014-11-12 16:11:13.0 +1100
@@ -11,8 +11,6 @@
  *  d...@colorado.edu
  *  +1 (303) 666-5836
  *
- * DISTRIBUTION RELEASE 6. 
- *
  * For more information, please consult 
  *
  * NCR 5380 Family
@@ -735,22 +733,6 @@ static int __maybe_unused NCR5380_show_i
 
hostdata = (struct NCR5380_hostdata *) instance-hostdata;
 
-   SPRINTF(NCR5380 core release=%d.   , NCR5380_PUBLIC_RELEASE);
-   if (((struct NCR5380_hostdata *) instance-hostdata)-flags  
FLAG_NCR53C400)
-   SPRINTF(ncr53c400 release=%d.  , NCR53C400_PUBLIC_RELEASE);
-#ifdef DTC_PUBLIC_RELEASE
-   SPRINTF(DTC 3180/3280 release %d, DTC_PUBLIC_RELEASE);
-#endif
-#ifdef T128_PUBLIC_RELEASE
-   SPRINTF(T128 release %d, T128_PUBLIC_RELEASE);
-#endif
-#ifdef GENERIC_NCR5380_PUBLIC_RELEASE
-   SPRINTF(Generic5380 release %d, GENERIC_NCR5380_PUBLIC_RELEASE);
-#endif
-#ifdef PAS16_PUBLIC_RELEASE
-   SPRINTF(PAS16 release=%d, PAS16_PUBLIC_RELEASE);
-#endif
-
 #ifdef PSEUDO_DMA
SPRINTF(Highwater I/O busy spin counts: write %d, read %d\n,
hostdata-spin_max_w, hostdata-spin_max_r);
Index: linux/drivers/scsi/atari_NCR5380.c
===
--- linux.orig/drivers/scsi/atari_NCR5380.c 2014-11-12 16:11:06.0 
+1100
+++ linux/drivers/scsi/atari_NCR5380.c  2014-11-12 16:11:13.0 +1100
@@ -11,8 +11,6 @@
  * d...@colorado.edu
  * +1 (303) 666-5836
  *
- * DISTRIBUTION RELEASE 6.
- *
  * For more information, please consult
  *
  * NCR 5380 Family
@@ -741,7 +739,6 @@ static void NCR5380_print_status(struct
 
hostdata = (struct NCR5380_hostdata *)instance-hostdata;
 
-   printk(\nNCR5380 core release=%d.\n, NCR5380_PUBLIC_RELEASE);
local_irq_save(flags);
printk(NCR5380: coroutine is%s running.\n,
main_running ?  : n't);
@@ -785,7 +782,6 @@ static int __maybe_unused NCR5380_show_i
 
hostdata = (struct NCR5380_hostdata *)instance-hostdata;
 
-   seq_printf(m, NCR5380 core release=%d.\n, NCR5380_PUBLIC_RELEASE);
local_irq_save(flags);
seq_printf(m, NCR5380: coroutine is%s running.\n,
main_running ?  : n't);
Index: linux/drivers/scsi/sun3_NCR5380.c
===
--- linux.orig/drivers/scsi/sun3_NCR5380.c  2014-11-12 16:11:06.0 
+1100
+++ linux/drivers/scsi/sun3_NCR5380.c   2014-11-12 16:11:13.0 +1100
@@ -13,8 +13,6 @@
  * d...@colorado.edu
  * +1 (303) 666-5836
  *
- * DISTRIBUTION RELEASE 6. 
- *
  * For more information, please consult 
  *
  * NCR 5380 Family
@@ -687,7 +685,6 @@ static void NCR5380_print_status(struct
 
hostdata = (struct NCR5380_hostdata *)instance-hostdata;
 
-   printk(\nNCR5380 core release=%d.\n, NCR5380_PUBLIC_RELEASE);
local_irq_save(flags);
printk(NCR5380: coroutine is%s running.\n,
main_running ?  : n't);
@@ -731,7 +728,6 @@ static int __maybe_unused NCR5380_show_i
 
hostdata = (struct NCR5380_hostdata *)instance-hostdata;
 
-   seq_printf(m, NCR5380 core release=%d.\n, NCR5380_PUBLIC_RELEASE);
local_irq_save(flags);
seq_printf(m, NCR5380: coroutine is%s running.\n,
main_running ?  : n't);
Index: linux/drivers/scsi/NCR5380.h
===
--- linux.orig/drivers/scsi/NCR5380.h   2014-11-12 16:11:10.0 +1100
+++ linux/drivers/scsi/NCR5380.h2014-11-12 16:11:13.0 +1100
@@ -7,8 +7,6 @@
  * d...@colorado.edu
  *  +1 (303) 666-5836
  *

[PATCH v3 22/37] atari_scsi: Fix atari_scsi deadlocks on Falcon

2014-11-11 Thread Finn Thain
Don't disable irqs when waiting for the ST DMA lock; its release may
require an interrupt.

Introduce stdma_try_lock() for use in soft irq context. atari_scsi now tells
the SCSI mid-layer to defer queueing a command if the ST DMA lock is not
available, as per Michael's patch:
http://marc.info/?l=linux-m68km=139095335824863w=2

The falcon_got_lock variable is race prone: we can't disable IRQs while
waiting to acquire the lock, so after acquiring it there must be some
interval during which falcon_got_lock remains false. Introduce
stdma_is_locked_by() to replace falcon_got_lock.

The falcon_got_lock tests in the EH handlers are incorrect these days. It
can happen that an EH handler is called after a command completes normally.
Remove these checks along with falcon_got_lock.

Also remove the complicated and racy fairness wait queues. If fairness is an
issue (when SCSI competes with IDE for the ST DMA interrupt), the solution
is likely to be a lower value for host-can_queue.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com
Acked-by: Geert Uytterhoeven ge...@linux-m68k.org

---

Changes since v1:
- Use Geert's suggestion for simpler stdma_is_locked_by() implementation.

Changes since v2:
- Remove obsolete comments regarding scsi command timer.
- Fix checkpatch warning (else after return).

---
 arch/m68k/atari/stdma.c |   61 +++--
 arch/m68k/include/asm/atari_stdma.h |4 -
 drivers/scsi/atari_NCR5380.c|   33 ---
 drivers/scsi/atari_scsi.c   |   75 ++--
 4 files changed, 66 insertions(+), 107 deletions(-)

Index: linux/arch/m68k/atari/stdma.c
===
--- linux.orig/arch/m68k/atari/stdma.c  2014-11-12 16:10:43.0 +1100
+++ linux/arch/m68k/atari/stdma.c   2014-11-12 16:11:25.0 +1100
@@ -59,6 +59,31 @@ static irqreturn_t stdma_int (int irq, v
 /* End of Prototypes **/
 
 
+/**
+ * stdma_try_lock - attempt to acquire ST DMA interrupt lock
+ * @handler: interrupt handler to use after acquisition
+ *
+ * Returns !0 if lock was acquired; otherwise 0.
+ */
+
+int stdma_try_lock(irq_handler_t handler, void *data)
+{
+   unsigned long flags;
+
+   local_irq_save(flags);
+   if (stdma_locked) {
+   local_irq_restore(flags);
+   return 0;
+   }
+
+   stdma_locked   = 1;
+   stdma_isr  = handler;
+   stdma_isr_data = data;
+   local_irq_restore(flags);
+   return 1;
+}
+EXPORT_SYMBOL(stdma_try_lock);
+
 
 /*
  * Function: void stdma_lock( isrfunc isr, void *data )
@@ -78,19 +103,10 @@ static irqreturn_t stdma_int (int irq, v
 
 void stdma_lock(irq_handler_t handler, void *data)
 {
-   unsigned long flags;
-
-   local_irq_save(flags);  /* protect lock */
-
/* Since the DMA is used for file system purposes, we
 have to sleep uninterruptible (there may be locked
 buffers) */
-   wait_event(stdma_wait, !stdma_locked);
-
-   stdma_locked   = 1;
-   stdma_isr  = handler;
-   stdma_isr_data = data;
-   local_irq_restore(flags);
+   wait_event(stdma_wait, stdma_try_lock(handler, data));
 }
 EXPORT_SYMBOL(stdma_lock);
 
@@ -122,22 +138,25 @@ void stdma_release(void)
 EXPORT_SYMBOL(stdma_release);
 
 
-/*
- * Function: int stdma_others_waiting( void )
- *
- * Purpose: Check if someone waits for the ST-DMA lock.
- *
- * Inputs: none
- *
- * Returns: 0 if no one is waiting, != 0 otherwise
+/**
+ * stdma_is_locked_by - allow lock holder to check whether it needs to release.
+ * @handler: interrupt handler previously used to acquire lock.
  *
+ * Returns !0 if locked for the given handler; 0 otherwise.
  */
 
-int stdma_others_waiting(void)
+int stdma_is_locked_by(irq_handler_t handler)
 {
-   return waitqueue_active(stdma_wait);
+   unsigned long flags;
+   int result;
+
+   local_irq_save(flags);
+   result = stdma_locked  (stdma_isr == handler);
+   local_irq_restore(flags);
+
+   return result;
 }
-EXPORT_SYMBOL(stdma_others_waiting);
+EXPORT_SYMBOL(stdma_is_locked_by);
 
 
 /*
Index: linux/arch/m68k/include/asm/atari_stdma.h
===
--- linux.orig/arch/m68k/include/asm/atari_stdma.h  2014-11-12 
16:10:43.0 +1100
+++ linux/arch/m68k/include/asm/atari_stdma.h   2014-11-12 16:11:25.0 
+1100
@@ -8,11 +8,11 @@
 
 /* Prototypes */
 
+int stdma_try_lock(irq_handler_t, void *);
 void stdma_lock(irq_handler_t handler, void *data);
 void stdma_release( void );
-int stdma_others_waiting( void );
 int stdma_islocked( void );
-void *stdma_locked_by( void );
+int stdma_is_locked_by(irq_handler_t);
 void stdma_init( void );
 
 

[PATCH v3 18/37] mac_scsi: Remove header

2014-11-11 Thread Finn Thain
The #defines in mac_scsi.h are intended to influence subsequent #includes in
mac_scsi.c. IMHO, that's too convoluted.

Remove mac_scsi.h by moving those macro definitions to mac_scsi.c,
consistent with other NCR5380 drivers.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de

---
 drivers/scsi/mac_scsi.c |   21 -
 drivers/scsi/mac_scsi.h |   42 --
 2 files changed, 20 insertions(+), 43 deletions(-)

Index: linux/drivers/scsi/mac_scsi.c
===
--- linux.orig/drivers/scsi/mac_scsi.c  2014-11-12 16:11:16.0 +1100
+++ linux/drivers/scsi/mac_scsi.c   2014-11-12 16:11:20.0 +1100
@@ -31,10 +31,29 @@
 #include asm/mac_via.h
 
 #include scsi/scsi_host.h
-#include mac_scsi.h
+
+/* Definitions for the core NCR5380 driver. */
 
 #define PSEUDO_DMA
 
+#define NCR5380_implementation_fields   /* none */
+#define NCR5380_local_declare() struct Scsi_Host *_instance
+#define NCR5380_setup(instance) _instance = instance
+
+#define NCR5380_read(reg)   macscsi_read(_instance, reg)
+#define NCR5380_write(reg, value)   macscsi_write(_instance, reg, value)
+
+#define NCR5380_pread   macscsi_pread
+#define NCR5380_pwrite  macscsi_pwrite
+
+#define NCR5380_intrmacscsi_intr
+#define NCR5380_queue_command   macscsi_queue_command
+#define NCR5380_abort   macscsi_abort
+#define NCR5380_bus_reset   macscsi_bus_reset
+#define NCR5380_infomacscsi_info
+#define NCR5380_show_info   macscsi_show_info
+#define NCR5380_write_info  macscsi_write_info
+
 #include NCR5380.h
 
 #define RESET_BOOT
Index: linux/drivers/scsi/mac_scsi.h
===
--- linux.orig/drivers/scsi/mac_scsi.h  2014-11-12 16:11:13.0 +1100
+++ /dev/null   1970-01-01 00:00:00.0 +
@@ -1,42 +0,0 @@
-/*
- * Cumana Generic NCR5380 driver defines
- *
- * Copyright 1993, Drew Eckhardt
- * Visionary Computing
- * (Unix and Linux consulting and custom programming)
- * d...@colorado.edu
- *  +1 (303) 440-4894
- */
-
-#ifndef MAC_NCR5380_H
-#define MAC_NCR5380_H
-
-#ifndef ASM
-
-#include scsi/scsicam.h
-
-#define NCR5380_implementation_fields /* none */
-
-#define NCR5380_local_declare() \
-struct Scsi_Host *_instance
-
-#define NCR5380_setup(instance) \
-_instance = instance
-
-#define NCR5380_read(reg) macscsi_read(_instance, reg)
-#define NCR5380_write(reg, value) macscsi_write(_instance, reg, value)
-
-#define NCR5380_pread  macscsi_pread
-#define NCR5380_pwrite macscsi_pwrite
-   
-#define NCR5380_intr macscsi_intr
-#define NCR5380_queue_command macscsi_queue_command
-#define NCR5380_abort macscsi_abort
-#define NCR5380_bus_reset macscsi_bus_reset
-#define NCR5380_info macscsi_info
-#define NCR5380_show_info macscsi_show_info
-#define NCR5380_write_info macscsi_write_info
-
-#endif /* ndef ASM */
-#endif /* MAC_NCR5380_H */
-


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


[PATCH v3 28/37] atari_NCR5380: Refactor Falcon special cases

2014-11-11 Thread Finn Thain
Make the atari_NCR5380.c core driver usable by sun3_scsi, mac_scsi and
others by moving some of the Falcon-specific code out of the core driver:
!IS_A_TT, atari_read_overruns and falcon_dont_release. Replace these with
hostdata variables and flags. FLAG_CHECK_LAST_BYTE_SENT is unused in
atari_NCR5380.c so don't set it.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---
 drivers/scsi/NCR5380.h   |4 
 drivers/scsi/atari_NCR5380.c |   30 +++---
 drivers/scsi/atari_scsi.c|   21 -
 3 files changed, 31 insertions(+), 24 deletions(-)

Index: linux/drivers/scsi/atari_scsi.c
===
--- linux.orig/drivers/scsi/atari_scsi.c2014-11-12 16:11:31.0 
+1100
+++ linux/drivers/scsi/atari_scsi.c 2014-11-12 16:11:32.0 +1100
@@ -196,8 +196,6 @@ static char *atari_dma_orig_addr;
 /* mask for address bits that can't be used with the ST-DMA */
 static unsigned long   atari_dma_stram_mask;
 #define STRAM_ADDR(a)  (((a)  atari_dma_stram_mask) == 0)
-/* number of bytes to cut from a transfer to handle NCR overruns */
-static int atari_read_overruns;
 #endif
 
 static int setup_can_queue = -1;
@@ -446,8 +444,6 @@ static void atari_scsi_fetch_restbytes(v
 #endif /* REAL_DMA */
 
 
-static int falcon_dont_release = 0;
-
 /* This function releases the lock on the DMA chip if there is no
  * connected command and the disconnected queue is empty.
  */
@@ -464,7 +460,7 @@ static void falcon_release_lock_if_possi
if (!hostdata-disconnected_queue 
!hostdata-issue_queue 
!hostdata-connected 
-   !falcon_dont_release 
+   !hostdata-retain_dma_intr 
stdma_is_locked_by(scsi_falcon_intr))
stdma_release();
 
@@ -846,6 +842,7 @@ static int __init atari_scsi_probe(struc
struct Scsi_Host *instance;
int error;
struct resource *irq;
+   int host_flags = 0;
 
irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (!irq)
@@ -942,7 +939,9 @@ static int __init atari_scsi_probe(struc
 
instance-irq = irq-start;
 
-   NCR5380_init(instance, 0);
+   host_flags |= IS_A_TT() ? 0 : FLAG_LATE_DMA_SETUP;
+
+   NCR5380_init(instance, host_flags);
 
if (IS_A_TT()) {
error = request_irq(instance-irq, scsi_tt_intr, 0,
@@ -965,12 +964,16 @@ static int __init atari_scsi_probe(struc
 *
 * In principle it should be sufficient to do max. 1 byte with
 * PIO, but there is another problem on the Medusa with the DMA
-* rest data register. So 'atari_read_overruns' is currently set
+* rest data register. So read_overruns is currently set
 * to 4 to avoid having transfers that aren't a multiple of 4.
 * If the rest data bug is fixed, this can be lowered to 1.
 */
-   if (MACH_IS_MEDUSA)
-   atari_read_overruns = 4;
+   if (MACH_IS_MEDUSA) {
+   struct NCR5380_hostdata *hostdata =
+   shost_priv(instance);
+
+   hostdata-read_overruns = 4;
+   }
 #endif
} else {
/* Nothing to do for the interrupt: the ST-DMA is initialized
Index: linux/drivers/scsi/NCR5380.h
===
--- linux.orig/drivers/scsi/NCR5380.h   2014-11-12 16:11:16.0 +1100
+++ linux/drivers/scsi/NCR5380.h2014-11-12 16:11:32.0 +1100
@@ -241,6 +241,7 @@
 #define FLAG_NCR53C400 4   /* NCR53c400 */
 #define FLAG_NO_PSEUDO_DMA 8   /* Inhibit DMA */
 #define FLAG_DTC3181E  16  /* DTC3181E */
+#define FLAG_LATE_DMA_SETUP32  /* Setup NCR before DMA H/W */
 
 #ifndef ASM
 struct NCR5380_hostdata {
@@ -269,6 +270,9 @@ struct NCR5380_hostdata {
struct delayed_work coroutine;  /* our co-routine */
struct scsi_eh_save ses;
char info[256];
+   int read_overruns;/* number of bytes to cut from a
+  * transfer to handle chip overruns */
+   int retain_dma_intr;
 #ifdef PSEUDO_DMA
unsigned spin_max_r;
unsigned spin_max_w;
Index: linux/drivers/scsi/atari_NCR5380.c
===
--- linux.orig/drivers/scsi/atari_NCR5380.c 2014-11-12 16:11:31.0 
+1100
+++ linux/drivers/scsi/atari_NCR5380.c  2014-11-12 16:11:32.0 +1100
@@ -839,7 +839,7 @@ static int __init NCR5380_init(struct Sc
hostdata-connected = NULL;
hostdata-issue_queue = NULL;
hostdata-disconnected_queue = NULL;
-   hostdata-flags = 

[PATCH v3 10/37] ncr5380: Fix SCSI_IRQ_NONE bugs

2014-11-11 Thread Finn Thain
Oak scsi doesn't use any IRQ, but it sets irq = IRQ_NONE rather than
SCSI_IRQ_NONE. Problem is, the core NCR5380 driver expects SCSI_IRQ_NONE
if it is to issue IDENTIFY commands that prevent target disconnection.
And, as Geert points out, IRQ_NONE is part of enum irqreturn.

Other drivers, when they can't get an IRQ or can't use one, will set
host-irq = SCSI_IRQ_NONE (that is, 255). But when they exit they will
attempt to free IRQ 255 which was never requested.

Fix these bugs by using NO_IRQ in place of SCSI_IRQ_NONE and IRQ_NONE.
That means IRQ 0 is no longer probed by ISA drivers but I don't think
this matters.

Setting IRQ = 255 for these ISA drivers is understood to mean no IRQ.
This remains supported so as to avoid breaking existing ISA setups (which
can be difficult to get working) and because existing documentation
(SANE, TLDP etc) describes this usage for the ISA NCR5380 driver options.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---

Changes since v1:
- Define NO_IRQ macro and use that instead of IRQ_NONE.

---
 drivers/scsi/NCR5380.c   |   12 ++--
 drivers/scsi/NCR5380.h   |5 -
 drivers/scsi/arm/oak.c   |2 +-
 drivers/scsi/dmx3191d.c  |7 ---
 drivers/scsi/dtc.c   |   22 +-
 drivers/scsi/g_NCR5380.c |   18 +++---
 drivers/scsi/mac_scsi.c  |8 
 drivers/scsi/pas16.c |   20 +++-
 drivers/scsi/sun3_scsi.c |6 +++---
 drivers/scsi/t128.c  |   14 +-
 10 files changed, 66 insertions(+), 48 deletions(-)

Index: linux/drivers/scsi/dtc.c
===
--- linux.orig/drivers/scsi/dtc.c   2014-11-12 16:10:59.0 +1100
+++ linux/drivers/scsi/dtc.c2014-11-12 16:11:02.0 +1100
@@ -254,31 +254,35 @@ found:
else
instance-irq = NCR5380_probe_irq(instance, DTC_IRQS);
 
+   /* Compatibility with documented NCR5380 kernel parameters */
+   if (instance-irq == 255)
+   instance-irq = NO_IRQ;
+
 #ifndef DONT_USE_INTR
/* With interrupts enabled, it will sometimes hang when doing 
heavy
 * reads. So better not enable them until I finger it out. */
-   if (instance-irq != SCSI_IRQ_NONE)
+   if (instance-irq != NO_IRQ)
if (request_irq(instance-irq, dtc_intr, 0,
dtc, instance)) {
printk(KERN_ERR scsi%d : IRQ%d not free, 
interrupts disabled\n, instance-host_no, instance-irq);
-   instance-irq = SCSI_IRQ_NONE;
+   instance-irq = NO_IRQ;
}
 
-   if (instance-irq == SCSI_IRQ_NONE) {
+   if (instance-irq == NO_IRQ) {
printk(KERN_WARNING scsi%d : interrupts not enabled. 
for better interactive performance,\n, instance-host_no);
printk(KERN_WARNING scsi%d : please jumper the board 
for a free IRQ.\n, instance-host_no);
}
 #else
-   if (instance-irq != SCSI_IRQ_NONE)
+   if (instance-irq != NO_IRQ)
printk(KERN_WARNING scsi%d : interrupts not used. 
Might as well not jumper it.\n, instance-host_no);
-   instance-irq = SCSI_IRQ_NONE;
+   instance-irq = NO_IRQ;
 #endif
 #if defined(DTCDEBUG)  (DTCDEBUG  DTCDEBUG_INIT)
printk(scsi%d : irq = %d\n, instance-host_no, instance-irq);
 #endif
 
printk(KERN_INFO scsi%d : at 0x%05X, instance-host_no, (int) 
instance-base);
-   if (instance-irq == SCSI_IRQ_NONE)
+   if (instance-irq == NO_IRQ)
printk( interrupts disabled);
else
printk( irq %d, instance-irq);
@@ -350,7 +354,7 @@ static inline int NCR5380_pread(struct S
i = 0;
NCR5380_read(RESET_PARITY_INTERRUPT_REG);
NCR5380_write(MODE_REG, MR_ENABLE_EOP_INTR | MR_DMA_MODE);
-   if (instance-irq == SCSI_IRQ_NONE)
+   if (instance-irq == NO_IRQ)
NCR5380_write(DTC_CONTROL_REG, CSR_DIR_READ);
else
NCR5380_write(DTC_CONTROL_REG, CSR_DIR_READ | CSR_INT_BASE);
@@ -401,7 +405,7 @@ static inline int NCR5380_pwrite(struct
NCR5380_read(RESET_PARITY_INTERRUPT_REG);
NCR5380_write(MODE_REG, MR_ENABLE_EOP_INTR | MR_DMA_MODE);
/* set direction (write) */
-   if (instance-irq == SCSI_IRQ_NONE)
+   if (instance-irq == NO_IRQ)
NCR5380_write(DTC_CONTROL_REG, 0);
else
NCR5380_write(DTC_CONTROL_REG, CSR_5380_INTR);
@@ -440,7 +444,7 @@ static int dtc_release(struct Scsi_Host
 {
NCR5380_local_declare();
NCR5380_setup(shost);
-   if 

[PATCH v3 34/37] atari_NCR5380: Move static TagAlloc array to host data

2014-11-11 Thread Finn Thain
The atari_NCR5380.c core driver keeps some per-host data in a static
variable which limits the driver to a single instance. Fix this by moving
TagAlloc to the hostdata struct.

Signed-off-by: Finn Thain fth...@telegraphics.com.au
Reviewed-by: Hannes Reinecke h...@suse.de
Tested-by: Michael Schmitz schmitz...@gmail.com

---
 drivers/scsi/NCR5380.h   |   12 
 drivers/scsi/atari_NCR5380.c |   27 +--
 2 files changed, 21 insertions(+), 18 deletions(-)

Index: linux/drivers/scsi/NCR5380.h
===
--- linux.orig/drivers/scsi/NCR5380.h   2014-11-12 16:11:39.0 +1100
+++ linux/drivers/scsi/NCR5380.h2014-11-12 16:11:41.0 +1100
@@ -245,6 +245,15 @@
 #define FLAG_TAGGED_QUEUING64  /* as X3T9.2 spelled it */
 
 #ifndef ASM
+
+#ifdef SUPPORT_TAGS
+struct tag_alloc {
+   DECLARE_BITMAP(allocated, MAX_TAGS);
+   int nr_allocated;
+   int queue_size;
+};
+#endif
+
 struct NCR5380_hostdata {
NCR5380_implementation_fields;  /* implementation specific */
struct Scsi_Host *host; /* Host backpointer */
@@ -274,6 +283,9 @@ struct NCR5380_hostdata {
int read_overruns;/* number of bytes to cut from a
   * transfer to handle chip overruns */
int retain_dma_intr;
+#ifdef SUPPORT_TAGS
+   struct tag_alloc TagAlloc[8][8];/* 8 targets and 8 LUNs */
+#endif
 #ifdef PSEUDO_DMA
unsigned spin_max_r;
unsigned spin_max_w;
Index: linux/drivers/scsi/atari_NCR5380.c
===
--- linux.orig/drivers/scsi/atari_NCR5380.c 2014-11-12 16:11:39.0 
+1100
+++ linux/drivers/scsi/atari_NCR5380.c  2014-11-12 16:11:41.0 +1100
@@ -274,26 +274,17 @@ static struct scsi_host_template *the_te
  * important: the tag bit must be cleared before 'nr_allocated' is decreased.
  */
 
-typedef struct {
-   DECLARE_BITMAP(allocated, MAX_TAGS);
-   int nr_allocated;
-   int queue_size;
-} TAG_ALLOC;
-
-static TAG_ALLOC TagAlloc[8][8];   /* 8 targets and 8 LUNs */
-
-
 static void __init init_tags(struct NCR5380_hostdata *hostdata)
 {
int target, lun;
-   TAG_ALLOC *ta;
+   struct tag_alloc *ta;
 
if (!(hostdata-flags  FLAG_TAGGED_QUEUING))
return;
 
for (target = 0; target  8; ++target) {
for (lun = 0; lun  8; ++lun) {
-   ta = TagAlloc[target][lun];
+   ta = hostdata-TagAlloc[target][lun];
bitmap_zero(ta-allocated, MAX_TAGS);
ta-nr_allocated = 0;
/* At the beginning, assume the maximum queue size we 
could
@@ -324,8 +315,8 @@ static int is_lun_busy(struct scsi_cmnd
!(hostdata-flags  FLAG_TAGGED_QUEUING) ||
!cmd-device-tagged_supported)
return 0;
-   if (TagAlloc[cmd-device-id][lun].nr_allocated =
-   TagAlloc[cmd-device-id][lun].queue_size) {
+   if (hostdata-TagAlloc[scmd_id(cmd)][lun].nr_allocated =
+   hostdata-TagAlloc[scmd_id(cmd)][lun].queue_size) {
dprintk(NDEBUG_TAGS, scsi%d: target %d lun %d: no free tags\n,
   H_NO(cmd), cmd-device-id, lun);
return 1;
@@ -355,7 +346,7 @@ static void cmd_get_tag(struct scsi_cmnd
dprintk(NDEBUG_TAGS, scsi%d: target %d lun %d now allocated by 
untagged 
   command\n, H_NO(cmd), cmd-device-id, lun);
} else {
-   TAG_ALLOC *ta = TagAlloc[cmd-device-id][lun];
+   struct tag_alloc *ta = hostdata-TagAlloc[scmd_id(cmd)][lun];
 
cmd-tag = find_first_zero_bit(ta-allocated, MAX_TAGS);
set_bit(cmd-tag, ta-allocated);
@@ -385,7 +376,7 @@ static void cmd_free_tag(struct scsi_cmn
printk(KERN_NOTICE scsi%d: trying to free bad tag %d!\n,
   H_NO(cmd), cmd-tag);
} else {
-   TAG_ALLOC *ta = TagAlloc[cmd-device-id][lun];
+   struct tag_alloc *ta = hostdata-TagAlloc[scmd_id(cmd)][lun];
clear_bit(cmd-tag, ta-allocated);
ta-nr_allocated--;
dprintk(NDEBUG_TAGS, scsi%d: freed tag %d for target %d lun 
%d\n,
@@ -397,14 +388,14 @@ static void cmd_free_tag(struct scsi_cmn
 static void free_all_tags(struct NCR5380_hostdata *hostdata)
 {
int target, lun;
-   TAG_ALLOC *ta;
+   struct tag_alloc *ta;
 
if (!(hostdata-flags  FLAG_TAGGED_QUEUING))
return;
 
for (target = 0; target  8; ++target) {
for (lun = 0; lun  8; ++lun) {
-   ta = TagAlloc[target][lun];
+   ta = hostdata-TagAlloc[target][lun];
bitmap_zero(ta-allocated, MAX_TAGS);