Changeset 609243f4 in mainline for uspace/lib/c/include/net/device.h
- Timestamp:
- 2011-10-07T15:46:01Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e2c50e1
- Parents:
- f51b1d3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/include/net/device.h
rf51b1d3 r609243f4 1 1 /* 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 * Copyright (c) 2011 Radim Vansa 3 4 * All rights reserved. 4 5 * … … 39 40 40 41 #include <adt/int_map.h> 42 #include <net/eth_phys.h> 43 44 /** Ethernet address length. */ 45 #define ETH_ADDR 6 46 47 /** MAC printing format */ 48 #define PRIMAC "%02x:%02x:%02x:%02x:%02x:%02x" 49 50 /** MAC arguments */ 51 #define ARGSMAC(__a) \ 52 (__a)[0], (__a)[1], (__a)[2], (__a)[3], (__a)[4], (__a)[5] 41 53 42 54 /** Device identifier to generic type map declaration. */ 43 #define DEVICE_MAP_DECLARE 55 #define DEVICE_MAP_DECLARE INT_MAP_DECLARE 44 56 45 57 /** Device identifier to generic type map implementation. */ 46 #define DEVICE_MAP_IMPLEMENT INT_MAP_IMPLEMENT 58 #define DEVICE_MAP_IMPLEMENT INT_MAP_IMPLEMENT 59 60 /** Max length of any hw nic address (currently only eth) */ 61 #define NIC_MAX_ADDRESS_LENGTH 16 47 62 48 63 /** Invalid device identifier. */ 49 #define DEVICE_INVALID_ID (-1) 64 #define NIC_DEVICE_INVALID_ID (-1) 65 66 #define NIC_VENDOR_MAX_LENGTH 64 67 #define NIC_MODEL_MAX_LENGTH 64 68 #define NIC_PART_NUMBER_MAX_LENGTH 64 69 #define NIC_SERIAL_NUMBER_MAX_LENGTH 64 70 71 /** 72 * The bitmap uses single bit for each of the 2^12 = 4096 possible VLAN tags. 73 * This means its size is 4096/8 = 512 bytes. 74 */ 75 #define NIC_VLAN_BITMAP_SIZE 512 76 77 #define NIC_DEVICE_PRINT_FMT "%x" 50 78 51 79 /** Device identifier type. */ 52 typedef int device_id_t; 53 54 /** Device state type. */ 55 typedef enum device_state device_state_t; 56 57 /** Type definition of the device usage statistics. 58 * @see device_stats 59 */ 60 typedef struct device_stats device_stats_t; 80 typedef int nic_device_id_t; 81 82 /** 83 * Structure covering the MAC address. 84 */ 85 typedef struct nic_address { 86 uint8_t address[ETH_ADDR]; 87 } nic_address_t; 61 88 62 89 /** Device state. */ 63 enum device_state { 64 /** Device not present or not initialized. */ 65 NETIF_NULL = 0, 66 /** Device present and stopped. */ 67 NETIF_STOPPED, 68 /** Device present and active. */ 69 NETIF_ACTIVE, 70 /** Device present but unable to transmit. */ 71 NETIF_CARRIER_LOST 72 }; 90 typedef enum nic_device_state { 91 /** 92 * Device present and stopped. Moving device to this state means to discard 93 * all settings and WOL virtues, rebooting the NIC to state as if the 94 * computer just booted (or the NIC was just inserted in case of removable 95 * NIC). 96 */ 97 NIC_STATE_STOPPED, 98 /** 99 * If the NIC is in this state no packets (frames) are transmitted nor 100 * received. However, the settings are not restarted. You can use this state 101 * to temporarily disable transmition/reception or atomically (with respect 102 * to incoming/outcoming packets) change frames acceptance etc. 103 */ 104 NIC_STATE_DOWN, 105 /** Device is normally operating. */ 106 NIC_STATE_ACTIVE, 107 /** Just a constant to limit the state numbers */ 108 NIC_STATE_MAX, 109 } nic_device_state_t; 110 111 /** 112 * Channel operating mode used on the medium. 113 */ 114 typedef enum { 115 NIC_CM_UNKNOWN, 116 NIC_CM_FULL_DUPLEX, 117 NIC_CM_HALF_DUPLEX, 118 NIC_CM_SIMPLEX 119 } nic_channel_mode_t; 120 121 /** 122 * Role for the device (used e.g. for 1000Gb ethernet) 123 */ 124 typedef enum { 125 NIC_ROLE_UNKNOWN, 126 NIC_ROLE_AUTO, 127 NIC_ROLE_MASTER, 128 NIC_ROLE_SLAVE 129 } nic_role_t; 130 131 /** 132 * Current state of the cable in the device 133 */ 134 typedef enum { 135 NIC_CS_UNKNOWN, 136 NIC_CS_PLUGGED, 137 NIC_CS_UNPLUGGED 138 } nic_cable_state_t; 139 140 /** 141 * Result of the requested operation 142 */ 143 typedef enum { 144 /** Successfully disabled */ 145 NIC_RESULT_DISABLED, 146 /** Successfully enabled */ 147 NIC_RESULT_ENABLED, 148 /** Not supported at all */ 149 NIC_RESULT_NOT_SUPPORTED, 150 /** Temporarily not available */ 151 NIC_RESULT_NOT_AVAILABLE, 152 /** Result extensions */ 153 NIC_RESULT_FIRST_EXTENSION 154 } nic_result_t; 73 155 74 156 /** Device usage statistics. */ 75 structdevice_stats {76 /** Total packets received . */157 typedef struct nic_device_stats { 158 /** Total packets received (accepted). */ 77 159 unsigned long receive_packets; 78 160 /** Total packets transmitted. */ 79 161 unsigned long send_packets; 80 /** Total bytes received . */162 /** Total bytes received (accepted). */ 81 163 unsigned long receive_bytes; 82 164 /** Total bytes transmitted. */ … … 86 168 /** Packet transmition problems counter. */ 87 169 unsigned long send_errors; 88 /** N o space in buffers counter.*/170 /** Number of frames dropped due to insufficient space in RX buffers */ 89 171 unsigned long receive_dropped; 90 /** N o space available counter.*/172 /** Number of frames dropped due to insufficient space in TX buffers */ 91 173 unsigned long send_dropped; 92 /** Total multicast packets received. */ 93 unsigned long multicast; 174 /** Total multicast packets received (accepted). */ 175 unsigned long receive_multicast; 176 /** Total broadcast packets received (accepted). */ 177 unsigned long receive_broadcast; 94 178 /** The number of collisions due to congestion on the medium. */ 95 179 unsigned long collisions; 180 /** Unicast packets received but not accepted (filtered) */ 181 unsigned long receive_filtered_unicast; 182 /** Multicast packets received but not accepted (filtered) */ 183 unsigned long receive_filtered_multicast; 184 /** Broadcast packets received but not accepted (filtered) */ 185 unsigned long receive_filtered_broadcast; 96 186 97 187 /* detailed receive_errors */ … … 129 219 /** Total compressed packet transmitted. */ 130 220 unsigned long send_compressed; 131 }; 221 } nic_device_stats_t; 222 223 /** 224 * Information about the NIC that never changes - name, vendor, model, 225 * capabilites and so on. 226 */ 227 typedef struct nic_device_info { 228 /* Device identification */ 229 char vendor_name[NIC_VENDOR_MAX_LENGTH]; 230 char model_name[NIC_MODEL_MAX_LENGTH]; 231 char part_number[NIC_PART_NUMBER_MAX_LENGTH]; 232 char serial_number[NIC_SERIAL_NUMBER_MAX_LENGTH]; 233 uint16_t vendor_id; 234 uint16_t device_id; 235 uint16_t subsystem_vendor_id; 236 uint16_t subsystem_id; 237 /* Device capabilities */ 238 uint16_t ethernet_support[ETH_PHYS_LAYERS]; 239 240 /** The mask of all modes which the device can advertise 241 * 242 * see ETH_AUTONEG_ macros in net/eth_phys.h of libc 243 */ 244 uint32_t autoneg_support; 245 } nic_device_info_t; 246 247 /** 248 * Specifies which unicast frames is the NIC receiving. 249 */ 250 typedef enum nic_unicast_mode { 251 NIC_UNICAST_UNKNOWN, 252 /** No unicast frames are received */ 253 NIC_UNICAST_BLOCKED, 254 /** Only the frames with this NIC's MAC as destination are received */ 255 NIC_UNICAST_DEFAULT, 256 /** 257 * Both frames with this NIC's MAC and those specified in the list are 258 * received 259 */ 260 NIC_UNICAST_LIST, 261 /** All unicast frames are received */ 262 NIC_UNICAST_PROMISC 263 } nic_unicast_mode_t; 264 265 typedef enum nic_multicast_mode { 266 NIC_MULTICAST_UNKNOWN, 267 /** No multicast frames are received */ 268 NIC_MULTICAST_BLOCKED, 269 /** Frames with multicast addresses specified in this list are received */ 270 NIC_MULTICAST_LIST, 271 /** All multicast frames are received */ 272 NIC_MULTICAST_PROMISC 273 } nic_multicast_mode_t; 274 275 typedef enum nic_broadcast_mode { 276 NIC_BROADCAST_UNKNOWN, 277 /** Broadcast frames are dropped */ 278 NIC_BROADCAST_BLOCKED, 279 /** Broadcast frames are received */ 280 NIC_BROADCAST_ACCEPTED 281 } nic_broadcast_mode_t; 282 283 /** 284 * Structure covering the bitmap with VLAN tags. 285 */ 286 typedef struct nic_vlan_mask { 287 uint8_t bitmap[NIC_VLAN_BITMAP_SIZE]; 288 } nic_vlan_mask_t; 289 290 /* WOL virtue identifier */ 291 typedef unsigned int nic_wv_id_t; 292 293 /** 294 * WOL virtue types defining the interpretation of data passed to the virtue. 295 * Those tagged with S can have only single virtue active at one moment, those 296 * tagged with M can have multiple ones. 297 */ 298 typedef enum nic_wv_type { 299 /** 300 * Used for deletion of the virtue - in this case the mask, data and length 301 * arguments are ignored. 302 */ 303 NIC_WV_NONE, 304 /** S 305 * Enabled <=> wakeup upon link change 306 */ 307 NIC_WV_LINK_CHANGE, 308 /** S 309 * If this virtue is set up, wakeup can be issued by a magic packet frame. 310 * If the data argument is not NULL, it must contain 311 * nic_wv_magic_packet_data structure with the SecureOn password. 312 */ 313 NIC_WV_MAGIC_PACKET, 314 /** M 315 * If the virtue is set up, wakeup can be issued by a frame targeted to 316 * device with MAC address specified in data. The data must contain 317 * nic_address_t structure. 318 */ 319 NIC_WV_DESTINATION, 320 /** S 321 * Enabled <=> wakeup upon receiving broadcast frame 322 */ 323 NIC_WV_BROADCAST, 324 /** S 325 * Enabled <=> wakeup upon receiving ARP Request 326 */ 327 NIC_WV_ARP_REQUEST, 328 /** M 329 * If enabled, the wakeup is issued upon receiving frame with an IPv4 packet 330 * with IPv4 address specified in data. The data must contain 331 * nic_wv_ipv4_data structure. 332 */ 333 NIC_WV_DIRECTED_IPV4, 334 /** M 335 * If enabled, the wakeup is issued upon receiving frame with an IPv4 packet 336 * with IPv6 address specified in data. The data must contain 337 * nic_wv_ipv6_data structure. 338 */ 339 NIC_WV_DIRECTED_IPV6, 340 /** M 341 * First length/2 bytes in the argument are interpreted as mask, second 342 * length/2 bytes are interpreted as content. 343 * If enabled, the wakeup is issued upon receiving frame where the bytes 344 * with non-zero value in the mask equal to those in the content. 345 */ 346 NIC_WV_FULL_MATCH, 347 /** 348 * Dummy value, do not use. 349 */ 350 NIC_WV_MAX 351 } nic_wv_type_t; 352 353 /** 354 * Specifies the interrupt/polling mode used by the driver and NIC 355 */ 356 typedef enum nic_poll_mode { 357 /** 358 * NIC issues interrupts upon events. 359 */ 360 NIC_POLL_IMMEDIATE, 361 /** 362 * Some uspace app calls nic_poll_now(...) in order to check the NIC state 363 * - no interrupts are received from the NIC. 364 */ 365 NIC_POLL_ON_DEMAND, 366 /** 367 * The driver itself issues a poll request in a periodic manner. It is 368 * allowed to use hardware timer if the NIC supports it. 369 */ 370 NIC_POLL_PERIODIC, 371 /** 372 * The driver itself issued a poll request in a periodic manner. The driver 373 * must create software timer, internal hardware timer of NIC must not be 374 * used even if the NIC supports it. 375 */ 376 NIC_POLL_SOFTWARE_PERIODIC 377 } nic_poll_mode_t; 378 379 static inline const char *nic_device_state_to_string(nic_device_state_t state) 380 { 381 switch (state) { 382 case NIC_STATE_STOPPED: 383 return "stopped"; 384 case NIC_STATE_DOWN: 385 return "down"; 386 case NIC_STATE_ACTIVE: 387 return "active"; 388 default: 389 return "undefined"; 390 } 391 } 132 392 133 393 #endif
Note:
See TracChangeset
for help on using the changeset viewer.