Changeset a35b458 in mainline for uspace/drv/nic/ar9271


Ignore:
Timestamp:
2018-03-02T20:10:49Z (8 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
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)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

Location:
uspace/drv/nic/ar9271
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/nic/ar9271/ar9271.c

    r3061bc1 ra35b458  
    148148        assert(dev);
    149149        assert(info);
    150        
     150
    151151        memset(info, 0, sizeof(nic_device_info_t));
    152        
     152
    153153        info->vendor_id = 0x0cf3;
    154154        info->device_id = 0x9271;
     
    157157        str_cpy(info->model_name, NIC_MODEL_MAX_LENGTH,
    158158            "AR9271");
    159        
     159
    160160        return EOK;
    161161}
     
    167167{
    168168        *state = NIC_CS_PLUGGED;
    169        
     169
    170170        return EOK;
    171171}
     
    180180        *speed = 10;
    181181        *role = NIC_ROLE_UNKNOWN;
    182        
     182
    183183        return EOK;
    184184}
     
    203203                return ENOTSUP;
    204204        }
    205        
     205
    206206        return EOK;
    207207}
     
    229229                return ENOTSUP;
    230230        }
    231        
     231
    232232        return EOK;
    233233}
     
    249249                return ENOTSUP;
    250250        }
    251        
     251
    252252        return EOK;
    253253}
     
    261261{
    262262        assert(arg);
    263        
     263
    264264        ar9271_t *ar9271 = (ar9271_t *) arg;
    265        
     265
    266266        size_t buffer_size = ar9271->ath_device->data_response_length;
    267267        void *buffer = malloc(buffer_size);
    268        
     268
    269269        while (true) {
    270270                size_t transferred_size;
     
    275275                            sizeof(htc_frame_header_t) +
    276276                            sizeof(htc_rx_status_t);
    277                        
     277
    278278                        if (transferred_size < strip_length)
    279279                                continue;
    280                        
     280
    281281                        ath_usb_data_header_t *data_header =
    282282                            (ath_usb_data_header_t *) buffer;
    283                        
     283
    284284                        /* Invalid packet. */
    285285                        if (data_header->tag != uint16_t_le2host(RX_TAG))
    286286                                continue;
    287                        
     287
    288288                        htc_rx_status_t *rx_status =
    289289                            (htc_rx_status_t *) ((void *) buffer +
    290290                            sizeof(ath_usb_data_header_t) +
    291291                            sizeof(htc_frame_header_t));
    292                        
     292
    293293                        uint16_t data_length =
    294294                            uint16_t_be2host(rx_status->data_length);
    295                        
     295
    296296                        int16_t payload_length =
    297297                            transferred_size - strip_length;
    298                        
     298
    299299                        if (payload_length - data_length < 0)
    300300                                continue;
    301                        
     301
    302302                        if (ar9271_rx_status_error(rx_status->status))
    303303                                continue;
    304                        
     304
    305305                        void *strip_buffer = buffer + strip_length;
    306                        
     306
    307307                        ieee80211_rx_handler(ar9271->ieee80211_dev,
    308308                            strip_buffer,
     
    310310                }
    311311        }
    312        
     312
    313313        free(buffer);
    314        
     314
    315315        return EOK;
    316316}
     
    323323{
    324324        assert(ieee80211_dev);
    325        
     325
    326326        ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev);
    327        
     327
    328328        wmi_send_command(ar9271->htc_device, WMI_DISABLE_INTR, NULL, 0, NULL);
    329329        wmi_send_command(ar9271->htc_device, WMI_DRAIN_TXQ_ALL, NULL, 0, NULL);
    330330        wmi_send_command(ar9271->htc_device, WMI_STOP_RECV, NULL, 0, NULL);
    331        
     331
    332332        errno_t rc = hw_freq_switch(ar9271, freq);
    333333        if (rc != EOK) {
     
    335335                return rc;
    336336        }
    337        
     337
    338338        wmi_send_command(ar9271->htc_device, WMI_START_RECV, NULL, 0, NULL);
    339        
     339
    340340        rc = hw_rx_init(ar9271);
    341341        if (rc != EOK) {
     
    343343                return rc;
    344344        }
    345        
     345
    346346        uint16_t htc_mode = host2uint16_t_be(1);
    347347        wmi_send_command(ar9271->htc_device, WMI_SET_MODE,
    348348            (uint8_t *) &htc_mode, sizeof(htc_mode), NULL);
    349349        wmi_send_command(ar9271->htc_device, WMI_ENABLE_INTR, NULL, 0, NULL);
    350        
     350
    351351        return EOK;
    352352}
     
    356356{
    357357        assert(ieee80211_dev);
    358        
     358
    359359        ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev);
    360        
     360
    361361        if (connected) {
    362362                nic_address_t bssid;
    363363                ieee80211_query_bssid(ieee80211_dev, &bssid);
    364                
     364
    365365                htc_sta_msg_t sta_msg;
    366366                memset(&sta_msg, 0, sizeof(htc_sta_msg_t));
     
    371371                sta_msg.vif_index = 0;
    372372                memcpy(&sta_msg.addr, bssid.address, ETH_ADDR);
    373                
     373
    374374                wmi_send_command(ar9271->htc_device, WMI_NODE_CREATE,
    375375                    (uint8_t *) &sta_msg, sizeof(sta_msg), NULL);
    376                
     376
    377377                htc_rate_msg_t rate_msg;
    378378                memset(&rate_msg, 0, sizeof(htc_rate_msg_t));
     
    383383                    ieee80211bg_data_rates,
    384384                    ARRAY_SIZE(ieee80211bg_data_rates));
    385                
     385
    386386                wmi_send_command(ar9271->htc_device, WMI_RC_RATE_UPDATE,
    387387                    (uint8_t *) &rate_msg, sizeof(rate_msg), NULL);
    388                
     388
    389389                hw_set_rx_filter(ar9271, true);
    390390        } else {
     
    392392                wmi_send_command(ar9271->htc_device, WMI_NODE_REMOVE,
    393393                    &station_id, sizeof(station_id), NULL);
    394                
     394
    395395                hw_set_rx_filter(ar9271, false);
    396396        }
    397        
     397
    398398        hw_set_bssid(ar9271);
    399        
     399
    400400        return EOK;
    401401}
     
    405405{
    406406        assert(ieee80211_dev);
    407        
     407
    408408        ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev);
    409        
     409
    410410        if(insert) {
    411411                assert(key_conf);
    412                
     412
    413413                uint32_t key[5];
    414414                uint32_t key_type;
    415415                uint32_t reg_ptr, mic_reg_ptr;
    416416                void *data_start;
    417                
     417
    418418                nic_address_t bssid;
    419419                ieee80211_query_bssid(ieee80211_dev, &bssid);
    420                
     420
    421421                switch (key_conf->suite) {
    422422                case IEEE80211_SECURITY_SUITE_WEP40:
     
    435435                        key_type = -1;
    436436                }
    437                
     437
    438438                uint8_t key_id =
    439439                    (key_conf->flags & IEEE80211_KEY_FLAG_TYPE_PAIRWISE) ?
    440440                    AR9271_STA_KEY_INDEX : key_conf->id;
    441                
     441
    442442                reg_ptr = AR9271_KEY_TABLE(key_id);
    443443                mic_reg_ptr = AR9271_KEY_TABLE(key_id + 64);
    444444                data_start = (void *) key_conf->data;
    445                
     445
    446446                key[0] = uint32_t_le2host(*((uint32_t *) data_start));
    447447                key[1] = uint16_t_le2host(*((uint16_t *) (data_start + 4)));
     
    449449                key[3] = uint16_t_le2host(*((uint16_t *) (data_start + 10)));
    450450                key[4] = uint32_t_le2host(*((uint32_t *) (data_start + 12)));
    451                
     451
    452452                if ((key_conf->suite == IEEE80211_SECURITY_SUITE_WEP40) ||
    453453                    (key_conf->suite == IEEE80211_SECURITY_SUITE_WEP104))
    454454                        key[4] &= 0xFF;
    455                
     455
    456456                wmi_reg_write(ar9271->htc_device, reg_ptr + 0, key[0]);
    457457                wmi_reg_write(ar9271->htc_device, reg_ptr + 4, key[1]);
     
    460460                wmi_reg_write(ar9271->htc_device, reg_ptr + 16, key[4]);
    461461                wmi_reg_write(ar9271->htc_device, reg_ptr + 20, key_type);
    462                
     462
    463463                uint32_t macl;
    464464                uint32_t mach;
     
    471471                        mach = 0;
    472472                }
    473                
     473
    474474                macl >>= 1;
    475475                macl |= (mach & 1) << 31;
    476476                mach >>= 1;
    477477                mach |= 0x8000;
    478                
     478
    479479                wmi_reg_write(ar9271->htc_device, reg_ptr + 24, macl);
    480480                wmi_reg_write(ar9271->htc_device, reg_ptr + 28, mach);
    481                
     481
    482482                /* Setup MIC keys for TKIP. */
    483483                if (key_conf->suite == IEEE80211_SECURITY_SUITE_TKIP) {
     
    485485                        uint8_t *gen_mic = data_start + IEEE80211_TKIP_RX_MIC_OFFSET;
    486486                        uint8_t *tx_mic;
    487                        
     487
    488488                        if (key_conf->flags & IEEE80211_KEY_FLAG_TYPE_GROUP)
    489489                                tx_mic = gen_mic;
    490490                        else
    491491                                tx_mic = data_start + IEEE80211_TKIP_TX_MIC_OFFSET;
    492                        
     492
    493493                        mic[0] = uint32_t_le2host(*((uint32_t *) gen_mic));
    494494                        mic[1] = uint16_t_le2host(*((uint16_t *) (tx_mic + 2))) & 0xFFFF;
     
    496496                        mic[3] = uint16_t_le2host(*((uint16_t *) tx_mic)) & 0xFFFF;
    497497                        mic[4] = uint32_t_le2host(*((uint32_t *) (tx_mic + 4)));
    498                        
     498
    499499                        wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 0, mic[0]);
    500500                        wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 4, mic[1]);
     
    504504                        wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 20,
    505505                            AR9271_KEY_TABLE_TYPE_CLR);
    506                        
     506
    507507                        wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 24, 0);
    508508                        wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 28, 0);
    509509                }
    510                
     510
    511511                if (key_conf->flags & IEEE80211_KEY_FLAG_TYPE_GROUP)
    512512                        ieee80211_setup_key_confirm(ieee80211_dev, true);
     
    515515                ieee80211_setup_key_confirm(ieee80211_dev, false);
    516516        }
    517        
     517
    518518        return EOK;
    519519}
     
    523523{
    524524        assert(ieee80211_dev);
    525        
     525
    526526        size_t complete_size;
    527527        size_t offset;
    528528        void *complete_buffer;
    529529        int endpoint;
    530        
     530
    531531        ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev);
    532        
     532
    533533        uint16_t frame_ctrl = *((uint16_t *) buffer);
    534534        if (ieee80211_is_data_frame(frame_ctrl)) {
     
    538538                complete_buffer = malloc(complete_size);
    539539                memset(complete_buffer, 0, complete_size);
    540                
     540
    541541                /*
    542542                 * Because we handle just station mode yet, node ID and VIF ID
     
    550550                data_header->vif_idx = 0;
    551551                data_header->cookie = 0;
    552                
     552
    553553                if (ieee80211_query_using_key(ieee80211_dev)) {
    554554                        data_header->keyix = AR9271_STA_KEY_INDEX;
    555                        
     555
    556556                        int sec_suite =
    557557                            ieee80211_get_pairwise_security(ieee80211_dev);
    558                        
     558
    559559                        switch (sec_suite) {
    560560                        case IEEE80211_SECURITY_SUITE_WEP40:
     
    573573                        data_header->keyix = 0xFF;
    574574                }
    575                
     575
    576576                endpoint = ar9271->htc_device->endpoints.data_be_endpoint;
    577577        } else {
     
    581581                complete_buffer = malloc(complete_size);
    582582                memset(complete_buffer, 0, complete_size);
    583                
     583
    584584                /*
    585585                 * Because we handle just station mode yet, node ID and VIF ID
     
    593593                mgmt_header->cookie = 0;
    594594                mgmt_header->keyix = 0xFF;
    595                
     595
    596596                endpoint = ar9271->htc_device->endpoints.mgmt_endpoint;
    597597        }
    598        
     598
    599599        /* Copy IEEE802.11 data to new allocated buffer with HTC headers. */
    600600        memcpy(complete_buffer + offset, buffer, buffer_size);
    601        
     601
    602602        htc_send_data_message(ar9271->htc_device, complete_buffer,
    603603            complete_size, endpoint);
    604        
     604
    605605        free(complete_buffer);
    606        
     606
    607607        return EOK;
    608608}
     
    611611{
    612612        assert(ieee80211_dev);
    613        
     613
    614614        ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev);
    615        
     615
    616616        wmi_send_command(ar9271->htc_device, WMI_FLUSH_RECV, NULL, 0, NULL);
    617        
     617
    618618        errno_t rc = hw_reset(ar9271);
    619619        if (rc != EOK) {
     
    621621                return rc;
    622622        }
    623        
     623
    624624        uint16_t htc_mode = host2uint16_t_be(1);
    625625        wmi_send_command(ar9271->htc_device, WMI_SET_MODE,
     
    628628        wmi_send_command(ar9271->htc_device, WMI_START_RECV, NULL, 0, NULL);
    629629        wmi_send_command(ar9271->htc_device, WMI_ENABLE_INTR, NULL, 0, NULL);
    630        
     630
    631631        rc = hw_rx_init(ar9271);
    632632        if (rc != EOK) {
     
    634634                return rc;
    635635        }
    636        
     636
    637637        /* Send capability message to target. */
    638638        htc_cap_msg_t cap_msg;
     
    641641        cap_msg.enable_coex = 0;
    642642        cap_msg.tx_chainmask = 0x1;
    643        
     643
    644644        wmi_send_command(ar9271->htc_device, WMI_TARGET_IC_UPDATE,
    645645            (uint8_t *) &cap_msg, sizeof(cap_msg), NULL);
    646        
     646
    647647        rc = htc_init_new_vif(ar9271->htc_device);
    648648        if (rc != EOK) {
     
    650650                return rc;
    651651        }
    652        
     652
    653653        /* Add data polling fibril. */
    654654        fid_t fibril = fibril_create(ar9271_data_polling, ar9271);
    655655        if (fibril == 0)
    656656                return ENOMEM;
    657        
     657
    658658        fibril_add_ready(fibril);
    659        
     659
    660660        ar9271->starting_up = false;
    661661        ieee80211_set_ready(ieee80211_dev, true);
    662        
     662
    663663        usb_log_info("Device fully initialized.\n");
    664        
     664
    665665        return EOK;
    666666}
     
    670670        ar9271->starting_up = true;
    671671        ar9271->usb_device = usb_device;
    672        
     672
    673673        fibril_mutex_initialize(&ar9271->ar9271_lock);
    674        
     674
    675675        ar9271->ath_device = calloc(1, sizeof(ath_t));
    676676        if (!ar9271->ath_device) {
     
    679679                return ENOMEM;
    680680        }
    681        
     681
    682682        errno_t rc = ath_usb_init(ar9271->ath_device, usb_device, endpoints);
    683683        if (rc != EOK) {
     
    686686                return rc;
    687687        }
    688        
     688
    689689        /* IEEE 802.11 framework structure initialization. */
    690690        ar9271->ieee80211_dev = ieee80211_device_create();
     
    695695                return ENOMEM;
    696696        }
    697        
     697
    698698        rc = ieee80211_device_init(ar9271->ieee80211_dev, ar9271->ddf_dev);
    699699        if (rc != EOK) {
     
    704704                return rc;
    705705        }
    706        
     706
    707707        ieee80211_set_specific(ar9271->ieee80211_dev, ar9271);
    708        
     708
    709709        /* HTC device structure initialization. */
    710710        ar9271->htc_device = calloc(1, sizeof(htc_device_t));
     
    716716                return ENOMEM;
    717717        }
    718        
     718
    719719        rc = htc_device_init(ar9271->ath_device, ar9271->ieee80211_dev,
    720720            ar9271->htc_device);
     
    726726                return rc;
    727727        }
    728        
     728
    729729        return EOK;
    730730}
     
    740740{
    741741        usb_device_t *usb_device = ar9271->usb_device;
    742        
     742
    743743        /* TODO: Set by maximum packet size in pipe. */
    744744        static const size_t MAX_TRANSFER_SIZE = 512;
    745        
     745
    746746        /* Load FW from file. */
    747747        FILE *fw_file = fopen(FIRMWARE_FILENAME, "rb");
     
    750750                return ENOENT;
    751751        }
    752        
     752
    753753        fseek(fw_file, 0, SEEK_END);
    754754        uint64_t file_size = ftell(fw_file);
    755755        fseek(fw_file, 0, SEEK_SET);
    756        
     756
    757757        void *fw_data = malloc(file_size);
    758758        if (fw_data == NULL) {
     
    761761                return ENOMEM;
    762762        }
    763        
     763
    764764        fread(fw_data, file_size, 1, fw_file);
    765765        fclose(fw_file);
    766        
     766
    767767        /* Upload FW to device. */
    768768        uint64_t remain_size = file_size;
     
    770770        uint8_t *current_data = fw_data;
    771771        uint8_t *buffer = malloc(MAX_TRANSFER_SIZE);
    772        
     772
    773773        while (remain_size > 0) {
    774774                size_t chunk_size = min(remain_size, MAX_TRANSFER_SIZE);
     
    788788                        return rc;
    789789                }
    790                
     790
    791791                remain_size -= chunk_size;
    792792                current_addr += chunk_size;
    793793                current_data += chunk_size;
    794794        }
    795        
     795
    796796        free(fw_data);
    797797        free(buffer);
    798        
     798
    799799        /*
    800800         * Send command that firmware is successfully uploaded.
     
    809809            uint16_host2usb(AR9271_FW_OFFSET >> 8),
    810810            0, NULL, 0);
    811        
     811
    812812        if (rc != EOK) {
    813813                usb_log_error("IO error when sending fw upload confirmation "
     
    815815                return rc;
    816816        }
    817        
     817
    818818        usb_log_info("Firmware uploaded successfully.\n");
    819        
     819
    820820        /* Wait until firmware is ready - wait for 1 second to be sure. */
    821821        async_sleep(1);
    822        
     822
    823823        return rc;
    824824}
     
    840840                return NULL;
    841841        }
    842        
     842
    843843        /* AR9271 structure initialization. */
    844844        ar9271_t *ar9271 = calloc(1, sizeof(ar9271_t));
     
    848848                return NULL;
    849849        }
    850        
     850
    851851        ar9271->ddf_dev = dev;
    852        
     852
    853853        rc = ar9271_init(ar9271, usb_device_get(dev), endpoints);
    854854        if (rc != EOK) {
     
    858858                return NULL;
    859859        }
    860        
     860
    861861        return ar9271;
    862862}
     
    869869{
    870870        assert(ar9271);
    871        
     871
    872872        // TODO
    873873}
     
    882882{
    883883        assert(dev);
    884        
     884
    885885        /* Allocate driver data for the device. */
    886886        ar9271_t *ar9271 = ar9271_create_dev_data(dev);
     
    889889                return ENOMEM;
    890890        }
    891        
     891
    892892        usb_log_info("HelenOS AR9271 device initialized.\n");
    893        
     893
    894894        /* Upload AR9271 firmware. */
    895895        ar9271_upload_fw(ar9271);
    896        
     896
    897897        /* Initialize AR9271 HTC services. */
    898898        errno_t rc = htc_init(ar9271->htc_device);
     
    902902                return rc;
    903903        }
    904        
     904
    905905        /* Initialize AR9271 HW. */
    906906        rc = hw_init(ar9271);
     
    910910                return rc;
    911911        }
    912        
     912
    913913        /* Initialize AR9271 IEEE 802.11 framework. */
    914914        rc = ieee80211_init(ar9271->ieee80211_dev, &ar9271_ieee80211_ops,
     
    920920                return rc;
    921921        }
    922        
     922
    923923        nic_set_filtering_change_handlers(nic_get_from_ddf_dev(dev),
    924924            ar9271_on_unicast_mode_change, ar9271_on_multicast_mode_change,
    925925            ar9271_on_broadcast_mode_change, NULL, NULL);
    926        
     926
    927927        usb_log_info("HelenOS AR9271 added device.\n");
    928        
     928
    929929        return EOK;
    930930}
     
    933933{
    934934        log_init(NAME);
    935        
     935
    936936        if (nic_driver_init(NAME) != EOK)
    937937                return 1;
    938        
     938
    939939        usb_log_info("HelenOS AR9271 driver started.\n");
    940        
     940
    941941        return ddf_driver_main(&ar9271_driver);
    942942}
  • uspace/drv/nic/ar9271/ar9271.h

    r3061bc1 ra35b458  
    6969        AR9271_COMMAND = 0x0008,
    7070        AR9271_COMMAND_RX_ENABLE = 0x00000004,
    71        
     71
    7272        /* ATH config register */
    7373        AR9271_CONFIG = 0x0014,
    7474        AR9271_CONFIG_ADHOC = 0x00000020,
    75        
     75
    7676        AR9271_QUEUE_BASE_MASK = 0x1000,
    77        
     77
    7878        /* EEPROM Addresses */
    7979        AR9271_EEPROM_BASE = 0x2100,
    8080        AR9271_EEPROM_MAC_ADDR_START = 0x2118,
    81        
     81
    8282        /* Reset MAC interface */
    8383        AR9271_RC = 0x4000,
    8484        AR9271_RC_AHB = 0x00000001,
    85        
     85
    8686        /* GPIO registers */
    8787        AR9271_GPIO_IN_OUT = 0x4048,       /**< GPIO value read/set  */
     
    9292        AR9271_GPIO_OUT_MUX3 = 0x4068,
    9393        AR9271_GPIO_OUT_MUX_AS_OUT = 0x0,  /**< GPIO set mux as output */
    94        
     94
    9595        /* RTC related registers */
    9696        AR9271_RTC_RC = 0x7000,
     
    109109        AR9271_RTC_FORCE_WAKE_ENABLE = 0x00000001,
    110110        AR9271_RTC_FORCE_WAKE_ON_INT = 0x00000002,
    111        
     111
    112112        /* MAC Registers */
    113113        AR9271_STATION_ID0 = 0x8000,  /**< STA Address Lower 32 Bits */
     
    122122        AR9271_MULTICAST_FILTER2 = 0x8044,
    123123        AR9271_DIAG = 0x8048,
    124        
     124
    125125        /* RX filtering register */
    126126        AR9271_RX_FILTER = 0x803C,
     
    134134        AR9271_RX_FILTER_MYBEACON = 0x00000200,
    135135        AR9271_RX_FILTER_MCAST_BCAST_ALL = 0x00008000,
    136        
     136
    137137        /* Key related registers */
    138138        AR9271_KEY_TABLE_BASE = 0x8800,
     
    142142        AR9271_KEY_TABLE_TYPE_CCMP = 0x6,
    143143        AR9271_KEY_TABLE_TYPE_CLR = 0x7,
    144        
     144
    145145        /* Physical layer registers */
    146146        AR9271_PHY_ACTIVE = 0x981C,
     
    168168        AR9271_PHY_TPCRG1_PD_CALIB = 0x00400000,
    169169        AR9271_CARRIER_LEAK_CALIB = 0x00000002,
    170        
     170
    171171        AR9271_OPMODE_STATION_AP_MASK = 0x00010000,
    172172        AR9271_OPMODE_ADHOC_MASK = 0x00020000,
    173        
     173
    174174        AR9271_CLOCK_CONTROL = 0x50040,
    175175        AR9271_MAX_CPU_CLOCK = 0x304,
    176        
     176
    177177        AR9271_RESET_POWER_DOWN_CONTROL = 0x50044,
    178178        AR9271_RADIO_RF_RESET = 0x20,
    179179        AR9271_GATE_MAC_CONTROL = 0x4000,
    180        
     180
    181181        /* FW Addresses */
    182182        AR9271_FW_ADDRESS = 0x501000,
     
    197197        /** Lock for access. */
    198198        fibril_mutex_t ar9271_lock;
    199        
     199
    200200        /** Whether device is starting up. */
    201201        bool starting_up;
    202        
     202
    203203        /** Backing DDF device */
    204204        ddf_dev_t *ddf_dev;
    205        
     205
    206206        /** USB device data */
    207207        usb_device_t *usb_device;
    208        
     208
    209209        /** IEEE 802.11 device data */
    210210        ieee80211_dev_t *ieee80211_dev;
    211        
     211
    212212        /** ATH device data */
    213213        ath_t *ath_device;
    214        
     214
    215215        /** HTC device data */
    216216        htc_device_t *htc_device;
  • uspace/drv/nic/ar9271/ath.h

    r3061bc1 ra35b458  
    5050        /** Maximum length of data response message. */
    5151        size_t data_response_length;
    52        
     52
    5353        /** Maximum length of control response message. */
    5454        size_t ctrl_response_length;
    55        
     55
    5656        /** Implementation specific data. */
    5757        void *specific_data;
    58        
     58
    5959        /** Generic Atheros wifi operations. */
    6060        const ath_ops_t *ops;
  • uspace/drv/nic/ar9271/ath_usb.c

    r3061bc1 ra35b458  
    6868                return ENOMEM;
    6969        }
    70        
     70
    7171        ath_usb->usb_device = usb_device;
    72        
     72
    7373        int rc;
    7474
     
    8989
    9090#undef _MAP_EP
    91        
     91
    9292        ath->ctrl_response_length = 64;
    9393        ath->data_response_length = 512;
    94        
     94
    9595        ath->specific_data = ath_usb;
    9696        ath->ops = &ath_usb_ops;
    97        
     97
    9898        return EOK;
    9999err_ath_usb:
     
    152152        memcpy(complete_buffer + sizeof(ath_usb_data_header_t),
    153153            buffer, buffer_size);
    154        
     154
    155155        ath_usb_data_header_t *data_header =
    156156            (ath_usb_data_header_t *) complete_buffer;
    157157        data_header->length = host2uint16_t_le(buffer_size);
    158158        data_header->tag = host2uint16_t_le(TX_TAG);
    159        
     159
    160160        ath_usb_t *ath_usb = (ath_usb_t *) ath->specific_data;
    161161        const errno_t ret_val = usb_pipe_write(ath_usb->output_data_pipe,
    162162            complete_buffer, complete_buffer_size);
    163        
     163
    164164        free(complete_buffer);
    165        
     165
    166166        return ret_val;
    167167}
  • uspace/drv/nic/ar9271/ath_usb.h

    r3061bc1 ra35b458  
    4949        usb_pipe_t *input_data_pipe;
    5050        usb_pipe_t *output_data_pipe;
    51        
     51
    5252        /** Pointer to connected USB device. */
    5353        usb_device_t *usb_device;
  • uspace/drv/nic/ar9271/htc.c

    r3061bc1 ra35b458  
    7070        htc_vif_msg_t vif_msg;
    7171        htc_sta_msg_t sta_msg;
    72        
     72
    7373        memset(&vif_msg, 0, sizeof(htc_vif_msg_t));
    7474        memset(&sta_msg, 0, sizeof(htc_sta_msg_t));
    75        
     75
    7676        nic_address_t addr;
    7777        nic_t *nic =
    7878            nic_get_from_ddf_dev(ieee80211_get_ddf_dev(htc_device->ieee80211_dev));
    7979        nic_query_address(nic, &addr);
    80        
     80
    8181        memcpy(&vif_msg.addr, &addr.address, ETH_ADDR);
    8282        memcpy(&sta_msg.addr, &addr.address, ETH_ADDR);
    83        
     83
    8484        ieee80211_operating_mode_t op_mode =
    8585            ieee80211_query_current_op_mode(htc_device->ieee80211_dev);
    86        
     86
    8787        switch (op_mode) {
    8888        case IEEE80211_OPMODE_ADHOC:
     
    9999                break;
    100100        }
    101        
     101
    102102        vif_msg.index = 0;
    103103        vif_msg.rts_thres = host2uint16_t_be(HTC_RTS_THRESHOLD);
    104        
     104
    105105        wmi_send_command(htc_device, WMI_VAP_CREATE, (uint8_t *) &vif_msg,
    106106            sizeof(vif_msg), NULL);
    107        
     107
    108108        sta_msg.is_vif_sta = 1;
    109109        sta_msg.max_ampdu = host2uint16_t_be(0xFFFF);
    110110        sta_msg.sta_index = 0;
    111111        sta_msg.vif_index = 0;
    112        
     112
    113113        wmi_send_command(htc_device, WMI_NODE_CREATE, (uint8_t *) &sta_msg,
    114114            sizeof(sta_msg), NULL);
    115        
     115
    116116        /* Write first 4 bytes of MAC address. */
    117117        uint32_t id0;
     
    119119        id0 = host2uint32_t_le(id0);
    120120        wmi_reg_write(htc_device, AR9271_STATION_ID0, id0);
    121        
     121
    122122        /* Write last 2 bytes of MAC address (and preserve existing data). */
    123123        uint32_t id1;
    124124        wmi_reg_read(htc_device, AR9271_STATION_ID1, &id1);
    125        
     125
    126126        uint16_t id1_addr;
    127127        memcpy(&id1_addr, &addr.address[4], 2);
    128128        id1 = (id1 & ~AR9271_STATION_ID1_MASK) | host2uint16_t_le(id1_addr);
    129129        wmi_reg_write(htc_device, AR9271_STATION_ID1, id1);
    130        
     130
    131131        return EOK;
    132132}
     
    136136{
    137137        memset(header, 0, sizeof(htc_frame_header_t));
    138        
     138
    139139        header->endpoint_id = endpoint_id;
    140140        header->payload_length =
     
    158158        htc_config_frame_header((htc_frame_header_t *) buffer, buffer_size,
    159159            endpoint_id);
    160        
     160
    161161        ath_t *ath_device = htc_device->ath_device;
    162        
     162
    163163        return ath_device->ops->send_ctrl_message(ath_device, buffer,
    164164            buffer_size);
     
    181181        htc_config_frame_header((htc_frame_header_t *) buffer, buffer_size,
    182182            endpoint_id);
    183        
     183
    184184        ath_t *ath_device = htc_device->ath_device;
    185        
     185
    186186        return ath_device->ops->send_data_message(ath_device, buffer,
    187187            buffer_size);
     
    203203{
    204204        ath_t *ath_device = htc_device->ath_device;
    205        
     205
    206206        return ath_device->ops->read_data_message(ath_device, buffer,
    207207            buffer_size, transferred_size);
     
    223223{
    224224        ath_t *ath_device = htc_device->ath_device;
    225        
     225
    226226        return ath_device->ops->read_ctrl_message(ath_device, buffer,
    227227            buffer_size, transferred_size);
     
    246246        void *buffer = malloc(buffer_size);
    247247        memset(buffer, 0, buffer_size);
    248        
     248
    249249        /* Fill service message structure. */
    250250        htc_service_msg_t *service_message = (htc_service_msg_t *)
     
    259259            wmi_service_to_upload_pipe(service_id);
    260260        service_message->connection_flags = 0;
    261        
     261
    262262        /* Send HTC message. */
    263263        errno_t rc = htc_send_control_message(htc_device, buffer, buffer_size,
     
    268268                return rc;
    269269        }
    270        
     270
    271271        free(buffer);
    272        
     272
    273273        buffer_size = htc_device->ath_device->ctrl_response_length;
    274274        buffer = malloc(buffer_size);
    275        
     275
    276276        /* Read response from device. */
    277277        rc = htc_read_control_message(htc_device, buffer, buffer_size, NULL);
     
    282282                return rc;
    283283        }
    284        
     284
    285285        htc_service_resp_msg_t *response_message = (htc_service_resp_msg_t *)
    286286            ((void *) buffer + sizeof(htc_frame_header_t));
    287        
     287
    288288        /*
    289289         * If service was successfully connected,
     
    299299                rc = EINVAL;
    300300        }
    301        
     301
    302302        free(buffer);
    303        
     303
    304304        return rc;
    305305}
     
    319319        htc_config_msg_t *config_message = (htc_config_msg_t *)
    320320            ((void *) buffer + sizeof(htc_frame_header_t));
    321        
     321
    322322        config_message->message_id =
    323323            host2uint16_t_be(HTC_MESSAGE_CONFIG);
     
    325325        config_message->credits = 33;
    326326        config_message->pipe_id = 1;
    327        
     327
    328328        /* Send HTC message. */
    329329        errno_t rc = htc_send_control_message(htc_device, buffer, buffer_size,
     
    335335                return rc;
    336336        }
    337        
     337
    338338        free(buffer);
    339        
     339
    340340        buffer_size = htc_device->ath_device->ctrl_response_length;
    341341        buffer = malloc(buffer_size);
    342        
     342
    343343        /* Check response from device. */
    344344        rc = htc_read_control_message(htc_device, buffer, buffer_size, NULL);
     
    347347                    "Error: %s\n", str_error_name(rc));
    348348        }
    349        
     349
    350350        free(buffer);
    351        
     351
    352352        return rc;
    353353}
     
    368368            (htc_setup_complete_msg_t *)
    369369            ((void *) buffer + sizeof(htc_frame_header_t));
    370        
     370
    371371        complete_message->message_id =
    372372            host2uint16_t_be(HTC_MESSAGE_SETUP_COMPLETE);
    373        
     373
    374374        /* Send HTC message. */
    375375        errno_t rc = htc_send_control_message(htc_device, buffer, buffer_size,
     
    378378                usb_log_error("Failed to send HTC setup complete message. "
    379379                    "Error: %s\n", str_error_name(rc));
    380        
     380
    381381        free(buffer);
    382        
     382
    383383        return rc;
    384384}
     
    398398        size_t buffer_size = htc_device->ath_device->ctrl_response_length;
    399399        void *buffer = malloc(buffer_size);
    400        
     400
    401401        /* Read response from device. */
    402402        errno_t rc = htc_read_control_message(htc_device, buffer, buffer_size,
     
    408408                return rc;
    409409        }
    410        
     410
    411411        uint16_t *message_id = (uint16_t *) ((void *) buffer +
    412412            sizeof(htc_frame_header_t));
     
    415415        else
    416416                rc = EINVAL;
    417        
     417
    418418        free(buffer);
    419        
     419
    420420        return rc;
    421421}
     
    435435        fibril_mutex_initialize(&htc_device->rx_lock);
    436436        fibril_mutex_initialize(&htc_device->tx_lock);
    437        
     437
    438438        htc_device->endpoints.ctrl_endpoint = 0;
    439        
     439
    440440        htc_device->ath_device = ath_device;
    441441        htc_device->ieee80211_dev = ieee80211_dev;
    442        
     442
    443443        return EOK;
    444444}
     
    460460                return rc;
    461461        }
    462        
     462
    463463        /*
    464464         * HTC services initialization start.
     
    470470                return rc;
    471471        }
    472        
     472
    473473        rc = htc_connect_service(htc_device, WMI_BEACON_SERVICE,
    474474            &htc_device->endpoints.beacon_endpoint);
     
    477477                return rc;
    478478        }
    479        
     479
    480480        rc = htc_connect_service(htc_device, WMI_CAB_SERVICE,
    481481            &htc_device->endpoints.cab_endpoint);
     
    484484                return rc;
    485485        }
    486        
     486
    487487        rc = htc_connect_service(htc_device, WMI_UAPSD_SERVICE,
    488488            &htc_device->endpoints.uapsd_endpoint);
     
    491491                return rc;
    492492        }
    493        
     493
    494494        rc = htc_connect_service(htc_device, WMI_MGMT_SERVICE,
    495495            &htc_device->endpoints.mgmt_endpoint);
     
    498498                return rc;
    499499        }
    500        
     500
    501501        rc = htc_connect_service(htc_device, WMI_DATA_BE_SERVICE,
    502502            &htc_device->endpoints.data_be_endpoint);
     
    506506                return rc;
    507507        }
    508        
     508
    509509        rc = htc_connect_service(htc_device, WMI_DATA_BK_SERVICE,
    510510            &htc_device->endpoints.data_bk_endpoint);
     
    514514                return rc;
    515515        }
    516        
     516
    517517        rc = htc_connect_service(htc_device, WMI_DATA_VIDEO_SERVICE,
    518518            &htc_device->endpoints.data_video_endpoint);
     
    521521                return rc;
    522522        }
    523        
     523
    524524        rc = htc_connect_service(htc_device, WMI_DATA_VOICE_SERVICE,
    525525            &htc_device->endpoints.data_voice_endpoint);
     
    528528                return rc;
    529529        }
    530        
     530
    531531        /*
    532532         * HTC services initialization end.
    533533         */
    534        
     534
    535535        /* Credits initialization message. */
    536536        rc = htc_config_credits(htc_device);
     
    539539                return rc;
    540540        }
    541        
     541
    542542        /* HTC setup complete confirmation message. */
    543543        rc = htc_complete_setup(htc_device);
     
    546546                return rc;
    547547        }
    548        
     548
    549549        usb_log_info("HTC services initialization finished successfully.\n");
    550        
     550
    551551        return EOK;
    552552}
  • uspace/drv/nic/ar9271/htc.h

    r3061bc1 ra35b458  
    112112        /** WMI message sequence number */
    113113        uint16_t sequence_number;
    114        
     114
    115115        /** HTC endpoints numbers */
    116116        htc_pipes_t endpoints;
    117        
     117
    118118        /** Lock for receiver */
    119119        fibril_mutex_t rx_lock;
    120        
     120
    121121        /** Lock for transmitter */
    122122        fibril_mutex_t tx_lock;
    123        
     123
    124124        /** Pointer to related IEEE 802.11 device */
    125125        ieee80211_dev_t *ieee80211_dev;
    126        
     126
    127127        /** Pointer to Atheros WiFi device structure */
    128128        ath_t *ath_device;
     
    175175        uint16_t credits;      /**< Big Endian value! */
    176176        uint16_t credit_size;  /**< Big Endian value! */
    177        
     177
    178178        uint8_t max_endpoints;
    179179        uint8_t pad;
     
    187187        uint16_t service_id;        /**< Big Endian value! */
    188188        uint16_t connection_flags;  /**< Big Endian value! */
    189        
     189
    190190        uint8_t download_pipe_id;
    191191        uint8_t upload_pipe_id;
     
    237237        uint8_t vif_index;
    238238        uint8_t is_vif_sta;
    239        
     239
    240240        uint16_t flags;      /**< Big Endian value! */
    241241        uint16_t ht_cap;     /**< Big Endian value! */
    242242        uint16_t max_ampdu;  /**< Big Endian value! */
    243        
     243
    244244        uint8_t pad;
    245245} __attribute__((packed)) htc_sta_msg_t;
  • uspace/drv/nic/ar9271/hw.c

    r3061bc1 ra35b458  
    5757        for (size_t i = 0; i < HW_WAIT_LOOPS; i++) {
    5858                udelay(HW_WAIT_TIME_US);
    59                
     59
    6060                uint32_t result;
    6161                wmi_reg_read(ar9271->htc_device, offset, &result);
     
    6363                        return EOK;
    6464        }
    65        
     65
    6666        return ETIMEOUT;
    6767}
     
    8484                }
    8585        };
    86        
     86
    8787        wmi_reg_buffer_write(ar9271->htc_device, buffer,
    8888            sizeof(buffer) / sizeof(wmi_reg_t));
    89        
     89
    9090        udelay(2);
    91        
     91
    9292        wmi_reg_write(ar9271->htc_device, AR9271_RC, 0);
    9393        wmi_reg_write(ar9271->htc_device, AR9271_RTC_RESET, 1);
    94        
     94
    9595        errno_t rc = hw_read_wait(ar9271,
    9696            AR9271_RTC_STATUS,
     
    101101                return rc;
    102102        }
    103        
     103
    104104        return EOK;
    105105}
     
    108108{
    109109        uint32_t reset_value = AR9271_RTC_RC_MAC_WARM;
    110        
     110
    111111        if (cold)
    112112                reset_value |= AR9271_RTC_RC_MAC_COLD;
    113        
     113
    114114        wmi_reg_t buffer[] = {
    115115                {
     
    127127                }
    128128        };
    129        
     129
    130130        wmi_reg_buffer_write(ar9271->htc_device, buffer,
    131131            sizeof(buffer) / sizeof(wmi_reg_t));
    132        
     132
    133133        udelay(100);
    134        
     134
    135135        wmi_reg_write(ar9271->htc_device, AR9271_RTC_RC, 0);
    136        
     136
    137137        errno_t rc = hw_read_wait(ar9271, AR9271_RTC_RC, AR9271_RTC_RC_MASK, 0);
    138138        if (rc != EOK) {
     
    140140                return rc;
    141141        }
    142        
     142
    143143        wmi_reg_write(ar9271->htc_device, AR9271_RC, 0);
    144144        wmi_reg_clear_bit(ar9271->htc_device, AR9271_STATION_ID1,
    145145            AR9271_STATION_ID1_POWER_SAVING);
    146        
     146
    147147        return EOK;
    148148}
     
    152152        uint32_t value;
    153153        nic_address_t ar9271_address;
    154        
     154
    155155        for (unsigned int i = 0; i < 3; i++) {
    156156                wmi_reg_read(ar9271->htc_device,
    157157                    AR9271_EEPROM_MAC_ADDR_START + i * 4, &value);
    158                
     158
    159159                uint16_t two_bytes = uint16_t_be2host(value);
    160160                ar9271_address.address[2*i] = two_bytes >> 8;
    161161                ar9271_address.address[2*i+1] = two_bytes & 0xff;
    162162        }
    163        
     163
    164164        nic_t *nic = nic_get_from_ddf_dev(ar9271->ddf_dev);
    165        
     165
    166166        errno_t rc = nic_report_address(nic, &ar9271_address);
    167167        if (rc != EOK) {
     
    169169                return rc;
    170170        }
    171        
     171
    172172        return EOK;
    173173}
     
    176176{
    177177        uint32_t address;
    178        
     178
    179179        if (gpio > 11)
    180180                address = AR9271_GPIO_OUT_MUX3;
     
    183183        else
    184184                address = AR9271_GPIO_OUT_MUX1;
    185        
     185
    186186        uint32_t gpio_shift = (gpio % 6) * 5;
    187        
     187
    188188        uint32_t temp;
    189189        wmi_reg_read(ar9271->htc_device, address, &temp);
    190        
     190
    191191        temp = ((temp & 0x1f0) << 1) | (temp & ~0x1f0);
    192192        temp &= ~(0x1f << gpio_shift);
    193193        temp |= (type << gpio_shift);
    194        
     194
    195195        wmi_reg_write(ar9271->htc_device, address, temp);
    196        
     196
    197197        gpio_shift = 2 * gpio;
    198        
     198
    199199        wmi_reg_set_clear_bit(ar9271->htc_device, AR9271_GPIO_OE_OUT,
    200200            AR9271_GPIO_OE_OUT_ALWAYS << gpio_shift,
    201201            AR9271_GPIO_OE_OUT_ALWAYS << gpio_shift);
    202        
     202
    203203        return EOK;
    204204}
     
    225225                return rc;
    226226        }
    227        
     227
    228228        rc = hw_set_reset(ar9271, false);
    229229        if (rc != EOK) {
     
    231231                return rc;
    232232        }
    233        
     233
    234234        rc = hw_addr_init(ar9271);
    235235        if (rc != EOK) {
     
    237237                return rc;
    238238        }
    239        
     239
    240240        return EOK;
    241241}
     
    249249                return rc;
    250250        }
    251        
     251
    252252        rc = hw_gpio_set_value(ar9271, AR9271_LED_PIN, 0);
    253253        if (rc != EOK) {
     
    255255                return rc;
    256256        }
    257        
     257
    258258        return EOK;
    259259}
     
    263263        wmi_reg_write(ar9271->htc_device, AR9271_PHY_ACTIVE, 1);
    264264        udelay(1000);
    265        
     265
    266266        return EOK;
    267267}
     
    271271{
    272272        uint32_t set_bit = 0x10000000;
    273        
     273
    274274        switch(op_mode) {
    275275        case IEEE80211_OPMODE_ADHOC:
     
    286286                    AR9271_CONFIG_ADHOC);
    287287        }
    288        
     288
    289289        wmi_reg_set_clear_bit(ar9271->htc_device, AR9271_STATION_ID1,
    290290            set_bit, AR9271_OPMODE_STATION_AP_MASK | AR9271_OPMODE_ADHOC_MASK);
    291        
     291
    292292        ieee80211_report_current_op_mode(ar9271->ieee80211_dev, op_mode);
    293        
     293
    294294        return EOK;
    295295}
     
    302302                return rc;
    303303        }
    304        
     304
    305305        return EOK;
    306306}
     
    310310        uint32_t value;
    311311        wmi_reg_read(ar9271->htc_device, AR9271_PHY_CAL, &value);
    312        
     312
    313313        value &= 0xfffffe00;
    314314        value |= (((uint32_t) AR9271_CALIB_NOMINAL_VALUE_2GHZ << 1) & 0x1ff);
    315        
     315
    316316        wmi_reg_write(ar9271->htc_device, AR9271_PHY_CAL, value);
    317        
     317
    318318        wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
    319319            AR9271_AGC_CONTROL_NF_CALIB_EN);
    320        
     320
    321321        wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
    322322            AR9271_AGC_CONTROL_NF_NOT_UPDATE);
    323        
     323
    324324        wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
    325325            AR9271_AGC_CONTROL_NF_CALIB);
    326        
     326
    327327        errno_t rc = hw_read_wait(ar9271, AR9271_AGC_CONTROL,
    328328            AR9271_AGC_CONTROL_NF_CALIB, 0);
     
    331331                return rc;
    332332        }
    333        
     333
    334334        wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
    335335            AR9271_AGC_CONTROL_NF_CALIB_EN);
    336        
     336
    337337        wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
    338338            AR9271_AGC_CONTROL_NF_NOT_UPDATE);
    339        
     339
    340340        wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
    341341            AR9271_AGC_CONTROL_NF_CALIB);
    342        
     342
    343343        return EOK;
    344344}
     
    349349        if ((freq < IEEE80211_FIRST_FREQ) || (freq > IEEE80211_MAX_FREQ))
    350350                return EINVAL;
    351        
     351
    352352        /* Not supported channel frequency. */
    353353        if ((freq - IEEE80211_FIRST_FREQ) % IEEE80211_CHANNEL_GAP != 0)
    354354                return EINVAL;
    355        
     355
    356356        uint32_t tx_control;
    357357        wmi_reg_read(ar9271->htc_device, AR9271_PHY_CCK_TX_CTRL, &tx_control);
    358358        wmi_reg_write(ar9271->htc_device, AR9271_PHY_CCK_TX_CTRL,
    359359            tx_control & ~AR9271_PHY_CCK_TX_CTRL_JAPAN);
    360        
     360
    361361        /* Some magic here. */
    362362        uint32_t synth_ctl;
     
    365365        uint32_t channel_select = (freq * 0x10000) / 15;
    366366        synth_ctl = synth_ctl | (1 << 29) | (1 << 28) | channel_select;
    367        
     367
    368368        wmi_reg_write(ar9271->htc_device, AR9271_PHY_SYNTH_CONTROL, synth_ctl);
    369        
     369
    370370        ieee80211_report_current_freq(ar9271->ieee80211_dev, freq);
    371        
     371
    372372        return EOK;
    373373}
     
    376376{
    377377        wmi_reg_write(ar9271->htc_device, AR9271_PHY_RFBUS_KILL, 0x1);
    378        
     378
    379379        errno_t rc = hw_read_wait(ar9271, AR9271_PHY_RFBUS_GRANT, 0x1, 0x1);
    380380        if (rc != EOK) {
     
    382382                return rc;
    383383        }
    384        
     384
    385385        rc = hw_set_freq(ar9271, freq);
    386386        if (rc != EOK) {
     
    388388                return rc;
    389389        }
    390        
     390
    391391        rc = hw_activate_phy(ar9271);
    392392        if (rc != EOK) {
     
    394394                return rc;
    395395        }
    396        
     396
    397397        udelay(1000);
    398398        wmi_reg_write(ar9271->htc_device, AR9271_PHY_RFBUS_KILL, 0x0);
    399        
     399
    400400        rc = hw_noise_floor_calibration(ar9271);
    401401        if (rc != EOK) {
     
    403403                return rc;
    404404        }
    405        
     405
    406406        return EOK;
    407407}
     
    410410{
    411411        uint32_t additional_bits = 0;
    412        
     412
    413413        if (assoc)
    414414                additional_bits |= AR9271_RX_FILTER_MYBEACON;
    415415        else
    416416                additional_bits |= AR9271_RX_FILTER_BEACON;
    417        
     417
    418418        uint32_t filter_bits = AR9271_RX_FILTER_UNI |
    419419            AR9271_RX_FILTER_MULTI | AR9271_RX_FILTER_BROAD |
    420420            additional_bits;
    421        
     421
    422422        wmi_reg_write(ar9271->htc_device, AR9271_RX_FILTER, filter_bits);
    423        
     423
    424424        return EOK;
    425425}
     
    428428{
    429429        ieee80211_dev_t *ieee80211_dev = ar9271->ieee80211_dev;
    430        
     430
    431431        nic_address_t bssid;
    432432        ieee80211_query_bssid(ieee80211_dev, &bssid);
    433        
     433
    434434        uint32_t *first_4bytes = (uint32_t *) &bssid.address;
    435435        uint16_t *last_2bytes = (uint16_t *) &bssid.address[4];
    436        
     436
    437437        wmi_reg_write(ar9271->htc_device, AR9271_BSSID0,
    438438            uint32_t_le2host(*first_4bytes));
    439        
     439
    440440        wmi_reg_write(ar9271->htc_device, AR9271_BSSID1,
    441441            uint16_t_le2host(*last_2bytes) |
    442442            ((ieee80211_get_aid(ieee80211_dev) & 0x3fff) << 16));
    443        
     443
    444444        return EOK;
    445445}
     
    449449        wmi_reg_write(ar9271->htc_device, AR9271_COMMAND,
    450450            AR9271_COMMAND_RX_ENABLE);
    451        
     451
    452452        errno_t rc = hw_set_rx_filter(ar9271, false);
    453453        if (rc != EOK) {
     
    455455                return rc;
    456456        }
    457        
     457
    458458        wmi_reg_write(ar9271->htc_device, AR9271_MULTICAST_FILTER1, ~0);
    459459        wmi_reg_write(ar9271->htc_device, AR9271_MULTICAST_FILTER2, ~0);
    460        
     460
    461461        /* Disable RX blocking. */
    462462        wmi_reg_clear_bit(ar9271->htc_device, AR9271_DIAG, (0x20 | 0x02000000));
    463        
     463
    464464        return EOK;
    465465}
     
    469469        /* Some magic here (set for 2GHz channels). But VERY important :-) */
    470470        uint32_t pll = (0x5 << 10) | 0x2c;
    471        
     471
    472472        wmi_reg_write(ar9271->htc_device, AR9271_RTC_PLL_CONTROL, pll);
    473        
     473
    474474        wmi_reg_write(ar9271->htc_device, AR9271_RTC_SLEEP_CLOCK,
    475475            AR9271_RTC_SLEEP_CLOCK_FORCE_DERIVED);
    476476        wmi_reg_set_bit(ar9271->htc_device, AR9271_RTC_FORCE_WAKE,
    477477            AR9271_RTC_FORCE_WAKE_ENABLE);
    478        
     478
    479479        return EOK;
    480480}
     
    484484        uint32_t reg_offset;
    485485        uint32_t reg_value;
    486        
     486
    487487        size_t size = ARRAY_SIZE(ar9271_2g_mode_array);
    488        
     488
    489489        for (size_t i = 0; i < size; i++) {
    490490                reg_offset = ar9271_2g_mode_array[i][0];
     
    492492                wmi_reg_write(ar9271->htc_device, reg_offset, reg_value);
    493493        }
    494        
     494
    495495        size = ARRAY_SIZE(ar9271_2g_tx_array);
    496        
     496
    497497        for (size_t i = 0; i < size; i++) {
    498498                reg_offset = ar9271_2g_tx_array[i][0];
     
    500500                wmi_reg_write(ar9271->htc_device, reg_offset, reg_value);
    501501        }
    502        
     502
    503503        size = ARRAY_SIZE(ar9271_init_array);
    504        
     504
    505505        for (size_t i = 0; i < size; i++) {
    506506                reg_offset = ar9271_init_array[i][0];
     
    522522        wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
    523523            AR9271_AGC_CONTROL_CALIB);
    524        
     524
    525525        errno_t rc = hw_read_wait(ar9271, AR9271_AGC_CONTROL,
    526526            AR9271_AGC_CONTROL_CALIB, 0);
     
    529529                return rc;
    530530        }
    531        
     531
    532532        wmi_reg_set_bit(ar9271->htc_device, AR9271_ADC_CONTROL,
    533533            AR9271_ADC_CONTROL_OFF_PWDADC);
     
    536536        wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
    537537            AR9271_AGC_CONTROL_TX_CALIB);
    538        
     538
    539539        return EOK;
    540540}
     
    544544        /* Set physical layer as deactivated. */
    545545        wmi_reg_write(ar9271->htc_device, AR9271_PHY_ACTIVE, 0);
    546        
     546
    547547        if(ar9271->starting_up) {
    548548                wmi_reg_write(ar9271->htc_device,
    549549                    AR9271_RESET_POWER_DOWN_CONTROL,
    550550                    AR9271_RADIO_RF_RESET);
    551                
     551
    552552                udelay(50);
    553553        }
    554        
     554
    555555        /* Cold reset when RX is enabled. */
    556556        uint32_t config_reg;
     
    558558        if (config_reg & AR9271_COMMAND_RX_ENABLE)
    559559                hw_set_reset(ar9271, true);
    560        
     560
    561561        errno_t rc = hw_init_pll(ar9271);
    562562        if (rc != EOK) {
     
    564564                return rc;
    565565        }
    566        
     566
    567567        udelay(500);
    568        
     568
    569569        wmi_reg_write(ar9271->htc_device, AR9271_CLOCK_CONTROL,
    570570            AR9271_MAX_CPU_CLOCK);
    571        
     571
    572572        udelay(100);
    573        
     573
    574574        if (ar9271->starting_up) {
    575575                wmi_reg_write(ar9271->htc_device,
    576576                    AR9271_RESET_POWER_DOWN_CONTROL,
    577577                    AR9271_GATE_MAC_CONTROL);
    578                
     578
    579579                udelay(50);
    580580        }
    581        
     581
    582582        hw_set_init_values(ar9271);
    583        
     583
    584584        /* Set physical layer mode. */
    585585        wmi_reg_write(ar9271->htc_device, AR9271_PHY_MODE,
    586586            AR9271_PHY_MODE_DYNAMIC);
    587        
     587
    588588        /* Reset device operating mode. */
    589589        rc = hw_reset_operating_mode(ar9271);
     
    592592                return rc;
    593593        }
    594        
     594
    595595        /* Set initial channel frequency. */
    596596        rc = hw_set_freq(ar9271, IEEE80211_FIRST_FREQ);
     
    599599                return rc;
    600600        }
    601        
     601
    602602        /* Initialize transmission queues. */
    603603        for (unsigned int i = 0; i < AR9271_QUEUES_COUNT; i++) {
     
    605605                    AR9271_QUEUE_BASE_MASK + (i << 2), 1 << i);
    606606        }
    607        
     607
    608608        /* Activate physical layer. */
    609609        rc = hw_activate_phy(ar9271);
     
    612612                return rc;
    613613        }
    614        
     614
    615615        /* Calibration. */
    616616        rc = hw_calibration(ar9271);
     
    619619                return rc;
    620620        }
    621        
     621
    622622        rc = hw_noise_floor_calibration(ar9271);
    623623        if (rc != EOK) {
     
    625625                return rc;
    626626        }
    627        
     627
    628628        /* Byteswap TX and RX data buffer words. */
    629629        wmi_reg_write(ar9271->htc_device, AR9271_CONFIG, 0xA);
    630        
     630
    631631        return EOK;
    632632}
     
    645645                return rc;
    646646        }
    647        
     647
    648648        rc = hw_init_led(ar9271);
    649649        if (rc != EOK) {
     
    651651                return rc;
    652652        }
    653        
     653
    654654        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  
    5353{
    5454        uint32_t cmd_value = host2uint32_t_be(reg_offset);
    55        
     55
    5656        void *resp_buffer =
    5757            malloc(htc_device->ath_device->ctrl_response_length);
    58        
     58
    5959        errno_t rc = wmi_send_command(htc_device, WMI_REG_READ,
    6060            (uint8_t *) &cmd_value, sizeof(cmd_value), resp_buffer);
    61        
     61
    6262        if (rc != EOK) {
    6363                usb_log_error("Failed to read registry value.\n");
    6464                return rc;
    6565        }
    66        
     66
    6767        uint32_t *resp_value = (uint32_t *) ((void *) resp_buffer +
    6868            sizeof(htc_frame_header_t) + sizeof(wmi_command_header_t));
    69        
     69
    7070        *res = uint32_t_be2host(*resp_value);
    71        
     71
    7272        return rc;
    7373}
     
    8888                host2uint32_t_be(val)
    8989        };
    90        
     90
    9191        void *resp_buffer =
    9292            malloc(htc_device->ath_device->ctrl_response_length);
    93        
     93
    9494        errno_t rc = wmi_send_command(htc_device, WMI_REG_WRITE,
    9595            (uint8_t *) &cmd_buffer, sizeof(cmd_buffer), resp_buffer);
    96        
     96
    9797        free(resp_buffer);
    98        
     98
    9999        if (rc != EOK) {
    100100                usb_log_error("Failed to write registry value.\n");
    101101                return rc;
    102102        }
    103        
     103
    104104        return rc;
    105105}
     
    119119{
    120120        uint32_t value;
    121        
     121
    122122        errno_t rc = wmi_reg_read(htc_device, reg_offset, &value);
    123123        if (rc != EOK) {
     
    126126                return rc;
    127127        }
    128        
     128
    129129        value &= ~clear_bit;
    130130        value |= set_bit;
    131        
     131
    132132        rc = wmi_reg_write(htc_device, reg_offset, value);
    133133        if (rc != EOK) {
     
    136136                return rc;
    137137        }
    138        
     138
    139139        return rc;
    140140}
     
    186186        void *resp_buffer =
    187187            malloc(htc_device->ath_device->ctrl_response_length);
    188        
     188
    189189        /* Convert values to correct endianness. */
    190190        for (size_t i = 0; i < elements; i++) {
     
    197197                    host2uint32_t_be(buffer_element->value);
    198198        }
    199        
     199
    200200        errno_t rc = wmi_send_command(htc_device, WMI_REG_WRITE,
    201201            (uint8_t *) buffer, buffer_size, resp_buffer);
    202        
     202
    203203        free(buffer);
    204204        free(resp_buffer);
    205        
     205
    206206        if (rc != EOK) {
    207207                usb_log_error("Failed to write multi registry value.\n");
    208208                return rc;
    209209        }
    210        
     210
    211211        return rc;
    212212}
     
    230230        size_t buffer_size = header_size + command_length;
    231231        void *buffer = malloc(buffer_size);
    232        
     232
    233233        if (command_buffer != NULL)
    234234                memcpy(buffer+header_size, command_buffer, command_length);
    235        
     235
    236236        /* Set up WMI header */
    237237        wmi_command_header_t *wmi_header = (wmi_command_header_t *)
     
    240240        wmi_header->sequence_number =
    241241            host2uint16_t_be(++htc_device->sequence_number);
    242        
     242
    243243        /* Send message. */
    244244        errno_t rc = htc_send_control_message(htc_device, buffer, buffer_size,
     
    249249                return rc;
    250250        }
    251        
     251
    252252        free(buffer);
    253        
     253
    254254        bool clean_resp_buffer = false;
    255255        size_t response_buffer_size =
     
    259259                clean_resp_buffer = true;
    260260        }
    261        
     261
    262262        /* Read response. */
    263263        /* TODO: Ignoring WMI management RX messages ~ TX statuses etc. */
     
    272272                        return rc;
    273273                }
    274                
     274
    275275                if (response_buffer_size < sizeof(htc_frame_header_t) +
    276276                    sizeof(wmi_command_header_t)) {
     
    279279                        return EINVAL;
    280280                }
    281                
     281
    282282                wmi_command_header_t *wmi_hdr = (wmi_command_header_t *)
    283283                    ((void *) response_buffer + sizeof(htc_frame_header_t));
    284284                cmd_id = uint16_t_be2host(wmi_hdr->command_id);
    285285        } while(cmd_id & WMI_MGMT_CMD_MASK);
    286        
     286
    287287        if (clean_resp_buffer)
    288288                free(response_buffer);
    289        
    290         return rc;
    291 }
     289
     290        return rc;
     291}
  • uspace/drv/nic/ar9271/wmi.h

    r3061bc1 ra35b458  
    7676        WMI_ECHO = 0x0001,
    7777        WMI_ACCESS_MEMORY,
    78        
     78
    7979        /* Commands used for HOST -> DEVICE communication */
    8080        WMI_GET_FW_VERSION,
Note: See TracChangeset for help on using the changeset viewer.