* May 1999, Al Viro: proper release of /proc/net/bmac entry, switched to
* dynamic procfs inode.
*/
-#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/netdevice.h>
struct bmac_data {
/* volatile struct bmac *bmac; */
struct sk_buff_head *queue;
- volatile struct dbdma_regs *tx_dma;
+ volatile struct dbdma_regs __iomem *tx_dma;
int tx_dma_intr;
- volatile struct dbdma_regs *rx_dma;
+ volatile struct dbdma_regs __iomem *rx_dma;
int rx_dma_intr;
volatile struct dbdma_cmd *tx_cmds; /* xmit dma command list */
volatile struct dbdma_cmd *rx_cmds; /* recv dma command list */
static void bmac_init_registers(struct net_device *dev);
static void bmac_enable_and_reset_chip(struct net_device *dev);
static int bmac_set_address(struct net_device *dev, void *addr);
-static irqreturn_t bmac_misc_intr(int irq, void *dev_id, struct pt_regs *regs);
-static irqreturn_t bmac_txdma_intr(int irq, void *dev_id, struct pt_regs *regs);
-static irqreturn_t bmac_rxdma_intr(int irq, void *dev_id, struct pt_regs *regs);
+static irqreturn_t bmac_misc_intr(int irq, void *dev_id);
+static irqreturn_t bmac_txdma_intr(int irq, void *dev_id);
+static irqreturn_t bmac_rxdma_intr(int irq, void *dev_id);
static void bmac_set_timeout(struct net_device *dev);
static void bmac_tx_timeout(unsigned long data);
static int bmac_output(struct sk_buff *skb, struct net_device *dev);
#define DBDMA_CLEAR(x) ( (x) << 16)
static inline void
-dbdma_st32(volatile unsigned long *a, unsigned long x)
+dbdma_st32(volatile __u32 __iomem *a, unsigned long x)
{
__asm__ volatile( "stwbrx %0,0,%1" : : "r" (x), "r" (a) : "memory");
return;
}
static inline unsigned long
-dbdma_ld32(volatile unsigned long *a)
+dbdma_ld32(volatile __u32 __iomem *a)
{
- unsigned long swap;
+ __u32 swap;
__asm__ volatile ("lwbrx %0,0,%1" : "=r" (swap) : "r" (a));
return swap;
}
static void
-dbdma_continue(volatile struct dbdma_regs *dmap)
+dbdma_continue(volatile struct dbdma_regs __iomem *dmap)
{
- dbdma_st32((volatile unsigned long *)&dmap->control,
+ dbdma_st32(&dmap->control,
DBDMA_SET(RUN|WAKE) | DBDMA_CLEAR(PAUSE|DEAD));
eieio();
}
static void
-dbdma_reset(volatile struct dbdma_regs *dmap)
+dbdma_reset(volatile struct dbdma_regs __iomem *dmap)
{
- dbdma_st32((volatile unsigned long *)&dmap->control,
+ dbdma_st32(&dmap->control,
DBDMA_CLEAR(ACTIVE|DEAD|WAKE|FLUSH|PAUSE|RUN));
eieio();
- while (dbdma_ld32((volatile unsigned long *)&dmap->status) & RUN)
+ while (dbdma_ld32(&dmap->status) & RUN)
eieio();
}
static inline
void bmwrite(struct net_device *dev, unsigned long reg_offset, unsigned data )
{
- out_le16((void *)dev->base_addr + reg_offset, data);
+ out_le16((void __iomem *)dev->base_addr + reg_offset, data);
}
static inline
-volatile unsigned short bmread(struct net_device *dev, unsigned long reg_offset )
+unsigned short bmread(struct net_device *dev, unsigned long reg_offset )
{
- return in_le16((void *)dev->base_addr + reg_offset);
+ return in_le16((void __iomem *)dev->base_addr + reg_offset);
}
static void
bmac_enable_and_reset_chip(struct net_device *dev)
{
struct bmac_data *bp = netdev_priv(dev);
- volatile struct dbdma_regs *rd = bp->rx_dma;
- volatile struct dbdma_regs *td = bp->tx_dma;
+ volatile struct dbdma_regs __iomem *rd = bp->rx_dma;
+ volatile struct dbdma_regs __iomem *td = bp->tx_dma;
if (rd)
dbdma_reset(rd);
udelay(10000);
}
- bmwrite(dev, RSEED, (unsigned short)0x1968);
+ bmwrite(dev, RSEED, (unsigned short)0x1968);
regValue = bmread(dev, XIFC);
regValue |= TxOutputEnable;
bmwrite(dev, BHASH2, bp->hash_table_mask[1]); /* bits 31 - 16 */
bmwrite(dev, BHASH1, bp->hash_table_mask[2]); /* bits 47 - 32 */
bmwrite(dev, BHASH0, bp->hash_table_mask[3]); /* bits 63 - 48 */
-
+
pWord16 = (unsigned short *)dev->dev_addr;
bmwrite(dev, MADD0, *pWord16++);
bmwrite(dev, MADD1, *pWord16++);
bmac_start_chip(struct net_device *dev)
{
struct bmac_data *bp = netdev_priv(dev);
- volatile struct dbdma_regs *rd = bp->rx_dma;
+ volatile struct dbdma_regs __iomem *rd = bp->rx_dma;
unsigned short oldConfig;
/* enable rx dma channel */
dbdma_continue(rd);
- oldConfig = bmread(dev, TXCFG);
+ oldConfig = bmread(dev, TXCFG);
bmwrite(dev, TXCFG, oldConfig | TxMACEnable );
/* turn on rx plus any other bits already on (promiscuous possibly) */
- oldConfig = bmread(dev, RXCFG);
+ oldConfig = bmread(dev, RXCFG);
bmwrite(dev, RXCFG, oldConfig | RxMACEnable );
udelay(20000);
}
}
#ifdef CONFIG_PM
-static int bmac_suspend(struct macio_dev *mdev, u32 state)
+static int bmac_suspend(struct macio_dev *mdev, pm_message_t state)
{
- struct net_device* dev = macio_get_drvdata(mdev);
+ struct net_device* dev = macio_get_drvdata(mdev);
struct bmac_data *bp = netdev_priv(dev);
unsigned long flags;
unsigned short config;
int i;
-
+
netif_device_detach(dev);
/* prolly should wait for dma to finish & turn off the chip */
spin_lock_irqsave(&bp->lock, flags);
bp->sleeping = 1;
spin_unlock_irqrestore(&bp->lock, flags);
if (bp->opened) {
- volatile struct dbdma_regs *rd = bp->rx_dma;
- volatile struct dbdma_regs *td = bp->tx_dma;
-
+ volatile struct dbdma_regs __iomem *rd = bp->rx_dma;
+ volatile struct dbdma_regs __iomem *td = bp->tx_dma;
+
config = bmread(dev, RXCFG);
bmwrite(dev, RXCFG, (config & ~RxMACEnable));
config = bmread(dev, TXCFG);
static int bmac_resume(struct macio_dev *mdev)
{
- struct net_device* dev = macio_get_drvdata(mdev);
+ struct net_device* dev = macio_get_drvdata(mdev);
struct bmac_data *bp = netdev_priv(dev);
/* see if this is enough */
static void
bmac_init_tx_ring(struct bmac_data *bp)
{
- volatile struct dbdma_regs *td = bp->tx_dma;
+ volatile struct dbdma_regs __iomem *td = bp->tx_dma;
memset((char *)bp->tx_cmds, 0, (N_TX_RING+1) * sizeof(struct dbdma_cmd));
static int
bmac_init_rx_ring(struct bmac_data *bp)
{
- volatile struct dbdma_regs *rd = bp->rx_dma;
+ volatile struct dbdma_regs __iomem *rd = bp->rx_dma;
int i;
struct sk_buff *skb;
static int bmac_transmit_packet(struct sk_buff *skb, struct net_device *dev)
{
struct bmac_data *bp = netdev_priv(dev);
- volatile struct dbdma_regs *td = bp->tx_dma;
+ volatile struct dbdma_regs __iomem *td = bp->tx_dma;
int i;
/* see if there's a free slot in the tx ring */
static int rxintcount;
-static irqreturn_t bmac_rxdma_intr(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t bmac_rxdma_intr(int irq, void *dev_id)
{
struct net_device *dev = (struct net_device *) dev_id;
struct bmac_data *bp = netdev_priv(dev);
- volatile struct dbdma_regs *rd = bp->rx_dma;
+ volatile struct dbdma_regs __iomem *rd = bp->rx_dma;
volatile struct dbdma_cmd *cp;
int i, nb, stat;
struct sk_buff *skb;
static int txintcount;
-static irqreturn_t bmac_txdma_intr(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t bmac_txdma_intr(int irq, void *dev_id)
{
struct net_device *dev = (struct net_device *) dev_id;
struct bmac_data *bp = netdev_priv(dev);
else high_crc_set = 1;
cur = cur << 1;
-
+
if ((next & 0x0001) == 0) low_data_set = 0;
else low_data_set = 1;
next = next >> 1;
-
+
/* do the XOR */
if (high_crc_set ^ low_data_set) cur = cur ^ ENET_CRCPOLY;
}
static unsigned int
bmac_crc(unsigned short *address)
-{
+{
unsigned int newcrc;
XXDEBUG(("bmac_crc: addr=%#04x, %#04x, %#04x\n", *address, address[1], address[2]));
static void
bmac_addhash(struct bmac_data *bp, unsigned char *addr)
-{
+{
unsigned int crc;
unsigned short mask;
static void
bmac_removehash(struct bmac_data *bp, unsigned char *addr)
-{
+{
unsigned int crc;
unsigned char mask;
bmwrite(dev, RXCFG, rx_cfg);
} else {
u16 hash_table[4];
-
+
rx_cfg = bmread(dev, RXCFG);
rx_cfg &= ~RxPromiscEnable;
bmwrite(dev, RXCFG, rx_cfg);
for(i = 0; i < 4; i++) hash_table[i] = 0;
-
+
for(i = 0; i < dev->mc_count; i++) {
addrs = dmi->dmi_addr;
dmi = dmi->next;
static int miscintcount;
-static irqreturn_t bmac_misc_intr(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t bmac_misc_intr(int irq, void *dev_id)
{
struct net_device *dev = (struct net_device *) dev_id;
struct bmac_data *bp = netdev_priv(dev);
XXDEBUG(("bmac_misc_intr\n"));
}
/* XXDEBUG(("bmac_misc_intr, status=%#08x\n", status)); */
- /* bmac_txdma_intr_inner(irq, dev_id, regs); */
+ /* bmac_txdma_intr_inner(irq, dev_id); */
/* if (status & FrameReceived) bp->stats.rx_dropped++; */
if (status & RxErrorMask) bp->stats.rx_errors++;
if (status & RxCRCCntExp) bp->stats.rx_crc_errors++;
int i;
unsigned short data;
- for (i = 0; i < 6; i++)
+ for (i = 0; i < 6; i++)
{
reset_and_select_srom(dev);
data = read_srom(dev, i + EnetAddressOffset/2, SROMAddressBits);
bmac_start_chip(dev);
bmwrite(dev, INTDISABLE, EnableNormal);
bp->sleeping = 0;
-
+
/*
* It seems that the bmac can't receive until it's transmitted
* a packet. So we give it a dummy packet to transmit.
spin_unlock_irqrestore(&bp->lock, flags);
}
-static int __devinit bmac_probe(struct macio_dev *mdev, const struct of_match *match)
+static int __devinit bmac_probe(struct macio_dev *mdev, const struct of_device_id *match)
{
int j, rev, ret;
struct bmac_data *bp;
- unsigned char *addr;
+ const unsigned char *prop_addr;
+ unsigned char addr[6];
struct net_device *dev;
int is_bmac_plus = ((int)match->data) != 0;
printk(KERN_ERR "BMAC: can't use, need 3 addrs and 3 intrs\n");
return -ENODEV;
}
- addr = get_property(macio_get_of_node(mdev), "mac-address", NULL);
- if (addr == NULL) {
- addr = get_property(macio_get_of_node(mdev), "local-mac-address", NULL);
- if (addr == NULL) {
+ prop_addr = get_property(macio_get_of_node(mdev), "mac-address", NULL);
+ if (prop_addr == NULL) {
+ prop_addr = get_property(macio_get_of_node(mdev),
+ "local-mac-address", NULL);
+ if (prop_addr == NULL) {
printk(KERN_ERR "BMAC: Can't get mac-address\n");
return -ENODEV;
}
}
+ memcpy(addr, prop_addr, sizeof(addr));
dev = alloc_etherdev(PRIV_BYTES);
if (!dev) {
printk(KERN_ERR "BMAC: alloc_etherdev failed, out of memory\n");
return -ENOMEM;
}
-
+
bp = netdev_priv(dev);
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &mdev->ofdev.dev);
goto err_out_iounmap;
bp->is_bmac_plus = is_bmac_plus;
- bp->tx_dma = (volatile struct dbdma_regs *)
- ioremap(macio_resource_start(mdev, 1), macio_resource_len(mdev, 1));
+ bp->tx_dma = ioremap(macio_resource_start(mdev, 1), macio_resource_len(mdev, 1));
if (!bp->tx_dma)
goto err_out_iounmap;
bp->tx_dma_intr = macio_irq(mdev, 1);
- bp->rx_dma = (volatile struct dbdma_regs *)
- ioremap(macio_resource_start(mdev, 2), macio_resource_len(mdev, 2));
+ bp->rx_dma = ioremap(macio_resource_start(mdev, 2), macio_resource_len(mdev, 2));
if (!bp->rx_dma)
goto err_out_iounmap_tx;
bp->rx_dma_intr = macio_irq(mdev, 2);
printk("%c%.2x", (j? ':': ' '), dev->dev_addr[j]);
XXDEBUG((", base_addr=%#0lx", dev->base_addr));
printk("\n");
-
+
return 0;
err_out_irq2:
err_out_irq0:
free_irq(dev->irq, dev);
err_out_iounmap_rx:
- iounmap((void *)bp->rx_dma);
+ iounmap(bp->rx_dma);
err_out_iounmap_tx:
- iounmap((void *)bp->tx_dma);
+ iounmap(bp->tx_dma);
err_out_iounmap:
- iounmap((void *)dev->base_addr);
+ iounmap((void __iomem *)dev->base_addr);
out_release:
macio_release_resources(mdev);
out_free:
bp->opened = 1;
bmac_reset_and_enable(dev);
enable_irq(dev->irq);
- dev->flags |= IFF_RUNNING;
return 0;
}
static int bmac_close(struct net_device *dev)
{
struct bmac_data *bp = netdev_priv(dev);
- volatile struct dbdma_regs *rd = bp->rx_dma;
- volatile struct dbdma_regs *td = bp->tx_dma;
+ volatile struct dbdma_regs __iomem *rd = bp->rx_dma;
+ volatile struct dbdma_regs __iomem *td = bp->tx_dma;
unsigned short config;
int i;
bp->sleeping = 1;
- dev->flags &= ~(IFF_UP | IFF_RUNNING);
/* disable rx and tx */
config = bmread(dev, RXCFG);
if (bp->sleeping)
return;
-
+
spin_lock_irqsave(&bp->lock, flags);
while (1) {
i = bp->tx_fill + 1;
{
struct net_device *dev = (struct net_device *) data;
struct bmac_data *bp = netdev_priv(dev);
- volatile struct dbdma_regs *td = bp->tx_dma;
- volatile struct dbdma_regs *rd = bp->rx_dma;
+ volatile struct dbdma_regs __iomem *td = bp->tx_dma;
+ volatile struct dbdma_regs __iomem *rd = bp->rx_dma;
volatile struct dbdma_cmd *cp;
unsigned long flags;
unsigned short config, oldConfig;
}
/* turn it back on */
- oldConfig = bmread(dev, RXCFG);
+ oldConfig = bmread(dev, RXCFG);
bmwrite(dev, RXCFG, oldConfig | RxMACEnable );
- oldConfig = bmread(dev, TXCFG);
+ oldConfig = bmread(dev, TXCFG);
bmwrite(dev, TXCFG, oldConfig | TxMACEnable );
spin_unlock_irqrestore(&bp->lock, flags);
static void dump_dbdma(volatile struct dbdma_cmd *cp,int count)
{
int i,*ip;
-
+
for (i=0;i< count;i++) {
ip = (int*)(cp+i);
-
+
printk("dbdma req 0x%x addr 0x%x baddr 0x%x xfer/res 0x%x\n",
ld_le32(ip+0),
ld_le32(ip+1),
unregister_netdev(dev);
free_irq(dev->irq, dev);
- free_irq(bp->tx_dma_intr, dev);
+ free_irq(bp->tx_dma_intr, dev);
free_irq(bp->rx_dma_intr, dev);
- iounmap((void *)dev->base_addr);
- iounmap((void *)bp->tx_dma);
- iounmap((void *)bp->rx_dma);
+ iounmap((void __iomem *)dev->base_addr);
+ iounmap(bp->tx_dma);
+ iounmap(bp->rx_dma);
macio_release_resources(mdev);
return 0;
}
-static struct of_match bmac_match[] =
+static struct of_device_id bmac_match[] =
{
{
.name = "bmac",
- .type = OF_ANY_MATCH,
- .compatible = OF_ANY_MATCH,
.data = (void *)0,
},
{
- .name = OF_ANY_MATCH,
.type = "network",
.compatible = "bmac+",
.data = (void *)1,
},
{},
};
+MODULE_DEVICE_TABLE (of, bmac_match);
-static struct macio_driver bmac_driver =
+static struct macio_driver bmac_driver =
{
.name = "bmac",
.match_table = bmac_match,
{
macio_unregister_driver(&bmac_driver);
- if (bmac_emergency_rxbuf != NULL) {
- kfree(bmac_emergency_rxbuf);
- bmac_emergency_rxbuf = NULL;
- }
+ kfree(bmac_emergency_rxbuf);
+ bmac_emergency_rxbuf = NULL;
}
MODULE_AUTHOR("Randy Gobbel/Paul Mackerras");