Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: wwan: t7xx: Add debug ports

Add support for userspace to enable/disable the debug ports(ADB,MIPC).
- ADB port: /dev/wwan0adb0
- MIPC port: /dev/wwan0mipc0

Application can use ADB (Android Debug Bridge) port to implement
functions (shell, pull, push ...) by ADB protocol commands.
E.g., ADB commands:
- A_OPEN: OPEN(local-id, 0, "destination")
- A_WRTE: WRITE(local-id, remote-id, "data")
- A_OKEY: READY(local-id, remote-id, "")
- A_CLSE: CLOSE(local-id, remote-id, "")

Link: https://android.googlesource.com/platform/packages/modules/adb/+/refs/heads/main/README.md

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

By default, debug ports are not exposed, so using the command
to enable or disable debug ports.

Enable debug ports:
- enable: 'echo 1 > /sys/bus/pci/devices/${bdf}/t7xx_debug_ports

Disable debug ports:
- disable: 'echo 0 > /sys/bus/pci/devices/${bdf}/t7xx_debug_ports

Signed-off-by: Jinjian Song <jinjian.song@fibocom.com>
Reviewed-by: Sergey Ryazanov <ryazanov.s.a@gmail.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Jinjian Song and committed by
Paolo Abeni
61329a11 495e7c8e

+157 -13
+47
Documentation/networking/device_drivers/wwan/t7xx.rst
··· 67 67 :: 68 68 $ echo fastboot_switching > /sys/bus/pci/devices/${bdf}/t7xx_mode 69 69 70 + t7xx_debug_ports 71 + ---------------- 72 + The sysfs interface provides userspace with access to enable/disable the debug 73 + ports, this interface supports read and write operations. 74 + 75 + Debug port status: 76 + 77 + - ``1`` represents enable debug ports 78 + - ``0`` represents disable debug ports 79 + 80 + Currently supported debug ports (ADB/MIPC). 81 + 82 + Read from userspace to get the current debug ports status. 83 + 84 + :: 85 + $ cat /sys/bus/pci/devices/${bdf}/t7xx_debug_ports 86 + 87 + Write from userspace to set the debug ports status. 88 + 89 + :: 90 + $ echo 1 > /sys/bus/pci/devices/${bdf}/t7xx_debug_ports 91 + 70 92 Management application development 71 93 ================================== 72 94 The driver and userspace interfaces are described below. The MBIM protocol is ··· 161 139 port, because device needs a cold reset after enter ``fastboot_switching`` 162 140 mode. 163 141 142 + ADB port userspace ABI 143 + ---------------------- 144 + 145 + /dev/wwan0adb0 character device 146 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 147 + The driver exposes a ADB protocol interface by implementing ADB WWAN Port. 148 + The userspace end of the ADB channel pipe is a /dev/wwan0adb0 character device. 149 + Application shall use this interface for ADB protocol communication. 150 + 151 + MIPC port userspace ABI 152 + ----------------------- 153 + 154 + /dev/wwan0mipc0 character device 155 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 156 + The driver exposes a diagnostic interface by implementing MIPC (Modem 157 + Information Process Center) WWAN Port. The userspace end of the MIPC channel 158 + pipe is a /dev/wwan0mipc0 character device. 159 + Application shall use this interface for MTK modem diagnostic communication. 160 + 164 161 The MediaTek's T700 modem supports the 3GPP TS 27.007 [4] specification. 165 162 166 163 References ··· 205 164 [5] *fastboot "a mechanism for communicating with bootloaders"* 206 165 207 166 - https://android.googlesource.com/platform/system/core/+/refs/heads/main/fastboot/README.md 167 + 168 + [6] *ADB (Android Debug Bridge) "a mechanism to keep track of Android devices 169 + and emulators instances connected to or running on a given host developer 170 + machine with ADB protocol"* 171 + 172 + - https://android.googlesource.com/platform/packages/modules/adb/+/refs/heads/main/README.md
+1
drivers/net/wwan/t7xx/t7xx_modem_ops.c
··· 198 198 pci_save_state(t7xx_dev->pdev); 199 199 t7xx_pci_reprobe_early(t7xx_dev); 200 200 t7xx_mode_update(t7xx_dev, T7XX_RESET); 201 + WRITE_ONCE(t7xx_dev->debug_ports_show, false); 201 202 202 203 if (type == FLDR) { 203 204 ret = t7xx_acpi_reset(t7xx_dev, "_RST");
+52 -6
drivers/net/wwan/t7xx/t7xx_pci.c
··· 41 41 #include "t7xx_pcie_mac.h" 42 42 #include "t7xx_reg.h" 43 43 #include "t7xx_state_monitor.h" 44 + #include "t7xx_port_proxy.h" 44 45 45 46 #define T7XX_PCI_IREG_BASE 0 46 47 #define T7XX_PCI_EREG_BASE 2 ··· 121 120 122 121 static DEVICE_ATTR_RW(t7xx_mode); 123 122 124 - static struct attribute *t7xx_mode_attr[] = { 123 + static ssize_t t7xx_debug_ports_store(struct device *dev, 124 + struct device_attribute *attr, 125 + const char *buf, size_t count) 126 + { 127 + struct t7xx_pci_dev *t7xx_dev; 128 + struct pci_dev *pdev; 129 + bool show; 130 + int ret; 131 + 132 + pdev = to_pci_dev(dev); 133 + t7xx_dev = pci_get_drvdata(pdev); 134 + if (!t7xx_dev) 135 + return -ENODEV; 136 + 137 + ret = kstrtobool(buf, &show); 138 + if (ret < 0) 139 + return ret; 140 + 141 + t7xx_proxy_debug_ports_show(t7xx_dev, show); 142 + WRITE_ONCE(t7xx_dev->debug_ports_show, show); 143 + 144 + return count; 145 + }; 146 + 147 + static ssize_t t7xx_debug_ports_show(struct device *dev, 148 + struct device_attribute *attr, 149 + char *buf) 150 + { 151 + struct t7xx_pci_dev *t7xx_dev; 152 + struct pci_dev *pdev; 153 + bool show; 154 + 155 + pdev = to_pci_dev(dev); 156 + t7xx_dev = pci_get_drvdata(pdev); 157 + if (!t7xx_dev) 158 + return -ENODEV; 159 + 160 + show = READ_ONCE(t7xx_dev->debug_ports_show); 161 + 162 + return sysfs_emit(buf, "%d\n", show); 163 + } 164 + 165 + static DEVICE_ATTR_RW(t7xx_debug_ports); 166 + 167 + static struct attribute *t7xx_attr[] = { 125 168 &dev_attr_t7xx_mode.attr, 169 + &dev_attr_t7xx_debug_ports.attr, 126 170 NULL 127 171 }; 128 172 129 - static const struct attribute_group t7xx_mode_attribute_group = { 130 - .attrs = t7xx_mode_attr, 173 + static const struct attribute_group t7xx_attribute_group = { 174 + .attrs = t7xx_attr, 131 175 }; 132 176 133 177 void t7xx_mode_update(struct t7xx_pci_dev *t7xx_dev, enum t7xx_mode mode) ··· 885 839 t7xx_pcie_mac_interrupts_dis(t7xx_dev); 886 840 887 841 ret = sysfs_create_group(&t7xx_dev->pdev->dev.kobj, 888 - &t7xx_mode_attribute_group); 842 + &t7xx_attribute_group); 889 843 if (ret) 890 844 goto err_md_exit; 891 845 ··· 901 855 902 856 err_remove_group: 903 857 sysfs_remove_group(&t7xx_dev->pdev->dev.kobj, 904 - &t7xx_mode_attribute_group); 858 + &t7xx_attribute_group); 905 859 906 860 err_md_exit: 907 861 t7xx_md_exit(t7xx_dev); ··· 916 870 t7xx_dev = pci_get_drvdata(pdev); 917 871 918 872 sysfs_remove_group(&t7xx_dev->pdev->dev.kobj, 919 - &t7xx_mode_attribute_group); 873 + &t7xx_attribute_group); 920 874 t7xx_md_exit(t7xx_dev); 921 875 922 876 for (i = 0; i < EXT_INT_NUM; i++) {
+1
drivers/net/wwan/t7xx/t7xx_pci.h
··· 94 94 struct dentry *debugfs_dir; 95 95 #endif 96 96 u32 mode; 97 + bool debug_ports_show; 97 98 }; 98 99 99 100 enum t7xx_pm_id {
+3
drivers/net/wwan/t7xx/t7xx_port.h
··· 42 42 /* to AP */ 43 43 PORT_CH_AP_CONTROL_RX = 0x1000, 44 44 PORT_CH_AP_CONTROL_TX = 0x1001, 45 + PORT_CH_AP_ADB_RX = 0x100a, 46 + PORT_CH_AP_ADB_TX = 0x100b, 45 47 46 48 /* to MD */ 47 49 PORT_CH_CONTROL_RX = 0x2000, ··· 102 100 struct port_ops *ops; 103 101 char *name; 104 102 enum wwan_port_type port_type; 103 + bool debug; 105 104 }; 106 105 107 106 struct t7xx_port {
+46 -5
drivers/net/wwan/t7xx/t7xx_port_proxy.c
··· 38 38 #include "t7xx_state_monitor.h" 39 39 40 40 #define Q_IDX_CTRL 0 41 - #define Q_IDX_MBIM 2 41 + #define Q_IDX_MBIM_MIPC 2 42 + #define Q_IDX_ADB 3 42 43 #define Q_IDX_AT_CMD 5 43 44 44 45 #define INVALID_SEQ_NUM GENMASK(15, 0) ··· 67 66 }, { 68 67 .tx_ch = PORT_CH_MBIM_TX, 69 68 .rx_ch = PORT_CH_MBIM_RX, 70 - .txq_index = Q_IDX_MBIM, 71 - .rxq_index = Q_IDX_MBIM, 69 + .txq_index = Q_IDX_MBIM_MIPC, 70 + .rxq_index = Q_IDX_MBIM_MIPC, 72 71 .path_id = CLDMA_ID_MD, 73 72 .ops = &wwan_sub_port_ops, 74 73 .name = "MBIM", ··· 101 100 .path_id = CLDMA_ID_AP, 102 101 .ops = &ctl_port_ops, 103 102 .name = "t7xx_ap_ctrl", 104 - }, 103 + }, { 104 + .tx_ch = PORT_CH_AP_ADB_TX, 105 + .rx_ch = PORT_CH_AP_ADB_RX, 106 + .txq_index = Q_IDX_ADB, 107 + .rxq_index = Q_IDX_ADB, 108 + .path_id = CLDMA_ID_AP, 109 + .ops = &wwan_sub_port_ops, 110 + .name = "adb", 111 + .port_type = WWAN_PORT_ADB, 112 + .debug = true, 113 + }, { 114 + .tx_ch = PORT_CH_MIPC_TX, 115 + .rx_ch = PORT_CH_MIPC_RX, 116 + .txq_index = Q_IDX_MBIM_MIPC, 117 + .rxq_index = Q_IDX_MBIM_MIPC, 118 + .path_id = CLDMA_ID_MD, 119 + .ops = &wwan_sub_port_ops, 120 + .name = "mipc", 121 + .port_type = WWAN_PORT_MIPC, 122 + .debug = true, 123 + } 105 124 }; 106 125 107 126 static const struct t7xx_port_conf t7xx_early_port_conf[] = { ··· 526 505 spin_lock_init(&port->port_update_lock); 527 506 port->chan_enable = false; 528 507 529 - if (port_conf->ops && port_conf->ops->init) 508 + if (!port_conf->debug && 509 + port_conf->ops && 510 + port_conf->ops->init) 530 511 port_conf->ops->init(port); 531 512 } 532 513 533 514 t7xx_proxy_setup_ch_mapping(port_prox); 515 + } 516 + 517 + void t7xx_proxy_debug_ports_show(struct t7xx_pci_dev *t7xx_dev, bool show) 518 + { 519 + struct port_proxy *port_prox = t7xx_dev->md->port_prox; 520 + struct t7xx_port *port; 521 + int i; 522 + 523 + for_each_proxy_port(i, port, port_prox) { 524 + const struct t7xx_port_conf *port_conf = port->port_conf; 525 + 526 + if (port_conf->debug && port_conf->ops) { 527 + if (show && port_conf->ops->init) 528 + port_conf->ops->init(port); 529 + else if (!show && port_conf->ops->uninit) 530 + port_conf->ops->uninit(port); 531 + } 532 + } 534 533 } 535 534 536 535 void t7xx_port_proxy_set_cfg(struct t7xx_modem *md, enum port_cfg_id cfg_id)
+1
drivers/net/wwan/t7xx/t7xx_port_proxy.h
··· 98 98 extern struct port_ops t7xx_trace_port_ops; 99 99 #endif 100 100 101 + void t7xx_proxy_debug_ports_show(struct t7xx_pci_dev *t7xx_dev, bool show); 101 102 void t7xx_port_proxy_reset(struct port_proxy *port_prox); 102 103 void t7xx_port_proxy_uninit(struct port_proxy *port_prox); 103 104 int t7xx_port_proxy_init(struct t7xx_modem *md);
+6 -2
drivers/net/wwan/t7xx/t7xx_port_wwan.c
··· 169 169 { 170 170 const struct t7xx_port_conf *port_conf = port->port_conf; 171 171 172 - if (port_conf->port_type == WWAN_PORT_FASTBOOT) 172 + if (port_conf->port_type == WWAN_PORT_FASTBOOT || 173 + port_conf->port_type == WWAN_PORT_ADB || 174 + port_conf->port_type == WWAN_PORT_MIPC) 173 175 t7xx_port_wwan_create(port); 174 176 175 177 port->rx_length_th = RX_QUEUE_MAXLEN; ··· 226 224 { 227 225 const struct t7xx_port_conf *port_conf = port->port_conf; 228 226 229 - if (port_conf->port_type == WWAN_PORT_FASTBOOT) 227 + if (port_conf->port_type == WWAN_PORT_FASTBOOT || 228 + port_conf->port_type == WWAN_PORT_ADB || 229 + port_conf->port_type == WWAN_PORT_MIPC) 230 230 return; 231 231 232 232 if (state != MD_STATE_READY)