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