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