source: mainline/uspace/drv/nic/ne2k/dp8390.h@ fb1007ef

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since fb1007ef was ea788701, checked in by Jiri Svoboda <jiri@…>, 13 years ago

Remove use of packet_t in NIC framework.

  • Property mode set to 100644
File size: 10.7 KB
Line 
1/*
2 * Copyright (c) 2009 Lukas Mejdrech
3 * Copyright (c) 2011 Martin Decky
4 * Copyright (c) 2011 Radim Vansa
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * - The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/*
32 * This code is based upon the NE2000 driver for MINIX,
33 * distributed according to a BSD-style license.
34 *
35 * Copyright (c) 1987, 1997, 2006 Vrije Universiteit
36 * Copyright (c) 1992, 1994 Philip Homburg
37 * Copyright (c) 1996 G. Falzoni
38 *
39 */
40
41/** @addtogroup drv_ne2k
42 * @{
43 */
44
45/** @file
46 * DP8390 network interface definitions.
47 */
48
49#ifndef __NET_NETIF_DP8390_H__
50#define __NET_NETIF_DP8390_H__
51
52#include <fibril_synch.h>
53#include <nic.h>
54#include <ddf/interrupt.h>
55
56/** Input/output size */
57#define NE2K_IO_SIZE 0x0020
58
59/* NE2000 implementation. */
60
61/** NE2000 Data Register */
62#define NE2K_DATA 0x0010
63
64/** NE2000 Reset register */
65#define NE2K_RESET 0x001f
66
67/** NE2000 data start */
68#define NE2K_START 0x4000
69
70/** NE2000 data size */
71#define NE2K_SIZE 0x4000
72
73/** NE2000 retry count */
74#define NE2K_RETRY 0x1000
75
76/** NE2000 error messages rate limiting */
77#define NE2K_ERL 10
78
79/** Minimum Ethernet packet size in bytes */
80#define ETH_MIN_PACK_SIZE 60
81
82/** Maximum Ethernet packet size in bytes */
83#define ETH_MAX_PACK_SIZE_TAGGED 1518
84
85/* National Semiconductor DP8390 Network Interface Controller. */
86
87/** Page 0, for reading */
88#define DP_CR 0x00 /**< Command Register */
89#define DP_CLDA0 0x01 /**< Current Local DMA Address 0 */
90#define DP_CLDA1 0x02 /**< Current Local DMA Address 1 */
91#define DP_BNRY 0x03 /**< Boundary Pointer */
92#define DP_TSR 0x04 /**< Transmit Status Register */
93#define DP_NCR 0x05 /**< Number of Collisions Register */
94#define DP_FIFO 0x06 /**< FIFO */
95#define DP_ISR 0x07 /**< Interrupt Status Register */
96#define DP_CRDA0 0x08 /**< Current Remote DMA Address 0 */
97#define DP_CRDA1 0x09 /**< Current Remote DMA Address 1 */
98#define DP_RSR 0x0c /**< Receive Status Register */
99#define DP_CNTR0 0x0d /**< Tally Counter 0 */
100#define DP_CNTR1 0x0e /**< Tally Counter 1 */
101#define DP_CNTR2 0x0f /**< Tally Counter 2 */
102
103/** Page 0, for writing */
104#define DP_PSTART 0x01 /**< Page Start Register*/
105#define DP_PSTOP 0x02 /**< Page Stop Register */
106#define DP_TPSR 0x04 /**< Transmit Page Start Register */
107#define DP_TBCR0 0x05 /**< Transmit Byte Count Register 0 */
108#define DP_TBCR1 0x06 /**< Transmit Byte Count Register 1 */
109#define DP_RSAR0 0x08 /**< Remote Start Address Register 0 */
110#define DP_RSAR1 0x09 /**< Remote Start Address Register 1 */
111#define DP_RBCR0 0x0a /**< Remote Byte Count Register 0 */
112#define DP_RBCR1 0x0b /**< Remote Byte Count Register 1 */
113#define DP_RCR 0x0c /**< Receive Configuration Register */
114#define DP_TCR 0x0d /**< Transmit Configuration Register */
115#define DP_DCR 0x0e /**< Data Configuration Register */
116#define DP_IMR 0x0f /**< Interrupt Mask Register */
117
118/** Page 1, read/write */
119#define DP_PAR0 0x01 /**< Physical Address Register 0 */
120#define DP_PAR1 0x02 /**< Physical Address Register 1 */
121#define DP_PAR2 0x03 /**< Physical Address Register 2 */
122#define DP_PAR3 0x04 /**< Physical Address Register 3 */
123#define DP_PAR4 0x05 /**< Physical Address Register 4 */
124#define DP_PAR5 0x06 /**< Physical Address Register 5 */
125#define DP_CURR 0x07 /**< Current Page Register */
126#define DP_MAR0 0x08 /**< Multicast Address Register 0 */
127#define DP_MAR1 0x09 /**< Multicast Address Register 1 */
128#define DP_MAR2 0x0a /**< Multicast Address Register 2 */
129#define DP_MAR3 0x0b /**< Multicast Address Register 3 */
130#define DP_MAR4 0x0c /**< Multicast Address Register 4 */
131#define DP_MAR5 0x0d /**< Multicast Address Register 5 */
132#define DP_MAR6 0x0e /**< Multicast Address Register 6 */
133#define DP_MAR7 0x0f /**< Multicast Address Register 7 */
134
135/* Bits in Command Register */
136#define CR_STP 0x01 /**< Stop (software reset) */
137#define CR_STA 0x02 /**< Start (activate NIC) */
138#define CR_TXP 0x04 /**< Transmit Packet */
139#define CR_DMA 0x38 /**< Mask for DMA control */
140#define CR_DM_NOP 0x00 /**< DMA: No Operation */
141#define CR_DM_RR 0x08 /**< DMA: Remote Read */
142#define CR_DM_RW 0x10 /**< DMA: Remote Write */
143#define CR_DM_SP 0x18 /**< DMA: Send Packet */
144#define CR_DM_ABORT 0x20 /**< DMA: Abort Remote DMA Operation */
145#define CR_PS 0xc0 /**< Mask for Page Select */
146#define CR_PS_P0 0x00 /**< Register Page 0 */
147#define CR_PS_P1 0x40 /**< Register Page 1 */
148#define CR_PS_P2 0x80 /**< Register Page 2 */
149#define CR_PS_T1 0xc0 /**< Test Mode Register Map */
150
151/* Bits in Interrupt State Register */
152#define ISR_PRX 0x01 /**< Packet Received with no errors */
153#define ISR_PTX 0x02 /**< Packet Transmitted with no errors */
154#define ISR_RXE 0x04 /**< Receive Error */
155#define ISR_TXE 0x08 /**< Transmit Error */
156#define ISR_OVW 0x10 /**< Overwrite Warning */
157#define ISR_CNT 0x20 /**< Counter Overflow */
158#define ISR_RDC 0x40 /**< Remote DMA Complete */
159#define ISR_RST 0x80 /**< Reset Status */
160
161/* Bits in Interrupt Mask Register */
162#define IMR_PRXE 0x01 /**< Packet Received Interrupt Enable */
163#define IMR_PTXE 0x02 /**< Packet Transmitted Interrupt Enable */
164#define IMR_RXEE 0x04 /**< Receive Error Interrupt Enable */
165#define IMR_TXEE 0x08 /**< Transmit Error Interrupt Enable */
166#define IMR_OVWE 0x10 /**< Overwrite Warning Interrupt Enable */
167#define IMR_CNTE 0x20 /**< Counter Overflow Interrupt Enable */
168#define IMR_RDCE 0x40 /**< DMA Complete Interrupt Enable */
169
170/* Bits in Data Configuration Register */
171#define DCR_WTS 0x01 /**< Word Transfer Select */
172#define DCR_BYTEWIDE 0x00 /**< WTS: byte wide transfers */
173#define DCR_WORDWIDE 0x01 /**< WTS: word wide transfers */
174#define DCR_BOS 0x02 /**< Byte Order Select */
175#define DCR_LTLENDIAN 0x00 /**< BOS: Little Endian */
176#define DCR_BIGENDIAN 0x02 /**< BOS: Big Endian */
177#define DCR_LAS 0x04 /**< Long Address Select */
178#define DCR_BMS 0x08 /**< Burst Mode Select */
179#define DCR_AR 0x10 /**< Autoinitialize Remote */
180#define DCR_FTS 0x60 /**< Fifo Threshold Select */
181#define DCR_2BYTES 0x00 /**< 2 bytes */
182#define DCR_4BYTES 0x40 /**< 4 bytes */
183#define DCR_8BYTES 0x20 /**< 8 bytes */
184#define DCR_12BYTES 0x60 /**< 12 bytes */
185
186/* Bits in Transmit Configuration Register */
187#define TCR_CRC 0x01 /**< Inhibit CRC */
188#define TCR_ELC 0x06 /**< Encoded Loopback Control */
189#define TCR_NORMAL 0x00 /**< ELC: Normal Operation */
190#define TCR_INTERNAL 0x02 /**< ELC: Internal Loopback */
191#define TCR_0EXTERNAL 0x04 /**< ELC: External Loopback LPBK=0 */
192#define TCR_1EXTERNAL 0x06 /**< ELC: External Loopback LPBK=1 */
193#define TCR_ATD 0x08 /**< Auto Transmit Disable */
194#define TCR_OFST 0x10 /**< Collision Offset Enable (be nice) */
195
196/* Bits in Interrupt Status Register */
197#define TSR_PTX 0x01 /**< Packet Transmitted (without error) */
198#define TSR_DFR 0x02 /**< Transmit Deferred (reserved) */
199#define TSR_COL 0x04 /**< Transmit Collided */
200#define TSR_ABT 0x08 /**< Transmit Aborted */
201#define TSR_CRS 0x10 /**< Carrier Sense Lost */
202#define TSR_FU 0x20 /**< FIFO Underrun */
203#define TSR_CDH 0x40 /**< CD Heartbeat */
204#define TSR_OWC 0x80 /**< Out of Window Collision */
205
206/* Bits in Receive Configuration Register */
207#define RCR_SEP 0x01 /**< Save Errored Packets */
208#define RCR_AR 0x02 /**< Accept Runt Packets */
209#define RCR_AB 0x04 /**< Accept Broadcast */
210#define RCR_AM 0x08 /**< Accept Multicast */
211#define RCR_PRO 0x10 /**< Physical Promiscuous */
212#define RCR_MON 0x20 /**< Monitor Mode */
213
214/* Bits in Receive Status Register */
215#define RSR_PRX 0x01 /**< Packet Received Intact */
216#define RSR_CRC 0x02 /**< CRC Error */
217#define RSR_FAE 0x04 /**< Frame Alignment Error */
218#define RSR_FO 0x08 /**< FIFO Overrun */
219#define RSR_MPA 0x10 /**< Missed Packet */
220#define RSR_PHY 0x20 /**< Multicast Address Match */
221#define RSR_DIS 0x40 /**< Receiver Disabled */
222#define RSR_DFR 0x80 /**< In later manuals: Deferring */
223
224typedef struct {
225 /* Device configuration */
226 void *base_port; /**< Port assigned from ISA configuration **/
227 void *port;
228 void *data_port;
229 int irq;
230 nic_address_t mac;
231
232 uint8_t start_page; /**< Ring buffer start page */
233 uint8_t stop_page; /**< Ring buffer stop page */
234
235 /* Send queue */
236 struct {
237 bool dirty; /**< Buffer contains a packet */
238 size_t size; /**< Packet size */
239 uint8_t page; /**< Starting page of the buffer */
240 } sq;
241 fibril_mutex_t sq_mutex;
242 fibril_condvar_t sq_cv;
243
244 /* Driver run-time variables */
245 bool probed;
246 bool up;
247
248 /* Irq code with assigned addresses for this device */
249 irq_code_t code;
250
251 /* Copy of the receive configuration register */
252 uint8_t receive_configuration;
253
254 /* Device statistics */
255 // TODO: shouldn't be these directly in device.h - nic_device_stats?
256 uint64_t misses; /**< Receive frame misses */
257 uint64_t underruns; /**< FIFO underruns */
258 uint64_t overruns; /**< FIFO overruns */
259} ne2k_t;
260
261extern int ne2k_probe(ne2k_t *);
262extern int ne2k_up(ne2k_t *);
263extern void ne2k_down(ne2k_t *);
264extern void ne2k_send(nic_t *, void *, size_t);
265extern void ne2k_interrupt(nic_t *, uint8_t, uint8_t);
266
267extern void ne2k_set_accept_mcast(ne2k_t *, int);
268extern void ne2k_set_accept_bcast(ne2k_t *, int);
269extern void ne2k_set_promisc_phys(ne2k_t *, int);
270extern void ne2k_set_mcast_hash(ne2k_t *, uint64_t);
271extern void ne2k_set_physical_address(ne2k_t *, const nic_address_t *address);
272
273#endif
274
275/** @}
276 */
Note: See TracBrowser for help on using the repository browser.