Changeset cf9cb36 in mainline
- Timestamp:
- 2012-01-22T13:41:20Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- eb2efc7
- Parents:
- 8d7ec69d
- Location:
- uspace/lib
- Files:
-
- 1 added
- 16 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/device/nic.c
r8d7ec69d rcf9cb36 345 345 * it can never force the NIC to advertise unsupported modes. 346 346 * 347 * The allowed modes are defined in "n et/eth_phys.h" in the C library.347 * The allowed modes are defined in "nic/eth_phys.h" in the C library. 348 348 * 349 349 * @param[in] dev_sess … … 382 382 /** Probe current state of auto-negotiation. 383 383 * 384 * Modes are defined in the "n et/eth_phys.h" in the C library.384 * Modes are defined in the "nic/eth_phys.h" in the C library. 385 385 * 386 386 * @param[in] dev_sess -
uspace/lib/c/include/device/nic.h
r8d7ec69d rcf9cb36 37 37 38 38 #include <async.h> 39 #include <net/device.h> 40 #include <net/packet.h> 39 #include <nic/nic.h> 41 40 #include <ipc/common.h> 42 #include <ipc/services.h>43 41 44 42 typedef enum { -
uspace/lib/c/include/net/device.h
r8d7ec69d rcf9cb36 1 1 /* 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 * Copyright (c) 2011 Radim Vansa4 3 * All rights reserved. 5 4 * … … 33 32 34 33 /** @file 35 * Device identifier, state and usage statistics.34 * Network device. 36 35 */ 37 36 38 #ifndef LIBC_ DEVICE_ID_TYPE_H_39 #define LIBC_ DEVICE_ID_TYPE_H_37 #ifndef LIBC_NET_DEVICE_H_ 38 #define LIBC_NET_DEVICE_H_ 40 39 41 40 #include <adt/int_map.h> 42 #include <net/eth_phys.h> 43 #include <bool.h> 44 45 /** Ethernet address length. */ 46 #define ETH_ADDR 6 47 48 /** MAC printing format */ 49 #define PRIMAC "%02x:%02x:%02x:%02x:%02x:%02x" 50 51 /** MAC arguments */ 52 #define ARGSMAC(__a) \ 53 (__a)[0], (__a)[1], (__a)[2], (__a)[3], (__a)[4], (__a)[5] 54 55 /* Compare MAC address with specific value */ 56 #define MAC_EQUALS_VALUE(__a, __a0, __a1, __a2, __a3, __a4, __a5) \ 57 ((__a)[0] == (__a0) && (__a)[1] == (__a1) && (__a)[2] == (__a2) \ 58 && (__a)[3] == (__a3) && (__a)[4] == (__a4) && (__a)[5] == (__a5)) 59 60 #define MAC_IS_ZERO(__x) \ 61 MAC_EQUALS_VALUE(__x, 0, 0, 0, 0, 0, 0) 41 #include <nic/nic.h> 62 42 63 43 /** Device identifier to generic type map declaration. */ … … 67 47 #define DEVICE_MAP_IMPLEMENT INT_MAP_IMPLEMENT 68 48 69 /** Max length of any hw nic address (currently only eth) */70 #define NIC_MAX_ADDRESS_LENGTH 1671 72 /** Invalid device identifier. */73 #define NIC_DEVICE_INVALID_ID (-1)74 75 #define NIC_VENDOR_MAX_LENGTH 6476 #define NIC_MODEL_MAX_LENGTH 6477 #define NIC_PART_NUMBER_MAX_LENGTH 6478 #define NIC_SERIAL_NUMBER_MAX_LENGTH 6479 80 #define NIC_DEFECTIVE_LONG 0x000181 #define NIC_DEFECTIVE_SHORT 0x000282 #define NIC_DEFECTIVE_BAD_CRC 0x001083 #define NIC_DEFECTIVE_BAD_IPV4_CHECKSUM 0x002084 #define NIC_DEFECTIVE_BAD_IPV6_CHECKSUM 0x004085 #define NIC_DEFECTIVE_BAD_TCP_CHECKSUM 0x008086 #define NIC_DEFECTIVE_BAD_UDP_CHECKSUM 0x010087 88 /**89 * The bitmap uses single bit for each of the 2^12 = 4096 possible VLAN tags.90 * This means its size is 4096/8 = 512 bytes.91 */92 #define NIC_VLAN_BITMAP_SIZE 51293 94 #define NIC_DEVICE_PRINT_FMT "%x"95 96 /** Device identifier type. */97 typedef int nic_device_id_t;98 99 /**100 * Structure covering the MAC address.101 */102 typedef struct nic_address {103 uint8_t address[ETH_ADDR];104 } nic_address_t;105 106 /** Device state. */107 typedef enum nic_device_state {108 /**109 * Device present and stopped. Moving device to this state means to discard110 * all settings and WOL virtues, rebooting the NIC to state as if the111 * computer just booted (or the NIC was just inserted in case of removable112 * NIC).113 */114 NIC_STATE_STOPPED,115 /**116 * If the NIC is in this state no packets (frames) are transmitted nor117 * received. However, the settings are not restarted. You can use this state118 * to temporarily disable transmition/reception or atomically (with respect119 * to incoming/outcoming packets) change frames acceptance etc.120 */121 NIC_STATE_DOWN,122 /** Device is normally operating. */123 NIC_STATE_ACTIVE,124 /** Just a constant to limit the state numbers */125 NIC_STATE_MAX,126 } nic_device_state_t;127 128 /**129 * Channel operating mode used on the medium.130 */131 typedef enum {132 NIC_CM_UNKNOWN,133 NIC_CM_FULL_DUPLEX,134 NIC_CM_HALF_DUPLEX,135 NIC_CM_SIMPLEX136 } nic_channel_mode_t;137 138 /**139 * Role for the device (used e.g. for 1000Gb ethernet)140 */141 typedef enum {142 NIC_ROLE_UNKNOWN,143 NIC_ROLE_AUTO,144 NIC_ROLE_MASTER,145 NIC_ROLE_SLAVE146 } nic_role_t;147 148 /**149 * Current state of the cable in the device150 */151 typedef enum {152 NIC_CS_UNKNOWN,153 NIC_CS_PLUGGED,154 NIC_CS_UNPLUGGED155 } nic_cable_state_t;156 157 /**158 * Result of the requested operation159 */160 typedef enum {161 /** Successfully disabled */162 NIC_RESULT_DISABLED,163 /** Successfully enabled */164 NIC_RESULT_ENABLED,165 /** Not supported at all */166 NIC_RESULT_NOT_SUPPORTED,167 /** Temporarily not available */168 NIC_RESULT_NOT_AVAILABLE,169 /** Result extensions */170 NIC_RESULT_FIRST_EXTENSION171 } nic_result_t;172 173 /** Device usage statistics. */174 typedef struct nic_device_stats {175 /** Total packets received (accepted). */176 unsigned long receive_packets;177 /** Total packets transmitted. */178 unsigned long send_packets;179 /** Total bytes received (accepted). */180 unsigned long receive_bytes;181 /** Total bytes transmitted. */182 unsigned long send_bytes;183 /** Bad packets received counter. */184 unsigned long receive_errors;185 /** Packet transmition problems counter. */186 unsigned long send_errors;187 /** Number of frames dropped due to insufficient space in RX buffers */188 unsigned long receive_dropped;189 /** Number of frames dropped due to insufficient space in TX buffers */190 unsigned long send_dropped;191 /** Total multicast packets received (accepted). */192 unsigned long receive_multicast;193 /** Total broadcast packets received (accepted). */194 unsigned long receive_broadcast;195 /** The number of collisions due to congestion on the medium. */196 unsigned long collisions;197 /** Unicast packets received but not accepted (filtered) */198 unsigned long receive_filtered_unicast;199 /** Multicast packets received but not accepted (filtered) */200 unsigned long receive_filtered_multicast;201 /** Broadcast packets received but not accepted (filtered) */202 unsigned long receive_filtered_broadcast;203 204 /* detailed receive_errors */205 206 /** Received packet length error counter. */207 unsigned long receive_length_errors;208 /** Receiver buffer overflow counter. */209 unsigned long receive_over_errors;210 /** Received packet with crc error counter. */211 unsigned long receive_crc_errors;212 /** Received frame alignment error counter. */213 unsigned long receive_frame_errors;214 /** Receiver fifo overrun counter. */215 unsigned long receive_fifo_errors;216 /** Receiver missed packet counter. */217 unsigned long receive_missed_errors;218 219 /* detailed send_errors */220 221 /** Transmitter aborted counter. */222 unsigned long send_aborted_errors;223 /** Transmitter carrier errors counter. */224 unsigned long send_carrier_errors;225 /** Transmitter fifo overrun counter. */226 unsigned long send_fifo_errors;227 /** Transmitter carrier errors counter. */228 unsigned long send_heartbeat_errors;229 /** Transmitter window errors counter. */230 unsigned long send_window_errors;231 232 /* for cslip etc */233 234 /** Total compressed packets received. */235 unsigned long receive_compressed;236 /** Total compressed packet transmitted. */237 unsigned long send_compressed;238 } nic_device_stats_t;239 240 /** Errors corresponding to those in the nic_device_stats_t */241 typedef enum {242 NIC_SEC_BUFFER_FULL,243 NIC_SEC_ABORTED,244 NIC_SEC_CARRIER_LOST,245 NIC_SEC_FIFO_OVERRUN,246 NIC_SEC_HEARTBEAT,247 NIC_SEC_WINDOW_ERROR,248 /* Error encountered during TX but with other type of error */249 NIC_SEC_OTHER250 } nic_send_error_cause_t;251 252 /** Errors corresponding to those in the nic_device_stats_t */253 typedef enum {254 NIC_REC_BUFFER_FULL,255 NIC_REC_LENGTH,256 NIC_REC_BUFFER_OVERFLOW,257 NIC_REC_CRC,258 NIC_REC_FRAME_ALIGNMENT,259 NIC_REC_FIFO_OVERRUN,260 NIC_REC_MISSED,261 /* Error encountered during RX but with other type of error */262 NIC_REC_OTHER263 } nic_receive_error_cause_t;264 265 /**266 * Information about the NIC that never changes - name, vendor, model,267 * capabilites and so on.268 */269 typedef struct nic_device_info {270 /* Device identification */271 char vendor_name[NIC_VENDOR_MAX_LENGTH];272 char model_name[NIC_MODEL_MAX_LENGTH];273 char part_number[NIC_PART_NUMBER_MAX_LENGTH];274 char serial_number[NIC_SERIAL_NUMBER_MAX_LENGTH];275 uint16_t vendor_id;276 uint16_t device_id;277 uint16_t subsystem_vendor_id;278 uint16_t subsystem_id;279 /* Device capabilities */280 uint16_t ethernet_support[ETH_PHYS_LAYERS];281 282 /** The mask of all modes which the device can advertise283 *284 * see ETH_AUTONEG_ macros in net/eth_phys.h of libc285 */286 uint32_t autoneg_support;287 } nic_device_info_t;288 289 /**290 * Type of the ethernet frame291 */292 typedef enum nic_frame_type {293 NIC_FRAME_UNICAST,294 NIC_FRAME_MULTICAST,295 NIC_FRAME_BROADCAST296 } nic_frame_type_t;297 298 /**299 * Specifies which unicast frames is the NIC receiving.300 */301 typedef enum nic_unicast_mode {302 NIC_UNICAST_UNKNOWN,303 /** No unicast frames are received */304 NIC_UNICAST_BLOCKED,305 /** Only the frames with this NIC's MAC as destination are received */306 NIC_UNICAST_DEFAULT,307 /**308 * Both frames with this NIC's MAC and those specified in the list are309 * received310 */311 NIC_UNICAST_LIST,312 /** All unicast frames are received */313 NIC_UNICAST_PROMISC314 } nic_unicast_mode_t;315 316 typedef enum nic_multicast_mode {317 NIC_MULTICAST_UNKNOWN,318 /** No multicast frames are received */319 NIC_MULTICAST_BLOCKED,320 /** Frames with multicast addresses specified in this list are received */321 NIC_MULTICAST_LIST,322 /** All multicast frames are received */323 NIC_MULTICAST_PROMISC324 } nic_multicast_mode_t;325 326 typedef enum nic_broadcast_mode {327 NIC_BROADCAST_UNKNOWN,328 /** Broadcast frames are dropped */329 NIC_BROADCAST_BLOCKED,330 /** Broadcast frames are received */331 NIC_BROADCAST_ACCEPTED332 } nic_broadcast_mode_t;333 334 /**335 * Structure covering the bitmap with VLAN tags.336 */337 typedef struct nic_vlan_mask {338 uint8_t bitmap[NIC_VLAN_BITMAP_SIZE];339 } nic_vlan_mask_t;340 341 /* WOL virtue identifier */342 typedef unsigned int nic_wv_id_t;343 344 /**345 * Structure passed as argument for virtue NIC_WV_MAGIC_PACKET.346 */347 typedef struct nic_wv_magic_packet_data {348 uint8_t password[6];349 } nic_wv_magic_packet_data_t;350 351 /**352 * Structure passed as argument for virtue NIC_WV_DIRECTED_IPV4353 */354 typedef struct nic_wv_ipv4_data {355 uint8_t address[4];356 } nic_wv_ipv4_data_t;357 358 /**359 * Structure passed as argument for virtue NIC_WV_DIRECTED_IPV6360 */361 typedef struct nic_wv_ipv6_data {362 uint8_t address[16];363 } nic_wv_ipv6_data_t;364 365 /**366 * WOL virtue types defining the interpretation of data passed to the virtue.367 * Those tagged with S can have only single virtue active at one moment, those368 * tagged with M can have multiple ones.369 */370 typedef enum nic_wv_type {371 /**372 * Used for deletion of the virtue - in this case the mask, data and length373 * arguments are ignored.374 */375 NIC_WV_NONE,376 /** S377 * Enabled <=> wakeup upon link change378 */379 NIC_WV_LINK_CHANGE,380 /** S381 * If this virtue is set up, wakeup can be issued by a magic packet frame.382 * If the data argument is not NULL, it must contain383 * nic_wv_magic_packet_data structure with the SecureOn password.384 */385 NIC_WV_MAGIC_PACKET,386 /** M387 * If the virtue is set up, wakeup can be issued by a frame targeted to388 * device with MAC address specified in data. The data must contain389 * nic_address_t structure.390 */391 NIC_WV_DESTINATION,392 /** S393 * Enabled <=> wakeup upon receiving broadcast frame394 */395 NIC_WV_BROADCAST,396 /** S397 * Enabled <=> wakeup upon receiving ARP Request398 */399 NIC_WV_ARP_REQUEST,400 /** M401 * If enabled, the wakeup is issued upon receiving frame with an IPv4 packet402 * with IPv4 address specified in data. The data must contain403 * nic_wv_ipv4_data structure.404 */405 NIC_WV_DIRECTED_IPV4,406 /** M407 * If enabled, the wakeup is issued upon receiving frame with an IPv4 packet408 * with IPv6 address specified in data. The data must contain409 * nic_wv_ipv6_data structure.410 */411 NIC_WV_DIRECTED_IPV6,412 /** M413 * First length/2 bytes in the argument are interpreted as mask, second414 * length/2 bytes are interpreted as content.415 * If enabled, the wakeup is issued upon receiving frame where the bytes416 * with non-zero value in the mask equal to those in the content.417 */418 NIC_WV_FULL_MATCH,419 /**420 * Dummy value, do not use.421 */422 NIC_WV_MAX423 } nic_wv_type_t;424 425 /**426 * Specifies the interrupt/polling mode used by the driver and NIC427 */428 typedef enum nic_poll_mode {429 /**430 * NIC issues interrupts upon events.431 */432 NIC_POLL_IMMEDIATE,433 /**434 * Some uspace app calls nic_poll_now(...) in order to check the NIC state435 * - no interrupts are received from the NIC.436 */437 NIC_POLL_ON_DEMAND,438 /**439 * The driver itself issues a poll request in a periodic manner. It is440 * allowed to use hardware timer if the NIC supports it.441 */442 NIC_POLL_PERIODIC,443 /**444 * The driver itself issued a poll request in a periodic manner. The driver445 * must create software timer, internal hardware timer of NIC must not be446 * used even if the NIC supports it.447 */448 NIC_POLL_SOFTWARE_PERIODIC449 } nic_poll_mode_t;450 451 /**452 * Says if this virtue type is a multi-virtue (there can be multiple virtues of453 * this type at once).454 *455 * @param type456 *457 * @return true or false458 */459 static inline int nic_wv_is_multi(nic_wv_type_t type) {460 switch (type) {461 case NIC_WV_FULL_MATCH:462 case NIC_WV_DESTINATION:463 case NIC_WV_DIRECTED_IPV4:464 case NIC_WV_DIRECTED_IPV6:465 return true;466 default:467 return false;468 }469 }470 471 static inline const char *nic_device_state_to_string(nic_device_state_t state)472 {473 switch (state) {474 case NIC_STATE_STOPPED:475 return "stopped";476 case NIC_STATE_DOWN:477 return "down";478 case NIC_STATE_ACTIVE:479 return "active";480 default:481 return "undefined";482 }483 }484 485 49 #endif 486 50 -
uspace/lib/c/include/nic/eth_phys.h
r8d7ec69d rcf9cb36 28 28 */ 29 29 30 #ifndef LIBC_N ET_ETH_PHYS_H_31 #define LIBC_N ET_ETH_PHYS_H_30 #ifndef LIBC_NIC_ETH_PHYS_H_ 31 #define LIBC_NIC_ETH_PHYS_H_ 32 32 33 33 #include <sys/types.h> -
uspace/lib/drv/include/ops/nic.h
r8d7ec69d rcf9cb36 38 38 39 39 #include <ipc/services.h> 40 #include <n et/device.h>40 #include <nic/nic.h> 41 41 #include <sys/time.h> 42 42 -
uspace/lib/net/generic/net_checksum.c
r8d7ec69d rcf9cb36 45 45 #define CRC_DIVIDER_LE 0xedb88320 46 46 47 /** Polynomial used in multicast address hashing */48 #define CRC_MCAST_POLYNOMIAL 0x04c11db649 50 47 /** Compacts the computed checksum to the 16 bit number adding the carries. 51 48 * … … 224 221 } 225 222 226 /** Compute the standard hash from MAC227 *228 * Hashing MAC into 64 possible values and using the value as index to229 * 64bit number.230 *231 * The code is copied from qemu-0.13's implementation of ne2000 and rt8139232 * drivers, but according to documentation there it originates in FreeBSD.233 *234 * @param[in] addr The 6-byte MAC address to be hashed235 *236 * @return 64-bit number with only single bit set to 1237 *238 */239 uint64_t multicast_hash(const uint8_t addr[6])240 {241 uint32_t crc;242 int carry, i, j;243 uint8_t b;244 245 crc = 0xffffffff;246 for (i = 0; i < 6; i++) {247 b = addr[i];248 for (j = 0; j < 8; j++) {249 carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01);250 crc <<= 1;251 b >>= 1;252 if (carry)253 crc = ((crc ^ CRC_MCAST_POLYNOMIAL) | carry);254 }255 }256 257 uint64_t one64 = 1;258 return one64 << (crc >> 26);259 }260 261 223 /** @} 262 224 */ -
uspace/lib/net/include/net_checksum.h
r8d7ec69d rcf9cb36 67 67 extern uint16_t flip_checksum(uint16_t); 68 68 extern uint16_t ip_checksum(uint8_t *, size_t); 69 extern uint64_t multicast_hash(const uint8_t addr[6]);70 69 71 70 #endif -
uspace/lib/nic/Makefile
r8d7ec69d rcf9cb36 29 29 USPACE_PREFIX = ../.. 30 30 LIBRARY = libnic 31 LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBNET_PREFIX)/libnet.a 32 EXTRA_CFLAGS += -DLIBNIC_INTERNAL -Iinclude -I$(LIBDRV_PREFIX)/include -I$(LIBNET_PREFIX)/include 31 #LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBNET_PREFIX)/libnet.a 32 EXTRA_CFLAGS += -DLIBNIC_INTERNAL -Iinclude -I$(LIBDRV_PREFIX)/include 33 # -I$(LIBNET_PREFIX)/include 33 34 34 35 SOURCES = \ -
uspace/lib/nic/include/nic_driver.h
r8d7ec69d rcf9cb36 44 44 45 45 #include <fibril_synch.h> 46 #include <n et/device.h>46 #include <nic/nic.h> 47 47 #include <async.h> 48 48 -
uspace/lib/nic/include/nic_ev.h
r8d7ec69d rcf9cb36 40 40 41 41 #include <async.h> 42 /* XXX for nic_device_id_t and nic_address_t */ 43 #include <net/device.h> 42 #include <nic/nic.h> 44 43 #include <sys/types.h> 45 44 -
uspace/lib/nic/include/nic_impl.h
r8d7ec69d rcf9cb36 40 40 41 41 #include <assert.h> 42 #include <n et/device.h>42 #include <nic/nic.h> 43 43 #include <ddf/driver.h> 44 #include <nil_remote.h>45 44 46 45 /* Inclusion of this file is not prohibited, because drivers could want to -
uspace/lib/nic/include/nic_rx_control.h
r8d7ec69d rcf9cb36 45 45 #include <adt/hash_table.h> 46 46 #include <fibril_synch.h> 47 #include <n et/device.h>47 #include <nic/nic.h> 48 48 49 49 #include "nic_addr_db.h" -
uspace/lib/nic/include/nic_wol_virtues.h
r8d7ec69d rcf9cb36 43 43 #endif 44 44 45 #include <n et/device.h>45 #include <nic/nic.h> 46 46 #include <adt/hash_table.h> 47 47 #include "nic.h" -
uspace/lib/nic/src/nic_ev.c
r8d7ec69d rcf9cb36 38 38 #include <async.h> 39 39 #include <device/nic.h> 40 #include <errno.h> 40 41 #include "nic_ev.h" 41 42 -
uspace/lib/nic/src/nic_impl.c
r8d7ec69d rcf9cb36 36 36 */ 37 37 38 #include <errno.h> 38 39 #include <str_error.h> 39 40 #include <ipc/services.h> -
uspace/lib/nic/src/nic_rx_control.c
r8d7ec69d rcf9cb36 40 40 #include <bool.h> 41 41 #include <errno.h> 42 #include <net/device.h> 43 #include <net_checksum.h> 44 #include <packet_client.h> 42 #include <mem.h> 43 #include <nic/nic.h> 45 44 #include "nic_rx_control.h" 46 45 … … 488 487 } 489 488 489 /** Polynomial used in multicast address hashing */ 490 #define CRC_MCAST_POLYNOMIAL 0x04c11db6 491 492 /** Compute the standard hash from MAC 493 * 494 * Hashing MAC into 64 possible values and using the value as index to 495 * 64bit number. 496 * 497 * The code is copied from qemu-0.13's implementation of ne2000 and rt8139 498 * drivers, but according to documentation there it originates in FreeBSD. 499 * 500 * @param[in] addr The 6-byte MAC address to be hashed 501 * 502 * @return 64-bit number with only single bit set to 1 503 * 504 */ 505 static uint64_t multicast_hash(const uint8_t addr[6]) 506 { 507 uint32_t crc; 508 int carry, i, j; 509 uint8_t b; 510 511 crc = 0xffffffff; 512 for (i = 0; i < 6; i++) { 513 b = addr[i]; 514 for (j = 0; j < 8; j++) { 515 carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01); 516 crc <<= 1; 517 b >>= 1; 518 if (carry) 519 crc = ((crc ^ CRC_MCAST_POLYNOMIAL) | carry); 520 } 521 } 522 523 uint64_t one64 = 1; 524 return one64 << (crc >> 26); 525 } 526 527 490 528 /** 491 529 * Computes hash for the address list based on standard multicast address -
uspace/lib/nic/src/nic_wol_virtues.c
r8d7ec69d rcf9cb36 38 38 #include "nic_wol_virtues.h" 39 39 #include <assert.h> 40 #include <errno.h> 40 41 41 42 #define NIC_WV_HASH_COUNT 32
Note:
See TracChangeset
for help on using the changeset viewer.