1 /*******************************************************************************
2 Header File to describe Normal/enhanced descriptor functions used for RING
3 and CHAINED modes.
4
5 Copyright(C) 2011 STMicroelectronics Ltd
6
7 It defines all the functions used to handle the normal/enhanced
8 descriptors in case of the DMA is configured to work in chained or
9 in ring mode.
10
11 This program is free software; you can redistribute it and/or modify it
12 under the terms and conditions of the GNU General Public License,
13 version 2, as published by the Free Software Foundation.
14
15 This program is distributed in the hope it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 more details.
19
20 You should have received a copy of the GNU General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc.,
22 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
23
24 The full GNU General Public License is included in this distribution in
25 the file called "COPYING".
26
27 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
28 *******************************************************************************/
29
30 #ifndef __DESC_COM_H__
31 #define __DESC_COM_H__
32
33 /* Specific functions used for Ring mode */
34
35 /* Enhanced descriptors */
ehn_desc_rx_set_on_ring(struct dma_desc * p,int end)36 static inline void ehn_desc_rx_set_on_ring(struct dma_desc *p, int end)
37 {
38 p->des1 |= ((BUF_SIZE_8KiB - 1) << ERDES1_BUFFER2_SIZE_SHIFT)
39 & ERDES1_BUFFER2_SIZE_MASK;
40
41 if (end)
42 p->des1 |= ERDES1_END_RING;
43 }
44
enh_desc_end_tx_desc_on_ring(struct dma_desc * p,int end)45 static inline void enh_desc_end_tx_desc_on_ring(struct dma_desc *p, int end)
46 {
47 if (end)
48 p->des0 |= ETDES0_END_RING;
49 else
50 p->des0 &= ~ETDES0_END_RING;
51 }
52
enh_set_tx_desc_len_on_ring(struct dma_desc * p,int len)53 static inline void enh_set_tx_desc_len_on_ring(struct dma_desc *p, int len)
54 {
55 if (unlikely(len > BUF_SIZE_4KiB)) {
56 p->des1 |= (((len - BUF_SIZE_4KiB) << ETDES1_BUFFER2_SIZE_SHIFT)
57 & ETDES1_BUFFER2_SIZE_MASK) | (BUF_SIZE_4KiB
58 & ETDES1_BUFFER1_SIZE_MASK);
59 } else
60 p->des1 |= (len & ETDES1_BUFFER1_SIZE_MASK);
61 }
62
63 /* Normal descriptors */
ndesc_rx_set_on_ring(struct dma_desc * p,int end)64 static inline void ndesc_rx_set_on_ring(struct dma_desc *p, int end)
65 {
66 p->des1 |= ((BUF_SIZE_2KiB - 1) << RDES1_BUFFER2_SIZE_SHIFT)
67 & RDES1_BUFFER2_SIZE_MASK;
68
69 if (end)
70 p->des1 |= RDES1_END_RING;
71 }
72
ndesc_end_tx_desc_on_ring(struct dma_desc * p,int end)73 static inline void ndesc_end_tx_desc_on_ring(struct dma_desc *p, int end)
74 {
75 if (end)
76 p->des1 |= TDES1_END_RING;
77 else
78 p->des1 &= ~TDES1_END_RING;
79 }
80
norm_set_tx_desc_len_on_ring(struct dma_desc * p,int len)81 static inline void norm_set_tx_desc_len_on_ring(struct dma_desc *p, int len)
82 {
83 if (unlikely(len > BUF_SIZE_2KiB)) {
84 unsigned int buffer1 = (BUF_SIZE_2KiB - 1)
85 & TDES1_BUFFER1_SIZE_MASK;
86 p->des1 |= ((((len - buffer1) << TDES1_BUFFER2_SIZE_SHIFT)
87 & TDES1_BUFFER2_SIZE_MASK) | buffer1);
88 } else
89 p->des1 |= (len & TDES1_BUFFER1_SIZE_MASK);
90 }
91
92 /* Specific functions used for Chain mode */
93
94 /* Enhanced descriptors */
ehn_desc_rx_set_on_chain(struct dma_desc * p)95 static inline void ehn_desc_rx_set_on_chain(struct dma_desc *p)
96 {
97 p->des1 |= ERDES1_SECOND_ADDRESS_CHAINED;
98 }
99
enh_desc_end_tx_desc_on_chain(struct dma_desc * p)100 static inline void enh_desc_end_tx_desc_on_chain(struct dma_desc *p)
101 {
102 p->des0 |= ETDES0_SECOND_ADDRESS_CHAINED;
103 }
104
enh_set_tx_desc_len_on_chain(struct dma_desc * p,int len)105 static inline void enh_set_tx_desc_len_on_chain(struct dma_desc *p, int len)
106 {
107 p->des1 |= (len & ETDES1_BUFFER1_SIZE_MASK);
108 }
109
110 /* Normal descriptors */
ndesc_rx_set_on_chain(struct dma_desc * p,int end)111 static inline void ndesc_rx_set_on_chain(struct dma_desc *p, int end)
112 {
113 p->des1 |= RDES1_SECOND_ADDRESS_CHAINED;
114 }
115
ndesc_tx_set_on_chain(struct dma_desc * p)116 static inline void ndesc_tx_set_on_chain(struct dma_desc *p)
117 {
118 p->des1 |= TDES1_SECOND_ADDRESS_CHAINED;
119 }
120
norm_set_tx_desc_len_on_chain(struct dma_desc * p,int len)121 static inline void norm_set_tx_desc_len_on_chain(struct dma_desc *p, int len)
122 {
123 p->des1 |= len & TDES1_BUFFER1_SIZE_MASK;
124 }
125 #endif /* __DESC_COM_H__ */
126