source: mainline/uspace/lib/nic/include/nic_driver.h@ 03cd7a9e

Last change on this file since 03cd7a9e was 03cd7a9e, checked in by Nataliia Korop <n.corop08@…>, 10 months ago

refactoring after 23.10

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