firewire-cdev.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. /*
  2. * Char device interface.
  3. *
  4. * Copyright (C) 2005-2006 Kristian Hoegsberg <krh@bitplanet.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. #ifndef _LINUX_FIREWIRE_CDEV_H
  21. #define _LINUX_FIREWIRE_CDEV_H
  22. #include <linux/ioctl.h>
  23. #include <linux/types.h>
  24. #include <linux/firewire-constants.h>
  25. #define FW_CDEV_EVENT_BUS_RESET 0x00
  26. #define FW_CDEV_EVENT_RESPONSE 0x01
  27. #define FW_CDEV_EVENT_REQUEST 0x02
  28. #define FW_CDEV_EVENT_ISO_INTERRUPT 0x03
  29. #define FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED 0x04
  30. #define FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED 0x05
  31. /* available since kernel version 2.6.36 */
  32. #define FW_CDEV_EVENT_REQUEST2 0x06
  33. #define FW_CDEV_EVENT_PHY_PACKET_SENT 0x07
  34. /**
  35. * struct fw_cdev_event_common - Common part of all fw_cdev_event_ types
  36. * @closure: For arbitrary use by userspace
  37. * @type: Discriminates the fw_cdev_event_ types
  38. *
  39. * This struct may be used to access generic members of all fw_cdev_event_
  40. * types regardless of the specific type.
  41. *
  42. * Data passed in the @closure field for a request will be returned in the
  43. * corresponding event. It is big enough to hold a pointer on all platforms.
  44. * The ioctl used to set @closure depends on the @type of event.
  45. */
  46. struct fw_cdev_event_common {
  47. __u64 closure;
  48. __u32 type;
  49. };
  50. /**
  51. * struct fw_cdev_event_bus_reset - Sent when a bus reset occurred
  52. * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_GET_INFO ioctl
  53. * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_BUS_RESET
  54. * @node_id: New node ID of this node
  55. * @local_node_id: Node ID of the local node, i.e. of the controller
  56. * @bm_node_id: Node ID of the bus manager
  57. * @irm_node_id: Node ID of the iso resource manager
  58. * @root_node_id: Node ID of the root node
  59. * @generation: New bus generation
  60. *
  61. * This event is sent when the bus the device belongs to goes through a bus
  62. * reset. It provides information about the new bus configuration, such as
  63. * new node ID for this device, new root ID, and others.
  64. *
  65. * If @bm_node_id is 0xffff right after bus reset it can be reread by an
  66. * %FW_CDEV_IOC_GET_INFO ioctl after bus manager selection was finished.
  67. * Kernels with ABI version < 4 do not set @bm_node_id.
  68. */
  69. struct fw_cdev_event_bus_reset {
  70. __u64 closure;
  71. __u32 type;
  72. __u32 node_id;
  73. __u32 local_node_id;
  74. __u32 bm_node_id;
  75. __u32 irm_node_id;
  76. __u32 root_node_id;
  77. __u32 generation;
  78. };
  79. /**
  80. * struct fw_cdev_event_response - Sent when a response packet was received
  81. * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_SEND_REQUEST
  82. * or %FW_CDEV_IOC_SEND_BROADCAST_REQUEST
  83. * or %FW_CDEV_IOC_SEND_STREAM_PACKET ioctl
  84. * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_RESPONSE
  85. * @rcode: Response code returned by the remote node
  86. * @length: Data length, i.e. the response's payload size in bytes
  87. * @data: Payload data, if any
  88. *
  89. * This event is sent when the stack receives a response to an outgoing request
  90. * sent by %FW_CDEV_IOC_SEND_REQUEST ioctl. The payload data for responses
  91. * carrying data (read and lock responses) follows immediately and can be
  92. * accessed through the @data field.
  93. *
  94. * The event is also generated after conclusions of transactions that do not
  95. * involve response packets. This includes unified write transactions,
  96. * broadcast write transactions, and transmission of asynchronous stream
  97. * packets. @rcode indicates success or failure of such transmissions.
  98. */
  99. struct fw_cdev_event_response {
  100. __u64 closure;
  101. __u32 type;
  102. __u32 rcode;
  103. __u32 length;
  104. __u32 data[0];
  105. };
  106. /**
  107. * struct fw_cdev_event_request - Old version of &fw_cdev_event_request2
  108. * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_ALLOCATE ioctl
  109. * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_REQUEST
  110. * @tcode: See &fw_cdev_event_request2
  111. * @offset: See &fw_cdev_event_request2
  112. * @handle: See &fw_cdev_event_request2
  113. * @length: See &fw_cdev_event_request2
  114. * @data: See &fw_cdev_event_request2
  115. *
  116. * This event is sent instead of &fw_cdev_event_request2 if the kernel or
  117. * the client implements ABI version <= 3.
  118. *
  119. * Unlike &fw_cdev_event_request2, the sender identity cannot be established,
  120. * broadcast write requests cannot be distinguished from unicast writes, and
  121. * @tcode of lock requests is %TCODE_LOCK_REQUEST.
  122. *
  123. * Requests to the FCP_REQUEST or FCP_RESPONSE register are responded to as
  124. * with &fw_cdev_event_request2, except in kernel 2.6.32 and older which send
  125. * the response packet of the client's %FW_CDEV_IOC_SEND_RESPONSE ioctl.
  126. */
  127. struct fw_cdev_event_request {
  128. __u64 closure;
  129. __u32 type;
  130. __u32 tcode;
  131. __u64 offset;
  132. __u32 handle;
  133. __u32 length;
  134. __u32 data[0];
  135. };
  136. /**
  137. * struct fw_cdev_event_request2 - Sent on incoming request to an address region
  138. * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_ALLOCATE ioctl
  139. * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_REQUEST2
  140. * @tcode: Transaction code of the incoming request
  141. * @offset: The offset into the 48-bit per-node address space
  142. * @source_node_id: Sender node ID
  143. * @destination_node_id: Destination node ID
  144. * @card: The index of the card from which the request came
  145. * @generation: Bus generation in which the request is valid
  146. * @handle: Reference to the kernel-side pending request
  147. * @length: Data length, i.e. the request's payload size in bytes
  148. * @data: Incoming data, if any
  149. *
  150. * This event is sent when the stack receives an incoming request to an address
  151. * region registered using the %FW_CDEV_IOC_ALLOCATE ioctl. The request is
  152. * guaranteed to be completely contained in the specified region. Userspace is
  153. * responsible for sending the response by %FW_CDEV_IOC_SEND_RESPONSE ioctl,
  154. * using the same @handle.
  155. *
  156. * The payload data for requests carrying data (write and lock requests)
  157. * follows immediately and can be accessed through the @data field.
  158. *
  159. * Unlike &fw_cdev_event_request, @tcode of lock requests is one of the
  160. * firewire-core specific %TCODE_LOCK_MASK_SWAP...%TCODE_LOCK_VENDOR_DEPENDENT,
  161. * i.e. encodes the extended transaction code.
  162. *
  163. * @card may differ from &fw_cdev_get_info.card because requests are received
  164. * from all cards of the Linux host. @source_node_id, @destination_node_id, and
  165. * @generation pertain to that card. Destination node ID and bus generation may
  166. * therefore differ from the corresponding fields of the last
  167. * &fw_cdev_event_bus_reset.
  168. *
  169. * @destination_node_id may also differ from the current node ID because of a
  170. * non-local bus ID part or in case of a broadcast write request. Note, a
  171. * client must call an %FW_CDEV_IOC_SEND_RESPONSE ioctl even in case of a
  172. * broadcast write request; the kernel will then release the kernel-side pending
  173. * request but will not actually send a response packet.
  174. *
  175. * In case of a write request to FCP_REQUEST or FCP_RESPONSE, the kernel already
  176. * sent a write response immediately after the request was received; in this
  177. * case the client must still call an %FW_CDEV_IOC_SEND_RESPONSE ioctl to
  178. * release the kernel-side pending request, though another response won't be
  179. * sent.
  180. *
  181. * If the client subsequently needs to initiate requests to the sender node of
  182. * an &fw_cdev_event_request2, it needs to use a device file with matching
  183. * card index, node ID, and generation for outbound requests.
  184. */
  185. struct fw_cdev_event_request2 {
  186. __u64 closure;
  187. __u32 type;
  188. __u32 tcode;
  189. __u64 offset;
  190. __u32 source_node_id;
  191. __u32 destination_node_id;
  192. __u32 card;
  193. __u32 generation;
  194. __u32 handle;
  195. __u32 length;
  196. __u32 data[0];
  197. };
  198. /**
  199. * struct fw_cdev_event_iso_interrupt - Sent when an iso packet was completed
  200. * @closure: See &fw_cdev_event_common;
  201. * set by %FW_CDEV_CREATE_ISO_CONTEXT ioctl
  202. * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_ISO_INTERRUPT
  203. * @cycle: Cycle counter of the interrupt packet
  204. * @header_length: Total length of following headers, in bytes
  205. * @header: Stripped headers, if any
  206. *
  207. * This event is sent when the controller has completed an &fw_cdev_iso_packet
  208. * with the %FW_CDEV_ISO_INTERRUPT bit set.
  209. *
  210. * Isochronous transmit events:
  211. *
  212. * In version 1 of the ABI, &header_length is 0. In version 3 and some
  213. * implementations of version 2 of the ABI, &header_length is a multiple of 4
  214. * and &header contains timestamps of all packets up until the interrupt packet.
  215. * The format of the timestamps is as described below for isochronous reception.
  216. *
  217. * Isochronous receive events:
  218. *
  219. * The headers stripped of all packets up until and including the interrupt
  220. * packet are returned in the @header field. The amount of header data per
  221. * packet is as specified at iso context creation by
  222. * &fw_cdev_create_iso_context.header_size.
  223. *
  224. * In version 1 of this ABI, header data consisted of the 1394 isochronous
  225. * packet header, followed by quadlets from the packet payload if
  226. * &fw_cdev_create_iso_context.header_size > 4.
  227. *
  228. * In version 2 of this ABI, header data consist of the 1394 isochronous
  229. * packet header, followed by a timestamp quadlet if
  230. * &fw_cdev_create_iso_context.header_size > 4, followed by quadlets from the
  231. * packet payload if &fw_cdev_create_iso_context.header_size > 8.
  232. *
  233. * Behaviour of ver. 1 of this ABI is no longer available since ABI ver. 2.
  234. *
  235. * Format of 1394 iso packet header: 16 bits len, 2 bits tag, 6 bits channel,
  236. * 4 bits tcode, 4 bits sy, in big endian byte order. Format of timestamp:
  237. * 16 bits invalid, 3 bits cycleSeconds, 13 bits cycleCount, in big endian byte
  238. * order.
  239. */
  240. struct fw_cdev_event_iso_interrupt {
  241. __u64 closure;
  242. __u32 type;
  243. __u32 cycle;
  244. __u32 header_length;
  245. __u32 header[0];
  246. };
  247. /**
  248. * struct fw_cdev_event_iso_resource - Iso resources were allocated or freed
  249. * @closure: See &fw_cdev_event_common;
  250. * set by %FW_CDEV_IOC_(DE)ALLOCATE_ISO_RESOURCE(_ONCE) ioctl
  251. * @type: %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED or
  252. * %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED
  253. * @handle: Reference by which an allocated resource can be deallocated
  254. * @channel: Isochronous channel which was (de)allocated, if any
  255. * @bandwidth: Bandwidth allocation units which were (de)allocated, if any
  256. *
  257. * An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED event is sent after an isochronous
  258. * resource was allocated at the IRM. The client has to check @channel and
  259. * @bandwidth for whether the allocation actually succeeded.
  260. *
  261. * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event is sent after an isochronous
  262. * resource was deallocated at the IRM. It is also sent when automatic
  263. * reallocation after a bus reset failed.
  264. *
  265. * @channel is <0 if no channel was (de)allocated or if reallocation failed.
  266. * @bandwidth is 0 if no bandwidth was (de)allocated or if reallocation failed.
  267. */
  268. struct fw_cdev_event_iso_resource {
  269. __u64 closure;
  270. __u32 type;
  271. __u32 handle;
  272. __s32 channel;
  273. __s32 bandwidth;
  274. };
  275. /**
  276. * struct fw_cdev_event_phy_packet - A PHY packet was transmitted
  277. * @closure: See &fw_cdev_event_common;
  278. * set by %FW_CDEV_IOC_SEND_PHY_PACKET ioctl
  279. * @type: %FW_CDEV_EVENT_PHY_PACKET_SENT
  280. * @rcode: %RCODE_..., indicates success or failure of transmission
  281. */
  282. struct fw_cdev_event_phy_packet {
  283. __u64 closure;
  284. __u32 type;
  285. __u32 rcode;
  286. };
  287. /**
  288. * union fw_cdev_event - Convenience union of fw_cdev_event_ types
  289. * @common: Valid for all types
  290. * @bus_reset: Valid if @common.type == %FW_CDEV_EVENT_BUS_RESET
  291. * @response: Valid if @common.type == %FW_CDEV_EVENT_RESPONSE
  292. * @request: Valid if @common.type == %FW_CDEV_EVENT_REQUEST
  293. * @request2: Valid if @common.type == %FW_CDEV_EVENT_REQUEST2
  294. * @iso_interrupt: Valid if @common.type == %FW_CDEV_EVENT_ISO_INTERRUPT
  295. * @iso_resource: Valid if @common.type ==
  296. * %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED or
  297. * %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED
  298. * @phy_packet: Valid if @common.type == %FW_CDEV_EVENT_PHY_PACKET_SENT
  299. *
  300. * Convenience union for userspace use. Events could be read(2) into an
  301. * appropriately aligned char buffer and then cast to this union for further
  302. * processing. Note that for a request, response or iso_interrupt event,
  303. * the data[] or header[] may make the size of the full event larger than
  304. * sizeof(union fw_cdev_event). Also note that if you attempt to read(2)
  305. * an event into a buffer that is not large enough for it, the data that does
  306. * not fit will be discarded so that the next read(2) will return a new event.
  307. */
  308. union fw_cdev_event {
  309. struct fw_cdev_event_common common;
  310. struct fw_cdev_event_bus_reset bus_reset;
  311. struct fw_cdev_event_response response;
  312. struct fw_cdev_event_request request;
  313. struct fw_cdev_event_request2 request2; /* added in 2.6.36 */
  314. struct fw_cdev_event_iso_interrupt iso_interrupt;
  315. struct fw_cdev_event_iso_resource iso_resource; /* added in 2.6.30 */
  316. struct fw_cdev_event_phy_packet phy_packet; /* added in 2.6.36 */
  317. };
  318. /* available since kernel version 2.6.22 */
  319. #define FW_CDEV_IOC_GET_INFO _IOWR('#', 0x00, struct fw_cdev_get_info)
  320. #define FW_CDEV_IOC_SEND_REQUEST _IOW('#', 0x01, struct fw_cdev_send_request)
  321. #define FW_CDEV_IOC_ALLOCATE _IOWR('#', 0x02, struct fw_cdev_allocate)
  322. #define FW_CDEV_IOC_DEALLOCATE _IOW('#', 0x03, struct fw_cdev_deallocate)
  323. #define FW_CDEV_IOC_SEND_RESPONSE _IOW('#', 0x04, struct fw_cdev_send_response)
  324. #define FW_CDEV_IOC_INITIATE_BUS_RESET _IOW('#', 0x05, struct fw_cdev_initiate_bus_reset)
  325. #define FW_CDEV_IOC_ADD_DESCRIPTOR _IOWR('#', 0x06, struct fw_cdev_add_descriptor)
  326. #define FW_CDEV_IOC_REMOVE_DESCRIPTOR _IOW('#', 0x07, struct fw_cdev_remove_descriptor)
  327. #define FW_CDEV_IOC_CREATE_ISO_CONTEXT _IOWR('#', 0x08, struct fw_cdev_create_iso_context)
  328. #define FW_CDEV_IOC_QUEUE_ISO _IOWR('#', 0x09, struct fw_cdev_queue_iso)
  329. #define FW_CDEV_IOC_START_ISO _IOW('#', 0x0a, struct fw_cdev_start_iso)
  330. #define FW_CDEV_IOC_STOP_ISO _IOW('#', 0x0b, struct fw_cdev_stop_iso)
  331. /* available since kernel version 2.6.24 */
  332. #define FW_CDEV_IOC_GET_CYCLE_TIMER _IOR('#', 0x0c, struct fw_cdev_get_cycle_timer)
  333. /* available since kernel version 2.6.30 */
  334. #define FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE _IOWR('#', 0x0d, struct fw_cdev_allocate_iso_resource)
  335. #define FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE _IOW('#', 0x0e, struct fw_cdev_deallocate)
  336. #define FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE _IOW('#', 0x0f, struct fw_cdev_allocate_iso_resource)
  337. #define FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE _IOW('#', 0x10, struct fw_cdev_allocate_iso_resource)
  338. #define FW_CDEV_IOC_GET_SPEED _IO('#', 0x11) /* returns speed code */
  339. #define FW_CDEV_IOC_SEND_BROADCAST_REQUEST _IOW('#', 0x12, struct fw_cdev_send_request)
  340. #define FW_CDEV_IOC_SEND_STREAM_PACKET _IOW('#', 0x13, struct fw_cdev_send_stream_packet)
  341. /* available since kernel version 2.6.34 */
  342. #define FW_CDEV_IOC_GET_CYCLE_TIMER2 _IOWR('#', 0x14, struct fw_cdev_get_cycle_timer2)
  343. /* available since kernel version 2.6.36 */
  344. #define FW_CDEV_IOC_SEND_PHY_PACKET _IOWR('#', 0x15, struct fw_cdev_send_phy_packet)
  345. /*
  346. * ABI version history
  347. * 1 (2.6.22) - initial version
  348. * (2.6.24) - added %FW_CDEV_IOC_GET_CYCLE_TIMER
  349. * 2 (2.6.30) - changed &fw_cdev_event_iso_interrupt.header if
  350. * &fw_cdev_create_iso_context.header_size is 8 or more
  351. * - added %FW_CDEV_IOC_*_ISO_RESOURCE*,
  352. * %FW_CDEV_IOC_GET_SPEED, %FW_CDEV_IOC_SEND_BROADCAST_REQUEST,
  353. * %FW_CDEV_IOC_SEND_STREAM_PACKET
  354. * (2.6.32) - added time stamp to xmit &fw_cdev_event_iso_interrupt
  355. * (2.6.33) - IR has always packet-per-buffer semantics now, not one of
  356. * dual-buffer or packet-per-buffer depending on hardware
  357. * - shared use and auto-response for FCP registers
  358. * 3 (2.6.34) - made &fw_cdev_get_cycle_timer reliable
  359. * - added %FW_CDEV_IOC_GET_CYCLE_TIMER2
  360. * 4 (2.6.36) - added %FW_CDEV_EVENT_REQUEST2, %FW_CDEV_EVENT_PHY_PACKET_SENT
  361. * - implemented &fw_cdev_event_bus_reset.bm_node_id
  362. * - added %FW_CDEV_IOC_SEND_PHY_PACKET
  363. */
  364. #define FW_CDEV_VERSION 3 /* Meaningless; don't use this macro. */
  365. /**
  366. * struct fw_cdev_get_info - General purpose information ioctl
  367. * @version: The version field is just a running serial number. Both an
  368. * input parameter (ABI version implemented by the client) and
  369. * output parameter (ABI version implemented by the kernel).
  370. * A client must not fill in an %FW_CDEV_VERSION defined from an
  371. * included kernel header file but the actual version for which
  372. * the client was implemented. This is necessary for forward
  373. * compatibility. We never break backwards compatibility, but
  374. * may add more structs, events, and ioctls in later revisions.
  375. * @rom_length: If @rom is non-zero, at most rom_length bytes of configuration
  376. * ROM will be copied into that user space address. In either
  377. * case, @rom_length is updated with the actual length of the
  378. * configuration ROM.
  379. * @rom: If non-zero, address of a buffer to be filled by a copy of the
  380. * device's configuration ROM
  381. * @bus_reset: If non-zero, address of a buffer to be filled by a
  382. * &struct fw_cdev_event_bus_reset with the current state
  383. * of the bus. This does not cause a bus reset to happen.
  384. * @bus_reset_closure: Value of &closure in this and subsequent bus reset events
  385. * @card: The index of the card this device belongs to
  386. */
  387. struct fw_cdev_get_info {
  388. __u32 version;
  389. __u32 rom_length;
  390. __u64 rom;
  391. __u64 bus_reset;
  392. __u64 bus_reset_closure;
  393. __u32 card;
  394. };
  395. /**
  396. * struct fw_cdev_send_request - Send an asynchronous request packet
  397. * @tcode: Transaction code of the request
  398. * @length: Length of outgoing payload, in bytes
  399. * @offset: 48-bit offset at destination node
  400. * @closure: Passed back to userspace in the response event
  401. * @data: Userspace pointer to payload
  402. * @generation: The bus generation where packet is valid
  403. *
  404. * Send a request to the device. This ioctl implements all outgoing requests.
  405. * Both quadlet and block request specify the payload as a pointer to the data
  406. * in the @data field. Once the transaction completes, the kernel writes an
  407. * &fw_cdev_event_response event back. The @closure field is passed back to
  408. * user space in the response event.
  409. */
  410. struct fw_cdev_send_request {
  411. __u32 tcode;
  412. __u32 length;
  413. __u64 offset;
  414. __u64 closure;
  415. __u64 data;
  416. __u32 generation;
  417. };
  418. /**
  419. * struct fw_cdev_send_response - Send an asynchronous response packet
  420. * @rcode: Response code as determined by the userspace handler
  421. * @length: Length of outgoing payload, in bytes
  422. * @data: Userspace pointer to payload
  423. * @handle: The handle from the &fw_cdev_event_request
  424. *
  425. * Send a response to an incoming request. By setting up an address range using
  426. * the %FW_CDEV_IOC_ALLOCATE ioctl, userspace can listen for incoming requests. An
  427. * incoming request will generate an %FW_CDEV_EVENT_REQUEST, and userspace must
  428. * send a reply using this ioctl. The event has a handle to the kernel-side
  429. * pending transaction, which should be used with this ioctl.
  430. */
  431. struct fw_cdev_send_response {
  432. __u32 rcode;
  433. __u32 length;
  434. __u64 data;
  435. __u32 handle;
  436. };
  437. /**
  438. * struct fw_cdev_allocate - Allocate a CSR address range
  439. * @offset: Start offset of the address range
  440. * @closure: To be passed back to userspace in request events
  441. * @length: Length of the address range, in bytes
  442. * @handle: Handle to the allocation, written by the kernel
  443. *
  444. * Allocate an address range in the 48-bit address space on the local node
  445. * (the controller). This allows userspace to listen for requests with an
  446. * offset within that address range. When the kernel receives a request
  447. * within the range, an &fw_cdev_event_request event will be written back.
  448. * The @closure field is passed back to userspace in the response event.
  449. * The @handle field is an out parameter, returning a handle to the allocated
  450. * range to be used for later deallocation of the range.
  451. *
  452. * The address range is allocated on all local nodes. The address allocation
  453. * is exclusive except for the FCP command and response registers. If an
  454. * exclusive address region is already in use, the ioctl fails with errno set
  455. * to %EBUSY.
  456. */
  457. struct fw_cdev_allocate {
  458. __u64 offset;
  459. __u64 closure;
  460. __u32 length;
  461. __u32 handle;
  462. };
  463. /**
  464. * struct fw_cdev_deallocate - Free a CSR address range or isochronous resource
  465. * @handle: Handle to the address range or iso resource, as returned by the
  466. * kernel when the range or resource was allocated
  467. */
  468. struct fw_cdev_deallocate {
  469. __u32 handle;
  470. };
  471. #define FW_CDEV_LONG_RESET 0
  472. #define FW_CDEV_SHORT_RESET 1
  473. /**
  474. * struct fw_cdev_initiate_bus_reset - Initiate a bus reset
  475. * @type: %FW_CDEV_SHORT_RESET or %FW_CDEV_LONG_RESET
  476. *
  477. * Initiate a bus reset for the bus this device is on. The bus reset can be
  478. * either the original (long) bus reset or the arbitrated (short) bus reset
  479. * introduced in 1394a-2000.
  480. *
  481. * The ioctl returns immediately. A subsequent &fw_cdev_event_bus_reset
  482. * indicates when the reset actually happened. Since ABI v4, this may be
  483. * considerably later than the ioctl because the kernel ensures a grace period
  484. * between subsequent bus resets as per IEEE 1394 bus management specification.
  485. */
  486. struct fw_cdev_initiate_bus_reset {
  487. __u32 type;
  488. };
  489. /**
  490. * struct fw_cdev_add_descriptor - Add contents to the local node's config ROM
  491. * @immediate: If non-zero, immediate key to insert before pointer
  492. * @key: Upper 8 bits of root directory pointer
  493. * @data: Userspace pointer to contents of descriptor block
  494. * @length: Length of descriptor block data, in quadlets
  495. * @handle: Handle to the descriptor, written by the kernel
  496. *
  497. * Add a descriptor block and optionally a preceding immediate key to the local
  498. * node's configuration ROM.
  499. *
  500. * The @key field specifies the upper 8 bits of the descriptor root directory
  501. * pointer and the @data and @length fields specify the contents. The @key
  502. * should be of the form 0xXX000000. The offset part of the root directory entry
  503. * will be filled in by the kernel.
  504. *
  505. * If not 0, the @immediate field specifies an immediate key which will be
  506. * inserted before the root directory pointer.
  507. *
  508. * @immediate, @key, and @data array elements are CPU-endian quadlets.
  509. *
  510. * If successful, the kernel adds the descriptor and writes back a @handle to
  511. * the kernel-side object to be used for later removal of the descriptor block
  512. * and immediate key. The kernel will also generate a bus reset to signal the
  513. * change of the configuration ROM to other nodes.
  514. *
  515. * This ioctl affects the configuration ROMs of all local nodes.
  516. * The ioctl only succeeds on device files which represent a local node.
  517. */
  518. struct fw_cdev_add_descriptor {
  519. __u32 immediate;
  520. __u32 key;
  521. __u64 data;
  522. __u32 length;
  523. __u32 handle;
  524. };
  525. /**
  526. * struct fw_cdev_remove_descriptor - Remove contents from the configuration ROM
  527. * @handle: Handle to the descriptor, as returned by the kernel when the
  528. * descriptor was added
  529. *
  530. * Remove a descriptor block and accompanying immediate key from the local
  531. * nodes' configuration ROMs. The kernel will also generate a bus reset to
  532. * signal the change of the configuration ROM to other nodes.
  533. */
  534. struct fw_cdev_remove_descriptor {
  535. __u32 handle;
  536. };
  537. #define FW_CDEV_ISO_CONTEXT_TRANSMIT 0
  538. #define FW_CDEV_ISO_CONTEXT_RECEIVE 1
  539. /**
  540. * struct fw_cdev_create_iso_context - Create a context for isochronous IO
  541. * @type: %FW_CDEV_ISO_CONTEXT_TRANSMIT or %FW_CDEV_ISO_CONTEXT_RECEIVE
  542. * @header_size: Header size to strip for receive contexts
  543. * @channel: Channel to bind to
  544. * @speed: Speed for transmit contexts
  545. * @closure: To be returned in &fw_cdev_event_iso_interrupt
  546. * @handle: Handle to context, written back by kernel
  547. *
  548. * Prior to sending or receiving isochronous I/O, a context must be created.
  549. * The context records information about the transmit or receive configuration
  550. * and typically maps to an underlying hardware resource. A context is set up
  551. * for either sending or receiving. It is bound to a specific isochronous
  552. * channel.
  553. *
  554. * If a context was successfully created, the kernel writes back a handle to the
  555. * context, which must be passed in for subsequent operations on that context.
  556. *
  557. * For receive contexts, @header_size must be at least 4 and must be a multiple
  558. * of 4.
  559. *
  560. * Note that the effect of a @header_size > 4 depends on
  561. * &fw_cdev_get_info.version, as documented at &fw_cdev_event_iso_interrupt.
  562. *
  563. * No more than one iso context can be created per fd.
  564. */
  565. struct fw_cdev_create_iso_context {
  566. __u32 type;
  567. __u32 header_size;
  568. __u32 channel;
  569. __u32 speed;
  570. __u64 closure;
  571. __u32 handle;
  572. };
  573. #define FW_CDEV_ISO_PAYLOAD_LENGTH(v) (v)
  574. #define FW_CDEV_ISO_INTERRUPT (1 << 16)
  575. #define FW_CDEV_ISO_SKIP (1 << 17)
  576. #define FW_CDEV_ISO_SYNC (1 << 17)
  577. #define FW_CDEV_ISO_TAG(v) ((v) << 18)
  578. #define FW_CDEV_ISO_SY(v) ((v) << 20)
  579. #define FW_CDEV_ISO_HEADER_LENGTH(v) ((v) << 24)
  580. /**
  581. * struct fw_cdev_iso_packet - Isochronous packet
  582. * @control: Contains the header length (8 uppermost bits), the sy field
  583. * (4 bits), the tag field (2 bits), a sync flag (1 bit),
  584. * a skip flag (1 bit), an interrupt flag (1 bit), and the
  585. * payload length (16 lowermost bits)
  586. * @header: Header and payload
  587. *
  588. * &struct fw_cdev_iso_packet is used to describe isochronous packet queues.
  589. *
  590. * Use the FW_CDEV_ISO_ macros to fill in @control.
  591. *
  592. * For transmit packets, the header length must be a multiple of 4 and specifies
  593. * the numbers of bytes in @header that will be prepended to the packet's
  594. * payload; these bytes are copied into the kernel and will not be accessed
  595. * after the ioctl has returned. The sy and tag fields are copied to the iso
  596. * packet header (these fields are specified by IEEE 1394a and IEC 61883-1).
  597. * The skip flag specifies that no packet is to be sent in a frame; when using
  598. * this, all other fields except the interrupt flag must be zero.
  599. *
  600. * For receive packets, the header length must be a multiple of the context's
  601. * header size; if the header length is larger than the context's header size,
  602. * multiple packets are queued for this entry. The sy and tag fields are
  603. * ignored. If the sync flag is set, the context drops all packets until
  604. * a packet with a matching sy field is received (the sync value to wait for is
  605. * specified in the &fw_cdev_start_iso structure). The payload length defines
  606. * how many payload bytes can be received for one packet (in addition to payload
  607. * quadlets that have been defined as headers and are stripped and returned in
  608. * the &fw_cdev_event_iso_interrupt structure). If more bytes are received, the
  609. * additional bytes are dropped. If less bytes are received, the remaining
  610. * bytes in this part of the payload buffer will not be written to, not even by
  611. * the next packet, i.e., packets received in consecutive frames will not
  612. * necessarily be consecutive in memory. If an entry has queued multiple
  613. * packets, the payload length is divided equally among them.
  614. *
  615. * When a packet with the interrupt flag set has been completed, the
  616. * &fw_cdev_event_iso_interrupt event will be sent. An entry that has queued
  617. * multiple receive packets is completed when its last packet is completed.
  618. */
  619. struct fw_cdev_iso_packet {
  620. __u32 control;
  621. __u32 header[0];
  622. };
  623. /**
  624. * struct fw_cdev_queue_iso - Queue isochronous packets for I/O
  625. * @packets: Userspace pointer to packet data
  626. * @data: Pointer into mmap()'ed payload buffer
  627. * @size: Size of packet data in bytes
  628. * @handle: Isochronous context handle
  629. *
  630. * Queue a number of isochronous packets for reception or transmission.
  631. * This ioctl takes a pointer to an array of &fw_cdev_iso_packet structs,
  632. * which describe how to transmit from or receive into a contiguous region
  633. * of a mmap()'ed payload buffer. As part of transmit packet descriptors,
  634. * a series of headers can be supplied, which will be prepended to the
  635. * payload during DMA.
  636. *
  637. * The kernel may or may not queue all packets, but will write back updated
  638. * values of the @packets, @data and @size fields, so the ioctl can be
  639. * resubmitted easily.
  640. */
  641. struct fw_cdev_queue_iso {
  642. __u64 packets;
  643. __u64 data;
  644. __u32 size;
  645. __u32 handle;
  646. };
  647. #define FW_CDEV_ISO_CONTEXT_MATCH_TAG0 1
  648. #define FW_CDEV_ISO_CONTEXT_MATCH_TAG1 2
  649. #define FW_CDEV_ISO_CONTEXT_MATCH_TAG2 4
  650. #define FW_CDEV_ISO_CONTEXT_MATCH_TAG3 8
  651. #define FW_CDEV_ISO_CONTEXT_MATCH_ALL_TAGS 15
  652. /**
  653. * struct fw_cdev_start_iso - Start an isochronous transmission or reception
  654. * @cycle: Cycle in which to start I/O. If @cycle is greater than or
  655. * equal to 0, the I/O will start on that cycle.
  656. * @sync: Determines the value to wait for for receive packets that have
  657. * the %FW_CDEV_ISO_SYNC bit set
  658. * @tags: Tag filter bit mask. Only valid for isochronous reception.
  659. * Determines the tag values for which packets will be accepted.
  660. * Use FW_CDEV_ISO_CONTEXT_MATCH_ macros to set @tags.
  661. * @handle: Isochronous context handle within which to transmit or receive
  662. */
  663. struct fw_cdev_start_iso {
  664. __s32 cycle;
  665. __u32 sync;
  666. __u32 tags;
  667. __u32 handle;
  668. };
  669. /**
  670. * struct fw_cdev_stop_iso - Stop an isochronous transmission or reception
  671. * @handle: Handle of isochronous context to stop
  672. */
  673. struct fw_cdev_stop_iso {
  674. __u32 handle;
  675. };
  676. /**
  677. * struct fw_cdev_get_cycle_timer - read cycle timer register
  678. * @local_time: system time, in microseconds since the Epoch
  679. * @cycle_timer: Cycle Time register contents
  680. *
  681. * The %FW_CDEV_IOC_GET_CYCLE_TIMER ioctl reads the isochronous cycle timer
  682. * and also the system clock (%CLOCK_REALTIME). This allows to express the
  683. * receive time of an isochronous packet as a system time.
  684. *
  685. * @cycle_timer consists of 7 bits cycleSeconds, 13 bits cycleCount, and
  686. * 12 bits cycleOffset, in host byte order. Cf. the Cycle Time register
  687. * per IEEE 1394 or Isochronous Cycle Timer register per OHCI-1394.
  688. *
  689. * In version 1 and 2 of the ABI, this ioctl returned unreliable (non-
  690. * monotonic) @cycle_timer values on certain controllers.
  691. */
  692. struct fw_cdev_get_cycle_timer {
  693. __u64 local_time;
  694. __u32 cycle_timer;
  695. };
  696. /**
  697. * struct fw_cdev_get_cycle_timer2 - read cycle timer register
  698. * @tv_sec: system time, seconds
  699. * @tv_nsec: system time, sub-seconds part in nanoseconds
  700. * @clk_id: input parameter, clock from which to get the system time
  701. * @cycle_timer: Cycle Time register contents
  702. *
  703. * The %FW_CDEV_IOC_GET_CYCLE_TIMER2 works like
  704. * %FW_CDEV_IOC_GET_CYCLE_TIMER but lets you choose a clock like with POSIX'
  705. * clock_gettime function. Supported @clk_id values are POSIX' %CLOCK_REALTIME
  706. * and %CLOCK_MONOTONIC and Linux' %CLOCK_MONOTONIC_RAW.
  707. */
  708. struct fw_cdev_get_cycle_timer2 {
  709. __s64 tv_sec;
  710. __s32 tv_nsec;
  711. __s32 clk_id;
  712. __u32 cycle_timer;
  713. };
  714. /**
  715. * struct fw_cdev_allocate_iso_resource - (De)allocate a channel or bandwidth
  716. * @closure: Passed back to userspace in correponding iso resource events
  717. * @channels: Isochronous channels of which one is to be (de)allocated
  718. * @bandwidth: Isochronous bandwidth units to be (de)allocated
  719. * @handle: Handle to the allocation, written by the kernel (only valid in
  720. * case of %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE ioctls)
  721. *
  722. * The %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE ioctl initiates allocation of an
  723. * isochronous channel and/or of isochronous bandwidth at the isochronous
  724. * resource manager (IRM). Only one of the channels specified in @channels is
  725. * allocated. An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED is sent after
  726. * communication with the IRM, indicating success or failure in the event data.
  727. * The kernel will automatically reallocate the resources after bus resets.
  728. * Should a reallocation fail, an %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event
  729. * will be sent. The kernel will also automatically deallocate the resources
  730. * when the file descriptor is closed.
  731. *
  732. * The %FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE ioctl can be used to initiate
  733. * deallocation of resources which were allocated as described above.
  734. * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event concludes this operation.
  735. *
  736. * The %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE ioctl is a variant of allocation
  737. * without automatic re- or deallocation.
  738. * An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED event concludes this operation,
  739. * indicating success or failure in its data.
  740. *
  741. * The %FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE ioctl works like
  742. * %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE except that resources are freed
  743. * instead of allocated.
  744. * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event concludes this operation.
  745. *
  746. * To summarize, %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE allocates iso resources
  747. * for the lifetime of the fd or @handle.
  748. * In contrast, %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE allocates iso resources
  749. * for the duration of a bus generation.
  750. *
  751. * @channels is a host-endian bitfield with the least significant bit
  752. * representing channel 0 and the most significant bit representing channel 63:
  753. * 1ULL << c for each channel c that is a candidate for (de)allocation.
  754. *
  755. * @bandwidth is expressed in bandwidth allocation units, i.e. the time to send
  756. * one quadlet of data (payload or header data) at speed S1600.
  757. */
  758. struct fw_cdev_allocate_iso_resource {
  759. __u64 closure;
  760. __u64 channels;
  761. __u32 bandwidth;
  762. __u32 handle;
  763. };
  764. /**
  765. * struct fw_cdev_send_stream_packet - send an asynchronous stream packet
  766. * @length: Length of outgoing payload, in bytes
  767. * @tag: Data format tag
  768. * @channel: Isochronous channel to transmit to
  769. * @sy: Synchronization code
  770. * @closure: Passed back to userspace in the response event
  771. * @data: Userspace pointer to payload
  772. * @generation: The bus generation where packet is valid
  773. * @speed: Speed to transmit at
  774. *
  775. * The %FW_CDEV_IOC_SEND_STREAM_PACKET ioctl sends an asynchronous stream packet
  776. * to every device which is listening to the specified channel. The kernel
  777. * writes an &fw_cdev_event_response event which indicates success or failure of
  778. * the transmission.
  779. */
  780. struct fw_cdev_send_stream_packet {
  781. __u32 length;
  782. __u32 tag;
  783. __u32 channel;
  784. __u32 sy;
  785. __u64 closure;
  786. __u64 data;
  787. __u32 generation;
  788. __u32 speed;
  789. };
  790. /**
  791. * struct fw_cdev_send_phy_packet - send a PHY packet
  792. * @closure: Passed back to userspace in the PHY-packet-sent event
  793. * @data: First and second quadlet of the PHY packet
  794. * @generation: The bus generation where packet is valid
  795. *
  796. * The %FW_CDEV_IOC_SEND_PHY_PACKET ioctl sends a PHY packet to all nodes
  797. * on the same card as this device. After transmission, an
  798. * %FW_CDEV_EVENT_PHY_PACKET_SENT event is generated.
  799. *
  800. * The payload @data[] shall be specified in host byte order. Usually,
  801. * @data[1] needs to be the bitwise inverse of @data[0]. VersaPHY packets
  802. * are an exception to this rule.
  803. *
  804. * The ioctl is only permitted on device files which represent a local node.
  805. */
  806. struct fw_cdev_send_phy_packet {
  807. __u64 closure;
  808. __u32 data[2];
  809. __u32 generation;
  810. };
  811. #endif /* _LINUX_FIREWIRE_CDEV_H */