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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since fd9f4ffe was 8d2dd7f2, checked in by Jakub Jermar <jakub@…>, 8 years ago

Reduce the number of files that include <sys/types.h>

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