aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-06-24 13:47:38 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-06-24 13:47:38 -0400
commitc82e6d450fda56cb2d4f68534173d3cd11b32f9f (patch)
treebac06ba3b1134e5eab072476129e943a1bf04fa6 /drivers
parentc3cb5e193937c7aa50c323e7933507020bd26340 (diff)
parenta620c1632629b42369e78448acc7b384fe1faf48 (diff)
Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus
* 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus: Staging: octeon-ethernet: Fix race freeing transmit buffers. Staging: octeon-ethernet: Convert to use net_device_ops. MIPS: Cavium: Add CPU hotplugging code. MIPS: SMP: Allow suspend and hibernation if CPU hotplug is available MIPS: Add arch generic CPU hotplug DMA: txx9dmac: use dma_unmap_single if DMA_COMPL_{SRC,DEST}_UNMAP_SINGLE set MIPS: Sibyte: Fix build error if CONFIG_SERIAL_SB1250_DUART is undefined. MIPS: MIPSsim: Fix build error if MSC01E_INT_BASE is undefined. MIPS: Hibernation: Remove SMP TLB and cacheflushing code. MIPS: Build fix - include <linux/smp.h> into all smp_processor_id() users. MIPS: bug.h Build fix - include <linux/compiler.h>.
Diffstat (limited to 'drivers')
-rw-r--r--drivers/dma/txx9dmac.c20
-rw-r--r--drivers/staging/octeon/Makefile1
-rw-r--r--drivers/staging/octeon/ethernet-common.c328
-rw-r--r--drivers/staging/octeon/ethernet-common.h29
-rw-r--r--drivers/staging/octeon/ethernet-defines.h2
-rw-r--r--drivers/staging/octeon/ethernet-rgmii.c9
-rw-r--r--drivers/staging/octeon/ethernet-sgmii.c9
-rw-r--r--drivers/staging/octeon/ethernet-spi.c1
-rw-r--r--drivers/staging/octeon/ethernet-tx.c62
-rw-r--r--drivers/staging/octeon/ethernet-tx.h25
-rw-r--r--drivers/staging/octeon/ethernet-xaui.c9
-rw-r--r--drivers/staging/octeon/ethernet.c470
-rw-r--r--drivers/staging/octeon/octeon-ethernet.h11
13 files changed, 507 insertions, 469 deletions
diff --git a/drivers/dma/txx9dmac.c b/drivers/dma/txx9dmac.c
index 9aa9ea9822c8..88dab52926f4 100644
--- a/drivers/dma/txx9dmac.c
+++ b/drivers/dma/txx9dmac.c
@@ -432,23 +432,27 @@ txx9dmac_descriptor_complete(struct txx9dmac_chan *dc,
432 list_splice_init(&txd->tx_list, &dc->free_list); 432 list_splice_init(&txd->tx_list, &dc->free_list);
433 list_move(&desc->desc_node, &dc->free_list); 433 list_move(&desc->desc_node, &dc->free_list);
434 434
435 /*
436 * We use dma_unmap_page() regardless of how the buffers were
437 * mapped before they were submitted...
438 */
439 if (!ds) { 435 if (!ds) {
440 dma_addr_t dmaaddr; 436 dma_addr_t dmaaddr;
441 if (!(txd->flags & DMA_COMPL_SKIP_DEST_UNMAP)) { 437 if (!(txd->flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
442 dmaaddr = is_dmac64(dc) ? 438 dmaaddr = is_dmac64(dc) ?
443 desc->hwdesc.DAR : desc->hwdesc32.DAR; 439 desc->hwdesc.DAR : desc->hwdesc32.DAR;
444 dma_unmap_page(chan2parent(&dc->chan), dmaaddr, 440 if (txd->flags & DMA_COMPL_DEST_UNMAP_SINGLE)
445 desc->len, DMA_FROM_DEVICE); 441 dma_unmap_single(chan2parent(&dc->chan),
442 dmaaddr, desc->len, DMA_FROM_DEVICE);
443 else
444 dma_unmap_page(chan2parent(&dc->chan),
445 dmaaddr, desc->len, DMA_FROM_DEVICE);
446 } 446 }
447 if (!(txd->flags & DMA_COMPL_SKIP_SRC_UNMAP)) { 447 if (!(txd->flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
448 dmaaddr = is_dmac64(dc) ? 448 dmaaddr = is_dmac64(dc) ?
449 desc->hwdesc.SAR : desc->hwdesc32.SAR; 449 desc->hwdesc.SAR : desc->hwdesc32.SAR;
450 dma_unmap_page(chan2parent(&dc->chan), dmaaddr, 450 if (txd->flags & DMA_COMPL_SRC_UNMAP_SINGLE)
451 desc->len, DMA_TO_DEVICE); 451 dma_unmap_single(chan2parent(&dc->chan),
452 dmaaddr, desc->len, DMA_TO_DEVICE);
453 else
454 dma_unmap_page(chan2parent(&dc->chan),
455 dmaaddr, desc->len, DMA_TO_DEVICE);
452 } 456 }
453 } 457 }
454 458
diff --git a/drivers/staging/octeon/Makefile b/drivers/staging/octeon/Makefile
index 3c839e37d37f..c0a583cc2227 100644
--- a/drivers/staging/octeon/Makefile
+++ b/drivers/staging/octeon/Makefile
@@ -12,7 +12,6 @@
12obj-${CONFIG_OCTEON_ETHERNET} := octeon-ethernet.o 12obj-${CONFIG_OCTEON_ETHERNET} := octeon-ethernet.o
13 13
14octeon-ethernet-objs := ethernet.o 14octeon-ethernet-objs := ethernet.o
15octeon-ethernet-objs += ethernet-common.o
16octeon-ethernet-objs += ethernet-mdio.o 15octeon-ethernet-objs += ethernet-mdio.o
17octeon-ethernet-objs += ethernet-mem.o 16octeon-ethernet-objs += ethernet-mem.o
18octeon-ethernet-objs += ethernet-proc.o 17octeon-ethernet-objs += ethernet-proc.o
diff --git a/drivers/staging/octeon/ethernet-common.c b/drivers/staging/octeon/ethernet-common.c
deleted file mode 100644
index 3e6f5b8cc63d..000000000000
--- a/drivers/staging/octeon/ethernet-common.c
+++ /dev/null
@@ -1,328 +0,0 @@
1/**********************************************************************
2 * Author: Cavium Networks
3 *
4 * Contact: support@caviumnetworks.com
5 * This file is part of the OCTEON SDK
6 *
7 * Copyright (c) 2003-2007 Cavium Networks
8 *
9 * This file is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License, Version 2, as
11 * published by the Free Software Foundation.
12 *
13 * This file is distributed in the hope that it will be useful, but
14 * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16 * NONINFRINGEMENT. See the GNU General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this file; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * or visit http://www.gnu.org/licenses/.
23 *
24 * This file may also be available under a different license from Cavium.
25 * Contact Cavium Networks for more information
26**********************************************************************/
27#include <linux/kernel.h>
28#include <linux/mii.h>
29#include <net/dst.h>
30
31#include <asm/atomic.h>
32#include <asm/octeon/octeon.h>
33
34#include "ethernet-defines.h"
35#include "ethernet-tx.h"
36#include "ethernet-mdio.h"
37#include "ethernet-util.h"
38#include "octeon-ethernet.h"
39#include "ethernet-common.h"
40
41#include "cvmx-pip.h"
42#include "cvmx-pko.h"
43#include "cvmx-fau.h"
44#include "cvmx-helper.h"
45
46#include "cvmx-gmxx-defs.h"
47
48/**
49 * Get the low level ethernet statistics
50 *
51 * @dev: Device to get the statistics from
52 * Returns Pointer to the statistics
53 */
54static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
55{
56 cvmx_pip_port_status_t rx_status;
57 cvmx_pko_port_status_t tx_status;
58 struct octeon_ethernet *priv = netdev_priv(dev);
59
60 if (priv->port < CVMX_PIP_NUM_INPUT_PORTS) {
61 if (octeon_is_simulation()) {
62 /* The simulator doesn't support statistics */
63 memset(&rx_status, 0, sizeof(rx_status));
64 memset(&tx_status, 0, sizeof(tx_status));
65 } else {
66 cvmx_pip_get_port_status(priv->port, 1, &rx_status);
67 cvmx_pko_get_port_status(priv->port, 1, &tx_status);
68 }
69
70 priv->stats.rx_packets += rx_status.inb_packets;
71 priv->stats.tx_packets += tx_status.packets;
72 priv->stats.rx_bytes += rx_status.inb_octets;
73 priv->stats.tx_bytes += tx_status.octets;
74 priv->stats.multicast += rx_status.multicast_packets;
75 priv->stats.rx_crc_errors += rx_status.inb_errors;
76 priv->stats.rx_frame_errors += rx_status.fcs_align_err_packets;
77
78 /*
79 * The drop counter must be incremented atomically
80 * since the RX tasklet also increments it.
81 */
82#ifdef CONFIG_64BIT
83 atomic64_add(rx_status.dropped_packets,
84 (atomic64_t *)&priv->stats.rx_dropped);
85#else
86 atomic_add(rx_status.dropped_packets,
87 (atomic_t *)&priv->stats.rx_dropped);
88#endif
89 }
90
91 return &priv->stats;
92}
93
94/**
95 * Set the multicast list. Currently unimplemented.
96 *
97 * @dev: Device to work on
98 */
99static void cvm_oct_common_set_multicast_list(struct net_device *dev)
100{
101 union cvmx_gmxx_prtx_cfg gmx_cfg;
102 struct octeon_ethernet *priv = netdev_priv(dev);
103 int interface = INTERFACE(priv->port);
104 int index = INDEX(priv->port);
105
106 if ((interface < 2)
107 && (cvmx_helper_interface_get_mode(interface) !=
108 CVMX_HELPER_INTERFACE_MODE_SPI)) {
109 union cvmx_gmxx_rxx_adr_ctl control;
110 control.u64 = 0;
111 control.s.bcst = 1; /* Allow broadcast MAC addresses */
112
113 if (dev->mc_list || (dev->flags & IFF_ALLMULTI) ||
114 (dev->flags & IFF_PROMISC))
115 /* Force accept multicast packets */
116 control.s.mcst = 2;
117 else
118 /* Force reject multicat packets */
119 control.s.mcst = 1;
120
121 if (dev->flags & IFF_PROMISC)
122 /*
123 * Reject matches if promisc. Since CAM is
124 * shut off, should accept everything.
125 */
126 control.s.cam_mode = 0;
127 else
128 /* Filter packets based on the CAM */
129 control.s.cam_mode = 1;
130
131 gmx_cfg.u64 =
132 cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
133 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface),
134 gmx_cfg.u64 & ~1ull);
135
136 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CTL(index, interface),
137 control.u64);
138 if (dev->flags & IFF_PROMISC)
139 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM_EN
140 (index, interface), 0);
141 else
142 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM_EN
143 (index, interface), 1);
144
145 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface),
146 gmx_cfg.u64);
147 }
148}
149
150/**
151 * Set the hardware MAC address for a device
152 *
153 * @dev: Device to change the MAC address for
154 * @addr: Address structure to change it too. MAC address is addr + 2.
155 * Returns Zero on success
156 */
157static int cvm_oct_common_set_mac_address(struct net_device *dev, void *addr)
158{
159 struct octeon_ethernet *priv = netdev_priv(dev);
160 union cvmx_gmxx_prtx_cfg gmx_cfg;
161 int interface = INTERFACE(priv->port);
162 int index = INDEX(priv->port);
163
164 memcpy(dev->dev_addr, addr + 2, 6);
165
166 if ((interface < 2)
167 && (cvmx_helper_interface_get_mode(interface) !=
168 CVMX_HELPER_INTERFACE_MODE_SPI)) {
169 int i;
170 uint8_t *ptr = addr;
171 uint64_t mac = 0;
172 for (i = 0; i < 6; i++)
173 mac = (mac << 8) | (uint64_t) (ptr[i + 2]);
174
175 gmx_cfg.u64 =
176 cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
177 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface),
178 gmx_cfg.u64 & ~1ull);
179
180 cvmx_write_csr(CVMX_GMXX_SMACX(index, interface), mac);
181 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM0(index, interface),
182 ptr[2]);
183 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM1(index, interface),
184 ptr[3]);
185 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM2(index, interface),
186 ptr[4]);
187 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM3(index, interface),
188 ptr[5]);
189 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM4(index, interface),
190 ptr[6]);
191 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM5(index, interface),
192 ptr[7]);
193 cvm_oct_common_set_multicast_list(dev);
194 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface),
195 gmx_cfg.u64);
196 }
197 return 0;
198}
199
200/**
201 * Change the link MTU. Unimplemented
202 *
203 * @dev: Device to change
204 * @new_mtu: The new MTU
205 *
206 * Returns Zero on success
207 */
208static int cvm_oct_common_change_mtu(struct net_device *dev, int new_mtu)
209{
210 struct octeon_ethernet *priv = netdev_priv(dev);
211 int interface = INTERFACE(priv->port);
212 int index = INDEX(priv->port);
213#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
214 int vlan_bytes = 4;
215#else
216 int vlan_bytes = 0;
217#endif
218
219 /*
220 * Limit the MTU to make sure the ethernet packets are between
221 * 64 bytes and 65535 bytes.
222 */
223 if ((new_mtu + 14 + 4 + vlan_bytes < 64)
224 || (new_mtu + 14 + 4 + vlan_bytes > 65392)) {
225 pr_err("MTU must be between %d and %d.\n",
226 64 - 14 - 4 - vlan_bytes, 65392 - 14 - 4 - vlan_bytes);
227 return -EINVAL;
228 }
229 dev->mtu = new_mtu;
230
231 if ((interface < 2)
232 && (cvmx_helper_interface_get_mode(interface) !=
233 CVMX_HELPER_INTERFACE_MODE_SPI)) {
234 /* Add ethernet header and FCS, and VLAN if configured. */
235 int max_packet = new_mtu + 14 + 4 + vlan_bytes;
236
237 if (OCTEON_IS_MODEL(OCTEON_CN3XXX)
238 || OCTEON_IS_MODEL(OCTEON_CN58XX)) {
239 /* Signal errors on packets larger than the MTU */
240 cvmx_write_csr(CVMX_GMXX_RXX_FRM_MAX(index, interface),
241 max_packet);
242 } else {
243 /*
244 * Set the hardware to truncate packets larger
245 * than the MTU and smaller the 64 bytes.
246 */
247 union cvmx_pip_frm_len_chkx frm_len_chk;
248 frm_len_chk.u64 = 0;
249 frm_len_chk.s.minlen = 64;
250 frm_len_chk.s.maxlen = max_packet;
251 cvmx_write_csr(CVMX_PIP_FRM_LEN_CHKX(interface),
252 frm_len_chk.u64);
253 }
254 /*
255 * Set the hardware to truncate packets larger than
256 * the MTU. The jabber register must be set to a
257 * multiple of 8 bytes, so round up.
258 */
259 cvmx_write_csr(CVMX_GMXX_RXX_JABBER(index, interface),
260 (max_packet + 7) & ~7u);
261 }
262 return 0;
263}
264
265/**
266 * Per network device initialization
267 *
268 * @dev: Device to initialize
269 * Returns Zero on success
270 */
271int cvm_oct_common_init(struct net_device *dev)
272{
273 static int count;
274 char mac[8] = { 0x00, 0x00,
275 octeon_bootinfo->mac_addr_base[0],
276 octeon_bootinfo->mac_addr_base[1],
277 octeon_bootinfo->mac_addr_base[2],
278 octeon_bootinfo->mac_addr_base[3],
279 octeon_bootinfo->mac_addr_base[4],
280 octeon_bootinfo->mac_addr_base[5] + count
281 };
282 struct octeon_ethernet *priv = netdev_priv(dev);
283
284 /*
285 * Force the interface to use the POW send if always_use_pow
286 * was specified or it is in the pow send list.
287 */
288 if ((pow_send_group != -1)
289 && (always_use_pow || strstr(pow_send_list, dev->name)))
290 priv->queue = -1;
291
292 if (priv->queue != -1) {
293 dev->hard_start_xmit = cvm_oct_xmit;
294 if (USE_HW_TCPUDP_CHECKSUM)
295 dev->features |= NETIF_F_IP_CSUM;
296 } else
297 dev->hard_start_xmit = cvm_oct_xmit_pow;
298 count++;
299
300 dev->get_stats = cvm_oct_common_get_stats;
301 dev->set_mac_address = cvm_oct_common_set_mac_address;
302 dev->set_multicast_list = cvm_oct_common_set_multicast_list;
303 dev->change_mtu = cvm_oct_common_change_mtu;
304 dev->do_ioctl = cvm_oct_ioctl;
305 /* We do our own locking, Linux doesn't need to */
306 dev->features |= NETIF_F_LLTX;
307 SET_ETHTOOL_OPS(dev, &cvm_oct_ethtool_ops);
308#ifdef CONFIG_NET_POLL_CONTROLLER
309 dev->poll_controller = cvm_oct_poll_controller;
310#endif
311
312 cvm_oct_mdio_setup_device(dev);
313 dev->set_mac_address(dev, mac);
314 dev->change_mtu(dev, dev->mtu);
315
316 /*
317 * Zero out stats for port so we won't mistakenly show
318 * counters from the bootloader.
319 */
320 memset(dev->get_stats(dev), 0, sizeof(struct net_device_stats));
321
322 return 0;
323}
324
325void cvm_oct_common_uninit(struct net_device *dev)
326{
327 /* Currently nothing to do */
328}
diff --git a/drivers/staging/octeon/ethernet-common.h b/drivers/staging/octeon/ethernet-common.h
deleted file mode 100644
index 2bd9cd76a398..000000000000
--- a/drivers/staging/octeon/ethernet-common.h
+++ /dev/null
@@ -1,29 +0,0 @@
1/*********************************************************************
2 * Author: Cavium Networks
3 *
4 * Contact: support@caviumnetworks.com
5 * This file is part of the OCTEON SDK
6 *
7 * Copyright (c) 2003-2007 Cavium Networks
8 *
9 * This file is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License, Version 2, as
11 * published by the Free Software Foundation.
12 *
13 * This file is distributed in the hope that it will be useful, but
14 * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16 * NONINFRINGEMENT. See the GNU General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this file; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * or visit http://www.gnu.org/licenses/.
23 *
24 * This file may also be available under a different license from Cavium.
25 * Contact Cavium Networks for more information
26*********************************************************************/
27
28int cvm_oct_common_init(struct net_device *dev);
29void cvm_oct_common_uninit(struct net_device *dev);
diff --git a/drivers/staging/octeon/ethernet-defines.h b/drivers/staging/octeon/ethernet-defines.h
index 8f7374e7664c..f13131b03c33 100644
--- a/drivers/staging/octeon/ethernet-defines.h
+++ b/drivers/staging/octeon/ethernet-defines.h
@@ -117,6 +117,8 @@
117 117
118/* Maximum number of packets to process per interrupt. */ 118/* Maximum number of packets to process per interrupt. */
119#define MAX_RX_PACKETS 120 119#define MAX_RX_PACKETS 120
120/* Maximum number of SKBs to try to free per xmit packet. */
121#define MAX_SKB_TO_FREE 10
120#define MAX_OUT_QUEUE_DEPTH 1000 122#define MAX_OUT_QUEUE_DEPTH 1000
121 123
122#ifndef CONFIG_SMP 124#ifndef CONFIG_SMP
diff --git a/drivers/staging/octeon/ethernet-rgmii.c b/drivers/staging/octeon/ethernet-rgmii.c
index 8579f1670d1e..8704133fe127 100644
--- a/drivers/staging/octeon/ethernet-rgmii.c
+++ b/drivers/staging/octeon/ethernet-rgmii.c
@@ -33,7 +33,6 @@
33 33
34#include "ethernet-defines.h" 34#include "ethernet-defines.h"
35#include "octeon-ethernet.h" 35#include "octeon-ethernet.h"
36#include "ethernet-common.h"
37#include "ethernet-util.h" 36#include "ethernet-util.h"
38 37
39#include "cvmx-helper.h" 38#include "cvmx-helper.h"
@@ -265,7 +264,7 @@ static irqreturn_t cvm_oct_rgmii_rml_interrupt(int cpl, void *dev_id)
265 return return_status; 264 return return_status;
266} 265}
267 266
268static int cvm_oct_rgmii_open(struct net_device *dev) 267int cvm_oct_rgmii_open(struct net_device *dev)
269{ 268{
270 union cvmx_gmxx_prtx_cfg gmx_cfg; 269 union cvmx_gmxx_prtx_cfg gmx_cfg;
271 struct octeon_ethernet *priv = netdev_priv(dev); 270 struct octeon_ethernet *priv = netdev_priv(dev);
@@ -286,7 +285,7 @@ static int cvm_oct_rgmii_open(struct net_device *dev)
286 return 0; 285 return 0;
287} 286}
288 287
289static int cvm_oct_rgmii_stop(struct net_device *dev) 288int cvm_oct_rgmii_stop(struct net_device *dev)
290{ 289{
291 union cvmx_gmxx_prtx_cfg gmx_cfg; 290 union cvmx_gmxx_prtx_cfg gmx_cfg;
292 struct octeon_ethernet *priv = netdev_priv(dev); 291 struct octeon_ethernet *priv = netdev_priv(dev);
@@ -305,9 +304,7 @@ int cvm_oct_rgmii_init(struct net_device *dev)
305 int r; 304 int r;
306 305
307 cvm_oct_common_init(dev); 306 cvm_oct_common_init(dev);
308 dev->open = cvm_oct_rgmii_open; 307 dev->netdev_ops->ndo_stop(dev);
309 dev->stop = cvm_oct_rgmii_stop;
310 dev->stop(dev);
311 308
312 /* 309 /*
313 * Due to GMX errata in CN3XXX series chips, it is necessary 310 * Due to GMX errata in CN3XXX series chips, it is necessary
diff --git a/drivers/staging/octeon/ethernet-sgmii.c b/drivers/staging/octeon/ethernet-sgmii.c
index 58fa39c1d675..2b54996bd85d 100644
--- a/drivers/staging/octeon/ethernet-sgmii.c
+++ b/drivers/staging/octeon/ethernet-sgmii.c
@@ -34,13 +34,12 @@
34#include "ethernet-defines.h" 34#include "ethernet-defines.h"
35#include "octeon-ethernet.h" 35#include "octeon-ethernet.h"
36#include "ethernet-util.h" 36#include "ethernet-util.h"
37#include "ethernet-common.h"
38 37
39#include "cvmx-helper.h" 38#include "cvmx-helper.h"
40 39
41#include "cvmx-gmxx-defs.h" 40#include "cvmx-gmxx-defs.h"
42 41
43static int cvm_oct_sgmii_open(struct net_device *dev) 42int cvm_oct_sgmii_open(struct net_device *dev)
44{ 43{
45 union cvmx_gmxx_prtx_cfg gmx_cfg; 44 union cvmx_gmxx_prtx_cfg gmx_cfg;
46 struct octeon_ethernet *priv = netdev_priv(dev); 45 struct octeon_ethernet *priv = netdev_priv(dev);
@@ -61,7 +60,7 @@ static int cvm_oct_sgmii_open(struct net_device *dev)
61 return 0; 60 return 0;
62} 61}
63 62
64static int cvm_oct_sgmii_stop(struct net_device *dev) 63int cvm_oct_sgmii_stop(struct net_device *dev)
65{ 64{
66 union cvmx_gmxx_prtx_cfg gmx_cfg; 65 union cvmx_gmxx_prtx_cfg gmx_cfg;
67 struct octeon_ethernet *priv = netdev_priv(dev); 66 struct octeon_ethernet *priv = netdev_priv(dev);
@@ -113,9 +112,7 @@ int cvm_oct_sgmii_init(struct net_device *dev)
113{ 112{
114 struct octeon_ethernet *priv = netdev_priv(dev); 113 struct octeon_ethernet *priv = netdev_priv(dev);
115 cvm_oct_common_init(dev); 114 cvm_oct_common_init(dev);
116 dev->open = cvm_oct_sgmii_open; 115 dev->netdev_ops->ndo_stop(dev);
117 dev->stop = cvm_oct_sgmii_stop;
118 dev->stop(dev);
119 if (!octeon_is_simulation()) 116 if (!octeon_is_simulation())
120 priv->poll = cvm_oct_sgmii_poll; 117 priv->poll = cvm_oct_sgmii_poll;
121 118
diff --git a/drivers/staging/octeon/ethernet-spi.c b/drivers/staging/octeon/ethernet-spi.c
index e0971bbe4ddc..66190b0cb68f 100644
--- a/drivers/staging/octeon/ethernet-spi.c
+++ b/drivers/staging/octeon/ethernet-spi.c
@@ -33,7 +33,6 @@
33 33
34#include "ethernet-defines.h" 34#include "ethernet-defines.h"
35#include "octeon-ethernet.h" 35#include "octeon-ethernet.h"
36#include "ethernet-common.h"
37#include "ethernet-util.h" 36#include "ethernet-util.h"
38 37
39#include "cvmx-spi.h" 38#include "cvmx-spi.h"
diff --git a/drivers/staging/octeon/ethernet-tx.c b/drivers/staging/octeon/ethernet-tx.c
index 77b7122c8fdb..81a851390f1b 100644
--- a/drivers/staging/octeon/ethernet-tx.c
+++ b/drivers/staging/octeon/ethernet-tx.c
@@ -47,6 +47,7 @@
47 47
48#include "ethernet-defines.h" 48#include "ethernet-defines.h"
49#include "octeon-ethernet.h" 49#include "octeon-ethernet.h"
50#include "ethernet-tx.h"
50#include "ethernet-util.h" 51#include "ethernet-util.h"
51 52
52#include "cvmx-wqe.h" 53#include "cvmx-wqe.h"
@@ -82,8 +83,10 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
82 uint64_t old_scratch2; 83 uint64_t old_scratch2;
83 int dropped; 84 int dropped;
84 int qos; 85 int qos;
86 int queue_it_up;
85 struct octeon_ethernet *priv = netdev_priv(dev); 87 struct octeon_ethernet *priv = netdev_priv(dev);
86 int32_t in_use; 88 int32_t skb_to_free;
89 int32_t undo;
87 int32_t buffers_to_free; 90 int32_t buffers_to_free;
88#if REUSE_SKBUFFS_WITHOUT_FREE 91#if REUSE_SKBUFFS_WITHOUT_FREE
89 unsigned char *fpa_head; 92 unsigned char *fpa_head;
@@ -120,15 +123,15 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
120 old_scratch2 = cvmx_scratch_read64(CVMX_SCR_SCRATCH + 8); 123 old_scratch2 = cvmx_scratch_read64(CVMX_SCR_SCRATCH + 8);
121 124
122 /* 125 /*
123 * Assume we're going to be able t osend this 126 * Fetch and increment the number of packets to be
124 * packet. Fetch and increment the number of pending 127 * freed.
125 * packets for output.
126 */ 128 */
127 cvmx_fau_async_fetch_and_add32(CVMX_SCR_SCRATCH + 8, 129 cvmx_fau_async_fetch_and_add32(CVMX_SCR_SCRATCH + 8,
128 FAU_NUM_PACKET_BUFFERS_TO_FREE, 130 FAU_NUM_PACKET_BUFFERS_TO_FREE,
129 0); 131 0);
130 cvmx_fau_async_fetch_and_add32(CVMX_SCR_SCRATCH, 132 cvmx_fau_async_fetch_and_add32(CVMX_SCR_SCRATCH,
131 priv->fau + qos * 4, 1); 133 priv->fau + qos * 4,
134 MAX_SKB_TO_FREE);
132 } 135 }
133 136
134 /* 137 /*
@@ -253,10 +256,10 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
253 256
254 /* 257 /*
255 * The skbuff will be reused without ever being freed. We must 258 * The skbuff will be reused without ever being freed. We must
256 * cleanup a bunch of Linux stuff. 259 * cleanup a bunch of core things.
257 */ 260 */
258 dst_release(skb->dst); 261 dst_release(skb_dst(skb));
259 skb->dst = NULL; 262 skb_dst_set(skb, NULL);
260#ifdef CONFIG_XFRM 263#ifdef CONFIG_XFRM
261 secpath_put(skb->sp); 264 secpath_put(skb->sp);
262 skb->sp = NULL; 265 skb->sp = NULL;
@@ -286,16 +289,30 @@ dont_put_skbuff_in_hw:
286 if (USE_ASYNC_IOBDMA) { 289 if (USE_ASYNC_IOBDMA) {
287 /* Get the number of skbuffs in use by the hardware */ 290 /* Get the number of skbuffs in use by the hardware */
288 CVMX_SYNCIOBDMA; 291 CVMX_SYNCIOBDMA;
289 in_use = cvmx_scratch_read64(CVMX_SCR_SCRATCH); 292 skb_to_free = cvmx_scratch_read64(CVMX_SCR_SCRATCH);
290 buffers_to_free = cvmx_scratch_read64(CVMX_SCR_SCRATCH + 8); 293 buffers_to_free = cvmx_scratch_read64(CVMX_SCR_SCRATCH + 8);
291 } else { 294 } else {
292 /* Get the number of skbuffs in use by the hardware */ 295 /* Get the number of skbuffs in use by the hardware */
293 in_use = cvmx_fau_fetch_and_add32(priv->fau + qos * 4, 1); 296 skb_to_free = cvmx_fau_fetch_and_add32(priv->fau + qos * 4,
297 MAX_SKB_TO_FREE);
294 buffers_to_free = 298 buffers_to_free =
295 cvmx_fau_fetch_and_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE, 0); 299 cvmx_fau_fetch_and_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE, 0);
296 } 300 }
297 301
298 /* 302 /*
303 * We try to claim MAX_SKB_TO_FREE buffers. If there were not
304 * that many available, we have to un-claim (undo) any that
305 * were in excess. If skb_to_free is positive we will free
306 * that many buffers.
307 */
308 undo = skb_to_free > 0 ?
309 MAX_SKB_TO_FREE : skb_to_free + MAX_SKB_TO_FREE;
310 if (undo > 0)
311 cvmx_fau_atomic_add32(priv->fau+qos*4, -undo);
312 skb_to_free = -skb_to_free > MAX_SKB_TO_FREE ?
313 MAX_SKB_TO_FREE : -skb_to_free;
314
315 /*
299 * If we're sending faster than the receive can free them then 316 * If we're sending faster than the receive can free them then
300 * don't do the HW free. 317 * don't do the HW free.
301 */ 318 */
@@ -330,38 +347,31 @@ dont_put_skbuff_in_hw:
330 cvmx_scratch_write64(CVMX_SCR_SCRATCH + 8, old_scratch2); 347 cvmx_scratch_write64(CVMX_SCR_SCRATCH + 8, old_scratch2);
331 } 348 }
332 349
350 queue_it_up = 0;
333 if (unlikely(dropped)) { 351 if (unlikely(dropped)) {
334 dev_kfree_skb_any(skb); 352 dev_kfree_skb_any(skb);
335 cvmx_fau_atomic_add32(priv->fau + qos * 4, -1);
336 priv->stats.tx_dropped++; 353 priv->stats.tx_dropped++;
337 } else { 354 } else {
338 if (USE_SKBUFFS_IN_HW) { 355 if (USE_SKBUFFS_IN_HW) {
339 /* Put this packet on the queue to be freed later */ 356 /* Put this packet on the queue to be freed later */
340 if (pko_command.s.dontfree) 357 if (pko_command.s.dontfree)
341 skb_queue_tail(&priv->tx_free_list[qos], skb); 358 queue_it_up = 1;
342 else { 359 else
343 cvmx_fau_atomic_add32 360 cvmx_fau_atomic_add32
344 (FAU_NUM_PACKET_BUFFERS_TO_FREE, -1); 361 (FAU_NUM_PACKET_BUFFERS_TO_FREE, -1);
345 cvmx_fau_atomic_add32(priv->fau + qos * 4, -1);
346 }
347 } else { 362 } else {
348 /* Put this packet on the queue to be freed later */ 363 /* Put this packet on the queue to be freed later */
349 skb_queue_tail(&priv->tx_free_list[qos], skb); 364 queue_it_up = 1;
350 } 365 }
351 } 366 }
352 367
353 /* Free skbuffs not in use by the hardware, possibly two at a time */ 368 if (queue_it_up) {
354 if (skb_queue_len(&priv->tx_free_list[qos]) > in_use) {
355 spin_lock(&priv->tx_free_list[qos].lock); 369 spin_lock(&priv->tx_free_list[qos].lock);
356 /* 370 __skb_queue_tail(&priv->tx_free_list[qos], skb);
357 * Check again now that we have the lock. It might 371 cvm_oct_free_tx_skbs(priv, skb_to_free, qos, 0);
358 * have changed.
359 */
360 if (skb_queue_len(&priv->tx_free_list[qos]) > in_use)
361 dev_kfree_skb(__skb_dequeue(&priv->tx_free_list[qos]));
362 if (skb_queue_len(&priv->tx_free_list[qos]) > in_use)
363 dev_kfree_skb(__skb_dequeue(&priv->tx_free_list[qos]));
364 spin_unlock(&priv->tx_free_list[qos].lock); 372 spin_unlock(&priv->tx_free_list[qos].lock);
373 } else {
374 cvm_oct_free_tx_skbs(priv, skb_to_free, qos, 1);
365 } 375 }
366 376
367 return 0; 377 return 0;
diff --git a/drivers/staging/octeon/ethernet-tx.h b/drivers/staging/octeon/ethernet-tx.h
index 5106236fe981..c0bebf750bc0 100644
--- a/drivers/staging/octeon/ethernet-tx.h
+++ b/drivers/staging/octeon/ethernet-tx.h
@@ -30,3 +30,28 @@ int cvm_oct_xmit_pow(struct sk_buff *skb, struct net_device *dev);
30int cvm_oct_transmit_qos(struct net_device *dev, void *work_queue_entry, 30int cvm_oct_transmit_qos(struct net_device *dev, void *work_queue_entry,
31 int do_free, int qos); 31 int do_free, int qos);
32void cvm_oct_tx_shutdown(struct net_device *dev); 32void cvm_oct_tx_shutdown(struct net_device *dev);
33
34/**
35 * Free dead transmit skbs.
36 *
37 * @priv: The driver data
38 * @skb_to_free: The number of SKBs to free (free none if negative).
39 * @qos: The queue to free from.
40 * @take_lock: If true, acquire the skb list lock.
41 */
42static inline void cvm_oct_free_tx_skbs(struct octeon_ethernet *priv,
43 int skb_to_free,
44 int qos, int take_lock)
45{
46 /* Free skbuffs not in use by the hardware. */
47 if (skb_to_free > 0) {
48 if (take_lock)
49 spin_lock(&priv->tx_free_list[qos].lock);
50 while (skb_to_free > 0) {
51 dev_kfree_skb(__skb_dequeue(&priv->tx_free_list[qos]));
52 skb_to_free--;
53 }
54 if (take_lock)
55 spin_unlock(&priv->tx_free_list[qos].lock);
56 }
57}
diff --git a/drivers/staging/octeon/ethernet-xaui.c b/drivers/staging/octeon/ethernet-xaui.c
index f08eb32e04fc..0c2e7cc40f35 100644
--- a/drivers/staging/octeon/ethernet-xaui.c
+++ b/drivers/staging/octeon/ethernet-xaui.c
@@ -33,14 +33,13 @@
33 33
34#include "ethernet-defines.h" 34#include "ethernet-defines.h"
35#include "octeon-ethernet.h" 35#include "octeon-ethernet.h"
36#include "ethernet-common.h"
37#include "ethernet-util.h" 36#include "ethernet-util.h"
38 37
39#include "cvmx-helper.h" 38#include "cvmx-helper.h"
40 39
41#include "cvmx-gmxx-defs.h" 40#include "cvmx-gmxx-defs.h"
42 41
43static int cvm_oct_xaui_open(struct net_device *dev) 42int cvm_oct_xaui_open(struct net_device *dev)
44{ 43{
45 union cvmx_gmxx_prtx_cfg gmx_cfg; 44 union cvmx_gmxx_prtx_cfg gmx_cfg;
46 struct octeon_ethernet *priv = netdev_priv(dev); 45 struct octeon_ethernet *priv = netdev_priv(dev);
@@ -60,7 +59,7 @@ static int cvm_oct_xaui_open(struct net_device *dev)
60 return 0; 59 return 0;
61} 60}
62 61
63static int cvm_oct_xaui_stop(struct net_device *dev) 62int cvm_oct_xaui_stop(struct net_device *dev)
64{ 63{
65 union cvmx_gmxx_prtx_cfg gmx_cfg; 64 union cvmx_gmxx_prtx_cfg gmx_cfg;
66 struct octeon_ethernet *priv = netdev_priv(dev); 65 struct octeon_ethernet *priv = netdev_priv(dev);
@@ -112,9 +111,7 @@ int cvm_oct_xaui_init(struct net_device *dev)
112{ 111{
113 struct octeon_ethernet *priv = netdev_priv(dev); 112 struct octeon_ethernet *priv = netdev_priv(dev);
114 cvm_oct_common_init(dev); 113 cvm_oct_common_init(dev);
115 dev->open = cvm_oct_xaui_open; 114 dev->netdev_ops->ndo_stop(dev);
116 dev->stop = cvm_oct_xaui_stop;
117 dev->stop(dev);
118 if (!octeon_is_simulation()) 115 if (!octeon_is_simulation())
119 priv->poll = cvm_oct_xaui_poll; 116 priv->poll = cvm_oct_xaui_poll;
120 117
diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
index e8ef9e0b791f..b8479517dce2 100644
--- a/drivers/staging/octeon/ethernet.c
+++ b/drivers/staging/octeon/ethernet.c
@@ -37,13 +37,14 @@
37#include <asm/octeon/octeon.h> 37#include <asm/octeon/octeon.h>
38 38
39#include "ethernet-defines.h" 39#include "ethernet-defines.h"
40#include "octeon-ethernet.h"
40#include "ethernet-mem.h" 41#include "ethernet-mem.h"
41#include "ethernet-rx.h" 42#include "ethernet-rx.h"
42#include "ethernet-tx.h" 43#include "ethernet-tx.h"
44#include "ethernet-mdio.h"
43#include "ethernet-util.h" 45#include "ethernet-util.h"
44#include "ethernet-proc.h" 46#include "ethernet-proc.h"
45#include "ethernet-common.h" 47
46#include "octeon-ethernet.h"
47 48
48#include "cvmx-pip.h" 49#include "cvmx-pip.h"
49#include "cvmx-pko.h" 50#include "cvmx-pko.h"
@@ -51,6 +52,7 @@
51#include "cvmx-ipd.h" 52#include "cvmx-ipd.h"
52#include "cvmx-helper.h" 53#include "cvmx-helper.h"
53 54
55#include "cvmx-gmxx-defs.h"
54#include "cvmx-smix-defs.h" 56#include "cvmx-smix-defs.h"
55 57
56#if defined(CONFIG_CAVIUM_OCTEON_NUM_PACKET_BUFFERS) \ 58#if defined(CONFIG_CAVIUM_OCTEON_NUM_PACKET_BUFFERS) \
@@ -129,53 +131,55 @@ extern struct semaphore mdio_sem;
129 */ 131 */
130static void cvm_do_timer(unsigned long arg) 132static void cvm_do_timer(unsigned long arg)
131{ 133{
134 int32_t skb_to_free, undo;
135 int queues_per_port;
136 int qos;
137 struct octeon_ethernet *priv;
132 static int port; 138 static int port;
133 if (port < CVMX_PIP_NUM_INPUT_PORTS) {
134 if (cvm_oct_device[port]) {
135 int queues_per_port;
136 int qos;
137 struct octeon_ethernet *priv =
138 netdev_priv(cvm_oct_device[port]);
139 if (priv->poll) {
140 /* skip polling if we don't get the lock */
141 if (!down_trylock(&mdio_sem)) {
142 priv->poll(cvm_oct_device[port]);
143 up(&mdio_sem);
144 }
145 }
146 139
147 queues_per_port = cvmx_pko_get_num_queues(port); 140 if (port >= CVMX_PIP_NUM_INPUT_PORTS) {
148 /* Drain any pending packets in the free list */ 141 /*
149 for (qos = 0; qos < queues_per_port; qos++) { 142 * All ports have been polled. Start the next
150 if (skb_queue_len(&priv->tx_free_list[qos])) { 143 * iteration through the ports in one second.
151 spin_lock(&priv->tx_free_list[qos]. 144 */
152 lock);
153 while (skb_queue_len
154 (&priv->tx_free_list[qos]) >
155 cvmx_fau_fetch_and_add32(priv->
156 fau +
157 qos * 4,
158 0))
159 dev_kfree_skb(__skb_dequeue
160 (&priv->
161 tx_free_list
162 [qos]));
163 spin_unlock(&priv->tx_free_list[qos].
164 lock);
165 }
166 }
167 cvm_oct_device[port]->get_stats(cvm_oct_device[port]);
168 }
169 port++;
170 /* Poll the next port in a 50th of a second.
171 This spreads the polling of ports out a little bit */
172 mod_timer(&cvm_oct_poll_timer, jiffies + HZ / 50);
173 } else {
174 port = 0; 145 port = 0;
175 /* All ports have been polled. Start the next iteration through
176 the ports in one second */
177 mod_timer(&cvm_oct_poll_timer, jiffies + HZ); 146 mod_timer(&cvm_oct_poll_timer, jiffies + HZ);
147 return;
148 }
149 if (!cvm_oct_device[port])
150 goto out;
151
152 priv = netdev_priv(cvm_oct_device[port]);
153 if (priv->poll) {
154 /* skip polling if we don't get the lock */
155 if (!down_trylock(&mdio_sem)) {
156 priv->poll(cvm_oct_device[port]);
157 up(&mdio_sem);
158 }
178 } 159 }
160
161 queues_per_port = cvmx_pko_get_num_queues(port);
162 /* Drain any pending packets in the free list */
163 for (qos = 0; qos < queues_per_port; qos++) {
164 if (skb_queue_len(&priv->tx_free_list[qos]) == 0)
165 continue;
166 skb_to_free = cvmx_fau_fetch_and_add32(priv->fau + qos * 4,
167 MAX_SKB_TO_FREE);
168 undo = skb_to_free > 0 ?
169 MAX_SKB_TO_FREE : skb_to_free + MAX_SKB_TO_FREE;
170 if (undo > 0)
171 cvmx_fau_atomic_add32(priv->fau+qos*4, -undo);
172 skb_to_free = -skb_to_free > MAX_SKB_TO_FREE ?
173 MAX_SKB_TO_FREE : -skb_to_free;
174 cvm_oct_free_tx_skbs(priv, skb_to_free, qos, 1);
175 }
176 cvm_oct_device[port]->netdev_ops->ndo_get_stats(cvm_oct_device[port]);
177
178out:
179 port++;
180 /* Poll the next port in a 50th of a second.
181 This spreads the polling of ports out a little bit */
182 mod_timer(&cvm_oct_poll_timer, jiffies + HZ / 50);
179} 183}
180 184
181/** 185/**
@@ -246,6 +250,362 @@ int cvm_oct_free_work(void *work_queue_entry)
246EXPORT_SYMBOL(cvm_oct_free_work); 250EXPORT_SYMBOL(cvm_oct_free_work);
247 251
248/** 252/**
253 * Get the low level ethernet statistics
254 *
255 * @dev: Device to get the statistics from
256 * Returns Pointer to the statistics
257 */
258static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
259{
260 cvmx_pip_port_status_t rx_status;
261 cvmx_pko_port_status_t tx_status;
262 struct octeon_ethernet *priv = netdev_priv(dev);
263
264 if (priv->port < CVMX_PIP_NUM_INPUT_PORTS) {
265 if (octeon_is_simulation()) {
266 /* The simulator doesn't support statistics */
267 memset(&rx_status, 0, sizeof(rx_status));
268 memset(&tx_status, 0, sizeof(tx_status));
269 } else {
270 cvmx_pip_get_port_status(priv->port, 1, &rx_status);
271 cvmx_pko_get_port_status(priv->port, 1, &tx_status);
272 }
273
274 priv->stats.rx_packets += rx_status.inb_packets;
275 priv->stats.tx_packets += tx_status.packets;
276 priv->stats.rx_bytes += rx_status.inb_octets;
277 priv->stats.tx_bytes += tx_status.octets;
278 priv->stats.multicast += rx_status.multicast_packets;
279 priv->stats.rx_crc_errors += rx_status.inb_errors;
280 priv->stats.rx_frame_errors += rx_status.fcs_align_err_packets;
281
282 /*
283 * The drop counter must be incremented atomically
284 * since the RX tasklet also increments it.
285 */
286#ifdef CONFIG_64BIT
287 atomic64_add(rx_status.dropped_packets,
288 (atomic64_t *)&priv->stats.rx_dropped);
289#else
290 atomic_add(rx_status.dropped_packets,
291 (atomic_t *)&priv->stats.rx_dropped);
292#endif
293 }
294
295 return &priv->stats;
296}
297
298/**
299 * Change the link MTU. Unimplemented
300 *
301 * @dev: Device to change
302 * @new_mtu: The new MTU
303 *
304 * Returns Zero on success
305 */
306static int cvm_oct_common_change_mtu(struct net_device *dev, int new_mtu)
307{
308 struct octeon_ethernet *priv = netdev_priv(dev);
309 int interface = INTERFACE(priv->port);
310 int index = INDEX(priv->port);
311#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
312 int vlan_bytes = 4;
313#else
314 int vlan_bytes = 0;
315#endif
316
317 /*
318 * Limit the MTU to make sure the ethernet packets are between
319 * 64 bytes and 65535 bytes.
320 */
321 if ((new_mtu + 14 + 4 + vlan_bytes < 64)
322 || (new_mtu + 14 + 4 + vlan_bytes > 65392)) {
323 pr_err("MTU must be between %d and %d.\n",
324 64 - 14 - 4 - vlan_bytes, 65392 - 14 - 4 - vlan_bytes);
325 return -EINVAL;
326 }
327 dev->mtu = new_mtu;
328
329 if ((interface < 2)
330 && (cvmx_helper_interface_get_mode(interface) !=
331 CVMX_HELPER_INTERFACE_MODE_SPI)) {
332 /* Add ethernet header and FCS, and VLAN if configured. */
333 int max_packet = new_mtu + 14 + 4 + vlan_bytes;
334
335 if (OCTEON_IS_MODEL(OCTEON_CN3XXX)
336 || OCTEON_IS_MODEL(OCTEON_CN58XX)) {
337 /* Signal errors on packets larger than the MTU */
338 cvmx_write_csr(CVMX_GMXX_RXX_FRM_MAX(index, interface),
339 max_packet);
340 } else {
341 /*
342 * Set the hardware to truncate packets larger
343 * than the MTU and smaller the 64 bytes.
344 */
345 union cvmx_pip_frm_len_chkx frm_len_chk;
346 frm_len_chk.u64 = 0;
347 frm_len_chk.s.minlen = 64;
348 frm_len_chk.s.maxlen = max_packet;
349 cvmx_write_csr(CVMX_PIP_FRM_LEN_CHKX(interface),
350 frm_len_chk.u64);
351 }
352 /*
353 * Set the hardware to truncate packets larger than
354 * the MTU. The jabber register must be set to a
355 * multiple of 8 bytes, so round up.
356 */
357 cvmx_write_csr(CVMX_GMXX_RXX_JABBER(index, interface),
358 (max_packet + 7) & ~7u);
359 }
360 return 0;
361}
362
363/**
364 * Set the multicast list. Currently unimplemented.
365 *
366 * @dev: Device to work on
367 */
368static void cvm_oct_common_set_multicast_list(struct net_device *dev)
369{
370 union cvmx_gmxx_prtx_cfg gmx_cfg;
371 struct octeon_ethernet *priv = netdev_priv(dev);
372 int interface = INTERFACE(priv->port);
373 int index = INDEX(priv->port);
374
375 if ((interface < 2)
376 && (cvmx_helper_interface_get_mode(interface) !=
377 CVMX_HELPER_INTERFACE_MODE_SPI)) {
378 union cvmx_gmxx_rxx_adr_ctl control;
379 control.u64 = 0;
380 control.s.bcst = 1; /* Allow broadcast MAC addresses */
381
382 if (dev->mc_list || (dev->flags & IFF_ALLMULTI) ||
383 (dev->flags & IFF_PROMISC))
384 /* Force accept multicast packets */
385 control.s.mcst = 2;
386 else
387 /* Force reject multicat packets */
388 control.s.mcst = 1;
389
390 if (dev->flags & IFF_PROMISC)
391 /*
392 * Reject matches if promisc. Since CAM is
393 * shut off, should accept everything.
394 */
395 control.s.cam_mode = 0;
396 else
397 /* Filter packets based on the CAM */
398 control.s.cam_mode = 1;
399
400 gmx_cfg.u64 =
401 cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
402 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface),
403 gmx_cfg.u64 & ~1ull);
404
405 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CTL(index, interface),
406 control.u64);
407 if (dev->flags & IFF_PROMISC)
408 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM_EN
409 (index, interface), 0);
410 else
411 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM_EN
412 (index, interface), 1);
413
414 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface),
415 gmx_cfg.u64);
416 }
417}
418
419/**
420 * Set the hardware MAC address for a device
421 *
422 * @dev: Device to change the MAC address for
423 * @addr: Address structure to change it too. MAC address is addr + 2.
424 * Returns Zero on success
425 */
426static int cvm_oct_common_set_mac_address(struct net_device *dev, void *addr)
427{
428 struct octeon_ethernet *priv = netdev_priv(dev);
429 union cvmx_gmxx_prtx_cfg gmx_cfg;
430 int interface = INTERFACE(priv->port);
431 int index = INDEX(priv->port);
432
433 memcpy(dev->dev_addr, addr + 2, 6);
434
435 if ((interface < 2)
436 && (cvmx_helper_interface_get_mode(interface) !=
437 CVMX_HELPER_INTERFACE_MODE_SPI)) {
438 int i;
439 uint8_t *ptr = addr;
440 uint64_t mac = 0;
441 for (i = 0; i < 6; i++)
442 mac = (mac << 8) | (uint64_t) (ptr[i + 2]);
443
444 gmx_cfg.u64 =
445 cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
446 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface),
447 gmx_cfg.u64 & ~1ull);
448
449 cvmx_write_csr(CVMX_GMXX_SMACX(index, interface), mac);
450 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM0(index, interface),
451 ptr[2]);
452 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM1(index, interface),
453 ptr[3]);
454 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM2(index, interface),
455 ptr[4]);
456 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM3(index, interface),
457 ptr[5]);
458 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM4(index, interface),
459 ptr[6]);
460 cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM5(index, interface),
461 ptr[7]);
462 cvm_oct_common_set_multicast_list(dev);
463 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface),
464 gmx_cfg.u64);
465 }
466 return 0;
467}
468
469/**
470 * Per network device initialization
471 *
472 * @dev: Device to initialize
473 * Returns Zero on success
474 */
475int cvm_oct_common_init(struct net_device *dev)
476{
477 static int count;
478 char mac[8] = { 0x00, 0x00,
479 octeon_bootinfo->mac_addr_base[0],
480 octeon_bootinfo->mac_addr_base[1],
481 octeon_bootinfo->mac_addr_base[2],
482 octeon_bootinfo->mac_addr_base[3],
483 octeon_bootinfo->mac_addr_base[4],
484 octeon_bootinfo->mac_addr_base[5] + count
485 };
486 struct octeon_ethernet *priv = netdev_priv(dev);
487
488 /*
489 * Force the interface to use the POW send if always_use_pow
490 * was specified or it is in the pow send list.
491 */
492 if ((pow_send_group != -1)
493 && (always_use_pow || strstr(pow_send_list, dev->name)))
494 priv->queue = -1;
495
496 if (priv->queue != -1 && USE_HW_TCPUDP_CHECKSUM)
497 dev->features |= NETIF_F_IP_CSUM;
498
499 count++;
500
501 /* We do our own locking, Linux doesn't need to */
502 dev->features |= NETIF_F_LLTX;
503 SET_ETHTOOL_OPS(dev, &cvm_oct_ethtool_ops);
504
505 cvm_oct_mdio_setup_device(dev);
506 dev->netdev_ops->ndo_set_mac_address(dev, mac);
507 dev->netdev_ops->ndo_change_mtu(dev, dev->mtu);
508
509 /*
510 * Zero out stats for port so we won't mistakenly show
511 * counters from the bootloader.
512 */
513 memset(dev->netdev_ops->ndo_get_stats(dev), 0,
514 sizeof(struct net_device_stats));
515
516 return 0;
517}
518
519void cvm_oct_common_uninit(struct net_device *dev)
520{
521 /* Currently nothing to do */
522}
523
524static const struct net_device_ops cvm_oct_npi_netdev_ops = {
525 .ndo_init = cvm_oct_common_init,
526 .ndo_uninit = cvm_oct_common_uninit,
527 .ndo_start_xmit = cvm_oct_xmit,
528 .ndo_set_multicast_list = cvm_oct_common_set_multicast_list,
529 .ndo_set_mac_address = cvm_oct_common_set_mac_address,
530 .ndo_do_ioctl = cvm_oct_ioctl,
531 .ndo_change_mtu = cvm_oct_common_change_mtu,
532 .ndo_get_stats = cvm_oct_common_get_stats,
533#ifdef CONFIG_NET_POLL_CONTROLLER
534 .ndo_poll_controller = cvm_oct_poll_controller,
535#endif
536};
537static const struct net_device_ops cvm_oct_xaui_netdev_ops = {
538 .ndo_init = cvm_oct_xaui_init,
539 .ndo_uninit = cvm_oct_xaui_uninit,
540 .ndo_open = cvm_oct_xaui_open,
541 .ndo_stop = cvm_oct_xaui_stop,
542 .ndo_start_xmit = cvm_oct_xmit,
543 .ndo_set_multicast_list = cvm_oct_common_set_multicast_list,
544 .ndo_set_mac_address = cvm_oct_common_set_mac_address,
545 .ndo_do_ioctl = cvm_oct_ioctl,
546 .ndo_change_mtu = cvm_oct_common_change_mtu,
547 .ndo_get_stats = cvm_oct_common_get_stats,
548#ifdef CONFIG_NET_POLL_CONTROLLER
549 .ndo_poll_controller = cvm_oct_poll_controller,
550#endif
551};
552static const struct net_device_ops cvm_oct_sgmii_netdev_ops = {
553 .ndo_init = cvm_oct_sgmii_init,
554 .ndo_uninit = cvm_oct_sgmii_uninit,
555 .ndo_open = cvm_oct_sgmii_open,
556 .ndo_stop = cvm_oct_sgmii_stop,
557 .ndo_start_xmit = cvm_oct_xmit,
558 .ndo_set_multicast_list = cvm_oct_common_set_multicast_list,
559 .ndo_set_mac_address = cvm_oct_common_set_mac_address,
560 .ndo_do_ioctl = cvm_oct_ioctl,
561 .ndo_change_mtu = cvm_oct_common_change_mtu,
562 .ndo_get_stats = cvm_oct_common_get_stats,
563#ifdef CONFIG_NET_POLL_CONTROLLER
564 .ndo_poll_controller = cvm_oct_poll_controller,
565#endif
566};
567static const struct net_device_ops cvm_oct_spi_netdev_ops = {
568 .ndo_init = cvm_oct_spi_init,
569 .ndo_uninit = cvm_oct_spi_uninit,
570 .ndo_start_xmit = cvm_oct_xmit,
571 .ndo_set_multicast_list = cvm_oct_common_set_multicast_list,
572 .ndo_set_mac_address = cvm_oct_common_set_mac_address,
573 .ndo_do_ioctl = cvm_oct_ioctl,
574 .ndo_change_mtu = cvm_oct_common_change_mtu,
575 .ndo_get_stats = cvm_oct_common_get_stats,
576#ifdef CONFIG_NET_POLL_CONTROLLER
577 .ndo_poll_controller = cvm_oct_poll_controller,
578#endif
579};
580static const struct net_device_ops cvm_oct_rgmii_netdev_ops = {
581 .ndo_init = cvm_oct_rgmii_init,
582 .ndo_uninit = cvm_oct_rgmii_uninit,
583 .ndo_open = cvm_oct_rgmii_open,
584 .ndo_stop = cvm_oct_rgmii_stop,
585 .ndo_start_xmit = cvm_oct_xmit,
586 .ndo_set_multicast_list = cvm_oct_common_set_multicast_list,
587 .ndo_set_mac_address = cvm_oct_common_set_mac_address,
588 .ndo_do_ioctl = cvm_oct_ioctl,
589 .ndo_change_mtu = cvm_oct_common_change_mtu,
590 .ndo_get_stats = cvm_oct_common_get_stats,
591#ifdef CONFIG_NET_POLL_CONTROLLER
592 .ndo_poll_controller = cvm_oct_poll_controller,
593#endif
594};
595static const struct net_device_ops cvm_oct_pow_netdev_ops = {
596 .ndo_init = cvm_oct_common_init,
597 .ndo_start_xmit = cvm_oct_xmit_pow,
598 .ndo_set_multicast_list = cvm_oct_common_set_multicast_list,
599 .ndo_set_mac_address = cvm_oct_common_set_mac_address,
600 .ndo_do_ioctl = cvm_oct_ioctl,
601 .ndo_change_mtu = cvm_oct_common_change_mtu,
602 .ndo_get_stats = cvm_oct_common_get_stats,
603#ifdef CONFIG_NET_POLL_CONTROLLER
604 .ndo_poll_controller = cvm_oct_poll_controller,
605#endif
606};
607
608/**
249 * Module/ driver initialization. Creates the linux network 609 * Module/ driver initialization. Creates the linux network
250 * devices. 610 * devices.
251 * 611 *
@@ -303,7 +663,7 @@ static int __init cvm_oct_init_module(void)
303 struct octeon_ethernet *priv = netdev_priv(dev); 663 struct octeon_ethernet *priv = netdev_priv(dev);
304 memset(priv, 0, sizeof(struct octeon_ethernet)); 664 memset(priv, 0, sizeof(struct octeon_ethernet));
305 665
306 dev->init = cvm_oct_common_init; 666 dev->netdev_ops = &cvm_oct_pow_netdev_ops;
307 priv->imode = CVMX_HELPER_INTERFACE_MODE_DISABLED; 667 priv->imode = CVMX_HELPER_INTERFACE_MODE_DISABLED;
308 priv->port = CVMX_PIP_NUM_INPUT_PORTS; 668 priv->port = CVMX_PIP_NUM_INPUT_PORTS;
309 priv->queue = -1; 669 priv->queue = -1;
@@ -372,44 +732,38 @@ static int __init cvm_oct_init_module(void)
372 break; 732 break;
373 733
374 case CVMX_HELPER_INTERFACE_MODE_NPI: 734 case CVMX_HELPER_INTERFACE_MODE_NPI:
375 dev->init = cvm_oct_common_init; 735 dev->netdev_ops = &cvm_oct_npi_netdev_ops;
376 dev->uninit = cvm_oct_common_uninit;
377 strcpy(dev->name, "npi%d"); 736 strcpy(dev->name, "npi%d");
378 break; 737 break;
379 738
380 case CVMX_HELPER_INTERFACE_MODE_XAUI: 739 case CVMX_HELPER_INTERFACE_MODE_XAUI:
381 dev->init = cvm_oct_xaui_init; 740 dev->netdev_ops = &cvm_oct_xaui_netdev_ops;
382 dev->uninit = cvm_oct_xaui_uninit;
383 strcpy(dev->name, "xaui%d"); 741 strcpy(dev->name, "xaui%d");
384 break; 742 break;
385 743
386 case CVMX_HELPER_INTERFACE_MODE_LOOP: 744 case CVMX_HELPER_INTERFACE_MODE_LOOP:
387 dev->init = cvm_oct_common_init; 745 dev->netdev_ops = &cvm_oct_npi_netdev_ops;
388 dev->uninit = cvm_oct_common_uninit;
389 strcpy(dev->name, "loop%d"); 746 strcpy(dev->name, "loop%d");
390 break; 747 break;
391 748
392 case CVMX_HELPER_INTERFACE_MODE_SGMII: 749 case CVMX_HELPER_INTERFACE_MODE_SGMII:
393 dev->init = cvm_oct_sgmii_init; 750 dev->netdev_ops = &cvm_oct_sgmii_netdev_ops;
394 dev->uninit = cvm_oct_sgmii_uninit;
395 strcpy(dev->name, "eth%d"); 751 strcpy(dev->name, "eth%d");
396 break; 752 break;
397 753
398 case CVMX_HELPER_INTERFACE_MODE_SPI: 754 case CVMX_HELPER_INTERFACE_MODE_SPI:
399 dev->init = cvm_oct_spi_init; 755 dev->netdev_ops = &cvm_oct_spi_netdev_ops;
400 dev->uninit = cvm_oct_spi_uninit;
401 strcpy(dev->name, "spi%d"); 756 strcpy(dev->name, "spi%d");
402 break; 757 break;
403 758
404 case CVMX_HELPER_INTERFACE_MODE_RGMII: 759 case CVMX_HELPER_INTERFACE_MODE_RGMII:
405 case CVMX_HELPER_INTERFACE_MODE_GMII: 760 case CVMX_HELPER_INTERFACE_MODE_GMII:
406 dev->init = cvm_oct_rgmii_init; 761 dev->netdev_ops = &cvm_oct_rgmii_netdev_ops;
407 dev->uninit = cvm_oct_rgmii_uninit;
408 strcpy(dev->name, "eth%d"); 762 strcpy(dev->name, "eth%d");
409 break; 763 break;
410 } 764 }
411 765
412 if (!dev->init) { 766 if (!dev->netdev_ops) {
413 kfree(dev); 767 kfree(dev);
414 } else if (register_netdev(dev) < 0) { 768 } else if (register_netdev(dev) < 0) {
415 pr_err("Failed to register ethernet device " 769 pr_err("Failed to register ethernet device "
diff --git a/drivers/staging/octeon/octeon-ethernet.h b/drivers/staging/octeon/octeon-ethernet.h
index b3199076ef5e..3aef9878fc0a 100644
--- a/drivers/staging/octeon/octeon-ethernet.h
+++ b/drivers/staging/octeon/octeon-ethernet.h
@@ -111,12 +111,23 @@ static inline int cvm_oct_transmit(struct net_device *dev,
111 111
112extern int cvm_oct_rgmii_init(struct net_device *dev); 112extern int cvm_oct_rgmii_init(struct net_device *dev);
113extern void cvm_oct_rgmii_uninit(struct net_device *dev); 113extern void cvm_oct_rgmii_uninit(struct net_device *dev);
114extern int cvm_oct_rgmii_open(struct net_device *dev);
115extern int cvm_oct_rgmii_stop(struct net_device *dev);
116
114extern int cvm_oct_sgmii_init(struct net_device *dev); 117extern int cvm_oct_sgmii_init(struct net_device *dev);
115extern void cvm_oct_sgmii_uninit(struct net_device *dev); 118extern void cvm_oct_sgmii_uninit(struct net_device *dev);
119extern int cvm_oct_sgmii_open(struct net_device *dev);
120extern int cvm_oct_sgmii_stop(struct net_device *dev);
121
116extern int cvm_oct_spi_init(struct net_device *dev); 122extern int cvm_oct_spi_init(struct net_device *dev);
117extern void cvm_oct_spi_uninit(struct net_device *dev); 123extern void cvm_oct_spi_uninit(struct net_device *dev);
118extern int cvm_oct_xaui_init(struct net_device *dev); 124extern int cvm_oct_xaui_init(struct net_device *dev);
119extern void cvm_oct_xaui_uninit(struct net_device *dev); 125extern void cvm_oct_xaui_uninit(struct net_device *dev);
126extern int cvm_oct_xaui_open(struct net_device *dev);
127extern int cvm_oct_xaui_stop(struct net_device *dev);
128
129extern int cvm_oct_common_init(struct net_device *dev);
130extern void cvm_oct_common_uninit(struct net_device *dev);
120 131
121extern int always_use_pow; 132extern int always_use_pow;
122extern int pow_send_group; 133extern int pow_send_group;