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..eeceae4 --- 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,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 @@ -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); */ @@ -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); + } } // @@ -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 */ @@ -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 @@ -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 diff --git a/src/rc_msg.c b/src/rc_msg.c old mode 100644 new mode 100755 index 9254538..530a0f3 --- 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