diff options
Diffstat (limited to 'include/net/caif')
-rw-r--r-- | include/net/caif/caif_dev.h | 107 | ||||
-rw-r--r-- | include/net/caif/caif_device.h | 55 | ||||
-rw-r--r-- | include/net/caif/caif_layer.h | 277 | ||||
-rw-r--r-- | include/net/caif/caif_spi.h | 153 | ||||
-rw-r--r-- | include/net/caif/cfcnfg.h | 148 | ||||
-rw-r--r-- | include/net/caif/cfctrl.h | 139 | ||||
-rw-r--r-- | include/net/caif/cffrml.h | 16 | ||||
-rw-r--r-- | include/net/caif/cfmuxl.h | 22 | ||||
-rw-r--r-- | include/net/caif/cfpkt.h | 274 | ||||
-rw-r--r-- | include/net/caif/cfserl.h | 12 | ||||
-rw-r--r-- | include/net/caif/cfsrvl.h | 63 |
11 files changed, 1266 insertions, 0 deletions
diff --git a/include/net/caif/caif_dev.h b/include/net/caif/caif_dev.h new file mode 100644 index 000000000000..6da573c75d54 --- /dev/null +++ b/include/net/caif/caif_dev.h | |||
@@ -0,0 +1,107 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/ sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #ifndef CAIF_DEV_H_ | ||
8 | #define CAIF_DEV_H_ | ||
9 | |||
10 | #include <net/caif/caif_layer.h> | ||
11 | #include <net/caif/cfcnfg.h> | ||
12 | #include <linux/caif/caif_socket.h> | ||
13 | #include <linux/if.h> | ||
14 | |||
15 | /** | ||
16 | * struct caif_param - CAIF parameters. | ||
17 | * @size: Length of data | ||
18 | * @data: Binary Data Blob | ||
19 | */ | ||
20 | struct caif_param { | ||
21 | u16 size; | ||
22 | u8 data[256]; | ||
23 | }; | ||
24 | |||
25 | /** | ||
26 | * struct caif_connect_request - Request data for CAIF channel setup. | ||
27 | * @protocol: Type of CAIF protocol to use (at, datagram etc) | ||
28 | * @sockaddr: Socket address to connect. | ||
29 | * @priority: Priority of the connection. | ||
30 | * @link_selector: Link selector (high bandwidth or low latency) | ||
31 | * @link_name: Name of the CAIF Link Layer to use. | ||
32 | * @param: Connect Request parameters (CAIF_SO_REQ_PARAM). | ||
33 | * | ||
34 | * This struct is used when connecting a CAIF channel. | ||
35 | * It contains all CAIF channel configuration options. | ||
36 | */ | ||
37 | struct caif_connect_request { | ||
38 | enum caif_protocol_type protocol; | ||
39 | struct sockaddr_caif sockaddr; | ||
40 | enum caif_channel_priority priority; | ||
41 | enum caif_link_selector link_selector; | ||
42 | char link_name[16]; | ||
43 | struct caif_param param; | ||
44 | }; | ||
45 | |||
46 | /** | ||
47 | * caif_connect_client - Connect a client to CAIF Core Stack. | ||
48 | * @config: Channel setup parameters, specifying what address | ||
49 | * to connect on the Modem. | ||
50 | * @client_layer: User implementation of client layer. This layer | ||
51 | * MUST have receive and control callback functions | ||
52 | * implemented. | ||
53 | * @ifindex: Link layer interface index used for this connection. | ||
54 | * @headroom: Head room needed by CAIF protocol. | ||
55 | * @tailroom: Tail room needed by CAIF protocol. | ||
56 | * | ||
57 | * This function connects a CAIF channel. The Client must implement | ||
58 | * the struct cflayer. This layer represents the Client layer and holds | ||
59 | * receive functions and control callback functions. Control callback | ||
60 | * function will receive information about connect/disconnect responses, | ||
61 | * flow control etc (see enum caif_control). | ||
62 | * E.g. CAIF Socket will call this function for each socket it connects | ||
63 | * and have one client_layer instance for each socket. | ||
64 | */ | ||
65 | int caif_connect_client(struct caif_connect_request *conn_req, | ||
66 | struct cflayer *client_layer, int *ifindex, | ||
67 | int *headroom, int *tailroom); | ||
68 | |||
69 | /** | ||
70 | * caif_disconnect_client - Disconnects a client from the CAIF stack. | ||
71 | * | ||
72 | * @client_layer: Client layer to be removed. | ||
73 | */ | ||
74 | int caif_disconnect_client(struct cflayer *client_layer); | ||
75 | |||
76 | /** | ||
77 | * caif_release_client - Release adaptation layer reference to client. | ||
78 | * | ||
79 | * @client_layer: Client layer. | ||
80 | * | ||
81 | * Releases a client/adaptation layer use of the caif stack. | ||
82 | * This function must be used after caif_disconnect_client to | ||
83 | * decrease the reference count of the service layer. | ||
84 | */ | ||
85 | void caif_release_client(struct cflayer *client_layer); | ||
86 | |||
87 | /** | ||
88 | * connect_req_to_link_param - Translate configuration parameters | ||
89 | * from socket format to internal format. | ||
90 | * @cnfg: Pointer to configuration handler | ||
91 | * @con_req: Configuration parameters supplied in function | ||
92 | * caif_connect_client | ||
93 | * @channel_setup_param: Parameters supplied to the CAIF Core stack for | ||
94 | * setting up channels. | ||
95 | * | ||
96 | */ | ||
97 | int connect_req_to_link_param(struct cfcnfg *cnfg, | ||
98 | struct caif_connect_request *con_req, | ||
99 | struct cfctrl_link_param *channel_setup_param); | ||
100 | |||
101 | /** | ||
102 | * get_caif_conf() - Get the configuration handler. | ||
103 | */ | ||
104 | struct cfcnfg *get_caif_conf(void); | ||
105 | |||
106 | |||
107 | #endif /* CAIF_DEV_H_ */ | ||
diff --git a/include/net/caif/caif_device.h b/include/net/caif/caif_device.h new file mode 100644 index 000000000000..d02f044adb8a --- /dev/null +++ b/include/net/caif/caif_device.h | |||
@@ -0,0 +1,55 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/ sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #ifndef CAIF_DEVICE_H_ | ||
8 | #define CAIF_DEVICE_H_ | ||
9 | #include <linux/kernel.h> | ||
10 | #include <linux/net.h> | ||
11 | #include <linux/netdevice.h> | ||
12 | #include <linux/caif/caif_socket.h> | ||
13 | #include <net/caif/caif_device.h> | ||
14 | |||
15 | /** | ||
16 | * struct caif_dev_common - data shared between CAIF drivers and stack. | ||
17 | * @flowctrl: Flow Control callback function. This function is | ||
18 | * supplied by CAIF Core Stack and is used by CAIF | ||
19 | * Link Layer to send flow-stop to CAIF Core. | ||
20 | * The flow information will be distributed to all | ||
21 | * clients of CAIF. | ||
22 | * | ||
23 | * @link_select: Profile of device, either high-bandwidth or | ||
24 | * low-latency. This member is set by CAIF Link | ||
25 | * Layer Device in order to indicate if this device | ||
26 | * is a high bandwidth or low latency device. | ||
27 | * | ||
28 | * @use_frag: CAIF Frames may be fragmented. | ||
29 | * Is set by CAIF Link Layer in order to indicate if the | ||
30 | * interface receives fragmented frames that must be | ||
31 | * assembled by CAIF Core Layer. | ||
32 | * | ||
33 | * @use_fcs: Indicate if Frame CheckSum (fcs) is used. | ||
34 | * Is set if the physical interface is | ||
35 | * using Frame Checksum on the CAIF Frames. | ||
36 | * | ||
37 | * @use_stx: Indicate STart of frame eXtension (stx) in use. | ||
38 | * Is set if the CAIF Link Layer expects | ||
39 | * CAIF Frames to start with the STX byte. | ||
40 | * | ||
41 | * This structure is shared between the CAIF drivers and the CAIF stack. | ||
42 | * It is used by the device to register its behavior. | ||
43 | * CAIF Core layer must set the member flowctrl in order to supply | ||
44 | * CAIF Link Layer with the flow control function. | ||
45 | * | ||
46 | */ | ||
47 | struct caif_dev_common { | ||
48 | void (*flowctrl)(struct net_device *net, int on); | ||
49 | enum caif_link_selector link_select; | ||
50 | int use_frag; | ||
51 | int use_fcs; | ||
52 | int use_stx; | ||
53 | }; | ||
54 | |||
55 | #endif /* CAIF_DEVICE_H_ */ | ||
diff --git a/include/net/caif/caif_layer.h b/include/net/caif/caif_layer.h new file mode 100644 index 000000000000..c8b07a904e78 --- /dev/null +++ b/include/net/caif/caif_layer.h | |||
@@ -0,0 +1,277 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland / sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #ifndef CAIF_LAYER_H_ | ||
8 | #define CAIF_LAYER_H_ | ||
9 | |||
10 | #include <linux/list.h> | ||
11 | |||
12 | struct cflayer; | ||
13 | struct cfpkt; | ||
14 | struct cfpktq; | ||
15 | struct caif_payload_info; | ||
16 | struct caif_packet_funcs; | ||
17 | |||
18 | |||
19 | #define CAIF_LAYER_NAME_SZ 16 | ||
20 | |||
21 | /** | ||
22 | * caif_assert() - Assert function for CAIF. | ||
23 | * @assert: expression to evaluate. | ||
24 | * | ||
25 | * This function will print a error message and a do WARN_ON if the | ||
26 | * assertion failes. Normally this will do a stack up at the current location. | ||
27 | */ | ||
28 | #define caif_assert(assert) \ | ||
29 | do { \ | ||
30 | if (!(assert)) { \ | ||
31 | pr_err("caif:Assert detected:'%s'\n", #assert); \ | ||
32 | WARN_ON(!(assert)); \ | ||
33 | } \ | ||
34 | } while (0) | ||
35 | |||
36 | |||
37 | /** | ||
38 | * enum caif_ctrlcmd - CAIF Stack Control Signaling sent in layer.ctrlcmd(). | ||
39 | * | ||
40 | * @CAIF_CTRLCMD_FLOW_OFF_IND: Flow Control is OFF, transmit function | ||
41 | * should stop sending data | ||
42 | * | ||
43 | * @CAIF_CTRLCMD_FLOW_ON_IND: Flow Control is ON, transmit function | ||
44 | * can start sending data | ||
45 | * | ||
46 | * @CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND: Remote end modem has decided to close | ||
47 | * down channel | ||
48 | * | ||
49 | * @CAIF_CTRLCMD_INIT_RSP: Called initially when the layer below | ||
50 | * has finished initialization | ||
51 | * | ||
52 | * @CAIF_CTRLCMD_DEINIT_RSP: Called when de-initialization is | ||
53 | * complete | ||
54 | * | ||
55 | * @CAIF_CTRLCMD_INIT_FAIL_RSP: Called if initialization fails | ||
56 | * | ||
57 | * @_CAIF_CTRLCMD_PHYIF_FLOW_OFF_IND: CAIF Link layer temporarily cannot | ||
58 | * send more packets. | ||
59 | * @_CAIF_CTRLCMD_PHYIF_FLOW_ON_IND: Called if CAIF Link layer is able | ||
60 | * to send packets again. | ||
61 | * @_CAIF_CTRLCMD_PHYIF_DOWN_IND: Called if CAIF Link layer is going | ||
62 | * down. | ||
63 | * | ||
64 | * These commands are sent upwards in the CAIF stack to the CAIF Client. | ||
65 | * They are used for signaling originating from the modem or CAIF Link Layer. | ||
66 | * These are either responses (*_RSP) or events (*_IND). | ||
67 | */ | ||
68 | enum caif_ctrlcmd { | ||
69 | CAIF_CTRLCMD_FLOW_OFF_IND, | ||
70 | CAIF_CTRLCMD_FLOW_ON_IND, | ||
71 | CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND, | ||
72 | CAIF_CTRLCMD_INIT_RSP, | ||
73 | CAIF_CTRLCMD_DEINIT_RSP, | ||
74 | CAIF_CTRLCMD_INIT_FAIL_RSP, | ||
75 | _CAIF_CTRLCMD_PHYIF_FLOW_OFF_IND, | ||
76 | _CAIF_CTRLCMD_PHYIF_FLOW_ON_IND, | ||
77 | _CAIF_CTRLCMD_PHYIF_DOWN_IND, | ||
78 | }; | ||
79 | |||
80 | /** | ||
81 | * enum caif_modemcmd - Modem Control Signaling, sent from CAIF Client | ||
82 | * to the CAIF Link Layer or modem. | ||
83 | * | ||
84 | * @CAIF_MODEMCMD_FLOW_ON_REQ: Flow Control is ON, transmit function | ||
85 | * can start sending data. | ||
86 | * | ||
87 | * @CAIF_MODEMCMD_FLOW_OFF_REQ: Flow Control is OFF, transmit function | ||
88 | * should stop sending data. | ||
89 | * | ||
90 | * @_CAIF_MODEMCMD_PHYIF_USEFULL: Notify physical layer that it is in use | ||
91 | * | ||
92 | * @_CAIF_MODEMCMD_PHYIF_USELESS: Notify physical layer that it is | ||
93 | * no longer in use. | ||
94 | * | ||
95 | * These are requests sent 'downwards' in the stack. | ||
96 | * Flow ON, OFF can be indicated to the modem. | ||
97 | */ | ||
98 | enum caif_modemcmd { | ||
99 | CAIF_MODEMCMD_FLOW_ON_REQ = 0, | ||
100 | CAIF_MODEMCMD_FLOW_OFF_REQ = 1, | ||
101 | _CAIF_MODEMCMD_PHYIF_USEFULL = 3, | ||
102 | _CAIF_MODEMCMD_PHYIF_USELESS = 4 | ||
103 | }; | ||
104 | |||
105 | /** | ||
106 | * enum caif_direction - CAIF Packet Direction. | ||
107 | * Indicate if a packet is to be sent out or to be received in. | ||
108 | * @CAIF_DIR_IN: Incoming packet received. | ||
109 | * @CAIF_DIR_OUT: Outgoing packet to be transmitted. | ||
110 | */ | ||
111 | enum caif_direction { | ||
112 | CAIF_DIR_IN = 0, | ||
113 | CAIF_DIR_OUT = 1 | ||
114 | }; | ||
115 | |||
116 | /** | ||
117 | * struct cflayer - CAIF Stack layer. | ||
118 | * Defines the framework for the CAIF Core Stack. | ||
119 | * @up: Pointer up to the layer above. | ||
120 | * @dn: Pointer down to the layer below. | ||
121 | * @node: List node used when layer participate in a list. | ||
122 | * @receive: Packet receive function. | ||
123 | * @transmit: Packet transmit funciton. | ||
124 | * @ctrlcmd: Used for control signalling upwards in the stack. | ||
125 | * @modemcmd: Used for control signaling downwards in the stack. | ||
126 | * @prio: Priority of this layer. | ||
127 | * @id: The identity of this layer | ||
128 | * @type: The type of this layer | ||
129 | * @name: Name of the layer. | ||
130 | * | ||
131 | * This structure defines the layered structure in CAIF. | ||
132 | * | ||
133 | * It defines CAIF layering structure, used by all CAIF Layers and the | ||
134 | * layers interfacing CAIF. | ||
135 | * | ||
136 | * In order to integrate with CAIF an adaptation layer on top of the CAIF stack | ||
137 | * and PHY layer below the CAIF stack | ||
138 | * must be implemented. These layer must follow the design principles below. | ||
139 | * | ||
140 | * Principles for layering of protocol layers: | ||
141 | * - All layers must use this structure. If embedding it, then place this | ||
142 | * structure first in the layer specific structure. | ||
143 | * | ||
144 | * - Each layer should not depend on any others layer private data. | ||
145 | * | ||
146 | * - In order to send data upwards do | ||
147 | * layer->up->receive(layer->up, packet); | ||
148 | * | ||
149 | * - In order to send data downwards do | ||
150 | * layer->dn->transmit(layer->dn, info, packet); | ||
151 | */ | ||
152 | struct cflayer { | ||
153 | struct cflayer *up; | ||
154 | struct cflayer *dn; | ||
155 | struct list_head node; | ||
156 | |||
157 | /* | ||
158 | * receive() - Receive Function. | ||
159 | * Contract: Each layer must implement a receive function passing the | ||
160 | * CAIF packets upwards in the stack. | ||
161 | * Packet handling rules: | ||
162 | * - The CAIF packet (cfpkt) cannot be accessed after | ||
163 | * passing it to the next layer using up->receive(). | ||
164 | * - If parsing of the packet fails, the packet must be | ||
165 | * destroyed and -1 returned from the function. | ||
166 | * - If parsing succeeds (and above layers return OK) then | ||
167 | * the function must return a value > 0. | ||
168 | * | ||
169 | * Returns result < 0 indicates an error, 0 or positive value | ||
170 | * indicates success. | ||
171 | * | ||
172 | * @layr: Pointer to the current layer the receive function is | ||
173 | * implemented for (this pointer). | ||
174 | * @cfpkt: Pointer to CaifPacket to be handled. | ||
175 | */ | ||
176 | int (*receive)(struct cflayer *layr, struct cfpkt *cfpkt); | ||
177 | |||
178 | /* | ||
179 | * transmit() - Transmit Function. | ||
180 | * Contract: Each layer must implement a transmit function passing the | ||
181 | * CAIF packet downwards in the stack. | ||
182 | * Packet handling rules: | ||
183 | * - The CAIF packet (cfpkt) ownership is passed to the | ||
184 | * transmit function. This means that the the packet | ||
185 | * cannot be accessed after passing it to the below | ||
186 | * layer using dn->transmit(). | ||
187 | * | ||
188 | * - If transmit fails, however, the ownership is returned | ||
189 | * to thecaller. The caller of "dn->transmit()" must | ||
190 | * destroy or resend packet. | ||
191 | * | ||
192 | * - Return value less than zero means error, zero or | ||
193 | * greater than zero means OK. | ||
194 | * | ||
195 | * result < 0 indicates an error, 0 or positive value | ||
196 | * indicate success. | ||
197 | * | ||
198 | * @layr: Pointer to the current layer the receive function | ||
199 | * isimplemented for (this pointer). | ||
200 | * @cfpkt: Pointer to CaifPacket to be handled. | ||
201 | */ | ||
202 | int (*transmit) (struct cflayer *layr, struct cfpkt *cfpkt); | ||
203 | |||
204 | /* | ||
205 | * cttrlcmd() - Control Function upwards in CAIF Stack. | ||
206 | * Used for signaling responses (CAIF_CTRLCMD_*_RSP) | ||
207 | * and asynchronous events from the modem (CAIF_CTRLCMD_*_IND) | ||
208 | * | ||
209 | * @layr: Pointer to the current layer the receive function | ||
210 | * is implemented for (this pointer). | ||
211 | * @ctrl: Control Command. | ||
212 | */ | ||
213 | void (*ctrlcmd) (struct cflayer *layr, enum caif_ctrlcmd ctrl, | ||
214 | int phyid); | ||
215 | |||
216 | /* | ||
217 | * modemctrl() - Control Function used for controlling the modem. | ||
218 | * Used to signal down-wards in the CAIF stack. | ||
219 | * Returns 0 on success, < 0 upon failure. | ||
220 | * | ||
221 | * @layr: Pointer to the current layer the receive function | ||
222 | * is implemented for (this pointer). | ||
223 | * @ctrl: Control Command. | ||
224 | */ | ||
225 | int (*modemcmd) (struct cflayer *layr, enum caif_modemcmd ctrl); | ||
226 | |||
227 | unsigned short prio; | ||
228 | unsigned int id; | ||
229 | unsigned int type; | ||
230 | char name[CAIF_LAYER_NAME_SZ]; | ||
231 | }; | ||
232 | |||
233 | /** | ||
234 | * layer_set_up() - Set the up pointer for a specified layer. | ||
235 | * @layr: Layer where up pointer shall be set. | ||
236 | * @above: Layer above. | ||
237 | */ | ||
238 | #define layer_set_up(layr, above) ((layr)->up = (struct cflayer *)(above)) | ||
239 | |||
240 | /** | ||
241 | * layer_set_dn() - Set the down pointer for a specified layer. | ||
242 | * @layr: Layer where down pointer shall be set. | ||
243 | * @below: Layer below. | ||
244 | */ | ||
245 | #define layer_set_dn(layr, below) ((layr)->dn = (struct cflayer *)(below)) | ||
246 | |||
247 | /** | ||
248 | * struct dev_info - Physical Device info information about physical layer. | ||
249 | * @dev: Pointer to native physical device. | ||
250 | * @id: Physical ID of the physical connection used by the | ||
251 | * logical CAIF connection. Used by service layers to | ||
252 | * identify their physical id to Caif MUX (CFMUXL)so | ||
253 | * that the MUX can add the correct physical ID to the | ||
254 | * packet. | ||
255 | */ | ||
256 | struct dev_info { | ||
257 | void *dev; | ||
258 | unsigned int id; | ||
259 | }; | ||
260 | |||
261 | /** | ||
262 | * struct caif_payload_info - Payload information embedded in packet (sk_buff). | ||
263 | * | ||
264 | * @dev_info: Information about the receiving device. | ||
265 | * | ||
266 | * @hdr_len: Header length, used to align pay load on 32bit boundary. | ||
267 | * | ||
268 | * @channel_id: Channel ID of the logical CAIF connection. | ||
269 | * Used by mux to insert channel id into the caif packet. | ||
270 | */ | ||
271 | struct caif_payload_info { | ||
272 | struct dev_info *dev_info; | ||
273 | unsigned short hdr_len; | ||
274 | unsigned short channel_id; | ||
275 | }; | ||
276 | |||
277 | #endif /* CAIF_LAYER_H_ */ | ||
diff --git a/include/net/caif/caif_spi.h b/include/net/caif/caif_spi.h new file mode 100644 index 000000000000..ce4570dff020 --- /dev/null +++ b/include/net/caif/caif_spi.h | |||
@@ -0,0 +1,153 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Daniel Martensson / Daniel.Martensson@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #ifndef CAIF_SPI_H_ | ||
8 | #define CAIF_SPI_H_ | ||
9 | |||
10 | #include <net/caif/caif_device.h> | ||
11 | |||
12 | #define SPI_CMD_WR 0x00 | ||
13 | #define SPI_CMD_RD 0x01 | ||
14 | #define SPI_CMD_EOT 0x02 | ||
15 | #define SPI_CMD_IND 0x04 | ||
16 | |||
17 | #define SPI_DMA_BUF_LEN 8192 | ||
18 | |||
19 | #define WL_SZ 2 /* 16 bits. */ | ||
20 | #define SPI_CMD_SZ 4 /* 32 bits. */ | ||
21 | #define SPI_IND_SZ 4 /* 32 bits. */ | ||
22 | |||
23 | #define SPI_XFER 0 | ||
24 | #define SPI_SS_ON 1 | ||
25 | #define SPI_SS_OFF 2 | ||
26 | #define SPI_TERMINATE 3 | ||
27 | |||
28 | /* Minimum time between different levels is 50 microseconds. */ | ||
29 | #define MIN_TRANSITION_TIME_USEC 50 | ||
30 | |||
31 | /* Defines for calculating duration of SPI transfers for a particular | ||
32 | * number of bytes. | ||
33 | */ | ||
34 | #define SPI_MASTER_CLK_MHZ 13 | ||
35 | #define SPI_XFER_TIME_USEC(bytes, clk) (((bytes) * 8) / clk) | ||
36 | |||
37 | /* Normally this should be aligned on the modem in order to benefit from full | ||
38 | * duplex transfers. However a size of 8188 provokes errors when running with | ||
39 | * the modem. These errors occur when packet sizes approaches 4 kB of data. | ||
40 | */ | ||
41 | #define CAIF_MAX_SPI_FRAME 4092 | ||
42 | |||
43 | /* Maximum number of uplink CAIF frames that can reside in the same SPI frame. | ||
44 | * This number should correspond with the modem setting. The application side | ||
45 | * CAIF accepts any number of embedded downlink CAIF frames. | ||
46 | */ | ||
47 | #define CAIF_MAX_SPI_PKTS 9 | ||
48 | |||
49 | /* Decides if SPI buffers should be prefilled with 0xFF pattern for easier | ||
50 | * debugging. Both TX and RX buffers will be filled before the transfer. | ||
51 | */ | ||
52 | #define CFSPI_DBG_PREFILL 0 | ||
53 | |||
54 | /* Structure describing a SPI transfer. */ | ||
55 | struct cfspi_xfer { | ||
56 | u16 tx_dma_len; | ||
57 | u16 rx_dma_len; | ||
58 | void *va_tx; | ||
59 | dma_addr_t pa_tx; | ||
60 | void *va_rx; | ||
61 | dma_addr_t pa_rx; | ||
62 | }; | ||
63 | |||
64 | /* Structure implemented by the SPI interface. */ | ||
65 | struct cfspi_ifc { | ||
66 | void (*ss_cb) (bool assert, struct cfspi_ifc *ifc); | ||
67 | void (*xfer_done_cb) (struct cfspi_ifc *ifc); | ||
68 | void *priv; | ||
69 | }; | ||
70 | |||
71 | /* Structure implemented by SPI clients. */ | ||
72 | struct cfspi_dev { | ||
73 | int (*init_xfer) (struct cfspi_xfer *xfer, struct cfspi_dev *dev); | ||
74 | void (*sig_xfer) (bool xfer, struct cfspi_dev *dev); | ||
75 | struct cfspi_ifc *ifc; | ||
76 | char *name; | ||
77 | u32 clk_mhz; | ||
78 | void *priv; | ||
79 | }; | ||
80 | |||
81 | /* Enumeration describing the CAIF SPI state. */ | ||
82 | enum cfspi_state { | ||
83 | CFSPI_STATE_WAITING = 0, | ||
84 | CFSPI_STATE_AWAKE, | ||
85 | CFSPI_STATE_FETCH_PKT, | ||
86 | CFSPI_STATE_GET_NEXT, | ||
87 | CFSPI_STATE_INIT_XFER, | ||
88 | CFSPI_STATE_WAIT_ACTIVE, | ||
89 | CFSPI_STATE_SIG_ACTIVE, | ||
90 | CFSPI_STATE_WAIT_XFER_DONE, | ||
91 | CFSPI_STATE_XFER_DONE, | ||
92 | CFSPI_STATE_WAIT_INACTIVE, | ||
93 | CFSPI_STATE_SIG_INACTIVE, | ||
94 | CFSPI_STATE_DELIVER_PKT, | ||
95 | CFSPI_STATE_MAX, | ||
96 | }; | ||
97 | |||
98 | /* Structure implemented by SPI physical interfaces. */ | ||
99 | struct cfspi { | ||
100 | struct caif_dev_common cfdev; | ||
101 | struct net_device *ndev; | ||
102 | struct platform_device *pdev; | ||
103 | struct sk_buff_head qhead; | ||
104 | struct sk_buff_head chead; | ||
105 | u16 cmd; | ||
106 | u16 tx_cpck_len; | ||
107 | u16 tx_npck_len; | ||
108 | u16 rx_cpck_len; | ||
109 | u16 rx_npck_len; | ||
110 | struct cfspi_ifc ifc; | ||
111 | struct cfspi_xfer xfer; | ||
112 | struct cfspi_dev *dev; | ||
113 | unsigned long state; | ||
114 | struct work_struct work; | ||
115 | struct workqueue_struct *wq; | ||
116 | struct list_head list; | ||
117 | int flow_off_sent; | ||
118 | u32 qd_low_mark; | ||
119 | u32 qd_high_mark; | ||
120 | struct completion comp; | ||
121 | wait_queue_head_t wait; | ||
122 | spinlock_t lock; | ||
123 | bool flow_stop; | ||
124 | #ifdef CONFIG_DEBUG_FS | ||
125 | enum cfspi_state dbg_state; | ||
126 | u16 pcmd; | ||
127 | u16 tx_ppck_len; | ||
128 | u16 rx_ppck_len; | ||
129 | struct dentry *dbgfs_dir; | ||
130 | struct dentry *dbgfs_state; | ||
131 | struct dentry *dbgfs_frame; | ||
132 | #endif /* CONFIG_DEBUG_FS */ | ||
133 | }; | ||
134 | |||
135 | extern int spi_frm_align; | ||
136 | extern int spi_up_head_align; | ||
137 | extern int spi_up_tail_align; | ||
138 | extern int spi_down_head_align; | ||
139 | extern int spi_down_tail_align; | ||
140 | extern struct platform_driver cfspi_spi_driver; | ||
141 | |||
142 | void cfspi_dbg_state(struct cfspi *cfspi, int state); | ||
143 | int cfspi_xmitfrm(struct cfspi *cfspi, u8 *buf, size_t len); | ||
144 | int cfspi_xmitlen(struct cfspi *cfspi); | ||
145 | int cfspi_rxfrm(struct cfspi *cfspi, u8 *buf, size_t len); | ||
146 | int cfspi_spi_remove(struct platform_device *pdev); | ||
147 | int cfspi_spi_probe(struct platform_device *pdev); | ||
148 | int cfspi_xmitfrm(struct cfspi *cfspi, u8 *buf, size_t len); | ||
149 | int cfspi_xmitlen(struct cfspi *cfspi); | ||
150 | int cfspi_rxfrm(struct cfspi *cfspi, u8 *buf, size_t len); | ||
151 | void cfspi_xfer(struct work_struct *work); | ||
152 | |||
153 | #endif /* CAIF_SPI_H_ */ | ||
diff --git a/include/net/caif/cfcnfg.h b/include/net/caif/cfcnfg.h new file mode 100644 index 000000000000..bd646faffa47 --- /dev/null +++ b/include/net/caif/cfcnfg.h | |||
@@ -0,0 +1,148 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #ifndef CFCNFG_H_ | ||
8 | #define CFCNFG_H_ | ||
9 | #include <linux/spinlock.h> | ||
10 | #include <linux/netdevice.h> | ||
11 | #include <net/caif/caif_layer.h> | ||
12 | #include <net/caif/cfctrl.h> | ||
13 | |||
14 | struct cfcnfg; | ||
15 | |||
16 | /** | ||
17 | * enum cfcnfg_phy_type - Types of physical layers defined in CAIF Stack | ||
18 | * | ||
19 | * @CFPHYTYPE_FRAG: Fragmented frames physical interface. | ||
20 | * @CFPHYTYPE_CAIF: Generic CAIF physical interface | ||
21 | */ | ||
22 | enum cfcnfg_phy_type { | ||
23 | CFPHYTYPE_FRAG = 1, | ||
24 | CFPHYTYPE_CAIF, | ||
25 | CFPHYTYPE_MAX | ||
26 | }; | ||
27 | |||
28 | /** | ||
29 | * enum cfcnfg_phy_preference - Physical preference HW Abstraction | ||
30 | * | ||
31 | * @CFPHYPREF_UNSPECIFIED: Default physical interface | ||
32 | * | ||
33 | * @CFPHYPREF_LOW_LAT: Default physical interface for low-latency | ||
34 | * traffic | ||
35 | * @CFPHYPREF_HIGH_BW: Default physical interface for high-bandwidth | ||
36 | * traffic | ||
37 | * @CFPHYPREF_LOOP: TEST only Loopback interface simulating modem | ||
38 | * responses. | ||
39 | * | ||
40 | */ | ||
41 | enum cfcnfg_phy_preference { | ||
42 | CFPHYPREF_UNSPECIFIED, | ||
43 | CFPHYPREF_LOW_LAT, | ||
44 | CFPHYPREF_HIGH_BW, | ||
45 | CFPHYPREF_LOOP | ||
46 | }; | ||
47 | |||
48 | /** | ||
49 | * cfcnfg_create() - Create the CAIF configuration object. | ||
50 | */ | ||
51 | struct cfcnfg *cfcnfg_create(void); | ||
52 | |||
53 | /** | ||
54 | * cfcnfg_remove() - Remove the CFCNFG object | ||
55 | * @cfg: config object | ||
56 | */ | ||
57 | void cfcnfg_remove(struct cfcnfg *cfg); | ||
58 | |||
59 | /** | ||
60 | * cfcnfg_add_phy_layer() - Adds a physical layer to the CAIF stack. | ||
61 | * @cnfg: Pointer to a CAIF configuration object, created by | ||
62 | * cfcnfg_create(). | ||
63 | * @phy_type: Specifies the type of physical interface, e.g. | ||
64 | * CFPHYTYPE_FRAG. | ||
65 | * @dev: Pointer to link layer device | ||
66 | * @phy_layer: Specify the physical layer. The transmit function | ||
67 | * MUST be set in the structure. | ||
68 | * @phyid: The assigned physical ID for this layer, used in | ||
69 | * cfcnfg_add_adapt_layer to specify PHY for the link. | ||
70 | * @pref: The phy (link layer) preference. | ||
71 | * @fcs: Specify if checksum is used in CAIF Framing Layer. | ||
72 | * @stx: Specify if Start Of Frame eXtention is used. | ||
73 | */ | ||
74 | |||
75 | void | ||
76 | cfcnfg_add_phy_layer(struct cfcnfg *cnfg, enum cfcnfg_phy_type phy_type, | ||
77 | struct net_device *dev, struct cflayer *phy_layer, | ||
78 | u16 *phyid, enum cfcnfg_phy_preference pref, | ||
79 | bool fcs, bool stx); | ||
80 | |||
81 | /** | ||
82 | * cfcnfg_del_phy_layer - Deletes an phy layer from the CAIF stack. | ||
83 | * | ||
84 | * @cnfg: Pointer to a CAIF configuration object, created by | ||
85 | * cfcnfg_create(). | ||
86 | * @phy_layer: Adaptation layer to be removed. | ||
87 | */ | ||
88 | int cfcnfg_del_phy_layer(struct cfcnfg *cnfg, struct cflayer *phy_layer); | ||
89 | |||
90 | /** | ||
91 | * cfcnfg_disconn_adapt_layer - Disconnects an adaptation layer. | ||
92 | * | ||
93 | * @cnfg: Pointer to a CAIF configuration object, created by | ||
94 | * cfcnfg_create(). | ||
95 | * @adap_layer: Adaptation layer to be removed. | ||
96 | */ | ||
97 | int cfcnfg_disconn_adapt_layer(struct cfcnfg *cnfg, | ||
98 | struct cflayer *adap_layer); | ||
99 | |||
100 | /** | ||
101 | * cfcnfg_release_adap_layer - Used by client to release the adaptation layer. | ||
102 | * | ||
103 | * @adap_layer: Adaptation layer. | ||
104 | */ | ||
105 | void cfcnfg_release_adap_layer(struct cflayer *adap_layer); | ||
106 | |||
107 | /** | ||
108 | * cfcnfg_add_adaptation_layer - Add an adaptation layer to the CAIF stack. | ||
109 | * | ||
110 | * The adaptation Layer is where the interface to application or higher-level | ||
111 | * driver functionality is implemented. | ||
112 | * | ||
113 | * @cnfg: Pointer to a CAIF configuration object, created by | ||
114 | * cfcnfg_create(). | ||
115 | * @param: Link setup parameters. | ||
116 | * @adap_layer: Specify the adaptation layer; the receive and | ||
117 | * flow-control functions MUST be set in the structure. | ||
118 | * @ifindex: Link layer interface index used for this connection. | ||
119 | * @proto_head: Protocol head-space needed by CAIF protocol, | ||
120 | * excluding link layer. | ||
121 | * @proto_tail: Protocol tail-space needed by CAIF protocol, | ||
122 | * excluding link layer. | ||
123 | */ | ||
124 | int cfcnfg_add_adaptation_layer(struct cfcnfg *cnfg, | ||
125 | struct cfctrl_link_param *param, | ||
126 | struct cflayer *adap_layer, | ||
127 | int *ifindex, | ||
128 | int *proto_head, | ||
129 | int *proto_tail); | ||
130 | |||
131 | /** | ||
132 | * cfcnfg_get_phyid() - Get physical ID, given type. | ||
133 | * Returns one of the physical interfaces matching the given type. | ||
134 | * Zero if no match is found. | ||
135 | * @cnfg: Configuration object | ||
136 | * @phy_pref: Caif Link Layer preference | ||
137 | */ | ||
138 | struct dev_info *cfcnfg_get_phyid(struct cfcnfg *cnfg, | ||
139 | enum cfcnfg_phy_preference phy_pref); | ||
140 | |||
141 | /** | ||
142 | * cfcnfg_get_named() - Get the Physical Identifier of CAIF Link Layer | ||
143 | * @cnfg: Configuration object | ||
144 | * @name: Name of the Physical Layer (Caif Link Layer) | ||
145 | */ | ||
146 | int cfcnfg_get_named(struct cfcnfg *cnfg, char *name); | ||
147 | |||
148 | #endif /* CFCNFG_H_ */ | ||
diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h new file mode 100644 index 000000000000..9402543fc20d --- /dev/null +++ b/include/net/caif/cfctrl.h | |||
@@ -0,0 +1,139 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #ifndef CFCTRL_H_ | ||
8 | #define CFCTRL_H_ | ||
9 | #include <net/caif/caif_layer.h> | ||
10 | #include <net/caif/cfsrvl.h> | ||
11 | |||
12 | /* CAIF Control packet commands */ | ||
13 | enum cfctrl_cmd { | ||
14 | CFCTRL_CMD_LINK_SETUP = 0, | ||
15 | CFCTRL_CMD_LINK_DESTROY = 1, | ||
16 | CFCTRL_CMD_LINK_ERR = 2, | ||
17 | CFCTRL_CMD_ENUM = 3, | ||
18 | CFCTRL_CMD_SLEEP = 4, | ||
19 | CFCTRL_CMD_WAKE = 5, | ||
20 | CFCTRL_CMD_LINK_RECONF = 6, | ||
21 | CFCTRL_CMD_START_REASON = 7, | ||
22 | CFCTRL_CMD_RADIO_SET = 8, | ||
23 | CFCTRL_CMD_MODEM_SET = 9, | ||
24 | CFCTRL_CMD_MASK = 0xf | ||
25 | }; | ||
26 | |||
27 | /* Channel types */ | ||
28 | enum cfctrl_srv { | ||
29 | CFCTRL_SRV_DECM = 0, | ||
30 | CFCTRL_SRV_VEI = 1, | ||
31 | CFCTRL_SRV_VIDEO = 2, | ||
32 | CFCTRL_SRV_DBG = 3, | ||
33 | CFCTRL_SRV_DATAGRAM = 4, | ||
34 | CFCTRL_SRV_RFM = 5, | ||
35 | CFCTRL_SRV_UTIL = 6, | ||
36 | CFCTRL_SRV_MASK = 0xf | ||
37 | }; | ||
38 | |||
39 | #define CFCTRL_RSP_BIT 0x20 | ||
40 | #define CFCTRL_ERR_BIT 0x10 | ||
41 | |||
42 | struct cfctrl_rsp { | ||
43 | void (*linksetup_rsp)(struct cflayer *layer, u8 linkid, | ||
44 | enum cfctrl_srv serv, u8 phyid, | ||
45 | struct cflayer *adapt_layer); | ||
46 | void (*linkdestroy_rsp)(struct cflayer *layer, u8 linkid); | ||
47 | void (*linkerror_ind)(void); | ||
48 | void (*enum_rsp)(void); | ||
49 | void (*sleep_rsp)(void); | ||
50 | void (*wake_rsp)(void); | ||
51 | void (*restart_rsp)(void); | ||
52 | void (*radioset_rsp)(void); | ||
53 | void (*reject_rsp)(struct cflayer *layer, u8 linkid, | ||
54 | struct cflayer *client_layer);; | ||
55 | }; | ||
56 | |||
57 | /* Link Setup Parameters for CAIF-Links. */ | ||
58 | struct cfctrl_link_param { | ||
59 | enum cfctrl_srv linktype;/* (T3,T0) Type of Channel */ | ||
60 | u8 priority; /* (P4,P0) Priority of the channel */ | ||
61 | u8 phyid; /* (U2-U0) Physical interface to connect */ | ||
62 | u8 endpoint; /* (E1,E0) Endpoint for data channels */ | ||
63 | u8 chtype; /* (H1,H0) Channel-Type, applies to | ||
64 | * VEI, DEBUG */ | ||
65 | union { | ||
66 | struct { | ||
67 | u8 connid; /* (D7,D0) Video LinkId */ | ||
68 | } video; | ||
69 | |||
70 | struct { | ||
71 | u32 connid; /* (N31,Ngit0) Connection ID used | ||
72 | * for Datagram */ | ||
73 | } datagram; | ||
74 | |||
75 | struct { | ||
76 | u32 connid; /* Connection ID used for RFM */ | ||
77 | char volume[20]; /* Volume to mount for RFM */ | ||
78 | } rfm; /* Configuration for RFM */ | ||
79 | |||
80 | struct { | ||
81 | u16 fifosize_kb; /* Psock FIFO size in KB */ | ||
82 | u16 fifosize_bufs; /* Psock # signal buffers */ | ||
83 | char name[16]; /* Name of the PSOCK service */ | ||
84 | u8 params[255]; /* Link setup Parameters> */ | ||
85 | u16 paramlen; /* Length of Link Setup | ||
86 | * Parameters */ | ||
87 | } utility; /* Configuration for Utility Links (Psock) */ | ||
88 | } u; | ||
89 | }; | ||
90 | |||
91 | /* This structure is used internally in CFCTRL */ | ||
92 | struct cfctrl_request_info { | ||
93 | int sequence_no; | ||
94 | enum cfctrl_cmd cmd; | ||
95 | u8 channel_id; | ||
96 | struct cfctrl_link_param param; | ||
97 | struct cflayer *client_layer; | ||
98 | struct list_head list; | ||
99 | }; | ||
100 | |||
101 | struct cfctrl { | ||
102 | struct cfsrvl serv; | ||
103 | struct cfctrl_rsp res; | ||
104 | atomic_t req_seq_no; | ||
105 | atomic_t rsp_seq_no; | ||
106 | struct list_head list; | ||
107 | /* Protects from simultaneous access to first_req list */ | ||
108 | spinlock_t info_list_lock; | ||
109 | #ifndef CAIF_NO_LOOP | ||
110 | u8 loop_linkid; | ||
111 | int loop_linkused[256]; | ||
112 | /* Protects simultaneous access to loop_linkid and loop_linkused */ | ||
113 | spinlock_t loop_linkid_lock; | ||
114 | #endif | ||
115 | |||
116 | }; | ||
117 | |||
118 | void cfctrl_enum_req(struct cflayer *cfctrl, u8 physlinkid); | ||
119 | int cfctrl_linkup_request(struct cflayer *cfctrl, | ||
120 | struct cfctrl_link_param *param, | ||
121 | struct cflayer *user_layer); | ||
122 | int cfctrl_linkdown_req(struct cflayer *cfctrl, u8 linkid, | ||
123 | struct cflayer *client); | ||
124 | void cfctrl_sleep_req(struct cflayer *cfctrl); | ||
125 | void cfctrl_wake_req(struct cflayer *cfctrl); | ||
126 | void cfctrl_getstartreason_req(struct cflayer *cfctrl); | ||
127 | struct cflayer *cfctrl_create(void); | ||
128 | void cfctrl_set_dnlayer(struct cflayer *this, struct cflayer *dn); | ||
129 | void cfctrl_set_uplayer(struct cflayer *this, struct cflayer *up); | ||
130 | struct cfctrl_rsp *cfctrl_get_respfuncs(struct cflayer *layer); | ||
131 | bool cfctrl_req_eq(struct cfctrl_request_info *r1, | ||
132 | struct cfctrl_request_info *r2); | ||
133 | void cfctrl_insert_req(struct cfctrl *ctrl, | ||
134 | struct cfctrl_request_info *req); | ||
135 | struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl, | ||
136 | struct cfctrl_request_info *req); | ||
137 | void cfctrl_cancel_req(struct cflayer *layr, struct cflayer *adap_layer); | ||
138 | |||
139 | #endif /* CFCTRL_H_ */ | ||
diff --git a/include/net/caif/cffrml.h b/include/net/caif/cffrml.h new file mode 100644 index 000000000000..3f14d2e1ce61 --- /dev/null +++ b/include/net/caif/cffrml.h | |||
@@ -0,0 +1,16 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #ifndef CFFRML_H_ | ||
8 | #define CFFRML_H_ | ||
9 | #include <net/caif/caif_layer.h> | ||
10 | |||
11 | struct cffrml; | ||
12 | struct cflayer *cffrml_create(u16 phyid, bool DoFCS); | ||
13 | void cffrml_set_uplayer(struct cflayer *this, struct cflayer *up); | ||
14 | void cffrml_set_dnlayer(struct cflayer *this, struct cflayer *dn); | ||
15 | |||
16 | #endif /* CFFRML_H_ */ | ||
diff --git a/include/net/caif/cfmuxl.h b/include/net/caif/cfmuxl.h new file mode 100644 index 000000000000..4e1b4f33423e --- /dev/null +++ b/include/net/caif/cfmuxl.h | |||
@@ -0,0 +1,22 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #ifndef CFMUXL_H_ | ||
8 | #define CFMUXL_H_ | ||
9 | #include <net/caif/caif_layer.h> | ||
10 | |||
11 | struct cfsrvl; | ||
12 | struct cffrml; | ||
13 | |||
14 | struct cflayer *cfmuxl_create(void); | ||
15 | int cfmuxl_set_uplayer(struct cflayer *layr, struct cflayer *up, u8 linkid); | ||
16 | struct cflayer *cfmuxl_remove_dnlayer(struct cflayer *layr, u8 phyid); | ||
17 | int cfmuxl_set_dnlayer(struct cflayer *layr, struct cflayer *up, u8 phyid); | ||
18 | struct cflayer *cfmuxl_remove_uplayer(struct cflayer *layr, u8 linkid); | ||
19 | bool cfmuxl_is_phy_inuse(struct cflayer *layr, u8 phyid); | ||
20 | u8 cfmuxl_get_phyid(struct cflayer *layr, u8 channel_id); | ||
21 | |||
22 | #endif /* CFMUXL_H_ */ | ||
diff --git a/include/net/caif/cfpkt.h b/include/net/caif/cfpkt.h new file mode 100644 index 000000000000..fbc681beff52 --- /dev/null +++ b/include/net/caif/cfpkt.h | |||
@@ -0,0 +1,274 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #ifndef CFPKT_H_ | ||
8 | #define CFPKT_H_ | ||
9 | #include <net/caif/caif_layer.h> | ||
10 | #include <linux/types.h> | ||
11 | struct cfpkt; | ||
12 | |||
13 | /* Create a CAIF packet. | ||
14 | * len: Length of packet to be created | ||
15 | * @return New packet. | ||
16 | */ | ||
17 | struct cfpkt *cfpkt_create(u16 len); | ||
18 | |||
19 | /* Create a CAIF packet. | ||
20 | * data Data to copy. | ||
21 | * len Length of packet to be created | ||
22 | * @return New packet. | ||
23 | */ | ||
24 | struct cfpkt *cfpkt_create_uplink(const unsigned char *data, unsigned int len); | ||
25 | /* | ||
26 | * Destroy a CAIF Packet. | ||
27 | * pkt Packet to be destoyed. | ||
28 | */ | ||
29 | void cfpkt_destroy(struct cfpkt *pkt); | ||
30 | |||
31 | /* | ||
32 | * Extract header from packet. | ||
33 | * | ||
34 | * pkt Packet to extract header data from. | ||
35 | * data Pointer to copy the header data into. | ||
36 | * len Length of head data to copy. | ||
37 | * @return zero on success and error code upon failure | ||
38 | */ | ||
39 | int cfpkt_extr_head(struct cfpkt *pkt, void *data, u16 len); | ||
40 | |||
41 | /* | ||
42 | * Peek header from packet. | ||
43 | * Reads data from packet without changing packet. | ||
44 | * | ||
45 | * pkt Packet to extract header data from. | ||
46 | * data Pointer to copy the header data into. | ||
47 | * len Length of head data to copy. | ||
48 | * @return zero on success and error code upon failure | ||
49 | */ | ||
50 | int cfpkt_peek_head(struct cfpkt *pkt, void *data, u16 len); | ||
51 | |||
52 | /* | ||
53 | * Extract header from trailer (end of packet). | ||
54 | * | ||
55 | * pkt Packet to extract header data from. | ||
56 | * data Pointer to copy the trailer data into. | ||
57 | * len Length of header data to copy. | ||
58 | * @return zero on success and error code upon failure | ||
59 | */ | ||
60 | int cfpkt_extr_trail(struct cfpkt *pkt, void *data, u16 len); | ||
61 | |||
62 | /* | ||
63 | * Add header to packet. | ||
64 | * | ||
65 | * | ||
66 | * pkt Packet to add header data to. | ||
67 | * data Pointer to data to copy into the header. | ||
68 | * len Length of header data to copy. | ||
69 | * @return zero on success and error code upon failure | ||
70 | */ | ||
71 | int cfpkt_add_head(struct cfpkt *pkt, const void *data, u16 len); | ||
72 | |||
73 | /* | ||
74 | * Add trailer to packet. | ||
75 | * | ||
76 | * | ||
77 | * pkt Packet to add trailer data to. | ||
78 | * data Pointer to data to copy into the trailer. | ||
79 | * len Length of trailer data to copy. | ||
80 | * @return zero on success and error code upon failure | ||
81 | */ | ||
82 | int cfpkt_add_trail(struct cfpkt *pkt, const void *data, u16 len); | ||
83 | |||
84 | /* | ||
85 | * Pad trailer on packet. | ||
86 | * Moves data pointer in packet, no content copied. | ||
87 | * | ||
88 | * pkt Packet in which to pad trailer. | ||
89 | * len Length of padding to add. | ||
90 | * @return zero on success and error code upon failure | ||
91 | */ | ||
92 | int cfpkt_pad_trail(struct cfpkt *pkt, u16 len); | ||
93 | |||
94 | /* | ||
95 | * Add a single byte to packet body (tail). | ||
96 | * | ||
97 | * pkt Packet in which to add byte. | ||
98 | * data Byte to add. | ||
99 | * @return zero on success and error code upon failure | ||
100 | */ | ||
101 | int cfpkt_addbdy(struct cfpkt *pkt, const u8 data); | ||
102 | |||
103 | /* | ||
104 | * Add a data to packet body (tail). | ||
105 | * | ||
106 | * pkt Packet in which to add data. | ||
107 | * data Pointer to data to copy into the packet body. | ||
108 | * len Length of data to add. | ||
109 | * @return zero on success and error code upon failure | ||
110 | */ | ||
111 | int cfpkt_add_body(struct cfpkt *pkt, const void *data, u16 len); | ||
112 | |||
113 | /* | ||
114 | * Checks whether there are more data to process in packet. | ||
115 | * pkt Packet to check. | ||
116 | * @return true if more data are available in packet false otherwise | ||
117 | */ | ||
118 | bool cfpkt_more(struct cfpkt *pkt); | ||
119 | |||
120 | /* | ||
121 | * Checks whether the packet is erroneous, | ||
122 | * i.e. if it has been attempted to extract more data than available in packet | ||
123 | * or writing more data than has been allocated in cfpkt_create(). | ||
124 | * pkt Packet to check. | ||
125 | * @return true on error false otherwise | ||
126 | */ | ||
127 | bool cfpkt_erroneous(struct cfpkt *pkt); | ||
128 | |||
129 | /* | ||
130 | * Get the packet length. | ||
131 | * pkt Packet to get length from. | ||
132 | * @return Number of bytes in packet. | ||
133 | */ | ||
134 | u16 cfpkt_getlen(struct cfpkt *pkt); | ||
135 | |||
136 | /* | ||
137 | * Set the packet length, by adjusting the trailer pointer according to length. | ||
138 | * pkt Packet to set length. | ||
139 | * len Packet length. | ||
140 | * @return Number of bytes in packet. | ||
141 | */ | ||
142 | int cfpkt_setlen(struct cfpkt *pkt, u16 len); | ||
143 | |||
144 | /* | ||
145 | * cfpkt_append - Appends a packet's data to another packet. | ||
146 | * dstpkt: Packet to append data into, WILL BE FREED BY THIS FUNCTION | ||
147 | * addpkt: Packet to be appended and automatically released, | ||
148 | * WILL BE FREED BY THIS FUNCTION. | ||
149 | * expectlen: Packet's expected total length. This should be considered | ||
150 | * as a hint. | ||
151 | * NB: Input packets will be destroyed after appending and cannot be used | ||
152 | * after calling this function. | ||
153 | * @return The new appended packet. | ||
154 | */ | ||
155 | struct cfpkt *cfpkt_append(struct cfpkt *dstpkt, struct cfpkt *addpkt, | ||
156 | u16 expectlen); | ||
157 | |||
158 | /* | ||
159 | * cfpkt_split - Split a packet into two packets at the specified split point. | ||
160 | * pkt: Packet to be split (will contain the first part of the data on exit) | ||
161 | * pos: Position to split packet in two parts. | ||
162 | * @return The new packet, containing the second part of the data. | ||
163 | */ | ||
164 | struct cfpkt *cfpkt_split(struct cfpkt *pkt, u16 pos); | ||
165 | |||
166 | /* | ||
167 | * Iteration function, iterates the packet buffers from start to end. | ||
168 | * | ||
169 | * Checksum iteration function used to iterate buffers | ||
170 | * (we may have packets consisting of a chain of buffers) | ||
171 | * pkt: Packet to calculate checksum for | ||
172 | * iter_func: Function pointer to iteration function | ||
173 | * chks: Checksum calculated so far. | ||
174 | * buf: Pointer to the buffer to checksum | ||
175 | * len: Length of buf. | ||
176 | * data: Initial checksum value. | ||
177 | * @return Checksum of buffer. | ||
178 | */ | ||
179 | |||
180 | u16 cfpkt_iterate(struct cfpkt *pkt, | ||
181 | u16 (*iter_func)(u16 chks, void *buf, u16 len), | ||
182 | u16 data); | ||
183 | |||
184 | /* Append by giving user access to packet buffer | ||
185 | * cfpkt Packet to append to | ||
186 | * buf Buffer inside pkt that user shall copy data into | ||
187 | * buflen Length of buffer and number of bytes added to packet | ||
188 | * @return 0 on error, 1 on success | ||
189 | */ | ||
190 | int cfpkt_raw_append(struct cfpkt *cfpkt, void **buf, unsigned int buflen); | ||
191 | |||
192 | /* Extract by giving user access to packet buffer | ||
193 | * cfpkt Packet to extract from | ||
194 | * buf Buffer inside pkt that user shall copy data from | ||
195 | * buflen Length of buffer and number of bytes removed from packet | ||
196 | * @return 0 on error, 1 on success | ||
197 | */ | ||
198 | int cfpkt_raw_extract(struct cfpkt *cfpkt, void **buf, unsigned int buflen); | ||
199 | |||
200 | /* Map from a "native" packet (e.g. Linux Socket Buffer) to a CAIF packet. | ||
201 | * dir - Direction indicating whether this packet is to be sent or received. | ||
202 | * nativepkt - The native packet to be transformed to a CAIF packet | ||
203 | * @return The mapped CAIF Packet CFPKT. | ||
204 | */ | ||
205 | struct cfpkt *cfpkt_fromnative(enum caif_direction dir, void *nativepkt); | ||
206 | |||
207 | /* Map from a CAIF packet to a "native" packet (e.g. Linux Socket Buffer). | ||
208 | * pkt - The CAIF packet to be transformed into a "native" packet. | ||
209 | * @return The native packet transformed from a CAIF packet. | ||
210 | */ | ||
211 | void *cfpkt_tonative(struct cfpkt *pkt); | ||
212 | |||
213 | /* | ||
214 | * Insert a packet in the packet queue. | ||
215 | * pktq Packet queue to insert into | ||
216 | * pkt Packet to be inserted in queue | ||
217 | * prio Priority of packet | ||
218 | */ | ||
219 | void cfpkt_queue(struct cfpktq *pktq, struct cfpkt *pkt, | ||
220 | unsigned short prio); | ||
221 | |||
222 | /* | ||
223 | * Remove a packet from the packet queue. | ||
224 | * pktq Packet queue to fetch packets from. | ||
225 | * @return Dequeued packet. | ||
226 | */ | ||
227 | struct cfpkt *cfpkt_dequeue(struct cfpktq *pktq); | ||
228 | |||
229 | /* | ||
230 | * Peek into a packet from the packet queue. | ||
231 | * pktq Packet queue to fetch packets from. | ||
232 | * @return Peeked packet. | ||
233 | */ | ||
234 | struct cfpkt *cfpkt_qpeek(struct cfpktq *pktq); | ||
235 | |||
236 | /* | ||
237 | * Initiates the packet queue. | ||
238 | * @return Pointer to new packet queue. | ||
239 | */ | ||
240 | struct cfpktq *cfpktq_create(void); | ||
241 | |||
242 | /* | ||
243 | * Get the number of packets in the queue. | ||
244 | * pktq Packet queue to fetch count from. | ||
245 | * @return Number of packets in queue. | ||
246 | */ | ||
247 | int cfpkt_qcount(struct cfpktq *pktq); | ||
248 | |||
249 | /* | ||
250 | * Put content of packet into buffer for debuging purposes. | ||
251 | * pkt Packet to copy data from | ||
252 | * buf Buffer to copy data into | ||
253 | * buflen Length of data to copy | ||
254 | * @return Pointer to copied data | ||
255 | */ | ||
256 | char *cfpkt_log_pkt(struct cfpkt *pkt, char *buf, int buflen); | ||
257 | |||
258 | /* | ||
259 | * Clones a packet and releases the original packet. | ||
260 | * This is used for taking ownership of a packet e.g queueing. | ||
261 | * pkt Packet to clone and release. | ||
262 | * @return Cloned packet. | ||
263 | */ | ||
264 | struct cfpkt *cfpkt_clone_release(struct cfpkt *pkt); | ||
265 | |||
266 | |||
267 | /* | ||
268 | * Returns packet information for a packet. | ||
269 | * pkt Packet to get info from; | ||
270 | * @return Packet information | ||
271 | */ | ||
272 | struct caif_payload_info *cfpkt_info(struct cfpkt *pkt); | ||
273 | /*! @} */ | ||
274 | #endif /* CFPKT_H_ */ | ||
diff --git a/include/net/caif/cfserl.h b/include/net/caif/cfserl.h new file mode 100644 index 000000000000..b8374321b362 --- /dev/null +++ b/include/net/caif/cfserl.h | |||
@@ -0,0 +1,12 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #ifndef CFSERL_H_ | ||
8 | #define CFSERL_H_ | ||
9 | #include <net/caif/caif_layer.h> | ||
10 | |||
11 | struct cflayer *cfserl_create(int type, int instance, bool use_stx); | ||
12 | #endif /* CFSERL_H_ */ | ||
diff --git a/include/net/caif/cfsrvl.h b/include/net/caif/cfsrvl.h new file mode 100644 index 000000000000..b1fa87ee0992 --- /dev/null +++ b/include/net/caif/cfsrvl.h | |||
@@ -0,0 +1,63 @@ | |||
1 | /* | ||
2 | * Copyright (C) ST-Ericsson AB 2010 | ||
3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com | ||
4 | * License terms: GNU General Public License (GPL) version 2 | ||
5 | */ | ||
6 | |||
7 | #ifndef CFSRVL_H_ | ||
8 | #define CFSRVL_H_ | ||
9 | #include <linux/list.h> | ||
10 | #include <linux/stddef.h> | ||
11 | #include <linux/types.h> | ||
12 | #include <linux/kref.h> | ||
13 | |||
14 | struct cfsrvl { | ||
15 | struct cflayer layer; | ||
16 | bool open; | ||
17 | bool phy_flow_on; | ||
18 | bool modem_flow_on; | ||
19 | bool supports_flowctrl; | ||
20 | void (*release)(struct kref *); | ||
21 | struct dev_info dev_info; | ||
22 | struct kref ref; | ||
23 | }; | ||
24 | |||
25 | void cfsrvl_release(struct kref *kref); | ||
26 | struct cflayer *cfvei_create(u8 linkid, struct dev_info *dev_info); | ||
27 | struct cflayer *cfdgml_create(u8 linkid, struct dev_info *dev_info); | ||
28 | struct cflayer *cfutill_create(u8 linkid, struct dev_info *dev_info); | ||
29 | struct cflayer *cfvidl_create(u8 linkid, struct dev_info *dev_info); | ||
30 | struct cflayer *cfrfml_create(u8 linkid, struct dev_info *dev_info, | ||
31 | int mtu_size); | ||
32 | struct cflayer *cfdbgl_create(u8 linkid, struct dev_info *dev_info); | ||
33 | bool cfsrvl_phyid_match(struct cflayer *layer, int phyid); | ||
34 | void cfservl_destroy(struct cflayer *layer); | ||
35 | void cfsrvl_init(struct cfsrvl *service, | ||
36 | u8 channel_id, | ||
37 | struct dev_info *dev_info, | ||
38 | bool supports_flowctrl); | ||
39 | bool cfsrvl_ready(struct cfsrvl *service, int *err); | ||
40 | u8 cfsrvl_getphyid(struct cflayer *layer); | ||
41 | |||
42 | static inline void cfsrvl_get(struct cflayer *layr) | ||
43 | { | ||
44 | struct cfsrvl *s; | ||
45 | if (layr == NULL) | ||
46 | return; | ||
47 | s = container_of(layr, struct cfsrvl, layer); | ||
48 | kref_get(&s->ref); | ||
49 | } | ||
50 | |||
51 | static inline void cfsrvl_put(struct cflayer *layr) | ||
52 | { | ||
53 | struct cfsrvl *s; | ||
54 | if (layr == NULL) | ||
55 | return; | ||
56 | s = container_of(layr, struct cfsrvl, layer); | ||
57 | |||
58 | WARN_ON(!s->release); | ||
59 | if (s->release) | ||
60 | kref_put(&s->ref, s->release); | ||
61 | } | ||
62 | |||
63 | #endif /* CFSRVL_H_ */ | ||