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_copy_dir(const struct tb_property_dir *dir); 150 struct tb_property_dir *tb_property_create_dir(const uuid_t *uuid); 151 void tb_property_free_dir(struct tb_property_dir *dir); 152 int tb_property_add_immediate(struct tb_property_dir *parent, const char *key, 153 u32 value); 154 int tb_property_add_data(struct tb_property_dir *parent, const char *key, 155 const void *buf, size_t buflen); 156 int tb_property_add_text(struct tb_property_dir *parent, const char *key, 157 const char *text); 158 int tb_property_add_dir(struct tb_property_dir *parent, const char *key, 159 struct tb_property_dir *dir); 160 void tb_property_remove(struct tb_property *tb_property); 161 struct tb_property *tb_property_find(struct tb_property_dir *dir, 162 const char *key, enum tb_property_type type); 163 struct tb_property *tb_property_get_next(struct tb_property_dir *dir, 164 struct tb_property *prev); 165 166 #define tb_property_for_each(dir, property) \ 167 for (property = tb_property_get_next(dir, NULL); \ 168 property; \ 169 property = tb_property_get_next(dir, property)) 170 171 int tb_register_property_dir(const char *key, struct tb_property_dir *dir); 172 void tb_unregister_property_dir(const char *key, struct tb_property_dir *dir); 173 174 /** 175 * struct tb_xdomain - Cross-domain (XDomain) connection 176 * @dev: XDomain device 177 * @tb: Pointer to the domain 178 * @remote_uuid: UUID of the remote domain (host) 179 * @local_uuid: Cached local UUID 180 * @route: Route string the other domain can be reached 181 * @vendor: Vendor ID of the remote domain 182 * @device: Device ID of the demote domain 183 * @local_max_hopid: Maximum input HopID of this host 184 * @remote_max_hopid: Maximum input HopID of the remote host 185 * @lock: Lock to serialize access to the following fields of this structure 186 * @vendor_name: Name of the vendor (or %NULL if not known) 187 * @device_name: Name of the device (or %NULL if not known) 188 * @link_speed: Speed of the link in Gb/s 189 * @link_width: Width of the link (1 or 2) 190 * @is_unplugged: The XDomain is unplugged 191 * @needs_uuid: If the XDomain does not have @remote_uuid it will be 192 * queried first 193 * @transmit_path: HopID which the remote end expects us to transmit 194 * @transmit_ring: Local ring (hop) where outgoing packets are pushed 195 * @receive_path: HopID which we expect the remote end to transmit 196 * @receive_ring: Local ring (hop) where incoming packets arrive 197 * @service_ids: Used to generate IDs for the services 198 * @local_property_block: Local block of properties 199 * @local_property_block_gen: Generation of @local_property_block 200 * @local_property_block_len: Length of the @local_property_block in dwords 201 * @remote_properties: Properties exported by the remote domain 202 * @remote_property_block_gen: Generation of @remote_properties 203 * @get_uuid_work: Work used to retrieve @remote_uuid 204 * @uuid_retries: Number of times left @remote_uuid is requested before 205 * giving up 206 * @get_properties_work: Work used to get remote domain properties 207 * @properties_retries: Number of times left to read properties 208 * @properties_changed_work: Work used to notify the remote domain that 209 * our properties have changed 210 * @properties_changed_retries: Number of times left to send properties 211 * changed notification 212 * @link: Root switch link the remote domain is connected (ICM only) 213 * @depth: Depth in the chain the remote domain is connected (ICM only) 214 * 215 * This structure represents connection across two domains (hosts). 216 * Each XDomain contains zero or more services which are exposed as 217 * &struct tb_service objects. 218 * 219 * Service drivers may access this structure if they need to enumerate 220 * non-standard properties but they need hold @lock when doing so 221 * because properties can be changed asynchronously in response to 222 * changes in the remote domain. 223 */ 224 struct tb_xdomain { 225 struct device dev; 226 struct tb *tb; 227 uuid_t *remote_uuid; 228 const uuid_t *local_uuid; 229 u64 route; 230 u16 vendor; 231 u16 device; 232 unsigned int local_max_hopid; 233 unsigned int remote_max_hopid; 234 struct mutex lock; 235 const char *vendor_name; 236 const char *device_name; 237 unsigned int link_speed; 238 unsigned int link_width; 239 bool is_unplugged; 240 bool needs_uuid; 241 u16 transmit_path; 242 u16 transmit_ring; 243 u16 receive_path; 244 u16 receive_ring; 245 struct ida service_ids; 246 u32 *local_property_block; 247 u32 local_property_block_gen; 248 u32 local_property_block_len; 249 struct tb_property_dir *remote_properties; 250 u32 remote_property_block_gen; 251 struct delayed_work get_uuid_work; 252 int uuid_retries; 253 struct delayed_work get_properties_work; 254 int properties_retries; 255 struct delayed_work properties_changed_work; 256 int properties_changed_retries; 257 u8 link; 258 u8 depth; 259 }; 260 261 int tb_xdomain_lane_bonding_enable(struct tb_xdomain *xd); 262 void tb_xdomain_lane_bonding_disable(struct tb_xdomain *xd); 263 int tb_xdomain_enable_paths(struct tb_xdomain *xd, u16 transmit_path, 264 u16 transmit_ring, u16 receive_path, 265 u16 receive_ring); 266 int tb_xdomain_disable_paths(struct tb_xdomain *xd); 267 struct tb_xdomain *tb_xdomain_find_by_uuid(struct tb *tb, const uuid_t *uuid); 268 struct tb_xdomain *tb_xdomain_find_by_route(struct tb *tb, u64 route); 269 270 static inline struct tb_xdomain * 271 tb_xdomain_find_by_uuid_locked(struct tb *tb, const uuid_t *uuid) 272 { 273 struct tb_xdomain *xd; 274 275 mutex_lock(&tb->lock); 276 xd = tb_xdomain_find_by_uuid(tb, uuid); 277 mutex_unlock(&tb->lock); 278 279 return xd; 280 } 281 282 static inline struct tb_xdomain * 283 tb_xdomain_find_by_route_locked(struct tb *tb, u64 route) 284 { 285 struct tb_xdomain *xd; 286 287 mutex_lock(&tb->lock); 288 xd = tb_xdomain_find_by_route(tb, route); 289 mutex_unlock(&tb->lock); 290 291 return xd; 292 } 293 294 static inline struct tb_xdomain *tb_xdomain_get(struct tb_xdomain *xd) 295 { 296 if (xd) 297 get_device(&xd->dev); 298 return xd; 299 } 300 301 static inline void tb_xdomain_put(struct tb_xdomain *xd) 302 { 303 if (xd) 304 put_device(&xd->dev); 305 } 306 307 static inline bool tb_is_xdomain(const struct device *dev) 308 { 309 return dev->type == &tb_xdomain_type; 310 } 311 312 static inline struct tb_xdomain *tb_to_xdomain(struct device *dev) 313 { 314 if (tb_is_xdomain(dev)) 315 return container_of(dev, struct tb_xdomain, dev); 316 return NULL; 317 } 318 319 int tb_xdomain_response(struct tb_xdomain *xd, const void *response, 320 size_t size, enum tb_cfg_pkg_type type); 321 int tb_xdomain_request(struct tb_xdomain *xd, const void *request, 322 size_t request_size, enum tb_cfg_pkg_type request_type, 323 void *response, size_t response_size, 324 enum tb_cfg_pkg_type response_type, 325 unsigned int timeout_msec); 326 327 /** 328 * tb_protocol_handler - Protocol specific handler 329 * @uuid: XDomain messages with this UUID are dispatched to this handler 330 * @callback: Callback called with the XDomain message. Returning %1 331 * here tells the XDomain core that the message was handled 332 * by this handler and should not be forwared to other 333 * handlers. 334 * @data: Data passed with the callback 335 * @list: Handlers are linked using this 336 * 337 * Thunderbolt services can hook into incoming XDomain requests by 338 * registering protocol handler. Only limitation is that the XDomain 339 * discovery protocol UUID cannot be registered since it is handled by 340 * the core XDomain code. 341 * 342 * The @callback must check that the message is really directed to the 343 * service the driver implements. 344 */ 345 struct tb_protocol_handler { 346 const uuid_t *uuid; 347 int (*callback)(const void *buf, size_t size, void *data); 348 void *data; 349 struct list_head list; 350 }; 351 352 int tb_register_protocol_handler(struct tb_protocol_handler *handler); 353 void tb_unregister_protocol_handler(struct tb_protocol_handler *handler); 354 355 /** 356 * struct tb_service - Thunderbolt service 357 * @dev: XDomain device 358 * @id: ID of the service (shown in sysfs) 359 * @key: Protocol key from the properties directory 360 * @prtcid: Protocol ID from the properties directory 361 * @prtcvers: Protocol version from the properties directory 362 * @prtcrevs: Protocol software revision from the properties directory 363 * @prtcstns: Protocol settings mask from the properties directory 364 * @debugfs_dir: Pointer to the service debugfs directory. Always created 365 * when debugfs is enabled. Can be used by service drivers to 366 * add their own entries under the service. 367 * 368 * Each domain exposes set of services it supports as collection of 369 * properties. For each service there will be one corresponding 370 * &struct tb_service. Service drivers are bound to these. 371 */ 372 struct tb_service { 373 struct device dev; 374 int id; 375 const char *key; 376 u32 prtcid; 377 u32 prtcvers; 378 u32 prtcrevs; 379 u32 prtcstns; 380 struct dentry *debugfs_dir; 381 }; 382 383 static inline struct tb_service *tb_service_get(struct tb_service *svc) 384 { 385 if (svc) 386 get_device(&svc->dev); 387 return svc; 388 } 389 390 static inline void tb_service_put(struct tb_service *svc) 391 { 392 if (svc) 393 put_device(&svc->dev); 394 } 395 396 static inline bool tb_is_service(const struct device *dev) 397 { 398 return dev->type == &tb_service_type; 399 } 400 401 static inline struct tb_service *tb_to_service(struct device *dev) 402 { 403 if (tb_is_service(dev)) 404 return container_of(dev, struct tb_service, dev); 405 return NULL; 406 } 407 408 /** 409 * tb_service_driver - Thunderbolt service driver 410 * @driver: Driver structure 411 * @probe: Called when the driver is probed 412 * @remove: Called when the driver is removed (optional) 413 * @shutdown: Called at shutdown time to stop the service (optional) 414 * @id_table: Table of service identifiers the driver supports 415 */ 416 struct tb_service_driver { 417 struct device_driver driver; 418 int (*probe)(struct tb_service *svc, const struct tb_service_id *id); 419 void (*remove)(struct tb_service *svc); 420 void (*shutdown)(struct tb_service *svc); 421 const struct tb_service_id *id_table; 422 }; 423 424 #define TB_SERVICE(key, id) \ 425 .match_flags = TBSVC_MATCH_PROTOCOL_KEY | \ 426 TBSVC_MATCH_PROTOCOL_ID, \ 427 .protocol_key = (key), \ 428 .protocol_id = (id) 429 430 int tb_register_service_driver(struct tb_service_driver *drv); 431 void tb_unregister_service_driver(struct tb_service_driver *drv); 432 433 static inline void *tb_service_get_drvdata(const struct tb_service *svc) 434 { 435 return dev_get_drvdata(&svc->dev); 436 } 437 438 static inline void tb_service_set_drvdata(struct tb_service *svc, void *data) 439 { 440 dev_set_drvdata(&svc->dev, data); 441 } 442 443 static inline struct tb_xdomain *tb_service_parent(struct tb_service *svc) 444 { 445 return tb_to_xdomain(svc->dev.parent); 446 } 447 448 /** 449 * struct tb_nhi - thunderbolt native host interface 450 * @lock: Must be held during ring creation/destruction. Is acquired by 451 * interrupt_work when dispatching interrupts to individual rings. 452 * @pdev: Pointer to the PCI device 453 * @ops: NHI specific optional ops 454 * @iobase: MMIO space of the NHI 455 * @tx_rings: All Tx rings available on this host controller 456 * @rx_rings: All Rx rings available on this host controller 457 * @msix_ida: Used to allocate MSI-X vectors for rings 458 * @going_away: The host controller device is about to disappear so when 459 * this flag is set, avoid touching the hardware anymore. 460 * @interrupt_work: Work scheduled to handle ring interrupt when no 461 * MSI-X is used. 462 * @hop_count: Number of rings (end point hops) supported by NHI. 463 */ 464 struct tb_nhi { 465 spinlock_t lock; 466 struct pci_dev *pdev; 467 const struct tb_nhi_ops *ops; 468 void __iomem *iobase; 469 struct tb_ring **tx_rings; 470 struct tb_ring **rx_rings; 471 struct ida msix_ida; 472 bool going_away; 473 struct work_struct interrupt_work; 474 u32 hop_count; 475 }; 476 477 /** 478 * struct tb_ring - thunderbolt TX or RX ring associated with a NHI 479 * @lock: Lock serializing actions to this ring. Must be acquired after 480 * nhi->lock. 481 * @nhi: Pointer to the native host controller interface 482 * @size: Size of the ring 483 * @hop: Hop (DMA channel) associated with this ring 484 * @head: Head of the ring (write next descriptor here) 485 * @tail: Tail of the ring (complete next descriptor here) 486 * @descriptors: Allocated descriptors for this ring 487 * @queue: Queue holding frames to be transferred over this ring 488 * @in_flight: Queue holding frames that are currently in flight 489 * @work: Interrupt work structure 490 * @is_tx: Is the ring Tx or Rx 491 * @running: Is the ring running 492 * @irq: MSI-X irq number if the ring uses MSI-X. %0 otherwise. 493 * @vector: MSI-X vector number the ring uses (only set if @irq is > 0) 494 * @flags: Ring specific flags 495 * @e2e_tx_hop: Transmit HopID when E2E is enabled. Only applicable to 496 * RX ring. For TX ring this should be set to %0. 497 * @sof_mask: Bit mask used to detect start of frame PDF 498 * @eof_mask: Bit mask used to detect end of frame PDF 499 * @start_poll: Called when ring interrupt is triggered to start 500 * polling. Passing %NULL keeps the ring in interrupt mode. 501 * @poll_data: Data passed to @start_poll 502 */ 503 struct tb_ring { 504 spinlock_t lock; 505 struct tb_nhi *nhi; 506 int size; 507 int hop; 508 int head; 509 int tail; 510 struct ring_desc *descriptors; 511 dma_addr_t descriptors_dma; 512 struct list_head queue; 513 struct list_head in_flight; 514 struct work_struct work; 515 bool is_tx:1; 516 bool running:1; 517 int irq; 518 u8 vector; 519 unsigned int flags; 520 int e2e_tx_hop; 521 u16 sof_mask; 522 u16 eof_mask; 523 void (*start_poll)(void *data); 524 void *poll_data; 525 }; 526 527 /* Leave ring interrupt enabled on suspend */ 528 #define RING_FLAG_NO_SUSPEND BIT(0) 529 /* Configure the ring to be in frame mode */ 530 #define RING_FLAG_FRAME BIT(1) 531 /* Enable end-to-end flow control */ 532 #define RING_FLAG_E2E BIT(2) 533 534 struct ring_frame; 535 typedef void (*ring_cb)(struct tb_ring *, struct ring_frame *, bool canceled); 536 537 /** 538 * enum ring_desc_flags - Flags for DMA ring descriptor 539 * %RING_DESC_ISOCH: Enable isonchronous DMA (Tx only) 540 * %RING_DESC_CRC_ERROR: In frame mode CRC check failed for the frame (Rx only) 541 * %RING_DESC_COMPLETED: Descriptor completed (set by NHI) 542 * %RING_DESC_POSTED: Always set this 543 * %RING_DESC_BUFFER_OVERRUN: RX buffer overrun 544 * %RING_DESC_INTERRUPT: Request an interrupt on completion 545 */ 546 enum ring_desc_flags { 547 RING_DESC_ISOCH = 0x1, 548 RING_DESC_CRC_ERROR = 0x1, 549 RING_DESC_COMPLETED = 0x2, 550 RING_DESC_POSTED = 0x4, 551 RING_DESC_BUFFER_OVERRUN = 0x04, 552 RING_DESC_INTERRUPT = 0x8, 553 }; 554 555 /** 556 * struct ring_frame - For use with ring_rx/ring_tx 557 * @buffer_phy: DMA mapped address of the frame 558 * @callback: Callback called when the frame is finished (optional) 559 * @list: Frame is linked to a queue using this 560 * @size: Size of the frame in bytes (%0 means %4096) 561 * @flags: Flags for the frame (see &enum ring_desc_flags) 562 * @eof: End of frame protocol defined field 563 * @sof: Start of frame protocol defined field 564 */ 565 struct ring_frame { 566 dma_addr_t buffer_phy; 567 ring_cb callback; 568 struct list_head list; 569 u32 size:12; 570 u32 flags:12; 571 u32 eof:4; 572 u32 sof:4; 573 }; 574 575 /* Minimum size for ring_rx */ 576 #define TB_FRAME_SIZE 0x100 577 578 struct tb_ring *tb_ring_alloc_tx(struct tb_nhi *nhi, int hop, int size, 579 unsigned int flags); 580 struct tb_ring *tb_ring_alloc_rx(struct tb_nhi *nhi, int hop, int size, 581 unsigned int flags, int e2e_tx_hop, 582 u16 sof_mask, u16 eof_mask, 583 void (*start_poll)(void *), void *poll_data); 584 void tb_ring_start(struct tb_ring *ring); 585 void tb_ring_stop(struct tb_ring *ring); 586 void tb_ring_free(struct tb_ring *ring); 587 588 int __tb_ring_enqueue(struct tb_ring *ring, struct ring_frame *frame); 589 590 /** 591 * tb_ring_rx() - enqueue a frame on an RX ring 592 * @ring: Ring to enqueue the frame 593 * @frame: Frame to enqueue 594 * 595 * @frame->buffer, @frame->buffer_phy have to be set. The buffer must 596 * contain at least %TB_FRAME_SIZE bytes. 597 * 598 * @frame->callback will be invoked with @frame->size, @frame->flags, 599 * @frame->eof, @frame->sof set once the frame has been received. 600 * 601 * If ring_stop() is called after the packet has been enqueued 602 * @frame->callback will be called with canceled set to true. 603 * 604 * Return: Returns %-ESHUTDOWN if ring_stop has been called. Zero otherwise. 605 */ 606 static inline int tb_ring_rx(struct tb_ring *ring, struct ring_frame *frame) 607 { 608 WARN_ON(ring->is_tx); 609 return __tb_ring_enqueue(ring, frame); 610 } 611 612 /** 613 * tb_ring_tx() - enqueue a frame on an TX ring 614 * @ring: Ring the enqueue the frame 615 * @frame: Frame to enqueue 616 * 617 * @frame->buffer, @frame->buffer_phy, @frame->size, @frame->eof and 618 * @frame->sof have to be set. 619 * 620 * @frame->callback will be invoked with once the frame has been transmitted. 621 * 622 * If ring_stop() is called after the packet has been enqueued @frame->callback 623 * will be called with canceled set to true. 624 * 625 * Return: Returns %-ESHUTDOWN if ring_stop has been called. Zero otherwise. 626 */ 627 static inline int tb_ring_tx(struct tb_ring *ring, struct ring_frame *frame) 628 { 629 WARN_ON(!ring->is_tx); 630 return __tb_ring_enqueue(ring, frame); 631 } 632 633 /* Used only when the ring is in polling mode */ 634 struct ring_frame *tb_ring_poll(struct tb_ring *ring); 635 void tb_ring_poll_complete(struct tb_ring *ring); 636 637 /** 638 * tb_ring_dma_device() - Return device used for DMA mapping 639 * @ring: Ring whose DMA device is retrieved 640 * 641 * Use this function when you are mapping DMA for buffers that are 642 * passed to the ring for sending/receiving. 643 */ 644 static inline struct device *tb_ring_dma_device(struct tb_ring *ring) 645 { 646 return &ring->nhi->pdev->dev; 647 } 648 649 #endif /* THUNDERBOLT_H_ */ 650