Changeset a35b458 in mainline for uspace/drv/nic/ar9271
- 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/ar9271
- Files:
-
- 10 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,
Note:
See TracChangeset
for help on using the changeset viewer.
