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 #if defined(CONFIG_STMMAC_RING)
34 static inline void ehn_desc_rx_set_on_ring_chain(struct dma_desc *p, int end)
35 {
36 	p->des01.erx.buffer2_size = BUF_SIZE_8KiB - 1;
37 	if (end)
38 		p->des01.erx.end_ring = 1;
39 }
40 
41 static inline void ehn_desc_tx_set_on_ring_chain(struct dma_desc *p, int end)
42 {
43 	if (end)
44 		p->des01.etx.end_ring = 1;
45 }
46 
47 static inline void enh_desc_end_tx_desc(struct dma_desc *p, int ter)
48 {
49 	p->des01.etx.end_ring = ter;
50 }
51 
52 static inline void enh_set_tx_desc_len(struct dma_desc *p, int len)
53 {
54 	if (unlikely(len > BUF_SIZE_4KiB)) {
55 		p->des01.etx.buffer1_size = BUF_SIZE_4KiB;
56 		p->des01.etx.buffer2_size = len - BUF_SIZE_4KiB;
57 	} else
58 		p->des01.etx.buffer1_size = len;
59 }
60 
61 static inline void ndesc_rx_set_on_ring_chain(struct dma_desc *p, int end)
62 {
63 	p->des01.rx.buffer2_size = BUF_SIZE_2KiB - 1;
64 	if (end)
65 		p->des01.rx.end_ring = 1;
66 }
67 
68 static inline void ndesc_tx_set_on_ring_chain(struct dma_desc *p, int end)
69 {
70 	if (end)
71 		p->des01.tx.end_ring = 1;
72 }
73 
74 static inline void ndesc_end_tx_desc(struct dma_desc *p, int ter)
75 {
76 	p->des01.tx.end_ring = ter;
77 }
78 
79 static inline void norm_set_tx_desc_len(struct dma_desc *p, int len)
80 {
81 	if (unlikely(len > BUF_SIZE_2KiB)) {
82 		p->des01.etx.buffer1_size = BUF_SIZE_2KiB - 1;
83 		p->des01.etx.buffer2_size = len - p->des01.etx.buffer1_size;
84 	} else
85 		p->des01.tx.buffer1_size = len;
86 }
87 
88 #else
89 
90 static inline void ehn_desc_rx_set_on_ring_chain(struct dma_desc *p, int end)
91 {
92 	p->des01.erx.second_address_chained = 1;
93 }
94 
95 static inline void ehn_desc_tx_set_on_ring_chain(struct dma_desc *p, int end)
96 {
97 	p->des01.etx.second_address_chained = 1;
98 }
99 
100 static inline void enh_desc_end_tx_desc(struct dma_desc *p, int ter)
101 {
102 	p->des01.etx.second_address_chained = 1;
103 }
104 
105 static inline void enh_set_tx_desc_len(struct dma_desc *p, int len)
106 {
107 	p->des01.etx.buffer1_size = len;
108 }
109 
110 static inline void ndesc_rx_set_on_ring_chain(struct dma_desc *p, int end)
111 {
112 	p->des01.rx.second_address_chained = 1;
113 }
114 
115 static inline void ndesc_tx_set_on_ring_chain(struct dma_desc *p, int ring_size)
116 {
117 	p->des01.tx.second_address_chained = 1;
118 }
119 
120 static inline void ndesc_end_tx_desc(struct dma_desc *p, int ter)
121 {
122 	p->des01.tx.second_address_chained = 1;
123 }
124 
125 static inline void norm_set_tx_desc_len(struct dma_desc *p, int len)
126 {
127 	p->des01.tx.buffer1_size = len;
128 }
129 #endif
130 
131 #endif /* __DESC_COM_H__ */
132