caif_layer.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * Copyright (C) ST-Ericsson AB 2010
  3. * Author: Sjur Brendeland
  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. * @id: The identity of this layer
  116. * @name: Name of the layer.
  117. *
  118. * This structure defines the layered structure in CAIF.
  119. *
  120. * It defines CAIF layering structure, used by all CAIF Layers and the
  121. * layers interfacing CAIF.
  122. *
  123. * In order to integrate with CAIF an adaptation layer on top of the CAIF stack
  124. * and PHY layer below the CAIF stack
  125. * must be implemented. These layer must follow the design principles below.
  126. *
  127. * Principles for layering of protocol layers:
  128. * - All layers must use this structure. If embedding it, then place this
  129. * structure first in the layer specific structure.
  130. *
  131. * - Each layer should not depend on any others layer's private data.
  132. *
  133. * - In order to send data upwards do
  134. * layer->up->receive(layer->up, packet);
  135. *
  136. * - In order to send data downwards do
  137. * layer->dn->transmit(layer->dn, info, packet);
  138. */
  139. struct cflayer {
  140. struct cflayer *up;
  141. struct cflayer *dn;
  142. struct list_head node;
  143. /*
  144. * receive() - Receive Function (non-blocking).
  145. * Contract: Each layer must implement a receive function passing the
  146. * CAIF packets upwards in the stack.
  147. * Packet handling rules:
  148. * - The CAIF packet (cfpkt) ownership is passed to the
  149. * called receive function. This means that the the
  150. * packet cannot be accessed after passing it to the
  151. * above layer using up->receive().
  152. *
  153. * - If parsing of the packet fails, the packet must be
  154. * destroyed and negative error code returned
  155. * from the function.
  156. * EXCEPTION: If the framing layer (cffrml) returns
  157. * -EILSEQ, the packet is not freed.
  158. *
  159. * - If parsing succeeds (and above layers return OK) then
  160. * the function must return a value >= 0.
  161. *
  162. * Returns result < 0 indicates an error, 0 or positive value
  163. * indicates success.
  164. *
  165. * @layr: Pointer to the current layer the receive function is
  166. * implemented for (this pointer).
  167. * @cfpkt: Pointer to CaifPacket to be handled.
  168. */
  169. int (*receive)(struct cflayer *layr, struct cfpkt *cfpkt);
  170. /*
  171. * transmit() - Transmit Function (non-blocking).
  172. * Contract: Each layer must implement a transmit function passing the
  173. * CAIF packet downwards in the stack.
  174. * Packet handling rules:
  175. * - The CAIF packet (cfpkt) ownership is passed to the
  176. * transmit function. This means that the the packet
  177. * cannot be accessed after passing it to the below
  178. * layer using dn->transmit().
  179. *
  180. * - Upon error the packet ownership is still passed on,
  181. * so the packet shall be freed where error is detected.
  182. * Callers of the transmit function shall not free packets,
  183. * but errors shall be returned.
  184. *
  185. * - Return value less than zero means error, zero or
  186. * greater than zero means OK.
  187. *
  188. * Returns result < 0 indicates an error, 0 or positive value
  189. * indicates success.
  190. *
  191. * @layr: Pointer to the current layer the receive function
  192. * isimplemented for (this pointer).
  193. * @cfpkt: Pointer to CaifPacket to be handled.
  194. */
  195. int (*transmit) (struct cflayer *layr, struct cfpkt *cfpkt);
  196. /*
  197. * cttrlcmd() - Control Function upwards in CAIF Stack (non-blocking).
  198. * Used for signaling responses (CAIF_CTRLCMD_*_RSP)
  199. * and asynchronous events from the modem (CAIF_CTRLCMD_*_IND)
  200. *
  201. * @layr: Pointer to the current layer the receive function
  202. * is implemented for (this pointer).
  203. * @ctrl: Control Command.
  204. */
  205. void (*ctrlcmd) (struct cflayer *layr, enum caif_ctrlcmd ctrl,
  206. int phyid);
  207. /*
  208. * modemctrl() - Control Function used for controlling the modem.
  209. * Used to signal down-wards in the CAIF stack.
  210. * Returns 0 on success, < 0 upon failure.
  211. *
  212. * @layr: Pointer to the current layer the receive function
  213. * is implemented for (this pointer).
  214. * @ctrl: Control Command.
  215. */
  216. int (*modemcmd) (struct cflayer *layr, enum caif_modemcmd ctrl);
  217. unsigned int id;
  218. char name[CAIF_LAYER_NAME_SZ];
  219. };
  220. /**
  221. * layer_set_up() - Set the up pointer for a specified layer.
  222. * @layr: Layer where up pointer shall be set.
  223. * @above: Layer above.
  224. */
  225. #define layer_set_up(layr, above) ((layr)->up = (struct cflayer *)(above))
  226. /**
  227. * layer_set_dn() - Set the down pointer for a specified layer.
  228. * @layr: Layer where down pointer shall be set.
  229. * @below: Layer below.
  230. */
  231. #define layer_set_dn(layr, below) ((layr)->dn = (struct cflayer *)(below))
  232. /**
  233. * struct dev_info - Physical Device info information about physical layer.
  234. * @dev: Pointer to native physical device.
  235. * @id: Physical ID of the physical connection used by the
  236. * logical CAIF connection. Used by service layers to
  237. * identify their physical id to Caif MUX (CFMUXL)so
  238. * that the MUX can add the correct physical ID to the
  239. * packet.
  240. */
  241. struct dev_info {
  242. void *dev;
  243. unsigned int id;
  244. };
  245. /**
  246. * struct caif_payload_info - Payload information embedded in packet (sk_buff).
  247. *
  248. * @dev_info: Information about the receiving device.
  249. *
  250. * @hdr_len: Header length, used to align pay load on 32bit boundary.
  251. *
  252. * @channel_id: Channel ID of the logical CAIF connection.
  253. * Used by mux to insert channel id into the caif packet.
  254. */
  255. struct caif_payload_info {
  256. struct dev_info *dev_info;
  257. unsigned short hdr_len;
  258. unsigned short channel_id;
  259. };
  260. #endif /* CAIF_LAYER_H_ */