KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
broadband_adapter.h
Go to the documentation of this file.
1 /* KallistiOS ##version##
2 
3  dc/net/broadband_adapter.h
4  Copyright (C) 2001-2002 Dan Potter
5 
6 */
7 
8 /** \file dc/net/broadband_adapter.h
9  \brief Broadband Adapter support.
10 
11  This file contains declarations related to support for the HIT-0400
12  "Broadband Adapter". There's not really anything that users will generally
13  have to deal with in here.
14 
15  \author Dan Potter
16 */
17 
18 #ifndef __DC_NET_BROADBAND_ADAPTER_H
19 #define __DC_NET_BROADBAND_ADAPTER_H
20 
21 #include <sys/cdefs.h>
22 __BEGIN_DECLS
23 
24 /** \defgroup bba_regs RTL8139C Register Definitions
25  @{
26 */
27 #define RT_IDR0 0x00 /**< \brief MAC address */
28 #define RT_MAR0 0x08 /**< \brief Multicast filter */
29 #define RT_TXSTATUS0 0x10 /**< \brief Transmit status (4 32bit regs) */
30 #define RT_TXADDR0 0x20 /**< \brief Tx descriptors (also 4 32bit) */
31 #define RT_RXBUF 0x30 /**< \brief Receive buffer start address */
32 #define RT_RXEARLYCNT 0x34 /**< \brief Early Rx byte count */
33 #define RT_RXEARLYSTATUS 0x36 /**< \brief Early Rx status */
34 #define RT_CHIPCMD 0x37 /**< \brief Command register */
35 #define RT_RXBUFTAIL 0x38 /**< \brief Current address of packet read (queue tail) */
36 #define RT_RXBUFHEAD 0x3A /**< \brief Current buffer address (queue head) */
37 #define RT_INTRMASK 0x3C /**< \brief Interrupt mask */
38 #define RT_INTRSTATUS 0x3E /**< \brief Interrupt status */
39 #define RT_TXCONFIG 0x40 /**< \brief Tx config */
40 #define RT_RXCONFIG 0x44 /**< \brief Rx config */
41 #define RT_TIMER 0x48 /**< \brief A general purpose counter */
42 #define RT_RXMISSED 0x4C /**< \brief 24 bits valid, write clears */
43 #define RT_CFG9346 0x50 /**< \brief 93C46 command register */
44 #define RT_CONFIG0 0x51 /**< \brief Configuration reg 0 */
45 #define RT_CONFIG1 0x52 /**< \brief Configuration reg 1 */
46 #define RT_TIMERINT 0x54 /**< \brief Timer interrupt register (32 bits) */
47 #define RT_MEDIASTATUS 0x58 /**< \brief Media status register */
48 #define RT_CONFIG3 0x59 /**< \brief Config register 3 */
49 #define RT_CONFIG4 0x5A /**< \brief Config register 4 */
50 #define RT_MULTIINTR 0x5C /**< \brief Multiple interrupt select */
51 #define RT_MII_TSAD 0x60 /**< \brief Transmit status of all descriptors (16 bits) */
52 #define RT_MII_BMCR 0x62 /**< \brief Basic Mode Control Register (16 bits) */
53 #define RT_MII_BMSR 0x64 /**< \brief Basic Mode Status Register (16 bits) */
54 #define RT_AS_ADVERT 0x66 /**< \brief Auto-negotiation advertisement reg (16 bits) */
55 #define RT_AS_LPAR 0x68 /**< \brief Auto-negotiation link partner reg (16 bits) */
56 #define RT_AS_EXPANSION 0x6A /**< \brief Auto-negotiation expansion reg (16 bits) */
57 /** @} */
58 
59 /** \defgroup bba_miicb RTL8139C MII (media independent interface) control bits
60  @{
61 */
62 #define RT_MII_AN_START 0x0200 /**< \brief Start auto-negotiation */
63 #define RT_MII_AN_ENABLE 0x1000 /**< \brief Enable auto-negotiation */
64 #define RT_MII_RESET 0x8000 /**< \brief Reset the MII chip */
65 /** @} */
66 
67 /** \defgroup bba_miisb RTL8139C MII (media independent interface) status bits
68  @{
69 */
70 #define RT_MII_LINK 0x0004 /**< \brief Link is present */
71 #define RT_MII_AN_CAPABLE 0x0008 /**< \brief Can do auto negotiation */
72 #define RT_MII_AN_COMPLETE 0x0020 /**< \brief Auto-negotiation complete */
73 #define RT_MII_10_HALF 0x0800 /**< \brief Can do 10Mbit half duplex */
74 #define RT_MII_10_FULL 0x1000 /**< \brief Can do 10Mbit full */
75 #define RT_MII_100_HALF 0x2000 /**< \brief Can do 100Mbit half */
76 #define RT_MII_100_FULL 0x4000 /**< \brief Can do 100Mbit full */
77 /** @} */
78 
79 /** \defgroup bba_cbits RTL8139C Command Bits
80 
81  OR appropriate bit values together and write into the RT_CHIPCMD register to
82  execute the command.
83 
84  @{
85 */
86 #define RT_CMD_RESET 0x10 /**< \brief Reset the RTL8139C */
87 #define RT_CMD_RX_ENABLE 0x08 /**< \brief Enable Rx */
88 #define RT_CMD_TX_ENABLE 0x04 /**< \brief Enable Tx */
89 #define RT_CMD_RX_BUF_EMPTY 0x01 /**< \brief Empty the Rx buffer */
90 /** @} */
91 
92 /** \defgroup bba_ibits RTL8139C Interrupt Status bits
93  @{
94 */
95 #define RT_INT_PCIERR 0x8000 /**< \brief PCI Bus error */
96 #define RT_INT_TIMEOUT 0x4000 /**< \brief Set when TCTR reaches TimerInt value */
97 #define RT_INT_RXFIFO_OVERFLOW 0x0040 /**< \brief Rx FIFO overflow */
98 #define RT_INT_RXFIFO_UNDERRUN 0x0020 /**< \brief Packet underrun / link change */
99 #define RT_INT_LINK_CHANGE 0x0020 /**< \brief Packet underrun / link change */
100 #define RT_INT_RXBUF_OVERFLOW 0x0010 /**< \brief Rx BUFFER overflow */
101 #define RT_INT_TX_ERR 0x0008 /**< \brief Tx error */
102 #define RT_INT_TX_OK 0x0004 /**< \brief Tx OK */
103 #define RT_INT_RX_ERR 0x0002 /**< \brief Rx error */
104 #define RT_INT_RX_OK 0x0001 /**< \brief Rx OK */
105 
106 /** \brief Composite RX bits we check for while doing an RX interrupt. */
107 #define RT_INT_RX_ACK (RT_INT_RXFIFO_OVERFLOW | RT_INT_RXBUF_OVERFLOW | RT_INT_RX_OK)
108 /** @} */
109 
110 /** \defgroup bba_tbits RTL8139C transmit status bits
111  @{
112 */
113 #define RT_TX_CARRIER_LOST 0x80000000 /**< \brief Carrier sense lost */
114 #define RT_TX_ABORTED 0x40000000 /**< \brief Transmission aborted */
115 #define RT_TX_OUT_OF_WINDOW 0x20000000 /**< \brief Out of window collision */
116 #define RT_TX_STATUS_OK 0x00008000 /**< \brief Status ok: a good packet was transmitted */
117 #define RT_TX_UNDERRUN 0x00004000 /**< \brief Transmit FIFO underrun */
118 #define RT_TX_HOST_OWNS 0x00002000 /**< \brief Set to 1 when DMA operation is completed */
119 #define RT_TX_SIZE_MASK 0x00001fff /**< \brief Descriptor size mask */
120 /** @} */
121 
122 /** \defgroup bba_rbits RTL8139C receive status bits
123  @{
124 */
125 #define RT_RX_MULTICAST 0x00008000 /**< \brief Multicast packet */
126 #define RT_RX_PAM 0x00004000 /**< \brief Physical address matched */
127 #define RT_RX_BROADCAST 0x00002000 /**< \brief Broadcast address matched */
128 #define RT_RX_BAD_SYMBOL 0x00000020 /**< \brief Invalid symbol in 100TX packet */
129 #define RT_RX_RUNT 0x00000010 /**< \brief Packet size is <64 bytes */
130 #define RT_RX_TOO_LONG 0x00000008 /**< \brief Packet size is >4K bytes */
131 #define RT_RX_CRC_ERR 0x00000004 /**< \brief CRC error */
132 #define RT_RX_FRAME_ALIGN 0x00000002 /**< \brief Frame alignment error */
133 #define RT_RX_STATUS_OK 0x00000001 /**< \brief Status ok: a good packet was received */
134 /** @} */
135 
136 /** \brief Retrieve the MAC Address of the attached BBA.
137 
138  This function reads the MAC Address of the BBA and places it in the buffer
139  passed in. The resulting data is undefined if no BBA is connected.
140 
141  \param arr The array to read the MAC into.
142 */
143 void bba_get_mac(uint8 *arr);
144 
145 /** \brief Receive packet callback function type.
146 
147  When a packet is received by the BBA, the callback function will be called
148  to handle it.
149 
150  \param pkt A pointer to the packet in question.
151  \param len The length, in bytes, of the packet.
152 */
153 typedef void (*eth_rx_callback_t)(uint8 *pkt, int len);
154 
155 /** \brief Set the ethernet packet receive callback.
156 
157  This function sets the function called when a packet is received by the BBA.
158  Generally, this inputs into the network layer.
159 
160  \param cb A pointer to the new callback function.
161 */
163 
164 /** \defgroup bba_txrv Return values from bba_tx().
165  @{
166 */
167 #define BBA_TX_OK 0 /**< \brief Transmit success */
168 #define BBA_TX_ERROR -1 /**< \brief Transmit error */
169 #define BBA_TX_AGAIN -2 /**< \brief Retry transmit again */
170 /** @} */
171 
172 #define BBA_TX_NOWAIT 0 /**< \brief Don't block waiting for the transfer. */
173 #define BBA_TX_WAIT 1 /**< \brief Wait, if needed on transfer. */
174 
175 /** \brief Transmit a single packet.
176 
177  This function transmits a single packet on the bba, waiting for the link to
178  become stable, if requested.
179 
180  \param pkt The packet to transmit.
181  \param len The length of the packet, in bytes.
182  \param wait BBA_TX_WAIT if you don't mind blocking for the
183  all clear to transmit, BBA_TX_NOWAIT otherwise.
184 
185  \retval BBA_TX_OK On success.
186  \retval BBA_TX_ERROR If there was an error transmitting the packet.
187  \retval BBA_TX_AGAIN If BBA_TX_NOWAIT was specified and it is not ok to
188  transmit right now.
189 */
190 int bba_tx(const uint8 *pkt, int len, int wait);
191 
192 /* \cond */
193 /* Initialize */
194 int bba_init();
195 
196 /* Shutdown */
197 int bba_shutdown();
198 /* \endcond */
199 
200 __END_DECLS
201 
202 #endif /* __DC_NET_BROADBAND_ADAPTER_H */
203 
void(* eth_rx_callback_t)(uint8 *pkt, int len)
Receive packet callback function type.
Definition: broadband_adapter.h:153
void bba_set_rx_callback(eth_rx_callback_t cb)
Set the ethernet packet receive callback.
unsigned char uint8
8-bit unsigned integer
Definition: types.h:30
int bba_tx(const uint8 *pkt, int len, int wait)
Transmit a single packet.
void bba_get_mac(uint8 *arr)
Retrieve the MAC Address of the attached BBA.