1 /* SPDX-License-Identifier: GPL-2.0-only
2  *
3  * Copyright (C) 2020-21 Intel Corporation.
4  */
5 
6 #ifndef IOSM_IPC_IMEM_OPS_H
7 #define IOSM_IPC_IMEM_OPS_H
8 
9 #include "iosm_ipc_mux_codec.h"
10 
11 /* Maximum wait time for blocking read */
12 #define IPC_READ_TIMEOUT 3000
13 
14 /* The delay in ms for defering the unregister */
15 #define SIO_UNREGISTER_DEFER_DELAY_MS 1
16 
17 /* Default delay till CP PSI image is running and modem updates the
18  * execution stage.
19  * unit : milliseconds
20  */
21 #define PSI_START_DEFAULT_TIMEOUT 3000
22 
23 /* Default time out when closing SIO, till the modem is in
24  * running state.
25  * unit : milliseconds
26  */
27 #define BOOT_CHECK_DEFAULT_TIMEOUT 400
28 
29 /* IP MUX channel range */
30 #define IP_MUX_SESSION_START 0
31 #define IP_MUX_SESSION_END 7
32 
33 /* Default IP MUX channel */
34 #define IP_MUX_SESSION_DEFAULT	0
35 
36 /**
37  * ipc_imem_sys_port_open - Open a port link to CP.
38  * @ipc_imem:	Imem instance.
39  * @chl_id:	Channel Indentifier.
40  * @hp_id:	HP Indentifier.
41  *
42  * Return: channel instance on success, NULL for failure
43  */
44 struct ipc_mem_channel *ipc_imem_sys_port_open(struct iosm_imem *ipc_imem,
45 					       int chl_id, int hp_id);
46 
47 /**
48  * ipc_imem_sys_cdev_close - Release a sio link to CP.
49  * @ipc_cdev:		iosm sio instance.
50  */
51 void ipc_imem_sys_cdev_close(struct iosm_cdev *ipc_cdev);
52 
53 /**
54  * ipc_imem_sys_cdev_write - Route the uplink buffer to CP.
55  * @ipc_cdev:		iosm_cdev instance.
56  * @skb:		Pointer to skb.
57  *
58  * Return: 0 on success and failure value on error
59  */
60 int ipc_imem_sys_cdev_write(struct iosm_cdev *ipc_cdev, struct sk_buff *skb);
61 
62 /**
63  * ipc_imem_sys_wwan_open - Open packet data online channel between network
64  *			layer and CP.
65  * @ipc_imem:		Imem instance.
66  * @if_id:		ip link tag of the net device.
67  *
68  * Return: Channel ID on success and failure value on error
69  */
70 int ipc_imem_sys_wwan_open(struct iosm_imem *ipc_imem, int if_id);
71 
72 /**
73  * ipc_imem_sys_wwan_close - Close packet data online channel between network
74  *			 layer and CP.
75  * @ipc_imem:		Imem instance.
76  * @if_id:		IP link id net device.
77  * @channel_id:		Channel ID to be closed.
78  */
79 void ipc_imem_sys_wwan_close(struct iosm_imem *ipc_imem, int if_id,
80 			     int channel_id);
81 
82 /**
83  * ipc_imem_sys_wwan_transmit - Function for transfer UL data
84  * @ipc_imem:		Imem instance.
85  * @if_id:		link ID of the device.
86  * @channel_id:		Channel ID used
87  * @skb:		Pointer to sk buffer
88  *
89  * Return: 0 on success and failure value on error
90  */
91 int ipc_imem_sys_wwan_transmit(struct iosm_imem *ipc_imem, int if_id,
92 			       int channel_id, struct sk_buff *skb);
93 /**
94  * ipc_imem_wwan_channel_init - Initializes WWAN channels and the channel for
95  *				MUX.
96  * @ipc_imem:		Pointer to iosm_imem struct.
97  * @mux_type:		Type of mux protocol.
98  */
99 void ipc_imem_wwan_channel_init(struct iosm_imem *ipc_imem,
100 				enum ipc_mux_protocol mux_type);
101 
102 /**
103  * ipc_imem_sys_devlink_open - Open a Flash/CD Channel link to CP
104  * @ipc_imem:   iosm_imem instance
105  *
106  * Return:	channel instance on success, NULL for failure
107  */
108 struct ipc_mem_channel *ipc_imem_sys_devlink_open(struct iosm_imem *ipc_imem);
109 
110 /**
111  * ipc_imem_sys_devlink_close - Release a Flash/CD channel link to CP
112  * @ipc_devlink:	Pointer to ipc_devlink data-struct
113  *
114  */
115 void ipc_imem_sys_devlink_close(struct iosm_devlink *ipc_devlink);
116 
117 /**
118  * ipc_imem_sys_devlink_notify_rx - Receive downlink characters from CP,
119  *				the downlink skbuf is added at the end of the
120  *				downlink or rx list
121  * @ipc_devlink:	Pointer to ipc_devlink data-struct
122  * @skb:		Pointer to sk buffer
123  */
124 void ipc_imem_sys_devlink_notify_rx(struct iosm_devlink *ipc_devlink,
125 				    struct sk_buff *skb);
126 
127 /**
128  * ipc_imem_sys_devlink_read - Copy the rx data and free the skbuf
129  * @ipc_devlink:	Devlink instance
130  * @data:		Buffer to read the data from modem
131  * @bytes_to_read:	Size of destination buffer
132  * @bytes_read:		Number of bytes read
133  *
134  * Return: 0 on success and failure value on error
135  */
136 int ipc_imem_sys_devlink_read(struct iosm_devlink *ipc_devlink, u8 *data,
137 			      u32 bytes_to_read, u32 *bytes_read);
138 
139 /**
140  * ipc_imem_sys_devlink_write - Route the uplink buffer to CP
141  * @ipc_devlink:	Devlink_sio instance
142  * @buf:		Pointer to buffer
143  * @count:		Number of data bytes to write
144  * Return:		0 on success and failure value on error
145  */
146 int ipc_imem_sys_devlink_write(struct iosm_devlink *ipc_devlink,
147 			       unsigned char *buf, int count);
148 #endif
149