source: mainline/uspace/lib/nic/include/nic_driver.h@ 49bd793b

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

networking improvements

  • start the networking stack from init
  • add loopback network interface driver (cherrypicked and sanitized from lp:~helenos-nicf/helenos/nicf)
  • add libnic and various small pieces from lp:~helenos-nicf/helenos/nicf
  • fix client side of NIC_GET_ADDRESS
  • net binary overhaul

Note: "ping 127.0.0.1" works, but the first three pings timeout for some reason

  • Property mode set to 100644
File size: 7.4 KB
Line 
1/*
2 * Copyright (c) 2011 Radim Vansa
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/**
30 * @addtogroup libnic
31 * @{
32 */
33/**
34 * @file
35 * @brief Internal NICF structures
36 */
37
38#ifndef __NIC_DRIVER_H__
39#define __NIC_DRIVER_H__
40
41#ifndef LIBNIC_INTERNAL
42#error "This is internal libnic's header, please do not include it"
43#endif
44
45#include <fibril_synch.h>
46#include <net/device.h>
47#include <async.h>
48
49#include "nic.h"
50#include "nic_rx_control.h"
51#include "nic_wol_virtues.h"
52
53#define DEVICE_CATEGORY_NIC "nic"
54
55struct sw_poll_info {
56 fid_t fibril;
57 volatile int run;
58 volatile int running;
59};
60
61struct nic {
62 /**
63 * Device from device manager's point of view.
64 * The value must be set within the add_device handler
65 * (in nic_create_and_bind) and must not be changed.
66 */
67 ddf_dev_t *dev;
68 /**
69 * Device's NIC function.
70 * The value must be set within the add_device handler
71 * (in nic_driver_register_as_ddf_function) and must not be changed.
72 */
73 ddf_fun_t *fun;
74 /** Identifier for higher network stack layers */
75 nic_device_id_t device_id;
76 /** Current state of the device */
77 nic_device_state_t state;
78 /** Transmiter is busy - messages are dropped */
79 int tx_busy;
80 /** Device's MAC address */
81 nic_address_t mac;
82 /** Device's default MAC address (assigned the first time, used in STOP) */
83 nic_address_t default_mac;
84 /** Session to SERVICE_NETWORKING */
85 async_sess_t *net_session;
86 /** Session to SERVICE_ETHERNET or SERVICE_NILDUMMY */
87 async_sess_t *nil_session;
88 /** Phone to APIC or i8259 */
89 async_sess_t *irc_session;
90 /** Current polling mode of the NIC */
91 nic_poll_mode_t poll_mode;
92 /** Polling period (applicable when poll_mode == NIC_POLL_PERIODIC) */
93 struct timeval poll_period;
94 /** Current polling mode of the NIC */
95 nic_poll_mode_t default_poll_mode;
96 /** Polling period (applicable when default_poll_mode == NIC_POLL_PERIODIC) */
97 struct timeval default_poll_period;
98 /** Software period fibrill information */
99 struct sw_poll_info sw_poll_info;
100 /**
101 * Lock on everything but statistics, rx control and wol virtues. This lock
102 * cannot be used if filters_lock or stats_lock is already held - you must
103 * acquire main_lock first (otherwise deadlock could happen).
104 */
105 fibril_rwlock_t main_lock;
106 /** Device statistics */
107 nic_device_stats_t stats;
108 /**
109 * Lock for statistics. You must not hold any other lock from nic_t except
110 * the main_lock at the same moment. If both this lock and main_lock should
111 * be locked, the main_lock must be locked as the first.
112 */
113 fibril_rwlock_t stats_lock;
114 /** Receive control configuration */
115 nic_rxc_t rx_control;
116 /**
117 * Lock for receive control. You must not hold any other lock from nic_t
118 * except the main_lock at the same moment. If both this lock and main_lock
119 * should be locked, the main_lock must be locked as the first.
120 */
121 fibril_rwlock_t rxc_lock;
122 /** WOL virtues configuration */
123 nic_wol_virtues_t wol_virtues;
124 /**
125 * Lock for WOL virtues. You must not hold any other lock from nic_t
126 * except the main_lock at the same moment. If both this lock and main_lock
127 * should be locked, the main_lock must be locked as the first.
128 */
129 fibril_rwlock_t wv_lock;
130 /**
131 * Function really sending the data. This MUST be filled in if the
132 * nic_send_message_impl function is used for sending messages (filled
133 * as send_message member of the nic_iface_t structure).
134 * Called with the main_lock locked for reading.
135 */
136 write_packet_handler write_packet;
137 /**
138 * Event handler called when device goes to the ACTIVE state.
139 * The implementation is optional.
140 * Called with the main_lock locked for writing.
141 */
142 state_change_handler on_activating;
143 /**
144 * Event handler called when device goes to the DOWN state.
145 * The implementation is optional.
146 * Called with the main_lock locked for writing.
147 */
148 state_change_handler on_going_down;
149 /**
150 * Event handler called when device goes to the STOPPED state.
151 * The implementation is optional.
152 * Called with the main_lock locked for writing.
153 */
154 state_change_handler on_stopping;
155 /**
156 * Event handler called when the unicast receive mode is changed.
157 * The implementation is optional. Called with rxc_lock locked for writing.
158 */
159 unicast_mode_change_handler on_unicast_mode_change;
160 /**
161 * Event handler called when the multicast receive mode is changed.
162 * The implementation is optional. Called with rxc_lock locked for writing.
163 */
164 multicast_mode_change_handler on_multicast_mode_change;
165 /**
166 * Event handler called when the broadcast receive mode is changed.
167 * The implementation is optional. Called with rxc_lock locked for writing.
168 */
169 broadcast_mode_change_handler on_broadcast_mode_change;
170 /**
171 * Event handler called when the blocked sources set is changed.
172 * The implementation is optional. Called with rxc_lock locked for writing.
173 */
174 blocked_sources_change_handler on_blocked_sources_change;
175 /**
176 * Event handler called when the VLAN mask is changed.
177 * The implementation is optional. Called with rxc_lock locked for writing.
178 */
179 vlan_mask_change_handler on_vlan_mask_change;
180 /**
181 * Event handler called when a new WOL virtue is added.
182 * The implementation is optional.
183 * Called with filters_lock locked for writing.
184 */
185 wol_virtue_add_handler on_wol_virtue_add;
186 /**
187 * Event handler called when a WOL virtue is removed.
188 * The implementation is optional.
189 * Called with filters_lock locked for writing.
190 */
191 wol_virtue_remove_handler on_wol_virtue_remove;
192 /**
193 * Event handler called when the polling mode is changed.
194 * The implementation is optional.
195 * Called with main_lock locked for writing.
196 */
197 poll_mode_change_handler on_poll_mode_change;
198 /**
199 * Event handler called when the NIC should poll its buffers for a new frame
200 * (in NIC_POLL_PERIODIC or NIC_POLL_ON_DEMAND) modes.
201 * Called with the main_lock locked for reading.
202 * The implementation is optional.
203 */
204 poll_request_handler on_poll_request;
205 /** Data specific for particular driver */
206 void *specific;
207};
208
209/**
210 * Structure keeping global data
211 */
212typedef struct nic_globals {
213 list_t frame_list_cache;
214 size_t frame_list_cache_size;
215 list_t frame_cache;
216 size_t frame_cache_size;
217 fibril_mutex_t lock;
218} nic_globals_t;
219
220#endif
221
222/** @}
223 */
Note: See TracBrowser for help on using the repository browser.