Changeset a35b458 in mainline for uspace/drv/nic
- Timestamp:
- 2018-03-02T20:10:49Z (8 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/drv/nic
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/ar9271/ar9271.c
r3061bc1 ra35b458 148 148 assert(dev); 149 149 assert(info); 150 150 151 151 memset(info, 0, sizeof(nic_device_info_t)); 152 152 153 153 info->vendor_id = 0x0cf3; 154 154 info->device_id = 0x9271; … … 157 157 str_cpy(info->model_name, NIC_MODEL_MAX_LENGTH, 158 158 "AR9271"); 159 159 160 160 return EOK; 161 161 } … … 167 167 { 168 168 *state = NIC_CS_PLUGGED; 169 169 170 170 return EOK; 171 171 } … … 180 180 *speed = 10; 181 181 *role = NIC_ROLE_UNKNOWN; 182 182 183 183 return EOK; 184 184 } … … 203 203 return ENOTSUP; 204 204 } 205 205 206 206 return EOK; 207 207 } … … 229 229 return ENOTSUP; 230 230 } 231 231 232 232 return EOK; 233 233 } … … 249 249 return ENOTSUP; 250 250 } 251 251 252 252 return EOK; 253 253 } … … 261 261 { 262 262 assert(arg); 263 263 264 264 ar9271_t *ar9271 = (ar9271_t *) arg; 265 265 266 266 size_t buffer_size = ar9271->ath_device->data_response_length; 267 267 void *buffer = malloc(buffer_size); 268 268 269 269 while (true) { 270 270 size_t transferred_size; … … 275 275 sizeof(htc_frame_header_t) + 276 276 sizeof(htc_rx_status_t); 277 277 278 278 if (transferred_size < strip_length) 279 279 continue; 280 280 281 281 ath_usb_data_header_t *data_header = 282 282 (ath_usb_data_header_t *) buffer; 283 283 284 284 /* Invalid packet. */ 285 285 if (data_header->tag != uint16_t_le2host(RX_TAG)) 286 286 continue; 287 287 288 288 htc_rx_status_t *rx_status = 289 289 (htc_rx_status_t *) ((void *) buffer + 290 290 sizeof(ath_usb_data_header_t) + 291 291 sizeof(htc_frame_header_t)); 292 292 293 293 uint16_t data_length = 294 294 uint16_t_be2host(rx_status->data_length); 295 295 296 296 int16_t payload_length = 297 297 transferred_size - strip_length; 298 298 299 299 if (payload_length - data_length < 0) 300 300 continue; 301 301 302 302 if (ar9271_rx_status_error(rx_status->status)) 303 303 continue; 304 304 305 305 void *strip_buffer = buffer + strip_length; 306 306 307 307 ieee80211_rx_handler(ar9271->ieee80211_dev, 308 308 strip_buffer, … … 310 310 } 311 311 } 312 312 313 313 free(buffer); 314 314 315 315 return EOK; 316 316 } … … 323 323 { 324 324 assert(ieee80211_dev); 325 325 326 326 ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev); 327 327 328 328 wmi_send_command(ar9271->htc_device, WMI_DISABLE_INTR, NULL, 0, NULL); 329 329 wmi_send_command(ar9271->htc_device, WMI_DRAIN_TXQ_ALL, NULL, 0, NULL); 330 330 wmi_send_command(ar9271->htc_device, WMI_STOP_RECV, NULL, 0, NULL); 331 331 332 332 errno_t rc = hw_freq_switch(ar9271, freq); 333 333 if (rc != EOK) { … … 335 335 return rc; 336 336 } 337 337 338 338 wmi_send_command(ar9271->htc_device, WMI_START_RECV, NULL, 0, NULL); 339 339 340 340 rc = hw_rx_init(ar9271); 341 341 if (rc != EOK) { … … 343 343 return rc; 344 344 } 345 345 346 346 uint16_t htc_mode = host2uint16_t_be(1); 347 347 wmi_send_command(ar9271->htc_device, WMI_SET_MODE, 348 348 (uint8_t *) &htc_mode, sizeof(htc_mode), NULL); 349 349 wmi_send_command(ar9271->htc_device, WMI_ENABLE_INTR, NULL, 0, NULL); 350 350 351 351 return EOK; 352 352 } … … 356 356 { 357 357 assert(ieee80211_dev); 358 358 359 359 ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev); 360 360 361 361 if (connected) { 362 362 nic_address_t bssid; 363 363 ieee80211_query_bssid(ieee80211_dev, &bssid); 364 364 365 365 htc_sta_msg_t sta_msg; 366 366 memset(&sta_msg, 0, sizeof(htc_sta_msg_t)); … … 371 371 sta_msg.vif_index = 0; 372 372 memcpy(&sta_msg.addr, bssid.address, ETH_ADDR); 373 373 374 374 wmi_send_command(ar9271->htc_device, WMI_NODE_CREATE, 375 375 (uint8_t *) &sta_msg, sizeof(sta_msg), NULL); 376 376 377 377 htc_rate_msg_t rate_msg; 378 378 memset(&rate_msg, 0, sizeof(htc_rate_msg_t)); … … 383 383 ieee80211bg_data_rates, 384 384 ARRAY_SIZE(ieee80211bg_data_rates)); 385 385 386 386 wmi_send_command(ar9271->htc_device, WMI_RC_RATE_UPDATE, 387 387 (uint8_t *) &rate_msg, sizeof(rate_msg), NULL); 388 388 389 389 hw_set_rx_filter(ar9271, true); 390 390 } else { … … 392 392 wmi_send_command(ar9271->htc_device, WMI_NODE_REMOVE, 393 393 &station_id, sizeof(station_id), NULL); 394 394 395 395 hw_set_rx_filter(ar9271, false); 396 396 } 397 397 398 398 hw_set_bssid(ar9271); 399 399 400 400 return EOK; 401 401 } … … 405 405 { 406 406 assert(ieee80211_dev); 407 407 408 408 ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev); 409 409 410 410 if(insert) { 411 411 assert(key_conf); 412 412 413 413 uint32_t key[5]; 414 414 uint32_t key_type; 415 415 uint32_t reg_ptr, mic_reg_ptr; 416 416 void *data_start; 417 417 418 418 nic_address_t bssid; 419 419 ieee80211_query_bssid(ieee80211_dev, &bssid); 420 420 421 421 switch (key_conf->suite) { 422 422 case IEEE80211_SECURITY_SUITE_WEP40: … … 435 435 key_type = -1; 436 436 } 437 437 438 438 uint8_t key_id = 439 439 (key_conf->flags & IEEE80211_KEY_FLAG_TYPE_PAIRWISE) ? 440 440 AR9271_STA_KEY_INDEX : key_conf->id; 441 441 442 442 reg_ptr = AR9271_KEY_TABLE(key_id); 443 443 mic_reg_ptr = AR9271_KEY_TABLE(key_id + 64); 444 444 data_start = (void *) key_conf->data; 445 445 446 446 key[0] = uint32_t_le2host(*((uint32_t *) data_start)); 447 447 key[1] = uint16_t_le2host(*((uint16_t *) (data_start + 4))); … … 449 449 key[3] = uint16_t_le2host(*((uint16_t *) (data_start + 10))); 450 450 key[4] = uint32_t_le2host(*((uint32_t *) (data_start + 12))); 451 451 452 452 if ((key_conf->suite == IEEE80211_SECURITY_SUITE_WEP40) || 453 453 (key_conf->suite == IEEE80211_SECURITY_SUITE_WEP104)) 454 454 key[4] &= 0xFF; 455 455 456 456 wmi_reg_write(ar9271->htc_device, reg_ptr + 0, key[0]); 457 457 wmi_reg_write(ar9271->htc_device, reg_ptr + 4, key[1]); … … 460 460 wmi_reg_write(ar9271->htc_device, reg_ptr + 16, key[4]); 461 461 wmi_reg_write(ar9271->htc_device, reg_ptr + 20, key_type); 462 462 463 463 uint32_t macl; 464 464 uint32_t mach; … … 471 471 mach = 0; 472 472 } 473 473 474 474 macl >>= 1; 475 475 macl |= (mach & 1) << 31; 476 476 mach >>= 1; 477 477 mach |= 0x8000; 478 478 479 479 wmi_reg_write(ar9271->htc_device, reg_ptr + 24, macl); 480 480 wmi_reg_write(ar9271->htc_device, reg_ptr + 28, mach); 481 481 482 482 /* Setup MIC keys for TKIP. */ 483 483 if (key_conf->suite == IEEE80211_SECURITY_SUITE_TKIP) { … … 485 485 uint8_t *gen_mic = data_start + IEEE80211_TKIP_RX_MIC_OFFSET; 486 486 uint8_t *tx_mic; 487 487 488 488 if (key_conf->flags & IEEE80211_KEY_FLAG_TYPE_GROUP) 489 489 tx_mic = gen_mic; 490 490 else 491 491 tx_mic = data_start + IEEE80211_TKIP_TX_MIC_OFFSET; 492 492 493 493 mic[0] = uint32_t_le2host(*((uint32_t *) gen_mic)); 494 494 mic[1] = uint16_t_le2host(*((uint16_t *) (tx_mic + 2))) & 0xFFFF; … … 496 496 mic[3] = uint16_t_le2host(*((uint16_t *) tx_mic)) & 0xFFFF; 497 497 mic[4] = uint32_t_le2host(*((uint32_t *) (tx_mic + 4))); 498 498 499 499 wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 0, mic[0]); 500 500 wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 4, mic[1]); … … 504 504 wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 20, 505 505 AR9271_KEY_TABLE_TYPE_CLR); 506 506 507 507 wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 24, 0); 508 508 wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 28, 0); 509 509 } 510 510 511 511 if (key_conf->flags & IEEE80211_KEY_FLAG_TYPE_GROUP) 512 512 ieee80211_setup_key_confirm(ieee80211_dev, true); … … 515 515 ieee80211_setup_key_confirm(ieee80211_dev, false); 516 516 } 517 517 518 518 return EOK; 519 519 } … … 523 523 { 524 524 assert(ieee80211_dev); 525 525 526 526 size_t complete_size; 527 527 size_t offset; 528 528 void *complete_buffer; 529 529 int endpoint; 530 530 531 531 ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev); 532 532 533 533 uint16_t frame_ctrl = *((uint16_t *) buffer); 534 534 if (ieee80211_is_data_frame(frame_ctrl)) { … … 538 538 complete_buffer = malloc(complete_size); 539 539 memset(complete_buffer, 0, complete_size); 540 540 541 541 /* 542 542 * Because we handle just station mode yet, node ID and VIF ID … … 550 550 data_header->vif_idx = 0; 551 551 data_header->cookie = 0; 552 552 553 553 if (ieee80211_query_using_key(ieee80211_dev)) { 554 554 data_header->keyix = AR9271_STA_KEY_INDEX; 555 555 556 556 int sec_suite = 557 557 ieee80211_get_pairwise_security(ieee80211_dev); 558 558 559 559 switch (sec_suite) { 560 560 case IEEE80211_SECURITY_SUITE_WEP40: … … 573 573 data_header->keyix = 0xFF; 574 574 } 575 575 576 576 endpoint = ar9271->htc_device->endpoints.data_be_endpoint; 577 577 } else { … … 581 581 complete_buffer = malloc(complete_size); 582 582 memset(complete_buffer, 0, complete_size); 583 583 584 584 /* 585 585 * Because we handle just station mode yet, node ID and VIF ID … … 593 593 mgmt_header->cookie = 0; 594 594 mgmt_header->keyix = 0xFF; 595 595 596 596 endpoint = ar9271->htc_device->endpoints.mgmt_endpoint; 597 597 } 598 598 599 599 /* Copy IEEE802.11 data to new allocated buffer with HTC headers. */ 600 600 memcpy(complete_buffer + offset, buffer, buffer_size); 601 601 602 602 htc_send_data_message(ar9271->htc_device, complete_buffer, 603 603 complete_size, endpoint); 604 604 605 605 free(complete_buffer); 606 606 607 607 return EOK; 608 608 } … … 611 611 { 612 612 assert(ieee80211_dev); 613 613 614 614 ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev); 615 615 616 616 wmi_send_command(ar9271->htc_device, WMI_FLUSH_RECV, NULL, 0, NULL); 617 617 618 618 errno_t rc = hw_reset(ar9271); 619 619 if (rc != EOK) { … … 621 621 return rc; 622 622 } 623 623 624 624 uint16_t htc_mode = host2uint16_t_be(1); 625 625 wmi_send_command(ar9271->htc_device, WMI_SET_MODE, … … 628 628 wmi_send_command(ar9271->htc_device, WMI_START_RECV, NULL, 0, NULL); 629 629 wmi_send_command(ar9271->htc_device, WMI_ENABLE_INTR, NULL, 0, NULL); 630 630 631 631 rc = hw_rx_init(ar9271); 632 632 if (rc != EOK) { … … 634 634 return rc; 635 635 } 636 636 637 637 /* Send capability message to target. */ 638 638 htc_cap_msg_t cap_msg; … … 641 641 cap_msg.enable_coex = 0; 642 642 cap_msg.tx_chainmask = 0x1; 643 643 644 644 wmi_send_command(ar9271->htc_device, WMI_TARGET_IC_UPDATE, 645 645 (uint8_t *) &cap_msg, sizeof(cap_msg), NULL); 646 646 647 647 rc = htc_init_new_vif(ar9271->htc_device); 648 648 if (rc != EOK) { … … 650 650 return rc; 651 651 } 652 652 653 653 /* Add data polling fibril. */ 654 654 fid_t fibril = fibril_create(ar9271_data_polling, ar9271); 655 655 if (fibril == 0) 656 656 return ENOMEM; 657 657 658 658 fibril_add_ready(fibril); 659 659 660 660 ar9271->starting_up = false; 661 661 ieee80211_set_ready(ieee80211_dev, true); 662 662 663 663 usb_log_info("Device fully initialized.\n"); 664 664 665 665 return EOK; 666 666 } … … 670 670 ar9271->starting_up = true; 671 671 ar9271->usb_device = usb_device; 672 672 673 673 fibril_mutex_initialize(&ar9271->ar9271_lock); 674 674 675 675 ar9271->ath_device = calloc(1, sizeof(ath_t)); 676 676 if (!ar9271->ath_device) { … … 679 679 return ENOMEM; 680 680 } 681 681 682 682 errno_t rc = ath_usb_init(ar9271->ath_device, usb_device, endpoints); 683 683 if (rc != EOK) { … … 686 686 return rc; 687 687 } 688 688 689 689 /* IEEE 802.11 framework structure initialization. */ 690 690 ar9271->ieee80211_dev = ieee80211_device_create(); … … 695 695 return ENOMEM; 696 696 } 697 697 698 698 rc = ieee80211_device_init(ar9271->ieee80211_dev, ar9271->ddf_dev); 699 699 if (rc != EOK) { … … 704 704 return rc; 705 705 } 706 706 707 707 ieee80211_set_specific(ar9271->ieee80211_dev, ar9271); 708 708 709 709 /* HTC device structure initialization. */ 710 710 ar9271->htc_device = calloc(1, sizeof(htc_device_t)); … … 716 716 return ENOMEM; 717 717 } 718 718 719 719 rc = htc_device_init(ar9271->ath_device, ar9271->ieee80211_dev, 720 720 ar9271->htc_device); … … 726 726 return rc; 727 727 } 728 728 729 729 return EOK; 730 730 } … … 740 740 { 741 741 usb_device_t *usb_device = ar9271->usb_device; 742 742 743 743 /* TODO: Set by maximum packet size in pipe. */ 744 744 static const size_t MAX_TRANSFER_SIZE = 512; 745 745 746 746 /* Load FW from file. */ 747 747 FILE *fw_file = fopen(FIRMWARE_FILENAME, "rb"); … … 750 750 return ENOENT; 751 751 } 752 752 753 753 fseek(fw_file, 0, SEEK_END); 754 754 uint64_t file_size = ftell(fw_file); 755 755 fseek(fw_file, 0, SEEK_SET); 756 756 757 757 void *fw_data = malloc(file_size); 758 758 if (fw_data == NULL) { … … 761 761 return ENOMEM; 762 762 } 763 763 764 764 fread(fw_data, file_size, 1, fw_file); 765 765 fclose(fw_file); 766 766 767 767 /* Upload FW to device. */ 768 768 uint64_t remain_size = file_size; … … 770 770 uint8_t *current_data = fw_data; 771 771 uint8_t *buffer = malloc(MAX_TRANSFER_SIZE); 772 772 773 773 while (remain_size > 0) { 774 774 size_t chunk_size = min(remain_size, MAX_TRANSFER_SIZE); … … 788 788 return rc; 789 789 } 790 790 791 791 remain_size -= chunk_size; 792 792 current_addr += chunk_size; 793 793 current_data += chunk_size; 794 794 } 795 795 796 796 free(fw_data); 797 797 free(buffer); 798 798 799 799 /* 800 800 * Send command that firmware is successfully uploaded. … … 809 809 uint16_host2usb(AR9271_FW_OFFSET >> 8), 810 810 0, NULL, 0); 811 811 812 812 if (rc != EOK) { 813 813 usb_log_error("IO error when sending fw upload confirmation " … … 815 815 return rc; 816 816 } 817 817 818 818 usb_log_info("Firmware uploaded successfully.\n"); 819 819 820 820 /* Wait until firmware is ready - wait for 1 second to be sure. */ 821 821 async_sleep(1); 822 822 823 823 return rc; 824 824 } … … 840 840 return NULL; 841 841 } 842 842 843 843 /* AR9271 structure initialization. */ 844 844 ar9271_t *ar9271 = calloc(1, sizeof(ar9271_t)); … … 848 848 return NULL; 849 849 } 850 850 851 851 ar9271->ddf_dev = dev; 852 852 853 853 rc = ar9271_init(ar9271, usb_device_get(dev), endpoints); 854 854 if (rc != EOK) { … … 858 858 return NULL; 859 859 } 860 860 861 861 return ar9271; 862 862 } … … 869 869 { 870 870 assert(ar9271); 871 871 872 872 // TODO 873 873 } … … 882 882 { 883 883 assert(dev); 884 884 885 885 /* Allocate driver data for the device. */ 886 886 ar9271_t *ar9271 = ar9271_create_dev_data(dev); … … 889 889 return ENOMEM; 890 890 } 891 891 892 892 usb_log_info("HelenOS AR9271 device initialized.\n"); 893 893 894 894 /* Upload AR9271 firmware. */ 895 895 ar9271_upload_fw(ar9271); 896 896 897 897 /* Initialize AR9271 HTC services. */ 898 898 errno_t rc = htc_init(ar9271->htc_device); … … 902 902 return rc; 903 903 } 904 904 905 905 /* Initialize AR9271 HW. */ 906 906 rc = hw_init(ar9271); … … 910 910 return rc; 911 911 } 912 912 913 913 /* Initialize AR9271 IEEE 802.11 framework. */ 914 914 rc = ieee80211_init(ar9271->ieee80211_dev, &ar9271_ieee80211_ops, … … 920 920 return rc; 921 921 } 922 922 923 923 nic_set_filtering_change_handlers(nic_get_from_ddf_dev(dev), 924 924 ar9271_on_unicast_mode_change, ar9271_on_multicast_mode_change, 925 925 ar9271_on_broadcast_mode_change, NULL, NULL); 926 926 927 927 usb_log_info("HelenOS AR9271 added device.\n"); 928 928 929 929 return EOK; 930 930 } … … 933 933 { 934 934 log_init(NAME); 935 935 936 936 if (nic_driver_init(NAME) != EOK) 937 937 return 1; 938 938 939 939 usb_log_info("HelenOS AR9271 driver started.\n"); 940 940 941 941 return ddf_driver_main(&ar9271_driver); 942 942 } -
uspace/drv/nic/ar9271/ar9271.h
r3061bc1 ra35b458 69 69 AR9271_COMMAND = 0x0008, 70 70 AR9271_COMMAND_RX_ENABLE = 0x00000004, 71 71 72 72 /* ATH config register */ 73 73 AR9271_CONFIG = 0x0014, 74 74 AR9271_CONFIG_ADHOC = 0x00000020, 75 75 76 76 AR9271_QUEUE_BASE_MASK = 0x1000, 77 77 78 78 /* EEPROM Addresses */ 79 79 AR9271_EEPROM_BASE = 0x2100, 80 80 AR9271_EEPROM_MAC_ADDR_START = 0x2118, 81 81 82 82 /* Reset MAC interface */ 83 83 AR9271_RC = 0x4000, 84 84 AR9271_RC_AHB = 0x00000001, 85 85 86 86 /* GPIO registers */ 87 87 AR9271_GPIO_IN_OUT = 0x4048, /**< GPIO value read/set */ … … 92 92 AR9271_GPIO_OUT_MUX3 = 0x4068, 93 93 AR9271_GPIO_OUT_MUX_AS_OUT = 0x0, /**< GPIO set mux as output */ 94 94 95 95 /* RTC related registers */ 96 96 AR9271_RTC_RC = 0x7000, … … 109 109 AR9271_RTC_FORCE_WAKE_ENABLE = 0x00000001, 110 110 AR9271_RTC_FORCE_WAKE_ON_INT = 0x00000002, 111 111 112 112 /* MAC Registers */ 113 113 AR9271_STATION_ID0 = 0x8000, /**< STA Address Lower 32 Bits */ … … 122 122 AR9271_MULTICAST_FILTER2 = 0x8044, 123 123 AR9271_DIAG = 0x8048, 124 124 125 125 /* RX filtering register */ 126 126 AR9271_RX_FILTER = 0x803C, … … 134 134 AR9271_RX_FILTER_MYBEACON = 0x00000200, 135 135 AR9271_RX_FILTER_MCAST_BCAST_ALL = 0x00008000, 136 136 137 137 /* Key related registers */ 138 138 AR9271_KEY_TABLE_BASE = 0x8800, … … 142 142 AR9271_KEY_TABLE_TYPE_CCMP = 0x6, 143 143 AR9271_KEY_TABLE_TYPE_CLR = 0x7, 144 144 145 145 /* Physical layer registers */ 146 146 AR9271_PHY_ACTIVE = 0x981C, … … 168 168 AR9271_PHY_TPCRG1_PD_CALIB = 0x00400000, 169 169 AR9271_CARRIER_LEAK_CALIB = 0x00000002, 170 170 171 171 AR9271_OPMODE_STATION_AP_MASK = 0x00010000, 172 172 AR9271_OPMODE_ADHOC_MASK = 0x00020000, 173 173 174 174 AR9271_CLOCK_CONTROL = 0x50040, 175 175 AR9271_MAX_CPU_CLOCK = 0x304, 176 176 177 177 AR9271_RESET_POWER_DOWN_CONTROL = 0x50044, 178 178 AR9271_RADIO_RF_RESET = 0x20, 179 179 AR9271_GATE_MAC_CONTROL = 0x4000, 180 180 181 181 /* FW Addresses */ 182 182 AR9271_FW_ADDRESS = 0x501000, … … 197 197 /** Lock for access. */ 198 198 fibril_mutex_t ar9271_lock; 199 199 200 200 /** Whether device is starting up. */ 201 201 bool starting_up; 202 202 203 203 /** Backing DDF device */ 204 204 ddf_dev_t *ddf_dev; 205 205 206 206 /** USB device data */ 207 207 usb_device_t *usb_device; 208 208 209 209 /** IEEE 802.11 device data */ 210 210 ieee80211_dev_t *ieee80211_dev; 211 211 212 212 /** ATH device data */ 213 213 ath_t *ath_device; 214 214 215 215 /** HTC device data */ 216 216 htc_device_t *htc_device; -
uspace/drv/nic/ar9271/ath.h
r3061bc1 ra35b458 50 50 /** Maximum length of data response message. */ 51 51 size_t data_response_length; 52 52 53 53 /** Maximum length of control response message. */ 54 54 size_t ctrl_response_length; 55 55 56 56 /** Implementation specific data. */ 57 57 void *specific_data; 58 58 59 59 /** Generic Atheros wifi operations. */ 60 60 const ath_ops_t *ops; -
uspace/drv/nic/ar9271/ath_usb.c
r3061bc1 ra35b458 68 68 return ENOMEM; 69 69 } 70 70 71 71 ath_usb->usb_device = usb_device; 72 72 73 73 int rc; 74 74 … … 89 89 90 90 #undef _MAP_EP 91 91 92 92 ath->ctrl_response_length = 64; 93 93 ath->data_response_length = 512; 94 94 95 95 ath->specific_data = ath_usb; 96 96 ath->ops = &ath_usb_ops; 97 97 98 98 return EOK; 99 99 err_ath_usb: … … 152 152 memcpy(complete_buffer + sizeof(ath_usb_data_header_t), 153 153 buffer, buffer_size); 154 154 155 155 ath_usb_data_header_t *data_header = 156 156 (ath_usb_data_header_t *) complete_buffer; 157 157 data_header->length = host2uint16_t_le(buffer_size); 158 158 data_header->tag = host2uint16_t_le(TX_TAG); 159 159 160 160 ath_usb_t *ath_usb = (ath_usb_t *) ath->specific_data; 161 161 const errno_t ret_val = usb_pipe_write(ath_usb->output_data_pipe, 162 162 complete_buffer, complete_buffer_size); 163 163 164 164 free(complete_buffer); 165 165 166 166 return ret_val; 167 167 } -
uspace/drv/nic/ar9271/ath_usb.h
r3061bc1 ra35b458 49 49 usb_pipe_t *input_data_pipe; 50 50 usb_pipe_t *output_data_pipe; 51 51 52 52 /** Pointer to connected USB device. */ 53 53 usb_device_t *usb_device; -
uspace/drv/nic/ar9271/htc.c
r3061bc1 ra35b458 70 70 htc_vif_msg_t vif_msg; 71 71 htc_sta_msg_t sta_msg; 72 72 73 73 memset(&vif_msg, 0, sizeof(htc_vif_msg_t)); 74 74 memset(&sta_msg, 0, sizeof(htc_sta_msg_t)); 75 75 76 76 nic_address_t addr; 77 77 nic_t *nic = 78 78 nic_get_from_ddf_dev(ieee80211_get_ddf_dev(htc_device->ieee80211_dev)); 79 79 nic_query_address(nic, &addr); 80 80 81 81 memcpy(&vif_msg.addr, &addr.address, ETH_ADDR); 82 82 memcpy(&sta_msg.addr, &addr.address, ETH_ADDR); 83 83 84 84 ieee80211_operating_mode_t op_mode = 85 85 ieee80211_query_current_op_mode(htc_device->ieee80211_dev); 86 86 87 87 switch (op_mode) { 88 88 case IEEE80211_OPMODE_ADHOC: … … 99 99 break; 100 100 } 101 101 102 102 vif_msg.index = 0; 103 103 vif_msg.rts_thres = host2uint16_t_be(HTC_RTS_THRESHOLD); 104 104 105 105 wmi_send_command(htc_device, WMI_VAP_CREATE, (uint8_t *) &vif_msg, 106 106 sizeof(vif_msg), NULL); 107 107 108 108 sta_msg.is_vif_sta = 1; 109 109 sta_msg.max_ampdu = host2uint16_t_be(0xFFFF); 110 110 sta_msg.sta_index = 0; 111 111 sta_msg.vif_index = 0; 112 112 113 113 wmi_send_command(htc_device, WMI_NODE_CREATE, (uint8_t *) &sta_msg, 114 114 sizeof(sta_msg), NULL); 115 115 116 116 /* Write first 4 bytes of MAC address. */ 117 117 uint32_t id0; … … 119 119 id0 = host2uint32_t_le(id0); 120 120 wmi_reg_write(htc_device, AR9271_STATION_ID0, id0); 121 121 122 122 /* Write last 2 bytes of MAC address (and preserve existing data). */ 123 123 uint32_t id1; 124 124 wmi_reg_read(htc_device, AR9271_STATION_ID1, &id1); 125 125 126 126 uint16_t id1_addr; 127 127 memcpy(&id1_addr, &addr.address[4], 2); 128 128 id1 = (id1 & ~AR9271_STATION_ID1_MASK) | host2uint16_t_le(id1_addr); 129 129 wmi_reg_write(htc_device, AR9271_STATION_ID1, id1); 130 130 131 131 return EOK; 132 132 } … … 136 136 { 137 137 memset(header, 0, sizeof(htc_frame_header_t)); 138 138 139 139 header->endpoint_id = endpoint_id; 140 140 header->payload_length = … … 158 158 htc_config_frame_header((htc_frame_header_t *) buffer, buffer_size, 159 159 endpoint_id); 160 160 161 161 ath_t *ath_device = htc_device->ath_device; 162 162 163 163 return ath_device->ops->send_ctrl_message(ath_device, buffer, 164 164 buffer_size); … … 181 181 htc_config_frame_header((htc_frame_header_t *) buffer, buffer_size, 182 182 endpoint_id); 183 183 184 184 ath_t *ath_device = htc_device->ath_device; 185 185 186 186 return ath_device->ops->send_data_message(ath_device, buffer, 187 187 buffer_size); … … 203 203 { 204 204 ath_t *ath_device = htc_device->ath_device; 205 205 206 206 return ath_device->ops->read_data_message(ath_device, buffer, 207 207 buffer_size, transferred_size); … … 223 223 { 224 224 ath_t *ath_device = htc_device->ath_device; 225 225 226 226 return ath_device->ops->read_ctrl_message(ath_device, buffer, 227 227 buffer_size, transferred_size); … … 246 246 void *buffer = malloc(buffer_size); 247 247 memset(buffer, 0, buffer_size); 248 248 249 249 /* Fill service message structure. */ 250 250 htc_service_msg_t *service_message = (htc_service_msg_t *) … … 259 259 wmi_service_to_upload_pipe(service_id); 260 260 service_message->connection_flags = 0; 261 261 262 262 /* Send HTC message. */ 263 263 errno_t rc = htc_send_control_message(htc_device, buffer, buffer_size, … … 268 268 return rc; 269 269 } 270 270 271 271 free(buffer); 272 272 273 273 buffer_size = htc_device->ath_device->ctrl_response_length; 274 274 buffer = malloc(buffer_size); 275 275 276 276 /* Read response from device. */ 277 277 rc = htc_read_control_message(htc_device, buffer, buffer_size, NULL); … … 282 282 return rc; 283 283 } 284 284 285 285 htc_service_resp_msg_t *response_message = (htc_service_resp_msg_t *) 286 286 ((void *) buffer + sizeof(htc_frame_header_t)); 287 287 288 288 /* 289 289 * If service was successfully connected, … … 299 299 rc = EINVAL; 300 300 } 301 301 302 302 free(buffer); 303 303 304 304 return rc; 305 305 } … … 319 319 htc_config_msg_t *config_message = (htc_config_msg_t *) 320 320 ((void *) buffer + sizeof(htc_frame_header_t)); 321 321 322 322 config_message->message_id = 323 323 host2uint16_t_be(HTC_MESSAGE_CONFIG); … … 325 325 config_message->credits = 33; 326 326 config_message->pipe_id = 1; 327 327 328 328 /* Send HTC message. */ 329 329 errno_t rc = htc_send_control_message(htc_device, buffer, buffer_size, … … 335 335 return rc; 336 336 } 337 337 338 338 free(buffer); 339 339 340 340 buffer_size = htc_device->ath_device->ctrl_response_length; 341 341 buffer = malloc(buffer_size); 342 342 343 343 /* Check response from device. */ 344 344 rc = htc_read_control_message(htc_device, buffer, buffer_size, NULL); … … 347 347 "Error: %s\n", str_error_name(rc)); 348 348 } 349 349 350 350 free(buffer); 351 351 352 352 return rc; 353 353 } … … 368 368 (htc_setup_complete_msg_t *) 369 369 ((void *) buffer + sizeof(htc_frame_header_t)); 370 370 371 371 complete_message->message_id = 372 372 host2uint16_t_be(HTC_MESSAGE_SETUP_COMPLETE); 373 373 374 374 /* Send HTC message. */ 375 375 errno_t rc = htc_send_control_message(htc_device, buffer, buffer_size, … … 378 378 usb_log_error("Failed to send HTC setup complete message. " 379 379 "Error: %s\n", str_error_name(rc)); 380 380 381 381 free(buffer); 382 382 383 383 return rc; 384 384 } … … 398 398 size_t buffer_size = htc_device->ath_device->ctrl_response_length; 399 399 void *buffer = malloc(buffer_size); 400 400 401 401 /* Read response from device. */ 402 402 errno_t rc = htc_read_control_message(htc_device, buffer, buffer_size, … … 408 408 return rc; 409 409 } 410 410 411 411 uint16_t *message_id = (uint16_t *) ((void *) buffer + 412 412 sizeof(htc_frame_header_t)); … … 415 415 else 416 416 rc = EINVAL; 417 417 418 418 free(buffer); 419 419 420 420 return rc; 421 421 } … … 435 435 fibril_mutex_initialize(&htc_device->rx_lock); 436 436 fibril_mutex_initialize(&htc_device->tx_lock); 437 437 438 438 htc_device->endpoints.ctrl_endpoint = 0; 439 439 440 440 htc_device->ath_device = ath_device; 441 441 htc_device->ieee80211_dev = ieee80211_dev; 442 442 443 443 return EOK; 444 444 } … … 460 460 return rc; 461 461 } 462 462 463 463 /* 464 464 * HTC services initialization start. … … 470 470 return rc; 471 471 } 472 472 473 473 rc = htc_connect_service(htc_device, WMI_BEACON_SERVICE, 474 474 &htc_device->endpoints.beacon_endpoint); … … 477 477 return rc; 478 478 } 479 479 480 480 rc = htc_connect_service(htc_device, WMI_CAB_SERVICE, 481 481 &htc_device->endpoints.cab_endpoint); … … 484 484 return rc; 485 485 } 486 486 487 487 rc = htc_connect_service(htc_device, WMI_UAPSD_SERVICE, 488 488 &htc_device->endpoints.uapsd_endpoint); … … 491 491 return rc; 492 492 } 493 493 494 494 rc = htc_connect_service(htc_device, WMI_MGMT_SERVICE, 495 495 &htc_device->endpoints.mgmt_endpoint); … … 498 498 return rc; 499 499 } 500 500 501 501 rc = htc_connect_service(htc_device, WMI_DATA_BE_SERVICE, 502 502 &htc_device->endpoints.data_be_endpoint); … … 506 506 return rc; 507 507 } 508 508 509 509 rc = htc_connect_service(htc_device, WMI_DATA_BK_SERVICE, 510 510 &htc_device->endpoints.data_bk_endpoint); … … 514 514 return rc; 515 515 } 516 516 517 517 rc = htc_connect_service(htc_device, WMI_DATA_VIDEO_SERVICE, 518 518 &htc_device->endpoints.data_video_endpoint); … … 521 521 return rc; 522 522 } 523 523 524 524 rc = htc_connect_service(htc_device, WMI_DATA_VOICE_SERVICE, 525 525 &htc_device->endpoints.data_voice_endpoint); … … 528 528 return rc; 529 529 } 530 530 531 531 /* 532 532 * HTC services initialization end. 533 533 */ 534 534 535 535 /* Credits initialization message. */ 536 536 rc = htc_config_credits(htc_device); … … 539 539 return rc; 540 540 } 541 541 542 542 /* HTC setup complete confirmation message. */ 543 543 rc = htc_complete_setup(htc_device); … … 546 546 return rc; 547 547 } 548 548 549 549 usb_log_info("HTC services initialization finished successfully.\n"); 550 550 551 551 return EOK; 552 552 } -
uspace/drv/nic/ar9271/htc.h
r3061bc1 ra35b458 112 112 /** WMI message sequence number */ 113 113 uint16_t sequence_number; 114 114 115 115 /** HTC endpoints numbers */ 116 116 htc_pipes_t endpoints; 117 117 118 118 /** Lock for receiver */ 119 119 fibril_mutex_t rx_lock; 120 120 121 121 /** Lock for transmitter */ 122 122 fibril_mutex_t tx_lock; 123 123 124 124 /** Pointer to related IEEE 802.11 device */ 125 125 ieee80211_dev_t *ieee80211_dev; 126 126 127 127 /** Pointer to Atheros WiFi device structure */ 128 128 ath_t *ath_device; … … 175 175 uint16_t credits; /**< Big Endian value! */ 176 176 uint16_t credit_size; /**< Big Endian value! */ 177 177 178 178 uint8_t max_endpoints; 179 179 uint8_t pad; … … 187 187 uint16_t service_id; /**< Big Endian value! */ 188 188 uint16_t connection_flags; /**< Big Endian value! */ 189 189 190 190 uint8_t download_pipe_id; 191 191 uint8_t upload_pipe_id; … … 237 237 uint8_t vif_index; 238 238 uint8_t is_vif_sta; 239 239 240 240 uint16_t flags; /**< Big Endian value! */ 241 241 uint16_t ht_cap; /**< Big Endian value! */ 242 242 uint16_t max_ampdu; /**< Big Endian value! */ 243 243 244 244 uint8_t pad; 245 245 } __attribute__((packed)) htc_sta_msg_t; -
uspace/drv/nic/ar9271/hw.c
r3061bc1 ra35b458 57 57 for (size_t i = 0; i < HW_WAIT_LOOPS; i++) { 58 58 udelay(HW_WAIT_TIME_US); 59 59 60 60 uint32_t result; 61 61 wmi_reg_read(ar9271->htc_device, offset, &result); … … 63 63 return EOK; 64 64 } 65 65 66 66 return ETIMEOUT; 67 67 } … … 84 84 } 85 85 }; 86 86 87 87 wmi_reg_buffer_write(ar9271->htc_device, buffer, 88 88 sizeof(buffer) / sizeof(wmi_reg_t)); 89 89 90 90 udelay(2); 91 91 92 92 wmi_reg_write(ar9271->htc_device, AR9271_RC, 0); 93 93 wmi_reg_write(ar9271->htc_device, AR9271_RTC_RESET, 1); 94 94 95 95 errno_t rc = hw_read_wait(ar9271, 96 96 AR9271_RTC_STATUS, … … 101 101 return rc; 102 102 } 103 103 104 104 return EOK; 105 105 } … … 108 108 { 109 109 uint32_t reset_value = AR9271_RTC_RC_MAC_WARM; 110 110 111 111 if (cold) 112 112 reset_value |= AR9271_RTC_RC_MAC_COLD; 113 113 114 114 wmi_reg_t buffer[] = { 115 115 { … … 127 127 } 128 128 }; 129 129 130 130 wmi_reg_buffer_write(ar9271->htc_device, buffer, 131 131 sizeof(buffer) / sizeof(wmi_reg_t)); 132 132 133 133 udelay(100); 134 134 135 135 wmi_reg_write(ar9271->htc_device, AR9271_RTC_RC, 0); 136 136 137 137 errno_t rc = hw_read_wait(ar9271, AR9271_RTC_RC, AR9271_RTC_RC_MASK, 0); 138 138 if (rc != EOK) { … … 140 140 return rc; 141 141 } 142 142 143 143 wmi_reg_write(ar9271->htc_device, AR9271_RC, 0); 144 144 wmi_reg_clear_bit(ar9271->htc_device, AR9271_STATION_ID1, 145 145 AR9271_STATION_ID1_POWER_SAVING); 146 146 147 147 return EOK; 148 148 } … … 152 152 uint32_t value; 153 153 nic_address_t ar9271_address; 154 154 155 155 for (unsigned int i = 0; i < 3; i++) { 156 156 wmi_reg_read(ar9271->htc_device, 157 157 AR9271_EEPROM_MAC_ADDR_START + i * 4, &value); 158 158 159 159 uint16_t two_bytes = uint16_t_be2host(value); 160 160 ar9271_address.address[2*i] = two_bytes >> 8; 161 161 ar9271_address.address[2*i+1] = two_bytes & 0xff; 162 162 } 163 163 164 164 nic_t *nic = nic_get_from_ddf_dev(ar9271->ddf_dev); 165 165 166 166 errno_t rc = nic_report_address(nic, &ar9271_address); 167 167 if (rc != EOK) { … … 169 169 return rc; 170 170 } 171 171 172 172 return EOK; 173 173 } … … 176 176 { 177 177 uint32_t address; 178 178 179 179 if (gpio > 11) 180 180 address = AR9271_GPIO_OUT_MUX3; … … 183 183 else 184 184 address = AR9271_GPIO_OUT_MUX1; 185 185 186 186 uint32_t gpio_shift = (gpio % 6) * 5; 187 187 188 188 uint32_t temp; 189 189 wmi_reg_read(ar9271->htc_device, address, &temp); 190 190 191 191 temp = ((temp & 0x1f0) << 1) | (temp & ~0x1f0); 192 192 temp &= ~(0x1f << gpio_shift); 193 193 temp |= (type << gpio_shift); 194 194 195 195 wmi_reg_write(ar9271->htc_device, address, temp); 196 196 197 197 gpio_shift = 2 * gpio; 198 198 199 199 wmi_reg_set_clear_bit(ar9271->htc_device, AR9271_GPIO_OE_OUT, 200 200 AR9271_GPIO_OE_OUT_ALWAYS << gpio_shift, 201 201 AR9271_GPIO_OE_OUT_ALWAYS << gpio_shift); 202 202 203 203 return EOK; 204 204 } … … 225 225 return rc; 226 226 } 227 227 228 228 rc = hw_set_reset(ar9271, false); 229 229 if (rc != EOK) { … … 231 231 return rc; 232 232 } 233 233 234 234 rc = hw_addr_init(ar9271); 235 235 if (rc != EOK) { … … 237 237 return rc; 238 238 } 239 239 240 240 return EOK; 241 241 } … … 249 249 return rc; 250 250 } 251 251 252 252 rc = hw_gpio_set_value(ar9271, AR9271_LED_PIN, 0); 253 253 if (rc != EOK) { … … 255 255 return rc; 256 256 } 257 257 258 258 return EOK; 259 259 } … … 263 263 wmi_reg_write(ar9271->htc_device, AR9271_PHY_ACTIVE, 1); 264 264 udelay(1000); 265 265 266 266 return EOK; 267 267 } … … 271 271 { 272 272 uint32_t set_bit = 0x10000000; 273 273 274 274 switch(op_mode) { 275 275 case IEEE80211_OPMODE_ADHOC: … … 286 286 AR9271_CONFIG_ADHOC); 287 287 } 288 288 289 289 wmi_reg_set_clear_bit(ar9271->htc_device, AR9271_STATION_ID1, 290 290 set_bit, AR9271_OPMODE_STATION_AP_MASK | AR9271_OPMODE_ADHOC_MASK); 291 291 292 292 ieee80211_report_current_op_mode(ar9271->ieee80211_dev, op_mode); 293 293 294 294 return EOK; 295 295 } … … 302 302 return rc; 303 303 } 304 304 305 305 return EOK; 306 306 } … … 310 310 uint32_t value; 311 311 wmi_reg_read(ar9271->htc_device, AR9271_PHY_CAL, &value); 312 312 313 313 value &= 0xfffffe00; 314 314 value |= (((uint32_t) AR9271_CALIB_NOMINAL_VALUE_2GHZ << 1) & 0x1ff); 315 315 316 316 wmi_reg_write(ar9271->htc_device, AR9271_PHY_CAL, value); 317 317 318 318 wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 319 319 AR9271_AGC_CONTROL_NF_CALIB_EN); 320 320 321 321 wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 322 322 AR9271_AGC_CONTROL_NF_NOT_UPDATE); 323 323 324 324 wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 325 325 AR9271_AGC_CONTROL_NF_CALIB); 326 326 327 327 errno_t rc = hw_read_wait(ar9271, AR9271_AGC_CONTROL, 328 328 AR9271_AGC_CONTROL_NF_CALIB, 0); … … 331 331 return rc; 332 332 } 333 333 334 334 wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 335 335 AR9271_AGC_CONTROL_NF_CALIB_EN); 336 336 337 337 wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 338 338 AR9271_AGC_CONTROL_NF_NOT_UPDATE); 339 339 340 340 wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 341 341 AR9271_AGC_CONTROL_NF_CALIB); 342 342 343 343 return EOK; 344 344 } … … 349 349 if ((freq < IEEE80211_FIRST_FREQ) || (freq > IEEE80211_MAX_FREQ)) 350 350 return EINVAL; 351 351 352 352 /* Not supported channel frequency. */ 353 353 if ((freq - IEEE80211_FIRST_FREQ) % IEEE80211_CHANNEL_GAP != 0) 354 354 return EINVAL; 355 355 356 356 uint32_t tx_control; 357 357 wmi_reg_read(ar9271->htc_device, AR9271_PHY_CCK_TX_CTRL, &tx_control); 358 358 wmi_reg_write(ar9271->htc_device, AR9271_PHY_CCK_TX_CTRL, 359 359 tx_control & ~AR9271_PHY_CCK_TX_CTRL_JAPAN); 360 360 361 361 /* Some magic here. */ 362 362 uint32_t synth_ctl; … … 365 365 uint32_t channel_select = (freq * 0x10000) / 15; 366 366 synth_ctl = synth_ctl | (1 << 29) | (1 << 28) | channel_select; 367 367 368 368 wmi_reg_write(ar9271->htc_device, AR9271_PHY_SYNTH_CONTROL, synth_ctl); 369 369 370 370 ieee80211_report_current_freq(ar9271->ieee80211_dev, freq); 371 371 372 372 return EOK; 373 373 } … … 376 376 { 377 377 wmi_reg_write(ar9271->htc_device, AR9271_PHY_RFBUS_KILL, 0x1); 378 378 379 379 errno_t rc = hw_read_wait(ar9271, AR9271_PHY_RFBUS_GRANT, 0x1, 0x1); 380 380 if (rc != EOK) { … … 382 382 return rc; 383 383 } 384 384 385 385 rc = hw_set_freq(ar9271, freq); 386 386 if (rc != EOK) { … … 388 388 return rc; 389 389 } 390 390 391 391 rc = hw_activate_phy(ar9271); 392 392 if (rc != EOK) { … … 394 394 return rc; 395 395 } 396 396 397 397 udelay(1000); 398 398 wmi_reg_write(ar9271->htc_device, AR9271_PHY_RFBUS_KILL, 0x0); 399 399 400 400 rc = hw_noise_floor_calibration(ar9271); 401 401 if (rc != EOK) { … … 403 403 return rc; 404 404 } 405 405 406 406 return EOK; 407 407 } … … 410 410 { 411 411 uint32_t additional_bits = 0; 412 412 413 413 if (assoc) 414 414 additional_bits |= AR9271_RX_FILTER_MYBEACON; 415 415 else 416 416 additional_bits |= AR9271_RX_FILTER_BEACON; 417 417 418 418 uint32_t filter_bits = AR9271_RX_FILTER_UNI | 419 419 AR9271_RX_FILTER_MULTI | AR9271_RX_FILTER_BROAD | 420 420 additional_bits; 421 421 422 422 wmi_reg_write(ar9271->htc_device, AR9271_RX_FILTER, filter_bits); 423 423 424 424 return EOK; 425 425 } … … 428 428 { 429 429 ieee80211_dev_t *ieee80211_dev = ar9271->ieee80211_dev; 430 430 431 431 nic_address_t bssid; 432 432 ieee80211_query_bssid(ieee80211_dev, &bssid); 433 433 434 434 uint32_t *first_4bytes = (uint32_t *) &bssid.address; 435 435 uint16_t *last_2bytes = (uint16_t *) &bssid.address[4]; 436 436 437 437 wmi_reg_write(ar9271->htc_device, AR9271_BSSID0, 438 438 uint32_t_le2host(*first_4bytes)); 439 439 440 440 wmi_reg_write(ar9271->htc_device, AR9271_BSSID1, 441 441 uint16_t_le2host(*last_2bytes) | 442 442 ((ieee80211_get_aid(ieee80211_dev) & 0x3fff) << 16)); 443 443 444 444 return EOK; 445 445 } … … 449 449 wmi_reg_write(ar9271->htc_device, AR9271_COMMAND, 450 450 AR9271_COMMAND_RX_ENABLE); 451 451 452 452 errno_t rc = hw_set_rx_filter(ar9271, false); 453 453 if (rc != EOK) { … … 455 455 return rc; 456 456 } 457 457 458 458 wmi_reg_write(ar9271->htc_device, AR9271_MULTICAST_FILTER1, ~0); 459 459 wmi_reg_write(ar9271->htc_device, AR9271_MULTICAST_FILTER2, ~0); 460 460 461 461 /* Disable RX blocking. */ 462 462 wmi_reg_clear_bit(ar9271->htc_device, AR9271_DIAG, (0x20 | 0x02000000)); 463 463 464 464 return EOK; 465 465 } … … 469 469 /* Some magic here (set for 2GHz channels). But VERY important :-) */ 470 470 uint32_t pll = (0x5 << 10) | 0x2c; 471 471 472 472 wmi_reg_write(ar9271->htc_device, AR9271_RTC_PLL_CONTROL, pll); 473 473 474 474 wmi_reg_write(ar9271->htc_device, AR9271_RTC_SLEEP_CLOCK, 475 475 AR9271_RTC_SLEEP_CLOCK_FORCE_DERIVED); 476 476 wmi_reg_set_bit(ar9271->htc_device, AR9271_RTC_FORCE_WAKE, 477 477 AR9271_RTC_FORCE_WAKE_ENABLE); 478 478 479 479 return EOK; 480 480 } … … 484 484 uint32_t reg_offset; 485 485 uint32_t reg_value; 486 486 487 487 size_t size = ARRAY_SIZE(ar9271_2g_mode_array); 488 488 489 489 for (size_t i = 0; i < size; i++) { 490 490 reg_offset = ar9271_2g_mode_array[i][0]; … … 492 492 wmi_reg_write(ar9271->htc_device, reg_offset, reg_value); 493 493 } 494 494 495 495 size = ARRAY_SIZE(ar9271_2g_tx_array); 496 496 497 497 for (size_t i = 0; i < size; i++) { 498 498 reg_offset = ar9271_2g_tx_array[i][0]; … … 500 500 wmi_reg_write(ar9271->htc_device, reg_offset, reg_value); 501 501 } 502 502 503 503 size = ARRAY_SIZE(ar9271_init_array); 504 504 505 505 for (size_t i = 0; i < size; i++) { 506 506 reg_offset = ar9271_init_array[i][0]; … … 522 522 wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 523 523 AR9271_AGC_CONTROL_CALIB); 524 524 525 525 errno_t rc = hw_read_wait(ar9271, AR9271_AGC_CONTROL, 526 526 AR9271_AGC_CONTROL_CALIB, 0); … … 529 529 return rc; 530 530 } 531 531 532 532 wmi_reg_set_bit(ar9271->htc_device, AR9271_ADC_CONTROL, 533 533 AR9271_ADC_CONTROL_OFF_PWDADC); … … 536 536 wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 537 537 AR9271_AGC_CONTROL_TX_CALIB); 538 538 539 539 return EOK; 540 540 } … … 544 544 /* Set physical layer as deactivated. */ 545 545 wmi_reg_write(ar9271->htc_device, AR9271_PHY_ACTIVE, 0); 546 546 547 547 if(ar9271->starting_up) { 548 548 wmi_reg_write(ar9271->htc_device, 549 549 AR9271_RESET_POWER_DOWN_CONTROL, 550 550 AR9271_RADIO_RF_RESET); 551 551 552 552 udelay(50); 553 553 } 554 554 555 555 /* Cold reset when RX is enabled. */ 556 556 uint32_t config_reg; … … 558 558 if (config_reg & AR9271_COMMAND_RX_ENABLE) 559 559 hw_set_reset(ar9271, true); 560 560 561 561 errno_t rc = hw_init_pll(ar9271); 562 562 if (rc != EOK) { … … 564 564 return rc; 565 565 } 566 566 567 567 udelay(500); 568 568 569 569 wmi_reg_write(ar9271->htc_device, AR9271_CLOCK_CONTROL, 570 570 AR9271_MAX_CPU_CLOCK); 571 571 572 572 udelay(100); 573 573 574 574 if (ar9271->starting_up) { 575 575 wmi_reg_write(ar9271->htc_device, 576 576 AR9271_RESET_POWER_DOWN_CONTROL, 577 577 AR9271_GATE_MAC_CONTROL); 578 578 579 579 udelay(50); 580 580 } 581 581 582 582 hw_set_init_values(ar9271); 583 583 584 584 /* Set physical layer mode. */ 585 585 wmi_reg_write(ar9271->htc_device, AR9271_PHY_MODE, 586 586 AR9271_PHY_MODE_DYNAMIC); 587 587 588 588 /* Reset device operating mode. */ 589 589 rc = hw_reset_operating_mode(ar9271); … … 592 592 return rc; 593 593 } 594 594 595 595 /* Set initial channel frequency. */ 596 596 rc = hw_set_freq(ar9271, IEEE80211_FIRST_FREQ); … … 599 599 return rc; 600 600 } 601 601 602 602 /* Initialize transmission queues. */ 603 603 for (unsigned int i = 0; i < AR9271_QUEUES_COUNT; i++) { … … 605 605 AR9271_QUEUE_BASE_MASK + (i << 2), 1 << i); 606 606 } 607 607 608 608 /* Activate physical layer. */ 609 609 rc = hw_activate_phy(ar9271); … … 612 612 return rc; 613 613 } 614 614 615 615 /* Calibration. */ 616 616 rc = hw_calibration(ar9271); … … 619 619 return rc; 620 620 } 621 621 622 622 rc = hw_noise_floor_calibration(ar9271); 623 623 if (rc != EOK) { … … 625 625 return rc; 626 626 } 627 627 628 628 /* Byteswap TX and RX data buffer words. */ 629 629 wmi_reg_write(ar9271->htc_device, AR9271_CONFIG, 0xA); 630 630 631 631 return EOK; 632 632 } … … 645 645 return rc; 646 646 } 647 647 648 648 rc = hw_init_led(ar9271); 649 649 if (rc != EOK) { … … 651 651 return rc; 652 652 } 653 653 654 654 usb_log_info("HW initialization finished successfully.\n"); 655 656 return EOK; 657 } 655 656 return EOK; 657 } -
uspace/drv/nic/ar9271/wmi.c
r3061bc1 ra35b458 53 53 { 54 54 uint32_t cmd_value = host2uint32_t_be(reg_offset); 55 55 56 56 void *resp_buffer = 57 57 malloc(htc_device->ath_device->ctrl_response_length); 58 58 59 59 errno_t rc = wmi_send_command(htc_device, WMI_REG_READ, 60 60 (uint8_t *) &cmd_value, sizeof(cmd_value), resp_buffer); 61 61 62 62 if (rc != EOK) { 63 63 usb_log_error("Failed to read registry value.\n"); 64 64 return rc; 65 65 } 66 66 67 67 uint32_t *resp_value = (uint32_t *) ((void *) resp_buffer + 68 68 sizeof(htc_frame_header_t) + sizeof(wmi_command_header_t)); 69 69 70 70 *res = uint32_t_be2host(*resp_value); 71 71 72 72 return rc; 73 73 } … … 88 88 host2uint32_t_be(val) 89 89 }; 90 90 91 91 void *resp_buffer = 92 92 malloc(htc_device->ath_device->ctrl_response_length); 93 93 94 94 errno_t rc = wmi_send_command(htc_device, WMI_REG_WRITE, 95 95 (uint8_t *) &cmd_buffer, sizeof(cmd_buffer), resp_buffer); 96 96 97 97 free(resp_buffer); 98 98 99 99 if (rc != EOK) { 100 100 usb_log_error("Failed to write registry value.\n"); 101 101 return rc; 102 102 } 103 103 104 104 return rc; 105 105 } … … 119 119 { 120 120 uint32_t value; 121 121 122 122 errno_t rc = wmi_reg_read(htc_device, reg_offset, &value); 123 123 if (rc != EOK) { … … 126 126 return rc; 127 127 } 128 128 129 129 value &= ~clear_bit; 130 130 value |= set_bit; 131 131 132 132 rc = wmi_reg_write(htc_device, reg_offset, value); 133 133 if (rc != EOK) { … … 136 136 return rc; 137 137 } 138 138 139 139 return rc; 140 140 } … … 186 186 void *resp_buffer = 187 187 malloc(htc_device->ath_device->ctrl_response_length); 188 188 189 189 /* Convert values to correct endianness. */ 190 190 for (size_t i = 0; i < elements; i++) { … … 197 197 host2uint32_t_be(buffer_element->value); 198 198 } 199 199 200 200 errno_t rc = wmi_send_command(htc_device, WMI_REG_WRITE, 201 201 (uint8_t *) buffer, buffer_size, resp_buffer); 202 202 203 203 free(buffer); 204 204 free(resp_buffer); 205 205 206 206 if (rc != EOK) { 207 207 usb_log_error("Failed to write multi registry value.\n"); 208 208 return rc; 209 209 } 210 210 211 211 return rc; 212 212 } … … 230 230 size_t buffer_size = header_size + command_length; 231 231 void *buffer = malloc(buffer_size); 232 232 233 233 if (command_buffer != NULL) 234 234 memcpy(buffer+header_size, command_buffer, command_length); 235 235 236 236 /* Set up WMI header */ 237 237 wmi_command_header_t *wmi_header = (wmi_command_header_t *) … … 240 240 wmi_header->sequence_number = 241 241 host2uint16_t_be(++htc_device->sequence_number); 242 242 243 243 /* Send message. */ 244 244 errno_t rc = htc_send_control_message(htc_device, buffer, buffer_size, … … 249 249 return rc; 250 250 } 251 251 252 252 free(buffer); 253 253 254 254 bool clean_resp_buffer = false; 255 255 size_t response_buffer_size = … … 259 259 clean_resp_buffer = true; 260 260 } 261 261 262 262 /* Read response. */ 263 263 /* TODO: Ignoring WMI management RX messages ~ TX statuses etc. */ … … 272 272 return rc; 273 273 } 274 274 275 275 if (response_buffer_size < sizeof(htc_frame_header_t) + 276 276 sizeof(wmi_command_header_t)) { … … 279 279 return EINVAL; 280 280 } 281 281 282 282 wmi_command_header_t *wmi_hdr = (wmi_command_header_t *) 283 283 ((void *) response_buffer + sizeof(htc_frame_header_t)); 284 284 cmd_id = uint16_t_be2host(wmi_hdr->command_id); 285 285 } while(cmd_id & WMI_MGMT_CMD_MASK); 286 286 287 287 if (clean_resp_buffer) 288 288 free(response_buffer); 289 290 return rc; 291 } 289 290 return rc; 291 } -
uspace/drv/nic/ar9271/wmi.h
r3061bc1 ra35b458 76 76 WMI_ECHO = 0x0001, 77 77 WMI_ACCESS_MEMORY, 78 78 79 79 /* Commands used for HOST -> DEVICE communication */ 80 80 WMI_GET_FW_VERSION, -
uspace/drv/nic/e1k/e1k.c
r3061bc1 ra35b458 122 122 /** Device configuration */ 123 123 e1000_info_t info; 124 124 125 125 /** Physical registers base address */ 126 126 void *reg_base_phys; 127 127 /** Virtual registers base address */ 128 128 void *reg_base_virt; 129 129 130 130 /** Physical tx ring address */ 131 131 uintptr_t tx_ring_phys; 132 132 /** Virtual tx ring address */ 133 133 void *tx_ring_virt; 134 134 135 135 /** Ring of TX frames, physical address */ 136 136 uintptr_t *tx_frame_phys; 137 137 /** Ring of TX frames, virtual address */ 138 138 void **tx_frame_virt; 139 139 140 140 /** Physical rx ring address */ 141 141 uintptr_t rx_ring_phys; 142 142 /** Virtual rx ring address */ 143 143 void *rx_ring_virt; 144 144 145 145 /** Ring of RX frames, physical address */ 146 146 uintptr_t *rx_frame_phys; 147 147 /** Ring of RX frames, virtual address */ 148 148 void **rx_frame_virt; 149 149 150 150 /** VLAN tag */ 151 151 uint16_t vlan_tag; 152 152 153 153 /** Add VLAN tag to frame */ 154 154 bool vlan_tag_add; 155 155 156 156 /** Used unicast Receive Address count */ 157 157 unsigned int unicast_ra_count; 158 158 159 159 /** Used milticast Receive addrress count */ 160 160 unsigned int multicast_ra_count; 161 161 162 162 /** The irq assigned */ 163 163 int irq; 164 164 165 165 /** Lock for CTRL register */ 166 166 fibril_mutex_t ctrl_lock; 167 167 168 168 /** Lock for receiver */ 169 169 fibril_mutex_t rx_lock; 170 170 171 171 /** Lock for transmitter */ 172 172 fibril_mutex_t tx_lock; 173 173 174 174 /** Lock for EEPROM access */ 175 175 fibril_mutex_t eeprom_lock; … … 292 292 assert(dev); 293 293 assert(info); 294 294 295 295 memset(info, 0, sizeof(nic_device_info_t)); 296 296 297 297 info->vendor_id = 0x8086; 298 298 str_cpy(info->vendor_name, NIC_VENDOR_MAX_LENGTH, … … 300 300 str_cpy(info->model_name, NIC_MODEL_MAX_LENGTH, 301 301 "Intel Pro"); 302 302 303 303 info->ethernet_support[ETH_10M] = ETH_10BASE_T; 304 304 info->ethernet_support[ETH_100M] = ETH_100BASE_TX; 305 305 info->ethernet_support[ETH_1000M] = ETH_1000BASE_T; 306 306 307 307 return EOK; 308 308 } … … 323 323 else 324 324 *state = NIC_CS_UNPLUGGED; 325 325 326 326 return EOK; 327 327 } … … 340 340 e1000_t *e1000 = DRIVER_DATA_FUN(fun); 341 341 uint32_t status = E1000_REG_READ(e1000, E1000_STATUS); 342 342 343 343 if (status & STATUS_FD) 344 344 *duplex = NIC_CM_FULL_DUPLEX; 345 345 else 346 346 *duplex = NIC_CM_HALF_DUPLEX; 347 347 348 348 uint32_t speed_bits = 349 349 (status >> STATUS_SPEED_SHIFT) & STATUS_SPEED_ALL; 350 350 351 351 if (speed_bits == STATUS_SPEED_10) 352 352 *speed = 10; … … 356 356 (speed_bits == STATUS_SPEED_1000B)) 357 357 *speed = 1000; 358 358 359 359 *role = NIC_ROLE_UNKNOWN; 360 360 return EOK; … … 364 364 { 365 365 fibril_mutex_lock(&e1000->ctrl_lock); 366 366 367 367 uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL); 368 368 369 369 if (ctrl & CTRL_SLU) { 370 370 ctrl &= ~(CTRL_SLU); 371 371 E1000_REG_WRITE(e1000, E1000_CTRL, ctrl); 372 372 fibril_mutex_unlock(&e1000->ctrl_lock); 373 373 374 374 async_usleep(10); 375 375 376 376 fibril_mutex_lock(&e1000->ctrl_lock); 377 377 ctrl = E1000_REG_READ(e1000, E1000_CTRL); … … 379 379 E1000_REG_WRITE(e1000, E1000_CTRL, ctrl); 380 380 } 381 381 382 382 fibril_mutex_unlock(&e1000->ctrl_lock); 383 383 } … … 391 391 if ((speed != 10) && (speed != 100) && (speed != 1000)) 392 392 return EINVAL; 393 393 394 394 if ((duplex != NIC_CM_HALF_DUPLEX) && (duplex != NIC_CM_FULL_DUPLEX)) 395 395 return EINVAL; 396 396 397 397 e1000_t *e1000 = DRIVER_DATA_FUN(fun); 398 398 399 399 fibril_mutex_lock(&e1000->ctrl_lock); 400 400 uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL); 401 401 402 402 ctrl |= CTRL_FRCSPD; 403 403 ctrl |= CTRL_FRCDPLX; 404 404 ctrl &= ~(CTRL_ASDE); 405 405 406 406 if (duplex == NIC_CM_FULL_DUPLEX) 407 407 ctrl |= CTRL_FD; 408 408 else 409 409 ctrl &= ~(CTRL_FD); 410 410 411 411 ctrl &= ~(CTRL_SPEED_MASK); 412 412 if (speed == 1000) … … 416 416 else 417 417 ctrl |= CTRL_SPEED_10 << CTRL_SPEED_SHIFT; 418 418 419 419 E1000_REG_WRITE(e1000, E1000_CTRL, ctrl); 420 420 421 421 fibril_mutex_unlock(&e1000->ctrl_lock); 422 422 423 423 e1000_link_restart(e1000); 424 424 425 425 return EOK; 426 426 } … … 437 437 { 438 438 e1000_t *e1000 = DRIVER_DATA_FUN(fun); 439 439 440 440 fibril_mutex_lock(&e1000->ctrl_lock); 441 441 442 442 uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL); 443 443 444 444 ctrl &= ~(CTRL_FRCSPD); 445 445 ctrl &= ~(CTRL_FRCDPLX); 446 446 ctrl |= CTRL_ASDE; 447 447 448 448 E1000_REG_WRITE(e1000, E1000_CTRL, ctrl); 449 449 450 450 fibril_mutex_unlock(&e1000->ctrl_lock); 451 451 452 452 e1000_link_restart(e1000); 453 453 454 454 return EOK; 455 455 } … … 465 465 { 466 466 e1000_t *e1000 = DRIVER_DATA_FUN(fun); 467 467 468 468 fibril_mutex_lock(&e1000->ctrl_lock); 469 469 470 470 uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL); 471 471 472 472 ctrl |= CTRL_FRCSPD; 473 473 ctrl |= CTRL_FRCDPLX; 474 474 ctrl &= ~(CTRL_ASDE); 475 475 476 476 E1000_REG_WRITE(e1000, E1000_CTRL, ctrl); 477 477 478 478 fibril_mutex_unlock(&e1000->ctrl_lock); 479 479 480 480 e1000_link_restart(e1000); 481 481 482 482 return EOK; 483 483 } … … 504 504 { 505 505 e1000_t *e1000 = DRIVER_DATA_FUN(fun); 506 506 507 507 *mode = 0; 508 508 uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL); 509 509 if (rctl & RCTL_SBP) 510 510 *mode = NIC_DEFECTIVE_BAD_CRC | NIC_DEFECTIVE_SHORT; 511 511 512 512 return EOK; 513 513 }; … … 526 526 e1000_t *e1000 = DRIVER_DATA_FUN(fun); 527 527 errno_t rc = EOK; 528 528 529 529 fibril_mutex_lock(&e1000->rx_lock); 530 530 531 531 uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL); 532 532 bool short_mode = (mode & NIC_DEFECTIVE_SHORT ? true : false); 533 533 bool bad_mode = (mode & NIC_DEFECTIVE_BAD_CRC ? true : false); 534 534 535 535 if (short_mode && bad_mode) 536 536 rctl |= RCTL_SBP; … … 539 539 else 540 540 rc = ENOTSUP; 541 541 542 542 E1000_REG_WRITE(e1000, E1000_RCTL, rctl); 543 543 544 544 fibril_mutex_unlock(&e1000->rx_lock); 545 545 return rc; … … 563 563 uint8_t *mac4 = (uint8_t *) address->address + 4; 564 564 uint8_t *mac5 = (uint8_t *) address->address + 5; 565 565 566 566 uint32_t rah; 567 567 uint32_t ral; 568 568 569 569 ral = ((*mac3) << 24) | ((*mac2) << 16) | ((*mac1) << 8) | (*mac0); 570 570 rah = ((*mac5) << 8) | ((*mac4)); 571 571 572 572 if (set_av_bit) 573 573 rah |= RAH_AV; 574 574 else 575 575 rah |= E1000_REG_READ(e1000, E1000_RAH_ARRAY(position)) & RAH_AV; 576 576 577 577 E1000_REG_WRITE(e1000, E1000_RAH_ARRAY(position), rah); 578 578 E1000_REG_WRITE(e1000, E1000_RAL_ARRAY(position), ral); … … 605 605 ra_num++) 606 606 e1000_disable_receive_address(e1000, ra_num); 607 607 608 608 e1000->unicast_ra_count = 0; 609 609 } … … 618 618 unsigned int first_multicast_ra_num = 619 619 E1000_RECEIVE_ADDRESS - e1000->multicast_ra_count; 620 620 621 621 for (unsigned int ra_num = E1000_RECEIVE_ADDRESS - 1; 622 622 ra_num >= first_multicast_ra_num; 623 623 ra_num--) 624 624 e1000_disable_receive_address(e1000, ra_num); 625 625 626 626 e1000->multicast_ra_count = 0; 627 627 } … … 662 662 { 663 663 assert(addr_cnt <= get_free_unicast_address_count(e1000)); 664 664 665 665 nic_address_t *addr_iterator = (nic_address_t *) addr; 666 666 667 667 /* ra_num = 0 is primary address */ 668 668 for (unsigned int ra_num = 1; … … 685 685 { 686 686 assert(addr_cnt <= get_free_multicast_address_count(e1000)); 687 687 688 688 nic_address_t *addr_iterator = (nic_address_t *) addr; 689 689 690 690 unsigned int first_multicast_ra_num = E1000_RECEIVE_ADDRESS - addr_cnt; 691 691 for (unsigned int ra_num = E1000_RECEIVE_ADDRESS - 1; … … 832 832 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 833 833 errno_t rc = EOK; 834 834 835 835 fibril_mutex_lock(&e1000->rx_lock); 836 836 837 837 switch (mode) { 838 838 case NIC_MULTICAST_BLOCKED: … … 866 866 break; 867 867 } 868 868 869 869 fibril_mutex_unlock(&e1000->rx_lock); 870 870 return rc; … … 886 886 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 887 887 errno_t rc = EOK; 888 888 889 889 fibril_mutex_lock(&e1000->rx_lock); 890 890 891 891 switch (mode) { 892 892 case NIC_UNICAST_BLOCKED: … … 924 924 break; 925 925 } 926 926 927 927 fibril_mutex_unlock(&e1000->rx_lock); 928 928 return rc; … … 941 941 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 942 942 errno_t rc = EOK; 943 943 944 944 fibril_mutex_lock(&e1000->rx_lock); 945 945 946 946 switch (mode) { 947 947 case NIC_BROADCAST_BLOCKED: … … 955 955 break; 956 956 } 957 957 958 958 fibril_mutex_unlock(&e1000->rx_lock); 959 959 return rc; … … 971 971 if (E1000_REG_READ(e1000, E1000_RCTL) & (RCTL_EN)) 972 972 return true; 973 973 974 974 return false; 975 975 } … … 1009 1009 { 1010 1010 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1011 1011 1012 1012 fibril_mutex_lock(&e1000->rx_lock); 1013 1013 1014 1014 if (vlan_mask) { 1015 1015 /* … … 1020 1020 if (rx_enabled) 1021 1021 e1000_disable_rx(e1000); 1022 1022 1023 1023 for (unsigned int i = 0; i < NIC_VLAN_BITMAP_SIZE; i += 4) { 1024 1024 uint32_t bitmap_part = … … 1029 1029 E1000_REG_WRITE(e1000, E1000_VFTA_ARRAY(i / 4), bitmap_part); 1030 1030 } 1031 1031 1032 1032 e1000_enable_vlan_filter(e1000); 1033 1033 if (rx_enabled) … … 1035 1035 } else 1036 1036 e1000_disable_vlan_filter(e1000); 1037 1037 1038 1038 fibril_mutex_unlock(&e1000->rx_lock); 1039 1039 } … … 1054 1054 if (tag & VLANTAG_CFI) 1055 1055 return ENOTSUP; 1056 1056 1057 1057 /* 1058 1058 * CTRL.VME is neccessary for both strip and add … … 1061 1061 if (!strip && add) 1062 1062 return ENOTSUP; 1063 1063 1064 1064 e1000_t *e1000 = DRIVER_DATA_FUN(fun); 1065 1065 1066 1066 e1000->vlan_tag = tag; 1067 1067 e1000->vlan_tag_add = add; 1068 1068 1069 1069 fibril_mutex_lock(&e1000->ctrl_lock); 1070 1070 1071 1071 uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL); 1072 1072 if (strip) … … 1074 1074 else 1075 1075 ctrl &= ~CTRL_VME; 1076 1076 1077 1077 E1000_REG_WRITE(e1000, E1000_CTRL, ctrl); 1078 1078 1079 1079 fibril_mutex_unlock(&e1000->ctrl_lock); 1080 1080 return EOK; … … 1092 1092 { 1093 1093 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1094 1094 1095 1095 e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *) 1096 1096 (e1000->rx_ring_virt + offset * sizeof(e1000_rx_descriptor_t)); 1097 1097 1098 1098 rx_descriptor->phys_addr = PTR_TO_U64(e1000->rx_frame_phys[offset]); 1099 1099 rx_descriptor->length = 0; … … 1114 1114 e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *) 1115 1115 (e1000->rx_ring_virt + offset * sizeof(e1000_rx_descriptor_t)); 1116 1116 1117 1117 rx_descriptor->length = 0; 1118 1118 rx_descriptor->checksum = 0; … … 1131 1131 { 1132 1132 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1133 1133 1134 1134 e1000_tx_descriptor_t *tx_descriptor = (e1000_tx_descriptor_t *) 1135 1135 (e1000->tx_ring_virt + offset * sizeof(e1000_tx_descriptor_t)); 1136 1136 1137 1137 tx_descriptor->phys_addr = 0; 1138 1138 tx_descriptor->length = 0; … … 1168 1168 { 1169 1169 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1170 1170 1171 1171 fibril_mutex_lock(&e1000->rx_lock); 1172 1172 1173 1173 uint32_t *tail_addr = E1000_REG_ADDR(e1000, E1000_RDT); 1174 1174 uint32_t next_tail = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT); 1175 1175 1176 1176 e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *) 1177 1177 (e1000->rx_ring_virt + next_tail * sizeof(e1000_rx_descriptor_t)); 1178 1178 1179 1179 while (rx_descriptor->status & 0x01) { 1180 1180 uint32_t frame_size = rx_descriptor->length - E1000_CRC_SIZE; 1181 1181 1182 1182 nic_frame_t *frame = nic_alloc_frame(nic, frame_size); 1183 1183 if (frame != NULL) { … … 1187 1187 ddf_msg(LVL_ERROR, "Memory allocation failed. Frame dropped."); 1188 1188 } 1189 1189 1190 1190 e1000_fill_new_rx_descriptor(nic, next_tail); 1191 1191 1192 1192 *tail_addr = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT); 1193 1193 next_tail = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT); 1194 1194 1195 1195 rx_descriptor = (e1000_rx_descriptor_t *) 1196 1196 (e1000->rx_ring_virt + next_tail * sizeof(e1000_rx_descriptor_t)); 1197 1197 } 1198 1198 1199 1199 fibril_mutex_unlock(&e1000->rx_lock); 1200 1200 } … … 1247 1247 nic_t *nic = NIC_DATA_DEV(dev); 1248 1248 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1249 1249 1250 1250 e1000_interrupt_handler_impl(nic, icr); 1251 1251 e1000_enable_interrupts(e1000); … … 1267 1267 { 1268 1268 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1269 1269 1270 1270 /* Lock the mutex in whole driver while working with global structure */ 1271 1271 fibril_mutex_lock(&irq_reg_mutex); 1272 1272 1273 1273 e1000_irq_code.ranges[0].base = (uintptr_t) e1000->reg_base_phys; 1274 1274 e1000_irq_code.cmds[0].addr = e1000->reg_base_phys + E1000_ICR; 1275 1275 e1000_irq_code.cmds[2].addr = e1000->reg_base_phys + E1000_IMC; 1276 1276 1277 1277 errno_t rc = register_interrupt_handler(nic_get_ddf_dev(nic), e1000->irq, 1278 1278 e1000_interrupt_handler, &e1000_irq_code, handle); 1279 1279 1280 1280 fibril_mutex_unlock(&irq_reg_mutex); 1281 1281 return rc; … … 1290 1290 { 1291 1291 assert(nic); 1292 1292 1293 1293 e1000_t *e1000 = nic_get_specific(nic); 1294 1294 assert(e1000); 1295 1295 1296 1296 uint32_t icr = E1000_REG_READ(e1000, E1000_ICR); 1297 1297 e1000_interrupt_handler_impl(nic, icr); … … 1323 1323 { 1324 1324 assert(nic); 1325 1325 1326 1326 e1000_t *e1000 = nic_get_specific(nic); 1327 1327 assert(e1000); 1328 1328 1329 1329 switch (mode) { 1330 1330 case NIC_POLL_IMMEDIATE: … … 1344 1344 return ENOTSUP; 1345 1345 } 1346 1346 1347 1347 return EOK; 1348 1348 } … … 1357 1357 E1000_REG_WRITE(e1000, E1000_RDLEN, E1000_RX_FRAME_COUNT * 16); 1358 1358 E1000_REG_WRITE(e1000, E1000_RDH, 0); 1359 1359 1360 1360 /* It is not posible to let HW use all descriptors */ 1361 1361 E1000_REG_WRITE(e1000, E1000_RDT, E1000_RX_FRAME_COUNT - 1); 1362 1362 1363 1363 /* Set Broadcast Enable Bit */ 1364 1364 E1000_REG_WRITE(e1000, E1000_RCTL, RCTL_BAM); … … 1377 1377 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1378 1378 fibril_mutex_lock(&e1000->rx_lock); 1379 1379 1380 1380 e1000->rx_ring_virt = AS_AREA_ANY; 1381 1381 errno_t rc = dmamem_map_anonymous( … … 1385 1385 if (rc != EOK) 1386 1386 return rc; 1387 1387 1388 1388 E1000_REG_WRITE(e1000, E1000_RDBAH, 1389 1389 (uint32_t) (PTR_TO_U64(e1000->rx_ring_phys) >> 32)); 1390 1390 E1000_REG_WRITE(e1000, E1000_RDBAL, 1391 1391 (uint32_t) PTR_TO_U64(e1000->rx_ring_phys)); 1392 1392 1393 1393 e1000->rx_frame_phys = (uintptr_t *) 1394 1394 calloc(E1000_RX_FRAME_COUNT, sizeof(uintptr_t)); … … 1399 1399 goto error; 1400 1400 } 1401 1401 1402 1402 for (size_t i = 0; i < E1000_RX_FRAME_COUNT; i++) { 1403 1403 uintptr_t frame_phys; 1404 1404 void *frame_virt = AS_AREA_ANY; 1405 1405 1406 1406 rc = dmamem_map_anonymous(E1000_MAX_SEND_FRAME_SIZE, 1407 1407 DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0, … … 1409 1409 if (rc != EOK) 1410 1410 goto error; 1411 1411 1412 1412 e1000->rx_frame_phys[i] = frame_phys; 1413 1413 e1000->rx_frame_virt[i] = frame_virt; 1414 1414 } 1415 1415 1416 1416 /* Write descriptor */ 1417 1417 for (size_t i = 0; i < E1000_RX_FRAME_COUNT; i++) 1418 1418 e1000_fill_new_rx_descriptor(nic, i); 1419 1419 1420 1420 e1000_initialize_rx_registers(e1000); 1421 1421 1422 1422 fibril_mutex_unlock(&e1000->rx_lock); 1423 1423 return EOK; 1424 1424 1425 1425 error: 1426 1426 for (size_t i = 0; i < E1000_RX_FRAME_COUNT; i++) { … … 1431 1431 } 1432 1432 } 1433 1433 1434 1434 if (e1000->rx_frame_phys != NULL) { 1435 1435 free(e1000->rx_frame_phys); 1436 1436 e1000->rx_frame_phys = NULL; 1437 1437 } 1438 1438 1439 1439 if (e1000->rx_frame_virt != NULL) { 1440 1440 free(e1000->rx_frame_virt); 1441 1441 e1000->rx_frame_virt = NULL; 1442 1442 } 1443 1443 1444 1444 return rc; 1445 1445 } … … 1453 1453 { 1454 1454 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1455 1455 1456 1456 /* Write descriptor */ 1457 1457 for (unsigned int offset = 0; offset < E1000_RX_FRAME_COUNT; offset++) { … … 1460 1460 e1000->rx_frame_virt[offset] = NULL; 1461 1461 } 1462 1462 1463 1463 free(e1000->rx_frame_virt); 1464 1464 1465 1465 e1000->rx_frame_phys = NULL; 1466 1466 e1000->rx_frame_virt = NULL; 1467 1467 1468 1468 dmamem_unmap_anonymous(e1000->rx_ring_virt); 1469 1469 } … … 1550 1550 E1000_REG_WRITE(e1000, E1000_TDH, 0); 1551 1551 E1000_REG_WRITE(e1000, E1000_TDT, 0); 1552 1552 1553 1553 E1000_REG_WRITE(e1000, E1000_TIPG, 1554 1554 10 << TIPG_IPGT_SHIFT | 1555 1555 8 << TIPG_IPGR1_SHIFT | 1556 1556 6 << TIPG_IPGR2_SHIFT); 1557 1557 1558 1558 E1000_REG_WRITE(e1000, E1000_TCTL, 1559 1559 0x0F << TCTL_CT_SHIFT /* Collision Threshold */ | … … 1570 1570 { 1571 1571 size_t i; 1572 1572 1573 1573 fibril_mutex_lock(&e1000->tx_lock); 1574 1574 1575 1575 e1000->tx_ring_phys = 0; 1576 1576 e1000->tx_ring_virt = AS_AREA_ANY; 1577 1577 1578 1578 e1000->tx_frame_phys = NULL; 1579 1579 e1000->tx_frame_virt = NULL; 1580 1580 1581 1581 errno_t rc = dmamem_map_anonymous( 1582 1582 E1000_TX_FRAME_COUNT * sizeof(e1000_tx_descriptor_t), … … 1585 1585 if (rc != EOK) 1586 1586 goto error; 1587 1587 1588 1588 memset(e1000->tx_ring_virt, 0, 1589 1589 E1000_TX_FRAME_COUNT * sizeof(e1000_tx_descriptor_t)); 1590 1590 1591 1591 e1000->tx_frame_phys = (uintptr_t *) 1592 1592 calloc(E1000_TX_FRAME_COUNT, sizeof(uintptr_t)); … … 1598 1598 goto error; 1599 1599 } 1600 1600 1601 1601 for (i = 0; i < E1000_TX_FRAME_COUNT; i++) { 1602 1602 e1000->tx_frame_virt[i] = AS_AREA_ANY; … … 1607 1607 goto error; 1608 1608 } 1609 1609 1610 1610 E1000_REG_WRITE(e1000, E1000_TDBAH, 1611 1611 (uint32_t) (PTR_TO_U64(e1000->tx_ring_phys) >> 32)); 1612 1612 E1000_REG_WRITE(e1000, E1000_TDBAL, 1613 1613 (uint32_t) PTR_TO_U64(e1000->tx_ring_phys)); 1614 1614 1615 1615 e1000_initialize_tx_registers(e1000); 1616 1616 1617 1617 fibril_mutex_unlock(&e1000->tx_lock); 1618 1618 return EOK; 1619 1619 1620 1620 error: 1621 1621 if (e1000->tx_ring_virt != NULL) { … … 1623 1623 e1000->tx_ring_virt = NULL; 1624 1624 } 1625 1625 1626 1626 if ((e1000->tx_frame_phys != NULL) && (e1000->tx_frame_virt != NULL)) { 1627 1627 for (i = 0; i < E1000_TX_FRAME_COUNT; i++) { … … 1633 1633 } 1634 1634 } 1635 1635 1636 1636 if (e1000->tx_frame_phys != NULL) { 1637 1637 free(e1000->tx_frame_phys); 1638 1638 e1000->tx_frame_phys = NULL; 1639 1639 } 1640 1640 1641 1641 if (e1000->tx_frame_virt != NULL) { 1642 1642 free(e1000->tx_frame_virt); 1643 1643 e1000->tx_frame_virt = NULL; 1644 1644 } 1645 1645 1646 1646 return rc; 1647 1647 } … … 1655 1655 { 1656 1656 size_t i; 1657 1657 1658 1658 for (i = 0; i < E1000_TX_FRAME_COUNT; i++) { 1659 1659 dmamem_unmap_anonymous(e1000->tx_frame_virt[i]); … … 1661 1661 e1000->tx_frame_virt[i] = NULL; 1662 1662 } 1663 1663 1664 1664 if (e1000->tx_frame_phys != NULL) { 1665 1665 free(e1000->tx_frame_phys); 1666 1666 e1000->tx_frame_phys = NULL; 1667 1667 } 1668 1668 1669 1669 if (e1000->tx_frame_virt != NULL) { 1670 1670 free(e1000->tx_frame_virt); 1671 1671 e1000->tx_frame_virt = NULL; 1672 1672 } 1673 1673 1674 1674 dmamem_unmap_anonymous(e1000->tx_ring_virt); 1675 1675 } … … 1721 1721 { 1722 1722 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1723 1723 1724 1724 E1000_REG_WRITE(e1000, E1000_CTRL, CTRL_RST); 1725 1725 1726 1726 /* Wait for the reset */ 1727 1727 async_usleep(20); 1728 1728 1729 1729 /* check if RST_BIT cleared */ 1730 1730 if (E1000_REG_READ(e1000, E1000_CTRL) & (CTRL_RST)) 1731 1731 return EINVAL; 1732 1732 1733 1733 e1000_initialize_registers(e1000); 1734 1734 e1000_initialize_rx_registers(e1000); … … 1737 1737 e1000_initialize_filters(e1000); 1738 1738 e1000_initialize_vlan(e1000); 1739 1739 1740 1740 return EOK; 1741 1741 } … … 1752 1752 { 1753 1753 assert(nic); 1754 1754 1755 1755 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1756 1756 1757 1757 fibril_mutex_lock(&e1000->rx_lock); 1758 1758 fibril_mutex_lock(&e1000->tx_lock); 1759 1759 fibril_mutex_lock(&e1000->ctrl_lock); 1760 1760 1761 1761 e1000_enable_interrupts(e1000); 1762 1762 1763 1763 errno_t rc = hw_res_enable_interrupt(e1000->parent_sess, e1000->irq); 1764 1764 if (rc != EOK) { … … 1769 1769 return rc; 1770 1770 } 1771 1771 1772 1772 e1000_clear_rx_ring(e1000); 1773 1773 e1000_enable_rx(e1000); 1774 1774 1775 1775 e1000_clear_tx_ring(nic); 1776 1776 e1000_enable_tx(e1000); 1777 1777 1778 1778 uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL); 1779 1779 ctrl |= CTRL_SLU; 1780 1780 E1000_REG_WRITE(e1000, E1000_CTRL, ctrl); 1781 1781 1782 1782 fibril_mutex_unlock(&e1000->ctrl_lock); 1783 1783 fibril_mutex_unlock(&e1000->tx_lock); 1784 1784 fibril_mutex_unlock(&e1000->rx_lock); 1785 1785 1786 1786 return EOK; 1787 1787 } … … 1798 1798 { 1799 1799 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1800 1800 1801 1801 uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL); 1802 1802 ctrl &= ~CTRL_SLU; 1803 1803 E1000_REG_WRITE(e1000, E1000_CTRL, ctrl); 1804 1804 1805 1805 e1000_disable_tx(e1000); 1806 1806 e1000_disable_rx(e1000); 1807 1807 1808 1808 hw_res_disable_interrupt(e1000->parent_sess, e1000->irq); 1809 1809 e1000_disable_interrupts(e1000); 1810 1810 1811 1811 /* 1812 1812 * Wait for the for the end of all data … … 1814 1814 */ 1815 1815 async_usleep(100); 1816 1816 1817 1817 return EOK; 1818 1818 } … … 1829 1829 { 1830 1830 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1831 1831 1832 1832 fibril_mutex_lock(&e1000->rx_lock); 1833 1833 fibril_mutex_lock(&e1000->tx_lock); 1834 1834 fibril_mutex_lock(&e1000->ctrl_lock); 1835 1835 1836 1836 errno_t rc = e1000_on_down_unlocked(nic); 1837 1837 1838 1838 fibril_mutex_unlock(&e1000->ctrl_lock); 1839 1839 fibril_mutex_unlock(&e1000->tx_lock); 1840 1840 fibril_mutex_unlock(&e1000->rx_lock); 1841 1841 1842 1842 return rc; 1843 1843 } … … 1854 1854 { 1855 1855 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1856 1856 1857 1857 fibril_mutex_lock(&e1000->rx_lock); 1858 1858 fibril_mutex_lock(&e1000->tx_lock); 1859 1859 fibril_mutex_lock(&e1000->ctrl_lock); 1860 1860 1861 1861 errno_t rc = e1000_on_down_unlocked(nic); 1862 1862 if (rc == EOK) 1863 1863 rc = e1000_reset(nic); 1864 1864 1865 1865 fibril_mutex_unlock(&e1000->ctrl_lock); 1866 1866 fibril_mutex_unlock(&e1000->tx_lock); 1867 1867 fibril_mutex_unlock(&e1000->rx_lock); 1868 1868 1869 1869 return rc; 1870 1870 } … … 1880 1880 if (!nic) 1881 1881 return NULL; 1882 1882 1883 1883 e1000_t *e1000 = malloc(sizeof(e1000_t)); 1884 1884 if (!e1000) { … … 1886 1886 return NULL; 1887 1887 } 1888 1888 1889 1889 memset(e1000, 0, sizeof(e1000_t)); 1890 1890 e1000->dev = dev; 1891 1891 1892 1892 nic_set_specific(nic, e1000); 1893 1893 nic_set_send_frame_handler(nic, e1000_send_frame); … … 1898 1898 e1000_on_broadcast_mode_change, NULL, e1000_on_vlan_mask_change); 1899 1899 nic_set_poll_handlers(nic, e1000_poll_mode_change, e1000_poll); 1900 1900 1901 1901 fibril_mutex_initialize(&e1000->ctrl_lock); 1902 1902 fibril_mutex_initialize(&e1000->rx_lock); 1903 1903 fibril_mutex_initialize(&e1000->tx_lock); 1904 1904 fibril_mutex_initialize(&e1000->eeprom_lock); 1905 1905 1906 1906 return e1000; 1907 1907 } … … 1915 1915 { 1916 1916 assert(dev); 1917 1917 1918 1918 if (ddf_dev_data_get(dev) != NULL) 1919 1919 nic_unbind_and_destroy(dev); … … 1928 1928 { 1929 1929 assert(dev); 1930 1930 1931 1931 e1000_delete_dev_data(dev); 1932 1932 } … … 1947 1947 { 1948 1948 e1000_t *e1000 = DRIVER_DATA_DEV(dev); 1949 1949 1950 1950 if (hw_resources->irqs.count != 1) 1951 1951 return EINVAL; 1952 1952 1953 1953 e1000->irq = hw_resources->irqs.irqs[0]; 1954 1954 e1000->reg_base_phys = 1955 1955 MEMADDR_TO_PTR(RNGABS(hw_resources->mem_ranges.ranges[0])); 1956 1956 1957 1957 return EOK; 1958 1958 } … … 1972 1972 assert(dev != NULL); 1973 1973 assert(NIC_DATA_DEV(dev) != NULL); 1974 1974 1975 1975 hw_res_list_parsed_t hw_res_parsed; 1976 1976 hw_res_list_parsed_init(&hw_res_parsed); 1977 1977 1978 1978 /* Get hw resources form parent driver */ 1979 1979 errno_t rc = nic_get_resources(NIC_DATA_DEV(dev), &hw_res_parsed); 1980 1980 if (rc != EOK) 1981 1981 return rc; 1982 1982 1983 1983 /* Fill resources information to the device */ 1984 1984 rc = e1000_fill_resource_info(dev, &hw_res_parsed); 1985 1985 hw_res_list_parsed_clean(&hw_res_parsed); 1986 1986 1987 1987 return rc; 1988 1988 } … … 2004 2004 return ENOMEM; 2005 2005 } 2006 2006 2007 2007 e1000->parent_sess = ddf_dev_parent_sess_get(dev); 2008 2008 if (e1000->parent_sess == NULL) { … … 2010 2010 return EIO; 2011 2011 } 2012 2012 2013 2013 /* Obtain and fill hardware resources info */ 2014 2014 errno_t rc = e1000_get_resource_info(dev); … … 2018 2018 return rc; 2019 2019 } 2020 2020 2021 2021 uint16_t device_id; 2022 2022 rc = pci_config_space_read_16(ddf_dev_parent_sess_get(dev), PCI_DEVICE_ID, … … 2027 2027 return rc; 2028 2028 } 2029 2029 2030 2030 e1000_board_t board; 2031 2031 switch (device_id) { … … 2077 2077 return ENOTSUP; 2078 2078 } 2079 2079 2080 2080 switch (board) { 2081 2081 case E1000_82540: … … 2098 2098 break; 2099 2099 } 2100 2100 2101 2101 return EOK; 2102 2102 } … … 2113 2113 { 2114 2114 e1000_t *e1000 = DRIVER_DATA_DEV(dev); 2115 2115 2116 2116 errno_t rc = pio_enable(e1000->reg_base_phys, 8 * PAGE_SIZE, 2117 2117 &e1000->reg_base_virt); 2118 2118 if (rc != EOK) 2119 2119 return EADDRNOTAVAIL; 2120 2120 2121 2121 return EOK; 2122 2122 } … … 2130 2130 { 2131 2131 ddf_fun_t *fun; 2132 2132 2133 2133 /* Initialize device structure for E1000 */ 2134 2134 errno_t rc = e1000_device_initialize(dev); 2135 2135 if (rc != EOK) 2136 2136 return rc; 2137 2137 2138 2138 /* Device initialization */ 2139 2139 nic_t *nic = ddf_dev_data_get(dev); 2140 2140 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 2141 2141 2142 2142 /* Map registers */ 2143 2143 rc = e1000_pio_enable(dev); 2144 2144 if (rc != EOK) 2145 2145 goto err_destroy; 2146 2146 2147 2147 e1000_initialize_registers(e1000); 2148 2148 rc = e1000_initialize_tx_structure(e1000); 2149 2149 if (rc != EOK) 2150 2150 goto err_pio; 2151 2151 2152 2152 fibril_mutex_lock(&e1000->rx_lock); 2153 2153 2154 2154 e1000_fill_mac_from_eeprom(e1000); 2155 2155 e1000_initialize_filters(e1000); 2156 2156 2157 2157 fibril_mutex_unlock(&e1000->rx_lock); 2158 2158 2159 2159 e1000_initialize_vlan(e1000); 2160 2160 2161 2161 fun = ddf_fun_create(nic_get_ddf_dev(nic), fun_exposed, "port0"); 2162 2162 if (fun == NULL) … … 2164 2164 nic_set_ddf_fun(nic, fun); 2165 2165 ddf_fun_set_ops(fun, &e1000_dev_ops); 2166 2166 2167 2167 int irq_cap; 2168 2168 rc = e1000_register_int_handler(nic, &irq_cap); … … 2170 2170 goto err_fun_create; 2171 2171 } 2172 2172 2173 2173 rc = e1000_initialize_rx_structure(nic); 2174 2174 if (rc != EOK) 2175 2175 goto err_irq; 2176 2176 2177 2177 nic_address_t e1000_address; 2178 2178 e1000_get_address(e1000, &e1000_address); … … 2180 2180 if (rc != EOK) 2181 2181 goto err_rx_structure; 2182 2182 2183 2183 struct timeval period; 2184 2184 period.tv_sec = 0; … … 2187 2187 if (rc != EOK) 2188 2188 goto err_rx_structure; 2189 2189 2190 2190 rc = ddf_fun_bind(fun); 2191 2191 if (rc != EOK) 2192 2192 goto err_fun_bind; 2193 2193 2194 2194 rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC); 2195 2195 if (rc != EOK) 2196 2196 goto err_add_to_cat; 2197 2197 2198 2198 return EOK; 2199 2199 2200 2200 err_add_to_cat: 2201 2201 ddf_fun_unbind(fun); … … 2230 2230 { 2231 2231 fibril_mutex_lock(&e1000->eeprom_lock); 2232 2232 2233 2233 /* Write address and START bit to EERD register */ 2234 2234 uint32_t write_data = e1000->info.eerd_start | … … 2236 2236 e1000->info.eerd_address_offset); 2237 2237 E1000_REG_WRITE(e1000, E1000_EERD, write_data); 2238 2238 2239 2239 uint32_t eerd = E1000_REG_READ(e1000, E1000_EERD); 2240 2240 while ((eerd & e1000->info.eerd_done) == 0) { … … 2242 2242 eerd = E1000_REG_READ(e1000, E1000_EERD); 2243 2243 } 2244 2244 2245 2245 fibril_mutex_unlock(&e1000->eeprom_lock); 2246 2246 2247 2247 return (uint16_t) (eerd >> e1000->info.eerd_data_offset); 2248 2248 } … … 2261 2261 { 2262 2262 fibril_mutex_lock(&e1000->rx_lock); 2263 2263 2264 2264 uint8_t *mac0_dest = (uint8_t *) address->address; 2265 2265 uint8_t *mac1_dest = (uint8_t *) address->address + 1; … … 2268 2268 uint8_t *mac4_dest = (uint8_t *) address->address + 4; 2269 2269 uint8_t *mac5_dest = (uint8_t *) address->address + 5; 2270 2270 2271 2271 uint32_t rah = E1000_REG_READ(e1000, E1000_RAH_ARRAY(0)); 2272 2272 uint32_t ral = E1000_REG_READ(e1000, E1000_RAL_ARRAY(0)); 2273 2273 2274 2274 *mac0_dest = (uint8_t) ral; 2275 2275 *mac1_dest = (uint8_t) (ral >> 8); … … 2278 2278 *mac4_dest = (uint8_t) rah; 2279 2279 *mac5_dest = (uint8_t) (rah >> 8); 2280 2280 2281 2281 fibril_mutex_unlock(&e1000->rx_lock); 2282 2282 return EOK; … … 2295 2295 nic_t *nic = NIC_DATA_FUN(fun); 2296 2296 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 2297 2297 2298 2298 fibril_mutex_lock(&e1000->rx_lock); 2299 2299 fibril_mutex_lock(&e1000->tx_lock); 2300 2300 2301 2301 errno_t rc = nic_report_address(nic, addr); 2302 2302 if (rc == EOK) 2303 2303 e1000_write_receive_address(e1000, 0, addr, false); 2304 2304 2305 2305 fibril_mutex_unlock(&e1000->tx_lock); 2306 2306 fibril_mutex_unlock(&e1000->rx_lock); 2307 2307 2308 2308 return rc; 2309 2309 } … … 2315 2315 uint16_t *mac2_dest = (uint16_t *) (address->address + 2); 2316 2316 uint16_t *mac4_dest = (uint16_t *) (address->address + 4); 2317 2317 2318 2318 *mac0_dest = e1000_eeprom_read(e1000, 0); 2319 2319 *mac2_dest = e1000_eeprom_read(e1000, 1); … … 2334 2334 { 2335 2335 assert(nic); 2336 2336 2337 2337 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 2338 2338 fibril_mutex_lock(&e1000->tx_lock); 2339 2339 2340 2340 uint32_t tdt = E1000_REG_READ(e1000, E1000_TDT); 2341 2341 e1000_tx_descriptor_t *tx_descriptor_addr = (e1000_tx_descriptor_t *) 2342 2342 (e1000->tx_ring_virt + tdt * sizeof(e1000_tx_descriptor_t)); 2343 2343 2344 2344 bool descriptor_available = false; 2345 2345 2346 2346 /* Descriptor never used */ 2347 2347 if (tx_descriptor_addr->length == 0) 2348 2348 descriptor_available = true; 2349 2349 2350 2350 /* Descriptor done */ 2351 2351 if (tx_descriptor_addr->status & TXDESCRIPTOR_STATUS_DD) 2352 2352 descriptor_available = true; 2353 2353 2354 2354 if (!descriptor_available) { 2355 2355 /* Frame lost */ … … 2357 2357 return; 2358 2358 } 2359 2359 2360 2360 memcpy(e1000->tx_frame_virt[tdt], data, size); 2361 2361 2362 2362 tx_descriptor_addr->phys_addr = PTR_TO_U64(e1000->tx_frame_phys[tdt]); 2363 2363 tx_descriptor_addr->length = size; 2364 2364 2365 2365 /* 2366 2366 * Report status to STATUS.DD (descriptor done), … … 2370 2370 TXDESCRIPTOR_COMMAND_IFCS | 2371 2371 TXDESCRIPTOR_COMMAND_EOP; 2372 2372 2373 2373 tx_descriptor_addr->checksum_offset = 0; 2374 2374 tx_descriptor_addr->status = 0; … … 2378 2378 } else 2379 2379 tx_descriptor_addr->special = 0; 2380 2380 2381 2381 tx_descriptor_addr->checksum_start_field = 0; 2382 2382 2383 2383 tdt++; 2384 2384 if (tdt == E1000_TX_FRAME_COUNT) 2385 2385 tdt = 0; 2386 2386 2387 2387 E1000_REG_WRITE(e1000, E1000_TDT, tdt); 2388 2388 2389 2389 fibril_mutex_unlock(&e1000->tx_lock); 2390 2390 } … … 2393 2393 { 2394 2394 printf("%s: HelenOS E1000 network adapter driver\n", NAME); 2395 2395 2396 2396 if (nic_driver_init(NAME) != EOK) 2397 2397 return 1; 2398 2398 2399 2399 nic_driver_implement(&e1000_driver_ops, &e1000_dev_ops, 2400 2400 &e1000_nic_iface); 2401 2401 2402 2402 ddf_log_init(NAME); 2403 2403 return ddf_driver_main(&e1000_driver); -
uspace/drv/nic/e1k/e1k.h
r3061bc1 ra35b458 97 97 uint32_t eerd_start; 98 98 uint32_t eerd_done; 99 99 100 100 uint32_t eerd_address_offset; 101 101 uint32_t eerd_data_offset; … … 159 159 CTRL_SLU = (1 << 6), /**< Set Link Up */ 160 160 CTRL_ILOS = (1 << 7), /**< Invert Loss-of-Signal */ 161 161 162 162 /** Speed selection shift */ 163 163 CTRL_SPEED_SHIFT = 8, … … 174 174 /** Speed selection 10 Mb/s value */ 175 175 CTRL_SPEED_1000 = 2, 176 176 177 177 CTRL_FRCSPD = (1 << 11), /**< Force Speed */ 178 178 CTRL_FRCDPLX = (1 << 12), /**< Force Duplex */ … … 186 186 STATUS_FD = (1 << 0), /**< Link Full Duplex configuration Indication */ 187 187 STATUS_LU = (1 << 1), /**< Link Up Indication */ 188 188 189 189 /** Link speed setting shift */ 190 190 STATUS_SPEED_SHIFT = 6, -
uspace/drv/nic/ne2k/dp8390.c
r3061bc1 ra35b458 74 74 /** Copy of RSR */ 75 75 uint8_t status; 76 76 77 77 /** Pointer to next frame */ 78 78 uint8_t next; 79 79 80 80 /** Receive Byte Count Low */ 81 81 uint8_t rbcl; 82 82 83 83 /** Receive Byte Count High */ 84 84 uint8_t rbch; … … 95 95 { 96 96 size_t i; 97 97 98 98 for (i = 0; (i << 1) < size; i++) 99 99 *((uint16_t *) buf + i) = pio_read_16((ioport16_t *) (port)); … … 110 110 { 111 111 size_t i; 112 112 113 113 for (i = 0; (i << 1) < size; i++) 114 114 pio_write_16((ioport16_t *) port, *((uint16_t *) buf + i)); … … 118 118 { 119 119 size_t esize = size & ~1; 120 120 121 121 pio_write_8(ne2k->port + DP_RBCR0, esize & 0xff); 122 122 pio_write_8(ne2k->port + DP_RBCR1, (esize >> 8) & 0xff); … … 124 124 pio_write_8(ne2k->port + DP_RSAR1, (addr >> 8) & 0xff); 125 125 pio_write_8(ne2k->port + DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA); 126 126 127 127 if (esize != 0) { 128 128 pio_read_buf_16(ne2k->data_port, buf, esize); … … 130 130 buf += esize; 131 131 } 132 132 133 133 if (size) { 134 134 assert(size == 1); 135 135 136 136 uint16_t word = pio_read_16(ne2k->data_port); 137 137 memcpy(buf, &word, 1); … … 143 143 size_t esize_ru = (size + 1) & ~1; 144 144 size_t esize = size & ~1; 145 145 146 146 pio_write_8(ne2k->port + DP_RBCR0, esize_ru & 0xff); 147 147 pio_write_8(ne2k->port + DP_RBCR1, (esize_ru >> 8) & 0xff); … … 149 149 pio_write_8(ne2k->port + DP_RSAR1, (addr >> 8) & 0xff); 150 150 pio_write_8(ne2k->port + DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA); 151 151 152 152 if (esize != 0) { 153 153 pio_write_buf_16(ne2k->data_port, buf, esize); … … 155 155 buf += esize; 156 156 } 157 157 158 158 if (size) { 159 159 assert(size == 1); 160 160 161 161 uint16_t word = 0; 162 162 163 163 memcpy(&word, buf, 1); 164 164 pio_write_16(ne2k->data_port, word); … … 169 169 { 170 170 unsigned int i; 171 171 172 172 /* Reset the ethernet card */ 173 173 uint8_t val = pio_read_8(ne2k->port + NE2K_RESET); … … 175 175 pio_write_8(ne2k->port + NE2K_RESET, val); 176 176 async_usleep(2000); 177 177 178 178 /* Reset the DP8390 */ 179 179 pio_write_8(ne2k->port + DP_CR, CR_STP | CR_DM_ABORT); … … 197 197 { 198 198 unsigned int i; 199 199 200 200 ne2k_init(ne2k); 201 201 202 202 /* Check if the DP8390 is really there */ 203 203 uint8_t val = pio_read_8(ne2k->port + DP_CR); 204 204 if ((val & (CR_STP | CR_TXP | CR_DM_ABORT)) != (CR_STP | CR_DM_ABORT)) 205 205 return EXDEV; 206 206 207 207 /* Disable the receiver and init TCR and DCR */ 208 208 pio_write_8(ne2k->port + DP_RCR, RCR_MON); 209 209 pio_write_8(ne2k->port + DP_TCR, TCR_NORMAL); 210 210 pio_write_8(ne2k->port + DP_DCR, DCR_WORDWIDE | DCR_8BYTES | DCR_BMS); 211 211 212 212 /* Setup a transfer to get the MAC address */ 213 213 pio_write_8(ne2k->port + DP_RBCR0, ETH_ADDR << 1); … … 216 216 pio_write_8(ne2k->port + DP_RSAR1, 0); 217 217 pio_write_8(ne2k->port + DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA); 218 218 219 219 for (i = 0; i < ETH_ADDR; i++) 220 220 ne2k->mac.address[i] = pio_read_16(ne2k->data_port); 221 221 222 222 return EOK; 223 223 } … … 226 226 { 227 227 memcpy(&ne2k->mac, address, sizeof(nic_address_t)); 228 228 229 229 pio_write_8(ne2k->port + DP_CR, CR_PS_P0 | CR_DM_ABORT | CR_STP); 230 230 231 231 pio_write_8(ne2k->port + DP_RBCR0, ETH_ADDR << 1); 232 232 pio_write_8(ne2k->port + DP_RBCR1, 0); … … 254 254 if (!ne2k->probed) 255 255 return EXDEV; 256 256 257 257 ne2k_init(ne2k); 258 258 259 259 /* 260 260 * Setup send queue. Use the first … … 266 266 fibril_mutex_initialize(&ne2k->sq_mutex); 267 267 fibril_condvar_initialize(&ne2k->sq_cv); 268 268 269 269 /* 270 270 * Setup receive ring buffer. Use all the rest … … 275 275 ne2k->start_page = ne2k->sq.page + SQ_PAGES; 276 276 ne2k->stop_page = ne2k->sq.page + NE2K_SIZE / DP_PAGE; 277 277 278 278 /* 279 279 * Initialization of the DP8390 following the mandatory procedure … … 281 281 * Controller", National Semiconductor, July 1995, Page 29). 282 282 */ 283 283 284 284 /* Step 1: */ 285 285 pio_write_8(ne2k->port + DP_CR, CR_PS_P0 | CR_STP | CR_DM_ABORT); 286 286 287 287 /* Step 2: */ 288 288 pio_write_8(ne2k->port + DP_DCR, DCR_WORDWIDE | DCR_8BYTES | DCR_BMS); 289 289 290 290 /* Step 3: */ 291 291 pio_write_8(ne2k->port + DP_RBCR0, 0); 292 292 pio_write_8(ne2k->port + DP_RBCR1, 0); 293 293 294 294 /* Step 4: */ 295 295 pio_write_8(ne2k->port + DP_RCR, ne2k->receive_configuration); 296 296 297 297 /* Step 5: */ 298 298 pio_write_8(ne2k->port + DP_TCR, TCR_INTERNAL); 299 299 300 300 /* Step 6: */ 301 301 pio_write_8(ne2k->port + DP_BNRY, ne2k->start_page); 302 302 pio_write_8(ne2k->port + DP_PSTART, ne2k->start_page); 303 303 pio_write_8(ne2k->port + DP_PSTOP, ne2k->stop_page); 304 304 305 305 /* Step 7: */ 306 306 pio_write_8(ne2k->port + DP_ISR, 0xff); 307 307 308 308 /* Step 8: */ 309 309 pio_write_8(ne2k->port + DP_IMR, 310 310 IMR_PRXE | IMR_PTXE | IMR_RXEE | IMR_TXEE | IMR_OVWE | IMR_CNTE); 311 311 312 312 /* Step 9: */ 313 313 pio_write_8(ne2k->port + DP_CR, CR_PS_P1 | CR_DM_ABORT | CR_STP); 314 314 315 315 pio_write_8(ne2k->port + DP_PAR0, ne2k->mac.address[0]); 316 316 pio_write_8(ne2k->port + DP_PAR1, ne2k->mac.address[1]); … … 319 319 pio_write_8(ne2k->port + DP_PAR4, ne2k->mac.address[4]); 320 320 pio_write_8(ne2k->port + DP_PAR5, ne2k->mac.address[5]); 321 321 322 322 pio_write_8(ne2k->port + DP_MAR0, 0); 323 323 pio_write_8(ne2k->port + DP_MAR1, 0); … … 328 328 pio_write_8(ne2k->port + DP_MAR6, 0); 329 329 pio_write_8(ne2k->port + DP_MAR7, 0); 330 330 331 331 pio_write_8(ne2k->port + DP_CURR, ne2k->start_page + 1); 332 332 333 333 /* Step 10: */ 334 334 pio_write_8(ne2k->port + DP_CR, CR_PS_P0 | CR_DM_ABORT | CR_STA); 335 335 336 336 /* Step 11: */ 337 337 pio_write_8(ne2k->port + DP_TCR, TCR_NORMAL); 338 338 339 339 /* Reset counters by reading */ 340 340 pio_read_8(ne2k->port + DP_CNTR0); 341 341 pio_read_8(ne2k->port + DP_CNTR1); 342 342 pio_read_8(ne2k->port + DP_CNTR2); 343 343 344 344 /* Finish the initialization */ 345 345 ne2k->up = true; … … 415 415 416 416 fibril_mutex_lock(&ne2k->sq_mutex); 417 417 418 418 while (ne2k->sq.dirty) { 419 419 fibril_condvar_wait(&ne2k->sq_cv, &ne2k->sq_mutex); 420 420 } 421 421 422 422 if ((size < ETH_MIN_PACK_SIZE) || (size > ETH_MAX_PACK_SIZE_TAGGED)) { 423 423 fibril_mutex_unlock(&ne2k->sq_mutex); … … 446 446 if (frame == NULL) 447 447 return NULL; 448 448 449 449 memset(frame->data, 0, length); 450 450 uint8_t last = page + length / DP_PAGE; 451 451 452 452 if (last >= ne2k->stop_page) { 453 453 size_t left = (ne2k->stop_page - page) * DP_PAGE … … 481 481 //TODO: isn't some locking necessary here? 482 482 uint8_t boundary = pio_read_8(ne2k->port + DP_BNRY) + 1; 483 483 484 484 if (boundary == ne2k->stop_page) 485 485 boundary = ne2k->start_page; 486 486 487 487 pio_write_8(ne2k->port + DP_CR, CR_PS_P1 | CR_STA); 488 488 uint8_t current = pio_read_8(ne2k->port + DP_CURR); … … 491 491 /* No more frames to process */ 492 492 break; 493 493 494 494 recv_header_t header; 495 495 size_t size = sizeof(header); 496 496 size_t offset = boundary * DP_PAGE; 497 497 498 498 /* Get the frame header */ 499 499 pio_write_8(ne2k->port + DP_RBCR0, size & 0xff); … … 502 502 pio_write_8(ne2k->port + DP_RSAR1, (offset >> 8) & 0xff); 503 503 pio_write_8(ne2k->port + DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA); 504 504 505 505 pio_read_buf_16(ne2k->data_port, (void *) &header, size); 506 506 … … 508 508 (((size_t) header.rbcl) | (((size_t) header.rbch) << 8)) - size; 509 509 uint8_t next = header.next; 510 510 511 511 if ((length < ETH_MIN_PACK_SIZE) 512 512 || (length > ETH_MAX_PACK_SIZE_TAGGED)) { … … 535 535 break; 536 536 } 537 537 538 538 /* 539 539 * Update the boundary pointer … … 585 585 ne2k->sq.dirty = false; 586 586 ne2k->sq.size = 0; 587 587 588 588 /* Signal a next frame to be sent */ 589 589 fibril_condvar_broadcast(&ne2k->sq_cv); … … 615 615 ne2k_reset(ne2k); 616 616 } 617 617 618 618 /* Unmask interrupts to be processed in the next round */ 619 619 pio_write_8(ne2k->port + DP_IMR, … … 627 627 else 628 628 ne2k->receive_configuration &= ~RCR_AB; 629 629 630 630 pio_write_8(ne2k->port + DP_RCR, ne2k->receive_configuration); 631 631 } … … 637 637 else 638 638 ne2k->receive_configuration &= ~RCR_AM; 639 639 640 640 pio_write_8(ne2k->port + DP_RCR, ne2k->receive_configuration); 641 641 } … … 647 647 else 648 648 ne2k->receive_configuration &= ~RCR_PRO; 649 649 650 650 pio_write_8(ne2k->port + DP_RCR, ne2k->receive_configuration); 651 651 } … … 655 655 /* Select Page 1 and stop all transfers */ 656 656 pio_write_8(ne2k->port + DP_CR, CR_PS_P1 | CR_DM_ABORT | CR_STP); 657 657 658 658 pio_write_8(ne2k->port + DP_MAR0, (uint8_t) hash); 659 659 pio_write_8(ne2k->port + DP_MAR1, (uint8_t) (hash >> 8)); … … 664 664 pio_write_8(ne2k->port + DP_MAR6, (uint8_t) (hash >> 48)); 665 665 pio_write_8(ne2k->port + DP_MAR7, (uint8_t) (hash >> 56)); 666 666 667 667 /* Select Page 0 and resume transfers */ 668 668 pio_write_8(ne2k->port + DP_CR, CR_PS_P0 | CR_DM_ABORT | CR_STA); -
uspace/drv/nic/ne2k/dp8390.h
r3061bc1 ra35b458 235 235 int irq; 236 236 nic_address_t mac; 237 237 238 238 uint8_t start_page; /**< Ring buffer start page */ 239 239 uint8_t stop_page; /**< Ring buffer stop page */ 240 240 241 241 /* Send queue */ 242 242 struct { … … 247 247 fibril_mutex_t sq_mutex; 248 248 fibril_condvar_t sq_cv; 249 249 250 250 /* Driver run-time variables */ 251 251 bool probed; -
uspace/drv/nic/ne2k/ne2k.c
r3061bc1 ra35b458 183 183 hw_res_list_parsed_t hw_res_parsed; 184 184 hw_res_list_parsed_init(&hw_res_parsed); 185 185 186 186 errno_t rc = nic_get_resources(nic_data, &hw_res_parsed); 187 187 188 188 if (rc != EOK) 189 189 goto failed; 190 190 191 191 if (hw_res_parsed.irqs.count == 0) { 192 192 rc = EINVAL; 193 193 goto failed; 194 194 } 195 195 196 196 if (hw_res_parsed.io_ranges.count == 0) { 197 197 rc = EINVAL; 198 198 goto failed; 199 199 } 200 200 201 201 if (hw_res_parsed.io_ranges.ranges[0].size < NE2K_IO_SIZE) { 202 202 rc = EINVAL; 203 203 goto failed; 204 204 } 205 205 206 206 ne2k_t *ne2k = (ne2k_t *) nic_get_specific(nic_data); 207 207 ne2k->irq = hw_res_parsed.irqs.irqs[0]; 208 208 209 209 addr_range_t regs = hw_res_parsed.io_ranges.ranges[0]; 210 210 ne2k->base_port = RNGABSPTR(regs); 211 211 212 212 hw_res_list_parsed_clean(&hw_res_parsed); 213 213 214 214 /* Enable programmed I/O */ 215 215 if (pio_enable_range(®s, &ne2k->port) != EOK) 216 216 return EADDRNOTAVAIL; 217 217 218 218 ne2k->data_port = ne2k->port + NE2K_DATA; 219 219 ne2k->receive_configuration = RCR_AB | RCR_AM; 220 220 ne2k->probed = false; 221 221 ne2k->up = false; 222 222 223 223 /* Find out whether the device is present. */ 224 224 if (ne2k_probe(ne2k) != EOK) 225 225 return ENOENT; 226 226 227 227 ne2k->probed = true; 228 228 229 229 if (ne2k_register_interrupt(nic_data, NULL) != EOK) 230 230 return EINVAL; 231 231 232 232 return EOK; 233 233 234 234 failed: 235 235 hw_res_list_parsed_clean(&hw_res_parsed); … … 358 358 { 359 359 ddf_fun_t *fun; 360 360 361 361 /* Allocate driver data for the device. */ 362 362 nic_t *nic_data = nic_create_and_bind(dev); 363 363 if (nic_data == NULL) 364 364 return ENOMEM; 365 365 366 366 nic_set_send_frame_handler(nic_data, ne2k_send); 367 367 nic_set_state_change_handlers(nic_data, … … 370 370 ne2k_on_unicast_mode_change, ne2k_on_multicast_mode_change, 371 371 ne2k_on_broadcast_mode_change, NULL, NULL); 372 372 373 373 ne2k_t *ne2k = malloc(sizeof(ne2k_t)); 374 374 if (NULL != ne2k) { … … 379 379 return ENOMEM; 380 380 } 381 381 382 382 ne2k->dev = dev; 383 383 ne2k->parent_sess = ddf_dev_parent_sess_get(dev); … … 386 386 return ENOMEM; 387 387 } 388 388 389 389 errno_t rc = ne2k_dev_init(nic_data); 390 390 if (rc != EOK) { … … 392 392 return rc; 393 393 } 394 394 395 395 rc = nic_report_address(nic_data, &ne2k->mac); 396 396 if (rc != EOK) { … … 398 398 return rc; 399 399 } 400 400 401 401 fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0"); 402 402 if (fun == NULL) { … … 404 404 return ENOMEM; 405 405 } 406 406 407 407 nic_set_ddf_fun(nic_data, fun); 408 408 ddf_fun_set_ops(fun, &ne2k_dev_ops); 409 409 410 410 rc = ddf_fun_bind(fun); 411 411 if (rc != EOK) { … … 414 414 return rc; 415 415 } 416 416 417 417 rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC); 418 418 if (rc != EOK) { … … 421 421 return rc; 422 422 } 423 423 424 424 return EOK; 425 425 } … … 441 441 { 442 442 printf("%s: HelenOS NE 2000 network adapter driver\n", NAME); 443 443 444 444 nic_driver_init(NAME); 445 445 nic_driver_implement(&ne2k_driver_ops, &ne2k_dev_ops, &ne2k_nic_iface); 446 446 447 447 return ddf_driver_main(&ne2k_driver); 448 448 } -
uspace/drv/nic/rtl8139/driver.c
r3061bc1 ra35b458 156 156 | rtl8139->rcr_data.defect_mask | 157 157 (RXBUF_SIZE_FLAGS << RCR_RBLEN_SHIFT); 158 158 159 159 ddf_msg(LVL_DEBUG, "Rewriting rcr: %x -> %x", pio_read_32(rtl8139->io_port + RCR), 160 160 rcr); … … 419 419 pio_write_32(tsd, tsd_value); 420 420 return; 421 421 422 422 err_busy_no_inc: 423 423 err_size: … … 550 550 bytes_received %= RxBUF_SIZE; 551 551 rx_offset %= RxBUF_SIZE; 552 552 553 553 /* count how many bytes to read maximaly */ 554 554 if (bytes_received < rx_offset) … … 775 775 { 776 776 assert(nic_data); 777 777 778 778 nic_poll_mode_t poll_mode = nic_query_poll_mode(nic_data, 0); 779 779 … … 1104 1104 1105 1105 ddf_msg(LVL_DEBUG, "Creating buffers"); 1106 1106 1107 1107 rtl8139->tx_buff_virt = AS_AREA_ANY; 1108 1108 rc = dmamem_map_anonymous(TX_PAGES * PAGE_SIZE, DMAMEM_4GiB, … … 1125 1125 ddf_msg(LVL_DEBUG, "Allocating receiver buffer of the size %d bytes", 1126 1126 RxBUF_TOT_LENGTH); 1127 1127 1128 1128 rtl8139->rx_buff_virt = AS_AREA_ANY; 1129 1129 rc = dmamem_map_anonymous(RxBUF_TOT_LENGTH, DMAMEM_4GiB, … … 1195 1195 ddf_msg(LVL_DEBUG, "The device is initialized"); 1196 1196 return ret; 1197 1197 1198 1198 failed: 1199 1199 ddf_msg(LVL_ERROR, "The device initialization failed"); … … 1318 1318 1319 1319 return EOK; 1320 1320 1321 1321 err_fun_bind: 1322 1322 ddf_fun_unbind(fun); … … 1547 1547 if (rtl8139_pause_is_valid(rtl8139) != VALUE_RW) 1548 1548 return EINVAL; 1549 1549 1550 1550 uint8_t msr = pio_read_8(rtl8139->io_port + MSR); 1551 1551 msr &= ~(uint8_t)(MSR_TXFCE | MSR_RXFCE); … … 1555 1555 if (allow_send) 1556 1556 msr |= MSR_TXFCE; 1557 1557 1558 1558 pio_write_8(rtl8139->io_port + MSR, msr); 1559 1559 … … 1624 1624 if ((advertisement | RTL8139_AUTONEG_CAPS) != RTL8139_AUTONEG_CAPS) 1625 1625 return EINVAL; /* some unsuported mode is requested */ 1626 1626 1627 1627 assert(advertisement != 0); 1628 1628 -
uspace/drv/nic/rtl8139/general.h
r3061bc1 ra35b458 45 45 /** Register value set in the last timer period */ 46 46 uint32_t last_val; 47 47 48 48 /** Register value set in the common timer period */ 49 49 uint32_t full_val; 50 50 51 51 /** Amount of full register periods in timer period */ 52 52 size_t full_skips; 53 53 54 54 /** Remaining full register periods to the next period end */ 55 55 size_t full_skips_remains; 56 56 57 57 /** Mark if there is a last run */ 58 58 int last_run; -
uspace/drv/nic/rtl8169/driver.c
r3061bc1 ra35b458 352 352 ddf_msg(LVL_DEBUG, "The device is initialized"); 353 353 return ret; 354 354 355 355 failed: 356 356 ddf_msg(LVL_ERROR, "The device initialization failed"); … … 460 460 goto err_fun_bind; 461 461 } 462 462 463 463 ddf_msg(LVL_NOTE, "The %s device has been successfully initialized.", 464 464 ddf_dev_get_name(dev)); … … 512 512 if (rtl8169->pci_vid == PCI_VID_REALTEK) 513 513 str_cpy(info->vendor_name, NIC_VENDOR_MAX_LENGTH, "Realtek"); 514 514 515 515 if (rtl8169->pci_vid == PCI_VID_DLINK) 516 516 str_cpy(info->vendor_name, NIC_VENDOR_MAX_LENGTH, "D-Link"); 517 517 518 518 if (rtl8169->pci_pid == 0x8168) 519 519 str_cpy(info->model_name, NIC_MODEL_MAX_LENGTH, "RTL8168"); 520 520 521 521 if (rtl8169->pci_pid == 0x8169) 522 522 str_cpy(info->model_name, NIC_MODEL_MAX_LENGTH, "RTL8169"); … … 577 577 bmcr = rtl8169_mii_read(rtl8169, MII_BMCR); 578 578 bmcr &= ~(BMCR_DUPLEX | BMCR_SPD_100 | BMCR_SPD_1000); 579 579 580 580 /* Disable autonegotiation */ 581 581 bmcr &= ~BMCR_AN_ENABLE; … … 918 918 { 919 919 rtl8169_t *rtl8169 = nic_get_specific(nic_data); 920 920 921 921 /* Configure Receive Control Register */ 922 922 uint32_t rcr = pio_read_32(rtl8169->regs + RCR); … … 961 961 write_barrier(); 962 962 ddf_msg(LVL_DEBUG, "TX status for descr %d: 0x%08x", tail, descr->control); 963 963 964 964 tail = (tail + 1) % TX_BUFFERS_COUNT; 965 965 sent++; … … 1005 1005 if (descr->control & CONTROL_FS) 1006 1006 fsidx = tail; 1007 1007 1008 1008 if (descr->control & CONTROL_LS) { 1009 1009 ddf_msg(LVL_DEBUG, "received message at slot %d, control 0x%08x", tail, descr->control);
Note:
See TracChangeset
for help on using the changeset viewer.