summaryrefslogtreecommitdiffstats
path: root/ports/beagleboneblack/etherdev.c
blob: 050f18f8697fe3c1bbebfcf9aef95a24d3ecf0c2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
//=============================================================================
//
//      etherdev.c
//
//      Ethernet Abstraction Layer for Micro Monitor
//
// Author(s):    Michael Kelly, Cogent Computer Systems, Inc.
// Contributors: Luis Torrico, Cogent Computer Systems, Inc.
// Date:         05-26-2002
// Modified:     06-26-2007
// Description:  This file contains the interface layer between Micro Monitor
//               and the Ethernet driver for the LAN921x on the CSB733.
//
//=============================================================================

#include "config.h"
#include "cpuio.h"
#include "genlib.h"
#include "stddefs.h"
#include "ether.h"

extern void smsc911x_reset(void);
extern ushort smsc911x_rx(uchar *pktbuf);
extern int smsc911x_init(void);
extern ulong smsc911x_tx(ulong txbuf, ulong length);
extern void smsc911x_enable_promiscuous_reception(void);
extern void smsc911x_disable_promiscuous_reception(void);
extern void smsc911x_enable_multicast_reception(void);
extern void smsc911x_disable_multicast_reception(void);
extern void smsc911x_enable_broadcast_reception(void);
extern void smsc911x_disable_broadcast_reception(void);

ulong tx_buf[400];

#if INCLUDE_ETHERNET

/*
 * enreset():
 *  Reset the PHY and MAC.
 */
void
enreset(void)
{
    smsc911x_reset();
}

/*
 * eninit():
 * This would include establishing buffer descriptor tables and
 * all the support code that will be used by the ethernet device.
 *
 * It can be assumed at this point that the array uchar BinEnetAddr[6]
 * contains the 6-byte MAC address.
 *
 * Return 0 if successful; else -1.
 */
int
eninit(void)
{
    return smsc911x_init();

}

int
EtherdevStartup(int verbose)
{
    /* Initialize local device error counts (if any) here. */
    /* OPT_ADD_CODE_HERE */

    /* Put ethernet controller in reset: */
    enreset();

    /* Initialize controller: */
    eninit();

    return(0);
}

/* disablePromiscuousReception():
 * Provide the code that disables promiscuous reception.
 */
void
disablePromiscuousReception(void)
{
    smsc911x_disable_promiscuous_reception();
}

/* enablePromiscuousReception():
 * Provide the code that enables promiscuous reception.
 */
void
enablePromiscuousReception(void)
{
    smsc911x_enable_promiscuous_reception();
}

/* disableBroadcastReception():
 * Provide the code that disables broadcast reception.
 */
void
disableBroadcastReception(void)
{
    smsc911x_disable_broadcast_reception();
}

/* enableBroadcastReception():
 * Provide the code that enables broadcast reception.
 */
void
enableBroadcastReception(void)
{
    smsc911x_enable_broadcast_reception();
}

void
disableMulticastReception(void)
{
    smsc911x_disable_multicast_reception();
}

void
enableMulticastReception(void)
{
    smsc911x_enable_multicast_reception();
}


/*
 * enselftest():
 *  Run a self test of the ethernet device(s).  This can be stubbed
 *  with a return(1).
 *  Return 1 if success; else -1 if failure.
 */
int
enselftest(int verbose)
{
    return(1);
}

/* ShowEtherdevStats():
 * This function is used to display device-specific stats (error counts
 * usually).
 */
void
ShowEtherdevStats(void)
{
    /* OPT_ADD_CODE_HERE */
}

/* getXmitBuffer():
 * Return a pointer to the buffer that is to be used for transmission of
 * the next packet.  Since the monitor's driver is EXTREMELY basic,
 * there will only be one packet ever being transmitted.  No need to queue
 * up transmit packets.
 */
uchar *
getXmitBuffer(void)
{
    return((uchar *) tx_buf);
}

/* sendBuffer():
 * Send out the packet assumed to be built in the buffer returned by the
 * previous call to getXmitBuffer() above.
 */
int
sendBuffer(int length)
{
    ulong temp32;

    if(length < 64) {
        length = 64;
    }

    if(EtherVerbose &  SHOW_OUTGOING) {
        printPkt((struct ether_header *)tx_buf,length,ETHER_OUTGOING);
    }

    // tell the cs8900a to send the tx buffer pointed to by tx_buf
    temp32 = smsc911x_tx((ulong)tx_buf, (ulong)length);

    EtherXFRAMECnt++;
    if(temp32) {
        return -1;
    } else {
        return 0;
    }
}

/* DisableEtherdev():
 * Fine as it is...
 */
void
DisableEtherdev(void)
{
    enreset();
}

/* extGetIpAdd():
 * If there was some external mechanism (other than just using the
 * IPADD shell variable established in the monrc file) for retrieval of
 * the board's IP address, then do it here...
 */
char *
extGetIpAdd(void)
{
    return((char *)0);
}

/* extGetEtherAdd():
 * If there was some external mechanism (other than just using the
 * ETHERADD shell variable established in the monrc file) for retrieval of
 * the board's MAC address, then do it here...
 */
char *
extGetEtherAdd(void)
{
    return((char *)0);
}

/*
 * polletherdev():
 * Called continuously by the monitor (ethernet.c) to determine if there
 * is any incoming ethernet packets.
 */
int
polletherdev(void)
{
    ulong pktbuf[RBUFSIZE/4];
    int pktlen, pktcnt = 0;

    pktlen = smsc911x_rx((uchar *)pktbuf);

    if(pktlen) {
        pktcnt = 1;
        EtherRFRAMECnt++;
        processPACKET((struct ether_header *)pktbuf, pktlen);
    }
    return(pktcnt);
}

#endif