Skip to content

Commit af568c7

Browse files
bvanasschemartinkpetersen
authored andcommitted
scsi: ufs: mcq: Make .get_hba_mac() optional
UFSHCI controllers that are compliant with the UFSHCI 4.0 standard report the maximum number of supported commands in the controller capabilities register. Use that value if .get_hba_mac == NULL. Reviewed-by: Peter Wang <peter.wang@mediatek.com> Signed-off-by: Bart Van Assche <bvanassche@acm.org> Link: https://lore.kernel.org/r/20240708211716.2827751-11-bvanassche@acm.org Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 5e2053a commit af568c7

File tree

5 files changed

+27
-8
lines changed

5 files changed

+27
-8
lines changed

drivers/ufs/core/ufs-mcq.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,26 @@ EXPORT_SYMBOL_GPL(ufshcd_mcq_queue_cfg_addr);
138138
*
139139
* MAC - Max. Active Command of the Host Controller (HC)
140140
* HC wouldn't send more than this commands to the device.
141-
* It is mandatory to implement get_hba_mac() to enable MCQ mode.
142141
* Calculates and adjusts the queue depth based on the depth
143142
* supported by the HC and ufs device.
144143
*/
145144
int ufshcd_mcq_decide_queue_depth(struct ufs_hba *hba)
146145
{
147-
int mac = -EOPNOTSUPP;
146+
int mac;
148147

149-
if (!hba->vops || !hba->vops->get_hba_mac)
150-
goto err;
151-
152-
mac = hba->vops->get_hba_mac(hba);
148+
if (!hba->vops || !hba->vops->get_hba_mac) {
149+
/*
150+
* Extract the maximum number of active transfer tasks value
151+
* from the host controller capabilities register. This value is
152+
* 0-based.
153+
*/
154+
hba->capabilities =
155+
ufshcd_readl(hba, REG_CONTROLLER_CAPABILITIES);
156+
mac = hba->capabilities & MASK_TRANSFER_REQUESTS_SLOTS_MCQ;
157+
mac++;
158+
} else {
159+
mac = hba->vops->get_hba_mac(hba);
160+
}
153161
if (mac < 0)
154162
goto err;
155163

@@ -424,6 +432,12 @@ void ufshcd_mcq_enable(struct ufs_hba *hba)
424432
}
425433
EXPORT_SYMBOL_GPL(ufshcd_mcq_enable);
426434

435+
void ufshcd_mcq_disable(struct ufs_hba *hba)
436+
{
437+
ufshcd_rmwl(hba, MCQ_MODE_SELECT, 0, REG_UFS_MEM_CFG);
438+
hba->mcq_enabled = false;
439+
}
440+
427441
void ufshcd_mcq_config_esi(struct ufs_hba *hba, struct msi_msg *msg)
428442
{
429443
ufshcd_writel(hba, msg->address_lo, REG_UFS_ESILBA);

drivers/ufs/core/ufshcd-priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit);
6464
void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag,
6565
struct cq_entry *cqe);
6666
int ufshcd_mcq_init(struct ufs_hba *hba);
67+
void ufshcd_mcq_disable(struct ufs_hba *hba);
6768
int ufshcd_mcq_decide_queue_depth(struct ufs_hba *hba);
6869
int ufshcd_mcq_memory_alloc(struct ufs_hba *hba);
6970
struct ufs_hw_queue *ufshcd_mcq_req_to_hwq(struct ufs_hba *hba,

drivers/ufs/core/ufshcd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8753,12 +8753,13 @@ static int ufshcd_device_init(struct ufs_hba *hba, bool init_dev_params)
87538753
if (ret)
87548754
return ret;
87558755
if (is_mcq_supported(hba) && !hba->scsi_host_added) {
8756+
ufshcd_mcq_enable(hba);
87568757
ret = ufshcd_alloc_mcq(hba);
87578758
if (!ret) {
87588759
ufshcd_config_mcq(hba);
8759-
ufshcd_mcq_enable(hba);
87608760
} else {
87618761
/* Continue with SDB mode */
8762+
ufshcd_mcq_disable(hba);
87628763
use_mcq_mode = false;
87638764
dev_err(hba->dev, "MCQ mode is disabled, err=%d\n",
87648765
ret);

include/ufs/ufshcd.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,9 @@ struct ufs_pwr_mode_info {
325325
* @event_notify: called to notify important events
326326
* @reinit_notify: called to notify reinit of UFSHCD during max gear switch
327327
* @mcq_config_resource: called to configure MCQ platform resources
328-
* @get_hba_mac: called to get vendor specific mac value, mandatory for mcq mode
328+
* @get_hba_mac: reports maximum number of outstanding commands supported by
329+
* the controller. Should be implemented for UFSHCI 4.0 or later
330+
* controllers that are not compliant with the UFSHCI 4.0 specification.
329331
* @op_runtime_config: called to config Operation and runtime regs Pointers
330332
* @get_outstanding_cqs: called to get outstanding completion queues
331333
* @config_esi: called to config Event Specific Interrupt

include/ufs/ufshci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ enum {
6868
/* Controller capability masks */
6969
enum {
7070
MASK_TRANSFER_REQUESTS_SLOTS_SDB = 0x0000001F,
71+
MASK_TRANSFER_REQUESTS_SLOTS_MCQ = 0x000000FF,
7172
MASK_NUMBER_OUTSTANDING_RTT = 0x0000FF00,
7273
MASK_TASK_MANAGEMENT_REQUEST_SLOTS = 0x00070000,
7374
MASK_EHSLUTRD_SUPPORTED = 0x00400000,

0 commit comments

Comments
 (0)