Commit Graph

32 Commits

Author SHA1 Message Date
Chandrakanth Patil 734843395f scsi: mpi3mr: Avoid reply queue full condition
JIRA: https://issues.redhat.com/browse/RHEL-49780

To avoid reply queue full condition, update the driver to check IOCFacts
capabilities for qfull.

Update the operational reply queue's Consumer Index after processing 100
replies. If pending I/Os on a reply queue exceeds a threshold
(reply_queue_depth - 200), then return I/O back to OS to retry.

Also increase default admin reply queue size to 2K.

Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
Link: https://lore.kernel.org/r/20250129100850.25430-2-ranjan.kumar@broadcom.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit f08b24d82749117ce779cc66689e8594341130d3)
Signed-off-by: Chandrakanth Patil <chanpati@redhat.com>
Conflicts:
	drivers/scsi/mpi3mr/mpi3mr_app.c
	The device attribute definition differs between upstream and CentOS 9.6, so adjusted it accordingly
	Upstream:
	static struct attribute *mpi3mr_host_attrs[] = {
		&dev_attr_reply_qfull_count.attr,
	}

	centos 9.6:
	struct device_attribute *mpi3mr_host_attrs[] = {
		&dev_attr_reply_qfull_count,
	}
2025-02-13 01:48:49 +05:30
Chandrakanth Patil 8bc1de1cef scsi: mpi3mr: Fix possible crash when setting up bsg fails
JIRA: https://issues.redhat.com/browse/RHEL-49780

If bsg_setup_queue() fails, the bsg_queue is assigned a non-NULL value.
Consequently, in mpi3mr_bsg_exit(), the condition "if(!mrioc->bsg_queue)"
will not be satisfied, preventing execution from entering
bsg_remove_queue(), which could lead to the following crash:

BUG: kernel NULL pointer dereference, address: 000000000000041c
Call Trace:
  <TASK>
  mpi3mr_bsg_exit+0x1f/0x50 [mpi3mr]
  mpi3mr_remove+0x6f/0x340 [mpi3mr]
  pci_device_remove+0x3f/0xb0
  device_release_driver_internal+0x19d/0x220
  unbind_store+0xa4/0xb0
  kernfs_fop_write_iter+0x11f/0x200
  vfs_write+0x1fc/0x3e0
  ksys_write+0x67/0xe0
  do_syscall_64+0x38/0x80
  entry_SYSCALL_64_after_hwframe+0x78/0xe2

Fixes: 4268fa751365 ("scsi: mpi3mr: Add bsg device support")
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
Link: https://lore.kernel.org/r/20250107022032.24006-1-kanie@linux.alibaba.com
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 295006f6e8c17212d3098811166e29627d19e05c)
Signed-off-by: Chandrakanth Patil <chanpati@redhat.com>
2025-02-13 01:46:56 +05:30
Chandrakanth Patil a2e928e648 scsi: mpi3mr: Synchronize access to ioctl data buffer
JIRA: https://issues.redhat.com/browse/RHEL-49780

The driver serializes ioctls through a mutex lock but access to the
ioctl data buffer is not guarded by the mutex. This results in multiple
user threads being able to write to the driver's ioctl buffer
simultaneously.

Protect the ioctl buffer with the ioctl mutex.

Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
Link: https://lore.kernel.org/r/20241110194405.10108-2-ranjan.kumar@broadcom.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 367ac16e5ff2dcd6b7f00a8f94e6ba98875cb397)
Signed-off-by: Chandrakanth Patil <chanpati@redhat.com>
2025-02-13 00:22:02 +05:30
Chandrakanth Patil 2ea3c0cddd scsi: mpi3mr: Avoid MAX_PAGE_ORDER WARNING for buffer allocations
JIRA: https://issues.redhat.com/browse/RHEL-49780

Commit fc4444941140 ("scsi: mpi3mr: HDB allocation and posting for hardware
and firmware buffers") added mpi3mr_alloc_diag_bufs() which calls
dma_alloc_coherent() to allocate the trace buffer and the firmware
buffer. mpi3mr_alloc_diag_bufs() decides the buffer sizes from the driver
configuration. In my environment, the sizes are 8MB. With the sizes,
dma_alloc_coherent() fails and report this WARNING:

    WARNING: CPU: 4 PID: 438 at mm/page_alloc.c:4676 __alloc_pages_noprof+0x52f/0x640

The WARNING indicates that the order of the allocation size is larger than
MAX_PAGE_ORDER. After this failure, mpi3mr_alloc_diag_bufs() reduces the
buffer sizes and retries dma_alloc_coherent(). In the end, the buffer
allocations succeed with 4MB size in my environment, which corresponds to
MAX_PAGE_ORDER=10. Though the allocations succeed, the WARNING message is
misleading and should be avoided.

To avoid the WARNING, check the orders of the buffer allocation sizes
before calling dma_alloc_coherent(). If the orders are larger than
MAX_PAGE_ORDER, fall back to the retry path.

Fixes: fc4444941140 ("scsi: mpi3mr: HDB allocation and posting for hardware and firmware buffers")
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Link: https://lore.kernel.org/r/20240810042701.661841-3-shinichiro.kawasaki@wdc.com
Acked-by: Sathya Prakash Veerichetty <sathya.prakash@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 8c6b808c8c2a9de21503944bd6308979410fd812)
Signed-off-by: Chandrakanth Patil <chanpati@redhat.com>
2025-02-13 00:22:00 +05:30
Chandrakanth Patil e04c185292 scsi: mpi3mr: Prevent PCI writes from driver during PCI error recovery
JIRA: https://issues.redhat.com/browse/RHEL-49780

Prevent interaction with the hardware while the error recovery in progress.

Co-developed-by: Sathya Prakash <sathya.prakash@broadcom.com>
Signed-off-by: Sathya Prakash <sathya.prakash@broadcom.com>
Co-developed-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Link: https://lore.kernel.org/r/20240627101735.18286-3-sumit.saxena@broadcom.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 1c342b0548e3f53a4478f8d7bcb5af34b361787f)
Signed-off-by: Chandrakanth Patil <chanpati@redhat.com>
2025-02-13 00:22:00 +05:30
Chandrakanth Patil 0049b2f2a3 scsi: mpi3mr: Add ioctl support for HDB
JIRA: https://issues.redhat.com/browse/RHEL-49780

Add interface for applications to manage the host diagnostic buffers and
update the automatic diag buffer capture triggers.

Co-developed-by: Sathya Prakash <sathya.prakash@broadcom.com>
Signed-off-by: Sathya Prakash <sathya.prakash@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
Link: https://lore.kernel.org/r/20240626102646.14298-4-ranjan.kumar@broadcom.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 78b506984ebeaefaf63172059422fc606dc23e68)
Signed-off-by: Chandrakanth Patil <chanpati@redhat.com>
2025-02-12 03:39:41 +05:30
Chandrakanth Patil 0a64570205 scsi: mpi3mr: Trigger support
JIRA: https://issues.redhat.com/browse/RHEL-49780

Add functions to process automatic diag triggers. If a condition defined in
the triggers is met, the driver will call appropriate controller functions
to save the diagnostic information.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202405151955.BiAWI1SY-lkp@intel.com/
Co-developed-by: Sathya Prakash <sathya.prakash@broadcom.com>
Signed-off-by: Sathya Prakash <sathya.prakash@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
Link: https://lore.kernel.org/r/20240626102646.14298-3-ranjan.kumar@broadcom.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit d8d08d1638ce1c237ce9c3f14649a3a4cf1b1749)
Signed-off-by: Chandrakanth Patil <chanpati@redhat.com>
2025-02-12 03:39:02 +05:30
Chandrakanth Patil 09f5883704 scsi: mpi3mr: HDB allocation and posting for hardware and firmware buffers
JIRA: https://issues.redhat.com/browse/RHEL-49780

To be able to debug controller problems it is beneficial to allocate and
configure system/host memory buffers which can be used to capture hardware
and firmware diagnostic information.

Add functions required to allocate and post firmware and hardware
diagnostic buffers to the controller and to set up automatic diagnostic
capture triggers.

Captures will be triggered under the following circumstances:

 1. Firmware is in FAULT state.

 2. Admin commands time out.

 3. Controller reset caused due to I/O timeout

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202405151758.7xrJz6rp-lkp@intel.com/
Co-developed-by: Sathya Prakash <sathya.prakash@broadcom.com>
Signed-off-by: Sathya Prakash <sathya.prakash@broadcom.com>
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
Link: https://lore.kernel.org/r/20240626102646.14298-2-ranjan.kumar@broadcom.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit fc4444941140c80088102b39eb130d2a7a048e58)
Signed-off-by: Chandrakanth Patil <chanpati@redhat.com>
2025-02-12 03:38:55 +05:30
Ming Lei 566cf5b05a scsi: mpi3mr: Pass queue_limits to bsg_setup_queue()
JIRA: https://issues.redhat.com/browse/RHEL-56837

commit 9042fb6d2c085eccdf11069b04754dac807c36ea
Author: Christoph Hellwig <hch@lst.de>
Date:   Tue Apr 9 16:37:28 2024 +0200

    scsi: mpi3mr: Pass queue_limits to bsg_setup_queue()

    Pass the limits to bsg_setup_queue() instead of setting them up on the live
    queue.

    Signed-off-by: Christoph Hellwig <hch@lst.de>
    Link: https://lore.kernel.org/r/20240409143748.980206-4-hch@lst.de
    Reviewed-by: John Garry <john.g.garry@oracle.com>
    Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
    Reviewed-by: Hannes Reinecke <hare@suse.de>
    Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

Signed-off-by: Ming Lei <ming.lei@redhat.com>
2024-09-27 11:19:01 +08:00
Ming Lei 5e64da6530 scsi: bsg: Pass queue_limits to bsg_setup_queue()
JIRA: https://issues.redhat.com/browse/RHEL-56837

commit 4373d2ecca7fa7ad04aa9c371c80049bafec2610
Author: Christoph Hellwig <hch@lst.de>
Date:   Tue Apr 9 16:37:27 2024 +0200

    scsi: bsg: Pass queue_limits to bsg_setup_queue()

    This allows bsg_setup_queue() to pass them to blk_mq_alloc_queue() and thus
    set up the limits at queue allocation time.

    Signed-off-by: Christoph Hellwig <hch@lst.de>
    Link: https://lore.kernel.org/r/20240409143748.980206-3-hch@lst.de
    Reviewed-by: Bart Van Assche <bvanassche@acm.org>
    Reviewed-by: John Garry <john.g.garry@oracle.com>
    Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
    Reviewed-by: Hannes Reinecke <hare@suse.de>
    Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
    Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

Signed-off-by: Ming Lei <ming.lei@redhat.com>
2024-09-27 11:19:01 +08:00
Ewan D. Milne ff8aaa58b6 scsi: mpi3mr: Avoid memcpy field-spanning write WARNING
JIRA: https://issues.redhat.com/browse/RHEL-39925
Depends: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/4365
Upstream Status: From upstream linux mainline

When the "storcli2 show" command is executed for eHBA-9600, mpi3mr driver
prints this WARNING message:

  memcpy: detected field-spanning write (size 128) of single field "bsg_reply_buf->reply_buf" at drivers/scsi/mpi3mr/mpi3mr_app.c:1658 (size 1)
  WARNING: CPU: 0 PID: 12760 at drivers/scsi/mpi3mr/mpi3mr_app.c:1658 mpi3mr_bsg_request+0x6b12/0x7f10 [mpi3mr]

The cause of the WARN is 128 bytes memcpy to the 1 byte size array "__u8
replay_buf[1]" in the struct mpi3mr_bsg_in_reply_buf. The array is intended
to be a flexible length array, so the WARN is a false positive.

To suppress the WARN, remove the constant number '1' from the array
declaration and clarify that it has flexible length. Also, adjust the
memory allocation size to match the change.

Suggested-by: Sathya Prakash Veerichetty <sathya.prakash@broadcom.com>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Link: https://lore.kernel.org/r/20240323084155.166835-1-shinichiro.kawasaki@wdc.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 429846b4b6ce9853e0d803a2357bb2e55083adf0)
Signed-off-by: Ewan D. Milne <emilne@redhat.com>
2024-06-03 16:58:00 -04:00
Ewan D. Milne 5151c73ffa scsi: mpi3mr: Debug ability improvements
JIRA: https://issues.redhat.com/browse/RHEL-30580
Depends: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/4364
Upstream Status: From upstream linux mainline

Update driver to include OS type in fault/reset reason code.  MPI request
sent through ioctl now automatically dumped on timeout.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202403081903.q3Dq54zZ-lkp@intel.com/
Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
Signed-off-by: Sathya Prakash <sathya.prakash@broadcom.com>
Link: https://lore.kernel.org/r/20240313100746.128951-6-ranjan.kumar@broadcom.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 0a2714b787b91176e7d4f005dcef8d177efdff8a)
Signed-off-by: Ewan D. Milne <emilne@redhat.com>
2024-05-29 17:06:01 -04:00
Ewan D. Milne 84b43b47a4 scsi: mpi3mr: Fix printk() format strings
JIRA: https://issues.redhat.com/browse/RHEL-18205
Upstream Status: From upstream linux mainline

The newly introduced error messages get multiple format strings wrong:
size_t must be printed using the %z modifier rather than %l and dma_addr_t
must be printed by reference using the special %pad pointer type:

drivers/scsi/mpi3mr/mpi3mr_app.c: In function 'mpi3mr_build_nvme_prp':
include/linux/kern_levels.h:5:25: error: format '%llx' expects argument of type 'long long unsigned int', but argument 4 has type 'dma_addr_t' {aka 'unsigned int'} [-Werror=format=]
drivers/scsi/mpi3mr/mpi3mr_app.c:949:25: note: in expansion of macro 'dprint_bsg_err'
  949 |                         dprint_bsg_err(mrioc,
      |                         ^~~~~~~~~~~~~~
include/linux/kern_levels.h:5:25: error: format '%ld' expects argument of type 'long int', but argument 4 has type 'size_t' {aka 'unsigned int'} [-Werror=format=]
drivers/scsi/mpi3mr/mpi3mr_app.c:1112:41: note: in expansion of macro 'dprint_bsg_err'
 1112 |                                         dprint_bsg_err(mrioc,
      |                                         ^~~~~~~~~~~~~~

Fixes: 9536af615dc9 ("scsi: mpi3mr: Support for preallocation of SGL BSG data buffers part-3")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/r/20231207142813.935717-1-arnd@kernel.org
Acked-by: Randy Dunlap <rdunlap@infradead.org>
Tested-by: Randy Dunlap <rdunlap@infradead.org> # build-tested
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit fc1fbd13a20596564f407a96ac511bf0db808a0e)
Signed-off-by: Ewan D. Milne <emilne@redhat.com>
2024-05-29 17:01:35 -04:00
Ewan D. Milne fd869a8fbf scsi: mpi3mr: Support for preallocation of SGL BSG data buffers part-3
JIRA: https://issues.redhat.com/browse/RHEL-18205
Upstream Status: From upstream linux mainline

The driver acquires the required NVMe SGLs from the pre-allocated
pool.

Co-developed-by: Sathya Prakash <sathya.prakash@broadcom.com>
Signed-off-by: Sathya Prakash <sathya.prakash@broadcom.com>
Signed-off-by: Chandrakanth patil <chandrakanth.patil@broadcom.com>
Link: https://lore.kernel.org/r/20231205191630.12201-4-chandrakanth.patil@broadcom.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 9536af615dc9ded0357341e8bd0efc8b34b2b484)
Signed-off-by: Ewan D. Milne <emilne@redhat.com>
2024-05-29 16:39:17 -04:00
Ewan D. Milne 64ba4cdeb7 scsi: mpi3mr: Support for preallocation of SGL BSG data buffers part-2
JIRA: https://issues.redhat.com/browse/RHEL-18205
Upstream Status: From upstream linux mainline

The driver acquires the required SGLs from the pre-allocated pool.

Co-developed-by: Sathya Prakash <sathya.prakash@broadcom.com>
Signed-off-by: Sathya Prakash <sathya.prakash@broadcom.com>
Signed-off-by: Chandrakanth patil <chandrakanth.patil@broadcom.com>
Link: https://lore.kernel.org/r/20231205191630.12201-3-chandrakanth.patil@broadcom.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit fb231d7deffb41fd445929a3b79815277b883fec)
Signed-off-by: Ewan D. Milne <emilne@redhat.com>
2024-05-29 16:38:07 -04:00
Tomas Henzl 9570854463 scsi: mpi3mr: Block PEL Enable Command on Controller Reset and Unrecoverable State
JIRA: https://issues.redhat.com/browse/RHEL-17364

If a controller reset is underway or the controller is in an unrecoverable
state, the PEL enable management command will be returned as EAGAIN or
EFAULT.

Cc: <stable@vger.kernel.org> # v6.1+
Co-developed-by: Sathya Prakash <sathya.prakash@broadcom.com>
Signed-off-by: Sathya Prakash <sathya.prakash@broadcom.com>
Signed-off-by: Chandrakanth patil <chandrakanth.patil@broadcom.com>
Link: https://lore.kernel.org/r/20231126053134.10133-4-chandrakanth.patil@broadcom.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit f8fb3f39148e8010479e4b2003ba4728818ec661)
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
2023-12-07 20:03:22 +01:00
Tomas Henzl 1207aabab5 scsi: mpi3mr: Update copyright year
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2163420

Update copyright year from 2022 to 2023.

Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Link: https://lore.kernel.org/r/20230316110209.60145-8-ranjan.kumar@broadcom.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit e74f2fbd8b06e57c60ad4b92ea302a11671ac634)
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
2023-05-13 16:25:41 +02:00
Tomas Henzl a2bf07a571 scsi: mpi3mr: Fix W=1 compilation warnings
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2163420

Fix W=1 compilation warnings.

Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Link: https://lore.kernel.org/r/20230316110209.60145-7-ranjan.kumar@broadcom.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 80b8fd0231d5c04a4a7d3442c243a4c93fac4fe4)
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
2023-05-13 16:25:41 +02:00
Tomas Henzl eed9aab5fc scsi: mpi3mr: NVMe command size greater than 8K fails
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2163420

A wrong variable is checked while populating PRP entries in the PRP page
and this results in failure. No PRP entries in the PRP page were
successfully created and any NVMe Encapsulated commands with PRP of size
greater than 8K failed.

Signed-off-by: Ranjan Kumar <ranjan.kumar@broadcom.com>
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Link: https://lore.kernel.org/r/20230228140835.4075-6-ranjan.kumar@broadcom.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 4f297e856a7b5da2f2c66a12e739666e23943560)
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
2023-05-10 16:53:48 +02:00
Tomas Henzl 9d58b6a2c3 scsi: mpi3mr: Remove unnecessary memcpy() to alltgt_info->dmi
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2163420

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>
(cherry picked from commit eeb270aee3e085411399f129fc14fa04bd6d83cf)
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
2023-05-10 16:52:27 +02:00
Tomas Henzl a7b67673c1 scsi: mpi3mr: Fix issues in mpi3mr_get_all_tgt_info()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2163420

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>
(cherry picked from commit fb428a2005fc1260d18b989cc5199f281617f44d)
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
2023-05-10 16:52:26 +02:00
Tomas Henzl 87b5f0d33c scsi: mpi3mr: Fix kernel-doc
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2091880

Fix the following W=1 kernel warnings:

drivers/scsi/mpi3mr/mpi3mr_app.c:1706: warning: expecting prototype for
adapter_state_show(). Prototype was for adp_state_show() instead.

Link: https://lore.kernel.org/r/20220525093514.55467-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>
(cherry picked from commit 1fcbe4c490396c5a0d4588cfb84923ad6076b62a)
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
2022-06-05 14:56:00 +02:00
Tomas Henzl cec23efef4 scsi: mpi3mr: Rework mrioc->bsg_device model to fix warnings
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2091880

During driver unload, mrioc->bsg_device reference count becomes
negative. Also, as reported in [1], the driver's bsg_device model had few
more bugs. Fix all these up.

[1] https://marc.info/?l=linux-scsi&m=165183971411991&w=2

Link: https://lore.kernel.org/r/20220526170157.58274-1-sumit.saxena@broadcom.com
Fixes: 4268fa751365 ("scsi: mpi3mr: Add bsg device support")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Tested-by: Tomas Henzl <thenzl@redhat.com>
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 4094981db7b6ed6ebe3ebe398d8d9136ac5c44c8)
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
2022-06-05 14:56:00 +02:00
Tomas Henzl c501c77568 scsi: mpi3mr: Add target device related sysfs attributes
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2091880

Add sysfs attributes for exposing target device details such as SAS
address, firmware device handle, and persistent ID for the
controller-attached devices and RAID volumes.

Link: https://lore.kernel.org/r/20220517115310.13062-3-sreekanth.reddy@broadcom.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 9feb5c4c3f95ec42fc12dc92f7216c2603b1a571)
Signed-off-by: Tomas Henzl <thenzl@redhat.com>

Conflicts:
	drivers/scsi/mpi3mr/mpi3mr.h
	drivers/scsi/mpi3mr/mpi3mr_app.c
	drivers/scsi/mpi3mr/mpi3mr_os.c
(issues with .shost_attrs)
2022-06-05 14:56:00 +02:00
Tomas Henzl b4726a7317 scsi: mpi3mr: Add shost related sysfs attributes
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2091880

Add shost related sysfs attributes to display the controller's firmware
version, queue depth, number of requests, and number of reply queues. Also
add an attribute to set & get the logging_level.

Link: https://lore.kernel.org/r/20220517115310.13062-2-sreekanth.reddy@broadcom.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit e51e76edddb10867f95df0c24a9769d6d97afeb0)
Signed-off-by: Tomas Henzl <thenzl@redhat.com>

Conflicts:
	drivers/scsi/mpi3mr/mpi3mr_app.c
(no shost_groups in scsi_host_template)
2022-06-05 14:55:26 +02:00
Tomas Henzl 261cdcd806 scsi: mpi3mr: Fix a NULL vs IS_ERR() bug in mpi3mr_bsg_init()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2091880

The bsg_setup_queue() function does not return NULL.  It returns error
pointers.  Fix the check accordingly.

Link: https://lore.kernel.org/r/YnUf7RQl+A3tigWh@kili
Fixes: 4268fa751365 ("scsi: mpi3mr: Add bsg device support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit a25eafd13e5f79d9bbada5a4a4a4224cc5f6d14c)
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
2022-06-05 11:53:19 +02:00
Tomas Henzl ce3c58f49e scsi: mpi3mr: Add support for NVMe passthrough
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2091880

Add support for management applications to send an MPI3 Encapsulated NVMe
passthru command to the NVMe devices attached to an Avenger controller.
Since the NVMe drives are exposed as SCSI devices by the controller, the
standard NVMe applications cannot be used to interact with the drives and
the command sets supported are also limited by the controller firmware.
Special handling is required for MPI3 Encapsulated NVMe passthru commands
for PRP/SGL setup in the commands.

Link: https://lore.kernel.org/r/20220429211641.642010-8-sumit.saxena@broadcom.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 7dbd0dd8cde356d2a747d5c87dad7c2233dad8a4)
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
2022-06-05 11:39:07 +02:00
Tomas Henzl 1ef68b21ba scsi: mpi3mr: Expose adapter state to sysfs
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2091880

Link: https://lore.kernel.org/r/20220429211641.642010-7-sumit.saxena@broadcom.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 986d6bad2103fb24bd886aad455245ace168c984)
Signed-off-by: Tomas Henzl <thenzl@redhat.com>

Conflicts:
(KABI issues with shost_groups)
2022-06-05 11:37:31 +02:00
Tomas Henzl 0a5e248894 scsi: mpi3mr: Add support for PEL commands
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2091880

Implement driver support for management applications to enable persistent
event log (PEL) notifications. Upon receipt of events, the driver will
increment a sysfs variable named event_counter. The management application
will poll for event_counter value changes and signal the application about
events.

Link: https://lore.kernel.org/r/20220429211641.642010-6-sumit.saxena@broadcom.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 43ca110050988c7a0e581d24ce212ef34a4cdf29)
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
2022-06-05 10:44:48 +02:00
Tomas Henzl 50fdfb6c64 scsi: mpi3mr: Add support for MPT commands
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2091880

There are certain management commands which require firmware intervention.
These commands are termed MPT commands. Add support for them.

Link: https://lore.kernel.org/r/20220429211641.642010-5-sumit.saxena@broadcom.com
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 506bc1a0d6ba626492c06e5632a3fbe202770fd2)
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
2022-06-05 10:44:47 +02:00
Tomas Henzl 1be6dd7417 scsi: mpi3mr: Add support for driver commands
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2091880

There are certain bsg commands which need to be completed by the driver
without involving firmware. These requests are termed driver commands. Add
support for these.

Link: https://lore.kernel.org/r/20220429211641.642010-3-sumit.saxena@broadcom.com
Reported by: Stephen Rothwell <sfr@canb.auug.org.au>
Reported-by: kernel test robot <lkp@intel.com>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit f5e6d5a343761081317c89d23489c93fbafc69ff)
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
2022-06-05 10:44:47 +02:00
Tomas Henzl 327325e568 scsi: mpi3mr: Add bsg device support
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2091880

Create bsg device per controller for controller management purposes.

bsg device nodes will be named /dev/bsg/mpi3mrctl0, /dev/bsg/mpi3mrctl1,
etc.

Link: https://lore.kernel.org/r/20220429211641.642010-2-sumit.saxena@broadcom.com
Reported-by: kernel test robot <lkp@intel.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 4268fa7513655a83d5492705591fdac6c65db48a)
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
2022-06-05 10:44:46 +02:00