File Index
Files and directories
Sign in
FILE

thunderbolt.h

File preview with syntax highlighting.

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