2 * Thunderbolt Cactus Ridge driver - NHI driver
10 #include <linux/mutex.h>
11 #include <linux/workqueue.h>
14 * struct tb_nhi - thunderbolt native host interface
18 * Must be held during ring creation/destruction.
19 * Is acquired by interrupt_work when dispatching
20 * interrupts to individual rings.
24 struct tb_ring **tx_rings;
25 struct tb_ring **rx_rings;
26 struct work_struct interrupt_work;
27 u32 hop_count; /* Number of rings (end point hops) supported by NHI. */
31 * struct tb_ring - thunderbolt TX or RX ring associated with a NHI
34 struct mutex lock; /* must be acquired after nhi->lock */
38 int head; /* write next descriptor here */
39 int tail; /* complete next descriptor here */
40 struct ring_desc *descriptors;
41 dma_addr_t descriptors_dma;
42 struct list_head queue;
43 struct list_head in_flight;
44 struct work_struct work;
45 bool is_tx:1; /* rx otherwise */
50 typedef void (*ring_cb)(struct tb_ring*, struct ring_frame*, bool canceled);
53 * struct ring_frame - for use with ring_rx/ring_tx
56 dma_addr_t buffer_phy;
58 struct list_head list;
59 u32 size:12; /* TX: in, RX: out*/
60 u32 flags:12; /* RX: out */
61 u32 eof:4; /* TX:in, RX: out */
62 u32 sof:4; /* TX:in, RX: out */
65 #define TB_FRAME_SIZE 0x100 /* minimum size for ring_rx */
67 struct tb_ring *ring_alloc_tx(struct tb_nhi *nhi, int hop, int size);
68 struct tb_ring *ring_alloc_rx(struct tb_nhi *nhi, int hop, int size);
69 void ring_start(struct tb_ring *ring);
70 void ring_stop(struct tb_ring *ring);
71 void ring_free(struct tb_ring *ring);
73 int __ring_enqueue(struct tb_ring *ring, struct ring_frame *frame);
76 * ring_rx() - enqueue a frame on an RX ring
78 * frame->buffer, frame->buffer_phy and frame->callback have to be set. The
79 * buffer must contain at least TB_FRAME_SIZE bytes.
81 * frame->callback will be invoked with frame->size, frame->flags, frame->eof,
82 * frame->sof set once the frame has been received.
84 * If ring_stop is called after the packet has been enqueued frame->callback
85 * will be called with canceled set to true.
87 * Return: Returns ESHUTDOWN if ring_stop has been called. Zero otherwise.
89 static inline int ring_rx(struct tb_ring *ring, struct ring_frame *frame)
92 return __ring_enqueue(ring, frame);
96 * ring_tx() - enqueue a frame on an TX ring
98 * frame->buffer, frame->buffer_phy, frame->callback, frame->size, frame->eof
99 * and frame->sof have to be set.
101 * frame->callback will be invoked with once the frame has been transmitted.
103 * If ring_stop is called after the packet has been enqueued frame->callback
104 * will be called with canceled set to true.
106 * Return: Returns ESHUTDOWN if ring_stop has been called. Zero otherwise.
108 static inline int ring_tx(struct tb_ring *ring, struct ring_frame *frame)
110 WARN_ON(!ring->is_tx);
111 return __ring_enqueue(ring, frame);