Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-btrfs-devel.git] / drivers / net / ethernet / stmicro / stmmac / norm_desc.c
blobf7e8ba7f501aaa49fa163a02bb504676c9279784
1 /*******************************************************************************
2 This contains the functions to handle the normal descriptors.
4 Copyright (C) 2007-2009 STMicroelectronics Ltd
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
22 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
23 *******************************************************************************/
25 #include "common.h"
26 #include "descs_com.h"
28 static int ndesc_get_tx_status(void *data, struct stmmac_extra_stats *x,
29 struct dma_desc *p, void __iomem *ioaddr)
31 int ret = 0;
32 struct net_device_stats *stats = (struct net_device_stats *)data;
34 if (unlikely(p->des01.tx.error_summary)) {
35 if (unlikely(p->des01.tx.underflow_error)) {
36 x->tx_underflow++;
37 stats->tx_fifo_errors++;
39 if (unlikely(p->des01.tx.no_carrier)) {
40 x->tx_carrier++;
41 stats->tx_carrier_errors++;
43 if (unlikely(p->des01.tx.loss_carrier)) {
44 x->tx_losscarrier++;
45 stats->tx_carrier_errors++;
47 if (unlikely((p->des01.tx.excessive_deferral) ||
48 (p->des01.tx.excessive_collisions) ||
49 (p->des01.tx.late_collision)))
50 stats->collisions += p->des01.tx.collision_count;
51 ret = -1;
53 if (unlikely(p->des01.tx.heartbeat_fail)) {
54 x->tx_heartbeat++;
55 stats->tx_heartbeat_errors++;
56 ret = -1;
58 if (unlikely(p->des01.tx.deferred))
59 x->tx_deferred++;
61 return ret;
64 static int ndesc_get_tx_len(struct dma_desc *p)
66 return p->des01.tx.buffer1_size;
69 /* This function verifies if each incoming frame has some errors
70 * and, if required, updates the multicast statistics.
71 * In case of success, it returns csum_none because the device
72 * is not able to compute the csum in HW. */
73 static int ndesc_get_rx_status(void *data, struct stmmac_extra_stats *x,
74 struct dma_desc *p)
76 int ret = csum_none;
77 struct net_device_stats *stats = (struct net_device_stats *)data;
79 if (unlikely(p->des01.rx.last_descriptor == 0)) {
80 pr_warning("ndesc Error: Oversized Ethernet "
81 "frame spanned multiple buffers\n");
82 stats->rx_length_errors++;
83 return discard_frame;
86 if (unlikely(p->des01.rx.error_summary)) {
87 if (unlikely(p->des01.rx.descriptor_error))
88 x->rx_desc++;
89 if (unlikely(p->des01.rx.partial_frame_error))
90 x->rx_partial++;
91 if (unlikely(p->des01.rx.run_frame))
92 x->rx_runt++;
93 if (unlikely(p->des01.rx.frame_too_long))
94 x->rx_toolong++;
95 if (unlikely(p->des01.rx.collision)) {
96 x->rx_collision++;
97 stats->collisions++;
99 if (unlikely(p->des01.rx.crc_error)) {
100 x->rx_crc++;
101 stats->rx_crc_errors++;
103 ret = discard_frame;
105 if (unlikely(p->des01.rx.dribbling))
106 ret = discard_frame;
108 if (unlikely(p->des01.rx.length_error)) {
109 x->rx_length++;
110 ret = discard_frame;
112 if (unlikely(p->des01.rx.mii_error)) {
113 x->rx_mii++;
114 ret = discard_frame;
116 if (p->des01.rx.multicast_frame) {
117 x->rx_multicast++;
118 stats->multicast++;
120 return ret;
123 static void ndesc_init_rx_desc(struct dma_desc *p, unsigned int ring_size,
124 int disable_rx_ic)
126 int i;
127 for (i = 0; i < ring_size; i++) {
128 p->des01.rx.own = 1;
129 p->des01.rx.buffer1_size = BUF_SIZE_2KiB - 1;
131 ndesc_rx_set_on_ring_chain(p, (i == ring_size - 1));
133 if (disable_rx_ic)
134 p->des01.rx.disable_ic = 1;
135 p++;
139 static void ndesc_init_tx_desc(struct dma_desc *p, unsigned int ring_size)
141 int i;
142 for (i = 0; i < ring_size; i++) {
143 p->des01.tx.own = 0;
144 ndesc_tx_set_on_ring_chain(p, (i == (ring_size - 1)));
145 p++;
149 static int ndesc_get_tx_owner(struct dma_desc *p)
151 return p->des01.tx.own;
154 static int ndesc_get_rx_owner(struct dma_desc *p)
156 return p->des01.rx.own;
159 static void ndesc_set_tx_owner(struct dma_desc *p)
161 p->des01.tx.own = 1;
164 static void ndesc_set_rx_owner(struct dma_desc *p)
166 p->des01.rx.own = 1;
169 static int ndesc_get_tx_ls(struct dma_desc *p)
171 return p->des01.tx.last_segment;
174 static void ndesc_release_tx_desc(struct dma_desc *p)
176 int ter = p->des01.tx.end_ring;
178 memset(p, 0, offsetof(struct dma_desc, des2));
179 ndesc_end_tx_desc(p, ter);
182 static void ndesc_prepare_tx_desc(struct dma_desc *p, int is_fs, int len,
183 int csum_flag)
185 p->des01.tx.first_segment = is_fs;
186 norm_set_tx_desc_len(p, len);
189 static void ndesc_clear_tx_ic(struct dma_desc *p)
191 p->des01.tx.interrupt = 0;
194 static void ndesc_close_tx_desc(struct dma_desc *p)
196 p->des01.tx.last_segment = 1;
197 p->des01.tx.interrupt = 1;
200 static int ndesc_get_rx_frame_len(struct dma_desc *p)
202 return p->des01.rx.frame_length;
205 const struct stmmac_desc_ops ndesc_ops = {
206 .tx_status = ndesc_get_tx_status,
207 .rx_status = ndesc_get_rx_status,
208 .get_tx_len = ndesc_get_tx_len,
209 .init_rx_desc = ndesc_init_rx_desc,
210 .init_tx_desc = ndesc_init_tx_desc,
211 .get_tx_owner = ndesc_get_tx_owner,
212 .get_rx_owner = ndesc_get_rx_owner,
213 .release_tx_desc = ndesc_release_tx_desc,
214 .prepare_tx_desc = ndesc_prepare_tx_desc,
215 .clear_tx_ic = ndesc_clear_tx_ic,
216 .close_tx_desc = ndesc_close_tx_desc,
217 .get_tx_ls = ndesc_get_tx_ls,
218 .set_tx_owner = ndesc_set_tx_owner,
219 .set_rx_owner = ndesc_set_rx_owner,
220 .get_rx_frame_len = ndesc_get_rx_frame_len,