caif_layer.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. #ifndef CAIF_LAYER_H_
  7. #define CAIF_LAYER_H_
  8. #include <linux/list.h>
  9. struct cflayer;
  10. struct cfpkt;
  11. struct cfpktq;
  12. struct caif_payload_info;
  13. struct caif_packet_funcs;
  14. #define CAIF_LAYER_NAME_SZ 16
  15. /**
  16. * caif_assert() - Assert function for CAIF.
  17. * @assert: expression to evaluate.
  18. *
  19. * This function will print a error message and a do WARN_ON if the
  20. * assertion failes. Normally this will do a stack up at the current location.
  21. */
  22. #define caif_assert(assert) \
  23. do { \
  24. if (!(assert)) { \
  25. pr_err("caif:Assert detected:'%s'\n", #assert); \
  26. WARN_ON(!(assert)); \
  27. } \
  28. } while (0)
  29. /**
  30. * enum caif_ctrlcmd - CAIF Stack Control Signaling sent in layer.ctrlcmd().
  31. *
  32. * @CAIF_CTRLCMD_FLOW_OFF_IND: Flow Control is OFF, transmit function
  33. * should stop sending data
  34. *
  35. * @CAIF_CTRLCMD_FLOW_ON_IND: Flow Control is ON, transmit function
  36. * can start sending data
  37. *
  38. * @CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND: Remote end modem has decided to close
  39. * down channel
  40. *
  41. * @CAIF_CTRLCMD_INIT_RSP: Called initially when the layer below
  42. * has finished initialization
  43. *
  44. * @CAIF_CTRLCMD_DEINIT_RSP: Called when de-initialization is
  45. * complete
  46. *
  47. * @CAIF_CTRLCMD_INIT_FAIL_RSP: Called if initialization fails
  48. *
  49. * @_CAIF_CTRLCMD_PHYIF_FLOW_OFF_IND: CAIF Link layer temporarily cannot
  50. * send more packets.
  51. * @_CAIF_CTRLCMD_PHYIF_FLOW_ON_IND: Called if CAIF Link layer is able
  52. * to send packets again.
  53. * @_CAIF_CTRLCMD_PHYIF_DOWN_IND: Called if CAIF Link layer is going
  54. * down.
  55. *
  56. * These commands are sent upwards in the CAIF stack to the CAIF Client.
  57. * They are used for signaling originating from the modem or CAIF Link Layer.
  58. * These are either responses (*_RSP) or events (*_IND).
  59. */
  60. enum caif_ctrlcmd {
  61. CAIF_CTRLCMD_FLOW_OFF_IND,
  62. CAIF_CTRLCMD_FLOW_ON_IND,
  63. CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND,
  64. CAIF_CTRLCMD_INIT_RSP,
  65. CAIF_CTRLCMD_DEINIT_RSP,
  66. CAIF_CTRLCMD_INIT_FAIL_RSP,
  67. _CAIF_CTRLCMD_PHYIF_FLOW_OFF_IND,
  68. _CAIF_CTRLCMD_PHYIF_FLOW_ON_IND,
  69. _CAIF_CTRLCMD_PHYIF_DOWN_IND,
  70. };
  71. /**
  72. * enum caif_modemcmd - Modem Control Signaling, sent from CAIF Client
  73. * to the CAIF Link Layer or modem.
  74. *
  75. * @CAIF_MODEMCMD_FLOW_ON_REQ: Flow Control is ON, transmit function
  76. * can start sending data.
  77. *
  78. * @CAIF_MODEMCMD_FLOW_OFF_REQ: Flow Control is OFF, transmit function
  79. * should stop sending data.
  80. *
  81. * @_CAIF_MODEMCMD_PHYIF_USEFULL: Notify physical layer that it is in use
  82. *
  83. * @_CAIF_MODEMCMD_PHYIF_USELESS: Notify physical layer that it is
  84. * no longer in use.
  85. *
  86. * These are requests sent 'downwards' in the stack.
  87. * Flow ON, OFF can be indicated to the modem.
  88. */
  89. enum caif_modemcmd {
  90. CAIF_MODEMCMD_FLOW_ON_REQ = 0,
  91. CAIF_MODEMCMD_FLOW_OFF_REQ = 1,
  92. _CAIF_MODEMCMD_PHYIF_USEFULL = 3,
  93. _CAIF_MODEMCMD_PHYIF_USELESS = 4
  94. };
  95. /**
  96. * enum caif_direction - CAIF Packet Direction.
  97. * Indicate if a packet is to be sent out or to be received in.
  98. * @CAIF_DIR_IN: Incoming packet received.
  99. * @CAIF_DIR_OUT: Outgoing packet to be transmitted.
  100. */
  101. enum caif_direction {
  102. CAIF_DIR_IN = 0,
  103. CAIF_DIR_OUT = 1
  104. };
  105. /**
  106. * struct cflayer - CAIF Stack layer.
  107. * Defines the framework for the CAIF Core Stack.
  108. * @up: Pointer up to the layer above.
  109. * @dn: Pointer down to the layer below.
  110. * @node: List node used when layer participate in a list.
  111. * @receive: Packet receive function.
  112. * @transmit: Packet transmit funciton.
  113. * @ctrlcmd: Used for control signalling upwards in the stack.
  114. * @modemcmd: Used for control signaling downwards in the stack.
  115. * @prio: Priority of this layer.
  116. * @id: The identity of this layer
  117. * @type: The type of this layer
  118. * @name: Name of the layer.
  119. *
  120. * This structure defines the layered structure in CAIF.
  121. *
  122. * It defines CAIF layering structure, used by all CAIF Layers and the
  123. * layers interfacing CAIF.
  124. *
  125. * In order to integrate with CAIF an adaptation layer on top of the CAIF stack
  126. * and PHY layer below the CAIF stack
  127. * must be implemented. These layer must follow the design principles below.
  128. *
  129. * Principles for layering of protocol layers:
  130. * - All layers must use this structure. If embedding it, then place this
  131. * structure first in the layer specific structure.
  132. *
  133. * - Each layer should not depend on any others layer's private data.
  134. *
  135. * - In order to send data upwards do
  136. * layer->up->receive(layer->up, packet);
  137. *
  138. * - In order to send data downwards do
  139. * layer->dn->transmit(layer->dn, info, packet);
  140. */
  141. struct cflayer {
  142. struct cflayer *up;
  143. struct cflayer *dn;
  144. struct list_head node;
  145. /*
  146. * receive() - Receive Function (non-blocking).
  147. * Contract: Each layer must implement a receive function passing the
  148. * CAIF packets upwards in the stack.
  149. * Packet handling rules:
  150. * - The CAIF packet (cfpkt) ownership is passed to the
  151. * called receive function. This means that the the
  152. * packet cannot be accessed after passing it to the
  153. * above layer using up->receive().
  154. *
  155. * - If parsing of the packet fails, the packet must be
  156. * destroyed and negative error code returned
  157. * from the function.
  158. * EXCEPTION: If the framing layer (cffrml) returns
  159. * -EILSEQ, the packet is not freed.
  160. *
  161. * - If parsing succeeds (and above layers return OK) then
  162. * the function must return a value >= 0.
  163. *
  164. * Returns result < 0 indicates an error, 0 or positive value
  165. * indicates success.
  166. *
  167. * @layr: Pointer to the current layer the receive function is
  168. * implemented for (this pointer).
  169. * @cfpkt: Pointer to CaifPacket to be handled.
  170. */
  171. int (*receive)(struct cflayer *layr, struct cfpkt *cfpkt);
  172. /*
  173. * transmit() - Transmit Function (non-blocking).
  174. * Contract: Each layer must implement a transmit function passing the
  175. * CAIF packet downwards in the stack.
  176. * Packet handling rules:
  177. * - The CAIF packet (cfpkt) ownership is passed to the
  178. * transmit function. This means that the the packet
  179. * cannot be accessed after passing it to the below
  180. * layer using dn->transmit().
  181. *
  182. * - Upon error the packet ownership is still passed on,
  183. * so the packet shall be freed where error is detected.
  184. * Callers of the transmit function shall not free packets,
  185. * but errors shall be returned.
  186. *
  187. * - Return value less than zero means error, zero or
  188. * greater than zero means OK.
  189. *
  190. * Returns result < 0 indicates an error, 0 or positive value
  191. * indicates success.
  192. *
  193. * @layr: Pointer to the current layer the receive function
  194. * isimplemented for (this pointer).
  195. * @cfpkt: Pointer to CaifPacket to be handled.
  196. */
  197. int (*transmit) (struct cflayer *layr, struct cfpkt *cfpkt);
  198. /*
  199. * cttrlcmd() - Control Function upwards in CAIF Stack (non-blocking).
  200. * Used for signaling responses (CAIF_CTRLCMD_*_RSP)
  201. * and asynchronous events from the modem (CAIF_CTRLCMD_*_IND)
  202. *
  203. * @layr: Pointer to the current layer the receive function
  204. * is implemented for (this pointer).
  205. * @ctrl: Control Command.
  206. */
  207. void (*ctrlcmd) (struct cflayer *layr, enum caif_ctrlcmd ctrl,
  208. int phyid);
  209. /*
  210. * modemctrl() - Control Function used for controlling the modem.
  211. * Used to signal down-wards in the CAIF stack.
  212. * Returns 0 on success, < 0 upon failure.
  213. *
  214. * @layr: Pointer to the current layer the receive function
  215. * is implemented for (this pointer).
  216. * @ctrl: Control Command.
  217. */
  218. int (*modemcmd) (struct cflayer *layr, enum caif_modemcmd ctrl);
  219. unsigned short prio;
  220. unsigned int id;
  221. unsigned int type;
  222. char name[CAIF_LAYER_NAME_SZ];
  223. };
  224. /**
  225. * layer_set_up() - Set the up pointer for a specified layer.
  226. * @layr: Layer where up pointer shall be set.
  227. * @above: Layer above.
  228. */
  229. #define layer_set_up(layr, above) ((layr)->up = (struct cflayer *)(above))
  230. /**
  231. * layer_set_dn() - Set the down pointer for a specified layer.
  232. * @layr: Layer where down pointer shall be set.
  233. * @below: Layer below.
  234. */
  235. #define layer_set_dn(layr, below) ((layr)->dn = (struct cflayer *)(below))
  236. /**
  237. * struct dev_info - Physical Device info information about physical layer.
  238. * @dev: Pointer to native physical device.
  239. * @id: Physical ID of the physical connection used by the
  240. * logical CAIF connection. Used by service layers to
  241. * identify their physical id to Caif MUX (CFMUXL)so
  242. * that the MUX can add the correct physical ID to the
  243. * packet.
  244. */
  245. struct dev_info {
  246. void *dev;
  247. unsigned int id;
  248. };
  249. /**
  250. * struct caif_payload_info - Payload information embedded in packet (sk_buff).
  251. *
  252. * @dev_info: Information about the receiving device.
  253. *
  254. * @hdr_len: Header length, used to align pay load on 32bit boundary.
  255. *
  256. * @channel_id: Channel ID of the logical CAIF connection.
  257. * Used by mux to insert channel id into the caif packet.
  258. */
  259. struct caif_payload_info {
  260. struct dev_info *dev_info;
  261. unsigned short hdr_len;
  262. unsigned short channel_id;
  263. };
  264. #endif /* CAIF_LAYER_H_ */