sfrench/cifs-2.6.git
15 months agoscsi: zfcp: Trace when request remove fails after qdio send fails
Benjamin Block [Tue, 21 Feb 2023 17:56:00 +0000 (18:56 +0100)]
scsi: zfcp: Trace when request remove fails after qdio send fails

When we fail to send a FSF request in 'zfcp_fsf_req_send()' when calling
'zfcp_qdio_send()' we try to remove the request object from our internal
hash table again to prevent keeping a stale memory reference. This removal
might still - very much theoretically - fail.

To store some evidence of when this happens add a new trace record for
this case; tag: 'fsrsrmf'.

We reuse the 'ZFCP_DBF_HBA_RES' trace ID for this, but mark all fields
other then the request ID with ~0, to make fairly obvious that these are
invalid values. This faking has to be done because we don't have a valid
request object at this point, and can not safely access any of the memory
of the old object - we just failed to find it in our hash table, so it
might be gone already.

Here is an example of a decoded trace record:

    Timestamp      : 2023-02-17-13:09:12:748140
    Area           : HBA
    Subarea        : 1
    Level          : -
    Exception      : 000003ff7ff500c2
    CPU ID         : 0011
    Caller         : 0x0
    Record ID      : 1
    Tag            : fsrsrmf
    Request ID     : 0x0000000080126ab6
    Request status : 0xffffffff
    FSF cmnd       : 0xffffffff
    FSF sequence no: 0xffffffff
    FSF issued     : 2042-09-18-01:53:47:370495
    FSF stat       : 0xffffffff
    FSF stat qual  : ffffffff ffffffff ffffffff ffffffff
    Prot stat      : 0xffffffff
    Prot stat qual : ffffffff ffffffff ffffffff ffffffff
    Port handle    : 0xffffffff
    LUN handle     : 0xffffffff

This provides at least some basic evidence that this event happened, and
what object was affected.

Link: https://lore.kernel.org/r/99b8246b2d71b63fa4f9c56333e2037502f7f5af.1677000450.git.bblock@linux.ibm.com
Signed-off-by: Benjamin Block <bblock@linux.ibm.com>
Reviewed-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: zfcp: Change the type of all fsf request id fields and variables to u64
Benjamin Block [Tue, 21 Feb 2023 17:55:59 +0000 (18:55 +0100)]
scsi: zfcp: Change the type of all fsf request id fields and variables to u64

We use different integer types throughout zfcp to store the FSF request ID
and related values; some places use 'unsigned long' and others 'u64'.  On
s390x these are effectively the same type, but this might cause confusions
and is generally inconsistent.

The specification for the used hardware specifies this value as a 64-bit
number, and ultimately we use this value to communicate with the hardware,
so it makes sense to change the type of all these variables to 'u64' where
we can.  The only exception being when we store it in the 'host_scribble'
field of a 'struct scsi_cmnd'; for this case we add a build time check to
make sure they are compatible.

Link: https://lore.kernel.org/r/9c9cbe5acc2b419a22dce2fed847e3db91b60201.1677000450.git.bblock@linux.ibm.com
Signed-off-by: Benjamin Block <bblock@linux.ibm.com>
Reviewed-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: zfcp: Make the type for accessing request hashtable buckets size_t
Benjamin Block [Tue, 21 Feb 2023 17:55:58 +0000 (18:55 +0100)]
scsi: zfcp: Make the type for accessing request hashtable buckets size_t

The appropriate type for array indices is 'size_t' and the current
implementation in 'zfcp_reqlist.h' mixes 'int' and 'unsigned int' in
different places to access the hashtable buckets of our internal request
hash table.

To prevent any confusion, change all places to 'size_t'.

Link: https://lore.kernel.org/r/64afe93f6263c6b07815937826cd7d5fc4f1a674.1677000450.git.bblock@linux.ibm.com
Signed-off-by: Benjamin Block <bblock@linux.ibm.com>
Reviewed-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ufs: core: Simplify ufshcd_execute_start_stop()
Bart Van Assche [Fri, 10 Feb 2023 19:32:58 +0000 (11:32 -0800)]
scsi: ufs: core: Simplify ufshcd_execute_start_stop()

Use scsi_execute_cmd() instead of open-coding it.

Link: https://lore.kernel.org/r/20230210193258.4004923-4-bvanassche@acm.org
Cc: Mike Christie <michael.christie@oracle.com>
Cc: John Garry <john.g.garry@oracle.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Asutosh Das <quic_asutoshd@quicinc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ufs: core: Rely on the block layer for setting RQF_PM
Bart Van Assche [Fri, 10 Feb 2023 19:32:57 +0000 (11:32 -0800)]
scsi: ufs: core: Rely on the block layer for setting RQF_PM

Do not set RQF_PM explicitly since scsi_alloc_request() sets it indirectly
if BLK_MQ_REQ_PM is set. The call chain for the code that sets RQF_PM is as
follows:

    scsi_alloc_request()
      blk_mq_alloc_request()
        __blk_mq_alloc_requests()
          blk_mq_rq_ctx_init()
            if (data->flags & BLK_MQ_REQ_PM)
              data->rq_flags |= RQF_PM;

Link: https://lore.kernel.org/r/20230210193258.4004923-3-bvanassche@acm.org
Cc: Mike Christie <michael.christie@oracle.com>
Cc: John Garry <john.g.garry@oracle.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: core: Extend struct scsi_exec_args
Bart Van Assche [Fri, 10 Feb 2023 19:32:56 +0000 (11:32 -0800)]
scsi: core: Extend struct scsi_exec_args

Allow SCSI LLDs to specify SCMD_* flags.

Link: https://lore.kernel.org/r/20230210193258.4004923-2-bvanassche@acm.org
Cc: Mike Christie <michael.christie@oracle.com>
Cc: John Garry <john.g.garry@oracle.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: lpfc: Fix double word in comments
Bo Liu [Fri, 17 Feb 2023 08:30:46 +0000 (03:30 -0500)]
scsi: lpfc: Fix double word in comments

Remove the repeated word "the" in comments.

[mkp: fixed additional typos in the changed lines]

Link: https://lore.kernel.org/r/20230217083046.4090-1-liubo03@inspur.com
Signed-off-by: Bo Liu <liubo03@inspur.com>
Reviewed-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: core: Remove the /proc/scsi/${proc_name} directory earlier
Bart Van Assche [Fri, 10 Feb 2023 20:52:00 +0000 (12:52 -0800)]
scsi: core: Remove the /proc/scsi/${proc_name} directory earlier

Remove the /proc/scsi/${proc_name} directory earlier to fix a race
condition between unloading and reloading kernel modules. This fixes a bug
introduced in 2009 by commit 77c019768f06 ("[SCSI] fix /proc memory leak in
the SCSI core").

Fix the following kernel warning:

proc_dir_entry 'scsi/scsi_debug' already registered
WARNING: CPU: 19 PID: 27986 at fs/proc/generic.c:376 proc_register+0x27d/0x2e0
Call Trace:
 proc_mkdir+0xb5/0xe0
 scsi_proc_hostdir_add+0xb5/0x170
 scsi_host_alloc+0x683/0x6c0
 sdebug_driver_probe+0x6b/0x2d0 [scsi_debug]
 really_probe+0x159/0x540
 __driver_probe_device+0xdc/0x230
 driver_probe_device+0x4f/0x120
 __device_attach_driver+0xef/0x180
 bus_for_each_drv+0xe5/0x130
 __device_attach+0x127/0x290
 device_initial_probe+0x17/0x20
 bus_probe_device+0x110/0x130
 device_add+0x673/0xc80
 device_register+0x1e/0x30
 sdebug_add_host_helper+0x1a7/0x3b0 [scsi_debug]
 scsi_debug_init+0x64f/0x1000 [scsi_debug]
 do_one_initcall+0xd7/0x470
 do_init_module+0xe7/0x330
 load_module+0x122a/0x12c0
 __do_sys_finit_module+0x124/0x1a0
 __x64_sys_finit_module+0x46/0x50
 do_syscall_64+0x38/0x80
 entry_SYSCALL_64_after_hwframe+0x46/0xb0

Link: https://lore.kernel.org/r/20230210205200.36973-3-bvanassche@acm.org
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Yi Zhang <yi.zhang@redhat.com>
Cc: stable@vger.kernel.org
Fixes: 77c019768f06 ("[SCSI] fix /proc memory leak in the SCSI core")
Reported-by: Yi Zhang <yi.zhang@redhat.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: core: Fix a source code comment
Bart Van Assche [Fri, 10 Feb 2023 20:51:59 +0000 (12:51 -0800)]
scsi: core: Fix a source code comment

Fix an incorrect reference to the scsi_remove_host() function in a source
code comment.

Link: https://lore.kernel.org/r/20230210205200.36973-2-bvanassche@acm.org
Fixes: b49493f99690 ("Fix a memory leak in scsi_host_dev_release()")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: cxgbi: Remove unneeded version.h include
Jesper Juhl [Thu, 16 Feb 2023 00:51:30 +0000 (01:51 +0100)]
scsi: cxgbi: Remove unneeded version.h include

Remove unneeded version.h include pointed out by 'make versioncheck'.

Link: https://lore.kernel.org/r/820137c2-decc-3d78-f170-7f1c0571fbb7@gmail.com
Signed-off-by: Jesper Juhl <jesperjuhl76@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: qedi: Remove unneeded version.h include
Jesper Juhl [Thu, 16 Feb 2023 00:51:30 +0000 (01:51 +0100)]
scsi: qedi: Remove unneeded version.h include

Remove unneeded version.h include pointed out by 'make versioncheck'.

Link: https://lore.kernel.org/r/820137c2-decc-3d78-f170-7f1c0571fbb7@gmail.com
Signed-off-by: Jesper Juhl <jesperjuhl76@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: mpi3mr: Remove unneeded version.h include
Jesper Juhl [Thu, 16 Feb 2023 00:51:30 +0000 (01:51 +0100)]
scsi: mpi3mr: Remove unneeded version.h include

Remove unneeded version.h include pointed out by 'make versioncheck'.

Link: https://lore.kernel.org/r/820137c2-decc-3d78-f170-7f1c0571fbb7@gmail.com
Signed-off-by: Jesper Juhl <jesperjuhl76@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: mpi3mr: Fix missing mrioc->evtack_cmds initialization
Shin'ichiro Kawasaki [Tue, 14 Feb 2023 00:50:19 +0000 (09:50 +0900)]
scsi: mpi3mr: Fix missing mrioc->evtack_cmds initialization

Commit c1af985d27da ("scsi: mpi3mr: Add Event acknowledgment logic")
introduced an array mrioc->evtack_cmds but initialization of the array
elements was missed. They are just zero cleared. The function
mpi3mr_complete_evt_ack() refers host_tag field of the elements. Due to the
zero value of the host_tag field, the function calls clear_bit() for
mrico->evtack_cmds_bitmap with wrong bit index. This results in memory
access to invalid address and "BUG: KASAN: use-after-free". This BUG was
observed at eHBA-9600 firmware update to version 8.3.1.0. To fix it, add
the missing initialization of mrioc->evtack_cmds.

Link: https://lore.kernel.org/r/20230214005019.1897251-5-shinichiro.kawasaki@wdc.com
Cc: stable@vger.kernel.org
Fixes: c1af985d27da ("scsi: mpi3mr: Add Event acknowledgment logic")
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Acked-by: Sathya Prakash Veerichetty <sathya.prakash@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: mpi3mr: Use number of bits to manage bitmap sizes
Shin'ichiro Kawasaki [Tue, 14 Feb 2023 00:50:18 +0000 (09:50 +0900)]
scsi: mpi3mr: Use number of bits to manage bitmap sizes

To allocate bitmaps, the mpi3mr driver calculates sizes of bitmaps using
byte as unit. However, bitmap helper functions assume that bitmaps are
allocated using unsigned long as unit. This gap causes memory access beyond
the bitmap sizes and results in "BUG: KASAN: slab-out-of-bounds".  The BUG
was observed at firmware download to eHBA-9600. Call trace indicated that
the out-of-bounds access happened in find_first_zero_bit() called from
mpi3mr_send_event_ack() for miroc->evtack_cmds_bitmap.

To fix the BUG, do not use bytes to manage bitmap sizes. Instead, use
number of bits, and call bitmap helper functions which take number of bits
as arguments. For memory allocation, call bitmap_zalloc() instead of
kzalloc() and krealloc(). For memory free, call bitmap_free() instead of
kfree(). For zero clear, call bitmap_clear() instead of memset().

Remove three fields for bitmap byte sizes in struct scmd_priv which are no
longer required. Replace the field dev_handle_bitmap_sz with
dev_handle_bitmap_bits to keep number of bits of removepend_bitmap across
resize.

Link: https://lore.kernel.org/r/20230214005019.1897251-4-shinichiro.kawasaki@wdc.com
Fixes: c5758fc72b92 ("scsi: mpi3mr: Gracefully handle online FW update operation")
Fixes: e844adb1fbdc ("scsi: mpi3mr: Implement SCSI error handler hooks")
Fixes: c1af985d27da ("scsi: mpi3mr: Add Event acknowledgment logic")
Fixes: 824a156633df ("scsi: mpi3mr: Base driver code")
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Acked-by: Sathya Prakash Veerichetty <sathya.prakash@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: mpi3mr: Remove unnecessary memcpy() to alltgt_info->dmi
Shin'ichiro Kawasaki [Tue, 14 Feb 2023 00:50:17 +0000 (09:50 +0900)]
scsi: mpi3mr: Remove unnecessary memcpy() to alltgt_info->dmi

In the function mpi3mr_get_all_tgt_info(), devmap_info points to
alltgt_info->dmi then there is no need to memcpy() data from devmap_info to
alltgt_info->dmi. Remove the unnecessary memcpy(). This also allows to
remove the local variable 'rval' and the goto label 'out'.

Link: https://lore.kernel.org/r/20230214005019.1897251-3-shinichiro.kawasaki@wdc.com
Cc: stable@vger.kernel.org
Fixes: f5e6d5a34376 ("scsi: mpi3mr: Add support for driver commands")
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Acked-by: Sathya Prakash Veerichetty <sathya.prakash@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: mpi3mr: Fix issues in mpi3mr_get_all_tgt_info()
Shin'ichiro Kawasaki [Tue, 14 Feb 2023 00:50:16 +0000 (09:50 +0900)]
scsi: mpi3mr: Fix issues in mpi3mr_get_all_tgt_info()

The function mpi3mr_get_all_tgt_info() has four issues:

1) It calculates valid entry length in alltgt_info assuming the header part
   of the struct mpi3mr_device_map_info would equal to sizeof(u32).  The
   correct size is sizeof(u64).

2) When it calculates the valid entry length kern_entrylen, it excludes one
   entry by subtracting 1 from num_devices.

3) It copies num_device by calling memcpy(). Substitution is enough.

4) It does not specify the calculated length to sg_copy_from_buffer().
   Instead, it specifies the payload length which is larger than the
   alltgt_info size. It causes "BUG: KASAN: slab-out-of-bounds".

Fix the issues by using the correct header size, removing the subtraction
from num_devices, replacing the memcpy() with substitution and specifying
the correct length to sg_copy_from_buffer().

Link: https://lore.kernel.org/r/20230214005019.1897251-2-shinichiro.kawasaki@wdc.com
Cc: stable@vger.kernel.org
Fixes: f5e6d5a34376 ("scsi: mpi3mr: Add support for driver commands")
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Acked-by: Sathya Prakash Veerichetty <sathya.prakash@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: mpi3mr: Fix an issue found by KASAN
Tomas Henzl [Mon, 13 Feb 2023 19:37:52 +0000 (20:37 +0100)]
scsi: mpi3mr: Fix an issue found by KASAN

Write only correct size (32 instead of 64 bytes).

Link: https://lore.kernel.org/r/20230213193752.6859-1-thenzl@redhat.com
Fixes: 42fc9fee116f ("scsi: mpi3mr: Add helper functions to manage device's port")
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
Acked-by: Sathya Prakash Veerichetty <sathya.prakash@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: mpi3mr: Replace 1-element array with flex-array
Kees Cook [Sat, 4 Feb 2023 18:37:16 +0000 (10:37 -0800)]
scsi: mpi3mr: Replace 1-element array with flex-array

Nothing else defined MPI3_NVME_ENCAP_CMD_MAX, so the "command" buffer was
being defined as a fake flexible array of size 1. Replace this with a
proper flex array. Avoids this GCC 13 warning under -fstrict-flex-arrays=3:

In function 'fortify_memset_chk',
    inlined from 'mpi3mr_build_nvme_sgl' at ../drivers/scsi/mpi3mr/mpi3mr_app.c:693:2,
    inlined from 'mpi3mr_bsg_process_mpt_cmds.constprop' at ../drivers/scsi/mpi3mr/mpi3mr_app.c:1214:8:
../include/linux/fortify-string.h:430:25: warning: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()?  [-Wattribute-warning]
  430 |                         __write_overflow_field(p_size_field, size);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Link: https://lore.kernel.org/r/20230204183715.never.937-kees@kernel.org
Cc: Sumit Saxena <sumit.saxena@broadcom.com>
Cc: Himanshu Madhani <himanshu.madhani@oracle.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: kernel test robot <lkp@intel.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ipr: Work around fortify-string warning
Arnd Bergmann [Tue, 14 Feb 2023 13:28:08 +0000 (14:28 +0100)]
scsi: ipr: Work around fortify-string warning

The ipr_log_vpd_compact() function triggers a fortified memcpy() warning
about a potential string overflow with all versions of clang:

In file included from drivers/scsi/ipr.c:43:
In file included from include/linux/string.h:254:
include/linux/fortify-string.h:520:4: error: call to '__write_overflow_field' declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning]
                        __write_overflow_field(p_size_field, size);
                        ^
include/linux/fortify-string.h:520:4: error: call to '__write_overflow_field' declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning]
2 errors generated.

I don't see anything actually wrong with the function, but this is the only
instance I can reproduce of the fortification going wrong in the kernel at
the moment, so the easiest solution may be to rewrite the function into
something that does not trigger the warning.

Instead of having a combined buffer for vendor/device/serial strings, use
three separate local variables and just truncate the whitespace
individually.

Link: https://lore.kernel.org/r/20230214132831.2118392-1-arnd@kernel.org
Cc: Kees Cook <keescook@chromium.org>
Fixes: 8cf093e275d0 ("[SCSI] ipr: Improved dual adapter errors")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Acked-by: Brian King <brking@linux.vnet.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ipr: Make ipr_probe_ioa_part2() return void
Deepak R Varma [Sun, 8 Jan 2023 16:28:51 +0000 (21:58 +0530)]
scsi: ipr: Make ipr_probe_ioa_part2() return void

Convert function ipr_probe_ioa_part2() to return void instead of int since
the current implementation always returns 0 to the caller.  The
transformation also eliminates the dead code when calling
ipr_probe_ioa_part2() function.  Issue identified using returnvar
Coccinelle semantic patch.

Link: https://lore.kernel.org/r/Y7rvQyMOGcPKPTv8@ubun2204.myguest.virtualbox.org
Signed-off-by: Deepak R Varma <drv@mailo.com>
Acked-by: Brian King <brking@linux.vnet.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: sd: Update DIX config every time sd_revalidate_disk() is called
Xingui Yang [Tue, 21 Feb 2023 08:10:26 +0000 (08:10 +0000)]
scsi: sd: Update DIX config every time sd_revalidate_disk() is called

If a controller has DIX is enabled and an attached disk is formatted using
a protection type supported by the controller, a block integrity profile is
registered to enable protected transfers.

If the disk is subsequently reformatted to disable PI, and the controller
does not support DIX Type 0, this can lead to failures such as this:

[142829.032340] hisi_sas_v3_hw 0000:b4:04.0: erroneous completion iptt=2375 task=00000000bea0970c dev id=5 direct-attached phy4 addr=51c20dbaf642a000 CQ hdr: 0x1023 0x50947 0x0 0x20000 Error info: 0x0 0x0 0x4 0x0
[142829.073883] sas: Enter sas_scsi_recover_host busy: 1 failed: 1
[142829.079783] sas: sas_scsi_find_task: aborting task 0x00000000bea0970c
[142829.102342] sas: Internal abort: task to dev 51c20dbaf642a000 response: 0x0 status 0x5
[142829.110319] sas: sas_eh_handle_sas_errors: task 0x00000000bea0970c is done
[142829.117275] sd 7:0:5:0: [sdc] tag#2375 UNKNOWN(0x2003) Result: hostbyte=0x05 driverbyte=DRIVER_OK cmd_age=0s
[142829.127171] sd 7:0:5:0: [sdc] tag#2375 CDB: opcode=0x2a 2a 00 00 00 00 00 00 00 08 00
[142829.135059] I/O error, dev sdc, sector 0 op 0x1:(WRITE) flags 0x18800 phys_seg 1 prio class 2

This is because the block layer integrity profile is currently only set up
the first time a disk is discovered.

To address this, remove the first_scan check when configuring protection
information during revalidate. Also unregister the block integrity profile
if DIX is not supported with a given protection type.

[mkp: commit description + printk dedup]

Link: https://lore.kernel.org/r/20230221081026.24736-1-yangxingui@huawei.com
Signed-off-by: Xingui Yang <yangxingui@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: sd: Remove unused sd_cdb_cache
Fengnan Chang [Tue, 21 Feb 2023 11:53:40 +0000 (19:53 +0800)]
scsi: sd: Remove unused sd_cdb_cache

Since commit ce70fd9a551a ("scsi: core: Remove the cmd field from struct
scsi_request") sd_cdb_cache is unused. Remove it.

Link: https://lore.kernel.org/r/20230221115340.21201-1-changfengnan@bytedance.com
Signed-off-by: Fengnan Chang <changfengnan@bytedance.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ufs: mcq: Fix incorrectly set queue depth
Asutosh Das [Thu, 16 Feb 2023 17:13:46 +0000 (09:13 -0800)]
scsi: ufs: mcq: Fix incorrectly set queue depth

ufshcd_config_mcq() may change the can_queue value. The current code
invokes scsi_add_host() before ufshcd_config_mcq() so the tags are
limited to the original can_queue value.

Fix this by invoking scsi_add_host() after ufshcd_config_mcq().

Link: https://lore.kernel.org/r/8840cea4a57b46dabce18acc39afc50ab826330f.1676567593.git.quic_asutoshd@quicinc.com
Fixes: 2468da61ea09 ("scsi: ufs: core: mcq: Configure operation and runtime interface")
Signed-off-by: Asutosh Das <quic_asutoshd@quicinc.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ufs: ufs-mediatek: Guard power management functions with CONFIG_PM
Yangtao Li [Mon, 20 Feb 2023 14:24:31 +0000 (22:24 +0800)]
scsi: ufs: ufs-mediatek: Guard power management functions with CONFIG_PM

Fix the following compilation error when CONFIG_PM is set to 'n':

drivers/ufs/host/ufs-mediatek.c: In function `ufs_mtk_runtime_suspend`:
drivers/ufs/host/ufs-mediatek.c:1623:8: error: implicit declaration of
function `ufshcd_runtime_suspend`; did you mean `ufs_mtk_runtime_suspend`?
[-Werror=implicit-function-declaration]
 1623 |  ret = ufshcd_runtime_suspend(dev);
      |        ^~~~~~~~~~~~~~~~~~~~~~
      |        ufs_mtk_runtime_suspend
drivers/ufs/host/ufs-mediatek.c: In function `ufs_mtk_runtime_resume`:
drivers/ufs/host/ufs-mediatek.c:1638:9: error: implicit declaration of function
`ufshcd_runtime_resume`; did you mean `ufs_mtk_runtime_resume`?
[-Werror=implicit-function-declaration]
 1638 |  return ufshcd_runtime_resume(dev);
      |         ^~~~~~~~~~~~~~~~~~~~~
      |         ufs_mtk_runtime_resume
At top level:
drivers/ufs/host/ufs-mediatek.c:1632:12: error: `ufs_mtk_runtime_resume`
defined but not used [-Werror=unused-function]
 1632 | static int ufs_mtk_runtime_resume(struct device *dev)
      |            ^~~~~~~~~~~~~~~~~~~~~~
drivers/ufs/host/ufs-mediatek.c:1618:12: error: `ufs_mtk_runtime_suspend`
defined but not used [-Werror=unused-function]
 1618 | static int ufs_mtk_runtime_suspend(struct device *dev)

Link: https://lore.kernel.org/r/20230220142431.54589-1-frank.li@vivo.com
Reported-by: k2ci <kernel-bot@kylinos.cn>
Reported-by: Shida Zhang <zhangshida@kylinos.cn>
Signed-off-by: Yangtao Li <frank.li@vivo.com>
Reviewed-by: Stanley Chu <stanley.chu@mediatek.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ufs: core: Initialize devfreq synchronously
Adrien Thierry [Fri, 17 Feb 2023 19:44:22 +0000 (14:44 -0500)]
scsi: ufs: core: Initialize devfreq synchronously

During UFS initialization, devfreq initialization is asynchronous:
ufshcd_async_scan() calls ufshcd_add_lus(), which in turn initializes
devfreq for UFS. The simple ondemand governor is then loaded. If it is
built as a module, request_module() is called and throws a warning:

  WARNING: CPU: 7 PID: 167 at kernel/kmod.c:136 __request_module+0x1e0/0x460
  Modules linked in: crct10dif_ce llcc_qcom phy_qcom_qmp_usb ufs_qcom phy_qcom_snps_femto_v2 ufshcd_pltfrm phy_qcom_qmp_combo ufshcd_core phy_qcom_qmp_ufs qcom_wdt socinfo fuse ipv6
  CPU: 7 PID: 167 Comm: kworker/u16:3 Not tainted 6.2.0-rc6-00009-g58706f7fb045 #1
  Hardware name: Qualcomm SA8540P Ride (DT)
  Workqueue: events_unbound async_run_entry_fn
  pstate: 00400005 (nzcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
  pc : __request_module+0x1e0/0x460
  lr : __request_module+0x1d8/0x460
  sp : ffff800009323b90
  x29: ffff800009323b90 x28: 0000000000000000 x27: 0000000000000000
  x26: ffff800009323d50 x25: ffff7b9045f57810 x24: ffff7b9045f57830
  x23: ffffdc5a83e426e8 x22: ffffdc5ae80a9818 x21: 0000000000000001
  x20: ffffdc5ae7502f98 x19: ffff7b9045f57800 x18: ffffffffffffffff
  x17: 312f716572667665 x16: 642f7366752e3030 x15: 0000000000000000
  x14: 000000000000021c x13: 0000000000005400 x12: ffff7b9042ed7614
  x11: ffff7b9042ed7600 x10: 00000000636c0890 x9 : 0000000000000038
  x8 : ffff7b9045f2c880 x7 : ffff7b9045f57c68 x6 : 0000000000000080
  x5 : 0000000000000000 x4 : 8000000000000000 x3 : 0000000000000000
  x2 : 0000000000000000 x1 : ffffdc5ae5d382f0 x0 : 0000000000000001
  Call trace:
   __request_module+0x1e0/0x460
   try_then_request_governor+0x7c/0x100
   devfreq_add_device+0x4b0/0x5fc
   ufshcd_async_scan+0x1d4/0x310 [ufshcd_core]
   async_run_entry_fn+0x34/0xe0
   process_one_work+0x1d0/0x320
   worker_thread+0x14c/0x444
   kthread+0x10c/0x110
   ret_from_fork+0x10/0x20

This occurs because synchronous module loading from async is not
allowed. According to __request_module():

  /*
   * We don't allow synchronous module loading from async.  Module
   * init may invoke async_synchronize_full() which will end up
   * waiting for this task which already is waiting for the module
   * loading to complete, leading to a deadlock.
   */

Such a deadlock was experienced on the Qualcomm QDrive3/sa8540p-ride. With
DEVFREQ_GOV_SIMPLE_ONDEMAND=m, the boot hangs after the warning.

Fix both the warning and the deadlock by moving devfreq initialization out
of the async routine.

Tested on the sa8540p-ride by using fio to put the UFS under load, and
printing the trace generated by
/sys/kernel/tracing/events/ufs/ufshcd_clk_scaling events. The trace looks
similar with and without the change.

Link: https://lore.kernel.org/r/20230217194423.42553-1-athierry@redhat.com
Signed-off-by: Adrien Thierry <athierry@redhat.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ufs: Make the TC G210 driver dependent on CONFIG_OF
Bart Van Assche [Thu, 9 Feb 2023 18:49:03 +0000 (10:49 -0800)]
scsi: ufs: Make the TC G210 driver dependent on CONFIG_OF

The TC G210 driver only supports devices declared in the device tree.
Hence make this driver dependent on CONFIG_OF. This patch fixes the
following compiler error:

drivers/ufs/host/tc-dwc-g210-pltfrm.c:36:34: error: â€˜tc_dwc_g210_pltfm_match’ defined but not used [-Werror=unused-const-variable=]
   36 | static const struct of_device_id tc_dwc_g210_pltfm_match[] = {
      |

Link: https://lore.kernel.org/r/20230209184914.2762172-1-bvanassche@acm.org
Cc: Joao Pinto <jpinto@synopsys.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Bean Huo <beanhuo@micron.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: scsi_transport_fc: Add an additional flag to fc_host_fpin_rcv()
Muneendra [Thu, 9 Feb 2023 03:43:26 +0000 (19:43 -0800)]
scsi: scsi_transport_fc: Add an additional flag to fc_host_fpin_rcv()

The LLDD and the stack currently process FPINs received from the fabric,
but the stack is not aware of any action taken by the driver to alleviate
congestion. The current interface between the driver and the SCSI stack is
limited to passing the notification mainly for statistics and heuristics.

The reaction to an FPIN could be handled either by the driver or by the
stack (marginal path and failover). Amend the interface to indicate if
action on an FPIN has already been reacted to by the LLDDs or not. Add an
additional flag to fc_host_fpin_rcv() to indicate if the FPIN has been
acknowledged/reacted to by the driver.

Also added a new event code FCH_EVT_LINK_FPIN_ACK to notify to the user
that the event has been acknowledged/reacted by the LLDD driver

Link: https://lore.kernel.org/r/20230209034326.882514-1-muneendra.kumar@broadcom.com
Co-developed-by: Anil Gurumurthy <agurumurthy@marvell.com>
Signed-off-by: Anil Gurumurthy <agurumurthy@marvell.com>
Co-developed-by: Nilesh Javali <njavali@marvell.com>
Signed-off-by: Nilesh Javali <njavali@marvell.com>
Signed-off-by: Muneendra <muneendra.kumar@broadcom.com>
Reviewed-by: James Smart <jsmart2021@gmail.com>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Reviewed-by: Ewan D. Milne <emilne@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ses: Don't attach if enclosure has no components
James Bottomley [Sat, 28 Nov 2020 23:27:21 +0000 (15:27 -0800)]
scsi: ses: Don't attach if enclosure has no components

An enclosure with no components can't usefully be operated by the driver
(since effectively it has nothing to manage), so report the problem and
don't attach. Not attaching also fixes an oops which could occur if the
driver tries to manage a zero component enclosure.

[mkp: Switched to KERN_WARNING since this scenario is common]

Link: https://lore.kernel.org/r/c5deac044ac409e32d9ad9968ce0dcbc996bfc7a.camel@linux.ibm.com
Cc: stable@vger.kernel.org
Reported-by: Ding Hui <dinghui@sangfor.com.cn>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ses: Fix slab-out-of-bounds in ses_intf_remove()
Tomas Henzl [Thu, 2 Feb 2023 16:24:51 +0000 (17:24 +0100)]
scsi: ses: Fix slab-out-of-bounds in ses_intf_remove()

A fix for:

BUG: KASAN: slab-out-of-bounds in ses_intf_remove+0x23f/0x270 [ses]
Read of size 8 at addr ffff88a10d32e5d8 by task rmmod/12013

When edev->components is zero, accessing edev->component[0] members is
wrong.

Link: https://lore.kernel.org/r/20230202162451.15346-5-thenzl@redhat.com
Cc: stable@vger.kernel.org
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ses: Fix possible desc_ptr out-of-bounds accesses
Tomas Henzl [Thu, 2 Feb 2023 16:24:50 +0000 (17:24 +0100)]
scsi: ses: Fix possible desc_ptr out-of-bounds accesses

Sanitize possible desc_ptr out-of-bounds accesses in
ses_enclosure_data_process().

Link: https://lore.kernel.org/r/20230202162451.15346-4-thenzl@redhat.com
Cc: stable@vger.kernel.org
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ses: Fix possible addl_desc_ptr out-of-bounds accesses
Tomas Henzl [Thu, 2 Feb 2023 16:24:49 +0000 (17:24 +0100)]
scsi: ses: Fix possible addl_desc_ptr out-of-bounds accesses

Sanitize possible addl_desc_ptr out-of-bounds accesses in
ses_enclosure_data_process().

Link: https://lore.kernel.org/r/20230202162451.15346-3-thenzl@redhat.com
Cc: stable@vger.kernel.org
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ses: Fix slab-out-of-bounds in ses_enclosure_data_process()
Tomas Henzl [Thu, 2 Feb 2023 16:24:48 +0000 (17:24 +0100)]
scsi: ses: Fix slab-out-of-bounds in ses_enclosure_data_process()

A fix for:

BUG: KASAN: slab-out-of-bounds in ses_enclosure_data_process+0x949/0xe30 [ses]
Read of size 1 at addr ffff88a1b043a451 by task systemd-udevd/3271

Checking after (and before in next loop) addl_desc_ptr[1] is sufficient, we
expect the size to be sanitized before first access to addl_desc_ptr[1].
Make sure we don't walk beyond end of page.

Link: https://lore.kernel.org/r/20230202162451.15346-2-thenzl@redhat.com
Cc: stable@vger.kernel.org
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ufs: core: Fix an error handling path in ufshcd_read_desc_param()
Christophe JAILLET [Sun, 15 Jan 2023 11:24:17 +0000 (12:24 +0100)]
scsi: ufs: core: Fix an error handling path in ufshcd_read_desc_param()

If an error occurs, some memory may need to be freed, as in the other error
handling paths.

Before the commit in the Fixes tag, this test was done before the memory
allocation, so there was no issue.

Fixes: 16ed9d312b42 ("scsi: ufs: core: Remove ufshcd_map_desc_id_to_length()")
Link: https://lore.kernel.org/r/2c6e42205e5ec22e5e8c7c85c6deb8fde31c74da.1673781835.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ufs: core: Fix device management cmd timeout flow
Mason Zhang [Fri, 16 Dec 2022 03:25:33 +0000 (11:25 +0800)]
scsi: ufs: core: Fix device management cmd timeout flow

In the UFS error handling flow, the host will send a device management cmd
(NOP OUT) to the device for link recovery. If this cmd times out and
clearing the doorbell fails, ufshcd_wait_for_dev_cmd() will do nothing and
return. hba->dev_cmd.complete struct is not set to NULL.

When this happens, if cmd has been completed by device, then we will call
complete() in __ufshcd_transfer_req_compl(). Because the complete struct is
allocated on the stack, the following crash will occur:

  ipanic_die+0x24/0x38 [mrdump]
  die+0x344/0x748
  arm64_notify_die+0x44/0x104
  do_debug_exception+0x104/0x1e0
  el1_dbg+0x38/0x54
  el1_sync_handler+0x40/0x88
  el1_sync+0x8c/0x140
  queued_spin_lock_slowpath+0x2e4/0x3c0
  __ufshcd_transfer_req_compl+0x3b0/0x1164
  ufshcd_trc_handler+0x15c/0x308
  ufshcd_host_reset_and_restore+0x54/0x260
  ufshcd_reset_and_restore+0x28c/0x57c
  ufshcd_err_handler+0xeb8/0x1b6c
  process_one_work+0x288/0x964
  worker_thread+0x4bc/0xc7c
  kthread+0x15c/0x264
  ret_from_fork+0x10/0x30

Link: https://lore.kernel.org/r/20221216032532.1280-1-mason.zhang@mediatek.com
Signed-off-by: Mason Zhang <Mason.Zhang@mediatek.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: aic94xx: Add missing check for dma_map_single()
Jiasheng Jiang [Sat, 28 Jan 2023 11:08:32 +0000 (19:08 +0800)]
scsi: aic94xx: Add missing check for dma_map_single()

Add check for dma_map_single() and return error if it fails in order to
avoid invalid DMA address.

Fixes: 2908d778ab3e ("[SCSI] aic94xx: new driver")
Link: https://lore.kernel.org/r/20230128110832.6792-1-jiasheng@iscas.ac.cn
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Jason Yan <yanaijie@huawei.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: smartpqi: Replace one-element array with flexible-array member
Gustavo A. R. Silva [Tue, 7 Feb 2023 21:59:43 +0000 (15:59 -0600)]
scsi: smartpqi: Replace one-element array with flexible-array member

One-element arrays are deprecated, and we are replacing them with flexible
array members instead. So, replace one-element array with flexible-array
member in struct report_log_lun_list.

This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines
on memcpy().

Link: https://lore.kernel.org/r/Y+LJz/r6+UeLqnV3@work
Link: https://github.com/KSPP/linux/issues/79
Link: https://github.com/KSPP/linux/issues/204
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Acked-by: Don Brace <don.brace@microchip.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: mpt3sas: Fix a memory leak
Tomas Henzl [Tue, 7 Feb 2023 15:21:59 +0000 (16:21 +0100)]
scsi: mpt3sas: Fix a memory leak

Add a forgotten kfree().

Fixes: dbec4c9040ed ("scsi: mpt3sas: lockless command submission")
Link: https://lore.kernel.org/r/20230207152159.18627-1-thenzl@redhat.com
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: qla2xxx: Remove the unused variable wwn
Jiapeng Chong [Tue, 7 Feb 2023 05:22:34 +0000 (13:22 +0800)]
scsi: qla2xxx: Remove the unused variable wwn

Variable wwn is not used. Delete it.

drivers/scsi/qla2xxx/qla_init.c:1657:6: warning: variable 'wwn' set but not used.

Link: https://lore.kernel.org/r/20230207052234.24535-1-jiapeng.chong@linux.alibaba.com
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ufs: core: Fix kernel-doc syntax
Bart Van Assche [Thu, 2 Feb 2023 22:01:42 +0000 (14:01 -0800)]
scsi: ufs: core: Fix kernel-doc syntax

Fix the following kernel-doc warnings:

drivers/ufs/core/ufs-mcq.c:87: warning: Function parameter or member 'hba' not described in 'ufshcd_mcq_config_mac'
drivers/ufs/core/ufs-mcq.c:87: warning: Function parameter or member 'max_active_cmds' not described in 'ufshcd_mcq_config_mac'
drivers/ufs/core/ufs-mcq.c:107: warning: Function parameter or member 'hba' not described in 'ufshcd_mcq_req_to_hwq'
drivers/ufs/core/ufs-mcq.c:107: warning: Function parameter or member 'req' not described in 'ufshcd_mcq_req_to_hwq'
drivers/ufs/core/ufs-mcq.c:128: warning: Function parameter or member 'hba' not described in 'ufshcd_mcq_decide_queue_depth'

Link: https://lore.kernel.org/r/20230202220155.561115-1-bvanassche@acm.org
Fixes: 854f84e7feeb ("scsi: ufs: core: mcq: Find hardware queue to queue request")
Fixes: 2468da61ea09 ("scsi: ufs: core: mcq: Configure operation and runtime interface")
Fixes: 7224c806876e ("scsi: ufs: core: mcq: Calculate queue depth")
Cc: Asutosh Das <quic_asutoshd@quicinc.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Asutosh Das <quic_asutoshd@quicinc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ufs: core: Add hibernation callbacks
Anjana Hari [Thu, 2 Feb 2023 16:10:45 +0000 (21:40 +0530)]
scsi: ufs: core: Add hibernation callbacks

Add freeze, thaw, and restore callbacks for hibernate and restore
functionality.

Link: https://lore.kernel.org/r/20230202161045.3956-2-quic_ahari@quicinc.com
Signed-off-by: Anjana Hari <quic_ahari@quicinc.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: snic: Fix memory leak with using debugfs_lookup()
Greg Kroah-Hartman [Thu, 2 Feb 2023 14:10:09 +0000 (15:10 +0100)]
scsi: snic: Fix memory leak with using debugfs_lookup()

When calling debugfs_lookup() the result must have dput() called on it,
otherwise the memory will leak over time.  To make things simpler, just
call debugfs_lookup_and_remove() instead which handles all of the logic at
once.

Link: https://lore.kernel.org/r/20230202141009.2290380-1-gregkh@linuxfoundation.org
Cc: Karan Tilak Kumar <kartilak@cisco.com>
Cc: Sesidhar Baddela <sebaddel@cisco.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ufs: core: Limit DMA alignment check
Bjorn Andersson [Wed, 1 Feb 2023 03:49:17 +0000 (19:49 -0800)]
scsi: ufs: core: Limit DMA alignment check

The three DMA memory regions allocated for the host memory space are
documented to require alignment of 128, 1024, and 1024 respectively, but
the returned address is checked for PAGE_SIZE alignment.

In the case where these allocations are serviced by e.g. the Arm SMMU, the
size and alignment will be determined by its supported page sizes. In most
cases SZ_4K and a few larger sizes are available.

In the typical configuration this does not cause problems, but in the event
that the system PAGE_SIZE is increased beyond 4k, it's no longer reasonable
to expect that the allocation will be PAGE_SIZE aligned.

Limit the DMA alignment check to the actual alignment requirements written
in the comments in the code, to avoid the UFS core refusing to initialize
with such configuration.

Link: https://lore.kernel.org/r/20230201034917.1902330-1-quic_bjorande@quicinc.com
Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Asutosh Das <quic_asutoshd@quicinc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: Documentation: Correct spelling
Randy Dunlap [Sun, 29 Jan 2023 23:10:51 +0000 (15:10 -0800)]
scsi: Documentation: Correct spelling

Correct spelling problems for Documentation/scsi/ as reported by codespell.

Link: https://lore.kernel.org/r/20230129231053.20863-8-rdunlap@infradead.org
Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: linux-doc@vger.kernel.org
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: Documentation: Correct spelling
Randy Dunlap [Sun, 29 Jan 2023 23:10:50 +0000 (15:10 -0800)]
scsi: Documentation: Correct spelling

Correct spelling problems for Documentation/scsi/ ChangeLogs as reported by
codespell.

Link: https://lore.kernel.org/r/20230129231053.20863-7-rdunlap@infradead.org
Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: linux-doc@vger.kernel.org
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: target: Documentation: Correct spelling
Randy Dunlap [Fri, 27 Jan 2023 06:39:58 +0000 (22:39 -0800)]
scsi: target: Documentation: Correct spelling

Correct spelling problems for Documentation/target/ as reported by
codespell.

Link: https://lore.kernel.org/r/20230127064005.1558-29-rdunlap@infradead.org
Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org
Cc: target-devel@vger.kernel.org
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: linux-doc@vger.kernel.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: aacraid: Allocate cmd_priv with scsicmd
Kees Cook [Sat, 28 Jan 2023 00:04:13 +0000 (16:04 -0800)]
scsi: aacraid: Allocate cmd_priv with scsicmd

The aac_priv() helper assumes that the private cmd area immediately follows
struct scsi_cmnd. Allocate this space as part of scsicmd, else there is a
risk of heap overflow. Seen with GCC 13:

../drivers/scsi/aacraid/aachba.c: In function 'aac_probe_container':
../drivers/scsi/aacraid/aachba.c:841:26: warning: array subscript 16 is outside array bounds of 'void[392]' [-Warray-bounds=]
  841 |         status = cmd_priv->status;
      |                          ^~
In file included from ../include/linux/resource_ext.h:11,
                 from ../include/linux/pci.h:40,
                 from ../drivers/scsi/aacraid/aachba.c:22:
In function 'kmalloc',
    inlined from 'kzalloc' at ../include/linux/slab.h:720:9,
    inlined from 'aac_probe_container' at ../drivers/scsi/aacraid/aachba.c:821:30:
../include/linux/slab.h:580:24: note: at offset 392 into object of size 392 allocated by 'kmalloc_trace'
  580 |                 return kmalloc_trace(
      |                        ^~~~~~~~~~~~~~
  581 |                                 kmalloc_caches[kmalloc_type(flags)][index],
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  582 |                                 flags, size);
      |                                 ~~~~~~~~~~~~

Fixes: 76a3451b64c6 ("scsi: aacraid: Move the SCSI pointer to private command data")
Link: https://lore.kernel.org/r/20230128000409.never.976-kees@kernel.org
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Himanshu Madhani <himanshu.madhani@oracle.com>
Cc: Adaptec OEM Raid Solutions <aacraid@microsemi.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org
Cc: stable@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Vegard Nossum <vegard.nossum@oracle.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoMerge patch series "ufs: host: ufs-qcom: Add support for SM8550"
Martin K. Petersen [Wed, 8 Feb 2023 23:06:39 +0000 (18:06 -0500)]
Merge patch series "ufs: host: ufs-qcom: Add support for SM8550"

Abel Vesa <abel.vesa@linaro.org> says:

This patchset adds UFS HC support for the new Qualcomm SM8550 SoC.

Link: https://lore.kernel.org/r/20230119151406.4168685-1-abel.vesa@linaro.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ufs: qcom: dt-bindings: Add SM8550 compatible string
Abel Vesa [Thu, 19 Jan 2023 15:14:06 +0000 (17:14 +0200)]
scsi: ufs: qcom: dt-bindings: Add SM8550 compatible string

Document the compatible string for the UFS found on SM8550.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Acked-by: Manivannan Sadhasivam <mani@kernel.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ufs: ufs-qcom: Clear qunipro_g4_sel for HW version major 5
Abel Vesa [Thu, 19 Jan 2023 15:14:05 +0000 (17:14 +0200)]
scsi: ufs: ufs-qcom: Clear qunipro_g4_sel for HW version major 5

On SM8550, depending on the Qunipro, we can run with G5 or G4.  For now,
when the major version is 5 or above, we go with G5.  Therefore, we need to
specifically tell UFS HC that.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
15 months agoscsi: ufs: qcom: fix platform_msi_domain_free_irqs() reference
Arnd Bergmann [Thu, 26 Jan 2023 21:17:31 +0000 (22:17 +0100)]
scsi: ufs: qcom: fix platform_msi_domain_free_irqs() reference

The newly added MSI support is mostly hidden inside of an #ifdef,
except for one line that now causes a build failure when MSI
is disabled:

drivers/ufs/host/ufs-qcom.c: In function 'ufs_qcom_remove':
drivers/ufs/host/ufs-qcom.c:1698:9: error: implicit declaration of function 'platform_msi_domain_free_irqs' [-Werror=i]
 1698 |         platform_msi_domain_free_irqs(hba->dev);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Above that, the symbol that guards the other call was recently removed, so
that is all dead code at the moment.

Remove the incorrect #ifdef and instead of a Kconfig dependency to only
allow building the driver when CONFIG_GENERIC_MSI_IRQ is enabled. This
symbol is always present when PCI_MSI or ARM_GIC_V3_ITS are enabled, both
of which should be present on kernels that can run on Qualcomm SoCs.

The 'select RESET_CONTROLLER' in combination with this dependency
unfortunately causes a dependency loop and this is a user-visible symbol,
so it's better to change both to 'depends on'.

Link: https://lore.kernel.org/r/20230126211831.2274211-1-arnd@kernel.org
Fixes: 519b6274a777 ("scsi: ufs: qcom: Add MCQ ESI config vendor specific ops")
Fixes: 13e7accb81d6 ("genirq: Get rid of GENERIC_MSI_IRQ_DOMAIN")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Acked-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoMerge patch series "Enable DMA clustering in the UFS driver"
Martin K. Petersen [Tue, 24 Jan 2023 02:38:10 +0000 (21:38 -0500)]
Merge patch series "Enable DMA clustering in the UFS driver"

Bart Van Assche <bvanassche@acm.org> says:

The third patch in this series enables DMA clustering in the UFS
driver since UFS host controllers support DMA clustering. The first
two patches fix bugs in the Exynos host controller driver.

Link: https://lore.kernel.org/r/20230112234215.2630817-1-bvanassche@acm.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: core: Enable DMA clustering
Bart Van Assche [Thu, 12 Jan 2023 23:42:15 +0000 (15:42 -0800)]
scsi: ufs: core: Enable DMA clustering

All UFS host controllers support DMA clustering. Hence enable DMA
clustering.

Notes:

 - The max_segment_size parameter implements the 256 KiB limit for the
   PRDT. The dma_boundary parameter represents a boundary that must not be
   crossed by DMA scatter/gather lists. I'm not aware of any restrictions
   on DMA scatter/gather lists in the UFSHCI specification other than the
   256 KiB limit for the PRDT and the 32-bit address restriction for
   controllers that only support 32-bits DMA. The latter restriction is
   already handled by ufshcd_set_dma_mask().

 - Without patch "scsi: ufs: exynos: Fix the maximum segment size", this
   patch breaks support for the Exynos controller.

The history of the dma_boundary parameter in the UFS driver is as
follows:

 * The initial UFS driver did not set the dma_boundary parameter.

 * Commit 4dd4130a722f ("scsi: make sure all drivers set the use_clustering
   flag") set the .use_clustering flag.

 * Commit 4af14d113bcf ("scsi: remove the use_clustering flag") removed the
   use_clustering flag and set the dma_boundary parameter instead.

Cc: Avri Altman <avri.altman@wdc.com>
Cc: Alim Akhtar <alim.akhtar@samsung.com>
Cc: Kiwoong Kim <kwmad.kim@samsung.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Reviewed-by: Alim Akhtar <alim.akhtar@samsung.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: exynos: Fix the maximum segment size
Bart Van Assche [Thu, 12 Jan 2023 23:42:14 +0000 (15:42 -0800)]
scsi: ufs: exynos: Fix the maximum segment size

Prepare for enabling DMA clustering and also for supporting PAGE_SIZE !=
4096 by declaring explicitly that the maximum segment size is 4096 bytes
for Exynos UFS host controllers. Add this code in
exynos_ufs_hce_enable_notify() such that it happens after scsi_host_alloc()
and before __scsi_init_queue() is called by the LUN scanning code.

Cc: Alim Akhtar <alim.akhtar@samsung.com>
Cc: Kiwoong Kim <kwmad.kim@samsung.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Alim Akhtar <alim.akhtar@samsung.com>
Tested-by: Alim Akhtar <alim.akhtar@samsung.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: exynos: Fix DMA alignment for PAGE_SIZE != 4096
Bart Van Assche [Thu, 12 Jan 2023 23:42:13 +0000 (15:42 -0800)]
scsi: ufs: exynos: Fix DMA alignment for PAGE_SIZE != 4096

The Exynos UFS controller only supports scatter/gather list elements that
are aligned on a 4 KiB boundary. Fix DMA alignment in case PAGE_SIZE !=
4096. Rename UFSHCD_QUIRK_ALIGN_SG_WITH_PAGE_SIZE into
UFSHCD_QUIRK_4KB_DMA_ALIGNMENT.

Cc: Kiwoong Kim <kwmad.kim@samsung.com>
Fixes: 2b2bfc8aa519 ("scsi: ufs: Introduce a quirk to allow only page-aligned sg entries")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Alim Akhtar <alim.akhtar@samsung.com>
Tested-by: Alim Akhtar <alim.akhtar@samsung.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: qla2xxx: Simplify if condition evaluation
Deepak R Varma [Thu, 12 Jan 2023 06:26:46 +0000 (11:56 +0530)]
scsi: qla2xxx: Simplify if condition evaluation

A logical evaluation of type (!A || A && B) can be simplified as (!A || B).
Improvement by suggested by excluded_middle.cocci Coccinelel semantic
patch.

Link: https://lore.kernel.org/r/Y7+oJuah0MgEW0PQ@ubun2204.myguest.virtualbox.org
Signed-off-by: Deepak R Varma <drv@mailo.com>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: qla2xxx: Use a variable for repeated mem_size computation
Deepak R Varma [Sun, 8 Jan 2023 20:38:24 +0000 (02:08 +0530)]
scsi: qla2xxx: Use a variable for repeated mem_size computation

Use a variable to compute memory size to be allocated once instead of
repeatedly computing it at different locations in the function. Issue
identified using the array_size_dup Coccinelle semantic patch.

Link: https://lore.kernel.org/r/Y7spwF8HTt0c0l7y@ubun2204.myguest.virtualbox.org
Signed-off-by: Deepak R Varma <drv@mailo.com>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: elx: libefc_sli: Use "/*" for non-kernel-doc comment
Randy Dunlap [Tue, 17 Jan 2023 07:01:51 +0000 (23:01 -0800)]
scsi: elx: libefc_sli: Use "/*" for non-kernel-doc comment

Don't use "/**" to begin non-kernel-doc comments.  Prevent a kernel-doc
warning:

drivers/scsi/elx/libefc_sli/sli4.c:13: warning: cannot understand function prototype: 'struct sli4_asic_entry_t sli4_asic_table[] = '

Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Cc: James Smart <james.smart@broadcom.com>
Cc: Ram Vegesna <ram.vegesna@broadcom.com>
Cc: target-devel@vger.kernel.org
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Link: https://lore.kernel.org/r/20230117070151.29339-1-rdunlap@infradead.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: qcom: dt-bindings: Allow 'dma-coherent' property
Johan Hovold [Mon, 16 Jan 2023 16:42:36 +0000 (17:42 +0100)]
scsi: ufs: qcom: dt-bindings: Allow 'dma-coherent' property

UFS controllers may be cache coherent and must be marked as such in the
devicetree to avoid data corruption.

This is specifically needed on recent Qualcomm platforms like SC8280XP.

Reviewed-by: Rob Herring <robh@kernel.org>
Reviewed-by: Bjorn Andersson <andersson@kernel.org>
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
Link: https://lore.kernel.org/r/20230116164236.18958-1-johan+linaro@kernel.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: qla2xxx: Make qla_trim_buf() and __qla_adjust_buf() static
Tom Rix [Sat, 14 Jan 2023 01:37:24 +0000 (20:37 -0500)]
scsi: qla2xxx: Make qla_trim_buf() and __qla_adjust_buf() static

Smatch reports:

drivers/scsi/qla2xxx/qla_mid.c:1189:6: warning: symbol 'qla_trim_buf' was not declared. Should it be static?
drivers/scsi/qla2xxx/qla_mid.c:1221:6: warning: symbol '__qla_adjust_buf' was not declared. Should it be static?

These functions are only used in qla_mid.c, so they should be static.

Fixes: 1f8f9c34127e ("scsi: qla2xxx: edif: Reduce memory usage during low I/O")
Signed-off-by: Tom Rix <trix@redhat.com>
Link: https://lore.kernel.org/r/20230114013724.3943580-1-trix@redhat.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ipr: Replace kmap() with kmap_local_page()
Fabio M. De Francesco [Tue, 3 Jan 2023 18:25:56 +0000 (19:25 +0100)]
scsi: ipr: Replace kmap() with kmap_local_page()

The use of kmap() is deprecated in favor of kmap_local_page().

There are two main problems with kmap(): (1) It comes with an overhead as
the mapping space is restricted and protected by a global lock for
synchronization and (2) it also requires global TLB invalidation when the
kmap’s pool wraps and it might block when the mapping space is fully
utilized until a slot becomes available.

With kmap_local_page() the mappings are per thread, CPU local, can take
page faults, and can be called from any context (including interrupts).  It
is faster than kmap() in kernels with HIGHMEM enabled. Furthermore, the
tasks can be preempted and, when they are scheduled to run again, the
kernel virtual addresses are restored and still valid.

Therefore, replace kmap() with kmap_local_page() in ipr_copy_ucode_buffer()
and, instead of open-coding local mappings + memcpy() + local un-mappings,
use the better suited memcpy_to_page() helper.

Suggested-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
Link: https://lore.kernel.org/r/20230103182556.29080-1-fmdefrancesco@gmail.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ips: Replace kmap_atomic() with kmap_local_page()
Fabio M. De Francesco [Tue, 3 Jan 2023 17:31:31 +0000 (18:31 +0100)]
scsi: ips: Replace kmap_atomic() with kmap_local_page()

kmap_atomic() is deprecated in favor of kmap_local_page(). Therefore,
replace kmap_atomic() with kmap_local_page() in ips_is_passthru(). In the
meantime remove an unnecessary comment, align code, and remove spaces.

kmap_atomic() is implemented like a kmap_local_page() which also disables
page-faults and preemption (the latter only for !PREEMPT_RT kernels).  The
code within the mapping/unmapping in ips_is_passthru() is already in atomic
context because of a call to local_irq_save() and kmap_local_page() can be
called in atomic context too (including interrupts).

Therefore, a mere replacement of the old API with the new one is all it is
required (i.e., there is no need to explicitly add any calls to
pagefault_disable() and/or preempt_disable()).

Suggested-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Link: https://lore.kernel.org/r/20230103173131.21259-1-fmdefrancesco@gmail.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: mpt3sas: Demote log level for trace buffer allocation to info
Paul Menzel [Tue, 3 Jan 2023 15:04:37 +0000 (16:04 +0100)]
scsi: mpt3sas: Demote log level for trace buffer allocation to info

Linux logs the error below:

    $ dmesg --level=err | grep mpt
    [    7.647675] mpt3sas_cm0: Trace buffer memory 2048 KB allocated

This state does not denote an error condition (and also no warning), so
demote the level from error to info.

Cc: it+linux-scsi@molgen.mpg.de
Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
Link: https://lore.kernel.org/r/20230103150438.45922-1-pmenzel@molgen.mpg.de
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: qla2xxx: Fix printk() format string
Arnd Bergmann [Tue, 17 Jan 2023 17:00:15 +0000 (18:00 +0100)]
scsi: qla2xxx: Fix printk() format string

Printing a size_t value that is the result of the sizeof() operator
requires using the %z format string modifier to avoid a warning on 32-bit
architectures:

drivers/scsi/qla2xxx/qla_mid.c: In function 'qla_create_buf_pool':
drivers/scsi/qla2xxx/qla_mid.c:1094:51: error: format '%ld' expects argument of type 'long int', but argument 5 has type 'unsigned int' [-Werror=format=]
 1094 |                     "Failed to allocate buf_map(%ld).\n", sz * sizeof(unsigned long));
      |                                                 ~~^       ~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                   |          |
      |                                                   long int   unsigned int
      |                                                 %d

Fixes: 82d8dfd2a238 ("scsi: qla2xxx: edif: Fix performance dip due to lock contention")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Himanshu Madhani <himansnhu.madhani@oracle.com <mailto:himansnhu.madhani@oracle.com>>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Link: https://lore.kernel.org/r/20230117170029.2387516-1-arnd@kernel.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: MAINTAINERS: Add entry for Exynos UFS driver
Alim Akhtar [Sat, 14 Jan 2023 08:02:47 +0000 (13:32 +0530)]
scsi: MAINTAINERS: Add entry for Exynos UFS driver

Add maintainer entry for Exynos UFS driver.

Signed-off-by: Alim Akhtar <alim.akhtar@samsung.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Link: https://lore.kernel.org/r/20230114080247.601312-1-alim.akhtar@samsung.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: ufs: Remove duplicate entry
Alim Akhtar [Sat, 14 Jan 2023 02:20:10 +0000 (07:50 +0530)]
scsi: ufs: ufs: Remove duplicate entry

PA_GRANULARITY is duplicated, delete one of the entries.

Signed-off-by: Alim Akhtar <alim.akhtar@samsung.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Link: https://lore.kernel.org/r/20230114022010.27088-1-alim.akhtar@samsung.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: megaraid_sas: Add flexible array member for SGLs
Kees Cook [Fri, 6 Jan 2023 05:32:00 +0000 (21:32 -0800)]
scsi: megaraid_sas: Add flexible array member for SGLs

struct MPI2_RAID_SCSI_IO_REQUEST ends with a single SGL, but expects to
copy multiple. Add a flexible array member so the compiler can reason about
the size of the memcpy(). This will avoid the run-time false positive
warning:

  memcpy: detected field-spanning write (size 128) of single field "&r1_cmd->io_request->SGL" at drivers/scsi/megaraid/megaraid_sas_fusion.c:3326 (size 16)

This change results in no binary output differences.

Reported-by: Holger Kiehl <Holger.Kiehl@dwd.de>
Link: https://lore.kernel.org/all/88de8faa-56c4-693d-2d3-67152ee72057@diagnostix.dwd.de/
Cc: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: Sumit Saxena <sumit.saxena@broadcom.com>
Cc: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: megaraidlinux.pdl@broadcom.com
Cc: linux-scsi@vger.kernel.org
Link: https://lore.kernel.org/r/20230106053153.never.999-kees@kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Tested-by: Holger Kiehl <Holger.Kiehl@dwd.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoMerge patch series "scsi: Add struct for args to execution functions"
Martin K. Petersen [Wed, 18 Jan 2023 23:15:20 +0000 (18:15 -0500)]
Merge patch series "scsi: Add struct for args to execution functions"

Mike Christie <michael.christie@oracle.com> says:

The following patches were made over Martin's scsi-staging/next
branch.  They add a struct that contains optinal arguments to the
scsi_execute* functions. This will be needed for the patches that
allow the SCSI passthrough users to control retries because I'm adding
a new optional argument. I separated the 2 sets to make it easier to
review and post.

Link: https://lore.kernel.org/r/20221229190154.7467-1-michael.christie@oracle.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: core: Remove scsi_execute_req()/scsi_execute() functions
Mike Christie [Thu, 29 Dec 2022 19:01:54 +0000 (13:01 -0600)]
scsi: core: Remove scsi_execute_req()/scsi_execute() functions

scsi_execute() and scsi_execute_req() are no longer used so remove them.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: cxlflash: Convert to scsi_execute_cmd()
Mike Christie [Thu, 29 Dec 2022 19:01:53 +0000 (13:01 -0600)]
scsi: cxlflash: Convert to scsi_execute_cmd()

scsi_execute() is going to be removed. Convert cxlflash to use
scsi_execute_cmd().

[mkp: roll in fix for issue reported by sfr]

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: target: target_core_pscsi: Convert to scsi_execute_cmd()
Mike Christie [Thu, 29 Dec 2022 19:01:52 +0000 (13:01 -0600)]
scsi: target: target_core_pscsi: Convert to scsi_execute_cmd()

scsi_execute_req() is going to be removed. Convert pscsi to
scsi_execute_cmd().

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: virtio_scsi: Convert to scsi_execute_cmd()
Mike Christie [Thu, 29 Dec 2022 19:01:51 +0000 (13:01 -0600)]
scsi: virtio_scsi: Convert to scsi_execute_cmd()

scsi_execute_req() is going to be removed. Convert virtio_scsi to
scsi_execute_cmd().

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: sr: Convert to scsi_execute_cmd()
Mike Christie [Thu, 29 Dec 2022 19:01:50 +0000 (13:01 -0600)]
scsi: sr: Convert to scsi_execute_cmd()

scsi_execute*() is going to be removed. Convert sr to scsi_execute_cmd().

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ses: Convert to scsi_execute_cmd()
Mike Christie [Thu, 29 Dec 2022 19:01:49 +0000 (13:01 -0600)]
scsi: ses: Convert to scsi_execute_cmd()

scsi_execute_req() is going to be removed. Convert ses to
scsi_execute_cmd().

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: zbc: Convert to scsi_execute_cmd()
Mike Christie [Thu, 29 Dec 2022 19:01:48 +0000 (13:01 -0600)]
scsi: zbc: Convert to scsi_execute_cmd()

scsi_execute_req() is going to be removed. Conver zbc to
scsi_execute_cmd().

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: sd: Convert to scsi_execute_cmd()
Mike Christie [Thu, 29 Dec 2022 19:01:47 +0000 (13:01 -0600)]
scsi: sd: Convert to scsi_execute_cmd()

scsi_execute*() is going to be removed. Convert sd_mod to use
scsi_execute_cmd().

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: spi: Convert to scsi_execute_cmd()
Mike Christie [Thu, 29 Dec 2022 19:01:46 +0000 (13:01 -0600)]
scsi: spi: Convert to scsi_execute_cmd()

scsi_execute() is going to be removed. Convert to the SPI class to
scsi_execute_cmd().

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: core: Convert to scsi_execute_cmd()
Mike Christie [Thu, 29 Dec 2022 19:01:45 +0000 (13:01 -0600)]
scsi: core: Convert to scsi_execute_cmd()

scsi_execute_req() is going to be removed. Convert SCSI midlayer to
scsi_execute_cmd().

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: scsi_dh: Convert to scsi_execute_cmd()
Mike Christie [Thu, 29 Dec 2022 19:01:44 +0000 (13:01 -0600)]
scsi: scsi_dh: Convert to scsi_execute_cmd()

scsi_execute() is going to be removed. Convert the scsi_dh users to
scsi_execute_cmd().

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ch: Convert to scsi_execute_cmd()
Mike Christie [Thu, 29 Dec 2022 19:01:43 +0000 (13:01 -0600)]
scsi: ch: Convert to scsi_execute_cmd()

scsi_execute_req() is going to be removed. Convert ch to
scsi_execute_cmd().

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: hwmon: drivetemp: Convert to scsi_execute_cmd()
Mike Christie [Thu, 29 Dec 2022 19:01:42 +0000 (13:01 -0600)]
scsi: hwmon: drivetemp: Convert to scsi_execute_cmd()

scsi_execute_req() is going to be removed. Convert drivetemp to
scsi_execute_cmd().

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ata: libata-scsi: Convert to scsi_execute_cmd()
Mike Christie [Thu, 29 Dec 2022 19:01:41 +0000 (13:01 -0600)]
scsi: ata: libata-scsi: Convert to scsi_execute_cmd()

scsi_execute_req() is going to be removed. Convert libata to
scsi_execute_cmd().

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Acked-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: core: Add struct for args to execution functions
Mike Christie [Thu, 29 Dec 2022 19:01:40 +0000 (13:01 -0600)]
scsi: core: Add struct for args to execution functions

Move the SCSI execution functions to use a struct for passing in optional
args. This commit adds the new struct, temporarily converts scsi_execute()
and scsi_execute_req() ands a new helper, scsi_execute_cmd(), which takes
the scsi_exec_args struct.

There should be no change in behavior. We no longer allow users to pass in
any request->rq_flags value, but they were only passing in RQF_PM which we
do support by allowing users to pass in the BLK_MQ_REQ flags used by
blk_mq_alloc_request().

Subsequent commits will convert scsi_execute() and scsi_execute_req() users
to the new helpers then remove scsi_execute() and scsi_execute_req().

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoMerge patch series "Add support for UFS Event Specific Interrupt"
Martin K. Petersen [Sat, 14 Jan 2023 02:15:07 +0000 (21:15 -0500)]
Merge patch series "Add support for UFS Event Specific Interrupt"

Can Guo <quic_cang@quicinc.com> says:

This patch series is to enable Event Specific Interrupt (ESI) which
can used in MCQ mode.

Link: https://lore.kernel.org/r/1671073583-10065-1-git-send-email-quic_cang@quicinc.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoMerge patch series "Add Multi Circular Queue Support"
Martin K. Petersen [Sat, 14 Jan 2023 02:13:43 +0000 (21:13 -0500)]
Merge patch series "Add Multi Circular Queue Support"

Asutosh Das <quic_asutoshd@quicinc.com> says:

This patch series is an implementation of UFS Multi-Circular Queue.
Please consider this series for next merge window.  This
implementation has been verified on a Qualcomm & MediaTek platform.

UFS Multi-Circular Queue (MCQ) has been added in UFSHCI v4.0 to
improve storage performance.  The implementation uses the shared
tagging mechanism so that tags are shared among the hardware
queues. The number of hardware queues is configurable.  This series
doesn't include the ESI implementation for completion handling.

Link: https://lore.kernel.org/r/cover.1673557949.git.quic_asutoshd@quicinc.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: qcom: Add MCQ ESI config vendor specific ops
Can Guo [Thu, 15 Dec 2022 03:06:22 +0000 (19:06 -0800)]
scsi: ufs: qcom: Add MCQ ESI config vendor specific ops

Add MCQ ESI config vendor specific ops.

Co-developed-by: Asutosh Das <quic_asutoshd@quicinc.com>
Signed-off-by: Asutosh Das <quic_asutoshd@quicinc.com>
Signed-off-by: Can Guo <quic_cang@quicinc.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: core: mcq: Add Event Specific Interrupt enable and config functions
Can Guo [Thu, 15 Dec 2022 03:06:21 +0000 (19:06 -0800)]
scsi: ufs: core: mcq: Add Event Specific Interrupt enable and config functions

Add and export two functions to enable ESI and config ESI base addresses.
The calls to these exported functions will be added by the next patch in
this series.

Signed-off-by: Can Guo <quic_cang@quicinc.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: core: Add Event Specific Interrupt configuration vendor specific ops
Can Guo [Thu, 15 Dec 2022 03:06:20 +0000 (19:06 -0800)]
scsi: ufs: core: Add Event Specific Interrupt configuration vendor specific ops

As Event Specific Interrupt message format is not defined in UFSHCI JEDEC
specs, and the ESI handling highly depends on how the format is designed,
hence add a vendor specific ops such that SoC vendors can configure their
own ESI handlers. If ESI vops is not provided or returning error, go with
the legacy (central) interrupt way.

Signed-off-by: Can Guo <quic_cang@quicinc.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: core: mcq: Enable multi-circular queue
Asutosh Das [Fri, 13 Jan 2023 20:48:52 +0000 (12:48 -0800)]
scsi: ufs: core: mcq: Enable multi-circular queue

Enable MCQ in the Host Controller.

Signed-off-by: Asutosh Das <quic_asutoshd@quicinc.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Reviewed-by: Stanley Chu <stanley.chu@mediatek.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: core: mcq: Add completion support in poll
Asutosh Das [Fri, 13 Jan 2023 20:48:51 +0000 (12:48 -0800)]
scsi: ufs: core: mcq: Add completion support in poll

Complete CQE requests in poll. Assumption is that several poll completion
may happen in different CPUs for the same completion queue. Hence a spin
lock protection is added.

Co-developed-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Asutosh Das <quic_asutoshd@quicinc.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Reviewed-by: Stanley Chu <stanley.chu@mediatek.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: mcq: Add completion support of a CQE
Asutosh Das [Fri, 13 Jan 2023 20:48:50 +0000 (12:48 -0800)]
scsi: ufs: mcq: Add completion support of a CQE

Add support for completing requests from Completion Queue.  Some host
controllers support vendor specific registers that provide a bitmap of all
CQs which have at least one completed CQE. Add this support.  The MCQ
specification doesn't provide the Task Tag or its equivalent in the
Completion Queue Entry.  So use an indirect method to find the Task Tag
from the Completion Queue Entry.

Co-developed-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Asutosh Das <quic_asutoshd@quicinc.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Reviewed-by: Stanley Chu <stanley.chu@mediatek.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: core: Prepare for completion in MCQ
Asutosh Das [Fri, 13 Jan 2023 20:48:49 +0000 (12:48 -0800)]
scsi: ufs: core: Prepare for completion in MCQ

Modify completion path APIs and add completion queue entry.

Co-developed-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Asutosh Das <quic_asutoshd@quicinc.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Reviewed-by: Stanley Chu <stanley.chu@mediatek.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: core: mcq: Find hardware queue to queue request
Asutosh Das [Fri, 13 Jan 2023 20:48:48 +0000 (12:48 -0800)]
scsi: ufs: core: mcq: Find hardware queue to queue request

Add support to find the hardware queue on which the request would be
queued.  Since the very first queue is to serve device commands, an offset
of 1 is added to the index of the hardware queue.

Co-developed-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Asutosh Das <quic_asutoshd@quicinc.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: core: Prepare ufshcd_send_command() for MCQ
Asutosh Das [Fri, 13 Jan 2023 20:48:47 +0000 (12:48 -0800)]
scsi: ufs: core: Prepare ufshcd_send_command() for MCQ

Add support to send commands using multiple submission queues in MCQ mode.
Modify the functions that use ufshcd_send_command().

Co-developed-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Asutosh Das <quic_asutoshd@quicinc.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Reviewed-by: Stanley Chu <stanley.chu@mediatek.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: core: mcq: Use shared tags for MCQ mode
Asutosh Das [Fri, 13 Jan 2023 20:48:46 +0000 (12:48 -0800)]
scsi: ufs: core: mcq: Use shared tags for MCQ mode

Enable shared tags for MCQ. For UFS, this should not have a huge
performance impact. It however simplifies the MCQ implementation and reuses
most of the existing code in the issue and completion path.  Also add
multiple queue mapping to map_queue().

Co-developed-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Asutosh Das <quic_asutoshd@quicinc.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Reviewed-by: Stanley Chu <stanley.chu@mediatek.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: core: mcq: Configure operation and runtime interface
Asutosh Das [Fri, 13 Jan 2023 20:48:45 +0000 (12:48 -0800)]
scsi: ufs: core: mcq: Configure operation and runtime interface

Runtime and operation registers are defined per Submission and Completion
queue.  The location of these registers is not defined in the spec; meaning
the offsets and stride may vary for different HC vendors. Establish the
stride, base address, and doorbell address offsets from vendor host driver
and program it.

Co-developed-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Asutosh Das <quic_asutoshd@quicinc.com>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: core: mcq: Allocate memory for MCQ mode
Asutosh Das [Fri, 13 Jan 2023 20:48:44 +0000 (12:48 -0800)]
scsi: ufs: core: mcq: Allocate memory for MCQ mode

To read the bqueuedepth, the device descriptor is fetched in Single
Doorbell Mode. This allocated memory may not be enough for MCQ mode because
the number of tags supported in MCQ mode may be larger than in SDB mode.
Hence, release the memory allocated in SDB mode and allocate memory for MCQ
mode operation.  Define the UFS hardware queue and Completion Queue Entry.

Co-developed-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Asutosh Das <quic_asutoshd@quicinc.com>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: core: mcq: Calculate queue depth
Asutosh Das [Fri, 13 Jan 2023 20:48:43 +0000 (12:48 -0800)]
scsi: ufs: core: mcq: Calculate queue depth

The UFS device defines the supported queuedepth by bqueuedepth which has a
max value of 256.  The HC defines MAC (Max Active Commands) that defines
the max number of commands that in flight to the UFS device.  Calculate and
configure the nutrs based on both these values.

Co-developed-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Asutosh Das <quic_asutoshd@quicinc.com>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Stanley Chu <stanley.chu@mediatek.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: core: mcq: Configure resource regions
Asutosh Das [Fri, 13 Jan 2023 20:48:42 +0000 (12:48 -0800)]
scsi: ufs: core: mcq: Configure resource regions

Define the MCQ resources and add support to ioremap the resource regions.

Co-developed-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Asutosh Das <quic_asutoshd@quicinc.com>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Stanley Chu <stanley.chu@mediatek.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: core: mcq: Add support to allocate multiple queues
Asutosh Das [Fri, 13 Jan 2023 20:48:41 +0000 (12:48 -0800)]
scsi: ufs: core: mcq: Add support to allocate multiple queues

Multi-circular queue (MCQ) has been added in UFSHC v4.0 standard in
addition to the Single Doorbell mode.  The MCQ mode supports multiple
submission and completion queues.  Add support to allocate and configure
the queues.  Add module parameters support to configure the queues.

Co-developed-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Asutosh Das <quic_asutoshd@quicinc.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
16 months agoscsi: ufs: core: Defer adding host to SCSI if MCQ is supported
Asutosh Das [Fri, 13 Jan 2023 20:48:40 +0000 (12:48 -0800)]
scsi: ufs: core: Defer adding host to SCSI if MCQ is supported

If MCQ support is present, enabling it after MCQ support has been
configured would require reallocating tags and memory.  It would also free
up the already allocated memory in Single Doorbell Mode. So defer invoking
scsi_add_host() until MCQ is configured.

Co-developed-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Can Guo <quic_cang@quicinc.com>
Signed-off-by: Asutosh Das <quic_asutoshd@quicinc.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>