Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /* hplance.c  : the  Linux/hp300/lance ethernet driver
0003  *
0004  * Copyright (C) 05/1998 Peter Maydell <pmaydell@chiark.greenend.org.uk>
0005  * Based on the Sun Lance driver and the NetBSD HP Lance driver
0006  * Uses the generic 7990.c LANCE code.
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/pgtable.h>
0019 /* Used for the temporal inet entries and routing */
0020 #include <linux/socket.h>
0021 #include <linux/route.h>
0022 #include <linux/dio.h>
0023 #include <linux/netdevice.h>
0024 #include <linux/etherdevice.h>
0025 #include <linux/skbuff.h>
0026 
0027 #include <asm/io.h>
0028 
0029 #include "hplance.h"
0030 
0031 /* We have 16392 bytes of RAM for the init block and buffers. This places
0032  * an upper limit on the number of buffers we can use. NetBSD uses 8 Rx
0033  * buffers and 2 Tx buffers, it takes (8 + 2) * 1544 bytes.
0034  */
0035 #define LANCE_LOG_TX_BUFFERS 1
0036 #define LANCE_LOG_RX_BUFFERS 3
0037 
0038 #include "7990.h"                                 /* use generic LANCE code */
0039 
0040 /* Our private data structure */
0041 struct hplance_private {
0042     struct lance_private lance;
0043 };
0044 
0045 /* function prototypes... This is easy because all the grot is in the
0046  * generic LANCE support. All we have to support is probing for boards,
0047  * plus board-specific init, open and close actions.
0048  * Oh, and we need to tell the generic code how to read and write LANCE registers...
0049  */
0050 static int hplance_init_one(struct dio_dev *d, const struct dio_device_id *ent);
0051 static void hplance_init(struct net_device *dev, struct dio_dev *d);
0052 static void hplance_remove_one(struct dio_dev *d);
0053 static void hplance_writerap(void *priv, unsigned short value);
0054 static void hplance_writerdp(void *priv, unsigned short value);
0055 static unsigned short hplance_readrdp(void *priv);
0056 static int hplance_open(struct net_device *dev);
0057 static int hplance_close(struct net_device *dev);
0058 
0059 static struct dio_device_id hplance_dio_tbl[] = {
0060     { DIO_ID_LAN },
0061     { 0 }
0062 };
0063 
0064 static struct dio_driver hplance_driver = {
0065     .name      = "hplance",
0066     .id_table  = hplance_dio_tbl,
0067     .probe     = hplance_init_one,
0068     .remove    = hplance_remove_one,
0069 };
0070 
0071 static const struct net_device_ops hplance_netdev_ops = {
0072     .ndo_open       = hplance_open,
0073     .ndo_stop       = hplance_close,
0074     .ndo_start_xmit     = lance_start_xmit,
0075     .ndo_set_rx_mode    = lance_set_multicast,
0076     .ndo_validate_addr  = eth_validate_addr,
0077     .ndo_set_mac_address    = eth_mac_addr,
0078 #ifdef CONFIG_NET_POLL_CONTROLLER
0079     .ndo_poll_controller    = lance_poll,
0080 #endif
0081 };
0082 
0083 /* Find all the HP Lance boards and initialise them... */
0084 static int hplance_init_one(struct dio_dev *d, const struct dio_device_id *ent)
0085 {
0086     struct net_device *dev;
0087     int err = -ENOMEM;
0088 
0089     dev = alloc_etherdev(sizeof(struct hplance_private));
0090     if (!dev)
0091         goto out;
0092 
0093     err = -EBUSY;
0094     if (!request_mem_region(dio_resource_start(d),
0095                 dio_resource_len(d), d->name))
0096         goto out_free_netdev;
0097 
0098     hplance_init(dev, d);
0099     err = register_netdev(dev);
0100     if (err)
0101         goto out_release_mem_region;
0102 
0103     dio_set_drvdata(d, dev);
0104 
0105     printk(KERN_INFO "%s: %s; select code %d, addr %pM, irq %d\n",
0106            dev->name, d->name, d->scode, dev->dev_addr, d->ipl);
0107 
0108     return 0;
0109 
0110  out_release_mem_region:
0111     release_mem_region(dio_resource_start(d), dio_resource_len(d));
0112  out_free_netdev:
0113     free_netdev(dev);
0114  out:
0115     return err;
0116 }
0117 
0118 static void hplance_remove_one(struct dio_dev *d)
0119 {
0120     struct net_device *dev = dio_get_drvdata(d);
0121 
0122     unregister_netdev(dev);
0123     release_mem_region(dio_resource_start(d), dio_resource_len(d));
0124     free_netdev(dev);
0125 }
0126 
0127 /* Initialise a single lance board at the given DIO device */
0128 static void hplance_init(struct net_device *dev, struct dio_dev *d)
0129 {
0130     unsigned long va = (d->resource.start + DIO_VIRADDRBASE);
0131     struct hplance_private *lp;
0132     u8 addr[ETH_ALEN];
0133     int i;
0134 
0135     /* reset the board */
0136     out_8(va + DIO_IDOFF, 0xff);
0137     udelay(100);                              /* ariba! ariba! udelay! udelay! */
0138 
0139     /* Fill the dev fields */
0140     dev->base_addr = va;
0141     dev->netdev_ops = &hplance_netdev_ops;
0142     dev->dma = 0;
0143 
0144     for (i = 0; i < 6; i++) {
0145         /* The NVRAM holds our ethernet address, one nibble per byte,
0146          * at bytes NVRAMOFF+1,3,5,7,9...
0147          */
0148         addr[i] = ((in_8(va + HPLANCE_NVRAMOFF + i*4 + 1) & 0xF) << 4)
0149             | (in_8(va + HPLANCE_NVRAMOFF + i*4 + 3) & 0xF);
0150     }
0151     eth_hw_addr_set(dev, addr);
0152 
0153     lp = netdev_priv(dev);
0154     lp->lance.name = d->name;
0155     lp->lance.base = va;
0156     lp->lance.init_block = (struct lance_init_block *)(va + HPLANCE_MEMOFF); /* CPU addr */
0157     lp->lance.lance_init_block = NULL;              /* LANCE addr of same RAM */
0158     lp->lance.busmaster_regval = LE_C3_BSWP;        /* we're bigendian */
0159     lp->lance.irq = d->ipl;
0160     lp->lance.writerap = hplance_writerap;
0161     lp->lance.writerdp = hplance_writerdp;
0162     lp->lance.readrdp = hplance_readrdp;
0163     lp->lance.lance_log_rx_bufs = LANCE_LOG_RX_BUFFERS;
0164     lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
0165     lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
0166     lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
0167 }
0168 
0169 /* This is disgusting. We have to check the DIO status register for ack every
0170  * time we read or write the LANCE registers.
0171  */
0172 static void hplance_writerap(void *priv, unsigned short value)
0173 {
0174     struct lance_private *lp = (struct lance_private *)priv;
0175 
0176     do {
0177         out_be16(lp->base + HPLANCE_REGOFF + LANCE_RAP, value);
0178     } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
0179 }
0180 
0181 static void hplance_writerdp(void *priv, unsigned short value)
0182 {
0183     struct lance_private *lp = (struct lance_private *)priv;
0184 
0185     do {
0186         out_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP, value);
0187     } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
0188 }
0189 
0190 static unsigned short hplance_readrdp(void *priv)
0191 {
0192     struct lance_private *lp = (struct lance_private *)priv;
0193     __u16 value;
0194 
0195     do {
0196         value = in_be16(lp->base + HPLANCE_REGOFF + LANCE_RDP);
0197     } while ((in_8(lp->base + HPLANCE_STATUS) & LE_ACK) == 0);
0198     return value;
0199 }
0200 
0201 static int hplance_open(struct net_device *dev)
0202 {
0203     int status;
0204     struct lance_private *lp = netdev_priv(dev);
0205 
0206     status = lance_open(dev);                 /* call generic lance open code */
0207     if (status)
0208         return status;
0209     /* enable interrupts at board level. */
0210     out_8(lp->base + HPLANCE_STATUS, LE_IE);
0211 
0212     return 0;
0213 }
0214 
0215 static int hplance_close(struct net_device *dev)
0216 {
0217     struct lance_private *lp = netdev_priv(dev);
0218 
0219     out_8(lp->base + HPLANCE_STATUS, 0);    /* disable interrupts at boardlevel */
0220     lance_close(dev);
0221     return 0;
0222 }
0223 
0224 static int __init hplance_init_module(void)
0225 {
0226     return dio_register_driver(&hplance_driver);
0227 }
0228 
0229 static void __exit hplance_cleanup_module(void)
0230 {
0231     dio_unregister_driver(&hplance_driver);
0232 }
0233 
0234 module_init(hplance_init_module);
0235 module_exit(hplance_cleanup_module);
0236 
0237 MODULE_LICENSE("GPL");