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 void ipc_imem_sys_port_close(struct iosm_imem *ipc_imem,
47 			     struct ipc_mem_channel *channel);
48 
49 /**
50  * ipc_imem_sys_cdev_write - Route the uplink buffer to CP.
51  * @ipc_cdev:		iosm_cdev instance.
52  * @skb:		Pointer to skb.
53  *
54  * Return: 0 on success and failure value on error
55  */
56 int ipc_imem_sys_cdev_write(struct iosm_cdev *ipc_cdev, struct sk_buff *skb);
57 
58 /**
59  * ipc_imem_sys_wwan_open - Open packet data online channel between network
60  *			layer and CP.
61  * @ipc_imem:		Imem instance.
62  * @if_id:		ip link tag of the net device.
63  *
64  * Return: Channel ID on success and failure value on error
65  */
66 int ipc_imem_sys_wwan_open(struct iosm_imem *ipc_imem, int if_id);
67 
68 /**
69  * ipc_imem_sys_wwan_close - Close packet data online channel between network
70  *			 layer and CP.
71  * @ipc_imem:		Imem instance.
72  * @if_id:		IP link id net device.
73  * @channel_id:		Channel ID to be closed.
74  */
75 void ipc_imem_sys_wwan_close(struct iosm_imem *ipc_imem, int if_id,
76 			     int channel_id);
77 
78 /**
79  * ipc_imem_sys_wwan_transmit - Function for transfer UL data
80  * @ipc_imem:		Imem instance.
81  * @if_id:		link ID of the device.
82  * @channel_id:		Channel ID used
83  * @skb:		Pointer to sk buffer
84  *
85  * Return: 0 on success and failure value on error
86  */
87 int ipc_imem_sys_wwan_transmit(struct iosm_imem *ipc_imem, int if_id,
88 			       int channel_id, struct sk_buff *skb);
89 /**
90  * ipc_imem_wwan_channel_init - Initializes WWAN channels and the channel for
91  *				MUX.
92  * @ipc_imem:		Pointer to iosm_imem struct.
93  * @mux_type:		Type of mux protocol.
94  */
95 void ipc_imem_wwan_channel_init(struct iosm_imem *ipc_imem,
96 				enum ipc_mux_protocol mux_type);
97 
98 /**
99  * ipc_imem_sys_devlink_open - Open a Flash/CD Channel link to CP
100  * @ipc_imem:   iosm_imem instance
101  *
102  * Return:	channel instance on success, NULL for failure
103  */
104 struct ipc_mem_channel *ipc_imem_sys_devlink_open(struct iosm_imem *ipc_imem);
105 
106 /**
107  * ipc_imem_sys_devlink_close - Release a Flash/CD channel link to CP
108  * @ipc_devlink:	Pointer to ipc_devlink data-struct
109  *
110  */
111 void ipc_imem_sys_devlink_close(struct iosm_devlink *ipc_devlink);
112 
113 /**
114  * ipc_imem_sys_devlink_notify_rx - Receive downlink characters from CP,
115  *				the downlink skbuf is added at the end of the
116  *				downlink or rx list
117  * @ipc_devlink:	Pointer to ipc_devlink data-struct
118  * @skb:		Pointer to sk buffer
119  */
120 void ipc_imem_sys_devlink_notify_rx(struct iosm_devlink *ipc_devlink,
121 				    struct sk_buff *skb);
122 
123 /**
124  * ipc_imem_sys_devlink_read - Copy the rx data and free the skbuf
125  * @ipc_devlink:	Devlink instance
126  * @data:		Buffer to read the data from modem
127  * @bytes_to_read:	Size of destination buffer
128  * @bytes_read:		Number of bytes read
129  *
130  * Return: 0 on success and failure value on error
131  */
132 int ipc_imem_sys_devlink_read(struct iosm_devlink *ipc_devlink, u8 *data,
133 			      u32 bytes_to_read, u32 *bytes_read);
134 
135 /**
136  * ipc_imem_sys_devlink_write - Route the uplink buffer to CP
137  * @ipc_devlink:	Devlink_sio instance
138  * @buf:		Pointer to buffer
139  * @count:		Number of data bytes to write
140  * Return:		0 on success and failure value on error
141  */
142 int ipc_imem_sys_devlink_write(struct iosm_devlink *ipc_devlink,
143 			       unsigned char *buf, int count);
144 
145 #endif
146