0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/module.h>
0010 #include <linux/kernel.h>
0011 #include <linux/types.h>
0012 #include <linux/interrupt.h>
0013 #include <linux/ioport.h>
0014 #include <linux/string.h>
0015 #include <linux/delay.h>
0016 #include <linux/init.h>
0017 #include <linux/errno.h>
0018 #include <linux/gfp.h>
0019 #include <linux/pgtable.h>
0020
0021 #include <linux/socket.h>
0022 #include <linux/route.h>
0023 #include <linux/netdevice.h>
0024 #include <linux/etherdevice.h>
0025 #include <linux/skbuff.h>
0026
0027 #include <asm/io.h>
0028 #include <asm/mvme147hw.h>
0029
0030
0031
0032
0033
0034 #define LANCE_LOG_TX_BUFFERS 1
0035 #define LANCE_LOG_RX_BUFFERS 3
0036
0037 #include "7990.h" /* use generic LANCE code */
0038
0039
0040 struct m147lance_private {
0041 struct lance_private lance;
0042 unsigned long ram;
0043 };
0044
0045
0046
0047
0048
0049
0050 static int m147lance_open(struct net_device *dev);
0051 static int m147lance_close(struct net_device *dev);
0052 static void m147lance_writerap(struct lance_private *lp, unsigned short value);
0053 static void m147lance_writerdp(struct lance_private *lp, unsigned short value);
0054 static unsigned short m147lance_readrdp(struct lance_private *lp);
0055
0056 typedef void (*writerap_t)(void *, unsigned short);
0057 typedef void (*writerdp_t)(void *, unsigned short);
0058 typedef unsigned short (*readrdp_t)(void *);
0059
0060 static const struct net_device_ops lance_netdev_ops = {
0061 .ndo_open = m147lance_open,
0062 .ndo_stop = m147lance_close,
0063 .ndo_start_xmit = lance_start_xmit,
0064 .ndo_set_rx_mode = lance_set_multicast,
0065 .ndo_tx_timeout = lance_tx_timeout,
0066 .ndo_validate_addr = eth_validate_addr,
0067 .ndo_set_mac_address = eth_mac_addr,
0068 };
0069
0070
0071 static struct net_device * __init mvme147lance_probe(void)
0072 {
0073 struct net_device *dev;
0074 static int called;
0075 static const char name[] = "MVME147 LANCE";
0076 struct m147lance_private *lp;
0077 u8 macaddr[ETH_ALEN];
0078 u_long *addr;
0079 u_long address;
0080 int err;
0081
0082 if (!MACH_IS_MVME147 || called)
0083 return ERR_PTR(-ENODEV);
0084 called++;
0085
0086 dev = alloc_etherdev(sizeof(struct m147lance_private));
0087 if (!dev)
0088 return ERR_PTR(-ENOMEM);
0089
0090
0091 dev->base_addr = (unsigned long)MVME147_LANCE_BASE;
0092 dev->netdev_ops = &lance_netdev_ops;
0093 dev->dma = 0;
0094
0095 addr = (u_long *)ETHERNET_ADDRESS;
0096 address = *addr;
0097 macaddr[0] = 0x08;
0098 macaddr[1] = 0x00;
0099 macaddr[2] = 0x3e;
0100 address = address >> 8;
0101 macaddr[5] = address&0xff;
0102 address = address >> 8;
0103 macaddr[4] = address&0xff;
0104 address = address >> 8;
0105 macaddr[3] = address&0xff;
0106 eth_hw_addr_set(dev, macaddr);
0107
0108 printk("%s: MVME147 at 0x%08lx, irq %d, Hardware Address %pM\n",
0109 dev->name, dev->base_addr, MVME147_LANCE_IRQ,
0110 dev->dev_addr);
0111
0112 lp = netdev_priv(dev);
0113 lp->ram = __get_dma_pages(GFP_ATOMIC, 3);
0114 if (!lp->ram) {
0115 printk("%s: No memory for LANCE buffers\n", dev->name);
0116 free_netdev(dev);
0117 return ERR_PTR(-ENOMEM);
0118 }
0119
0120 lp->lance.name = name;
0121 lp->lance.base = dev->base_addr;
0122 lp->lance.init_block = (struct lance_init_block *)(lp->ram);
0123 lp->lance.lance_init_block = (struct lance_init_block *)(lp->ram);
0124 lp->lance.busmaster_regval = LE_C3_BSWP;
0125 lp->lance.irq = MVME147_LANCE_IRQ;
0126 lp->lance.writerap = (writerap_t)m147lance_writerap;
0127 lp->lance.writerdp = (writerdp_t)m147lance_writerdp;
0128 lp->lance.readrdp = (readrdp_t)m147lance_readrdp;
0129 lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
0130 lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
0131 lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
0132 lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
0133
0134 err = register_netdev(dev);
0135 if (err) {
0136 free_pages(lp->ram, 3);
0137 free_netdev(dev);
0138 return ERR_PTR(err);
0139 }
0140
0141 return dev;
0142 }
0143
0144 static void m147lance_writerap(struct lance_private *lp, unsigned short value)
0145 {
0146 out_be16(lp->base + LANCE_RAP, value);
0147 }
0148
0149 static void m147lance_writerdp(struct lance_private *lp, unsigned short value)
0150 {
0151 out_be16(lp->base + LANCE_RDP, value);
0152 }
0153
0154 static unsigned short m147lance_readrdp(struct lance_private *lp)
0155 {
0156 return in_be16(lp->base + LANCE_RDP);
0157 }
0158
0159 static int m147lance_open(struct net_device *dev)
0160 {
0161 int status;
0162
0163 status = lance_open(dev);
0164 if (status)
0165 return status;
0166
0167 m147_pcc->lan_cntrl = 0;
0168 m147_pcc->lan_cntrl = 0x08 | 0x04;
0169
0170 return 0;
0171 }
0172
0173 static int m147lance_close(struct net_device *dev)
0174 {
0175
0176 m147_pcc->lan_cntrl = 0x0;
0177 lance_close(dev);
0178 return 0;
0179 }
0180
0181 MODULE_LICENSE("GPL");
0182
0183 static struct net_device *dev_mvme147_lance;
0184 static int __init m147lance_init(void)
0185 {
0186 dev_mvme147_lance = mvme147lance_probe();
0187 return PTR_ERR_OR_ZERO(dev_mvme147_lance);
0188 }
0189 module_init(m147lance_init);
0190
0191 static void __exit m147lance_exit(void)
0192 {
0193 struct m147lance_private *lp = netdev_priv(dev_mvme147_lance);
0194 unregister_netdev(dev_mvme147_lance);
0195 free_pages(lp->ram, 3);
0196 free_netdev(dev_mvme147_lance);
0197 }
0198 module_exit(m147lance_exit);