Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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