source: mainline/uspace/drv/nic/rtl8139/driver.h@ bf84871

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since bf84871 was bf84871, checked in by Martin Decky <martin@…>, 14 years ago

merge Realtek RTL8319 and Intel E1000 drivers from lp:~helenos-nicf/helenos/nicf
(the drivers do not compile and are not part of the build system so far)

  • Property mode set to 100644
File size: 6.9 KB
Line 
1/*
2 * Copyright (c) 2011 Jiri Michalec
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef RTL8139_DRIVER_H_
30#define RTL8139_DRIVER_H_
31
32#include "rtl8139_defs.h"
33#include "rtl8139_general.h"
34#include <sys/types.h>
35#include <stdint.h>
36#include <dma.h>
37
38/** The driver name */
39#define NAME "rtl8139"
40/** Transmittion buffers count */
41#define TX_BUFF_COUNT 4
42/** Size of buffer for one packet
43 * - 2kB
44 */
45#define TX_BUFF_SIZE (2 * 1024)
46/** Count of pages to allocate for TxBuffers */
47#define TX_PAGES 2
48
49/** Size of the CRC after the received frame in the receiver buffer */
50#define RTL8139_CRC_SIZE 4
51
52/** The default mode of accepting unicast packets */
53#define RTL8139_RCR_UCAST_DEFAULT RCR_ACCEPT_PHYS_MATCH
54/** The default mode of accepting multicast packets */
55#define RTL8139_RCR_MCAST_DEFAULT 0
56/** The default mode of accepting broadcast packets */
57#define RTL8139_RCR_BCAST_DEFAULT RCR_ACCEPT_BROADCAST
58/** The default mode of accepting defect packets */
59#define RTL8139_RCR_DEFECT_DEFAULT 0
60
61/** Mask for accepting all multicast */
62#define RTL8139_MCAST_MASK_PROMISC UINT64_MAX
63
64/** Data */
65struct rtl8139_rcr_data {
66 /** Configuration part of RCR */
67 uint32_t rcr_base;
68 /** Mask of unicast */
69 uint8_t ucast_mask;
70 /** Mask of multicast */
71 uint8_t mcast_mask;
72 /** Mask of broadcast */
73 uint8_t bcast_mask;
74 /** Mask of defective */
75 uint8_t defect_mask;
76};
77
78/** Power management related data */
79typedef struct rtl8139_pm {
80 /** Count of used activities which needs PMEn bit set */
81 int active;
82} rtl8139_pm_t;
83
84/** RTL8139 device data */
85typedef struct rtl8139_data {
86 /** I/O address of the device */
87 void *io_addr;
88 /** Mapped I/O port */
89 void *io_port;
90 /** The irq assigned */
91 int irq;
92
93 /** Mask of the turned interupts (IMR value) */
94 uint16_t int_mask;
95
96 /** The memory allocated for the transmittion buffers
97 * Each buffer takes 2kB
98 */
99 dma_mem_t tx_buff_mem;
100 /** Virtual adresses of the Tx buffers */
101 void *tx_buff[TX_BUFF_COUNT];
102
103 /** The nubmer of the next buffer to use, index = tx_next % TX_BUFF_COUNT */
104 size_t tx_next;
105 /** The number of the first used buffer in the row
106 *
107 * tx_used is in the interval tx_next - TX_BUFF_COUNT and tx_next:
108 * tx_next - TX_BUFF_COUNT: there is no useable Tx descriptor
109 * tx_next: all Tx descriptors are can be used
110 */
111 size_t tx_used;
112
113 /** Buffer for receiving packets */
114 dma_mem_t rx_buff;
115
116 /** Receiver control register data */
117 struct rtl8139_rcr_data rcr_data;
118
119 /** Power management information */
120 rtl8139_pm_t pm;
121
122 /** Lock for receiver */
123 fibril_mutex_t rx_lock;
124 /** Lock for transmitter */
125 fibril_mutex_t tx_lock;
126
127 /** Polling mode information */
128 rtl8139_timer_act_t poll_timer;
129
130 /** Backward pointer to nic_data */
131 nic_t *nic_data;
132
133 /** Version of RT8139 controller */
134 enum rtl8139_version_id hw_version;
135} rtl8139_t;
136
137
138/* ***** Pointers casting - for both amd64 and ia32 ***** */
139
140/** Cast pointer to uint32_t
141 *
142 * @param ptr The pointer to cast
143 * @return The uint32_t pointer representation. The low 32 bit is taken
144 * in the case of the 64 bit pointers
145 */
146#define PTR2U32(ptr) ((uint32_t)((size_t)(ptr)))
147
148/** Check if the pointer can be cast to uint32_t without the data lost
149 *
150 * @param ptr The pointer to check
151 * @return The true value if the pointer can be cast, false if not
152 */
153#define PTR_IS_32(ptr) ((size_t)PTR2U32(ptr) == (size_t)(ptr))
154
155/** Cast the ioaddr part to the void*
156 *
157 * @param ioaddr The ioaddr value
158 */
159#define IOADDR_TO_PTR(ioaddr) ((void*)((size_t)(ioaddr)))
160
161
162
163/* ***** Bit operation macros ***** */
164
165/** Set the bits specified by the given bit mask to the different values
166 *
167 * The bit from the src is used if the corresponding bit in the mask is 0,
168 * the bit from the value is used if the corresponding bit in the mask is 1
169 *
170 * @param src The original value
171 * @param value The new bit value
172 * @param mask The mask to specify modified bits
173 * @param type The values type
174 *
175 * @return New value
176 */
177#define bit_set_part_g( src, value, mask, type ) \
178 ((type)(((src) & ~((type)(mask))) | ((value) & (type)(mask))))
179
180/** Set the bits specified by the given bit mask to the different values
181 *
182 * The version of the uint32_t
183 *
184 * @see bit_set_part_g
185 */
186
187#define bit_set_part_32(src, value, mask) bit_set_part_g(src, value, mask, uint32_t)
188/** Set the bits specified by the given bit mask to the different values
189 *
190 * The version of the uint16_t
191 *
192 * @see bit_set_part_g
193 */
194
195#define bit_set_part_16(src, value, mask) bit_set_part_g(src, value, mask, uint16_t)
196
197/** Set the bits specified by the given bit mask to the different values
198 *
199 * The version of the uint8_t
200 *
201 * @see bit_set_part_g
202 */
203#define bit_set_part_8(src, value, mask) bit_set_part_g(src, value, mask, uint8_t)
204
205/** Clear specified bits in the value
206 *
207 * @param src Original value
208 * @param clear_mask Bits to clear mask
209 * @param type The values type
210 */
211#define bit_clear_g(src, clear_mask, type) ((type)((src) & ~((type)(clear_mask))))
212
213/** Clear specified bits in the value, 32bit version
214 *
215 * @see bit_clear_g
216 */
217#define bit_clear_32(src, clear_mask) bit_clear_g(src, clear_mask, uint32_t)
218/** Clear specified bits in the value, 16bit version
219 *
220 * @see bit_clear_g
221 */
222#define bit_clear_16(src, clear_mask) bit_clear_g(src, clear_mask, uint16_t)
223/** Clear specified bits in the value, 8bit version
224 *
225 * @see bit_clear_g
226 */
227#define bit_clear_8(src, clear_mask) bit_clear_g(src, clear_mask, uint8_t)
228
229/** Obtain value of the TSD register with size part modified
230 *
231 * @param tsd_value Old value of the TSD
232 * @param size The size to set
233 */
234#define rtl8139_tsd_set_size(tsd_value, size) \
235 bit_set_part_32(tsd_value, (size) << TSD_SIZE_SHIFT, TSD_SIZE_MASK << TSD_SIZE_SHIFT)
236
237
238#endif
Note: See TracBrowser for help on using the repository browser.