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

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

Let leaf drivers enable/disable/clear interrupts via hw_res instead of directly using irc.

  • 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 /** DDF device */
90 ddf_dev_t *dev;
91 /** Parent session */
92 async_sess_t *parent_sess;
93 /** I/O address of the device */
94 void *io_addr;
95 /** Mapped I/O port */
96 void *io_port;
97 /** The irq assigned */
98 int irq;
99
100 /** Mask of the turned interupts (IMR value) */
101 uint16_t int_mask;
102
103 /** The memory allocated for the transmittion buffers
104 * Each buffer takes 2kB
105 */
106 uintptr_t tx_buff_phys;
107 void *tx_buff_virt;
108
109 /** Virtual adresses of the Tx buffers */
110 void *tx_buff[TX_BUFF_COUNT];
111
112 /** The nubmer of the next buffer to use, index = tx_next % TX_BUFF_COUNT */
113 size_t tx_next;
114 /** The number of the first used buffer in the row
115 *
116 * tx_used is in the interval tx_next - TX_BUFF_COUNT and tx_next:
117 * tx_next - TX_BUFF_COUNT: there is no useable Tx descriptor
118 * tx_next: all Tx descriptors are can be used
119 */
120 size_t tx_used;
121
122 /** Buffer for receiving frames */
123 uintptr_t rx_buff_phys;
124 void *rx_buff_virt;
125
126 /** Receiver control register data */
127 struct rtl8139_rcr_data rcr_data;
128
129 /** Power management information */
130 rtl8139_pm_t pm;
131
132 /** Lock for receiver */
133 fibril_mutex_t rx_lock;
134 /** Lock for transmitter */
135 fibril_mutex_t tx_lock;
136
137 /** Polling mode information */
138 rtl8139_timer_act_t poll_timer;
139
140 /** Backward pointer to nic_data */
141 nic_t *nic_data;
142
143 /** Version of RT8139 controller */
144 rtl8139_version_id_t hw_version;
145} rtl8139_t;
146
147/* ***** Pointers casting - for both amd64 and ia32 ***** */
148
149/** Cast pointer to uint32_t
150 *
151 * @param ptr The pointer to cast
152 * @return The uint32_t pointer representation. The low 32 bit is taken
153 * in the case of the 64 bit pointers
154 */
155#define PTR2U32(ptr) ((uint32_t)((size_t)(ptr)))
156
157/** Check if the pointer can be cast to uint32_t without the data lost
158 *
159 * @param ptr The pointer to check
160 * @return The true value if the pointer can be cast, false if not
161 */
162#define PTR_IS_32(ptr) ((size_t)PTR2U32(ptr) == (size_t)(ptr))
163
164/** Cast the ioaddr part to the void*
165 *
166 * @param ioaddr The ioaddr value
167 */
168#define IOADDR_TO_PTR(ioaddr) ((void*)((size_t)(ioaddr)))
169
170/* ***** Bit operation macros ***** */
171
172/** Set the bits specified by the given bit mask to the different values
173 *
174 * The bit from the src is used if the corresponding bit in the mask is 0,
175 * the bit from the value is used if the corresponding bit in the mask is 1
176 *
177 * @param src The original value
178 * @param value The new bit value
179 * @param mask The mask to specify modified bits
180 * @param type The values type
181 *
182 * @return New value
183 */
184#define bit_set_part_g(src, value, mask, type) \
185 ((type)(((src) & ~((type)(mask))) | ((value) & (type)(mask))))
186
187/** Set the bits specified by the given bit mask to the different values
188 *
189 * The version of the uint32_t
190 *
191 * @see bit_set_part_g
192 */
193
194#define bit_set_part_32(src, value, mask) bit_set_part_g(src, value, mask, uint32_t)
195/** Set the bits specified by the given bit mask to the different values
196 *
197 * The version of the uint16_t
198 *
199 * @see bit_set_part_g
200 */
201
202#define bit_set_part_16(src, value, mask) bit_set_part_g(src, value, mask, uint16_t)
203
204/** Set the bits specified by the given bit mask to the different values
205 *
206 * The version of the uint8_t
207 *
208 * @see bit_set_part_g
209 */
210#define bit_set_part_8(src, value, mask) bit_set_part_g(src, value, mask, uint8_t)
211
212/** Clear specified bits in the value
213 *
214 * @param src Original value
215 * @param clear_mask Bits to clear mask
216 * @param type The values type
217 */
218#define bit_clear_g(src, clear_mask, type) ((type)((src) & ~((type)(clear_mask))))
219
220/** Clear specified bits in the value, 32bit version
221 *
222 * @see bit_clear_g
223 */
224#define bit_clear_32(src, clear_mask) bit_clear_g(src, clear_mask, uint32_t)
225/** Clear specified bits in the value, 16bit version
226 *
227 * @see bit_clear_g
228 */
229#define bit_clear_16(src, clear_mask) bit_clear_g(src, clear_mask, uint16_t)
230/** Clear specified bits in the value, 8bit version
231 *
232 * @see bit_clear_g
233 */
234#define bit_clear_8(src, clear_mask) bit_clear_g(src, clear_mask, uint8_t)
235
236/** Obtain value of the TSD register with size part modified
237 *
238 * @param tsd_value Old value of the TSD
239 * @param size The size to set
240 */
241#define rtl8139_tsd_set_size(tsd_value, size) \
242 bit_set_part_32(tsd_value, (size) << TSD_SIZE_SHIFT, TSD_SIZE_MASK << TSD_SIZE_SHIFT)
243
244#endif
Note: See TracBrowser for help on using the repository browser.