Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi

Pull SCSI updates from James Bottomley:
"Usual driver updates (ufs, lpfc, target, qla2xxx) plus assorted
cleanups and fixes including the WQ_PERCPU series.

The biggest core change is the new allocation of pseudo-devices which
allow the sending of internal commands to a given SCSI target"

* tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi: (147 commits)
scsi: MAINTAINERS: Add the UFS include directory
scsi: scsi_debug: Support injecting unaligned write errors
scsi: qla2xxx: Fix improper freeing of purex item
scsi: ufs: rockchip: Fix compile error without CONFIG_GPIOLIB
scsi: ufs: rockchip: Reset controller on PRE_CHANGE of hce enable notify
scsi: ufs: core: Use scsi_device_busy()
scsi: ufs: core: Fix single doorbell mode support
scsi: pm80xx: Add WQ_PERCPU to alloc_workqueue() users
scsi: target: Add WQ_PERCPU to alloc_workqueue() users
scsi: qedi: Add WQ_PERCPU to alloc_workqueue() users
scsi: target: ibmvscsi: Add WQ_PERCPU to alloc_workqueue() users
scsi: qedf: Add WQ_PERCPU to alloc_workqueue() users
scsi: bnx2fc: Add WQ_PERCPU to alloc_workqueue() users
scsi: be2iscsi: Add WQ_PERCPU to alloc_workqueue() users
scsi: message: fusion: Add WQ_PERCPU to alloc_workqueue() users
scsi: lpfc: WQ_PERCPU added to alloc_workqueue() users
scsi: scsi_transport_fc: WQ_PERCPU added to alloc_workqueue users()
scsi: scsi_dh_alua: WQ_PERCPU added to alloc_workqueue() users
scsi: qla2xxx: WQ_PERCPU added to alloc_workqueue() users
scsi: target: sbp: Replace use of system_unbound_wq with system_dfl_wq
...

+4921 -1442
+2 -1
Documentation/devicetree/bindings/phy/mediatek,ufs-phy.yaml
··· 8 8 title: MediaTek Universal Flash Storage (UFS) M-PHY 9 9 10 10 maintainers: 11 - - Stanley Chu <stanley.chu@mediatek.com> 12 11 - Chunfeng Yun <chunfeng.yun@mediatek.com> 12 + - Peter Wang <peter.wang@mediatek.com> 13 + - Chaotian Jing <chaotian.jing@mediatek.com> 13 14 14 15 description: | 15 16 UFS M-PHY nodes are defined to describe on-chip UFS M-PHY hardware macro.
+61
Documentation/devicetree/bindings/ufs/amd,versal2-ufs.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/ufs/amd,versal2-ufs.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: AMD Versal Gen 2 UFS Host Controller 8 + 9 + maintainers: 10 + - Sai Krishna Potthuri <sai.krishna.potthuri@amd.com> 11 + 12 + allOf: 13 + - $ref: ufs-common.yaml 14 + 15 + properties: 16 + compatible: 17 + const: amd,versal2-ufs 18 + 19 + reg: 20 + maxItems: 1 21 + 22 + clocks: 23 + maxItems: 1 24 + 25 + clock-names: 26 + items: 27 + - const: core 28 + 29 + power-domains: 30 + maxItems: 1 31 + 32 + resets: 33 + maxItems: 2 34 + 35 + reset-names: 36 + items: 37 + - const: host 38 + - const: phy 39 + 40 + required: 41 + - reg 42 + - clocks 43 + - clock-names 44 + - resets 45 + - reset-names 46 + 47 + unevaluatedProperties: false 48 + 49 + examples: 50 + - | 51 + #include <dt-bindings/interrupt-controller/arm-gic.h> 52 + ufs@f10b0000 { 53 + compatible = "amd,versal2-ufs"; 54 + reg = <0xf10b0000 0x1000>; 55 + clocks = <&ufs_core_clk>; 56 + clock-names = "core"; 57 + resets = <&scmi_reset 4>, <&scmi_reset 35>; 58 + reset-names = "host", "phy"; 59 + interrupts = <GIC_SPI 234 IRQ_TYPE_LEVEL_HIGH>; 60 + freq-table-hz = <0 0>; 61 + };
+2 -1
Documentation/devicetree/bindings/ufs/mediatek,ufs.yaml
··· 7 7 title: Mediatek Universal Flash Storage (UFS) Controller 8 8 9 9 maintainers: 10 - - Stanley Chu <stanley.chu@mediatek.com> 10 + - Peter Wang <peter.wang@mediatek.com> 11 + - Chaotian Jing <chaotian.jing@mediatek.com> 11 12 12 13 properties: 13 14 compatible:
-3
Documentation/devicetree/bindings/ufs/qcom,ufs.yaml
··· 88 88 - const: ice_core_clk 89 89 reg: 90 90 minItems: 2 91 - maxItems: 2 92 91 reg-names: 93 92 minItems: 2 94 93 required: ··· 116 117 - const: tx_lane0_sync_clk 117 118 - const: rx_lane0_sync_clk 118 119 reg: 119 - minItems: 1 120 120 maxItems: 1 121 121 reg-names: 122 122 maxItems: 1 ··· 145 147 - const: ice_core_clk 146 148 reg: 147 149 minItems: 2 148 - maxItems: 2 149 150 reg-names: 150 151 minItems: 2 151 152 required:
+3
Documentation/devicetree/bindings/ufs/samsung,exynos-ufs.yaml
··· 61 61 phy-names: 62 62 const: ufs-phy 63 63 64 + power-domains: 65 + maxItems: 1 66 + 64 67 samsung,sysreg: 65 68 $ref: /schemas/types.yaml#/definitions/phandle-array 66 69 items:
+10
MAINTAINERS
··· 23313 23313 F: drivers/ufs/ 23314 23314 F: include/scsi/ 23315 23315 F: include/uapi/scsi/ 23316 + F: include/ufs/ 23316 23317 23317 23318 SCSI TAPE DRIVER 23318 23319 M: Kai Mäkisara <Kai.Makisara@kolumbus.fi> ··· 26629 26628 F: Documentation/devicetree/bindings/ufs/ 26630 26629 F: Documentation/scsi/ufs.rst 26631 26630 F: drivers/ufs/core/ 26631 + F: include/ufs/ 26632 + 26633 + UNIVERSAL FLASH STORAGE HOST CONTROLLER DRIVER AMD VERSAL2 26634 + M: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com> 26635 + M: Ajay Neeli <ajay.neeli@amd.com> 26636 + S: Maintained 26637 + F: Documentation/devicetree/bindings/ufs/amd,versal2-ufs.yaml 26638 + F: drivers/ufs/host/ufs-amd-versal2.c 26632 26639 26633 26640 UNIVERSAL FLASH STORAGE HOST CONTROLLER DRIVER DWC HOOKS 26634 26641 M: Pedro Sousa <pedrom.sousa@synopsys.com> ··· 26654 26645 26655 26646 UNIVERSAL FLASH STORAGE HOST CONTROLLER DRIVER MEDIATEK HOOKS 26656 26647 M: Peter Wang <peter.wang@mediatek.com> 26648 + M: Chaotian Jing <chaotian.jing@mediatek.com> 26657 26649 R: Stanley Jhu <chu.stanley@gmail.com> 26658 26650 L: linux-scsi@vger.kernel.org 26659 26651 L: linux-mediatek@lists.infradead.org (moderated for non-subscribers)
+67
drivers/ata/libata-acpi.c
··· 246 246 } 247 247 248 248 /** 249 + * ata_acpi_dev_manage_restart - if the disk should be stopped (spun down) on 250 + * system restart. 251 + * @dev: target ATA device 252 + * 253 + * RETURNS: 254 + * true if the disk should be stopped, otherwise false. 255 + */ 256 + bool ata_acpi_dev_manage_restart(struct ata_device *dev) 257 + { 258 + struct device *tdev; 259 + 260 + /* 261 + * If ATA_FLAG_ACPI_SATA is set, the acpi fwnode is attached to the 262 + * ata_device instead of the ata_port. 263 + */ 264 + if (dev->link->ap->flags & ATA_FLAG_ACPI_SATA) 265 + tdev = &dev->tdev; 266 + else 267 + tdev = &dev->link->ap->tdev; 268 + 269 + if (!is_acpi_device_node(tdev->fwnode)) 270 + return false; 271 + return acpi_bus_power_manageable(ACPI_HANDLE(tdev)); 272 + } 273 + 274 + /** 275 + * ata_acpi_port_power_on - set the power state of the ata port to D0 276 + * @ap: target ATA port 277 + * 278 + * This function is called at the beginning of ata_port_probe(). 279 + */ 280 + void ata_acpi_port_power_on(struct ata_port *ap) 281 + { 282 + acpi_handle handle; 283 + int i; 284 + 285 + /* 286 + * If ATA_FLAG_ACPI_SATA is set, the acpi fwnode is attached to the 287 + * ata_device instead of the ata_port. 288 + */ 289 + if (ap->flags & ATA_FLAG_ACPI_SATA) { 290 + for (i = 0; i < ATA_MAX_DEVICES; i++) { 291 + struct ata_device *dev = &ap->link.device[i]; 292 + 293 + if (!is_acpi_device_node(dev->tdev.fwnode)) 294 + continue; 295 + handle = ACPI_HANDLE(&dev->tdev); 296 + if (!acpi_bus_power_manageable(handle)) 297 + continue; 298 + if (acpi_bus_set_power(handle, ACPI_STATE_D0)) 299 + ata_dev_err(dev, 300 + "acpi: failed to set power state to D0\n"); 301 + } 302 + return; 303 + } 304 + 305 + if (!is_acpi_device_node(ap->tdev.fwnode)) 306 + return; 307 + handle = ACPI_HANDLE(&ap->tdev); 308 + if (!acpi_bus_power_manageable(handle)) 309 + return; 310 + 311 + if (acpi_bus_set_power(handle, ACPI_STATE_D0)) 312 + ata_port_err(ap, "acpi: failed to set power state to D0\n"); 313 + } 314 + 315 + /** 249 316 * ata_acpi_dissociate - dissociate ATA host from ACPI objects 250 317 * @host: target ATA host 251 318 *
+2
drivers/ata/libata-core.c
··· 5915 5915 struct ata_eh_info *ehi = &ap->link.eh_info; 5916 5916 unsigned long flags; 5917 5917 5918 + ata_acpi_port_power_on(ap); 5919 + 5918 5920 /* kick EH for boot probing */ 5919 5921 spin_lock_irqsave(ap->lock, flags); 5920 5922
+1
drivers/ata/libata-scsi.c
··· 1102 1102 */ 1103 1103 sdev->manage_runtime_start_stop = 1; 1104 1104 sdev->manage_shutdown = 1; 1105 + sdev->manage_restart = ata_acpi_dev_manage_restart(dev); 1105 1106 sdev->force_runtime_start_on_system_start = 1; 1106 1107 } 1107 1108
+4
drivers/ata/libata.h
··· 130 130 extern void ata_acpi_set_state(struct ata_port *ap, pm_message_t state); 131 131 extern void ata_acpi_bind_port(struct ata_port *ap); 132 132 extern void ata_acpi_bind_dev(struct ata_device *dev); 133 + extern void ata_acpi_port_power_on(struct ata_port *ap); 134 + extern bool ata_acpi_dev_manage_restart(struct ata_device *dev); 133 135 extern acpi_handle ata_dev_acpi_handle(struct ata_device *dev); 134 136 #else 135 137 static inline void ata_acpi_dissociate(struct ata_host *host) { } ··· 142 140 pm_message_t state) { } 143 141 static inline void ata_acpi_bind_port(struct ata_port *ap) {} 144 142 static inline void ata_acpi_bind_dev(struct ata_device *dev) {} 143 + static inline void ata_acpi_port_power_on(struct ata_port *ap) {} 144 + static inline bool ata_acpi_dev_manage_restart(struct ata_device *dev) { return 0; } 145 145 #endif 146 146 147 147 /* libata-scsi.c */
+1 -1
drivers/firmware/xilinx/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 # Makefile for Xilinx firmwares 3 3 4 - obj-$(CONFIG_ZYNQMP_FIRMWARE) += zynqmp.o 4 + obj-$(CONFIG_ZYNQMP_FIRMWARE) += zynqmp.o zynqmp-ufs.o 5 5 obj-$(CONFIG_ZYNQMP_FIRMWARE_DEBUG) += zynqmp-debug.o
+118
drivers/firmware/xilinx/zynqmp-ufs.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Firmware Layer for UFS APIs 4 + * 5 + * Copyright (C) 2025 Advanced Micro Devices, Inc. 6 + */ 7 + 8 + #include <linux/firmware/xlnx-zynqmp.h> 9 + #include <linux/module.h> 10 + 11 + /* Register Node IDs */ 12 + #define PM_REGNODE_PMC_IOU_SLCR 0x30000002 /* PMC IOU SLCR */ 13 + #define PM_REGNODE_EFUSE_CACHE 0x30000003 /* EFUSE Cache */ 14 + 15 + /* Register Offsets for PMC IOU SLCR */ 16 + #define SRAM_CSR_OFFSET 0x104C /* SRAM Control and Status */ 17 + #define TXRX_CFGRDY_OFFSET 0x1054 /* M-PHY TX-RX Config ready */ 18 + 19 + /* Masks for SRAM Control and Status Register */ 20 + #define SRAM_CSR_INIT_DONE_MASK BIT(0) /* SRAM initialization done */ 21 + #define SRAM_CSR_EXT_LD_DONE_MASK BIT(1) /* SRAM External load done */ 22 + #define SRAM_CSR_BYPASS_MASK BIT(2) /* Bypass SRAM interface */ 23 + 24 + /* Mask to check M-PHY TX-RX configuration readiness */ 25 + #define TX_RX_CFG_RDY_MASK GENMASK(3, 0) 26 + 27 + /* Register Offsets for EFUSE Cache */ 28 + #define UFS_CAL_1_OFFSET 0xBE8 /* UFS Calibration Value */ 29 + 30 + /** 31 + * zynqmp_pm_is_mphy_tx_rx_config_ready - check M-PHY TX-RX config readiness 32 + * @is_ready: Store output status (true/false) 33 + * 34 + * Return: Returns 0 on success or error value on failure. 35 + */ 36 + int zynqmp_pm_is_mphy_tx_rx_config_ready(bool *is_ready) 37 + { 38 + u32 regval; 39 + int ret; 40 + 41 + if (!is_ready) 42 + return -EINVAL; 43 + 44 + ret = zynqmp_pm_sec_read_reg(PM_REGNODE_PMC_IOU_SLCR, TXRX_CFGRDY_OFFSET, &regval); 45 + if (ret) 46 + return ret; 47 + 48 + regval &= TX_RX_CFG_RDY_MASK; 49 + if (regval) 50 + *is_ready = true; 51 + else 52 + *is_ready = false; 53 + 54 + return ret; 55 + } 56 + EXPORT_SYMBOL_GPL(zynqmp_pm_is_mphy_tx_rx_config_ready); 57 + 58 + /** 59 + * zynqmp_pm_is_sram_init_done - check SRAM initialization 60 + * @is_done: Store output status (true/false) 61 + * 62 + * Return: Returns 0 on success or error value on failure. 63 + */ 64 + int zynqmp_pm_is_sram_init_done(bool *is_done) 65 + { 66 + u32 regval; 67 + int ret; 68 + 69 + if (!is_done) 70 + return -EINVAL; 71 + 72 + ret = zynqmp_pm_sec_read_reg(PM_REGNODE_PMC_IOU_SLCR, SRAM_CSR_OFFSET, &regval); 73 + if (ret) 74 + return ret; 75 + 76 + regval &= SRAM_CSR_INIT_DONE_MASK; 77 + if (regval) 78 + *is_done = true; 79 + else 80 + *is_done = false; 81 + 82 + return ret; 83 + } 84 + EXPORT_SYMBOL_GPL(zynqmp_pm_is_sram_init_done); 85 + 86 + /** 87 + * zynqmp_pm_set_sram_bypass - Set SRAM bypass Control 88 + * 89 + * Return: Returns 0 on success or error value on failure. 90 + */ 91 + int zynqmp_pm_set_sram_bypass(void) 92 + { 93 + u32 sram_csr; 94 + int ret; 95 + 96 + ret = zynqmp_pm_sec_read_reg(PM_REGNODE_PMC_IOU_SLCR, SRAM_CSR_OFFSET, &sram_csr); 97 + if (ret) 98 + return ret; 99 + 100 + sram_csr &= ~SRAM_CSR_EXT_LD_DONE_MASK; 101 + sram_csr |= SRAM_CSR_BYPASS_MASK; 102 + 103 + return zynqmp_pm_sec_mask_write_reg(PM_REGNODE_PMC_IOU_SLCR, SRAM_CSR_OFFSET, 104 + GENMASK(2, 1), sram_csr); 105 + } 106 + EXPORT_SYMBOL_GPL(zynqmp_pm_set_sram_bypass); 107 + 108 + /** 109 + * zynqmp_pm_get_ufs_calibration_values - Read UFS calibration values 110 + * @val: Store the calibration value 111 + * 112 + * Return: Returns 0 on success or error value on failure. 113 + */ 114 + int zynqmp_pm_get_ufs_calibration_values(u32 *val) 115 + { 116 + return zynqmp_pm_sec_read_reg(PM_REGNODE_EFUSE_CACHE, UFS_CAL_1_OFFSET, val); 117 + } 118 + EXPORT_SYMBOL_GPL(zynqmp_pm_get_ufs_calibration_values);
+46
drivers/firmware/xilinx/zynqmp.c
··· 1654 1654 } 1655 1655 1656 1656 /** 1657 + * zynqmp_pm_sec_read_reg - PM call to securely read from given offset 1658 + * of the node 1659 + * @node_id: Node Id of the device 1660 + * @offset: Offset to be used (20-bit) 1661 + * @ret_value: Output data read from the given offset after 1662 + * firmware access policy is successfully enforced 1663 + * 1664 + * Return: Returns 0 on success or error value on failure 1665 + */ 1666 + int zynqmp_pm_sec_read_reg(u32 node_id, u32 offset, u32 *ret_value) 1667 + { 1668 + u32 ret_payload[PAYLOAD_ARG_CNT]; 1669 + u32 count = 1; 1670 + int ret; 1671 + 1672 + if (!ret_value) 1673 + return -EINVAL; 1674 + 1675 + ret = zynqmp_pm_invoke_fn(PM_IOCTL, ret_payload, 4, node_id, IOCTL_READ_REG, 1676 + offset, count); 1677 + 1678 + *ret_value = ret_payload[1]; 1679 + 1680 + return ret; 1681 + } 1682 + EXPORT_SYMBOL_GPL(zynqmp_pm_sec_read_reg); 1683 + 1684 + /** 1685 + * zynqmp_pm_sec_mask_write_reg - PM call to securely write to given offset 1686 + * of the node 1687 + * @node_id: Node Id of the device 1688 + * @offset: Offset to be used (20-bit) 1689 + * @mask: Mask to be used 1690 + * @value: Value to be written 1691 + * 1692 + * Return: Returns 0 on success or error value on failure 1693 + */ 1694 + int zynqmp_pm_sec_mask_write_reg(const u32 node_id, const u32 offset, u32 mask, 1695 + u32 value) 1696 + { 1697 + return zynqmp_pm_invoke_fn(PM_IOCTL, NULL, 5, node_id, IOCTL_MASK_WRITE_REG, 1698 + offset, mask, value); 1699 + } 1700 + EXPORT_SYMBOL_GPL(zynqmp_pm_sec_mask_write_reg); 1701 + 1702 + /** 1657 1703 * zynqmp_pm_set_sd_config - PM call to set value of SD config registers 1658 1704 * @node: SD node ID 1659 1705 * @config: The config type of SD registers
+5 -2
drivers/message/fusion/mptbase.c
··· 1857 1857 INIT_DELAYED_WORK(&ioc->fault_reset_work, mpt_fault_reset_work); 1858 1858 1859 1859 ioc->reset_work_q = 1860 - alloc_workqueue("mpt_poll_%d", WQ_MEM_RECLAIM, 0, ioc->id); 1860 + alloc_workqueue("mpt_poll_%d", WQ_MEM_RECLAIM | WQ_PERCPU, 0, 1861 + ioc->id); 1861 1862 if (!ioc->reset_work_q) { 1862 1863 printk(MYIOC_s_ERR_FMT "Insufficient memory to add adapter!\n", 1863 1864 ioc->name); ··· 1985 1984 1986 1985 INIT_LIST_HEAD(&ioc->fw_event_list); 1987 1986 spin_lock_init(&ioc->fw_event_lock); 1988 - ioc->fw_event_q = alloc_workqueue("mpt/%d", WQ_MEM_RECLAIM, 0, ioc->id); 1987 + ioc->fw_event_q = alloc_workqueue("mpt/%d", 1988 + WQ_MEM_RECLAIM | WQ_PERCPU, 0, 1989 + ioc->id); 1989 1990 if (!ioc->fw_event_q) { 1990 1991 printk(MYIOC_s_ERR_FMT "Insufficient memory to add adapter!\n", 1991 1992 ioc->name);
+1 -1
drivers/misc/Kconfig
··· 106 106 107 107 config RPMB 108 108 tristate "RPMB partition interface" 109 - depends on MMC 109 + depends on MMC || SCSI_UFSHCD 110 110 help 111 111 Unified RPMB unit interface for RPMB capable devices such as eMMC and 112 112 UFS. Provides interface for in-kernel security controllers to access
+1 -1
drivers/scsi/aacraid/linit.c
··· 242 242 { 243 243 aac_priv(cmd)->owner = AAC_OWNER_LOWLEVEL; 244 244 245 - return aac_scsi_cmd(cmd) ? FAILED : 0; 245 + return aac_scsi_cmd(cmd) ? SCSI_MLQUEUE_HOST_BUSY : 0; 246 246 } 247 247 248 248 /**
+1 -2
drivers/scsi/advansys.c
··· 2401 2401 struct asc_board *boardp = shost_priv(s); 2402 2402 2403 2403 printk("Scsi_Host at addr 0x%p, device %s\n", s, dev_name(boardp->dev)); 2404 - printk(" host_busy %d, host_no %d,\n", 2405 - scsi_host_busy(s), s->host_no); 2404 + printk(" host_no %d,\n", s->host_no); 2406 2405 2407 2406 printk(" base 0x%lx, io_port 0x%lx, irq %d,\n", 2408 2407 (ulong)s->base, (ulong)s->io_port, boardp->irq);
+3
drivers/scsi/aic94xx/aic94xx_init.c
··· 882 882 883 883 asd_disable_ints(asd_ha); 884 884 885 + /* Ensure all scheduled tasklets complete before freeing resources */ 886 + tasklet_kill(&asd_ha->seq.dl_tasklet); 887 + 885 888 asd_remove_dev_attrs(asd_ha); 886 889 887 890 /* XXX more here as needed */
+2 -1
drivers/scsi/be2iscsi/be_main.c
··· 5633 5633 5634 5634 phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0; 5635 5635 5636 - phba->wq = alloc_workqueue("beiscsi_%02x_wq", WQ_MEM_RECLAIM, 1, 5636 + phba->wq = alloc_workqueue("beiscsi_%02x_wq", 5637 + WQ_MEM_RECLAIM | WQ_PERCPU, 1, 5637 5638 phba->shost->host_no); 5638 5639 if (!phba->wq) { 5639 5640 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
+1 -1
drivers/scsi/bnx2fc/bnx2fc_fcoe.c
··· 2695 2695 if (rc) 2696 2696 goto detach_ft; 2697 2697 2698 - bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0); 2698 + bnx2fc_wq = alloc_workqueue("bnx2fc", WQ_PERCPU, 0); 2699 2699 if (!bnx2fc_wq) { 2700 2700 rc = -ENOMEM; 2701 2701 goto release_bt;
+1 -1
drivers/scsi/device_handler/scsi_dh_alua.c
··· 1300 1300 { 1301 1301 int r; 1302 1302 1303 - kaluad_wq = alloc_workqueue("kaluad", WQ_MEM_RECLAIM, 0); 1303 + kaluad_wq = alloc_workqueue("kaluad", WQ_MEM_RECLAIM | WQ_PERCPU, 0); 1304 1304 if (!kaluad_wq) 1305 1305 return -ENOMEM; 1306 1306
+1 -1
drivers/scsi/fcoe/fcoe.c
··· 2438 2438 unsigned int cpu; 2439 2439 int rc = 0; 2440 2440 2441 - fcoe_wq = alloc_workqueue("fcoe", 0, 0); 2441 + fcoe_wq = alloc_workqueue("fcoe", WQ_PERCPU, 0); 2442 2442 if (!fcoe_wq) 2443 2443 return -ENOMEM; 2444 2444
-1
drivers/scsi/fnic/fnic_res.c
··· 134 134 c->luns_per_tgt)); 135 135 136 136 c->intr_timer = min_t(u16, VNIC_INTR_TIMER_MAX, c->intr_timer); 137 - c->intr_timer_type = c->intr_timer_type; 138 137 139 138 /* for older firmware, GET_CONFIG will not return anything */ 140 139 if (c->wq_copy_count == 0)
+17 -2
drivers/scsi/hosts.c
··· 231 231 goto fail; 232 232 } 233 233 234 + if (shost->nr_reserved_cmds && !sht->queue_reserved_command) { 235 + shost_printk(KERN_ERR, shost, 236 + "nr_reserved_cmds set but no method to queue\n"); 237 + goto fail; 238 + } 239 + 234 240 /* Use min_t(int, ...) in case shost->can_queue exceeds SHRT_MAX */ 235 241 shost->cmd_per_lun = min_t(int, shost->cmd_per_lun, 236 242 shost->can_queue); ··· 312 306 error = scsi_sysfs_add_host(shost); 313 307 if (error) 314 308 goto out_del_dev; 309 + 310 + if (shost->nr_reserved_cmds) { 311 + shost->pseudo_sdev = scsi_get_pseudo_sdev(shost); 312 + if (!shost->pseudo_sdev) { 313 + error = -ENOMEM; 314 + goto out_del_dev; 315 + } 316 + } 315 317 316 318 scsi_proc_host_add(shost); 317 319 scsi_autopm_put_host(shost); ··· 450 436 shost->hostt = sht; 451 437 shost->this_id = sht->this_id; 452 438 shost->can_queue = sht->can_queue; 439 + shost->nr_reserved_cmds = sht->nr_reserved_cmds; 453 440 shost->sg_tablesize = sht->sg_tablesize; 454 441 shost->sg_prot_tablesize = sht->sg_prot_tablesize; 455 442 shost->cmd_per_lun = sht->cmd_per_lun; ··· 619 604 } 620 605 621 606 /** 622 - * scsi_host_busy - Return the host busy counter 623 - * @shost: Pointer to Scsi_Host to inc. 607 + * scsi_host_busy - Return the count of in-flight commands 608 + * @shost: Pointer to Scsi_Host 624 609 **/ 625 610 int scsi_host_busy(struct Scsi_Host *shost) 626 611 {
+2 -1
drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
··· 3533 3533 init_completion(&vscsi->wait_idle); 3534 3534 init_completion(&vscsi->unconfig); 3535 3535 3536 - vscsi->work_q = alloc_workqueue("ibmvscsis%s", WQ_MEM_RECLAIM, 1, 3536 + vscsi->work_q = alloc_workqueue("ibmvscsis%s", 3537 + WQ_MEM_RECLAIM | WQ_PERCPU, 1, 3537 3538 dev_name(&vdev->dev)); 3538 3539 if (!vscsi->work_q) { 3539 3540 rc = -ENOMEM;
+6 -4
drivers/scsi/isci/task.h
··· 85 85 86 86 struct completion *complete; 87 87 enum sas_protocol proto; 88 + unsigned char lun[8]; 89 + u16 io_tag; 90 + enum isci_tmf_function_codes tmf_code; 91 + int status; 92 + 93 + /* Must be last --ends in a flexible-array member. */ 88 94 union { 89 95 struct ssp_response_iu resp_iu; 90 96 struct dev_to_host_fis d2h_fis; 91 97 u8 rsp_buf[SSP_RESP_IU_MAX_SIZE]; 92 98 } resp; 93 - unsigned char lun[8]; 94 - u16 io_tag; 95 - enum isci_tmf_function_codes tmf_code; 96 - int status; 97 99 }; 98 100 99 101 static inline void isci_print_tmf(struct isci_host *ihost, struct isci_tmf *tmf)
+3 -1
drivers/scsi/lpfc/lpfc.h
··· 311 311 u16 rx_id; 312 312 u16 ox_id; 313 313 struct lpfc_nodelist *ndlp; 314 - 315 314 }; 316 315 317 316 #define LPFC_VMID_TIMER 300 /* timer interval in seconds */ ··· 633 634 #define FC_CT_RSPN_ID 0x8 /* RSPN_ID accepted by switch */ 634 635 #define FC_CT_RFT_ID 0x10 /* RFT_ID accepted by switch */ 635 636 #define FC_CT_RPRT_DEFER 0x20 /* Defer issuing FDMI RPRT */ 637 + #define FC_CT_RSPNI_PNI 0x40 /* RSPNI_PNI accepted by switch */ 636 638 637 639 struct list_head fc_nodes; 638 640 spinlock_t fc_nodes_list_lock; /* spinlock for fc_nodes list */ ··· 1077 1077 struct lpfc_stats fc_stat; 1078 1078 1079 1079 uint32_t nport_event_cnt; /* timestamp for nlplist entry */ 1080 + 1081 + unsigned long pni; /* 64-bit Platform Name Identifier */ 1080 1082 1081 1083 uint8_t wwnn[8]; 1082 1084 uint8_t wwpn[8];
+36
drivers/scsi/lpfc/lpfc_ct.c
··· 1743 1743 } 1744 1744 1745 1745 static void 1746 + lpfc_cmpl_ct_cmd_rspni_pni(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1747 + struct lpfc_iocbq *rspiocb) 1748 + { 1749 + struct lpfc_vport *vport; 1750 + struct lpfc_dmabuf *outp; 1751 + struct lpfc_sli_ct_request *ctrsp; 1752 + u32 ulp_status; 1753 + 1754 + vport = cmdiocb->vport; 1755 + ulp_status = get_job_ulpstatus(phba, rspiocb); 1756 + 1757 + if (ulp_status == IOSTAT_SUCCESS) { 1758 + outp = cmdiocb->rsp_dmabuf; 1759 + ctrsp = (struct lpfc_sli_ct_request *)outp->virt; 1760 + if (be16_to_cpu(ctrsp->CommandResponse.bits.CmdRsp) == 1761 + SLI_CT_RESPONSE_FS_ACC) 1762 + vport->ct_flags |= FC_CT_RSPNI_PNI; 1763 + } 1764 + lpfc_cmpl_ct(phba, cmdiocb, rspiocb); 1765 + } 1766 + 1767 + static void 1746 1768 lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 1747 1769 struct lpfc_iocbq *rspiocb) 1748 1770 { ··· 1978 1956 bpl->tus.f.bdeSize = RSPN_REQUEST_SZ; 1979 1957 else if (cmdcode == SLI_CTNS_RSNN_NN) 1980 1958 bpl->tus.f.bdeSize = RSNN_REQUEST_SZ; 1959 + else if (cmdcode == SLI_CTNS_RSPNI_PNI) 1960 + bpl->tus.f.bdeSize = RSPNI_REQUEST_SZ; 1981 1961 else if (cmdcode == SLI_CTNS_DA_ID) 1982 1962 bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ; 1983 1963 else if (cmdcode == SLI_CTNS_RFF_ID) ··· 2100 2076 lpfc_vport_symbolic_node_name(vport, 2101 2077 CtReq->un.rsnn.symbname, size); 2102 2078 cmpl = lpfc_cmpl_ct_cmd_rsnn_nn; 2079 + break; 2080 + case SLI_CTNS_RSPNI_PNI: 2081 + vport->ct_flags &= ~FC_CT_RSPNI_PNI; 2082 + CtReq->CommandResponse.bits.CmdRsp = 2083 + cpu_to_be16(SLI_CTNS_RSPNI_PNI); 2084 + CtReq->un.rspni.pni = cpu_to_be64(phba->pni); 2085 + scnprintf(CtReq->un.rspni.symbname, 2086 + sizeof(CtReq->un.rspni.symbname), "OS Host Name::%s", 2087 + phba->os_host_name); 2088 + CtReq->un.rspni.len = strnlen(CtReq->un.rspni.symbname, 2089 + sizeof(CtReq->un.rspni.symbname)); 2090 + cmpl = lpfc_cmpl_ct_cmd_rspni_pni; 2103 2091 break; 2104 2092 case SLI_CTNS_DA_ID: 2105 2093 /* Implement DA_ID Nameserver request */
+2 -1
drivers/scsi/lpfc/lpfc_disc.h
··· 1 1 /******************************************************************* 2 2 * This file is part of the Emulex Linux Device Driver for * 3 3 * Fibre Channel Host Bus Adapters. * 4 - * Copyright (C) 2017-2024 Broadcom. All Rights Reserved. The term * 4 + * Copyright (C) 2017-2025 Broadcom. All Rights Reserved. The term * 5 5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * 6 6 * Copyright (C) 2004-2013 Emulex. All rights reserved. * 7 7 * EMULEX and SLI are trademarks of Emulex. * ··· 208 208 NPR list */ 209 209 NLP_RM_DFLT_RPI = 26, /* need to remove leftover dflt RPI */ 210 210 NLP_NODEV_REMOVE = 27, /* Defer removal till discovery ends */ 211 + NLP_FLOGI_DFR_ACC = 28, /* FLOGI LS_ACC was Deferred */ 211 212 NLP_SC_REQ = 29, /* Target requires authentication */ 212 213 NLP_FIRSTBURST = 30, /* Target supports FirstBurst */ 213 214 NLP_RPI_REGISTERED = 31 /* nlp_rpi is valid */
+174 -75
drivers/scsi/lpfc/lpfc_els.c
··· 650 650 ndlp->nlp_class_sup |= FC_COS_CLASS2; 651 651 if (sp->cls3.classValid) 652 652 ndlp->nlp_class_sup |= FC_COS_CLASS3; 653 - if (sp->cls4.classValid) 654 - ndlp->nlp_class_sup |= FC_COS_CLASS4; 655 653 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | 656 654 sp->cmn.bbRcvSizeLsb; 657 655 ··· 932 934 /* Check to see if link went down during discovery */ 933 935 if (lpfc_els_chk_latt(vport)) { 934 936 /* One additional decrement on node reference count to 935 - * trigger the release of the node 937 + * trigger the release of the node. Make sure the ndlp 938 + * is marked NLP_DROPPED. 936 939 */ 937 - if (!(ndlp->fc4_xpt_flags & SCSI_XPT_REGD)) 940 + if (!test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag) && 941 + !test_bit(NLP_DROPPED, &ndlp->nlp_flag) && 942 + !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD)) { 943 + set_bit(NLP_DROPPED, &ndlp->nlp_flag); 938 944 lpfc_nlp_put(ndlp); 945 + } 939 946 goto out; 940 947 } 941 948 ··· 998 995 IOERR_LOOP_OPEN_FAILURE))) 999 996 lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS, 1000 997 "2858 FLOGI Status:x%x/x%x TMO" 1001 - ":x%x Data x%lx x%x\n", 998 + ":x%x Data x%lx x%x x%lx x%x\n", 1002 999 ulp_status, ulp_word4, tmo, 1003 - phba->hba_flag, phba->fcf.fcf_flag); 1000 + phba->hba_flag, phba->fcf.fcf_flag, 1001 + ndlp->nlp_flag, ndlp->fc4_xpt_flags); 1004 1002 1005 1003 /* Check for retry */ 1006 1004 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) { ··· 1019 1015 * reference to trigger node release. 1020 1016 */ 1021 1017 if (!test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag) && 1022 - !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD)) 1018 + !test_bit(NLP_DROPPED, &ndlp->nlp_flag) && 1019 + !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD)) { 1020 + set_bit(NLP_DROPPED, &ndlp->nlp_flag); 1023 1021 lpfc_nlp_put(ndlp); 1022 + } 1024 1023 1025 1024 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS, 1026 1025 "0150 FLOGI Status:x%x/x%x " 1027 - "xri x%x TMO:x%x refcnt %d\n", 1026 + "xri x%x iotag x%x TMO:x%x refcnt %d\n", 1028 1027 ulp_status, ulp_word4, cmdiocb->sli4_xritag, 1029 - tmo, kref_read(&ndlp->kref)); 1028 + cmdiocb->iotag, tmo, kref_read(&ndlp->kref)); 1030 1029 1031 1030 /* If this is not a loop open failure, bail out */ 1032 1031 if (!(ulp_status == IOSTAT_LOCAL_REJECT && ··· 1286 1279 uint32_t tmo, did; 1287 1280 int rc; 1288 1281 1282 + /* It's possible for lpfc to reissue a FLOGI on an ndlp that is marked 1283 + * NLP_DROPPED. This happens when the FLOGI completed with the XB bit 1284 + * set causing lpfc to reference the ndlp until the XRI_ABORTED CQE is 1285 + * issued. The time window for the XRI_ABORTED CQE can be as much as 1286 + * 2*2*RA_TOV allowing for ndlp reuse of this type when the link is 1287 + * cycling quickly. When true, restore the initial reference and remove 1288 + * the NLP_DROPPED flag as lpfc is retrying. 1289 + */ 1290 + if (test_and_clear_bit(NLP_DROPPED, &ndlp->nlp_flag)) { 1291 + if (!lpfc_nlp_get(ndlp)) 1292 + return 1; 1293 + } 1294 + 1289 1295 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm)); 1290 1296 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, 1291 1297 ndlp->nlp_DID, ELS_CMD_FLOGI); ··· 1354 1334 /* Can't do SLI4 class2 without support sequence coalescing */ 1355 1335 sp->cls2.classValid = 0; 1356 1336 sp->cls2.seqDelivery = 0; 1337 + 1338 + /* Fill out Auxiliary Parameter Data */ 1339 + if (phba->pni) { 1340 + sp->aux.flags = 1341 + AUX_PARM_DATA_VALID | AUX_PARM_PNI_VALID; 1342 + sp->aux.pni = cpu_to_be64(phba->pni); 1343 + sp->aux.npiv_cnt = cpu_to_be16(phba->max_vpi - 1); 1344 + } 1357 1345 } else { 1358 1346 /* Historical, setting sequential-delivery bit for SLI3 */ 1359 1347 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0; ··· 1441 1413 phba->defer_flogi_acc.ox_id; 1442 1414 } 1443 1415 1444 - lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 1445 - "3354 Xmit deferred FLOGI ACC: rx_id: x%x," 1446 - " ox_id: x%x, hba_flag x%lx\n", 1447 - phba->defer_flogi_acc.rx_id, 1448 - phba->defer_flogi_acc.ox_id, phba->hba_flag); 1416 + /* The LS_ACC completion needs to drop the initial reference. 1417 + * This is a special case for Pt2Pt because both FLOGIs need 1418 + * to complete and lpfc defers the LS_ACC when the remote 1419 + * FLOGI arrives before the driver's FLOGI. 1420 + */ 1421 + set_bit(NLP_FLOGI_DFR_ACC, &ndlp->nlp_flag); 1449 1422 1450 1423 /* Send deferred FLOGI ACC */ 1451 1424 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc, ··· 1461 1432 lpfc_nlp_put(phba->defer_flogi_acc.ndlp); 1462 1433 phba->defer_flogi_acc.ndlp = NULL; 1463 1434 } 1435 + 1436 + lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 1437 + "3354 Xmit deferred FLOGI ACC: rx_id: x%x," 1438 + " ox_id: x%x, ndlp x%px hba_flag x%lx\n", 1439 + phba->defer_flogi_acc.rx_id, 1440 + phba->defer_flogi_acc.ox_id, 1441 + phba->defer_flogi_acc.ndlp, 1442 + phba->hba_flag); 1464 1443 1465 1444 vport->fc_myDID = did; 1466 1445 } ··· 2285 2248 2286 2249 sp->cmn.valid_vendor_ver_level = 0; 2287 2250 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion)); 2288 - sp->cmn.bbRcvSizeMsb &= 0xF; 2251 + if (!test_bit(FC_PT2PT, &vport->fc_flag)) 2252 + sp->cmn.bbRcvSizeMsb &= 0xF; 2289 2253 2290 2254 /* Check if the destination port supports VMID */ 2291 2255 ndlp->vmid_support = 0; ··· 2405 2367 mode = KERN_INFO; 2406 2368 2407 2369 /* Warn PRLI status */ 2408 - lpfc_printf_vlog(vport, mode, LOG_ELS, 2370 + lpfc_vlog_msg(vport, mode, LOG_ELS, 2409 2371 "2754 PRLI DID:%06X Status:x%x/x%x, " 2410 2372 "data: x%x x%x x%lx\n", 2411 2373 ndlp->nlp_DID, ulp_status, ··· 3062 3024 ndlp->nlp_DID, ulp_status, 3063 3025 ulp_word4); 3064 3026 3027 + /* Call NLP_EVT_DEVICE_RM if link is down or LOGO is aborted */ 3065 3028 if (lpfc_error_lost_link(vport, ulp_status, ulp_word4)) 3066 3029 skip_recovery = 1; 3067 3030 } ··· 3301 3262 return -ENOMEM; 3302 3263 } 3303 3264 rc = lpfc_reg_rpi(phba, vport->vpi, fc_ndlp->nlp_DID, 3304 - (u8 *)&vport->fc_sparam, mbox, fc_ndlp->nlp_rpi); 3265 + (u8 *)&ns_ndlp->fc_sparam, mbox, fc_ndlp->nlp_rpi); 3305 3266 if (rc) { 3306 3267 rc = -EACCES; 3307 3268 goto out; ··· 3345 3306 * 3346 3307 * This routine is a generic completion callback function for Discovery ELS cmd. 3347 3308 * Currently used by the ELS command issuing routines for the ELS State Change 3348 - * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf(). 3309 + * Request (SCR), lpfc_issue_els_scr(), Exchange Diagnostic Capabilities (EDC), 3310 + * lpfc_issue_els_edc() and the ELS RDF, lpfc_issue_els_rdf(). 3349 3311 * These commands will be retried once only for ELS timeout errors. 3350 3312 **/ 3351 3313 static void ··· 3419 3379 lpfc_cmpl_els_edc(phba, cmdiocb, rspiocb); 3420 3380 return; 3421 3381 } 3382 + 3422 3383 if (ulp_status) { 3423 3384 /* ELS discovery cmd completes with error */ 3424 3385 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS | LOG_CGN_MGMT, 3425 3386 "4203 ELS cmd x%x error: x%x x%X\n", cmd, 3426 3387 ulp_status, ulp_word4); 3388 + 3389 + /* In the case where the ELS cmd completes with an error and 3390 + * the node does not have RPI registered, the node is 3391 + * outstanding and should put its initial reference. 3392 + */ 3393 + if ((cmd == ELS_CMD_SCR || cmd == ELS_CMD_RDF) && 3394 + !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD) && 3395 + !test_and_set_bit(NLP_DROPPED, &ndlp->nlp_flag)) 3396 + lpfc_nlp_put(ndlp); 3427 3397 goto out; 3428 3398 } 3429 3399 ··· 3502 3452 uint8_t *pcmd; 3503 3453 uint16_t cmdsize; 3504 3454 struct lpfc_nodelist *ndlp; 3455 + bool node_created = false; 3505 3456 3506 3457 cmdsize = (sizeof(uint32_t) + sizeof(SCR)); 3507 3458 ··· 3512 3461 if (!ndlp) 3513 3462 return 1; 3514 3463 lpfc_enqueue_node(vport, ndlp); 3464 + node_created = true; 3515 3465 } 3516 3466 3517 3467 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, 3518 3468 ndlp->nlp_DID, ELS_CMD_SCR); 3519 3469 if (!elsiocb) 3520 - return 1; 3470 + goto out_node_created; 3521 3471 3522 3472 if (phba->sli_rev == LPFC_SLI_REV4) { 3523 3473 rc = lpfc_reg_fab_ctrl_node(vport, ndlp); 3524 3474 if (rc) { 3525 - lpfc_els_free_iocb(phba, elsiocb); 3526 3475 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE, 3527 3476 "0937 %s: Failed to reg fc node, rc %d\n", 3528 3477 __func__, rc); 3529 - return 1; 3478 + goto out_free_iocb; 3530 3479 } 3531 3480 } 3532 3481 pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt; ··· 3545 3494 phba->fc_stat.elsXmitSCR++; 3546 3495 elsiocb->cmd_cmpl = lpfc_cmpl_els_disc_cmd; 3547 3496 elsiocb->ndlp = lpfc_nlp_get(ndlp); 3548 - if (!elsiocb->ndlp) { 3549 - lpfc_els_free_iocb(phba, elsiocb); 3550 - return 1; 3551 - } 3497 + if (!elsiocb->ndlp) 3498 + goto out_free_iocb; 3552 3499 3553 3500 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 3554 3501 "Issue SCR: did:x%x refcnt %d", 3555 3502 ndlp->nlp_DID, kref_read(&ndlp->kref), 0); 3556 3503 3557 3504 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 3558 - if (rc == IOCB_ERROR) { 3559 - lpfc_els_free_iocb(phba, elsiocb); 3560 - lpfc_nlp_put(ndlp); 3561 - return 1; 3562 - } 3505 + if (rc == IOCB_ERROR) 3506 + goto out_iocb_error; 3563 3507 3564 3508 return 0; 3509 + 3510 + out_iocb_error: 3511 + lpfc_nlp_put(ndlp); 3512 + out_free_iocb: 3513 + lpfc_els_free_iocb(phba, elsiocb); 3514 + out_node_created: 3515 + if (node_created) 3516 + lpfc_nlp_put(ndlp); 3517 + return 1; 3565 3518 } 3566 3519 3567 3520 /** ··· 3652 3597 } 3653 3598 3654 3599 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, 3655 - "Issue RSCN: did:x%x", 3656 - ndlp->nlp_DID, 0, 0); 3600 + "Issue RSCN: did:x%x refcnt %d", 3601 + ndlp->nlp_DID, kref_read(&ndlp->kref), 0); 3657 3602 3658 3603 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 3659 3604 if (rc == IOCB_ERROR) { ··· 3760 3705 lpfc_nlp_put(ndlp); 3761 3706 return 1; 3762 3707 } 3763 - /* This will cause the callback-function lpfc_cmpl_els_cmd to 3764 - * trigger the release of the node. 3765 - */ 3766 - /* Don't release reference count as RDF is likely outstanding */ 3708 + 3767 3709 return 0; 3768 3710 } 3769 3711 ··· 3778 3726 * 3779 3727 * Return code 3780 3728 * 0 - Successfully issued rdf command 3781 - * 1 - Failed to issue rdf command 3729 + * < 0 - Failed to issue rdf command 3730 + * -EACCES - RDF not required for NPIV_PORT 3731 + * -ENODEV - No fabric controller device available 3732 + * -ENOMEM - No available memory 3733 + * -EIO - The mailbox failed to complete successfully. 3734 + * 3782 3735 **/ 3783 3736 int 3784 3737 lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry) ··· 3794 3737 struct lpfc_nodelist *ndlp; 3795 3738 uint16_t cmdsize; 3796 3739 int rc; 3740 + bool node_created = false; 3741 + int err; 3797 3742 3798 3743 cmdsize = sizeof(*prdf); 3744 + 3745 + /* RDF ELS is not required on an NPIV VN_Port. */ 3746 + if (vport->port_type == LPFC_NPIV_PORT) 3747 + return -EACCES; 3799 3748 3800 3749 ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID); 3801 3750 if (!ndlp) { ··· 3809 3746 if (!ndlp) 3810 3747 return -ENODEV; 3811 3748 lpfc_enqueue_node(vport, ndlp); 3749 + node_created = true; 3812 3750 } 3813 - 3814 - /* RDF ELS is not required on an NPIV VN_Port. */ 3815 - if (vport->port_type == LPFC_NPIV_PORT) 3816 - return -EACCES; 3817 3751 3818 3752 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, 3819 3753 ndlp->nlp_DID, ELS_CMD_RDF); 3820 - if (!elsiocb) 3821 - return -ENOMEM; 3754 + if (!elsiocb) { 3755 + err = -ENOMEM; 3756 + goto out_node_created; 3757 + } 3822 3758 3823 3759 /* Configure the payload for the supported FPIN events. */ 3824 3760 prdf = (struct lpfc_els_rdf_req *)elsiocb->cmd_dmabuf->virt; ··· 3843 3781 elsiocb->cmd_cmpl = lpfc_cmpl_els_disc_cmd; 3844 3782 elsiocb->ndlp = lpfc_nlp_get(ndlp); 3845 3783 if (!elsiocb->ndlp) { 3846 - lpfc_els_free_iocb(phba, elsiocb); 3847 - return -EIO; 3784 + err = -EIO; 3785 + goto out_free_iocb; 3848 3786 } 3849 3787 3850 3788 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD, ··· 3853 3791 3854 3792 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 3855 3793 if (rc == IOCB_ERROR) { 3856 - lpfc_els_free_iocb(phba, elsiocb); 3857 - lpfc_nlp_put(ndlp); 3858 - return -EIO; 3794 + err = -EIO; 3795 + goto out_iocb_error; 3859 3796 } 3860 3797 return 0; 3798 + 3799 + out_iocb_error: 3800 + lpfc_nlp_put(ndlp); 3801 + out_free_iocb: 3802 + lpfc_els_free_iocb(phba, elsiocb); 3803 + out_node_created: 3804 + if (node_created) 3805 + lpfc_nlp_put(ndlp); 3806 + return err; 3861 3807 } 3862 3808 3863 3809 /** ··· 3886 3816 lpfc_els_rcv_rdf(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb, 3887 3817 struct lpfc_nodelist *ndlp) 3888 3818 { 3819 + int rc; 3820 + 3821 + rc = lpfc_els_rsp_acc(vport, ELS_CMD_RDF, cmdiocb, ndlp, NULL); 3889 3822 /* Send LS_ACC */ 3890 - if (lpfc_els_rsp_acc(vport, ELS_CMD_RDF, cmdiocb, ndlp, NULL)) { 3823 + if (rc) { 3891 3824 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT, 3892 - "1623 Failed to RDF_ACC from x%x for x%x\n", 3893 - ndlp->nlp_DID, vport->fc_myDID); 3825 + "1623 Failed to RDF_ACC from x%x for x%x Data: %d\n", 3826 + ndlp->nlp_DID, vport->fc_myDID, rc); 3894 3827 return -EIO; 3895 3828 } 3896 3829 3830 + rc = lpfc_issue_els_rdf(vport, 0); 3897 3831 /* Issue new RDF for reregistering */ 3898 - if (lpfc_issue_els_rdf(vport, 0)) { 3832 + if (rc) { 3899 3833 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT, 3900 - "2623 Failed to re register RDF for x%x\n", 3901 - vport->fc_myDID); 3834 + "2623 Failed to re register RDF for x%x Data: %d\n", 3835 + vport->fc_myDID, rc); 3902 3836 return -EIO; 3903 3837 } 3904 3838 ··· 4373 4299 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0); 4374 4300 if (rc == IOCB_ERROR) { 4375 4301 /* The additional lpfc_nlp_put will cause the following 4376 - * lpfc_els_free_iocb routine to trigger the rlease of 4302 + * lpfc_els_free_iocb routine to trigger the release of 4377 4303 * the node. 4378 4304 */ 4379 4305 lpfc_els_free_iocb(phba, elsiocb); ··· 5201 5127 { 5202 5128 struct lpfc_dmabuf *buf_ptr, *buf_ptr1; 5203 5129 5204 - /* The I/O iocb is complete. Clear the node and first dmbuf */ 5130 + /* The I/O iocb is complete. Clear the node and first dmabuf */ 5205 5131 elsiocb->ndlp = NULL; 5206 5132 5207 5133 /* cmd_dmabuf = cmd, cmd_dmabuf->next = rsp, bpl_dmabuf = bpl */ ··· 5234 5160 } else { 5235 5161 buf_ptr1 = elsiocb->cmd_dmabuf; 5236 5162 lpfc_els_free_data(phba, buf_ptr1); 5237 - elsiocb->cmd_dmabuf = NULL; 5238 5163 } 5239 5164 } 5240 5165 5241 5166 if (elsiocb->bpl_dmabuf) { 5242 5167 buf_ptr = elsiocb->bpl_dmabuf; 5243 5168 lpfc_els_free_bpl(phba, buf_ptr); 5244 - elsiocb->bpl_dmabuf = NULL; 5245 5169 } 5246 5170 lpfc_sli_release_iocbq(phba, elsiocb); 5247 5171 return 0; ··· 5377 5305 IOCB_t *irsp; 5378 5306 LPFC_MBOXQ_t *mbox = NULL; 5379 5307 u32 ulp_status, ulp_word4, tmo, did, iotag; 5308 + u32 cmd; 5380 5309 5381 5310 if (!vport) { 5382 5311 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, 5383 5312 "3177 null vport in ELS rsp\n"); 5384 - goto out; 5313 + goto release; 5385 5314 } 5386 5315 if (cmdiocb->context_un.mbox) 5387 5316 mbox = cmdiocb->context_un.mbox; ··· 5492 5419 * these conditions because it doesn't need the login. 5493 5420 */ 5494 5421 if (phba->sli_rev == LPFC_SLI_REV4 && 5495 - vport && vport->port_type == LPFC_NPIV_PORT && 5422 + vport->port_type == LPFC_NPIV_PORT && 5496 5423 !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD)) { 5497 5424 if (ndlp->nlp_state != NLP_STE_PLOGI_ISSUE && 5498 5425 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE && ··· 5508 5435 } 5509 5436 } 5510 5437 5438 + /* The driver's unsolicited deferred FLOGI ACC in Pt2Pt needs to 5439 + * release the initial reference because the put after the free_iocb 5440 + * call removes only the reference from the defer logic. This FLOGI 5441 + * is never registered with the SCSI transport. 5442 + */ 5443 + if (test_bit(FC_PT2PT, &vport->fc_flag) && 5444 + test_and_clear_bit(NLP_FLOGI_DFR_ACC, &ndlp->nlp_flag)) { 5445 + lpfc_printf_vlog(vport, KERN_INFO, 5446 + LOG_ELS | LOG_NODE | LOG_DISCOVERY, 5447 + "3357 Pt2Pt Defer FLOGI ACC ndlp x%px, " 5448 + "nflags x%lx, fc_flag x%lx\n", 5449 + ndlp, ndlp->nlp_flag, 5450 + vport->fc_flag); 5451 + cmd = *((u32 *)cmdiocb->cmd_dmabuf->virt); 5452 + if (cmd == ELS_CMD_ACC) { 5453 + if (!test_and_set_bit(NLP_DROPPED, &ndlp->nlp_flag)) 5454 + lpfc_nlp_put(ndlp); 5455 + } 5456 + } 5457 + 5458 + release: 5511 5459 /* Release the originating I/O reference. */ 5512 5460 lpfc_els_free_iocb(phba, cmdiocb); 5513 5461 lpfc_nlp_put(ndlp); ··· 5663 5569 sp->cls1.classValid = 0; 5664 5570 sp->cls2.classValid = 0; 5665 5571 sp->cls3.classValid = 0; 5666 - sp->cls4.classValid = 0; 5667 5572 5668 5573 /* Copy our worldwide names */ 5669 5574 memcpy(&sp->portName, &vport->fc_sparam.portName, ··· 5676 5583 sp->cmn.valid_vendor_ver_level = 0; 5677 5584 memset(sp->un.vendorVersion, 0, 5678 5585 sizeof(sp->un.vendorVersion)); 5679 - sp->cmn.bbRcvSizeMsb &= 0xF; 5586 + if (!test_bit(FC_PT2PT, &vport->fc_flag)) 5587 + sp->cmn.bbRcvSizeMsb &= 0xF; 5680 5588 5681 5589 /* If our firmware supports this feature, convey that 5682 5590 * info to the target using the vendor specific field. ··· 8496 8402 &wqe->xmit_els_rsp.wqe_com); 8497 8403 8498 8404 vport->fc_myDID = did; 8499 - 8500 - lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 8501 - "3344 Deferring FLOGI ACC: rx_id: x%x," 8502 - " ox_id: x%x, hba_flag x%lx\n", 8503 - phba->defer_flogi_acc.rx_id, 8504 - phba->defer_flogi_acc.ox_id, phba->hba_flag); 8505 - 8506 8405 phba->defer_flogi_acc.flag = true; 8507 8406 8508 8407 /* This nlp_get is paired with nlp_puts that reset the ··· 8504 8417 * processed or cancelled. 8505 8418 */ 8506 8419 phba->defer_flogi_acc.ndlp = lpfc_nlp_get(ndlp); 8420 + 8421 + lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 8422 + "3344 Deferring FLOGI ACC: rx_id: x%x," 8423 + " ox_id: x%x, ndlp x%px, hba_flag x%lx\n", 8424 + phba->defer_flogi_acc.rx_id, 8425 + phba->defer_flogi_acc.ox_id, 8426 + phba->defer_flogi_acc.ndlp, 8427 + phba->hba_flag); 8507 8428 return 0; 8508 8429 } 8509 8430 ··· 8829 8734 * @cmdiocb: pointer to lpfc command iocb data structure. 8830 8735 * @ndlp: pointer to a node-list data structure. 8831 8736 * 8832 - * This routine processes Read Timout Value (RTV) IOCB received as an 8737 + * This routine processes Read Timeout Value (RTV) IOCB received as an 8833 8738 * ELS unsolicited event. It first checks the remote port state. If the 8834 8739 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE 8835 8740 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject ··· 10452 10357 * Do not process any unsolicited ELS commands 10453 10358 * if the ndlp is in DEV_LOSS 10454 10359 */ 10455 - if (test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag)) { 10456 - if (newnode) 10457 - lpfc_nlp_put(ndlp); 10360 + if (test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag)) 10458 10361 goto dropit; 10459 - } 10460 10362 10461 10363 elsiocb->ndlp = lpfc_nlp_get(ndlp); 10462 10364 if (!elsiocb->ndlp) ··· 10935 10843 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb); 10936 10844 /* 10937 10845 * The different unsolicited event handlers would tell us 10938 - * if they are done with "mp" by setting cmd_dmabuf to NULL. 10846 + * if they are done with "mp" by setting cmd_dmabuf/bpl_dmabuf to NULL. 10939 10847 */ 10940 10848 if (elsiocb->cmd_dmabuf) { 10941 10849 lpfc_in_buf_free(phba, elsiocb->cmd_dmabuf); ··· 11514 11422 sp->cls1.classValid = 0; 11515 11423 sp->cls2.seqDelivery = 1; 11516 11424 sp->cls3.seqDelivery = 1; 11425 + 11426 + /* Fill out Auxiliary Parameter Data */ 11427 + if (phba->pni) { 11428 + sp->aux.flags = 11429 + AUX_PARM_DATA_VALID | AUX_PARM_PNI_VALID; 11430 + sp->aux.pni = cpu_to_be64(phba->pni); 11431 + } 11517 11432 11518 11433 pcmd += sizeof(uint32_t); /* CSP Word 2 */ 11519 11434 pcmd += sizeof(uint32_t); /* CSP Word 3 */
+5 -1
drivers/scsi/lpfc/lpfc_hbadisc.c
··· 424 424 struct lpfc_nodelist *ndlp) 425 425 { 426 426 if (test_and_clear_bit(NLP_IN_RECOV_POST_DEV_LOSS, &ndlp->save_flags)) { 427 + clear_bit(NLP_DROPPED, &ndlp->nlp_flag); 427 428 lpfc_nlp_get(ndlp); 428 429 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY | LOG_NODE, 429 430 "8438 Devloss timeout reversed on DID x%x " ··· 567 566 return fcf_inuse; 568 567 } 569 568 570 - lpfc_nlp_put(ndlp); 569 + if (!test_and_set_bit(NLP_DROPPED, &ndlp->nlp_flag)) 570 + lpfc_nlp_put(ndlp); 571 571 return fcf_inuse; 572 572 } 573 573 ··· 4373 4371 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0); 4374 4372 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0); 4375 4373 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); 4374 + if (phba->pni) 4375 + lpfc_ns_cmd(vport, SLI_CTNS_RSPNI_PNI, 0, 0); 4376 4376 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0); 4377 4377 4378 4378 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
+24 -1
drivers/scsi/lpfc/lpfc_hw.h
··· 168 168 uint8_t len; 169 169 uint8_t symbname[255]; 170 170 } rspn; 171 + struct rspni { /* For RSPNI_PNI requests */ 172 + __be64 pni; 173 + u8 len; 174 + u8 symbname[255]; 175 + } rspni; 171 176 struct gff { 172 177 uint32_t PortId; 173 178 } gff; ··· 218 213 sizeof(struct da_id)) 219 214 #define RSPN_REQUEST_SZ (offsetof(struct lpfc_sli_ct_request, un) + \ 220 215 sizeof(struct rspn)) 216 + #define RSPNI_REQUEST_SZ (offsetof(struct lpfc_sli_ct_request, un) + \ 217 + sizeof(struct rspni)) 221 218 222 219 /* 223 220 * FsType Definitions ··· 316 309 #define SLI_CTNS_RIP_NN 0x0235 317 310 #define SLI_CTNS_RIPA_NN 0x0236 318 311 #define SLI_CTNS_RSNN_NN 0x0239 312 + #define SLI_CTNS_RSPNI_PNI 0x0240 319 313 #define SLI_CTNS_DA_ID 0x0300 320 314 321 315 /* ··· 520 512 uint8_t word3Reserved2; /* Fc Word 3, bit 0: 7 */ 521 513 }; 522 514 515 + enum aux_parm_flags { 516 + AUX_PARM_PNI_VALID = 0x20, /* FC Word 0, bit 29 */ 517 + AUX_PARM_DATA_VALID = 0x40, /* FC Word 0, bit 30 */ 518 + }; 519 + 520 + struct aux_parm { 521 + u8 flags; /* FC Word 0, bit 31:24 */ 522 + u8 ext_feat[3]; /* FC Word 0, bit 23:0 */ 523 + 524 + __be64 pni; /* FC Word 1 and 2, platform name identifier */ 525 + 526 + __be16 rsvd; /* FC Word 3, bit 31:16 */ 527 + __be16 npiv_cnt; /* FC Word 3, bit 15:0 */ 528 + } __packed; 529 + 523 530 struct serv_parm { /* Structure is in Big Endian format */ 524 531 struct csp cmn; 525 532 struct lpfc_name portName; ··· 542 519 struct class_parms cls1; 543 520 struct class_parms cls2; 544 521 struct class_parms cls3; 545 - struct class_parms cls4; 522 + struct aux_parm aux; 546 523 union { 547 524 uint8_t vendorVersion[16]; 548 525 struct {
+4 -10
drivers/scsi/lpfc/lpfc_init.c
··· 3057 3057 lpfc_vmid_vport_cleanup(vport); 3058 3058 3059 3059 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { 3060 - if (ndlp->nlp_DID == Fabric_Cntl_DID && 3061 - ndlp->nlp_state == NLP_STE_UNUSED_NODE) { 3062 - lpfc_nlp_put(ndlp); 3063 - continue; 3064 - } 3065 - 3066 3060 /* Fabric Ports not in UNMAPPED state are cleaned up in the 3067 3061 * DEVICE_RM event. 3068 3062 */ ··· 7944 7950 /* Allocate all driver workqueues here */ 7945 7951 7946 7952 /* The lpfc_wq workqueue for deferred irq use */ 7947 - phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0); 7953 + phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM | WQ_PERCPU, 0); 7948 7954 if (!phba->wq) 7949 7955 return -ENOMEM; 7950 7956 ··· 9076 9082 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; 9077 9083 } 9078 9084 9079 - lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, 9080 - "6077 Setup FDMI mask: hba x%x port x%x\n", 9081 - vport->fdmi_hba_mask, vport->fdmi_port_mask); 9085 + lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY, 9086 + "6077 Setup FDMI mask: hba x%x port x%x\n", 9087 + vport->fdmi_hba_mask, vport->fdmi_port_mask); 9082 9088 } 9083 9089 9084 9090 /**
+4 -17
drivers/scsi/lpfc/lpfc_nportdisc.c
··· 432 432 ndlp->nlp_class_sup |= FC_COS_CLASS2; 433 433 if (sp->cls3.classValid) 434 434 ndlp->nlp_class_sup |= FC_COS_CLASS3; 435 - if (sp->cls4.classValid) 436 - ndlp->nlp_class_sup |= FC_COS_CLASS4; 437 435 ndlp->nlp_maxframe = 438 436 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb; 439 437 /* if already logged in, do implicit logout */ ··· 450 452 */ 451 453 if (!(ndlp->nlp_type & NLP_FABRIC) && 452 454 !(phba->nvmet_support)) { 453 - /* Clear ndlp info, since follow up PRLI may have 454 - * updated ndlp information 455 - */ 456 - ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR); 457 - ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR); 458 - ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; 459 - ndlp->nlp_nvme_info &= ~NLP_NVME_NSLER; 460 - clear_bit(NLP_FIRSTBURST, &ndlp->nlp_flag); 461 - 462 - lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, 463 - ndlp, NULL); 464 - return 1; 455 + break; 465 456 } 466 457 if (nlp_portwwn != 0 && 467 458 nlp_portwwn != wwn_to_u64(sp->portName.u.wwn)) ··· 472 485 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); 473 486 break; 474 487 } 475 - 488 + /* Clear ndlp info, since follow up processes may have 489 + * updated ndlp information 490 + */ 476 491 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR); 477 492 ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR); 478 493 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; ··· 1415 1426 ndlp->nlp_class_sup |= FC_COS_CLASS2; 1416 1427 if (sp->cls3.classValid) 1417 1428 ndlp->nlp_class_sup |= FC_COS_CLASS3; 1418 - if (sp->cls4.classValid) 1419 - ndlp->nlp_class_sup |= FC_COS_CLASS4; 1420 1429 ndlp->nlp_maxframe = 1421 1430 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb; 1422 1431
+75 -4
drivers/scsi/lpfc/lpfc_sli.c
··· 27 27 #include <linux/delay.h> 28 28 #include <linux/slab.h> 29 29 #include <linux/lockdep.h> 30 + #include <linux/dmi.h> 31 + #include <linux/of.h> 30 32 31 33 #include <scsi/scsi.h> 32 34 #include <scsi/scsi_cmnd.h> ··· 8449 8447 } 8450 8448 8451 8449 /** 8450 + * lpfc_get_platform_uuid - Attempts to extract a platform uuid 8451 + * @phba: pointer to lpfc hba data structure. 8452 + * 8453 + * This routine attempts to first read SMBIOS DMI data for the System 8454 + * Information structure offset 08h called System UUID. Else, no platform 8455 + * UUID will be advertised. 8456 + **/ 8457 + static void 8458 + lpfc_get_platform_uuid(struct lpfc_hba *phba) 8459 + { 8460 + int rc; 8461 + const char *uuid; 8462 + char pni[17] = {0}; /* 16 characters + '\0' */ 8463 + bool is_ff = true, is_00 = true; 8464 + u8 i; 8465 + 8466 + /* First attempt SMBIOS DMI */ 8467 + uuid = dmi_get_system_info(DMI_PRODUCT_UUID); 8468 + if (uuid) { 8469 + lpfc_printf_log(phba, KERN_INFO, LOG_INIT, 8470 + "2088 SMBIOS UUID %s\n", 8471 + uuid); 8472 + } else { 8473 + lpfc_printf_log(phba, KERN_INFO, LOG_INIT, 8474 + "2099 Could not extract UUID\n"); 8475 + } 8476 + 8477 + if (uuid && uuid_is_valid(uuid)) { 8478 + /* Generate PNI from UUID format. 8479 + * 8480 + * 1.) Extract lower 64 bits from UUID format. 8481 + * 2.) Set 3h for NAA Locally Assigned Name Identifier format. 8482 + * 8483 + * e.g. xxxxxxxx-xxxx-xxxx-yyyy-yyyyyyyyyyyy 8484 + * 8485 + * extract the yyyy-yyyyyyyyyyyy portion 8486 + * final PNI 3yyyyyyyyyyyyyyy 8487 + */ 8488 + scnprintf(pni, sizeof(pni), "3%c%c%c%s", 8489 + uuid[20], uuid[21], uuid[22], &uuid[24]); 8490 + 8491 + /* Sanitize the converted PNI */ 8492 + for (i = 1; i < 16 && (is_ff || is_00); i++) { 8493 + if (pni[i] != '0') 8494 + is_00 = false; 8495 + if (pni[i] != 'f' && pni[i] != 'F') 8496 + is_ff = false; 8497 + } 8498 + 8499 + /* Convert from char* to unsigned long */ 8500 + rc = kstrtoul(pni, 16, &phba->pni); 8501 + if (!rc && !is_ff && !is_00) { 8502 + lpfc_printf_log(phba, KERN_INFO, LOG_INIT, 8503 + "2100 PNI 0x%016lx\n", phba->pni); 8504 + } else { 8505 + lpfc_printf_log(phba, KERN_INFO, LOG_INIT, 8506 + "2101 PNI %s generation status %d\n", 8507 + pni, rc); 8508 + phba->pni = 0; 8509 + } 8510 + } 8511 + } 8512 + 8513 + /** 8452 8514 * lpfc_sli4_hba_setup - SLI4 device initialization PCI function 8453 8515 * @phba: Pointer to HBA context object. 8454 8516 * ··· 8594 8528 } else { 8595 8529 clear_bit(HBA_FCOE_MODE, &phba->hba_flag); 8596 8530 } 8531 + 8532 + /* Obtain platform UUID, only for SLI4 FC adapters */ 8533 + if (!test_bit(HBA_FCOE_MODE, &phba->hba_flag)) 8534 + lpfc_get_platform_uuid(phba); 8597 8535 8598 8536 if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == 8599 8537 LPFC_DCBX_CEE_MODE) ··· 19928 19858 } 19929 19859 19930 19860 /** 19931 - * lpfc_sli4_resume_rpi - Remove the rpi bitmask region 19861 + * lpfc_sli4_resume_rpi - Resume traffic relative to an RPI 19932 19862 * @ndlp: pointer to lpfc nodelist data structure. 19933 19863 * @cmpl: completion call-back. 19934 19864 * @iocbq: data to load as mbox ctx_u information 19935 19865 * 19936 - * This routine is invoked to remove the memory region that 19937 - * provided rpi via a bitmask. 19866 + * Return codes 19867 + * 0 - successful 19868 + * -ENOMEM - No available memory 19869 + * -EIO - The mailbox failed to complete successfully. 19938 19870 **/ 19939 19871 int 19940 19872 lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, ··· 19966 19894 return -EIO; 19967 19895 } 19968 19896 19969 - /* Post all rpi memory regions to the port. */ 19970 19897 lpfc_resume_rpi(mboxq, ndlp); 19971 19898 if (cmpl) { 19972 19899 mboxq->mbox_cmpl = cmpl;
+1 -1
drivers/scsi/lpfc/lpfc_version.h
··· 20 20 * included with this package. * 21 21 *******************************************************************/ 22 22 23 - #define LPFC_DRIVER_VERSION "14.4.0.11" 23 + #define LPFC_DRIVER_VERSION "14.4.0.12" 24 24 #define LPFC_DRIVER_NAME "lpfc" 25 25 26 26 /* Used for SLI 2/3 */
+12 -5
drivers/scsi/megaraid/megaraid_sas_fusion.h
··· 1150 1150 } LD_SPAN_INFO, *PLD_SPAN_INFO; 1151 1151 1152 1152 struct MR_FW_RAID_MAP_ALL { 1153 - struct MR_FW_RAID_MAP raidMap; 1154 - struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES]; 1153 + /* Must be last --ends in a flexible-array member. */ 1154 + TRAILING_OVERLAP(struct MR_FW_RAID_MAP, raidMap, ldSpanMap, 1155 + struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES]; 1156 + ); 1155 1157 } __attribute__ ((packed)); 1158 + static_assert(offsetof(struct MR_FW_RAID_MAP_ALL, raidMap.ldSpanMap) == 1159 + offsetof(struct MR_FW_RAID_MAP_ALL, ldSpanMap)); 1156 1160 1157 1161 struct MR_DRV_RAID_MAP { 1158 1162 /* total size of this structure, including this field. ··· 1198 1194 * And it is mainly for code re-use purpose. 1199 1195 */ 1200 1196 struct MR_DRV_RAID_MAP_ALL { 1201 - 1202 - struct MR_DRV_RAID_MAP raidMap; 1203 - struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES_DYN]; 1197 + /* Must be last --ends in a flexible-array member. */ 1198 + TRAILING_OVERLAP(struct MR_DRV_RAID_MAP, raidMap, ldSpanMap, 1199 + struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES_DYN]; 1200 + ); 1204 1201 } __packed; 1202 + static_assert(offsetof(struct MR_DRV_RAID_MAP_ALL, raidMap.ldSpanMap) == 1203 + offsetof(struct MR_DRV_RAID_MAP_ALL, ldSpanMap)); 1205 1204 1206 1205 1207 1206
+1 -1
drivers/scsi/pm8001/pm8001_init.c
··· 1534 1534 if (pm8001_use_tasklet && !pm8001_use_msix) 1535 1535 pm8001_use_tasklet = false; 1536 1536 1537 - pm8001_wq = alloc_workqueue("pm80xx", 0, 0); 1537 + pm8001_wq = alloc_workqueue("pm80xx", WQ_PERCPU, 0); 1538 1538 if (!pm8001_wq) 1539 1539 goto err; 1540 1540
+10 -5
drivers/scsi/qedf/qedf_main.c
··· 3374 3374 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_INFO, "qedf->io_mempool=%p.\n", 3375 3375 qedf->io_mempool); 3376 3376 3377 - qedf->link_update_wq = alloc_workqueue("qedf_%u_link", WQ_MEM_RECLAIM, 3377 + qedf->link_update_wq = alloc_workqueue("qedf_%u_link", 3378 + WQ_MEM_RECLAIM | WQ_PERCPU, 3378 3379 1, qedf->lport->host->host_no); 3379 3380 INIT_DELAYED_WORK(&qedf->link_update, qedf_handle_link_update); 3380 3381 INIT_DELAYED_WORK(&qedf->link_recovery, qedf_link_recovery); ··· 3586 3585 ether_addr_copy(params.ll2_mac_address, qedf->mac); 3587 3586 3588 3587 /* Start LL2 processing thread */ 3589 - qedf->ll2_recv_wq = alloc_workqueue("qedf_%d_ll2", WQ_MEM_RECLAIM, 1, 3588 + qedf->ll2_recv_wq = alloc_workqueue("qedf_%d_ll2", 3589 + WQ_MEM_RECLAIM | WQ_PERCPU, 1, 3590 3590 host->host_no); 3591 3591 if (!qedf->ll2_recv_wq) { 3592 3592 QEDF_ERR(&(qedf->dbg_ctx), "Failed to LL2 workqueue.\n"); ··· 3630 3628 } 3631 3629 3632 3630 qedf->timer_work_queue = alloc_workqueue("qedf_%u_timer", 3633 - WQ_MEM_RECLAIM, 1, qedf->lport->host->host_no); 3631 + WQ_MEM_RECLAIM | WQ_PERCPU, 1, 3632 + qedf->lport->host->host_no); 3634 3633 if (!qedf->timer_work_queue) { 3635 3634 QEDF_ERR(&(qedf->dbg_ctx), "Failed to start timer " 3636 3635 "workqueue.\n"); ··· 3644 3641 sprintf(host_buf, "qedf_%u_dpc", 3645 3642 qedf->lport->host->host_no); 3646 3643 qedf->dpc_wq = 3647 - alloc_workqueue("%s", WQ_MEM_RECLAIM, 1, host_buf); 3644 + alloc_workqueue("%s", WQ_MEM_RECLAIM | WQ_PERCPU, 1, 3645 + host_buf); 3648 3646 } 3649 3647 INIT_DELAYED_WORK(&qedf->recovery_work, qedf_recovery_handler); 3650 3648 ··· 4181 4177 goto err3; 4182 4178 } 4183 4179 4184 - qedf_io_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 1, "qedf_io_wq"); 4180 + qedf_io_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM | WQ_PERCPU, 1, 4181 + "qedf_io_wq"); 4185 4182 if (!qedf_io_wq) { 4186 4183 QEDF_ERR(NULL, "Could not create qedf_io_wq.\n"); 4187 4184 goto err4;
+1 -1
drivers/scsi/qedi/qedi_main.c
··· 2768 2768 } 2769 2769 2770 2770 qedi->offload_thread = alloc_workqueue("qedi_ofld%d", 2771 - WQ_MEM_RECLAIM, 2771 + WQ_MEM_RECLAIM | WQ_PERCPU, 2772 2772 1, qedi->shost->host_no); 2773 2773 if (!qedi->offload_thread) { 2774 2774 QEDI_ERR(&qedi->dbg_ctx,
+6 -29
drivers/scsi/qla1280.c
··· 2799 2799 2800 2800 dprintk(2, "start: cmd=%p sp=%p CDB=%xm, handle %lx\n", cmd, sp, 2801 2801 cmd->cmnd[0], (long)CMD_HANDLE(sp->cmd)); 2802 - dprintk(2, " bus %i, target %i, lun %i\n", 2802 + dprintk(2, " bus %i, target %i, lun %llu\n", 2803 2803 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd)); 2804 2804 qla1280_dump_buffer(2, cmd->cmnd, MAX_COMMAND_SIZE); 2805 2805 ··· 2871 2871 remseg--; 2872 2872 } 2873 2873 dprintk(5, "qla1280_64bit_start_scsi: Scatter/gather " 2874 - "command packet data - b %i, t %i, l %i \n", 2874 + "command packet data - b %i, t %i, l %llu\n", 2875 2875 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), 2876 2876 SCSI_LUN_32(cmd)); 2877 2877 qla1280_dump_buffer(5, (char *)pkt, ··· 2929 2929 remseg -= cnt; 2930 2930 dprintk(5, "qla1280_64bit_start_scsi: " 2931 2931 "continuation packet data - b %i, t " 2932 - "%i, l %i \n", SCSI_BUS_32(cmd), 2932 + "%i, l %llu\n", SCSI_BUS_32(cmd), 2933 2933 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd)); 2934 2934 qla1280_dump_buffer(5, (char *)pkt, 2935 2935 REQUEST_ENTRY_SIZE); 2936 2936 } 2937 2937 } else { /* No data transfer */ 2938 2938 dprintk(5, "qla1280_64bit_start_scsi: No data, command " 2939 - "packet data - b %i, t %i, l %i \n", 2939 + "packet data - b %i, t %i, l %llu\n", 2940 2940 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd)); 2941 2941 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE); 2942 2942 } ··· 3655 3655 3656 3656 dprintk(2, "qla1280_status_entry: Check " 3657 3657 "condition Sense data, b %i, t %i, " 3658 - "l %i\n", SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), 3658 + "l %llu\n", SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), 3659 3659 SCSI_LUN_32(cmd)); 3660 3660 if (sense_sz) 3661 3661 qla1280_dump_buffer(2, ··· 3955 3955 3956 3956 sp = scsi_cmd_priv(cmd); 3957 3957 printk("SCSI Command @= 0x%p, Handle=0x%p\n", cmd, CMD_HANDLE(cmd)); 3958 - printk(" chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n", 3958 + printk(" chan=%d, target = 0x%02x, lun = 0x%02llx, cmd_len = 0x%02x\n", 3959 3959 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd), 3960 3960 CMD_CDBLEN(cmd)); 3961 3961 printk(" CDB = "); ··· 3975 3975 scsi_cmd_to_rq(cmd)->tag, cmd->transfersize); 3976 3976 printk(" underflow size = 0x%x, direction=0x%x\n", 3977 3977 cmd->underflow, cmd->sc_data_direction); 3978 - } 3979 - 3980 - /************************************************************************** 3981 - * ql1280_dump_device 3982 - * 3983 - **************************************************************************/ 3984 - static void 3985 - ql1280_dump_device(struct scsi_qla_host *ha) 3986 - { 3987 - 3988 - struct scsi_cmnd *cp; 3989 - struct srb *sp; 3990 - int i; 3991 - 3992 - printk(KERN_DEBUG "Outstanding Commands on controller:\n"); 3993 - 3994 - for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) { 3995 - if ((sp = ha->outstanding_cmds[i]) == NULL) 3996 - continue; 3997 - if ((cp = sp->cmd) == NULL) 3998 - continue; 3999 - qla1280_print_scsi_cmd(1, cp); 4000 - } 4001 3978 } 4002 3979 #endif 4003 3980
+2 -1
drivers/scsi/qla2xxx/qla_dbg.c
··· 54 54 * | Misc | 0xd303 | 0xd031-0xd0ff | 55 55 * | | | 0xd101-0xd1fe | 56 56 * | | | 0xd214-0xd2fe | 57 - * | Target Mode | 0xe081 | | 57 + * | Target Mode | 0xe089 | | 58 58 * | Target Mode Management | 0xf09b | 0xf002 | 59 59 * | | | 0xf046-0xf049 | 60 60 * | Target Mode Task Management | 0x1000d | | 61 + * | Target Mode SRR | 0x11038 | | 61 62 * ---------------------------------------------------------------------- 62 63 */ 63 64
-1
drivers/scsi/qla2xxx/qla_def.h
··· 3503 3503 #define QLA_MSIX_RSP_Q 0x01 3504 3504 #define QLA_ATIO_VECTOR 0x02 3505 3505 #define QLA_MSIX_QPAIR_MULTIQ_RSP_Q 0x03 3506 - #define QLA_MSIX_QPAIR_MULTIQ_RSP_Q_HS 0x04 3507 3506 3508 3507 #define QLA_MIDX_DEFAULT 0 3509 3508 #define QLA_MIDX_RSP_Q 1
+1 -1
drivers/scsi/qla2xxx/qla_gbl.h
··· 766 766 767 767 /* Globa function prototypes for multi-q */ 768 768 extern int qla25xx_request_irq(struct qla_hw_data *, struct qla_qpair *, 769 - struct qla_msix_entry *, int); 769 + struct qla_msix_entry *); 770 770 extern int qla25xx_init_req_que(struct scsi_qla_host *, struct req_que *); 771 771 extern int qla25xx_init_rsp_que(struct scsi_qla_host *, struct rsp_que *); 772 772 extern int qla25xx_create_req_que(struct qla_hw_data *, uint16_t, uint8_t,
+1
drivers/scsi/qla2xxx/qla_init.c
··· 4369 4369 ha->max_npiv_vports = 4370 4370 MIN_MULTI_ID_FABRIC - 1; 4371 4371 } 4372 + qlt_config_nvram_with_fw_version(vha); 4372 4373 qla2x00_get_resource_cnts(vha); 4373 4374 qla_init_iocb_limit(vha); 4374 4375
+3 -29
drivers/scsi/qla2xxx/qla_isr.c
··· 4467 4467 return IRQ_HANDLED; 4468 4468 } 4469 4469 4470 - irqreturn_t 4471 - qla2xxx_msix_rsp_q_hs(int irq, void *dev_id) 4472 - { 4473 - struct qla_hw_data *ha; 4474 - struct qla_qpair *qpair; 4475 - struct device_reg_24xx __iomem *reg; 4476 - unsigned long flags; 4477 - 4478 - qpair = dev_id; 4479 - if (!qpair) { 4480 - ql_log(ql_log_info, NULL, 0x505b, 4481 - "%s: NULL response queue pointer.\n", __func__); 4482 - return IRQ_NONE; 4483 - } 4484 - ha = qpair->hw; 4485 - 4486 - reg = &ha->iobase->isp24; 4487 - spin_lock_irqsave(&ha->hardware_lock, flags); 4488 - wrt_reg_dword(&reg->hccr, HCCRX_CLR_RISC_INT); 4489 - spin_unlock_irqrestore(&ha->hardware_lock, flags); 4490 - 4491 - queue_work(ha->wq, &qpair->q_work); 4492 - 4493 - return IRQ_HANDLED; 4494 - } 4495 - 4496 4470 /* Interrupt handling helpers. */ 4497 4471 4498 4472 struct qla_init_msix_entry { ··· 4479 4505 { "rsp_q", qla24xx_msix_rsp_q }, 4480 4506 { "atio_q", qla83xx_msix_atio_q }, 4481 4507 { "qpair_multiq", qla2xxx_msix_rsp_q }, 4482 - { "qpair_multiq_hs", qla2xxx_msix_rsp_q_hs }, 4483 4508 }; 4484 4509 4485 4510 static const struct qla_init_msix_entry qla82xx_msix_entries[] = { ··· 4765 4792 } 4766 4793 4767 4794 int qla25xx_request_irq(struct qla_hw_data *ha, struct qla_qpair *qpair, 4768 - struct qla_msix_entry *msix, int vector_type) 4795 + struct qla_msix_entry *msix) 4769 4796 { 4770 - const struct qla_init_msix_entry *intr = &msix_entries[vector_type]; 4797 + const struct qla_init_msix_entry *intr = 4798 + &msix_entries[QLA_MSIX_QPAIR_MULTIQ_RSP_Q]; 4771 4799 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev); 4772 4800 int ret; 4773 4801
+2
drivers/scsi/qla2xxx/qla_mbx.c
··· 253 253 /* Issue set host interrupt command to send cmd out. */ 254 254 ha->flags.mbox_int = 0; 255 255 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); 256 + reinit_completion(&ha->mbx_intr_comp); 256 257 257 258 /* Unlock mbx registers and wait for interrupt */ 258 259 ql_dbg(ql_dbg_mbx, vha, 0x100f, ··· 280 279 "cmd=%x Timeout.\n", command); 281 280 spin_lock_irqsave(&ha->hardware_lock, flags); 282 281 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags); 282 + reinit_completion(&ha->mbx_intr_comp); 283 283 spin_unlock_irqrestore(&ha->hardware_lock, flags); 284 284 285 285 if (chip_reset != ha->chip_reset) {
+1 -3
drivers/scsi/qla2xxx/qla_mid.c
··· 899 899 rsp->options, rsp->id, rsp->rsp_q_in, 900 900 rsp->rsp_q_out); 901 901 902 - ret = qla25xx_request_irq(ha, qpair, qpair->msix, 903 - ha->flags.disable_msix_handshake ? 904 - QLA_MSIX_QPAIR_MULTIQ_RSP_Q : QLA_MSIX_QPAIR_MULTIQ_RSP_Q_HS); 902 + ret = qla25xx_request_irq(ha, qpair, qpair->msix); 905 903 if (ret) 906 904 goto que_failed; 907 905
+1 -1
drivers/scsi/qla2xxx/qla_nvme.c
··· 1292 1292 a.reason = FCNVME_RJT_RC_LOGIC; 1293 1293 a.explanation = FCNVME_RJT_EXP_NONE; 1294 1294 xmt_reject = true; 1295 - kfree(item); 1295 + qla24xx_free_purex_item(item); 1296 1296 goto out; 1297 1297 } 1298 1298
+22 -17
drivers/scsi/qla2xxx/qla_os.c
··· 1862 1862 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) { 1863 1863 sp = req->outstanding_cmds[cnt]; 1864 1864 if (sp) { 1865 - if (qla2x00_chip_is_down(vha)) { 1866 - req->outstanding_cmds[cnt] = NULL; 1867 - sp->done(sp, res); 1868 - continue; 1869 - } 1870 - 1871 1865 switch (sp->cmd_type) { 1872 1866 case TYPE_SRB: 1873 1867 qla2x00_abort_srb(qp, sp, res, &flags); ··· 1875 1881 continue; 1876 1882 } 1877 1883 cmd = (struct qla_tgt_cmd *)sp; 1878 - cmd->aborted = 1; 1884 + 1885 + if (cmd->sg_mapped) 1886 + qlt_unmap_sg(vha, cmd); 1887 + 1888 + if (cmd->state == QLA_TGT_STATE_NEED_DATA) { 1889 + cmd->aborted = 1; 1890 + cmd->write_data_transferred = 0; 1891 + cmd->state = QLA_TGT_STATE_DATA_IN; 1892 + ha->tgt.tgt_ops->handle_data(cmd); 1893 + } else { 1894 + ha->tgt.tgt_ops->free_cmd(cmd); 1895 + } 1879 1896 break; 1880 1897 case TYPE_TGT_TMCMD: 1881 - /* Skip task management functions. */ 1898 + /* 1899 + * Currently, only ABTS response gets on the 1900 + * outstanding_cmds[] 1901 + */ 1902 + qlt_free_ul_mcmd(ha, 1903 + (struct qla_tgt_mgmt_cmd *) sp); 1882 1904 break; 1883 1905 default: 1884 1906 break; ··· 3407 3397 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n", 3408 3398 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out); 3409 3399 3410 - ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 0); 3400 + ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM | WQ_PERCPU, 0); 3411 3401 if (unlikely(!ha->wq)) { 3412 3402 ret = -ENOMEM; 3413 3403 goto probe_failed; ··· 3454 3444 ha->mqenable = 0; 3455 3445 3456 3446 if (ha->mqenable) { 3457 - bool startit = false; 3458 - 3459 - if (QLA_TGT_MODE_ENABLED()) 3460 - startit = false; 3461 - 3462 - if (ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED) 3463 - startit = true; 3447 + bool startit = !!(host->active_mode & MODE_INITIATOR); 3464 3448 3465 3449 /* Create start of day qpairs for Block MQ */ 3466 3450 for (i = 0; i < ha->max_qpairs; i++) ··· 5284 5280 qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT); 5285 5281 spin_unlock_irqrestore(&fcport->vha->work_lock, flags); 5286 5282 5287 - queue_work(system_unbound_wq, &fcport->reg_work); 5283 + queue_work(system_dfl_wq, &fcport->reg_work); 5288 5284 } 5289 5285 5290 5286 static ··· 7248 7244 if (!test_bit(UNLOADING, &vha->dpc_flags) && t) 7249 7245 wake_up_process(t); 7250 7246 } 7247 + EXPORT_SYMBOL(qla2xxx_wake_dpc); 7251 7248 7252 7249 /* 7253 7250 * qla2x00_rst_aen
+1495 -276
drivers/scsi/qla2xxx/qla_target.c
··· 104 104 response_t *pkt); 105 105 static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun, 106 106 int fn, void *iocb, int flags); 107 - static void qlt_send_term_exchange(struct qla_qpair *, struct qla_tgt_cmd 108 - *cmd, struct atio_from_isp *atio, int ha_locked, int ul_abort); 109 107 static void qlt_alloc_qfull_cmd(struct scsi_qla_host *vha, 110 108 struct atio_from_isp *atio, uint16_t status, int qfull); 111 109 static void qlt_disable_vha(struct scsi_qla_host *vha); ··· 133 135 static struct workqueue_struct *qla_tgt_wq; 134 136 static DEFINE_MUTEX(qla_tgt_mutex); 135 137 static LIST_HEAD(qla_tgt_glist); 136 - 137 - static const char *prot_op_str(u32 prot_op) 138 - { 139 - switch (prot_op) { 140 - case TARGET_PROT_NORMAL: return "NORMAL"; 141 - case TARGET_PROT_DIN_INSERT: return "DIN_INSERT"; 142 - case TARGET_PROT_DOUT_INSERT: return "DOUT_INSERT"; 143 - case TARGET_PROT_DIN_STRIP: return "DIN_STRIP"; 144 - case TARGET_PROT_DOUT_STRIP: return "DOUT_STRIP"; 145 - case TARGET_PROT_DIN_PASS: return "DIN_PASS"; 146 - case TARGET_PROT_DOUT_PASS: return "DOUT_PASS"; 147 - default: return "UNKNOWN"; 148 - } 149 - } 150 138 151 139 /* This API intentionally takes dest as a parameter, rather than returning 152 140 * int value to avoid caller forgetting to issue wmb() after the store */ ··· 210 226 struct qla_tgt_sess_op *u; 211 227 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; 212 228 unsigned long flags; 229 + unsigned int add_cdb_len = 0; 230 + 231 + /* atio must be the last member of qla_tgt_sess_op for add_cdb_len */ 232 + BUILD_BUG_ON(offsetof(struct qla_tgt_sess_op, atio) + sizeof(u->atio) != sizeof(*u)); 213 233 214 234 if (tgt->tgt_stop) { 215 235 ql_dbg(ql_dbg_async, vha, 0x502c, ··· 222 234 goto out_term; 223 235 } 224 236 225 - u = kzalloc(sizeof(*u), GFP_ATOMIC); 237 + if (atio->u.raw.entry_type == ATIO_TYPE7 && 238 + atio->u.isp24.fcp_cmnd.task_mgmt_flags == 0) 239 + add_cdb_len = 240 + ((unsigned int) atio->u.isp24.fcp_cmnd.add_cdb_len) * 4; 241 + 242 + u = kzalloc(sizeof(*u) + add_cdb_len, GFP_ATOMIC); 226 243 if (u == NULL) 227 244 goto out_term; 228 245 229 246 u->vha = vha; 230 - memcpy(&u->atio, atio, sizeof(*atio)); 247 + memcpy(&u->atio, atio, sizeof(*atio) + add_cdb_len); 231 248 INIT_LIST_HEAD(&u->cmd_list); 232 249 233 250 spin_lock_irqsave(&vha->cmd_list_lock, flags); ··· 245 252 return; 246 253 247 254 out_term: 248 - qlt_send_term_exchange(vha->hw->base_qpair, NULL, atio, ha_locked, 0); 255 + qlt_send_term_exchange(vha->hw->base_qpair, NULL, atio, ha_locked); 249 256 goto out; 250 257 } 251 258 ··· 264 271 "Freeing unknown %s %p, because of Abort\n", 265 272 "ATIO_TYPE7", u); 266 273 qlt_send_term_exchange(vha->hw->base_qpair, NULL, 267 - &u->atio, ha_locked, 0); 274 + &u->atio, ha_locked); 268 275 goto abort; 269 276 } 270 277 ··· 278 285 "Freeing unknown %s %p, because tgt is being stopped\n", 279 286 "ATIO_TYPE7", u); 280 287 qlt_send_term_exchange(vha->hw->base_qpair, NULL, 281 - &u->atio, ha_locked, 0); 288 + &u->atio, ha_locked); 282 289 } else { 283 290 ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503d, 284 291 "Reschedule u %p, vha %p, host %p\n", u, vha, host); ··· 1902 1909 * ABTS response. So, in it ID fields are reversed. 1903 1910 */ 1904 1911 1912 + ql_dbg(ql_dbg_tgt_mgt, vha, 0xe082, 1913 + "qla_target(%d): tag %u: Sending TERM EXCH CTIO for ABTS\n", 1914 + vha->vp_idx, le32_to_cpu(entry->exchange_addr_to_abort)); 1915 + 1905 1916 ctio->entry_type = CTIO_TYPE7; 1906 1917 ctio->entry_count = 1; 1907 1918 ctio->nport_handle = entry->nport_handle; ··· 1984 1987 cmd_key = sid_to_key(cmd->atio.u.isp24.fcp_hdr.s_id); 1985 1988 cmd_lun = scsilun_to_int( 1986 1989 (struct scsi_lun *)&cmd->atio.u.isp24.fcp_cmnd.lun); 1987 - if (cmd_key == key && cmd_lun == lun) 1990 + if (cmd_key == key && cmd_lun == lun) { 1991 + ql_dbg(ql_dbg_tgt_mgt, vha, 0xe085, 1992 + "qla_target(%d): tag %lld: aborted by TMR\n", 1993 + vha->vp_idx, cmd->se_cmd.tag); 1988 1994 cmd->aborted = 1; 1995 + } 1989 1996 } 1990 1997 spin_unlock_irqrestore(&vha->cmd_list_lock, flags); 1991 1998 } ··· 2018 2017 struct qla_hw_data *ha = mcmd->vha->hw; 2019 2018 int rc; 2020 2019 uint32_t tag; 2021 - unsigned long flags; 2022 2020 2023 2021 switch (mcmd->tmr_func) { 2024 2022 case QLA_TGT_ABTS: ··· 2032 2032 mcmd->tmr_func, tag); 2033 2033 2034 2034 if (rc != 0) { 2035 - spin_lock_irqsave(mcmd->qpair->qp_lock_ptr, flags); 2036 - switch (mcmd->tmr_func) { 2037 - case QLA_TGT_ABTS: 2038 - mcmd->fc_tm_rsp = FCP_TMF_REJECTED; 2039 - qlt_build_abts_resp_iocb(mcmd); 2040 - break; 2041 - case QLA_TGT_LUN_RESET: 2042 - case QLA_TGT_CLEAR_TS: 2043 - case QLA_TGT_ABORT_TS: 2044 - case QLA_TGT_CLEAR_ACA: 2045 - case QLA_TGT_TARGET_RESET: 2046 - qlt_send_busy(mcmd->qpair, &mcmd->orig_iocb.atio, 2047 - qla_sam_status); 2048 - break; 2049 - 2050 - case QLA_TGT_ABORT_ALL: 2051 - case QLA_TGT_NEXUS_LOSS_SESS: 2052 - case QLA_TGT_NEXUS_LOSS: 2053 - qlt_send_notify_ack(mcmd->qpair, 2054 - &mcmd->orig_iocb.imm_ntfy, 0, 0, 0, 0, 0, 0); 2055 - break; 2056 - } 2057 - spin_unlock_irqrestore(mcmd->qpair->qp_lock_ptr, flags); 2058 - 2059 2035 ql_dbg(ql_dbg_tgt_mgt, mcmd->vha, 0xf052, 2060 2036 "qla_target(%d): tgt_ops->handle_tmr() failed: %d\n", 2061 2037 mcmd->vha->vp_idx, rc); 2062 - mempool_free(mcmd, qla_tgt_mgmt_cmd_mempool); 2038 + mcmd->flags |= QLA24XX_MGMT_LLD_OWNED; 2039 + mcmd->fc_tm_rsp = FCP_TMF_FAILED; 2040 + qlt_xmit_tm_rsp(mcmd); 2063 2041 } 2064 2042 } 2065 2043 ··· 2225 2247 EXPORT_SYMBOL(qlt_free_mcmd); 2226 2248 2227 2249 /* 2250 + * If the upper layer knows about this mgmt cmd, then call its ->free_cmd() 2251 + * callback, which will eventually call qlt_free_mcmd(). Otherwise, call 2252 + * qlt_free_mcmd() directly. 2253 + */ 2254 + void qlt_free_ul_mcmd(struct qla_hw_data *ha, struct qla_tgt_mgmt_cmd *mcmd) 2255 + { 2256 + if (!mcmd) 2257 + return; 2258 + if (mcmd->flags & QLA24XX_MGMT_LLD_OWNED) 2259 + qlt_free_mcmd(mcmd); 2260 + else 2261 + ha->tgt.tgt_ops->free_mcmd(mcmd); 2262 + } 2263 + 2264 + /* 2228 2265 * ha->hardware_lock supposed to be held on entry. Might drop it, then 2229 2266 * reacquire 2230 2267 */ ··· 2331 2338 "RESET-TMR online/active/old-count/new-count = %d/%d/%d/%d.\n", 2332 2339 vha->flags.online, qla2x00_reset_active(vha), 2333 2340 mcmd->reset_count, qpair->chip_reset); 2334 - ha->tgt.tgt_ops->free_mcmd(mcmd); 2341 + qlt_free_ul_mcmd(ha, mcmd); 2335 2342 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); 2336 2343 return; 2337 2344 } 2338 2345 2339 - if (mcmd->flags == QLA24XX_MGMT_SEND_NACK) { 2346 + if (mcmd->flags & QLA24XX_MGMT_SEND_NACK) { 2340 2347 switch (mcmd->orig_iocb.imm_ntfy.u.isp24.status_subcode) { 2341 2348 case ELS_LOGO: 2342 2349 case ELS_PRLO: ··· 2369 2376 * qlt_xmit_tm_rsp() returns here.. 2370 2377 */ 2371 2378 if (free_mcmd) 2372 - ha->tgt.tgt_ops->free_mcmd(mcmd); 2379 + qlt_free_ul_mcmd(ha, mcmd); 2373 2380 2374 2381 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); 2375 2382 } ··· 2436 2443 return -1; 2437 2444 } 2438 2445 2439 - static void qlt_unmap_sg(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd) 2446 + void qlt_unmap_sg(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd) 2440 2447 { 2441 2448 struct qla_hw_data *ha; 2442 2449 struct qla_qpair *qpair; ··· 3211 3218 uint32_t full_req_cnt = 0; 3212 3219 unsigned long flags = 0; 3213 3220 int res; 3214 - 3215 - if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) || 3216 - (cmd->sess && cmd->sess->deleted)) { 3217 - cmd->state = QLA_TGT_STATE_PROCESSED; 3218 - return 0; 3219 - } 3221 + int pre_xmit_res; 3220 3222 3221 3223 ql_dbg_qp(ql_dbg_tgt, qpair, 0xe018, 3222 3224 "is_send_status=%d, cmd->bufflen=%d, cmd->sg_cnt=%d, cmd->dma_data_direction=%d se_cmd[%p] qp %d\n", ··· 3219 3231 1 : 0, cmd->bufflen, cmd->sg_cnt, cmd->dma_data_direction, 3220 3232 &cmd->se_cmd, qpair->id); 3221 3233 3222 - res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status, 3234 + pre_xmit_res = qlt_pre_xmit_response(cmd, &prm, xmit_type, scsi_status, 3223 3235 &full_req_cnt); 3224 - if (unlikely(res != 0)) { 3225 - return res; 3226 - } 3236 + /* 3237 + * Check pre_xmit_res later because we want to check other errors 3238 + * first. 3239 + */ 3240 + 3241 + /* Begin timer on the first call, not on SRR retry. */ 3242 + if (likely(cmd->jiffies_at_hw_st_entry == 0)) 3243 + cmd->jiffies_at_hw_st_entry = get_jiffies_64(); 3227 3244 3228 3245 spin_lock_irqsave(qpair->qp_lock_ptr, flags); 3246 + 3247 + if (unlikely(cmd->sent_term_exchg || 3248 + cmd->sess->deleted || 3249 + !qpair->fw_started || 3250 + cmd->reset_count != qpair->chip_reset)) { 3251 + ql_dbg(ql_dbg_tgt_mgt, vha, 0xe101, 3252 + "qla_target(%d): tag %lld: skipping send response for aborted cmd\n", 3253 + vha->vp_idx, cmd->se_cmd.tag); 3254 + qlt_unmap_sg(vha, cmd); 3255 + cmd->state = QLA_TGT_STATE_PROCESSED; 3256 + vha->hw->tgt.tgt_ops->free_cmd(cmd); 3257 + spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); 3258 + return 0; 3259 + } 3260 + 3261 + /* Check for errors from qlt_pre_xmit_response(). */ 3262 + res = pre_xmit_res; 3263 + if (unlikely(res)) 3264 + goto out_unmap_unlock; 3229 3265 3230 3266 if (xmit_type == QLA_TGT_XMIT_STATUS) 3231 3267 qpair->tgt_counters.core_qla_snd_status++; 3232 3268 else 3233 3269 qpair->tgt_counters.core_qla_que_buf++; 3234 - 3235 - if (!qpair->fw_started || cmd->reset_count != qpair->chip_reset) { 3236 - /* 3237 - * Either the port is not online or this request was from 3238 - * previous life, just abort the processing. 3239 - */ 3240 - cmd->state = QLA_TGT_STATE_PROCESSED; 3241 - ql_dbg_qp(ql_dbg_async, qpair, 0xe101, 3242 - "RESET-RSP online/active/old-count/new-count = %d/%d/%d/%d.\n", 3243 - vha->flags.online, qla2x00_reset_active(vha), 3244 - cmd->reset_count, qpair->chip_reset); 3245 - res = 0; 3246 - goto out_unmap_unlock; 3247 - } 3248 3270 3249 3271 /* Does F/W have an IOCBs for this request */ 3250 3272 res = qlt_check_reserve_free_req(qpair, full_req_cnt); ··· 3370 3372 struct qla_tgt_prm prm; 3371 3373 unsigned long flags = 0; 3372 3374 int res = 0; 3375 + int pci_map_res; 3373 3376 struct qla_qpair *qpair = cmd->qpair; 3377 + 3378 + /* Begin timer on the first call, not on SRR retry. */ 3379 + if (likely(cmd->jiffies_at_hw_st_entry == 0)) 3380 + cmd->jiffies_at_hw_st_entry = get_jiffies_64(); 3374 3381 3375 3382 memset(&prm, 0, sizeof(prm)); 3376 3383 prm.cmd = cmd; ··· 3383 3380 prm.sg = NULL; 3384 3381 prm.req_cnt = 1; 3385 3382 3386 - if (!qpair->fw_started || (cmd->reset_count != qpair->chip_reset) || 3387 - (cmd->sess && cmd->sess->deleted)) { 3388 - /* 3389 - * Either the port is not online or this request was from 3390 - * previous life, just abort the processing. 3391 - */ 3383 + /* Calculate number of entries and segments required */ 3384 + pci_map_res = qlt_pci_map_calc_cnt(&prm); 3385 + /* 3386 + * Check pci_map_res later because we want to check other errors first. 3387 + */ 3388 + 3389 + spin_lock_irqsave(qpair->qp_lock_ptr, flags); 3390 + 3391 + if (unlikely(cmd->sent_term_exchg || 3392 + cmd->sess->deleted || 3393 + !qpair->fw_started || 3394 + cmd->reset_count != qpair->chip_reset)) { 3395 + ql_dbg(ql_dbg_tgt_mgt, vha, 0xe102, 3396 + "qla_target(%d): tag %lld: skipping data-out for aborted cmd\n", 3397 + vha->vp_idx, cmd->se_cmd.tag); 3398 + qlt_unmap_sg(vha, cmd); 3392 3399 cmd->aborted = 1; 3393 3400 cmd->write_data_transferred = 0; 3394 3401 cmd->state = QLA_TGT_STATE_DATA_IN; 3402 + cmd->jiffies_at_hw_st_entry = 0; 3395 3403 vha->hw->tgt.tgt_ops->handle_data(cmd); 3396 - ql_dbg_qp(ql_dbg_async, qpair, 0xe102, 3397 - "RESET-XFR online/active/old-count/new-count = %d/%d/%d/%d.\n", 3398 - vha->flags.online, qla2x00_reset_active(vha), 3399 - cmd->reset_count, qpair->chip_reset); 3404 + spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); 3400 3405 return 0; 3401 3406 } 3402 3407 3403 - /* Calculate number of entries and segments required */ 3404 - if (qlt_pci_map_calc_cnt(&prm) != 0) 3405 - return -EAGAIN; 3408 + /* Check for errors from qlt_pci_map_calc_cnt(). */ 3409 + if (unlikely(pci_map_res != 0)) { 3410 + res = -EAGAIN; 3411 + goto out_unlock_free_unmap; 3412 + } 3406 3413 3407 - spin_lock_irqsave(qpair->qp_lock_ptr, flags); 3408 3414 /* Does F/W have an IOCBs for this request */ 3409 3415 res = qlt_check_reserve_free_req(qpair, prm.req_cnt); 3410 3416 if (res != 0) ··· 3450 3438 return res; 3451 3439 3452 3440 out_unlock_free_unmap: 3441 + cmd->jiffies_at_hw_st_entry = 0; 3453 3442 qlt_unmap_sg(vha, cmd); 3454 3443 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); 3455 3444 ··· 3470 3457 uint8_t *ep = &sts->expected_dif[0]; 3471 3458 uint64_t lba = cmd->se_cmd.t_task_lba; 3472 3459 uint8_t scsi_status, sense_key, asc, ascq; 3473 - unsigned long flags; 3474 3460 struct scsi_qla_host *vha = cmd->vha; 3475 3461 3476 3462 cmd->trc_flags |= TRC_DIF_ERR; ··· 3540 3528 case QLA_TGT_STATE_NEED_DATA: 3541 3529 /* handle_data will load DIF error code */ 3542 3530 cmd->state = QLA_TGT_STATE_DATA_IN; 3531 + cmd->jiffies_at_hw_st_entry = 0; 3543 3532 vha->hw->tgt.tgt_ops->handle_data(cmd); 3544 3533 break; 3545 3534 default: 3546 - spin_lock_irqsave(&cmd->cmd_lock, flags); 3547 - if (cmd->aborted) { 3548 - spin_unlock_irqrestore(&cmd->cmd_lock, flags); 3535 + if (cmd->sent_term_exchg) { 3549 3536 vha->hw->tgt.tgt_ops->free_cmd(cmd); 3550 3537 break; 3551 3538 } 3552 - spin_unlock_irqrestore(&cmd->cmd_lock, flags); 3553 3539 3554 3540 qlt_send_resp_ctio(qpair, cmd, scsi_status, sense_key, asc, 3555 3541 ascq); ··· 3621 3611 } 3622 3612 3623 3613 /* 3614 + * Handle a SRR that had been previously associated with a command when the 3615 + * command has been aborted or otherwise cannot process the SRR. 3616 + * 3617 + * If reject is true, then attempt to reject the SRR. Otherwise abort the 3618 + * immediate notify exchange. 3619 + */ 3620 + void qlt_srr_abort(struct qla_tgt_cmd *cmd, bool reject) 3621 + { 3622 + struct scsi_qla_host *vha = cmd->vha; 3623 + struct qla_tgt_srr *srr = cmd->srr; 3624 + 3625 + if (srr->imm_ntfy_recvd) { 3626 + if (reject) 3627 + srr->reject = true; 3628 + else 3629 + srr->aborted = true; 3630 + 3631 + if (srr->ctio_recvd) { 3632 + /* 3633 + * The SRR should already be scheduled for processing, 3634 + * and the SRR processing code should see that the cmd 3635 + * has been aborted and take appropriate action. In 3636 + * addition, the cmd refcount should have been 3637 + * incremented, preventing the cmd from being freed 3638 + * until SRR processing is done. 3639 + */ 3640 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x1102e, 3641 + "qla_target(%d): tag %lld: %s: SRR already scheduled\n", 3642 + vha->vp_idx, cmd->se_cmd.tag, __func__); 3643 + } else { 3644 + struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; 3645 + unsigned long flags; 3646 + 3647 + /* Shedule processing for the SRR immediate notify. */ 3648 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x1102f, 3649 + "qla_target(%d): tag %lld: %s: schedule SRR %s\n", 3650 + vha->vp_idx, cmd->se_cmd.tag, __func__, 3651 + reject ? "reject" : "abort"); 3652 + cmd->srr = NULL; 3653 + srr->cmd = NULL; 3654 + spin_lock_irqsave(&tgt->srr_lock, flags); 3655 + list_add_tail(&srr->srr_list_entry, &tgt->srr_list); 3656 + queue_work(qla_tgt_wq, &tgt->srr_work); 3657 + spin_unlock_irqrestore(&tgt->srr_lock, flags); 3658 + } 3659 + } else { 3660 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11030, 3661 + "qla_target(%d): tag %lld: %s: no IMM SRR; free SRR\n", 3662 + vha->vp_idx, cmd->se_cmd.tag, __func__); 3663 + cmd->srr = NULL; 3664 + kfree(srr); 3665 + } 3666 + } 3667 + EXPORT_SYMBOL(qlt_srr_abort); 3668 + 3669 + /* 3624 3670 * If hardware_lock held on entry, might drop it, then reaquire 3625 3671 * This function sends the appropriate CTIO to ISP 2xxx or 24xx 3626 3672 */ ··· 3684 3618 struct qla_tgt_cmd *cmd, 3685 3619 struct atio_from_isp *atio) 3686 3620 { 3687 - struct scsi_qla_host *vha = qpair->vha; 3688 3621 struct ctio7_to_24xx *ctio24; 3689 - struct qla_hw_data *ha = vha->hw; 3690 - request_t *pkt; 3691 - int ret = 0; 3622 + struct scsi_qla_host *vha; 3623 + uint16_t loop_id; 3692 3624 uint16_t temp; 3693 3625 3694 - ql_dbg(ql_dbg_tgt, vha, 0xe009, "Sending TERM EXCH CTIO (ha=%p)\n", ha); 3695 - 3696 - if (cmd) 3626 + if (cmd) { 3697 3627 vha = cmd->vha; 3628 + loop_id = cmd->loop_id; 3629 + } else { 3630 + port_id_t id = be_to_port_id(atio->u.isp24.fcp_hdr.s_id); 3631 + struct qla_hw_data *ha; 3632 + struct fc_port *sess; 3633 + unsigned long flags; 3698 3634 3699 - pkt = (request_t *)qla2x00_alloc_iocbs_ready(qpair, NULL); 3700 - if (pkt == NULL) { 3635 + vha = qpair->vha; 3636 + ha = vha->hw; 3637 + 3638 + /* 3639 + * CTIO7_NHANDLE_UNRECOGNIZED works when aborting an idle 3640 + * command but not when aborting a command with an active CTIO 3641 + * exchange. 3642 + */ 3643 + loop_id = CTIO7_NHANDLE_UNRECOGNIZED; 3644 + spin_lock_irqsave(&ha->tgt.sess_lock, flags); 3645 + sess = qla2x00_find_fcport_by_nportid(vha, &id, 1); 3646 + if (sess) 3647 + loop_id = sess->loop_id; 3648 + spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); 3649 + } 3650 + 3651 + if (cmd) { 3652 + ql_dbg(ql_dbg_tgt_mgt, vha, 0xe009, 3653 + "qla_target(%d): tag %lld: Sending TERM EXCH CTIO state %d cmd_sent_to_fw %u\n", 3654 + vha->vp_idx, cmd->se_cmd.tag, cmd->state, 3655 + cmd->cmd_sent_to_fw); 3656 + } else { 3657 + ql_dbg(ql_dbg_tgt_mgt, vha, 0xe009, 3658 + "qla_target(%d): tag %u: Sending TERM EXCH CTIO (no cmd)\n", 3659 + vha->vp_idx, le32_to_cpu(atio->u.isp24.exchange_addr)); 3660 + } 3661 + 3662 + ctio24 = qla2x00_alloc_iocbs_ready(qpair, NULL); 3663 + if (!ctio24) { 3701 3664 ql_dbg(ql_dbg_tgt, vha, 0xe050, 3702 3665 "qla_target(%d): %s failed: unable to allocate " 3703 3666 "request packet\n", vha->vp_idx, __func__); 3704 3667 return -ENOMEM; 3705 3668 } 3706 3669 3707 - if (cmd != NULL) { 3708 - if (cmd->state < QLA_TGT_STATE_PROCESSED) { 3709 - ql_dbg(ql_dbg_tgt, vha, 0xe051, 3710 - "qla_target(%d): Terminating cmd %p with " 3711 - "incorrect state %d\n", vha->vp_idx, cmd, 3712 - cmd->state); 3713 - } else 3714 - ret = 1; 3715 - } 3716 - 3717 3670 qpair->tgt_counters.num_term_xchg_sent++; 3718 - pkt->entry_count = 1; 3719 - pkt->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; 3720 3671 3721 - ctio24 = (struct ctio7_to_24xx *)pkt; 3722 3672 ctio24->entry_type = CTIO_TYPE7; 3723 - ctio24->nport_handle = cpu_to_le16(CTIO7_NHANDLE_UNRECOGNIZED); 3673 + ctio24->entry_count = 1; 3674 + ctio24->handle = QLA_TGT_SKIP_HANDLE | CTIO_COMPLETION_HANDLE_MARK; 3675 + ctio24->nport_handle = cpu_to_le16(loop_id); 3724 3676 ctio24->timeout = cpu_to_le16(QLA_TGT_TIMEOUT); 3725 3677 ctio24->vp_index = vha->vp_idx; 3726 3678 ctio24->initiator_id = be_id_to_le(atio->u.isp24.fcp_hdr.s_id); ··· 3755 3671 qpair->reqq_start_iocbs(qpair); 3756 3672 else 3757 3673 qla2x00_start_iocbs(vha, qpair->req); 3758 - return ret; 3674 + return 0; 3759 3675 } 3760 3676 3761 - static void qlt_send_term_exchange(struct qla_qpair *qpair, 3762 - struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked, 3763 - int ul_abort) 3677 + /* 3678 + * Aborting a command that is active in the FW (i.e. cmd->cmd_sent_to_fw == 1) 3679 + * will usually trigger the FW to send a completion CTIO with error status, 3680 + * and the driver will then call the ->handle_data() or ->free_cmd() callbacks. 3681 + * This can be used to clear a command that is locked up in the FW unless there 3682 + * is something more seriously wrong. 3683 + * 3684 + * Aborting a command that is not active in the FW (i.e. 3685 + * cmd->cmd_sent_to_fw == 0) will not directly trigger any callbacks. Instead, 3686 + * when the target mode midlevel calls qlt_rdy_to_xfer() or 3687 + * qlt_xmit_response(), the driver will see that the cmd has been aborted and 3688 + * call the appropriate callback immediately without performing the requested 3689 + * operation. 3690 + */ 3691 + void qlt_send_term_exchange(struct qla_qpair *qpair, 3692 + struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked) 3764 3693 { 3765 3694 struct scsi_qla_host *vha; 3766 3695 unsigned long flags = 0; ··· 3797 3700 qlt_alloc_qfull_cmd(vha, atio, 0, 0); 3798 3701 3799 3702 done: 3800 - if (cmd && !ul_abort && !cmd->aborted) { 3801 - if (cmd->sg_mapped) 3802 - qlt_unmap_sg(vha, cmd); 3803 - vha->hw->tgt.tgt_ops->free_cmd(cmd); 3703 + if (cmd) { 3704 + /* 3705 + * Set this even if -ENOMEM above, since term exchange will be 3706 + * sent eventually... 3707 + */ 3708 + cmd->sent_term_exchg = 1; 3709 + cmd->aborted = 1; 3710 + cmd->jiffies_at_term_exchg = jiffies; 3804 3711 } 3805 3712 3806 3713 if (!ha_locked) ··· 3812 3711 3813 3712 return; 3814 3713 } 3714 + EXPORT_SYMBOL(qlt_send_term_exchange); 3815 3715 3816 3716 static void qlt_init_term_exchange(struct scsi_qla_host *vha) 3817 3717 { ··· 3863 3761 3864 3762 int qlt_abort_cmd(struct qla_tgt_cmd *cmd) 3865 3763 { 3866 - struct qla_tgt *tgt = cmd->tgt; 3867 - struct scsi_qla_host *vha = tgt->vha; 3868 - struct se_cmd *se_cmd = &cmd->se_cmd; 3764 + struct scsi_qla_host *vha = cmd->vha; 3765 + struct qla_qpair *qpair = cmd->qpair; 3869 3766 unsigned long flags; 3870 3767 3768 + spin_lock_irqsave(qpair->qp_lock_ptr, flags); 3769 + 3871 3770 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf014, 3872 - "qla_target(%d): terminating exchange for aborted cmd=%p " 3873 - "(se_cmd=%p, tag=%llu)", vha->vp_idx, cmd, &cmd->se_cmd, 3874 - se_cmd->tag); 3771 + "qla_target(%d): tag %lld: cmd being aborted (state %d) %s; %s\n", 3772 + vha->vp_idx, cmd->se_cmd.tag, cmd->state, 3773 + cmd->cmd_sent_to_fw ? "sent to fw" : "not sent to fw", 3774 + cmd->aborted ? "aborted" : "not aborted"); 3875 3775 3876 - spin_lock_irqsave(&cmd->cmd_lock, flags); 3877 - if (cmd->aborted) { 3878 - if (cmd->sg_mapped) 3879 - qlt_unmap_sg(vha, cmd); 3880 - 3881 - spin_unlock_irqrestore(&cmd->cmd_lock, flags); 3882 - /* 3883 - * It's normal to see 2 calls in this path: 3884 - * 1) XFER Rdy completion + CMD_T_ABORT 3885 - * 2) TCM TMR - drain_state_list 3886 - */ 3887 - ql_dbg(ql_dbg_tgt_mgt, vha, 0xf016, 3888 - "multiple abort. %p transport_state %x, t_state %x, " 3889 - "se_cmd_flags %x\n", cmd, cmd->se_cmd.transport_state, 3890 - cmd->se_cmd.t_state, cmd->se_cmd.se_cmd_flags); 3891 - return -EIO; 3776 + if (cmd->state != QLA_TGT_STATE_DONE && !cmd->sent_term_exchg) { 3777 + if (!qpair->fw_started || 3778 + cmd->reset_count != qpair->chip_reset) { 3779 + /* 3780 + * Chip was reset; just pretend that we sent the term 3781 + * exchange. 3782 + */ 3783 + cmd->sent_term_exchg = 1; 3784 + cmd->aborted = 1; 3785 + cmd->jiffies_at_term_exchg = jiffies; 3786 + } else { 3787 + qlt_send_term_exchange(qpair, cmd, &cmd->atio, 1); 3788 + } 3892 3789 } 3893 - cmd->aborted = 1; 3894 - cmd->trc_flags |= TRC_ABORT; 3895 - spin_unlock_irqrestore(&cmd->cmd_lock, flags); 3896 3790 3897 - qlt_send_term_exchange(cmd->qpair, cmd, &cmd->atio, 0, 1); 3791 + spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); 3792 + 3898 3793 return 0; 3899 3794 } 3900 3795 EXPORT_SYMBOL(qlt_abort_cmd); ··· 3911 3812 qlt_decr_num_pend_cmds(cmd->vha); 3912 3813 3913 3814 BUG_ON(cmd->sg_mapped); 3815 + if (unlikely(cmd->free_sg)) { 3816 + cmd->free_sg = 0; 3817 + qlt_free_sg(cmd); 3818 + } 3819 + if (unlikely(cmd->srr)) 3820 + qlt_srr_abort(cmd, false); 3821 + 3822 + if (unlikely(cmd->aborted || 3823 + (cmd->trc_flags & (TRC_CTIO_STRANGE | TRC_CTIO_ERR | 3824 + TRC_SRR_CTIO | TRC_SRR_IMM)))) { 3825 + ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xe086, 3826 + "qla_target(%d): tag %lld: free cmd (trc_flags %x, aborted %u, sent_term_exchg %u, rsp_sent %u)\n", 3827 + cmd->vha->vp_idx, cmd->se_cmd.tag, 3828 + cmd->trc_flags, cmd->aborted, cmd->sent_term_exchg, 3829 + cmd->rsp_sent); 3830 + } 3831 + 3832 + if (unlikely(cmd->cdb != &cmd->atio.u.isp24.fcp_cmnd.cdb[0])) { 3833 + kfree(cmd->cdb); 3834 + cmd->cdb = &cmd->atio.u.isp24.fcp_cmnd.cdb[0]; 3835 + cmd->cdb_len = 16; 3836 + } 3837 + 3914 3838 cmd->jiffies_at_free = get_jiffies_64(); 3915 3839 3916 3840 if (!sess || !sess->se_sess) { 3917 3841 WARN_ON(1); 3918 3842 return; 3919 3843 } 3920 - cmd->jiffies_at_free = get_jiffies_64(); 3921 3844 cmd->vha->hw->tgt.tgt_ops->rel_cmd(cmd); 3922 3845 } 3923 3846 EXPORT_SYMBOL(qlt_free_cmd); 3924 3847 3925 3848 /* 3926 - * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire 3849 + * Process a CTIO response for a SCSI command that failed due to SRR. 3850 + * 3851 + * qpair->qp_lock_ptr supposed to be held on entry 3927 3852 */ 3928 - static int qlt_term_ctio_exchange(struct qla_qpair *qpair, void *ctio, 3929 - struct qla_tgt_cmd *cmd, uint32_t status) 3853 + static int qlt_prepare_srr_ctio(struct qla_qpair *qpair, 3854 + struct qla_tgt_cmd *cmd) 3930 3855 { 3931 - int term = 0; 3932 - struct scsi_qla_host *vha = qpair->vha; 3856 + struct scsi_qla_host *vha = cmd->vha; 3857 + struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; 3858 + struct qla_tgt_srr *srr; 3933 3859 3934 - if (cmd->se_cmd.prot_op) 3935 - ql_dbg(ql_dbg_tgt_dif, vha, 0xe013, 3936 - "Term DIF cmd: lba[0x%llx|%lld] len[0x%x] " 3937 - "se_cmd=%p tag[%x] op %#x/%s", 3938 - cmd->lba, cmd->lba, 3939 - cmd->num_blks, &cmd->se_cmd, 3940 - cmd->atio.u.isp24.exchange_addr, 3941 - cmd->se_cmd.prot_op, 3942 - prot_op_str(cmd->se_cmd.prot_op)); 3860 + cmd->trc_flags |= TRC_SRR_CTIO; 3943 3861 3944 - if (ctio != NULL) { 3945 - struct ctio7_from_24xx *c = (struct ctio7_from_24xx *)ctio; 3862 + srr = cmd->srr; 3863 + if (srr != NULL) { 3864 + /* qlt_prepare_srr_imm() was called first. */ 3946 3865 3947 - term = !(c->flags & 3948 - cpu_to_le16(OF_TERM_EXCH)); 3949 - } else 3950 - term = 1; 3866 + WARN_ON(srr->ctio_recvd); 3867 + WARN_ON(!srr->imm_ntfy_recvd); 3951 3868 3952 - if (term) 3953 - qlt_send_term_exchange(qpair, cmd, &cmd->atio, 1, 0); 3869 + if (vha->hw->tgt.tgt_ops->get_cmd_ref(cmd)) { 3870 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11037, 3871 + "qla_target(%d): tag %lld: unable to get cmd ref for SRR processing\n", 3872 + vha->vp_idx, cmd->se_cmd.tag); 3873 + qlt_srr_abort(cmd, true); 3874 + return -ESHUTDOWN; 3875 + } 3954 3876 3955 - return term; 3877 + srr->ctio_recvd = true; 3878 + 3879 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x1100f, 3880 + "qla_target(%d): tag %lld: Scheduling SRR work\n", 3881 + vha->vp_idx, cmd->se_cmd.tag); 3882 + 3883 + /* Schedule the srr for processing in qlt_handle_srr(). */ 3884 + /* IRQ is already OFF */ 3885 + spin_lock(&tgt->srr_lock); 3886 + list_add_tail(&srr->srr_list_entry, &tgt->srr_list); 3887 + queue_work_on(cmd->se_cmd.cpuid, qla_tgt_wq, &tgt->srr_work); 3888 + spin_unlock(&tgt->srr_lock); 3889 + return 0; 3890 + } 3891 + 3892 + srr = kzalloc(sizeof(*srr), GFP_ATOMIC); 3893 + if (!srr) 3894 + return -ENOMEM; 3895 + 3896 + /* Expect qlt_prepare_srr_imm() to be called. */ 3897 + srr->ctio_recvd = true; 3898 + srr->cmd = cmd; 3899 + srr->reset_count = cmd->reset_count; 3900 + cmd->srr = srr; 3901 + return 0; 3956 3902 } 3957 - 3958 3903 3959 3904 /* ha->hardware_lock supposed to be held on entry */ 3960 3905 static void *qlt_ctio_to_cmd(struct scsi_qla_host *vha, 3961 - struct rsp_que *rsp, uint32_t handle, void *ctio) 3906 + struct rsp_que *rsp, uint32_t handle, uint8_t cmd_type, 3907 + const void *ctio) 3962 3908 { 3963 3909 void *cmd = NULL; 3964 3910 struct req_que *req; ··· 4026 3882 4027 3883 h &= QLA_CMD_HANDLE_MASK; 4028 3884 4029 - if (h != QLA_TGT_NULL_HANDLE) { 4030 - if (unlikely(h >= req->num_outstanding_cmds)) { 4031 - ql_dbg(ql_dbg_tgt, vha, 0xe052, 4032 - "qla_target(%d): Wrong handle %x received\n", 4033 - vha->vp_idx, handle); 4034 - return NULL; 4035 - } 4036 - 4037 - cmd = req->outstanding_cmds[h]; 4038 - if (unlikely(cmd == NULL)) { 4039 - ql_dbg(ql_dbg_async, vha, 0xe053, 4040 - "qla_target(%d): Suspicious: unable to find the command with handle %x req->id %d rsp->id %d\n", 4041 - vha->vp_idx, handle, req->id, rsp->id); 4042 - return NULL; 4043 - } 4044 - req->outstanding_cmds[h] = NULL; 4045 - } else if (ctio != NULL) { 3885 + if (h == QLA_TGT_NULL_HANDLE) { 4046 3886 /* We can't get loop ID from CTIO7 */ 4047 3887 ql_dbg(ql_dbg_tgt, vha, 0xe054, 4048 3888 "qla_target(%d): Wrong CTIO received: QLA24xx doesn't " 4049 3889 "support NULL handles\n", vha->vp_idx); 4050 3890 return NULL; 4051 3891 } 3892 + if (unlikely(h >= req->num_outstanding_cmds)) { 3893 + ql_dbg(ql_dbg_tgt, vha, 0xe052, 3894 + "qla_target(%d): Wrong handle %x received\n", 3895 + vha->vp_idx, handle); 3896 + return NULL; 3897 + } 3898 + 3899 + /* 3900 + * We passed a numeric handle for a cmd to the hardware, and the 3901 + * hardware passed the handle back to us. Look up the associated cmd, 3902 + * and validate that the cmd_type and exchange address match what the 3903 + * caller expects. This guards against buggy HBA firmware that returns 3904 + * the same CTIO multiple times. 3905 + */ 3906 + 3907 + cmd = req->outstanding_cmds[h]; 3908 + 3909 + if (unlikely(cmd == NULL)) { 3910 + if (cmd_type == TYPE_TGT_CMD) { 3911 + __le32 ctio_exchange_addr = 3912 + ((const struct ctio7_from_24xx *)ctio)-> 3913 + exchange_address; 3914 + 3915 + ql_dbg(ql_dbg_tgt_mgt, vha, 0xe053, 3916 + "qla_target(%d): tag %u: handle %x: cmd detached; ignoring CTIO (handle %x req->id %d rsp->id %d)\n", 3917 + vha->vp_idx, le32_to_cpu(ctio_exchange_addr), h, 3918 + handle, req->id, rsp->id); 3919 + } else { 3920 + ql_dbg(ql_dbg_tgt_mgt, vha, 0xe053, 3921 + "qla_target(%d): cmd detached; ignoring CTIO (handle %x req->id %d rsp->id %d)\n", 3922 + vha->vp_idx, handle, req->id, rsp->id); 3923 + } 3924 + return NULL; 3925 + } 3926 + 3927 + if (unlikely(((srb_t *)cmd)->cmd_type != cmd_type)) { 3928 + ql_dbg(ql_dbg_tgt_mgt, vha, 0xe087, 3929 + "qla_target(%d): handle %x: cmd detached; ignoring CTIO (cmd_type mismatch)\n", 3930 + vha->vp_idx, h); 3931 + return NULL; 3932 + } 3933 + 3934 + switch (cmd_type) { 3935 + case TYPE_TGT_CMD: { 3936 + __le32 ctio_exchange_addr = 3937 + ((const struct ctio7_from_24xx *)ctio)-> 3938 + exchange_address; 3939 + __le32 cmd_exchange_addr = 3940 + ((struct qla_tgt_cmd *)cmd)-> 3941 + atio.u.isp24.exchange_addr; 3942 + 3943 + BUILD_BUG_ON(offsetof(struct ctio7_from_24xx, 3944 + exchange_address) != 3945 + offsetof(struct ctio_crc_from_fw, 3946 + exchange_address)); 3947 + 3948 + if (unlikely(ctio_exchange_addr != cmd_exchange_addr)) { 3949 + ql_dbg(ql_dbg_tgt_mgt, vha, 0xe088, 3950 + "qla_target(%d): tag %u: handle %x: cmd detached; ignoring CTIO (exchange address mismatch)\n", 3951 + vha->vp_idx, le32_to_cpu(ctio_exchange_addr), h); 3952 + return NULL; 3953 + } 3954 + break; 3955 + } 3956 + 3957 + case TYPE_TGT_TMCMD: { 3958 + __le32 ctio_exchange_addr = 3959 + ((const struct abts_resp_from_24xx_fw *)ctio)-> 3960 + exchange_address; 3961 + __le32 cmd_exchange_addr = 3962 + ((struct qla_tgt_mgmt_cmd *)cmd)-> 3963 + orig_iocb.abts.exchange_address; 3964 + 3965 + if (unlikely(ctio_exchange_addr != cmd_exchange_addr)) { 3966 + ql_dbg(ql_dbg_tgt_mgt, vha, 0xe089, 3967 + "qla_target(%d): ABTS: handle %x: cmd detached; ignoring CTIO (exchange address mismatch)\n", 3968 + vha->vp_idx, h); 3969 + return NULL; 3970 + } 3971 + break; 3972 + } 3973 + } 3974 + 3975 + req->outstanding_cmds[h] = NULL; 4052 3976 4053 3977 return cmd; 4054 3978 } ··· 4125 3913 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire 4126 3914 */ 4127 3915 static void qlt_do_ctio_completion(struct scsi_qla_host *vha, 4128 - struct rsp_que *rsp, uint32_t handle, uint32_t status, void *ctio) 3916 + struct rsp_que *rsp, uint32_t handle, uint32_t status, 3917 + struct ctio7_from_24xx *ctio) 4129 3918 { 4130 3919 struct qla_hw_data *ha = vha->hw; 4131 - struct se_cmd *se_cmd; 4132 3920 struct qla_tgt_cmd *cmd; 4133 3921 struct qla_qpair *qpair = rsp->qpair; 3922 + uint16_t ctio_flags; 4134 3923 4135 3924 if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) { 4136 3925 /* That could happen only in case of an error/reset/abort */ ··· 4143 3930 return; 4144 3931 } 4145 3932 4146 - cmd = qlt_ctio_to_cmd(vha, rsp, handle, ctio); 4147 - if (cmd == NULL) 4148 - return; 3933 + ctio_flags = le16_to_cpu(ctio->flags); 4149 3934 4150 - if ((le16_to_cpu(((struct ctio7_from_24xx *)ctio)->flags) & CTIO7_FLAGS_DATA_OUT) && 4151 - cmd->sess) { 4152 - qlt_chk_edif_rx_sa_delete_pending(vha, cmd->sess, 4153 - (struct ctio7_from_24xx *)ctio); 3935 + cmd = qlt_ctio_to_cmd(vha, rsp, handle, TYPE_TGT_CMD, ctio); 3936 + if (unlikely(cmd == NULL)) { 3937 + if ((handle & ~QLA_TGT_HANDLE_MASK) == QLA_TGT_SKIP_HANDLE && 3938 + (ctio_flags & 0xe1ff) == (CTIO7_FLAGS_STATUS_MODE_1 | 3939 + CTIO7_FLAGS_TERMINATE)) { 3940 + u32 tag = le32_to_cpu(ctio->exchange_address); 3941 + 3942 + if (status == CTIO_SUCCESS) 3943 + ql_dbg(ql_dbg_tgt_mgt, vha, 0xe083, 3944 + "qla_target(%d): tag %u: term exchange successful\n", 3945 + vha->vp_idx, tag); 3946 + else 3947 + ql_dbg(ql_dbg_tgt_mgt, vha, 0xe084, 3948 + "qla_target(%d): tag %u: term exchange failed; status = 0x%x\n", 3949 + vha->vp_idx, tag, status); 3950 + } 3951 + return; 4154 3952 } 4155 3953 4156 - se_cmd = &cmd->se_cmd; 3954 + if ((ctio_flags & CTIO7_FLAGS_DATA_OUT) && cmd->sess) 3955 + qlt_chk_edif_rx_sa_delete_pending(vha, cmd->sess, ctio); 3956 + 4157 3957 cmd->cmd_sent_to_fw = 0; 4158 3958 4159 3959 qlt_unmap_sg(vha, cmd); 4160 3960 4161 3961 if (unlikely(status != CTIO_SUCCESS)) { 3962 + u8 op = cmd->cdb ? cmd->cdb[0] : 0; 3963 + bool term_exchg = false; 3964 + 3965 + /* 3966 + * If the hardware terminated the exchange, then we don't need 3967 + * to send an explicit term exchange message. 3968 + */ 3969 + if (ctio_flags & OF_TERM_EXCH) { 3970 + cmd->sent_term_exchg = 1; 3971 + cmd->aborted = 1; 3972 + cmd->jiffies_at_term_exchg = jiffies; 3973 + } 3974 + 4162 3975 switch (status & 0xFFFF) { 4163 3976 case CTIO_INVALID_RX_ID: 3977 + term_exchg = true; 4164 3978 if (printk_ratelimit()) 4165 3979 dev_info(&vha->hw->pdev->dev, 4166 - "qla_target(%d): CTIO with INVALID_RX_ID ATIO attr %x CTIO Flags %x|%x\n", 4167 - vha->vp_idx, cmd->atio.u.isp24.attr, 3980 + "qla_target(%d): tag %lld, op %x: CTIO with INVALID_RX_ID status 0x%x received (state %d, port %8phC, LUN %lld, ATIO attr %x, CTIO Flags %x|%x)\n", 3981 + vha->vp_idx, cmd->se_cmd.tag, op, 3982 + status, cmd->state, cmd->sess->port_name, 3983 + cmd->unpacked_lun, cmd->atio.u.isp24.attr, 4168 3984 ((cmd->ctio_flags >> 9) & 0xf), 4169 3985 cmd->ctio_flags); 4170 - 4171 3986 break; 3987 + 4172 3988 case CTIO_LIP_RESET: 4173 3989 case CTIO_TARGET_RESET: 4174 3990 case CTIO_ABORTED: 4175 - /* driver request abort via Terminate exchange */ 3991 + term_exchg = true; 3992 + fallthrough; 4176 3993 case CTIO_TIMEOUT: 4177 - /* They are OK */ 3994 + { 3995 + const char *status_str; 3996 + 3997 + switch (status & 0xFFFF) { 3998 + case CTIO_LIP_RESET: 3999 + status_str = "LIP_RESET"; 4000 + break; 4001 + case CTIO_TARGET_RESET: 4002 + status_str = "TARGET_RESET"; 4003 + break; 4004 + case CTIO_ABORTED: 4005 + status_str = "ABORTED"; 4006 + break; 4007 + case CTIO_TIMEOUT: 4008 + default: 4009 + status_str = "TIMEOUT"; 4010 + break; 4011 + } 4178 4012 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf058, 4179 - "qla_target(%d): CTIO with " 4180 - "status %#x received, state %x, se_cmd %p, " 4181 - "(LIP_RESET=e, ABORTED=2, TARGET_RESET=17, " 4182 - "TIMEOUT=b, INVALID_RX_ID=8)\n", vha->vp_idx, 4183 - status, cmd->state, se_cmd); 4013 + "qla_target(%d): tag %lld, op %x: CTIO with %s status 0x%x received (state %d, port %8phC, LUN %lld)\n", 4014 + vha->vp_idx, cmd->se_cmd.tag, op, 4015 + status_str, status, cmd->state, 4016 + cmd->sess->port_name, cmd->unpacked_lun); 4184 4017 break; 4018 + } 4185 4019 4186 4020 case CTIO_PORT_LOGGED_OUT: 4187 4021 case CTIO_PORT_UNAVAILABLE: ··· 4237 3977 (status & 0xFFFF) == CTIO_PORT_LOGGED_OUT; 4238 3978 4239 3979 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf059, 4240 - "qla_target(%d): CTIO with %s status %x " 4241 - "received (state %x, se_cmd %p)\n", vha->vp_idx, 3980 + "qla_target(%d): tag %lld, op %x: CTIO with %s status 0x%x received (state %d, port %8phC, LUN %lld)\n", 3981 + vha->vp_idx, cmd->se_cmd.tag, op, 4242 3982 logged_out ? "PORT LOGGED OUT" : "PORT UNAVAILABLE", 4243 - status, cmd->state, se_cmd); 3983 + status, cmd->state, cmd->sess->port_name, 3984 + cmd->unpacked_lun); 4244 3985 3986 + term_exchg = true; 4245 3987 if (logged_out && cmd->sess) { 4246 3988 /* 4247 3989 * Session is already logged out, but we need ··· 4258 3996 } 4259 3997 break; 4260 3998 } 3999 + 4000 + case CTIO_SRR_RECEIVED: 4001 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x1100e, 4002 + "qla_target(%d): tag %lld, op %x: CTIO with SRR status 0x%x received (state %d, port %8phC, LUN %lld, bufflen %d)\n", 4003 + vha->vp_idx, cmd->se_cmd.tag, op, status, 4004 + cmd->state, cmd->sess->port_name, 4005 + cmd->unpacked_lun, cmd->bufflen); 4006 + 4007 + if (qlt_prepare_srr_ctio(qpair, cmd) == 0) 4008 + return; 4009 + break; 4010 + 4261 4011 case CTIO_DIF_ERROR: { 4262 4012 struct ctio_crc_from_fw *crc = 4263 4013 (struct ctio_crc_from_fw *)ctio; 4264 4014 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf073, 4265 - "qla_target(%d): CTIO with DIF_ERROR status %x " 4266 - "received (state %x, ulp_cmd %p) actual_dif[0x%llx] " 4267 - "expect_dif[0x%llx]\n", 4268 - vha->vp_idx, status, cmd->state, se_cmd, 4015 + "qla_target(%d): tag %lld, op %x: CTIO with DIF_ERROR status 0x%x received (state %d, port %8phC, LUN %lld, actual_dif[0x%llx] expect_dif[0x%llx])\n", 4016 + vha->vp_idx, cmd->se_cmd.tag, op, status, 4017 + cmd->state, cmd->sess->port_name, 4018 + cmd->unpacked_lun, 4269 4019 *((u64 *)&crc->actual_dif[0]), 4270 4020 *((u64 *)&crc->expected_dif[0])); 4271 4021 4272 - qlt_handle_dif_error(qpair, cmd, ctio); 4022 + qlt_handle_dif_error(qpair, cmd, crc); 4273 4023 return; 4274 4024 } 4275 4025 ··· 4290 4016 case CTIO_FAST_INVALID_REQ: 4291 4017 case CTIO_FAST_SPI_ERR: 4292 4018 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05b, 4293 - "qla_target(%d): CTIO with EDIF error status 0x%x received (state %x, se_cmd %p\n", 4294 - vha->vp_idx, status, cmd->state, se_cmd); 4019 + "qla_target(%d): tag %lld, op %x: CTIO with EDIF error status 0x%x received (state %d, port %8phC, LUN %lld)\n", 4020 + vha->vp_idx, cmd->se_cmd.tag, op, status, 4021 + cmd->state, cmd->sess->port_name, 4022 + cmd->unpacked_lun); 4295 4023 break; 4296 4024 4297 4025 default: 4298 4026 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05b, 4299 - "qla_target(%d): CTIO with error status 0x%x received (state %x, se_cmd %p\n", 4300 - vha->vp_idx, status, cmd->state, se_cmd); 4027 + "qla_target(%d): tag %lld, op %x: CTIO with error status 0x%x received (state %d, port %8phC, LUN %lld)\n", 4028 + vha->vp_idx, cmd->se_cmd.tag, op, status, 4029 + cmd->state, cmd->sess->port_name, 4030 + cmd->unpacked_lun); 4301 4031 break; 4302 4032 } 4303 4033 4034 + cmd->trc_flags |= TRC_CTIO_ERR; 4304 4035 4305 - /* "cmd->aborted" means 4306 - * cmd is already aborted/terminated, we don't 4307 - * need to terminate again. The exchange is already 4308 - * cleaned up/freed at FW level. Just cleanup at driver 4309 - * level. 4036 + /* 4037 + * In state QLA_TGT_STATE_NEED_DATA the failed CTIO was for 4038 + * Data-Out, so either abort the exchange or try sending check 4039 + * condition with sense data depending on the severity of 4040 + * the error. In state QLA_TGT_STATE_PROCESSED the failed CTIO 4041 + * was for status (and possibly Data-In), so don't try sending 4042 + * an error status again in that case (if the error was for 4043 + * Data-In with status, we could try sending status without 4044 + * Data-In, but we don't do that currently). 4310 4045 */ 4311 - if ((cmd->state != QLA_TGT_STATE_NEED_DATA) && 4312 - (!cmd->aborted)) { 4313 - cmd->trc_flags |= TRC_CTIO_ERR; 4314 - if (qlt_term_ctio_exchange(qpair, ctio, cmd, status)) 4315 - return; 4316 - } 4046 + if (!cmd->sent_term_exchg && 4047 + (term_exchg || cmd->state != QLA_TGT_STATE_NEED_DATA)) 4048 + qlt_send_term_exchange(qpair, cmd, &cmd->atio, 1); 4049 + } 4050 + 4051 + if (unlikely(cmd->srr != NULL)) { 4052 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11031, 4053 + "qla_target(%d): tag %lld, op %x: expected CTIO with SRR status; got status 0x%x: state %d, bufflen %d\n", 4054 + vha->vp_idx, cmd->se_cmd.tag, 4055 + cmd->cdb ? cmd->cdb[0] : 0, status, cmd->state, 4056 + cmd->bufflen); 4057 + qlt_srr_abort(cmd, true); 4317 4058 } 4318 4059 4319 4060 if (cmd->state == QLA_TGT_STATE_PROCESSED) { 4320 4061 cmd->trc_flags |= TRC_CTIO_DONE; 4062 + 4063 + if (likely(status == CTIO_SUCCESS)) 4064 + cmd->rsp_sent = 1; 4065 + 4321 4066 } else if (cmd->state == QLA_TGT_STATE_NEED_DATA) { 4322 4067 cmd->state = QLA_TGT_STATE_DATA_IN; 4323 4068 4324 4069 if (status == CTIO_SUCCESS) 4325 4070 cmd->write_data_transferred = 1; 4326 4071 4072 + cmd->jiffies_at_hw_st_entry = 0; 4327 4073 ha->tgt.tgt_ops->handle_data(cmd); 4328 4074 return; 4329 4075 } else if (cmd->aborted) { 4330 4076 cmd->trc_flags |= TRC_CTIO_ABORTED; 4331 4077 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01e, 4332 - "Aborted command %p (tag %lld) finished\n", cmd, se_cmd->tag); 4078 + "qla_target(%d): tag %lld: Aborted command finished\n", 4079 + vha->vp_idx, cmd->se_cmd.tag); 4333 4080 } else { 4334 4081 cmd->trc_flags |= TRC_CTIO_STRANGE; 4335 4082 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05c, 4336 - "qla_target(%d): A command in state (%d) should " 4337 - "not return a CTIO complete\n", vha->vp_idx, cmd->state); 4083 + "qla_target(%d): tag %lld: A command in state (%d) should not return a CTIO complete\n", 4084 + vha->vp_idx, cmd->se_cmd.tag, cmd->state); 4338 4085 } 4339 4086 4340 4087 if (unlikely(status != CTIO_SUCCESS) && ··· 4408 4113 struct qla_hw_data *ha = vha->hw; 4409 4114 struct fc_port *sess = cmd->sess; 4410 4115 struct atio_from_isp *atio = &cmd->atio; 4411 - unsigned char *cdb; 4412 4116 unsigned long flags; 4413 4117 uint32_t data_length; 4414 4118 int ret, fcp_task_attr, data_dir, bidi = 0; ··· 4423 4129 goto out_term; 4424 4130 } 4425 4131 4426 - spin_lock_init(&cmd->cmd_lock); 4427 - cdb = &atio->u.isp24.fcp_cmnd.cdb[0]; 4428 4132 cmd->se_cmd.tag = le32_to_cpu(atio->u.isp24.exchange_addr); 4429 4133 4430 4134 if (atio->u.isp24.fcp_cmnd.rddata && ··· 4440 4148 atio->u.isp24.fcp_cmnd.task_attr); 4441 4149 data_length = get_datalen_for_atio(atio); 4442 4150 4443 - ret = ha->tgt.tgt_ops->handle_cmd(vha, cmd, cdb, data_length, 4151 + ret = ha->tgt.tgt_ops->handle_cmd(vha, cmd, cmd->cdb, data_length, 4444 4152 fcp_task_attr, data_dir, bidi); 4445 4153 if (ret != 0) 4446 4154 goto out_term; ··· 4458 4166 */ 4459 4167 cmd->trc_flags |= TRC_DO_WORK_ERR; 4460 4168 spin_lock_irqsave(qpair->qp_lock_ptr, flags); 4461 - qlt_send_term_exchange(qpair, NULL, &cmd->atio, 1, 0); 4169 + qlt_send_term_exchange(qpair, NULL, &cmd->atio, 1); 4462 4170 4463 4171 qlt_decr_num_pend_cmds(vha); 4172 + if (unlikely(cmd->cdb != &cmd->atio.u.isp24.fcp_cmnd.cdb[0])) { 4173 + kfree(cmd->cdb); 4174 + cmd->cdb = &cmd->atio.u.isp24.fcp_cmnd.cdb[0]; 4175 + cmd->cdb_len = 16; 4176 + } 4464 4177 cmd->vha->hw->tgt.tgt_ops->rel_cmd(cmd); 4465 4178 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); 4466 4179 ··· 4589 4292 cmd->se_cmd.cpuid = h->cpuid; 4590 4293 } 4591 4294 4295 + /* 4296 + * Safely make a fixed-length copy of a variable-length atio by truncating the 4297 + * CDB if necessary. 4298 + */ 4299 + static void memcpy_atio(struct atio_from_isp *dst, 4300 + const struct atio_from_isp *src) 4301 + { 4302 + int len; 4303 + 4304 + memcpy(dst, src, sizeof(*dst)); 4305 + 4306 + /* 4307 + * If the CDB was truncated, prevent get_datalen_for_atio() from 4308 + * accessing invalid memory. 4309 + */ 4310 + len = src->u.isp24.fcp_cmnd.add_cdb_len; 4311 + if (unlikely(len != 0)) { 4312 + dst->u.isp24.fcp_cmnd.add_cdb_len = 0; 4313 + memcpy(&dst->u.isp24.fcp_cmnd.add_cdb[0], 4314 + &src->u.isp24.fcp_cmnd.add_cdb[len * 4], 4315 + 4); 4316 + } 4317 + } 4318 + 4592 4319 static struct qla_tgt_cmd *qlt_get_tag(scsi_qla_host_t *vha, 4593 4320 struct fc_port *sess, 4594 4321 struct atio_from_isp *atio) 4595 4322 { 4596 4323 struct qla_tgt_cmd *cmd; 4324 + int add_cdb_len; 4597 4325 4598 4326 cmd = vha->hw->tgt.tgt_ops->get_cmd(sess); 4599 4327 if (!cmd) 4600 4328 return NULL; 4601 4329 4602 4330 cmd->cmd_type = TYPE_TGT_CMD; 4603 - memcpy(&cmd->atio, atio, sizeof(*atio)); 4331 + memcpy_atio(&cmd->atio, atio); 4604 4332 INIT_LIST_HEAD(&cmd->sess_cmd_list); 4605 4333 cmd->state = QLA_TGT_STATE_NEW; 4606 4334 cmd->tgt = vha->vha_tgt.qla_tgt; ··· 4644 4322 cmd->reset_count = vha->hw->base_qpair->chip_reset; 4645 4323 cmd->vp_idx = vha->vp_idx; 4646 4324 cmd->edif = sess->edif.enable; 4325 + 4326 + cmd->cdb = &cmd->atio.u.isp24.fcp_cmnd.cdb[0]; 4327 + cmd->cdb_len = 16; 4328 + 4329 + /* 4330 + * NOTE: memcpy_atio() set cmd->atio.u.isp24.fcp_cmnd.add_cdb_len to 0, 4331 + * so use the original value here. 4332 + */ 4333 + add_cdb_len = atio->u.isp24.fcp_cmnd.add_cdb_len; 4334 + if (unlikely(add_cdb_len != 0)) { 4335 + int cdb_len = 16 + add_cdb_len * 4; 4336 + u8 *cdb; 4337 + 4338 + cdb = kmalloc(cdb_len, GFP_ATOMIC); 4339 + if (unlikely(!cdb)) { 4340 + vha->hw->tgt.tgt_ops->free_cmd(cmd); 4341 + return NULL; 4342 + } 4343 + /* CAUTION: copy CDB from atio not cmd->atio */ 4344 + memcpy(cdb, atio->u.isp24.fcp_cmnd.cdb, cdb_len); 4345 + cmd->cdb = cdb; 4346 + cmd->cdb_len = cdb_len; 4347 + } 4647 4348 4648 4349 return cmd; 4649 4350 } ··· 5245 4900 } 5246 4901 5247 4902 /* 4903 + * Return true if the HBA firmware version is known to have bugs that 4904 + * prevent Sequence Level Error Recovery (SLER) / Sequence Retransmission 4905 + * Request (SRR) from working. 4906 + * 4907 + * Some bad versions are based on testing and some are based on "Marvell Fibre 4908 + * Channel Firmware Release Notes". 4909 + */ 4910 + static bool qlt_has_sler_fw_bug(struct qla_hw_data *ha) 4911 + { 4912 + bool has_sler_fw_bug = false; 4913 + 4914 + if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) { 4915 + /* 4916 + * In the fw release notes: 4917 + * ER147301 was added to v9.05.00 causing SLER regressions 4918 + * FCD-259 was fixed in v9.08.00 4919 + * FCD-371 was fixed in v9.08.00 4920 + * FCD-1183 was fixed in v9.09.00 4921 + * 4922 + * QLE2694L (ISP2071) known bad firmware (tested): 4923 + * 9.06.02 4924 + * 9.07.00 4925 + * 9.08.02 4926 + * SRRs trigger hundreds of bogus entries in the response 4927 + * queue and various other problems. 4928 + * 4929 + * QLE2694L known good firmware (tested): 4930 + * 8.08.05 4931 + * 9.09.00 4932 + * 4933 + * Suspected bad firmware (not confirmed by testing): 4934 + * v9.05.xx 4935 + * 4936 + * unknown firmware: 4937 + * 9.00.00 - 9.04.xx 4938 + */ 4939 + if (ha->fw_major_version == 9 && 4940 + ha->fw_minor_version >= 5 && 4941 + ha->fw_minor_version <= 8) 4942 + has_sler_fw_bug = true; 4943 + } 4944 + 4945 + return has_sler_fw_bug; 4946 + } 4947 + 4948 + /* 4949 + * Return true and print a message if the HA has been reset since the SRR 4950 + * immediate notify was received; else return false. 4951 + */ 4952 + static bool qlt_srr_is_chip_reset(struct scsi_qla_host *vha, 4953 + struct qla_qpair *qpair, struct qla_tgt_srr *srr) 4954 + { 4955 + if (!vha->flags.online || 4956 + !qpair->fw_started || 4957 + srr->reset_count != qpair->chip_reset) { 4958 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x1100d, 4959 + "qla_target(%d): chip reset; discarding IMM SRR\n", 4960 + vha->vp_idx); 4961 + return true; 4962 + } 4963 + return false; 4964 + } 4965 + 4966 + /* Find and return the command associated with a SRR immediate notify. */ 4967 + static struct qla_tgt_cmd *qlt_srr_to_cmd(struct scsi_qla_host *vha, 4968 + const struct imm_ntfy_from_isp *iocb) 4969 + { 4970 + struct qla_hw_data *ha = vha->hw; 4971 + struct fc_port *sess; 4972 + struct qla_tgt_cmd *cmd; 4973 + uint32_t tag = le32_to_cpu(iocb->u.isp24.exchange_address); 4974 + uint16_t loop_id; 4975 + be_id_t s_id; 4976 + unsigned long flags; 4977 + 4978 + if (tag == ATIO_EXCHANGE_ADDRESS_UNKNOWN) { 4979 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11009, 4980 + "qla_target(%d): IMM SRR with unknown exchange address; reject SRR\n", 4981 + vha->vp_idx); 4982 + return NULL; 4983 + } 4984 + 4985 + loop_id = le16_to_cpu(iocb->u.isp24.nport_handle); 4986 + 4987 + s_id.domain = iocb->u.isp24.port_id[2]; 4988 + s_id.area = iocb->u.isp24.port_id[1]; 4989 + s_id.al_pa = iocb->u.isp24.port_id[0]; 4990 + 4991 + spin_lock_irqsave(&ha->tgt.sess_lock, flags); 4992 + sess = ha->tgt.tgt_ops->find_sess_by_s_id(vha, s_id); 4993 + if (!sess) 4994 + sess = ha->tgt.tgt_ops->find_sess_by_loop_id(vha, loop_id); 4995 + if (!sess || sess->deleted) { 4996 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x1100a, 4997 + "qla_target(%d): could not find session for IMM SRR; reject SRR\n", 4998 + vha->vp_idx); 4999 + spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); 5000 + return NULL; 5001 + } 5002 + spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); 5003 + 5004 + cmd = ha->tgt.tgt_ops->find_cmd_by_tag(sess, tag); 5005 + if (!cmd) { 5006 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x1100b, 5007 + "qla_target(%d): could not find cmd for IMM SRR; reject SRR\n", 5008 + vha->vp_idx); 5009 + } else { 5010 + u16 srr_ox_id = le16_to_cpu(iocb->u.isp24.srr_ox_id); 5011 + u16 cmd_ox_id = be16_to_cpu(cmd->atio.u.isp24.fcp_hdr.ox_id); 5012 + 5013 + if (srr_ox_id != cmd_ox_id) { 5014 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x1100c, 5015 + "qla_target(%d): tag %lld: IMM SRR: srr_ox_id[%04x] != cmd_ox_id[%04x]; reject SRR\n", 5016 + vha->vp_idx, cmd->se_cmd.tag, 5017 + srr_ox_id, cmd_ox_id); 5018 + cmd = NULL; 5019 + } 5020 + } 5021 + 5022 + return cmd; 5023 + } 5024 + 5025 + /* 5026 + * Handle an immediate notify SRR (Sequence Retransmission Request) message from 5027 + * the hardware. The hardware will also send a CTIO with CTIO_SRR_RECEIVED status 5028 + * for the affected command. 5029 + * 5030 + * This may be called a second time for the same immediate notify SRR if 5031 + * CTIO_SRR_RECEIVED is never received and qlt_srr_abort() is called. 5032 + * 5033 + * Process context, no locks 5034 + */ 5035 + static void qlt_handle_srr_imm(struct scsi_qla_host *vha, 5036 + struct qla_tgt_srr *srr) 5037 + { 5038 + struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; 5039 + struct qla_hw_data *ha = vha->hw; 5040 + struct qla_qpair *qpair; 5041 + struct qla_tgt_cmd *cmd; 5042 + uint8_t srr_explain = NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL; 5043 + 5044 + /* handle qlt_srr_abort() */ 5045 + if (srr->aborted) { 5046 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11004, 5047 + "qla_target(%d): IMM SRR: terminating SRR for aborted cmd\n", 5048 + vha->vp_idx); 5049 + spin_lock_irq(&ha->hardware_lock); 5050 + if (!qlt_srr_is_chip_reset(vha, ha->base_qpair, srr)) 5051 + qlt_send_term_imm_notif(vha, &srr->imm_ntfy, 1); 5052 + spin_unlock_irq(&ha->hardware_lock); 5053 + kfree(srr); 5054 + return; 5055 + } 5056 + if (srr->reject) { 5057 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11005, 5058 + "qla_target(%d): IMM SRR: rejecting SRR for unknown cmd\n", 5059 + vha->vp_idx); 5060 + goto out_reject; 5061 + } 5062 + 5063 + /* Find the command associated with the SRR. */ 5064 + cmd = qlt_srr_to_cmd(vha, &srr->imm_ntfy); 5065 + if (cmd == NULL) { 5066 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11005, 5067 + "qla_target(%d): IMM SRR: rejecting SRR for unknown cmd\n", 5068 + vha->vp_idx); 5069 + srr_explain = NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_INVALID_OX_ID_RX_ID; 5070 + goto out_reject; 5071 + } 5072 + 5073 + if (ha->tgt.tgt_ops->get_cmd_ref(cmd)) { 5074 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11038, 5075 + "qla_target(%d): IMM SRR: unable to get cmd ref; rejecting SRR\n", 5076 + vha->vp_idx); 5077 + cmd = NULL; 5078 + goto out_reject; 5079 + } 5080 + 5081 + qpair = cmd->qpair; 5082 + 5083 + spin_lock_irq(qpair->qp_lock_ptr); 5084 + 5085 + if (cmd->reset_count != srr->reset_count) { 5086 + /* force a miscompare */ 5087 + srr->reset_count = qpair->chip_reset ^ 1; 5088 + } 5089 + if (qlt_srr_is_chip_reset(vha, qpair, srr)) { 5090 + spin_unlock_irq(qpair->qp_lock_ptr); 5091 + ha->tgt.tgt_ops->put_cmd_ref(cmd); 5092 + kfree(srr); 5093 + return; 5094 + } 5095 + 5096 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11001, 5097 + "qla_target(%d): tag %lld, op %x: received IMM SRR\n", 5098 + vha->vp_idx, cmd->se_cmd.tag, cmd->cdb ? cmd->cdb[0] : 0); 5099 + 5100 + cmd->trc_flags |= TRC_SRR_IMM; 5101 + 5102 + if (cmd->srr != NULL) { 5103 + if (cmd->srr->imm_ntfy_recvd) { 5104 + /* 5105 + * Received another immediate notify SRR message for 5106 + * this command before the previous one could be processed 5107 + * (not expected to happen). 5108 + */ 5109 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11006, 5110 + "qla_target(%d): tag %lld: received multiple IMM SRR; reject SRR\n", 5111 + vha->vp_idx, cmd->se_cmd.tag); 5112 + spin_unlock_irq(qpair->qp_lock_ptr); 5113 + ha->tgt.tgt_ops->put_cmd_ref(cmd); 5114 + goto out_reject; 5115 + } 5116 + 5117 + /* qlt_prepare_srr_ctio() was called first. */ 5118 + WARN_ON(!cmd->srr->ctio_recvd); 5119 + 5120 + /* 5121 + * The immediate notify and CTIO handlers both allocated 5122 + * separate srr structs; combine them. 5123 + */ 5124 + memcpy(&cmd->srr->imm_ntfy, &srr->imm_ntfy, 5125 + sizeof(srr->imm_ntfy)); 5126 + kfree(srr); 5127 + srr = cmd->srr; 5128 + srr->imm_ntfy_recvd = true; 5129 + 5130 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11002, 5131 + "qla_target(%d): tag %lld: schedule SRR work\n", 5132 + vha->vp_idx, cmd->se_cmd.tag); 5133 + 5134 + /* Schedule the srr for processing in qlt_handle_srr(). */ 5135 + spin_lock(&tgt->srr_lock); 5136 + list_add_tail(&srr->srr_list_entry, &tgt->srr_list); 5137 + /* 5138 + * Already running the work function; no need to schedule 5139 + * tgt->srr_work. 5140 + */ 5141 + spin_unlock(&tgt->srr_lock); 5142 + spin_unlock_irq(qpair->qp_lock_ptr); 5143 + /* return with cmd refcount incremented */ 5144 + return; 5145 + } 5146 + 5147 + /* The CTIO SRR for this command has not yet been received. */ 5148 + 5149 + if (cmd->sent_term_exchg) { 5150 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11007, 5151 + "qla_target(%d): tag %lld: IMM SRR: cmd already aborted\n", 5152 + vha->vp_idx, cmd->se_cmd.tag); 5153 + spin_unlock_irq(qpair->qp_lock_ptr); 5154 + spin_lock_irq(&ha->hardware_lock); 5155 + if (!qlt_srr_is_chip_reset(vha, ha->base_qpair, srr)) 5156 + qlt_send_term_imm_notif(vha, &srr->imm_ntfy, 1); 5157 + spin_unlock_irq(&ha->hardware_lock); 5158 + kfree(srr); 5159 + ha->tgt.tgt_ops->put_cmd_ref(cmd); 5160 + return; 5161 + } 5162 + 5163 + /* If not expecting a CTIO, then reject IMM SRR. */ 5164 + if (!cmd->cmd_sent_to_fw) { 5165 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11008, 5166 + "qla_target(%d): tag %lld: IMM SRR but !cmd_sent_to_fw (state %d); reject SRR\n", 5167 + vha->vp_idx, cmd->se_cmd.tag, cmd->state); 5168 + spin_unlock_irq(qpair->qp_lock_ptr); 5169 + ha->tgt.tgt_ops->put_cmd_ref(cmd); 5170 + goto out_reject; 5171 + } 5172 + 5173 + /* Expect qlt_prepare_srr_ctio() to be called. */ 5174 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11003, 5175 + "qla_target(%d): tag %lld: wait for CTIO SRR (state %d)\n", 5176 + vha->vp_idx, cmd->se_cmd.tag, cmd->state); 5177 + srr->cmd = cmd; 5178 + cmd->srr = srr; 5179 + 5180 + spin_unlock_irq(qpair->qp_lock_ptr); 5181 + 5182 + ha->tgt.tgt_ops->put_cmd_ref(cmd); 5183 + return; 5184 + 5185 + out_reject: 5186 + qpair = vha->hw->base_qpair; 5187 + spin_lock_irq(qpair->qp_lock_ptr); 5188 + if (!qlt_srr_is_chip_reset(vha, qpair, srr)) 5189 + qlt_send_notify_ack(qpair, &srr->imm_ntfy, 0, 0, 0, 5190 + NOTIFY_ACK_SRR_FLAGS_REJECT, 5191 + NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM, 5192 + srr_explain); 5193 + spin_unlock_irq(qpair->qp_lock_ptr); 5194 + kfree(srr); 5195 + } 5196 + 5197 + /* 5198 + * Handle an immediate notify SRR (Sequence Retransmission Request) message from 5199 + * the hardware. The hardware will also send a CTIO with CTIO_SRR_RECEIVED status 5200 + * for the affected command. 5201 + * 5202 + * ha->hardware_lock supposed to be held on entry 5203 + */ 5204 + static void qlt_prepare_srr_imm(struct scsi_qla_host *vha, 5205 + struct imm_ntfy_from_isp *iocb) 5206 + { 5207 + struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; 5208 + struct qla_tgt_srr *srr; 5209 + 5210 + ql_log(ql_log_warn, vha, 0x11000, "qla_target(%d): received IMM SRR\n", 5211 + vha->vp_idx); 5212 + 5213 + /* 5214 + * Need cmd->qpair->qp_lock_ptr, but have ha->hardware_lock. Defer 5215 + * processing to a workqueue so that the right lock can be acquired 5216 + * safely. 5217 + */ 5218 + 5219 + srr = kzalloc(sizeof(*srr), GFP_ATOMIC); 5220 + if (!srr) 5221 + goto out_reject; 5222 + 5223 + memcpy(&srr->imm_ntfy, iocb, sizeof(srr->imm_ntfy)); 5224 + srr->imm_ntfy_recvd = true; 5225 + srr->reset_count = vha->hw->base_qpair->chip_reset; 5226 + spin_lock(&tgt->srr_lock); 5227 + list_add_tail(&srr->srr_list_entry, &tgt->srr_list); 5228 + queue_work(qla_tgt_wq, &tgt->srr_work); 5229 + spin_unlock(&tgt->srr_lock); 5230 + /* resume processing in qlt_handle_srr_imm() */ 5231 + return; 5232 + 5233 + out_reject: 5234 + qlt_send_notify_ack(vha->hw->base_qpair, iocb, 0, 0, 0, 5235 + NOTIFY_ACK_SRR_FLAGS_REJECT, 5236 + NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM, 5237 + NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL); 5238 + } 5239 + 5240 + /* 5241 + * If possible, undo the effect of qlt_set_data_offset() and restore the cmd 5242 + * data buffer back to its full size. 5243 + */ 5244 + static int qlt_restore_orig_sg(struct qla_tgt_cmd *cmd) 5245 + { 5246 + struct scsi_qla_host *vha = cmd->vha; 5247 + struct se_cmd *se_cmd = &cmd->se_cmd; 5248 + 5249 + WARN_ON(cmd->sg_mapped); 5250 + 5251 + if (cmd->offset == 0) { 5252 + /* qlt_set_data_offset() has not been called. */ 5253 + return 0; 5254 + } 5255 + 5256 + if (se_cmd->t_data_sg == NULL || 5257 + se_cmd->t_data_nents == 0 || 5258 + se_cmd->data_length == 0) { 5259 + /* The original scatterlist is not available. */ 5260 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x1102c, 5261 + "qla_target(%d): tag %lld: cannot restore original cmd buffer; keep modified buffer at offset %d\n", 5262 + vha->vp_idx, cmd->se_cmd.tag, cmd->offset); 5263 + return -ENOENT; 5264 + } 5265 + 5266 + /* Restore the original scatterlist. */ 5267 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x1102d, 5268 + "qla_target(%d): tag %lld: restore original cmd buffer: offset %d -> 0\n", 5269 + vha->vp_idx, cmd->se_cmd.tag, cmd->offset); 5270 + if (cmd->free_sg) { 5271 + cmd->free_sg = 0; 5272 + qlt_free_sg(cmd); 5273 + } 5274 + cmd->offset = 0; 5275 + cmd->sg = se_cmd->t_data_sg; 5276 + cmd->sg_cnt = se_cmd->t_data_nents; 5277 + cmd->bufflen = se_cmd->data_length; 5278 + return 0; 5279 + } 5280 + 5281 + /* 5282 + * Adjust the data buffer of the given command to skip over offset bytes from 5283 + * the beginning while also reducing the length by offset bytes. 5284 + * 5285 + * This may be called multiple times for a single command if there are multiple 5286 + * SRRs, which each call reducing the buffer size further relative to the 5287 + * previous call. Note that the buffer may be reset back to its original size 5288 + * by calling qlt_restore_orig_sg(). 5289 + */ 5290 + static int qlt_set_data_offset(struct qla_tgt_cmd *cmd, uint32_t offset) 5291 + { 5292 + struct scsi_qla_host *vha = cmd->vha; 5293 + struct scatterlist *sg_srr_start = NULL, *sg; 5294 + uint32_t first_offset = offset; 5295 + int sg_srr_cnt, i; 5296 + int bufflen = 0; 5297 + 5298 + WARN_ON(cmd->sg_mapped); 5299 + 5300 + ql_dbg(ql_dbg_tgt, vha, 0x11020, 5301 + "qla_target(%d): tag %lld: %s: sg %p sg_cnt %d dir %d cmd->offset %d cmd->bufflen %d add offset %u\n", 5302 + vha->vp_idx, cmd->se_cmd.tag, __func__, cmd->sg, 5303 + cmd->sg_cnt, cmd->dma_data_direction, cmd->offset, cmd->bufflen, 5304 + offset); 5305 + 5306 + if (cmd->se_cmd.prot_op != TARGET_PROT_NORMAL) { 5307 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11021, 5308 + "qla_target(%d): tag %lld: %s: SRR with protection information at nonzero offset not implemented\n", 5309 + vha->vp_idx, cmd->se_cmd.tag, __func__); 5310 + return -EINVAL; 5311 + } 5312 + 5313 + if (!cmd->sg || !cmd->sg_cnt) { 5314 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11022, 5315 + "qla_target(%d): tag %lld: %s: Missing cmd->sg or zero cmd->sg_cnt\n", 5316 + vha->vp_idx, cmd->se_cmd.tag, __func__); 5317 + return -EINVAL; 5318 + } 5319 + 5320 + /* 5321 + * Walk the current cmd->sg list until we locate the new sg_srr_start 5322 + */ 5323 + for_each_sg(cmd->sg, sg, cmd->sg_cnt, i) { 5324 + ql_dbg(ql_dbg_tgt, vha, 0x11023, 5325 + "sg[%d]: %p page: %p, length: %d, offset: %d\n", 5326 + i, sg, sg_page(sg), sg->length, sg->offset); 5327 + 5328 + if (first_offset < sg->length) { 5329 + sg_srr_start = sg; 5330 + break; 5331 + } 5332 + first_offset -= sg->length; 5333 + } 5334 + 5335 + if (!sg_srr_start) { 5336 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11024, 5337 + "qla_target(%d): tag %lld: Unable to locate sg_srr_start for offset: %u\n", 5338 + vha->vp_idx, cmd->se_cmd.tag, offset); 5339 + return -EINVAL; 5340 + } 5341 + 5342 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11025, 5343 + "qla_target(%d): tag %lld: prepare SRR sgl at sg index %d of %d byte offset %u of %u\n", 5344 + vha->vp_idx, cmd->se_cmd.tag, i, cmd->sg_cnt, 5345 + first_offset, sg_srr_start->length); 5346 + 5347 + sg_srr_cnt = cmd->sg_cnt - i; 5348 + 5349 + if (first_offset == 0 && !cmd->free_sg) { 5350 + /* 5351 + * The offset points to the beginning of a scatterlist element. 5352 + * In this case there is no need to modify the first scatterlist 5353 + * element, so we can just point directly inside the original 5354 + * unmodified scatterlist. 5355 + */ 5356 + ql_dbg(ql_dbg_tgt, vha, 0x11026, "point directly to old sgl\n"); 5357 + cmd->sg = sg_srr_start; 5358 + } else { 5359 + /* 5360 + * Allocate at most 2 new scatterlist elements to reduce memory 5361 + * requirements. 5362 + */ 5363 + int n_alloc_sg = min(sg_srr_cnt, 2); 5364 + struct scatterlist *sg_srr = 5365 + kmalloc_array(n_alloc_sg, sizeof(*sg_srr), GFP_ATOMIC); 5366 + if (!sg_srr) { 5367 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11027, 5368 + "qla_target(%d): tag %lld: Unable to allocate SRR scatterlist\n", 5369 + vha->vp_idx, cmd->se_cmd.tag); 5370 + return -ENOMEM; 5371 + } 5372 + sg_init_table(sg_srr, n_alloc_sg); 5373 + 5374 + /* Init the first sg element to skip over the unneeded data. */ 5375 + sg_set_page(&sg_srr[0], sg_page(sg_srr_start), 5376 + sg_srr_start->length - first_offset, 5377 + sg_srr_start->offset + first_offset); 5378 + if (sg_srr_cnt == 1) { 5379 + ql_dbg(ql_dbg_tgt, vha, 0x11028, 5380 + "single-element array\n"); 5381 + } else if (sg_srr_cnt == 2) { 5382 + /* Only two elements; copy the last element. */ 5383 + ql_dbg(ql_dbg_tgt, vha, 0x11029, 5384 + "complete two-element array\n"); 5385 + sg = sg_next(sg_srr_start); 5386 + sg_set_page(&sg_srr[1], sg_page(sg), sg->length, 5387 + sg->offset); 5388 + } else { 5389 + /* 5390 + * Three or more elements; chain our newly-allocated 5391 + * 2-entry array to the rest of the original 5392 + * scatterlist at the splice point. 5393 + */ 5394 + ql_dbg(ql_dbg_tgt, vha, 0x1102a, 5395 + "chain to original scatterlist\n"); 5396 + sg = sg_next(sg_srr_start); 5397 + sg_chain(sg_srr, 2, sg); 5398 + } 5399 + 5400 + /* 5401 + * If the previous scatterlist was allocated here on a previous 5402 + * call, then it should be safe to free now. 5403 + */ 5404 + if (cmd->free_sg) 5405 + qlt_free_sg(cmd); 5406 + cmd->sg = sg_srr; 5407 + cmd->free_sg = 1; 5408 + } 5409 + 5410 + /* Note that sg_cnt doesn't include any extra chain elements. */ 5411 + cmd->sg_cnt = sg_srr_cnt; 5412 + cmd->offset += offset; 5413 + cmd->bufflen -= offset; 5414 + 5415 + /* Check the scatterlist length for consistency. */ 5416 + for_each_sg(cmd->sg, sg, cmd->sg_cnt, i) { 5417 + bufflen += sg->length; 5418 + } 5419 + if (bufflen != cmd->bufflen) { 5420 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x1102b, 5421 + "qla_target(%d): tag %lld: %s: bad sgl length: expected %d got %d\n", 5422 + vha->vp_idx, cmd->se_cmd.tag, __func__, cmd->bufflen, bufflen); 5423 + return -EINVAL; 5424 + } 5425 + 5426 + return 0; 5427 + } 5428 + 5429 + /* 5430 + * Given the "SRR relative offset" (offset of data to retry), determine what 5431 + * needs to be retransmitted (data and/or status) and return the mask in 5432 + * xmit_type. If retrying data, adjust the command buffer to point to only the 5433 + * data that need to be retried, skipping over the data that don't need to be 5434 + * retried. 5435 + * 5436 + * Returns 0 for success or a negative error number. 5437 + */ 5438 + static inline int qlt_srr_adjust_data(struct qla_tgt_cmd *cmd, 5439 + uint32_t srr_rel_offs, int *xmit_type) 5440 + { 5441 + struct scsi_qla_host *vha = cmd->vha; 5442 + int res = 0, rel_offs; 5443 + 5444 + if (srr_rel_offs < cmd->offset || 5445 + srr_rel_offs > cmd->offset + cmd->bufflen) { 5446 + *xmit_type = 0; 5447 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x1101e, 5448 + "qla_target(%d): tag %lld: srr_rel_offs %u outside accepted range %u - %u\n", 5449 + vha->vp_idx, cmd->se_cmd.tag, srr_rel_offs, 5450 + cmd->offset, cmd->offset + cmd->bufflen); 5451 + return -EINVAL; 5452 + } 5453 + 5454 + /* 5455 + * srr_rel_offs is the offset of the data we need from the beginning of 5456 + * the *original* buffer. 5457 + * 5458 + * cmd->offset is the offset of the current cmd scatterlist from the 5459 + * beginning of the *original* buffer, which might be nonzero if there 5460 + * was a previous SRR and the buffer could not be reset back to its 5461 + * original size. 5462 + * 5463 + * rel_offs is the offset of the data we need from the beginning of the 5464 + * current cmd scatterlist. 5465 + */ 5466 + rel_offs = srr_rel_offs - cmd->offset; 5467 + 5468 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x1101f, 5469 + "qla_target(%d): tag %lld: current buffer [%u - %u); srr_rel_offs=%d, rel_offs=%d\n", 5470 + vha->vp_idx, cmd->se_cmd.tag, cmd->offset, 5471 + cmd->offset + cmd->bufflen, srr_rel_offs, rel_offs); 5472 + 5473 + *xmit_type = QLA_TGT_XMIT_ALL; 5474 + 5475 + if (rel_offs == cmd->bufflen) 5476 + *xmit_type = QLA_TGT_XMIT_STATUS; 5477 + else if (rel_offs > 0) 5478 + res = qlt_set_data_offset(cmd, rel_offs); 5479 + 5480 + return res; 5481 + } 5482 + 5483 + /* 5484 + * Process a SRR (Sequence Retransmission Request) for a SCSI command once both 5485 + * the immediate notify SRR and CTIO SRR have been received from the hw. 5486 + * 5487 + * Process context, no locks 5488 + */ 5489 + static void qlt_handle_srr(struct scsi_qla_host *vha, struct qla_tgt_srr *srr) 5490 + { 5491 + struct qla_tgt_cmd *cmd = srr->cmd; 5492 + struct se_cmd *se_cmd = &cmd->se_cmd; 5493 + struct qla_qpair *qpair = cmd->qpair; 5494 + struct qla_hw_data *ha = vha->hw; 5495 + uint8_t op = cmd->cdb ? cmd->cdb[0] : 0; 5496 + uint32_t srr_rel_offs = le32_to_cpu(srr->imm_ntfy.u.isp24.srr_rel_offs); 5497 + uint16_t srr_ui = le16_to_cpu(srr->imm_ntfy.u.isp24.srr_ui); 5498 + int xmit_type = 0; 5499 + bool xmit_response = false; 5500 + bool rdy_to_xfer = false; 5501 + bool did_timeout; 5502 + bool send_term_exch = false; 5503 + 5504 + spin_lock_irq(qpair->qp_lock_ptr); 5505 + 5506 + WARN_ON(cmd->cmd_sent_to_fw); 5507 + 5508 + cmd->srr = NULL; 5509 + 5510 + if (qlt_srr_is_chip_reset(vha, qpair, srr)) 5511 + goto out_advance_cmd; 5512 + 5513 + if (cmd->sent_term_exchg || cmd->sess->deleted || srr->aborted) { 5514 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11010, 5515 + "qla_target(%d): tag %lld: IMM SRR: cmd already aborted\n", 5516 + vha->vp_idx, cmd->se_cmd.tag); 5517 + 5518 + spin_unlock_irq(qpair->qp_lock_ptr); 5519 + 5520 + spin_lock_irq(&ha->hardware_lock); 5521 + if (!qlt_srr_is_chip_reset(vha, ha->base_qpair, srr)) 5522 + qlt_send_term_imm_notif(vha, &srr->imm_ntfy, 1); 5523 + spin_unlock_irq(&ha->hardware_lock); 5524 + 5525 + send_term_exch = true; 5526 + 5527 + spin_lock_irq(qpair->qp_lock_ptr); 5528 + goto out_advance_cmd; 5529 + } 5530 + 5531 + if (srr->reject) 5532 + goto out_reject; 5533 + 5534 + /* 5535 + * If we receive multiple SRRs for the same command, place a time limit 5536 + * on how long we are willing to retry. This timeout should be less 5537 + * than SQA_MAX_HW_PENDING_TIME in scst_qla2xxx.c. 5538 + */ 5539 + did_timeout = time_is_before_jiffies64((cmd->jiffies_at_hw_st_entry ? : 5540 + cmd->jiffies_at_alloc) + 30 * HZ); 5541 + 5542 + qlt_restore_orig_sg(cmd); 5543 + 5544 + switch (srr_ui) { 5545 + case SRR_IU_STATUS: 5546 + if (cmd->state != QLA_TGT_STATE_PROCESSED) { 5547 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11011, 5548 + "qla_target(%d): tag %lld, op %x: reject SRR_IU_STATUS due to unexpected state %d\n", 5549 + vha->vp_idx, se_cmd->tag, op, 5550 + cmd->state); 5551 + goto out_reject; 5552 + } 5553 + 5554 + if (did_timeout) { 5555 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11033, 5556 + "qla_target(%d): tag %lld, op %x: reject SRR_IU_STATUS due to timeout\n", 5557 + vha->vp_idx, se_cmd->tag, op); 5558 + goto out_reject; 5559 + } 5560 + 5561 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11012, 5562 + "qla_target(%d): tag %lld, op %x: accept SRR_IU_STATUS and retransmit scsi_status=%x\n", 5563 + vha->vp_idx, se_cmd->tag, op, 5564 + se_cmd->scsi_status); 5565 + xmit_type = QLA_TGT_XMIT_STATUS; 5566 + xmit_response = true; 5567 + cmd->trc_flags |= TRC_SRR_RSP; 5568 + break; 5569 + 5570 + case SRR_IU_DATA_IN: 5571 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11013, 5572 + "qla_target(%d): tag %lld, op %x: process SRR_IU_DATA_IN: bufflen=%d, sg_cnt=%d, offset=%d, srr_offset=%d, scsi_status=%x\n", 5573 + vha->vp_idx, se_cmd->tag, op, cmd->bufflen, 5574 + cmd->sg_cnt, cmd->offset, srr_rel_offs, 5575 + se_cmd->scsi_status); 5576 + 5577 + if (cmd->state != QLA_TGT_STATE_PROCESSED) { 5578 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11014, 5579 + "qla_target(%d): tag %lld: reject SRR_IU_DATA_IN due to unexpected state %d\n", 5580 + vha->vp_idx, se_cmd->tag, cmd->state); 5581 + goto out_reject; 5582 + } 5583 + 5584 + /* 5585 + * QLA_TGT_STATE_PROCESSED does not necessarily imply data-in 5586 + */ 5587 + if (!qlt_has_data(cmd)) { 5588 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11015, 5589 + "qla_target(%d): tag %lld: reject SRR_IU_DATA_IN because cmd has no data to send\n", 5590 + vha->vp_idx, se_cmd->tag); 5591 + goto out_reject; 5592 + } 5593 + 5594 + if (!cmd->sg || !cmd->sg_cnt) { 5595 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11016, 5596 + "qla_target(%d): tag %lld: reject SRR_IU_DATA_IN because buffer is missing\n", 5597 + vha->vp_idx, se_cmd->tag); 5598 + goto out_reject; 5599 + } 5600 + 5601 + if (did_timeout) { 5602 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11034, 5603 + "qla_target(%d): tag %lld, op %x: reject SRR_IU_DATA_IN due to timeout\n", 5604 + vha->vp_idx, se_cmd->tag, op); 5605 + goto out_reject; 5606 + } 5607 + 5608 + if (qlt_srr_adjust_data(cmd, srr_rel_offs, &xmit_type) != 0) 5609 + goto out_reject; 5610 + 5611 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11017, 5612 + "qla_target(%d): tag %lld: accept SRR_IU_DATA_IN and retransmit data: bufflen=%d, offset=%d\n", 5613 + vha->vp_idx, se_cmd->tag, cmd->bufflen, 5614 + cmd->offset); 5615 + xmit_response = true; 5616 + cmd->trc_flags |= TRC_SRR_RSP; 5617 + break; 5618 + 5619 + case SRR_IU_DATA_OUT: 5620 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11018, 5621 + "qla_target(%d): tag %lld, op %x: process SRR_IU_DATA_OUT: bufflen=%d, sg_cnt=%d, offset=%d, srr_offset=%d\n", 5622 + vha->vp_idx, se_cmd->tag, op, cmd->bufflen, 5623 + cmd->sg_cnt, cmd->offset, srr_rel_offs); 5624 + 5625 + if (cmd->state != QLA_TGT_STATE_NEED_DATA) { 5626 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11019, 5627 + "qla_target(%d): tag %lld: reject SRR_IU_DATA_OUT due to unexpected state %d\n", 5628 + vha->vp_idx, se_cmd->tag, cmd->state); 5629 + goto out_reject; 5630 + } 5631 + 5632 + /* 5633 + * QLA_TGT_STATE_NEED_DATA implies there should be data-out 5634 + */ 5635 + if (!qlt_has_data(cmd) || !cmd->sg || !cmd->sg_cnt) { 5636 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x1101a, 5637 + "qla_target(%d): tag %lld: reject SRR_IU_DATA_OUT because buffer is missing\n", 5638 + vha->vp_idx, se_cmd->tag); 5639 + goto out_reject; 5640 + } 5641 + 5642 + if (did_timeout) { 5643 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11035, 5644 + "qla_target(%d): tag %lld, op %x: reject SRR_IU_DATA_OUT due to timeout\n", 5645 + vha->vp_idx, se_cmd->tag, op); 5646 + goto out_reject; 5647 + } 5648 + 5649 + if (qlt_srr_adjust_data(cmd, srr_rel_offs, &xmit_type) != 0) 5650 + goto out_reject; 5651 + 5652 + if (!(xmit_type & QLA_TGT_XMIT_DATA)) { 5653 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x1101b, 5654 + "qla_target(%d): tag %lld: reject SRR_IU_DATA_OUT: bad offset\n", 5655 + vha->vp_idx, se_cmd->tag); 5656 + goto out_reject; 5657 + } 5658 + 5659 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x1101c, 5660 + "qla_target(%d): tag %lld: accept SRR_IU_DATA_OUT and receive data again: bufflen=%d, offset=%d\n", 5661 + vha->vp_idx, se_cmd->tag, cmd->bufflen, 5662 + cmd->offset); 5663 + cmd->trc_flags |= TRC_SRR_XRDY; 5664 + rdy_to_xfer = true; 5665 + break; 5666 + 5667 + default: 5668 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x1101d, 5669 + "qla_target(%d): tag %lld, op %x: reject unknown srr_ui value 0x%x: state=%d, bufflen=%d, offset=%d, srr_offset=%d\n", 5670 + vha->vp_idx, se_cmd->tag, op, srr_ui, cmd->state, 5671 + cmd->bufflen, cmd->offset, srr_rel_offs); 5672 + goto out_reject; 5673 + } 5674 + 5675 + qlt_send_notify_ack(qpair, &srr->imm_ntfy, 0, 0, 0, 5676 + NOTIFY_ACK_SRR_FLAGS_ACCEPT, 0, 0); 5677 + 5678 + spin_unlock_irq(qpair->qp_lock_ptr); 5679 + 5680 + if (xmit_response) { 5681 + /* For status and data-in, retransmit the response. */ 5682 + if (qlt_xmit_response(cmd, xmit_type, se_cmd->scsi_status)) { 5683 + send_term_exch = true; 5684 + spin_lock_irq(qpair->qp_lock_ptr); 5685 + goto out_advance_cmd; 5686 + } 5687 + } else if (rdy_to_xfer) { 5688 + /* For data-out, receive data again. */ 5689 + if (qlt_rdy_to_xfer(cmd)) { 5690 + send_term_exch = true; 5691 + spin_lock_irq(qpair->qp_lock_ptr); 5692 + goto out_advance_cmd; 5693 + } 5694 + } 5695 + 5696 + return; 5697 + 5698 + out_reject: 5699 + qlt_send_notify_ack(qpair, &srr->imm_ntfy, 0, 0, 0, 5700 + NOTIFY_ACK_SRR_FLAGS_REJECT, 5701 + NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM, 5702 + NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL); 5703 + 5704 + out_advance_cmd: 5705 + if (!cmd->sent_term_exchg && 5706 + (send_term_exch || cmd->state != QLA_TGT_STATE_NEED_DATA) && 5707 + !qlt_srr_is_chip_reset(vha, qpair, srr)) { 5708 + cmd->trc_flags |= TRC_SRR_TERM; 5709 + qlt_send_term_exchange(qpair, cmd, &cmd->atio, 1); 5710 + } 5711 + if (cmd->state == QLA_TGT_STATE_NEED_DATA) { 5712 + /* 5713 + * The initiator should abort the command, but if not, try to 5714 + * return an error. 5715 + */ 5716 + cmd->srr_failed = 1; 5717 + cmd->write_data_transferred = 0; 5718 + cmd->state = QLA_TGT_STATE_DATA_IN; 5719 + cmd->jiffies_at_hw_st_entry = 0; 5720 + vha->hw->tgt.tgt_ops->handle_data(cmd); 5721 + } else { 5722 + vha->hw->tgt.tgt_ops->free_cmd(cmd); 5723 + } 5724 + spin_unlock_irq(qpair->qp_lock_ptr); 5725 + } 5726 + 5727 + /* Workqueue function for processing SRR work in process context. */ 5728 + static void qlt_handle_srr_work(struct work_struct *work) 5729 + { 5730 + struct qla_tgt *tgt = container_of(work, struct qla_tgt, srr_work); 5731 + struct scsi_qla_host *vha = tgt->vha; 5732 + 5733 + ql_dbg(ql_dbg_tgt_mgt, vha, 0x11032, 5734 + "qla_target(%d): Entering SRR work\n", vha->vp_idx); 5735 + 5736 + for (;;) { 5737 + struct qla_tgt_srr *srr; 5738 + 5739 + spin_lock_irq(&tgt->srr_lock); 5740 + srr = list_first_entry_or_null(&tgt->srr_list, typeof(*srr), 5741 + srr_list_entry); 5742 + if (!srr) { 5743 + spin_unlock_irq(&tgt->srr_lock); 5744 + break; 5745 + } 5746 + list_del(&srr->srr_list_entry); 5747 + spin_unlock_irq(&tgt->srr_lock); 5748 + 5749 + if (!srr->cmd) { 5750 + qlt_handle_srr_imm(vha, srr); 5751 + } else { 5752 + qlt_handle_srr(vha, srr); 5753 + vha->hw->tgt.tgt_ops->put_cmd_ref(srr->cmd); 5754 + kfree(srr); 5755 + } 5756 + } 5757 + } 5758 + 5759 + /* 5248 5760 * ha->hardware_lock supposed to be held on entry. Might drop it, then reaquire 5249 5761 */ 5250 5762 static int qlt_24xx_handle_els(struct scsi_qla_host *vha, ··· 6527 5325 if (qlt_24xx_handle_els(vha, iocb) == 0) 6528 5326 send_notify_ack = 0; 6529 5327 break; 5328 + 5329 + case IMM_NTFY_SRR: 5330 + qlt_prepare_srr_imm(vha, iocb); 5331 + send_notify_ack = 0; 5332 + break; 5333 + 6530 5334 default: 6531 5335 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf06d, 6532 5336 "qla_target(%d): Received unknown immediate " ··· 6567 5359 sess = qla2x00_find_fcport_by_nportid(vha, &id, 1); 6568 5360 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); 6569 5361 if (!sess) { 6570 - qlt_send_term_exchange(qpair, NULL, atio, 1, 0); 5362 + qlt_send_term_exchange(qpair, NULL, atio, 1); 6571 5363 return 0; 6572 5364 } 6573 5365 /* Sending marker isn't necessary, since we called from ISR */ ··· 6677 5469 6678 5470 qlt_incr_num_pend_cmds(vha); 6679 5471 INIT_LIST_HEAD(&cmd->cmd_list); 6680 - memcpy(&cmd->atio, atio, sizeof(*atio)); 5472 + memcpy_atio(&cmd->atio, atio); 6681 5473 6682 5474 cmd->tgt = vha->vha_tgt.qla_tgt; 6683 5475 cmd->vha = vha; 6684 5476 cmd->reset_count = ha->base_qpair->chip_reset; 6685 5477 cmd->q_full = 1; 6686 5478 cmd->qpair = ha->base_qpair; 5479 + cmd->cdb = &cmd->atio.u.isp24.fcp_cmnd.cdb[0]; 5480 + cmd->cdb_len = 16; 6687 5481 6688 5482 if (qfull) { 6689 5483 cmd->q_full = 1; ··· 6798 5588 ql_dbg(ql_dbg_tgt, vha, 0xe05f, 6799 5589 "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n"); 6800 5590 qlt_send_term_exchange(ha->base_qpair, NULL, 6801 - atio, 1, 0); 5591 + atio, 1); 6802 5592 break; 6803 5593 case -EBUSY: 6804 5594 ql_dbg(ql_dbg_tgt, vha, 0xe060, ··· 6907 5697 struct qla_tgt_mgmt_cmd *mcmd; 6908 5698 struct qla_hw_data *ha = vha->hw; 6909 5699 6910 - mcmd = qlt_ctio_to_cmd(vha, rsp, pkt->handle, pkt); 5700 + mcmd = qlt_ctio_to_cmd(vha, rsp, pkt->handle, TYPE_TGT_TMCMD, pkt); 6911 5701 if (mcmd == NULL && h != QLA_TGT_SKIP_HANDLE) { 6912 5702 ql_dbg(ql_dbg_async, vha, 0xe064, 6913 5703 "qla_target(%d): ABTS Comp without mcmd\n", ··· 6927 5717 if (le32_to_cpu(entry->error_subcode1) == 0x1E && 6928 5718 le32_to_cpu(entry->error_subcode2) == 0) { 6929 5719 if (qlt_chk_unresolv_exchg(vha, rsp->qpair, entry)) { 6930 - ha->tgt.tgt_ops->free_mcmd(mcmd); 5720 + qlt_free_ul_mcmd(ha, mcmd); 6931 5721 return; 6932 5722 } 6933 5723 qlt_24xx_retry_term_exchange(vha, rsp->qpair, ··· 6938 5728 vha->vp_idx, entry->compl_status, 6939 5729 entry->error_subcode1, 6940 5730 entry->error_subcode2); 6941 - ha->tgt.tgt_ops->free_mcmd(mcmd); 5731 + qlt_free_ul_mcmd(ha, mcmd); 6942 5732 } 6943 5733 } else if (mcmd) { 6944 - ha->tgt.tgt_ops->free_mcmd(mcmd); 5734 + qlt_free_ul_mcmd(ha, mcmd); 6945 5735 } 6946 5736 } 6947 5737 ··· 7005 5795 ql_dbg(ql_dbg_tgt, vha, 0xe05f, 7006 5796 "qla_target: Unable to send command to target, sending TERM EXCHANGE for rsp\n"); 7007 5797 qlt_send_term_exchange(rsp->qpair, NULL, 7008 - atio, 1, 0); 5798 + atio, 1); 7009 5799 break; 7010 5800 case -EBUSY: 7011 5801 ql_dbg(ql_dbg_tgt, vha, 0xe060, ··· 7025 5815 } 7026 5816 } 7027 5817 break; 7028 - 7029 - case CONTINUE_TGT_IO_TYPE: 7030 - { 7031 - struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; 7032 - 7033 - qlt_do_ctio_completion(vha, rsp, entry->handle, 7034 - le16_to_cpu(entry->status)|(pkt->entry_status << 16), 7035 - entry); 7036 - break; 7037 - } 7038 - 7039 - case CTIO_A64_TYPE: 7040 - { 7041 - struct ctio_to_2xxx *entry = (struct ctio_to_2xxx *)pkt; 7042 - 7043 - qlt_do_ctio_completion(vha, rsp, entry->handle, 7044 - le16_to_cpu(entry->status)|(pkt->entry_status << 16), 7045 - entry); 7046 - break; 7047 - } 7048 5818 7049 5819 case IMMED_NOTIFY_TYPE: 7050 5820 ql_dbg(ql_dbg_tgt, vha, 0xe035, "%s", "IMMED_NOTIFY\n"); ··· 7513 6323 spin_lock_init(&tgt->sess_work_lock); 7514 6324 INIT_WORK(&tgt->sess_work, qlt_sess_work_fn); 7515 6325 INIT_LIST_HEAD(&tgt->sess_works_list); 6326 + spin_lock_init(&tgt->srr_lock); 6327 + INIT_LIST_HEAD(&tgt->srr_list); 6328 + INIT_WORK(&tgt->srr_work, qlt_handle_srr_work); 7516 6329 atomic_set(&tgt->tgt_global_resets_count, 0); 7517 6330 7518 6331 base_vha->vha_tgt.qla_tgt = tgt; ··· 7898 6705 7899 6706 adjust_corrupted_atio(pkt); 7900 6707 qlt_send_term_exchange(ha->base_qpair, NULL, pkt, 7901 - ha_locked, 0); 6708 + ha_locked); 7902 6709 } else { 7903 6710 qlt_24xx_atio_pkt_all_vps(vha, 7904 6711 (struct atio_from_isp *)pkt, ha_locked); ··· 8161 6968 if (ha->tgt.node_name_set) { 8162 6969 memcpy(icb->node_name, ha->tgt.tgt_node_name, WWN_SIZE); 8163 6970 icb->firmware_options_1 |= cpu_to_le32(BIT_14); 6971 + } 6972 + } 6973 + 6974 + /* Update any settings that depend on ha->fw_*_version. */ 6975 + void 6976 + qlt_config_nvram_with_fw_version(struct scsi_qla_host *vha) 6977 + { 6978 + struct qla_hw_data *ha = vha->hw; 6979 + 6980 + if (!QLA_TGT_MODE_ENABLED()) 6981 + return; 6982 + 6983 + if (ql2xtgt_tape_enable && qlt_has_sler_fw_bug(ha)) { 6984 + ql_log(ql_log_warn, vha, 0x11036, 6985 + "WARNING: ignoring ql2xtgt_tape_enable due to buggy HBA firmware; please upgrade FW\n"); 6986 + 6987 + /* Disable FC Tape support */ 6988 + if (ha->isp_ops->nvram_config == qla81xx_nvram_config) { 6989 + struct init_cb_81xx *icb = 6990 + (struct init_cb_81xx *)ha->init_cb; 6991 + icb->firmware_options_2 &= cpu_to_le32(~BIT_12); 6992 + } else { 6993 + struct init_cb_24xx *icb = 6994 + (struct init_cb_24xx *)ha->init_cb; 6995 + icb->firmware_options_2 &= cpu_to_le32(~BIT_12); 6996 + } 8164 6997 } 8165 6998 } 8166 6999
+105 -11
drivers/scsi/qla2xxx/qla_target.h
··· 184 184 #define NOTIFY_ACK_SRR_REJECT_REASON_UNABLE_TO_PERFORM 0x9 185 185 186 186 #define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_NO_EXPL 0 187 + #define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_INVALID_OX_ID_RX_ID 0x17 187 188 #define NOTIFY_ACK_SRR_FLAGS_REJECT_EXPL_UNABLE_TO_SUPPLY_DATA 0x2a 188 189 189 190 #define NOTIFY_ACK_SUCCESS 0x01 ··· 687 686 int (*handle_tmr)(struct qla_tgt_mgmt_cmd *, u64, uint16_t, 688 687 uint32_t); 689 688 struct qla_tgt_cmd *(*get_cmd)(struct fc_port *); 689 + int (*get_cmd_ref)(struct qla_tgt_cmd *cmd); 690 + void (*put_cmd_ref)(struct qla_tgt_cmd *cmd); 690 691 void (*rel_cmd)(struct qla_tgt_cmd *); 691 692 void (*free_cmd)(struct qla_tgt_cmd *); 692 693 void (*free_mcmd)(struct qla_tgt_mgmt_cmd *); ··· 757 754 #define QLA_TGT_STATE_NEED_DATA 1 /* target needs data to continue */ 758 755 #define QLA_TGT_STATE_DATA_IN 2 /* Data arrived + target processing */ 759 756 #define QLA_TGT_STATE_PROCESSED 3 /* target done processing */ 757 + #define QLA_TGT_STATE_DONE 4 /* cmd being freed */ 760 758 761 759 /* ATIO task_codes field */ 762 760 #define ATIO_SIMPLE_QUEUE 0 ··· 826 822 int notify_ack_expected; 827 823 int abts_resp_expected; 828 824 int modify_lun_expected; 825 + 826 + spinlock_t srr_lock; 827 + struct list_head srr_list; 828 + struct work_struct srr_work; 829 + 829 830 atomic_t tgt_global_resets_count; 831 + 830 832 struct list_head tgt_list_entry; 831 833 }; 832 834 833 835 struct qla_tgt_sess_op { 834 836 struct scsi_qla_host *vha; 835 837 uint32_t chip_reset; 836 - struct atio_from_isp atio; 837 838 struct work_struct work; 838 839 struct list_head cmd_list; 839 840 bool aborted; 840 841 struct rsp_que *rsp; 842 + 843 + struct atio_from_isp atio; 844 + /* DO NOT ADD ANYTHING ELSE HERE - atio must be last member */ 841 845 }; 842 846 843 847 enum trace_flags { ··· 870 858 TRC_DATA_IN = BIT_18, 871 859 TRC_ABORT = BIT_19, 872 860 TRC_DIF_ERR = BIT_20, 861 + TRC_SRR_IMM = BIT_21, 873 862 }; 874 863 875 864 struct qla_tgt_cmd { ··· 889 876 /* Sense buffer that will be mapped into outgoing status */ 890 877 unsigned char sense_buffer[TRANSPORT_SENSE_BUFFER]; 891 878 892 - spinlock_t cmd_lock; 893 - /* to save extra sess dereferences */ 894 879 unsigned int conf_compl_supported:1; 895 880 unsigned int sg_mapped:1; 881 + 882 + /* Call qlt_free_sg() if set. */ 883 + unsigned int free_sg:1; 884 + 896 885 unsigned int write_data_transferred:1; 886 + 887 + /* Set if the SCSI status was sent successfully. */ 888 + unsigned int rsp_sent:1; 889 + 897 890 unsigned int q_full:1; 898 891 unsigned int term_exchg:1; 899 892 unsigned int cmd_sent_to_fw:1; 900 893 unsigned int cmd_in_wq:1; 901 894 unsigned int edif:1; 902 895 903 - /* 904 - * This variable may be set from outside the LIO and I/O completion 905 - * callback functions. Do not declare this member variable as a 906 - * bitfield to avoid a read-modify-write operation when this variable 907 - * is set. 908 - */ 909 - unsigned int aborted; 896 + /* Set if a SRR was rejected. */ 897 + unsigned int srr_failed:1; 910 898 899 + /* Set if the exchange has been terminated. */ 900 + unsigned int sent_term_exchg:1; 901 + 902 + /* 903 + * Set if sent_term_exchg is set, or if the cmd was aborted by a TMR, 904 + * or if some other error prevents normal processing of the command. 905 + */ 906 + unsigned int aborted:1; 907 + 908 + struct qla_tgt_srr *srr; 911 909 struct scatterlist *sg; /* cmd data buffer SG vector */ 912 910 int sg_cnt; /* SG segments count */ 913 911 int bufflen; /* cmd buffer length */ ··· 949 925 uint8_t scsi_status, sense_key, asc, ascq; 950 926 951 927 struct crc_context *ctx; 952 - const uint8_t *cdb; 928 + uint8_t *cdb; 953 929 uint64_t lba; 930 + int cdb_len; 954 931 uint16_t a_guard, e_guard, a_app_tag, e_app_tag; 955 932 uint32_t a_ref_tag, e_ref_tag; 956 933 #define DIF_BUNDL_DMA_VALID 1 957 934 uint16_t prot_flags; 935 + 936 + unsigned long jiffies_at_term_exchg; 937 + 938 + /* 939 + * jiffies64 when qlt_rdy_to_xfer() or qlt_xmit_response() first 940 + * called, or 0 when not in those states. Used to limit the number of 941 + * SRR retries. 942 + */ 943 + uint64_t jiffies_at_hw_st_entry; 958 944 959 945 uint64_t jiffies_at_alloc; 960 946 uint64_t jiffies_at_free; ··· 999 965 unsigned int flags; 1000 966 #define QLA24XX_MGMT_SEND_NACK BIT_0 1001 967 #define QLA24XX_MGMT_ABORT_IO_ATTR_VALID BIT_1 968 + #define QLA24XX_MGMT_LLD_OWNED BIT_2 1002 969 uint32_t reset_count; 1003 970 struct work_struct work; 1004 971 uint64_t unpacked_lun; ··· 1026 991 struct scatterlist *prot_sg; 1027 992 uint16_t prot_seg_cnt; 1028 993 uint16_t tot_dsds; 994 + }; 995 + 996 + /* 997 + * SRR (Sequence Retransmission Request) - resend or re-receive some or all 998 + * data or status to recover from a transient I/O error. 999 + */ 1000 + struct qla_tgt_srr { 1001 + /* 1002 + * Copy of immediate notify SRR message received from hw; valid only if 1003 + * imm_ntfy_recvd is true. 1004 + */ 1005 + struct imm_ntfy_from_isp imm_ntfy; 1006 + 1007 + struct list_head srr_list_entry; 1008 + 1009 + /* The command affected by this SRR, or NULL if not yet determined. */ 1010 + struct qla_tgt_cmd *cmd; 1011 + 1012 + /* Used to detect if the HBA has been reset since receiving the SRR. */ 1013 + uint32_t reset_count; 1014 + 1015 + /* 1016 + * The hardware sends two messages for each SRR - an immediate notify 1017 + * and a CTIO with CTIO_SRR_RECEIVED status. These keep track of which 1018 + * messages have been received. The SRR can be processed once both of 1019 + * these are true. 1020 + */ 1021 + bool imm_ntfy_recvd; 1022 + bool ctio_recvd; 1023 + 1024 + /* 1025 + * This is set to true if the affected command was aborted (cmd may be 1026 + * set to NULL), in which case the immediate notify exchange also needs 1027 + * to be aborted. 1028 + */ 1029 + bool aborted; 1030 + 1031 + /* This is set to true to force the SRR to be rejected. */ 1032 + bool reject; 1029 1033 }; 1030 1034 1031 1035 /* Check for Switch reserved address */ ··· 1122 1048 } 1123 1049 1124 1050 /* 1051 + * Free the scatterlist allocated by qlt_set_data_offset(). Call this only if 1052 + * cmd->free_sg is set. 1053 + */ 1054 + static inline void qlt_free_sg(struct qla_tgt_cmd *cmd) 1055 + { 1056 + /* 1057 + * The scatterlist may be chained to the original scatterlist, but we 1058 + * only need to free the first segment here since that is the only part 1059 + * allocated by qlt_set_data_offset(). 1060 + */ 1061 + kfree(cmd->sg); 1062 + } 1063 + 1064 + /* 1125 1065 * Exported symbols from qla_target.c LLD logic used by qla2xxx code.. 1126 1066 */ 1127 1067 extern void qlt_response_pkt_all_vps(struct scsi_qla_host *, struct rsp_que *, ··· 1143 1055 extern int qlt_rdy_to_xfer(struct qla_tgt_cmd *); 1144 1056 extern int qlt_xmit_response(struct qla_tgt_cmd *, int, uint8_t); 1145 1057 extern int qlt_abort_cmd(struct qla_tgt_cmd *); 1058 + void qlt_srr_abort(struct qla_tgt_cmd *cmd, bool reject); 1059 + void qlt_send_term_exchange(struct qla_qpair *qpair, 1060 + struct qla_tgt_cmd *cmd, struct atio_from_isp *atio, int ha_locked); 1146 1061 extern void qlt_xmit_tm_rsp(struct qla_tgt_mgmt_cmd *); 1062 + void qlt_free_ul_mcmd(struct qla_hw_data *ha, struct qla_tgt_mgmt_cmd *mcmd); 1147 1063 extern void qlt_free_mcmd(struct qla_tgt_mgmt_cmd *); 1148 1064 extern void qlt_free_cmd(struct qla_tgt_cmd *cmd); 1065 + extern void qlt_unmap_sg(struct scsi_qla_host *vha, struct qla_tgt_cmd *cmd); 1149 1066 extern void qlt_async_event(uint16_t, struct scsi_qla_host *, uint16_t *); 1150 1067 extern void qlt_enable_vha(struct scsi_qla_host *); 1151 1068 extern void qlt_vport_create(struct scsi_qla_host *, struct qla_hw_data *); ··· 1166 1073 struct init_cb_81xx *); 1167 1074 extern void qlt_81xx_config_nvram_stage1(struct scsi_qla_host *, 1168 1075 struct nvram_81xx *); 1076 + void qlt_config_nvram_with_fw_version(struct scsi_qla_host *vha); 1169 1077 extern void qlt_modify_vp_config(struct scsi_qla_host *, 1170 1078 struct vp_config_entry_24xx *); 1171 1079 extern void qlt_probe_one_stage1(struct scsi_qla_host *, struct qla_hw_data *);
+17
drivers/scsi/qla2xxx/tcm_qla2xxx.c
··· 291 291 return cmd; 292 292 } 293 293 294 + static int tcm_qla2xxx_get_cmd_ref(struct qla_tgt_cmd *cmd) 295 + { 296 + return target_get_sess_cmd(&cmd->se_cmd, true); 297 + } 298 + 299 + static void tcm_qla2xxx_put_cmd_ref(struct qla_tgt_cmd *cmd) 300 + { 301 + target_put_sess_cmd(&cmd->se_cmd); 302 + } 303 + 294 304 static void tcm_qla2xxx_rel_cmd(struct qla_tgt_cmd *cmd) 295 305 { 296 306 target_free_tag(cmd->sess->se_sess, &cmd->se_cmd); ··· 313 303 */ 314 304 static void tcm_qla2xxx_free_cmd(struct qla_tgt_cmd *cmd) 315 305 { 306 + cmd->state = QLA_TGT_STATE_DONE; 307 + 316 308 cmd->qpair->tgt_counters.core_qla_free_cmd++; 317 309 cmd->cmd_in_wq = 1; 318 310 ··· 541 529 if (cmd->se_cmd.pi_err) 542 530 transport_generic_request_failure(&cmd->se_cmd, 543 531 cmd->se_cmd.pi_err); 532 + else if (cmd->srr_failed) 533 + transport_generic_request_failure(&cmd->se_cmd, 534 + TCM_SNACK_REJECTED); 544 535 else 545 536 transport_generic_request_failure(&cmd->se_cmd, 546 537 TCM_CHECK_CONDITION_ABORT_CMD); ··· 1539 1524 .handle_data = tcm_qla2xxx_handle_data, 1540 1525 .handle_tmr = tcm_qla2xxx_handle_tmr, 1541 1526 .get_cmd = tcm_qla2xxx_get_cmd, 1527 + .get_cmd_ref = tcm_qla2xxx_get_cmd_ref, 1528 + .put_cmd_ref = tcm_qla2xxx_put_cmd_ref, 1542 1529 .rel_cmd = tcm_qla2xxx_rel_cmd, 1543 1530 .free_cmd = tcm_qla2xxx_free_cmd, 1544 1531 .free_mcmd = tcm_qla2xxx_free_mcmd,
+2 -2
drivers/scsi/qla4xxx/ql4_mbx.c
··· 1016 1016 uint32_t crash_record_size = 0; 1017 1017 1018 1018 memset(&mbox_cmd, 0, sizeof(mbox_cmd)); 1019 - memset(&mbox_sts, 0, sizeof(mbox_cmd)); 1019 + memset(&mbox_sts, 0, sizeof(mbox_sts)); 1020 1020 1021 1021 /* Get size of crash record. */ 1022 1022 mbox_cmd[0] = MBOX_CMD_GET_CRASH_RECORD; ··· 1099 1099 1100 1100 /* Get Crash Record. */ 1101 1101 memset(&mbox_cmd, 0, sizeof(mbox_cmd)); 1102 - memset(&mbox_sts, 0, sizeof(mbox_cmd)); 1102 + memset(&mbox_sts, 0, sizeof(mbox_sts)); 1103 1103 1104 1104 mbox_cmd[0] = MBOX_CMD_GET_CONN_EVENT_LOG; 1105 1105 mbox_cmd[2] = LSDW(event_log_dma);
+10 -2
drivers/scsi/scsi.c
··· 216 216 */ 217 217 int scsi_change_queue_depth(struct scsi_device *sdev, int depth) 218 218 { 219 + if (!sdev->budget_map.map) 220 + return -EINVAL; 221 + 219 222 depth = min_t(int, depth, scsi_device_max_queue_depth(sdev)); 220 223 221 224 if (depth > 0) { ··· 258 255 */ 259 256 int scsi_track_queue_full(struct scsi_device *sdev, int depth) 260 257 { 258 + if (!sdev->budget_map.map) 259 + return 0; 261 260 262 261 /* 263 262 * Don't let QUEUE_FULLs on the same ··· 831 826 spin_lock_irqsave(shost->host_lock, flags); 832 827 while (list->next != &shost->__devices) { 833 828 next = list_entry(list->next, struct scsi_device, siblings); 834 - /* skip devices that we can't get a reference to */ 835 - if (!scsi_device_get(next)) 829 + /* 830 + * Skip pseudo devices and also devices we can't get a 831 + * reference to. 832 + */ 833 + if (!scsi_device_is_pseudo_dev(next) && !scsi_device_get(next)) 836 834 break; 837 835 next = NULL; 838 836 list = list->next;
+117 -13
drivers/scsi/scsi_debug.c
··· 230 230 #define SDEBUG_OPT_NO_CDB_NOISE 0x4000 231 231 #define SDEBUG_OPT_HOST_BUSY 0x8000 232 232 #define SDEBUG_OPT_CMD_ABORT 0x10000 233 + #define SDEBUG_OPT_UNALIGNED_WRITE 0x20000 233 234 #define SDEBUG_OPT_ALL_NOISE (SDEBUG_OPT_NOISE | SDEBUG_OPT_Q_NOISE | \ 234 235 SDEBUG_OPT_RESET_NOISE) 235 236 #define SDEBUG_OPT_ALL_INJECTING (SDEBUG_OPT_RECOVERED_ERR | \ ··· 238 237 SDEBUG_OPT_DIF_ERR | SDEBUG_OPT_DIX_ERR | \ 239 238 SDEBUG_OPT_SHORT_TRANSFER | \ 240 239 SDEBUG_OPT_HOST_BUSY | \ 241 - SDEBUG_OPT_CMD_ABORT) 240 + SDEBUG_OPT_CMD_ABORT | \ 241 + SDEBUG_OPT_UNALIGNED_WRITE) 242 242 #define SDEBUG_OPT_RECOV_DIF_DIX (SDEBUG_OPT_RECOVERED_ERR | \ 243 243 SDEBUG_OPT_DIF_ERR | SDEBUG_OPT_DIX_ERR) 244 244 ··· 2963 2961 int target_dev_id; 2964 2962 int target = scp->device->id; 2965 2963 unsigned char *ap; 2966 - unsigned char *arr __free(kfree); 2967 2964 unsigned char *cmd = scp->cmnd; 2968 2965 bool dbd, llbaa, msense_6, is_disk, is_zbc, is_tape; 2969 2966 2970 - arr = kzalloc(SDEBUG_MAX_MSENSE_SZ, GFP_ATOMIC); 2967 + unsigned char *arr __free(kfree) = kzalloc(SDEBUG_MAX_MSENSE_SZ, GFP_ATOMIC); 2968 + 2971 2969 if (!arr) 2972 2970 return -ENOMEM; 2973 2971 dbd = !!(cmd[1] & 0x8); /* disable block descriptors */ ··· 4934 4932 u8 *cmd = scp->cmnd; 4935 4933 bool meta_data_locked = false; 4936 4934 4935 + if (unlikely(sdebug_opts & SDEBUG_OPT_UNALIGNED_WRITE && 4936 + atomic_read(&sdeb_inject_pending))) { 4937 + atomic_set(&sdeb_inject_pending, 0); 4938 + mk_sense_buffer(scp, ILLEGAL_REQUEST, LBA_OUT_OF_RANGE, 4939 + UNALIGNED_WRITE_ASCQ); 4940 + return check_condition_result; 4941 + } 4942 + 4937 4943 switch (cmd[0]) { 4938 4944 case WRITE_16: 4939 4945 ei_lba = 0; ··· 6762 6752 return false; 6763 6753 } 6764 6754 6755 + struct sdebug_abort_cmd { 6756 + u32 unique_tag; 6757 + }; 6758 + 6759 + enum sdebug_internal_cmd_type { 6760 + SCSI_DEBUG_ABORT_CMD, 6761 + }; 6762 + 6763 + struct sdebug_internal_cmd { 6764 + enum sdebug_internal_cmd_type type; 6765 + 6766 + union { 6767 + struct sdebug_abort_cmd abort_cmd; 6768 + }; 6769 + }; 6770 + 6771 + union sdebug_priv { 6772 + struct sdebug_scsi_cmd cmd; 6773 + struct sdebug_internal_cmd internal_cmd; 6774 + }; 6775 + 6765 6776 /* 6766 - * Called from scsi_debug_abort() only, which is for timed-out cmd. 6777 + * Abort SCSI command @cmnd. Only called from scsi_debug_abort(). Although 6778 + * it would be possible to call scsi_debug_stop_cmnd() directly, an internal 6779 + * command is allocated and submitted to trigger the reserved command 6780 + * infrastructure. 6767 6781 */ 6768 6782 static bool scsi_debug_abort_cmnd(struct scsi_cmnd *cmnd) 6769 6783 { 6770 - struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmnd); 6771 - unsigned long flags; 6772 - bool res; 6784 + struct Scsi_Host *shost = cmnd->device->host; 6785 + struct request *rq = scsi_cmd_to_rq(cmnd); 6786 + u32 unique_tag = blk_mq_unique_tag(rq); 6787 + struct sdebug_internal_cmd *internal_cmd; 6788 + struct scsi_cmnd *abort_cmd; 6789 + struct request *abort_rq; 6790 + blk_status_t res; 6773 6791 6774 - spin_lock_irqsave(&sdsc->lock, flags); 6775 - res = scsi_debug_stop_cmnd(cmnd); 6776 - spin_unlock_irqrestore(&sdsc->lock, flags); 6777 - 6778 - return res; 6792 + abort_cmd = scsi_get_internal_cmd(shost->pseudo_sdev, DMA_NONE, 6793 + BLK_MQ_REQ_RESERVED); 6794 + if (!abort_cmd) 6795 + return false; 6796 + internal_cmd = scsi_cmd_priv(abort_cmd); 6797 + *internal_cmd = (struct sdebug_internal_cmd) { 6798 + .type = SCSI_DEBUG_ABORT_CMD, 6799 + .abort_cmd = { 6800 + .unique_tag = unique_tag, 6801 + }, 6802 + }; 6803 + abort_rq = scsi_cmd_to_rq(abort_cmd); 6804 + abort_rq->timeout = secs_to_jiffies(3); 6805 + res = blk_execute_rq(abort_rq, true); 6806 + scsi_put_internal_cmd(abort_cmd); 6807 + return res == BLK_STS_OK; 6779 6808 } 6780 6809 6781 6810 /* ··· 9269 9220 return ret; 9270 9221 } 9271 9222 9223 + /* Process @scp, a request to abort a SCSI command by tag. */ 9224 + static void scsi_debug_abort_cmd(struct Scsi_Host *shost, struct scsi_cmnd *scp) 9225 + { 9226 + struct sdebug_internal_cmd *internal_cmd = scsi_cmd_priv(scp); 9227 + struct sdebug_abort_cmd *abort_cmd = &internal_cmd->abort_cmd; 9228 + const u32 unique_tag = abort_cmd->unique_tag; 9229 + struct scsi_cmnd *to_be_aborted_scmd = 9230 + scsi_host_find_tag(shost, unique_tag); 9231 + struct sdebug_scsi_cmd *to_be_aborted_sdsc = 9232 + scsi_cmd_priv(to_be_aborted_scmd); 9233 + bool res = false; 9234 + 9235 + if (!to_be_aborted_scmd) { 9236 + pr_err("%s: command with tag %#x not found\n", __func__, 9237 + unique_tag); 9238 + return; 9239 + } 9240 + 9241 + scoped_guard(spinlock_irqsave, &to_be_aborted_sdsc->lock) 9242 + res = scsi_debug_stop_cmnd(to_be_aborted_scmd); 9243 + 9244 + if (res) 9245 + pr_info("%s: aborted command with tag %#x\n", 9246 + __func__, unique_tag); 9247 + else 9248 + pr_err("%s: failed to abort command with tag %#x\n", 9249 + __func__, unique_tag); 9250 + 9251 + set_host_byte(scp, res ? DID_OK : DID_ERROR); 9252 + } 9253 + 9254 + static int scsi_debug_process_reserved_command(struct Scsi_Host *shost, 9255 + struct scsi_cmnd *scp) 9256 + { 9257 + struct sdebug_internal_cmd *internal_cmd = scsi_cmd_priv(scp); 9258 + 9259 + switch (internal_cmd->type) { 9260 + case SCSI_DEBUG_ABORT_CMD: 9261 + scsi_debug_abort_cmd(shost, scp); 9262 + break; 9263 + default: 9264 + WARN_ON_ONCE(true); 9265 + set_host_byte(scp, DID_ERROR); 9266 + break; 9267 + } 9268 + 9269 + scsi_done(scp); 9270 + return 0; 9271 + } 9272 + 9272 9273 static int scsi_debug_queuecommand(struct Scsi_Host *shost, 9273 9274 struct scsi_cmnd *scp) 9274 9275 { ··· 9519 9420 struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmd); 9520 9421 struct sdebug_defer *sd_dp = &sdsc->sd_dp; 9521 9422 9423 + if (blk_mq_is_reserved_rq(scsi_cmd_to_rq(cmd))) 9424 + return 0; 9425 + 9522 9426 spin_lock_init(&sdsc->lock); 9523 9427 hrtimer_setup(&sd_dp->hrt, sdebug_q_cmd_hrt_complete, CLOCK_MONOTONIC, 9524 9428 HRTIMER_MODE_REL_PINNED); ··· 9541 9439 .sdev_destroy = scsi_debug_sdev_destroy, 9542 9440 .ioctl = scsi_debug_ioctl, 9543 9441 .queuecommand = scsi_debug_queuecommand, 9442 + .queue_reserved_command = scsi_debug_process_reserved_command, 9544 9443 .change_queue_depth = sdebug_change_qdepth, 9545 9444 .map_queues = sdebug_map_queues, 9546 9445 .mq_poll = sdebug_blk_mq_poll, ··· 9551 9448 .eh_bus_reset_handler = scsi_debug_bus_reset, 9552 9449 .eh_host_reset_handler = scsi_debug_host_reset, 9553 9450 .can_queue = SDEBUG_CANQUEUE, 9451 + .nr_reserved_cmds = 1, 9554 9452 .this_id = 7, 9555 9453 .sg_tablesize = SG_MAX_SEGMENTS, 9556 9454 .cmd_per_lun = DEF_CMD_PER_LUN, ··· 9560 9456 .module = THIS_MODULE, 9561 9457 .skip_settle_delay = 1, 9562 9458 .track_queue_depth = 1, 9563 - .cmd_size = sizeof(struct sdebug_scsi_cmd), 9459 + .cmd_size = sizeof(union sdebug_priv), 9564 9460 .init_cmd_priv = sdebug_init_cmd_priv, 9565 9461 .target_alloc = sdebug_target_alloc, 9566 9462 .target_destroy = sdebug_target_destroy,
+3
drivers/scsi/scsi_error.c
··· 749 749 const struct scsi_host_template *sht = sdev->host->hostt; 750 750 struct scsi_device *tmp_sdev; 751 751 752 + if (!sdev->budget_map.map) 753 + return; 754 + 752 755 if (!sht->track_queue_depth || 753 756 sdev->queue_depth >= sdev->max_queue_depth) 754 757 return;
+85 -19
drivers/scsi/scsi_lib.c
··· 396 396 if (starget->can_queue > 0) 397 397 atomic_dec(&starget->target_busy); 398 398 399 - sbitmap_put(&sdev->budget_map, cmd->budget_token); 399 + if (sdev->budget_map.map) 400 + sbitmap_put(&sdev->budget_map, cmd->budget_token); 400 401 cmd->budget_token = -1; 401 402 } 402 403 ··· 1361 1360 { 1362 1361 int token; 1363 1362 1363 + if (!sdev->budget_map.map) 1364 + return INT_MAX; 1365 + 1364 1366 token = sbitmap_get(&sdev->budget_map); 1365 1367 if (token < 0) 1366 1368 return -1; ··· 1533 1529 { 1534 1530 struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); 1535 1531 enum scsi_disposition disposition; 1532 + 1533 + if (blk_mq_is_reserved_rq(rq)) { 1534 + /* Only pass-through requests are supported in this code path. */ 1535 + WARN_ON_ONCE(!blk_rq_is_passthrough(scsi_cmd_to_rq(cmd))); 1536 + scsi_mq_uninit_cmd(cmd); 1537 + __blk_mq_end_request(rq, scsi_result_to_blk_status(cmd->result)); 1538 + return; 1539 + } 1536 1540 1537 1541 INIT_LIST_HEAD(&cmd->eh_entry); 1538 1542 ··· 1761 1749 { 1762 1750 struct scsi_device *sdev = q->queuedata; 1763 1751 1764 - sbitmap_put(&sdev->budget_map, budget_token); 1752 + if (sdev->budget_map.map) 1753 + sbitmap_put(&sdev->budget_map, budget_token); 1765 1754 } 1766 1755 1767 1756 /* ··· 1831 1818 WARN_ON_ONCE(cmd->budget_token < 0); 1832 1819 1833 1820 /* 1834 - * If the device is not in running state we will reject some or all 1835 - * commands. 1821 + * Bypass the SCSI device, SCSI target and SCSI host checks for 1822 + * reserved commands. 1836 1823 */ 1837 - if (unlikely(sdev->sdev_state != SDEV_RUNNING)) { 1838 - ret = scsi_device_state_check(sdev, req); 1839 - if (ret != BLK_STS_OK) 1840 - goto out_put_budget; 1841 - } 1824 + if (!blk_mq_is_reserved_rq(req)) { 1825 + /* 1826 + * If the device is not in running state we will reject some or 1827 + * all commands. 1828 + */ 1829 + if (unlikely(sdev->sdev_state != SDEV_RUNNING)) { 1830 + ret = scsi_device_state_check(sdev, req); 1831 + if (ret != BLK_STS_OK) 1832 + goto out_put_budget; 1833 + } 1842 1834 1843 - ret = BLK_STS_RESOURCE; 1844 - if (!scsi_target_queue_ready(shost, sdev)) 1845 - goto out_put_budget; 1846 - if (unlikely(scsi_host_in_recovery(shost))) { 1847 - if (cmd->flags & SCMD_FAIL_IF_RECOVERING) 1848 - ret = BLK_STS_OFFLINE; 1849 - goto out_dec_target_busy; 1835 + ret = BLK_STS_RESOURCE; 1836 + if (!scsi_target_queue_ready(shost, sdev)) 1837 + goto out_put_budget; 1838 + if (unlikely(scsi_host_in_recovery(shost))) { 1839 + if (cmd->flags & SCMD_FAIL_IF_RECOVERING) 1840 + ret = BLK_STS_OFFLINE; 1841 + goto out_dec_target_busy; 1842 + } 1843 + if (!scsi_host_queue_ready(q, shost, sdev, cmd)) 1844 + goto out_dec_target_busy; 1850 1845 } 1851 - if (!scsi_host_queue_ready(q, shost, sdev, cmd)) 1852 - goto out_dec_target_busy; 1853 1846 1854 1847 /* 1855 1848 * Only clear the driver-private command data if the LLD does not supply ··· 1884 1865 cmd->submitter = SUBMITTED_BY_BLOCK_LAYER; 1885 1866 1886 1867 blk_mq_start_request(req); 1868 + if (blk_mq_is_reserved_rq(req)) { 1869 + reason = shost->hostt->queue_reserved_command(shost, cmd); 1870 + if (reason) { 1871 + ret = BLK_STS_RESOURCE; 1872 + goto out_put_budget; 1873 + } 1874 + return BLK_STS_OK; 1875 + } 1887 1876 reason = scsi_dispatch_cmd(cmd); 1888 1877 if (reason) { 1889 1878 scsi_set_blocked(cmd, reason); ··· 2110 2083 tag_set->ops = &scsi_mq_ops_no_commit; 2111 2084 tag_set->nr_hw_queues = shost->nr_hw_queues ? : 1; 2112 2085 tag_set->nr_maps = shost->nr_maps ? : 1; 2113 - tag_set->queue_depth = shost->can_queue; 2086 + tag_set->queue_depth = shost->can_queue + shost->nr_reserved_cmds; 2087 + tag_set->reserved_tags = shost->nr_reserved_cmds; 2114 2088 tag_set->cmd_size = cmd_size; 2115 2089 tag_set->numa_node = dev_to_node(shost->dma_dev); 2116 2090 if (shost->hostt->tag_alloc_policy_rr) ··· 2133 2105 blk_mq_free_tag_set(&shost->tag_set); 2134 2106 complete(&shost->tagset_freed); 2135 2107 } 2108 + 2109 + /** 2110 + * scsi_get_internal_cmd() - Allocate an internal SCSI command. 2111 + * @sdev: SCSI device from which to allocate the command 2112 + * @data_direction: Data direction for the allocated command 2113 + * @flags: request allocation flags, e.g. BLK_MQ_REQ_RESERVED or 2114 + * BLK_MQ_REQ_NOWAIT. 2115 + * 2116 + * Allocates a SCSI command for internal LLDD use. 2117 + */ 2118 + struct scsi_cmnd *scsi_get_internal_cmd(struct scsi_device *sdev, 2119 + enum dma_data_direction data_direction, 2120 + blk_mq_req_flags_t flags) 2121 + { 2122 + enum req_op op = data_direction == DMA_TO_DEVICE ? REQ_OP_DRV_OUT : 2123 + REQ_OP_DRV_IN; 2124 + struct scsi_cmnd *scmd; 2125 + struct request *rq; 2126 + 2127 + rq = scsi_alloc_request(sdev->request_queue, op, flags); 2128 + if (IS_ERR(rq)) 2129 + return NULL; 2130 + scmd = blk_mq_rq_to_pdu(rq); 2131 + scmd->device = sdev; 2132 + 2133 + return scmd; 2134 + } 2135 + EXPORT_SYMBOL_GPL(scsi_get_internal_cmd); 2136 + 2137 + /** 2138 + * scsi_put_internal_cmd() - Free an internal SCSI command. 2139 + * @scmd: SCSI command to be freed 2140 + */ 2141 + void scsi_put_internal_cmd(struct scsi_cmnd *scmd) 2142 + { 2143 + blk_mq_free_request(blk_mq_rq_from_pdu(scmd)); 2144 + } 2145 + EXPORT_SYMBOL_GPL(scsi_put_internal_cmd); 2136 2146 2137 2147 /** 2138 2148 * scsi_device_from_queue - return sdev associated with a request_queue
+10 -11
drivers/scsi/scsi_logging.c
··· 26 26 kfree(bufptr); 27 27 } 28 28 29 - static inline const char *scmd_name(const struct scsi_cmnd *scmd) 29 + static inline const char *scmd_name(struct scsi_cmnd *scmd) 30 30 { 31 - struct request *rq = scsi_cmd_to_rq((struct scsi_cmnd *)scmd); 31 + const struct request *rq = scsi_cmd_to_rq(scmd); 32 32 33 33 if (!rq->q || !rq->q->disk) 34 34 return NULL; ··· 80 80 } 81 81 EXPORT_SYMBOL(sdev_prefix_printk); 82 82 83 - void scmd_printk(const char *level, const struct scsi_cmnd *scmd, 84 - const char *fmt, ...) 83 + void scmd_printk(const char *level, struct scsi_cmnd *scmd, const char *fmt, 84 + ...) 85 85 { 86 86 va_list args; 87 87 char *logbuf; ··· 94 94 if (!logbuf) 95 95 return; 96 96 off = sdev_format_header(logbuf, logbuf_len, scmd_name(scmd), 97 - scsi_cmd_to_rq((struct scsi_cmnd *)scmd)->tag); 97 + scsi_cmd_to_rq(scmd)->tag); 98 98 if (off < logbuf_len) { 99 99 va_start(args, fmt); 100 100 off += vscnprintf(logbuf + off, logbuf_len - off, fmt, args); ··· 371 371 EXPORT_SYMBOL(__scsi_print_sense); 372 372 373 373 /* Normalize and print sense buffer in SCSI command */ 374 - void scsi_print_sense(const struct scsi_cmnd *cmd) 374 + void scsi_print_sense(struct scsi_cmnd *cmd) 375 375 { 376 376 scsi_log_print_sense(cmd->device, scmd_name(cmd), 377 - scsi_cmd_to_rq((struct scsi_cmnd *)cmd)->tag, 378 - cmd->sense_buffer, SCSI_SENSE_BUFFERSIZE); 377 + scsi_cmd_to_rq(cmd)->tag, cmd->sense_buffer, 378 + SCSI_SENSE_BUFFERSIZE); 379 379 } 380 380 EXPORT_SYMBOL(scsi_print_sense); 381 381 382 - void scsi_print_result(const struct scsi_cmnd *cmd, const char *msg, 383 - int disposition) 382 + void scsi_print_result(struct scsi_cmnd *cmd, const char *msg, int disposition) 384 383 { 385 384 char *logbuf; 386 385 size_t off, logbuf_len; ··· 392 393 return; 393 394 394 395 off = sdev_format_header(logbuf, logbuf_len, scmd_name(cmd), 395 - scsi_cmd_to_rq((struct scsi_cmnd *)cmd)->tag); 396 + scsi_cmd_to_rq(cmd)->tag); 396 397 397 398 if (off >= logbuf_len) 398 399 goto out_printk;
-1
drivers/scsi/scsi_pm.c
··· 205 205 /* Insert hooks here for targets, hosts, and transport classes */ 206 206 207 207 if (scsi_is_sdev_device(dev)) { 208 - pm_runtime_mark_last_busy(dev); 209 208 pm_runtime_autosuspend(dev); 210 209 return -EBUSY; 211 210 }
+1
drivers/scsi/scsi_priv.h
··· 135 135 extern int scsi_scan_host_selected(struct Scsi_Host *, unsigned int, 136 136 unsigned int, u64, enum scsi_scan_mode); 137 137 extern void scsi_forget_host(struct Scsi_Host *); 138 + struct scsi_device *scsi_get_pseudo_sdev(struct Scsi_Host *); 138 139 139 140 /* scsi_sysctl.c */ 140 141 #ifdef CONFIG_SYSCTL
+70 -4
drivers/scsi/scsi_scan.c
··· 347 347 kref_get(&sdev->host->tagset_refcnt); 348 348 sdev->request_queue = q; 349 349 350 + scsi_sysfs_device_initialize(sdev); 351 + 352 + if (scsi_device_is_pseudo_dev(sdev)) 353 + return sdev; 354 + 350 355 depth = sdev->host->cmd_per_lun ?: 1; 351 356 352 357 /* ··· 367 362 } 368 363 369 364 scsi_change_queue_depth(sdev, depth); 370 - 371 - scsi_sysfs_device_initialize(sdev); 372 365 373 366 if (shost->hostt->sdev_init) { 374 367 ret = shost->hostt->sdev_init(sdev); ··· 1071 1068 1072 1069 transport_configure_device(&sdev->sdev_gendev); 1073 1070 1071 + sdev->sdev_bflags = *bflags; 1072 + 1073 + if (scsi_device_is_pseudo_dev(sdev)) 1074 + return SCSI_SCAN_LUN_PRESENT; 1075 + 1074 1076 /* 1075 1077 * No need to freeze the queue as it isn't reachable to anyone else yet. 1076 1078 */ ··· 1121 1113 1122 1114 sdev->max_queue_depth = sdev->queue_depth; 1123 1115 WARN_ON_ONCE(sdev->max_queue_depth > sdev->budget_map.depth); 1124 - sdev->sdev_bflags = *bflags; 1125 1116 1126 1117 /* 1127 1118 * Ok, the device is now all set up, we can ··· 1218 1211 sdev = scsi_alloc_sdev(starget, lun, hostdata); 1219 1212 if (!sdev) 1220 1213 goto out; 1214 + 1215 + if (scsi_device_is_pseudo_dev(sdev)) { 1216 + if (bflagsp) 1217 + *bflagsp = BLIST_NOLUN; 1218 + return SCSI_SCAN_LUN_PRESENT; 1219 + } 1221 1220 1222 1221 result = kmalloc(result_len, GFP_KERNEL); 1223 1222 if (!result) ··· 2096 2083 restart: 2097 2084 spin_lock_irqsave(shost->host_lock, flags); 2098 2085 list_for_each_entry(sdev, &shost->__devices, siblings) { 2099 - if (sdev->sdev_state == SDEV_DEL) 2086 + if (scsi_device_is_pseudo_dev(sdev) || 2087 + sdev->sdev_state == SDEV_DEL) 2100 2088 continue; 2101 2089 spin_unlock_irqrestore(shost->host_lock, flags); 2102 2090 __scsi_remove_device(sdev); 2103 2091 goto restart; 2104 2092 } 2105 2093 spin_unlock_irqrestore(shost->host_lock, flags); 2094 + 2095 + /* 2096 + * Remove the pseudo device last since it may be needed during removal 2097 + * of other SCSI devices. 2098 + */ 2099 + if (shost->pseudo_sdev) 2100 + __scsi_remove_device(shost->pseudo_sdev); 2106 2101 } 2107 2102 2103 + /** 2104 + * scsi_get_pseudo_sdev() - Attach a pseudo SCSI device to a SCSI host 2105 + * @shost: Host that needs a pseudo SCSI device 2106 + * 2107 + * Lock status: None assumed. 2108 + * 2109 + * Returns: The scsi_device or NULL 2110 + * 2111 + * Notes: 2112 + * Attach a single scsi_device to the Scsi_Host. The primary aim for this 2113 + * device is to serve as a container from which SCSI commands can be 2114 + * allocated. Each SCSI command will carry a command tag allocated by the 2115 + * block layer. These SCSI commands can be used by the LLDD to send 2116 + * internal or passthrough commands without having to manage tag allocation 2117 + * inside the LLDD. 2118 + */ 2119 + struct scsi_device *scsi_get_pseudo_sdev(struct Scsi_Host *shost) 2120 + { 2121 + struct scsi_device *sdev = NULL; 2122 + struct scsi_target *starget; 2123 + 2124 + guard(mutex)(&shost->scan_mutex); 2125 + 2126 + if (!scsi_host_scan_allowed(shost)) 2127 + goto out; 2128 + 2129 + starget = scsi_alloc_target(&shost->shost_gendev, 0, shost->max_id); 2130 + if (!starget) 2131 + goto out; 2132 + 2133 + sdev = scsi_alloc_sdev(starget, U64_MAX, NULL); 2134 + if (!sdev) { 2135 + scsi_target_reap(starget); 2136 + goto put_target; 2137 + } 2138 + 2139 + sdev->borken = 0; 2140 + 2141 + put_target: 2142 + /* See also the get_device(dev) call in scsi_alloc_target(). */ 2143 + put_device(&starget->dev); 2144 + 2145 + out: 2146 + return sdev; 2147 + }
+12 -67
drivers/scsi/scsi_sysfs.c
··· 605 605 sdev_show_function(field, format_string) \ 606 606 static DEVICE_ATTR(field, S_IRUGO, sdev_show_##field, NULL); 607 607 608 - 609 - /* 610 - * sdev_rw_attr: create a function and attribute variable for a 611 - * read/write field. 612 - */ 613 - #define sdev_rw_attr(field, format_string) \ 614 - sdev_show_function(field, format_string) \ 615 - \ 616 - static ssize_t \ 617 - sdev_store_##field (struct device *dev, struct device_attribute *attr, \ 618 - const char *buf, size_t count) \ 619 - { \ 620 - struct scsi_device *sdev; \ 621 - sdev = to_scsi_device(dev); \ 622 - sscanf (buf, format_string, &sdev->field); \ 623 - return count; \ 624 - } \ 625 - static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, sdev_show_##field, sdev_store_##field); 626 - 627 - /* Currently we don't export bit fields, but we might in future, 628 - * so leave this code in */ 629 - #if 0 630 - /* 631 - * sdev_rd_attr: create a function and attribute variable for a 632 - * read/write bit field. 633 - */ 634 - #define sdev_rw_attr_bit(field) \ 635 - sdev_show_function(field, "%d\n") \ 636 - \ 637 - static ssize_t \ 638 - sdev_store_##field (struct device *dev, struct device_attribute *attr, \ 639 - const char *buf, size_t count) \ 640 - { \ 641 - int ret; \ 642 - struct scsi_device *sdev; \ 643 - ret = scsi_sdev_check_buf_bit(buf); \ 644 - if (ret >= 0) { \ 645 - sdev = to_scsi_device(dev); \ 646 - sdev->field = ret; \ 647 - ret = count; \ 648 - } \ 649 - return ret; \ 650 - } \ 651 - static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, sdev_show_##field, sdev_store_##field); 652 - 653 - /* 654 - * scsi_sdev_check_buf_bit: return 0 if buf is "0", return 1 if buf is "1", 655 - * else return -EINVAL. 656 - */ 657 - static int scsi_sdev_check_buf_bit(const char *buf) 658 - { 659 - if ((buf[1] == '\0') || ((buf[1] == '\n') && (buf[2] == '\0'))) { 660 - if (buf[0] == '1') 661 - return 1; 662 - else if (buf[0] == '0') 663 - return 0; 664 - else 665 - return -EINVAL; 666 - } else 667 - return -EINVAL; 668 - } 669 - #endif 670 608 /* 671 609 * Create the actual show/store functions and data structures. 672 610 */ ··· 648 710 sdev_store_timeout (struct device *dev, struct device_attribute *attr, 649 711 const char *buf, size_t count) 650 712 { 651 - struct scsi_device *sdev; 652 - int timeout; 653 - sdev = to_scsi_device(dev); 654 - sscanf (buf, "%d\n", &timeout); 713 + struct scsi_device *sdev = to_scsi_device(dev); 714 + int ret, timeout; 715 + 716 + ret = kstrtoint(buf, 0, &timeout); 717 + if (ret) 718 + return ret; 719 + if (timeout <= 0) 720 + return -EINVAL; 655 721 blk_queue_rq_timeout(sdev->request_queue, timeout * HZ); 656 722 return count; 657 723 } ··· 1348 1406 int error; 1349 1407 struct scsi_target *starget = sdev->sdev_target; 1350 1408 1409 + if (WARN_ON_ONCE(scsi_device_is_pseudo_dev(sdev))) 1410 + return -EINVAL; 1411 + 1351 1412 error = scsi_target_add(starget); 1352 1413 if (error) 1353 1414 return error; ··· 1458 1513 kref_put(&sdev->host->tagset_refcnt, scsi_mq_free_tags); 1459 1514 cancel_work_sync(&sdev->requeue_work); 1460 1515 1461 - if (sdev->host->hostt->sdev_destroy) 1516 + if (!scsi_device_is_pseudo_dev(sdev) && sdev->host->hostt->sdev_destroy) 1462 1517 sdev->host->hostt->sdev_destroy(sdev); 1463 1518 transport_destroy_device(dev); 1464 1519
+3 -2
drivers/scsi/scsi_transport_fc.c
··· 441 441 fc_host->next_vport_number = 0; 442 442 fc_host->npiv_vports_inuse = 0; 443 443 444 - fc_host->work_q = alloc_workqueue("fc_wq_%d", 0, 0, shost->host_no); 444 + fc_host->work_q = alloc_workqueue("fc_wq_%d", WQ_PERCPU, 0, 445 + shost->host_no); 445 446 if (!fc_host->work_q) 446 447 return -ENOMEM; 447 448 ··· 3089 3088 3090 3089 spin_unlock_irqrestore(shost->host_lock, flags); 3091 3090 3092 - rport->devloss_work_q = alloc_workqueue("fc_dl_%d_%d", 0, 0, 3091 + rport->devloss_work_q = alloc_workqueue("fc_dl_%d_%d", WQ_PERCPU, 0, 3093 3092 shost->host_no, rport->number); 3094 3093 if (!rport->devloss_work_q) { 3095 3094 printk(KERN_ERR "FC Remote Port alloc_workqueue failed\n");
+1 -1
drivers/scsi/scsi_transport_iscsi.c
··· 3961 3961 list_del_init(&session->sess_list); 3962 3962 spin_unlock_irqrestore(&sesslock, flags); 3963 3963 3964 - queue_work(system_unbound_wq, &session->destroy_work); 3964 + queue_work(system_dfl_wq, &session->destroy_work); 3965 3965 } 3966 3966 break; 3967 3967 case ISCSI_UEVENT_UNBIND_SESSION:
+33 -1
drivers/scsi/sd.c
··· 318 318 } 319 319 static DEVICE_ATTR_RW(manage_shutdown); 320 320 321 + static ssize_t manage_restart_show(struct device *dev, 322 + struct device_attribute *attr, char *buf) 323 + { 324 + struct scsi_disk *sdkp = to_scsi_disk(dev); 325 + struct scsi_device *sdp = sdkp->device; 326 + 327 + return sysfs_emit(buf, "%u\n", sdp->manage_restart); 328 + } 329 + 330 + static ssize_t manage_restart_store(struct device *dev, 331 + struct device_attribute *attr, 332 + const char *buf, size_t count) 333 + { 334 + struct scsi_disk *sdkp = to_scsi_disk(dev); 335 + struct scsi_device *sdp = sdkp->device; 336 + bool v; 337 + 338 + if (!capable(CAP_SYS_ADMIN)) 339 + return -EACCES; 340 + 341 + if (kstrtobool(buf, &v)) 342 + return -EINVAL; 343 + 344 + sdp->manage_restart = v; 345 + 346 + return count; 347 + } 348 + static DEVICE_ATTR_RW(manage_restart); 349 + 321 350 static ssize_t 322 351 allow_restart_show(struct device *dev, struct device_attribute *attr, char *buf) 323 352 { ··· 683 654 &dev_attr_manage_system_start_stop.attr, 684 655 &dev_attr_manage_runtime_start_stop.attr, 685 656 &dev_attr_manage_shutdown.attr, 657 + &dev_attr_manage_restart.attr, 686 658 &dev_attr_protection_type.attr, 687 659 &dev_attr_protection_mode.attr, 688 660 &dev_attr_app_tag_own.attr, ··· 4207 4177 (system_state == SYSTEM_POWER_OFF && 4208 4178 sdkp->device->manage_shutdown) || 4209 4179 (system_state == SYSTEM_RUNNING && 4210 - sdkp->device->manage_runtime_start_stop)) { 4180 + sdkp->device->manage_runtime_start_stop) || 4181 + (system_state == SYSTEM_RESTART && 4182 + sdkp->device->manage_restart)) { 4211 4183 sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n"); 4212 4184 sd_start_stop_device(sdkp, 0); 4213 4185 }
+2
drivers/scsi/sim710.c
··· 133 133 out_put_host: 134 134 scsi_host_put(host); 135 135 out_release: 136 + ioport_unmap(hostdata->base); 136 137 release_region(base_addr, 64); 137 138 out_free: 138 139 kfree(hostdata); ··· 149 148 150 149 scsi_remove_host(host); 151 150 NCR_700_release(host); 151 + ioport_unmap(hostdata->base); 152 152 kfree(hostdata); 153 153 free_irq(host->irq, host); 154 154 release_region(host->base, 64);
+45 -4
drivers/scsi/smartpqi/smartpqi_init.c
··· 34 34 #define BUILD_TIMESTAMP 35 35 #endif 36 36 37 - #define DRIVER_VERSION "2.1.34-035" 37 + #define DRIVER_VERSION "2.1.36-026" 38 38 #define DRIVER_MAJOR 2 39 39 #define DRIVER_MINOR 1 40 - #define DRIVER_RELEASE 34 41 - #define DRIVER_REVISION 35 40 + #define DRIVER_RELEASE 36 41 + #define DRIVER_REVISION 26 42 42 43 43 #define DRIVER_NAME "Microchip SmartPQI Driver (v" \ 44 44 DRIVER_VERSION BUILD_TIMESTAMP ")" ··· 5555 5555 pqi_scsi_done(scmd); 5556 5556 } 5557 5557 5558 + /* 5559 + * Adjust the timeout value for physical devices sent to the firmware 5560 + * by subtracting 3 seconds for timeouts greater than or equal to 8 seconds. 5561 + * 5562 + * This provides the firmware with additional time to attempt early recovery 5563 + * before the OS-level timeout occurs. 5564 + */ 5565 + #define ADJUST_SECS_TIMEOUT_VALUE(tv) (((tv) >= 8) ? ((tv) - 3) : (tv)) 5566 + 5558 5567 static int pqi_raid_submit_io(struct pqi_ctrl_info *ctrl_info, 5559 5568 struct pqi_scsi_dev *device, struct scsi_cmnd *scmd, 5560 5569 struct pqi_queue_group *queue_group, bool io_high_prio) 5561 5570 { 5562 5571 int rc; 5572 + u32 timeout; 5563 5573 size_t cdb_length; 5564 5574 struct pqi_io_request *io_request; 5565 5575 struct pqi_raid_path_request *request; 5576 + struct request *rq; 5566 5577 5567 5578 io_request = pqi_alloc_io_request(ctrl_info, scmd); 5568 5579 if (!io_request) ··· 5643 5632 if (rc) { 5644 5633 pqi_free_io_request(io_request); 5645 5634 return SCSI_MLQUEUE_HOST_BUSY; 5635 + } 5636 + 5637 + if (device->is_physical_device) { 5638 + rq = scsi_cmd_to_rq(scmd); 5639 + timeout = rq->timeout / HZ; 5640 + put_unaligned_le32(ADJUST_SECS_TIMEOUT_VALUE(timeout), &request->timeout); 5646 5641 } 5647 5642 5648 5643 pqi_start_io(ctrl_info, queue_group, RAID_PATH, io_request); ··· 6427 6410 6428 6411 static int pqi_device_reset_handler(struct pqi_ctrl_info *ctrl_info, struct pqi_scsi_dev *device, u8 lun, struct scsi_cmnd *scmd, u8 scsi_opcode) 6429 6412 { 6413 + unsigned long flags; 6430 6414 int rc; 6431 6415 6432 6416 mutex_lock(&ctrl_info->lun_reset_mutex); 6417 + 6418 + spin_lock_irqsave(&ctrl_info->scsi_device_list_lock, flags); 6419 + if (pqi_find_scsi_dev(ctrl_info, device->bus, device->target, device->lun) == NULL) { 6420 + dev_warn(&ctrl_info->pci_dev->dev, 6421 + "skipping reset of scsi %d:%d:%d:%u, device has been removed\n", 6422 + ctrl_info->scsi_host->host_no, device->bus, device->target, device->lun); 6423 + spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags); 6424 + mutex_unlock(&ctrl_info->lun_reset_mutex); 6425 + return 0; 6426 + } 6427 + spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags); 6433 6428 6434 6429 dev_err(&ctrl_info->pci_dev->dev, 6435 6430 "resetting scsi %d:%d:%d:%u SCSI cmd at %p due to cmd opcode 0x%02x\n", ··· 6623 6594 { 6624 6595 struct pqi_ctrl_info *ctrl_info; 6625 6596 struct pqi_scsi_dev *device; 6597 + struct pqi_tmf_work *tmf_work; 6626 6598 int mutex_acquired; 6599 + unsigned int lun; 6627 6600 unsigned long flags; 6628 6601 6629 6602 ctrl_info = shost_to_hba(sdev->host); ··· 6652 6621 6653 6622 mutex_unlock(&ctrl_info->scan_mutex); 6654 6623 6624 + for (lun = 0, tmf_work = device->tmf_work; lun < PQI_MAX_LUNS_PER_DEVICE; lun++, tmf_work++) 6625 + cancel_work_sync(&tmf_work->work_struct); 6626 + 6627 + mutex_lock(&ctrl_info->lun_reset_mutex); 6655 6628 pqi_dev_info(ctrl_info, "removed", device); 6656 6629 pqi_free_device(device); 6630 + mutex_unlock(&ctrl_info->lun_reset_mutex); 6657 6631 } 6658 6632 6659 6633 static int pqi_getpciinfo_ioctl(struct pqi_ctrl_info *ctrl_info, void __user *arg) ··· 8972 8936 if (sg_count == 0 || sg_count > PQI_HOST_MAX_SG_DESCRIPTORS) 8973 8937 goto out; 8974 8938 8975 - host_memory_descriptor->host_chunk_virt_address = kmalloc(sg_count * sizeof(void *), GFP_KERNEL); 8939 + host_memory_descriptor->host_chunk_virt_address = 8940 + kmalloc_array(sg_count, sizeof(void *), GFP_KERNEL); 8976 8941 if (!host_memory_descriptor->host_chunk_virt_address) 8977 8942 goto out; 8978 8943 ··· 10144 10107 { 10145 10108 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, 10146 10109 0x207d, 0x4240) 10110 + }, 10111 + { 10112 + PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f, 10113 + 0x207d, 0x4840) 10147 10114 }, 10148 10115 { 10149 10116 PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
+66 -23
drivers/scsi/st.c
··· 3526 3526 out: 3527 3527 return result; 3528 3528 } 3529 - 3530 3529 3530 + /* 3531 + * Handles any extra state needed for ioctls which are not st-specific. 3532 + * Called with the scsi_tape lock held, released before return 3533 + */ 3534 + static long st_common_ioctl(struct scsi_tape *STp, struct st_modedef *STm, 3535 + struct file *file, unsigned int cmd_in, 3536 + unsigned long arg) 3537 + { 3538 + int i, retval = 0; 3539 + 3540 + if (!STm->defined) { 3541 + retval = -ENXIO; 3542 + goto out; 3543 + } 3544 + 3545 + switch (cmd_in) { 3546 + case SCSI_IOCTL_GET_IDLUN: 3547 + case SCSI_IOCTL_GET_BUS_NUMBER: 3548 + case SCSI_IOCTL_GET_PCI: 3549 + break; 3550 + case SG_IO: 3551 + case SCSI_IOCTL_SEND_COMMAND: 3552 + case CDROM_SEND_PACKET: 3553 + if (!capable(CAP_SYS_RAWIO)) { 3554 + retval = -EPERM; 3555 + goto out; 3556 + } 3557 + fallthrough; 3558 + default: 3559 + if ((i = flush_buffer(STp, 0)) < 0) { 3560 + retval = i; 3561 + goto out; 3562 + } else { /* flush_buffer succeeds */ 3563 + if (STp->can_partitions) { 3564 + i = switch_partition(STp); 3565 + if (i < 0) { 3566 + retval = i; 3567 + goto out; 3568 + } 3569 + } 3570 + } 3571 + } 3572 + mutex_unlock(&STp->lock); 3573 + 3574 + retval = scsi_ioctl(STp->device, file->f_mode & FMODE_WRITE, 3575 + cmd_in, (void __user *)arg); 3576 + if (!retval && cmd_in == SCSI_IOCTL_STOP_UNIT) { 3577 + /* unload */ 3578 + STp->rew_at_close = 0; 3579 + STp->ready = ST_NO_TAPE; 3580 + } 3581 + 3582 + return retval; 3583 + out: 3584 + mutex_unlock(&STp->lock); 3585 + return retval; 3586 + } 3531 3587 3532 3588 /* The ioctl command */ 3533 3589 static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) ··· 3620 3564 file->f_flags & O_NDELAY); 3621 3565 if (retval) 3622 3566 goto out; 3567 + 3568 + switch (cmd_in) { 3569 + case MTIOCPOS: 3570 + case MTIOCGET: 3571 + case MTIOCTOP: 3572 + break; 3573 + default: 3574 + return st_common_ioctl(STp, STm, file, cmd_in, arg); 3575 + } 3623 3576 3624 3577 cmd_type = _IOC_TYPE(cmd_in); 3625 3578 cmd_nr = _IOC_NR(cmd_in); ··· 3941 3876 } 3942 3877 mt_pos.mt_blkno = blk; 3943 3878 retval = put_user_mtpos(p, &mt_pos); 3944 - goto out; 3945 3879 } 3946 - mutex_unlock(&STp->lock); 3947 - 3948 - switch (cmd_in) { 3949 - case SG_IO: 3950 - case SCSI_IOCTL_SEND_COMMAND: 3951 - case CDROM_SEND_PACKET: 3952 - if (!capable(CAP_SYS_RAWIO)) 3953 - return -EPERM; 3954 - break; 3955 - default: 3956 - break; 3957 - } 3958 - 3959 - retval = scsi_ioctl(STp->device, file->f_mode & FMODE_WRITE, cmd_in, p); 3960 - if (!retval && cmd_in == SCSI_IOCTL_STOP_UNIT) { 3961 - /* unload */ 3962 - STp->rew_at_close = 0; 3963 - STp->ready = ST_NO_TAPE; 3964 - } 3965 - return retval; 3966 - 3967 3880 out: 3968 3881 mutex_unlock(&STp->lock); 3969 3882 return retval;
+1
drivers/scsi/stex.c
··· 1844 1844 out_scsi_host_put: 1845 1845 scsi_host_put(host); 1846 1846 out_disable: 1847 + unregister_reboot_notifier(&stex_notifier); 1847 1848 pci_disable_device(pdev); 1848 1849 1849 1850 return err;
+4 -4
drivers/target/sbp/sbp_target.c
··· 730 730 pr_debug("tgt_agent ORB_POINTER write: 0x%llx\n", 731 731 agent->orb_pointer); 732 732 733 - queue_work(system_unbound_wq, &agent->work); 733 + queue_work(system_dfl_wq, &agent->work); 734 734 735 735 return RCODE_COMPLETE; 736 736 ··· 764 764 765 765 pr_debug("tgt_agent DOORBELL\n"); 766 766 767 - queue_work(system_unbound_wq, &agent->work); 767 + queue_work(system_dfl_wq, &agent->work); 768 768 769 769 return RCODE_COMPLETE; 770 770 ··· 990 990 991 991 if (tgt_agent_check_active(agent) && !doorbell) { 992 992 INIT_WORK(&req->work, tgt_agent_process_work); 993 - queue_work(system_unbound_wq, &req->work); 993 + queue_work(system_dfl_wq, &req->work); 994 994 } else { 995 995 /* don't process this request, just check next_ORB */ 996 996 sbp_free_request(req); ··· 1618 1618 agent->orb_offset = sbp2_pointer_to_addr(ptr); 1619 1619 agent->request = req; 1620 1620 1621 - queue_work(system_unbound_wq, &agent->work); 1621 + queue_work(system_dfl_wq, &agent->work); 1622 1622 rcode = RCODE_COMPLETE; 1623 1623 } else if (tcode == TCODE_READ_BLOCK_REQUEST) { 1624 1624 addr_to_sbp2_pointer(agent->orb_offset, ptr);
+22 -16
drivers/target/target_core_configfs.c
··· 578 578 DEF_CONFIGFS_ATTRIB_SHOW(max_write_same_len); 579 579 DEF_CONFIGFS_ATTRIB_SHOW(emulate_rsoc); 580 580 DEF_CONFIGFS_ATTRIB_SHOW(submit_type); 581 + DEF_CONFIGFS_ATTRIB_SHOW(atomic_max_len); 582 + DEF_CONFIGFS_ATTRIB_SHOW(atomic_alignment); 583 + DEF_CONFIGFS_ATTRIB_SHOW(atomic_granularity); 584 + DEF_CONFIGFS_ATTRIB_SHOW(atomic_max_with_boundary); 585 + DEF_CONFIGFS_ATTRIB_SHOW(atomic_max_boundary); 581 586 582 587 #define DEF_CONFIGFS_ATTRIB_STORE_U32(_name) \ 583 588 static ssize_t _name##_store(struct config_item *item, const char *page,\ ··· 1305 1300 CONFIGFS_ATTR(, alua_support); 1306 1301 CONFIGFS_ATTR(, pgr_support); 1307 1302 CONFIGFS_ATTR(, submit_type); 1303 + CONFIGFS_ATTR_RO(, atomic_max_len); 1304 + CONFIGFS_ATTR_RO(, atomic_alignment); 1305 + CONFIGFS_ATTR_RO(, atomic_granularity); 1306 + CONFIGFS_ATTR_RO(, atomic_max_with_boundary); 1307 + CONFIGFS_ATTR_RO(, atomic_max_boundary); 1308 1308 1309 1309 /* 1310 1310 * dev_attrib attributes for devices using the target core SBC/SPC ··· 1353 1343 &attr_pgr_support, 1354 1344 &attr_emulate_rsoc, 1355 1345 &attr_submit_type, 1346 + &attr_atomic_alignment, 1347 + &attr_atomic_max_len, 1348 + &attr_atomic_granularity, 1349 + &attr_atomic_max_with_boundary, 1350 + &attr_atomic_max_boundary, 1356 1351 NULL, 1357 1352 }; 1358 1353 EXPORT_SYMBOL(sbc_attrib_attrs); ··· 2773 2758 static ssize_t target_lu_gp_members_show(struct config_item *item, char *page) 2774 2759 { 2775 2760 struct t10_alua_lu_gp *lu_gp = to_lu_gp(item); 2776 - struct se_device *dev; 2777 - struct se_hba *hba; 2778 2761 struct t10_alua_lu_gp_member *lu_gp_mem; 2779 - ssize_t len = 0, cur_len; 2780 - unsigned char buf[LU_GROUP_NAME_BUF] = { }; 2762 + const char *const end = page + PAGE_SIZE; 2763 + char *cur = page; 2781 2764 2782 2765 spin_lock(&lu_gp->lu_gp_lock); 2783 2766 list_for_each_entry(lu_gp_mem, &lu_gp->lu_gp_mem_list, lu_gp_mem_list) { 2784 - dev = lu_gp_mem->lu_gp_mem_dev; 2785 - hba = dev->se_hba; 2767 + struct se_device *dev = lu_gp_mem->lu_gp_mem_dev; 2768 + struct se_hba *hba = dev->se_hba; 2786 2769 2787 - cur_len = snprintf(buf, LU_GROUP_NAME_BUF, "%s/%s\n", 2770 + cur += scnprintf(cur, end - cur, "%s/%s\n", 2788 2771 config_item_name(&hba->hba_group.cg_item), 2789 2772 config_item_name(&dev->dev_group.cg_item)); 2790 - cur_len++; /* Extra byte for NULL terminator */ 2791 - 2792 - if ((cur_len + len) > PAGE_SIZE || cur_len > LU_GROUP_NAME_BUF) { 2793 - pr_warn("Ran out of lu_gp_show_attr" 2794 - "_members buffer\n"); 2773 + if (WARN_ON_ONCE(cur >= end)) 2795 2774 break; 2796 - } 2797 - memcpy(page+len, buf, cur_len); 2798 - len += cur_len; 2799 2775 } 2800 2776 spin_unlock(&lu_gp->lu_gp_lock); 2801 2777 2802 - return len; 2778 + return cur - page; 2803 2779 } 2804 2780 2805 2781 CONFIGFS_ATTR(target_lu_gp_, lu_gp_id);
+21 -3
drivers/target/target_core_device.c
··· 814 814 dev->dev_attrib.max_write_same_len = DA_MAX_WRITE_SAME_LEN; 815 815 dev->dev_attrib.submit_type = TARGET_FABRIC_DEFAULT_SUBMIT; 816 816 817 + /* Skip allocating lun_stats since we can't export them. */ 817 818 xcopy_lun = &dev->xcopy_lun; 818 819 rcu_assign_pointer(xcopy_lun->lun_se_dev, dev); 819 820 init_completion(&xcopy_lun->lun_shutdown_comp); ··· 841 840 return NULL; 842 841 } 843 842 843 + void target_configure_write_atomic_from_bdev(struct se_dev_attrib *attrib, 844 + struct block_device *bdev) 845 + { 846 + struct request_queue *q = bdev_get_queue(bdev); 847 + int block_size = bdev_logical_block_size(bdev); 848 + 849 + if (!bdev_can_atomic_write(bdev)) 850 + return; 851 + 852 + attrib->atomic_max_len = queue_atomic_write_max_bytes(q) / block_size; 853 + attrib->atomic_granularity = attrib->atomic_alignment = 854 + queue_atomic_write_unit_min_bytes(q) / block_size; 855 + attrib->atomic_max_with_boundary = 0; 856 + attrib->atomic_max_boundary = 0; 857 + } 858 + EXPORT_SYMBOL_GPL(target_configure_write_atomic_from_bdev); 859 + 844 860 /* 845 861 * Check if the underlying struct block_device supports discard and if yes 846 862 * configure the UNMAP parameters. 847 863 */ 848 - bool target_configure_unmap_from_queue(struct se_dev_attrib *attrib, 849 - struct block_device *bdev) 864 + bool target_configure_unmap_from_bdev(struct se_dev_attrib *attrib, 865 + struct block_device *bdev) 850 866 { 851 867 int block_size = bdev_logical_block_size(bdev); 852 868 ··· 881 863 bdev_discard_alignment(bdev) / block_size; 882 864 return true; 883 865 } 884 - EXPORT_SYMBOL(target_configure_unmap_from_queue); 866 + EXPORT_SYMBOL(target_configure_unmap_from_bdev); 885 867 886 868 /* 887 869 * Convert from blocksize advertised to the initiator to the 512 byte
+1 -1
drivers/target/target_core_fabric_configfs.c
··· 697 697 struct se_lun *lun = container_of(to_config_group(item), 698 698 struct se_lun, lun_group); 699 699 700 - kfree_rcu(lun, rcu_head); 700 + call_rcu(&lun->rcu_head, target_tpg_free_lun); 701 701 } 702 702 703 703 static struct configfs_item_operations target_fabric_port_item_ops = {
+2 -2
drivers/target/target_core_file.c
··· 92 92 struct inode *inode = file->f_mapping->host; 93 93 94 94 if (S_ISBLK(inode->i_mode)) 95 - return target_configure_unmap_from_queue(&dev->dev_attrib, 96 - I_BDEV(inode)); 95 + return target_configure_unmap_from_bdev(&dev->dev_attrib, 96 + I_BDEV(inode)); 97 97 98 98 /* Limit UNMAP emulation to 8k Number of LBAs (NoLB) */ 99 99 dev->dev_attrib.max_unmap_lba_count = 0x2000;
+7 -2
drivers/target/target_core_iblock.c
··· 84 84 { 85 85 struct iblock_dev *ib_dev = IBLOCK_DEV(dev); 86 86 87 - return target_configure_unmap_from_queue(&dev->dev_attrib, 88 - ib_dev->ibd_bd); 87 + return target_configure_unmap_from_bdev(&dev->dev_attrib, 88 + ib_dev->ibd_bd); 89 89 } 90 90 91 91 static int iblock_configure_device(struct se_device *dev) ··· 151 151 152 152 if (bdev_nonrot(bd)) 153 153 dev->dev_attrib.is_nonrot = 1; 154 + 155 + target_configure_write_atomic_from_bdev(&dev->dev_attrib, bd); 154 156 155 157 bi = bdev_get_integrity(bd); 156 158 if (!bi) ··· 775 773 else if (!bdev_write_cache(ib_dev->ibd_bd)) 776 774 opf |= REQ_FUA; 777 775 } 776 + 777 + if (cmd->se_cmd_flags & SCF_ATOMIC) 778 + opf |= REQ_ATOMIC; 778 779 } else { 779 780 opf = REQ_OP_READ; 780 781 miter_dir = SG_MITER_FROM_SG;
+1
drivers/target/target_core_internal.h
··· 125 125 struct se_lun *); 126 126 void core_tpg_wait_for_nacl_pr_ref(struct se_node_acl *); 127 127 struct se_lun *core_tpg_alloc_lun(struct se_portal_group *, u64); 128 + void target_tpg_free_lun(struct rcu_head *head); 128 129 int core_tpg_add_lun(struct se_portal_group *, struct se_lun *, 129 130 bool, struct se_device *); 130 131 void core_tpg_remove_lun(struct se_portal_group *, struct se_lun *);
+51
drivers/target/target_core_sbc.c
··· 764 764 return 0; 765 765 } 766 766 767 + static sense_reason_t 768 + sbc_check_atomic(struct se_device *dev, struct se_cmd *cmd, unsigned char *cdb) 769 + { 770 + struct se_dev_attrib *attrib = &dev->dev_attrib; 771 + u16 boundary, transfer_len; 772 + u64 lba; 773 + 774 + lba = transport_lba_64(cdb); 775 + boundary = get_unaligned_be16(&cdb[10]); 776 + transfer_len = get_unaligned_be16(&cdb[12]); 777 + 778 + if (!attrib->atomic_max_len) 779 + return TCM_UNSUPPORTED_SCSI_OPCODE; 780 + 781 + if (boundary) { 782 + if (transfer_len > attrib->atomic_max_with_boundary) 783 + return TCM_INVALID_CDB_FIELD; 784 + 785 + if (boundary > attrib->atomic_max_boundary) 786 + return TCM_INVALID_CDB_FIELD; 787 + } else { 788 + if (transfer_len > attrib->atomic_max_len) 789 + return TCM_INVALID_CDB_FIELD; 790 + } 791 + 792 + if (attrib->atomic_granularity) { 793 + if (transfer_len % attrib->atomic_granularity) 794 + return TCM_INVALID_CDB_FIELD; 795 + 796 + if (boundary && boundary % attrib->atomic_granularity) 797 + return TCM_INVALID_CDB_FIELD; 798 + } 799 + 800 + if (dev->dev_attrib.atomic_alignment) { 801 + u64 _lba = lba; 802 + 803 + if (do_div(_lba, dev->dev_attrib.atomic_alignment)) 804 + return TCM_INVALID_CDB_FIELD; 805 + } 806 + 807 + return 0; 808 + } 809 + 767 810 sense_reason_t 768 811 sbc_parse_cdb(struct se_cmd *cmd, struct exec_cmd_ops *ops) 769 812 { ··· 904 861 break; 905 862 case WRITE_16: 906 863 case WRITE_VERIFY_16: 864 + case WRITE_ATOMIC_16: 907 865 sectors = transport_get_sectors_16(cdb); 908 866 cmd->t_task_lba = transport_lba_64(cdb); 909 867 ··· 916 872 return ret; 917 873 918 874 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; 875 + if (cdb[0] == WRITE_ATOMIC_16) { 876 + cmd->se_cmd_flags |= SCF_ATOMIC; 877 + 878 + ret = sbc_check_atomic(dev, cmd, cdb); 879 + if (ret) 880 + return ret; 881 + } 919 882 cmd->execute_cmd = sbc_execute_rw; 920 883 break; 921 884 case VARIABLE_LENGTH_CMD:
+43 -6
drivers/target/target_core_spc.c
··· 521 521 have_tp = 1; 522 522 523 523 buf[0] = dev->transport->get_device_type(dev); 524 - buf[3] = have_tp ? 0x3c : 0x10; 525 524 526 525 /* Set WSNZ to 1 */ 527 526 buf[4] = 0x01; ··· 561 562 else 562 563 put_unaligned_be32(dev->dev_attrib.optimal_sectors, &buf[12]); 563 564 564 - /* 565 - * Exit now if we don't support TP. 566 - */ 565 + put_unaligned_be16(12, &buf[2]); 566 + 567 567 if (!have_tp) 568 - goto max_write_same; 568 + goto try_atomic; 569 569 570 570 /* 571 571 * Set MAXIMUM UNMAP LBA COUNT ··· 593 595 /* 594 596 * MAXIMUM WRITE SAME LENGTH 595 597 */ 596 - max_write_same: 597 598 put_unaligned_be64(dev->dev_attrib.max_write_same_len, &buf[36]); 598 599 600 + put_unaligned_be16(40, &buf[2]); 601 + 602 + try_atomic: 603 + /* 604 + * ATOMIC 605 + */ 606 + if (!dev->dev_attrib.atomic_max_len) 607 + goto done; 608 + 609 + if (dev->dev_attrib.atomic_max_len < io_max_blocks) 610 + put_unaligned_be32(dev->dev_attrib.atomic_max_len, &buf[44]); 611 + else 612 + put_unaligned_be32(io_max_blocks, &buf[44]); 613 + 614 + put_unaligned_be32(dev->dev_attrib.atomic_alignment, &buf[48]); 615 + put_unaligned_be32(dev->dev_attrib.atomic_granularity, &buf[52]); 616 + put_unaligned_be32(dev->dev_attrib.atomic_max_with_boundary, &buf[56]); 617 + put_unaligned_be32(dev->dev_attrib.atomic_max_boundary, &buf[60]); 618 + 619 + put_unaligned_be16(60, &buf[2]); 620 + done: 599 621 return 0; 600 622 } 601 623 ··· 1470 1452 .update_usage_bits = set_dpofua_usage_bits32, 1471 1453 }; 1472 1454 1455 + static bool tcm_is_atomic_enabled(const struct target_opcode_descriptor *descr, 1456 + struct se_cmd *cmd) 1457 + { 1458 + return cmd->se_dev->dev_attrib.atomic_max_len; 1459 + } 1460 + 1461 + static struct target_opcode_descriptor tcm_opcode_write_atomic16 = { 1462 + .support = SCSI_SUPPORT_FULL, 1463 + .opcode = WRITE_ATOMIC_16, 1464 + .cdb_size = 16, 1465 + .usage_bits = {WRITE_ATOMIC_16, 0xf8, 0xff, 0xff, 1466 + 0xff, 0xff, 0xff, 0xff, 1467 + 0xff, 0xff, 0xff, 0xff, 1468 + 0xff, 0xff, SCSI_GROUP_NUMBER_MASK, SCSI_CONTROL_MASK}, 1469 + .enabled = tcm_is_atomic_enabled, 1470 + .update_usage_bits = set_dpofua_usage_bits, 1471 + }; 1472 + 1473 1473 static bool tcm_is_caw_enabled(const struct target_opcode_descriptor *descr, 1474 1474 struct se_cmd *cmd) 1475 1475 { ··· 2044 2008 &tcm_opcode_write16, 2045 2009 &tcm_opcode_write_verify16, 2046 2010 &tcm_opcode_write_same32, 2011 + &tcm_opcode_write_atomic16, 2047 2012 &tcm_opcode_compare_write, 2048 2013 &tcm_opcode_read_capacity, 2049 2014 &tcm_opcode_read_capacity16,
+78 -176
drivers/target/target_core_stat.c
··· 276 276 return snprintf(page, PAGE_SIZE, "exposed\n"); 277 277 } 278 278 279 - static ssize_t target_stat_lu_num_cmds_show(struct config_item *item, 280 - char *page) 281 - { 282 - struct se_device *dev = to_stat_lu_dev(item); 283 - struct se_dev_io_stats *stats; 284 - unsigned int cpu; 285 - u32 cmds = 0; 286 - 287 - for_each_possible_cpu(cpu) { 288 - stats = per_cpu_ptr(dev->stats, cpu); 289 - cmds += stats->total_cmds; 290 - } 291 - 292 - /* scsiLuNumCommands */ 293 - return snprintf(page, PAGE_SIZE, "%u\n", cmds); 279 + #define per_cpu_stat_snprintf(stats_struct, prefix, field, shift) \ 280 + static ssize_t \ 281 + per_cpu_stat_##prefix##_snprintf(struct stats_struct __percpu *per_cpu_stats, \ 282 + char *page) \ 283 + { \ 284 + struct stats_struct *stats; \ 285 + unsigned int cpu; \ 286 + u64 sum = 0; \ 287 + \ 288 + for_each_possible_cpu(cpu) { \ 289 + stats = per_cpu_ptr(per_cpu_stats, cpu); \ 290 + sum += stats->field; \ 291 + } \ 292 + \ 293 + return snprintf(page, PAGE_SIZE, "%llu\n", sum >> shift); \ 294 294 } 295 295 296 - static ssize_t target_stat_lu_read_mbytes_show(struct config_item *item, 297 - char *page) 298 - { 299 - struct se_device *dev = to_stat_lu_dev(item); 300 - struct se_dev_io_stats *stats; 301 - unsigned int cpu; 302 - u32 bytes = 0; 296 + #define lu_show_per_cpu_stat(prefix, field, shift) \ 297 + per_cpu_stat_snprintf(se_dev_io_stats, prefix, field, shift); \ 298 + static ssize_t \ 299 + target_stat_##prefix##_show(struct config_item *item, char *page) \ 300 + { \ 301 + struct se_device *dev = to_stat_lu_dev(item); \ 302 + \ 303 + return per_cpu_stat_##prefix##_snprintf(dev->stats, page); \ 304 + } \ 303 305 304 - for_each_possible_cpu(cpu) { 305 - stats = per_cpu_ptr(dev->stats, cpu); 306 - bytes += stats->read_bytes; 307 - } 308 - 309 - /* scsiLuReadMegaBytes */ 310 - return snprintf(page, PAGE_SIZE, "%u\n", bytes >> 20); 311 - } 312 - 313 - static ssize_t target_stat_lu_write_mbytes_show(struct config_item *item, 314 - char *page) 315 - { 316 - struct se_device *dev = to_stat_lu_dev(item); 317 - struct se_dev_io_stats *stats; 318 - unsigned int cpu; 319 - u32 bytes = 0; 320 - 321 - for_each_possible_cpu(cpu) { 322 - stats = per_cpu_ptr(dev->stats, cpu); 323 - bytes += stats->write_bytes; 324 - } 325 - 326 - /* scsiLuWrittenMegaBytes */ 327 - return snprintf(page, PAGE_SIZE, "%u\n", bytes >> 20); 328 - } 306 + /* scsiLuNumCommands */ 307 + lu_show_per_cpu_stat(lu_num_cmds, total_cmds, 0); 308 + /* scsiLuReadMegaBytes */ 309 + lu_show_per_cpu_stat(lu_read_mbytes, read_bytes, 20); 310 + /* scsiLuWrittenMegaBytes */ 311 + lu_show_per_cpu_stat(lu_write_mbytes, write_bytes, 20); 329 312 330 313 static ssize_t target_stat_lu_resets_show(struct config_item *item, char *page) 331 314 { ··· 606 623 return ret; 607 624 } 608 625 609 - static ssize_t target_stat_tgt_port_in_cmds_show(struct config_item *item, 610 - char *page) 611 - { 612 - struct se_lun *lun = to_stat_tgt_port(item); 613 - struct se_device *dev; 614 - ssize_t ret = -ENODEV; 615 - 616 - rcu_read_lock(); 617 - dev = rcu_dereference(lun->lun_se_dev); 618 - if (dev) 619 - ret = snprintf(page, PAGE_SIZE, "%lu\n", 620 - atomic_long_read(&lun->lun_stats.cmd_pdus)); 621 - rcu_read_unlock(); 622 - return ret; 626 + #define tgt_port_show_per_cpu_stat(prefix, field, shift) \ 627 + per_cpu_stat_snprintf(scsi_port_stats, prefix, field, shift); \ 628 + static ssize_t \ 629 + target_stat_##prefix##_show(struct config_item *item, char *page) \ 630 + { \ 631 + struct se_lun *lun = to_stat_tgt_port(item); \ 632 + struct se_device *dev; \ 633 + int ret; \ 634 + \ 635 + rcu_read_lock(); \ 636 + dev = rcu_dereference(lun->lun_se_dev); \ 637 + if (!dev) { \ 638 + rcu_read_unlock(); \ 639 + return -ENODEV; \ 640 + } \ 641 + \ 642 + ret = per_cpu_stat_##prefix##_snprintf(lun->lun_stats, page); \ 643 + rcu_read_unlock(); \ 644 + return ret; \ 623 645 } 624 646 625 - static ssize_t target_stat_tgt_port_write_mbytes_show(struct config_item *item, 626 - char *page) 627 - { 628 - struct se_lun *lun = to_stat_tgt_port(item); 629 - struct se_device *dev; 630 - ssize_t ret = -ENODEV; 631 - 632 - rcu_read_lock(); 633 - dev = rcu_dereference(lun->lun_se_dev); 634 - if (dev) 635 - ret = snprintf(page, PAGE_SIZE, "%u\n", 636 - (u32)(atomic_long_read(&lun->lun_stats.rx_data_octets) >> 20)); 637 - rcu_read_unlock(); 638 - return ret; 639 - } 640 - 641 - static ssize_t target_stat_tgt_port_read_mbytes_show(struct config_item *item, 642 - char *page) 643 - { 644 - struct se_lun *lun = to_stat_tgt_port(item); 645 - struct se_device *dev; 646 - ssize_t ret = -ENODEV; 647 - 648 - rcu_read_lock(); 649 - dev = rcu_dereference(lun->lun_se_dev); 650 - if (dev) 651 - ret = snprintf(page, PAGE_SIZE, "%u\n", 652 - (u32)(atomic_long_read(&lun->lun_stats.tx_data_octets) >> 20)); 653 - rcu_read_unlock(); 654 - return ret; 655 - } 647 + tgt_port_show_per_cpu_stat(tgt_port_in_cmds, cmd_pdus, 0); 648 + tgt_port_show_per_cpu_stat(tgt_port_write_mbytes, rx_data_octets, 20); 649 + tgt_port_show_per_cpu_stat(tgt_port_read_mbytes, tx_data_octets, 20); 656 650 657 651 static ssize_t target_stat_tgt_port_hs_in_cmds_show(struct config_item *item, 658 652 char *page) ··· 995 1035 return ret; 996 1036 } 997 1037 998 - static ssize_t target_stat_auth_num_cmds_show(struct config_item *item, 999 - char *page) 1000 - { 1001 - struct se_lun_acl *lacl = auth_to_lacl(item); 1002 - struct se_node_acl *nacl = lacl->se_lun_nacl; 1003 - struct se_dev_entry_io_stats *stats; 1004 - struct se_dev_entry *deve; 1005 - unsigned int cpu; 1006 - ssize_t ret; 1007 - u32 cmds = 0; 1008 - 1009 - rcu_read_lock(); 1010 - deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1011 - if (!deve) { 1012 - rcu_read_unlock(); 1013 - return -ENODEV; 1014 - } 1015 - 1016 - for_each_possible_cpu(cpu) { 1017 - stats = per_cpu_ptr(deve->stats, cpu); 1018 - cmds += stats->total_cmds; 1019 - } 1020 - 1021 - /* scsiAuthIntrOutCommands */ 1022 - ret = snprintf(page, PAGE_SIZE, "%u\n", cmds); 1023 - rcu_read_unlock(); 1024 - return ret; 1038 + #define auth_show_per_cpu_stat(prefix, field, shift) \ 1039 + per_cpu_stat_snprintf(se_dev_entry_io_stats, prefix, field, shift); \ 1040 + static ssize_t \ 1041 + target_stat_##prefix##_show(struct config_item *item, char *page) \ 1042 + { \ 1043 + struct se_lun_acl *lacl = auth_to_lacl(item); \ 1044 + struct se_node_acl *nacl = lacl->se_lun_nacl; \ 1045 + struct se_dev_entry *deve; \ 1046 + int ret; \ 1047 + \ 1048 + rcu_read_lock(); \ 1049 + deve = target_nacl_find_deve(nacl, lacl->mapped_lun); \ 1050 + if (!deve) { \ 1051 + rcu_read_unlock(); \ 1052 + return -ENODEV; \ 1053 + } \ 1054 + \ 1055 + ret = per_cpu_stat_##prefix##_snprintf(deve->stats, page); \ 1056 + rcu_read_unlock(); \ 1057 + return ret; \ 1025 1058 } 1026 1059 1027 - static ssize_t target_stat_auth_read_mbytes_show(struct config_item *item, 1028 - char *page) 1029 - { 1030 - struct se_lun_acl *lacl = auth_to_lacl(item); 1031 - struct se_node_acl *nacl = lacl->se_lun_nacl; 1032 - struct se_dev_entry_io_stats *stats; 1033 - struct se_dev_entry *deve; 1034 - unsigned int cpu; 1035 - ssize_t ret; 1036 - u32 bytes = 0; 1037 - 1038 - rcu_read_lock(); 1039 - deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1040 - if (!deve) { 1041 - rcu_read_unlock(); 1042 - return -ENODEV; 1043 - } 1044 - 1045 - for_each_possible_cpu(cpu) { 1046 - stats = per_cpu_ptr(deve->stats, cpu); 1047 - bytes += stats->read_bytes; 1048 - } 1049 - 1050 - /* scsiAuthIntrReadMegaBytes */ 1051 - ret = snprintf(page, PAGE_SIZE, "%u\n", bytes >> 20); 1052 - rcu_read_unlock(); 1053 - return ret; 1054 - } 1055 - 1056 - static ssize_t target_stat_auth_write_mbytes_show(struct config_item *item, 1057 - char *page) 1058 - { 1059 - struct se_lun_acl *lacl = auth_to_lacl(item); 1060 - struct se_node_acl *nacl = lacl->se_lun_nacl; 1061 - struct se_dev_entry_io_stats *stats; 1062 - struct se_dev_entry *deve; 1063 - unsigned int cpu; 1064 - ssize_t ret; 1065 - u32 bytes = 0; 1066 - 1067 - rcu_read_lock(); 1068 - deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1069 - if (!deve) { 1070 - rcu_read_unlock(); 1071 - return -ENODEV; 1072 - } 1073 - 1074 - for_each_possible_cpu(cpu) { 1075 - stats = per_cpu_ptr(deve->stats, cpu); 1076 - bytes += stats->write_bytes; 1077 - } 1078 - 1079 - /* scsiAuthIntrWrittenMegaBytes */ 1080 - ret = snprintf(page, PAGE_SIZE, "%u\n", bytes >> 20); 1081 - rcu_read_unlock(); 1082 - return ret; 1083 - } 1060 + /* scsiAuthIntrOutCommands */ 1061 + auth_show_per_cpu_stat(auth_num_cmds, total_cmds, 0); 1062 + /* scsiAuthIntrReadMegaBytes */ 1063 + auth_show_per_cpu_stat(auth_read_mbytes, read_bytes, 20); 1064 + /* scsiAuthIntrWrittenMegaBytes */ 1065 + auth_show_per_cpu_stat(auth_write_mbytes, write_bytes, 20); 1084 1066 1085 1067 static ssize_t target_stat_auth_hs_num_cmds_show(struct config_item *item, 1086 1068 char *page)
+21 -2
drivers/target/target_core_tpg.c
··· 548 548 ret = core_tpg_add_lun(se_tpg, se_tpg->tpg_virt_lun0, 549 549 true, g_lun0_dev); 550 550 if (ret < 0) { 551 - kfree(se_tpg->tpg_virt_lun0); 551 + target_tpg_free_lun(&se_tpg->tpg_virt_lun0->rcu_head); 552 552 return ret; 553 553 } 554 554 } ··· 595 595 596 596 if (se_tpg->proto_id >= 0) { 597 597 core_tpg_remove_lun(se_tpg, se_tpg->tpg_virt_lun0); 598 - kfree_rcu(se_tpg->tpg_virt_lun0, rcu_head); 598 + call_rcu(&se_tpg->tpg_virt_lun0->rcu_head, target_tpg_free_lun); 599 599 } 600 600 601 601 target_tpg_deregister_rtpi(se_tpg); ··· 615 615 pr_err("Unable to allocate se_lun memory\n"); 616 616 return ERR_PTR(-ENOMEM); 617 617 } 618 + 619 + lun->lun_stats = alloc_percpu(struct scsi_port_stats); 620 + if (!lun->lun_stats) { 621 + pr_err("Unable to allocate se_lun stats memory\n"); 622 + goto free_lun; 623 + } 624 + 618 625 lun->unpacked_lun = unpacked_lun; 619 626 atomic_set(&lun->lun_acl_count, 0); 620 627 init_completion(&lun->lun_shutdown_comp); ··· 635 628 lun->lun_tpg = tpg; 636 629 637 630 return lun; 631 + 632 + free_lun: 633 + kfree(lun); 634 + return ERR_PTR(-ENOMEM); 635 + } 636 + 637 + void target_tpg_free_lun(struct rcu_head *head) 638 + { 639 + struct se_lun *lun = container_of(head, struct se_lun, rcu_head); 640 + 641 + free_percpu(lun->lun_stats); 642 + kfree(lun); 638 643 } 639 644 640 645 int core_tpg_add_lun(
+17 -9
drivers/target/target_core_transport.c
··· 126 126 } 127 127 128 128 target_completion_wq = alloc_workqueue("target_completion", 129 - WQ_MEM_RECLAIM, 0); 129 + WQ_MEM_RECLAIM | WQ_PERCPU, 0); 130 130 if (!target_completion_wq) 131 131 goto out_free_lba_map_mem_cache; 132 132 133 133 target_submission_wq = alloc_workqueue("target_submission", 134 - WQ_MEM_RECLAIM, 0); 134 + WQ_MEM_RECLAIM | WQ_PERCPU, 0); 135 135 if (!target_submission_wq) 136 136 goto out_free_completion_wq; 137 137 ··· 1571 1571 return ret; 1572 1572 1573 1573 cmd->se_cmd_flags |= SCF_SUPPORTED_SAM_OPCODE; 1574 - atomic_long_inc(&cmd->se_lun->lun_stats.cmd_pdus); 1574 + /* 1575 + * If this is the xcopy_lun then we won't have lun_stats since we 1576 + * can't export them. 1577 + */ 1578 + if (cmd->se_lun->lun_stats) 1579 + this_cpu_inc(cmd->se_lun->lun_stats->cmd_pdus); 1575 1580 return 0; 1576 1581 } 1577 1582 EXPORT_SYMBOL(target_cmd_parse_cdb); ··· 2602 2597 !(cmd->se_cmd_flags & SCF_TREAT_READ_AS_NORMAL)) 2603 2598 goto queue_status; 2604 2599 2605 - atomic_long_add(cmd->data_length, 2606 - &cmd->se_lun->lun_stats.tx_data_octets); 2600 + if (cmd->se_lun->lun_stats) 2601 + this_cpu_add(cmd->se_lun->lun_stats->tx_data_octets, 2602 + cmd->data_length); 2607 2603 /* 2608 2604 * Perform READ_STRIP of PI using software emulation when 2609 2605 * backend had PI enabled, if the transport will not be ··· 2627 2621 goto queue_full; 2628 2622 break; 2629 2623 case DMA_TO_DEVICE: 2630 - atomic_long_add(cmd->data_length, 2631 - &cmd->se_lun->lun_stats.rx_data_octets); 2624 + if (cmd->se_lun->lun_stats) 2625 + this_cpu_add(cmd->se_lun->lun_stats->rx_data_octets, 2626 + cmd->data_length); 2632 2627 /* 2633 2628 * Check if we need to send READ payload for BIDI-COMMAND 2634 2629 */ 2635 2630 if (cmd->se_cmd_flags & SCF_BIDI) { 2636 - atomic_long_add(cmd->data_length, 2637 - &cmd->se_lun->lun_stats.tx_data_octets); 2631 + if (cmd->se_lun->lun_stats) 2632 + this_cpu_add(cmd->se_lun->lun_stats->tx_data_octets, 2633 + cmd->data_length); 2638 2634 ret = cmd->se_tfo->queue_data_in(cmd); 2639 2635 if (ret) 2640 2636 goto queue_full;
+1 -1
drivers/target/target_core_xcopy.c
··· 462 462 463 463 int target_xcopy_setup_pt(void) 464 464 { 465 - xcopy_wq = alloc_workqueue("xcopy_wq", WQ_MEM_RECLAIM, 0); 465 + xcopy_wq = alloc_workqueue("xcopy_wq", WQ_MEM_RECLAIM | WQ_PERCPU, 0); 466 466 if (!xcopy_wq) { 467 467 pr_err("Unable to allocate xcopy_wq\n"); 468 468 return -ENOMEM;
+1 -1
drivers/target/tcm_fc/tfc_conf.c
··· 250 250 tpg->lport_wwn = ft_wwn; 251 251 INIT_LIST_HEAD(&tpg->lun_list); 252 252 253 - wq = alloc_workqueue("tcm_fc", 0, 1); 253 + wq = alloc_workqueue("tcm_fc", WQ_PERCPU, 1); 254 254 if (!wq) { 255 255 kfree(tpg); 256 256 return NULL;
+1
drivers/ufs/core/Makefile
··· 2 2 3 3 obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o 4 4 ufshcd-core-y += ufshcd.o ufs-sysfs.o ufs-mcq.o 5 + ufshcd-core-$(CONFIG_RPMB) += ufs-rpmb.o 5 6 ufshcd-core-$(CONFIG_DEBUG_FS) += ufs-debugfs.o 6 7 ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o 7 8 ufshcd-core-$(CONFIG_SCSI_UFS_CRYPTO) += ufshcd-crypto.o
+22 -40
drivers/ufs/core/ufs-mcq.c
··· 134 134 EXPORT_SYMBOL_GPL(ufshcd_mcq_queue_cfg_addr); 135 135 136 136 /** 137 - * ufshcd_mcq_decide_queue_depth - decide the queue depth 137 + * ufshcd_get_hba_mac - Maximum number of commands supported by the host 138 + * controller. 138 139 * @hba: per adapter instance 139 140 * 140 - * Return: queue-depth on success, non-zero on error 141 + * Return: queue depth on success; negative upon error. 141 142 * 142 - * MAC - Max. Active Command of the Host Controller (HC) 143 - * HC wouldn't send more than this commands to the device. 144 - * Calculates and adjusts the queue depth based on the depth 145 - * supported by the HC and ufs device. 143 + * MAC = Maximum number of Active Commands supported by the Host Controller. 146 144 */ 147 - int ufshcd_mcq_decide_queue_depth(struct ufs_hba *hba) 145 + int ufshcd_get_hba_mac(struct ufs_hba *hba) 148 146 { 149 147 int mac; 150 148 ··· 160 162 mac = hba->vops->get_hba_mac(hba); 161 163 } 162 164 if (mac < 0) 163 - goto err; 164 - 165 - WARN_ON_ONCE(!hba->dev_info.bqueuedepth); 166 - /* 167 - * max. value of bqueuedepth = 256, mac is host dependent. 168 - * It is mandatory for UFS device to define bQueueDepth if 169 - * shared queuing architecture is enabled. 170 - */ 171 - return min_t(int, mac, hba->dev_info.bqueuedepth); 172 - 173 - err: 174 - dev_err(hba->dev, "Failed to get mac, err=%d\n", mac); 165 + dev_err(hba->dev, "Failed to get mac, err=%d\n", mac); 175 166 return mac; 176 167 } 177 168 ··· 294 307 struct ufs_hw_queue *hwq) 295 308 { 296 309 struct cq_entry *cqe = ufshcd_mcq_cur_cqe(hwq); 297 - int tag = ufshcd_mcq_get_tag(hba, cqe); 298 310 299 311 if (cqe->command_desc_base_addr) { 312 + int tag = ufshcd_mcq_get_tag(hba, cqe); 313 + 300 314 ufshcd_compl_one_cqe(hba, tag, cqe); 301 315 /* After processed the cqe, mark it empty (invalid) entry */ 302 316 cqe->command_desc_base_addr = 0; ··· 479 491 mutex_init(&hwq->sq_mutex); 480 492 } 481 493 482 - /* The very first HW queue serves device commands */ 483 - hba->dev_cmd_queue = &hba->uhq[0]; 484 - 485 494 host->host_tagset = 1; 486 495 return 0; 487 496 } ··· 531 546 */ 532 547 int ufshcd_mcq_sq_cleanup(struct ufs_hba *hba, int task_tag) 533 548 { 534 - struct ufshcd_lrb *lrbp = &hba->lrb[task_tag]; 535 - struct scsi_cmnd *cmd = lrbp->cmd; 549 + struct scsi_cmnd *cmd = ufshcd_tag_to_cmd(hba, task_tag); 550 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 551 + struct request *rq = scsi_cmd_to_rq(cmd); 536 552 struct ufs_hw_queue *hwq; 537 553 void __iomem *reg, *opr_sqd_base; 538 554 u32 nexus, id, val; ··· 542 556 if (hba->quirks & UFSHCD_QUIRK_MCQ_BROKEN_RTC) 543 557 return -ETIMEDOUT; 544 558 545 - if (task_tag != hba->nutrs - UFSHCD_NUM_RESERVED) { 546 - if (!cmd) 547 - return -EINVAL; 548 - hwq = ufshcd_mcq_req_to_hwq(hba, scsi_cmd_to_rq(cmd)); 549 - if (!hwq) 550 - return 0; 551 - } else { 552 - hwq = hba->dev_cmd_queue; 553 - } 559 + if (!cmd) 560 + return -EINVAL; 561 + 562 + hwq = ufshcd_mcq_req_to_hwq(hba, rq); 563 + if (!hwq) 564 + return 0; 554 565 555 566 id = hwq->id; 556 567 557 - mutex_lock(&hwq->sq_mutex); 568 + guard(mutex)(&hwq->sq_mutex); 558 569 559 570 /* stop the SQ fetching before working on it */ 560 571 err = ufshcd_mcq_sq_stop(hba, hwq); 561 572 if (err) 562 - goto unlock; 573 + return err; 563 574 564 575 /* SQCTI = EXT_IID, IID, LUN, Task Tag */ 565 576 nexus = lrbp->lun << 8 | task_tag; ··· 583 600 if (ufshcd_mcq_sq_start(hba, hwq)) 584 601 err = -ETIMEDOUT; 585 602 586 - unlock: 587 - mutex_unlock(&hwq->sq_mutex); 588 603 return err; 589 604 } 590 605 ··· 613 632 static bool ufshcd_mcq_sqe_search(struct ufs_hba *hba, 614 633 struct ufs_hw_queue *hwq, int task_tag) 615 634 { 616 - struct ufshcd_lrb *lrbp = &hba->lrb[task_tag]; 635 + struct scsi_cmnd *cmd = ufshcd_tag_to_cmd(hba, task_tag); 636 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 617 637 struct utp_transfer_req_desc *utrd; 618 638 __le64 cmd_desc_base_addr; 619 639 bool ret = false; ··· 665 683 struct Scsi_Host *host = cmd->device->host; 666 684 struct ufs_hba *hba = shost_priv(host); 667 685 int tag = scsi_cmd_to_rq(cmd)->tag; 668 - struct ufshcd_lrb *lrbp = &hba->lrb[tag]; 686 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 669 687 struct ufs_hw_queue *hwq; 670 688 int err; 671 689
+254
drivers/ufs/core/ufs-rpmb.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * UFS OP-TEE based RPMB Driver 4 + * 5 + * Copyright (C) 2025 Micron Technology, Inc. 6 + * Copyright (C) 2025 Qualcomm Technologies, Inc. 7 + * 8 + * Authors: 9 + * Bean Huo <beanhuo@micron.com> 10 + * Can Guo <can.guo@oss.qualcomm.com> 11 + */ 12 + 13 + #include <linux/module.h> 14 + #include <linux/device.h> 15 + #include <linux/kernel.h> 16 + #include <linux/types.h> 17 + #include <linux/rpmb.h> 18 + #include <linux/string.h> 19 + #include <linux/list.h> 20 + #include <ufs/ufshcd.h> 21 + #include <linux/unaligned.h> 22 + #include "ufshcd-priv.h" 23 + 24 + #define UFS_RPMB_SEC_PROTOCOL 0xEC /* JEDEC UFS application */ 25 + #define UFS_RPMB_SEC_PROTOCOL_ID 0x01 /* JEDEC UFS RPMB protocol ID, CDB byte3 */ 26 + 27 + static const struct bus_type ufs_rpmb_bus_type = { 28 + .name = "ufs_rpmb", 29 + }; 30 + 31 + /* UFS RPMB device structure */ 32 + struct ufs_rpmb_dev { 33 + u8 region_id; 34 + struct device dev; 35 + struct rpmb_dev *rdev; 36 + struct ufs_hba *hba; 37 + struct list_head node; 38 + }; 39 + 40 + static int ufs_sec_submit(struct ufs_hba *hba, u16 spsp, void *buffer, size_t len, bool send) 41 + { 42 + struct scsi_device *sdev = hba->ufs_rpmb_wlun; 43 + u8 cdb[12] = { }; 44 + 45 + cdb[0] = send ? SECURITY_PROTOCOL_OUT : SECURITY_PROTOCOL_IN; 46 + cdb[1] = UFS_RPMB_SEC_PROTOCOL; 47 + put_unaligned_be16(spsp, &cdb[2]); 48 + put_unaligned_be32(len, &cdb[6]); 49 + 50 + return scsi_execute_cmd(sdev, cdb, send ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN, 51 + buffer, len, /*timeout=*/30 * HZ, 0, NULL); 52 + } 53 + 54 + /* UFS RPMB route frames implementation */ 55 + static int ufs_rpmb_route_frames(struct device *dev, u8 *req, unsigned int req_len, u8 *resp, 56 + unsigned int resp_len) 57 + { 58 + struct ufs_rpmb_dev *ufs_rpmb = dev_get_drvdata(dev); 59 + struct rpmb_frame *frm_out = (struct rpmb_frame *)req; 60 + bool need_result_read = true; 61 + u16 req_type, protocol_id; 62 + struct ufs_hba *hba; 63 + int ret; 64 + 65 + if (!ufs_rpmb) { 66 + dev_err(dev, "Missing driver data\n"); 67 + return -ENODEV; 68 + } 69 + 70 + hba = ufs_rpmb->hba; 71 + 72 + req_type = be16_to_cpu(frm_out->req_resp); 73 + 74 + switch (req_type) { 75 + case RPMB_PROGRAM_KEY: 76 + if (req_len != sizeof(struct rpmb_frame) || resp_len != sizeof(struct rpmb_frame)) 77 + return -EINVAL; 78 + break; 79 + case RPMB_GET_WRITE_COUNTER: 80 + if (req_len != sizeof(struct rpmb_frame) || resp_len != sizeof(struct rpmb_frame)) 81 + return -EINVAL; 82 + need_result_read = false; 83 + break; 84 + case RPMB_WRITE_DATA: 85 + if (req_len % sizeof(struct rpmb_frame) || resp_len != sizeof(struct rpmb_frame)) 86 + return -EINVAL; 87 + break; 88 + case RPMB_READ_DATA: 89 + if (req_len != sizeof(struct rpmb_frame) || resp_len % sizeof(struct rpmb_frame)) 90 + return -EINVAL; 91 + need_result_read = false; 92 + break; 93 + default: 94 + dev_err(dev, "Unknown request type=0x%04x\n", req_type); 95 + return -EINVAL; 96 + } 97 + 98 + protocol_id = ufs_rpmb->region_id << 8 | UFS_RPMB_SEC_PROTOCOL_ID; 99 + 100 + ret = ufs_sec_submit(hba, protocol_id, req, req_len, true); 101 + if (ret) { 102 + dev_err(dev, "Command failed with ret=%d\n", ret); 103 + return ret; 104 + } 105 + 106 + if (need_result_read) { 107 + struct rpmb_frame *frm_resp = (struct rpmb_frame *)resp; 108 + 109 + memset(frm_resp, 0, sizeof(*frm_resp)); 110 + frm_resp->req_resp = cpu_to_be16(RPMB_RESULT_READ); 111 + ret = ufs_sec_submit(hba, protocol_id, resp, resp_len, true); 112 + if (ret) { 113 + dev_err(dev, "Result read request failed with ret=%d\n", ret); 114 + return ret; 115 + } 116 + } 117 + 118 + if (!ret) { 119 + ret = ufs_sec_submit(hba, protocol_id, resp, resp_len, false); 120 + if (ret) 121 + dev_err(dev, "Response read failed with ret=%d\n", ret); 122 + } 123 + 124 + return ret; 125 + } 126 + 127 + static void ufs_rpmb_device_release(struct device *dev) 128 + { 129 + struct ufs_rpmb_dev *ufs_rpmb = dev_get_drvdata(dev); 130 + 131 + rpmb_dev_unregister(ufs_rpmb->rdev); 132 + } 133 + 134 + /* UFS RPMB device registration */ 135 + int ufs_rpmb_probe(struct ufs_hba *hba) 136 + { 137 + struct ufs_rpmb_dev *ufs_rpmb, *it, *tmp; 138 + struct rpmb_dev *rdev; 139 + char *cid = NULL; 140 + int region; 141 + u32 cap; 142 + int ret; 143 + 144 + if (!hba->ufs_rpmb_wlun || hba->dev_info.b_advanced_rpmb_en) { 145 + dev_info(hba->dev, "Skip OP-TEE RPMB registration\n"); 146 + return -ENODEV; 147 + } 148 + 149 + /* Check if device_id is available */ 150 + if (!hba->dev_info.device_id) { 151 + dev_err(hba->dev, "UFS Device ID not available\n"); 152 + return -EINVAL; 153 + } 154 + 155 + INIT_LIST_HEAD(&hba->rpmbs); 156 + 157 + struct rpmb_descr descr = { 158 + .type = RPMB_TYPE_UFS, 159 + .route_frames = ufs_rpmb_route_frames, 160 + .reliable_wr_count = hba->dev_info.rpmb_io_size, 161 + }; 162 + 163 + for (region = 0; region < ARRAY_SIZE(hba->dev_info.rpmb_region_size); region++) { 164 + cap = hba->dev_info.rpmb_region_size[region]; 165 + if (!cap) 166 + continue; 167 + 168 + ufs_rpmb = devm_kzalloc(hba->dev, sizeof(*ufs_rpmb), GFP_KERNEL); 169 + if (!ufs_rpmb) { 170 + ret = -ENOMEM; 171 + goto err_out; 172 + } 173 + 174 + ufs_rpmb->hba = hba; 175 + ufs_rpmb->dev.parent = &hba->ufs_rpmb_wlun->sdev_gendev; 176 + ufs_rpmb->dev.bus = &ufs_rpmb_bus_type; 177 + ufs_rpmb->dev.release = ufs_rpmb_device_release; 178 + dev_set_name(&ufs_rpmb->dev, "ufs_rpmb%d", region); 179 + 180 + /* Set driver data BEFORE device_register */ 181 + dev_set_drvdata(&ufs_rpmb->dev, ufs_rpmb); 182 + 183 + ret = device_register(&ufs_rpmb->dev); 184 + if (ret) { 185 + dev_err(hba->dev, "Failed to register UFS RPMB device %d\n", region); 186 + put_device(&ufs_rpmb->dev); 187 + goto err_out; 188 + } 189 + 190 + /* Create unique ID by appending region number to device_id */ 191 + cid = kasprintf(GFP_KERNEL, "%s-R%d", hba->dev_info.device_id, region); 192 + if (!cid) { 193 + device_unregister(&ufs_rpmb->dev); 194 + ret = -ENOMEM; 195 + goto err_out; 196 + } 197 + 198 + descr.dev_id = cid; 199 + descr.dev_id_len = strlen(cid); 200 + descr.capacity = cap; 201 + 202 + /* Register RPMB device */ 203 + rdev = rpmb_dev_register(&ufs_rpmb->dev, &descr); 204 + if (IS_ERR(rdev)) { 205 + dev_err(hba->dev, "Failed to register UFS RPMB device.\n"); 206 + device_unregister(&ufs_rpmb->dev); 207 + ret = PTR_ERR(rdev); 208 + goto err_out; 209 + } 210 + 211 + kfree(cid); 212 + cid = NULL; 213 + 214 + ufs_rpmb->rdev = rdev; 215 + ufs_rpmb->region_id = region; 216 + 217 + list_add_tail(&ufs_rpmb->node, &hba->rpmbs); 218 + 219 + dev_info(hba->dev, "UFS RPMB region %d registered (capacity=%u)\n", region, cap); 220 + } 221 + 222 + return 0; 223 + err_out: 224 + kfree(cid); 225 + list_for_each_entry_safe(it, tmp, &hba->rpmbs, node) { 226 + list_del(&it->node); 227 + device_unregister(&it->dev); 228 + } 229 + 230 + return ret; 231 + } 232 + 233 + /* UFS RPMB remove handler */ 234 + void ufs_rpmb_remove(struct ufs_hba *hba) 235 + { 236 + struct ufs_rpmb_dev *ufs_rpmb, *tmp; 237 + 238 + if (list_empty(&hba->rpmbs)) 239 + return; 240 + 241 + /* Remove all registered RPMB devices */ 242 + list_for_each_entry_safe(ufs_rpmb, tmp, &hba->rpmbs, node) { 243 + dev_info(hba->dev, "Removing UFS RPMB region %d\n", ufs_rpmb->region_id); 244 + /* Remove from list first */ 245 + list_del(&ufs_rpmb->node); 246 + /* Unregister device */ 247 + device_unregister(&ufs_rpmb->dev); 248 + } 249 + 250 + dev_info(hba->dev, "All UFS RPMB devices unregistered\n"); 251 + } 252 + 253 + MODULE_LICENSE("GPL v2"); 254 + MODULE_DESCRIPTION("OP-TEE UFS RPMB driver");
+2 -1
drivers/ufs/core/ufs-sysfs.c
··· 235 235 } 236 236 237 237 /* Convert microseconds to Auto-Hibernate Idle Timer register value */ 238 - static u32 ufshcd_us_to_ahit(unsigned int timer) 238 + u32 ufshcd_us_to_ahit(unsigned int timer) 239 239 { 240 240 unsigned int scale; 241 241 ··· 245 245 return FIELD_PREP(UFSHCI_AHIBERN8_TIMER_MASK, timer) | 246 246 FIELD_PREP(UFSHCI_AHIBERN8_SCALE_MASK, scale); 247 247 } 248 + EXPORT_SYMBOL_GPL(ufshcd_us_to_ahit); 248 249 249 250 static int ufshcd_read_hci_reg(struct ufs_hba *hba, u32 *val, unsigned int reg) 250 251 {
+1 -1
drivers/ufs/core/ufs_bsg.c
··· 105 105 106 106 if (dir != DMA_NONE) { 107 107 payload = &job->request_payload; 108 - if (!payload || !payload->payload_len || !payload->sg_cnt) 108 + if (!payload->payload_len || !payload->sg_cnt) 109 109 return -EINVAL; 110 110 111 111 sg_cnt = dma_map_sg(hba->host->dma_dev, payload->sg_list, payload->sg_cnt, dir);
-1
drivers/ufs/core/ufs_trace.h
··· 42 42 #define UFS_CMD_TRACE_STRINGS \ 43 43 EM(UFS_CMD_SEND, "send_req") \ 44 44 EM(UFS_CMD_COMP, "complete_rsp") \ 45 - EM(UFS_DEV_COMP, "dev_complete") \ 46 45 EM(UFS_QUERY_SEND, "query_send") \ 47 46 EM(UFS_QUERY_COMP, "query_complete") \ 48 47 EM(UFS_QUERY_ERR, "query_complete_err") \
-1
drivers/ufs/core/ufs_trace_types.h
··· 5 5 enum ufs_trace_str_t { 6 6 UFS_CMD_SEND, 7 7 UFS_CMD_COMP, 8 - UFS_DEV_COMP, 9 8 UFS_QUERY_SEND, 10 9 UFS_QUERY_COMP, 11 10 UFS_QUERY_ERR,
+11 -7
drivers/ufs/core/ufshcd-crypto.h
··· 38 38 } 39 39 40 40 static inline int ufshcd_crypto_fill_prdt(struct ufs_hba *hba, 41 - struct ufshcd_lrb *lrbp) 41 + struct scsi_cmnd *cmd) 42 42 { 43 - struct scsi_cmnd *cmd = lrbp->cmd; 44 43 const struct bio_crypt_ctx *crypt_ctx = scsi_cmd_to_rq(cmd)->crypt_ctx; 44 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 45 45 46 46 if (crypt_ctx && hba->vops && hba->vops->fill_crypto_prdt) 47 47 return hba->vops->fill_crypto_prdt(hba, crypt_ctx, ··· 51 51 } 52 52 53 53 static inline void ufshcd_crypto_clear_prdt(struct ufs_hba *hba, 54 - struct ufshcd_lrb *lrbp) 54 + struct scsi_cmnd *cmd) 55 55 { 56 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 57 + 56 58 if (!(hba->quirks & UFSHCD_QUIRK_KEYS_IN_PRDT)) 57 59 return; 58 60 59 - if (!(scsi_cmd_to_rq(lrbp->cmd)->crypt_ctx)) 61 + if (!(scsi_cmd_to_rq(cmd)->crypt_ctx)) 60 62 return; 61 63 62 64 /* Zeroize the PRDT because it can contain cryptographic keys. */ 63 65 memzero_explicit(lrbp->ucd_prdt_ptr, 64 - ufshcd_sg_entry_size(hba) * scsi_sg_count(lrbp->cmd)); 66 + ufshcd_sg_entry_size(hba) * scsi_sg_count(cmd)); 65 67 } 66 68 67 69 bool ufshcd_crypto_enable(struct ufs_hba *hba); ··· 84 82 struct request_desc_header *h) { } 85 83 86 84 static inline int ufshcd_crypto_fill_prdt(struct ufs_hba *hba, 87 - struct ufshcd_lrb *lrbp) 85 + struct scsi_cmnd *cmd) 88 86 { 89 87 return 0; 90 88 } 91 89 92 90 static inline void ufshcd_crypto_clear_prdt(struct ufs_hba *hba, 93 - struct ufshcd_lrb *lrbp) { } 91 + struct scsi_cmnd *cmd) 92 + { 93 + } 94 94 95 95 static inline bool ufshcd_crypto_enable(struct ufs_hba *hba) 96 96 {
+47 -7
drivers/ufs/core/ufshcd-priv.h
··· 6 6 #include <linux/pm_runtime.h> 7 7 #include <ufs/ufshcd.h> 8 8 9 + void ufshcd_enable_intr(struct ufs_hba *hba, u32 intrs); 10 + 9 11 static inline bool ufshcd_is_user_access_allowed(struct ufs_hba *hba) 10 12 { 11 13 return !hba->shutting_down; ··· 67 65 struct cq_entry *cqe); 68 66 int ufshcd_mcq_init(struct ufs_hba *hba); 69 67 void ufshcd_mcq_disable(struct ufs_hba *hba); 70 - int ufshcd_mcq_decide_queue_depth(struct ufs_hba *hba); 68 + int ufshcd_get_hba_mac(struct ufs_hba *hba); 71 69 int ufshcd_mcq_memory_alloc(struct ufs_hba *hba); 72 70 struct ufs_hw_queue *ufshcd_mcq_req_to_hwq(struct ufs_hba *hba, 73 71 struct request *req); ··· 77 75 int ufshcd_mcq_sq_cleanup(struct ufs_hba *hba, int task_tag); 78 76 int ufshcd_mcq_abort(struct scsi_cmnd *cmd); 79 77 int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag); 80 - void ufshcd_release_scsi_cmd(struct ufs_hba *hba, 81 - struct ufshcd_lrb *lrbp); 78 + void ufshcd_release_scsi_cmd(struct ufs_hba *hba, struct scsi_cmnd *cmd); 82 79 83 - #define SD_ASCII_STD true 84 - #define SD_RAW false 85 - int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, 86 - u8 **buf, bool ascii); 80 + /** 81 + * enum ufs_descr_fmt - UFS string descriptor format 82 + * @SD_RAW: Raw UTF-16 format 83 + * @SD_ASCII_STD: Convert to null-terminated ASCII string 84 + */ 85 + enum ufs_descr_fmt { 86 + SD_RAW = 0, 87 + SD_ASCII_STD = 1, 88 + }; 87 89 90 + int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, u8 **buf, enum ufs_descr_fmt fmt); 88 91 int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd); 89 92 int ufshcd_send_bsg_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd); 90 93 ··· 368 361 return lun == UFS_UPIU_RPMB_WLUN || (lun < dev_info->max_lu_supported); 369 362 } 370 363 364 + /* 365 + * Convert a block layer tag into a SCSI command pointer. This function is 366 + * called once per I/O completion path and is also called from error paths. 367 + */ 368 + static inline struct scsi_cmnd *ufshcd_tag_to_cmd(struct ufs_hba *hba, u32 tag) 369 + { 370 + /* 371 + * Host-wide tags are enabled in MCQ mode only. See also the 372 + * host->host_tagset assignment in ufs-mcq.c. 373 + */ 374 + struct blk_mq_tags *tags = hba->host->tag_set.shared_tags ?: 375 + hba->host->tag_set.tags[0]; 376 + struct request *rq = blk_mq_tag_to_rq(tags, tag); 377 + 378 + if (WARN_ON_ONCE(!rq)) 379 + return NULL; 380 + 381 + return blk_mq_rq_to_pdu(rq); 382 + } 383 + 371 384 static inline void ufshcd_inc_sq_tail(struct ufs_hw_queue *q) 372 385 __must_hold(&q->sq_lock) 373 386 { ··· 437 410 438 411 return val / sizeof(struct utp_transfer_req_desc); 439 412 } 413 + 414 + #if IS_ENABLED(CONFIG_RPMB) 415 + int ufs_rpmb_probe(struct ufs_hba *hba); 416 + void ufs_rpmb_remove(struct ufs_hba *hba); 417 + #else 418 + static inline int ufs_rpmb_probe(struct ufs_hba *hba) 419 + { 420 + return 0; 421 + } 422 + static inline void ufs_rpmb_remove(struct ufs_hba *hba) 423 + { 424 + } 425 + #endif 440 426 441 427 #endif /* _UFSHCD_PRIV_H_ */
+533 -403
drivers/ufs/core/ufshcd.c
··· 28 28 #include <scsi/scsi_dbg.h> 29 29 #include <scsi/scsi_driver.h> 30 30 #include <scsi/scsi_eh.h> 31 + #include <scsi/scsi_tcq.h> 31 32 #include "ufshcd-priv.h" 32 33 #include <ufs/ufs_quirks.h> 33 34 #include <ufs/unipro.h> ··· 404 403 ufshcd_wb_toggle_buf_flush(hba, true); 405 404 } 406 405 407 - static void ufshcd_add_cmd_upiu_trace(struct ufs_hba *hba, unsigned int tag, 406 + static void ufshcd_add_cmd_upiu_trace(struct ufs_hba *hba, 407 + struct ufshcd_lrb *lrb, 408 408 enum ufs_trace_str_t str_t) 409 409 { 410 - struct utp_upiu_req *rq = hba->lrb[tag].ucd_req_ptr; 410 + struct utp_upiu_req *rq = lrb->ucd_req_ptr; 411 411 struct utp_upiu_header *header; 412 412 413 413 if (!trace_ufshcd_upiu_enabled()) ··· 417 415 if (str_t == UFS_CMD_SEND) 418 416 header = &rq->header; 419 417 else 420 - header = &hba->lrb[tag].ucd_rsp_ptr->header; 418 + header = &lrb->ucd_rsp_ptr->header; 421 419 422 420 trace_ufshcd_upiu(hba, str_t, header, &rq->sc.cdb, 423 421 UFS_TSF_CDB); ··· 474 472 ufshcd_readl(hba, REG_UIC_COMMAND_ARG_3)); 475 473 } 476 474 477 - static void ufshcd_add_command_trace(struct ufs_hba *hba, unsigned int tag, 475 + static void ufshcd_add_command_trace(struct ufs_hba *hba, struct scsi_cmnd *cmd, 478 476 enum ufs_trace_str_t str_t) 479 477 { 480 478 u64 lba = 0; ··· 482 480 u32 doorbell = 0; 483 481 u32 intr; 484 482 u32 hwq_id = 0; 485 - struct ufshcd_lrb *lrbp = &hba->lrb[tag]; 486 - struct scsi_cmnd *cmd = lrbp->cmd; 487 483 struct request *rq = scsi_cmd_to_rq(cmd); 484 + unsigned int tag = rq->tag; 485 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 488 486 int transfer_len = -1; 489 487 490 - if (!cmd) 491 - return; 492 - 493 488 /* trace UPIU also */ 494 - ufshcd_add_cmd_upiu_trace(hba, tag, str_t); 489 + ufshcd_add_cmd_upiu_trace(hba, lrbp, str_t); 495 490 if (!trace_ufshcd_command_enabled()) 496 491 return; 497 492 ··· 502 503 be32_to_cpu(lrbp->ucd_req_ptr->sc.exp_data_transfer_len); 503 504 lba = scsi_get_lba(cmd); 504 505 if (opcode == WRITE_10) 505 - group_id = lrbp->cmd->cmnd[6]; 506 + group_id = cmd->cmnd[6]; 506 507 } else if (opcode == UNMAP) { 507 508 /* 508 509 * The number of Bytes to be unmapped beginning with the lba. ··· 595 596 ufshcd_vops_dbg_register_dump(hba); 596 597 } 597 598 598 - static 599 - void ufshcd_print_tr(struct ufs_hba *hba, int tag, bool pr_prdt) 599 + static void ufshcd_print_tr(struct ufs_hba *hba, struct scsi_cmnd *cmd, 600 + bool pr_prdt) 600 601 { 601 - const struct ufshcd_lrb *lrbp; 602 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 603 + const int tag = scsi_cmd_to_rq(cmd)->tag; 602 604 int prdt_length; 603 - 604 - lrbp = &hba->lrb[tag]; 605 605 606 606 if (hba->monitor.enabled) { 607 607 dev_err(hba->dev, "UPIU[%d] - issue time %lld us\n", tag, ··· 644 646 struct Scsi_Host *shost = sdev->host; 645 647 struct ufs_hba *hba = shost_priv(shost); 646 648 647 - ufshcd_print_tr(hba, req->tag, *(bool *)priv); 649 + if (!blk_mq_is_reserved_rq(req)) 650 + ufshcd_print_tr(hba, blk_mq_rq_to_pdu(req), *(bool *)priv); 648 651 649 652 return true; 650 653 } ··· 855 856 struct cq_entry *cqe) 856 857 { 857 858 if (cqe) 858 - return le32_to_cpu(cqe->status) & MASK_OCS; 859 + return cqe->overall_status & MASK_OCS; 859 860 860 861 return lrbp->utr_descriptor_ptr->header.ocs & MASK_OCS; 861 862 } ··· 1075 1076 * @hba: per adapter instance 1076 1077 * @on: If True, vote for perf PM QoS mode otherwise power save mode 1077 1078 */ 1078 - static void ufshcd_pm_qos_update(struct ufs_hba *hba, bool on) 1079 + void ufshcd_pm_qos_update(struct ufs_hba *hba, bool on) 1079 1080 { 1080 1081 guard(mutex)(&hba->pm_qos_mutex); 1081 1082 ··· 1084 1085 1085 1086 cpu_latency_qos_update_request(&hba->pm_qos_req, on ? 0 : PM_QOS_DEFAULT_VALUE); 1086 1087 } 1088 + EXPORT_SYMBOL_GPL(ufshcd_pm_qos_update); 1087 1089 1088 1090 /** 1089 1091 * ufshcd_set_clk_freq - set UFS controller clock frequencies ··· 1290 1290 */ 1291 1291 static u32 ufshcd_pending_cmds(struct ufs_hba *hba) 1292 1292 { 1293 - const struct scsi_device *sdev; 1293 + struct scsi_device *sdev; 1294 1294 unsigned long flags; 1295 1295 u32 pending = 0; 1296 1296 1297 1297 spin_lock_irqsave(hba->host->host_lock, flags); 1298 1298 __shost_for_each_device(sdev, hba->host) 1299 - pending += sbitmap_weight(&sdev->budget_map); 1299 + pending += scsi_device_busy(sdev); 1300 1300 spin_unlock_irqrestore(hba->host->host_lock, flags); 1301 1301 1302 1302 return pending; ··· 2294 2294 return -EINVAL; 2295 2295 } 2296 2296 2297 + /* Must only be called for SCSI commands. */ 2297 2298 static inline bool ufshcd_should_inform_monitor(struct ufs_hba *hba, 2298 - struct ufshcd_lrb *lrbp) 2299 + struct scsi_cmnd *cmd) 2299 2300 { 2300 2301 const struct ufs_hba_monitor *m = &hba->monitor; 2302 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 2301 2303 2302 - return (m->enabled && lrbp && lrbp->cmd && 2303 - (!m->chunk_size || m->chunk_size == lrbp->cmd->sdb.length) && 2304 - ktime_before(hba->monitor.enabled_ts, lrbp->issue_time_stamp)); 2304 + return m->enabled && 2305 + (!m->chunk_size || m->chunk_size == cmd->sdb.length) && 2306 + ktime_before(hba->monitor.enabled_ts, lrbp->issue_time_stamp); 2305 2307 } 2306 2308 2307 - static void ufshcd_start_monitor(struct ufs_hba *hba, 2308 - const struct ufshcd_lrb *lrbp) 2309 + static void ufshcd_start_monitor(struct ufs_hba *hba, struct scsi_cmnd *cmd) 2309 2310 { 2310 - int dir = ufshcd_monitor_opcode2dir(*lrbp->cmd->cmnd); 2311 + int dir = ufshcd_monitor_opcode2dir(cmd->cmnd[0]); 2311 2312 unsigned long flags; 2312 2313 2313 2314 spin_lock_irqsave(hba->host->host_lock, flags); ··· 2317 2316 spin_unlock_irqrestore(hba->host->host_lock, flags); 2318 2317 } 2319 2318 2320 - static void ufshcd_update_monitor(struct ufs_hba *hba, const struct ufshcd_lrb *lrbp) 2319 + static void ufshcd_update_monitor(struct ufs_hba *hba, struct scsi_cmnd *cmd) 2321 2320 { 2322 - int dir = ufshcd_monitor_opcode2dir(*lrbp->cmd->cmnd); 2321 + struct request *req = scsi_cmd_to_rq(cmd); 2322 + const struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 2323 + int dir = ufshcd_monitor_opcode2dir(cmd->cmnd[0]); 2323 2324 unsigned long flags; 2324 2325 2325 2326 spin_lock_irqsave(hba->host->host_lock, flags); 2326 2327 if (dir >= 0 && hba->monitor.nr_queued[dir] > 0) { 2327 - const struct request *req = scsi_cmd_to_rq(lrbp->cmd); 2328 2328 struct ufs_hba_monitor *m = &hba->monitor; 2329 2329 ktime_t now, inc, lat; 2330 2330 ··· 2350 2348 spin_unlock_irqrestore(hba->host->host_lock, flags); 2351 2349 } 2352 2350 2351 + /* Returns %true for SCSI commands and %false for device management commands. */ 2352 + static bool ufshcd_is_scsi_cmd(struct scsi_cmnd *cmd) 2353 + { 2354 + return !blk_mq_is_reserved_rq(scsi_cmd_to_rq(cmd)); 2355 + } 2356 + 2353 2357 /** 2354 2358 * ufshcd_send_command - Send SCSI or device management commands 2355 2359 * @hba: per adapter instance 2356 - * @task_tag: Task tag of the command 2360 + * @cmd: SCSI command or device management command pointer 2357 2361 * @hwq: pointer to hardware queue instance 2358 2362 */ 2359 - static inline 2360 - void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag, 2361 - struct ufs_hw_queue *hwq) 2363 + static inline void ufshcd_send_command(struct ufs_hba *hba, 2364 + struct scsi_cmnd *cmd, 2365 + struct ufs_hw_queue *hwq) 2362 2366 { 2363 - struct ufshcd_lrb *lrbp = &hba->lrb[task_tag]; 2367 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 2368 + const int tag = scsi_cmd_to_rq(cmd)->tag; 2364 2369 unsigned long flags; 2365 2370 2366 2371 if (hba->monitor.enabled) { ··· 2376 2367 lrbp->compl_time_stamp = ktime_set(0, 0); 2377 2368 lrbp->compl_time_stamp_local_clock = 0; 2378 2369 } 2379 - ufshcd_add_command_trace(hba, task_tag, UFS_CMD_SEND); 2380 - if (lrbp->cmd) 2370 + if (ufshcd_is_scsi_cmd(cmd)) { 2371 + ufshcd_add_command_trace(hba, cmd, UFS_CMD_SEND); 2381 2372 ufshcd_clk_scaling_start_busy(hba); 2382 - if (unlikely(ufshcd_should_inform_monitor(hba, lrbp))) 2383 - ufshcd_start_monitor(hba, lrbp); 2373 + if (unlikely(ufshcd_should_inform_monitor(hba, cmd))) 2374 + ufshcd_start_monitor(hba, cmd); 2375 + } 2384 2376 2385 2377 if (hba->mcq_enabled) { 2386 2378 int utrd_size = sizeof(struct utp_transfer_req_desc); ··· 2396 2386 } else { 2397 2387 spin_lock_irqsave(&hba->outstanding_lock, flags); 2398 2388 if (hba->vops && hba->vops->setup_xfer_req) 2399 - hba->vops->setup_xfer_req(hba, lrbp->task_tag, 2400 - !!lrbp->cmd); 2401 - __set_bit(lrbp->task_tag, &hba->outstanding_reqs); 2402 - ufshcd_writel(hba, 1 << lrbp->task_tag, 2403 - REG_UTP_TRANSFER_REQ_DOOR_BELL); 2389 + hba->vops->setup_xfer_req(hba, tag, 2390 + ufshcd_is_scsi_cmd(cmd)); 2391 + __set_bit(tag, &hba->outstanding_reqs); 2392 + ufshcd_writel(hba, 1 << tag, REG_UTP_TRANSFER_REQ_DOOR_BELL); 2404 2393 spin_unlock_irqrestore(&hba->outstanding_lock, flags); 2405 2394 } 2406 2395 } 2407 2396 2408 2397 /** 2409 2398 * ufshcd_copy_sense_data - Copy sense data in case of check condition 2410 - * @lrbp: pointer to local reference block 2399 + * @cmd: SCSI command 2411 2400 */ 2412 - static inline void ufshcd_copy_sense_data(struct ufshcd_lrb *lrbp) 2401 + static inline void ufshcd_copy_sense_data(struct scsi_cmnd *cmd) 2413 2402 { 2414 - u8 *const sense_buffer = lrbp->cmd->sense_buffer; 2403 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 2404 + u8 *const sense_buffer = cmd->sense_buffer; 2415 2405 u16 resp_len; 2416 2406 int len; 2417 2407 ··· 2484 2474 hba->nutrs = (hba->capabilities & MASK_TRANSFER_REQUESTS_SLOTS_SDB) + 1; 2485 2475 hba->nutmrs = 2486 2476 ((hba->capabilities & MASK_TASK_MANAGEMENT_REQUEST_SLOTS) >> 16) + 1; 2487 - hba->reserved_slot = hba->nutrs - 1; 2488 2477 2489 2478 hba->nortt = FIELD_GET(MASK_NUMBER_OUTSTANDING_RTT, hba->capabilities) + 1; 2490 2479 ··· 2627 2618 2628 2619 init_completion(&uic_cmd->done); 2629 2620 2630 - uic_cmd->cmd_active = 1; 2621 + uic_cmd->cmd_active = true; 2631 2622 ufshcd_dispatch_uic_cmd(hba, uic_cmd); 2632 2623 2633 2624 return 0; ··· 2715 2706 /** 2716 2707 * ufshcd_map_sg - Map scatter-gather list to prdt 2717 2708 * @hba: per adapter instance 2718 - * @lrbp: pointer to local reference block 2709 + * @cmd: SCSI command 2719 2710 * 2720 2711 * Return: 0 in case of success, non-zero value in case of failure. 2721 2712 */ 2722 - static int ufshcd_map_sg(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) 2713 + static int ufshcd_map_sg(struct ufs_hba *hba, struct scsi_cmnd *cmd) 2723 2714 { 2724 - struct scsi_cmnd *cmd = lrbp->cmd; 2715 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 2725 2716 int sg_segments = scsi_dma_map(cmd); 2726 2717 2727 2718 if (sg_segments < 0) ··· 2729 2720 2730 2721 ufshcd_sgl_to_prdt(hba, lrbp, sg_segments, scsi_sglist(cmd)); 2731 2722 2732 - return ufshcd_crypto_fill_prdt(hba, lrbp); 2723 + return ufshcd_crypto_fill_prdt(hba, cmd); 2733 2724 } 2734 2725 2735 2726 /** ··· 2788 2779 /** 2789 2780 * ufshcd_prepare_utp_scsi_cmd_upiu() - fills the utp_transfer_req_desc, 2790 2781 * for scsi commands 2791 - * @lrbp: local reference block pointer 2782 + * @cmd: SCSI command 2792 2783 * @upiu_flags: flags 2793 2784 */ 2794 - static 2795 - void ufshcd_prepare_utp_scsi_cmd_upiu(struct ufshcd_lrb *lrbp, u8 upiu_flags) 2785 + static void ufshcd_prepare_utp_scsi_cmd_upiu(struct scsi_cmnd *cmd, 2786 + u8 upiu_flags) 2796 2787 { 2797 - struct scsi_cmnd *cmd = lrbp->cmd; 2788 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 2789 + const int tag = scsi_cmd_to_rq(cmd)->tag; 2798 2790 struct utp_upiu_req *ucd_req_ptr = lrbp->ucd_req_ptr; 2799 2791 unsigned short cdb_len; 2800 2792 ··· 2803 2793 .transaction_code = UPIU_TRANSACTION_COMMAND, 2804 2794 .flags = upiu_flags, 2805 2795 .lun = lrbp->lun, 2806 - .task_tag = lrbp->task_tag, 2796 + .task_tag = tag, 2807 2797 .command_set_type = UPIU_COMMAND_SET_TYPE_SCSI, 2808 2798 }; 2809 2799 2810 - WARN_ON_ONCE(ucd_req_ptr->header.task_tag != lrbp->task_tag); 2800 + WARN_ON_ONCE(ucd_req_ptr->header.task_tag != tag); 2811 2801 2812 2802 ucd_req_ptr->sc.exp_data_transfer_len = cpu_to_be32(cmd->sdb.length); 2813 2803 ··· 2820 2810 /** 2821 2811 * ufshcd_prepare_utp_query_req_upiu() - fill the utp_transfer_req_desc for query request 2822 2812 * @hba: UFS hba 2823 - * @lrbp: local reference block pointer 2813 + * @cmd: SCSI command pointer 2824 2814 * @upiu_flags: flags 2825 2815 */ 2826 2816 static void ufshcd_prepare_utp_query_req_upiu(struct ufs_hba *hba, 2827 - struct ufshcd_lrb *lrbp, u8 upiu_flags) 2817 + struct scsi_cmnd *cmd, u8 upiu_flags) 2828 2818 { 2819 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 2829 2820 struct utp_upiu_req *ucd_req_ptr = lrbp->ucd_req_ptr; 2821 + const int tag = scsi_cmd_to_rq(cmd)->tag; 2830 2822 struct ufs_query *query = &hba->dev_cmd.query; 2831 2823 u16 len = be16_to_cpu(query->request.upiu_req.length); 2832 2824 ··· 2837 2825 .transaction_code = UPIU_TRANSACTION_QUERY_REQ, 2838 2826 .flags = upiu_flags, 2839 2827 .lun = lrbp->lun, 2840 - .task_tag = lrbp->task_tag, 2828 + .task_tag = tag, 2841 2829 .query_function = query->request.query_func, 2842 2830 /* Data segment length only need for WRITE_DESC */ 2843 2831 .data_segment_length = ··· 2856 2844 memcpy(ucd_req_ptr + 1, query->descriptor, len); 2857 2845 } 2858 2846 2859 - static inline void ufshcd_prepare_utp_nop_upiu(struct ufshcd_lrb *lrbp) 2847 + static inline void ufshcd_prepare_utp_nop_upiu(struct scsi_cmnd *cmd) 2860 2848 { 2849 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 2861 2850 struct utp_upiu_req *ucd_req_ptr = lrbp->ucd_req_ptr; 2851 + const int tag = scsi_cmd_to_rq(cmd)->tag; 2862 2852 2863 2853 memset(ucd_req_ptr, 0, sizeof(struct utp_upiu_req)); 2864 2854 2865 2855 ucd_req_ptr->header = (struct utp_upiu_header){ 2866 2856 .transaction_code = UPIU_TRANSACTION_NOP_OUT, 2867 - .task_tag = lrbp->task_tag, 2857 + .task_tag = tag, 2868 2858 }; 2869 2859 } 2870 2860 ··· 2874 2860 * ufshcd_compose_devman_upiu - UFS Protocol Information Unit(UPIU) 2875 2861 * for Device Management Purposes 2876 2862 * @hba: per adapter instance 2877 - * @lrbp: pointer to local reference block 2863 + * @cmd: SCSI command pointer 2878 2864 * 2879 2865 * Return: 0 upon success; < 0 upon failure. 2880 2866 */ 2881 2867 static int ufshcd_compose_devman_upiu(struct ufs_hba *hba, 2882 - struct ufshcd_lrb *lrbp) 2868 + struct scsi_cmnd *cmd) 2883 2869 { 2870 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 2884 2871 u8 upiu_flags; 2885 2872 int ret = 0; 2886 2873 2887 2874 ufshcd_prepare_req_desc_hdr(hba, lrbp, &upiu_flags, DMA_NONE, 0); 2888 2875 2889 2876 if (hba->dev_cmd.type == DEV_CMD_TYPE_QUERY) 2890 - ufshcd_prepare_utp_query_req_upiu(hba, lrbp, upiu_flags); 2877 + ufshcd_prepare_utp_query_req_upiu(hba, cmd, upiu_flags); 2891 2878 else if (hba->dev_cmd.type == DEV_CMD_TYPE_NOP) 2892 - ufshcd_prepare_utp_nop_upiu(lrbp); 2879 + ufshcd_prepare_utp_nop_upiu(cmd); 2893 2880 else 2894 2881 ret = -EINVAL; 2895 2882 ··· 2903 2888 * ufshcd_comp_scsi_upiu - UFS Protocol Information Unit(UPIU) 2904 2889 * for SCSI Purposes 2905 2890 * @hba: per adapter instance 2906 - * @lrbp: pointer to local reference block 2891 + * @cmd: SCSI command 2907 2892 */ 2908 - static void ufshcd_comp_scsi_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) 2893 + static void ufshcd_comp_scsi_upiu(struct ufs_hba *hba, struct scsi_cmnd *cmd) 2909 2894 { 2910 - struct request *rq = scsi_cmd_to_rq(lrbp->cmd); 2895 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 2896 + struct request *rq = scsi_cmd_to_rq(cmd); 2911 2897 unsigned int ioprio_class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq)); 2912 2898 u8 upiu_flags; 2913 2899 2914 - ufshcd_prepare_req_desc_hdr(hba, lrbp, &upiu_flags, lrbp->cmd->sc_data_direction, 0); 2900 + ufshcd_prepare_req_desc_hdr(hba, lrbp, &upiu_flags, 2901 + cmd->sc_data_direction, 0); 2915 2902 if (ioprio_class == IOPRIO_CLASS_RT) 2916 2903 upiu_flags |= UPIU_CMD_FLAGS_CP; 2917 - ufshcd_prepare_utp_scsi_cmd_upiu(lrbp, upiu_flags); 2904 + ufshcd_prepare_utp_scsi_cmd_upiu(cmd, upiu_flags); 2918 2905 } 2919 2906 2920 - static void __ufshcd_setup_cmd(struct ufshcd_lrb *lrbp, struct scsi_cmnd *cmd, u8 lun, int tag) 2907 + static void ufshcd_init_lrb(struct ufs_hba *hba, struct scsi_cmnd *cmd) 2921 2908 { 2909 + const int i = scsi_cmd_to_rq(cmd)->tag; 2910 + struct utp_transfer_cmd_desc *cmd_descp = 2911 + (void *)hba->ucdl_base_addr + i * ufshcd_get_ucd_size(hba); 2912 + struct utp_transfer_req_desc *utrdlp = hba->utrdl_base_addr; 2913 + dma_addr_t cmd_desc_element_addr = 2914 + hba->ucdl_dma_addr + i * ufshcd_get_ucd_size(hba); 2915 + u16 response_offset = le16_to_cpu(utrdlp[i].response_upiu_offset); 2916 + u16 prdt_offset = le16_to_cpu(utrdlp[i].prd_table_offset); 2917 + struct ufshcd_lrb *lrb = scsi_cmd_priv(cmd); 2918 + 2919 + lrb->utr_descriptor_ptr = utrdlp + i; 2920 + lrb->utrd_dma_addr = 2921 + hba->utrdl_dma_addr + i * sizeof(struct utp_transfer_req_desc); 2922 + lrb->ucd_req_ptr = (struct utp_upiu_req *)cmd_descp->command_upiu; 2923 + lrb->ucd_req_dma_addr = cmd_desc_element_addr; 2924 + lrb->ucd_rsp_ptr = (struct utp_upiu_rsp *)cmd_descp->response_upiu; 2925 + lrb->ucd_rsp_dma_addr = cmd_desc_element_addr + response_offset; 2926 + lrb->ucd_prdt_ptr = (struct ufshcd_sg_entry *)cmd_descp->prd_table; 2927 + lrb->ucd_prdt_dma_addr = cmd_desc_element_addr + prdt_offset; 2928 + } 2929 + 2930 + static void __ufshcd_setup_cmd(struct ufs_hba *hba, struct scsi_cmnd *cmd, 2931 + u8 lun, int tag) 2932 + { 2933 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 2934 + 2935 + ufshcd_init_lrb(hba, cmd); 2936 + 2922 2937 memset(lrbp->ucd_req_ptr, 0, sizeof(*lrbp->ucd_req_ptr)); 2923 2938 2924 - lrbp->cmd = cmd; 2925 - lrbp->task_tag = tag; 2926 2939 lrbp->lun = lun; 2927 - ufshcd_prepare_lrbp_crypto(cmd ? scsi_cmd_to_rq(cmd) : NULL, lrbp); 2940 + ufshcd_prepare_lrbp_crypto(ufshcd_is_scsi_cmd(cmd) ? 2941 + scsi_cmd_to_rq(cmd) : NULL, lrbp); 2928 2942 } 2929 2943 2930 - static void ufshcd_setup_scsi_cmd(struct ufs_hba *hba, struct ufshcd_lrb *lrbp, 2931 - struct scsi_cmnd *cmd, u8 lun, int tag) 2944 + static void ufshcd_setup_scsi_cmd(struct ufs_hba *hba, struct scsi_cmnd *cmd, 2945 + u8 lun, int tag) 2932 2946 { 2933 - __ufshcd_setup_cmd(lrbp, cmd, lun, tag); 2947 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 2948 + 2949 + __ufshcd_setup_cmd(hba, cmd, lun, tag); 2934 2950 lrbp->intr_cmd = !ufshcd_is_intr_aggr_allowed(hba); 2935 2951 lrbp->req_abort_skip = false; 2936 2952 2937 - ufshcd_comp_scsi_upiu(hba, lrbp); 2953 + ufshcd_comp_scsi_upiu(hba, cmd); 2938 2954 } 2939 2955 2940 2956 /** ··· 3016 2970 } 3017 2971 } 3018 2972 3019 - static void ufshcd_init_lrb(struct ufs_hba *hba, struct ufshcd_lrb *lrb, int i) 2973 + /* 2974 + * The only purpose of this function is to make the SCSI core skip the memset() 2975 + * call for the private command data. 2976 + */ 2977 + static int ufshcd_init_cmd_priv(struct Scsi_Host *host, struct scsi_cmnd *cmd) 3020 2978 { 3021 - struct utp_transfer_cmd_desc *cmd_descp = (void *)hba->ucdl_base_addr + 3022 - i * ufshcd_get_ucd_size(hba); 3023 - struct utp_transfer_req_desc *utrdlp = hba->utrdl_base_addr; 3024 - dma_addr_t cmd_desc_element_addr = hba->ucdl_dma_addr + 3025 - i * ufshcd_get_ucd_size(hba); 3026 - u16 response_offset = le16_to_cpu(utrdlp[i].response_upiu_offset); 3027 - u16 prdt_offset = le16_to_cpu(utrdlp[i].prd_table_offset); 3028 - 3029 - lrb->utr_descriptor_ptr = utrdlp + i; 3030 - lrb->utrd_dma_addr = hba->utrdl_dma_addr + 3031 - i * sizeof(struct utp_transfer_req_desc); 3032 - lrb->ucd_req_ptr = (struct utp_upiu_req *)cmd_descp->command_upiu; 3033 - lrb->ucd_req_dma_addr = cmd_desc_element_addr; 3034 - lrb->ucd_rsp_ptr = (struct utp_upiu_rsp *)cmd_descp->response_upiu; 3035 - lrb->ucd_rsp_dma_addr = cmd_desc_element_addr + response_offset; 3036 - lrb->ucd_prdt_ptr = (struct ufshcd_sg_entry *)cmd_descp->prd_table; 3037 - lrb->ucd_prdt_dma_addr = cmd_desc_element_addr + prdt_offset; 2979 + return 0; 3038 2980 } 3039 2981 3040 2982 /** ··· 3036 3002 { 3037 3003 struct ufs_hba *hba = shost_priv(host); 3038 3004 int tag = scsi_cmd_to_rq(cmd)->tag; 3039 - struct ufshcd_lrb *lrbp; 3040 3005 int err = 0; 3041 3006 struct ufs_hw_queue *hwq = NULL; 3042 3007 ··· 3086 3053 3087 3054 ufshcd_hold(hba); 3088 3055 3089 - lrbp = &hba->lrb[tag]; 3056 + ufshcd_setup_scsi_cmd(hba, cmd, 3057 + ufshcd_scsi_to_upiu_lun(cmd->device->lun), tag); 3090 3058 3091 - ufshcd_setup_scsi_cmd(hba, lrbp, cmd, ufshcd_scsi_to_upiu_lun(cmd->device->lun), tag); 3092 - 3093 - err = ufshcd_map_sg(hba, lrbp); 3059 + err = ufshcd_map_sg(hba, cmd); 3094 3060 if (err) { 3095 3061 ufshcd_release(hba); 3096 3062 goto out; ··· 3098 3066 if (hba->mcq_enabled) 3099 3067 hwq = ufshcd_mcq_req_to_hwq(hba, scsi_cmd_to_rq(cmd)); 3100 3068 3101 - ufshcd_send_command(hba, tag, hwq); 3069 + ufshcd_send_command(hba, cmd, hwq); 3102 3070 3103 3071 out: 3104 3072 if (ufs_trigger_eh(hba)) { ··· 3112 3080 return err; 3113 3081 } 3114 3082 3115 - static void ufshcd_setup_dev_cmd(struct ufs_hba *hba, struct ufshcd_lrb *lrbp, 3116 - enum dev_cmd_type cmd_type, u8 lun, int tag) 3083 + static int ufshcd_queue_reserved_command(struct Scsi_Host *host, 3084 + struct scsi_cmnd *cmd) 3117 3085 { 3118 - __ufshcd_setup_cmd(lrbp, NULL, lun, tag); 3086 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 3087 + struct request *rq = scsi_cmd_to_rq(cmd); 3088 + struct ufs_hba *hba = shost_priv(host); 3089 + struct ufs_hw_queue *hwq = 3090 + hba->mcq_enabled ? ufshcd_mcq_req_to_hwq(hba, rq) : NULL; 3091 + 3092 + ufshcd_add_query_upiu_trace(hba, UFS_QUERY_SEND, lrbp->ucd_req_ptr); 3093 + ufshcd_send_command(hba, cmd, hwq); 3094 + return 0; 3095 + } 3096 + 3097 + static void ufshcd_setup_dev_cmd(struct ufs_hba *hba, struct scsi_cmnd *cmd, 3098 + enum dev_cmd_type cmd_type, u8 lun, int tag) 3099 + { 3100 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 3101 + 3102 + __ufshcd_setup_cmd(hba, cmd, lun, tag); 3119 3103 lrbp->intr_cmd = true; /* No interrupt aggregation */ 3120 3104 hba->dev_cmd.type = cmd_type; 3121 3105 } ··· 3139 3091 /* 3140 3092 * Return: 0 upon success; < 0 upon failure. 3141 3093 */ 3142 - static int ufshcd_compose_dev_cmd(struct ufs_hba *hba, 3143 - struct ufshcd_lrb *lrbp, enum dev_cmd_type cmd_type, int tag) 3094 + static int ufshcd_compose_dev_cmd(struct ufs_hba *hba, struct scsi_cmnd *cmd, 3095 + enum dev_cmd_type cmd_type, int tag) 3144 3096 { 3145 - ufshcd_setup_dev_cmd(hba, lrbp, cmd_type, 0, tag); 3097 + ufshcd_setup_dev_cmd(hba, cmd, cmd_type, 0, tag); 3146 3098 3147 - return ufshcd_compose_devman_upiu(hba, lrbp); 3099 + return ufshcd_compose_devman_upiu(hba, cmd); 3148 3100 } 3149 3101 3150 3102 /* ··· 3255 3207 return err; 3256 3208 } 3257 3209 3258 - /* 3259 - * Return: 0 upon success; > 0 in case the UFS device reported an OCS error; 3260 - * < 0 if another error occurred. 3261 - */ 3262 - static int ufshcd_wait_for_dev_cmd(struct ufs_hba *hba, 3263 - struct ufshcd_lrb *lrbp, int max_timeout) 3264 - { 3265 - unsigned long time_left = msecs_to_jiffies(max_timeout); 3266 - unsigned long flags; 3267 - bool pending; 3268 - int err; 3269 - 3270 - retry: 3271 - time_left = wait_for_completion_timeout(&hba->dev_cmd.complete, 3272 - time_left); 3273 - 3274 - if (likely(time_left)) { 3275 - err = ufshcd_get_tr_ocs(lrbp, NULL); 3276 - if (!err) 3277 - err = ufshcd_dev_cmd_completion(hba, lrbp); 3278 - } else { 3279 - err = -ETIMEDOUT; 3280 - dev_dbg(hba->dev, "%s: dev_cmd request timedout, tag %d\n", 3281 - __func__, lrbp->task_tag); 3282 - 3283 - /* MCQ mode */ 3284 - if (hba->mcq_enabled) { 3285 - /* successfully cleared the command, retry if needed */ 3286 - if (ufshcd_clear_cmd(hba, lrbp->task_tag) == 0) 3287 - err = -EAGAIN; 3288 - return err; 3289 - } 3290 - 3291 - /* SDB mode */ 3292 - if (ufshcd_clear_cmd(hba, lrbp->task_tag) == 0) { 3293 - /* successfully cleared the command, retry if needed */ 3294 - err = -EAGAIN; 3295 - /* 3296 - * Since clearing the command succeeded we also need to 3297 - * clear the task tag bit from the outstanding_reqs 3298 - * variable. 3299 - */ 3300 - spin_lock_irqsave(&hba->outstanding_lock, flags); 3301 - pending = test_bit(lrbp->task_tag, 3302 - &hba->outstanding_reqs); 3303 - if (pending) 3304 - __clear_bit(lrbp->task_tag, 3305 - &hba->outstanding_reqs); 3306 - spin_unlock_irqrestore(&hba->outstanding_lock, flags); 3307 - 3308 - if (!pending) { 3309 - /* 3310 - * The completion handler ran while we tried to 3311 - * clear the command. 3312 - */ 3313 - time_left = 1; 3314 - goto retry; 3315 - } 3316 - } else { 3317 - dev_err(hba->dev, "%s: failed to clear tag %d\n", 3318 - __func__, lrbp->task_tag); 3319 - 3320 - spin_lock_irqsave(&hba->outstanding_lock, flags); 3321 - pending = test_bit(lrbp->task_tag, 3322 - &hba->outstanding_reqs); 3323 - spin_unlock_irqrestore(&hba->outstanding_lock, flags); 3324 - 3325 - if (!pending) { 3326 - /* 3327 - * The completion handler ran while we tried to 3328 - * clear the command. 3329 - */ 3330 - time_left = 1; 3331 - goto retry; 3332 - } 3333 - } 3334 - } 3335 - 3336 - return err; 3337 - } 3338 - 3339 3210 static void ufshcd_dev_man_lock(struct ufs_hba *hba) 3340 3211 { 3341 3212 ufshcd_hold(hba); ··· 3269 3302 ufshcd_release(hba); 3270 3303 } 3271 3304 3305 + static struct scsi_cmnd *ufshcd_get_dev_mgmt_cmd(struct ufs_hba *hba) 3306 + { 3307 + /* 3308 + * The caller must hold this lock to guarantee that the NOWAIT 3309 + * allocation will succeed. 3310 + */ 3311 + lockdep_assert_held(&hba->dev_cmd.lock); 3312 + 3313 + return scsi_get_internal_cmd( 3314 + hba->host->pseudo_sdev, DMA_TO_DEVICE, 3315 + BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT); 3316 + } 3317 + 3318 + static void ufshcd_put_dev_mgmt_cmd(struct scsi_cmnd *cmd) 3319 + { 3320 + scsi_put_internal_cmd(cmd); 3321 + } 3322 + 3272 3323 /* 3273 3324 * Return: 0 upon success; > 0 in case the UFS device reported an OCS error; 3274 3325 * < 0 if another error occurred. 3275 3326 */ 3276 - static int ufshcd_issue_dev_cmd(struct ufs_hba *hba, struct ufshcd_lrb *lrbp, 3277 - const u32 tag, int timeout) 3327 + static int ufshcd_issue_dev_cmd(struct ufs_hba *hba, struct scsi_cmnd *cmd, 3328 + const u32 tag, int timeout) 3278 3329 { 3279 - int err; 3330 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 3331 + struct request *rq = scsi_cmd_to_rq(cmd); 3332 + blk_status_t sts; 3280 3333 3281 - ufshcd_add_query_upiu_trace(hba, UFS_QUERY_SEND, lrbp->ucd_req_ptr); 3282 - ufshcd_send_command(hba, tag, hba->dev_cmd_queue); 3283 - err = ufshcd_wait_for_dev_cmd(hba, lrbp, timeout); 3284 - 3285 - ufshcd_add_query_upiu_trace(hba, err ? UFS_QUERY_ERR : UFS_QUERY_COMP, 3286 - (struct utp_upiu_req *)lrbp->ucd_rsp_ptr); 3287 - 3288 - return err; 3334 + rq->timeout = timeout; 3335 + sts = blk_execute_rq(rq, true); 3336 + if (sts != BLK_STS_OK) 3337 + return blk_status_to_errno(sts); 3338 + return lrbp->utr_descriptor_ptr->header.ocs; 3289 3339 } 3290 3340 3291 3341 /** ··· 3320 3336 static int ufshcd_exec_dev_cmd(struct ufs_hba *hba, 3321 3337 enum dev_cmd_type cmd_type, int timeout) 3322 3338 { 3323 - const u32 tag = hba->reserved_slot; 3324 - struct ufshcd_lrb *lrbp = &hba->lrb[tag]; 3339 + struct scsi_cmnd *cmd = ufshcd_get_dev_mgmt_cmd(hba); 3340 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 3341 + u32 tag; 3325 3342 int err; 3326 3343 3327 - /* Protects use of hba->reserved_slot. */ 3344 + /* Protects use of hba->dev_cmd. */ 3328 3345 lockdep_assert_held(&hba->dev_cmd.lock); 3329 3346 3330 - err = ufshcd_compose_dev_cmd(hba, lrbp, cmd_type, tag); 3331 - if (unlikely(err)) 3332 - return err; 3347 + if (WARN_ON_ONCE(!cmd)) 3348 + return -ENOMEM; 3333 3349 3334 - return ufshcd_issue_dev_cmd(hba, lrbp, tag, timeout); 3350 + tag = scsi_cmd_to_rq(cmd)->tag; 3351 + 3352 + err = ufshcd_compose_dev_cmd(hba, cmd, cmd_type, tag); 3353 + if (unlikely(err)) 3354 + goto out; 3355 + 3356 + err = ufshcd_issue_dev_cmd(hba, cmd, tag, timeout); 3357 + if (err == 0) 3358 + err = ufshcd_dev_cmd_completion(hba, lrbp); 3359 + 3360 + out: 3361 + ufshcd_put_dev_mgmt_cmd(cmd); 3362 + 3363 + return err; 3335 3364 } 3336 3365 3337 3366 /** ··· 3770 3773 * @desc_index: descriptor index 3771 3774 * @buf: pointer to buffer where descriptor would be read, 3772 3775 * the caller should free the memory. 3773 - * @ascii: if true convert from unicode to ascii characters 3774 - * null terminated string. 3776 + * @fmt: if %SD_ASCII_STD, convert from UTF-16 to ASCII 3775 3777 * 3776 3778 * Return: 3777 3779 * * string size on success. 3778 3780 * * -ENOMEM: on allocation failure 3779 3781 * * -EINVAL: on a wrong parameter 3780 3782 */ 3781 - int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, 3782 - u8 **buf, bool ascii) 3783 + int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, u8 **buf, enum ufs_descr_fmt fmt) 3783 3784 { 3784 3785 struct uc_string_id *uc_str; 3785 3786 u8 *str; ··· 3806 3811 goto out; 3807 3812 } 3808 3813 3809 - if (ascii) { 3814 + if (fmt == SD_ASCII_STD) { 3810 3815 ssize_t ascii_len; 3811 3816 int i; 3812 3817 /* remove header and divide by 2 to move from UTF16 to UTF8 */ ··· 3832 3837 str[ret++] = '\0'; 3833 3838 3834 3839 } else { 3835 - str = kmemdup(uc_str, uc_str->len, GFP_KERNEL); 3840 + str = kmemdup(uc_str->uc, uc_str->len, GFP_KERNEL); 3836 3841 if (!str) { 3837 3842 ret = -ENOMEM; 3838 3843 goto out; ··· 3972 3977 } 3973 3978 3974 3979 skip_utmrdl: 3975 - /* Allocate memory for local reference block */ 3976 - hba->lrb = devm_kcalloc(hba->dev, 3977 - hba->nutrs, sizeof(struct ufshcd_lrb), 3978 - GFP_KERNEL); 3979 - if (!hba->lrb) { 3980 - dev_err(hba->dev, "LRB Memory allocation failed\n"); 3981 - goto out; 3982 - } 3983 3980 return 0; 3984 3981 out: 3985 3982 return -ENOMEM; ··· 4033 4046 utrdlp[i].response_upiu_length = 4034 4047 cpu_to_le16(ALIGNED_UPIU_SIZE >> 2); 4035 4048 } 4036 - 4037 - ufshcd_init_lrb(hba, &hba->lrb[i], i); 4038 4049 } 4039 4050 } 4040 4051 ··· 5238 5253 desc_buf[UNIT_DESC_PARAM_LU_WR_PROTECT] == UFS_LU_POWER_ON_WP) 5239 5254 hba->dev_info.is_lu_power_on_wp = true; 5240 5255 5241 - /* In case of RPMB LU, check if advanced RPMB mode is enabled */ 5242 - if (desc_buf[UNIT_DESC_PARAM_UNIT_INDEX] == UFS_UPIU_RPMB_WLUN && 5243 - desc_buf[RPMB_UNIT_DESC_PARAM_REGION_EN] & BIT(4)) 5244 - hba->dev_info.b_advanced_rpmb_en = true; 5256 + /* In case of RPMB LU, check if advanced RPMB mode is enabled, and get region size */ 5257 + if (desc_buf[UNIT_DESC_PARAM_UNIT_INDEX] == UFS_UPIU_RPMB_WLUN) { 5258 + if (desc_buf[RPMB_UNIT_DESC_PARAM_REGION_EN] & BIT(4)) 5259 + hba->dev_info.b_advanced_rpmb_en = true; 5260 + hba->dev_info.rpmb_region_size[0] = desc_buf[RPMB_UNIT_DESC_PARAM_REGION0_SIZE]; 5261 + hba->dev_info.rpmb_region_size[1] = desc_buf[RPMB_UNIT_DESC_PARAM_REGION1_SIZE]; 5262 + hba->dev_info.rpmb_region_size[2] = desc_buf[RPMB_UNIT_DESC_PARAM_REGION2_SIZE]; 5263 + hba->dev_info.rpmb_region_size[3] = desc_buf[RPMB_UNIT_DESC_PARAM_REGION3_SIZE]; 5264 + } 5245 5265 5246 5266 5247 5267 kfree(desc_buf); ··· 5386 5396 5387 5397 /** 5388 5398 * ufshcd_scsi_cmd_status - Update SCSI command result based on SCSI status 5389 - * @lrbp: pointer to local reference block of completed command 5399 + * @cmd: SCSI command 5390 5400 * @scsi_status: SCSI command status 5391 5401 * 5392 5402 * Return: value base on SCSI command status. 5393 5403 */ 5394 - static inline int 5395 - ufshcd_scsi_cmd_status(struct ufshcd_lrb *lrbp, int scsi_status) 5404 + static inline int ufshcd_scsi_cmd_status(struct scsi_cmnd *cmd, int scsi_status) 5396 5405 { 5397 5406 int result = 0; 5398 5407 5399 5408 switch (scsi_status) { 5400 5409 case SAM_STAT_CHECK_CONDITION: 5401 - ufshcd_copy_sense_data(lrbp); 5410 + ufshcd_copy_sense_data(cmd); 5402 5411 fallthrough; 5403 5412 case SAM_STAT_GOOD: 5404 5413 result |= DID_OK << 16 | scsi_status; ··· 5405 5416 case SAM_STAT_TASK_SET_FULL: 5406 5417 case SAM_STAT_BUSY: 5407 5418 case SAM_STAT_TASK_ABORTED: 5408 - ufshcd_copy_sense_data(lrbp); 5419 + ufshcd_copy_sense_data(cmd); 5409 5420 result |= scsi_status; 5410 5421 break; 5411 5422 default: ··· 5419 5430 /** 5420 5431 * ufshcd_transfer_rsp_status - Get overall status of the response 5421 5432 * @hba: per adapter instance 5422 - * @lrbp: pointer to local reference block of completed command 5433 + * @cmd: SCSI command 5423 5434 * @cqe: pointer to the completion queue entry 5424 5435 * 5425 5436 * Return: result of the command to notify SCSI midlayer. 5426 5437 */ 5427 - static inline int 5428 - ufshcd_transfer_rsp_status(struct ufs_hba *hba, struct ufshcd_lrb *lrbp, 5429 - struct cq_entry *cqe) 5438 + static inline int ufshcd_transfer_rsp_status(struct ufs_hba *hba, 5439 + struct scsi_cmnd *cmd, 5440 + struct cq_entry *cqe) 5430 5441 { 5442 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 5443 + const int tag = scsi_cmd_to_rq(cmd)->tag; 5431 5444 int result = 0; 5432 5445 int scsi_status; 5433 5446 enum utp_ocs ocs; ··· 5443 5452 * not set either flag. 5444 5453 */ 5445 5454 if (resid && !(upiu_flags & UPIU_RSP_FLAG_OVERFLOW)) 5446 - scsi_set_resid(lrbp->cmd, resid); 5455 + scsi_set_resid(cmd, resid); 5447 5456 5448 5457 /* overall command status of utrd */ 5449 5458 ocs = ufshcd_get_tr_ocs(lrbp, cqe); ··· 5464 5473 * to notify the SCSI midlayer of the command status 5465 5474 */ 5466 5475 scsi_status = lrbp->ucd_rsp_ptr->header.status; 5467 - result = ufshcd_scsi_cmd_status(lrbp, scsi_status); 5476 + result = ufshcd_scsi_cmd_status(cmd, scsi_status); 5468 5477 5469 5478 /* 5470 5479 * Currently we are only supporting BKOPs exception ··· 5501 5510 case OCS_ABORTED: 5502 5511 case OCS_INVALID_COMMAND_STATUS: 5503 5512 result |= DID_REQUEUE << 16; 5504 - dev_warn(hba->dev, 5505 - "OCS %s from controller for tag %d\n", 5506 - (ocs == OCS_ABORTED ? "aborted" : "invalid"), 5507 - lrbp->task_tag); 5513 + dev_warn(hba->dev, "OCS %s from controller for tag %d\n", 5514 + ocs == OCS_ABORTED ? "aborted" : "invalid", tag); 5508 5515 break; 5509 5516 case OCS_INVALID_CMD_TABLE_ATTR: 5510 5517 case OCS_INVALID_PRDT_ATTR: ··· 5515 5526 case OCS_GENERAL_CRYPTO_ERROR: 5516 5527 default: 5517 5528 result |= DID_ERROR << 16; 5518 - dev_err(hba->dev, 5519 - "OCS error from controller = %x for tag %d\n", 5520 - ocs, lrbp->task_tag); 5529 + dev_err(hba->dev, "OCS error from controller = %x for tag %d\n", 5530 + ocs, tag); 5521 5531 ufshcd_print_evt_hist(hba); 5522 5532 ufshcd_print_host_state(hba); 5523 5533 break; 5524 5534 } /* end of switch */ 5525 5535 5526 5536 if ((host_byte(result) != DID_OK) && 5527 - (host_byte(result) != DID_REQUEUE) && !hba->silence_err_logs) 5528 - ufshcd_print_tr(hba, lrbp->task_tag, true); 5537 + (host_byte(result) != DID_REQUEUE) && !hba->silence_err_logs) { 5538 + if (cqe) 5539 + ufshcd_hex_dump("UPIU CQE: ", cqe, sizeof(struct cq_entry)); 5540 + ufshcd_print_tr(hba, cmd, true); 5541 + } 5529 5542 return result; 5530 5543 } 5531 5544 ··· 5566 5575 guard(spinlock_irqsave)(hba->host->host_lock); 5567 5576 cmd = hba->active_uic_cmd; 5568 5577 if (!cmd) 5569 - goto unlock; 5578 + return retval; 5570 5579 5571 5580 if (ufshcd_is_auto_hibern8_error(hba, intr_status)) 5572 5581 hba->errors |= (UFSHCD_UIC_HIBERN8_MASK & intr_status); ··· 5575 5584 cmd->argument2 |= ufshcd_get_uic_cmd_result(hba); 5576 5585 cmd->argument3 = ufshcd_get_dme_attr_val(hba); 5577 5586 if (!hba->uic_async_done) 5578 - cmd->cmd_active = 0; 5587 + cmd->cmd_active = false; 5579 5588 complete(&cmd->done); 5580 5589 retval = IRQ_HANDLED; 5581 5590 } 5582 5591 5583 5592 if (intr_status & UFSHCD_UIC_PWR_MASK && hba->uic_async_done) { 5584 - cmd->cmd_active = 0; 5593 + cmd->cmd_active = false; 5585 5594 complete(hba->uic_async_done); 5586 5595 retval = IRQ_HANDLED; 5587 5596 } ··· 5589 5598 if (retval == IRQ_HANDLED) 5590 5599 ufshcd_add_uic_command_trace(hba, cmd, UFS_CMD_COMP); 5591 5600 5592 - unlock: 5593 5601 return retval; 5594 5602 } 5595 5603 5596 5604 /* Release the resources allocated for processing a SCSI command. */ 5597 - void ufshcd_release_scsi_cmd(struct ufs_hba *hba, 5598 - struct ufshcd_lrb *lrbp) 5605 + void ufshcd_release_scsi_cmd(struct ufs_hba *hba, struct scsi_cmnd *cmd) 5599 5606 { 5600 - struct scsi_cmnd *cmd = lrbp->cmd; 5601 - 5602 5607 scsi_dma_unmap(cmd); 5603 - ufshcd_crypto_clear_prdt(hba, lrbp); 5608 + ufshcd_crypto_clear_prdt(hba, cmd); 5604 5609 ufshcd_release(hba); 5605 5610 ufshcd_clk_scaling_update_busy(hba); 5606 5611 } ··· 5610 5623 void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag, 5611 5624 struct cq_entry *cqe) 5612 5625 { 5613 - struct ufshcd_lrb *lrbp; 5614 - struct scsi_cmnd *cmd; 5626 + struct scsi_cmnd *cmd = ufshcd_tag_to_cmd(hba, task_tag); 5627 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 5615 5628 enum utp_ocs ocs; 5616 5629 5617 - lrbp = &hba->lrb[task_tag]; 5630 + if (WARN_ONCE(!cmd, "cqe->command_desc_base_addr = %#llx\n", 5631 + le64_to_cpu(cqe->command_desc_base_addr))) 5632 + return; 5633 + 5618 5634 if (hba->monitor.enabled) { 5619 5635 lrbp->compl_time_stamp = ktime_get(); 5620 5636 lrbp->compl_time_stamp_local_clock = local_clock(); 5621 5637 } 5622 - cmd = lrbp->cmd; 5623 - if (cmd) { 5624 - if (unlikely(ufshcd_should_inform_monitor(hba, lrbp))) 5625 - ufshcd_update_monitor(hba, lrbp); 5626 - ufshcd_add_command_trace(hba, task_tag, UFS_CMD_COMP); 5627 - cmd->result = ufshcd_transfer_rsp_status(hba, lrbp, cqe); 5628 - ufshcd_release_scsi_cmd(hba, lrbp); 5629 - /* Do not touch lrbp after scsi done */ 5630 - scsi_done(cmd); 5638 + if (ufshcd_is_scsi_cmd(cmd)) { 5639 + if (unlikely(ufshcd_should_inform_monitor(hba, cmd))) 5640 + ufshcd_update_monitor(hba, cmd); 5641 + ufshcd_add_command_trace(hba, cmd, UFS_CMD_COMP); 5642 + cmd->result = ufshcd_transfer_rsp_status(hba, cmd, cqe); 5643 + ufshcd_release_scsi_cmd(hba, cmd); 5631 5644 } else { 5632 5645 if (cqe) { 5633 - ocs = le32_to_cpu(cqe->status) & MASK_OCS; 5646 + ocs = cqe->overall_status & MASK_OCS; 5634 5647 lrbp->utr_descriptor_ptr->header.ocs = ocs; 5648 + } else { 5649 + ocs = lrbp->utr_descriptor_ptr->header.ocs; 5635 5650 } 5636 - complete(&hba->dev_cmd.complete); 5651 + ufshcd_add_query_upiu_trace( 5652 + hba, 5653 + ocs == OCS_SUCCESS ? UFS_QUERY_COMP : UFS_QUERY_ERR, 5654 + (struct utp_upiu_req *)lrbp->ucd_rsp_ptr); 5655 + cmd->result = 0; 5637 5656 } 5657 + /* Do not touch lrbp after scsi_done() has been called. */ 5658 + scsi_done(cmd); 5638 5659 } 5639 5660 5640 5661 /** ··· 5670 5675 int tag; 5671 5676 5672 5677 for_each_set_bit(tag, completed_reqs, hba->nutrs) { 5673 - struct scsi_cmnd *cmd = hba->lrb[tag].cmd; 5678 + struct scsi_cmnd *cmd = scsi_host_find_tag(hba->host, tag); 5674 5679 5675 5680 if (!cmd) 5676 5681 continue; ··· 5715 5720 return completed_reqs != 0; 5716 5721 } 5717 5722 5723 + static bool ufshcd_mcq_force_compl_one(struct request *rq, void *priv) 5724 + { 5725 + struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); 5726 + struct scsi_device *sdev = rq->q->queuedata; 5727 + struct Scsi_Host *shost = sdev->host; 5728 + struct ufs_hba *hba = shost_priv(shost); 5729 + struct ufs_hw_queue *hwq = ufshcd_mcq_req_to_hwq(hba, rq); 5730 + 5731 + if (blk_mq_is_reserved_rq(rq) || !hwq) 5732 + return true; 5733 + 5734 + ufshcd_mcq_compl_all_cqes_lock(hba, hwq); 5735 + 5736 + /* 5737 + * For those cmds of which the cqes are not present in the cq, complete 5738 + * them explicitly. 5739 + */ 5740 + scoped_guard(spinlock_irqsave, &hwq->cq_lock) { 5741 + if (!test_bit(SCMD_STATE_COMPLETE, &cmd->state)) { 5742 + set_host_byte(cmd, DID_REQUEUE); 5743 + ufshcd_release_scsi_cmd(hba, cmd); 5744 + scsi_done(cmd); 5745 + } 5746 + } 5747 + 5748 + return true; 5749 + } 5750 + 5751 + static bool ufshcd_mcq_compl_one(struct request *rq, void *priv) 5752 + { 5753 + struct scsi_device *sdev = rq->q->queuedata; 5754 + struct Scsi_Host *shost = sdev->host; 5755 + struct ufs_hba *hba = shost_priv(shost); 5756 + struct ufs_hw_queue *hwq = ufshcd_mcq_req_to_hwq(hba, rq); 5757 + 5758 + if (!blk_mq_is_reserved_rq(rq) && hwq) 5759 + ufshcd_mcq_poll_cqe_lock(hba, hwq); 5760 + 5761 + return true; 5762 + } 5763 + 5718 5764 /** 5719 5765 * ufshcd_mcq_compl_pending_transfer - MCQ mode function. It is 5720 5766 * invoked from the error handler context or ufshcd_host_reset_and_restore() ··· 5770 5734 static void ufshcd_mcq_compl_pending_transfer(struct ufs_hba *hba, 5771 5735 bool force_compl) 5772 5736 { 5773 - struct ufs_hw_queue *hwq; 5774 - struct ufshcd_lrb *lrbp; 5775 - struct scsi_cmnd *cmd; 5776 - unsigned long flags; 5777 - int tag; 5778 - 5779 - for (tag = 0; tag < hba->nutrs; tag++) { 5780 - lrbp = &hba->lrb[tag]; 5781 - cmd = lrbp->cmd; 5782 - if (!ufshcd_cmd_inflight(cmd) || 5783 - test_bit(SCMD_STATE_COMPLETE, &cmd->state)) 5784 - continue; 5785 - 5786 - hwq = ufshcd_mcq_req_to_hwq(hba, scsi_cmd_to_rq(cmd)); 5787 - if (!hwq) 5788 - continue; 5789 - 5790 - if (force_compl) { 5791 - ufshcd_mcq_compl_all_cqes_lock(hba, hwq); 5792 - /* 5793 - * For those cmds of which the cqes are not present 5794 - * in the cq, complete them explicitly. 5795 - */ 5796 - spin_lock_irqsave(&hwq->cq_lock, flags); 5797 - if (cmd && !test_bit(SCMD_STATE_COMPLETE, &cmd->state)) { 5798 - set_host_byte(cmd, DID_REQUEUE); 5799 - ufshcd_release_scsi_cmd(hba, lrbp); 5800 - scsi_done(cmd); 5801 - } 5802 - spin_unlock_irqrestore(&hwq->cq_lock, flags); 5803 - } else { 5804 - ufshcd_mcq_poll_cqe_lock(hba, hwq); 5805 - } 5806 - } 5737 + blk_mq_tagset_busy_iter(&hba->host->tag_set, 5738 + force_compl ? ufshcd_mcq_force_compl_one : 5739 + ufshcd_mcq_compl_one, 5740 + NULL); 5807 5741 } 5808 5742 5809 5743 /** ··· 6618 6612 struct Scsi_Host *shost = sdev->host; 6619 6613 struct ufs_hba *hba = shost_priv(shost); 6620 6614 6615 + if (blk_mq_is_reserved_rq(rq)) 6616 + return true; 6617 + 6621 6618 *ret = ufshcd_try_to_abort_task(hba, tag); 6622 6619 dev_err(hba->dev, "Aborting tag %d / CDB %#02x %s\n", tag, 6623 - hba->lrb[tag].cmd ? hba->lrb[tag].cmd->cmnd[0] : -1, 6620 + ufshcd_is_scsi_cmd(cmd) ? cmd->cmnd[0] : -1, 6624 6621 *ret ? "failed" : "succeeded"); 6625 6622 6626 6623 return *ret == 0; ··· 7358 7349 enum dev_cmd_type cmd_type, 7359 7350 enum query_opcode desc_op) 7360 7351 { 7361 - const u32 tag = hba->reserved_slot; 7362 - struct ufshcd_lrb *lrbp = &hba->lrb[tag]; 7352 + struct scsi_cmnd *cmd = ufshcd_get_dev_mgmt_cmd(hba); 7353 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 7354 + u32 tag; 7363 7355 int err = 0; 7364 7356 u8 upiu_flags; 7365 7357 7366 - /* Protects use of hba->reserved_slot. */ 7358 + /* Protects use of hba->dev_cmd. */ 7367 7359 lockdep_assert_held(&hba->dev_cmd.lock); 7368 7360 7369 - ufshcd_setup_dev_cmd(hba, lrbp, cmd_type, 0, tag); 7361 + if (WARN_ON_ONCE(!cmd)) 7362 + return -ENOMEM; 7363 + 7364 + tag = scsi_cmd_to_rq(cmd)->tag; 7365 + 7366 + ufshcd_setup_dev_cmd(hba, cmd, cmd_type, 0, tag); 7370 7367 7371 7368 ufshcd_prepare_req_desc_hdr(hba, lrbp, &upiu_flags, DMA_NONE, 0); 7372 7369 ··· 7392 7377 7393 7378 memset(lrbp->ucd_rsp_ptr, 0, sizeof(struct utp_upiu_rsp)); 7394 7379 7395 - /* 7396 - * ignore the returning value here - ufshcd_check_query_response is 7397 - * bound to fail since dev_cmd.query and dev_cmd.type were left empty. 7398 - * read the response directly ignoring all errors. 7399 - */ 7400 - ufshcd_issue_dev_cmd(hba, lrbp, tag, dev_cmd_timeout); 7380 + err = ufshcd_issue_dev_cmd(hba, cmd, tag, dev_cmd_timeout); 7381 + if (err) 7382 + goto put_dev_mgmt_cmd; 7401 7383 7402 7384 /* just copy the upiu response as it is */ 7403 7385 memcpy(rsp_upiu, lrbp->ucd_rsp_ptr, sizeof(*rsp_upiu)); ··· 7414 7402 err = -EINVAL; 7415 7403 } 7416 7404 } 7405 + 7406 + put_dev_mgmt_cmd: 7407 + ufshcd_put_dev_mgmt_cmd(cmd); 7417 7408 7418 7409 return err; 7419 7410 } ··· 7511 7496 struct ufs_ehs *rsp_ehs, int sg_cnt, struct scatterlist *sg_list, 7512 7497 enum dma_data_direction dir) 7513 7498 { 7514 - const u32 tag = hba->reserved_slot; 7515 - struct ufshcd_lrb *lrbp = &hba->lrb[tag]; 7499 + struct scsi_cmnd *cmd; 7500 + struct ufshcd_lrb *lrbp; 7501 + u32 tag; 7516 7502 int err = 0; 7517 7503 int result; 7518 7504 u8 upiu_flags; ··· 7521 7505 u16 ehs_len; 7522 7506 int ehs = (hba->capabilities & MASK_EHSLUTRD_SUPPORTED) ? 2 : 0; 7523 7507 7524 - /* Protects use of hba->reserved_slot. */ 7525 7508 ufshcd_dev_man_lock(hba); 7526 7509 7527 - ufshcd_setup_dev_cmd(hba, lrbp, DEV_CMD_TYPE_RPMB, UFS_UPIU_RPMB_WLUN, tag); 7510 + cmd = ufshcd_get_dev_mgmt_cmd(hba); 7511 + 7512 + if (WARN_ON_ONCE(!cmd)) { 7513 + err = -ENOMEM; 7514 + goto unlock; 7515 + } 7516 + 7517 + lrbp = scsi_cmd_priv(cmd); 7518 + tag = scsi_cmd_to_rq(cmd)->tag; 7519 + 7520 + ufshcd_setup_dev_cmd(hba, cmd, DEV_CMD_TYPE_RPMB, UFS_UPIU_RPMB_WLUN, 7521 + tag); 7528 7522 7529 7523 ufshcd_prepare_req_desc_hdr(hba, lrbp, &upiu_flags, DMA_NONE, ehs); 7530 7524 ··· 7551 7525 7552 7526 memset(lrbp->ucd_rsp_ptr, 0, sizeof(struct utp_upiu_rsp)); 7553 7527 7554 - err = ufshcd_issue_dev_cmd(hba, lrbp, tag, ADVANCED_RPMB_REQ_TIMEOUT); 7528 + err = ufshcd_issue_dev_cmd(hba, cmd, tag, ADVANCED_RPMB_REQ_TIMEOUT); 7529 + if (err) 7530 + goto put_dev_mgmt_cmd; 7555 7531 7532 + err = ufshcd_dev_cmd_completion(hba, lrbp); 7556 7533 if (!err) { 7557 7534 /* Just copy the upiu response as it is */ 7558 7535 memcpy(rsp_upiu, lrbp->ucd_rsp_ptr, sizeof(*rsp_upiu)); ··· 7579 7550 } 7580 7551 } 7581 7552 7553 + put_dev_mgmt_cmd: 7554 + ufshcd_put_dev_mgmt_cmd(cmd); 7555 + 7556 + unlock: 7582 7557 ufshcd_dev_man_unlock(hba); 7583 7558 7584 7559 return err ? : result; 7560 + } 7561 + 7562 + static bool ufshcd_clear_lu_cmds(struct request *req, void *priv) 7563 + { 7564 + struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req); 7565 + struct scsi_device *sdev = cmd->device; 7566 + struct Scsi_Host *shost = sdev->host; 7567 + struct ufs_hba *hba = shost_priv(shost); 7568 + const u64 lun = *(u64 *)priv; 7569 + const u32 tag = req->tag; 7570 + 7571 + if (blk_mq_is_reserved_rq(req) || sdev->lun != lun) 7572 + return true; 7573 + 7574 + if (ufshcd_clear_cmd(hba, tag) < 0) { 7575 + dev_err(hba->dev, "%s: failed to clear request %d\n", __func__, 7576 + tag); 7577 + return true; 7578 + } 7579 + 7580 + if (hba->mcq_enabled) { 7581 + struct ufs_hw_queue *hwq = ufshcd_mcq_req_to_hwq(hba, req); 7582 + 7583 + if (hwq) 7584 + ufshcd_mcq_poll_cqe_lock(hba, hwq); 7585 + return true; 7586 + } 7587 + 7588 + ufshcd_compl_one_cqe(hba, tag, NULL); 7589 + return true; 7585 7590 } 7586 7591 7587 7592 /** ··· 7626 7563 */ 7627 7564 static int ufshcd_eh_device_reset_handler(struct scsi_cmnd *cmd) 7628 7565 { 7629 - unsigned long flags, pending_reqs = 0, not_cleared = 0; 7630 7566 struct Scsi_Host *host; 7631 7567 struct ufs_hba *hba; 7632 - struct ufs_hw_queue *hwq; 7633 - struct ufshcd_lrb *lrbp; 7634 - u32 pos, not_cleared_mask = 0; 7635 7568 int err; 7636 7569 u8 resp = 0xF, lun; 7637 7570 ··· 7636 7577 7637 7578 lun = ufshcd_scsi_to_upiu_lun(cmd->device->lun); 7638 7579 err = ufshcd_issue_tm_cmd(hba, lun, 0, UFS_LOGICAL_RESET, &resp); 7639 - if (err || resp != UPIU_TASK_MANAGEMENT_FUNC_COMPL) { 7640 - if (!err) 7641 - err = resp; 7642 - goto out; 7580 + if (err) { 7581 + } else if (resp != UPIU_TASK_MANAGEMENT_FUNC_COMPL) { 7582 + err = resp; 7583 + } else { 7584 + /* clear the commands that were pending for corresponding LUN */ 7585 + blk_mq_tagset_busy_iter(&hba->host->tag_set, 7586 + ufshcd_clear_lu_cmds, 7587 + &cmd->device->lun); 7643 7588 } 7644 7589 7645 - if (hba->mcq_enabled) { 7646 - for (pos = 0; pos < hba->nutrs; pos++) { 7647 - lrbp = &hba->lrb[pos]; 7648 - if (ufshcd_cmd_inflight(lrbp->cmd) && 7649 - lrbp->lun == lun) { 7650 - ufshcd_clear_cmd(hba, pos); 7651 - hwq = ufshcd_mcq_req_to_hwq(hba, scsi_cmd_to_rq(lrbp->cmd)); 7652 - ufshcd_mcq_poll_cqe_lock(hba, hwq); 7653 - } 7654 - } 7655 - err = 0; 7656 - goto out; 7657 - } 7658 - 7659 - /* clear the commands that were pending for corresponding LUN */ 7660 - spin_lock_irqsave(&hba->outstanding_lock, flags); 7661 - for_each_set_bit(pos, &hba->outstanding_reqs, hba->nutrs) 7662 - if (hba->lrb[pos].lun == lun) 7663 - __set_bit(pos, &pending_reqs); 7664 - hba->outstanding_reqs &= ~pending_reqs; 7665 - spin_unlock_irqrestore(&hba->outstanding_lock, flags); 7666 - 7667 - for_each_set_bit(pos, &pending_reqs, hba->nutrs) { 7668 - if (ufshcd_clear_cmd(hba, pos) < 0) { 7669 - spin_lock_irqsave(&hba->outstanding_lock, flags); 7670 - not_cleared = 1U << pos & 7671 - ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL); 7672 - hba->outstanding_reqs |= not_cleared; 7673 - not_cleared_mask |= not_cleared; 7674 - spin_unlock_irqrestore(&hba->outstanding_lock, flags); 7675 - 7676 - dev_err(hba->dev, "%s: failed to clear request %d\n", 7677 - __func__, pos); 7678 - } 7679 - } 7680 - __ufshcd_transfer_req_compl(hba, pending_reqs & ~not_cleared_mask); 7681 - 7682 - out: 7683 7590 hba->req_abort_count = 0; 7684 7591 ufshcd_update_evt_hist(hba, UFS_EVT_DEV_RESET, (u32)err); 7685 7592 if (!err) { ··· 7659 7634 7660 7635 static void ufshcd_set_req_abort_skip(struct ufs_hba *hba, unsigned long bitmap) 7661 7636 { 7662 - struct ufshcd_lrb *lrbp; 7663 7637 int tag; 7664 7638 7665 7639 for_each_set_bit(tag, &bitmap, hba->nutrs) { 7666 - lrbp = &hba->lrb[tag]; 7640 + struct scsi_cmnd *cmd = ufshcd_tag_to_cmd(hba, tag); 7641 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 7642 + 7667 7643 lrbp->req_abort_skip = true; 7668 7644 } 7669 7645 } ··· 7672 7646 /** 7673 7647 * ufshcd_try_to_abort_task - abort a specific task 7674 7648 * @hba: Pointer to adapter instance 7675 - * @tag: Task tag/index to be aborted 7649 + * @tag: Tag of the task to be aborted 7676 7650 * 7677 7651 * Abort the pending command in device by sending UFS_ABORT_TASK task management 7678 7652 * command, and in host controller by clearing the door-bell register. There can ··· 7684 7658 */ 7685 7659 int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag) 7686 7660 { 7687 - struct ufshcd_lrb *lrbp = &hba->lrb[tag]; 7661 + struct scsi_cmnd *cmd = ufshcd_tag_to_cmd(hba, tag); 7662 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 7688 7663 int err; 7689 7664 int poll_cnt; 7690 7665 u8 resp = 0xF; 7691 7666 7692 7667 for (poll_cnt = 100; poll_cnt; poll_cnt--) { 7693 - err = ufshcd_issue_tm_cmd(hba, lrbp->lun, lrbp->task_tag, 7694 - UFS_QUERY_TASK, &resp); 7668 + err = ufshcd_issue_tm_cmd(hba, lrbp->lun, tag, UFS_QUERY_TASK, 7669 + &resp); 7695 7670 if (!err && resp == UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED) { 7696 7671 /* cmd pending in the device */ 7697 7672 dev_err(hba->dev, "%s: cmd pending in the device. tag = %d\n", ··· 7707 7680 hba->dev, 7708 7681 "%s: cmd with tag %d not pending in the device.\n", 7709 7682 __func__, tag); 7710 - if (!ufshcd_cmd_inflight(lrbp->cmd)) { 7683 + if (!ufshcd_cmd_inflight(cmd)) { 7711 7684 dev_info(hba->dev, 7712 7685 "%s: cmd with tag=%d completed.\n", 7713 7686 __func__, tag); ··· 7725 7698 if (!poll_cnt) 7726 7699 return -EBUSY; 7727 7700 7728 - err = ufshcd_issue_tm_cmd(hba, lrbp->lun, lrbp->task_tag, 7729 - UFS_ABORT_TASK, &resp); 7701 + err = ufshcd_issue_tm_cmd(hba, lrbp->lun, tag, UFS_ABORT_TASK, &resp); 7730 7702 if (err || resp != UPIU_TASK_MANAGEMENT_FUNC_COMPL) { 7731 7703 if (!err) { 7732 7704 err = resp; /* service response error */ ··· 7753 7727 { 7754 7728 struct Scsi_Host *host = cmd->device->host; 7755 7729 struct ufs_hba *hba = shost_priv(host); 7756 - int tag = scsi_cmd_to_rq(cmd)->tag; 7757 - struct ufshcd_lrb *lrbp = &hba->lrb[tag]; 7730 + struct request *rq = scsi_cmd_to_rq(cmd); 7731 + int tag = rq->tag; 7732 + struct ufshcd_lrb *lrbp = scsi_cmd_priv(cmd); 7758 7733 unsigned long flags; 7759 7734 int err = FAILED; 7760 7735 bool outstanding; ··· 7784 7757 * to reduce repeated printouts. For other aborted requests only print 7785 7758 * basic details. 7786 7759 */ 7787 - scsi_print_command(cmd); 7760 + if (ufshcd_is_scsi_cmd(cmd)) 7761 + scsi_print_command(cmd); 7788 7762 if (!hba->req_abort_count) { 7789 7763 ufshcd_update_evt_hist(hba, UFS_EVT_ABORT, tag); 7790 7764 ufshcd_print_evt_hist(hba); 7791 7765 ufshcd_print_host_state(hba); 7792 7766 ufshcd_print_pwr_info(hba); 7793 - ufshcd_print_tr(hba, tag, true); 7767 + ufshcd_print_tr(hba, cmd, true); 7794 7768 } else { 7795 - ufshcd_print_tr(hba, tag, false); 7769 + ufshcd_print_tr(hba, cmd, false); 7796 7770 } 7797 7771 hba->req_abort_count++; 7798 7772 ··· 7837 7809 goto release; 7838 7810 } 7839 7811 7840 - err = ufshcd_try_to_abort_task(hba, tag); 7812 + if (blk_mq_is_reserved_rq(rq)) 7813 + err = ufshcd_clear_cmd(hba, tag); 7814 + else 7815 + err = ufshcd_try_to_abort_task(hba, tag); 7841 7816 if (err) { 7842 7817 dev_err(hba->dev, "%s: failed with err %d\n", __func__, err); 7843 7818 ufshcd_set_req_abort_skip(hba, hba->outstanding_reqs); ··· 7857 7826 spin_unlock_irqrestore(&hba->outstanding_lock, flags); 7858 7827 7859 7828 if (outstanding) 7860 - ufshcd_release_scsi_cmd(hba, lrbp); 7829 + ufshcd_release_scsi_cmd(hba, cmd); 7861 7830 7862 7831 err = SUCCESS; 7863 7832 ··· 8223 8192 ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_RPMB_WLUN), NULL); 8224 8193 if (IS_ERR(sdev_rpmb)) { 8225 8194 ret = PTR_ERR(sdev_rpmb); 8195 + hba->ufs_rpmb_wlun = NULL; 8196 + dev_err(hba->dev, "%s: RPMB WLUN not found\n", __func__); 8226 8197 goto remove_ufs_device_wlun; 8227 8198 } 8199 + hba->ufs_rpmb_wlun = sdev_rpmb; 8228 8200 ufshcd_blk_pm_runtime_init(sdev_rpmb); 8229 8201 scsi_device_put(sdev_rpmb); 8230 8202 ··· 8495 8461 dev_info->rtc_update_period = 0; 8496 8462 } 8497 8463 8464 + /** 8465 + * ufshcd_create_device_id - Generate unique device identifier string 8466 + * @hba: per-adapter instance 8467 + * @desc_buf: device descriptor buffer 8468 + * 8469 + * Creates a unique device ID string combining manufacturer ID, spec version, 8470 + * model name, serial number (as hex), device version, and manufacture date. 8471 + * 8472 + * Returns: Allocated device ID string on success, NULL on failure 8473 + */ 8474 + static char *ufshcd_create_device_id(struct ufs_hba *hba, u8 *desc_buf) 8475 + { 8476 + struct ufs_dev_info *dev_info = &hba->dev_info; 8477 + u16 manufacture_date; 8478 + u16 device_version; 8479 + u8 *serial_number; 8480 + char *serial_hex; 8481 + char *device_id; 8482 + u8 serial_index; 8483 + int serial_len; 8484 + int ret; 8485 + 8486 + serial_index = desc_buf[DEVICE_DESC_PARAM_SN]; 8487 + 8488 + ret = ufshcd_read_string_desc(hba, serial_index, &serial_number, SD_RAW); 8489 + if (ret < 0) { 8490 + dev_err(hba->dev, "Failed reading Serial Number. err = %d\n", ret); 8491 + return NULL; 8492 + } 8493 + 8494 + device_version = get_unaligned_be16(&desc_buf[DEVICE_DESC_PARAM_DEV_VER]); 8495 + manufacture_date = get_unaligned_be16(&desc_buf[DEVICE_DESC_PARAM_MANF_DATE]); 8496 + 8497 + serial_len = ret; 8498 + /* Allocate buffer for hex string: 2 chars per byte + null terminator */ 8499 + serial_hex = kzalloc(serial_len * 2 + 1, GFP_KERNEL); 8500 + if (!serial_hex) { 8501 + kfree(serial_number); 8502 + return NULL; 8503 + } 8504 + 8505 + bin2hex(serial_hex, serial_number, serial_len); 8506 + 8507 + /* 8508 + * Device ID format is ABI with secure world - do not change without firmware 8509 + * coordination. 8510 + */ 8511 + device_id = kasprintf(GFP_KERNEL, "%04X-%04X-%s-%s-%04X-%04X", 8512 + dev_info->wmanufacturerid, dev_info->wspecversion, 8513 + dev_info->model, serial_hex, device_version, 8514 + manufacture_date); 8515 + 8516 + kfree(serial_hex); 8517 + kfree(serial_number); 8518 + 8519 + if (!device_id) 8520 + dev_warn(hba->dev, "Failed to allocate unique device ID\n"); 8521 + 8522 + return device_id; 8523 + } 8524 + 8498 8525 static int ufs_get_device_desc(struct ufs_hba *hba) 8499 8526 { 8527 + struct ufs_dev_info *dev_info = &hba->dev_info; 8528 + struct Scsi_Host *shost = hba->host; 8500 8529 int err; 8501 8530 u8 model_index; 8502 8531 u8 *desc_buf; 8503 - struct ufs_dev_info *dev_info = &hba->dev_info; 8504 8532 8505 8533 desc_buf = kzalloc(QUERY_DESC_MAX_SIZE, GFP_KERNEL); 8506 8534 if (!desc_buf) { ··· 8590 8494 desc_buf[DEVICE_DESC_PARAM_SPEC_VER + 1]; 8591 8495 dev_info->bqueuedepth = desc_buf[DEVICE_DESC_PARAM_Q_DPTH]; 8592 8496 8497 + /* 8498 + * According to the UFS standard, the UFS device queue depth 8499 + * (bQueueDepth) must be in the range 1..255 if the shared queueing 8500 + * architecture is supported. bQueueDepth is zero if the shared queueing 8501 + * architecture is not supported. 8502 + */ 8503 + if (dev_info->bqueuedepth) 8504 + shost->cmd_per_lun = min(hba->nutrs, dev_info->bqueuedepth) - 8505 + UFSHCD_NUM_RESERVED; 8506 + else 8507 + shost->cmd_per_lun = shost->can_queue; 8508 + 8593 8509 dev_info->rtt_cap = desc_buf[DEVICE_DESC_PARAM_RTT_CAP]; 8594 8510 8595 8511 dev_info->hid_sup = get_unaligned_be32(desc_buf + ··· 8617 8509 __func__, err); 8618 8510 goto out; 8619 8511 } 8512 + 8513 + /* Generate unique device ID */ 8514 + dev_info->device_id = ufshcd_create_device_id(hba, desc_buf); 8620 8515 8621 8516 hba->luns_avail = desc_buf[DEVICE_DESC_PARAM_NUM_LU] + 8622 8517 desc_buf[DEVICE_DESC_PARAM_NUM_WLU]; ··· 8656 8545 8657 8546 kfree(dev_info->model); 8658 8547 dev_info->model = NULL; 8548 + kfree(dev_info->device_id); 8549 + dev_info->device_id = NULL; 8659 8550 } 8660 8551 8661 8552 /** ··· 8800 8687 hba->dev_info.max_lu_supported = 32; 8801 8688 else if (desc_buf[GEOMETRY_DESC_PARAM_MAX_NUM_LUN] == 0) 8802 8689 hba->dev_info.max_lu_supported = 8; 8690 + 8691 + hba->dev_info.rpmb_io_size = desc_buf[GEOMETRY_DESC_PARAM_RPMB_RW_SIZE]; 8803 8692 8804 8693 out: 8805 8694 kfree(desc_buf); ··· 8989 8874 8990 8875 ufs_bsg_probe(hba); 8991 8876 scsi_scan_host(hba->host); 8877 + ufs_rpmb_probe(hba); 8992 8878 8993 8879 out: 8994 8880 return ret; ··· 9007 8891 utrdl_size = sizeof(struct utp_transfer_req_desc) * nutrs; 9008 8892 dmam_free_coherent(hba->dev, utrdl_size, hba->utrdl_base_addr, 9009 8893 hba->utrdl_dma_addr); 9010 - 9011 - devm_kfree(hba->dev, hba->lrb); 9012 8894 } 9013 8895 9014 8896 static int ufshcd_alloc_mcq(struct ufs_hba *hba) ··· 9014 8900 int ret; 9015 8901 int old_nutrs = hba->nutrs; 9016 8902 9017 - ret = ufshcd_mcq_decide_queue_depth(hba); 8903 + ret = ufshcd_get_hba_mac(hba); 9018 8904 if (ret < 0) 9019 8905 return ret; 9020 8906 ··· 9040 8926 goto err; 9041 8927 9042 8928 hba->host->can_queue = hba->nutrs - UFSHCD_NUM_RESERVED; 9043 - hba->reserved_slot = hba->nutrs - UFSHCD_NUM_RESERVED; 9044 8929 9045 8930 return 0; 9046 8931 err: ··· 9277 9164 .name = UFSHCD, 9278 9165 .proc_name = UFSHCD, 9279 9166 .map_queues = ufshcd_map_queues, 9167 + .cmd_size = sizeof(struct ufshcd_lrb), 9168 + .init_cmd_priv = ufshcd_init_cmd_priv, 9280 9169 .queuecommand = ufshcd_queuecommand, 9170 + .queue_reserved_command = ufshcd_queue_reserved_command, 9171 + .nr_reserved_cmds = UFSHCD_NUM_RESERVED, 9281 9172 .mq_poll = ufshcd_poll, 9282 9173 .sdev_init = ufshcd_sdev_init, 9283 9174 .sdev_configure = ufshcd_sdev_configure, ··· 9892 9775 } 9893 9776 9894 9777 /* 9895 - * Some UFS devices require delay after VCC power rail is turned-off. 9778 + * All UFS devices require delay after VCC power rail is turned-off. 9896 9779 */ 9897 - if (vcc_off && hba->vreg_info.vcc && 9898 - hba->dev_quirks & UFS_DEVICE_QUIRK_DELAY_AFTER_LPM) 9899 - usleep_range(5000, 5100); 9780 + if (vcc_off && hba->vreg_info.vcc && !hba->vreg_info.vcc->always_on) 9781 + usleep_range(hba->vcc_off_delay_us, 9782 + hba->vcc_off_delay_us + 100); 9900 9783 } 9901 9784 9902 9785 #ifdef CONFIG_PM ··· 10545 10428 ufshcd_rpm_get_sync(hba); 10546 10429 ufs_hwmon_remove(hba); 10547 10430 ufs_bsg_remove(hba); 10431 + ufs_rpmb_remove(hba); 10548 10432 ufs_sysfs_remove_nodes(hba->dev); 10549 10433 cancel_delayed_work_sync(&hba->ufs_rtc_update_work); 10550 10434 blk_mq_destroy_queue(hba->tmf_queue); ··· 10705 10587 { 10706 10588 int err; 10707 10589 10590 + WARN_ON_ONCE(!hba->host->can_queue); 10591 + WARN_ON_ONCE(!hba->host->cmd_per_lun); 10592 + 10708 10593 if (is_mcq_supported(hba)) { 10709 10594 ufshcd_mcq_enable(hba); 10710 10595 err = ufshcd_alloc_mcq(hba); ··· 10827 10706 UFS_SLEEP_PWR_MODE, 10828 10707 UIC_LINK_HIBERN8_STATE); 10829 10708 10830 - init_completion(&hba->dev_cmd.complete); 10709 + /* 10710 + * Most ufs devices require 1ms delay after vcc is powered off before 10711 + * it can be powered on again. Set the default to 2ms. The platform 10712 + * drivers can override this setting as needed. 10713 + */ 10714 + hba->vcc_off_delay_us = 2000; 10831 10715 10832 10716 err = ufshcd_hba_init(hba); 10833 10717 if (err) ··· 10866 10740 ufshcd_host_memory_configure(hba); 10867 10741 10868 10742 host->can_queue = hba->nutrs - UFSHCD_NUM_RESERVED; 10869 - host->cmd_per_lun = hba->nutrs - UFSHCD_NUM_RESERVED; 10743 + /* 10744 + * Set the queue depth for WLUNs. ufs_get_device_desc() will increase 10745 + * host->cmd_per_lun to a larger value. 10746 + */ 10747 + host->cmd_per_lun = 1; 10870 10748 host->max_id = UFSHCD_MAX_ID; 10871 10749 host->max_lun = UFS_MAX_LUNS; 10872 10750 host->max_channel = UFSHCD_MAX_CHANNEL; ··· 10962 10832 FIELD_PREP(UFSHCI_AHIBERN8_SCALE_MASK, 3); 10963 10833 } 10964 10834 10835 + err = ufshcd_add_scsi_host(hba); 10836 + if (err) 10837 + goto out_disable; 10838 + 10965 10839 /* Hold auto suspend until async scan completes */ 10966 10840 pm_runtime_get_sync(dev); 10967 10841 ··· 11013 10879 11014 10880 initialized: 11015 10881 ufshcd_process_probe_result(hba, probe_start, err); 11016 - if (err) 11017 - goto out_disable; 11018 - 11019 - err = ufshcd_add_scsi_host(hba); 11020 10882 if (err) 11021 10883 goto out_disable; 11022 10884
+13
drivers/ufs/host/Kconfig
··· 154 154 155 155 Select this if you have UFS controller on Rockchip chipset. 156 156 If unsure, say N. 157 + 158 + config SCSI_UFS_AMD_VERSAL2 159 + tristate "AMD Versal Gen 2 UFS controller platform driver" 160 + depends on SCSI_UFSHCD_PLATFORM && (ARCH_ZYNQMP || COMPILE_TEST) 161 + help 162 + This selects the AMD Versal Gen 2 specific additions on top of 163 + the UFSHCD DWC and UFSHCD platform driver. UFS host on AMD 164 + Versal Gen 2 needs some vendor specific configurations like PHY 165 + and vendor specific register accesses before accessing the 166 + hardware. 167 + 168 + Select this if you have UFS controller on AMD Versal Gen 2 SoC. 169 + If unsure, say N.
+1
drivers/ufs/host/Makefile
··· 13 13 obj-$(CONFIG_SCSI_UFS_ROCKCHIP) += ufs-rockchip.o 14 14 obj-$(CONFIG_SCSI_UFS_SPRD) += ufs-sprd.o 15 15 obj-$(CONFIG_SCSI_UFS_TI_J721E) += ti-j721e-ufs.o 16 + obj-$(CONFIG_SCSI_UFS_AMD_VERSAL2) += ufs-amd-versal2.o ufshcd-dwc.o
+29 -8
drivers/ufs/host/ti-j721e-ufs.c
··· 15 15 #define TI_UFS_SS_RST_N_PCS BIT(0) 16 16 #define TI_UFS_SS_CLK_26MHZ BIT(4) 17 17 18 + struct ti_j721e_ufs { 19 + void __iomem *regbase; 20 + u32 reg; 21 + }; 22 + 18 23 static int ti_j721e_ufs_probe(struct platform_device *pdev) 19 24 { 20 25 struct device *dev = &pdev->dev; 26 + struct ti_j721e_ufs *ufs; 21 27 unsigned long clk_rate; 22 - void __iomem *regbase; 23 28 struct clk *clk; 24 - u32 reg = 0; 25 29 int ret; 26 30 27 - regbase = devm_platform_ioremap_resource(pdev, 0); 28 - if (IS_ERR(regbase)) 29 - return PTR_ERR(regbase); 31 + ufs = devm_kzalloc(dev, sizeof(*ufs), GFP_KERNEL); 32 + if (!ufs) 33 + return -ENOMEM; 34 + 35 + ufs->regbase = devm_platform_ioremap_resource(pdev, 0); 36 + if (IS_ERR(ufs->regbase)) 37 + return PTR_ERR(ufs->regbase); 30 38 31 39 pm_runtime_enable(dev); 32 40 ret = pm_runtime_resume_and_get(dev); ··· 50 42 } 51 43 clk_rate = clk_get_rate(clk); 52 44 if (clk_rate == 26000000) 53 - reg |= TI_UFS_SS_CLK_26MHZ; 45 + ufs->reg |= TI_UFS_SS_CLK_26MHZ; 54 46 devm_clk_put(dev, clk); 55 47 56 48 /* Take UFS slave device out of reset */ 57 - reg |= TI_UFS_SS_RST_N_PCS; 58 - writel(reg, regbase + TI_UFS_SS_CTRL); 49 + ufs->reg |= TI_UFS_SS_RST_N_PCS; 50 + writel(ufs->reg, ufs->regbase + TI_UFS_SS_CTRL); 51 + 52 + dev_set_drvdata(dev, ufs); 59 53 60 54 ret = of_platform_populate(pdev->dev.of_node, NULL, NULL, 61 55 dev); ··· 82 72 pm_runtime_disable(&pdev->dev); 83 73 } 84 74 75 + static int ti_j721e_ufs_resume(struct device *dev) 76 + { 77 + struct ti_j721e_ufs *ufs = dev_get_drvdata(dev); 78 + 79 + writel(ufs->reg, ufs->regbase + TI_UFS_SS_CTRL); 80 + return 0; 81 + } 82 + 83 + static DEFINE_SIMPLE_DEV_PM_OPS(ti_j721e_ufs_pm_ops, NULL, ti_j721e_ufs_resume); 84 + 85 85 static const struct of_device_id ti_j721e_ufs_of_match[] = { 86 86 { 87 87 .compatible = "ti,j721e-ufs", ··· 107 87 .driver = { 108 88 .name = "ti-j721e-ufs", 109 89 .of_match_table = ti_j721e_ufs_of_match, 90 + .pm = pm_sleep_ptr(&ti_j721e_ufs_pm_ops), 110 91 }, 111 92 }; 112 93 module_platform_driver(ti_j721e_ufs_driver);
+564
drivers/ufs/host/ufs-amd-versal2.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (C) 2025 Advanced Micro Devices, Inc. 4 + * 5 + * Authors: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com> 6 + */ 7 + 8 + #include <linux/clk.h> 9 + #include <linux/delay.h> 10 + #include <linux/firmware/xlnx-zynqmp.h> 11 + #include <linux/irqreturn.h> 12 + #include <linux/module.h> 13 + #include <linux/of.h> 14 + #include <linux/platform_device.h> 15 + #include <linux/reset.h> 16 + #include <ufs/unipro.h> 17 + 18 + #include "ufshcd-dwc.h" 19 + #include "ufshcd-pltfrm.h" 20 + #include "ufshci-dwc.h" 21 + 22 + /* PHY modes */ 23 + #define UFSHCD_DWC_PHY_MODE_ROM 0 24 + 25 + #define MPHY_FAST_RX_AFE_CAL BIT(2) 26 + #define MPHY_FW_CALIB_CFG_VAL BIT(8) 27 + 28 + #define MPHY_RX_OVRD_EN BIT(3) 29 + #define MPHY_RX_OVRD_VAL BIT(2) 30 + #define MPHY_RX_ACK_MASK BIT(0) 31 + 32 + #define TIMEOUT_MICROSEC 1000000 33 + 34 + struct ufs_versal2_host { 35 + struct ufs_hba *hba; 36 + struct reset_control *rstc; 37 + struct reset_control *rstphy; 38 + u32 phy_mode; 39 + unsigned long host_clk; 40 + u8 attcompval0; 41 + u8 attcompval1; 42 + u8 ctlecompval0; 43 + u8 ctlecompval1; 44 + }; 45 + 46 + static int ufs_versal2_phy_reg_write(struct ufs_hba *hba, u32 addr, u32 val) 47 + { 48 + static struct ufshcd_dme_attr_val phy_write_attrs[] = { 49 + { UIC_ARG_MIB(CBCREGADDRLSB), 0, DME_LOCAL }, 50 + { UIC_ARG_MIB(CBCREGADDRMSB), 0, DME_LOCAL }, 51 + { UIC_ARG_MIB(CBCREGWRLSB), 0, DME_LOCAL }, 52 + { UIC_ARG_MIB(CBCREGWRMSB), 0, DME_LOCAL }, 53 + { UIC_ARG_MIB(CBCREGRDWRSEL), 1, DME_LOCAL }, 54 + { UIC_ARG_MIB(VS_MPHYCFGUPDT), 1, DME_LOCAL } 55 + }; 56 + 57 + phy_write_attrs[0].mib_val = (u8)addr; 58 + phy_write_attrs[1].mib_val = (u8)(addr >> 8); 59 + phy_write_attrs[2].mib_val = (u8)val; 60 + phy_write_attrs[3].mib_val = (u8)(val >> 8); 61 + 62 + return ufshcd_dwc_dme_set_attrs(hba, phy_write_attrs, ARRAY_SIZE(phy_write_attrs)); 63 + } 64 + 65 + static int ufs_versal2_phy_reg_read(struct ufs_hba *hba, u32 addr, u32 *val) 66 + { 67 + u32 mib_val; 68 + int ret; 69 + static struct ufshcd_dme_attr_val phy_read_attrs[] = { 70 + { UIC_ARG_MIB(CBCREGADDRLSB), 0, DME_LOCAL }, 71 + { UIC_ARG_MIB(CBCREGADDRMSB), 0, DME_LOCAL }, 72 + { UIC_ARG_MIB(CBCREGRDWRSEL), 0, DME_LOCAL }, 73 + { UIC_ARG_MIB(VS_MPHYCFGUPDT), 1, DME_LOCAL } 74 + }; 75 + 76 + phy_read_attrs[0].mib_val = (u8)addr; 77 + phy_read_attrs[1].mib_val = (u8)(addr >> 8); 78 + 79 + ret = ufshcd_dwc_dme_set_attrs(hba, phy_read_attrs, ARRAY_SIZE(phy_read_attrs)); 80 + if (ret) 81 + return ret; 82 + 83 + ret = ufshcd_dme_get(hba, UIC_ARG_MIB(CBCREGRDLSB), &mib_val); 84 + if (ret) 85 + return ret; 86 + 87 + *val = mib_val; 88 + ret = ufshcd_dme_get(hba, UIC_ARG_MIB(CBCREGRDMSB), &mib_val); 89 + if (ret) 90 + return ret; 91 + 92 + *val |= (mib_val << 8); 93 + 94 + return 0; 95 + } 96 + 97 + static int ufs_versal2_enable_phy(struct ufs_hba *hba) 98 + { 99 + u32 offset, reg; 100 + int ret; 101 + 102 + ret = ufshcd_dme_set(hba, UIC_ARG_MIB(VS_MPHYDISABLE), 0); 103 + if (ret) 104 + return ret; 105 + 106 + ret = ufshcd_dme_set(hba, UIC_ARG_MIB(VS_MPHYCFGUPDT), 1); 107 + if (ret) 108 + return ret; 109 + 110 + /* Check Tx/Rx FSM states */ 111 + for (offset = 0; offset < 2; offset++) { 112 + u32 time_left, mibsel; 113 + 114 + time_left = TIMEOUT_MICROSEC; 115 + mibsel = UIC_ARG_MIB_SEL(MTX_FSM_STATE, UIC_ARG_MPHY_TX_GEN_SEL_INDEX(offset)); 116 + do { 117 + ret = ufshcd_dme_get(hba, mibsel, &reg); 118 + if (ret) 119 + return ret; 120 + 121 + if (reg == TX_STATE_HIBERN8 || reg == TX_STATE_SLEEP || 122 + reg == TX_STATE_LSBURST) 123 + break; 124 + 125 + time_left--; 126 + usleep_range(1, 5); 127 + } while (time_left); 128 + 129 + if (!time_left) { 130 + dev_err(hba->dev, "Invalid Tx FSM state.\n"); 131 + return -ETIMEDOUT; 132 + } 133 + 134 + time_left = TIMEOUT_MICROSEC; 135 + mibsel = UIC_ARG_MIB_SEL(MRX_FSM_STATE, UIC_ARG_MPHY_RX_GEN_SEL_INDEX(offset)); 136 + do { 137 + ret = ufshcd_dme_get(hba, mibsel, &reg); 138 + if (ret) 139 + return ret; 140 + 141 + if (reg == RX_STATE_HIBERN8 || reg == RX_STATE_SLEEP || 142 + reg == RX_STATE_LSBURST) 143 + break; 144 + 145 + time_left--; 146 + usleep_range(1, 5); 147 + } while (time_left); 148 + 149 + if (!time_left) { 150 + dev_err(hba->dev, "Invalid Rx FSM state.\n"); 151 + return -ETIMEDOUT; 152 + } 153 + } 154 + 155 + return 0; 156 + } 157 + 158 + static int ufs_versal2_setup_phy(struct ufs_hba *hba) 159 + { 160 + struct ufs_versal2_host *host = ufshcd_get_variant(hba); 161 + int ret; 162 + u32 reg; 163 + 164 + /* Bypass RX-AFE offset calibrations (ATT/CTLE) */ 165 + ret = ufs_versal2_phy_reg_read(hba, FAST_FLAGS(0), &reg); 166 + if (ret) 167 + return ret; 168 + 169 + reg |= MPHY_FAST_RX_AFE_CAL; 170 + ret = ufs_versal2_phy_reg_write(hba, FAST_FLAGS(0), reg); 171 + if (ret) 172 + return ret; 173 + 174 + ret = ufs_versal2_phy_reg_read(hba, FAST_FLAGS(1), &reg); 175 + if (ret) 176 + return ret; 177 + 178 + reg |= MPHY_FAST_RX_AFE_CAL; 179 + ret = ufs_versal2_phy_reg_write(hba, FAST_FLAGS(1), reg); 180 + if (ret) 181 + return ret; 182 + 183 + /* Program ATT and CTLE compensation values */ 184 + if (host->attcompval0) { 185 + ret = ufs_versal2_phy_reg_write(hba, RX_AFE_ATT_IDAC(0), host->attcompval0); 186 + if (ret) 187 + return ret; 188 + } 189 + 190 + if (host->attcompval1) { 191 + ret = ufs_versal2_phy_reg_write(hba, RX_AFE_ATT_IDAC(1), host->attcompval1); 192 + if (ret) 193 + return ret; 194 + } 195 + 196 + if (host->ctlecompval0) { 197 + ret = ufs_versal2_phy_reg_write(hba, RX_AFE_CTLE_IDAC(0), host->ctlecompval0); 198 + if (ret) 199 + return ret; 200 + } 201 + 202 + if (host->ctlecompval1) { 203 + ret = ufs_versal2_phy_reg_write(hba, RX_AFE_CTLE_IDAC(1), host->ctlecompval1); 204 + if (ret) 205 + return ret; 206 + } 207 + 208 + ret = ufs_versal2_phy_reg_read(hba, FW_CALIB_CCFG(0), &reg); 209 + if (ret) 210 + return ret; 211 + 212 + reg |= MPHY_FW_CALIB_CFG_VAL; 213 + ret = ufs_versal2_phy_reg_write(hba, FW_CALIB_CCFG(0), reg); 214 + if (ret) 215 + return ret; 216 + 217 + ret = ufs_versal2_phy_reg_read(hba, FW_CALIB_CCFG(1), &reg); 218 + if (ret) 219 + return ret; 220 + 221 + reg |= MPHY_FW_CALIB_CFG_VAL; 222 + return ufs_versal2_phy_reg_write(hba, FW_CALIB_CCFG(1), reg); 223 + } 224 + 225 + static int ufs_versal2_phy_init(struct ufs_hba *hba) 226 + { 227 + struct ufs_versal2_host *host = ufshcd_get_variant(hba); 228 + u32 time_left; 229 + bool is_ready; 230 + int ret; 231 + static const struct ufshcd_dme_attr_val rmmi_attrs[] = { 232 + { UIC_ARG_MIB(CBREFCLKCTRL2), CBREFREFCLK_GATE_OVR_EN, DME_LOCAL }, 233 + { UIC_ARG_MIB(CBCRCTRL), 1, DME_LOCAL }, 234 + { UIC_ARG_MIB(CBC10DIRECTCONF2), 1, DME_LOCAL }, 235 + { UIC_ARG_MIB(VS_MPHYCFGUPDT), 1, DME_LOCAL } 236 + }; 237 + 238 + /* Wait for Tx/Rx config_rdy */ 239 + time_left = TIMEOUT_MICROSEC; 240 + do { 241 + time_left--; 242 + ret = zynqmp_pm_is_mphy_tx_rx_config_ready(&is_ready); 243 + if (ret) 244 + return ret; 245 + 246 + if (!is_ready) 247 + break; 248 + 249 + usleep_range(1, 5); 250 + } while (time_left); 251 + 252 + if (!time_left) { 253 + dev_err(hba->dev, "Tx/Rx configuration signal busy.\n"); 254 + return -ETIMEDOUT; 255 + } 256 + 257 + ret = ufshcd_dwc_dme_set_attrs(hba, rmmi_attrs, ARRAY_SIZE(rmmi_attrs)); 258 + if (ret) 259 + return ret; 260 + 261 + ret = reset_control_deassert(host->rstphy); 262 + if (ret) { 263 + dev_err(hba->dev, "ufsphy reset deassert failed, err = %d\n", ret); 264 + return ret; 265 + } 266 + 267 + /* Wait for SRAM init done */ 268 + time_left = TIMEOUT_MICROSEC; 269 + do { 270 + time_left--; 271 + ret = zynqmp_pm_is_sram_init_done(&is_ready); 272 + if (ret) 273 + return ret; 274 + 275 + if (is_ready) 276 + break; 277 + 278 + usleep_range(1, 5); 279 + } while (time_left); 280 + 281 + if (!time_left) { 282 + dev_err(hba->dev, "SRAM initialization failed.\n"); 283 + return -ETIMEDOUT; 284 + } 285 + 286 + ret = ufs_versal2_setup_phy(hba); 287 + if (ret) 288 + return ret; 289 + 290 + return ufs_versal2_enable_phy(hba); 291 + } 292 + 293 + static int ufs_versal2_init(struct ufs_hba *hba) 294 + { 295 + struct ufs_versal2_host *host; 296 + struct device *dev = hba->dev; 297 + struct ufs_clk_info *clki; 298 + int ret; 299 + u32 cal; 300 + 301 + host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL); 302 + if (!host) 303 + return -ENOMEM; 304 + 305 + host->hba = hba; 306 + ufshcd_set_variant(hba, host); 307 + 308 + host->phy_mode = UFSHCD_DWC_PHY_MODE_ROM; 309 + 310 + list_for_each_entry(clki, &hba->clk_list_head, list) { 311 + if (!strcmp(clki->name, "core")) 312 + host->host_clk = clk_get_rate(clki->clk); 313 + } 314 + 315 + host->rstc = devm_reset_control_get_exclusive(dev, "host"); 316 + if (IS_ERR(host->rstc)) { 317 + dev_err(dev, "failed to get reset ctrl: host\n"); 318 + return PTR_ERR(host->rstc); 319 + } 320 + 321 + host->rstphy = devm_reset_control_get_exclusive(dev, "phy"); 322 + if (IS_ERR(host->rstphy)) { 323 + dev_err(dev, "failed to get reset ctrl: phy\n"); 324 + return PTR_ERR(host->rstphy); 325 + } 326 + 327 + ret = reset_control_assert(host->rstc); 328 + if (ret) { 329 + dev_err(hba->dev, "host reset assert failed, err = %d\n", ret); 330 + return ret; 331 + } 332 + 333 + ret = reset_control_assert(host->rstphy); 334 + if (ret) { 335 + dev_err(hba->dev, "phy reset assert failed, err = %d\n", ret); 336 + return ret; 337 + } 338 + 339 + ret = zynqmp_pm_set_sram_bypass(); 340 + if (ret) { 341 + dev_err(dev, "Bypass SRAM interface failed, err = %d\n", ret); 342 + return ret; 343 + } 344 + 345 + ret = reset_control_deassert(host->rstc); 346 + if (ret) 347 + dev_err(hba->dev, "host reset deassert failed, err = %d\n", ret); 348 + 349 + ret = zynqmp_pm_get_ufs_calibration_values(&cal); 350 + if (ret) { 351 + dev_err(dev, "failed to read calibration values\n"); 352 + return ret; 353 + } 354 + 355 + host->attcompval0 = (u8)cal; 356 + host->attcompval1 = (u8)(cal >> 8); 357 + host->ctlecompval0 = (u8)(cal >> 16); 358 + host->ctlecompval1 = (u8)(cal >> 24); 359 + 360 + hba->quirks |= UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING; 361 + 362 + return 0; 363 + } 364 + 365 + static int ufs_versal2_hce_enable_notify(struct ufs_hba *hba, 366 + enum ufs_notify_change_status status) 367 + { 368 + int ret = 0; 369 + 370 + if (status == PRE_CHANGE) { 371 + ret = ufs_versal2_phy_init(hba); 372 + if (ret) 373 + dev_err(hba->dev, "Phy init failed (%d)\n", ret); 374 + } 375 + 376 + return ret; 377 + } 378 + 379 + static int ufs_versal2_link_startup_notify(struct ufs_hba *hba, 380 + enum ufs_notify_change_status status) 381 + { 382 + struct ufs_versal2_host *host = ufshcd_get_variant(hba); 383 + int ret = 0; 384 + 385 + switch (status) { 386 + case PRE_CHANGE: 387 + if (host->host_clk) 388 + ufshcd_writel(hba, host->host_clk / 1000000, DWC_UFS_REG_HCLKDIV); 389 + 390 + break; 391 + case POST_CHANGE: 392 + ret = ufshcd_dwc_link_startup_notify(hba, status); 393 + break; 394 + default: 395 + ret = -EINVAL; 396 + break; 397 + } 398 + 399 + return ret; 400 + } 401 + 402 + static int ufs_versal2_phy_ratesel(struct ufs_hba *hba, u32 activelanes, u32 rx_req) 403 + { 404 + u32 time_left, reg, lane; 405 + int ret; 406 + 407 + for (lane = 0; lane < activelanes; lane++) { 408 + time_left = TIMEOUT_MICROSEC; 409 + ret = ufs_versal2_phy_reg_read(hba, RX_OVRD_IN_1(lane), &reg); 410 + if (ret) 411 + return ret; 412 + 413 + reg |= MPHY_RX_OVRD_EN; 414 + if (rx_req) 415 + reg |= MPHY_RX_OVRD_VAL; 416 + else 417 + reg &= ~MPHY_RX_OVRD_VAL; 418 + 419 + ret = ufs_versal2_phy_reg_write(hba, RX_OVRD_IN_1(lane), reg); 420 + if (ret) 421 + return ret; 422 + 423 + do { 424 + ret = ufs_versal2_phy_reg_read(hba, RX_PCS_OUT(lane), &reg); 425 + if (ret) 426 + return ret; 427 + 428 + reg &= MPHY_RX_ACK_MASK; 429 + if (reg == rx_req) 430 + break; 431 + 432 + time_left--; 433 + usleep_range(1, 5); 434 + } while (time_left); 435 + 436 + if (!time_left) { 437 + dev_err(hba->dev, "Invalid Rx Ack value.\n"); 438 + return -ETIMEDOUT; 439 + } 440 + } 441 + 442 + return 0; 443 + } 444 + 445 + static int ufs_versal2_pwr_change_notify(struct ufs_hba *hba, enum ufs_notify_change_status status, 446 + const struct ufs_pa_layer_attr *dev_max_params, 447 + struct ufs_pa_layer_attr *dev_req_params) 448 + { 449 + struct ufs_versal2_host *host = ufshcd_get_variant(hba); 450 + u32 lane, reg, rate = 0; 451 + int ret = 0; 452 + 453 + if (status == PRE_CHANGE) { 454 + memcpy(dev_req_params, dev_max_params, sizeof(struct ufs_pa_layer_attr)); 455 + 456 + /* If it is not a calibrated part, switch PWRMODE to SLOW_MODE */ 457 + if (!host->attcompval0 && !host->attcompval1 && !host->ctlecompval0 && 458 + !host->ctlecompval1) { 459 + dev_req_params->pwr_rx = SLOW_MODE; 460 + dev_req_params->pwr_tx = SLOW_MODE; 461 + return 0; 462 + } 463 + 464 + if (dev_req_params->pwr_rx == SLOW_MODE || dev_req_params->pwr_rx == SLOWAUTO_MODE) 465 + return 0; 466 + 467 + if (dev_req_params->hs_rate == PA_HS_MODE_B) 468 + rate = 1; 469 + 470 + /* Select the rate */ 471 + ret = ufshcd_dme_set(hba, UIC_ARG_MIB(CBRATESEL), rate); 472 + if (ret) 473 + return ret; 474 + 475 + ret = ufshcd_dme_set(hba, UIC_ARG_MIB(VS_MPHYCFGUPDT), 1); 476 + if (ret) 477 + return ret; 478 + 479 + ret = ufs_versal2_phy_ratesel(hba, dev_req_params->lane_tx, 1); 480 + if (ret) 481 + return ret; 482 + 483 + ret = ufs_versal2_phy_ratesel(hba, dev_req_params->lane_tx, 0); 484 + if (ret) 485 + return ret; 486 + 487 + /* Remove rx_req override */ 488 + for (lane = 0; lane < dev_req_params->lane_tx; lane++) { 489 + ret = ufs_versal2_phy_reg_read(hba, RX_OVRD_IN_1(lane), &reg); 490 + if (ret) 491 + return ret; 492 + 493 + reg &= ~MPHY_RX_OVRD_EN; 494 + ret = ufs_versal2_phy_reg_write(hba, RX_OVRD_IN_1(lane), reg); 495 + if (ret) 496 + return ret; 497 + } 498 + 499 + if (dev_req_params->lane_tx == UFS_LANE_2 && dev_req_params->lane_rx == UFS_LANE_2) 500 + ret = ufshcd_dme_configure_adapt(hba, dev_req_params->gear_tx, 501 + PA_INITIAL_ADAPT); 502 + } 503 + 504 + return ret; 505 + } 506 + 507 + static struct ufs_hba_variant_ops ufs_versal2_hba_vops = { 508 + .name = "ufs-versal2-pltfm", 509 + .init = ufs_versal2_init, 510 + .link_startup_notify = ufs_versal2_link_startup_notify, 511 + .hce_enable_notify = ufs_versal2_hce_enable_notify, 512 + .pwr_change_notify = ufs_versal2_pwr_change_notify, 513 + }; 514 + 515 + static const struct of_device_id ufs_versal2_pltfm_match[] = { 516 + { 517 + .compatible = "amd,versal2-ufs", 518 + .data = &ufs_versal2_hba_vops, 519 + }, 520 + { }, 521 + }; 522 + MODULE_DEVICE_TABLE(of, ufs_versal2_pltfm_match); 523 + 524 + static int ufs_versal2_probe(struct platform_device *pdev) 525 + { 526 + struct device *dev = &pdev->dev; 527 + int ret; 528 + 529 + /* Perform generic probe */ 530 + ret = ufshcd_pltfrm_init(pdev, &ufs_versal2_hba_vops); 531 + if (ret) 532 + dev_err(dev, "ufshcd_pltfrm_init() failed %d\n", ret); 533 + 534 + return ret; 535 + } 536 + 537 + static void ufs_versal2_remove(struct platform_device *pdev) 538 + { 539 + struct ufs_hba *hba = platform_get_drvdata(pdev); 540 + 541 + pm_runtime_get_sync(&(pdev)->dev); 542 + ufshcd_remove(hba); 543 + } 544 + 545 + static const struct dev_pm_ops ufs_versal2_pm_ops = { 546 + SET_SYSTEM_SLEEP_PM_OPS(ufshcd_system_suspend, ufshcd_system_resume) 547 + SET_RUNTIME_PM_OPS(ufshcd_runtime_suspend, ufshcd_runtime_resume, NULL) 548 + }; 549 + 550 + static struct platform_driver ufs_versal2_pltfm = { 551 + .probe = ufs_versal2_probe, 552 + .remove = ufs_versal2_remove, 553 + .driver = { 554 + .name = "ufshcd-versal2", 555 + .pm = &ufs_versal2_pm_ops, 556 + .of_match_table = of_match_ptr(ufs_versal2_pltfm_match), 557 + }, 558 + }; 559 + 560 + module_platform_driver(ufs_versal2_pltfm); 561 + 562 + MODULE_AUTHOR("Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>"); 563 + MODULE_DESCRIPTION("AMD Versal Gen 2 UFS Host Controller driver"); 564 + MODULE_LICENSE("GPL");
+103 -27
drivers/ufs/host/ufs-mediatek.c
··· 41 41 static const struct ufs_dev_quirk ufs_mtk_dev_fixups[] = { 42 42 { .wmanufacturerid = UFS_ANY_VENDOR, 43 43 .model = UFS_ANY_MODEL, 44 - .quirk = UFS_DEVICE_QUIRK_DELAY_AFTER_LPM | 45 - UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM }, 44 + .quirk = UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM }, 46 45 { .wmanufacturerid = UFS_VENDOR_SKHYNIX, 47 46 .model = "H9HQ21AFAMZDAR", 48 47 .quirk = UFS_DEVICE_QUIRK_SUPPORT_EXTENDED_FEATURES }, ··· 279 280 ufshcd_readl(hba, REG_UFS_XOUFS_CTRL) | 0x80, 280 281 REG_UFS_XOUFS_CTRL); 281 282 283 + if (host->legacy_ip_ver) 284 + return 0; 285 + 282 286 /* DDR_EN setting */ 283 287 if (host->ip_ver >= IP_VER_MT6989) { 284 288 ufshcd_rmwl(hba, UFS_MASK(0x7FFF, 8), 285 289 0x453000, REG_UFS_MMIO_OPT_CTRL_0); 286 290 } 287 291 292 + if (host->ip_ver >= IP_VER_MT6991_A0) { 293 + /* Enable multi-rtt */ 294 + ufshcd_rmwl(hba, MRTT_EN, MRTT_EN, REG_UFS_MMIO_OPT_CTRL_0); 295 + /* Enable random performance improvement */ 296 + ufshcd_rmwl(hba, RDN_PFM_IMPV_DIS, 0, REG_UFS_MMIO_OPT_CTRL_0); 297 + } 288 298 } 289 299 290 300 return 0; ··· 413 405 { 414 406 struct ufs_mtk_host *host = ufshcd_get_variant(hba); 415 407 416 - if (((host->ip_ver >> 16) & 0xFF) >= 0x36) { 408 + if (!host->legacy_ip_ver && host->ip_ver >= IP_VER_MT6983) { 417 409 ufshcd_writel(hba, 0x820820, REG_UFS_DEBUG_SEL); 418 410 ufshcd_writel(hba, 0x0, REG_UFS_DEBUG_SEL_B0); 419 411 ufshcd_writel(hba, 0x55555555, REG_UFS_DEBUG_SEL_B1); ··· 430 422 u64 timeout, time_checked; 431 423 u32 val, sm; 432 424 bool wait_idle; 425 + struct ufs_mtk_host *host = ufshcd_get_variant(hba); 433 426 434 427 /* cannot use plain ktime_get() in suspend */ 435 428 timeout = ktime_get_mono_fast_ns() + retry_ms * 1000000UL; ··· 441 432 442 433 do { 443 434 time_checked = ktime_get_mono_fast_ns(); 444 - ufs_mtk_dbg_sel(hba); 445 - val = ufshcd_readl(hba, REG_UFS_PROBE); 435 + if (host->legacy_ip_ver || host->ip_ver < IP_VER_MT6899) { 436 + ufs_mtk_dbg_sel(hba); 437 + val = ufshcd_readl(hba, REG_UFS_PROBE); 438 + } else { 439 + val = ufshcd_readl(hba, REG_UFS_UFS_MMIO_OTSD_CTRL); 440 + val = val >> 16; 441 + } 446 442 447 443 sm = val & 0x1f; 448 444 ··· 479 465 { 480 466 ktime_t timeout, time_checked; 481 467 u32 val; 468 + struct ufs_mtk_host *host = ufshcd_get_variant(hba); 482 469 483 470 timeout = ktime_add_ms(ktime_get(), max_wait_ms); 484 471 do { 485 472 time_checked = ktime_get(); 486 - ufs_mtk_dbg_sel(hba); 487 - val = ufshcd_readl(hba, REG_UFS_PROBE); 488 - val = val >> 28; 473 + 474 + if (host->legacy_ip_ver || host->ip_ver < IP_VER_MT6899) { 475 + ufs_mtk_dbg_sel(hba); 476 + val = ufshcd_readl(hba, REG_UFS_PROBE); 477 + val = val >> 28; 478 + } else { 479 + val = ufshcd_readl(hba, REG_UFS_UFS_MMIO_OTSD_CTRL); 480 + val = val >> 24; 481 + } 489 482 490 483 if (val == state) 491 484 return 0; ··· 1130 1109 } 1131 1110 } 1132 1111 1133 - /* Convert microseconds to Auto-Hibernate Idle Timer register value */ 1134 - static u32 ufs_mtk_us_to_ahit(unsigned int timer) 1135 - { 1136 - unsigned int scale; 1137 - 1138 - for (scale = 0; timer > UFSHCI_AHIBERN8_TIMER_MASK; ++scale) 1139 - timer /= UFSHCI_AHIBERN8_SCALE_FACTOR; 1140 - 1141 - return FIELD_PREP(UFSHCI_AHIBERN8_TIMER_MASK, timer) | 1142 - FIELD_PREP(UFSHCI_AHIBERN8_SCALE_MASK, scale); 1143 - } 1144 - 1145 1112 static void ufs_mtk_fix_ahit(struct ufs_hba *hba) 1146 1113 { 1147 1114 unsigned int us; ··· 1152 1143 break; 1153 1144 } 1154 1145 1155 - hba->ahit = ufs_mtk_us_to_ahit(us); 1146 + hba->ahit = ufshcd_us_to_ahit(us); 1156 1147 } 1157 1148 1158 1149 ufs_mtk_setup_clk_gating(hba); ··· 1341 1332 return true; 1342 1333 } 1343 1334 1335 + static void ufs_mtk_adjust_sync_length(struct ufs_hba *hba) 1336 + { 1337 + int i; 1338 + u32 value; 1339 + u32 cnt, att, min; 1340 + struct attr_min { 1341 + u32 attr; 1342 + u32 min_value; 1343 + } pa_min_sync_length[] = { 1344 + {PA_TXHSG1SYNCLENGTH, 0x48}, 1345 + {PA_TXHSG2SYNCLENGTH, 0x48}, 1346 + {PA_TXHSG3SYNCLENGTH, 0x48}, 1347 + {PA_TXHSG4SYNCLENGTH, 0x48}, 1348 + {PA_TXHSG5SYNCLENGTH, 0x48} 1349 + }; 1350 + 1351 + cnt = sizeof(pa_min_sync_length) / sizeof(struct attr_min); 1352 + for (i = 0; i < cnt; i++) { 1353 + att = pa_min_sync_length[i].attr; 1354 + min = pa_min_sync_length[i].min_value; 1355 + ufshcd_dme_get(hba, UIC_ARG_MIB(att), &value); 1356 + if (value < min) 1357 + ufshcd_dme_set(hba, UIC_ARG_MIB(att), min); 1358 + 1359 + ufshcd_dme_peer_get(hba, UIC_ARG_MIB(att), &value); 1360 + if (value < min) 1361 + ufshcd_dme_peer_set(hba, UIC_ARG_MIB(att), min); 1362 + } 1363 + } 1364 + 1344 1365 static int ufs_mtk_pre_pwr_change(struct ufs_hba *hba, 1345 1366 const struct ufs_pa_layer_attr *dev_max_params, 1346 1367 struct ufs_pa_layer_attr *dev_req_params) ··· 1394 1355 } 1395 1356 1396 1357 if (ufs_mtk_pmc_via_fastauto(hba, dev_req_params)) { 1358 + ufs_mtk_adjust_sync_length(hba); 1359 + 1397 1360 ufshcd_dme_set(hba, UIC_ARG_MIB(PA_TXTERMINATION), true); 1398 1361 ufshcd_dme_set(hba, UIC_ARG_MIB(PA_TXGEAR), UFS_HS_G1); 1399 1362 ··· 1660 1619 static int ufs_mtk_link_set_hpm(struct ufs_hba *hba) 1661 1620 { 1662 1621 int err; 1622 + u32 val; 1623 + struct ufs_mtk_host *host = ufshcd_get_variant(hba); 1663 1624 1664 1625 err = ufshcd_hba_enable(hba); 1665 1626 if (err) 1666 1627 return err; 1667 1628 1668 1629 err = ufs_mtk_unipro_set_lpm(hba, false); 1669 - if (err) 1630 + if (err) { 1631 + if (host->ip_ver < IP_VER_MT6899) { 1632 + ufs_mtk_dbg_sel(hba); 1633 + val = ufshcd_readl(hba, REG_UFS_PROBE); 1634 + } else { 1635 + val = ufshcd_readl(hba, REG_UFS_UFS_MMIO_OTSD_CTRL); 1636 + } 1637 + ufshcd_update_evt_hist(hba, UFS_EVT_RESUME_ERR, (u32)val); 1638 + val = ufshcd_readl(hba, REG_INTERRUPT_STATUS); 1639 + ufshcd_update_evt_hist(hba, UFS_EVT_RESUME_ERR, (u32)val); 1670 1640 return err; 1641 + } 1671 1642 1672 1643 err = ufshcd_uic_hibern8_exit(hba); 1673 1644 if (err) ··· 1797 1744 { 1798 1745 int err; 1799 1746 struct arm_smccc_res res; 1747 + struct ufs_mtk_host *host = ufshcd_get_variant(hba); 1800 1748 1801 1749 if (status == PRE_CHANGE) { 1802 1750 if (ufshcd_is_auto_hibern8_supported(hba)) ··· 1827 1773 1828 1774 ufs_mtk_sram_pwr_ctrl(false, res); 1829 1775 1776 + /* Release pm_qos/clk if in scale-up mode during suspend */ 1777 + if (ufshcd_is_clkscaling_supported(hba) && (host->clk_scale_up)) { 1778 + ufshcd_pm_qos_update(hba, false); 1779 + _ufs_mtk_clk_scale(hba, false); 1780 + } else if ((!ufshcd_is_clkscaling_supported(hba) && 1781 + hba->pwr_info.gear_rx >= UFS_HS_G5)) { 1782 + _ufs_mtk_clk_scale(hba, false); 1783 + } 1784 + 1830 1785 return 0; 1831 1786 fail: 1832 1787 /* ··· 1851 1788 { 1852 1789 int err; 1853 1790 struct arm_smccc_res res; 1791 + struct ufs_mtk_host *host = ufshcd_get_variant(hba); 1854 1792 1855 1793 if (hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL) 1856 1794 ufs_mtk_dev_vreg_set_lpm(hba, false); ··· 1861 1797 err = ufs_mtk_mphy_power_on(hba, true); 1862 1798 if (err) 1863 1799 goto fail; 1800 + 1801 + /* Request pm_qos/clk if in scale-up mode after resume */ 1802 + if (ufshcd_is_clkscaling_supported(hba) && (host->clk_scale_up)) { 1803 + ufshcd_pm_qos_update(hba, true); 1804 + _ufs_mtk_clk_scale(hba, true); 1805 + } else if ((!ufshcd_is_clkscaling_supported(hba) && 1806 + hba->pwr_info.gear_rx >= UFS_HS_G5)) { 1807 + _ufs_mtk_clk_scale(hba, true); 1808 + } 1864 1809 1865 1810 if (ufshcd_is_link_hibern8(hba)) { 1866 1811 err = ufs_mtk_link_set_hpm(hba); ··· 1962 1889 { 1963 1890 ufshcd_fixup_dev_quirks(hba, ufs_mtk_dev_fixups); 1964 1891 1965 - if (ufs_mtk_is_broken_vcc(hba) && hba->vreg_info.vcc && 1966 - (hba->dev_quirks & UFS_DEVICE_QUIRK_DELAY_AFTER_LPM)) { 1892 + if (ufs_mtk_is_broken_vcc(hba) && hba->vreg_info.vcc) { 1967 1893 hba->vreg_info.vcc->always_on = true; 1968 1894 /* 1969 1895 * VCC will be kept always-on thus we don't 1970 - * need any delay during regulator operations 1896 + * need any delay before putting device's VCC in LPM mode. 1971 1897 */ 1972 - hba->dev_quirks &= ~(UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM | 1973 - UFS_DEVICE_QUIRK_DELAY_AFTER_LPM); 1898 + hba->dev_quirks &= ~UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM; 1974 1899 } 1975 1900 1976 1901 ufs_mtk_vreg_fix_vcc(hba); ··· 2443 2372 struct ufs_hba *hba = dev_get_drvdata(dev); 2444 2373 struct arm_smccc_res res; 2445 2374 int ret; 2375 + 2376 + if (hba->shutting_down) { 2377 + ret = -EBUSY; 2378 + goto out; 2379 + } 2446 2380 2447 2381 ret = ufshcd_system_suspend(dev); 2448 2382 if (ret)
+4
drivers/ufs/host/ufs-mediatek.h
··· 20 20 #define MCQ_MULTI_INTR_EN BIT(2) 21 21 #define MCQ_CMB_INTR_EN BIT(3) 22 22 #define MCQ_AH8 BIT(4) 23 + #define MON_EN BIT(5) 24 + #define MRTT_EN BIT(25) 25 + #define RDN_PFM_IMPV_DIS BIT(28) 23 26 24 27 #define MCQ_INTR_EN_MSK (MCQ_MULTI_INTR_EN | MCQ_CMB_INTR_EN) 25 28 ··· 31 28 */ 32 29 #define REG_UFS_XOUFS_CTRL 0x140 33 30 #define REG_UFS_REFCLK_CTRL 0x144 31 + #define REG_UFS_UFS_MMIO_OTSD_CTRL 0x14C 34 32 #define REG_UFS_MMIO_OPT_CTRL_0 0x160 35 33 #define REG_UFS_EXTREG 0x2100 36 34 #define REG_UFS_MPHYCTRL 0x2200
-3
drivers/ufs/host/ufs-qcom.c
··· 1037 1037 { .wmanufacturerid = UFS_VENDOR_SKHYNIX, 1038 1038 .model = UFS_ANY_MODEL, 1039 1039 .quirk = UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM }, 1040 - { .wmanufacturerid = UFS_VENDOR_TOSHIBA, 1041 - .model = UFS_ANY_MODEL, 1042 - .quirk = UFS_DEVICE_QUIRK_DELAY_AFTER_LPM }, 1043 1040 { .wmanufacturerid = UFS_VENDOR_WDC, 1044 1041 .model = UFS_ANY_MODEL, 1045 1042 .quirk = UFS_DEVICE_QUIRK_HOST_PA_TACTIVATE },
+14 -6
drivers/ufs/host/ufs-rockchip.c
··· 7 7 8 8 #include <linux/clk.h> 9 9 #include <linux/gpio.h> 10 + #include <linux/gpio/consumer.h> 10 11 #include <linux/mfd/syscon.h> 11 12 #include <linux/of.h> 12 13 #include <linux/platform_device.h> ··· 21 20 #include "ufshcd-pltfrm.h" 22 21 #include "ufs-rockchip.h" 23 22 23 + static void ufs_rockchip_controller_reset(struct ufs_rockchip_host *host) 24 + { 25 + reset_control_assert(host->rst); 26 + udelay(1); 27 + reset_control_deassert(host->rst); 28 + } 29 + 24 30 static int ufs_rockchip_hce_enable_notify(struct ufs_hba *hba, 25 31 enum ufs_notify_change_status status) 26 32 { 33 + struct ufs_rockchip_host *host = ufshcd_get_variant(hba); 27 34 int err = 0; 28 35 29 36 if (status == POST_CHANGE) { ··· 45 36 46 37 return ufshcd_vops_phy_initialization(hba); 47 38 } 39 + 40 + /* PRE_CHANGE */ 41 + ufs_rockchip_controller_reset(host); 48 42 49 43 return 0; 50 44 } ··· 168 156 return dev_err_probe(dev, PTR_ERR(host->rst), 169 157 "failed to get reset control\n"); 170 158 171 - reset_control_assert(host->rst); 172 - udelay(1); 173 - reset_control_deassert(host->rst); 159 + ufs_rockchip_controller_reset(host); 174 160 175 161 host->ref_out_clk = devm_clk_get_enabled(dev, "ref_out"); 176 162 if (IS_ERR(host->ref_out_clk)) ··· 292 282 return err; 293 283 } 294 284 295 - reset_control_assert(host->rst); 296 - udelay(1); 297 - reset_control_deassert(host->rst); 285 + ufs_rockchip_controller_reset(host); 298 286 299 287 return ufshcd_runtime_resume(dev); 300 288 }
+46
drivers/ufs/host/ufshcd-dwc.h
··· 12 12 13 13 #include <ufs/ufshcd.h> 14 14 15 + /* RMMI Attributes */ 16 + #define CBREFCLKCTRL2 0x8132 17 + #define CBCRCTRL 0x811F 18 + #define CBC10DIRECTCONF2 0x810E 19 + #define CBRATESEL 0x8114 20 + #define CBCREGADDRLSB 0x8116 21 + #define CBCREGADDRMSB 0x8117 22 + #define CBCREGWRLSB 0x8118 23 + #define CBCREGWRMSB 0x8119 24 + #define CBCREGRDLSB 0x811A 25 + #define CBCREGRDMSB 0x811B 26 + #define CBCREGRDWRSEL 0x811C 27 + 28 + #define CBREFREFCLK_GATE_OVR_EN BIT(7) 29 + 30 + /* M-PHY Attributes */ 31 + #define MTX_FSM_STATE 0x41 32 + #define MRX_FSM_STATE 0xC1 33 + 34 + /* M-PHY registers */ 35 + #define RX_OVRD_IN_1(n) (0x3006 + ((n) * 0x100)) 36 + #define RX_PCS_OUT(n) (0x300F + ((n) * 0x100)) 37 + #define FAST_FLAGS(n) (0x401C + ((n) * 0x100)) 38 + #define RX_AFE_ATT_IDAC(n) (0x4000 + ((n) * 0x100)) 39 + #define RX_AFE_CTLE_IDAC(n) (0x4001 + ((n) * 0x100)) 40 + #define FW_CALIB_CCFG(n) (0x404D + ((n) * 0x100)) 41 + 42 + /* Tx/Rx FSM state */ 43 + enum rx_fsm_state { 44 + RX_STATE_DISABLED = 0, 45 + RX_STATE_HIBERN8 = 1, 46 + RX_STATE_SLEEP = 2, 47 + RX_STATE_STALL = 3, 48 + RX_STATE_LSBURST = 4, 49 + RX_STATE_HSBURST = 5, 50 + }; 51 + 52 + enum tx_fsm_state { 53 + TX_STATE_DISABLED = 0, 54 + TX_STATE_HIBERN8 = 1, 55 + TX_STATE_SLEEP = 2, 56 + TX_STATE_STALL = 3, 57 + TX_STATE_LSBURST = 4, 58 + TX_STATE_HSBURST = 5, 59 + }; 60 + 15 61 struct ufshcd_dme_attr_val { 16 62 u32 attr_sel; 17 63 u32 mib_val;
+38
include/linux/firmware/xlnx-zynqmp-ufs.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * Firmware layer for UFS APIs. 4 + * 5 + * Copyright (c) 2025 Advanced Micro Devices, Inc. 6 + */ 7 + 8 + #ifndef __FIRMWARE_XLNX_ZYNQMP_UFS_H__ 9 + #define __FIRMWARE_XLNX_ZYNQMP_UFS_H__ 10 + 11 + #if IS_REACHABLE(CONFIG_ZYNQMP_FIRMWARE) 12 + int zynqmp_pm_is_mphy_tx_rx_config_ready(bool *is_ready); 13 + int zynqmp_pm_is_sram_init_done(bool *is_done); 14 + int zynqmp_pm_set_sram_bypass(void); 15 + int zynqmp_pm_get_ufs_calibration_values(u32 *val); 16 + #else 17 + static inline int zynqmp_pm_is_mphy_tx_rx_config_ready(bool *is_ready) 18 + { 19 + return -ENODEV; 20 + } 21 + 22 + static inline int zynqmp_pm_is_sram_init_done(bool *is_done) 23 + { 24 + return -ENODEV; 25 + } 26 + 27 + static inline int zynqmp_pm_set_sram_bypass(void) 28 + { 29 + return -ENODEV; 30 + } 31 + 32 + static inline int zynqmp_pm_get_ufs_calibration_values(u32 *val) 33 + { 34 + return -ENODEV; 35 + } 36 + #endif 37 + 38 + #endif /* __FIRMWARE_XLNX_ZYNQMP_UFS_H__ */
+16
include/linux/firmware/xlnx-zynqmp.h
··· 16 16 #include <linux/types.h> 17 17 18 18 #include <linux/err.h> 19 + #include <linux/firmware/xlnx-zynqmp-ufs.h> 19 20 20 21 #define ZYNQMP_PM_VERSION_MAJOR 1 21 22 #define ZYNQMP_PM_VERSION_MINOR 0 ··· 237 236 IOCTL_GET_FEATURE_CONFIG = 27, 238 237 /* IOCTL for Secure Read/Write Interface */ 239 238 IOCTL_READ_REG = 28, 239 + IOCTL_MASK_WRITE_REG = 29, 240 240 /* Dynamic SD/GEM configuration */ 241 241 IOCTL_SET_SD_CONFIG = 30, 242 242 IOCTL_SET_GEM_CONFIG = 31, ··· 616 614 int zynqmp_pm_is_function_supported(const u32 api_id, const u32 id); 617 615 int zynqmp_pm_set_feature_config(enum pm_feature_config_id id, u32 value); 618 616 int zynqmp_pm_get_feature_config(enum pm_feature_config_id id, u32 *payload); 617 + int zynqmp_pm_sec_read_reg(u32 node_id, u32 offset, u32 *ret_value); 618 + int zynqmp_pm_sec_mask_write_reg(const u32 node_id, const u32 offset, 619 + u32 mask, u32 value); 619 620 int zynqmp_pm_register_sgi(u32 sgi_num, u32 reset); 620 621 int zynqmp_pm_force_pwrdwn(const u32 target, 621 622 const enum zynqmp_pm_request_ack ack); ··· 914 909 const bool set_addr, 915 910 const u64 address, 916 911 const enum zynqmp_pm_request_ack ack) 912 + { 913 + return -ENODEV; 914 + } 915 + 916 + static inline int zynqmp_pm_sec_read_reg(u32 node_id, u32 offset, u32 *ret_value) 917 + { 918 + return -ENODEV; 919 + } 920 + 921 + static inline int zynqmp_pm_sec_mask_write_reg(const u32 node_id, const u32 offset, 922 + u32 mask, u32 value) 917 923 { 918 924 return -ENODEV; 919 925 }
+2 -2
include/scsi/scsi_dbg.h
··· 11 11 const unsigned char *, size_t); 12 12 extern void scsi_print_sense_hdr(const struct scsi_device *, const char *, 13 13 const struct scsi_sense_hdr *); 14 - extern void scsi_print_sense(const struct scsi_cmnd *); 14 + extern void scsi_print_sense(struct scsi_cmnd *); 15 15 extern void __scsi_print_sense(const struct scsi_device *, const char *name, 16 16 const unsigned char *sense_buffer, 17 17 int sense_len); 18 - extern void scsi_print_result(const struct scsi_cmnd *, const char *, int); 18 + extern void scsi_print_result(struct scsi_cmnd *, const char *, int); 19 19 20 20 #ifdef CONFIG_SCSI_CONSTANTS 21 21 extern bool scsi_opcode_sa_name(int, int, const char **, const char **);
+28 -2
include/scsi/scsi_device.h
··· 179 179 unsigned manage_shutdown:1; 180 180 181 181 /* 182 + * If true, let the high-level device driver (sd) manage the device 183 + * power state for system restart (reboot) operations. 184 + */ 185 + unsigned manage_restart:1; 186 + 187 + /* 182 188 * If set and if the device is runtime suspended, ask the high-level 183 189 * device driver (sd) to force a runtime resume of the device. 184 190 */ ··· 319 313 #define sdev_printk(l, sdev, fmt, a...) \ 320 314 sdev_prefix_printk(l, sdev, NULL, fmt, ##a) 321 315 322 - __printf(3, 4) void 323 - scmd_printk(const char *, const struct scsi_cmnd *, const char *, ...); 316 + __printf(3, 4) void scmd_printk(const char *, struct scsi_cmnd *, const char *, 317 + ...); 324 318 325 319 #define scmd_dbg(scmd, fmt, a...) \ 326 320 do { \ ··· 564 558 const struct scsi_exec_args *args); 565 559 void scsi_failures_reset_retries(struct scsi_failures *failures); 566 560 561 + struct scsi_cmnd *scsi_get_internal_cmd(struct scsi_device *sdev, 562 + enum dma_data_direction data_direction, 563 + blk_mq_req_flags_t flags); 564 + void scsi_put_internal_cmd(struct scsi_cmnd *scmd); 567 565 extern void sdev_disable_disk_events(struct scsi_device *sdev); 568 566 extern void sdev_enable_disk_events(struct scsi_device *sdev); 569 567 extern int scsi_vpd_lun_id(struct scsi_device *, char *, size_t); ··· 598 588 599 589 #define scmd_id(scmd) sdev_id((scmd)->device) 600 590 #define scmd_channel(scmd) sdev_channel((scmd)->device) 591 + 592 + /** 593 + * scsi_device_is_pseudo_dev() - Whether a device is a pseudo SCSI device. 594 + * @sdev: SCSI device to examine 595 + * 596 + * A pseudo SCSI device can be used to allocate SCSI commands but does not show 597 + * up in sysfs. Additionally, the logical unit information in *@sdev is made up. 598 + * 599 + * This function tests the LUN number instead of comparing @sdev with 600 + * @sdev->host->pseudo_sdev because this function may be called before 601 + * @sdev->host->pseudo_sdev has been initialized. 602 + */ 603 + static inline bool scsi_device_is_pseudo_dev(struct scsi_device *sdev) 604 + { 605 + return sdev->lun == U64_MAX; 606 + } 601 607 602 608 /* 603 609 * checks for positions of the SCSI state machine
+32 -1
include/scsi/scsi_host.h
··· 87 87 int (* queuecommand)(struct Scsi_Host *, struct scsi_cmnd *); 88 88 89 89 /* 90 + * Queue a reserved command (BLK_MQ_REQ_RESERVED). The .queuecommand() 91 + * documentation also applies to the .queue_reserved_command() callback. 92 + */ 93 + int (*queue_reserved_command)(struct Scsi_Host *, struct scsi_cmnd *); 94 + 95 + /* 90 96 * The commit_rqs function is used to trigger a hardware 91 97 * doorbell after some requests have been queued with 92 98 * queuecommand, when an error is encountered before sending ··· 381 375 /* 382 376 * This determines if we will use a non-interrupt driven 383 377 * or an interrupt driven scheme. It is set to the maximum number 384 - * of simultaneous commands a single hw queue in HBA will accept. 378 + * of simultaneous commands a single hw queue in HBA will accept 379 + * excluding internal commands. 385 380 */ 386 381 int can_queue; 382 + 383 + /* 384 + * This determines how many commands the HBA will set aside 385 + * for internal commands. This number will be added to 386 + * @can_queue to calculate the maximum number of simultaneous 387 + * commands sent to the host. 388 + */ 389 + int nr_reserved_cmds; 387 390 388 391 /* 389 392 * In many instances, especially where disconnect / reconnect are ··· 626 611 unsigned short max_cmd_len; 627 612 628 613 int this_id; 614 + 615 + /* 616 + * Number of commands this host can handle at the same time. 617 + * This excludes reserved commands as specified by nr_reserved_cmds. 618 + */ 629 619 int can_queue; 620 + /* 621 + * Number of reserved commands to allocate, if any. 622 + */ 623 + unsigned int nr_reserved_cmds; 624 + 630 625 short cmd_per_lun; 631 626 short unsigned int sg_tablesize; 632 627 short unsigned int sg_prot_tablesize; ··· 726 701 727 702 /* ldm bits */ 728 703 struct device shost_gendev, shost_dev; 704 + 705 + /* 706 + * A SCSI device structure used for sending internal commands to the 707 + * HBA. There is no corresponding logical unit inside the SCSI device. 708 + */ 709 + struct scsi_device *pseudo_sdev; 729 710 730 711 /* 731 712 * Points to the transport data (if any) which is allocated
+4 -2
include/target/target_core_backend.h
··· 121 121 122 122 bool target_sense_desc_format(struct se_device *dev); 123 123 sector_t target_to_linux_sector(struct se_device *dev, sector_t lb); 124 - bool target_configure_unmap_from_queue(struct se_dev_attrib *attrib, 125 - struct block_device *bdev); 124 + bool target_configure_unmap_from_bdev(struct se_dev_attrib *attrib, 125 + struct block_device *bdev); 126 + void target_configure_write_atomic_from_bdev(struct se_dev_attrib *attrib, 127 + struct block_device *bdev); 126 128 127 129 static inline bool target_dev_configured(struct se_device *se_dev) 128 130 {
+16 -10
include/target/target_core_base.h
··· 158 158 SCF_TASK_ATTR_SET = (1 << 17), 159 159 SCF_TREAT_READ_AS_NORMAL = (1 << 18), 160 160 SCF_TASK_ORDERED_SYNC = (1 << 19), 161 + SCF_ATOMIC = (1 << 20), 161 162 }; 162 163 163 164 /* ··· 672 671 }; 673 672 674 673 struct se_dev_entry_io_stats { 675 - u32 total_cmds; 676 - u32 read_bytes; 677 - u32 write_bytes; 674 + u64 total_cmds; 675 + u64 read_bytes; 676 + u64 write_bytes; 678 677 }; 679 678 680 679 struct se_dev_entry { ··· 732 731 u32 unmap_granularity; 733 732 u32 unmap_granularity_alignment; 734 733 u32 max_write_same_len; 734 + u32 atomic_max_len; 735 + u32 atomic_alignment; 736 + u32 atomic_granularity; 737 + u32 atomic_max_with_boundary; 738 + u32 atomic_max_boundary; 735 739 u8 submit_type; 736 740 struct se_device *da_dev; 737 741 struct config_group da_group; ··· 750 744 }; 751 745 752 746 struct scsi_port_stats { 753 - atomic_long_t cmd_pdus; 754 - atomic_long_t tx_data_octets; 755 - atomic_long_t rx_data_octets; 747 + u64 cmd_pdus; 748 + u64 tx_data_octets; 749 + u64 rx_data_octets; 756 750 }; 757 751 758 752 struct se_lun { ··· 779 773 spinlock_t lun_tg_pt_gp_lock; 780 774 781 775 struct se_portal_group *lun_tpg; 782 - struct scsi_port_stats lun_stats; 776 + struct scsi_port_stats __percpu *lun_stats; 783 777 struct config_group lun_group; 784 778 struct se_port_stat_grps port_stat_grps; 785 779 struct completion lun_shutdown_comp; ··· 812 806 }; 813 807 814 808 struct se_dev_io_stats { 815 - u32 total_cmds; 816 - u32 read_bytes; 817 - u32 write_bytes; 809 + u64 total_cmds; 810 + u64 read_bytes; 811 + u64 write_bytes; 818 812 }; 819 813 820 814 struct se_device {
+5
include/ufs/ufs.h
··· 651 651 u8 rtt_cap; /* bDeviceRTTCap */ 652 652 653 653 bool hid_sup; 654 + 655 + /* Unique device ID string (manufacturer+model+serial+version+date) */ 656 + char *device_id; 657 + u8 rpmb_io_size; 658 + u8 rpmb_region_size[4]; 654 659 }; 655 660 656 661 #endif /* End of Header */
-7
include/ufs/ufs_quirks.h
··· 101 101 #define UFS_DEVICE_QUIRK_SUPPORT_EXTENDED_FEATURES (1 << 10) 102 102 103 103 /* 104 - * Some UFS devices require delay after VCC power rail is turned-off. 105 - * Enable this quirk to introduce 5ms delays after VCC power-off during 106 - * suspend flow. 107 - */ 108 - #define UFS_DEVICE_QUIRK_DELAY_AFTER_LPM (1 << 11) 109 - 110 - /* 111 104 * Some ufs devices may need more time to be in hibern8 before exiting. 112 105 * Enable this quirk to give it an additional 100us. 113 106 */
+9 -20
include/ufs/ufshcd.h
··· 78 78 const u32 argument1; 79 79 u32 argument2; 80 80 u32 argument3; 81 - int cmd_active; 81 + bool cmd_active; 82 82 struct completion done; 83 83 }; 84 84 ··· 161 161 * @ucd_prdt_dma_addr: PRDT dma address for debug 162 162 * @ucd_rsp_dma_addr: UPIU response dma address for debug 163 163 * @ucd_req_dma_addr: UPIU request dma address for debug 164 - * @cmd: pointer to SCSI command 165 164 * @scsi_status: SCSI status of the command 166 165 * @command_type: SCSI, UFS, Query. 167 166 * @task_tag: Task tag of the command ··· 185 186 dma_addr_t ucd_rsp_dma_addr; 186 187 dma_addr_t ucd_prdt_dma_addr; 187 188 188 - struct scsi_cmnd *cmd; 189 189 int scsi_status; 190 190 191 191 int command_type; 192 - int task_tag; 193 192 u8 lun; /* UPIU LUN id field is only 8-bit wide */ 194 193 bool intr_cmd; 195 194 bool req_abort_skip; ··· 236 239 * struct ufs_dev_cmd - all assosiated fields with device management commands 237 240 * @type: device management command type - Query, NOP OUT 238 241 * @lock: lock to allow one command at a time 239 - * @complete: internal commands completion 240 242 * @query: Device management query information 241 243 */ 242 244 struct ufs_dev_cmd { 243 245 enum dev_cmd_type type; 244 246 struct mutex lock; 245 - struct completion complete; 246 247 struct ufs_query query; 247 248 }; 248 249 ··· 828 833 * @host: Scsi_Host instance of the driver 829 834 * @dev: device handle 830 835 * @ufs_device_wlun: WLUN that controls the entire UFS device. 836 + * @ufs_rpmb_wlun: RPMB WLUN SCSI device 831 837 * @hwmon_device: device instance registered with the hwmon core. 832 838 * @curr_dev_pwr_mode: active UFS device power mode. 833 839 * @uic_link_state: active state of the link to the UFS device. ··· 836 840 * @spm_lvl: desired UFS power management level during system PM. 837 841 * @pm_op_in_progress: whether or not a PM operation is in progress. 838 842 * @ahit: value of Auto-Hibernate Idle Timer register. 839 - * @lrb: local reference block 840 843 * @outstanding_tasks: Bits representing outstanding task requests 841 844 * @outstanding_lock: Protects @outstanding_reqs. 842 845 * @outstanding_reqs: Bits representing outstanding transfer requests ··· 844 849 * @nutrs: Transfer Request Queue depth supported by controller 845 850 * @nortt - Max outstanding RTTs supported by controller 846 851 * @nutmrs: Task Management Queue depth supported by controller 847 - * @reserved_slot: Used to submit device commands. Protected by @dev_cmd.lock. 848 852 * @ufs_version: UFS Version to which controller complies 849 853 * @vops: pointer to variant specific operations 850 854 * @vps: pointer to variant specific parameters ··· 934 940 * @res: array of resource info of MCQ registers 935 941 * @mcq_base: Multi circular queue registers base address 936 942 * @uhq: array of supported hardware queues 937 - * @dev_cmd_queue: Queue for issuing device management commands 938 943 * @mcq_opr: MCQ operation and runtime registers 939 944 * @ufs_rtc_update_work: A work for UFS RTC periodic update 940 945 * @pm_qos_req: PM QoS request handle ··· 941 948 * @pm_qos_mutex: synchronizes PM QoS request and status updates 942 949 * @critical_health_count: count of critical health exceptions 943 950 * @dev_lvl_exception_count: count of device level exceptions since last reset 944 - * @dev_lvl_exception_id: vendor specific information about the 945 - * device level exception event. 951 + * @dev_lvl_exception_id: vendor specific information about the device level exception event. 952 + * @rpmbs: list of OP-TEE RPMB devices (one per RPMB region) 946 953 */ 947 954 struct ufs_hba { 948 955 void __iomem *mmio_base; ··· 960 967 struct Scsi_Host *host; 961 968 struct device *dev; 962 969 struct scsi_device *ufs_device_wlun; 970 + struct scsi_device *ufs_rpmb_wlun; 963 971 964 972 #ifdef CONFIG_SCSI_UFS_HWMON 965 973 struct device *hwmon_device; ··· 977 983 /* Auto-Hibernate Idle Timer register value */ 978 984 u32 ahit; 979 985 980 - struct ufshcd_lrb *lrb; 981 - 982 986 unsigned long outstanding_tasks; 983 987 spinlock_t outstanding_lock; 984 988 unsigned long outstanding_reqs; ··· 986 994 int nortt; 987 995 u32 mcq_capabilities; 988 996 int nutmrs; 989 - u32 reserved_slot; 990 997 u32 ufs_version; 991 998 const struct ufs_hba_variant_ops *vops; 992 999 struct ufs_hba_variant_params *vps; ··· 1103 1112 bool mcq_esi_enabled; 1104 1113 void __iomem *mcq_base; 1105 1114 struct ufs_hw_queue *uhq; 1106 - struct ufs_hw_queue *dev_cmd_queue; 1107 1115 struct ufshcd_mcq_opr_info_t mcq_opr[OPR_MAX]; 1108 1116 1109 1117 struct delayed_work ufs_rtc_update_work; ··· 1114 1124 int critical_health_count; 1115 1125 atomic_t dev_lvl_exception_count; 1116 1126 u64 dev_lvl_exception_id; 1127 + u32 vcc_off_delay_us; 1128 + struct list_head rpmbs; 1117 1129 }; 1118 1130 1119 1131 /** ··· 1294 1302 1295 1303 void ufshcd_enable_irq(struct ufs_hba *hba); 1296 1304 void ufshcd_disable_irq(struct ufs_hba *hba); 1297 - void ufshcd_enable_intr(struct ufs_hba *hba, u32 intrs); 1298 1305 int ufshcd_alloc_host(struct device *, struct ufs_hba **); 1299 1306 int ufshcd_hba_enable(struct ufs_hba *hba); 1300 1307 int ufshcd_init(struct ufs_hba *, void __iomem *, unsigned int); ··· 1429 1438 void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit); 1430 1439 void ufshcd_fixup_dev_quirks(struct ufs_hba *hba, 1431 1440 const struct ufs_dev_quirk *fixups); 1432 - #define SD_ASCII_STD true 1433 - #define SD_RAW false 1434 - int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, 1435 - u8 **buf, bool ascii); 1436 1441 1437 1442 void ufshcd_hold(struct ufs_hba *hba); 1438 1443 void ufshcd_release(struct ufs_hba *hba); ··· 1481 1494 int ufshcd_update_ee_control(struct ufs_hba *hba, u16 *mask, 1482 1495 const u16 *other_mask, u16 set, u16 clr); 1483 1496 void ufshcd_force_error_recovery(struct ufs_hba *hba); 1497 + void ufshcd_pm_qos_update(struct ufs_hba *hba, bool on); 1498 + u32 ufshcd_us_to_ahit(unsigned int timer); 1484 1499 1485 1500 #endif /* End of Header */
+22 -3
include/ufs/ufshci.h
··· 83 83 }; 84 84 85 85 enum { 86 + /* Submission Queue (SQ) Configuration Registers */ 86 87 REG_SQATTR = 0x0, 87 88 REG_SQLBA = 0x4, 88 89 REG_SQUBA = 0x8, 89 90 REG_SQDAO = 0xC, 90 91 REG_SQISAO = 0x10, 91 92 93 + /* Completion Queue (CQ) Configuration Registers */ 92 94 REG_CQATTR = 0x20, 93 95 REG_CQLBA = 0x24, 94 96 REG_CQUBA = 0x28, ··· 98 96 REG_CQISAO = 0x30, 99 97 }; 100 98 99 + /* Operation and Runtime Registers - Submission Queues and Completion Queues */ 101 100 enum { 102 101 REG_SQHP = 0x0, 103 102 REG_SQTP = 0x4, ··· 572 569 __le16 prd_table_offset; 573 570 574 571 /* DW 4 */ 575 - __le32 status; 572 + u8 overall_status; 573 + u8 extended_error_code; 574 + __le16 reserved_1; 576 575 577 - /* DW 5-7 */ 578 - __le32 reserved[3]; 576 + /* DW 5 */ 577 + u8 task_tag; 578 + u8 lun; 579 + #if defined(__BIG_ENDIAN) 580 + u8 ext_iid:4; 581 + u8 iid:4; 582 + #elif defined(__LITTLE_ENDIAN) 583 + u8 iid:4; 584 + u8 ext_iid:4; 585 + #else 586 + #error 587 + #endif 588 + u8 reserved_2; 589 + 590 + /* DW 6-7 */ 591 + __le32 reserved_3[2]; 579 592 }; 580 593 581 594 static_assert(sizeof(struct cq_entry) == 32);
+7 -1
include/ufs/unipro.h
··· 111 111 #define PA_TXLINKSTARTUPHS 0x1544 112 112 #define PA_AVAILRXDATALANES 0x1540 113 113 #define PA_MINRXTRAILINGCLOCKS 0x1543 114 + #define PA_TXHSG1SYNCLENGTH 0x1552 115 + #define PA_TXHSG2SYNCLENGTH 0x1554 116 + #define PA_TXHSG3SYNCLENGTH 0x1556 114 117 #define PA_LOCAL_TX_LCC_ENABLE 0x155E 115 118 #define PA_ACTIVETXDATALANES 0x1560 116 119 #define PA_CONNECTEDTXDATALANES 0x1561 ··· 163 160 #define PA_PACPFRAMECOUNT 0x15C0 164 161 #define PA_PACPERRORCOUNT 0x15C1 165 162 #define PA_PHYTESTCONTROL 0x15C2 166 - #define PA_TXHSADAPTTYPE 0x15D4 163 + #define PA_TXHSG4SYNCLENGTH 0x15D0 164 + #define PA_TXHSADAPTTYPE 0x15D4 165 + #define PA_TXHSG5SYNCLENGTH 0x15D6 167 166 168 167 /* Adpat type for PA_TXHSADAPTTYPE attribute */ 169 168 #define PA_REFRESH_ADAPT 0x00 ··· 179 174 #define VS_POWERSTATE 0xD083 180 175 #define VS_MPHYCFGUPDT 0xD085 181 176 #define VS_DEBUGOMC 0xD09E 177 + #define VS_MPHYDISABLE 0xD0C1 182 178 183 179 #define PA_GRANULARITY_MIN_VAL 1 184 180 #define PA_GRANULARITY_MAX_VAL 6