Commit | Line | Data |
---|---|---|
cdae7c07 MW |
1 | /* |
2 | * Thunderbolt service API | |
3 | * | |
eaf8ff35 | 4 | * Copyright (C) 2014 Andreas Noever <andreas.noever@gmail.com> |
cdae7c07 MW |
5 | * Copyright (C) 2017, Intel Corporation |
6 | * Authors: Michael Jamet <michael.jamet@intel.com> | |
7 | * Mika Westerberg <mika.westerberg@linux.intel.com> | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License version 2 as | |
11 | * published by the Free Software Foundation. | |
12 | */ | |
13 | ||
14 | #ifndef THUNDERBOLT_H_ | |
15 | #define THUNDERBOLT_H_ | |
16 | ||
9e99b9f4 | 17 | #include <linux/device.h> |
3b3d9f4d | 18 | #include <linux/idr.h> |
cdae7c07 | 19 | #include <linux/list.h> |
9e99b9f4 | 20 | #include <linux/mutex.h> |
d1ff7024 | 21 | #include <linux/mod_devicetable.h> |
cdae7c07 | 22 | #include <linux/uuid.h> |
3b3d9f4d | 23 | #include <linux/workqueue.h> |
cdae7c07 | 24 | |
eaf8ff35 MW |
25 | enum tb_cfg_pkg_type { |
26 | TB_CFG_PKG_READ = 1, | |
27 | TB_CFG_PKG_WRITE = 2, | |
28 | TB_CFG_PKG_ERROR = 3, | |
29 | TB_CFG_PKG_NOTIFY_ACK = 4, | |
30 | TB_CFG_PKG_EVENT = 5, | |
31 | TB_CFG_PKG_XDOMAIN_REQ = 6, | |
32 | TB_CFG_PKG_XDOMAIN_RESP = 7, | |
33 | TB_CFG_PKG_OVERRIDE = 8, | |
34 | TB_CFG_PKG_RESET = 9, | |
35 | TB_CFG_PKG_ICM_EVENT = 10, | |
36 | TB_CFG_PKG_ICM_CMD = 11, | |
37 | TB_CFG_PKG_ICM_RESP = 12, | |
38 | TB_CFG_PKG_PREPARE_TO_SLEEP = 13, | |
39 | }; | |
40 | ||
9e99b9f4 MW |
41 | /** |
42 | * enum tb_security_level - Thunderbolt security level | |
43 | * @TB_SECURITY_NONE: No security, legacy mode | |
44 | * @TB_SECURITY_USER: User approval required at minimum | |
45 | * @TB_SECURITY_SECURE: One time saved key required at minimum | |
46 | * @TB_SECURITY_DPONLY: Only tunnel Display port (and USB) | |
47 | */ | |
48 | enum tb_security_level { | |
49 | TB_SECURITY_NONE, | |
50 | TB_SECURITY_USER, | |
51 | TB_SECURITY_SECURE, | |
52 | TB_SECURITY_DPONLY, | |
53 | }; | |
54 | ||
55 | /** | |
56 | * struct tb - main thunderbolt bus structure | |
57 | * @dev: Domain device | |
58 | * @lock: Big lock. Must be held when accessing any struct | |
59 | * tb_switch / struct tb_port. | |
60 | * @nhi: Pointer to the NHI structure | |
61 | * @ctl: Control channel for this domain | |
62 | * @wq: Ordered workqueue for all domain specific work | |
63 | * @root_switch: Root switch of this domain | |
64 | * @cm_ops: Connection manager specific operations vector | |
65 | * @index: Linux assigned domain number | |
66 | * @security_level: Current security level | |
67 | * @privdata: Private connection manager specific data | |
68 | */ | |
69 | struct tb { | |
70 | struct device dev; | |
71 | struct mutex lock; | |
72 | struct tb_nhi *nhi; | |
73 | struct tb_ctl *ctl; | |
74 | struct workqueue_struct *wq; | |
75 | struct tb_switch *root_switch; | |
76 | const struct tb_cm_ops *cm_ops; | |
77 | int index; | |
78 | enum tb_security_level security_level; | |
79 | unsigned long privdata[0]; | |
80 | }; | |
81 | ||
82 | extern struct bus_type tb_bus_type; | |
d1ff7024 MW |
83 | extern struct device_type tb_service_type; |
84 | extern struct device_type tb_xdomain_type; | |
9e99b9f4 | 85 | |
e69b71f8 MW |
86 | #define TB_LINKS_PER_PHY_PORT 2 |
87 | ||
88 | static inline unsigned int tb_phy_port_from_link(unsigned int link) | |
89 | { | |
90 | return (link - 1) / TB_LINKS_PER_PHY_PORT; | |
91 | } | |
92 | ||
cdae7c07 MW |
93 | /** |
94 | * struct tb_property_dir - XDomain property directory | |
95 | * @uuid: Directory UUID or %NULL if root directory | |
96 | * @properties: List of properties in this directory | |
97 | * | |
98 | * User needs to provide serialization if needed. | |
99 | */ | |
100 | struct tb_property_dir { | |
101 | const uuid_t *uuid; | |
102 | struct list_head properties; | |
103 | }; | |
104 | ||
105 | enum tb_property_type { | |
106 | TB_PROPERTY_TYPE_UNKNOWN = 0x00, | |
107 | TB_PROPERTY_TYPE_DIRECTORY = 0x44, | |
108 | TB_PROPERTY_TYPE_DATA = 0x64, | |
109 | TB_PROPERTY_TYPE_TEXT = 0x74, | |
110 | TB_PROPERTY_TYPE_VALUE = 0x76, | |
111 | }; | |
112 | ||
113 | #define TB_PROPERTY_KEY_SIZE 8 | |
114 | ||
115 | /** | |
116 | * struct tb_property - XDomain property | |
117 | * @list: Used to link properties together in a directory | |
118 | * @key: Key for the property (always terminated). | |
119 | * @type: Type of the property | |
120 | * @length: Length of the property data in dwords | |
121 | * @value: Property value | |
122 | * | |
123 | * Users use @type to determine which field in @value is filled. | |
124 | */ | |
125 | struct tb_property { | |
126 | struct list_head list; | |
127 | char key[TB_PROPERTY_KEY_SIZE + 1]; | |
128 | enum tb_property_type type; | |
129 | size_t length; | |
130 | union { | |
131 | struct tb_property_dir *dir; | |
132 | u8 *data; | |
133 | char *text; | |
134 | u32 immediate; | |
135 | } value; | |
136 | }; | |
137 | ||
138 | struct tb_property_dir *tb_property_parse_dir(const u32 *block, | |
139 | size_t block_len); | |
140 | ssize_t tb_property_format_dir(const struct tb_property_dir *dir, u32 *block, | |
141 | size_t block_len); | |
142 | struct tb_property_dir *tb_property_create_dir(const uuid_t *uuid); | |
143 | void tb_property_free_dir(struct tb_property_dir *dir); | |
144 | int tb_property_add_immediate(struct tb_property_dir *parent, const char *key, | |
145 | u32 value); | |
146 | int tb_property_add_data(struct tb_property_dir *parent, const char *key, | |
147 | const void *buf, size_t buflen); | |
148 | int tb_property_add_text(struct tb_property_dir *parent, const char *key, | |
149 | const char *text); | |
150 | int tb_property_add_dir(struct tb_property_dir *parent, const char *key, | |
151 | struct tb_property_dir *dir); | |
152 | void tb_property_remove(struct tb_property *tb_property); | |
153 | struct tb_property *tb_property_find(struct tb_property_dir *dir, | |
154 | const char *key, enum tb_property_type type); | |
155 | struct tb_property *tb_property_get_next(struct tb_property_dir *dir, | |
156 | struct tb_property *prev); | |
157 | ||
158 | #define tb_property_for_each(dir, property) \ | |
159 | for (property = tb_property_get_next(dir, NULL); \ | |
160 | property; \ | |
161 | property = tb_property_get_next(dir, property)) | |
162 | ||
d1ff7024 MW |
163 | int tb_register_property_dir(const char *key, struct tb_property_dir *dir); |
164 | void tb_unregister_property_dir(const char *key, struct tb_property_dir *dir); | |
165 | ||
166 | /** | |
167 | * struct tb_xdomain - Cross-domain (XDomain) connection | |
168 | * @dev: XDomain device | |
169 | * @tb: Pointer to the domain | |
170 | * @remote_uuid: UUID of the remote domain (host) | |
171 | * @local_uuid: Cached local UUID | |
172 | * @route: Route string the other domain can be reached | |
173 | * @vendor: Vendor ID of the remote domain | |
174 | * @device: Device ID of the demote domain | |
175 | * @lock: Lock to serialize access to the following fields of this structure | |
176 | * @vendor_name: Name of the vendor (or %NULL if not known) | |
177 | * @device_name: Name of the device (or %NULL if not known) | |
178 | * @is_unplugged: The XDomain is unplugged | |
179 | * @resume: The XDomain is being resumed | |
180 | * @transmit_path: HopID which the remote end expects us to transmit | |
181 | * @transmit_ring: Local ring (hop) where outgoing packets are pushed | |
182 | * @receive_path: HopID which we expect the remote end to transmit | |
183 | * @receive_ring: Local ring (hop) where incoming packets arrive | |
184 | * @service_ids: Used to generate IDs for the services | |
185 | * @properties: Properties exported by the remote domain | |
186 | * @property_block_gen: Generation of @properties | |
187 | * @properties_lock: Lock protecting @properties. | |
188 | * @get_properties_work: Work used to get remote domain properties | |
189 | * @properties_retries: Number of times left to read properties | |
190 | * @properties_changed_work: Work used to notify the remote domain that | |
191 | * our properties have changed | |
192 | * @properties_changed_retries: Number of times left to send properties | |
193 | * changed notification | |
194 | * @link: Root switch link the remote domain is connected (ICM only) | |
195 | * @depth: Depth in the chain the remote domain is connected (ICM only) | |
196 | * | |
197 | * This structure represents connection across two domains (hosts). | |
198 | * Each XDomain contains zero or more services which are exposed as | |
199 | * &struct tb_service objects. | |
200 | * | |
201 | * Service drivers may access this structure if they need to enumerate | |
202 | * non-standard properties but they need hold @lock when doing so | |
203 | * because properties can be changed asynchronously in response to | |
204 | * changes in the remote domain. | |
205 | */ | |
206 | struct tb_xdomain { | |
207 | struct device dev; | |
208 | struct tb *tb; | |
209 | uuid_t *remote_uuid; | |
210 | const uuid_t *local_uuid; | |
211 | u64 route; | |
212 | u16 vendor; | |
213 | u16 device; | |
214 | struct mutex lock; | |
215 | const char *vendor_name; | |
216 | const char *device_name; | |
217 | bool is_unplugged; | |
218 | bool resume; | |
219 | u16 transmit_path; | |
220 | u16 transmit_ring; | |
221 | u16 receive_path; | |
222 | u16 receive_ring; | |
223 | struct ida service_ids; | |
224 | struct tb_property_dir *properties; | |
225 | u32 property_block_gen; | |
226 | struct delayed_work get_properties_work; | |
227 | int properties_retries; | |
228 | struct delayed_work properties_changed_work; | |
229 | int properties_changed_retries; | |
230 | u8 link; | |
231 | u8 depth; | |
232 | }; | |
233 | ||
234 | int tb_xdomain_enable_paths(struct tb_xdomain *xd, u16 transmit_path, | |
235 | u16 transmit_ring, u16 receive_path, | |
236 | u16 receive_ring); | |
237 | int tb_xdomain_disable_paths(struct tb_xdomain *xd); | |
238 | struct tb_xdomain *tb_xdomain_find_by_uuid(struct tb *tb, const uuid_t *uuid); | |
239 | ||
240 | static inline struct tb_xdomain * | |
241 | tb_xdomain_find_by_uuid_locked(struct tb *tb, const uuid_t *uuid) | |
242 | { | |
243 | struct tb_xdomain *xd; | |
244 | ||
245 | mutex_lock(&tb->lock); | |
246 | xd = tb_xdomain_find_by_uuid(tb, uuid); | |
247 | mutex_unlock(&tb->lock); | |
248 | ||
249 | return xd; | |
250 | } | |
251 | ||
252 | static inline struct tb_xdomain *tb_xdomain_get(struct tb_xdomain *xd) | |
253 | { | |
254 | if (xd) | |
255 | get_device(&xd->dev); | |
256 | return xd; | |
257 | } | |
258 | ||
259 | static inline void tb_xdomain_put(struct tb_xdomain *xd) | |
260 | { | |
261 | if (xd) | |
262 | put_device(&xd->dev); | |
263 | } | |
264 | ||
265 | static inline bool tb_is_xdomain(const struct device *dev) | |
266 | { | |
267 | return dev->type == &tb_xdomain_type; | |
268 | } | |
269 | ||
270 | static inline struct tb_xdomain *tb_to_xdomain(struct device *dev) | |
271 | { | |
272 | if (tb_is_xdomain(dev)) | |
273 | return container_of(dev, struct tb_xdomain, dev); | |
274 | return NULL; | |
275 | } | |
276 | ||
277 | int tb_xdomain_response(struct tb_xdomain *xd, const void *response, | |
278 | size_t size, enum tb_cfg_pkg_type type); | |
279 | int tb_xdomain_request(struct tb_xdomain *xd, const void *request, | |
280 | size_t request_size, enum tb_cfg_pkg_type request_type, | |
281 | void *response, size_t response_size, | |
282 | enum tb_cfg_pkg_type response_type, | |
283 | unsigned int timeout_msec); | |
284 | ||
285 | /** | |
286 | * tb_protocol_handler - Protocol specific handler | |
287 | * @uuid: XDomain messages with this UUID are dispatched to this handler | |
288 | * @callback: Callback called with the XDomain message. Returning %1 | |
289 | * here tells the XDomain core that the message was handled | |
290 | * by this handler and should not be forwared to other | |
291 | * handlers. | |
292 | * @data: Data passed with the callback | |
293 | * @list: Handlers are linked using this | |
294 | * | |
295 | * Thunderbolt services can hook into incoming XDomain requests by | |
296 | * registering protocol handler. Only limitation is that the XDomain | |
297 | * discovery protocol UUID cannot be registered since it is handled by | |
298 | * the core XDomain code. | |
299 | * | |
300 | * The @callback must check that the message is really directed to the | |
301 | * service the driver implements. | |
302 | */ | |
303 | struct tb_protocol_handler { | |
304 | const uuid_t *uuid; | |
305 | int (*callback)(const void *buf, size_t size, void *data); | |
306 | void *data; | |
307 | struct list_head list; | |
308 | }; | |
309 | ||
310 | int tb_register_protocol_handler(struct tb_protocol_handler *handler); | |
311 | void tb_unregister_protocol_handler(struct tb_protocol_handler *handler); | |
312 | ||
313 | /** | |
314 | * struct tb_service - Thunderbolt service | |
315 | * @dev: XDomain device | |
316 | * @id: ID of the service (shown in sysfs) | |
317 | * @key: Protocol key from the properties directory | |
318 | * @prtcid: Protocol ID from the properties directory | |
319 | * @prtcvers: Protocol version from the properties directory | |
320 | * @prtcrevs: Protocol software revision from the properties directory | |
321 | * @prtcstns: Protocol settings mask from the properties directory | |
322 | * | |
323 | * Each domain exposes set of services it supports as collection of | |
324 | * properties. For each service there will be one corresponding | |
325 | * &struct tb_service. Service drivers are bound to these. | |
326 | */ | |
327 | struct tb_service { | |
328 | struct device dev; | |
329 | int id; | |
330 | const char *key; | |
331 | u32 prtcid; | |
332 | u32 prtcvers; | |
333 | u32 prtcrevs; | |
334 | u32 prtcstns; | |
335 | }; | |
336 | ||
337 | static inline struct tb_service *tb_service_get(struct tb_service *svc) | |
338 | { | |
339 | if (svc) | |
340 | get_device(&svc->dev); | |
341 | return svc; | |
342 | } | |
343 | ||
344 | static inline void tb_service_put(struct tb_service *svc) | |
345 | { | |
346 | if (svc) | |
347 | put_device(&svc->dev); | |
348 | } | |
349 | ||
350 | static inline bool tb_is_service(const struct device *dev) | |
351 | { | |
352 | return dev->type == &tb_service_type; | |
353 | } | |
354 | ||
355 | static inline struct tb_service *tb_to_service(struct device *dev) | |
356 | { | |
357 | if (tb_is_service(dev)) | |
358 | return container_of(dev, struct tb_service, dev); | |
359 | return NULL; | |
360 | } | |
361 | ||
362 | /** | |
363 | * tb_service_driver - Thunderbolt service driver | |
364 | * @driver: Driver structure | |
365 | * @probe: Called when the driver is probed | |
366 | * @remove: Called when the driver is removed (optional) | |
367 | * @shutdown: Called at shutdown time to stop the service (optional) | |
368 | * @id_table: Table of service identifiers the driver supports | |
369 | */ | |
370 | struct tb_service_driver { | |
371 | struct device_driver driver; | |
372 | int (*probe)(struct tb_service *svc, const struct tb_service_id *id); | |
373 | void (*remove)(struct tb_service *svc); | |
374 | void (*shutdown)(struct tb_service *svc); | |
375 | const struct tb_service_id *id_table; | |
376 | }; | |
377 | ||
378 | #define TB_SERVICE(key, id) \ | |
379 | .match_flags = TBSVC_MATCH_PROTOCOL_KEY | \ | |
380 | TBSVC_MATCH_PROTOCOL_ID, \ | |
381 | .protocol_key = (key), \ | |
382 | .protocol_id = (id) | |
383 | ||
384 | int tb_register_service_driver(struct tb_service_driver *drv); | |
385 | void tb_unregister_service_driver(struct tb_service_driver *drv); | |
386 | ||
387 | static inline void *tb_service_get_drvdata(const struct tb_service *svc) | |
388 | { | |
389 | return dev_get_drvdata(&svc->dev); | |
390 | } | |
391 | ||
392 | static inline void tb_service_set_drvdata(struct tb_service *svc, void *data) | |
393 | { | |
394 | dev_set_drvdata(&svc->dev, data); | |
395 | } | |
396 | ||
397 | static inline struct tb_xdomain *tb_service_parent(struct tb_service *svc) | |
398 | { | |
399 | return tb_to_xdomain(svc->dev.parent); | |
400 | } | |
401 | ||
3b3d9f4d MW |
402 | /** |
403 | * struct tb_nhi - thunderbolt native host interface | |
404 | * @lock: Must be held during ring creation/destruction. Is acquired by | |
405 | * interrupt_work when dispatching interrupts to individual rings. | |
406 | * @pdev: Pointer to the PCI device | |
407 | * @iobase: MMIO space of the NHI | |
408 | * @tx_rings: All Tx rings available on this host controller | |
409 | * @rx_rings: All Rx rings available on this host controller | |
410 | * @msix_ida: Used to allocate MSI-X vectors for rings | |
411 | * @going_away: The host controller device is about to disappear so when | |
412 | * this flag is set, avoid touching the hardware anymore. | |
413 | * @interrupt_work: Work scheduled to handle ring interrupt when no | |
414 | * MSI-X is used. | |
415 | * @hop_count: Number of rings (end point hops) supported by NHI. | |
416 | */ | |
417 | struct tb_nhi { | |
59120e06 | 418 | spinlock_t lock; |
3b3d9f4d MW |
419 | struct pci_dev *pdev; |
420 | void __iomem *iobase; | |
421 | struct tb_ring **tx_rings; | |
422 | struct tb_ring **rx_rings; | |
423 | struct ida msix_ida; | |
424 | bool going_away; | |
425 | struct work_struct interrupt_work; | |
426 | u32 hop_count; | |
427 | }; | |
428 | ||
429 | /** | |
430 | * struct tb_ring - thunderbolt TX or RX ring associated with a NHI | |
431 | * @lock: Lock serializing actions to this ring. Must be acquired after | |
432 | * nhi->lock. | |
433 | * @nhi: Pointer to the native host controller interface | |
434 | * @size: Size of the ring | |
435 | * @hop: Hop (DMA channel) associated with this ring | |
436 | * @head: Head of the ring (write next descriptor here) | |
437 | * @tail: Tail of the ring (complete next descriptor here) | |
438 | * @descriptors: Allocated descriptors for this ring | |
439 | * @queue: Queue holding frames to be transferred over this ring | |
440 | * @in_flight: Queue holding frames that are currently in flight | |
441 | * @work: Interrupt work structure | |
442 | * @is_tx: Is the ring Tx or Rx | |
443 | * @running: Is the ring running | |
444 | * @irq: MSI-X irq number if the ring uses MSI-X. %0 otherwise. | |
445 | * @vector: MSI-X vector number the ring uses (only set if @irq is > 0) | |
446 | * @flags: Ring specific flags | |
447 | * @sof_mask: Bit mask used to detect start of frame PDF | |
448 | * @eof_mask: Bit mask used to detect end of frame PDF | |
449 | */ | |
450 | struct tb_ring { | |
22b7de10 | 451 | spinlock_t lock; |
3b3d9f4d MW |
452 | struct tb_nhi *nhi; |
453 | int size; | |
454 | int hop; | |
455 | int head; | |
456 | int tail; | |
457 | struct ring_desc *descriptors; | |
458 | dma_addr_t descriptors_dma; | |
459 | struct list_head queue; | |
460 | struct list_head in_flight; | |
461 | struct work_struct work; | |
462 | bool is_tx:1; | |
463 | bool running:1; | |
464 | int irq; | |
465 | u8 vector; | |
466 | unsigned int flags; | |
467 | u16 sof_mask; | |
468 | u16 eof_mask; | |
469 | }; | |
470 | ||
471 | /* Leave ring interrupt enabled on suspend */ | |
472 | #define RING_FLAG_NO_SUSPEND BIT(0) | |
473 | /* Configure the ring to be in frame mode */ | |
474 | #define RING_FLAG_FRAME BIT(1) | |
475 | /* Enable end-to-end flow control */ | |
476 | #define RING_FLAG_E2E BIT(2) | |
477 | ||
478 | struct ring_frame; | |
479 | typedef void (*ring_cb)(struct tb_ring *, struct ring_frame *, bool canceled); | |
480 | ||
2a91ec63 MW |
481 | /** |
482 | * enum ring_desc_flags - Flags for DMA ring descriptor | |
483 | * %RING_DESC_ISOCH: Enable isonchronous DMA (Tx only) | |
484 | * %RING_DESC_CRC_ERROR: In frame mode CRC check failed for the frame (Rx only) | |
485 | * %RING_DESC_COMPLETED: Descriptor completed (set by NHI) | |
486 | * %RING_DESC_POSTED: Always set this | |
487 | * %RING_DESC_BUFFER_OVERRUN: RX buffer overrun | |
488 | * %RING_DESC_INTERRUPT: Request an interrupt on completion | |
489 | */ | |
490 | enum ring_desc_flags { | |
491 | RING_DESC_ISOCH = 0x1, | |
492 | RING_DESC_CRC_ERROR = 0x1, | |
493 | RING_DESC_COMPLETED = 0x2, | |
494 | RING_DESC_POSTED = 0x4, | |
495 | RING_DESC_BUFFER_OVERRUN = 0x04, | |
496 | RING_DESC_INTERRUPT = 0x8, | |
497 | }; | |
498 | ||
3b3d9f4d MW |
499 | /** |
500 | * struct ring_frame - For use with ring_rx/ring_tx | |
501 | * @buffer_phy: DMA mapped address of the frame | |
502 | * @callback: Callback called when the frame is finished | |
503 | * @list: Frame is linked to a queue using this | |
504 | * @size: Size of the frame in bytes (%0 means %4096) | |
505 | * @flags: Flags for the frame (see &enum ring_desc_flags) | |
506 | * @eof: End of frame protocol defined field | |
507 | * @sof: Start of frame protocol defined field | |
508 | */ | |
509 | struct ring_frame { | |
510 | dma_addr_t buffer_phy; | |
511 | ring_cb callback; | |
512 | struct list_head list; | |
513 | u32 size:12; | |
514 | u32 flags:12; | |
515 | u32 eof:4; | |
516 | u32 sof:4; | |
517 | }; | |
518 | ||
519 | /* Minimum size for ring_rx */ | |
520 | #define TB_FRAME_SIZE 0x100 | |
521 | ||
522 | struct tb_ring *tb_ring_alloc_tx(struct tb_nhi *nhi, int hop, int size, | |
523 | unsigned int flags); | |
524 | struct tb_ring *tb_ring_alloc_rx(struct tb_nhi *nhi, int hop, int size, | |
525 | unsigned int flags, u16 sof_mask, | |
526 | u16 eof_mask); | |
527 | void tb_ring_start(struct tb_ring *ring); | |
528 | void tb_ring_stop(struct tb_ring *ring); | |
529 | void tb_ring_free(struct tb_ring *ring); | |
530 | ||
531 | int __tb_ring_enqueue(struct tb_ring *ring, struct ring_frame *frame); | |
532 | ||
533 | /** | |
534 | * tb_ring_rx() - enqueue a frame on an RX ring | |
535 | * @ring: Ring to enqueue the frame | |
536 | * @frame: Frame to enqueue | |
537 | * | |
538 | * @frame->buffer, @frame->buffer_phy and @frame->callback have to be set. The | |
539 | * buffer must contain at least %TB_FRAME_SIZE bytes. | |
540 | * | |
541 | * @frame->callback will be invoked with @frame->size, @frame->flags, | |
542 | * @frame->eof, @frame->sof set once the frame has been received. | |
543 | * | |
544 | * If ring_stop() is called after the packet has been enqueued | |
545 | * @frame->callback will be called with canceled set to true. | |
546 | * | |
547 | * Return: Returns %-ESHUTDOWN if ring_stop has been called. Zero otherwise. | |
548 | */ | |
549 | static inline int tb_ring_rx(struct tb_ring *ring, struct ring_frame *frame) | |
550 | { | |
551 | WARN_ON(ring->is_tx); | |
552 | return __tb_ring_enqueue(ring, frame); | |
553 | } | |
554 | ||
555 | /** | |
556 | * tb_ring_tx() - enqueue a frame on an TX ring | |
557 | * @ring: Ring the enqueue the frame | |
558 | * @frame: Frame to enqueue | |
559 | * | |
560 | * @frame->buffer, @frame->buffer_phy, @frame->callback, @frame->size, | |
561 | * @frame->eof and @frame->sof have to be set. | |
562 | * | |
563 | * @frame->callback will be invoked with once the frame has been transmitted. | |
564 | * | |
565 | * If ring_stop() is called after the packet has been enqueued @frame->callback | |
566 | * will be called with canceled set to true. | |
567 | * | |
568 | * Return: Returns %-ESHUTDOWN if ring_stop has been called. Zero otherwise. | |
569 | */ | |
570 | static inline int tb_ring_tx(struct tb_ring *ring, struct ring_frame *frame) | |
571 | { | |
572 | WARN_ON(!ring->is_tx); | |
573 | return __tb_ring_enqueue(ring, frame); | |
574 | } | |
575 | ||
cdae7c07 | 576 | #endif /* THUNDERBOLT_H_ */ |