Commit 15e70f0d authored by Martin K. Petersen's avatar Martin K. Petersen

Merge patch series "Add Multi Circular Queue Support"

Asutosh Das <quic_asutoshd@quicinc.com> says:

This patch series is an implementation of UFS Multi-Circular Queue.
Please consider this series for next merge window.  This
implementation has been verified on a Qualcomm & MediaTek platform.

UFS Multi-Circular Queue (MCQ) has been added in UFSHCI v4.0 to
improve storage performance.  The implementation uses the shared
tagging mechanism so that tags are shared among the hardware
queues. The number of hardware queues is configurable.  This series
doesn't include the ESI implementation for completion handling.

Link: https://lore.kernel.org/r/cover.1673557949.git.quic_asutoshd@quicinc.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parents 64b6dead eacb139b
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o
ufshcd-core-y += ufshcd.o ufs-sysfs.o
ufshcd-core-y += ufshcd.o ufs-sysfs.o ufs-mcq.o
ufshcd-core-$(CONFIG_DEBUG_FS) += ufs-debugfs.o
ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o
ufshcd-core-$(CONFIG_SCSI_UFS_CRYPTO) += ufshcd-crypto.o
......
This diff is collapsed.
......@@ -61,7 +61,24 @@ int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode,
int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode,
enum flag_idn idn, u8 index, bool *flag_res);
void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit);
void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag,
struct cq_entry *cqe);
int ufshcd_mcq_init(struct ufs_hba *hba);
int ufshcd_mcq_decide_queue_depth(struct ufs_hba *hba);
int ufshcd_mcq_memory_alloc(struct ufs_hba *hba);
void ufshcd_mcq_make_queues_operational(struct ufs_hba *hba);
void ufshcd_mcq_config_mac(struct ufs_hba *hba, u32 max_active_cmds);
void ufshcd_mcq_select_mcq_mode(struct ufs_hba *hba);
u32 ufshcd_mcq_read_cqis(struct ufs_hba *hba, int i);
void ufshcd_mcq_write_cqis(struct ufs_hba *hba, u32 val, int i);
unsigned long ufshcd_mcq_poll_cqe_nolock(struct ufs_hba *hba,
struct ufs_hw_queue *hwq);
struct ufs_hw_queue *ufshcd_mcq_req_to_hwq(struct ufs_hba *hba,
struct request *req);
unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba,
struct ufs_hw_queue *hwq);
#define UFSHCD_MCQ_IO_QUEUE_OFFSET 1
#define SD_ASCII_STD true
#define SD_RAW false
int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index,
......@@ -229,6 +246,39 @@ static inline void ufshcd_vops_reinit_notify(struct ufs_hba *hba)
hba->vops->reinit_notify(hba);
}
static inline int ufshcd_vops_mcq_config_resource(struct ufs_hba *hba)
{
if (hba->vops && hba->vops->mcq_config_resource)
return hba->vops->mcq_config_resource(hba);
return -EOPNOTSUPP;
}
static inline int ufshcd_mcq_vops_get_hba_mac(struct ufs_hba *hba)
{
if (hba->vops && hba->vops->get_hba_mac)
return hba->vops->get_hba_mac(hba);
return -EOPNOTSUPP;
}
static inline int ufshcd_mcq_vops_op_runtime_config(struct ufs_hba *hba)
{
if (hba->vops && hba->vops->op_runtime_config)
return hba->vops->op_runtime_config(hba);
return -EOPNOTSUPP;
}
static inline int ufshcd_vops_get_outstanding_cqs(struct ufs_hba *hba,
unsigned long *ocqs)
{
if (hba->vops && hba->vops->get_outstanding_cqs)
return hba->vops->get_outstanding_cqs(hba, ocqs);
return -EOPNOTSUPP;
}
extern const struct ufs_pm_lvl_states ufs_pm_lvl_states[];
/**
......@@ -305,4 +355,44 @@ static inline bool ufs_is_valid_unit_desc_lun(struct ufs_dev_info *dev_info, u8
return lun == UFS_UPIU_RPMB_WLUN || (lun < dev_info->max_lu_supported);
}
static inline void ufshcd_inc_sq_tail(struct ufs_hw_queue *q)
{
u32 mask = q->max_entries - 1;
u32 val;
q->sq_tail_slot = (q->sq_tail_slot + 1) & mask;
val = q->sq_tail_slot * sizeof(struct utp_transfer_req_desc);
writel(val, q->mcq_sq_tail);
}
static inline void ufshcd_mcq_update_cq_tail_slot(struct ufs_hw_queue *q)
{
u32 val = readl(q->mcq_cq_tail);
q->cq_tail_slot = val / sizeof(struct cq_entry);
}
static inline bool ufshcd_mcq_is_cq_empty(struct ufs_hw_queue *q)
{
return q->cq_head_slot == q->cq_tail_slot;
}
static inline void ufshcd_mcq_inc_cq_head_slot(struct ufs_hw_queue *q)
{
q->cq_head_slot++;
if (q->cq_head_slot == q->max_entries)
q->cq_head_slot = 0;
}
static inline void ufshcd_mcq_update_cq_head(struct ufs_hw_queue *q)
{
writel(q->cq_head_slot * sizeof(struct cq_entry), q->mcq_cq_head);
}
static inline struct cq_entry *ufshcd_mcq_cur_cqe(struct ufs_hw_queue *q)
{
struct cq_entry *cqe = q->cqe_base_addr;
return cqe + q->cq_head_slot;
}
#endif /* _UFSHCD_PRIV_H_ */
This diff is collapsed.
......@@ -22,6 +22,12 @@
#include <ufs/ufshci.h>
#include <ufs/ufs_quirks.h>
#define MCQ_QCFGPTR_MASK GENMASK(7, 0)
#define MCQ_QCFGPTR_UNIT 0x200
#define MCQ_SQATTR_OFFSET(c) \
((((c) >> 16) & MCQ_QCFGPTR_MASK) * MCQ_QCFGPTR_UNIT)
#define MCQ_QCFG_SIZE 0x40
enum {
TSTBUS_UAWM,
TSTBUS_UARM,
......@@ -1396,6 +1402,142 @@ static void ufs_qcom_reinit_notify(struct ufs_hba *hba)
phy_power_off(host->generic_phy);
}
/* Resources */
static const struct ufshcd_res_info ufs_res_info[RES_MAX] = {
{.name = "ufs_mem",},
{.name = "mcq",},
/* Submission Queue DAO */
{.name = "mcq_sqd",},
/* Submission Queue Interrupt Status */
{.name = "mcq_sqis",},
/* Completion Queue DAO */
{.name = "mcq_cqd",},
/* Completion Queue Interrupt Status */
{.name = "mcq_cqis",},
/* MCQ vendor specific */
{.name = "mcq_vs",},
};
static int ufs_qcom_mcq_config_resource(struct ufs_hba *hba)
{
struct platform_device *pdev = to_platform_device(hba->dev);
struct ufshcd_res_info *res;
struct resource *res_mem, *res_mcq;
int i, ret = 0;
memcpy(hba->res, ufs_res_info, sizeof(ufs_res_info));
for (i = 0; i < RES_MAX; i++) {
res = &hba->res[i];
res->resource = platform_get_resource_byname(pdev,
IORESOURCE_MEM,
res->name);
if (!res->resource) {
dev_info(hba->dev, "Resource %s not provided\n", res->name);
if (i == RES_UFS)
return -ENOMEM;
continue;
} else if (i == RES_UFS) {
res_mem = res->resource;
res->base = hba->mmio_base;
continue;
}
res->base = devm_ioremap_resource(hba->dev, res->resource);
if (IS_ERR(res->base)) {
dev_err(hba->dev, "Failed to map res %s, err=%d\n",
res->name, (int)PTR_ERR(res->base));
res->base = NULL;
ret = PTR_ERR(res->base);
return ret;
}
}
/* MCQ resource provided in DT */
res = &hba->res[RES_MCQ];
/* Bail if MCQ resource is provided */
if (res->base)
goto out;
/* Explicitly allocate MCQ resource from ufs_mem */
res_mcq = devm_kzalloc(hba->dev, sizeof(*res_mcq), GFP_KERNEL);
if (!res_mcq)
return ret;
res_mcq->start = res_mem->start +
MCQ_SQATTR_OFFSET(hba->mcq_capabilities);
res_mcq->end = res_mcq->start + hba->nr_hw_queues * MCQ_QCFG_SIZE - 1;
res_mcq->flags = res_mem->flags;
res_mcq->name = "mcq";
ret = insert_resource(&iomem_resource, res_mcq);
if (ret) {
dev_err(hba->dev, "Failed to insert MCQ resource, err=%d\n",
ret);
goto insert_res_err;
}
res->base = devm_ioremap_resource(hba->dev, res_mcq);
if (IS_ERR(res->base)) {
dev_err(hba->dev, "MCQ registers mapping failed, err=%d\n",
(int)PTR_ERR(res->base));
ret = PTR_ERR(res->base);
goto ioremap_err;
}
out:
hba->mcq_base = res->base;
return 0;
ioremap_err:
res->base = NULL;
remove_resource(res_mcq);
insert_res_err:
devm_kfree(hba->dev, res_mcq);
return ret;
}
static int ufs_qcom_op_runtime_config(struct ufs_hba *hba)
{
struct ufshcd_res_info *mem_res, *sqdao_res;
struct ufshcd_mcq_opr_info_t *opr;
int i;
mem_res = &hba->res[RES_UFS];
sqdao_res = &hba->res[RES_MCQ_SQD];
if (!mem_res->base || !sqdao_res->base)
return -EINVAL;
for (i = 0; i < OPR_MAX; i++) {
opr = &hba->mcq_opr[i];
opr->offset = sqdao_res->resource->start -
mem_res->resource->start + 0x40 * i;
opr->stride = 0x100;
opr->base = sqdao_res->base + 0x40 * i;
}
return 0;
}
static int ufs_qcom_get_hba_mac(struct ufs_hba *hba)
{
/* Qualcomm HC supports up to 64 */
return MAX_SUPP_MAC;
}
static int ufs_qcom_get_outstanding_cqs(struct ufs_hba *hba,
unsigned long *ocqs)
{
struct ufshcd_res_info *mcq_vs_res = &hba->res[RES_MCQ_VS];
if (!mcq_vs_res->base)
return -EINVAL;
*ocqs = readl(mcq_vs_res->base + UFS_MEM_CQIS_VS);
return 0;
}
/*
* struct ufs_hba_qcom_vops - UFS QCOM specific variant operations
*
......@@ -1420,6 +1562,10 @@ static const struct ufs_hba_variant_ops ufs_hba_qcom_vops = {
.config_scaling_param = ufs_qcom_config_scaling_param,
.program_key = ufs_qcom_ice_program_key,
.reinit_notify = ufs_qcom_reinit_notify,
.mcq_config_resource = ufs_qcom_mcq_config_resource,
.get_hba_mac = ufs_qcom_get_hba_mac,
.op_runtime_config = ufs_qcom_op_runtime_config,
.get_outstanding_cqs = ufs_qcom_get_outstanding_cqs,
};
/**
......
......@@ -16,6 +16,7 @@
#define HBRN8_POLL_TOUT_MS 100
#define DEFAULT_CLK_RATE_HZ 1000000
#define BUS_VECTOR_NAME_LEN 32
#define MAX_SUPP_MAC 64
#define UFS_HW_VER_MAJOR_MASK GENMASK(31, 28)
#define UFS_HW_VER_MINOR_MASK GENMASK(27, 16)
......@@ -70,6 +71,10 @@ enum {
UFS_UFS_DBG_RD_EDTL_RAM = 0x1900,
};
enum {
UFS_MEM_CQIS_VS = 0x8,
};
#define UFS_CNTLR_2_x_x_VEN_REGS_OFFSET(x) (0x000 + x)
#define UFS_CNTLR_3_x_x_VEN_REGS_OFFSET(x) (0x400 + x)
......
......@@ -169,6 +169,7 @@ enum attr_idn {
QUERY_ATTR_IDN_AVAIL_WB_BUFF_SIZE = 0x1D,
QUERY_ATTR_IDN_WB_BUFF_LIFE_TIME_EST = 0x1E,
QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE = 0x1F,
QUERY_ATTR_IDN_EXT_IID_EN = 0x2A,
};
/* Descriptor idn for Query requests */
......@@ -378,6 +379,7 @@ enum {
UFS_DEV_EXT_TEMP_NOTIF = BIT(6),
UFS_DEV_HPB_SUPPORT = BIT(7),
UFS_DEV_WRITE_BOOSTER_SUP = BIT(8),
UFS_DEV_EXT_IID_SUP = BIT(16),
};
#define UFS_DEV_HPB_SUPPORT_VERSION 0x310
......@@ -615,6 +617,8 @@ struct ufs_dev_info {
u8 *model;
u16 wspecversion;
u32 clk_gating_wait_us;
/* Stores the depth of queue in UFS device */
u8 bqueuedepth;
/* UFS HPB related flag */
bool hpb_enabled;
......@@ -629,6 +633,9 @@ struct ufs_dev_info {
u8 b_presrv_uspc_en;
bool b_advanced_rpmb_en;
/* UFS EXT_IID Enable */
bool b_ext_iid_en;
};
/*
......
......@@ -224,6 +224,7 @@ struct ufs_dev_cmd {
struct mutex lock;
struct completion *complete;
struct ufs_query query;
struct cq_entry *cqe;
};
/**
......@@ -300,6 +301,10 @@ struct ufs_pwr_mode_info {
* @program_key: program or evict an inline encryption key
* @event_notify: called to notify important events
* @reinit_notify: called to notify reinit of UFSHCD during max gear switch
* @mcq_config_resource: called to configure MCQ platform resources
* @get_hba_mac: called to get vendor specific mac value, mandatory for mcq mode
* @op_runtime_config: called to config Operation and runtime regs Pointers
* @get_outstanding_cqs: called to get outstanding completion queues
*/
struct ufs_hba_variant_ops {
const char *name;
......@@ -339,6 +344,11 @@ struct ufs_hba_variant_ops {
void (*event_notify)(struct ufs_hba *hba,
enum ufs_event_type evt, void *data);
void (*reinit_notify)(struct ufs_hba *);
int (*mcq_config_resource)(struct ufs_hba *hba);
int (*get_hba_mac)(struct ufs_hba *hba);
int (*op_runtime_config)(struct ufs_hba *hba);
int (*get_outstanding_cqs)(struct ufs_hba *hba,
unsigned long *ocqs);
};
/* clock gating state */
......@@ -733,6 +743,51 @@ struct ufs_hba_monitor {
bool enabled;
};
/**
* struct ufshcd_res_info_t - MCQ related resource regions
*
* @name: resource name
* @resource: pointer to resource region
* @base: register base address
*/
struct ufshcd_res_info {
const char *name;
struct resource *resource;
void __iomem *base;
};
enum ufshcd_res {
RES_UFS,
RES_MCQ,
RES_MCQ_SQD,
RES_MCQ_SQIS,
RES_MCQ_CQD,
RES_MCQ_CQIS,
RES_MCQ_VS,
RES_MAX,
};
/**
* struct ufshcd_mcq_opr_info_t - Operation and Runtime registers
*
* @offset: Doorbell Address Offset
* @stride: Steps proportional to queue [0...31]
* @base: base address
*/
struct ufshcd_mcq_opr_info_t {
unsigned long offset;
unsigned long stride;
void __iomem *base;
};
enum ufshcd_mcq_opr {
OPR_SQD,
OPR_SQIS,
OPR_CQD,
OPR_CQIS,
OPR_MAX,
};
/**
* struct ufs_hba - per adapter private structure
* @mmio_base: UFSHCI base register address
......@@ -757,6 +812,7 @@ struct ufs_hba_monitor {
* @outstanding_lock: Protects @outstanding_reqs.
* @outstanding_reqs: Bits representing outstanding transfer requests
* @capabilities: UFS Controller Capabilities
* @mcq_capabilities: UFS Multi Circular Queue capabilities
* @nutrs: Transfer Request Queue depth supported by controller
* @nutmrs: Task Management Queue depth supported by controller
* @reserved_slot: Used to submit device commands. Protected by @dev_cmd.lock.
......@@ -839,8 +895,17 @@ struct ufs_hba_monitor {
* ee_ctrl_mask
* @luns_avail: number of regular and well known LUNs supported by the UFS
* device
* @nr_hw_queues: number of hardware queues configured
* @nr_queues: number of Queues of different queue types
* @complete_put: whether or not to call ufshcd_rpm_put() from inside
* ufshcd_resume_complete()
* @ext_iid_sup: is EXT_IID is supported by UFSHC
* @mcq_sup: is mcq supported by UFSHC
* @mcq_enabled: is mcq ready to accept requests
* @res: array of resource info of MCQ registers
* @mcq_base: Multi circular queue registers base address
* @uhq: array of supported hardware queues
* @dev_cmd_queue: Queue for issuing device management commands
*/
struct ufs_hba {
void __iomem *mmio_base;
......@@ -882,6 +947,7 @@ struct ufs_hba {
u32 capabilities;
int nutrs;
u32 mcq_capabilities;
int nutmrs;
u32 reserved_slot;
u32 ufs_version;
......@@ -990,9 +1056,62 @@ struct ufs_hba {
u32 debugfs_ee_rate_limit_ms;
#endif
u32 luns_avail;
unsigned int nr_hw_queues;
unsigned int nr_queues[HCTX_MAX_TYPES];
bool complete_put;
bool ext_iid_sup;
bool scsi_host_added;
bool mcq_sup;
bool mcq_enabled;
struct ufshcd_res_info res[RES_MAX];
void __iomem *mcq_base;
struct ufs_hw_queue *uhq;
struct ufs_hw_queue *dev_cmd_queue;
struct ufshcd_mcq_opr_info_t mcq_opr[OPR_MAX];
};
/**
* struct ufs_hw_queue - per hardware queue structure
* @mcq_sq_head: base address of submission queue head pointer
* @mcq_sq_tail: base address of submission queue tail pointer
* @mcq_cq_head: base address of completion queue head pointer
* @mcq_cq_tail: base address of completion queue tail pointer
* @sqe_base_addr: submission queue entry base address
* @sqe_dma_addr: submission queue dma address
* @cqe_base_addr: completion queue base address
* @cqe_dma_addr: completion queue dma address
* @max_entries: max number of slots in this hardware queue
* @id: hardware queue ID
* @sq_tp_slot: current slot to which SQ tail pointer is pointing
* @sq_lock: serialize submission queue access
* @cq_tail_slot: current slot to which CQ tail pointer is pointing
* @cq_head_slot: current slot to which CQ head pointer is pointing
* @cq_lock: Synchronize between multiple polling instances
*/
struct ufs_hw_queue {
void __iomem *mcq_sq_head;
void __iomem *mcq_sq_tail;
void __iomem *mcq_cq_head;
void __iomem *mcq_cq_tail;
void *sqe_base_addr;
dma_addr_t sqe_dma_addr;
struct cq_entry *cqe_base_addr;
dma_addr_t cqe_dma_addr;
u32 max_entries;
u32 id;
u32 sq_tail_slot;
spinlock_t sq_lock;
u32 cq_tail_slot;
u32 cq_head_slot;
spinlock_t cq_lock;
};
static inline bool is_mcq_enabled(struct ufs_hba *hba)
{
return hba->mcq_enabled;
}
#ifdef CONFIG_SCSI_UFS_VARIABLE_SG_ENTRY_SIZE
static inline size_t ufshcd_sg_entry_size(const struct ufs_hba *hba)
{
......@@ -1074,6 +1193,16 @@ static inline bool ufshcd_enable_wb_if_scaling_up(struct ufs_hba *hba)
return hba->caps & UFSHCD_CAP_WB_WITH_CLK_SCALING;
}
#define ufsmcq_writel(hba, val, reg) \
writel((val), (hba)->mcq_base + (reg))
#define ufsmcq_readl(hba, reg) \
readl((hba)->mcq_base + (reg))
#define ufsmcq_writelx(hba, val, reg) \
writel_relaxed((val), (hba)->mcq_base + (reg))
#define ufsmcq_readlx(hba, reg) \
readl_relaxed((hba)->mcq_base + (reg))
#define ufshcd_writel(hba, val, reg) \
writel((val), (hba)->mmio_base + (reg))
#define ufshcd_readl(hba, reg) \
......
......@@ -22,6 +22,7 @@ enum {
/* UFSHCI Registers */
enum {
REG_CONTROLLER_CAPABILITIES = 0x00,
REG_MCQCAP = 0x04,
REG_UFS_VERSION = 0x08,
REG_CONTROLLER_DEV_ID = 0x10,
REG_CONTROLLER_PROD_ID = 0x14,
......@@ -56,6 +57,8 @@ enum {
REG_UFS_CCAP = 0x100,
REG_UFS_CRYPTOCAP = 0x104,
REG_UFS_MEM_CFG = 0x300,
REG_UFS_MCQ_CFG = 0x380,
UFSHCI_CRYPTO_REG_SPACE_SIZE = 0x400,
};
......@@ -69,6 +72,41 @@ enum {
MASK_OUT_OF_ORDER_DATA_DELIVERY_SUPPORT = 0x02000000,
MASK_UIC_DME_TEST_MODE_SUPPORT = 0x04000000,
MASK_CRYPTO_SUPPORT = 0x10000000,
MASK_MCQ_SUPPORT = 0x40000000,
};
/* MCQ capability mask */
enum {
MASK_EXT_IID_SUPPORT = 0x00000400,
};
enum {
REG_SQATTR = 0x0,
REG_SQLBA = 0x4,
REG_SQUBA = 0x8,
REG_SQDAO = 0xC,
REG_SQISAO = 0x10,
REG_CQATTR = 0x20,
REG_CQLBA = 0x24,
REG_CQUBA = 0x28,
REG_CQDAO = 0x2C,
REG_CQISAO = 0x30,
};
enum {
REG_SQHP = 0x0,
REG_SQTP = 0x4,
};
enum {
REG_CQHP = 0x0,
REG_CQTP = 0x4,
};
enum {
REG_CQIS = 0x0,
REG_CQIE = 0x4,
};
#define UFS_MASK(mask, offset) ((mask) << (offset))
......@@ -127,6 +165,7 @@ static inline u32 ufshci_version(u32 major, u32 minor)
#define CONTROLLER_FATAL_ERROR 0x10000
#define SYSTEM_BUS_FATAL_ERROR 0x20000
#define CRYPTO_ENGINE_FATAL_ERROR 0x40000
#define MCQ_CQ_EVENT_STATUS 0x100000
#define UFSHCD_UIC_HIBERN8_MASK (UIC_HIBERNATE_ENTER |\
UIC_HIBERNATE_EXIT)
......@@ -224,6 +263,9 @@ enum {
/* UTMRLRSR - UTP Task Management Request Run-Stop Register 80h */
#define UTP_TASK_REQ_LIST_RUN_STOP_BIT 0x1
/* CQISy - CQ y Interrupt Status Register */
#define UFSHCD_MCQ_CQIS_TAIL_ENT_PUSH_STS 0x1
/* UICCMD - UIC Command */
#define COMMAND_OPCODE_MASK 0xFF
#define GEN_SELECTOR_INDEX_MASK 0xFFFF
......@@ -484,6 +526,28 @@ struct utp_transfer_req_desc {
__le16 prd_table_offset;
};
/* MCQ Completion Queue Entry */
struct cq_entry {
/* DW 0-1 */
__le64 command_desc_base_addr;
/* DW 2 */
__le16 response_upiu_length;
__le16 response_upiu_offset;
/* DW 3 */
__le16 prd_table_length;
__le16 prd_table_offset;
/* DW 4 */
__le32 status;
/* DW 5-7 */
__le32 reserved[3];
};
static_assert(sizeof(struct cq_entry) == 32);
/*
* UTMRD structure.
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment