Imported Upstream version 3.2.2
[debian/gnuradio] / usrp2 / firmware / lib / ethernet.h
1 /* -*- c -*- */
2 /*
3  * Copyright 2007 Free Software Foundation, Inc.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifndef INCLUDED_ETHERNET_H
20 #define INCLUDED_ETHERNET_H
21
22 #include "usrp2_mac_addr.h"
23 #include "bool.h"
24
25 typedef void (*ethernet_link_changed_callback_t)(int speed);
26
27
28 /*!
29  * \brief one time call to initialize ethernet
30  */
31 void ethernet_init(void);
32
33 /*!
34  * \brief Specify the function to call on link state changes.
35  * 
36  * When the link comes up, speed is the link speed in Mbit/s.
37  * When the link goes down, speed is 0.
38  */
39 void ethernet_register_link_changed_callback(ethernet_link_changed_callback_t cb);
40
41 /*!
42  * \returns ethernet MAC address
43  */
44 const u2_mac_addr_t *ethernet_mac_addr(void);
45
46 /*!
47  * \brief write mac address to eeprom and begin using it
48  */
49 bool ethernet_set_mac_addr(const u2_mac_addr_t *t);
50
51
52 /*
53  * \brief read RMON regs and return error mask
54  */
55 int ethernet_check_errors(void);
56
57 #define RME_RX_CRC           0x0001
58 #define RME_RX_FIFO_FULL     0x0002
59 #define RME_RX_2SHORT_2LONG  0x0004
60
61 #define RME_TX_JAM_DROP      0x0010
62 #define RME_TX_FIFO_UNDER    0x0020
63 #define RME_TX_FIFO_OVER     0x0040
64
65
66 typedef enum { LS_UNKNOWN, LS_DOWN, LS_UP } eth_link_state_t;
67
68 // flow control bitmasks
69 #define FC_NONE         0x0
70 #define FC_WE_TX        0x1                     // we send PAUSE frames
71 #define FC_WE_RX        0x2                     // we honor received PAUSE frames
72 #define FC_SYMM         (FC_WE_TX | FC_WE_RX)
73
74 #define S_UNKNOWN (-1)                  // unknown link speed
75
76 typedef struct {
77   eth_link_state_t      link_state;
78   int                   link_speed;     // in Mb/s
79   int                   flow_control;
80 } ethernet_t;
81
82 #endif /* INCLUDED_ETHERNET_H */