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


Ignore:
Timestamp:
2018-03-02T20:10:49Z (6 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.

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.