nhi.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Thunderbolt Cactus Ridge driver - NHI driver
  3. *
  4. * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
  5. */
  6. #ifndef DSL3510_H_
  7. #define DSL3510_H_
  8. #include <linux/mutex.h>
  9. #include <linux/workqueue.h>
  10. /**
  11. * struct tb_nhi - thunderbolt native host interface
  12. */
  13. struct tb_nhi {
  14. struct mutex lock; /*
  15. * Must be held during ring creation/destruction.
  16. * Is acquired by interrupt_work when dispatching
  17. * interrupts to individual rings.
  18. **/
  19. struct pci_dev *pdev;
  20. void __iomem *iobase;
  21. struct tb_ring **tx_rings;
  22. struct tb_ring **rx_rings;
  23. struct work_struct interrupt_work;
  24. u32 hop_count; /* Number of rings (end point hops) supported by NHI. */
  25. };
  26. /**
  27. * struct tb_ring - thunderbolt TX or RX ring associated with a NHI
  28. */
  29. struct tb_ring {
  30. struct mutex lock; /* must be acquired after nhi->lock */
  31. struct tb_nhi *nhi;
  32. int size;
  33. int hop;
  34. int head; /* write next descriptor here */
  35. int tail; /* complete next descriptor here */
  36. struct ring_desc *descriptors;
  37. dma_addr_t descriptors_dma;
  38. struct list_head queue;
  39. struct list_head in_flight;
  40. struct work_struct work;
  41. bool is_tx:1; /* rx otherwise */
  42. bool running:1;
  43. };
  44. struct ring_frame;
  45. typedef void (*ring_cb)(struct tb_ring*, struct ring_frame*, bool canceled);
  46. /**
  47. * struct ring_frame - for use with ring_rx/ring_tx
  48. */
  49. struct ring_frame {
  50. dma_addr_t buffer_phy;
  51. ring_cb callback;
  52. struct list_head list;
  53. u32 size:12; /* TX: in, RX: out*/
  54. u32 flags:12; /* RX: out */
  55. u32 eof:4; /* TX:in, RX: out */
  56. u32 sof:4; /* TX:in, RX: out */
  57. };
  58. #define TB_FRAME_SIZE 0x100 /* minimum size for ring_rx */
  59. struct tb_ring *ring_alloc_tx(struct tb_nhi *nhi, int hop, int size);
  60. struct tb_ring *ring_alloc_rx(struct tb_nhi *nhi, int hop, int size);
  61. void ring_start(struct tb_ring *ring);
  62. void ring_stop(struct tb_ring *ring);
  63. void ring_free(struct tb_ring *ring);
  64. int __ring_enqueue(struct tb_ring *ring, struct ring_frame *frame);
  65. /**
  66. * ring_rx() - enqueue a frame on an RX ring
  67. *
  68. * frame->buffer, frame->buffer_phy and frame->callback have to be set. The
  69. * buffer must contain at least TB_FRAME_SIZE bytes.
  70. *
  71. * frame->callback will be invoked with frame->size, frame->flags, frame->eof,
  72. * frame->sof set once the frame has been received.
  73. *
  74. * If ring_stop is called after the packet has been enqueued frame->callback
  75. * will be called with canceled set to true.
  76. *
  77. * Return: Returns ESHUTDOWN if ring_stop has been called. Zero otherwise.
  78. */
  79. static inline int ring_rx(struct tb_ring *ring, struct ring_frame *frame)
  80. {
  81. WARN_ON(ring->is_tx);
  82. return __ring_enqueue(ring, frame);
  83. }
  84. /**
  85. * ring_tx() - enqueue a frame on an TX ring
  86. *
  87. * frame->buffer, frame->buffer_phy, frame->callback, frame->size, frame->eof
  88. * and frame->sof have to be set.
  89. *
  90. * frame->callback will be invoked with once the frame has been transmitted.
  91. *
  92. * If ring_stop is called after the packet has been enqueued frame->callback
  93. * will be called with canceled set to true.
  94. *
  95. * Return: Returns ESHUTDOWN if ring_stop has been called. Zero otherwise.
  96. */
  97. static inline int ring_tx(struct tb_ring *ring, struct ring_frame *frame)
  98. {
  99. WARN_ON(!ring->is_tx);
  100. return __ring_enqueue(ring, frame);
  101. }
  102. #endif