caif_layer.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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 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.
  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) cannot be accessed after
  151. * passing it to the next layer using up->receive().
  152. * - If parsing of the packet fails, the packet must be
  153. * destroyed and -1 returned from the function.
  154. * - If parsing succeeds (and above layers return OK) then
  155. * the function must return a value > 0.
  156. *
  157. * Returns result < 0 indicates an error, 0 or positive value
  158. * indicates success.
  159. *
  160. * @layr: Pointer to the current layer the receive function is
  161. * implemented for (this pointer).
  162. * @cfpkt: Pointer to CaifPacket to be handled.
  163. */
  164. int (*receive)(struct cflayer *layr, struct cfpkt *cfpkt);
  165. /*
  166. * transmit() - Transmit Function.
  167. * Contract: Each layer must implement a transmit function passing the
  168. * CAIF packet downwards in the stack.
  169. * Packet handling rules:
  170. * - The CAIF packet (cfpkt) ownership is passed to the
  171. * transmit function. This means that the the packet
  172. * cannot be accessed after passing it to the below
  173. * layer using dn->transmit().
  174. *
  175. * - If transmit fails, however, the ownership is returned
  176. * to thecaller. The caller of "dn->transmit()" must
  177. * destroy or resend packet.
  178. *
  179. * - Return value less than zero means error, zero or
  180. * greater than zero means OK.
  181. *
  182. * result < 0 indicates an error, 0 or positive value
  183. * indicate success.
  184. *
  185. * @layr: Pointer to the current layer the receive function
  186. * isimplemented for (this pointer).
  187. * @cfpkt: Pointer to CaifPacket to be handled.
  188. */
  189. int (*transmit) (struct cflayer *layr, struct cfpkt *cfpkt);
  190. /*
  191. * cttrlcmd() - Control Function upwards in CAIF Stack.
  192. * Used for signaling responses (CAIF_CTRLCMD_*_RSP)
  193. * and asynchronous events from the modem (CAIF_CTRLCMD_*_IND)
  194. *
  195. * @layr: Pointer to the current layer the receive function
  196. * is implemented for (this pointer).
  197. * @ctrl: Control Command.
  198. */
  199. void (*ctrlcmd) (struct cflayer *layr, enum caif_ctrlcmd ctrl,
  200. int phyid);
  201. /*
  202. * modemctrl() - Control Function used for controlling the modem.
  203. * Used to signal down-wards in the CAIF stack.
  204. * Returns 0 on success, < 0 upon failure.
  205. *
  206. * @layr: Pointer to the current layer the receive function
  207. * is implemented for (this pointer).
  208. * @ctrl: Control Command.
  209. */
  210. int (*modemcmd) (struct cflayer *layr, enum caif_modemcmd ctrl);
  211. unsigned short prio;
  212. unsigned int id;
  213. unsigned int type;
  214. char name[CAIF_LAYER_NAME_SZ];
  215. };
  216. /**
  217. * layer_set_up() - Set the up pointer for a specified layer.
  218. * @layr: Layer where up pointer shall be set.
  219. * @above: Layer above.
  220. */
  221. #define layer_set_up(layr, above) ((layr)->up = (struct cflayer *)(above))
  222. /**
  223. * layer_set_dn() - Set the down pointer for a specified layer.
  224. * @layr: Layer where down pointer shall be set.
  225. * @below: Layer below.
  226. */
  227. #define layer_set_dn(layr, below) ((layr)->dn = (struct cflayer *)(below))
  228. /**
  229. * struct dev_info - Physical Device info information about physical layer.
  230. * @dev: Pointer to native physical device.
  231. * @id: Physical ID of the physical connection used by the
  232. * logical CAIF connection. Used by service layers to
  233. * identify their physical id to Caif MUX (CFMUXL)so
  234. * that the MUX can add the correct physical ID to the
  235. * packet.
  236. */
  237. struct dev_info {
  238. void *dev;
  239. unsigned int id;
  240. };
  241. /**
  242. * struct caif_payload_info - Payload information embedded in packet (sk_buff).
  243. *
  244. * @dev_info: Information about the receiving device.
  245. *
  246. * @hdr_len: Header length, used to align pay load on 32bit boundary.
  247. *
  248. * @channel_id: Channel ID of the logical CAIF connection.
  249. * Used by mux to insert channel id into the caif packet.
  250. */
  251. struct caif_payload_info {
  252. struct dev_info *dev_info;
  253. unsigned short hdr_len;
  254. unsigned short channel_id;
  255. };
  256. #endif /* CAIF_LAYER_H_ */