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