blob: e80bfb60c3efb922a76149ce81b9a120c60fe9ce [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Ralf Baechlef90fdc32006-02-08 23:23:26 +00002 * Copyright (C) 2001,2002,2003,2004 Broadcom Corporation
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01003 * Copyright (c) 2006, 2007 Maciej W. Rozycki
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Ralf Baechle74b02472005-10-19 15:40:02 +010014 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *
19 *
20 * This driver is designed for the Broadcom SiByte SOC built-in
21 * Ethernet controllers. Written by Mitch Lichtenberg at Broadcom Corp.
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +010022 *
23 * Updated to the driver model and the PHY abstraction layer
24 * by Maciej W. Rozycki.
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +010026
27#include <linux/bug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/module.h>
29#include <linux/kernel.h>
30#include <linux/string.h>
31#include <linux/timer.h>
32#include <linux/errno.h>
33#include <linux/ioport.h>
34#include <linux/slab.h>
35#include <linux/interrupt.h>
36#include <linux/netdevice.h>
37#include <linux/etherdevice.h>
38#include <linux/skbuff.h>
39#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/bitops.h>
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +010041#include <linux/err.h>
42#include <linux/ethtool.h>
43#include <linux/mii.h>
44#include <linux/phy.h>
45#include <linux/platform_device.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040046#include <linux/prefetch.h>
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +010047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <asm/cache.h>
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +010049#include <asm/io.h>
50#include <asm/processor.h> /* Processor type for cache alignment. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Linus Torvalds1da177e2005-04-16 15:20:36 -070052/* Operational parameters that usually are not changed. */
53
54#define CONFIG_SBMAC_COALESCE
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056/* Time in jiffies before concluding the transmitter is hung. */
57#define TX_TIMEOUT (2*HZ)
58
59
60MODULE_AUTHOR("Mitch Lichtenberg (Broadcom Corp.)");
61MODULE_DESCRIPTION("Broadcom SiByte SOC GB Ethernet driver");
62
63/* A few user-configurable values which may be modified when a driver
64 module is loaded. */
65
66/* 1 normal messages, 0 quiet .. 7 verbose. */
67static int debug = 1;
68module_param(debug, int, S_IRUGO);
69MODULE_PARM_DESC(debug, "Debug messages");
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#ifdef CONFIG_SBMAC_COALESCE
Mark Mason693aa942007-04-26 00:23:22 -070072static int int_pktcnt_tx = 255;
73module_param(int_pktcnt_tx, int, S_IRUGO);
74MODULE_PARM_DESC(int_pktcnt_tx, "TX packet count");
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Mark Mason693aa942007-04-26 00:23:22 -070076static int int_timeout_tx = 255;
77module_param(int_timeout_tx, int, S_IRUGO);
78MODULE_PARM_DESC(int_timeout_tx, "TX timeout value");
79
80static int int_pktcnt_rx = 64;
81module_param(int_pktcnt_rx, int, S_IRUGO);
82MODULE_PARM_DESC(int_pktcnt_rx, "RX packet count");
83
84static int int_timeout_rx = 64;
85module_param(int_timeout_rx, int, S_IRUGO);
86MODULE_PARM_DESC(int_timeout_rx, "RX timeout value");
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#endif
88
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +010089#include <asm/sibyte/board.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070090#include <asm/sibyte/sb1250.h>
Ralf Baechlef90fdc32006-02-08 23:23:26 +000091#if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
92#include <asm/sibyte/bcm1480_regs.h>
93#include <asm/sibyte/bcm1480_int.h>
Mark Mason693aa942007-04-26 00:23:22 -070094#define R_MAC_DMA_OODPKTLOST_RX R_MAC_DMA_OODPKTLOST
Ralf Baechlef90fdc32006-02-08 23:23:26 +000095#elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#include <asm/sibyte/sb1250_regs.h>
Ralf Baechlef90fdc32006-02-08 23:23:26 +000097#include <asm/sibyte/sb1250_int.h>
98#else
Thomas Weber0b1974d2010-09-23 11:46:48 +020099#error invalid SiByte MAC configuration
Ralf Baechlef90fdc32006-02-08 23:23:26 +0000100#endif
101#include <asm/sibyte/sb1250_scd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#include <asm/sibyte/sb1250_mac.h>
103#include <asm/sibyte/sb1250_dma.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Ralf Baechlef90fdc32006-02-08 23:23:26 +0000105#if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
106#define UNIT_INT(n) (K_BCM1480_INT_MAC_0 + ((n) * 2))
107#elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X)
108#define UNIT_INT(n) (K_INT_MAC_0 + (n))
109#else
Thomas Weber0b1974d2010-09-23 11:46:48 +0200110#error invalid SiByte MAC configuration
Ralf Baechlef90fdc32006-02-08 23:23:26 +0000111#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100113#ifdef K_INT_PHY
114#define SBMAC_PHY_INT K_INT_PHY
115#else
116#define SBMAC_PHY_INT PHY_POLL
117#endif
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119/**********************************************************************
120 * Simple types
121 ********************************************************************* */
122
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100123enum sbmac_speed {
124 sbmac_speed_none = 0,
125 sbmac_speed_10 = SPEED_10,
126 sbmac_speed_100 = SPEED_100,
127 sbmac_speed_1000 = SPEED_1000,
128};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100130enum sbmac_duplex {
131 sbmac_duplex_none = -1,
132 sbmac_duplex_half = DUPLEX_HALF,
133 sbmac_duplex_full = DUPLEX_FULL,
134};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100136enum sbmac_fc {
137 sbmac_fc_none,
138 sbmac_fc_disabled,
139 sbmac_fc_frame,
140 sbmac_fc_collision,
141 sbmac_fc_carrier,
142};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100144enum sbmac_state {
145 sbmac_state_uninit,
146 sbmac_state_off,
147 sbmac_state_on,
148 sbmac_state_broken,
149};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151
152/**********************************************************************
153 * Macros
154 ********************************************************************* */
155
156
157#define SBDMA_NEXTBUF(d,f) ((((d)->f+1) == (d)->sbdma_dscrtable_end) ? \
158 (d)->sbdma_dscrtable : (d)->f+1)
159
160
161#define NUMCACHEBLKS(x) (((x)+SMP_CACHE_BYTES-1)/SMP_CACHE_BYTES)
162
Mark Mason693aa942007-04-26 00:23:22 -0700163#define SBMAC_MAX_TXDESCR 256
164#define SBMAC_MAX_RXDESCR 256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Ralf Baechle74b02472005-10-19 15:40:02 +0100166#define ENET_PACKET_SIZE 1518
167/*#define ENET_PACKET_SIZE 9216 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169/**********************************************************************
170 * DMA Descriptor structure
171 ********************************************************************* */
172
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100173struct sbdmadscr {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 uint64_t dscr_a;
175 uint64_t dscr_b;
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100176};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178/**********************************************************************
179 * DMA Controller structure
180 ********************************************************************* */
181
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100182struct sbmacdma {
Ralf Baechle74b02472005-10-19 15:40:02 +0100183
184 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 * This stuff is used to identify the channel and the registers
186 * associated with it.
187 */
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100188 struct sbmac_softc *sbdma_eth; /* back pointer to associated
189 MAC */
190 int sbdma_channel; /* channel number */
191 int sbdma_txdir; /* direction (1=transmit) */
192 int sbdma_maxdescr; /* total # of descriptors
193 in ring */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194#ifdef CONFIG_SBMAC_COALESCE
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100195 int sbdma_int_pktcnt;
196 /* # descriptors rx/tx
197 before interrupt */
198 int sbdma_int_timeout;
199 /* # usec rx/tx interrupt */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200#endif
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100201 void __iomem *sbdma_config0; /* DMA config register 0 */
202 void __iomem *sbdma_config1; /* DMA config register 1 */
203 void __iomem *sbdma_dscrbase;
204 /* descriptor base address */
205 void __iomem *sbdma_dscrcnt; /* descriptor count register */
206 void __iomem *sbdma_curdscr; /* current descriptor
207 address */
208 void __iomem *sbdma_oodpktlost;
209 /* pkt drop (rx only) */
Ralf Baechle74b02472005-10-19 15:40:02 +0100210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 /*
212 * This stuff is for maintenance of the ring
213 */
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100214 void *sbdma_dscrtable_unaligned;
215 struct sbdmadscr *sbdma_dscrtable;
216 /* base of descriptor table */
217 struct sbdmadscr *sbdma_dscrtable_end;
218 /* end of descriptor table */
219 struct sk_buff **sbdma_ctxtable;
220 /* context table, one
221 per descr */
222 dma_addr_t sbdma_dscrtable_phys;
223 /* and also the phys addr */
224 struct sbdmadscr *sbdma_addptr; /* next dscr for sw to add */
225 struct sbdmadscr *sbdma_remptr; /* next dscr for sw
226 to remove */
227};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229
230/**********************************************************************
231 * Ethernet softc structure
232 ********************************************************************* */
233
234struct sbmac_softc {
Ralf Baechle74b02472005-10-19 15:40:02 +0100235
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 /*
237 * Linux-specific things
238 */
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100239 struct net_device *sbm_dev; /* pointer to linux device */
240 struct napi_struct napi;
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100241 struct phy_device *phy_dev; /* the associated PHY device */
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700242 struct mii_bus *mii_bus; /* the MII bus */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100243 int phy_irq[PHY_MAX_ADDR];
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100244 spinlock_t sbm_lock; /* spin lock */
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100245 int sbm_devflags; /* current device flags */
Ralf Baechle74b02472005-10-19 15:40:02 +0100246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 /*
248 * Controller-specific things
249 */
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100250 void __iomem *sbm_base; /* MAC's base address */
251 enum sbmac_state sbm_state; /* current state */
Ralf Baechle74b02472005-10-19 15:40:02 +0100252
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100253 void __iomem *sbm_macenable; /* MAC Enable Register */
254 void __iomem *sbm_maccfg; /* MAC Config Register */
255 void __iomem *sbm_fifocfg; /* FIFO Config Register */
256 void __iomem *sbm_framecfg; /* Frame Config Register */
257 void __iomem *sbm_rxfilter; /* Receive Filter Register */
258 void __iomem *sbm_isr; /* Interrupt Status Register */
259 void __iomem *sbm_imr; /* Interrupt Mask Register */
260 void __iomem *sbm_mdio; /* MDIO Register */
Ralf Baechle74b02472005-10-19 15:40:02 +0100261
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100262 enum sbmac_speed sbm_speed; /* current speed */
263 enum sbmac_duplex sbm_duplex; /* current duplex */
264 enum sbmac_fc sbm_fc; /* cur. flow control setting */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100265 int sbm_pause; /* current pause setting */
266 int sbm_link; /* current link state */
Ralf Baechle74b02472005-10-19 15:40:02 +0100267
Joe Perches104bf3f2011-11-16 09:38:03 +0000268 unsigned char sbm_hwaddr[ETH_ALEN];
Ralf Baechle74b02472005-10-19 15:40:02 +0100269
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100270 struct sbmacdma sbm_txdma; /* only channel 0 for now */
271 struct sbmacdma sbm_rxdma;
272 int rx_hw_checksum;
273 int sbe_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274};
275
276
277/**********************************************************************
278 * Externs
279 ********************************************************************* */
280
281/**********************************************************************
282 * Prototypes
283 ********************************************************************* */
284
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100285static void sbdma_initctx(struct sbmacdma *d, struct sbmac_softc *s, int chan,
286 int txrx, int maxdescr);
287static void sbdma_channel_start(struct sbmacdma *d, int rxtx);
Stephen Hemminger789585e2008-05-18 04:45:09 +0100288static int sbdma_add_rcvbuffer(struct sbmac_softc *sc, struct sbmacdma *d,
289 struct sk_buff *m);
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100290static int sbdma_add_txbuffer(struct sbmacdma *d, struct sk_buff *m);
291static void sbdma_emptyring(struct sbmacdma *d);
Stephen Hemminger789585e2008-05-18 04:45:09 +0100292static void sbdma_fillring(struct sbmac_softc *sc, struct sbmacdma *d);
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100293static int sbdma_rx_process(struct sbmac_softc *sc, struct sbmacdma *d,
294 int work_to_do, int poll);
295static void sbdma_tx_process(struct sbmac_softc *sc, struct sbmacdma *d,
296 int poll);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297static int sbmac_initctx(struct sbmac_softc *s);
298static void sbmac_channel_start(struct sbmac_softc *s);
299static void sbmac_channel_stop(struct sbmac_softc *s);
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100300static enum sbmac_state sbmac_set_channel_state(struct sbmac_softc *,
301 enum sbmac_state);
302static void sbmac_promiscuous_mode(struct sbmac_softc *sc, int onoff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303static uint64_t sbmac_addr2reg(unsigned char *ptr);
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100304static irqreturn_t sbmac_intr(int irq, void *dev_instance);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305static int sbmac_start_tx(struct sk_buff *skb, struct net_device *dev);
306static void sbmac_setmulti(struct sbmac_softc *sc);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100307static int sbmac_init(struct platform_device *pldev, long long base);
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100308static int sbmac_set_speed(struct sbmac_softc *s, enum sbmac_speed speed);
309static int sbmac_set_duplex(struct sbmac_softc *s, enum sbmac_duplex duplex,
310 enum sbmac_fc fc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
312static int sbmac_open(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313static void sbmac_tx_timeout (struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314static void sbmac_set_rx_mode(struct net_device *dev);
315static int sbmac_mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
316static int sbmac_close(struct net_device *dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700317static int sbmac_poll(struct napi_struct *napi, int budget);
Mark Mason693aa942007-04-26 00:23:22 -0700318
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100319static void sbmac_mii_poll(struct net_device *dev);
Ralf Baechle59b81822005-10-20 12:01:28 +0100320static int sbmac_mii_probe(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100322static void sbmac_mii_sync(void __iomem *sbm_mdio);
323static void sbmac_mii_senddata(void __iomem *sbm_mdio, unsigned int data,
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100324 int bitcnt);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100325static int sbmac_mii_read(struct mii_bus *bus, int phyaddr, int regidx);
326static int sbmac_mii_write(struct mii_bus *bus, int phyaddr, int regidx,
327 u16 val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329
330/**********************************************************************
331 * Globals
332 ********************************************************************* */
333
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100334static char sbmac_string[] = "sb1250-mac";
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100335
336static char sbmac_mdio_string[] = "sb1250-mac-mdio";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
338
339/**********************************************************************
340 * MDIO constants
341 ********************************************************************* */
342
343#define MII_COMMAND_START 0x01
344#define MII_COMMAND_READ 0x02
345#define MII_COMMAND_WRITE 0x01
346#define MII_COMMAND_ACK 0x02
347
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348#define M_MAC_MDIO_DIR_OUTPUT 0 /* for clarity */
349
350#define ENABLE 1
351#define DISABLE 0
352
353/**********************************************************************
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100354 * SBMAC_MII_SYNC(sbm_mdio)
Ralf Baechle74b02472005-10-19 15:40:02 +0100355 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 * Synchronize with the MII - send a pattern of bits to the MII
357 * that will guarantee that it is ready to accept a command.
Ralf Baechle74b02472005-10-19 15:40:02 +0100358 *
359 * Input parameters:
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100360 * sbm_mdio - address of the MAC's MDIO register
Ralf Baechle74b02472005-10-19 15:40:02 +0100361 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 * Return value:
363 * nothing
364 ********************************************************************* */
365
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100366static void sbmac_mii_sync(void __iomem *sbm_mdio)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367{
368 int cnt;
369 uint64_t bits;
370 int mac_mdio_genc;
371
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100372 mac_mdio_genc = __raw_readq(sbm_mdio) & M_MAC_GENC;
Ralf Baechle74b02472005-10-19 15:40:02 +0100373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 bits = M_MAC_MDIO_DIR_OUTPUT | M_MAC_MDIO_OUT;
Ralf Baechle74b02472005-10-19 15:40:02 +0100375
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100376 __raw_writeq(bits | mac_mdio_genc, sbm_mdio);
Ralf Baechle74b02472005-10-19 15:40:02 +0100377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 for (cnt = 0; cnt < 32; cnt++) {
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100379 __raw_writeq(bits | M_MAC_MDC | mac_mdio_genc, sbm_mdio);
380 __raw_writeq(bits | mac_mdio_genc, sbm_mdio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 }
382}
383
384/**********************************************************************
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100385 * SBMAC_MII_SENDDATA(sbm_mdio, data, bitcnt)
Ralf Baechle74b02472005-10-19 15:40:02 +0100386 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 * Send some bits to the MII. The bits to be sent are right-
388 * justified in the 'data' parameter.
Ralf Baechle74b02472005-10-19 15:40:02 +0100389 *
390 * Input parameters:
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100391 * sbm_mdio - address of the MAC's MDIO register
392 * data - data to send
393 * bitcnt - number of bits to send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 ********************************************************************* */
395
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100396static void sbmac_mii_senddata(void __iomem *sbm_mdio, unsigned int data,
397 int bitcnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
399 int i;
400 uint64_t bits;
401 unsigned int curmask;
402 int mac_mdio_genc;
403
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100404 mac_mdio_genc = __raw_readq(sbm_mdio) & M_MAC_GENC;
Ralf Baechle74b02472005-10-19 15:40:02 +0100405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 bits = M_MAC_MDIO_DIR_OUTPUT;
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100407 __raw_writeq(bits | mac_mdio_genc, sbm_mdio);
Ralf Baechle74b02472005-10-19 15:40:02 +0100408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 curmask = 1 << (bitcnt - 1);
Ralf Baechle74b02472005-10-19 15:40:02 +0100410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 for (i = 0; i < bitcnt; i++) {
412 if (data & curmask)
413 bits |= M_MAC_MDIO_OUT;
414 else bits &= ~M_MAC_MDIO_OUT;
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100415 __raw_writeq(bits | mac_mdio_genc, sbm_mdio);
416 __raw_writeq(bits | M_MAC_MDC | mac_mdio_genc, sbm_mdio);
417 __raw_writeq(bits | mac_mdio_genc, sbm_mdio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 curmask >>= 1;
419 }
420}
421
422
423
424/**********************************************************************
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100425 * SBMAC_MII_READ(bus, phyaddr, regidx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 * Read a PHY register.
Ralf Baechle74b02472005-10-19 15:40:02 +0100427 *
428 * Input parameters:
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100429 * bus - MDIO bus handle
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 * phyaddr - PHY's address
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100431 * regnum - index of register to read
Ralf Baechle74b02472005-10-19 15:40:02 +0100432 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 * Return value:
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100434 * value read, or 0xffff if an error occurred.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 ********************************************************************* */
436
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100437static int sbmac_mii_read(struct mii_bus *bus, int phyaddr, int regidx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100439 struct sbmac_softc *sc = (struct sbmac_softc *)bus->priv;
440 void __iomem *sbm_mdio = sc->sbm_mdio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 int idx;
442 int error;
443 int regval;
444 int mac_mdio_genc;
445
446 /*
447 * Synchronize ourselves so that the PHY knows the next
448 * thing coming down is a command
449 */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100450 sbmac_mii_sync(sbm_mdio);
Ralf Baechle74b02472005-10-19 15:40:02 +0100451
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 /*
453 * Send the data to the PHY. The sequence is
454 * a "start" command (2 bits)
455 * a "read" command (2 bits)
456 * the PHY addr (5 bits)
457 * the register index (5 bits)
458 */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100459 sbmac_mii_senddata(sbm_mdio, MII_COMMAND_START, 2);
460 sbmac_mii_senddata(sbm_mdio, MII_COMMAND_READ, 2);
461 sbmac_mii_senddata(sbm_mdio, phyaddr, 5);
462 sbmac_mii_senddata(sbm_mdio, regidx, 5);
Ralf Baechle74b02472005-10-19 15:40:02 +0100463
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100464 mac_mdio_genc = __raw_readq(sbm_mdio) & M_MAC_GENC;
Ralf Baechle74b02472005-10-19 15:40:02 +0100465
466 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 * Switch the port around without a clock transition.
468 */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100469 __raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, sbm_mdio);
Ralf Baechle74b02472005-10-19 15:40:02 +0100470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 /*
472 * Send out a clock pulse to signal we want the status
473 */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100474 __raw_writeq(M_MAC_MDIO_DIR_INPUT | M_MAC_MDC | mac_mdio_genc,
475 sbm_mdio);
476 __raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, sbm_mdio);
Ralf Baechle74b02472005-10-19 15:40:02 +0100477
478 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 * If an error occurred, the PHY will signal '1' back
480 */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100481 error = __raw_readq(sbm_mdio) & M_MAC_MDIO_IN;
Ralf Baechle74b02472005-10-19 15:40:02 +0100482
483 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 * Issue an 'idle' clock pulse, but keep the direction
485 * the same.
486 */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100487 __raw_writeq(M_MAC_MDIO_DIR_INPUT | M_MAC_MDC | mac_mdio_genc,
488 sbm_mdio);
489 __raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, sbm_mdio);
Ralf Baechle74b02472005-10-19 15:40:02 +0100490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 regval = 0;
Ralf Baechle74b02472005-10-19 15:40:02 +0100492
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 for (idx = 0; idx < 16; idx++) {
494 regval <<= 1;
Ralf Baechle74b02472005-10-19 15:40:02 +0100495
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 if (error == 0) {
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100497 if (__raw_readq(sbm_mdio) & M_MAC_MDIO_IN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 regval |= 1;
499 }
Ralf Baechle74b02472005-10-19 15:40:02 +0100500
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100501 __raw_writeq(M_MAC_MDIO_DIR_INPUT | M_MAC_MDC | mac_mdio_genc,
502 sbm_mdio);
503 __raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, sbm_mdio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 }
Ralf Baechle74b02472005-10-19 15:40:02 +0100505
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 /* Switch back to output */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100507 __raw_writeq(M_MAC_MDIO_DIR_OUTPUT | mac_mdio_genc, sbm_mdio);
Ralf Baechle74b02472005-10-19 15:40:02 +0100508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 if (error == 0)
510 return regval;
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100511 return 0xffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512}
513
514
515/**********************************************************************
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100516 * SBMAC_MII_WRITE(bus, phyaddr, regidx, regval)
Ralf Baechle74b02472005-10-19 15:40:02 +0100517 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 * Write a value to a PHY register.
Ralf Baechle74b02472005-10-19 15:40:02 +0100519 *
520 * Input parameters:
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100521 * bus - MDIO bus handle
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 * phyaddr - PHY to use
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100523 * regidx - register within the PHY
524 * regval - data to write to register
Ralf Baechle74b02472005-10-19 15:40:02 +0100525 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 * Return value:
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100527 * 0 for success
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 ********************************************************************* */
529
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100530static int sbmac_mii_write(struct mii_bus *bus, int phyaddr, int regidx,
531 u16 regval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532{
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100533 struct sbmac_softc *sc = (struct sbmac_softc *)bus->priv;
534 void __iomem *sbm_mdio = sc->sbm_mdio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 int mac_mdio_genc;
536
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100537 sbmac_mii_sync(sbm_mdio);
Ralf Baechle74b02472005-10-19 15:40:02 +0100538
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100539 sbmac_mii_senddata(sbm_mdio, MII_COMMAND_START, 2);
540 sbmac_mii_senddata(sbm_mdio, MII_COMMAND_WRITE, 2);
541 sbmac_mii_senddata(sbm_mdio, phyaddr, 5);
542 sbmac_mii_senddata(sbm_mdio, regidx, 5);
543 sbmac_mii_senddata(sbm_mdio, MII_COMMAND_ACK, 2);
544 sbmac_mii_senddata(sbm_mdio, regval, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100546 mac_mdio_genc = __raw_readq(sbm_mdio) & M_MAC_GENC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100548 __raw_writeq(M_MAC_MDIO_DIR_OUTPUT | mac_mdio_genc, sbm_mdio);
549
550 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551}
552
553
554
555/**********************************************************************
556 * SBDMA_INITCTX(d,s,chan,txrx,maxdescr)
Ralf Baechle74b02472005-10-19 15:40:02 +0100557 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 * Initialize a DMA channel context. Since there are potentially
559 * eight DMA channels per MAC, it's nice to do this in a standard
Ralf Baechle74b02472005-10-19 15:40:02 +0100560 * way.
561 *
562 * Input parameters:
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100563 * d - struct sbmacdma (DMA channel context)
564 * s - struct sbmac_softc (pointer to a MAC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 * chan - channel number (0..1 right now)
566 * txrx - Identifies DMA_TX or DMA_RX for channel direction
567 * maxdescr - number of descriptors
Ralf Baechle74b02472005-10-19 15:40:02 +0100568 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 * Return value:
570 * nothing
571 ********************************************************************* */
572
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100573static void sbdma_initctx(struct sbmacdma *d, struct sbmac_softc *s, int chan,
574 int txrx, int maxdescr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575{
Mark Mason693aa942007-04-26 00:23:22 -0700576#ifdef CONFIG_SBMAC_COALESCE
577 int int_pktcnt, int_timeout;
578#endif
579
Ralf Baechle74b02472005-10-19 15:40:02 +0100580 /*
581 * Save away interesting stuff in the structure
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100583
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 d->sbdma_eth = s;
585 d->sbdma_channel = chan;
586 d->sbdma_txdir = txrx;
Ralf Baechle74b02472005-10-19 15:40:02 +0100587
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588#if 0
589 /* RMON clearing */
590 s->sbe_idx =(s->sbm_base - A_MAC_BASE_0)/MAC_SPACING;
591#endif
592
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100593 __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_BYTES);
594 __raw_writeq(0, s->sbm_base + R_MAC_RMON_COLLISIONS);
595 __raw_writeq(0, s->sbm_base + R_MAC_RMON_LATE_COL);
596 __raw_writeq(0, s->sbm_base + R_MAC_RMON_EX_COL);
597 __raw_writeq(0, s->sbm_base + R_MAC_RMON_FCS_ERROR);
598 __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_ABORT);
599 __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_BAD);
600 __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_GOOD);
601 __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_RUNT);
602 __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_OVERSIZE);
603 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_BYTES);
604 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_MCAST);
605 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_BCAST);
606 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_BAD);
607 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_GOOD);
608 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_RUNT);
609 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_OVERSIZE);
610 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_FCS_ERROR);
611 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_LENGTH_ERROR);
612 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_CODE_ERROR);
613 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_ALIGN_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
Ralf Baechle74b02472005-10-19 15:40:02 +0100615 /*
616 * initialize register pointers
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100618
619 d->sbdma_config0 =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CONFIG0);
Ralf Baechle74b02472005-10-19 15:40:02 +0100621 d->sbdma_config1 =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CONFIG1);
Ralf Baechle74b02472005-10-19 15:40:02 +0100623 d->sbdma_dscrbase =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_DSCR_BASE);
Ralf Baechle74b02472005-10-19 15:40:02 +0100625 d->sbdma_dscrcnt =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_DSCR_CNT);
Ralf Baechle74b02472005-10-19 15:40:02 +0100627 d->sbdma_curdscr =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CUR_DSCRADDR);
Mark Mason693aa942007-04-26 00:23:22 -0700629 if (d->sbdma_txdir)
630 d->sbdma_oodpktlost = NULL;
631 else
632 d->sbdma_oodpktlost =
633 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_OODPKTLOST_RX);
Ralf Baechle74b02472005-10-19 15:40:02 +0100634
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 /*
636 * Allocate memory for the ring
637 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100638
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 d->sbdma_maxdescr = maxdescr;
Ralf Baechle74b02472005-10-19 15:40:02 +0100640
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100641 d->sbdma_dscrtable_unaligned = kcalloc(d->sbdma_maxdescr + 1,
642 sizeof(*d->sbdma_dscrtable),
643 GFP_KERNEL);
Ralf Baechle04115de2005-10-10 14:50:36 +0100644
645 /*
646 * The descriptor table must be aligned to at least 16 bytes or the
647 * MAC will corrupt it.
648 */
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100649 d->sbdma_dscrtable = (struct sbdmadscr *)
650 ALIGN((unsigned long)d->sbdma_dscrtable_unaligned,
651 sizeof(*d->sbdma_dscrtable));
Ralf Baechle74b02472005-10-19 15:40:02 +0100652
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 d->sbdma_dscrtable_end = d->sbdma_dscrtable + d->sbdma_maxdescr;
Ralf Baechle74b02472005-10-19 15:40:02 +0100654
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 d->sbdma_dscrtable_phys = virt_to_phys(d->sbdma_dscrtable);
Ralf Baechle74b02472005-10-19 15:40:02 +0100656
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 /*
658 * And context table
659 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100660
Mariusz Kozlowskic477f332007-07-31 23:58:36 +0200661 d->sbdma_ctxtable = kcalloc(d->sbdma_maxdescr,
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100662 sizeof(*d->sbdma_ctxtable), GFP_KERNEL);
Ralf Baechle74b02472005-10-19 15:40:02 +0100663
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664#ifdef CONFIG_SBMAC_COALESCE
665 /*
666 * Setup Rx/Tx DMA coalescing defaults
667 */
668
Mark Mason693aa942007-04-26 00:23:22 -0700669 int_pktcnt = (txrx == DMA_TX) ? int_pktcnt_tx : int_pktcnt_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 if ( int_pktcnt ) {
671 d->sbdma_int_pktcnt = int_pktcnt;
672 } else {
673 d->sbdma_int_pktcnt = 1;
674 }
Ralf Baechle74b02472005-10-19 15:40:02 +0100675
Mark Mason693aa942007-04-26 00:23:22 -0700676 int_timeout = (txrx == DMA_TX) ? int_timeout_tx : int_timeout_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 if ( int_timeout ) {
678 d->sbdma_int_timeout = int_timeout;
679 } else {
680 d->sbdma_int_timeout = 0;
681 }
682#endif
683
684}
685
686/**********************************************************************
687 * SBDMA_CHANNEL_START(d)
Ralf Baechle74b02472005-10-19 15:40:02 +0100688 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 * Initialize the hardware registers for a DMA channel.
Ralf Baechle74b02472005-10-19 15:40:02 +0100690 *
691 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 * d - DMA channel to init (context must be previously init'd
693 * rxtx - DMA_RX or DMA_TX depending on what type of channel
Ralf Baechle74b02472005-10-19 15:40:02 +0100694 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 * Return value:
696 * nothing
697 ********************************************************************* */
698
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100699static void sbdma_channel_start(struct sbmacdma *d, int rxtx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700{
701 /*
702 * Turn on the DMA channel
703 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100704
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705#ifdef CONFIG_SBMAC_COALESCE
Ralf Baechle20399732005-10-19 15:39:05 +0100706 __raw_writeq(V_DMA_INT_TIMEOUT(d->sbdma_int_timeout) |
707 0, d->sbdma_config1);
708 __raw_writeq(M_DMA_EOP_INT_EN |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 V_DMA_RINGSZ(d->sbdma_maxdescr) |
710 V_DMA_INT_PKTCNT(d->sbdma_int_pktcnt) |
Ralf Baechle20399732005-10-19 15:39:05 +0100711 0, d->sbdma_config0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712#else
Ralf Baechle20399732005-10-19 15:39:05 +0100713 __raw_writeq(0, d->sbdma_config1);
714 __raw_writeq(V_DMA_RINGSZ(d->sbdma_maxdescr) |
715 0, d->sbdma_config0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716#endif
717
Ralf Baechle20399732005-10-19 15:39:05 +0100718 __raw_writeq(d->sbdma_dscrtable_phys, d->sbdma_dscrbase);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
720 /*
721 * Initialize ring pointers
722 */
723
724 d->sbdma_addptr = d->sbdma_dscrtable;
725 d->sbdma_remptr = d->sbdma_dscrtable;
726}
727
728/**********************************************************************
729 * SBDMA_CHANNEL_STOP(d)
Ralf Baechle74b02472005-10-19 15:40:02 +0100730 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 * Initialize the hardware registers for a DMA channel.
Ralf Baechle74b02472005-10-19 15:40:02 +0100732 *
733 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 * d - DMA channel to init (context must be previously init'd
Ralf Baechle74b02472005-10-19 15:40:02 +0100735 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 * Return value:
737 * nothing
738 ********************************************************************* */
739
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100740static void sbdma_channel_stop(struct sbmacdma *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741{
742 /*
743 * Turn off the DMA channel
744 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100745
Ralf Baechle20399732005-10-19 15:39:05 +0100746 __raw_writeq(0, d->sbdma_config1);
Ralf Baechle74b02472005-10-19 15:40:02 +0100747
Ralf Baechle20399732005-10-19 15:39:05 +0100748 __raw_writeq(0, d->sbdma_dscrbase);
Ralf Baechle74b02472005-10-19 15:40:02 +0100749
Ralf Baechle20399732005-10-19 15:39:05 +0100750 __raw_writeq(0, d->sbdma_config0);
Ralf Baechle74b02472005-10-19 15:40:02 +0100751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 /*
753 * Zero ring pointers
754 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100755
Ralf Baechle20399732005-10-19 15:39:05 +0100756 d->sbdma_addptr = NULL;
757 d->sbdma_remptr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758}
759
Stephen Hemminger789585e2008-05-18 04:45:09 +0100760static inline void sbdma_align_skb(struct sk_buff *skb,
761 unsigned int power2, unsigned int offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762{
Stephen Hemminger789585e2008-05-18 04:45:09 +0100763 unsigned char *addr = skb->data;
764 unsigned char *newaddr = PTR_ALIGN(addr, power2);
Ralf Baechle74b02472005-10-19 15:40:02 +0100765
Stephen Hemminger789585e2008-05-18 04:45:09 +0100766 skb_reserve(skb, newaddr - addr + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767}
768
769
770/**********************************************************************
771 * SBDMA_ADD_RCVBUFFER(d,sb)
Ralf Baechle74b02472005-10-19 15:40:02 +0100772 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 * Add a buffer to the specified DMA channel. For receive channels,
774 * this queues a buffer for inbound packets.
Ralf Baechle74b02472005-10-19 15:40:02 +0100775 *
776 * Input parameters:
Stephen Hemminger789585e2008-05-18 04:45:09 +0100777 * sc - softc structure
778 * d - DMA channel descriptor
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 * sb - sk_buff to add, or NULL if we should allocate one
Ralf Baechle74b02472005-10-19 15:40:02 +0100780 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 * Return value:
782 * 0 if buffer could not be added (ring is full)
783 * 1 if buffer added successfully
784 ********************************************************************* */
785
786
Stephen Hemminger789585e2008-05-18 04:45:09 +0100787static int sbdma_add_rcvbuffer(struct sbmac_softc *sc, struct sbmacdma *d,
788 struct sk_buff *sb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789{
Stephen Hemminger789585e2008-05-18 04:45:09 +0100790 struct net_device *dev = sc->sbm_dev;
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100791 struct sbdmadscr *dsc;
792 struct sbdmadscr *nextdsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 struct sk_buff *sb_new = NULL;
794 int pktsize = ENET_PACKET_SIZE;
Ralf Baechle74b02472005-10-19 15:40:02 +0100795
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 /* get pointer to our current place in the ring */
Ralf Baechle74b02472005-10-19 15:40:02 +0100797
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 dsc = d->sbdma_addptr;
799 nextdsc = SBDMA_NEXTBUF(d,sbdma_addptr);
Ralf Baechle74b02472005-10-19 15:40:02 +0100800
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 /*
802 * figure out if the ring is full - if the next descriptor
803 * is the same as the one that we're going to remove from
804 * the ring, the ring is full
805 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100806
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 if (nextdsc == d->sbdma_remptr) {
808 return -ENOSPC;
809 }
810
Ralf Baechle74b02472005-10-19 15:40:02 +0100811 /*
812 * Allocate a sk_buff if we don't already have one.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 * If we do have an sk_buff, reset it so that it's empty.
814 *
815 * Note: sk_buffs don't seem to be guaranteed to have any sort
816 * of alignment when they are allocated. Therefore, allocate enough
817 * extra space to make sure that:
818 *
819 * 1. the data does not start in the middle of a cache line.
820 * 2. The data does not end in the middle of a cache line
Ralf Baechle74b02472005-10-19 15:40:02 +0100821 * 3. The buffer can be aligned such that the IP addresses are
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 * naturally aligned.
823 *
824 * Remember, the SOCs MAC writes whole cache lines at a time,
825 * without reading the old contents first. So, if the sk_buff's
826 * data portion starts in the middle of a cache line, the SOC
827 * DMA will trash the beginning (and ending) portions.
828 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100829
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 if (sb == NULL) {
Stephen Hemminger789585e2008-05-18 04:45:09 +0100831 sb_new = netdev_alloc_skb(dev, ENET_PACKET_SIZE +
832 SMP_CACHE_BYTES * 2 +
833 NET_IP_ALIGN);
Joe Perches720a43e2013-03-08 15:03:25 +0000834 if (sb_new == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 return -ENOBUFS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
Stephen Hemminger789585e2008-05-18 04:45:09 +0100837 sbdma_align_skb(sb_new, SMP_CACHE_BYTES, NET_IP_ALIGN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 }
839 else {
840 sb_new = sb;
Ralf Baechle74b02472005-10-19 15:40:02 +0100841 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 * nothing special to reinit buffer, it's already aligned
843 * and sb->data already points to a good place.
844 */
845 }
Ralf Baechle74b02472005-10-19 15:40:02 +0100846
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 /*
Ralf Baechle74b02472005-10-19 15:40:02 +0100848 * fill in the descriptor
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100850
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851#ifdef CONFIG_SBMAC_COALESCE
852 /*
853 * Do not interrupt per DMA transfer.
854 */
David S. Miller689be432005-06-28 15:25:31 -0700855 dsc->dscr_a = virt_to_phys(sb_new->data) |
Stephen Hemminger789585e2008-05-18 04:45:09 +0100856 V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize + NET_IP_ALIGN)) | 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857#else
David S. Miller689be432005-06-28 15:25:31 -0700858 dsc->dscr_a = virt_to_phys(sb_new->data) |
Stephen Hemminger789585e2008-05-18 04:45:09 +0100859 V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize + NET_IP_ALIGN)) |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 M_DMA_DSCRA_INTERRUPT;
861#endif
862
863 /* receiving: no options */
864 dsc->dscr_b = 0;
Ralf Baechle74b02472005-10-19 15:40:02 +0100865
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 /*
Ralf Baechle74b02472005-10-19 15:40:02 +0100867 * fill in the context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100869
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 d->sbdma_ctxtable[dsc-d->sbdma_dscrtable] = sb_new;
Ralf Baechle74b02472005-10-19 15:40:02 +0100871
872 /*
873 * point at next packet
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 d->sbdma_addptr = nextdsc;
Ralf Baechle74b02472005-10-19 15:40:02 +0100877
878 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 * Give the buffer to the DMA engine.
880 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100881
Ralf Baechle20399732005-10-19 15:39:05 +0100882 __raw_writeq(1, d->sbdma_dscrcnt);
Ralf Baechle74b02472005-10-19 15:40:02 +0100883
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 return 0; /* we did it */
885}
886
887/**********************************************************************
888 * SBDMA_ADD_TXBUFFER(d,sb)
Ralf Baechle74b02472005-10-19 15:40:02 +0100889 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 * Add a transmit buffer to the specified DMA channel, causing a
891 * transmit to start.
Ralf Baechle74b02472005-10-19 15:40:02 +0100892 *
893 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 * d - DMA channel descriptor
895 * sb - sk_buff to add
Ralf Baechle74b02472005-10-19 15:40:02 +0100896 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 * Return value:
898 * 0 transmit queued successfully
899 * otherwise error code
900 ********************************************************************* */
901
902
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100903static int sbdma_add_txbuffer(struct sbmacdma *d, struct sk_buff *sb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904{
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100905 struct sbdmadscr *dsc;
906 struct sbdmadscr *nextdsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 uint64_t phys;
908 uint64_t ncb;
909 int length;
Ralf Baechle74b02472005-10-19 15:40:02 +0100910
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 /* get pointer to our current place in the ring */
Ralf Baechle74b02472005-10-19 15:40:02 +0100912
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 dsc = d->sbdma_addptr;
914 nextdsc = SBDMA_NEXTBUF(d,sbdma_addptr);
Ralf Baechle74b02472005-10-19 15:40:02 +0100915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 /*
917 * figure out if the ring is full - if the next descriptor
918 * is the same as the one that we're going to remove from
919 * the ring, the ring is full
920 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100921
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 if (nextdsc == d->sbdma_remptr) {
923 return -ENOSPC;
924 }
Ralf Baechle74b02472005-10-19 15:40:02 +0100925
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 /*
927 * Under Linux, it's not necessary to copy/coalesce buffers
928 * like it is on NetBSD. We think they're all contiguous,
929 * but that may not be true for GBE.
930 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100931
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 length = sb->len;
Ralf Baechle74b02472005-10-19 15:40:02 +0100933
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 /*
935 * fill in the descriptor. Note that the number of cache
936 * blocks in the descriptor is the number of blocks
937 * *spanned*, so we need to add in the offset (if any)
938 * while doing the calculation.
939 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100940
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 phys = virt_to_phys(sb->data);
942 ncb = NUMCACHEBLKS(length+(phys & (SMP_CACHE_BYTES - 1)));
943
Ralf Baechle74b02472005-10-19 15:40:02 +0100944 dsc->dscr_a = phys |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 V_DMA_DSCRA_A_SIZE(ncb) |
946#ifndef CONFIG_SBMAC_COALESCE
947 M_DMA_DSCRA_INTERRUPT |
948#endif
949 M_DMA_ETHTX_SOP;
Ralf Baechle74b02472005-10-19 15:40:02 +0100950
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 /* transmitting: set outbound options and length */
952
953 dsc->dscr_b = V_DMA_DSCRB_OPTIONS(K_DMA_ETHTX_APPENDCRC_APPENDPAD) |
954 V_DMA_DSCRB_PKT_SIZE(length);
Ralf Baechle74b02472005-10-19 15:40:02 +0100955
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 /*
Ralf Baechle74b02472005-10-19 15:40:02 +0100957 * fill in the context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100959
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 d->sbdma_ctxtable[dsc-d->sbdma_dscrtable] = sb;
Ralf Baechle74b02472005-10-19 15:40:02 +0100961
962 /*
963 * point at next packet
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100965
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 d->sbdma_addptr = nextdsc;
Ralf Baechle74b02472005-10-19 15:40:02 +0100967
968 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 * Give the buffer to the DMA engine.
970 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100971
Ralf Baechle20399732005-10-19 15:39:05 +0100972 __raw_writeq(1, d->sbdma_dscrcnt);
Ralf Baechle74b02472005-10-19 15:40:02 +0100973
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 return 0; /* we did it */
975}
976
977
978
979
980/**********************************************************************
981 * SBDMA_EMPTYRING(d)
Ralf Baechle74b02472005-10-19 15:40:02 +0100982 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 * Free all allocated sk_buffs on the specified DMA channel;
Ralf Baechle74b02472005-10-19 15:40:02 +0100984 *
985 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 * d - DMA channel
Ralf Baechle74b02472005-10-19 15:40:02 +0100987 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 * Return value:
989 * nothing
990 ********************************************************************* */
991
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100992static void sbdma_emptyring(struct sbmacdma *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993{
994 int idx;
995 struct sk_buff *sb;
Ralf Baechle74b02472005-10-19 15:40:02 +0100996
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 for (idx = 0; idx < d->sbdma_maxdescr; idx++) {
998 sb = d->sbdma_ctxtable[idx];
999 if (sb) {
1000 dev_kfree_skb(sb);
1001 d->sbdma_ctxtable[idx] = NULL;
1002 }
1003 }
1004}
1005
1006
1007/**********************************************************************
1008 * SBDMA_FILLRING(d)
Ralf Baechle74b02472005-10-19 15:40:02 +01001009 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 * Fill the specified DMA channel (must be receive channel)
1011 * with sk_buffs
Ralf Baechle74b02472005-10-19 15:40:02 +01001012 *
1013 * Input parameters:
Stephen Hemminger789585e2008-05-18 04:45:09 +01001014 * sc - softc structure
1015 * d - DMA channel
Ralf Baechle74b02472005-10-19 15:40:02 +01001016 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 * Return value:
1018 * nothing
1019 ********************************************************************* */
1020
Stephen Hemminger789585e2008-05-18 04:45:09 +01001021static void sbdma_fillring(struct sbmac_softc *sc, struct sbmacdma *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022{
1023 int idx;
Ralf Baechle74b02472005-10-19 15:40:02 +01001024
Stephen Hemminger789585e2008-05-18 04:45:09 +01001025 for (idx = 0; idx < SBMAC_MAX_RXDESCR - 1; idx++) {
1026 if (sbdma_add_rcvbuffer(sc, d, NULL) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 break;
1028 }
1029}
1030
Deepak Saxenad6830012007-03-19 15:43:11 -07001031#ifdef CONFIG_NET_POLL_CONTROLLER
1032static void sbmac_netpoll(struct net_device *netdev)
1033{
1034 struct sbmac_softc *sc = netdev_priv(netdev);
1035 int irq = sc->sbm_dev->irq;
1036
1037 __raw_writeq(0, sc->sbm_imr);
1038
Yoann Padioleau0da2f0f2007-07-06 02:39:56 -07001039 sbmac_intr(irq, netdev);
Deepak Saxenad6830012007-03-19 15:43:11 -07001040
1041#ifdef CONFIG_SBMAC_COALESCE
1042 __raw_writeq(((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_TX_CH0) |
1043 ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_RX_CH0),
1044 sc->sbm_imr);
1045#else
Jeff Garzik7d2e3cb2008-05-13 01:41:58 -04001046 __raw_writeq((M_MAC_INT_CHANNEL << S_MAC_TX_CH0) |
Deepak Saxenad6830012007-03-19 15:43:11 -07001047 (M_MAC_INT_CHANNEL << S_MAC_RX_CH0), sc->sbm_imr);
1048#endif
1049}
1050#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051
1052/**********************************************************************
Mark Mason693aa942007-04-26 00:23:22 -07001053 * SBDMA_RX_PROCESS(sc,d,work_to_do,poll)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 *
Ralf Baechle74b02472005-10-19 15:40:02 +01001055 * Process "completed" receive buffers on the specified DMA channel.
Ralf Baechle74b02472005-10-19 15:40:02 +01001056 *
1057 * Input parameters:
Mark Mason693aa942007-04-26 00:23:22 -07001058 * sc - softc structure
1059 * d - DMA channel context
1060 * work_to_do - no. of packets to process before enabling interrupt
1061 * again (for NAPI)
1062 * poll - 1: using polling (for NAPI)
Ralf Baechle74b02472005-10-19 15:40:02 +01001063 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 * Return value:
1065 * nothing
1066 ********************************************************************* */
1067
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001068static int sbdma_rx_process(struct sbmac_softc *sc, struct sbmacdma *d,
1069 int work_to_do, int poll)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070{
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001071 struct net_device *dev = sc->sbm_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 int curidx;
1073 int hwidx;
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001074 struct sbdmadscr *dsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 struct sk_buff *sb;
1076 int len;
Mark Mason693aa942007-04-26 00:23:22 -07001077 int work_done = 0;
1078 int dropped = 0;
Ralf Baechle74b02472005-10-19 15:40:02 +01001079
Mark Mason693aa942007-04-26 00:23:22 -07001080 prefetch(d);
1081
1082again:
1083 /* Check if the HW dropped any frames */
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001084 dev->stats.rx_fifo_errors
Mark Mason693aa942007-04-26 00:23:22 -07001085 += __raw_readq(sc->sbm_rxdma.sbdma_oodpktlost) & 0xffff;
1086 __raw_writeq(0, sc->sbm_rxdma.sbdma_oodpktlost);
1087
1088 while (work_to_do-- > 0) {
Ralf Baechle74b02472005-10-19 15:40:02 +01001089 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 * figure out where we are (as an index) and where
1091 * the hardware is (also as an index)
1092 *
Ralf Baechle74b02472005-10-19 15:40:02 +01001093 * This could be done faster if (for example) the
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 * descriptor table was page-aligned and contiguous in
1095 * both virtual and physical memory -- you could then
1096 * just compare the low-order bits of the virtual address
1097 * (sbdma_remptr) and the physical address (sbdma_curdscr CSR)
1098 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001099
Mark Mason693aa942007-04-26 00:23:22 -07001100 dsc = d->sbdma_remptr;
1101 curidx = dsc - d->sbdma_dscrtable;
1102
1103 prefetch(dsc);
1104 prefetch(&d->sbdma_ctxtable[curidx]);
1105
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001106 hwidx = ((__raw_readq(d->sbdma_curdscr) & M_DMA_CURDSCR_ADDR) -
1107 d->sbdma_dscrtable_phys) /
1108 sizeof(*d->sbdma_dscrtable);
Ralf Baechle74b02472005-10-19 15:40:02 +01001109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 /*
1111 * If they're the same, that means we've processed all
1112 * of the descriptors up to (but not including) the one that
1113 * the hardware is working on right now.
1114 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001115
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 if (curidx == hwidx)
Mark Mason693aa942007-04-26 00:23:22 -07001117 goto done;
Ralf Baechle74b02472005-10-19 15:40:02 +01001118
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 /*
1120 * Otherwise, get the packet's sk_buff ptr back
1121 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001122
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 sb = d->sbdma_ctxtable[curidx];
1124 d->sbdma_ctxtable[curidx] = NULL;
Ralf Baechle74b02472005-10-19 15:40:02 +01001125
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 len = (int)G_DMA_DSCRB_PKT_SIZE(dsc->dscr_b) - 4;
Ralf Baechle74b02472005-10-19 15:40:02 +01001127
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 /*
1129 * Check packet status. If good, process it.
1130 * If not, silently drop it and put it back on the
1131 * receive ring.
1132 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001133
Mark Mason693aa942007-04-26 00:23:22 -07001134 if (likely (!(dsc->dscr_a & M_DMA_ETHRX_BAD))) {
Ralf Baechle74b02472005-10-19 15:40:02 +01001135
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 /*
1137 * Add a new buffer to replace the old one. If we fail
1138 * to allocate a buffer, we're going to drop this
1139 * packet and put it right back on the receive ring.
1140 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001141
Stephen Hemminger789585e2008-05-18 04:45:09 +01001142 if (unlikely(sbdma_add_rcvbuffer(sc, d, NULL) ==
1143 -ENOBUFS)) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001144 dev->stats.rx_dropped++;
Stephen Hemminger789585e2008-05-18 04:45:09 +01001145 /* Re-add old buffer */
1146 sbdma_add_rcvbuffer(sc, d, sb);
Mark Mason693aa942007-04-26 00:23:22 -07001147 /* No point in continuing at the moment */
1148 printk(KERN_ERR "dropped packet (1)\n");
1149 d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr);
1150 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 } else {
1152 /*
1153 * Set length into the packet
1154 */
1155 skb_put(sb,len);
Ralf Baechle74b02472005-10-19 15:40:02 +01001156
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 /*
1158 * Buffer has been replaced on the
1159 * receive ring. Pass the buffer to
1160 * the kernel
1161 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 sb->protocol = eth_type_trans(sb,d->sbdma_eth->sbm_dev);
1163 /* Check hw IPv4/TCP checksum if supported */
1164 if (sc->rx_hw_checksum == ENABLE) {
1165 if (!((dsc->dscr_a) & M_DMA_ETHRX_BADIP4CS) &&
1166 !((dsc->dscr_a) & M_DMA_ETHRX_BADTCPCS)) {
1167 sb->ip_summed = CHECKSUM_UNNECESSARY;
1168 /* don't need to set sb->csum */
1169 } else {
Eric Dumazetbc8acf22010-09-02 13:07:41 -07001170 skb_checksum_none_assert(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 }
1172 }
Mark Mason693aa942007-04-26 00:23:22 -07001173 prefetch(sb->data);
1174 prefetch((const void *)(((char *)sb->data)+32));
1175 if (poll)
1176 dropped = netif_receive_skb(sb);
1177 else
1178 dropped = netif_rx(sb);
Ralf Baechle74b02472005-10-19 15:40:02 +01001179
Mark Mason693aa942007-04-26 00:23:22 -07001180 if (dropped == NET_RX_DROP) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001181 dev->stats.rx_dropped++;
Mark Mason693aa942007-04-26 00:23:22 -07001182 d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr);
1183 goto done;
1184 }
1185 else {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001186 dev->stats.rx_bytes += len;
1187 dev->stats.rx_packets++;
Mark Mason693aa942007-04-26 00:23:22 -07001188 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 }
1190 } else {
1191 /*
1192 * Packet was mangled somehow. Just drop it and
1193 * put it back on the receive ring.
1194 */
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001195 dev->stats.rx_errors++;
Stephen Hemminger789585e2008-05-18 04:45:09 +01001196 sbdma_add_rcvbuffer(sc, d, sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001198
1199
1200 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 * .. and advance to the next buffer.
1202 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001203
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr);
Mark Mason693aa942007-04-26 00:23:22 -07001205 work_done++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 }
Mark Mason693aa942007-04-26 00:23:22 -07001207 if (!poll) {
1208 work_to_do = 32;
1209 goto again; /* collect fifo drop statistics again */
1210 }
1211done:
1212 return work_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213}
1214
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215/**********************************************************************
1216 * SBDMA_TX_PROCESS(sc,d)
Ralf Baechle74b02472005-10-19 15:40:02 +01001217 *
1218 * Process "completed" transmit buffers on the specified DMA channel.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 * This is normally called within the interrupt service routine.
1220 * Note that this isn't really ideal for priority channels, since
Ralf Baechle74b02472005-10-19 15:40:02 +01001221 * it processes all of the packets on a given channel before
1222 * returning.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 *
Ralf Baechle74b02472005-10-19 15:40:02 +01001224 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 * sc - softc structure
Mark Mason693aa942007-04-26 00:23:22 -07001226 * d - DMA channel context
1227 * poll - 1: using polling (for NAPI)
Ralf Baechle74b02472005-10-19 15:40:02 +01001228 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 * Return value:
1230 * nothing
1231 ********************************************************************* */
1232
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001233static void sbdma_tx_process(struct sbmac_softc *sc, struct sbmacdma *d,
1234 int poll)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235{
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001236 struct net_device *dev = sc->sbm_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 int curidx;
1238 int hwidx;
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001239 struct sbdmadscr *dsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 struct sk_buff *sb;
1241 unsigned long flags;
Mark Mason693aa942007-04-26 00:23:22 -07001242 int packets_handled = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
1244 spin_lock_irqsave(&(sc->sbm_lock), flags);
Ralf Baechle74b02472005-10-19 15:40:02 +01001245
Mark Mason693aa942007-04-26 00:23:22 -07001246 if (d->sbdma_remptr == d->sbdma_addptr)
1247 goto end_unlock;
1248
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001249 hwidx = ((__raw_readq(d->sbdma_curdscr) & M_DMA_CURDSCR_ADDR) -
1250 d->sbdma_dscrtable_phys) / sizeof(*d->sbdma_dscrtable);
Mark Mason693aa942007-04-26 00:23:22 -07001251
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 for (;;) {
Ralf Baechle74b02472005-10-19 15:40:02 +01001253 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 * figure out where we are (as an index) and where
1255 * the hardware is (also as an index)
1256 *
Ralf Baechle74b02472005-10-19 15:40:02 +01001257 * This could be done faster if (for example) the
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 * descriptor table was page-aligned and contiguous in
1259 * both virtual and physical memory -- you could then
1260 * just compare the low-order bits of the virtual address
1261 * (sbdma_remptr) and the physical address (sbdma_curdscr CSR)
1262 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001263
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 curidx = d->sbdma_remptr - d->sbdma_dscrtable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
1266 /*
1267 * If they're the same, that means we've processed all
1268 * of the descriptors up to (but not including) the one that
1269 * the hardware is working on right now.
1270 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001271
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 if (curidx == hwidx)
1273 break;
Ralf Baechle74b02472005-10-19 15:40:02 +01001274
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 /*
1276 * Otherwise, get the packet's sk_buff ptr back
1277 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001278
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 dsc = &(d->sbdma_dscrtable[curidx]);
1280 sb = d->sbdma_ctxtable[curidx];
1281 d->sbdma_ctxtable[curidx] = NULL;
Ralf Baechle74b02472005-10-19 15:40:02 +01001282
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 /*
1284 * Stats
1285 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001286
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001287 dev->stats.tx_bytes += sb->len;
1288 dev->stats.tx_packets++;
Ralf Baechle74b02472005-10-19 15:40:02 +01001289
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 /*
1291 * for transmits, we just free buffers.
1292 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001293
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 dev_kfree_skb_irq(sb);
Ralf Baechle74b02472005-10-19 15:40:02 +01001295
1296 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 * .. and advance to the next buffer.
1298 */
1299
1300 d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr);
Ralf Baechle74b02472005-10-19 15:40:02 +01001301
Mark Mason693aa942007-04-26 00:23:22 -07001302 packets_handled++;
1303
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001305
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 /*
1307 * Decide if we should wake up the protocol or not.
1308 * Other drivers seem to do this when we reach a low
1309 * watermark on the transmit queue.
1310 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001311
Mark Mason693aa942007-04-26 00:23:22 -07001312 if (packets_handled)
1313 netif_wake_queue(d->sbdma_eth->sbm_dev);
Ralf Baechle74b02472005-10-19 15:40:02 +01001314
Mark Mason693aa942007-04-26 00:23:22 -07001315end_unlock:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 spin_unlock_irqrestore(&(sc->sbm_lock), flags);
Ralf Baechle74b02472005-10-19 15:40:02 +01001317
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318}
1319
1320
1321
1322/**********************************************************************
1323 * SBMAC_INITCTX(s)
Ralf Baechle74b02472005-10-19 15:40:02 +01001324 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 * Initialize an Ethernet context structure - this is called
1326 * once per MAC on the 1250. Memory is allocated here, so don't
1327 * call it again from inside the ioctl routines that bring the
1328 * interface up/down
Ralf Baechle74b02472005-10-19 15:40:02 +01001329 *
1330 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 * s - sbmac context structure
Ralf Baechle74b02472005-10-19 15:40:02 +01001332 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 * Return value:
1334 * 0
1335 ********************************************************************* */
1336
1337static int sbmac_initctx(struct sbmac_softc *s)
1338{
Ralf Baechle74b02472005-10-19 15:40:02 +01001339
1340 /*
1341 * figure out the addresses of some ports
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001343
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 s->sbm_macenable = s->sbm_base + R_MAC_ENABLE;
1345 s->sbm_maccfg = s->sbm_base + R_MAC_CFG;
1346 s->sbm_fifocfg = s->sbm_base + R_MAC_THRSH_CFG;
1347 s->sbm_framecfg = s->sbm_base + R_MAC_FRAMECFG;
1348 s->sbm_rxfilter = s->sbm_base + R_MAC_ADFILTER_CFG;
1349 s->sbm_isr = s->sbm_base + R_MAC_STATUS;
1350 s->sbm_imr = s->sbm_base + R_MAC_INT_MASK;
1351 s->sbm_mdio = s->sbm_base + R_MAC_MDIO;
1352
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 /*
1354 * Initialize the DMA channels. Right now, only one per MAC is used
1355 * Note: Only do this _once_, as it allocates memory from the kernel!
1356 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001357
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 sbdma_initctx(&(s->sbm_txdma),s,0,DMA_TX,SBMAC_MAX_TXDESCR);
1359 sbdma_initctx(&(s->sbm_rxdma),s,0,DMA_RX,SBMAC_MAX_RXDESCR);
Ralf Baechle74b02472005-10-19 15:40:02 +01001360
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 /*
1362 * initial state is OFF
1363 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001364
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 s->sbm_state = sbmac_state_off;
Ralf Baechle74b02472005-10-19 15:40:02 +01001366
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 return 0;
1368}
1369
1370
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001371static void sbdma_uninitctx(struct sbmacdma *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372{
Mark Mason693aa942007-04-26 00:23:22 -07001373 if (d->sbdma_dscrtable_unaligned) {
1374 kfree(d->sbdma_dscrtable_unaligned);
1375 d->sbdma_dscrtable_unaligned = d->sbdma_dscrtable = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001377
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 if (d->sbdma_ctxtable) {
1379 kfree(d->sbdma_ctxtable);
1380 d->sbdma_ctxtable = NULL;
1381 }
1382}
1383
1384
1385static void sbmac_uninitctx(struct sbmac_softc *sc)
1386{
1387 sbdma_uninitctx(&(sc->sbm_txdma));
1388 sbdma_uninitctx(&(sc->sbm_rxdma));
1389}
1390
1391
1392/**********************************************************************
1393 * SBMAC_CHANNEL_START(s)
Ralf Baechle74b02472005-10-19 15:40:02 +01001394 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 * Start packet processing on this MAC.
Ralf Baechle74b02472005-10-19 15:40:02 +01001396 *
1397 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 * s - sbmac structure
Ralf Baechle74b02472005-10-19 15:40:02 +01001399 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 * Return value:
1401 * nothing
1402 ********************************************************************* */
1403
1404static void sbmac_channel_start(struct sbmac_softc *s)
1405{
1406 uint64_t reg;
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001407 void __iomem *port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 uint64_t cfg,fifo,framecfg;
1409 int idx, th_value;
Ralf Baechle74b02472005-10-19 15:40:02 +01001410
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 /*
1412 * Don't do this if running
1413 */
1414
1415 if (s->sbm_state == sbmac_state_on)
1416 return;
Ralf Baechle74b02472005-10-19 15:40:02 +01001417
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 /*
1419 * Bring the controller out of reset, but leave it off.
1420 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001421
Ralf Baechle20399732005-10-19 15:39:05 +01001422 __raw_writeq(0, s->sbm_macenable);
Ralf Baechle74b02472005-10-19 15:40:02 +01001423
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 /*
1425 * Ignore all received packets
1426 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001427
Ralf Baechle20399732005-10-19 15:39:05 +01001428 __raw_writeq(0, s->sbm_rxfilter);
Ralf Baechle74b02472005-10-19 15:40:02 +01001429
1430 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 * Calculate values for various control registers.
1432 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001433
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 cfg = M_MAC_RETRY_EN |
Ralf Baechle74b02472005-10-19 15:40:02 +01001435 M_MAC_TX_HOLD_SOP_EN |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 V_MAC_TX_PAUSE_CNT_16K |
1437 M_MAC_AP_STAT_EN |
1438 M_MAC_FAST_SYNC |
1439 M_MAC_SS_EN |
1440 0;
Ralf Baechle74b02472005-10-19 15:40:02 +01001441
1442 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 * Be sure that RD_THRSH+WR_THRSH <= 32 for pass1 pars
1444 * and make sure that RD_THRSH + WR_THRSH <=128 for pass2 and above
1445 * Use a larger RD_THRSH for gigabit
1446 */
Ralf Baechlef90fdc32006-02-08 23:23:26 +00001447 if (soc_type == K_SYS_SOC_TYPE_BCM1250 && periph_rev < 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 th_value = 28;
Ralf Baechlef90fdc32006-02-08 23:23:26 +00001449 else
1450 th_value = 64;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451
1452 fifo = V_MAC_TX_WR_THRSH(4) | /* Must be '4' or '8' */
1453 ((s->sbm_speed == sbmac_speed_1000)
1454 ? V_MAC_TX_RD_THRSH(th_value) : V_MAC_TX_RD_THRSH(4)) |
1455 V_MAC_TX_RL_THRSH(4) |
1456 V_MAC_RX_PL_THRSH(4) |
1457 V_MAC_RX_RD_THRSH(4) | /* Must be '4' */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 V_MAC_RX_RL_THRSH(8) |
1459 0;
1460
1461 framecfg = V_MAC_MIN_FRAMESZ_DEFAULT |
1462 V_MAC_MAX_FRAMESZ_DEFAULT |
1463 V_MAC_BACKOFF_SEL(1);
1464
1465 /*
Ralf Baechle74b02472005-10-19 15:40:02 +01001466 * Clear out the hash address map
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001468
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 port = s->sbm_base + R_MAC_HASH_BASE;
1470 for (idx = 0; idx < MAC_HASH_COUNT; idx++) {
Ralf Baechle20399732005-10-19 15:39:05 +01001471 __raw_writeq(0, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 port += sizeof(uint64_t);
1473 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001474
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 /*
1476 * Clear out the exact-match table
1477 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001478
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 port = s->sbm_base + R_MAC_ADDR_BASE;
1480 for (idx = 0; idx < MAC_ADDR_COUNT; idx++) {
Ralf Baechle20399732005-10-19 15:39:05 +01001481 __raw_writeq(0, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 port += sizeof(uint64_t);
1483 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001484
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 /*
1486 * Clear out the DMA Channel mapping table registers
1487 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001488
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 port = s->sbm_base + R_MAC_CHUP0_BASE;
1490 for (idx = 0; idx < MAC_CHMAP_COUNT; idx++) {
Ralf Baechle20399732005-10-19 15:39:05 +01001491 __raw_writeq(0, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 port += sizeof(uint64_t);
1493 }
1494
1495
1496 port = s->sbm_base + R_MAC_CHLO0_BASE;
1497 for (idx = 0; idx < MAC_CHMAP_COUNT; idx++) {
Ralf Baechle20399732005-10-19 15:39:05 +01001498 __raw_writeq(0, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 port += sizeof(uint64_t);
1500 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001501
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 /*
1503 * Program the hardware address. It goes into the hardware-address
1504 * register as well as the first filter register.
1505 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001506
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 reg = sbmac_addr2reg(s->sbm_hwaddr);
Ralf Baechle74b02472005-10-19 15:40:02 +01001508
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 port = s->sbm_base + R_MAC_ADDR_BASE;
Ralf Baechle20399732005-10-19 15:39:05 +01001510 __raw_writeq(reg, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 port = s->sbm_base + R_MAC_ETHERNET_ADDR;
1512
1513#ifdef CONFIG_SB1_PASS_1_WORKAROUNDS
1514 /*
1515 * Pass1 SOCs do not receive packets addressed to the
1516 * destination address in the R_MAC_ETHERNET_ADDR register.
1517 * Set the value to zero.
1518 */
Ralf Baechle20399732005-10-19 15:39:05 +01001519 __raw_writeq(0, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520#else
Ralf Baechle20399732005-10-19 15:39:05 +01001521 __raw_writeq(reg, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522#endif
Ralf Baechle74b02472005-10-19 15:40:02 +01001523
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 /*
1525 * Set the receive filter for no packets, and write values
1526 * to the various config registers
1527 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001528
Ralf Baechle20399732005-10-19 15:39:05 +01001529 __raw_writeq(0, s->sbm_rxfilter);
1530 __raw_writeq(0, s->sbm_imr);
1531 __raw_writeq(framecfg, s->sbm_framecfg);
1532 __raw_writeq(fifo, s->sbm_fifocfg);
1533 __raw_writeq(cfg, s->sbm_maccfg);
Ralf Baechle74b02472005-10-19 15:40:02 +01001534
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 /*
1536 * Initialize DMA channels (rings should be ok now)
1537 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001538
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 sbdma_channel_start(&(s->sbm_rxdma), DMA_RX);
1540 sbdma_channel_start(&(s->sbm_txdma), DMA_TX);
Ralf Baechle74b02472005-10-19 15:40:02 +01001541
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 /*
1543 * Configure the speed, duplex, and flow control
1544 */
1545
1546 sbmac_set_speed(s,s->sbm_speed);
1547 sbmac_set_duplex(s,s->sbm_duplex,s->sbm_fc);
Ralf Baechle74b02472005-10-19 15:40:02 +01001548
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 /*
1550 * Fill the receive ring
1551 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001552
Stephen Hemminger789585e2008-05-18 04:45:09 +01001553 sbdma_fillring(s, &(s->sbm_rxdma));
Ralf Baechle74b02472005-10-19 15:40:02 +01001554
1555 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 * Turn on the rest of the bits in the enable register
Ralf Baechle74b02472005-10-19 15:40:02 +01001557 */
1558
Ralf Baechlef90fdc32006-02-08 23:23:26 +00001559#if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
1560 __raw_writeq(M_MAC_RXDMA_EN0 |
1561 M_MAC_TXDMA_EN0, s->sbm_macenable);
1562#elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X)
Ralf Baechle20399732005-10-19 15:39:05 +01001563 __raw_writeq(M_MAC_RXDMA_EN0 |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 M_MAC_TXDMA_EN0 |
1565 M_MAC_RX_ENABLE |
Ralf Baechle20399732005-10-19 15:39:05 +01001566 M_MAC_TX_ENABLE, s->sbm_macenable);
Ralf Baechlef90fdc32006-02-08 23:23:26 +00001567#else
Thomas Weber0b1974d2010-09-23 11:46:48 +02001568#error invalid SiByte MAC configuration
Ralf Baechlef90fdc32006-02-08 23:23:26 +00001569#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
1571#ifdef CONFIG_SBMAC_COALESCE
Ralf Baechle20399732005-10-19 15:39:05 +01001572 __raw_writeq(((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_TX_CH0) |
1573 ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_RX_CH0), s->sbm_imr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574#else
Ralf Baechle20399732005-10-19 15:39:05 +01001575 __raw_writeq((M_MAC_INT_CHANNEL << S_MAC_TX_CH0) |
1576 (M_MAC_INT_CHANNEL << S_MAC_RX_CH0), s->sbm_imr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577#endif
Ralf Baechle74b02472005-10-19 15:40:02 +01001578
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 /*
Ralf Baechle74b02472005-10-19 15:40:02 +01001580 * Enable receiving unicasts and broadcasts
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001582
1583 __raw_writeq(M_MAC_UCAST_EN | M_MAC_BCAST_EN, s->sbm_rxfilter);
1584
1585 /*
1586 * we're running now.
1587 */
1588
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 s->sbm_state = sbmac_state_on;
Ralf Baechle74b02472005-10-19 15:40:02 +01001590
1591 /*
1592 * Program multicast addresses
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001594
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 sbmac_setmulti(s);
Ralf Baechle74b02472005-10-19 15:40:02 +01001596
1597 /*
1598 * If channel was in promiscuous mode before, turn that on
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001600
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 if (s->sbm_devflags & IFF_PROMISC) {
1602 sbmac_promiscuous_mode(s,1);
1603 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001604
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605}
1606
1607
1608/**********************************************************************
1609 * SBMAC_CHANNEL_STOP(s)
Ralf Baechle74b02472005-10-19 15:40:02 +01001610 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 * Stop packet processing on this MAC.
Ralf Baechle74b02472005-10-19 15:40:02 +01001612 *
1613 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 * s - sbmac structure
Ralf Baechle74b02472005-10-19 15:40:02 +01001615 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 * Return value:
1617 * nothing
1618 ********************************************************************* */
1619
1620static void sbmac_channel_stop(struct sbmac_softc *s)
1621{
1622 /* don't do this if already stopped */
Ralf Baechle74b02472005-10-19 15:40:02 +01001623
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 if (s->sbm_state == sbmac_state_off)
1625 return;
Ralf Baechle74b02472005-10-19 15:40:02 +01001626
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 /* don't accept any packets, disable all interrupts */
Ralf Baechle74b02472005-10-19 15:40:02 +01001628
Ralf Baechle20399732005-10-19 15:39:05 +01001629 __raw_writeq(0, s->sbm_rxfilter);
1630 __raw_writeq(0, s->sbm_imr);
Ralf Baechle74b02472005-10-19 15:40:02 +01001631
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 /* Turn off ticker */
Ralf Baechle74b02472005-10-19 15:40:02 +01001633
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 /* XXX */
Ralf Baechle74b02472005-10-19 15:40:02 +01001635
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 /* turn off receiver and transmitter */
Ralf Baechle74b02472005-10-19 15:40:02 +01001637
Ralf Baechle20399732005-10-19 15:39:05 +01001638 __raw_writeq(0, s->sbm_macenable);
Ralf Baechle74b02472005-10-19 15:40:02 +01001639
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 /* We're stopped now. */
Ralf Baechle74b02472005-10-19 15:40:02 +01001641
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 s->sbm_state = sbmac_state_off;
Ralf Baechle74b02472005-10-19 15:40:02 +01001643
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 /*
1645 * Stop DMA channels (rings should be ok now)
1646 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001647
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 sbdma_channel_stop(&(s->sbm_rxdma));
1649 sbdma_channel_stop(&(s->sbm_txdma));
Ralf Baechle74b02472005-10-19 15:40:02 +01001650
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 /* Empty the receive and transmit rings */
Ralf Baechle74b02472005-10-19 15:40:02 +01001652
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 sbdma_emptyring(&(s->sbm_rxdma));
1654 sbdma_emptyring(&(s->sbm_txdma));
Ralf Baechle74b02472005-10-19 15:40:02 +01001655
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656}
1657
1658/**********************************************************************
1659 * SBMAC_SET_CHANNEL_STATE(state)
Ralf Baechle74b02472005-10-19 15:40:02 +01001660 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 * Set the channel's state ON or OFF
Ralf Baechle74b02472005-10-19 15:40:02 +01001662 *
1663 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 * state - new state
Ralf Baechle74b02472005-10-19 15:40:02 +01001665 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 * Return value:
1667 * old state
1668 ********************************************************************* */
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001669static enum sbmac_state sbmac_set_channel_state(struct sbmac_softc *sc,
1670 enum sbmac_state state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671{
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001672 enum sbmac_state oldstate = sc->sbm_state;
Ralf Baechle74b02472005-10-19 15:40:02 +01001673
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 /*
1675 * If same as previous state, return
1676 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001677
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 if (state == oldstate) {
1679 return oldstate;
1680 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001681
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 /*
Ralf Baechle74b02472005-10-19 15:40:02 +01001683 * If new state is ON, turn channel on
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001685
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 if (state == sbmac_state_on) {
1687 sbmac_channel_start(sc);
1688 }
1689 else {
1690 sbmac_channel_stop(sc);
1691 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001692
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 /*
1694 * Return previous state
1695 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001696
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 return oldstate;
1698}
1699
1700
1701/**********************************************************************
1702 * SBMAC_PROMISCUOUS_MODE(sc,onoff)
Ralf Baechle74b02472005-10-19 15:40:02 +01001703 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 * Turn on or off promiscuous mode
Ralf Baechle74b02472005-10-19 15:40:02 +01001705 *
1706 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 * sc - softc
1708 * onoff - 1 to turn on, 0 to turn off
Ralf Baechle74b02472005-10-19 15:40:02 +01001709 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 * Return value:
1711 * nothing
1712 ********************************************************************* */
1713
1714static void sbmac_promiscuous_mode(struct sbmac_softc *sc,int onoff)
1715{
1716 uint64_t reg;
Ralf Baechle74b02472005-10-19 15:40:02 +01001717
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 if (sc->sbm_state != sbmac_state_on)
1719 return;
Ralf Baechle74b02472005-10-19 15:40:02 +01001720
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 if (onoff) {
Ralf Baechle20399732005-10-19 15:39:05 +01001722 reg = __raw_readq(sc->sbm_rxfilter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 reg |= M_MAC_ALLPKT_EN;
Ralf Baechle20399732005-10-19 15:39:05 +01001724 __raw_writeq(reg, sc->sbm_rxfilter);
Ralf Baechle74b02472005-10-19 15:40:02 +01001725 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 else {
Ralf Baechle20399732005-10-19 15:39:05 +01001727 reg = __raw_readq(sc->sbm_rxfilter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 reg &= ~M_MAC_ALLPKT_EN;
Ralf Baechle20399732005-10-19 15:39:05 +01001729 __raw_writeq(reg, sc->sbm_rxfilter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 }
1731}
1732
1733/**********************************************************************
1734 * SBMAC_SETIPHDR_OFFSET(sc,onoff)
Ralf Baechle74b02472005-10-19 15:40:02 +01001735 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 * Set the iphdr offset as 15 assuming ethernet encapsulation
Ralf Baechle74b02472005-10-19 15:40:02 +01001737 *
1738 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 * sc - softc
Ralf Baechle74b02472005-10-19 15:40:02 +01001740 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 * Return value:
1742 * nothing
1743 ********************************************************************* */
1744
1745static void sbmac_set_iphdr_offset(struct sbmac_softc *sc)
1746{
1747 uint64_t reg;
Ralf Baechle74b02472005-10-19 15:40:02 +01001748
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 /* Hard code the off set to 15 for now */
Ralf Baechle20399732005-10-19 15:39:05 +01001750 reg = __raw_readq(sc->sbm_rxfilter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 reg &= ~M_MAC_IPHDR_OFFSET | V_MAC_IPHDR_OFFSET(15);
Ralf Baechle20399732005-10-19 15:39:05 +01001752 __raw_writeq(reg, sc->sbm_rxfilter);
Ralf Baechle74b02472005-10-19 15:40:02 +01001753
Ralf Baechlef90fdc32006-02-08 23:23:26 +00001754 /* BCM1250 pass1 didn't have hardware checksum. Everything
1755 later does. */
1756 if (soc_type == K_SYS_SOC_TYPE_BCM1250 && periph_rev < 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 sc->rx_hw_checksum = DISABLE;
Ralf Baechlef90fdc32006-02-08 23:23:26 +00001758 } else {
1759 sc->rx_hw_checksum = ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 }
1761}
1762
1763
1764/**********************************************************************
1765 * SBMAC_ADDR2REG(ptr)
Ralf Baechle74b02472005-10-19 15:40:02 +01001766 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 * Convert six bytes into the 64-bit register value that
1768 * we typically write into the SBMAC's address/mcast registers
Ralf Baechle74b02472005-10-19 15:40:02 +01001769 *
1770 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 * ptr - pointer to 6 bytes
Ralf Baechle74b02472005-10-19 15:40:02 +01001772 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 * Return value:
1774 * register value
1775 ********************************************************************* */
1776
1777static uint64_t sbmac_addr2reg(unsigned char *ptr)
1778{
1779 uint64_t reg = 0;
Ralf Baechle74b02472005-10-19 15:40:02 +01001780
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 ptr += 6;
Ralf Baechle74b02472005-10-19 15:40:02 +01001782
1783 reg |= (uint64_t) *(--ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 reg <<= 8;
Ralf Baechle74b02472005-10-19 15:40:02 +01001785 reg |= (uint64_t) *(--ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 reg <<= 8;
Ralf Baechle74b02472005-10-19 15:40:02 +01001787 reg |= (uint64_t) *(--ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 reg <<= 8;
Ralf Baechle74b02472005-10-19 15:40:02 +01001789 reg |= (uint64_t) *(--ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 reg <<= 8;
Ralf Baechle74b02472005-10-19 15:40:02 +01001791 reg |= (uint64_t) *(--ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 reg <<= 8;
Ralf Baechle74b02472005-10-19 15:40:02 +01001793 reg |= (uint64_t) *(--ptr);
1794
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 return reg;
1796}
1797
1798
1799/**********************************************************************
1800 * SBMAC_SET_SPEED(s,speed)
Ralf Baechle74b02472005-10-19 15:40:02 +01001801 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 * Configure LAN speed for the specified MAC.
1803 * Warning: must be called when MAC is off!
Ralf Baechle74b02472005-10-19 15:40:02 +01001804 *
1805 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 * s - sbmac structure
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001807 * speed - speed to set MAC to (see enum sbmac_speed)
Ralf Baechle74b02472005-10-19 15:40:02 +01001808 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 * Return value:
1810 * 1 if successful
1811 * 0 indicates invalid parameters
1812 ********************************************************************* */
1813
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001814static int sbmac_set_speed(struct sbmac_softc *s, enum sbmac_speed speed)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815{
1816 uint64_t cfg;
1817 uint64_t framecfg;
1818
1819 /*
1820 * Save new current values
1821 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001822
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 s->sbm_speed = speed;
Ralf Baechle74b02472005-10-19 15:40:02 +01001824
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 if (s->sbm_state == sbmac_state_on)
1826 return 0; /* save for next restart */
1827
1828 /*
Ralf Baechle74b02472005-10-19 15:40:02 +01001829 * Read current register values
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001831
Ralf Baechle20399732005-10-19 15:39:05 +01001832 cfg = __raw_readq(s->sbm_maccfg);
1833 framecfg = __raw_readq(s->sbm_framecfg);
Ralf Baechle74b02472005-10-19 15:40:02 +01001834
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 /*
1836 * Mask out the stuff we want to change
1837 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001838
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 cfg &= ~(M_MAC_BURST_EN | M_MAC_SPEED_SEL);
1840 framecfg &= ~(M_MAC_IFG_RX | M_MAC_IFG_TX | M_MAC_IFG_THRSH |
1841 M_MAC_SLOT_SIZE);
Ralf Baechle74b02472005-10-19 15:40:02 +01001842
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 /*
1844 * Now add in the new bits
1845 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001846
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 switch (speed) {
1848 case sbmac_speed_10:
1849 framecfg |= V_MAC_IFG_RX_10 |
1850 V_MAC_IFG_TX_10 |
1851 K_MAC_IFG_THRSH_10 |
1852 V_MAC_SLOT_SIZE_10;
1853 cfg |= V_MAC_SPEED_SEL_10MBPS;
1854 break;
Ralf Baechle74b02472005-10-19 15:40:02 +01001855
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 case sbmac_speed_100:
1857 framecfg |= V_MAC_IFG_RX_100 |
1858 V_MAC_IFG_TX_100 |
1859 V_MAC_IFG_THRSH_100 |
1860 V_MAC_SLOT_SIZE_100;
1861 cfg |= V_MAC_SPEED_SEL_100MBPS ;
1862 break;
Ralf Baechle74b02472005-10-19 15:40:02 +01001863
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 case sbmac_speed_1000:
1865 framecfg |= V_MAC_IFG_RX_1000 |
1866 V_MAC_IFG_TX_1000 |
1867 V_MAC_IFG_THRSH_1000 |
1868 V_MAC_SLOT_SIZE_1000;
1869 cfg |= V_MAC_SPEED_SEL_1000MBPS | M_MAC_BURST_EN;
1870 break;
Ralf Baechle74b02472005-10-19 15:40:02 +01001871
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 default:
1873 return 0;
1874 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001875
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 /*
Ralf Baechle74b02472005-10-19 15:40:02 +01001877 * Send the bits back to the hardware
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001879
Ralf Baechle20399732005-10-19 15:39:05 +01001880 __raw_writeq(framecfg, s->sbm_framecfg);
1881 __raw_writeq(cfg, s->sbm_maccfg);
Ralf Baechle74b02472005-10-19 15:40:02 +01001882
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 return 1;
1884}
1885
1886/**********************************************************************
1887 * SBMAC_SET_DUPLEX(s,duplex,fc)
Ralf Baechle74b02472005-10-19 15:40:02 +01001888 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 * Set Ethernet duplex and flow control options for this MAC
1890 * Warning: must be called when MAC is off!
Ralf Baechle74b02472005-10-19 15:40:02 +01001891 *
1892 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 * s - sbmac structure
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001894 * duplex - duplex setting (see enum sbmac_duplex)
1895 * fc - flow control setting (see enum sbmac_fc)
Ralf Baechle74b02472005-10-19 15:40:02 +01001896 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 * Return value:
1898 * 1 if ok
1899 * 0 if an invalid parameter combination was specified
1900 ********************************************************************* */
1901
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001902static int sbmac_set_duplex(struct sbmac_softc *s, enum sbmac_duplex duplex,
1903 enum sbmac_fc fc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904{
1905 uint64_t cfg;
Ralf Baechle74b02472005-10-19 15:40:02 +01001906
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 /*
1908 * Save new current values
1909 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001910
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 s->sbm_duplex = duplex;
1912 s->sbm_fc = fc;
Ralf Baechle74b02472005-10-19 15:40:02 +01001913
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 if (s->sbm_state == sbmac_state_on)
1915 return 0; /* save for next restart */
Ralf Baechle74b02472005-10-19 15:40:02 +01001916
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 /*
Ralf Baechle74b02472005-10-19 15:40:02 +01001918 * Read current register values
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001920
Ralf Baechle20399732005-10-19 15:39:05 +01001921 cfg = __raw_readq(s->sbm_maccfg);
Ralf Baechle74b02472005-10-19 15:40:02 +01001922
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 /*
1924 * Mask off the stuff we're about to change
1925 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001926
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 cfg &= ~(M_MAC_FC_SEL | M_MAC_FC_CMD | M_MAC_HDX_EN);
Ralf Baechle74b02472005-10-19 15:40:02 +01001928
1929
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 switch (duplex) {
1931 case sbmac_duplex_half:
1932 switch (fc) {
1933 case sbmac_fc_disabled:
1934 cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_DISABLED;
1935 break;
Ralf Baechle74b02472005-10-19 15:40:02 +01001936
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 case sbmac_fc_collision:
1938 cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_ENABLED;
1939 break;
Ralf Baechle74b02472005-10-19 15:40:02 +01001940
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 case sbmac_fc_carrier:
1942 cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_ENAB_FALSECARR;
1943 break;
Ralf Baechle74b02472005-10-19 15:40:02 +01001944
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 case sbmac_fc_frame: /* not valid in half duplex */
1946 default: /* invalid selection */
1947 return 0;
1948 }
1949 break;
Ralf Baechle74b02472005-10-19 15:40:02 +01001950
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 case sbmac_duplex_full:
1952 switch (fc) {
1953 case sbmac_fc_disabled:
1954 cfg |= V_MAC_FC_CMD_DISABLED;
1955 break;
Ralf Baechle74b02472005-10-19 15:40:02 +01001956
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 case sbmac_fc_frame:
1958 cfg |= V_MAC_FC_CMD_ENABLED;
1959 break;
Ralf Baechle74b02472005-10-19 15:40:02 +01001960
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 case sbmac_fc_collision: /* not valid in full duplex */
1962 case sbmac_fc_carrier: /* not valid in full duplex */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 default:
1964 return 0;
1965 }
1966 break;
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01001967 default:
1968 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001970
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971 /*
Ralf Baechle74b02472005-10-19 15:40:02 +01001972 * Send the bits back to the hardware
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001974
Ralf Baechle20399732005-10-19 15:39:05 +01001975 __raw_writeq(cfg, s->sbm_maccfg);
Ralf Baechle74b02472005-10-19 15:40:02 +01001976
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 return 1;
1978}
1979
1980
1981
1982
1983/**********************************************************************
1984 * SBMAC_INTR()
Ralf Baechle74b02472005-10-19 15:40:02 +01001985 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 * Interrupt handler for MAC interrupts
Ralf Baechle74b02472005-10-19 15:40:02 +01001987 *
1988 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 * MAC structure
Ralf Baechle74b02472005-10-19 15:40:02 +01001990 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 * Return value:
1992 * nothing
1993 ********************************************************************* */
David Howells7d12e782006-10-05 14:55:46 +01001994static irqreturn_t sbmac_intr(int irq,void *dev_instance)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995{
1996 struct net_device *dev = (struct net_device *) dev_instance;
1997 struct sbmac_softc *sc = netdev_priv(dev);
1998 uint64_t isr;
1999 int handled = 0;
2000
Mark Mason693aa942007-04-26 00:23:22 -07002001 /*
2002 * Read the ISR (this clears the bits in the real
2003 * register, except for counter addr)
2004 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002005
Mark Mason693aa942007-04-26 00:23:22 -07002006 isr = __raw_readq(sc->sbm_isr) & ~M_MAC_COUNTER_ADDR;
Ralf Baechle74b02472005-10-19 15:40:02 +01002007
Mark Mason693aa942007-04-26 00:23:22 -07002008 if (isr == 0)
2009 return IRQ_RETVAL(0);
2010 handled = 1;
Ralf Baechle74b02472005-10-19 15:40:02 +01002011
Mark Mason693aa942007-04-26 00:23:22 -07002012 /*
2013 * Transmits on channel 0
2014 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002016 if (isr & (M_MAC_INT_CHANNEL << S_MAC_TX_CH0))
Mark Mason693aa942007-04-26 00:23:22 -07002017 sbdma_tx_process(sc,&(sc->sbm_txdma), 0);
Ralf Baechle74b02472005-10-19 15:40:02 +01002018
Mark Mason693aa942007-04-26 00:23:22 -07002019 if (isr & (M_MAC_INT_CHANNEL << S_MAC_RX_CH0)) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002020 if (napi_schedule_prep(&sc->napi)) {
Mark Mason693aa942007-04-26 00:23:22 -07002021 __raw_writeq(0, sc->sbm_imr);
Ben Hutchings288379f2009-01-19 16:43:59 -08002022 __napi_schedule(&sc->napi);
Mark Mason693aa942007-04-26 00:23:22 -07002023 /* Depend on the exit from poll to reenable intr */
2024 }
2025 else {
2026 /* may leave some packets behind */
2027 sbdma_rx_process(sc,&(sc->sbm_rxdma),
2028 SBMAC_MAX_RXDESCR * 2, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 }
2030 }
2031 return IRQ_RETVAL(handled);
2032}
2033
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034/**********************************************************************
2035 * SBMAC_START_TX(skb,dev)
Ralf Baechle74b02472005-10-19 15:40:02 +01002036 *
2037 * Start output on the specified interface. Basically, we
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 * queue as many buffers as we can until the ring fills up, or
2039 * we run off the end of the queue, whichever comes first.
Ralf Baechle74b02472005-10-19 15:40:02 +01002040 *
2041 * Input parameters:
2042 *
2043 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 * Return value:
2045 * nothing
2046 ********************************************************************* */
2047static int sbmac_start_tx(struct sk_buff *skb, struct net_device *dev)
2048{
2049 struct sbmac_softc *sc = netdev_priv(dev);
Weiwei Wangbe61ea52008-09-18 08:23:48 +08002050 unsigned long flags;
Ralf Baechle74b02472005-10-19 15:40:02 +01002051
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 /* lock eth irq */
Weiwei Wangbe61ea52008-09-18 08:23:48 +08002053 spin_lock_irqsave(&sc->sbm_lock, flags);
Ralf Baechle74b02472005-10-19 15:40:02 +01002054
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 /*
Ralf Baechle74b02472005-10-19 15:40:02 +01002056 * Put the buffer on the transmit ring. If we
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 * don't have room, stop the queue.
2058 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002059
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 if (sbdma_add_txbuffer(&(sc->sbm_txdma),skb)) {
2061 /* XXX save skb that we could not send */
2062 netif_stop_queue(dev);
Weiwei Wangbe61ea52008-09-18 08:23:48 +08002063 spin_unlock_irqrestore(&sc->sbm_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
Patrick McHardy5b548142009-06-12 06:22:29 +00002065 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 }
Ralf Baechle74b02472005-10-19 15:40:02 +01002067
Weiwei Wangbe61ea52008-09-18 08:23:48 +08002068 spin_unlock_irqrestore(&sc->sbm_lock, flags);
Ralf Baechle74b02472005-10-19 15:40:02 +01002069
Patrick McHardy6ed10652009-06-23 06:03:08 +00002070 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071}
2072
2073/**********************************************************************
2074 * SBMAC_SETMULTI(sc)
Ralf Baechle74b02472005-10-19 15:40:02 +01002075 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 * Reprogram the multicast table into the hardware, given
2077 * the list of multicasts associated with the interface
2078 * structure.
Ralf Baechle74b02472005-10-19 15:40:02 +01002079 *
2080 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 * sc - softc
Ralf Baechle74b02472005-10-19 15:40:02 +01002082 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 * Return value:
2084 * nothing
2085 ********************************************************************* */
2086
2087static void sbmac_setmulti(struct sbmac_softc *sc)
2088{
2089 uint64_t reg;
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01002090 void __iomem *port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 int idx;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002092 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 struct net_device *dev = sc->sbm_dev;
Ralf Baechle74b02472005-10-19 15:40:02 +01002094
2095 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 * Clear out entire multicast table. We do this by nuking
2097 * the entire hash table and all the direct matches except
Ralf Baechle74b02472005-10-19 15:40:02 +01002098 * the first one, which is used for our station address
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002100
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 for (idx = 1; idx < MAC_ADDR_COUNT; idx++) {
2102 port = sc->sbm_base + R_MAC_ADDR_BASE+(idx*sizeof(uint64_t));
Ralf Baechle20399732005-10-19 15:39:05 +01002103 __raw_writeq(0, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 }
Ralf Baechle74b02472005-10-19 15:40:02 +01002105
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 for (idx = 0; idx < MAC_HASH_COUNT; idx++) {
2107 port = sc->sbm_base + R_MAC_HASH_BASE+(idx*sizeof(uint64_t));
Ralf Baechle20399732005-10-19 15:39:05 +01002108 __raw_writeq(0, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 }
Ralf Baechle74b02472005-10-19 15:40:02 +01002110
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 /*
2112 * Clear the filter to say we don't want any multicasts.
2113 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002114
Ralf Baechle20399732005-10-19 15:39:05 +01002115 reg = __raw_readq(sc->sbm_rxfilter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 reg &= ~(M_MAC_MCAST_INV | M_MAC_MCAST_EN);
Ralf Baechle20399732005-10-19 15:39:05 +01002117 __raw_writeq(reg, sc->sbm_rxfilter);
Ralf Baechle74b02472005-10-19 15:40:02 +01002118
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 if (dev->flags & IFF_ALLMULTI) {
Ralf Baechle74b02472005-10-19 15:40:02 +01002120 /*
2121 * Enable ALL multicasts. Do this by inverting the
2122 * multicast enable bit.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 */
Ralf Baechle20399732005-10-19 15:39:05 +01002124 reg = __raw_readq(sc->sbm_rxfilter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 reg |= (M_MAC_MCAST_INV | M_MAC_MCAST_EN);
Ralf Baechle20399732005-10-19 15:39:05 +01002126 __raw_writeq(reg, sc->sbm_rxfilter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 return;
2128 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129
Ralf Baechle74b02472005-10-19 15:40:02 +01002130
2131 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 * Progam new multicast entries. For now, only use the
2133 * perfect filter. In the future we'll need to use the
2134 * hash filter if the perfect filter overflows
2135 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002136
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 /* XXX only using perfect filter for now, need to use hash
2138 * XXX if the table overflows */
Ralf Baechle74b02472005-10-19 15:40:02 +01002139
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 idx = 1; /* skip station address */
Jiri Pirko22bedad2010-04-01 21:22:57 +00002141 netdev_for_each_mc_addr(ha, dev) {
Jiri Pirko55085902010-02-18 00:42:54 +00002142 if (idx == MAC_ADDR_COUNT)
2143 break;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002144 reg = sbmac_addr2reg(ha->addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 port = sc->sbm_base + R_MAC_ADDR_BASE+(idx * sizeof(uint64_t));
Ralf Baechle20399732005-10-19 15:39:05 +01002146 __raw_writeq(reg, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 idx++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 }
Ralf Baechle74b02472005-10-19 15:40:02 +01002149
2150 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 * Enable the "accept multicast bits" if we programmed at least one
Ralf Baechle74b02472005-10-19 15:40:02 +01002152 * multicast.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002154
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 if (idx > 1) {
Ralf Baechle20399732005-10-19 15:39:05 +01002156 reg = __raw_readq(sc->sbm_rxfilter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 reg |= M_MAC_MCAST_EN;
Ralf Baechle20399732005-10-19 15:39:05 +01002158 __raw_writeq(reg, sc->sbm_rxfilter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 }
2160}
2161
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162static int sb1250_change_mtu(struct net_device *_dev, int new_mtu)
2163{
2164 if (new_mtu > ENET_PACKET_SIZE)
2165 return -EINVAL;
2166 _dev->mtu = new_mtu;
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002167 pr_info("changing the mtu to %d\n", new_mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 return 0;
2169}
2170
Alexander Beregalovb4cf3422009-04-15 12:52:57 +00002171static const struct net_device_ops sbmac_netdev_ops = {
2172 .ndo_open = sbmac_open,
2173 .ndo_stop = sbmac_close,
2174 .ndo_start_xmit = sbmac_start_tx,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00002175 .ndo_set_rx_mode = sbmac_set_rx_mode,
Alexander Beregalovb4cf3422009-04-15 12:52:57 +00002176 .ndo_tx_timeout = sbmac_tx_timeout,
2177 .ndo_do_ioctl = sbmac_mii_ioctl,
2178 .ndo_change_mtu = sb1250_change_mtu,
2179 .ndo_validate_addr = eth_validate_addr,
2180 .ndo_set_mac_address = eth_mac_addr,
2181#ifdef CONFIG_NET_POLL_CONTROLLER
2182 .ndo_poll_controller = sbmac_netpoll,
2183#endif
2184};
2185
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186/**********************************************************************
2187 * SBMAC_INIT(dev)
Ralf Baechle74b02472005-10-19 15:40:02 +01002188 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 * Attach routine - init hardware and hook ourselves into linux
Ralf Baechle74b02472005-10-19 15:40:02 +01002190 *
2191 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 * dev - net_device structure
Ralf Baechle74b02472005-10-19 15:40:02 +01002193 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 * Return value:
2195 * status
2196 ********************************************************************* */
2197
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002198static int sbmac_init(struct platform_device *pldev, long long base)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07002200 struct net_device *dev = dev_get_drvdata(&pldev->dev);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002201 int idx = pldev->id;
2202 struct sbmac_softc *sc = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 unsigned char *eaddr;
2204 uint64_t ea_reg;
2205 int i;
2206 int err;
Ralf Baechle74b02472005-10-19 15:40:02 +01002207
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 sc->sbm_dev = dev;
2209 sc->sbe_idx = idx;
Ralf Baechle74b02472005-10-19 15:40:02 +01002210
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 eaddr = sc->sbm_hwaddr;
Ralf Baechle74b02472005-10-19 15:40:02 +01002212
2213 /*
Nick Andrew877d0312009-01-26 11:06:57 +01002214 * Read the ethernet address. The firmware left this programmed
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 * for us in the ethernet address register for each mac.
2216 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002217
Ralf Baechle20399732005-10-19 15:39:05 +01002218 ea_reg = __raw_readq(sc->sbm_base + R_MAC_ETHERNET_ADDR);
2219 __raw_writeq(0, sc->sbm_base + R_MAC_ETHERNET_ADDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 for (i = 0; i < 6; i++) {
2221 eaddr[i] = (uint8_t) (ea_reg & 0xFF);
2222 ea_reg >>= 8;
2223 }
Ralf Baechle74b02472005-10-19 15:40:02 +01002224
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 for (i = 0; i < 6; i++) {
2226 dev->dev_addr[i] = eaddr[i];
2227 }
Ralf Baechle74b02472005-10-19 15:40:02 +01002228
Ralf Baechle74b02472005-10-19 15:40:02 +01002229 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 * Initialize context (get pointers to registers and stuff), then
2231 * allocate the memory for the descriptor tables.
2232 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002233
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 sbmac_initctx(sc);
Ralf Baechle74b02472005-10-19 15:40:02 +01002235
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 /*
2237 * Set up Linux device callins
2238 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002239
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 spin_lock_init(&(sc->sbm_lock));
Ralf Baechle74b02472005-10-19 15:40:02 +01002241
Alexander Beregalovb4cf3422009-04-15 12:52:57 +00002242 dev->netdev_ops = &sbmac_netdev_ops;
2243 dev->watchdog_timeo = TX_TIMEOUT;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002244
2245 netif_napi_add(dev, &sc->napi, sbmac_poll, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002247 dev->irq = UNIT_INT(idx);
2248
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 /* This is needed for PASS2 for Rx H/W checksum feature */
2250 sbmac_set_iphdr_offset(sc);
2251
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -07002252 sc->mii_bus = mdiobus_alloc();
2253 if (sc->mii_bus == NULL) {
Sebastian Siewior03f80cc2010-04-28 09:57:01 +00002254 err = -ENOMEM;
2255 goto uninit_ctx;
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -07002256 }
2257
Sebastian Siewior03f80cc2010-04-28 09:57:01 +00002258 sc->mii_bus->name = sbmac_mdio_string;
Florian Fainelli446bbc42012-01-09 23:59:10 +00002259 snprintf(sc->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
2260 pldev->name, idx);
Sebastian Siewior03f80cc2010-04-28 09:57:01 +00002261 sc->mii_bus->priv = sc;
2262 sc->mii_bus->read = sbmac_mii_read;
2263 sc->mii_bus->write = sbmac_mii_write;
2264 sc->mii_bus->irq = sc->phy_irq;
2265 for (i = 0; i < PHY_MAX_ADDR; ++i)
2266 sc->mii_bus->irq[i] = SBMAC_PHY_INT;
2267
2268 sc->mii_bus->parent = &pldev->dev;
2269 /*
2270 * Probe PHY address
2271 */
2272 err = mdiobus_register(sc->mii_bus);
2273 if (err) {
2274 printk(KERN_ERR "%s: unable to register MDIO bus\n",
2275 dev->name);
2276 goto free_mdio;
2277 }
2278 dev_set_drvdata(&pldev->dev, sc->mii_bus);
2279
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 err = register_netdev(dev);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002281 if (err) {
2282 printk(KERN_ERR "%s.%d: unable to register netdev\n",
2283 sbmac_string, idx);
Sebastian Siewior03f80cc2010-04-28 09:57:01 +00002284 goto unreg_mdio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 }
2286
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002287 pr_info("%s.%d: registered as %s\n", sbmac_string, idx, dev->name);
2288
2289 if (sc->rx_hw_checksum == ENABLE)
2290 pr_info("%s: enabling TCP rcv checksum\n", dev->name);
2291
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 /*
2293 * Display Ethernet address (this is called during the config
2294 * process so we need to finish off the config message that
2295 * was being displayed)
2296 */
Johannes Berge1749612008-10-27 15:59:26 -07002297 pr_info("%s: SiByte Ethernet at 0x%08Lx, address: %pM\n",
2298 dev->name, base, eaddr);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002299
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 return 0;
Sebastian Siewior03f80cc2010-04-28 09:57:01 +00002301unreg_mdio:
2302 mdiobus_unregister(sc->mii_bus);
2303 dev_set_drvdata(&pldev->dev, NULL);
2304free_mdio:
2305 mdiobus_free(sc->mii_bus);
2306uninit_ctx:
2307 sbmac_uninitctx(sc);
2308 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309}
2310
2311
2312static int sbmac_open(struct net_device *dev)
2313{
2314 struct sbmac_softc *sc = netdev_priv(dev);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002315 int err;
Ralf Baechle74b02472005-10-19 15:40:02 +01002316
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002317 if (debug > 1)
2318 pr_debug("%s: sbmac_open() irq %d.\n", dev->name, dev->irq);
Ralf Baechle74b02472005-10-19 15:40:02 +01002319
2320 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 * map/route interrupt (clear status first, in case something
2322 * weird is pending; we haven't initialized the mac registers
2323 * yet)
2324 */
2325
Ralf Baechle20399732005-10-19 15:39:05 +01002326 __raw_readq(sc->sbm_isr);
Joe Perchesa0607fd2009-11-18 23:29:17 -08002327 err = request_irq(dev->irq, sbmac_intr, IRQF_SHARED, dev->name, dev);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002328 if (err) {
2329 printk(KERN_ERR "%s: unable to get IRQ %d\n", dev->name,
2330 dev->irq);
2331 goto out_err;
Ralf Baechle59b81822005-10-20 12:01:28 +01002332 }
2333
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002334 sc->sbm_speed = sbmac_speed_none;
2335 sc->sbm_duplex = sbmac_duplex_none;
2336 sc->sbm_fc = sbmac_fc_none;
2337 sc->sbm_pause = -1;
2338 sc->sbm_link = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002339
Ralf Baechle59b81822005-10-20 12:01:28 +01002340 /*
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002341 * Attach to the PHY
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002343 err = sbmac_mii_probe(dev);
2344 if (err)
2345 goto out_unregister;
Ralf Baechle74b02472005-10-19 15:40:02 +01002346
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 /*
2348 * Turn on the channel
2349 */
2350
2351 sbmac_set_channel_state(sc,sbmac_state_on);
Ralf Baechle74b02472005-10-19 15:40:02 +01002352
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 netif_start_queue(dev);
Ralf Baechle74b02472005-10-19 15:40:02 +01002354
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 sbmac_set_rx_mode(dev);
Ralf Baechle74b02472005-10-19 15:40:02 +01002356
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002357 phy_start(sc->phy_dev);
2358
2359 napi_enable(&sc->napi);
Ralf Baechle74b02472005-10-19 15:40:02 +01002360
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 return 0;
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002362
2363out_unregister:
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002364 free_irq(dev->irq, dev);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002365out_err:
2366 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367}
2368
Ralf Baechle59b81822005-10-20 12:01:28 +01002369static int sbmac_mii_probe(struct net_device *dev)
2370{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 struct sbmac_softc *sc = netdev_priv(dev);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002372 struct phy_device *phy_dev;
2373 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002375 for (i = 0; i < PHY_MAX_ADDR; i++) {
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -07002376 phy_dev = sc->mii_bus->phy_map[i];
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002377 if (phy_dev)
2378 break;
2379 }
2380 if (!phy_dev) {
2381 printk(KERN_ERR "%s: no PHY found\n", dev->name);
2382 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 }
Ralf Baechle74b02472005-10-19 15:40:02 +01002384
Florian Fainellif9a8f832013-01-14 00:52:52 +00002385 phy_dev = phy_connect(dev, dev_name(&phy_dev->dev), &sbmac_mii_poll,
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002386 PHY_INTERFACE_MODE_GMII);
2387 if (IS_ERR(phy_dev)) {
2388 printk(KERN_ERR "%s: could not attach to PHY\n", dev->name);
2389 return PTR_ERR(phy_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 }
Ralf Baechle74b02472005-10-19 15:40:02 +01002391
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002392 /* Remove any features not supported by the controller */
2393 phy_dev->supported &= SUPPORTED_10baseT_Half |
2394 SUPPORTED_10baseT_Full |
2395 SUPPORTED_100baseT_Half |
2396 SUPPORTED_100baseT_Full |
2397 SUPPORTED_1000baseT_Half |
2398 SUPPORTED_1000baseT_Full |
2399 SUPPORTED_Autoneg |
2400 SUPPORTED_MII |
2401 SUPPORTED_Pause |
2402 SUPPORTED_Asym_Pause;
2403 phy_dev->advertising = phy_dev->supported;
Ralf Baechle74b02472005-10-19 15:40:02 +01002404
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002405 pr_info("%s: attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
2406 dev->name, phy_dev->drv->name,
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08002407 dev_name(&phy_dev->dev), phy_dev->irq);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002408
2409 sc->phy_dev = phy_dev;
2410
2411 return 0;
2412}
2413
2414
2415static void sbmac_mii_poll(struct net_device *dev)
2416{
2417 struct sbmac_softc *sc = netdev_priv(dev);
2418 struct phy_device *phy_dev = sc->phy_dev;
2419 unsigned long flags;
2420 enum sbmac_fc fc;
2421 int link_chg, speed_chg, duplex_chg, pause_chg, fc_chg;
2422
2423 link_chg = (sc->sbm_link != phy_dev->link);
2424 speed_chg = (sc->sbm_speed != phy_dev->speed);
2425 duplex_chg = (sc->sbm_duplex != phy_dev->duplex);
2426 pause_chg = (sc->sbm_pause != phy_dev->pause);
2427
2428 if (!link_chg && !speed_chg && !duplex_chg && !pause_chg)
2429 return; /* Hmmm... */
2430
2431 if (!phy_dev->link) {
2432 if (link_chg) {
2433 sc->sbm_link = phy_dev->link;
2434 sc->sbm_speed = sbmac_speed_none;
2435 sc->sbm_duplex = sbmac_duplex_none;
2436 sc->sbm_fc = sbmac_fc_disabled;
2437 sc->sbm_pause = -1;
2438 pr_info("%s: link unavailable\n", dev->name);
2439 }
2440 return;
2441 }
2442
2443 if (phy_dev->duplex == DUPLEX_FULL) {
2444 if (phy_dev->pause)
2445 fc = sbmac_fc_frame;
2446 else
2447 fc = sbmac_fc_disabled;
2448 } else
2449 fc = sbmac_fc_collision;
2450 fc_chg = (sc->sbm_fc != fc);
2451
2452 pr_info("%s: link available: %dbase-%cD\n", dev->name, phy_dev->speed,
2453 phy_dev->duplex == DUPLEX_FULL ? 'F' : 'H');
2454
2455 spin_lock_irqsave(&sc->sbm_lock, flags);
2456
2457 sc->sbm_speed = phy_dev->speed;
2458 sc->sbm_duplex = phy_dev->duplex;
2459 sc->sbm_fc = fc;
2460 sc->sbm_pause = phy_dev->pause;
2461 sc->sbm_link = phy_dev->link;
2462
2463 if ((speed_chg || duplex_chg || fc_chg) &&
2464 sc->sbm_state != sbmac_state_off) {
2465 /*
2466 * something changed, restart the channel
2467 */
2468 if (debug > 1)
2469 pr_debug("%s: restarting channel "
2470 "because PHY state changed\n", dev->name);
2471 sbmac_channel_stop(sc);
2472 sbmac_channel_start(sc);
2473 }
2474
2475 spin_unlock_irqrestore(&sc->sbm_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476}
2477
2478
2479static void sbmac_tx_timeout (struct net_device *dev)
2480{
2481 struct sbmac_softc *sc = netdev_priv(dev);
Weiwei Wangbe61ea52008-09-18 08:23:48 +08002482 unsigned long flags;
Ralf Baechle74b02472005-10-19 15:40:02 +01002483
Weiwei Wangbe61ea52008-09-18 08:23:48 +08002484 spin_lock_irqsave(&sc->sbm_lock, flags);
Ralf Baechle74b02472005-10-19 15:40:02 +01002485
2486
Eric Dumazet1ae5dc32010-05-10 05:01:31 -07002487 dev->trans_start = jiffies; /* prevent tx timeout */
Jeff Garzik09f75cd2007-10-03 17:41:50 -07002488 dev->stats.tx_errors++;
Ralf Baechle74b02472005-10-19 15:40:02 +01002489
Weiwei Wangbe61ea52008-09-18 08:23:48 +08002490 spin_unlock_irqrestore(&sc->sbm_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491
2492 printk (KERN_WARNING "%s: Transmit timed out\n",dev->name);
2493}
2494
2495
2496
2497
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498static void sbmac_set_rx_mode(struct net_device *dev)
2499{
2500 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 struct sbmac_softc *sc = netdev_priv(dev);
2502
2503 spin_lock_irqsave(&sc->sbm_lock, flags);
2504 if ((dev->flags ^ sc->sbm_devflags) & IFF_PROMISC) {
2505 /*
2506 * Promiscuous changed.
2507 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002508
2509 if (dev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 sbmac_promiscuous_mode(sc,1);
2511 }
2512 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 sbmac_promiscuous_mode(sc,0);
2514 }
2515 }
2516 spin_unlock_irqrestore(&sc->sbm_lock, flags);
Ralf Baechle74b02472005-10-19 15:40:02 +01002517
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 /*
2519 * Program the multicasts. Do this every time.
2520 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002521
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 sbmac_setmulti(sc);
Ralf Baechle74b02472005-10-19 15:40:02 +01002523
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524}
2525
2526static int sbmac_mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2527{
2528 struct sbmac_softc *sc = netdev_priv(dev);
Ralf Baechle74b02472005-10-19 15:40:02 +01002529
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002530 if (!netif_running(dev) || !sc->phy_dev)
2531 return -EINVAL;
Ralf Baechle74b02472005-10-19 15:40:02 +01002532
Richard Cochran28b04112010-07-17 08:48:55 +00002533 return phy_mii_ioctl(sc->phy_dev, rq, cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534}
2535
2536static int sbmac_close(struct net_device *dev)
2537{
2538 struct sbmac_softc *sc = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002540 napi_disable(&sc->napi);
2541
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002542 phy_stop(sc->phy_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002544 sbmac_set_channel_state(sc, sbmac_state_off);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545
2546 netif_stop_queue(dev);
2547
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002548 if (debug > 1)
2549 pr_debug("%s: Shutting down ethercard\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002551 phy_disconnect(sc->phy_dev);
2552 sc->phy_dev = NULL;
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002553 free_irq(dev->irq, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554
2555 sbdma_emptyring(&(sc->sbm_txdma));
2556 sbdma_emptyring(&(sc->sbm_rxdma));
Ralf Baechle74b02472005-10-19 15:40:02 +01002557
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 return 0;
2559}
2560
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002561static int sbmac_poll(struct napi_struct *napi, int budget)
Mark Mason693aa942007-04-26 00:23:22 -07002562{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002563 struct sbmac_softc *sc = container_of(napi, struct sbmac_softc, napi);
Mark Mason693aa942007-04-26 00:23:22 -07002564 int work_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002566 work_done = sbdma_rx_process(sc, &(sc->sbm_rxdma), budget, 1);
Mark Mason693aa942007-04-26 00:23:22 -07002567 sbdma_tx_process(sc, &(sc->sbm_txdma), 1);
2568
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002569 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002570 napi_complete(napi);
Mark Mason693aa942007-04-26 00:23:22 -07002571
2572#ifdef CONFIG_SBMAC_COALESCE
2573 __raw_writeq(((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_TX_CH0) |
2574 ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_RX_CH0),
2575 sc->sbm_imr);
2576#else
2577 __raw_writeq((M_MAC_INT_CHANNEL << S_MAC_TX_CH0) |
2578 (M_MAC_INT_CHANNEL << S_MAC_RX_CH0), sc->sbm_imr);
2579#endif
2580 }
2581
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002582 return work_done;
Mark Mason693aa942007-04-26 00:23:22 -07002583}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002585
Bill Pemberton047fc562012-12-03 09:24:23 -05002586static int sbmac_probe(struct platform_device *pldev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587{
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002588 struct net_device *dev;
2589 struct sbmac_softc *sc;
2590 void __iomem *sbm_base;
2591 struct resource *res;
2592 u64 sbmac_orig_hwaddr;
2593 int err;
2594
2595 res = platform_get_resource(pldev, IORESOURCE_MEM, 0);
2596 BUG_ON(!res);
Joe Perches28f65c112011-06-09 09:13:32 -07002597 sbm_base = ioremap_nocache(res->start, resource_size(res));
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002598 if (!sbm_base) {
2599 printk(KERN_ERR "%s: unable to map device registers\n",
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08002600 dev_name(&pldev->dev));
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002601 err = -ENOMEM;
2602 goto out_out;
2603 }
2604
2605 /*
2606 * The R_MAC_ETHERNET_ADDR register will be set to some nonzero
2607 * value for us by the firmware if we're going to use this MAC.
2608 * If we find a zero, skip this MAC.
2609 */
2610 sbmac_orig_hwaddr = __raw_readq(sbm_base + R_MAC_ETHERNET_ADDR);
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08002611 pr_debug("%s: %sconfiguring MAC at 0x%08Lx\n", dev_name(&pldev->dev),
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002612 sbmac_orig_hwaddr ? "" : "not ", (long long)res->start);
2613 if (sbmac_orig_hwaddr == 0) {
2614 err = 0;
2615 goto out_unmap;
2616 }
2617
2618 /*
2619 * Okay, cool. Initialize this MAC.
2620 */
2621 dev = alloc_etherdev(sizeof(struct sbmac_softc));
2622 if (!dev) {
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002623 err = -ENOMEM;
2624 goto out_unmap;
2625 }
2626
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07002627 dev_set_drvdata(&pldev->dev, dev);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002628 SET_NETDEV_DEV(dev, &pldev->dev);
2629
2630 sc = netdev_priv(dev);
2631 sc->sbm_base = sbm_base;
2632
2633 err = sbmac_init(pldev, res->start);
2634 if (err)
2635 goto out_kfree;
2636
2637 return 0;
2638
2639out_kfree:
2640 free_netdev(dev);
2641 __raw_writeq(sbmac_orig_hwaddr, sbm_base + R_MAC_ETHERNET_ADDR);
2642
2643out_unmap:
2644 iounmap(sbm_base);
2645
2646out_out:
2647 return err;
2648}
2649
2650static int __exit sbmac_remove(struct platform_device *pldev)
2651{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07002652 struct net_device *dev = dev_get_drvdata(&pldev->dev);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002653 struct sbmac_softc *sc = netdev_priv(dev);
2654
2655 unregister_netdev(dev);
2656 sbmac_uninitctx(sc);
Sebastian Siewior03f80cc2010-04-28 09:57:01 +00002657 mdiobus_unregister(sc->mii_bus);
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -07002658 mdiobus_free(sc->mii_bus);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002659 iounmap(sc->sbm_base);
2660 free_netdev(dev);
2661
2662 return 0;
2663}
2664
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002665static struct platform_driver sbmac_driver = {
2666 .probe = sbmac_probe,
2667 .remove = __exit_p(sbmac_remove),
2668 .driver = {
2669 .name = sbmac_string,
Ralf Baechle33b665e2010-07-06 05:18:11 +00002670 .owner = THIS_MODULE,
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002671 },
2672};
2673
Axel Lindb62f682011-11-27 16:44:17 +00002674module_platform_driver(sbmac_driver);