13670970dSM Chetan Kumar /* SPDX-License-Identifier: GPL-2.0-only 23670970dSM Chetan Kumar * 33670970dSM Chetan Kumar * Copyright (C) 2020-21 Intel Corporation. 43670970dSM Chetan Kumar */ 53670970dSM Chetan Kumar 63670970dSM Chetan Kumar #ifndef IOSM_IPC_IMEM_H 73670970dSM Chetan Kumar #define IOSM_IPC_IMEM_H 83670970dSM Chetan Kumar 93670970dSM Chetan Kumar #include <linux/skbuff.h> 103670970dSM Chetan Kumar 113670970dSM Chetan Kumar #include "iosm_ipc_mmio.h" 123670970dSM Chetan Kumar #include "iosm_ipc_pcie.h" 133670970dSM Chetan Kumar #include "iosm_ipc_uevent.h" 143670970dSM Chetan Kumar #include "iosm_ipc_wwan.h" 153670970dSM Chetan Kumar #include "iosm_ipc_task_queue.h" 163670970dSM Chetan Kumar 173670970dSM Chetan Kumar struct ipc_chnl_cfg; 183670970dSM Chetan Kumar 193670970dSM Chetan Kumar /* IRQ moderation in usec */ 203670970dSM Chetan Kumar #define IRQ_MOD_OFF 0 213670970dSM Chetan Kumar #define IRQ_MOD_NET 1000 223670970dSM Chetan Kumar #define IRQ_MOD_TRC 4000 233670970dSM Chetan Kumar 243670970dSM Chetan Kumar /* Either the PSI image is accepted by CP or the suspended flash tool is waken, 253670970dSM Chetan Kumar * informed that the CP ROM driver is not ready to process the PSI image. 263670970dSM Chetan Kumar * unit : milliseconds 273670970dSM Chetan Kumar */ 283670970dSM Chetan Kumar #define IPC_PSI_TRANSFER_TIMEOUT 3000 293670970dSM Chetan Kumar 303670970dSM Chetan Kumar /* Timeout in 20 msec to wait for the modem to boot up to 313670970dSM Chetan Kumar * IPC_MEM_DEVICE_IPC_INIT state. 323670970dSM Chetan Kumar * unit : milliseconds (500 * ipc_util_msleep(20)) 333670970dSM Chetan Kumar */ 343670970dSM Chetan Kumar #define IPC_MODEM_BOOT_TIMEOUT 500 353670970dSM Chetan Kumar 363670970dSM Chetan Kumar /* Wait timeout for ipc status reflects IPC_MEM_DEVICE_IPC_UNINIT 373670970dSM Chetan Kumar * unit : milliseconds 383670970dSM Chetan Kumar */ 393670970dSM Chetan Kumar #define IPC_MODEM_UNINIT_TIMEOUT_MS 30 403670970dSM Chetan Kumar 413670970dSM Chetan Kumar /* Pending time for processing data. 423670970dSM Chetan Kumar * unit : milliseconds 433670970dSM Chetan Kumar */ 443670970dSM Chetan Kumar #define IPC_PEND_DATA_TIMEOUT 500 453670970dSM Chetan Kumar 463670970dSM Chetan Kumar /* The timeout in milliseconds for application to wait for remote time. */ 473670970dSM Chetan Kumar #define IPC_REMOTE_TS_TIMEOUT_MS 10 483670970dSM Chetan Kumar 493670970dSM Chetan Kumar /* Timeout for TD allocation retry. 503670970dSM Chetan Kumar * unit : milliseconds 513670970dSM Chetan Kumar */ 523670970dSM Chetan Kumar #define IPC_TD_ALLOC_TIMER_PERIOD_MS 100 533670970dSM Chetan Kumar 543670970dSM Chetan Kumar /* Host sleep target is host */ 553670970dSM Chetan Kumar #define IPC_HOST_SLEEP_HOST 0 563670970dSM Chetan Kumar 573670970dSM Chetan Kumar /* Host sleep target is device */ 583670970dSM Chetan Kumar #define IPC_HOST_SLEEP_DEVICE 1 593670970dSM Chetan Kumar 603670970dSM Chetan Kumar /* Sleep message, target host: AP enters sleep / target device: CP is 613670970dSM Chetan Kumar * allowed to enter sleep and shall use the host sleep protocol 623670970dSM Chetan Kumar */ 633670970dSM Chetan Kumar #define IPC_HOST_SLEEP_ENTER_SLEEP 0 643670970dSM Chetan Kumar 653670970dSM Chetan Kumar /* Sleep_message, target host: AP exits sleep / target device: CP is 663670970dSM Chetan Kumar * NOT allowed to enter sleep 673670970dSM Chetan Kumar */ 683670970dSM Chetan Kumar #define IPC_HOST_SLEEP_EXIT_SLEEP 1 693670970dSM Chetan Kumar 703670970dSM Chetan Kumar #define IMEM_IRQ_DONT_CARE (-1) 713670970dSM Chetan Kumar 728d9be063SM Chetan Kumar #define IPC_MEM_MAX_CHANNELS 8 733670970dSM Chetan Kumar 743670970dSM Chetan Kumar #define IPC_MEM_MUX_IP_SESSION_ENTRIES 8 753670970dSM Chetan Kumar 763670970dSM Chetan Kumar #define IPC_MEM_MUX_IP_CH_IF_ID 0 773670970dSM Chetan Kumar 783670970dSM Chetan Kumar #define TD_UPDATE_DEFAULT_TIMEOUT_USEC 1900 793670970dSM Chetan Kumar 803670970dSM Chetan Kumar #define FORCE_UPDATE_DEFAULT_TIMEOUT_USEC 500 813670970dSM Chetan Kumar 823670970dSM Chetan Kumar /* Sleep_message, target host: not applicable / target device: CP is 833670970dSM Chetan Kumar * allowed to enter sleep and shall NOT use the device sleep protocol 843670970dSM Chetan Kumar */ 853670970dSM Chetan Kumar #define IPC_HOST_SLEEP_ENTER_SLEEP_NO_PROTOCOL 2 863670970dSM Chetan Kumar 873670970dSM Chetan Kumar /* in_band_crash_signal IPC_MEM_INBAND_CRASH_SIG 883670970dSM Chetan Kumar * Modem crash notification configuration. If this value is non-zero then 893670970dSM Chetan Kumar * FEATURE_SET message will be sent to the Modem as a result the Modem will 903670970dSM Chetan Kumar * signal Crash via Execution Stage register. If this value is zero then Modem 913670970dSM Chetan Kumar * will use out-of-band method to notify about it's Crash. 923670970dSM Chetan Kumar */ 933670970dSM Chetan Kumar #define IPC_MEM_INBAND_CRASH_SIG 1 943670970dSM Chetan Kumar 953670970dSM Chetan Kumar /* Extra headroom to be allocated for DL SKBs to allow addition of Ethernet 963670970dSM Chetan Kumar * header 973670970dSM Chetan Kumar */ 983670970dSM Chetan Kumar #define IPC_MEM_DL_ETH_OFFSET 16 993670970dSM Chetan Kumar 1003670970dSM Chetan Kumar #define IPC_CB(skb) ((struct ipc_skb_cb *)((skb)->cb)) 1018d9be063SM Chetan Kumar #define IOSM_CHIP_INFO_SIZE_MAX 100 1023670970dSM Chetan Kumar 1033670970dSM Chetan Kumar #define FULLY_FUNCTIONAL 0 10407d3f274SM Chetan Kumar #define IOSM_DEVLINK_INIT 1 1053670970dSM Chetan Kumar 1063670970dSM Chetan Kumar /* List of the supported UL/DL pipes. */ 1073670970dSM Chetan Kumar enum ipc_mem_pipes { 1083670970dSM Chetan Kumar IPC_MEM_PIPE_0 = 0, 1093670970dSM Chetan Kumar IPC_MEM_PIPE_1, 1103670970dSM Chetan Kumar IPC_MEM_PIPE_2, 1113670970dSM Chetan Kumar IPC_MEM_PIPE_3, 1123670970dSM Chetan Kumar IPC_MEM_PIPE_4, 1133670970dSM Chetan Kumar IPC_MEM_PIPE_5, 1143670970dSM Chetan Kumar IPC_MEM_PIPE_6, 1153670970dSM Chetan Kumar IPC_MEM_PIPE_7, 1163670970dSM Chetan Kumar IPC_MEM_PIPE_8, 1173670970dSM Chetan Kumar IPC_MEM_PIPE_9, 1183670970dSM Chetan Kumar IPC_MEM_PIPE_10, 1193670970dSM Chetan Kumar IPC_MEM_PIPE_11, 1203670970dSM Chetan Kumar IPC_MEM_PIPE_12, 1213670970dSM Chetan Kumar IPC_MEM_PIPE_13, 1223670970dSM Chetan Kumar IPC_MEM_PIPE_14, 1233670970dSM Chetan Kumar IPC_MEM_PIPE_15, 1243670970dSM Chetan Kumar IPC_MEM_PIPE_16, 1253670970dSM Chetan Kumar IPC_MEM_PIPE_17, 1263670970dSM Chetan Kumar IPC_MEM_PIPE_18, 1273670970dSM Chetan Kumar IPC_MEM_PIPE_19, 1283670970dSM Chetan Kumar IPC_MEM_PIPE_20, 1293670970dSM Chetan Kumar IPC_MEM_PIPE_21, 1303670970dSM Chetan Kumar IPC_MEM_PIPE_22, 1313670970dSM Chetan Kumar IPC_MEM_PIPE_23, 1323670970dSM Chetan Kumar IPC_MEM_MAX_PIPES 1333670970dSM Chetan Kumar }; 1343670970dSM Chetan Kumar 1353670970dSM Chetan Kumar /* Enum defining channel states. */ 1363670970dSM Chetan Kumar enum ipc_channel_state { 1373670970dSM Chetan Kumar IMEM_CHANNEL_FREE, 1383670970dSM Chetan Kumar IMEM_CHANNEL_RESERVED, 1393670970dSM Chetan Kumar IMEM_CHANNEL_ACTIVE, 1403670970dSM Chetan Kumar IMEM_CHANNEL_CLOSING, 1413670970dSM Chetan Kumar }; 1423670970dSM Chetan Kumar 1433670970dSM Chetan Kumar /** 1443670970dSM Chetan Kumar * enum ipc_ctype - Enum defining supported channel type needed for control 1453670970dSM Chetan Kumar * /IP traffic. 1463670970dSM Chetan Kumar * @IPC_CTYPE_WWAN: Used for IP traffic 1473670970dSM Chetan Kumar * @IPC_CTYPE_CTRL: Used for Control Communication 1483670970dSM Chetan Kumar */ 1493670970dSM Chetan Kumar enum ipc_ctype { 1503670970dSM Chetan Kumar IPC_CTYPE_WWAN, 1513670970dSM Chetan Kumar IPC_CTYPE_CTRL, 1523670970dSM Chetan Kumar }; 1533670970dSM Chetan Kumar 1543670970dSM Chetan Kumar /* Pipe direction. */ 1553670970dSM Chetan Kumar enum ipc_mem_pipe_dir { 1563670970dSM Chetan Kumar IPC_MEM_DIR_UL, 1573670970dSM Chetan Kumar IPC_MEM_DIR_DL, 1583670970dSM Chetan Kumar }; 1593670970dSM Chetan Kumar 1603670970dSM Chetan Kumar /* HP update identifier. To be used as data for ipc_cp_irq_hpda_update() */ 1613670970dSM Chetan Kumar enum ipc_hp_identifier { 1623670970dSM Chetan Kumar IPC_HP_MR = 0, 1633670970dSM Chetan Kumar IPC_HP_PM_TRIGGER, 1643670970dSM Chetan Kumar IPC_HP_WAKEUP_SPEC_TMR, 1653670970dSM Chetan Kumar IPC_HP_TD_UPD_TMR_START, 1663670970dSM Chetan Kumar IPC_HP_TD_UPD_TMR, 1673670970dSM Chetan Kumar IPC_HP_FAST_TD_UPD_TMR, 1683670970dSM Chetan Kumar IPC_HP_UL_WRITE_TD, 1693670970dSM Chetan Kumar IPC_HP_DL_PROCESS, 1703670970dSM Chetan Kumar IPC_HP_NET_CHANNEL_INIT, 1713670970dSM Chetan Kumar IPC_HP_CDEV_OPEN, 1723670970dSM Chetan Kumar }; 1733670970dSM Chetan Kumar 1743670970dSM Chetan Kumar /** 1753670970dSM Chetan Kumar * struct ipc_pipe - Structure for Pipe. 1763670970dSM Chetan Kumar * @tdr_start: Ipc private protocol Transfer Descriptor Ring 1773670970dSM Chetan Kumar * @channel: Id of the sio device, set by imem_sio_open, 1783670970dSM Chetan Kumar * needed to pass DL char to the user terminal 1793670970dSM Chetan Kumar * @skbr_start: Circular buffer for skbuf and the buffer 1803670970dSM Chetan Kumar * reference in a tdr_start entry. 1813670970dSM Chetan Kumar * @phy_tdr_start: Transfer descriptor start address 1823670970dSM Chetan Kumar * @old_head: last head pointer reported to CP. 1833670970dSM Chetan Kumar * @old_tail: AP read position before CP moves the read 1843670970dSM Chetan Kumar * position to write/head. If CP has consumed the 1853670970dSM Chetan Kumar * buffers, AP has to freed the skbuf starting at 1863670970dSM Chetan Kumar * tdr_start[old_tail]. 1873670970dSM Chetan Kumar * @nr_of_entries: Number of elements of skb_start and tdr_start. 1883670970dSM Chetan Kumar * @max_nr_of_queued_entries: Maximum number of queued entries in TDR 1893670970dSM Chetan Kumar * @accumulation_backoff: Accumulation in usec for accumulation 1903670970dSM Chetan Kumar * backoff (0 = no acc backoff) 1913670970dSM Chetan Kumar * @irq_moderation: timer in usec for irq_moderation 1923670970dSM Chetan Kumar * (0=no irq moderation) 1933670970dSM Chetan Kumar * @pipe_nr: Pipe identification number 1943670970dSM Chetan Kumar * @irq: Interrupt vector 1953670970dSM Chetan Kumar * @dir: Direction of data stream in pipe 1963670970dSM Chetan Kumar * @buf_size: Buffer size (in bytes) for preallocated 1973670970dSM Chetan Kumar * buffers (for DL pipes) 1983670970dSM Chetan Kumar * @nr_of_queued_entries: Aueued number of entries 1993670970dSM Chetan Kumar * @is_open: Check for open pipe status 2003670970dSM Chetan Kumar */ 2013670970dSM Chetan Kumar struct ipc_pipe { 2023670970dSM Chetan Kumar struct ipc_protocol_td *tdr_start; 2033670970dSM Chetan Kumar struct ipc_mem_channel *channel; 2043670970dSM Chetan Kumar struct sk_buff **skbr_start; 2053670970dSM Chetan Kumar dma_addr_t phy_tdr_start; 2063670970dSM Chetan Kumar u32 old_head; 2073670970dSM Chetan Kumar u32 old_tail; 2083670970dSM Chetan Kumar u32 nr_of_entries; 2093670970dSM Chetan Kumar u32 max_nr_of_queued_entries; 2103670970dSM Chetan Kumar u32 accumulation_backoff; 2113670970dSM Chetan Kumar u32 irq_moderation; 2123670970dSM Chetan Kumar u32 pipe_nr; 2133670970dSM Chetan Kumar u32 irq; 2143670970dSM Chetan Kumar enum ipc_mem_pipe_dir dir; 2153670970dSM Chetan Kumar u32 buf_size; 2163670970dSM Chetan Kumar u16 nr_of_queued_entries; 2173670970dSM Chetan Kumar u8 is_open:1; 2183670970dSM Chetan Kumar }; 2193670970dSM Chetan Kumar 2203670970dSM Chetan Kumar /** 2213670970dSM Chetan Kumar * struct ipc_mem_channel - Structure for Channel. 2223670970dSM Chetan Kumar * @channel_id: Instance of the channel list and is return to the user 2233670970dSM Chetan Kumar * at the end of the open operation. 2243670970dSM Chetan Kumar * @ctype: Control or netif channel. 2253670970dSM Chetan Kumar * @index: unique index per ctype 2263670970dSM Chetan Kumar * @ul_pipe: pipe objects 2273670970dSM Chetan Kumar * @dl_pipe: pipe objects 2283670970dSM Chetan Kumar * @if_id: Interface ID 2293670970dSM Chetan Kumar * @net_err_count: Number of downlink errors returned by ipc_wwan_receive 2303670970dSM Chetan Kumar * interface at the entry point of the IP stack. 2313670970dSM Chetan Kumar * @state: Free, reserved or busy (in use). 2323670970dSM Chetan Kumar * @ul_sem: Needed for the blocking write or uplink transfer. 2333670970dSM Chetan Kumar * @ul_list: Uplink accumulator which is filled by the uplink 2343670970dSM Chetan Kumar * char app or IP stack. The socket buffer pointer are 2353670970dSM Chetan Kumar * added to the descriptor list in the kthread context. 2363670970dSM Chetan Kumar */ 2373670970dSM Chetan Kumar struct ipc_mem_channel { 2383670970dSM Chetan Kumar int channel_id; 2393670970dSM Chetan Kumar enum ipc_ctype ctype; 2403670970dSM Chetan Kumar int index; 2413670970dSM Chetan Kumar struct ipc_pipe ul_pipe; 2423670970dSM Chetan Kumar struct ipc_pipe dl_pipe; 2433670970dSM Chetan Kumar int if_id; 2443670970dSM Chetan Kumar u32 net_err_count; 2453670970dSM Chetan Kumar enum ipc_channel_state state; 2463670970dSM Chetan Kumar struct completion ul_sem; 2473670970dSM Chetan Kumar struct sk_buff_head ul_list; 2483670970dSM Chetan Kumar }; 2493670970dSM Chetan Kumar 2503670970dSM Chetan Kumar /** 2513670970dSM Chetan Kumar * enum ipc_phase - Different AP and CP phases. 2523670970dSM Chetan Kumar * The enums defined after "IPC_P_ROM" and before 2533670970dSM Chetan Kumar * "IPC_P_RUN" indicates the operating state where CP can 2543670970dSM Chetan Kumar * respond to any requests. So while introducing new phase 2553670970dSM Chetan Kumar * this shall be taken into consideration. 2563670970dSM Chetan Kumar * @IPC_P_OFF: On host PC, the PCIe device link settings are known 2573670970dSM Chetan Kumar * about the combined power on. PC is running, the driver 2583670970dSM Chetan Kumar * is loaded and CP is in power off mode. The PCIe bus 2593670970dSM Chetan Kumar * driver call the device power mode D3hot. In this phase 2603670970dSM Chetan Kumar * the driver the polls the device, until the device is in 2613670970dSM Chetan Kumar * the power on state and signals the power mode D0. 2623670970dSM Chetan Kumar * @IPC_P_OFF_REQ: The intermediate phase between cleanup activity starts 2633670970dSM Chetan Kumar * and ends. 2643670970dSM Chetan Kumar * @IPC_P_CRASH: The phase indicating CP crash 2653670970dSM Chetan Kumar * @IPC_P_CD_READY: The phase indicating CP core dump is ready 2663670970dSM Chetan Kumar * @IPC_P_ROM: After power on, CP starts in ROM mode and the IPC ROM 2673670970dSM Chetan Kumar * driver is waiting 150 ms for the AP active notification 2683670970dSM Chetan Kumar * saved in the PCI link status register. 2693670970dSM Chetan Kumar * @IPC_P_PSI: Primary signed image download phase 2703670970dSM Chetan Kumar * @IPC_P_EBL: Extended bootloader pahse 2713670970dSM Chetan Kumar * @IPC_P_RUN: The phase after flashing to RAM is the RUNTIME phase. 2723670970dSM Chetan Kumar */ 2733670970dSM Chetan Kumar enum ipc_phase { 2743670970dSM Chetan Kumar IPC_P_OFF, 2753670970dSM Chetan Kumar IPC_P_OFF_REQ, 2763670970dSM Chetan Kumar IPC_P_CRASH, 2773670970dSM Chetan Kumar IPC_P_CD_READY, 2783670970dSM Chetan Kumar IPC_P_ROM, 2793670970dSM Chetan Kumar IPC_P_PSI, 2803670970dSM Chetan Kumar IPC_P_EBL, 2813670970dSM Chetan Kumar IPC_P_RUN, 2823670970dSM Chetan Kumar }; 2833670970dSM Chetan Kumar 2843670970dSM Chetan Kumar /** 2853670970dSM Chetan Kumar * struct iosm_imem - Current state of the IPC shared memory. 2863670970dSM Chetan Kumar * @mmio: mmio instance to access CP MMIO area / 2873670970dSM Chetan Kumar * doorbell scratchpad. 2883670970dSM Chetan Kumar * @ipc_protocol: IPC Protocol instance 2893670970dSM Chetan Kumar * @ipc_task: Task for entry into ipc task queue 2903670970dSM Chetan Kumar * @wwan: WWAN device pointer 2913670970dSM Chetan Kumar * @mux: IP Data multiplexing state. 2923670970dSM Chetan Kumar * @sio: IPC SIO data structure pointer 2933670970dSM Chetan Kumar * @ipc_port: IPC PORT data structure pointer 2943670970dSM Chetan Kumar * @pcie: IPC PCIe 29500ef3256SM Chetan Kumar * @trace: IPC trace data structure pointer 2963670970dSM Chetan Kumar * @dev: Pointer to device structure 2973670970dSM Chetan Kumar * @ipc_requested_state: Expected IPC state on CP. 2983670970dSM Chetan Kumar * @channels: Channel list with UL/DL pipe pairs. 2998d9be063SM Chetan Kumar * @ipc_devlink: IPC Devlink data structure pointer 3003670970dSM Chetan Kumar * @ipc_status: local ipc_status 3013670970dSM Chetan Kumar * @nr_of_channels: number of configured channels 3023670970dSM Chetan Kumar * @startup_timer: startup timer for NAND support. 3033670970dSM Chetan Kumar * @hrtimer_period: Hr timer period 3043670970dSM Chetan Kumar * @tdupdate_timer: Delay the TD update doorbell. 3053670970dSM Chetan Kumar * @fast_update_timer: forced head pointer update delay timer. 3063670970dSM Chetan Kumar * @td_alloc_timer: Timer for DL pipe TD allocation retry 3071f52d7b6SM Chetan Kumar * @adb_timer: Timer for finishing the ADB. 3083670970dSM Chetan Kumar * @rom_exit_code: Mapped boot rom exit code. 3093670970dSM Chetan Kumar * @enter_runtime: 1 means the transition to runtime phase was 3103670970dSM Chetan Kumar * executed. 3113670970dSM Chetan Kumar * @ul_pend_sem: Semaphore to wait/complete of UL TDs 3123670970dSM Chetan Kumar * before closing pipe. 3133670970dSM Chetan Kumar * @app_notify_ul_pend: Signal app if UL TD is pending 3143670970dSM Chetan Kumar * @dl_pend_sem: Semaphore to wait/complete of DL TDs 3153670970dSM Chetan Kumar * before closing pipe. 3163670970dSM Chetan Kumar * @app_notify_dl_pend: Signal app if DL TD is pending 3173670970dSM Chetan Kumar * @phase: Operating phase like runtime. 3183670970dSM Chetan Kumar * @pci_device_id: Device ID 3193670970dSM Chetan Kumar * @cp_version: CP version 3203670970dSM Chetan Kumar * @device_sleep: Device sleep state 3213670970dSM Chetan Kumar * @run_state_worker: Pointer to worker component for device 3223670970dSM Chetan Kumar * setup operations to be called when modem 3233670970dSM Chetan Kumar * reaches RUN state 3243670970dSM Chetan Kumar * @ev_irq_pending: 0 means inform the IPC tasklet to 3253670970dSM Chetan Kumar * process the irq actions. 3263670970dSM Chetan Kumar * @flag: Flag to monitor the state of driver 3273670970dSM Chetan Kumar * @td_update_timer_suspended: if true then td update timer suspend 3283670970dSM Chetan Kumar * @ev_mux_net_transmit_pending:0 means inform the IPC tasklet to pass 3293670970dSM Chetan Kumar * @reset_det_n: Reset detect flag 3303670970dSM Chetan Kumar * @pcie_wake_n: Pcie wake flag 331*163f69aeSM Chetan Kumar * @debugfs_wwan_dir: WWAN Debug FS directory entry 332cf90098dSSergey Ryazanov * @debugfs_dir: Debug FS directory for driver-specific entries 3333670970dSM Chetan Kumar */ 3343670970dSM Chetan Kumar struct iosm_imem { 3353670970dSM Chetan Kumar struct iosm_mmio *mmio; 3363670970dSM Chetan Kumar struct iosm_protocol *ipc_protocol; 3373670970dSM Chetan Kumar struct ipc_task *ipc_task; 3383670970dSM Chetan Kumar struct iosm_wwan *wwan; 3393670970dSM Chetan Kumar struct iosm_mux *mux; 3403670970dSM Chetan Kumar struct iosm_cdev *ipc_port[IPC_MEM_MAX_CHANNELS]; 3413670970dSM Chetan Kumar struct iosm_pcie *pcie; 342283e6f5aSSergey Ryazanov #ifdef CONFIG_WWAN_DEBUGFS 34300ef3256SM Chetan Kumar struct iosm_trace *trace; 344283e6f5aSSergey Ryazanov #endif 3453670970dSM Chetan Kumar struct device *dev; 3463670970dSM Chetan Kumar enum ipc_mem_device_ipc_state ipc_requested_state; 3473670970dSM Chetan Kumar struct ipc_mem_channel channels[IPC_MEM_MAX_CHANNELS]; 3488d9be063SM Chetan Kumar struct iosm_devlink *ipc_devlink; 3493670970dSM Chetan Kumar u32 ipc_status; 3503670970dSM Chetan Kumar u32 nr_of_channels; 3513670970dSM Chetan Kumar struct hrtimer startup_timer; 3523670970dSM Chetan Kumar ktime_t hrtimer_period; 3533670970dSM Chetan Kumar struct hrtimer tdupdate_timer; 3543670970dSM Chetan Kumar struct hrtimer fast_update_timer; 3553670970dSM Chetan Kumar struct hrtimer td_alloc_timer; 3561f52d7b6SM Chetan Kumar struct hrtimer adb_timer; 3573670970dSM Chetan Kumar enum rom_exit_code rom_exit_code; 3583670970dSM Chetan Kumar u32 enter_runtime; 3593670970dSM Chetan Kumar struct completion ul_pend_sem; 3603670970dSM Chetan Kumar u32 app_notify_ul_pend; 3613670970dSM Chetan Kumar struct completion dl_pend_sem; 3623670970dSM Chetan Kumar u32 app_notify_dl_pend; 3633670970dSM Chetan Kumar enum ipc_phase phase; 3643670970dSM Chetan Kumar u16 pci_device_id; 3653670970dSM Chetan Kumar int cp_version; 3663670970dSM Chetan Kumar int device_sleep; 3673670970dSM Chetan Kumar struct work_struct run_state_worker; 3683670970dSM Chetan Kumar u8 ev_irq_pending[IPC_IRQ_VECTORS]; 3693670970dSM Chetan Kumar unsigned long flag; 3703670970dSM Chetan Kumar u8 td_update_timer_suspended:1, 3713670970dSM Chetan Kumar ev_mux_net_transmit_pending:1, 3723670970dSM Chetan Kumar reset_det_n:1, 3733670970dSM Chetan Kumar pcie_wake_n:1; 374283e6f5aSSergey Ryazanov #ifdef CONFIG_WWAN_DEBUGFS 375*163f69aeSM Chetan Kumar struct dentry *debugfs_wwan_dir; 376cf90098dSSergey Ryazanov struct dentry *debugfs_dir; 377283e6f5aSSergey Ryazanov #endif 3783670970dSM Chetan Kumar }; 3793670970dSM Chetan Kumar 3803670970dSM Chetan Kumar /** 3813670970dSM Chetan Kumar * ipc_imem_init - Initialize the shared memory region 3823670970dSM Chetan Kumar * @pcie: Pointer to core driver data-struct 3833670970dSM Chetan Kumar * @device_id: PCI device ID 3843670970dSM Chetan Kumar * @mmio: Pointer to the mmio area 3853670970dSM Chetan Kumar * @dev: Pointer to device structure 3863670970dSM Chetan Kumar * 3873670970dSM Chetan Kumar * Returns: Initialized imem pointer on success else NULL 3883670970dSM Chetan Kumar */ 3893670970dSM Chetan Kumar struct iosm_imem *ipc_imem_init(struct iosm_pcie *pcie, unsigned int device_id, 3903670970dSM Chetan Kumar void __iomem *mmio, struct device *dev); 3913670970dSM Chetan Kumar 3923670970dSM Chetan Kumar /** 3933670970dSM Chetan Kumar * ipc_imem_pm_s2idle_sleep - Set PM variables to sleep/active for 3943670970dSM Chetan Kumar * s2idle sleep/active 3953670970dSM Chetan Kumar * @ipc_imem: Pointer to imem data-struct 3963670970dSM Chetan Kumar * @sleep: Set PM Variable to sleep/active 3973670970dSM Chetan Kumar */ 3983670970dSM Chetan Kumar void ipc_imem_pm_s2idle_sleep(struct iosm_imem *ipc_imem, bool sleep); 3993670970dSM Chetan Kumar 4003670970dSM Chetan Kumar /** 4013670970dSM Chetan Kumar * ipc_imem_pm_suspend - The HAL shall ask the shared memory layer 4023670970dSM Chetan Kumar * whether D3 is allowed. 4033670970dSM Chetan Kumar * @ipc_imem: Pointer to imem data-struct 4043670970dSM Chetan Kumar */ 4053670970dSM Chetan Kumar void ipc_imem_pm_suspend(struct iosm_imem *ipc_imem); 4063670970dSM Chetan Kumar 4073670970dSM Chetan Kumar /** 4083670970dSM Chetan Kumar * ipc_imem_pm_resume - The HAL shall inform the shared memory layer 4093670970dSM Chetan Kumar * that the device is active. 4103670970dSM Chetan Kumar * @ipc_imem: Pointer to imem data-struct 4113670970dSM Chetan Kumar */ 4123670970dSM Chetan Kumar void ipc_imem_pm_resume(struct iosm_imem *ipc_imem); 4133670970dSM Chetan Kumar 4143670970dSM Chetan Kumar /** 4153670970dSM Chetan Kumar * ipc_imem_cleanup - Inform CP and free the shared memory resources. 4163670970dSM Chetan Kumar * @ipc_imem: Pointer to imem data-struct 4173670970dSM Chetan Kumar */ 4183670970dSM Chetan Kumar void ipc_imem_cleanup(struct iosm_imem *ipc_imem); 4193670970dSM Chetan Kumar 4203670970dSM Chetan Kumar /** 4213670970dSM Chetan Kumar * ipc_imem_irq_process - Shift the IRQ actions to the IPC thread. 4223670970dSM Chetan Kumar * @ipc_imem: Pointer to imem data-struct 4233670970dSM Chetan Kumar * @irq: Irq number 4243670970dSM Chetan Kumar */ 4253670970dSM Chetan Kumar void ipc_imem_irq_process(struct iosm_imem *ipc_imem, int irq); 4263670970dSM Chetan Kumar 4273670970dSM Chetan Kumar /** 4283670970dSM Chetan Kumar * imem_get_device_sleep_state - Get the device sleep state value. 4293670970dSM Chetan Kumar * @ipc_imem: Pointer to imem instance 4303670970dSM Chetan Kumar * 4313670970dSM Chetan Kumar * Returns: device sleep state 4323670970dSM Chetan Kumar */ 4333670970dSM Chetan Kumar int imem_get_device_sleep_state(struct iosm_imem *ipc_imem); 4343670970dSM Chetan Kumar 4353670970dSM Chetan Kumar /** 4363670970dSM Chetan Kumar * ipc_imem_td_update_timer_suspend - Updates the TD Update Timer suspend flag. 4373670970dSM Chetan Kumar * @ipc_imem: Pointer to imem data-struct 4383670970dSM Chetan Kumar * @suspend: Flag to update. If TRUE then HP update doorbell is triggered to 4393670970dSM Chetan Kumar * device without any wait. If FALSE then HP update doorbell is 4403670970dSM Chetan Kumar * delayed until timeout. 4413670970dSM Chetan Kumar */ 4423670970dSM Chetan Kumar void ipc_imem_td_update_timer_suspend(struct iosm_imem *ipc_imem, bool suspend); 4433670970dSM Chetan Kumar 4443670970dSM Chetan Kumar /** 4453670970dSM Chetan Kumar * ipc_imem_channel_close - Release the channel resources. 4463670970dSM Chetan Kumar * @ipc_imem: Pointer to imem data-struct 4473670970dSM Chetan Kumar * @channel_id: Channel ID to be cleaned up. 4483670970dSM Chetan Kumar */ 4493670970dSM Chetan Kumar void ipc_imem_channel_close(struct iosm_imem *ipc_imem, int channel_id); 4503670970dSM Chetan Kumar 4513670970dSM Chetan Kumar /** 4523670970dSM Chetan Kumar * ipc_imem_channel_alloc - Reserves a channel 4533670970dSM Chetan Kumar * @ipc_imem: Pointer to imem data-struct 4543670970dSM Chetan Kumar * @index: ID to lookup from the preallocated list. 4553670970dSM Chetan Kumar * @ctype: Channel type. 4563670970dSM Chetan Kumar * 4573670970dSM Chetan Kumar * Returns: Index on success and failure value on error 4583670970dSM Chetan Kumar */ 4593670970dSM Chetan Kumar int ipc_imem_channel_alloc(struct iosm_imem *ipc_imem, int index, 4603670970dSM Chetan Kumar enum ipc_ctype ctype); 4613670970dSM Chetan Kumar 4623670970dSM Chetan Kumar /** 4633670970dSM Chetan Kumar * ipc_imem_channel_open - Establish the pipes. 4643670970dSM Chetan Kumar * @ipc_imem: Pointer to imem data-struct 4653670970dSM Chetan Kumar * @channel_id: Channel ID returned during alloc. 4663670970dSM Chetan Kumar * @db_id: Doorbell ID for trigger identifier. 4673670970dSM Chetan Kumar * 4683670970dSM Chetan Kumar * Returns: Pointer of ipc_mem_channel on success and NULL on failure. 4693670970dSM Chetan Kumar */ 4703670970dSM Chetan Kumar struct ipc_mem_channel *ipc_imem_channel_open(struct iosm_imem *ipc_imem, 4713670970dSM Chetan Kumar int channel_id, u32 db_id); 4723670970dSM Chetan Kumar 4733670970dSM Chetan Kumar /** 4743670970dSM Chetan Kumar * ipc_imem_td_update_timer_start - Starts the TD Update Timer if not running. 4753670970dSM Chetan Kumar * @ipc_imem: Pointer to imem data-struct 4763670970dSM Chetan Kumar */ 4773670970dSM Chetan Kumar void ipc_imem_td_update_timer_start(struct iosm_imem *ipc_imem); 4783670970dSM Chetan Kumar 4793670970dSM Chetan Kumar /** 4803670970dSM Chetan Kumar * ipc_imem_ul_write_td - Pass the channel UL list to protocol layer for TD 4813670970dSM Chetan Kumar * preparation and sending them to the device. 4823670970dSM Chetan Kumar * @ipc_imem: Pointer to imem data-struct 4833670970dSM Chetan Kumar * 4843670970dSM Chetan Kumar * Returns: TRUE of HP Doorbell trigger is pending. FALSE otherwise. 4853670970dSM Chetan Kumar */ 4863670970dSM Chetan Kumar bool ipc_imem_ul_write_td(struct iosm_imem *ipc_imem); 4873670970dSM Chetan Kumar 4883670970dSM Chetan Kumar /** 4893670970dSM Chetan Kumar * ipc_imem_ul_send - Dequeue SKB from channel list and start with 4903670970dSM Chetan Kumar * the uplink transfer.If HP Doorbell is pending to be 4913670970dSM Chetan Kumar * triggered then starts the TD Update Timer. 4923670970dSM Chetan Kumar * @ipc_imem: Pointer to imem data-struct 4933670970dSM Chetan Kumar */ 4943670970dSM Chetan Kumar void ipc_imem_ul_send(struct iosm_imem *ipc_imem); 4953670970dSM Chetan Kumar 4963670970dSM Chetan Kumar /** 4973670970dSM Chetan Kumar * ipc_imem_channel_update - Set or modify pipe config of an existing channel 4983670970dSM Chetan Kumar * @ipc_imem: Pointer to imem data-struct 4993670970dSM Chetan Kumar * @id: Channel config index 5003670970dSM Chetan Kumar * @chnl_cfg: Channel config struct 5013670970dSM Chetan Kumar * @irq_moderation: Timer in usec for irq_moderation 5023670970dSM Chetan Kumar */ 5033670970dSM Chetan Kumar void ipc_imem_channel_update(struct iosm_imem *ipc_imem, int id, 5043670970dSM Chetan Kumar struct ipc_chnl_cfg chnl_cfg, u32 irq_moderation); 5053670970dSM Chetan Kumar 5063670970dSM Chetan Kumar /** 5073670970dSM Chetan Kumar * ipc_imem_channel_free -Free an IPC channel. 5083670970dSM Chetan Kumar * @channel: Channel to be freed 5093670970dSM Chetan Kumar */ 5103670970dSM Chetan Kumar void ipc_imem_channel_free(struct ipc_mem_channel *channel); 5113670970dSM Chetan Kumar 5123670970dSM Chetan Kumar /** 5133670970dSM Chetan Kumar * ipc_imem_hrtimer_stop - Stop the hrtimer 5143670970dSM Chetan Kumar * @hr_timer: Pointer to hrtimer instance 5153670970dSM Chetan Kumar */ 5163670970dSM Chetan Kumar void ipc_imem_hrtimer_stop(struct hrtimer *hr_timer); 5173670970dSM Chetan Kumar 5183670970dSM Chetan Kumar /** 5193670970dSM Chetan Kumar * ipc_imem_pipe_cleanup - Reset volatile pipe content for all channels 5203670970dSM Chetan Kumar * @ipc_imem: Pointer to imem data-struct 5213670970dSM Chetan Kumar * @pipe: Pipe to cleaned up 5223670970dSM Chetan Kumar */ 5233670970dSM Chetan Kumar void ipc_imem_pipe_cleanup(struct iosm_imem *ipc_imem, struct ipc_pipe *pipe); 5243670970dSM Chetan Kumar 5253670970dSM Chetan Kumar /** 5263670970dSM Chetan Kumar * ipc_imem_pipe_close - Send msg to device to close pipe 5273670970dSM Chetan Kumar * @ipc_imem: Pointer to imem data-struct 5283670970dSM Chetan Kumar * @pipe: Pipe to be closed 5293670970dSM Chetan Kumar */ 5303670970dSM Chetan Kumar void ipc_imem_pipe_close(struct iosm_imem *ipc_imem, struct ipc_pipe *pipe); 5313670970dSM Chetan Kumar 5323670970dSM Chetan Kumar /** 5333670970dSM Chetan Kumar * ipc_imem_phase_update - Get the CP execution state 5343670970dSM Chetan Kumar * and map it to the AP phase. 5353670970dSM Chetan Kumar * @ipc_imem: Pointer to imem data-struct 5363670970dSM Chetan Kumar * 5373670970dSM Chetan Kumar * Returns: Current ap updated phase 5383670970dSM Chetan Kumar */ 5393670970dSM Chetan Kumar enum ipc_phase ipc_imem_phase_update(struct iosm_imem *ipc_imem); 5403670970dSM Chetan Kumar 5413670970dSM Chetan Kumar /** 5423670970dSM Chetan Kumar * ipc_imem_phase_get_string - Return the current operation 5433670970dSM Chetan Kumar * phase as string. 5443670970dSM Chetan Kumar * @phase: AP phase 5453670970dSM Chetan Kumar * 5463670970dSM Chetan Kumar * Returns: AP phase string 5473670970dSM Chetan Kumar */ 5483670970dSM Chetan Kumar const char *ipc_imem_phase_get_string(enum ipc_phase phase); 5493670970dSM Chetan Kumar 5503670970dSM Chetan Kumar /** 5513670970dSM Chetan Kumar * ipc_imem_msg_send_feature_set - Send feature set message to modem 5523670970dSM Chetan Kumar * @ipc_imem: Pointer to imem data-struct 5533670970dSM Chetan Kumar * @reset_enable: 0 = out-of-band, 1 = in-band-crash notification 5543670970dSM Chetan Kumar * @atomic_ctx: if disabled call in tasklet context 5553670970dSM Chetan Kumar * 5563670970dSM Chetan Kumar */ 5573670970dSM Chetan Kumar void ipc_imem_msg_send_feature_set(struct iosm_imem *ipc_imem, 5583670970dSM Chetan Kumar unsigned int reset_enable, bool atomic_ctx); 5593670970dSM Chetan Kumar 5603670970dSM Chetan Kumar /** 5613670970dSM Chetan Kumar * ipc_imem_ipc_init_check - Send the init event to CP, wait a certain time and 5623670970dSM Chetan Kumar * set CP to runtime with the context information 5633670970dSM Chetan Kumar * @ipc_imem: Pointer to imem data-struct 5643670970dSM Chetan Kumar */ 5653670970dSM Chetan Kumar void ipc_imem_ipc_init_check(struct iosm_imem *ipc_imem); 5663670970dSM Chetan Kumar 5673670970dSM Chetan Kumar /** 5683670970dSM Chetan Kumar * ipc_imem_channel_init - Initialize the channel list with UL/DL pipe pairs. 5693670970dSM Chetan Kumar * @ipc_imem: Pointer to imem data-struct 5703670970dSM Chetan Kumar * @ctype: Channel type 5713670970dSM Chetan Kumar * @chnl_cfg: Channel configuration struct 5723670970dSM Chetan Kumar * @irq_moderation: Timer in usec for irq_moderation 5733670970dSM Chetan Kumar */ 5743670970dSM Chetan Kumar void ipc_imem_channel_init(struct iosm_imem *ipc_imem, enum ipc_ctype ctype, 5753670970dSM Chetan Kumar struct ipc_chnl_cfg chnl_cfg, u32 irq_moderation); 5768d9be063SM Chetan Kumar 5778d9be063SM Chetan Kumar /** 5788d9be063SM Chetan Kumar * ipc_imem_devlink_trigger_chip_info - Inform devlink that the chip 5798d9be063SM Chetan Kumar * information are available if the 5808d9be063SM Chetan Kumar * flashing to RAM interworking shall be 5818d9be063SM Chetan Kumar * executed. 5828d9be063SM Chetan Kumar * @ipc_imem: Pointer to imem structure 5838d9be063SM Chetan Kumar * 5848d9be063SM Chetan Kumar * Returns: 0 on success, -1 on failure 5858d9be063SM Chetan Kumar */ 5868d9be063SM Chetan Kumar int ipc_imem_devlink_trigger_chip_info(struct iosm_imem *ipc_imem); 5871f52d7b6SM Chetan Kumar 5881f52d7b6SM Chetan Kumar void ipc_imem_adb_timer_start(struct iosm_imem *ipc_imem); 5891f52d7b6SM Chetan Kumar 5903670970dSM Chetan Kumar #endif 591