thunderbolt.h 19 KB

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