source: mainline/uspace/lib/nic/include/nic.h@ a270026

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

small typos and ccheck

  • Property mode set to 100644
File size: 10.0 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 Public header exposing NICF to drivers
36 */
37
38#ifndef __NIC_H__
39#define __NIC_H__
40
41#include <adt/list.h>
42#include <adt/hash_table.h>
43#include <ddf/driver.h>
44#include <device/hw_res_parsed.h>
45#include <ops/nic.h>
46
47#include "pcap_iface.h"
48
49#define DEVICE_CATEGORY_NIC "nic"
50
51struct nic;
52typedef struct nic nic_t;
53
54/**
55 * Single WOL virtue descriptor.
56 */
57typedef struct nic_wol_virtue {
58 ht_link_t item;
59 nic_wv_id_t id;
60 nic_wv_type_t type;
61 void *data;
62 size_t length;
63 struct nic_wol_virtue *next;
64} nic_wol_virtue_t;
65
66/**
67 * Simple structure for sending lists of frames.
68 */
69typedef struct {
70 link_t link;
71 void *data;
72 size_t size;
73} nic_frame_t;
74
75typedef list_t nic_frame_list_t;
76
77/**
78 * Handler for writing frame data to the NIC device.
79 * The function is responsible for releasing the frame.
80 * It does not return anything, if some error is detected the function just
81 * silently fails (logging on debug level is suggested).
82 *
83 * @param nic_data
84 * @param data Pointer to frame data
85 * @param size Size of frame data in bytes
86 */
87typedef void (*send_frame_handler)(nic_t *, void *, size_t);
88
89/**
90 * The handler for transitions between driver states.
91 * If the handler returns error code, the transition between
92 * states is canceled (the state is not changed).
93 *
94 * @param nic_data NICF main structure
95 *
96 * @return EOK If everything is all right.
97 * @return error code on error.
98 */
99typedef errno_t (*state_change_handler)(nic_t *);
100
101/**
102 * Handler for unicast filtering mode change.
103 *
104 * @param nic_data NICF main structure
105 * @param new_mode The mode that should be set up
106 * @param address_list Addresses as argument to the mode
107 * @param address_count Number of addresses in the list
108 *
109 * @return EOK If the mode is set up
110 * @return ENOTSUP If this mode is not supported
111 */
112typedef errno_t (*unicast_mode_change_handler)(nic_t *,
113 nic_unicast_mode_t, const nic_address_t *, size_t);
114
115/**
116 * Handler for multicast filtering mode change.
117 *
118 * @param nic_data NICF main structure
119 * @param new_mode The mode that should be set up
120 * @param address_list Addresses as argument to the mode
121 * @param address_count Number of addresses in the list
122 *
123 * @return EOK If the mode is set up
124 * @return ENOTSUP If this mode is not supported
125 */
126typedef errno_t (*multicast_mode_change_handler)(nic_t *,
127 nic_multicast_mode_t, const nic_address_t *, size_t);
128
129/**
130 * Handler for broadcast filtering mode change.
131 *
132 * @param nic_data NICF main structure
133 * @param new_mode The mode that should be set up
134 *
135 * @return EOK If the mode is set up
136 * @return ENOTSUP If this mode is not supported
137 */
138typedef errno_t (*broadcast_mode_change_handler)(nic_t *, nic_broadcast_mode_t);
139
140/**
141 * Handler for blocked sources list change.
142 *
143 * @param nic_data NICF main structure
144 * @param address_list Addresses as argument to the mode
145 * @param address_count Number of addresses in the list
146 */
147typedef void (*blocked_sources_change_handler)(nic_t *,
148 const nic_address_t *, size_t);
149
150/**
151 * Handler for VLAN filtering mask change.
152 * @param nic_data NICF main structure
153 * @param vlan_mask The new mask | NULL for disabling vlan filter
154 */
155typedef void (*vlan_mask_change_handler)(nic_t *, const nic_vlan_mask_t *);
156
157/**
158 * Handler called when a WOL virtue is added.
159 * If the maximum of accepted WOL virtues changes due to adding this virtue
160 * you should update the vector wol_virtues.caps_max.
161 * The driver is allowed to store pointer to the virtue data until
162 * on_wol_virtue_remove on these data is called (although probably this is
163 * not a good practice).
164 *
165 * @param nic_data NICF main structure
166 * @param virtue Structure with virtue description
167 *
168 * @return EOK If the filter can be used. Software emulation of the
169 * filter is activated unless the emulate is set to 0.
170 * @return ENOTSUP If this filter cannot work on this NIC (e.g. the NIC
171 * cannot run in promiscuous node or the limit of WOL
172 * frames' specifications was reached).
173 * @return ELIMIT If this filter must implemented in HW but currently the
174 * limit of these HW filters was reached.
175 */
176typedef errno_t (*wol_virtue_add_handler)(nic_t *, const nic_wol_virtue_t *);
177
178/**
179 * Handler called when a WOL virtue is removed.
180 * If the maximum of accepted WOL virtues changes due to removing this
181 * virtue you should update the vector wol_virtues.caps_max.
182 *
183 * @param nic_data NICF main structure
184 * @param virtue Structure with virtue description
185 */
186typedef void (*wol_virtue_remove_handler)(nic_t *, const nic_wol_virtue_t *);
187
188/**
189 * Handler for poll mode change.
190 *
191 * @param nic_data NICF main structure
192 * @param mode Mode to be set up
193 * @param period New period of polling (with NIC_POLL_PERIODIC)
194 *
195 * @return EOK If the mode was fully setup
196 * @return ENOTSUP If NICF should do the periodic polling
197 * @return EINVAL If this mode cannot be set up under no circumstances
198 */
199typedef errno_t (*poll_mode_change_handler)(nic_t *,
200 nic_poll_mode_t, const struct timespec *);
201
202/**
203 * Event handler called when the NIC should poll its buffers for a new frame
204 * (in NIC_POLL_PERIODIC or NIC_POLL_ON_DEMAND) modes.
205 *
206 * @param nic_data NICF main structure
207 */
208typedef void (*poll_request_handler)(nic_t *);
209
210/* nic_t allocation and deallocation */
211extern nic_t *nic_create_and_bind(ddf_dev_t *);
212extern void nic_unbind_and_destroy(ddf_dev_t *);
213
214/* Functions called in the main function */
215extern errno_t nic_driver_init(const char *);
216extern void nic_driver_implement(driver_ops_t *, ddf_dev_ops_t *,
217 nic_iface_t *);
218
219/* Functions called in add_device */
220extern errno_t nic_get_resources(nic_t *, hw_res_list_parsed_t *);
221extern void nic_set_specific(nic_t *, void *);
222extern void nic_set_send_frame_handler(nic_t *, send_frame_handler);
223extern void nic_set_state_change_handlers(nic_t *,
224 state_change_handler, state_change_handler, state_change_handler);
225extern void nic_set_filtering_change_handlers(nic_t *,
226 unicast_mode_change_handler, multicast_mode_change_handler,
227 broadcast_mode_change_handler, blocked_sources_change_handler,
228 vlan_mask_change_handler);
229extern void nic_set_wol_virtue_change_handlers(nic_t *,
230 wol_virtue_add_handler, wol_virtue_remove_handler);
231extern void nic_set_poll_handlers(nic_t *,
232 poll_mode_change_handler, poll_request_handler);
233
234/* General driver functions */
235extern ddf_dev_t *nic_get_ddf_dev(nic_t *);
236extern ddf_fun_t *nic_get_ddf_fun(nic_t *);
237extern void nic_set_ddf_fun(nic_t *, ddf_fun_t *);
238extern nic_t *nic_get_from_ddf_dev(ddf_dev_t *);
239extern nic_t *nic_get_from_ddf_fun(ddf_fun_t *);
240extern void *nic_get_specific(nic_t *);
241extern nic_device_state_t nic_query_state(nic_t *);
242extern void nic_set_tx_busy(nic_t *, int);
243extern errno_t nic_report_address(nic_t *, const nic_address_t *);
244extern errno_t nic_report_poll_mode(nic_t *, nic_poll_mode_t, struct timespec *);
245extern void nic_query_address(nic_t *, nic_address_t *);
246extern void nic_received_frame(nic_t *, nic_frame_t *);
247extern void nic_received_frame_list(nic_t *, nic_frame_list_t *);
248extern nic_poll_mode_t nic_query_poll_mode(nic_t *, struct timespec *);
249
250/* Statistics updates */
251extern void nic_report_send_ok(nic_t *, size_t, size_t);
252extern void nic_report_send_error(nic_t *, nic_send_error_cause_t, unsigned);
253extern void nic_report_receive_error(nic_t *, nic_receive_error_cause_t,
254 unsigned);
255extern void nic_report_collisions(nic_t *, unsigned);
256
257/* Frame / frame list allocation and deallocation */
258extern nic_frame_t *nic_alloc_frame(nic_t *, size_t);
259extern nic_frame_list_t *nic_alloc_frame_list(void);
260extern void nic_frame_list_append(nic_frame_list_t *, nic_frame_t *);
261extern void nic_release_frame(nic_t *, nic_frame_t *);
262
263/* RXC query and report functions */
264extern void nic_report_hw_filtering(nic_t *, int, int, int);
265extern void nic_query_unicast(const nic_t *,
266 nic_unicast_mode_t *, size_t, nic_address_t *, size_t *);
267extern void nic_query_multicast(const nic_t *,
268 nic_multicast_mode_t *, size_t, nic_address_t *, size_t *);
269extern void nic_query_broadcast(const nic_t *, nic_broadcast_mode_t *);
270extern void nic_query_blocked_sources(const nic_t *,
271 size_t, nic_address_t *, size_t *);
272extern errno_t nic_query_vlan_mask(const nic_t *, nic_vlan_mask_t *);
273extern int nic_query_wol_max_caps(const nic_t *, nic_wv_type_t);
274extern void nic_set_wol_max_caps(nic_t *, nic_wv_type_t, int);
275extern uint64_t nic_mcast_hash(const nic_address_t *, size_t);
276extern uint64_t nic_query_mcast_hash(nic_t *);
277
278/* Software period functions */
279extern void nic_sw_period_start(nic_t *);
280extern void nic_sw_period_stop(nic_t *);
281
282/* pcapdump interface */
283extern pcap_iface_t *nic_get_pcap_iface(nic_t *);
284
285#endif // __NIC_H__
286
287/** @}
288 */
Note: See TracBrowser for help on using the repository browser.