2005-04-17 00:20:36 +02:00
|
|
|
/*
|
2006-02-09 00:23:26 +01:00
|
|
|
* Copyright (C) 2001,2002,2003,2004 Broadcom Corporation
|
2005-04-17 00:20:36 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This driver is designed for the Broadcom SiByte SOC built-in
|
|
|
|
* Ethernet controllers. Written by Mitch Lichtenberg at Broadcom Corp.
|
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/config.h>
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <asm/processor.h> /* Processor type for cache alignment. */
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/cache.h>
|
|
|
|
|
|
|
|
/* This is only here until the firmware is ready. In that case,
|
|
|
|
the firmware leaves the ethernet address in the register for us. */
|
|
|
|
#ifdef CONFIG_SIBYTE_STANDALONE
|
|
|
|
#define SBMAC_ETH0_HWADDR "40:00:00:00:01:00"
|
|
|
|
#define SBMAC_ETH1_HWADDR "40:00:00:00:01:01"
|
|
|
|
#define SBMAC_ETH2_HWADDR "40:00:00:00:01:02"
|
2006-02-09 00:23:26 +01:00
|
|
|
#define SBMAC_ETH3_HWADDR "40:00:00:00:01:03"
|
2005-04-17 00:20:36 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* These identify the driver base version and may not be removed. */
|
|
|
|
#if 0
|
|
|
|
static char version1[] __devinitdata =
|
|
|
|
"sb1250-mac.c:1.00 1/11/2001 Written by Mitch Lichtenberg\n";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* Operational parameters that usually are not changed. */
|
|
|
|
|
|
|
|
#define CONFIG_SBMAC_COALESCE
|
|
|
|
|
2006-02-09 00:23:26 +01:00
|
|
|
#define MAX_UNITS 4 /* More are supported, limit only on options */
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* Time in jiffies before concluding the transmitter is hung. */
|
|
|
|
#define TX_TIMEOUT (2*HZ)
|
|
|
|
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Mitch Lichtenberg (Broadcom Corp.)");
|
|
|
|
MODULE_DESCRIPTION("Broadcom SiByte SOC GB Ethernet driver");
|
|
|
|
|
|
|
|
/* A few user-configurable values which may be modified when a driver
|
|
|
|
module is loaded. */
|
|
|
|
|
|
|
|
/* 1 normal messages, 0 quiet .. 7 verbose. */
|
|
|
|
static int debug = 1;
|
|
|
|
module_param(debug, int, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(debug, "Debug messages");
|
|
|
|
|
|
|
|
/* mii status msgs */
|
|
|
|
static int noisy_mii = 1;
|
|
|
|
module_param(noisy_mii, int, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(noisy_mii, "MII status messages");
|
|
|
|
|
|
|
|
/* Used to pass the media type, etc.
|
|
|
|
Both 'options[]' and 'full_duplex[]' should exist for driver
|
|
|
|
interoperability.
|
|
|
|
The media type is usually passed in 'options[]'.
|
|
|
|
*/
|
|
|
|
#ifdef MODULE
|
2006-02-09 00:23:26 +01:00
|
|
|
static int options[MAX_UNITS] = {-1, -1, -1, -1};
|
2005-04-17 00:20:36 +02:00
|
|
|
module_param_array(options, int, NULL, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(options, "1-" __MODULE_STRING(MAX_UNITS));
|
|
|
|
|
2006-02-09 00:23:26 +01:00
|
|
|
static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1};
|
2005-04-17 00:20:36 +02:00
|
|
|
module_param_array(full_duplex, int, NULL, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(full_duplex, "1-" __MODULE_STRING(MAX_UNITS));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_SBMAC_COALESCE
|
|
|
|
static int int_pktcnt = 0;
|
|
|
|
module_param(int_pktcnt, int, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(int_pktcnt, "Packet count");
|
|
|
|
|
|
|
|
static int int_timeout = 0;
|
|
|
|
module_param(int_timeout, int, S_IRUGO);
|
|
|
|
MODULE_PARM_DESC(int_timeout, "Timeout value");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <asm/sibyte/sb1250.h>
|
2006-02-09 00:23:26 +01:00
|
|
|
#if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
|
|
|
|
#include <asm/sibyte/bcm1480_regs.h>
|
|
|
|
#include <asm/sibyte/bcm1480_int.h>
|
|
|
|
#elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X)
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <asm/sibyte/sb1250_regs.h>
|
|
|
|
#include <asm/sibyte/sb1250_int.h>
|
2006-02-09 00:23:26 +01:00
|
|
|
#else
|
|
|
|
#error invalid SiByte MAC configuation
|
|
|
|
#endif
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <asm/sibyte/sb1250_scd.h>
|
2006-02-09 00:23:26 +01:00
|
|
|
#include <asm/sibyte/sb1250_mac.h>
|
|
|
|
#include <asm/sibyte/sb1250_dma.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2006-02-09 00:23:26 +01:00
|
|
|
#if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
|
|
|
|
#define UNIT_INT(n) (K_BCM1480_INT_MAC_0 + ((n) * 2))
|
|
|
|
#elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X)
|
|
|
|
#define UNIT_INT(n) (K_INT_MAC_0 + (n))
|
|
|
|
#else
|
|
|
|
#error invalid SiByte MAC configuation
|
|
|
|
#endif
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* Simple types
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
|
|
|
|
typedef enum { sbmac_speed_auto, sbmac_speed_10,
|
|
|
|
sbmac_speed_100, sbmac_speed_1000 } sbmac_speed_t;
|
|
|
|
|
|
|
|
typedef enum { sbmac_duplex_auto, sbmac_duplex_half,
|
|
|
|
sbmac_duplex_full } sbmac_duplex_t;
|
|
|
|
|
|
|
|
typedef enum { sbmac_fc_auto, sbmac_fc_disabled, sbmac_fc_frame,
|
|
|
|
sbmac_fc_collision, sbmac_fc_carrier } sbmac_fc_t;
|
|
|
|
|
2005-10-19 16:40:02 +02:00
|
|
|
typedef enum { sbmac_state_uninit, sbmac_state_off, sbmac_state_on,
|
2005-04-17 00:20:36 +02:00
|
|
|
sbmac_state_broken } sbmac_state_t;
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* Macros
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
|
|
|
|
#define SBDMA_NEXTBUF(d,f) ((((d)->f+1) == (d)->sbdma_dscrtable_end) ? \
|
|
|
|
(d)->sbdma_dscrtable : (d)->f+1)
|
|
|
|
|
|
|
|
|
|
|
|
#define NUMCACHEBLKS(x) (((x)+SMP_CACHE_BYTES-1)/SMP_CACHE_BYTES)
|
|
|
|
|
|
|
|
#define SBMAC_MAX_TXDESCR 32
|
|
|
|
#define SBMAC_MAX_RXDESCR 32
|
|
|
|
|
|
|
|
#define ETHER_ALIGN 2
|
|
|
|
#define ETHER_ADDR_LEN 6
|
2005-10-19 16:40:02 +02:00
|
|
|
#define ENET_PACKET_SIZE 1518
|
|
|
|
/*#define ENET_PACKET_SIZE 9216 */
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* DMA Descriptor structure
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
typedef struct sbdmadscr_s {
|
|
|
|
uint64_t dscr_a;
|
|
|
|
uint64_t dscr_b;
|
|
|
|
} sbdmadscr_t;
|
|
|
|
|
|
|
|
typedef unsigned long paddr_t;
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* DMA Controller structure
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
typedef struct sbmacdma_s {
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* This stuff is used to identify the channel and the registers
|
|
|
|
* associated with it.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
struct sbmac_softc *sbdma_eth; /* back pointer to associated MAC */
|
|
|
|
int sbdma_channel; /* channel number */
|
|
|
|
int sbdma_txdir; /* direction (1=transmit) */
|
|
|
|
int sbdma_maxdescr; /* total # of descriptors in ring */
|
|
|
|
#ifdef CONFIG_SBMAC_COALESCE
|
|
|
|
int sbdma_int_pktcnt; /* # descriptors rx/tx before interrupt*/
|
|
|
|
int sbdma_int_timeout; /* # usec rx/tx interrupt */
|
|
|
|
#endif
|
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
volatile void __iomem *sbdma_config0; /* DMA config register 0 */
|
|
|
|
volatile void __iomem *sbdma_config1; /* DMA config register 1 */
|
|
|
|
volatile void __iomem *sbdma_dscrbase; /* Descriptor base address */
|
|
|
|
volatile void __iomem *sbdma_dscrcnt; /* Descriptor count register */
|
|
|
|
volatile void __iomem *sbdma_curdscr; /* current descriptor address */
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* This stuff is for maintenance of the ring
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
sbdmadscr_t *sbdma_dscrtable; /* base of descriptor table */
|
|
|
|
sbdmadscr_t *sbdma_dscrtable_end; /* end of descriptor table */
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
struct sk_buff **sbdma_ctxtable; /* context table, one per descr */
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
paddr_t sbdma_dscrtable_phys; /* and also the phys addr */
|
|
|
|
sbdmadscr_t *sbdma_addptr; /* next dscr for sw to add */
|
|
|
|
sbdmadscr_t *sbdma_remptr; /* next dscr for sw to remove */
|
|
|
|
} sbmacdma_t;
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* Ethernet softc structure
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
struct sbmac_softc {
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Linux-specific things
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
struct net_device *sbm_dev; /* pointer to linux device */
|
|
|
|
spinlock_t sbm_lock; /* spin lock */
|
|
|
|
struct timer_list sbm_timer; /* for monitoring MII */
|
2005-10-19 16:40:02 +02:00
|
|
|
struct net_device_stats sbm_stats;
|
2005-04-17 00:20:36 +02:00
|
|
|
int sbm_devflags; /* current device flags */
|
|
|
|
|
|
|
|
int sbm_phy_oldbmsr;
|
|
|
|
int sbm_phy_oldanlpar;
|
|
|
|
int sbm_phy_oldk1stsr;
|
|
|
|
int sbm_phy_oldlinkstat;
|
|
|
|
int sbm_buffersize;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
unsigned char sbm_phys[2];
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Controller-specific things
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
volatile void __iomem *sbm_base; /* MAC's base address */
|
2005-04-17 00:20:36 +02:00
|
|
|
sbmac_state_t sbm_state; /* current state */
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
volatile void __iomem *sbm_macenable; /* MAC Enable Register */
|
|
|
|
volatile void __iomem *sbm_maccfg; /* MAC Configuration Register */
|
|
|
|
volatile void __iomem *sbm_fifocfg; /* FIFO configuration register */
|
|
|
|
volatile void __iomem *sbm_framecfg; /* Frame configuration register */
|
|
|
|
volatile void __iomem *sbm_rxfilter; /* receive filter register */
|
|
|
|
volatile void __iomem *sbm_isr; /* Interrupt status register */
|
|
|
|
volatile void __iomem *sbm_imr; /* Interrupt mask register */
|
|
|
|
volatile void __iomem *sbm_mdio; /* MDIO register */
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
sbmac_speed_t sbm_speed; /* current speed */
|
|
|
|
sbmac_duplex_t sbm_duplex; /* current duplex */
|
|
|
|
sbmac_fc_t sbm_fc; /* current flow control setting */
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
unsigned char sbm_hwaddr[ETHER_ADDR_LEN];
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
sbmacdma_t sbm_txdma; /* for now, only use channel 0 */
|
|
|
|
sbmacdma_t sbm_rxdma;
|
|
|
|
int rx_hw_checksum;
|
|
|
|
int sbe_idx;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* Externs
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* Prototypes
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static void sbdma_initctx(sbmacdma_t *d,
|
|
|
|
struct sbmac_softc *s,
|
|
|
|
int chan,
|
|
|
|
int txrx,
|
|
|
|
int maxdescr);
|
|
|
|
static void sbdma_channel_start(sbmacdma_t *d, int rxtx);
|
|
|
|
static int sbdma_add_rcvbuffer(sbmacdma_t *d,struct sk_buff *m);
|
|
|
|
static int sbdma_add_txbuffer(sbmacdma_t *d,struct sk_buff *m);
|
|
|
|
static void sbdma_emptyring(sbmacdma_t *d);
|
|
|
|
static void sbdma_fillring(sbmacdma_t *d);
|
|
|
|
static void sbdma_rx_process(struct sbmac_softc *sc,sbmacdma_t *d);
|
|
|
|
static void sbdma_tx_process(struct sbmac_softc *sc,sbmacdma_t *d);
|
|
|
|
static int sbmac_initctx(struct sbmac_softc *s);
|
|
|
|
static void sbmac_channel_start(struct sbmac_softc *s);
|
|
|
|
static void sbmac_channel_stop(struct sbmac_softc *s);
|
|
|
|
static sbmac_state_t sbmac_set_channel_state(struct sbmac_softc *,sbmac_state_t);
|
|
|
|
static void sbmac_promiscuous_mode(struct sbmac_softc *sc,int onoff);
|
|
|
|
static uint64_t sbmac_addr2reg(unsigned char *ptr);
|
|
|
|
static irqreturn_t sbmac_intr(int irq,void *dev_instance,struct pt_regs *rgs);
|
|
|
|
static int sbmac_start_tx(struct sk_buff *skb, struct net_device *dev);
|
|
|
|
static void sbmac_setmulti(struct sbmac_softc *sc);
|
|
|
|
static int sbmac_init(struct net_device *dev, int idx);
|
|
|
|
static int sbmac_set_speed(struct sbmac_softc *s,sbmac_speed_t speed);
|
|
|
|
static int sbmac_set_duplex(struct sbmac_softc *s,sbmac_duplex_t duplex,sbmac_fc_t fc);
|
|
|
|
|
|
|
|
static int sbmac_open(struct net_device *dev);
|
|
|
|
static void sbmac_timer(unsigned long data);
|
|
|
|
static void sbmac_tx_timeout (struct net_device *dev);
|
|
|
|
static struct net_device_stats *sbmac_get_stats(struct net_device *dev);
|
|
|
|
static void sbmac_set_rx_mode(struct net_device *dev);
|
|
|
|
static int sbmac_mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
|
|
|
|
static int sbmac_close(struct net_device *dev);
|
|
|
|
static int sbmac_mii_poll(struct sbmac_softc *s,int noisy);
|
2005-10-20 13:01:28 +02:00
|
|
|
static int sbmac_mii_probe(struct net_device *dev);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
static void sbmac_mii_sync(struct sbmac_softc *s);
|
|
|
|
static void sbmac_mii_senddata(struct sbmac_softc *s,unsigned int data, int bitcnt);
|
|
|
|
static unsigned int sbmac_mii_read(struct sbmac_softc *s,int phyaddr,int regidx);
|
|
|
|
static void sbmac_mii_write(struct sbmac_softc *s,int phyaddr,int regidx,
|
|
|
|
unsigned int regval);
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* Globals
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static uint64_t sbmac_orig_hwaddr[MAX_UNITS];
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* MDIO constants
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
#define MII_COMMAND_START 0x01
|
|
|
|
#define MII_COMMAND_READ 0x02
|
|
|
|
#define MII_COMMAND_WRITE 0x01
|
|
|
|
#define MII_COMMAND_ACK 0x02
|
|
|
|
|
|
|
|
#define BMCR_RESET 0x8000
|
|
|
|
#define BMCR_LOOPBACK 0x4000
|
|
|
|
#define BMCR_SPEED0 0x2000
|
|
|
|
#define BMCR_ANENABLE 0x1000
|
|
|
|
#define BMCR_POWERDOWN 0x0800
|
|
|
|
#define BMCR_ISOLATE 0x0400
|
|
|
|
#define BMCR_RESTARTAN 0x0200
|
|
|
|
#define BMCR_DUPLEX 0x0100
|
|
|
|
#define BMCR_COLTEST 0x0080
|
|
|
|
#define BMCR_SPEED1 0x0040
|
|
|
|
#define BMCR_SPEED1000 BMCR_SPEED1
|
|
|
|
#define BMCR_SPEED100 BMCR_SPEED0
|
|
|
|
#define BMCR_SPEED10 0
|
|
|
|
|
|
|
|
#define BMSR_100BT4 0x8000
|
|
|
|
#define BMSR_100BT_FDX 0x4000
|
|
|
|
#define BMSR_100BT_HDX 0x2000
|
|
|
|
#define BMSR_10BT_FDX 0x1000
|
|
|
|
#define BMSR_10BT_HDX 0x0800
|
|
|
|
#define BMSR_100BT2_FDX 0x0400
|
|
|
|
#define BMSR_100BT2_HDX 0x0200
|
|
|
|
#define BMSR_1000BT_XSR 0x0100
|
|
|
|
#define BMSR_PRESUP 0x0040
|
|
|
|
#define BMSR_ANCOMPLT 0x0020
|
|
|
|
#define BMSR_REMFAULT 0x0010
|
|
|
|
#define BMSR_AUTONEG 0x0008
|
|
|
|
#define BMSR_LINKSTAT 0x0004
|
|
|
|
#define BMSR_JABDETECT 0x0002
|
|
|
|
#define BMSR_EXTCAPAB 0x0001
|
|
|
|
|
|
|
|
#define PHYIDR1 0x2000
|
|
|
|
#define PHYIDR2 0x5C60
|
|
|
|
|
|
|
|
#define ANAR_NP 0x8000
|
|
|
|
#define ANAR_RF 0x2000
|
|
|
|
#define ANAR_ASYPAUSE 0x0800
|
|
|
|
#define ANAR_PAUSE 0x0400
|
|
|
|
#define ANAR_T4 0x0200
|
|
|
|
#define ANAR_TXFD 0x0100
|
|
|
|
#define ANAR_TXHD 0x0080
|
|
|
|
#define ANAR_10FD 0x0040
|
|
|
|
#define ANAR_10HD 0x0020
|
|
|
|
#define ANAR_PSB 0x0001
|
|
|
|
|
|
|
|
#define ANLPAR_NP 0x8000
|
|
|
|
#define ANLPAR_ACK 0x4000
|
|
|
|
#define ANLPAR_RF 0x2000
|
|
|
|
#define ANLPAR_ASYPAUSE 0x0800
|
|
|
|
#define ANLPAR_PAUSE 0x0400
|
|
|
|
#define ANLPAR_T4 0x0200
|
|
|
|
#define ANLPAR_TXFD 0x0100
|
|
|
|
#define ANLPAR_TXHD 0x0080
|
|
|
|
#define ANLPAR_10FD 0x0040
|
|
|
|
#define ANLPAR_10HD 0x0020
|
|
|
|
#define ANLPAR_PSB 0x0001 /* 802.3 */
|
|
|
|
|
|
|
|
#define ANER_PDF 0x0010
|
|
|
|
#define ANER_LPNPABLE 0x0008
|
|
|
|
#define ANER_NPABLE 0x0004
|
|
|
|
#define ANER_PAGERX 0x0002
|
|
|
|
#define ANER_LPANABLE 0x0001
|
|
|
|
|
|
|
|
#define ANNPTR_NP 0x8000
|
|
|
|
#define ANNPTR_MP 0x2000
|
|
|
|
#define ANNPTR_ACK2 0x1000
|
|
|
|
#define ANNPTR_TOGTX 0x0800
|
|
|
|
#define ANNPTR_CODE 0x0008
|
|
|
|
|
|
|
|
#define ANNPRR_NP 0x8000
|
|
|
|
#define ANNPRR_MP 0x2000
|
|
|
|
#define ANNPRR_ACK3 0x1000
|
|
|
|
#define ANNPRR_TOGTX 0x0800
|
|
|
|
#define ANNPRR_CODE 0x0008
|
|
|
|
|
|
|
|
#define K1TCR_TESTMODE 0x0000
|
|
|
|
#define K1TCR_MSMCE 0x1000
|
|
|
|
#define K1TCR_MSCV 0x0800
|
|
|
|
#define K1TCR_RPTR 0x0400
|
|
|
|
#define K1TCR_1000BT_FDX 0x200
|
|
|
|
#define K1TCR_1000BT_HDX 0x100
|
|
|
|
|
|
|
|
#define K1STSR_MSMCFLT 0x8000
|
|
|
|
#define K1STSR_MSCFGRES 0x4000
|
|
|
|
#define K1STSR_LRSTAT 0x2000
|
|
|
|
#define K1STSR_RRSTAT 0x1000
|
|
|
|
#define K1STSR_LP1KFD 0x0800
|
|
|
|
#define K1STSR_LP1KHD 0x0400
|
|
|
|
#define K1STSR_LPASMDIR 0x0200
|
|
|
|
|
|
|
|
#define K1SCR_1KX_FDX 0x8000
|
|
|
|
#define K1SCR_1KX_HDX 0x4000
|
|
|
|
#define K1SCR_1KT_FDX 0x2000
|
|
|
|
#define K1SCR_1KT_HDX 0x1000
|
|
|
|
|
|
|
|
#define STRAP_PHY1 0x0800
|
|
|
|
#define STRAP_NCMODE 0x0400
|
|
|
|
#define STRAP_MANMSCFG 0x0200
|
|
|
|
#define STRAP_ANENABLE 0x0100
|
|
|
|
#define STRAP_MSVAL 0x0080
|
|
|
|
#define STRAP_1KHDXADV 0x0010
|
|
|
|
#define STRAP_1KFDXADV 0x0008
|
|
|
|
#define STRAP_100ADV 0x0004
|
|
|
|
#define STRAP_SPEEDSEL 0x0000
|
|
|
|
#define STRAP_SPEED100 0x0001
|
|
|
|
|
|
|
|
#define PHYSUP_SPEED1000 0x10
|
|
|
|
#define PHYSUP_SPEED100 0x08
|
|
|
|
#define PHYSUP_SPEED10 0x00
|
|
|
|
#define PHYSUP_LINKUP 0x04
|
|
|
|
#define PHYSUP_FDX 0x02
|
|
|
|
|
|
|
|
#define MII_BMCR 0x00 /* Basic mode control register (rw) */
|
|
|
|
#define MII_BMSR 0x01 /* Basic mode status register (ro) */
|
2005-10-20 13:01:28 +02:00
|
|
|
#define MII_PHYIDR1 0x02
|
|
|
|
#define MII_PHYIDR2 0x03
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
#define MII_K1STSR 0x0A /* 1K Status Register (ro) */
|
|
|
|
#define MII_ANLPAR 0x05 /* Autonegotiation lnk partner abilities (rw) */
|
|
|
|
|
|
|
|
|
|
|
|
#define M_MAC_MDIO_DIR_OUTPUT 0 /* for clarity */
|
|
|
|
|
|
|
|
#define ENABLE 1
|
|
|
|
#define DISABLE 0
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBMAC_MII_SYNC(s)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Synchronize with the MII - send a pattern of bits to the MII
|
|
|
|
* that will guarantee that it is ready to accept a command.
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* s - sbmac structure
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* nothing
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static void sbmac_mii_sync(struct sbmac_softc *s)
|
|
|
|
{
|
|
|
|
int cnt;
|
|
|
|
uint64_t bits;
|
|
|
|
int mac_mdio_genc;
|
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
mac_mdio_genc = __raw_readq(s->sbm_mdio) & M_MAC_GENC;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
bits = M_MAC_MDIO_DIR_OUTPUT | M_MAC_MDIO_OUT;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(bits | mac_mdio_genc, s->sbm_mdio);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
for (cnt = 0; cnt < 32; cnt++) {
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(bits | M_MAC_MDC | mac_mdio_genc, s->sbm_mdio);
|
|
|
|
__raw_writeq(bits | mac_mdio_genc, s->sbm_mdio);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBMAC_MII_SENDDATA(s,data,bitcnt)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Send some bits to the MII. The bits to be sent are right-
|
|
|
|
* justified in the 'data' parameter.
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* s - sbmac structure
|
|
|
|
* data - data to send
|
|
|
|
* bitcnt - number of bits to send
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static void sbmac_mii_senddata(struct sbmac_softc *s,unsigned int data, int bitcnt)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint64_t bits;
|
|
|
|
unsigned int curmask;
|
|
|
|
int mac_mdio_genc;
|
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
mac_mdio_genc = __raw_readq(s->sbm_mdio) & M_MAC_GENC;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
bits = M_MAC_MDIO_DIR_OUTPUT;
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(bits | mac_mdio_genc, s->sbm_mdio);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
curmask = 1 << (bitcnt - 1);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
for (i = 0; i < bitcnt; i++) {
|
|
|
|
if (data & curmask)
|
|
|
|
bits |= M_MAC_MDIO_OUT;
|
|
|
|
else bits &= ~M_MAC_MDIO_OUT;
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(bits | mac_mdio_genc, s->sbm_mdio);
|
|
|
|
__raw_writeq(bits | M_MAC_MDC | mac_mdio_genc, s->sbm_mdio);
|
|
|
|
__raw_writeq(bits | mac_mdio_genc, s->sbm_mdio);
|
2005-04-17 00:20:36 +02:00
|
|
|
curmask >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBMAC_MII_READ(s,phyaddr,regidx)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Read a PHY register.
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* s - sbmac structure
|
|
|
|
* phyaddr - PHY's address
|
|
|
|
* regidx = index of register to read
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* value read, or 0 if an error occurred.
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static unsigned int sbmac_mii_read(struct sbmac_softc *s,int phyaddr,int regidx)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
int error;
|
|
|
|
int regval;
|
|
|
|
int mac_mdio_genc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Synchronize ourselves so that the PHY knows the next
|
|
|
|
* thing coming down is a command
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
sbmac_mii_sync(s);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Send the data to the PHY. The sequence is
|
|
|
|
* a "start" command (2 bits)
|
|
|
|
* a "read" command (2 bits)
|
|
|
|
* the PHY addr (5 bits)
|
|
|
|
* the register index (5 bits)
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
sbmac_mii_senddata(s,MII_COMMAND_START, 2);
|
|
|
|
sbmac_mii_senddata(s,MII_COMMAND_READ, 2);
|
|
|
|
sbmac_mii_senddata(s,phyaddr, 5);
|
|
|
|
sbmac_mii_senddata(s,regidx, 5);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
mac_mdio_genc = __raw_readq(s->sbm_mdio) & M_MAC_GENC;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Switch the port around without a clock transition.
|
|
|
|
*/
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, s->sbm_mdio);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Send out a clock pulse to signal we want the status
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(M_MAC_MDIO_DIR_INPUT | M_MAC_MDC | mac_mdio_genc, s->sbm_mdio);
|
|
|
|
__raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, s->sbm_mdio);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* If an error occurred, the PHY will signal '1' back
|
|
|
|
*/
|
2005-10-19 16:39:05 +02:00
|
|
|
error = __raw_readq(s->sbm_mdio) & M_MAC_MDIO_IN;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Issue an 'idle' clock pulse, but keep the direction
|
|
|
|
* the same.
|
|
|
|
*/
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(M_MAC_MDIO_DIR_INPUT | M_MAC_MDC | mac_mdio_genc, s->sbm_mdio);
|
|
|
|
__raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, s->sbm_mdio);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
regval = 0;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
for (idx = 0; idx < 16; idx++) {
|
|
|
|
regval <<= 1;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (error == 0) {
|
2005-10-19 16:39:05 +02:00
|
|
|
if (__raw_readq(s->sbm_mdio) & M_MAC_MDIO_IN)
|
2005-04-17 00:20:36 +02:00
|
|
|
regval |= 1;
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(M_MAC_MDIO_DIR_INPUT|M_MAC_MDC | mac_mdio_genc, s->sbm_mdio);
|
|
|
|
__raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, s->sbm_mdio);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* Switch back to output */
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(M_MAC_MDIO_DIR_OUTPUT | mac_mdio_genc, s->sbm_mdio);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (error == 0)
|
|
|
|
return regval;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBMAC_MII_WRITE(s,phyaddr,regidx,regval)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Write a value to a PHY register.
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* s - sbmac structure
|
|
|
|
* phyaddr - PHY to use
|
|
|
|
* regidx - register within the PHY
|
|
|
|
* regval - data to write to register
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* nothing
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static void sbmac_mii_write(struct sbmac_softc *s,int phyaddr,int regidx,
|
|
|
|
unsigned int regval)
|
|
|
|
{
|
|
|
|
int mac_mdio_genc;
|
|
|
|
|
|
|
|
sbmac_mii_sync(s);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
sbmac_mii_senddata(s,MII_COMMAND_START,2);
|
|
|
|
sbmac_mii_senddata(s,MII_COMMAND_WRITE,2);
|
|
|
|
sbmac_mii_senddata(s,phyaddr, 5);
|
|
|
|
sbmac_mii_senddata(s,regidx, 5);
|
|
|
|
sbmac_mii_senddata(s,MII_COMMAND_ACK,2);
|
|
|
|
sbmac_mii_senddata(s,regval,16);
|
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
mac_mdio_genc = __raw_readq(s->sbm_mdio) & M_MAC_GENC;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(M_MAC_MDIO_DIR_OUTPUT | mac_mdio_genc, s->sbm_mdio);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBDMA_INITCTX(d,s,chan,txrx,maxdescr)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Initialize a DMA channel context. Since there are potentially
|
|
|
|
* eight DMA channels per MAC, it's nice to do this in a standard
|
2005-10-19 16:40:02 +02:00
|
|
|
* way.
|
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* d - sbmacdma_t structure (DMA channel context)
|
|
|
|
* s - sbmac_softc structure (pointer to a MAC)
|
|
|
|
* chan - channel number (0..1 right now)
|
|
|
|
* txrx - Identifies DMA_TX or DMA_RX for channel direction
|
|
|
|
* maxdescr - number of descriptors
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* nothing
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static void sbdma_initctx(sbmacdma_t *d,
|
|
|
|
struct sbmac_softc *s,
|
|
|
|
int chan,
|
|
|
|
int txrx,
|
|
|
|
int maxdescr)
|
|
|
|
{
|
2005-10-19 16:40:02 +02:00
|
|
|
/*
|
|
|
|
* Save away interesting stuff in the structure
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
d->sbdma_eth = s;
|
|
|
|
d->sbdma_channel = chan;
|
|
|
|
d->sbdma_txdir = txrx;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
#if 0
|
|
|
|
/* RMON clearing */
|
|
|
|
s->sbe_idx =(s->sbm_base - A_MAC_BASE_0)/MAC_SPACING;
|
|
|
|
#endif
|
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_BYTES)));
|
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_COLLISIONS)));
|
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_LATE_COL)));
|
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_EX_COL)));
|
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_FCS_ERROR)));
|
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_ABORT)));
|
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_BAD)));
|
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_GOOD)));
|
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_RUNT)));
|
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_OVERSIZE)));
|
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_BYTES)));
|
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_MCAST)));
|
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_BCAST)));
|
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_BAD)));
|
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_GOOD)));
|
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_RUNT)));
|
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_OVERSIZE)));
|
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_FCS_ERROR)));
|
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_LENGTH_ERROR)));
|
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_CODE_ERROR)));
|
|
|
|
__raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_ALIGN_ERROR)));
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-10-19 16:40:02 +02:00
|
|
|
/*
|
|
|
|
* initialize register pointers
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
d->sbdma_config0 =
|
2005-04-17 00:20:36 +02:00
|
|
|
s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CONFIG0);
|
2005-10-19 16:40:02 +02:00
|
|
|
d->sbdma_config1 =
|
2005-04-17 00:20:36 +02:00
|
|
|
s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CONFIG1);
|
2005-10-19 16:40:02 +02:00
|
|
|
d->sbdma_dscrbase =
|
2005-04-17 00:20:36 +02:00
|
|
|
s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_DSCR_BASE);
|
2005-10-19 16:40:02 +02:00
|
|
|
d->sbdma_dscrcnt =
|
2005-04-17 00:20:36 +02:00
|
|
|
s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_DSCR_CNT);
|
2005-10-19 16:40:02 +02:00
|
|
|
d->sbdma_curdscr =
|
2005-04-17 00:20:36 +02:00
|
|
|
s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CUR_DSCRADDR);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Allocate memory for the ring
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
d->sbdma_maxdescr = maxdescr;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
d->sbdma_dscrtable = (sbdmadscr_t *)
|
2005-10-10 15:50:36 +02:00
|
|
|
kmalloc((d->sbdma_maxdescr+1)*sizeof(sbdmadscr_t), GFP_KERNEL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The descriptor table must be aligned to at least 16 bytes or the
|
|
|
|
* MAC will corrupt it.
|
|
|
|
*/
|
|
|
|
d->sbdma_dscrtable = (sbdmadscr_t *)
|
|
|
|
ALIGN((unsigned long)d->sbdma_dscrtable, sizeof(sbdmadscr_t));
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
memset(d->sbdma_dscrtable,0,d->sbdma_maxdescr*sizeof(sbdmadscr_t));
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
d->sbdma_dscrtable_end = d->sbdma_dscrtable + d->sbdma_maxdescr;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
d->sbdma_dscrtable_phys = virt_to_phys(d->sbdma_dscrtable);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* And context table
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
d->sbdma_ctxtable = (struct sk_buff **)
|
2005-04-17 00:20:36 +02:00
|
|
|
kmalloc(d->sbdma_maxdescr*sizeof(struct sk_buff *), GFP_KERNEL);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
memset(d->sbdma_ctxtable,0,d->sbdma_maxdescr*sizeof(struct sk_buff *));
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
#ifdef CONFIG_SBMAC_COALESCE
|
|
|
|
/*
|
|
|
|
* Setup Rx/Tx DMA coalescing defaults
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ( int_pktcnt ) {
|
|
|
|
d->sbdma_int_pktcnt = int_pktcnt;
|
|
|
|
} else {
|
|
|
|
d->sbdma_int_pktcnt = 1;
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if ( int_timeout ) {
|
|
|
|
d->sbdma_int_timeout = int_timeout;
|
|
|
|
} else {
|
|
|
|
d->sbdma_int_timeout = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBDMA_CHANNEL_START(d)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Initialize the hardware registers for a DMA channel.
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* d - DMA channel to init (context must be previously init'd
|
|
|
|
* rxtx - DMA_RX or DMA_TX depending on what type of channel
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* nothing
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static void sbdma_channel_start(sbmacdma_t *d, int rxtx )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Turn on the DMA channel
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
#ifdef CONFIG_SBMAC_COALESCE
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(V_DMA_INT_TIMEOUT(d->sbdma_int_timeout) |
|
|
|
|
0, d->sbdma_config1);
|
|
|
|
__raw_writeq(M_DMA_EOP_INT_EN |
|
2005-04-17 00:20:36 +02:00
|
|
|
V_DMA_RINGSZ(d->sbdma_maxdescr) |
|
|
|
|
V_DMA_INT_PKTCNT(d->sbdma_int_pktcnt) |
|
2005-10-19 16:39:05 +02:00
|
|
|
0, d->sbdma_config0);
|
2005-04-17 00:20:36 +02:00
|
|
|
#else
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(0, d->sbdma_config1);
|
|
|
|
__raw_writeq(V_DMA_RINGSZ(d->sbdma_maxdescr) |
|
|
|
|
0, d->sbdma_config0);
|
2005-04-17 00:20:36 +02:00
|
|
|
#endif
|
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(d->sbdma_dscrtable_phys, d->sbdma_dscrbase);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize ring pointers
|
|
|
|
*/
|
|
|
|
|
|
|
|
d->sbdma_addptr = d->sbdma_dscrtable;
|
|
|
|
d->sbdma_remptr = d->sbdma_dscrtable;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBDMA_CHANNEL_STOP(d)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Initialize the hardware registers for a DMA channel.
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* d - DMA channel to init (context must be previously init'd
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* nothing
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static void sbdma_channel_stop(sbmacdma_t *d)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Turn off the DMA channel
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(0, d->sbdma_config1);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(0, d->sbdma_dscrbase);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(0, d->sbdma_config0);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Zero ring pointers
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
d->sbdma_addptr = NULL;
|
|
|
|
d->sbdma_remptr = NULL;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sbdma_align_skb(struct sk_buff *skb,int power2,int offset)
|
|
|
|
{
|
|
|
|
unsigned long addr;
|
|
|
|
unsigned long newaddr;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
addr = (unsigned long) skb->data;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
newaddr = (addr + power2 - 1) & ~(power2 - 1);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
skb_reserve(skb,newaddr-addr+offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBDMA_ADD_RCVBUFFER(d,sb)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Add a buffer to the specified DMA channel. For receive channels,
|
|
|
|
* this queues a buffer for inbound packets.
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* d - DMA channel descriptor
|
|
|
|
* sb - sk_buff to add, or NULL if we should allocate one
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* 0 if buffer could not be added (ring is full)
|
|
|
|
* 1 if buffer added successfully
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
|
|
|
|
static int sbdma_add_rcvbuffer(sbmacdma_t *d,struct sk_buff *sb)
|
|
|
|
{
|
|
|
|
sbdmadscr_t *dsc;
|
|
|
|
sbdmadscr_t *nextdsc;
|
|
|
|
struct sk_buff *sb_new = NULL;
|
|
|
|
int pktsize = ENET_PACKET_SIZE;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* get pointer to our current place in the ring */
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
dsc = d->sbdma_addptr;
|
|
|
|
nextdsc = SBDMA_NEXTBUF(d,sbdma_addptr);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* figure out if the ring is full - if the next descriptor
|
|
|
|
* is the same as the one that we're going to remove from
|
|
|
|
* the ring, the ring is full
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (nextdsc == d->sbdma_remptr) {
|
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
|
2005-10-19 16:40:02 +02:00
|
|
|
/*
|
|
|
|
* Allocate a sk_buff if we don't already have one.
|
2005-04-17 00:20:36 +02:00
|
|
|
* If we do have an sk_buff, reset it so that it's empty.
|
|
|
|
*
|
|
|
|
* Note: sk_buffs don't seem to be guaranteed to have any sort
|
|
|
|
* of alignment when they are allocated. Therefore, allocate enough
|
|
|
|
* extra space to make sure that:
|
|
|
|
*
|
|
|
|
* 1. the data does not start in the middle of a cache line.
|
|
|
|
* 2. The data does not end in the middle of a cache line
|
2005-10-19 16:40:02 +02:00
|
|
|
* 3. The buffer can be aligned such that the IP addresses are
|
2005-04-17 00:20:36 +02:00
|
|
|
* naturally aligned.
|
|
|
|
*
|
|
|
|
* Remember, the SOCs MAC writes whole cache lines at a time,
|
|
|
|
* without reading the old contents first. So, if the sk_buff's
|
|
|
|
* data portion starts in the middle of a cache line, the SOC
|
|
|
|
* DMA will trash the beginning (and ending) portions.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (sb == NULL) {
|
|
|
|
sb_new = dev_alloc_skb(ENET_PACKET_SIZE + SMP_CACHE_BYTES * 2 + ETHER_ALIGN);
|
|
|
|
if (sb_new == NULL) {
|
|
|
|
printk(KERN_INFO "%s: sk_buff allocation failed\n",
|
|
|
|
d->sbdma_eth->sbm_dev->name);
|
|
|
|
return -ENOBUFS;
|
|
|
|
}
|
|
|
|
|
|
|
|
sbdma_align_skb(sb_new, SMP_CACHE_BYTES, ETHER_ALIGN);
|
|
|
|
|
|
|
|
/* mark skbuff owned by our device */
|
|
|
|
sb_new->dev = d->sbdma_eth->sbm_dev;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sb_new = sb;
|
2005-10-19 16:40:02 +02:00
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* nothing special to reinit buffer, it's already aligned
|
|
|
|
* and sb->data already points to a good place.
|
|
|
|
*/
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
2005-10-19 16:40:02 +02:00
|
|
|
* fill in the descriptor
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
#ifdef CONFIG_SBMAC_COALESCE
|
|
|
|
/*
|
|
|
|
* Do not interrupt per DMA transfer.
|
|
|
|
*/
|
2005-06-29 00:25:31 +02:00
|
|
|
dsc->dscr_a = virt_to_phys(sb_new->data) |
|
2005-10-19 16:39:05 +02:00
|
|
|
V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize+ETHER_ALIGN)) | 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
#else
|
2005-06-29 00:25:31 +02:00
|
|
|
dsc->dscr_a = virt_to_phys(sb_new->data) |
|
2005-04-17 00:20:36 +02:00
|
|
|
V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize+ETHER_ALIGN)) |
|
|
|
|
M_DMA_DSCRA_INTERRUPT;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* receiving: no options */
|
|
|
|
dsc->dscr_b = 0;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
2005-10-19 16:40:02 +02:00
|
|
|
* fill in the context
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
d->sbdma_ctxtable[dsc-d->sbdma_dscrtable] = sb_new;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* point at next packet
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
d->sbdma_addptr = nextdsc;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Give the buffer to the DMA engine.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(1, d->sbdma_dscrcnt);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0; /* we did it */
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBDMA_ADD_TXBUFFER(d,sb)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Add a transmit buffer to the specified DMA channel, causing a
|
|
|
|
* transmit to start.
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* d - DMA channel descriptor
|
|
|
|
* sb - sk_buff to add
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* 0 transmit queued successfully
|
|
|
|
* otherwise error code
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
|
|
|
|
static int sbdma_add_txbuffer(sbmacdma_t *d,struct sk_buff *sb)
|
|
|
|
{
|
|
|
|
sbdmadscr_t *dsc;
|
|
|
|
sbdmadscr_t *nextdsc;
|
|
|
|
uint64_t phys;
|
|
|
|
uint64_t ncb;
|
|
|
|
int length;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* get pointer to our current place in the ring */
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
dsc = d->sbdma_addptr;
|
|
|
|
nextdsc = SBDMA_NEXTBUF(d,sbdma_addptr);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* figure out if the ring is full - if the next descriptor
|
|
|
|
* is the same as the one that we're going to remove from
|
|
|
|
* the ring, the ring is full
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (nextdsc == d->sbdma_remptr) {
|
|
|
|
return -ENOSPC;
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Under Linux, it's not necessary to copy/coalesce buffers
|
|
|
|
* like it is on NetBSD. We think they're all contiguous,
|
|
|
|
* but that may not be true for GBE.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
length = sb->len;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* fill in the descriptor. Note that the number of cache
|
|
|
|
* blocks in the descriptor is the number of blocks
|
|
|
|
* *spanned*, so we need to add in the offset (if any)
|
|
|
|
* while doing the calculation.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
phys = virt_to_phys(sb->data);
|
|
|
|
ncb = NUMCACHEBLKS(length+(phys & (SMP_CACHE_BYTES - 1)));
|
|
|
|
|
2005-10-19 16:40:02 +02:00
|
|
|
dsc->dscr_a = phys |
|
2005-04-17 00:20:36 +02:00
|
|
|
V_DMA_DSCRA_A_SIZE(ncb) |
|
|
|
|
#ifndef CONFIG_SBMAC_COALESCE
|
|
|
|
M_DMA_DSCRA_INTERRUPT |
|
|
|
|
#endif
|
|
|
|
M_DMA_ETHTX_SOP;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* transmitting: set outbound options and length */
|
|
|
|
|
|
|
|
dsc->dscr_b = V_DMA_DSCRB_OPTIONS(K_DMA_ETHTX_APPENDCRC_APPENDPAD) |
|
|
|
|
V_DMA_DSCRB_PKT_SIZE(length);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
2005-10-19 16:40:02 +02:00
|
|
|
* fill in the context
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
d->sbdma_ctxtable[dsc-d->sbdma_dscrtable] = sb;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* point at next packet
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
d->sbdma_addptr = nextdsc;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Give the buffer to the DMA engine.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(1, d->sbdma_dscrcnt);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0; /* we did it */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBDMA_EMPTYRING(d)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Free all allocated sk_buffs on the specified DMA channel;
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* d - DMA channel
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* nothing
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static void sbdma_emptyring(sbmacdma_t *d)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
struct sk_buff *sb;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
for (idx = 0; idx < d->sbdma_maxdescr; idx++) {
|
|
|
|
sb = d->sbdma_ctxtable[idx];
|
|
|
|
if (sb) {
|
|
|
|
dev_kfree_skb(sb);
|
|
|
|
d->sbdma_ctxtable[idx] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBDMA_FILLRING(d)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Fill the specified DMA channel (must be receive channel)
|
|
|
|
* with sk_buffs
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* d - DMA channel
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* nothing
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static void sbdma_fillring(sbmacdma_t *d)
|
|
|
|
{
|
|
|
|
int idx;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
for (idx = 0; idx < SBMAC_MAX_RXDESCR-1; idx++) {
|
|
|
|
if (sbdma_add_rcvbuffer(d,NULL) != 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBDMA_RX_PROCESS(sc,d)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Process "completed" receive buffers on the specified DMA channel.
|
2005-04-17 00:20:36 +02:00
|
|
|
* Note that this isn't really ideal for priority channels, since
|
2005-10-19 16:40:02 +02:00
|
|
|
* it processes all of the packets on a given channel before
|
|
|
|
* returning.
|
2005-04-17 00:20:36 +02:00
|
|
|
*
|
2005-10-19 16:40:02 +02:00
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* sc - softc structure
|
|
|
|
* d - DMA channel context
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* nothing
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static void sbdma_rx_process(struct sbmac_softc *sc,sbmacdma_t *d)
|
|
|
|
{
|
|
|
|
int curidx;
|
|
|
|
int hwidx;
|
|
|
|
sbdmadscr_t *dsc;
|
|
|
|
struct sk_buff *sb;
|
|
|
|
int len;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
for (;;) {
|
2005-10-19 16:40:02 +02:00
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* figure out where we are (as an index) and where
|
|
|
|
* the hardware is (also as an index)
|
|
|
|
*
|
2005-10-19 16:40:02 +02:00
|
|
|
* This could be done faster if (for example) the
|
2005-04-17 00:20:36 +02:00
|
|
|
* descriptor table was page-aligned and contiguous in
|
|
|
|
* both virtual and physical memory -- you could then
|
|
|
|
* just compare the low-order bits of the virtual address
|
|
|
|
* (sbdma_remptr) and the physical address (sbdma_curdscr CSR)
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
curidx = d->sbdma_remptr - d->sbdma_dscrtable;
|
2005-10-19 16:39:05 +02:00
|
|
|
hwidx = (int) (((__raw_readq(d->sbdma_curdscr) & M_DMA_CURDSCR_ADDR) -
|
2005-04-17 00:20:36 +02:00
|
|
|
d->sbdma_dscrtable_phys) / sizeof(sbdmadscr_t));
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* If they're the same, that means we've processed all
|
|
|
|
* of the descriptors up to (but not including) the one that
|
|
|
|
* the hardware is working on right now.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (curidx == hwidx)
|
|
|
|
break;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Otherwise, get the packet's sk_buff ptr back
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
dsc = &(d->sbdma_dscrtable[curidx]);
|
|
|
|
sb = d->sbdma_ctxtable[curidx];
|
|
|
|
d->sbdma_ctxtable[curidx] = NULL;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
len = (int)G_DMA_DSCRB_PKT_SIZE(dsc->dscr_b) - 4;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Check packet status. If good, process it.
|
|
|
|
* If not, silently drop it and put it back on the
|
|
|
|
* receive ring.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (!(dsc->dscr_a & M_DMA_ETHRX_BAD)) {
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Add a new buffer to replace the old one. If we fail
|
|
|
|
* to allocate a buffer, we're going to drop this
|
|
|
|
* packet and put it right back on the receive ring.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (sbdma_add_rcvbuffer(d,NULL) == -ENOBUFS) {
|
|
|
|
sc->sbm_stats.rx_dropped++;
|
|
|
|
sbdma_add_rcvbuffer(d,sb); /* re-add old buffer */
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Set length into the packet
|
|
|
|
*/
|
|
|
|
skb_put(sb,len);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Buffer has been replaced on the
|
|
|
|
* receive ring. Pass the buffer to
|
|
|
|
* the kernel
|
|
|
|
*/
|
|
|
|
sc->sbm_stats.rx_bytes += len;
|
|
|
|
sc->sbm_stats.rx_packets++;
|
|
|
|
sb->protocol = eth_type_trans(sb,d->sbdma_eth->sbm_dev);
|
|
|
|
/* Check hw IPv4/TCP checksum if supported */
|
|
|
|
if (sc->rx_hw_checksum == ENABLE) {
|
|
|
|
if (!((dsc->dscr_a) & M_DMA_ETHRX_BADIP4CS) &&
|
|
|
|
!((dsc->dscr_a) & M_DMA_ETHRX_BADTCPCS)) {
|
|
|
|
sb->ip_summed = CHECKSUM_UNNECESSARY;
|
|
|
|
/* don't need to set sb->csum */
|
|
|
|
} else {
|
|
|
|
sb->ip_summed = CHECKSUM_NONE;
|
|
|
|
}
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
netif_rx(sb);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Packet was mangled somehow. Just drop it and
|
|
|
|
* put it back on the receive ring.
|
|
|
|
*/
|
|
|
|
sc->sbm_stats.rx_errors++;
|
|
|
|
sbdma_add_rcvbuffer(d,sb);
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* .. and advance to the next buffer.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBDMA_TX_PROCESS(sc,d)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Process "completed" transmit buffers on the specified DMA channel.
|
2005-04-17 00:20:36 +02:00
|
|
|
* This is normally called within the interrupt service routine.
|
|
|
|
* Note that this isn't really ideal for priority channels, since
|
2005-10-19 16:40:02 +02:00
|
|
|
* it processes all of the packets on a given channel before
|
|
|
|
* returning.
|
2005-04-17 00:20:36 +02:00
|
|
|
*
|
2005-10-19 16:40:02 +02:00
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* sc - softc structure
|
|
|
|
* d - DMA channel context
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* nothing
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static void sbdma_tx_process(struct sbmac_softc *sc,sbmacdma_t *d)
|
|
|
|
{
|
|
|
|
int curidx;
|
|
|
|
int hwidx;
|
|
|
|
sbdmadscr_t *dsc;
|
|
|
|
struct sk_buff *sb;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&(sc->sbm_lock), flags);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
for (;;) {
|
2005-10-19 16:40:02 +02:00
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* figure out where we are (as an index) and where
|
|
|
|
* the hardware is (also as an index)
|
|
|
|
*
|
2005-10-19 16:40:02 +02:00
|
|
|
* This could be done faster if (for example) the
|
2005-04-17 00:20:36 +02:00
|
|
|
* descriptor table was page-aligned and contiguous in
|
|
|
|
* both virtual and physical memory -- you could then
|
|
|
|
* just compare the low-order bits of the virtual address
|
|
|
|
* (sbdma_remptr) and the physical address (sbdma_curdscr CSR)
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
curidx = d->sbdma_remptr - d->sbdma_dscrtable;
|
2005-10-19 16:39:05 +02:00
|
|
|
hwidx = (int) (((__raw_readq(d->sbdma_curdscr) & M_DMA_CURDSCR_ADDR) -
|
2005-04-17 00:20:36 +02:00
|
|
|
d->sbdma_dscrtable_phys) / sizeof(sbdmadscr_t));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If they're the same, that means we've processed all
|
|
|
|
* of the descriptors up to (but not including) the one that
|
|
|
|
* the hardware is working on right now.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (curidx == hwidx)
|
|
|
|
break;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Otherwise, get the packet's sk_buff ptr back
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
dsc = &(d->sbdma_dscrtable[curidx]);
|
|
|
|
sb = d->sbdma_ctxtable[curidx];
|
|
|
|
d->sbdma_ctxtable[curidx] = NULL;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Stats
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
sc->sbm_stats.tx_bytes += sb->len;
|
|
|
|
sc->sbm_stats.tx_packets++;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* for transmits, we just free buffers.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
dev_kfree_skb_irq(sb);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* .. and advance to the next buffer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Decide if we should wake up the protocol or not.
|
|
|
|
* Other drivers seem to do this when we reach a low
|
|
|
|
* watermark on the transmit queue.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
netif_wake_queue(d->sbdma_eth->sbm_dev);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
spin_unlock_irqrestore(&(sc->sbm_lock), flags);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBMAC_INITCTX(s)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Initialize an Ethernet context structure - this is called
|
|
|
|
* once per MAC on the 1250. Memory is allocated here, so don't
|
|
|
|
* call it again from inside the ioctl routines that bring the
|
|
|
|
* interface up/down
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* s - sbmac context structure
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* 0
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static int sbmac_initctx(struct sbmac_softc *s)
|
|
|
|
{
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* figure out the addresses of some ports
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
s->sbm_macenable = s->sbm_base + R_MAC_ENABLE;
|
|
|
|
s->sbm_maccfg = s->sbm_base + R_MAC_CFG;
|
|
|
|
s->sbm_fifocfg = s->sbm_base + R_MAC_THRSH_CFG;
|
|
|
|
s->sbm_framecfg = s->sbm_base + R_MAC_FRAMECFG;
|
|
|
|
s->sbm_rxfilter = s->sbm_base + R_MAC_ADFILTER_CFG;
|
|
|
|
s->sbm_isr = s->sbm_base + R_MAC_STATUS;
|
|
|
|
s->sbm_imr = s->sbm_base + R_MAC_INT_MASK;
|
|
|
|
s->sbm_mdio = s->sbm_base + R_MAC_MDIO;
|
|
|
|
|
|
|
|
s->sbm_phys[0] = 1;
|
|
|
|
s->sbm_phys[1] = 0;
|
|
|
|
|
|
|
|
s->sbm_phy_oldbmsr = 0;
|
|
|
|
s->sbm_phy_oldanlpar = 0;
|
|
|
|
s->sbm_phy_oldk1stsr = 0;
|
|
|
|
s->sbm_phy_oldlinkstat = 0;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Initialize the DMA channels. Right now, only one per MAC is used
|
|
|
|
* Note: Only do this _once_, as it allocates memory from the kernel!
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
sbdma_initctx(&(s->sbm_txdma),s,0,DMA_TX,SBMAC_MAX_TXDESCR);
|
|
|
|
sbdma_initctx(&(s->sbm_rxdma),s,0,DMA_RX,SBMAC_MAX_RXDESCR);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* initial state is OFF
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
s->sbm_state = sbmac_state_off;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Initial speed is (XXX TEMP) 10MBit/s HDX no FC
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
s->sbm_speed = sbmac_speed_10;
|
|
|
|
s->sbm_duplex = sbmac_duplex_half;
|
|
|
|
s->sbm_fc = sbmac_fc_disabled;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void sbdma_uninitctx(struct sbmacdma_s *d)
|
|
|
|
{
|
|
|
|
if (d->sbdma_dscrtable) {
|
|
|
|
kfree(d->sbdma_dscrtable);
|
|
|
|
d->sbdma_dscrtable = NULL;
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (d->sbdma_ctxtable) {
|
|
|
|
kfree(d->sbdma_ctxtable);
|
|
|
|
d->sbdma_ctxtable = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void sbmac_uninitctx(struct sbmac_softc *sc)
|
|
|
|
{
|
|
|
|
sbdma_uninitctx(&(sc->sbm_txdma));
|
|
|
|
sbdma_uninitctx(&(sc->sbm_rxdma));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBMAC_CHANNEL_START(s)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Start packet processing on this MAC.
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* s - sbmac structure
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* nothing
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static void sbmac_channel_start(struct sbmac_softc *s)
|
|
|
|
{
|
|
|
|
uint64_t reg;
|
2005-10-19 16:39:05 +02:00
|
|
|
volatile void __iomem *port;
|
2005-04-17 00:20:36 +02:00
|
|
|
uint64_t cfg,fifo,framecfg;
|
|
|
|
int idx, th_value;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Don't do this if running
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (s->sbm_state == sbmac_state_on)
|
|
|
|
return;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Bring the controller out of reset, but leave it off.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(0, s->sbm_macenable);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Ignore all received packets
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(0, s->sbm_rxfilter);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Calculate values for various control registers.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
cfg = M_MAC_RETRY_EN |
|
2005-10-19 16:40:02 +02:00
|
|
|
M_MAC_TX_HOLD_SOP_EN |
|
2005-04-17 00:20:36 +02:00
|
|
|
V_MAC_TX_PAUSE_CNT_16K |
|
|
|
|
M_MAC_AP_STAT_EN |
|
|
|
|
M_MAC_FAST_SYNC |
|
|
|
|
M_MAC_SS_EN |
|
|
|
|
0;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Be sure that RD_THRSH+WR_THRSH <= 32 for pass1 pars
|
|
|
|
* and make sure that RD_THRSH + WR_THRSH <=128 for pass2 and above
|
|
|
|
* Use a larger RD_THRSH for gigabit
|
|
|
|
*/
|
2006-02-09 00:23:26 +01:00
|
|
|
if (soc_type == K_SYS_SOC_TYPE_BCM1250 && periph_rev < 2)
|
2005-04-17 00:20:36 +02:00
|
|
|
th_value = 28;
|
2006-02-09 00:23:26 +01:00
|
|
|
else
|
|
|
|
th_value = 64;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
fifo = V_MAC_TX_WR_THRSH(4) | /* Must be '4' or '8' */
|
|
|
|
((s->sbm_speed == sbmac_speed_1000)
|
|
|
|
? V_MAC_TX_RD_THRSH(th_value) : V_MAC_TX_RD_THRSH(4)) |
|
|
|
|
V_MAC_TX_RL_THRSH(4) |
|
|
|
|
V_MAC_RX_PL_THRSH(4) |
|
|
|
|
V_MAC_RX_RD_THRSH(4) | /* Must be '4' */
|
|
|
|
V_MAC_RX_PL_THRSH(4) |
|
|
|
|
V_MAC_RX_RL_THRSH(8) |
|
|
|
|
0;
|
|
|
|
|
|
|
|
framecfg = V_MAC_MIN_FRAMESZ_DEFAULT |
|
|
|
|
V_MAC_MAX_FRAMESZ_DEFAULT |
|
|
|
|
V_MAC_BACKOFF_SEL(1);
|
|
|
|
|
|
|
|
/*
|
2005-10-19 16:40:02 +02:00
|
|
|
* Clear out the hash address map
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
port = s->sbm_base + R_MAC_HASH_BASE;
|
|
|
|
for (idx = 0; idx < MAC_HASH_COUNT; idx++) {
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(0, port);
|
2005-04-17 00:20:36 +02:00
|
|
|
port += sizeof(uint64_t);
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Clear out the exact-match table
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
port = s->sbm_base + R_MAC_ADDR_BASE;
|
|
|
|
for (idx = 0; idx < MAC_ADDR_COUNT; idx++) {
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(0, port);
|
2005-04-17 00:20:36 +02:00
|
|
|
port += sizeof(uint64_t);
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Clear out the DMA Channel mapping table registers
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
port = s->sbm_base + R_MAC_CHUP0_BASE;
|
|
|
|
for (idx = 0; idx < MAC_CHMAP_COUNT; idx++) {
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(0, port);
|
2005-04-17 00:20:36 +02:00
|
|
|
port += sizeof(uint64_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
port = s->sbm_base + R_MAC_CHLO0_BASE;
|
|
|
|
for (idx = 0; idx < MAC_CHMAP_COUNT; idx++) {
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(0, port);
|
2005-04-17 00:20:36 +02:00
|
|
|
port += sizeof(uint64_t);
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Program the hardware address. It goes into the hardware-address
|
|
|
|
* register as well as the first filter register.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
reg = sbmac_addr2reg(s->sbm_hwaddr);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
port = s->sbm_base + R_MAC_ADDR_BASE;
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(reg, port);
|
2005-04-17 00:20:36 +02:00
|
|
|
port = s->sbm_base + R_MAC_ETHERNET_ADDR;
|
|
|
|
|
|
|
|
#ifdef CONFIG_SB1_PASS_1_WORKAROUNDS
|
|
|
|
/*
|
|
|
|
* Pass1 SOCs do not receive packets addressed to the
|
|
|
|
* destination address in the R_MAC_ETHERNET_ADDR register.
|
|
|
|
* Set the value to zero.
|
|
|
|
*/
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(0, port);
|
2005-04-17 00:20:36 +02:00
|
|
|
#else
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(reg, port);
|
2005-04-17 00:20:36 +02:00
|
|
|
#endif
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Set the receive filter for no packets, and write values
|
|
|
|
* to the various config registers
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(0, s->sbm_rxfilter);
|
|
|
|
__raw_writeq(0, s->sbm_imr);
|
|
|
|
__raw_writeq(framecfg, s->sbm_framecfg);
|
|
|
|
__raw_writeq(fifo, s->sbm_fifocfg);
|
|
|
|
__raw_writeq(cfg, s->sbm_maccfg);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Initialize DMA channels (rings should be ok now)
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
sbdma_channel_start(&(s->sbm_rxdma), DMA_RX);
|
|
|
|
sbdma_channel_start(&(s->sbm_txdma), DMA_TX);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Configure the speed, duplex, and flow control
|
|
|
|
*/
|
|
|
|
|
|
|
|
sbmac_set_speed(s,s->sbm_speed);
|
|
|
|
sbmac_set_duplex(s,s->sbm_duplex,s->sbm_fc);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Fill the receive ring
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
sbdma_fillring(&(s->sbm_rxdma));
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Turn on the rest of the bits in the enable register
|
2005-10-19 16:40:02 +02:00
|
|
|
*/
|
|
|
|
|
2006-02-09 00:23:26 +01:00
|
|
|
#if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
|
|
|
|
__raw_writeq(M_MAC_RXDMA_EN0 |
|
|
|
|
M_MAC_TXDMA_EN0, s->sbm_macenable);
|
|
|
|
#elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X)
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(M_MAC_RXDMA_EN0 |
|
2005-04-17 00:20:36 +02:00
|
|
|
M_MAC_TXDMA_EN0 |
|
|
|
|
M_MAC_RX_ENABLE |
|
2005-10-19 16:39:05 +02:00
|
|
|
M_MAC_TX_ENABLE, s->sbm_macenable);
|
2006-02-09 00:23:26 +01:00
|
|
|
#else
|
|
|
|
#error invalid SiByte MAC configuation
|
|
|
|
#endif
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_SBMAC_COALESCE
|
|
|
|
/*
|
|
|
|
* Accept any TX interrupt and EOP count/timer RX interrupts on ch 0
|
|
|
|
*/
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_TX_CH0) |
|
|
|
|
((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_RX_CH0), s->sbm_imr);
|
2005-04-17 00:20:36 +02:00
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* Accept any kind of interrupt on TX and RX DMA channel 0
|
|
|
|
*/
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq((M_MAC_INT_CHANNEL << S_MAC_TX_CH0) |
|
|
|
|
(M_MAC_INT_CHANNEL << S_MAC_RX_CH0), s->sbm_imr);
|
2005-04-17 00:20:36 +02:00
|
|
|
#endif
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable receiving unicasts and broadcasts
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(M_MAC_UCAST_EN | M_MAC_BCAST_EN, s->sbm_rxfilter);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
2005-10-19 16:40:02 +02:00
|
|
|
* we're running now.
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
s->sbm_state = sbmac_state_on;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Program multicast addresses
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
sbmac_setmulti(s);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If channel was in promiscuous mode before, turn that on
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (s->sbm_devflags & IFF_PROMISC) {
|
|
|
|
sbmac_promiscuous_mode(s,1);
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBMAC_CHANNEL_STOP(s)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Stop packet processing on this MAC.
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* s - sbmac structure
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* nothing
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static void sbmac_channel_stop(struct sbmac_softc *s)
|
|
|
|
{
|
|
|
|
/* don't do this if already stopped */
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (s->sbm_state == sbmac_state_off)
|
|
|
|
return;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* don't accept any packets, disable all interrupts */
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(0, s->sbm_rxfilter);
|
|
|
|
__raw_writeq(0, s->sbm_imr);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* Turn off ticker */
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* XXX */
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* turn off receiver and transmitter */
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(0, s->sbm_macenable);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* We're stopped now. */
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
s->sbm_state = sbmac_state_off;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Stop DMA channels (rings should be ok now)
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
sbdma_channel_stop(&(s->sbm_rxdma));
|
|
|
|
sbdma_channel_stop(&(s->sbm_txdma));
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* Empty the receive and transmit rings */
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
sbdma_emptyring(&(s->sbm_rxdma));
|
|
|
|
sbdma_emptyring(&(s->sbm_txdma));
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBMAC_SET_CHANNEL_STATE(state)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Set the channel's state ON or OFF
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* state - new state
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* old state
|
|
|
|
********************************************************************* */
|
|
|
|
static sbmac_state_t sbmac_set_channel_state(struct sbmac_softc *sc,
|
|
|
|
sbmac_state_t state)
|
|
|
|
{
|
|
|
|
sbmac_state_t oldstate = sc->sbm_state;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* If same as previous state, return
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (state == oldstate) {
|
|
|
|
return oldstate;
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
2005-10-19 16:40:02 +02:00
|
|
|
* If new state is ON, turn channel on
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (state == sbmac_state_on) {
|
|
|
|
sbmac_channel_start(sc);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sbmac_channel_stop(sc);
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Return previous state
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return oldstate;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBMAC_PROMISCUOUS_MODE(sc,onoff)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Turn on or off promiscuous mode
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* sc - softc
|
|
|
|
* onoff - 1 to turn on, 0 to turn off
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* nothing
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static void sbmac_promiscuous_mode(struct sbmac_softc *sc,int onoff)
|
|
|
|
{
|
|
|
|
uint64_t reg;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (sc->sbm_state != sbmac_state_on)
|
|
|
|
return;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (onoff) {
|
2005-10-19 16:39:05 +02:00
|
|
|
reg = __raw_readq(sc->sbm_rxfilter);
|
2005-04-17 00:20:36 +02:00
|
|
|
reg |= M_MAC_ALLPKT_EN;
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(reg, sc->sbm_rxfilter);
|
2005-10-19 16:40:02 +02:00
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
else {
|
2005-10-19 16:39:05 +02:00
|
|
|
reg = __raw_readq(sc->sbm_rxfilter);
|
2005-04-17 00:20:36 +02:00
|
|
|
reg &= ~M_MAC_ALLPKT_EN;
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(reg, sc->sbm_rxfilter);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBMAC_SETIPHDR_OFFSET(sc,onoff)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Set the iphdr offset as 15 assuming ethernet encapsulation
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* sc - softc
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* nothing
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static void sbmac_set_iphdr_offset(struct sbmac_softc *sc)
|
|
|
|
{
|
|
|
|
uint64_t reg;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* Hard code the off set to 15 for now */
|
2005-10-19 16:39:05 +02:00
|
|
|
reg = __raw_readq(sc->sbm_rxfilter);
|
2005-04-17 00:20:36 +02:00
|
|
|
reg &= ~M_MAC_IPHDR_OFFSET | V_MAC_IPHDR_OFFSET(15);
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(reg, sc->sbm_rxfilter);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2006-02-09 00:23:26 +01:00
|
|
|
/* BCM1250 pass1 didn't have hardware checksum. Everything
|
|
|
|
later does. */
|
|
|
|
if (soc_type == K_SYS_SOC_TYPE_BCM1250 && periph_rev < 2) {
|
2005-04-17 00:20:36 +02:00
|
|
|
sc->rx_hw_checksum = DISABLE;
|
2006-02-09 00:23:26 +01:00
|
|
|
} else {
|
|
|
|
sc->rx_hw_checksum = ENABLE;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBMAC_ADDR2REG(ptr)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Convert six bytes into the 64-bit register value that
|
|
|
|
* we typically write into the SBMAC's address/mcast registers
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* ptr - pointer to 6 bytes
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* register value
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static uint64_t sbmac_addr2reg(unsigned char *ptr)
|
|
|
|
{
|
|
|
|
uint64_t reg = 0;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
ptr += 6;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
reg |= (uint64_t) *(--ptr);
|
2005-04-17 00:20:36 +02:00
|
|
|
reg <<= 8;
|
2005-10-19 16:40:02 +02:00
|
|
|
reg |= (uint64_t) *(--ptr);
|
2005-04-17 00:20:36 +02:00
|
|
|
reg <<= 8;
|
2005-10-19 16:40:02 +02:00
|
|
|
reg |= (uint64_t) *(--ptr);
|
2005-04-17 00:20:36 +02:00
|
|
|
reg <<= 8;
|
2005-10-19 16:40:02 +02:00
|
|
|
reg |= (uint64_t) *(--ptr);
|
2005-04-17 00:20:36 +02:00
|
|
|
reg <<= 8;
|
2005-10-19 16:40:02 +02:00
|
|
|
reg |= (uint64_t) *(--ptr);
|
2005-04-17 00:20:36 +02:00
|
|
|
reg <<= 8;
|
2005-10-19 16:40:02 +02:00
|
|
|
reg |= (uint64_t) *(--ptr);
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return reg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBMAC_SET_SPEED(s,speed)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Configure LAN speed for the specified MAC.
|
|
|
|
* Warning: must be called when MAC is off!
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* s - sbmac structure
|
|
|
|
* speed - speed to set MAC to (see sbmac_speed_t enum)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* 1 if successful
|
|
|
|
* 0 indicates invalid parameters
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static int sbmac_set_speed(struct sbmac_softc *s,sbmac_speed_t speed)
|
|
|
|
{
|
|
|
|
uint64_t cfg;
|
|
|
|
uint64_t framecfg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save new current values
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
s->sbm_speed = speed;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (s->sbm_state == sbmac_state_on)
|
|
|
|
return 0; /* save for next restart */
|
|
|
|
|
|
|
|
/*
|
2005-10-19 16:40:02 +02:00
|
|
|
* Read current register values
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
cfg = __raw_readq(s->sbm_maccfg);
|
|
|
|
framecfg = __raw_readq(s->sbm_framecfg);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Mask out the stuff we want to change
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
cfg &= ~(M_MAC_BURST_EN | M_MAC_SPEED_SEL);
|
|
|
|
framecfg &= ~(M_MAC_IFG_RX | M_MAC_IFG_TX | M_MAC_IFG_THRSH |
|
|
|
|
M_MAC_SLOT_SIZE);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Now add in the new bits
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
switch (speed) {
|
|
|
|
case sbmac_speed_10:
|
|
|
|
framecfg |= V_MAC_IFG_RX_10 |
|
|
|
|
V_MAC_IFG_TX_10 |
|
|
|
|
K_MAC_IFG_THRSH_10 |
|
|
|
|
V_MAC_SLOT_SIZE_10;
|
|
|
|
cfg |= V_MAC_SPEED_SEL_10MBPS;
|
|
|
|
break;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
case sbmac_speed_100:
|
|
|
|
framecfg |= V_MAC_IFG_RX_100 |
|
|
|
|
V_MAC_IFG_TX_100 |
|
|
|
|
V_MAC_IFG_THRSH_100 |
|
|
|
|
V_MAC_SLOT_SIZE_100;
|
|
|
|
cfg |= V_MAC_SPEED_SEL_100MBPS ;
|
|
|
|
break;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
case sbmac_speed_1000:
|
|
|
|
framecfg |= V_MAC_IFG_RX_1000 |
|
|
|
|
V_MAC_IFG_TX_1000 |
|
|
|
|
V_MAC_IFG_THRSH_1000 |
|
|
|
|
V_MAC_SLOT_SIZE_1000;
|
|
|
|
cfg |= V_MAC_SPEED_SEL_1000MBPS | M_MAC_BURST_EN;
|
|
|
|
break;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
case sbmac_speed_auto: /* XXX not implemented */
|
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
2005-10-19 16:40:02 +02:00
|
|
|
* Send the bits back to the hardware
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(framecfg, s->sbm_framecfg);
|
|
|
|
__raw_writeq(cfg, s->sbm_maccfg);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBMAC_SET_DUPLEX(s,duplex,fc)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Set Ethernet duplex and flow control options for this MAC
|
|
|
|
* Warning: must be called when MAC is off!
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* s - sbmac structure
|
|
|
|
* duplex - duplex setting (see sbmac_duplex_t)
|
|
|
|
* fc - flow control setting (see sbmac_fc_t)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* 1 if ok
|
|
|
|
* 0 if an invalid parameter combination was specified
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static int sbmac_set_duplex(struct sbmac_softc *s,sbmac_duplex_t duplex,sbmac_fc_t fc)
|
|
|
|
{
|
|
|
|
uint64_t cfg;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Save new current values
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
s->sbm_duplex = duplex;
|
|
|
|
s->sbm_fc = fc;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (s->sbm_state == sbmac_state_on)
|
|
|
|
return 0; /* save for next restart */
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
2005-10-19 16:40:02 +02:00
|
|
|
* Read current register values
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
cfg = __raw_readq(s->sbm_maccfg);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Mask off the stuff we're about to change
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
cfg &= ~(M_MAC_FC_SEL | M_MAC_FC_CMD | M_MAC_HDX_EN);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
switch (duplex) {
|
|
|
|
case sbmac_duplex_half:
|
|
|
|
switch (fc) {
|
|
|
|
case sbmac_fc_disabled:
|
|
|
|
cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_DISABLED;
|
|
|
|
break;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
case sbmac_fc_collision:
|
|
|
|
cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_ENABLED;
|
|
|
|
break;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
case sbmac_fc_carrier:
|
|
|
|
cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_ENAB_FALSECARR;
|
|
|
|
break;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
case sbmac_fc_auto: /* XXX not implemented */
|
2005-10-19 16:40:02 +02:00
|
|
|
/* fall through */
|
2005-04-17 00:20:36 +02:00
|
|
|
case sbmac_fc_frame: /* not valid in half duplex */
|
|
|
|
default: /* invalid selection */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
case sbmac_duplex_full:
|
|
|
|
switch (fc) {
|
|
|
|
case sbmac_fc_disabled:
|
|
|
|
cfg |= V_MAC_FC_CMD_DISABLED;
|
|
|
|
break;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
case sbmac_fc_frame:
|
|
|
|
cfg |= V_MAC_FC_CMD_ENABLED;
|
|
|
|
break;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
case sbmac_fc_collision: /* not valid in full duplex */
|
|
|
|
case sbmac_fc_carrier: /* not valid in full duplex */
|
|
|
|
case sbmac_fc_auto: /* XXX not implemented */
|
2005-10-19 16:40:02 +02:00
|
|
|
/* fall through */
|
2005-04-17 00:20:36 +02:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case sbmac_duplex_auto:
|
|
|
|
/* XXX not implemented */
|
|
|
|
break;
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
2005-10-19 16:40:02 +02:00
|
|
|
* Send the bits back to the hardware
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(cfg, s->sbm_maccfg);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBMAC_INTR()
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Interrupt handler for MAC interrupts
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* MAC structure
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* nothing
|
|
|
|
********************************************************************* */
|
|
|
|
static irqreturn_t sbmac_intr(int irq,void *dev_instance,struct pt_regs *rgs)
|
|
|
|
{
|
|
|
|
struct net_device *dev = (struct net_device *) dev_instance;
|
|
|
|
struct sbmac_softc *sc = netdev_priv(dev);
|
|
|
|
uint64_t isr;
|
|
|
|
int handled = 0;
|
|
|
|
|
|
|
|
for (;;) {
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Read the ISR (this clears the bits in the real
|
|
|
|
* register, except for counter addr)
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
isr = __raw_readq(sc->sbm_isr) & ~M_MAC_COUNTER_ADDR;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (isr == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
handled = 1;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Transmits on channel 0
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (isr & (M_MAC_INT_CHANNEL << S_MAC_TX_CH0)) {
|
|
|
|
sbdma_tx_process(sc,&(sc->sbm_txdma));
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Receives on channel 0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It's important to test all the bits (or at least the
|
|
|
|
* EOP_SEEN bit) when deciding to do the RX process
|
|
|
|
* particularly when coalescing, to make sure we
|
|
|
|
* take care of the following:
|
|
|
|
*
|
|
|
|
* If you have some packets waiting (have been received
|
|
|
|
* but no interrupt) and get a TX interrupt before
|
|
|
|
* the RX timer or counter expires, reading the ISR
|
|
|
|
* above will clear the timer and counter, and you
|
|
|
|
* won't get another interrupt until a packet shows
|
|
|
|
* up to start the timer again. Testing
|
|
|
|
* EOP_SEEN here takes care of this case.
|
|
|
|
* (EOP_SEEN is part of M_MAC_INT_CHANNEL << S_MAC_RX_CH0)
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (isr & (M_MAC_INT_CHANNEL << S_MAC_RX_CH0)) {
|
|
|
|
sbdma_rx_process(sc,&(sc->sbm_rxdma));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return IRQ_RETVAL(handled);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBMAC_START_TX(skb,dev)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Start output on the specified interface. Basically, we
|
2005-04-17 00:20:36 +02:00
|
|
|
* queue as many buffers as we can until the ring fills up, or
|
|
|
|
* we run off the end of the queue, whichever comes first.
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
|
|
|
*
|
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* nothing
|
|
|
|
********************************************************************* */
|
|
|
|
static int sbmac_start_tx(struct sk_buff *skb, struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct sbmac_softc *sc = netdev_priv(dev);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* lock eth irq */
|
|
|
|
spin_lock_irq (&sc->sbm_lock);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
2005-10-19 16:40:02 +02:00
|
|
|
* Put the buffer on the transmit ring. If we
|
2005-04-17 00:20:36 +02:00
|
|
|
* don't have room, stop the queue.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (sbdma_add_txbuffer(&(sc->sbm_txdma),skb)) {
|
|
|
|
/* XXX save skb that we could not send */
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
spin_unlock_irq(&sc->sbm_lock);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
dev->trans_start = jiffies;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
spin_unlock_irq (&sc->sbm_lock);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBMAC_SETMULTI(sc)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Reprogram the multicast table into the hardware, given
|
|
|
|
* the list of multicasts associated with the interface
|
|
|
|
* structure.
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* sc - softc
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* nothing
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static void sbmac_setmulti(struct sbmac_softc *sc)
|
|
|
|
{
|
|
|
|
uint64_t reg;
|
2005-10-19 16:39:05 +02:00
|
|
|
volatile void __iomem *port;
|
2005-04-17 00:20:36 +02:00
|
|
|
int idx;
|
|
|
|
struct dev_mc_list *mclist;
|
|
|
|
struct net_device *dev = sc->sbm_dev;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Clear out entire multicast table. We do this by nuking
|
|
|
|
* the entire hash table and all the direct matches except
|
2005-10-19 16:40:02 +02:00
|
|
|
* the first one, which is used for our station address
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
for (idx = 1; idx < MAC_ADDR_COUNT; idx++) {
|
|
|
|
port = sc->sbm_base + R_MAC_ADDR_BASE+(idx*sizeof(uint64_t));
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(0, port);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
for (idx = 0; idx < MAC_HASH_COUNT; idx++) {
|
|
|
|
port = sc->sbm_base + R_MAC_HASH_BASE+(idx*sizeof(uint64_t));
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(0, port);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Clear the filter to say we don't want any multicasts.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
reg = __raw_readq(sc->sbm_rxfilter);
|
2005-04-17 00:20:36 +02:00
|
|
|
reg &= ~(M_MAC_MCAST_INV | M_MAC_MCAST_EN);
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(reg, sc->sbm_rxfilter);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (dev->flags & IFF_ALLMULTI) {
|
2005-10-19 16:40:02 +02:00
|
|
|
/*
|
|
|
|
* Enable ALL multicasts. Do this by inverting the
|
|
|
|
* multicast enable bit.
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:39:05 +02:00
|
|
|
reg = __raw_readq(sc->sbm_rxfilter);
|
2005-04-17 00:20:36 +02:00
|
|
|
reg |= (M_MAC_MCAST_INV | M_MAC_MCAST_EN);
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(reg, sc->sbm_rxfilter);
|
2005-04-17 00:20:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Progam new multicast entries. For now, only use the
|
|
|
|
* perfect filter. In the future we'll need to use the
|
|
|
|
* hash filter if the perfect filter overflows
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* XXX only using perfect filter for now, need to use hash
|
|
|
|
* XXX if the table overflows */
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
idx = 1; /* skip station address */
|
|
|
|
mclist = dev->mc_list;
|
|
|
|
while (mclist && (idx < MAC_ADDR_COUNT)) {
|
|
|
|
reg = sbmac_addr2reg(mclist->dmi_addr);
|
|
|
|
port = sc->sbm_base + R_MAC_ADDR_BASE+(idx * sizeof(uint64_t));
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(reg, port);
|
2005-04-17 00:20:36 +02:00
|
|
|
idx++;
|
|
|
|
mclist = mclist->next;
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Enable the "accept multicast bits" if we programmed at least one
|
2005-10-19 16:40:02 +02:00
|
|
|
* multicast.
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (idx > 1) {
|
2005-10-19 16:39:05 +02:00
|
|
|
reg = __raw_readq(sc->sbm_rxfilter);
|
2005-04-17 00:20:36 +02:00
|
|
|
reg |= M_MAC_MCAST_EN;
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(reg, sc->sbm_rxfilter);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-02-09 00:23:26 +01:00
|
|
|
#if defined(SBMAC_ETH0_HWADDR) || defined(SBMAC_ETH1_HWADDR) || defined(SBMAC_ETH2_HWADDR) || defined(SBMAC_ETH3_HWADDR)
|
2005-04-17 00:20:36 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* SBMAC_PARSE_XDIGIT(str)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Parse a hex digit, returning its value
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* str - character
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* hex value, or -1 if invalid
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static int sbmac_parse_xdigit(char str)
|
|
|
|
{
|
|
|
|
int digit;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if ((str >= '0') && (str <= '9'))
|
|
|
|
digit = str - '0';
|
|
|
|
else if ((str >= 'a') && (str <= 'f'))
|
|
|
|
digit = str - 'a' + 10;
|
|
|
|
else if ((str >= 'A') && (str <= 'F'))
|
|
|
|
digit = str - 'A' + 10;
|
|
|
|
else
|
|
|
|
return -1;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return digit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBMAC_PARSE_HWADDR(str,hwaddr)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Convert a string in the form xx:xx:xx:xx:xx:xx into a 6-byte
|
|
|
|
* Ethernet address.
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* str - string
|
|
|
|
* hwaddr - pointer to hardware address
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* 0 if ok, else -1
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static int sbmac_parse_hwaddr(char *str, unsigned char *hwaddr)
|
|
|
|
{
|
|
|
|
int digit1,digit2;
|
|
|
|
int idx = 6;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
while (*str && (idx > 0)) {
|
|
|
|
digit1 = sbmac_parse_xdigit(*str);
|
|
|
|
if (digit1 < 0)
|
|
|
|
return -1;
|
|
|
|
str++;
|
|
|
|
if (!*str)
|
|
|
|
return -1;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if ((*str == ':') || (*str == '-')) {
|
|
|
|
digit2 = digit1;
|
|
|
|
digit1 = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
digit2 = sbmac_parse_xdigit(*str);
|
|
|
|
if (digit2 < 0)
|
|
|
|
return -1;
|
|
|
|
str++;
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
*hwaddr++ = (digit1 << 4) | digit2;
|
|
|
|
idx--;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (*str == '-')
|
|
|
|
str++;
|
|
|
|
if (*str == ':')
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int sb1250_change_mtu(struct net_device *_dev, int new_mtu)
|
|
|
|
{
|
|
|
|
if (new_mtu > ENET_PACKET_SIZE)
|
|
|
|
return -EINVAL;
|
|
|
|
_dev->mtu = new_mtu;
|
|
|
|
printk(KERN_INFO "changing the mtu to %d\n", new_mtu);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SBMAC_INIT(dev)
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Attach routine - init hardware and hook ourselves into linux
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
|
|
|
* Input parameters:
|
2005-04-17 00:20:36 +02:00
|
|
|
* dev - net_device structure
|
2005-10-19 16:40:02 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Return value:
|
|
|
|
* status
|
|
|
|
********************************************************************* */
|
|
|
|
|
|
|
|
static int sbmac_init(struct net_device *dev, int idx)
|
|
|
|
{
|
|
|
|
struct sbmac_softc *sc;
|
|
|
|
unsigned char *eaddr;
|
|
|
|
uint64_t ea_reg;
|
|
|
|
int i;
|
|
|
|
int err;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
sc = netdev_priv(dev);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* Determine controller base address */
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
sc->sbm_base = IOADDR(dev->base_addr);
|
|
|
|
sc->sbm_dev = dev;
|
|
|
|
sc->sbe_idx = idx;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
eaddr = sc->sbm_hwaddr;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Read the ethernet address. The firwmare left this programmed
|
|
|
|
* for us in the ethernet address register for each mac.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
ea_reg = __raw_readq(sc->sbm_base + R_MAC_ETHERNET_ADDR);
|
|
|
|
__raw_writeq(0, sc->sbm_base + R_MAC_ETHERNET_ADDR);
|
2005-04-17 00:20:36 +02:00
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
eaddr[i] = (uint8_t) (ea_reg & 0xFF);
|
|
|
|
ea_reg >>= 8;
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
dev->dev_addr[i] = eaddr[i];
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
2005-10-19 16:40:02 +02:00
|
|
|
* Init packet size
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
sc->sbm_buffersize = ENET_PACKET_SIZE + SMP_CACHE_BYTES * 2 + ETHER_ALIGN;
|
|
|
|
|
2005-10-19 16:40:02 +02:00
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Initialize context (get pointers to registers and stuff), then
|
|
|
|
* allocate the memory for the descriptor tables.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
sbmac_initctx(sc);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Set up Linux device callins
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
spin_lock_init(&(sc->sbm_lock));
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
dev->open = sbmac_open;
|
|
|
|
dev->hard_start_xmit = sbmac_start_tx;
|
|
|
|
dev->stop = sbmac_close;
|
|
|
|
dev->get_stats = sbmac_get_stats;
|
|
|
|
dev->set_multicast_list = sbmac_set_rx_mode;
|
|
|
|
dev->do_ioctl = sbmac_mii_ioctl;
|
|
|
|
dev->tx_timeout = sbmac_tx_timeout;
|
|
|
|
dev->watchdog_timeo = TX_TIMEOUT;
|
|
|
|
|
|
|
|
dev->change_mtu = sb1250_change_mtu;
|
|
|
|
|
|
|
|
/* This is needed for PASS2 for Rx H/W checksum feature */
|
|
|
|
sbmac_set_iphdr_offset(sc);
|
|
|
|
|
|
|
|
err = register_netdev(dev);
|
|
|
|
if (err)
|
|
|
|
goto out_uninit;
|
|
|
|
|
2005-10-10 15:50:24 +02:00
|
|
|
if (sc->rx_hw_checksum == ENABLE) {
|
2005-04-17 00:20:36 +02:00
|
|
|
printk(KERN_INFO "%s: enabling TCP rcv checksum\n",
|
|
|
|
sc->sbm_dev->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Display Ethernet address (this is called during the config
|
|
|
|
* process so we need to finish off the config message that
|
|
|
|
* was being displayed)
|
|
|
|
*/
|
|
|
|
printk(KERN_INFO
|
2005-10-19 16:40:02 +02:00
|
|
|
"%s: SiByte Ethernet at 0x%08lX, address: %02X:%02X:%02X:%02X:%02X:%02X\n",
|
2005-04-17 00:20:36 +02:00
|
|
|
dev->name, dev->base_addr,
|
|
|
|
eaddr[0],eaddr[1],eaddr[2],eaddr[3],eaddr[4],eaddr[5]);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_uninit:
|
|
|
|
sbmac_uninitctx(sc);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int sbmac_open(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct sbmac_softc *sc = netdev_priv(dev);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (debug > 1) {
|
|
|
|
printk(KERN_DEBUG "%s: sbmac_open() irq %d.\n", dev->name, dev->irq);
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* map/route interrupt (clear status first, in case something
|
|
|
|
* weird is pending; we haven't initialized the mac registers
|
|
|
|
* yet)
|
|
|
|
*/
|
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_readq(sc->sbm_isr);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (request_irq(dev->irq, &sbmac_intr, SA_SHIRQ, dev->name, dev))
|
|
|
|
return -EBUSY;
|
|
|
|
|
2005-10-20 13:01:28 +02:00
|
|
|
/*
|
|
|
|
* Probe phy address
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(sbmac_mii_probe(dev) == -1) {
|
|
|
|
printk("%s: failed to probe PHY.\n", dev->name);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
2005-10-19 16:40:02 +02:00
|
|
|
* Configure default speed
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
sbmac_mii_poll(sc,noisy_mii);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Turn on the channel
|
|
|
|
*/
|
|
|
|
|
|
|
|
sbmac_set_channel_state(sc,sbmac_state_on);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* XXX Station address is in dev->dev_addr
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (dev->if_port == 0)
|
2005-10-19 16:40:02 +02:00
|
|
|
dev->if_port = 0;
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
netif_start_queue(dev);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
sbmac_set_rx_mode(dev);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* Set the timer to check for link beat. */
|
|
|
|
init_timer(&sc->sbm_timer);
|
|
|
|
sc->sbm_timer.expires = jiffies + 2 * HZ/100;
|
|
|
|
sc->sbm_timer.data = (unsigned long)dev;
|
|
|
|
sc->sbm_timer.function = &sbmac_timer;
|
|
|
|
add_timer(&sc->sbm_timer);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-10-20 13:01:28 +02:00
|
|
|
static int sbmac_mii_probe(struct net_device *dev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct sbmac_softc *s = netdev_priv(dev);
|
|
|
|
u16 bmsr, id1, id2;
|
|
|
|
u32 vendor, device;
|
|
|
|
|
|
|
|
for (i=1; i<31; i++) {
|
|
|
|
bmsr = sbmac_mii_read(s, i, MII_BMSR);
|
|
|
|
if (bmsr != 0) {
|
|
|
|
s->sbm_phys[0] = i;
|
|
|
|
id1 = sbmac_mii_read(s, i, MII_PHYIDR1);
|
|
|
|
id2 = sbmac_mii_read(s, i, MII_PHYIDR2);
|
|
|
|
vendor = ((u32)id1 << 6) | ((id2 >> 10) & 0x3f);
|
|
|
|
device = (id2 >> 4) & 0x3f;
|
|
|
|
|
|
|
|
printk(KERN_INFO "%s: found phy %d, vendor %06x part %02x\n",
|
|
|
|
dev->name, i, vendor, device);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
static int sbmac_mii_poll(struct sbmac_softc *s,int noisy)
|
|
|
|
{
|
|
|
|
int bmsr,bmcr,k1stsr,anlpar;
|
|
|
|
int chg;
|
|
|
|
char buffer[100];
|
|
|
|
char *p = buffer;
|
|
|
|
|
|
|
|
/* Read the mode status and mode control registers. */
|
|
|
|
bmsr = sbmac_mii_read(s,s->sbm_phys[0],MII_BMSR);
|
|
|
|
bmcr = sbmac_mii_read(s,s->sbm_phys[0],MII_BMCR);
|
|
|
|
|
|
|
|
/* get the link partner status */
|
|
|
|
anlpar = sbmac_mii_read(s,s->sbm_phys[0],MII_ANLPAR);
|
|
|
|
|
|
|
|
/* if supported, read the 1000baseT register */
|
|
|
|
if (bmsr & BMSR_1000BT_XSR) {
|
|
|
|
k1stsr = sbmac_mii_read(s,s->sbm_phys[0],MII_K1STSR);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
k1stsr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
chg = 0;
|
|
|
|
|
|
|
|
if ((bmsr & BMSR_LINKSTAT) == 0) {
|
|
|
|
/*
|
|
|
|
* If link status is down, clear out old info so that when
|
|
|
|
* it comes back up it will force us to reconfigure speed
|
|
|
|
*/
|
|
|
|
s->sbm_phy_oldbmsr = 0;
|
|
|
|
s->sbm_phy_oldanlpar = 0;
|
|
|
|
s->sbm_phy_oldk1stsr = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((s->sbm_phy_oldbmsr != bmsr) ||
|
|
|
|
(s->sbm_phy_oldanlpar != anlpar) ||
|
|
|
|
(s->sbm_phy_oldk1stsr != k1stsr)) {
|
|
|
|
if (debug > 1) {
|
|
|
|
printk(KERN_DEBUG "%s: bmsr:%x/%x anlpar:%x/%x k1stsr:%x/%x\n",
|
|
|
|
s->sbm_dev->name,
|
|
|
|
s->sbm_phy_oldbmsr,bmsr,
|
|
|
|
s->sbm_phy_oldanlpar,anlpar,
|
|
|
|
s->sbm_phy_oldk1stsr,k1stsr);
|
|
|
|
}
|
|
|
|
s->sbm_phy_oldbmsr = bmsr;
|
|
|
|
s->sbm_phy_oldanlpar = anlpar;
|
|
|
|
s->sbm_phy_oldk1stsr = k1stsr;
|
|
|
|
chg = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chg == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
p += sprintf(p,"Link speed: ");
|
|
|
|
|
|
|
|
if (k1stsr & K1STSR_LP1KFD) {
|
|
|
|
s->sbm_speed = sbmac_speed_1000;
|
|
|
|
s->sbm_duplex = sbmac_duplex_full;
|
|
|
|
s->sbm_fc = sbmac_fc_frame;
|
|
|
|
p += sprintf(p,"1000BaseT FDX");
|
|
|
|
}
|
|
|
|
else if (k1stsr & K1STSR_LP1KHD) {
|
|
|
|
s->sbm_speed = sbmac_speed_1000;
|
|
|
|
s->sbm_duplex = sbmac_duplex_half;
|
|
|
|
s->sbm_fc = sbmac_fc_disabled;
|
|
|
|
p += sprintf(p,"1000BaseT HDX");
|
|
|
|
}
|
|
|
|
else if (anlpar & ANLPAR_TXFD) {
|
|
|
|
s->sbm_speed = sbmac_speed_100;
|
|
|
|
s->sbm_duplex = sbmac_duplex_full;
|
|
|
|
s->sbm_fc = (anlpar & ANLPAR_PAUSE) ? sbmac_fc_frame : sbmac_fc_disabled;
|
|
|
|
p += sprintf(p,"100BaseT FDX");
|
|
|
|
}
|
|
|
|
else if (anlpar & ANLPAR_TXHD) {
|
|
|
|
s->sbm_speed = sbmac_speed_100;
|
|
|
|
s->sbm_duplex = sbmac_duplex_half;
|
|
|
|
s->sbm_fc = sbmac_fc_disabled;
|
|
|
|
p += sprintf(p,"100BaseT HDX");
|
|
|
|
}
|
|
|
|
else if (anlpar & ANLPAR_10FD) {
|
|
|
|
s->sbm_speed = sbmac_speed_10;
|
|
|
|
s->sbm_duplex = sbmac_duplex_full;
|
|
|
|
s->sbm_fc = sbmac_fc_frame;
|
|
|
|
p += sprintf(p,"10BaseT FDX");
|
|
|
|
}
|
|
|
|
else if (anlpar & ANLPAR_10HD) {
|
|
|
|
s->sbm_speed = sbmac_speed_10;
|
|
|
|
s->sbm_duplex = sbmac_duplex_half;
|
|
|
|
s->sbm_fc = sbmac_fc_collision;
|
|
|
|
p += sprintf(p,"10BaseT HDX");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p += sprintf(p,"Unknown");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (noisy) {
|
|
|
|
printk(KERN_INFO "%s: %s\n",s->sbm_dev->name,buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void sbmac_timer(unsigned long data)
|
|
|
|
{
|
|
|
|
struct net_device *dev = (struct net_device *)data;
|
|
|
|
struct sbmac_softc *sc = netdev_priv(dev);
|
|
|
|
int next_tick = HZ;
|
|
|
|
int mii_status;
|
|
|
|
|
|
|
|
spin_lock_irq (&sc->sbm_lock);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* make IFF_RUNNING follow the MII status bit "Link established" */
|
|
|
|
mii_status = sbmac_mii_read(sc, sc->sbm_phys[0], MII_BMSR);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if ( (mii_status & BMSR_LINKSTAT) != (sc->sbm_phy_oldlinkstat) ) {
|
|
|
|
sc->sbm_phy_oldlinkstat = mii_status & BMSR_LINKSTAT;
|
|
|
|
if (mii_status & BMSR_LINKSTAT) {
|
|
|
|
netif_carrier_on(dev);
|
|
|
|
}
|
|
|
|
else {
|
2005-10-19 16:40:02 +02:00
|
|
|
netif_carrier_off(dev);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Poll the PHY to see what speed we should be running at
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (sbmac_mii_poll(sc,noisy_mii)) {
|
|
|
|
if (sc->sbm_state != sbmac_state_off) {
|
|
|
|
/*
|
|
|
|
* something changed, restart the channel
|
|
|
|
*/
|
|
|
|
if (debug > 1) {
|
|
|
|
printk("%s: restarting channel because speed changed\n",
|
|
|
|
sc->sbm_dev->name);
|
|
|
|
}
|
|
|
|
sbmac_channel_stop(sc);
|
|
|
|
sbmac_channel_start(sc);
|
|
|
|
}
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
spin_unlock_irq (&sc->sbm_lock);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
sc->sbm_timer.expires = jiffies + next_tick;
|
|
|
|
add_timer(&sc->sbm_timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void sbmac_tx_timeout (struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct sbmac_softc *sc = netdev_priv(dev);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
spin_lock_irq (&sc->sbm_lock);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
dev->trans_start = jiffies;
|
|
|
|
sc->sbm_stats.tx_errors++;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
spin_unlock_irq (&sc->sbm_lock);
|
|
|
|
|
|
|
|
printk (KERN_WARNING "%s: Transmit timed out\n",dev->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static struct net_device_stats *sbmac_get_stats(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct sbmac_softc *sc = netdev_priv(dev);
|
|
|
|
unsigned long flags;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
spin_lock_irqsave(&sc->sbm_lock, flags);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* XXX update other stats here */
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
spin_unlock_irqrestore(&sc->sbm_lock, flags);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return &sc->sbm_stats;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void sbmac_set_rx_mode(struct net_device *dev)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int msg_flag = 0;
|
|
|
|
struct sbmac_softc *sc = netdev_priv(dev);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sc->sbm_lock, flags);
|
|
|
|
if ((dev->flags ^ sc->sbm_devflags) & IFF_PROMISC) {
|
|
|
|
/*
|
|
|
|
* Promiscuous changed.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
|
|
|
if (dev->flags & IFF_PROMISC) {
|
2005-04-17 00:20:36 +02:00
|
|
|
/* Unconditionally log net taps. */
|
|
|
|
msg_flag = 1;
|
|
|
|
sbmac_promiscuous_mode(sc,1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
msg_flag = 2;
|
|
|
|
sbmac_promiscuous_mode(sc,0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&sc->sbm_lock, flags);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (msg_flag) {
|
|
|
|
printk(KERN_NOTICE "%s: Promiscuous mode %sabled.\n",
|
|
|
|
dev->name,(msg_flag==1)?"en":"dis");
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Program the multicasts. Do this every time.
|
|
|
|
*/
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
sbmac_setmulti(sc);
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sbmac_mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
|
|
|
|
{
|
|
|
|
struct sbmac_softc *sc = netdev_priv(dev);
|
|
|
|
u16 *data = (u16 *)&rq->ifr_ifru;
|
|
|
|
unsigned long flags;
|
|
|
|
int retval;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
spin_lock_irqsave(&sc->sbm_lock, flags);
|
|
|
|
retval = 0;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
switch(cmd) {
|
|
|
|
case SIOCDEVPRIVATE: /* Get the address of the PHY in use. */
|
|
|
|
data[0] = sc->sbm_phys[0] & 0x1f;
|
|
|
|
/* Fall Through */
|
|
|
|
case SIOCDEVPRIVATE+1: /* Read the specified MII register. */
|
|
|
|
data[3] = sbmac_mii_read(sc, data[0] & 0x1f, data[1] & 0x1f);
|
|
|
|
break;
|
|
|
|
case SIOCDEVPRIVATE+2: /* Write the specified MII register */
|
|
|
|
if (!capable(CAP_NET_ADMIN)) {
|
|
|
|
retval = -EPERM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (debug > 1) {
|
|
|
|
printk(KERN_DEBUG "%s: sbmac_mii_ioctl: write %02X %02X %02X\n",dev->name,
|
|
|
|
data[0],data[1],data[2]);
|
|
|
|
}
|
|
|
|
sbmac_mii_write(sc, data[0] & 0x1f, data[1] & 0x1f, data[2]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
retval = -EOPNOTSUPP;
|
|
|
|
}
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
spin_unlock_irqrestore(&sc->sbm_lock, flags);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sbmac_close(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct sbmac_softc *sc = netdev_priv(dev);
|
|
|
|
unsigned long flags;
|
|
|
|
int irq;
|
|
|
|
|
|
|
|
sbmac_set_channel_state(sc,sbmac_state_off);
|
|
|
|
|
|
|
|
del_timer_sync(&sc->sbm_timer);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sc->sbm_lock, flags);
|
|
|
|
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
|
|
|
|
if (debug > 1) {
|
|
|
|
printk(KERN_DEBUG "%s: Shutting down ethercard\n",dev->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&sc->sbm_lock, flags);
|
|
|
|
|
|
|
|
irq = dev->irq;
|
|
|
|
synchronize_irq(irq);
|
|
|
|
free_irq(irq, dev);
|
|
|
|
|
|
|
|
sbdma_emptyring(&(sc->sbm_txdma));
|
|
|
|
sbdma_emptyring(&(sc->sbm_rxdma));
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-02-09 00:23:26 +01:00
|
|
|
#if defined(SBMAC_ETH0_HWADDR) || defined(SBMAC_ETH1_HWADDR) || defined(SBMAC_ETH2_HWADDR) || defined(SBMAC_ETH3_HWADDR)
|
2005-04-17 00:20:36 +02:00
|
|
|
static void
|
|
|
|
sbmac_setup_hwaddr(int chan,char *addr)
|
|
|
|
{
|
|
|
|
uint8_t eaddr[6];
|
|
|
|
uint64_t val;
|
2005-10-19 16:39:05 +02:00
|
|
|
unsigned long port;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
port = A_MAC_CHANNEL_BASE(chan);
|
|
|
|
sbmac_parse_hwaddr(addr,eaddr);
|
|
|
|
val = sbmac_addr2reg(eaddr);
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(val, IOADDR(port+R_MAC_ETHERNET_ADDR));
|
|
|
|
val = __raw_readq(IOADDR(port+R_MAC_ETHERNET_ADDR));
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct net_device *dev_sbmac[MAX_UNITS];
|
|
|
|
|
|
|
|
static int __init
|
|
|
|
sbmac_init_module(void)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
struct net_device *dev;
|
2005-10-19 16:39:05 +02:00
|
|
|
unsigned long port;
|
2005-04-17 00:20:36 +02:00
|
|
|
int chip_max_units;
|
2005-10-19 16:40:02 +02:00
|
|
|
|
2006-02-09 00:23:26 +01:00
|
|
|
/* Set the number of available units based on the SOC type. */
|
2005-04-17 00:20:36 +02:00
|
|
|
switch (soc_type) {
|
|
|
|
case K_SYS_SOC_TYPE_BCM1250:
|
|
|
|
case K_SYS_SOC_TYPE_BCM1250_ALT:
|
|
|
|
chip_max_units = 3;
|
|
|
|
break;
|
|
|
|
case K_SYS_SOC_TYPE_BCM1120:
|
|
|
|
case K_SYS_SOC_TYPE_BCM1125:
|
|
|
|
case K_SYS_SOC_TYPE_BCM1125H:
|
|
|
|
case K_SYS_SOC_TYPE_BCM1250_ALT2: /* Hybrid */
|
|
|
|
chip_max_units = 2;
|
|
|
|
break;
|
2006-02-09 00:23:26 +01:00
|
|
|
case K_SYS_SOC_TYPE_BCM1x55:
|
|
|
|
case K_SYS_SOC_TYPE_BCM1x80:
|
|
|
|
chip_max_units = 4;
|
|
|
|
break;
|
2005-04-17 00:20:36 +02:00
|
|
|
default:
|
|
|
|
chip_max_units = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (chip_max_units > MAX_UNITS)
|
|
|
|
chip_max_units = MAX_UNITS;
|
|
|
|
|
2006-02-09 00:23:26 +01:00
|
|
|
/*
|
|
|
|
* For bringup when not using the firmware, we can pre-fill
|
|
|
|
* the MAC addresses using the environment variables
|
|
|
|
* specified in this file (or maybe from the config file?)
|
|
|
|
*/
|
|
|
|
#ifdef SBMAC_ETH0_HWADDR
|
|
|
|
if (chip_max_units > 0)
|
|
|
|
sbmac_setup_hwaddr(0,SBMAC_ETH0_HWADDR);
|
|
|
|
#endif
|
|
|
|
#ifdef SBMAC_ETH1_HWADDR
|
|
|
|
if (chip_max_units > 1)
|
|
|
|
sbmac_setup_hwaddr(1,SBMAC_ETH1_HWADDR);
|
|
|
|
#endif
|
|
|
|
#ifdef SBMAC_ETH2_HWADDR
|
|
|
|
if (chip_max_units > 2)
|
|
|
|
sbmac_setup_hwaddr(2,SBMAC_ETH2_HWADDR);
|
|
|
|
#endif
|
|
|
|
#ifdef SBMAC_ETH3_HWADDR
|
|
|
|
if (chip_max_units > 3)
|
|
|
|
sbmac_setup_hwaddr(3,SBMAC_ETH3_HWADDR);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Walk through the Ethernet controllers and find
|
|
|
|
* those who have their MAC addresses set.
|
|
|
|
*/
|
2005-04-17 00:20:36 +02:00
|
|
|
for (idx = 0; idx < chip_max_units; idx++) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the base address of the MAC.
|
|
|
|
*/
|
|
|
|
|
|
|
|
port = A_MAC_CHANNEL_BASE(idx);
|
|
|
|
|
2005-10-19 16:40:02 +02:00
|
|
|
/*
|
2005-04-17 00:20:36 +02:00
|
|
|
* The R_MAC_ETHERNET_ADDR register will be set to some nonzero
|
|
|
|
* value for us by the firmware if we're going to use this MAC.
|
|
|
|
* If we find a zero, skip this MAC.
|
|
|
|
*/
|
|
|
|
|
2005-10-19 16:39:05 +02:00
|
|
|
sbmac_orig_hwaddr[idx] = __raw_readq(IOADDR(port+R_MAC_ETHERNET_ADDR));
|
2005-04-17 00:20:36 +02:00
|
|
|
if (sbmac_orig_hwaddr[idx] == 0) {
|
|
|
|
printk(KERN_DEBUG "sbmac: not configuring MAC at "
|
|
|
|
"%lx\n", port);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Okay, cool. Initialize this MAC.
|
|
|
|
*/
|
|
|
|
|
|
|
|
dev = alloc_etherdev(sizeof(struct sbmac_softc));
|
2005-10-19 16:40:02 +02:00
|
|
|
if (!dev)
|
2005-04-17 00:20:36 +02:00
|
|
|
return -ENOMEM; /* return ENOMEM */
|
|
|
|
|
|
|
|
printk(KERN_DEBUG "sbmac: configuring MAC at %lx\n", port);
|
|
|
|
|
2006-02-09 00:23:26 +01:00
|
|
|
dev->irq = UNIT_INT(idx);
|
2005-04-17 00:20:36 +02:00
|
|
|
dev->base_addr = port;
|
|
|
|
dev->mem_end = 0;
|
|
|
|
if (sbmac_init(dev, idx)) {
|
|
|
|
port = A_MAC_CHANNEL_BASE(idx);
|
2005-10-19 16:39:05 +02:00
|
|
|
__raw_writeq(sbmac_orig_hwaddr[idx], IOADDR(port+R_MAC_ETHERNET_ADDR));
|
2005-04-17 00:20:36 +02:00
|
|
|
free_netdev(dev);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dev_sbmac[idx] = dev;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void __exit
|
|
|
|
sbmac_cleanup_module(void)
|
|
|
|
{
|
|
|
|
struct net_device *dev;
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
for (idx = 0; idx < MAX_UNITS; idx++) {
|
|
|
|
struct sbmac_softc *sc;
|
|
|
|
dev = dev_sbmac[idx];
|
|
|
|
if (!dev)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sc = netdev_priv(dev);
|
|
|
|
unregister_netdev(dev);
|
|
|
|
sbmac_uninitctx(sc);
|
|
|
|
free_netdev(dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(sbmac_init_module);
|
|
|
|
module_exit(sbmac_cleanup_module);
|