openblt

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

ne2k.h (4059B)


      1 /* $Id: //depot/blt/srv/ne2000/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_data packet_data;
     36 typedef struct packet_buffer packet_buffer;
     37 typedef struct nic_error_stat nic_error_stat;
     38 #endif /* NE2000_SHARED_CODE_BASE */
     39 
     40 #define LEN_ADDR		6
     41 #define MAX_TX			2	/* be careful with this (dual buffers) */
     42 #define MAX_PAGESPERPACKET	6
     43 #define TXPAGES			(MAX_TX*MAX_PAGESPERPACKET)
     44 #define LEN_PROM		16
     45 #define LEN_HEADER		14
     46 #define MIN_LENGTH              60      /* minimum length for packet data */
     47 #define MAX_LENGTH              1500    /* maximum length for packet data area */
     48 
     49 #ifdef __CPP_BINDING
     50 extern "C" {
     51 #endif
     52 
     53 /* external interface */
     54 int nic_detect(int given);
     55 int nic_init(snic* nic, int addr, unsigned char *prom, unsigned char *manual);
     56 void nic_register_notify(snic *nic, void(*newnotify)(void*,packet_data*),void*);
     57 void nic_start(snic *nic, int promiscuous);
     58 void nic_stop(snic *nic);
     59 void nic_isr(snic *nic);
     60 nic_stat nic_get_stats(snic *nic);
     61 void nic_stat_clear(nic_stat *that);
     62 int nic_send_packet(snic *nic, packet_buffer *buffer);
     63 
     64 /* Your implementation */
     65 /*packet_buffer *alloc_buffer(uint count); */     /* Optional */
     66 packet_data *alloc_buffer_data(uint size);
     67 void free_buffer(packet_buffer *ptr);
     68 void cleanup_buffer(packet_buffer *ptr);
     69 void free_buffer_data(packet_data *ptr); 	/* Optional */
     70 /* I reserve the right to use the "Option" procedures in the future */
     71 
     72 #ifdef __CPP_BINDING
     73 };
     74 #endif
     75 
     76 struct buffer_header {
     77 	unsigned char status;
     78 	unsigned char next;
     79 	unsigned short count;	/* length of header and packet */
     80 };
     81 
     82 struct nic_error_stat {
     83 	long frame_alignment, crc, missed_packets;
     84 	long rx, rx_size, rx_dropped, rx_fifo, rx_overruns;
     85 	long tx_collisions;
     86 	long tx_aborts, tx_carrier, tx_fifo, tx_heartbeat, tx_window;
     87 };
     88 
     89 struct nic_stat {
     90 	long rx_packets;
     91 	long tx_buffered, tx_packets;
     92 	nic_error_stat errors;
     93 };
     94 
     95 struct packet_buffer {
     96 	uint page;
     97 	uint count, len;
     98 	packet_data *buf;	/* An array of data segments */
     99 };
    100 
    101 struct packet_data {		/* each protocol layer can add it's own */
    102 	uint len;
    103 	char *ptr;
    104 };
    105 
    106 struct snic {
    107 	int iobase;	/* NULL if uninitialized */
    108 	int pstart, pstop, wordlength, current_page;
    109 	nic_stat stat;
    110 	void (*notify)(void *passback, packet_data *newpacket);
    111 	void *kore;	/* Passback pointer */
    112 	packet_buffer *tx_packet[MAX_TX], *last_tx;
    113 	int busy, send, sending;
    114 };
    115 
    116 #endif	/* __NE2000_INTERFACE */