Commit 2a6f99ee authored by Paolo Abeni's avatar Paolo Abeni
Browse files

Merge branch 'net-wwan-t7xx-add-t7xx-debug-ports'

Jinjian Song says:

====================
net: wwan: t7xx: Add t7xx debug ports

Add support for t7xx WWAN device to debug by ADB (Android Debug Bridge)
port and MTK MIPCi (Modem Information Process Center) port.

Application can use ADB (Android Debug Bridge) port to implement
functions (shell, pull, push ...) by ADB protocol commands.

Application can use MIPC (Modem Information Process Center) port
to debug antenna tuner or noise profiling through this MTK modem
diagnostic interface.
====================

Link: https://patch.msgid.link/20241104094436.466861-1-jinjian.song@fibocom.com


Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parents 17bcfe66 238f2ca1
Loading
Loading
Loading
Loading
+56 −8
Original line number Diff line number Diff line
@@ -7,12 +7,13 @@
============================================
t7xx driver for MTK PCIe based T700 5G modem
============================================
The t7xx driver is a WWAN PCIe host driver developed for linux or Chrome OS platforms
for data exchange over PCIe interface between Host platform & MediaTek's T700 5G modem.
The driver exposes an interface conforming to the MBIM protocol [1]. Any front end
application (e.g. Modem Manager) could easily manage the MBIM interface to enable
data communication towards WWAN. The driver also provides an interface to interact
with the MediaTek's modem via AT commands.
The t7xx driver is a WWAN PCIe host driver developed for linux or Chrome OS
platforms for data exchange over PCIe interface between Host platform &
MediaTek's T700 5G modem.
The driver exposes an interface conforming to the MBIM protocol [1]. Any front
end application (e.g. Modem Manager) could easily manage the MBIM interface to
enable data communication towards WWAN. The driver also provides an interface
to interact with the MediaTek's modem via AT commands.

Basic usage
===========
@@ -45,8 +46,8 @@ The driver provides sysfs interfaces to userspace.

t7xx_mode
---------
The sysfs interface provides userspace with access to the device mode, this interface
supports read and write operations.
The sysfs interface provides userspace with access to the device mode, this
interface supports read and write operations.

Device mode:

@@ -67,6 +68,28 @@ Write from userspace to set the device mode.
::
  $ echo fastboot_switching > /sys/bus/pci/devices/${bdf}/t7xx_mode

t7xx_debug_ports
----------------
The sysfs interface provides userspace with access to enable/disable the debug
ports, this interface supports read and write operations.

Debug port status:

- ``1`` represents enable debug ports
- ``0`` represents disable debug ports

Currently supported debug ports (ADB/MIPC).

Read from userspace to get the current debug ports status.

::
  $ cat /sys/bus/pci/devices/${bdf}/t7xx_debug_ports

Write from userspace to set the debug ports status.

::
  $ echo 1 > /sys/bus/pci/devices/${bdf}/t7xx_debug_ports

Management application development
==================================
The driver and userspace interfaces are described below. The MBIM protocol is
@@ -139,6 +162,25 @@ Please note that driver needs to be reloaded to export /dev/wwan0fastboot0
port, because device needs a cold reset after enter ``fastboot_switching``
mode.

ADB port userspace ABI
----------------------

/dev/wwan0adb0 character device
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The driver exposes a ADB protocol interface by implementing ADB WWAN Port.
The userspace end of the ADB channel pipe is a /dev/wwan0adb0 character device.
Application shall use this interface for ADB protocol communication.

MIPC port userspace ABI
-----------------------

/dev/wwan0mipc0 character device
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The driver exposes a diagnostic interface by implementing MIPC (Modem
Information Process Center) WWAN Port. The userspace end of the MIPC channel
pipe is a /dev/wwan0mipc0 character device.
Application shall use this interface for MTK modem diagnostic communication.

The MediaTek's T700 modem supports the 3GPP TS 27.007 [4] specification.

References
@@ -164,3 +206,9 @@ speak the Mobile Interface Broadband Model (MBIM) protocol"*
[5] *fastboot "a mechanism for communicating with bootloaders"*

- https://android.googlesource.com/platform/system/core/+/refs/heads/main/fastboot/README.md

[6] *ADB (Android Debug Bridge) "a mechanism to keep track of Android devices
and emulators instances connected to or running on a given host developer
machine with ADB protocol"*

- https://android.googlesource.com/platform/packages/modules/adb/+/refs/heads/main/README.md
+1 −0
Original line number Diff line number Diff line
@@ -198,6 +198,7 @@ int t7xx_reset_device(struct t7xx_pci_dev *t7xx_dev, enum reset_type type)
	pci_save_state(t7xx_dev->pdev);
	t7xx_pci_reprobe_early(t7xx_dev);
	t7xx_mode_update(t7xx_dev, T7XX_RESET);
	WRITE_ONCE(t7xx_dev->debug_ports_show, false);

	if (type == FLDR) {
		ret = t7xx_acpi_reset(t7xx_dev, "_RST");
+52 −6
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@
#include "t7xx_pcie_mac.h"
#include "t7xx_reg.h"
#include "t7xx_state_monitor.h"
#include "t7xx_port_proxy.h"

#define T7XX_PCI_IREG_BASE		0
#define T7XX_PCI_EREG_BASE		2
@@ -120,13 +121,58 @@ static ssize_t t7xx_mode_show(struct device *dev,

static DEVICE_ATTR_RW(t7xx_mode);

static struct attribute *t7xx_mode_attr[] = {
static ssize_t t7xx_debug_ports_store(struct device *dev,
				      struct device_attribute *attr,
				      const char *buf, size_t count)
{
	struct t7xx_pci_dev *t7xx_dev;
	struct pci_dev *pdev;
	bool show;
	int ret;

	pdev = to_pci_dev(dev);
	t7xx_dev = pci_get_drvdata(pdev);
	if (!t7xx_dev)
		return -ENODEV;

	ret = kstrtobool(buf, &show);
	if (ret < 0)
		return ret;

	t7xx_proxy_debug_ports_show(t7xx_dev, show);
	WRITE_ONCE(t7xx_dev->debug_ports_show, show);

	return count;
};

static ssize_t t7xx_debug_ports_show(struct device *dev,
				     struct device_attribute *attr,
				     char *buf)
{
	struct t7xx_pci_dev *t7xx_dev;
	struct pci_dev *pdev;
	bool show;

	pdev = to_pci_dev(dev);
	t7xx_dev = pci_get_drvdata(pdev);
	if (!t7xx_dev)
		return -ENODEV;

	show = READ_ONCE(t7xx_dev->debug_ports_show);

	return sysfs_emit(buf, "%d\n", show);
}

static DEVICE_ATTR_RW(t7xx_debug_ports);

static struct attribute *t7xx_attr[] = {
	&dev_attr_t7xx_mode.attr,
	&dev_attr_t7xx_debug_ports.attr,
	NULL
};

static const struct attribute_group t7xx_mode_attribute_group = {
	.attrs = t7xx_mode_attr,
static const struct attribute_group t7xx_attribute_group = {
	.attrs = t7xx_attr,
};

void t7xx_mode_update(struct t7xx_pci_dev *t7xx_dev, enum t7xx_mode mode)
@@ -839,7 +885,7 @@ static int t7xx_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
	t7xx_pcie_mac_interrupts_dis(t7xx_dev);

	ret = sysfs_create_group(&t7xx_dev->pdev->dev.kobj,
				 &t7xx_mode_attribute_group);
				 &t7xx_attribute_group);
	if (ret)
		goto err_md_exit;

@@ -855,7 +901,7 @@ static int t7xx_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)

err_remove_group:
	sysfs_remove_group(&t7xx_dev->pdev->dev.kobj,
			   &t7xx_mode_attribute_group);
			   &t7xx_attribute_group);

err_md_exit:
	t7xx_md_exit(t7xx_dev);
@@ -870,7 +916,7 @@ static void t7xx_pci_remove(struct pci_dev *pdev)
	t7xx_dev = pci_get_drvdata(pdev);

	sysfs_remove_group(&t7xx_dev->pdev->dev.kobj,
			   &t7xx_mode_attribute_group);
			   &t7xx_attribute_group);
	t7xx_md_exit(t7xx_dev);

	for (i = 0; i < EXT_INT_NUM; i++) {
+1 −0
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ struct t7xx_pci_dev {
	struct dentry		*debugfs_dir;
#endif
	u32			mode;
	bool			debug_ports_show;
};

enum t7xx_pm_id {
+3 −0
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ enum port_ch {
	/* to AP */
	PORT_CH_AP_CONTROL_RX = 0x1000,
	PORT_CH_AP_CONTROL_TX = 0x1001,
	PORT_CH_AP_ADB_RX = 0x100a,
	PORT_CH_AP_ADB_TX = 0x100b,

	/* to MD */
	PORT_CH_CONTROL_RX = 0x2000,
@@ -100,6 +102,7 @@ struct t7xx_port_conf {
	struct port_ops		*ops;
	char			*name;
	enum wwan_port_type	port_type;
	bool			debug;
};

struct t7xx_port {
Loading