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
10 #include <linux/list.h>
15 struct caif_payload_info
;
16 struct caif_packet_funcs
;
18 #define CAIF_LAYER_NAME_SZ 16
21 * caif_assert() - Assert function for CAIF.
22 * @assert: expression to evaluate.
24 * This function will print a error message and a do WARN_ON if the
25 * assertion failes. Normally this will do a stack up at the current location.
27 #define caif_assert(assert) \
30 pr_err("caif:Assert detected:'%s'\n", #assert); \
36 * enum caif_ctrlcmd - CAIF Stack Control Signaling sent in layer.ctrlcmd().
38 * @CAIF_CTRLCMD_FLOW_OFF_IND: Flow Control is OFF, transmit function
39 * should stop sending data
41 * @CAIF_CTRLCMD_FLOW_ON_IND: Flow Control is ON, transmit function
42 * can start sending data
44 * @CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND: Remote end modem has decided to close
47 * @CAIF_CTRLCMD_INIT_RSP: Called initially when the layer below
48 * has finished initialization
50 * @CAIF_CTRLCMD_DEINIT_RSP: Called when de-initialization is
53 * @CAIF_CTRLCMD_INIT_FAIL_RSP: Called if initialization fails
55 * @_CAIF_CTRLCMD_PHYIF_FLOW_OFF_IND: CAIF Link layer temporarily cannot
57 * @_CAIF_CTRLCMD_PHYIF_FLOW_ON_IND: Called if CAIF Link layer is able
58 * to send packets again.
59 * @_CAIF_CTRLCMD_PHYIF_DOWN_IND: Called if CAIF Link layer is going
62 * These commands are sent upwards in the CAIF stack to the CAIF Client.
63 * They are used for signaling originating from the modem or CAIF Link Layer.
64 * These are either responses (*_RSP) or events (*_IND).
67 CAIF_CTRLCMD_FLOW_OFF_IND
,
68 CAIF_CTRLCMD_FLOW_ON_IND
,
69 CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND
,
70 CAIF_CTRLCMD_INIT_RSP
,
71 CAIF_CTRLCMD_DEINIT_RSP
,
72 CAIF_CTRLCMD_INIT_FAIL_RSP
,
73 _CAIF_CTRLCMD_PHYIF_FLOW_OFF_IND
,
74 _CAIF_CTRLCMD_PHYIF_FLOW_ON_IND
,
75 _CAIF_CTRLCMD_PHYIF_DOWN_IND
,
79 * enum caif_modemcmd - Modem Control Signaling, sent from CAIF Client
80 * to the CAIF Link Layer or modem.
82 * @CAIF_MODEMCMD_FLOW_ON_REQ: Flow Control is ON, transmit function
83 * can start sending data.
85 * @CAIF_MODEMCMD_FLOW_OFF_REQ: Flow Control is OFF, transmit function
86 * should stop sending data.
88 * @_CAIF_MODEMCMD_PHYIF_USEFULL: Notify physical layer that it is in use
90 * @_CAIF_MODEMCMD_PHYIF_USELESS: Notify physical layer that it is
93 * These are requests sent 'downwards' in the stack.
94 * Flow ON, OFF can be indicated to the modem.
97 CAIF_MODEMCMD_FLOW_ON_REQ
= 0,
98 CAIF_MODEMCMD_FLOW_OFF_REQ
= 1,
99 _CAIF_MODEMCMD_PHYIF_USEFULL
= 3,
100 _CAIF_MODEMCMD_PHYIF_USELESS
= 4
104 * enum caif_direction - CAIF Packet Direction.
105 * Indicate if a packet is to be sent out or to be received in.
106 * @CAIF_DIR_IN: Incoming packet received.
107 * @CAIF_DIR_OUT: Outgoing packet to be transmitted.
109 enum caif_direction
{
115 * struct cflayer - CAIF Stack layer.
116 * Defines the framework for the CAIF Core Stack.
117 * @up: Pointer up to the layer above.
118 * @dn: Pointer down to the layer below.
119 * @node: List node used when layer participate in a list.
120 * @receive: Packet receive function.
121 * @transmit: Packet transmit funciton.
122 * @ctrlcmd: Used for control signalling upwards in the stack.
123 * @modemcmd: Used for control signaling downwards in the stack.
124 * @prio: Priority of this layer.
125 * @id: The identity of this layer
126 * @type: The type of this layer
127 * @name: Name of the layer.
129 * This structure defines the layered structure in CAIF.
131 * It defines CAIF layering structure, used by all CAIF Layers and the
132 * layers interfacing CAIF.
134 * In order to integrate with CAIF an adaptation layer on top of the CAIF stack
135 * and PHY layer below the CAIF stack
136 * must be implemented. These layer must follow the design principles below.
138 * Principles for layering of protocol layers:
139 * - All layers must use this structure. If embedding it, then place this
140 * structure first in the layer specific structure.
142 * - Each layer should not depend on any others layer's private data.
144 * - In order to send data upwards do
145 * layer->up->receive(layer->up, packet);
147 * - In order to send data downwards do
148 * layer->dn->transmit(layer->dn, info, packet);
153 struct list_head node
;
156 * receive() - Receive Function (non-blocking).
157 * Contract: Each layer must implement a receive function passing the
158 * CAIF packets upwards in the stack.
159 * Packet handling rules:
160 * - The CAIF packet (cfpkt) ownership is passed to the
161 * called receive function. This means that the the
162 * packet cannot be accessed after passing it to the
163 * above layer using up->receive().
165 * - If parsing of the packet fails, the packet must be
166 * destroyed and negative error code returned
168 * EXCEPTION: If the framing layer (cffrml) returns
169 * -EILSEQ, the packet is not freed.
171 * - If parsing succeeds (and above layers return OK) then
172 * the function must return a value >= 0.
174 * Returns result < 0 indicates an error, 0 or positive value
177 * @layr: Pointer to the current layer the receive function is
178 * implemented for (this pointer).
179 * @cfpkt: Pointer to CaifPacket to be handled.
181 int (*receive
)(struct cflayer
*layr
, struct cfpkt
*cfpkt
);
184 * transmit() - Transmit Function (non-blocking).
185 * Contract: Each layer must implement a transmit function passing the
186 * CAIF packet downwards in the stack.
187 * Packet handling rules:
188 * - The CAIF packet (cfpkt) ownership is passed to the
189 * transmit function. This means that the the packet
190 * cannot be accessed after passing it to the below
191 * layer using dn->transmit().
193 * - Upon error the packet ownership is still passed on,
194 * so the packet shall be freed where error is detected.
195 * Callers of the transmit function shall not free packets,
196 * but errors shall be returned.
198 * - Return value less than zero means error, zero or
199 * greater than zero means OK.
201 * Returns result < 0 indicates an error, 0 or positive value
204 * @layr: Pointer to the current layer the receive function
205 * isimplemented for (this pointer).
206 * @cfpkt: Pointer to CaifPacket to be handled.
208 int (*transmit
) (struct cflayer
*layr
, struct cfpkt
*cfpkt
);
211 * cttrlcmd() - Control Function upwards in CAIF Stack (non-blocking).
212 * Used for signaling responses (CAIF_CTRLCMD_*_RSP)
213 * and asynchronous events from the modem (CAIF_CTRLCMD_*_IND)
215 * @layr: Pointer to the current layer the receive function
216 * is implemented for (this pointer).
217 * @ctrl: Control Command.
219 void (*ctrlcmd
) (struct cflayer
*layr
, enum caif_ctrlcmd ctrl
,
223 * modemctrl() - Control Function used for controlling the modem.
224 * Used to signal down-wards in the CAIF stack.
225 * Returns 0 on success, < 0 upon failure.
227 * @layr: Pointer to the current layer the receive function
228 * is implemented for (this pointer).
229 * @ctrl: Control Command.
231 int (*modemcmd
) (struct cflayer
*layr
, enum caif_modemcmd ctrl
);
236 char name
[CAIF_LAYER_NAME_SZ
];
240 * layer_set_up() - Set the up pointer for a specified layer.
241 * @layr: Layer where up pointer shall be set.
242 * @above: Layer above.
244 #define layer_set_up(layr, above) ((layr)->up = (struct cflayer *)(above))
247 * layer_set_dn() - Set the down pointer for a specified layer.
248 * @layr: Layer where down pointer shall be set.
249 * @below: Layer below.
251 #define layer_set_dn(layr, below) ((layr)->dn = (struct cflayer *)(below))
254 * struct dev_info - Physical Device info information about physical layer.
255 * @dev: Pointer to native physical device.
256 * @id: Physical ID of the physical connection used by the
257 * logical CAIF connection. Used by service layers to
258 * identify their physical id to Caif MUX (CFMUXL)so
259 * that the MUX can add the correct physical ID to the
268 * struct caif_payload_info - Payload information embedded in packet (sk_buff).
270 * @dev_info: Information about the receiving device.
272 * @hdr_len: Header length, used to align pay load on 32bit boundary.
274 * @channel_id: Channel ID of the logical CAIF connection.
275 * Used by mux to insert channel id into the caif packet.
277 struct caif_payload_info
{
278 struct dev_info
*dev_info
;
279 unsigned short hdr_len
;
280 unsigned short channel_id
;
283 #endif /* CAIF_LAYER_H_ */