Skip to contentSkip to conversation

net: wwan: t7xx: PCIe driver for MediaTek M.2 modem

PATCH Superseded Ricardo Martinez 5 participants 35 messages Dec 7, 2021 – Jan 13, 2022

Subsystems (5)

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Ricardo Martinez

author reviewer
#0 lore raw

v3 cover net: wwan: t7xx: PCIe driver for MediaTek M.2 modem

t7xx is the PCIe host device driver for Intel 5G 5000 M.2 solution which is based on MediaTek's T700 modem to provide WWAN connectivity. The driver uses the WWAN framework infrastructure to create the following control ports and network interfaces:
* /dev/wwan0mbim0 - Interface conforming to the MBIM protocol. Applications like libmbim [1] or Modem Manager [2] from v1.16 onwards with [3][4] can use it to enable data communication towards WWAN.
* /dev/wwan0at0 - Interface that supports AT commands.
* wwan0 - Primary network interface for IP traffic.

The main blocks in t7xx driver are:
* PCIe layer - Implements probe, removal, and power management callbacks.
* Port-proxy - Provides a common interface to interact with different types of ports such as WWAN ports.
* Modem control & status monitor - Implements the entry point for modem initialization, reset and exit, as well as exception handling.
* CLDMA (Control Layer DMA) - Manages the HW used by the port layer to send control messages to the modem using MediaTek's CCCI (Cross-Core Communication Interface) protocol.
* DPMAIF (Data Plane Modem AP Interface) - Controls the HW that provides uplink and downlink queues for the data path. The data exchange takes place using circular buffers to share data buffer addresses and metadata to describe the packets.
* MHCCIF (Modem Host Cross-Core Interface) - Provides interrupt channels for bidirectional event notification such as handshake, exception, PM and port enumeration.

The compilation of the t7xx driver is enabled by the CONFIG_MTK_T7XX config option which depends on CONFIG_WWAN.
This driver was originally developed by MediaTek. Intel adapted t7xx to the WWAN framework, optimized and refactored the driver source in close collaboration with MediaTek. This will enable getting the t7xx driver on Approved Vendor List for interested OEM's and ODM's productization plans with Intel 5G 5000 M.2 solution.

List of contributors:
Amir Hanania <[email protected]>
Andriy Shevchenko <[email protected]> Chandrashekar Devegowda <[email protected]> Dinesh Sharma <[email protected]>
Eliot Lee <[email protected]>
Haijun Liu <[email protected]>
M Chetan Kumar <[email protected]>
Mika Westerberg <[email protected]> Moises Veleta <[email protected]> Pierre-louis Bossart <[email protected]> Chiranjeevi Rapolu <[email protected]> Ricardo Martinez <[email protected]> Muralidharan Sethuraman <[email protected]> Soumya Prakash Mishra <[email protected]> Sreehari Kancharla <[email protected]> Suresh Nagaraj <[email protected]>

[1] https://www.freedesktop.org/software/libmbim/
[2] https://www.freedesktop.org/software/ModemManager/
[3] https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/merge_requests/582
[4] https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/merge_requests/523

v3:
- Avoid unneeded ping-pong changes between patches.
- Use t7xx_ prefix in functions.
- Use t7xx_ prefix in generic structs where mtk_ or ccci prefix was used.
- Update Authors/Contributors header.
- Remove skb pools used for control path.
- Remove skb pools used for RX data path.
- Do not use dedicated TX queue for ACK-only packets.
- Remove __packed attribute from GPD structs.
- Remove the infrastructure for test and debug ports.
- Use the skb control buffer to store metadata.
- Get the IP packet type from RX PIT.
- Merge variable declaration and simple assignments.
- Use preferred coding patterns.
- Remove global variables.
- Declare HW facing structure members as little endian.
- Rename goto tags to describe what is going to be done.
- Do not use variable length arrays.
- Remove unneeded blank lines source code and kdoc headers.
- Use C99 initialization format for port-proxy ports.
- Clean up comments.
- Review included headers.
- Better use of 100 column limit.
- Remove unneeded mb() in CLDMA.
- Remove unneeded spin locks and atomics.
- Handle read_poll_timeout error.
- Use dev_err_ratelimited() where required.
- Fix resource leak when requesting IRQs.
- Use generic DEFAULT_TX_QUEUE_LEN instead custom macro.
- Use ETH_DATA_LEN instead of defining WWAN_DEFAULT_MTU.
- Use sizeof() instead of defines when the size of structures is required.
- Remove unneeded code from netdev:
No need to configure HW address length
No need to implement .ndo_change_mtu
Remove random address generation
- Code simplifications by using kernel provided functions and macros such as:

    module_pci_driver
    PTR_ERR_OR_ZERO
    for_each_set_bit
    pci_device_is_present
    skb_queue_purge
    list_prev_entry
    __ffs64

v2:
- Replace pdev->driver->name with dev_driver_string(&pdev->dev).
- Replace random_ether_addr() with eth_random_addr().
- Update kernel-doc comment for enum data_policy.
- Indicate the driver is 'Supported' instead of 'Maintained'.
- Fix the Signed-of-by and Co-developed-by tags in the patches.
- Added authors and contributors in the top comment of the src files.

Ricardo Martinez (12):
net: wwan: t7xx: Add control DMA interface
net: wwan: t7xx: Add core components
net: wwan: t7xx: Add port proxy infrastructure
net: wwan: t7xx: Add control port
net: wwan: t7xx: Add AT and MBIM WWAN ports
net: wwan: t7xx: Data path HW layer
net: wwan: t7xx: Add data path interface
net: wwan: t7xx: Add WWAN network interface
net: wwan: t7xx: Introduce power management support
net: wwan: t7xx: Runtime PM
net: wwan: t7xx: Device deep sleep lock/unlock
net: wwan: t7xx: Add maintainers and documentation

 .../networking/device_drivers/wwan/index.rst  |    1 +
 .../networking/device_drivers/wwan/t7xx.rst   |  120 ++
 MAINTAINERS                                   |   11 +
 drivers/net/wwan/Kconfig                      |   14 +
 drivers/net/wwan/Makefile                     |    1 +
 drivers/net/wwan/t7xx/Makefile                |   20 +
 drivers/net/wwan/t7xx/t7xx_cldma.c            |  290 ++++
 drivers/net/wwan/t7xx/t7xx_cldma.h            |  177 ++
 drivers/net/wwan/t7xx/t7xx_common.h           |   95 ++
 drivers/net/wwan/t7xx/t7xx_dpmaif.c           | 1424 ++++++++++++++++
 drivers/net/wwan/t7xx/t7xx_dpmaif.h           |  146 ++
 drivers/net/wwan/t7xx/t7xx_hif_cldma.c        | 1471 +++++++++++++++++
 drivers/net/wwan/t7xx/t7xx_hif_cldma.h        |  140 ++
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c       |  577 +++++++
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h       |  260 +++
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c    | 1275 ++++++++++++++
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h    |  115 ++
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c    |  760 +++++++++
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.h    |   89 +
 drivers/net/wwan/t7xx/t7xx_mhccif.c           |  118 ++
 drivers/net/wwan/t7xx/t7xx_mhccif.h           |   37 +
 drivers/net/wwan/t7xx/t7xx_modem_ops.c        |  714 ++++++++
 drivers/net/wwan/t7xx/t7xx_modem_ops.h        |   87 +
 drivers/net/wwan/t7xx/t7xx_netdev.c           |  433 +++++
 drivers/net/wwan/t7xx/t7xx_netdev.h           |   61 +
 drivers/net/wwan/t7xx/t7xx_pci.c              |  767 +++++++++
 drivers/net/wwan/t7xx/t7xx_pci.h              |  123 ++
 drivers/net/wwan/t7xx/t7xx_pcie_mac.c         |  277 ++++
 drivers/net/wwan/t7xx/t7xx_pcie_mac.h         |   37 +
 drivers/net/wwan/t7xx/t7xx_port.h             |  153 ++
 drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c    |  161 ++
 drivers/net/wwan/t7xx/t7xx_port_proxy.c       |  677 ++++++++
 drivers/net/wwan/t7xx/t7xx_port_proxy.h       |   83 +
 drivers/net/wwan/t7xx/t7xx_port_wwan.c        |  258 +++
 drivers/net/wwan/t7xx/t7xx_reg.h              |  379 +++++
 drivers/net/wwan/t7xx/t7xx_state_monitor.c    |  578 +++++++
 drivers/net/wwan/t7xx/t7xx_state_monitor.h    |  127 ++
 37 files changed, 12056 insertions(+)
 create mode 100644 Documentation/networking/device_drivers/wwan/t7xx.rst
 create mode 100644 drivers/net/wwan/t7xx/Makefile
 create mode 100644 drivers/net/wwan/t7xx/t7xx_cldma.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_cldma.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_common.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_dpmaif.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_dpmaif.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_hif_cldma.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_hif_cldma.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_mhccif.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_mhccif.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_modem_ops.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_modem_ops.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_netdev.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_netdev.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_pci.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_pci.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_pcie_mac.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_pcie_mac.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_port.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_port_proxy.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_port_proxy.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_port_wwan.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_reg.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_state_monitor.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_state_monitor.h
Signature · 1 line
2.17.1
author reviewer
#1 lore raw

PATCH v3 1/12 net: wwan: t7xx: Add control DMA interface

From: Haijun Liu <[email protected]>

Cross Layer DMA (CLDMA) Hardware interface (HIF) enables the control path of Host-Modem data transfers. CLDMA HIF layer provides a common interface to the Port Layer.

CLDMA manages 8 independent RX/TX physical channels with data flow control in HW queues. CLDMA uses ring buffers of General Packet Descriptors (GPD) for TX/RX. GPDs can represent multiple or single data buffers (DB).

CLDMA HIF initializes GPD rings, registers ISR handlers for CLDMA interrupts, and initializes CLDMA HW registers.

CLDMA TX flow:
1. Port Layer write
2. Get DB address
3. Configure GPD
4. Triggering processing via HW register write

CLDMA RX flow:
1. CLDMA HW sends a RX "done" to host
2. Driver starts thread to safely read GPD
3. DB is sent to Port layer
4. Create a new buffer for GPD ring

---
 drivers/net/wwan/t7xx/t7xx_cldma.c     |  290 ++++++
 drivers/net/wwan/t7xx/t7xx_cldma.h     |  177 ++++
 drivers/net/wwan/t7xx/t7xx_hif_cldma.c | 1328 ++++++++++++++++++++++++
 drivers/net/wwan/t7xx/t7xx_hif_cldma.h |  139 +++
 4 files changed, 1934 insertions(+)
 create mode 100644 drivers/net/wwan/t7xx/t7xx_cldma.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_cldma.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_hif_cldma.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_hif_cldma.h
drivers/net/wwan/t7xx/t7xx_cldma.c new file +290 -0
new file mode 100644
index 000000000000..4f068ad27900
@@ -0,0 +1,290 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2021, MediaTek Inc.
+ * Copyright (c) 2021, Intel Corporation.
+ *
+ * Authors:
+ *  Haijun Liu <[email protected]>
+ *  Moises Veleta <[email protected]>
+ *  Ricardo Martinez<[email protected]>
+ *
+ * Contributors:
+ *  Amir Hanania <[email protected]>
+ *  Andy Shevchenko <[email protected]>
+ *  Eliot Lee <[email protected]>
+ *  Sreehari Kancharla <[email protected]>
+ */
+
+#include <linux/bits.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/io-64-nonatomic-lo-hi.h>
+#include <linux/types.h>
+
+#include "t7xx_common.h"
+#include "t7xx_cldma.h"
+
+#define ADDR_SIZE	8
+
+void t7xx_cldma_clear_ip_busy(struct t7xx_cldma_hw *hw_info)
+{
+	u32 val;
+
+	val = ioread32(hw_info->ap_pdn_base + REG_CLDMA_IP_BUSY);
+	val |= IP_BUSY_WAKEUP;
+	iowrite32(val, hw_info->ap_pdn_base + REG_CLDMA_IP_BUSY);
+}
+
+/**
+ * t7xx_cldma_hw_restore() - Restore CLDMA HW registers.
+ * @hw_info: Pointer to struct t7xx_cldma_hw.
+ *
+ * Restore HW after resume. Writes uplink configuration for CLDMA HW.
+ */
+void t7xx_cldma_hw_restore(struct t7xx_cldma_hw *hw_info)
+{
+	u32 ul_cfg;
+
+	ul_cfg = ioread32(hw_info->ap_pdn_base + REG_CLDMA_UL_CFG);
+	ul_cfg &= ~UL_CFG_BIT_MODE_MASK;
+
+	if (hw_info->hw_mode == MODE_BIT_64)
+		ul_cfg |= UL_CFG_BIT_MODE_64;
+	else if (hw_info->hw_mode == MODE_BIT_40)
+		ul_cfg |= UL_CFG_BIT_MODE_40;
+	else if (hw_info->hw_mode == MODE_BIT_36)
+		ul_cfg |= UL_CFG_BIT_MODE_36;
+
+	iowrite32(ul_cfg, hw_info->ap_pdn_base + REG_CLDMA_UL_CFG);
+	/* Disable TX and RX invalid address check */
+	iowrite32(UL_MEM_CHECK_DIS, hw_info->ap_pdn_base + REG_CLDMA_UL_MEM);
+	iowrite32(DL_MEM_CHECK_DIS, hw_info->ap_pdn_base + REG_CLDMA_DL_MEM);
+}
+
+void t7xx_cldma_hw_start_queue(struct t7xx_cldma_hw *hw_info, u8 qno, enum mtk_txrx tx_rx)
+{
+	void __iomem *reg_start_cmd;
+	u32 val;
+
+	reg_start_cmd = (tx_rx == MTK_RX) ? hw_info->ap_pdn_base + REG_CLDMA_DL_START_CMD :
+					    hw_info->ap_pdn_base + REG_CLDMA_UL_START_CMD;
+	val = (qno == CLDMA_ALL_Q) ? CLDMA_ALL_Q : BIT(qno);
+	iowrite32(val, reg_start_cmd);
+}
+
+void t7xx_cldma_hw_start(struct t7xx_cldma_hw *hw_info)
+{
+	/* Enable the TX & RX interrupts */
+	iowrite32(TXRX_STATUS_BITMASK, hw_info->ap_pdn_base + REG_CLDMA_L2TIMCR0);
+	iowrite32(TXRX_STATUS_BITMASK, hw_info->ap_ao_base + REG_CLDMA_L2RIMCR0);
+	/* Enable the empty queue interrupt */
+	iowrite32(EMPTY_STATUS_BITMASK, hw_info->ap_pdn_base + REG_CLDMA_L2TIMCR0);
+	iowrite32(EMPTY_STATUS_BITMASK, hw_info->ap_ao_base + REG_CLDMA_L2RIMCR0);
+}
+
+void t7xx_cldma_hw_reset(void __iomem *ao_base)
+{
+	u32 val;
+
+	val = ioread32(ao_base + REG_INFRA_RST2_SET);
+	val |= RST2_PMIC_SW_RST_SET;
+	iowrite32(val, ao_base + REG_INFRA_RST2_SET);
+	val = ioread32(ao_base + REG_INFRA_RST4_SET);
+	val |= RST4_CLDMA1_SW_RST_SET;
+	iowrite32(val, ao_base + REG_INFRA_RST4_SET);
+	udelay(1);
+
+	val = ioread32(ao_base + REG_INFRA_RST4_CLR);
+	val |= RST4_CLDMA1_SW_RST_CLR;
+	iowrite32(val, ao_base + REG_INFRA_RST4_CLR);
+	val = ioread32(ao_base + REG_INFRA_RST2_CLR);
+	val |= RST2_PMIC_SW_RST_CLR;
+	iowrite32(val, ao_base + REG_INFRA_RST2_CLR);
+}
+
+bool t7xx_cldma_tx_addr_is_set(struct t7xx_cldma_hw *hw_info, unsigned char qno)
+{
+	u32 offset =  REG_CLDMA_UL_START_ADDRL_0 + qno * ADDR_SIZE;
+
+	return !!ioread64(hw_info->ap_pdn_base + offset);
+}
+
+void t7xx_cldma_hw_set_start_addr(struct t7xx_cldma_hw *hw_info, unsigned char qno, u64 address,
+				  enum mtk_txrx tx_rx)
+{
+	void __iomem *base;
+	u32 offset =  qno * ADDR_SIZE;
+
+	if (tx_rx == MTK_RX) {
+		base = hw_info->ap_ao_base;
+		iowrite64(address, base + REG_CLDMA_DL_START_ADDRL_0 + offset);
+	} else {
+		base = hw_info->ap_pdn_base;
+		iowrite64(address, base + REG_CLDMA_UL_START_ADDRL_0 + offset);
+	}
+}
+
+void t7xx_cldma_hw_resume_queue(struct t7xx_cldma_hw *hw_info, unsigned char qno,
+				enum mtk_txrx tx_rx)
+{
+	void __iomem *base = hw_info->ap_pdn_base;
+
+	if (tx_rx == MTK_RX)
+		iowrite32(BIT(qno), base + REG_CLDMA_DL_RESUME_CMD);
+	else
+		iowrite32(BIT(qno), base + REG_CLDMA_UL_RESUME_CMD);
+}
+
+unsigned int t7xx_cldma_hw_queue_status(struct t7xx_cldma_hw *hw_info, unsigned char qno,
+					enum mtk_txrx tx_rx)
+{
+	u32 mask, val;
+
+	mask = (qno == CLDMA_ALL_Q) ? CLDMA_ALL_Q : BIT(qno);
+
+	if (tx_rx == MTK_RX) {
+		val = ioread32(hw_info->ap_ao_base + REG_CLDMA_DL_STATUS);
+		return val & mask;
+	}
+
+	val = ioread32(hw_info->ap_pdn_base + REG_CLDMA_UL_STATUS);
+	return val & mask;
+}
+
+void t7xx_cldma_hw_tx_done(struct t7xx_cldma_hw *hw_info, unsigned int bitmask)
+{
+	unsigned int ch_id;
+
+	ch_id = ioread32(hw_info->ap_pdn_base + REG_CLDMA_L2TISAR0);
+	ch_id &= bitmask;
+	/* Clear the ch IDs in the TX interrupt status register */
+	iowrite32(ch_id, hw_info->ap_pdn_base + REG_CLDMA_L2TISAR0);
+	ioread32(hw_info->ap_pdn_base + REG_CLDMA_L2TISAR0);
+}
+
+void t7xx_cldma_hw_rx_done(struct t7xx_cldma_hw *hw_info, unsigned int bitmask)
+{
+	unsigned int ch_id;
+
+	ch_id = ioread32(hw_info->ap_pdn_base + REG_CLDMA_L2RISAR0);
+	ch_id &= bitmask;
+	/* Clear the ch IDs in the RX interrupt status register */
+	iowrite32(ch_id, hw_info->ap_pdn_base + REG_CLDMA_L2RISAR0);
+	ioread32(hw_info->ap_pdn_base + REG_CLDMA_L2RISAR0);
+}
+
+unsigned int t7xx_cldma_hw_int_status(struct t7xx_cldma_hw *hw_info, unsigned int bitmask,
+				      enum mtk_txrx tx_rx)
+{
+	void __iomem *reg_int_sta;
+	u32 val;
+
+	reg_int_sta = (tx_rx == MTK_RX) ? hw_info->ap_pdn_base + REG_CLDMA_L2RISAR0 :
+					  hw_info->ap_pdn_base + REG_CLDMA_L2TISAR0;
+	val = ioread32(reg_int_sta);
+	return val & bitmask;
+}
+
+void t7xx_cldma_hw_irq_dis_txrx(struct t7xx_cldma_hw *hw_info, unsigned char qno,
+				enum mtk_txrx tx_rx)
+{
+	void __iomem *reg;
+	u32 val;
+
+	reg = (tx_rx == MTK_RX) ? hw_info->ap_ao_base + REG_CLDMA_L2RIMSR0 :
+				  hw_info->ap_pdn_base + REG_CLDMA_L2TIMSR0;
+	val = (qno == CLDMA_ALL_Q) ? CLDMA_ALL_Q : BIT(qno);
+	iowrite32(val, reg);
+}
+
+void t7xx_cldma_hw_irq_dis_eq(struct t7xx_cldma_hw *hw_info, unsigned char qno, enum mtk_txrx tx_rx)
+{
+	void __iomem *reg;
+	u32 val;
+
+	reg = (tx_rx == MTK_RX) ? hw_info->ap_ao_base + REG_CLDMA_L2RIMSR0 :
+				  hw_info->ap_pdn_base + REG_CLDMA_L2TIMSR0;
+
+	val = (qno == CLDMA_ALL_Q) ? CLDMA_ALL_Q : BIT(qno);
+	iowrite32(val << EQ_STA_BIT_OFFSET, reg);
+}
+
+void t7xx_cldma_hw_irq_en_txrx(struct t7xx_cldma_hw *hw_info, unsigned char qno,
+			       enum mtk_txrx tx_rx)
+{
+	void __iomem *reg;
+	u32 val;
+
+	reg = (tx_rx == MTK_RX) ? hw_info->ap_ao_base + REG_CLDMA_L2RIMCR0 :
+				  hw_info->ap_pdn_base + REG_CLDMA_L2TIMCR0;
+	val = (qno == CLDMA_ALL_Q) ? CLDMA_ALL_Q : BIT(qno);
+	iowrite32(val, reg);
+}
+
+void t7xx_cldma_hw_irq_en_eq(struct t7xx_cldma_hw *hw_info, unsigned char qno, enum mtk_txrx tx_rx)
+{
+	void __iomem *reg;
+	u32 val;
+
+	reg = (tx_rx == MTK_RX) ? hw_info->ap_ao_base + REG_CLDMA_L2RIMCR0 :
+				  hw_info->ap_pdn_base + REG_CLDMA_L2TIMCR0;
+	val = (qno == CLDMA_ALL_Q) ? CLDMA_ALL_Q : BIT(qno);
+	iowrite32(val << EQ_STA_BIT_OFFSET, reg);
+}
+
+/**
+ * t7xx_cldma_hw_init() - Initialize CLDMA HW.
+ * @hw_info: Pointer to struct t7xx_cldma_hw.
+ *
+ * Write uplink and downlink configuration to CLDMA HW.
+ */
+void t7xx_cldma_hw_init(struct t7xx_cldma_hw *hw_info)
+{
+	u32 ul_cfg, dl_cfg;
+
+	ul_cfg = ioread32(hw_info->ap_pdn_base + REG_CLDMA_UL_CFG);
+	dl_cfg = ioread32(hw_info->ap_ao_base + REG_CLDMA_DL_CFG);
+	/* Configure the DRAM address mode */
+	ul_cfg &= ~UL_CFG_BIT_MODE_MASK;
+	dl_cfg &= ~DL_CFG_BIT_MODE_MASK;
+
+	if (hw_info->hw_mode == MODE_BIT_64) {
+		ul_cfg |= UL_CFG_BIT_MODE_64;
+		dl_cfg |= DL_CFG_BIT_MODE_64;
+	} else if (hw_info->hw_mode == MODE_BIT_40) {
+		ul_cfg |= UL_CFG_BIT_MODE_40;
+		dl_cfg |= DL_CFG_BIT_MODE_40;
+	} else if (hw_info->hw_mode == MODE_BIT_36) {
+		ul_cfg |= UL_CFG_BIT_MODE_36;
+		dl_cfg |= DL_CFG_BIT_MODE_36;
+	}
+
+	iowrite32(ul_cfg, hw_info->ap_pdn_base + REG_CLDMA_UL_CFG);
+	dl_cfg |= DL_CFG_UP_HW_LAST;
+	iowrite32(dl_cfg, hw_info->ap_ao_base + REG_CLDMA_DL_CFG);
+	iowrite32(0, hw_info->ap_ao_base + REG_CLDMA_INT_MASK);
+	iowrite32(BUSY_MASK_MD, hw_info->ap_ao_base + REG_CLDMA_BUSY_MASK);
+	iowrite32(UL_MEM_CHECK_DIS, hw_info->ap_pdn_base + REG_CLDMA_UL_MEM);
+	iowrite32(DL_MEM_CHECK_DIS, hw_info->ap_pdn_base + REG_CLDMA_DL_MEM);
+}
+
+void t7xx_cldma_hw_stop_queue(struct t7xx_cldma_hw *hw_info, u8 qno, enum mtk_txrx tx_rx)
+{
+	void __iomem *reg_stop_cmd;
+	u32 val;
+
+	reg_stop_cmd = (tx_rx == MTK_RX) ? hw_info->ap_pdn_base + REG_CLDMA_DL_STOP_CMD :
+					   hw_info->ap_pdn_base + REG_CLDMA_UL_STOP_CMD;
+	val = (qno == CLDMA_ALL_Q) ? CLDMA_ALL_Q : BIT(qno);
+	iowrite32(val, reg_stop_cmd);
+}
+
+void t7xx_cldma_hw_stop(struct t7xx_cldma_hw *hw_info, enum mtk_txrx tx_rx)
+{
+	void __iomem *reg_ims;
+
+	reg_ims = (tx_rx == MTK_RX) ? hw_info->ap_ao_base + REG_CLDMA_L2RIMSR0 :
+				      hw_info->ap_pdn_base + REG_CLDMA_L2TIMSR0;
+	iowrite32(TXRX_STATUS_BITMASK, reg_ims);
+	iowrite32(EMPTY_STATUS_BITMASK, reg_ims);
+}
drivers/net/wwan/t7xx/t7xx_cldma.h new file +177 -0

177 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +1328 -0

1,328 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_hif_cldma.h new file +139 -0

139 lines not on this page · raw message

Signature · 1 line
2.17.1
maintainer
#2 lore raw

Re: [PATCH net-next v3 01/12] net: wwan: t7xx: Add control DMA interface

Quoted 1 line · On Mon, 6 Dec 2021 19:47:00 -0700 Ricardo Martinez wrote:

+static inline void __iomem *pcie_addr_transfer(void __iomem *addr, u32 addr_trs1, u32 phy_addr)

please drop the inline keyword from all C files in the next version, the compiler will know to inline trivial functions.

Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +3 -0
+{
+	return addr + phy_addr - addr_trs1;
+}
#3 lore raw

Re: [PATCH net-next v3 01/12] net: wwan: t7xx: Add control DMA interface

In reply to Ricardo Martinez
Quoted 39 lines · Ricardo Martinez

From: Haijun Liu <[email protected]>

Cross Layer DMA (CLDMA) Hardware interface (HIF) enables the control path of Host-Modem data transfers. CLDMA HIF layer provides a common interface to the Port Layer.

CLDMA manages 8 independent RX/TX physical channels with data flow control in HW queues. CLDMA uses ring buffers of General Packet Descriptors (GPD) for TX/RX. GPDs can represent multiple or single data buffers (DB).

CLDMA HIF initializes GPD rings, registers ISR handlers for CLDMA interrupts, and initializes CLDMA HW registers.

CLDMA TX flow:
1. Port Layer write
2. Get DB address
3. Configure GPD
4. Triggering processing via HW register write

CLDMA RX flow:
1. CLDMA HW sends a RX "done" to host
2. Driver starts thread to safely read GPD
3. DB is sent to Port layer
4. Create a new buffer for GPD ring

drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +7 -0
+static struct cldma_request *t7xx_cldma_ring_step_forward(struct cldma_ring *ring,
+							  struct cldma_request *req)
+{
+	if (req->entry.next == &ring->gpd_ring)
+		return list_first_entry(&ring->gpd_ring, struct cldma_request, entry);
+
+	return list_next_entry(req, entry);

drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 120

Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +10 -0
+}
+
+static struct cldma_request *t7xx_cldma_ring_step_backward(struct cldma_ring *ring,
+							   struct cldma_request *req)
+{
+	if (req->entry.prev == &ring->gpd_ring)
+		return list_last_entry(&ring->gpd_ring, struct cldma_request, entry);
+
+	return list_prev_entry(req, entry);
+}

Wouldn't these two seems generic enough to warrant adding something like list_next/prev_entry_circular(...) to list.h?

drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 130

Quoted 9 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +9 -0
+static int t7xx_cldma_alloc_and_map_skb(struct cldma_ctrl *md_ctrl, struct cldma_request *req,
+					size_t size)
+{
+	req->skb = __dev_alloc_skb(size, GFP_KERNEL);
+	if (!req->skb)
+		return -ENOMEM;
+
+	req->mapped_buff = dma_map_single(md_ctrl->dev, req->skb->data,
+					  t7xx_skb_data_size(req->skb), DMA_FROM_DEVICE);

t7xx_skb_data_size() is not defined by this patch but only in a later patch in the series.

Also, I'd prefer its name to be changed to e.g. t7xx_skb_data_area_size() given what it calculates. IHMO, "data size" refers to actual frame/packet/payload and does not include the reserves/*rooms around it so the name is bit misleading as is.

Signature · 1 line
 i.
author reviewer
#4 lore raw

Re: [PATCH net-next v3 01/12] net: wwan: t7xx: Add control DMA interface

Quoted 2 lines · Ilpo Järvinen

On Mon, 6 Dec 2021, Ricardo Martinez wrote:

...

Quoted 11 lines
Quoted 11 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +11 -0
+static struct cldma_request *t7xx_cldma_ring_step_forward(struct cldma_ring *ring,
+							  struct cldma_request *req)
+{
+	if (req->entry.next == &ring->gpd_ring)
+		return list_first_entry(&ring->gpd_ring, struct cldma_request, entry);
+
+	return list_next_entry(req, entry);
+}
+
+static struct cldma_request *t7xx_cldma_ring_step_backward(struct cldma_ring *ring,
+							   struct cldma_request *req)
Quoted 8 lines

drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 120

Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +6 -0
+{
+	if (req->entry.prev == &ring->gpd_ring)
+		return list_last_entry(&ring->gpd_ring, struct cldma_request, entry);
+
+	return list_prev_entry(req, entry);
+}

Wouldn't these two seems generic enough to warrant adding something like list_next/prev_entry_circular(...) to list.h?

Agree, in the upcoming version I'm planning to include something like this to list.h as suggested:

#define list_next_entry_circular(pos, ptr, member) \
    ((pos)->member.next == (ptr) ? \
    list_first_entry(ptr, typeof(*(pos)), member) : \
    list_next_entry(pos, member))

#5 lore raw

Re: [PATCH net-next v3 01/12] net: wwan: t7xx: Add control DMA interface

Quoted 7 lines · Ricardo
Quoted 6 lines · Ilpo Järvinen
Quoted 4 lines · Ricardo Martinez
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +4 -0
+	if (req->entry.next == &ring->gpd_ring)
+		return list_first_entry(&ring->gpd_ring, struct cldma_request, entry);
+
+	return list_next_entry(req, entry);

...

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +4 -0
+	if (req->entry.prev == &ring->gpd_ring)
+		return list_last_entry(&ring->gpd_ring, struct cldma_request, entry);
+
+	return list_prev_entry(req, entry);

...

Quoted 5 lines
Quoted 2 lines

Wouldn't these two seems generic enough to warrant adding something like list_next/prev_entry_circular(...) to list.h?

Agree, in the upcoming version I'm planning to include something like this to list.h as suggested:

I think you mean for next and prev, i.o.w. two helpers, correct?

Quoted 3 lines

#define list_next_entry_circular(pos, ptr, member) \

    ((pos)->member.next == (ptr) ? \

I believe this is list_entry_is_head().

Quoted 2 lines

    list_first_entry(ptr, typeof(*(pos)), member) : \
    list_next_entry(pos, member))

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw

Re: [PATCH net-next v3 01/12] net: wwan: t7xx: Add control DMA interface

Quoted 24 lines · Andy Shevchenko
Quoted 7 lines · Ricardo
Quoted 6 lines · Ilpo Järvinen
Quoted 4 lines · Ricardo Martinez
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +4 -0
+	if (req->entry.next == &ring->gpd_ring)
+		return list_first_entry(&ring->gpd_ring, struct cldma_request, entry);
+
+	return list_next_entry(req, entry);

...

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +4 -0
+	if (req->entry.prev == &ring->gpd_ring)
+		return list_last_entry(&ring->gpd_ring, struct cldma_request, entry);
+
+	return list_prev_entry(req, entry);

...

Quoted 5 lines
Quoted 2 lines

Wouldn't these two seems generic enough to warrant adding something like list_next/prev_entry_circular(...) to list.h?

Agree, in the upcoming version I'm planning to include something like this to list.h as suggested:

Quoted 7 lines

I think you mean for next and prev, i.o.w. two helpers, correct?

Quoted 3 lines

#define list_next_entry_circular(pos, ptr, member) \

    ((pos)->member.next == (ptr) ? \

I believe this is list_entry_is_head().

It takes .next so it's not the same as list_entry_is_head() and list_entry_is_last() doesn't exist.

Signature · 1 line
 i.
Quoted 4 lines
Quoted 2 lines

    list_first_entry(ptr, typeof(*(pos)), member) : \
    list_next_entry(pos, member))

#7 lore raw

Re: [PATCH net-next v3 01/12] net: wwan: t7xx: Add control DMA interface

Quoted 27 lines · Ilpo Järvinen
Quoted 26 lines · Andy Shevchenko
Quoted 7 lines · Ricardo
Quoted 6 lines · Ilpo Järvinen
Quoted 4 lines · Ricardo Martinez
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +4 -0
+	if (req->entry.next == &ring->gpd_ring)
+		return list_first_entry(&ring->gpd_ring, struct cldma_request, entry);
+
+	return list_next_entry(req, entry);

...

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +4 -0
+	if (req->entry.prev == &ring->gpd_ring)
+		return list_last_entry(&ring->gpd_ring, struct cldma_request, entry);
+
+	return list_prev_entry(req, entry);

...

Quoted 5 lines
Quoted 2 lines

Wouldn't these two seems generic enough to warrant adding something like list_next/prev_entry_circular(...) to list.h?

Agree, in the upcoming version I'm planning to include something like this to list.h as suggested:

I think you mean for next and prev, i.o.w. two helpers, correct?

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

#define list_next_entry_circular(pos, ptr, member) \

    ((pos)->member.next == (ptr) ? \

I believe this is list_entry_is_head().

It takes .next so it's not the same as list_entry_is_head() and list_entry_is_last() doesn't exist.

But we have list_last_entry(). So, what about

list_last_entry() == pos ? first : next;

and counterpart

list_first_entry() == pos ? last : prev;

?

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

    list_first_entry(ptr, typeof(*(pos)), member) : \
    list_next_entry(pos, member))

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw

Re: [PATCH net-next v3 01/12] net: wwan: t7xx: Add control DMA interface

Quoted 23 lines · Andy Shevchenko
Quoted 22 lines · Ilpo Järvinen
Quoted 21 lines · Andy Shevchenko
Quoted 7 lines · Ricardo
Quoted 6 lines · Ilpo Järvinen
Quoted 4 lines · Ricardo Martinez
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +4 -0
+	if (req->entry.next == &ring->gpd_ring)
+		return list_first_entry(&ring->gpd_ring, struct cldma_request, entry);
+
+	return list_next_entry(req, entry);

...

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +4 -0
+	if (req->entry.prev == &ring->gpd_ring)
+		return list_last_entry(&ring->gpd_ring, struct cldma_request, entry);
+
+	return list_prev_entry(req, entry);

...

Quoted 3 lines
Quoted 2 lines

Wouldn't these two seems generic enough to warrant adding something like list_next/prev_entry_circular(...) to list.h?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

Agree, in the upcoming version I'm planning to include something like this to list.h as suggested:

I think you mean for next and prev, i.o.w. two helpers, correct?

Quoted 1 line

#define list_next_entry_circular(pos, ptr, member) \

One thing I missed earlier, the sigrature should instead of ptr have head:
#define list_next_entry_circular(pos, head, member)

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

    ((pos)->member.next == (ptr) ? \

I believe this is list_entry_is_head().

It takes .next so it's not the same as list_entry_is_head() and list_entry_is_last() doesn't exist.

But we have list_last_entry(). So, what about

Quoted 7 lines

list_last_entry() == pos ? first : next;

and counterpart

list_first_entry() == pos ? last : prev;

?

Yes, although now that I think it more, using them implies the head element has to be always accessed. It might be marginally cache friendlier to use list_entry_is_head you originally suggested but get the next entry first:

({
	typeof(pos) next__ = list_next_entry(pos, member); \
	!list_entry_is_head(next__, head, member) ? next__ : list_next_entry(next__, member);
})

(This was written directly to email, entirely untested).

Here, the head element would only get accessed when we really need to walk through it.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

    list_first_entry(ptr, typeof(*(pos)), member) : \
    list_next_entry(pos, member))

Signature · 1 line
 i.
author reviewer
#9 lore raw

Re: [PATCH net-next v3 01/12] net: wwan: t7xx: Add control DMA interface

Quoted 46 lines · Ilpo Järvinen
Quoted 17 lines · Andy Shevchenko
Quoted 16 lines · Ilpo Järvinen
Quoted 15 lines · Andy Shevchenko
Quoted 6 lines · Ricardo
Quoted 5 lines · Ilpo Järvinen
Quoted 4 lines · Ricardo Martinez
(quoted diff) +4 -0
+	if (req->entry.next == &ring->gpd_ring)
+		return list_first_entry(&ring->gpd_ring, struct cldma_request, entry);
+
+	return list_next_entry(req, entry);

...

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +4 -0
+	if (req->entry.prev == &ring->gpd_ring)
+		return list_last_entry(&ring->gpd_ring, struct cldma_request, entry);
+
+	return list_prev_entry(req, entry);

...

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Wouldn't these two seems generic enough to warrant adding something like list_next/prev_entry_circular(...) to list.h?

Agree, in the upcoming version I'm planning to include something like this to list.h as suggested:

I think you mean for next and prev, i.o.w. two helpers, correct?

Quoted 1 line

#define list_next_entry_circular(pos, ptr, member) \

One thing I missed earlier, the sigrature should instead of ptr have head:
#define list_next_entry_circular(pos, head, member)

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line

    ((pos)->member.next == (ptr) ? \

I believe this is list_entry_is_head().

It takes .next so it's not the same as list_entry_is_head() and list_entry_is_last() doesn't exist.

But we have list_last_entry(). So, what about

Quoted 7 lines

list_last_entry() == pos ? first : next;

and counterpart

list_first_entry() == pos ? last : prev;

?

Yes, although now that I think it more, using them implies the head element has to be always accessed. It might be marginally cache friendlier to use list_entry_is_head you originally suggested but get the next entry first:

Quoted 8 lines
({
	typeof(pos) next__ = list_next_entry(pos, member); \
	!list_entry_is_head(next__, head, member) ? next__ : list_next_entry(next__, member);
})

(This was written directly to email, entirely untested).

Here, the head element would only get accessed when we really need to walk through it.

I'm not sure if list_next_entry() will work for the last element, what about using list_is_last()?

This way we avoid accessing head if not needed and does not to use 'container_of()' on (pos)->member.next.

    (list_is_last(&(pos)->member, head) ? \
    list_first_entry(head, typeof(*(pos)), member) : \
    list_next_entry(pos, member))

(untested)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

    list_first_entry(ptr, typeof(*(pos)), member) : \
    list_next_entry(pos, member))

#10 lore raw

Re: [PATCH net-next v3 01/12] net: wwan: t7xx: Add control DMA interface

Quoted 59 lines · Ricardo
Quoted 57 lines · Ilpo Järvinen
Quoted 22 lines · Andy Shevchenko
Quoted 21 lines · Ilpo Järvinen
Quoted 20 lines · Andy Shevchenko
Quoted 7 lines · Ricardo
Quoted 6 lines · Ilpo Järvinen
Quoted 5 lines · Ricardo Martinez
(quoted diff) +2 -0
+	if (req->entry.next == &ring->gpd_ring)
+		return list_first_entry(&ring->gpd_ring, struct

cldma_request, entry);

(quoted diff) +2 -0
+
+	return list_next_entry(req, entry);

...

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +2 -0
+	if (req->entry.prev == &ring->gpd_ring)
+		return list_last_entry(&ring->gpd_ring, struct

cldma_request, entry);

(quoted diff) +2 -0
+
+	return list_prev_entry(req, entry);

...

Quoted 3 lines
Quoted 3 lines

Wouldn't these two seems generic enough to warrant adding something like list_next/prev_entry_circular(...) to list.h?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

Agree, in the upcoming version I'm planning to include something like this
to list.h as suggested:

I think you mean for next and prev, i.o.w. two helpers, correct?

Quoted 1 line

#define list_next_entry_circular(pos, ptr, member) \

One thing I missed earlier, the sigrature should instead of ptr have head:
#define list_next_entry_circular(pos, head, member)

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line

    ((pos)->member.next == (ptr) ? \

I believe this is list_entry_is_head().

It takes .next so it's not the same as list_entry_is_head() and list_entry_is_last() doesn't exist.

But we have list_last_entry(). So, what about

Quoted 7 lines

list_last_entry() == pos ? first : next;

and counterpart

list_first_entry() == pos ? last : prev;

?

Yes, although now that I think it more, using them implies the head element has to be always accessed. It might be marginally cache friendlier to use list_entry_is_head you originally suggested but get the next entry first:

({
	typeof(pos) next__ = list_next_entry(pos, member); \
	!list_entry_is_head(next__, head, member) ? next__ :

list_next_entry(next__, member);
})
(This was written directly to email, entirely untested).

Quoted 5 lines
Quoted 2 lines

Here, the head element would only get accessed when we really need to walk through it.

I'm not sure if list_next_entry() will work for the last element, what about using list_is_last()?

Why wouldn't it? E.g., list_for_each_entry() does it for the last entry before terminating the for loop.

Signature · 1 line
 i.
Quoted 12 lines

This way we avoid accessing head if not needed and does not to use 'container_of()' on (pos)->member.next.

    (list_is_last(&(pos)->member, head) ? \
    list_first_entry(head, typeof(*(pos)), member) : \
    list_next_entry(pos, member))

(untested)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

    list_first_entry(ptr, typeof(*(pos)), member) : \
    list_next_entry(pos, member))

author reviewer
#11 lore raw

Re: [PATCH net-next v3 01/12] net: wwan: t7xx: Add control DMA interface

Quoted 60 lines · Ilpo Järvinen
Quoted 58 lines · Ricardo
Quoted 57 lines · Ilpo Järvinen
Quoted 22 lines · Andy Shevchenko
Quoted 21 lines · Ilpo Järvinen
Quoted 20 lines · Andy Shevchenko
Quoted 7 lines · Ricardo
Quoted 6 lines · Ilpo Järvinen
Quoted 5 lines · Ricardo Martinez
(quoted diff) +2 -0
+	if (req->entry.next == &ring->gpd_ring)
+		return list_first_entry(&ring->gpd_ring, struct

cldma_request, entry);

(quoted diff) +2 -0
+
+	return list_next_entry(req, entry);

...

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +2 -0
+	if (req->entry.prev == &ring->gpd_ring)
+		return list_last_entry(&ring->gpd_ring, struct

cldma_request, entry);

(quoted diff) +2 -0
+
+	return list_prev_entry(req, entry);

...

Quoted 3 lines
Quoted 3 lines

Wouldn't these two seems generic enough to warrant adding something like list_next/prev_entry_circular(...) to list.h?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

Agree, in the upcoming version I'm planning to include something like this
to list.h as suggested:

I think you mean for next and prev, i.o.w. two helpers, correct?

Quoted 1 line

#define list_next_entry_circular(pos, ptr, member) \

One thing I missed earlier, the sigrature should instead of ptr have head:
#define list_next_entry_circular(pos, head, member)

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
      ((pos)->member.next == (ptr) ? \

I believe this is list_entry_is_head().

It takes .next so it's not the same as list_entry_is_head() and list_entry_is_last() doesn't exist.

But we have list_last_entry(). So, what about

Quoted 7 lines

list_last_entry() == pos ? first : next;

and counterpart

list_first_entry() == pos ? last : prev;

?

Yes, although now that I think it more, using them implies the head element has to be always accessed. It might be marginally cache friendlier to use list_entry_is_head you originally suggested but get the next entry first:

({
	typeof(pos) next__ = list_next_entry(pos, member); \
	!list_entry_is_head(next__, head, member) ? next__ :

list_next_entry(next__, member);
})
(This was written directly to email, entirely untested).

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Here, the head element would only get accessed when we really need to walk through it.

I'm not sure if list_next_entry() will work for the last element, what about using list_is_last()?

Why wouldn't it? E.g., list_for_each_entry() does it for the last entry before terminating the for loop.

I wasn't sure about using container_of() on the head of the list, but I see that it is not a problem.

Would that still be preferred over the list_is_last() approach?

#12 lore raw

Re: [PATCH net-next v3 01/12] net: wwan: t7xx: Add control DMA interface

Quoted 72 lines · Ricardo
Quoted 70 lines · Ilpo Järvinen
Quoted 68 lines · Ricardo
Quoted 57 lines · Ilpo Järvinen
Quoted 23 lines · Andy Shevchenko
Quoted 22 lines · Ilpo Järvinen
Quoted 21 lines · Andy Shevchenko
Quoted 8 lines · Ricardo
Quoted 7 lines · Ilpo Järvinen
Quoted 6 lines · Ricardo Martinez
(quoted diff) +2 -0
+	if (req->entry.next == &ring->gpd_ring)
+		return list_first_entry(&ring->gpd_ring,

struct
cldma_request, entry);

(quoted diff) +2 -0
+
+	return list_next_entry(req, entry);

...

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +2 -0
+	if (req->entry.prev == &ring->gpd_ring)
+		return list_last_entry(&ring->gpd_ring, struct

cldma_request, entry);

(quoted diff) +2 -0
+
+	return list_prev_entry(req, entry);

...

Quoted 3 lines
Quoted 3 lines

Wouldn't these two seems generic enough to warrant adding something like list_next/prev_entry_circular(...) to list.h?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

Agree, in the upcoming version I'm planning to include something like this
to list.h as suggested:

I think you mean for next and prev, i.o.w. two helpers, correct?

Quoted 1 line

#define list_next_entry_circular(pos, ptr, member) \

One thing I missed earlier, the sigrature should instead of ptr have head:
#define list_next_entry_circular(pos, head, member)

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
      ((pos)->member.next == (ptr) ? \

I believe this is list_entry_is_head().

It takes .next so it's not the same as list_entry_is_head() and list_entry_is_last() doesn't exist.

But we have list_last_entry(). So, what about

Quoted 7 lines

list_last_entry() == pos ? first : next;

and counterpart

list_first_entry() == pos ? last : prev;

?

Yes, although now that I think it more, using them implies the head element has to be always accessed. It might be marginally cache friendlier
to use list_entry_is_head you originally suggested but get the next entry
first:

({
	typeof(pos) next__ = list_next_entry(pos, member); \
	!list_entry_is_head(next__, head, member) ? next__ :
Quoted 7 lines

list_next_entry(next__, member);
})
(This was written directly to email, entirely untested).

Here, the head element would only get accessed when we really need to walk
through it.

I'm not sure if list_next_entry() will work for the last element, what about
using list_is_last()?

Quoted 7 lines
Quoted 2 lines

Why wouldn't it? E.g., list_for_each_entry() does it for the last entry before terminating the for loop.

I wasn't sure about using container_of() on the head of the list, but I see that it is not a problem.

Would that still be preferred over the list_is_last() approach?

I think list_is_last() is fine if that's what you want to use. ...I missed earlier the fact that you were referring to something else than list_entry_is_last thanks to these n similarly named functions :-).

Signature · 1 line
 i.
author reviewer
#13 lore raw

PATCH v3 2/12 net: wwan: t7xx: Add core components

In reply to Ricardo Martinez

From: Haijun Liu <[email protected]>

Registers the t7xx device driver with the kernel. Setup all the core
components: PCIe layer, Modem Host Cross Core Interface (MHCCIF), modem control operations, modem state machine, and build infrastructure.

* PCIe layer code implements driver probe and removal.
* MHCCIF provides interrupt channels to communicate events such as handshake, PM and port enumeration.
* Modem control implements the entry point for modem init, reset and exit.
* The modem status monitor is a state machine used by modem control to complete initialization and stop. It is used also to propagate exception events reported by other components.

---
 drivers/net/wwan/Kconfig                   |  14 +
 drivers/net/wwan/Makefile                  |   1 +
 drivers/net/wwan/t7xx/Makefile             |  12 +
 drivers/net/wwan/t7xx/t7xx_common.h        |  95 ++++
 drivers/net/wwan/t7xx/t7xx_mhccif.c        |  98 ++++
 drivers/net/wwan/t7xx/t7xx_mhccif.h        |  37 ++
 drivers/net/wwan/t7xx/t7xx_modem_ops.c     | 434 ++++++++++++++++
 drivers/net/wwan/t7xx/t7xx_modem_ops.h     |  84 +++
 drivers/net/wwan/t7xx/t7xx_pci.c           | 223 ++++++++
 drivers/net/wwan/t7xx/t7xx_pci.h           |  67 +++
 drivers/net/wwan/t7xx/t7xx_pcie_mac.c      | 277 ++++++++++
 drivers/net/wwan/t7xx/t7xx_pcie_mac.h      |  37 ++
 drivers/net/wwan/t7xx/t7xx_reg.h           | 379 ++++++++++++++
 drivers/net/wwan/t7xx/t7xx_state_monitor.c | 569 +++++++++++++++++++++
 drivers/net/wwan/t7xx/t7xx_state_monitor.h | 124 +++++
 15 files changed, 2451 insertions(+)
 create mode 100644 drivers/net/wwan/t7xx/Makefile
 create mode 100644 drivers/net/wwan/t7xx/t7xx_common.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_mhccif.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_mhccif.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_modem_ops.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_modem_ops.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_pci.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_pci.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_pcie_mac.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_pcie_mac.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_reg.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_state_monitor.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_state_monitor.h
drivers/net/wwan/Kconfig +14 -0
index bdb2b0e46c12..aa1a1f6bfc23 100644
@@ -93,6 +93,20 @@ config IOSM
 
 	  If unsure, say N.
 
+config MTK_T7XX
+	tristate "MediaTek PCIe 5G WWAN modem T7xx device"
+	depends on PCI
+	help
+	  Enables MediaTek PCIe based 5G WWAN modem (T7xx series) device.
+	  Adapts WWAN framework and provides network interface like wwan0
+	  and tty interfaces like wwan0at0 (AT protocol), wwan0mbim0
+	  (MBIM protocol), etc.
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called mtk_t7xx.
+
+	  If unsure, say N.
+
 endif # WWAN
 
 endmenu
drivers/net/wwan/Makefile +1 -0
index e722650bebea..3960c0ae2445 100644
@@ -13,3 +13,4 @@ obj-$(CONFIG_MHI_WWAN_MBIM) += mhi_wwan_mbim.o
 obj-$(CONFIG_QCOM_BAM_DMUX) += qcom_bam_dmux.o
 obj-$(CONFIG_RPMSG_WWAN_CTRL) += rpmsg_wwan_ctrl.o
 obj-$(CONFIG_IOSM) += iosm/
+obj-$(CONFIG_MTK_T7XX) += t7xx/
drivers/net/wwan/t7xx/Makefile new file +12 -0
new file mode 100644
index 000000000000..6a49013bc343
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+ccflags-y += -Werror
+
+obj-${CONFIG_MTK_T7XX} := mtk_t7xx.o
+mtk_t7xx-y:=	t7xx_pci.o \
+		t7xx_pcie_mac.o \
+		t7xx_mhccif.o \
+		t7xx_state_monitor.o  \
+		t7xx_modem_ops.o \
+		t7xx_cldma.o \
+		t7xx_hif_cldma.o  \
drivers/net/wwan/t7xx/t7xx_common.h new file +95 -0

95 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_mhccif.c new file +98 -0

98 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_mhccif.h new file +37 -0
new file mode 100644
index 000000000000..62e9afa59296
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0-only
+ *
+ * Copyright (c) 2021, MediaTek Inc.
+ * Copyright (c) 2021, Intel Corporation.
+ *
+ * Authors:
+ *  Haijun Liu <[email protected]>
+ *  Sreehari Kancharla <[email protected]>
+ *
+ * Contributors:
+ *  Amir Hanania <[email protected]>
+ *  Ricardo Martinez<[email protected]>
+ */
+
+#ifndef __T7XX_MHCCIF_H__
+#define __T7XX_MHCCIF_H__
+
+#include <linux/types.h>
+
+#include "t7xx_pci.h"
+#include "t7xx_reg.h"
+
+#define D2H_SW_INT_MASK (D2H_INT_EXCEPTION_INIT |		\
+			 D2H_INT_EXCEPTION_INIT_DONE |		\
+			 D2H_INT_EXCEPTION_CLEARQ_DONE |	\
+			 D2H_INT_EXCEPTION_ALLQ_RESET |		\
+			 D2H_INT_PORT_ENUM |			\
+			 D2H_INT_ASYNC_MD_HK)
+
+void t7xx_mhccif_mask_set(struct t7xx_pci_dev *t7xx_dev, u32 val);
+void t7xx_mhccif_mask_clr(struct t7xx_pci_dev *t7xx_dev, u32 val);
+u32 t7xx_mhccif_mask_get(struct t7xx_pci_dev *t7xx_dev);
+void t7xx_mhccif_init(struct t7xx_pci_dev *t7xx_dev);
+u32 t7xx_mhccif_read_sw_int_sts(struct t7xx_pci_dev *t7xx_dev);
+void t7xx_mhccif_h2d_swint_trigger(struct t7xx_pci_dev *t7xx_dev, u32 channel);
+
+#endif /*__T7XX_MHCCIF_H__ */
drivers/net/wwan/t7xx/t7xx_modem_ops.c new file +434 -0

434 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_modem_ops.h new file +84 -0

84 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_pci.c new file +223 -0

223 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_pci.h new file +67 -0

67 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_pcie_mac.c new file +277 -0

277 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_pcie_mac.h new file +37 -0
new file mode 100644
index 000000000000..7cb6942fd44f
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0-only
+ *
+ * Copyright (c) 2021, MediaTek Inc.
+ * Copyright (c) 2021, Intel Corporation.
+ *
+ * Authors:
+ *  Haijun Liu <[email protected]>
+ *  Sreehari Kancharla <[email protected]>
+ *
+ * Contributors:
+ *  Moises Veleta <[email protected]>
+ *  Ricardo Martinez<[email protected]>
+ */
+
+#ifndef __T7XX_PCIE_MAC_H__
+#define __T7XX_PCIE_MAC_H__
+
+#include <linux/bits.h>
+#include <linux/io.h>
+
+#include "t7xx_pci.h"
+#include "t7xx_reg.h"
+
+#define IREG_BASE(t7xx_dev)	((t7xx_dev)->base_addr.pcie_mac_ireg_base)
+
+#define PCIE_MAC_MSIX_MSK_SET(t7xx_dev, ext_id)	\
+	iowrite32(BIT(ext_id), IREG_BASE(t7xx_dev) + IMASK_HOST_MSIX_SET_GRP0_0)
+
+void t7xx_pcie_mac_interrupts_en(struct t7xx_pci_dev *t7xx_dev);
+void t7xx_pcie_mac_interrupts_dis(struct t7xx_pci_dev *t7xx_dev);
+void t7xx_pcie_mac_atr_init(struct t7xx_pci_dev *t7xx_dev);
+void t7xx_pcie_mac_clear_int(struct t7xx_pci_dev *t7xx_dev, enum pcie_int int_type);
+void t7xx_pcie_mac_set_int(struct t7xx_pci_dev *t7xx_dev, enum pcie_int int_type);
+void t7xx_pcie_mac_clear_int_status(struct t7xx_pci_dev *t7xx_dev, enum pcie_int int_type);
+void t7xx_pcie_set_mac_msix_cfg(struct t7xx_pci_dev *t7xx_dev, unsigned int irq_count);
+
+#endif /* __T7XX_PCIE_MAC_H__ */
drivers/net/wwan/t7xx/t7xx_reg.h new file +379 -0

379 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +569 -0

569 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_state_monitor.h new file +124 -0

124 lines not on this page · raw message

Signature · 1 line
2.17.1
#14 lore raw

Re: [PATCH net-next v3 02/12] net: wwan: t7xx: Add core components

Quoted 68 lines · Ricardo Martinez

From: Haijun Liu <[email protected]>

Registers the t7xx device driver with the kernel. Setup all the core
components: PCIe layer, Modem Host Cross Core Interface (MHCCIF), modem control operations, modem state machine, and build infrastructure.

* PCIe layer code implements driver probe and removal.
* MHCCIF provides interrupt channels to communicate events such as handshake, PM and port enumeration.
* Modem control implements the entry point for modem init, reset and exit.
* The modem status monitor is a state machine used by modem control to complete initialization and stop. It is used also to propagate exception events reported by other components.

drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +46 -0
+	switch (reason) {
+	case EXCEPTION_HS_TIMEOUT:
+		dev_err(dev, "BOOT_HS_FAIL\n");
+		break;
+
+	case EXCEPTION_EVENT:
+		t7xx_fsm_broadcast_state(ctl, MD_STATE_EXCEPTION);
+		t7xx_md_exception_handshake(ctl->md);
+
+		cnt = 0;
+		while (cnt < FSM_MD_EX_REC_OK_TIMEOUT_MS / FSM_EVENT_POLL_INTERVAL_MS) {
+			if (kthread_should_stop())
+				return;
+
+			spin_lock_irqsave(&ctl->event_lock, flags);
+			event = list_first_entry_or_null(&ctl->event_queue,
+							 struct t7xx_fsm_event, entry);
+			if (event) {
+				if (event->event_id == FSM_EVENT_MD_EX) {
+					fsm_del_kf_event(event);
+				} else if (event->event_id == FSM_EVENT_MD_EX_REC_OK) {
+					rec_ok = true;
+					fsm_del_kf_event(event);
+				}
+			}
+
+			spin_unlock_irqrestore(&ctl->event_lock, flags);
+			if (rec_ok)
+				break;
+
+			cnt++;
+			/* Try again after 20ms */
+			msleep(FSM_EVENT_POLL_INTERVAL_MS);
+		}
+
+		cnt = 0;
+		while (cnt < FSM_MD_EX_PASS_TIMEOUT_MS / FSM_EVENT_POLL_INTERVAL_MS) {
+			if (kthread_should_stop())
+				return;
+
+			spin_lock_irqsave(&ctl->event_lock, flags);
+			event = list_first_entry_or_null(&ctl->event_queue,
+							 struct t7xx_fsm_event, entry);
+			if (event && event->event_id == FSM_EVENT_MD_EX_PASS) {
+				pass = true;
+				fsm_del_kf_event(event);

drivers/net/wwan/t7xx/t7xx_state_monitor.c line 219

Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +10 -0
+			}
+
+			spin_unlock_irqrestore(&ctl->event_lock, flags);
+
+			if (pass)
+				break;
+			cnt++;
+			/* Try again after 20ms */
+			msleep(FSM_EVENT_POLL_INTERVAL_MS);
+		}

It hurts me a bit to see so much code duplication with only that one extra if branch + if condition right-hand sides being different. It would seem like something that could be solved with a helper taking those two things as parameters.

I hope the ordering of FSM_EVENT_MD_EX, FSM_EVENT_MD_EX_REC_OK, and FSM_EVENT_MD_EX_PASS is guaranteed by something. Otherwise, the event being waited for might not become the first entry in the event_queue and the loop just keeps waiting until timeout?

drivers/net/wwan/t7xx/t7xx_state_monitor.c line 487

Quoted 13 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +13 -0
+void t7xx_fsm_clr_event(struct t7xx_fsm_ctl *ctl, enum t7xx_fsm_event_state event_id)
+{
+       struct device *dev = &ctl->md->t7xx_dev->pdev->dev;
+       struct t7xx_fsm_event *event, *evt_next;
+       unsigned long flags;
+
+       spin_lock_irqsave(&ctl->event_lock, flags);
+       list_for_each_entry_safe(event, evt_next, &ctl->event_queue, entry) {
+               dev_err(dev, "Unhandled event %d\n", event->event_id);
+
+               if (event->event_id == event_id)
+                       fsm_del_kf_event(event);
+       }

It seems that only events matching to event_id are removed from the event_queue. Can that dev_err print the same event over and over again (I'm assuming here multiple calls to t7xx_fsm_clr_event can occur) because the other events still remaining in event_queue?

drivers/net/wwan/t7xx/t7xx_state_monitor.h line 75

Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.h new file +5 -0
+struct t7xx_fsm_ctl {
+	struct t7xx_modem	*md;
+	enum md_state		md_state;
+	unsigned int		curr_state;
+	unsigned int		last_state;

The value of last_state is never used.

Signature · 1 line
 i.
author reviewer
#15 lore raw

Re: [PATCH net-next v3 02/12] net: wwan: t7xx: Add core components

On 12/16/2021 3:55 AM, Ilpo Järvinen wrote:
...

Quoted 62 lines
Quoted 47 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +46 -0
+	switch (reason) {
+	case EXCEPTION_HS_TIMEOUT:
+		dev_err(dev, "BOOT_HS_FAIL\n");
+		break;
+
+	case EXCEPTION_EVENT:
+		t7xx_fsm_broadcast_state(ctl, MD_STATE_EXCEPTION);
+		t7xx_md_exception_handshake(ctl->md);
+
+		cnt = 0;
+		while (cnt < FSM_MD_EX_REC_OK_TIMEOUT_MS / FSM_EVENT_POLL_INTERVAL_MS) {
+			if (kthread_should_stop())
+				return;
+
+			spin_lock_irqsave(&ctl->event_lock, flags);
+			event = list_first_entry_or_null(&ctl->event_queue,
+							 struct t7xx_fsm_event, entry);
+			if (event) {
+				if (event->event_id == FSM_EVENT_MD_EX) {
+					fsm_del_kf_event(event);
+				} else if (event->event_id == FSM_EVENT_MD_EX_REC_OK) {
+					rec_ok = true;
+					fsm_del_kf_event(event);
+				}
+			}
+
+			spin_unlock_irqrestore(&ctl->event_lock, flags);
+			if (rec_ok)
+				break;
+
+			cnt++;
+			/* Try again after 20ms */
+			msleep(FSM_EVENT_POLL_INTERVAL_MS);
+		}
+
+		cnt = 0;
+		while (cnt < FSM_MD_EX_PASS_TIMEOUT_MS / FSM_EVENT_POLL_INTERVAL_MS) {
+			if (kthread_should_stop())
+				return;
+
+			spin_lock_irqsave(&ctl->event_lock, flags);
+			event = list_first_entry_or_null(&ctl->event_queue,
+							 struct t7xx_fsm_event, entry);
+			if (event && event->event_id == FSM_EVENT_MD_EX_PASS) {
+				pass = true;
+				fsm_del_kf_event(event);

drivers/net/wwan/t7xx/t7xx_state_monitor.c line 219

Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +10 -0
+			}
+
+			spin_unlock_irqrestore(&ctl->event_lock, flags);
+
+			if (pass)
+				break;
+			cnt++;
+			/* Try again after 20ms */
+			msleep(FSM_EVENT_POLL_INTERVAL_MS);
+		}

It hurts me a bit to see so much code duplication with only that one extra if branch + if condition right-hand sides being different. It would seem like something that could be solved with a helper taking those two things as parameters.

Quoted 5 lines

I hope the ordering of FSM_EVENT_MD_EX, FSM_EVENT_MD_EX_REC_OK, and FSM_EVENT_MD_EX_PASS is guaranteed by something. Otherwise, the event being waited for might not become the first entry in the event_queue and the loop just keeps waiting until timeout?

Ordering is guaranteed by the modem. Removing code duplication in the next iteration.

Quoted 9 lines
Quoted 9 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +9 -0
+void t7xx_fsm_clr_event(struct t7xx_fsm_ctl *ctl, enum t7xx_fsm_event_state event_id)
+{
+       struct device *dev = &ctl->md->t7xx_dev->pdev->dev;
+       struct t7xx_fsm_event *event, *evt_next;
+       unsigned long flags;
+
+       spin_lock_irqsave(&ctl->event_lock, flags);
+       list_for_each_entry_safe(event, evt_next, &ctl->event_queue, entry) {
+               dev_err(dev, "Unhandled event %d\n", event->event_id);
Quoted 9 lines

drivers/net/wwan/t7xx/t7xx_state_monitor.c line 487

Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +4 -0
+
+               if (event->event_id == event_id)
+                       fsm_del_kf_event(event);
+       }

It seems that only events matching to event_id are removed from the event_queue. Can that dev_err print the same event over and over again (I'm assuming here multiple calls to t7xx_fsm_clr_event can occur) because the other events still remaining in event_queue?

The purpose of this function is just to remove an event if present, it is not relevant if there

were other events in the list, so I'll remove the dev_err.

author reviewer
#16 lore raw

PATCH v3 3/12 net: wwan: t7xx: Add port proxy infrastructure

In reply to Ricardo Martinez

From: Haijun Liu <[email protected]>

Port-proxy provides a common interface to interact with different types of ports. Ports export their configuration via struct t7xx_port and operate as defined by struct port_ops.

---
 drivers/net/wwan/t7xx/Makefile             |   1 +
 drivers/net/wwan/t7xx/t7xx_modem_ops.c     |  12 +
 drivers/net/wwan/t7xx/t7xx_port.h          | 153 ++++++
 drivers/net/wwan/t7xx/t7xx_port_proxy.c    | 590 +++++++++++++++++++++
 drivers/net/wwan/t7xx/t7xx_port_proxy.h    |  71 +++
 drivers/net/wwan/t7xx/t7xx_state_monitor.c |   4 +
 6 files changed, 831 insertions(+)
 create mode 100644 drivers/net/wwan/t7xx/t7xx_port.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_port_proxy.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_port_proxy.h
drivers/net/wwan/t7xx/Makefile +1 -0
index 6a49013bc343..99f9ca3b4b51 100644
@@ -10,3 +10,4 @@ mtk_t7xx-y:=	t7xx_pci.o \
 		t7xx_modem_ops.o \
 		t7xx_cldma.o \
 		t7xx_hif_cldma.o  \
+		t7xx_port_proxy.o  \
drivers/net/wwan/t7xx/t7xx_modem_ops.c +12 -0
index 53ab88d33b56..304b096366a6 100644
@@ -34,6 +34,8 @@
 #include "t7xx_modem_ops.h"
 #include "t7xx_pci.h"
 #include "t7xx_pcie_mac.h"
+#include "t7xx_port.h"
+#include "t7xx_port_proxy.h"
 #include "t7xx_reg.h"
 #include "t7xx_state_monitor.h"
 
@@ -212,6 +214,7 @@ static void t7xx_md_exception(struct t7xx_modem *md, enum hif_ex_stage stage)
 	if (stage == HIF_EX_CLEARQ_DONE) {
 		/* Give DHL time to flush data */
 		msleep(PORT_RESET_DELAY_MS);
+		t7xx_port_proxy_reset(md->port_prox);
 	}
 
 	t7xx_cldma_exception(md->md_ctrl[ID_CLDMA1], stage);
@@ -369,6 +372,7 @@ void t7xx_md_reset(struct t7xx_pci_dev *t7xx_dev)
 	spin_lock_init(&md->exp_lock);
 	t7xx_fsm_reset(md);
 	t7xx_cldma_reset(md->md_ctrl[ID_CLDMA1]);
+	t7xx_port_proxy_reset(md->port_prox);
 	md->md_init_finish = true;
 }
 
@@ -404,11 +408,18 @@ int t7xx_md_init(struct t7xx_pci_dev *t7xx_dev)
 	if (ret)
 		goto err_uninit_fsm;
 
+	ret = t7xx_port_proxy_init(md);
+	if (ret)
+		goto err_uninit_cldma;
+
 	t7xx_fsm_append_cmd(md->fsm_ctl, FSM_CMD_START, 0);
 	t7xx_md_sys_sw_init(t7xx_dev);
 	md->md_init_finish = true;
 	return 0;
 
+err_uninit_cldma:
+	t7xx_cldma_exit(md->md_ctrl[ID_CLDMA1]);
+
 err_uninit_fsm:
 	t7xx_fsm_uninit(md);
 
@@ -428,6 +439,7 @@ void t7xx_md_exit(struct t7xx_pci_dev *t7xx_dev)
 		return;
 
 	t7xx_fsm_append_cmd(md->fsm_ctl, FSM_CMD_PRE_STOP, FSM_CMD_FLAG_WAIT_FOR_COMPLETION);
+	t7xx_port_proxy_uninit(md->port_prox);
 	t7xx_cldma_exit(md->md_ctrl[ID_CLDMA1]);
 	t7xx_fsm_uninit(md);
 	destroy_workqueue(md->handshake_wq);
drivers/net/wwan/t7xx/t7xx_port.h new file +153 -0

153 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +590 -0

590 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_port_proxy.h new file +71 -0

71 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_state_monitor.c +4 -0
index cfd4e4b1a8df..a436e1450af6 100644
@@ -38,6 +38,7 @@
 #include "t7xx_modem_ops.h"
 #include "t7xx_pci.h"
 #include "t7xx_pcie_mac.h"
+#include "t7xx_port_proxy.h"
 #include "t7xx_reg.h"
 #include "t7xx_state_monitor.h"
 
@@ -97,6 +98,9 @@ void t7xx_fsm_broadcast_state(struct t7xx_fsm_ctl *ctl, enum md_state state)
 
 	ctl->md_state = state;
 
+	/* Update to port first, otherwise sending message on HS2 may fail */
+	t7xx_port_proxy_md_status_notify(ctl->md->port_prox, state);
+
 	fsm_state_notify(ctl->md, state);
 }
 
Signature · 1 line
2.17.1
#17 lore raw

Re: [PATCH net-next v3 03/12] net: wwan: t7xx: Add port proxy infrastructure

Quoted 13 lines · Ricardo Martinez

From: Haijun Liu <[email protected]>

Port-proxy provides a common interface to interact with different types of ports. Ports export their configuration via struct t7xx_port and operate as defined by struct port_ops.

drivers/net/wwan/t7xx/t7xx_port_proxy.c line 174

Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +3 -0
+		status = FIELD_GET(HDR_FLD_CHN, le32_to_cpu(ccci_h->status));
+		if (status == PORT_CH_STATUS_RX) {
+			port->skb_handler(port, skb);

In the other callsite, port->skb_handler is checked for NULL but not here, is it ok?

drivers/net/wwan/t7xx/t7xx_port_proxy.c line 285

Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +3 -0
+		if (md_state == MD_STATE_EXCEPTION && port_static->tx_ch != PORT_CH_MD_LOG_TX &&
+		    port_static->tx_ch != PORT_CH_UART1_TX)
+			return -ETXTBSY;

Here "TXT" = "text" (it seems unrelated to TX path).

drivers/net/wwan/t7xx/t7xx_port_proxy.h line 32

Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.h new file +3 -0
+#define MTK_MAX_QUEUE_NUM	16
+#define MAX_RX_QUEUE_LENGTH	32
+#define MAX_CTRL_QUEUE_LENGTH	16

MTK_QUEUES, RX_QUEUE_MAXLEN, CTRL_QUEUE_MAXLEN would be shorter and not lose any of the meaning.

drivers/net/wwan/t7xx/t7xx_port_proxy.h line 40

Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.h new file +7 -0
+#define CLDMA_TXQ_MTU		MTK_SKB_4K
+
+struct port_proxy {
+	int				port_number;
+	struct t7xx_port_static		*ports_shared;
+	struct t7xx_port		*ports_private;
+	struct list_head		rx_ch_ports[PORT_CH_ID_MASK];

An off-by-one error in the array sizing?

Signature · 1 line
 i.
author reviewer
#18 lore raw

PATCH v3 4/12 net: wwan: t7xx: Add control port

In reply to Ricardo Martinez

From: Haijun Liu <[email protected]>

Control Port implements driver control messages such as modem-host handshaking, controls port enumeration, and handles exception messages.

The handshaking process between the driver and the modem happens during the init sequence. The process involves the exchange of a list of supported runtime features to make sure that modem and host are ready to provide proper feature lists including port enumeration. Further features can be enabled and controlled in this handshaking process.

---
 drivers/net/wwan/t7xx/Makefile             |   1 +
 drivers/net/wwan/t7xx/t7xx_modem_ops.c     | 263 ++++++++++++++++++++-
 drivers/net/wwan/t7xx/t7xx_modem_ops.h     |   3 +
 drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c | 161 +++++++++++++
 drivers/net/wwan/t7xx/t7xx_port_proxy.c    |  65 ++++-
 drivers/net/wwan/t7xx/t7xx_port_proxy.h    |  11 +
 drivers/net/wwan/t7xx/t7xx_state_monitor.c |   3 +
 drivers/net/wwan/t7xx/t7xx_state_monitor.h |   3 +
 8 files changed, 507 insertions(+), 3 deletions(-)
 create mode 100644 drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c
drivers/net/wwan/t7xx/Makefile +1 -0
index 99f9ca3b4b51..63e1c67b82b5 100644
@@ -11,3 +11,4 @@ mtk_t7xx-y:=	t7xx_pci.o \
 		t7xx_cldma.o \
 		t7xx_hif_cldma.o  \
 		t7xx_port_proxy.o  \
+		t7xx_port_ctrl_msg.o \
drivers/net/wwan/t7xx/t7xx_modem_ops.c +261 -2

318 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_modem_ops.h +3 -0
index 24d2ee5bfbda..842def631b21 100644
@@ -56,6 +56,9 @@ enum md_event_id {
 
 struct t7xx_sys_info {
 	bool				ready;
+	bool				handshake_ongoing;
+	u8				feature_set[FEATURE_COUNT];
+	struct t7xx_port		*ctl_port;
 };
 
 struct t7xx_modem {
drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c new file +161 -0

161 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_port_proxy.c +64 -1

83 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_port_proxy.h +11 -0
index de7ba70bd471..06ccda839445 100644
@@ -42,6 +42,12 @@ struct port_proxy {
 	struct device			*dev;
 };
 
+struct ctrl_msg_header {
+	__le32	ctrl_msg_id;
+	__le32	ex_msg;
+	__le32	data_length;
+};
+
 struct port_msg {
 	__le32	head_pattern;
 	__le32	info;
@@ -60,10 +66,15 @@ struct port_msg {
 #define PORT_ENUM_TAIL_PATTERN	0xa5a5a5a5
 #define PORT_ENUM_VER_MISMATCH	0x00657272
 
+/* Port operations mapping */
+extern struct port_ops ctl_port_ops;
+
 int t7xx_port_proxy_send_skb(struct t7xx_port *port, struct sk_buff *skb);
 void t7xx_port_proxy_set_seq_num(struct t7xx_port *port, struct ccci_header *ccci_h);
 int t7xx_port_proxy_node_control(struct t7xx_modem *md, struct port_msg *port_msg);
 void t7xx_port_proxy_reset(struct port_proxy *port_prox);
+void t7xx_port_proxy_send_msg_to_md(struct port_proxy *port_prox, enum port_ch ch,
+				    unsigned int msg, unsigned int ex_msg);
 void t7xx_port_proxy_uninit(struct port_proxy *port_prox);
 int t7xx_port_proxy_init(struct t7xx_modem *md);
 void t7xx_port_proxy_md_status_notify(struct port_proxy *port_prox, unsigned int state);
drivers/net/wwan/t7xx/t7xx_state_monitor.c +3 -0
index a436e1450af6..d09a64518b8b 100644
@@ -315,6 +315,9 @@ static void fsm_routine_starting(struct t7xx_fsm_ctl *ctl)
 
 	if (!md->core_md.ready) {
 		dev_err(dev, "MD handshake timeout\n");
+		if (md->core_md.handshake_ongoing)
+			t7xx_fsm_append_event(ctl, FSM_EVENT_MD_HS2_EXIT, NULL, 0);
+
 		fsm_routine_exception(ctl, NULL, EXCEPTION_HS_TIMEOUT);
 	} else {
 		fsm_routine_ready(ctl);
drivers/net/wwan/t7xx/t7xx_state_monitor.h +3 -0
index f1e0b1a3f8de..e00aae054d4d 100644
@@ -38,9 +38,12 @@ enum t7xx_fsm_state {
 
 enum t7xx_fsm_event_state {
 	FSM_EVENT_INVALID,
+	FSM_EVENT_MD_HS2,
 	FSM_EVENT_MD_EX,
 	FSM_EVENT_MD_EX_REC_OK,
 	FSM_EVENT_MD_EX_PASS,
+	FSM_EVENT_MD_HS2_EXIT,
+	FSM_EVENT_AP_HS2_EXIT,
 	FSM_EVENT_MAX
 };
 
Signature · 1 line
2.17.1
#19 lore raw

Re: [PATCH net-next v3 04/12] net: wwan: t7xx: Add control port

Quoted 24 lines · Ricardo Martinez

From: Haijun Liu <[email protected]>

Control Port implements driver control messages such as modem-host handshaking, controls port enumeration, and handles exception messages.

The handshaking process between the driver and the modem happens during the init sequence. The process involves the exchange of a list of supported runtime features to make sure that modem and host are ready to provide proper feature lists including port enumeration. Further features can be enabled and controlled in this handshaking process.

drivers/net/wwan/t7xx/t7xx_modem_ops.c +6 -0
+	ccci_h->packet_header = 0;
+	ccci_h->packet_len = cpu_to_le32(packet_size);
+	ccci_h->status &= cpu_to_le32(~HDR_FLD_CHN);
+	ccci_h->status |= cpu_to_le32(FIELD_PREP(HDR_FLD_CHN, port_static->tx_ch));
+	ccci_h->status &= cpu_to_le32(~HDR_FLD_SEQ);
+	ccci_h->ex_msg = 0;

...

Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c +5 -0
+		ccci_h->packet_header = cpu_to_le32(CCCI_HEADER_NO_DATA);
+		ccci_h->packet_len = cpu_to_le32(sizeof(*ctrl_msg_h) + CCCI_H_LEN);
+		ccci_h->status &= cpu_to_le32(~HDR_FLD_CHN);
+		ccci_h->status |= cpu_to_le32(FIELD_PREP(HDR_FLD_CHN, ch));
+		ccci_h->ex_msg = 0;

...

drivers/net/wwan/t7xx/t7xx_port_proxy.c static void t7xx_proxy_setup_ch_mapping(struct port_proxy *port_prox) · line 370

Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c +5 -0
+		ccci_h->packet_header = cpu_to_le32(CCCI_HEADER_NO_DATA);
+		ccci_h->packet_len = cpu_to_le32(msg);
+		ccci_h->status &= cpu_to_le32(~HDR_FLD_CHN);
+		ccci_h->status |= cpu_to_le32(FIELD_PREP(HDR_FLD_CHN, ch));
+		ccci_h->ex_msg = cpu_to_le32(ex_msg);

A helper to handle the common part of ccci_h init would be useful.

Signature · 1 line
 i.
author reviewer
#20 lore raw

PATCH v3 5/12 net: wwan: t7xx: Add AT and MBIM WWAN ports

In reply to Ricardo Martinez

From: Chandrashekar Devegowda <[email protected]>

Adds AT and MBIM ports to the port proxy infrastructure.
The initialization method is responsible for creating the corresponding ports using the WWAN framework infrastructure. The implemented WWAN port operations are start, stop, and TX.

---
 drivers/net/wwan/t7xx/Makefile          |   1 +
 drivers/net/wwan/t7xx/t7xx_port_proxy.c |  24 +++
 drivers/net/wwan/t7xx/t7xx_port_proxy.h |   1 +
 drivers/net/wwan/t7xx/t7xx_port_wwan.c  | 258 ++++++++++++++++++++++++
 4 files changed, 284 insertions(+)
 create mode 100644 drivers/net/wwan/t7xx/t7xx_port_wwan.c
drivers/net/wwan/t7xx/Makefile +1 -0
index 63e1c67b82b5..9eec2e2472fb 100644
@@ -12,3 +12,4 @@ mtk_t7xx-y:=	t7xx_pci.o \
 		t7xx_hif_cldma.o  \
 		t7xx_port_proxy.o  \
 		t7xx_port_ctrl_msg.o \
+		t7xx_port_wwan.o \
drivers/net/wwan/t7xx/t7xx_port_proxy.c +24 -0
index 67219319e9f7..4c6f255c4d2f 100644
@@ -51,6 +51,30 @@
 
 static struct t7xx_port_static t7xx_md_ports[] = {
 	{
+		.tx_ch = PORT_CH_UART2_TX,
+		.rx_ch = PORT_CH_UART2_RX,
+		.txq_index = Q_IDX_AT_CMD,
+		.rxq_index = Q_IDX_AT_CMD,
+		.txq_exp_index = 0xff,
+		.rxq_exp_index = 0xff,
+		.path_id = ID_CLDMA1,
+		.flags = PORT_F_RX_CHAR_NODE,
+		.ops = &wwan_sub_port_ops,
+		.name = "AT",
+		.port_type = WWAN_PORT_AT,
+	}, {
+		.tx_ch = PORT_CH_MBIM_TX,
+		.rx_ch = PORT_CH_MBIM_RX,
+		.txq_index = Q_IDX_MBIM,
+		.rxq_index = Q_IDX_MBIM,
+		.txq_exp_index = 0,
+		.rxq_exp_index = 0,
+		.path_id = ID_CLDMA1,
+		.flags = PORT_F_RX_CHAR_NODE,
+		.ops = &wwan_sub_port_ops,
+		.name = "MBIM",
+		.port_type = WWAN_PORT_MBIM,
+	}, {
 		.tx_ch = PORT_CH_CONTROL_TX,
 		.rx_ch = PORT_CH_CONTROL_RX,
 		.txq_index = Q_IDX_CTRL,
drivers/net/wwan/t7xx/t7xx_port_proxy.h +1 -0
index 06ccda839445..1f49d1ef6bad 100644
@@ -67,6 +67,7 @@ struct port_msg {
 #define PORT_ENUM_VER_MISMATCH	0x00657272
 
 /* Port operations mapping */
+extern struct port_ops wwan_sub_port_ops;
 extern struct port_ops ctl_port_ops;
 
 int t7xx_port_proxy_send_skb(struct t7xx_port *port, struct sk_buff *skb);
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +258 -0

258 lines not on this page · raw message

Signature · 1 line
2.17.1
#21 lore raw

Re: [PATCH net-next v3 05/12] net: wwan: t7xx: Add AT and MBIM WWAN ports

Hi Ricardo,

Overall, it looks good, but:

Quoted 19 lines · Ricardo Martinez

From: Chandrashekar Devegowda <[email protected]>

Adds AT and MBIM ports to the port proxy infrastructure.
The initialization method is responsible for creating the corresponding ports using the WWAN framework infrastructure. The implemented WWAN port operations are start, stop, and TX.

---
 drivers/net/wwan/t7xx/Makefile          |   1 +
 drivers/net/wwan/t7xx/t7xx_port_proxy.c |  24 +++
 drivers/net/wwan/t7xx/t7xx_port_proxy.h |   1 +
 drivers/net/wwan/t7xx/t7xx_port_wwan.c  | 258 ++++++++++++++++++++++++
 4 files changed, 284 insertions(+)
 create mode 100644 drivers/net/wwan/t7xx/t7xx_port_wwan.c

[...]

Quoted 68 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +68 -0
+static int t7xx_port_ctrl_tx(struct wwan_port *port, struct sk_buff *skb)
+{
+       struct t7xx_port *port_private = wwan_port_get_drvdata(port);
+       size_t actual_count = 0, alloc_size = 0, txq_mtu = 0;
+       struct t7xx_port_static *port_static;
+       int i, multi_packet = 1, ret = 0;
+       struct sk_buff *skb_ccci = NULL;
+       struct t7xx_fsm_ctl *ctl;
+       enum md_state md_state;
+       unsigned int count;
+       bool port_multi;
+
+       count = skb->len;
+       if (!count)
+               return -EINVAL;
+
+       port_static = port_private->port_static;
+       ctl = port_private->t7xx_dev->md->fsm_ctl;
+       md_state = t7xx_fsm_get_md_state(ctl);
+       if (md_state == MD_STATE_WAITING_FOR_HS1 || md_state == MD_STATE_WAITING_FOR_HS2) {
+               dev_warn(port_private->dev, "Cannot write to %s port when md_state=%d\n",
+                        port_static->name, md_state);
+               return -ENODEV;
+       }
+
+       txq_mtu = CLDMA_TXQ_MTU;
+
+       if (port_private->flags & PORT_F_USER_HEADER) {
+               if (port_private->flags & PORT_F_USER_HEADER && count > txq_mtu) {
+                       dev_err(port_private->dev, "Packet %u larger than MTU on %s port\n",
+                               count, port_static->name);
+                       return -ENOMEM;
+               }
+
+               alloc_size = min_t(size_t, txq_mtu, count);
+               actual_count = alloc_size;
+       } else {
+               alloc_size = min_t(size_t, txq_mtu, count + CCCI_H_ELEN);
+               actual_count = alloc_size - CCCI_H_ELEN;
+               port_multi = t7xx_port_wwan_multipkt_capable(port_static);
+               if ((count + CCCI_H_ELEN > txq_mtu) && port_multi)
+                       multi_packet = DIV_ROUND_UP(count, txq_mtu - CCCI_H_ELEN);
+       }
+
+       for (i = 0; i < multi_packet; i++) {
+               struct ccci_header *ccci_h = NULL;
+
+               if (multi_packet > 1 && multi_packet == i + 1) {
+                       actual_count = count % (txq_mtu - CCCI_H_ELEN);
+                       alloc_size = actual_count + CCCI_H_ELEN;
+               }
+
+               skb_ccci = __dev_alloc_skb(alloc_size, GFP_KERNEL);
+               if (!skb_ccci)
+                       return -ENOMEM;
+
+               ccci_h = skb_put(skb_ccci, CCCI_H_LEN);
+               ccci_h->packet_header = 0;
+               ccci_h->packet_len = cpu_to_le32(actual_count + CCCI_H_LEN);
+               ccci_h->status &= cpu_to_le32(~HDR_FLD_CHN);
+               ccci_h->status |= cpu_to_le32(FIELD_PREP(HDR_FLD_CHN, port_static->tx_ch));
+               ccci_h->ex_msg = 0;
+
+               memcpy(skb_put(skb_ccci, actual_count), skb->data + i * (txq_mtu - CCCI_H_ELEN),
+                      actual_count);
+
+               t7xx_port_proxy_set_seq_num(port_private, ccci_h);
+

drivers/net/wwan/t7xx/t7xx_port_wwan.c line 138

Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +10 -0
+               ret = t7xx_port_send_skb_to_md(port_private, skb_ccci, true);
+               if (ret)
+                       goto err_free_skb;
+
+               port_private->seq_nums[MTK_TX]++;
+
+               if (multi_packet == 1)
+                       return actual_count;
+               else if (multi_packet == i + 1)
+                       return count;

wwan port tx ops is supposed to return 0 on success, and release the processed skb. In your case it works because wwan core does:

ret = wwan_port_op_tx(port, skb, !!(filp->f_flags & O_NONBLOCK));

if (ret) {
        kfree_skb(skb);
        return ret;
}

So returning a positive value here (count) makes the core enter the error case, release the skb for you and return your count value to write fops. Eventually, you land on your feet, but it's not what was expected from tx ops. You should simply return 0 on success and release the skb. Alternatively, if you think partial TX is something we need, it should be somewhat documented in the wwan_port_fops_write function or tx_ops definition.

Regards,
Loic

#22 lore raw

Re: [PATCH net-next v3 05/12] net: wwan: t7xx: Add AT and MBIM WWAN ports

In reply to Ricardo Martinez
Quoted 80 lines · Ricardo Martinez

From: Chandrashekar Devegowda <[email protected]>

Adds AT and MBIM ports to the port proxy infrastructure.
The initialization method is responsible for creating the corresponding ports using the WWAN framework infrastructure. The implemented WWAN port operations are start, stop, and TX.

drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +69 -0
+static int t7xx_port_ctrl_tx(struct wwan_port *port, struct sk_buff *skb)
+{
+	struct t7xx_port *port_private = wwan_port_get_drvdata(port);
+	size_t actual_count = 0, alloc_size = 0, txq_mtu = 0;
+	struct t7xx_port_static *port_static;
+	int i, multi_packet = 1, ret = 0;
+	struct sk_buff *skb_ccci = NULL;
+	struct t7xx_fsm_ctl *ctl;
+	enum md_state md_state;
+	unsigned int count;
+	bool port_multi;
+
+	count = skb->len;
+	if (!count)
+		return -EINVAL;
+
+	port_static = port_private->port_static;
+	ctl = port_private->t7xx_dev->md->fsm_ctl;
+	md_state = t7xx_fsm_get_md_state(ctl);
+	if (md_state == MD_STATE_WAITING_FOR_HS1 || md_state == MD_STATE_WAITING_FOR_HS2) {
+		dev_warn(port_private->dev, "Cannot write to %s port when md_state=%d\n",
+			 port_static->name, md_state);
+		return -ENODEV;
+	}
+
+	txq_mtu = CLDMA_TXQ_MTU;
+
+	if (port_private->flags & PORT_F_USER_HEADER) {
+		if (port_private->flags & PORT_F_USER_HEADER && count > txq_mtu) {
+			dev_err(port_private->dev, "Packet %u larger than MTU on %s port\n",
+				count, port_static->name);
+			return -ENOMEM;
+		}
+
+		alloc_size = min_t(size_t, txq_mtu, count);
+		actual_count = alloc_size;
+	} else {
+		alloc_size = min_t(size_t, txq_mtu, count + CCCI_H_ELEN);
+		actual_count = alloc_size - CCCI_H_ELEN;
+		port_multi = t7xx_port_wwan_multipkt_capable(port_static);
+		if ((count + CCCI_H_ELEN > txq_mtu) && port_multi)
+			multi_packet = DIV_ROUND_UP(count, txq_mtu - CCCI_H_ELEN);
+	}
+
+	for (i = 0; i < multi_packet; i++) {
+		struct ccci_header *ccci_h = NULL;
+
+		if (multi_packet > 1 && multi_packet == i + 1) {
+			actual_count = count % (txq_mtu - CCCI_H_ELEN);
+			alloc_size = actual_count + CCCI_H_ELEN;
+		}
+
+		skb_ccci = __dev_alloc_skb(alloc_size, GFP_KERNEL);
+		if (!skb_ccci)
+			return -ENOMEM;
+
+		ccci_h = skb_put(skb_ccci, CCCI_H_LEN);
+		ccci_h->packet_header = 0;
+		ccci_h->packet_len = cpu_to_le32(actual_count + CCCI_H_LEN);
+		ccci_h->status &= cpu_to_le32(~HDR_FLD_CHN);
+		ccci_h->status |= cpu_to_le32(FIELD_PREP(HDR_FLD_CHN, port_static->tx_ch));
+		ccci_h->ex_msg = 0;
+
+		memcpy(skb_put(skb_ccci, actual_count), skb->data + i * (txq_mtu - CCCI_H_ELEN),
+		       actual_count);
+
+		t7xx_port_proxy_set_seq_num(port_private, ccci_h);
+
+		ret = t7xx_port_send_skb_to_md(port_private, skb_ccci, true);

drivers/net/wwan/t7xx/t7xx_port_wwan.c line 139

Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +10 -0
+		if (ret)
+			goto err_free_skb;
+
+		port_private->seq_nums[MTK_TX]++;
+
+		if (multi_packet == 1)
+			return actual_count;
+		else if (multi_packet == i + 1)
+			return count;
+	}

I'd recommend renaming variables to make it clearer what they count:
- count -> bytes
- actual_count -> actual_bytes
- multi_packet -> packets

Signature · 1 line
 i.
#23 lore raw

Re: [PATCH net-next v3 05/12] net: wwan: t7xx: Add AT and MBIM WWAN ports

Quoted 5 lines · Ilpo Järvinen

drivers/net/wwan/t7xx/t7xx_port_wwan.c line 137

Quoted 3 lines · Ricardo Martinez
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +3 -0
+		if (multi_packet == 1)
+			return actual_count;
+		else if (multi_packet == i + 1)

On top of that redundant 'else' here.

Quoted 7 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+			return count;
+	}

I'd recommend renaming variables to make it clearer what they count:
- count -> bytes
- actual_count -> actual_bytes
- multi_packet -> packets

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author reviewer
#24 lore raw

PATCH v3 6/12 net: wwan: t7xx: Data path HW layer

In reply to Ricardo Martinez

From: Haijun Liu <[email protected]>

Data Path Modem AP Interface (DPMAIF) HW layer provides HW abstraction for the upper layer (DPMAIF HIF). It implements functions to do the HW configuration, TX/RX control and interrupt handling.

---
 drivers/net/wwan/t7xx/t7xx_dpmaif.c | 1424 +++++++++++++++++++++++++++
 drivers/net/wwan/t7xx/t7xx_dpmaif.h |  146 +++
 2 files changed, 1570 insertions(+)
 create mode 100644 drivers/net/wwan/t7xx/t7xx_dpmaif.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_dpmaif.h
drivers/net/wwan/t7xx/t7xx_dpmaif.c new file +1424 -0
new file mode 100644
index 000000000000..e98f2a0d2e7c
@@ -0,0 +1,1424 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2021, MediaTek Inc.
+ * Copyright (c) 2021, Intel Corporation.
+ *
+ * Authors:
+ *  Amir Hanania <[email protected]>
+ *  Haijun Liu <[email protected]>
+ *  Moises Veleta <[email protected]>
+ *  Ricardo Martinez<[email protected]>
+ *
+ * Contributors:
+ *  Andy Shevchenko <[email protected]>
+ *  Chiranjeevi Rapolu <[email protected]>
+ *  Eliot Lee <[email protected]>
+ *  Sreehari Kancharla <[email protected]>
+ */
+
+#include <linux/bits.h>
+#include <linux/bitfield.h>
+#include <linux/bitops.h>
+#include <linux/delay.h>
+#include <linux/dev_printk.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/types.h>
+
+#include "t7xx_dpmaif.h"
+#include "t7xx_hif_dpmaif.h"
+#include "t7xx_reg.h"
+
+static int t7xx_dpmaif_init_intr(struct dpmaif_hw_info *hw_info)
+{
+	struct dpmaif_isr_en_mask *isr_en_msk = &hw_info->isr_en_mask;
+	u32 value, ul_intr_enable, dl_intr_enable;
+	int ret;
+
+	ul_intr_enable = DP_UL_INT_ERR_MSK | DP_UL_INT_QDONE_MSK;
+	isr_en_msk->ap_ul_l2intr_en_msk = ul_intr_enable;
+	iowrite32(DPMAIF_AP_ALL_L2TISAR0_MASK, hw_info->pcie_base + DPMAIF_AP_L2TISAR0);
+
+	/* Set interrupt enable mask */
+	iowrite32(ul_intr_enable, hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMCR0);
+	iowrite32(~ul_intr_enable, hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMSR0);
+
+	/* Check mask status */
+	ret = readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMR0,
+					value, (value & ul_intr_enable) != ul_intr_enable, 0,
+					DPMAIF_CHECK_INIT_TIMEOUT_US);
+	if (ret)
+		return ret;
+
+	dl_intr_enable = DP_DL_INT_PITCNT_LEN_ERR | DP_DL_INT_BATCNT_LEN_ERR;
+	isr_en_msk->ap_dl_l2intr_err_en_msk = dl_intr_enable;
+	ul_intr_enable = DPMAIF_DL_INT_DLQ0_QDONE | DPMAIF_DL_INT_DLQ0_PITCNT_LEN |
+		    DPMAIF_DL_INT_DLQ1_QDONE | DPMAIF_DL_INT_DLQ1_PITCNT_LEN;
+	isr_en_msk->ap_ul_l2intr_en_msk = ul_intr_enable;
+	iowrite32(DPMAIF_AP_APDL_ALL_L2TISAR0_MASK, hw_info->pcie_base + DPMAIF_AP_APDL_L2TISAR0);
+
+	/* Set DL ISR PD enable mask */
+	iowrite32(~ul_intr_enable, hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMSR0);
+	ret = readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMR0,
+					value, (value & ul_intr_enable) != ul_intr_enable, 0,
+					DPMAIF_CHECK_INIT_TIMEOUT_US);
+	if (ret)
+		return ret;
+
+	isr_en_msk->ap_udl_ip_busy_en_msk = DPMAIF_UDL_IP_BUSY;
+	iowrite32(DPMAIF_AP_IP_BUSY_MASK, hw_info->pcie_base + DPMAIF_AP_IP_BUSY);
+	iowrite32(isr_en_msk->ap_udl_ip_busy_en_msk,
+		  hw_info->pcie_base + DPMAIF_AO_AP_DLUL_IP_BUSY_MASK);
+	value = ioread32(hw_info->pcie_base + DPMAIF_AO_UL_AP_L1TIMR0);
+	value |= DPMAIF_DL_INT_Q2APTOP | DPMAIF_DL_INT_Q2TOQ1;
+	iowrite32(value, hw_info->pcie_base + DPMAIF_AO_UL_AP_L1TIMR0);
+	iowrite32(DPMA_HPC_ALL_INT_MASK, hw_info->pcie_base + DPMAIF_HPC_INTR_MASK);
+
+	return 0;
+}
+
+static void t7xx_dpmaif_mask_ulq_interrupt(struct dpmaif_ctrl *dpmaif_ctrl, unsigned int q_num)
+{
+	struct dpmaif_hw_info *hw_info = &dpmaif_ctrl->hif_hw_info;
+	struct dpmaif_isr_en_mask *isr_en_msk;
+	u32 value, ul_int_que_done;
+	int ret;
+
+	isr_en_msk = &hw_info->isr_en_mask;
+	ul_int_que_done = BIT(q_num + DP_UL_INT_DONE_OFFSET) & DP_UL_INT_QDONE_MSK;
+	isr_en_msk->ap_ul_l2intr_en_msk &= ~ul_int_que_done;
+	iowrite32(ul_int_que_done, hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMSR0);
+
+	ret = readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMR0,
+					value, (value & ul_int_que_done) == ul_int_que_done, 0,
+					DPMAIF_CHECK_TIMEOUT_US);
+	if (ret)
+		dev_err(dpmaif_ctrl->dev,
+			"Could not mask the UL interrupt. DPMAIF_AO_UL_AP_L2TIMR0 is 0x%x\n",
+			value);
+}
+
+void t7xx_dpmaif_unmask_ulq_intr(struct dpmaif_ctrl *dpmaif_ctrl, unsigned int q_num)
+{
+	struct dpmaif_hw_info *hw_info = &dpmaif_ctrl->hif_hw_info;
+	struct dpmaif_isr_en_mask *isr_en_msk;
+	u32 value, ul_int_que_done;
+	int ret;
+
+	isr_en_msk = &hw_info->isr_en_mask;
+	ul_int_que_done = BIT(q_num + DP_UL_INT_DONE_OFFSET) & DP_UL_INT_QDONE_MSK;
+	isr_en_msk->ap_ul_l2intr_en_msk |= ul_int_que_done;
+	iowrite32(ul_int_que_done, hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMCR0);
+
+	ret = readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMR0,
+					value, (value & ul_int_que_done) != ul_int_que_done, 0,
+					DPMAIF_CHECK_TIMEOUT_US);
+	if (ret)
+		dev_err(dpmaif_ctrl->dev,
+			"Could not unmask the UL interrupt. DPMAIF_AO_UL_AP_L2TIMR0 is 0x%x\n",
+			value);
+}
+
+static void t7xx_dpmaif_dl_mask_batcnt_len_err_intr(struct dpmaif_hw_info *hw_info)
+{
+	hw_info->isr_en_mask.ap_dl_l2intr_en_msk &= ~DP_DL_INT_BATCNT_LEN_ERR;
+	iowrite32(DP_DL_INT_BATCNT_LEN_ERR, hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMSR0);
+}
+
+void t7xx_dpmaif_dl_unmask_batcnt_len_err_intr(struct dpmaif_hw_info *hw_info)
+{
+	hw_info->isr_en_mask.ap_dl_l2intr_en_msk |= DP_DL_INT_BATCNT_LEN_ERR;
+	iowrite32(DP_DL_INT_BATCNT_LEN_ERR, hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMCR0);
+}
+
+static void t7xx_dpmaif_dl_mask_pitcnt_len_err_intr(struct dpmaif_hw_info *hw_info)
+{
+	hw_info->isr_en_mask.ap_dl_l2intr_en_msk &= ~DP_DL_INT_PITCNT_LEN_ERR;
+	iowrite32(DP_DL_INT_PITCNT_LEN_ERR, hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMSR0);
+}
+
+void t7xx_dpmaif_dl_unmask_pitcnt_len_err_intr(struct dpmaif_hw_info *hw_info)
+{
+	hw_info->isr_en_mask.ap_dl_l2intr_en_msk |= DP_DL_INT_PITCNT_LEN_ERR;
+	iowrite32(DP_DL_INT_PITCNT_LEN_ERR, hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMCR0);
+}
+
+static u32 t7xx_update_dlq_interrupt(struct dpmaif_hw_info *hw_info, u32 q_done)
+{
+	u32 value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMR0);
+	iowrite32(q_done, hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMSR0);
+	return value;
+}
+
+static int t7xx_mask_dlq_interrupt(struct dpmaif_ctrl *dpmaif_ctrl, unsigned char qno)
+{
+	struct dpmaif_hw_info *hw_info = &dpmaif_ctrl->hif_hw_info;
+	u32 value, q_done;
+	int ret;
+
+	q_done = (qno == DPF_RX_QNO0) ? DPMAIF_DL_INT_DLQ0_QDONE : DPMAIF_DL_INT_DLQ1_QDONE;
+	iowrite32(q_done, hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMSR0);
+
+	ret = read_poll_timeout_atomic(t7xx_update_dlq_interrupt, value, value & q_done,
+				       0, DPMAIF_CHECK_TIMEOUT_US, false, hw_info, q_done);
+	if (ret) {
+		dev_err(dpmaif_ctrl->dev,
+			"Could not mask the DL interrupt. DPMAIF_AO_UL_AP_L2TIMR0 is 0x%x\n",
+			value);
+		return -ETIMEDOUT;
+	}
+
+	hw_info->isr_en_mask.ap_dl_l2intr_en_msk &= ~q_done;
+	return 0;
+}
+
+void t7xx_dpmaif_dlq_unmask_rx_done(struct dpmaif_hw_info *hw_info, unsigned char qno)
+{
+	u32 mask;
+
+	mask = (qno == DPF_RX_QNO0) ? DPMAIF_DL_INT_DLQ0_QDONE : DPMAIF_DL_INT_DLQ1_QDONE;
+	iowrite32(mask, hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMCR0);
+	hw_info->isr_en_mask.ap_dl_l2intr_en_msk |= mask;
+}
+
+void t7xx_dpmaif_clr_ip_busy_sts(struct dpmaif_hw_info *hw_info)
+{
+	u32 ip_busy_sts;
+
+	ip_busy_sts = ioread32(hw_info->pcie_base + DPMAIF_AP_IP_BUSY);
+	iowrite32(ip_busy_sts, hw_info->pcie_base + DPMAIF_AP_IP_BUSY);
+}
+
+static void t7xx_dpmaif_dlq_mask_rx_pitcnt_len_err_intr(struct dpmaif_hw_info *hw_info,
+							unsigned char qno)
+{
+	if (qno == DPF_RX_QNO0)
+		iowrite32(DPMAIF_DL_INT_DLQ0_PITCNT_LEN,
+			  hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMSR0);
+	else
+		iowrite32(DPMAIF_DL_INT_DLQ1_PITCNT_LEN,
+			  hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMSR0);
+}
+
+void t7xx_dpmaif_dlq_unmask_pitcnt_len_err_intr(struct dpmaif_hw_info *hw_info,
+						unsigned char qno)
+{
+	if (qno == DPF_RX_QNO0)
+		iowrite32(DPMAIF_DL_INT_DLQ0_PITCNT_LEN,
+			  hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMCR0);
+	else
+		iowrite32(DPMAIF_DL_INT_DLQ1_PITCNT_LEN,
+			  hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMCR0);
+}
+
+void t7xx_dpmaif_ul_clr_all_intr(struct dpmaif_hw_info *hw_info)
+{
+	iowrite32(DPMAIF_AP_ALL_L2TISAR0_MASK, hw_info->pcie_base + DPMAIF_AP_L2TISAR0);
+}
+
+void t7xx_dpmaif_dl_clr_all_intr(struct dpmaif_hw_info *hw_info)
+{
+	iowrite32(DPMAIF_AP_APDL_ALL_L2TISAR0_MASK, hw_info->pcie_base + DPMAIF_AP_APDL_L2TISAR0);
+}
+
+/* The para->intr_cnt counter is set to zero before this function is called.
+ * It does not check for overflow as there is no risk of overflowing intr_types or intr_queues.
+ */
+static void t7xx_dpmaif_hw_check_tx_interrupt(struct dpmaif_ctrl *dpmaif_ctrl,
+					      unsigned int l2_txisar0,
+					      struct dpmaif_hw_intr_st_para *para)
+{
+	unsigned long value;
+
+	value = FIELD_GET(DP_UL_INT_QDONE_MSK, l2_txisar0);
+	if (value) {
+		unsigned int index;
+
+		para->intr_types[para->intr_cnt] = DPF_INTR_UL_DONE;
+		para->intr_queues[para->intr_cnt] = value;
+		para->intr_cnt++;
+
+		for_each_set_bit(index, &value, DPMAIF_TXQ_NUM)
+			t7xx_dpmaif_mask_ulq_interrupt(dpmaif_ctrl, index);
+	}
+
+	value = FIELD_GET(DP_UL_INT_EMPTY_MSK, l2_txisar0);
+	if (value) {
+		para->intr_types[para->intr_cnt] = DPF_INTR_UL_DRB_EMPTY;
+		para->intr_queues[para->intr_cnt] = value;
+		para->intr_cnt++;
+	}
+
+	value = FIELD_GET(DP_UL_INT_MD_NOTREADY_MSK, l2_txisar0);
+	if (value) {
+		para->intr_types[para->intr_cnt] = DPF_INTR_UL_MD_NOTREADY;
+		para->intr_queues[para->intr_cnt] = value;
+		para->intr_cnt++;
+	}
+
+	value = FIELD_GET(DP_UL_INT_MD_PWR_NOTREADY_MSK, l2_txisar0);
+	if (value) {
+		para->intr_types[para->intr_cnt] = DPF_INTR_UL_MD_PWR_NOTREADY;
+		para->intr_queues[para->intr_cnt] = value;
+		para->intr_cnt++;
+	}
+
+	value = FIELD_GET(DP_UL_INT_ERR_MSK, l2_txisar0);
+	if (value) {
+		para->intr_types[para->intr_cnt] = DPF_INTR_UL_LEN_ERR;
+		para->intr_queues[para->intr_cnt] = value;
+		para->intr_cnt++;
+	}
+}
+
+/* The para->intr_cnt counter is set to zero before this function is called.
+ * It does not check for overflow as there is no risk of overflowing intr_types or intr_queues.
+ */
+static void t7xx_dpmaif_hw_check_rx_interrupt(struct dpmaif_ctrl *dpmaif_ctrl,
+					      unsigned int *pl2_rxisar0,
+					      struct dpmaif_hw_intr_st_para *para, int qno)
+{
+	struct dpmaif_hw_info *hw_info = &dpmaif_ctrl->hif_hw_info;
+	unsigned int l2_rxisar0 = *pl2_rxisar0;
+	unsigned int value;
+
+	if (qno == DPF_RX_QNO_DFT) {
+		value = l2_rxisar0 & DP_DL_INT_SKB_LEN_ERR;
+		if (value) {
+			para->intr_types[para->intr_cnt] = DPF_INTR_DL_SKB_LEN_ERR;
+			para->intr_queues[para->intr_cnt] = DPF_RX_QNO_DFT;
+			para->intr_cnt++;
+		}
+
+		value = l2_rxisar0 & DP_DL_INT_BATCNT_LEN_ERR;
+		if (value) {
+			para->intr_types[para->intr_cnt] = DPF_INTR_DL_BATCNT_LEN_ERR;
+			para->intr_queues[para->intr_cnt] = DPF_RX_QNO_DFT;
+			para->intr_cnt++;
+			t7xx_dpmaif_dl_mask_batcnt_len_err_intr(hw_info);
+		}
+
+		value = l2_rxisar0 & DP_DL_INT_PITCNT_LEN_ERR;
+		if (value) {
+			para->intr_types[para->intr_cnt] = DPF_INTR_DL_PITCNT_LEN_ERR;
+			para->intr_queues[para->intr_cnt] = DPF_RX_QNO_DFT;
+			para->intr_cnt++;
+			t7xx_dpmaif_dl_mask_pitcnt_len_err_intr(hw_info);
+		}
+
+		value = l2_rxisar0 & DP_DL_INT_PKT_EMPTY_MSK;
+		if (value) {
+			para->intr_types[para->intr_cnt] = DPF_INTR_DL_PKT_EMPTY_SET;
+			para->intr_queues[para->intr_cnt] = DPF_RX_QNO_DFT;
+			para->intr_cnt++;
+		}
+
+		value = l2_rxisar0 & DP_DL_INT_FRG_EMPTY_MSK;
+		if (value) {
+			para->intr_types[para->intr_cnt] = DPF_INTR_DL_FRG_EMPTY_SET;
+			para->intr_queues[para->intr_cnt] = DPF_RX_QNO_DFT;
+			para->intr_cnt++;
+		}
+
+		value = l2_rxisar0 & DP_DL_INT_MTU_ERR_MSK;
+		if (value) {
+			para->intr_types[para->intr_cnt] = DPF_INTR_DL_MTU_ERR;
+			para->intr_queues[para->intr_cnt] = DPF_RX_QNO_DFT;
+			para->intr_cnt++;
+		}
+
+		value = l2_rxisar0 & DP_DL_INT_FRG_LENERR_MSK;
+		if (value) {
+			para->intr_types[para->intr_cnt] = DPF_INTR_DL_FRGCNT_LEN_ERR;
+			para->intr_queues[para->intr_cnt] = DPF_RX_QNO_DFT;
+			para->intr_cnt++;
+		}
+
+		value = l2_rxisar0 & DP_DL_INT_Q0_PITCNT_LEN_ERR;
+		if (value) {
+			para->intr_types[para->intr_cnt] = DPF_INTR_DL_Q0_PITCNT_LEN_ERR;
+			para->intr_queues[para->intr_cnt] = BIT(qno);
+			para->intr_cnt++;
+			t7xx_dpmaif_dlq_mask_rx_pitcnt_len_err_intr(hw_info, qno);
+		}
+
+		value = l2_rxisar0 & DP_DL_INT_HPC_ENT_TYPE_ERR;
+		if (value) {
+			para->intr_types[para->intr_cnt] = DPF_INTR_DL_HPC_ENT_TYPE_ERR;
+			para->intr_queues[para->intr_cnt] = DPF_RX_QNO_DFT;
+			para->intr_cnt++;
+		}
+
+		value = l2_rxisar0 & DP_DL_INT_Q0_DONE;
+		if (value) {
+			/* Mask RX done interrupt immediately after it occurs */
+			if (!t7xx_mask_dlq_interrupt(dpmaif_ctrl, qno)) {
+				para->intr_types[para->intr_cnt] = DPF_INTR_DL_Q0_DONE;
+				para->intr_queues[para->intr_cnt] = BIT(qno);
+				para->intr_cnt++;
+			} else {
+				/* Unable to clear the interrupt, try again on the next one
+				 * device entered low power mode or suffer exception
+				 */
+				*pl2_rxisar0 = l2_rxisar0 & ~DP_DL_INT_Q0_DONE;
+			}
+		}
+	} else {
+		value = l2_rxisar0 & DP_DL_INT_Q1_PITCNT_LEN_ERR;
+		if (value) {
+			para->intr_types[para->intr_cnt] = DPF_INTR_DL_Q1_PITCNT_LEN_ERR;
+			para->intr_queues[para->intr_cnt] = BIT(qno);
+			para->intr_cnt++;
+			t7xx_dpmaif_dlq_mask_rx_pitcnt_len_err_intr(hw_info, qno);
+		}
+
+		value = l2_rxisar0 & DP_DL_INT_Q1_DONE;
+		if (value) {
+			if (!t7xx_mask_dlq_interrupt(dpmaif_ctrl, qno)) {
+				para->intr_types[para->intr_cnt] = DPF_INTR_DL_Q1_DONE;
+				para->intr_queues[para->intr_cnt] = BIT(qno);
+				para->intr_cnt++;
+			} else {
+				*pl2_rxisar0 = l2_rxisar0 & ~DP_DL_INT_Q1_DONE;
+			}
+		}
+	}
+}
+
+/**
+ * t7xx_dpmaif_hw_get_intr_cnt() - Reads interrupt status and count from HW.
+ * @dpmaif_ctrl: Pointer to struct dpmaif_ctrl.
+ * @para: Pointer to struct dpmaif_hw_intr_st_para.
+ * @qno: Queue number.
+ *
+ * Reads RX/TX interrupt status from HW and clears UL/DL status as needed.
+ *
+ * Return: Interrupt count.
+ */
+int t7xx_dpmaif_hw_get_intr_cnt(struct dpmaif_ctrl *dpmaif_ctrl,
+				struct dpmaif_hw_intr_st_para *para, int qno)
+{
+	struct dpmaif_hw_info *hw_info = &dpmaif_ctrl->hif_hw_info;
+	u32 rx_intr_status, tx_intr_status = 0;
+	u32 rx_intr_qdone, tx_intr_qdone = 0;
+
+	rx_intr_status = ioread32(hw_info->pcie_base + DPMAIF_AP_APDL_L2TISAR0);
+	rx_intr_qdone = ioread32(hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMR0);
+
+	/* TX interrupt status */
+	if (qno == DPF_RX_QNO_DFT) {
+		/* All ULQ and DLQ0 interrupts use the same source no need to check ULQ interrupts
+		 * when a DLQ1 interrupt has occurred.
+		 */
+		tx_intr_status = ioread32(hw_info->pcie_base + DPMAIF_AP_L2TISAR0);
+		tx_intr_qdone = ioread32(hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMR0);
+	}
+
+	t7xx_dpmaif_clr_ip_busy_sts(hw_info);
+
+	if (qno == DPF_RX_QNO_DFT) {
+		/* Do not schedule bottom half again or clear UL interrupt status when we
+		 * have already masked it.
+		 */
+		tx_intr_status &= ~tx_intr_qdone;
+		if (tx_intr_status) {
+			t7xx_dpmaif_hw_check_tx_interrupt(dpmaif_ctrl, tx_intr_status, para);
+			/* Clear interrupt status */
+			iowrite32(tx_intr_status, hw_info->pcie_base + DPMAIF_AP_L2TISAR0);
+		}
+	}
+
+	if (rx_intr_status) {
+		if (qno == DPF_RX_QNO0) {
+			rx_intr_status &= DP_DL_Q0_STATUS_MASK;
+			if (rx_intr_qdone & DPMAIF_DL_INT_DLQ0_QDONE)
+				/* Do not schedule bottom half again or clear DL
+				 * queue done interrupt status when we have already masked it.
+				 */
+				rx_intr_status &= ~DP_DL_INT_Q0_DONE;
+		} else {
+			rx_intr_status &= DP_DL_Q1_STATUS_MASK;
+			if (rx_intr_qdone & DPMAIF_DL_INT_DLQ1_QDONE)
+				rx_intr_status &= ~DP_DL_INT_Q1_DONE;
+		}
+
+		if (rx_intr_status) {
+			t7xx_dpmaif_hw_check_rx_interrupt(dpmaif_ctrl, &rx_intr_status, para, qno);
+			rx_intr_status |= DP_DL_INT_BATCNT_LEN_ERR;
+			/* Clear interrupt status */
+			iowrite32(rx_intr_status, hw_info->pcie_base + DPMAIF_AP_APDL_L2TISAR0);
+		}
+	}
+
+	return para->intr_cnt;
+}
+
+static int t7xx_dpmaif_sram_init(struct dpmaif_hw_info *hw_info)
+{
+	u32 value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_AP_MEM_CLR);
+	value |= DPMAIF_MEM_CLR;
+	iowrite32(value, hw_info->pcie_base + DPMAIF_AP_MEM_CLR);
+
+	return readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_AP_MEM_CLR,
+					value, !(value & DPMAIF_MEM_CLR), 0,
+					DPMAIF_CHECK_INIT_TIMEOUT_US);
+}
+
+static void t7xx_dpmaif_hw_reset(struct dpmaif_hw_info *hw_info)
+{
+	iowrite32(DPMAIF_AP_AO_RST_BIT, hw_info->pcie_base + DPMAIF_AP_AO_RGU_ASSERT);
+	udelay(2);
+	iowrite32(DPMAIF_AP_RST_BIT, hw_info->pcie_base + DPMAIF_AP_RGU_ASSERT);
+	udelay(2);
+	iowrite32(DPMAIF_AP_AO_RST_BIT, hw_info->pcie_base + DPMAIF_AP_AO_RGU_DEASSERT);
+	udelay(2);
+	iowrite32(DPMAIF_AP_RST_BIT, hw_info->pcie_base + DPMAIF_AP_RGU_DEASSERT);
+	udelay(2);
+}
+
+static int t7xx_dpmaif_hw_config(struct dpmaif_hw_info *hw_info)
+{
+	u32 ap_port_mode;
+	int ret;
+
+	t7xx_dpmaif_hw_reset(hw_info);
+
+	ret = t7xx_dpmaif_sram_init(hw_info);
+	if (ret)
+		return ret;
+
+	ap_port_mode = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_THRES);
+	ap_port_mode |= DPMAIF_PORT_MODE_PCIE;
+	iowrite32(ap_port_mode, hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_THRES);
+	iowrite32(DPMAIF_CG_EN, hw_info->pcie_base + DPMAIF_AP_CG_EN);
+	return 0;
+}
+
+static inline void t7xx_dpmaif_pcie_dpmaif_sign(struct dpmaif_hw_info *hw_info)
+{
+	iowrite32(DPMAIF_PCIE_MODE_SET_VALUE, hw_info->pcie_base + DPMAIF_UL_RESERVE_AO_RW);
+}
+
+static void t7xx_dpmaif_dl_performance(struct dpmaif_hw_info *hw_info)
+{
+	u32 enable_bat_cache, enable_pit_burst;
+
+	enable_bat_cache = ioread32(hw_info->pcie_base + DPMAIF_DL_BAT_INIT_CON1);
+	enable_bat_cache |= DPMAIF_DL_BAT_CACHE_PRI;
+	iowrite32(enable_bat_cache, hw_info->pcie_base + DPMAIF_DL_BAT_INIT_CON1);
+
+	enable_pit_burst = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_THRES);
+	enable_pit_burst |= DPMAIF_DL_BURST_PIT_EN;
+	iowrite32(enable_pit_burst, hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_THRES);
+}
+
+static void t7xx_dpmaif_common_hw_init(struct dpmaif_hw_info *hw_info)
+{
+	t7xx_dpmaif_pcie_dpmaif_sign(hw_info);
+	t7xx_dpmaif_dl_performance(hw_info);
+}
+
+ /* DPMAIF DL DLQ part HW setting */
+
+static inline void t7xx_dpmaif_hw_hpc_cntl_set(struct dpmaif_hw_info *hw_info)
+{
+	unsigned int value;
+
+	value = DPMAIF_HPC_DLQ_PATH_MODE | DPMAIF_HPC_ADD_MODE_DF << 2;
+	value |= DPMAIF_HASH_PRIME_DF << 4;
+	value |= DPMAIF_HPC_TOTAL_NUM << 8;
+	iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_HPC_CNTL);
+}
+
+static inline void t7xx_dpmaif_hw_agg_cfg_set(struct dpmaif_hw_info *hw_info)
+{
+	unsigned int value;
+
+	value = DPMAIF_AGG_MAX_LEN_DF | DPMAIF_AGG_TBL_ENT_NUM_DF << 16;
+	iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_DLQ_AGG_CFG);
+}
+
+static inline void t7xx_dpmaif_hw_hash_bit_choose_set(struct dpmaif_hw_info *hw_info)
+{
+	iowrite32(DPMAIF_DLQ_HASH_BIT_CHOOSE_DF,
+		  hw_info->pcie_base + DPMAIF_AO_DL_DLQPIT_INIT_CON5);
+}
+
+static inline void t7xx_dpmaif_hw_mid_pit_timeout_thres_set(struct dpmaif_hw_info *hw_info)
+{
+	iowrite32(DPMAIF_MID_TIMEOUT_THRES_DF, hw_info->pcie_base + DPMAIF_AO_DL_DLQPIT_TIMEOUT0);
+}
+
+static void t7xx_dpmaif_hw_dlq_timeout_thres_set(struct dpmaif_hw_info *hw_info)
+{
+	unsigned int value, i;
+
+	/* Each register holds two DLQ threshold timeout values */
+	for (i = 0; i < DPMAIF_HPC_MAX_TOTAL_NUM / 2; i++) {
+		value = FIELD_PREP(DPMAIF_DLQ_LOW_TIMEOUT_THRES_MKS, DPMAIF_DLQ_TIMEOUT_THRES_DF);
+		value |= FIELD_PREP(DPMAIF_DLQ_HIGH_TIMEOUT_THRES_MSK,
+				    DPMAIF_DLQ_TIMEOUT_THRES_DF);
+		iowrite32(value,
+			  hw_info->pcie_base + DPMAIF_AO_DL_DLQPIT_TIMEOUT1 + sizeof(u32) * i);
+	}
+}
+
+static inline void t7xx_dpmaif_hw_dlq_start_prs_thres_set(struct dpmaif_hw_info *hw_info)
+{
+	iowrite32(DPMAIF_DLQ_PRS_THRES_DF, hw_info->pcie_base + DPMAIF_AO_DL_DLQPIT_TRIG_THRES);
+}
+
+static void t7xx_dpmaif_dl_dlq_hpc_hw_init(struct dpmaif_hw_info *hw_info)
+{
+	t7xx_dpmaif_hw_hpc_cntl_set(hw_info);
+	t7xx_dpmaif_hw_agg_cfg_set(hw_info);
+	t7xx_dpmaif_hw_hash_bit_choose_set(hw_info);
+	t7xx_dpmaif_hw_mid_pit_timeout_thres_set(hw_info);
+	t7xx_dpmaif_hw_dlq_timeout_thres_set(hw_info);
+	t7xx_dpmaif_hw_dlq_start_prs_thres_set(hw_info);
+}
+
+static int t7xx_dpmaif_dl_bat_init_done(struct dpmaif_ctrl *dpmaif_ctrl,
+					unsigned char q_num, bool frg_en)
+{
+	struct dpmaif_hw_info *hw_info = &dpmaif_ctrl->hif_hw_info;
+	u32 value, dl_bat_init = 0;
+	int ret;
+
+	if (frg_en)
+		dl_bat_init = DPMAIF_DL_BAT_FRG_INIT;
+
+	dl_bat_init |= DPMAIF_DL_BAT_INIT_ALLSET;
+	dl_bat_init |= DPMAIF_DL_BAT_INIT_EN;
+
+	ret = readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_DL_BAT_INIT,
+					value, !(value & DPMAIF_DL_BAT_INIT_NOT_READY), 0,
+					DPMAIF_CHECK_INIT_TIMEOUT_US);
+	if (ret) {
+		dev_err(dpmaif_ctrl->dev, "Data plane modem DL BAT is not ready\n");
+		return ret;
+	}
+
+	iowrite32(dl_bat_init, hw_info->pcie_base + DPMAIF_DL_BAT_INIT);
+
+	ret = readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_DL_BAT_INIT,
+					value, !(value & DPMAIF_DL_BAT_INIT_NOT_READY), 0,
+					DPMAIF_CHECK_INIT_TIMEOUT_US);
+	if (ret)
+		dev_err(dpmaif_ctrl->dev, "Data plane modem DL BAT initialization failed\n");
+
+	return ret;
+}
+
+static void t7xx_dpmaif_dl_set_bat_base_addr(struct dpmaif_hw_info *hw_info,
+					     unsigned char q_num, dma_addr_t addr)
+{
+	iowrite32(lower_32_bits(addr), hw_info->pcie_base + DPMAIF_DL_BAT_INIT_CON0);
+	iowrite32(upper_32_bits(addr), hw_info->pcie_base + DPMAIF_DL_BAT_INIT_CON3);
+}
+
+static void t7xx_dpmaif_dl_set_bat_size(struct dpmaif_hw_info *hw_info,
+					unsigned char q_num, unsigned int size)
+{
+	unsigned int value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_DL_BAT_INIT_CON1);
+	value &= ~DPMAIF_BAT_SIZE_MSK;
+	value |= size & DPMAIF_BAT_SIZE_MSK;
+	iowrite32(value, hw_info->pcie_base + DPMAIF_DL_BAT_INIT_CON1);
+}
+
+static void t7xx_dpmaif_dl_bat_en(struct dpmaif_hw_info *hw_info, unsigned char q_num, bool enable)
+{
+	unsigned int value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_DL_BAT_INIT_CON1);
+
+	if (enable)
+		value |= DPMAIF_BAT_EN_MSK;
+	else
+		value &= ~DPMAIF_BAT_EN_MSK;
+
+	iowrite32(value, hw_info->pcie_base + DPMAIF_DL_BAT_INIT_CON1);
+}
+
+static void t7xx_dpmaif_dl_set_ao_bid_maxcnt(struct dpmaif_hw_info *hw_info,
+					     unsigned char q_num, unsigned int cnt)
+{
+	unsigned int value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON0);
+	value &= ~DPMAIF_BAT_BID_MAXCNT_MSK;
+	value |= FIELD_PREP(DPMAIF_BAT_BID_MAXCNT_MSK, cnt);
+	iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON0);
+}
+
+static inline void t7xx_dpmaif_dl_set_ao_mtu(struct dpmaif_hw_info *hw_info, unsigned int mtu_sz)
+{
+	iowrite32(mtu_sz, hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON1);
+}
+
+static void t7xx_dpmaif_dl_set_ao_pit_chknum(struct dpmaif_hw_info *hw_info, unsigned char q_num,
+					     unsigned int number)
+{
+	unsigned int value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON2);
+	value &= ~DPMAIF_PIT_CHK_NUM_MSK;
+	value |= FIELD_PREP(DPMAIF_PIT_CHK_NUM_MSK, number);
+	iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON2);
+}
+
+static void t7xx_dpmaif_dl_set_ao_remain_minsz(struct dpmaif_hw_info *hw_info, unsigned char q_num,
+					       size_t min_sz)
+{
+	unsigned int value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON0);
+	value &= ~DPMAIF_BAT_REMAIN_MINSZ_MSK;
+	value |= FIELD_PREP(DPMAIF_BAT_REMAIN_MINSZ_MSK, min_sz / DPMAIF_BAT_REMAIN_SZ_BASE);
+	iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON0);
+}
+
+static void t7xx_dpmaif_dl_set_ao_bat_bufsz(struct dpmaif_hw_info *hw_info,
+					    unsigned char q_num, size_t buf_sz)
+{
+	unsigned int value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON2);
+	value &= ~DPMAIF_BAT_BUF_SZ_MSK;
+	value |= FIELD_PREP(DPMAIF_BAT_BUF_SZ_MSK, buf_sz / DPMAIF_BAT_BUFFER_SZ_BASE);
+	iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON2);
+}
+
+static void t7xx_dpmaif_dl_set_ao_bat_rsv_length(struct dpmaif_hw_info *hw_info,
+						 unsigned char q_num, unsigned int length)
+{
+	unsigned int value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON2);
+	value &= ~DPMAIF_BAT_RSV_LEN_MSK;
+	value |= length & DPMAIF_BAT_RSV_LEN_MSK;
+	iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_PKTINFO_CON2);
+}
+
+static void t7xx_dpmaif_dl_set_pkt_alignment(struct dpmaif_hw_info *hw_info, unsigned char q_num,
+					     bool enable, unsigned int mode)
+{
+	unsigned int value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_THRES);
+	value &= ~DPMAIF_PKT_ALIGN_MSK;
+
+	if (enable) {
+		value |= DPMAIF_PKT_ALIGN_EN;
+		value |= FIELD_PREP(DPMAIF_PKT_ALIGN_MSK, mode);
+	}
+
+	iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_THRES);
+}
+
+static void t7xx_dpmaif_dl_set_pkt_checksum(struct dpmaif_hw_info *hw_info)
+{
+	unsigned int value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_THRES);
+	value |= DPMAIF_DL_PKT_CHECKSUM_EN;
+	iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_THRES);
+}
+
+static void t7xx_dpmaif_dl_set_ao_frg_check_thres(struct dpmaif_hw_info *hw_info,
+						  unsigned char q_num, unsigned int size)
+{
+	unsigned int value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_FRG_THRES);
+	value &= ~DPMAIF_FRG_CHECK_THRES_MSK;
+	value |= (size & DPMAIF_FRG_CHECK_THRES_MSK);
+	iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_FRG_THRES);
+}
+
+static void t7xx_dpmaif_dl_set_ao_frg_bufsz(struct dpmaif_hw_info *hw_info,
+					    unsigned char q_num, unsigned int buf_sz)
+{
+	unsigned int value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_FRG_THRES);
+	value &= ~DPMAIF_FRG_BUF_SZ_MSK;
+	value |= FIELD_PREP(DPMAIF_FRG_BUF_SZ_MSK, buf_sz / DPMAIF_FRG_BUFFER_SZ_BASE);
+	iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_FRG_THRES);
+}
+
+static void t7xx_dpmaif_dl_frg_ao_en(struct dpmaif_hw_info *hw_info, unsigned char q_num,
+				     bool enable)
+{
+	unsigned int value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_FRG_THRES);
+
+	if (enable)
+		value |= DPMAIF_FRG_EN_MSK;
+	else
+		value &= ~DPMAIF_FRG_EN_MSK;
+
+	iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_FRG_THRES);
+}
+
+static void t7xx_dpmaif_dl_set_ao_bat_check_thres(struct dpmaif_hw_info *hw_info,
+						  unsigned char q_num, unsigned int size)
+{
+	unsigned int value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_THRES);
+	value &= ~DPMAIF_BAT_CHECK_THRES_MSK;
+	value |= FIELD_PREP(DPMAIF_BAT_CHECK_THRES_MSK, size);
+	iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_RDY_CHK_THRES);
+}
+
+static void t7xx_dpmaif_dl_set_pit_seqnum(struct dpmaif_hw_info *hw_info,
+					  unsigned char q_num, unsigned int seq)
+{
+	unsigned int value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_PIT_SEQ_END);
+	value &= ~DPMAIF_DL_PIT_SEQ_MSK;
+	value |= seq & DPMAIF_DL_PIT_SEQ_MSK;
+	iowrite32(value, hw_info->pcie_base + DPMAIF_AO_DL_PIT_SEQ_END);
+}
+
+static void t7xx_dpmaif_dl_set_dlq_pit_base_addr(struct dpmaif_hw_info *hw_info,
+						 unsigned char q_num, dma_addr_t addr)
+{
+	iowrite32(lower_32_bits(addr), hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT_CON0);
+	iowrite32(upper_32_bits(addr), hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT_CON4);
+}
+
+static void t7xx_dpmaif_dl_set_dlq_pit_size(struct dpmaif_hw_info *hw_info,
+					    unsigned char q_num, unsigned int size)
+{
+	unsigned int value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT_CON1);
+	value &= ~DPMAIF_PIT_SIZE_MSK;
+	value |= size & DPMAIF_PIT_SIZE_MSK;
+	iowrite32(value, hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT_CON1);
+	iowrite32(0, hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT_CON2);
+	iowrite32(0, hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT_CON3);
+	iowrite32(0, hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT_CON5);
+	iowrite32(0, hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT_CON6);
+}
+
+static void t7xx_dpmaif_dl_dlq_pit_en(struct dpmaif_hw_info *hw_info, unsigned char q_num,
+				      bool enable)
+{
+	unsigned int value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT_CON3);
+
+	if (enable)
+		value |= DPMAIF_DLQPIT_EN_MSK;
+	else
+		value &= ~DPMAIF_DLQPIT_EN_MSK;
+
+	iowrite32(value, hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT_CON3);
+}
+
+static void t7xx_dpmaif_dl_dlq_pit_init_done(struct dpmaif_ctrl *dpmaif_ctrl,
+					     unsigned char q_num, unsigned int pit_idx)
+{
+	struct dpmaif_hw_info *hw_info = &dpmaif_ctrl->hif_hw_info;
+	unsigned int dl_pit_init;
+	int timeout;
+	u32 value;
+
+	dl_pit_init = DPMAIF_DL_PIT_INIT_ALLSET;
+	dl_pit_init |= (pit_idx << DPMAIF_DLQPIT_CHAN_OFS);
+	dl_pit_init |= DPMAIF_DL_PIT_INIT_EN;
+
+	timeout = readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT,
+					    value, !(value & DPMAIF_DL_PIT_INIT_NOT_READY),
+					    DPMAIF_CHECK_DELAY_US, DPMAIF_CHECK_INIT_TIMEOUT_US);
+	if (timeout) {
+		dev_err(dpmaif_ctrl->dev, "Data plane modem DL PIT is not ready\n");
+		return;
+	}
+
+	iowrite32(dl_pit_init, hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT);
+	timeout = readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_DL_DLQPIT_INIT,
+					    value, !(value & DPMAIF_DL_PIT_INIT_NOT_READY),
+					    DPMAIF_CHECK_DELAY_US, DPMAIF_CHECK_INIT_TIMEOUT_US);
+	if (timeout)
+		dev_err(dpmaif_ctrl->dev, "Data plane modem DL PIT initialization failed\n");
+}
+
+static void t7xx_dpmaif_config_dlq_pit_hw(struct dpmaif_ctrl *dpmaif_ctrl, unsigned char q_num,
+					  struct dpmaif_dl *dl_que)
+{
+	struct dpmaif_hw_info *hw_info = &dpmaif_ctrl->hif_hw_info;
+	unsigned int pit_idx = q_num;
+
+	t7xx_dpmaif_dl_set_dlq_pit_base_addr(hw_info, q_num, dl_que->pit_base);
+	t7xx_dpmaif_dl_set_dlq_pit_size(hw_info, q_num, dl_que->pit_size_cnt);
+	t7xx_dpmaif_dl_dlq_pit_en(hw_info, q_num, true);
+	t7xx_dpmaif_dl_dlq_pit_init_done(dpmaif_ctrl, q_num, pit_idx);
+}
+
+static void t7xx_dpmaif_config_all_dlq_hw(struct dpmaif_ctrl *dpmaif_ctrl)
+{
+	struct dpmaif_hw_info *hw_info = &dpmaif_ctrl->hif_hw_info;
+	int i;
+
+	for (i = 0; i < DPMAIF_RXQ_NUM; i++)
+		t7xx_dpmaif_config_dlq_pit_hw(dpmaif_ctrl, i, &hw_info->dl_que[i]);
+}
+
+static void t7xx_dpmaif_dl_all_queue_en(struct dpmaif_ctrl *dpmaif_ctrl, bool enable)
+{
+	struct dpmaif_hw_info *hw_info = &dpmaif_ctrl->hif_hw_info;
+	u32 dl_bat_init, value;
+	int timeout;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_DL_BAT_INIT_CON1);
+
+	if (enable)
+		value |= DPMAIF_BAT_EN_MSK;
+	else
+		value &= ~DPMAIF_BAT_EN_MSK;
+
+	iowrite32(value, hw_info->pcie_base + DPMAIF_DL_BAT_INIT_CON1);
+	dl_bat_init = DPMAIF_DL_BAT_INIT_ONLY_ENABLE_BIT;
+	dl_bat_init |= DPMAIF_DL_BAT_INIT_EN;
+
+	timeout = readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_DL_BAT_INIT,
+					    value, !(value & DPMAIF_DL_BAT_INIT_NOT_READY),
+					    0, DPMAIF_CHECK_TIMEOUT_US);
+	if (timeout)
+		dev_err(dpmaif_ctrl->dev, "Timeout updating BAT setting to HW\n");
+
+	iowrite32(dl_bat_init, hw_info->pcie_base + DPMAIF_DL_BAT_INIT);
+	timeout = readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_DL_BAT_INIT,
+					    value, !(value & DPMAIF_DL_BAT_INIT_NOT_READY),
+					    0, DPMAIF_CHECK_TIMEOUT_US);
+	if (timeout)
+		dev_err(dpmaif_ctrl->dev, "Data plane modem DL BAT is not ready\n");
+}
+
+static int t7xx_dpmaif_config_dlq_hw(struct dpmaif_ctrl *dpmaif_ctrl)
+{
+	struct dpmaif_hw_info *hw_info = &dpmaif_ctrl->hif_hw_info;
+	struct dpmaif_dl_hwq *dl_hw;
+	struct dpmaif_dl *dl_que;
+	unsigned int queue = 0; /* All queues share one BAT/frag BAT table */
+	int ret;
+
+	t7xx_dpmaif_dl_dlq_hpc_hw_init(hw_info);
+	dl_hw = &hw_info->dl_que_hw[queue];
+
+	dl_que = &hw_info->dl_que[queue];
+	if (!dl_que->que_started)
+		return -EBUSY;
+
+	t7xx_dpmaif_dl_set_ao_remain_minsz(hw_info, queue, dl_hw->bat_remain_size);
+	t7xx_dpmaif_dl_set_ao_bat_bufsz(hw_info, queue, dl_hw->bat_pkt_bufsz);
+	t7xx_dpmaif_dl_set_ao_frg_bufsz(hw_info, queue, dl_hw->frg_pkt_bufsz);
+	t7xx_dpmaif_dl_set_ao_bat_rsv_length(hw_info, queue, dl_hw->bat_rsv_length);
+	t7xx_dpmaif_dl_set_ao_bid_maxcnt(hw_info, queue, dl_hw->pkt_bid_max_cnt);
+
+	if (dl_hw->pkt_alignment == 64)
+		t7xx_dpmaif_dl_set_pkt_alignment(hw_info, queue, true, DPMAIF_PKT_ALIGN64_MODE);
+	else if (dl_hw->pkt_alignment == 128)
+		t7xx_dpmaif_dl_set_pkt_alignment(hw_info, queue, true, DPMAIF_PKT_ALIGN128_MODE);
+	else
+		t7xx_dpmaif_dl_set_pkt_alignment(hw_info, queue, false, 0);
+
+	t7xx_dpmaif_dl_set_pit_seqnum(hw_info, queue, DPMAIF_DL_PIT_SEQ_VALUE);
+	t7xx_dpmaif_dl_set_ao_mtu(hw_info, dl_hw->mtu_size);
+	t7xx_dpmaif_dl_set_ao_pit_chknum(hw_info, queue, dl_hw->chk_pit_num);
+	t7xx_dpmaif_dl_set_ao_bat_check_thres(hw_info, queue, dl_hw->chk_bat_num);
+	t7xx_dpmaif_dl_set_ao_frg_check_thres(hw_info, queue, dl_hw->chk_frg_num);
+	t7xx_dpmaif_dl_frg_ao_en(hw_info, queue, true);
+
+	t7xx_dpmaif_dl_set_bat_base_addr(hw_info, queue, dl_que->frg_base);
+	t7xx_dpmaif_dl_set_bat_size(hw_info, queue, dl_que->frg_size_cnt);
+	t7xx_dpmaif_dl_bat_en(hw_info, queue, true);
+
+	ret = t7xx_dpmaif_dl_bat_init_done(dpmaif_ctrl, queue, true);
+	if (ret)
+		return ret;
+
+	t7xx_dpmaif_dl_set_bat_base_addr(hw_info, queue, dl_que->bat_base);
+	t7xx_dpmaif_dl_set_bat_size(hw_info, queue, dl_que->bat_size_cnt);
+	t7xx_dpmaif_dl_bat_en(hw_info, queue, false);
+
+	ret = t7xx_dpmaif_dl_bat_init_done(dpmaif_ctrl, queue, false);
+	if (ret)
+		return ret;
+
+	/* Init PIT (two PIT table) */
+	t7xx_dpmaif_config_all_dlq_hw(dpmaif_ctrl);
+	t7xx_dpmaif_dl_all_queue_en(dpmaif_ctrl, true);
+	t7xx_dpmaif_dl_set_pkt_checksum(hw_info);
+	return 0;
+}
+
+static void t7xx_dpmaif_ul_update_drb_size(struct dpmaif_hw_info *hw_info,
+					   unsigned char q_num, unsigned int size)
+{
+	unsigned int value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_UL_DRBSIZE_ADDRH_n(q_num));
+	value &= ~DPMAIF_DRB_SIZE_MSK;
+	value |= size & DPMAIF_DRB_SIZE_MSK;
+	iowrite32(value, hw_info->pcie_base + DPMAIF_UL_DRBSIZE_ADDRH_n(q_num));
+}
+
+static void t7xx_dpmaif_ul_update_drb_base_addr(struct dpmaif_hw_info *hw_info,
+						unsigned char q_num, dma_addr_t addr)
+{
+	iowrite32(lower_32_bits(addr), hw_info->pcie_base + DPMAIF_ULQSAR_n(q_num));
+	iowrite32(upper_32_bits(addr), hw_info->pcie_base + DPMAIF_UL_DRB_ADDRH_n(q_num));
+}
+
+static void t7xx_dpmaif_ul_rdy_en(struct dpmaif_hw_info *hw_info,
+				  unsigned char q_num, bool ready)
+{
+	u32 value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_AO_UL_CHNL_ARB0);
+
+	if (ready)
+		value |= BIT(q_num);
+	else
+		value &= ~BIT(q_num);
+
+	iowrite32(value, hw_info->pcie_base + DPMAIF_AO_UL_CHNL_ARB0);
+}
+
+static void t7xx_dpmaif_ul_arb_en(struct dpmaif_hw_info *hw_info,
+				  unsigned char q_num, bool enable)
+{
+	u32 value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_AO_UL_CHNL_ARB0);
+
+	if (enable)
+		value |= BIT(q_num + 8);
+	else
+		value &= ~BIT(q_num + 8);
+
+	iowrite32(value, hw_info->pcie_base + DPMAIF_AO_UL_CHNL_ARB0);
+}
+
+static void t7xx_dpmaif_config_ulq_hw(struct dpmaif_hw_info *hw_info)
+{
+	struct dpmaif_ul *ul_que;
+	int i;
+
+	for (i = 0; i < DPMAIF_TXQ_NUM; i++) {
+		ul_que = &hw_info->ul_que[i];
+		if (ul_que->que_started) {
+			t7xx_dpmaif_ul_update_drb_size(hw_info, i, ul_que->drb_size_cnt *
+						       DPMAIF_UL_DRB_ENTRY_WORD);
+			t7xx_dpmaif_ul_update_drb_base_addr(hw_info, i, ul_que->drb_base);
+			t7xx_dpmaif_ul_rdy_en(hw_info, i, true);
+			t7xx_dpmaif_ul_arb_en(hw_info, i, true);
+		} else {
+			t7xx_dpmaif_ul_arb_en(hw_info, i, false);
+		}
+	}
+}
+
+static int t7xx_dpmaif_hw_init_done(struct dpmaif_hw_info *hw_info)
+{
+	u32 ap_cfg;
+	int ret;
+
+	ap_cfg = ioread32(hw_info->pcie_base + DPMAIF_AP_OVERWRITE_CFG);
+	ap_cfg |= DPMAIF_SRAM_SYNC;
+	iowrite32(ap_cfg, hw_info->pcie_base + DPMAIF_AP_OVERWRITE_CFG);
+
+	ret = readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_AP_OVERWRITE_CFG,
+					ap_cfg, !(ap_cfg & DPMAIF_SRAM_SYNC),
+					0, DPMAIF_CHECK_TIMEOUT_US);
+	if (ret)
+		return ret;
+
+	iowrite32(DPMAIF_UL_INIT_DONE, hw_info->pcie_base + DPMAIF_AO_UL_INIT_SET);
+	iowrite32(DPMAIF_DL_INIT_DONE, hw_info->pcie_base + DPMAIF_AO_DL_INIT_SET);
+	return 0;
+}
+
+static int t7xx_dpmaif_config_que_hw(struct dpmaif_ctrl *dpmaif_ctrl)
+{
+	struct dpmaif_hw_info *hw_info = &dpmaif_ctrl->hif_hw_info;
+	int ret;
+
+	t7xx_dpmaif_common_hw_init(hw_info);
+
+	ret = t7xx_dpmaif_config_dlq_hw(dpmaif_ctrl);
+	if (ret)
+		return ret;
+
+	t7xx_dpmaif_config_ulq_hw(hw_info);
+	return t7xx_dpmaif_hw_init_done(hw_info);
+}
+
+static inline bool t7xx_dpmaif_dl_idle_check(struct dpmaif_hw_info *hw_info)
+{
+	u32 dpmaif_dl_is_busy = ioread32(hw_info->pcie_base + DPMAIF_DL_CHK_BUSY);
+
+	return !(dpmaif_dl_is_busy & DPMAIF_DL_IDLE_STS);
+}
+
+static void t7xx_dpmaif_ul_all_queue_en(struct dpmaif_hw_info *hw_info, bool enable)
+{
+	u32 ul_arb_en = ioread32(hw_info->pcie_base + DPMAIF_AO_UL_CHNL_ARB0);
+
+	if (enable)
+		ul_arb_en |= DPMAIF_UL_ALL_QUE_ARB_EN;
+	else
+		ul_arb_en &= ~DPMAIF_UL_ALL_QUE_ARB_EN;
+
+	iowrite32(ul_arb_en, hw_info->pcie_base + DPMAIF_AO_UL_CHNL_ARB0);
+}
+
+static inline bool t7xx_dpmaif_ul_idle_check(struct dpmaif_hw_info *hw_info)
+{
+	u32 dpmaif_ul_is_busy = ioread32(hw_info->pcie_base + DPMAIF_UL_CHK_BUSY);
+
+	return !(dpmaif_ul_is_busy & DPMAIF_UL_IDLE_STS);
+}
+
+ /* DPMAIF UL Part HW setting */
+
+int t7xx_dpmaif_ul_update_hw_drb_cnt(struct dpmaif_ctrl *dpmaif_ctrl, unsigned char q_num,
+				     unsigned int drb_entry_cnt)
+{
+	struct dpmaif_hw_info *hw_info = &dpmaif_ctrl->hif_hw_info;
+	u32 ul_update, value;
+	int ret;
+
+	ul_update = drb_entry_cnt & DPMAIF_UL_ADD_COUNT_MASK;
+	ul_update |= DPMAIF_UL_ADD_UPDATE;
+
+	ret = readx_poll_timeout_atomic(ioread32,
+					hw_info->pcie_base + DPMAIF_ULQ_ADD_DESC_CH_n(q_num),
+					value, !(value & DPMAIF_UL_ADD_NOT_READY),
+					     0, DPMAIF_CHECK_TIMEOUT_US);
+	if (ret) {
+		dev_err(dpmaif_ctrl->dev, "UL add is not ready\n");
+		return ret;
+	}
+
+	iowrite32(ul_update, hw_info->pcie_base + DPMAIF_ULQ_ADD_DESC_CH_n(q_num));
+
+	ret = readx_poll_timeout_atomic(ioread32,
+					hw_info->pcie_base + DPMAIF_ULQ_ADD_DESC_CH_n(q_num),
+					value, !(value & DPMAIF_UL_ADD_NOT_READY),
+					0, DPMAIF_CHECK_TIMEOUT_US);
+	if (ret) {
+		dev_err(dpmaif_ctrl->dev, "Timeout updating UL add\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+unsigned int t7xx_dpmaif_ul_get_ridx(struct dpmaif_hw_info *hw_info, unsigned char q_num)
+{
+	unsigned int value = ioread32(hw_info->pcie_base + DPMAIF_ULQ_STA0_n(q_num));
+
+	return value >> DPMAIF_UL_DRB_RIDX_OFFSET;
+}
+
+int t7xx_dpmaif_dlq_add_pit_remain_cnt(struct dpmaif_ctrl *dpmaif_ctrl, unsigned int dlq_pit_idx,
+				       unsigned int pit_remain_cnt)
+{
+	struct dpmaif_hw_info *hw_info = &dpmaif_ctrl->hif_hw_info;
+	u32 dl_update, value;
+	int ret;
+
+	dl_update = pit_remain_cnt & DPMAIF_PIT_REM_CNT_MSK;
+	dl_update |= DPMAIF_DL_ADD_UPDATE | (dlq_pit_idx << DPMAIF_ADD_DLQ_PIT_CHAN_OFS);
+
+	ret = readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_DL_DLQPIT_ADD,
+					value, !(value & DPMAIF_DL_ADD_NOT_READY),
+					0, DPMAIF_CHECK_TIMEOUT_US);
+	if (ret) {
+		dev_err(dpmaif_ctrl->dev, "Data plane modem is not ready to add dlq\n");
+		return ret;
+	}
+
+	iowrite32(dl_update, hw_info->pcie_base + DPMAIF_DL_DLQPIT_ADD);
+
+	ret = readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_DL_DLQPIT_ADD,
+					value, !(value & DPMAIF_DL_ADD_NOT_READY),
+					0, DPMAIF_CHECK_TIMEOUT_US);
+	if (ret) {
+		dev_err(dpmaif_ctrl->dev, "Data plane modem add dlq failed\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+unsigned int t7xx_dpmaif_dl_dlq_pit_get_wridx(struct dpmaif_hw_info *hw_info,
+					      unsigned int dlq_pit_idx)
+{
+	u32 value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_DLQ_WRIDX +
+			 dlq_pit_idx * DLQ_PIT_IDX_SIZE);
+	return value & DPMAIF_DL_PIT_WRIDX_MSK;
+}
+
+static bool t7xx_dl_add_timedout(struct dpmaif_hw_info *hw_info)
+{
+	u32 value;
+	int ret;
+
+	ret = readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_DL_BAT_ADD,
+					value, !(value & DPMAIF_DL_ADD_NOT_READY),
+					0, DPMAIF_CHECK_TIMEOUT_US);
+	return !!ret;
+}
+
+int t7xx_dpmaif_dl_snd_hw_bat_cnt(struct dpmaif_ctrl *dpmaif_ctrl, unsigned int bat_entry_cnt)
+{
+	struct dpmaif_hw_info *hw_info = &dpmaif_ctrl->hif_hw_info;
+	unsigned int value;
+
+	if (t7xx_dl_add_timedout(hw_info)) {
+		dev_err(dpmaif_ctrl->dev, "DL add BAT not ready\n");
+		return -EBUSY;
+	}
+
+	value = bat_entry_cnt & DPMAIF_DL_ADD_COUNT_MASK;
+	value |= DPMAIF_DL_ADD_UPDATE;
+	iowrite32(value, hw_info->pcie_base + DPMAIF_DL_BAT_ADD);
+
+	if (t7xx_dl_add_timedout(hw_info)) {
+		dev_err(dpmaif_ctrl->dev, "DL add BAT timeout\n");
+		return -EBUSY;
+	}
+
+	return 0;
+}
+
+unsigned int t7xx_dpmaif_dl_get_bat_ridx(struct dpmaif_hw_info *hw_info, unsigned char q_num)
+{
+	u32 value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_BAT_RIDX);
+	return value & DPMAIF_DL_BAT_WRIDX_MSK;
+}
+
+unsigned int t7xx_dpmaif_dl_get_bat_wridx(struct dpmaif_hw_info *hw_info, unsigned char q_num)
+{
+	u32 value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_BAT_WRIDX);
+	return value & DPMAIF_DL_BAT_WRIDX_MSK;
+}
+
+int t7xx_dpmaif_dl_snd_hw_frg_cnt(struct dpmaif_ctrl *dpmaif_ctrl, unsigned int frg_entry_cnt)
+{
+	struct dpmaif_hw_info *hw_info = &dpmaif_ctrl->hif_hw_info;
+	unsigned int value;
+
+	if (t7xx_dl_add_timedout(hw_info)) {
+		dev_err(dpmaif_ctrl->dev, "Data plane modem is not ready to add frag DLQ\n");
+		return -EBUSY;
+	}
+
+	value = frg_entry_cnt & DPMAIF_DL_ADD_COUNT_MASK;
+	value |= DPMAIF_DL_FRG_ADD_UPDATE | DPMAIF_DL_ADD_UPDATE;
+	iowrite32(value, hw_info->pcie_base + DPMAIF_DL_BAT_ADD);
+
+	if (t7xx_dl_add_timedout(hw_info)) {
+		dev_err(dpmaif_ctrl->dev, "Data plane modem add frag DLQ failed");
+		return -EBUSY;
+	}
+
+	return 0;
+}
+
+unsigned int t7xx_dpmaif_dl_get_frg_ridx(struct dpmaif_hw_info *hw_info, unsigned char q_num)
+{
+	u32 value;
+
+	value = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_FRGBAT_WRIDX);
+	return value & DPMAIF_DL_FRG_WRIDX_MSK;
+}
+
+static void t7xx_dpmaif_set_queue_property(struct dpmaif_hw_info *hw_info,
+					   struct dpmaif_hw_params *init_para)
+{
+	struct dpmaif_dl_hwq *dl_hwq;
+	struct dpmaif_dl *dl_que;
+	struct dpmaif_ul *ul_que;
+	int i;
+
+	for (i = 0; i < DPMAIF_RXQ_NUM; i++) {
+		dl_hwq = &hw_info->dl_que_hw[i];
+		dl_hwq->bat_remain_size = DPMAIF_HW_BAT_REMAIN;
+		dl_hwq->bat_pkt_bufsz = DPMAIF_HW_BAT_PKTBUF;
+		dl_hwq->frg_pkt_bufsz = DPMAIF_HW_FRG_PKTBUF;
+		dl_hwq->bat_rsv_length = DPMAIF_HW_BAT_RSVLEN;
+		dl_hwq->pkt_bid_max_cnt = DPMAIF_HW_PKT_BIDCNT;
+		dl_hwq->pkt_alignment = DPMAIF_HW_PKT_ALIGN;
+		dl_hwq->mtu_size = DPMAIF_HW_MTU_SIZE;
+		dl_hwq->chk_bat_num = DPMAIF_HW_CHK_BAT_NUM;
+		dl_hwq->chk_frg_num = DPMAIF_HW_CHK_FRG_NUM;
+		dl_hwq->chk_pit_num = DPMAIF_HW_CHK_PIT_NUM;
+
+		dl_que = &hw_info->dl_que[i];
+		dl_que->bat_base = init_para->pkt_bat_base_addr[i];
+		dl_que->bat_size_cnt = init_para->pkt_bat_size_cnt[i];
+		dl_que->pit_base = init_para->pit_base_addr[i];
+		dl_que->pit_size_cnt = init_para->pit_size_cnt[i];
+		dl_que->frg_base = init_para->frg_bat_base_addr[i];
+		dl_que->frg_size_cnt = init_para->frg_bat_size_cnt[i];
+		dl_que->que_started = true;
+	}
+
+	for (i = 0; i < DPMAIF_TXQ_NUM; i++) {
+		ul_que = &hw_info->ul_que[i];
+		ul_que->drb_base = init_para->drb_base_addr[i];
+		ul_que->drb_size_cnt = init_para->drb_size_cnt[i];
+		ul_que->que_started = true;
+	}
+}
+
+/**
+ * t7xx_dpmaif_hw_stop_tx_queue() - Stop all TX queues.
+ * @dpmaif_ctrl: Pointer to struct dpmaif_ctrl.
+ *
+ * Disable HW UL queues. Checks busy UL queues to go to idle
+ * with an attempt count of 1000000.
+ *
+ * Return:
+ * * 0			- Success
+ * * -ETIMEDOUT		- Timed out checking busy queues
+ */
+int t7xx_dpmaif_hw_stop_tx_queue(struct dpmaif_ctrl *dpmaif_ctrl)
+{
+	struct dpmaif_hw_info *hw_info = &dpmaif_ctrl->hif_hw_info;
+	int count = 0;
+
+	t7xx_dpmaif_ul_all_queue_en(hw_info, false);
+	while (t7xx_dpmaif_ul_idle_check(hw_info)) {
+		if (++count >= DPMAIF_MAX_CHECK_COUNT) {
+			dev_err(dpmaif_ctrl->dev, "Failed to stop TX, status: 0x%x\n",
+				ioread32(hw_info->pcie_base + DPMAIF_UL_CHK_BUSY));
+			return -ETIMEDOUT;
+		}
+	}
+
+	return 0;
+}
+
+/**
+ * t7xx_dpmaif_hw_stop_rx_queue() - Stop all RX queues.
+ * @dpmaif_ctrl: Pointer to struct dpmaif_ctrl.
+ *
+ * Disable HW DL queue. Checks busy UL queues to go to idle
+ * with an attempt count of 1000000.
+ * Check that HW PIT write index equals read index with the same
+ * attempt count.
+ *
+ * Return:
+ * * 0			- Success.
+ * * -ETIMEDOUT		- Timed out checking busy queues.
+ */
+int t7xx_dpmaif_hw_stop_rx_queue(struct dpmaif_ctrl *dpmaif_ctrl)
+{
+	struct dpmaif_hw_info *hw_info = &dpmaif_ctrl->hif_hw_info;
+	unsigned int wridx, ridx;
+	int count = 0;
+
+	t7xx_dpmaif_dl_all_queue_en(dpmaif_ctrl, false);
+	while (t7xx_dpmaif_dl_idle_check(hw_info)) {
+		if (++count >= DPMAIF_MAX_CHECK_COUNT) {
+			dev_err(dpmaif_ctrl->dev, "Failed to stop RX, status: 0x%x\n",
+				ioread32(hw_info->pcie_base + DPMAIF_DL_CHK_BUSY));
+			return -ETIMEDOUT;
+		}
+	}
+
+	/* Check middle PIT sync done */
+	count = 0;
+	do {
+		wridx = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_PIT_WRIDX);
+		wridx &= DPMAIF_DL_PIT_WRIDX_MSK;
+		ridx = ioread32(hw_info->pcie_base + DPMAIF_AO_DL_PIT_RIDX);
+		ridx &= DPMAIF_DL_PIT_WRIDX_MSK;
+
+		if (wridx == ridx)
+			return 0;
+	} while (++count < DPMAIF_MAX_CHECK_COUNT);
+
+	dev_err(dpmaif_ctrl->dev, "Check middle PIT sync fail\n");
+	return -ETIMEDOUT;
+}
+
+void t7xx_dpmaif_start_hw(struct dpmaif_ctrl *dpmaif_ctrl)
+{
+	t7xx_dpmaif_ul_all_queue_en(&dpmaif_ctrl->hif_hw_info, true);
+	t7xx_dpmaif_dl_all_queue_en(dpmaif_ctrl, true);
+}
+
+/**
+ * t7xx_dpmaif_hw_init() - Initialize HW data path API.
+ * @dpmaif_ctrl: Pointer to struct dpmaif_ctrl.
+ * @init_param: Pointer to struct dpmaif_hw_params.
+ *
+ * Configures port mode, clock config, HW interrupt initialization, and HW queue.
+ *
+ * Return:
+ * * 0		- Success.
+ * * -ERROR	- Error code from failure sub-initializations.
+ */
+int t7xx_dpmaif_hw_init(struct dpmaif_ctrl *dpmaif_ctrl, struct dpmaif_hw_params *init_param)
+{
+	struct dpmaif_hw_info *hw_info = &dpmaif_ctrl->hif_hw_info;
+	int ret;
+
+	ret = t7xx_dpmaif_hw_config(hw_info);
+	if (ret) {
+		dev_err(dpmaif_ctrl->dev, "DPMAIF HW config failed\n");
+		return ret;
+	}
+
+	ret = t7xx_dpmaif_init_intr(hw_info);
+	if (ret) {
+		dev_err(dpmaif_ctrl->dev, "DPMAIF HW interrupts init failed\n");
+		return ret;
+	}
+
+	t7xx_dpmaif_set_queue_property(hw_info, init_param);
+
+	ret = t7xx_dpmaif_config_que_hw(dpmaif_ctrl);
+	if (ret)
+		dev_err(dpmaif_ctrl->dev, "DPMAIF HW queue init failed\n");
+
+	return ret;
+}
+
+bool t7xx_dpmaif_ul_clr_done(struct dpmaif_hw_info *hw_info, unsigned char qno)
+{
+	u32 intr_status;
+
+	intr_status = ioread32(hw_info->pcie_base + DPMAIF_AP_L2TISAR0);
+	intr_status &= BIT(DP_UL_INT_DONE_OFFSET + qno);
+	if (intr_status) {
+		iowrite32(intr_status, hw_info->pcie_base + DPMAIF_AP_L2TISAR0);
+		return true;
+	}
+
+	return false;
+}
drivers/net/wwan/t7xx/t7xx_dpmaif.h new file +146 -0

146 lines not on this page · raw message

Signature · 1 line
2.17.1
#25 lore raw

Re: [PATCH net-next v3 06/12] net: wwan: t7xx: Data path HW layer

Quoted 5 lines · Ricardo Martinez

From: Haijun Liu <[email protected]>

Data Path Modem AP Interface (DPMAIF) HW layer provides HW abstraction for the upper layer (DPMAIF HIF). It implements functions to do the HW configuration, TX/RX control and interrupt handling.

...

Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_dpmaif.c new file +5 -0
+	ret = readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMR0,
+					value, (value & ul_intr_enable) != ul_intr_enable, 0,
+					DPMAIF_CHECK_INIT_TIMEOUT_US);
+	if (ret)
+		return ret;

...

Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_dpmaif.c new file +5 -0
+	ret = readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMR0,
+					value, (value & ul_intr_enable) != ul_intr_enable, 0,
+					DPMAIF_CHECK_INIT_TIMEOUT_US);
+	if (ret)
+		return ret;

...

drivers/net/wwan/t7xx/t7xx_dpmaif.c line 98

Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_dpmaif.c new file +7 -0
+	ret = readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMR0,
+					value, (value & ul_int_que_done) == ul_int_que_done, 0,
+					DPMAIF_CHECK_TIMEOUT_US);
+	if (ret)
+		dev_err(dpmaif_ctrl->dev,
+			"Could not mask the UL interrupt. DPMAIF_AO_UL_AP_L2TIMR0 is 0x%x\n",
+			value);

I would recommend to add a small patch that extends iopoll.h by ioreadXX() variants.

Or as alternative just define it here at the top of the file (or in one of the header if it's used more than in one module) so we may move it to the iopoll.h in the future:

#define ioread32_poll_timeout_atomic(addr, val, cond, delay_us, timeout_us) \
readx_poll_timeout_atomic(ioread32, addr, val, cond, delay_us, timeout_us)

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#26 lore raw

Re: [PATCH net-next v3 06/12] net: wwan: t7xx: Data path HW layer

+Cc: people from "[PATCH v7 1/2] iopoll: Introduce memory-mapped IO polling macros"

Any idea why ioreadXX() doomed between v7 and v10 of that series? Any further work is going on?

Quoted 49 lines · Andy Shevchenko
Quoted 5 lines · Ricardo Martinez

From: Haijun Liu <[email protected]>

Data Path Modem AP Interface (DPMAIF) HW layer provides HW abstraction for the upper layer (DPMAIF HIF). It implements functions to do the HW configuration, TX/RX control and interrupt handling.

...

Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_dpmaif.c new file +5 -0
+	ret = readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMR0,
+					value, (value & ul_intr_enable) != ul_intr_enable, 0,
+					DPMAIF_CHECK_INIT_TIMEOUT_US);
+	if (ret)
+		return ret;

...

Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_dpmaif.c new file +5 -0
+	ret = readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_AO_UL_APDL_L2TIMR0,
+					value, (value & ul_intr_enable) != ul_intr_enable, 0,
+					DPMAIF_CHECK_INIT_TIMEOUT_US);
+	if (ret)
+		return ret;

...

drivers/net/wwan/t7xx/t7xx_dpmaif.c line 98

Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_dpmaif.c new file +7 -0
+	ret = readx_poll_timeout_atomic(ioread32, hw_info->pcie_base + DPMAIF_AO_UL_AP_L2TIMR0,
+					value, (value & ul_int_que_done) == ul_int_que_done, 0,
+					DPMAIF_CHECK_TIMEOUT_US);
+	if (ret)
+		dev_err(dpmaif_ctrl->dev,
+			"Could not mask the UL interrupt. DPMAIF_AO_UL_AP_L2TIMR0 is 0x%x\n",
+			value);

I would recommend to add a small patch that extends iopoll.h by ioreadXX() variants.

Or as alternative just define it here at the top of the file (or in one of the header if it's used more than in one module) so we may move it to the iopoll.h in the future:

#define ioread32_poll_timeout_atomic(addr, val, cond, delay_us, timeout_us) \
readx_poll_timeout_atomic(ioread32, addr, val, cond, delay_us, timeout_us)

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author reviewer
#27 lore raw

PATCH v3 7/12 net: wwan: t7xx: Add data path interface

In reply to Ricardo Martinez

From: Haijun Liu <[email protected]>

Data Path Modem AP Interface (DPMAIF) HIF layer provides methods for initialization, ISR, control and event handling of TX/RX flows.

DPMAIF TX
Exposes the dmpaif_tx_send_skb function which can be used by the network device to transmit packets.
The uplink data management uses a Descriptor Ring Buffer (DRB). First DRB entry is a message type that will be followed by 1 or more normal DRB entries. Message type DRB will hold the skb information and each normal DRB entry holds a pointer to the skb payload.

DPMAIF RX
The downlink buffer management uses Buffer Address Table (BAT) and Packet Information Table (PIT) rings.
The BAT ring holds the address of skb data buffer for the HW to use, while the PIT contains metadata about a whole network packet including a reference to the BAT entry holding the data buffer address. The driver reads the PIT and BAT entries written by the modem, when reaching a threshold, the driver will reload the PIT and BAT rings.

---
 drivers/net/wwan/t7xx/Makefile             |    4 +
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c    |  487 ++++++++
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h    |  259 ++++
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 1251 ++++++++++++++++++++
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h |  115 ++
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c |  730 ++++++++++++
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.h |   89 ++
 7 files changed, 2935 insertions(+)
 create mode 100644 drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h
 create mode 100644 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.h
drivers/net/wwan/t7xx/Makefile +4 -0
index 9eec2e2472fb..04a9ba50dc14 100644
@@ -13,3 +13,7 @@ mtk_t7xx-y:=	t7xx_pci.o \
 		t7xx_port_proxy.o  \
 		t7xx_port_ctrl_msg.o \
 		t7xx_port_wwan.o \
+		t7xx_hif_dpmaif.o  \
+		t7xx_hif_dpmaif_tx.o \
+		t7xx_hif_dpmaif_rx.o  \
+		t7xx_dpmaif.o \
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c new file +487 -0

487 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h new file +259 -0

259 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +1251 -0

1,251 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h new file +115 -0

115 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c new file +730 -0

730 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.h new file +89 -0

89 lines not on this page · raw message

Signature · 1 line
2.17.1
#28 lore raw

Re: [PATCH net-next v3 07/12] net: wwan: t7xx: Add data path interface

Quoted 22 lines · Ricardo Martinez

From: Haijun Liu <[email protected]>

Data Path Modem AP Interface (DPMAIF) HIF layer provides methods for initialization, ISR, control and event handling of TX/RX flows.

DPMAIF TX
Exposes the dmpaif_tx_send_skb function which can be used by the network device to transmit packets.
The uplink data management uses a Descriptor Ring Buffer (DRB). First DRB entry is a message type that will be followed by 1 or more normal DRB entries. Message type DRB will hold the skb information and each normal DRB entry holds a pointer to the skb payload.

DPMAIF RX
The downlink buffer management uses Buffer Address Table (BAT) and Packet Information Table (PIT) rings.
The BAT ring holds the address of skb data buffer for the HW to use, while the PIT contains metadata about a whole network packet including a reference to the BAT entry holding the data buffer address. The driver reads the PIT and BAT entries written by the modem, when reaching a threshold, the driver will reload the PIT and BAT rings.

Quoted 4 lines

+struct dpmaif_ctrl {
...
+ unsigned char txq_select_times;

txq_select_times value is never used.

Quoted 12 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c new file +12 -0
+unsigned int t7xx_ring_buf_get_next_wrdx(unsigned int buf_len, unsigned int buf_idx)
+{
+	buf_idx++;
+
+	return buf_idx < buf_len ? buf_idx : 0;
+}
+
+unsigned int t7xx_ring_buf_rd_wr_count(unsigned int total_cnt, unsigned int rd_idx,
+				       unsigned int wrt_idx, enum dpmaif_rdwr rd_wr)
+{
+	int pkt_cnt;
+

drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c line 57

Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c new file +10 -0
+	if (rd_wr == DPMAIF_READ)
+		pkt_cnt = wrt_idx - rd_idx;
+	else
+		pkt_cnt = rd_idx - wrt_idx - 1;
+
+	if (pkt_cnt < 0)
+		pkt_cnt += total_cnt;
+
+	return (unsigned int)pkt_cnt;
+}

Didn't the earlier patch use wridx and ridx for the same concept? It would be useful to have consistency in variable naming.

Quoted 1 line

+static inline unsigned int t7xx_normal_pit_bid(const struct dpmaif_normal_pit *pit_info)

No inlines in .c files please. Please fix all of them, not just this one..

Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +10 -0
+	for (i = 0; i < alloc_cnt; i++) {
+		unsigned short cur_bat_idx = bat_start_idx + i;
+		struct dpmaif_bat_skb *cur_skb;
+		struct dpmaif_bat *cur_bat;
+
+		if (cur_bat_idx >= bat_max_cnt)
+			cur_bat_idx -= bat_max_cnt;
+
+		cur_skb = (struct dpmaif_bat_skb *)bat_req->bat_skb + cur_bat_idx;
+		if (!cur_skb->skb) {

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c line 259

Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +10 -0
+			struct dpmaif_skb_info *skb_info;
+
+			skb_info = t7xx_dpmaif_dev_alloc_skb(dpmaif_ctrl, bat_req->pkt_buf_sz);
+			if (!skb_info)
+				break;
+
+			cur_skb->skb = skb_info->skb;
+			cur_skb->data_bus_addr = skb_info->data_bus_addr;
+			cur_skb->data_len = skb_info->data_len;
+			kfree(skb_info);

It seems that here you do an alloc that is immediately followed by kfree. Couldn't this be solved by passing cur_skb to a function which assigns those values you want directly to it?

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c line 307

Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +5 -0
+	old_sw_rel_idx = rxq->pit_release_rd_idx;
+	new_sw_rel_idx = old_sw_rel_idx + rel_entry_num;
+	old_hw_wr_idx = rxq->pit_wr_idx;
+	if (old_hw_wr_idx < old_sw_rel_idx && new_sw_rel_idx >= rxq->pit_size_cnt)
+		new_sw_rel_idx = new_sw_rel_idx - rxq->pit_size_cnt;

-=

Quoted 67 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +67 -0
+/**
+ * t7xx_dpmaif_rx_frag_alloc() - Allocates buffers for the Fragment BAT ring.
+ * @dpmaif_ctrl: Pointer to DPMAIF context structure.
+ * @bat_req: Pointer to BAT request structure.
+ * @buf_cnt: Number of buffers to allocate.
+ * @initial: Indicates if the ring is being populated for the first time.
+ *
+ * Fragment BAT is used when the received packet does not fit in a normal BAT entry.
+ * This function allocates a page fragment and stores the start address of the page
+ * into the Fragment BAT ring.
+ * If this is not the initial call, notify the HW about the new entries.
+ *
+ * Return:
+ * * 0		- Success.
+ * * -ERROR	- Error code from failure sub-initializations.
+ */
+int t7xx_dpmaif_rx_frag_alloc(struct dpmaif_ctrl *dpmaif_ctrl, struct dpmaif_bat_request *bat_req,
+			      const unsigned int buf_cnt, const bool initial)
+{
+	struct dpmaif_bat_page *bat_skb = bat_req->bat_skb;
+	unsigned short cur_bat_idx = bat_req->bat_wr_idx;
+	unsigned int buf_space;
+	int i;
+
+	if (!buf_cnt || buf_cnt > bat_req->bat_size_cnt)
+		return -EINVAL;
+
+	buf_space = t7xx_ring_buf_rd_wr_count(bat_req->bat_size_cnt,
+					      bat_req->bat_release_rd_idx, bat_req->bat_wr_idx,
+					      DPMAIF_WRITE);
+	if (buf_cnt > buf_space) {
+		dev_err(dpmaif_ctrl->dev,
+			"Requested more buffers than the space available in RX frag ring\n");
+		return -EINVAL;
+	}
+
+	for (i = 0; i < buf_cnt; i++) {
+		struct dpmaif_bat_page *cur_page = bat_skb + cur_bat_idx;
+		struct dpmaif_bat *cur_bat;
+		dma_addr_t data_base_addr;
+
+		if (!cur_page->page) {
+			unsigned long offset;
+			struct page *page;
+			void *data;
+
+			data = netdev_alloc_frag(bat_req->pkt_buf_sz);
+			if (!data)
+				break;
+
+			page = virt_to_head_page(data);
+			offset = data - page_address(page);
+
+			data_base_addr = dma_map_page(dpmaif_ctrl->dev, page, offset,
+						      bat_req->pkt_buf_sz, DMA_FROM_DEVICE);
+			if (dma_mapping_error(dpmaif_ctrl->dev, data_base_addr)) {
+				dev_err(dpmaif_ctrl->dev, "DMA mapping fail\n");
+				put_page(virt_to_head_page(data));
+				break;
+			}
+
+			cur_page->page = page;
+			cur_page->data_bus_addr = data_base_addr;
+			cur_page->offset = offset;
+			cur_page->data_len = bat_req->pkt_buf_sz;
+		}
+

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c line 422

Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +10 -0
+		data_base_addr = cur_page->data_bus_addr;
+		cur_bat = (struct dpmaif_bat *)bat_req->bat_base + cur_bat_idx;
+		cur_bat->buffer_addr_ext = upper_32_bits(data_base_addr);
+		cur_bat->p_buffer_addr = lower_32_bits(data_base_addr);
+		cur_bat_idx = t7xx_ring_buf_get_next_wrdx(bat_req->bat_size_cnt, cur_bat_idx);
+	}
+
+	if (i < buf_cnt)
+		return -ENOMEM;
+	bat_req->bat_wr_idx = cur_bat_idx;

Is there some leak if this early returns and does not update bat_wr_idx? One call path seems to eventually just ignore error code.

Quoted 79 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +79 -0
+static int t7xx_dpmaif_rx_start(struct dpmaif_rx_queue *rxq, const unsigned short pit_cnt,
+				const unsigned long timeout)
+{
+	struct device *dev = rxq->dpmaif_ctrl->dev;
+	struct dpmaif_cur_rx_skb_info *skb_info;
+	unsigned short rx_cnt, recv_skb_cnt = 0;
+	unsigned int cur_pit, pit_len;
+	int ret = 0, ret_hw = 0;
+
+	pit_len = rxq->pit_size_cnt;
+	skb_info = &rxq->rx_data_info;
+	cur_pit = rxq->pit_rd_idx;
+
+	for (rx_cnt = 0; rx_cnt < pit_cnt; rx_cnt++) {
+		struct dpmaif_normal_pit *pkt_info;
+		u32 val;
+
+		if (!skb_info->msg_pit_received && time_after_eq(jiffies, timeout))
+			break;
+
+		pkt_info = (struct dpmaif_normal_pit *)rxq->pit_base + cur_pit;
+		if (t7xx_dpmaif_check_pit_seq(rxq, pkt_info)) {
+			dev_err_ratelimited(dev, "RXQ%u checks PIT SEQ fail\n", rxq->index);
+			return -EAGAIN;
+		}
+
+		val = FIELD_GET(NORMAL_PIT_PACKET_TYPE, le32_to_cpu(pkt_info->pit_header));
+		if (val == DES_PT_MSG) {
+			if (skb_info->msg_pit_received)
+				dev_err(dev, "RXQ%u received repeated PIT\n", rxq->index);
+
+			skb_info->msg_pit_received = true;
+			t7xx_dpmaif_parse_msg_pit(rxq, (struct dpmaif_msg_pit *)pkt_info,
+						  skb_info);
+		} else { /* DES_PT_PD */
+			val = FIELD_GET(NORMAL_PIT_BUFFER_TYPE, le32_to_cpu(pkt_info->pit_header));
+			if (val != PKT_BUF_FRAG)
+				ret = t7xx_dpmaif_get_rx_pkt(rxq, pkt_info, skb_info);
+			else if (!skb_info->cur_skb)
+				ret = -EINVAL;
+			else
+				ret = t7xx_dpmaif_get_frag(rxq, pkt_info, skb_info);
+
+			if (ret < 0) {
+				skb_info->err_payload = 1;
+				dev_err_ratelimited(dev, "RXQ%u error payload\n", rxq->index);
+			}
+
+			val = FIELD_GET(NORMAL_PIT_CONT, le32_to_cpu(pkt_info->pit_header));
+			if (!val) {
+				if (!skb_info->err_payload) {
+					t7xx_dpmaif_rx_skb(rxq, skb_info);
+				} else if (skb_info->cur_skb) {
+					dev_kfree_skb_any(skb_info->cur_skb);
+					skb_info->cur_skb = NULL;
+				}
+
+				memset(skb_info, 0, sizeof(*skb_info));
+
+				recv_skb_cnt++;
+				if (!(recv_skb_cnt & DPMAIF_RX_PUSH_THRESHOLD_MASK)) {
+					wake_up_all(&rxq->rx_wq);
+					recv_skb_cnt = 0;
+				}
+			}
+		}
+
+		cur_pit = t7xx_ring_buf_get_next_wrdx(pit_len, cur_pit);
+		rxq->pit_rd_idx = cur_pit;
+		rxq->pit_remain_release_cnt++;
+
+		if (rx_cnt > 0 && !(rx_cnt % DPMAIF_NOTIFY_RELEASE_COUNT)) {
+			ret_hw = t7xx_dpmaifq_rx_notify_hw(rxq);
+			if (ret_hw < 0)
+				break;
+		}
+	}
+
+	if (recv_skb_cnt)

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c line 848

Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +10 -0
+		wake_up_all(&rxq->rx_wq);
+
+	if (!ret_hw)
+		ret_hw = t7xx_dpmaifq_rx_notify_hw(rxq);
+
+	if (ret_hw < 0 && !ret)
+		ret = ret_hw;
+
+	return ret < 0 ? ret : rx_cnt;
+}

ret variable handling seems odd, loop overwrites prev errors. Is there perhaps a break missing from somewhere as post loop checks seem to care about the value of ret variable?

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c line 159

Quoted 1 line
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c new file +1 -0
+	return (real_rel_cnt < rel_cnt) ? -EAGAIN : 0;

Extra ().

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c line 247

Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c new file +8 -0
+static int t7xx_dpmaif_add_skb_to_ring(struct dpmaif_ctrl *dpmaif_ctrl, struct sk_buff *skb)
+{
+	unsigned int wr_cnt, send_cnt, payload_cnt;
+	bool is_frag, is_last_one = false;
+	int qtype = skb->cb[TX_CB_QTYPE];
+	struct skb_shared_info *info;
+	struct dpmaif_tx_queue *txq;
+	int drb_wr_idx_backup = -1;

Redundant initialization.

Quoted 65 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c new file +65 -0
+	unsigned short cur_idx;
+	unsigned int data_len;
+	dma_addr_t bus_addr;
+	unsigned long flags;
+	void *data_addr;
+	int ret = 0;
+
+	txq = &dpmaif_ctrl->txq[qtype];
+	if (!txq->que_started || dpmaif_ctrl->state != DPMAIF_STATE_PWRON)
+		return -ENODEV;
+
+	atomic_set(&txq->tx_processing, 1);
+	 /* Ensure tx_processing is changed to 1 before actually begin TX flow */
+	smp_mb();
+
+	info = skb_shinfo(skb);
+	if (info->frag_list)
+		dev_warn_ratelimited(dpmaif_ctrl->dev, "frag_list not supported\n");
+
+	payload_cnt = info->nr_frags + 1;
+	/* nr_frags: frag cnt, 1: skb->data, 1: msg DRB */
+	send_cnt = payload_cnt + 1;
+
+	spin_lock_irqsave(&txq->tx_lock, flags);
+	cur_idx = txq->drb_wr_idx;
+	drb_wr_idx_backup = cur_idx;
+
+	txq->drb_wr_idx += send_cnt;
+	if (txq->drb_wr_idx >= txq->drb_size_cnt)
+		txq->drb_wr_idx -= txq->drb_size_cnt;
+
+	t7xx_setup_msg_drb(dpmaif_ctrl, txq->index, cur_idx, skb->len, 0, skb->cb[TX_CB_NETIF_IDX]);
+	t7xx_record_drb_skb(dpmaif_ctrl, txq->index, cur_idx, skb, 1, 0, 0, 0, 0);
+	spin_unlock_irqrestore(&txq->tx_lock, flags);
+
+	cur_idx = t7xx_ring_buf_get_next_wrdx(txq->drb_size_cnt, cur_idx);
+
+	for (wr_cnt = 0; wr_cnt < payload_cnt; wr_cnt++) {
+		if (!wr_cnt) {
+			data_len = skb_headlen(skb);
+			data_addr = skb->data;
+			is_frag = false;
+		} else {
+			skb_frag_t *frag = info->frags + wr_cnt - 1;
+
+			data_len = skb_frag_size(frag);
+			data_addr = skb_frag_address(frag);
+			is_frag = true;
+		}
+
+		if (wr_cnt == payload_cnt - 1)
+			is_last_one = true;
+
+		/* TX mapping */
+		bus_addr = dma_map_single(dpmaif_ctrl->dev, data_addr, data_len, DMA_TO_DEVICE);
+		if (dma_mapping_error(dpmaif_ctrl->dev, bus_addr)) {
+			dev_err(dpmaif_ctrl->dev, "DMA mapping fail\n");
+			ret = -ENOMEM;
+			break;
+		}
+
+		spin_lock_irqsave(&txq->tx_lock, flags);
+		t7xx_setup_payload_drb(dpmaif_ctrl, txq->index, cur_idx, bus_addr, data_len,
+				       is_last_one);
+		t7xx_record_drb_skb(dpmaif_ctrl, txq->index, cur_idx, skb, 0, is_frag,

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c line 322

Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c new file +10 -0
+				    is_last_one, bus_addr, data_len);
+		spin_unlock_irqrestore(&txq->tx_lock, flags);
+
+		cur_idx = t7xx_ring_buf_get_next_wrdx(txq->drb_size_cnt, cur_idx);
+	}
+
+	if (ret < 0) {
+		atomic_set(&txq->tx_processing, 0);
+
+		if (drb_wr_idx_backup >= 0) {

Always true?

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c line 707

Quoted 9 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c new file +9 -0
+		/* Confirm that SW will not transmit */
+		count = 0;
+
+		do {
+			if (++count >= DPMAIF_MAX_CHECK_COUNT) {
+				dev_err(dpmaif_ctrl->dev, "TX queue stop failed\n");
+				break;
+			}
+		} while (atomic_read(&txq->tx_processing));
while (atomic_read(...)) {
	...
}
Signature · 1 line
 i.
author reviewer
#29 lore raw

Re: [PATCH net-next v3 07/12] net: wwan: t7xx: Add data path interface

On 12/16/2021 5:30 AM, Ilpo Järvinen wrote:
...

Quoted 16 lines
Quoted 16 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +15 -0
+	for (i = 0; i < alloc_cnt; i++) {
+		unsigned short cur_bat_idx = bat_start_idx + i;
+		struct dpmaif_bat_skb *cur_skb;
+		struct dpmaif_bat *cur_bat;
+
+		if (cur_bat_idx >= bat_max_cnt)
+			cur_bat_idx -= bat_max_cnt;
+
+		cur_skb = (struct dpmaif_bat_skb *)bat_req->bat_skb + cur_bat_idx;
+		if (!cur_skb->skb) {
+			struct dpmaif_skb_info *skb_info;
+
+			skb_info = t7xx_dpmaif_dev_alloc_skb(dpmaif_ctrl, bat_req->pkt_buf_sz);
+			if (!skb_info)
+				break;
Quoted 8 lines

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c line 259

Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +5 -0
+
+			cur_skb->skb = skb_info->skb;
+			cur_skb->data_bus_addr = skb_info->data_bus_addr;
+			cur_skb->data_len = skb_info->data_len;
+			kfree(skb_info);

It seems that here you do an alloc that is immediately followed by kfree. Couldn't this be solved by passing cur_skb to a function which assigns those values you want directly to it?

Yes, alloc removed in the next version.

...

Quoted 56 lines
Quoted 56 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +55 -0
+int t7xx_dpmaif_rx_frag_alloc(struct dpmaif_ctrl *dpmaif_ctrl, struct dpmaif_bat_request *bat_req,
+			      const unsigned int buf_cnt, const bool initial)
+{
+	struct dpmaif_bat_page *bat_skb = bat_req->bat_skb;
+	unsigned short cur_bat_idx = bat_req->bat_wr_idx;
+	unsigned int buf_space;
+	int i;
+
+	if (!buf_cnt || buf_cnt > bat_req->bat_size_cnt)
+		return -EINVAL;
+
+	buf_space = t7xx_ring_buf_rd_wr_count(bat_req->bat_size_cnt,
+					      bat_req->bat_release_rd_idx, bat_req->bat_wr_idx,
+					      DPMAIF_WRITE);
+	if (buf_cnt > buf_space) {
+		dev_err(dpmaif_ctrl->dev,
+			"Requested more buffers than the space available in RX frag ring\n");
+		return -EINVAL;
+	}
+
+	for (i = 0; i < buf_cnt; i++) {
+		struct dpmaif_bat_page *cur_page = bat_skb + cur_bat_idx;
+		struct dpmaif_bat *cur_bat;
+		dma_addr_t data_base_addr;
+
+		if (!cur_page->page) {
+			unsigned long offset;
+			struct page *page;
+			void *data;
+
+			data = netdev_alloc_frag(bat_req->pkt_buf_sz);
+			if (!data)
+				break;
+
+			page = virt_to_head_page(data);
+			offset = data - page_address(page);
+
+			data_base_addr = dma_map_page(dpmaif_ctrl->dev, page, offset,
+						      bat_req->pkt_buf_sz, DMA_FROM_DEVICE);
+			if (dma_mapping_error(dpmaif_ctrl->dev, data_base_addr)) {
+				dev_err(dpmaif_ctrl->dev, "DMA mapping fail\n");
+				put_page(virt_to_head_page(data));
+				break;
+			}
+
+			cur_page->page = page;
+			cur_page->data_bus_addr = data_base_addr;
+			cur_page->offset = offset;
+			cur_page->data_len = bat_req->pkt_buf_sz;
+		}
+
+		data_base_addr = cur_page->data_bus_addr;
+		cur_bat = (struct dpmaif_bat *)bat_req->bat_base + cur_bat_idx;
+		cur_bat->buffer_addr_ext = upper_32_bits(data_base_addr);
+		cur_bat->p_buffer_addr = lower_32_bits(data_base_addr);
Quoted 8 lines

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c line 422

Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +6 -0
+		cur_bat_idx = t7xx_ring_buf_get_next_wrdx(bat_req->bat_size_cnt, cur_bat_idx);
+	}
+
+	if (i < buf_cnt)
+		return -ENOMEM;
+	bat_req->bat_wr_idx = cur_bat_idx;

Is there some leak if this early returns and does not update bat_wr_idx? One call path seems to eventually just ignore error code.

Yes, the code should not return here. Also need to unmap the pages in case of error.

...

Quoted 84 lines
Quoted 84 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +84 -0
+static int t7xx_dpmaif_rx_start(struct dpmaif_rx_queue *rxq, const unsigned short pit_cnt,
+				const unsigned long timeout)
+{
+	struct device *dev = rxq->dpmaif_ctrl->dev;
+	struct dpmaif_cur_rx_skb_info *skb_info;
+	unsigned short rx_cnt, recv_skb_cnt = 0;
+	unsigned int cur_pit, pit_len;
+	int ret = 0, ret_hw = 0;
+
+	pit_len = rxq->pit_size_cnt;
+	skb_info = &rxq->rx_data_info;
+	cur_pit = rxq->pit_rd_idx;
+
+	for (rx_cnt = 0; rx_cnt < pit_cnt; rx_cnt++) {
+		struct dpmaif_normal_pit *pkt_info;
+		u32 val;
+
+		if (!skb_info->msg_pit_received && time_after_eq(jiffies, timeout))
+			break;
+
+		pkt_info = (struct dpmaif_normal_pit *)rxq->pit_base + cur_pit;
+		if (t7xx_dpmaif_check_pit_seq(rxq, pkt_info)) {
+			dev_err_ratelimited(dev, "RXQ%u checks PIT SEQ fail\n", rxq->index);
+			return -EAGAIN;
+		}
+
+		val = FIELD_GET(NORMAL_PIT_PACKET_TYPE, le32_to_cpu(pkt_info->pit_header));
+		if (val == DES_PT_MSG) {
+			if (skb_info->msg_pit_received)
+				dev_err(dev, "RXQ%u received repeated PIT\n", rxq->index);
+
+			skb_info->msg_pit_received = true;
+			t7xx_dpmaif_parse_msg_pit(rxq, (struct dpmaif_msg_pit *)pkt_info,
+						  skb_info);
+		} else { /* DES_PT_PD */
+			val = FIELD_GET(NORMAL_PIT_BUFFER_TYPE, le32_to_cpu(pkt_info->pit_header));
+			if (val != PKT_BUF_FRAG)
+				ret = t7xx_dpmaif_get_rx_pkt(rxq, pkt_info, skb_info);
+			else if (!skb_info->cur_skb)
+				ret = -EINVAL;
+			else
+				ret = t7xx_dpmaif_get_frag(rxq, pkt_info, skb_info);
+
+			if (ret < 0) {
+				skb_info->err_payload = 1;
+				dev_err_ratelimited(dev, "RXQ%u error payload\n", rxq->index);
+			}
+
+			val = FIELD_GET(NORMAL_PIT_CONT, le32_to_cpu(pkt_info->pit_header));
+			if (!val) {
+				if (!skb_info->err_payload) {
+					t7xx_dpmaif_rx_skb(rxq, skb_info);
+				} else if (skb_info->cur_skb) {
+					dev_kfree_skb_any(skb_info->cur_skb);
+					skb_info->cur_skb = NULL;
+				}
+
+				memset(skb_info, 0, sizeof(*skb_info));
+
+				recv_skb_cnt++;
+				if (!(recv_skb_cnt & DPMAIF_RX_PUSH_THRESHOLD_MASK)) {
+					wake_up_all(&rxq->rx_wq);
+					recv_skb_cnt = 0;
+				}
+			}
+		}
+
+		cur_pit = t7xx_ring_buf_get_next_wrdx(pit_len, cur_pit);
+		rxq->pit_rd_idx = cur_pit;
+		rxq->pit_remain_release_cnt++;
+
+		if (rx_cnt > 0 && !(rx_cnt % DPMAIF_NOTIFY_RELEASE_COUNT)) {
+			ret_hw = t7xx_dpmaifq_rx_notify_hw(rxq);
+			if (ret_hw < 0)
+				break;
+		}
+	}
+
+	if (recv_skb_cnt)
+		wake_up_all(&rxq->rx_wq);
+
+	if (!ret_hw)
+		ret_hw = t7xx_dpmaifq_rx_notify_hw(rxq);
+
Quoted 8 lines

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c line 848

Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +5 -0
+	if (ret_hw < 0 && !ret)
+		ret = ret_hw;
+
+	return ret < 0 ? ret : rx_cnt;
+}

ret variable handling seems odd, loop overwrites prev errors. Is there perhaps a break missing from somewhere as post loop checks seem to care about the value of ret variable?

ret should not be used outside of the loop, the error handling will be cleaned up in the

next version.

ret tells if the payload is good, in the unlikely case of error, the loop can continue

with the next packet.

author reviewer
#30 lore raw

PATCH v3 8/12 net: wwan: t7xx: Add WWAN network interface

In reply to Ricardo Martinez

From: Haijun Liu <[email protected]>

Creates the Cross Core Modem Network Interface (CCMNI) which implements the wwan_ops for registration with the WWAN framework, CCMNI also implements the net_device_ops functions used by the network device. Network device operations include open, close, start transmission, TX timeout, change MTU, and select queue.

---
 drivers/net/wwan/t7xx/Makefile         |   1 +
 drivers/net/wwan/t7xx/t7xx_modem_ops.c |  11 +-
 drivers/net/wwan/t7xx/t7xx_netdev.c    | 433 +++++++++++++++++++++++++
 drivers/net/wwan/t7xx/t7xx_netdev.h    |  61 ++++
 4 files changed, 505 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/wwan/t7xx/t7xx_netdev.c
 create mode 100644 drivers/net/wwan/t7xx/t7xx_netdev.h
drivers/net/wwan/t7xx/Makefile +1 -0
index 04a9ba50dc14..dc6a7d682c15 100644
@@ -17,3 +17,4 @@ mtk_t7xx-y:=	t7xx_pci.o \
 		t7xx_hif_dpmaif_tx.o \
 		t7xx_hif_dpmaif_rx.o  \
 		t7xx_dpmaif.o \
+		t7xx_netdev.o
drivers/net/wwan/t7xx/t7xx_modem_ops.c +10 -1
index 3db5e86c23e5..5a7089f10b80 100644
@@ -35,6 +35,7 @@
 #include "t7xx_hif_cldma.h"
 #include "t7xx_mhccif.h"
 #include "t7xx_modem_ops.h"
+#include "t7xx_netdev.h"
 #include "t7xx_pci.h"
 #include "t7xx_pcie_mac.h"
 #include "t7xx_port.h"
@@ -663,10 +664,14 @@ int t7xx_md_init(struct t7xx_pci_dev *t7xx_dev)
 	if (ret)
 		goto err_destroy_hswq;
 
-	ret = t7xx_cldma_init(md, md->md_ctrl[ID_CLDMA1]);
+	ret = t7xx_ccmni_init(t7xx_dev);
 	if (ret)
 		goto err_uninit_fsm;
 
+	ret = t7xx_cldma_init(md, md->md_ctrl[ID_CLDMA1]);
+	if (ret)
+		goto err_uninit_ccmni;
+
 	ret = t7xx_port_proxy_init(md);
 	if (ret)
 		goto err_uninit_cldma;
@@ -679,6 +684,9 @@ int t7xx_md_init(struct t7xx_pci_dev *t7xx_dev)
 err_uninit_cldma:
 	t7xx_cldma_exit(md->md_ctrl[ID_CLDMA1]);
 
+err_uninit_ccmni:
+	t7xx_ccmni_exit(t7xx_dev);
+
 err_uninit_fsm:
 	t7xx_fsm_uninit(md);
 
@@ -700,6 +708,7 @@ void t7xx_md_exit(struct t7xx_pci_dev *t7xx_dev)
 	t7xx_fsm_append_cmd(md->fsm_ctl, FSM_CMD_PRE_STOP, FSM_CMD_FLAG_WAIT_FOR_COMPLETION);
 	t7xx_port_proxy_uninit(md->port_prox);
 	t7xx_cldma_exit(md->md_ctrl[ID_CLDMA1]);
+	t7xx_ccmni_exit(t7xx_dev);
 	t7xx_fsm_uninit(md);
 	destroy_workqueue(md->handshake_wq);
 }
drivers/net/wwan/t7xx/t7xx_netdev.c new file +433 -0

433 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_netdev.h new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
2.17.1
author reviewer
#31 lore raw

PATCH v3 9/12 net: wwan: t7xx: Introduce power management support

In reply to Ricardo Martinez

From: Haijun Liu <[email protected]>

Implements suspend, resumes, freeze, thaw, poweroff, and restore dev_pm_ops callbacks.

From the host point of view, the t7xx driver is one entity. But, the device has several modules that need to be addressed in different ways during power management (PM) flows.
The driver uses the term 'PM entities' to refer to the 2 DPMA and 2 CLDMA HW blocks that need to be managed during PM flows. When a dev_pm_ops function is called, the PM entities list is iterated and the matching function is called for each entry in the list.

---
 drivers/net/wwan/t7xx/t7xx_hif_cldma.c     | 120 +++++-
 drivers/net/wwan/t7xx/t7xx_hif_cldma.h     |   1 +
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c    |  90 +++++
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h    |   1 +
 drivers/net/wwan/t7xx/t7xx_mhccif.c        |  17 +
 drivers/net/wwan/t7xx/t7xx_pci.c           | 426 +++++++++++++++++++++
 drivers/net/wwan/t7xx/t7xx_pci.h           |  46 +++
 drivers/net/wwan/t7xx/t7xx_state_monitor.c |   2 +
 8 files changed, 702 insertions(+), 1 deletion(-)
drivers/net/wwan/t7xx/t7xx_hif_cldma.c +119 -1
index 300ffbcc4735..8f35e6e43504 100644
@@ -1216,6 +1216,117 @@ void t7xx_cldma_exception(struct cldma_ctrl *md_ctrl, enum hif_ex_stage stage)
 	}
 }
 
+static void t7xx_cldma_resume_early(struct t7xx_pci_dev *mtk_dev, void *entity_param)
+{
+	struct cldma_ctrl *md_ctrl = entity_param;
+	struct t7xx_cldma_hw *hw_info;
+	unsigned long flags;
+	int qno_t;
+
+	hw_info = &md_ctrl->hw_info;
+	spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
+	t7xx_cldma_hw_restore(hw_info);
+	for (qno_t = 0; qno_t < CLDMA_TXQ_NUM; qno_t++) {
+		t7xx_cldma_hw_set_start_addr(hw_info, qno_t, md_ctrl->txq[qno_t].tx_xmit->gpd_addr,
+					     MTK_TX);
+		t7xx_cldma_hw_set_start_addr(hw_info, qno_t, md_ctrl->rxq[qno_t].tr_done->gpd_addr,
+					     MTK_RX);
+	}
+
+	t7xx_cldma_enable_irq(md_ctrl);
+	t7xx_cldma_hw_start_queue(hw_info, CLDMA_ALL_Q, MTK_RX);
+	md_ctrl->rxq_active |= TXRX_STATUS_BITMASK;
+	t7xx_cldma_hw_irq_en_eq(hw_info, CLDMA_ALL_Q, MTK_RX);
+	t7xx_cldma_hw_irq_en_txrx(hw_info, CLDMA_ALL_Q, MTK_RX);
+	spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
+}
+
+static int t7xx_cldma_resume(struct t7xx_pci_dev *t7xx_dev, void *entity_param)
+{
+	struct cldma_ctrl *md_ctrl = entity_param;
+	unsigned long flags;
+
+	spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
+	md_ctrl->txq_active |= TXRX_STATUS_BITMASK;
+	t7xx_cldma_hw_irq_en_txrx(&md_ctrl->hw_info, CLDMA_ALL_Q, MTK_TX);
+	t7xx_cldma_hw_irq_en_eq(&md_ctrl->hw_info, CLDMA_ALL_Q, MTK_TX);
+	spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
+
+	if (md_ctrl->hif_id == ID_CLDMA1)
+		t7xx_mhccif_mask_clr(t7xx_dev, D2H_SW_INT_MASK);
+
+	return 0;
+}
+
+static void t7xx_cldma_suspend_late(struct t7xx_pci_dev *t7xx_dev, void *entity_param)
+{
+	struct cldma_ctrl *md_ctrl = entity_param;
+	struct t7xx_cldma_hw *hw_info;
+	unsigned long flags;
+
+	hw_info = &md_ctrl->hw_info;
+	spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
+	t7xx_cldma_hw_irq_dis_eq(hw_info, CLDMA_ALL_Q, MTK_RX);
+	t7xx_cldma_hw_irq_dis_txrx(hw_info, CLDMA_ALL_Q, MTK_RX);
+	md_ctrl->rxq_active &= ~TXRX_STATUS_BITMASK;
+	t7xx_cldma_hw_stop_queue(hw_info, CLDMA_ALL_Q, MTK_RX);
+	t7xx_cldma_clear_ip_busy(hw_info);
+	t7xx_cldma_disable_irq(md_ctrl);
+	spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
+}
+
+static int t7xx_cldma_suspend(struct t7xx_pci_dev *t7xx_dev, void *entity_param)
+{
+	struct cldma_ctrl *md_ctrl = entity_param;
+	struct t7xx_cldma_hw *hw_info;
+	unsigned long flags;
+
+	if (md_ctrl->hif_id == ID_CLDMA1)
+		t7xx_mhccif_mask_set(t7xx_dev, D2H_SW_INT_MASK);
+
+	hw_info = &md_ctrl->hw_info;
+	spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
+	t7xx_cldma_hw_irq_dis_eq(hw_info, CLDMA_ALL_Q, MTK_TX);
+	t7xx_cldma_hw_irq_dis_txrx(hw_info, CLDMA_ALL_Q, MTK_TX);
+	md_ctrl->txq_active &= ~TXRX_STATUS_BITMASK;
+	t7xx_cldma_hw_stop_queue(hw_info, CLDMA_ALL_Q, MTK_TX);
+	md_ctrl->txq_started = 0;
+	spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
+	return 0;
+}
+
+static int t7xx_cldma_pm_init(struct cldma_ctrl *md_ctrl)
+{
+	md_ctrl->pm_entity = kzalloc(sizeof(*md_ctrl->pm_entity), GFP_KERNEL);
+	if (!md_ctrl->pm_entity)
+		return -ENOMEM;
+
+	md_ctrl->pm_entity->entity_param = md_ctrl;
+
+	if (md_ctrl->hif_id == ID_CLDMA1)
+		md_ctrl->pm_entity->id = PM_ENTITY_ID_CTRL1;
+	else
+		md_ctrl->pm_entity->id = PM_ENTITY_ID_CTRL2;
+
+	md_ctrl->pm_entity->suspend = t7xx_cldma_suspend;
+	md_ctrl->pm_entity->suspend_late = t7xx_cldma_suspend_late;
+	md_ctrl->pm_entity->resume = t7xx_cldma_resume;
+	md_ctrl->pm_entity->resume_early = t7xx_cldma_resume_early;
+
+	return t7xx_pci_pm_entity_register(md_ctrl->t7xx_dev, md_ctrl->pm_entity);
+}
+
+static int t7xx_cldma_pm_uninit(struct cldma_ctrl *md_ctrl)
+{
+	if (!md_ctrl->pm_entity)
+		return -EINVAL;
+
+	t7xx_pci_pm_entity_unregister(md_ctrl->t7xx_dev, md_ctrl->pm_entity);
+	kfree_sensitive(md_ctrl->pm_entity);
+	md_ctrl->pm_entity = NULL;
+	return 0;
+}
+
 void t7xx_cldma_hif_hw_init(struct cldma_ctrl *md_ctrl)
 {
 	struct t7xx_cldma_hw *hw_info = &md_ctrl->hw_info;
@@ -1248,6 +1359,7 @@ static irqreturn_t t7xx_cldma_isr_handler(int irq, void *data)
  * @md: Modem context structure.
  * @md_ctrl: CLDMA context structure.
  *
+ * Allocate and initialize device power management entity.
  * Initialize HIF TX/RX queue structure.
  * Register CLDMA callback ISR with PCIe driver.
  *
@@ -1258,12 +1370,16 @@ static irqreturn_t t7xx_cldma_isr_handler(int irq, void *data)
 int t7xx_cldma_init(struct t7xx_modem *md, struct cldma_ctrl *md_ctrl)
 {
 	struct t7xx_cldma_hw *hw_info = &md_ctrl->hw_info;
-	int i;
+	int ret, i;
 
 	md_ctrl->txq_active = 0;
 	md_ctrl->rxq_active = 0;
 	md_ctrl->is_late_init = false;
 
+	ret = t7xx_cldma_pm_init(md_ctrl);
+	if (ret)
+		return ret;
+
 	spin_lock_init(&md_ctrl->cldma_lock);
 	for (i = 0; i < CLDMA_TXQ_NUM; i++) {
 		md_cd_queue_struct_init(&md_ctrl->txq[i], md_ctrl, MTK_TX, i);
@@ -1325,4 +1441,6 @@ void t7xx_cldma_exit(struct cldma_ctrl *md_ctrl)
 			md_ctrl->rxq[i].worker = NULL;
 		}
 	}
+
+	t7xx_cldma_pm_uninit(md_ctrl);
 }
drivers/net/wwan/t7xx/t7xx_hif_cldma.h +1 -0
index 5db6d69373e3..964bf4df15ee 100644
@@ -85,6 +85,7 @@ struct cldma_ctrl {
 	struct dma_pool *gpd_dmapool;
 	struct cldma_ring tx_ring[CLDMA_TXQ_NUM];
 	struct cldma_ring rx_ring[CLDMA_RXQ_NUM];
+	struct md_pm_entity *pm_entity;
 	struct t7xx_cldma_hw hw_info;
 	bool is_late_init;
 	int (*recv_skb)(struct cldma_queue *queue, struct sk_buff *skb);
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c +90 -0

114 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h +1 -0
index cdb4706bb3ed..ef21ac87b028 100644
@@ -227,6 +227,7 @@ struct dpmaif_callbacks {
 struct dpmaif_ctrl {
 	struct device			*dev;
 	struct t7xx_pci_dev		*t7xx_dev;
+	struct md_pm_entity		dpmaif_pm_entity;
 	enum dpmaif_state		state;
 	bool				dpmaif_sw_init_done;
 	struct dpmaif_hw_info		hif_hw_info;
drivers/net/wwan/t7xx/t7xx_mhccif.c +17 -0
index 20aae457629c..74c79d520d88 100644
@@ -24,6 +24,11 @@
 #include "t7xx_pcie_mac.h"
 #include "t7xx_reg.h"
 
+#define D2H_INT_SR_ACK		(D2H_INT_SUSPEND_ACK |		\
+				 D2H_INT_RESUME_ACK |		\
+				 D2H_INT_SUSPEND_ACK_AP |	\
+				 D2H_INT_RESUME_ACK_AP)
+
 static void t7xx_mhccif_clear_interrupts(struct t7xx_pci_dev *t7xx_dev, u32 mask)
 {
 	void __iomem *mhccif_pbase = t7xx_dev->base_addr.mhccif_rc_base;
@@ -49,6 +54,18 @@ static irqreturn_t t7xx_mhccif_isr_thread(int irq, void *data)
 		t7xx_pci_mhccif_isr(t7xx_dev);
 
 	t7xx_mhccif_clear_interrupts(t7xx_dev, int_sts);
+
+	if (int_sts & D2H_INT_SR_ACK)
+		complete(&t7xx_dev->pm_sr_ack);
+
+	iowrite32(L1_DISABLE_BIT(1), IREG_BASE(t7xx_dev) + DIS_ASPM_LOWPWR_CLR_0);
+
+	int_sts = t7xx_mhccif_read_sw_int_sts(t7xx_dev);
+	if (!int_sts) {
+		val = L1_1_DISABLE_BIT(1) | L1_2_DISABLE_BIT(1);
+		iowrite32(val, IREG_BASE(t7xx_dev) + DIS_ASPM_LOWPWR_CLR_0);
+	}
+
 	t7xx_pcie_mac_set_int(t7xx_dev, MHCCIF_INT);
 	return IRQ_HANDLED;
 }
drivers/net/wwan/t7xx/t7xx_pci.c +426 -0

462 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_pci.h +46 -0

67 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_state_monitor.c +2 -0
index d09a64518b8b..b5c0752c9af8 100644
@@ -172,6 +172,7 @@ static void fsm_routine_exception(struct t7xx_fsm_ctl *ctl, struct t7xx_fsm_comm
 
 	case EXCEPTION_EVENT:
 		t7xx_fsm_broadcast_state(ctl, MD_STATE_EXCEPTION);
+		t7xx_pci_pm_exp_detected(ctl->md->t7xx_dev);
 		t7xx_md_exception_handshake(ctl->md);
 
 		cnt = 0;
@@ -320,6 +321,7 @@ static void fsm_routine_starting(struct t7xx_fsm_ctl *ctl)
 
 		fsm_routine_exception(ctl, NULL, EXCEPTION_HS_TIMEOUT);
 	} else {
+		t7xx_pci_pm_init_late(md->t7xx_dev);
 		fsm_routine_ready(ctl);
 	}
 }
Signature · 1 line
2.17.1
author reviewer
#32 lore raw

PATCH v3 10/12 net: wwan: t7xx: Runtime PM

In reply to Ricardo Martinez

From: Haijun Liu <[email protected]>

Enables runtime power management callbacks including runtime_suspend and runtime_resume. Autosuspend is used to prevent overhead by frequent wake-ups.

---
 drivers/net/wwan/t7xx/t7xx_hif_cldma.c     | 13 +++++++++++++
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 16 ++++++++++++++++
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c | 15 +++++++++++++++
 drivers/net/wwan/t7xx/t7xx_pci.c           | 21 +++++++++++++++++++++
 4 files changed, 65 insertions(+)
drivers/net/wwan/t7xx/t7xx_hif_cldma.c +13 -0
index 8f35e6e43504..cdeb79bb006e 100644
@@ -34,6 +34,7 @@
 #include <linux/list.h>
 #include <linux/netdevice.h>
 #include <linux/pci.h>
+#include <linux/pm_runtime.h>
 #include <linux/sched.h>
 #include <linux/skbuff.h>
 #include <linux/slab.h>
@@ -274,6 +275,8 @@ static void t7xx_cldma_rx_done(struct work_struct *work)
 	t7xx_cldma_clear_ip_busy(&md_ctrl->hw_info);
 	t7xx_cldma_hw_irq_en_txrx(&md_ctrl->hw_info, queue->index, MTK_RX);
 	t7xx_cldma_hw_irq_en_eq(&md_ctrl->hw_info, queue->index, MTK_RX);
+	pm_runtime_mark_last_busy(md_ctrl->dev);
+	pm_runtime_put_autosuspend(md_ctrl->dev);
 }
 
 static int t7xx_cldma_gpd_tx_collect(struct cldma_queue *queue)
@@ -390,6 +393,8 @@ static void t7xx_cldma_tx_done(struct work_struct *work)
 	}
 
 	spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
+	pm_runtime_mark_last_busy(md_ctrl->dev);
+	pm_runtime_put_autosuspend(md_ctrl->dev);
 }
 
 static void t7xx_cldma_ring_free(struct cldma_ctrl *md_ctrl,
@@ -599,6 +604,7 @@ static void t7xx_cldma_irq_work_cb(struct cldma_ctrl *md_ctrl)
 		if (l2_tx_int & (TXRX_STATUS_BITMASK | EMPTY_STATUS_BITMASK)) {
 			for_each_set_bit(i, (unsigned long *)&l2_tx_int, L2_INT_BIT_COUNT) {
 				if (i < CLDMA_TXQ_NUM) {
+					pm_runtime_get(md_ctrl->dev);
 					t7xx_cldma_hw_irq_dis_eq(hw_info, i, MTK_TX);
 					t7xx_cldma_hw_irq_dis_txrx(hw_info, i, MTK_TX);
 					queue_work(md_ctrl->txq[i].worker,
@@ -623,6 +629,7 @@ static void t7xx_cldma_irq_work_cb(struct cldma_ctrl *md_ctrl)
 		if (l2_rx_int & (TXRX_STATUS_BITMASK | EMPTY_STATUS_BITMASK)) {
 			l2_rx_int |=  l2_rx_int >> CLDMA_RXQ_NUM;
 			for_each_set_bit(i, (unsigned long *)&l2_rx_int, CLDMA_RXQ_NUM) {
+				pm_runtime_get(md_ctrl->dev);
 				t7xx_cldma_hw_irq_dis_eq(hw_info, i, MTK_RX);
 				t7xx_cldma_hw_irq_dis_txrx(hw_info, i, MTK_RX);
 				queue_work(md_ctrl->rxq[i].worker, &md_ctrl->rxq[i].cldma_work);
@@ -986,6 +993,10 @@ int t7xx_cldma_send_skb(struct cldma_ctrl *md_ctrl, int qno, struct sk_buff *skb
 	if (qno >= CLDMA_TXQ_NUM)
 		return -EINVAL;
 
+	ret = pm_runtime_resume_and_get(md_ctrl->dev);
+	if (ret < 0 && ret != -EACCES)
+		return ret;
+
 	queue = &md_ctrl->txq[qno];
 
 	spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
@@ -1033,6 +1044,8 @@ int t7xx_cldma_send_skb(struct cldma_ctrl *md_ctrl, int qno, struct sk_buff *skb
 	} while (!ret);
 
 allow_sleep:
+	pm_runtime_mark_last_busy(md_ctrl->dev);
+	pm_runtime_put_autosuspend(md_ctrl->dev);
 	return ret;
 }
 
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +16 -0
index ce73081470f6..710e4727ea84 100644
@@ -32,6 +32,7 @@
 #include <linux/list.h>
 #include <linux/mm.h>
 #include <linux/netdevice.h>
+#include <linux/pm_runtime.h>
 #include <linux/sched.h>
 #include <linux/skbuff.h>
 #include <linux/slab.h>
@@ -912,6 +913,7 @@ static void t7xx_dpmaif_rxq_work(struct work_struct *work)
 {
 	struct dpmaif_rx_queue *rxq = container_of(work, struct dpmaif_rx_queue, dpmaif_rxq_work);
 	struct dpmaif_ctrl *dpmaif_ctrl = rxq->dpmaif_ctrl;
+	int ret;
 
 	atomic_set(&rxq->rx_processing, 1);
 	/* Ensure rx_processing is changed to 1 before actually begin RX flow */
@@ -923,8 +925,14 @@ static void t7xx_dpmaif_rxq_work(struct work_struct *work)
 		return;
 	}
 
+	ret = pm_runtime_resume_and_get(dpmaif_ctrl->dev);
+	if (ret < 0 && ret != -EACCES)
+		return;
+
 	t7xx_dpmaif_do_rx(dpmaif_ctrl, rxq);
 
+	pm_runtime_mark_last_busy(dpmaif_ctrl->dev);
+	pm_runtime_put_autosuspend(dpmaif_ctrl->dev);
 	atomic_set(&rxq->rx_processing, 0);
 }
 
@@ -1154,11 +1162,19 @@ static void t7xx_dpmaif_bat_release_work(struct work_struct *work)
 {
 	struct dpmaif_ctrl *dpmaif_ctrl = container_of(work, struct dpmaif_ctrl, bat_release_work);
 	struct dpmaif_rx_queue *rxq;
+	int ret;
+
+	ret = pm_runtime_resume_and_get(dpmaif_ctrl->dev);
+	if (ret < 0 && ret != -EACCES)
+		return;
 
 	/* ALL RXQ use one BAT table, so choose DPF_RX_QNO_DFT */
 	rxq = &dpmaif_ctrl->rxq[DPF_RX_QNO_DFT];
 	t7xx_dpmaif_bat_release_and_add(rxq);
 	t7xx_dpmaif_frag_bat_release_and_add(rxq);
+
+	pm_runtime_mark_last_busy(dpmaif_ctrl->dev);
+	pm_runtime_put_autosuspend(dpmaif_ctrl->dev);
 }
 
 int t7xx_dpmaif_bat_rel_wq_alloc(struct dpmaif_ctrl *dpmaif_ctrl)
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c +15 -0
index fc6e04edc5ea..f8e7a10273a4 100644
@@ -29,6 +29,7 @@
 #include <linux/list.h>
 #include <linux/minmax.h>
 #include <linux/netdevice.h>
+#include <linux/pm_runtime.h>
 #include <linux/sched.h>
 #include <linux/spinlock.h>
 #include <linux/skbuff.h>
@@ -170,6 +171,10 @@ static void t7xx_dpmaif_tx_done(struct work_struct *work)
 	struct dpmaif_ctrl *dpmaif_ctrl = txq->dpmaif_ctrl;
 	int ret;
 
+	ret = pm_runtime_resume_and_get(dpmaif_ctrl->dev);
+	if (ret < 0 && ret != -EACCES)
+		return;
+
 	ret = t7xx_dpmaif_tx_release(dpmaif_ctrl, txq->index, txq->drb_size_cnt);
 	if (ret == -EAGAIN ||
 	    (t7xx_dpmaif_ul_clr_done(&dpmaif_ctrl->hif_hw_info, txq->index) &&
@@ -182,6 +187,9 @@ static void t7xx_dpmaif_tx_done(struct work_struct *work)
 		t7xx_dpmaif_clr_ip_busy_sts(&dpmaif_ctrl->hif_hw_info);
 		t7xx_dpmaif_unmask_ulq_intr(dpmaif_ctrl, txq->index);
 	}
+
+	pm_runtime_mark_last_busy(dpmaif_ctrl->dev);
+	pm_runtime_put_autosuspend(dpmaif_ctrl->dev);
 }
 
 static void t7xx_setup_msg_drb(struct dpmaif_ctrl *dpmaif_ctrl, unsigned char q_num,
@@ -457,6 +465,7 @@ static void t7xx_do_tx_hw_push(struct dpmaif_ctrl *dpmaif_ctrl)
 static int t7xx_dpmaif_tx_hw_push_thread(void *arg)
 {
 	struct dpmaif_ctrl *dpmaif_ctrl = arg;
+	int ret;
 
 	while (!kthread_should_stop()) {
 		if (t7xx_tx_lists_are_all_empty(dpmaif_ctrl) ||
@@ -470,7 +479,13 @@ static int t7xx_dpmaif_tx_hw_push_thread(void *arg)
 				break;
 		}
 
+		ret = pm_runtime_resume_and_get(dpmaif_ctrl->dev);
+		if (ret < 0 && ret != -EACCES)
+			return ret;
+
 		t7xx_do_tx_hw_push(dpmaif_ctrl);
+		pm_runtime_mark_last_busy(dpmaif_ctrl->dev);
+		pm_runtime_put_autosuspend(dpmaif_ctrl->dev);
 	}
 
 	return 0;
drivers/net/wwan/t7xx/t7xx_pci.c +21 -0
index 546f22aa555f..a1a0824c1e11 100644
@@ -32,6 +32,7 @@
 #include <linux/mutex.h>
 #include <linux/pci.h>
 #include <linux/pm.h>
+#include <linux/pm_runtime.h>
 #include <linux/pm_wakeup.h>
 
 #include "t7xx_mhccif.h"
@@ -45,6 +46,7 @@
 #define PCI_EREG_BASE			2
 
 #define PM_ACK_TIMEOUT_MS		1500
+#define PM_AUTOSUSPEND_MS		20000
 #define PM_RESOURCE_POLL_TIMEOUT_US	10000
 #define PM_RESOURCE_POLL_STEP_US	100
 
@@ -87,6 +89,8 @@ static int t7xx_pci_pm_init(struct t7xx_pci_dev *t7xx_dev)
 	atomic_set(&t7xx_dev->md_pm_state, MTK_PM_INIT);
 
 	iowrite32(L1_DISABLE_BIT(0), IREG_BASE(t7xx_dev) + DIS_ASPM_LOWPWR_SET_0);
+	pm_runtime_set_autosuspend_delay(&pdev->dev, PM_AUTOSUSPEND_MS);
+	pm_runtime_use_autosuspend(&pdev->dev);
 
 	return t7xx_wait_pm_config(t7xx_dev);
 }
@@ -101,6 +105,8 @@ void t7xx_pci_pm_init_late(struct t7xx_pci_dev *t7xx_dev)
 			     D2H_INT_RESUME_ACK_AP);
 	iowrite32(L1_DISABLE_BIT(0), IREG_BASE(t7xx_dev) + DIS_ASPM_LOWPWR_CLR_0);
 	atomic_set(&t7xx_dev->md_pm_state, MTK_PM_RESUMED);
+
+	pm_runtime_put_noidle(&t7xx_dev->pdev->dev);
 }
 
 static int t7xx_pci_pm_reinit(struct t7xx_pci_dev *t7xx_dev)
@@ -110,6 +116,8 @@ static int t7xx_pci_pm_reinit(struct t7xx_pci_dev *t7xx_dev)
 	 */
 	atomic_set(&t7xx_dev->md_pm_state, MTK_PM_INIT);
 
+	pm_runtime_get_noresume(&t7xx_dev->pdev->dev);
+
 	iowrite32(L1_DISABLE_BIT(0), IREG_BASE(t7xx_dev) + DIS_ASPM_LOWPWR_SET_0);
 	return t7xx_wait_pm_config(t7xx_dev);
 }
@@ -404,6 +412,7 @@ static int __t7xx_pci_pm_resume(struct pci_dev *pdev, bool state_check)
 	t7xx_dev->rgu_pci_irq_en = true;
 	t7xx_pcie_mac_set_int(t7xx_dev, SAP_RGU_INT);
 	iowrite32(L1_DISABLE_BIT(0), IREG_BASE(t7xx_dev) + DIS_ASPM_LOWPWR_CLR_0);
+	pm_runtime_mark_last_busy(&pdev->dev);
 	atomic_set(&t7xx_dev->md_pm_state, MTK_PM_RESUMED);
 
 	return ret;
@@ -445,6 +454,16 @@ static int t7xx_pci_pm_thaw(struct device *dev)
 	return __t7xx_pci_pm_resume(to_pci_dev(dev), false);
 }
 
+static int t7xx_pci_pm_runtime_suspend(struct device *dev)
+{
+	return __t7xx_pci_pm_suspend(to_pci_dev(dev));
+}
+
+static int t7xx_pci_pm_runtime_resume(struct device *dev)
+{
+	return __t7xx_pci_pm_resume(to_pci_dev(dev), true);
+}
+
 static const struct dev_pm_ops t7xx_pci_pm_ops = {
 	.suspend = t7xx_pci_pm_suspend,
 	.resume = t7xx_pci_pm_resume,
@@ -454,6 +473,8 @@ static const struct dev_pm_ops t7xx_pci_pm_ops = {
 	.poweroff = t7xx_pci_pm_suspend,
 	.restore = t7xx_pci_pm_resume,
 	.restore_noirq = t7xx_pci_pm_resume_noirq,
+	.runtime_suspend = t7xx_pci_pm_runtime_suspend,
+	.runtime_resume = t7xx_pci_pm_runtime_resume
 };
 
 static int t7xx_request_irq(struct pci_dev *pdev)
Signature · 1 line
2.17.1
author reviewer
#33 lore raw

PATCH v3 11/12 net: wwan: t7xx: Device deep sleep lock/unlock

In reply to Ricardo Martinez

From: Haijun Liu <[email protected]>

Introduce the mechanism to lock/unlock the device 'deep sleep' mode. When the PCIe link state is L1.2 or L2, the host side still can keep the device is in D0 state from the host side point of view. At the same time, if the device's 'deep sleep' mode is unlocked, the device will go to 'deep sleep' while it is still in D0 state on the host side.

---
 drivers/net/wwan/t7xx/t7xx_hif_cldma.c     | 12 +++
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 14 +++-
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c | 37 ++++++---
 drivers/net/wwan/t7xx/t7xx_mhccif.c        |  3 +
 drivers/net/wwan/t7xx/t7xx_pci.c           | 97 ++++++++++++++++++++++
 drivers/net/wwan/t7xx/t7xx_pci.h           | 10 +++
 6 files changed, 159 insertions(+), 14 deletions(-)
drivers/net/wwan/t7xx/t7xx_hif_cldma.c +12 -0
index cdeb79bb006e..7b8c135600cf 100644
@@ -997,6 +997,7 @@ int t7xx_cldma_send_skb(struct cldma_ctrl *md_ctrl, int qno, struct sk_buff *skb
 	if (ret < 0 && ret != -EACCES)
 		return ret;
 
+	t7xx_pci_disable_sleep(md_ctrl->t7xx_dev);
 	queue = &md_ctrl->txq[qno];
 
 	spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
@@ -1017,6 +1018,11 @@ int t7xx_cldma_send_skb(struct cldma_ctrl *md_ctrl, int qno, struct sk_buff *skb
 			queue->tx_xmit = t7xx_cldma_ring_step_forward(queue->tr_ring, tx_req);
 			spin_unlock_irqrestore(&queue->ring_lock, flags);
 
+			if (!t7xx_pci_sleep_disable_complete(md_ctrl->t7xx_dev)) {
+				ret = -EBUSY;
+				break;
+			}
+
 			/* Protect the access to the modem for queues operations (resume/start)
 			 * which access shared locations by all the queues.
 			 * cldma_lock is independent of ring_lock which is per queue.
@@ -1029,6 +1035,11 @@ int t7xx_cldma_send_skb(struct cldma_ctrl *md_ctrl, int qno, struct sk_buff *skb
 
 		spin_unlock_irqrestore(&queue->ring_lock, flags);
 
+		if (!t7xx_pci_sleep_disable_complete(md_ctrl->t7xx_dev)) {
+			ret = -EBUSY;
+			break;
+		}
+
 		if (!t7xx_cldma_hw_queue_status(&md_ctrl->hw_info, qno, MTK_TX)) {
 			spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
 			t7xx_cldma_hw_resume_queue(&md_ctrl->hw_info, qno, MTK_TX);
@@ -1044,6 +1055,7 @@ int t7xx_cldma_send_skb(struct cldma_ctrl *md_ctrl, int qno, struct sk_buff *skb
 	} while (!ret);
 
 allow_sleep:
+	t7xx_pci_enable_sleep(md_ctrl->t7xx_dev);
 	pm_runtime_mark_last_busy(md_ctrl->dev);
 	pm_runtime_put_autosuspend(md_ctrl->dev);
 	return ret;
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +11 -3
index 710e4727ea84..1a4694f405ea 100644
@@ -929,8 +929,11 @@ static void t7xx_dpmaif_rxq_work(struct work_struct *work)
 	if (ret < 0 && ret != -EACCES)
 		return;
 
-	t7xx_dpmaif_do_rx(dpmaif_ctrl, rxq);
+	t7xx_pci_disable_sleep(dpmaif_ctrl->t7xx_dev);
+	if (t7xx_pci_sleep_disable_complete(dpmaif_ctrl->t7xx_dev))
+		t7xx_dpmaif_do_rx(dpmaif_ctrl, rxq);
 
+	t7xx_pci_enable_sleep(dpmaif_ctrl->t7xx_dev);
 	pm_runtime_mark_last_busy(dpmaif_ctrl->dev);
 	pm_runtime_put_autosuspend(dpmaif_ctrl->dev);
 	atomic_set(&rxq->rx_processing, 0);
@@ -1168,11 +1171,16 @@ static void t7xx_dpmaif_bat_release_work(struct work_struct *work)
 	if (ret < 0 && ret != -EACCES)
 		return;
 
+	t7xx_pci_disable_sleep(dpmaif_ctrl->t7xx_dev);
+
 	/* ALL RXQ use one BAT table, so choose DPF_RX_QNO_DFT */
 	rxq = &dpmaif_ctrl->rxq[DPF_RX_QNO_DFT];
-	t7xx_dpmaif_bat_release_and_add(rxq);
-	t7xx_dpmaif_frag_bat_release_and_add(rxq);
+	if (t7xx_pci_sleep_disable_complete(dpmaif_ctrl->t7xx_dev)) {
+		t7xx_dpmaif_bat_release_and_add(rxq);
+		t7xx_dpmaif_frag_bat_release_and_add(rxq);
+	}
 
+	t7xx_pci_enable_sleep(dpmaif_ctrl->t7xx_dev);
 	pm_runtime_mark_last_busy(dpmaif_ctrl->dev);
 	pm_runtime_put_autosuspend(dpmaif_ctrl->dev);
 }
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c +26 -11
index f8e7a10273a4..17f473d8e5ae 100644
@@ -175,19 +175,24 @@ static void t7xx_dpmaif_tx_done(struct work_struct *work)
 	if (ret < 0 && ret != -EACCES)
 		return;
 
-	ret = t7xx_dpmaif_tx_release(dpmaif_ctrl, txq->index, txq->drb_size_cnt);
-	if (ret == -EAGAIN ||
-	    (t7xx_dpmaif_ul_clr_done(&dpmaif_ctrl->hif_hw_info, txq->index) &&
-	     t7xx_dpmaif_drb_ring_not_empty(txq))) {
-		queue_work(dpmaif_ctrl->txq[txq->index].worker,
-			   &dpmaif_ctrl->txq[txq->index].dpmaif_tx_work);
-		/* Give the device time to enter the low power state */
-		t7xx_dpmaif_clr_ip_busy_sts(&dpmaif_ctrl->hif_hw_info);
-	} else {
-		t7xx_dpmaif_clr_ip_busy_sts(&dpmaif_ctrl->hif_hw_info);
-		t7xx_dpmaif_unmask_ulq_intr(dpmaif_ctrl, txq->index);
+	/* The device may be in low power state. Disable sleep if needed */
+	t7xx_pci_disable_sleep(dpmaif_ctrl->t7xx_dev);
+	if (t7xx_pci_sleep_disable_complete(dpmaif_ctrl->t7xx_dev)) {
+		ret = t7xx_dpmaif_tx_release(dpmaif_ctrl, txq->index, txq->drb_size_cnt);
+		if (ret == -EAGAIN ||
+		    (t7xx_dpmaif_ul_clr_done(&dpmaif_ctrl->hif_hw_info, txq->index) &&
+		     t7xx_dpmaif_drb_ring_not_empty(txq))) {
+			queue_work(dpmaif_ctrl->txq[txq->index].worker,
+				   &dpmaif_ctrl->txq[txq->index].dpmaif_tx_work);
+			/* Give the device time to enter the low power state */
+			t7xx_dpmaif_clr_ip_busy_sts(&dpmaif_ctrl->hif_hw_info);
+		} else {
+			t7xx_dpmaif_clr_ip_busy_sts(&dpmaif_ctrl->hif_hw_info);
+			t7xx_dpmaif_unmask_ulq_intr(dpmaif_ctrl, txq->index);
+		}
 	}
 
+	t7xx_pci_enable_sleep(dpmaif_ctrl->t7xx_dev);
 	pm_runtime_mark_last_busy(dpmaif_ctrl->dev);
 	pm_runtime_put_autosuspend(dpmaif_ctrl->dev);
 }
@@ -429,6 +434,8 @@ static bool t7xx_check_all_txq_drb_lack(const struct dpmaif_ctrl *dpmaif_ctrl)
 
 static void t7xx_do_tx_hw_push(struct dpmaif_ctrl *dpmaif_ctrl)
 {
+	bool first_time = true;
+
 	dpmaif_ctrl->txq_select_times = 0;
 	do {
 		int txq_id;
@@ -444,6 +451,11 @@ static void t7xx_do_tx_hw_push(struct dpmaif_ctrl *dpmaif_ctrl)
 			if (ret > 0) {
 				int drb_send_cnt = ret;
 
+				/* Wait for the PCIe resource to unlock */
+				if (first_time &&
+				    !t7xx_pci_sleep_disable_complete(dpmaif_ctrl->t7xx_dev))
+					return;
+
 				ret = t7xx_dpmaif_ul_update_hw_drb_cnt(dpmaif_ctrl,
 								       (unsigned char)txq_id,
 								       drb_send_cnt *
@@ -457,6 +469,7 @@ static void t7xx_do_tx_hw_push(struct dpmaif_ctrl *dpmaif_ctrl)
 			}
 		}
 
+		first_time = false;
 		cond_resched();
 	} while (!t7xx_tx_lists_are_all_empty(dpmaif_ctrl) && !kthread_should_stop() &&
 		 (dpmaif_ctrl->state == DPMAIF_STATE_PWRON));
@@ -483,7 +496,9 @@ static int t7xx_dpmaif_tx_hw_push_thread(void *arg)
 		if (ret < 0 && ret != -EACCES)
 			return ret;
 
+		t7xx_pci_disable_sleep(dpmaif_ctrl->t7xx_dev);
 		t7xx_do_tx_hw_push(dpmaif_ctrl);
+		t7xx_pci_enable_sleep(dpmaif_ctrl->t7xx_dev);
 		pm_runtime_mark_last_busy(dpmaif_ctrl->dev);
 		pm_runtime_put_autosuspend(dpmaif_ctrl->dev);
 	}
drivers/net/wwan/t7xx/t7xx_mhccif.c +3 -0
index 74c79d520d88..da076416da10 100644
@@ -55,6 +55,9 @@ static irqreturn_t t7xx_mhccif_isr_thread(int irq, void *data)
 
 	t7xx_mhccif_clear_interrupts(t7xx_dev, int_sts);
 
+	if (int_sts & D2H_INT_DS_LOCK_ACK)
+		complete_all(&t7xx_dev->sleep_lock_acquire);
+
 	if (int_sts & D2H_INT_SR_ACK)
 		complete(&t7xx_dev->pm_sr_ack);
 
drivers/net/wwan/t7xx/t7xx_pci.c +97 -0

137 lines not on this page · raw message

drivers/net/wwan/t7xx/t7xx_pci.h +10 -0
index 6310f31540ca..90d358bff54c 100644
@@ -21,6 +21,7 @@
 #include <linux/irqreturn.h>
 #include <linux/mutex.h>
 #include <linux/pci.h>
+#include <linux/spinlock.h>
 #include <linux/types.h>
 
 #include "t7xx_reg.h"
@@ -51,7 +52,10 @@ typedef irqreturn_t (*t7xx_intr_callback)(int irq, void *param);
  * @base_addr: memory base addresses of HW components
  * @md: modem interface
  * @md_pm_entities: list of pm entities
+ * @md_pm_lock: protects PCIe sleep lock
  * @md_pm_entity_mtx: protects md_pm_entities list
+ * @sleep_disable_count: PCIe L1.2 lock counter
+ * @sleep_lock_acquire: indicates that sleep has been disabled
  * @pm_sr_ack: ack from the device when went to sleep or woke up
  * @md_pm_state: state for resume/suspend
  * @ccmni_ctlb: context structure used to control the network data path
@@ -69,7 +73,10 @@ struct t7xx_pci_dev {
 
 	/* Low Power Items */
 	struct list_head	md_pm_entities;
+	spinlock_t		md_pm_lock;		/* Protects PCI resource lock */
 	struct mutex		md_pm_entity_mtx;	/* Protects MD PM entities list */
+	atomic_t		sleep_disable_count;
+	struct completion	sleep_lock_acquire;
 	struct completion	pm_sr_ack;
 	atomic_t		md_pm_state;
 
@@ -105,6 +112,9 @@ struct md_pm_entity {
 	void			*entity_param;
 };
 
+void t7xx_pci_disable_sleep(struct t7xx_pci_dev *t7xx_dev);
+void t7xx_pci_enable_sleep(struct t7xx_pci_dev *t7xx_dev);
+int t7xx_pci_sleep_disable_complete(struct t7xx_pci_dev *t7xx_dev);
 int t7xx_pci_pm_entity_register(struct t7xx_pci_dev *t7xx_dev, struct md_pm_entity *pm_entity);
 int t7xx_pci_pm_entity_unregister(struct t7xx_pci_dev *t7xx_dev, struct md_pm_entity *pm_entity);
 void t7xx_pci_pm_init_late(struct t7xx_pci_dev *t7xx_dev);
Signature · 1 line
2.17.1
author reviewer
#34 lore raw

PATCH v3 12/12 net: wwan: t7xx: Add maintainers and documentation

In reply to Ricardo Martinez

Adds maintainers and documentation for MediaTek t7xx 5G WWAN modem device driver.

---
 .../networking/device_drivers/wwan/index.rst  |   1 +
 .../networking/device_drivers/wwan/t7xx.rst   | 120 ++++++++++++++++++
 MAINTAINERS                                   |  11 ++
 3 files changed, 132 insertions(+)
 create mode 100644 Documentation/networking/device_drivers/wwan/t7xx.rst
Documentation/networking/device_drivers/wwan/index.rst +1 -0
index 1cb8c7371401..370d8264d5dc 100644
@@ -9,6 +9,7 @@ Contents:
    :maxdepth: 2
 
    iosm
+   t7xx
 
 .. only::  subproject and html
 
Documentation/networking/device_drivers/wwan/t7xx.rst new file +120 -0

120 lines not on this page · raw message

MAINTAINERS +11 -0
index 79ef55bf2ca7..a1dfc9beaf7a 100644
@@ -12156,6 +12156,17 @@ S:	Maintained
 F:	drivers/net/dsa/mt7530.*
 F:	net/dsa/tag_mtk.c
 
+MEDIATEK T7XX 5G WWAN MODEM DRIVER
+M:	Chandrashekar Devegowda <[email protected]>
+M:	Intel Corporation <[email protected]>
+R:	Chiranjeevi Rapolu <[email protected]>
+R:	Liu Haijun <[email protected]>
+R:	M Chetan Kumar <[email protected]>
+R:	Ricardo Martinez <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	drivers/net/wwan/t7xx/
+
 MEDIATEK USB3 DRD IP DRIVER
 M:	Chunfeng Yun <[email protected]>
 L:	[email protected]
Signature · 1 line
2.17.1