Changeset a35b458 in mainline for uspace/lib/nic/src
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- Location:
- uspace/lib/nic/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/nic/src/nic_addr_db.c
r3061bc1 ra35b458 68 68 addr_key_t *key = (addr_key_t*)key_arg; 69 69 nic_addr_entry_t *entry = member_to_inst(item, nic_addr_entry_t, link); 70 70 71 71 return memcmp(entry->addr, key->addr, entry->len) == 0; 72 72 } … … 75 75 { 76 76 size_t hash = 0; 77 77 78 78 for (size_t i = 0; i < len; ++i) { 79 79 hash = (hash << 5) ^ addr[i]; 80 80 } 81 81 82 82 return hash; 83 83 } … … 98 98 { 99 99 nic_addr_entry_t *entry = member_to_inst(item, nic_addr_entry_t, link); 100 100 101 101 free(entry); 102 102 } … … 123 123 { 124 124 assert(db); 125 125 126 126 if (addr_len > UCHAR_MAX) 127 127 return EINVAL; 128 128 129 129 if (!hash_table_create(&db->set, 0, 0, &set_ops)) 130 130 return ENOMEM; 131 131 132 132 db->addr_len = addr_len; 133 133 return EOK; … … 176 176 .addr = addr 177 177 }; 178 178 179 179 if (hash_table_find(&db->set, &key)) 180 180 return EEXIST; 181 181 182 182 nic_addr_entry_t *entry = malloc(sizeof(nic_addr_entry_t) + db->addr_len - 1); 183 183 if (entry == NULL) … … 186 186 entry->len = (uint8_t) db->addr_len; 187 187 memcpy(entry->addr, addr, db->addr_len); 188 188 189 189 hash_table_insert(&db->set, &entry->link); 190 190 return EOK; … … 203 203 { 204 204 assert(db && addr); 205 205 206 206 addr_key_t key = { 207 207 .len = db->addr_len, 208 208 .addr = addr 209 209 }; 210 210 211 211 if (hash_table_remove(&db->set, &key)) 212 212 return EOK; … … 226 226 { 227 227 assert(db && addr); 228 228 229 229 addr_key_t key = { 230 230 .len = db->addr_len, 231 231 .addr = addr 232 232 }; 233 233 234 234 return 0 != hash_table_find(&db->set, &key); 235 235 } -
uspace/lib/nic/src/nic_driver.c
r3061bc1 ra35b458 68 68 nic_globals.frame_cache_size = 0; 69 69 fibril_mutex_initialize(&nic_globals.lock); 70 70 71 71 char buffer[256]; 72 72 snprintf(buffer, 256, "drv/" DEVICE_CATEGORY_NIC "/%s", name); 73 73 74 74 return EOK; 75 75 } … … 247 247 ddf_dev_t *dev = nic_data->dev; 248 248 async_sess_t *parent_sess; 249 249 250 250 /* Connect to the parent's driver. */ 251 251 parent_sess = ddf_dev_parent_sess_get(dev); 252 252 if (parent_sess == NULL) 253 253 return EIO; 254 254 255 255 return hw_res_get_list_parsed(parent_sess, resources, 0); 256 256 } … … 277 277 if (!frame) 278 278 return NULL; 279 279 280 280 link_initialize(&frame->link); 281 281 } … … 327 327 nic_frame_list_t *frames; 328 328 fibril_mutex_lock(&nic_globals.lock); 329 329 330 330 if (nic_globals.frame_list_cache_size > 0) { 331 331 frames = … … 338 338 } else { 339 339 fibril_mutex_unlock(&nic_globals.lock); 340 340 341 341 frames = malloc(sizeof (nic_frame_list_t)); 342 342 if (frames != NULL) 343 343 list_initialize(frames); 344 344 } 345 345 346 346 return frames; 347 347 } … … 426 426 { 427 427 assert(nic_data); 428 428 429 429 if (address->address[0] & 1) 430 430 return EINVAL; 431 431 432 432 fibril_rwlock_write_lock(&nic_data->main_lock); 433 433 434 434 /* Notify NIL layer (and uppper) if bound - not in add_device */ 435 435 if (nic_data->client_session != NULL) { … … 442 442 } 443 443 } 444 444 445 445 fibril_rwlock_write_lock(&nic_data->rxc_lock); 446 446 447 447 /* 448 448 * The initial address (all zeroes) shouldn't be … … 452 452 errno_t rc = nic_rxc_set_addr(&nic_data->rx_control, 453 453 &nic_data->mac, address); 454 454 455 455 /* For the first time also record the default MAC */ 456 456 if (MAC_IS_ZERO(nic_data->default_mac.address)) { … … 458 458 memcpy(&nic_data->default_mac, address, sizeof(nic_address_t)); 459 459 } 460 460 461 461 fibril_rwlock_write_unlock(&nic_data->rxc_lock); 462 462 463 463 if ((rc != EOK) && (rc != ENOENT)) { 464 464 fibril_rwlock_write_unlock(&nic_data->main_lock); 465 465 return rc; 466 466 } 467 467 468 468 memcpy(&nic_data->mac, address, sizeof(nic_address_t)); 469 469 470 470 fibril_rwlock_write_unlock(&nic_data->main_lock); 471 471 472 472 return EOK; 473 473 } … … 593 593 if (nic_data == NULL) 594 594 return NULL; 595 595 596 596 /* Force zero to all uninitialized fields (e.g. added in future) */ 597 597 if (nic_rxc_init(&nic_data->rx_control) != EOK) { 598 598 return NULL; 599 599 } 600 600 601 601 if (nic_wol_virtues_init(&nic_data->wol_virtues) != EOK) { 602 602 return NULL; 603 603 } 604 604 605 605 nic_data->dev = NULL; 606 606 nic_data->fun = NULL; … … 614 614 nic_data->on_stopping = NULL; 615 615 nic_data->specific = NULL; 616 616 617 617 fibril_rwlock_initialize(&nic_data->main_lock); 618 618 fibril_rwlock_initialize(&nic_data->stats_lock); 619 619 fibril_rwlock_initialize(&nic_data->rxc_lock); 620 620 fibril_rwlock_initialize(&nic_data->wv_lock); 621 621 622 622 memset(&nic_data->mac, 0, sizeof(nic_address_t)); 623 623 memset(&nic_data->default_mac, 0, sizeof(nic_address_t)); 624 624 memset(&nic_data->stats, 0, sizeof(nic_device_stats_t)); 625 625 626 626 return nic_data; 627 627 } … … 642 642 if (!nic_data) 643 643 return NULL; 644 644 645 645 nic_data->dev = device; 646 646 647 647 return nic_data; 648 648 } … … 943 943 if (count == 0) 944 944 return; 945 945 946 946 fibril_rwlock_write_lock(&nic_data->stats_lock); 947 947 nic_data->stats.send_errors += count; … … 1079 1079 } 1080 1080 async_usleep(wait); 1081 1081 1082 1082 /* Check if the period was not reset */ 1083 1083 if (info->run != run) 1084 1084 break; 1085 1085 } 1086 1086 1087 1087 /* Provide polling if the period finished */ 1088 1088 fibril_rwlock_read_lock(&nic->main_lock); -
uspace/lib/nic/src/nic_impl.c
r3061bc1 ra35b458 195 195 nic_t *nic = nic_get_from_ddf_fun(fun); 196 196 fibril_rwlock_write_lock(&nic->main_lock); 197 197 198 198 nic->client_session = async_callback_receive(EXCHANGE_SERIALIZE); 199 199 if (nic->client_session == NULL) { … … 201 201 return ENOMEM; 202 202 } 203 203 204 204 fibril_rwlock_write_unlock(&nic->main_lock); 205 205 return EOK; -
uspace/lib/nic/src/nic_rx_control.c
r3061bc1 ra35b458 112 112 return rc; 113 113 } 114 114 115 115 return nic_addr_db_insert(&rxc->unicast_addrs, 116 116 (const uint8_t *) &curr_addr->address); … … 244 244 else if (mode != NIC_MULTICAST_LIST && address_list != NULL) 245 245 return EINVAL; 246 246 247 247 if (rxc->multicast_mode == NIC_MULTICAST_LIST) 248 248 nic_addr_db_clear(&rxc->multicast_addrs); 249 249 250 250 rxc->multicast_mode = mode; 251 251 size_t i; … … 439 439 } 440 440 } 441 441 442 442 /* Blocked source addresses */ 443 443 if (rxc->block_sources) { … … 445 445 return false; 446 446 } 447 447 448 448 /* VLAN filtering */ 449 449 if (!rxc->vlan_exact && rxc->vlan_mask != NULL) { … … 459 459 } 460 460 } 461 461 462 462 return true; 463 463 } … … 519 519 } 520 520 } 521 521 522 522 uint64_t one64 = 1; 523 523 return one64 << (crc >> 26); -
uspace/lib/nic/src/nic_wol_virtues.c
r3061bc1 ra35b458 79 79 wvs->table_operations.equal = 0; 80 80 wvs->table_operations.remove_callback = 0; 81 81 82 82 if (!hash_table_create(&wvs->table, 0, 0, &wvs->table_operations)) { 83 83 return ENOMEM;
Note:
See TracChangeset
for help on using the changeset viewer.