Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to kernel 5.17 and 5.18 #47

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/rc_config.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
*
****************************************************************************/

#include <linux/version.h>

#include <linux/module.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <linux/genhd.h>
#include <linux/sched.h>
#include <linux/completion.h>

Expand All @@ -27,6 +27,10 @@
#include "rc_msg_platform.h"
#include "rc_adapter.h"

#if LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0)
#include <linux/genhd.h>
#endif

#ifndef GFP_NOWAIT
#define GFP_NOWAIT (GFP_ATOMIC & ~__GFP_HIGH)
#endif // ! GFP_NOWAIT
Expand Down
101 changes: 78 additions & 23 deletions src/rc_init.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "version.h"
#include "build_number.h"
#include "rc_pci_ids.h"
#include <linux/version.h>
#include <linux/hdreg.h>
#include <linux/reboot.h>
#include <linux/pci.h>
Expand All @@ -49,6 +50,10 @@
#include <linux/sysctl.h>
#include <linux/pm_runtime.h>

#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,18,0)
#include <linux/dma-mapping.h>
#endif

// FIXME: some older kernels still supported by RAIDCore do not have
// DMA_BIT_MASK(). Remove once support for them has been dropped.
#ifndef DMA_BIT_MASK
Expand Down Expand Up @@ -184,6 +189,8 @@ int rc_bios_params(struct scsi_device *sdev, struct block_device *bdev,

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36)
int rc_queue_cmd(struct scsi_cmnd * scp, void (*CompletionRoutine) (struct scsi_cmnd *));
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(5,16,0)
int rc_queue_cmd_lck(struct scsi_cmnd * scp);
#else
int rc_queue_cmd_lck(struct scsi_cmnd * scp, void (*CompletionRoutine) (struct scsi_cmnd *));
#endif
Expand Down Expand Up @@ -525,6 +532,7 @@ rc_init_adapter(struct pci_dev *dev, const struct pci_device_id *id)
/*
* set dma_mask to 64 bit capabilities but if that fails, try 32 bit
*/
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0)
if (!pci_set_dma_mask(dev, DMA_BIT_MASK(64)) &&
!pci_set_consistent_dma_mask(dev, DMA_BIT_MASK(64))) {
rc_printk(RC_NOTE, RC_DRIVER_NAME ": %s 64 bit DMA enabled\n",
Expand All @@ -539,6 +547,22 @@ rc_init_adapter(struct pci_dev *dev, const struct pci_device_id *id)
rc_shutdown_adapter(adapter);
return -ENODEV;
}
#else
if (!dma_set_mask(&dev->dev, DMA_BIT_MASK(64)) &&
!dma_set_coherent_mask(&dev->dev, DMA_BIT_MASK(64))) {
rc_printk(RC_NOTE, RC_DRIVER_NAME ": %s 64 bit DMA enabled\n",
__FUNCTION__);
} else if (!dma_set_mask(&dev->dev, DMA_BIT_MASK(32)) &&
!dma_set_coherent_mask(&dev->dev, DMA_BIT_MASK(32))) {
rc_printk(RC_NOTE, RC_DRIVER_NAME ": %s 64 bit DMA disabled\n",
__FUNCTION__);
} else {
rc_printk(RC_ERROR, RC_DRIVER_NAME ": %s failed to "
"set usable DMA mask\n", __FUNCTION__);
rc_shutdown_adapter(adapter);
return -ENODEV;
}
#endif

/*
* map in the adapter MMIO space
Expand Down Expand Up @@ -905,10 +929,17 @@ rc_shutdown_adapter(rc_adapter_t *adapter)
rc_printk(RC_DEBUG, "%s: free private_mem 0x%p\n",
__FUNCTION__, adapter->private_mem.vaddr);
if (adapter->private_mem.vaddr) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0)
pci_free_consistent(adapter->pdev,
rc_state.memsize_per_controller,
adapter->private_mem.vaddr,
adapter->private_mem.dma_address);
#else
dma_free_coherent(&adapter->pdev->dev,
rc_state.memsize_per_controller,
adapter->private_mem.vaddr,
adapter->private_mem.dma_address);
#endif
}

/* pci_disable_device(adapter->pdev); */
Expand Down Expand Up @@ -1102,14 +1133,19 @@ static int rcraid_resume_one(struct pci_dev *pdev)

pci_restore_state(adapter->pdev);

pci_enable_device(adapter->pdev);

if (adapter->version->start_func)
{
(*adapter->version->start_func)(adapter);
}
if (pci_enable_device(adapter->pdev) != -ENOMEM) {
if (adapter->version->start_func)
{
(*adapter->version->start_func)(adapter);
}

state->adapter_is_suspended &= ~(1 << adapter->instance);
state->adapter_is_suspended &= ~(1 << adapter->instance);
}
else
{
rc_printk(RC_NOTE, RC_DRIVER_NAME ": Failed to enable pdev %p\n",
adapter->pdev);
}
}

//
Expand All @@ -1127,29 +1163,33 @@ static int rcraid_resume_one(struct pci_dev *pdev)

pci_restore_state(pdev);

pcim_enable_device(pdev);

//
// and restart the core...
//
if (adapter->version->start_func)
{
(*adapter->version->start_func)(adapter);
}
if (pcim_enable_device(pdev) != -ENOMEM){
//
// and restart the core...
//
if (adapter->version->start_func)
{
(*adapter->version->start_func)(adapter);
}

rc_msg_init_tasklets(state);
rc_msg_init_tasklets(state);

rc_start_all_threads();
rc_start_all_threads();

rc_event_init();
rc_event_init();

schedule_delayed_work(&state->resume_work,250);
schedule_delayed_work(&state->resume_work,250);

scsi_unblock_requests(rc_state.host_ptr);
scsi_unblock_requests(rc_state.host_ptr);

state->adapter_is_suspended &= ~(1 << adapter->instance);
state->adapter_is_suspended &= ~(1 << adapter->instance);

return 0;
return 0;
} else {
rc_printk(RC_NOTE, RC_DRIVER_NAME ": Failed to enable pdev %p\n",
adapter->pdev);
return -1;
}
}
#endif /* CONFIG_PM */

Expand Down Expand Up @@ -1389,12 +1429,16 @@ int rc_mpt2_shutdown(rc_adapter_t *adapter)

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36)
int rc_queue_cmd (struct scsi_cmnd * scp, void (*CompletionRoutine) (struct scsi_cmnd *))
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(5,16,0)
int rc_queue_cmd_lck(struct scsi_cmnd * scp)
#else
int rc_queue_cmd_lck (struct scsi_cmnd * scp, void (*CompletionRoutine) (struct scsi_cmnd *))
#endif

{
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,16,0)
scp->scsi_done = CompletionRoutine;
#endif
//#define FAIL_ALL_IO 0

#ifdef FAIL_ALL_IO
Expand Down Expand Up @@ -1430,13 +1474,24 @@ rc_eh_abort_cmd (struct scsi_cmnd * scp)
scp, scp->device->channel, scp->device->id);
// rc_config_debug = 1;

#if (LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0))
srb = (rc_srb_t *)scp->SCp.ptr;
#else
srb = (rc_srb_t *)scp->host_scribble;
#endif

if (srb != NULL) {
rc_printk(RC_DEBUG, "\tsrb: 0x%p seq_num %d function %x status %x "
"flags %x b/t/l %d/%d/%d\n", srb, srb->seq_num, srb->function,
srb->status, srb->flags, srb->bus, srb->target, srb->lun);
srb->scsi_context = NULL;

#if (LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0))
scp->SCp.ptr = NULL;
#else
scp->host_scribble = NULL;
#endif

} else {
rc_printk(RC_WARN, "rc_eh_abort_cmd: srb already completed\n");
// most likely here because we already processed srb
Expand Down
79 changes: 69 additions & 10 deletions src/rc_msg.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@
****************************************************************************/

#include "rc.h"
#include "linux/sysrq.h"
#include "linux/nmi.h"
#include "rc_ahci.h"
#include "asm/msr.h"

#include <linux/version.h>
#include <linux/page-flags.h>
#include <linux/vmalloc.h>
#include <linux/sysrq.h>
#include <linux/nmi.h>
#include <scsi/sg.h>
#include "rc_ahci.h"

#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,18,0)
#include <linux/dma-mapping.h>
#endif

int rc_setup_communications(void);
void rc_send_msg(struct rc_send_arg_s *p_send_arg);
Expand Down Expand Up @@ -1116,9 +1122,16 @@ rc_msg_init(rc_softstate_t *state)
if (adapter == (rc_adapter_t *)0) {
rc_printk(RC_ERROR, "rc_msg_init null adapter\n");
}
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0)
addr = pci_alloc_consistent(adapter->pdev,
state->memsize_per_controller,
&adapter->private_mem.dma_address);
#else
addr = dma_alloc_coherent(&adapter->pdev->dev,
state->memsize_per_controller,
&adapter->private_mem.dma_address,
GFP_ATOMIC);
#endif

if (addr == (void *)0) {
rc_printk(RC_ERROR,"rc_msg_init: can not alloc %d bytes of per "
Expand Down Expand Up @@ -1426,7 +1439,11 @@ rc_msg_send_srb(struct scsi_cmnd * scp)
rc_printk(RC_ERROR, "rc_msg_send_srb: scatter-gather list too large "
"(%d)\n", scsi_sg_count(scp));
scp->result = DID_NO_CONNECT << 16;
scp->scsi_done(scp);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,16,0)
scsi_done(scp);
#else
scp->scsi_done(scp);
#endif
return 0;
}

Expand Down Expand Up @@ -1478,7 +1495,11 @@ rc_msg_send_srb(struct scsi_cmnd * scp)
/* the scsi_cmnd pointer points at our srb, at least until the command is
* aborted
*/
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0))
scp->SCp.ptr = (void *)srb;
#else
scp->host_scribble = (void *)srb;
#endif

rc_msg_build_sg(srb);

Expand Down Expand Up @@ -1868,15 +1889,23 @@ rc_msg_srb_complete(struct rc_srb_s *srb)
return;
}

#if (LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0))
scp->SCp.ptr = NULL;
#else
scp->host_scribble = NULL;
#endif

if (srb->status == RC_SRB_STATUS_SUCCESS) {
//rc_printk(RC_DEBUG2, "%s: seq_num %d SUCCESS\n", __FUNCTION__,
// srb->seq_num);
scp->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | GOOD;

GET_IO_REQUEST_LOCK_IRQSAVE(irql);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,16,0)
scsi_done(scp);
#else
scp->scsi_done(scp);
#endif
PUT_IO_REQUEST_LOCK_IRQRESTORE(irql);
srb->seq_num = -1;
kfree(srb);
Expand All @@ -1895,7 +1924,11 @@ rc_msg_srb_complete(struct rc_srb_s *srb)
srb->seq_num);
scp->result = DID_BAD_TARGET << 16;
GET_IO_REQUEST_LOCK_IRQSAVE(irql);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,16,0)
scsi_done(scp);
#else
scp->scsi_done(scp);
#endif
PUT_IO_REQUEST_LOCK_IRQRESTORE(irql);
srb->seq_num = -1;
kfree(srb);
Expand Down Expand Up @@ -1932,7 +1965,11 @@ rc_msg_srb_complete(struct rc_srb_s *srb)
}

GET_IO_REQUEST_LOCK_IRQSAVE(irql);
scp->scsi_done (scp);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,16,0)
scsi_done(scp);
#else
scp->scsi_done(scp);
#endif
PUT_IO_REQUEST_LOCK_IRQRESTORE(irql);
srb->seq_num = -1;
kfree(srb);
Expand Down Expand Up @@ -2191,8 +2228,17 @@ rc_msg_get_dma_memory(alloc_dma_address_t *dma_address)
adapter = (rc_adapter_t *) dma_address->dev_handle;
dmaHandle = (dma_addr_t*) &dma_address->dmaHandle;


dma_address->cpu_addr = pci_alloc_consistent(adapter->pdev,dma_address->bytes, dmaHandle );
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0)
dma_address->cpu_addr = pci_alloc_consistent(
adapter->pdev,
dma_address->bytes,
dmaHandle);
#else
dma_address->cpu_addr = dma_alloc_coherent(&adapter->pdev->dev,
dma_address->bytes,
dmaHandle,
GFP_ATOMIC);
#endif

if (dma_address->cpu_addr)
{
Expand All @@ -2203,7 +2249,12 @@ rc_msg_get_dma_memory(alloc_dma_address_t *dma_address)
void
rc_msg_free_dma_memory(rc_adapter_t *adapter, void *cpu_addr, dma_addr_t dmaHandle, rc_uint32_t bytes)
{
pci_free_consistent(adapter->pdev, bytes, cpu_addr, dmaHandle);
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0)
pci_free_consistent(adapter->pdev, bytes, cpu_addr, dmaHandle);
#else
dma_free_coherent(&adapter->pdev->dev, bytes, cpu_addr, dmaHandle);
#endif

}

void
Expand Down Expand Up @@ -2291,8 +2342,11 @@ rc_msg_map_mem(struct map_memory_s *map)
len_mapped = PAGE_SIZE - offset;
if (len < len_mapped)
len_mapped = len;

#if LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0)
map->physical_address = dma_map_page(&adapter->pdev->dev, page, offset, len_mapped, PCI_DMA_BIDIRECTIONAL);
#else
map->physical_address = dma_map_page(&adapter->pdev->dev, page, offset, len_mapped, DMA_BIDIRECTIONAL);
#endif
if (dma_mapping_error(&adapter->pdev->dev, map->physical_address))
{
map->number_bytes = 0;
Expand All @@ -2303,7 +2357,12 @@ rc_msg_map_mem(struct map_memory_s *map)
} else if ((map->memory_id & MEM_TYPE) == RC_MEM_DMA) {
vaddr = (void *)(rc_uint_ptr_t)map->address;

map->physical_address = dma_map_single(&adapter->pdev->dev, vaddr, map->number_bytes, PCI_DMA_BIDIRECTIONAL);
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0)
map->physical_address = dma_map_single(&adapter->pdev->dev, vaddr, map->number_bytes, PCI_DMA_BIDIRECTIONAL);
#else
map->physical_address = dma_map_single(&adapter->pdev->dev, vaddr, map->number_bytes, DMA_BIDIRECTIONAL);
#endif

if (dma_mapping_error(&adapter->pdev->dev, map->physical_address))
{
map->number_bytes = 0;
Expand Down
Loading