blob: 80ff5252723343bff26dc27d888bc777abb348fa [file] [log] [blame]
Thomas Gleixner1ccea772019-05-19 15:51:43 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Ralf Baechlef90fdc32006-02-08 23:23:26 +00003 * Copyright (C) 2001,2002,2003,2004 Broadcom Corporation
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01004 * Copyright (c) 2006, 2007 Maciej W. Rozycki
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * This driver is designed for the Broadcom SiByte SOC built-in
7 * Ethernet controllers. Written by Mitch Lichtenberg at Broadcom Corp.
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01008 *
9 * Updated to the driver model and the PHY abstraction layer
10 * by Maciej W. Rozycki.
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +010012
13#include <linux/bug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/string.h>
17#include <linux/timer.h>
18#include <linux/errno.h>
19#include <linux/ioport.h>
20#include <linux/slab.h>
21#include <linux/interrupt.h>
22#include <linux/netdevice.h>
23#include <linux/etherdevice.h>
24#include <linux/skbuff.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/bitops.h>
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +010026#include <linux/err.h>
27#include <linux/ethtool.h>
28#include <linux/mii.h>
29#include <linux/phy.h>
30#include <linux/platform_device.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040031#include <linux/prefetch.h>
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +010032
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <asm/cache.h>
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +010034#include <asm/io.h>
35#include <asm/processor.h> /* Processor type for cache alignment. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Linus Torvalds1da177e2005-04-16 15:20:36 -070037/* Operational parameters that usually are not changed. */
38
39#define CONFIG_SBMAC_COALESCE
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041/* Time in jiffies before concluding the transmitter is hung. */
42#define TX_TIMEOUT (2*HZ)
43
44
45MODULE_AUTHOR("Mitch Lichtenberg (Broadcom Corp.)");
46MODULE_DESCRIPTION("Broadcom SiByte SOC GB Ethernet driver");
47
48/* A few user-configurable values which may be modified when a driver
49 module is loaded. */
50
51/* 1 normal messages, 0 quiet .. 7 verbose. */
52static int debug = 1;
Joe Perchesd3757ba2018-03-23 16:34:44 -070053module_param(debug, int, 0444);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054MODULE_PARM_DESC(debug, "Debug messages");
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#ifdef CONFIG_SBMAC_COALESCE
Mark Mason693aa942007-04-26 00:23:22 -070057static int int_pktcnt_tx = 255;
Joe Perchesd3757ba2018-03-23 16:34:44 -070058module_param(int_pktcnt_tx, int, 0444);
Mark Mason693aa942007-04-26 00:23:22 -070059MODULE_PARM_DESC(int_pktcnt_tx, "TX packet count");
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Mark Mason693aa942007-04-26 00:23:22 -070061static int int_timeout_tx = 255;
Joe Perchesd3757ba2018-03-23 16:34:44 -070062module_param(int_timeout_tx, int, 0444);
Mark Mason693aa942007-04-26 00:23:22 -070063MODULE_PARM_DESC(int_timeout_tx, "TX timeout value");
64
65static int int_pktcnt_rx = 64;
Joe Perchesd3757ba2018-03-23 16:34:44 -070066module_param(int_pktcnt_rx, int, 0444);
Mark Mason693aa942007-04-26 00:23:22 -070067MODULE_PARM_DESC(int_pktcnt_rx, "RX packet count");
68
69static int int_timeout_rx = 64;
Joe Perchesd3757ba2018-03-23 16:34:44 -070070module_param(int_timeout_rx, int, 0444);
Mark Mason693aa942007-04-26 00:23:22 -070071MODULE_PARM_DESC(int_timeout_rx, "RX timeout value");
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#endif
73
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +010074#include <asm/sibyte/board.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070075#include <asm/sibyte/sb1250.h>
Ralf Baechlef90fdc32006-02-08 23:23:26 +000076#if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
77#include <asm/sibyte/bcm1480_regs.h>
78#include <asm/sibyte/bcm1480_int.h>
Mark Mason693aa942007-04-26 00:23:22 -070079#define R_MAC_DMA_OODPKTLOST_RX R_MAC_DMA_OODPKTLOST
Ralf Baechlef90fdc32006-02-08 23:23:26 +000080#elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#include <asm/sibyte/sb1250_regs.h>
Ralf Baechlef90fdc32006-02-08 23:23:26 +000082#include <asm/sibyte/sb1250_int.h>
83#else
Thomas Weber0b1974d2010-09-23 11:46:48 +020084#error invalid SiByte MAC configuration
Ralf Baechlef90fdc32006-02-08 23:23:26 +000085#endif
86#include <asm/sibyte/sb1250_scd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#include <asm/sibyte/sb1250_mac.h>
88#include <asm/sibyte/sb1250_dma.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Ralf Baechlef90fdc32006-02-08 23:23:26 +000090#if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
91#define UNIT_INT(n) (K_BCM1480_INT_MAC_0 + ((n) * 2))
92#elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X)
93#define UNIT_INT(n) (K_INT_MAC_0 + (n))
94#else
Thomas Weber0b1974d2010-09-23 11:46:48 +020095#error invalid SiByte MAC configuration
Ralf Baechlef90fdc32006-02-08 23:23:26 +000096#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +010098#ifdef K_INT_PHY
99#define SBMAC_PHY_INT K_INT_PHY
100#else
101#define SBMAC_PHY_INT PHY_POLL
102#endif
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104/**********************************************************************
105 * Simple types
106 ********************************************************************* */
107
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100108enum sbmac_speed {
109 sbmac_speed_none = 0,
110 sbmac_speed_10 = SPEED_10,
111 sbmac_speed_100 = SPEED_100,
112 sbmac_speed_1000 = SPEED_1000,
113};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100115enum sbmac_duplex {
116 sbmac_duplex_none = -1,
117 sbmac_duplex_half = DUPLEX_HALF,
118 sbmac_duplex_full = DUPLEX_FULL,
119};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100121enum sbmac_fc {
122 sbmac_fc_none,
123 sbmac_fc_disabled,
124 sbmac_fc_frame,
125 sbmac_fc_collision,
126 sbmac_fc_carrier,
127};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100129enum sbmac_state {
130 sbmac_state_uninit,
131 sbmac_state_off,
132 sbmac_state_on,
133 sbmac_state_broken,
134};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136
137/**********************************************************************
138 * Macros
139 ********************************************************************* */
140
141
142#define SBDMA_NEXTBUF(d,f) ((((d)->f+1) == (d)->sbdma_dscrtable_end) ? \
143 (d)->sbdma_dscrtable : (d)->f+1)
144
145
zhong jiangf8a19882018-09-11 21:08:15 +0800146#define NUMCACHEBLKS(x) DIV_ROUND_UP(x, SMP_CACHE_BYTES)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Mark Mason693aa942007-04-26 00:23:22 -0700148#define SBMAC_MAX_TXDESCR 256
149#define SBMAC_MAX_RXDESCR 256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Ralf Baechle74b02472005-10-19 15:40:02 +0100151#define ENET_PACKET_SIZE 1518
152/*#define ENET_PACKET_SIZE 9216 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154/**********************************************************************
155 * DMA Descriptor structure
156 ********************************************************************* */
157
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100158struct sbdmadscr {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 uint64_t dscr_a;
160 uint64_t dscr_b;
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100161};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163/**********************************************************************
164 * DMA Controller structure
165 ********************************************************************* */
166
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100167struct sbmacdma {
Ralf Baechle74b02472005-10-19 15:40:02 +0100168
169 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 * This stuff is used to identify the channel and the registers
171 * associated with it.
172 */
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100173 struct sbmac_softc *sbdma_eth; /* back pointer to associated
174 MAC */
175 int sbdma_channel; /* channel number */
176 int sbdma_txdir; /* direction (1=transmit) */
177 int sbdma_maxdescr; /* total # of descriptors
178 in ring */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179#ifdef CONFIG_SBMAC_COALESCE
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100180 int sbdma_int_pktcnt;
181 /* # descriptors rx/tx
182 before interrupt */
183 int sbdma_int_timeout;
184 /* # usec rx/tx interrupt */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185#endif
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100186 void __iomem *sbdma_config0; /* DMA config register 0 */
187 void __iomem *sbdma_config1; /* DMA config register 1 */
188 void __iomem *sbdma_dscrbase;
189 /* descriptor base address */
190 void __iomem *sbdma_dscrcnt; /* descriptor count register */
191 void __iomem *sbdma_curdscr; /* current descriptor
192 address */
193 void __iomem *sbdma_oodpktlost;
194 /* pkt drop (rx only) */
Ralf Baechle74b02472005-10-19 15:40:02 +0100195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 /*
197 * This stuff is for maintenance of the ring
198 */
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100199 void *sbdma_dscrtable_unaligned;
200 struct sbdmadscr *sbdma_dscrtable;
201 /* base of descriptor table */
202 struct sbdmadscr *sbdma_dscrtable_end;
203 /* end of descriptor table */
204 struct sk_buff **sbdma_ctxtable;
205 /* context table, one
206 per descr */
207 dma_addr_t sbdma_dscrtable_phys;
208 /* and also the phys addr */
209 struct sbdmadscr *sbdma_addptr; /* next dscr for sw to add */
210 struct sbdmadscr *sbdma_remptr; /* next dscr for sw
211 to remove */
212};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214
215/**********************************************************************
216 * Ethernet softc structure
217 ********************************************************************* */
218
219struct sbmac_softc {
Ralf Baechle74b02472005-10-19 15:40:02 +0100220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 /*
222 * Linux-specific things
223 */
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100224 struct net_device *sbm_dev; /* pointer to linux device */
225 struct napi_struct napi;
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100226 struct phy_device *phy_dev; /* the associated PHY device */
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700227 struct mii_bus *mii_bus; /* the MII bus */
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100228 spinlock_t sbm_lock; /* spin lock */
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100229 int sbm_devflags; /* current device flags */
Ralf Baechle74b02472005-10-19 15:40:02 +0100230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 /*
232 * Controller-specific things
233 */
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100234 void __iomem *sbm_base; /* MAC's base address */
235 enum sbmac_state sbm_state; /* current state */
Ralf Baechle74b02472005-10-19 15:40:02 +0100236
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100237 void __iomem *sbm_macenable; /* MAC Enable Register */
238 void __iomem *sbm_maccfg; /* MAC Config Register */
239 void __iomem *sbm_fifocfg; /* FIFO Config Register */
240 void __iomem *sbm_framecfg; /* Frame Config Register */
241 void __iomem *sbm_rxfilter; /* Receive Filter Register */
242 void __iomem *sbm_isr; /* Interrupt Status Register */
243 void __iomem *sbm_imr; /* Interrupt Mask Register */
244 void __iomem *sbm_mdio; /* MDIO Register */
Ralf Baechle74b02472005-10-19 15:40:02 +0100245
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100246 enum sbmac_speed sbm_speed; /* current speed */
247 enum sbmac_duplex sbm_duplex; /* current duplex */
248 enum sbmac_fc sbm_fc; /* cur. flow control setting */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100249 int sbm_pause; /* current pause setting */
250 int sbm_link; /* current link state */
Ralf Baechle74b02472005-10-19 15:40:02 +0100251
Joe Perches104bf3f2011-11-16 09:38:03 +0000252 unsigned char sbm_hwaddr[ETH_ALEN];
Ralf Baechle74b02472005-10-19 15:40:02 +0100253
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100254 struct sbmacdma sbm_txdma; /* only channel 0 for now */
255 struct sbmacdma sbm_rxdma;
256 int rx_hw_checksum;
257 int sbe_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258};
259
260
261/**********************************************************************
262 * Externs
263 ********************************************************************* */
264
265/**********************************************************************
266 * Prototypes
267 ********************************************************************* */
268
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100269static void sbdma_initctx(struct sbmacdma *d, struct sbmac_softc *s, int chan,
270 int txrx, int maxdescr);
271static void sbdma_channel_start(struct sbmacdma *d, int rxtx);
Stephen Hemminger789585e2008-05-18 04:45:09 +0100272static int sbdma_add_rcvbuffer(struct sbmac_softc *sc, struct sbmacdma *d,
273 struct sk_buff *m);
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100274static int sbdma_add_txbuffer(struct sbmacdma *d, struct sk_buff *m);
275static void sbdma_emptyring(struct sbmacdma *d);
Stephen Hemminger789585e2008-05-18 04:45:09 +0100276static void sbdma_fillring(struct sbmac_softc *sc, struct sbmacdma *d);
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100277static int sbdma_rx_process(struct sbmac_softc *sc, struct sbmacdma *d,
278 int work_to_do, int poll);
279static void sbdma_tx_process(struct sbmac_softc *sc, struct sbmacdma *d,
280 int poll);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281static int sbmac_initctx(struct sbmac_softc *s);
282static void sbmac_channel_start(struct sbmac_softc *s);
283static void sbmac_channel_stop(struct sbmac_softc *s);
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100284static enum sbmac_state sbmac_set_channel_state(struct sbmac_softc *,
285 enum sbmac_state);
286static void sbmac_promiscuous_mode(struct sbmac_softc *sc, int onoff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287static uint64_t sbmac_addr2reg(unsigned char *ptr);
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100288static irqreturn_t sbmac_intr(int irq, void *dev_instance);
YueHaibing0c13b8d2018-09-19 18:45:12 +0800289static netdev_tx_t sbmac_start_tx(struct sk_buff *skb, struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290static void sbmac_setmulti(struct sbmac_softc *sc);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100291static int sbmac_init(struct platform_device *pldev, long long base);
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100292static int sbmac_set_speed(struct sbmac_softc *s, enum sbmac_speed speed);
293static int sbmac_set_duplex(struct sbmac_softc *s, enum sbmac_duplex duplex,
294 enum sbmac_fc fc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296static int sbmac_open(struct net_device *dev);
Michael S. Tsirkin0290bd22019-12-10 09:23:51 -0500297static void sbmac_tx_timeout (struct net_device *dev, unsigned int txqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298static void sbmac_set_rx_mode(struct net_device *dev);
299static int sbmac_mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
300static int sbmac_close(struct net_device *dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700301static int sbmac_poll(struct napi_struct *napi, int budget);
Mark Mason693aa942007-04-26 00:23:22 -0700302
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100303static void sbmac_mii_poll(struct net_device *dev);
Ralf Baechle59b81822005-10-20 12:01:28 +0100304static int sbmac_mii_probe(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100306static void sbmac_mii_sync(void __iomem *sbm_mdio);
307static void sbmac_mii_senddata(void __iomem *sbm_mdio, unsigned int data,
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100308 int bitcnt);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100309static int sbmac_mii_read(struct mii_bus *bus, int phyaddr, int regidx);
310static int sbmac_mii_write(struct mii_bus *bus, int phyaddr, int regidx,
311 u16 val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
313
314/**********************************************************************
315 * Globals
316 ********************************************************************* */
317
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100318static char sbmac_string[] = "sb1250-mac";
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100319
320static char sbmac_mdio_string[] = "sb1250-mac-mdio";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322
323/**********************************************************************
324 * MDIO constants
325 ********************************************************************* */
326
327#define MII_COMMAND_START 0x01
328#define MII_COMMAND_READ 0x02
329#define MII_COMMAND_WRITE 0x01
330#define MII_COMMAND_ACK 0x02
331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332#define M_MAC_MDIO_DIR_OUTPUT 0 /* for clarity */
333
334#define ENABLE 1
335#define DISABLE 0
336
337/**********************************************************************
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100338 * SBMAC_MII_SYNC(sbm_mdio)
Ralf Baechle74b02472005-10-19 15:40:02 +0100339 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 * Synchronize with the MII - send a pattern of bits to the MII
341 * that will guarantee that it is ready to accept a command.
Ralf Baechle74b02472005-10-19 15:40:02 +0100342 *
343 * Input parameters:
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100344 * sbm_mdio - address of the MAC's MDIO register
Ralf Baechle74b02472005-10-19 15:40:02 +0100345 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 * Return value:
347 * nothing
348 ********************************************************************* */
349
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100350static void sbmac_mii_sync(void __iomem *sbm_mdio)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
352 int cnt;
353 uint64_t bits;
354 int mac_mdio_genc;
355
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100356 mac_mdio_genc = __raw_readq(sbm_mdio) & M_MAC_GENC;
Ralf Baechle74b02472005-10-19 15:40:02 +0100357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 bits = M_MAC_MDIO_DIR_OUTPUT | M_MAC_MDIO_OUT;
Ralf Baechle74b02472005-10-19 15:40:02 +0100359
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100360 __raw_writeq(bits | mac_mdio_genc, sbm_mdio);
Ralf Baechle74b02472005-10-19 15:40:02 +0100361
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 for (cnt = 0; cnt < 32; cnt++) {
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100363 __raw_writeq(bits | M_MAC_MDC | mac_mdio_genc, sbm_mdio);
364 __raw_writeq(bits | mac_mdio_genc, sbm_mdio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 }
366}
367
368/**********************************************************************
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100369 * SBMAC_MII_SENDDATA(sbm_mdio, data, bitcnt)
Ralf Baechle74b02472005-10-19 15:40:02 +0100370 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 * Send some bits to the MII. The bits to be sent are right-
372 * justified in the 'data' parameter.
Ralf Baechle74b02472005-10-19 15:40:02 +0100373 *
374 * Input parameters:
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100375 * sbm_mdio - address of the MAC's MDIO register
376 * data - data to send
377 * bitcnt - number of bits to send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 ********************************************************************* */
379
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100380static void sbmac_mii_senddata(void __iomem *sbm_mdio, unsigned int data,
381 int bitcnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382{
383 int i;
384 uint64_t bits;
385 unsigned int curmask;
386 int mac_mdio_genc;
387
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100388 mac_mdio_genc = __raw_readq(sbm_mdio) & M_MAC_GENC;
Ralf Baechle74b02472005-10-19 15:40:02 +0100389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 bits = M_MAC_MDIO_DIR_OUTPUT;
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100391 __raw_writeq(bits | mac_mdio_genc, sbm_mdio);
Ralf Baechle74b02472005-10-19 15:40:02 +0100392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 curmask = 1 << (bitcnt - 1);
Ralf Baechle74b02472005-10-19 15:40:02 +0100394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 for (i = 0; i < bitcnt; i++) {
396 if (data & curmask)
397 bits |= M_MAC_MDIO_OUT;
398 else bits &= ~M_MAC_MDIO_OUT;
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100399 __raw_writeq(bits | mac_mdio_genc, sbm_mdio);
400 __raw_writeq(bits | M_MAC_MDC | mac_mdio_genc, sbm_mdio);
401 __raw_writeq(bits | mac_mdio_genc, sbm_mdio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 curmask >>= 1;
403 }
404}
405
406
407
408/**********************************************************************
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100409 * SBMAC_MII_READ(bus, phyaddr, regidx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 * Read a PHY register.
Ralf Baechle74b02472005-10-19 15:40:02 +0100411 *
412 * Input parameters:
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100413 * bus - MDIO bus handle
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 * phyaddr - PHY's address
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100415 * regnum - index of register to read
Ralf Baechle74b02472005-10-19 15:40:02 +0100416 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 * Return value:
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100418 * value read, or 0xffff if an error occurred.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 ********************************************************************* */
420
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100421static int sbmac_mii_read(struct mii_bus *bus, int phyaddr, int regidx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422{
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100423 struct sbmac_softc *sc = (struct sbmac_softc *)bus->priv;
424 void __iomem *sbm_mdio = sc->sbm_mdio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 int idx;
426 int error;
427 int regval;
428 int mac_mdio_genc;
429
430 /*
431 * Synchronize ourselves so that the PHY knows the next
432 * thing coming down is a command
433 */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100434 sbmac_mii_sync(sbm_mdio);
Ralf Baechle74b02472005-10-19 15:40:02 +0100435
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 /*
437 * Send the data to the PHY. The sequence is
438 * a "start" command (2 bits)
439 * a "read" command (2 bits)
440 * the PHY addr (5 bits)
441 * the register index (5 bits)
442 */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100443 sbmac_mii_senddata(sbm_mdio, MII_COMMAND_START, 2);
444 sbmac_mii_senddata(sbm_mdio, MII_COMMAND_READ, 2);
445 sbmac_mii_senddata(sbm_mdio, phyaddr, 5);
446 sbmac_mii_senddata(sbm_mdio, regidx, 5);
Ralf Baechle74b02472005-10-19 15:40:02 +0100447
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100448 mac_mdio_genc = __raw_readq(sbm_mdio) & M_MAC_GENC;
Ralf Baechle74b02472005-10-19 15:40:02 +0100449
450 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 * Switch the port around without a clock transition.
452 */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100453 __raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, sbm_mdio);
Ralf Baechle74b02472005-10-19 15:40:02 +0100454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 /*
456 * Send out a clock pulse to signal we want the status
457 */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100458 __raw_writeq(M_MAC_MDIO_DIR_INPUT | M_MAC_MDC | mac_mdio_genc,
459 sbm_mdio);
460 __raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, sbm_mdio);
Ralf Baechle74b02472005-10-19 15:40:02 +0100461
462 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 * If an error occurred, the PHY will signal '1' back
464 */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100465 error = __raw_readq(sbm_mdio) & M_MAC_MDIO_IN;
Ralf Baechle74b02472005-10-19 15:40:02 +0100466
467 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 * Issue an 'idle' clock pulse, but keep the direction
469 * the same.
470 */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100471 __raw_writeq(M_MAC_MDIO_DIR_INPUT | M_MAC_MDC | mac_mdio_genc,
472 sbm_mdio);
473 __raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, sbm_mdio);
Ralf Baechle74b02472005-10-19 15:40:02 +0100474
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 regval = 0;
Ralf Baechle74b02472005-10-19 15:40:02 +0100476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 for (idx = 0; idx < 16; idx++) {
478 regval <<= 1;
Ralf Baechle74b02472005-10-19 15:40:02 +0100479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 if (error == 0) {
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100481 if (__raw_readq(sbm_mdio) & M_MAC_MDIO_IN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 regval |= 1;
483 }
Ralf Baechle74b02472005-10-19 15:40:02 +0100484
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100485 __raw_writeq(M_MAC_MDIO_DIR_INPUT | M_MAC_MDC | mac_mdio_genc,
486 sbm_mdio);
487 __raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, sbm_mdio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 }
Ralf Baechle74b02472005-10-19 15:40:02 +0100489
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 /* Switch back to output */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100491 __raw_writeq(M_MAC_MDIO_DIR_OUTPUT | mac_mdio_genc, sbm_mdio);
Ralf Baechle74b02472005-10-19 15:40:02 +0100492
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 if (error == 0)
494 return regval;
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100495 return 0xffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496}
497
498
499/**********************************************************************
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100500 * SBMAC_MII_WRITE(bus, phyaddr, regidx, regval)
Ralf Baechle74b02472005-10-19 15:40:02 +0100501 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 * Write a value to a PHY register.
Ralf Baechle74b02472005-10-19 15:40:02 +0100503 *
504 * Input parameters:
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100505 * bus - MDIO bus handle
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 * phyaddr - PHY to use
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100507 * regidx - register within the PHY
508 * regval - data to write to register
Ralf Baechle74b02472005-10-19 15:40:02 +0100509 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 * Return value:
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100511 * 0 for success
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 ********************************************************************* */
513
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100514static int sbmac_mii_write(struct mii_bus *bus, int phyaddr, int regidx,
515 u16 regval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516{
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100517 struct sbmac_softc *sc = (struct sbmac_softc *)bus->priv;
518 void __iomem *sbm_mdio = sc->sbm_mdio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 int mac_mdio_genc;
520
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100521 sbmac_mii_sync(sbm_mdio);
Ralf Baechle74b02472005-10-19 15:40:02 +0100522
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100523 sbmac_mii_senddata(sbm_mdio, MII_COMMAND_START, 2);
524 sbmac_mii_senddata(sbm_mdio, MII_COMMAND_WRITE, 2);
525 sbmac_mii_senddata(sbm_mdio, phyaddr, 5);
526 sbmac_mii_senddata(sbm_mdio, regidx, 5);
527 sbmac_mii_senddata(sbm_mdio, MII_COMMAND_ACK, 2);
528 sbmac_mii_senddata(sbm_mdio, regval, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100530 mac_mdio_genc = __raw_readq(sbm_mdio) & M_MAC_GENC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100532 __raw_writeq(M_MAC_MDIO_DIR_OUTPUT | mac_mdio_genc, sbm_mdio);
533
534 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535}
536
537
538
539/**********************************************************************
540 * SBDMA_INITCTX(d,s,chan,txrx,maxdescr)
Ralf Baechle74b02472005-10-19 15:40:02 +0100541 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 * Initialize a DMA channel context. Since there are potentially
543 * eight DMA channels per MAC, it's nice to do this in a standard
Ralf Baechle74b02472005-10-19 15:40:02 +0100544 * way.
545 *
546 * Input parameters:
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100547 * d - struct sbmacdma (DMA channel context)
548 * s - struct sbmac_softc (pointer to a MAC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 * chan - channel number (0..1 right now)
550 * txrx - Identifies DMA_TX or DMA_RX for channel direction
551 * maxdescr - number of descriptors
Ralf Baechle74b02472005-10-19 15:40:02 +0100552 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 * Return value:
554 * nothing
555 ********************************************************************* */
556
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100557static void sbdma_initctx(struct sbmacdma *d, struct sbmac_softc *s, int chan,
558 int txrx, int maxdescr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559{
Mark Mason693aa942007-04-26 00:23:22 -0700560#ifdef CONFIG_SBMAC_COALESCE
561 int int_pktcnt, int_timeout;
562#endif
563
Ralf Baechle74b02472005-10-19 15:40:02 +0100564 /*
565 * Save away interesting stuff in the structure
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100567
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 d->sbdma_eth = s;
569 d->sbdma_channel = chan;
570 d->sbdma_txdir = txrx;
Ralf Baechle74b02472005-10-19 15:40:02 +0100571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572#if 0
573 /* RMON clearing */
574 s->sbe_idx =(s->sbm_base - A_MAC_BASE_0)/MAC_SPACING;
575#endif
576
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +0100577 __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_BYTES);
578 __raw_writeq(0, s->sbm_base + R_MAC_RMON_COLLISIONS);
579 __raw_writeq(0, s->sbm_base + R_MAC_RMON_LATE_COL);
580 __raw_writeq(0, s->sbm_base + R_MAC_RMON_EX_COL);
581 __raw_writeq(0, s->sbm_base + R_MAC_RMON_FCS_ERROR);
582 __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_ABORT);
583 __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_BAD);
584 __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_GOOD);
585 __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_RUNT);
586 __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_OVERSIZE);
587 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_BYTES);
588 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_MCAST);
589 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_BCAST);
590 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_BAD);
591 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_GOOD);
592 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_RUNT);
593 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_OVERSIZE);
594 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_FCS_ERROR);
595 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_LENGTH_ERROR);
596 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_CODE_ERROR);
597 __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_ALIGN_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
Ralf Baechle74b02472005-10-19 15:40:02 +0100599 /*
600 * initialize register pointers
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100602
603 d->sbdma_config0 =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CONFIG0);
Ralf Baechle74b02472005-10-19 15:40:02 +0100605 d->sbdma_config1 =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CONFIG1);
Ralf Baechle74b02472005-10-19 15:40:02 +0100607 d->sbdma_dscrbase =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_DSCR_BASE);
Ralf Baechle74b02472005-10-19 15:40:02 +0100609 d->sbdma_dscrcnt =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_DSCR_CNT);
Ralf Baechle74b02472005-10-19 15:40:02 +0100611 d->sbdma_curdscr =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CUR_DSCRADDR);
Mark Mason693aa942007-04-26 00:23:22 -0700613 if (d->sbdma_txdir)
614 d->sbdma_oodpktlost = NULL;
615 else
616 d->sbdma_oodpktlost =
617 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_OODPKTLOST_RX);
Ralf Baechle74b02472005-10-19 15:40:02 +0100618
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 /*
620 * Allocate memory for the ring
621 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100622
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 d->sbdma_maxdescr = maxdescr;
Ralf Baechle74b02472005-10-19 15:40:02 +0100624
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100625 d->sbdma_dscrtable_unaligned = kcalloc(d->sbdma_maxdescr + 1,
626 sizeof(*d->sbdma_dscrtable),
627 GFP_KERNEL);
Ralf Baechle04115de2005-10-10 14:50:36 +0100628
629 /*
630 * The descriptor table must be aligned to at least 16 bytes or the
631 * MAC will corrupt it.
632 */
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100633 d->sbdma_dscrtable = (struct sbdmadscr *)
634 ALIGN((unsigned long)d->sbdma_dscrtable_unaligned,
635 sizeof(*d->sbdma_dscrtable));
Ralf Baechle74b02472005-10-19 15:40:02 +0100636
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 d->sbdma_dscrtable_end = d->sbdma_dscrtable + d->sbdma_maxdescr;
Ralf Baechle74b02472005-10-19 15:40:02 +0100638
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 d->sbdma_dscrtable_phys = virt_to_phys(d->sbdma_dscrtable);
Ralf Baechle74b02472005-10-19 15:40:02 +0100640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 /*
642 * And context table
643 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100644
Mariusz Kozlowskic477f332007-07-31 23:58:36 +0200645 d->sbdma_ctxtable = kcalloc(d->sbdma_maxdescr,
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100646 sizeof(*d->sbdma_ctxtable), GFP_KERNEL);
Ralf Baechle74b02472005-10-19 15:40:02 +0100647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648#ifdef CONFIG_SBMAC_COALESCE
649 /*
650 * Setup Rx/Tx DMA coalescing defaults
651 */
652
Mark Mason693aa942007-04-26 00:23:22 -0700653 int_pktcnt = (txrx == DMA_TX) ? int_pktcnt_tx : int_pktcnt_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 if ( int_pktcnt ) {
655 d->sbdma_int_pktcnt = int_pktcnt;
656 } else {
657 d->sbdma_int_pktcnt = 1;
658 }
Ralf Baechle74b02472005-10-19 15:40:02 +0100659
Mark Mason693aa942007-04-26 00:23:22 -0700660 int_timeout = (txrx == DMA_TX) ? int_timeout_tx : int_timeout_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 if ( int_timeout ) {
662 d->sbdma_int_timeout = int_timeout;
663 } else {
664 d->sbdma_int_timeout = 0;
665 }
666#endif
667
668}
669
670/**********************************************************************
671 * SBDMA_CHANNEL_START(d)
Ralf Baechle74b02472005-10-19 15:40:02 +0100672 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 * Initialize the hardware registers for a DMA channel.
Ralf Baechle74b02472005-10-19 15:40:02 +0100674 *
675 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 * d - DMA channel to init (context must be previously init'd
677 * rxtx - DMA_RX or DMA_TX depending on what type of channel
Ralf Baechle74b02472005-10-19 15:40:02 +0100678 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 * Return value:
680 * nothing
681 ********************************************************************* */
682
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100683static void sbdma_channel_start(struct sbmacdma *d, int rxtx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684{
685 /*
686 * Turn on the DMA channel
687 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689#ifdef CONFIG_SBMAC_COALESCE
Ralf Baechle20399732005-10-19 15:39:05 +0100690 __raw_writeq(V_DMA_INT_TIMEOUT(d->sbdma_int_timeout) |
691 0, d->sbdma_config1);
692 __raw_writeq(M_DMA_EOP_INT_EN |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 V_DMA_RINGSZ(d->sbdma_maxdescr) |
694 V_DMA_INT_PKTCNT(d->sbdma_int_pktcnt) |
Ralf Baechle20399732005-10-19 15:39:05 +0100695 0, d->sbdma_config0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696#else
Ralf Baechle20399732005-10-19 15:39:05 +0100697 __raw_writeq(0, d->sbdma_config1);
698 __raw_writeq(V_DMA_RINGSZ(d->sbdma_maxdescr) |
699 0, d->sbdma_config0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700#endif
701
Ralf Baechle20399732005-10-19 15:39:05 +0100702 __raw_writeq(d->sbdma_dscrtable_phys, d->sbdma_dscrbase);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
704 /*
705 * Initialize ring pointers
706 */
707
708 d->sbdma_addptr = d->sbdma_dscrtable;
709 d->sbdma_remptr = d->sbdma_dscrtable;
710}
711
712/**********************************************************************
713 * SBDMA_CHANNEL_STOP(d)
Ralf Baechle74b02472005-10-19 15:40:02 +0100714 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 * Initialize the hardware registers for a DMA channel.
Ralf Baechle74b02472005-10-19 15:40:02 +0100716 *
717 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 * d - DMA channel to init (context must be previously init'd
Ralf Baechle74b02472005-10-19 15:40:02 +0100719 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 * Return value:
721 * nothing
722 ********************************************************************* */
723
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100724static void sbdma_channel_stop(struct sbmacdma *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725{
726 /*
727 * Turn off the DMA channel
728 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100729
Ralf Baechle20399732005-10-19 15:39:05 +0100730 __raw_writeq(0, d->sbdma_config1);
Ralf Baechle74b02472005-10-19 15:40:02 +0100731
Ralf Baechle20399732005-10-19 15:39:05 +0100732 __raw_writeq(0, d->sbdma_dscrbase);
Ralf Baechle74b02472005-10-19 15:40:02 +0100733
Ralf Baechle20399732005-10-19 15:39:05 +0100734 __raw_writeq(0, d->sbdma_config0);
Ralf Baechle74b02472005-10-19 15:40:02 +0100735
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 /*
737 * Zero ring pointers
738 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100739
Ralf Baechle20399732005-10-19 15:39:05 +0100740 d->sbdma_addptr = NULL;
741 d->sbdma_remptr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742}
743
Stephen Hemminger789585e2008-05-18 04:45:09 +0100744static inline void sbdma_align_skb(struct sk_buff *skb,
745 unsigned int power2, unsigned int offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746{
Stephen Hemminger789585e2008-05-18 04:45:09 +0100747 unsigned char *addr = skb->data;
748 unsigned char *newaddr = PTR_ALIGN(addr, power2);
Ralf Baechle74b02472005-10-19 15:40:02 +0100749
Stephen Hemminger789585e2008-05-18 04:45:09 +0100750 skb_reserve(skb, newaddr - addr + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751}
752
753
754/**********************************************************************
755 * SBDMA_ADD_RCVBUFFER(d,sb)
Ralf Baechle74b02472005-10-19 15:40:02 +0100756 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 * Add a buffer to the specified DMA channel. For receive channels,
758 * this queues a buffer for inbound packets.
Ralf Baechle74b02472005-10-19 15:40:02 +0100759 *
760 * Input parameters:
Stephen Hemminger789585e2008-05-18 04:45:09 +0100761 * sc - softc structure
762 * d - DMA channel descriptor
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 * sb - sk_buff to add, or NULL if we should allocate one
Ralf Baechle74b02472005-10-19 15:40:02 +0100764 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 * Return value:
766 * 0 if buffer could not be added (ring is full)
767 * 1 if buffer added successfully
768 ********************************************************************* */
769
770
Stephen Hemminger789585e2008-05-18 04:45:09 +0100771static int sbdma_add_rcvbuffer(struct sbmac_softc *sc, struct sbmacdma *d,
772 struct sk_buff *sb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773{
Stephen Hemminger789585e2008-05-18 04:45:09 +0100774 struct net_device *dev = sc->sbm_dev;
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100775 struct sbdmadscr *dsc;
776 struct sbdmadscr *nextdsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 struct sk_buff *sb_new = NULL;
778 int pktsize = ENET_PACKET_SIZE;
Ralf Baechle74b02472005-10-19 15:40:02 +0100779
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 /* get pointer to our current place in the ring */
Ralf Baechle74b02472005-10-19 15:40:02 +0100781
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 dsc = d->sbdma_addptr;
783 nextdsc = SBDMA_NEXTBUF(d,sbdma_addptr);
Ralf Baechle74b02472005-10-19 15:40:02 +0100784
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 /*
786 * figure out if the ring is full - if the next descriptor
787 * is the same as the one that we're going to remove from
788 * the ring, the ring is full
789 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100790
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 if (nextdsc == d->sbdma_remptr) {
792 return -ENOSPC;
793 }
794
Ralf Baechle74b02472005-10-19 15:40:02 +0100795 /*
796 * Allocate a sk_buff if we don't already have one.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 * If we do have an sk_buff, reset it so that it's empty.
798 *
799 * Note: sk_buffs don't seem to be guaranteed to have any sort
800 * of alignment when they are allocated. Therefore, allocate enough
801 * extra space to make sure that:
802 *
803 * 1. the data does not start in the middle of a cache line.
804 * 2. The data does not end in the middle of a cache line
Ralf Baechle74b02472005-10-19 15:40:02 +0100805 * 3. The buffer can be aligned such that the IP addresses are
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 * naturally aligned.
807 *
808 * Remember, the SOCs MAC writes whole cache lines at a time,
809 * without reading the old contents first. So, if the sk_buff's
810 * data portion starts in the middle of a cache line, the SOC
811 * DMA will trash the beginning (and ending) portions.
812 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100813
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 if (sb == NULL) {
Stephen Hemminger789585e2008-05-18 04:45:09 +0100815 sb_new = netdev_alloc_skb(dev, ENET_PACKET_SIZE +
816 SMP_CACHE_BYTES * 2 +
817 NET_IP_ALIGN);
Joe Perches720a43e2013-03-08 15:03:25 +0000818 if (sb_new == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 return -ENOBUFS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
Stephen Hemminger789585e2008-05-18 04:45:09 +0100821 sbdma_align_skb(sb_new, SMP_CACHE_BYTES, NET_IP_ALIGN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 }
823 else {
824 sb_new = sb;
Ralf Baechle74b02472005-10-19 15:40:02 +0100825 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 * nothing special to reinit buffer, it's already aligned
827 * and sb->data already points to a good place.
828 */
829 }
Ralf Baechle74b02472005-10-19 15:40:02 +0100830
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 /*
Ralf Baechle74b02472005-10-19 15:40:02 +0100832 * fill in the descriptor
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100834
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835#ifdef CONFIG_SBMAC_COALESCE
836 /*
837 * Do not interrupt per DMA transfer.
838 */
David S. Miller689be432005-06-28 15:25:31 -0700839 dsc->dscr_a = virt_to_phys(sb_new->data) |
Stephen Hemminger789585e2008-05-18 04:45:09 +0100840 V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize + NET_IP_ALIGN)) | 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841#else
David S. Miller689be432005-06-28 15:25:31 -0700842 dsc->dscr_a = virt_to_phys(sb_new->data) |
Stephen Hemminger789585e2008-05-18 04:45:09 +0100843 V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize + NET_IP_ALIGN)) |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 M_DMA_DSCRA_INTERRUPT;
845#endif
846
847 /* receiving: no options */
848 dsc->dscr_b = 0;
Ralf Baechle74b02472005-10-19 15:40:02 +0100849
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 /*
Ralf Baechle74b02472005-10-19 15:40:02 +0100851 * fill in the context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100853
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 d->sbdma_ctxtable[dsc-d->sbdma_dscrtable] = sb_new;
Ralf Baechle74b02472005-10-19 15:40:02 +0100855
856 /*
857 * point at next packet
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100859
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 d->sbdma_addptr = nextdsc;
Ralf Baechle74b02472005-10-19 15:40:02 +0100861
862 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 * Give the buffer to the DMA engine.
864 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100865
Ralf Baechle20399732005-10-19 15:39:05 +0100866 __raw_writeq(1, d->sbdma_dscrcnt);
Ralf Baechle74b02472005-10-19 15:40:02 +0100867
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 return 0; /* we did it */
869}
870
871/**********************************************************************
872 * SBDMA_ADD_TXBUFFER(d,sb)
Ralf Baechle74b02472005-10-19 15:40:02 +0100873 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 * Add a transmit buffer to the specified DMA channel, causing a
875 * transmit to start.
Ralf Baechle74b02472005-10-19 15:40:02 +0100876 *
877 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 * d - DMA channel descriptor
879 * sb - sk_buff to add
Ralf Baechle74b02472005-10-19 15:40:02 +0100880 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 * Return value:
882 * 0 transmit queued successfully
883 * otherwise error code
884 ********************************************************************* */
885
886
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100887static int sbdma_add_txbuffer(struct sbmacdma *d, struct sk_buff *sb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888{
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100889 struct sbdmadscr *dsc;
890 struct sbdmadscr *nextdsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 uint64_t phys;
892 uint64_t ncb;
893 int length;
Ralf Baechle74b02472005-10-19 15:40:02 +0100894
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 /* get pointer to our current place in the ring */
Ralf Baechle74b02472005-10-19 15:40:02 +0100896
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 dsc = d->sbdma_addptr;
898 nextdsc = SBDMA_NEXTBUF(d,sbdma_addptr);
Ralf Baechle74b02472005-10-19 15:40:02 +0100899
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 /*
901 * figure out if the ring is full - if the next descriptor
902 * is the same as the one that we're going to remove from
903 * the ring, the ring is full
904 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100905
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 if (nextdsc == d->sbdma_remptr) {
907 return -ENOSPC;
908 }
Ralf Baechle74b02472005-10-19 15:40:02 +0100909
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 /*
911 * Under Linux, it's not necessary to copy/coalesce buffers
912 * like it is on NetBSD. We think they're all contiguous,
913 * but that may not be true for GBE.
914 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 length = sb->len;
Ralf Baechle74b02472005-10-19 15:40:02 +0100917
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 /*
919 * fill in the descriptor. Note that the number of cache
920 * blocks in the descriptor is the number of blocks
921 * *spanned*, so we need to add in the offset (if any)
922 * while doing the calculation.
923 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100924
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 phys = virt_to_phys(sb->data);
926 ncb = NUMCACHEBLKS(length+(phys & (SMP_CACHE_BYTES - 1)));
927
Ralf Baechle74b02472005-10-19 15:40:02 +0100928 dsc->dscr_a = phys |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 V_DMA_DSCRA_A_SIZE(ncb) |
930#ifndef CONFIG_SBMAC_COALESCE
931 M_DMA_DSCRA_INTERRUPT |
932#endif
933 M_DMA_ETHTX_SOP;
Ralf Baechle74b02472005-10-19 15:40:02 +0100934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 /* transmitting: set outbound options and length */
936
937 dsc->dscr_b = V_DMA_DSCRB_OPTIONS(K_DMA_ETHTX_APPENDCRC_APPENDPAD) |
938 V_DMA_DSCRB_PKT_SIZE(length);
Ralf Baechle74b02472005-10-19 15:40:02 +0100939
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 /*
Ralf Baechle74b02472005-10-19 15:40:02 +0100941 * fill in the context
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100943
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 d->sbdma_ctxtable[dsc-d->sbdma_dscrtable] = sb;
Ralf Baechle74b02472005-10-19 15:40:02 +0100945
946 /*
947 * point at next packet
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100949
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 d->sbdma_addptr = nextdsc;
Ralf Baechle74b02472005-10-19 15:40:02 +0100951
952 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 * Give the buffer to the DMA engine.
954 */
Ralf Baechle74b02472005-10-19 15:40:02 +0100955
Ralf Baechle20399732005-10-19 15:39:05 +0100956 __raw_writeq(1, d->sbdma_dscrcnt);
Ralf Baechle74b02472005-10-19 15:40:02 +0100957
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 return 0; /* we did it */
959}
960
961
962
963
964/**********************************************************************
965 * SBDMA_EMPTYRING(d)
Ralf Baechle74b02472005-10-19 15:40:02 +0100966 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 * Free all allocated sk_buffs on the specified DMA channel;
Ralf Baechle74b02472005-10-19 15:40:02 +0100968 *
969 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 * d - DMA channel
Ralf Baechle74b02472005-10-19 15:40:02 +0100971 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 * Return value:
973 * nothing
974 ********************************************************************* */
975
Maciej W. Rozycki73d73962007-09-20 19:14:01 +0100976static void sbdma_emptyring(struct sbmacdma *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977{
978 int idx;
979 struct sk_buff *sb;
Ralf Baechle74b02472005-10-19 15:40:02 +0100980
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 for (idx = 0; idx < d->sbdma_maxdescr; idx++) {
982 sb = d->sbdma_ctxtable[idx];
983 if (sb) {
984 dev_kfree_skb(sb);
985 d->sbdma_ctxtable[idx] = NULL;
986 }
987 }
988}
989
990
991/**********************************************************************
992 * SBDMA_FILLRING(d)
Ralf Baechle74b02472005-10-19 15:40:02 +0100993 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 * Fill the specified DMA channel (must be receive channel)
995 * with sk_buffs
Ralf Baechle74b02472005-10-19 15:40:02 +0100996 *
997 * Input parameters:
Stephen Hemminger789585e2008-05-18 04:45:09 +0100998 * sc - softc structure
999 * d - DMA channel
Ralf Baechle74b02472005-10-19 15:40:02 +01001000 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 * Return value:
1002 * nothing
1003 ********************************************************************* */
1004
Stephen Hemminger789585e2008-05-18 04:45:09 +01001005static void sbdma_fillring(struct sbmac_softc *sc, struct sbmacdma *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006{
1007 int idx;
Ralf Baechle74b02472005-10-19 15:40:02 +01001008
Stephen Hemminger789585e2008-05-18 04:45:09 +01001009 for (idx = 0; idx < SBMAC_MAX_RXDESCR - 1; idx++) {
1010 if (sbdma_add_rcvbuffer(sc, d, NULL) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 break;
1012 }
1013}
1014
Deepak Saxenad6830012007-03-19 15:43:11 -07001015#ifdef CONFIG_NET_POLL_CONTROLLER
1016static void sbmac_netpoll(struct net_device *netdev)
1017{
1018 struct sbmac_softc *sc = netdev_priv(netdev);
1019 int irq = sc->sbm_dev->irq;
1020
1021 __raw_writeq(0, sc->sbm_imr);
1022
Yoann Padioleau0da2f0f2007-07-06 02:39:56 -07001023 sbmac_intr(irq, netdev);
Deepak Saxenad6830012007-03-19 15:43:11 -07001024
1025#ifdef CONFIG_SBMAC_COALESCE
1026 __raw_writeq(((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_TX_CH0) |
1027 ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_RX_CH0),
1028 sc->sbm_imr);
1029#else
Jeff Garzik7d2e3cb2008-05-13 01:41:58 -04001030 __raw_writeq((M_MAC_INT_CHANNEL << S_MAC_TX_CH0) |
Deepak Saxenad6830012007-03-19 15:43:11 -07001031 (M_MAC_INT_CHANNEL << S_MAC_RX_CH0), sc->sbm_imr);
1032#endif
1033}
1034#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
1036/**********************************************************************
Mark Mason693aa942007-04-26 00:23:22 -07001037 * SBDMA_RX_PROCESS(sc,d,work_to_do,poll)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 *
Ralf Baechle74b02472005-10-19 15:40:02 +01001039 * Process "completed" receive buffers on the specified DMA channel.
Ralf Baechle74b02472005-10-19 15:40:02 +01001040 *
1041 * Input parameters:
Mark Mason693aa942007-04-26 00:23:22 -07001042 * sc - softc structure
1043 * d - DMA channel context
1044 * work_to_do - no. of packets to process before enabling interrupt
1045 * again (for NAPI)
1046 * poll - 1: using polling (for NAPI)
Ralf Baechle74b02472005-10-19 15:40:02 +01001047 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 * Return value:
1049 * nothing
1050 ********************************************************************* */
1051
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001052static int sbdma_rx_process(struct sbmac_softc *sc, struct sbmacdma *d,
1053 int work_to_do, int poll)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054{
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001055 struct net_device *dev = sc->sbm_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 int curidx;
1057 int hwidx;
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001058 struct sbdmadscr *dsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 struct sk_buff *sb;
1060 int len;
Mark Mason693aa942007-04-26 00:23:22 -07001061 int work_done = 0;
1062 int dropped = 0;
Ralf Baechle74b02472005-10-19 15:40:02 +01001063
Mark Mason693aa942007-04-26 00:23:22 -07001064 prefetch(d);
1065
1066again:
1067 /* Check if the HW dropped any frames */
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001068 dev->stats.rx_fifo_errors
Mark Mason693aa942007-04-26 00:23:22 -07001069 += __raw_readq(sc->sbm_rxdma.sbdma_oodpktlost) & 0xffff;
1070 __raw_writeq(0, sc->sbm_rxdma.sbdma_oodpktlost);
1071
1072 while (work_to_do-- > 0) {
Ralf Baechle74b02472005-10-19 15:40:02 +01001073 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 * figure out where we are (as an index) and where
1075 * the hardware is (also as an index)
1076 *
Ralf Baechle74b02472005-10-19 15:40:02 +01001077 * This could be done faster if (for example) the
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 * descriptor table was page-aligned and contiguous in
1079 * both virtual and physical memory -- you could then
1080 * just compare the low-order bits of the virtual address
1081 * (sbdma_remptr) and the physical address (sbdma_curdscr CSR)
1082 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001083
Mark Mason693aa942007-04-26 00:23:22 -07001084 dsc = d->sbdma_remptr;
1085 curidx = dsc - d->sbdma_dscrtable;
1086
1087 prefetch(dsc);
1088 prefetch(&d->sbdma_ctxtable[curidx]);
1089
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001090 hwidx = ((__raw_readq(d->sbdma_curdscr) & M_DMA_CURDSCR_ADDR) -
1091 d->sbdma_dscrtable_phys) /
1092 sizeof(*d->sbdma_dscrtable);
Ralf Baechle74b02472005-10-19 15:40:02 +01001093
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 /*
1095 * If they're the same, that means we've processed all
1096 * of the descriptors up to (but not including) the one that
1097 * the hardware is working on right now.
1098 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001099
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 if (curidx == hwidx)
Mark Mason693aa942007-04-26 00:23:22 -07001101 goto done;
Ralf Baechle74b02472005-10-19 15:40:02 +01001102
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 /*
1104 * Otherwise, get the packet's sk_buff ptr back
1105 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001106
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 sb = d->sbdma_ctxtable[curidx];
1108 d->sbdma_ctxtable[curidx] = NULL;
Ralf Baechle74b02472005-10-19 15:40:02 +01001109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 len = (int)G_DMA_DSCRB_PKT_SIZE(dsc->dscr_b) - 4;
Ralf Baechle74b02472005-10-19 15:40:02 +01001111
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 /*
1113 * Check packet status. If good, process it.
1114 * If not, silently drop it and put it back on the
1115 * receive ring.
1116 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001117
Mark Mason693aa942007-04-26 00:23:22 -07001118 if (likely (!(dsc->dscr_a & M_DMA_ETHRX_BAD))) {
Ralf Baechle74b02472005-10-19 15:40:02 +01001119
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 /*
1121 * Add a new buffer to replace the old one. If we fail
1122 * to allocate a buffer, we're going to drop this
1123 * packet and put it right back on the receive ring.
1124 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001125
Stephen Hemminger789585e2008-05-18 04:45:09 +01001126 if (unlikely(sbdma_add_rcvbuffer(sc, d, NULL) ==
1127 -ENOBUFS)) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001128 dev->stats.rx_dropped++;
Stephen Hemminger789585e2008-05-18 04:45:09 +01001129 /* Re-add old buffer */
1130 sbdma_add_rcvbuffer(sc, d, sb);
Mark Mason693aa942007-04-26 00:23:22 -07001131 /* No point in continuing at the moment */
1132 printk(KERN_ERR "dropped packet (1)\n");
1133 d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr);
1134 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 } else {
1136 /*
1137 * Set length into the packet
1138 */
1139 skb_put(sb,len);
Ralf Baechle74b02472005-10-19 15:40:02 +01001140
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 /*
1142 * Buffer has been replaced on the
1143 * receive ring. Pass the buffer to
1144 * the kernel
1145 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 sb->protocol = eth_type_trans(sb,d->sbdma_eth->sbm_dev);
1147 /* Check hw IPv4/TCP checksum if supported */
1148 if (sc->rx_hw_checksum == ENABLE) {
1149 if (!((dsc->dscr_a) & M_DMA_ETHRX_BADIP4CS) &&
1150 !((dsc->dscr_a) & M_DMA_ETHRX_BADTCPCS)) {
1151 sb->ip_summed = CHECKSUM_UNNECESSARY;
1152 /* don't need to set sb->csum */
1153 } else {
Eric Dumazetbc8acf22010-09-02 13:07:41 -07001154 skb_checksum_none_assert(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 }
1156 }
Mark Mason693aa942007-04-26 00:23:22 -07001157 prefetch(sb->data);
1158 prefetch((const void *)(((char *)sb->data)+32));
1159 if (poll)
1160 dropped = netif_receive_skb(sb);
1161 else
1162 dropped = netif_rx(sb);
Ralf Baechle74b02472005-10-19 15:40:02 +01001163
Mark Mason693aa942007-04-26 00:23:22 -07001164 if (dropped == NET_RX_DROP) {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001165 dev->stats.rx_dropped++;
Mark Mason693aa942007-04-26 00:23:22 -07001166 d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr);
1167 goto done;
1168 }
1169 else {
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001170 dev->stats.rx_bytes += len;
1171 dev->stats.rx_packets++;
Mark Mason693aa942007-04-26 00:23:22 -07001172 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 }
1174 } else {
1175 /*
1176 * Packet was mangled somehow. Just drop it and
1177 * put it back on the receive ring.
1178 */
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001179 dev->stats.rx_errors++;
Stephen Hemminger789585e2008-05-18 04:45:09 +01001180 sbdma_add_rcvbuffer(sc, d, sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001182
1183
1184 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 * .. and advance to the next buffer.
1186 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001187
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr);
Mark Mason693aa942007-04-26 00:23:22 -07001189 work_done++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 }
Mark Mason693aa942007-04-26 00:23:22 -07001191 if (!poll) {
1192 work_to_do = 32;
1193 goto again; /* collect fifo drop statistics again */
1194 }
1195done:
1196 return work_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197}
1198
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199/**********************************************************************
1200 * SBDMA_TX_PROCESS(sc,d)
Ralf Baechle74b02472005-10-19 15:40:02 +01001201 *
1202 * Process "completed" transmit buffers on the specified DMA channel.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 * This is normally called within the interrupt service routine.
1204 * Note that this isn't really ideal for priority channels, since
Ralf Baechle74b02472005-10-19 15:40:02 +01001205 * it processes all of the packets on a given channel before
1206 * returning.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 *
Ralf Baechle74b02472005-10-19 15:40:02 +01001208 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 * sc - softc structure
Mark Mason693aa942007-04-26 00:23:22 -07001210 * d - DMA channel context
1211 * poll - 1: using polling (for NAPI)
Ralf Baechle74b02472005-10-19 15:40:02 +01001212 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 * Return value:
1214 * nothing
1215 ********************************************************************* */
1216
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001217static void sbdma_tx_process(struct sbmac_softc *sc, struct sbmacdma *d,
1218 int poll)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219{
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001220 struct net_device *dev = sc->sbm_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 int curidx;
1222 int hwidx;
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001223 struct sbdmadscr *dsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 struct sk_buff *sb;
1225 unsigned long flags;
Mark Mason693aa942007-04-26 00:23:22 -07001226 int packets_handled = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
1228 spin_lock_irqsave(&(sc->sbm_lock), flags);
Ralf Baechle74b02472005-10-19 15:40:02 +01001229
Mark Mason693aa942007-04-26 00:23:22 -07001230 if (d->sbdma_remptr == d->sbdma_addptr)
1231 goto end_unlock;
1232
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001233 hwidx = ((__raw_readq(d->sbdma_curdscr) & M_DMA_CURDSCR_ADDR) -
1234 d->sbdma_dscrtable_phys) / sizeof(*d->sbdma_dscrtable);
Mark Mason693aa942007-04-26 00:23:22 -07001235
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 for (;;) {
Ralf Baechle74b02472005-10-19 15:40:02 +01001237 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 * figure out where we are (as an index) and where
1239 * the hardware is (also as an index)
1240 *
Ralf Baechle74b02472005-10-19 15:40:02 +01001241 * This could be done faster if (for example) the
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 * descriptor table was page-aligned and contiguous in
1243 * both virtual and physical memory -- you could then
1244 * just compare the low-order bits of the virtual address
1245 * (sbdma_remptr) and the physical address (sbdma_curdscr CSR)
1246 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001247
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 curidx = d->sbdma_remptr - d->sbdma_dscrtable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
1250 /*
1251 * If they're the same, that means we've processed all
1252 * of the descriptors up to (but not including) the one that
1253 * the hardware is working on right now.
1254 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001255
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 if (curidx == hwidx)
1257 break;
Ralf Baechle74b02472005-10-19 15:40:02 +01001258
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 /*
1260 * Otherwise, get the packet's sk_buff ptr back
1261 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001262
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 dsc = &(d->sbdma_dscrtable[curidx]);
1264 sb = d->sbdma_ctxtable[curidx];
1265 d->sbdma_ctxtable[curidx] = NULL;
Ralf Baechle74b02472005-10-19 15:40:02 +01001266
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 /*
1268 * Stats
1269 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001270
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001271 dev->stats.tx_bytes += sb->len;
1272 dev->stats.tx_packets++;
Ralf Baechle74b02472005-10-19 15:40:02 +01001273
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 /*
1275 * for transmits, we just free buffers.
1276 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001277
Yang Weid2901b02019-02-06 00:25:54 +08001278 dev_consume_skb_irq(sb);
Ralf Baechle74b02472005-10-19 15:40:02 +01001279
1280 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 * .. and advance to the next buffer.
1282 */
1283
1284 d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr);
Ralf Baechle74b02472005-10-19 15:40:02 +01001285
Mark Mason693aa942007-04-26 00:23:22 -07001286 packets_handled++;
1287
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001289
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 /*
1291 * Decide if we should wake up the protocol or not.
1292 * Other drivers seem to do this when we reach a low
1293 * watermark on the transmit queue.
1294 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001295
Mark Mason693aa942007-04-26 00:23:22 -07001296 if (packets_handled)
1297 netif_wake_queue(d->sbdma_eth->sbm_dev);
Ralf Baechle74b02472005-10-19 15:40:02 +01001298
Mark Mason693aa942007-04-26 00:23:22 -07001299end_unlock:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 spin_unlock_irqrestore(&(sc->sbm_lock), flags);
Ralf Baechle74b02472005-10-19 15:40:02 +01001301
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302}
1303
1304
1305
1306/**********************************************************************
1307 * SBMAC_INITCTX(s)
Ralf Baechle74b02472005-10-19 15:40:02 +01001308 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 * Initialize an Ethernet context structure - this is called
1310 * once per MAC on the 1250. Memory is allocated here, so don't
1311 * call it again from inside the ioctl routines that bring the
1312 * interface up/down
Ralf Baechle74b02472005-10-19 15:40:02 +01001313 *
1314 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 * s - sbmac context structure
Ralf Baechle74b02472005-10-19 15:40:02 +01001316 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 * Return value:
1318 * 0
1319 ********************************************************************* */
1320
1321static int sbmac_initctx(struct sbmac_softc *s)
1322{
Ralf Baechle74b02472005-10-19 15:40:02 +01001323
1324 /*
1325 * figure out the addresses of some ports
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001327
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 s->sbm_macenable = s->sbm_base + R_MAC_ENABLE;
1329 s->sbm_maccfg = s->sbm_base + R_MAC_CFG;
1330 s->sbm_fifocfg = s->sbm_base + R_MAC_THRSH_CFG;
1331 s->sbm_framecfg = s->sbm_base + R_MAC_FRAMECFG;
1332 s->sbm_rxfilter = s->sbm_base + R_MAC_ADFILTER_CFG;
1333 s->sbm_isr = s->sbm_base + R_MAC_STATUS;
1334 s->sbm_imr = s->sbm_base + R_MAC_INT_MASK;
1335 s->sbm_mdio = s->sbm_base + R_MAC_MDIO;
1336
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 /*
1338 * Initialize the DMA channels. Right now, only one per MAC is used
1339 * Note: Only do this _once_, as it allocates memory from the kernel!
1340 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001341
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 sbdma_initctx(&(s->sbm_txdma),s,0,DMA_TX,SBMAC_MAX_TXDESCR);
1343 sbdma_initctx(&(s->sbm_rxdma),s,0,DMA_RX,SBMAC_MAX_RXDESCR);
Ralf Baechle74b02472005-10-19 15:40:02 +01001344
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 /*
1346 * initial state is OFF
1347 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001348
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 s->sbm_state = sbmac_state_off;
Ralf Baechle74b02472005-10-19 15:40:02 +01001350
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 return 0;
1352}
1353
1354
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001355static void sbdma_uninitctx(struct sbmacdma *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356{
Himanshu Jha0df49582017-08-27 01:47:47 +05301357 kfree(d->sbdma_dscrtable_unaligned);
1358 d->sbdma_dscrtable_unaligned = d->sbdma_dscrtable = NULL;
Ralf Baechle74b02472005-10-19 15:40:02 +01001359
Himanshu Jha0df49582017-08-27 01:47:47 +05301360 kfree(d->sbdma_ctxtable);
1361 d->sbdma_ctxtable = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362}
1363
1364
1365static void sbmac_uninitctx(struct sbmac_softc *sc)
1366{
1367 sbdma_uninitctx(&(sc->sbm_txdma));
1368 sbdma_uninitctx(&(sc->sbm_rxdma));
1369}
1370
1371
1372/**********************************************************************
1373 * SBMAC_CHANNEL_START(s)
Ralf Baechle74b02472005-10-19 15:40:02 +01001374 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 * Start packet processing on this MAC.
Ralf Baechle74b02472005-10-19 15:40:02 +01001376 *
1377 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 * s - sbmac structure
Ralf Baechle74b02472005-10-19 15:40:02 +01001379 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 * Return value:
1381 * nothing
1382 ********************************************************************* */
1383
1384static void sbmac_channel_start(struct sbmac_softc *s)
1385{
1386 uint64_t reg;
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001387 void __iomem *port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 uint64_t cfg,fifo,framecfg;
1389 int idx, th_value;
Ralf Baechle74b02472005-10-19 15:40:02 +01001390
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 /*
1392 * Don't do this if running
1393 */
1394
1395 if (s->sbm_state == sbmac_state_on)
1396 return;
Ralf Baechle74b02472005-10-19 15:40:02 +01001397
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 /*
1399 * Bring the controller out of reset, but leave it off.
1400 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001401
Ralf Baechle20399732005-10-19 15:39:05 +01001402 __raw_writeq(0, s->sbm_macenable);
Ralf Baechle74b02472005-10-19 15:40:02 +01001403
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 /*
1405 * Ignore all received packets
1406 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001407
Ralf Baechle20399732005-10-19 15:39:05 +01001408 __raw_writeq(0, s->sbm_rxfilter);
Ralf Baechle74b02472005-10-19 15:40:02 +01001409
1410 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 * Calculate values for various control registers.
1412 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001413
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 cfg = M_MAC_RETRY_EN |
Ralf Baechle74b02472005-10-19 15:40:02 +01001415 M_MAC_TX_HOLD_SOP_EN |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 V_MAC_TX_PAUSE_CNT_16K |
1417 M_MAC_AP_STAT_EN |
1418 M_MAC_FAST_SYNC |
1419 M_MAC_SS_EN |
1420 0;
Ralf Baechle74b02472005-10-19 15:40:02 +01001421
1422 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 * Be sure that RD_THRSH+WR_THRSH <= 32 for pass1 pars
1424 * and make sure that RD_THRSH + WR_THRSH <=128 for pass2 and above
1425 * Use a larger RD_THRSH for gigabit
1426 */
Ralf Baechlef90fdc32006-02-08 23:23:26 +00001427 if (soc_type == K_SYS_SOC_TYPE_BCM1250 && periph_rev < 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 th_value = 28;
Ralf Baechlef90fdc32006-02-08 23:23:26 +00001429 else
1430 th_value = 64;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431
1432 fifo = V_MAC_TX_WR_THRSH(4) | /* Must be '4' or '8' */
1433 ((s->sbm_speed == sbmac_speed_1000)
1434 ? V_MAC_TX_RD_THRSH(th_value) : V_MAC_TX_RD_THRSH(4)) |
1435 V_MAC_TX_RL_THRSH(4) |
1436 V_MAC_RX_PL_THRSH(4) |
1437 V_MAC_RX_RD_THRSH(4) | /* Must be '4' */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 V_MAC_RX_RL_THRSH(8) |
1439 0;
1440
1441 framecfg = V_MAC_MIN_FRAMESZ_DEFAULT |
1442 V_MAC_MAX_FRAMESZ_DEFAULT |
1443 V_MAC_BACKOFF_SEL(1);
1444
1445 /*
Ralf Baechle74b02472005-10-19 15:40:02 +01001446 * Clear out the hash address map
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001448
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 port = s->sbm_base + R_MAC_HASH_BASE;
1450 for (idx = 0; idx < MAC_HASH_COUNT; idx++) {
Ralf Baechle20399732005-10-19 15:39:05 +01001451 __raw_writeq(0, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 port += sizeof(uint64_t);
1453 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001454
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 /*
1456 * Clear out the exact-match table
1457 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001458
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 port = s->sbm_base + R_MAC_ADDR_BASE;
1460 for (idx = 0; idx < MAC_ADDR_COUNT; idx++) {
Ralf Baechle20399732005-10-19 15:39:05 +01001461 __raw_writeq(0, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 port += sizeof(uint64_t);
1463 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001464
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 /*
1466 * Clear out the DMA Channel mapping table registers
1467 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001468
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 port = s->sbm_base + R_MAC_CHUP0_BASE;
1470 for (idx = 0; idx < MAC_CHMAP_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 }
1474
1475
1476 port = s->sbm_base + R_MAC_CHLO0_BASE;
1477 for (idx = 0; idx < MAC_CHMAP_COUNT; idx++) {
Ralf Baechle20399732005-10-19 15:39:05 +01001478 __raw_writeq(0, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 port += sizeof(uint64_t);
1480 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001481
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 /*
1483 * Program the hardware address. It goes into the hardware-address
1484 * register as well as the first filter register.
1485 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001486
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 reg = sbmac_addr2reg(s->sbm_hwaddr);
Ralf Baechle74b02472005-10-19 15:40:02 +01001488
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 port = s->sbm_base + R_MAC_ADDR_BASE;
Ralf Baechle20399732005-10-19 15:39:05 +01001490 __raw_writeq(reg, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 port = s->sbm_base + R_MAC_ETHERNET_ADDR;
1492
Ralf Baechle20399732005-10-19 15:39:05 +01001493 __raw_writeq(reg, port);
Ralf Baechle74b02472005-10-19 15:40:02 +01001494
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 /*
1496 * Set the receive filter for no packets, and write values
1497 * to the various config registers
1498 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001499
Ralf Baechle20399732005-10-19 15:39:05 +01001500 __raw_writeq(0, s->sbm_rxfilter);
1501 __raw_writeq(0, s->sbm_imr);
1502 __raw_writeq(framecfg, s->sbm_framecfg);
1503 __raw_writeq(fifo, s->sbm_fifocfg);
1504 __raw_writeq(cfg, s->sbm_maccfg);
Ralf Baechle74b02472005-10-19 15:40:02 +01001505
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 /*
1507 * Initialize DMA channels (rings should be ok now)
1508 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001509
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 sbdma_channel_start(&(s->sbm_rxdma), DMA_RX);
1511 sbdma_channel_start(&(s->sbm_txdma), DMA_TX);
Ralf Baechle74b02472005-10-19 15:40:02 +01001512
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 /*
1514 * Configure the speed, duplex, and flow control
1515 */
1516
1517 sbmac_set_speed(s,s->sbm_speed);
1518 sbmac_set_duplex(s,s->sbm_duplex,s->sbm_fc);
Ralf Baechle74b02472005-10-19 15:40:02 +01001519
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 /*
1521 * Fill the receive ring
1522 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001523
Stephen Hemminger789585e2008-05-18 04:45:09 +01001524 sbdma_fillring(s, &(s->sbm_rxdma));
Ralf Baechle74b02472005-10-19 15:40:02 +01001525
1526 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 * Turn on the rest of the bits in the enable register
Ralf Baechle74b02472005-10-19 15:40:02 +01001528 */
1529
Ralf Baechlef90fdc32006-02-08 23:23:26 +00001530#if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
1531 __raw_writeq(M_MAC_RXDMA_EN0 |
1532 M_MAC_TXDMA_EN0, s->sbm_macenable);
1533#elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X)
Ralf Baechle20399732005-10-19 15:39:05 +01001534 __raw_writeq(M_MAC_RXDMA_EN0 |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 M_MAC_TXDMA_EN0 |
1536 M_MAC_RX_ENABLE |
Ralf Baechle20399732005-10-19 15:39:05 +01001537 M_MAC_TX_ENABLE, s->sbm_macenable);
Ralf Baechlef90fdc32006-02-08 23:23:26 +00001538#else
Thomas Weber0b1974d2010-09-23 11:46:48 +02001539#error invalid SiByte MAC configuration
Ralf Baechlef90fdc32006-02-08 23:23:26 +00001540#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
1542#ifdef CONFIG_SBMAC_COALESCE
Ralf Baechle20399732005-10-19 15:39:05 +01001543 __raw_writeq(((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_TX_CH0) |
1544 ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_RX_CH0), s->sbm_imr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545#else
Ralf Baechle20399732005-10-19 15:39:05 +01001546 __raw_writeq((M_MAC_INT_CHANNEL << S_MAC_TX_CH0) |
1547 (M_MAC_INT_CHANNEL << S_MAC_RX_CH0), s->sbm_imr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548#endif
Ralf Baechle74b02472005-10-19 15:40:02 +01001549
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 /*
Ralf Baechle74b02472005-10-19 15:40:02 +01001551 * Enable receiving unicasts and broadcasts
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001553
1554 __raw_writeq(M_MAC_UCAST_EN | M_MAC_BCAST_EN, s->sbm_rxfilter);
1555
1556 /*
1557 * we're running now.
1558 */
1559
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 s->sbm_state = sbmac_state_on;
Ralf Baechle74b02472005-10-19 15:40:02 +01001561
1562 /*
1563 * Program multicast addresses
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001565
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 sbmac_setmulti(s);
Ralf Baechle74b02472005-10-19 15:40:02 +01001567
1568 /*
1569 * If channel was in promiscuous mode before, turn that on
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001571
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 if (s->sbm_devflags & IFF_PROMISC) {
1573 sbmac_promiscuous_mode(s,1);
1574 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001575
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576}
1577
1578
1579/**********************************************************************
1580 * SBMAC_CHANNEL_STOP(s)
Ralf Baechle74b02472005-10-19 15:40:02 +01001581 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 * Stop packet processing on this MAC.
Ralf Baechle74b02472005-10-19 15:40:02 +01001583 *
1584 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 * s - sbmac structure
Ralf Baechle74b02472005-10-19 15:40:02 +01001586 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 * Return value:
1588 * nothing
1589 ********************************************************************* */
1590
1591static void sbmac_channel_stop(struct sbmac_softc *s)
1592{
1593 /* don't do this if already stopped */
Ralf Baechle74b02472005-10-19 15:40:02 +01001594
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 if (s->sbm_state == sbmac_state_off)
1596 return;
Ralf Baechle74b02472005-10-19 15:40:02 +01001597
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 /* don't accept any packets, disable all interrupts */
Ralf Baechle74b02472005-10-19 15:40:02 +01001599
Ralf Baechle20399732005-10-19 15:39:05 +01001600 __raw_writeq(0, s->sbm_rxfilter);
1601 __raw_writeq(0, s->sbm_imr);
Ralf Baechle74b02472005-10-19 15:40:02 +01001602
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 /* Turn off ticker */
Ralf Baechle74b02472005-10-19 15:40:02 +01001604
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 /* XXX */
Ralf Baechle74b02472005-10-19 15:40:02 +01001606
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 /* turn off receiver and transmitter */
Ralf Baechle74b02472005-10-19 15:40:02 +01001608
Ralf Baechle20399732005-10-19 15:39:05 +01001609 __raw_writeq(0, s->sbm_macenable);
Ralf Baechle74b02472005-10-19 15:40:02 +01001610
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 /* We're stopped now. */
Ralf Baechle74b02472005-10-19 15:40:02 +01001612
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 s->sbm_state = sbmac_state_off;
Ralf Baechle74b02472005-10-19 15:40:02 +01001614
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 /*
1616 * Stop DMA channels (rings should be ok now)
1617 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001618
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 sbdma_channel_stop(&(s->sbm_rxdma));
1620 sbdma_channel_stop(&(s->sbm_txdma));
Ralf Baechle74b02472005-10-19 15:40:02 +01001621
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 /* Empty the receive and transmit rings */
Ralf Baechle74b02472005-10-19 15:40:02 +01001623
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 sbdma_emptyring(&(s->sbm_rxdma));
1625 sbdma_emptyring(&(s->sbm_txdma));
Ralf Baechle74b02472005-10-19 15:40:02 +01001626
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627}
1628
1629/**********************************************************************
1630 * SBMAC_SET_CHANNEL_STATE(state)
Ralf Baechle74b02472005-10-19 15:40:02 +01001631 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 * Set the channel's state ON or OFF
Ralf Baechle74b02472005-10-19 15:40:02 +01001633 *
1634 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 * state - new state
Ralf Baechle74b02472005-10-19 15:40:02 +01001636 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 * Return value:
1638 * old state
1639 ********************************************************************* */
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001640static enum sbmac_state sbmac_set_channel_state(struct sbmac_softc *sc,
1641 enum sbmac_state state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642{
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001643 enum sbmac_state oldstate = sc->sbm_state;
Ralf Baechle74b02472005-10-19 15:40:02 +01001644
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 /*
1646 * If same as previous state, return
1647 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001648
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 if (state == oldstate) {
1650 return oldstate;
1651 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001652
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 /*
Ralf Baechle74b02472005-10-19 15:40:02 +01001654 * If new state is ON, turn channel on
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001656
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 if (state == sbmac_state_on) {
1658 sbmac_channel_start(sc);
1659 }
1660 else {
1661 sbmac_channel_stop(sc);
1662 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001663
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 /*
1665 * Return previous state
1666 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001667
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 return oldstate;
1669}
1670
1671
1672/**********************************************************************
1673 * SBMAC_PROMISCUOUS_MODE(sc,onoff)
Ralf Baechle74b02472005-10-19 15:40:02 +01001674 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 * Turn on or off promiscuous mode
Ralf Baechle74b02472005-10-19 15:40:02 +01001676 *
1677 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 * sc - softc
1679 * onoff - 1 to turn on, 0 to turn off
Ralf Baechle74b02472005-10-19 15:40:02 +01001680 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 * Return value:
1682 * nothing
1683 ********************************************************************* */
1684
1685static void sbmac_promiscuous_mode(struct sbmac_softc *sc,int onoff)
1686{
1687 uint64_t reg;
Ralf Baechle74b02472005-10-19 15:40:02 +01001688
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 if (sc->sbm_state != sbmac_state_on)
1690 return;
Ralf Baechle74b02472005-10-19 15:40:02 +01001691
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 if (onoff) {
Ralf Baechle20399732005-10-19 15:39:05 +01001693 reg = __raw_readq(sc->sbm_rxfilter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 reg |= M_MAC_ALLPKT_EN;
Ralf Baechle20399732005-10-19 15:39:05 +01001695 __raw_writeq(reg, sc->sbm_rxfilter);
Ralf Baechle74b02472005-10-19 15:40:02 +01001696 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 else {
Ralf Baechle20399732005-10-19 15:39:05 +01001698 reg = __raw_readq(sc->sbm_rxfilter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 reg &= ~M_MAC_ALLPKT_EN;
Ralf Baechle20399732005-10-19 15:39:05 +01001700 __raw_writeq(reg, sc->sbm_rxfilter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 }
1702}
1703
1704/**********************************************************************
1705 * SBMAC_SETIPHDR_OFFSET(sc,onoff)
Ralf Baechle74b02472005-10-19 15:40:02 +01001706 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 * Set the iphdr offset as 15 assuming ethernet encapsulation
Ralf Baechle74b02472005-10-19 15:40:02 +01001708 *
1709 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 * sc - softc
Ralf Baechle74b02472005-10-19 15:40:02 +01001711 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 * Return value:
1713 * nothing
1714 ********************************************************************* */
1715
1716static void sbmac_set_iphdr_offset(struct sbmac_softc *sc)
1717{
1718 uint64_t reg;
Ralf Baechle74b02472005-10-19 15:40:02 +01001719
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 /* Hard code the off set to 15 for now */
Ralf Baechle20399732005-10-19 15:39:05 +01001721 reg = __raw_readq(sc->sbm_rxfilter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 reg &= ~M_MAC_IPHDR_OFFSET | V_MAC_IPHDR_OFFSET(15);
Ralf Baechle20399732005-10-19 15:39:05 +01001723 __raw_writeq(reg, sc->sbm_rxfilter);
Ralf Baechle74b02472005-10-19 15:40:02 +01001724
Ralf Baechlef90fdc32006-02-08 23:23:26 +00001725 /* BCM1250 pass1 didn't have hardware checksum. Everything
1726 later does. */
1727 if (soc_type == K_SYS_SOC_TYPE_BCM1250 && periph_rev < 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 sc->rx_hw_checksum = DISABLE;
Ralf Baechlef90fdc32006-02-08 23:23:26 +00001729 } else {
1730 sc->rx_hw_checksum = ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 }
1732}
1733
1734
1735/**********************************************************************
1736 * SBMAC_ADDR2REG(ptr)
Ralf Baechle74b02472005-10-19 15:40:02 +01001737 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 * Convert six bytes into the 64-bit register value that
1739 * we typically write into the SBMAC's address/mcast registers
Ralf Baechle74b02472005-10-19 15:40:02 +01001740 *
1741 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 * ptr - pointer to 6 bytes
Ralf Baechle74b02472005-10-19 15:40:02 +01001743 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 * Return value:
1745 * register value
1746 ********************************************************************* */
1747
1748static uint64_t sbmac_addr2reg(unsigned char *ptr)
1749{
1750 uint64_t reg = 0;
Ralf Baechle74b02472005-10-19 15:40:02 +01001751
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 ptr += 6;
Ralf Baechle74b02472005-10-19 15:40:02 +01001753
1754 reg |= (uint64_t) *(--ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 reg <<= 8;
Ralf Baechle74b02472005-10-19 15:40:02 +01001756 reg |= (uint64_t) *(--ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 reg <<= 8;
Ralf Baechle74b02472005-10-19 15:40:02 +01001758 reg |= (uint64_t) *(--ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 reg <<= 8;
Ralf Baechle74b02472005-10-19 15:40:02 +01001760 reg |= (uint64_t) *(--ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 reg <<= 8;
Ralf Baechle74b02472005-10-19 15:40:02 +01001762 reg |= (uint64_t) *(--ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 reg <<= 8;
Ralf Baechle74b02472005-10-19 15:40:02 +01001764 reg |= (uint64_t) *(--ptr);
1765
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 return reg;
1767}
1768
1769
1770/**********************************************************************
1771 * SBMAC_SET_SPEED(s,speed)
Ralf Baechle74b02472005-10-19 15:40:02 +01001772 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 * Configure LAN speed for the specified MAC.
1774 * Warning: must be called when MAC is off!
Ralf Baechle74b02472005-10-19 15:40:02 +01001775 *
1776 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 * s - sbmac structure
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001778 * speed - speed to set MAC to (see enum sbmac_speed)
Ralf Baechle74b02472005-10-19 15:40:02 +01001779 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 * Return value:
1781 * 1 if successful
1782 * 0 indicates invalid parameters
1783 ********************************************************************* */
1784
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001785static int sbmac_set_speed(struct sbmac_softc *s, enum sbmac_speed speed)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786{
1787 uint64_t cfg;
1788 uint64_t framecfg;
1789
1790 /*
1791 * Save new current values
1792 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001793
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 s->sbm_speed = speed;
Ralf Baechle74b02472005-10-19 15:40:02 +01001795
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 if (s->sbm_state == sbmac_state_on)
1797 return 0; /* save for next restart */
1798
1799 /*
Ralf Baechle74b02472005-10-19 15:40:02 +01001800 * Read current register values
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001802
Ralf Baechle20399732005-10-19 15:39:05 +01001803 cfg = __raw_readq(s->sbm_maccfg);
1804 framecfg = __raw_readq(s->sbm_framecfg);
Ralf Baechle74b02472005-10-19 15:40:02 +01001805
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 /*
1807 * Mask out the stuff we want to change
1808 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001809
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 cfg &= ~(M_MAC_BURST_EN | M_MAC_SPEED_SEL);
1811 framecfg &= ~(M_MAC_IFG_RX | M_MAC_IFG_TX | M_MAC_IFG_THRSH |
1812 M_MAC_SLOT_SIZE);
Ralf Baechle74b02472005-10-19 15:40:02 +01001813
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 /*
1815 * Now add in the new bits
1816 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001817
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 switch (speed) {
1819 case sbmac_speed_10:
1820 framecfg |= V_MAC_IFG_RX_10 |
1821 V_MAC_IFG_TX_10 |
1822 K_MAC_IFG_THRSH_10 |
1823 V_MAC_SLOT_SIZE_10;
1824 cfg |= V_MAC_SPEED_SEL_10MBPS;
1825 break;
Ralf Baechle74b02472005-10-19 15:40:02 +01001826
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 case sbmac_speed_100:
1828 framecfg |= V_MAC_IFG_RX_100 |
1829 V_MAC_IFG_TX_100 |
1830 V_MAC_IFG_THRSH_100 |
1831 V_MAC_SLOT_SIZE_100;
1832 cfg |= V_MAC_SPEED_SEL_100MBPS ;
1833 break;
Ralf Baechle74b02472005-10-19 15:40:02 +01001834
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 case sbmac_speed_1000:
1836 framecfg |= V_MAC_IFG_RX_1000 |
1837 V_MAC_IFG_TX_1000 |
1838 V_MAC_IFG_THRSH_1000 |
1839 V_MAC_SLOT_SIZE_1000;
1840 cfg |= V_MAC_SPEED_SEL_1000MBPS | M_MAC_BURST_EN;
1841 break;
Ralf Baechle74b02472005-10-19 15:40:02 +01001842
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 default:
1844 return 0;
1845 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001846
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 /*
Ralf Baechle74b02472005-10-19 15:40:02 +01001848 * Send the bits back to the hardware
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001850
Ralf Baechle20399732005-10-19 15:39:05 +01001851 __raw_writeq(framecfg, s->sbm_framecfg);
1852 __raw_writeq(cfg, s->sbm_maccfg);
Ralf Baechle74b02472005-10-19 15:40:02 +01001853
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 return 1;
1855}
1856
1857/**********************************************************************
1858 * SBMAC_SET_DUPLEX(s,duplex,fc)
Ralf Baechle74b02472005-10-19 15:40:02 +01001859 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 * Set Ethernet duplex and flow control options for this MAC
1861 * Warning: must be called when MAC is off!
Ralf Baechle74b02472005-10-19 15:40:02 +01001862 *
1863 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 * s - sbmac structure
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001865 * duplex - duplex setting (see enum sbmac_duplex)
1866 * fc - flow control setting (see enum sbmac_fc)
Ralf Baechle74b02472005-10-19 15:40:02 +01001867 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 * Return value:
1869 * 1 if ok
1870 * 0 if an invalid parameter combination was specified
1871 ********************************************************************* */
1872
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01001873static int sbmac_set_duplex(struct sbmac_softc *s, enum sbmac_duplex duplex,
1874 enum sbmac_fc fc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875{
1876 uint64_t cfg;
Ralf Baechle74b02472005-10-19 15:40:02 +01001877
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 /*
1879 * Save new current values
1880 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001881
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 s->sbm_duplex = duplex;
1883 s->sbm_fc = fc;
Ralf Baechle74b02472005-10-19 15:40:02 +01001884
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 if (s->sbm_state == sbmac_state_on)
1886 return 0; /* save for next restart */
Ralf Baechle74b02472005-10-19 15:40:02 +01001887
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 /*
Ralf Baechle74b02472005-10-19 15:40:02 +01001889 * Read current register values
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001891
Ralf Baechle20399732005-10-19 15:39:05 +01001892 cfg = __raw_readq(s->sbm_maccfg);
Ralf Baechle74b02472005-10-19 15:40:02 +01001893
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 /*
1895 * Mask off the stuff we're about to change
1896 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001897
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 cfg &= ~(M_MAC_FC_SEL | M_MAC_FC_CMD | M_MAC_HDX_EN);
Ralf Baechle74b02472005-10-19 15:40:02 +01001899
1900
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 switch (duplex) {
1902 case sbmac_duplex_half:
1903 switch (fc) {
1904 case sbmac_fc_disabled:
1905 cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_DISABLED;
1906 break;
Ralf Baechle74b02472005-10-19 15:40:02 +01001907
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 case sbmac_fc_collision:
1909 cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_ENABLED;
1910 break;
Ralf Baechle74b02472005-10-19 15:40:02 +01001911
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 case sbmac_fc_carrier:
1913 cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_ENAB_FALSECARR;
1914 break;
Ralf Baechle74b02472005-10-19 15:40:02 +01001915
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 case sbmac_fc_frame: /* not valid in half duplex */
1917 default: /* invalid selection */
1918 return 0;
1919 }
1920 break;
Ralf Baechle74b02472005-10-19 15:40:02 +01001921
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 case sbmac_duplex_full:
1923 switch (fc) {
1924 case sbmac_fc_disabled:
1925 cfg |= V_MAC_FC_CMD_DISABLED;
1926 break;
Ralf Baechle74b02472005-10-19 15:40:02 +01001927
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 case sbmac_fc_frame:
1929 cfg |= V_MAC_FC_CMD_ENABLED;
1930 break;
Ralf Baechle74b02472005-10-19 15:40:02 +01001931
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 case sbmac_fc_collision: /* not valid in full duplex */
1933 case sbmac_fc_carrier: /* not valid in full duplex */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 default:
1935 return 0;
1936 }
1937 break;
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01001938 default:
1939 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 }
Ralf Baechle74b02472005-10-19 15:40:02 +01001941
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 /*
Ralf Baechle74b02472005-10-19 15:40:02 +01001943 * Send the bits back to the hardware
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001945
Ralf Baechle20399732005-10-19 15:39:05 +01001946 __raw_writeq(cfg, s->sbm_maccfg);
Ralf Baechle74b02472005-10-19 15:40:02 +01001947
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 return 1;
1949}
1950
1951
1952
1953
1954/**********************************************************************
1955 * SBMAC_INTR()
Ralf Baechle74b02472005-10-19 15:40:02 +01001956 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 * Interrupt handler for MAC interrupts
Ralf Baechle74b02472005-10-19 15:40:02 +01001958 *
1959 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 * MAC structure
Ralf Baechle74b02472005-10-19 15:40:02 +01001961 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 * Return value:
1963 * nothing
1964 ********************************************************************* */
David Howells7d12e782006-10-05 14:55:46 +01001965static irqreturn_t sbmac_intr(int irq,void *dev_instance)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966{
1967 struct net_device *dev = (struct net_device *) dev_instance;
1968 struct sbmac_softc *sc = netdev_priv(dev);
1969 uint64_t isr;
1970 int handled = 0;
1971
Mark Mason693aa942007-04-26 00:23:22 -07001972 /*
1973 * Read the ISR (this clears the bits in the real
1974 * register, except for counter addr)
1975 */
Ralf Baechle74b02472005-10-19 15:40:02 +01001976
Mark Mason693aa942007-04-26 00:23:22 -07001977 isr = __raw_readq(sc->sbm_isr) & ~M_MAC_COUNTER_ADDR;
Ralf Baechle74b02472005-10-19 15:40:02 +01001978
Mark Mason693aa942007-04-26 00:23:22 -07001979 if (isr == 0)
1980 return IRQ_RETVAL(0);
1981 handled = 1;
Ralf Baechle74b02472005-10-19 15:40:02 +01001982
Mark Mason693aa942007-04-26 00:23:22 -07001983 /*
1984 * Transmits on channel 0
1985 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001987 if (isr & (M_MAC_INT_CHANNEL << S_MAC_TX_CH0))
Mark Mason693aa942007-04-26 00:23:22 -07001988 sbdma_tx_process(sc,&(sc->sbm_txdma), 0);
Ralf Baechle74b02472005-10-19 15:40:02 +01001989
Mark Mason693aa942007-04-26 00:23:22 -07001990 if (isr & (M_MAC_INT_CHANNEL << S_MAC_RX_CH0)) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001991 if (napi_schedule_prep(&sc->napi)) {
Mark Mason693aa942007-04-26 00:23:22 -07001992 __raw_writeq(0, sc->sbm_imr);
Ben Hutchings288379f2009-01-19 16:43:59 -08001993 __napi_schedule(&sc->napi);
Mark Mason693aa942007-04-26 00:23:22 -07001994 /* Depend on the exit from poll to reenable intr */
1995 }
1996 else {
1997 /* may leave some packets behind */
1998 sbdma_rx_process(sc,&(sc->sbm_rxdma),
1999 SBMAC_MAX_RXDESCR * 2, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 }
2001 }
2002 return IRQ_RETVAL(handled);
2003}
2004
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005/**********************************************************************
2006 * SBMAC_START_TX(skb,dev)
Ralf Baechle74b02472005-10-19 15:40:02 +01002007 *
2008 * Start output on the specified interface. Basically, we
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 * queue as many buffers as we can until the ring fills up, or
2010 * we run off the end of the queue, whichever comes first.
Ralf Baechle74b02472005-10-19 15:40:02 +01002011 *
2012 * Input parameters:
2013 *
2014 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 * Return value:
2016 * nothing
2017 ********************************************************************* */
YueHaibing0c13b8d2018-09-19 18:45:12 +08002018static netdev_tx_t sbmac_start_tx(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019{
2020 struct sbmac_softc *sc = netdev_priv(dev);
Weiwei Wangbe61ea52008-09-18 08:23:48 +08002021 unsigned long flags;
Ralf Baechle74b02472005-10-19 15:40:02 +01002022
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 /* lock eth irq */
Weiwei Wangbe61ea52008-09-18 08:23:48 +08002024 spin_lock_irqsave(&sc->sbm_lock, flags);
Ralf Baechle74b02472005-10-19 15:40:02 +01002025
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 /*
Ralf Baechle74b02472005-10-19 15:40:02 +01002027 * Put the buffer on the transmit ring. If we
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 * don't have room, stop the queue.
2029 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002030
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 if (sbdma_add_txbuffer(&(sc->sbm_txdma),skb)) {
2032 /* XXX save skb that we could not send */
2033 netif_stop_queue(dev);
Weiwei Wangbe61ea52008-09-18 08:23:48 +08002034 spin_unlock_irqrestore(&sc->sbm_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035
Patrick McHardy5b548142009-06-12 06:22:29 +00002036 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 }
Ralf Baechle74b02472005-10-19 15:40:02 +01002038
Weiwei Wangbe61ea52008-09-18 08:23:48 +08002039 spin_unlock_irqrestore(&sc->sbm_lock, flags);
Ralf Baechle74b02472005-10-19 15:40:02 +01002040
Patrick McHardy6ed10652009-06-23 06:03:08 +00002041 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042}
2043
2044/**********************************************************************
2045 * SBMAC_SETMULTI(sc)
Ralf Baechle74b02472005-10-19 15:40:02 +01002046 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 * Reprogram the multicast table into the hardware, given
2048 * the list of multicasts associated with the interface
2049 * structure.
Ralf Baechle74b02472005-10-19 15:40:02 +01002050 *
2051 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 * sc - softc
Ralf Baechle74b02472005-10-19 15:40:02 +01002053 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 * Return value:
2055 * nothing
2056 ********************************************************************* */
2057
2058static void sbmac_setmulti(struct sbmac_softc *sc)
2059{
2060 uint64_t reg;
Maciej W. Rozycki73d73962007-09-20 19:14:01 +01002061 void __iomem *port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 int idx;
Jiri Pirko22bedad32010-04-01 21:22:57 +00002063 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 struct net_device *dev = sc->sbm_dev;
Ralf Baechle74b02472005-10-19 15:40:02 +01002065
2066 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 * Clear out entire multicast table. We do this by nuking
2068 * the entire hash table and all the direct matches except
Ralf Baechle74b02472005-10-19 15:40:02 +01002069 * the first one, which is used for our station address
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002071
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 for (idx = 1; idx < MAC_ADDR_COUNT; idx++) {
2073 port = sc->sbm_base + R_MAC_ADDR_BASE+(idx*sizeof(uint64_t));
Ralf Baechle20399732005-10-19 15:39:05 +01002074 __raw_writeq(0, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 }
Ralf Baechle74b02472005-10-19 15:40:02 +01002076
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 for (idx = 0; idx < MAC_HASH_COUNT; idx++) {
2078 port = sc->sbm_base + R_MAC_HASH_BASE+(idx*sizeof(uint64_t));
Ralf Baechle20399732005-10-19 15:39:05 +01002079 __raw_writeq(0, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 }
Ralf Baechle74b02472005-10-19 15:40:02 +01002081
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 /*
2083 * Clear the filter to say we don't want any multicasts.
2084 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002085
Ralf Baechle20399732005-10-19 15:39:05 +01002086 reg = __raw_readq(sc->sbm_rxfilter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 reg &= ~(M_MAC_MCAST_INV | M_MAC_MCAST_EN);
Ralf Baechle20399732005-10-19 15:39:05 +01002088 __raw_writeq(reg, sc->sbm_rxfilter);
Ralf Baechle74b02472005-10-19 15:40:02 +01002089
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 if (dev->flags & IFF_ALLMULTI) {
Ralf Baechle74b02472005-10-19 15:40:02 +01002091 /*
2092 * Enable ALL multicasts. Do this by inverting the
2093 * multicast enable bit.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 */
Ralf Baechle20399732005-10-19 15:39:05 +01002095 reg = __raw_readq(sc->sbm_rxfilter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 reg |= (M_MAC_MCAST_INV | M_MAC_MCAST_EN);
Ralf Baechle20399732005-10-19 15:39:05 +01002097 __raw_writeq(reg, sc->sbm_rxfilter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 return;
2099 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
Ralf Baechle74b02472005-10-19 15:40:02 +01002101
2102 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 * Progam new multicast entries. For now, only use the
2104 * perfect filter. In the future we'll need to use the
2105 * hash filter if the perfect filter overflows
2106 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002107
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 /* XXX only using perfect filter for now, need to use hash
2109 * XXX if the table overflows */
Ralf Baechle74b02472005-10-19 15:40:02 +01002110
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 idx = 1; /* skip station address */
Jiri Pirko22bedad32010-04-01 21:22:57 +00002112 netdev_for_each_mc_addr(ha, dev) {
Jiri Pirko55085902010-02-18 00:42:54 +00002113 if (idx == MAC_ADDR_COUNT)
2114 break;
Jiri Pirko22bedad32010-04-01 21:22:57 +00002115 reg = sbmac_addr2reg(ha->addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 port = sc->sbm_base + R_MAC_ADDR_BASE+(idx * sizeof(uint64_t));
Ralf Baechle20399732005-10-19 15:39:05 +01002117 __raw_writeq(reg, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 idx++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 }
Ralf Baechle74b02472005-10-19 15:40:02 +01002120
2121 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 * Enable the "accept multicast bits" if we programmed at least one
Ralf Baechle74b02472005-10-19 15:40:02 +01002123 * multicast.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002125
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 if (idx > 1) {
Ralf Baechle20399732005-10-19 15:39:05 +01002127 reg = __raw_readq(sc->sbm_rxfilter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 reg |= M_MAC_MCAST_EN;
Ralf Baechle20399732005-10-19 15:39:05 +01002129 __raw_writeq(reg, sc->sbm_rxfilter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 }
2131}
2132
Alexander Beregalovb4cf3422009-04-15 12:52:57 +00002133static const struct net_device_ops sbmac_netdev_ops = {
2134 .ndo_open = sbmac_open,
2135 .ndo_stop = sbmac_close,
2136 .ndo_start_xmit = sbmac_start_tx,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00002137 .ndo_set_rx_mode = sbmac_set_rx_mode,
Alexander Beregalovb4cf3422009-04-15 12:52:57 +00002138 .ndo_tx_timeout = sbmac_tx_timeout,
2139 .ndo_do_ioctl = sbmac_mii_ioctl,
Alexander Beregalovb4cf3422009-04-15 12:52:57 +00002140 .ndo_validate_addr = eth_validate_addr,
2141 .ndo_set_mac_address = eth_mac_addr,
2142#ifdef CONFIG_NET_POLL_CONTROLLER
2143 .ndo_poll_controller = sbmac_netpoll,
2144#endif
2145};
2146
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147/**********************************************************************
2148 * SBMAC_INIT(dev)
Ralf Baechle74b02472005-10-19 15:40:02 +01002149 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 * Attach routine - init hardware and hook ourselves into linux
Ralf Baechle74b02472005-10-19 15:40:02 +01002151 *
2152 * Input parameters:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 * dev - net_device structure
Ralf Baechle74b02472005-10-19 15:40:02 +01002154 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 * Return value:
2156 * status
2157 ********************************************************************* */
2158
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002159static int sbmac_init(struct platform_device *pldev, long long base)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160{
Jingoo Han8513fbd2013-05-23 00:52:31 +00002161 struct net_device *dev = platform_get_drvdata(pldev);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002162 int idx = pldev->id;
2163 struct sbmac_softc *sc = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 unsigned char *eaddr;
2165 uint64_t ea_reg;
2166 int i;
2167 int err;
Ralf Baechle74b02472005-10-19 15:40:02 +01002168
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 sc->sbm_dev = dev;
2170 sc->sbe_idx = idx;
Ralf Baechle74b02472005-10-19 15:40:02 +01002171
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 eaddr = sc->sbm_hwaddr;
Ralf Baechle74b02472005-10-19 15:40:02 +01002173
2174 /*
Nick Andrew877d0312009-01-26 11:06:57 +01002175 * Read the ethernet address. The firmware left this programmed
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 * for us in the ethernet address register for each mac.
2177 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002178
Ralf Baechle20399732005-10-19 15:39:05 +01002179 ea_reg = __raw_readq(sc->sbm_base + R_MAC_ETHERNET_ADDR);
2180 __raw_writeq(0, sc->sbm_base + R_MAC_ETHERNET_ADDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 for (i = 0; i < 6; i++) {
2182 eaddr[i] = (uint8_t) (ea_reg & 0xFF);
2183 ea_reg >>= 8;
2184 }
Ralf Baechle74b02472005-10-19 15:40:02 +01002185
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 for (i = 0; i < 6; i++) {
2187 dev->dev_addr[i] = eaddr[i];
2188 }
Ralf Baechle74b02472005-10-19 15:40:02 +01002189
Ralf Baechle74b02472005-10-19 15:40:02 +01002190 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 * Initialize context (get pointers to registers and stuff), then
2192 * allocate the memory for the descriptor tables.
2193 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002194
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 sbmac_initctx(sc);
Ralf Baechle74b02472005-10-19 15:40:02 +01002196
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 /*
2198 * Set up Linux device callins
2199 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002200
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 spin_lock_init(&(sc->sbm_lock));
Ralf Baechle74b02472005-10-19 15:40:02 +01002202
Alexander Beregalovb4cf3422009-04-15 12:52:57 +00002203 dev->netdev_ops = &sbmac_netdev_ops;
2204 dev->watchdog_timeo = TX_TIMEOUT;
Stefan Richter110447f82016-10-24 14:42:26 +02002205 dev->min_mtu = 0;
Jarod Wilsond894be52016-10-20 13:55:16 -04002206 dev->max_mtu = ENET_PACKET_SIZE;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002207
2208 netif_napi_add(dev, &sc->napi, sbmac_poll, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002210 dev->irq = UNIT_INT(idx);
2211
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 /* This is needed for PASS2 for Rx H/W checksum feature */
2213 sbmac_set_iphdr_offset(sc);
2214
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -07002215 sc->mii_bus = mdiobus_alloc();
2216 if (sc->mii_bus == NULL) {
Sebastian Siewior03f80cc2010-04-28 09:57:01 +00002217 err = -ENOMEM;
2218 goto uninit_ctx;
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -07002219 }
2220
Sebastian Siewior03f80cc2010-04-28 09:57:01 +00002221 sc->mii_bus->name = sbmac_mdio_string;
Florian Fainelli446bbc42012-01-09 23:59:10 +00002222 snprintf(sc->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
2223 pldev->name, idx);
Sebastian Siewior03f80cc2010-04-28 09:57:01 +00002224 sc->mii_bus->priv = sc;
2225 sc->mii_bus->read = sbmac_mii_read;
2226 sc->mii_bus->write = sbmac_mii_write;
Sebastian Siewior03f80cc2010-04-28 09:57:01 +00002227
2228 sc->mii_bus->parent = &pldev->dev;
2229 /*
2230 * Probe PHY address
2231 */
2232 err = mdiobus_register(sc->mii_bus);
2233 if (err) {
2234 printk(KERN_ERR "%s: unable to register MDIO bus\n",
2235 dev->name);
2236 goto free_mdio;
2237 }
Jingoo Han8513fbd2013-05-23 00:52:31 +00002238 platform_set_drvdata(pldev, sc->mii_bus);
Sebastian Siewior03f80cc2010-04-28 09:57:01 +00002239
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 err = register_netdev(dev);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002241 if (err) {
2242 printk(KERN_ERR "%s.%d: unable to register netdev\n",
2243 sbmac_string, idx);
Sebastian Siewior03f80cc2010-04-28 09:57:01 +00002244 goto unreg_mdio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 }
2246
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002247 pr_info("%s.%d: registered as %s\n", sbmac_string, idx, dev->name);
2248
2249 if (sc->rx_hw_checksum == ENABLE)
2250 pr_info("%s: enabling TCP rcv checksum\n", dev->name);
2251
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 /*
2253 * Display Ethernet address (this is called during the config
2254 * process so we need to finish off the config message that
2255 * was being displayed)
2256 */
Johannes Berge1749612008-10-27 15:59:26 -07002257 pr_info("%s: SiByte Ethernet at 0x%08Lx, address: %pM\n",
2258 dev->name, base, eaddr);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002259
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 return 0;
Sebastian Siewior03f80cc2010-04-28 09:57:01 +00002261unreg_mdio:
2262 mdiobus_unregister(sc->mii_bus);
Sebastian Siewior03f80cc2010-04-28 09:57:01 +00002263free_mdio:
2264 mdiobus_free(sc->mii_bus);
2265uninit_ctx:
2266 sbmac_uninitctx(sc);
2267 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268}
2269
2270
2271static int sbmac_open(struct net_device *dev)
2272{
2273 struct sbmac_softc *sc = netdev_priv(dev);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002274 int err;
Ralf Baechle74b02472005-10-19 15:40:02 +01002275
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002276 if (debug > 1)
2277 pr_debug("%s: sbmac_open() irq %d.\n", dev->name, dev->irq);
Ralf Baechle74b02472005-10-19 15:40:02 +01002278
2279 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 * map/route interrupt (clear status first, in case something
2281 * weird is pending; we haven't initialized the mac registers
2282 * yet)
2283 */
2284
Ralf Baechle20399732005-10-19 15:39:05 +01002285 __raw_readq(sc->sbm_isr);
Joe Perchesa0607fd2009-11-18 23:29:17 -08002286 err = request_irq(dev->irq, sbmac_intr, IRQF_SHARED, dev->name, dev);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002287 if (err) {
2288 printk(KERN_ERR "%s: unable to get IRQ %d\n", dev->name,
2289 dev->irq);
2290 goto out_err;
Ralf Baechle59b81822005-10-20 12:01:28 +01002291 }
2292
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002293 sc->sbm_speed = sbmac_speed_none;
2294 sc->sbm_duplex = sbmac_duplex_none;
2295 sc->sbm_fc = sbmac_fc_none;
2296 sc->sbm_pause = -1;
2297 sc->sbm_link = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002298
Ralf Baechle59b81822005-10-20 12:01:28 +01002299 /*
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002300 * Attach to the PHY
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 */
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002302 err = sbmac_mii_probe(dev);
2303 if (err)
2304 goto out_unregister;
Ralf Baechle74b02472005-10-19 15:40:02 +01002305
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 /*
2307 * Turn on the channel
2308 */
2309
2310 sbmac_set_channel_state(sc,sbmac_state_on);
Ralf Baechle74b02472005-10-19 15:40:02 +01002311
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 netif_start_queue(dev);
Ralf Baechle74b02472005-10-19 15:40:02 +01002313
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 sbmac_set_rx_mode(dev);
Ralf Baechle74b02472005-10-19 15:40:02 +01002315
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002316 phy_start(sc->phy_dev);
2317
2318 napi_enable(&sc->napi);
Ralf Baechle74b02472005-10-19 15:40:02 +01002319
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 return 0;
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002321
2322out_unregister:
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002323 free_irq(dev->irq, dev);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002324out_err:
2325 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326}
2327
Ralf Baechle59b81822005-10-20 12:01:28 +01002328static int sbmac_mii_probe(struct net_device *dev)
2329{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 struct sbmac_softc *sc = netdev_priv(dev);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002331 struct phy_device *phy_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332
Guenter Roeckee64f082016-01-10 12:03:16 -08002333 phy_dev = phy_find_first(sc->mii_bus);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002334 if (!phy_dev) {
2335 printk(KERN_ERR "%s: no PHY found\n", dev->name);
2336 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 }
Ralf Baechle74b02472005-10-19 15:40:02 +01002338
Andrew Lunne5a03bf2016-01-06 20:11:16 +01002339 phy_dev = phy_connect(dev, dev_name(&phy_dev->mdio.dev),
2340 &sbmac_mii_poll, PHY_INTERFACE_MODE_GMII);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002341 if (IS_ERR(phy_dev)) {
2342 printk(KERN_ERR "%s: could not attach to PHY\n", dev->name);
2343 return PTR_ERR(phy_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 }
Ralf Baechle74b02472005-10-19 15:40:02 +01002345
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002346 /* Remove any features not supported by the controller */
Andrew Lunn58056c12018-09-12 01:53:11 +02002347 phy_set_max_speed(phy_dev, SPEED_1000);
Andrew Lunnaf8d9bb2018-09-12 01:53:15 +02002348 phy_support_asym_pause(phy_dev);
Ralf Baechle74b02472005-10-19 15:40:02 +01002349
Guenter Roeckee64f082016-01-10 12:03:16 -08002350 phy_attached_info(phy_dev);
Andrew Lunn22209432016-01-06 20:11:13 +01002351
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002352 sc->phy_dev = phy_dev;
2353
2354 return 0;
2355}
2356
2357
2358static void sbmac_mii_poll(struct net_device *dev)
2359{
2360 struct sbmac_softc *sc = netdev_priv(dev);
2361 struct phy_device *phy_dev = sc->phy_dev;
2362 unsigned long flags;
2363 enum sbmac_fc fc;
2364 int link_chg, speed_chg, duplex_chg, pause_chg, fc_chg;
2365
2366 link_chg = (sc->sbm_link != phy_dev->link);
2367 speed_chg = (sc->sbm_speed != phy_dev->speed);
2368 duplex_chg = (sc->sbm_duplex != phy_dev->duplex);
2369 pause_chg = (sc->sbm_pause != phy_dev->pause);
2370
2371 if (!link_chg && !speed_chg && !duplex_chg && !pause_chg)
2372 return; /* Hmmm... */
2373
2374 if (!phy_dev->link) {
2375 if (link_chg) {
2376 sc->sbm_link = phy_dev->link;
2377 sc->sbm_speed = sbmac_speed_none;
2378 sc->sbm_duplex = sbmac_duplex_none;
2379 sc->sbm_fc = sbmac_fc_disabled;
2380 sc->sbm_pause = -1;
2381 pr_info("%s: link unavailable\n", dev->name);
2382 }
2383 return;
2384 }
2385
2386 if (phy_dev->duplex == DUPLEX_FULL) {
2387 if (phy_dev->pause)
2388 fc = sbmac_fc_frame;
2389 else
2390 fc = sbmac_fc_disabled;
2391 } else
2392 fc = sbmac_fc_collision;
2393 fc_chg = (sc->sbm_fc != fc);
2394
2395 pr_info("%s: link available: %dbase-%cD\n", dev->name, phy_dev->speed,
2396 phy_dev->duplex == DUPLEX_FULL ? 'F' : 'H');
2397
2398 spin_lock_irqsave(&sc->sbm_lock, flags);
2399
2400 sc->sbm_speed = phy_dev->speed;
2401 sc->sbm_duplex = phy_dev->duplex;
2402 sc->sbm_fc = fc;
2403 sc->sbm_pause = phy_dev->pause;
2404 sc->sbm_link = phy_dev->link;
2405
2406 if ((speed_chg || duplex_chg || fc_chg) &&
2407 sc->sbm_state != sbmac_state_off) {
2408 /*
2409 * something changed, restart the channel
2410 */
2411 if (debug > 1)
2412 pr_debug("%s: restarting channel "
2413 "because PHY state changed\n", dev->name);
2414 sbmac_channel_stop(sc);
2415 sbmac_channel_start(sc);
2416 }
2417
2418 spin_unlock_irqrestore(&sc->sbm_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419}
2420
2421
Michael S. Tsirkin0290bd22019-12-10 09:23:51 -05002422static void sbmac_tx_timeout (struct net_device *dev, unsigned int txqueue)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423{
2424 struct sbmac_softc *sc = netdev_priv(dev);
Weiwei Wangbe61ea52008-09-18 08:23:48 +08002425 unsigned long flags;
Ralf Baechle74b02472005-10-19 15:40:02 +01002426
Weiwei Wangbe61ea52008-09-18 08:23:48 +08002427 spin_lock_irqsave(&sc->sbm_lock, flags);
Ralf Baechle74b02472005-10-19 15:40:02 +01002428
2429
Florian Westphal860e9532016-05-03 16:33:13 +02002430 netif_trans_update(dev); /* prevent tx timeout */
Jeff Garzik09f75cd2007-10-03 17:41:50 -07002431 dev->stats.tx_errors++;
Ralf Baechle74b02472005-10-19 15:40:02 +01002432
Weiwei Wangbe61ea52008-09-18 08:23:48 +08002433 spin_unlock_irqrestore(&sc->sbm_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434
2435 printk (KERN_WARNING "%s: Transmit timed out\n",dev->name);
2436}
2437
2438
2439
2440
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441static void sbmac_set_rx_mode(struct net_device *dev)
2442{
2443 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 struct sbmac_softc *sc = netdev_priv(dev);
2445
2446 spin_lock_irqsave(&sc->sbm_lock, flags);
2447 if ((dev->flags ^ sc->sbm_devflags) & IFF_PROMISC) {
2448 /*
2449 * Promiscuous changed.
2450 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002451
2452 if (dev->flags & IFF_PROMISC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 sbmac_promiscuous_mode(sc,1);
2454 }
2455 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 sbmac_promiscuous_mode(sc,0);
2457 }
2458 }
2459 spin_unlock_irqrestore(&sc->sbm_lock, flags);
Ralf Baechle74b02472005-10-19 15:40:02 +01002460
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 /*
2462 * Program the multicasts. Do this every time.
2463 */
Ralf Baechle74b02472005-10-19 15:40:02 +01002464
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 sbmac_setmulti(sc);
Ralf Baechle74b02472005-10-19 15:40:02 +01002466
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467}
2468
2469static int sbmac_mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2470{
2471 struct sbmac_softc *sc = netdev_priv(dev);
Ralf Baechle74b02472005-10-19 15:40:02 +01002472
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002473 if (!netif_running(dev) || !sc->phy_dev)
2474 return -EINVAL;
Ralf Baechle74b02472005-10-19 15:40:02 +01002475
Richard Cochran28b04112010-07-17 08:48:55 +00002476 return phy_mii_ioctl(sc->phy_dev, rq, cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477}
2478
2479static int sbmac_close(struct net_device *dev)
2480{
2481 struct sbmac_softc *sc = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002483 napi_disable(&sc->napi);
2484
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002485 phy_stop(sc->phy_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002487 sbmac_set_channel_state(sc, sbmac_state_off);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488
2489 netif_stop_queue(dev);
2490
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002491 if (debug > 1)
2492 pr_debug("%s: Shutting down ethercard\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002494 phy_disconnect(sc->phy_dev);
2495 sc->phy_dev = NULL;
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002496 free_irq(dev->irq, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497
2498 sbdma_emptyring(&(sc->sbm_txdma));
2499 sbdma_emptyring(&(sc->sbm_rxdma));
Ralf Baechle74b02472005-10-19 15:40:02 +01002500
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 return 0;
2502}
2503
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002504static int sbmac_poll(struct napi_struct *napi, int budget)
Mark Mason693aa942007-04-26 00:23:22 -07002505{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002506 struct sbmac_softc *sc = container_of(napi, struct sbmac_softc, napi);
Mark Mason693aa942007-04-26 00:23:22 -07002507 int work_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002509 work_done = sbdma_rx_process(sc, &(sc->sbm_rxdma), budget, 1);
Mark Mason693aa942007-04-26 00:23:22 -07002510 sbdma_tx_process(sc, &(sc->sbm_txdma), 1);
2511
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002512 if (work_done < budget) {
Eric Dumazet6ad20162017-01-30 08:22:01 -08002513 napi_complete_done(napi, work_done);
Mark Mason693aa942007-04-26 00:23:22 -07002514
2515#ifdef CONFIG_SBMAC_COALESCE
2516 __raw_writeq(((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_TX_CH0) |
2517 ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_RX_CH0),
2518 sc->sbm_imr);
2519#else
2520 __raw_writeq((M_MAC_INT_CHANNEL << S_MAC_TX_CH0) |
2521 (M_MAC_INT_CHANNEL << S_MAC_RX_CH0), sc->sbm_imr);
2522#endif
2523 }
2524
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002525 return work_done;
Mark Mason693aa942007-04-26 00:23:22 -07002526}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002528
Bill Pemberton047fc562012-12-03 09:24:23 -05002529static int sbmac_probe(struct platform_device *pldev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530{
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002531 struct net_device *dev;
2532 struct sbmac_softc *sc;
2533 void __iomem *sbm_base;
2534 struct resource *res;
2535 u64 sbmac_orig_hwaddr;
2536 int err;
2537
2538 res = platform_get_resource(pldev, IORESOURCE_MEM, 0);
2539 BUG_ON(!res);
Joe Perches28f65c112011-06-09 09:13:32 -07002540 sbm_base = ioremap_nocache(res->start, resource_size(res));
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002541 if (!sbm_base) {
2542 printk(KERN_ERR "%s: unable to map device registers\n",
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08002543 dev_name(&pldev->dev));
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002544 err = -ENOMEM;
2545 goto out_out;
2546 }
2547
2548 /*
2549 * The R_MAC_ETHERNET_ADDR register will be set to some nonzero
2550 * value for us by the firmware if we're going to use this MAC.
2551 * If we find a zero, skip this MAC.
2552 */
2553 sbmac_orig_hwaddr = __raw_readq(sbm_base + R_MAC_ETHERNET_ADDR);
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08002554 pr_debug("%s: %sconfiguring MAC at 0x%08Lx\n", dev_name(&pldev->dev),
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002555 sbmac_orig_hwaddr ? "" : "not ", (long long)res->start);
2556 if (sbmac_orig_hwaddr == 0) {
2557 err = 0;
2558 goto out_unmap;
2559 }
2560
2561 /*
2562 * Okay, cool. Initialize this MAC.
2563 */
2564 dev = alloc_etherdev(sizeof(struct sbmac_softc));
2565 if (!dev) {
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002566 err = -ENOMEM;
2567 goto out_unmap;
2568 }
2569
Jingoo Han8513fbd2013-05-23 00:52:31 +00002570 platform_set_drvdata(pldev, dev);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002571 SET_NETDEV_DEV(dev, &pldev->dev);
2572
2573 sc = netdev_priv(dev);
2574 sc->sbm_base = sbm_base;
2575
2576 err = sbmac_init(pldev, res->start);
2577 if (err)
2578 goto out_kfree;
2579
2580 return 0;
2581
2582out_kfree:
2583 free_netdev(dev);
2584 __raw_writeq(sbmac_orig_hwaddr, sbm_base + R_MAC_ETHERNET_ADDR);
2585
2586out_unmap:
2587 iounmap(sbm_base);
2588
2589out_out:
2590 return err;
2591}
2592
Dmitry Torokhovbe125022017-03-01 17:24:47 -08002593static int sbmac_remove(struct platform_device *pldev)
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002594{
Jingoo Han8513fbd2013-05-23 00:52:31 +00002595 struct net_device *dev = platform_get_drvdata(pldev);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002596 struct sbmac_softc *sc = netdev_priv(dev);
2597
2598 unregister_netdev(dev);
2599 sbmac_uninitctx(sc);
Sebastian Siewior03f80cc2010-04-28 09:57:01 +00002600 mdiobus_unregister(sc->mii_bus);
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -07002601 mdiobus_free(sc->mii_bus);
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002602 iounmap(sc->sbm_base);
2603 free_netdev(dev);
2604
2605 return 0;
2606}
2607
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002608static struct platform_driver sbmac_driver = {
2609 .probe = sbmac_probe,
Dmitry Torokhovbe125022017-03-01 17:24:47 -08002610 .remove = sbmac_remove,
Maciej W. Rozyckif5279ff2007-09-21 12:52:10 +01002611 .driver = {
2612 .name = sbmac_string,
2613 },
2614};
2615
Axel Lindb62f682011-11-27 16:44:17 +00002616module_platform_driver(sbmac_driver);
Ralf Baechlea98e1782017-04-21 03:06:06 +02002617MODULE_LICENSE("GPL");