📄 sk_g16.c
字号:
/**************************************************************************Etherboot - BOOTP/TFTP Bootstrap ProgramSchneider & Koch G16 NIC driver for Etherbootheavily based on SK G16 driver from Linux 2.0.36Changes to make it work with Etherboot by Georg Baum <Georg.Baum@gmx.de>***************************************************************************//*- * Copyright (C) 1994 by PJD Weichmann & SWS Bern, Switzerland * * This software may be used and distributed according to the terms * of the GNU Public License, incorporated herein by reference. * * Module : sk_g16.c * * Version : $Revision: 1.4 $ * * Author : Patrick J.D. Weichmann * * Date Created : 94/05/26 * Last Updated : $Date: 2002/01/02 21:56:40 $ * * Description : Schneider & Koch G16 Ethernet Device Driver for * Linux Kernel >= 1.1.22 * Update History : *-*//* * The Schneider & Koch (SK) G16 Network device driver is based * on the 'ni6510' driver from Michael Hipp which can be found at * ftp://sunsite.unc.edu/pub/Linux/system/Network/drivers/nidrivers.tar.gz * * Sources: 1) ni6510.c by M. Hipp * 2) depca.c by D.C. Davies * 3) skeleton.c by D. Becker * 4) Am7990 Local Area Network Controller for Ethernet (LANCE), * AMD, Pub. #05698, June 1989 * * Many Thanks for helping me to get things working to: * * A. Cox (A.Cox@swansea.ac.uk) * M. Hipp (mhipp@student.uni-tuebingen.de) * R. Bolz (Schneider & Koch, Germany) * * See README.sk_g16 for details about limitations and bugs for the * current version. * * To Do: * - Support of SK_G8 and other SK Network Cards. * - Autoset memory mapped RAM. Check for free memory and then * configure RAM correctly. * - SK_close should really set card in to initial state. * - Test if IRQ 3 is not switched off. Use autoirq() functionality. * (as in /drivers/net/skeleton.c) * - Implement Multicast addressing. At minimum something like * in depca.c. * - Redo the statistics part. * - Try to find out if the board is in 8 Bit or 16 Bit slot. * If in 8 Bit mode don't use IRQ 11. * - (Try to make it slightly faster.) *//* to get some global routines like printf */#include "etherboot.h"/* to get the interface to the body of the program */#include "nic.h"/* From linux/if_ether.h: */#define ETH_ZLEN 60 /* Min. octets in frame sans FCS */#include "sk_g16.h"/* * Schneider & Koch Card Definitions * ================================= */#define SK_NAME "SK_G16"/* * SK_G16 Configuration * -------------------- *//* * Abbreviations * ------------- * * RAM - used for the 16KB shared memory * Boot_ROM, ROM - are used for referencing the BootEPROM * * SK_ADDR is a symbolic constant used to configure * the behaviour of the driver and the SK_G16. * * SK_ADDR defines the address where the RAM will be mapped into the real * host memory. * valid addresses are from 0xa0000 to 0xfc000 in 16Kbyte steps. */#define SK_ADDR 0xcc000/* * In POS3 are bits A14-A19 of the address bus. These bits can be set * to choose the RAM address. That's why we only can choose the RAM address * in 16KB steps. */#define POS_ADDR (rom_addr>>14) /* Do not change this line *//* * SK_G16 I/O PORT's + IRQ's + Boot_ROM locations * ---------------------------------------------- *//* * As nearly every card has also SK_G16 a specified I/O Port region and * only a few possible IRQ's. * In the Installation Guide from Schneider & Koch is listed a possible * Interrupt IRQ2. IRQ2 is always IRQ9 in boards with two cascaded interrupt * controllers. So we use in SK_IRQS IRQ9. *//* Don't touch any of the following #defines. */#define SK_IO_PORTS { 0x100, 0x180, 0x208, 0x220, 0x288, 0x320, 0x328, 0x390, 0 }/* * SK_G16 POS REGISTERS * -------------------- *//* * SK_G16 has a Programmable Option Select (POS) Register. * The POS is composed of 8 separate registers (POS0-7) which * are I/O mapped on an address set by the W1 switch. * */#define SK_POS_SIZE 8 /* 8 I/O Ports are used by SK_G16 */#define SK_POS0 ioaddr /* Card-ID Low (R) */#define SK_POS1 ioaddr+1 /* Card-ID High (R) */#define SK_POS2 ioaddr+2 /* Card-Enable, Boot-ROM Disable (RW) */#define SK_POS3 ioaddr+3 /* Base address of RAM */#define SK_POS4 ioaddr+4 /* IRQ *//* POS5 - POS7 are unused *//* * SK_G16 MAC PREFIX * ----------------- *//* * Scheider & Koch manufacturer code (00:00:a5). * This must be checked, that we are sure it is a SK card. */#define SK_MAC0 0x00#define SK_MAC1 0x00#define SK_MAC2 0x5a/* * SK_G16 ID * --------- *//* * If POS0,POS1 contain the following ID, then we know * at which I/O Port Address we are. */#define SK_IDLOW 0xfd#define SK_IDHIGH 0x6a/* * LANCE POS Bit definitions * ------------------------- */#define SK_ROM_RAM_ON (POS2_CARD)#define SK_ROM_RAM_OFF (POS2_EPROM)#define SK_ROM_ON (inb(SK_POS2) & POS2_CARD)#define SK_ROM_OFF (inb(SK_POS2) | POS2_EPROM)#define SK_RAM_ON (inb(SK_POS2) | POS2_CARD)#define SK_RAM_OFF (inb(SK_POS2) & POS2_EPROM)#define POS2_CARD 0x0001 /* 1 = SK_G16 on 0 = off */#define POS2_EPROM 0x0002 /* 1 = Boot EPROM off 0 = on *//* * SK_G16 Memory mapped Registers * ------------------------------ * */#define SK_IOREG (board->ioreg) /* LANCE data registers. */#define SK_PORT (board->port) /* Control, Status register */#define SK_IOCOM (board->iocom) /* I/O Command *//* * SK_G16 Status/Control Register bits * ----------------------------------- * * (C) Controlreg (S) Statusreg *//* * Register transfer: 0 = no transfer * 1 = transferring data between LANCE and I/O reg */#define SK_IORUN 0x20/* * LANCE interrupt: 0 = LANCE interrupt occurred * 1 = no LANCE interrupt occurred */#define SK_IRQ 0x10#define SK_RESET 0x08 /* Reset SK_CARD: 0 = RESET 1 = normal */#define SK_RW 0x02 /* 0 = write to 1 = read from */#define SK_ADR 0x01 /* 0 = REG DataPort 1 = RAP Reg addr port */#define SK_RREG SK_RW /* Transferdirection to read from lance */#define SK_WREG 0 /* Transferdirection to write to lance */#define SK_RAP SK_ADR /* Destination Register RAP */#define SK_RDATA 0 /* Destination Register REG DataPort *//* * SK_G16 I/O Command * ------------------ *//* * Any bitcombination sets the internal I/O bit (transfer will start) * when written to I/O Command */#define SK_DOIO 0x80 /* Do Transfer *//* * LANCE RAP (Register Address Port). * --------------------------------- *//* * The LANCE internal registers are selected through the RAP. * The Registers are: * * CSR0 - Status and Control flags * CSR1 - Low order bits of initialize block (bits 15:00) * CSR2 - High order bits of initialize block (bits 07:00, 15:08 are reserved) * CSR3 - Allows redefinition of the Bus Master Interface. * This register must be set to 0x0002, which means BSWAP = 0, * ACON = 1, BCON = 0; * */#define CSR0 0x00#define CSR1 0x01#define CSR2 0x02#define CSR3 0x03/* * General Definitions * =================== *//* * Set the number of Tx and Rx buffers, using Log_2(# buffers). * We have 16KB RAM which can be accessed by the LANCE. In the * memory are not only the buffers but also the ring descriptors and * the initialize block. * Don't change anything unless you really know what you do. */#define LC_LOG_TX_BUFFERS 1 /* (2 == 2^^1) 2 Transmit buffers */#define LC_LOG_RX_BUFFERS 2 /* (8 == 2^^3) 8 Receive buffers *//* Descriptor ring sizes */#define TMDNUM (1 << (LC_LOG_TX_BUFFERS)) /* 2 Transmit descriptor rings */#define RMDNUM (1 << (LC_LOG_RX_BUFFERS)) /* 8 Receive Buffers *//* Define Mask for setting RMD, TMD length in the LANCE init_block */#define TMDNUMMASK (LC_LOG_TX_BUFFERS << 29)#define RMDNUMMASK (LC_LOG_RX_BUFFERS << 29)/* * Data Buffer size is set to maximum packet length. */#define PKT_BUF_SZ 1518/* * The number of low I/O ports used by the ethercard. */#define ETHERCARD_TOTAL_SIZE SK_POS_SIZE/* * Portreserve is there to mark the Card I/O Port region as used. * Check_region is to check if the region at ioaddr with the size "size" * is free or not. * Snarf_region allocates the I/O Port region. */#ifndef HAVE_PORTRESERVE#define check_region(ioaddr1, size) 0#define request_region(ioaddr1, size,name) do ; while (0)#endif/* * SK_DEBUG * * Here you can choose what level of debugging wanted. * * If SK_DEBUG and SK_DEBUG2 are undefined, then only the * necessary messages will be printed. * * If SK_DEBUG is defined, there will be many debugging prints * which can help to find some mistakes in configuration or even * in the driver code. * * If SK_DEBUG2 is defined, many many messages will be printed * which normally you don't need. I used this to check the interrupt * routine. * * (If you define only SK_DEBUG2 then only the messages for * checking interrupts will be printed!) * * Normal way of live is: * * For the whole thing get going let both symbolic constants * undefined. If you face any problems and you know what's going * on (you know something about the card and you can interpret some * hex LANCE register output) then define SK_DEBUG * */#undef SK_DEBUG /* debugging */#undef SK_DEBUG2 /* debugging with more verbose report */#ifdef SK_DEBUG#define PRINTF(x) printf x#else#define PRINTF(x) /**/#endif#ifdef SK_DEBUG2#define PRINTF2(x) printf x#else#define PRINTF2(x) /**/#endif/* * SK_G16 RAM * * The components are memory mapped and can be set in a region from * 0x00000 through 0xfc000 in 16KB steps. * * The Network components are: dual ported RAM, Prom, I/O Reg, Status-, * Controlregister and I/O Command. * * dual ported RAM: This is the only memory region which the LANCE chip * has access to. From the Lance it is addressed from 0x0000 to * 0x3fbf. The host accesses it normally. * * PROM: The PROM obtains the ETHERNET-MAC-Address. It is realised as a * 8-Bit PROM, this means only the 16 even addresses are used of the * 32 Byte Address region. Access to a odd address results in invalid * data. * * LANCE I/O Reg: The I/O Reg is build of 4 single Registers, Low-Byte Write, * Hi-Byte Write, Low-Byte Read, Hi-Byte Read. * Transfer from or to the LANCE is always in 16Bit so Low and High * registers are always relevant. * * The Data from the Readregister is not the data in the Writeregister!! * * Port: Status- and Controlregister.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -