Skip to content

Commit 57b1c0e

Browse files
Asutosh Dasmartinkpetersen
authored andcommitted
scsi: ufs: core: mcq: Add support to allocate multiple queues
Multi-circular queue (MCQ) has been added in UFSHC v4.0 standard in addition to the Single Doorbell mode. The MCQ mode supports multiple submission and completion queues. Add support to allocate and configure the queues. Add module parameters support to configure the queues. Co-developed-by: Can Guo <[email protected]> Signed-off-by: Can Guo <[email protected]> Signed-off-by: Asutosh Das <[email protected]> Reviewed-by: Bart Van Assche <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 0cab402 commit 57b1c0e

File tree

5 files changed

+142
-1
lines changed

5 files changed

+142
-1
lines changed

drivers/ufs/core/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0
22

33
obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o
4-
ufshcd-core-y += ufshcd.o ufs-sysfs.o
4+
ufshcd-core-y += ufshcd.o ufs-sysfs.o ufs-mcq.o
55
ufshcd-core-$(CONFIG_DEBUG_FS) += ufs-debugfs.o
66
ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o
77
ufshcd-core-$(CONFIG_SCSI_UFS_CRYPTO) += ufshcd-crypto.o

drivers/ufs/core/ufs-mcq.c

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Copyright (c) 2022 Qualcomm Innovation Center. All rights reserved.
4+
*
5+
* Authors:
6+
* Asutosh Das <[email protected]>
7+
* Can Guo <[email protected]>
8+
*/
9+
10+
#include <asm/unaligned.h>
11+
#include <linux/dma-mapping.h>
12+
#include <linux/module.h>
13+
#include <linux/platform_device.h>
14+
#include "ufshcd-priv.h"
15+
16+
#define MAX_QUEUE_SUP GENMASK(7, 0)
17+
#define UFS_MCQ_MIN_RW_QUEUES 2
18+
#define UFS_MCQ_MIN_READ_QUEUES 0
19+
#define UFS_MCQ_NUM_DEV_CMD_QUEUES 1
20+
#define UFS_MCQ_MIN_POLL_QUEUES 0
21+
22+
static int rw_queue_count_set(const char *val, const struct kernel_param *kp)
23+
{
24+
return param_set_uint_minmax(val, kp, UFS_MCQ_MIN_RW_QUEUES,
25+
num_possible_cpus());
26+
}
27+
28+
static const struct kernel_param_ops rw_queue_count_ops = {
29+
.set = rw_queue_count_set,
30+
.get = param_get_uint,
31+
};
32+
33+
static unsigned int rw_queues;
34+
module_param_cb(rw_queues, &rw_queue_count_ops, &rw_queues, 0644);
35+
MODULE_PARM_DESC(rw_queues,
36+
"Number of interrupt driven I/O queues used for rw. Default value is nr_cpus");
37+
38+
static int read_queue_count_set(const char *val, const struct kernel_param *kp)
39+
{
40+
return param_set_uint_minmax(val, kp, UFS_MCQ_MIN_READ_QUEUES,
41+
num_possible_cpus());
42+
}
43+
44+
static const struct kernel_param_ops read_queue_count_ops = {
45+
.set = read_queue_count_set,
46+
.get = param_get_uint,
47+
};
48+
49+
static unsigned int read_queues;
50+
module_param_cb(read_queues, &read_queue_count_ops, &read_queues, 0644);
51+
MODULE_PARM_DESC(read_queues,
52+
"Number of interrupt driven read queues used for read. Default value is 0");
53+
54+
static int poll_queue_count_set(const char *val, const struct kernel_param *kp)
55+
{
56+
return param_set_uint_minmax(val, kp, UFS_MCQ_MIN_POLL_QUEUES,
57+
num_possible_cpus());
58+
}
59+
60+
static const struct kernel_param_ops poll_queue_count_ops = {
61+
.set = poll_queue_count_set,
62+
.get = param_get_uint,
63+
};
64+
65+
static unsigned int poll_queues = 1;
66+
module_param_cb(poll_queues, &poll_queue_count_ops, &poll_queues, 0644);
67+
MODULE_PARM_DESC(poll_queues,
68+
"Number of poll queues used for r/w. Default value is 1");
69+
70+
static int ufshcd_mcq_config_nr_queues(struct ufs_hba *hba)
71+
{
72+
int i;
73+
u32 hba_maxq, rem, tot_queues;
74+
struct Scsi_Host *host = hba->host;
75+
76+
hba_maxq = FIELD_GET(MAX_QUEUE_SUP, hba->mcq_capabilities);
77+
78+
tot_queues = UFS_MCQ_NUM_DEV_CMD_QUEUES + read_queues + poll_queues +
79+
rw_queues;
80+
81+
if (hba_maxq < tot_queues) {
82+
dev_err(hba->dev, "Total queues (%d) exceeds HC capacity (%d)\n",
83+
tot_queues, hba_maxq);
84+
return -EOPNOTSUPP;
85+
}
86+
87+
rem = hba_maxq - UFS_MCQ_NUM_DEV_CMD_QUEUES;
88+
89+
if (rw_queues) {
90+
hba->nr_queues[HCTX_TYPE_DEFAULT] = rw_queues;
91+
rem -= hba->nr_queues[HCTX_TYPE_DEFAULT];
92+
} else {
93+
rw_queues = num_possible_cpus();
94+
}
95+
96+
if (poll_queues) {
97+
hba->nr_queues[HCTX_TYPE_POLL] = poll_queues;
98+
rem -= hba->nr_queues[HCTX_TYPE_POLL];
99+
}
100+
101+
if (read_queues) {
102+
hba->nr_queues[HCTX_TYPE_READ] = read_queues;
103+
rem -= hba->nr_queues[HCTX_TYPE_READ];
104+
}
105+
106+
if (!hba->nr_queues[HCTX_TYPE_DEFAULT])
107+
hba->nr_queues[HCTX_TYPE_DEFAULT] = min3(rem, rw_queues,
108+
num_possible_cpus());
109+
110+
for (i = 0; i < HCTX_MAX_TYPES; i++)
111+
host->nr_hw_queues += hba->nr_queues[i];
112+
113+
hba->nr_hw_queues = host->nr_hw_queues + UFS_MCQ_NUM_DEV_CMD_QUEUES;
114+
return 0;
115+
}
116+
117+
int ufshcd_mcq_init(struct ufs_hba *hba)
118+
{
119+
int ret;
120+
121+
ret = ufshcd_mcq_config_nr_queues(hba);
122+
123+
return ret;
124+
}

drivers/ufs/core/ufshcd-priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode,
6161
int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode,
6262
enum flag_idn idn, u8 index, bool *flag_res);
6363
void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit);
64+
int ufshcd_mcq_init(struct ufs_hba *hba);
6465

6566
#define SD_ASCII_STD true
6667
#define SD_RAW false

drivers/ufs/core/ufshcd.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8294,6 +8294,11 @@ static int ufshcd_add_lus(struct ufs_hba *hba)
82948294
return ret;
82958295
}
82968296

8297+
static int ufshcd_alloc_mcq(struct ufs_hba *hba)
8298+
{
8299+
return ufshcd_mcq_init(hba);
8300+
}
8301+
82978302
static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params)
82988303
{
82998304
int ret;
@@ -8333,6 +8338,13 @@ static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params)
83338338
if (ret)
83348339
return ret;
83358340
if (is_mcq_supported(hba) && !hba->scsi_host_added) {
8341+
ret = ufshcd_alloc_mcq(hba);
8342+
if (ret) {
8343+
/* Continue with SDB mode */
8344+
use_mcq_mode = false;
8345+
dev_err(hba->dev, "MCQ mode is disabled, err=%d\n",
8346+
ret);
8347+
}
83368348
ret = scsi_add_host(host, hba->dev);
83378349
if (ret) {
83388350
dev_err(hba->dev, "scsi_add_host failed\n");

include/ufs/ufshcd.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,8 @@ struct ufs_hba_monitor {
840840
* ee_ctrl_mask
841841
* @luns_avail: number of regular and well known LUNs supported by the UFS
842842
* device
843+
* @nr_hw_queues: number of hardware queues configured
844+
* @nr_queues: number of Queues of different queue types
843845
* @complete_put: whether or not to call ufshcd_rpm_put() from inside
844846
* ufshcd_resume_complete()
845847
* @ext_iid_sup: is EXT_IID is supported by UFSHC
@@ -994,6 +996,8 @@ struct ufs_hba {
994996
u32 debugfs_ee_rate_limit_ms;
995997
#endif
996998
u32 luns_avail;
999+
unsigned int nr_hw_queues;
1000+
unsigned int nr_queues[HCTX_MAX_TYPES];
9971001
bool complete_put;
9981002
bool ext_iid_sup;
9991003
bool scsi_host_added;

0 commit comments

Comments
 (0)