net: iosm: PCIe Driver for Intel M.2 Modem
Subsystems (5)
v2 cover net: iosm: PCIe Driver for Intel M.2 Modem
The IOSM (IPC over Shared Memory) driver is a PCIe host driver implemented for linux or chrome platform for data exchange over PCIe interface between Host platform & Intel M.2 Modem. The driver exposes interface conforming to the MBIM protocol. Any front end application ( eg: Modem Manager) could easily manage the MBIM interface to enable data communication towards WWAN.
Intel M.2 modem uses 2 BAR regions. The first region is dedicated to Doorbell register for IRQs and the second region is used as scratchpad area for book keeping modem execution stage details along with host system shared memory region context details. The upper edge of the driver exposes the control and data channels for user space application interaction. At lower edge these data and control channels are associated to pipes. The pipes are lowest level interfaces used over PCIe as a logical channel for message exchange. A single channel maps to UL and DL pipe and are initialized on device open.
On UL path, driver copies application sent data to SKBs associate it with transfer descriptor and puts it on to ring buffer for DMA transfer. Once information has been updated in shared memory region, host gives a Doorbell to modem to perform DMA and modem uses MSI to communicate back to host. For receiving data in DL path, SKBs are pre-allocated during pipe open and transfer descriptors are given to modem for DMA transfer.
The driver exposes two types of ports, namely "wwanctrl", a char device node which is used for MBIM control operation and "INMx",(x = 0,1,2..7) network interfaces for IP data communication.
1) MBIM Control Interface:
This node exposes an interface between modem and application using char device exposed by "IOSM" driver to establish and manage the MBIM data communication with PCIe based Intel M.2 Modems.
It also support an IOCTL command, apart from read and write methods. The IOCTL command, "IOCTL_WDM_MAX_COMMAND" could be used by applications to fetch the Maximum Command buffer length supported by the driver which is restricted to 4096 bytes.
2) MBIM Data Interface:
The IOSM driver exposes IP link interface "inmX" of type "IOSM" for IP traffic. Iproute network utility is used for creating "inmX" network interface and for associating it with MBIM IP session. The Driver supports upto 8 IP sessions for simultaneous IP communication.
Changes since v1:
* Removed Ethernet header & VLAN tag handling from wwan net driver.
* Implement rtnet_link interface for IP traffic handling.
* Strip off Modem FW flashing & CD collection code changes.
* Moved driver documentation to RsT file.
* Change copyright year.
* PATCH1:
* Implement module_init() & exit() callbacks for rtnl_link.
* Documentation correction for function signature.
* Fix coverity warnings.
* PATCH2:
* Streamline multiple returns using goto.
* PATCH3:
* Removed space around the : for the bitfields.
* Return proper error code instead of returning -1.
* PATCH4:
* Clean-up vlan tag ids & removed FW flashing logic.
* Function return type correction.
* Return proper error code instead of returning -1.
* PATCH5:
* Change vlan_id to ip link if_id & document correction.
* Define new enums for IP & DSS session mapping.
* Return proper error code instead of returning -1.
* Clean-up vlan tag id & removed FW flashing logic.
* PATCH6:
* Return proper error code instead of returning -1.
* Define IPC channels in serial order.
* PATCH7:
* Renamed iosm_sio struct to iosm_cdev.
* Added memory barriers around atomic operations.
* PATCH8:
* Moved task queue struct to header file.
* Streamline multiple returns using goto.
* PATCH9:
* Endianness type correction for Host-Device protocol structure.
* Removed space around the : for the bitfields.
* Change session from dynamic to static.
* Streamline multiple returns using goto.
* PATCH10:
* Endianness type correction for Host-Device protocol structure.
* Function signature documentation correction.
* Streamline multiple returns using goto.
* Removed vlan tag id & replace it with ip link interface id.
* PATCH11:
* Removed space around the : for the bitfields.
* Moved pm module under static allocation.
* Added memory barriers around atomic operations.
* PATCH12:
* Endianness type correction for Host-Device protocol structure.
* Function signature documentation correction.
* Streamline multiple returns using goto.
* PATCH13:
* Endianness type correction for Host-Device protocol structure.
* Function signature documentation correction.
* Streamline multiple returns using goto.
* PATCH14:
* Removed no related header file inclusion.
* PATCH15:
* Removed Ethernet header & VLAN tag handling from wwan net driver.
* Implement rtnet_link interface for IP traffic handling.
* PATCH16:
* Moved driver documentation to RsT file.
* Modified if_link.h file to support link type iosm.
--
M Chetan Kumar (16):
net: iosm: entry point
net: iosm: irq handling
net: iosm: mmio scratchpad
net: iosm: shared memory IPC interface
net: iosm: shared memory I/O operations
net: iosm: channel configuration
net: iosm: mbim control device
net: iosm: bottom half
net: iosm: multiplex IP sessions
net: iosm: encode or decode datagram
net: iosm: power management
net: iosm: shared memory protocol
net: iosm: protocol operations
net: iosm: uevent support
net: iosm: net driver
net: iosm: infrastructure
.../networking/device_drivers/index.rst | 1 + .../networking/device_drivers/wwan/index.rst | 18 + .../networking/device_drivers/wwan/iosm.rst | 126 ++ MAINTAINERS | 7 + drivers/net/Kconfig | 1 + drivers/net/Makefile | 1 + drivers/net/wwan/Kconfig | 19 + drivers/net/wwan/Makefile | 5 + drivers/net/wwan/iosm/Kconfig | 17 + drivers/net/wwan/iosm/Makefile | 26 + drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c | 82 + drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.h | 55 + drivers/net/wwan/iosm/iosm_ipc_imem.c | 1390 +++++++++++++++++ drivers/net/wwan/iosm/iosm_ipc_imem.h | 582 +++++++ drivers/net/wwan/iosm/iosm_ipc_imem_ops.c | 512 ++++++ drivers/net/wwan/iosm/iosm_ipc_imem_ops.h | 135 ++ drivers/net/wwan/iosm/iosm_ipc_irq.c | 91 ++ drivers/net/wwan/iosm/iosm_ipc_irq.h | 33 + drivers/net/wwan/iosm/iosm_ipc_mbim.c | 306 ++++ drivers/net/wwan/iosm/iosm_ipc_mbim.h | 78 + drivers/net/wwan/iosm/iosm_ipc_mmio.c | 223 +++ drivers/net/wwan/iosm/iosm_ipc_mmio.h | 193 +++ drivers/net/wwan/iosm/iosm_ipc_mux.c | 454 ++++++ drivers/net/wwan/iosm/iosm_ipc_mux.h | 343 ++++ drivers/net/wwan/iosm/iosm_ipc_mux_codec.c | 901 +++++++++++ drivers/net/wwan/iosm/iosm_ipc_mux_codec.h | 193 +++ drivers/net/wwan/iosm/iosm_ipc_pcie.c | 588 +++++++ drivers/net/wwan/iosm/iosm_ipc_pcie.h | 211 +++ drivers/net/wwan/iosm/iosm_ipc_pm.c | 333 ++++ drivers/net/wwan/iosm/iosm_ipc_pm.h | 207 +++ drivers/net/wwan/iosm/iosm_ipc_protocol.c | 283 ++++ drivers/net/wwan/iosm/iosm_ipc_protocol.h | 237 +++ drivers/net/wwan/iosm/iosm_ipc_protocol_ops.c | 552 +++++++ drivers/net/wwan/iosm/iosm_ipc_protocol_ops.h | 444 ++++++ drivers/net/wwan/iosm/iosm_ipc_task_queue.c | 202 +++ drivers/net/wwan/iosm/iosm_ipc_task_queue.h | 97 ++ drivers/net/wwan/iosm/iosm_ipc_uevent.c | 44 + drivers/net/wwan/iosm/iosm_ipc_uevent.h | 41 + drivers/net/wwan/iosm/iosm_ipc_wwan.c | 445 ++++++ drivers/net/wwan/iosm/iosm_ipc_wwan.h | 55 + include/uapi/linux/if_link.h | 10 + tools/include/uapi/linux/if_link.h | 10 + 42 files changed, 9551 insertions(+) create mode 100644 Documentation/networking/device_drivers/wwan/index.rst create mode 100755 Documentation/networking/device_drivers/wwan/iosm.rst create mode 100644 drivers/net/wwan/Kconfig create mode 100644 drivers/net/wwan/Makefile create mode 100644 drivers/net/wwan/iosm/Kconfig create mode 100644 drivers/net/wwan/iosm/Makefile create mode 100644 drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.h create mode 100644 drivers/net/wwan/iosm/iosm_ipc_imem.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_imem.h create mode 100644 drivers/net/wwan/iosm/iosm_ipc_imem_ops.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_imem_ops.h create mode 100644 drivers/net/wwan/iosm/iosm_ipc_irq.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_irq.h create mode 100644 drivers/net/wwan/iosm/iosm_ipc_mbim.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_mbim.h create mode 100644 drivers/net/wwan/iosm/iosm_ipc_mmio.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_mmio.h create mode 100644 drivers/net/wwan/iosm/iosm_ipc_mux.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_mux.h create mode 100644 drivers/net/wwan/iosm/iosm_ipc_mux_codec.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_mux_codec.h create mode 100644 drivers/net/wwan/iosm/iosm_ipc_pcie.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_pcie.h create mode 100644 drivers/net/wwan/iosm/iosm_ipc_pm.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_pm.h create mode 100644 drivers/net/wwan/iosm/iosm_ipc_protocol.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_protocol.h create mode 100644 drivers/net/wwan/iosm/iosm_ipc_protocol_ops.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_protocol_ops.h create mode 100644 drivers/net/wwan/iosm/iosm_ipc_task_queue.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_task_queue.h create mode 100644 drivers/net/wwan/iosm/iosm_ipc_uevent.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_uevent.h create mode 100644 drivers/net/wwan/iosm/iosm_ipc_wwan.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_wwan.h
Signature · 1 line
2.25.1
PATCH v2 1/16 net: iosm: entry point
1) Register IOSM driver with kernel to manage Intel WWAN PCIe device(PCI_VENDOR_ID_INTEL, INTEL_CP_DEVICE_7560_ID).
2) Exposes the EP PCIe device capability to Host PCIe core.
3) Initializes PCIe EP configuration and defines PCIe driver probe, remove and power management OPS.
4) Allocate and map(dma) skb memory for data communication from device to kernel and vice versa.
---
v2:
* Implement module_init() & exit() callbacks for rtnl_link.
* Documentation correction for function signature.
* Fix coverity warnings.
--- drivers/net/wwan/iosm/iosm_ipc_pcie.c | 588 ++++++++++++++++++++++++++ drivers/net/wwan/iosm/iosm_ipc_pcie.h | 211 +++++++++ 2 files changed, 799 insertions(+) create mode 100644 drivers/net/wwan/iosm/iosm_ipc_pcie.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_pcie.h
drivers/net/wwan/iosm/iosm_ipc_pcie.c new file +588 -0
@@ -0,0 +1,588 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2020-21 Intel Corporation. +*/ + +#include <linux/acpi.h> +#include <linux/bitfield.h> +#include <linux/module.h> +#include <net/rtnetlink.h> + +#include "iosm_ipc_imem.h" +#include "iosm_ipc_pcie.h" +#include "iosm_ipc_protocol.h" + +#define DRV_AUTHOR "Intel Corporation <[email protected]>" + +MODULE_AUTHOR (DRV_AUTHOR ); +MODULE_DESCRIPTION ("IOSM Driver" ); +MODULE_LICENSE ("GPL v2" ); + +/* WWAN GUID */ +static guid_t wwan_acpi_guid =GUID_INIT (0xbad01b75 ,0x22a8 ,0x4f48 ,0x87 ,0x92 , +0xbd ,0xde ,0x94 ,0x67 ,0x74 ,0x7d ); + +static void ipc_pcie_resources_release (struct iosm_pcie *ipc_pcie) +{ +/* Free the MSI resources. */ +ipc_release_irq (ipc_pcie); + +/* Free mapped doorbell scratchpad bus memory into CPU space. */ +iounmap (ipc_pcie->scratchpad); + +/* Free mapped IPC_REGS bus memory into CPU space. */ +iounmap (ipc_pcie->ipc_regs); + +/* Releases all PCI I/O and memory resources previously reserved by a +* successful call to pci_request_regions. Call this function only +* after all use of the PCI regions has ceased. +*/ +pci_release_regions (ipc_pcie->pci); +} + +static void ipc_cleanup (struct iosm_pcie *ipc_pcie) +{ +/* Free the shared memory resources. */ +ipc_imem_cleanup (ipc_pcie->imem); + +ipc_pcie_resources_release (ipc_pcie); + +/* Signal to the system that the PCI device is not in use. */ +pci_disable_device (ipc_pcie->pci); +} + +static void ipc_pcie_deinit (struct iosm_pcie *ipc_pcie) +{ +kfree (ipc_pcie->imem); +kfree (ipc_pcie); +} + +static void iosm_ipc_remove (struct pci_dev *pci) +{ +struct iosm_pcie *ipc_pcie =pci_get_drvdata (pci); + +ipc_cleanup (ipc_pcie); + +ipc_pcie_deinit (ipc_pcie); +} + +static int ipc_pcie_resources_request (struct iosm_pcie *ipc_pcie) +{ +struct pci_dev *pci = ipc_pcie->pci; +u32 cap =0 ; +u32 ret; + +/* Reserved PCI I/O and memory resources. +* Mark all PCI regions associated with PCI device pci as +* being reserved by owner IOSM_IPC. +*/ + ret =pci_request_regions (pci,"IOSM_IPC" ); +if (ret) { +dev_err (ipc_pcie->dev,"failed pci request regions" ); + goto pci_request_region_fail; + } + +/* Reserve the doorbell IPC REGS memory resources. +* Remap the memory into CPU space. Arrange for the physical address +* (BAR) to be visible from this driver. +* pci_ioremap_bar() ensures that the memory is marked uncachable. +*/ + ipc_pcie->ipc_regs =pci_ioremap_bar (pci, ipc_pcie->ipc_regs_bar_nr); + +if (!ipc_pcie->ipc_regs) { +dev_err (ipc_pcie->dev,"IPC REGS ioremap error" ); + ret = -EBUSY ; + goto ipc_regs_remap_fail; + } + +/* Reserve the MMIO scratchpad memory resources. +* Remap the memory into CPU space. Arrange for the physical address +* (BAR) to be visible from this driver. +* pci_ioremap_bar() ensures that the memory is marked uncachable. +*/ + ipc_pcie->scratchpad = +pci_ioremap_bar (pci, ipc_pcie->scratchpad_bar_nr); + +if (!ipc_pcie->scratchpad) { +dev_err (ipc_pcie->dev,"doorbell scratchpad ioremap error" ); + ret = -EBUSY ; + goto scratch_remap_fail; + } + +/* Install the irq handler triggered by CP. */ + ret =ipc_acquire_irq (ipc_pcie); +if (ret) { +dev_err (ipc_pcie->dev,"acquiring MSI irq failed!" ); + goto irq_acquire_fail; + } + +/* Enable bus-mastering for the IOSM IPC device. */ +pci_set_master (pci); + +/* Enable LTR if possible +* This is needed for L1.2! +*/ +pcie_capability_read_dword (ipc_pcie->pci,PCI_EXP_DEVCAP2 , &cap); +if (cap &PCI_EXP_DEVCAP2_LTR ) +pcie_capability_set_word (ipc_pcie->pci,PCI_EXP_DEVCTL2 , +PCI_EXP_DEVCTL2_LTR_EN ); + +dev_dbg (ipc_pcie->dev,"link between AP and CP is fully on" ); + +return ret; + +irq_acquire_fail: +iounmap (ipc_pcie->scratchpad); +scratch_remap_fail: +iounmap (ipc_pcie->ipc_regs); +ipc_regs_remap_fail: +pci_release_regions (pci); +pci_request_region_fail: +return ret; +} + +bool ipc_pcie_check_aspm_enabled (struct iosm_pcie *ipc_pcie, +bool parent) +{ +struct pci_dev *pdev; +u16 value =0 ; +u32 enabled; + +if (parent) + pdev = ipc_pcie->pci->bus->self; +else + pdev = ipc_pcie->pci; + +pcie_capability_read_word (pdev,PCI_EXP_LNKCTL , &value); + enabled = value &PCI_EXP_LNKCTL_ASPMC ; +dev_dbg (ipc_pcie->dev,"ASPM L1: 0x%04X 0x%03X" , pdev->device, value); + +return (enabled ==PCI_EXP_LNKCTL_ASPM_L1 || + enabled ==PCI_EXP_LNKCTL_ASPMC ); +} + +bool ipc_pcie_check_data_link_active (struct iosm_pcie *ipc_pcie) +{ +struct pci_dev *parent; +u16 link_status =0 ; + +if (!ipc_pcie->pci->bus || !ipc_pcie->pci->bus->self) { +dev_err (ipc_pcie->dev,"root port not found" ); +return false; + } + + parent = ipc_pcie->pci->bus->self; + +pcie_capability_read_word (parent,PCI_EXP_LNKSTA , &link_status); +dev_dbg (ipc_pcie->dev,"Link status: 0x%04X" , link_status); + +return link_status &PCI_EXP_LNKSTA_DLLLA ; +} + +static bool ipc_pcie_check_aspm_supported (struct iosm_pcie *ipc_pcie, +bool parent) +{ +struct pci_dev *pdev; +u32 support; +u32 cap =0 ; + +if (parent) + pdev = ipc_pcie->pci->bus->self; +else + pdev = ipc_pcie->pci; +pcie_capability_read_dword (pdev,PCI_EXP_LNKCAP , &cap); + support =u32_get_bits (cap,PCI_EXP_LNKCAP_ASPMS ); +if (support <PCI_EXP_LNKCTL_ASPM_L1 ) { +dev_dbg (ipc_pcie->dev,"ASPM L1 not supported: 0x%04X" , + pdev->device); +return false; + } +return true; +} + +void ipc_pcie_config_aspm (struct iosm_pcie *ipc_pcie) +{ +bool parent_aspm_enabled, dev_aspm_enabled; + +/* check if both root port and child supports ASPM L1 */ +if (!ipc_pcie_check_aspm_supported (ipc_pcie, true) || + !ipc_pcie_check_aspm_supported (ipc_pcie, false)) +return ; + + parent_aspm_enabled =ipc_pcie_check_aspm_enabled (ipc_pcie, true); + dev_aspm_enabled =ipc_pcie_check_aspm_enabled (ipc_pcie, false); + +dev_dbg (ipc_pcie->dev,"ASPM parent: %s device: %s" , + parent_aspm_enabled ?"Enabled" :"Disabled" , + dev_aspm_enabled ?"Enabled" :"Disabled" ); +} + +/* Initializes PCIe endpoint configuration */ +static void ipc_pcie_config_init (struct iosm_pcie *ipc_pcie) +{ +/* BAR0 is used for doorbell */ + ipc_pcie->ipc_regs_bar_nr =IPC_DOORBELL_BAR0 ; + +/* update HW configuration */ + ipc_pcie->scratchpad_bar_nr =IPC_SCRATCHPAD_BAR2 ; + ipc_pcie->doorbell_reg_offset =IPC_DOORBELL_CH_OFFSET ; + ipc_pcie->doorbell_write =IPC_WRITE_PTR_REG_0 ; + ipc_pcie->doorbell_capture =IPC_CAPTURE_PTR_REG_0 ; +} + +/* This will read the BIOS WWAN RTD3 settings: +* D0L1.2/D3L2/Disabled +*/ +static enum ipc_pcie_sleep_state imc_ipc_read_bios_cfg (struct device *dev) +{ +union acpi_object *object; +acpi_handle handle_acpi; + + handle_acpi =ACPI_HANDLE (dev); +if (!handle_acpi) { +pr_debug ("pci device is NOT ACPI supporting device\n" ); + goto default_ret; + } + + object =acpi_evaluate_dsm (handle_acpi, &wwan_acpi_guid,0 ,3 ,NULL ); + +if (object && object->integer.value ==3 ) +return IPC_PCIE_D3L2 ; + +default_ret: +return IPC_PCIE_D0L12 ; +} + +static int iosm_ipc_probe (struct pci_dev *pci, +const struct pci_device_id *pci_id) +{ +struct iosm_pcie *ipc_pcie =kzalloc (sizeof (*ipc_pcie),GFP_KERNEL ); + +pr_debug ("Probing device 0x%X from the vendor 0x%X" , pci_id->device, + pci_id->vendor); + +if (!ipc_pcie) + goto ret_fail; + +/* Initialize ipc dbg component for the PCIe device */ + ipc_pcie->dev = &pci->dev; + +/* Set the driver specific data. */ +pci_set_drvdata (pci, ipc_pcie); + +/* Save the address of the PCI device configuration. */ + ipc_pcie->pci = pci; + +/* Update platform configuration */ +ipc_pcie_config_init (ipc_pcie); + +/* Initialize the device before it is used. Ask low-level code +* to enable I/O and memory. Wake up the device if it was suspended. +*/ +if (pci_enable_device (pci)) { +dev_err (ipc_pcie->dev,"failed to enable the AP PCIe device" ); +/* If enable of PCIe device has failed then calling ipc_cleanup +* will panic the system. More over ipc_cleanup() is required to +* be called after ipc_imem_mount() +*/ + goto pci_enable_fail; + } + +ipc_pcie_config_aspm (ipc_pcie); +dev_dbg (ipc_pcie->dev,"PCIe device enabled." ); + +/* Read WWAN RTD3 BIOS Setting +*/ + ipc_pcie->d3l2_support =imc_ipc_read_bios_cfg (&pci->dev); + + ipc_pcie->suspend =0 ; + +if (ipc_pcie_resources_request (ipc_pcie)) + goto resources_req_fail; + +/* Establish the link to the imem layer. */ + ipc_pcie->imem =ipc_imem_init (ipc_pcie, pci->device, + ipc_pcie->scratchpad, ipc_pcie->dev); +if (!ipc_pcie->imem) { +dev_err (ipc_pcie->dev,"failed to init imem" ); + goto imem_init_fail; + } + +return 0 ; + +imem_init_fail: +ipc_pcie_resources_release (ipc_pcie); +resources_req_fail: +pci_disable_device (pci); +pci_enable_fail: +kfree (ipc_pcie); +ret_fail: +return -EIO ; +} + +static const struct pci_device_id iosm_ipc_ids[] = { + {PCI_DEVICE (PCI_VENDOR_ID_INTEL ,INTEL_CP_DEVICE_7560_ID ) }, + {} +}; + +/* Enter sleep in s2idle case +*/ +static int __maybe_unused iosm_ipc_suspend_s2idle (struct iosm_pcie *ipc_pcie) +{ +ipc_cp_irq_sleep_control (ipc_pcie,IPC_MEM_DEV_PM_FORCE_SLEEP ); + +/* Complete all memory stores before setting bit */ +smp_mb__before_atomic (); + +set_bit (0 , &ipc_pcie->suspend); + +/* Complete all memory stores after setting bit */ +smp_mb__after_atomic (); + +ipc_imem_pm_s2idle_sleep (ipc_pcie->imem, true); + +return 0 ; +} + +/* Resume from sleep in s2idle case +*/ +static int __maybe_unused iosm_ipc_resume_s2idle (struct iosm_pcie *ipc_pcie) +{ +ipc_cp_irq_sleep_control (ipc_pcie,IPC_MEM_DEV_PM_FORCE_ACTIVE ); + +ipc_imem_pm_s2idle_sleep (ipc_pcie->imem, false); + +/* Complete all memory stores before clearing bit. */ +smp_mb__before_atomic (); + +clear_bit (0 , &ipc_pcie->suspend); + +/* Complete all memory stores after clearing bit. */ +smp_mb__after_atomic (); +return 0 ; +} + +int __maybe_unused iosm_ipc_suspend (struct iosm_pcie *ipc_pcie) +{ +struct pci_dev *pdev; +int ret; + + pdev = ipc_pcie->pci; + +/* Execute D3 one time. */ +if (pdev->current_state !=PCI_D0 ) { +dev_dbg (ipc_pcie->dev,"done for PM=%d" , pdev->current_state); +return 0 ; + } + +/* The HAL shall ask the shared memory layer whether D3 is allowed. */ +ipc_imem_pm_suspend (ipc_pcie->imem); + +/* Save the PCI configuration space of a device before suspending. */ + ret =pci_save_state (pdev); + +if (ret) { +dev_err (ipc_pcie->dev,"pci_save_state error=%d" , ret); +return ret; + } + +/* Set the power state of a PCI device. +* Transition a device to a new power state, using the device's PCI PM +* registers. +*/ + ret =pci_set_power_state (pdev, PCI_D3cold); + +if (ret) { +dev_err (ipc_pcie->dev,"pci_set_power_state error=%d" , ret); +return ret; + } + +dev_dbg (ipc_pcie->dev,"SUSPEND done" ); +return ret; +} + +int __maybe_unused iosm_ipc_resume (struct iosm_pcie *ipc_pcie) +{ +int ret; + +/* Set the power state of a PCI device. +* Transition a device to a new power state, using the device's PCI PM +* registers. +*/ + ret =pci_set_power_state (ipc_pcie->pci,PCI_D0 ); + +if (ret) { +dev_err (ipc_pcie->dev,"pci_set_power_state error=%d" , ret); +return ret; + } + +pci_restore_state (ipc_pcie->pci); + +/* The HAL shall inform the shared memory layer that the device is +* active. +*/ +ipc_imem_pm_resume (ipc_pcie->imem); + +dev_dbg (ipc_pcie->dev,"RESUME done" ); +return ret; +} + +static int __maybe_unused iosm_ipc_suspend_cb (struct device *dev) +{ +struct iosm_pcie *ipc_pcie; +struct pci_dev *pdev; + + pdev =to_pci_dev (dev); + + ipc_pcie =pci_get_drvdata (pdev); + +switch (ipc_pcie->d3l2_support) { +case IPC_PCIE_D0L12 : +iosm_ipc_suspend_s2idle (ipc_pcie); +break ; +case IPC_PCIE_D3L2 : +iosm_ipc_suspend (ipc_pcie); +break ; + } + +return 0 ; +} + +static int __maybe_unused iosm_ipc_resume_cb (struct device *dev) +{ +struct iosm_pcie *ipc_pcie; +struct pci_dev *pdev; + + pdev =to_pci_dev (dev); + + ipc_pcie =pci_get_drvdata (pdev); + +switch (ipc_pcie->d3l2_support) { +case IPC_PCIE_D0L12 : +iosm_ipc_resume_s2idle (ipc_pcie); +break ; +case IPC_PCIE_D3L2 : +iosm_ipc_resume (ipc_pcie); +break ; + } + +return 0 ; +} + +static SIMPLE_DEV_PM_OPS(iosm_ipc_pm, iosm_ipc_suspend_cb, iosm_ipc_resume_cb); + +static struct pci_driver iosm_ipc_driver = { + .name =KBUILD_MODNAME , + .probe = iosm_ipc_probe, + .remove = iosm_ipc_remove, + .driver = { + .pm = &iosm_ipc_pm, + }, + .id_table = iosm_ipc_ids, +}; + +int ipc_pcie_addr_map (struct iosm_pcie *ipc_pcie,unsigned char *data,size_t size, +dma_addr_t *mapping,int direction) +{ +if (ipc_pcie->pci) { + *mapping =dma_map_single (&ipc_pcie->pci->dev, data, size, + direction); +if (dma_mapping_error (&ipc_pcie->pci->dev, *mapping)) { +dev_err (ipc_pcie->dev,"dma mapping failed" ); +return -EINVAL ; + } + } +return 0 ; +} + +void ipc_pcie_addr_unmap (struct iosm_pcie *ipc_pcie,size_t size, +dma_addr_t mapping,int direction) +{ +if (!mapping) +return ; +if (ipc_pcie->pci) +dma_unmap_single (&ipc_pcie->pci->dev, mapping, size, direction); +} + +struct sk_buff *ipc_pcie_alloc_local_skb (struct iosm_pcie *ipc_pcie, +gfp_t flags,size_t size) +{ +struct sk_buff *skb; + +if (!ipc_pcie || !size) { +pr_err ("invalid pcie object or size" ); +return NULL ; + } + + skb =__netdev_alloc_skb (NULL , size, flags); +if (!skb) +return NULL ; + +IPC_CB (skb)->op_type = (u8 )UL_DEFAULT ; +IPC_CB (skb)->mapping =0 ; + +return skb; +} + +struct sk_buff *ipc_pcie_alloc_skb (struct iosm_pcie *ipc_pcie,size_t size, +gfp_t flags,dma_addr_t *mapping, +int direction,size_t headroom) +{ +struct sk_buff *skb =ipc_pcie_alloc_local_skb (ipc_pcie, flags, + size + headroom); +if (!skb) +return NULL ; + +if (headroom) +skb_reserve (skb, headroom); + +if (ipc_pcie_addr_map (ipc_pcie, skb->data, size, mapping, direction)) { +dev_kfree_skb (skb); +return NULL ; + } + +BUILD_BUG_ON (sizeof (*IPC_CB (skb)) >sizeof (skb->cb)); + +/* Store the mapping address in skb scratch pad for later usage */ +IPC_CB (skb)->mapping = *mapping; +IPC_CB (skb)->direction = direction; +IPC_CB (skb)->len = size; + +return skb; +} + +void ipc_pcie_kfree_skb (struct iosm_pcie *ipc_pcie,struct sk_buff *skb) +{ +if (!skb) +return ; + +ipc_pcie_addr_unmap (ipc_pcie,IPC_CB (skb)->len,IPC_CB (skb)->mapping, +IPC_CB (skb)->direction); +IPC_CB (skb)->mapping =0 ; +dev_kfree_skb (skb); +} + +static int __init iosm_ipc_init (void ) +{ +if (pci_register_driver (&iosm_ipc_driver)) { +pr_err ("registering of IOSM PCIe driver failed" ); +return -1 ; + } + +if (rtnl_link_register (&iosm_netlink)) { +pr_err ("IOSM RTNL register failed" ); +pci_unregister_driver (&iosm_ipc_driver); +return -1 ; + } + +return 0 ; +} + +static void __exit iosm_ipc_exit(void) +{ +rtnl_link_unregister (&iosm_netlink); +pci_unregister_driver (&iosm_ipc_driver); +} + +module_init (iosm_ipc_init); +module_exit (iosm_ipc_exit);
drivers/net/wwan/iosm/iosm_ipc_pcie.h new file +211 -0
211 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH V2 01/16] net: iosm: entry point
Quoted 32 lines · M Chetan Kumar
1) Register IOSM driver with kernel to manage Intel WWAN PCIe
device(PCI_VENDOR_ID_INTEL, INTEL_CP_DEVICE_7560_ID).
2) Exposes the EP PCIe device capability to Host PCIe core.
3) Initializes PCIe EP configuration and defines PCIe driver probe, remove and power management OPS.
4) Allocate and map(dma) skb memory for data communication from device to kernel and vice versa.Signed-off-by M Chetan Kumar <[email protected]>---
v2:
* Implementmodule_init()&exit()callbacks forrtnl_link.
* Documentation correction for function signature.
* Fix coverity warnings.--- drivers/net/wwan/iosm/iosm_ipc_pcie.c | 588 ++++++++++++++++++++++++++ drivers/net/wwan/iosm/iosm_ipc_pcie.h | 211 +++++++++ 2 files changed, 799 insertions(+) create mode 100644 drivers/net/wwan/iosm/iosm_ipc_pcie.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_pcie.hdrivers/net/wwan/iosm/iosm_ipc_pcie.c new file +5
-0@@ -0,0 +1,588 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2020-21 Intel Corporation. +*/ +
drivers/net/wwan/iosm/iosm_ipc_pcie.c line 15
Quoted 10 lines
drivers/net/wwan/iosm/iosm_ipc_pcie.c new file +10
-0+#include <linux/acpi.h> +#include <linux/bitfield.h> +#include <linux/module.h> +#include <net/rtnetlink.h> + +#include "iosm_ipc_imem.h" +#include "iosm_ipc_pcie.h" +#include "iosm_ipc_protocol.h" + +#define DRV_AUTHOR "Intel Corporation <[email protected]>"
Driver author can't be a company. It needs to be a person.
Thanks
Johannes Berg
reviewerRe: [PATCH V2 01/16] net: iosm: entry point
Quoted 4 lines · Leon Romanovsky
Quoted 2 lines
+#define
DRV_AUTHOR"Intel Corporation <[email protected]>"Driver author can't be a company. It needs to be a person.
Most of
git grep MODULE_AUTHOR|grep Inc
disagrees.
johannes
Re: [PATCH V2 01/16] net: iosm: entry point
Quoted 11 lines · Johannes Berg
Quoted 4 lines · Leon Romanovsky
Quoted 2 lines
+#define
DRV_AUTHOR"Intel Corporation <[email protected]>"Driver author can't be a company. It needs to be a person.
Most of
git grep MODULE_AUTHOR|grep Inc
disagrees.
Did you actually look on the output of that grep?
We have three types of MODULE_AUTHOR(..) there
1. Really old code with non-existent companies
2. People who added their names together with the company name
3. Heavy copy/pasted code
MODULE_AUTHOR is not copyright which (usually) goes to the company that sponsored the work, but can be seen as git commit author in pre-historic days.
So no, old doesn't mean correct.
Thanks
Quoted 3 lines
johannes
PATCH v2 2/16 net: iosm: irq handling
In reply to M Chetan Kumar1) Request interrupt vector, frees allocated resource.
2) Registers IRQ handler.
---
v2: Streamline multiple returns using goto.
--- drivers/net/wwan/iosm/iosm_ipc_irq.c | 91 ++++++++++++++++++++++++++++ drivers/net/wwan/iosm/iosm_ipc_irq.h | 33 ++++++++++ 2 files changed, 124 insertions(+) create mode 100644 drivers/net/wwan/iosm/iosm_ipc_irq.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_irq.h
drivers/net/wwan/iosm/iosm_ipc_irq.c new file +91 -0
@@ -0,0 +1,91 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2020-21 Intel Corporation. +*/ + +#include "iosm_ipc_pcie.h" +#include "iosm_ipc_protocol.h" + +static inline void write_dbell_reg (struct iosm_pcie *ipc_pcie,int irq_n, +u32 data) +{ +void __iomem *write_reg; + +/* Select the first doorbell register, which is only currently needed +* by CP. +*/ + write_reg = (void __iomem *)((u8 __iomem *)ipc_pcie->ipc_regs + + ipc_pcie->doorbell_write + + (irq_n * ipc_pcie->doorbell_reg_offset)); + +/* Fire the doorbell irq by writing data on the doorbell write pointer +* register. +*/ +iowrite32 (data, write_reg); +} + +void ipc_doorbell_fire (struct iosm_pcie *ipc_pcie,int irq_n,u32 data) +{ +write_dbell_reg (ipc_pcie, irq_n, data); +} + +/* Threaded Interrupt handler for MSI interrupts */ +static irqreturn_t ipc_msi_interrupt (int irq,void *dev_id) +{ +struct iosm_pcie *ipc_pcie = dev_id; +int instance = irq - ipc_pcie->pci->irq; + +/* Shift the MSI irq actions to the IPC tasklet. IRQ_NONE means the +* irq was not from the IPC device or could not be served. +*/ +if (instance >= ipc_pcie->nvec) +return IRQ_NONE ; + +if (!test_bit (0 , &ipc_pcie->suspend)) +ipc_imem_irq_process (ipc_pcie->imem, instance); + +return IRQ_HANDLED ; +} + +void ipc_release_irq (struct iosm_pcie *ipc_pcie) +{ +struct pci_dev *pdev = ipc_pcie->pci; + +if (pdev->msi_enabled) { +while (--ipc_pcie->nvec >=0 ) +free_irq (pdev->irq + ipc_pcie->nvec, ipc_pcie); + } +pci_free_irq_vectors (pdev); +} + +int ipc_acquire_irq (struct iosm_pcie *ipc_pcie) +{ +struct pci_dev *pdev = ipc_pcie->pci; +int i, rc = -EINVAL ; + + ipc_pcie->nvec =pci_alloc_irq_vectors (pdev,IPC_MSI_VECTORS , +IPC_MSI_VECTORS ,PCI_IRQ_MSI ); + +if (ipc_pcie->nvec <0 ) { + rc = ipc_pcie->nvec; + goto error; + } + +if (!pdev->msi_enabled) + goto error; + +for (i =0 ; i < ipc_pcie->nvec; ++i) { + rc =request_threaded_irq (pdev->irq + i,NULL , + ipc_msi_interrupt,IRQF_ONESHOT , +KBUILD_MODNAME , ipc_pcie); +if (rc) { +dev_err (ipc_pcie->dev,"unable to grab IRQ, rc=%d" , rc); + ipc_pcie->nvec = i; +ipc_release_irq (ipc_pcie); + goto error; + } + } + +error: +return rc; +}
drivers/net/wwan/iosm/iosm_ipc_irq.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0-only +* +* Copyright (C) 2020-21 Intel Corporation. +*/ + +#ifndef IOSM_IPC_IRQ_H +#define IOSM_IPC_IRQ_H + +struct iosm_pcie ; + +/** +* ipc_doorbell_fire - fire doorbell to CP +* @ipc_pcie: Pointer to iosm_pcie +* @irq_n: Doorbell type +* @data: ipc state +*/ +void ipc_doorbell_fire (struct iosm_pcie *ipc_pcie,int irq_n,u32 data); + +/** +* ipc_release_irq - Release the IRQ handler. +* @ipc_pcie: Pointer to iosm_pcie struct +*/ +void ipc_release_irq (struct iosm_pcie *ipc_pcie); + +/** +* ipc_acquire_irq - acquire IRQ & register IRQ handler. +* @ipc_pcie: Pointer to iosm_pcie struct +* +* Return: 0 on success and failure value on error +*/ +int ipc_acquire_irq (struct iosm_pcie *ipc_pcie); + +#endif
Signature · 1 line
2.25.1
David Miller
maintainerRe: [PATCH V2 02/16] net: iosm: irq handling
From: M Chetan Kumar <[email protected]>
Date: Tue, 20 Apr 2021 21:42:56 +0530
Quoted 19 lines
1) Request interrupt vector, frees allocated resource.
2) Registers IRQ handler.Signed-off-by M Chetan Kumar <[email protected]>---
v2: Streamline multiple returns using goto.--- drivers/net/wwan/iosm/iosm_ipc_irq.c | 91 ++++++++++++++++++++++++++++ drivers/net/wwan/iosm/iosm_ipc_irq.h | 33 ++++++++++ 2 files changed, 124 insertions(+) create mode 100644 drivers/net/wwan/iosm/iosm_ipc_irq.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_irq.hdrivers/net/wwan/iosm/iosm_ipc_irq.c new file +0
-0
drivers/net/wwan/iosm/iosm_ipc_irq.c line 10
Quoted 10 lines
drivers/net/wwan/iosm/iosm_ipc_irq.c new file +10
-0@@ -0,0 +1,91 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2020-21 Intel Corporation. +*/ + +#include "iosm_ipc_pcie.h" +#include "iosm_ipc_protocol.h" + +static inline void write_dbell_reg (struct iosm_pcie *ipc_pcie,int irq_n, +u32 data)
Please do not use inline in foo.c files, let the compiler decide.
Thank you.
PATCH v2 3/16 net: iosm: mmio scratchpad
In reply to M Chetan Kumar1) Initializes the Scratchpad region for Host-Device communication.
2) Exposes device capabilities like chip info and device execution stages.
---
v2:
* Removed space around the : for the bitfields.
* Return proper error code instead of returning -1.
--- drivers/net/wwan/iosm/iosm_ipc_mmio.c | 223 ++++++++++++++++++++++++++ drivers/net/wwan/iosm/iosm_ipc_mmio.h | 193 ++++++++++++++++++++++ 2 files changed, 416 insertions(+) create mode 100644 drivers/net/wwan/iosm/iosm_ipc_mmio.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_mmio.h
drivers/net/wwan/iosm/iosm_ipc_mmio.c new file +223 -0
@@ -0,0 +1,223 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2020-21 Intel Corporation. +*/ + +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/io.h> +#include <linux/io-64-nonatomic-lo-hi.h> +#include <linux/slab.h> + +#include "iosm_ipc_mmio.h" + +/* Definition of MMIO offsets +* note that MMIO_CI offsets are relative to end of chip info structure +*/ + +/* MMIO chip info size in bytes */ +#define MMIO_CHIP_INFO_SIZE 60 + +/* CP execution stage */ +#define MMIO_OFFSET_EXECUTION_STAGE 0x00 + +/* Boot ROM Chip Info struct */ +#define MMIO_OFFSET_CHIP_INFO 0x04 + +#define MMIO_OFFSET_ROM_EXIT_CODE 0x40 + +#define MMIO_OFFSET_PSI_ADDRESS 0x54 + +#define MMIO_OFFSET_PSI_SIZE 0x5C + +#define MMIO_OFFSET_IPC_STATUS 0x60 + +#define MMIO_OFFSET_CONTEXT_INFO 0x64 + +#define MMIO_OFFSET_BASE_ADDR 0x6C + +#define MMIO_OFFSET_END_ADDR 0x74 + +#define MMIO_OFFSET_CP_VERSION 0xF0 + +#define MMIO_OFFSET_CP_CAPABILITIES 0xF4 + +/* Timeout in 50 msec to wait for the modem boot code to write a valid +* execution stage into mmio area +*/ +#define IPC_MMIO_EXEC_STAGE_TIMEOUT 50 + +/* check if exec stage has one of the valid values */ +static bool ipc_mmio_is_valid_exec_stage (enum ipc_mem_exec_stage stage) +{ +switch (stage) { +case IPC_MEM_EXEC_STAGE_BOOT : +case IPC_MEM_EXEC_STAGE_PSI : +case IPC_MEM_EXEC_STAGE_EBL : +case IPC_MEM_EXEC_STAGE_RUN : +case IPC_MEM_EXEC_STAGE_CRASH : +case IPC_MEM_EXEC_STAGE_CD_READY : +return true; +default : +return false; + } +} + +void ipc_mmio_update_cp_capability (struct iosm_mmio *ipc_mmio) +{ +u32 cp_cap; +unsigned int ver; + + ver =ipc_mmio_get_cp_version (ipc_mmio); + cp_cap =readl (ipc_mmio->base + ipc_mmio->offset.cp_capability); + + ipc_mmio->has_mux_lite = (ver >=IOSM_CP_VERSION ) && + !(cp_cap &DL_AGGR ) && !(cp_cap &UL_AGGR ); + + ipc_mmio->has_ul_flow_credit = + (ver >=IOSM_CP_VERSION ) && (cp_cap &UL_FLOW_CREDIT ); +} + +struct iosm_mmio *ipc_mmio_init (void __iomem *mmio,struct device *dev) +{ +struct iosm_mmio *ipc_mmio =kzalloc (sizeof (*ipc_mmio),GFP_KERNEL ); +int retries =IPC_MMIO_EXEC_STAGE_TIMEOUT ; +enum ipc_mem_exec_stage stage; + +if (!ipc_mmio) +return NULL ; + + ipc_mmio->dev = dev; + + ipc_mmio->base = mmio; + + ipc_mmio->offset.exec_stage =MMIO_OFFSET_EXECUTION_STAGE ; + +/* Check for a valid execution stage to make sure that the boot code +* has correctly initialized the MMIO area. +*/ +do { + stage =ipc_mmio_get_exec_stage (ipc_mmio); +if (ipc_mmio_is_valid_exec_stage (stage)) +break ; + +msleep (20 ); + }while (retries-- >0 ); + +if (!retries) { +dev_err (ipc_mmio->dev,"invalid exec stage %X" , stage); + goto init_fail; + } + + ipc_mmio->offset.chip_info =MMIO_OFFSET_CHIP_INFO ; + +/* read chip info size and version from chip info structure */ + ipc_mmio->chip_info_version = +ioread8 (ipc_mmio->base + ipc_mmio->offset.chip_info); + +/* Increment of 2 is needed as the size value in the chip info +* excludes the version and size field, which are always present +*/ + ipc_mmio->chip_info_size = +ioread8 (ipc_mmio->base + ipc_mmio->offset.chip_info +1 ) +2 ; + +if (ipc_mmio->chip_info_size !=MMIO_CHIP_INFO_SIZE ) { +dev_err (ipc_mmio->dev,"Unexpected Chip Info" ); + goto init_fail; + } + + ipc_mmio->offset.rom_exit_code =MMIO_OFFSET_ROM_EXIT_CODE ; + + ipc_mmio->offset.psi_address =MMIO_OFFSET_PSI_ADDRESS ; + ipc_mmio->offset.psi_size =MMIO_OFFSET_PSI_SIZE ; + ipc_mmio->offset.ipc_status =MMIO_OFFSET_IPC_STATUS ; + ipc_mmio->offset.context_info =MMIO_OFFSET_CONTEXT_INFO ; + ipc_mmio->offset.ap_win_base =MMIO_OFFSET_BASE_ADDR ; + ipc_mmio->offset.ap_win_end =MMIO_OFFSET_END_ADDR ; + + ipc_mmio->offset.cp_version =MMIO_OFFSET_CP_VERSION ; + ipc_mmio->offset.cp_capability =MMIO_OFFSET_CP_CAPABILITIES ; + +return ipc_mmio; + +init_fail: +kfree (ipc_mmio); +return NULL ; +} + +enum ipc_mem_exec_stage ipc_mmio_get_exec_stage (struct iosm_mmio *ipc_mmio) +{ +if (!ipc_mmio) +return IPC_MEM_EXEC_STAGE_INVALID ; + +return (enum ipc_mem_exec_stage )readl (ipc_mmio->base + + ipc_mmio->offset.exec_stage); +} + +void ipc_mmio_copy_chip_info (struct iosm_mmio *ipc_mmio,void *dest, +size_t size) +{ +if (ipc_mmio && dest) +memcpy_fromio (dest, ipc_mmio->base + ipc_mmio->offset.chip_info, + size); +} + +enum ipc_mem_device_ipc_state ipc_mmio_get_ipc_state (struct iosm_mmio *ipc_mmio) +{ +if (!ipc_mmio) +return IPC_MEM_DEVICE_IPC_INVALID ; + +return (enum ipc_mem_device_ipc_state ) +readl (ipc_mmio->base + ipc_mmio->offset.ipc_status); +} + +enum rom_exit_code ipc_mmio_get_rom_exit_code (struct iosm_mmio *ipc_mmio) +{ +if (!ipc_mmio) +return IMEM_ROM_EXIT_FAIL ; + +return (enum rom_exit_code )readl (ipc_mmio->base + + ipc_mmio->offset.rom_exit_code); +} + +void ipc_mmio_config (struct iosm_mmio *ipc_mmio) +{ +if (!ipc_mmio) +return ; + +/* AP memory window (full window is open and active so that modem checks +* each AP address) 0 means don't check on modem side. +*/ +iowrite64_lo_hi (0 , ipc_mmio->base + ipc_mmio->offset.ap_win_base); +iowrite64_lo_hi (0 , ipc_mmio->base + ipc_mmio->offset.ap_win_end); + +iowrite64_lo_hi (ipc_mmio->context_info_addr, + ipc_mmio->base + ipc_mmio->offset.context_info); +} + +void ipc_mmio_set_psi_addr_and_size (struct iosm_mmio *ipc_mmio,dma_addr_t addr, +u32 size) +{ +if (!ipc_mmio) +return ; + +iowrite64_lo_hi (addr, ipc_mmio->base + ipc_mmio->offset.psi_address); +writel (size, ipc_mmio->base + ipc_mmio->offset.psi_size); +} + +void ipc_mmio_set_contex_info_addr (struct iosm_mmio *ipc_mmio,phys_addr_t addr) +{ +if (!ipc_mmio) +return ; + +/* store context_info address. This will be stored in the mmio area +* during IPC_MEM_DEVICE_IPC_INIT state via ipc_mmio_config() +*/ + ipc_mmio->context_info_addr = addr; +} + +int ipc_mmio_get_cp_version (struct iosm_mmio *ipc_mmio) +{ +return ipc_mmio ?readl (ipc_mmio->base + ipc_mmio->offset.cp_version) : + -EFAULT ; +}
drivers/net/wwan/iosm/iosm_ipc_mmio.h new file +193 -0
193 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 4/16 net: iosm: shared memory IPC interface
In reply to M Chetan Kumar1) Initializes shared memory for host-device communication.
2) Allocate resources required for control & data operations.
3) Transfers the Device IRQ to IPC execution thread.
4) Defines the timer cbs for async events.
---
v2:
* Clean-up vlan tag ids & removed FW flashing logic.
* Function return type correction.
* Return proper error code instead of returning -1.
--- drivers/net/wwan/iosm/iosm_ipc_imem.c | 1390 +++++++++++++++++++++++++ drivers/net/wwan/iosm/iosm_ipc_imem.h | 582 +++++++++++ 2 files changed, 1972 insertions(+) create mode 100644 drivers/net/wwan/iosm/iosm_ipc_imem.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_imem.h
drivers/net/wwan/iosm/iosm_ipc_imem.c new file +1390 -0
@@ -0,0 +1,1390 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2020-21 Intel Corporation. +*/ + +#include <linux/delay.h> + +#include "iosm_ipc_chnl_cfg.h" +#include "iosm_ipc_imem.h" +#include "iosm_ipc_mbim.h" + +/* Check the wwan ips if it is valid with Channel as input. */ +static inline int ipc_imem_check_wwan_ips (struct ipc_mem_channel *chnl) +{ +if (chnl) +return chnl->ctype ==IPC_CTYPE_WWAN && + chnl->if_id ==IPC_MEM_MUX_IP_CH_IF_ID ; +return false; +} + +static int imem_msg_send_device_sleep (struct iosm_imem *ipc_imem,u32 state) +{ +union ipc_msg_prep_args prep_args = { + .sleep.target =1 , + .sleep.state = state, + }; + + ipc_imem->device_sleep = state; + +return ipc_protocol_tq_msg_send (ipc_imem->ipc_protocol, +IPC_MSG_PREP_SLEEP , &prep_args,NULL ); +} + +static bool imem_dl_skb_alloc (struct iosm_imem *ipc_imem,struct ipc_pipe *pipe) +{ +/* limit max. nr of entries */ +if (pipe->nr_of_queued_entries >= pipe->max_nr_of_queued_entries) +return false; + +return ipc_protocol_dl_td_prepare (ipc_imem->ipc_protocol, pipe); +} + +/* This timer handler will retry DL buff allocation if a pipe has no free buf +* and gives doorbell if TD is available +*/ +static int imem_tq_td_alloc_timer (struct iosm_imem *ipc_imem,int arg, +void *msg,size_t size) +{ +bool new_buffers_available = false; +bool retry_allocation = false; +int i; + +for (i =0 ; i <IPC_MEM_MAX_CHANNELS ; i++) { +struct ipc_pipe *pipe = &ipc_imem->channels[i].dl_pipe; + +if (!pipe->is_open || pipe->nr_of_queued_entries >0 ) +continue ; + +while (imem_dl_skb_alloc (ipc_imem, pipe)) + new_buffers_available = true; + +if (pipe->nr_of_queued_entries ==0 ) + retry_allocation = true; + } + +if (new_buffers_available) +ipc_protocol_doorbell_trigger (ipc_imem->ipc_protocol, +IPC_HP_DL_PROCESS ); + +if (retry_allocation) { + ipc_imem->hrtimer_period = +ktime_set (0 ,IPC_TD_ALLOC_TIMER_PERIOD_MS *1000 *1000ULL ); +if (!hrtimer_active (&ipc_imem->td_alloc_timer)) +hrtimer_start (&ipc_imem->td_alloc_timer, + ipc_imem->hrtimer_period, +HRTIMER_MODE_REL ); + } +return 0 ; +} + +static enum hrtimer_restart imem_td_alloc_timer_cb (struct hrtimer *hr_timer) +{ +struct iosm_imem *ipc_imem = + container_of(hr_timer, struct iosm_imem, td_alloc_timer); +/* Post an async tasklet event to trigger HP update Doorbell */ +ipc_task_queue_send_task (ipc_imem, imem_tq_td_alloc_timer,0 ,NULL ,0 , + false); +return HRTIMER_NORESTART ; +} + +/* Fast update timer tasklet handler to trigger HP update */ +static int imem_tq_fast_update_timer_cb (struct iosm_imem *ipc_imem,int arg, +void *msg,size_t size) +{ +ipc_protocol_doorbell_trigger (ipc_imem->ipc_protocol, +IPC_HP_FAST_TD_UPD_TMR ); + +return 0 ; +} + +static enum hrtimer_restart imem_fast_update_timer_cb (struct hrtimer *hr_timer) +{ +struct iosm_imem *ipc_imem = + container_of(hr_timer, struct iosm_imem, fast_update_timer); +/* Post an async tasklet event to trigger HP update Doorbell */ +ipc_task_queue_send_task (ipc_imem, imem_tq_fast_update_timer_cb,0 , +NULL ,0 , false); +return HRTIMER_NORESTART ; +} + +static int imem_setup_cp_mux_cap_init (struct iosm_imem *ipc_imem, +struct ipc_mux_config *cfg) +{ +ipc_mmio_update_cp_capability (ipc_imem->mmio); + +if (!ipc_imem->mmio->has_mux_lite) { +dev_err (ipc_imem->dev,"Failed to get Mux capability." ); +return -EINVAL ; + } + + cfg->protocol =MUX_LITE ; + + cfg->ul_flow = (ipc_imem->mmio->has_ul_flow_credit ==1 ) ? +MUX_UL_ON_CREDITS : +MUX_UL ; + +/* The instance ID is same as channel ID because this is been reused +* for channel alloc function. +*/ + cfg->instance_id =IPC_MEM_MUX_IP_CH_IF_ID ; + cfg->nr_sessions =IPC_MEM_MUX_IP_SESSION_ENTRIES ; + +return 0 ; +} + +void imem_msg_send_feature_set (struct iosm_imem *ipc_imem, +unsigned int reset_enable,bool atomic_ctx) +{ +union ipc_msg_prep_args prep_args = { .feature_set.reset_enable = + reset_enable }; + +if (atomic_ctx) +ipc_protocol_tq_msg_send (ipc_imem->ipc_protocol, +IPC_MSG_PREP_FEATURE_SET , &prep_args, +NULL ); +else +ipc_protocol_msg_send (ipc_imem->ipc_protocol, +IPC_MSG_PREP_FEATURE_SET , &prep_args); +} + +void imem_td_update_timer_start (struct iosm_imem *ipc_imem) +{ +/* Use the TD update timer only in the runtime phase */ +if (!ipc_imem->enter_runtime || ipc_imem->td_update_timer_suspended) { +/* trigger the doorbell irq on CP directly. */ +ipc_protocol_doorbell_trigger (ipc_imem->ipc_protocol, +IPC_HP_TD_UPD_TMR_START ); +return ; + } + +if (!hrtimer_active (&ipc_imem->tdupdate_timer)) { + ipc_imem->hrtimer_period = +ktime_set (0 ,TD_UPDATE_DEFAULT_TIMEOUT_USEC *1000ULL ); +if (!hrtimer_active (&ipc_imem->tdupdate_timer)) +hrtimer_start (&ipc_imem->tdupdate_timer, + ipc_imem->hrtimer_period, +HRTIMER_MODE_REL ); + } +} + +void imem_hrtimer_stop (struct hrtimer *hr_timer) +{ +if (hrtimer_active (hr_timer)) +hrtimer_cancel (hr_timer); +} + +bool imem_ul_write_td (struct iosm_imem *ipc_imem) +{ +struct ipc_mem_channel *channel; +struct sk_buff_head *ul_list; +bool hpda_pending = false; +bool forced_hpdu = false; +struct ipc_pipe *pipe; +int i; + +/* Analyze the uplink pipe of all active channels. */ +for (i =0 ; i < ipc_imem->nr_of_channels; i++) { + channel = &ipc_imem->channels[i]; + +if (channel->state !=IMEM_CHANNEL_ACTIVE ) +continue ; + + pipe = &channel->ul_pipe; + +/* Get the reference to the skbuf accumulator list. */ + ul_list = &channel->ul_list; + +/* Fill the transfer descriptor with the uplink buffer info. */ + hpda_pending |=ipc_protocol_ul_td_send (ipc_imem->ipc_protocol, + pipe, ul_list); + +/* forced HP update needed for non data channels */ +if (hpda_pending && !ipc_imem_check_wwan_ips (channel)) + forced_hpdu = true; + } + +if (forced_hpdu) { + hpda_pending = false; +ipc_protocol_doorbell_trigger (ipc_imem->ipc_protocol, +IPC_HP_UL_WRITE_TD ); + } + +return hpda_pending; +} + +void imem_ipc_init_check (struct iosm_imem *ipc_imem) +{ +int timeout =IPC_MODEM_BOOT_TIMEOUT ; + + ipc_imem->ipc_requested_state =IPC_MEM_DEVICE_IPC_INIT ; + +/* Trigger the CP interrupt to enter the init state. */ +ipc_doorbell_fire (ipc_imem->pcie,IPC_DOORBELL_IRQ_IPC , +IPC_MEM_DEVICE_IPC_INIT ); +/* Wait for the CP update. */ +do { +if (ipc_mmio_get_ipc_state (ipc_imem->mmio) == + ipc_imem->ipc_requested_state) { +/* Prepare the MMIO space */ +ipc_mmio_config (ipc_imem->mmio); + +/* Trigger the CP irq to enter the running state. */ + ipc_imem->ipc_requested_state = +IPC_MEM_DEVICE_IPC_RUNNING ; +ipc_doorbell_fire (ipc_imem->pcie,IPC_DOORBELL_IRQ_IPC , +IPC_MEM_DEVICE_IPC_RUNNING ); + +return ; + } +msleep (20 ); + }while (--timeout); + +/* timeout */ +dev_err (ipc_imem->dev,"%s: ipc_status(%d) ne. IPC_MEM_DEVICE_IPC_INIT" , +ipc_ap_phase_get_string (ipc_imem->phase), +ipc_mmio_get_ipc_state (ipc_imem->mmio)); + +ipc_uevent_send (ipc_imem->dev,UEVENT_MDM_TIMEOUT ); +} + +/* Analyze the packet type and distribute it. */ +static void imem_dl_skb_process (struct iosm_imem *ipc_imem, +struct ipc_pipe *pipe,struct sk_buff *skb) +{ +int index =0 ; + +if (!skb) +return ; + +/* An AT/control or IP packet is expected. */ +switch (pipe->channel->ctype) { +case IPC_CTYPE_MBIM : +/* Pass the packet to the char layer. */ +if (imem_sys_cdev_receive (ipc_imem->mbim, skb)) + goto rcv_err; +break ; + +case IPC_CTYPE_WWAN : +/* allow the packet if interface id is from 257 to 261. */ +if (pipe->channel->if_id >=DSS_SESSION_START && + pipe->channel->if_id <=DSS_SESSION_END ) { +if (pipe->channel->state !=IMEM_CHANNEL_ACTIVE ) + goto rcv_err; + +IPC_CB (skb)->mapping =0 ; +/* unmap skb from address mapping */ +ipc_pcie_addr_unmap (ipc_imem->pcie,IPC_CB (skb)->len, +IPC_CB (skb)->mapping, +IPC_CB (skb)->direction); + + index = pipe->channel->if_id; + +/* Complete all memory stores before this point */ +smp_mb (); +if (index >=DSS_SESSION_START && index <=DSS_SESSION_END ) + index = (index -DSS_SESSION_START ) +IP_MUX_SESSION_END +1 ; + +if (ipc_wwan_receive (ipc_imem->wwan, skb, true, index -1 )) + pipe->channel->net_err_count++; +/* DL packet through IP MUX layer */ + }else if (pipe->channel->if_id == +IPC_MEM_MUX_IP_CH_IF_ID ) { +ipc_mux_dl_decode (ipc_imem->mux, skb); + } +break ; +default : +dev_err (ipc_imem->dev,"Invalid channel type" ); +break ; + } +return ; + +rcv_err: +ipc_pcie_kfree_skb (ipc_imem->pcie, skb); +} + +/* Process the downlink data and pass them to the char or net layer. */ +static void imem_dl_pipe_process (struct iosm_imem *ipc_imem, +struct ipc_pipe *pipe) +{ +s32 cnt =0 , processed_td_cnt =0 ; +struct ipc_mem_channel *channel; +u32 head =0 , tail =0 ; +bool processed = false; +struct sk_buff *skb; + + channel = pipe->channel; + +ipc_protocol_get_head_tail_index (ipc_imem->ipc_protocol, pipe, &head, + &tail); +if (pipe->old_tail != tail) { +if (pipe->old_tail < tail) + cnt = tail - pipe->old_tail; +else + cnt = pipe->nr_of_entries - pipe->old_tail + tail; + } + + processed_td_cnt = cnt; + +/* Seek for pipes with pending DL data. */ +while (cnt--) { + skb =ipc_protocol_dl_td_process (ipc_imem->ipc_protocol, pipe); + +/* Analyze the packet type and distribute it. */ +imem_dl_skb_process (ipc_imem, pipe, skb); + } + +/* try to allocate new empty DL SKbs from head..tail - 1*/ +while (imem_dl_skb_alloc (ipc_imem, pipe)) + processed = true; + +if (processed && !ipc_imem_check_wwan_ips (channel)) { +/* Force HP update for non IP channels */ +ipc_protocol_doorbell_trigger (ipc_imem->ipc_protocol, +IPC_HP_DL_PROCESS ); + processed = false; + +/* If Fast Update timer is already running then stop */ +imem_hrtimer_stop (&ipc_imem->fast_update_timer); + } + +/* Any control channel process will get immediate HP update. +* Start Fast update timer only for IP channel if all the TDs were +* used in last process. +*/ +if (processed && (processed_td_cnt == pipe->nr_of_entries -1 )) { + ipc_imem->hrtimer_period = +ktime_set (0 ,FORCE_UPDATE_DEFAULT_TIMEOUT_USEC *1000ULL ); +hrtimer_start (&ipc_imem->fast_update_timer, + ipc_imem->hrtimer_period,HRTIMER_MODE_REL ); + } + +if (ipc_imem->app_notify_dl_pend) +complete (&ipc_imem->dl_pend_sem); +} + +/* process open uplink pipe */ +static void imem_ul_pipe_process (struct iosm_imem *ipc_imem, +struct ipc_pipe *pipe) +{ +struct ipc_mem_channel *channel; +u32 tail =0 , head =0 ; +struct sk_buff *skb; +s32 cnt =0 ; + + channel = pipe->channel; + +/* Get the internal phase. */ +ipc_protocol_get_head_tail_index (ipc_imem->ipc_protocol, pipe, &head, + &tail); + +if (pipe->old_tail != tail) { +if (pipe->old_tail < tail) + cnt = tail - pipe->old_tail; +else + cnt = pipe->nr_of_entries - pipe->old_tail + tail; + } + +/* Free UL buffers. */ +while (cnt--) { + skb =ipc_protocol_ul_td_process (ipc_imem->ipc_protocol, pipe); + +if (!skb) +continue ; + +/* If the user app was suspended in uplink direction - blocking +* write, resume it. +*/ +if (IPC_CB (skb)->op_type ==UL_USR_OP_BLOCKED ) +complete (&channel->ul_sem); + +/* Free the skbuf element. */ +if (IPC_CB (skb)->op_type ==UL_MUX_OP_ADB ) { +if (channel->if_id ==IPC_MEM_MUX_IP_CH_IF_ID ) +ipc_mux_ul_encoded_process (ipc_imem->mux, skb); +else +dev_err (ipc_imem->dev, +"Channel OP Type is UL_MUX but if_id %d is unknown" , + channel->if_id); + }else { +ipc_pcie_kfree_skb (ipc_imem->pcie, skb); + } + } + +/* Trace channel stats for IP UL pipe. */ +if (ipc_imem_check_wwan_ips (pipe->channel)) +ipc_mux_check_n_restart_tx (ipc_imem->mux); + +if (ipc_imem->app_notify_ul_pend) +complete (&ipc_imem->ul_pend_sem); +} + +/* Executes the irq. */ +static void imem_rom_irq_exec (struct iosm_imem *ipc_imem) +{ +struct ipc_mem_channel *channel; + +if (ipc_imem->flash_channel_id <0 ) { + ipc_imem->rom_exit_code =IMEM_ROM_EXIT_FAIL ; +dev_err (ipc_imem->dev,"Missing flash app:%d" , + ipc_imem->flash_channel_id); +return ; + } + + ipc_imem->rom_exit_code =ipc_mmio_get_rom_exit_code (ipc_imem->mmio); + +/* Wake up the flash app to continue or to terminate depending +* on the CP ROM exit code. +*/ + channel = &ipc_imem->channels[ipc_imem->flash_channel_id]; +complete (&channel->ul_sem); +} + +/* Execute the UL bundle timer actions, generating the doorbell irq. */ +static int imem_tq_td_update_timer_cb (struct iosm_imem *ipc_imem,int arg, +void *msg,size_t size) +{ +ipc_protocol_doorbell_trigger (ipc_imem->ipc_protocol, +IPC_HP_TD_UPD_TMR ); +return 0 ; +} + +/* Consider link power management in the runtime phase. */ +static void imem_slp_control_exec (struct iosm_imem *ipc_imem) +{ +/* link will go down, Test pending UL packets.*/ +if (ipc_protocol_pm_dev_sleep_handle (ipc_imem->ipc_protocol) && +hrtimer_active (&ipc_imem->tdupdate_timer)) { +/* Generate the doorbell irq. */ +imem_tq_td_update_timer_cb (ipc_imem,0 ,NULL ,0 ); +/* Stop the TD update timer. */ +imem_hrtimer_stop (&ipc_imem->tdupdate_timer); +/* Stop the fast update timer. */ +imem_hrtimer_stop (&ipc_imem->fast_update_timer); + } +} + +/* Execute startup timer and wait for delayed start (e.g. NAND) */ +static int imem_tq_startup_timer_cb (struct iosm_imem *ipc_imem,int arg, +void *msg,size_t size) +{ +/* Update & check the current operation phase. */ +if (imem_ap_phase_update (ipc_imem) !=IPC_P_RUN ) +return -EIO ; + +if (ipc_mmio_get_ipc_state (ipc_imem->mmio) == +IPC_MEM_DEVICE_IPC_UNINIT ) { + ipc_imem->ipc_requested_state =IPC_MEM_DEVICE_IPC_INIT ; + +ipc_doorbell_fire (ipc_imem->pcie,IPC_DOORBELL_IRQ_IPC , +IPC_MEM_DEVICE_IPC_INIT ); + + ipc_imem->hrtimer_period =ktime_set (0 ,100 *1000UL *1000ULL ); +/* reduce period to 100 ms to check for mmio init state */ +if (!hrtimer_active (&ipc_imem->startup_timer)) +hrtimer_start (&ipc_imem->startup_timer, + ipc_imem->hrtimer_period, +HRTIMER_MODE_REL ); + }else if (ipc_mmio_get_ipc_state (ipc_imem->mmio) == +IPC_MEM_DEVICE_IPC_INIT ) { +/* Startup complete - disable timer */ +imem_hrtimer_stop (&ipc_imem->startup_timer); + +/* Prepare the MMIO space */ +ipc_mmio_config (ipc_imem->mmio); + ipc_imem->ipc_requested_state =IPC_MEM_DEVICE_IPC_RUNNING ; +ipc_doorbell_fire (ipc_imem->pcie,IPC_DOORBELL_IRQ_IPC , +IPC_MEM_DEVICE_IPC_RUNNING ); + } + +return 0 ; +} + +static enum hrtimer_restart imem_startup_timer_cb (struct hrtimer *hr_timer) +{ +enum hrtimer_restart result =HRTIMER_NORESTART ; +struct iosm_imem *ipc_imem = + container_of(hr_timer, struct iosm_imem, startup_timer); + +if (ktime_to_ns (ipc_imem->hrtimer_period)) { +hrtimer_forward (&ipc_imem->startup_timer,ktime_get (), + ipc_imem->hrtimer_period); + result =HRTIMER_RESTART ; + } + +ipc_task_queue_send_task (ipc_imem, imem_tq_startup_timer_cb,0 ,NULL ,0 , + false); +return result; +} + +/* Get the CP execution stage */ +static enum ipc_mem_exec_stage +ipc_imem_get_exec_stage_buffered (struct iosm_imem *ipc_imem) +{ +return (ipc_imem->phase ==IPC_P_RUN && + ipc_imem->ipc_status ==IPC_MEM_DEVICE_IPC_RUNNING ) ? +ipc_protocol_get_ap_exec_stage (ipc_imem->ipc_protocol) : +ipc_mmio_get_exec_stage (ipc_imem->mmio); +} + +/* Callback to send the modem ready uevent */ +static int imem_send_mdm_rdy_cb (struct iosm_imem *ipc_imem,int arg,void *msg, +size_t size) +{ +enum ipc_mem_exec_stage exec_stage = +ipc_imem_get_exec_stage_buffered (ipc_imem); + +if (exec_stage ==IPC_MEM_EXEC_STAGE_RUN ) +ipc_uevent_send (ipc_imem->dev,UEVENT_MDM_READY ); + +return 0 ; +} + +/* This function is executed in a task context via an ipc_worker object, +* as the creation or removal of device can't be done from tasklet. +*/ +static void ipc_imem_run_state_worker (struct work_struct *instance) +{ +struct ipc_chnl_cfg chnl_cfg_mbim = {0 }; +struct ipc_mux_config mux_cfg; +struct iosm_imem *ipc_imem; +char name_mbim[32 ] = {0 };/* Holds mbim device name */ + + ipc_imem = container_of(instance, struct iosm_imem, run_state_worker); + +if (ipc_imem->phase !=IPC_P_RUN ) { +dev_err (ipc_imem->dev, +"Modem link down. Exit run state worker." ); +return ; + } + +if (!imem_setup_cp_mux_cap_init (ipc_imem, &mux_cfg)) + ipc_imem->mux =mux_init (&mux_cfg, ipc_imem); + +wwan_channel_init (ipc_imem, mux_cfg.protocol); +if (ipc_imem->mux) + ipc_imem->mux->wwan = ipc_imem->wwan; + +if (!ipc_chnl_cfg_get (&chnl_cfg_mbim,IPC_MEM_MBIM_CTRL_CH_ID )) { +imem_channel_init (ipc_imem,IPC_CTYPE_MBIM , chnl_cfg_mbim, +IRQ_MOD_OFF ); +snprintf (name_mbim,sizeof (name_mbim) -1 ,"wwanctrl" ); + ipc_imem->mbim =ipc_mbim_init (ipc_imem, name_mbim); + } + +ipc_task_queue_send_task (ipc_imem, imem_send_mdm_rdy_cb,0 ,NULL ,0 , + false); + +/* Complete all memory stores before setting bit */ +smp_mb__before_atomic (); + +set_bit (FULLY_FUNCTIONAL , &ipc_imem->flag); + +/* Complete all memory stores after setting bit */ +smp_mb__after_atomic (); +} + +static void imem_handle_irq (struct iosm_imem *ipc_imem,int irq) +{ +enum ipc_mem_device_ipc_state curr_ipc_status; +enum ipc_phase old_phase, phase; +bool retry_allocation = false; +bool ul_pending = false; +int ch_id, i; + +if (irq !=IMEM_IRQ_DONT_CARE ) + ipc_imem->ev_irq_pending[irq] = false; + +/* Get the internal phase. */ + old_phase = ipc_imem->phase; + +if (old_phase ==IPC_P_OFF_REQ ) { +dev_dbg (ipc_imem->dev, +"[%s]: Ignoring MSI. Deinit sequence in progress!" , +ipc_ap_phase_get_string (old_phase)); +return ; + } + +/* Update the phase controlled by CP. */ + phase =imem_ap_phase_update (ipc_imem); + +switch (phase) { +case IPC_P_RUN : +if (!ipc_imem->enter_runtime) { +/* Excute the transition from flash/boot to runtime. */ + ipc_imem->enter_runtime =1 ; + +/* allow device to sleep, default value is +* IPC_HOST_SLEEP_ENTER_SLEEP +*/ +imem_msg_send_device_sleep (ipc_imem, + ipc_imem->device_sleep); + +imem_msg_send_feature_set (ipc_imem, +IPC_MEM_INBAND_CRASH_SIG , + true); + } + + curr_ipc_status = +ipc_protocol_get_ipc_status (ipc_imem->ipc_protocol); + +/* check ipc_status change */ +if (ipc_imem->ipc_status != curr_ipc_status) { + ipc_imem->ipc_status = curr_ipc_status; + +if (ipc_imem->ipc_status == +IPC_MEM_DEVICE_IPC_RUNNING ) { +schedule_work (&ipc_imem->run_state_worker); + } + } + +/* Consider power management in the runtime phase. */ +imem_slp_control_exec (ipc_imem); +break ;/* Continue with skbuf processing. */ + +/* Unexpected phases. */ +case IPC_P_OFF : +case IPC_P_OFF_REQ : +dev_err (ipc_imem->dev,"confused phase %s" , +ipc_ap_phase_get_string (phase)); +return ; + +case IPC_P_PSI : +if (old_phase !=IPC_P_ROM ) +break ; + + fallthrough; +/* On CP the PSI phase is already active. */ + +case IPC_P_ROM : +/* Before CP ROM driver starts the PSI image, it sets +* the exit_code field on the doorbell scratchpad and +* triggers the irq. +*/ +imem_rom_irq_exec (ipc_imem); +return ; + +default : +break ; + } + +/* process message ring */ +ipc_protocol_msg_process (ipc_imem, irq); + +/* process all open pipes */ +for (i =0 ; i <IPC_MEM_MAX_CHANNELS ; i++) { +struct ipc_pipe *ul_pipe = &ipc_imem->channels[i].ul_pipe; +struct ipc_pipe *dl_pipe = &ipc_imem->channels[i].dl_pipe; + +if (dl_pipe->is_open && + (irq ==IMEM_IRQ_DONT_CARE || irq == dl_pipe->irq)) { +imem_dl_pipe_process (ipc_imem, dl_pipe); + +if (dl_pipe->nr_of_queued_entries ==0 ) + retry_allocation = true; + } + +if (ul_pipe->is_open) +imem_ul_pipe_process (ipc_imem, ul_pipe); + } + +/* Try to generate new ADB or ADGH. */ +if (ipc_mux_ul_data_encode (ipc_imem->mux)) +imem_td_update_timer_start (ipc_imem); + +/* Continue the send procedure with accumulated SIO or NETIF packets. +* Reset the debounce flags. +*/ + ul_pending |=imem_ul_write_td (ipc_imem); + +/* if UL data is pending restart TD update timer */ +if (ul_pending) { + ipc_imem->hrtimer_period = +ktime_set (0 ,TD_UPDATE_DEFAULT_TIMEOUT_USEC *1000ULL ); +if (!hrtimer_active (&ipc_imem->tdupdate_timer)) +hrtimer_start (&ipc_imem->tdupdate_timer, + ipc_imem->hrtimer_period, +HRTIMER_MODE_REL ); + } + +/* If CP has executed the transition +* from IPC_INIT to IPC_RUNNING in the PSI +* phase, wake up the flash app to open the pipes. +*/ +if ((phase ==IPC_P_PSI || phase ==IPC_P_EBL ) && + ipc_imem->ipc_requested_state ==IPC_MEM_DEVICE_IPC_RUNNING && +ipc_mmio_get_ipc_state (ipc_imem->mmio) == +IPC_MEM_DEVICE_IPC_RUNNING && + ipc_imem->flash_channel_id >=0 ) { +/* Wake up the flash app to open the pipes. */ + ch_id = ipc_imem->flash_channel_id; +complete (&ipc_imem->channels[ch_id].ul_sem); + } + +/* Reset the expected CP state. */ + ipc_imem->ipc_requested_state =IPC_MEM_DEVICE_IPC_DONT_CARE ; + +if (retry_allocation) { + ipc_imem->hrtimer_period = +ktime_set (0 ,IPC_TD_ALLOC_TIMER_PERIOD_MS *1000 *1000ULL ); +if (!hrtimer_active (&ipc_imem->td_alloc_timer)) +hrtimer_start (&ipc_imem->td_alloc_timer, + ipc_imem->hrtimer_period, +HRTIMER_MODE_REL ); + } +} + +/* Callback by tasklet for handling interrupt events. */ +static int imem_tq_irq_cb (struct iosm_imem *ipc_imem,int arg,void *msg, +size_t size) +{ +imem_handle_irq (ipc_imem, arg); + +return 0 ; +} + +void imem_ul_send (struct iosm_imem *ipc_imem) +{ +/* start doorbell irq delay timer if UL is pending */ +if (imem_ul_write_td (ipc_imem)) +imem_td_update_timer_start (ipc_imem); +} + +/* Check the execution stage and update the AP phase */ +static enum ipc_phase imem_ap_phase_update_check (struct iosm_imem *ipc_imem, +enum ipc_mem_exec_stage stage) +{ +switch (stage) { +case IPC_MEM_EXEC_STAGE_BOOT : +if (ipc_imem->phase !=IPC_P_ROM ) { +/* Send this event only once */ +ipc_uevent_send (ipc_imem->dev,UEVENT_ROM_READY ); + } + + ipc_imem->phase =IPC_P_ROM ; +break ; + +case IPC_MEM_EXEC_STAGE_PSI : + ipc_imem->phase =IPC_P_PSI ; +break ; + +case IPC_MEM_EXEC_STAGE_EBL : + ipc_imem->phase =IPC_P_EBL ; +break ; + +case IPC_MEM_EXEC_STAGE_RUN : +if (ipc_imem->phase !=IPC_P_RUN && + ipc_imem->ipc_status ==IPC_MEM_DEVICE_IPC_RUNNING ) { +ipc_uevent_send (ipc_imem->dev,UEVENT_MDM_READY ); + } + ipc_imem->phase =IPC_P_RUN ; +break ; + +case IPC_MEM_EXEC_STAGE_CRASH : +if (ipc_imem->phase !=IPC_P_CRASH ) +ipc_uevent_send (ipc_imem->dev,UEVENT_CRASH ); + + ipc_imem->phase =IPC_P_CRASH ; +break ; + +case IPC_MEM_EXEC_STAGE_CD_READY : +if (ipc_imem->phase !=IPC_P_CD_READY ) +ipc_uevent_send (ipc_imem->dev,UEVENT_CD_READY ); + ipc_imem->phase =IPC_P_CD_READY ; +break ; + +default : +/* unknown exec stage: +* assume that link is down and send info to listeners +*/ +ipc_uevent_send (ipc_imem->dev,UEVENT_CD_READY_LINK_DOWN ); +break ; + } + +return ipc_imem->phase; +} + +/* Send msg to device to open pipe */ +static bool imem_pipe_open (struct iosm_imem *ipc_imem,struct ipc_pipe *pipe) +{ +union ipc_msg_prep_args prep_args = { + .pipe_open.pipe = pipe, + }; + +if (ipc_protocol_msg_send (ipc_imem->ipc_protocol, +IPC_MSG_PREP_PIPE_OPEN , &prep_args) ==0 ) + pipe->is_open = true; + +return pipe->is_open; +} + +/* Allocates the TDs for the given pipe along with firing HP update DB. */ +static int imem_tq_pipe_td_alloc (struct iosm_imem *ipc_imem,int arg,void *msg, +size_t size) +{ +struct ipc_pipe *dl_pipe = msg; +bool processed = false; +int i; + +for (i =0 ; i < dl_pipe->nr_of_entries -1 ; i++) + processed |=imem_dl_skb_alloc (ipc_imem, dl_pipe); + +/* Trigger the doorbell irq to inform CP that new downlink buffers are +* available. +*/ +if (processed) +ipc_protocol_doorbell_trigger (ipc_imem->ipc_protocol, arg); + +return 0 ; +} + +static enum hrtimer_restart imem_td_update_timer_cb (struct hrtimer *hr_timer) +{ +struct iosm_imem *ipc_imem = + container_of(hr_timer, struct iosm_imem, tdupdate_timer); + +ipc_task_queue_send_task (ipc_imem, imem_tq_td_update_timer_cb,0 ,NULL , +0 , false); +return HRTIMER_NORESTART ; +} + +/* Get the CP execution state and map it to the AP phase. */ +enum ipc_phase imem_ap_phase_update (struct iosm_imem *ipc_imem) +{ +enum ipc_mem_exec_stage exec_stage = +ipc_imem_get_exec_stage_buffered (ipc_imem); +/* If the CP stage is undef, return the internal precalculated phase. */ +return ipc_imem->phase ==IPC_P_OFF_REQ ? + ipc_imem->phase : +imem_ap_phase_update_check (ipc_imem, exec_stage); +} + +const char *ipc_ap_phase_get_string (enum ipc_phase phase) +{ +switch (phase) { +case IPC_P_RUN : +return "A-RUN" ; + +case IPC_P_OFF : +return "A-OFF" ; + +case IPC_P_ROM : +return "A-ROM" ; + +case IPC_P_PSI : +return "A-PSI" ; + +case IPC_P_EBL : +return "A-EBL" ; + +case IPC_P_CRASH : +return "A-CRASH" ; + +case IPC_P_CD_READY : +return "A-CD_READY" ; + +case IPC_P_OFF_REQ : +return "A-OFF_REQ" ; + +default : +return "A-???" ; + } +} + +void imem_pipe_close (struct iosm_imem *ipc_imem,struct ipc_pipe *pipe) +{ +union ipc_msg_prep_args prep_args = { .pipe_close.pipe = pipe }; + + pipe->is_open = false; +ipc_protocol_msg_send (ipc_imem->ipc_protocol,IPC_MSG_PREP_PIPE_CLOSE , + &prep_args); + +imem_pipe_cleanup (ipc_imem, pipe); +} + +void imem_channel_close (struct iosm_imem *ipc_imem,int channel_id) +{ +struct ipc_mem_channel *channel; + +if (channel_id <0 || channel_id >= ipc_imem->nr_of_channels) { +dev_err (ipc_imem->dev,"invalid channel id %d" , channel_id); +return ; + } + + channel = &ipc_imem->channels[channel_id]; + +if (channel->state ==IMEM_CHANNEL_FREE ) { +dev_err (ipc_imem->dev,"ch[%d]: invalid channel state %d" , + channel_id, channel->state); +return ; + } + +/* Free only the channel id in the CP power off mode. */ +if (channel->state ==IMEM_CHANNEL_RESERVED ) +/* Release only the channel id. */ + goto channel_free; + +if (ipc_imem->phase ==IPC_P_RUN ) { +imem_pipe_close (ipc_imem, &channel->ul_pipe); +imem_pipe_close (ipc_imem, &channel->dl_pipe); + } + +imem_pipe_cleanup (ipc_imem, &channel->ul_pipe); +imem_pipe_cleanup (ipc_imem, &channel->dl_pipe); + +channel_free: +imem_channel_free (channel); +} + +struct ipc_mem_channel *imem_channel_open (struct iosm_imem *ipc_imem, +int channel_id,u32 db_id) +{ +struct ipc_mem_channel *channel; + +if (channel_id <0 || channel_id >=IPC_MEM_MAX_CHANNELS ) { +dev_err (ipc_imem->dev,"invalid channel ID: %d" , channel_id); +return NULL ; + } + + channel = &ipc_imem->channels[channel_id]; + + channel->state =IMEM_CHANNEL_ACTIVE ; + +if (!imem_pipe_open (ipc_imem, &channel->ul_pipe)) + goto ul_pipe_err; + +if (!imem_pipe_open (ipc_imem, &channel->dl_pipe)) + goto dl_pipe_err; + +/* Allocate the downlink buffers in tasklet context. */ +if (ipc_task_queue_send_task (ipc_imem, imem_tq_pipe_td_alloc, db_id, + &channel->dl_pipe,0 , false)) { +dev_err (ipc_imem->dev,"td allocation failed : %d" , channel_id); + goto task_failed; + } + +/* Active channel. */ +return channel; +task_failed: +imem_pipe_close (ipc_imem, &channel->dl_pipe); +dl_pipe_err: +imem_pipe_close (ipc_imem, &channel->ul_pipe); +ul_pipe_err: +imem_channel_free (channel); +return NULL ; +} + +void ipc_imem_pm_suspend (struct iosm_imem *ipc_imem) +{ +ipc_protocol_suspend (ipc_imem->ipc_protocol); +} + +void ipc_imem_pm_s2idle_sleep (struct iosm_imem *ipc_imem,bool sleep) +{ +ipc_protocol_s2idle_sleep (ipc_imem->ipc_protocol, sleep); +} + +void ipc_imem_pm_resume (struct iosm_imem *ipc_imem) +{ +enum ipc_mem_exec_stage stage; + +if (ipc_protocol_resume (ipc_imem->ipc_protocol)) { + stage =ipc_mmio_get_exec_stage (ipc_imem->mmio); +imem_ap_phase_update_check (ipc_imem, stage); + } +} + +void imem_channel_free (struct ipc_mem_channel *channel) +{ +/* Reset dynamic channel elements. */ + channel->state =IMEM_CHANNEL_FREE ; +} + +int imem_channel_alloc (struct iosm_imem *ipc_imem,int index, +enum ipc_ctype ctype) +{ +struct ipc_mem_channel *channel; +int i; + +/* Find channel of given type/index */ +for (i =0 ; i < ipc_imem->nr_of_channels; i++) { + channel = &ipc_imem->channels[i]; +if (channel->ctype == ctype && channel->index == index) +break ; + } + +if (i >= ipc_imem->nr_of_channels) { +dev_dbg (ipc_imem->dev, +"no channel definition for index=%d ctype=%d" , index, + ctype); +return -ECHRNG ; + } + +if (ipc_imem->channels[i].state !=IMEM_CHANNEL_FREE ) { +dev_dbg (ipc_imem->dev,"channel is in use" ); +return -EBUSY ; + } + +/* set interface id here only for dss channels */ +if (channel->ctype ==IPC_CTYPE_WWAN && + ((index >=DSS_CHANNEL_START && index <=DSS_CHANNEL_END ) || + index ==IPC_MEM_MUX_IP_CH_IF_ID )) + channel->if_id = index; + + channel->state =IMEM_CHANNEL_RESERVED ; + +return i; +} + +void imem_channel_init (struct iosm_imem *ipc_imem,enum ipc_ctype ctype, +struct ipc_chnl_cfg chnl_cfg,u32 irq_moderation) +{ +struct ipc_mem_channel *channel; + +if (chnl_cfg.ul_pipe >=IPC_MEM_MAX_PIPES || + chnl_cfg.dl_pipe >=IPC_MEM_MAX_PIPES ) { +dev_err (ipc_imem->dev,"invalid pipe: ul_pipe=%d, dl_pipe=%d" , + chnl_cfg.ul_pipe, chnl_cfg.dl_pipe); +return ; + } + +if (ipc_imem->nr_of_channels >=IPC_MEM_MAX_CHANNELS ) { +dev_err (ipc_imem->dev,"too many channels" ); +return ; + } + + channel = &ipc_imem->channels[ipc_imem->nr_of_channels]; + channel->channel_id = ipc_imem->nr_of_channels; + channel->ctype = ctype; + channel->index = chnl_cfg.id; + channel->net_err_count =0 ; + channel->state =IMEM_CHANNEL_FREE ; + ipc_imem->nr_of_channels++; + +ipc_imem_channel_update (ipc_imem, channel->channel_id, chnl_cfg, +IRQ_MOD_OFF ); + +skb_queue_head_init (&channel->ul_list); + +init_completion (&channel->ul_sem); +} + +void ipc_imem_channel_update (struct iosm_imem *ipc_imem,int id, +struct ipc_chnl_cfg chnl_cfg,u32 irq_moderation) +{ +struct ipc_mem_channel *channel; + +if (id <0 || id >= ipc_imem->nr_of_channels) { +dev_err (ipc_imem->dev,"invalid channel id %d" , id); +return ; + } + + channel = &ipc_imem->channels[id]; + +if (channel->state !=IMEM_CHANNEL_FREE && + channel->state !=IMEM_CHANNEL_RESERVED ) { +dev_err (ipc_imem->dev,"invalid channel state %d" , + channel->state); +return ; + } + + channel->ul_pipe.nr_of_entries = chnl_cfg.ul_nr_of_entries; + channel->ul_pipe.pipe_nr = chnl_cfg.ul_pipe; + channel->ul_pipe.is_open = false; + channel->ul_pipe.irq =IPC_UL_PIPE_IRQ_VECTOR ; + channel->ul_pipe.channel = channel; + channel->ul_pipe.dir =IPC_MEM_DIR_UL ; + channel->ul_pipe.accumulation_backoff = chnl_cfg.accumulation_backoff; + channel->ul_pipe.irq_moderation = irq_moderation; + channel->ul_pipe.buf_size =0 ; + + channel->dl_pipe.nr_of_entries = chnl_cfg.dl_nr_of_entries; + channel->dl_pipe.pipe_nr = chnl_cfg.dl_pipe; + channel->dl_pipe.is_open = false; + channel->dl_pipe.irq =IPC_DL_PIPE_IRQ_VECTOR ; + channel->dl_pipe.channel = channel; + channel->dl_pipe.dir =IPC_MEM_DIR_DL ; + channel->dl_pipe.accumulation_backoff = chnl_cfg.accumulation_backoff; + channel->dl_pipe.irq_moderation = irq_moderation; + channel->dl_pipe.buf_size = chnl_cfg.dl_buf_size; +} + +static void imem_channel_reset (struct iosm_imem *ipc_imem) +{ +int i; + +for (i =0 ; i < ipc_imem->nr_of_channels; i++) { +struct ipc_mem_channel *channel; + + channel = &ipc_imem->channels[i]; + +imem_pipe_cleanup (ipc_imem, &channel->dl_pipe); +imem_pipe_cleanup (ipc_imem, &channel->ul_pipe); + +imem_channel_free (channel); + } +} + +void imem_pipe_cleanup (struct iosm_imem *ipc_imem,struct ipc_pipe *pipe) +{ +struct sk_buff *skb; + +/* Force pipe to closed state also when not explicitly closed through +* imem_pipe_close() +*/ + pipe->is_open = false; + +/* Empty the uplink skb accumulator. */ +while ((skb =skb_dequeue (&pipe->channel->ul_list))) +ipc_pcie_kfree_skb (ipc_imem->pcie, skb); + +ipc_protocol_pipe_cleanup (ipc_imem->ipc_protocol, pipe); +} + +/* Send IPC protocol uninit to the modem when Link is active. */ +static void ipc_imem_device_ipc_uninit (struct iosm_imem *ipc_imem) +{ +int timeout =IPC_MODEM_UNINIT_TIMEOUT_MS ; +enum ipc_mem_device_ipc_state ipc_state; + +/* When PCIe link is up set IPC_UNINIT +* of the modem otherwise ignore it when PCIe link down happens. +*/ +if (ipc_pcie_check_data_link_active (ipc_imem->pcie)) { +/* set modem to UNINIT +* (in case we want to reload the AP driver without resetting +* the modem) +*/ +ipc_doorbell_fire (ipc_imem->pcie,IPC_DOORBELL_IRQ_IPC , +IPC_MEM_DEVICE_IPC_UNINIT ); + ipc_state =ipc_mmio_get_ipc_state (ipc_imem->mmio); + +/* Wait for maximum 30ms to allow the Modem to uninitialize the +* protocol. +*/ +while ((ipc_state <=IPC_MEM_DEVICE_IPC_DONT_CARE ) && + (ipc_state !=IPC_MEM_DEVICE_IPC_UNINIT ) && + (timeout >0 )) { +usleep_range (1000 ,1250 ); + timeout--; + ipc_state =ipc_mmio_get_ipc_state (ipc_imem->mmio); + } + } +} + +void ipc_imem_cleanup (struct iosm_imem *ipc_imem) +{ + ipc_imem->phase =IPC_P_OFF_REQ ; + +/* forward MDM_NOT_READY to listeners */ +ipc_uevent_send (ipc_imem->dev,UEVENT_MDM_NOT_READY ); + +ipc_imem_device_ipc_uninit (ipc_imem); + +hrtimer_cancel (&ipc_imem->td_alloc_timer); + +hrtimer_cancel (&ipc_imem->tdupdate_timer); + +hrtimer_cancel (&ipc_imem->fast_update_timer); + +hrtimer_cancel (&ipc_imem->startup_timer); + +/* cancel the workqueue */ +cancel_work_sync (&ipc_imem->run_state_worker); + +if (test_and_clear_bit (FULLY_FUNCTIONAL , &ipc_imem->flag)) { +ipc_mux_deinit (ipc_imem->mux); +ipc_wwan_deinit (ipc_imem->wwan); + } + +imem_channel_reset (ipc_imem); + +ipc_mbim_deinit (ipc_imem->mbim); + +ipc_protocol_deinit (ipc_imem->ipc_protocol); + +ipc_task_deinit (ipc_imem->ipc_task); + +kfree (ipc_imem->ipc_task); + +kfree (ipc_imem->mmio); + + ipc_imem->phase =IPC_P_OFF ; + + ipc_imem->pcie =NULL ; + ipc_imem->dev =NULL ; +} + +/* After CP has unblocked the PCIe link, save the start address of the doorbell +* scratchpad and prepare the shared memory region. If the flashing to RAM +* procedure shall be executed, copy the chip information from the doorbell +* scratchtpad to the application buffer and wake up the flash app. +*/ +static int ipc_imem_config (struct iosm_imem *ipc_imem) +{ +enum ipc_phase phase; + +/* Initialize the semaphore for the blocking read UL/DL transfer. */ +init_completion (&ipc_imem->ul_pend_sem); + +init_completion (&ipc_imem->dl_pend_sem); + +/* clear internal flags */ + ipc_imem->ipc_status =IPC_MEM_DEVICE_IPC_UNINIT ; + ipc_imem->enter_runtime =0 ; + + phase =imem_ap_phase_update (ipc_imem); + +/* Either CP shall be in the power off or power on phase. */ +switch (phase) { +case IPC_P_ROM : + ipc_imem->hrtimer_period =ktime_set (0 ,1000 *1000 *1000ULL ); +/* poll execution stage (for delayed start, e.g. NAND) */ +if (!hrtimer_active (&ipc_imem->startup_timer)) +hrtimer_start (&ipc_imem->startup_timer, + ipc_imem->hrtimer_period, +HRTIMER_MODE_REL ); +return 0 ; + +case IPC_P_PSI : +case IPC_P_EBL : +case IPC_P_RUN : +/* The initial IPC state is IPC_MEM_DEVICE_IPC_UNINIT. */ + ipc_imem->ipc_requested_state =IPC_MEM_DEVICE_IPC_UNINIT ; + +/* Verify the exepected initial state. */ +if (ipc_imem->ipc_requested_state == +ipc_mmio_get_ipc_state (ipc_imem->mmio)) { +imem_ipc_init_check (ipc_imem); + +return 0 ; + } +dev_err (ipc_imem->dev, +"ipc_status(%d) != IPC_MEM_DEVICE_IPC_UNINIT" , +ipc_mmio_get_ipc_state (ipc_imem->mmio)); +break ; +case IPC_P_CRASH : +case IPC_P_CD_READY : +dev_dbg (ipc_imem->dev, +"Modem is in phase %d, reset Modem to collect CD" , + phase); +return 0 ; +default : +dev_err (ipc_imem->dev,"unexpected operation phase %d" , phase); +break ; + } + +complete (&ipc_imem->dl_pend_sem); +complete (&ipc_imem->ul_pend_sem); + ipc_imem->phase =IPC_P_OFF ; +return -EIO ; +} + +/* Pass the dev ptr to the shared memory driver and request the entry points */ +struct iosm_imem *ipc_imem_init (struct iosm_pcie *pcie,unsigned int device_id, +void __iomem *mmio,struct device *dev) +{ +struct iosm_imem *ipc_imem =kzalloc (sizeof (*pcie->imem),GFP_KERNEL ); + +if (!ipc_imem) +return NULL ; + +/* Save the device address. */ + ipc_imem->pcie = pcie; + ipc_imem->dev = dev; + + ipc_imem->pci_device_id = device_id; + + ipc_imem->ev_cdev_write_pending = false; + ipc_imem->cp_version =0 ; + ipc_imem->device_sleep =IPC_HOST_SLEEP_ENTER_SLEEP ; + +/* Reset the flash channel id. */ + ipc_imem->flash_channel_id =-1 ; + +/* Reset the max number of configured channels */ + ipc_imem->nr_of_channels =0 ; + +/* allocate IPC MMIO */ + ipc_imem->mmio =ipc_mmio_init (mmio, ipc_imem->dev); +if (!ipc_imem->mmio) { +dev_err (ipc_imem->dev,"failed to initialize mmio region" ); + goto mmio_init_fail; + } + + ipc_imem->ipc_task =kzalloc (sizeof (*ipc_imem->ipc_task), +GFP_KERNEL ); + +/* Create tasklet for event handling*/ +if (!ipc_imem->ipc_task) + goto ipc_task_fail; + +if (ipc_task_init (ipc_imem->ipc_task)) + goto ipc_task_init_fail; + + ipc_imem->ipc_task->dev = ipc_imem->dev; + +INIT_WORK (&ipc_imem->run_state_worker, ipc_imem_run_state_worker); + + ipc_imem->ipc_protocol =ipc_protocol_init (ipc_imem); + +if (!ipc_imem->ipc_protocol) + goto protocol_init_fail; + +/* The phase is set to power off. */ + ipc_imem->phase =IPC_P_OFF ; + +hrtimer_init (&ipc_imem->startup_timer,CLOCK_MONOTONIC , +HRTIMER_MODE_REL ); + ipc_imem->startup_timer.function = imem_startup_timer_cb; + +hrtimer_init (&ipc_imem->tdupdate_timer,CLOCK_MONOTONIC , +HRTIMER_MODE_REL ); + ipc_imem->tdupdate_timer.function = imem_td_update_timer_cb; + +hrtimer_init (&ipc_imem->fast_update_timer,CLOCK_MONOTONIC , +HRTIMER_MODE_REL ); + ipc_imem->fast_update_timer.function = imem_fast_update_timer_cb; + +hrtimer_init (&ipc_imem->td_alloc_timer,CLOCK_MONOTONIC , +HRTIMER_MODE_REL ); + ipc_imem->td_alloc_timer.function = imem_td_alloc_timer_cb; + +if (ipc_imem_config (ipc_imem)) { +dev_err (ipc_imem->dev,"failed to initialize the imem" ); + goto imem_config_fail; + } + +return ipc_imem; + +imem_config_fail: +hrtimer_cancel (&ipc_imem->td_alloc_timer); +hrtimer_cancel (&ipc_imem->fast_update_timer); +hrtimer_cancel (&ipc_imem->tdupdate_timer); +hrtimer_cancel (&ipc_imem->startup_timer); +protocol_init_fail: +cancel_work_sync (&ipc_imem->run_state_worker); +ipc_task_deinit (ipc_imem->ipc_task); +ipc_task_init_fail: +kfree (ipc_imem->ipc_task); +ipc_task_fail: +kfree (ipc_imem->mmio); +mmio_init_fail: +kfree (ipc_imem); +return NULL ; +} + +void ipc_imem_irq_process (struct iosm_imem *ipc_imem,int irq) +{ +/* Debounce IPC_EV_IRQ. */ +if (ipc_imem && !ipc_imem->ev_irq_pending[irq]) { + ipc_imem->ev_irq_pending[irq] = true; +ipc_task_queue_send_task (ipc_imem, imem_tq_irq_cb, irq,NULL ,0 , + false); + } +} + +void imem_td_update_timer_suspend (struct iosm_imem *ipc_imem,bool suspend) +{ + ipc_imem->td_update_timer_suspended = suspend; +}
drivers/net/wwan/iosm/iosm_ipc_imem.h new file +582 -0
582 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 5/16 net: iosm: shared memory I/O operations
In reply to M Chetan Kumar1) Binds logical channel between host-device for communication.
2) Implements device specific(Char/Net) IO operations.
---
v2:
* Change vlan_id to ip link if_id & document correction.
* Define new enums for IP & DSS session mapping.
* Return proper error code instead of returning -1.
* Clean-up vlan tag id & removed FW flashing logic.
--- drivers/net/wwan/iosm/iosm_ipc_imem_ops.c | 512 ++++++++++++++++++++++ drivers/net/wwan/iosm/iosm_ipc_imem_ops.h | 135 ++++++ 2 files changed, 647 insertions(+) create mode 100644 drivers/net/wwan/iosm/iosm_ipc_imem_ops.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_imem_ops.h
drivers/net/wwan/iosm/iosm_ipc_imem_ops.c new file +512 -0
@@ -0,0 +1,512 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2020-21 Intel Corporation. +*/ + +#include <linux/delay.h> + +#include "iosm_ipc_chnl_cfg.h" +#include "iosm_ipc_imem.h" +#include "iosm_ipc_imem_ops.h" +#include "iosm_ipc_mbim.h" +#include "iosm_ipc_task_queue.h" + +/* Open a packet data online channel between the network layer and CP. */ +int imem_sys_wwan_open (struct iosm_imem *ipc_imem,int if_id) +{ +dev_dbg (ipc_imem->dev,"%s if id: %d" , +ipc_ap_phase_get_string (ipc_imem->phase), if_id); + +/* The network interface is only supported in the runtime phase. */ +if (imem_ap_phase_update (ipc_imem) !=IPC_P_RUN ) { +dev_err (ipc_imem->dev,"net:%d : refused phase %s" , if_id, +ipc_ap_phase_get_string (ipc_imem->phase)); +return -EIO ; + } + +/* check for the interafce id +* if tag 1 to 8 then create IP MUX channel sessions. +* if tag 257 to 261 then create dss channel. +* To start MUX session from 0 as network interface id would start +* from 1 so map it to if_id = if_id - 1 +*/ +if (if_id >=IP_MUX_SESSION_START && if_id <=IP_MUX_SESSION_END ) { +return ipc_mux_open_session (ipc_imem->mux, if_id -1 ); + }else if (if_id >=DSS_CHANNEL_START && if_id <=DSS_CHANNEL_END ) { +int ch_id = +imem_channel_alloc (ipc_imem, if_id,IPC_CTYPE_WWAN ); + +if (imem_channel_open (ipc_imem, ch_id,IPC_HP_NET_CHANNEL_INIT )) +return ch_id; + } + +return -EINVAL ; +} + +/* Release a net link to CP. */ +void imem_sys_wwan_close (struct iosm_imem *ipc_imem,int if_id, +int channel_id) +{ +if (ipc_imem->mux && if_id >=IP_MUX_SESSION_START && + if_id <=IP_MUX_SESSION_END ) +ipc_mux_close_session (ipc_imem->mux, if_id -1 ); + +else if ((if_id >=DSS_CHANNEL_START && if_id <=DSS_CHANNEL_END )) +imem_channel_close (ipc_imem, channel_id); +} + +/* Tasklet call to do uplink transfer. */ +static int imem_tq_cdev_write (struct iosm_imem *ipc_imem,int arg,void *msg, +size_t size) +{ + ipc_imem->ev_cdev_write_pending = false; +imem_ul_send (ipc_imem); + +return 0 ; +} + +/* Through tasklet to do sio write. */ +static bool imem_call_cdev_write (struct iosm_imem *ipc_imem) +{ +if (ipc_imem->ev_cdev_write_pending) +return false; + + ipc_imem->ev_cdev_write_pending = true; + +return (!ipc_task_queue_send_task (ipc_imem, imem_tq_cdev_write,0 ,NULL , +0 , false)); +} + +/* Add skb to the ul list */ +static int imem_wwan_transmit (struct iosm_imem *ipc_imem, +int channel_id,struct sk_buff *skb) +{ +struct ipc_mem_channel *channel; +int ret = -EIO ; + + channel = &ipc_imem->channels[channel_id]; + +if (channel->state !=IMEM_CHANNEL_ACTIVE ) { +dev_err (ipc_imem->dev,"invalid state of channel %d" , + channel_id); + goto out; + } + + ret =ipc_pcie_addr_map (ipc_imem->pcie, skb->data, skb->len, + &IPC_CB (skb)->mapping,DMA_TO_DEVICE ); +if (ret) { +dev_err (ipc_imem->dev,"failed to map skb" ); +IPC_CB (skb)->direction =DMA_TO_DEVICE ; +IPC_CB (skb)->len = skb->len; +IPC_CB (skb)->op_type =UL_DEFAULT ; + goto out; + } + +/* Add skb to the uplink skbuf accumulator */ +skb_queue_tail (&channel->ul_list, skb); +imem_call_cdev_write (ipc_imem); + + ret =0 ; +out: +return ret; +} + +/* Function for transfer UL data */ +int imem_sys_wwan_transmit (struct iosm_imem *ipc_imem, +int if_id,int channel_id,struct sk_buff *skb) +{ +int ret = -EINVAL ; + +if (!ipc_imem || channel_id <0 ) + goto out; + +/* Is CP Running? */ +if (ipc_imem->phase !=IPC_P_RUN ) { +dev_dbg (ipc_imem->dev,"phase %s transmit" , +ipc_ap_phase_get_string (ipc_imem->phase)); + ret = -EIO ; + goto out; + } + +if (if_id >=IP_MUX_SESSION_START && if_id <=IP_MUX_SESSION_END ) +/* Route the UL packet through IP MUX Layer */ + ret =ipc_mux_ul_trigger_encode (ipc_imem->mux, + if_id -1 , skb); +/* DSS channels */ +else if (if_id >=DSS_CHANNEL_START && if_id <=DSS_CHANNEL_END ) + ret =imem_wwan_transmit (ipc_imem, channel_id, skb); +else +dev_err (ipc_imem->dev, +"invalid if_id %d: " , if_id); +out: +return ret; +} + +void wwan_channel_init (struct iosm_imem *ipc_imem, +enum ipc_mux_protocol mux_type) +{ +struct ipc_chnl_cfg chnl_cfg = {0 }; + + ipc_imem->cp_version =ipc_mmio_get_cp_version (ipc_imem->mmio); + +/* If modem version is invalid (0xffffffff), do not initialize WWAN. */ +if (ipc_imem->cp_version ==-1 ) { +dev_err (ipc_imem->dev,"invalid CP version" ); +return ; + } + +while (ipc_imem->nr_of_channels < (IPC_MEM_MAX_CHANNELS -1 ) && + !ipc_chnl_cfg_get (&chnl_cfg, ipc_imem->nr_of_channels)) { +imem_channel_init (ipc_imem,IPC_CTYPE_WWAN , chnl_cfg, +IRQ_MOD_OFF ); + } +/* WWAN registration. */ + ipc_imem->wwan =ipc_wwan_init (ipc_imem, ipc_imem->dev); +if (!ipc_imem->wwan) +dev_err (ipc_imem->dev, +"failed to register the ipc_wwan interfaces" ); +} + +/* Copies the data from user space */ +static struct sk_buff * +imem_cdev_copy_from_user_to_skb (struct iosm_imem *ipc_imem,int channel_id, +const unsigned char __user *buf,int size, +int is_blocking) +{ +struct sk_buff *skb; +dma_addr_t mapping; + +/* Allocate skb memory for the uplink buffer. */ + skb =ipc_pcie_alloc_skb (ipc_imem->pcie, size,GFP_KERNEL , &mapping, +DMA_TO_DEVICE ,0 ); +if (!skb) +return skb; + +if (copy_from_user (skb_put (skb, size), buf, size)) { +dev_err (ipc_imem->dev,"ch[%d]: copy from user failed" , + channel_id); +ipc_pcie_kfree_skb (ipc_imem->pcie, skb); +return NULL ; + } + +IPC_CB (skb)->op_type = + (u8)(is_blocking ?UL_USR_OP_BLOCKED :UL_DEFAULT ); + +return skb; +} + +/* Get the write active channel */ +static struct ipc_mem_channel * +imem_cdev_get_write_channel (struct iosm_imem *ipc_imem, +struct ipc_mem_channel *channel, +const unsigned char __user *buf,int size) +{ +enum ipc_phase phase; + +if (size <=0 ) { +dev_err (ipc_imem->dev,"invalid buff size" ); +return NULL ; + } + +/* Update the current operation phase. */ + phase = ipc_imem->phase; + +/* Select the operation depending on the execution stage. */ +switch (phase) { +case IPC_P_RUN : +case IPC_P_PSI : +case IPC_P_EBL : +break ; + +case IPC_P_ROM : +/* Prepare the PSI image for the CP ROM driver and +* suspend the flash app. +*/ +if (channel->state !=IMEM_CHANNEL_RESERVED ) { +dev_err (ipc_imem->dev, +"ch[%d]:invalid channel state %d,expected %d" , + channel->channel_id, channel->state, +IMEM_CHANNEL_RESERVED ); +return NULL ; + } +return channel; + +default : +/* Ignore uplink actions in all other phases. */ +dev_err (ipc_imem->dev,"ch[%d]: confused phase %d" , + channel->channel_id, phase); +return NULL ; + } + +/* Check the full availability of the channel. */ +if (channel->state !=IMEM_CHANNEL_ACTIVE ) { +dev_err (ipc_imem->dev,"ch[%d]: confused channel state %d" , + channel->channel_id, channel->state); +return NULL ; + } + +return channel; +} + +/* Release a sio link to CP. */ +void imem_sys_cdev_close (struct iosm_cdev *ipc_cdev) +{ +struct iosm_imem *ipc_imem = ipc_cdev->ipc_imem; +struct ipc_mem_channel *channel = ipc_cdev->channel; +enum ipc_phase curr_phase; +int status =0 ; +u32 tail =0 ; + + curr_phase = ipc_imem->phase; + +/* If current phase is IPC_P_OFF or SIO ID is -ve then +* channel is already freed. Nothing to do. +*/ +if (curr_phase ==IPC_P_OFF ) { +dev_err (ipc_imem->dev, +"nothing to do. Current Phase: %s" , +ipc_ap_phase_get_string (curr_phase)); +return ; + } + +if (channel->state ==IMEM_CHANNEL_FREE ) { +dev_err (ipc_imem->dev,"ch[%d]: invalid channel state %d" , + channel->channel_id, channel->state); +return ; + } + +/* If there are any pending TDs then wait for Timeout/Completion before +* closing pipe. +*/ +if (channel->ul_pipe.old_tail != channel->ul_pipe.old_head) { + ipc_imem->app_notify_ul_pend =1 ; + +/* Suspend the user app and wait a certain time for processing +* UL Data. +*/ + status =wait_for_completion_interruptible_timeout + (&ipc_imem->ul_pend_sem, +msecs_to_jiffies (IPC_PEND_DATA_TIMEOUT )); +if (status ==0 ) { +dev_dbg (ipc_imem->dev, +"Pending data Timeout on UL-Pipe:%d Head:%d Tail:%d" , + channel->ul_pipe.pipe_nr, + channel->ul_pipe.old_head, + channel->ul_pipe.old_tail); + } + + ipc_imem->app_notify_ul_pend =0 ; + } + +/* If there are any pending TDs then wait for Timeout/Completion before +* closing pipe. +*/ +ipc_protocol_get_head_tail_index (ipc_imem->ipc_protocol, + &channel->dl_pipe,NULL , &tail); + +if (tail != channel->dl_pipe.old_tail) { + ipc_imem->app_notify_dl_pend =1 ; + +/* Suspend the user app and wait a certain time for processing +* DL Data. +*/ + status =wait_for_completion_interruptible_timeout + (&ipc_imem->dl_pend_sem, +msecs_to_jiffies (IPC_PEND_DATA_TIMEOUT )); +if (status ==0 ) { +dev_dbg (ipc_imem->dev, +"Pending data Timeout on DL-Pipe:%d Head:%d Tail:%d" , + channel->dl_pipe.pipe_nr, + channel->dl_pipe.old_head, + channel->dl_pipe.old_tail); + } + + ipc_imem->app_notify_dl_pend =0 ; + } + +/* Due to wait for completion in messages, there is a small window +* between closing the pipe and updating the channel is closed. In this +* small window there could be HP update from Host Driver. Hence update +* the channel state as CLOSING to aviod unnecessary interrupt +* towards CP. +*/ + channel->state =IMEM_CHANNEL_CLOSING ; + +imem_pipe_close (ipc_imem, &channel->ul_pipe); +imem_pipe_close (ipc_imem, &channel->dl_pipe); + +imem_channel_free (channel); + +if (channel->channel_id !=IPC_MEM_MBIM_CTRL_CH_ID ) +/* Reset the global flash channel id. */ + ipc_imem->flash_channel_id =-1 ; +} + +/* Open a MBIM link to CP and return the channel */ +struct ipc_mem_channel *imem_sys_mbim_open (struct iosm_imem *ipc_imem) +{ +int ch_id; +struct ipc_mem_channel *channel; + +/* The MBIM interface is only supported in the runtime phase. */ +if (imem_ap_phase_update (ipc_imem) !=IPC_P_RUN ) { +dev_err (ipc_imem->dev,"MBIM open refused, phase %s" , +ipc_ap_phase_get_string (ipc_imem->phase)); +return NULL ; + } + + ch_id =imem_channel_alloc (ipc_imem,IPC_MEM_MBIM_CTRL_CH_ID , +IPC_CTYPE_MBIM ); + +if (ch_id <0 ) { +dev_err (ipc_imem->dev,"reservation of an MBIM chnl id failed" ); +return NULL ; + } + + channel =imem_channel_open (ipc_imem, ch_id,IPC_HP_CDEV_OPEN ); + +if (!channel) { +dev_err (ipc_imem->dev,"MBIM channel id open failed" ); +return NULL ; + } + +return channel; +} + +ssize_t imem_sys_cdev_read (struct iosm_cdev *ipc_cdev,unsigned char __user *buf, +size_t size,struct sk_buff *skb) +{ +unsigned char __user *dest_buf, *dest_end; +size_t dest_len, src_len, copied_b =0 ; +unsigned char *src_buf; + +/* Prepare the destination space. */ + dest_buf = buf; + dest_end = dest_buf + size; + +/* Copy the accumulated rx packets. */ +while (skb) { +/* Prepare the source elements. */ + src_buf = skb->data; + src_len = skb->len; + +/* Calculate the current size of the destination buffer. */ + dest_len = dest_end - dest_buf; + +/* Compute the number of bytes to copy. */ + copied_b = (dest_len < src_len) ? dest_len : src_len; + +/* Copy the chars into the user space buffer. */ +if (copy_to_user ((void __user *)dest_buf, src_buf, copied_b) != +0 ) { +dev_err (ipc_cdev->dev, +"chid[%d] userspace copy failed n=%zu\n" , + ipc_cdev->channel->channel_id, copied_b); +ipc_pcie_kfree_skb (ipc_cdev->pcie, skb); +return -EFAULT ; + } + +/* Update the source elements. */ + skb->data = src_buf + copied_b; + skb->len = skb->len - copied_b; + +/* Update the desctination pointer. */ + dest_buf += copied_b; + +/* Test the fill level of the user buffer. */ +if (dest_buf >= dest_end) { +/* Free the consumed skbuf or save the pending skbuf +* to consume it in the read call. +*/ +if (skb->len ==0 ) +ipc_pcie_kfree_skb (ipc_cdev->pcie, skb); +else + ipc_cdev->rx_pending_buf = skb; + +/* Return the number of saved chars. */ +break ; + } + +/* Free the consumed skbuf. */ +ipc_pcie_kfree_skb (ipc_cdev->pcie, skb); + +/* Get the next skbuf element. */ + skb =skb_dequeue (&ipc_cdev->rx_list); + } + +/* Return the number of saved chars. */ + copied_b = dest_buf - buf; +return copied_b; +} + +int imem_sys_cdev_write (struct iosm_cdev *ipc_cdev, +const unsigned char __user *buf,int count, +bool blocking_write) +{ +struct iosm_imem *ipc_imem = ipc_cdev->ipc_imem; +struct ipc_mem_channel *channel = ipc_cdev->channel; +struct sk_buff *skb; +int ret = -EIO ; + +/* Complete all memory stores before setting bit */ +smp_mb__before_atomic (); + +set_bit (WRITE_IN_USE , &ipc_cdev->flag); + +/* Complete all memory stores after setting bit */ +smp_mb__after_atomic (); + + channel =imem_cdev_get_write_channel (ipc_imem, channel, buf, count); + +if (!channel || ipc_imem->phase ==IPC_P_OFF_REQ ) + goto out; + +/* Allocate skb memory for the uplink buffer.*/ + skb =imem_cdev_copy_from_user_to_skb (ipc_imem, channel->channel_id, buf, + count, blocking_write); +if (!skb) { + ret = -ENOMEM ; + goto out; + } + +/* Add skb to the uplink skbuf accumulator. */ +skb_queue_tail (&channel->ul_list, skb); + +/* Inform the IPC tasklet to pass uplink IP packets to CP. +* Blocking write waits for UL completion notification, +* non-blocking write simply returns the count. +*/ +if (imem_call_cdev_write (ipc_imem) && blocking_write) { +/* Suspend the app and wait for UL data completion. */ + ret =wait_for_completion_interruptible (&channel->ul_sem); + +if (ret <0 ) { +dev_err (ipc_imem->dev, +"ch[%d] no CP confirmation, status=%d" , + channel->channel_id, ret); + goto out; + } + } + ret = count; +out: +/* Complete all memory stores before clearing bit. */ +smp_mb__before_atomic (); + +clear_bit (WRITE_IN_USE , &ipc_cdev->flag); + +/* Complete all memory stores after clearing bit. */ +smp_mb__after_atomic (); +return ret; +} + +int imem_sys_cdev_receive (struct iosm_cdev *ipc_cdev,struct sk_buff *skb) +{ +skb_queue_tail ((&ipc_cdev->rx_list), skb); + +if (test_bit (IS_BLOCKING , &ipc_cdev->flag)) +complete (&ipc_cdev->read_sem); +else if (!test_bit (IS_BLOCKING , &ipc_cdev->flag)) +wake_up_interruptible (&ipc_cdev->poll_inq); + +return 0 ; +}
drivers/net/wwan/iosm/iosm_ipc_imem_ops.h new file +135 -0
135 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 6/16 net: iosm: channel configuration
In reply to M Chetan KumarDefines pipes & channel configurations like channel type, pipe mappings, No. of transfer descriptors and transfer buffer size etc.
---
v2:
* Return proper error code instead of returning -1.
* Define IPC channels in serial order.
--- drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c | 82 +++++++++++++++++++++++ drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.h | 55 +++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.h
drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c new file +82 -0
@@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2020-21 Intel Corporation. +*/ + +#include "iosm_ipc_chnl_cfg.h" + +/* Max. sizes of a downlink buffers */ +#define IPC_MEM_MAX_DL_FLASH_BUF_SIZE (16 * 1024) +#define IPC_MEM_MAX_DL_LOOPBACK_SIZE (1 * 1024 * 1024) +#define IPC_MEM_MAX_DL_AT_BUF_SIZE 2048 +#define IPC_MEM_MAX_DL_RPC_BUF_SIZE (32 * 1024) +#define IPC_MEM_MAX_DL_MBIM_BUF_SIZE IPC_MEM_MAX_DL_RPC_BUF_SIZE + +/* Max. transfer descriptors for a pipe. */ +#define IPC_MEM_MAX_TDS_FLASH_DL 3 +#define IPC_MEM_MAX_TDS_FLASH_UL 6 +#define IPC_MEM_MAX_TDS_AT 4 +#define IPC_MEM_MAX_TDS_RPC 4 +#define IPC_MEM_MAX_TDS_MBIM IPC_MEM_MAX_TDS_RPC +#define IPC_MEM_MAX_TDS_LOOPBACK 11 + +/* Accumulation backoff usec */ +#define IRQ_ACC_BACKOFF_OFF 0 + +/* MUX acc backoff 1ms */ +#define IRQ_ACC_BACKOFF_MUX 1000 + +/* Modem channel configuration table +* Always reserve element zero for flash channel. +*/ +static struct ipc_chnl_cfg modem_cfg[] = { +/* IP Mux */ + {IPC_MEM_MUX_IP_CH_IF_ID ,IPC_MEM_PIPE_0 ,IPC_MEM_PIPE_1 , +IPC_MEM_MAX_TDS_MUX_LITE_UL ,IPC_MEM_MAX_TDS_MUX_LITE_DL , +IPC_MEM_MAX_DL_MUX_LITE_BUF_SIZE }, +/* RPC - 0 */ + {IPC_WWAN_DSS_ID_0 ,IPC_MEM_PIPE_2 ,IPC_MEM_PIPE_3 , +IPC_MEM_MAX_TDS_RPC ,IPC_MEM_MAX_TDS_RPC , +IPC_MEM_MAX_DL_RPC_BUF_SIZE }, +/* IAT0 */ + {IPC_WWAN_DSS_ID_1 ,IPC_MEM_PIPE_4 ,IPC_MEM_PIPE_5 ,IPC_MEM_MAX_TDS_AT , +IPC_MEM_MAX_TDS_AT ,IPC_MEM_MAX_DL_AT_BUF_SIZE }, +/* Trace */ + {IPC_WWAN_DSS_ID_2 ,IPC_MEM_PIPE_6 ,IPC_MEM_PIPE_7 ,IPC_MEM_TDS_TRC , +IPC_MEM_TDS_TRC ,IPC_MEM_MAX_DL_TRC_BUF_SIZE }, +/* IAT1 */ + {IPC_WWAN_DSS_ID_3 ,IPC_MEM_PIPE_8 ,IPC_MEM_PIPE_9 ,IPC_MEM_MAX_TDS_AT , +IPC_MEM_MAX_TDS_AT ,IPC_MEM_MAX_DL_AT_BUF_SIZE }, +/* Loopback */ + {IPC_WWAN_DSS_ID_4 ,IPC_MEM_PIPE_10 ,IPC_MEM_PIPE_11 , +IPC_MEM_MAX_TDS_LOOPBACK ,IPC_MEM_MAX_TDS_LOOPBACK , +IPC_MEM_MAX_DL_LOOPBACK_SIZE }, +/* MBIM Channel */ + {IPC_MEM_MBIM_CTRL_CH_ID ,IPC_MEM_PIPE_12 ,IPC_MEM_PIPE_13 , +IPC_MEM_MAX_TDS_MBIM ,IPC_MEM_MAX_TDS_MBIM , +IPC_MEM_MAX_DL_MBIM_BUF_SIZE }, +}; + +int ipc_chnl_cfg_get (struct ipc_chnl_cfg *chnl_cfg,int index) +{ +int array_size =ARRAY_SIZE (modem_cfg); + +if (index >= array_size) { +pr_err ("index: %d and array_size %d" , index, array_size); +return -ECHRNG ; + } + +if (index ==IPC_MEM_MUX_IP_CH_IF_ID ) + chnl_cfg->accumulation_backoff =IRQ_ACC_BACKOFF_MUX ; +else + chnl_cfg->accumulation_backoff =IRQ_ACC_BACKOFF_OFF ; + + chnl_cfg->ul_nr_of_entries = modem_cfg[index].ul_nr_of_entries; + chnl_cfg->dl_nr_of_entries = modem_cfg[index].dl_nr_of_entries; + chnl_cfg->dl_buf_size = modem_cfg[index].dl_buf_size; + chnl_cfg->id = modem_cfg[index].id; + chnl_cfg->ul_pipe = modem_cfg[index].ul_pipe; + chnl_cfg->dl_pipe = modem_cfg[index].dl_pipe; + +return 0 ; +}
drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.h new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 7/16 net: iosm: mbim control device
In reply to M Chetan KumarImplements a char device for MBIM protocol communication & provides a simple IOCTL for max transfer buffer size configuration.
---
v2:
* Renamed iosm_sio struct to iosm_cdev.
* Added memory barriers around atomic operations.
--- drivers/net/wwan/iosm/iosm_ipc_mbim.c | 306 ++++++++++++++++++++++++++ drivers/net/wwan/iosm/iosm_ipc_mbim.h | 78 +++++++ 2 files changed, 384 insertions(+) create mode 100644 drivers/net/wwan/iosm/iosm_ipc_mbim.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_mbim.h
drivers/net/wwan/iosm/iosm_ipc_mbim.c new file +306 -0
@@ -0,0 +1,306 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2020-21 Intel Corporation. +*/ + +#include <linux/poll.h> +#include <linux/skbuff.h> +#include <linux/uaccess.h> + +#include "iosm_ipc_imem_ops.h" +#include "iosm_ipc_mbim.h" + +#define IOCTL_WDM_MAX_COMMAND _IOR('H', 0xA0, __u16) +#define WDM_MAX_SIZE 4096 + +static struct mutex mbim_flock;/* Mutex Lock for mbim read */ +static struct mutex mbim_flock_wr;/* Mutex Lock for mbim write */ + +/* MBIM IOCTL for configuring max MBIM packet size. */ +static long ipc_mbim_fop_unlocked_ioctl (struct file *filp,unsigned int cmd, +unsigned long arg) +{ +struct iosm_cdev *ipc_mbim = + container_of(filp->private_data, struct iosm_cdev, misc); + +if (cmd !=IOCTL_WDM_MAX_COMMAND || + !access_ok ((void __user *)arg,sizeof (ipc_mbim->wmaxcommand))) +return -EINVAL ; + +if (copy_to_user ((void __user *)arg, &ipc_mbim->wmaxcommand, +sizeof (ipc_mbim->wmaxcommand))) +return -EFAULT ; + +return 0 ; +} + +/* Open a shared memory device and initialize the head of the rx skbuf list. */ +static int ipc_mbim_fop_open (struct inode *inode,struct file *filp) +{ +struct iosm_cdev *ipc_mbim = + container_of(filp->private_data, struct iosm_cdev, misc); + +struct iosm_cdev_open_file *mbim_op =kzalloc (sizeof (*mbim_op), +GFP_KERNEL ); +if (!mbim_op) +return -ENOMEM ; + +if (test_and_set_bit (IS_OPEN , &ipc_mbim->flag)) { +kfree (mbim_op); +return -EBUSY ; + } + + ipc_mbim->channel =imem_sys_mbim_open (ipc_mbim->ipc_imem); + +if (!ipc_mbim->channel) { +kfree (mbim_op); +return -EIO ; + } + +mutex_lock (&mbim_flock); + + inode->i_private = mbim_op; + ipc_mbim->cdev_fop = mbim_op; + mbim_op->ipc_cdev = ipc_mbim; + +mutex_unlock (&mbim_flock); +return 0 ; +} + +/* Close a shared memory control device and free the rx skbuf list. */ +static int ipc_mbim_fop_release (struct inode *inode,struct file *filp) +{ +struct iosm_cdev_open_file *mbim_op = inode->i_private; + +mutex_lock (&mbim_flock); +if (mbim_op->ipc_cdev) { +/* Complete all memory stores before clearing bit. */ +smp_mb__before_atomic (); + +clear_bit (IS_OPEN , &mbim_op->ipc_cdev->flag); + +/* Complete all memory stores after clearing bit. */ +smp_mb__after_atomic (); + +imem_sys_cdev_close (mbim_op->ipc_cdev); + mbim_op->ipc_cdev->cdev_fop =NULL ; + } +kfree (mbim_op); +mutex_unlock (&mbim_flock); +return 0 ; +} + +/* Copy the data from skbuff to the user buffer */ +static ssize_t ipc_mbim_fop_read (struct file *filp,char __user *buf, +size_t size,loff_t *l) +{ +struct iosm_cdev_open_file *mbim_op = filp->f_inode->i_private; +struct sk_buff *skb =NULL ; +struct iosm_cdev *ipc_mbim; +ssize_t read_byt; +int ret_err; + +if (!access_ok (buf, size)) { + ret_err = -EINVAL ; + goto err; + } + +mutex_lock (&mbim_flock); + +if (!mbim_op->ipc_cdev) { + ret_err = -EIO ; + goto err_free_lock; + } + + ipc_mbim = mbim_op->ipc_cdev; + +if (!(filp->f_flags &O_NONBLOCK )) { +/* Complete all memory stores before setting bit */ +smp_mb__before_atomic (); + +set_bit (IS_BLOCKING , &ipc_mbim->flag); + +/* Complete all memory stores after setting bit */ +smp_mb__after_atomic (); + } + +/* First provide the pending skbuf to the user. */ +if (ipc_mbim->rx_pending_buf) { + skb = ipc_mbim->rx_pending_buf; + ipc_mbim->rx_pending_buf =NULL ; + } + +/* Check rx queue until skb is available */ +while (!skb && !(skb =skb_dequeue (&ipc_mbim->rx_list))) { +if (!test_bit (IS_BLOCKING , &ipc_mbim->flag)) { + ret_err = -EAGAIN ; + goto err_free_lock; + } + +/* Suspend the user app and wait a certain time for data +* from CP. +*/ +if (!wait_for_completion_interruptible_timeout + (&ipc_mbim->read_sem,msecs_to_jiffies (IPC_READ_TIMEOUT ))) { +dev_err (ipc_mbim->dev,"Read timedout" ); + ret_err = -ETIMEDOUT ; + goto err_free_lock; + } + +if (test_bit (IS_DEINIT , &ipc_mbim->flag)) { + ret_err = -EPERM ; + goto err_free_lock; + } + } + + read_byt =imem_sys_cdev_read (ipc_mbim, buf, size, skb); +mutex_unlock (&mbim_flock); +return read_byt; + +err_free_lock: +mutex_unlock (&mbim_flock); +err: +return ret_err; +} + +/* Route the user data to the shared memory layer. */ +static ssize_t ipc_mbim_fop_write (struct file *filp,const char __user *buf, +size_t size,loff_t *l) +{ +struct iosm_cdev_open_file *mbim_op = filp->f_inode->i_private; +struct iosm_cdev *ipc_mbim; +bool is_blocking; +ssize_t write_byt; +int ret_err; + +if (!access_ok (buf, size)) { + ret_err = -EINVAL ; + goto err; + } + +mutex_lock (&mbim_flock_wr); + +if (!mbim_op->ipc_cdev) { + ret_err = -EIO ; + goto err_free_lock; + } + + ipc_mbim = mbim_op->ipc_cdev; + + is_blocking = !(filp->f_flags &O_NONBLOCK ); + +if (test_bit (WRITE_IN_USE , &ipc_mbim->flag)) { + ret_err = -EAGAIN ; + goto err_free_lock; + } + write_byt =imem_sys_cdev_write (ipc_mbim, buf, size, is_blocking); + +mutex_unlock (&mbim_flock_wr); +return write_byt; + +err_free_lock: +mutex_unlock (&mbim_flock_wr); +err: +return ret_err; +} + +/* Poll mechanism for applications that use nonblocking IO */ +static __poll_t ipc_mbim_fop_poll (struct file *filp,poll_table *wait) +{ +struct iosm_cdev *ipc_mbim = + container_of(filp->private_data, struct iosm_cdev, misc); +__poll_t mask =0 ; + +/* Just registers wait_queue hook. This doesn't really wait. */ +poll_wait (filp, &ipc_mbim->poll_inq, wait); + +/* Test the fill level of the skbuf rx queue. */ +if (!test_bit (WRITE_IN_USE , &ipc_mbim->flag)) + mask |=EPOLLOUT |EPOLLWRNORM ;/* writable */ + +if (!skb_queue_empty (&ipc_mbim->rx_list) || ipc_mbim->rx_pending_buf) + mask |=EPOLLIN |EPOLLRDNORM ;/* readable */ + +return mask; +} + +struct iosm_cdev *ipc_mbim_init (struct iosm_imem *ipc_imem,const char *name) +{ +struct iosm_cdev *ipc_mbim =kzalloc (sizeof (*ipc_mbim),GFP_KERNEL ); + +static const struct file_operations fops = { + .owner =THIS_MODULE , + .open = ipc_mbim_fop_open, + .release = ipc_mbim_fop_release, + .read = ipc_mbim_fop_read, + .write = ipc_mbim_fop_write, + .poll = ipc_mbim_fop_poll, + .unlocked_ioctl = ipc_mbim_fop_unlocked_ioctl, + }; + +if (!ipc_mbim) +return NULL ; + + ipc_mbim->dev = ipc_imem->dev; + ipc_mbim->pcie = ipc_imem->pcie; + ipc_mbim->ipc_imem = ipc_imem; + + ipc_mbim->wmaxcommand =WDM_MAX_SIZE ; + +mutex_init (&mbim_flock); +mutex_init (&mbim_flock_wr); +init_completion (&ipc_mbim->read_sem); + +skb_queue_head_init (&ipc_mbim->rx_list); +init_waitqueue_head (&ipc_mbim->poll_inq); + +strncpy (ipc_mbim->devname, name,sizeof (ipc_mbim->devname) -1 ); + ipc_mbim->devname[IPC_CDEV_NAME_LEN -1 ] ='\0' ; + + ipc_mbim->misc.minor =MISC_DYNAMIC_MINOR ; + ipc_mbim->misc.name = ipc_mbim->devname; + ipc_mbim->misc.fops = &fops; + ipc_mbim->misc.mode =IPC_CHAR_DEVICE_DEFAULT_MODE ; + +if (misc_register (&ipc_mbim->misc)) { +kfree (ipc_mbim); +return NULL ; + } + +dev_set_drvdata (ipc_mbim->misc.this_device, ipc_mbim); + +return ipc_mbim; +} + +void ipc_mbim_deinit (struct iosm_cdev *ipc_mbim) +{ +misc_deregister (&ipc_mbim->misc); + +/* Complete all memory stores before setting bit */ +smp_mb__before_atomic (); + +set_bit (IS_DEINIT , &ipc_mbim->flag); + +/* Complete all memory stores after setting bit */ +smp_mb__after_atomic (); + +if (test_bit (IS_BLOCKING , &ipc_mbim->flag)) { +complete (&ipc_mbim->read_sem); +complete (&ipc_mbim->channel->ul_sem); + } + +mutex_lock (&mbim_flock); +mutex_lock (&mbim_flock_wr); + +ipc_pcie_kfree_skb (ipc_mbim->pcie, ipc_mbim->rx_pending_buf); + ipc_mbim->rx_pending_buf =NULL ; +skb_queue_purge (&ipc_mbim->rx_list); + +if (ipc_mbim->cdev_fop) + ipc_mbim->cdev_fop->ipc_cdev =NULL ; + +mutex_unlock (&mbim_flock_wr); +mutex_unlock (&mbim_flock); + +kfree (ipc_mbim); +}
drivers/net/wwan/iosm/iosm_ipc_mbim.h new file +78 -0
78 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH V2 07/16] net: iosm: mbim control device
Hi Chetan,
Quoted 6 lines · M Chetan Kumar
Implements a char device for MBIM protocol communication & provides a simple IOCTL for max transfer buffer size configuration.
Signed-off-by M Chetan Kumar <[email protected]>
Now that the initial wwan framework support landed, could you migrate to it for creating the MBIM 'WWAN port' instead of creating yet another char driver? I see you introduced an IOCTL for packet size, I see no objection to add that in the wwan core.
Regards,
Loic
RE: [PATCH V2 07/16] net: iosm: mbim control device
Hi Loic,
Quoted 11 lines
Quoted 5 lines
Implements a char device for MBIM protocol communication & provides a simple IOCTL for max transfer buffer size configuration.
Signed-off-by M Chetan Kumar <[email protected]>Now that the initial wwan framework support landed, could you migrate to it for creating the MBIM 'WWAN port' instead of creating yet another char driver? I see you introduced an IOCTL for packet size, I see no objection to add that in the wwan core.
Sure, we have started the migration to MBIM 'WWAN port'. The next version of patch would contain these adaptations.
If wwan core supports IOCTL for packet size, then we shall remove that piece of implementation in driver code.
Regards
Chetan
Re: [PATCH V2 07/16] net: iosm: mbim control device
Quoted 18 lines · M Chetan
Hi Loic,
Quoted 7 lines
Quoted 6 lines
Implements a char device for MBIM protocol communication & provides a
simple IOCTL for max transfer buffer size configuration.Signed-off-by M Chetan Kumar <[email protected]>Quoted 8 lines
Now that the initial wwan framework support landed, could you migrate to it
for creating the MBIM 'WWAN port' instead of creating yet another char
driver? I see you introduced an IOCTL for packet size, I see no objection to
add that in the wwan core.
Quoted 7 lines
Sure, we have started the migration to MBIM 'WWAN port'. The next version of patch
would contain these adaptations.If wwan core supports IOCTL for packet size, then we shall remove that piece of
implementation in driver code.
There has got to be a better way to do that than an ioctl. ioctls are not looked on favorably these days. Usually it's sysfs files or netlink config instead.
Dan
PATCH v2 8/16 net: iosm: bottom half
In reply to M Chetan Kumar1) Bottom half(tasklet) for IRQ and task processing.
2) Tasks are processed asynchronous and synchronously.
---
v2:
* Moved task queue struct to header file.
* Streamline multiple returns using goto.
--- drivers/net/wwan/iosm/iosm_ipc_task_queue.c | 202 ++++++++++++++++++++ drivers/net/wwan/iosm/iosm_ipc_task_queue.h | 97 ++++++++++ 2 files changed, 299 insertions(+) create mode 100644 drivers/net/wwan/iosm/iosm_ipc_task_queue.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_task_queue.h
drivers/net/wwan/iosm/iosm_ipc_task_queue.c new file +202 -0
@@ -0,0 +1,202 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2020-21 Intel Corporation. +*/ + +#include "iosm_ipc_imem.h" +#include "iosm_ipc_task_queue.h" + +/* Actual tasklet function, will be called whenever tasklet is scheduled. +* Calls event handler involves callback for each element in the message queue +*/ +static void ipc_task_queue_handler (unsigned long data) +{ +struct ipc_task_queue *ipc_task = (struct ipc_task_queue *)data; +unsigned int q_rpos = ipc_task->q_rpos; + +/* Loop over the input queue contents. */ +while (q_rpos != ipc_task->q_wpos) { +/* Get the current first queue element. */ +struct ipc_task_queue_args *args = &ipc_task->args[q_rpos]; + +/* Process the input message. */ +if (args->func) + args->response = args->func (args->ipc_imem, args->arg, + args->msg, args->size); + +/* Signal completion for synchronous calls */ +if (args->completion) +complete (args->completion); + +/* Free message if copy was allocated. */ +if (args->is_copy) +kfree (args->msg); + +/* Set invalid queue element. Technically +* spin_lock_irqsave is not required here as +* the array element has been processed already +* so we can assume that immediately after processing +* ipc_task element, queue will not rotate again to +* ipc_task same element within such short time. +*/ + args->completion =NULL ; + args->func =NULL ; + args->msg =NULL ; + args->size =0 ; + args->is_copy = false; + +/* calculate the new read ptr and update the volatile read +* ptr +*/ + q_rpos = (q_rpos +1 ) %IPC_THREAD_QUEUE_SIZE ; + ipc_task->q_rpos = q_rpos; + } +} + +/* Free memory alloc and trigger completions left in the queue during dealloc */ +static void ipc_task_queue_cleanup (struct ipc_task_queue *ipc_task) +{ +unsigned int q_rpos = ipc_task->q_rpos; + +while (q_rpos != ipc_task->q_wpos) { +struct ipc_task_queue_args *args = &ipc_task->args[q_rpos]; + +if (args->completion) +complete (args->completion); + +if (args->is_copy) +kfree (args->msg); + + q_rpos = (q_rpos +1 ) %IPC_THREAD_QUEUE_SIZE ; + ipc_task->q_rpos = q_rpos; + } +} + +/* Add a message to the queue and trigger the ipc_task. */ +static int +ipc_task_queue_add_task (struct iosm_imem *ipc_imem, +int arg,void *msg, +int (*func)(struct iosm_imem *ipc_imem,int arg, +void *msg,size_t size), +size_t size,bool is_copy,bool wait) +{ +struct tasklet_struct *ipc_tasklet = ipc_imem->ipc_task->ipc_tasklet; +struct ipc_task_queue *ipc_task = &ipc_imem->ipc_task->ipc_queue; +struct completion completion; +unsigned int pos, nextpos; +unsigned long flags; +int result = -EIO ; + +init_completion (&completion); + +/* tasklet send may be called from both interrupt or thread +* context, therefore protect queue operation by spinlock +*/ +spin_lock_irqsave (&ipc_task->q_lock, flags); + + pos = ipc_task->q_wpos; + nextpos = (pos +1 ) %IPC_THREAD_QUEUE_SIZE ; + +/* Get next queue position. */ +if (nextpos != ipc_task->q_rpos) { +/* Get the reference to the queue element and save the passed +* values. +*/ + ipc_task->args[pos].arg = arg; + ipc_task->args[pos].msg = msg; + ipc_task->args[pos].func = func; + ipc_task->args[pos].ipc_imem = ipc_imem; + ipc_task->args[pos].size = size; + ipc_task->args[pos].is_copy = is_copy; + ipc_task->args[pos].completion = wait ? &completion :NULL ; + ipc_task->args[pos].response =-1 ; + +/* apply write barrier so that ipc_task->q_rpos elements +* are updated before ipc_task->q_wpos is being updated. +*/ +smp_wmb (); + +/* Update the status of the free queue space. */ + ipc_task->q_wpos = nextpos; + result =0 ; + } + +spin_unlock_irqrestore (&ipc_task->q_lock, flags); + +if (result ==0 ) { +tasklet_schedule (ipc_tasklet); + +if (wait) { +wait_for_completion (&completion); + result = ipc_task->args[pos].response; + } + }else { +dev_err (ipc_imem->ipc_task->dev,"queue is full" ); + } + +return result; +} + +int ipc_task_queue_send_task (struct iosm_imem *imem, +int (*func)(struct iosm_imem *ipc_imem,int arg, +void *msg,size_t size), +int arg,void *msg,size_t size,bool wait) +{ +bool is_copy = false; +void *copy = msg; +int ret = -ENOMEM ; + +if (size >0 ) { + copy =kmemdup (msg, size,GFP_ATOMIC ); +if (!copy) + goto out; + + is_copy = true; + } + + ret =ipc_task_queue_add_task (imem, arg, copy, func, + size, is_copy, wait); +if (ret <0 ) { +dev_err (imem->ipc_task->dev, +"add task failed for %ps %d, %p, %zu, %d" , func, arg, + copy, size, is_copy); +if (is_copy) +kfree (copy); + goto out; + } + + ret =0 ; +out: +return ret; +} + +int ipc_task_init (struct ipc_task *ipc_task) +{ +struct ipc_task_queue *ipc_queue = &ipc_task->ipc_queue; + + ipc_task->ipc_tasklet =kzalloc (sizeof (*ipc_task->ipc_tasklet), +GFP_KERNEL ); + +if (!ipc_task->ipc_tasklet) +return -ENOMEM ; + +/* Initialize the spinlock needed to protect the message queue of the +* ipc_task +*/ +spin_lock_init (&ipc_queue->q_lock); + +tasklet_init (ipc_task->ipc_tasklet, ipc_task_queue_handler, + (unsigned long )ipc_queue); +return 0 ; +} + +void ipc_task_deinit (struct ipc_task *ipc_task) +{ +tasklet_kill (ipc_task->ipc_tasklet); + +kfree (ipc_task->ipc_tasklet); +/* This will free/complete any outstanding messages, +* without calling the actual handler +*/ +ipc_task_queue_cleanup (&ipc_task->ipc_queue); +}
drivers/net/wwan/iosm/iosm_ipc_task_queue.h new file +97 -0
97 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 9/16 net: iosm: multiplex IP sessions
In reply to M Chetan KumarEstablish IP session between host-device & session management.
---
v2:
* Endianness type correction for Host-Device protocol structure.
* Removed space around the : for the bitfields.
* Change session from dynamic to static.
* Streamline multiple returns using goto.
--- drivers/net/wwan/iosm/iosm_ipc_mux.c | 454 +++++++++++++++++++++++++++ drivers/net/wwan/iosm/iosm_ipc_mux.h | 343 ++++++++++++++++++++ 2 files changed, 797 insertions(+) create mode 100644 drivers/net/wwan/iosm/iosm_ipc_mux.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_mux.h
drivers/net/wwan/iosm/iosm_ipc_mux.c new file +454 -0
@@ -0,0 +1,454 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2020-21 Intel Corporation. +*/ + +#include "iosm_ipc_mux_codec.h" + +/* At the begin of the runtime phase the IP MUX channel shall created. */ +static int mux_channel_create (struct iosm_mux *ipc_mux) +{ +int channel_id; + + channel_id =imem_channel_alloc (ipc_mux->imem, ipc_mux->instance_id, +IPC_CTYPE_WWAN ); + +if (channel_id <0 ) { +dev_err (ipc_mux->dev, +"allocation of the MUX channel id failed" ); + ipc_mux->state =MUX_S_ERROR ; + ipc_mux->event =MUX_E_NOT_APPLICABLE ; + goto no_channel; + } + +/* Establish the MUX channel in blocking mode. */ + ipc_mux->channel =imem_channel_open (ipc_mux->imem, channel_id, +IPC_HP_NET_CHANNEL_INIT ); + +if (!ipc_mux->channel) { +dev_err (ipc_mux->dev,"imem_channel_open failed" ); + ipc_mux->state =MUX_S_ERROR ; + ipc_mux->event =MUX_E_NOT_APPLICABLE ; +return -ENODEV ;/* MUX channel is not available. */ + } + +/* Define the MUX active state properties. */ + ipc_mux->state =MUX_S_ACTIVE ; + ipc_mux->event =MUX_E_NO_ORDERS ; + +no_channel: +return channel_id; +} + +/* Reset the session/if id state. */ +static void mux_session_free (struct iosm_mux *ipc_mux,int if_id) +{ +struct mux_session *if_entry; + + if_entry = &ipc_mux->session[if_id]; +/* Reset the session state. */ + if_entry->wwan =NULL ; +} + +/* Create and send the session open command. */ +static struct mux_cmd_open_session_resp * +mux_session_open_send (struct iosm_mux *ipc_mux,int if_id) +{ +struct mux_cmd_open_session_resp *open_session_resp; +struct mux_acb *acb = &ipc_mux->acb; +union mux_cmd_param param; + +/* open_session commands to one ACB and start transmission. */ + param.open_session.flow_ctrl =0 ; + param.open_session.ipv4v6_hints =0 ; + param.open_session.reserved2 =0 ; + param.open_session.dl_head_pad_len =cpu_to_le32 (IPC_MEM_DL_ETH_OFFSET ); + +/* Finish and transfer ACB. The user thread is suspended. +* It is a blocking function call, until CP responds or timeout. +*/ + acb->wanted_response =MUX_CMD_OPEN_SESSION_RESP ; +if (mux_dl_acb_send_cmds (ipc_mux,MUX_CMD_OPEN_SESSION , if_id,0 , + ¶m,sizeof (param.open_session), true, + false) || + acb->got_response !=MUX_CMD_OPEN_SESSION_RESP ) { +dev_err (ipc_mux->dev,"if_id %d: OPEN_SESSION send failed" , + if_id); +return NULL ; + } + + open_session_resp = &ipc_mux->acb.got_param.open_session_resp; +if (open_session_resp->response !=cpu_to_le32 (MUX_CMD_RESP_SUCCESS )) { +dev_err (ipc_mux->dev, +"if_id %d,session open failed,response=%d" , if_id, + open_session_resp->response); +return NULL ; + } + +return open_session_resp; +} + +/* Open the first IP session. */ +static bool mux_session_open (struct iosm_mux *ipc_mux, +struct mux_session_open *session_open) +{ +struct mux_cmd_open_session_resp *open_session_resp; +int if_id; + +/* Search for a free session interface id. */ + if_id =le32_to_cpu (session_open->if_id); +if (if_id <0 || if_id >= ipc_mux->nr_sessions) { +dev_err (ipc_mux->dev,"invalid interface id=%d" , if_id); +return false; + } + +/* Create and send the session open command. +* It is a blocking function call, until CP responds or timeout. +*/ + open_session_resp =mux_session_open_send (ipc_mux, if_id); +if (!open_session_resp) { +mux_session_free (ipc_mux, if_id); + session_open->if_id =cpu_to_le32 (-1 ); +return false; + } + +/* Initialize the uplink skb accumulator. */ +skb_queue_head_init (&ipc_mux->session[if_id].ul_list); + + ipc_mux->session[if_id].dl_head_pad_len =IPC_MEM_DL_ETH_OFFSET ; + ipc_mux->session[if_id].ul_head_pad_len = +le32_to_cpu (open_session_resp->ul_head_pad_len); + ipc_mux->session[if_id].wwan = ipc_mux->wwan; + +/* Reset the flow ctrl stats of the session */ + ipc_mux->session[if_id].flow_ctl_en_cnt =0 ; + ipc_mux->session[if_id].flow_ctl_dis_cnt =0 ; + ipc_mux->session[if_id].ul_flow_credits =0 ; + ipc_mux->session[if_id].net_tx_stop = false; + ipc_mux->session[if_id].flow_ctl_mask =0 ; + +/* Save and return the assigned if id. */ + session_open->if_id =cpu_to_le32 (if_id); + +return true; +} + +/* Free pending session UL packet. */ +static void mux_session_reset (struct iosm_mux *ipc_mux,int if_id) +{ +/* Reset the session/if id state. */ +mux_session_free (ipc_mux, if_id); + +/* Empty the uplink skb accumulator. */ +skb_queue_purge (&ipc_mux->session[if_id].ul_list); +} + +static void mux_session_close (struct iosm_mux *ipc_mux, +struct mux_session_close *msg) +{ +int if_id; + +/* Copy the session interface id. */ + if_id =le32_to_cpu (msg->if_id); + +if (if_id <0 || if_id >= ipc_mux->nr_sessions) { +dev_err (ipc_mux->dev,"invalid session id %d" , if_id); +return ; + } + +/* Create and send the session close command. +* It is a blocking function call, until CP responds or timeout. +*/ +if (mux_dl_acb_send_cmds (ipc_mux,MUX_CMD_CLOSE_SESSION , if_id,0 ,NULL , +0 , true, false)) +dev_err (ipc_mux->dev,"if_id %d: CLOSE_SESSION send failed" , + if_id); + +/* Reset the flow ctrl stats of the session */ + ipc_mux->session[if_id].flow_ctl_en_cnt =0 ; + ipc_mux->session[if_id].flow_ctl_dis_cnt =0 ; + ipc_mux->session[if_id].flow_ctl_mask =0 ; + +mux_session_reset (ipc_mux, if_id); +} + +static void mux_channel_close (struct iosm_mux *ipc_mux, +struct mux_channel_close *channel_close_p) +{ +int i; + +/* Free pending session UL packet. */ +for (i =0 ; i < ipc_mux->nr_sessions; i++) +if (ipc_mux->session[i].wwan) +mux_session_reset (ipc_mux, i); + +imem_channel_close (ipc_mux->imem, ipc_mux->channel_id); + +/* Reset the MUX object. */ + ipc_mux->state =MUX_S_INACTIVE ; + ipc_mux->event =MUX_E_INACTIVE ; +} + +/* CP has interrupted AP. If AP is in IP MUX mode, execute the pending ops. */ +static int mux_schedule (struct iosm_mux *ipc_mux,union mux_msg *msg) +{ +enum mux_event order; +bool success; +int ret = -EIO ; + +if (!ipc_mux->initialized) { + ret = -EAGAIN ; + goto out; + } + + order = msg->common.event; + +switch (ipc_mux->state) { +case MUX_S_INACTIVE : +if (order !=MUX_E_MUX_SESSION_OPEN ) + goto out;/* Wait for the request to open a session */ + +if (ipc_mux->event ==MUX_E_INACTIVE ) +/* Establish the MUX channel and the new state. */ + ipc_mux->channel_id =mux_channel_create (ipc_mux); + +if (ipc_mux->state !=MUX_S_ACTIVE ) { + ret = ipc_mux->channel_id;/* Missing the MUX channel */ + goto out; + } + +/* Disable the TD update timer and open the first IP session. */ +imem_td_update_timer_suspend (ipc_mux->imem, true); + ipc_mux->event =MUX_E_MUX_SESSION_OPEN ; + success =mux_session_open (ipc_mux, &msg->session_open); + +imem_td_update_timer_suspend (ipc_mux->imem, false); +if (success) + ret = ipc_mux->channel_id; + goto out; + +case MUX_S_ACTIVE : +switch (order) { +case MUX_E_MUX_SESSION_OPEN : +/* Disable the TD update timer and open a session */ +imem_td_update_timer_suspend (ipc_mux->imem, true); + ipc_mux->event =MUX_E_MUX_SESSION_OPEN ; + success =mux_session_open (ipc_mux, &msg->session_open); +imem_td_update_timer_suspend (ipc_mux->imem, false); +if (success) + ret = ipc_mux->channel_id; + goto out; + +case MUX_E_MUX_SESSION_CLOSE : +/* Release an IP session. */ + ipc_mux->event =MUX_E_MUX_SESSION_CLOSE ; +mux_session_close (ipc_mux, &msg->session_close); + ret = ipc_mux->channel_id; + goto out; + +case MUX_E_MUX_CHANNEL_CLOSE : +/* Close the MUX channel pipes. */ + ipc_mux->event =MUX_E_MUX_CHANNEL_CLOSE ; +mux_channel_close (ipc_mux, &msg->channel_close); + ret = ipc_mux->channel_id; + goto out; + +default : +/* Invalid order. */ + goto out; + } + +default : +dev_err (ipc_mux->dev, +"unexpected MUX transition: state=%d, event=%d" , + ipc_mux->state, ipc_mux->event); + } +out: +return ret; +} + +struct iosm_mux *mux_init (struct ipc_mux_config *mux_cfg, +struct iosm_imem *imem) +{ +struct iosm_mux *ipc_mux =kzalloc (sizeof (*ipc_mux),GFP_KERNEL ); +int i, ul_tds, ul_td_size; +struct sk_buff_head *free_list; +struct sk_buff *skb; + +if (!ipc_mux) +return NULL ; + + ipc_mux->protocol = mux_cfg->protocol; + ipc_mux->ul_flow = mux_cfg->ul_flow; + ipc_mux->nr_sessions = mux_cfg->nr_sessions; + ipc_mux->instance_id = mux_cfg->instance_id; + ipc_mux->wwan_q_offset =0 ; + + ipc_mux->pcie = imem->pcie; + ipc_mux->imem = imem; + ipc_mux->ipc_protocol = imem->ipc_protocol; + ipc_mux->dev = imem->dev; + ipc_mux->wwan = imem->wwan; + +/* Get the reference to the UL ADB list. */ + free_list = &ipc_mux->ul_adb.free_list; + +/* Initialize the list with free ADB. */ +skb_queue_head_init (free_list); + + ul_td_size =IPC_MEM_MAX_DL_MUX_LITE_BUF_SIZE ; + + ul_tds =IPC_MEM_MAX_TDS_MUX_LITE_UL ; + + ipc_mux->ul_adb.dest_skb =NULL ; + + ipc_mux->initialized = true; + ipc_mux->adb_prep_ongoing = false; + ipc_mux->size_needed =0 ; + ipc_mux->ul_data_pend_bytes =0 ; + ipc_mux->state =MUX_S_INACTIVE ; + ipc_mux->ev_mux_net_transmit_pending = false; + ipc_mux->tx_transaction_id =0 ; + ipc_mux->rr_next_session =0 ; + ipc_mux->event =MUX_E_INACTIVE ; + ipc_mux->channel_id =-1 ; + ipc_mux->channel =NULL ; + +/* Allocate the list of UL ADB. */ +for (i =0 ; i < ul_tds; i++) { +dma_addr_t mapping; + + skb =ipc_pcie_alloc_skb (ipc_mux->pcie, ul_td_size,GFP_ATOMIC , + &mapping,DMA_TO_DEVICE ,0 ); +if (!skb) { +ipc_mux_deinit (ipc_mux); +return NULL ; + } +/* Extend the UL ADB list. */ +skb_queue_tail (free_list, skb); + } + +return ipc_mux; +} + +/* Informs the network stack to restart transmission for all opened session if +* Flow Control is not ON for that session. +*/ +static void mux_restart_tx_for_all_sessions (struct iosm_mux *ipc_mux) +{ +struct mux_session *session; +int idx; + +for (idx =0 ; idx < ipc_mux->nr_sessions; idx++) { + session = &ipc_mux->session[idx]; + +if (!session->wwan) +continue ; + +/* If flow control of the session is OFF and if there was tx +* stop then restart. Inform the network interface to restart +* sending data. +*/ +if (session->flow_ctl_mask ==0 ) { + session->net_tx_stop = false; +mux_netif_tx_flowctrl (session, idx, false); + } + } +} + +/* Informs the network stack to stop sending further pkt for all opened +* sessions +*/ +static void mux_stop_netif_for_all_sessions (struct iosm_mux *ipc_mux) +{ +struct mux_session *session; +int idx; + +for (idx =0 ; idx < ipc_mux->nr_sessions; idx++) { + session = &ipc_mux->session[idx]; + +if (!session->wwan) +continue ; + +mux_netif_tx_flowctrl (session, session->if_id, true); + } +} + +void ipc_mux_check_n_restart_tx (struct iosm_mux *ipc_mux) +{ +if (ipc_mux->ul_flow ==MUX_UL ) { +int low_thresh =IPC_MEM_MUX_UL_FLOWCTRL_LOW_B ; + +if (ipc_mux->ul_data_pend_bytes < low_thresh) +mux_restart_tx_for_all_sessions (ipc_mux); + } +} + +int ipc_mux_get_max_sessions (struct iosm_mux *ipc_mux) +{ +return ipc_mux ? ipc_mux->nr_sessions : -EFAULT ; +} + +enum ipc_mux_protocol ipc_mux_get_active_protocol (struct iosm_mux *ipc_mux) +{ +return ipc_mux ? ipc_mux->protocol :MUX_UNKNOWN ; +} + +int ipc_mux_open_session (struct iosm_mux *ipc_mux,int session_nr) +{ +struct mux_session_open *session_open; +union mux_msg mux_msg; + + session_open = &mux_msg.session_open; + session_open->event =MUX_E_MUX_SESSION_OPEN ; + + session_open->if_id =cpu_to_le32 (session_nr); + ipc_mux->session[session_nr].flags |=IPC_MEM_WWAN_MUX ; +return mux_schedule (ipc_mux, &mux_msg); +} + +int ipc_mux_close_session (struct iosm_mux *ipc_mux,int session_nr) +{ +struct mux_session_close *session_close; +union mux_msg mux_msg; +int ret_val; + + session_close = &mux_msg.session_close; + session_close->event =MUX_E_MUX_SESSION_CLOSE ; + + session_close->if_id =cpu_to_le32 (session_nr); + ret_val =mux_schedule (ipc_mux, &mux_msg); + ipc_mux->session[session_nr].flags &= ~IPC_MEM_WWAN_MUX ; + +return ret_val; +} + +void ipc_mux_deinit (struct iosm_mux *ipc_mux) +{ +struct mux_channel_close *channel_close; +struct sk_buff_head *free_list; +union mux_msg mux_msg; +struct sk_buff *skb; + +if (!ipc_mux->initialized) +return ; +mux_stop_netif_for_all_sessions (ipc_mux); + + channel_close = &mux_msg.channel_close; + channel_close->event =MUX_E_MUX_CHANNEL_CLOSE ; +mux_schedule (ipc_mux, &mux_msg); + +/* Empty the ADB free list. */ + free_list = &ipc_mux->ul_adb.free_list; + +/* Remove from the head of the downlink queue. */ +while ((skb =skb_dequeue (free_list))) +ipc_pcie_kfree_skb (ipc_mux->pcie, skb); + +if (ipc_mux->channel) { + ipc_mux->channel->ul_pipe.is_open = false; + ipc_mux->channel->dl_pipe.is_open = false; + } + +kfree (ipc_mux); +}
drivers/net/wwan/iosm/iosm_ipc_mux.h new file +343 -0
343 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 10/16 net: iosm: encode or decode datagram
In reply to M Chetan Kumar1) Encode UL packet into datagram.
2) Decode DL datagram and route it to network layer.
3) Supports credit based flow control.
---
v2:
* Endianness type correction for Host-Device protocol structure.
* Function signature documentation correction.
* Streamline multiple returns using goto.
* Removed vlan tag id & replace with ip link interface id.
--- drivers/net/wwan/iosm/iosm_ipc_mux_codec.c | 901 +++++++++++++++++++++ drivers/net/wwan/iosm/iosm_ipc_mux_codec.h | 193 +++++ 2 files changed, 1094 insertions(+) create mode 100644 drivers/net/wwan/iosm/iosm_ipc_mux_codec.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_mux_codec.h
drivers/net/wwan/iosm/iosm_ipc_mux_codec.c new file +901 -0
@@ -0,0 +1,901 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2020-21 Intel Corporation. +*/ + +#include <linux/nospec.h> + +#include "iosm_ipc_imem_ops.h" +#include "iosm_ipc_mux_codec.h" +#include "iosm_ipc_task_queue.h" + +/* Test the link power state and send a MUX command in blocking mode. */ +static int mux_tq_cmd_send (struct iosm_imem *ipc_imem,int arg,void *msg, +size_t size) +{ +struct iosm_mux *ipc_mux = ipc_imem->mux; +const struct mux_acb *acb = msg; + +skb_queue_tail (&ipc_mux->channel->ul_list, acb->skb); +imem_ul_send (ipc_mux->imem); + +return 0 ; +} + +static int mux_acb_send (struct iosm_mux *ipc_mux,bool blocking) +{ +struct completion *completion = &ipc_mux->channel->ul_sem; +int ret =ipc_task_queue_send_task (ipc_mux->imem, mux_tq_cmd_send,0 , + &ipc_mux->acb,sizeof (ipc_mux->acb), + false); +if (ret) { +dev_err (ipc_mux->dev,"unable to send mux command" ); +return ret; + } + +/* if blocking, suspend the app and wait for irq in the flash or +* crash phase. return false on timeout to indicate failure. +*/ +if (blocking) { +u32 wait_time_milliseconds =IPC_MUX_CMD_RUN_DEFAULT_TIMEOUT ; + +reinit_completion (completion); + +if (wait_for_completion_interruptible_timeout + (completion,msecs_to_jiffies (wait_time_milliseconds)) == +0 ) { +dev_err (ipc_mux->dev,"ch[%d] timeout" , + ipc_mux->channel_id); +ipc_uevent_send (ipc_mux->imem->dev,UEVENT_MDM_TIMEOUT ); +return -ETIMEDOUT ; + } + } + +return 0 ; +} + +/* Prepare mux Command */ +static struct mux_lite_cmdh *mux_lite_add_cmd (struct iosm_mux *ipc_mux,u32 cmd, +struct mux_acb *acb,void *param, +u32 param_size) +{ +struct mux_lite_cmdh *cmdh = (struct mux_lite_cmdh *)acb->skb->data; + + cmdh->signature =cpu_to_le32 (MUX_SIG_CMDH ); + cmdh->command_type =cpu_to_le32 (cmd); + cmdh->if_id = acb->if_id; + + acb->cmd = cmd; + + cmdh->cmd_len =cpu_to_le16 (offsetof(struct mux_lite_cmdh , param) + + param_size); + cmdh->transaction_id =cpu_to_le32 (ipc_mux->tx_transaction_id++); + +if (param) +memcpy (&cmdh->param, param, param_size); + +skb_put (acb->skb,le16_to_cpu (cmdh->cmd_len)); + +return cmdh; +} + +static int mux_acb_alloc (struct iosm_mux *ipc_mux) +{ +struct mux_acb *acb = &ipc_mux->acb; +struct sk_buff *skb; +dma_addr_t mapping; + +/* Allocate skb memory for the uplink buffer. */ + skb =ipc_pcie_alloc_skb (ipc_mux->pcie,MUX_MAX_UL_ACB_BUF_SIZE , +GFP_ATOMIC , &mapping,DMA_TO_DEVICE ,0 ); +if (!skb) +return -ENOMEM ; + +/* Save the skb address. */ + acb->skb = skb; + +memset (skb->data,0 ,MUX_MAX_UL_ACB_BUF_SIZE ); + +return 0 ; +} + +int mux_dl_acb_send_cmds (struct iosm_mux *ipc_mux,u32 cmd_type,u8 if_id, +u32 transaction_id,union mux_cmd_param *param, +size_t res_size,bool blocking,bool respond) +{ +struct mux_acb *acb = &ipc_mux->acb; +struct mux_lite_cmdh *ack_lite; +int ret =0 ; + + acb->if_id = if_id; + ret =mux_acb_alloc (ipc_mux); +if (ret) +return ret; + + ack_lite =mux_lite_add_cmd (ipc_mux, cmd_type, acb, param, res_size); +if (respond) + ack_lite->transaction_id =cpu_to_le32 (transaction_id); + + ret =mux_acb_send (ipc_mux, blocking); + +return ret; +} + +void mux_netif_tx_flowctrl (struct mux_session *session,int idx,bool on) +{ +/* Inform the network interface to start/stop flow ctrl */ +ipc_wwan_tx_flowctrl (session->wwan, idx, on); +} + +static int mux_dl_cmdresps_decode_process (struct iosm_mux *ipc_mux, +struct mux_lite_cmdh *cmdh) +{ +struct mux_acb *acb = &ipc_mux->acb; + +switch (le32_to_cpu (cmdh->command_type)) { +case MUX_CMD_OPEN_SESSION_RESP : +case MUX_CMD_CLOSE_SESSION_RESP : +/* Resume the control application. */ + acb->got_param = cmdh->param; +break ; + +case MUX_LITE_CMD_FLOW_CTL_ACK : +/* This command type is not expected as response for +* Aggregation version of the protocol. So return non-zero. +*/ +if (ipc_mux->protocol !=MUX_LITE ) +return -EINVAL ; + +dev_dbg (ipc_mux->dev,"if %u FLOW_CTL_ACK %u received" , + cmdh->if_id,le32_to_cpu (cmdh->transaction_id)); +break ; + +default : +return -EINVAL ; + } + + acb->wanted_response =MUX_CMD_INVALID ; + acb->got_response =le32_to_cpu (cmdh->command_type); +complete (&ipc_mux->channel->ul_sem); + +return 0 ; +} + +static int mux_dl_dlcmds_decode_process (struct iosm_mux *ipc_mux, +struct mux_lite_cmdh *cmdh) +{ +union mux_cmd_param *param = &cmdh->param; +struct mux_session *session; +int new_size; + +dev_dbg (ipc_mux->dev,"if_id[%d]: dlcmds decode process %d" , + cmdh->if_id,le32_to_cpu (cmdh->command_type)); + +switch (le32_to_cpu (cmdh->command_type)) { +case MUX_LITE_CMD_FLOW_CTL : + +if (cmdh->if_id >= ipc_mux->nr_sessions) { +dev_err (ipc_mux->dev,"if_id [%d] not valid" , + cmdh->if_id); +return -EINVAL ;/* No session interface id. */ + } + + session = &ipc_mux->session[cmdh->if_id]; + + new_size = offsetof(struct mux_lite_cmdh , param) + +sizeof (param->flow_ctl); +if (param->flow_ctl.mask ==cpu_to_le32 (0xFFFFFFFF )) { +/* Backward Compatibility */ +if (cmdh->cmd_len ==cpu_to_le16 (new_size)) + session->flow_ctl_mask = +le32_to_cpu (param->flow_ctl.mask); +else + session->flow_ctl_mask = ~0 ; +/* if CP asks for FLOW CTRL Enable +* then set our internal flow control Tx flag +* to limit uplink session queueing +*/ + session->net_tx_stop = true; +/* Update the stats */ + session->flow_ctl_en_cnt++; + }else if (param->flow_ctl.mask ==0 ) { +/* Just reset the Flow control mask and let +* mux_flow_ctrl_low_thre_b take control on +* our internal Tx flag and enabling kernel +* flow control +*/ +/* Backward Compatibility */ +if (cmdh->cmd_len ==cpu_to_le16 (new_size)) + session->flow_ctl_mask = +le32_to_cpu (param->flow_ctl.mask); +else + session->flow_ctl_mask =0 ; +/* Update the stats */ + session->flow_ctl_dis_cnt++; + }else { +break ; + } + +dev_dbg (ipc_mux->dev,"if[%u] FLOW CTRL 0x%08X" , cmdh->if_id, +le32_to_cpu (param->flow_ctl.mask)); +break ; + +case MUX_LITE_CMD_LINK_STATUS_REPORT : +break ; + +default : +return -EINVAL ; + } +return 0 ; +} + +/* Decode and Send appropriate response to a command block. */ +static void mux_dl_cmd_decode (struct iosm_mux *ipc_mux,struct sk_buff *skb) +{ +struct mux_lite_cmdh *cmdh = (struct mux_lite_cmdh *)skb->data; + +if (mux_dl_cmdresps_decode_process (ipc_mux, cmdh)) { +/* Unable to decode command response indicates the cmd_type +* may be a command instead of response. So try to decoding it. +*/ +if (!mux_dl_dlcmds_decode_process (ipc_mux, cmdh)) { +/* Decoded command may need a response. Give the +* response according to the command type. +*/ +union mux_cmd_param *mux_cmd =NULL ; +size_t size =0 ; +u32 cmd =MUX_LITE_CMD_LINK_STATUS_REPORT_RESP ; + +if (cmdh->command_type == +cpu_to_le32 (MUX_LITE_CMD_LINK_STATUS_REPORT )) { + mux_cmd = &cmdh->param; + mux_cmd->link_status_resp.response = +cpu_to_le32 (MUX_CMD_RESP_SUCCESS ); +/* response field is u32 */ + size =sizeof (u32); + }else if (cmdh->command_type == +cpu_to_le32 (MUX_LITE_CMD_FLOW_CTL )) { + cmd =MUX_LITE_CMD_FLOW_CTL_ACK ; + }else { +return ; + } + +if (mux_dl_acb_send_cmds (ipc_mux, cmd, cmdh->if_id, +le32_to_cpu (cmdh->transaction_id), + mux_cmd, size, false, true)) +dev_err (ipc_mux->dev, +"if_id %d: cmd send failed" , + cmdh->if_id); + } + } +} + +/* Pass the DL packet to the netif layer. */ +static int mux_net_receive (struct iosm_mux *ipc_mux,int if_id, +struct iosm_wwan *wwan,u32 offset,u8 service_class, +struct sk_buff *skb) +{ +struct sk_buff *dest_skb =skb_clone (skb,GFP_ATOMIC ); + +if (!dest_skb) +return -ENOMEM ; + +skb_pull (dest_skb, offset); +skb_set_tail_pointer (dest_skb, dest_skb->len); +/* Pass the packet to the netif layer. */ + dest_skb->priority = service_class; + +return ipc_wwan_receive (wwan, dest_skb, false, if_id); +} + +/* Decode Flow Credit Table in the block */ +static void mux_dl_fcth_decode (struct iosm_mux *ipc_mux,unsigned char *block) +{ +struct ipc_mem_lite_gen_tbl *fct = (struct ipc_mem_lite_gen_tbl *)block; +struct iosm_wwan *wwan; +int ul_credits; +int if_id; + +if (fct->vfl_length !=sizeof (fct->vfl.nr_of_bytes)) { +dev_err (ipc_mux->dev,"unexpected FCT length: %d" , + fct->vfl_length); +return ; + } + + if_id = fct->if_id; +if (if_id >= ipc_mux->nr_sessions) { +dev_err (ipc_mux->dev,"not supported if_id: %d" , if_id); +return ; + } + +/* Is the session active ? */ + if_id =array_index_nospec (if_id, ipc_mux->nr_sessions); + wwan = ipc_mux->session[if_id].wwan; +if (!wwan) { +dev_err (ipc_mux->dev,"session Net ID is NULL" ); +return ; + } + + ul_credits = fct->vfl.nr_of_bytes; + +dev_dbg (ipc_mux->dev,"Flow_Credit:: if_id[%d] Old: %d Grants: %d" , + if_id, ipc_mux->session[if_id].ul_flow_credits, ul_credits); + +/* Update the Flow Credit information from ADB */ + ipc_mux->session[if_id].ul_flow_credits += ul_credits; + +/* Check whether the TX can be started */ +if (ipc_mux->session[if_id].ul_flow_credits >0 ) { + ipc_mux->session[if_id].net_tx_stop = false; +mux_netif_tx_flowctrl (&ipc_mux->session[if_id], + ipc_mux->session[if_id].if_id, false); + } +} + +/* Decode non-aggregated datagram */ +static void mux_dl_adgh_decode (struct iosm_mux *ipc_mux,struct sk_buff *skb) +{ +u32 pad_len, packet_offset; +struct iosm_wwan *wwan; +struct mux_adgh *adgh; +u8 *block = skb->data; +int rc =0 ; +u8 if_id; + + adgh = (struct mux_adgh *)block; + +if (adgh->signature !=cpu_to_le32 (MUX_SIG_ADGH )) { +dev_err (ipc_mux->dev,"invalid ADGH signature received" ); +return ; + } + + if_id = adgh->if_id; +if (if_id >= ipc_mux->nr_sessions) { +dev_err (ipc_mux->dev,"invalid if_id while decoding %d" , if_id); +return ; + } + +/* Is the session active ? */ + if_id =array_index_nospec (if_id, ipc_mux->nr_sessions); + wwan = ipc_mux->session[if_id].wwan; +if (!wwan) { +dev_err (ipc_mux->dev,"session Net ID is NULL" ); +return ; + } + +/* Store the pad len for the corresponding session +* Pad bytes as negotiated in the open session less the header size +* (see session management chapter for details). +* If resulting padding is zero or less, the additional head padding is +* omitted. For e.g., if HEAD_PAD_LEN = 16 or less, this field is +* omitted if HEAD_PAD_LEN = 20, then this field will have 4 bytes +* set to zero +*/ + pad_len = + ipc_mux->session[if_id].dl_head_pad_len -IPC_MEM_DL_ETH_OFFSET ; + packet_offset =sizeof (*adgh) + pad_len; + + if_id += ipc_mux->wwan_q_offset; + +/* Pass the packet to the netif layer */ + rc =mux_net_receive (ipc_mux, if_id, wwan, packet_offset, + adgh->service_class, skb); +if (rc) { +dev_err (ipc_mux->dev,"mux adgh decoding error" ); +return ; + } + ipc_mux->session[if_id].flush =1 ; +} + +void ipc_mux_dl_decode (struct iosm_mux *ipc_mux,struct sk_buff *skb) +{ +u32 signature; + +if (!skb->data) +return ; + +/* Decode the MUX header type. */ + signature =le32_to_cpup ((__le32 *)skb->data); + +switch (signature) { +case MUX_SIG_ADGH : +mux_dl_adgh_decode (ipc_mux, skb); +break ; + +case MUX_SIG_FCTH : +mux_dl_fcth_decode (ipc_mux, skb->data); +break ; + +case MUX_SIG_CMDH : +mux_dl_cmd_decode (ipc_mux, skb); +break ; + +default : +dev_err (ipc_mux->dev,"invalid ABH signature" ); + } + +ipc_pcie_kfree_skb (ipc_mux->pcie, skb); +} + +static int mux_ul_skb_alloc (struct iosm_mux *ipc_mux,struct mux_adb *ul_adb, +u32 type) +{ +/* Take the first element of the free list. */ +struct sk_buff *skb =skb_dequeue (&ul_adb->free_list); +int qlt_size; + +if (!skb) +return -EBUSY ;/* Wait for a free ADB skb. */ + +/* Mark it as UL ADB to select the right free operation. */ +IPC_CB (skb)->op_type = (u8 )UL_MUX_OP_ADB ; + +switch (type) { +case MUX_SIG_ADGH : +/* Save the ADB memory settings. */ + ul_adb->dest_skb = skb; + ul_adb->buf = skb->data; + ul_adb->size =IPC_MEM_MAX_DL_MUX_LITE_BUF_SIZE ; +/* reset statistic counter */ + ul_adb->if_cnt =0 ; + ul_adb->payload_size =0 ; + ul_adb->dg_cnt_total =0 ; + + ul_adb->adgh = (struct mux_adgh *)skb->data; +memset (ul_adb->adgh,0 ,sizeof (struct mux_adgh )); +break ; + +case MUX_SIG_QLTH : + qlt_size = offsetof(struct ipc_mem_lite_gen_tbl , vfl) + + (MUX_QUEUE_LEVEL *sizeof (struct mux_lite_vfl )); + +if (qlt_size >IPC_MEM_MAX_DL_MUX_LITE_BUF_SIZE ) { +dev_err (ipc_mux->dev, +"can't support. QLT size:%d SKB size: %d" , + qlt_size,IPC_MEM_MAX_DL_MUX_LITE_BUF_SIZE ); +return -ERANGE ; + } + + ul_adb->qlth_skb = skb; +memset ((ul_adb->qlth_skb)->data,0 , qlt_size); +skb_put (skb, qlt_size); +break ; + } + +return 0 ; +} + +static void mux_ul_adgh_finish (struct iosm_mux *ipc_mux) +{ +struct mux_adb *ul_adb = &ipc_mux->ul_adb; +u16 adgh_len; +long long bytes; +char *str; + +if (!ul_adb || !ul_adb->dest_skb) { +dev_err (ipc_mux->dev,"no dest skb" ); +return ; + } + + adgh_len =le16_to_cpu (ul_adb->adgh->length); +skb_put (ul_adb->dest_skb, adgh_len); +skb_queue_tail (&ipc_mux->channel->ul_list, ul_adb->dest_skb); + ul_adb->dest_skb =NULL ; + +if (ipc_mux->ul_flow ==MUX_UL_ON_CREDITS ) { +struct mux_session *session; + + session = &ipc_mux->session[ul_adb->adgh->if_id]; + str ="available_credits" ; + bytes = (long long )session->ul_flow_credits; + + }else { + str ="pend_bytes" ; + bytes = ipc_mux->ul_data_pend_bytes; + ipc_mux->ul_data_pend_bytes = ipc_mux->ul_data_pend_bytes + + adgh_len; + } + +dev_dbg (ipc_mux->dev,"UL ADGH: size=%u, if_id=%d, payload=%d, %s=%lld" , + adgh_len, ul_adb->adgh->if_id, ul_adb->payload_size, + str, bytes); +} + +/* Allocates an ADB from the free list and initializes it with ADBH */ +static bool mux_ul_adb_allocate (struct iosm_mux *ipc_mux,struct mux_adb *adb, +int *size_needed,u32 type) +{ +bool ret_val = false; +int status; + +if (!adb->dest_skb) { +/* Allocate memory for the ADB including of the +* datagram table header. +*/ + status =mux_ul_skb_alloc (ipc_mux, adb, type); +if (status) +/* Is a pending ADB available ? */ + ret_val = true;/* None. */ + +/* Update size need to zero only for new ADB memory */ + *size_needed =0 ; + } + +return ret_val; +} + +/* Informs the network stack to stop sending further packets for all opened +* sessions +*/ +static void mux_stop_tx_for_all_sessions (struct iosm_mux *ipc_mux) +{ +struct mux_session *session; +int idx; + +for (idx =0 ; idx < ipc_mux->nr_sessions; idx++) { + session = &ipc_mux->session[idx]; + +if (!session->wwan) +continue ; + + session->net_tx_stop = true; + } +} + +/* Sends Queue Level Table of all opened sessions */ +static bool mux_lite_send_qlt (struct iosm_mux *ipc_mux) +{ +struct ipc_mem_lite_gen_tbl *qlt; +struct mux_session *session; +bool qlt_updated = false; +int i; +int qlt_size; + +if (!ipc_mux->initialized || ipc_mux->state !=MUX_S_ACTIVE ) +return qlt_updated; + + qlt_size = offsetof(struct ipc_mem_lite_gen_tbl , vfl) + +MUX_QUEUE_LEVEL *sizeof (struct mux_lite_vfl ); + +for (i =0 ; i < ipc_mux->nr_sessions; i++) { + session = &ipc_mux->session[i]; + +if (!session->wwan || session->flow_ctl_mask) +continue ; + +if (mux_ul_skb_alloc (ipc_mux, &ipc_mux->ul_adb,MUX_SIG_QLTH )) { +dev_err (ipc_mux->dev, +"no reserved mem to send QLT of if_id: %d" , i); +break ; + } + +/* Prepare QLT */ + qlt = (struct ipc_mem_lite_gen_tbl *)(ipc_mux->ul_adb.qlth_skb) + ->data; + qlt->signature =cpu_to_le32 (MUX_SIG_QLTH ); + qlt->length =cpu_to_le16 (qlt_size); + qlt->if_id = i; + qlt->vfl_length =MUX_QUEUE_LEVEL *sizeof (struct mux_lite_vfl ); + qlt->reserved[0 ] =0 ; + qlt->reserved[1 ] =0 ; + + qlt->vfl.nr_of_bytes = session->ul_list.qlen; + +/* Add QLT to the transfer list. */ +skb_queue_tail (&ipc_mux->channel->ul_list, + ipc_mux->ul_adb.qlth_skb); + + qlt_updated = true; + ipc_mux->ul_adb.qlth_skb =NULL ; + } + +if (qlt_updated) +/* Updates the TDs with ul_list */ + (void )imem_ul_write_td (ipc_mux->imem); + +return qlt_updated; +} + +/* Checks the available credits for the specified session and returns +* number of packets for which credits are available. +*/ +static int mux_ul_bytes_credits_check (struct iosm_mux *ipc_mux, +struct mux_session *session, +struct sk_buff_head *ul_list, +int max_nr_of_pkts) +{ +int pkts_to_send =0 ; +struct sk_buff *skb; +int credits =0 ; + +if (ipc_mux->ul_flow ==MUX_UL_ON_CREDITS ) { + credits = session->ul_flow_credits; +if (credits <=0 ) { +dev_dbg (ipc_mux->dev, +"FC::if_id[%d] Insuff.Credits/Qlen:%d/%u" , + session->if_id, session->ul_flow_credits, + session->ul_list.qlen);/* nr_of_bytes */ +return 0 ; + } + }else { + credits =IPC_MEM_MUX_UL_FLOWCTRL_HIGH_B - + ipc_mux->ul_data_pend_bytes; +if (credits <=0 ) { +mux_stop_tx_for_all_sessions (ipc_mux); + +dev_dbg (ipc_mux->dev, +"if_id[%d] Stopped encoding.PendBytes: %llu, high_thresh: %d" , + session->if_id, ipc_mux->ul_data_pend_bytes, +IPC_MEM_MUX_UL_FLOWCTRL_HIGH_B ); +return 0 ; + } + } + +/* Check if there are enough credits/bytes available to send the +* requested max_nr_of_pkts. Otherwise restrict the nr_of_pkts +* depending on available credits. +*/ + skb_queue_walk(ul_list, skb) + { +if (!(credits >= skb->len && pkts_to_send < max_nr_of_pkts)) +break ; + credits -= skb->len; + pkts_to_send++; + } + +return pkts_to_send; +} + +/* Encode the UL IP packet according to Lite spec. */ +static int mux_ul_adgh_encode (struct iosm_mux *ipc_mux,int session_id, +struct mux_session *session, +struct sk_buff_head *ul_list,struct mux_adb *adb, +int nr_of_pkts) +{ +int offset =sizeof (struct mux_adgh ); +int adb_updated = -EINVAL ; +struct sk_buff *src_skb; +int aligned_size =0 ; +int nr_of_skb =0 ; +u32 pad_len =0 ; + +/* Re-calculate the number of packets depending on number of bytes to be +* processed/available credits. +*/ + nr_of_pkts =mux_ul_bytes_credits_check (ipc_mux, session, ul_list, + nr_of_pkts); + +/* If calculated nr_of_pkts from available credits is <= 0 +* then nothing to do. +*/ +if (nr_of_pkts <=0 ) +return 0 ; + +/* Read configured UL head_pad_length for session.*/ +if (session->ul_head_pad_len >IPC_MEM_DL_ETH_OFFSET ) + pad_len = session->ul_head_pad_len -IPC_MEM_DL_ETH_OFFSET ; + +/* Process all pending UL packets for this session +* depending on the allocated datagram table size. +*/ +while (nr_of_pkts >0 ) { +/* get destination skb allocated */ +if (mux_ul_adb_allocate (ipc_mux, adb, &ipc_mux->size_needed, +MUX_SIG_ADGH )) { +dev_err (ipc_mux->dev,"no reserved memory for ADGH" ); +return -ENOMEM ; + } + +/* Peek at the head of the list. */ + src_skb =skb_peek (ul_list); +if (!src_skb) { +dev_err (ipc_mux->dev, +"skb peek return NULL with count : %d" , + nr_of_pkts); +break ; + } + +/* Calculate the memory value. */ + aligned_size =ALIGN ((pad_len + src_skb->len),4 ); + + ipc_mux->size_needed =sizeof (struct mux_adgh ) + aligned_size; + +if (ipc_mux->size_needed > adb->size) { +dev_dbg (ipc_mux->dev,"size needed %d, adgh size %d" , + ipc_mux->size_needed, adb->size); +/* Return 1 if any IP packet is added to the transfer +* list. +*/ +return nr_of_skb ?1 :0 ; + } + +/* Add buffer (without head padding to next pending transfer) */ +memcpy (adb->buf + offset + pad_len, src_skb->data, + src_skb->len); + + adb->adgh->signature =cpu_to_le32 (MUX_SIG_ADGH ); + adb->adgh->if_id = session_id; + adb->adgh->length = +cpu_to_le16 (sizeof (struct mux_adgh ) + pad_len + src_skb->len); + adb->adgh->service_class = src_skb->priority; + adb->adgh->next_count = --nr_of_pkts; + adb->dg_cnt_total++; + adb->payload_size += src_skb->len; + +if (ipc_mux->ul_flow ==MUX_UL_ON_CREDITS ) +/* Decrement the credit value as we are processing the +* datagram from the UL list. +*/ + session->ul_flow_credits -= src_skb->len; + +/* Remove the processed elements and free it. */ + src_skb =skb_dequeue (ul_list); +dev_kfree_skb (src_skb); + nr_of_skb++; + +mux_ul_adgh_finish (ipc_mux); + } + +if (nr_of_skb) { +/* Send QLT info to modem if pending bytes > high watermark +* in case of mux lite +*/ +if (ipc_mux->ul_flow ==MUX_UL_ON_CREDITS || + ipc_mux->ul_data_pend_bytes >= +IPC_MEM_MUX_UL_FLOWCTRL_LOW_B ) + adb_updated =mux_lite_send_qlt (ipc_mux); +else + adb_updated =1 ; + +/* Updates the TDs with ul_list */ + (void )imem_ul_write_td (ipc_mux->imem); + } + +return adb_updated; +} + +bool ipc_mux_ul_data_encode (struct iosm_mux *ipc_mux) +{ +struct sk_buff_head *ul_list; +struct mux_session *session; +int updated =0 ; +int session_id; +int dg_n; +int i; + +if (!ipc_mux || ipc_mux->state !=MUX_S_ACTIVE || + ipc_mux->adb_prep_ongoing) +return false; + + ipc_mux->adb_prep_ongoing = true; + +for (i =0 ; i < ipc_mux->nr_sessions; i++) { + session_id = ipc_mux->rr_next_session; + session = &ipc_mux->session[session_id]; + +/* Go to next handle rr_next_session overflow */ + ipc_mux->rr_next_session++; +if (ipc_mux->rr_next_session >= ipc_mux->nr_sessions) + ipc_mux->rr_next_session =0 ; + +if (!session->wwan || session->flow_ctl_mask || + session->net_tx_stop) +continue ; + + ul_list = &session->ul_list; + +/* Is something pending in UL and flow ctrl off */ + dg_n =skb_queue_len (ul_list); +if (dg_n >MUX_MAX_UL_DG_ENTRIES ) + dg_n =MUX_MAX_UL_DG_ENTRIES ; + +if (dg_n ==0 ) +/* Nothing to do for ipc_mux session +* -> try next session id. +*/ +continue ; + + updated =mux_ul_adgh_encode (ipc_mux, session_id, session, + ul_list, &ipc_mux->ul_adb, dg_n); + } + + ipc_mux->adb_prep_ongoing = false; +return updated ==1 ; +} + +void ipc_mux_ul_encoded_process (struct iosm_mux *ipc_mux,struct sk_buff *skb) +{ +struct mux_adgh *adgh; +u16 adgh_len; + + adgh = (struct mux_adgh *)skb->data; + adgh_len =le16_to_cpu (adgh->length); + +if (adgh->signature ==cpu_to_le32 (MUX_SIG_ADGH ) && + ipc_mux->ul_flow ==MUX_UL ) + ipc_mux->ul_data_pend_bytes = ipc_mux->ul_data_pend_bytes - + adgh_len; + +if (ipc_mux->ul_flow ==MUX_UL ) +dev_dbg (ipc_mux->dev,"ul_data_pend_bytes: %lld" , + ipc_mux->ul_data_pend_bytes); + +/* Reset the skb settings. */ + skb->tail =0 ; + skb->len =0 ; + +/* Add the consumed ADB to the free list. */ +skb_queue_tail ((&ipc_mux->ul_adb.free_list), skb); +} + +/* Start the NETIF uplink send transfer in MUX mode. */ +static int mux_tq_ul_trigger_encode (struct iosm_imem *ipc_imem,int arg, +void *msg,size_t size) +{ +struct iosm_mux *ipc_mux = ipc_imem->mux; +bool ul_data_pend = false; + +/* Add session UL data to a ADB and ADGH */ + ul_data_pend =ipc_mux_ul_data_encode (ipc_mux); +if (ul_data_pend) +/* Delay the doorbell irq */ +imem_td_update_timer_start (ipc_mux->imem); + +/* reset the debounce flag */ + ipc_mux->ev_mux_net_transmit_pending = false; + +return 0 ; +} + +int ipc_mux_ul_trigger_encode (struct iosm_mux *ipc_mux,int if_id, +struct sk_buff *skb) +{ +struct mux_session *session = &ipc_mux->session[if_id]; +int ret = -EINVAL ; + +if (ipc_mux->channel && + ipc_mux->channel->state !=IMEM_CHANNEL_ACTIVE ) { +dev_err (ipc_mux->dev, +"channel state is not IMEM_CHANNEL_ACTIVE" ); + goto out; + } + +if (!session->wwan) { +dev_err (ipc_mux->dev,"session net ID is NULL" ); + ret = -EFAULT ; + goto out; + } + +/* Session is under flow control. +* Check if packet can be queued in session list, if not +* suspend net tx +*/ +if (skb_queue_len (&session->ul_list) >= + (session->net_tx_stop ? +IPC_MEM_MUX_UL_SESS_FCON_THRESHOLD : + (IPC_MEM_MUX_UL_SESS_FCON_THRESHOLD * +IPC_MEM_MUX_UL_SESS_FCOFF_THRESHOLD_FACTOR ))) { +mux_netif_tx_flowctrl (session, session->if_id, true); + ret = -EBUSY ; + goto out; + } + +/* Add skb to the uplink skb accumulator. */ +skb_queue_tail (&session->ul_list, skb); + +/* Inform the IPC kthread to pass uplink IP packets to CP. */ +if (!ipc_mux->ev_mux_net_transmit_pending) { + ipc_mux->ev_mux_net_transmit_pending = true; + ret =ipc_task_queue_send_task (ipc_mux->imem, + mux_tq_ul_trigger_encode,0 , +NULL ,0 , false); +if (ret) + goto out; + } +dev_dbg (ipc_mux->dev,"mux ul if[%d] qlen=%d/%u, len=%d/%d, prio=%d" , + if_id,skb_queue_len (&session->ul_list), session->ul_list.qlen, + skb->len, skb->truesize, skb->priority); + ret =0 ; +out: +return ret; +}
drivers/net/wwan/iosm/iosm_ipc_mux_codec.h new file +193 -0
193 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 11/16 net: iosm: power management
In reply to M Chetan KumarImplements state machine to handle host & device sleep.
---
v2:
* Removed space around the : for the bitfields.
* Moved pm module under static allocation
* Added memory barriers around atomic operations.
--- drivers/net/wwan/iosm/iosm_ipc_pm.c | 333 ++++++++++++++++++++++++++++ drivers/net/wwan/iosm/iosm_ipc_pm.h | 207 +++++++++++++++++ 2 files changed, 540 insertions(+) create mode 100644 drivers/net/wwan/iosm/iosm_ipc_pm.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_pm.h
drivers/net/wwan/iosm/iosm_ipc_pm.c new file +333 -0
@@ -0,0 +1,333 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2020-21 Intel Corporation. +*/ + +#include "iosm_ipc_protocol.h" + +/* Timeout value in MS for the PM to wait for device to reach active state */ +#define IPC_PM_ACTIVE_TIMEOUT_MS (500) + +/* Note that here "active" has the value 1, as compared to the enums +* ipc_mem_host_pm_state or ipc_mem_dev_pm_state, where "active" is 0 +*/ +#define IPC_PM_SLEEP (0) +#define CONSUME_STATE (0) +#define IPC_PM_ACTIVE (1) + +void ipc_pm_signal_hpda_doorbell (struct iosm_pm *ipc_pm,u32 identifier, +bool host_slp_check) +{ +if (host_slp_check && ipc_pm->host_pm_state !=IPC_MEM_HOST_PM_ACTIVE && + ipc_pm->host_pm_state !=IPC_MEM_HOST_PM_ACTIVE_WAIT ) { + ipc_pm->pending_hpda_update = true; +dev_dbg (ipc_pm->dev, +"Pending HPDA update set. Host PM_State: %d identifier:%d" , + ipc_pm->host_pm_state, identifier); +return ; + } + +if (!ipc_pm_trigger (ipc_pm,IPC_PM_UNIT_IRQ , true)) { + ipc_pm->pending_hpda_update = true; +dev_dbg (ipc_pm->dev,"Pending HPDA update set. identifier:%d" , + identifier); +return ; + } + ipc_pm->pending_hpda_update = false; + +/* Trigger the irq towards CP */ +ipc_cp_irq_hpda_update (ipc_pm->pcie, identifier); + +ipc_pm_trigger (ipc_pm,IPC_PM_UNIT_IRQ , false); +} + +/* Wake up the device if it is in low power mode. */ +static bool ipc_pm_link_activate (struct iosm_pm *ipc_pm) +{ +if (ipc_pm->cp_state ==IPC_MEM_DEV_PM_ACTIVE ) +return true; + +if (ipc_pm->cp_state ==IPC_MEM_DEV_PM_SLEEP ) { +if (ipc_pm->ap_state ==IPC_MEM_DEV_PM_SLEEP ) { +/* Wake up the device. */ +ipc_cp_irq_sleep_control (ipc_pm->pcie, +IPC_MEM_DEV_PM_WAKEUP ); + ipc_pm->ap_state =IPC_MEM_DEV_PM_ACTIVE_WAIT ; + + goto not_active; + } + +if (ipc_pm->ap_state ==IPC_MEM_DEV_PM_ACTIVE_WAIT ) + goto not_active; + +return true; + } + +not_active: +/* link is not ready */ +return false; +} + +bool ipc_pm_wait_for_device_active (struct iosm_pm *ipc_pm) +{ +bool ret_val = false; + +if (ipc_pm->ap_state !=IPC_MEM_DEV_PM_ACTIVE ) { +/* Complete all memory stores before setting bit */ +smp_mb__before_atomic (); + +/* Wait for IPC_PM_ACTIVE_TIMEOUT_MS for Device sleep state +* machine to enter ACTIVE state. +*/ +set_bit (0 , &ipc_pm->host_sleep_pend); + +/* Complete all memory stores after setting bit */ +smp_mb__after_atomic (); + +if (!wait_for_completion_interruptible_timeout + (&ipc_pm->host_sleep_complete, +msecs_to_jiffies (IPC_PM_ACTIVE_TIMEOUT_MS ))) { +dev_err (ipc_pm->dev, +"PM timeout. Expected State:%d. Actual: %d" , +IPC_MEM_DEV_PM_ACTIVE , ipc_pm->ap_state); + goto active_timeout; + } + } + + ret_val = true; +active_timeout: +/* Complete all memory stores before clearing bit */ +smp_mb__before_atomic (); + +/* Reset the atomic variable in any case as device sleep +* state machine change is no longer of interest. +*/ +clear_bit (0 , &ipc_pm->host_sleep_pend); + +/* Complete all memory stores after clearing bit */ +smp_mb__after_atomic (); + +return ret_val; +} + +static void ipc_pm_on_link_sleep (struct iosm_pm *ipc_pm) +{ +/* pending sleep ack and all conditions are cleared +* -> signal SLEEP__ACK to CP +*/ + ipc_pm->cp_state =IPC_MEM_DEV_PM_SLEEP ; + ipc_pm->ap_state =IPC_MEM_DEV_PM_SLEEP ; + +ipc_cp_irq_sleep_control (ipc_pm->pcie,IPC_MEM_DEV_PM_SLEEP ); +} + +static void ipc_pm_on_link_wake (struct iosm_pm *ipc_pm,bool ack) +{ + ipc_pm->ap_state =IPC_MEM_DEV_PM_ACTIVE ; + +if (ack) { + ipc_pm->cp_state =IPC_MEM_DEV_PM_ACTIVE ; + +ipc_cp_irq_sleep_control (ipc_pm->pcie,IPC_MEM_DEV_PM_ACTIVE ); + +/* check the consume state !!! */ +if (test_bit (CONSUME_STATE , &ipc_pm->host_sleep_pend)) +complete (&ipc_pm->host_sleep_complete); + } + +/* Check for pending HPDA update. +* Pending HP update could be because of sending message was +* put on hold due to Device sleep state or due to TD update +* which could be because of Device Sleep and Host Sleep +* states. +*/ +if (ipc_pm->pending_hpda_update && + ipc_pm->host_pm_state ==IPC_MEM_HOST_PM_ACTIVE ) +ipc_pm_signal_hpda_doorbell (ipc_pm,IPC_HP_PM_TRIGGER , true); +} + +bool ipc_pm_trigger (struct iosm_pm *ipc_pm,enum ipc_pm_unit unit,bool active) +{ +union ipc_pm_cond old_cond; +union ipc_pm_cond new_cond; +bool link_active; + +/* Save the current D3 state. */ + new_cond = ipc_pm->pm_cond; + old_cond = ipc_pm->pm_cond; + +/* Calculate the power state only in the runtime phase. */ +switch (unit) { +case IPC_PM_UNIT_IRQ :/* CP irq */ + new_cond.irq = active; +break ; + +case IPC_PM_UNIT_LINK :/* Device link state. */ + new_cond.link = active; +break ; + +case IPC_PM_UNIT_HS :/* Host sleep trigger requires Link. */ + new_cond.hs = active; +break ; + +default : +break ; + } + +/* Something changed ? */ +if (old_cond.raw == new_cond.raw) { +/* Stay in the current PM state. */ + link_active = old_cond.link ==IPC_PM_ACTIVE ; + goto ret; + } + + ipc_pm->pm_cond = new_cond; + +if (new_cond.link) +ipc_pm_on_link_wake (ipc_pm, unit ==IPC_PM_UNIT_LINK ); +else if (unit ==IPC_PM_UNIT_LINK ) +ipc_pm_on_link_sleep (ipc_pm); + +if (old_cond.link ==IPC_PM_SLEEP && new_cond.raw) { + link_active =ipc_pm_link_activate (ipc_pm); + goto ret; + } + + link_active = old_cond.link ==IPC_PM_ACTIVE ; + +ret: +return link_active; +} + +bool ipc_pm_prepare_host_sleep (struct iosm_pm *ipc_pm) +{ +/* suspend not allowed if host_pm_state is not IPC_MEM_HOST_PM_ACTIVE */ +if (ipc_pm->host_pm_state !=IPC_MEM_HOST_PM_ACTIVE ) { +dev_err (ipc_pm->dev,"host_pm_state=%d\tExpected to be: %d" , + ipc_pm->host_pm_state,IPC_MEM_HOST_PM_ACTIVE ); +return false; + } + + ipc_pm->host_pm_state =IPC_MEM_HOST_PM_SLEEP_WAIT_D3 ; + +return true; +} + +bool ipc_pm_prepare_host_active (struct iosm_pm *ipc_pm) +{ +if (ipc_pm->host_pm_state !=IPC_MEM_HOST_PM_SLEEP ) { +dev_err (ipc_pm->dev,"host_pm_state=%d\tExpected to be: %d" , + ipc_pm->host_pm_state,IPC_MEM_HOST_PM_SLEEP ); +return false; + } + +/* Sending Sleep Exit message to CP. Update the state */ + ipc_pm->host_pm_state =IPC_MEM_HOST_PM_ACTIVE_WAIT ; + +return true; +} + +void ipc_pm_set_s2idle_sleep (struct iosm_pm *ipc_pm,bool sleep) +{ +if (sleep) { + ipc_pm->ap_state =IPC_MEM_DEV_PM_SLEEP ; + ipc_pm->cp_state =IPC_MEM_DEV_PM_SLEEP ; + ipc_pm->device_sleep_notification =IPC_MEM_DEV_PM_SLEEP ; + }else { + ipc_pm->ap_state =IPC_MEM_DEV_PM_ACTIVE ; + ipc_pm->cp_state =IPC_MEM_DEV_PM_ACTIVE ; + ipc_pm->device_sleep_notification =IPC_MEM_DEV_PM_ACTIVE ; + ipc_pm->pm_cond.link =IPC_PM_ACTIVE ; + } +} + +bool ipc_pm_dev_slp_notification (struct iosm_pm *ipc_pm,u32 cp_pm_req) +{ +if (cp_pm_req == ipc_pm->device_sleep_notification) +return false; + + ipc_pm->device_sleep_notification = cp_pm_req; + +/* Evaluate the PM request. */ +switch (ipc_pm->cp_state) { +case IPC_MEM_DEV_PM_ACTIVE : +switch (cp_pm_req) { +case IPC_MEM_DEV_PM_ACTIVE : +break ; + +case IPC_MEM_DEV_PM_SLEEP : +/* Inform the PM that the device link can go down. */ +ipc_pm_trigger (ipc_pm,IPC_PM_UNIT_LINK , false); +return true; + +default : +dev_err (ipc_pm->dev, +"loc-pm=%d active: confused req-pm=%d" , + ipc_pm->cp_state, cp_pm_req); +break ; + } +break ; + +case IPC_MEM_DEV_PM_SLEEP : +switch (cp_pm_req) { +case IPC_MEM_DEV_PM_ACTIVE : +/* Inform the PM that the device link is active. */ +ipc_pm_trigger (ipc_pm,IPC_PM_UNIT_LINK , true); +break ; + +case IPC_MEM_DEV_PM_SLEEP : +break ; + +default : +dev_err (ipc_pm->dev, +"loc-pm=%d sleep: confused req-pm=%d" , + ipc_pm->cp_state, cp_pm_req); +break ; + } +break ; + +default : +dev_err (ipc_pm->dev,"confused loc-pm=%d, req-pm=%d" , + ipc_pm->cp_state, cp_pm_req); +break ; + } + +return false; +} + +void ipc_pm_init (struct iosm_protocol *ipc_protocol) +{ +struct iosm_imem *ipc_imem = ipc_protocol->imem; +struct iosm_pm *ipc_pm = &ipc_protocol->pm; + + ipc_pm->pcie = ipc_imem->pcie; + ipc_pm->dev = ipc_imem->dev; + + ipc_pm->pm_cond.irq =IPC_PM_SLEEP ; + ipc_pm->pm_cond.hs =IPC_PM_SLEEP ; + ipc_pm->pm_cond.link =IPC_PM_ACTIVE ; + + ipc_pm->cp_state =IPC_MEM_DEV_PM_ACTIVE ; + ipc_pm->ap_state =IPC_MEM_DEV_PM_ACTIVE ; + ipc_pm->host_pm_state =IPC_MEM_HOST_PM_ACTIVE ; + +/* Create generic wait-for-completion handler for Host Sleep +* and device sleep coordination. +*/ +init_completion (&ipc_pm->host_sleep_complete); + +/* Complete all memory stores before clearing bit */ +smp_mb__before_atomic (); + +clear_bit (0 , &ipc_pm->host_sleep_pend); + +/* Complete all memory stores after clearing bit */ +smp_mb__after_atomic (); +} + +void ipc_pm_deinit (struct iosm_protocol *proto) +{ +struct iosm_pm *ipc_pm = &proto->pm; + +complete (&ipc_pm->host_sleep_complete); +}
drivers/net/wwan/iosm/iosm_ipc_pm.h new file +207 -0
207 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 12/16 net: iosm: shared memory protocol
In reply to M Chetan Kumar1) Defines messaging protocol for handling Transfer Descriptor in both UL/DL direction.
2) Ring buffer management.
---
v2:
* Endianness type correction for Host-device protocol structure.
* Function signature documentation correction.
* Streamline multiple returns using goto.
--- drivers/net/wwan/iosm/iosm_ipc_protocol.c | 283 ++++++++++++++++++++++ drivers/net/wwan/iosm/iosm_ipc_protocol.h | 237 ++++++++++++++++++ 2 files changed, 520 insertions(+) create mode 100644 drivers/net/wwan/iosm/iosm_ipc_protocol.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_protocol.h
drivers/net/wwan/iosm/iosm_ipc_protocol.c new file +283 -0
@@ -0,0 +1,283 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2020-21 Intel Corporation. +*/ + +#include "iosm_ipc_imem.h" +#include "iosm_ipc_protocol.h" +#include "iosm_ipc_protocol_ops.h" +#include "iosm_ipc_pm.h" +#include "iosm_ipc_task_queue.h" + +int ipc_protocol_tq_msg_send (struct iosm_protocol *ipc_protocol, +enum ipc_msg_prep_type msg_type, +union ipc_msg_prep_args *prep_args, +struct ipc_rsp *response) +{ +int index =ipc_protocol_msg_prep (ipc_protocol->imem, msg_type, + prep_args); + +/* Store reference towards caller specified response in response ring +* and signal CP +*/ +if (index >=0 && index <IPC_MEM_MSG_ENTRIES ) { + ipc_protocol->rsp_ring[index] = response; +ipc_protocol_msg_hp_update (ipc_protocol->imem); + } + +return index; +} + +/* Callback for message send */ +static int ipc_protocol_tq_msg_send_cb (struct iosm_imem *ipc_imem,int arg, +void *msg,size_t size) +{ +struct ipc_call_msg_send_args *send_args = msg; +struct iosm_protocol *ipc_protocol = ipc_imem->ipc_protocol; + +return ipc_protocol_tq_msg_send (ipc_protocol, send_args->msg_type, + send_args->prep_args, + send_args->response); +} + +/* Remove reference to a response. This is typically used when a requestor timed +* out and is no longer interested in the response. +*/ +static int ipc_protocol_tq_msg_remove (struct iosm_imem *ipc_imem,int arg, +void *msg,size_t size) +{ +struct iosm_protocol *ipc_protocol = ipc_imem->ipc_protocol; + + ipc_protocol->rsp_ring[arg] =NULL ; +return 0 ; +} + +int ipc_protocol_msg_send (struct iosm_protocol *ipc_protocol, +enum ipc_msg_prep_type prep, +union ipc_msg_prep_args *prep_args) +{ +struct ipc_call_msg_send_args send_args; +unsigned int exec_timeout; +struct ipc_rsp response; +int index; + + exec_timeout = (ipc_protocol_get_ap_exec_stage (ipc_protocol) == +IPC_MEM_EXEC_STAGE_RUN ? +IPC_MSG_COMPLETE_RUN_DEFAULT_TIMEOUT : +IPC_MSG_COMPLETE_BOOT_DEFAULT_TIMEOUT ); + +/* Trap if called from non-preemptible context */ +might_sleep (); + + response.status =IPC_MEM_MSG_CS_INVALID ; +init_completion (&response.completion); + + send_args.msg_type = prep; + send_args.prep_args = prep_args; + send_args.response = &response; + +/* Allocate and prepare message to be sent in tasklet context. +* A positive index returned form tasklet_call references the message +* in case it needs to be cancelled when there is a timeout. +*/ + index =ipc_task_queue_send_task (ipc_protocol->imem, + ipc_protocol_tq_msg_send_cb,0 , + &send_args,0 , true); + +if (index <0 ) { +dev_err (ipc_protocol->dev,"msg %d failed" , prep); +return index; + } + +/* Wait for the device to respond to the message */ +switch (wait_for_completion_timeout (&response.completion, +msecs_to_jiffies (exec_timeout))) { +case 0 : +/* Timeout, there was no response from the device. +* Remove the reference to the local response completion +* object as we are no longer interested in the response. +*/ +ipc_task_queue_send_task (ipc_protocol->imem, + ipc_protocol_tq_msg_remove, index, +NULL ,0 , true); +dev_err (ipc_protocol->dev,"msg timeout" ); +ipc_uevent_send (ipc_protocol->pcie->dev,UEVENT_MDM_TIMEOUT ); +break ; +default : +/* We got a response in time; check completion status: */ +if (response.status !=IPC_MEM_MSG_CS_SUCCESS ) { +dev_err (ipc_protocol->dev, +"msg completion status error %d" , + response.status); +return -EIO ; + } + } + +return 0 ; +} + +static int ipc_protocol_msg_send_host_sleep (struct iosm_protocol *ipc_protocol, +u32 state) +{ +union ipc_msg_prep_args prep_args = { + .sleep.target =0 , + .sleep.state = state, + }; + +return ipc_protocol_msg_send (ipc_protocol,IPC_MSG_PREP_SLEEP , + &prep_args); +} + +void ipc_protocol_doorbell_trigger (struct iosm_protocol *ipc_protocol, +u32 identifier) +{ +ipc_pm_signal_hpda_doorbell (&ipc_protocol->pm, identifier, true); +} + +bool ipc_protocol_pm_dev_sleep_handle (struct iosm_protocol *ipc_protocol) +{ +u32 ipc_status =ipc_protocol_get_ipc_status (ipc_protocol); +u32 requested; + +if (ipc_status !=IPC_MEM_DEVICE_IPC_RUNNING ) { +dev_err (ipc_protocol->dev, +"irq ignored, CP IPC state is %d, should be RUNNING" , + ipc_status); + +/* Stop further processing. */ +return false; + } + +/* Get a copy of the requested PM state by the device and the local +* device PM state. +*/ + requested =ipc_protocol_pm_dev_get_sleep_notification (ipc_protocol); + +return ipc_pm_dev_slp_notification (&ipc_protocol->pm, requested); +} + +static int ipc_protocol_tq_wakeup_dev_slp (struct iosm_imem *ipc_imem,int arg, +void *msg,size_t size) +{ +struct iosm_pm *ipc_pm = &ipc_imem->ipc_protocol->pm; + +/* Wakeup from device sleep if it is not ACTIVE */ +ipc_pm_trigger (ipc_pm,IPC_PM_UNIT_HS , true); + +ipc_pm_trigger (ipc_pm,IPC_PM_UNIT_HS , false); + +return 0 ; +} + +void ipc_protocol_s2idle_sleep (struct iosm_protocol *ipc_protocol,bool sleep) +{ +ipc_pm_set_s2idle_sleep (&ipc_protocol->pm, sleep); +} + +bool ipc_protocol_suspend (struct iosm_protocol *ipc_protocol) +{ +if (!ipc_pm_prepare_host_sleep (&ipc_protocol->pm)) + goto err; + +ipc_task_queue_send_task (ipc_protocol->imem, + ipc_protocol_tq_wakeup_dev_slp,0 ,NULL ,0 , + true); + +if (!ipc_pm_wait_for_device_active (&ipc_protocol->pm)) { +ipc_uevent_send (ipc_protocol->pcie->dev,UEVENT_MDM_TIMEOUT ); + goto err; + } + +/* Send the sleep message for sync sys calls. */ +dev_dbg (ipc_protocol->dev,"send TARGET_HOST, ENTER_SLEEP" ); +if (ipc_protocol_msg_send_host_sleep (ipc_protocol, +IPC_HOST_SLEEP_ENTER_SLEEP )) { +/* Sending ENTER_SLEEP message failed, we are still active */ + ipc_protocol->pm.host_pm_state =IPC_MEM_HOST_PM_ACTIVE ; + goto err; + } + + ipc_protocol->pm.host_pm_state =IPC_MEM_HOST_PM_SLEEP ; +return true; +err: +return false; +} + +bool ipc_protocol_resume (struct iosm_protocol *ipc_protocol) +{ +if (!ipc_pm_prepare_host_active (&ipc_protocol->pm)) +return false; + +dev_dbg (ipc_protocol->dev,"send TARGET_HOST, EXIT_SLEEP" ); +if (ipc_protocol_msg_send_host_sleep (ipc_protocol, +IPC_HOST_SLEEP_EXIT_SLEEP )) { + ipc_protocol->pm.host_pm_state =IPC_MEM_HOST_PM_SLEEP ; +return false; + } + + ipc_protocol->pm.host_pm_state =IPC_MEM_HOST_PM_ACTIVE ; + +return true; +} + +struct iosm_protocol *ipc_protocol_init (struct iosm_imem *ipc_imem) +{ +struct iosm_protocol *ipc_protocol = +kzalloc (sizeof (*ipc_protocol),GFP_KERNEL ); +struct ipc_protocol_context_info *p_ci; +u64 addr; + +if (!ipc_protocol) +return NULL ; + + ipc_protocol->dev = ipc_imem->dev; + ipc_protocol->pcie = ipc_imem->pcie; + ipc_protocol->imem = ipc_imem; + ipc_protocol->p_ap_shm =NULL ; + ipc_protocol->phy_ap_shm =0 ; + + ipc_protocol->old_msg_tail =0 ; + + ipc_protocol->p_ap_shm = +pci_alloc_consistent (ipc_protocol->pcie->pci, +sizeof (*ipc_protocol->p_ap_shm), + &ipc_protocol->phy_ap_shm); + +if (!ipc_protocol->p_ap_shm) { +dev_err (ipc_protocol->dev,"pci shm alloc error" ); +kfree (ipc_protocol); +return NULL ; + } + +/* Prepare the context info for CP. */ + addr = ipc_protocol->phy_ap_shm; + p_ci = &ipc_protocol->p_ap_shm->ci; + p_ci->device_info_addr = + addr + offsetof(struct ipc_protocol_ap_shm , device_info); + p_ci->head_array = + addr + offsetof(struct ipc_protocol_ap_shm , head_array); + p_ci->tail_array = + addr + offsetof(struct ipc_protocol_ap_shm , tail_array); + p_ci->msg_head = addr + offsetof(struct ipc_protocol_ap_shm , msg_head); + p_ci->msg_tail = addr + offsetof(struct ipc_protocol_ap_shm , msg_tail); + p_ci->msg_ring_addr = + addr + offsetof(struct ipc_protocol_ap_shm , msg_ring); + p_ci->msg_ring_entries =cpu_to_le16 (IPC_MEM_MSG_ENTRIES ); + p_ci->msg_irq_vector =IPC_MSG_IRQ_VECTOR ; + p_ci->device_info_irq_vector =IPC_DEVICE_IRQ_VECTOR ; + +ipc_mmio_set_contex_info_addr (ipc_imem->mmio, addr); + +ipc_pm_init (ipc_protocol); + +return ipc_protocol; +} + +void ipc_protocol_deinit (struct iosm_protocol *proto) +{ +pci_free_consistent (proto->pcie->pci,sizeof (*proto->p_ap_shm), + proto->p_ap_shm, proto->phy_ap_shm); + +ipc_pm_deinit (proto); +kfree (proto); +}
drivers/net/wwan/iosm/iosm_ipc_protocol.h new file +237 -0
237 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 13/16 net: iosm: protocol operations
In reply to M Chetan Kumar1) Update UL/DL transfer descriptors in message ring.
2) Define message set for pipe/sleep protocol.
---
v2:
* Endianness type correction for Host-Device protocol structure.
* Function signature documentation correction.
* Streamline multiple returns using goto.
--- drivers/net/wwan/iosm/iosm_ipc_protocol_ops.c | 552 ++++++++++++++++++ drivers/net/wwan/iosm/iosm_ipc_protocol_ops.h | 444 ++++++++++++++ 2 files changed, 996 insertions(+) create mode 100644 drivers/net/wwan/iosm/iosm_ipc_protocol_ops.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_protocol_ops.h
drivers/net/wwan/iosm/iosm_ipc_protocol_ops.c new file +552 -0
@@ -0,0 +1,552 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2020-21 Intel Corporation. +*/ + +#include "iosm_ipc_protocol.h" +#include "iosm_ipc_protocol_ops.h" + +/* Get the next free message element.*/ +static union ipc_mem_msg_entry * +ipc_protocol_free_msg_get (struct iosm_protocol *ipc_protocol,int *index) +{ +u32 head =le32_to_cpu (ipc_protocol->p_ap_shm->msg_head); +u32 new_head = (head +1 ) %IPC_MEM_MSG_ENTRIES ; +union ipc_mem_msg_entry *msg; + +if (new_head ==le32_to_cpu (ipc_protocol->p_ap_shm->msg_tail)) { +dev_err (ipc_protocol->dev,"message ring is full" ); +return NULL ; + } + +/* Get the pointer to the next free message element, +* reset the fields and mark is as invalid. +*/ + msg = &ipc_protocol->p_ap_shm->msg_ring[head]; +memset (msg,0 ,sizeof (*msg)); + +/* return index in message ring */ + *index = head; + +return msg; +} + +/* Updates the message ring Head pointer */ +void ipc_protocol_msg_hp_update (struct iosm_imem *ipc_imem) +{ +struct iosm_protocol *ipc_protocol = ipc_imem->ipc_protocol; +u32 head =le32_to_cpu (ipc_protocol->p_ap_shm->msg_head); +u32 new_head = (head +1 ) %IPC_MEM_MSG_ENTRIES ; + +/* Update head pointer and fire doorbell. */ + ipc_protocol->p_ap_shm->msg_head =cpu_to_le32 (new_head); + ipc_protocol->old_msg_tail = +le32_to_cpu (ipc_protocol->p_ap_shm->msg_tail); + +ipc_pm_signal_hpda_doorbell (&ipc_protocol->pm,IPC_HP_MR , false); +} + +/* Allocate and prepare a OPEN_PIPE message. +* This also allocates the memory for the new TDR structure and +* updates the pipe structure referenced in the preparation arguments. +*/ +static int ipc_protocol_msg_prepipe_open (struct iosm_protocol *ipc_protocol, +union ipc_msg_prep_args *args) +{ +int index; +union ipc_mem_msg_entry *msg = +ipc_protocol_free_msg_get (ipc_protocol, &index); +struct ipc_pipe *pipe = args->pipe_open.pipe; +struct ipc_protocol_td *tdr; +struct sk_buff **skbr; + +if (!msg) { +dev_err (ipc_protocol->dev,"failed to get free message" ); +return -EIO ; + } + +/* Allocate the skbuf elements for the skbuf which are on the way. +* SKB ring is internal memory allocation for driver. No need to +* re-calculate the start and end addresses. +*/ + skbr =kcalloc (pipe->nr_of_entries,sizeof (*skbr),GFP_ATOMIC ); +if (!skbr) +return -ENOMEM ; + +/* Allocate the transfer descriptors for the pipe. */ + tdr =pci_alloc_consistent (ipc_protocol->pcie->pci, + pipe->nr_of_entries *sizeof (*tdr), + &pipe->phy_tdr_start); +if (!tdr) { +kfree (skbr); +dev_err (ipc_protocol->dev,"tdr alloc error" ); +return -ENOMEM ; + } + + pipe->max_nr_of_queued_entries = pipe->nr_of_entries -1 ; + pipe->nr_of_queued_entries =0 ; + pipe->tdr_start = tdr; + pipe->skbr_start = skbr; + pipe->old_tail =0 ; + + ipc_protocol->p_ap_shm->head_array[pipe->pipe_nr] =0 ; + + msg->open_pipe.type_of_message =IPC_MEM_MSG_OPEN_PIPE ; + msg->open_pipe.pipe_nr = pipe->pipe_nr; + msg->open_pipe.tdr_addr =cpu_to_le64 (pipe->phy_tdr_start); + msg->open_pipe.tdr_entries =cpu_to_le16 (pipe->nr_of_entries); + msg->open_pipe.accumulation_backoff =cpu_to_le32 (pipe->accumulation_backoff); + msg->open_pipe.irq_vector =cpu_to_le32 (pipe->irq); + +return index; +} + +static int ipc_protocol_msg_prepipe_close (struct iosm_protocol *ipc_protocol, +union ipc_msg_prep_args *args) +{ +int index =-1 ; +union ipc_mem_msg_entry *msg = +ipc_protocol_free_msg_get (ipc_protocol, &index); +struct ipc_pipe *pipe = args->pipe_close.pipe; + +if (!msg) +return -EIO ; + + msg->close_pipe.type_of_message =IPC_MEM_MSG_CLOSE_PIPE ; + msg->close_pipe.pipe_nr = pipe->pipe_nr; + +dev_dbg (ipc_protocol->dev,"IPC_MEM_MSG_CLOSE_PIPE(pipe_nr=%d)" , + msg->close_pipe.pipe_nr); + +return index; +} + +static int ipc_protocol_msg_prep_sleep (struct iosm_protocol *ipc_protocol, +union ipc_msg_prep_args *args) +{ +int index =-1 ; +union ipc_mem_msg_entry *msg = +ipc_protocol_free_msg_get (ipc_protocol, &index); + +if (!msg) { +dev_err (ipc_protocol->dev,"failed to get free message" ); +return -EIO ; + } + +/* Prepare and send the host sleep message to CP to enter or exit D3. */ + msg->host_sleep.type_of_message =IPC_MEM_MSG_SLEEP ; + msg->host_sleep.target = args->sleep.target;/* 0=host, 1=device */ + +/* state; 0=enter, 1=exit 2=enter w/o protocol */ + msg->host_sleep.state = args->sleep.state; + +dev_dbg (ipc_protocol->dev,"IPC_MEM_MSG_SLEEP(target=%d; state=%d)" , + msg->host_sleep.target, msg->host_sleep.state); + +return index; +} + +static int ipc_protocol_msg_prep_feature_set (struct iosm_protocol *ipc_protocol, +union ipc_msg_prep_args *args) +{ +int index =-1 ; +union ipc_mem_msg_entry *msg = +ipc_protocol_free_msg_get (ipc_protocol, &index); + +if (!msg) { +dev_err (ipc_protocol->dev,"failed to get free message" ); +return -EIO ; + } + + msg->feature_set.type_of_message =IPC_MEM_MSG_FEATURE_SET ; + msg->feature_set.reset_enable = args->feature_set.reset_enable; + +dev_dbg (ipc_protocol->dev,"IPC_MEM_MSG_FEATURE_SET(reset_enable=%d)" , + msg->feature_set.reset_enable); + +return index; +} + +/* Processes the message consumed by CP. */ +bool ipc_protocol_msg_process (struct iosm_imem *ipc_imem,int irq) +{ +struct iosm_protocol *ipc_protocol = ipc_imem->ipc_protocol; +struct ipc_rsp **rsp_ring = ipc_protocol->rsp_ring; +bool msg_processed = false; +u32 i; + +if (le32_to_cpu (ipc_protocol->p_ap_shm->msg_tail) >= +IPC_MEM_MSG_ENTRIES ) { +dev_err (ipc_protocol->dev,"msg_tail out of range: %d" , +le32_to_cpu (ipc_protocol->p_ap_shm->msg_tail)); +return msg_processed; + } + +if (irq !=IMEM_IRQ_DONT_CARE && + irq != ipc_protocol->p_ap_shm->ci.msg_irq_vector) +return msg_processed; + +for (i = ipc_protocol->old_msg_tail; + i !=le32_to_cpu (ipc_protocol->p_ap_shm->msg_tail); + i = (i +1 ) %IPC_MEM_MSG_ENTRIES ) { +union ipc_mem_msg_entry *msg = + &ipc_protocol->p_ap_shm->msg_ring[i]; + +dev_dbg (ipc_protocol->dev,"msg[%d]: type=%u status=%d" , i, + msg->common.type_of_message, + msg->common.completion_status); + +/* Update response with status and wake up waiting requestor */ +if (rsp_ring[i]) { + rsp_ring[i]->status = +le32_to_cpu (msg->common.completion_status); +complete (&rsp_ring[i]->completion); + rsp_ring[i] =NULL ; + } + msg_processed = true; + } + + ipc_protocol->old_msg_tail = i; +return msg_processed; +} + +/* Sends data from UL list to CP for the provided pipe by updating the Head +* pointer of given pipe. +*/ +bool ipc_protocol_ul_td_send (struct iosm_protocol *ipc_protocol, +struct ipc_pipe *pipe, +struct sk_buff_head *p_ul_list) +{ +struct ipc_protocol_td *td; +bool hpda_pending = false; +struct sk_buff *skb; +s32 free_elements; +u32 head; +u32 tail; + +if (!ipc_protocol->p_ap_shm) { +dev_err (ipc_protocol->dev,"driver is not initialized" ); +return false; + } + +/* Get head and tail of the td list and calculate +* the number of free elements. +*/ + head =le32_to_cpu (ipc_protocol->p_ap_shm->head_array[pipe->pipe_nr]); + tail = pipe->old_tail; + +while (!skb_queue_empty (p_ul_list)) { +if (head < tail) + free_elements = tail - head -1 ; +else + free_elements = + pipe->nr_of_entries - head + ((s32 )tail -1 ); + +if (free_elements <=0 ) { +dev_dbg (ipc_protocol->dev, +"no free td elements for UL pipe %d" , + pipe->pipe_nr); +break ; + } + +/* Get the td address. */ + td = &pipe->tdr_start[head]; + +/* Take the first element of the uplink list and add it +* to the td list. +*/ + skb =skb_dequeue (p_ul_list); +if (WARN_ON (!skb)) +break ; + +/* Save the reference to the uplink skbuf. */ + pipe->skbr_start[head] = skb; + + td->buffer.address =IPC_CB (skb)->mapping; + td->scs.size = skb->len; + td->scs.completion_status =0 ; + td->next =0 ; + td->reserved1 =0 ; + + pipe->nr_of_queued_entries++; + +/* Calculate the new head and save it. */ + head++; +if (head >= pipe->nr_of_entries) + head =0 ; + + ipc_protocol->p_ap_shm->head_array[pipe->pipe_nr] = +cpu_to_le32 (head); + } + +if (pipe->old_head != head) { +dev_dbg (ipc_protocol->dev,"New UL TDs Pipe:%d" , pipe->pipe_nr); + + pipe->old_head = head; +/* Trigger doorbell because of pending UL packets. */ + hpda_pending = true; + } + +return hpda_pending; +} + +/* Checks for Tail pointer update from CP and returns the data as SKB. */ +struct sk_buff *ipc_protocol_ul_td_process (struct iosm_protocol *ipc_protocol, +struct ipc_pipe *pipe) +{ +struct ipc_protocol_td *p_td = &pipe->tdr_start[pipe->old_tail]; +struct sk_buff *skb = pipe->skbr_start[pipe->old_tail]; + + pipe->nr_of_queued_entries--; + pipe->old_tail++; +if (pipe->old_tail >= pipe->nr_of_entries) + pipe->old_tail =0 ; + +if (!p_td->buffer.address) { +dev_err (ipc_protocol->dev,"Td buffer address is NULL" ); +return NULL ; + } + +if (p_td->buffer.address !=IPC_CB (skb)->mapping) { +dev_err (ipc_protocol->dev, +"pipe %d: invalid buf_addr or skb_data" , + pipe->pipe_nr); +return NULL ; + } + +return skb; +} + +/* Allocates an SKB for CP to send data and updates the Head Pointer +* of the given Pipe#. +*/ +bool ipc_protocol_dl_td_prepare (struct iosm_protocol *ipc_protocol, +struct ipc_pipe *pipe) +{ +struct ipc_protocol_td *td; +dma_addr_t mapping =0 ; +u32 head, new_head; +struct sk_buff *skb; +u32 tail; + +/* Get head and tail of the td list and calculate +* the number of free elements. +*/ + head =le32_to_cpu (ipc_protocol->p_ap_shm->head_array[pipe->pipe_nr]); + tail =le32_to_cpu (ipc_protocol->p_ap_shm->tail_array[pipe->pipe_nr]); + + new_head = head +1 ; +if (new_head >= pipe->nr_of_entries) + new_head =0 ; + +if (new_head == tail) +return false; + +/* Get the td address. */ + td = &pipe->tdr_start[head]; + +/* Allocate the skbuf for the descriptor. */ + skb =ipc_pcie_alloc_skb (ipc_protocol->pcie, pipe->buf_size,GFP_ATOMIC , + &mapping,DMA_FROM_DEVICE , +IPC_MEM_DL_ETH_OFFSET ); +if (!skb) +return false; + + td->buffer.address = mapping; + td->scs.size = pipe->buf_size; + td->scs.completion_status =0 ; + td->next =0 ; + td->reserved1 =0 ; + +/* store the new head value. */ + ipc_protocol->p_ap_shm->head_array[pipe->pipe_nr] = +cpu_to_le32 (new_head); + +/* Save the reference to the skbuf. */ + pipe->skbr_start[head] = skb; + + pipe->nr_of_queued_entries++; + +return true; +} + +/* Processes DL TD's */ +struct sk_buff *ipc_protocol_dl_td_process (struct iosm_protocol *ipc_protocol, +struct ipc_pipe *pipe) +{ +u32 tail = +le32_to_cpu (ipc_protocol->p_ap_shm->tail_array[pipe->pipe_nr]); +struct ipc_protocol_td *p_td; +struct sk_buff *skb; + +if (!pipe->tdr_start) +return NULL ; + +/* Copy the reference to the downlink buffer. */ + p_td = &pipe->tdr_start[pipe->old_tail]; + skb = pipe->skbr_start[pipe->old_tail]; + +/* Reset the ring elements. */ + pipe->skbr_start[pipe->old_tail] =NULL ; + + pipe->nr_of_queued_entries--; + + pipe->old_tail++; +if (pipe->old_tail >= pipe->nr_of_entries) + pipe->old_tail =0 ; + +if (!skb) { +dev_err (ipc_protocol->dev,"skb is null" ); + goto ret; + }else if (!p_td->buffer.address) { +dev_err (ipc_protocol->dev,"td/buffer address is null" ); +ipc_pcie_kfree_skb (ipc_protocol->pcie, skb); + skb =NULL ; + goto ret; + } + +if (!IPC_CB (skb)) { +dev_err (ipc_protocol->dev,"pipe# %d, tail: %d skb_cb is NULL" , + pipe->pipe_nr, tail); +ipc_pcie_kfree_skb (ipc_protocol->pcie, skb); + skb =NULL ; + goto ret; + } + +if (p_td->buffer.address !=IPC_CB (skb)->mapping) { +dev_err (ipc_protocol->dev,"invalid buf=%p or skb=%p" , + (void *)p_td->buffer.address, skb->data); +ipc_pcie_kfree_skb (ipc_protocol->pcie, skb); + skb =NULL ; + goto ret; + }else if (p_td->scs.size > pipe->buf_size) { +dev_err (ipc_protocol->dev,"invalid buffer size %d > %d" , + p_td->scs.size, pipe->buf_size); +ipc_pcie_kfree_skb (ipc_protocol->pcie, skb); + skb =NULL ; + goto ret; + }else if (p_td->scs.completion_status ==IPC_MEM_TD_CS_ABORT ) { +/* Discard aborted buffers. */ +dev_dbg (ipc_protocol->dev,"discard 'aborted' buffers" ); +ipc_pcie_kfree_skb (ipc_protocol->pcie, skb); + skb =NULL ; + goto ret; + } + +/* Set the length field in skbuf. */ +skb_put (skb, p_td->scs.size); + +ret: +return skb; +} + +void ipc_protocol_get_head_tail_index (struct iosm_protocol *ipc_protocol, +struct ipc_pipe *pipe,u32 *head, +u32 *tail) +{ +struct ipc_protocol_ap_shm *ipc_ap_shm = ipc_protocol->p_ap_shm; + +if (head) + *head =le32_to_cpu (ipc_ap_shm->head_array[pipe->pipe_nr]); + +if (tail) + *tail =le32_to_cpu (ipc_ap_shm->tail_array[pipe->pipe_nr]); +} + +/* Frees the TDs given to CP. */ +void ipc_protocol_pipe_cleanup (struct iosm_protocol *ipc_protocol, +struct ipc_pipe *pipe) +{ +struct sk_buff *skb; +u32 head; +u32 tail; + +/* Get the start and the end of the buffer list. */ + head =le32_to_cpu (ipc_protocol->p_ap_shm->head_array[pipe->pipe_nr]); + tail = pipe->old_tail; + +/* Reset tail and head to 0. */ + ipc_protocol->p_ap_shm->tail_array[pipe->pipe_nr] =0 ; + ipc_protocol->p_ap_shm->head_array[pipe->pipe_nr] =0 ; + +/* Free pending uplink and downlink buffers. */ +if (pipe->skbr_start) { +while (head != tail) { +/* Get the reference to the skbuf, +* which is on the way and free it. +*/ + skb = pipe->skbr_start[tail]; +if (skb) +ipc_pcie_kfree_skb (ipc_protocol->pcie, skb); + + tail++; +if (tail >= pipe->nr_of_entries) + tail =0 ; + } + +kfree (pipe->skbr_start); + pipe->skbr_start =NULL ; + } + + pipe->old_tail =0 ; + +/* Free and reset the td and skbuf circular buffers. kfree is save! */ +if (pipe->tdr_start) { +pci_free_consistent (ipc_protocol->pcie->pci, +sizeof (*pipe->tdr_start) * + pipe->nr_of_entries, + pipe->tdr_start, pipe->phy_tdr_start); + + pipe->tdr_start =NULL ; + } +} + +enum ipc_mem_device_ipc_state ipc_protocol_get_ipc_status (struct iosm_protocol + *ipc_protocol) +{ +return (enum ipc_mem_device_ipc_state ) +le32_to_cpu (ipc_protocol->p_ap_shm->device_info.ipc_status); +} + +enum ipc_mem_exec_stage +ipc_protocol_get_ap_exec_stage (struct iosm_protocol *ipc_protocol) +{ +return le32_to_cpu (ipc_protocol->p_ap_shm->device_info.execution_stage); +} + +int ipc_protocol_msg_prep (struct iosm_imem *ipc_imem, +enum ipc_msg_prep_type msg_type, +union ipc_msg_prep_args *args) +{ +struct iosm_protocol *ipc_protocol = ipc_imem->ipc_protocol; + +switch (msg_type) { +case IPC_MSG_PREP_SLEEP : +return ipc_protocol_msg_prep_sleep (ipc_protocol, args); + +case IPC_MSG_PREP_PIPE_OPEN : +return ipc_protocol_msg_prepipe_open (ipc_protocol, args); + +case IPC_MSG_PREP_PIPE_CLOSE : +return ipc_protocol_msg_prepipe_close (ipc_protocol, args); + +case IPC_MSG_PREP_FEATURE_SET : +return ipc_protocol_msg_prep_feature_set (ipc_protocol, args); + +/* Unsupported messages in protocol */ +case IPC_MSG_PREP_MAP : +case IPC_MSG_PREP_UNMAP : +default : +dev_err (ipc_protocol->dev, +"unsupported message type: %d in protocol" , msg_type); +return -EINVAL ; + } +} + +u32 +ipc_protocol_pm_dev_get_sleep_notification (struct iosm_protocol *ipc_protocol) +{ +struct ipc_protocol_ap_shm *ipc_ap_shm = ipc_protocol->p_ap_shm; + +return le32_to_cpu (ipc_ap_shm->device_info.device_sleep_notification); +}
drivers/net/wwan/iosm/iosm_ipc_protocol_ops.h new file +444 -0
444 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 14/16 net: iosm: uevent support
In reply to M Chetan KumarReport modem status via uevent.
---
v2: Removed non-related header file inclusion.
--- drivers/net/wwan/iosm/iosm_ipc_uevent.c | 44 +++++++++++++++++++++++++ drivers/net/wwan/iosm/iosm_ipc_uevent.h | 41 +++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 drivers/net/wwan/iosm/iosm_ipc_uevent.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_uevent.h
drivers/net/wwan/iosm/iosm_ipc_uevent.c new file +44 -0
@@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2020-21 Intel Corporation. +*/ + +#include <linux/device.h> +#include <linux/kobject.h> +#include <linux/slab.h> + +#include "iosm_ipc_uevent.h" + +/* Update the uevent in work queue context */ +static void ipc_uevent_work (struct work_struct *data) +{ +struct ipc_uevent_info *info; +char *envp[2 ] = {NULL ,NULL }; + + info = container_of(data, struct ipc_uevent_info, work); + + envp[0 ] = info->uevent; + +if (kobject_uevent_env (&info->dev->kobj,KOBJ_CHANGE , envp)) +pr_err ("uevent %s failed to sent" , info->uevent); + +kfree (info); +} + +void ipc_uevent_send (struct device *dev,char *uevent) +{ +struct ipc_uevent_info *info =kzalloc (sizeof (*info),GFP_ATOMIC ); + +if (!info) +return ; + +/* Initialize the kernel work queue */ +INIT_WORK (&info->work, ipc_uevent_work); + +/* Store the device and event information */ + info->dev = dev; +snprintf (info->uevent,MAX_UEVENT_LEN ,"%s: %s" ,dev_name (dev), uevent); + +/* Schedule uevent in process context using work queue */ +schedule_work (&info->work); +}
drivers/net/wwan/iosm/iosm_ipc_uevent.h new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 15/16 net: iosm: net driver
In reply to M Chetan Kumar1) Create net device & implement net operations for data/IP communication.
2) Bind IP Link to mux IP session for simultaneous IP traffic.
---
v2:
* Removed Ethernet header & VLAN tag handling from wwan net driver.
* Implement rtnet_link interface for IP traffic handling.
--- drivers/net/wwan/iosm/iosm_ipc_wwan.c | 445 ++++++++++++++++++++++++++ drivers/net/wwan/iosm/iosm_ipc_wwan.h | 55 ++++ 2 files changed, 500 insertions(+) create mode 100644 drivers/net/wwan/iosm/iosm_ipc_wwan.c create mode 100644 drivers/net/wwan/iosm/iosm_ipc_wwan.h
drivers/net/wwan/iosm/iosm_ipc_wwan.c new file +445 -0
@@ -0,0 +1,445 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2020-21 Intel Corporation. +*/ + +#include <linux/etherdevice.h> +#include <linux/if_arp.h> +#include <linux/if_link.h> +#include <net/rtnetlink.h> + +#include "iosm_ipc_chnl_cfg.h" +#include "iosm_ipc_imem_ops.h" +#include "iosm_ipc_wwan.h" + +#define IOSM_IP_TYPE_MASK 0xF0 +#define IOSM_IP_TYPE_IPV4 0x40 +#define IOSM_IP_TYPE_IPV6 0x60 + +#define IOSM_IF_ID_PAYLOAD 2 + +static struct device_type wwan_type = { .name ="wwan" }; + +static const struct nla_policy iosm_wwan_policy[IFLA_IOSM_MAX +1 ] = { + [IFLA_IOSM_IF_ID ] = { .type =NLA_U16 }, +}; + +/** +* struct iosm_net_link - This structure includes information about interface dev. +* @if_id: Interface id for device. +* @ch_id: IPC channel number for which interface device is created. +* @netdev: Pointer to network interface device structure +* @ipc_wwan: Pointer to iosm_wwan struct +*/ + +struct iosm_net_link { +int if_id; +int ch_id; +struct net_device *netdev; +struct iosm_wwan *ipc_wwan; +}; + +/** +* struct iosm_wwan - This structure contains information about WWAN root device +* and interface to the IPC layer. +* @netdev: Pointer to network interface device structure. +* @sub_netlist: List of netlink interfaces +* @ipc_imem: Pointer to imem data-struct +* @dev: Pointer device structure +* @if_mutex: Mutex used for add and remove interface id +* @is_registered: Registration status with netdev +*/ +struct iosm_wwan { +struct net_device *netdev; +struct iosm_net_link __rcu *sub_netlist[MAX_NET_SESSION ]; +struct iosm_imem *ipc_imem; +struct device *dev; +struct mutex if_mutex;/* Mutex used for add and remove interface id */ +u8 is_registered:1 ; +}; + +/* Bring-up the wwan net link */ +static int iosm_wwan_link_open (struct net_device *netdev) +{ +struct iosm_net_link *netlink =netdev_priv (netdev); +struct iosm_wwan *ipc_wwan = netlink->ipc_wwan; +int if_id = netlink->if_id; +int ret = -EINVAL ; + +if ((if_id <IP_MUX_SESSION_START || if_id >IP_MUX_SESSION_END ) && + (if_id <DSS_CHANNEL_START || if_id >DSS_CHANNEL_END )) +return ret; + +mutex_lock (&ipc_wwan->if_mutex); + +/* get channel id */ + netlink->ch_id = +imem_sys_wwan_open (ipc_wwan->ipc_imem, if_id); + +if (netlink->ch_id <0 ) { +dev_err (ipc_wwan->dev, +"cannot connect wwan0 & id %d to the IPC mem layer" , + if_id); + ret = -ENODEV ; + goto out; + } + +/* enable tx path, DL data may follow */ +netif_start_queue (netdev); + +dev_dbg (ipc_wwan->dev,"Channel id %d allocated to if_id %d" , + netlink->ch_id, netlink->if_id); + + ret =0 ; +out: +mutex_unlock (&ipc_wwan->if_mutex); +return ret; +} + +/* Bring-down the wwan net link */ +static int iosm_wwan_link_stop (struct net_device *netdev) +{ +struct iosm_net_link *netlink =netdev_priv (netdev); + +netif_stop_queue (netdev); + +mutex_lock (&netlink->ipc_wwan->if_mutex); +imem_sys_wwan_close (netlink->ipc_wwan->ipc_imem, netlink->if_id, + netlink->ch_id); +mutex_unlock (&netlink->ipc_wwan->if_mutex); + +return 0 ; +} + +/* Transmit a packet */ +static int iosm_wwan_link_transmit (struct sk_buff *skb, +struct net_device *netdev) +{ +struct iosm_net_link *netlink =netdev_priv (netdev); +struct iosm_wwan *ipc_wwan = netlink->ipc_wwan; +int if_id = netlink->if_id; +int ret = -EINVAL ; + +/* Interface IDs from 1 to 8 are for IP data +* & from 257 to 261 are for non-IP data +*/ +if ((if_id <IP_MUX_SESSION_START || if_id >IP_MUX_SESSION_END ) && + (if_id <DSS_CHANNEL_START || if_id >DSS_CHANNEL_END )) + goto exit; + +/* Send the SKB to device for transmission */ + ret =imem_sys_wwan_transmit (ipc_wwan->ipc_imem, + if_id, netlink->ch_id, skb); + +/* Return code of zero is success */ +if (ret ==0 ) { + ret =NETDEV_TX_OK ; + }else if (ret == -EBUSY ) { + ret =NETDEV_TX_BUSY ; +dev_err (ipc_wwan->dev,"unable to push packets" ); + }else { + goto exit; + } + +return ret; + +exit: +/* Log any skb drop */ +if (if_id) +dev_dbg (ipc_wwan->dev,"skb dropped. IF_ID: %d, ret: %d" , if_id, + ret); + +dev_kfree_skb_any (skb); +return ret; +} + +/* Ops structure for wwan net link */ +static const struct net_device_ops iosm_inm_ops = { + .ndo_open = iosm_wwan_link_open, + .ndo_stop = iosm_wwan_link_stop, + .ndo_start_xmit = iosm_wwan_link_transmit, +}; + +/* Setup function for creating new net link */ +static void iosm_wwan_setup (struct net_device *iosm_dev) +{ + iosm_dev->header_ops =NULL ; + iosm_dev->hard_header_len =0 ; + iosm_dev->priv_flags |=IFF_NO_QUEUE ; + + iosm_dev->type =ARPHRD_NONE ; + iosm_dev->min_mtu =ETH_MIN_MTU ; + iosm_dev->max_mtu =ETH_MAX_MTU ; + + iosm_dev->flags =IFF_POINTOPOINT |IFF_NOARP ; + + iosm_dev->netdev_ops = &iosm_inm_ops; +} + +static struct device_type inm_type = { .name ="iosmdev" }; + +/* Create new wwan net link */ +static int iosm_wwan_newlink (struct net *src_net,struct net_device *dev, +struct nlattr *tb[],struct nlattr *data[], +struct netlink_ext_ack *extack) +{ +struct iosm_net_link *netlink =netdev_priv (dev); +struct iosm_wwan *ipc_wwan; +struct net_device *netdev; +int err = -EINVAL ; +int index; + +if (!data[IFLA_IOSM_IF_ID ]) { +pr_err ("Interface ID not specified" ); + goto out; + } + +if (!tb[IFLA_LINK ]) { +pr_err ("Link not specified" ); + goto out; + } + + netlink->netdev = dev; + + netdev =__dev_get_by_index (src_net,nla_get_u32 (tb[IFLA_LINK ])); + + netlink->ipc_wwan =netdev_priv (netdev); + + ipc_wwan = netlink->ipc_wwan; + +if (ipc_wwan->netdev != netdev) + goto out; + + netlink->if_id =nla_get_u16 (data[IFLA_IOSM_IF_ID ]); + index = netlink->if_id; + +/* Complete all memory stores before this point */ +smp_mb (); +if (index >=DSS_SESSION_START && index <=DSS_SESSION_END ) + index = (index -DSS_SESSION_START ) +IP_MUX_SESSION_END +1 ; +else if ((index <IP_MUX_SESSION_START || index >IP_MUX_SESSION_END ) && + (index <DSS_SESSION_START || index >DSS_SESSION_END )) + goto out; + +rcu_read_lock (); + +if (rcu_access_pointer (ipc_wwan->sub_netlist[index -1 ])) { +pr_err ("IOSM interface ID already in use" ); + goto out_free_lock; + } + +SET_NETDEV_DEVTYPE (dev, &inm_type); + +eth_hw_addr_random (dev); + err =register_netdevice (dev); +if (err) { +dev_err (ipc_wwan->dev,"register netlink failed.\n" ); + goto out_free_lock; + } + + err =netdev_upper_dev_link (ipc_wwan->netdev, dev, extack); + +if (err) { +dev_err (ipc_wwan->dev,"netdev linking with parent failed.\n" ); + goto netlink_err; + } + +rcu_assign_pointer (ipc_wwan->sub_netlist[index -1 ], netlink); +netif_device_attach (dev); +rcu_read_unlock (); + +return 0 ; + +netlink_err: +unregister_netdevice (dev); +out_free_lock: +rcu_read_unlock (); +out: +return err; +} + +/* Delete new wwan net link */ +static void iosm_wwan_dellink (struct net_device *dev,struct list_head *head) +{ +struct iosm_net_link *netlink =netdev_priv (dev); +u16 index = netlink->if_id; + +netdev_upper_dev_unlink (netlink->ipc_wwan->netdev, dev); +unregister_netdevice (dev); + +if (index >=DSS_SESSION_START && index <=DSS_SESSION_END ) + index = (index -DSS_SESSION_START ) +IP_MUX_SESSION_END +1 ; + +mutex_lock (&netlink->ipc_wwan->if_mutex); +rcu_assign_pointer (netlink->ipc_wwan->sub_netlist[index -1 ],NULL ); +mutex_unlock (&netlink->ipc_wwan->if_mutex); +} + +/* Get size for iosm net link payload*/ +static size_t iosm_wwan_get_size (const struct net_device *dev) +{ +return nla_total_size (IOSM_IF_ID_PAYLOAD ); +} + +/* Validate the input parameters for wwan net link */ +static int iosm_wwan_validate (struct nlattr *tb[],struct nlattr *data[], +struct netlink_ext_ack *extack) +{ +u16 if_id; + +if (!data || !data[IFLA_IOSM_IF_ID ]) { +NL_SET_ERR_MSG_MOD (extack,"IF ID not specified" ); +return -EINVAL ; + } + + if_id =nla_get_u16 (data[IFLA_IOSM_IF_ID ]); + +if ((if_id <IP_MUX_SESSION_START || if_id >IP_MUX_SESSION_END ) && + (if_id <DSS_SESSION_START || if_id >DSS_SESSION_END )) { +NL_SET_ERR_MSG_MOD (extack,"Invalid Interface" ); +return -ERANGE ; + } + +return 0 ; +} + +/* RT Net link ops structure for new wwan net link */ +struct rtnl_link_ops iosm_netlink__read_mostly = { + .kind ="iosm" , + .maxtype = __IFLA_IOSM_MAX, + .priv_size =sizeof (struct iosm_net_link ), + .setup = iosm_wwan_setup, + .validate = iosm_wwan_validate, + .newlink = iosm_wwan_newlink, + .dellink = iosm_wwan_dellink, + .get_size = iosm_wwan_get_size, + .policy = iosm_wwan_policy, +}; + +int ipc_wwan_receive (struct iosm_wwan *ipc_wwan,struct sk_buff *skb_arg, +bool dss,int if_id) +{ +struct sk_buff *skb = skb_arg; +struct net_device_stats stats; +int ret; + +if ((skb->data[0 ] &IOSM_IP_TYPE_MASK ) ==IOSM_IP_TYPE_IPV4 ) + skb->protocol =htons (ETH_P_IP ); +else if ((skb->data[0 ] &IOSM_IP_TYPE_MASK ) == +IOSM_IP_TYPE_IPV6 ) + skb->protocol =htons (ETH_P_IPV6 ); + + skb->pkt_type =PACKET_HOST ; + +if (if_id < (NET_SESSION_START -1 ) || if_id > (MAX_NET_SESSION -1 )) { +dev_kfree_skb (skb); +return -EINVAL ; + } + +rcu_read_lock (); + skb->dev =rcu_dereference (ipc_wwan->sub_netlist[if_id])->netdev; + stats =rcu_dereference (ipc_wwan->sub_netlist[if_id])->netdev->stats; + stats.rx_packets++; + stats.rx_bytes += skb->len; + + ret =netif_rx (skb); +rcu_read_unlock (); + +return ret; +} + +void ipc_wwan_tx_flowctrl (struct iosm_wwan *ipc_wwan,int if_id,bool on) +{ +struct net_device *netdev; +bool is_tx_blk; + +rcu_read_lock (); + netdev =rcu_dereference (ipc_wwan->sub_netlist[if_id])->netdev; + + is_tx_blk =netif_queue_stopped (netdev); + +if (on) +dev_dbg (ipc_wwan->dev,"session id[%d]: flowctrl enable" , + if_id); + +if (on && !is_tx_blk) +netif_stop_queue (netdev); +else if (!on && is_tx_blk) +netif_wake_queue (netdev); +rcu_read_unlock (); +} + +static void iosm_netdev_setup (struct net_device *dev) {} + +struct iosm_wwan *ipc_wwan_init (struct iosm_imem *ipc_imem,struct device *dev) +{ +static const struct net_device_ops iosm_wwandev_ops = {}; +struct iosm_wwan *ipc_wwan; +struct net_device *netdev; + + netdev =alloc_netdev (sizeof (*ipc_wwan),"wwan%d" ,NET_NAME_ENUM , + iosm_netdev_setup); + +if (!netdev) +return NULL ; + + ipc_wwan =netdev_priv (netdev); + + ipc_wwan->dev = dev; + ipc_wwan->netdev = netdev; + ipc_wwan->is_registered = false; + + ipc_wwan->ipc_imem = ipc_imem; + +mutex_init (&ipc_wwan->if_mutex); + +/* allocate random ethernet address */ +eth_random_addr (netdev->dev_addr); + netdev->addr_assign_type =NET_ADDR_RANDOM ; + + netdev->netdev_ops = &iosm_wwandev_ops; + netdev->flags |=IFF_NOARP ; + +SET_NETDEV_DEVTYPE (netdev, &wwan_type); + +if (register_netdev (netdev)) { +dev_err (ipc_wwan->dev,"register_netdev failed" ); + goto reg_fail; + } + + ipc_wwan->is_registered = true; + +netif_device_attach (netdev); + +return ipc_wwan; + +reg_fail: +free_netdev (netdev); +return NULL ; +} + +void ipc_wwan_deinit (struct iosm_wwan *ipc_wwan) +{ +struct iosm_net_link *netlink; +int i; + +if (ipc_wwan->is_registered) { +rcu_read_lock (); +for (i =IP_MUX_SESSION_START ; i <=IP_DSS_SESSION_END ; i++) { +if (rcu_access_pointer (ipc_wwan->sub_netlist[i -1 ])) { + netlink = +rcu_dereference (ipc_wwan->sub_netlist[i -1 ]); +rtnl_lock (); +netdev_upper_dev_unlink (ipc_wwan->netdev, + netlink->netdev); +unregister_netdevice (netlink->netdev); +rtnl_unlock (); +rcu_assign_pointer (ipc_wwan->sub_netlist[i -1 ],NULL ); + } + } +rcu_read_unlock (); + +unregister_netdev (ipc_wwan->netdev); +free_netdev (ipc_wwan->netdev); + } +}
drivers/net/wwan/iosm/iosm_ipc_wwan.h new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 16/16 net: iosm: infrastructure
In reply to M Chetan Kumar1) Kconfig & Makefile changes for IOSM Driver compilation.
2) Modified driver/net Kconfig & Makefile for driver inclusion.
3) Add IOSM Driver documentation.
4) Modified MAINTAINER file for IOSM Driver addition.
---
v2:
* Moved driver documentation to RsT file.
* Modified if_link.h file to support link type iosm.
--- .../networking/device_drivers/index.rst | 1 + .../networking/device_drivers/wwan/index.rst | 18 +++ .../networking/device_drivers/wwan/iosm.rst | 126 ++++++++++++++++++ MAINTAINERS | 7 + drivers/net/Kconfig | 1 + drivers/net/Makefile | 1 + drivers/net/wwan/Kconfig | 19 +++ drivers/net/wwan/Makefile | 5 + drivers/net/wwan/iosm/Kconfig | 17 +++ drivers/net/wwan/iosm/Makefile | 26 ++++ include/uapi/linux/if_link.h | 10 ++ tools/include/uapi/linux/if_link.h | 10 ++ 12 files changed, 241 insertions(+) create mode 100644 Documentation/networking/device_drivers/wwan/index.rst create mode 100755 Documentation/networking/device_drivers/wwan/iosm.rst create mode 100644 drivers/net/wwan/Kconfig create mode 100644 drivers/net/wwan/Makefile create mode 100644 drivers/net/wwan/iosm/Kconfig create mode 100644 drivers/net/wwan/iosm/Makefile
Documentation/networking/device_drivers/index.rst +1 -0
@@ -18,6 +18,7 @@ Contents: qlogic/index wan/index wifi/index + wwan/index .. only:: subproject and html
Documentation/networking/device_drivers/wwan/index.rst new file +18 -0
@@ -0,0 +1,18 @@ +.. SPDX-License-Identifier: GPL-2.0-only + +WWAN Device Drivers +=================== + +Contents: + +.. toctree:: + :maxdepth: 2 + + iosm + +.. only:: subproject and html + + Indices + ======= + + * :ref:`genindex`
Documentation/networking/device_drivers/wwan/iosm.rst new file +126 -0
126 lines not on this page · raw message
MAINTAINERS +7 -0
@@ -9256,6 +9256,13 @@ M: Mario Limonciello <[email protected]> S: Maintained F: drivers/platform/x86/intel-wmi-thunderbolt.c +INTEL WWAN IOSM DRIVER +M: M Chetan Kumar <[email protected]> +M: Intel Corporation <[email protected]> +L: [email protected] +S: Maintained +F: drivers/net/wwan/iosm/ + INTEL(R) TRACE HUB M: Alexander Shishkin <[email protected]> S: Supported
drivers/net/Kconfig +1 -0
@@ -600,4 +600,5 @@ config NET_FAILOVER a VM with direct attached VF by failing over to the paravirtual datapath when the VF is unplugged. +source "drivers/net/wwan/Kconfig" endif # NETDEVICES
drivers/net/Makefile +1 -0
@@ -84,3 +84,4 @@ thunderbolt-net-y += thunderbolt.o obj-$(CONFIG_USB4_NET) += thunderbolt-net.o obj-$(CONFIG_NETDEVSIM) += netdevsim/ obj-$(CONFIG_NET_FAILOVER) += net_failover.o +obj-$(CONFIG_WWAN)+= wwan/
drivers/net/wwan/Kconfig new file +19 -0
@@ -0,0 +1,19 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Wireless WAN device configuration +# + +menuconfig WWAN + bool "Wireless WAN" + depends on NET + help + This section contains all Wireless WAN (WWAN) device drivers. + + If you have one of those WWAN M.2 Modules and wish to use it in Linux + say Y here and also to the Module specific WWAN Device Driver. + + If unsure, say N. + +if WWAN +source "drivers/net/wwan/iosm/Kconfig" +endif # WWAN
drivers/net/wwan/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for the Linux WWAN Device Drivers. +# +obj-$(CONFIG_IOSM)+= iosm/
drivers/net/wwan/iosm/Kconfig new file +17 -0
@@ -0,0 +1,17 @@ +# SPDX-License-Identifier: (GPL-2.0-only) +# +# IOSM Driver configuration +# +# Copyright (C) 2020-21 Intel Corporation +# + +config IOSM + tristate "IOSM Driver" + depends on INTEL_IOMMU + help + This driver enables Intel M.2 WWAN Device communication. + + If you have one of those Intel M.2 WWAN Modules and wish to use it in + Linux say Y/M here. + + If unsure, say N.
drivers/net/wwan/iosm/Makefile new file +26 -0
@@ -0,0 +1,26 @@ +# SPDX-License-Identifier: (GPL-2.0-only) +# +# Copyright (C) 2020-21 Intel Corporation. +# + +iosm-y = \ + iosm_ipc_task_queue.o \ + iosm_ipc_imem.o \ + iosm_ipc_imem_ops.o \ + iosm_ipc_mmio.o \ + iosm_ipc_mbim.o \ + iosm_ipc_wwan.o \ + iosm_ipc_uevent.o \ + iosm_ipc_pm.o \ + iosm_ipc_pcie.o \ + iosm_ipc_irq.o \ + iosm_ipc_chnl_cfg.o \ + iosm_ipc_protocol.o \ + iosm_ipc_protocol_ops.o \ + iosm_ipc_mux.o \ + iosm_ipc_mux_codec.o + +obj-$(CONFIG_IOSM) := iosm.o + +# compilation flags +ccflags-y += -DDEBUG
include/uapi/linux/if_link.h +10 -0
@@ -1250,4 +1250,14 @@ struct ifla_rmnet_flags { __u32 mask; }; +/* IOSM Section */ + +enum { +IFLA_IOSM_UNSPEC , +IFLA_IOSM_IF_ID , + __IFLA_IOSM_MAX, +}; + +#define IFLA_IOSM_MAX (__IFLA_IOSM_MAX - 1) +#endif /* _UAPI_LINUX_IF_LINK_H */
tools/include/uapi/linux/if_link.h +10 -0
@@ -1046,4 +1046,14 @@ struct ifla_rmnet_flags { __u32 mask; }; +/* IOSM Section */ + +enum { +IFLA_IOSM_UNSPEC , +IFLA_IOSM_IF_ID , + __IFLA_IOSM_MAX, +}; + +#define IFLA_IOSM_MAX (__IFLA_IOSM_MAX - 1) +#endif /* _UAPI_LINUX_IF_LINK_H */
Signature · 1 line
2.25.1
Randy Dunlap
reviewerRe: [PATCH V2 16/16] net: iosm: infrastructure
Hi--
Quoted 6 lines · M Chetan Kumar
drivers/net/wwan/Kconfig new file +0
-0
drivers/net/wwan/Kconfig line 8
Quoted 8 lines
drivers/net/wwan/Kconfig new file +8
-0@@ -0,0 +1,19 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Wireless WAN device configuration +# + +menuconfig WWAN + bool "Wireless WAN" + depends on NET
This already depends on NET since it is inside NETDEVICES which depends on NET.
Quoted 11 lines
drivers/net/wwan/Kconfig new file +11
-0+ help + This section contains all Wireless WAN (WWAN) device drivers. + + If you have one of those WWAN M.2 Modules and wish to use it in Linux + say Y here and also to the Module specific WWAN Device Driver. + + If unsure, say N. + +if WWAN +source "drivers/net/wwan/iosm/Kconfig" +endif # WWAN
Signature · 1 line
~Randy
Hey,
Quoted 23 lines · M Chetan Kumar
The IOSM (IPC over Shared Memory) driver is a PCIe host driver implemented for linux or chrome platform for data exchange over PCIe interface between Host platform & Intel M.2 Modem. The driver exposes interface conforming to the MBIM protocol. Any front end application ( eg: Modem Manager) could easily manage the MBIM interface to enable data communication towards WWAN.
Intel M.2 modem uses 2 BAR regions. The first region is dedicated to Doorbell register for IRQs and the second region is used as scratchpad area for book keeping modem execution stage details along with host system shared memory region context details. The upper edge of the driver exposes the control and data channels for user space application interaction. At lower edge these data and control channels are associated to pipes. The pipes are lowest level interfaces used over PCIe as a logical channel for message exchange. A single channel maps to UL and DL pipe and are initialized on device open.
On UL path, driver copies application sent data to SKBs associate it with transfer descriptor and puts it on to ring buffer for DMA transfer. Once information has been updated in shared memory region, host gives a Doorbell to modem to perform DMA and modem uses MSI to communicate back to host. For receiving data in DL path, SKBs are pre-allocated during pipe open and transfer descriptors are given to modem for DMA transfer.
Quoted 3 lines
The driver exposes two types of ports, namely "wwanctrl", a char device node which is used for MBIM control operation and "INMx",(x = 0,1,2..7) network interfaces for IP data communication.
Is there any plan to integrate this driver in the new "wwan" subsystem so that the character device for MBIM control is exposed in the same format (i.e. same name rules and such) as with the MHI driver?
Signature · 2 lines
Aleksander https://aleksander.es
Hi Aleksander,
Quoted 25 lines
Quoted 5 lines
The IOSM (IPC over Shared Memory) driver is a PCIe host driver implemented for linux or chrome platform for data exchange over PCIe interface between Host platform & Intel M.2 Modem. The driver exposes interface conforming to the MBIM protocol. Any front end application (
eg: Modem Manager) could easily manage the MBIM interface to enabledata communication towards WWAN.
Quoted 9 lines
Intel M.2 modem uses 2 BAR regions. The first region is dedicated to Doorbell register for IRQs and the second region is used as scratchpad area for book keeping modem execution stage details along with host system shared memory region context details. The upper edge of the driver exposes the control and data channels for user space application interaction. At lower edge these data and control channels are associated to pipes. The pipes are lowest level interfaces used over PCIe as a logical channel for message exchange. A single channel maps
to UL and DL pipe and are initialized on device open.
Quoted 5 lines
On UL path, driver copies application sent data to SKBs associate it with transfer descriptor and puts it on to ring buffer for DMA transfer. Once information has been updated in shared memory region, host gives a Doorbell to modem to perform DMA and modem uses MSI to
communicate back to host.
Quoted 3 lines
For receiving data in DL path, SKBs are pre-allocated during pipe open and transfer descriptors are given to modem for DMA transfer.
Quoted 8 lines
Quoted 3 lines
The driver exposes two types of ports, namely "wwanctrl", a char device node which is used for MBIM control operation and "INMx",(x = 0,1,2..7) network interfaces for IP data communication.
Is there any plan to integrate this driver in the new "wwan" subsystem so that the character device for MBIM control is exposed in the same format (i.e. same name rules and such) as with the MHI driver?
Yes, we are working on it. The next version of driver would have these adaptation to expose MBIM "WWAN Port".
Regards,
Chetan