GNU Linux-libre 4.4.288-gnu1
[releases.git] / drivers / net / ethernet / stmicro / stmmac / descs_com.h
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 */
36 static inline void ehn_desc_rx_set_on_ring(struct dma_desc *p, int end, int bfsize)
37 {
38         if (bfsize == BUF_SIZE_16KiB)
39                 p->des01.erx.buffer2_size = BUF_SIZE_8KiB - 1;
40         if (end)
41                 p->des01.erx.end_ring = 1;
42 }
43
44 static inline void ehn_desc_tx_set_on_ring(struct dma_desc *p, int end)
45 {
46         if (end)
47                 p->des01.etx.end_ring = 1;
48 }
49
50 static inline void enh_desc_end_tx_desc_on_ring(struct dma_desc *p, int ter)
51 {
52         p->des01.etx.end_ring = ter;
53 }
54
55 static inline void enh_set_tx_desc_len_on_ring(struct dma_desc *p, int len)
56 {
57         if (unlikely(len > BUF_SIZE_4KiB)) {
58                 p->des01.etx.buffer1_size = BUF_SIZE_4KiB;
59                 p->des01.etx.buffer2_size = len - BUF_SIZE_4KiB;
60         } else
61                 p->des01.etx.buffer1_size = len;
62 }
63
64 /* Normal descriptors */
65 static inline void ndesc_rx_set_on_ring(struct dma_desc *p, int end, int bfsize)
66 {
67         int size;
68
69         if (bfsize >= BUF_SIZE_2KiB) {
70                 size = min(bfsize - BUF_SIZE_2KiB + 1, BUF_SIZE_2KiB - 1);
71                 p->des01.rx.buffer2_size = size;
72         }
73         if (end)
74                 p->des01.rx.end_ring = 1;
75 }
76
77 static inline void ndesc_tx_set_on_ring(struct dma_desc *p, int end)
78 {
79         if (end)
80                 p->des01.tx.end_ring = 1;
81 }
82
83 static inline void ndesc_end_tx_desc_on_ring(struct dma_desc *p, int ter)
84 {
85         p->des01.tx.end_ring = ter;
86 }
87
88 static inline void norm_set_tx_desc_len_on_ring(struct dma_desc *p, int len)
89 {
90         if (unlikely(len > BUF_SIZE_2KiB)) {
91                 p->des01.etx.buffer1_size = BUF_SIZE_2KiB - 1;
92                 p->des01.etx.buffer2_size = len - p->des01.etx.buffer1_size;
93         } else
94                 p->des01.tx.buffer1_size = len;
95 }
96
97 /* Specific functions used for Chain mode */
98
99 /* Enhanced descriptors */
100 static inline void ehn_desc_rx_set_on_chain(struct dma_desc *p, int end)
101 {
102         p->des01.erx.second_address_chained = 1;
103 }
104
105 static inline void ehn_desc_tx_set_on_chain(struct dma_desc *p, int end)
106 {
107         p->des01.etx.second_address_chained = 1;
108 }
109
110 static inline void enh_desc_end_tx_desc_on_chain(struct dma_desc *p, int ter)
111 {
112         p->des01.etx.second_address_chained = 1;
113 }
114
115 static inline void enh_set_tx_desc_len_on_chain(struct dma_desc *p, int len)
116 {
117         p->des01.etx.buffer1_size = len;
118 }
119
120 /* Normal descriptors */
121 static inline void ndesc_rx_set_on_chain(struct dma_desc *p, int end)
122 {
123         p->des01.rx.second_address_chained = 1;
124 }
125
126 static inline void ndesc_tx_set_on_chain(struct dma_desc *p, int ring_size)
127 {
128         p->des01.tx.second_address_chained = 1;
129 }
130
131 static inline void ndesc_end_tx_desc_on_chain(struct dma_desc *p, int ter)
132 {
133         p->des01.tx.second_address_chained = 1;
134 }
135
136 static inline void norm_set_tx_desc_len_on_chain(struct dma_desc *p, int len)
137 {
138         p->des01.tx.buffer1_size = len;
139 }
140 #endif /* __DESC_COM_H__ */