Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* mvme147.c : the Linux/mvme147/lance ethernet driver |
| 3 | * |
| 4 | * Copyright (C) 05/1998 Peter Maydell <pmaydell@chiark.greenend.org.uk> |
| 5 | * Based on the Sun Lance driver and the NetBSD HP Lance driver |
| 6 | * Uses the generic 7990.c LANCE code. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/types.h> |
| 12 | #include <linux/interrupt.h> |
| 13 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/string.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/errno.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | /* Used for the temporal inet entries and routing */ |
| 20 | #include <linux/socket.h> |
| 21 | #include <linux/route.h> |
| 22 | #include <linux/netdevice.h> |
| 23 | #include <linux/etherdevice.h> |
| 24 | #include <linux/skbuff.h> |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <asm/io.h> |
| 27 | #include <asm/pgtable.h> |
| 28 | #include <asm/mvme147hw.h> |
| 29 | |
Amos Kong | 1cff389 | 2014-06-05 11:01:21 +0800 | [diff] [blame] | 30 | /* We have 32K of RAM for the init block and buffers. This places |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx |
Amos Kong | 1cff389 | 2014-06-05 11:01:21 +0800 | [diff] [blame] | 32 | * buffers and 2 Tx buffers, it takes (8 + 2) * 1544 bytes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | */ |
| 34 | #define LANCE_LOG_TX_BUFFERS 1 |
| 35 | #define LANCE_LOG_RX_BUFFERS 3 |
| 36 | |
| 37 | #include "7990.h" /* use generic LANCE code */ |
| 38 | |
| 39 | /* Our private data structure */ |
| 40 | struct m147lance_private { |
| 41 | struct lance_private lance; |
| 42 | unsigned long ram; |
| 43 | }; |
| 44 | |
| 45 | /* function prototypes... This is easy because all the grot is in the |
| 46 | * generic LANCE support. All we have to support is probing for boards, |
| 47 | * plus board-specific init, open and close actions. |
| 48 | * Oh, and we need to tell the generic code how to read and write LANCE registers... |
| 49 | */ |
| 50 | static int m147lance_open(struct net_device *dev); |
| 51 | static int m147lance_close(struct net_device *dev); |
| 52 | static void m147lance_writerap(struct lance_private *lp, unsigned short value); |
| 53 | static void m147lance_writerdp(struct lance_private *lp, unsigned short value); |
| 54 | static unsigned short m147lance_readrdp(struct lance_private *lp); |
| 55 | |
| 56 | typedef void (*writerap_t)(void *, unsigned short); |
| 57 | typedef void (*writerdp_t)(void *, unsigned short); |
| 58 | typedef unsigned short (*readrdp_t)(void *); |
| 59 | |
Alexander Beregalov | 96cd55e | 2009-04-15 12:52:52 +0000 | [diff] [blame] | 60 | static const struct net_device_ops lance_netdev_ops = { |
| 61 | .ndo_open = m147lance_open, |
| 62 | .ndo_stop = m147lance_close, |
| 63 | .ndo_start_xmit = lance_start_xmit, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 64 | .ndo_set_rx_mode = lance_set_multicast, |
Alexander Beregalov | 96cd55e | 2009-04-15 12:52:52 +0000 | [diff] [blame] | 65 | .ndo_tx_timeout = lance_tx_timeout, |
Alexander Beregalov | 96cd55e | 2009-04-15 12:52:52 +0000 | [diff] [blame] | 66 | .ndo_validate_addr = eth_validate_addr, |
| 67 | .ndo_set_mac_address = eth_mac_addr, |
| 68 | }; |
| 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | /* Initialise the one and only on-board 7990 */ |
| 71 | struct net_device * __init mvme147lance_probe(int unit) |
| 72 | { |
| 73 | struct net_device *dev; |
| 74 | static int called; |
| 75 | static const char name[] = "MVME147 LANCE"; |
| 76 | struct m147lance_private *lp; |
| 77 | u_long *addr; |
| 78 | u_long address; |
| 79 | int err; |
| 80 | |
| 81 | if (!MACH_IS_MVME147 || called) |
| 82 | return ERR_PTR(-ENODEV); |
| 83 | called++; |
| 84 | |
| 85 | dev = alloc_etherdev(sizeof(struct m147lance_private)); |
| 86 | if (!dev) |
| 87 | return ERR_PTR(-ENOMEM); |
| 88 | |
| 89 | if (unit >= 0) |
| 90 | sprintf(dev->name, "eth%d", unit); |
| 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | /* Fill the dev fields */ |
| 93 | dev->base_addr = (unsigned long)MVME147_LANCE_BASE; |
Alexander Beregalov | 96cd55e | 2009-04-15 12:52:52 +0000 | [diff] [blame] | 94 | dev->netdev_ops = &lance_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | dev->dma = 0; |
| 96 | |
Geert Uytterhoeven | a8ab77a | 2013-12-28 21:11:14 +0100 | [diff] [blame] | 97 | addr = (u_long *)ETHERNET_ADDRESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | address = *addr; |
Geert Uytterhoeven | a8ab77a | 2013-12-28 21:11:14 +0100 | [diff] [blame] | 99 | dev->dev_addr[0] = 0x08; |
| 100 | dev->dev_addr[1] = 0x00; |
| 101 | dev->dev_addr[2] = 0x3e; |
| 102 | address = address >> 8; |
| 103 | dev->dev_addr[5] = address&0xff; |
| 104 | address = address >> 8; |
| 105 | dev->dev_addr[4] = address&0xff; |
| 106 | address = address >> 8; |
| 107 | dev->dev_addr[3] = address&0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Geert Uytterhoeven | a8ab77a | 2013-12-28 21:11:14 +0100 | [diff] [blame] | 109 | printk("%s: MVME147 at 0x%08lx, irq %d, Hardware Address %pM\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 110 | dev->name, dev->base_addr, MVME147_LANCE_IRQ, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 111 | dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 113 | lp = netdev_priv(dev); |
Amos Kong | 1cff389 | 2014-06-05 11:01:21 +0800 | [diff] [blame] | 114 | lp->ram = __get_dma_pages(GFP_ATOMIC, 3); /* 32K */ |
Geert Uytterhoeven | a8ab77a | 2013-12-28 21:11:14 +0100 | [diff] [blame] | 115 | if (!lp->ram) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | printk("%s: No memory for LANCE buffers\n", dev->name); |
| 117 | free_netdev(dev); |
| 118 | return ERR_PTR(-ENOMEM); |
| 119 | } |
| 120 | |
Geert Uytterhoeven | 4ffa8fc | 2013-12-28 21:11:15 +0100 | [diff] [blame] | 121 | lp->lance.name = name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | lp->lance.base = dev->base_addr; |
| 123 | lp->lance.init_block = (struct lance_init_block *)(lp->ram); /* CPU addr */ |
| 124 | lp->lance.lance_init_block = (struct lance_init_block *)(lp->ram); /* LANCE addr of same RAM */ |
| 125 | lp->lance.busmaster_regval = LE_C3_BSWP; /* we're bigendian */ |
| 126 | lp->lance.irq = MVME147_LANCE_IRQ; |
| 127 | lp->lance.writerap = (writerap_t)m147lance_writerap; |
| 128 | lp->lance.writerdp = (writerdp_t)m147lance_writerdp; |
| 129 | lp->lance.readrdp = (readrdp_t)m147lance_readrdp; |
| 130 | lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS; |
| 131 | lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS; |
| 132 | lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK; |
| 133 | lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK; |
| 134 | |
| 135 | err = register_netdev(dev); |
| 136 | if (err) { |
| 137 | free_pages(lp->ram, 3); |
| 138 | free_netdev(dev); |
| 139 | return ERR_PTR(err); |
| 140 | } |
| 141 | |
| 142 | return dev; |
| 143 | } |
| 144 | |
| 145 | static void m147lance_writerap(struct lance_private *lp, unsigned short value) |
| 146 | { |
| 147 | out_be16(lp->base + LANCE_RAP, value); |
| 148 | } |
| 149 | |
| 150 | static void m147lance_writerdp(struct lance_private *lp, unsigned short value) |
| 151 | { |
| 152 | out_be16(lp->base + LANCE_RDP, value); |
| 153 | } |
| 154 | |
| 155 | static unsigned short m147lance_readrdp(struct lance_private *lp) |
| 156 | { |
| 157 | return in_be16(lp->base + LANCE_RDP); |
| 158 | } |
| 159 | |
| 160 | static int m147lance_open(struct net_device *dev) |
| 161 | { |
| 162 | int status; |
| 163 | |
| 164 | status = lance_open(dev); /* call generic lance open code */ |
| 165 | if (status) |
| 166 | return status; |
| 167 | /* enable interrupts at board level. */ |
Geert Uytterhoeven | a8ab77a | 2013-12-28 21:11:14 +0100 | [diff] [blame] | 168 | m147_pcc->lan_cntrl = 0; /* clear the interrupts (if any) */ |
| 169 | m147_pcc->lan_cntrl = 0x08 | 0x04; /* Enable irq 4 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | static int m147lance_close(struct net_device *dev) |
| 175 | { |
| 176 | /* disable interrupts at boardlevel */ |
Geert Uytterhoeven | a8ab77a | 2013-12-28 21:11:14 +0100 | [diff] [blame] | 177 | m147_pcc->lan_cntrl = 0x0; /* disable interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | lance_close(dev); |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | #ifdef MODULE |
| 183 | MODULE_LICENSE("GPL"); |
| 184 | |
| 185 | static struct net_device *dev_mvme147_lance; |
Al Viro | afc8eb4 | 2006-06-14 18:50:53 -0400 | [diff] [blame] | 186 | int __init init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | { |
| 188 | dev_mvme147_lance = mvme147lance_probe(-1); |
Rusty Russell | 8c6ffba | 2013-07-15 11:20:32 +0930 | [diff] [blame] | 189 | return PTR_ERR_OR_ZERO(dev_mvme147_lance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Al Viro | afc8eb4 | 2006-06-14 18:50:53 -0400 | [diff] [blame] | 192 | void __exit cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 194 | struct m147lance_private *lp = netdev_priv(dev_mvme147_lance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | unregister_netdev(dev_mvme147_lance); |
| 196 | free_pages(lp->ram, 3); |
| 197 | free_netdev(dev_mvme147_lance); |
| 198 | } |
| 199 | |
| 200 | #endif /* MODULE */ |