18c2ecf20Sopenharmony_ci/* lasi_82596.c -- driver for the intel 82596 ethernet controller, as
28c2ecf20Sopenharmony_ci   munged into HPPA boxen .
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci   This driver is based upon 82596.c, original credits are below...
58c2ecf20Sopenharmony_ci   but there were too many hoops which HP wants jumped through to
68c2ecf20Sopenharmony_ci   keep this code in there in a sane manner.
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci   3 primary sources of the mess --
98c2ecf20Sopenharmony_ci   1) hppa needs *lots* of cacheline flushing to keep this kind of
108c2ecf20Sopenharmony_ci   MMIO running.
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci   2) The 82596 needs to see all of its pointers as their physical
138c2ecf20Sopenharmony_ci   address.  Thus virt_to_bus/bus_to_virt are *everywhere*.
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci   3) The implementation HP is using seems to be significantly pickier
168c2ecf20Sopenharmony_ci   about when and how the command and RX units are started.  some
178c2ecf20Sopenharmony_ci   command ordering was changed.
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci   Examination of the mach driver leads one to believe that there
208c2ecf20Sopenharmony_ci   might be a saner way to pull this off...  anyone who feels like a
218c2ecf20Sopenharmony_ci   full rewrite can be my guest.
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci   Split 02/13/2000 Sam Creasey (sammy@oh.verio.com)
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci   02/01/2000  Initial modifications for parisc by Helge Deller (deller@gmx.de)
268c2ecf20Sopenharmony_ci   03/02/2000  changes for better/correct(?) cache-flushing (deller)
278c2ecf20Sopenharmony_ci*/
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci/* 82596.c: A generic 82596 ethernet driver for linux. */
308c2ecf20Sopenharmony_ci/*
318c2ecf20Sopenharmony_ci   Based on Apricot.c
328c2ecf20Sopenharmony_ci   Written 1994 by Mark Evans.
338c2ecf20Sopenharmony_ci   This driver is for the Apricot 82596 bus-master interface
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci   Modularised 12/94 Mark Evans
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci   Modified to support the 82596 ethernet chips on 680x0 VME boards.
398c2ecf20Sopenharmony_ci   by Richard Hirst <richard@sleepie.demon.co.uk>
408c2ecf20Sopenharmony_ci   Renamed to be 82596.c
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci   980825:  Changed to receive directly in to sk_buffs which are
438c2ecf20Sopenharmony_ci   allocated at open() time.  Eliminates copy on incoming frames
448c2ecf20Sopenharmony_ci   (small ones are still copied).  Shared data now held in a
458c2ecf20Sopenharmony_ci   non-cached page, so we can run on 68060 in copyback mode.
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci   TBD:
488c2ecf20Sopenharmony_ci   * look at deferring rx frames rather than discarding (as per tulip)
498c2ecf20Sopenharmony_ci   * handle tx ring full as per tulip
508c2ecf20Sopenharmony_ci   * performance test to tune rx_copybreak
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci   Most of my modifications relate to the braindead big-endian
538c2ecf20Sopenharmony_ci   implementation by Intel.  When the i596 is operating in
548c2ecf20Sopenharmony_ci   'big-endian' mode, it thinks a 32 bit value of 0x12345678
558c2ecf20Sopenharmony_ci   should be stored as 0x56781234.  This is a real pain, when
568c2ecf20Sopenharmony_ci   you have linked lists which are shared by the 680x0 and the
578c2ecf20Sopenharmony_ci   i596.
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci   Driver skeleton
608c2ecf20Sopenharmony_ci   Written 1993 by Donald Becker.
618c2ecf20Sopenharmony_ci   Copyright 1993 United States Government as represented by the Director,
628c2ecf20Sopenharmony_ci   National Security Agency. This software may only be used and distributed
638c2ecf20Sopenharmony_ci   according to the terms of the GNU General Public License as modified by SRC,
648c2ecf20Sopenharmony_ci   incorporated herein by reference.
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci   The author may be reached as becker@scyld.com, or C/O
678c2ecf20Sopenharmony_ci   Scyld Computing Corporation, 410 Severn Ave., Suite 210, Annapolis MD 21403
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci */
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#include <linux/module.h>
728c2ecf20Sopenharmony_ci#include <linux/kernel.h>
738c2ecf20Sopenharmony_ci#include <linux/string.h>
748c2ecf20Sopenharmony_ci#include <linux/ptrace.h>
758c2ecf20Sopenharmony_ci#include <linux/errno.h>
768c2ecf20Sopenharmony_ci#include <linux/ioport.h>
778c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
788c2ecf20Sopenharmony_ci#include <linux/delay.h>
798c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
808c2ecf20Sopenharmony_ci#include <linux/etherdevice.h>
818c2ecf20Sopenharmony_ci#include <linux/skbuff.h>
828c2ecf20Sopenharmony_ci#include <linux/types.h>
838c2ecf20Sopenharmony_ci#include <linux/bitops.h>
848c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h>
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci#include <asm/io.h>
878c2ecf20Sopenharmony_ci#include <asm/irq.h>
888c2ecf20Sopenharmony_ci#include <asm/pdc.h>
898c2ecf20Sopenharmony_ci#include <asm/parisc-device.h>
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci#define LASI_82596_DRIVER_VERSION "LASI 82596 driver - Revision: 1.30"
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#define PA_I82596_RESET		0	/* Offsets relative to LASI-LAN-Addr.*/
948c2ecf20Sopenharmony_ci#define PA_CPU_PORT_L_ACCESS	4
958c2ecf20Sopenharmony_ci#define PA_CHANNEL_ATTENTION	8
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci#define OPT_SWAP_PORT	0x0001	/* Need to wordswp on the MPU port */
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#define SYSBUS      0x0000006c
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci/* big endian CPU, 82596 "big" endian mode */
1028c2ecf20Sopenharmony_ci#define SWAP32(x)   (((u32)(x)<<16) | ((((u32)(x)))>>16))
1038c2ecf20Sopenharmony_ci#define SWAP16(x)   (x)
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci#define NONCOHERENT_DMA 1
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#include "lib82596.c"
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ciMODULE_AUTHOR("Richard Hirst");
1108c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("i82596 driver");
1118c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
1128c2ecf20Sopenharmony_cimodule_param(i596_debug, int, 0);
1138c2ecf20Sopenharmony_ciMODULE_PARM_DESC(i596_debug, "lasi_82596 debug mask");
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_cistatic inline void ca(struct net_device *dev)
1168c2ecf20Sopenharmony_ci{
1178c2ecf20Sopenharmony_ci	gsc_writel(0, dev->base_addr + PA_CHANNEL_ATTENTION);
1188c2ecf20Sopenharmony_ci}
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_cistatic void mpu_port(struct net_device *dev, int c, dma_addr_t x)
1228c2ecf20Sopenharmony_ci{
1238c2ecf20Sopenharmony_ci	struct i596_private *lp = netdev_priv(dev);
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci	u32 v = (u32) (c) | (u32) (x);
1268c2ecf20Sopenharmony_ci	u16 a, b;
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci	if (lp->options & OPT_SWAP_PORT) {
1298c2ecf20Sopenharmony_ci		a = v >> 16;
1308c2ecf20Sopenharmony_ci		b = v & 0xffff;
1318c2ecf20Sopenharmony_ci	} else {
1328c2ecf20Sopenharmony_ci		a = v & 0xffff;
1338c2ecf20Sopenharmony_ci		b = v >> 16;
1348c2ecf20Sopenharmony_ci	}
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci	gsc_writel(a, dev->base_addr + PA_CPU_PORT_L_ACCESS);
1378c2ecf20Sopenharmony_ci	if (!running_on_qemu)
1388c2ecf20Sopenharmony_ci		udelay(1);
1398c2ecf20Sopenharmony_ci	gsc_writel(b, dev->base_addr + PA_CPU_PORT_L_ACCESS);
1408c2ecf20Sopenharmony_ci}
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci#define LAN_PROM_ADDR	0xF0810000
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_cistatic int __init
1458c2ecf20Sopenharmony_cilan_init_chip(struct parisc_device *dev)
1468c2ecf20Sopenharmony_ci{
1478c2ecf20Sopenharmony_ci	struct	net_device *netdevice;
1488c2ecf20Sopenharmony_ci	struct i596_private *lp;
1498c2ecf20Sopenharmony_ci	int retval = -ENOMEM;
1508c2ecf20Sopenharmony_ci	int i;
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci	if (!dev->irq) {
1538c2ecf20Sopenharmony_ci		printk(KERN_ERR "%s: IRQ not found for i82596 at 0x%lx\n",
1548c2ecf20Sopenharmony_ci			__FILE__, (unsigned long)dev->hpa.start);
1558c2ecf20Sopenharmony_ci		return -ENODEV;
1568c2ecf20Sopenharmony_ci	}
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci	printk(KERN_INFO "Found i82596 at 0x%lx, IRQ %d\n",
1598c2ecf20Sopenharmony_ci			(unsigned long)dev->hpa.start, dev->irq);
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci	netdevice = alloc_etherdev(sizeof(struct i596_private));
1628c2ecf20Sopenharmony_ci	if (!netdevice)
1638c2ecf20Sopenharmony_ci		return -ENOMEM;
1648c2ecf20Sopenharmony_ci	SET_NETDEV_DEV(netdevice, &dev->dev);
1658c2ecf20Sopenharmony_ci	parisc_set_drvdata (dev, netdevice);
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci	netdevice->base_addr = dev->hpa.start;
1688c2ecf20Sopenharmony_ci	netdevice->irq = dev->irq;
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci	if (pdc_lan_station_id(netdevice->dev_addr, netdevice->base_addr)) {
1718c2ecf20Sopenharmony_ci		for (i = 0; i < 6; i++) {
1728c2ecf20Sopenharmony_ci			netdevice->dev_addr[i] = gsc_readb(LAN_PROM_ADDR + i);
1738c2ecf20Sopenharmony_ci		}
1748c2ecf20Sopenharmony_ci		printk(KERN_INFO
1758c2ecf20Sopenharmony_ci		       "%s: MAC of HP700 LAN read from EEPROM\n", __FILE__);
1768c2ecf20Sopenharmony_ci	}
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	lp = netdev_priv(netdevice);
1798c2ecf20Sopenharmony_ci	lp->options = dev->id.sversion == 0x72 ? OPT_SWAP_PORT : 0;
1808c2ecf20Sopenharmony_ci	lp->dma = dma_alloc_noncoherent(&dev->dev,
1818c2ecf20Sopenharmony_ci			sizeof(struct i596_dma), &lp->dma_addr,
1828c2ecf20Sopenharmony_ci			DMA_BIDIRECTIONAL, GFP_KERNEL);
1838c2ecf20Sopenharmony_ci	if (!lp->dma)
1848c2ecf20Sopenharmony_ci		goto out_free_netdev;
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci	retval = i82596_probe(netdevice);
1878c2ecf20Sopenharmony_ci	if (retval)
1888c2ecf20Sopenharmony_ci		goto out_free_dma;
1898c2ecf20Sopenharmony_ci	return 0;
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ciout_free_dma:
1928c2ecf20Sopenharmony_ci	dma_free_noncoherent(&dev->dev, sizeof(struct i596_dma),
1938c2ecf20Sopenharmony_ci		       lp->dma, lp->dma_addr, DMA_BIDIRECTIONAL);
1948c2ecf20Sopenharmony_ciout_free_netdev:
1958c2ecf20Sopenharmony_ci	free_netdev(netdevice);
1968c2ecf20Sopenharmony_ci	return retval;
1978c2ecf20Sopenharmony_ci}
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_cistatic int __exit lan_remove_chip(struct parisc_device *pdev)
2008c2ecf20Sopenharmony_ci{
2018c2ecf20Sopenharmony_ci	struct net_device *dev = parisc_get_drvdata(pdev);
2028c2ecf20Sopenharmony_ci	struct i596_private *lp = netdev_priv(dev);
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci	unregister_netdev (dev);
2058c2ecf20Sopenharmony_ci	dma_free_noncoherent(&pdev->dev, sizeof(struct i596_private), lp->dma,
2068c2ecf20Sopenharmony_ci		       lp->dma_addr, DMA_BIDIRECTIONAL);
2078c2ecf20Sopenharmony_ci	free_netdev (dev);
2088c2ecf20Sopenharmony_ci	return 0;
2098c2ecf20Sopenharmony_ci}
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_cistatic const struct parisc_device_id lan_tbl[] __initconst = {
2128c2ecf20Sopenharmony_ci	{ HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0008a },
2138c2ecf20Sopenharmony_ci	{ HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00072 },
2148c2ecf20Sopenharmony_ci	{ 0, }
2158c2ecf20Sopenharmony_ci};
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(parisc, lan_tbl);
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_cistatic struct parisc_driver lan_driver __refdata = {
2208c2ecf20Sopenharmony_ci	.name		= "lasi_82596",
2218c2ecf20Sopenharmony_ci	.id_table	= lan_tbl,
2228c2ecf20Sopenharmony_ci	.probe		= lan_init_chip,
2238c2ecf20Sopenharmony_ci	.remove         = __exit_p(lan_remove_chip),
2248c2ecf20Sopenharmony_ci};
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_cistatic int lasi_82596_init(void)
2278c2ecf20Sopenharmony_ci{
2288c2ecf20Sopenharmony_ci	printk(KERN_INFO LASI_82596_DRIVER_VERSION "\n");
2298c2ecf20Sopenharmony_ci	return register_parisc_driver(&lan_driver);
2308c2ecf20Sopenharmony_ci}
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_cimodule_init(lasi_82596_init);
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_cistatic void __exit lasi_82596_exit(void)
2358c2ecf20Sopenharmony_ci{
2368c2ecf20Sopenharmony_ci	unregister_parisc_driver(&lan_driver);
2378c2ecf20Sopenharmony_ci}
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_cimodule_exit(lasi_82596_exit);
240