Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Release 1.0
[palacios.git] / geekos / include / geekos / ne2k.h
1 /*
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2008, Matt Wojcik
11  * Copyright (c) 2008, Peter Kamm
12  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
13  * All rights reserved.
14  *
15  * Author: Matt Wojcik
16  * Author: Peter Kamm
17  *
18  * This is free software.  You are permitted to use,
19  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
20  */
21
22 #ifndef GEEKOS_NE2K_H
23 #define GEEKOS_NE2K_H
24
25 #include <geekos/malloc.h>
26
27 #define NE2K_PAGE0      0x00
28 #define NE2K_PAGE1      0x40
29 #define NE2K_PAGE2      0x80
30 #define NE2K_PAGE3      0xc0
31
32 #define NE2K_BASE_ADDR  0xc100          /* Starting address of the card */
33 #define NE2K_CR         NE2K_BASE_ADDR  /* Command register */
34 #define NE2K_DATAPORT   (NE2K_CR + 0x10)
35 #define NE2K_RESET      (NE2K_CR + 0x1f)
36
37 /* Page 0 register offsets */
38 #define NE2K CLDA0      (NE2K_CR + 0x01)
39 #define NE2K_PSTART     (NE2K_CR + 0x01)        /* Page start register */
40 #define NE2K_CLDA1      (NE2K_CR + 0x02)
41 #define NE2K_PSTOP      (NE2K_CR + 0x02)        /* Page stop register */
42 #define NE2K_BNRY       (NE2K_CR + 0x03)        /* Boundary register */
43 #define NE2K_TSR        (NE2K_CR + 0x04)
44 #define NE2K_TPSR       (NE2K_CR + 0x04)
45 #define NE2K_NCR        (NE2K_CR + 0x05)
46 #define NE2K_TBCR0      (NE2K_CR + 0x05)
47 #define NE2K_FIFO       (NE2K_CR + 0x06)
48 #define NE2K_TBCR1      (NE2K_CR + 0x06)
49 #define NE2K_ISR        (NE2K_CR + 0x07)        /* Interrupt status register */
50 #define NE2K_CRDA0      (NE2K_CR + 0x08)
51 #define NE2K_RSAR0      (NE2K_CR + 0x08)        /* Remote start address registers */
52 #define NE2K_CRDA1      (NE2K_CR + 0x09)
53 #define NE2K_RSAR1      (NE2K_CR + 0x09)
54 #define NE2K_RBCR0      (NE2K_CR + 0x0a)        /* Remote byte count registers */
55 #define NE2K_RBCR1      (NE2K_CR + 0x0b)
56 #define NE2K_RSR        (NE2K_CR + 0x0c)
57 #define NE2K_RCR        (NE2K_CR + 0x0c)        /* Receive configuration register */
58 #define NE2K_CNTR0      (NE2K_CR + 0x0d)
59 #define NE2K_TCR        (NE2K_CR + 0x0d)        /* Transmit configuration register */
60 #define NE2K_CNTR1      (NE2K_CR + 0x0e)
61 #define NE2K_DCR        (NE2K_CR + 0x0e)        /* Data configuration register */
62 #define NE2K_CNTR2      (NE2K_CR + 0x0f)
63 #define NE2K_IMR        (NE2K_CR + 0x0f)        /* Interrupt mask register */
64
65 /* Page 1 register offsets */
66 #define NE2K_PAR0       (NE2K_CR + 0x01)
67 #define NE2K_PAR1       (NE2K_CR + 0x02)
68 #define NE2K_PAR2       (NE2K_CR + 0x03)
69 #define NE2K_PAR3       (NE2K_CR + 0x04)
70 #define NE2K_PAR4       (NE2K_CR + 0x05)
71 #define NE2K_PAR5       (NE2K_CR + 0x06)
72 #define NE2K_CURR       (NE2K_CR + 0x07)
73 #define NE2K_MAR0       (NE2K_CR + 0x08)
74 #define NE2K_MAR1       (NE2K_CR + 0x09)
75 #define NE2K_MAR2       (NE2K_CR + 0x0a)
76 #define NE2K_MAR3       (NE2K_CR + 0x0b)
77 #define NE2K_MAR4       (NE2K_CR + 0x0c)
78 #define NE2K_MAR5       (NE2K_CR + 0x0d)
79 #define NE2K_MAR6       (NE2K_CR + 0x0e)
80 #define NE2K_MAR7       (NE2K_CR + 0x0f)
81
82 #define NE2K_IRQ        11              /* Interrupt channel */
83
84
85 /* Physical Address of Network Card */
86 #define PHY_ADDR1 0x52
87 #define PHY_ADDR2 0x54
88 #define PHY_ADDR3 0x00
89 #define PHY_ADDR4 0x12
90 #define PHY_ADDR5 0x34
91 #define PHY_ADDR6 0x58
92
93
94 struct NE2K_REGS {
95         uchar_t cr;
96         uchar_t isr;
97         uchar_t imr;
98         uchar_t dcr;
99         uchar_t tcr;
100         uchar_t tsr;
101         uchar_t rcr;
102         uchar_t rsr;
103 };
104
105 struct _CR {  //COMMAND REG
106         uint_t stp: 1;  //STOP- software reset
107         uint_t sta: 1;  //START- activates NIC
108         uint_t txp: 1;  //TRANSMIT- set to send
109         uint_t rd:  3;  //REMOTE DMA
110         uint_t ps:  2;  //PAGE SELECT
111 }__attribute__((__packed__)) __attribute__((__aligned__(1)));
112
113 struct _ISR{  //INTERRUPT STATUS REG
114         uint_t prx: 1;  //PACKET RECIEVED
115         uint_t ptx: 1;  //PACKET TRANSMITTED
116         uint_t rxe: 1;  //TRANSMIT ERROR
117         uint_t txe: 1;  //RECEIVE ERROR
118         uint_t ovw: 1;  //OVERWRITE WARNING
119         uint_t cnt: 1;  //COUNTER OVERFLOW
120         uint_t rdc: 1;  //REMOTE DMA COMPLETE
121         uint_t rst: 1;  //RESET STATUS
122 }__attribute__((__packed__)) __attribute__((__aligned__(1)));
123
124 struct _IMR {  //INTERRUPT MASK REG
125         uint_t prxe: 1;  //PACKET RX INTRPT
126         uint_t ptxe: 1;  //PACKET TX INTRPT
127         uint_t rxee: 1;  //RX ERROR INTRPT
128         uint_t txee: 1;  //TX ERROR INTRPt
129         uint_t ovwe: 1;  //OVERWRITE WARNING INTRPT
130         uint_t cnte: 1;  //COUNTER OVERFLOW INTRPT
131         uint_t rdce: 1;  //DMA COMLETE INTRPT
132         uint_t rsvd: 1;
133 }__attribute__((__packed__)) __attribute__((__aligned__(1)));
134
135 struct _DCR {  //DATA CONFIG REGISTER
136         uint_t wts: 1;  //WORD TRANSFER SELECT
137         uint_t bos: 1;  //BYTE ORDER SELECT
138         uint_t las: 1;  //LONG ADDR SELECT
139         uint_t ls:  1;  //LOOPBACK SELECT
140         uint_t arm: 1;  //AUTO-INITIALIZE REMOTE
141         uint_t ft:  2;  //FIFO THRESH SELECT
142 }__attribute__((__packed__)) __attribute__((__aligned__(1)));
143
144 struct _TCR {  //TX CONFIG REGISTER
145         uint_t crc:  1;  //INHIBIT CRC
146         uint_t lb:   2;  //ENCODED LOOPBACK
147         uint_t atd:  1;  //AUTO TRANSMIT
148         uint_t ofst: 1;  //COLLISION OFFSET ENABLE
149         uint_t rsvd: 3;
150 }__attribute__((__packed__)) __attribute__((__aligned__(1)));
151
152 struct _TSR {
153         uint_t ptx:  1;  //PACKET TX
154         uint_t rsvd: 1;
155         uint_t col:  1;  //TX COLLIDED
156         uint_t abt:  1;  //TX ABORTED
157         uint_t crs:  1;  //CARRIER SENSE LOST
158         uint_t fu:   1;  //FIFO UNDERRUN
159         uint_t cdh:  1;  //CD HEARTBEAT
160         uint_t owc:  1;  //OUT OF WINDOW COLLISION
161 }__attribute__((__packed__)) __attribute__((__aligned__(1)));
162
163 struct _RCR {  //RECEIVE CONFIGURATION REGISTER
164         uint_t sep:  1;  //SAVE ERRORED PACKETS
165         uint_t ar:   1;  //ACCEPT RUNT PACKETS
166         uint_t ab:   1;  //ACCEPT BROADCAST
167         uint_t am:   1;  //ACCEPT MULTICAST
168         uint_t pro:  1;  //PROMISCUOUS PHYSICAL
169         uint_t mon:  1;  //MONITOR MODE
170         uint_t rsvd: 2;
171 }__attribute__((__packed__)) __attribute__((__aligned__(1)));
172   
173 struct _RSR {  //RECEIVE STATUS REG
174         uint_t prx: 1;  //PACKET RX INTACT
175         uint_t crc: 1;  //CRC ERROR
176         uint_t fae: 1;  //FRAME ALIGNMENT ERROR
177         uint_t fo:  1;  //FIFO OVERRUN
178         uint_t mpa: 1;  //MISSED PACKET
179         uint_t phy: 1;  //PHYSICAL/MULTICAST ADDR
180         uint_t dis: 1;  //RX DISABLED
181         uint_t dfr: 1;  //DEFERRING
182 }__attribute__((__packed__)) __attribute__((__aligned__(1)));
183
184 struct NE2K_Packet_Info {
185   uchar_t status;
186   uint_t size;
187   uchar_t src[6];
188   uchar_t dest[6];
189 };
190
191 int Init_Ne2k();
192 int NE2K_Receive();
193 int NE2K_Transmit(uint_t size);
194 int NE2K_Send_Packet(uchar_t *packet, uint_t size);
195 int NE2K_Send(uchar_t src[], uchar_t dest[], uint_t type, uchar_t *data, uint_t size);
196
197 #endif  /* GEEKOS_NE2K_H */