Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit f87b2c4

Browse files
Asutosh Dasmartinkpetersen
authored andcommitted
scsi: ufs: mcq: Add completion support of a CQE
Add support for completing requests from Completion Queue. Some host controllers support vendor specific registers that provide a bitmap of all CQs which have at least one completed CQE. Add this support. The MCQ specification doesn't provide the Task Tag or its equivalent in the Completion Queue Entry. So use an indirect method to find the Task Tag from the Completion Queue Entry. 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]> Reviewed-by: Stanley Chu <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent c30d8d0 commit f87b2c4

File tree

7 files changed

+169
-0
lines changed

7 files changed

+169
-0
lines changed

drivers/ufs/core/ufs-mcq.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define MCQ_CFG_MAC_MASK GENMASK(16, 8)
2626
#define MCQ_QCFG_SIZE 0x40
2727
#define MCQ_ENTRY_SIZE_IN_DWORD 8
28+
#define CQE_UCD_BA GENMASK_ULL(63, 7)
2829

2930
static int rw_queue_count_set(const char *val, const struct kernel_param *kp)
3031
{
@@ -236,6 +237,63 @@ static void __iomem *mcq_opr_base(struct ufs_hba *hba,
236237
return opr->base + opr->stride * i;
237238
}
238239

240+
u32 ufshcd_mcq_read_cqis(struct ufs_hba *hba, int i)
241+
{
242+
return readl(mcq_opr_base(hba, OPR_CQIS, i) + REG_CQIS);
243+
}
244+
245+
void ufshcd_mcq_write_cqis(struct ufs_hba *hba, u32 val, int i)
246+
{
247+
writel(val, mcq_opr_base(hba, OPR_CQIS, i) + REG_CQIS);
248+
}
249+
250+
/*
251+
* Current MCQ specification doesn't provide a Task Tag or its equivalent in
252+
* the Completion Queue Entry. Find the Task Tag using an indirect method.
253+
*/
254+
static int ufshcd_mcq_get_tag(struct ufs_hba *hba,
255+
struct ufs_hw_queue *hwq,
256+
struct cq_entry *cqe)
257+
{
258+
u64 addr;
259+
260+
/* sizeof(struct utp_transfer_cmd_desc) must be a multiple of 128 */
261+
BUILD_BUG_ON(sizeof(struct utp_transfer_cmd_desc) & GENMASK(6, 0));
262+
263+
/* Bits 63:7 UCD base address, 6:5 are reserved, 4:0 is SQ ID */
264+
addr = (le64_to_cpu(cqe->command_desc_base_addr) & CQE_UCD_BA) -
265+
hba->ucdl_dma_addr;
266+
267+
return div_u64(addr, sizeof(struct utp_transfer_cmd_desc));
268+
}
269+
270+
static void ufshcd_mcq_process_cqe(struct ufs_hba *hba,
271+
struct ufs_hw_queue *hwq)
272+
{
273+
struct cq_entry *cqe = ufshcd_mcq_cur_cqe(hwq);
274+
int tag = ufshcd_mcq_get_tag(hba, hwq, cqe);
275+
276+
ufshcd_compl_one_cqe(hba, tag, cqe);
277+
}
278+
279+
unsigned long ufshcd_mcq_poll_cqe_nolock(struct ufs_hba *hba,
280+
struct ufs_hw_queue *hwq)
281+
{
282+
unsigned long completed_reqs = 0;
283+
284+
ufshcd_mcq_update_cq_tail_slot(hwq);
285+
while (!ufshcd_mcq_is_cq_empty(hwq)) {
286+
ufshcd_mcq_process_cqe(hba, hwq);
287+
ufshcd_mcq_inc_cq_head_slot(hwq);
288+
completed_reqs++;
289+
}
290+
291+
if (completed_reqs)
292+
ufshcd_mcq_update_cq_head(hwq);
293+
294+
return completed_reqs;
295+
}
296+
239297
void ufshcd_mcq_make_queues_operational(struct ufs_hba *hba)
240298
{
241299
struct ufs_hw_queue *hwq;
@@ -279,6 +337,9 @@ void ufshcd_mcq_make_queues_operational(struct ufs_hba *hba)
279337
hwq->mcq_cq_head = mcq_opr_base(hba, OPR_CQD, i) + REG_CQHP;
280338
hwq->mcq_cq_tail = mcq_opr_base(hba, OPR_CQD, i) + REG_CQTP;
281339

340+
/* Reinitializing is needed upon HC reset */
341+
hwq->sq_tail_slot = hwq->cq_tail_slot = hwq->cq_head_slot = 0;
342+
282343
/* Enable Tail Entry Push Status interrupt only for non-poll queues */
283344
if (i < hba->nr_hw_queues - hba->nr_queues[HCTX_TYPE_POLL])
284345
writel(1, mcq_opr_base(hba, OPR_CQIS, i) + REG_CQIE);

drivers/ufs/core/ufshcd-priv.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ int ufshcd_mcq_memory_alloc(struct ufs_hba *hba);
6969
void ufshcd_mcq_make_queues_operational(struct ufs_hba *hba);
7070
void ufshcd_mcq_config_mac(struct ufs_hba *hba, u32 max_active_cmds);
7171
void ufshcd_mcq_select_mcq_mode(struct ufs_hba *hba);
72+
u32 ufshcd_mcq_read_cqis(struct ufs_hba *hba, int i);
73+
void ufshcd_mcq_write_cqis(struct ufs_hba *hba, u32 val, int i);
74+
unsigned long ufshcd_mcq_poll_cqe_nolock(struct ufs_hba *hba,
75+
struct ufs_hw_queue *hwq);
7276
struct ufs_hw_queue *ufshcd_mcq_req_to_hwq(struct ufs_hba *hba,
7377
struct request *req);
7478

@@ -264,6 +268,15 @@ static inline int ufshcd_mcq_vops_op_runtime_config(struct ufs_hba *hba)
264268
return -EOPNOTSUPP;
265269
}
266270

271+
static inline int ufshcd_vops_get_outstanding_cqs(struct ufs_hba *hba,
272+
unsigned long *ocqs)
273+
{
274+
if (hba->vops && hba->vops->get_outstanding_cqs)
275+
return hba->vops->get_outstanding_cqs(hba, ocqs);
276+
277+
return -EOPNOTSUPP;
278+
}
279+
267280
extern const struct ufs_pm_lvl_states ufs_pm_lvl_states[];
268281

269282
/**
@@ -350,4 +363,34 @@ static inline void ufshcd_inc_sq_tail(struct ufs_hw_queue *q)
350363
writel(val, q->mcq_sq_tail);
351364
}
352365

366+
static inline void ufshcd_mcq_update_cq_tail_slot(struct ufs_hw_queue *q)
367+
{
368+
u32 val = readl(q->mcq_cq_tail);
369+
370+
q->cq_tail_slot = val / sizeof(struct cq_entry);
371+
}
372+
373+
static inline bool ufshcd_mcq_is_cq_empty(struct ufs_hw_queue *q)
374+
{
375+
return q->cq_head_slot == q->cq_tail_slot;
376+
}
377+
378+
static inline void ufshcd_mcq_inc_cq_head_slot(struct ufs_hw_queue *q)
379+
{
380+
q->cq_head_slot++;
381+
if (q->cq_head_slot == q->max_entries)
382+
q->cq_head_slot = 0;
383+
}
384+
385+
static inline void ufshcd_mcq_update_cq_head(struct ufs_hw_queue *q)
386+
{
387+
writel(q->cq_head_slot * sizeof(struct cq_entry), q->mcq_cq_head);
388+
}
389+
390+
static inline struct cq_entry *ufshcd_mcq_cur_cqe(struct ufs_hw_queue *q)
391+
{
392+
struct cq_entry *cqe = q->cqe_base_addr;
393+
394+
return cqe + q->cq_head_slot;
395+
}
353396
#endif /* _UFSHCD_PRIV_H_ */

drivers/ufs/core/ufshcd.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6683,6 +6683,40 @@ static irqreturn_t ufshcd_tmc_handler(struct ufs_hba *hba)
66836683
return ret;
66846684
}
66856685

6686+
/**
6687+
* ufshcd_handle_mcq_cq_events - handle MCQ completion queue events
6688+
* @hba: per adapter instance
6689+
*
6690+
* Returns IRQ_HANDLED if interrupt is handled
6691+
*/
6692+
static irqreturn_t ufshcd_handle_mcq_cq_events(struct ufs_hba *hba)
6693+
{
6694+
struct ufs_hw_queue *hwq;
6695+
unsigned long outstanding_cqs;
6696+
unsigned int nr_queues;
6697+
int i, ret;
6698+
u32 events;
6699+
6700+
ret = ufshcd_vops_get_outstanding_cqs(hba, &outstanding_cqs);
6701+
if (ret)
6702+
outstanding_cqs = (1U << hba->nr_hw_queues) - 1;
6703+
6704+
/* Exclude the poll queues */
6705+
nr_queues = hba->nr_hw_queues - hba->nr_queues[HCTX_TYPE_POLL];
6706+
for_each_set_bit(i, &outstanding_cqs, nr_queues) {
6707+
hwq = &hba->uhq[i];
6708+
6709+
events = ufshcd_mcq_read_cqis(hba, i);
6710+
if (events)
6711+
ufshcd_mcq_write_cqis(hba, events, i);
6712+
6713+
if (events & UFSHCD_MCQ_CQIS_TAIL_ENT_PUSH_STS)
6714+
ufshcd_mcq_poll_cqe_nolock(hba, hwq);
6715+
}
6716+
6717+
return IRQ_HANDLED;
6718+
}
6719+
66866720
/**
66876721
* ufshcd_sl_intr - Interrupt service routine
66886722
* @hba: per adapter instance
@@ -6708,6 +6742,9 @@ static irqreturn_t ufshcd_sl_intr(struct ufs_hba *hba, u32 intr_status)
67086742
if (intr_status & UTP_TRANSFER_REQ_COMPL)
67096743
retval |= ufshcd_transfer_req_compl(hba);
67106744

6745+
if (intr_status & MCQ_CQ_EVENT_STATUS)
6746+
retval |= ufshcd_handle_mcq_cq_events(hba);
6747+
67116748
return retval;
67126749
}
67136750

drivers/ufs/host/ufs-qcom.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,19 @@ static int ufs_qcom_get_hba_mac(struct ufs_hba *hba)
15251525
return MAX_SUPP_MAC;
15261526
}
15271527

1528+
static int ufs_qcom_get_outstanding_cqs(struct ufs_hba *hba,
1529+
unsigned long *ocqs)
1530+
{
1531+
struct ufshcd_res_info *mcq_vs_res = &hba->res[RES_MCQ_VS];
1532+
1533+
if (!mcq_vs_res->base)
1534+
return -EINVAL;
1535+
1536+
*ocqs = readl(mcq_vs_res->base + UFS_MEM_CQIS_VS);
1537+
1538+
return 0;
1539+
}
1540+
15281541
/*
15291542
* struct ufs_hba_qcom_vops - UFS QCOM specific variant operations
15301543
*
@@ -1552,6 +1565,7 @@ static const struct ufs_hba_variant_ops ufs_hba_qcom_vops = {
15521565
.mcq_config_resource = ufs_qcom_mcq_config_resource,
15531566
.get_hba_mac = ufs_qcom_get_hba_mac,
15541567
.op_runtime_config = ufs_qcom_op_runtime_config,
1568+
.get_outstanding_cqs = ufs_qcom_get_outstanding_cqs,
15551569
};
15561570

15571571
/**

drivers/ufs/host/ufs-qcom.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ enum {
7171
UFS_UFS_DBG_RD_EDTL_RAM = 0x1900,
7272
};
7373

74+
enum {
75+
UFS_MEM_CQIS_VS = 0x8,
76+
};
77+
7478
#define UFS_CNTLR_2_x_x_VEN_REGS_OFFSET(x) (0x000 + x)
7579
#define UFS_CNTLR_3_x_x_VEN_REGS_OFFSET(x) (0x400 + x)
7680

include/ufs/ufshcd.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ struct ufs_pwr_mode_info {
304304
* @mcq_config_resource: called to configure MCQ platform resources
305305
* @get_hba_mac: called to get vendor specific mac value, mandatory for mcq mode
306306
* @op_runtime_config: called to config Operation and runtime regs Pointers
307+
* @get_outstanding_cqs: called to get outstanding completion queues
307308
*/
308309
struct ufs_hba_variant_ops {
309310
const char *name;
@@ -346,6 +347,8 @@ struct ufs_hba_variant_ops {
346347
int (*mcq_config_resource)(struct ufs_hba *hba);
347348
int (*get_hba_mac)(struct ufs_hba *hba);
348349
int (*op_runtime_config)(struct ufs_hba *hba);
350+
int (*get_outstanding_cqs)(struct ufs_hba *hba,
351+
unsigned long *ocqs);
349352
};
350353

351354
/* clock gating state */
@@ -1081,6 +1084,8 @@ struct ufs_hba {
10811084
* @id: hardware queue ID
10821085
* @sq_tp_slot: current slot to which SQ tail pointer is pointing
10831086
* @sq_lock: serialize submission queue access
1087+
* @cq_tail_slot: current slot to which CQ tail pointer is pointing
1088+
* @cq_head_slot: current slot to which CQ head pointer is pointing
10841089
*/
10851090
struct ufs_hw_queue {
10861091
void __iomem *mcq_sq_head;
@@ -1096,6 +1101,8 @@ struct ufs_hw_queue {
10961101
u32 id;
10971102
u32 sq_tail_slot;
10981103
spinlock_t sq_lock;
1104+
u32 cq_tail_slot;
1105+
u32 cq_head_slot;
10991106
};
11001107

11011108
static inline bool is_mcq_enabled(struct ufs_hba *hba)

include/ufs/ufshci.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ enum {
263263
/* UTMRLRSR - UTP Task Management Request Run-Stop Register 80h */
264264
#define UTP_TASK_REQ_LIST_RUN_STOP_BIT 0x1
265265

266+
/* CQISy - CQ y Interrupt Status Register */
267+
#define UFSHCD_MCQ_CQIS_TAIL_ENT_PUSH_STS 0x1
268+
266269
/* UICCMD - UIC Command */
267270
#define COMMAND_OPCODE_MASK 0xFF
268271
#define GEN_SELECTOR_INDEX_MASK 0xFFFF

0 commit comments

Comments
 (0)