net: wwan: t7xx: PCIe driver for MediaTek M.2 modem
Subsystems (5)
Ricardo Martinez
reviewerv5 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 code in close collaboration with MediaTek. This will enable getting the t7xx driver on the 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]> Madhusmita Sahu <[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
v5:
- Update Intel's copyright years to 2021-2022.
- Remove circular dependency between DPMAIF HW (07) and HIF (08).
- Keep separate patches for CLDMA (02) and Core (03)
but improve the code split by decoupling CLDMA from
modem ops and cleaning up t7xx_common.h.
- Rename ID_CLDMA0/ID_CLDMA1 to CLDMA_ID_AP/CLDMA_ID_MD.
- Consistently use CLDMA's ring_lock to protect tr_ring.
- Free resources first and then print messages.
- Implement suggested name changes.
- Do not explicitly include dev_printk.h.
- Remove redundant dev_err()s.
- Fix possible memory leak during probe.
- Remove infrastructure for legacy interrupts.
- Remove unused macros and variables, including those that
can be replaced with constants.
- Remove PCIE_MAC_MSIX_MSK_SET macro which is duplicated code.
- Refactor __t7xx_pci_pm_suspend() for clarity.
- Refactor t7xx_cldma_rx_ring_init() and t7xx_cldma_tx_ring_init().
- Do not use & for function callbacks.
- Declare a structure to access skb->cb[] data.
- Use skb_put_data instead of memcpy.
- No need to use kfree_sensitive.
- Use dev_kfree_skb() instead of kfree_skb().
- Refactor t7xx_prepare_device_rt_data() to remove potential leaks, avoid unneeded memset and keep rt_data and packet_size updates inside the same 'if' block.
- Set port's rx_length_th back to 0 during uninit.
- Remove unneeded 'blocking' parameter from t7xx_cldma_send_skb().
- Return -EIO in t7xx_cldma_send_skb() if the queue is inactive.
- Refactor t7xx_cldma_qs_are_active() to use pci_device_is_present().
- Simplify t7xx_cldma_stop_q() and rename it to t7xx_cldma_stop_all_qs().
- Fix potential leaks in t7xx_cldma_init().
- Improve error handling in fsm_append_event and fsm_routine_starting().
- Propagate return codes from fsm_append_cmd() and t7xx_fsm_append_event().
- Refactor fsm_wait_for_event() to avoid unnecessary sleep.
- Create the WWAN ports and net device only after the modem is in the ready state.
- Refactor t7xx_port_proxy_recv_skb() and port_recv_skb().
- Rename t7xx_port_check_rx_seq_num() as t7xx_port_next_rx_seq_num() and fix the seq_num logic to handle overflows.
- Declare seq_nums as u16 instead of short.
- Use unsigned int for local indexes.
- Use min_t instead of the ternary operator.
- Refactor the loop in t7xx_dpmaif_rx_data_collect() to avoid a dead condition check.
- Use a bitmap (bat_bitmap) instead of an array to keep track of the DRB status. Used in t7xx_dpmaif_avail_pkt_bat_cnt().
- Refactor t7xx_dpmaif_tx_send_skb() to protect tx_submit_skb_cnt with spinlock and remove the misleading tx_drb_available variable.
- Consolidate bit operations before endianness conversion.
- Use C bit fields in dpmaif_drb_skb struct which is not HW related.
- Add back the que_started check in t7xx_select_tx_queue().
- Create a helper function to get the DRB count.
- Simplify the use of 'usage' during t7xx_ccmni_close().
- Enforce CCMNI MTU selection with BUILD_BUG_ON() instead of a comment.
- Remove t7xx_ccmni_ctrl->capability parameter which remains constant.
v4:
- Implement list_prev_entry_circular() and list_next_entry_circular() macros.
- Remove inline from all c files.
- Define ioread32_poll_timeout_atomic() helper macro.
- Fix return code for WWAN port tx op.
- Allow AT commands fragmentation same as MBIM commands.
- Introduce t7xx_common.h file in the first patch.
- Rename functions and variables as suggested in v3.
- Reduce code duplication by creating fsm_wait_for_event() helper function.
- Remove unneeded dev_err in t7xx_fsm_clr_event().
- Remove unused variable last_state from struct t7xx_fsm_ctl.
- Remove unused variable txq_select_times from struct dpmaif_ctrl.
- Replace ETXTBSY with EBUSY.
- Refactor t7xx_dpmaif_rx_buf_alloc() to remove an unneeded allocation.
- Fix potential leak at t7xx_dpmaif_rx_frag_alloc().
- Simplify return value handling at t7xx_dpmaif_rx_start().
- Add a helper to handle the common part of CCCI header initialization.
- Make sure interrupts are enabled during PM resume.
- Add a parameter to t7xx_fsm_append_cmd() to tell if it is in interrupt context.
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
__ffs64v2:
- 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 (13):
list: Add list_next_entry_circular() and list_prev_entry_circular()
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
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 | 281 ++++ drivers/net/wwan/t7xx/t7xx_cldma.h | 176 +++ drivers/net/wwan/t7xx/t7xx_common.h | 66 + drivers/net/wwan/t7xx/t7xx_dpmaif.c | 1294 ++++++++++++++++ drivers/net/wwan/t7xx/t7xx_dpmaif.h | 179 +++ drivers/net/wwan/t7xx/t7xx_hif_cldma.c | 1351 +++++++++++++++++ drivers/net/wwan/t7xx/t7xx_hif_cldma.h | 142 ++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c | 574 +++++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h | 211 +++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 1248 +++++++++++++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h | 114 ++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c | 729 +++++++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.h | 84 + drivers/net/wwan/t7xx/t7xx_mhccif.c | 122 ++ drivers/net/wwan/t7xx/t7xx_mhccif.h | 37 + drivers/net/wwan/t7xx/t7xx_modem_ops.c | 764 ++++++++++ drivers/net/wwan/t7xx/t7xx_modem_ops.h | 87 ++ drivers/net/wwan/t7xx/t7xx_netdev.c | 430 ++++++ drivers/net/wwan/t7xx/t7xx_netdev.h | 56 + drivers/net/wwan/t7xx/t7xx_pci.c | 768 ++++++++++ drivers/net/wwan/t7xx/t7xx_pci.h | 122 ++ drivers/net/wwan/t7xx/t7xx_pcie_mac.c | 263 ++++ drivers/net/wwan/t7xx/t7xx_pcie_mac.h | 31 + drivers/net/wwan/t7xx/t7xx_port.h | 149 ++ drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c | 205 +++ drivers/net/wwan/t7xx/t7xx_port_proxy.c | 621 ++++++++ drivers/net/wwan/t7xx/t7xx_port_proxy.h | 100 ++ drivers/net/wwan/t7xx/t7xx_port_wwan.c | 210 +++ drivers/net/wwan/t7xx/t7xx_reg.h | 352 +++++ drivers/net/wwan/t7xx/t7xx_state_monitor.c | 550 +++++++ drivers/net/wwan/t7xx/t7xx_state_monitor.h | 125 ++ include/linux/list.h | 26 + 38 files changed, 11634 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
Ricardo Martinez
reviewerPATCH v5 1/13 list: Add list_next_entry_circular() and list_prev_entry_circular()
Add macros to get the next or previous entries and wraparound if needed. For example, calling list_next_entry_circular() on the last element should return the first element in the list.
--- include/linux/list.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
include/linux/list.h +26 -0
@@ -563,6 +563,19 @@ static inline void list_splice_tail_init(struct list_head *list,#define list_next_entry (pos, member) \ list_entry((pos)->member.next, typeof(*(pos)), member) +/** +* list_next_entry_circular - get the next element in list +* @pos: the type * to cursor. +* @head: the list head to take the element from. +* @member: the name of the list_head within the struct. +* +* Wraparound if pos is the last element (return the first element). +* Note, that list is expected to be not empty. +*/ +#define list_next_entry_circular (pos, head, member) \ + (list_is_last(&(pos)->member, head) ? \ + list_first_entry(head, typeof(*(pos)), member) : list_next_entry(pos, member)) +/** * list_prev_entry - get the prev element in list * @pos: the type * to cursor
@@ -571,6 +584,19 @@ static inline void list_splice_tail_init(struct list_head *list,#define list_prev_entry (pos, member) \ list_entry((pos)->member.prev, typeof(*(pos)), member) +/** +* list_prev_entry_circular - get the prev element in list +* @pos: the type * to cursor. +* @head: the list head to take the element from. +* @member: the name of the list_head within the struct. +* +* Wraparound if pos is the first element (return the last element). +* Note, that list is expected to be not empty. +*/ +#define list_prev_entry_circular (pos, head, member) \ + (list_is_first(&(pos)->member, head) ? \ + list_last_entry(head, typeof(*(pos)), member) : list_prev_entry(pos, member)) +/** * list_for_each - iterate over a list * @pos: the &struct list_head to use as a loop cursor.
Signature · 1 line
2.17.1
Ricardo Martinez
reviewerPATCH v5 2/13 net: wwan: t7xx: Add control DMA interface
In reply to Ricardo MartinezFrom: 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
From a WWAN framework perspective:
--- drivers/net/wwan/t7xx/t7xx_cldma.c | 281 ++++++ drivers/net/wwan/t7xx/t7xx_cldma.h | 176 ++++ drivers/net/wwan/t7xx/t7xx_common.h | 40 + drivers/net/wwan/t7xx/t7xx_hif_cldma.c | 1204 ++++++++++++++++++++++++ drivers/net/wwan/t7xx/t7xx_hif_cldma.h | 141 +++ drivers/net/wwan/t7xx/t7xx_reg.h | 33 + 6 files changed, 1875 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_common.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_reg.h
drivers/net/wwan/t7xx/t7xx_cldma.c new file +281 -0
@@ -0,0 +1,281 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) 2021, MediaTek Inc. +* Copyright (c) 2021-2022, 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; +u32 val; + + reg = 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); +} + +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) +{ +u32 offset = qno *ADDR_SIZE ; +void __iomem *reg; + + reg = tx_rx ==MTK_RX ? hw_info->ap_ao_base +REG_CLDMA_DL_START_ADDRL_0 : + hw_info->ap_pdn_base +REG_CLDMA_UL_START_ADDRL_0 ; +iowrite64 (address, reg + 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) +{ +void __iomem *reg; +u32 mask, val; + + mask = qno ==CLDMA_ALL_Q ?CLDMA_ALL_Q :BIT (qno); + reg = tx_rx ==MTK_RX ? hw_info->ap_ao_base +REG_CLDMA_DL_STATUS : + hw_info->ap_pdn_base +REG_CLDMA_UL_STATUS ; + val =ioread32 (reg); + +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; +u32 val; + + reg = tx_rx ==MTK_RX ? hw_info->ap_pdn_base +REG_CLDMA_L2RISAR0 : + hw_info->ap_pdn_base +REG_CLDMA_L2TISAR0 ; + val =ioread32 (reg); +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_all_qs (struct t7xx_cldma_hw *hw_info,enum mtk_txrx tx_rx) +{ +void __iomem *reg; + + reg = tx_rx ==MTK_RX ? hw_info->ap_pdn_base +REG_CLDMA_DL_STOP_CMD : + hw_info->ap_pdn_base +REG_CLDMA_UL_STOP_CMD ; +iowrite32 (CLDMA_ALL_Q , reg); +} + +void t7xx_cldma_hw_stop (struct t7xx_cldma_hw *hw_info,enum mtk_txrx tx_rx) +{ +void __iomem *reg; + + reg = 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); +iowrite32 (EMPTY_STATUS_BITMASK , reg); +}
drivers/net/wwan/t7xx/t7xx_cldma.h new file +176 -0
176 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_common.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0-only +* +* Copyright (c) 2021, MediaTek Inc. +* Copyright (c) 2021-2022, Intel Corporation. +* +* Authors: +* Haijun Liu <[email protected]> +* Ricardo Martinez<[email protected]> +* +* Contributors: +* Andy Shevchenko <[email protected]> +* Chiranjeevi Rapolu <[email protected]> +* Eliot Lee <[email protected]> +* Moises Veleta <[email protected]> +* Sreehari Kancharla <[email protected]> +*/ + +#ifndef __T7XX_COMMON_H__ +#define __T7XX_COMMON_H__ + +#include <linux/skbuff.h> + +enum mtk_txrx { +MTK_TX , +MTK_RX , +}; + +#ifdef NET_SKBUFF_DATA_USES_OFFSET +static inline unsigned int t7xx_skb_data_area_size (struct sk_buff *skb) +{ +return skb->head + skb->end - skb->data; +} +#else +static inline unsigned int t7xx_skb_data_area_size (struct sk_buff *skb) +{ +return skb->end - skb->data; +} +#endif + +#endif
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +1204 -0
1,204 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_hif_cldma.h new file +141 -0
141 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_reg.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0-only +* +* Copyright (c) 2021, MediaTek Inc. +* Copyright (c) 2021-2022, Intel Corporation. +* +* Authors: +* Haijun Liu <[email protected]> +* Chiranjeevi Rapolu <[email protected]> +* +* Contributors: +* Amir Hanania <[email protected]> +* Andy Shevchenko <[email protected]> +* Eliot Lee <[email protected]> +* Moises Veleta <[email protected]> +* Ricardo Martinez<[email protected]> +* Sreehari Kancharla <[email protected]> +*/ + +#ifndef __T7XX_REG_H__ +#define __T7XX_REG_H__ + +enum t7xx_int { +DPMAIF_INT , +CLDMA0_INT , +CLDMA1_INT , +CLDMA2_INT , +MHCCIF_INT , +DPMAIF2_INT , +SAP_RGU_INT , +CLDMA3_INT , +}; + +#endif /* __T7XX_REG_H__ */
Signature · 1 line
2.17.1
Re: [PATCH net-next v5 02/13] net: wwan: t7xx: Add control DMA interface
Quoted 26 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 writeCLDMA 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
Quoted 8 lines
Signed-off-by Haijun Liu <[email protected]>Signed-off-by Chandrashekar Devegowda <[email protected]>Co-developed-by Ricardo Martinez <[email protected]>Signed-off-by Ricardo Martinez <[email protected]>Quoted 1 line
From a WWAN framework perspective:
Reviewed-by Loic Poulain <[email protected]>---
Since t7xx_pcie_mac_set_int and t7xx_pcie_mac_clear_int are still not here, please note in your commit message there are these dependencies between patches 02 and 03 (and I don't promise somebody else wouldn't oppose).
Quoted 1 line
+{
...
Quoted 1 line
(quoted diff) +1
-0+ for (i = 0; i < ring->length; i++) {
...
Quoted 1 line
(quoted diff) +1
-0+ gpd = req->gpd;
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 454
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +5
-0+ } + +list_for_each_entry (req, &ring->gpd_ring, entry) { +t7xx_cldma_rgpd_set_next_ptr (gpd, req->gpd_addr); + gpd = req->gpd;
Despite being correct, this is bit of a trick. I'd add a comment between the loops to help the reader to track where gpd points to.
Quoted 7 lines
+/**
+ *t7xx_cldma_send_skb()- Send control data to modem.
+ * @md_ctrl: CLDMA context structure.
+ * @qno: Queue number.
+ * @skb: Socket buffer.
+ *
+ * Return:
...
Quoted 1 line
+ * *
-EBUSY- Resource lock failure.
Leftover?
...with those addressed
And kudos for rx_not_done -> pending_rx_int change. It was a minor thing for me but the logic is so much easier to understand now with that better name :-).
Some other nice cleanups compared with v4 also noted.
Signature · 1 line
i.
Martinez, Ricardo
reviewerRe: [PATCH net-next v5 02/13] net: wwan: t7xx: Add control DMA interface
Quoted 1 line · Ilpo Järvinen
On Wed, 23 Feb 2022, Ricardo Martinez wrote:
...
Quoted 10 lines
Quoted 7 lines
+/**
+ *t7xx_cldma_send_skb()- Send control data to modem.
+ * @md_ctrl: CLDMA context structure.
+ * @qno: Queue number.
+ * @skb: Socket buffer.
+ *
+ * Return:...
Quoted 1 line
+ * *
-EBUSY- Resource lock failure.Leftover?
This function can still return -EBUSY if t7xx_pci_sleep_disable_complete() fails.
Maybe returning -ETIMED would make more sense based on the implementation of t7xx_pci_sleep_disable_complete().
Quoted 12 lines
...with those addressed
Reviewed-by Ilpo Järvinen <[email protected]>And kudos for
rx_not_done->pending_rx_intchange. It was a minor thing for me but the logic is so much easier to understand now with that better name :-).Some other nice cleanups compared with v4 also noted.
Sergey Ryazanov
maintainerRe: [PATCH net-next v5 02/13] net: wwan: t7xx: Add control DMA interface
In reply to Ricardo MartinezQuoted 54 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 writeCLDMA 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 ringSigned-off-by Haijun Liu <[email protected]>Signed-off-by Chandrashekar Devegowda <[email protected]>Co-developed-by Ricardo Martinez <[email protected]>Signed-off-by Ricardo Martinez <[email protected]>From a WWAN framework perspective:
Reviewed-by Loic Poulain <[email protected]>--- drivers/net/wwan/t7xx/t7xx_cldma.c | 281 ++++++ drivers/net/wwan/t7xx/t7xx_cldma.h | 176 ++++ drivers/net/wwan/t7xx/t7xx_common.h | 40 + drivers/net/wwan/t7xx/t7xx_hif_cldma.c | 1204 ++++++++++++++++++++++++ drivers/net/wwan/t7xx/t7xx_hif_cldma.h | 141 +++ drivers/net/wwan/t7xx/t7xx_reg.h | 33 + 6 files changed, 1875 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_common.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_reg.hdrivers/net/wwan/t7xx/t7xx_cldma.c new file +0
-0
drivers/net/wwan/t7xx/t7xx_cldma.c line 9
Quoted 9 lines
drivers/net/wwan/t7xx/t7xx_cldma.c new file +9
-0@@ -0,0 +1,281 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) 2021, MediaTek Inc. +* Copyright (c) 2021-2022, Intel Corporation. +* +* Authors: +* Haijun Liu <[email protected]> +* Moises Veleta <[email protected]> +* Ricardo Martinez<[email protected]>
The space is missed between name and email. The same issue repeated in every file of the series.
[skipped]
drivers/net/wwan/t7xx/t7xx_cldma.c line 20
Quoted 11 lines
drivers/net/wwan/t7xx/t7xx_cldma.c new file +11
-0+#ifdef NET_SKBUFF_DATA_USES_OFFSET +static inline unsigned int t7xx_skb_data_area_size (struct sk_buff *skb) +{ +return skb->head + skb->end - skb->data; +} +#else +static inline unsigned int t7xx_skb_data_area_size (struct sk_buff *skb) +{ +return skb->end - skb->data; +} +#endif
You can use skb_end_pointer() to avoid conditional compilation.
--
Sergey
Ricardo Martinez
reviewerPATCH v5 3/13 net: wwan: t7xx: Add core components
In reply to Ricardo MartinezFrom: 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.
From a WWAN framework perspective:
--- drivers/net/wwan/Kconfig | 14 + drivers/net/wwan/Makefile | 1 + drivers/net/wwan/t7xx/Makefile | 12 + drivers/net/wwan/t7xx/t7xx_common.h | 10 + drivers/net/wwan/t7xx/t7xx_mhccif.c | 102 ++++ drivers/net/wwan/t7xx/t7xx_mhccif.h | 37 ++ drivers/net/wwan/t7xx/t7xx_modem_ops.c | 500 +++++++++++++++++++ drivers/net/wwan/t7xx/t7xx_modem_ops.h | 84 ++++ drivers/net/wwan/t7xx/t7xx_pci.c | 225 +++++++++ drivers/net/wwan/t7xx/t7xx_pci.h | 65 +++ drivers/net/wwan/t7xx/t7xx_pcie_mac.c | 263 ++++++++++ drivers/net/wwan/t7xx/t7xx_pcie_mac.h | 31 ++ drivers/net/wwan/t7xx/t7xx_reg.h | 106 ++++ drivers/net/wwan/t7xx/t7xx_state_monitor.c | 540 +++++++++++++++++++++ drivers/net/wwan/t7xx/t7xx_state_monitor.h | 123 +++++ 15 files changed, 2113 insertions(+) create mode 100644 drivers/net/wwan/t7xx/Makefile 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_state_monitor.c create mode 100644 drivers/net/wwan/t7xx/t7xx_state_monitor.h
drivers/net/wwan/Kconfig +14 -0
@@ -105,6 +105,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
@@ -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
@@ -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 +10 -0
@@ -20,6 +20,16 @@#include <linux/skbuff.h> +enum md_state { +MD_STATE_INVALID , +MD_STATE_WAITING_FOR_HS1 , +MD_STATE_WAITING_FOR_HS2 , +MD_STATE_READY , +MD_STATE_EXCEPTION , +MD_STATE_WAITING_TO_STOP , +MD_STATE_STOPPED , +}; +enum mtk_txrx {MTK_TX ,MTK_RX ,
drivers/net/wwan/t7xx/t7xx_mhccif.c new file +102 -0
102 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_mhccif.h new file +37 -0
@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0-only +* +* Copyright (c) 2021, MediaTek Inc. +* Copyright (c) 2021-2022, 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 +500 -0
500 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 +225 -0
225 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_pci.h new file +65 -0
65 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_pcie_mac.c new file +263 -0
263 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_pcie_mac.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0-only +* +* Copyright (c) 2021, MediaTek Inc. +* Copyright (c) 2021-2022, 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 "t7xx_pci.h" +#include "t7xx_reg.h" + +#define IREG_BASE (t7xx_dev) ((t7xx_dev)->base_addr.pcie_mac_ireg_base) + +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 t7xx_int int_type); +void t7xx_pcie_mac_set_int (struct t7xx_pci_dev *t7xx_dev,enum t7xx_int int_type); +void t7xx_pcie_mac_clear_int_status (struct t7xx_pci_dev *t7xx_dev,enum t7xx_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 +106 -0
112 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +540 -0
540 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_state_monitor.h new file +123 -0
123 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH net-next v5 03/13] net: wwan: t7xx: Add core components
Quoted 25 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.Signed-off-by Haijun Liu <[email protected]>Signed-off-by Chandrashekar Devegowda <[email protected]>Co-developed-by Ricardo Martinez <[email protected]>Signed-off-by Ricardo Martinez <[email protected]>Quoted 1 line
From a WWAN framework perspective:
Reviewed-by Loic Poulain <[email protected]>---
drivers/net/wwan/t7xx/t7xx_pci.c line 116
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_pci.c new file +3
-0+/* IPs enable interrupts when ready */ +for (i =0 ; i <EXT_INT_NUM ; i++) +t7xx_pcie_mac_clear_int (t7xx_dev, i);
In v4, PCIE_MAC_MSIX_MSK_SET() wrote to IMASK_HOST_MSIX_SET_GRP0_0. In v5, t7xx_pcie_mac_clear_int() writes to IMASK_HOST_MSIX_CLR_GRP0_0.
t7xx_pcie_mac_set_int() would write to IMASK_HOST_MSIX_SET_GRP0_0 matching to what v4 did. So you probably want to call t7xx_pcie_mac_set_int() instead of t7xx_pcie_mac_clear_int()?
Signature · 1 line
i.
Martinez, Ricardo
reviewerRe: [PATCH net-next v5 03/13] net: wwan: t7xx: Add core components
Quoted 32 lines · Ilpo Järvinen
Quoted 24 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.Signed-off-by Haijun Liu <[email protected]>Signed-off-by Chandrashekar Devegowda <[email protected]>Co-developed-by Ricardo Martinez <[email protected]>Signed-off-by Ricardo Martinez <[email protected]>Quoted 1 line
From a WWAN framework perspective:
Reviewed-by Loic Poulain <[email protected]>---
drivers/net/wwan/t7xx/t7xx_pci.c line 116
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_pci.c new file +3
-0+/* IPs enable interrupts when ready */ +for (i =0 ; i <EXT_INT_NUM ; i++) +t7xx_pcie_mac_clear_int (t7xx_dev, i);In v4,
PCIE_MAC_MSIX_MSK_SET()wrote toIMASK_HOST_MSIX_SET_GRP0_0. In v5,t7xx_pcie_mac_clear_int()writes toIMASK_HOST_MSIX_CLR_GRP0_0.
Quoted 3 lines
t7xx_pcie_mac_set_int()would write toIMASK_HOST_MSIX_SET_GRP0_0matching to what v4 did. So you probably want to callt7xx_pcie_mac_set_int()instead oft7xx_pcie_mac_clear_int()?
Yes, this should call t7xx_pcie_mac_set_int().
Quoted 1 line
Sergey Ryazanov
maintainerRe: [PATCH net-next v5 03/13] net: wwan: t7xx: Add core components
In reply to Ricardo MartinezQuoted 15 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.
[skipped]
Quoted 19 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c new file +19
-0+static struct t7xx_modem *t7xx_md_alloc (struct t7xx_pci_dev *t7xx_dev) +{ +struct device *dev = &t7xx_dev->pdev->dev; +struct t7xx_modem *md; + + md =devm_kzalloc (dev,sizeof (*md),GFP_KERNEL ); +if (!md) +return NULL ; + + md->t7xx_dev = t7xx_dev; + t7xx_dev->md = md; + md->core_md.ready = false; +spin_lock_init (&md->exp_lock); + md->handshake_wq =alloc_workqueue ("%s" ,WQ_UNBOUND |WQ_MEM_RECLAIM |WQ_HIGHPRI , +0 ,"md_hk_wq" ); +if (!md->handshake_wq) +return NULL ; + +INIT_WORK (&md->handshake_work, t7xx_md_hk_wq);
drivers/net/wwan/t7xx/t7xx_modem_ops.c line 428
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c new file +10
-0+return md; +} + +int t7xx_md_reset (struct t7xx_pci_dev *t7xx_dev) +{ +struct t7xx_modem *md = t7xx_dev->md; + + md->md_init_finish = false; + md->exp_id =0 ; +spin_lock_init (&md->exp_lock);
Looks like a duplicated initialization, the first time the lock was initialized in the t7xx_md_alloc() above.
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c new file +5
-0+t7xx_fsm_reset (md); +t7xx_cldma_reset (md->md_ctrl[CLDMA_ID_MD ]); + md->md_init_finish = true; +return 0 ; +}
[skipped]
drivers/net/wwan/t7xx/t7xx_pcie_mac.c line 261
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_pcie_mac.c new file +5
-0+void t7xx_pcie_set_mac_msix_cfg (struct t7xx_pci_dev *t7xx_dev,unsigned int irq_count) +{ +u32 val; + + val =ffs (irq_count) *2 -1 ;
Move this initialization to the variable declaration.
drivers/net/wwan/t7xx/t7xx_pcie_mac.c line 263
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_pcie_mac.c new file +2
-0+iowrite32 (val,IREG_BASE (t7xx_dev) +T7XX_PCIE_CFG_MSIX ); +}
--
Sergey
Ricardo Martinez
reviewerPATCH v5 4/13 net: wwan: t7xx: Add port proxy infrastructure
In reply to Ricardo MartinezFrom: 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.
From a WWAN framework perspective:
--- drivers/net/wwan/t7xx/Makefile | 1 + drivers/net/wwan/t7xx/t7xx_common.h | 16 + drivers/net/wwan/t7xx/t7xx_modem_ops.c | 14 +- drivers/net/wwan/t7xx/t7xx_port.h | 149 ++++++ drivers/net/wwan/t7xx/t7xx_port_proxy.c | 525 +++++++++++++++++++++ drivers/net/wwan/t7xx/t7xx_port_proxy.h | 69 +++ drivers/net/wwan/t7xx/t7xx_state_monitor.c | 5 + 7 files changed, 778 insertions(+), 1 deletion(-) 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
@@ -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_common.h +16 -0
@@ -18,7 +18,23 @@#ifndef __T7XX_COMMON_H__#define __T7XX_COMMON_H__ +#include <linux/bits.h> #include <linux/skbuff.h> +#include <linux/types.h> + +struct ccci_header { +__le32 packet_header; +__le32 packet_len; +__le32 status; +__le32 ex_msg; +}; + +/* Coupled with HW - indicates if there is data following the CCCI header or not */ +#define CCCI_HEADER_NO_DATA 0xffffffff + +#define CCCI_H_AST_BIT BIT(31) +#define CCCI_H_SEQ_FLD GENMASK(30, 16) +#define CCCI_H_CHN_FLD GENMASK(15, 0)enum md_state { MD_STATE_INVALID,
drivers/net/wwan/t7xx/t7xx_modem_ops.c +13 -1
@@ -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"
@@ -273,6 +275,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[CLDMA_ID_MD ], stage);
@@ -428,6 +431,7 @@ int 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[CLDMA_ID_MD ]); +t7xx_port_proxy_reset (md->port_prox); md->md_init_finish = true;return 0 ; }
@@ -464,14 +468,21 @@ 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; + ret =t7xx_fsm_append_cmd (md->fsm_ctl,FSM_CMD_START ,0 );if (ret)/* fsm_uninit flushes cmd queue */ - goto err_uninit_cldma; + goto err_uninit_proxy;t7xx_md_sys_sw_init (t7xx_dev); md->md_init_finish = true;return 0 ; +err_uninit_proxy: +t7xx_port_proxy_uninit (md->port_prox); + err_uninit_cldma:t7xx_cldma_exit (md->md_ctrl[CLDMA_ID_MD ]);
@@ -494,6 +505,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[CLDMA_ID_MD ]);t7xx_fsm_uninit (md);destroy_workqueue (md->handshake_wq);
drivers/net/wwan/t7xx/t7xx_port.h new file +149 -0
149 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +525 -0
525 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_port_proxy.h new file +69 -0
69 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_state_monitor.c +5 -0
@@ -37,6 +37,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"
@@ -90,6 +91,9 @@ static void fsm_state_notify(struct t7xx_modem *md, enum md_state state)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); }
@@ -258,6 +262,7 @@ static void t7xx_fsm_broadcast_ready_state(struct t7xx_fsm_ctl *ctl) ctl->md_state =MD_STATE_READY ;fsm_state_notify (ctl->md,MD_STATE_READY ); +t7xx_port_proxy_md_status_notify (ctl->md->port_prox,MD_STATE_READY ); }static void fsm_routine_ready (struct t7xx_fsm_ctl *ctl)
Signature · 1 line
2.17.1
Re: [PATCH net-next v5 04/13] net: wwan: t7xx: Add port proxy infrastructure
Quoted 17 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_portand operate as defined bystruct port_ops.Signed-off-by Haijun Liu <[email protected]>Co-developed-by Chandrashekar Devegowda <[email protected]>Signed-off-by Chandrashekar Devegowda <[email protected]>Co-developed-by Ricardo Martinez <[email protected]>Signed-off-by Ricardo Martinez <[email protected]>Quoted 1 line
From a WWAN framework perspective:
Reviewed-by Loic Poulain <[email protected]>---
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 78
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +3
-0+static u16 t7xx_port_next_rx_seq_num (struct t7xx_port *port,struct ccci_header *ccci_h) +{ +u16 seq_num, next_seq_num, assert_bit;
assert_bit could be bool.
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 83
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +5
-0+ + seq_num =FIELD_GET (CCCI_H_SEQ_FLD ,le32_to_cpu (ccci_h->status)); + next_seq_num = (seq_num +1 ) &FIELD_MAX (CCCI_H_SEQ_FLD ); + assert_bit = !!(le32_to_cpu (ccci_h->status) &CCCI_H_AST_BIT ); +if (!assert_bit || port->seq_nums[MTK_RX ] >FIELD_MAX (CCCI_H_SEQ_FLD ))
Is this an obfuscated way to say:
... || port->seq_nums[MTK_RX] == INVALID_SEQ_NUM
?
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 478
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +3
-0+int t7xx_port_proxy_node_control (struct t7xx_modem *md,struct port_msg *port_msg) +{ +u32 *port_info_base = (void *)port_msg +sizeof (*port_msg);
__le32 *port_info_base = (void *)port_msg + sizeof(*port_msg);
As port_msg has __le32 fields, the endianess likely should disappear in this casting?
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +7
-0+struct device *dev = &md->t7xx_dev->pdev->dev; +unsigned int version, ports, i; + + version =FIELD_GET (PORT_MSG_VERSION ,le32_to_cpu (port_msg->info)); +if (version !=PORT_ENUM_VER || +le32_to_cpu (port_msg->head_pattern) !=PORT_ENUM_HEAD_PATTERN || +le32_to_cpu (port_msg->tail_pattern) !=PORT_ENUM_TAIL_PATTERN ) {
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 495
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +10
-0+dev_err (dev,"Invalid port control message %x:%x:%x\n" , + version,le32_to_cpu (port_msg->head_pattern), +le32_to_cpu (port_msg->tail_pattern)); +return -EFAULT ; + } + + ports =FIELD_GET (PORT_MSG_PRT_CNT ,le32_to_cpu (port_msg->info)); +for (i =0 ; i < ports; i++) { +struct t7xx_port_static *port_static; +u32 *port_info = port_info_base + i;
__le32 *port_info = port_info_base + i;
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 500
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +5
-0+struct t7xx_port *port; +unsigned int ch_id; +bool en_flag; + + ch_id =FIELD_GET (PORT_INFO_CH_ID , *port_info);
ch_id = FIELD_GET(PORT_INFO_CH_ID, le32_to_cpu(*port_info));
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 507
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +7
-0+ port =t7xx_proxy_get_port_by_ch (md->port_prox, ch_id); +if (!port) { +dev_dbg (dev,"Port:%x not found\n" , ch_id); +continue ; + } + + en_flag = !!(PORT_INFO_ENFLG & *port_info);
*port_info & PORT_INFO_ENFLG
Signature · 1 line
i.
Martinez, Ricardo
reviewerRe: [PATCH net-next v5 04/13] net: wwan: t7xx: Add port proxy infrastructure
Quoted 17 lines · Ilpo Järvinen
Quoted 15 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_portand operate as defined bystruct port_ops.Signed-off-by Haijun Liu <[email protected]>Co-developed-by Chandrashekar Devegowda <[email protected]>Signed-off-by Chandrashekar Devegowda <[email protected]>Co-developed-by Ricardo Martinez <[email protected]>Signed-off-by Ricardo Martinez <[email protected]>Quoted 1 line
From a WWAN framework perspective:
Reviewed-by Loic Poulain <[email protected]>---
...
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 83
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +5
-0+ + seq_num =FIELD_GET (CCCI_H_SEQ_FLD ,le32_to_cpu (ccci_h->status)); + next_seq_num = (seq_num +1 ) &FIELD_MAX (CCCI_H_SEQ_FLD ); + assert_bit = !!(le32_to_cpu (ccci_h->status) &CCCI_H_AST_BIT ); +if (!assert_bit || port->seq_nums[MTK_RX ] >FIELD_MAX (CCCI_H_SEQ_FLD ))Is this an obfuscated way to say:
... || port->seq_nums[MTK_RX] == INVALID_SEQ_NUM?
Right, that condition is true only for the first packet, when seq num is set to INVALID_SEQ_NUM.
The next version will explicitly compare seq_nums[MTK_RX] against INVALID_SEQ_NUM.
Sergey Ryazanov
maintainerRe: [PATCH net-next v5 04/13] net: wwan: t7xx: Add port proxy infrastructure
In reply to Ricardo MartinezQuoted 5 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_portand operate as defined bystruct port_ops.
[skipped]
drivers/net/wwan/t7xx/t7xx_port.h line 34
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_port.h new file +1
-0+#define PORT_F_RX_ALLOW_DROP BIT(0)/* Packet will be dropped if port's RX buffer full */
The flag is advertised as an overflow policy, but it is actually only used for WWAN (AT&MBIM) ports, and only to free skb in case of an error. Should it be removed and skb consumption rethought?
Quoted 1 line
+#define
PORT_F_RX_FULLEDBIT(1) /* RX buffer has been detected to be full */
This flag is set, but is never checked.
Quoted 1 line
+#define
PORT_F_USER_HEADERBIT(2) /* CCCI header will be provided by user, but not by CCCI */
Above flag is never set and looks like a leftover from earlier driver development. Should it be removed?
Quoted 1 line
+#define
PORT_F_RX_EXCLUSIVEBIT(3) /* RX queue only has this one port */
This flag is not used at all.
Quoted 1 line
+#define
PORT_F_RX_ADJUST_HEADERBIT(4) /* Check whether need remove CCCI header while recv skb */
This flag is set for WWAN ports, but the control port code unconditionally strips the CCCI header. Should the header be always stripped and this flag removed from the code?
Quoted 1 line
+#define
PORT_F_RX_CH_TRAFFICBIT(5) /* Enable port channel traffic */
This flag is set for wwan ports, but is not ever checked.
Quoted 1 line
+#define
PORT_F_RX_CHAR_NODEBIT(7) /* Requires exporting char dev node to userspace */
This flag is not used at all.
Quoted 1 line
+#define
PORT_F_CHAR_NODE_SHOWBIT(10) /* The char dev node is shown to userspace by default */
This flag is checked but is never set.
[skipped]
Quoted 1 line
+#define
PORT_INVALID_CH_IDGENMASK(15, 0)
Looks like this macro is never used, should it be removed? And BTW, why is this value defined as a mask?
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_port.h new file +8
-0+/* Channel ID and Message ID definitions. +* The channel number consists of peer_id(15:12) , channel_id(11:0) +* peer_id: +* 0:reserved, 1: to sAP, 2: to MD +*/ +enum port_ch { +/* to MD */ +PORT_CH_CONTROL_RX =0x2000 ,
drivers/net/wwan/t7xx/t7xx_port.h line 67
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port.h new file +10
-0+PORT_CH_CONTROL_TX =0x2001 , +PORT_CH_UART1_RX =0x2006 ,/* META */ +PORT_CH_UART1_TX =0x2008 , +PORT_CH_UART2_RX =0x200a ,/* AT */ +PORT_CH_UART2_TX =0x200c , +PORT_CH_MD_LOG_RX =0x202a ,/* MD logging */ +PORT_CH_MD_LOG_TX =0x202b , +PORT_CH_LB_IT_RX =0x203e ,/* Loop back test */ +PORT_CH_LB_IT_TX =0x203f , + PORT_CH_STATUS_RX = 0x2043, /* Status polling */
There is no STATUS_TX channel, so how is the polling performed? Is it performed through the CONTROL_TX channel? Or should the comment be changed to "status events"?
Quoted 15 lines
drivers/net/wwan/t7xx/t7xx_port.h new file +15
-0+PORT_CH_MIPC_RX =0x20ce ,/* MIPC */ +PORT_CH_MIPC_TX =0x20cf , +PORT_CH_MBIM_RX =0x20d0 , +PORT_CH_MBIM_TX =0x20d1 , +PORT_CH_DSS0_RX =0x20d2 , +PORT_CH_DSS0_TX =0x20d3 , +PORT_CH_DSS1_RX =0x20d4 , +PORT_CH_DSS1_TX =0x20d5 , +PORT_CH_DSS2_RX =0x20d6 , +PORT_CH_DSS2_TX =0x20d7 , +PORT_CH_DSS3_RX =0x20d8 , +PORT_CH_DSS3_TX =0x20d9 , +PORT_CH_DSS4_RX =0x20da , +PORT_CH_DSS4_TX =0x20db , + PORT_CH_DSS5_RX = 0x20dc,
drivers/net/wwan/t7xx/t7xx_port.h line 102
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port.h new file +9
-0+PORT_CH_DSS5_TX =0x20dd , +PORT_CH_DSS6_RX =0x20de , +PORT_CH_DSS6_TX =0x20df , +PORT_CH_DSS7_RX =0x20e0 , + PORT_CH_DSS7_TX = 0x20e1, +}; + + +struct t7xx_port_static {
I do not care too much, but the purpose of this structure is to carry static port configuration. And the main word here is "configuration", not "static". So why not name this structure port_conf or port_params?
drivers/net/wwan/t7xx/t7xx_port.h line 110
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_port.h new file +8
-0+enum port_ch tx_ch; +enum port_ch rx_ch; +unsigned char txq_index; +unsigned char rxq_index; +unsigned char txq_exp_index; +unsigned char rxq_exp_index; +enum cldma_id path_id; +unsigned int flags;
This field is not used.
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_port.h new file +4
-0+struct port_ops *ops; +char *name; +enum wwan_port_type port_type; +};
[skipped]
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 52
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +1
-0+static struct t7xx_port_static t7xx_md_ports[1 ];
This array can be defined from the beginning as:
static struct t7xx_port_static t7xx_md_ports[] = { };
This will reduce a number of ping-pong changes in the further patches.
[skipped]
Quoted 11 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +11
-0+int t7xx_port_recv_skb (struct t7xx_port *port,struct sk_buff *skb) +{ +struct ccci_header *ccci_h; +unsigned long flags; +u32 channel; +int ret =0 ; + +spin_lock_irqsave (&port->rx_wq.lock, flags); +if (port->rx_skb_list.qlen >= port->rx_length_th) { + port->flags |=PORT_F_RX_FULLED ; +spin_unlock_irqrestore (&port->rx_wq.lock, flags);
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 178
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +10
-0+ +return -ENOBUFS ; + } + ccci_h = (struct ccci_header *)skb->data; + port->flags &= ~PORT_F_RX_FULLED ; +if (port->flags &PORT_F_RX_ADJUST_HEADER ) +t7xx_port_adjust_skb (port, skb); + channel =FIELD_GET (CCCI_H_CHN_FLD ,le32_to_cpu (ccci_h->status)); +if (channel ==PORT_CH_STATUS_RX ) { + ret = port->skb_handler (port, skb);
This handler will never be called. A message with channel = PORT_CH_STATUS_RX will be dropped in the t7xx_port_proxy_recv_skb() function, since the corresponding port is nonexistent.
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 189
Quoted 11 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +11
-0+ }else { +if (port->wwan_port) +wwan_port_rx (port->wwan_port, skb); +else +__skb_queue_tail (&port->rx_skb_list, skb); + } +spin_unlock_irqrestore (&port->rx_wq.lock, flags); + +wake_up_all (&port->rx_wq); +return ret; +}
Whole this function looks like a big unintentional duct tape. On the one hand, each port type has a specific recv_skb callback. But in fact, all message processing paths pass through this place. And here the single function forced to take into account the specialties of each port type:
a) immediately passes status events to the handler via the indirect call;
b) enqueues control messages to the rx queue;
c) directly passes WWAN management (MBIM & AT) message to the WWAN subsystem.
I would like to suggest the following reworking plan for the function:
1) move the common processing code (header stripping code) to the t7xx_port_proxy_recv_skb() function, where it belongs;
2) add a dedicated port ops for the PORT_CH_STATUS_RX channel and call control_msg_handler() from its recv_skb callback (lets call it t7xx_port_status_recv_skb()); this will solve both issues: status messages will no more dropped and status message hook will be removed;
3) move the wwan_port_rx() call to the t7xx_port_wwan_recv_skb() callback; this will remove another one hook;
4) finally rename t7xx_port_recv_skb() to t7xx_port_enqueue_skb(), since after the hooks removing, the only purpose of this function will be to enqueue received skb(s).
[skipped]
Quoted 13 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +13
-0+int t7xx_port_proxy_send_skb (struct t7xx_port *port,struct sk_buff *skb) +{ +struct ccci_header *ccci_h = (struct ccci_header *)(skb->data); +struct cldma_ctrl *md_ctrl; +unsigned char tx_qno; +int ret; + + tx_qno =t7xx_port_get_queue_no (port); +t7xx_port_proxy_set_tx_seq_num (port, ccci_h); + + md_ctrl =get_md_ctrl (port); + ret =t7xx_cldma_send_skb (md_ctrl, tx_qno, skb); +if (ret) {
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 220
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +10
-0+dev_err (port->dev,"Failed to send skb: %d\n" , ret); +return ret; + } + + port->seq_nums[MTK_TX ]++; + +return 0 ; +} + +int t7xx_port_send_skb_to_md (struct t7xx_port *port,struct sk_buff *skb)
This function looks like a duplicate of the above t7xx_port_proxy_send_skb(). Why can not t7xx_port_proxy_send_skb() be used to send a WWAN (MBIM&AT) port skb?
If you need to bypass some checks in t7xx_port_send_skb_to_md() then you can create an exception as already done for PORT_CH_MD_LOG_TX. Or, better, create a set of two functions: first will perform checks and call an actual skb send routine. E.g.
int __t7xx_port_proxy_send_skb(...)
{
return t7xx_cldma_send_skb(...);
}int t7xx_port_proxy_send_skb(...)
{
/* Perform checks here */
return __t7xx_port_proxy_send_skb(...)
}This way code duplication will be reduced and if someone calls __t7xx_port_proxy_send_skb() directly bypassing state checks, then it will be clear that such call is a special case.
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +6
-0+{ +struct t7xx_port_static *port_static = port->port_static; +struct t7xx_fsm_ctl *ctl = port->t7xx_dev->md->fsm_ctl; +struct cldma_ctrl *md_ctrl; +enum md_state md_state; +unsigned int fsm_state;
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 236
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +10
-0+ + md_state =t7xx_fsm_get_md_state (ctl); + + fsm_state =t7xx_fsm_get_ctl_state (ctl); +if (fsm_state !=FSM_STATE_PRE_START ) { +if (md_state ==MD_STATE_WAITING_FOR_HS1 || md_state ==MD_STATE_WAITING_FOR_HS2 ) +return -ENODEV ; + +if (md_state ==MD_STATE_EXCEPTION && port_static->tx_ch !=PORT_CH_MD_LOG_TX && + port_static->tx_ch !=PORT_CH_UART1_TX )
There are no ports defined for PORT_CH_MD_LOG_TX and PORT_CH_UART1_TX channels, should this check be removed?
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 241
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +5
-0+return -EBUSY ; + +if (md_state ==MD_STATE_STOPPED || md_state ==MD_STATE_WAITING_TO_STOP || + md_state ==MD_STATE_INVALID ) +return -ENODEV ;
Did you consider to convert the above tests into a big switch? e.g.:
switch (md_state) {
case MD_STATE_WAITING_FOR_HS1:
case ...:
case MD_STATE_INVALID:
return -ENODEV;
case MD_STATE_EXCEPTION:
if (port_static->tx_ch != PORT_CH_MD_LOG_TX &&
port_static->tx_ch != PORT_CH_UART1_TX)
return -EBUSY;
break;
}Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +5
-0+ } + + md_ctrl =get_md_ctrl (port); +return t7xx_cldma_send_skb (md_ctrl,t7xx_port_get_queue_no (port), skb); +}
[skipped]
Quoted 76 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +76
-0+static struct t7xx_port *t7xx_port_proxy_find_port (struct t7xx_pci_dev *t7xx_dev, +struct cldma_queue *queue,u16 channel) +{ +struct port_proxy *port_prox = t7xx_dev->md->port_prox; +struct list_head *port_list; +struct t7xx_port *port; +u8 ch_id; + + ch_id =FIELD_GET (PORT_CH_ID_MASK , channel); + port_list = &port_prox->rx_ch_ports[ch_id]; +list_for_each_entry (port, port_list, entry) { +struct t7xx_port_static *port_static = port->port_static; + +if (queue->md_ctrl->hif_id == port_static->path_id && + channel == port_static->rx_ch) +return port; + } + +return NULL ; +} + +/** +* t7xx_port_proxy_recv_skb() - Dispatch received skb. +* @queue: CLDMA queue. +* @skb: Socket buffer. +* +* Return: +** 0 - Packet consumed. +** -ERROR - Failed to process skb. +*/ +static int t7xx_port_proxy_recv_skb (struct cldma_queue *queue,struct sk_buff *skb) +{ +struct ccci_header *ccci_h = (struct ccci_header *)skb->data; +struct t7xx_pci_dev *t7xx_dev = queue->md_ctrl->t7xx_dev; +struct t7xx_fsm_ctl *ctl = t7xx_dev->md->fsm_ctl; +struct device *dev = queue->md_ctrl->dev; +struct t7xx_port_static *port_static; +struct t7xx_port *port; +u16 seq_num, channel; +int ret; + +if (!skb) +return -EINVAL ; + + channel =FIELD_GET (CCCI_H_CHN_FLD ,le32_to_cpu (ccci_h->status)); +if (t7xx_fsm_get_md_state (ctl) ==MD_STATE_INVALID ) { +dev_err_ratelimited (dev,"Packet drop on channel 0x%x, modem not ready\n" , channel); + goto drop_skb; + } + + port =t7xx_port_proxy_find_port (t7xx_dev, queue, channel); +if (!port) { +dev_err_ratelimited (dev,"Packet drop on channel 0x%x, port not found\n" , channel); + goto drop_skb; + } + + seq_num =t7xx_port_next_rx_seq_num (port, ccci_h); + port_static = port->port_static; + ret = port_static->ops->recv_skb (port, skb); +if (ret && port->flags &PORT_F_RX_ALLOW_DROP ) { + port->seq_nums[MTK_RX ] = seq_num; +dev_err_ratelimited (dev,"Packed drop on port %s, error %d\n" , + port_static->name, ret); + goto drop_skb; + } + +if (ret) +return ret; + + port->seq_nums[MTK_RX ] = seq_num; +return 0 ; + +drop_skb: +dev_kfree_skb_any (skb); +return 0 ; +}
[skipped]
Quoted 51 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +51
-0+/** +* t7xx_port_proxy_node_control() - Create/remove node. +* @md: Modem. +* @port_msg: Message. +* +* Used to control create/remove device node. +* +* Return: +* * 0 - Success. +* * -EFAULT - Message check failure. +*/ +int t7xx_port_proxy_node_control (struct t7xx_modem *md,struct port_msg *port_msg) +{ +u32 *port_info_base = (void *)port_msg +sizeof (*port_msg); +struct device *dev = &md->t7xx_dev->pdev->dev; +unsigned int version, ports, i; + + version =FIELD_GET (PORT_MSG_VERSION ,le32_to_cpu (port_msg->info)); +if (version !=PORT_ENUM_VER || +le32_to_cpu (port_msg->head_pattern) !=PORT_ENUM_HEAD_PATTERN || +le32_to_cpu (port_msg->tail_pattern) !=PORT_ENUM_TAIL_PATTERN ) { +dev_err (dev,"Invalid port control message %x:%x:%x\n" , + version,le32_to_cpu (port_msg->head_pattern), +le32_to_cpu (port_msg->tail_pattern)); +return -EFAULT ; + } + + ports =FIELD_GET (PORT_MSG_PRT_CNT ,le32_to_cpu (port_msg->info)); +for (i =0 ; i < ports; i++) { +struct t7xx_port_static *port_static; +u32 *port_info = port_info_base + i; +struct t7xx_port *port; +unsigned int ch_id; +bool en_flag; + + ch_id =FIELD_GET (PORT_INFO_CH_ID , *port_info); + port =t7xx_proxy_get_port_by_ch (md->port_prox, ch_id); +if (!port) { +dev_dbg (dev,"Port:%x not found\n" , ch_id); +continue ; + } + + en_flag = !!(PORT_INFO_ENFLG & *port_info); + +if (t7xx_fsm_get_md_state (md->fsm_ctl) ==MD_STATE_READY ) { + port_static = port->port_static; + +if (en_flag) { +if (port_static->ops->enable_chl) + port_static->ops->enable_chl (port); + }else {
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 525
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +10
-0+if (port_static->ops->disable_chl) + port_static->ops->disable_chl (port); + } + }else { + port->chan_enable = en_flag; + } + } + +return 0 ; +}
Should most of this function (message parsing and verification code) be moved to the control port code, and left only the channel enable/disable code here? The port_msg structure definition should probably be moved to the control port code too.
I mean, the port message belongs more to the control protocol and the proxy should not care too much about this top level protocol internals.
[skipped]
drivers/net/wwan/t7xx/t7xx_port_proxy.c
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +3
-0+struct port_proxy { +int port_number; +struct t7xx_port_static *ports_shared;
This field is not actually used and probably should be removed.
Quoted 1 line
+ struct
t7xx_port*ports_private;
Since the 'ports_shared' field should be removed, this field can be renamed to 'ports' for simplicity.
BTW, the ports array can be moved to the end of the structure in form of flexible array:
struct t7xx_port ports[];
so it will be possible to allocate memory for the main proxy data and for ports array as a single block.
drivers/net/wwan/t7xx/t7xx_port_proxy.c
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +4
-0+struct list_head rx_ch_ports[PORT_CH_ID_MASK +1 ]; +struct list_head queue_ports[CLDMA_NUM ][MTK_QUEUES ]; +struct device *dev; +};
--
Sergey
Martinez, Ricardo
reviewerRe: [PATCH net-next v5 04/13] net: wwan: t7xx: Add port proxy infrastructure
Quoted 8 lines · Sergey Ryazanov
Quoted 5 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_portand operate as defined bystruct port_ops.[skipped]
...
Quoted 18 lines
drivers/net/wwan/t7xx/t7xx_port.h new file +18
-0+/* Channel ID and Message ID definitions. +* The channel number consists of peer_id(15:12) , channel_id(11:0) +* peer_id: +* 0:reserved, 1: to sAP, 2: to MD +*/ +enum port_ch { +/* to MD */ +PORT_CH_CONTROL_RX =0x2000 , +PORT_CH_CONTROL_TX =0x2001 , +PORT_CH_UART1_RX =0x2006 ,/* META */ +PORT_CH_UART1_TX =0x2008 , +PORT_CH_UART2_RX =0x200a ,/* AT */ +PORT_CH_UART2_TX =0x200c , +PORT_CH_MD_LOG_RX =0x202a ,/* MD logging */ +PORT_CH_MD_LOG_TX =0x202b , +PORT_CH_LB_IT_RX =0x203e ,/* Loop back test */ +PORT_CH_LB_IT_TX =0x203f , +PORT_CH_STATUS_RX =0x2043 ,/* Status polling */
Quoted 3 lines
There is no
STATUS_TXchannel, so how is the polling performed? Is it performed through theCONTROL_TXchannel? Or should the comment be changed to "status events"?
Currently there's no port listening to this channel, the suggested comment would be more accurate.
Quoted 25 lines
Quoted 25 lines
drivers/net/wwan/t7xx/t7xx_port.h new file +24
-0+PORT_CH_MIPC_RX =0x20ce ,/* MIPC */ +PORT_CH_MIPC_TX =0x20cf , +PORT_CH_MBIM_RX =0x20d0 , +PORT_CH_MBIM_TX =0x20d1 , +PORT_CH_DSS0_RX =0x20d2 , +PORT_CH_DSS0_TX =0x20d3 , +PORT_CH_DSS1_RX =0x20d4 , +PORT_CH_DSS1_TX =0x20d5 , +PORT_CH_DSS2_RX =0x20d6 , +PORT_CH_DSS2_TX =0x20d7 , +PORT_CH_DSS3_RX =0x20d8 , +PORT_CH_DSS3_TX =0x20d9 , +PORT_CH_DSS4_RX =0x20da , +PORT_CH_DSS4_TX =0x20db , +PORT_CH_DSS5_RX =0x20dc , +PORT_CH_DSS5_TX =0x20dd , +PORT_CH_DSS6_RX =0x20de , +PORT_CH_DSS6_TX =0x20df , +PORT_CH_DSS7_RX =0x20e0 , + PORT_CH_DSS7_TX = 0x20e1, +}; + + +struct t7xx_port_static {
...
Quoted 45 lines
Quoted 11 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +11
-0+int t7xx_port_recv_skb (struct t7xx_port *port,struct sk_buff *skb) +{ +struct ccci_header *ccci_h; +unsigned long flags; +u32 channel; +int ret =0 ; + +spin_lock_irqsave (&port->rx_wq.lock, flags); +if (port->rx_skb_list.qlen >= port->rx_length_th) { + port->flags |=PORT_F_RX_FULLED ; +spin_unlock_irqrestore (&port->rx_wq.lock, flags);drivers/net/wwan/t7xx/t7xx_port_proxy.c line 178
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +10
-0+ +return -ENOBUFS ; + } + ccci_h = (struct ccci_header *)skb->data; + port->flags &= ~PORT_F_RX_FULLED ; +if (port->flags &PORT_F_RX_ADJUST_HEADER ) +t7xx_port_adjust_skb (port, skb); + channel =FIELD_GET (CCCI_H_CHN_FLD ,le32_to_cpu (ccci_h->status)); +if (channel ==PORT_CH_STATUS_RX ) { + ret = port->skb_handler (port, skb);This handler will never be called. A message with channel =
PORT_CH_STATUS_RXwill be dropped in thet7xx_port_proxy_recv_skb()function, since the corresponding port is nonexistent.drivers/net/wwan/t7xx/t7xx_port_proxy.c line 189
Quoted 11 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +11
-0+ }else { +if (port->wwan_port) +wwan_port_rx (port->wwan_port, skb); +else +__skb_queue_tail (&port->rx_skb_list, skb); + } +spin_unlock_irqrestore (&port->rx_wq.lock, flags); + +wake_up_all (&port->rx_wq); +return ret; +}Whole this function looks like a big unintentional duct tape. On the one hand, each port type has a specific
recv_skbcallback. But in fact, all message processing paths pass through this place. And here the single function forced to take into account the specialties of each port type:
a) immediately passes status events to the handler via the indirect call;
b) enqueues control messages to the rx queue;
c) directly passes WWAN management (MBIM & AT) message to the WWAN subsystem.
Quoted 12 lines
I would like to suggest the following reworking plan for the function:
1) move the common processing code (header stripping code) to thet7xx_port_proxy_recv_skb()function, where it belongs;
2) add a dedicated port ops for thePORT_CH_STATUS_RXchannel and callcontrol_msg_handler()from itsrecv_skbcallback (lets call itt7xx_port_status_recv_skb()); this will solve both issues: status messages will no more dropped and status message hook will be removed;
3) move thewwan_port_rx()call to thet7xx_port_wwan_recv_skb()callback; this will remove another one hook;
4) finally renamet7xx_port_recv_skb()tot7xx_port_enqueue_skb(), since after the hooks removing, the only purpose of this function will be to enqueue received skb(s).
Thanks for the suggestions.
After the changes this function will just figure out the channel by reading the CCCI header and invoke the corresponding port's recv_skb().
I do not think we want to remove the CCCI header yet since recv_skb() may fail and the caller might decide to try again later.
The generic t7xx_port_enqueue_skb() function will remove the CCCI header before enqueuing the skb, t7xx_port_wwan_recv_skb() should do the same before calling wwan_port_rx().
...
Quoted 10 lines
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +10
-0+{ +struct t7xx_port_static *port_static = port->port_static; +struct t7xx_fsm_ctl *ctl = port->t7xx_dev->md->fsm_ctl; +struct cldma_ctrl *md_ctrl; +enum md_state md_state; +unsigned int fsm_state; + + md_state =t7xx_fsm_get_md_state (ctl); + + fsm_state =t7xx_fsm_get_ctl_state (ctl);
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 236
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +6
-0+if (fsm_state !=FSM_STATE_PRE_START ) { +if (md_state ==MD_STATE_WAITING_FOR_HS1 || md_state ==MD_STATE_WAITING_FOR_HS2 ) +return -ENODEV ; + +if (md_state ==MD_STATE_EXCEPTION && port_static->tx_ch !=PORT_CH_MD_LOG_TX && + port_static->tx_ch !=PORT_CH_UART1_TX )There are no ports defined for
PORT_CH_MD_LOG_TXandPORT_CH_UART1_TXchannels, should this check be removed?
PORT_CH_UART1_TX should be removed, but PORT_CH_MD_LOG_TX is going to be used by the upcoming modem logging port feature.
...
Ricardo Martinez
reviewerPATCH v5 5/13 net: wwan: t7xx: Add control port
In reply to Ricardo MartinezFrom: 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.
From a WWAN framework perspective:
--- drivers/net/wwan/t7xx/Makefile | 1 + drivers/net/wwan/t7xx/t7xx_modem_ops.c | 249 ++++++++++++++++++++- drivers/net/wwan/t7xx/t7xx_modem_ops.h | 3 + drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c | 205 +++++++++++++++++ drivers/net/wwan/t7xx/t7xx_port_proxy.c | 74 +++++- drivers/net/wwan/t7xx/t7xx_port_proxy.h | 30 +++ drivers/net/wwan/t7xx/t7xx_state_monitor.c | 3 + drivers/net/wwan/t7xx/t7xx_state_monitor.h | 2 + 8 files changed, 563 insertions(+), 4 deletions(-) create mode 100644 drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c
drivers/net/wwan/t7xx/Makefile +1 -0
@@ -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 +246 -3
304 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_modem_ops.h +3 -0
@@ -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 +205 -0
205 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_port_proxy.c +73 -1
92 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_port_proxy.h +30 -0
@@ -40,6 +40,27 @@ struct port_proxy {struct device *dev; }; +struct ctrl_msg_header { +__le32 ctrl_msg_id; +__le32 ex_msg; +__le32 data_length; +}; + +/* Control identification numbers for AP<->MD messages */ +#define CTL_ID_HS1_MSG 0x0 +#define CTL_ID_HS2_MSG 0x1 +#define CTL_ID_HS3_MSG 0x2 +#define CTL_ID_MD_EX 0x4 +#define CTL_ID_DRV_VER_ERROR 0x5 +#define CTL_ID_MD_EX_ACK 0x6 +#define CTL_ID_MD_EX_PASS 0x8 +#define CTL_ID_PORT_ENUM 0x9 + +/* Modem exception check identification code - "EXCP" */ +#define MD_EX_CHK_ID 0x45584350 +/* Modem exception check acknowledge identification code - "EREC" */ +#define MD_EX_CHK_ACK_ID 0x45524543 +struct port_msg {__le32 head_pattern;__le32 info;
@@ -58,12 +79,21 @@ 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_tx_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); +void t7xx_ccci_header_init (struct ccci_header *ccci_h,unsigned int pkt_header, +size_t pkt_len,enum port_ch ch,unsigned int ex_msg); +void t7xx_ctrl_msg_header_init (struct ctrl_msg_header *ctrl_msg_h,unsigned int msg_id, +unsigned int ex_msg,unsigned int len);#endif /* __T7XX_PORT_PROXY_H__ */
drivers/net/wwan/t7xx/t7xx_state_monitor.c +3 -0
@@ -293,6 +293,9 @@ static int 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 );return -ETIMEDOUT ; }
drivers/net/wwan/t7xx/t7xx_state_monitor.h +2 -0
@@ -38,9 +38,11 @@ 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_MAX };
Signature · 1 line
2.17.1
Re: [PATCH net-next v5 05/13] net: wwan: t7xx: Add control port
Quoted 21 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.
Signed-off-by Haijun Liu <[email protected]>Signed-off-by Chandrashekar Devegowda <[email protected]>Co-developed-by Ricardo Martinez <[email protected]>Signed-off-by Ricardo Martinez <[email protected]>Quoted 1 line
From a WWAN framework perspective:
Reviewed-by Loic Poulain <[email protected]>---
(quoted diff) +0
-0@@ -412,6 +651,7 @@ static struct t7xx_modem *t7xx_md_alloc(struct t7xx_pci_dev *t7xx_dev)
...
drivers/net/wwan/t7xx/t7xx_modem_ops.c static struct t7xx_modem *t7xx_md_alloc(struct t7xx_pci_dev *t7xx_dev) · line 654
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c +1
-0md->core_md.ready = false; + md->core_md.handshake_ongoing = false;
These assignments are not needed with mem from kzalloc.
Signature · 1 line
i.
Sergey Ryazanov
maintainerRe: [PATCH net-next v5 05/13] net: wwan: t7xx: Add control port
In reply to Ricardo MartinezQuoted 10 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.
[skipped]
Quoted 27 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c +27
-0+struct feature_query { +__le32 head_pattern; +u8 feature_set[FEATURE_COUNT ]; +__le32 tail_pattern; +}; + +static void t7xx_prepare_host_rt_data_query (struct t7xx_sys_info *core) +{ +struct t7xx_port_static *port_static = core->ctl_port->port_static; +struct ctrl_msg_header *ctrl_msg_h; +struct feature_query *ft_query; +struct ccci_header *ccci_h; +struct sk_buff *skb; +size_t packet_size; + + packet_size =sizeof (*ccci_h) +sizeof (*ctrl_msg_h) +sizeof (*ft_query); + skb =__dev_alloc_skb (packet_size,GFP_KERNEL ); +if (!skb) +return ; + +skb_put (skb, packet_size); + + ccci_h = (struct ccci_header *)skb->data; +t7xx_ccci_header_init (ccci_h,0 , packet_size, port_static->tx_ch,0 ); + ccci_h->status &=cpu_to_le32 (~CCCI_H_SEQ_FLD ); + + ctrl_msg_h = (struct ctrl_msg_header *)(skb->data +sizeof (*ccci_h));
drivers/net/wwan/t7xx/t7xx_modem_ops.c static void t7xx_md_sys_sw_init(struct t7xx_pci_dev *t7xx_dev) · line 369
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c +10
-0+t7xx_ctrl_msg_header_init (ctrl_msg_h,CTL_ID_HS1_MSG ,0 ,sizeof (*ft_query)); + + ft_query = (struct feature_query *)(skb->data +sizeof (*ccci_h) +sizeof (*ctrl_msg_h)); + ft_query->head_pattern =cpu_to_le32 (MD_FEATURE_QUERY_ID ); +memcpy (ft_query->feature_set, core->feature_set,FEATURE_COUNT ); + ft_query->tail_pattern =cpu_to_le32 (MD_FEATURE_QUERY_ID ); + +/* Send HS1 message to device */ +t7xx_port_proxy_send_skb (core->ctl_port, skb); +}
I do not care too much, but this code and many other places could be greatly simplified. It looks like the modem communication protocol has a layered design, skb and its API are also designed to handle layered protocols. It just needs to rearrange the code a bit.
For example, to avoid manual accounting of each header in the stack, skb allocation can be implemented using a stack of allocation functions:
struct sk_buff *t7xx_port_alloc_skb(int payload)
{
struct sk_buff *skb = alloc_skb(payload + sizeof(struct ccci_header), ...);
if (skb)
skb_reserve(skb, sizeof(struct ccci_header));
return skb;
}struct sk_buff *t7xx_ctrl_alloc_skb(int payload)
{
struct sk_buff *skb = t7xx_port_alloc_skb(payload + sizeof(struct
ctlr_msg_header), ...);
if (skb)
skb_reserve(skb, sizeof(struct ctrl_msg_header));
return skb;
}Message sending operation can also be perfectly stacked:
int t7xx_port_proxy_send_skb(*port, *skb)
{
struct ccci_header *ccci_h = skb_push(skb, sizeof(*ccci_h));
/* Build CCCI header (including seqno assignment) */
ccci_h->packet_len = cpu_to_le32(skb->len);
res = cldma_send_skb(..., skb, ...);
if (res)
return res;
/* Update seqno counter here */
return 0;
}int t7xx_ctrl_send_msg(port, msg_id, skb)
{
int len = skb->len; /* Preserve payload len */
struct ctrl_msg_header *ctrl_msg_h = skb_push(skb, sizeof(*ctrl_msg_h));
/* Build ctrl msg header here */
ctrl_msg_h->data_length = cpu_to_le32(len);
return t7xx_port_proxy_send_skb(port, skb);
}So the above features request becomes as simple as:
void t7xx_prepare_host_rt_data_query(struct t7xx_sys_info *core)
{
struct feature_query *ft_query;
struct sk_buff *skb;
skb = t7xx_ctrl_alloc_skb(sizeof(*ft_query));
if (!skb)
return;
ft_query = skb_put(skb, sizeof(*ft_query));
/* Build features request here */
if (t7xx_ctrl_send_msg(core->ctl_port, CTL_ID_HS1_MSG, skb))
kfree_skb(skb);
}Once the allocation and sending functions are implemented in a stacked way, many other places can be simplified in a similar way.
[skipped]
Quoted 34 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c +34
-0+static void t7xx_core_hk_handler (struct t7xx_modem *md,struct t7xx_fsm_ctl *ctl, +enum t7xx_fsm_event_state event_id, +enum t7xx_fsm_event_state err_detect) +{ +struct t7xx_sys_info *core_info = &md->core_md; +struct device *dev = &md->t7xx_dev->pdev->dev; +struct t7xx_fsm_event *event, *event_next; +unsigned long flags; +void *event_data; +int ret; + +t7xx_prepare_host_rt_data_query (core_info); + +while (!kthread_should_stop ()) { +bool event_received = false; + +spin_lock_irqsave (&ctl->event_lock, flags); +list_for_each_entry_safe (event, event_next, &ctl->event_queue, entry) { +if (event->event_id == err_detect) { +list_del (&event->entry); +spin_unlock_irqrestore (&ctl->event_lock, flags); +dev_err (dev,"Core handshake error event received\n" ); + goto err_free_event; + }else if (event->event_id == event_id) { +list_del (&event->entry); + event_received = true; +break ; + } + } +spin_unlock_irqrestore (&ctl->event_lock, flags); + +if (event_received) +break ; +
drivers/net/wwan/t7xx/t7xx_modem_ops.c static void t7xx_md_sys_sw_init(struct t7xx_pci_dev *t7xx_dev) · line 531
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c +10
-0+wait_event_interruptible (ctl->event_wq, !list_empty (&ctl->event_queue) || +kthread_should_stop ()); +if (kthread_should_stop ()) + goto err_free_event; + } + +if (ctl->exp_flg) + goto err_free_event; + + event_data = (void *)event +sizeof (*event);
In the V2, the event structure has a data field. But then it was dropped and now the attached data offset is manually calculated. Why did you do this, why event->data is not suitable here?
Quoted 21 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c +21
-0+ ret =t7xx_parse_host_rt_data (ctl, core_info, dev, event_data, event->length); +if (ret) { +dev_err (dev,"Host failure parsing runtime data: %d\n" , ret); + goto err_free_event; + } + +if (ctl->exp_flg) + goto err_free_event; + + ret =t7xx_prepare_device_rt_data (core_info, dev, event_data, event->length); +if (ret) { +dev_err (dev,"Device failure parsing runtime data: %d" , ret); + goto err_free_event; + } + + core_info->ready = true; + core_info->handshake_ongoing = false; +wake_up (&ctl->async_hk_wq); +err_free_event: +kfree (event); +}
[skipped]
drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c line 175
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c new file +5
-0+static int port_ctl_init (struct t7xx_port *port) +{ +struct t7xx_port_static *port_static = port->port_static; + + port->skb_handler = &control_msg_handler;
& is not necessary here and only misguides readers.
Quoted 9 lines
drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c new file +9
-0+ port->thread =kthread_run (port_ctl_rx_thread, port,"%s" , port_static->name); +if (IS_ERR (port->thread)) { +dev_err (port->dev,"Failed to start port control thread\n" ); +return PTR_ERR (port->thread); + } + + port->rx_length_th =CTRL_QUEUE_MAXLEN ; +return 0 ; +}
[skipped]
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 61
Quoted 11 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c +10
-1-static struct t7xx_port_static t7xx_md_ports[1 ]; +static struct t7xx_port_static t7xx_md_ports[] = { + { + .tx_ch =PORT_CH_CONTROL_TX , + .rx_ch =PORT_CH_CONTROL_RX , + .txq_index =Q_IDX_CTRL , + .rxq_index =Q_IDX_CTRL , + .txq_exp_index =0 , + .rxq_exp_index =0 , + .path_id =CLDMA_ID_MD , + .flags =0 ,
Zero initializer is not needed here, a static variable is filled with zeros automatically.
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c +4
-0+ .ops = &ctl_port_ops, + .name = "t7xx_ctrl", + }, +};
[skipped]
drivers/net/wwan/t7xx/t7xx_port_proxy.c static void t7xx_proxy_setup_ch_mapping(struct port_proxy *port_prox) · line 306
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c +2
-0+void t7xx_port_proxy_send_msg_to_md (struct port_proxy *port_prox,enum port_ch ch, +unsigned int msg,unsigned int ex_msg)
This function is called only from the control port code and only with ch = PORT_CH_CONTROL_TX, so I would like to recommend to move it there and drop the ch argument.
Quoted 25 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c +25
-0+{ +struct ctrl_msg_header *ctrl_msg_h; +struct ccci_header *ccci_h; +struct t7xx_port *port; +struct sk_buff *skb; +int ret; + + port =t7xx_proxy_get_port_by_ch (port_prox, ch); +if (!port) +return ; + + skb =__dev_alloc_skb (sizeof (*ccci_h),GFP_KERNEL ); +if (!skb) +return ; + +if (ch ==PORT_CH_CONTROL_TX ) { + ccci_h = (struct ccci_header *)(skb->data); +t7xx_ccci_header_init (ccci_h,CCCI_HEADER_NO_DATA , +sizeof (*ctrl_msg_h) +sizeof (*ccci_h), ch,0 ); + ctrl_msg_h = (struct ctrl_msg_header *)(skb->data +sizeof (*ccci_h)); +t7xx_ctrl_msg_header_init (ctrl_msg_h, msg, ex_msg,0 ); +skb_put (skb,sizeof (*ccci_h) +sizeof (*ctrl_msg_h)); + }else { + ccci_h =skb_put (skb,sizeof (*ccci_h)); +t7xx_ccci_header_init (ccci_h,CCCI_HEADER_NO_DATA , msg, ch, ex_msg);
drivers/net/wwan/t7xx/t7xx_port_proxy.c static void t7xx_proxy_setup_ch_mapping(struct port_proxy *port_prox) · line 341
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c +10
-0+ } + + ret =t7xx_port_proxy_send_skb (port, skb); +if (ret) { +struct t7xx_port_static *port_static = port->port_static; + +dev_kfree_skb_any (skb); +dev_err (port->dev,"port%s send to MD fail\n" , port_static->name); + } +}
--
Sergey
Martinez, Ricardo
reviewerRe: [PATCH net-next v5 05/13] net: wwan: t7xx: Add control port
Hi Sergey,
Quoted 13 lines · Sergey Ryazanov
Quoted 11 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.
...
Quoted 39 lines
Quoted 39 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c +39
-0+static void t7xx_core_hk_handler (struct t7xx_modem *md,struct t7xx_fsm_ctl *ctl, +enum t7xx_fsm_event_state event_id, +enum t7xx_fsm_event_state err_detect) +{ +struct t7xx_sys_info *core_info = &md->core_md; +struct device *dev = &md->t7xx_dev->pdev->dev; +struct t7xx_fsm_event *event, *event_next; +unsigned long flags; +void *event_data; +int ret; + +t7xx_prepare_host_rt_data_query (core_info); + +while (!kthread_should_stop ()) { +bool event_received = false; + +spin_lock_irqsave (&ctl->event_lock, flags); +list_for_each_entry_safe (event, event_next, &ctl->event_queue, entry) { +if (event->event_id == err_detect) { +list_del (&event->entry); +spin_unlock_irqrestore (&ctl->event_lock, flags); +dev_err (dev,"Core handshake error event received\n" ); + goto err_free_event; + }else if (event->event_id == event_id) { +list_del (&event->entry); + event_received = true; +break ; + } + } +spin_unlock_irqrestore (&ctl->event_lock, flags); + +if (event_received) +break ; + +wait_event_interruptible (ctl->event_wq, !list_empty (&ctl->event_queue) || +kthread_should_stop ()); +if (kthread_should_stop ()) + goto err_free_event; + }
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c static void t7xx_md_sys_sw_init(struct t7xx_pci_dev *t7xx_dev) · line 531
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c +5
-0+ +if (ctl->exp_flg) + goto err_free_event; + + event_data = (void *)event +sizeof (*event);In the V2, the event structure has a data field. But then it was dropped and now the attached data offset is manually calculated. Why did you do this, why
event->datais not suitable here?
It was removed along with other zero length arrays, although it was declared as an empty array.
The next iteration will use C99 flexible arrays where required, instead of calculating the data offset manually.
...
Ricardo Martinez
reviewerPATCH v5 6/13 net: wwan: t7xx: Add AT and MBIM WWAN ports
In reply to Ricardo MartinezFrom: 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.
From a WWAN framework perspective:
--- 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 | 210 ++++++++++++++++++++++++ 4 files changed, 236 insertions(+) create mode 100644 drivers/net/wwan/t7xx/t7xx_port_wwan.c
drivers/net/wwan/t7xx/Makefile +1 -0
@@ -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
@@ -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 =CLDMA_ID_MD , + .flags =0 , + .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 =CLDMA_ID_MD , + .flags =0 , + .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
@@ -80,6 +80,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 +210 -0
210 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH net-next v5 06/13] net: wwan: t7xx: Add AT and MBIM WWAN ports
Quoted 17 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.Signed-off-by Chandrashekar Devegowda <[email protected]>Co-developed-by Ricardo Martinez <[email protected]>Signed-off-by Ricardo Martinez <[email protected]>Quoted 1 line
From a WWAN framework perspective:
Reviewed-by Loic Poulain <[email protected]>---
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +2
-0+static int t7xx_port_ctrl_tx (struct wwan_port *port,struct sk_buff *skb) +{
...
drivers/net/wwan/t7xx/t7xx_port_wwan.c line 67
Quoted 1 line
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +1
-0+if (!len || !port_private->rx_length_th || !port_private->chan_enable)
It raises eyebrows to see rx_xx being used on something called "tx". Is it trying to tests port not inited?
Signature · 1 line
i.
Sergey Ryazanov
maintainerRe: [PATCH net-next v5 06/13] net: wwan: t7xx: Add AT and MBIM WWAN ports
In reply to Ricardo MartinezQuoted 6 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.
[skipped]
Quoted 25 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +25
-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_len, alloc_size, txq_mtu =CLDMA_MTU ; +struct t7xx_port_static *port_static; +unsigned int len, i, packets; +struct t7xx_fsm_ctl *ctl; +enum md_state md_state; + + len = skb->len; +if (!len || !port_private->rx_length_th || !port_private->chan_enable) +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 ; + } + + alloc_size =min_t (size_t, txq_mtu, len +CCCI_HEADROOM ); + actual_len = alloc_size -CCCI_HEADROOM ; + packets =DIV_ROUND_UP (len, txq_mtu -CCCI_HEADROOM );
drivers/net/wwan/t7xx/t7xx_port_wwan.c line 91
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +10
-0+ +for (i =0 ; i < packets; i++) { +struct ccci_header *ccci_h; +struct sk_buff *skb_ccci; +int ret; + +if (packets >1 && packets == i +1 ) { + actual_len = len % (txq_mtu -CCCI_HEADROOM ); + alloc_size = actual_len +CCCI_HEADROOM ; + }
Why do you track the packet number? Why not track the offset in the passed data? E.g.:
for (off = 0; off < len; off += chunklen) {
chunklen = min(len - off, CLDMA_MTU - sizeof(struct ccci_header);
skb_ccci = alloc_skb(chunklen + sizeof(struct ccci_header), ...);
skb_put_data(skb_ccci, skb->data + off, chunklen);
/* Send skb_ccci */
}Quoted 9 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +9
-0+ skb_ccci =__dev_alloc_skb (alloc_size,GFP_KERNEL ); +if (!skb_ccci) +return -ENOMEM ; + + ccci_h =skb_put (skb_ccci,sizeof (*ccci_h)); +t7xx_ccci_header_init (ccci_h,0 , actual_len +sizeof (*ccci_h), + port_static->tx_ch,0 ); +skb_put_data (skb_ccci, skb->data + i * (txq_mtu -CCCI_HEADROOM ), actual_len); +t7xx_port_proxy_set_tx_seq_num (port_private, ccci_h);
drivers/net/wwan/t7xx/t7xx_port_wwan.c line 111
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); +if (ret) { +dev_kfree_skb_any (skb_ccci); +dev_err (port_private->dev,"Write error on %s port, %d\n" , + port_static->name, ret); +return ret; + } + + port_private->seq_nums[MTK_TX ]++;
Sequence number tracking as well as CCCI header construction are common operations, so why not move them to t7xx_port_send_skb_to_md()?
drivers/net/wwan/t7xx/t7xx_port_wwan.c line 116
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +5
-0+ } + +dev_kfree_skb (skb); +return 0 ; +}
--
Sergey
Martinez, Ricardo
reviewerRe: [PATCH net-next v5 06/13] net: wwan: t7xx: Add AT and MBIM WWAN ports
Quoted 48 lines · Sergey Ryazanov
Quoted 6 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.[skipped]
Quoted 25 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +25
-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_len, alloc_size, txq_mtu =CLDMA_MTU ; +struct t7xx_port_static *port_static; +unsigned int len, i, packets; +struct t7xx_fsm_ctl *ctl; +enum md_state md_state; + + len = skb->len; +if (!len || !port_private->rx_length_th || !port_private->chan_enable) +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 ; + } + + alloc_size =min_t (size_t, txq_mtu, len +CCCI_HEADROOM ); + actual_len = alloc_size -CCCI_HEADROOM ; + packets =DIV_ROUND_UP (len, txq_mtu -CCCI_HEADROOM );drivers/net/wwan/t7xx/t7xx_port_wwan.c line 91
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +10
-0+ +for (i =0 ; i < packets; i++) { +struct ccci_header *ccci_h; +struct sk_buff *skb_ccci; +int ret; + +if (packets >1 && packets == i +1 ) { + actual_len = len % (txq_mtu -CCCI_HEADROOM ); + alloc_size = actual_len +CCCI_HEADROOM ; + }Why do you track the packet number? Why not track the offset in the passed data? E.g.:
Quoted 6 lines
for (off = 0; off < len; off += chunklen) {
chunklen = min(len - off, CLDMA_MTU - sizeof(struct ccci_header);
skb_ccci = alloc_skb(chunklen + sizeof(struct ccci_header), ...);
skb_put_data(skb_ccci, skb->data + off, chunklen);
/* Send skb_ccci */
}Sure, I'll make that change.
Quoted 13 lines
Quoted 13 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +13
-0+ skb_ccci =__dev_alloc_skb (alloc_size,GFP_KERNEL ); +if (!skb_ccci) +return -ENOMEM ; + + ccci_h =skb_put (skb_ccci,sizeof (*ccci_h)); +t7xx_ccci_header_init (ccci_h,0 , actual_len +sizeof (*ccci_h), + port_static->tx_ch,0 ); +skb_put_data (skb_ccci, skb->data + i * (txq_mtu -CCCI_HEADROOM ), actual_len); +t7xx_port_proxy_set_tx_seq_num (port_private, ccci_h); + + ret =t7xx_port_send_skb_to_md (port_private, skb_ccci); +if (ret) { +dev_kfree_skb_any (skb_ccci);
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c line 111
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +6
-0+dev_err (port_private->dev,"Write error on %s port, %d\n" , + port_static->name, ret); +return ret; + } + + port_private->seq_nums[MTK_TX ]++;Sequence number tracking as well as CCCI header construction are common operations, so why not move them to
t7xx_port_send_skb_to_md()?
Sequence number should be set as part of CCCI header construction.
I think it's a bit more readable to initialize the CCCI header right after the corresponding skb_put(). Not a big deal, any thoughts?
Note that the upcoming fw update feature doesn't require a CCCI header, so we could rename the TX function as t7xx_port_send_ccci_skb_to_md(), this would give a hint that it is taking care of the CCCI header.
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c line 116
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +5
-0+ } + +dev_kfree_skb (skb); +return 0 ; +}--
Sergey
Sergey Ryazanov
maintainerRe: [PATCH net-next v5 06/13] net: wwan: t7xx: Add AT and MBIM WWAN ports
Quoted 82 lines · Ricardo
Quoted 49 lines · Sergey Ryazanov
Quoted 6 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.[skipped]
Quoted 25 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +25
-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_len, alloc_size, txq_mtu =CLDMA_MTU ; +struct t7xx_port_static *port_static; +unsigned int len, i, packets; +struct t7xx_fsm_ctl *ctl; +enum md_state md_state; + + len = skb->len; +if (!len || !port_private->rx_length_th || !port_private->chan_enable) +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 ; + } + + alloc_size =min_t (size_t, txq_mtu, len +CCCI_HEADROOM ); + actual_len = alloc_size -CCCI_HEADROOM ; + packets =DIV_ROUND_UP (len, txq_mtu -CCCI_HEADROOM );drivers/net/wwan/t7xx/t7xx_port_wwan.c line 91
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +10
-0+ +for (i =0 ; i < packets; i++) { +struct ccci_header *ccci_h; +struct sk_buff *skb_ccci; +int ret; + +if (packets >1 && packets == i +1 ) { + actual_len = len % (txq_mtu -CCCI_HEADROOM ); + alloc_size = actual_len +CCCI_HEADROOM ; + }Why do you track the packet number? Why not track the offset in the passed data? E.g.:
Quoted 6 lines
for (off = 0; off < len; off += chunklen) { chunklen = min(len - off, CLDMA_MTU - sizeof(struct ccci_header); skb_ccci = alloc_skb(chunklen + sizeof(struct ccci_header), ...); skb_put_data(skb_ccci, skb->data + off, chunklen); /* Send skb_ccci */ }Sure, I'll make that change.
Quoted 14 lines
Quoted 14 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +14
-0+ skb_ccci =__dev_alloc_skb (alloc_size,GFP_KERNEL ); +if (!skb_ccci) +return -ENOMEM ; + + ccci_h =skb_put (skb_ccci,sizeof (*ccci_h)); +t7xx_ccci_header_init (ccci_h,0 , actual_len +sizeof (*ccci_h), + port_static->tx_ch,0 ); +skb_put_data (skb_ccci, skb->data + i * (txq_mtu -CCCI_HEADROOM ), actual_len); +t7xx_port_proxy_set_tx_seq_num (port_private, ccci_h); + + ret =t7xx_port_send_skb_to_md (port_private, skb_ccci); +if (ret) { +dev_kfree_skb_any (skb_ccci); + dev_err(port_private->dev, "Write error on %s port, %d\n",Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c line 111
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +5
-0+ port_static->name, ret); +return ret; + } + + port_private->seq_nums[MTK_TX ]++;Sequence number tracking as well as CCCI header construction are common operations, so why not move them to
t7xx_port_send_skb_to_md()?
Quoted 4 lines
Sequence number should be set as part of CCCI header construction.
I think it's a bit more readable to initialize the CCCI header right after the corresponding
skb_put(). Not a big deal, any thoughts?
I do not _think_ creating the CCCI header in the WWAN or CTRL port functions is any good idea. In case of stacked protocols, each layer should create its own header, pass the packet down the stack, and then a next layer will create a next header.
In case of the CTRL port, this means that the control port code should take an opaque data block from an upper layer (e.g. features request), prepend it with a control msg header, and pass it down the stack to the port proxy layer, where the CCCI header will be prepended.
In case a WWAN port, all headers are passed from user space, so there шы nothing to prepend. And the only remaining function is to fragment a user input, and then pass all the fragments to the port proxy layer, where the CCCI header will be prepended.
This way, you do not overload the CTRL/WWAN port with code of other protocols (i.e. CCCI), reduce code duplication. Which in itself improves the code maintainability and future development. Creating a CCCI header at the WWAN port layer is like forcing a user to manually create IP and UDP headers before writing a data block into a network socket :)
Anyway, it is up to you to decide exactly how to create headers and assign sequence numbers. I just wanted to point out the code inconsistency. It does not make the code wrong, it just makes the code look stranger.
Quoted 3 lines
Note that the upcoming fw update feature doesn't require a CCCI header, so we could rename the TX function as
t7xx_port_send_ccci_skb_to_md(), this would give a hint that it is taking care of the CCCI header.
Does this mean the firmware upgrade does not utilize the channel id, and just pushes data directly to a specific CLDMA queue? In that case it looks like the firmware upgrade code needs to entirely bypass the port proxy layer and communicate directly with CLDMA. Isn't it?
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +5
-0+ } + +dev_kfree_skb (skb); +return 0 ; +}
Signature · 1 line
Sergey
Martinez, Ricardo
reviewerRe: [PATCH net-next v5 06/13] net: wwan: t7xx: Add AT and MBIM WWAN ports
Quoted 106 lines · Sergey Ryazanov
Quoted 78 lines · Ricardo
Quoted 48 lines · Sergey Ryazanov
Quoted 6 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.[skipped]
Quoted 25 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +25
-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_len, alloc_size, txq_mtu =CLDMA_MTU ; +struct t7xx_port_static *port_static; +unsigned int len, i, packets; +struct t7xx_fsm_ctl *ctl; +enum md_state md_state; + + len = skb->len; +if (!len || !port_private->rx_length_th || !port_private->chan_enable) +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 ; + } + + alloc_size =min_t (size_t, txq_mtu, len +CCCI_HEADROOM ); + actual_len = alloc_size -CCCI_HEADROOM ; + packets =DIV_ROUND_UP (len, txq_mtu -CCCI_HEADROOM );drivers/net/wwan/t7xx/t7xx_port_wwan.c line 91
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +10
-0+ +for (i =0 ; i < packets; i++) { +struct ccci_header *ccci_h; +struct sk_buff *skb_ccci; +int ret; + +if (packets >1 && packets == i +1 ) { + actual_len = len % (txq_mtu -CCCI_HEADROOM ); + alloc_size = actual_len +CCCI_HEADROOM ; + }Why do you track the packet number? Why not track the offset in the passed data? E.g.:
Quoted 6 lines
for (off = 0; off < len; off += chunklen) { chunklen = min(len - off, CLDMA_MTU - sizeof(struct ccci_header); skb_ccci = alloc_skb(chunklen + sizeof(struct ccci_header), ...); skb_put_data(skb_ccci, skb->data + off, chunklen); /* Send skb_ccci */ }Sure, I'll make that change.
Quoted 13 lines
Quoted 13 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +13
-0+ skb_ccci =__dev_alloc_skb (alloc_size,GFP_KERNEL ); +if (!skb_ccci) +return -ENOMEM ; + + ccci_h =skb_put (skb_ccci,sizeof (*ccci_h)); +t7xx_ccci_header_init (ccci_h,0 , actual_len +sizeof (*ccci_h), + port_static->tx_ch,0 ); +skb_put_data (skb_ccci, skb->data + i * (txq_mtu -CCCI_HEADROOM ), actual_len); +t7xx_port_proxy_set_tx_seq_num (port_private, ccci_h); + + ret =t7xx_port_send_skb_to_md (port_private, skb_ccci); +if (ret) { +dev_kfree_skb_any (skb_ccci);Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c line 111
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +6
-0+dev_err (port_private->dev,"Write error on %s port, %d\n" , + port_static->name, ret); +return ret; + } + + port_private->seq_nums[MTK_TX ]++;Sequence number tracking as well as CCCI header construction are common operations, so why not move them to
t7xx_port_send_skb_to_md()?Quoted 4 lines
Sequence number should be set as part of CCCI header construction.
I think it's a bit more readable to initialize the CCCI header right after the corresponding
skb_put(). Not a big deal, any thoughts?I do not _think_ creating the CCCI header in the WWAN or CTRL port functions is any good idea. In case of stacked protocols, each layer should create its own header, pass the packet down the stack, and then a next layer will create a next header.
In case of the CTRL port, this means that the control port code should take an opaque data block from an upper layer (e.g. features request), prepend it with a control msg header, and pass it down the stack to the port proxy layer, where the CCCI header will be prepended.
In case a WWAN port, all headers are passed from user space, so there шы nothing to prepend. And the only remaining function is to fragment a user input, and then pass all the fragments to the port proxy layer, where the CCCI header will be prepended.
This way, you do not overload the CTRL/WWAN port with code of other protocols (i.e. CCCI), reduce code duplication. Which in itself improves the code maintainability and future development. Creating a CCCI header at the WWAN port layer is like forcing a user to manually create IP and UDP headers before writing a data block into a network socket :)
Quoted 4 lines
Anyway, it is up to you to decide exactly how to create headers and assign sequence numbers. I just wanted to point out the code inconsistency. It does not make the code wrong, it just makes the code look stranger.
Agree, the next iteration will implement a layered approach.
Quoted 7 lines
Quoted 3 lines
Note that the upcoming fw update feature doesn't require a CCCI header, so we could rename the TX function as
t7xx_port_send_ccci_skb_to_md(), this would give a hint that it is taking care of the CCCI header.Does this mean the firmware upgrade does not utilize the channel id, and just pushes data directly to a specific CLDMA queue? In that case it looks like the firmware upgrade code needs to entirely bypass the port proxy layer and communicate directly with CLDMA. Isn't it?
It could bypass port proxy, or it could use a new helper function implemented for the layered approach, this function (t7xx_port_send_raw_skb) sends an skb to the right CLDMA instance and queue based on the port configuration.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +5
-0+ } + +dev_kfree_skb (skb); +return 0 ; +}
Ricardo Martinez
reviewerPATCH v5 7/13 net: wwan: t7xx: Data path HW layer
In reply to Ricardo MartinezFrom: 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.
From a WWAN framework perspective:
--- drivers/net/wwan/t7xx/t7xx_dpmaif.c | 1294 +++++++++++++++++++++++++++ drivers/net/wwan/t7xx/t7xx_dpmaif.h | 179 ++++ drivers/net/wwan/t7xx/t7xx_reg.h | 213 +++++ 3 files changed, 1686 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 +1294 -0
@@ -0,0 +1,1294 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) 2021, MediaTek Inc. +* Copyright (c) 2021-2022, 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_reg.h" + +#define ioread32_poll_timeout_atomic (addr, val, cond, delay_us, timeout_us) \ + readx_poll_timeout_atomic(ioread32, addr, val, cond, delay_us, timeout_us) + +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 =ioread32_poll_timeout_atomic (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 =ioread32_poll_timeout_atomic (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_intr (struct dpmaif_hw_info *hw_info,unsigned int q_num) +{ +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 =ioread32_poll_timeout_atomic (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 (hw_info->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_hw_info *hw_info,unsigned int q_num) +{ +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 =ioread32_poll_timeout_atomic (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 (hw_info->dev, +"Could not unmask the UL interrupt. DPMAIF_AO_UL_AP_L2TIMR0 is 0x%x\n" , + value); +} + +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 ); +} + +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_intr (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_intr (struct dpmaif_hw_info *hw_info,unsigned char qno) +{ +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_intr, value, value & q_done, +0 ,DPMAIF_CHECK_TIMEOUT_US , false, hw_info, q_done); +if (ret) { +dev_err (hw_info->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 ); +} + +static void t7xx_dpmaif_set_intr_para (struct dpmaif_hw_intr_st_para *para, +enum dpmaif_hw_intr_type intr_type,unsigned int intr_queue) +{ + para->intr_types[para->intr_cnt] = intr_type; + para->intr_queues[para->intr_cnt] = intr_queue; + 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_tx_intr (struct dpmaif_hw_info *hw_info, +unsigned int intr_status, +struct dpmaif_hw_intr_st_para *para) +{ +unsigned long value; + + value =FIELD_GET (DP_UL_INT_QDONE_MSK , intr_status); +if (value) { +unsigned int index; + +t7xx_dpmaif_set_intr_para (para,DPF_INTR_UL_DONE , value); + +for_each_set_bit (index, &value,DPMAIF_TXQ_NUM ) +t7xx_dpmaif_mask_ulq_intr (hw_info, index); + } + + value =FIELD_GET (DP_UL_INT_EMPTY_MSK , intr_status); +if (value) +t7xx_dpmaif_set_intr_para (para,DPF_INTR_UL_DRB_EMPTY , value); + + value =FIELD_GET (DP_UL_INT_MD_NOTREADY_MSK , intr_status); +if (value) +t7xx_dpmaif_set_intr_para (para,DPF_INTR_UL_MD_NOTREADY , value); + + value =FIELD_GET (DP_UL_INT_MD_PWR_NOTREADY_MSK , intr_status); +if (value) +t7xx_dpmaif_set_intr_para (para,DPF_INTR_UL_MD_PWR_NOTREADY , value); + + value =FIELD_GET (DP_UL_INT_ERR_MSK , intr_status); +if (value) +t7xx_dpmaif_set_intr_para (para,DPF_INTR_UL_LEN_ERR , value); + +/* Clear interrupt status */ +iowrite32 (intr_status, hw_info->pcie_base +DPMAIF_AP_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_rx_intr (struct dpmaif_hw_info *hw_info, +unsigned int intr_status, +struct dpmaif_hw_intr_st_para *para,int qno) +{ +if (qno ==DPF_RX_QNO_DFT ) { +if (intr_status &DP_DL_INT_SKB_LEN_ERR ) +t7xx_dpmaif_set_intr_para (para,DPF_INTR_DL_SKB_LEN_ERR ,DPF_RX_QNO_DFT ); + +if (intr_status &DP_DL_INT_BATCNT_LEN_ERR ) { +t7xx_dpmaif_set_intr_para (para,DPF_INTR_DL_BATCNT_LEN_ERR ,DPF_RX_QNO_DFT ); + 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 ); + } + +if (intr_status &DP_DL_INT_PITCNT_LEN_ERR ) { +t7xx_dpmaif_set_intr_para (para,DPF_INTR_DL_PITCNT_LEN_ERR ,DPF_RX_QNO_DFT ); + 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 ); + } + +if (intr_status &DP_DL_INT_PKT_EMPTY_MSK ) +t7xx_dpmaif_set_intr_para (para,DPF_INTR_DL_PKT_EMPTY_SET ,DPF_RX_QNO_DFT ); + +if (intr_status &DP_DL_INT_FRG_EMPTY_MSK ) +t7xx_dpmaif_set_intr_para (para,DPF_INTR_DL_FRG_EMPTY_SET ,DPF_RX_QNO_DFT ); + +if (intr_status &DP_DL_INT_MTU_ERR_MSK ) +t7xx_dpmaif_set_intr_para (para,DPF_INTR_DL_MTU_ERR ,DPF_RX_QNO_DFT ); + +if (intr_status &DP_DL_INT_FRG_LEN_ERR_MSK ) +t7xx_dpmaif_set_intr_para (para,DPF_INTR_DL_FRGCNT_LEN_ERR ,DPF_RX_QNO_DFT ); + +if (intr_status &DP_DL_INT_Q0_PITCNT_LEN_ERR ) { +t7xx_dpmaif_set_intr_para (para,DPF_INTR_DL_Q0_PITCNT_LEN_ERR ,BIT (qno)); +t7xx_dpmaif_dlq_mask_rx_pitcnt_len_err_intr (hw_info, qno); + } + +if (intr_status &DP_DL_INT_HPC_ENT_TYPE_ERR ) +t7xx_dpmaif_set_intr_para (para,DPF_INTR_DL_HPC_ENT_TYPE_ERR , +DPF_RX_QNO_DFT ); + +if (intr_status &DP_DL_INT_Q0_DONE ) { +/* Mask RX done interrupt immediately after it occurs, do not clear +* the interrupt if the mask operation fails. +*/ +if (!t7xx_mask_dlq_intr (hw_info, qno)) +t7xx_dpmaif_set_intr_para (para,DPF_INTR_DL_Q0_DONE ,BIT (qno)); +else + intr_status &= ~DP_DL_INT_Q0_DONE ; + } + }else { +if (intr_status &DP_DL_INT_Q1_PITCNT_LEN_ERR ) { +t7xx_dpmaif_set_intr_para (para,DPF_INTR_DL_Q1_PITCNT_LEN_ERR ,BIT (qno)); +t7xx_dpmaif_dlq_mask_rx_pitcnt_len_err_intr (hw_info, qno); + } + +if (intr_status &DP_DL_INT_Q1_DONE ) { +if (!t7xx_mask_dlq_intr (hw_info, qno)) +t7xx_dpmaif_set_intr_para (para,DPF_INTR_DL_Q1_DONE ,BIT (qno)); +else + intr_status &= ~DP_DL_INT_Q1_DONE ; + } + } + + intr_status |=DP_DL_INT_BATCNT_LEN_ERR ; +/* Clear interrupt status */ +iowrite32 (intr_status, hw_info->pcie_base +DPMAIF_AP_APDL_L2TISAR0 ); +} + +/** +* t7xx_dpmaif_hw_get_intr_cnt() - Reads interrupt status and count from HW. +* @hw_info: Pointer to struct hw_info. +* @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_hw_info *hw_info, +struct dpmaif_hw_intr_st_para *para,int qno) +{ +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_intr (hw_info, tx_intr_status, para); + } + +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_intr (hw_info, rx_intr_status, para, qno); + } + +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 ioread32_poll_timeout_atomic (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 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 ); +} + +/* DPMAIF DL DLQ part HW setting */ + +static 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 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 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 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 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_hw_info *hw_info, +unsigned char q_num,bool frg_en) +{ +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 =ioread32_poll_timeout_atomic (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 (hw_info->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 =ioread32_poll_timeout_atomic (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 (hw_info->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 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 ,DPMAIF_HW_PKT_BIDCNT ); +iowrite32 (value, hw_info->pcie_base +DPMAIF_AO_DL_PKTINFO_CON0 ); +} + +static void t7xx_dpmaif_dl_set_ao_mtu (struct dpmaif_hw_info *hw_info) +{ +iowrite32 (DPMAIF_HW_MTU_SIZE , 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 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 ,DPMAIF_HW_CHK_PIT_NUM ); +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 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 , +DPMAIF_HW_BAT_REMAIN /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 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 , +DPMAIF_HW_BAT_PKTBUF /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 int value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_PKTINFO_CON2 ); + value &= ~DPMAIF_BAT_RSV_LEN_MSK ; + value |=DPMAIF_HW_BAT_RSVLEN &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 int value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_RDY_CHK_THRES ); + value &= ~DPMAIF_PKT_ALIGN_MSK ; + value |=DPMAIF_PKT_ALIGN_EN ; +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 int value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_RDY_CHK_FRG_THRES ); + value &= ~DPMAIF_FRG_CHECK_THRES_MSK ; + value |= (DPMAIF_HW_CHK_FRG_NUM &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 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 , +DPMAIF_HW_FRG_PKTBUF /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 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 ,DPMAIF_HW_CHK_BAT_NUM ); +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 int value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_PIT_SEQ_END ); + value &= ~DPMAIF_DL_PIT_SEQ_MSK ; + value |=DPMAIF_DL_PIT_SEQ_VALUE &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) +{ +unsigned int value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_DL_DLQPIT_INIT_CON3 ); + 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_hw_info *hw_info, +unsigned char q_num,unsigned int pit_idx) +{ +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 =ioread32_poll_timeout_atomic (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 (hw_info->dev,"Data plane modem DL PIT is not ready\n" ); +return ; + } + +iowrite32 (dl_pit_init, hw_info->pcie_base +DPMAIF_DL_DLQPIT_INIT ); + timeout =ioread32_poll_timeout_atomic (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 (hw_info->dev,"Data plane modem DL PIT initialization failed\n" ); +} + +static void t7xx_dpmaif_config_dlq_pit_hw (struct dpmaif_hw_info *hw_info,unsigned char q_num, +struct dpmaif_dl *dl_que) +{ +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); +t7xx_dpmaif_dl_dlq_pit_init_done (hw_info, q_num, pit_idx); +} + +static void t7xx_dpmaif_config_all_dlq_hw (struct dpmaif_hw_info *hw_info) +{ +int i; + +for (i =0 ; i <DPMAIF_RXQ_NUM ; i++) +t7xx_dpmaif_config_dlq_pit_hw (hw_info, i, &hw_info->dl_que[i]); +} + +static void t7xx_dpmaif_dl_all_q_en (struct dpmaif_hw_info *hw_info,bool enable) +{ +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 =ioread32_poll_timeout_atomic (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 (hw_info->dev,"Timeout updating BAT setting to HW\n" ); + +iowrite32 (dl_bat_init, hw_info->pcie_base +DPMAIF_DL_BAT_INIT ); + timeout =ioread32_poll_timeout_atomic (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 (hw_info->dev,"Data plane modem DL BAT is not ready\n" ); +} + +static int t7xx_dpmaif_config_dlq_hw (struct dpmaif_hw_info *hw_info) +{ +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_que = &hw_info->dl_que[queue]; +if (!dl_que->que_started) +return -EBUSY ; + +t7xx_dpmaif_dl_set_ao_remain_minsz (hw_info); +t7xx_dpmaif_dl_set_ao_bat_bufsz (hw_info); +t7xx_dpmaif_dl_set_ao_frg_bufsz (hw_info); +t7xx_dpmaif_dl_set_ao_bat_rsv_length (hw_info); +t7xx_dpmaif_dl_set_ao_bid_maxcnt (hw_info); +t7xx_dpmaif_dl_set_pkt_alignment (hw_info); +t7xx_dpmaif_dl_set_pit_seqnum (hw_info); +t7xx_dpmaif_dl_set_ao_mtu (hw_info); +t7xx_dpmaif_dl_set_ao_pit_chknum (hw_info); +t7xx_dpmaif_dl_set_ao_bat_check_thres (hw_info); +t7xx_dpmaif_dl_set_ao_frg_check_thres (hw_info); +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 (hw_info, 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 (hw_info, queue, false); +if (ret) +return ret; + +/* Init PIT (two PIT table) */ +t7xx_dpmaif_config_all_dlq_hw (hw_info); +t7xx_dpmaif_dl_all_q_en (hw_info, 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_SIZE_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 =ioread32_poll_timeout_atomic (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 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_q_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 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 ); +} + +int t7xx_dpmaif_ul_update_hw_drb_cnt (struct dpmaif_hw_info *hw_info,unsigned char q_num, +unsigned int drb_entry_cnt) +{ +u32 ul_update, value; +int ret; + + ul_update = drb_entry_cnt &DPMAIF_UL_ADD_COUNT_MASK ; + ul_update |=DPMAIF_UL_ADD_UPDATE ; + + ret =ioread32_poll_timeout_atomic (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 (hw_info->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 =ioread32_poll_timeout_atomic (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 (hw_info->dev,"Timeout updating UL add\n" ); +return ret; + } + +return 0 ; +} + +unsigned int t7xx_dpmaif_ul_get_rd_idx (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 FIELD_GET (DPMAIF_UL_DRB_RIDX_MSK , value) /DPMAIF_UL_DRB_SIZE_WORD ; +} + +int t7xx_dpmaif_dlq_add_pit_remain_cnt (struct dpmaif_hw_info *hw_info,unsigned int dlq_pit_idx, +unsigned int pit_remain_cnt) +{ +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 =ioread32_poll_timeout_atomic (hw_info->pcie_base +DPMAIF_DL_DLQPIT_ADD , + value, !(value &DPMAIF_DL_ADD_NOT_READY ),0 , +DPMAIF_CHECK_TIMEOUT_US ); +if (ret) { +dev_err (hw_info->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 =ioread32_poll_timeout_atomic (hw_info->pcie_base +DPMAIF_DL_DLQPIT_ADD , + value, !(value &DPMAIF_DL_ADD_NOT_READY ),0 , +DPMAIF_CHECK_TIMEOUT_US ); +if (ret) { +dev_err (hw_info->dev,"Data plane modem add dlq failed\n" ); +return ret; + } + +return 0 ; +} + +unsigned int t7xx_dpmaif_dl_dlq_pit_get_wr_idx (struct dpmaif_hw_info *hw_info, +unsigned int dlq_pit_idx) +{ +u32 value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_DLQ_WR_IDX + + dlq_pit_idx *DLQ_PIT_IDX_SIZE ); +return value &DPMAIF_DL_RD_WR_IDX_MSK ; +} + +static bool t7xx_dl_add_timedout (struct dpmaif_hw_info *hw_info) +{ +u32 value; +int ret; + + ret =ioread32_poll_timeout_atomic (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_hw_info *hw_info,unsigned int bat_entry_cnt) +{ +unsigned int value; + +if (t7xx_dl_add_timedout (hw_info)) { +dev_err (hw_info->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 (hw_info->dev,"DL add BAT timeout\n" ); +return -EBUSY ; + } + +return 0 ; +} + +unsigned int t7xx_dpmaif_dl_get_bat_rd_idx (struct dpmaif_hw_info *hw_info,unsigned char q_num) +{ +u32 value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_BAT_RD_IDX ); +return value &DPMAIF_DL_RD_WR_IDX_MSK ; +} + +unsigned int t7xx_dpmaif_dl_get_bat_wr_idx (struct dpmaif_hw_info *hw_info,unsigned char q_num) +{ +u32 value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_BAT_WR_IDX ); +return value &DPMAIF_DL_RD_WR_IDX_MSK ; +} + +int t7xx_dpmaif_dl_snd_hw_frg_cnt (struct dpmaif_hw_info *hw_info,unsigned int frg_entry_cnt) +{ +unsigned int value; + +if (t7xx_dl_add_timedout (hw_info)) { +dev_err (hw_info->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 (hw_info->dev,"Data plane modem add frag DLQ failed" ); +return -EBUSY ; + } + +return 0 ; +} + +unsigned int t7xx_dpmaif_dl_get_frg_rd_idx (struct dpmaif_hw_info *hw_info,unsigned char q_num) +{ +u32 value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_FRGBAT_RD_IDX ); +return value &DPMAIF_DL_RD_WR_IDX_MSK ; +} + +static void t7xx_dpmaif_set_queue_property (struct dpmaif_hw_info *hw_info, +struct dpmaif_hw_params *init_para) +{ +struct dpmaif_dl *dl_que; +struct dpmaif_ul *ul_que; +int i; + +for (i =0 ; i <DPMAIF_RXQ_NUM ; i++) { + 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_all_txq() - Stop all TX queues. +* @hw_info: Pointer to struct hw_info. +* +* 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_all_txq (struct dpmaif_hw_info *hw_info) +{ +int count =0 ; + +t7xx_dpmaif_ul_all_q_en (hw_info, false); +while (t7xx_dpmaif_ul_idle_check (hw_info)) { +if (++count >=DPMAIF_MAX_CHECK_COUNT ) { +dev_err (hw_info->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_all_rxq() - Stop all RX queues. +* @hw_info: Pointer to struct hw_info. +* +* 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_all_rxq (struct dpmaif_hw_info *hw_info) +{ +unsigned int wr_idx, rd_idx; +int count =0 ; + +t7xx_dpmaif_dl_all_q_en (hw_info, false); +while (t7xx_dpmaif_dl_idle_check (hw_info)) { +if (++count >=DPMAIF_MAX_CHECK_COUNT ) { +dev_err (hw_info->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 { + wr_idx =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_PIT_WR_IDX ); + wr_idx &=DPMAIF_DL_RD_WR_IDX_MSK ; + rd_idx =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_PIT_RD_IDX ); + rd_idx &=DPMAIF_DL_RD_WR_IDX_MSK ; + +if (wr_idx == rd_idx) +return 0 ; + }while (++count <DPMAIF_MAX_CHECK_COUNT ); + +dev_err (hw_info->dev,"Check middle PIT sync fail\n" ); +return -ETIMEDOUT ; +} + +void t7xx_dpmaif_start_hw (struct dpmaif_hw_info *hw_info) +{ +t7xx_dpmaif_ul_all_q_en (hw_info, true); +t7xx_dpmaif_dl_all_q_en (hw_info, true); +} + +/** +* t7xx_dpmaif_hw_init() - Initialize HW data path API. +* @hw_info: Pointer to struct hw_info. +* @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_hw_info *hw_info,struct dpmaif_hw_params *init_param) +{ +int ret; + + ret =t7xx_dpmaif_hw_config (hw_info); +if (ret) { +dev_err (hw_info->dev,"DPMAIF HW config failed\n" ); +return ret; + } + + ret =t7xx_dpmaif_init_intr (hw_info); +if (ret) { +dev_err (hw_info->dev,"DPMAIF HW interrupts init failed\n" ); +return ret; + } + +t7xx_dpmaif_set_queue_property (hw_info, init_param); +t7xx_dpmaif_pcie_dpmaif_sign (hw_info); +t7xx_dpmaif_dl_performance (hw_info); + + ret =t7xx_dpmaif_config_dlq_hw (hw_info); +if (ret) { +dev_err (hw_info->dev,"DPMAIF HW dlq config failed\n" ); +return ret; + } + +t7xx_dpmaif_config_ulq_hw (hw_info); + + ret =t7xx_dpmaif_hw_init_done (hw_info); +if (ret) +dev_err (hw_info->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 +179 -0
179 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_reg.h +213 -0
217 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH net-next v5 07/13] net: wwan: t7xx: Data path HW layer
Quoted 16 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.
Signed-off-by Haijun Liu <[email protected]>Signed-off-by Chandrashekar Devegowda <[email protected]>Co-developed-by Ricardo Martinez <[email protected]>Signed-off-by Ricardo Martinez <[email protected]>Quoted 1 line
From a WWAN framework perspective:
Reviewed-by Loic Poulain <[email protected]>---
drivers/net/wwan/t7xx/t7xx_dpmaif.c line 631
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_dpmaif.c new file +7
-0+static void t7xx_dpmaif_dl_set_ao_bat_rsv_length (struct dpmaif_hw_info *hw_info) +{ +unsigned int value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_PKTINFO_CON2 ); + value &= ~DPMAIF_BAT_RSV_LEN_MSK ; + value |=DPMAIF_HW_BAT_RSVLEN &DPMAIF_BAT_RSV_LEN_MSK ;
Drop & DPMAIF_BAT_RSV_LEN_MSK
drivers/net/wwan/t7xx/t7xx_dpmaif.c line 660
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_dpmaif.c new file +7
-0+static void t7xx_dpmaif_dl_set_ao_frg_check_thres (struct dpmaif_hw_info *hw_info) +{ +unsigned int value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_RDY_CHK_FRG_THRES ); + value &= ~DPMAIF_FRG_CHECK_THRES_MSK ; + value |= (DPMAIF_HW_CHK_FRG_NUM &DPMAIF_FRG_CHECK_THRES_MSK );
Ditto.
drivers/net/wwan/t7xx/t7xx_dpmaif.c line 706
Quoted 1 line
drivers/net/wwan/t7xx/t7xx_dpmaif.c new file +1
-0+ value |=DPMAIF_DL_PIT_SEQ_VALUE &DPMAIF_DL_PIT_SEQ_MSK ;
Ditto.
Signature · 1 line
i.
Ricardo Martinez
reviewerPATCH v5 8/13 net: wwan: t7xx: Add data path interface
In reply to Ricardo MartinezFrom: 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.
From a WWAN framework perspective:
--- drivers/net/wwan/t7xx/Makefile | 4 + drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c | 484 ++++++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h | 210 ++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 1223 ++++++++++++++++++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h | 114 ++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c | 697 +++++++++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.h | 84 ++ 7 files changed, 2816 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
@@ -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 +484 -0
484 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h new file +210 -0
210 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +1223 -0
1,223 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h new file +114 -0
114 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c new file +697 -0
697 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.h new file +84 -0
84 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH net-next v5 08/13] net: wwan: t7xx: Add data path interface
Quoted 31 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 thedmpaif_tx_send_skbfunction 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.Signed-off-by Haijun Liu <[email protected]>Signed-off-by Chandrashekar Devegowda <[email protected]>Co-developed-by Ricardo Martinez <[email protected]>Signed-off-by Ricardo Martinez <[email protected]>Quoted 1 line
From a WWAN framework perspective:
Reviewed-by Loic Poulain <[email protected]>---
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c line 119
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +5
-0+static int t7xx_dpmaif_update_bat_wr_idx (struct dpmaif_ctrl *dpmaif_ctrl, +const unsigned char q_num,const unsigned int bat_cnt) +{ +struct dpmaif_rx_queue *rxq = &dpmaif_ctrl->rxq[q_num]; +unsigned short old_rl_idx, new_wr_idx, old_wr_idx;
unsigned int. I thought you listed a change for these idx local variables but there were still many unsigned shorts. Please check the whole change.
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +4
-0+static int t7xx_dpmaif_rx_data_collect (struct dpmaif_ctrl *dpmaif_ctrl, +const unsigned char q_num,const unsigned int budget) +{ +struct dpmaif_rx_queue *rxq = &dpmaif_ctrl->rxq[q_num];
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c line 882
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +10
-0+unsigned long time_limit; +unsigned int cnt; + + time_limit = jiffies +msecs_to_jiffies (DPMAIF_WQ_TIME_LIMIT_MS ); + +while ((cnt =t7xx_dpmaifq_poll_pit (rxq))) { +unsigned int rd_cnt; +int real_cnt; + + rd_cnt = min_t(unsigned int, cnt, budget);
This can be min(cnt, budget); because they're now both unsigned ints. min_t is only needed if the args are of different type.
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c line 431
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c new file +2
-0+t7xx_dpmaif_ul_update_hw_drb_cnt (&dpmaif_ctrl->hw_info, txq->index, + drb_send_cnt *DPMAIF_UL_DRB_SIZE_WORD );
This is the only callsite for t7xx_dpmaif_ul_update_hw_drb_cnt that returns int (in 07). Change it to void?
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c line 668
Quoted 1 line
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c new file +1
-0+/* Wait for active Tx to be doneg */
doneg -> done.
Signature · 1 line
i.
Sergey Ryazanov
maintainerRe: [PATCH net-next v5 08/13] net: wwan: t7xx: Add data path interface
In reply to Ricardo MartinezQuoted 21 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 thedmpaif_tx_send_skbfunction 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.
[skipped]
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h line 19
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h new file +2
-0+#ifndef __T7XX_DPMA_TX_H__ +#define __T7XX_DPMA_TX_H__
Maybe __T7XX_HIF_DPMAIF_H__ ?
[skipped]
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h new file +10
-0+struct dpmaif_tx_queue { +unsigned char index; +bool que_started; +atomic_t tx_budget; +void *drb_base; +dma_addr_t drb_bus_addr; +unsigned int drb_size_cnt; +unsigned short drb_wr_idx; +unsigned short drb_rd_idx; +unsigned short drb_release_rd_idx;
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h line 148
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h new file +10
-0+void *drb_skb_base; +wait_queue_head_t req_wq; +struct workqueue_struct *worker; +struct work_struct dpmaif_tx_work; +spinlock_t tx_lock;/* Protects txq DRB */ +atomic_t tx_processing; + +struct dpmaif_ctrl *dpmaif_ctrl; +spinlock_t tx_skb_lock;/* Protects TX thread skb list */ +struct list_head tx_skb_queue;
Should this be the sk_buff_head struct? So you will be able to use a regular skb_queue_foo() functions and have the embedded spinlock?
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h new file +4
-0+unsigned int tx_submit_skb_cnt; +unsigned int tx_list_max_len; +unsigned int tx_skb_stat; +};
[skipped]
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h new file +7
-0+static void t7xx_dpmaif_parse_msg_pit (const struct dpmaif_rx_queue *rxq, +const struct dpmaif_msg_pit *msg_pit, +struct dpmaif_cur_rx_skb_info *skb_info) +{ + skb_info->cur_chn_idx =FIELD_GET (MSG_PIT_CHANNEL_ID ,le32_to_cpu (msg_pit->dword1)); + skb_info->check_sum =FIELD_GET (MSG_PIT_CHECKSUM ,le32_to_cpu (msg_pit->dword1)); + skb_info->pit_dp =FIELD_GET (MSG_PIT_DP ,le32_to_cpu (msg_pit->dword1));
Here you can first convert dword1 field value to a native endians and store it in a local variable, and then use it in the FIELD_GET().
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h new file +2
-0+ skb_info->pkt_type =FIELD_GET (MSG_PIT_IP ,le32_to_cpu (msg_pit->dword4)); +}
[skipped]
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h new file +6
-0+/* Structure of DL PIT */ +struct dpmaif_normal_pit { +__le32 pit_header; +__le32 p_data_addr; +__le32 data_addr_ext; +__le32 pit_footer;
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h new file +7
-0+}; +struct dpmaif_msg_pit { +__le32 dword1; +__le32 dword2; +__le32 dword3; +__le32 dword4; +};
Just an idea. Both PIT normal (aka PD) and PIT Msg structs have the same size and even partially share the first header bits, so why not define both formats in a single structure using union:
struct dpmaif_pit {
__le32 header;
union {
struct {
__le32 data_addr_l;
__le32 data_addr_h;
__le32 footer;
} pd;
struct {
__le32 dword2;
__le32 dword3;
__le32 dword4;
} msg;
};
};Defining the format in this way eliminates the cast and allows to turn the pit_base field from a void pointer into a struct dpmaif_pit pointer and handle it as an array.
[skipped]
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h
Quoted 13 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h new file +13
-0+static void t7xx_setup_payload_drb (struct dpmaif_ctrl *dpmaif_ctrl,unsigned char q_num, +unsigned short cur_idx,dma_addr_t data_addr, +unsigned int pkt_size,bool last_one) +{ +struct dpmaif_drb_pd *drb_base = dpmaif_ctrl->txq[q_num].drb_base; +struct dpmaif_drb_pd *drb = drb_base + cur_idx; + + drb->header &=cpu_to_le32 (~DRB_PD_DTYP ); + drb->header |=cpu_to_le32 (FIELD_PREP (DRB_PD_DTYP ,DES_DTYP_PD )); + drb->header &=cpu_to_le32 (~DRB_PD_CONT ); + +if (!last_one) + drb->header |=cpu_to_le32 (FIELD_PREP (DRB_PD_CONT ,1 ));
Empty line between DRB_PD_CONT field clean and setup looks odd.
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h new file +6
-0+ + drb->header &=cpu_to_le32 (~(u32 )DRB_PD_DATA_LEN ); + drb->header |=cpu_to_le32 (FIELD_PREP (DRB_PD_DATA_LEN , pkt_size)); + drb->p_data_addr =cpu_to_le32 (lower_32_bits (data_addr)); + drb->data_addr_ext =cpu_to_le32 (upper_32_bits (data_addr)); +}
[skipped]
Quoted 9 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h new file +6
-0+static int t7xx_dpmaif_add_skb_to_ring (struct dpmaif_ctrl *dpmaif_ctrl,struct sk_buff *skb) +{ +unsigned short cur_idx, drb_wr_idx_backup; + txq = &dpmaif_ctrl->txq[skb_cb->txq_number]; + cur_idx = txq->drb_wr_idx; + drb_wr_idx_backup = cur_idx;
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h new file +9
-0+for (wr_cnt =0 ; wr_cnt < payload_cnt; wr_cnt++) { + 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" ); +atomic_set (&txq->tx_processing,0 ); + +spin_lock_irqsave (&txq->tx_lock, flags); + txq->drb_wr_idx = drb_wr_idx_backup; +spin_unlock_irqrestore (&txq->tx_lock, flags);
What is the purpose of locking here?
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h new file +4
-0+return -ENOMEM ; + } + } +}
[skipped]
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h
Quoted 13 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h new file +12
-0+struct dpmaif_drb_pd { +__le32 header; +__le32 p_data_addr; +__le32 data_addr_ext; +__le32 reserved2; +}; +struct dpmaif_drb_msg { +__le32 header_dw1; +__le32 header_dw2; +__le32 reserved4; +__le32 reserved5; +};
Like PIT, DRB can be defined using a single structure with union. With the same benefits as for PIT.
struct dpmaif_drb {
__le32 header;
union {
struct {
__le32 data_addr_l;
__le32 data_addr_h;
__le32 reserved2;
} pd;
struct {
__le32 msghdr;
__le32 reserved4;
__le32 reserved5;
} msg;
};
};But it is up to you how you define and handle these formats. I just like unions, as you can see :)
--
Sergey
Martinez, Ricardo
reviewerRe: [PATCH net-next v5 08/13] net: wwan: t7xx: Add data path interface
Hi Sergey,
Quoted 23 lines · Sergey Ryazanov
Quoted 21 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 thedmpaif_tx_send_skbfunction 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 12 lines
Quoted 12 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 short cur_idx, drb_wr_idx_backup; + txq = &dpmaif_ctrl->txq[skb_cb->txq_number]; + cur_idx = txq->drb_wr_idx; + drb_wr_idx_backup = cur_idx; +for (wr_cnt =0 ; wr_cnt < payload_cnt; wr_cnt++) { + bus_addr =dma_map_single (dpmaif_ctrl->dev, data_addr, data_len,DMA_TO_DEVICE );
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c line 300
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c new file +7
-0+if (dma_mapping_error (dpmaif_ctrl->dev, bus_addr)) { +dev_err (dpmaif_ctrl->dev,"DMA mapping fail\n" ); +atomic_set (&txq->tx_processing,0 ); + +spin_lock_irqsave (&txq->tx_lock, flags); + txq->drb_wr_idx = drb_wr_idx_backup; +spin_unlock_irqrestore (&txq->tx_lock, flags);What is the purpose of locking here?
The intention is to protect against concurrent access of drb_wr_idx by t7xx_txq_drb_wr_available()
Quoted 8 lines
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +4
-0+return -ENOMEM ; + } + } +}
Sergey Ryazanov
maintainerRe: [PATCH net-next v5 08/13] net: wwan: t7xx: Add data path interface
Hello Ricardo,
Quoted 47 lines · Ricardo
Quoted 23 lines · Sergey Ryazanov
Quoted 21 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 thedmpaif_tx_send_skbfunction 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 13 lines
Quoted 13 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c new file +9
-0+static int t7xx_dpmaif_add_skb_to_ring (struct dpmaif_ctrl *dpmaif_ctrl,struct sk_buff *skb) +{ +unsigned short cur_idx, drb_wr_idx_backup; + txq = &dpmaif_ctrl->txq[skb_cb->txq_number]; + cur_idx = txq->drb_wr_idx; + drb_wr_idx_backup = cur_idx; +for (wr_cnt =0 ; wr_cnt < payload_cnt; wr_cnt++) { + bus_addr =dma_map_single (dpmaif_ctrl->dev, data_addr, data_len,DMA_TO_DEVICE ); +if (dma_mapping_error (dpmaif_ctrl->dev, bus_addr)) {Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c line 300
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c new file +6
-0+dev_err (dpmaif_ctrl->dev,"DMA mapping fail\n" ); +atomic_set (&txq->tx_processing,0 ); + +spin_lock_irqsave (&txq->tx_lock, flags); + txq->drb_wr_idx = drb_wr_idx_backup; +spin_unlock_irqrestore (&txq->tx_lock, flags);What is the purpose of locking here?
Quoted 1 line
The intention is to protect against concurrent access of
drb_wr_idxbyt7xx_txq_drb_wr_available()
t7xx_txq_drb_wr_available() only reads the drb_wr_idx field, why would you serialize that concurrent read?
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +4
-0+return -ENOMEM ; + } + } +}
Signature · 1 line
Sergey
Martinez, Ricardo
reviewerRe: [PATCH net-next v5 08/13] net: wwan: t7xx: Add data path interface
Quoted 49 lines · Sergey Ryazanov
Hello Ricardo,
Quoted 45 lines · Ricardo
Quoted 23 lines · Sergey Ryazanov
Quoted 21 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 thedmpaif_tx_send_skbfunction 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 20 lines
Quoted 9 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c new file +6
-0+static int t7xx_dpmaif_add_skb_to_ring (struct dpmaif_ctrl *dpmaif_ctrl,struct sk_buff *skb) +{ +unsigned short cur_idx, drb_wr_idx_backup; + txq = &dpmaif_ctrl->txq[skb_cb->txq_number]; + cur_idx = txq->drb_wr_idx; + drb_wr_idx_backup = cur_idx;drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c line 300
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c new file +9
-0+for (wr_cnt =0 ; wr_cnt < payload_cnt; wr_cnt++) { + 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" ); +atomic_set (&txq->tx_processing,0 ); + +spin_lock_irqsave (&txq->tx_lock, flags); + txq->drb_wr_idx = drb_wr_idx_backup; +spin_unlock_irqrestore (&txq->tx_lock, flags);What is the purpose of locking here?
Quoted 3 lines
Quoted 1 line
The intention is to protect against concurrent access of
drb_wr_idxbyt7xx_txq_drb_wr_available()
t7xx_txq_drb_wr_available()only reads thedrb_wr_idxfield, why would you serialize that concurrent read?
Good point, drb_wr_idx has only 1 writer which is this thread.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +4
-0+return -ENOMEM ; + } + } +}
Ricardo Martinez
reviewerPATCH v5 9/13 net: wwan: t7xx: Add WWAN network interface
In reply to Ricardo MartinezFrom: 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.
From a WWAN framework perspective:
--- drivers/net/wwan/t7xx/Makefile | 1 + drivers/net/wwan/t7xx/t7xx_modem_ops.c | 11 +- drivers/net/wwan/t7xx/t7xx_netdev.c | 430 +++++++++++++++++++++++++ drivers/net/wwan/t7xx/t7xx_netdev.h | 56 ++++ 4 files changed, 497 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
@@ -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
@@ -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"
@@ -707,10 +708,14 @@ int t7xx_md_init(struct t7xx_pci_dev *t7xx_dev)if (ret) goto err_destroy_hswq; - ret =t7xx_cldma_init (md->md_ctrl[CLDMA_ID_MD ]); + ret =t7xx_ccmni_init (t7xx_dev);if (ret) goto err_uninit_fsm; + ret =t7xx_cldma_init (md->md_ctrl[CLDMA_ID_MD ]); +if (ret) + goto err_uninit_ccmni; + ret =t7xx_port_proxy_init (md);if (ret) goto err_uninit_cldma;
@@ -729,6 +734,9 @@ int t7xx_md_init(struct t7xx_pci_dev *t7xx_dev) err_uninit_cldma:t7xx_cldma_exit (md->md_ctrl[CLDMA_ID_MD ]); +err_uninit_ccmni: +t7xx_ccmni_exit (t7xx_dev); + err_uninit_fsm:t7xx_fsm_uninit (md);
@@ -750,6 +758,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[CLDMA_ID_MD ]); +t7xx_ccmni_exit (t7xx_dev);t7xx_fsm_uninit (md);destroy_workqueue (md->handshake_wq); }
drivers/net/wwan/t7xx/t7xx_netdev.c new file +430 -0
430 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_netdev.h new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.17.1
Sergey Ryazanov
maintainerRe: [PATCH net-next v5 09/13] net: wwan: t7xx: Add WWAN network interface
Quoted 7 lines · Ricardo Martinez
From: Haijun Liu <[email protected]>
Creates the Cross Core Modem Network Interface (CCMNI) which implements the
wwan_opsfor registration with the WWAN framework, CCMNI also implements thenet_device_opsfunctions used by the network device. Network device operations include open, close, start transmission, TX timeout, change MTU, and select queue.
[skipped]
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_netdev.c new file +5
-0+static u16 t7xx_ccmni_select_queue (struct net_device *dev,struct sk_buff *skb, +struct net_device *sb_dev) +{ +return DPMAIF_TX_DEFAULT_QUEUE ; +}
[skipped]
drivers/net/wwan/t7xx/t7xx_netdev.c line 119
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_netdev.c new file +6
-0+static const struct net_device_ops ccmni_netdev_ops = { + .ndo_open = t7xx_ccmni_open, + .ndo_stop = t7xx_ccmni_close, + .ndo_start_xmit = t7xx_ccmni_start_xmit, + .ndo_tx_timeout = t7xx_ccmni_tx_timeout, + .ndo_select_queue = t7xx_ccmni_select_queue,
Since the driver works in the single queue mode, this callback is unneeded.
Quoted 1 line
+};
--
Sergey
Ricardo Martinez
reviewerPATCH v5 10/13 net: wwan: t7xx: Introduce power management
In reply to Ricardo MartinezFrom: 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 | 123 +++++- 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 | 425 +++++++++++++++++++++ drivers/net/wwan/t7xx/t7xx_pci.h | 47 +++ drivers/net/wwan/t7xx/t7xx_state_monitor.c | 2 + 8 files changed, 705 insertions(+), 1 deletion(-)
drivers/net/wwan/t7xx/t7xx_hif_cldma.c +122 -1
@@ -1087,6 +1087,120 @@ int t7xx_cldma_alloc(enum cldma_id hif_id, struct t7xx_pci_dev *t7xx_dev)return 0 ; } +static void t7xx_cldma_resume_early (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; +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_next->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 ==CLDMA_ID_MD ) +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_all_qs (hw_info,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 ==CLDMA_ID_MD ) +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_all_qs (hw_info,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 ==CLDMA_ID_MD ) + 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 (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;
@@ -1137,6 +1251,7 @@ static void t7xx_cldma_destroy_wqs(struct cldma_ctrl *md_ctrl)* t7xx_cldma_init() - Initialize CLDMA. * @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. *
@@ -1147,12 +1262,16 @@ static void t7xx_cldma_destroy_wqs(struct cldma_ctrl *md_ctrl)int t7xx_cldma_init (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++) {
@@ -1187,6 +1306,7 @@ int t7xx_cldma_init(struct cldma_ctrl *md_ctrl) err_workqueue:t7xx_cldma_destroy_wqs (md_ctrl); +t7xx_cldma_pm_uninit (md_ctrl);return -ENOMEM ; }
@@ -1201,4 +1321,5 @@ void t7xx_cldma_exit(struct cldma_ctrl *md_ctrl)t7xx_cldma_stop (md_ctrl);t7xx_cldma_late_release (md_ctrl);t7xx_cldma_destroy_wqs (md_ctrl); +t7xx_cldma_pm_uninit (md_ctrl); }
drivers/net/wwan/t7xx/t7xx_hif_cldma.h +1 -0
@@ -87,6 +87,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
113 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h +1 -0
@@ -179,6 +179,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 hw_info;
drivers/net/wwan/t7xx/t7xx_mhccif.c +17 -0
@@ -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;
@@ -53,6 +58,18 @@ static irqreturn_t t7xx_mhccif_isr_thread(int irq, void *data) }t7xx_mhccif_clear_interrupts (t7xx_dev, int_status); + +if (int_status &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_status =t7xx_mhccif_read_sw_int_sts (t7xx_dev); +if (!int_status) { + 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 +425 -0
460 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_pci.h +47 -0
68 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_state_monitor.c +2 -0
@@ -188,6 +188,7 @@ static void fsm_routine_exception(struct t7xx_fsm_ctl *ctl, struct t7xx_fsm_commcase EXCEPTION_EVENT :dev_err (dev,"Exception event\n" );t7xx_fsm_broadcast_state (ctl,MD_STATE_EXCEPTION ); +t7xx_pci_pm_exp_detected (ctl->md->t7xx_dev);t7xx_md_exception_handshake (ctl->md); fsm_wait_for_event(ctl, FSM_EVENT_MD_EX_REC_OK, FSM_EVENT_MD_EX,
@@ -300,6 +301,7 @@ static int fsm_routine_starting(struct t7xx_fsm_ctl *ctl)return -ETIMEDOUT ; } +t7xx_pci_pm_init_late (md->t7xx_dev);fsm_routine_ready (ctl);return 0 ; }
Signature · 1 line
2.17.1
Re: [PATCH net-next v5 10/13] net: wwan: t7xx: Introduce power management
Quoted 21 lines · Ricardo Martinez
From: Haijun Liu <[email protected]>
Implements suspend, resumes, freeze, thaw, poweroff, and restore
dev_pm_opscallbacks.Quoted 1 line
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 adev_pm_opsfunction is called, the PM entities list is iterated and the matching function is called for each entry in the list.Signed-off-by Haijun Liu <[email protected]>Signed-off-by Chandrashekar Devegowda <[email protected]>Co-developed-by Ricardo Martinez <[email protected]>Signed-off-by Ricardo Martinez <[email protected]>---
drivers/net/wwan/t7xx/t7xx_pci.c +2
-0+static int __t7xx_pci_pm_suspend (struct pci_dev *pdev) +{
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ iowrite32(L1_DISABLE_BIT(0), IREG_BASE(t7xx_dev) + DIS_ASPM_LOWPWR_CLR_0); + return 0;
The success path does this same iowrite32 to DIS_ASPM_LOWPWR_CLR_0 as the failure paths. Is that intended?
The function looks much better now!
Signature · 1 line
i.
Martinez, Ricardo
reviewerRe: [PATCH net-next v5 10/13] net: wwan: t7xx: Introduce power management
Quoted 23 lines · Ilpo Järvinen
Quoted 20 lines · Ricardo Martinez
From: Haijun Liu <[email protected]>
Implements suspend, resumes, freeze, thaw, poweroff, and restore
dev_pm_opscallbacks.Quoted 1 line
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 adev_pm_opsfunction is called, the PM entities list is iterated and the matching function is called for each entry in the list.Signed-off-by Haijun Liu <[email protected]>Signed-off-by Chandrashekar Devegowda <[email protected]>Co-developed-by Ricardo Martinez <[email protected]>Signed-off-by Ricardo Martinez <[email protected]>---
drivers/net/wwan/t7xx/t7xx_pci.c +2
-0+static int __t7xx_pci_pm_suspend (struct pci_dev *pdev) +{...
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ iowrite32(L1_DISABLE_BIT(0), IREG_BASE(t7xx_dev) + DIS_ASPM_LOWPWR_CLR_0); + return 0;The success path does this same iowrite32 to
DIS_ASPM_LOWPWR_CLR_0as the failure paths. Is that intended?
Yes, that's intended.
This function disables low power mode at the beginning and it has to re-enable it before
returning, regardless of the success or failure path.
The next iteration will contain some naming changes to avoid double negatives :
- iowrite32(L1_DISABLE_BIT(0), IREG_BASE(t7xx_dev) + DIS_ASPM_LOWPWR_CLR_0);
+ iowrite32(T7XX_L1_BIT(0), IREG_BASE(t7xx_dev) + DISABLE_ASPM_LOWPWR);
Quoted 3 lines
The function looks much better now!
Ricardo Martinez
reviewerPATCH v5 11/13 net: wwan: t7xx: Runtime PM
In reply to Ricardo MartinezFrom: 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 | 14 ++++++++++++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 17 +++++++++++++++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c | 15 +++++++++++++++ drivers/net/wwan/t7xx/t7xx_pci.c | 22 ++++++++++++++++++++++ 4 files changed, 68 insertions(+)
drivers/net/wwan/t7xx/t7xx_hif_cldma.c +14 -0
@@ -33,6 +33,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>
@@ -262,6 +263,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)
@@ -373,6 +376,9 @@ static void t7xx_cldma_tx_done(struct work_struct *work)t7xx_cldma_hw_irq_en_txrx (hw_info, queue->index,MTK_TX ); }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,
@@ -579,6 +585,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,
@@ -603,6 +610,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);
@@ -933,6 +941,10 @@ int t7xx_cldma_send_skb(struct cldma_ctrl *md_ctrl, int qno, struct sk_buff *skbif (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);
@@ -976,6 +988,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 +17 -0
@@ -32,6 +32,7 @@#include <linux/minmax.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,7 +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 ); }
@@ -1126,11 +1135,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
@@ -28,6 +28,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>
@@ -164,6 +165,10 @@ static void t7xx_dpmaif_tx_done(struct work_struct *work)struct dpmaif_hw_info *hw_info;int ret; + ret =pm_runtime_resume_and_get (dpmaif_ctrl->dev); +if (ret <0 && ret != -EACCES ) +return ; + hw_info = &dpmaif_ctrl->hw_info; ret =t7xx_dpmaif_tx_release (dpmaif_ctrl, txq->index, txq->drb_size_cnt); if (ret == -EAGAIN ||
@@ -177,6 +182,9 @@ static void t7xx_dpmaif_tx_done(struct work_struct *work)t7xx_dpmaif_clr_ip_busy_sts (hw_info);t7xx_dpmaif_unmask_ulq_intr (hw_info, 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,
@@ -438,6 +446,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) ||
@@ -452,7 +461,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 +22 -0
@@ -31,6 +31,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"
@@ -44,6 +45,7 @@#define T7XX_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
@@ -86,6 +88,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); }
@@ -100,6 +104,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)
@@ -108,6 +114,9 @@ static int t7xx_pci_pm_reinit(struct t7xx_pci_dev *t7xx_dev)* so just roll back PM setting to the init setting. */ 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); }
@@ -407,6 +416,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;
@@ -443,6 +453,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,
@@ -452,6 +472,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
Ricardo Martinez
reviewerPATCH v5 12/13 net: wwan: t7xx: Device deep sleep lock/unlock
In reply to Ricardo MartinezFrom: 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 | 41 ++++++--- drivers/net/wwan/t7xx/t7xx_mhccif.c | 3 + drivers/net/wwan/t7xx/t7xx_pci.c | 96 ++++++++++++++++++++++ drivers/net/wwan/t7xx/t7xx_pci.h | 10 +++ 6 files changed, 161 insertions(+), 15 deletions(-)
drivers/net/wwan/t7xx/t7xx_hif_cldma.c +12 -0
@@ -945,6 +945,7 @@ int t7xx_cldma_send_skb(struct cldma_ctrl *md_ctrl, int qno, struct sk_buff *skbif (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);
@@ -966,6 +967,11 @@ int t7xx_cldma_send_skb(struct cldma_ctrl *md_ctrl, int qno, struct sk_buff *skb queue->tx_next =list_next_entry_circular (tx_req, gpd_ring, entry);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.
@@ -978,6 +984,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 );
@@ -988,6 +999,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
@@ -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 );
@@ -1141,11 +1144,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 +29 -12
68 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_mhccif.c +3 -0
@@ -59,6 +59,9 @@ static irqreturn_t t7xx_mhccif_isr_thread(int irq, void *data)t7xx_mhccif_clear_interrupts (t7xx_dev, int_status); +if (int_status &D2H_INT_DS_LOCK_ACK ) +complete_all (&t7xx_dev->sleep_lock_acquire); +if (int_status &D2H_INT_SR_ACK )complete (&t7xx_dev->pm_sr_ack);
drivers/net/wwan/t7xx/t7xx_pci.c +96 -0
136 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_pci.h +10 -0
@@ -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"
@@ -50,7 +51,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
@@ -67,7 +71,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;
@@ -104,6 +111,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
Re: [PATCH net-next v5 12/13] net: wwan: t7xx: Device deep sleep lock/unlock
Quoted 43 lines · 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.
Signed-off-by Haijun Liu <[email protected]>Signed-off-by Chandrashekar Devegowda <[email protected]>Co-developed-by Ricardo Martinez <[email protected]>Signed-off-by Ricardo Martinez <[email protected]>---
drivers/net/wwan/t7xx/t7xx_pci.c +27
-0+int t7xx_pci_sleep_disable_complete (struct t7xx_pci_dev *t7xx_dev) +{ +struct device *dev = &t7xx_dev->pdev->dev; +int ret; + + ret =wait_for_completion_timeout (&t7xx_dev->sleep_lock_acquire, +msecs_to_jiffies (PM_SLEEP_DIS_TIMEOUT_MS )); +if (!ret) +dev_err_ratelimited (dev,"Resource wait complete timed out\n" ); + +return ret; +} + +/** +* t7xx_pci_disable_sleep() - Disable deep sleep capability. +* @t7xx_dev: MTK device. +* +* Lock the deep sleep capability, note that the device can still go into deep sleep +* state while device is in D0 state, from the host's point-of-view. +* +* If device is in deep sleep state, wake up the device and disable deep sleep capability. +*/ +void t7xx_pci_disable_sleep (struct t7xx_pci_dev *t7xx_dev) +{ +unsigned long flags; + +if (atomic_read (&t7xx_dev->md_pm_state) <MTK_PM_RESUMED ) {
drivers/net/wwan/t7xx/t7xx_pci.c int t7xx_pci_pm_entity_unregister(struct t7xx_pci_dev *t7xx_dev, struct md_pm_en · line 224
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_pci.c +10
-0+atomic_inc (&t7xx_dev->sleep_disable_count); +complete_all (&t7xx_dev->sleep_lock_acquire); +return ; + } + +spin_lock_irqsave (&t7xx_dev->md_pm_lock, flags); +if (atomic_inc_return (&t7xx_dev->sleep_disable_count) ==1 ) { +u32 deep_sleep_enabled; + +reinit_completion (&t7xx_dev->sleep_lock_acquire);
You might want to check that there's a mechanism that prevents this racing with wait_for_completion_timeout() in t7xx_pci_sleep_disable_complete().
I couldn't prove it myself but there are probably aspect in the PM side of things I wasn't able to take fully into account (that is, which call paths are not possible to occur).
Quoted 14 lines
drivers/net/wwan/t7xx/t7xx_pci.c +14
-0+t7xx_dev_set_sleep_capability (t7xx_dev, false); + + deep_sleep_enabled =ioread32 (IREG_BASE (t7xx_dev) +T7XX_PCIE_RESOURCE_STATUS ); + deep_sleep_enabled &=T7XX_PCIE_RESOURCE_STS_MSK ; +if (deep_sleep_enabled) { +spin_unlock_irqrestore (&t7xx_dev->md_pm_lock, flags); +complete_all (&t7xx_dev->sleep_lock_acquire); +return ; + } + +t7xx_mhccif_h2d_swint_trigger (t7xx_dev,H2D_CH_DS_LOCK ); + } +spin_unlock_irqrestore (&t7xx_dev->md_pm_lock, flags); +}
Signature · 1 line
i.
Martinez, Ricardo
reviewerRe: [PATCH net-next v5 12/13] net: wwan: t7xx: Device deep sleep lock/unlock
Quoted 15 lines · Ilpo Järvinen
Quoted 13 lines · 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.
Signed-off-by Haijun Liu <[email protected]>Signed-off-by Chandrashekar Devegowda <[email protected]>Co-developed-by Ricardo Martinez <[email protected]>Signed-off-by Ricardo Martinez <[email protected]>---
...
Quoted 40 lines
Quoted 27 lines
drivers/net/wwan/t7xx/t7xx_pci.c +27
-0+int t7xx_pci_sleep_disable_complete (struct t7xx_pci_dev *t7xx_dev) +{ +struct device *dev = &t7xx_dev->pdev->dev; +int ret; + + ret =wait_for_completion_timeout (&t7xx_dev->sleep_lock_acquire, +msecs_to_jiffies (PM_SLEEP_DIS_TIMEOUT_MS )); +if (!ret) +dev_err_ratelimited (dev,"Resource wait complete timed out\n" ); + +return ret; +} + +/** +* t7xx_pci_disable_sleep() - Disable deep sleep capability. +* @t7xx_dev: MTK device. +* +* Lock the deep sleep capability, note that the device can still go into deep sleep +* state while device is in D0 state, from the host's point-of-view. +* +* If device is in deep sleep state, wake up the device and disable deep sleep capability. +*/ +void t7xx_pci_disable_sleep (struct t7xx_pci_dev *t7xx_dev) +{ +unsigned long flags; + +if (atomic_read (&t7xx_dev->md_pm_state) <MTK_PM_RESUMED ) {drivers/net/wwan/t7xx/t7xx_pci.c int t7xx_pci_pm_entity_unregister(struct t7xx_pci_dev *t7xx_dev, struct md_pm_en · line 224
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_pci.c +10
-0+atomic_inc (&t7xx_dev->sleep_disable_count); +complete_all (&t7xx_dev->sleep_lock_acquire); +return ; + } + +spin_lock_irqsave (&t7xx_dev->md_pm_lock, flags); +if (atomic_inc_return (&t7xx_dev->sleep_disable_count) ==1 ) { +u32 deep_sleep_enabled; + +reinit_completion (&t7xx_dev->sleep_lock_acquire);You might want to check that there's a mechanism that prevents this racing with
wait_for_completion_timeout()int7xx_pci_sleep_disable_complete().
Quoted 3 lines
I couldn't prove it myself but there are probably aspect in the PM side of things I wasn't able to take fully into account (that is, which call paths are not possible to occur).
Those functions are called in the following order:
1.- t7xx_pci_disable_sleep()
2.- t7xx_pci_sleep_disable_complete()
3.- t7xx_pci_enable_sleep()
That sequence and md_pm_lock protect against a race condition between wait_for_completion_timeout() and reinit_completion().
On the other hand, there could be a race condition between t7xx_pci_disable_sleep() and t7xx_pci_enable_sleep() which may cause sleep to get enabled while one thread expects it to be disabled. The fix would be to protect sleep_disable_count with md_pm_lock, then sleep_disable_count doesn't need to be declared as atomic.
The next version will include cleanup in this area.
Quoted 15 lines
Quoted 14 lines
drivers/net/wwan/t7xx/t7xx_pci.c +14
-0+t7xx_dev_set_sleep_capability (t7xx_dev, false); + + deep_sleep_enabled =ioread32 (IREG_BASE (t7xx_dev) +T7XX_PCIE_RESOURCE_STATUS ); + deep_sleep_enabled &=T7XX_PCIE_RESOURCE_STS_MSK ; +if (deep_sleep_enabled) { +spin_unlock_irqrestore (&t7xx_dev->md_pm_lock, flags); +complete_all (&t7xx_dev->sleep_lock_acquire); +return ; + } + +t7xx_mhccif_h2d_swint_trigger (t7xx_dev,H2D_CH_DS_LOCK ); + } +spin_unlock_irqrestore (&t7xx_dev->md_pm_lock, flags); +}
Re: [PATCH net-next v5 12/13] net: wwan: t7xx: Device deep sleep lock/unlock
Quoted 63 lines · Ricardo
Quoted 15 lines · Ilpo Järvinen
Quoted 13 lines · 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.
Signed-off-by Haijun Liu <[email protected]>Signed-off-by Chandrashekar Devegowda <[email protected]>Co-developed-by Ricardo Martinez <[email protected]>Signed-off-by Ricardo Martinez <[email protected]>---
...
Quoted 45 lines
Quoted 31 lines
drivers/net/wwan/t7xx/t7xx_pci.c +7
-0+int t7xx_pci_sleep_disable_complete (struct t7xx_pci_dev *t7xx_dev) +{ +struct device *dev = &t7xx_dev->pdev->dev; +int ret; + + ret = wait_for_completion_timeout(&t7xx_dev->sleep_lock_acquire, +
msecs_to_jiffies(PM_SLEEP_DIS_TIMEOUT_MS));(quoted diff) +2
-0+ if (!ret) + dev_err_ratelimited(dev, "Resource wait complete timedout\n");
drivers/net/wwan/t7xx/t7xx_pci.c +9
-0+ +return ret; +} + +/** +* t7xx_pci_disable_sleep() - Disable deep sleep capability. +* @t7xx_dev: MTK device. +* +* Lock the deep sleep capability, note that the device can still go into deep sleep
+ * state while device is in D0 state, from the host's point-of-view.
+ *
+ * If device is in deep sleep state, wake up the device and disable deep sleep capability.
+ */drivers/net/wwan/t7xx/t7xx_pci.c +5
-0+void t7xx_pci_disable_sleep (struct t7xx_pci_dev *t7xx_dev) +{ +unsigned long flags; + +if (atomic_read (&t7xx_dev->md_pm_state) <MTK_PM_RESUMED ) {drivers/net/wwan/t7xx/t7xx_pci.c int t7xx_pci_pm_entity_unregister(struct t7xx_pci_dev *t7xx_dev, struct md_pm_en · line 224
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_pci.c +10
-0+atomic_inc (&t7xx_dev->sleep_disable_count); +complete_all (&t7xx_dev->sleep_lock_acquire); +return ; + } + +spin_lock_irqsave (&t7xx_dev->md_pm_lock, flags); +if (atomic_inc_return (&t7xx_dev->sleep_disable_count) ==1 ) { +u32 deep_sleep_enabled; + +reinit_completion (&t7xx_dev->sleep_lock_acquire);You might want to check that there's a mechanism that prevents this racing with
wait_for_completion_timeout()int7xx_pci_sleep_disable_complete().
Quoted 7 lines
Quoted 3 lines
I couldn't prove it myself but there are probably aspect in the PM side of things I wasn't able to take fully into account (that is, which call paths are not possible to occur).
Those functions are called in the following order:
1.-t7xx_pci_disable_sleep()
2.-t7xx_pci_sleep_disable_complete()
3.-t7xx_pci_enable_sleep()
That sequence gets called from 5 places:
- t7xx_cldma_send_skb
- t7xx_dpmaif_rxq_work
- t7xx_dpmaif_bat_release_work
- t7xx_dpmaif_tx_done
- t7xx_dpmaif_tx_hw_push_thread + t7xx_do_tx_hw_push
Which of those can run parallel to each other, I'm not sure of. But they can, the race is likely there between those "instances" of the sequence, one instance doing reinit_completion() and the other wait_for_completion_timeout().
Quoted 2 lines
That sequence and
md_pm_lockprotect against a race condition betweenwait_for_completion_timeout()andreinit_completion().
wait_for_completion_timeout() is not protected by md_pm_lock. There is a path with return in t7xx_pci_disable_sleep() before taking md_pm_lock.
Quoted 3 lines
On the other hand, there could be a race condition between
t7xx_pci_disable_sleep()andt7xx_pci_enable_sleep()which may cause sleep to get enabled while one thread expects it to be disabled.
...And once sleep gets enabled, this can get true, no?
if (atomic_read(&t7xx_dev->md_pm_state) < MTK_PM_RESUMED) {...after which there's nothing which protects wait_for_completion_timeout() from racing with another instance of the sequence which has not yet executed reinit_completion()?
I think you found the very race which I was worried about. :-)
Quoted 3 lines
The fix would be to protect
sleep_disable_countwithmd_pm_lock, thensleep_disable_countdoesn't need to be declared as atomic. The next version will include cleanup in this area.
Ok. I'll take a look once you post the next version.
Signature · 1 line
i.
Ricardo Martinez
reviewerPATCH v5 13/13 net: wwan: t7xx: Add maintainers and documentation
In reply to Ricardo MartinezAdds maintainers and documentation for MediaTek t7xx 5G WWAN modem device driver.
From a WWAN framework perspective:
--- .../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
@@ -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
@@ -12338,6 +12338,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
Sergey Ryazanov
maintainerHello Ricardo,
Quoted 181 lines · Ricardo Martinez
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_T7XXconfig option which depends onCONFIG_WWAN.
This driver was originally developed by MediaTek. Intel adapted t7xx to the WWAN framework, optimized and refactored the driver source code in close collaboration with MediaTek. This will enable getting the t7xx driver on the 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]> Madhusmita Sahu <[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/523v5:
- Update Intel's copyright years to 2021-2022.
- Remove circular dependency between DPMAIF HW (07) and HIF (08).
- Keep separate patches for CLDMA (02) and Core (03)
but improve the code split by decoupling CLDMA from
modem ops and cleaning upt7xx_common.h.
- Rename ID_CLDMA0/ID_CLDMA1 to CLDMA_ID_AP/CLDMA_ID_MD.
- Consistently use CLDMA'sring_lockto protecttr_ring.
- Free resources first and then print messages.
- Implement suggested name changes.
- Do not explicitly includedev_printk.h.
- Remove redundant dev_err()s.
- Fix possible memory leak during probe.
- Remove infrastructure for legacy interrupts.
- Remove unused macros and variables, including those that
can be replaced with constants.
- RemovePCIE_MAC_MSIX_MSK_SETmacro which is duplicated code.
- Refactor__t7xx_pci_pm_suspend()for clarity.
- Refactort7xx_cldma_rx_ring_init()andt7xx_cldma_tx_ring_init().
- Do not use & for function callbacks.
- Declare a structure to access skb->cb[] data.
- Useskb_put_datainstead of memcpy.
- No need to usekfree_sensitive.
- Usedev_kfree_skb()instead ofkfree_skb().
- Refactort7xx_prepare_device_rt_data()to remove potential leaks, avoid unneeded memset and keeprt_dataandpacket_sizeupdates inside the same 'if' block.
- Set port'srx_length_thback to 0 during uninit.
- Remove unneeded 'blocking' parameter fromt7xx_cldma_send_skb().
- Return-EIOint7xx_cldma_send_skb()if the queue is inactive.
- Refactort7xx_cldma_qs_are_active()to usepci_device_is_present().
- Simplifyt7xx_cldma_stop_q()and rename it tot7xx_cldma_stop_all_qs().
- Fix potential leaks int7xx_cldma_init().
- Improve error handling infsm_append_eventandfsm_routine_starting().
- Propagate return codes fromfsm_append_cmd()andt7xx_fsm_append_event().
- Refactorfsm_wait_for_event()to avoid unnecessary sleep.
- Create the WWAN ports and net device only after the modem is in the ready state.
- Refactort7xx_port_proxy_recv_skb()andport_recv_skb().
- Renamet7xx_port_check_rx_seq_num()ast7xx_port_next_rx_seq_num()and fix theseq_numlogic to handle overflows.
- Declareseq_numsas u16 instead of short.
- Use unsigned int for local indexes.
- Usemin_tinstead of the ternary operator.
- Refactor the loop int7xx_dpmaif_rx_data_collect()to avoid a dead condition check.
- Use a bitmap (bat_bitmap) instead of an array to keep track of the DRB status. Used int7xx_dpmaif_avail_pkt_bat_cnt().
- Refactort7xx_dpmaif_tx_send_skb()to protecttx_submit_skb_cntwith spinlock and remove the misleadingtx_drb_availablevariable.
- Consolidate bit operations before endianness conversion.
- Use C bit fields indpmaif_drb_skbstruct which is not HW related.
- Add back theque_startedcheck int7xx_select_tx_queue().
- Create a helper function to get the DRB count.
- Simplify the use of 'usage' duringt7xx_ccmni_close().
- Enforce CCMNI MTU selection withBUILD_BUG_ON()instead of a comment.
- Removet7xx_ccmni_ctrl->capabilityparameter which remains constant.v4:
- Implementlist_prev_entry_circular()andlist_next_entry_circular()macros.
- Remove inline from all c files.
- Defineioread32_poll_timeout_atomic()helper macro.
- Fix return code for WWAN port tx op.
- Allow AT commands fragmentation same as MBIM commands.
- Introducet7xx_common.hfile in the first patch.
- Rename functions and variables as suggested in v3.
- Reduce code duplication by creatingfsm_wait_for_event()helper function.
- Remove unneededdev_errint7xx_fsm_clr_event().
- Remove unused variablelast_statefrom structt7xx_fsm_ctl.
- Remove unused variabletxq_select_timesfrom structdpmaif_ctrl.
- Replace ETXTBSY with EBUSY.
- Refactort7xx_dpmaif_rx_buf_alloc()to remove an unneeded allocation.
- Fix potential leak att7xx_dpmaif_rx_frag_alloc().
- Simplify return value handling att7xx_dpmaif_rx_start().
- Add a helper to handle the common part of CCCI header initialization.
- Make sure interrupts are enabled during PM resume.
- Add a parameter tot7xx_fsm_append_cmd()to tell if it is in interrupt context.v3:
- Avoid unneeded ping-pong changes between patches.
- Uset7xx_prefix in functions.
- Uset7xx_prefix in generic structs wheremtk_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__packedattribute 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 unneededmb()in CLDMA.
- Remove unneeded spin locks and atomics.
- Handleread_poll_timeouterror.
- Usedev_err_ratelimited()where required.
- Fix resource leak when requesting IRQs.
- Use genericDEFAULT_TX_QUEUE_LENinstead custom macro.
- UseETH_DATA_LENinstead of definingWWAN_DEFAULT_MTU.
- Usesizeof()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
Quoted 7 lines
v2:
- Replacepdev->driver->namewithdev_driver_string(&pdev->dev).
- Replacerandom_ether_addr()witheth_random_addr().
- Update kernel-doc comment for enumdata_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.
Sorry for the delay in review. There are too many changes from version to version and it took some time to dig through them. I would like to admit that the driver now looks much better. Good job!
Please find per-patch comments.
--
Sergey