caif_layer.h 8.7 KB

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