Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
caif_layer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) ST-Ericsson AB 2010
3  * Author: Sjur Brendeland / [email protected]
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 #define CAIF_LAYER_NAME_SZ 16
19 
27 #define caif_assert(assert) \
28 do { \
29  if (!(assert)) { \
30  pr_err("caif:Assert detected:'%s'\n", #assert); \
31  WARN_ON(!(assert)); \
32  } \
33 } while (0)
34 
76 };
77 
101 };
102 
112 };
113 
148 struct cflayer {
149  struct cflayer *up;
150  struct cflayer *dn;
151  struct list_head node;
152 
153  /*
154  * receive() - Receive Function (non-blocking).
155  * Contract: Each layer must implement a receive function passing the
156  * CAIF packets upwards in the stack.
157  * Packet handling rules:
158  * - The CAIF packet (cfpkt) ownership is passed to the
159  * called receive function. This means that the the
160  * packet cannot be accessed after passing it to the
161  * above layer using up->receive().
162  *
163  * - If parsing of the packet fails, the packet must be
164  * destroyed and negative error code returned
165  * from the function.
166  * EXCEPTION: If the framing layer (cffrml) returns
167  * -EILSEQ, the packet is not freed.
168  *
169  * - If parsing succeeds (and above layers return OK) then
170  * the function must return a value >= 0.
171  *
172  * Returns result < 0 indicates an error, 0 or positive value
173  * indicates success.
174  *
175  * @layr: Pointer to the current layer the receive function is
176  * implemented for (this pointer).
177  * @cfpkt: Pointer to CaifPacket to be handled.
178  */
179  int (*receive)(struct cflayer *layr, struct cfpkt *cfpkt);
180 
181  /*
182  * transmit() - Transmit Function (non-blocking).
183  * Contract: Each layer must implement a transmit function passing the
184  * CAIF packet downwards in the stack.
185  * Packet handling rules:
186  * - The CAIF packet (cfpkt) ownership is passed to the
187  * transmit function. This means that the the packet
188  * cannot be accessed after passing it to the below
189  * layer using dn->transmit().
190  *
191  * - Upon error the packet ownership is still passed on,
192  * so the packet shall be freed where error is detected.
193  * Callers of the transmit function shall not free packets,
194  * but errors shall be returned.
195  *
196  * - Return value less than zero means error, zero or
197  * greater than zero means OK.
198  *
199  * Returns result < 0 indicates an error, 0 or positive value
200  * indicates success.
201  *
202  * @layr: Pointer to the current layer the receive function
203  * isimplemented for (this pointer).
204  * @cfpkt: Pointer to CaifPacket to be handled.
205  */
206  int (*transmit) (struct cflayer *layr, struct cfpkt *cfpkt);
207 
208  /*
209  * cttrlcmd() - Control Function upwards in CAIF Stack (non-blocking).
210  * Used for signaling responses (CAIF_CTRLCMD_*_RSP)
211  * and asynchronous events from the modem (CAIF_CTRLCMD_*_IND)
212  *
213  * @layr: Pointer to the current layer the receive function
214  * is implemented for (this pointer).
215  * @ctrl: Control Command.
216  */
217  void (*ctrlcmd) (struct cflayer *layr, enum caif_ctrlcmd ctrl,
218  int phyid);
219 
220  /*
221  * modemctrl() - Control Function used for controlling the modem.
222  * Used to signal down-wards in the CAIF stack.
223  * Returns 0 on success, < 0 upon failure.
224  *
225  * @layr: Pointer to the current layer the receive function
226  * is implemented for (this pointer).
227  * @ctrl: Control Command.
228  */
229  int (*modemcmd) (struct cflayer *layr, enum caif_modemcmd ctrl);
230 
231  unsigned int id;
233 };
234 
240 #define layer_set_up(layr, above) ((layr)->up = (struct cflayer *)(above))
241 
247 #define layer_set_dn(layr, below) ((layr)->dn = (struct cflayer *)(below))
248 
258 struct dev_info {
259  void *dev;
260  unsigned int id;
261 };
262 
275  unsigned short hdr_len;
276  unsigned short channel_id;
277 };
278 
279 #endif /* CAIF_LAYER_H_ */