Changeset 8565a42 in mainline for uspace/drv/nic


Ignore:
Timestamp:
2018-03-02T20:34:50Z (8 years ago)
Author:
GitHub <noreply@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a1a81f69, d5e5fd1
Parents:
3061bc1 (diff), 34e1206 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:34:50)
git-committer:
GitHub <noreply@…> (2018-03-02 20:34:50)
Message:

Remove all trailing whitespace, everywhere.

See individual commit messages for details.

Location:
uspace/drv/nic
Files:
18 edited

Legend:

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

    r3061bc1 r8565a42  
    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 r8565a42  
    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 r8565a42  
    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 r8565a42  
    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 r8565a42  
    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 r8565a42  
    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 r8565a42  
    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 r8565a42  
    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 r8565a42  
    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 r8565a42  
    7676        WMI_ECHO = 0x0001,
    7777        WMI_ACCESS_MEMORY,
    78        
     78
    7979        /* Commands used for HOST -> DEVICE communication */
    8080        WMI_GET_FW_VERSION,
  • uspace/drv/nic/e1k/e1k.c

    r3061bc1 r8565a42  
    122122        /** Device configuration */
    123123        e1000_info_t info;
    124        
     124
    125125        /** Physical registers base address */
    126126        void *reg_base_phys;
    127127        /** Virtual registers base address */
    128128        void *reg_base_virt;
    129        
     129
    130130        /** Physical tx ring address */
    131131        uintptr_t tx_ring_phys;
    132132        /** Virtual tx ring address */
    133133        void *tx_ring_virt;
    134        
     134
    135135        /** Ring of TX frames, physical address */
    136136        uintptr_t *tx_frame_phys;
    137137        /** Ring of TX frames, virtual address */
    138138        void **tx_frame_virt;
    139        
     139
    140140        /** Physical rx ring address */
    141141        uintptr_t rx_ring_phys;
    142142        /** Virtual rx ring address */
    143143        void *rx_ring_virt;
    144        
     144
    145145        /** Ring of RX frames, physical address */
    146146        uintptr_t *rx_frame_phys;
    147147        /** Ring of RX frames, virtual address */
    148148        void **rx_frame_virt;
    149        
     149
    150150        /** VLAN tag */
    151151        uint16_t vlan_tag;
    152        
     152
    153153        /** Add VLAN tag to frame */
    154154        bool vlan_tag_add;
    155        
     155
    156156        /** Used unicast Receive Address count */
    157157        unsigned int unicast_ra_count;
    158        
     158
    159159        /** Used milticast Receive addrress count */
    160160        unsigned int multicast_ra_count;
    161        
     161
    162162        /** The irq assigned */
    163163        int irq;
    164        
     164
    165165        /** Lock for CTRL register */
    166166        fibril_mutex_t ctrl_lock;
    167        
     167
    168168        /** Lock for receiver */
    169169        fibril_mutex_t rx_lock;
    170        
     170
    171171        /** Lock for transmitter */
    172172        fibril_mutex_t tx_lock;
    173        
     173
    174174        /** Lock for EEPROM access */
    175175        fibril_mutex_t eeprom_lock;
     
    292292        assert(dev);
    293293        assert(info);
    294        
     294
    295295        memset(info, 0, sizeof(nic_device_info_t));
    296        
     296
    297297        info->vendor_id = 0x8086;
    298298        str_cpy(info->vendor_name, NIC_VENDOR_MAX_LENGTH,
     
    300300        str_cpy(info->model_name, NIC_MODEL_MAX_LENGTH,
    301301            "Intel Pro");
    302        
     302
    303303        info->ethernet_support[ETH_10M] = ETH_10BASE_T;
    304304        info->ethernet_support[ETH_100M] = ETH_100BASE_TX;
    305305        info->ethernet_support[ETH_1000M] = ETH_1000BASE_T;
    306        
     306
    307307        return EOK;
    308308}
     
    323323        else
    324324                *state = NIC_CS_UNPLUGGED;
    325        
     325
    326326        return EOK;
    327327}
     
    340340        e1000_t *e1000 = DRIVER_DATA_FUN(fun);
    341341        uint32_t status = E1000_REG_READ(e1000, E1000_STATUS);
    342        
     342
    343343        if (status & STATUS_FD)
    344344                *duplex = NIC_CM_FULL_DUPLEX;
    345345        else
    346346                *duplex = NIC_CM_HALF_DUPLEX;
    347        
     347
    348348        uint32_t speed_bits =
    349349            (status >> STATUS_SPEED_SHIFT) & STATUS_SPEED_ALL;
    350        
     350
    351351        if (speed_bits == STATUS_SPEED_10)
    352352                *speed = 10;
     
    356356            (speed_bits == STATUS_SPEED_1000B))
    357357                *speed = 1000;
    358        
     358
    359359        *role = NIC_ROLE_UNKNOWN;
    360360        return EOK;
     
    364364{
    365365        fibril_mutex_lock(&e1000->ctrl_lock);
    366        
     366
    367367        uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL);
    368        
     368
    369369        if (ctrl & CTRL_SLU) {
    370370                ctrl &= ~(CTRL_SLU);
    371371                E1000_REG_WRITE(e1000, E1000_CTRL, ctrl);
    372372                fibril_mutex_unlock(&e1000->ctrl_lock);
    373                
     373
    374374                async_usleep(10);
    375                
     375
    376376                fibril_mutex_lock(&e1000->ctrl_lock);
    377377                ctrl = E1000_REG_READ(e1000, E1000_CTRL);
     
    379379                E1000_REG_WRITE(e1000, E1000_CTRL, ctrl);
    380380        }
    381        
     381
    382382        fibril_mutex_unlock(&e1000->ctrl_lock);
    383383}
     
    391391        if ((speed != 10) && (speed != 100) && (speed != 1000))
    392392                return EINVAL;
    393        
     393
    394394        if ((duplex != NIC_CM_HALF_DUPLEX) && (duplex != NIC_CM_FULL_DUPLEX))
    395395                return EINVAL;
    396        
     396
    397397        e1000_t *e1000 = DRIVER_DATA_FUN(fun);
    398        
     398
    399399        fibril_mutex_lock(&e1000->ctrl_lock);
    400400        uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL);
    401        
     401
    402402        ctrl |= CTRL_FRCSPD;
    403403        ctrl |= CTRL_FRCDPLX;
    404404        ctrl &= ~(CTRL_ASDE);
    405        
     405
    406406        if (duplex == NIC_CM_FULL_DUPLEX)
    407407                ctrl |= CTRL_FD;
    408408        else
    409409                ctrl &= ~(CTRL_FD);
    410        
     410
    411411        ctrl &= ~(CTRL_SPEED_MASK);
    412412        if (speed == 1000)
     
    416416        else
    417417                ctrl |= CTRL_SPEED_10 << CTRL_SPEED_SHIFT;
    418        
     418
    419419        E1000_REG_WRITE(e1000, E1000_CTRL, ctrl);
    420        
     420
    421421        fibril_mutex_unlock(&e1000->ctrl_lock);
    422        
     422
    423423        e1000_link_restart(e1000);
    424        
     424
    425425        return EOK;
    426426}
     
    437437{
    438438        e1000_t *e1000 = DRIVER_DATA_FUN(fun);
    439        
     439
    440440        fibril_mutex_lock(&e1000->ctrl_lock);
    441        
     441
    442442        uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL);
    443        
     443
    444444        ctrl &= ~(CTRL_FRCSPD);
    445445        ctrl &= ~(CTRL_FRCDPLX);
    446446        ctrl |= CTRL_ASDE;
    447        
     447
    448448        E1000_REG_WRITE(e1000, E1000_CTRL, ctrl);
    449        
     449
    450450        fibril_mutex_unlock(&e1000->ctrl_lock);
    451        
     451
    452452        e1000_link_restart(e1000);
    453        
     453
    454454        return EOK;
    455455}
     
    465465{
    466466        e1000_t *e1000 = DRIVER_DATA_FUN(fun);
    467        
     467
    468468        fibril_mutex_lock(&e1000->ctrl_lock);
    469        
     469
    470470        uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL);
    471        
     471
    472472        ctrl |= CTRL_FRCSPD;
    473473        ctrl |= CTRL_FRCDPLX;
    474474        ctrl &= ~(CTRL_ASDE);
    475        
     475
    476476        E1000_REG_WRITE(e1000, E1000_CTRL, ctrl);
    477        
     477
    478478        fibril_mutex_unlock(&e1000->ctrl_lock);
    479        
     479
    480480        e1000_link_restart(e1000);
    481        
     481
    482482        return EOK;
    483483}
     
    504504{
    505505        e1000_t *e1000 = DRIVER_DATA_FUN(fun);
    506        
     506
    507507        *mode = 0;
    508508        uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL);
    509509        if (rctl & RCTL_SBP)
    510510                *mode = NIC_DEFECTIVE_BAD_CRC | NIC_DEFECTIVE_SHORT;
    511        
     511
    512512        return EOK;
    513513};
     
    526526        e1000_t *e1000 = DRIVER_DATA_FUN(fun);
    527527        errno_t rc = EOK;
    528        
     528
    529529        fibril_mutex_lock(&e1000->rx_lock);
    530        
     530
    531531        uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL);
    532532        bool short_mode = (mode & NIC_DEFECTIVE_SHORT ? true : false);
    533533        bool bad_mode = (mode & NIC_DEFECTIVE_BAD_CRC ? true : false);
    534        
     534
    535535        if (short_mode && bad_mode)
    536536                rctl |= RCTL_SBP;
     
    539539        else
    540540                rc = ENOTSUP;
    541        
     541
    542542        E1000_REG_WRITE(e1000, E1000_RCTL, rctl);
    543        
     543
    544544        fibril_mutex_unlock(&e1000->rx_lock);
    545545        return rc;
     
    563563        uint8_t *mac4 = (uint8_t *) address->address + 4;
    564564        uint8_t *mac5 = (uint8_t *) address->address + 5;
    565        
     565
    566566        uint32_t rah;
    567567        uint32_t ral;
    568        
     568
    569569        ral = ((*mac3) << 24) | ((*mac2) << 16) | ((*mac1) << 8) | (*mac0);
    570570        rah = ((*mac5) << 8) | ((*mac4));
    571        
     571
    572572        if (set_av_bit)
    573573                rah |= RAH_AV;
    574574        else
    575575                rah |= E1000_REG_READ(e1000, E1000_RAH_ARRAY(position)) & RAH_AV;
    576        
     576
    577577        E1000_REG_WRITE(e1000, E1000_RAH_ARRAY(position), rah);
    578578        E1000_REG_WRITE(e1000, E1000_RAL_ARRAY(position), ral);
     
    605605            ra_num++)
    606606                e1000_disable_receive_address(e1000, ra_num);
    607        
     607
    608608        e1000->unicast_ra_count = 0;
    609609}
     
    618618        unsigned int first_multicast_ra_num =
    619619            E1000_RECEIVE_ADDRESS - e1000->multicast_ra_count;
    620        
     620
    621621        for (unsigned int ra_num = E1000_RECEIVE_ADDRESS - 1;
    622622            ra_num >= first_multicast_ra_num;
    623623            ra_num--)
    624624                e1000_disable_receive_address(e1000, ra_num);
    625        
     625
    626626        e1000->multicast_ra_count = 0;
    627627}
     
    662662{
    663663        assert(addr_cnt <= get_free_unicast_address_count(e1000));
    664        
     664
    665665        nic_address_t *addr_iterator = (nic_address_t *) addr;
    666        
     666
    667667        /* ra_num = 0 is primary address */
    668668        for (unsigned int ra_num = 1;
     
    685685{
    686686        assert(addr_cnt <= get_free_multicast_address_count(e1000));
    687        
     687
    688688        nic_address_t *addr_iterator = (nic_address_t *) addr;
    689        
     689
    690690        unsigned int first_multicast_ra_num = E1000_RECEIVE_ADDRESS - addr_cnt;
    691691        for (unsigned int ra_num = E1000_RECEIVE_ADDRESS - 1;
     
    832832        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    833833        errno_t rc = EOK;
    834        
     834
    835835        fibril_mutex_lock(&e1000->rx_lock);
    836        
     836
    837837        switch (mode) {
    838838        case NIC_MULTICAST_BLOCKED:
     
    866866                break;
    867867        }
    868        
     868
    869869        fibril_mutex_unlock(&e1000->rx_lock);
    870870        return rc;
     
    886886        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    887887        errno_t rc = EOK;
    888        
     888
    889889        fibril_mutex_lock(&e1000->rx_lock);
    890        
     890
    891891        switch (mode) {
    892892        case NIC_UNICAST_BLOCKED:
     
    924924                break;
    925925        }
    926        
     926
    927927        fibril_mutex_unlock(&e1000->rx_lock);
    928928        return rc;
     
    941941        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    942942        errno_t rc = EOK;
    943        
     943
    944944        fibril_mutex_lock(&e1000->rx_lock);
    945        
     945
    946946        switch (mode) {
    947947        case NIC_BROADCAST_BLOCKED:
     
    955955                break;
    956956        }
    957        
     957
    958958        fibril_mutex_unlock(&e1000->rx_lock);
    959959        return rc;
     
    971971        if (E1000_REG_READ(e1000, E1000_RCTL) & (RCTL_EN))
    972972                return true;
    973        
     973
    974974        return false;
    975975}
     
    10091009{
    10101010        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    1011        
     1011
    10121012        fibril_mutex_lock(&e1000->rx_lock);
    1013        
     1013
    10141014        if (vlan_mask) {
    10151015                /*
     
    10201020                if (rx_enabled)
    10211021                        e1000_disable_rx(e1000);
    1022                
     1022
    10231023                for (unsigned int i = 0; i < NIC_VLAN_BITMAP_SIZE; i += 4) {
    10241024                        uint32_t bitmap_part =
     
    10291029                        E1000_REG_WRITE(e1000, E1000_VFTA_ARRAY(i / 4), bitmap_part);
    10301030                }
    1031                
     1031
    10321032                e1000_enable_vlan_filter(e1000);
    10331033                if (rx_enabled)
     
    10351035        } else
    10361036                e1000_disable_vlan_filter(e1000);
    1037        
     1037
    10381038        fibril_mutex_unlock(&e1000->rx_lock);
    10391039}
     
    10541054        if (tag & VLANTAG_CFI)
    10551055                return ENOTSUP;
    1056        
     1056
    10571057        /*
    10581058         * CTRL.VME is neccessary for both strip and add
     
    10611061        if (!strip && add)
    10621062                return ENOTSUP;
    1063        
     1063
    10641064        e1000_t *e1000 = DRIVER_DATA_FUN(fun);
    1065        
     1065
    10661066        e1000->vlan_tag = tag;
    10671067        e1000->vlan_tag_add = add;
    1068        
     1068
    10691069        fibril_mutex_lock(&e1000->ctrl_lock);
    1070        
     1070
    10711071        uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL);
    10721072        if (strip)
     
    10741074        else
    10751075                ctrl &= ~CTRL_VME;
    1076        
     1076
    10771077        E1000_REG_WRITE(e1000, E1000_CTRL, ctrl);
    1078        
     1078
    10791079        fibril_mutex_unlock(&e1000->ctrl_lock);
    10801080        return EOK;
     
    10921092{
    10931093        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    1094        
     1094
    10951095        e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *)
    10961096            (e1000->rx_ring_virt + offset * sizeof(e1000_rx_descriptor_t));
    1097        
     1097
    10981098        rx_descriptor->phys_addr = PTR_TO_U64(e1000->rx_frame_phys[offset]);
    10991099        rx_descriptor->length = 0;
     
    11141114        e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *)
    11151115            (e1000->rx_ring_virt + offset * sizeof(e1000_rx_descriptor_t));
    1116        
     1116
    11171117        rx_descriptor->length = 0;
    11181118        rx_descriptor->checksum = 0;
     
    11311131{
    11321132        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    1133        
     1133
    11341134        e1000_tx_descriptor_t *tx_descriptor = (e1000_tx_descriptor_t *)
    11351135            (e1000->tx_ring_virt + offset * sizeof(e1000_tx_descriptor_t));
    1136        
     1136
    11371137        tx_descriptor->phys_addr = 0;
    11381138        tx_descriptor->length = 0;
     
    11681168{
    11691169        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    1170        
     1170
    11711171        fibril_mutex_lock(&e1000->rx_lock);
    1172        
     1172
    11731173        uint32_t *tail_addr = E1000_REG_ADDR(e1000, E1000_RDT);
    11741174        uint32_t next_tail = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT);
    1175        
     1175
    11761176        e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *)
    11771177            (e1000->rx_ring_virt + next_tail * sizeof(e1000_rx_descriptor_t));
    1178        
     1178
    11791179        while (rx_descriptor->status & 0x01) {
    11801180                uint32_t frame_size = rx_descriptor->length - E1000_CRC_SIZE;
    1181                
     1181
    11821182                nic_frame_t *frame = nic_alloc_frame(nic, frame_size);
    11831183                if (frame != NULL) {
     
    11871187                        ddf_msg(LVL_ERROR, "Memory allocation failed. Frame dropped.");
    11881188                }
    1189                
     1189
    11901190                e1000_fill_new_rx_descriptor(nic, next_tail);
    1191                
     1191
    11921192                *tail_addr = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT);
    11931193                next_tail = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT);
    1194                
     1194
    11951195                rx_descriptor = (e1000_rx_descriptor_t *)
    11961196                    (e1000->rx_ring_virt + next_tail * sizeof(e1000_rx_descriptor_t));
    11971197        }
    1198        
     1198
    11991199        fibril_mutex_unlock(&e1000->rx_lock);
    12001200}
     
    12471247        nic_t *nic = NIC_DATA_DEV(dev);
    12481248        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    1249        
     1249
    12501250        e1000_interrupt_handler_impl(nic, icr);
    12511251        e1000_enable_interrupts(e1000);
     
    12671267{
    12681268        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    1269        
     1269
    12701270        /* Lock the mutex in whole driver while working with global structure */
    12711271        fibril_mutex_lock(&irq_reg_mutex);
    1272        
     1272
    12731273        e1000_irq_code.ranges[0].base = (uintptr_t) e1000->reg_base_phys;
    12741274        e1000_irq_code.cmds[0].addr = e1000->reg_base_phys + E1000_ICR;
    12751275        e1000_irq_code.cmds[2].addr = e1000->reg_base_phys + E1000_IMC;
    1276        
     1276
    12771277        errno_t rc = register_interrupt_handler(nic_get_ddf_dev(nic), e1000->irq,
    12781278            e1000_interrupt_handler, &e1000_irq_code, handle);
    1279        
     1279
    12801280        fibril_mutex_unlock(&irq_reg_mutex);
    12811281        return rc;
     
    12901290{
    12911291        assert(nic);
    1292        
     1292
    12931293        e1000_t *e1000 = nic_get_specific(nic);
    12941294        assert(e1000);
    1295        
     1295
    12961296        uint32_t icr = E1000_REG_READ(e1000, E1000_ICR);
    12971297        e1000_interrupt_handler_impl(nic, icr);
     
    13231323{
    13241324        assert(nic);
    1325        
     1325
    13261326        e1000_t *e1000 = nic_get_specific(nic);
    13271327        assert(e1000);
    1328        
     1328
    13291329        switch (mode) {
    13301330        case NIC_POLL_IMMEDIATE:
     
    13441344                return ENOTSUP;
    13451345        }
    1346        
     1346
    13471347        return EOK;
    13481348}
     
    13571357        E1000_REG_WRITE(e1000, E1000_RDLEN, E1000_RX_FRAME_COUNT * 16);
    13581358        E1000_REG_WRITE(e1000, E1000_RDH, 0);
    1359        
     1359
    13601360        /* It is not posible to let HW use all descriptors */
    13611361        E1000_REG_WRITE(e1000, E1000_RDT, E1000_RX_FRAME_COUNT - 1);
    1362        
     1362
    13631363        /* Set Broadcast Enable Bit */
    13641364        E1000_REG_WRITE(e1000, E1000_RCTL, RCTL_BAM);
     
    13771377        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    13781378        fibril_mutex_lock(&e1000->rx_lock);
    1379        
     1379
    13801380        e1000->rx_ring_virt = AS_AREA_ANY;
    13811381        errno_t rc = dmamem_map_anonymous(
     
    13851385        if (rc != EOK)
    13861386                return rc;
    1387        
     1387
    13881388        E1000_REG_WRITE(e1000, E1000_RDBAH,
    13891389            (uint32_t) (PTR_TO_U64(e1000->rx_ring_phys) >> 32));
    13901390        E1000_REG_WRITE(e1000, E1000_RDBAL,
    13911391            (uint32_t) PTR_TO_U64(e1000->rx_ring_phys));
    1392        
     1392
    13931393        e1000->rx_frame_phys = (uintptr_t *)
    13941394            calloc(E1000_RX_FRAME_COUNT, sizeof(uintptr_t));
     
    13991399                goto error;
    14001400        }
    1401        
     1401
    14021402        for (size_t i = 0; i < E1000_RX_FRAME_COUNT; i++) {
    14031403                uintptr_t frame_phys;
    14041404                void *frame_virt = AS_AREA_ANY;
    1405                
     1405
    14061406                rc = dmamem_map_anonymous(E1000_MAX_SEND_FRAME_SIZE,
    14071407                    DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0,
     
    14091409                if (rc != EOK)
    14101410                        goto error;
    1411                
     1411
    14121412                e1000->rx_frame_phys[i] = frame_phys;
    14131413                e1000->rx_frame_virt[i] = frame_virt;
    14141414        }
    1415        
     1415
    14161416        /* Write descriptor */
    14171417        for (size_t i = 0; i < E1000_RX_FRAME_COUNT; i++)
    14181418                e1000_fill_new_rx_descriptor(nic, i);
    1419        
     1419
    14201420        e1000_initialize_rx_registers(e1000);
    1421        
     1421
    14221422        fibril_mutex_unlock(&e1000->rx_lock);
    14231423        return EOK;
    1424        
     1424
    14251425error:
    14261426        for (size_t i = 0; i < E1000_RX_FRAME_COUNT; i++) {
     
    14311431                }
    14321432        }
    1433        
     1433
    14341434        if (e1000->rx_frame_phys != NULL) {
    14351435                free(e1000->rx_frame_phys);
    14361436                e1000->rx_frame_phys = NULL;
    14371437        }
    1438        
     1438
    14391439        if (e1000->rx_frame_virt != NULL) {
    14401440                free(e1000->rx_frame_virt);
    14411441                e1000->rx_frame_virt = NULL;
    14421442        }
    1443        
     1443
    14441444        return rc;
    14451445}
     
    14531453{
    14541454        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    1455        
     1455
    14561456        /* Write descriptor */
    14571457        for (unsigned int offset = 0; offset < E1000_RX_FRAME_COUNT; offset++) {
     
    14601460                e1000->rx_frame_virt[offset] = NULL;
    14611461        }
    1462        
     1462
    14631463        free(e1000->rx_frame_virt);
    1464        
     1464
    14651465        e1000->rx_frame_phys = NULL;
    14661466        e1000->rx_frame_virt = NULL;
    1467        
     1467
    14681468        dmamem_unmap_anonymous(e1000->rx_ring_virt);
    14691469}
     
    15501550        E1000_REG_WRITE(e1000, E1000_TDH, 0);
    15511551        E1000_REG_WRITE(e1000, E1000_TDT, 0);
    1552        
     1552
    15531553        E1000_REG_WRITE(e1000, E1000_TIPG,
    15541554            10 << TIPG_IPGT_SHIFT |
    15551555            8 << TIPG_IPGR1_SHIFT |
    15561556            6 << TIPG_IPGR2_SHIFT);
    1557        
     1557
    15581558        E1000_REG_WRITE(e1000, E1000_TCTL,
    15591559            0x0F << TCTL_CT_SHIFT /* Collision Threshold */ |
     
    15701570{
    15711571        size_t i;
    1572        
     1572
    15731573        fibril_mutex_lock(&e1000->tx_lock);
    1574        
     1574
    15751575        e1000->tx_ring_phys = 0;
    15761576        e1000->tx_ring_virt = AS_AREA_ANY;
    1577        
     1577
    15781578        e1000->tx_frame_phys = NULL;
    15791579        e1000->tx_frame_virt = NULL;
    1580        
     1580
    15811581        errno_t rc = dmamem_map_anonymous(
    15821582            E1000_TX_FRAME_COUNT * sizeof(e1000_tx_descriptor_t),
     
    15851585        if (rc != EOK)
    15861586                goto error;
    1587        
     1587
    15881588        memset(e1000->tx_ring_virt, 0,
    15891589            E1000_TX_FRAME_COUNT * sizeof(e1000_tx_descriptor_t));
    1590        
     1590
    15911591        e1000->tx_frame_phys = (uintptr_t *)
    15921592            calloc(E1000_TX_FRAME_COUNT, sizeof(uintptr_t));
     
    15981598                goto error;
    15991599        }
    1600        
     1600
    16011601        for (i = 0; i < E1000_TX_FRAME_COUNT; i++) {
    16021602                e1000->tx_frame_virt[i] = AS_AREA_ANY;
     
    16071607                        goto error;
    16081608        }
    1609        
     1609
    16101610        E1000_REG_WRITE(e1000, E1000_TDBAH,
    16111611            (uint32_t) (PTR_TO_U64(e1000->tx_ring_phys) >> 32));
    16121612        E1000_REG_WRITE(e1000, E1000_TDBAL,
    16131613            (uint32_t) PTR_TO_U64(e1000->tx_ring_phys));
    1614        
     1614
    16151615        e1000_initialize_tx_registers(e1000);
    1616        
     1616
    16171617        fibril_mutex_unlock(&e1000->tx_lock);
    16181618        return EOK;
    1619        
     1619
    16201620error:
    16211621        if (e1000->tx_ring_virt != NULL) {
     
    16231623                e1000->tx_ring_virt = NULL;
    16241624        }
    1625        
     1625
    16261626        if ((e1000->tx_frame_phys != NULL) && (e1000->tx_frame_virt != NULL)) {
    16271627                for (i = 0; i < E1000_TX_FRAME_COUNT; i++) {
     
    16331633                }
    16341634        }
    1635        
     1635
    16361636        if (e1000->tx_frame_phys != NULL) {
    16371637                free(e1000->tx_frame_phys);
    16381638                e1000->tx_frame_phys = NULL;
    16391639        }
    1640        
     1640
    16411641        if (e1000->tx_frame_virt != NULL) {
    16421642                free(e1000->tx_frame_virt);
    16431643                e1000->tx_frame_virt = NULL;
    16441644        }
    1645        
     1645
    16461646        return rc;
    16471647}
     
    16551655{
    16561656        size_t i;
    1657        
     1657
    16581658        for (i = 0; i < E1000_TX_FRAME_COUNT; i++) {
    16591659                dmamem_unmap_anonymous(e1000->tx_frame_virt[i]);
     
    16611661                e1000->tx_frame_virt[i] = NULL;
    16621662        }
    1663        
     1663
    16641664        if (e1000->tx_frame_phys != NULL) {
    16651665                free(e1000->tx_frame_phys);
    16661666                e1000->tx_frame_phys = NULL;
    16671667        }
    1668        
     1668
    16691669        if (e1000->tx_frame_virt != NULL) {
    16701670                free(e1000->tx_frame_virt);
    16711671                e1000->tx_frame_virt = NULL;
    16721672        }
    1673        
     1673
    16741674        dmamem_unmap_anonymous(e1000->tx_ring_virt);
    16751675}
     
    17211721{
    17221722        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    1723        
     1723
    17241724        E1000_REG_WRITE(e1000, E1000_CTRL, CTRL_RST);
    1725        
     1725
    17261726        /* Wait for the reset */
    17271727        async_usleep(20);
    1728        
     1728
    17291729        /* check if RST_BIT cleared */
    17301730        if (E1000_REG_READ(e1000, E1000_CTRL) & (CTRL_RST))
    17311731                return EINVAL;
    1732        
     1732
    17331733        e1000_initialize_registers(e1000);
    17341734        e1000_initialize_rx_registers(e1000);
     
    17371737        e1000_initialize_filters(e1000);
    17381738        e1000_initialize_vlan(e1000);
    1739        
     1739
    17401740        return EOK;
    17411741}
     
    17521752{
    17531753        assert(nic);
    1754        
     1754
    17551755        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    1756        
     1756
    17571757        fibril_mutex_lock(&e1000->rx_lock);
    17581758        fibril_mutex_lock(&e1000->tx_lock);
    17591759        fibril_mutex_lock(&e1000->ctrl_lock);
    1760        
     1760
    17611761        e1000_enable_interrupts(e1000);
    1762        
     1762
    17631763        errno_t rc = hw_res_enable_interrupt(e1000->parent_sess, e1000->irq);
    17641764        if (rc != EOK) {
     
    17691769                return rc;
    17701770        }
    1771        
     1771
    17721772        e1000_clear_rx_ring(e1000);
    17731773        e1000_enable_rx(e1000);
    1774        
     1774
    17751775        e1000_clear_tx_ring(nic);
    17761776        e1000_enable_tx(e1000);
    1777        
     1777
    17781778        uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL);
    17791779        ctrl |= CTRL_SLU;
    17801780        E1000_REG_WRITE(e1000, E1000_CTRL, ctrl);
    1781        
     1781
    17821782        fibril_mutex_unlock(&e1000->ctrl_lock);
    17831783        fibril_mutex_unlock(&e1000->tx_lock);
    17841784        fibril_mutex_unlock(&e1000->rx_lock);
    1785        
     1785
    17861786        return EOK;
    17871787}
     
    17981798{
    17991799        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    1800        
     1800
    18011801        uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL);
    18021802        ctrl &= ~CTRL_SLU;
    18031803        E1000_REG_WRITE(e1000, E1000_CTRL, ctrl);
    1804        
     1804
    18051805        e1000_disable_tx(e1000);
    18061806        e1000_disable_rx(e1000);
    1807        
     1807
    18081808        hw_res_disable_interrupt(e1000->parent_sess, e1000->irq);
    18091809        e1000_disable_interrupts(e1000);
    1810        
     1810
    18111811        /*
    18121812         * Wait for the for the end of all data
     
    18141814         */
    18151815        async_usleep(100);
    1816        
     1816
    18171817        return EOK;
    18181818}
     
    18291829{
    18301830        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    1831        
     1831
    18321832        fibril_mutex_lock(&e1000->rx_lock);
    18331833        fibril_mutex_lock(&e1000->tx_lock);
    18341834        fibril_mutex_lock(&e1000->ctrl_lock);
    1835        
     1835
    18361836        errno_t rc = e1000_on_down_unlocked(nic);
    1837        
     1837
    18381838        fibril_mutex_unlock(&e1000->ctrl_lock);
    18391839        fibril_mutex_unlock(&e1000->tx_lock);
    18401840        fibril_mutex_unlock(&e1000->rx_lock);
    1841        
     1841
    18421842        return rc;
    18431843}
     
    18541854{
    18551855        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    1856        
     1856
    18571857        fibril_mutex_lock(&e1000->rx_lock);
    18581858        fibril_mutex_lock(&e1000->tx_lock);
    18591859        fibril_mutex_lock(&e1000->ctrl_lock);
    1860        
     1860
    18611861        errno_t rc = e1000_on_down_unlocked(nic);
    18621862        if (rc == EOK)
    18631863                rc = e1000_reset(nic);
    1864        
     1864
    18651865        fibril_mutex_unlock(&e1000->ctrl_lock);
    18661866        fibril_mutex_unlock(&e1000->tx_lock);
    18671867        fibril_mutex_unlock(&e1000->rx_lock);
    1868        
     1868
    18691869        return rc;
    18701870}
     
    18801880        if (!nic)
    18811881                return NULL;
    1882        
     1882
    18831883        e1000_t *e1000 = malloc(sizeof(e1000_t));
    18841884        if (!e1000) {
     
    18861886                return NULL;
    18871887        }
    1888        
     1888
    18891889        memset(e1000, 0, sizeof(e1000_t));
    18901890        e1000->dev = dev;
    1891        
     1891
    18921892        nic_set_specific(nic, e1000);
    18931893        nic_set_send_frame_handler(nic, e1000_send_frame);
     
    18981898            e1000_on_broadcast_mode_change, NULL, e1000_on_vlan_mask_change);
    18991899        nic_set_poll_handlers(nic, e1000_poll_mode_change, e1000_poll);
    1900        
     1900
    19011901        fibril_mutex_initialize(&e1000->ctrl_lock);
    19021902        fibril_mutex_initialize(&e1000->rx_lock);
    19031903        fibril_mutex_initialize(&e1000->tx_lock);
    19041904        fibril_mutex_initialize(&e1000->eeprom_lock);
    1905        
     1905
    19061906        return e1000;
    19071907}
     
    19151915{
    19161916        assert(dev);
    1917        
     1917
    19181918        if (ddf_dev_data_get(dev) != NULL)
    19191919                nic_unbind_and_destroy(dev);
     
    19281928{
    19291929        assert(dev);
    1930        
     1930
    19311931        e1000_delete_dev_data(dev);
    19321932}
     
    19471947{
    19481948        e1000_t *e1000 = DRIVER_DATA_DEV(dev);
    1949        
     1949
    19501950        if (hw_resources->irqs.count != 1)
    19511951                return EINVAL;
    1952        
     1952
    19531953        e1000->irq = hw_resources->irqs.irqs[0];
    19541954        e1000->reg_base_phys =
    19551955            MEMADDR_TO_PTR(RNGABS(hw_resources->mem_ranges.ranges[0]));
    1956        
     1956
    19571957        return EOK;
    19581958}
     
    19721972        assert(dev != NULL);
    19731973        assert(NIC_DATA_DEV(dev) != NULL);
    1974        
     1974
    19751975        hw_res_list_parsed_t hw_res_parsed;
    19761976        hw_res_list_parsed_init(&hw_res_parsed);
    1977        
     1977
    19781978        /* Get hw resources form parent driver */
    19791979        errno_t rc = nic_get_resources(NIC_DATA_DEV(dev), &hw_res_parsed);
    19801980        if (rc != EOK)
    19811981                return rc;
    1982        
     1982
    19831983        /* Fill resources information to the device */
    19841984        rc = e1000_fill_resource_info(dev, &hw_res_parsed);
    19851985        hw_res_list_parsed_clean(&hw_res_parsed);
    1986        
     1986
    19871987        return rc;
    19881988}
     
    20042004                return ENOMEM;
    20052005        }
    2006        
     2006
    20072007        e1000->parent_sess = ddf_dev_parent_sess_get(dev);
    20082008        if (e1000->parent_sess == NULL) {
     
    20102010                return EIO;
    20112011        }
    2012        
     2012
    20132013        /* Obtain and fill hardware resources info */
    20142014        errno_t rc = e1000_get_resource_info(dev);
     
    20182018                return rc;
    20192019        }
    2020        
     2020
    20212021        uint16_t device_id;
    20222022        rc = pci_config_space_read_16(ddf_dev_parent_sess_get(dev), PCI_DEVICE_ID,
     
    20272027                return rc;
    20282028        }
    2029        
     2029
    20302030        e1000_board_t board;
    20312031        switch (device_id) {
     
    20772077                return ENOTSUP;
    20782078        }
    2079        
     2079
    20802080        switch (board) {
    20812081        case E1000_82540:
     
    20982098                break;
    20992099        }
    2100        
     2100
    21012101        return EOK;
    21022102}
     
    21132113{
    21142114        e1000_t *e1000 = DRIVER_DATA_DEV(dev);
    2115        
     2115
    21162116        errno_t rc = pio_enable(e1000->reg_base_phys, 8 * PAGE_SIZE,
    21172117            &e1000->reg_base_virt);
    21182118        if (rc != EOK)
    21192119                return EADDRNOTAVAIL;
    2120        
     2120
    21212121        return EOK;
    21222122}
     
    21302130{
    21312131        ddf_fun_t *fun;
    2132        
     2132
    21332133        /* Initialize device structure for E1000 */
    21342134        errno_t rc = e1000_device_initialize(dev);
    21352135        if (rc != EOK)
    21362136                return rc;
    2137        
     2137
    21382138        /* Device initialization */
    21392139        nic_t *nic = ddf_dev_data_get(dev);
    21402140        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    2141        
     2141
    21422142        /* Map registers */
    21432143        rc = e1000_pio_enable(dev);
    21442144        if (rc != EOK)
    21452145                goto err_destroy;
    2146        
     2146
    21472147        e1000_initialize_registers(e1000);
    21482148        rc = e1000_initialize_tx_structure(e1000);
    21492149        if (rc != EOK)
    21502150                goto err_pio;
    2151        
     2151
    21522152        fibril_mutex_lock(&e1000->rx_lock);
    2153        
     2153
    21542154        e1000_fill_mac_from_eeprom(e1000);
    21552155        e1000_initialize_filters(e1000);
    2156        
     2156
    21572157        fibril_mutex_unlock(&e1000->rx_lock);
    2158        
     2158
    21592159        e1000_initialize_vlan(e1000);
    2160        
     2160
    21612161        fun = ddf_fun_create(nic_get_ddf_dev(nic), fun_exposed, "port0");
    21622162        if (fun == NULL)
     
    21642164        nic_set_ddf_fun(nic, fun);
    21652165        ddf_fun_set_ops(fun, &e1000_dev_ops);
    2166        
     2166
    21672167        int irq_cap;
    21682168        rc = e1000_register_int_handler(nic, &irq_cap);
     
    21702170                goto err_fun_create;
    21712171        }
    2172        
     2172
    21732173        rc = e1000_initialize_rx_structure(nic);
    21742174        if (rc != EOK)
    21752175                goto err_irq;
    2176        
     2176
    21772177        nic_address_t e1000_address;
    21782178        e1000_get_address(e1000, &e1000_address);
     
    21802180        if (rc != EOK)
    21812181                goto err_rx_structure;
    2182        
     2182
    21832183        struct timeval period;
    21842184        period.tv_sec = 0;
     
    21872187        if (rc != EOK)
    21882188                goto err_rx_structure;
    2189        
     2189
    21902190        rc = ddf_fun_bind(fun);
    21912191        if (rc != EOK)
    21922192                goto err_fun_bind;
    2193        
     2193
    21942194        rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
    21952195        if (rc != EOK)
    21962196                goto err_add_to_cat;
    2197        
     2197
    21982198        return EOK;
    2199        
     2199
    22002200err_add_to_cat:
    22012201        ddf_fun_unbind(fun);
     
    22302230{
    22312231        fibril_mutex_lock(&e1000->eeprom_lock);
    2232        
     2232
    22332233        /* Write address and START bit to EERD register */
    22342234        uint32_t write_data = e1000->info.eerd_start |
     
    22362236            e1000->info.eerd_address_offset);
    22372237        E1000_REG_WRITE(e1000, E1000_EERD, write_data);
    2238        
     2238
    22392239        uint32_t eerd = E1000_REG_READ(e1000, E1000_EERD);
    22402240        while ((eerd & e1000->info.eerd_done) == 0) {
     
    22422242                eerd = E1000_REG_READ(e1000, E1000_EERD);
    22432243        }
    2244        
     2244
    22452245        fibril_mutex_unlock(&e1000->eeprom_lock);
    2246        
     2246
    22472247        return (uint16_t) (eerd >> e1000->info.eerd_data_offset);
    22482248}
     
    22612261{
    22622262        fibril_mutex_lock(&e1000->rx_lock);
    2263        
     2263
    22642264        uint8_t *mac0_dest = (uint8_t *) address->address;
    22652265        uint8_t *mac1_dest = (uint8_t *) address->address + 1;
     
    22682268        uint8_t *mac4_dest = (uint8_t *) address->address + 4;
    22692269        uint8_t *mac5_dest = (uint8_t *) address->address + 5;
    2270        
     2270
    22712271        uint32_t rah = E1000_REG_READ(e1000, E1000_RAH_ARRAY(0));
    22722272        uint32_t ral = E1000_REG_READ(e1000, E1000_RAL_ARRAY(0));
    2273        
     2273
    22742274        *mac0_dest = (uint8_t) ral;
    22752275        *mac1_dest = (uint8_t) (ral >> 8);
     
    22782278        *mac4_dest = (uint8_t) rah;
    22792279        *mac5_dest = (uint8_t) (rah >> 8);
    2280        
     2280
    22812281        fibril_mutex_unlock(&e1000->rx_lock);
    22822282        return EOK;
     
    22952295        nic_t *nic = NIC_DATA_FUN(fun);
    22962296        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    2297        
     2297
    22982298        fibril_mutex_lock(&e1000->rx_lock);
    22992299        fibril_mutex_lock(&e1000->tx_lock);
    2300        
     2300
    23012301        errno_t rc = nic_report_address(nic, addr);
    23022302        if (rc == EOK)
    23032303                e1000_write_receive_address(e1000, 0, addr, false);
    2304        
     2304
    23052305        fibril_mutex_unlock(&e1000->tx_lock);
    23062306        fibril_mutex_unlock(&e1000->rx_lock);
    2307        
     2307
    23082308        return rc;
    23092309}
     
    23152315        uint16_t *mac2_dest = (uint16_t *) (address->address + 2);
    23162316        uint16_t *mac4_dest = (uint16_t *) (address->address + 4);
    2317        
     2317
    23182318        *mac0_dest = e1000_eeprom_read(e1000, 0);
    23192319        *mac2_dest = e1000_eeprom_read(e1000, 1);
     
    23342334{
    23352335        assert(nic);
    2336        
     2336
    23372337        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    23382338        fibril_mutex_lock(&e1000->tx_lock);
    2339        
     2339
    23402340        uint32_t tdt = E1000_REG_READ(e1000, E1000_TDT);
    23412341        e1000_tx_descriptor_t *tx_descriptor_addr = (e1000_tx_descriptor_t *)
    23422342            (e1000->tx_ring_virt + tdt * sizeof(e1000_tx_descriptor_t));
    2343        
     2343
    23442344        bool descriptor_available = false;
    2345        
     2345
    23462346        /* Descriptor never used */
    23472347        if (tx_descriptor_addr->length == 0)
    23482348                descriptor_available = true;
    2349        
     2349
    23502350        /* Descriptor done */
    23512351        if (tx_descriptor_addr->status & TXDESCRIPTOR_STATUS_DD)
    23522352                descriptor_available = true;
    2353        
     2353
    23542354        if (!descriptor_available) {
    23552355                /* Frame lost */
     
    23572357                return;
    23582358        }
    2359        
     2359
    23602360        memcpy(e1000->tx_frame_virt[tdt], data, size);
    2361        
     2361
    23622362        tx_descriptor_addr->phys_addr = PTR_TO_U64(e1000->tx_frame_phys[tdt]);
    23632363        tx_descriptor_addr->length = size;
    2364        
     2364
    23652365        /*
    23662366         * Report status to STATUS.DD (descriptor done),
     
    23702370            TXDESCRIPTOR_COMMAND_IFCS |
    23712371            TXDESCRIPTOR_COMMAND_EOP;
    2372        
     2372
    23732373        tx_descriptor_addr->checksum_offset = 0;
    23742374        tx_descriptor_addr->status = 0;
     
    23782378        } else
    23792379                tx_descriptor_addr->special = 0;
    2380        
     2380
    23812381        tx_descriptor_addr->checksum_start_field = 0;
    2382        
     2382
    23832383        tdt++;
    23842384        if (tdt == E1000_TX_FRAME_COUNT)
    23852385                tdt = 0;
    2386        
     2386
    23872387        E1000_REG_WRITE(e1000, E1000_TDT, tdt);
    2388        
     2388
    23892389        fibril_mutex_unlock(&e1000->tx_lock);
    23902390}
     
    23932393{
    23942394        printf("%s: HelenOS E1000 network adapter driver\n", NAME);
    2395        
     2395
    23962396        if (nic_driver_init(NAME) != EOK)
    23972397                return 1;
    2398        
     2398
    23992399        nic_driver_implement(&e1000_driver_ops, &e1000_dev_ops,
    24002400            &e1000_nic_iface);
    2401        
     2401
    24022402        ddf_log_init(NAME);
    24032403        return ddf_driver_main(&e1000_driver);
  • uspace/drv/nic/e1k/e1k.h

    r3061bc1 r8565a42  
    9797        uint32_t eerd_start;
    9898        uint32_t eerd_done;
    99        
     99
    100100        uint32_t eerd_address_offset;
    101101        uint32_t eerd_data_offset;
     
    159159        CTRL_SLU = (1 << 6),   /**< Set Link Up */
    160160        CTRL_ILOS = (1 << 7),  /**< Invert Loss-of-Signal */
    161        
     161
    162162        /** Speed selection shift */
    163163        CTRL_SPEED_SHIFT = 8,
     
    174174        /** Speed selection 10 Mb/s value */
    175175        CTRL_SPEED_1000 = 2,
    176        
     176
    177177        CTRL_FRCSPD = (1 << 11),   /**< Force Speed */
    178178        CTRL_FRCDPLX = (1 << 12),  /**< Force Duplex */
     
    186186        STATUS_FD = (1 << 0),  /**< Link Full Duplex configuration Indication */
    187187        STATUS_LU = (1 << 1),  /**< Link Up Indication */
    188        
     188
    189189        /** Link speed setting shift */
    190190        STATUS_SPEED_SHIFT = 6,
  • uspace/drv/nic/ne2k/dp8390.c

    r3061bc1 r8565a42  
    7474        /** Copy of RSR */
    7575        uint8_t status;
    76        
     76
    7777        /** Pointer to next frame */
    7878        uint8_t next;
    79        
     79
    8080        /** Receive Byte Count Low */
    8181        uint8_t rbcl;
    82        
     82
    8383        /** Receive Byte Count High */
    8484        uint8_t rbch;
     
    9595{
    9696        size_t i;
    97        
     97
    9898        for (i = 0; (i << 1) < size; i++)
    9999                *((uint16_t *) buf + i) = pio_read_16((ioport16_t *) (port));
     
    110110{
    111111        size_t i;
    112        
     112
    113113        for (i = 0; (i << 1) < size; i++)
    114114                pio_write_16((ioport16_t *) port, *((uint16_t *) buf + i));
     
    118118{
    119119        size_t esize = size & ~1;
    120        
     120
    121121        pio_write_8(ne2k->port + DP_RBCR0, esize & 0xff);
    122122        pio_write_8(ne2k->port + DP_RBCR1, (esize >> 8) & 0xff);
     
    124124        pio_write_8(ne2k->port + DP_RSAR1, (addr >> 8) & 0xff);
    125125        pio_write_8(ne2k->port + DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
    126        
     126
    127127        if (esize != 0) {
    128128                pio_read_buf_16(ne2k->data_port, buf, esize);
     
    130130                buf += esize;
    131131        }
    132        
     132
    133133        if (size) {
    134134                assert(size == 1);
    135                
     135
    136136                uint16_t word = pio_read_16(ne2k->data_port);
    137137                memcpy(buf, &word, 1);
     
    143143        size_t esize_ru = (size + 1) & ~1;
    144144        size_t esize = size & ~1;
    145        
     145
    146146        pio_write_8(ne2k->port + DP_RBCR0, esize_ru & 0xff);
    147147        pio_write_8(ne2k->port + DP_RBCR1, (esize_ru >> 8) & 0xff);
     
    149149        pio_write_8(ne2k->port + DP_RSAR1, (addr >> 8) & 0xff);
    150150        pio_write_8(ne2k->port + DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
    151        
     151
    152152        if (esize != 0) {
    153153                pio_write_buf_16(ne2k->data_port, buf, esize);
     
    155155                buf += esize;
    156156        }
    157        
     157
    158158        if (size) {
    159159                assert(size == 1);
    160                
     160
    161161                uint16_t word = 0;
    162                
     162
    163163                memcpy(&word, buf, 1);
    164164                pio_write_16(ne2k->data_port, word);
     
    169169{
    170170        unsigned int i;
    171        
     171
    172172        /* Reset the ethernet card */
    173173        uint8_t val = pio_read_8(ne2k->port + NE2K_RESET);
     
    175175        pio_write_8(ne2k->port + NE2K_RESET, val);
    176176        async_usleep(2000);
    177        
     177
    178178        /* Reset the DP8390 */
    179179        pio_write_8(ne2k->port + DP_CR, CR_STP | CR_DM_ABORT);
     
    197197{
    198198        unsigned int i;
    199        
     199
    200200        ne2k_init(ne2k);
    201        
     201
    202202        /* Check if the DP8390 is really there */
    203203        uint8_t val = pio_read_8(ne2k->port + DP_CR);
    204204        if ((val & (CR_STP | CR_TXP | CR_DM_ABORT)) != (CR_STP | CR_DM_ABORT))
    205205                return EXDEV;
    206        
     206
    207207        /* Disable the receiver and init TCR and DCR */
    208208        pio_write_8(ne2k->port + DP_RCR, RCR_MON);
    209209        pio_write_8(ne2k->port + DP_TCR, TCR_NORMAL);
    210210        pio_write_8(ne2k->port + DP_DCR, DCR_WORDWIDE | DCR_8BYTES | DCR_BMS);
    211        
     211
    212212        /* Setup a transfer to get the MAC address */
    213213        pio_write_8(ne2k->port + DP_RBCR0, ETH_ADDR << 1);
     
    216216        pio_write_8(ne2k->port + DP_RSAR1, 0);
    217217        pio_write_8(ne2k->port + DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
    218        
     218
    219219        for (i = 0; i < ETH_ADDR; i++)
    220220                ne2k->mac.address[i] = pio_read_16(ne2k->data_port);
    221        
     221
    222222        return EOK;
    223223}
     
    226226{
    227227        memcpy(&ne2k->mac, address, sizeof(nic_address_t));
    228        
     228
    229229        pio_write_8(ne2k->port + DP_CR, CR_PS_P0 | CR_DM_ABORT | CR_STP);
    230        
     230
    231231        pio_write_8(ne2k->port + DP_RBCR0, ETH_ADDR << 1);
    232232        pio_write_8(ne2k->port + DP_RBCR1, 0);
     
    254254        if (!ne2k->probed)
    255255                return EXDEV;
    256        
     256
    257257        ne2k_init(ne2k);
    258        
     258
    259259        /*
    260260         * Setup send queue. Use the first
     
    266266        fibril_mutex_initialize(&ne2k->sq_mutex);
    267267        fibril_condvar_initialize(&ne2k->sq_cv);
    268        
     268
    269269        /*
    270270         * Setup receive ring buffer. Use all the rest
     
    275275        ne2k->start_page = ne2k->sq.page + SQ_PAGES;
    276276        ne2k->stop_page = ne2k->sq.page + NE2K_SIZE / DP_PAGE;
    277        
     277
    278278        /*
    279279         * Initialization of the DP8390 following the mandatory procedure
     
    281281         * Controller", National Semiconductor, July 1995, Page 29).
    282282         */
    283        
     283
    284284        /* Step 1: */
    285285        pio_write_8(ne2k->port + DP_CR, CR_PS_P0 | CR_STP | CR_DM_ABORT);
    286        
     286
    287287        /* Step 2: */
    288288        pio_write_8(ne2k->port + DP_DCR, DCR_WORDWIDE | DCR_8BYTES | DCR_BMS);
    289        
     289
    290290        /* Step 3: */
    291291        pio_write_8(ne2k->port + DP_RBCR0, 0);
    292292        pio_write_8(ne2k->port + DP_RBCR1, 0);
    293        
     293
    294294        /* Step 4: */
    295295        pio_write_8(ne2k->port + DP_RCR, ne2k->receive_configuration);
    296        
     296
    297297        /* Step 5: */
    298298        pio_write_8(ne2k->port + DP_TCR, TCR_INTERNAL);
    299        
     299
    300300        /* Step 6: */
    301301        pio_write_8(ne2k->port + DP_BNRY, ne2k->start_page);
    302302        pio_write_8(ne2k->port + DP_PSTART, ne2k->start_page);
    303303        pio_write_8(ne2k->port + DP_PSTOP, ne2k->stop_page);
    304        
     304
    305305        /* Step 7: */
    306306        pio_write_8(ne2k->port + DP_ISR, 0xff);
    307        
     307
    308308        /* Step 8: */
    309309        pio_write_8(ne2k->port + DP_IMR,
    310310            IMR_PRXE | IMR_PTXE | IMR_RXEE | IMR_TXEE | IMR_OVWE | IMR_CNTE);
    311        
     311
    312312        /* Step 9: */
    313313        pio_write_8(ne2k->port + DP_CR, CR_PS_P1 | CR_DM_ABORT | CR_STP);
    314        
     314
    315315        pio_write_8(ne2k->port + DP_PAR0, ne2k->mac.address[0]);
    316316        pio_write_8(ne2k->port + DP_PAR1, ne2k->mac.address[1]);
     
    319319        pio_write_8(ne2k->port + DP_PAR4, ne2k->mac.address[4]);
    320320        pio_write_8(ne2k->port + DP_PAR5, ne2k->mac.address[5]);
    321        
     321
    322322        pio_write_8(ne2k->port + DP_MAR0, 0);
    323323        pio_write_8(ne2k->port + DP_MAR1, 0);
     
    328328        pio_write_8(ne2k->port + DP_MAR6, 0);
    329329        pio_write_8(ne2k->port + DP_MAR7, 0);
    330        
     330
    331331        pio_write_8(ne2k->port + DP_CURR, ne2k->start_page + 1);
    332        
     332
    333333        /* Step 10: */
    334334        pio_write_8(ne2k->port + DP_CR, CR_PS_P0 | CR_DM_ABORT | CR_STA);
    335        
     335
    336336        /* Step 11: */
    337337        pio_write_8(ne2k->port + DP_TCR, TCR_NORMAL);
    338        
     338
    339339        /* Reset counters by reading */
    340340        pio_read_8(ne2k->port + DP_CNTR0);
    341341        pio_read_8(ne2k->port + DP_CNTR1);
    342342        pio_read_8(ne2k->port + DP_CNTR2);
    343        
     343
    344344        /* Finish the initialization */
    345345        ne2k->up = true;
     
    415415
    416416        fibril_mutex_lock(&ne2k->sq_mutex);
    417        
     417
    418418        while (ne2k->sq.dirty) {
    419419                fibril_condvar_wait(&ne2k->sq_cv, &ne2k->sq_mutex);
    420420        }
    421        
     421
    422422        if ((size < ETH_MIN_PACK_SIZE) || (size > ETH_MAX_PACK_SIZE_TAGGED)) {
    423423                fibril_mutex_unlock(&ne2k->sq_mutex);
     
    446446        if (frame == NULL)
    447447                return NULL;
    448        
     448
    449449        memset(frame->data, 0, length);
    450450        uint8_t last = page + length / DP_PAGE;
    451        
     451
    452452        if (last >= ne2k->stop_page) {
    453453                size_t left = (ne2k->stop_page - page) * DP_PAGE
     
    481481                //TODO: isn't some locking necessary here?
    482482                uint8_t boundary = pio_read_8(ne2k->port + DP_BNRY) + 1;
    483                
     483
    484484                if (boundary == ne2k->stop_page)
    485485                        boundary = ne2k->start_page;
    486                
     486
    487487                pio_write_8(ne2k->port + DP_CR, CR_PS_P1 | CR_STA);
    488488                uint8_t current = pio_read_8(ne2k->port + DP_CURR);
     
    491491                        /* No more frames to process */
    492492                        break;
    493                
     493
    494494                recv_header_t header;
    495495                size_t size = sizeof(header);
    496496                size_t offset = boundary * DP_PAGE;
    497                
     497
    498498                /* Get the frame header */
    499499                pio_write_8(ne2k->port + DP_RBCR0, size & 0xff);
     
    502502                pio_write_8(ne2k->port + DP_RSAR1, (offset >> 8) & 0xff);
    503503                pio_write_8(ne2k->port + DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
    504                
     504
    505505                pio_read_buf_16(ne2k->data_port, (void *) &header, size);
    506506
     
    508508                    (((size_t) header.rbcl) | (((size_t) header.rbch) << 8)) - size;
    509509                uint8_t next = header.next;
    510                
     510
    511511                if ((length < ETH_MIN_PACK_SIZE)
    512512                    || (length > ETH_MAX_PACK_SIZE_TAGGED)) {
     
    535535                                break;
    536536                }
    537                
     537
    538538                /*
    539539                 * Update the boundary pointer
     
    585585                        ne2k->sq.dirty = false;
    586586                        ne2k->sq.size = 0;
    587                        
     587
    588588                        /* Signal a next frame to be sent */
    589589                        fibril_condvar_broadcast(&ne2k->sq_cv);
     
    615615                ne2k_reset(ne2k);
    616616        }
    617        
     617
    618618        /* Unmask interrupts to be processed in the next round */
    619619        pio_write_8(ne2k->port + DP_IMR,
     
    627627        else
    628628                ne2k->receive_configuration &= ~RCR_AB;
    629        
     629
    630630        pio_write_8(ne2k->port + DP_RCR, ne2k->receive_configuration);
    631631}
     
    637637        else
    638638                ne2k->receive_configuration &= ~RCR_AM;
    639        
     639
    640640        pio_write_8(ne2k->port + DP_RCR, ne2k->receive_configuration);
    641641}
     
    647647        else
    648648                ne2k->receive_configuration &= ~RCR_PRO;
    649        
     649
    650650        pio_write_8(ne2k->port + DP_RCR, ne2k->receive_configuration);
    651651}
     
    655655        /* Select Page 1 and stop all transfers */
    656656        pio_write_8(ne2k->port + DP_CR, CR_PS_P1 | CR_DM_ABORT | CR_STP);
    657        
     657
    658658        pio_write_8(ne2k->port + DP_MAR0, (uint8_t) hash);
    659659        pio_write_8(ne2k->port + DP_MAR1, (uint8_t) (hash >> 8));
     
    664664        pio_write_8(ne2k->port + DP_MAR6, (uint8_t) (hash >> 48));
    665665        pio_write_8(ne2k->port + DP_MAR7, (uint8_t) (hash >> 56));
    666        
     666
    667667        /* Select Page 0 and resume transfers */
    668668        pio_write_8(ne2k->port + DP_CR, CR_PS_P0 | CR_DM_ABORT | CR_STA);
  • uspace/drv/nic/ne2k/dp8390.h

    r3061bc1 r8565a42  
    235235        int irq;
    236236        nic_address_t mac;
    237        
     237
    238238        uint8_t start_page;  /**< Ring buffer start page */
    239239        uint8_t stop_page;   /**< Ring buffer stop page */
    240        
     240
    241241        /* Send queue */
    242242        struct {
     
    247247        fibril_mutex_t sq_mutex;
    248248        fibril_condvar_t sq_cv;
    249        
     249
    250250        /* Driver run-time variables */
    251251        bool probed;
  • uspace/drv/nic/ne2k/ne2k.c

    r3061bc1 r8565a42  
    183183        hw_res_list_parsed_t hw_res_parsed;
    184184        hw_res_list_parsed_init(&hw_res_parsed);
    185        
     185
    186186        errno_t rc = nic_get_resources(nic_data, &hw_res_parsed);
    187        
     187
    188188        if (rc != EOK)
    189189                goto failed;
    190        
     190
    191191        if (hw_res_parsed.irqs.count == 0) {
    192192                rc = EINVAL;
    193193                goto failed;
    194194        }
    195        
     195
    196196        if (hw_res_parsed.io_ranges.count == 0) {
    197197                rc = EINVAL;
    198198                goto failed;
    199199        }
    200        
     200
    201201        if (hw_res_parsed.io_ranges.ranges[0].size < NE2K_IO_SIZE) {
    202202                rc = EINVAL;
    203203                goto failed;
    204204        }
    205        
     205
    206206        ne2k_t *ne2k = (ne2k_t *) nic_get_specific(nic_data);
    207207        ne2k->irq = hw_res_parsed.irqs.irqs[0];
    208        
     208
    209209        addr_range_t regs = hw_res_parsed.io_ranges.ranges[0];
    210210        ne2k->base_port = RNGABSPTR(regs);
    211        
     211
    212212        hw_res_list_parsed_clean(&hw_res_parsed);
    213        
     213
    214214        /* Enable programmed I/O */
    215215        if (pio_enable_range(&regs, &ne2k->port) != EOK)
    216216                return EADDRNOTAVAIL;
    217        
     217
    218218        ne2k->data_port = ne2k->port + NE2K_DATA;
    219219        ne2k->receive_configuration = RCR_AB | RCR_AM;
    220220        ne2k->probed = false;
    221221        ne2k->up = false;
    222        
     222
    223223        /* Find out whether the device is present. */
    224224        if (ne2k_probe(ne2k) != EOK)
    225225                return ENOENT;
    226        
     226
    227227        ne2k->probed = true;
    228        
     228
    229229        if (ne2k_register_interrupt(nic_data, NULL) != EOK)
    230230                return EINVAL;
    231        
     231
    232232        return EOK;
    233        
     233
    234234failed:
    235235        hw_res_list_parsed_clean(&hw_res_parsed);
     
    358358{
    359359        ddf_fun_t *fun;
    360        
     360
    361361        /* Allocate driver data for the device. */
    362362        nic_t *nic_data = nic_create_and_bind(dev);
    363363        if (nic_data == NULL)
    364364                return ENOMEM;
    365        
     365
    366366        nic_set_send_frame_handler(nic_data, ne2k_send);
    367367        nic_set_state_change_handlers(nic_data,
     
    370370                ne2k_on_unicast_mode_change, ne2k_on_multicast_mode_change,
    371371                ne2k_on_broadcast_mode_change, NULL, NULL);
    372        
     372
    373373        ne2k_t *ne2k = malloc(sizeof(ne2k_t));
    374374        if (NULL != ne2k) {
     
    379379                return ENOMEM;
    380380        }
    381        
     381
    382382        ne2k->dev = dev;
    383383        ne2k->parent_sess = ddf_dev_parent_sess_get(dev);
     
    386386                return ENOMEM;
    387387        }
    388        
     388
    389389        errno_t rc = ne2k_dev_init(nic_data);
    390390        if (rc != EOK) {
     
    392392                return rc;
    393393        }
    394        
     394
    395395        rc = nic_report_address(nic_data, &ne2k->mac);
    396396        if (rc != EOK) {
     
    398398                return rc;
    399399        }
    400        
     400
    401401        fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0");
    402402        if (fun == NULL) {
     
    404404                return ENOMEM;
    405405        }
    406        
     406
    407407        nic_set_ddf_fun(nic_data, fun);
    408408        ddf_fun_set_ops(fun, &ne2k_dev_ops);
    409        
     409
    410410        rc = ddf_fun_bind(fun);
    411411        if (rc != EOK) {
     
    414414                return rc;
    415415        }
    416        
     416
    417417        rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
    418418        if (rc != EOK) {
     
    421421                return rc;
    422422        }
    423        
     423
    424424        return EOK;
    425425}
     
    441441{
    442442        printf("%s: HelenOS NE 2000 network adapter driver\n", NAME);
    443        
     443
    444444        nic_driver_init(NAME);
    445445        nic_driver_implement(&ne2k_driver_ops, &ne2k_dev_ops, &ne2k_nic_iface);
    446        
     446
    447447        return ddf_driver_main(&ne2k_driver);
    448448}
  • uspace/drv/nic/rtl8139/driver.c

    r3061bc1 r8565a42  
    156156            | rtl8139->rcr_data.defect_mask |
    157157            (RXBUF_SIZE_FLAGS << RCR_RBLEN_SHIFT);
    158        
     158
    159159        ddf_msg(LVL_DEBUG, "Rewriting rcr: %x -> %x", pio_read_32(rtl8139->io_port + RCR),
    160160            rcr);
     
    419419        pio_write_32(tsd, tsd_value);
    420420        return;
    421        
     421
    422422err_busy_no_inc:
    423423err_size:
     
    550550        bytes_received %= RxBUF_SIZE;
    551551        rx_offset %= RxBUF_SIZE;
    552        
     552
    553553        /* count how many bytes to read maximaly */
    554554        if (bytes_received < rx_offset)
     
    775775{
    776776        assert(nic_data);
    777        
     777
    778778        nic_poll_mode_t poll_mode = nic_query_poll_mode(nic_data, 0);
    779779
     
    11041104
    11051105        ddf_msg(LVL_DEBUG, "Creating buffers");
    1106        
     1106
    11071107        rtl8139->tx_buff_virt = AS_AREA_ANY;
    11081108        rc = dmamem_map_anonymous(TX_PAGES * PAGE_SIZE, DMAMEM_4GiB,
     
    11251125        ddf_msg(LVL_DEBUG, "Allocating receiver buffer of the size %d bytes",
    11261126            RxBUF_TOT_LENGTH);
    1127        
     1127
    11281128        rtl8139->rx_buff_virt = AS_AREA_ANY;
    11291129        rc = dmamem_map_anonymous(RxBUF_TOT_LENGTH, DMAMEM_4GiB,
     
    11951195        ddf_msg(LVL_DEBUG, "The device is initialized");
    11961196        return ret;
    1197        
     1197
    11981198failed:
    11991199        ddf_msg(LVL_ERROR, "The device initialization failed");
     
    13181318
    13191319        return EOK;
    1320        
     1320
    13211321err_fun_bind:
    13221322        ddf_fun_unbind(fun);
     
    15471547        if (rtl8139_pause_is_valid(rtl8139) != VALUE_RW)
    15481548                return EINVAL;
    1549        
     1549
    15501550        uint8_t msr = pio_read_8(rtl8139->io_port + MSR);
    15511551        msr &= ~(uint8_t)(MSR_TXFCE | MSR_RXFCE);
     
    15551555        if (allow_send)
    15561556                msr |= MSR_TXFCE;
    1557        
     1557
    15581558        pio_write_8(rtl8139->io_port + MSR, msr);
    15591559
     
    16241624        if ((advertisement | RTL8139_AUTONEG_CAPS) != RTL8139_AUTONEG_CAPS)
    16251625                return EINVAL; /* some unsuported mode is requested */
    1626        
     1626
    16271627        assert(advertisement != 0);
    16281628
  • uspace/drv/nic/rtl8139/general.h

    r3061bc1 r8565a42  
    4545        /** Register value set in the last timer period */
    4646        uint32_t last_val;
    47        
     47
    4848        /** Register value set in the common timer period */
    4949        uint32_t full_val;
    50        
     50
    5151        /** Amount of full register periods in timer period */
    5252        size_t full_skips;
    53        
     53
    5454        /** Remaining full register periods to the next period end */
    5555        size_t full_skips_remains;
    56        
     56
    5757        /** Mark if there is a last run */
    5858        int last_run;
  • uspace/drv/nic/rtl8169/driver.c

    r3061bc1 r8565a42  
    352352        ddf_msg(LVL_DEBUG, "The device is initialized");
    353353        return ret;
    354        
     354
    355355failed:
    356356        ddf_msg(LVL_ERROR, "The device initialization failed");
     
    460460                goto err_fun_bind;
    461461        }
    462        
     462
    463463        ddf_msg(LVL_NOTE, "The %s device has been successfully initialized.",
    464464            ddf_dev_get_name(dev));
     
    512512        if (rtl8169->pci_vid == PCI_VID_REALTEK)
    513513                str_cpy(info->vendor_name, NIC_VENDOR_MAX_LENGTH, "Realtek");
    514        
     514
    515515        if (rtl8169->pci_vid == PCI_VID_DLINK)
    516516                str_cpy(info->vendor_name, NIC_VENDOR_MAX_LENGTH, "D-Link");
    517        
     517
    518518        if (rtl8169->pci_pid == 0x8168)
    519519                str_cpy(info->model_name, NIC_MODEL_MAX_LENGTH, "RTL8168");
    520        
     520
    521521        if (rtl8169->pci_pid == 0x8169)
    522522                str_cpy(info->model_name, NIC_MODEL_MAX_LENGTH, "RTL8169");
     
    577577        bmcr = rtl8169_mii_read(rtl8169, MII_BMCR);
    578578        bmcr &= ~(BMCR_DUPLEX | BMCR_SPD_100 | BMCR_SPD_1000);
    579        
     579
    580580        /* Disable autonegotiation */
    581581        bmcr &= ~BMCR_AN_ENABLE;
     
    918918{
    919919        rtl8169_t *rtl8169 = nic_get_specific(nic_data);
    920        
     920
    921921        /* Configure Receive Control Register */
    922922        uint32_t rcr = pio_read_32(rtl8169->regs + RCR);
     
    961961                write_barrier();
    962962                ddf_msg(LVL_DEBUG, "TX status for descr %d: 0x%08x", tail, descr->control);
    963        
     963
    964964                tail = (tail + 1) % TX_BUFFERS_COUNT;
    965965                sent++;
     
    10051005                if (descr->control & CONTROL_FS)
    10061006                        fsidx = tail;
    1007                
     1007
    10081008                if (descr->control & CONTROL_LS) {
    10091009                        ddf_msg(LVL_DEBUG, "received message at slot %d, control 0x%08x", tail, descr->control);
Note: See TracChangeset for help on using the changeset viewer.