caif_layer.h 8.6 KB

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