162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci * 362306a36Sopenharmony_ci * Copyright (C) 2020-21 Intel Corporation. 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#ifndef IOSM_IPC_IMEM_H 762306a36Sopenharmony_ci#define IOSM_IPC_IMEM_H 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#include <linux/skbuff.h> 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include "iosm_ipc_mmio.h" 1262306a36Sopenharmony_ci#include "iosm_ipc_pcie.h" 1362306a36Sopenharmony_ci#include "iosm_ipc_uevent.h" 1462306a36Sopenharmony_ci#include "iosm_ipc_wwan.h" 1562306a36Sopenharmony_ci#include "iosm_ipc_task_queue.h" 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_cistruct ipc_chnl_cfg; 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci/* IRQ moderation in usec */ 2062306a36Sopenharmony_ci#define IRQ_MOD_OFF 0 2162306a36Sopenharmony_ci#define IRQ_MOD_NET 1000 2262306a36Sopenharmony_ci#define IRQ_MOD_TRC 4000 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci/* Either the PSI image is accepted by CP or the suspended flash tool is waken, 2562306a36Sopenharmony_ci * informed that the CP ROM driver is not ready to process the PSI image. 2662306a36Sopenharmony_ci * unit : milliseconds 2762306a36Sopenharmony_ci */ 2862306a36Sopenharmony_ci#define IPC_PSI_TRANSFER_TIMEOUT 3000 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci/* Timeout in 20 msec to wait for the modem to boot up to 3162306a36Sopenharmony_ci * IPC_MEM_DEVICE_IPC_INIT state. 3262306a36Sopenharmony_ci * unit : milliseconds (500 * ipc_util_msleep(20)) 3362306a36Sopenharmony_ci */ 3462306a36Sopenharmony_ci#define IPC_MODEM_BOOT_TIMEOUT 500 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci/* Wait timeout for ipc status reflects IPC_MEM_DEVICE_IPC_UNINIT 3762306a36Sopenharmony_ci * unit : milliseconds 3862306a36Sopenharmony_ci */ 3962306a36Sopenharmony_ci#define IPC_MODEM_UNINIT_TIMEOUT_MS 30 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci/* Pending time for processing data. 4262306a36Sopenharmony_ci * unit : milliseconds 4362306a36Sopenharmony_ci */ 4462306a36Sopenharmony_ci#define IPC_PEND_DATA_TIMEOUT 500 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci/* The timeout in milliseconds for application to wait for remote time. */ 4762306a36Sopenharmony_ci#define IPC_REMOTE_TS_TIMEOUT_MS 10 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci/* Timeout for TD allocation retry. 5062306a36Sopenharmony_ci * unit : milliseconds 5162306a36Sopenharmony_ci */ 5262306a36Sopenharmony_ci#define IPC_TD_ALLOC_TIMER_PERIOD_MS 100 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci/* Host sleep target is host */ 5562306a36Sopenharmony_ci#define IPC_HOST_SLEEP_HOST 0 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci/* Host sleep target is device */ 5862306a36Sopenharmony_ci#define IPC_HOST_SLEEP_DEVICE 1 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci/* Sleep message, target host: AP enters sleep / target device: CP is 6162306a36Sopenharmony_ci * allowed to enter sleep and shall use the host sleep protocol 6262306a36Sopenharmony_ci */ 6362306a36Sopenharmony_ci#define IPC_HOST_SLEEP_ENTER_SLEEP 0 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci/* Sleep_message, target host: AP exits sleep / target device: CP is 6662306a36Sopenharmony_ci * NOT allowed to enter sleep 6762306a36Sopenharmony_ci */ 6862306a36Sopenharmony_ci#define IPC_HOST_SLEEP_EXIT_SLEEP 1 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci#define IMEM_IRQ_DONT_CARE (-1) 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci#define IPC_MEM_MAX_CHANNELS 8 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci#define IPC_MEM_MUX_IP_SESSION_ENTRIES 8 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci#define IPC_MEM_MUX_IP_CH_IF_ID 0 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci#define TD_UPDATE_DEFAULT_TIMEOUT_USEC 1900 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci#define FORCE_UPDATE_DEFAULT_TIMEOUT_USEC 500 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci/* Sleep_message, target host: not applicable / target device: CP is 8362306a36Sopenharmony_ci * allowed to enter sleep and shall NOT use the device sleep protocol 8462306a36Sopenharmony_ci */ 8562306a36Sopenharmony_ci#define IPC_HOST_SLEEP_ENTER_SLEEP_NO_PROTOCOL 2 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci/* in_band_crash_signal IPC_MEM_INBAND_CRASH_SIG 8862306a36Sopenharmony_ci * Modem crash notification configuration. If this value is non-zero then 8962306a36Sopenharmony_ci * FEATURE_SET message will be sent to the Modem as a result the Modem will 9062306a36Sopenharmony_ci * signal Crash via Execution Stage register. If this value is zero then Modem 9162306a36Sopenharmony_ci * will use out-of-band method to notify about it's Crash. 9262306a36Sopenharmony_ci */ 9362306a36Sopenharmony_ci#define IPC_MEM_INBAND_CRASH_SIG 1 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci/* Extra headroom to be allocated for DL SKBs to allow addition of Ethernet 9662306a36Sopenharmony_ci * header 9762306a36Sopenharmony_ci */ 9862306a36Sopenharmony_ci#define IPC_MEM_DL_ETH_OFFSET 16 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci#define IPC_CB(skb) ((struct ipc_skb_cb *)((skb)->cb)) 10162306a36Sopenharmony_ci#define IOSM_CHIP_INFO_SIZE_MAX 100 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci#define FULLY_FUNCTIONAL 0 10462306a36Sopenharmony_ci#define IOSM_DEVLINK_INIT 1 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ci/* List of the supported UL/DL pipes. */ 10762306a36Sopenharmony_cienum ipc_mem_pipes { 10862306a36Sopenharmony_ci IPC_MEM_PIPE_0 = 0, 10962306a36Sopenharmony_ci IPC_MEM_PIPE_1, 11062306a36Sopenharmony_ci IPC_MEM_PIPE_2, 11162306a36Sopenharmony_ci IPC_MEM_PIPE_3, 11262306a36Sopenharmony_ci IPC_MEM_PIPE_4, 11362306a36Sopenharmony_ci IPC_MEM_PIPE_5, 11462306a36Sopenharmony_ci IPC_MEM_PIPE_6, 11562306a36Sopenharmony_ci IPC_MEM_PIPE_7, 11662306a36Sopenharmony_ci IPC_MEM_PIPE_8, 11762306a36Sopenharmony_ci IPC_MEM_PIPE_9, 11862306a36Sopenharmony_ci IPC_MEM_PIPE_10, 11962306a36Sopenharmony_ci IPC_MEM_PIPE_11, 12062306a36Sopenharmony_ci IPC_MEM_PIPE_12, 12162306a36Sopenharmony_ci IPC_MEM_PIPE_13, 12262306a36Sopenharmony_ci IPC_MEM_PIPE_14, 12362306a36Sopenharmony_ci IPC_MEM_PIPE_15, 12462306a36Sopenharmony_ci IPC_MEM_PIPE_16, 12562306a36Sopenharmony_ci IPC_MEM_PIPE_17, 12662306a36Sopenharmony_ci IPC_MEM_PIPE_18, 12762306a36Sopenharmony_ci IPC_MEM_PIPE_19, 12862306a36Sopenharmony_ci IPC_MEM_PIPE_20, 12962306a36Sopenharmony_ci IPC_MEM_PIPE_21, 13062306a36Sopenharmony_ci IPC_MEM_PIPE_22, 13162306a36Sopenharmony_ci IPC_MEM_PIPE_23, 13262306a36Sopenharmony_ci IPC_MEM_MAX_PIPES 13362306a36Sopenharmony_ci}; 13462306a36Sopenharmony_ci 13562306a36Sopenharmony_ci/* Enum defining channel states. */ 13662306a36Sopenharmony_cienum ipc_channel_state { 13762306a36Sopenharmony_ci IMEM_CHANNEL_FREE, 13862306a36Sopenharmony_ci IMEM_CHANNEL_RESERVED, 13962306a36Sopenharmony_ci IMEM_CHANNEL_ACTIVE, 14062306a36Sopenharmony_ci IMEM_CHANNEL_CLOSING, 14162306a36Sopenharmony_ci}; 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_ci/** 14462306a36Sopenharmony_ci * enum ipc_ctype - Enum defining supported channel type needed for control 14562306a36Sopenharmony_ci * /IP traffic. 14662306a36Sopenharmony_ci * @IPC_CTYPE_WWAN: Used for IP traffic 14762306a36Sopenharmony_ci * @IPC_CTYPE_CTRL: Used for Control Communication 14862306a36Sopenharmony_ci */ 14962306a36Sopenharmony_cienum ipc_ctype { 15062306a36Sopenharmony_ci IPC_CTYPE_WWAN, 15162306a36Sopenharmony_ci IPC_CTYPE_CTRL, 15262306a36Sopenharmony_ci}; 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_ci/* Pipe direction. */ 15562306a36Sopenharmony_cienum ipc_mem_pipe_dir { 15662306a36Sopenharmony_ci IPC_MEM_DIR_UL, 15762306a36Sopenharmony_ci IPC_MEM_DIR_DL, 15862306a36Sopenharmony_ci}; 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ci/* HP update identifier. To be used as data for ipc_cp_irq_hpda_update() */ 16162306a36Sopenharmony_cienum ipc_hp_identifier { 16262306a36Sopenharmony_ci IPC_HP_MR = 0, 16362306a36Sopenharmony_ci IPC_HP_PM_TRIGGER, 16462306a36Sopenharmony_ci IPC_HP_WAKEUP_SPEC_TMR, 16562306a36Sopenharmony_ci IPC_HP_TD_UPD_TMR_START, 16662306a36Sopenharmony_ci IPC_HP_TD_UPD_TMR, 16762306a36Sopenharmony_ci IPC_HP_FAST_TD_UPD_TMR, 16862306a36Sopenharmony_ci IPC_HP_UL_WRITE_TD, 16962306a36Sopenharmony_ci IPC_HP_DL_PROCESS, 17062306a36Sopenharmony_ci IPC_HP_NET_CHANNEL_INIT, 17162306a36Sopenharmony_ci IPC_HP_CDEV_OPEN, 17262306a36Sopenharmony_ci}; 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ci/** 17562306a36Sopenharmony_ci * struct ipc_pipe - Structure for Pipe. 17662306a36Sopenharmony_ci * @tdr_start: Ipc private protocol Transfer Descriptor Ring 17762306a36Sopenharmony_ci * @channel: Id of the sio device, set by imem_sio_open, 17862306a36Sopenharmony_ci * needed to pass DL char to the user terminal 17962306a36Sopenharmony_ci * @skbr_start: Circular buffer for skbuf and the buffer 18062306a36Sopenharmony_ci * reference in a tdr_start entry. 18162306a36Sopenharmony_ci * @phy_tdr_start: Transfer descriptor start address 18262306a36Sopenharmony_ci * @old_head: last head pointer reported to CP. 18362306a36Sopenharmony_ci * @old_tail: AP read position before CP moves the read 18462306a36Sopenharmony_ci * position to write/head. If CP has consumed the 18562306a36Sopenharmony_ci * buffers, AP has to freed the skbuf starting at 18662306a36Sopenharmony_ci * tdr_start[old_tail]. 18762306a36Sopenharmony_ci * @nr_of_entries: Number of elements of skb_start and tdr_start. 18862306a36Sopenharmony_ci * @max_nr_of_queued_entries: Maximum number of queued entries in TDR 18962306a36Sopenharmony_ci * @accumulation_backoff: Accumulation in usec for accumulation 19062306a36Sopenharmony_ci * backoff (0 = no acc backoff) 19162306a36Sopenharmony_ci * @irq_moderation: timer in usec for irq_moderation 19262306a36Sopenharmony_ci * (0=no irq moderation) 19362306a36Sopenharmony_ci * @pipe_nr: Pipe identification number 19462306a36Sopenharmony_ci * @irq: Interrupt vector 19562306a36Sopenharmony_ci * @dir: Direction of data stream in pipe 19662306a36Sopenharmony_ci * @buf_size: Buffer size (in bytes) for preallocated 19762306a36Sopenharmony_ci * buffers (for DL pipes) 19862306a36Sopenharmony_ci * @nr_of_queued_entries: Aueued number of entries 19962306a36Sopenharmony_ci * @is_open: Check for open pipe status 20062306a36Sopenharmony_ci */ 20162306a36Sopenharmony_cistruct ipc_pipe { 20262306a36Sopenharmony_ci struct ipc_protocol_td *tdr_start; 20362306a36Sopenharmony_ci struct ipc_mem_channel *channel; 20462306a36Sopenharmony_ci struct sk_buff **skbr_start; 20562306a36Sopenharmony_ci dma_addr_t phy_tdr_start; 20662306a36Sopenharmony_ci u32 old_head; 20762306a36Sopenharmony_ci u32 old_tail; 20862306a36Sopenharmony_ci u32 nr_of_entries; 20962306a36Sopenharmony_ci u32 max_nr_of_queued_entries; 21062306a36Sopenharmony_ci u32 accumulation_backoff; 21162306a36Sopenharmony_ci u32 irq_moderation; 21262306a36Sopenharmony_ci u32 pipe_nr; 21362306a36Sopenharmony_ci u32 irq; 21462306a36Sopenharmony_ci enum ipc_mem_pipe_dir dir; 21562306a36Sopenharmony_ci u32 buf_size; 21662306a36Sopenharmony_ci u16 nr_of_queued_entries; 21762306a36Sopenharmony_ci u8 is_open:1; 21862306a36Sopenharmony_ci}; 21962306a36Sopenharmony_ci 22062306a36Sopenharmony_ci/** 22162306a36Sopenharmony_ci * struct ipc_mem_channel - Structure for Channel. 22262306a36Sopenharmony_ci * @channel_id: Instance of the channel list and is return to the user 22362306a36Sopenharmony_ci * at the end of the open operation. 22462306a36Sopenharmony_ci * @ctype: Control or netif channel. 22562306a36Sopenharmony_ci * @index: unique index per ctype 22662306a36Sopenharmony_ci * @ul_pipe: pipe objects 22762306a36Sopenharmony_ci * @dl_pipe: pipe objects 22862306a36Sopenharmony_ci * @if_id: Interface ID 22962306a36Sopenharmony_ci * @net_err_count: Number of downlink errors returned by ipc_wwan_receive 23062306a36Sopenharmony_ci * interface at the entry point of the IP stack. 23162306a36Sopenharmony_ci * @state: Free, reserved or busy (in use). 23262306a36Sopenharmony_ci * @ul_sem: Needed for the blocking write or uplink transfer. 23362306a36Sopenharmony_ci * @ul_list: Uplink accumulator which is filled by the uplink 23462306a36Sopenharmony_ci * char app or IP stack. The socket buffer pointer are 23562306a36Sopenharmony_ci * added to the descriptor list in the kthread context. 23662306a36Sopenharmony_ci */ 23762306a36Sopenharmony_cistruct ipc_mem_channel { 23862306a36Sopenharmony_ci int channel_id; 23962306a36Sopenharmony_ci enum ipc_ctype ctype; 24062306a36Sopenharmony_ci int index; 24162306a36Sopenharmony_ci struct ipc_pipe ul_pipe; 24262306a36Sopenharmony_ci struct ipc_pipe dl_pipe; 24362306a36Sopenharmony_ci int if_id; 24462306a36Sopenharmony_ci u32 net_err_count; 24562306a36Sopenharmony_ci enum ipc_channel_state state; 24662306a36Sopenharmony_ci struct completion ul_sem; 24762306a36Sopenharmony_ci struct sk_buff_head ul_list; 24862306a36Sopenharmony_ci}; 24962306a36Sopenharmony_ci 25062306a36Sopenharmony_ci/** 25162306a36Sopenharmony_ci * enum ipc_phase - Different AP and CP phases. 25262306a36Sopenharmony_ci * The enums defined after "IPC_P_ROM" and before 25362306a36Sopenharmony_ci * "IPC_P_RUN" indicates the operating state where CP can 25462306a36Sopenharmony_ci * respond to any requests. So while introducing new phase 25562306a36Sopenharmony_ci * this shall be taken into consideration. 25662306a36Sopenharmony_ci * @IPC_P_OFF: On host PC, the PCIe device link settings are known 25762306a36Sopenharmony_ci * about the combined power on. PC is running, the driver 25862306a36Sopenharmony_ci * is loaded and CP is in power off mode. The PCIe bus 25962306a36Sopenharmony_ci * driver call the device power mode D3hot. In this phase 26062306a36Sopenharmony_ci * the driver the polls the device, until the device is in 26162306a36Sopenharmony_ci * the power on state and signals the power mode D0. 26262306a36Sopenharmony_ci * @IPC_P_OFF_REQ: The intermediate phase between cleanup activity starts 26362306a36Sopenharmony_ci * and ends. 26462306a36Sopenharmony_ci * @IPC_P_CRASH: The phase indicating CP crash 26562306a36Sopenharmony_ci * @IPC_P_CD_READY: The phase indicating CP core dump is ready 26662306a36Sopenharmony_ci * @IPC_P_ROM: After power on, CP starts in ROM mode and the IPC ROM 26762306a36Sopenharmony_ci * driver is waiting 150 ms for the AP active notification 26862306a36Sopenharmony_ci * saved in the PCI link status register. 26962306a36Sopenharmony_ci * @IPC_P_PSI: Primary signed image download phase 27062306a36Sopenharmony_ci * @IPC_P_EBL: Extended bootloader pahse 27162306a36Sopenharmony_ci * @IPC_P_RUN: The phase after flashing to RAM is the RUNTIME phase. 27262306a36Sopenharmony_ci */ 27362306a36Sopenharmony_cienum ipc_phase { 27462306a36Sopenharmony_ci IPC_P_OFF, 27562306a36Sopenharmony_ci IPC_P_OFF_REQ, 27662306a36Sopenharmony_ci IPC_P_CRASH, 27762306a36Sopenharmony_ci IPC_P_CD_READY, 27862306a36Sopenharmony_ci IPC_P_ROM, 27962306a36Sopenharmony_ci IPC_P_PSI, 28062306a36Sopenharmony_ci IPC_P_EBL, 28162306a36Sopenharmony_ci IPC_P_RUN, 28262306a36Sopenharmony_ci}; 28362306a36Sopenharmony_ci 28462306a36Sopenharmony_ci/** 28562306a36Sopenharmony_ci * struct iosm_imem - Current state of the IPC shared memory. 28662306a36Sopenharmony_ci * @mmio: mmio instance to access CP MMIO area / 28762306a36Sopenharmony_ci * doorbell scratchpad. 28862306a36Sopenharmony_ci * @ipc_protocol: IPC Protocol instance 28962306a36Sopenharmony_ci * @ipc_task: Task for entry into ipc task queue 29062306a36Sopenharmony_ci * @wwan: WWAN device pointer 29162306a36Sopenharmony_ci * @mux: IP Data multiplexing state. 29262306a36Sopenharmony_ci * @sio: IPC SIO data structure pointer 29362306a36Sopenharmony_ci * @ipc_port: IPC PORT data structure pointer 29462306a36Sopenharmony_ci * @pcie: IPC PCIe 29562306a36Sopenharmony_ci * @trace: IPC trace data structure pointer 29662306a36Sopenharmony_ci * @dev: Pointer to device structure 29762306a36Sopenharmony_ci * @ipc_requested_state: Expected IPC state on CP. 29862306a36Sopenharmony_ci * @channels: Channel list with UL/DL pipe pairs. 29962306a36Sopenharmony_ci * @ipc_devlink: IPC Devlink data structure pointer 30062306a36Sopenharmony_ci * @ipc_status: local ipc_status 30162306a36Sopenharmony_ci * @nr_of_channels: number of configured channels 30262306a36Sopenharmony_ci * @startup_timer: startup timer for NAND support. 30362306a36Sopenharmony_ci * @hrtimer_period: Hr timer period 30462306a36Sopenharmony_ci * @tdupdate_timer: Delay the TD update doorbell. 30562306a36Sopenharmony_ci * @fast_update_timer: forced head pointer update delay timer. 30662306a36Sopenharmony_ci * @td_alloc_timer: Timer for DL pipe TD allocation retry 30762306a36Sopenharmony_ci * @adb_timer: Timer for finishing the ADB. 30862306a36Sopenharmony_ci * @rom_exit_code: Mapped boot rom exit code. 30962306a36Sopenharmony_ci * @enter_runtime: 1 means the transition to runtime phase was 31062306a36Sopenharmony_ci * executed. 31162306a36Sopenharmony_ci * @ul_pend_sem: Semaphore to wait/complete of UL TDs 31262306a36Sopenharmony_ci * before closing pipe. 31362306a36Sopenharmony_ci * @app_notify_ul_pend: Signal app if UL TD is pending 31462306a36Sopenharmony_ci * @dl_pend_sem: Semaphore to wait/complete of DL TDs 31562306a36Sopenharmony_ci * before closing pipe. 31662306a36Sopenharmony_ci * @app_notify_dl_pend: Signal app if DL TD is pending 31762306a36Sopenharmony_ci * @phase: Operating phase like runtime. 31862306a36Sopenharmony_ci * @pci_device_id: Device ID 31962306a36Sopenharmony_ci * @cp_version: CP version 32062306a36Sopenharmony_ci * @device_sleep: Device sleep state 32162306a36Sopenharmony_ci * @run_state_worker: Pointer to worker component for device 32262306a36Sopenharmony_ci * setup operations to be called when modem 32362306a36Sopenharmony_ci * reaches RUN state 32462306a36Sopenharmony_ci * @ev_irq_pending: 0 means inform the IPC tasklet to 32562306a36Sopenharmony_ci * process the irq actions. 32662306a36Sopenharmony_ci * @flag: Flag to monitor the state of driver 32762306a36Sopenharmony_ci * @td_update_timer_suspended: if true then td update timer suspend 32862306a36Sopenharmony_ci * @ev_mux_net_transmit_pending:0 means inform the IPC tasklet to pass 32962306a36Sopenharmony_ci * @reset_det_n: Reset detect flag 33062306a36Sopenharmony_ci * @pcie_wake_n: Pcie wake flag 33162306a36Sopenharmony_ci * @debugfs_wwan_dir: WWAN Debug FS directory entry 33262306a36Sopenharmony_ci * @debugfs_dir: Debug FS directory for driver-specific entries 33362306a36Sopenharmony_ci */ 33462306a36Sopenharmony_cistruct iosm_imem { 33562306a36Sopenharmony_ci struct iosm_mmio *mmio; 33662306a36Sopenharmony_ci struct iosm_protocol *ipc_protocol; 33762306a36Sopenharmony_ci struct ipc_task *ipc_task; 33862306a36Sopenharmony_ci struct iosm_wwan *wwan; 33962306a36Sopenharmony_ci struct iosm_mux *mux; 34062306a36Sopenharmony_ci struct iosm_cdev *ipc_port[IPC_MEM_MAX_CHANNELS]; 34162306a36Sopenharmony_ci struct iosm_pcie *pcie; 34262306a36Sopenharmony_ci#ifdef CONFIG_WWAN_DEBUGFS 34362306a36Sopenharmony_ci struct iosm_trace *trace; 34462306a36Sopenharmony_ci#endif 34562306a36Sopenharmony_ci struct device *dev; 34662306a36Sopenharmony_ci enum ipc_mem_device_ipc_state ipc_requested_state; 34762306a36Sopenharmony_ci struct ipc_mem_channel channels[IPC_MEM_MAX_CHANNELS]; 34862306a36Sopenharmony_ci struct iosm_devlink *ipc_devlink; 34962306a36Sopenharmony_ci u32 ipc_status; 35062306a36Sopenharmony_ci u32 nr_of_channels; 35162306a36Sopenharmony_ci struct hrtimer startup_timer; 35262306a36Sopenharmony_ci ktime_t hrtimer_period; 35362306a36Sopenharmony_ci struct hrtimer tdupdate_timer; 35462306a36Sopenharmony_ci struct hrtimer fast_update_timer; 35562306a36Sopenharmony_ci struct hrtimer td_alloc_timer; 35662306a36Sopenharmony_ci struct hrtimer adb_timer; 35762306a36Sopenharmony_ci enum rom_exit_code rom_exit_code; 35862306a36Sopenharmony_ci u32 enter_runtime; 35962306a36Sopenharmony_ci struct completion ul_pend_sem; 36062306a36Sopenharmony_ci u32 app_notify_ul_pend; 36162306a36Sopenharmony_ci struct completion dl_pend_sem; 36262306a36Sopenharmony_ci u32 app_notify_dl_pend; 36362306a36Sopenharmony_ci enum ipc_phase phase; 36462306a36Sopenharmony_ci u16 pci_device_id; 36562306a36Sopenharmony_ci int cp_version; 36662306a36Sopenharmony_ci int device_sleep; 36762306a36Sopenharmony_ci struct work_struct run_state_worker; 36862306a36Sopenharmony_ci u8 ev_irq_pending[IPC_IRQ_VECTORS]; 36962306a36Sopenharmony_ci unsigned long flag; 37062306a36Sopenharmony_ci u8 td_update_timer_suspended:1, 37162306a36Sopenharmony_ci ev_mux_net_transmit_pending:1, 37262306a36Sopenharmony_ci reset_det_n:1, 37362306a36Sopenharmony_ci pcie_wake_n:1; 37462306a36Sopenharmony_ci#ifdef CONFIG_WWAN_DEBUGFS 37562306a36Sopenharmony_ci struct dentry *debugfs_wwan_dir; 37662306a36Sopenharmony_ci struct dentry *debugfs_dir; 37762306a36Sopenharmony_ci#endif 37862306a36Sopenharmony_ci}; 37962306a36Sopenharmony_ci 38062306a36Sopenharmony_ci/** 38162306a36Sopenharmony_ci * ipc_imem_init - Initialize the shared memory region 38262306a36Sopenharmony_ci * @pcie: Pointer to core driver data-struct 38362306a36Sopenharmony_ci * @device_id: PCI device ID 38462306a36Sopenharmony_ci * @mmio: Pointer to the mmio area 38562306a36Sopenharmony_ci * @dev: Pointer to device structure 38662306a36Sopenharmony_ci * 38762306a36Sopenharmony_ci * Returns: Initialized imem pointer on success else NULL 38862306a36Sopenharmony_ci */ 38962306a36Sopenharmony_cistruct iosm_imem *ipc_imem_init(struct iosm_pcie *pcie, unsigned int device_id, 39062306a36Sopenharmony_ci void __iomem *mmio, struct device *dev); 39162306a36Sopenharmony_ci 39262306a36Sopenharmony_ci/** 39362306a36Sopenharmony_ci * ipc_imem_pm_s2idle_sleep - Set PM variables to sleep/active for 39462306a36Sopenharmony_ci * s2idle sleep/active 39562306a36Sopenharmony_ci * @ipc_imem: Pointer to imem data-struct 39662306a36Sopenharmony_ci * @sleep: Set PM Variable to sleep/active 39762306a36Sopenharmony_ci */ 39862306a36Sopenharmony_civoid ipc_imem_pm_s2idle_sleep(struct iosm_imem *ipc_imem, bool sleep); 39962306a36Sopenharmony_ci 40062306a36Sopenharmony_ci/** 40162306a36Sopenharmony_ci * ipc_imem_pm_suspend - The HAL shall ask the shared memory layer 40262306a36Sopenharmony_ci * whether D3 is allowed. 40362306a36Sopenharmony_ci * @ipc_imem: Pointer to imem data-struct 40462306a36Sopenharmony_ci */ 40562306a36Sopenharmony_civoid ipc_imem_pm_suspend(struct iosm_imem *ipc_imem); 40662306a36Sopenharmony_ci 40762306a36Sopenharmony_ci/** 40862306a36Sopenharmony_ci * ipc_imem_pm_resume - The HAL shall inform the shared memory layer 40962306a36Sopenharmony_ci * that the device is active. 41062306a36Sopenharmony_ci * @ipc_imem: Pointer to imem data-struct 41162306a36Sopenharmony_ci */ 41262306a36Sopenharmony_civoid ipc_imem_pm_resume(struct iosm_imem *ipc_imem); 41362306a36Sopenharmony_ci 41462306a36Sopenharmony_ci/** 41562306a36Sopenharmony_ci * ipc_imem_cleanup - Inform CP and free the shared memory resources. 41662306a36Sopenharmony_ci * @ipc_imem: Pointer to imem data-struct 41762306a36Sopenharmony_ci */ 41862306a36Sopenharmony_civoid ipc_imem_cleanup(struct iosm_imem *ipc_imem); 41962306a36Sopenharmony_ci 42062306a36Sopenharmony_ci/** 42162306a36Sopenharmony_ci * ipc_imem_irq_process - Shift the IRQ actions to the IPC thread. 42262306a36Sopenharmony_ci * @ipc_imem: Pointer to imem data-struct 42362306a36Sopenharmony_ci * @irq: Irq number 42462306a36Sopenharmony_ci */ 42562306a36Sopenharmony_civoid ipc_imem_irq_process(struct iosm_imem *ipc_imem, int irq); 42662306a36Sopenharmony_ci 42762306a36Sopenharmony_ci/** 42862306a36Sopenharmony_ci * imem_get_device_sleep_state - Get the device sleep state value. 42962306a36Sopenharmony_ci * @ipc_imem: Pointer to imem instance 43062306a36Sopenharmony_ci * 43162306a36Sopenharmony_ci * Returns: device sleep state 43262306a36Sopenharmony_ci */ 43362306a36Sopenharmony_ciint imem_get_device_sleep_state(struct iosm_imem *ipc_imem); 43462306a36Sopenharmony_ci 43562306a36Sopenharmony_ci/** 43662306a36Sopenharmony_ci * ipc_imem_td_update_timer_suspend - Updates the TD Update Timer suspend flag. 43762306a36Sopenharmony_ci * @ipc_imem: Pointer to imem data-struct 43862306a36Sopenharmony_ci * @suspend: Flag to update. If TRUE then HP update doorbell is triggered to 43962306a36Sopenharmony_ci * device without any wait. If FALSE then HP update doorbell is 44062306a36Sopenharmony_ci * delayed until timeout. 44162306a36Sopenharmony_ci */ 44262306a36Sopenharmony_civoid ipc_imem_td_update_timer_suspend(struct iosm_imem *ipc_imem, bool suspend); 44362306a36Sopenharmony_ci 44462306a36Sopenharmony_ci/** 44562306a36Sopenharmony_ci * ipc_imem_channel_close - Release the channel resources. 44662306a36Sopenharmony_ci * @ipc_imem: Pointer to imem data-struct 44762306a36Sopenharmony_ci * @channel_id: Channel ID to be cleaned up. 44862306a36Sopenharmony_ci */ 44962306a36Sopenharmony_civoid ipc_imem_channel_close(struct iosm_imem *ipc_imem, int channel_id); 45062306a36Sopenharmony_ci 45162306a36Sopenharmony_ci/** 45262306a36Sopenharmony_ci * ipc_imem_channel_alloc - Reserves a channel 45362306a36Sopenharmony_ci * @ipc_imem: Pointer to imem data-struct 45462306a36Sopenharmony_ci * @index: ID to lookup from the preallocated list. 45562306a36Sopenharmony_ci * @ctype: Channel type. 45662306a36Sopenharmony_ci * 45762306a36Sopenharmony_ci * Returns: Index on success and failure value on error 45862306a36Sopenharmony_ci */ 45962306a36Sopenharmony_ciint ipc_imem_channel_alloc(struct iosm_imem *ipc_imem, int index, 46062306a36Sopenharmony_ci enum ipc_ctype ctype); 46162306a36Sopenharmony_ci 46262306a36Sopenharmony_ci/** 46362306a36Sopenharmony_ci * ipc_imem_channel_open - Establish the pipes. 46462306a36Sopenharmony_ci * @ipc_imem: Pointer to imem data-struct 46562306a36Sopenharmony_ci * @channel_id: Channel ID returned during alloc. 46662306a36Sopenharmony_ci * @db_id: Doorbell ID for trigger identifier. 46762306a36Sopenharmony_ci * 46862306a36Sopenharmony_ci * Returns: Pointer of ipc_mem_channel on success and NULL on failure. 46962306a36Sopenharmony_ci */ 47062306a36Sopenharmony_cistruct ipc_mem_channel *ipc_imem_channel_open(struct iosm_imem *ipc_imem, 47162306a36Sopenharmony_ci int channel_id, u32 db_id); 47262306a36Sopenharmony_ci 47362306a36Sopenharmony_ci/** 47462306a36Sopenharmony_ci * ipc_imem_td_update_timer_start - Starts the TD Update Timer if not running. 47562306a36Sopenharmony_ci * @ipc_imem: Pointer to imem data-struct 47662306a36Sopenharmony_ci */ 47762306a36Sopenharmony_civoid ipc_imem_td_update_timer_start(struct iosm_imem *ipc_imem); 47862306a36Sopenharmony_ci 47962306a36Sopenharmony_ci/** 48062306a36Sopenharmony_ci * ipc_imem_ul_write_td - Pass the channel UL list to protocol layer for TD 48162306a36Sopenharmony_ci * preparation and sending them to the device. 48262306a36Sopenharmony_ci * @ipc_imem: Pointer to imem data-struct 48362306a36Sopenharmony_ci * 48462306a36Sopenharmony_ci * Returns: TRUE of HP Doorbell trigger is pending. FALSE otherwise. 48562306a36Sopenharmony_ci */ 48662306a36Sopenharmony_cibool ipc_imem_ul_write_td(struct iosm_imem *ipc_imem); 48762306a36Sopenharmony_ci 48862306a36Sopenharmony_ci/** 48962306a36Sopenharmony_ci * ipc_imem_ul_send - Dequeue SKB from channel list and start with 49062306a36Sopenharmony_ci * the uplink transfer.If HP Doorbell is pending to be 49162306a36Sopenharmony_ci * triggered then starts the TD Update Timer. 49262306a36Sopenharmony_ci * @ipc_imem: Pointer to imem data-struct 49362306a36Sopenharmony_ci */ 49462306a36Sopenharmony_civoid ipc_imem_ul_send(struct iosm_imem *ipc_imem); 49562306a36Sopenharmony_ci 49662306a36Sopenharmony_ci/** 49762306a36Sopenharmony_ci * ipc_imem_channel_update - Set or modify pipe config of an existing channel 49862306a36Sopenharmony_ci * @ipc_imem: Pointer to imem data-struct 49962306a36Sopenharmony_ci * @id: Channel config index 50062306a36Sopenharmony_ci * @chnl_cfg: Channel config struct 50162306a36Sopenharmony_ci * @irq_moderation: Timer in usec for irq_moderation 50262306a36Sopenharmony_ci */ 50362306a36Sopenharmony_civoid ipc_imem_channel_update(struct iosm_imem *ipc_imem, int id, 50462306a36Sopenharmony_ci struct ipc_chnl_cfg chnl_cfg, u32 irq_moderation); 50562306a36Sopenharmony_ci 50662306a36Sopenharmony_ci/** 50762306a36Sopenharmony_ci * ipc_imem_channel_free -Free an IPC channel. 50862306a36Sopenharmony_ci * @channel: Channel to be freed 50962306a36Sopenharmony_ci */ 51062306a36Sopenharmony_civoid ipc_imem_channel_free(struct ipc_mem_channel *channel); 51162306a36Sopenharmony_ci 51262306a36Sopenharmony_ci/** 51362306a36Sopenharmony_ci * ipc_imem_hrtimer_stop - Stop the hrtimer 51462306a36Sopenharmony_ci * @hr_timer: Pointer to hrtimer instance 51562306a36Sopenharmony_ci */ 51662306a36Sopenharmony_civoid ipc_imem_hrtimer_stop(struct hrtimer *hr_timer); 51762306a36Sopenharmony_ci 51862306a36Sopenharmony_ci/** 51962306a36Sopenharmony_ci * ipc_imem_pipe_cleanup - Reset volatile pipe content for all channels 52062306a36Sopenharmony_ci * @ipc_imem: Pointer to imem data-struct 52162306a36Sopenharmony_ci * @pipe: Pipe to cleaned up 52262306a36Sopenharmony_ci */ 52362306a36Sopenharmony_civoid ipc_imem_pipe_cleanup(struct iosm_imem *ipc_imem, struct ipc_pipe *pipe); 52462306a36Sopenharmony_ci 52562306a36Sopenharmony_ci/** 52662306a36Sopenharmony_ci * ipc_imem_pipe_close - Send msg to device to close pipe 52762306a36Sopenharmony_ci * @ipc_imem: Pointer to imem data-struct 52862306a36Sopenharmony_ci * @pipe: Pipe to be closed 52962306a36Sopenharmony_ci */ 53062306a36Sopenharmony_civoid ipc_imem_pipe_close(struct iosm_imem *ipc_imem, struct ipc_pipe *pipe); 53162306a36Sopenharmony_ci 53262306a36Sopenharmony_ci/** 53362306a36Sopenharmony_ci * ipc_imem_phase_update - Get the CP execution state 53462306a36Sopenharmony_ci * and map it to the AP phase. 53562306a36Sopenharmony_ci * @ipc_imem: Pointer to imem data-struct 53662306a36Sopenharmony_ci * 53762306a36Sopenharmony_ci * Returns: Current ap updated phase 53862306a36Sopenharmony_ci */ 53962306a36Sopenharmony_cienum ipc_phase ipc_imem_phase_update(struct iosm_imem *ipc_imem); 54062306a36Sopenharmony_ci 54162306a36Sopenharmony_ci/** 54262306a36Sopenharmony_ci * ipc_imem_phase_get_string - Return the current operation 54362306a36Sopenharmony_ci * phase as string. 54462306a36Sopenharmony_ci * @phase: AP phase 54562306a36Sopenharmony_ci * 54662306a36Sopenharmony_ci * Returns: AP phase string 54762306a36Sopenharmony_ci */ 54862306a36Sopenharmony_ciconst char *ipc_imem_phase_get_string(enum ipc_phase phase); 54962306a36Sopenharmony_ci 55062306a36Sopenharmony_ci/** 55162306a36Sopenharmony_ci * ipc_imem_msg_send_feature_set - Send feature set message to modem 55262306a36Sopenharmony_ci * @ipc_imem: Pointer to imem data-struct 55362306a36Sopenharmony_ci * @reset_enable: 0 = out-of-band, 1 = in-band-crash notification 55462306a36Sopenharmony_ci * @atomic_ctx: if disabled call in tasklet context 55562306a36Sopenharmony_ci * 55662306a36Sopenharmony_ci */ 55762306a36Sopenharmony_civoid ipc_imem_msg_send_feature_set(struct iosm_imem *ipc_imem, 55862306a36Sopenharmony_ci unsigned int reset_enable, bool atomic_ctx); 55962306a36Sopenharmony_ci 56062306a36Sopenharmony_ci/** 56162306a36Sopenharmony_ci * ipc_imem_ipc_init_check - Send the init event to CP, wait a certain time and 56262306a36Sopenharmony_ci * set CP to runtime with the context information 56362306a36Sopenharmony_ci * @ipc_imem: Pointer to imem data-struct 56462306a36Sopenharmony_ci */ 56562306a36Sopenharmony_civoid ipc_imem_ipc_init_check(struct iosm_imem *ipc_imem); 56662306a36Sopenharmony_ci 56762306a36Sopenharmony_ci/** 56862306a36Sopenharmony_ci * ipc_imem_channel_init - Initialize the channel list with UL/DL pipe pairs. 56962306a36Sopenharmony_ci * @ipc_imem: Pointer to imem data-struct 57062306a36Sopenharmony_ci * @ctype: Channel type 57162306a36Sopenharmony_ci * @chnl_cfg: Channel configuration struct 57262306a36Sopenharmony_ci * @irq_moderation: Timer in usec for irq_moderation 57362306a36Sopenharmony_ci */ 57462306a36Sopenharmony_civoid ipc_imem_channel_init(struct iosm_imem *ipc_imem, enum ipc_ctype ctype, 57562306a36Sopenharmony_ci struct ipc_chnl_cfg chnl_cfg, u32 irq_moderation); 57662306a36Sopenharmony_ci 57762306a36Sopenharmony_ci/** 57862306a36Sopenharmony_ci * ipc_imem_devlink_trigger_chip_info - Inform devlink that the chip 57962306a36Sopenharmony_ci * information are available if the 58062306a36Sopenharmony_ci * flashing to RAM interworking shall be 58162306a36Sopenharmony_ci * executed. 58262306a36Sopenharmony_ci * @ipc_imem: Pointer to imem structure 58362306a36Sopenharmony_ci * 58462306a36Sopenharmony_ci * Returns: 0 on success, -1 on failure 58562306a36Sopenharmony_ci */ 58662306a36Sopenharmony_ciint ipc_imem_devlink_trigger_chip_info(struct iosm_imem *ipc_imem); 58762306a36Sopenharmony_ci 58862306a36Sopenharmony_civoid ipc_imem_adb_timer_start(struct iosm_imem *ipc_imem); 58962306a36Sopenharmony_ci 59062306a36Sopenharmony_ci#endif 591