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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since d8da56b was 1bc35b5, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Remove most use of packet_t from NIC drivers.

  • 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 "defs.h"
33#include "general.h"
34#include <sys/types.h>
35#include <stdint.h>
36
37/** The driver name */
38#define NAME "rtl8139"
39/** Transmittion buffers count */
40#define TX_BUFF_COUNT 4
41/** Size of buffer for one frame
42 * - 2kB
43 */
44#define TX_BUFF_SIZE (2 * 1024)
45/** Count of pages to allocate for TxBuffers */
46#define TX_PAGES 2
47
48/** Size of the CRC after the received frame in the receiver buffer */
49#define RTL8139_CRC_SIZE 4
50
51/** The default mode of accepting unicast frames */
52#define RTL8139_RCR_UCAST_DEFAULT RCR_ACCEPT_PHYS_MATCH
53/** The default mode of accepting multicast frames */
54#define RTL8139_RCR_MCAST_DEFAULT 0
55/** The default mode of accepting broadcast frames */
56#define RTL8139_RCR_BCAST_DEFAULT RCR_ACCEPT_BROADCAST
57/** The default mode of accepting defect frames */
58#define RTL8139_RCR_DEFECT_DEFAULT 0
59
60/** Mask for accepting all multicast */
61#define RTL8139_MCAST_MASK_PROMISC UINT64_MAX
62
63/** Data */
64struct rtl8139_rcr_data {
65 /** Configuration part of RCR */
66 uint32_t rcr_base;
67 /** Mask of unicast */
68 uint8_t ucast_mask;
69 /** Mask of multicast */
70 uint8_t mcast_mask;
71 /** Mask of broadcast */
72 uint8_t bcast_mask;
73 /** Mask of defective */
74 uint8_t defect_mask;
75};
76
77/** Power management related data */
78typedef struct rtl8139_pm {
79 /** Count of used activities which needs PMEn bit set */
80 int active;
81} rtl8139_pm_t;
82
83/** RTL8139 device data */
84typedef struct rtl8139_data {
85 /** I/O address of the device */
86 void *io_addr;
87 /** Mapped I/O port */
88 void *io_port;
89 /** The irq assigned */
90 int irq;
91
92 /** Mask of the turned interupts (IMR value) */
93 uint16_t int_mask;
94
95 /** The memory allocated for the transmittion buffers
96 * Each buffer takes 2kB
97 */
98 void *tx_buff_phys;
99 void *tx_buff_virt;
100
101 /** Virtual adresses of the Tx buffers */
102 void *tx_buff[TX_BUFF_COUNT];
103
104 /** The nubmer of the next buffer to use, index = tx_next % TX_BUFF_COUNT */
105 size_t tx_next;
106 /** The number of the first used buffer in the row
107 *
108 * tx_used is in the interval tx_next - TX_BUFF_COUNT and tx_next:
109 * tx_next - TX_BUFF_COUNT: there is no useable Tx descriptor
110 * tx_next: all Tx descriptors are can be used
111 */
112 size_t tx_used;
113
114 /** Buffer for receiving frames */
115 void *rx_buff_phys;
116 void *rx_buff_virt;
117
118 /** Receiver control register data */
119 struct rtl8139_rcr_data rcr_data;
120
121 /** Power management information */
122 rtl8139_pm_t pm;
123
124 /** Lock for receiver */
125 fibril_mutex_t rx_lock;
126 /** Lock for transmitter */
127 fibril_mutex_t tx_lock;
128
129 /** Polling mode information */
130 rtl8139_timer_act_t poll_timer;
131
132 /** Backward pointer to nic_data */
133 nic_t *nic_data;
134
135 /** Version of RT8139 controller */
136 enum rtl8139_version_id hw_version;
137} rtl8139_t;
138
139
140/* ***** Pointers casting - for both amd64 and ia32 ***** */
141
142/** Cast pointer to uint32_t
143 *
144 * @param ptr The pointer to cast
145 * @return The uint32_t pointer representation. The low 32 bit is taken
146 * in the case of the 64 bit pointers
147 */
148#define PTR2U32(ptr) ((uint32_t)((size_t)(ptr)))
149
150/** Check if the pointer can be cast to uint32_t without the data lost
151 *
152 * @param ptr The pointer to check
153 * @return The true value if the pointer can be cast, false if not
154 */
155#define PTR_IS_32(ptr) ((size_t)PTR2U32(ptr) == (size_t)(ptr))
156
157/** Cast the ioaddr part to the void*
158 *
159 * @param ioaddr The ioaddr value
160 */
161#define IOADDR_TO_PTR(ioaddr) ((void*)((size_t)(ioaddr)))
162
163
164
165/* ***** Bit operation macros ***** */
166
167/** Set the bits specified by the given bit mask to the different values
168 *
169 * The bit from the src is used if the corresponding bit in the mask is 0,
170 * the bit from the value is used if the corresponding bit in the mask is 1
171 *
172 * @param src The original value
173 * @param value The new bit value
174 * @param mask The mask to specify modified bits
175 * @param type The values type
176 *
177 * @return New value
178 */
179#define bit_set_part_g( src, value, mask, type ) \
180 ((type)(((src) & ~((type)(mask))) | ((value) & (type)(mask))))
181
182/** Set the bits specified by the given bit mask to the different values
183 *
184 * The version of the uint32_t
185 *
186 * @see bit_set_part_g
187 */
188
189#define bit_set_part_32(src, value, mask) bit_set_part_g(src, value, mask, uint32_t)
190/** Set the bits specified by the given bit mask to the different values
191 *
192 * The version of the uint16_t
193 *
194 * @see bit_set_part_g
195 */
196
197#define bit_set_part_16(src, value, mask) bit_set_part_g(src, value, mask, uint16_t)
198
199/** Set the bits specified by the given bit mask to the different values
200 *
201 * The version of the uint8_t
202 *
203 * @see bit_set_part_g
204 */
205#define bit_set_part_8(src, value, mask) bit_set_part_g(src, value, mask, uint8_t)
206
207/** Clear specified bits in the value
208 *
209 * @param src Original value
210 * @param clear_mask Bits to clear mask
211 * @param type The values type
212 */
213#define bit_clear_g(src, clear_mask, type) ((type)((src) & ~((type)(clear_mask))))
214
215/** Clear specified bits in the value, 32bit version
216 *
217 * @see bit_clear_g
218 */
219#define bit_clear_32(src, clear_mask) bit_clear_g(src, clear_mask, uint32_t)
220/** Clear specified bits in the value, 16bit version
221 *
222 * @see bit_clear_g
223 */
224#define bit_clear_16(src, clear_mask) bit_clear_g(src, clear_mask, uint16_t)
225/** Clear specified bits in the value, 8bit version
226 *
227 * @see bit_clear_g
228 */
229#define bit_clear_8(src, clear_mask) bit_clear_g(src, clear_mask, uint8_t)
230
231/** Obtain value of the TSD register with size part modified
232 *
233 * @param tsd_value Old value of the TSD
234 * @param size The size to set
235 */
236#define rtl8139_tsd_set_size(tsd_value, size) \
237 bit_set_part_32(tsd_value, (size) << TSD_SIZE_SHIFT, TSD_SIZE_MASK << TSD_SIZE_SHIFT)
238
239
240#endif
Note: See TracBrowser for help on using the repository browser.