openblt

a hobby OS from the late 90s
git clone http://frotz.net/git/openblt.git
Log | Files | Refs | LICENSE

ne2k.h (3426B)


      1 /* $Id: //depot/blt/netboot/ne2k.h#2 $
      2 **
      3 ** Copyright 1998 Brian J. Swetland
      4 ** All rights reserved.
      5 **
      6 ** Redistribution and use in source and binary forms, with or without
      7 ** modification, are permitted provided that the following conditions
      8 ** are met:
      9 ** 1. Redistributions of source code must retain the above copyright
     10 **    notice, this list of conditions, and the following disclaimer.
     11 ** 2. Redistributions in binary form must reproduce the above copyright
     12 **    notice, this list of conditions, and the following disclaimer in the
     13 **    documentation and/or other materials provided with the distribution.
     14 ** 3. The name of the author may not be used to endorse or promote products
     15 **    derived from this software without specific prior written permission.
     16 **
     17 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28 #ifndef __NE2000_INTERFACE
     29 #define __NE2000_INTERFACE
     30 #ifndef __NE2000_SHARED_CODE_BASE
     31 typedef unsigned int uint;
     32 typedef struct snic snic;
     33 typedef struct nic_stat nic_stat;
     34 typedef struct buffer_header buffer_header;
     35 typedef struct packet_buffer packet_buffer;
     36 typedef struct nic_error_stat nic_error_stat;
     37 #endif /* NE2000_SHARED_CODE_BASE */
     38 
     39 #define LEN_ADDR		6
     40 #define MAX_TX			2	/* be careful with this (dual buffers) */
     41 #define MAX_PAGESPERPACKET	6
     42 #define TXPAGES			(MAX_TX*MAX_PAGESPERPACKET)
     43 #define LEN_PROM		16
     44 #define LEN_HEADER		14
     45 
     46 #ifdef __CPP_BINDING
     47 extern "C" {
     48 #endif
     49 
     50 /* external interface */
     51 int nic_detect(int given);
     52 int nic_init(snic* nic, int addr, unsigned char *prom, unsigned char *manual);
     53 void nic_register_notify(snic *nic, void (*newnotify)(packet_buffer *newpacket));
     54 void nic_start(snic *nic, int promiscuous);
     55 void nic_stop(snic *nic);
     56 void nic_isr(snic *nic);
     57 nic_stat nic_get_stats(snic *nic);
     58 void nic_stat_clear(nic_stat *that);
     59 int nic_send_packet(snic *nic, packet_buffer*);
     60 
     61 /* Your implementation */
     62 packet_buffer *alloc_buffer(uint size);
     63 void free_buffer(packet_buffer *ptr);
     64 
     65 #ifdef __CPP_BINDING
     66 };
     67 #endif
     68 
     69 struct buffer_header {
     70 	unsigned char status;
     71 	unsigned char next;
     72 	unsigned short count;	/* length of header and packet */
     73 };
     74 
     75 struct nic_error_stat {
     76 	long frame_alignment, crc, missed_packets;
     77 	long rx, rx_size, rx_dropped, rx_fifo, rx_overruns;
     78 	long tx_collisions;
     79 	long tx_aborts, tx_carrier, tx_fifo, tx_heartbeat, tx_window;
     80 };
     81 
     82 struct nic_stat {
     83 	long rx_packets;
     84 	long tx_buffered, tx_packets;
     85 	nic_error_stat errors;
     86 };
     87 
     88 struct packet_buffer {
     89 	uint len;
     90 	uint page;
     91 	unsigned char *ptr;
     92 };
     93 
     94 struct snic {
     95 	int iobase;	/* NULL if uninitialized */
     96 	int pstart, pstop, wordlength, current_page;
     97 	nic_stat stat;
     98 	void (*notify)(packet_buffer *newpacket);
     99 	packet_buffer tx_packet[MAX_TX], *last_tx;
    100 	char busy, send;
    101 };
    102 
    103 #endif	/* __NE2000_INTERFACE */