Skip to contentSkip to conversation

bus: mhi: host: Add support to read MHI capabilities

PATCH New Krishna Chaitanya Chundru 2 participants 2 messages Aug 18, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 bus: mhi: host: Add support to read MHI capabilities

From: Vivek Pernamitta <[email protected]>

As per MHI spec v1.2,sec 6.6, MHI has capability registers which are located after the ERDB array. The location of this group of registers is indicated by the MISCOFF register. Each capability has a capability ID to determine which functionality is supported and each capability will point to the next capability supported.

Add a basic function to read those capabilities offsets.

---
This patch is required by MHI TSC time sync also, for that reason sending this seperately.
Changes from v4:
- Removed the le32_to_cpu conversions as these will be taken care by the readl API's (Mani)

---
 drivers/bus/mhi/common.h    | 13 +++++++++++++
 drivers/bus/mhi/host/init.c | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)
drivers/bus/mhi/common.h +13 -0
index dda340aaed95a5573a2ec776ca712e11a1ed0b52..58f27c6ba63e3e6fa28ca48d6d1065684ed6e1dd 100644
@@ -16,6 +16,7 @@
 #define MHICFG				0x10
 #define CHDBOFF				0x18
 #define ERDBOFF				0x20
+#define MISCOFF				0x24
 #define BHIOFF				0x28
 #define BHIEOFF				0x2c
 #define DEBUGOFF			0x30
@@ -113,6 +114,9 @@
 #define MHISTATUS_MHISTATE_MASK		GENMASK(15, 8)
 #define MHISTATUS_SYSERR_MASK		BIT(2)
 #define MHISTATUS_READY_MASK		BIT(0)
+#define MISC_CAP_MASK			GENMASK(31, 0)
+#define CAP_CAPID_MASK			GENMASK(31, 24)
+#define CAP_NEXT_CAP_MASK		GENMASK(23, 12)
 
 /* Command Ring Element macros */
 /* No operation command */
@@ -204,6 +208,15 @@
 #define MHI_RSCTRE_DATA_DWORD1		cpu_to_le32(FIELD_PREP(GENMASK(23, 16), \
 							       MHI_PKT_TYPE_COALESCING))
 
+enum mhi_capability_type {
+	MHI_CAP_ID_INTX = 0x1,
+	MHI_CAP_ID_TIME_SYNC = 0x2,
+	MHI_CAP_ID_BW_SCALE = 0x3,
+	MHI_CAP_ID_TSC_TIME_SYNC = 0x4,
+	MHI_CAP_ID_MAX_TRB_LEN = 0x5,
+	MHI_CAP_ID_MAX,
+};
+
 enum mhi_pkt_type {
 	MHI_PKT_TYPE_INVALID = 0x0,
 	MHI_PKT_TYPE_NOOP_CMD = 0x1,
drivers/bus/mhi/host/init.c +32 -0
index 7f72aab38ce92fea9e875e65c69d9a4714ecbc13..b5f23336eb6afe249c07932bc4182fafdf1f2a19 100644
@@ -467,6 +467,38 @@ static int mhi_init_dev_ctxt(struct mhi_controller *mhi_cntrl)
 	return ret;
 }
 
+static int mhi_find_capability(struct mhi_controller *mhi_cntrl, u32 capability, u32 *offset)
+{
+	u32 val, cur_cap, next_offset;
+	int ret;
+
+	/* Get the first supported capability offset */
+	ret = mhi_read_reg_field(mhi_cntrl, mhi_cntrl->regs, MISCOFF, MISC_CAP_MASK, offset);
+	if (ret)
+		return ret;
+
+	do {
+		if (*offset >= mhi_cntrl->reg_len)
+			return -ENXIO;
+
+		ret = mhi_read_reg(mhi_cntrl, mhi_cntrl->regs, *offset, &val);
+		if (ret)
+			return ret;
+
+		cur_cap = FIELD_GET(CAP_CAPID_MASK, val);
+		next_offset = FIELD_GET(CAP_NEXT_CAP_MASK, val);
+		if (cur_cap >= MHI_CAP_ID_MAX)
+			return -ENXIO;
+
+		if (cur_cap == capability)
+			return 0;
+
+		*offset = next_offset;
+	} while (next_offset);
+
+	return -ENXIO;
+}
+
 int mhi_init_mmio(struct mhi_controller *mhi_cntrl)
 {
 	u32 val;

---
base-commit: c17b750b3ad9f45f2b6f7e6f7f4679844244f0b9
change-id: 20250818-mhi_cap-3b2bb05663f4

Best regards,

Signature · 1 line
Krishna Chaitanya Chundru <[email protected]>
#1 lore raw
kernel test robot noticed the following build warnings:

Hi Krishna,

kernel test robot noticed the following build warnings:

[auto build test WARNING on c17b750b3ad9f45f2b6f7e6f7f4679844244f0b9]

url:    https://github.com/intel-lab-lkp/linux/commits/Krishna-Chaitanya-Chundru/bus-mhi-host-Add-support-to-read-MHI-capabilities/20250818-140440
base:   c17b750b3ad9f45f2b6f7e6f7f4679844244f0b9
patch link:    https://lore.kernel.org/r/20250818-mhi_cap-v5-1-5e2d69aa2ace%40oss.qualcomm.com
patch subject: [PATCH v5] bus: mhi: host: Add support to read MHI capabilities
config: i386-buildonly-randconfig-003-20250818 (https://download.01.org/0day-ci/archive/20250818/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14+deb12u1) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250818/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/bus/mhi/host/init.c:470:12: warning: 'mhi_find_capability' defined but not used [-Wunused-function]

470 | static int mhi_find_capability(struct mhi_controller *mhi_cntrl, u32 capability, u32 *offset)
| ^~~~~~~~~~~~~~~~~~~

vim +/mhi_find_capability +470 drivers/bus/mhi/host/init.c

469

 > 470	static int mhi_find_capability(struct mhi_controller *mhi_cntrl, u32 capability, u32 *offset)

471 {
472 u32 val, cur_cap, next_offset;
473 int ret;
474
475 /* Get the first supported capability offset */
476 ret = mhi_read_reg_field(mhi_cntrl, mhi_cntrl->regs, MISCOFF, MISC_CAP_MASK, offset);
477 if (ret)
478 return ret;
479
480 do {
481 if (*offset >= mhi_cntrl->reg_len)
482 return -ENXIO;
483
484 ret = mhi_read_reg(mhi_cntrl, mhi_cntrl->regs, *offset, &val);
485 if (ret)
486 return ret;
487
488 cur_cap = FIELD_GET(CAP_CAPID_MASK, val);
489 next_offset = FIELD_GET(CAP_NEXT_CAP_MASK, val);
490 if (cur_cap >= MHI_CAP_ID_MAX)
491 return -ENXIO;
492
493 if (cur_cap == capability)
494 return 0;
495
496 *offset = next_offset;
497 } while (next_offset);
498
499 return -ENXIO;
500 }
501

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki