mostcore.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /*
  2. * mostcore.h - Interface between MostCore,
  3. * Hardware Dependent Module (HDM) and Application Interface Module (AIM).
  4. *
  5. * Copyright (C) 2013-2015, Microchip Technology Germany II GmbH & Co. KG
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * This file is licensed under GPLv2.
  13. */
  14. /*
  15. * Authors:
  16. * Andrey Shvetsov <andrey.shvetsov@k2l.de>
  17. * Christian Gromm <christian.gromm@microchip.com>
  18. * Sebastian Graf
  19. */
  20. #ifndef __MOST_CORE_H__
  21. #define __MOST_CORE_H__
  22. #include <linux/types.h>
  23. struct kobject;
  24. struct module;
  25. /**
  26. * Interface type
  27. */
  28. enum most_interface_type {
  29. ITYPE_LOOPBACK = 1,
  30. ITYPE_I2C,
  31. ITYPE_I2S,
  32. ITYPE_TSI,
  33. ITYPE_HBI,
  34. ITYPE_MEDIALB_DIM,
  35. ITYPE_MEDIALB_DIM2,
  36. ITYPE_USB,
  37. ITYPE_PCIE
  38. };
  39. /**
  40. * Channel direction.
  41. */
  42. enum most_channel_direction {
  43. MOST_CH_RX = 1 << 0,
  44. MOST_CH_TX = 1 << 1,
  45. };
  46. /**
  47. * Channel data type.
  48. */
  49. enum most_channel_data_type {
  50. MOST_CH_CONTROL = 1 << 0,
  51. MOST_CH_ASYNC = 1 << 1,
  52. MOST_CH_ISOC_AVP = 1 << 2,
  53. MOST_CH_SYNC = 1 << 5,
  54. };
  55. enum mbo_status_flags {
  56. /* MBO was processed successfully (data was send or received )*/
  57. MBO_SUCCESS = 0,
  58. /* The MBO contains wrong or missing information. */
  59. MBO_E_INVAL,
  60. /* MBO was completed as HDM Channel will be closed */
  61. MBO_E_CLOSE,
  62. };
  63. /**
  64. * struct most_channel_capability - Channel capability
  65. * @direction: Supported channel directions.
  66. * The value is bitwise OR-combination of the values from the
  67. * enumeration most_channel_direction. Zero is allowed value and means
  68. * "channel may not be used".
  69. * @data_type: Supported channel data types.
  70. * The value is bitwise OR-combination of the values from the
  71. * enumeration most_channel_data_type. Zero is allowed value and means
  72. * "channel may not be used".
  73. * @num_buffer_packet: Maximum number of buffers supported by this channel
  74. * for packet data types (Async,Control,QoS)
  75. * @buffer_size_packet: Maximum buffer size supported by this channel
  76. * for packet data types (Async,Control,QoS)
  77. * @num_buffer_streaming: Maximum number of buffers supported by this channel
  78. * for streaming data types (Sync,AV Packetized)
  79. * @buffer_size_streaming: Maximum buffer size supported by this channel
  80. * for streaming data types (Sync,AV Packetized)
  81. * @name_suffix: Optional suffix providean by an HDM that is attached to the
  82. * regular channel name.
  83. *
  84. * Describes the capabilities of a MostCore channel like supported Data Types
  85. * and directions. This information is provided by an HDM for the MostCore.
  86. *
  87. * The Core creates read only sysfs attribute files in
  88. * /sys/devices/virtual/most/mostcore/devices/mdev-#/mdev#-ch#/ with the
  89. * following attributes:
  90. * -available_directions
  91. * -available_datatypes
  92. * -number_of_packet_buffers
  93. * -number_of_stream_buffers
  94. * -size_of_packet_buffer
  95. * -size_of_stream_buffer
  96. * where content of each file is a string with all supported properties of this
  97. * very channel attribute.
  98. */
  99. struct most_channel_capability {
  100. u16 direction;
  101. u16 data_type;
  102. u16 num_buffers_packet;
  103. u16 buffer_size_packet;
  104. u16 num_buffers_streaming;
  105. u16 buffer_size_streaming;
  106. char *name_suffix;
  107. };
  108. /**
  109. * struct most_channel_config - stores channel configuration
  110. * @direction: direction of the channel
  111. * @data_type: data type travelling over this channel
  112. * @num_buffers: number of buffers
  113. * @buffer_size: size of a buffer for AIM.
  114. * Buffer size may be cutted down by HDM in a configure callback
  115. * to match to a given interface and channel type.
  116. * @extra_len: additional buffer space for internal HDM purposes like padding.
  117. * May be set by HDM in a configure callback if needed.
  118. * @subbuffer_size: size of a subbuffer
  119. * @packets_per_xact: number of MOST frames that are packet inside one USB
  120. * packet. This is USB specific
  121. *
  122. * Describes the configuration for a MostCore channel. This information is
  123. * provided from the MostCore to a HDM (like the Medusa PCIe Interface) as a
  124. * parameter of the "configure" function call.
  125. */
  126. struct most_channel_config {
  127. enum most_channel_direction direction;
  128. enum most_channel_data_type data_type;
  129. u16 num_buffers;
  130. u16 buffer_size;
  131. u16 extra_len;
  132. u16 subbuffer_size;
  133. u16 packets_per_xact;
  134. };
  135. /*
  136. * struct mbo - MOST Buffer Object.
  137. * @context: context for core completion handler
  138. * @priv: private data for HDM
  139. *
  140. * public: documented fields that are used for the communications
  141. * between MostCore and HDMs
  142. *
  143. * @list: list head for use by the mbo's current owner
  144. * @ifp: (in) associated interface instance
  145. * @hdm_channel_id: (in) HDM channel instance
  146. * @virt_address: (in) kernel virtual address of the buffer
  147. * @bus_address: (in) bus address of the buffer
  148. * @buffer_length: (in) buffer payload length
  149. * @processed_length: (out) processed length
  150. * @status: (out) transfer status
  151. * @complete: (in) completion routine
  152. *
  153. * The MostCore allocates and initializes the MBO.
  154. *
  155. * The HDM receives MBO for transfer from MostCore with the call to enqueue().
  156. * The HDM copies the data to- or from the buffer depending on configured
  157. * channel direction, set "processed_length" and "status" and completes
  158. * the transfer procedure by calling the completion routine.
  159. *
  160. * At the end the MostCore deallocates the MBO or recycles it for further
  161. * transfers for the same or different HDM.
  162. *
  163. * Directions of usage:
  164. * The core driver should never access any MBO fields (even if marked
  165. * as "public") while the MBO is owned by an HDM. The ownership starts with
  166. * the call of enqueue() and ends with the call of its complete() routine.
  167. *
  168. * II.
  169. * Every HDM attached to the core driver _must_ ensure that it returns any MBO
  170. * it owns (due to a previous call to enqueue() by the core driver) before it
  171. * de-registers an interface or gets unloaded from the kernel. If this direction
  172. * is violated memory leaks will occur, since the core driver does _not_ track
  173. * MBOs it is currently not in control of.
  174. *
  175. */
  176. struct mbo {
  177. void *context;
  178. void *priv;
  179. struct list_head list;
  180. struct most_interface *ifp;
  181. int *num_buffers_ptr;
  182. u16 hdm_channel_id;
  183. void *virt_address;
  184. dma_addr_t bus_address;
  185. u16 buffer_length;
  186. u16 processed_length;
  187. enum mbo_status_flags status;
  188. void (*complete)(struct mbo *);
  189. };
  190. /**
  191. * Interface instance description.
  192. *
  193. * Describes one instance of an interface like Medusa PCIe or Vantage USB.
  194. * This structure is allocated and initialized in the HDM. MostCore may not
  195. * modify this structure.
  196. *
  197. * @interface Interface type. \sa most_interface_type.
  198. * @description PRELIMINARY.
  199. * Unique description of the device instance from point of view of the
  200. * interface in free text form (ASCII).
  201. * It may be a hexadecimal presentation of the memory address for the MediaLB
  202. * IP or USB device ID with USB properties for USB interface, etc.
  203. * @num_channels Number of channels and size of the channel_vector.
  204. * @channel_vector Properties of the channels.
  205. * Array index represents channel ID by the driver.
  206. * @configure Callback to change data type for the channel of the
  207. * interface instance. May be zero if the instance of the interface is not
  208. * configurable. Parameter channel_config describes direction and data
  209. * type for the channel, configured by the higher level. The content of
  210. * @enqueue Delivers MBO to the HDM for processing.
  211. * After HDM completes Rx- or Tx- operation the processed MBO shall
  212. * be returned back to the MostCore using completion routine.
  213. * The reason to get the MBO delivered from the MostCore after the channel
  214. * is poisoned is the re-opening of the channel by the application.
  215. * In this case the HDM shall hold MBOs and service the channel as usual.
  216. * The HDM must be able to hold at least one MBO for each channel.
  217. * The callback returns a negative value on error, otherwise 0.
  218. * @poison_channel Informs HDM about closing the channel. The HDM shall
  219. * cancel all transfers and synchronously or asynchronously return
  220. * all enqueued for this channel MBOs using the completion routine.
  221. * The callback returns a negative value on error, otherwise 0.
  222. * @request_netinfo: triggers retrieving of network info from the HDM by
  223. * means of "Message exchange over MDP/MEP"
  224. * @priv Private field used by mostcore to store context information.
  225. */
  226. struct most_interface {
  227. struct module *mod;
  228. enum most_interface_type interface;
  229. const char *description;
  230. int num_channels;
  231. struct most_channel_capability *channel_vector;
  232. int (*configure)(struct most_interface *iface, int channel_idx,
  233. struct most_channel_config *channel_config);
  234. int (*enqueue)(struct most_interface *iface, int channel_idx,
  235. struct mbo *mbo);
  236. int (*poison_channel)(struct most_interface *iface, int channel_idx);
  237. void (*request_netinfo)(struct most_interface *iface, int channel_idx);
  238. void *priv;
  239. };
  240. /**
  241. * struct most_aim - identifies MOST device driver to mostcore
  242. * @name: Driver name
  243. * @probe_channel: function for core to notify driver about channel connection
  244. * @disconnect_channel: callback function to disconnect a certain channel
  245. * @rx_completion: completion handler for received packets
  246. * @tx_completion: completion handler for transmitted packets
  247. * @context: context pointer to be used by mostcore
  248. */
  249. struct most_aim {
  250. const char *name;
  251. int (*probe_channel)(struct most_interface *iface, int channel_idx,
  252. struct most_channel_config *cfg,
  253. struct kobject *parent, char *name);
  254. int (*disconnect_channel)(struct most_interface *iface,
  255. int channel_idx);
  256. int (*rx_completion)(struct mbo *mbo);
  257. int (*tx_completion)(struct most_interface *iface, int channel_idx);
  258. void *context;
  259. };
  260. /**
  261. * most_register_interface - Registers instance of the interface.
  262. * @iface: Pointer to the interface instance description.
  263. *
  264. * Returns a pointer to the kobject of the generated instance.
  265. *
  266. * Note: HDM has to ensure that any reference held on the kobj is
  267. * released before deregistering the interface.
  268. */
  269. struct kobject *most_register_interface(struct most_interface *iface);
  270. /**
  271. * Deregisters instance of the interface.
  272. * @intf_instance Pointer to the interface instance description.
  273. */
  274. void most_deregister_interface(struct most_interface *iface);
  275. int most_submit_mbo(struct mbo *mbo);
  276. /**
  277. * most_stop_enqueue - prevents core from enqueing MBOs
  278. * @iface: pointer to interface
  279. * @channel_idx: channel index
  280. */
  281. void most_stop_enqueue(struct most_interface *iface, int channel_idx);
  282. /**
  283. * most_resume_enqueue - allow core to enqueue MBOs again
  284. * @iface: pointer to interface
  285. * @channel_idx: channel index
  286. *
  287. * This clears the enqueue halt flag and enqueues all MBOs currently
  288. * in wait fifo.
  289. */
  290. void most_resume_enqueue(struct most_interface *iface, int channel_idx);
  291. int most_register_aim(struct most_aim *aim);
  292. int most_deregister_aim(struct most_aim *aim);
  293. struct mbo *most_get_mbo(struct most_interface *iface, int channel_idx,
  294. struct most_aim *);
  295. void most_put_mbo(struct mbo *mbo);
  296. int channel_has_mbo(struct most_interface *iface, int channel_idx);
  297. int most_start_channel(struct most_interface *iface, int channel_idx,
  298. struct most_aim *);
  299. int most_stop_channel(struct most_interface *iface, int channel_idx,
  300. struct most_aim *);
  301. #endif /* MOST_CORE_H_ */