From 0aabb1fdcfdf1098f6216f30117475555e3aadfd Mon Sep 17 00:00:00 2001 From: Exioncore Date: Sat, 18 Jun 2022 10:49:57 +0200 Subject: [PATCH 1/3] Update to kernel 5.17 and 5.18 --- src/rc_config.c | 6 ++- src/rc_init.c | 86 +++++++++++++++++++++++++++++++------------ src/rc_msg.c | 79 ++++++++++++++++++++++++++++++++++----- src/rc_msg_platform.h | 2 +- 4 files changed, 138 insertions(+), 35 deletions(-) mode change 100644 => 100755 src/rc_config.c mode change 100644 => 100755 src/rc_init.c mode change 100644 => 100755 src/rc_msg.c mode change 100644 => 100755 src/rc_msg_platform.h diff --git a/src/rc_config.c b/src/rc_config.c old mode 100644 new mode 100755 index a048a02..8ea575a --- a/src/rc_config.c +++ b/src/rc_config.c @@ -4,11 +4,11 @@ * ****************************************************************************/ +#include #include #include #include -#include #include #include @@ -27,6 +27,10 @@ #include "rc_msg_platform.h" #include "rc_adapter.h" +#if LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0) +#include +#endif + #ifndef GFP_NOWAIT #define GFP_NOWAIT (GFP_ATOMIC & ~__GFP_HIGH) #endif // ! GFP_NOWAIT diff --git a/src/rc_init.c b/src/rc_init.c old mode 100644 new mode 100755 index 487ed07..40b806c --- a/src/rc_init.c +++ b/src/rc_init.c @@ -39,6 +39,7 @@ #include "version.h" #include "build_number.h" #include "rc_pci_ids.h" +#include #include #include #include @@ -49,6 +50,10 @@ #include #include +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,18,0) +#include +#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 @@ -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 @@ -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", @@ -539,6 +547,7 @@ rc_init_adapter(struct pci_dev *dev, const struct pci_device_id *id) rc_shutdown_adapter(adapter); return -ENODEV; } + #endif /* * map in the adapter MMIO space @@ -905,10 +914,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); */ @@ -1102,14 +1118,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); + } } // @@ -1127,29 +1148,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 */ @@ -1389,12 +1414,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 @@ -1430,13 +1459,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 diff --git a/src/rc_msg.c b/src/rc_msg.c old mode 100644 new mode 100755 index 9254538..ae18489 --- a/src/rc_msg.c +++ b/src/rc_msg.c @@ -20,13 +20,19 @@ ****************************************************************************/ #include "rc.h" -#include "linux/sysrq.h" -#include "linux/nmi.h" +#include "rc_ahci.h" #include "asm/msr.h" + +#include #include #include +#include +#include #include -#include "rc_ahci.h" + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,18,0) +#include +#endif int rc_setup_communications(void); void rc_send_msg(struct rc_send_arg_s *p_send_arg); @@ -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 " @@ -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; } @@ -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); @@ -1868,7 +1889,11 @@ 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__, @@ -1876,7 +1901,11 @@ rc_msg_srb_complete(struct rc_srb_s *srb) 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); @@ -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); @@ -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); @@ -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) { @@ -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 @@ -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; @@ -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; diff --git a/src/rc_msg_platform.h b/src/rc_msg_platform.h old mode 100644 new mode 100755 index 63daa3e..3ea43de --- a/src/rc_msg_platform.h +++ b/src/rc_msg_platform.h @@ -27,7 +27,7 @@ #define RC_STHEXT_REDO_STRICT_TYPES #endif //int -#include +#include #ifdef RC_STHEXT_REDO_STRICT_TYPES #define int Cannot_USE_int_because_it_is_ambiguous From 57733065af6c9a5d50579e7c7bf21fc248b7e1d0 Mon Sep 17 00:00:00 2001 From: Exioncore Date: Sat, 18 Jun 2022 11:06:27 +0200 Subject: [PATCH 2/3] hotfix --- src/rc_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rc_init.c b/src/rc_init.c index 40b806c..176788e 100755 --- a/src/rc_init.c +++ b/src/rc_init.c @@ -1415,7 +1415,7 @@ 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); +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 From f74c5f1a52ae04fdb14095a6e0e85b21ef01afac Mon Sep 17 00:00:00 2001 From: Exioncore Date: Sun, 19 Jun 2022 12:52:44 +0200 Subject: [PATCH 3/3] dma masking re-introduced --- src/rc_init.c | 19 +++++++++++++++++-- src/rc_msg.c | 4 ++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/rc_init.c b/src/rc_init.c index 176788e..eeceae4 100755 --- a/src/rc_init.c +++ b/src/rc_init.c @@ -547,6 +547,21 @@ 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 /* @@ -1459,7 +1474,7 @@ 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)) +#if (LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0)) srb = (rc_srb_t *)scp->SCp.ptr; #else srb = (rc_srb_t *)scp->host_scribble; @@ -1471,7 +1486,7 @@ rc_eh_abort_cmd (struct scsi_cmnd * scp) srb->status, srb->flags, srb->bus, srb->target, srb->lun); srb->scsi_context = NULL; -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0)) +#if (LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0)) scp->SCp.ptr = NULL; #else scp->host_scribble = NULL; diff --git a/src/rc_msg.c b/src/rc_msg.c index ae18489..530a0f3 100755 --- a/src/rc_msg.c +++ b/src/rc_msg.c @@ -1495,7 +1495,7 @@ 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)) +#if (LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0)) scp->SCp.ptr = (void *)srb; #else scp->host_scribble = (void *)srb; @@ -1889,7 +1889,7 @@ rc_msg_srb_complete(struct rc_srb_s *srb) return; } -#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0)) +#if (LINUX_VERSION_CODE < KERNEL_VERSION(5,18,0)) scp->SCp.ptr = NULL; #else scp->host_scribble = NULL;