#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
+#include <linux/bitops.h>
#include <asm/auxio.h>
-#include <asm/bitops.h>
#include <asm/byteorder.h>
#include <asm/dma.h>
#include <asm/idprom.h>
#include "sunbmac.h"
-static char version[] __initdata =
- "sunbmac.c:v2.0 24/Nov/03 David S. Miller (davem@redhat.com)\n";
+#define DRV_NAME "sunbmac"
+#define DRV_VERSION "2.0"
+#define DRV_RELDATE "11/24/03"
+#define DRV_AUTHOR "David S. Miller (davem@redhat.com)"
+
+static char version[] =
+ DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " " DRV_AUTHOR "\n";
+
+MODULE_VERSION(DRV_VERSION);
+MODULE_AUTHOR(DRV_AUTHOR);
+MODULE_DESCRIPTION("Sun BigMAC 100baseT ethernet driver");
+MODULE_LICENSE("GPL");
#undef DEBUG_PROBE
#undef DEBUG_TX
#define DIRQ(x)
#endif
-static struct bigmac *root_bigmac_dev;
-
#define DEFAULT_JAMSIZE 4 /* Toe jam */
#define QEC_RESET_TRIES 200
-static int qec_global_reset(unsigned long gregs)
+static int qec_global_reset(void __iomem *gregs)
{
int tries = QEC_RESET_TRIES;
static void qec_init(struct bigmac *bp)
{
- unsigned long gregs = bp->gregs;
+ void __iomem *gregs = bp->gregs;
struct sbus_dev *qec_sdev = bp->qec_sdev;
u8 bsizes = bp->bigmac_bursts;
u32 regval;
#define TX_RESET_TRIES 32
#define RX_RESET_TRIES 32
-static void bigmac_tx_reset(unsigned long bregs)
+static void bigmac_tx_reset(void __iomem *bregs)
{
int tries = TX_RESET_TRIES;
}
}
-static void bigmac_rx_reset(unsigned long bregs)
+static void bigmac_rx_reset(void __iomem *bregs)
{
int tries = RX_RESET_TRIES;
bigmac_rx_reset(bp->bregs);
}
-static void bigmac_get_counters(struct bigmac *bp, unsigned long bregs)
+static void bigmac_get_counters(struct bigmac *bp, void __iomem *bregs)
{
struct net_device_stats *stats = &bp->enet_stats;
{
struct bmac_init_block *bb = bp->bmac_block;
struct net_device *dev = bp->dev;
- int i, gfp_flags = GFP_KERNEL;
+ int i;
+ gfp_t gfp_flags = GFP_KERNEL;
if (from_irq || in_interrupt())
gfp_flags = GFP_ATOMIC;
#define MGMT_CLKON (MGMT_PAL_INT_MDIO|MGMT_PAL_EXT_MDIO|MGMT_PAL_OENAB|MGMT_PAL_DCLOCK)
#define MGMT_CLKOFF (MGMT_PAL_INT_MDIO|MGMT_PAL_EXT_MDIO|MGMT_PAL_OENAB)
-static void idle_transceiver(unsigned long tregs)
+static void idle_transceiver(void __iomem *tregs)
{
int i = 20;
}
}
-static void write_tcvr_bit(struct bigmac *bp, unsigned long tregs, int bit)
+static void write_tcvr_bit(struct bigmac *bp, void __iomem *tregs, int bit)
{
if (bp->tcvr_type == internal) {
bit = (bit & 1) << 3;
}
}
-static int read_tcvr_bit(struct bigmac *bp, unsigned long tregs)
+static int read_tcvr_bit(struct bigmac *bp, void __iomem *tregs)
{
int retval = 0;
return retval;
}
-static int read_tcvr_bit2(struct bigmac *bp, unsigned long tregs)
+static int read_tcvr_bit2(struct bigmac *bp, void __iomem *tregs)
{
int retval = 0;
}
static void put_tcvr_byte(struct bigmac *bp,
- unsigned long tregs,
+ void __iomem *tregs,
unsigned int byte)
{
int shift = 4;
} while (shift >= 0);
}
-static void bigmac_tcvr_write(struct bigmac *bp, unsigned long tregs,
+static void bigmac_tcvr_write(struct bigmac *bp, void __iomem *tregs,
int reg, unsigned short val)
{
int shift;
}
static unsigned short bigmac_tcvr_read(struct bigmac *bp,
- unsigned long tregs,
+ void __iomem *tregs,
int reg)
{
unsigned short retval = 0;
static void bigmac_tcvr_init(struct bigmac *bp)
{
- unsigned long tregs = bp->tregs;
+ void __iomem *tregs = bp->tregs;
u32 mpal;
idle_transceiver(tregs);
}
}
-static int bigmac_init(struct bigmac *, int);
+static int bigmac_init_hw(struct bigmac *, int);
-static int try_next_permutation(struct bigmac *bp, unsigned long tregs)
+static int try_next_permutation(struct bigmac *bp, void __iomem *tregs)
{
if (bp->sw_bmcr & BMCR_SPEED100) {
int timeout;
static void bigmac_timer(unsigned long data)
{
struct bigmac *bp = (struct bigmac *) data;
- unsigned long tregs = bp->tregs;
+ void __iomem *tregs = bp->tregs;
int restart_timer = 0;
bp->timer_ticks++;
if (ret == -1) {
printk(KERN_ERR "%s: Link down, cable problem?\n",
bp->dev->name);
- ret = bigmac_init(bp, 0);
+ ret = bigmac_init_hw(bp, 0);
if (ret) {
printk(KERN_ERR "%s: Error, cannot re-init the "
"BigMAC.\n", bp->dev->name);
*/
static void bigmac_begin_auto_negotiation(struct bigmac *bp)
{
- unsigned long tregs = bp->tregs;
+ void __iomem *tregs = bp->tregs;
int timeout;
/* Grab new software copies of PHY registers. */
add_timer(&bp->bigmac_timer);
}
-static int bigmac_init(struct bigmac *bp, int from_irq)
+static int bigmac_init_hw(struct bigmac *bp, int from_irq)
{
- unsigned long gregs = bp->gregs;
- unsigned long cregs = bp->creg;
- unsigned long bregs = bp->bregs;
+ void __iomem *gregs = bp->gregs;
+ void __iomem *cregs = bp->creg;
+ void __iomem *bregs = bp->bregs;
unsigned char *e = &bp->dev->dev_addr[0];
/* Latch current counters into statistics. */
}
printk(" RESET\n");
- bigmac_init(bp, 1);
+ bigmac_init_hw(bp, 1);
}
/* BigMAC transmit complete service routines. */
printk(KERN_NOTICE "%s: Memory squeeze, deferring packet.\n", bp->dev->name);
}
-static irqreturn_t bigmac_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t bigmac_interrupt(int irq, void *dev_id)
{
struct bigmac *bp = (struct bigmac *) dev_id;
u32 qec_status, bmac_status;
struct bigmac *bp = (struct bigmac *) dev->priv;
int ret;
- ret = request_irq(dev->irq, &bigmac_interrupt, SA_SHIRQ, dev->name, bp);
+ ret = request_irq(dev->irq, &bigmac_interrupt, IRQF_SHARED, dev->name, bp);
if (ret) {
printk(KERN_ERR "BIGMAC: Can't order irq %d to go.\n", dev->irq);
return ret;
}
init_timer(&bp->bigmac_timer);
- ret = bigmac_init(bp, 0);
+ ret = bigmac_init_hw(bp, 0);
if (ret)
free_irq(dev->irq, bp);
return ret;
{
struct bigmac *bp = (struct bigmac *) dev->priv;
- bigmac_init(bp, 0);
+ bigmac_init_hw(bp, 0);
netif_wake_queue(dev);
}
static void bigmac_set_multicast(struct net_device *dev)
{
struct bigmac *bp = (struct bigmac *) dev->priv;
- unsigned long bregs = bp->bregs;
+ void __iomem *bregs = bp->bregs;
struct dev_mc_list *dmi = dev->mc_list;
char *addrs;
int i;
return (bp->sw_bmsr & BMSR_LSTATUS);
}
-static struct ethtool_ops bigmac_ethtool_ops = {
+static const struct ethtool_ops bigmac_ethtool_ops = {
.get_drvinfo = bigmac_get_drvinfo,
.get_link = bigmac_get_link,
};
bp->qec_sdev = qec_sdev;
bp->bigmac_sdev = qec_sdev->child;
+ SET_NETDEV_DEV(dev, &bp->bigmac_sdev->ofdev.dev);
+
spin_lock_init(&bp->lock);
/* Verify the registers we expect, are actually there. */
goto fail_and_cleanup;
}
- /* Put us into the list of instances attached for later driver
- * exit.
- */
- bp->next_module = root_bigmac_dev;
- root_bigmac_dev = bp;
+ dev_set_drvdata(&bp->bigmac_sdev->ofdev.dev, bp);
printk(KERN_INFO "%s: BigMAC 100baseT Ethernet ", dev->name);
for (i = 0; i < 6; i++)
/* QEC can be the parent of either QuadEthernet or
* a BigMAC. We want the latter.
*/
-static int __init bigmac_match(struct sbus_dev *sdev)
+static int __devinit bigmac_sbus_probe(struct of_device *dev, const struct of_device_id *match)
{
- struct sbus_dev *child = sdev->child;
+ struct sbus_dev *sdev = to_sbus_device(&dev->dev);
+ struct device_node *dp = dev->node;
- if (strcmp(sdev->prom_name, "qec") != 0)
- return 0;
-
- if (child == NULL)
- return 0;
+ if (!strcmp(dp->name, "be"))
+ sdev = sdev->parent;
- if (strcmp(child->prom_name, "be") != 0)
- return 0;
-
- return 1;
+ return bigmac_ether_init(sdev);
}
-static int __init bigmac_probe(void)
+static int __devexit bigmac_sbus_remove(struct of_device *dev)
{
- struct sbus_bus *sbus;
- struct sbus_dev *sdev = 0;
- static int called;
- int cards = 0, v;
-
- root_bigmac_dev = NULL;
-
- if (called)
- return -ENODEV;
- called++;
-
- for_each_sbus(sbus) {
- for_each_sbusdev(sdev, sbus) {
- if (bigmac_match(sdev)) {
- cards++;
- if ((v = bigmac_ether_init(sdev)))
- return v;
- }
- }
- }
- if (!cards)
- return -ENODEV;
+ struct bigmac *bp = dev_get_drvdata(&dev->dev);
+ struct net_device *net_dev = bp->dev;
+
+ unregister_netdevice(net_dev);
+
+ sbus_iounmap(bp->gregs, GLOB_REG_SIZE);
+ sbus_iounmap(bp->creg, CREG_REG_SIZE);
+ sbus_iounmap(bp->bregs, BMAC_REG_SIZE);
+ sbus_iounmap(bp->tregs, TCVR_REG_SIZE);
+ sbus_free_consistent(bp->bigmac_sdev,
+ PAGE_SIZE,
+ bp->bmac_block,
+ bp->bblock_dvma);
+
+ free_netdev(net_dev);
+
+ dev_set_drvdata(&dev->dev, NULL);
+
return 0;
}
-static void __exit bigmac_cleanup(void)
-{
- while (root_bigmac_dev) {
- struct bigmac *bp = root_bigmac_dev;
- struct bigmac *bp_nxt = root_bigmac_dev->next_module;
+static struct of_device_id bigmac_sbus_match[] = {
+ {
+ .name = "qec",
+ },
+ {
+ .name = "be",
+ },
+ {},
+};
- sbus_iounmap(bp->gregs, GLOB_REG_SIZE);
- sbus_iounmap(bp->creg, CREG_REG_SIZE);
- sbus_iounmap(bp->bregs, BMAC_REG_SIZE);
- sbus_iounmap(bp->tregs, TCVR_REG_SIZE);
- sbus_free_consistent(bp->bigmac_sdev,
- PAGE_SIZE,
- bp->bmac_block,
- bp->bblock_dvma);
+MODULE_DEVICE_TABLE(of, bigmac_sbus_match);
- unregister_netdev(bp->dev);
- free_netdev(bp->dev);
- root_bigmac_dev = bp_nxt;
- }
+static struct of_platform_driver bigmac_sbus_driver = {
+ .name = "sunbmac",
+ .match_table = bigmac_sbus_match,
+ .probe = bigmac_sbus_probe,
+ .remove = __devexit_p(bigmac_sbus_remove),
+};
+
+static int __init bigmac_init(void)
+{
+ return of_register_driver(&bigmac_sbus_driver, &sbus_bus_type);
}
-module_init(bigmac_probe);
-module_exit(bigmac_cleanup);
-MODULE_LICENSE("GPL");
+static void __exit bigmac_exit(void)
+{
+ of_unregister_driver(&bigmac_sbus_driver);
+}
+
+module_init(bigmac_init);
+module_exit(bigmac_exit);