UbixOS  2.0
lnc.h
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2002-2018 The UbixOS Project.
3  * All rights reserved.
4  *
5  * This was developed by Christopher W. Olsen for the UbixOS Project.
6  *
7  * Redistribution and use in source and binary forms, with or without modification, are permitted
8  * provided that the following conditions are met:
9  *
10  * 1) Redistributions of source code must retain the above copyright notice, this list of
11  * conditions, the following disclaimer and the list of authors.
12  * 2) Redistributions in binary form must reproduce the above copyright notice, this list of
13  * conditions, the following disclaimer and the list of authors in the documentation and/or
14  * other materials provided with the distribution.
15  * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to
16  * endorse or promote products derived from this software without specific prior written
17  * permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
20  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef _PCI_LNC_H
30 #define _PCI_LNC_H
31 
32 #include <sys/types.h>
33 
34 // TEMP COMMENT FRESH
35 #define RDP 0x10 // Register Data Port 16Bit
36 #define RDP32 0x10 // Register Data Port 32Bit
37 #define RAP 0x12 // Register Address Port 16Bit
38 #define RAP32 0x14 // Register Address Port 32Bit
39 #define RESET 0x14 // Reset Port 16Bit
40 #define RESET32 0x18 // Reset Port 32Bit
41 #define BDP 0x16 // 16Bit
42 #define BDP32 0x1C // 32Bit
43 
44 // BCR18
45 #define BCR18 18
46 #define BCR18_DWIO 0x0080
47 
48 // BCR20
49 #define BCR20 0x0014
50 
51 // Modes
52 #define MODE_16 0
53 #define MODE_32 1
54 #define MODE_INVALID 3
55 
56 // CSR0
57 #define CSR0 0x0000
58 #define CSR0_STOP 0x0004
59 
60 // CSR15
61 #define CSR15 15
62 #define CSR15_DXMTFCS 0x0008
63 #define CSR15_DRTY 0x0020
64 #define CSR15_PROM 0x8000
65 
66 // CSR58
67 #define CSR58 0x003A
68 
69 struct mds {
72  short md2;
74 };
75 
77  struct mds *md;
78  union {
79  //struct mbuf *mbuf;
80  char *data;
81  } buff;
82 };
83 
84 struct hostRingEntry {
87  uint8_t md[6];
89 };
90 
91 struct arpcom {
92  //struct ifnet ac_if; /* network-visible interface */
93  uint8_t ac_enaddr[6]; /* ethernet hardware address */
94  int ac_multicnt; /* length of ac_multiaddrs list */
95  void *ac_netgraph; /* ng_ether(4) netgraph node info */
96 };
97 
98 struct nicInfo {
99  int ident; /* Type of card */
100  int ic; /* Type of ic, Am7990, Am79C960 etc. */
101  int memMode;
102  int iobase;
103  int mode; /* Mode setting at initialization */
104 };
105 
106 struct initBlock16 {
107  uint16_t mode; // Mode register
108  uint8_t padr[6]; // Ethernet address
109  uint8_t ladrf[8]; // Logical address filter (multicast)
110  uint16_t rdra; // Low order pointer to receive ring
111  uint16_t rlen; // High order pointer and no. rings
112  uint16_t tdra; // Low order pointer to transmit ring
113  uint16_t tlen; // High order pointer and no rings
114 };
115 
116 struct initBlock32 {
125 };
126 
127 struct lncInfo {
128  struct arpcom arpcom;
129  struct nicInfo nic;
131  char *rxBuffer;
133  char *txBuffer;
135  unsigned int ioAddr;
136  int nrdre;
137  int ntdre;
139  int txPtr;
140  int rxPtr;
141 };
142 
143 /* Functions */
144 void lnc_writeCSR(struct lncInfo *, uint16_t, uint16_t);
145 void lnc_writeCSR32(struct lncInfo *, uint32_t, uint32_t);
146 
149 
150 void lnc_writeBCR(struct lncInfo *, uint16_t, uint16_t);
151 void lnc_writeBCR32(struct lncInfo *, uint32_t, uint32_t);
152 
155 
156 void lnc_reset(struct lncInfo *);
157 void lnc_reset32(struct lncInfo *);
158 
159 int lnc_probe(struct lncInfo *);
160 
161 int lnc_switchDWord(struct lncInfo *);
162 
163 int lnc_getMode(struct lncInfo *);
164 
165 void lnc_isr();
166 int lnc_driverOwnsRX(struct lncInfo *);
167 int lnc_driverOwnsRX(struct lncInfo *);
168 
169 void lnc_INT();
170 void lnc_rxINT();
171 void lnc_txINT();
172 
173 // OLD
174 
175 #define NDESC(len2) (1 << len2)
176 #define NORMAL 0
177 #define MEM_SLEW 8
178 #define TRANSBUFSIZE 1518
179 #define RECVBUFSIZE 1518
180 #define NRDRE 3
181 #define NTDRE 3
182 #define ETHER_ADDR_LEN 6
183 #define NE2100_IOSIZE 24
184 
185 #define PCNET_VSW 0x18
186 #define NE2100 2
187 
188 /* mem_mode values */
189 #define DMA_FIXED 1
190 #define DMA_MBUF 2
191 #define SHMEM 4
192 
193 /********** Chip Types **********/
194 #define UNKNOWN 0 /* Unknown */
195 #define LANCE 1 /* Am7990 */
196 #define C_LANCE 2 /* Am79C90 */
197 #define PCnet_ISA 3 /* Am79C960 */
198 #define PCnet_ISAplus 4 /* Am79C961 */
199 #define PCnet_ISA_II 5 /* Am79C961A */
200 #define PCnet_32 6 /* Am79C965 */
201 #define PCnet_PCI 7 /* Am79C970 */
202 #define PCnet_PCI_II 8 /* Am79C970A */
203 #define PCnet_FAST 9 /* Am79C971 */
204 #define PCnet_FASTplus 10 /* Am79C972 */
205 #define PCnet_Home 11 /* Am79C978 */
206 
207 /******** AM7990 Specifics **************/
208 #define CSR1 1
209 #define CSR2 2
210 #define CSR3 3
211 #define CSR88 88
212 #define CSR89 89
213 
214 #define ERR 0x8000
215 #define BABL 0x4000
216 #define CERR 0x2000
217 #define MISS 0x1000
218 #define MERR 0x0800
219 #define RINT 0x0400
220 #define TINT 0x0200
221 #define IDON 0x0100
222 #define INTR 0x0080
223 #define INEA 0x0040
224 #define RXON 0x0020
225 #define TXON 0x0010
226 #define TDMD 0x0008
227 
228 #define STRT 0x0002
229 #define INIT 0x0001
230 
231 /* CSR88-89: Chip ID masks */
232 #define AMD_MASK 0x003
233 #define PART_MASK 0xffff
234 #define Am79C960 0x0003
235 #define Am79C961 0x2260
236 #define Am79C961A 0x2261
237 #define Am79C965 0x2430
238 #define Am79C970 0x0242
239 #define Am79C970A 0x2621
240 #define Am79C971 0x2623
241 #define Am79C972 0x2624
242 #define Am79C973 0x2625
243 #define Am79C978 0x2626
244 
245 extern struct lncInfo *lnc;
246 
247 int initLNC();
248 int probe(struct lncInfo *lnc);
249 int lanceProbe(struct lncInfo *lnc);
250 int lncAttach(struct lncInfo *lnc, int unit);
251 
252 void lncInt();
253 void _lncInt();
254 
255 int lnc_sendPacket(struct lncInfo *lnc, void *packet, size_t len, uInt8 *dest);
256 
257 #endif
nicInfo
Definition: lnc.h:98
lncInfo::txRing
struct hostRingEntry * txRing
Definition: lnc.h:132
lncInfo::rxRing
struct hostRingEntry * rxRing
Definition: lnc.h:130
initBlock16::rdra
uint16_t rdra
Definition: lnc.h:110
hostRingEntry_old::data
char * data
Definition: lnc.h:80
initBlock32::ladrf
uint8_t ladrf[8]
Definition: lnc.h:122
initBlock16::rlen
uint16_t rlen
Definition: lnc.h:111
mds::md2
short md2
Definition: lnc.h:72
lnc_sendPacket
int lnc_sendPacket(struct lncInfo *lnc, void *packet, size_t len, uInt8 *dest)
Definition: lnc.c:546
initBlock16::padr
uint8_t padr[6]
Definition: lnc.h:108
arpcom::ac_netgraph
void * ac_netgraph
Definition: lnc.h:95
lnc_reset
void lnc_reset(struct lncInfo *)
Definition: lnc.c:585
arpcom::ac_multicnt
int ac_multicnt
Definition: lnc.h:94
nicInfo::iobase
int iobase
Definition: lnc.h:102
lnc_reset32
void lnc_reset32(struct lncInfo *)
Definition: lnc.c:589
mds::md1
uint16_t md1
Definition: lnc.h:71
initBlock16
Definition: lnc.h:106
hostRingEntry_old::buff
union hostRingEntry_old::@8 buff
nicInfo::ic
int ic
Definition: lnc.h:100
hostRingEntry::bcnt
uint16_t bcnt
Definition: lnc.h:86
lncInfo::init
struct initBlock32 init
Definition: lnc.h:134
lncInfo
Definition: lnc.h:127
nicInfo::ident
int ident
Definition: lnc.h:99
initBlock16::tdra
uint16_t tdra
Definition: lnc.h:112
types.h
initBlock32::mode
uint16_t mode
Definition: lnc.h:117
lnc_driverOwnsRX
int lnc_driverOwnsRX(struct lncInfo *)
Definition: lnc.c:518
lnc_isr
void lnc_isr()
lncInfo::rxBuffer
char * rxBuffer
Definition: lnc.h:131
uint16_t
__uint16_t uint16_t
Definition: types.h:45
lncInfo::nrdre
int nrdre
Definition: lnc.h:136
nicInfo::memMode
int memMode
Definition: lnc.h:101
lnc_switchDWord
int lnc_switchDWord(struct lncInfo *)
Definition: lnc.c:593
lnc_readCSR
uint16_t lnc_readCSR(struct lncInfo *, uint16_t)
Definition: lnc.c:64
lnc_rxINT
void lnc_rxINT()
Definition: lnc.c:316
lnc_INT
void lnc_INT()
Definition: lnc.c:254
lncInfo::rxPtr
int rxPtr
Definition: lnc.h:140
lnc
struct lncInfo * lnc
Definition: lnc.c:44
lnc_readBCR32
uint32_t lnc_readBCR32(struct lncInfo *, uint32_t)
Definition: lnc.c:89
uInt8
unsigned char uInt8
Definition: objgfx30.h:47
lncInfo::nic
struct nicInfo nic
Definition: lnc.h:129
_lncInt
void _lncInt()
initLNC
int initLNC()
Definition: lnc.c:94
initBlock16::mode
uint16_t mode
Definition: lnc.h:107
lnc_writeCSR32
void lnc_writeCSR32(struct lncInfo *, uint32_t, uint32_t)
Definition: lnc.c:59
initBlock32::padr
uint8_t padr[6]
Definition: lnc.h:120
hostRingEntry_old
Definition: lnc.h:76
uint32_t
__uint32_t uint32_t
Definition: types.h:46
lncInfo::ioAddr
unsigned int ioAddr
Definition: lnc.h:135
arpcom
Definition: lnc.h:91
hostRingEntry::reserved
uint32_t reserved
Definition: lnc.h:88
lncInfo::bufferSize
int bufferSize
Definition: lnc.h:138
initBlock16::tlen
uint16_t tlen
Definition: lnc.h:113
lnc_getMode
int lnc_getMode(struct lncInfo *)
Definition: lnc.c:573
lncInt
void lncInt()
Definition: lnc.c:368
lnc_writeCSR
void lnc_writeCSR(struct lncInfo *, uint16_t, uint16_t)
Definition: lnc.c:54
lncAttach
int lncAttach(struct lncInfo *lnc, int unit)
Definition: lnc.c:419
probe
int probe(struct lncInfo *lnc)
lnc_txINT
void lnc_txINT()
Definition: lnc.c:352
lnc_probe
int lnc_probe(struct lncInfo *)
Definition: lnc.c:191
lncInfo::ntdre
int ntdre
Definition: lnc.h:137
initBlock32
Definition: lnc.h:116
mds::md0
uint16_t md0
Definition: lnc.h:70
hostRingEntry::addr
uint32_t addr
Definition: lnc.h:85
arpcom::ac_enaddr
uint8_t ac_enaddr[6]
Definition: lnc.h:93
initBlock32::rdra
uint32_t rdra
Definition: lnc.h:123
mds
Definition: lnc.h:69
hostRingEntry_old::md
struct mds * md
Definition: lnc.h:77
initBlock16::ladrf
uint8_t ladrf[8]
Definition: lnc.h:109
initBlock32::tdra
uint32_t tdra
Definition: lnc.h:124
lncInfo::txPtr
int txPtr
Definition: lnc.h:139
hostRingEntry::md
uint8_t md[6]
Definition: lnc.h:87
initBlock32::tlen
uint8_t tlen
Definition: lnc.h:119
lncInfo::txBuffer
char * txBuffer
Definition: lnc.h:133
uint8_t
__uint8_t uint8_t
Definition: types.h:44
lanceProbe
int lanceProbe(struct lncInfo *lnc)
Definition: lnc.c:231
hostRingEntry
Definition: lnc.h:84
lnc_readCSR32
uint32_t lnc_readCSR32(struct lncInfo *, uint32_t)
Definition: lnc.c:69
lnc_writeBCR
void lnc_writeBCR(struct lncInfo *, uint16_t, uint16_t)
Definition: lnc.c:74
mds::md3
uint16_t md3
Definition: lnc.h:73
lnc_readBCR
uint16_t lnc_readBCR(struct lncInfo *, uint16_t)
Definition: lnc.c:84
initBlock32::rlen
uint8_t rlen
Definition: lnc.h:118
lnc_writeBCR32
void lnc_writeBCR32(struct lncInfo *, uint32_t, uint32_t)
Definition: lnc.c:79
nicInfo::mode
int mode
Definition: lnc.h:103
initBlock32::res
uint16_t res
Definition: lnc.h:121