davinci_cpdma.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Texas Instruments CPDMA Driver
  4. *
  5. * Copyright (C) 2010 Texas Instruments
  6. *
  7. */
  8. #ifndef __DAVINCI_CPDMA_H__
  9. #define __DAVINCI_CPDMA_H__
  10. #define CPDMA_MAX_CHANNELS BITS_PER_LONG
  11. #define CPDMA_RX_SOURCE_PORT(__status__) ((__status__ >> 16) & 0x7)
  12. #define CPDMA_RX_VLAN_ENCAP BIT(19)
  13. #define CPDMA_EOI_RX_THRESH 0x0
  14. #define CPDMA_EOI_RX 0x1
  15. #define CPDMA_EOI_TX 0x2
  16. #define CPDMA_EOI_MISC 0x3
  17. struct cpdma_params {
  18. struct device *dev;
  19. void __iomem *dmaregs;
  20. void __iomem *txhdp, *rxhdp, *txcp, *rxcp;
  21. void __iomem *rxthresh, *rxfree;
  22. int num_chan;
  23. bool has_soft_reset;
  24. int min_packet_size;
  25. dma_addr_t desc_mem_phys;
  26. dma_addr_t desc_hw_addr;
  27. int desc_mem_size;
  28. int desc_align;
  29. u32 bus_freq_mhz;
  30. u32 descs_pool_size;
  31. /*
  32. * Some instances of embedded cpdma controllers have extra control and
  33. * status registers. The following flag enables access to these
  34. * "extended" registers.
  35. */
  36. bool has_ext_regs;
  37. };
  38. struct cpdma_chan_stats {
  39. u32 head_enqueue;
  40. u32 tail_enqueue;
  41. u32 pad_enqueue;
  42. u32 misqueued;
  43. u32 desc_alloc_fail;
  44. u32 pad_alloc_fail;
  45. u32 runt_receive_buff;
  46. u32 runt_transmit_buff;
  47. u32 empty_dequeue;
  48. u32 busy_dequeue;
  49. u32 good_dequeue;
  50. u32 requeue;
  51. u32 teardown_dequeue;
  52. };
  53. struct cpdma_ctlr;
  54. struct cpdma_chan;
  55. typedef void (*cpdma_handler_fn)(void *token, int len, int status);
  56. struct cpdma_ctlr *cpdma_ctlr_create(struct cpdma_params *params);
  57. int cpdma_ctlr_destroy(struct cpdma_ctlr *ctlr);
  58. int cpdma_ctlr_start(struct cpdma_ctlr *ctlr);
  59. int cpdma_ctlr_stop(struct cpdma_ctlr *ctlr);
  60. struct cpdma_chan *cpdma_chan_create(struct cpdma_ctlr *ctlr, int chan_num,
  61. cpdma_handler_fn handler, int rx_type);
  62. int cpdma_chan_get_rx_buf_num(struct cpdma_chan *chan);
  63. int cpdma_chan_destroy(struct cpdma_chan *chan);
  64. int cpdma_chan_start(struct cpdma_chan *chan);
  65. int cpdma_chan_stop(struct cpdma_chan *chan);
  66. int cpdma_chan_get_stats(struct cpdma_chan *chan,
  67. struct cpdma_chan_stats *stats);
  68. int cpdma_chan_submit_mapped(struct cpdma_chan *chan, void *token,
  69. dma_addr_t data, int len, int directed);
  70. int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data,
  71. int len, int directed);
  72. int cpdma_chan_idle_submit_mapped(struct cpdma_chan *chan, void *token,
  73. dma_addr_t data, int len, int directed);
  74. int cpdma_chan_idle_submit(struct cpdma_chan *chan, void *token, void *data,
  75. int len, int directed);
  76. int cpdma_chan_process(struct cpdma_chan *chan, int quota);
  77. int cpdma_ctlr_int_ctrl(struct cpdma_ctlr *ctlr, bool enable);
  78. void cpdma_ctlr_eoi(struct cpdma_ctlr *ctlr, u32 value);
  79. int cpdma_chan_int_ctrl(struct cpdma_chan *chan, bool enable);
  80. u32 cpdma_ctrl_rxchs_state(struct cpdma_ctlr *ctlr);
  81. u32 cpdma_ctrl_txchs_state(struct cpdma_ctlr *ctlr);
  82. bool cpdma_check_free_tx_desc(struct cpdma_chan *chan);
  83. int cpdma_chan_set_weight(struct cpdma_chan *ch, int weight);
  84. int cpdma_chan_set_rate(struct cpdma_chan *ch, u32 rate);
  85. u32 cpdma_chan_get_rate(struct cpdma_chan *ch);
  86. u32 cpdma_chan_get_min_rate(struct cpdma_ctlr *ctlr);
  87. enum cpdma_control {
  88. CPDMA_TX_RLIM, /* read-write */
  89. CPDMA_CMD_IDLE, /* write-only */
  90. CPDMA_COPY_ERROR_FRAMES, /* read-write */
  91. CPDMA_RX_OFF_LEN_UPDATE, /* read-write */
  92. CPDMA_RX_OWNERSHIP_FLIP, /* read-write */
  93. CPDMA_TX_PRIO_FIXED, /* read-write */
  94. CPDMA_STAT_IDLE, /* read-only */
  95. CPDMA_STAT_TX_ERR_CHAN, /* read-only */
  96. CPDMA_STAT_TX_ERR_CODE, /* read-only */
  97. CPDMA_STAT_RX_ERR_CHAN, /* read-only */
  98. CPDMA_STAT_RX_ERR_CODE, /* read-only */
  99. CPDMA_RX_BUFFER_OFFSET, /* read-write */
  100. };
  101. int cpdma_control_get(struct cpdma_ctlr *ctlr, int control);
  102. int cpdma_control_set(struct cpdma_ctlr *ctlr, int control, int value);
  103. int cpdma_get_num_rx_descs(struct cpdma_ctlr *ctlr);
  104. int cpdma_set_num_rx_descs(struct cpdma_ctlr *ctlr, int num_rx_desc);
  105. int cpdma_get_num_tx_descs(struct cpdma_ctlr *ctlr);
  106. #endif