net: wwan: t7xx: PCIe driver for MediaTek M.2 modem
Subsystems (5)
Ricardo Martinez
reviewerv2 cover net: wwan: t7xx: PCIe driver for MediaTek M.2 modem
t7xx is the PCIe host device driver for Intel 5G 5000 M.2 solution which is based on MediaTek's T700 modem to provide WWAN connectivity. The driver uses the WWAN framework infrastructure to create the following control ports and network interfaces:
* /dev/wwan0mbim0 - Interface conforming to the MBIM protocol. Applications like libmbim [1] or Modem Manager [2] from v1.16 onwards with [3][4] can use it to enable data communication towards WWAN.
* /dev/wwan0at0 - Interface that supports AT commands.
* wwan0 - Primary network interface for IP traffic.
The main blocks in t7xx driver are:
* PCIe layer - Implements probe, removal, and power management callbacks.
* Port-proxy - Provides a common interface to interact with different types of ports such as WWAN ports.
* Modem control & status monitor - Implements the entry point for modem initialization, reset and exit, as well as exception handling.
* CLDMA (Control Layer DMA) - Manages the HW used by the port layer to send control messages to the modem using MediaTek's CCCI (Cross-Core Communication Interface) protocol.
* DPMAIF (Data Plane Modem AP Interface) - Controls the HW that provides uplink and downlink queues for the data path. The data exchange takes place using circular buffers to share data buffer addresses and metadata to describe the packets.
* MHCCIF (Modem Host Cross-Core Interface) - Provides interrupt channels for bidirectional event notification such as handshake, exception, PM and port enumeration.
The compilation of the t7xx driver is enabled by the CONFIG_MTK_T7XX config option which depends on CONFIG_WWAN.
This driver was originally developed by MediaTek. Intel adapted t7xx to the WWAN framework, optimized and refactored the driver source in close collaboration with MediaTek. This will enable getting the t7xx driver on Approved Vendor List for interested OEM's and ODM's productization plans with Intel 5G 5000 M.2 solution.
List of contributors:
Amir Hanania <[email protected]>
Andriy Shevchenko <[email protected]> Chandrashekar Devegowda <[email protected]> Dinesh Sharma <[email protected]>
Eliot Lee <[email protected]>
Haijun Liu <[email protected]>
M Chetan Kumar <[email protected]>
Mika Westerberg <[email protected]> Moises Veleta <[email protected]> Pierre-louis Bossart <[email protected]> Chiranjeevi Rapolu <[email protected]> Ricardo Martinez <[email protected]> Muralidharan Sethuraman <[email protected]> Soumya Prakash Mishra <[email protected]> Sreehari Kancharla <[email protected]> Suresh Nagaraj <[email protected]>
[1] https://www.freedesktop.org/software/libmbim/
[2] https://www.freedesktop.org/software/ModemManager/
[3] https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/merge_requests/582
[4] https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/merge_requests/523
v2:
- Replace pdev->driver->name with dev_driver_string(&pdev->dev).
- Replace random_ether_addr() with eth_random_addr().
- Update kernel-doc comment for enum data_policy.
- Indicate the driver is 'Supported' instead of 'Maintained'.
- Fix the Signed-of-by and Co-developed-by tags in the patches.
- Added authors and contributors in the top comment of the src files.
Chandrashekar Devegowda (1):
net: wwan: t7xx: Add AT and MBIM WWAN ports
Haijun Lio (11):
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: Data path HW layer
net: wwan: t7xx: Add data path interface
net: wwan: t7xx: Add WWAN network interface
net: wwan: t7xx: Introduce power management support
net: wwan: t7xx: Runtime PM
net: wwan: t7xx: Device deep sleep lock/unlock
net: wwan: t7xx: Add debug and test ports
Ricardo Martinez (2):
net: wwan: Add default MTU size
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 | 24 + drivers/net/wwan/t7xx/t7xx_cldma.c | 277 +++ drivers/net/wwan/t7xx/t7xx_cldma.h | 168 ++ drivers/net/wwan/t7xx/t7xx_common.h | 76 + drivers/net/wwan/t7xx/t7xx_dpmaif.c | 1524 +++++++++++++++ drivers/net/wwan/t7xx/t7xx_dpmaif.h | 168 ++ drivers/net/wwan/t7xx/t7xx_hif_cldma.c | 1663 +++++++++++++++++ drivers/net/wwan/t7xx/t7xx_hif_cldma.h | 156 ++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c | 638 +++++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h | 279 +++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 1562 ++++++++++++++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h | 117 ++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c | 842 +++++++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.h | 82 + drivers/net/wwan/t7xx/t7xx_mhccif.c | 124 ++ drivers/net/wwan/t7xx/t7xx_mhccif.h | 35 + drivers/net/wwan/t7xx/t7xx_modem_ops.c | 747 ++++++++ drivers/net/wwan/t7xx/t7xx_modem_ops.h | 92 + drivers/net/wwan/t7xx/t7xx_monitor.h | 147 ++ drivers/net/wwan/t7xx/t7xx_netdev.c | 545 ++++++ drivers/net/wwan/t7xx/t7xx_netdev.h | 63 + drivers/net/wwan/t7xx/t7xx_pci.c | 789 ++++++++ drivers/net/wwan/t7xx/t7xx_pci.h | 121 ++ drivers/net/wwan/t7xx/t7xx_pcie_mac.c | 277 +++ drivers/net/wwan/t7xx/t7xx_pcie_mac.h | 36 + drivers/net/wwan/t7xx/t7xx_port.h | 163 ++ drivers/net/wwan/t7xx/t7xx_port_char.c | 424 +++++ drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c | 150 ++ drivers/net/wwan/t7xx/t7xx_port_proxy.c | 829 ++++++++ drivers/net/wwan/t7xx/t7xx_port_proxy.h | 102 + drivers/net/wwan/t7xx/t7xx_port_tty.c | 191 ++ drivers/net/wwan/t7xx/t7xx_port_wwan.c | 281 +++ drivers/net/wwan/t7xx/t7xx_reg.h | 398 ++++ drivers/net/wwan/t7xx/t7xx_skb_util.c | 362 ++++ drivers/net/wwan/t7xx/t7xx_skb_util.h | 110 ++ drivers/net/wwan/t7xx/t7xx_state_monitor.c | 627 +++++++ drivers/net/wwan/t7xx/t7xx_tty_ops.c | 205 ++ drivers/net/wwan/t7xx/t7xx_tty_ops.h | 44 + include/linux/wwan.h | 5 + 44 files changed, 14590 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_monitor.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_char.c 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_tty.c 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_skb_util.c create mode 100644 drivers/net/wwan/t7xx/t7xx_skb_util.h create mode 100644 drivers/net/wwan/t7xx/t7xx_state_monitor.c create mode 100644 drivers/net/wwan/t7xx/t7xx_tty_ops.c create mode 100644 drivers/net/wwan/t7xx/t7xx_tty_ops.h
Signature · 1 line
2.17.1
Ricardo Martinez
reviewerPATCH v2 1/14 net: wwan: Add default MTU size
Add a default MTU size definition that new WWAN drivers can refer to.
--- include/linux/wwan.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/wwan.h +5 -0
@@ -171,4 +171,9 @@ int wwan_register_ops(struct device *parent, const struct wwan_ops *ops,void wwan_unregister_ops (struct device *parent); +/* +* Default WWAN interface MTU value +*/ +#define WWAN_DEFAULT_MTU 1500 +#endif /* __WWAN_H */
Signature · 1 line
2.17.1
Sergey Ryazanov
maintainerRe: [PATCH v2 01/14] net: wwan: Add default MTU size
Quoted 1 line · Ricardo Martinez
Add a default MTU size definition that new WWAN drivers can refer to.
[skipped]
include/linux/wwan.h int wwan_register_ops(struct device *parent, const struct wwan_ops *ops, · line 177
Quoted 4 lines
include/linux/wwan.h +4
-0+/* +* Default WWAN interface MTU value +*/ +#define WWAN_DEFAULT_MTU 1500
Why do you need another one macro for the 1500 bytes default MTU? Consider using ETH_DATA_LEN macro.
--
Sergey
Ricardo Martinez
reviewerPATCH v2 2/14 net: wwan: t7xx: Add control DMA interface
In reply to Ricardo MartinezFrom: Haijun Lio <[email protected]>
Cross Layer DMA (CLDMA) Hardware interface (HIF) enables the control path of Host-Modem data transfers. CLDMA HIF layer provides a common interface to the Port Layer.
CLDMA manages 8 independent RX/TX physical channels with data flow control in HW queues. CLDMA uses ring buffers of General Packet Descriptors (GPD) for TX/RX. GPDs can represent multiple or single data buffers (DB).
CLDMA HIF initializes GPD rings, registers ISR handlers for CLDMA interrupts, and initializes CLDMA HW registers.
CLDMA TX flow:
1. Port Layer write
2. Get DB address
3. Configure GPD
4. Triggering processing via HW register write
CLDMA RX flow:
1. CLDMA HW sends a RX "done" to host
2. Driver starts thread to safely read GPD
3. DB is sent to Port layer
4. Create a new buffer for GPD ring
--- drivers/net/wwan/t7xx/t7xx_cldma.c | 277 +++++ drivers/net/wwan/t7xx/t7xx_cldma.h | 168 +++ drivers/net/wwan/t7xx/t7xx_hif_cldma.c | 1519 ++++++++++++++++++++++++ drivers/net/wwan/t7xx/t7xx_hif_cldma.h | 155 +++ 4 files changed, 2119 insertions(+) create mode 100644 drivers/net/wwan/t7xx/t7xx_cldma.c create mode 100644 drivers/net/wwan/t7xx/t7xx_cldma.h create mode 100644 drivers/net/wwan/t7xx/t7xx_hif_cldma.c create mode 100644 drivers/net/wwan/t7xx/t7xx_hif_cldma.h
drivers/net/wwan/t7xx/t7xx_cldma.c new file +277 -0
@@ -0,0 +1,277 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) 2021, MediaTek Inc. +* Copyright (c) 2021, Intel Corporation. +* +* Authors: Haijun Lio <[email protected]> +* Contributors: Amir Hanania <[email protected]> +* Andy Shevchenko <[email protected]> +* Moises Veleta <[email protected]> +* Ricardo Martinez<[email protected]> +* Sreehari Kancharla <[email protected]> +*/ + +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/io-64-nonatomic-lo-hi.h> + +#include "t7xx_cldma.h" + +void cldma_clear_ip_busy (struct cldma_hw_info *hw_info) +{ +/* write 1 to clear IP busy register wake up CPU case */ +iowrite32 (ioread32 (hw_info->ap_pdn_base +REG_CLDMA_IP_BUSY ) |IP_BUSY_WAKEUP , + hw_info->ap_pdn_base +REG_CLDMA_IP_BUSY ); +} + +/** +* cldma_hw_restore() - Restore CLDMA HW registers +* @hw_info: Pointer to struct cldma_hw_info +* +* Restore HW after resume. Writes uplink configuration for CLDMA HW. +* +*/ +void cldma_hw_restore (struct cldma_hw_info *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 cldma_hw_start_queue (struct cldma_hw_info *hw_info,u8 qno,bool is_rx) +{ +void __iomem *reg_start_cmd; +u32 val; + +mb ();/* prevents outstanding GPD updates */ + reg_start_cmd = is_rx ? hw_info->ap_pdn_base +REG_CLDMA_DL_START_CMD : + hw_info->ap_pdn_base +REG_CLDMA_UL_START_CMD ; + + val = (qno ==CLDMA_ALL_Q ) ?CLDMA_ALL_Q :BIT (qno); +iowrite32 (val, reg_start_cmd); +} + +void cldma_hw_start (struct cldma_hw_info *hw_info) +{ +/* unmask txrx interrupt */ +iowrite32 (TXRX_STATUS_BITMASK , hw_info->ap_pdn_base +REG_CLDMA_L2TIMCR0 ); +iowrite32 (TXRX_STATUS_BITMASK , hw_info->ap_ao_base +REG_CLDMA_L2RIMCR0 ); +/* unmask 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 cldma_hw_reset (void __iomem *ao_base) +{ +iowrite32 (ioread32 (ao_base +REG_INFRA_RST4_SET ) |RST4_CLDMA1_SW_RST_SET , + ao_base +REG_INFRA_RST4_SET ); +iowrite32 (ioread32 (ao_base +REG_INFRA_RST2_SET ) |RST2_CLDMA1_AO_SW_RST_SET , + ao_base +REG_INFRA_RST2_SET ); +udelay (1 ); +iowrite32 (ioread32 (ao_base +REG_INFRA_RST4_CLR ) |RST4_CLDMA1_SW_RST_CLR , + ao_base +REG_INFRA_RST4_CLR ); +iowrite32 (ioread32 (ao_base +REG_INFRA_RST2_CLR ) |RST2_CLDMA1_AO_SW_RST_CLR , + ao_base +REG_INFRA_RST2_CLR ); +} + +bool cldma_tx_addr_is_set (struct cldma_hw_info *hw_info,unsigned char qno) +{ +return !!ioread64 (hw_info->ap_pdn_base +REG_CLDMA_UL_START_ADDRL_0 + qno *8 ); +} + +void cldma_hw_set_start_address (struct cldma_hw_info *hw_info,unsigned char qno,u64 address, +bool is_rx) +{ +void __iomem *base; + +if (is_rx) { + base = hw_info->ap_ao_base; +iowrite64 (address, base +REG_CLDMA_DL_START_ADDRL_0 + qno *8 ); + }else { + base = hw_info->ap_pdn_base; +iowrite64 (address, base +REG_CLDMA_UL_START_ADDRL_0 + qno *8 ); + } +} + +void cldma_hw_resume_queue (struct cldma_hw_info *hw_info,unsigned char qno,bool is_rx) +{ +void __iomem *base; + + base = hw_info->ap_pdn_base; +mb ();/* prevents outstanding GPD updates */ + +if (is_rx) +iowrite32 (BIT (qno), base +REG_CLDMA_DL_RESUME_CMD ); +else +iowrite32 (BIT (qno), base +REG_CLDMA_UL_RESUME_CMD ); +} + +unsigned int cldma_hw_queue_status (struct cldma_hw_info *hw_info,unsigned char qno,bool is_rx) +{ +u32 mask; + + mask = (qno ==CLDMA_ALL_Q ) ?CLDMA_ALL_Q :BIT (qno); +if (is_rx) +return ioread32 (hw_info->ap_ao_base +REG_CLDMA_DL_STATUS ) & mask; +else +return ioread32 (hw_info->ap_pdn_base +REG_CLDMA_UL_STATUS ) & mask; +} + +void cldma_hw_tx_done (struct cldma_hw_info *hw_info,unsigned int bitmask) +{ +unsigned int ch_id; + + ch_id =ioread32 (hw_info->ap_pdn_base +REG_CLDMA_L2TISAR0 ) & bitmask; +/* ack interrupt */ +iowrite32 (ch_id, hw_info->ap_pdn_base +REG_CLDMA_L2TISAR0 ); +ioread32 (hw_info->ap_pdn_base +REG_CLDMA_L2TISAR0 ); +} + +void cldma_hw_rx_done (struct cldma_hw_info *hw_info,unsigned int bitmask) +{ +unsigned int ch_id; + + ch_id =ioread32 (hw_info->ap_pdn_base +REG_CLDMA_L2RISAR0 ) & bitmask; +/* ack interrupt */ +iowrite32 (ch_id, hw_info->ap_pdn_base +REG_CLDMA_L2RISAR0 ); +ioread32 (hw_info->ap_pdn_base +REG_CLDMA_L2RISAR0 ); +} + +unsigned int cldma_hw_int_status (struct cldma_hw_info *hw_info,unsigned int bitmask,bool is_rx) +{ +void __iomem *reg_int_sta; + + reg_int_sta = is_rx ? hw_info->ap_pdn_base +REG_CLDMA_L2RISAR0 : + hw_info->ap_pdn_base +REG_CLDMA_L2TISAR0 ; + +return ioread32 (reg_int_sta) & bitmask; +} + +void cldma_hw_mask_txrxirq (struct cldma_hw_info *hw_info,unsigned char qno,bool is_rx) +{ +void __iomem *reg_ims; +u32 val; + +/* select the right interrupt mask set register */ + reg_ims = is_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_ims); +} + +void cldma_hw_mask_eqirq (struct cldma_hw_info *hw_info,unsigned char qno,bool is_rx) +{ +void __iomem *reg_ims; +u32 val; + +/* select the right interrupt mask set register */ + reg_ims = is_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_ims); +} + +void cldma_hw_dismask_txrxirq (struct cldma_hw_info *hw_info,unsigned char qno,bool is_rx) +{ +void __iomem *reg_imc; +u32 val; + +/* select the right interrupt mask clear register */ + reg_imc = is_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_imc); +} + +void cldma_hw_dismask_eqirq (struct cldma_hw_info *hw_info,unsigned char qno,bool is_rx) +{ +void __iomem *reg_imc; +u32 val; + +/* select the right interrupt mask clear register */ + reg_imc = is_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_imc); +} + +/** +* cldma_hw_init() - Initialize CLDMA HW +* @hw_info: Pointer to struct cldma_hw_info +* +* Write uplink and downlink configuration to CLDMA HW. +* +*/ +void cldma_hw_init (struct cldma_hw_info *hw_info) +{ +u32 ul_cfg; +u32 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 ); +/* enable interrupt */ +iowrite32 (0 , hw_info->ap_ao_base +REG_CLDMA_INT_MASK ); +/* mask wakeup signal */ +iowrite32 (BUSY_MASK_MD , hw_info->ap_ao_base +REG_CLDMA_BUSY_MASK ); +/* 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 cldma_hw_stop_queue (struct cldma_hw_info *hw_info,u8 qno,bool is_rx) +{ +void __iomem *reg_stop_cmd; +u32 val; + + reg_stop_cmd = is_rx ? hw_info->ap_pdn_base +REG_CLDMA_DL_STOP_CMD : + hw_info->ap_pdn_base +REG_CLDMA_UL_STOP_CMD ; + + val = (qno ==CLDMA_ALL_Q ) ?CLDMA_ALL_Q :BIT (qno); +iowrite32 (val, reg_stop_cmd); +} + +void cldma_hw_stop (struct cldma_hw_info *hw_info,bool is_rx) +{ +void __iomem *reg_ims; + +/* select the right L2 interrupt mask set register */ + reg_ims = is_rx ? hw_info->ap_ao_base +REG_CLDMA_L2RIMSR0 : + hw_info->ap_pdn_base +REG_CLDMA_L2TIMSR0 ; + +iowrite32 (TXRX_STATUS_BITMASK , reg_ims); +iowrite32 (EMPTY_STATUS_BITMASK , reg_ims); +}
drivers/net/wwan/t7xx/t7xx_cldma.h new file +168 -0
168 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +1519 -0
1,519 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_hif_cldma.h new file +155 -0
155 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v2 02/14] net: wwan: t7xx: Add control DMA interface
Quoted 26 lines · Ricardo Martinez
From: Haijun Lio <[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 4 lines
Signed-off-by Haijun Lio <[email protected]>Signed-off-by Chandrashekar Devegowda <[email protected]>Co-developed-by Ricardo Martinez <[email protected]>Signed-off-by Ricardo Martinez <[email protected]>
This...
Quoted 1 line
+ * Authors: Haijun Lio <[email protected]>
(singular form?)
Quoted 5 lines
+ * Contributors: Amir Hanania <[email protected]>
+ * Andy Shevchenko <[email protected]> + * Moises Veleta <[email protected]> + * Ricardo Martinez<[email protected]> + * Sreehari Kancharla <[email protected]>
...doesn't correlate with the above.
At least Ricardo seems to be the (co-)author of the code according to the tag block above.
Also consider to start list(s) from the new line:
Autors:
A B <>
X Y <>
etc.
...
drivers/net/wwan/t7xx/t7xx_cldma.c line 16
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_cldma.c new file +3
-0+#include <linux/delay.h> +#include <linux/io.h> +#include <linux/io-64-nonatomic-lo-hi.h>
You may play with iwyu and amend this (including for headers and the rest of the C-files).
drivers/net/wwan/t7xx/t7xx_cldma.c line 24
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_cldma.c new file +7
-0+#include "t7xx_cldma.h" + +void cldma_clear_ip_busy (struct cldma_hw_info *hw_info) +{ +/* write 1 to clear IP busy register wake up CPU case */ +iowrite32 (ioread32 (hw_info->ap_pdn_base +REG_CLDMA_IP_BUSY ) |IP_BUSY_WAKEUP , + hw_info->ap_pdn_base +REG_CLDMA_IP_BUSY );
Much easier to read in the standard pattern, i.e.
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);
drivers/net/wwan/t7xx/t7xx_cldma.c line 32
Quoted 9 lines
drivers/net/wwan/t7xx/t7xx_cldma.c new file +8
-0+} + +/** +* cldma_hw_restore() - Restore CLDMA HW registers +* @hw_info: Pointer to struct cldma_hw_info +* +* Restore HW after resume. Writes uplink configuration for CLDMA HW. +*
Redundant blank line. Check again your code for unneeded redundant lines.
Quoted 1 line
+ */
...
drivers/net/wwan/t7xx/t7xx_cldma.c line 86
Quoted 11 lines
drivers/net/wwan/t7xx/t7xx_cldma.c new file +11
-0+void cldma_hw_reset (void __iomem *ao_base) +{ +iowrite32 (ioread32 (ao_base +REG_INFRA_RST4_SET ) |RST4_CLDMA1_SW_RST_SET , + ao_base +REG_INFRA_RST4_SET ); +iowrite32 (ioread32 (ao_base +REG_INFRA_RST2_SET ) |RST2_CLDMA1_AO_SW_RST_SET , + ao_base +REG_INFRA_RST2_SET ); +udelay (1 ); +iowrite32 (ioread32 (ao_base +REG_INFRA_RST4_CLR ) |RST4_CLDMA1_SW_RST_CLR , + ao_base +REG_INFRA_RST4_CLR ); +iowrite32 (ioread32 (ao_base +REG_INFRA_RST2_CLR ) |RST2_CLDMA1_AO_SW_RST_CLR , + ao_base +REG_INFRA_RST2_CLR );
Setting and clearing are in the same order, is it okay? Can we do it rather symmetrical?
Quoted 1 line
+}
...
Review
Quoted 1 line
(quoted diff) +1
-0+ mb(); /* prevents outstanding GPD updates */
Is there any counterpart of this barrier?
...
drivers/net/wwan/t7xx/t7xx_cldma.c line 136
Quoted 1 line
drivers/net/wwan/t7xx/t7xx_cldma.c new file +1
-0+ ch_id =ioread32 (hw_info->ap_pdn_base +REG_CLDMA_L2TISAR0 ) & bitmask;
ch_id = ioread32(hw_info->ap_pdn_base + REG_CLDMA_L2TISAR0); ch_id &= bitmask;
Consider to use this pattern everywhere in the similar cases.
...
Review
Quoted 1 line
(quoted diff) +1
-0+ /* ack interrupt */
Is it useful? If so it sounds to me like half said phrase, perhaps needs more elaboration?
...
drivers/net/wwan/t7xx/t7xx_cldma.c line 250
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_cldma.c new file +3
-0+/* enable interrupt */ +/* mask wakeup signal */ +/* disable TX and RX invalid address check */
Diito to all of these and more.
You shouldn't describe what code is doing, you should put why it's doing it.
...
drivers/net/wwan/t7xx/t7xx_cldma.h line 25
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_cldma.h new file +3
-0+/* interrupt status bit meaning, bitmask */ +#define EMPTY_STATUS_BITMASK 0xff00 +#define TXRX_STATUS_BITMASK 0x00ff
GENMASK()
drivers/net/wwan/t7xx/t7xx_cldma.h line 34
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_cldma.h new file +6
-0+/* L2RISAR0 */ +#define TQ_ERR_INT_BITMASK 0x00ff0000 +#define TQ_ACTIVE_START_ERR_INT_BITMASK 0xff000000 + +#define RQ_ERR_INT_BITMASK 0x00ff0000 +#define RQ_ACTIVE_START_ERR_INT_BITMASK 0xff000000
GENMASK()
What exactly BIT means in all of them when they are _not_ bit masks?
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 113
Quoted 9 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +9
-0+static struct cldma_request *cldma_ring_step_forward (struct cldma_ring *ring, +struct cldma_request *req) +{ +struct cldma_request *next_req; + +if (req->entry.next == &ring->gpd_ring) + next_req = list_first_entry(&ring->gpd_ring, struct cldma_request, entry); +else + next_req = list_entry(req->entry.next, struct cldma_request, entry);
list_next_entry()
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 126
Quoted 13 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +13
-0+ +return next_req; +} + +static struct cldma_request *cldma_ring_step_backward (struct cldma_ring *ring, +struct cldma_request *req) +{ +struct cldma_request *prev_req; + +if (req->entry.prev == &ring->gpd_ring) + prev_req = list_last_entry(&ring->gpd_ring, struct cldma_request, entry); +else + prev_req = list_entry(req->entry.prev, struct cldma_request, entry);
list_prev_entry()
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +3
-0+ +return prev_req; +}
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 142
Quoted 13 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +12
-0+static int cldma_gpd_rx_from_queue (struct cldma_queue *queue,int budget,bool *over_budget) +{ +unsigned char hwo_polling_count =0 ; +struct cldma_hw_info *hw_info; +struct cldma_ctrl *md_ctrl; +struct cldma_request *req; +struct cldma_rgpd *rgpd; +struct sk_buff *new_skb; +bool rx_done = false; +struct sk_buff *skb; +int count =0 ; +int ret =0 ;
How exactly is this assignment being used?
You need to revisit all of them in the driver.
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 147
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +3
-0+ md_ctrl =md_cd_get (queue->hif_id); + hw_info = &md_ctrl->hw_info; +while (!rx_done) {
do {
Quoted 9 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +9
-0+ req = queue->tr_done; +if (!req) { +dev_err (md_ctrl->dev,"RXQ was released\n" ); +return -ENODATA ; + } + + rgpd = req->gpd; +if ((rgpd->gpd_flags &GPD_FLAGS_HWO ) || !req->skb) { +u64 gpd_addr;
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 165
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +9
-0+ +/* current 64 bit address is in a table by Q index */ + gpd_addr =ioread64 (hw_info->ap_pdn_base + +REG_CLDMA_DL_CURRENT_ADDRL_0 + + queue->index *sizeof (u64)); +if (gpd_addr ==GENMASK_ULL (63 ,0 )) { +dev_err (md_ctrl->dev,"PCIe Link disconnected\n" ); +return -ENODATA ; + }
I'm wondering if PCI core provides some common method for that (like pci_dev_is_present() or so) and if it can be used here.
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 173
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +7
-0+if ((u64 )queue->tr_done->gpd_addr != gpd_addr && + hwo_polling_count++ <100 ) { +udelay (1 ); +continue ; + } + +break ;
I would rather expect
if (...) break; ... continue;
Quoted 15 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +15
-0+ } + + hwo_polling_count =0 ; + skb = req->skb; + +if (req->mapped_buff) { +dma_unmap_single (md_ctrl->dev, req->mapped_buff, +skb_data_size (skb),DMA_FROM_DEVICE ); + req->mapped_buff =0 ; + } + +/* init skb struct */ + skb->len =0 ; +skb_reset_tail_pointer (skb); +skb_put (skb, rgpd->data_buff_len);
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 198
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +9
-0+ +/* consume skb */ +if (md_ctrl->recv_skb) { + ret = md_ctrl->recv_skb (queue, skb); + }else { +ccci_free_skb (&md_ctrl->mtk_dev->pools, skb); + ret = -ENETDOWN ; + } + new_skb =NULL ;
Would be better to put it to else branch...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 203
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +5
-0+if (ret >=0 || ret == -ENETDOWN ) + new_skb =ccci_alloc_skb_from_pool (&md_ctrl->mtk_dev->pools, + queue->tr_ring->pkt_size, +GFS_BLOCKING ); +
...and drop this empty line.
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 207
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +4
-0+if (!new_skb) { +/* either the port was busy or the skb pool was empty */ +usleep_range (5000 ,10000 ); +return -EAGAIN ;
Neither comment, nor function name suggests this error code. Why not -EBUSY nor -ENOMEM?
Quoted 20 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +20
-0+ } + +/* mark cldma_request as available */ + req->skb =NULL ; +cldma_rgpd_set_data_ptr (rgpd,0 ); + queue->tr_done =cldma_ring_step_forward (queue->tr_ring, req); + + req = queue->rx_refill; + rgpd = req->gpd; + req->mapped_buff =dma_map_single (md_ctrl->dev, new_skb->data, +skb_data_size (new_skb),DMA_FROM_DEVICE ); +if (dma_mapping_error (md_ctrl->dev, req->mapped_buff)) { +dev_err (md_ctrl->dev,"DMA mapping failed\n" ); + req->mapped_buff =0 ; +ccci_free_skb (&md_ctrl->mtk_dev->pools, new_skb); +return -ENOMEM ; + } + +cldma_rgpd_set_data_ptr (rgpd, req->mapped_buff); + rgpd->data_buff_len =0 ;
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 237
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +9
-0+/* set HWO, no need to hold ring_lock */ + rgpd->gpd_flags =GPD_FLAGS_IOC |GPD_FLAGS_HWO ; +/* mark cldma_request as available */ + req->skb = new_skb; + queue->rx_refill =cldma_ring_step_forward (queue->tr_ring, req); +if (++count >= budget &&need_resched ()) { + *over_budget = true; + rx_done = true; + }
} while (...); *over_budget = true;
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +4
-0+ } + +return 0 ; +}
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 263
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +6
-0+ ret =cldma_gpd_rx_from_queue (queue, budget, &over_budget); +if (ret == -ENODATA ) +return 0 ; + +if (ret) +return ret;
Drop redundant blank line
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 273
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +3
-0+/* greedy mode */ + l2_rx_int =cldma_hw_int_status (hw_info,BIT (queue->index), true); +
Redundant blank line. I think you may shrink your driver by 100+ LOCs due to these...
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +3
-0+if (l2_rx_int) { + } + }
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 300
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +6
-0+struct cldma_ctrl *md_ctrl; +struct cldma_queue *queue; +int value; + + queue = container_of(work, struct cldma_queue, cldma_rx_work); + md_ctrl =md_cd_get (queue->hif_id);
These assignments seem easily can be unified with the definitions.
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 302
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +2
-0+ value = queue->tr_ring->handle_rx_done (queue, queue->budget); +
Redundant.
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +4
-0+if (value && md_ctrl->rxq_active &BIT (queue->index)) { +queue_work (queue->worker, &queue->cldma_rx_work); +return ; + }
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 332
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +4
-0+spin_lock_irqsave (&queue->ring_lock, flags); + req = queue->tr_done; +if (!req) { +dev_err (md_ctrl->dev,"TXQ was released\n" );
Under spin lock?! Why?
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +3
-0+spin_unlock_irqrestore (&queue->ring_lock, flags); +break ; + }
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 351
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +9
-0+/* restore IOC setting */ +if (req->ioc_override &GPD_FLAGS_IOC ) { +if (req->ioc_override &GPD_FLAGS_HWO ) + tgpd->gpd_flags |=GPD_FLAGS_IOC ; +else + tgpd->gpd_flags &= ~GPD_FLAGS_IOC ; +dev_notice (md_ctrl->dev, +"qno%u, req->ioc_override=0x%x,tgpd->gpd_flags=0x%x\n" , + queue->index, req->ioc_override, tgpd->gpd_flags);
Why so high level of the message without baling out?
Quoted 1 line
(quoted diff) +1
-0+ }
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 409
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +7
-0+ ul_curr_addr =ioread64 (hw_info->ap_pdn_base + +REG_CLDMA_UL_CURRENT_ADDRL_0 + + queue->index *sizeof (u64)); +if (req->gpd_addr != ul_curr_addr) +dev_err (md_ctrl->dev, +"CLDMA%d Q%d TGPD addr, SW:%pad, HW:%pad\n" , md_ctrl->hif_id, + queue->index, &req->gpd_addr, &ul_curr_addr);
Why error level without bailing out?
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +3
-0+else +/* retry */ +cldma_hw_resume_queue (&md_ctrl->hw_info, queue->index, false);
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 428
Quoted 9 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +9
-0+struct cldma_hw_info *hw_info; +struct cldma_ctrl *md_ctrl; +struct cldma_queue *queue; +unsigned int l2_tx_int; +unsigned long flags; + + queue = container_of(work, struct cldma_queue, cldma_tx_work); + md_ctrl =md_cd_get (queue->hif_id); + hw_info = &md_ctrl->hw_info;
Can be unified with definitions above.
Same to all similar cases.
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ item->gpd = dma_pool_alloc(md_ctrl->gpd_dmapool, GFP_KERNEL | __GFP_ZERO, + &item->gpd_addr);
dma_pool_zalloc()
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +2
-0+if (!item->gpd) + goto err_gpd_alloc;
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ item->gpd = dma_pool_alloc(md_ctrl->gpd_dmapool, GFP_KERNEL | __GFP_ZERO, + &item->gpd_addr);
Ditto.
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +4
-0+if (!item->gpd) { +kfree (item); +return NULL ; + }
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 676
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +2
-0+for (i =0 ; i <CLDMA_TXQ_NUM ; i++) { +if (l2_tx_int &BIT (i)) {
NIH for_each_set_bit()
Quoted 1 line
(quoted diff) +1
-0+ }
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 704
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +2
-0+for (i =0 ; i <CLDMA_RXQ_NUM ; i++) { +if (l2_rx_int & (BIT (i) |EQ_STA_BIT (i))) {
Ditto.
Quoted 1 line
(quoted diff) +1
-0+ }
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 724
Quoted 1 line
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +1
-0+return ((tx_active || rx_active) && tx_active !=CLDMA_ALL_Q && rx_active !=CLDMA_ALL_Q );
Too many parentheses.
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 777
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +4
-0+if (read_poll_timeout (queues_active, active, !active,CHECK_Q_STOP_STEP_US , +CHECK_Q_STOP_TIMEOUT_US , true, hw_info)) { +dev_err (md_ctrl->dev,"Could not stop CLDMA%d queues" , hif_id); +return -EAGAIN ;
Why shadowing error code?
Quoted 1 line
(quoted diff) +1
-0+ }
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 787
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +4
-0+static void cldma_late_release (struct cldma_ctrl *md_ctrl) +{ +int i; +if (md_ctrl->is_late_init) {
if (!...) return;
Quoted 2 lines
(quoted diff) +2
-0+ } +}
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 876
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +2
-0+/* wait write done */ +wmb ();
This requires also elaboration on where is the counterpart of this barrier.
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 892
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +7
-0+static void clear_txq (struct cldma_ctrl *md_ctrl,int qnum) +{ +struct cldma_request *req; +struct cldma_queue *txq; +struct cldma_tgpd *tgpd; +unsigned long flags; + txq = &md_ctrl->txq[qnum];
To the definition block.
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 897
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +5
-0+spin_lock_irqsave (&txq->ring_lock, flags); + req = list_first_entry(&txq->tr_ring->gpd_ring, struct cldma_request, entry); + txq->tr_done = req; + txq->tx_xmit = req; + txq->budget = txq->tr_ring->length;
I'm wondering what the magic is behind these lines...
Quoted 13 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +13
-0+list_for_each_entry (req, &txq->tr_ring->gpd_ring, entry) { + tgpd = req->gpd; + tgpd->gpd_flags &= ~GPD_FLAGS_HWO ; +cldma_tgpd_set_data_ptr (tgpd,0 ); + tgpd->data_buff_len =0 ; +if (req->skb) { +ccci_free_skb (&md_ctrl->mtk_dev->pools, req->skb); + req->skb =NULL ; + } + } + +spin_unlock_irqrestore (&txq->ring_lock, flags); +}
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 1032
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +2
-0+ tx_req->mapped_buff =dma_map_single (md_ctrl->dev, skb->data, + skb->len,DMA_TO_DEVICE );
In one case you have a long line, in many others you have doing this. A bit of consistency is required. If you use 100, use it everywhere, or otherwise go for 80 everywhere (with possible exceptions as written in the documentation).
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 1094
Quoted 1 line
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +1
-0+if (queue->budget > (MAX_TX_BUDGET -1 ))
if (queue->budget >= MAX_TX_BUDGET)
Quoted 1 line
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +1
-0+return queue->budget;
...
Quoted 2 lines
+ * Return: 0 on success,
-ENOMEMon allocation failure,-EINVALon invalid queue request, or
+ *-EBUSYon resource lock failure.
* Return: 0 on success,
-ENOMEM on allocation failure,
-EINVAL on invalid queue request, or
-EBUSY on resource lock failure.
?
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 1172
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +8
-0+ do { + spin_lock_irqsave(&queue->ring_lock, flags); + tx_req = queue->tx_xmit; + if (queue->budget > 0 && !tx_req->skb) { + queue->budget--; + queue->tr_ring->handle_tx_request(queue, tx_req, skb, ioc_override); + queue->tx_xmit = cldma_ring_step_forward(queue->tr_ring, tx_req); + spin_unlock_irqrestore(&queue->ring_lock, flags);
Since these are two different locks, how you guarantee that below will be run correctly? (Perhaps some explanation is needed)
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +5
-0+spin_lock_irqsave (&md_ctrl->cldma_lock, flags); +cldma_hw_start_send (md_ctrl, qno); +spin_unlock_irqrestore (&md_ctrl->cldma_lock, flags); +break ; + }
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 1197
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +3
-0+ ret =wait_event_interruptible_exclusive (queue->req_wq, queue->budget >0 ); +if (ret == -ERESTARTSYS ) + ret = -EINTR ;
Why overriding?
...
Quoted 1 line
+exit:
Seems useless.
Quoted 1 line
(quoted diff) +1
-0+ return ret;
...
Quoted 1 line
+/* this function contains longer duration initializations */
Useless.
You must really revisit all the comments over the driver and change them to explain why rather than what.
Above, of course, maybe converted to kernel doc that actually describes what the API is doing in more verbose way.
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 1238
Quoted 1 line
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +1
-0+snprintf (dma_pool_name,32 ,"cldma_request_dma_hif%d" , md_ctrl->hif_id);
sizeof()
...
sizeof(struct cldma_tgpd), 16, 0);
16 is magic.
...
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +5
-0+for (i =0 ; i <CLDMA_TXQ_NUM ; i++) +cldma_tx_queue_init (&md_ctrl->txq[i]); + +for (i =0 ; i <CLDMA_RXQ_NUM ; i++) +cldma_rx_queue_init (&md_ctrl->rxq[i]);
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 1286
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +9
-0+mutex_unlock (&ctl_cfg_mutex); + + md_ctrl->is_late_init = true; +return 0 ; + +err_rx_ring: +while (i--) +cldma_ring_free (md_ctrl, &md_ctrl->rx_ring[i],DMA_FROM_DEVICE ); + i =CLDMA_TXQ_NUM ;
I would rather provide i,j and drop this line for good.
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +3
-0+err_tx_ring: +while (i--) +cldma_ring_free (md_ctrl, &md_ctrl->tx_ring[i],DMA_TO_DEVICE );
...
Quoted 6 lines
+/**
+ *cldma_exception()- CLDMA exception handler
+ * @hif_id: CLDMA ID (ID_CLDMA0orID_CLDMA1)
+ * @stage: exception stage
+ *
+ * disable/flush/stop/start CLDMA/queues based on exception stage.
Please, elaborate state machine here with the (ASCII) chart of the (possible) state changes.
Quoted 1 line
+ *
Redundant.
Quoted 1 line
+ */
...
Quoted 6 lines
+/**
+ *cldma_init()- Initialize CLDMA
+ * @hif_id: CLDMA ID (ID_CLDMA0orID_CLDMA1)+ * initialize HIF TX/RX queue structure
+ * register CLDMA callback isr with PCIe driver
You need to revisit all descriptions in order to amend English grammar and punctuation. E.g. here you lost capitalization and period.
Quoted 2 lines
+ * Return: 0 on success, a negative error code on failure
+ */
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 1453
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +2
-0+ alloc_workqueue("md_hif%d_tx%d_worker", + WQ_UNBOUND | WQ_MEM_RECLAIM | (!i ? WQ_HIGHPRI : 0),
What is the idea behind redundant negation?
Quoted 1 line
(quoted diff) +1
-0+ 1, hif_id, i);
...
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.h new file +4
-0+#ifndef __T7XX_HIF_CLDMA_H__ +#define __T7XX_HIF_CLDMA_H__ + +#include <linux/pci.h>
drivers/net/wwan/t7xx/t7xx_hif_cldma.h line 28
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.h new file +10
-0+#include <linux/sched.h> +#include <linux/spinlock.h> +#include <linux/wait.h> +#include <linux/workqueue.h> +#include <linux/types.h> + +#include "t7xx_cldma.h" +#include "t7xx_common.h" +#include "t7xx_modem_ops.h" +#include "t7xx_pci.h"
All of these headers are needed and used here?
Really?!
But bits.h is missed...
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.h line 65
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.h new file +10
-0+/* cldma_ring is quite light, most of ring buffer operations require queue struct. */ +struct cldma_ring { +struct list_head gpd_ring;/* ring of struct cldma_request */ +int length;/* number of struct cldma_request */ +int pkt_size;/* size of each packet in ring */ + +int (*handle_tx_request)(struct cldma_queue *queue,struct cldma_request *req, +struct sk_buff *skb,unsigned int ioc_override); +int (*handle_rx_done)(struct cldma_queue *queue,int budget); +int (*handle_tx_done)(struct cldma_queue *queue);
Perhaps convert comments to proper kernel doc.
Quoted 1 line
+};
...
drivers/net/wwan/t7xx/t7xx_hif_cldma.h line 125
Quoted 11 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.h new file +11
-0+struct cldma_tgpd { +u8 gpd_flags; +u16 non_used; +u8 debug_id; +u32 next_gpd_ptr_h; +u32 next_gpd_ptr_l; +u32 data_buff_bd_ptr_h; +u32 data_buff_bd_ptr_l; +u16 data_buff_len; +u16 non_used1; +} __packed;
What useful does __packed here?
drivers/net/wwan/t7xx/t7xx_hif_cldma.h line 138
Quoted 12 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.h new file +12
-0+struct cldma_rgpd { +u8 gpd_flags; +u8 non_used; +u16 data_allow_len; +u32 next_gpd_ptr_h; +u32 next_gpd_ptr_l; +u32 data_buff_bd_ptr_h; +u32 data_buff_bd_ptr_l; +u16 data_buff_len; +u8 non_used1; +u8 debug_id; +} __packed;
Ditto.
(If it's about unaligned addresses, then you have to mention it somewhere)
Signature · 2 lines
With Best Regards, Andy Shevchenko
Martinez, Ricardo
reviewerRe: [PATCH v2 02/14] net: wwan: t7xx: Add control DMA interface
Quoted 26 lines · Andy Shevchenko
Quoted 25 lines · Ricardo Martinez
From: Haijun Lio <[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 14 lines
drivers/net/wwan/t7xx/t7xx_cldma.c line 86
Quoted 12 lines
drivers/net/wwan/t7xx/t7xx_cldma.c new file +11
-0+void cldma_hw_reset (void __iomem *ao_base) +{ +iowrite32 (ioread32 (ao_base +REG_INFRA_RST4_SET ) |RST4_CLDMA1_SW_RST_SET , + ao_base +REG_INFRA_RST4_SET ); +iowrite32 (ioread32 (ao_base +REG_INFRA_RST2_SET ) |RST2_CLDMA1_AO_SW_RST_SET , + ao_base +REG_INFRA_RST2_SET ); +udelay (1 ); +iowrite32 (ioread32 (ao_base +REG_INFRA_RST4_CLR ) |RST4_CLDMA1_SW_RST_CLR , + ao_base +REG_INFRA_RST4_CLR ); +iowrite32 (ioread32 (ao_base +REG_INFRA_RST2_CLR ) |RST2_CLDMA1_AO_SW_RST_CLR , + ao_base +REG_INFRA_RST2_CLR );Setting and clearing are in the same order, is it okay? Can we do it rather symmetrical?
In this case, order does not matter.
This will be symmetrical in the next iteration.
Quoted 5 lines
Quoted 1 line
+}
...
Review
Quoted 1 line
(quoted diff) +1
-0+ mb(); /* prevents outstanding GPD updates */Is there any counterpart of this barrier?
This is not needed, removing it.
...
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 263
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +6
-0+ ret =cldma_gpd_rx_from_queue (queue, budget, &over_budget); +if (ret == -ENODATA ) +return 0 ; + +if (ret) +return ret;Drop redundant blank line
The style followed is to keep a blank line after 'if' blocks.
Is that acceptable as long as it is consistent across the driver?
Quoted 3 lines
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +2
-0+/* greedy mode */ + l2_rx_int =cldma_hw_int_status (hw_info,BIT (queue->index), true);
...
Quoted 3 lines
Quoted 2 lines
+exit:
Seems useless.
This tag is used when the PM patch is introduced later in the same series.
Quoted 1 line
(quoted diff) +1
-0+ return ret;
...
Re: [PATCH v2 02/14] net: wwan: t7xx: Add control DMA interface
Quoted 2 lines · Ricardo
Quoted 1 line · Andy Shevchenko
On Sun, Oct 31, 2021 at 08:56:23PM -0700, Ricardo Martinez wrote:
...
Quoted 11 lines
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 263
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c new file +6
-0+ ret =cldma_gpd_rx_from_queue (queue, budget, &over_budget); +if (ret == -ENODATA ) +return 0 ; + +if (ret) +return ret;Drop redundant blank line
The style followed is to keep a blank line after 'if' blocks.
Is that acceptable as long as it is consistent across the driver?
The idea behind suggestion is that you check for value returned from the call. So, both if:s are tighten to that call and can be considered as a whole.
It doesn't mean you should blindly remove blank lines everywhere.
...
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
+exit:
Seems useless.
This tag is used when the PM patch is introduced later in the same series.
Can you give it better name?
Quoted 1 line
Quoted 1 line
(quoted diff) +1
-0+ return ret;
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sergey Ryazanov
maintainerRe: [PATCH v2 02/14] net: wwan: t7xx: Add control DMA interface
In reply to Ricardo MartinezQuoted 23 lines · Ricardo Martinez
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
[skipped]
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 42
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c +1
-0+static struct cldma_ctrl *cldma_md_ctrl[CLDMA_NUM ];
Place this pointers array to a private _device_ state structure. Otherwise, with these global pointers, the driver will break as soon as a second modem is connected to the host.
Also all corresponding functions should be reworked to be able to accept a modem state container pointer.
Quoted 1 line
+static
DEFINE_MUTEX(ctl_cfg_mutex); /* protects CLDMA late init config */
Place this mutex to a private device state structure as well to avoid useless inter-device locking and possible deadlocks.
drivers/net/wwan/t7xx/t7xx_hif_cldma.c line 50
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_hif_cldma.c +5
-0+static enum cldma_queue_type rxq_type[CLDMA_RXQ_NUM ]; +static enum cldma_queue_type txq_type[CLDMA_TXQ_NUM ]; +static int rxq_buff_size[CLDMA_RXQ_NUM ]; +static int rxq_buff_num[CLDMA_RXQ_NUM ]; +static int txq_buff_num[CLDMA_TXQ_NUM ];
If these arrays could be shared between modem instances (i.e. if this is a some kind of static configuration) then initialize them statically or in the module_init(). Otherwise, if these arrays are part of the runtime state, then place them in a device state container.
--
Sergey
Ricardo Martinez
reviewerPATCH v2 3/14 net: wwan: t7xx: Add core components
In reply to Ricardo MartinezFrom: Haijun Lio <[email protected]>
Registers the t7xx device driver with the kernel. Setup all the core
components: PCIe layer, Modem Host Cross Core Interface (MHCCIF), modem control operations, modem state machine, and build infrastructure.
* PCIe layer code implements driver probe and removal.
* MHCCIF provides interrupt channels to communicate events such as handshake, PM and port enumeration.
* Modem control implements the entry point for modem init, reset and exit.
* The modem status monitor is a state machine used by modem control to complete initialization and stop. It is used also to propagate exception events reported by other components.
--- drivers/net/wwan/Kconfig | 14 + drivers/net/wwan/Makefile | 1 + drivers/net/wwan/t7xx/Makefile | 13 + drivers/net/wwan/t7xx/t7xx_common.h | 76 +++ drivers/net/wwan/t7xx/t7xx_mhccif.c | 105 ++++ drivers/net/wwan/t7xx/t7xx_mhccif.h | 35 ++ drivers/net/wwan/t7xx/t7xx_modem_ops.c | 486 +++++++++++++++++ drivers/net/wwan/t7xx/t7xx_modem_ops.h | 90 ++++ drivers/net/wwan/t7xx/t7xx_monitor.h | 144 +++++ drivers/net/wwan/t7xx/t7xx_pci.c | 238 ++++++++ drivers/net/wwan/t7xx/t7xx_pci.h | 66 +++ drivers/net/wwan/t7xx/t7xx_pcie_mac.c | 277 ++++++++++ drivers/net/wwan/t7xx/t7xx_pcie_mac.h | 36 ++ drivers/net/wwan/t7xx/t7xx_reg.h | 398 ++++++++++++++ drivers/net/wwan/t7xx/t7xx_skb_util.c | 362 +++++++++++++ drivers/net/wwan/t7xx/t7xx_skb_util.h | 110 ++++ drivers/net/wwan/t7xx/t7xx_state_monitor.c | 598 +++++++++++++++++++++ 17 files changed, 3049 insertions(+) create mode 100644 drivers/net/wwan/t7xx/Makefile create mode 100644 drivers/net/wwan/t7xx/t7xx_common.h create mode 100644 drivers/net/wwan/t7xx/t7xx_mhccif.c create mode 100644 drivers/net/wwan/t7xx/t7xx_mhccif.h create mode 100644 drivers/net/wwan/t7xx/t7xx_modem_ops.c create mode 100644 drivers/net/wwan/t7xx/t7xx_modem_ops.h create mode 100644 drivers/net/wwan/t7xx/t7xx_monitor.h create mode 100644 drivers/net/wwan/t7xx/t7xx_pci.c create mode 100644 drivers/net/wwan/t7xx/t7xx_pci.h create mode 100644 drivers/net/wwan/t7xx/t7xx_pcie_mac.c create mode 100644 drivers/net/wwan/t7xx/t7xx_pcie_mac.h create mode 100644 drivers/net/wwan/t7xx/t7xx_reg.h create mode 100644 drivers/net/wwan/t7xx/t7xx_skb_util.c create mode 100644 drivers/net/wwan/t7xx/t7xx_skb_util.h create mode 100644 drivers/net/wwan/t7xx/t7xx_state_monitor.c
drivers/net/wwan/Kconfig +14 -0
@@ -80,6 +80,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 (T700 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
@@ -12,3 +12,4 @@ obj-$(CONFIG_MHI_WWAN_CTRL) += mhi_wwan_ctrl.o obj-$(CONFIG_MHI_WWAN_MBIM) += mhi_wwan_mbim.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 +13 -0
@@ -0,0 +1,13 @@ +# 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_skb_util.o \ + t7xx_cldma.o \ + t7xx_hif_cldma.o \
drivers/net/wwan/t7xx/t7xx_common.h new file +76 -0
76 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_mhccif.c new file +105 -0
105 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_mhccif.h new file +35 -0
@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only +* +* Copyright (c) 2021, MediaTek Inc. +* Copyright (c) 2021, Intel Corporation. +* +* Authors: Haijun Lio <[email protected]> +* Contributors: Amir Hanania <[email protected]> +* Moises Veleta <[email protected]> +* Ricardo Martinez<[email protected]> +* Sreehari Kancharla <[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 mhccif_mask_set (struct mtk_pci_dev *mtk_dev,u32 val); +void mhccif_mask_clr (struct mtk_pci_dev *mtk_dev,u32 val); +u32 mhccif_mask_get (struct mtk_pci_dev *mtk_dev); +void mhccif_init (struct mtk_pci_dev *mtk_dev); +u32 mhccif_read_sw_int_sts (struct mtk_pci_dev *mtk_dev); +void mhccif_h2d_swint_trigger (struct mtk_pci_dev *mtk_dev,u32 channel); + +#endif /*__T7XX_MHCCIF_H__ */
drivers/net/wwan/t7xx/t7xx_modem_ops.c new file +486 -0
486 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_modem_ops.h new file +90 -0
90 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_monitor.h new file +144 -0
144 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_pci.c new file +238 -0
238 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_pci.h new file +66 -0
66 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_pcie_mac.c new file +277 -0
277 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_pcie_mac.h new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-only +* +* Copyright (c) 2021, MediaTek Inc. +* Copyright (c) 2021, Intel Corporation. +* +* Authors: Haijun Lio <[email protected]> +* Contributors: Amir Hanania <[email protected]> +* Chiranjeevi Rapolu <[email protected]> +* Moises Veleta <[email protected]> +* Ricardo Martinez<[email protected]> +* Sreehari Kancharla <[email protected]> +*/ + +#ifndef __T7XX_PCIE_MAC_H__ +#define __T7XX_PCIE_MAC_H__ + +#include <linux/bitops.h> +#include <linux/io.h> + +#include "t7xx_pci.h" +#include "t7xx_reg.h" + +#define IREG_BASE (mtk_dev) ((mtk_dev)->base_addr.pcie_mac_ireg_base) + +#define PCIE_MAC_MSIX_MSK_SET (mtk_dev, ext_id) \ + iowrite32(BIT(ext_id), IREG_BASE(mtk_dev) + IMASK_HOST_MSIX_SET_GRP0_0) + +void mtk_pcie_mac_interrupts_en (struct mtk_pci_dev *mtk_dev); +void mtk_pcie_mac_interrupts_dis (struct mtk_pci_dev *mtk_dev); +void mtk_pcie_mac_atr_init (struct mtk_pci_dev *mtk_dev); +void mtk_pcie_mac_clear_int (struct mtk_pci_dev *mtk_dev,enum pcie_int int_type); +void mtk_pcie_mac_set_int (struct mtk_pci_dev *mtk_dev,enum pcie_int int_type); +void mtk_pcie_mac_clear_int_status (struct mtk_pci_dev *mtk_dev,enum pcie_int int_type); +void mtk_pcie_mac_msix_cfg (struct mtk_pci_dev *mtk_dev,unsigned int irq_count); + +#endif /* __T7XX_PCIE_MAC_H__ */
drivers/net/wwan/t7xx/t7xx_reg.h new file +398 -0
398 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_skb_util.c new file +362 -0
362 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_skb_util.h new file +110 -0
110 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +598 -0
540 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
Re: [PATCH v2 03/14] net: wwan: t7xx: Add core components
Quoted 7 lines · Ricardo Martinez
From: Haijun Lio <[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.
Quoted 8 lines
* 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.
I will assume that the comments given against previous patch will be applied to this and the rest of the patches where it makes sense or appropriate.
Below only new comments.
...
drivers/net/wwan/Kconfig config IOSM · line 84
Quoted 2 lines
drivers/net/wwan/Kconfig +2
-0+config MTK_T7XX + tristate "MediaTek PCIe 5G WWAN modem T7XX device"
T77xx is easier to read by human beings.
Quoted 1 line
drivers/net/wwan/Kconfig +1
-0+ depends on PCI
...
drivers/net/wwan/t7xx/t7xx_common.h line 21
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_common.h new file +2
-0+struct ccci_header { +/* do not assume data[1] is data length in rx */
To understand this comment you need to elaborate the content of the header.
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_common.h new file +4
-0+u32 data[2 ]; +u32 status; +u32 reserved; +};
...
Quoted 1 line
+#define
CCCI_HEADER_NO_DATA0xffffffff
Is this internal value to Linux or something which is given by hardware?
...
drivers/net/wwan/t7xx/t7xx_common.h line 62
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_common.h new file +4
-0+/* Modem exception check identification number */ +#define MD_EX_CHK_ID 0x45584350 +/* Modem exception check acknowledge identification number */ +#define MD_EX_CHK_ACK_ID 0x45524543
To me both looks like fourcc. Can you add their ASCII values into comments?
...
drivers/net/wwan/t7xx/t7xx_mhccif.c line 44
Quoted 1 line
drivers/net/wwan/t7xx/t7xx_mhccif.c new file +1
-0+/* Use 1*4 bits to avoid low power bits*/
What does "1*4 bits" mean?
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_mhccif.c new file +2
-0+iowrite32 (L1_1_DISABLE_BIT (1 ) |L1_2_DISABLE_BIT (1 ), +IREG_BASE (mtk_dev) +DIS_ASPM_LOWPWR_SET_0 );
...
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c new file +5
-0+int mtk_pci_mhccif_isr (struct mtk_pci_dev *mtk_dev) +{ +struct md_sys_info *md_info; +struct ccci_fsm_ctl *ctl; +struct mtk_modem *md;
drivers/net/wwan/t7xx/t7xx_modem_ops.c line 62
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c new file +9
-0+unsigned int int_sta; +unsigned long flags; +u32 mask; + + md = mtk_dev->md; + ctl =fsm_get_entry (); +if (!ctl) { +dev_err (&mtk_dev->pdev->dev, +"process MHCCIF interrupt before modem monitor was initialized\n" );
Can this potentially flood the logs? If so, needs to be rate limited.
drivers/net/wwan/t7xx/t7xx_modem_ops.c line 67
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c new file +4
-0+return -EINVAL ; + } + md_info = md->md_info; +spin_lock_irqsave (&md_info->exp_spinlock, flags);
Can it be called outside of IRQ context?
Quoted 32 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c new file +32
-0+ int_sta =get_interrupt_status (mtk_dev); + md_info->exp_id |= int_sta; + +if (md_info->exp_id &D2H_INT_PORT_ENUM ) { + md_info->exp_id &= ~D2H_INT_PORT_ENUM ; +if (ctl->curr_state ==CCCI_FSM_INIT || + ctl->curr_state ==CCCI_FSM_PRE_START || + ctl->curr_state ==CCCI_FSM_STOPPED ) +ccci_fsm_recv_md_interrupt (MD_IRQ_PORT_ENUM ); + } + +if (md_info->exp_id &D2H_INT_EXCEPTION_INIT ) { +if (ctl->md_state ==MD_STATE_INVALID || + ctl->md_state ==MD_STATE_WAITING_FOR_HS1 || + ctl->md_state ==MD_STATE_WAITING_FOR_HS2 || + ctl->md_state ==MD_STATE_READY ) { + md_info->exp_id &= ~D2H_INT_EXCEPTION_INIT ; +ccci_fsm_recv_md_interrupt (MD_IRQ_CCIF_EX ); + } + }else if (ctl->md_state ==MD_STATE_WAITING_FOR_HS1 ) { +/* start handshake if MD not assert */ + mask =mhccif_mask_get (mtk_dev); +if ((md_info->exp_id &D2H_INT_ASYNC_MD_HK ) && !(mask &D2H_INT_ASYNC_MD_HK )) { + md_info->exp_id &= ~D2H_INT_ASYNC_MD_HK ; +queue_work (md->handshake_wq, &md->handshake_work); + } + } + +spin_unlock_irqrestore (&md_info->exp_spinlock, flags); + +return 0 ; +}
...
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c new file +4
-0+static int mtk_acpi_reset (struct mtk_pci_dev *mtk_dev,char *fn_name) +{ +#ifdef CONFIG_ACPI +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL };
drivers/net/wwan/t7xx/t7xx_modem_ops.c line 135
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c new file +9
-0+acpi_status acpi_ret; +struct device *dev; +acpi_handle handle; + + dev = &mtk_dev->pdev->dev; +if (acpi_disabled) { +dev_err (dev,"acpi function isn't enabled\n" ); +return -EFAULT ; + }
Why this check?
drivers/net/wwan/t7xx/t7xx_modem_ops.c line 139
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c new file +3
-0+ handle =ACPI_HANDLE (dev); +if (!handle) { +dev_err (dev,"acpi handle isn't found\n" );
acpi --> ACPI
Quoted 16 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c new file +16
-0+ return -EFAULT; + } + +if (!acpi_has_method (handle, fn_name)) { +dev_err (dev,"%s method isn't found\n" , fn_name); +return -EFAULT ; + } + + acpi_ret =acpi_evaluate_object (handle, fn_name,NULL , &buffer); +if (ACPI_FAILURE (acpi_ret)) { +dev_err (dev,"%s method fail: %s\n" , fn_name,acpi_format_exception (acpi_ret)); +return -EFAULT ; + } +#endif +return 0 ; +}
...
drivers/net/wwan/t7xx/t7xx_modem_ops.c line 182
Quoted 1 line
drivers/net/wwan/t7xx/t7xx_modem_ops.c new file +1
-0+msleep (RGU_RESET_DELAY_US );
DELAY in microseconds while msleep() takes milliseconds. Something is wrong here.
Also, delays such as 10ms+ should be explained. Esp. when they are in the threaded IRQ handler.
...
drivers/net/wwan/t7xx/t7xx_modem_ops.c line 352
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c new file +3
-0+void mtk_md_exception_handshake (struct mtk_modem *md) +{ +struct mtk_pci_dev *mtk_dev;
struct device *dev = &mtk_dev->pdev->dev;
will help a lot to make below code cleaner.
Quoted 24 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c new file +23
-0+int ret; + mtk_dev = md->mtk_dev; +md_exception (md,HIF_EX_INIT ); + ret =wait_hif_ex_hk_event (md,D2H_INT_EXCEPTION_INIT_DONE ); + +if (ret) +dev_err (&mtk_dev->pdev->dev,"EX CCIF HS timeout, RCH 0x%lx\n" , +D2H_INT_EXCEPTION_INIT_DONE ); + +md_exception (md,HIF_EX_INIT_DONE ); + ret =wait_hif_ex_hk_event (md,D2H_INT_EXCEPTION_CLEARQ_DONE ); +if (ret) +dev_err (&mtk_dev->pdev->dev,"EX CCIF HS timeout, RCH 0x%lx\n" , +D2H_INT_EXCEPTION_CLEARQ_DONE ); + +md_exception (md,HIF_EX_CLEARQ_DONE ); + ret =wait_hif_ex_hk_event (md,D2H_INT_EXCEPTION_ALLQ_RESET ); +if (ret) +dev_err (&mtk_dev->pdev->dev,"EX CCIF HS timeout, RCH 0x%lx\n" , +D2H_INT_EXCEPTION_ALLQ_RESET ); + +md_exception (md,HIF_EX_ALLQ_RESET ); +}
...
drivers/net/wwan/t7xx/t7xx_modem_ops.c line 464
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c new file +4
-0+err_fsm_init: +ccci_fsm_uninit (); +err_alloc: +destroy_workqueue (md->handshake_wq);
Labels should explain what will be done when goto, and not what was done.
...
drivers/net/wwan/t7xx/t7xx_modem_ops.h line 28
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.h new file +2
-0+/* Modem feature query identification number */ +#define MD_FEATURE_QUERY_ID 0x49434343
All fourcc:s should be represented as ASCII in the comments.
...
drivers/net/wwan/t7xx/t7xx_monitor.h line 17
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_monitor.h new file +3
-0+#ifndef __T7XX_MONITOR_H__ +#define __T7XX_MONITOR_H__ +#include <linux/sched.h>
Who is the user of this?
...
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_pci.c new file +7
-0+static int mtk_request_irq (struct pci_dev *pdev) +{ +struct mtk_pci_dev *mtk_dev; +int ret, i; + + mtk_dev =pci_get_drvdata (pdev); +
drivers/net/wwan/t7xx/t7xx_pci.c line 47
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_pci.c new file +10
-0+for (i =0 ; i <EXT_INT_NUM ; i++) { +const char *irq_descr; +int irq_vec; + +if (!mtk_dev->intr_handler[i]) +continue ; + + irq_descr =devm_kasprintf (&pdev->dev,GFP_KERNEL ,"%s_%d" , +dev_driver_string (&pdev->dev), i); +if (!irq_descr)
Resource leak is here.
Quoted 22 lines
drivers/net/wwan/t7xx/t7xx_pci.c new file +22
-0+return -ENOMEM ; + + irq_vec =pci_irq_vector (pdev, i); + ret =request_threaded_irq (irq_vec, mtk_dev->intr_handler[i], + mtk_dev->intr_thread[i],0 , irq_descr, + mtk_dev->callback_param[i]); +if (ret) { +dev_err (&pdev->dev,"Failed to request_irq: %d, int: %d, ret: %d\n" , + irq_vec, i, ret); +while (i--) { +if (!mtk_dev->intr_handler[i]) +continue ; + +free_irq (pci_irq_vector (pdev, i), mtk_dev->callback_param[i]); + } + +return ret; + } + } + +return 0 ; +}
...
drivers/net/wwan/t7xx/t7xx_pci.c line 80
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_pci.c new file +3
-0+ ret =pci_alloc_irq_vectors (mtk_dev->pdev,EXT_INT_NUM ,EXT_INT_NUM ,PCI_IRQ_MSIX ); +if (ret <0 ) { +dev_err (&mtk_dev->pdev->dev,"Failed to allocate MSI-X entry, errno: %d\n" , ret);
', errno' is redundant.
Quoted 13 lines
drivers/net/wwan/t7xx/t7xx_pci.c new file +13
-0+return ret; + } + + ret =mtk_request_irq (mtk_dev->pdev); +if (ret) { +pci_free_irq_vectors (mtk_dev->pdev); +return ret; + } + +/* Set MSIX merge config */ +mtk_pcie_mac_msix_cfg (mtk_dev,EXT_INT_NUM ); +return 0 ; +}
...
drivers/net/wwan/t7xx/t7xx_pci.c line 142
Quoted 1 line
drivers/net/wwan/t7xx/t7xx_pci.c new file +1
-0+ ret =pci_set_dma_mask (pdev,DMA_BIT_MASK (64 ));
This API is absoleted, use corresponding DMA API directly. On top of that, 64-bit setting never fail...
drivers/net/wwan/t7xx/t7xx_pci.c line 148
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_pci.c new file +6
-0+if (ret) { + ret =pci_set_dma_mask (pdev,DMA_BIT_MASK (32 )); +if (ret) { +dev_err (&pdev->dev,"Could not set PCI DMA mask, err: %d\n" , ret); +return ret; + }
...so this attempt is almost a dead code.
Quoted 1 line
(quoted diff) +1
-0+ }
...
drivers/net/wwan/t7xx/t7xx_pci.c line 159
Quoted 9 lines
drivers/net/wwan/t7xx/t7xx_pci.c new file +9
-0+ ret =pci_set_consistent_dma_mask (pdev,DMA_BIT_MASK (64 )); +if (ret) { + ret =pci_set_consistent_dma_mask (pdev,DMA_BIT_MASK (32 )); +if (ret) { +dev_err (&pdev->dev,"Could not set consistent PCI DMA mask, err: %d\n" , + ret); +return ret; + } + }
Ditto.
...
drivers/net/wwan/t7xx/t7xx_pci.c line 183
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_pci.c new file +3
-0+mtk_pcie_mac_set_int (mtk_dev,MHCCIF_INT ); +mtk_pcie_mac_interrupts_en (mtk_dev); +pci_set_master (pdev);
It's too late for this call. Are you sure it's needed here? Why?
Quoted 2 lines
(quoted diff) +2
-0+ + return 0;
...
Quoted 1 line
+err:
Meaningless label name. Try your best to make it better.
Review
Quoted 1 line
(quoted diff) +1
-0+ ccci_skb_pool_free(&mtk_dev->pools);
Does it free IRQ handlers? If so, the function naming is not good enough.
Quoted 1 line
(quoted diff) +1
-0+ return ret;
...
drivers/net/wwan/t7xx/t7xx_pci.c line 234
Quoted 11 lines
drivers/net/wwan/t7xx/t7xx_pci.c new file +11
-0+static int __init mtk_pci_init (void ) +{ +return pci_register_driver (&mtk_pci_driver); +} +module_init (mtk_pci_init); + +static void __exit mtk_pci_cleanup(void) +{ +pci_unregister_driver (&mtk_pci_driver); +} +module_exit (mtk_pci_cleanup);
NIH module_pci_driver().
...
Quoted 1 line
+ * @pdev: pci device
pci --> PCI
...
drivers/net/wwan/t7xx/t7xx_pcie_mac.c line 15
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_pcie_mac.c new file +2
-0+#include <linux/io-64-nonatomic-lo-hi.h> +#include <linux/msi.h>
Wondering what the APIs you are using from there.
...
drivers/net/wwan/t7xx/t7xx_pcie_mac.c line 68
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_pcie_mac.c new file +2
-0+for (i =0 ; i <ATR_TABLE_NUM_PER_ATR ; i++) { + offset = (ATR_PORT_OFFSET * port) + (ATR_TABLE_OFFSET * i);
Too many parentheses.
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_pcie_mac.c new file +4
-0+/* Disable table by SRC_ADDR */ + reg = pbase +ATR_PCIE_WIN0_T0_ATR_PARAM_SRC_ADDR + offset; +iowrite64 (0 , reg); + }
...
drivers/net/wwan/t7xx/t7xx_pcie_mac.c line 104
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_pcie_mac.c new file +3
-0+ pos =ffs (lower_32_bits (cfg->size)); +if (!pos) + pos =ffs (upper_32_bits (cfg->size)) +32 ;
NIH __ffs64() ?
...
drivers/net/wwan/t7xx/t7xx_pcie_mac.c line 188
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_pcie_mac.c new file +5
-0+static void mtk_pcie_mac_enable_disable_int (struct mtk_pci_dev *mtk_dev,bool enable) +{ +u32 value; + + value =ioread32 (IREG_BASE (mtk_dev) +ISTAT_HST_CTRL );
Either add...
drivers/net/wwan/t7xx/t7xx_pcie_mac.c line 193
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_pcie_mac.c new file +5
-0+if (enable) + value &= ~ISTAT_HST_CTRL_DIS ; +else + value |=ISTAT_HST_CTRL_DIS ; +
...or remove blank line for the sake of consistency.
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_pcie_mac.c new file +2
-0+iowrite32 (value,IREG_BASE (mtk_dev) +ISTAT_HST_CTRL ); +}
...
Quoted 1 line
+#include <
linux/bitops.h>
Who is the user of this?
...
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_reg.h new file +4
-0+#ifndef __T7XX_REG_H__ +#define __T7XX_REG_H__ + +#include <linux/bits.h>
...
drivers/net/wwan/t7xx/t7xx_reg.h line 78
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_reg.h new file +3
-0+#define EXP_BAR0 0x0c +#define EXP_BAR2 0x04 +#define EXP_BAR4 0x0c
BAR0 and BAR4 have the same value. Either explain or fix accordingly.
...
Quoted 1 line
+#define
MSIX_MSK_SET_ALLGENMASK(31, 24)
Missed blank line ?
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_reg.h new file +10
-0+enum pcie_int { +DPMAIF_INT =0 , +CLDMA0_INT , +CLDMA1_INT , +CLDMA2_INT , +MHCCIF_INT , +DPMAIF2_INT , +SAP_RGU_INT , +CLDMA3_INT , +};
...
drivers/net/wwan/t7xx/t7xx_skb_util.c line 42
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_skb_util.c new file +8
-0+static struct sk_buff *alloc_skb_from_pool (struct skb_pools *pools,size_t size) +{ +if (size >MTK_SKB_4K ) +return ccci_skb_dequeue (pools->reload_work_queue, &pools->skb_pool_64k); +else if (size >MTK_SKB_16 ) +return ccci_skb_dequeue (pools->reload_work_queue, &pools->skb_pool_4k); +else if (size >0 ) +return ccci_skb_dequeue (pools->reload_work_queue, &pools->skb_pool_16);
Redundant 'else'. Recommend to read again our internal Wiki about typical issues with the code.
Quoted 2 lines
(quoted diff) +2
-0+ return NULL; +}
...
drivers/net/wwan/t7xx/t7xx_skb_util.c line 56
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_skb_util.c new file +10
-0+static struct sk_buff *alloc_skb_from_kernel (size_t size,gfp_t gfp_mask) +{ +if (size >MTK_SKB_4K ) +return __dev_alloc_skb (MTK_SKB_64K , gfp_mask); +else if (size >MTK_SKB_1_5K ) +return __dev_alloc_skb (MTK_SKB_4K , gfp_mask); +else if (size >MTK_SKB_16 ) +return __dev_alloc_skb (MTK_SKB_1_5K , gfp_mask); +else if (size >0 ) +return __dev_alloc_skb (MTK_SKB_16 , gfp_mask);
Ditto.
Quoted 2 lines
(quoted diff) +2
-0+ return NULL; +}
...
drivers/net/wwan/t7xx/t7xx_skb_util.c line 109
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_skb_util.c new file +5
-0+for (i =0 ; i < queue->max_len; i++) { +struct sk_buff *skb; + + skb =alloc_skb_from_kernel (skb_size,GFP_KERNEL ); +
Redundant.
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_skb_util.c new file +8
-0+if (!skb) { +while ((skb =skb_dequeue (&queue->skb_list))) +dev_kfree_skb_any (skb); +return -ENOMEM ; + } + +skb_queue_tail (&queue->skb_list, skb); + }
...
Quoted 5 lines
+/**
+ *ccci_alloc_skb_from_pool()- allocate memory for skb from pre-allocated pools
+ * @pools: skb pools
+ * @size: allocation size
+ * @blocking : true for blocking operation
Extra white space.
Again, revisit _all_ comments in your series and make them consistent in _all_ possible aspects (style, grammar, ...).
Quoted 3 lines
+ *
+ * Returns pointer to skb on success, NULL on failure.
+ */
...
drivers/net/wwan/t7xx/t7xx_skb_util.c line 185
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_skb_util.c new file +2
-0+if (blocking) { +might_sleep ();
might_sleep_if() at the top of the function?
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_skb_util.c new file +8
-0+ skb =alloc_skb_from_kernel (size,GFP_KERNEL ); + }else { +for (count =0 ; count <ALLOC_SKB_RETRY ; count++) { + skb =alloc_skb_from_kernel (size,GFP_ATOMIC ); +if (skb) +return skb; + } + }
...
drivers/net/wwan/t7xx/t7xx_skb_util.c line 261
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_skb_util.c new file +5
-0+while (queue->skb_list.qlen <SKB_64K_POOL_SIZE ) { + skb =alloc_skb_from_kernel (MTK_SKB_64K ,GFP_KERNEL ); +if (skb) +skb_queue_tail (&queue->skb_list, skb); + }
May it become an infinite loop?
...
drivers/net/wwan/t7xx/t7xx_skb_util.c line 275
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_skb_util.c new file +5
-0+while (queue->skb_list.qlen <SKB_4K_POOL_SIZE ) { + skb =alloc_skb_from_kernel (MTK_SKB_4K ,GFP_KERNEL ); +if (skb) +skb_queue_tail (&queue->skb_list, skb); + }
Ditto.
...
drivers/net/wwan/t7xx/t7xx_skb_util.c line 289
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_skb_util.c new file +5
-0+while (queue->skb_list.qlen <SKB_16_POOL_SIZE ) { + skb =alloc_skb_from_kernel (MTK_SKB_16 ,GFP_KERNEL ); +if (skb) +skb_queue_tail (&queue->skb_list, skb); + }
Ditto.
...
drivers/net/wwan/t7xx/t7xx_skb_util.c line 314
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_skb_util.c new file +3
-0+ pools->reload_work_queue =alloc_workqueue ("pool_reload_work" , +WQ_UNBOUND |WQ_MEM_RECLAIM |WQ_HIGHPRI , +1 );
... wqflags = WQ_UNBOUND | WQ_MEM_RECLAIM | WQ_HIGHPRI;
pools->reload_work_queue = alloc_workqueue("pool_reload_work", wqflags, 1);Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_skb_util.c new file +4
-0+if (!pools->reload_work_queue) { + ret = -ENOMEM ; + goto err_wq; + }
...
drivers/net/wwan/t7xx/t7xx_state_monitor.c line 53
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +2
-0+list_for_each_entry_safe (notifier_cur, notifier_next, + &ctl->notifier_list, entry) {
Out of a sudden this is two lines...
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +3
-0+if (notifier_cur == notifier) +list_del (¬ifier->entry); + }
...
drivers/net/wwan/t7xx/t7xx_state_monitor.c line 179
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +3
-0+if (!list_empty (&ctl->event_queue)) { + event =list_first_entry (&ctl->event_queue, + struct ccci_fsm_event, entry);
event = list_first_entry_or_null();
if (event) {Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +7
-0+if (event->event_id ==CCCI_EVENT_MD_EX ) { +fsm_finish_event (ctl, event); + }else if (event->event_id ==CCCI_EVENT_MD_EX_REC_OK ) { + rec_ok = true; +fsm_finish_event (ctl, event); + } + }
...
drivers/net/wwan/t7xx/t7xx_state_monitor.c line 207
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +6
-0+if (!list_empty (&ctl->event_queue)) { + event =list_first_entry (&ctl->event_queue, + struct ccci_fsm_event, entry); +if (event->event_id ==CCCI_EVENT_MD_EX_PASS ) +fsm_finish_event (ctl, event); + }
Ditto
...
drivers/net/wwan/t7xx/t7xx_state_monitor.c line 264
Quoted 1 line
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +1
-0+if (!atomic_read (&ctl->md->rgu_irq_asserted)) {
It may be set exactly here, what's the point in atomicity of the above check?
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +8
-0+/* disable DRM before FLDR */ +mhccif_h2d_swint_trigger (mtk_dev,H2D_CH_DRM_DISABLE_AP ); +msleep (FSM_DRM_DISABLE_DELAY_MS ); +/* try FLDR first */ + err =mtk_acpi_fldr_func (mtk_dev); +if (err) +mhccif_h2d_swint_trigger (mtk_dev,H2D_CH_DEVICE_RESET ); + }
...
drivers/net/wwan/t7xx/t7xx_state_monitor.c line 306
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +3
-0+wait_event_interruptible_timeout (ctl->async_hk_wq, +atomic_read (&md->core_md.ready) || +atomic_read (&ctl->exp_flg),HZ *60 );
Are you sure you understand what you are doing with the atomics?
Quoted 9 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +9
-0+if (atomic_read (&ctl->exp_flg)) +dev_err (dev,"MD exception is captured during handshake\n" ); + +if (!atomic_read (&md->core_md.ready)) { +dev_err (dev,"MD handshake timeout\n" ); +fsm_routine_exception (ctl,NULL ,EXCEPTION_HS_TIMEOUT ); + }else { +fsm_routine_ready (ctl); + }
...
drivers/net/wwan/t7xx/t7xx_state_monitor.c line 343
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +2
-0+read_poll_timeout (ioread32, dev_status, (dev_status &MISC_STAGE_MASK ) ==LINUX_STAGE , +20000 ,2000000 , false,IREG_BASE (md->mtk_dev) +PCIE_MISC_DEV_STATUS );
Why ignoring an error is fine here?
...
drivers/net/wwan/t7xx/t7xx_state_monitor.c line 408
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +2
-0+ cmd =kmalloc (sizeof (*cmd), + (in_irq () ||in_softirq () ||irqs_disabled ()) ?GFP_ATOMIC :GFP_KERNEL );
Hmm...
drivers/net/wwan/t7xx/t7xx_state_monitor.c line 417
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +4
-0+if (!cmd) +return -ENOMEM ; +if (in_irq () ||irqs_disabled ()) + flag &= ~FSM_CMD_FLAG_WAITING_TO_COMPLETE ;
Even more hmm...
drivers/net/wwan/t7xx/t7xx_state_monitor.c line 427
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +2
-0+if (flag &FSM_CMD_FLAG_WAITING_TO_COMPLETE ) { +wait_event (cmd->complete_wq, cmd->result !=FSM_CMD_RESULT_PENDING );
Is it okay in IRQ context?
drivers/net/wwan/t7xx/t7xx_state_monitor.c line 433
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +5
-0+if (cmd->result !=FSM_CMD_RESULT_OK ) + result = -EINVAL ; +spin_lock_irqsave (&ctl->cmd_complete_lock, flags); +kfree (cmd); +spin_unlock_irqrestore (&ctl->cmd_complete_lock, flags);
While this is under spin lock?
Quoted 1 line
(quoted diff) +1
-0+ }
...
Quoted 11 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +11
-0+enum md_state ccci_fsm_get_md_state (void ) +{ +struct ccci_fsm_ctl *ctl; + + ctl = ccci_fsm_entry; +if (ctl) +return ctl->md_state; +else +return MD_STATE_INVALID ; +} +
drivers/net/wwan/t7xx/t7xx_state_monitor.c line 522
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +10
-0+unsigned int ccci_fsm_get_current_state (void ) +{ +struct ccci_fsm_ctl *ctl; + + ctl = ccci_fsm_entry; +if (ctl) +return ctl->curr_state; +else +return CCCI_FSM_STOPPED ; +}
Redundant 'else' everywhere.
...
drivers/net/wwan/t7xx/t7xx_state_monitor.c line 555
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +3
-0+int ccci_fsm_init (struct mtk_modem *md) +{ +struct ccci_fsm_ctl *ctl;
struct device *dev = &md->mtk_dev->pdev->dev;
...
drivers/net/wwan/t7xx/t7xx_state_monitor.c line 583
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c new file +7
-0+ ctl->fsm_thread =kthread_run (fsm_main_thread, ctl,"ccci_fsm" ); +if (IS_ERR (ctl->fsm_thread)) { +dev_err (&md->mtk_dev->pdev->dev,"failed to start monitor thread\n" ); +return PTR_ERR (ctl->fsm_thread); + } + +return 0 ;
return PTR_ERR_OR_ZERO(...);
Quoted 1 line
+}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sergey Ryazanov
maintainerRe: [PATCH v2 03/14] net: wwan: t7xx: Add core components
In reply to Ricardo MartinezQuoted 13 lines · Ricardo Martinez
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 3 lines
drivers/net/wwan/t7xx/t7xx_monitor.h | 144 +++++ ... drivers/net/wwan/t7xx/t7xx_state_monitor.c | 598 +++++++++++++++++++++
Out of curiosity, why is this file called t7xx_state_monitor.c, while the corresponding header file is called simply t7xx_monitor.h? Are any other monitors planed?
[skipped]
drivers/net/wwan/Kconfig config IOSM · line 84
Quoted 4 lines
drivers/net/wwan/Kconfig +2
-0+config MTK_T7XX + tristate "MediaTek PCIe 5G WWAN modem T7XX device"
As already suggested by Andy, using "T7xx" (lowercase x) in the title to make it more readable.
drivers/net/wwan/Kconfig config IOSM · line 87
Quoted 3 lines
drivers/net/wwan/Kconfig +3
-0+ depends on PCI + help + Enables MediaTek PCIe based 5G WWAN modem (T700 series) device.
Maybe use the term "T7xx series" here too? Otherwise, it sounds like a driver for the smartphone chipset only.
Quoted 3 lines
drivers/net/wwan/Kconfig +3
-0+ Adapts WWAN framework and provides network interface like wwan0 + and tty interfaces like wwan0at0 (AT protocol), wwan0mbim0 + (MBIM protocol), etc.
[skipped]
drivers/net/wwan/t7xx/t7xx_common.h line 22
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_common.h +3
-0+struct ccci_header { +/* do not assume data[1] is data length in rx */ +u32 data[2 ];
If these fields have different meaning on Tx and Rx you could define them using a union. E.g.
union {
struct {
__le32 idx;
__le32 type;
} rx;
struct {
__le32 idx;
__le32 len;
} tx;
};
__le32 status;or even like this:
__le32 idx;
union {
__le32 rx_type;
__le32 tx_len;
};
__le32 status;Such definition better documents code then the comment above the field.
drivers/net/wwan/t7xx/t7xx_common.h line 25
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_common.h +3
-0+u32 status; +u32 reserved; +};
All these fields should have a type of __le32 since the structure passed to the modem as is.
[skipped]
drivers/net/wwan/t7xx/t7xx_pci.c line 234
Quoted 13 lines
drivers/net/wwan/t7xx/t7xx_pci.c +11
-0+static int __init mtk_pci_init (void ) +{ +return pci_register_driver (&mtk_pci_driver); +} +module_init (mtk_pci_init); + +static void __exit mtk_pci_cleanup(void) +{ +pci_unregister_driver (&mtk_pci_driver); +} +module_exit (mtk_pci_cleanup);
Since the module does not do anything specific on (de-)initialization use the module_pci_driver() macro instead of this boilerplate code.
[skipped]
Quoted 17 lines
drivers/net/wwan/t7xx/t7xx_skb_util.c +15
-0+static struct sk_buff *alloc_skb_from_pool (struct skb_pools *pools,size_t size) +{ +if (size >MTK_SKB_4K ) +return ccci_skb_dequeue (pools->reload_work_queue, &pools->skb_pool_64k); +else if (size >MTK_SKB_16 ) +return ccci_skb_dequeue (pools->reload_work_queue, &pools->skb_pool_4k); +else if (size >0 ) +return ccci_skb_dequeue (pools->reload_work_queue, &pools->skb_pool_16); + +return NULL ; +} + +static struct sk_buff *alloc_skb_from_kernel (size_t size,gfp_t gfp_mask) +{ +if (size >MTK_SKB_4K )
drivers/net/wwan/t7xx/t7xx_skb_util.c line 59
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_skb_util.c +10
-0+return __dev_alloc_skb (MTK_SKB_64K , gfp_mask); + else if (size > MTK_SKB_1_5K) + return __dev_alloc_skb(MTK_SKB_4K, gfp_mask); + else if (size > MTK_SKB_16) + return __dev_alloc_skb(MTK_SKB_1_5K, gfp_mask); + else if (size > 0) + return __dev_alloc_skb(MTK_SKB_16, gfp_mask); + + return NULL; +}
I am wondering what performance gains have you achieved with these skb pools? Can we see any numbers?
I do not think the control path performance is worth the complexity of the multilayer skb allocation. In the data packet Rx path, you need to allocate skb anyway as soon as the driver passes them to the stack. So what is the gain?
[skipped]
drivers/net/wwan/t7xx/t7xx_state_monitor.c line 31
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c +1
-0+static struct ccci_fsm_ctl *ccci_fsm_entry;
Place this pointer at least to the mtk_modem structure. Otherwise, with this global pointer, the driver will break as soon as a second modem will be connected to the host.
Also all functions in this file also should be reworked to be able to accept modem state container pointer, e.g. mtk_modem or some other related structure.
--
Sergey
Martinez, Ricardo
reviewerRe: [PATCH v2 03/14] net: wwan: t7xx: Add core components
Quoted 17 lines · Sergey Ryazanov
Quoted 13 lines · Ricardo Martinez
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 8 lines
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_monitor.h | 144 +++++ ... drivers/net/wwan/t7xx/t7xx_state_monitor.c | 598 +++++++++++++++++++++Out of curiosity, why is this file called
t7xx_state_monitor.c, while the corresponding header file is called simplyt7xx_monitor.h? Are any other monitors planed?[skipped]
No other monitors, I'll rename it to make it consistent.
[skipped]
Quoted 31 lines
Quoted 18 lines
drivers/net/wwan/t7xx/t7xx_skb_util.c +15
-0+static struct sk_buff *alloc_skb_from_pool (struct skb_pools *pools,size_t size) +{ +if (size >MTK_SKB_4K ) +return ccci_skb_dequeue (pools->reload_work_queue, &pools->skb_pool_64k); +else if (size >MTK_SKB_16 ) +return ccci_skb_dequeue (pools->reload_work_queue, &pools->skb_pool_4k); +else if (size >0 ) +return ccci_skb_dequeue (pools->reload_work_queue, &pools->skb_pool_16); + +return NULL ; +} + +static struct sk_buff *alloc_skb_from_kernel (size_t size,gfp_t gfp_mask) +{ +if (size >MTK_SKB_4K )drivers/net/wwan/t7xx/t7xx_skb_util.c line 59
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_skb_util.c +10
-0+return __dev_alloc_skb (MTK_SKB_64K , gfp_mask); + else if (size > MTK_SKB_1_5K) + return __dev_alloc_skb(MTK_SKB_4K, gfp_mask); + else if (size > MTK_SKB_16) + return __dev_alloc_skb(MTK_SKB_1_5K, gfp_mask); + else if (size > 0) + return __dev_alloc_skb(MTK_SKB_16, gfp_mask); + + return NULL; +}I am wondering what performance gains have you achieved with these skb pools? Can we see any numbers?
Quoted 6 lines
I do not think the control path performance is worth the complexity of the multilayer skb allocation. In the data packet Rx path, you need to allocate skb anyway as soon as the driver passes them to the stack. So what is the gain?
[skipped]
Agree, we are removing the skb pools for the control path.
Regarding Rx data path, we'll get some numbers to see if the pool is worth it,
otherwise remove it too.
[skipped]
Ricardo Martinez
reviewerPATCH v2 4/14 net: wwan: t7xx: Add port proxy infrastructure
In reply to Ricardo MartinezFrom: Haijun Lio <[email protected]>
Port-proxy provides a common interface to interact with different types of ports. Ports export their configuration via struct t7xx_port and operate as defined by struct port_ops.
--- drivers/net/wwan/t7xx/Makefile | 1 + drivers/net/wwan/t7xx/t7xx_modem_ops.c | 14 +- drivers/net/wwan/t7xx/t7xx_port.h | 161 +++++ drivers/net/wwan/t7xx/t7xx_port_proxy.c | 775 +++++++++++++++++++++ drivers/net/wwan/t7xx/t7xx_port_proxy.h | 94 +++ drivers/net/wwan/t7xx/t7xx_state_monitor.c | 28 +- 6 files changed, 1070 insertions(+), 3 deletions(-) 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
@@ -11,3 +11,4 @@ mtk_t7xx-y:= t7xx_pci.o \ t7xx_skb_util.o \ t7xx_cldma.o \ t7xx_hif_cldma.o \ + t7xx_port_proxy.o \
drivers/net/wwan/t7xx/t7xx_modem_ops.c +13 -1
@@ -23,6 +23,8 @@#include "t7xx_monitor.h" #include "t7xx_pci.h" #include "t7xx_pcie_mac.h" +#include "t7xx_port.h" +#include "t7xx_port_proxy.h" #define RGU_RESET_DELAY_US 20#define PORT_RESET_DELAY_US 2000
@@ -220,12 +222,14 @@ static void md_exception(struct mtk_modem *md, enum hif_ex_stage stage) mtk_dev = md->mtk_dev; -if (stage ==HIF_EX_CLEARQ_DONE ) +if (stage ==HIF_EX_CLEARQ_DONE ) {/* give DHL time to flush data. * this is an empirical value that assure * that DHL have enough time to flush all the date. */ msleep (PORT_RESET_DELAY_US ); +port_proxy_reset (&mtk_dev->pdev->dev); + }cldma_exception (ID_CLDMA1 , stage);
@@ -412,6 +416,7 @@ void mtk_md_reset(struct mtk_pci_dev *mtk_dev)md_structure_reset (md);ccci_fsm_reset ();cldma_reset (ID_CLDMA1 ); +port_proxy_reset (&mtk_dev->pdev->dev); md->md_init_finish = true; }
@@ -450,6 +455,10 @@ int mtk_md_init(struct mtk_pci_dev *mtk_dev)if (ret) goto err_fsm_init; + ret =port_proxy_init (mtk_dev->md); +if (ret) + goto err_cldma_init; + fsm_ctl =fsm_get_entry ();fsm_append_command (fsm_ctl,CCCI_COMMAND_START ,0 );
@@ -458,6 +467,8 @@ int mtk_md_init(struct mtk_pci_dev *mtk_dev) md->md_init_finish = true;return 0 ; +err_cldma_init: +cldma_exit (ID_CLDMA1 ); err_fsm_init:ccci_fsm_uninit (); err_alloc:
@@ -480,6 +491,7 @@ void mtk_md_exit(struct mtk_pci_dev *mtk_dev) fsm_ctl =fsm_get_entry ();/* change FSM state, will auto jump to stopped */ fsm_append_command (fsm_ctl,CCCI_COMMAND_PRE_STOP ,1 ); +port_proxy_uninit ();cldma_exit (ID_CLDMA1 );ccci_fsm_uninit ();destroy_workqueue (md->handshake_wq);
drivers/net/wwan/t7xx/t7xx_port.h new file +161 -0
161 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +775 -0
775 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_port_proxy.h new file +94 -0
94 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_state_monitor.c +26 -2
@@ -24,6 +24,8 @@#include "t7xx_monitor.h" #include "t7xx_pci.h" #include "t7xx_pcie_mac.h" +#include "t7xx_port.h" +#include "t7xx_port_proxy.h" #define FSM_DRM_DISABLE_DELAY_MS 200#define FSM_EX_REASON GENMASK(23, 16)
@@ -84,6 +86,9 @@ void fsm_broadcast_state(struct ccci_fsm_ctl *ctl, enum md_state state) ctl->md_state = state; +/* update to port first, otherwise sending message on HS2 may fail */ +port_proxy_md_status_notify (state); +fsm_state_notify (state); }
@@ -141,7 +146,8 @@ static void fsm_flush_queue(struct ccci_fsm_ctl *ctl)static void fsm_routine_exception (struct ccci_fsm_ctl *ctl,struct ccci_fsm_command *cmd,enum ccci_ex_reason reason) { -bool rec_ok = false; +struct t7xx_port *log_port, *meta_port; +bool rec_ok = false, pass = false;struct ccci_fsm_event *event;unsigned long flags;struct device *dev;
@@ -202,11 +208,29 @@ static void fsm_routine_exception(struct ccci_fsm_ctl *ctl, struct ccci_fsm_commif (!list_empty (&ctl->event_queue)) { event =list_first_entry (&ctl->event_queue, struct ccci_fsm_event, entry); -if (event->event_id ==CCCI_EVENT_MD_EX_PASS ) +if (event->event_id ==CCCI_EVENT_MD_EX_PASS ) { + pass = true;fsm_finish_event (ctl, event); + } }spin_unlock_irqrestore (&ctl->event_lock, flags); +if (pass) { + log_port =port_get_by_name ("ttyCMdLog" ); +if (log_port) + log_port->ops->enable_chl (log_port); +else +dev_err (dev,"ttyCMdLog port not found\n" ); + + meta_port =port_get_by_name ("ttyCMdMeta" ); +if (meta_port) + meta_port->ops->enable_chl (meta_port); +else +dev_err (dev,"ttyCMdMeta port not found\n" ); + +break ; + } + cnt++;msleep (EVENT_POLL_INTERVAL_MS ); }
Signature · 1 line
2.17.1
Re: [PATCH v2 04/14] net: wwan: t7xx: Add port proxy infrastructure
Quoted 5 lines · Ricardo Martinez
From: Haijun Lio <[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.
Same here, assuming that the comments from the previous patches are applied here as well, only unique are given.
...
drivers/net/wwan/t7xx/t7xx_modem_ops.c static void md_exception(struct mtk_modem *md, enum hif_ex_stage stage)
Quoted 9 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c +2
-1-if (stage ==HIF_EX_CLEARQ_DONE ) +if (stage ==HIF_EX_CLEARQ_DONE ) {/* give DHL time to flush data. * this is an empirical value that assure * that DHL have enough time to flush all the date. */ msleep (PORT_RESET_DELAY_US ); + }
These curly brackets should be part of previous patch. Try to minimize (ideally avoid) ping-pong style of changes in the same series.
...
Quoted 1 line
+#define
CCCI_MAX_CH_ID0xff/* RX channel ID should NOT be >= this!! */
I haven't got the details behind the comment. Is the Rx channel ID predefined somewhere? If so, use static_assert() instead of this comment.
...
Quoted 32 lines
drivers/net/wwan/t7xx/t7xx_port.h new file +32
-0+enum ccci_ch { +/* to MD */ +CCCI_CONTROL_RX =0x2000 , +CCCI_CONTROL_TX =0x2001 , +CCCI_SYSTEM_RX =0x2002 , +CCCI_SYSTEM_TX =0x2003 , +CCCI_UART1_RX =0x2006 ,/* META */ +CCCI_UART1_RX_ACK =0x2007 , +CCCI_UART1_TX =0x2008 , +CCCI_UART1_TX_ACK =0x2009 , +CCCI_UART2_RX =0x200a ,/* AT */ +CCCI_UART2_RX_ACK =0x200b , +CCCI_UART2_TX =0x200c , +CCCI_UART2_TX_ACK =0x200d , +CCCI_MD_LOG_RX =0x202a ,/* MD logging */ +CCCI_MD_LOG_TX =0x202b , +CCCI_LB_IT_RX =0x203e ,/* loop back test */ +CCCI_LB_IT_TX =0x203f , +CCCI_STATUS_RX =0x2043 ,/* status polling */ +CCCI_STATUS_TX =0x2044 , +CCCI_MIPC_RX =0x20ce ,/* MIPC */ +CCCI_MIPC_TX =0x20cf , +CCCI_MBIM_RX =0x20d0 , +CCCI_MBIM_TX =0x20d1 , +CCCI_DSS0_RX =0x20d2 , +CCCI_DSS0_TX =0x20d3 , +CCCI_DSS1_RX =0x20d4 , +CCCI_DSS1_TX =0x20d5 , +CCCI_DSS2_RX =0x20d6 , +CCCI_DSS2_TX =0x20d7 , +CCCI_DSS3_RX =0x20d8 , +CCCI_DSS3_TX =0x20d9 ,
drivers/net/wwan/t7xx/t7xx_port.h line 88
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port.h new file +9
-0+CCCI_DSS4_RX =0x20da , +CCCI_DSS4_TX =0x20db , +CCCI_DSS5_RX =0x20dc , +CCCI_DSS5_TX =0x20dd , +CCCI_DSS6_RX =0x20de , +CCCI_DSS6_TX =0x20df , +CCCI_DSS7_RX =0x20e0 , +CCCI_DSS7_TX =0x20e1 , + CCCI_MAX_CH_NUM,
Not sure about meaning of this and even needfulness. It's obvious you don't care about actual value here.
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_port.h new file +3
-0+CCCI_MONITOR_CH_ID =GENMASK (31 ,28 ),/* for MD init */ + CCCI_INVALID_CH_ID = GENMASK(15, 0), +};
...
Quoted 1 line
+#define
MTK_DEV_NAME"MTK_WWAN_M80"
DEV?
...
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 44
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +6
-0+/* port->minor is configured in-sequence, but when we use it in code +* it should be unique among all ports for addressing. +*/ +#define TTY_IPC_MINOR_BASE 100 +#define TTY_PORT_MINOR_BASE 250 +#define TTY_PORT_MINOR_INVALID -1
Why it's not automatically allocated?
...
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 56
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +2
-0+static struct t7xx_port md_ccci_ports[] = { + {0 ,0 ,0 ,0 ,0 ,0 ,ID_CLDMA1 ,0 , &dummy_port_ops,0xff ,"dummy_port" ,},
Use C99 initializers.
Quoted 1 line
+};
...
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 72
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +3
-0+ nlh =nlmsg_put (nl_skb,0 ,1 ,NLMSG_DONE , len,0 ); +if (!nlh) { +dev_err (port->dev,"could not release netlink\n" );
I'm wondering why you are not using net_err() / netdev_err() / netif_err() where it's appropriate.
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +3
-0+nlmsg_free (nl_skb); +return -EFAULT ; + }
...
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 85
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +2
-0+return netlink_broadcast (pprox->netlink_sock, nl_skb, +0 , grp,GFP_KERNEL );
One line?
...
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +5
-0+static int port_netlink_init (void ) +{ + port_prox->netlink_sock =netlink_kernel_create (&init_net,PORT_NOTIFY_PROTOCOL ,NULL ); + +if (!port_prox->netlink_sock) {
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 102
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +10
-0+dev_err (port_prox->dev,"failed to create netlink socket\n" ); +return -ENOMEM ; + } + +return 0 ; +} + +static void port_netlink_uninit (void ) +{ +if (port_prox->netlink_sock) {
if (!->netlink_sock) ?
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +4
-0+netlink_kernel_release (port_prox->netlink_sock); + port_prox->netlink_sock =NULL ; + } +}
...
Quoted 16 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +16
-0+static struct t7xx_port *proxy_get_port (int minor,enum ccci_ch ch) +{ +struct t7xx_port *port; +int i; + +if (!port_prox) +return NULL ; + +for_each_proxy_port (i, port, port_prox) { +if (minor >=0 && port->minor == minor) +return port; + +if (ch !=CCCI_INVALID_CH_ID && (port->rx_ch == ch || port->tx_ch == ch)) +return port; + } +
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 133
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +10
-0+return NULL ; +} + +struct t7xx_port *port_proxy_get_port (int major,int minor) +{ +if (port_prox && port_prox->major == major) +return proxy_get_port (minor,CCCI_INVALID_CH_ID ); + +return NULL ; +}
Looking into the second one I would definitely refactor the first one
static struct t7xx_port *do_proxy_get_port(int minor, enum ccci_ch ch)
{
struct t7xx_port *port;
int i;
for_each_proxy_port(i, port, port_prox) {
if (minor >= 0 && port->minor == minor)
return port;
if (ch != CCCI_INVALID_CH_ID && (port->rx_ch == ch || port->tx_ch == ch))
return port;
}
return NULL;
}// If it's even needed at all... Perhaps you may move NULL check to the (single?) caller static struct t7xx_port *proxy_get_port(int minor, enum ccci_ch ch)
{
if (port_prox)
return do_proxy_get_port(minor, ch);
return NULL;
}struct t7xx_port *port_proxy_get_port(int major, int minor)
{
if (port_prox && port_prox->major == major)
return do_proxy_get_port(minor, CCCI_INVALID_CH_ID);
return NULL;
}Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +4
-0+static inline struct t7xx_port *port_get_by_ch (enum ccci_ch ch) +{ +return proxy_get_port (TTY_PORT_MINOR_INVALID , ch); +}
...
Review
Quoted 1 line
(quoted diff) +1
-0+ ccci_h = (struct ccci_header *)skb->data;
Do you need casting?
...
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 207
Quoted 1 line
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +1
-0+if (port->flags &PORT_F_USER_HEADER ) {/* header provide by user */
Is it proper English in the comment?
Quoted 15 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +15
-0+/* CCCI_MON_CH should fall in here, as header must be +* send to md_init. +*/ +if (ccci_h->data[0 ] ==CCCI_HEADER_NO_DATA ) { +if (skb->len >sizeof (struct ccci_header )) { +dev_err_ratelimited (port->dev, +"recv unexpected data for %s, skb->len=%d\n" , + port->name, skb->len); +skb_trim (skb,sizeof (struct ccci_header )); + } + } + }else { +/* remove CCCI header */ +skb_pull (skb,sizeof (struct ccci_header )); + }
...
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +10
-0+int port_proxy_send_skb (struct t7xx_port *port,struct sk_buff *skb,bool from_pool) +{ +struct ccci_header *ccci_h; +unsigned char tx_qno; +int ret; + + ccci_h = (struct ccci_header *)(skb->data); + tx_qno =port_get_queue_no (port); +port_proxy_set_seq_num (port, (struct ccci_header *)ccci_h); + ret =cldma_send_skb (port->path_id, tx_qno, skb, from_pool, true);
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 336
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +10
-0+if (ret) { +dev_err (port->dev,"failed to send skb, error: %d\n" , ret); + }else { +/* Record the port seq_num after the data is sent to HIF. +* Only bits 0-14 are used, thus negating overflow. +*/ + port->seq_nums[MTK_OUT ]++; + } + +return ret;
The density of the characters is a bit high. Why not refactor this?
...blank line here...
ret = cldma_send_skb(port->path_id, tx_qno, skb, from_pool, true);
if (ret) {
dev_err(port->dev, "failed to send skb, error: %d\n", ret);
return ret;
}
...Quoted 1 line
+}
...
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +8
-0+ port_list = &port_prox->rx_ch_ports[channel &CCCI_CH_ID_MASK ]; +list_for_each_entry (port, port_list, entry) { +if (queue->hif_id != port->path_id || channel != port->rx_ch) +continue ; + +/* Multi-cast is not supported, because one port may be freed +* and can modify this request before another port can process it. +* However we still can use req->state to achieve some kind of
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 512
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +10
-0+* multi-cast if needed. +*/ +if (port->ops->recv_skb) { + seq_num =port_check_rx_seq_num (port, ccci_h); + ret = port->ops->recv_skb (port, skb); +/* If the packet is stored to RX buffer +* successfully or drop, the sequence +* num will be updated. +*/ +if (ret == -ENOBUFS )
Why you don't need to free SKB here?
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +8
-0+return ret; + + port->seq_nums[MTK_IN ] = seq_num; + } + +break ; + } +
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 530
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +10
-0+err_exit: +if (ret <0 ) { +struct skb_pools *pools; + + pools = &queue->md->mtk_dev->pools; +ccci_free_skb (pools, skb); +return -ENETDOWN ; + } + +return 0 ;
Why not simply split this to
return 0;
// pay attention to the label namingerr_free_skb:
ccci_free_skb(&queue->md->mtk_dev->pools, skb); return -ENETDOWN;
I suspect that this may be part of something bigger which is comming, so try to minimize both weirdness here and additional shuffling somewhere else in that case.
...
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 559
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +3
-0+for_each_proxy_port (i, port, port_prox) +if (port->ops->md_state_notify) + port->ops->md_state_notify (port, state);
Perhaps {} ?
...
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 649
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +3
-0+for_each_proxy_port (i, port, port_prox) +if (!strncmp (port->name, port_name,strlen (port->name))) +return port;
Ditto.
...
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 663
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +3
-0+switch (state) { +case MTK_PORT_STATE_ENABLE : +snprintf (msg,PORT_NETLINK_MSG_MAX_PAYLOAD ,"enable %s" , port->name);
sizeof(msg) is much shorter and flexible.
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +10
-0+break ; + +case MTK_PORT_STATE_DISABLE : +snprintf (msg,PORT_NETLINK_MSG_MAX_PAYLOAD ,"disable %s" , port->name); +break ; + +default : +snprintf (msg,PORT_NETLINK_MSG_MAX_PAYLOAD ,"invalid operation" ); +break ; + }
...
drivers/net/wwan/t7xx/t7xx_port_proxy.h line 61
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.h new file +5
-0+struct ctrl_msg_header { +u32 ctrl_msg_id; +u32 reserved; +u32 data_length; +u8 data[0 ];
We don't allow VLAs.
drivers/net/wwan/t7xx/t7xx_port_proxy.h line 68
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.h new file +7
-0+}; + +struct port_msg { +u32 head_pattern; +u32 info; +u32 tail_pattern; +u8 data[0 ];/* port set info */
Ditto.
Quoted 1 line
+};
...
drivers/net/wwan/t7xx/t7xx_state_monitor.c static void fsm_routine_exception(struct ccci_fsm_ctl *ctl, struct ccci_fsm_comm · line 214
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c +3
-1-if (event->event_id ==CCCI_EVENT_MD_EX_PASS ) +if (event->event_id ==CCCI_EVENT_MD_EX_PASS ) { + pass = true;fsm_finish_event (ctl, event); + }
Make curly braces to go to the previous patch despite checkpatch warnings.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Martinez, Ricardo
reviewerRe: [PATCH v2 04/14] net: wwan: t7xx: Add port proxy infrastructure
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Ricardo Martinez
From: Haijun Lio <[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.Same here, assuming that the comments from the previous patches are applied here as well, only unique are given.
Thanks for the feedback.
...
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 72
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +3
-0+ nlh =nlmsg_put (nl_skb,0 ,1 ,NLMSG_DONE , len,0 ); +if (!nlh) { +dev_err (port->dev,"could not release netlink\n" );I'm wondering why you are not using
net_err()/netdev_err()/netif_err()where it's appropriate.
The original idea was to avoid mixing different types of APIs, but yes, it makes sense to use
those APIs where it's appropriate, I'm thinking on using them at t7xx_netdev.c where the
required net_device is available.
...
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +4
-0+nlmsg_free (nl_skb); +return -EFAULT ; + } + ccci_h = (struct ccci_header *)skb->data;Do you need casting?
Yes, skb->data is an unsigned char*
Quoted 1 line
...
...
Sergey Ryazanov
maintainerRe: [PATCH v2 04/14] net: wwan: t7xx: Add port proxy infrastructure
In reply to Ricardo MartinezQuoted 3 lines · Ricardo Martinez
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 106
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_port.h +2
-0+struct t7xx_port { +/* members used for initialization, do not change the order */
As already suggested by Andy, use C99 initializers to initialize the md_ccci_ports array and drop the above comment about the strict order requirements.
drivers/net/wwan/t7xx/t7xx_port.h line 117
Quoted 11 lines
drivers/net/wwan/t7xx/t7xx_port.h +11
-0+enum ccci_ch tx_ch; +enum ccci_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; +struct port_ops *ops; +unsigned int minor; +char *name;
Why did you need these two fields with the port name and minor number? The WWAN subsystem will care about these data for you. It is its purpose.
Quoted 25 lines
drivers/net/wwan/t7xx/t7xx_port.h +25
-0+enum wwan_port_type mtk_port_type; + +/* members un-initialized in definition */ +struct wwan_port *mtk_wwan_port; +struct mtk_pci_dev *mtk_dev; +struct device *dev; +short seq_nums[2 ]; +struct port_proxy *port_proxy; +atomic_t usage_cnt; +struct list_head entry; +struct list_head queue_entry; +unsigned int major; +unsigned int minor_base; +/* TX and RX flows are asymmetric since ports are multiplexed on +* queues. +* +* TX: data blocks are sent directly to a queue. Each port +* does not maintain a TX list; instead, they only provide +* a wait_queue_head for blocking writes. +* +* RX: Each port uses a RX list to hold packets, +* allowing the modem to dispatch RX packet as quickly as possible. +*/ +struct sk_buff_head rx_skb_list; +bool skb_from_pool;
drivers/net/wwan/t7xx/t7xx_port.h line 152
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port.h +10
-0+spinlock_t port_update_lock;/* protects port configuration */ +wait_queue_head_t rx_wq; +int rx_length_th; +port_skb_handler skb_handler; +unsigned char chan_enable; +unsigned char chn_crt_stat; +struct cdev *cdev; +struct task_struct *thread; +struct mutex tx_mutex_lock;/* protects the seq number operation */ +};
You should split the t7xx_port structure at least for two parts. A first part with static configuration can remain in the structure and statically initialized in the md_ccci_ports array. All non-shareable runtime state fields (e.g. SKB lists, pointers to dynamically allocated device instance structures) should be moved to a device state container.
[skipped]
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 34
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c +2
-0+#define PORT_NETLINK_MSG_MAX_PAYLOAD 32 +#define PORT_NOTIFY_PROTOCOL NETLINK_USERSOCK
There is a clear statement in the include/uapi/linux/netlink.h file that NETLINK_USERSOCK is reserved for user mode socket protocols. Please do not abuse netlink protocol numbers.
If you really need a special Netlink interface to communicate with userspace, consider creating a new generic netlink family. But it looks like all the Netlink stuff here is a leftover of a debug interface that was used at an earlier driver development stage. So I suggest to just remove all Netlink usage here and consider using dynamic debug logging, or switch to the kernel tracing.
Quoted 2 lines
...
+static structport_proxy*port_prox;
This is another one pointer that should be placed into a device runtime state structure to avoid driver crash with multiple modems.
Quoted 2 lines
...
+static structport_opsdummy_port_ops;
Why do you need this dummy ops structure? You anyway remove it in the next patch. If you need it as a placeholder for the md_ccci_ports array below, then it is safe to define an empty md_ccci_ports array and then just fill it. Please consider removing this structure to avoid ping-pong changes.
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 56
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c +2
-0+static struct t7xx_port md_ccci_ports[] = { + {0 ,0 ,0 ,0 ,0 ,0 ,ID_CLDMA1 ,0 , &dummy_port_ops,0xff ,"dummy_port" ,},
As already suggested by Andy, use C99 initializers here. E.g.
{
.tx_ch = 0,
.rx_ch = 0,
.txq_index = 0,
.rxq_index = 0,
.txq_exp_index = 0,
.rxq_exp_index = 0,
.path_id = ID_CLDMA1,
.ops = &dummy_port_ops,
.name = "dummy_port",
}, {
...
}, {
...
}drivers/net/wwan/t7xx/t7xx_port_proxy.c line 148
Quoted 10 lines
...
drivers/net/wwan/t7xx/t7xx_port_proxy.c +9
-0+/* Sequence numbering to track for lost packets */ +void port_proxy_set_seq_num (struct t7xx_port *port,struct ccci_header *ccci_h) +{ +if (ccci_h && port) { + ccci_h->status &= ~HDR_FLD_SEQ ; + ccci_h->status |=FIELD_PREP (HDR_FLD_SEQ , port->seq_nums[MTK_OUT ]); + ccci_h->status &= ~HDR_FLD_AST ; + ccci_h->status |=FIELD_PREP (HDR_FLD_AST ,1 ); + }
Endians handling required here.
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 157
Quoted 9 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c +9
-0+} + +static u16 port_check_rx_seq_num (struct t7xx_port *port,struct ccci_header *ccci_h) +{ +u16 channel, seq_num, assert_bit; + + channel =FIELD_GET (HDR_FLD_CHN , ccci_h->status); + seq_num =FIELD_GET (HDR_FLD_SEQ , ccci_h->status); + assert_bit =FIELD_GET (HDR_FLD_AST , ccci_h->status);
Field endians handling is missed here. Probably you should first convert status field data to CPU endians and only then parse it. E.g.
u32 status = le32_to_cpu(ccci_h->status);
channel = FIELD_GET(HDR_FLD_CHN, status);
seq_num = FIELD_GET(HDR_FLD_SEQ, status);
assert_bit = FIELD_GET(HDR_FLD_AST, status);drivers/net/wwan/t7xx/t7xx_port_proxy.c line 162
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c +5
-0+if (assert_bit && port->seq_nums[MTK_IN ] && + ((seq_num - port->seq_nums[MTK_IN ]) &CHECK_RX_SEQ_MASK ) !=1 ) { +dev_err (port->dev,"channel %d seq number out-of-order %d->%d (data: %X, %X)\n" , + channel, seq_num, port->seq_nums[MTK_IN ], + ccci_h->data[0 ], ccci_h->data[1 ]);
dev_err_ratelimited() ?
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 265
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c +8
-0+ } + +return seq_num; +} +int port_recv_skb (struct t7xx_port *port,struct sk_buff *skb) +{ +if (port->flags &PORT_F_RX_ALLOW_DROP ) { +dev_err (port->dev,"port %s RX full, drop packet\n" , port->name);
Should the ratelimited variant be used here? And why is so high message level used?
Quoted 1 line
+ return
-ENETDOWN;
Why ENETDOWN on buffer space exhaustion?
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 325
Quoted 12 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c +9
-0+ } + +return -ENOBUFS ; +} +int port_proxy_send_skb (struct t7xx_port *port,struct sk_buff *skb,bool from_pool) +{ +struct ccci_header *ccci_h; + ccci_h = (struct ccci_header *)(skb->data); +port_proxy_set_seq_num (port, (struct ccci_header *)ccci_h);
cchi_h is already of type ccci_header, no casting is required here.
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 395
Quoted 4 lines
...
drivers/net/wwan/t7xx/t7xx_port_proxy.c +3
-0+ +/* inject CCCI message to modem */ +void port_proxy_send_msg_to_md (int ch,unsigned int msg,unsigned int resv)
This function is not called by any code in this patch. Should the function be moved to the "net: wwan: t7xx: Add control port" patch along with the ctrl_msg_header structure definition?
Quoted 26 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c +26
-0+{ +struct ctrl_msg_header *ctrl_msg_h; +struct ccci_header *ccci_h; +struct t7xx_port *port; +struct sk_buff *skb; +int ret; + + port =port_get_by_ch (ch); +if (!port) +return ; + + skb =ccci_alloc_skb_from_pool (&port->mtk_dev->pools,sizeof (struct ccci_header ), +GFS_BLOCKING ); +if (!skb) +return ; + +if (ch ==CCCI_CONTROL_TX ) { + ccci_h = (struct ccci_header *)(skb->data); + ccci_h->data[0 ] =CCCI_HEADER_NO_DATA ; + ccci_h->data[1 ] =sizeof (struct ctrl_msg_header ) +CCCI_H_LEN ; + ccci_h->status &= ~HDR_FLD_CHN ; + ccci_h->status |=FIELD_PREP (HDR_FLD_CHN , ch); + ccci_h->reserved =0 ; + ctrl_msg_h = (struct ctrl_msg_header *)(skb->data +CCCI_H_LEN ); + ctrl_msg_h->data_length =0 ; + ctrl_msg_h->reserved = resv;
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 431
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c +10
-0+ ctrl_msg_h->ctrl_msg_id = msg; +skb_put (skb,CCCI_H_LEN +sizeof (struct ctrl_msg_header )); + }else { + ccci_h =skb_put (skb,sizeof (struct ccci_header )); + ccci_h->data[0 ] =CCCI_HEADER_NO_DATA ; + ccci_h->data[1 ] = msg; + ccci_h->status &= ~HDR_FLD_CHN ; + ccci_h->status |=FIELD_PREP (HDR_FLD_CHN , ch); + ccci_h->reserved = resv; + }
Endians handling missed here as well.
Quoted 13 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c +12
-0+ ret =port_proxy_send_skb (port, skb, port->skb_from_pool); +if (ret) { +dev_err (port->dev,"port%s send to MD fail\n" , port->name); +ccci_free_skb (&port->mtk_dev->pools, skb); + } +} +static int proxy_register_char_dev (void ) +{ +dev_t dev =0 ; +int ret; + +if (port_prox->major) {
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 577
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c +10
-0+ dev =MKDEV (port_prox->major, port_prox->minor_base); + ret =register_chrdev_region (dev,TTY_IPC_MINOR_BASE ,MTK_DEV_NAME ); + }else { + ret =alloc_chrdev_region (&dev, port_prox->minor_base, +TTY_IPC_MINOR_BASE ,MTK_DEV_NAME ); +if (ret) +dev_err (port_prox->dev,"failed to alloc chrdev region, ret=%d\n" , ret); + + port_prox->major =MAJOR (dev); + }
For what do you need these character devices? The WWAN subsystem already handle all these tasks.
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 620
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c +9
-0+return ret; +} +static int proxy_alloc (struct mtk_modem *md) +{ +int ret; + + port_prox =devm_kzalloc (&md->mtk_dev->pdev->dev,sizeof (*port_prox),GFP_KERNEL ); +if (!port_prox) +return -ENOMEM ;
This pointer should be placed into the mtk_modem, not to a global variable.
Quoted 13 lines
...
drivers/net/wwan/t7xx/t7xx_port_proxy.c +12
-0+int port_proxy_broadcast_state (struct t7xx_port *port,int state) +{ +char msg[PORT_NETLINK_MSG_MAX_PAYLOAD ]; + +if (state >=MTK_PORT_STATE_INVALID ) +return -EINVAL ; + +switch (state) { +case MTK_PORT_STATE_ENABLE : +snprintf (msg,PORT_NETLINK_MSG_MAX_PAYLOAD ,"enable %s" , port->name); +break ; +
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 675
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c +10
-0+case MTK_PORT_STATE_DISABLE : +snprintf (msg,PORT_NETLINK_MSG_MAX_PAYLOAD ,"disable %s" , port->name); +break ; + +default : +snprintf (msg,PORT_NETLINK_MSG_MAX_PAYLOAD ,"invalid operation" ); +break ; + } + +return port_netlink_send_msg (port,PORT_STATE_BROADCAST_GROUP , msg,strlen (msg) +1 );
Netlink by nature is a binary protocol. You need to emit messages of different types per port state with a port name attribute inside. Or emit a single type message with two separate attributes: one to carry a port state and a separate attribute to carry a port name.
Or, as I suggested above, just drop this Netlink abuse and switch to dynamic debug logging. Or even better, consider switching to the kernel tracing API.
[skipped]
drivers/net/wwan/t7xx/t7xx_port_proxy.h line 60
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.h +4
-0+struct ctrl_msg_header { +u32 ctrl_msg_id; +u32 reserved; +u32 data_length;
All three of these fields should be of type __be32, since the structure is passed to the modem as is.
drivers/net/wwan/t7xx/t7xx_port_proxy.h line 67
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.h +7
-0+u8 data[0 ]; +}; + +struct port_msg { +u32 head_pattern; +u32 info; +u32 tail_pattern;
Same here.
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.h +2
-0+u8 data[0 ];/* port set info */ +};
[skipped]
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c +2
-0@@ -202,11 +208,29 @@ static void fsm_routine_exception(struct ccci_fsm_ctl *ctl, struct ccci_fsm_commspin_unlock_irqrestore (&ctl->event_lock, flags); +if (pass) { + log_port =port_get_by_name ("ttyCMdLog" );
drivers/net/wwan/t7xx/t7xx_state_monitor.c static void fsm_routine_exception(struct ccci_fsm_ctl *ctl, struct ccci_fsm_comm · line 229
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_state_monitor.c +10
-0+if (log_port) + log_port->ops->enable_chl (log_port); +else +dev_err (dev,"ttyCMdLog port not found\n" ); + + meta_port =port_get_by_name ("ttyCMdMeta" ); +if (meta_port) + meta_port->ops->enable_chl (meta_port); +else +dev_err (dev,"ttyCMdMeta port not found\n" );
Looks like this change does not belong to this patch. The "ttyCMdLog" port entry will be created only by the last patch.
--
Sergey
Martinez, Ricardo
reviewerRe: [PATCH v2 04/14] net: wwan: t7xx: Add port proxy infrastructure
Quoted 5 lines · Sergey Ryazanov
Quoted 3 lines · Ricardo Martinez
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 12 lines
drivers/net/wwan/t7xx/t7xx_port.h line 117
Quoted 12 lines
drivers/net/wwan/t7xx/t7xx_port.h new file +11
-0+enum ccci_ch tx_ch; +enum ccci_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; +struct port_ops *ops; +unsigned int minor; +char *name;
Quoted 3 lines
Why did you need these two fields with the port name and minor number? The WWAN subsystem will care about these data for you. It is its purpose.
This port proxy structure can abstract different types of ports. 'minor' field is used for
tty and char ports but it will be removed since the next iteration will contain only
WWAN ports and one control port.
'name' is currently used when printing error logs, in the future it can be used
to define the name in the file system for test and debug ports.
[skipped]
Quoted 10 lines
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +10
-0+static int proxy_register_char_dev (void ) +{ +dev_t dev =0 ; +int ret; + +if (port_prox->major) { + dev =MKDEV (port_prox->major, port_prox->minor_base); + ret =register_chrdev_region (dev,TTY_IPC_MINOR_BASE ,MTK_DEV_NAME ); + }else { + ret = alloc_chrdev_region(&dev, port_prox->minor_base,
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 577
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +6
-0+ TTY_IPC_MINOR_BASE, MTK_DEV_NAME); +if (ret) +dev_err (port_prox->dev,"failed to alloc chrdev region, ret=%d\n" , ret); + + port_prox->major =MAJOR (dev); + }For what do you need these character devices? The WWAN subsystem already handle all these tasks.
This infrastructure is not going to be included in the next iteration, it is used for debug and test ports.
Quoted 11 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c line 620
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_port_proxy.c new file +9
-0+return ret; +} +static int proxy_alloc (struct mtk_modem *md) +{ +int ret; + + port_prox =devm_kzalloc (&md->mtk_dev->pdev->dev,sizeof (*port_prox),GFP_KERNEL ); +if (!port_prox) +return -ENOMEM ;
[skipped]
Ricardo
Ricardo Martinez
reviewerPATCH v2 5/14 net: wwan: t7xx: Add control port
In reply to Ricardo MartinezFrom: Haijun Lio <[email protected]>
Control Port implements driver control messages such as modem-host handshaking, controls port enumeration, and handles exception messages.
The handshaking process between the driver and the modem happens during the init sequence. The process involves the exchange of a list of supported runtime features to make sure that modem and host are ready to provide proper feature lists including port enumeration. Further features can be enabled and controlled in this handshaking process.
--- drivers/net/wwan/t7xx/Makefile | 1 + drivers/net/wwan/t7xx/t7xx_modem_ops.c | 244 ++++++++++++++++++++- drivers/net/wwan/t7xx/t7xx_modem_ops.h | 2 + drivers/net/wwan/t7xx/t7xx_monitor.h | 3 + drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c | 150 +++++++++++++ drivers/net/wwan/t7xx/t7xx_port_proxy.c | 9 +- drivers/net/wwan/t7xx/t7xx_port_proxy.h | 4 + drivers/net/wwan/t7xx/t7xx_state_monitor.c | 3 + 8 files changed, 411 insertions(+), 5 deletions(-) create mode 100644 drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c
drivers/net/wwan/t7xx/Makefile +1 -0
@@ -12,3 +12,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 +242 -2
272 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_modem_ops.h +2 -0
@@ -60,7 +60,9 @@ enum md_event_id {struct core_sys_info {atomic_t ready; +atomic_t handshake_ongoing;u8 feature_set[FEATURE_COUNT ]; +struct t7xx_port *ctl_port; };struct mtk_modem {
drivers/net/wwan/t7xx/t7xx_monitor.h +3 -0
@@ -36,9 +36,12 @@ enum ccci_fsm_state {enum ccci_fsm_event_state {CCCI_EVENT_INVALID , +CCCI_EVENT_MD_HS2 ,CCCI_EVENT_MD_EX ,CCCI_EVENT_MD_EX_REC_OK ,CCCI_EVENT_MD_EX_PASS , +CCCI_EVENT_MD_HS2_EXIT , +CCCI_EVENT_AP_HS2_EXIT ,CCCI_EVENT_MAX };
drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c new file +150 -0
150 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_port_proxy.c +6 -3
@@ -50,10 +50,9 @@ static struct port_proxy *port_prox; i < (proxy)->port_number; \ i++, (p) = &(proxy)->ports[i]) -static struct port_ops dummy_port_ops; -static struct t7xx_port md_ccci_ports[] = { - {0 ,0 ,0 ,0 ,0 ,0 ,ID_CLDMA1 ,0 , &dummy_port_ops,0xff ,"dummy_port" ,}, + {CCCI_CONTROL_TX ,CCCI_CONTROL_RX ,0 ,0 ,0 ,0 ,ID_CLDMA1 , +0 , &ctl_port_ops,0xff ,"ccci_ctrl" ,}, }; static int port_netlink_send_msg(struct t7xx_port *port, int grp,
@@ -586,6 +585,10 @@ static void proxy_init_all_ports(struct mtk_modem *md)for_each_proxy_port (i, port, port_prox) {port_struct_init (port); +if (port->tx_ch ==CCCI_CONTROL_TX ) { + port_prox->ctl_port = port; + md->core_md.ctl_port = port; + } port->major = port_prox->major; port->minor_base = port_prox->minor_base;
drivers/net/wwan/t7xx/t7xx_port_proxy.h +4 -0
@@ -45,6 +45,7 @@ struct port_proxy {unsigned int major;unsigned int minor_base;struct t7xx_port *ports; +struct t7xx_port *ctl_port;struct t7xx_port *dedicated_ports[CLDMA_NUM ][MTK_MAX_QUEUE_NUM ];/* port list of each RX channel, for RX dispatching */ struct list_head rx_ch_ports[CCCI_MAX_CH_ID ];
@@ -80,6 +81,9 @@ 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 port_proxy_send_skb (struct t7xx_port *port,struct sk_buff *skb,bool from_pool);void port_proxy_set_seq_num (struct t7xx_port *port,struct ccci_header *ccci_h);int port_proxy_node_control (struct device *dev,struct port_msg *port_msg);
drivers/net/wwan/t7xx/t7xx_state_monitor.c +3 -0
@@ -334,6 +334,9 @@ static void fsm_routine_starting(struct ccci_fsm_ctl *ctl)if (!atomic_read (&md->core_md.ready)) {dev_err (dev,"MD handshake timeout\n" ); +if (atomic_read (&md->core_md.handshake_ongoing)) +fsm_append_event (ctl,CCCI_EVENT_MD_HS2_EXIT ,NULL ,0 ); +fsm_routine_exception (ctl,NULL ,EXCEPTION_HS_TIMEOUT ); }else {fsm_routine_ready (ctl);
Signature · 1 line
2.17.1
Sergey Ryazanov
maintainerRe: [PATCH v2 05/14] net: wwan: t7xx: Add control port
Quoted 8 lines · Ricardo Martinez
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]
drivers/net/wwan/t7xx/t7xx_modem_ops.c static void md_sys_sw_init(struct mtk_pci_dev *mtk_dev) · line 274
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c +2
-0+struct feature_query { +u32 head_pattern;
Looks like this field should be __le32 since it is sent to modem as is.
drivers/net/wwan/t7xx/t7xx_modem_ops.c static void md_sys_sw_init(struct mtk_pci_dev *mtk_dev) · line 276
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c +2
-0+u8 feature_set[FEATURE_COUNT ]; +u32 tail_pattern;
Ditto.
drivers/net/wwan/t7xx/t7xx_modem_ops.c static void md_sys_sw_init(struct mtk_pci_dev *mtk_dev) · line 313
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c +5
-0+}; + +static void prepare_host_rt_data_query (struct core_sys_info *core) +{ + ft_query->head_pattern =MD_FEATURE_QUERY_ID ;
This should be a
ft_query->head_pattern = cpu_to_le32(MD_FEATURE_QUERY_ID);
to run on the big-endians CPU. strace will notify you about each endians mismatch as soon as you change head_pattern field type to __le32.
drivers/net/wwan/t7xx/t7xx_modem_ops.c static void md_sys_sw_init(struct mtk_pci_dev *mtk_dev) · line 315
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c +2
-0+memcpy (ft_query->feature_set, core->feature_set,FEATURE_COUNT ); + ft_query->tail_pattern =MD_FEATURE_QUERY_ID ;
Ditto.
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_modem_ops.c +3
-0+/* send HS1 message to device */ +port_proxy_send_skb (core->ctl_port, skb,0 ); +}
[skipped]
drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c line 40
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c +4
-0+static void fsm_ee_message_handler (struct sk_buff *skb) +{ + ctrl_msg_h = (struct ctrl_msg_header *)skb->data; +switch (ctrl_msg_h->ctrl_msg_id) {
This should be:
switch (le32_to_cpu(ctrl_msg_h->ctrl_msg_id)) {drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c line 42
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c +2
-0+case CTL_ID_MD_EX : +if (ctrl_msg_h->reserved !=MD_EX_CHK_ID ) {
Why is this field called 'reserved', but used to perform message validation?
drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c line 78
Quoted 8 lines
...
drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c +5
-0+static void control_msg_handler (struct t7xx_port *port,struct sk_buff *skb) +{ +struct ctrl_msg_header *ctrl_msg_h; + ctrl_msg_h = (struct ctrl_msg_header *)skb->data; +switch (ctrl_msg_h->ctrl_msg_id) {
This should be something like this:
switch (le32_to_cpu(ctrl_msg_h->ctrl_msg_id)) {--
Sergey
Ricardo Martinez
reviewerPATCH v2 6/14 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.
--- drivers/net/wwan/t7xx/Makefile | 1 + drivers/net/wwan/t7xx/t7xx_port_proxy.c | 4 + drivers/net/wwan/t7xx/t7xx_port_proxy.h | 1 + drivers/net/wwan/t7xx/t7xx_port_wwan.c | 281 ++++++++++++++++++++++++ 4 files changed, 287 insertions(+) create mode 100644 drivers/net/wwan/t7xx/t7xx_port_wwan.c
drivers/net/wwan/t7xx/Makefile +1 -0
@@ -13,3 +13,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 +4 -0
@@ -51,6 +51,10 @@ static struct port_proxy *port_prox; i++, (p) = &(proxy)->ports[i])static struct t7xx_port md_ccci_ports[] = { + {CCCI_UART2_TX ,CCCI_UART2_RX ,DATA_AT_CMD_Q ,DATA_AT_CMD_Q ,0xff , +0xff ,ID_CLDMA1 ,PORT_F_RX_CHAR_NODE , &wwan_sub_port_ops,0 ,"ttyC0" ,WWAN_PORT_AT }, + {CCCI_MBIM_TX ,CCCI_MBIM_RX ,2 ,2 ,0 ,0 ,ID_CLDMA1 , +PORT_F_RX_CHAR_NODE , &wwan_sub_port_ops,10 ,"ttyCMBIM0" ,WWAN_PORT_MBIM }, {CCCI_CONTROL_TX ,CCCI_CONTROL_RX ,0 ,0 ,0 ,0 ,ID_CLDMA1 ,0 , &ctl_port_ops,0xff ,"ccci_ctrl" ,}, };
drivers/net/wwan/t7xx/t7xx_port_proxy.h +1 -0
@@ -82,6 +82,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 port_proxy_send_skb (struct t7xx_port *port,struct sk_buff *skb,bool from_pool);
drivers/net/wwan/t7xx/t7xx_port_wwan.c new file +281 -0
281 lines not on this page · raw message
Signature · 1 line
2.17.1
Sergey Ryazanov
maintainerRe: [PATCH v2 06/14] net: wwan: t7xx: Add AT and MBIM WWAN ports
drivers/net/wwan/t7xx/t7xx_port_proxy.c static struct port_proxy *port_prox;
Quoted 11 lines · Ricardo Martinez
...
static structt7xx_portmd_ccci_ports[] = {drivers/net/wwan/t7xx/t7xx_port_proxy.c +8
-0+ {CCCI_UART2_TX ,CCCI_UART2_RX ,DATA_AT_CMD_Q ,DATA_AT_CMD_Q ,0xff , + 0xff, ID_CLDMA1, PORT_F_RX_CHAR_NODE, &wwan_sub_port_ops, 0, "ttyC0", WWAN_PORT_AT}, + {CCCI_MBIM_TX, CCCI_MBIM_RX, 2, 2, 0, 0, ID_CLDMA1, + PORT_F_RX_CHAR_NODE, &wwan_sub_port_ops, 10, "ttyCMBIM0", WWAN_PORT_MBIM}, + if (count + CCCI_H_ELEN > txq_mtu && + (port_ccci->tx_ch ==CCCI_MBIM_TX || + (port_ccci->tx_ch >=CCCI_DSS0_TX && port_ccci->tx_ch <=CCCI_DSS7_TX ))) + multi_packet = DIV_ROUND_UP(count, txq_mtu - CCCI_H_ELEN);
I am just wondering, the chip does support MBIM message fragmentation, but does not support AT commands stream (CCCI_UART2_TX) fragmentation. Is that the correct conclusion from the code above?
BTW, you could factor out data fragmentation support to a dedicated function to improve code readability. Something like this:
static inline bool port_is_multipacket_capable(... *port)
{
return port->tx_ch == CCCI_MBIM_TX ||
(port->tx_ch >= CCCI_DSS0_TX && port->tx_ch <= CCCI_DSS7_TX);
}So condition become something like that:
if (count + CCCI_H_ELEN > txq_mtu &&
port_is_multipacket_capable(port))
multi_packet = DIV_ROUND_UP(count, txq_mtu - CCCI_H_ELEN);Signature · 1 line
Sergey
Martinez, Ricardo
reviewerRe: [PATCH v2 06/14] net: wwan: t7xx: Add AT and MBIM WWAN ports
Quoted 12 lines · Sergey Ryazanov
drivers/net/wwan/t7xx/t7xx_port_proxy.c static struct port_proxy *port_prox;
Quoted 11 lines · Ricardo Martinez
...
static structt7xx_portmd_ccci_ports[] = {drivers/net/wwan/t7xx/t7xx_port_proxy.c +8
-0+ {CCCI_UART2_TX ,CCCI_UART2_RX ,DATA_AT_CMD_Q ,DATA_AT_CMD_Q ,0xff , + 0xff, ID_CLDMA1, PORT_F_RX_CHAR_NODE, &wwan_sub_port_ops, 0, "ttyC0", WWAN_PORT_AT}, + {CCCI_MBIM_TX, CCCI_MBIM_RX, 2, 2, 0, 0, ID_CLDMA1, + PORT_F_RX_CHAR_NODE, &wwan_sub_port_ops, 10, "ttyCMBIM0", WWAN_PORT_MBIM}, + if (count + CCCI_H_ELEN > txq_mtu && + (port_ccci->tx_ch ==CCCI_MBIM_TX || + (port_ccci->tx_ch >=CCCI_DSS0_TX && port_ccci->tx_ch <=CCCI_DSS7_TX ))) + multi_packet = DIV_ROUND_UP(count, txq_mtu - CCCI_H_ELEN);
Quoted 3 lines
I am just wondering, the chip does support MBIM message fragmentation, but does not support AT commands stream (
CCCI_UART2_TX) fragmentation. Is that the correct conclusion from the code above?
Yes, that is correct.
Quoted 10 lines
BTW, you could factor out data fragmentation support to a dedicated function to improve code readability. Something like this:
static inline bool port_is_multipacket_capable(... *port)
{ return port->tx_ch == CCCI_MBIM_TX || (port->tx_ch >= CCCI_DSS0_TX && port->tx_ch <= CCCI_DSS7_TX); }
Quoted 5 lines
So condition become something like that:
if (count + CCCI_H_ELEN > txq_mtu && port_is_multipacket_capable(port)) multi_packet = DIV_ROUND_UP(count, txq_mtu - CCCI_H_ELEN);
Ricardo
Sergey Ryazanov
maintainerRe: [PATCH v2 06/14] net: wwan: t7xx: Add AT and MBIM WWAN ports
Hello Ricardo,
Quoted 14 lines · Ricardo
Quoted 13 lines · Sergey Ryazanov
Quoted 11 lines · Ricardo Martinez
...
static structt7xx_portmd_ccci_ports[] = {drivers/net/wwan/t7xx/t7xx_port_proxy.c +8
-0+ {CCCI_UART2_TX ,CCCI_UART2_RX ,DATA_AT_CMD_Q ,DATA_AT_CMD_Q ,0xff , + 0xff, ID_CLDMA1, PORT_F_RX_CHAR_NODE, &wwan_sub_port_ops, 0, "ttyC0", WWAN_PORT_AT}, + {CCCI_MBIM_TX, CCCI_MBIM_RX, 2, 2, 0, 0, ID_CLDMA1, + PORT_F_RX_CHAR_NODE, &wwan_sub_port_ops, 10, "ttyCMBIM0", WWAN_PORT_MBIM}, + if (count + CCCI_H_ELEN > txq_mtu && + (port_ccci->tx_ch ==CCCI_MBIM_TX || + (port_ccci->tx_ch >=CCCI_DSS0_TX && port_ccci->tx_ch <=CCCI_DSS7_TX ))) + multi_packet = DIV_ROUND_UP(count, txq_mtu - CCCI_H_ELEN);
Quoted 5 lines
Quoted 3 lines
I am just wondering, the chip does support MBIM message fragmentation, but does not support AT commands stream (
CCCI_UART2_TX) fragmentation. Is that the correct conclusion from the code above?Yes, that is correct.
Are you sure that the modem does not support AT command fragmentation? The AT commands interface is a stream of chars by its nature. It is designed to work over serial lines. Some modem configuration software even writes commands to a port in a char-by-char manner, i.e. it writes no more than one char at a time to the port.
The mechanism that is implemented in the driver to split user input into individual messages is not a true fragmentation mechanism since it does not preserve the original user input length. It just cuts the user input into individual messages and sends them to the modem independently. So, the modem firmware has no way to distinguish whether the user input has been "fragmented" by the user or the driver. How, then, does the modem firmware deal with an AT command "fragmented" by a user? Will the modem firmware ignore the AT command that is received in the char-by-char manner?
Signature · 1 line
Sergey
Martinez, Ricardo
reviewerRe: [PATCH v2 06/14] net: wwan: t7xx: Add AT and MBIM WWAN ports
Quoted 27 lines · Sergey Ryazanov
Hello Ricardo,
Quoted 13 lines · Ricardo
Quoted 12 lines · Sergey Ryazanov
Quoted 11 lines · Ricardo Martinez
...
static structt7xx_portmd_ccci_ports[] = {drivers/net/wwan/t7xx/t7xx_port_proxy.c +8
-0+ {CCCI_UART2_TX ,CCCI_UART2_RX ,DATA_AT_CMD_Q ,DATA_AT_CMD_Q ,0xff , + 0xff, ID_CLDMA1, PORT_F_RX_CHAR_NODE, &wwan_sub_port_ops, 0, "ttyC0", WWAN_PORT_AT}, + {CCCI_MBIM_TX, CCCI_MBIM_RX, 2, 2, 0, 0, ID_CLDMA1, + PORT_F_RX_CHAR_NODE, &wwan_sub_port_ops, 10, "ttyCMBIM0", WWAN_PORT_MBIM}, + if (count + CCCI_H_ELEN > txq_mtu && + (port_ccci->tx_ch ==CCCI_MBIM_TX || + (port_ccci->tx_ch >=CCCI_DSS0_TX && port_ccci->tx_ch <=CCCI_DSS7_TX ))) + multi_packet = DIV_ROUND_UP(count, txq_mtu - CCCI_H_ELEN);Quoted 4 lines
Quoted 3 lines
I am just wondering, the chip does support MBIM message fragmentation, but does not support AT commands stream (
CCCI_UART2_TX) fragmentation. Is that the correct conclusion from the code above?Yes, that is correct.
Are you sure that the modem does not support AT command fragmentation? The AT commands interface is a stream of chars by its nature. It is designed to work over serial lines. Some modem configuration software even writes commands to a port in a char-by-char manner, i.e. it writes no more than one char at a time to the port.
Quoted 9 lines
The mechanism that is implemented in the driver to split user input into individual messages is not a true fragmentation mechanism since it does not preserve the original user input length. It just cuts the user input into individual messages and sends them to the modem independently. So, the modem firmware has no way to distinguish whether the user input has been "fragmented" by the user or the driver. How, then, does the modem firmware deal with an AT command "fragmented" by a user? Will the modem firmware ignore the AT command that is received in the char-by-char manner?
The modem supports char-by-char AT command over serial lines, I'll get more information
about why splitting long commands is supported only for MBIM and not for AT commands.
Martinez, Ricardo
reviewerRe: [PATCH v2 06/14] net: wwan: t7xx: Add AT and MBIM WWAN ports
Hi Sergey,
Quoted 44 lines · Ricardo
Quoted 32 lines · Sergey Ryazanov
Hello Ricardo,
Quoted 18 lines · Ricardo
Quoted 17 lines · Sergey Ryazanov
Quoted 16 lines · Ricardo Martinez
...
static structt7xx_portmd_ccci_ports[] = {
+ {CCCI_UART2_TX,CCCI_UART2_RX,DATA_AT_CMD_Q,DATA_AT_CMD_Q,0xff,
+0xff,ID_CLDMA1,PORT_F_RX_CHAR_NODE,&wwan_sub_port_ops, 0, "ttyC0",WWAN_PORT_AT},
+ {CCCI_MBIM_TX,CCCI_MBIM_RX, 2, 2, 0, 0,ID_CLDMA1, +PORT_F_RX_CHAR_NODE,&wwan_sub_port_ops, 10, "ttyCMBIM0",WWAN_PORT_MBIM},
...
+ if (count +CCCI_H_ELEN>txq_mtu&&
+ (port_ccci->tx_ch==CCCI_MBIM_TX|| + (port_ccci->tx_ch>=CCCI_DSS0_TX&&port_ccci->tx_ch<=CCCI_DSS7_TX)))
+multi_packet= DIV_ROUND_UP(count,txq_mtu
-CCCI_H_ELEN);Quoted 4 lines
Quoted 3 lines
I am just wondering, the chip does support MBIM message fragmentation, but does not support AT commands stream (
CCCI_UART2_TX) fragmentation. Is that the correct conclusion from the code above?Yes, that is correct.
Are you sure that the modem does not support AT command fragmentation? The AT commands interface is a stream of chars by its nature. It is designed to work over serial lines. Some modem configuration software even writes commands to a port in a char-by-char manner, i.e. it writes no more than one char at a time to the port.
Quoted 9 lines
The mechanism that is implemented in the driver to split user input into individual messages is not a true fragmentation mechanism since it does not preserve the original user input length. It just cuts the user input into individual messages and sends them to the modem independently. So, the modem firmware has no way to distinguish whether the user input has been "fragmented" by the user or the driver. How, then, does the modem firmware deal with an AT command "fragmented" by a user? Will the modem firmware ignore the AT command that is received in the char-by-char manner?
Quoted 4 lines
The modem supports char-by-char AT command over serial lines, I'll get more information
about why splitting long commands is supported only for MBIM and not for AT commands.
The next version will allow AT command fragmentation as there is modem is able to handle
fragments as you pointed out. This will make the WWAN Tx callback a bit simpler.
Ricardo Martinez
reviewerPATCH v2 7/14 net: wwan: t7xx: Data path HW layer
In reply to Ricardo MartinezFrom: Haijun Lio <[email protected]>
Data Path Modem AP Interface (DPMAIF) HW layer provides HW abstraction for the upper layer (DPMAIF HIF). It implements functions to do the HW configuration, TX/RX control and interrupt handling.
--- drivers/net/wwan/t7xx/t7xx_dpmaif.c | 1524 +++++++++++++++++++++++++++ drivers/net/wwan/t7xx/t7xx_dpmaif.h | 168 +++ 2 files changed, 1692 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 +1524 -0
@@ -0,0 +1,1524 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) 2021, MediaTek Inc. +* Copyright (c) 2021, Intel Corporation. +* +* Authors: Haijun Lio <[email protected]> +* Contributors: Amir Hanania <[email protected]> +* Andy Shevchenko <[email protected]> +* Chiranjeevi Rapolu <[email protected]> +* Eliot Lee <[email protected]> +* Moises Veleta <[email protected]> +* Ricardo Martinez<[email protected]> +* Sreehari Kancharla <[email protected]> +*/ + +#include <linux/bitfield.h> +#include <linux/bitops.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/iopoll.h> +#include <linux/kernel.h> + +#include "t7xx_dpmaif.h" +#include "t7xx_reg.h" + +static int dpmaif_init_intr (struct dpmaif_hw_info *hw_info) +{ +struct dpmaif_isr_en_mask *isr_en_msk; +u32 value, l2intr_en, l2intr_err_en; +int ret; + + isr_en_msk = &hw_info->isr_en_mask; + +/* set UL interrupt */ + l2intr_en =DPMAIF_UL_INT_ERR_MSK |DPMAIF_UL_INT_QDONE_MSK ; + isr_en_msk->ap_ul_l2intr_en_msk = l2intr_en; + +iowrite32 (DPMAIF_AP_ALL_L2TISAR0_MASK , hw_info->pcie_base +DPMAIF_AP_L2TISAR0 ); + +/* set interrupt enable mask */ +iowrite32 (l2intr_en, hw_info->pcie_base +DPMAIF_AO_UL_AP_L2TIMCR0 ); +iowrite32 (~l2intr_en, hw_info->pcie_base +DPMAIF_AO_UL_AP_L2TIMSR0 ); + +/* check mask status */ + ret =readx_poll_timeout_atomic (ioread32, + hw_info->pcie_base +DPMAIF_AO_UL_AP_L2TIMR0 , + value, (value & l2intr_en) != l2intr_en, +0 ,DPMAIF_CHECK_INIT_TIMEOUT_US ); +if (ret) +return ret; + +/* set DL interrupt */ + l2intr_err_en =DPMAIF_DL_INT_PITCNT_LEN_ERR |DPMAIF_DL_INT_BATCNT_LEN_ERR ; + isr_en_msk->ap_dl_l2intr_err_en_msk = l2intr_err_en; + + l2intr_en =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 = l2intr_en; + +iowrite32 (DPMAIF_AP_APDL_ALL_L2TISAR0_MASK , hw_info->pcie_base +DPMAIF_AP_APDL_L2TISAR0 ); + +/* set DL ISR PD enable mask */ +iowrite32 (~l2intr_en, hw_info->pcie_base +DPMAIF_AO_UL_APDL_L2TIMSR0 ); + +/* check mask status */ + ret =readx_poll_timeout_atomic (ioread32, + hw_info->pcie_base +DPMAIF_AO_UL_APDL_L2TIMR0 , + value, (value & l2intr_en) != l2intr_en, +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 dpmaif_mask_ulq_interrupt (struct dpmaif_ctrl *dpmaif_ctrl,unsigned int q_num) +{ +struct dpmaif_isr_en_mask *isr_en_msk; +struct dpmaif_hw_info *hw_info; +u32 value, ul_int_que_done; +int ret; + + hw_info = &dpmaif_ctrl->hif_hw_info; + isr_en_msk = &hw_info->isr_en_mask; + ul_int_que_done =BIT (q_num + _UL_INT_DONE_OFFSET) &DPMAIF_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 ); + +/* check mask status */ + ret =readx_poll_timeout_atomic (ioread32, + hw_info->pcie_base +DPMAIF_AO_UL_AP_L2TIMR0 , + value, (value & ul_int_que_done) == ul_int_que_done, +0 ,DPMAIF_CHECK_TIMEOUT_US ); +if (ret) +dev_err (dpmaif_ctrl->dev, +"Could not mask the UL interrupt. DPMAIF_AO_UL_AP_L2TIMR0 is 0x%x\n" , + value); +} + +void dpmaif_unmask_ulq_interrupt (struct dpmaif_ctrl *dpmaif_ctrl,unsigned int q_num) +{ +struct dpmaif_isr_en_mask *isr_en_msk; +struct dpmaif_hw_info *hw_info; +u32 value, ul_int_que_done; +int ret; + + hw_info = &dpmaif_ctrl->hif_hw_info; + isr_en_msk = &hw_info->isr_en_mask; + ul_int_que_done =BIT (q_num + _UL_INT_DONE_OFFSET) &DPMAIF_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 ); + +/* check mask status */ + ret =readx_poll_timeout_atomic (ioread32, + hw_info->pcie_base +DPMAIF_AO_UL_AP_L2TIMR0 , + value, (value & ul_int_que_done) != ul_int_que_done, +0 ,DPMAIF_CHECK_TIMEOUT_US ); +if (ret) +dev_err (dpmaif_ctrl->dev, +"Could not unmask the UL interrupt. DPMAIF_AO_UL_AP_L2TIMR0 is 0x%x\n" , + value); +} + +static void dpmaif_mask_dl_batcnt_len_err_interrupt (struct dpmaif_hw_info *hw_info) +{ + hw_info->isr_en_mask.ap_dl_l2intr_en_msk &= ~DPMAIF_DL_INT_BATCNT_LEN_ERR ; +iowrite32 (DPMAIF_DL_INT_BATCNT_LEN_ERR , + hw_info->pcie_base +DPMAIF_AO_UL_APDL_L2TIMSR0 ); +} + +void dpmaif_unmask_dl_batcnt_len_err_interrupt (struct dpmaif_hw_info *hw_info) +{ + hw_info->isr_en_mask.ap_dl_l2intr_en_msk |=DPMAIF_DL_INT_BATCNT_LEN_ERR ; +iowrite32 (DPMAIF_DL_INT_BATCNT_LEN_ERR , + hw_info->pcie_base +DPMAIF_AO_UL_APDL_L2TIMCR0 ); +} + +static void dpmaif_mask_dl_pitcnt_len_err_interrupt (struct dpmaif_hw_info *hw_info) +{ + hw_info->isr_en_mask.ap_dl_l2intr_en_msk &= ~DPMAIF_DL_INT_PITCNT_LEN_ERR ; +iowrite32 (DPMAIF_DL_INT_PITCNT_LEN_ERR , + hw_info->pcie_base +DPMAIF_AO_UL_APDL_L2TIMSR0 ); +} + +void dpmaif_unmask_dl_pitcnt_len_err_interrupt (struct dpmaif_hw_info *hw_info) +{ + hw_info->isr_en_mask.ap_dl_l2intr_en_msk |=DPMAIF_DL_INT_PITCNT_LEN_ERR ; +iowrite32 (DPMAIF_DL_INT_PITCNT_LEN_ERR , + hw_info->pcie_base +DPMAIF_AO_UL_APDL_L2TIMCR0 ); +} + +static u32 update_dlq_interrupt (struct dpmaif_hw_info *hw_info,u32 q_done) +{ +u32 value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_UL_AP_L2TIMR0 ); +iowrite32 (q_done, hw_info->pcie_base +DPMAIF_AO_UL_APDL_L2TIMSR0 ); + +return value; +} + +static int mask_dlq_interrupt (struct dpmaif_ctrl *dpmaif_ctrl,unsigned char qno) +{ +struct dpmaif_hw_info *hw_info; +u32 value, q_done; +int ret; + + hw_info = &dpmaif_ctrl->hif_hw_info; + 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 ); + +/* check mask status */ + ret =read_poll_timeout_atomic (update_dlq_interrupt, value, value & q_done, +0 ,DPMAIF_CHECK_TIMEOUT_US , false, hw_info, q_done); +if (ret) { +dev_err (dpmaif_ctrl->dev,"mask_dl_dlq0 check timeout\n" ); +return -ETIMEDOUT ; + } + + hw_info->isr_en_mask.ap_dl_l2intr_en_msk &= ~q_done; + +return 0 ; +} + +void dpmaif_hw_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 dpmaif_clr_ip_busy_sts (struct dpmaif_hw_info *hw_info) +{ +u32 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 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 dpmaif_dlq_unmask_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_L2TIMCR0 ); +else +iowrite32 (DPMAIF_DL_INT_DLQ1_PITCNT_LEN , + hw_info->pcie_base +DPMAIF_AO_UL_APDL_L2TIMCR0 ); +} + +void dpmaif_clr_ul_all_interrupt (struct dpmaif_hw_info *hw_info) +{ +iowrite32 (DPMAIF_AP_ALL_L2TISAR0_MASK , hw_info->pcie_base +DPMAIF_AP_L2TISAR0 ); +} + +void dpmaif_clr_dl_all_interrupt (struct dpmaif_hw_info *hw_info) +{ +iowrite32 (DPMAIF_AP_APDL_ALL_L2TISAR0_MASK , hw_info->pcie_base +DPMAIF_AP_APDL_L2TISAR0 ); +} + +/* para->intr_cnt counter is set to zero before this function is called. +* it is not check for overflow as there is no risk of overflowing intr_types or intr_queues. +*/ +static void dpmaif_hw_check_tx_interrupt (struct dpmaif_ctrl *dpmaif_ctrl, +unsigned int l2_txisar0, +struct dpmaif_hw_intr_st_para *para) +{ +unsigned int index; +unsigned int value; + + value = l2_txisar0 &DP_UL_INT_QDONE_MSK ; +if (value) { +unsigned long pending = (value >>DP_UL_INT_DONE_OFFSET ) &DP_UL_QNUM_MSK ; + + para->intr_types[para->intr_cnt] =DPF_INTR_UL_DONE ; + para->intr_queues[para->intr_cnt] = pending; + +/* mask TX queue interrupt immediately after it occurs */ +for_each_set_bit (index, &pending,DPMAIF_TXQ_NUM ) +dpmaif_mask_ulq_interrupt (dpmaif_ctrl, index); + + para->intr_cnt++; + } + + value = l2_txisar0 &DP_UL_INT_EMPTY_MSK ; +if (value) { + para->intr_types[para->intr_cnt] =DPF_INTR_UL_DRB_EMPTY ; + para->intr_queues[para->intr_cnt] = + (value >>DP_UL_INT_EMPTY_OFFSET ) &DP_UL_QNUM_MSK ; + para->intr_cnt++; + } + + value = l2_txisar0 &DP_UL_INT_MD_NOTREADY_MSK ; +if (value) { + para->intr_types[para->intr_cnt] =DPF_INTR_UL_MD_NOTREADY ; + para->intr_queues[para->intr_cnt] = + (value >>DP_UL_INT_MD_NOTRDY_OFFSET ) &DP_UL_QNUM_MSK ; + para->intr_cnt++; + } + + value = l2_txisar0 &DP_UL_INT_MD_PWR_NOTREADY_MSK ; +if (value) { + para->intr_types[para->intr_cnt] =DPF_INTR_UL_MD_PWR_NOTREADY ; + para->intr_queues[para->intr_cnt] = + (value >>DP_UL_INT_PWR_NOTRDY_OFFSET ) &DP_UL_QNUM_MSK ; + para->intr_cnt++; + } + + value = l2_txisar0 &DP_UL_INT_ERR_MSK ; +if (value) { + para->intr_types[para->intr_cnt] =DPF_INTR_UL_LEN_ERR ; + para->intr_queues[para->intr_cnt] = + (value >>DP_UL_INT_LEN_ERR_OFFSET ) &DP_UL_QNUM_MSK ; + para->intr_cnt++; + } +} + +/* para->intr_cnt counter is set to zero before this function is called. +* it is not check for overflow as there is no risk of overflowing intr_types or intr_queues. +*/ +static void dpmaif_hw_check_rx_interrupt (struct dpmaif_ctrl *dpmaif_ctrl, +unsigned int *pl2_rxisar0, +struct dpmaif_hw_intr_st_para *para, +int qno) +{ +unsigned int l2_rxisar0 = *pl2_rxisar0; +struct dpmaif_hw_info *hw_info; +unsigned int value; + + hw_info = &dpmaif_ctrl->hif_hw_info; + +if (qno ==DPF_RX_QNO_DFT ) { + value = l2_rxisar0 &DP_DL_INT_SKB_LEN_ERR ; +if (value) { + para->intr_types[para->intr_cnt] =DPF_INTR_DL_SKB_LEN_ERR ; + para->intr_queues[para->intr_cnt] =DPF_RX_QNO_DFT ; + para->intr_cnt++; + } + + value = l2_rxisar0 &DP_DL_INT_BATCNT_LEN_ERR ; +if (value) { + para->intr_types[para->intr_cnt] =DPF_INTR_DL_BATCNT_LEN_ERR ; + para->intr_queues[para->intr_cnt] =DPF_RX_QNO_DFT ; + para->intr_cnt++; + +dpmaif_mask_dl_batcnt_len_err_interrupt (hw_info); + } + + value = l2_rxisar0 &DP_DL_INT_PITCNT_LEN_ERR ; +if (value) { + para->intr_types[para->intr_cnt] =DPF_INTR_DL_PITCNT_LEN_ERR ; + para->intr_queues[para->intr_cnt] =DPF_RX_QNO_DFT ; + para->intr_cnt++; + +dpmaif_mask_dl_pitcnt_len_err_interrupt (hw_info); + } + + value = l2_rxisar0 &DP_DL_INT_PKT_EMPTY_MSK ; +if (value) { + para->intr_types[para->intr_cnt] =DPF_INTR_DL_PKT_EMPTY_SET ; + para->intr_queues[para->intr_cnt] =DPF_RX_QNO_DFT ; + para->intr_cnt++; + } + + value = l2_rxisar0 &DP_DL_INT_FRG_EMPTY_MSK ; +if (value) { + para->intr_types[para->intr_cnt] =DPF_INTR_DL_FRG_EMPTY_SET ; + para->intr_queues[para->intr_cnt] =DPF_RX_QNO_DFT ; + para->intr_cnt++; + } + + value = l2_rxisar0 &DP_DL_INT_MTU_ERR_MSK ; +if (value) { + para->intr_types[para->intr_cnt] =DPF_INTR_DL_MTU_ERR ; + para->intr_queues[para->intr_cnt] =DPF_RX_QNO_DFT ; + para->intr_cnt++; + } + + value = l2_rxisar0 &DP_DL_INT_FRG_LENERR_MSK ; +if (value) { + para->intr_types[para->intr_cnt] =DPF_INTR_DL_FRGCNT_LEN_ERR ; + para->intr_queues[para->intr_cnt] =DPF_RX_QNO_DFT ; + para->intr_cnt++; + } + + value = l2_rxisar0 &DP_DL_INT_DLQ0_PITCNT_LEN_ERR ; +if (value) { + para->intr_types[para->intr_cnt] =DPF_DL_INT_DLQ0_PITCNT_LEN_ERR ; + para->intr_queues[para->intr_cnt] =BIT (qno); + para->intr_cnt++; + +dpmaif_dlq_mask_rx_pitcnt_len_err_intr (hw_info, qno); + } + + value = l2_rxisar0 &DP_DL_INT_HPC_ENT_TYPE_ERR ; +if (value) { + para->intr_types[para->intr_cnt] =DPF_DL_INT_HPC_ENT_TYPE_ERR ; + para->intr_queues[para->intr_cnt] =DPF_RX_QNO_DFT ; + para->intr_cnt++; + } + + value = l2_rxisar0 &DP_DL_INT_DLQ0_QDONE_SET ; +if (value) { +/* mask RX done interrupt immediately after it occurs */ +if (!mask_dlq_interrupt (dpmaif_ctrl, qno)) { + para->intr_types[para->intr_cnt] =DPF_INTR_DL_DLQ0_DONE ; + para->intr_queues[para->intr_cnt] =BIT (qno); + para->intr_cnt++; + }else { +/* Unable to clear the interrupt, try again on the next one +* device entered low power mode or suffer exception +*/ + *pl2_rxisar0 = l2_rxisar0 & ~DP_DL_INT_DLQ0_QDONE_SET ; + } + } + }else { + value = l2_rxisar0 &DP_DL_INT_DLQ1_PITCNT_LEN_ERR ; +if (value) { + para->intr_types[para->intr_cnt] =DPF_DL_INT_DLQ1_PITCNT_LEN_ERR ; + para->intr_queues[para->intr_cnt] =BIT (qno); + para->intr_cnt++; + +dpmaif_dlq_mask_rx_pitcnt_len_err_intr (hw_info, qno); + } + + value = l2_rxisar0 &DP_DL_INT_DLQ1_QDONE_SET ; +if (value) { +/* mask RX done interrupt immediately after it occurs */ +if (!mask_dlq_interrupt (dpmaif_ctrl, qno)) { + para->intr_types[para->intr_cnt] =DPF_INTR_DL_DLQ1_DONE ; + para->intr_queues[para->intr_cnt] =BIT (qno); + para->intr_cnt++; + }else { +/* Unable to clear the interrupt, try again on the next one +* device entered low power mode or suffer exception +*/ + *pl2_rxisar0 = l2_rxisar0 & ~DP_DL_INT_DLQ1_QDONE_SET ; + } + } + } +} + +/** +* dpmaif_hw_get_interrupt_status() - Gets interrupt status from HW +* @dpmaif_ctrl: Pointer to struct dpmaif_ctrl +* @para: Pointer to struct dpmaif_hw_intr_st_para +* @qno: Queue number +* +* Gets RX/TX interrupt and checks DL/UL interrupt status. +* Clears interrupt statuses if needed. +* +* Return: Interrupt Count +*/ +int dpmaif_hw_get_interrupt_status (struct dpmaif_ctrl *dpmaif_ctrl, +struct dpmaif_hw_intr_st_para *para,int qno) +{ +struct dpmaif_hw_info *hw_info; +u32 l2_ri_sar0, l2_ti_sar0 =0 ; +u32 l2_rim_r0, l2_tim_r0 =0 ; + + hw_info = &dpmaif_ctrl->hif_hw_info; + +/* get RX interrupt status from HW */ + l2_ri_sar0 =ioread32 (hw_info->pcie_base +DPMAIF_AP_APDL_L2TISAR0 ); + l2_rim_r0 =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. +*/ + l2_ti_sar0 =ioread32 (hw_info->pcie_base +DPMAIF_AP_L2TISAR0 ); + l2_tim_r0 =ioread32 (hw_info->pcie_base +DPMAIF_AO_UL_AP_L2TIMR0 ); + } + +/* clear IP busy register wake up CPU case */ +dpmaif_clr_ip_busy_sts (hw_info); + +/* check UL interrupt status */ +if (qno ==DPF_RX_QNO_DFT ) { +/* Do not schedule bottom half again or clear UL +* interrupt status when we have already masked it. +*/ + l2_ti_sar0 &= ~l2_tim_r0; +if (l2_ti_sar0) { +dpmaif_hw_check_tx_interrupt (dpmaif_ctrl, l2_ti_sar0, para); + +/* clear interrupt status */ +iowrite32 (l2_ti_sar0, hw_info->pcie_base +DPMAIF_AP_L2TISAR0 ); + } + } + +/* check DL interrupt status */ +if (l2_ri_sar0) { +if (qno ==DPF_RX_QNO0 ) { + l2_ri_sar0 &=DP_DL_DLQ0_STATUS_MASK ; + +if (l2_rim_r0 &DPMAIF_DL_INT_DLQ0_QDONE ) +/* Do not schedule bottom half again or clear DL +* queue done interrupt status when we have already masked it. +*/ + l2_ri_sar0 &= ~DP_DL_INT_DLQ0_QDONE_SET ; + }else { + l2_ri_sar0 &=DP_DL_DLQ1_STATUS_MASK ; + +if (l2_rim_r0 &DPMAIF_DL_INT_DLQ1_QDONE ) +/* Do not schedule bottom half again or clear DL +* queue done interrupt status when we have already masked it. +*/ + l2_ri_sar0 &= ~DP_DL_INT_DLQ1_QDONE_SET ; + } + +/* have interrupt event */ +if (l2_ri_sar0) { +dpmaif_hw_check_rx_interrupt (dpmaif_ctrl, &l2_ri_sar0, para, qno); +/* always clear BATCNT_ERR */ + l2_ri_sar0 |=DP_DL_INT_BATCNT_LEN_ERR ; + +/* clear interrupt status */ +iowrite32 (l2_ri_sar0, hw_info->pcie_base +DPMAIF_AP_APDL_L2TISAR0 ); + } + } + +return para->intr_cnt; +} + +static int dpmaif_sram_init (struct dpmaif_hw_info *hw_info) +{ +u32 value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AP_MEM_CLR ); + value |=DPMAIF_MEM_CLR ; +iowrite32 (value, hw_info->pcie_base +DPMAIF_AP_MEM_CLR ); + +return readx_poll_timeout_atomic (ioread32, + hw_info->pcie_base +DPMAIF_AP_MEM_CLR , + value, !(value &DPMAIF_MEM_CLR ), +0 ,DPMAIF_CHECK_INIT_TIMEOUT_US ); +} + +static void 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 dpmaif_hw_config (struct dpmaif_hw_info *hw_info) +{ +unsigned int value; +int ret; + +dpmaif_hw_reset (hw_info); + ret =dpmaif_sram_init (hw_info); +if (ret) +return ret; + +/* Set DPMAIF AP port mode */ + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_RDY_CHK_THRES ); + value |=DPMAIF_PORT_MODE_PCIE ; +iowrite32 (value, hw_info->pcie_base +DPMAIF_AO_DL_RDY_CHK_THRES ); + +iowrite32 (DPMAIF_CG_EN , hw_info->pcie_base +DPMAIF_AP_CG_EN ); + +return 0 ; +} + +static inline void 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 dpmaif_dl_performance (struct dpmaif_hw_info *hw_info) +{ +unsigned int value; + +/* BAT cache enable */ + value =ioread32 (hw_info->pcie_base +DPMAIF_DL_BAT_INIT_CON1 ); + value |=DPMAIF_DL_BAT_CACHE_PRI ; +iowrite32 (value, hw_info->pcie_base +DPMAIF_DL_BAT_INIT_CON1 ); + +/* PIT burst enable */ + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_RDY_CHK_THRES ); + value |=DPMAIF_DL_BURST_PIT_EN ; +iowrite32 (value, hw_info->pcie_base +DPMAIF_AO_DL_RDY_CHK_THRES ); +} + +static void dpmaif_common_hw_init (struct dpmaif_hw_info *hw_info) +{ +dpmaif_pcie_dpmaif_sign (hw_info); +dpmaif_dl_performance (hw_info); +} + +/* DPMAIF DL DLQ part HW setting */ + +static inline void dpmaif_hw_hpc_cntl_set (struct dpmaif_hw_info *hw_info) +{ +unsigned int value; + + value =DPMAIF_HPC_DLQ_PATH_MODE |DPMAIF_HPC_ADD_MODE_DF <<2 ; + value |=DPMAIF_HASH_PRIME_DF <<4 ; + value |=DPMAIF_HPC_TOTAL_NUM <<8 ; +iowrite32 (value, hw_info->pcie_base +DPMAIF_AO_DL_HPC_CNTL ); +} + +static inline void dpmaif_hw_agg_cfg_set (struct dpmaif_hw_info *hw_info) +{ +unsigned int value; + + value =DPMAIF_AGG_MAX_LEN_DF |DPMAIF_AGG_TBL_ENT_NUM_DF <<16 ; +iowrite32 (value, hw_info->pcie_base +DPMAIF_AO_DL_DLQ_AGG_CFG ); +} + +static inline void dpmaif_hw_hash_bit_choose_set (struct dpmaif_hw_info *hw_info) +{ +iowrite32 (DPMAIF_DLQ_HASH_BIT_CHOOSE_DF , + hw_info->pcie_base +DPMAIF_AO_DL_DLQPIT_INIT_CON5 ); +} + +static inline void 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 dpmaif_hw_dlq_timeout_thres_set (struct dpmaif_hw_info *hw_info) +{ +unsigned int value, i; + +/* each registers holds two DLQ threshold timeout values */ +for (i =0 ; i <DPMAIF_HPC_MAX_TOTAL_NUM /2 ; i++) { + value =FIELD_PREP (DPMAIF_DLQ_LOW_TIMEOUT_THRES_MKS ,DPMAIF_DLQ_TIMEOUT_THRES_DF ); + value |=FIELD_PREP (DPMAIF_DLQ_HIGH_TIMEOUT_THRES_MSK , +DPMAIF_DLQ_TIMEOUT_THRES_DF ); +iowrite32 (value, + hw_info->pcie_base +DPMAIF_AO_DL_DLQPIT_TIMEOUT1 +sizeof (u32) * i); + } +} + +static inline void 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 dpmaif_dl_dlq_hpc_hw_init (struct dpmaif_hw_info *hw_info) +{ +dpmaif_hw_hpc_cntl_set (hw_info); +dpmaif_hw_agg_cfg_set (hw_info); +dpmaif_hw_hash_bit_choose_set (hw_info); +dpmaif_hw_mid_pit_timeout_thres_set (hw_info); +dpmaif_hw_dlq_timeout_thres_set (hw_info); +dpmaif_hw_dlq_start_prs_thres_set (hw_info); +} + +static int dpmaif_dl_bat_init_done (struct dpmaif_ctrl *dpmaif_ctrl, +unsigned char q_num,bool frg_en) +{ +struct dpmaif_hw_info *hw_info; +u32 value, dl_bat_init =0 ; +int ret; + + hw_info = &dpmaif_ctrl->hif_hw_info; + +if (frg_en) + dl_bat_init =DPMAIF_DL_BAT_FRG_INIT ; + + dl_bat_init |=DPMAIF_DL_BAT_INIT_ALLSET ; + dl_bat_init |=DPMAIF_DL_BAT_INIT_EN ; + + ret =readx_poll_timeout_atomic (ioread32, + hw_info->pcie_base +DPMAIF_DL_BAT_INIT , + value, !(value &DPMAIF_DL_BAT_INIT_NOT_READY ), +0 ,DPMAIF_CHECK_INIT_TIMEOUT_US ); +if (ret) { +dev_err (dpmaif_ctrl->dev,"data plane modem DL BAT is not ready\n" ); +return ret; + } + +iowrite32 (dl_bat_init, hw_info->pcie_base +DPMAIF_DL_BAT_INIT ); + + ret =readx_poll_timeout_atomic (ioread32, + hw_info->pcie_base +DPMAIF_DL_BAT_INIT , + value, !(value &DPMAIF_DL_BAT_INIT_NOT_READY ), +0 ,DPMAIF_CHECK_INIT_TIMEOUT_US ); +if (ret) +dev_err (dpmaif_ctrl->dev,"data plane modem DL BAT initialization failed\n" ); + +return ret; +} + +static void 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 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 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 dpmaif_dl_set_ao_bid_maxcnt (struct dpmaif_hw_info *hw_info, +unsigned char q_num,unsigned int cnt) +{ +unsigned int value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_PKTINFO_CON0 ); + value &= ~DPMAIF_BAT_BID_MAXCNT_MSK ; + value |=FIELD_PREP (DPMAIF_BAT_BID_MAXCNT_MSK , cnt); +iowrite32 (value, hw_info->pcie_base +DPMAIF_AO_DL_PKTINFO_CON0 ); +} + +static inline void dpmaif_dl_set_ao_mtu (struct dpmaif_hw_info *hw_info,unsigned int mtu_sz) +{ +iowrite32 (mtu_sz, hw_info->pcie_base +DPMAIF_AO_DL_PKTINFO_CON1 ); +} + +static void dpmaif_dl_set_ao_pit_chknum (struct dpmaif_hw_info *hw_info,unsigned char q_num, +unsigned int number) +{ +unsigned int value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_PKTINFO_CON2 ); + value &= ~DPMAIF_PIT_CHK_NUM_MSK ; + value |=FIELD_PREP (DPMAIF_PIT_CHK_NUM_MSK , number); +iowrite32 (value, hw_info->pcie_base +DPMAIF_AO_DL_PKTINFO_CON2 ); +} + +static void dpmaif_dl_set_ao_remain_minsz (struct dpmaif_hw_info *hw_info,unsigned char q_num, +size_t min_sz) +{ +unsigned int value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_PKTINFO_CON0 ); + value &= ~DPMAIF_BAT_REMAIN_MINSZ_MSK ; + value |=FIELD_PREP (DPMAIF_BAT_REMAIN_MINSZ_MSK , min_sz /DPMAIF_BAT_REMAIN_SZ_BASE ); +iowrite32 (value, hw_info->pcie_base +DPMAIF_AO_DL_PKTINFO_CON0 ); +} + +static void dpmaif_dl_set_ao_bat_bufsz (struct dpmaif_hw_info *hw_info, +unsigned char q_num,size_t buf_sz) +{ +unsigned int value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_PKTINFO_CON2 ); + value &= ~DPMAIF_BAT_BUF_SZ_MSK ; + value |=FIELD_PREP (DPMAIF_BAT_BUF_SZ_MSK , buf_sz /DPMAIF_BAT_BUFFER_SZ_BASE ); +iowrite32 (value, hw_info->pcie_base +DPMAIF_AO_DL_PKTINFO_CON2 ); +} + +static void dpmaif_dl_set_ao_bat_rsv_length (struct dpmaif_hw_info *hw_info,unsigned char q_num, +unsigned int length) +{ +unsigned int value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_PKTINFO_CON2 ); + value &= ~DPMAIF_BAT_RSV_LEN_MSK ; + value |= length &DPMAIF_BAT_RSV_LEN_MSK ; +iowrite32 (value, hw_info->pcie_base +DPMAIF_AO_DL_PKTINFO_CON2 ); +} + +static void dpmaif_dl_set_pkt_alignment (struct dpmaif_hw_info *hw_info,unsigned char q_num, +bool enable,unsigned int mode) +{ +unsigned int value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_RDY_CHK_THRES ); + value &= ~DPMAIF_PKT_ALIGN_MSK ; +if (enable) { + value |=DPMAIF_PKT_ALIGN_EN ; + value |=FIELD_PREP (DPMAIF_PKT_ALIGN_MSK , mode); + } + +iowrite32 (value, hw_info->pcie_base +DPMAIF_AO_DL_RDY_CHK_THRES ); +} + +static void 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 dpmaif_dl_set_ao_frg_check_thres (struct dpmaif_hw_info *hw_info,unsigned char q_num, +unsigned int size) +{ +unsigned int value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_RDY_CHK_FRG_THRES ); + value &= ~DPMAIF_FRG_CHECK_THRES_MSK ; + value |= (size &DPMAIF_FRG_CHECK_THRES_MSK ); +iowrite32 (value, hw_info->pcie_base +DPMAIF_AO_DL_RDY_CHK_FRG_THRES ); +} + +static void dpmaif_dl_set_ao_frg_bufsz (struct dpmaif_hw_info *hw_info, +unsigned char q_num,unsigned int buf_sz) +{ +unsigned int value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_RDY_CHK_FRG_THRES ); + value &= ~DPMAIF_FRG_BUF_SZ_MSK ; + value |=FIELD_PREP (DPMAIF_FRG_BUF_SZ_MSK , buf_sz /DPMAIF_FRG_BUFFER_SZ_BASE ); +iowrite32 (value, hw_info->pcie_base +DPMAIF_AO_DL_RDY_CHK_FRG_THRES ); +} + +static void 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 dpmaif_dl_set_ao_bat_check_thres (struct dpmaif_hw_info *hw_info, +unsigned char q_num,unsigned int size) +{ +unsigned int value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_RDY_CHK_THRES ); + value &= ~DPMAIF_BAT_CHECK_THRES_MSK ; + value |=FIELD_PREP (DPMAIF_BAT_CHECK_THRES_MSK , size); +iowrite32 (value, hw_info->pcie_base +DPMAIF_AO_DL_RDY_CHK_THRES ); +} + +static void dpmaif_dl_set_pit_seqnum (struct dpmaif_hw_info *hw_info, +unsigned char q_num,unsigned int seq) +{ +unsigned int value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_PIT_SEQ_END ); + value &= ~DPMAIF_DL_PIT_SEQ_MSK ; + value |= seq &DPMAIF_DL_PIT_SEQ_MSK ; +iowrite32 (value, hw_info->pcie_base +DPMAIF_AO_DL_PIT_SEQ_END ); +} + +static void 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 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 dpmaif_dl_dlq_pit_en (struct dpmaif_hw_info *hw_info, +unsigned char q_num,bool enable) +{ +unsigned int value; + + value =ioread32 (hw_info->pcie_base +DPMAIF_DL_DLQPIT_INIT_CON3 ); +if (enable) + value |=DPMAIF_DLQPIT_EN_MSK ; +else + value &= ~DPMAIF_DLQPIT_EN_MSK ; + +iowrite32 (value, hw_info->pcie_base +DPMAIF_DL_DLQPIT_INIT_CON3 ); +} + +static void dpmaif_dl_dlq_pit_init_done (struct dpmaif_ctrl *dpmaif_ctrl, +unsigned char q_num,unsigned int pit_idx) +{ +struct dpmaif_hw_info *hw_info; +unsigned int dl_pit_init; +u32 value; +int timeout; + + hw_info = &dpmaif_ctrl->hif_hw_info; + dl_pit_init =DPMAIF_DL_PIT_INIT_ALLSET ; + dl_pit_init |= (pit_idx <<DPMAIF_DLQPIT_CHAN_OFS ); + dl_pit_init |=DPMAIF_DL_PIT_INIT_EN ; + + timeout =readx_poll_timeout_atomic (ioread32, + hw_info->pcie_base +DPMAIF_DL_DLQPIT_INIT , + value, !(value &DPMAIF_DL_PIT_INIT_NOT_READY ), +DPMAIF_CHECK_DELAY_US ,DPMAIF_CHECK_INIT_TIMEOUT_US ); +if (timeout) { +dev_err (dpmaif_ctrl->dev,"data plane modem DL PIT is not ready\n" ); +return ; + } + +iowrite32 (dl_pit_init, hw_info->pcie_base +DPMAIF_DL_DLQPIT_INIT ); + + timeout =readx_poll_timeout_atomic (ioread32, + hw_info->pcie_base +DPMAIF_DL_DLQPIT_INIT , + value, !(value &DPMAIF_DL_PIT_INIT_NOT_READY ), +DPMAIF_CHECK_DELAY_US ,DPMAIF_CHECK_INIT_TIMEOUT_US ); +if (timeout) +dev_err (dpmaif_ctrl->dev,"data plane modem DL PIT initialization failed\n" ); +} + +static void dpmaif_config_dlq_pit_hw (struct dpmaif_ctrl *dpmaif_ctrl,unsigned char q_num, +struct dpmaif_dl *dl_que) +{ +struct dpmaif_hw_info *hw_info; +unsigned int pit_idx = q_num; + + hw_info = &dpmaif_ctrl->hif_hw_info; +dpmaif_dl_set_dlq_pit_base_addr (hw_info, q_num, dl_que->pit_base); +dpmaif_dl_set_dlq_pit_size (hw_info, q_num, dl_que->pit_size_cnt); +dpmaif_dl_dlq_pit_en (hw_info, q_num, true); +dpmaif_dl_dlq_pit_init_done (dpmaif_ctrl, q_num, pit_idx); +} + +static void dpmaif_config_all_dlq_hw (struct dpmaif_ctrl *dpmaif_ctrl) +{ +struct dpmaif_hw_info *hw_info; +int i; + + hw_info = &dpmaif_ctrl->hif_hw_info; + +for (i =0 ; i <DPMAIF_RXQ_NUM ; i++) +dpmaif_config_dlq_pit_hw (dpmaif_ctrl, i, &hw_info->dl_que[i]); +} + +static void dpmaif_dl_all_queue_en (struct dpmaif_ctrl *dpmaif_ctrl,bool enable) +{ +struct dpmaif_hw_info *hw_info; +u32 dl_bat_init, value; +int timeout; + + hw_info = &dpmaif_ctrl->hif_hw_info; + 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 ; + +/* update DL BAT setting to HW */ + timeout =readx_poll_timeout_atomic (ioread32, hw_info->pcie_base +DPMAIF_DL_BAT_INIT , + value, !(value &DPMAIF_DL_BAT_INIT_NOT_READY ), +0 ,DPMAIF_CHECK_TIMEOUT_US ); + +if (timeout) +dev_err (dpmaif_ctrl->dev,"timeout updating BAT setting to HW\n" ); + +iowrite32 (dl_bat_init, hw_info->pcie_base +DPMAIF_DL_BAT_INIT ); + +/* wait for HW update */ + timeout =readx_poll_timeout_atomic (ioread32, hw_info->pcie_base +DPMAIF_DL_BAT_INIT , + value, !(value &DPMAIF_DL_BAT_INIT_NOT_READY ), +0 ,DPMAIF_CHECK_TIMEOUT_US ); + +if (timeout) +dev_err (dpmaif_ctrl->dev,"data plane modem DL BAT is not ready\n" ); +} + +static int dpmaif_config_dlq_hw (struct dpmaif_ctrl *dpmaif_ctrl) +{ +struct dpmaif_hw_info *hw_info; +struct dpmaif_dl_hwq *dl_hw; +struct dpmaif_dl *dl_que; +unsigned int queue =0 ;/* all queues share one BAT/frag BAT table */ +int ret; + + hw_info = &dpmaif_ctrl->hif_hw_info; +dpmaif_dl_dlq_hpc_hw_init (hw_info); + + dl_que = &hw_info->dl_que[queue]; + dl_hw = &hw_info->dl_que_hw[queue]; +if (!dl_que->que_started) +return -EBUSY ; + +dpmaif_dl_set_ao_remain_minsz (hw_info, queue, dl_hw->bat_remain_size); +dpmaif_dl_set_ao_bat_bufsz (hw_info, queue, dl_hw->bat_pkt_bufsz); +dpmaif_dl_set_ao_frg_bufsz (hw_info, queue, dl_hw->frg_pkt_bufsz); +dpmaif_dl_set_ao_bat_rsv_length (hw_info, queue, dl_hw->bat_rsv_length); +dpmaif_dl_set_ao_bid_maxcnt (hw_info, queue, dl_hw->pkt_bid_max_cnt); + +if (dl_hw->pkt_alignment ==64 ) +dpmaif_dl_set_pkt_alignment (hw_info, queue, true,DPMAIF_PKT_ALIGN64_MODE ); +else if (dl_hw->pkt_alignment ==128 ) +dpmaif_dl_set_pkt_alignment (hw_info, queue, true,DPMAIF_PKT_ALIGN128_MODE ); +else +dpmaif_dl_set_pkt_alignment (hw_info, queue, false,0 ); + +dpmaif_dl_set_pit_seqnum (hw_info, queue,DPMAIF_DL_PIT_SEQ_VALUE ); +dpmaif_dl_set_ao_mtu (hw_info, dl_hw->mtu_size); +dpmaif_dl_set_ao_pit_chknum (hw_info, queue, dl_hw->chk_pit_num); +dpmaif_dl_set_ao_bat_check_thres (hw_info, queue, dl_hw->chk_bat_num); +dpmaif_dl_set_ao_frg_check_thres (hw_info, queue, dl_hw->chk_frg_num); +/* enable frag feature */ +dpmaif_dl_frg_ao_en (hw_info, queue, true); +/* init frag use same BAT register */ +dpmaif_dl_set_bat_base_addr (hw_info, queue, dl_que->frg_base); +dpmaif_dl_set_bat_size (hw_info, queue, dl_que->frg_size_cnt); +dpmaif_dl_bat_en (hw_info, queue, true); + ret =dpmaif_dl_bat_init_done (dpmaif_ctrl, queue, true); +if (ret) +return ret; + +/* normal BAT init */ +dpmaif_dl_set_bat_base_addr (hw_info, queue, dl_que->bat_base); +dpmaif_dl_set_bat_size (hw_info, queue, dl_que->bat_size_cnt); +/* enable BAT */ +dpmaif_dl_bat_en (hw_info, queue, false); +/* notify HW init/setting done */ + ret =dpmaif_dl_bat_init_done (dpmaif_ctrl, queue, false); +if (ret) +return ret; + +/* init PIT (two PIT table) */ +dpmaif_config_all_dlq_hw (dpmaif_ctrl); +dpmaif_dl_all_queue_en (dpmaif_ctrl, true); + +dpmaif_dl_set_pkt_checksum (hw_info); + +return ret; +} + +static void 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 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 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 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 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) { +dpmaif_ul_update_drb_size (hw_info, i, ul_que->drb_size_cnt * +DPMAIF_UL_DRB_ENTRY_WORD ); +dpmaif_ul_update_drb_base_addr (hw_info, i, ul_que->drb_base); +dpmaif_ul_rdy_en (hw_info, i, true); +dpmaif_ul_arb_en (hw_info, i, true); + }else { +dpmaif_ul_arb_en (hw_info, i, false); + } + } +} + +static int dpmaif_hw_init_done (struct dpmaif_hw_info *hw_info) +{ +u32 value; +int ret; + +/* sync default value to SRAM */ + value =ioread32 (hw_info->pcie_base +DPMAIF_AP_OVERWRITE_CFG ); + value |=DPMAIF_SRAM_SYNC ; +iowrite32 (value, hw_info->pcie_base +DPMAIF_AP_OVERWRITE_CFG ); + + ret =readx_poll_timeout_atomic (ioread32, hw_info->pcie_base +DPMAIF_AP_OVERWRITE_CFG , + value, !(value &DPMAIF_SRAM_SYNC ), +0 ,DPMAIF_CHECK_TIMEOUT_US ); +if (ret) +return ret; + +iowrite32 (DPMAIF_UL_INIT_DONE , hw_info->pcie_base +DPMAIF_AO_UL_INIT_SET ); +iowrite32 (DPMAIF_DL_INIT_DONE , hw_info->pcie_base +DPMAIF_AO_DL_INIT_SET ); +return 0 ; +} + +static int dpmaif_config_que_hw (struct dpmaif_ctrl *dpmaif_ctrl) +{ +struct dpmaif_hw_info *hw_info; +int ret; + + hw_info = &dpmaif_ctrl->hif_hw_info; +dpmaif_common_hw_init (hw_info); + ret =dpmaif_config_dlq_hw (dpmaif_ctrl); +if (ret) +return ret; + +dpmaif_config_ulq_hw (hw_info); +return dpmaif_hw_init_done (hw_info); +} + +static inline bool dpmaif_dl_idle_check (struct dpmaif_hw_info *hw_info) +{ +u32 value =ioread32 (hw_info->pcie_base +DPMAIF_DL_CHK_BUSY ); + +/* If total queue is idle, then all DL is idle. +* 0: idle, 1: busy +*/ +return !(value &DPMAIF_DL_IDLE_STS ); +} + +static void dpmaif_ul_all_queue_en (struct dpmaif_hw_info *hw_info,bool enable) +{ +u32 ul_arb_en =ioread32 (hw_info->pcie_base +DPMAIF_AO_UL_CHNL_ARB0 ); + +if (enable) + ul_arb_en |=DPMAIF_UL_ALL_QUE_ARB_EN ; +else + ul_arb_en &= ~DPMAIF_UL_ALL_QUE_ARB_EN ; + +iowrite32 (ul_arb_en, hw_info->pcie_base +DPMAIF_AO_UL_CHNL_ARB0 ); +} + +static inline int dpmaif_ul_idle_check (struct dpmaif_hw_info *hw_info) +{ +u32 value =ioread32 (hw_info->pcie_base +DPMAIF_UL_CHK_BUSY ); + +/* If total queue is idle, then all UL is idle. +* 0: idle, 1: busy +*/ +return !(value &DPMAIF_UL_IDLE_STS ); +} + +/* DPMAIF UL Part HW setting */ + +int dpmaif_ul_add_wcnt (struct dpmaif_ctrl *dpmaif_ctrl, +unsigned char q_num,unsigned int drb_entry_cnt) +{ +struct dpmaif_hw_info *hw_info; +u32 ul_update, value; +int ret; + + hw_info = &dpmaif_ctrl->hif_hw_info; + ul_update = drb_entry_cnt &DPMAIF_UL_ADD_COUNT_MASK ; + ul_update |=DPMAIF_UL_ADD_UPDATE ; + + ret =readx_poll_timeout_atomic (ioread32, + hw_info->pcie_base +DPMAIF_ULQ_ADD_DESC_CH_n (q_num), + value, !(value &DPMAIF_UL_ADD_NOT_READY ), +0 ,DPMAIF_CHECK_TIMEOUT_US ); + +if (ret) { +dev_err (dpmaif_ctrl->dev,"UL add is not ready\n" ); +return ret; + } + +iowrite32 (ul_update, hw_info->pcie_base +DPMAIF_ULQ_ADD_DESC_CH_n (q_num)); + + ret =readx_poll_timeout_atomic (ioread32, + hw_info->pcie_base +DPMAIF_ULQ_ADD_DESC_CH_n (q_num), + value, !(value &DPMAIF_UL_ADD_NOT_READY ), +0 ,DPMAIF_CHECK_TIMEOUT_US ); + +if (ret) { +dev_err (dpmaif_ctrl->dev,"timeout updating UL add\n" ); +return ret; + } + +return 0 ; +} + +unsigned int dpmaif_ul_get_ridx (struct dpmaif_hw_info *hw_info,unsigned char q_num) +{ +unsigned int value =ioread32 (hw_info->pcie_base +DPMAIF_ULQ_STA0_n (q_num)); + +return value >>DPMAIF_UL_DRB_RIDX_OFFSET ; +} + +int dpmaif_dl_add_dlq_pit_remain_cnt (struct dpmaif_ctrl *dpmaif_ctrl,unsigned int dlq_pit_idx, +unsigned int pit_remain_cnt) +{ +struct dpmaif_hw_info *hw_info; +u32 dl_update, value; +int ret; + + hw_info = &dpmaif_ctrl->hif_hw_info; + dl_update = pit_remain_cnt &DPMAIF_PIT_REM_CNT_MSK ; + dl_update |=DPMAIF_DL_ADD_UPDATE | (dlq_pit_idx <<DPMAIF_ADD_DLQ_PIT_CHAN_OFS ); + + ret =readx_poll_timeout_atomic (ioread32, hw_info->pcie_base +DPMAIF_DL_DLQPIT_ADD , + value, !(value &DPMAIF_DL_ADD_NOT_READY ), +0 ,DPMAIF_CHECK_TIMEOUT_US ); + +if (ret) { +dev_err (dpmaif_ctrl->dev,"data plane modem is not ready to add dlq\n" ); +return ret; + } + +iowrite32 (dl_update, hw_info->pcie_base +DPMAIF_DL_DLQPIT_ADD ); + + ret =readx_poll_timeout_atomic (ioread32, hw_info->pcie_base +DPMAIF_DL_DLQPIT_ADD , + value, !(value &DPMAIF_DL_ADD_NOT_READY ), +0 ,DPMAIF_CHECK_TIMEOUT_US ); + +if (ret) { +dev_err (dpmaif_ctrl->dev,"data plane modem add dlq failed\n" ); +return ret; + } + +return 0 ; +} + +unsigned int dpmaif_dl_dlq_pit_get_wridx (struct dpmaif_hw_info *hw_info,unsigned int dlq_pit_idx) +{ +return ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_DLQ_WRIDX + + dlq_pit_idx *DLQ_PIT_IDX_SIZE ) &DPMAIF_DL_PIT_WRIDX_MSK ; +} + +static bool dl_add_timedout (struct dpmaif_hw_info *hw_info) +{ +u32 value; +int ret; + + ret =readx_poll_timeout_atomic (ioread32, hw_info->pcie_base +DPMAIF_DL_BAT_ADD , + value, !(value &DPMAIF_DL_ADD_NOT_READY ), +0 ,DPMAIF_CHECK_TIMEOUT_US ); + +if (ret) +return true; + +return false; +} + +int dpmaif_dl_add_bat_cnt (struct dpmaif_ctrl *dpmaif_ctrl, +unsigned char q_num,unsigned int bat_entry_cnt) +{ +struct dpmaif_hw_info *hw_info; +unsigned int value; + + hw_info = &dpmaif_ctrl->hif_hw_info; + value = bat_entry_cnt &DPMAIF_DL_ADD_COUNT_MASK ; + value |=DPMAIF_DL_ADD_UPDATE ; + +if (dl_add_timedout (hw_info)) { +dev_err (dpmaif_ctrl->dev,"DL add BAT not ready. count: %u queue: %dn" , + bat_entry_cnt, q_num); +return -EBUSY ; + } + +iowrite32 (value, hw_info->pcie_base +DPMAIF_DL_BAT_ADD ); + +if (dl_add_timedout (hw_info)) { +dev_err (dpmaif_ctrl->dev,"DL add BAT timeout. count: %u queue: %dn" , + bat_entry_cnt, q_num); +return -EBUSY ; + } + +return 0 ; +} + +unsigned int dpmaif_dl_get_bat_ridx (struct dpmaif_hw_info *hw_info,unsigned char q_num) +{ +return ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_BAT_RIDX ) &DPMAIF_DL_BAT_WRIDX_MSK ; +} + +unsigned int dpmaif_dl_get_bat_wridx (struct dpmaif_hw_info *hw_info,unsigned char q_num) +{ +return ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_BAT_WRIDX ) &DPMAIF_DL_BAT_WRIDX_MSK ; +} + +int dpmaif_dl_add_frg_cnt (struct dpmaif_ctrl *dpmaif_ctrl, +unsigned char q_num,unsigned int frg_entry_cnt) +{ +struct dpmaif_hw_info *hw_info; +unsigned int value; + + hw_info = &dpmaif_ctrl->hif_hw_info; + value = frg_entry_cnt &DPMAIF_DL_ADD_COUNT_MASK ; + value |=DPMAIF_DL_FRG_ADD_UPDATE ; + value |=DPMAIF_DL_ADD_UPDATE ; + +if (dl_add_timedout (hw_info)) { +dev_err (dpmaif_ctrl->dev,"Data plane modem is not ready to add frag DLQ\n" ); +return -EBUSY ; + } + +iowrite32 (value, hw_info->pcie_base +DPMAIF_DL_BAT_ADD ); + +if (dl_add_timedout (hw_info)) { +dev_err (dpmaif_ctrl->dev,"Data plane modem add frag DLQ failed" ); +return -EBUSY ; + } + +return 0 ; +} + +unsigned int dpmaif_dl_get_frg_ridx (struct dpmaif_hw_info *hw_info,unsigned char q_num) +{ +return ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_FRGBAT_WRIDX ) &DPMAIF_DL_FRG_WRIDX_MSK ; +} + +static void dpmaif_set_queue_property (struct dpmaif_hw_info *hw_info, +struct dpmaif_hw_params *init_para) +{ +struct dpmaif_dl_hwq *dl_hwq; +struct dpmaif_dl *dl_que; +struct dpmaif_ul *ul_que; +int i; + +for (i =0 ; i <DPMAIF_RXQ_NUM ; i++) { + dl_hwq = &hw_info->dl_que_hw[i]; + dl_hwq->bat_remain_size =DPMAIF_HW_BAT_REMAIN ; + dl_hwq->bat_pkt_bufsz =DPMAIF_HW_BAT_PKTBUF ; + dl_hwq->frg_pkt_bufsz =DPMAIF_HW_FRG_PKTBUF ; + dl_hwq->bat_rsv_length =DPMAIF_HW_BAT_RSVLEN ; + dl_hwq->pkt_bid_max_cnt =DPMAIF_HW_PKT_BIDCNT ; + dl_hwq->pkt_alignment =DPMAIF_HW_PKT_ALIGN ; + dl_hwq->mtu_size =DPMAIF_HW_MTU_SIZE ; + dl_hwq->chk_bat_num =DPMAIF_HW_CHK_BAT_NUM ; + dl_hwq->chk_frg_num =DPMAIF_HW_CHK_FRG_NUM ; + dl_hwq->chk_pit_num =DPMAIF_HW_CHK_PIT_NUM ; + + dl_que = &hw_info->dl_que[i]; + dl_que->bat_base = init_para->pkt_bat_base_addr[i]; + dl_que->bat_size_cnt = init_para->pkt_bat_size_cnt[i]; + dl_que->pit_base = init_para->pit_base_addr[i]; + dl_que->pit_size_cnt = init_para->pit_size_cnt[i]; + dl_que->frg_base = init_para->frg_bat_base_addr[i]; + dl_que->frg_size_cnt = init_para->frg_bat_size_cnt[i]; + dl_que->que_started = true; + } + +for (i =0 ; i <DPMAIF_TXQ_NUM ; i++) { + ul_que = &hw_info->ul_que[i]; + ul_que->drb_base = init_para->drb_base_addr[i]; + ul_que->drb_size_cnt = init_para->drb_size_cnt[i]; + ul_que->que_started = true; + } +} + +/** +* dpmaif_hw_stop_tx_queue() - Stop all TX queues +* @dpmaif_ctrl: Pointer to struct dpmaif_ctrl +* +* Disable HW UL queue. Checks busy UL queues to go to idle +* with an attempt count of 1000000. +* +* Return: 0 on success and -ETIMEDOUT upon a timeout +*/ +int dpmaif_hw_stop_tx_queue (struct dpmaif_ctrl *dpmaif_ctrl) +{ +struct dpmaif_hw_info *hw_info; +int count =0 ; + + hw_info = &dpmaif_ctrl->hif_hw_info; + +/* disables HW UL arb queue and check for idle */ +dpmaif_ul_all_queue_en (hw_info, false); +while (dpmaif_ul_idle_check (hw_info)) { +if (++count >=DPMAIF_MAX_CHECK_COUNT ) { +dev_err (dpmaif_ctrl->dev,"Stop TX failed, 0x%x\n" , +ioread32 (hw_info->pcie_base +DPMAIF_UL_CHK_BUSY )); +return -ETIMEDOUT ; + } + } + +return 0 ; +} + +/** +* dpmaif_hw_stop_rx_queue() - Stop all RX queues +* @dpmaif_ctrl: Pointer to struct dpmaif_ctrl +* +* Disable HW DL queue. Checks busy UL queues to go to idle +* with an attempt count of 1000000. +* Check that HW PIT write index equals read index with the same +* attempt count. +* +* Return: 0 on success and -ETIMEDOUT upon a timeout +*/ +int dpmaif_hw_stop_rx_queue (struct dpmaif_ctrl *dpmaif_ctrl) +{ +struct dpmaif_hw_info *hw_info; +unsigned int wridx; +unsigned int ridx; +int count =0 ; + + hw_info = &dpmaif_ctrl->hif_hw_info; + +/* disables HW DL queue and check idle */ +dpmaif_dl_all_queue_en (dpmaif_ctrl, false); +while (dpmaif_dl_idle_check (hw_info)) { +if (++count >=DPMAIF_MAX_CHECK_COUNT ) { +dev_err (dpmaif_ctrl->dev,"stop RX failed, 0x%x\n" , +ioread32 (hw_info->pcie_base +DPMAIF_DL_CHK_BUSY )); +return -ETIMEDOUT ; + } + } + +/* check middle PIT sync done */ + count =0 ; +do { + wridx =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_PIT_WRIDX ) & +DPMAIF_DL_PIT_WRIDX_MSK ; + ridx =ioread32 (hw_info->pcie_base +DPMAIF_AO_DL_PIT_RIDX ) & +DPMAIF_DL_PIT_WRIDX_MSK ; +if (wridx == ridx) +return 0 ; + +if (++count >=DPMAIF_MAX_CHECK_COUNT ) { +dev_err (dpmaif_ctrl->dev,"check middle PIT sync fail\n" ); +break ; + } + }while (1 ); + +return -ETIMEDOUT ; +} + +void dpmaif_start_hw (struct dpmaif_ctrl *dpmaif_ctrl) +{ +dpmaif_ul_all_queue_en (&dpmaif_ctrl->hif_hw_info, true); +dpmaif_dl_all_queue_en (dpmaif_ctrl, true); +} + +/** +* dpmaif_hw_init() - Initialize HW data path API +* @dpmaif_ctrl: Pointer to struct dpmaif_ctrl +* @init_param: Pointer to struct dpmaif_hw_params +* +* Configures port mode, clock config, HW interrupt init, +* and HW queue config. +* +* Return: 0 on success and -error code upon failure +*/ +int dpmaif_hw_init (struct dpmaif_ctrl *dpmaif_ctrl,struct dpmaif_hw_params *init_param) +{ +struct dpmaif_hw_info *hw_info; +int ret; + + hw_info = &dpmaif_ctrl->hif_hw_info; + +/* port mode & clock config */ + ret =dpmaif_hw_config (hw_info); + +if (ret) { +dev_err (dpmaif_ctrl->dev,"sram_init check fail\n" ); +return ret; + } + +/* HW interrupt init */ + ret =dpmaif_init_intr (hw_info); +if (ret) { +dev_err (dpmaif_ctrl->dev,"init_intr check fail\n" ); +return ret; + } + +/* HW queue config */ +dpmaif_set_queue_property (hw_info, init_param); + ret =dpmaif_config_que_hw (dpmaif_ctrl); +if (ret) +dev_err (dpmaif_ctrl->dev,"DPMAIF hw_init_done check fail\n" ); + +return ret; +} + +bool dpmaif_hw_check_clr_ul_done_status (struct dpmaif_hw_info *hw_info,unsigned char qno) +{ +u32 value =ioread32 (hw_info->pcie_base +DPMAIF_AP_L2TISAR0 ); + + value &=BIT (DP_UL_INT_DONE_OFFSET + qno); +if (value) { +/* clear interrupt status */ +iowrite32 (value, hw_info->pcie_base +DPMAIF_AP_L2TISAR0 ); +return true; + } + +return false; +}
drivers/net/wwan/t7xx/t7xx_dpmaif.h new file +168 -0
168 lines not on this page · raw message
Signature · 1 line
2.17.1
Ricardo Martinez
reviewerPATCH v2 8/14 net: wwan: t7xx: Add data path interface
In reply to Ricardo MartinezFrom: Haijun Lio <[email protected]>
Data Path Modem AP Interface (DPMAIF) HIF layer provides methods for initialization, ISR, control and event handling of TX/RX flows.
DPMAIF TX
Exposes the dmpaif_tx_send_skb function which can be used by the network device to transmit packets.
The uplink data management uses a Descriptor Ring Buffer (DRB). First DRB entry is a message type that will be followed by 1 or more normal DRB entries. Message type DRB will hold the skb information and each normal DRB entry holds a pointer to the skb payload.
DPMAIF RX
The downlink buffer management uses Buffer Address Table (BAT) and Packet Information Table (PIT) rings.
The BAT ring holds the address of skb data buffer for the HW to use, while the PIT contains metadata about a whole network packet including a reference to the BAT entry holding the data buffer address. The driver reads the PIT and BAT entries written by the modem, when reaching a threshold, the driver will reload the PIT and BAT rings.
--- drivers/net/wwan/t7xx/Makefile | 4 + drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c | 540 +++++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h | 278 ++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 1532 ++++++++++++++++++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h | 117 ++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c | 810 +++++++++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.h | 82 ++ 7 files changed, 3363 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
@@ -14,3 +14,7 @@ mtk_t7xx-y:= t7xx_pci.o \ t7xx_port_proxy.o \ t7xx_port_ctrl_msg.o \ t7xx_port_wwan.o \ + t7xx_dpmaif.o \ + t7xx_hif_dpmaif.o \ + t7xx_hif_dpmaif_tx.o \ + t7xx_hif_dpmaif_rx.o \
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c new file +540 -0
540 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h new file +278 -0
278 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c new file +1532 -0
1,532 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h new file +117 -0
117 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c new file +810 -0
526 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.h new file +82 -0
82 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
Sergey Ryazanov
maintainerRe: [PATCH v2 08/14] net: wwan: t7xx: Add data path interface
Quoted 19 lines · Ricardo Martinez
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]
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +2
-0+static int dpmaif_net_rx_push_thread (void *arg) +{
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c line 95
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +10
-0+while (!kthread_should_stop ()) { +if (skb_queue_empty (&q->skb_queue.skb_list)) { +if (wait_event_interruptible (q->rx_wq, + !skb_queue_empty (&q->skb_queue.skb_list) || +kthread_should_stop ())) +continue ; + } + +if (kthread_should_stop ()) +break ;
Looks like the above check is used to recheck thread state after the wait_event_interruptible() call, so the check could be moved to the skb_queue_empty() code block to avoid odd thread state checks.
Quoted 4 lines
...
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +3
-0+static void dpmaif_rx_skb (struct dpmaif_rx_queue *rxq,struct dpmaif_cur_rx_skb_info *rx_skb_info) +{ +struct sk_buff *new_skb;
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c line 867
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +9
-0+u32 *lhif_header; + + new_skb = rx_skb_info->cur_skb; +/* MD put the ccmni_index to the msg pkt, +* so we need push it alone. Maybe not needed. +*/ + lhif_header =skb_push (new_skb,sizeof (*lhif_header)); + *lhif_header &= ~LHIF_HEADER_NETIF ; + *lhif_header |=FIELD_PREP (LHIF_HEADER_NETIF , rx_skb_info->cur_chn_idx);
Why is the skb data field used to carry packet control data? Consider using the skb control buffer (i.e skb->cb) to carry control data between the driver layers to make metadata handling less expensive and increase driver performance.
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c line 1288
Quoted 9 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +7
-0+/* add data to rx thread skb list */ +ccci_skb_enqueue (&rxq->skb_queue, new_skb); +} +void dpmaif_rxq_free (struct dpmaif_rx_queue *queue) +{ +while ((skb =skb_dequeue (&queue->skb_queue.skb_list))) +kfree_skb (skb);
skb_queue_purge()
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c line 1370
Quoted 8 lines
...
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +6
-0+static int dpmaif_skb_queue_init_struct (struct dpmaif_ctrl *dpmaif_ctrl, +const unsigned int index) +{ +INIT_LIST_HEAD (&queue->skb_list.head); +spin_lock_init (&queue->skb_list.lock); + queue->skb_list.qlen =0 ;
skb_queue_head_init()
[skipped]
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h line 26
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h +5
-0+/* lhif header feilds */ +#define LHIF_HEADER_NW_TYPE GENMASK(31, 29) +#define LHIF_HEADER_NETIF GENMASK(28, 24) +#define LHIF_HEADER_F GENMASK(22, 20) +#define LHIF_HEADER_FLOW GENMASK(19, 16)
Just place control data to the skb control buffer (i.e. skb->cb) and define this control data as a structure:
struct rx_pkt_cb {
u8 nw_type;
u8 netif;
u8 flow;
};drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c line 286
Quoted 12 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c +7
-0+static int dpmaif_tx_send_skb_on_tx_thread (struct dpmaif_ctrl *dpmaif_ctrl, +struct dpmaif_tx_event *event) +{ +struct ccci_header ccci_h; + skb = event->skb; + ccci_h = *(struct ccci_header *)skb->data; +skb_pull (skb,sizeof (struct ccci_header ));
Place this metadata to the skb control buffer (i.e. skb->cb) to avoid odd skb_push()/skb_pull() calls.
Also this looks like an abuse of ccci_header structure. In fact it never passed to the modem along with a data packet, but searching through the code show this as a structure usage place.
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c line 611
Quoted 13 lines
...
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c +9
-0+int dpmaif_tx_send_skb (struct dpmaif_ctrl *dpmaif_ctrl,enum txq_type txqt,struct sk_buff *skb) +{ +if (txq->tx_submit_skb_cnt < txq->tx_list_max_len && tx_drb_available) { +struct dpmaif_tx_event *event; + event =kmalloc (sizeof (*event),GFP_ATOMIC ); +INIT_LIST_HEAD (&event->entry); + event->qno = txqt; + event->skb = skb; + event->drb_cnt = send_drb_cnt;
Please, place the packet metadata (dpmaif_tx_event data) in the skb control buffer (i.e. skb->cb) and use skb queue API as in Rx path. This will allow you to avoid the per-packet metadata memory allocation and make code simple.
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c line 625
Quoted 13 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c +13
-0+spin_lock_irqsave (&txq->tx_event_lock, flags); +list_add_tail (&event->entry, &txq->tx_event_queue); + txq->tx_submit_skb_cnt++; +spin_unlock_irqrestore (&txq->tx_event_lock, flags); +wake_up (&dpmaif_ctrl->tx_wq); + +return 0 ; + } + + cb = dpmaif_ctrl->callbacks; + cb->state_notify (dpmaif_ctrl->mtk_dev,DMPAIF_TXQ_STATE_FULL , txqt); + +return -EBUSY ;
It is better to invert the above condition, handle TXQ full situation as a corner case and packet queuing as a normal case. I.e. instead of:
if (have_queue_space) {
/* Enqueue packet */
return 0;
}
/* Queue full notification emitting */
return -EBUSY;handle queuing like this:
if (unlikely(!have_queue_space)) {
/* Queue full notification emitting */
return -EBUSY;
}
/* Enqueue packet */
return 0;This is a matter of taste, but makes code more readable.
--
Sergey
Ricardo Martinez
reviewerPATCH v2 9/14 net: wwan: t7xx: Add WWAN network interface
In reply to Ricardo MartinezFrom: Haijun Lio <[email protected]>
Creates the Cross Core Modem Network Interface (CCMNI) which implements the wwan_ops for registration with the WWAN framework, CCMNI also implements the net_device_ops functions used by the network device. Network device operations include open, close, start transmission, TX timeout, change MTU, and select queue.
--- drivers/net/wwan/t7xx/Makefile | 1 + drivers/net/wwan/t7xx/t7xx_modem_ops.c | 11 +- drivers/net/wwan/t7xx/t7xx_netdev.c | 545 +++++++++++++++++++++++++ drivers/net/wwan/t7xx/t7xx_netdev.h | 63 +++ 4 files changed, 619 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
@@ -18,3 +18,4 @@ mtk_t7xx-y:= t7xx_pci.o \ t7xx_hif_dpmaif.o \ t7xx_hif_dpmaif_tx.o \ t7xx_hif_dpmaif_rx.o \ + t7xx_netdev.o \
drivers/net/wwan/t7xx/t7xx_modem_ops.c +10 -1
@@ -21,6 +21,7 @@#include "t7xx_mhccif.h" #include "t7xx_modem_ops.h" #include "t7xx_monitor.h" +#include "t7xx_netdev.h" #include "t7xx_pci.h" #include "t7xx_pcie_mac.h" #include "t7xx_port.h"
@@ -691,10 +692,15 @@ int mtk_md_init(struct mtk_pci_dev *mtk_dev)if (ret) goto err_alloc; - ret =cldma_init (ID_CLDMA1 ); +/* init the data path */ + ret =ccmni_init (mtk_dev);if (ret) goto err_fsm_init; + ret =cldma_init (ID_CLDMA1 ); +if (ret) + goto err_ccmni_init; + ret =port_proxy_init (mtk_dev->md);if (ret) goto err_cldma_init;
@@ -709,6 +715,8 @@ int mtk_md_init(struct mtk_pci_dev *mtk_dev) err_cldma_init:cldma_exit (ID_CLDMA1 ); +err_ccmni_init: +ccmni_exit (mtk_dev); err_fsm_init:ccci_fsm_uninit (); err_alloc:
@@ -733,6 +741,7 @@ void mtk_md_exit(struct mtk_pci_dev *mtk_dev)fsm_append_command (fsm_ctl,CCCI_COMMAND_PRE_STOP ,1 );port_proxy_uninit ();cldma_exit (ID_CLDMA1 ); +ccmni_exit (mtk_dev);ccci_fsm_uninit ();destroy_workqueue (md->handshake_wq); }
drivers/net/wwan/t7xx/t7xx_netdev.c new file +545 -0
545 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_netdev.h new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.17.1
Sergey Ryazanov
maintainerRe: [PATCH v2 09/14] net: wwan: t7xx: Add WWAN network interface
Quoted 5 lines · Ricardo Martinez
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 6 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +4
-0+static void ccmni_make_etherframe (struct net_device *dev,void *skb_eth_hdr, +u8 *mac_addr,unsigned int packet_type) +{ +struct ethhdr *eth_hdr;
drivers/net/wwan/t7xx/t7xx_netdev.c line 44
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +10
-0+ + eth_hdr = skb_eth_hdr; +memcpy (eth_hdr->h_dest, mac_addr,sizeof (eth_hdr->h_dest)); +memset (eth_hdr->h_source,0 ,sizeof (eth_hdr->h_source)); + +if (packet_type ==IPV6_VERSION ) + eth_hdr->h_proto =cpu_to_be16 (ETH_P_IPV6 ); +else + eth_hdr->h_proto =cpu_to_be16 (ETH_P_IP ); +}
If the modem is a pure IP device, you do not need to forge an Ethernet header. Moreover this does not make any sense, only odd CPU time spending. Just set netdev->type to ARPHRD_NONE and send a pure IPv4/IPv6 packet up to the stack.
Quoted 23 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +23
-0+static enum txq_type get_txq_type (struct sk_buff *skb) +{ +u32 total_len, payload_len, l4_off; +bool tcp_syn_fin_rst, is_tcp; +struct ipv6hdr *ip6h; +struct tcphdr *tcph; +struct iphdr *ip4h; +u32 packet_type; +__be16 frag_off; + + packet_type = skb->data[0 ] &SBD_PACKET_TYPE_MASK ; +if (packet_type ==IPV6_VERSION ) { + ip6h = (struct ipv6hdr *)skb->data; + total_len =sizeof (struct ipv6hdr ) +ntohs (ip6h->payload_len); + l4_off =ipv6_skip_exthdr (skb,sizeof (struct ipv6hdr ), &ip6h->nexthdr, &frag_off); + tcph = (struct tcphdr *)(skb->data + l4_off); + is_tcp = ip6h->nexthdr ==IPPROTO_TCP ; + payload_len = total_len - l4_off - (tcph->doff <<2 ); + }else if (packet_type ==IPV4_VERSION ) { + ip4h = (struct iphdr *)skb->data; + tcph = (struct tcphdr *)(skb->data + (ip4h->ihl <<2 )); + is_tcp = ip4h->protocol ==IPPROTO_TCP ; + payload_len =ntohs (ip4h->tot_len) - (ip4h->ihl <<2 ) - (tcph->doff <<2 );
drivers/net/wwan/t7xx/t7xx_netdev.c line 78
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +10
-0+ }else { +return TXQ_NORMAL ; + } + + tcp_syn_fin_rst = tcph->syn || tcph->fin || tcph->rst; +if (is_tcp && !payload_len && !tcp_syn_fin_rst) +return TXQ_FAST ; + +return TXQ_NORMAL ; +}
I am wondering how much modem performance has improved with this optimization compared to the performance loss on each packet due to the cache miss? Do you have any measurement results?
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +8
-0+static u16 ccmni_select_queue (struct net_device *dev,struct sk_buff *skb, +struct net_device *sb_dev) +{ +struct ccmni_instance *ccmni; + + ccmni =netdev_priv (dev); + +if (ccmni->ctlb->capability &NIC_CAP_DATA_ACK_DVD )
drivers/net/wwan/t7xx/t7xx_netdev.c line 97
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +10
-0+return get_txq_type (skb); + +return TXQ_NORMAL ; +} + +static int ccmni_open (struct net_device *dev) +{ +struct ccmni_instance *ccmni; + + ccmni =wwan_netdev_drvpriv (dev);
Move this assignment to the variable definition.
drivers/net/wwan/t7xx/t7xx_netdev.c line 108
Quoted 11 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +11
-0+netif_carrier_on (dev); +netif_tx_start_all_queues (dev); +atomic_inc (&ccmni->usage); +return 0 ; +} + +static int ccmni_close (struct net_device *dev) +{ +struct ccmni_instance *ccmni; + + ccmni =wwan_netdev_drvpriv (dev);
Same here.
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +7
-0+if (atomic_dec_return (&ccmni->usage) <0 ) +return -EINVAL ; + +netif_carrier_off (dev); +netif_tx_disable (dev); +return 0 ; +}
drivers/net/wwan/t7xx/t7xx_netdev.c line 126
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +10
-0+ +static int ccmni_send_packet (struct ccmni_instance *ccmni,struct sk_buff *skb,enum txq_type txqt) +{ +struct ccmni_ctl_block *ctlb; +struct ccci_header *ccci_h; +unsigned int ccmni_idx; + +skb_push (skb,sizeof (struct ccci_header )); + ccci_h = (struct ccci_header *)skb->data; + ccci_h->status &= ~HDR_FLD_CHN ;
Please do not push control data to the skb data. You anyway will remove them during the enqueuing to HW. This approach will cause a performance penalty. Also this looks like a ccci_header structure abuse.
Use a dedicated structure and the skb control buffer (e.g. skb->cb) to preserve control data while the packet stays in an intermediate queue.
Quoted 13 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +13
-0+ ccmni_idx = ccmni->index; + ccci_h->data[0 ] = ccmni_idx; + ccci_h->data[1 ] = skb->len; + ccci_h->reserved =0 ; + + ctlb = ccmni->ctlb; +if (dpmaif_tx_send_skb (ctlb->hif_ctrl, txqt, skb)) { +skb_pull (skb,sizeof (struct ccci_header )); +/* we will reserve header again in the next retry */ +return NETDEV_TX_BUSY ; + } + +return 0 ;
drivers/net/wwan/t7xx/t7xx_netdev.c line 150
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +10
-0+} + +static int ccmni_start_xmit (struct sk_buff *skb,struct net_device *dev) +{ +struct ccmni_instance *ccmni; +struct ccmni_ctl_block *ctlb; +enum txq_type txqt; +int skb_len; + + ccmni =wwan_netdev_drvpriv (dev);
Move assignment to the variable definition.
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +10
-0+ ctlb = ccmni->ctlb; + txqt =TXQ_NORMAL ; + skb_len = skb->len; + +/* If MTU changed or there is no headroom, drop the packet */ +if (skb->len > dev->mtu ||skb_headroom (skb) <sizeof (struct ccci_header )) { +dev_kfree_skb (skb); + dev->stats.tx_dropped++; +return NETDEV_TX_OK ; + }
drivers/net/wwan/t7xx/t7xx_netdev.c line 170
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +10
-0+ +if (ctlb->capability &NIC_CAP_DATA_ACK_DVD ) + txqt =get_txq_type (skb); + +if (ccmni_send_packet (ccmni, skb, txqt)) { +if (!(ctlb->capability &NIC_CAP_TXBUSY_STOP )) { +if ((ccmni->tx_busy_cnt[txqt]++) %100 ==0 ) +netdev_notice (dev,"[TX]CCMNI:%d busy:pkt=%ld(ack=%d) cnt=%ld\n" , + ccmni->index, dev->stats.tx_packets, + txqt, ccmni->tx_busy_cnt[txqt]);
What is the purpose of this message?
Quoted 17 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +17
-0+ }else { + ccmni->tx_busy_cnt[txqt]++; + } + +return NETDEV_TX_BUSY ; + } + + dev->stats.tx_packets++; + dev->stats.tx_bytes += skb_len; +if (ccmni->tx_busy_cnt[txqt] >10 ) { +netdev_notice (dev,"[TX]CCMNI:%d TX busy:tx_pkt=%ld(ack=%d) retries=%ld\n" , + ccmni->index, dev->stats.tx_packets, + txqt, ccmni->tx_busy_cnt[txqt]); + } + ccmni->tx_busy_cnt[txqt] =0 ; + +return NETDEV_TX_OK ;
drivers/net/wwan/t7xx/t7xx_netdev.c line 197
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +10
-0+} + +static int ccmni_change_mtu (struct net_device *dev,int new_mtu) +{ +if (new_mtu >CCMNI_MTU_MAX ) +return -EINVAL ; + + dev->mtu = new_mtu; +return 0 ; +}
You do not need this function at all. You already specify the max_mtu value in the ccmni_wwan_setup(), so the network core code will be happy to check a user requested MTU against max_mtu for you.
drivers/net/wwan/t7xx/t7xx_netdev.c line 252
Quoted 7 lines
...
drivers/net/wwan/t7xx/t7xx_netdev.c +5
-0+static void ccmni_pre_stop (struct ccmni_ctl_block *ctlb) +{ +} + +static void ccmni_pos_stop (struct ccmni_ctl_block *ctlb)
Please consider renaming this function to ccmni_post_stop(). It is quite hard to figure out what position should be stopped on first code reading.
drivers/net/wwan/t7xx/t7xx_netdev.c line 279
Quoted 13 lines
...
drivers/net/wwan/t7xx/t7xx_netdev.c +12
-0+static void ccmni_wwan_setup (struct net_device *dev) +{ + dev->header_ops =NULL ; + dev->hard_header_len +=sizeof (struct ccci_header ); + + dev->mtu =WWAN_DEFAULT_MTU ; + dev->max_mtu =CCMNI_MTU_MAX ; + dev->tx_queue_len =CCMNI_TX_QUEUE ; + dev->watchdog_timeo =CCMNI_NETDEV_WDT_TO ; +/* ccmni is a pure IP device */ + dev->flags = (IFF_POINTOPOINT |IFF_NOARP ) + & ~(IFF_BROADCAST |IFF_MULTICAST );
You do not need to reset flags on the initial assignment. Just
dev->flags = IFF_POINTOPOINT | IFF_NOARP;
would be enough.
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +5
-0+/* not supporting VLAN */ + dev->features =NETIF_F_VLAN_CHALLENGED ; + + dev->features |=NETIF_F_SG ; + dev->hw_features |=NETIF_F_SG ;
drivers/net/wwan/t7xx/t7xx_netdev.c line 295
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +10
-0+ +/* uplink checksum offload */ + dev->features |=NETIF_F_HW_CSUM ; + dev->hw_features |=NETIF_F_HW_CSUM ; + +/* downlink checksum offload */ + dev->features |=NETIF_F_RXCSUM ; + dev->hw_features |=NETIF_F_RXCSUM ; + + dev->addr_len =ETH_ALEN ;
You do not need to configure HW address length as the modem is a pure IP device. Just drop the above line or explicitly set address length to zero.
drivers/net/wwan/t7xx/t7xx_netdev.c line 302
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +6
-0+/* use kernel default free_netdev() function */ + dev->needs_free_netdev = true; + +/* no need to free again because of free_netdev() */ + dev->priv_destructor =NULL ; + dev->type =ARPHRD_PPP ;
Use ARPHRD_NONE here since the modem is a pure IP device. Or you could use ARPHRD_RAWIP depending on how you would like to allocate the link IPv6 address. If in doubt then ARPHRD_NONE is a good starting point.
drivers/net/wwan/t7xx/t7xx_netdev.c line 305
Quoted 2 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +2
-0+ dev->netdev_ops = &ccmni_netdev_ops; +eth_random_addr (dev->dev_addr);
You do not need this random address generation.
drivers/net/wwan/t7xx/t7xx_netdev.c line 428
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +5
-0+} +static void ccmni_recv_skb (struct mtk_pci_dev *mtk_dev,int netif_id,struct sk_buff *skb) +{ + pkt_type = skb->data[0 ] &SBD_PACKET_TYPE_MASK ; +ccmni_make_etherframe (dev, skb->data -ETH_HLEN , dev->dev_addr, pkt_type);
As I wrote above, you do not need to forge an Ethernet header for pure IP devices.
drivers/net/wwan/t7xx/t7xx_netdev.c line 439
Quoted 11 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +11
-0+skb_set_mac_header (skb, -ETH_HLEN ); +skb_reset_network_header (skb); + skb->dev = dev; +if (pkt_type ==IPV6_VERSION ) + skb->protocol =htons (ETH_P_IPV6 ); +else + skb->protocol =htons (ETH_P_IP ); + + skb_len = skb->len; + +netif_rx_any_context (skb);
Did you consider using NAPI for the packet Rx path? This should improve Rx performance.
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_netdev.c +3
-0+ dev->stats.rx_packets++; + dev->stats.rx_bytes += skb_len; +}
[skipped]
drivers/net/wwan/t7xx/t7xx_netdev.h line 34
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_netdev.h +1
-0+#define CCMNI_TX_QUEUE 1000
Is this a really carefully selected queue depth limit, or just an arbitrary value? If the last one, then feel free to use the DEFAULT_TX_QUEUE_LEN macro.
drivers/net/wwan/t7xx/t7xx_netdev.h line 38
Quoted 3 lines
..
drivers/net/wwan/t7xx/t7xx_netdev.h +2
-0+#define IPV4_VERSION 0x40 +#define IPV6_VERSION 0x60
Just curious why the _VERSION suffix? Why not, for example, PKT_TYPE_ prefix?
--
Sergey
Martinez, Ricardo
reviewerRe: [PATCH v2 09/14] net: wwan: t7xx: Add WWAN network interface
Quoted 8 lines · Sergey Ryazanov
Quoted 6 lines · Ricardo Martinez
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 28 lines
Quoted 28 lines
drivers/net/wwan/t7xx/t7xx_netdev.c new file +28
-0+static enum txq_type get_txq_type (struct sk_buff *skb) +{ +u32 total_len, payload_len, l4_off; +bool tcp_syn_fin_rst, is_tcp; +struct ipv6hdr *ip6h; +struct tcphdr *tcph; +struct iphdr *ip4h; +u32 packet_type; +__be16 frag_off; + + packet_type = skb->data[0 ] &SBD_PACKET_TYPE_MASK ; +if (packet_type ==IPV6_VERSION ) { + ip6h = (struct ipv6hdr *)skb->data; + total_len =sizeof (struct ipv6hdr ) +ntohs (ip6h->payload_len); + l4_off =ipv6_skip_exthdr (skb,sizeof (struct ipv6hdr ), &ip6h->nexthdr, &frag_off); + tcph = (struct tcphdr *)(skb->data + l4_off); + is_tcp = ip6h->nexthdr ==IPPROTO_TCP ; + payload_len = total_len - l4_off - (tcph->doff <<2 ); + }else if (packet_type ==IPV4_VERSION ) { + ip4h = (struct iphdr *)skb->data; + tcph = (struct tcphdr *)(skb->data + (ip4h->ihl <<2 )); + is_tcp = ip4h->protocol ==IPPROTO_TCP ; + payload_len =ntohs (ip4h->tot_len) - (ip4h->ihl <<2 ) - (tcph->doff <<2 ); + }else { +return TXQ_NORMAL ; + } + + tcp_syn_fin_rst = tcph->syn || tcph->fin || tcph->rst;
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_netdev.c line 78
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_netdev.c new file +5
-0+if (is_tcp && !payload_len && !tcp_syn_fin_rst) +return TXQ_FAST ; + +return TXQ_NORMAL ; +}I am wondering how much modem performance has improved with this optimization compared to the performance loss on each packet due to the cache miss? Do you have any measurement results?
No performance gains observed in the latest tests, this is going to be removed for the
next iteration.
Quoted 19 lines
Quoted 18 lines
drivers/net/wwan/t7xx/t7xx_netdev.c new file +18
-0+static u16 ccmni_select_queue (struct net_device *dev,struct sk_buff *skb, +struct net_device *sb_dev) +{ +struct ccmni_instance *ccmni; + + ccmni =netdev_priv (dev); + +if (ccmni->ctlb->capability &NIC_CAP_DATA_ACK_DVD ) +return get_txq_type (skb); + +return TXQ_NORMAL ; +} + +static int ccmni_open (struct net_device *dev) +{ +struct ccmni_instance *ccmni; + + ccmni =wwan_netdev_drvpriv (dev);
[skipped]
Quoted 5 lines
Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_netdev.c new file +5
-0+skb_set_mac_header (skb, -ETH_HLEN ); +skb_reset_network_header (skb); + skb->dev = dev; +if (pkt_type ==IPV6_VERSION ) + skb->protocol =htons (ETH_P_IPV6 );
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_netdev.c line 439
Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_netdev.c new file +6
-0+else + skb->protocol =htons (ETH_P_IP ); + + skb_len = skb->len; + +netif_rx_any_context (skb);Did you consider using NAPI for the packet Rx path? This should improve Rx performance.
Yes, NAPI implementation is in the plan.
Quoted 11 lines
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_netdev.c new file +3
-0+ dev->stats.rx_packets++; + dev->stats.rx_bytes += skb_len; +}[skipped]
drivers/net/wwan/t7xx/t7xx_netdev.h line 34
Quoted 3 lines
drivers/net/wwan/t7xx/t7xx_netdev.h +1
-0+#define CCMNI_TX_QUEUE 1000Is this a really carefully selected queue depth limit, or just an arbitrary value? If the last one, then feel free to use the
DEFAULT_TX_QUEUE_LENmacro.
Changing this to DEFAULT_TX_QUEUE_LEN for the next iteration
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_netdev.h line 38
Quoted 3 lines
..
drivers/net/wwan/t7xx/t7xx_netdev.h +2
-0+#define IPV4_VERSION 0x40 +#define IPV6_VERSION 0x60Just curious why the
_VERSIONsuffix? Why not, for example,PKT_TYPE_prefix?
Nothing special about _VERSION, but it does look a bit weird, will use PKT_TYPE_ as suggested
Quoted 2 lines
--
Sergey
Ricardo
Sergey Ryazanov
maintainerRe: [PATCH v2 09/14] net: wwan: t7xx: Add WWAN network interface
Quoted 9 lines · Ricardo
Quoted 5 lines · Sergey Ryazanov
drivers/net/wwan/t7xx/t7xx_netdev.h line 38
Quoted 2 lines · Ricardo Martinez
drivers/net/wwan/t7xx/t7xx_netdev.h new file +2
-0+#define IPV4_VERSION 0x40 +#define IPV6_VERSION 0x60Just curious why the
_VERSIONsuffix? Why not, for example,PKT_TYPE_prefix?Nothing special about
_VERSION, but it does look a bit weird, will usePKT_TYPE_as suggested
I checked the driver code again and found that these constants are really used to distinguish between IPv4 and IPv6 packets by checking the first byte of the data packet (IP header version field).
Now I am wondering, does the modem firmware report a packet type in one of the BAT or PIT headers? If the modem is already reporting a packet type, then it is better to use the provided information instead of touching the packet data. Otherwise, if the modem does not explicitly report a packet type, and you have to check the version field of the IP header, then it seems Ok to keep the names of these constants as they are (with the _VERSION suffix).
Signature · 1 line
Sergey
Martinez, Ricardo
reviewerRe: [PATCH v2 09/14] net: wwan: t7xx: Add WWAN network interface
Hi Sergey,
Quoted 13 lines · Sergey Ryazanov
Quoted 7 lines · Ricardo
Quoted 4 lines · Sergey Ryazanov
drivers/net/wwan/t7xx/t7xx_netdev.h line 38
Quoted 2 lines · Ricardo Martinez
drivers/net/wwan/t7xx/t7xx_netdev.h new file +2
-0+#define IPV4_VERSION 0x40 +#define IPV6_VERSION 0x60Just curious why the
_VERSIONsuffix? Why not, for example,PKT_TYPE_prefix?Nothing special about
_VERSION, but it does look a bit weird, will usePKT_TYPE_as suggestedI checked the driver code again and found that these constants are really used to distinguish between IPv4 and IPv6 packets by checking the first byte of the data packet (IP header version field).
Quoted 7 lines
Now I am wondering, does the modem firmware report a packet type in one of the BAT or PIT headers? If the modem is already reporting a packet type, then it is better to use the provided information instead of touching the packet data. Otherwise, if the modem does not explicitly report a packet type, and you have to check the version field of the IP header, then it seems Ok to keep the names of these constants as they are (with the
_VERSIONsuffix).
Actually, there is a bit in the PIT header for the packet type, I'll make the driver
use it instead of looking at the data packet.
Ricardo Martinez
reviewerPATCH v2 10/14 net: wwan: t7xx: Introduce power management support
In reply to Ricardo MartinezFrom: Haijun Lio <[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 | 122 +++++- drivers/net/wwan/t7xx/t7xx_hif_cldma.h | 1 + drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c | 98 +++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h | 1 + drivers/net/wwan/t7xx/t7xx_mhccif.c | 16 + drivers/net/wwan/t7xx/t7xx_pci.c | 435 +++++++++++++++++++++ drivers/net/wwan/t7xx/t7xx_pci.h | 45 +++ drivers/net/wwan/t7xx/t7xx_state_monitor.c | 2 + 8 files changed, 719 insertions(+), 1 deletion(-)
drivers/net/wwan/t7xx/t7xx_hif_cldma.c +121 -1
@@ -1382,6 +1382,120 @@ void cldma_exception(enum cldma_id hif_id, enum hif_ex_stage stage) } } +static void cldma_resume_early (struct mtk_pci_dev *mtk_dev,void *entity_param) +{ +struct cldma_hw_info *hw_info; +struct cldma_ctrl *md_ctrl; +unsigned long flags; +int qno_t; + + md_ctrl = entity_param; + hw_info = &md_ctrl->hw_info; +spin_lock_irqsave (&md_ctrl->cldma_lock, flags); +cldma_hw_restore (hw_info); + +for (qno_t =0 ; qno_t <CLDMA_TXQ_NUM ; qno_t++) { +cldma_hw_set_start_address (hw_info, qno_t, md_ctrl->txq[qno_t].tx_xmit->gpd_addr, + false); +cldma_hw_set_start_address (hw_info, qno_t, md_ctrl->rxq[qno_t].tr_done->gpd_addr, + true); + } + +cldma_enable_irq (md_ctrl); +cldma_hw_start_queue (hw_info,CLDMA_ALL_Q , true); + md_ctrl->rxq_active |=TXRX_STATUS_BITMASK ; +cldma_hw_dismask_eqirq (hw_info,CLDMA_ALL_Q , true); +cldma_hw_dismask_txrxirq (hw_info,CLDMA_ALL_Q , true); +spin_unlock_irqrestore (&md_ctrl->cldma_lock, flags); +} + +static int cldma_resume (struct mtk_pci_dev *mtk_dev,void *entity_param) +{ +struct cldma_ctrl *md_ctrl; +unsigned long flags; + + md_ctrl = entity_param; +spin_lock_irqsave (&md_ctrl->cldma_lock, flags); + md_ctrl->txq_active |=TXRX_STATUS_BITMASK ; +cldma_hw_dismask_txrxirq (&md_ctrl->hw_info,CLDMA_ALL_Q , false); +cldma_hw_dismask_eqirq (&md_ctrl->hw_info,CLDMA_ALL_Q , false); +spin_unlock_irqrestore (&md_ctrl->cldma_lock, flags); +if (md_ctrl->hif_id ==ID_CLDMA1 ) +mhccif_mask_clr (mtk_dev,D2H_SW_INT_MASK ); + +return 0 ; +} + +static void cldma_suspend_late (struct mtk_pci_dev *mtk_dev,void *entity_param) +{ +struct cldma_hw_info *hw_info; +struct cldma_ctrl *md_ctrl; +unsigned long flags; + + md_ctrl = entity_param; + hw_info = &md_ctrl->hw_info; +spin_lock_irqsave (&md_ctrl->cldma_lock, flags); +cldma_hw_mask_eqirq (hw_info,CLDMA_ALL_Q , true); +cldma_hw_mask_txrxirq (hw_info,CLDMA_ALL_Q , true); + md_ctrl->rxq_active &= ~TXRX_STATUS_BITMASK ; +cldma_hw_stop_queue (hw_info,CLDMA_ALL_Q , true); +cldma_clear_ip_busy (hw_info); +cldma_disable_irq (md_ctrl); +spin_unlock_irqrestore (&md_ctrl->cldma_lock, flags); +} + +static int cldma_suspend (struct mtk_pci_dev *mtk_dev,void *entity_param) +{ +struct cldma_hw_info *hw_info; +struct cldma_ctrl *md_ctrl; +unsigned long flags; + + md_ctrl = entity_param; + hw_info = &md_ctrl->hw_info; +if (md_ctrl->hif_id ==ID_CLDMA1 ) +mhccif_mask_set (mtk_dev,D2H_SW_INT_MASK ); + +spin_lock_irqsave (&md_ctrl->cldma_lock, flags); +cldma_hw_mask_eqirq (hw_info,CLDMA_ALL_Q , false); +cldma_hw_mask_txrxirq (hw_info,CLDMA_ALL_Q , false); + md_ctrl->txq_active &= ~TXRX_STATUS_BITMASK ; +cldma_hw_stop_queue (hw_info,CLDMA_ALL_Q , false); + md_ctrl->txq_started =0 ; +spin_unlock_irqrestore (&md_ctrl->cldma_lock, flags); +return 0 ; +} + +static int cldma_pm_init (struct cldma_ctrl *md_ctrl) +{ + md_ctrl->pm_entity =kzalloc (sizeof (*md_ctrl->pm_entity),GFP_KERNEL ); +if (!md_ctrl->pm_entity) +return -ENOMEM ; + + md_ctrl->pm_entity->entity_param = md_ctrl; +if (md_ctrl->hif_id ==ID_CLDMA1 ) + md_ctrl->pm_entity->id =PM_ENTITY_ID_CTRL1 ; +else + md_ctrl->pm_entity->id =PM_ENTITY_ID_CTRL2 ; + + md_ctrl->pm_entity->suspend = cldma_suspend; + md_ctrl->pm_entity->suspend_late = cldma_suspend_late; + md_ctrl->pm_entity->resume = cldma_resume; + md_ctrl->pm_entity->resume_early = cldma_resume_early; + +return mtk_pci_pm_entity_register (md_ctrl->mtk_dev, md_ctrl->pm_entity); +} + +static int cldma_pm_uninit (struct cldma_ctrl *md_ctrl) +{ +if (!md_ctrl->pm_entity) +return -EINVAL ; + +mtk_pci_pm_entity_unregister (md_ctrl->mtk_dev, md_ctrl->pm_entity); +kfree_sensitive (md_ctrl->pm_entity); + md_ctrl->pm_entity =NULL ; +return 0 ; +} +void cldma_hif_hw_init (enum cldma_id hif_id) {struct cldma_hw_info *hw_info;
@@ -1423,6 +1537,7 @@ static irqreturn_t cldma_isr_handler(int irq, void *data)* cldma_init() - Initialize CLDMA * @hif_id: CLDMA ID (ID_CLDMA0 or ID_CLDMA1) * +* allocate and initialize device power management entity * initialize HIF TX/RX queue structure * register CLDMA callback isr with PCIe driver *
@@ -1433,7 +1548,7 @@ int cldma_init(enum cldma_id hif_id)struct cldma_hw_info *hw_info;struct cldma_ctrl *md_ctrl;struct mtk_modem *md; -int i; +int ret, i; md_ctrl =md_cd_get (hif_id); md = md_ctrl->mtk_dev->md;
@@ -1442,6 +1557,9 @@ int cldma_init(enum cldma_id hif_id) md_ctrl->rxq_active =0 ; md_ctrl->is_late_init = false; hw_info = &md_ctrl->hw_info; + ret =cldma_pm_init (md_ctrl); +if (ret) +return ret;spin_lock_init (&md_ctrl->cldma_lock);/* initialize HIF queue structure */
@@ -1516,4 +1634,6 @@ void cldma_exit(enum cldma_id hif_id) md_ctrl->rxq[i].worker =NULL ; } } + +cldma_pm_uninit (md_ctrl); }
drivers/net/wwan/t7xx/t7xx_hif_cldma.h +1 -0
@@ -102,6 +102,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 cldma_hw_info 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 +98 -0
122 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h +1 -0
@@ -245,6 +245,7 @@ struct dpmaif_callbacks {struct dpmaif_ctrl {struct device *dev;struct mtk_pci_dev *mtk_dev; +struct md_pm_entity dpmaif_pm_entity;enum dpmaif_state state;bool dpmaif_sw_init_done;struct dpmaif_hw_info hif_hw_info;
drivers/net/wwan/t7xx/t7xx_mhccif.c +16 -0
@@ -18,6 +18,11 @@#include "t7xx_pci.h" #include "t7xx_pcie_mac.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 mhccif_clear_interrupts (struct mtk_pci_dev *mtk_dev,u32 mask) {void __iomem *mhccif_pbase;
@@ -52,6 +57,17 @@ static irqreturn_t mhccif_isr_thread(int irq, void *data)/* Clear 2 & 1 level interrupts */ mhccif_clear_interrupts (mtk_dev, int_sts); +if (int_sts &D2H_INT_SR_ACK ) +complete (&mtk_dev->pm_sr_ack); + +/* Use the 1 bits to avoid low power bits */ +iowrite32 (L1_DISABLE_BIT (1 ),IREG_BASE (mtk_dev) +DIS_ASPM_LOWPWR_CLR_0 ); + + int_sts =mhccif_read_sw_int_sts (mtk_dev); +if (!int_sts) +iowrite32 (L1_1_DISABLE_BIT (1 ) |L1_2_DISABLE_BIT (1 ), +IREG_BASE (mtk_dev) +DIS_ASPM_LOWPWR_CLR_0 ); +/* Enable corresponding interrupt */ mtk_pcie_mac_set_int (mtk_dev,MHCCIF_INT );return IRQ_HANDLED ;
drivers/net/wwan/t7xx/t7xx_pci.c +435 -0
466 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_pci.h +45 -0
66 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_state_monitor.c +2 -0
@@ -173,6 +173,7 @@ static void fsm_routine_exception(struct ccci_fsm_ctl *ctl, struct ccci_fsm_commcase EXCEPTION_EVENT :fsm_broadcast_state (ctl,MD_STATE_EXCEPTION ); +mtk_pci_pm_exp_detected (ctl->md->mtk_dev);mtk_md_exception_handshake (ctl->md); cnt =0 ;while (cnt <MD_EX_REC_OK_TIMEOUT_MS /EVENT_POLL_INTERVAL_MS ) {
@@ -339,6 +340,7 @@ static void fsm_routine_starting(struct ccci_fsm_ctl *ctl)fsm_routine_exception (ctl,NULL ,EXCEPTION_HS_TIMEOUT ); }else { +mtk_pci_pm_init_late (md->mtk_dev);fsm_routine_ready (ctl); } }
Signature · 1 line
2.17.1
Ricardo Martinez
reviewerPATCH v2 11/14 net: wwan: t7xx: Runtime PM
In reply to Ricardo MartinezFrom: Haijun Lio <[email protected]>
Enables runtime power management callbacks including runtime_suspend and runtime_resume. Autosuspend is used to prevent overhead by frequent wake-ups.
--- drivers/net/wwan/t7xx/t7xx_hif_cldma.c | 13 +++++++++++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 16 ++++++++++++++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c | 15 +++++++++++++++ drivers/net/wwan/t7xx/t7xx_pci.c | 21 +++++++++++++++++++++ 4 files changed, 65 insertions(+)
drivers/net/wwan/t7xx/t7xx_hif_cldma.c +13 -0
@@ -22,6 +22,7 @@#include <linux/kernel.h> #include <linux/list.h> #include <linux/mutex.h> +#include <linux/pm_runtime.h> #include <linux/skbuff.h> #include "t7xx_cldma.h"
@@ -310,6 +311,8 @@ static void cldma_rx_done(struct work_struct *work)/* enable RX_DONE && EMPTY interrupt */ cldma_hw_dismask_txrxirq (&md_ctrl->hw_info, queue->index, true);cldma_hw_dismask_eqirq (&md_ctrl->hw_info, queue->index, true); +pm_runtime_mark_last_busy (md_ctrl->dev); +pm_runtime_put_autosuspend (md_ctrl->dev); }static int cldma_gpd_tx_collect (struct cldma_queue *queue)
@@ -451,6 +454,8 @@ static void cldma_tx_done(struct work_struct *work) }spin_unlock_irqrestore (&md_ctrl->cldma_lock, flags); +pm_runtime_mark_last_busy (md_ctrl->dev); +pm_runtime_put_autosuspend (md_ctrl->dev); } static void cldma_ring_free(struct cldma_ctrl *md_ctrl,
@@ -674,6 +679,7 @@ static void cldma_irq_work_cb(struct cldma_ctrl *md_ctrl)if (l2_tx_int & (TXRX_STATUS_BITMASK |EMPTY_STATUS_BITMASK )) {for (i =0 ; i <CLDMA_TXQ_NUM ; i++) {if (l2_tx_int &BIT (i)) { +pm_runtime_get (md_ctrl->dev);/* disable TX_DONE interrupt */ cldma_hw_mask_eqirq (hw_info, i, false);cldma_hw_mask_txrxirq (hw_info, i, false);
@@ -702,6 +708,7 @@ static void cldma_irq_work_cb(struct cldma_ctrl *md_ctrl)if (l2_rx_int & (TXRX_STATUS_BITMASK |EMPTY_STATUS_BITMASK )) {for (i =0 ; i <CLDMA_RXQ_NUM ; i++) {if (l2_rx_int & (BIT (i) |EQ_STA_BIT (i))) { +pm_runtime_get (md_ctrl->dev);/* disable RX_DONE and QUEUE_EMPTY interrupt */ cldma_hw_mask_eqirq (hw_info, i, true);cldma_hw_mask_txrxirq (hw_info, i, true);
@@ -1133,8 +1140,12 @@ int cldma_send_skb(enum cldma_id hif_id, int qno, struct sk_buff *skb, bool skb_struct cldma_queue *queue;unsigned long flags;int ret =0 ; +int val; md_ctrl =md_cd_get (hif_id); + val =pm_runtime_resume_and_get (md_ctrl->dev); +if (val <0 && val != -EACCES ) +return val;if (qno >=CLDMA_TXQ_NUM ) { ret = -EINVAL ;
@@ -1199,6 +1210,8 @@ int cldma_send_skb(enum cldma_id hif_id, int qno, struct sk_buff *skb, bool skb_ }while (!ret); exit: +pm_runtime_mark_last_busy (md_ctrl->dev); +pm_runtime_put_autosuspend (md_ctrl->dev);return ret; }
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +16 -0
@@ -22,6 +22,7 @@#include <linux/kthread.h> #include <linux/list.h> #include <linux/mm.h> +#include <linux/pm_runtime.h> #include <linux/skbuff.h> #include <linux/slab.h> #include <linux/spinlock.h>
@@ -1039,6 +1040,7 @@ static void dpmaif_rxq_work(struct work_struct *work) {struct dpmaif_ctrl *dpmaif_ctrl;struct dpmaif_rx_queue *rxq; +int ret; rxq = container_of(work, struct dpmaif_rx_queue, dpmaif_rxq_work); dpmaif_ctrl = rxq->dpmaif_ctrl;
@@ -1053,8 +1055,14 @@ static void dpmaif_rxq_work(struct work_struct *work)return ; } + ret =pm_runtime_resume_and_get (dpmaif_ctrl->dev); +if (ret <0 && ret != -EACCES ) +return ; +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 ); }
@@ -1417,9 +1425,14 @@ static void dpmaif_bat_release_work(struct work_struct *work) {struct dpmaif_ctrl *dpmaif_ctrl;struct dpmaif_rx_queue *rxq; +int ret; dpmaif_ctrl = container_of(work, struct dpmaif_ctrl, bat_release_work); + 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 ];
@@ -1427,6 +1440,9 @@ static void dpmaif_bat_release_work(struct work_struct *work)dpmaif_dl_pkt_bat_release_and_add (rxq);/* frag BAT release and add */ dpmaif_dl_frag_bat_release_and_add (rxq); + +pm_runtime_mark_last_busy (dpmaif_ctrl->dev); +pm_runtime_put_autosuspend (dpmaif_ctrl->dev); }int dpmaif_bat_release_work_alloc (struct dpmaif_ctrl *dpmaif_ctrl)
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c +15 -0
@@ -18,6 +18,7 @@#include <linux/kernel.h> #include <linux/kthread.h> #include <linux/list.h> +#include <linux/pm_runtime.h> #include <linux/spinlock.h> #include "t7xx_common.h"
@@ -167,6 +168,10 @@ static void dpmaif_tx_done(struct work_struct *work) txq = container_of(work, struct dpmaif_tx_queue, dpmaif_tx_work); dpmaif_ctrl = txq->dpmaif_ctrl; + ret =pm_runtime_resume_and_get (dpmaif_ctrl->dev); +if (ret <0 && ret != -EACCES ) +return ; + ret =dpmaif_tx_release (dpmaif_ctrl, txq->index, txq->drb_size_cnt); if (ret == -EAGAIN || (dpmaif_hw_check_clr_ul_done_status(&dpmaif_ctrl->hif_hw_info, txq->index) &&
@@ -179,6 +184,9 @@ static void dpmaif_tx_done(struct work_struct *work)dpmaif_clr_ip_busy_sts (&dpmaif_ctrl->hif_hw_info);dpmaif_unmask_ulq_interrupt (dpmaif_ctrl, txq->index); } + +pm_runtime_mark_last_busy (dpmaif_ctrl->dev); +pm_runtime_put_autosuspend (dpmaif_ctrl->dev); } static void set_drb_msg(struct dpmaif_ctrl *dpmaif_ctrl,
@@ -513,6 +521,7 @@ static void do_tx_hw_push(struct dpmaif_ctrl *dpmaif_ctrl)static int dpmaif_tx_hw_push_thread (void *arg) {struct dpmaif_ctrl *dpmaif_ctrl; +int ret; dpmaif_ctrl = arg;while (!kthread_should_stop ()) {
@@ -528,7 +537,13 @@ static int dpmaif_tx_hw_push_thread(void *arg)if (kthread_should_stop ())break ; + ret =pm_runtime_resume_and_get (dpmaif_ctrl->dev); +if (ret <0 && ret != -EACCES ) +return ret; +do_tx_hw_push (dpmaif_ctrl); +pm_runtime_mark_last_busy (dpmaif_ctrl->dev); +pm_runtime_put_autosuspend (dpmaif_ctrl->dev); }return 0 ;
drivers/net/wwan/t7xx/t7xx_pci.c +21 -0
@@ -20,6 +20,7 @@#include <linux/module.h> #include <linux/mutex.h> #include <linux/pci.h> +#include <linux/pm_runtime.h> #include <linux/spinlock.h> #include "t7xx_mhccif.h"
@@ -34,6 +35,7 @@#define PCI_EREG_BASE 2#define PM_ACK_TIMEOUT_MS 1500 +#define PM_AUTOSUSPEND_MS 20000#define PM_RESOURCE_POLL_TIMEOUT_US 10000#define PM_RESOURCE_POLL_STEP_US 100
@@ -78,6 +80,8 @@ static int mtk_pci_pm_init(struct mtk_pci_dev *mtk_dev)atomic_set (&mtk_dev->md_pm_state,MTK_PM_INIT );iowrite32 (L1_DISABLE_BIT (0 ),IREG_BASE (mtk_dev) +DIS_ASPM_LOWPWR_SET_0 ); +pm_runtime_set_autosuspend_delay (&pdev->dev,PM_AUTOSUSPEND_MS ); +pm_runtime_use_autosuspend (&pdev->dev);return mtk_wait_pm_config (mtk_dev); }
@@ -92,6 +96,8 @@ void mtk_pci_pm_init_late(struct mtk_pci_dev *mtk_dev) D2H_INT_RESUME_ACK_AP);iowrite32 (L1_DISABLE_BIT (0 ),IREG_BASE (mtk_dev) +DIS_ASPM_LOWPWR_CLR_0 );atomic_set (&mtk_dev->md_pm_state,MTK_PM_RESUMED ); + +pm_runtime_put_noidle (&mtk_dev->pdev->dev); }static int mtk_pci_pm_reinit (struct mtk_pci_dev *mtk_dev)
@@ -101,6 +107,8 @@ static int mtk_pci_pm_reinit(struct mtk_pci_dev *mtk_dev)*/ atomic_set (&mtk_dev->md_pm_state,MTK_PM_INIT ); +pm_runtime_get_noresume (&mtk_dev->pdev->dev); +iowrite32 (L1_DISABLE_BIT (0 ),IREG_BASE (mtk_dev) +DIS_ASPM_LOWPWR_SET_0 );return mtk_wait_pm_config (mtk_dev); }
@@ -405,6 +413,7 @@ static int __mtk_pci_pm_resume(struct pci_dev *pdev, bool state_check) mtk_dev->rgu_pci_irq_en = true;mtk_pcie_mac_set_int (mtk_dev,SAP_RGU_INT );iowrite32 (L1_DISABLE_BIT (0 ),IREG_BASE (mtk_dev) +DIS_ASPM_LOWPWR_CLR_0 ); +pm_runtime_mark_last_busy (&pdev->dev);atomic_set (&mtk_dev->md_pm_state,MTK_PM_RESUMED );return ret;
@@ -446,6 +455,16 @@ static int mtk_pci_pm_thaw(struct device *dev)return __mtk_pci_pm_resume (to_pci_dev (dev), false); } +static int mtk_pci_pm_runtime_suspend (struct device *dev) +{ +return __mtk_pci_pm_suspend (to_pci_dev (dev)); +} + +static int mtk_pci_pm_runtime_resume (struct device *dev) +{ +return __mtk_pci_pm_resume (to_pci_dev (dev), true); +} +static const struct dev_pm_ops mtk_pci_pm_ops = { .suspend = mtk_pci_pm_suspend, .resume = mtk_pci_pm_resume,
@@ -455,6 +474,8 @@ static const struct dev_pm_ops mtk_pci_pm_ops = { .poweroff = mtk_pci_pm_suspend, .restore = mtk_pci_pm_resume, .restore_noirq = mtk_pci_pm_resume_noirq, + .runtime_suspend = mtk_pci_pm_runtime_suspend, + .runtime_resume = mtk_pci_pm_runtime_resume };static int mtk_request_irq (struct pci_dev *pdev)
Signature · 1 line
2.17.1
Ricardo Martinez
reviewerPATCH v2 12/14 net: wwan: t7xx: Device deep sleep lock/unlock
In reply to Ricardo MartinezFrom: Haijun Lio <[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 | 11 +++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 24 ++++-- drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c | 39 ++++++--- drivers/net/wwan/t7xx/t7xx_mhccif.c | 3 + drivers/net/wwan/t7xx/t7xx_pci.c | 95 ++++++++++++++++++++++ drivers/net/wwan/t7xx/t7xx_pci.h | 10 +++ 6 files changed, 166 insertions(+), 16 deletions(-)
drivers/net/wwan/t7xx/t7xx_hif_cldma.c +11 -0
@@ -1147,6 +1147,7 @@ int cldma_send_skb(enum cldma_id hif_id, int qno, struct sk_buff *skb, bool skb_if (val <0 && val != -EACCES )return val; +mtk_pci_disable_sleep (md_ctrl->mtk_dev);if (qno >=CLDMA_TXQ_NUM ) { ret = -EINVAL ; goto exit;
@@ -1182,6 +1183,11 @@ int cldma_send_skb(enum cldma_id hif_id, int qno, struct sk_buff *skb, bool skb_ queue->tx_xmit =cldma_ring_step_forward (queue->tr_ring, tx_req);spin_unlock_irqrestore (&queue->ring_lock, flags); +if (!mtk_pci_sleep_disable_complete (md_ctrl->mtk_dev)) { + ret = -EBUSY ; +break ; + } +spin_lock_irqsave (&md_ctrl->cldma_lock, flags);cldma_hw_start_send (md_ctrl, qno);spin_unlock_irqrestore (&md_ctrl->cldma_lock, flags);
@@ -1189,6 +1195,10 @@ int cldma_send_skb(enum cldma_id hif_id, int qno, struct sk_buff *skb, bool skb_ }spin_unlock_irqrestore (&queue->ring_lock, flags); +if (!mtk_pci_sleep_disable_complete (md_ctrl->mtk_dev)) { + ret = -EBUSY ; +break ; + }/* check CLDMA status */ if (!cldma_hw_queue_status (&md_ctrl->hw_info, qno, false)) {
@@ -1210,6 +1220,7 @@ int cldma_send_skb(enum cldma_id hif_id, int qno, struct sk_buff *skb, bool skb_ }while (!ret); exit: +mtk_pci_enable_sleep (md_ctrl->mtk_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 +19 -5
@@ -40,6 +40,8 @@#define DPMAIF_RX_PUSH_THRESHOLD_MASK 0x7#define DPMAIF_NOTIFY_RELEASE_COUNT 128#define DPMAIF_POLL_PIT_TIME_US 20 +#define DPMAIF_POLL_RX_TIME_US 10 +#define DPMAIF_POLL_RX_TIMEOUT_US 200#define DPMAIF_POLL_PIT_MAX_TIME_US 2000#define DPMAIF_WQ_TIME_LIMIT_MS 2#define DPMAIF_CS_RESULT_PASS 0
@@ -1020,6 +1022,7 @@ static int dpmaif_rx_data_collect(struct dpmaif_ctrl *dpmaif_ctrl,return 0 ; } +/* call after mtk_pci_disable_sleep */ static void dpmaif_do_rx (struct dpmaif_ctrl *dpmaif_ctrl,struct dpmaif_rx_queue *rxq) {int ret;
@@ -1059,7 +1062,13 @@ static void dpmaif_rxq_work(struct work_struct *work)if (ret <0 && ret != -EACCES )return ; -dpmaif_do_rx (dpmaif_ctrl, rxq); +mtk_pci_disable_sleep (dpmaif_ctrl->mtk_dev); + +/* we can try blocking wait for lock resource here in process context */ +if (mtk_pci_sleep_disable_complete (dpmaif_ctrl->mtk_dev)) +dpmaif_do_rx (dpmaif_ctrl, rxq); + +mtk_pci_enable_sleep (dpmaif_ctrl->mtk_dev);pm_runtime_mark_last_busy (dpmaif_ctrl->dev);pm_runtime_put_autosuspend (dpmaif_ctrl->dev);
@@ -1433,14 +1442,19 @@ static void dpmaif_bat_release_work(struct work_struct *work)if (ret <0 && ret != -EACCES )return ; +mtk_pci_disable_sleep (dpmaif_ctrl->mtk_dev); +/* ALL RXQ use one BAT table, so choose DPF_RX_QNO_DFT */ rxq = &dpmaif_ctrl->rxq[DPF_RX_QNO_DFT ]; -/* normal BAT release and add */ -dpmaif_dl_pkt_bat_release_and_add (rxq); -/* frag BAT release and add */ -dpmaif_dl_frag_bat_release_and_add (rxq); +if (mtk_pci_sleep_disable_complete (dpmaif_ctrl->mtk_dev)) { +/* normal BAT release and add */ +dpmaif_dl_pkt_bat_release_and_add (rxq); +/* frag BAT release and add */ +dpmaif_dl_frag_bat_release_and_add (rxq); + } +mtk_pci_enable_sleep (dpmaif_ctrl->mtk_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 +28 -11
@@ -172,19 +172,26 @@ static void dpmaif_tx_done(struct work_struct *work)if (ret <0 && ret != -EACCES )return ; - ret =dpmaif_tx_release (dpmaif_ctrl, txq->index, txq->drb_size_cnt); -if (ret == -EAGAIN || - (dpmaif_hw_check_clr_ul_done_status (&dpmaif_ctrl->hif_hw_info, txq->index) && -dpmaif_no_remain_spurious_tx_done_intr (txq))) { -queue_work (dpmaif_ctrl->txq[txq->index].worker, - &dpmaif_ctrl->txq[txq->index].dpmaif_tx_work); -/* clear IP busy to give the device time to enter the low power state */ -dpmaif_clr_ip_busy_sts (&dpmaif_ctrl->hif_hw_info); - }else { -dpmaif_clr_ip_busy_sts (&dpmaif_ctrl->hif_hw_info); -dpmaif_unmask_ulq_interrupt (dpmaif_ctrl, txq->index); +/* The device may be in low power state. disable sleep if needed */ +mtk_pci_disable_sleep (dpmaif_ctrl->mtk_dev); + +/* ensure that we are not in deep sleep */ +if (mtk_pci_sleep_disable_complete (dpmaif_ctrl->mtk_dev)) { + ret =dpmaif_tx_release (dpmaif_ctrl, txq->index, txq->drb_size_cnt); +if (ret == -EAGAIN || + (dpmaif_hw_check_clr_ul_done_status (&dpmaif_ctrl->hif_hw_info, txq->index) && +dpmaif_no_remain_spurious_tx_done_intr (txq))) { +queue_work (dpmaif_ctrl->txq[txq->index].worker, + &dpmaif_ctrl->txq[txq->index].dpmaif_tx_work); +/* clear IP busy to give the device time to enter the low power state */ +dpmaif_clr_ip_busy_sts (&dpmaif_ctrl->hif_hw_info); + }else { +dpmaif_clr_ip_busy_sts (&dpmaif_ctrl->hif_hw_info); +dpmaif_unmask_ulq_interrupt (dpmaif_ctrl, txq->index); + } } +mtk_pci_enable_sleep (dpmaif_ctrl->mtk_dev);pm_runtime_mark_last_busy (dpmaif_ctrl->dev);pm_runtime_put_autosuspend (dpmaif_ctrl->dev); }
@@ -485,6 +492,8 @@ static bool check_all_txq_drb_lack(const struct dpmaif_ctrl *dpmaif_ctrl)static void do_tx_hw_push (struct dpmaif_ctrl *dpmaif_ctrl) { +bool first_time = true; + dpmaif_ctrl->txq_select_times =0 ; do { int txq_id;
@@ -499,6 +508,11 @@ static void do_tx_hw_push(struct dpmaif_ctrl *dpmaif_ctrl)if (ret >0 ) {int drb_send_cnt = ret; +/* wait for the PCIe resource locked done */ +if (first_time && + !mtk_pci_sleep_disable_complete (dpmaif_ctrl->mtk_dev)) +return ; +/* notify the dpmaif HW */ ret =dpmaif_ul_add_wcnt (dpmaif_ctrl, (unsigned char )txq_id, drb_send_cnt *DPMAIF_UL_DRB_ENTRY_WORD );
@@ -512,6 +526,7 @@ static void do_tx_hw_push(struct dpmaif_ctrl *dpmaif_ctrl) } } + first_time = false;cond_resched (); } while (!tx_lists_are_all_empty(dpmaif_ctrl) && !kthread_should_stop() &&
@@ -541,7 +556,9 @@ static int dpmaif_tx_hw_push_thread(void *arg)if (ret <0 && ret != -EACCES )return ret; +mtk_pci_disable_sleep (dpmaif_ctrl->mtk_dev);do_tx_hw_push (dpmaif_ctrl); +mtk_pci_enable_sleep (dpmaif_ctrl->mtk_dev);pm_runtime_mark_last_busy (dpmaif_ctrl->dev);pm_runtime_put_autosuspend (dpmaif_ctrl->dev); }
drivers/net/wwan/t7xx/t7xx_mhccif.c +3 -0
@@ -57,6 +57,9 @@ static irqreturn_t mhccif_isr_thread(int irq, void *data)/* Clear 2 & 1 level interrupts */ mhccif_clear_interrupts (mtk_dev, int_sts); +if (int_sts &D2H_INT_DS_LOCK_ACK ) +complete_all (&mtk_dev->sleep_lock_acquire); +if (int_sts &D2H_INT_SR_ACK )complete (&mtk_dev->pm_sr_ack);
drivers/net/wwan/t7xx/t7xx_pci.c +95 -0
129 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_pci.h +10 -0
@@ -17,6 +17,7 @@#include <linux/completion.h> #include <linux/mutex.h> #include <linux/pci.h> +#include <linux/spinlock.h> #include <linux/types.h> #include "t7xx_reg.h"
@@ -48,7 +49,10 @@ typedef irqreturn_t (*mtk_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
@@ -66,7 +70,10 @@ struct mtk_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;
@@ -103,6 +110,9 @@ struct md_pm_entity {void *entity_param; }; +void mtk_pci_disable_sleep (struct mtk_pci_dev *mtk_dev); +void mtk_pci_enable_sleep (struct mtk_pci_dev *mtk_dev); +int mtk_pci_sleep_disable_complete (struct mtk_pci_dev *mtk_dev);int mtk_pci_pm_entity_register (struct mtk_pci_dev *mtk_dev,struct md_pm_entity *pm_entity);int mtk_pci_pm_entity_unregister (struct mtk_pci_dev *mtk_dev,struct md_pm_entity *pm_entity);void mtk_pci_pm_init_late (struct mtk_pci_dev *mtk_dev);
Signature · 1 line
2.17.1
Ricardo Martinez
reviewerPATCH v2 13/14 net: wwan: t7xx: Add debug and test ports
In reply to Ricardo MartinezFrom: Haijun Lio <[email protected]>
Creates char and tty port infrastructure for debug and testing. Those ports support use cases such as:
* Modem log collection
* Memory dump
* Loop-back test
* Factory tests
* Device Service Streams
--- drivers/net/wwan/t7xx/Makefile | 3 + drivers/net/wwan/t7xx/t7xx_port.h | 2 + drivers/net/wwan/t7xx/t7xx_port_char.c | 424 ++++++++++++++++++++++++ drivers/net/wwan/t7xx/t7xx_port_proxy.c | 49 ++- drivers/net/wwan/t7xx/t7xx_port_proxy.h | 3 + drivers/net/wwan/t7xx/t7xx_port_tty.c | 191 +++++++++++ drivers/net/wwan/t7xx/t7xx_tty_ops.c | 205 ++++++++++++ drivers/net/wwan/t7xx/t7xx_tty_ops.h | 44 +++ 8 files changed, 920 insertions(+), 1 deletion(-) create mode 100644 drivers/net/wwan/t7xx/t7xx_port_char.c create mode 100644 drivers/net/wwan/t7xx/t7xx_port_tty.c create mode 100644 drivers/net/wwan/t7xx/t7xx_tty_ops.c create mode 100644 drivers/net/wwan/t7xx/t7xx_tty_ops.h
drivers/net/wwan/t7xx/Makefile +3 -0
@@ -19,3 +19,6 @@ mtk_t7xx-y:= t7xx_pci.o \ t7xx_hif_dpmaif_tx.o \ t7xx_hif_dpmaif_rx.o \ t7xx_netdev.o \ + t7xx_port_char.o \ + t7xx_port_tty.o \ + t7xx_tty_ops.o
drivers/net/wwan/t7xx/t7xx_port.h +2 -0
@@ -157,5 +157,7 @@ int port_write_room_to_md(struct t7xx_port *port);struct t7xx_port *port_get_by_minor (int minor);struct t7xx_port *port_get_by_name (char *port_name);int port_send_skb_to_md (struct t7xx_port *port,struct sk_buff *skb,bool blocking); +int port_register_device (const char *name,int major,int minor); +void port_unregister_device (int major,int minor);#endif /* __T7XX_PORT_H__ */
drivers/net/wwan/t7xx/t7xx_port_char.c new file +424 -0
424 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_port_proxy.c +48 -1
89 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_port_proxy.h +3 -0
@@ -82,8 +82,11 @@ struct port_msg {#define PORT_ENUM_VER_MISMATCH 0x00657272/* port operations mapping */ +extern struct port_ops char_port_ops;extern struct port_ops wwan_sub_port_ops;extern struct port_ops ctl_port_ops; +extern struct port_ops tty_port_ops; +extern struct tty_dev_ops tty_ops;int port_proxy_send_skb (struct t7xx_port *port,struct sk_buff *skb,bool from_pool);void port_proxy_set_seq_num (struct t7xx_port *port,struct ccci_header *ccci_h);
drivers/net/wwan/t7xx/t7xx_port_tty.c new file +191 -0
191 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_tty_ops.c new file +205 -0
205 lines not on this page · raw message
drivers/net/wwan/t7xx/t7xx_tty_ops.h new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.17.1
Sergey Ryazanov
maintainerRe: [PATCH v2 13/14] net: wwan: t7xx: Add debug and test ports
Quoted 7 lines · Ricardo Martinez
Creates char and tty port infrastructure for debug and testing. Those ports support use cases such as:
* Modem log collection
* Memory dump
* Loop-back test
* Factory tests
* Device Service Streams
A-ha. The purpose of chardev stuff in previous patches becomes much more clear.
Please do not do this in such a way. This is not an everyday usage operation to be supported via the chardev. Also this will require an end user to study another one bunch of custom vendor tools for quite common development tasks.
The kernel already has a rich set of frameworks for device debugging. If you need to update firmware use the devlink firmware updating facility, see e.g. Intel iosm driver for reference. For memory dumping you could utilize devlink or device coredump facilities (see ath10k driver for reference).
For other debugging tasks I recommend you to use debugfs. The WWAN subsystem could be extended to provide a driver with a common debugfs infrastructure (e.g. create common directory for WWAN devices, etc.).
As for modem logs, you could pipe them to the common kernel log via the dynamic debug logging or export them via the debugfs as well.
Loic, Johannes, do you have some other advice on how to facilitate the modem debugging/development tasks?
--
Sergey
Ricardo Martinez
reviewerPATCH v2 14/14 net: wwan: t7xx: Add maintainers and documentation
In reply to Ricardo MartinezAdds maintainers and documentation for MediaTek t7xx 5G WWAN modem device driver.
--- .../networking/device_drivers/wwan/index.rst | 1 + .../networking/device_drivers/wwan/t7xx.rst | 120 ++++++++++++++++++ MAINTAINERS | 11 ++ 3 files changed, 132 insertions(+) create mode 100644 Documentation/networking/device_drivers/wwan/t7xx.rst
Documentation/networking/device_drivers/wwan/index.rst +1 -0
@@ -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
@@ -12066,6 +12066,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
11/1/21 6:56 AM, Ricardo Martinez пишет:
Quoted 9 lines
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.
That should be prefixed with net-next
Quoted 162 lines
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 in close collaboration with MediaTek. This will enable getting the t7xx driver on Approved Vendor List for interested OEM's and ODM's productization plans with Intel 5G 5000 M.2 solution.List of contributors:
Amir Hanania <[email protected]>
Andriy Shevchenko <[email protected]> Chandrashekar Devegowda <[email protected]> Dinesh Sharma <[email protected]>
Eliot Lee <[email protected]>
Haijun Liu <[email protected]>
M Chetan Kumar <[email protected]>
Mika Westerberg <[email protected]> Moises Veleta <[email protected]> Pierre-louis Bossart <[email protected]> Chiranjeevi Rapolu <[email protected]> Ricardo Martinez <[email protected]> Muralidharan Sethuraman <[email protected]> Soumya Prakash Mishra <[email protected]> Sreehari Kancharla <[email protected]> Suresh Nagaraj <[email protected]>[1] https://www.freedesktop.org/software/libmbim/
[2] https://www.freedesktop.org/software/ModemManager/
[3] https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/merge_requests/582
[4] https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/merge_requests/523v2:
- 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.Chandrashekar Devegowda (1):
net: wwan: t7xx: Add AT and MBIM WWAN portsHaijun Lio (11):
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: Data path HW layer
net: wwan: t7xx: Add data path interface
net: wwan: t7xx: Add WWAN network interface
net: wwan: t7xx: Introduce power management support
net: wwan: t7xx: Runtime PM
net: wwan: t7xx: Device deep sleep lock/unlock
net: wwan: t7xx: Add debug and test portsRicardo Martinez (2):
net: wwan: Add default MTU size
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 | 24 + drivers/net/wwan/t7xx/t7xx_cldma.c | 277 +++ drivers/net/wwan/t7xx/t7xx_cldma.h | 168 ++ drivers/net/wwan/t7xx/t7xx_common.h | 76 + drivers/net/wwan/t7xx/t7xx_dpmaif.c | 1524 +++++++++++++++ drivers/net/wwan/t7xx/t7xx_dpmaif.h | 168 ++ drivers/net/wwan/t7xx/t7xx_hif_cldma.c | 1663 +++++++++++++++++ drivers/net/wwan/t7xx/t7xx_hif_cldma.h | 156 ++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c | 638 +++++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h | 279 +++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 1562 ++++++++++++++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h | 117 ++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c | 842 +++++++++ drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.h | 82 + drivers/net/wwan/t7xx/t7xx_mhccif.c | 124 ++ drivers/net/wwan/t7xx/t7xx_mhccif.h | 35 + drivers/net/wwan/t7xx/t7xx_modem_ops.c | 747 ++++++++ drivers/net/wwan/t7xx/t7xx_modem_ops.h | 92 + drivers/net/wwan/t7xx/t7xx_monitor.h | 147 ++ drivers/net/wwan/t7xx/t7xx_netdev.c | 545 ++++++ drivers/net/wwan/t7xx/t7xx_netdev.h | 63 + drivers/net/wwan/t7xx/t7xx_pci.c | 789 ++++++++ drivers/net/wwan/t7xx/t7xx_pci.h | 121 ++ drivers/net/wwan/t7xx/t7xx_pcie_mac.c | 277 +++ drivers/net/wwan/t7xx/t7xx_pcie_mac.h | 36 + drivers/net/wwan/t7xx/t7xx_port.h | 163 ++ drivers/net/wwan/t7xx/t7xx_port_char.c | 424 +++++ drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c | 150 ++ drivers/net/wwan/t7xx/t7xx_port_proxy.c | 829 ++++++++ drivers/net/wwan/t7xx/t7xx_port_proxy.h | 102 + drivers/net/wwan/t7xx/t7xx_port_tty.c | 191 ++ drivers/net/wwan/t7xx/t7xx_port_wwan.c | 281 +++ drivers/net/wwan/t7xx/t7xx_reg.h | 398 ++++ drivers/net/wwan/t7xx/t7xx_skb_util.c | 362 ++++ drivers/net/wwan/t7xx/t7xx_skb_util.h | 110 ++ drivers/net/wwan/t7xx/t7xx_state_monitor.c | 627 +++++++ drivers/net/wwan/t7xx/t7xx_tty_ops.c | 205 ++ drivers/net/wwan/t7xx/t7xx_tty_ops.h | 44 + include/linux/wwan.h | 5 + 44 files changed, 14590 insertions(+)create mode 100644
Documentation/networking/device_drivers/wwan/t7xx.rstcreate mode 100644drivers/net/wwan/t7xx/Makefile
create mode 100644drivers/net/wwan/t7xx/t7xx_cldma.c
create mode 100644drivers/net/wwan/t7xx/t7xx_cldma.h
create mode 100644drivers/net/wwan/t7xx/t7xx_common.hcreate mode 100644drivers/net/wwan/t7xx/t7xx_dpmaif.ccreate mode 100644drivers/net/wwan/t7xx/t7xx_dpmaif.hcreate mode 100644drivers/net/wwan/t7xx/t7xx_hif_cldma.ccreate mode 100644drivers/net/wwan/t7xx/t7xx_hif_cldma.hcreate mode 100644drivers/net/wwan/t7xx/t7xx_hif_dpmaif.ccreate mode 100644drivers/net/wwan/t7xx/t7xx_hif_dpmaif.hcreate mode 100644drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.ccreate mode 100644drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.hcreate mode 100644drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.ccreate mode 100644drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.hcreate mode 100644drivers/net/wwan/t7xx/t7xx_mhccif.ccreate mode 100644drivers/net/wwan/t7xx/t7xx_mhccif.hcreate mode 100644drivers/net/wwan/t7xx/t7xx_modem_ops.ccreate mode 100644drivers/net/wwan/t7xx/t7xx_modem_ops.hcreate mode 100644drivers/net/wwan/t7xx/t7xx_monitor.hcreate mode 100644drivers/net/wwan/t7xx/t7xx_netdev.ccreate mode 100644drivers/net/wwan/t7xx/t7xx_netdev.hcreate mode 100644drivers/net/wwan/t7xx/t7xx_pci.c
create mode 100644drivers/net/wwan/t7xx/t7xx_pci.h
create mode 100644drivers/net/wwan/t7xx/t7xx_pcie_mac.ccreate mode 100644drivers/net/wwan/t7xx/t7xx_pcie_mac.hcreate mode 100644drivers/net/wwan/t7xx/t7xx_port.h
create mode 100644drivers/net/wwan/t7xx/t7xx_port_char.ccreate mode 100644drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.ccreate mode 100644drivers/net/wwan/t7xx/t7xx_port_proxy.ccreate mode 100644drivers/net/wwan/t7xx/t7xx_port_proxy.hcreate mode 100644drivers/net/wwan/t7xx/t7xx_port_tty.ccreate mode 100644drivers/net/wwan/t7xx/t7xx_port_wwan.ccreate mode 100644drivers/net/wwan/t7xx/t7xx_reg.h
create mode 100644drivers/net/wwan/t7xx/t7xx_skb_util.ccreate mode 100644drivers/net/wwan/t7xx/t7xx_skb_util.hcreate mode 100644drivers/net/wwan/t7xx/t7xx_state_monitor.ccreate mode 100644drivers/net/wwan/t7xx/t7xx_tty_ops.ccreate mode 100644drivers/net/wwan/t7xx/t7xx_tty_ops.h
Sergey Ryazanov
maintainerHello Ricardo,
Quoted 27 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.
Quoted 7 lines
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 in close collaboration with MediaTek. This will enable getting the t7xx driver on Approved Vendor List for interested OEM's and ODM's productization plans with Intel 5G 5000 M.2 solution.
Nice work! The driver generally looks good for me. But at the same time the driver looks a bit raw, needs some style and functionality improvements, and a lot of cleanup. Please find general thoughts below and per-patch comments.
A one nitpick that is common for the entire series. Please consider using a common prefix for all driver function names (e.g. t7xx_) to make them more specific. This should improve the code readability. Thus, any reader will know for sure that the called functions belong to the driver, and not to a generic kernel API. E.g. use the t7xx_cldma_hw_init() name for the CLDMA initialization function instead of the too generic cldma_hw_init() name, etc.
Interestingly, that you are using the common 't7xx_' prefix for all driver file names. This is Ok, but it does not add to the specifics as all driver files are already located in a common directory with the specific name. But function names at the same time lack a common prefix.
Another common drawback is that the driver should break as soon as two modems are connected simultaneously. This should happen due to the use of multiple _global_ variables that keeps pointers to a modem runtime state. Out of curiosity, did you test the driver with two or more modems connected simultaneously?
Next, the driver entirely lacks the multibyte field endians handling. Looks like it will be unable to run on a big-endians CPU. To fix this, it is needed to find all the structures that are passed to the modem and replace the multibyte fields of types u16/u32 with __le16/__le32. Then examine all the field accesses and use cpu_to_le{16,32}()/le{16,32}_to_cpu() to update/read field contents. As soon as you change the types to __le16/__le32, sparse (a static analyzing utility) will warn you about every unsafe field access. Just build your kernel with make C=1.
Ricardo, please consider submitting at the next iteration a patch series with the driver that will be cleaned from debug stuff and questionable optimizations. Just a bare minimum functional: AT/MBIM control ports and network interface for data communications. This will cut the code in half. What will greatly facilitate the reviewing process. And then extend the driver functionality with follow up patches.
--
Sergey
Martinez, Ricardo
reviewerQuoted 4 lines · Sergey Ryazanov
Hello Ricardo,
On Mon, Nov 1, 2021 at 6:57 AM Ricardo Martinez
<[email protected]> wrote:
...
Quoted 4 lines
Nice work! The driver generally looks good for me. But at the same time the driver looks a bit raw, needs some style and functionality improvements, and a lot of cleanup. Please find general thoughts below and per-patch comments.
Thanks for the feedback Sergey, we will work on it.
Quoted 8 lines
A one nitpick that is common for the entire series. Please consider using a common prefix for all driver function names (e.g.
t7xx_) to make them more specific. This should improve the code readability. Thus, any reader will know for sure that the called functions belong to the driver, and not to a generic kernel API. E.g. use thet7xx_cldma_hw_init()name for the CLDMA initialization function instead of the too genericcldma_hw_init()name, etc.
Does this apply to static functions as well?
Quoted 7 lines
Interestingly, that you are using the common '
t7xx_' prefix for all driver file names. This is Ok, but it does not add to the specifics as all driver files are already located in a common directory with the specific name. But function names at the same time lack a common prefix.
Quoted 5 lines
Another common drawback is that the driver should break as soon as two modems are connected simultaneously. This should happen due to the use of multiple _global_ variables that keeps pointers to a modem runtime state. Out of curiosity, did you test the driver with two or more modems connected simultaneously?
We haven't tested such configurations, we are focusing on platforms with one single modem.
Quoted 22 lines
Next, the driver entirely lacks the multibyte field endians handling. Looks like it will be unable to run on a big-endians CPU. To fix this, it is needed to find all the structures that are passed to the modem and replace the multibyte fields of types u16/u32 with __le16/__le32. Then examine all the field accesses and use cpu_to_le{16,32}()/le{16,32}_to_cpu() to update/read field contents. As soon as you change the types to __le16/__le32, sparse (a static analyzing utility) will warn you about every unsafe field access. Just build your kernel with make C=1.
Ricardo, please consider submitting at the next iteration a patch series with the driver that will be cleaned from debug stuff and questionable optimizations. Just a bare minimum functional: AT/MBIM control ports and network interface for data communications. This will cut the code in half. What will greatly facilitate the reviewing process. And then extend the driver functionality with follow up patches.
--
Sergey
Sergey Ryazanov
maintainerQuoted 10 lines · Ricardo
Quoted 7 lines · Sergey Ryazanov
A one nitpick that is common for the entire series. Please consider using a common prefix for all driver function names (e.g.
t7xx_) to make them more specific. This should improve the code readability. Thus, any reader will know for sure that the called functions belong to the driver, and not to a generic kernel API. E.g. use thet7xx_cldma_hw_init()name for the CLDMA initialization function instead of the too genericcldma_hw_init()name, etc.Does this apply to static functions as well?
As I wrote, this is a nitpick. As you can see in Documentation/process/coding-style.rst, there are no general rules for functions naming. My personal rule of thumb is that if a function performs a very general operation (like averaging, interpolation, etc.), then a prefix can be omitted. If a function operation is specific for a module, then add a common module prefix to the function name. But again, this is my personal rule.
As for the driver, it was quite difficult to read the code that calls functions such as cldma_alloc(), cldma_init(). It was hard to figure out whether these functions are new kernel API or they are specific to the driver. A common way to solve such ambiguity issues is to prefix the driver function names. But again, this was just an attempt to draw your attention to the function naming. Feel free to name functions as you would like, just make the code readable for developers who are not familiar with the specific HW chip.
Quoted 7 lines
Quoted 5 lines
Another common drawback is that the driver should break as soon as two modems are connected simultaneously. This should happen due to the use of multiple _global_ variables that keeps pointers to a modem runtime state. Out of curiosity, did you test the driver with two or more modems connected simultaneously?
We haven't tested such configurations, we are focusing on platforms with one single modem.
Now you are aware of the potential kernel crash due to the global variables misuse. Please fix it.
Signature · 1 line
Sergey