Changeset 56c0930 in mainline


Ignore:
Timestamp:
2015-02-20T14:33:29Z (9 years ago)
Author:
Jan Kolarik <kolarik@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4cb0148
Parents:
ab365c4
Message:

Started writing TX and RX handlers, VIF init, setting RX filter, PLL init and calibration, some corrections. Added HW values array initialization, registered diagnostic polling fibril. But still not receiving any packets…

Location:
uspace
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ar9271/ar9271.c

    rab365c4 r56c0930  
    101101/* IEEE802.11 callbacks */
    102102static int ar9271_ieee80211_start(ieee80211_dev_t *ieee80211_dev);
     103static int ar9271_ieee80211_tx_handler(ieee80211_dev_t *ieee80211_dev,
     104        void *buffer, size_t buffer_size);
    103105
    104106static driver_ops_t ar9271_driver_ops = {
     
    112114
    113115static ieee80211_ops_t ar9271_ieee80211_ops = {
    114         .start = ar9271_ieee80211_start
    115 };
    116 
    117 static int ar9271_set_rx_filter(ar9271_t *ar9271)
    118 {
    119         uint32_t filter_bits;
    120         int rc = wmi_reg_read(ar9271->htc_device, AR9271_RX_FILTER,
    121                 &filter_bits);
    122         if(rc != EOK) {
    123                 usb_log_error("Failed to read RX filter.\n");
    124                 return EINVAL;
    125         }
    126        
    127         /* TODO: Do proper filtering here. */
    128        
    129         filter_bits |= AR9271_RX_FILTER_UNI | AR9271_RX_FILTER_MULTI |
    130                 AR9271_RX_FILTER_BROAD | AR9271_RX_FILTER_PROMISCUOUS;
    131        
    132         rc = wmi_reg_write(ar9271->htc_device, AR9271_RX_FILTER, filter_bits);
    133         if(rc != EOK) {
    134                 usb_log_error("Failed to write RX filter.\n");
    135                 return EINVAL;
    136         }
    137        
    138         return EOK;
    139 }
    140 
    141 static int ar9271_rx_init(ar9271_t *ar9271)
    142 {
    143         int rc = wmi_reg_write(ar9271->htc_device, AR9271_COMMAND,
    144                 AR9271_COMMAND_RX_ENABLE);
    145         if(rc != EOK) {
    146                 usb_log_error("Failed to send RX enable command.\n");
    147                 return EINVAL;
    148         }
    149        
    150         rc = ar9271_set_rx_filter(ar9271);
    151         if(rc != EOK) {
    152                 usb_log_error("Failed to set RX filtering.\n");
    153                 return EINVAL;
    154         }
     116        .start = ar9271_ieee80211_start,
     117        .tx_handler = ar9271_ieee80211_tx_handler
     118};
     119
     120static int ar9271_ieee80211_tx_handler(ieee80211_dev_t *ieee80211_dev,
     121        void *buffer, size_t buffer_size)
     122{
     123        /* TODO: Process TX message properly */
     124       
     125        size_t complete_size, offset;
     126        void *complete_buffer;
     127        int endpoint;
     128       
     129        ar9271_t *ar9271 = (ar9271_t *) ieee80211_dev->driver_data;
     130       
     131        ieee80211_header_t *ieee80211_header = (ieee80211_header_t *) buffer;
     132       
     133        if(ieee80211_is_data_frame(ieee80211_header)) {
     134                offset = sizeof(htc_frame_header_t);
     135                complete_size = buffer_size + offset;
     136                complete_buffer = malloc(complete_size);
     137                endpoint = ar9271->htc_device->endpoints.data_be_endpoint;
     138        } else {
     139                offset = sizeof(htc_tx_management_header_t) +
     140                        sizeof(htc_frame_header_t);
     141                complete_size = buffer_size + offset;
     142                complete_buffer = malloc(complete_size);
     143                endpoint = ar9271->htc_device->endpoints.mgmt_endpoint;
     144        }
     145       
     146        /* Copy IEEE802.11 data to new allocated buffer with HTC headers. */
     147        memcpy(complete_buffer + offset, buffer, buffer_size);
     148       
     149        htc_send_data_message(ar9271->htc_device, complete_buffer,
     150                complete_size, endpoint);
     151       
     152        free(complete_buffer);
     153       
     154        return EOK;
     155}
     156
     157static int ar9271_data_polling(void *arg)
     158{
     159        ar9271_t *ar9271 = (ar9271_t *) arg;
     160        size_t buffer_size = ar9271->ath_device->data_response_length;
     161        void *buffer = malloc(buffer_size);
     162       
     163        while(true) {
     164                int rc =
     165                htc_read_data_message(ar9271->htc_device, buffer, buffer_size,
     166                        NULL);
     167                usb_log_info("RC is %d.\n", rc);
     168               
     169                /* TODO: Process RX message */
     170        }
     171       
     172        return EOK;
     173}
     174
     175static int ar9271_diag_polling(void *arg)
     176{
     177        ar9271_t *ar9271 = (ar9271_t *) arg;
     178       
     179        while(true) {
     180                uint32_t result;
     181                wmi_reg_read(ar9271->htc_device, 0x80F0, &result);
     182                usb_log_info("RX count: %x\n", result);
     183                wmi_reg_read(ar9271->htc_device, 0x8098, &result);
     184                usb_log_info("Beacon count: %x\n", result);
     185                sleep(1);
     186        }
     187       
     188        return EOK;
     189}
     190
     191static int ar9271_register_polling_fibrils(ar9271_t *ar9271)
     192{
     193        /* Add data polling fibril. */
     194        fid_t fibril = fibril_create(ar9271_data_polling, ar9271);
     195        if (fibril == 0) {
     196                return ENOMEM;
     197        }
     198        fibril_add_ready(fibril);
     199       
     200        /* Add debug polling fibril. */
     201        fibril = fibril_create(ar9271_diag_polling, ar9271);
     202        if (fibril == 0) {
     203                return ENOMEM;
     204        }
     205        fibril_add_ready(fibril);
    155206       
    156207        return EOK;
     
    165216        if(rc != EOK) {
    166217                usb_log_error("Failed to flush receiving buffer.\n");
    167                 return EINVAL;
     218                return rc;
    168219        }
    169220       
     
    171222        if(rc != EOK) {
    172223                usb_log_error("Failed to do HW reset.\n");
    173                 return EINVAL;
     224                return rc;
    174225        }
    175226       
     
    179230        if(rc != EOK) {
    180231                usb_log_error("Failed to set HTC mode.\n");
    181                 return EINVAL;
     232                return rc;
    182233        }
    183234       
     
    186237        if(rc != EOK) {
    187238                usb_log_error("Failed to send ath init command.\n");
    188                 return EINVAL;
     239                return rc;
    189240        }
    190241       
     
    193244        if(rc != EOK) {
    194245                usb_log_error("Failed to send receiving init command.\n");
    195                 return EINVAL;
    196         }
    197        
    198         rc = ar9271_rx_init(ar9271);
     246                return rc;
     247        }
     248       
     249        rc = hw_rx_init(ar9271);
    199250        if(rc != EOK) {
    200251                usb_log_error("Failed to initialize RX.\n");
    201                 return EINVAL;
     252                return rc;
     253        }
     254       
     255        rc = htc_init_new_vif(ar9271->htc_device);
     256        if(rc != EOK) {
     257                usb_log_error("Failed to initialize new VIF.\n");
     258                return rc;
     259        }
     260       
     261        rc = ar9271_register_polling_fibrils(ar9271);
     262        if(rc != EOK) {
     263                usb_log_error("Failed to register polling fibrils.\n");
     264                return rc;
    202265        }
    203266       
     
    220283                free(ar9271->ath_device);
    221284                usb_log_error("Failed to initialize ath device.\n");
    222                 return EINVAL;
     285                return rc;
     286        }
     287       
     288        /* IEEE 802.11 framework structure initialization. */
     289        ar9271->ieee80211_dev = calloc(1, sizeof(ieee80211_dev_t));
     290        if (!ar9271->ieee80211_dev) {
     291                free(ar9271->ath_device);
     292                usb_log_error("Failed to allocate memory for IEEE80211 device "
     293                    "structure.\n");
     294                return ENOMEM;
     295        }
     296       
     297        rc = ieee80211_device_init(ar9271->ieee80211_dev, ar9271,
     298                ar9271->ddf_dev);
     299        if(rc != EOK) {
     300                free(ar9271->ieee80211_dev);
     301                free(ar9271->ath_device);
     302                usb_log_error("Failed to initialize IEEE80211 device structure."
     303                        "\n");
     304                return rc;
    223305        }
    224306               
     
    226308        ar9271->htc_device = calloc(1, sizeof(htc_device_t));
    227309        if(!ar9271->htc_device) {
     310                free(ar9271->ieee80211_dev);
    228311                free(ar9271->ath_device);
    229312                usb_log_error("Failed to allocate memory for HTC device "
     
    232315        }
    233316       
    234         rc = htc_device_init(ar9271->ath_device, ar9271->htc_device);
     317        rc = htc_device_init(ar9271->ath_device, ar9271->ieee80211_dev,
     318                ar9271->htc_device);
    235319        if(rc != EOK) {
    236320                free(ar9271->htc_device);
     321                free(ar9271->ieee80211_dev);
    237322                free(ar9271->ath_device);
    238323                usb_log_error("Failed to initialize HTC device structure.\n");
    239                 return EINVAL;
    240         }
    241        
    242         /* IEEE 802.11 framework structure initialization. */
    243         ar9271->ieee80211_dev = calloc(1, sizeof(ieee80211_dev_t));
    244         if (!ar9271->ieee80211_dev) {
    245                 free(ar9271->htc_device);
    246                 free(ar9271->ath_device);
    247                 usb_log_error("Failed to allocate memory for IEEE80211 device "
    248                     "structure.\n");
    249                 return ENOMEM;
    250         }
    251        
    252         rc = ieee80211_device_init(ar9271->ieee80211_dev, ar9271,
    253                 ar9271->ddf_dev);
    254         if(rc != EOK) {
    255                 free(ar9271->ieee80211_dev);
    256                 free(ar9271->htc_device);
    257                 free(ar9271->ath_device);
    258                 usb_log_error("Failed to initialize IEEE80211 device structure."
    259                         "\n");
    260                 return EINVAL;
     324                return rc;
    261325        }
    262326       
  • uspace/drv/bus/usb/ar9271/ar9271.h

    rab365c4 r56c0930  
    4040#include "htc.h"
    4141
    42 /** Max supported channel frequency. */
    43 #define AR9271_MAX_CHANNEL 2472
    44 
    45 /** Number of transmisson queues */
     42/** Number of transmission queues */
    4643#define AR9271_QUEUES_COUNT 10
    4744
     
    8380        AR9271_RTC_RC_MAC_COLD = 0x00000002,
    8481        AR9271_RTC_RC_MASK = 0x00000003,
     82        AR9271_RTC_PLL_CONTROL = 0x7014,
    8583        AR9271_RTC_RESET = 0x7040,
    8684        AR9271_RTC_STATUS = 0x7044,
     
    9290        AR9271_RTC_FORCE_WAKE_ON_INT = 0x00000002,
    9391               
     92        /* MAC Registers */
     93        AR9271_STATION_ID0 = 0x8000,    /**< STA Address Lower 32 Bits */
     94        AR9271_STATION_ID1 = 0x8004,    /**< STA Address Upper 16 Bits */
     95        AR9271_BSSID0 = 0x8008,                 /**< BSSID Lower 32 Bits */
     96        AR9271_BSSID1 = 0x800C,                 /**< BSSID Upper 16 Bits */
     97        AR9271_BSSID_MASK0 = 0x80E0,            /**< BSSID Mask Lower 32 Bits */
     98        AR9271_BSSID_MASK1 = 0x80E4,            /**< BSSID Mask Upper 16 Bits */
     99        AR9271_STATION_ID1_MASK = 0x0000FFFF,
     100               
     101        /* RX filtering register */
    94102        AR9271_RX_FILTER = 0x803C,
    95103        AR9271_RX_FILTER_UNI = 0x00000001,
     
    100108        AR9271_RX_FILTER_PROMISCUOUS = 0x00000020,
    101109        AR9271_RX_FILTER_PROBEREQ = 0x00000080,
    102                
     110        AR9271_RX_FILTER_MYBEACON = 0x00000200,
     111               
     112        /* Physical layer registers */
    103113        AR9271_PHY_BASE = 0x9800,
    104         AR9271_PHY_ACTIVE = 0x981C,     
     114        AR9271_PHY_ACTIVE = 0x981C,
     115        AR9271_ADC_CONTROL = 0x982C,
     116        AR9271_AGC_CONTROL = 0x9860,
    105117        AR9271_PHY_MODE = 0xA200,
     118        AR9271_PHY_CCK_TX_CTRL = 0xA204,
     119        AR9271_PHY_TPCRG1 = 0xA258,
     120        AR9271_CARRIER_LEAK_CONTROL = 0xA358,
     121        AR9271_ADC_CONTROL_OFF_PWDADC = 0x00008000,
     122        AR9271_AGC_CONTROL_CALIB = 0x00000001,
     123        AR9271_AGC_CONTROL_TX_CALIB = 0x00010000,
    106124        AR9271_PHY_MODE_2G = 0x02,
    107125        AR9271_PHY_MODE_DYNAMIC = 0x04,
    108         AR9271_PHY_CCK_TX_CTRL = 0xA204,
    109126        AR9271_PHY_CCK_TX_CTRL_JAPAN = 0x00000010,
     127        AR9271_PHY_TPCRG1_PD_CALIB = 0x00400000,
     128        AR9271_CARRIER_LEAK_CALIB = 0x00000002,
    110129               
    111130        AR9271_OPMODE_STATION_AP_MASK = 0x00010000,
    112131        AR9271_OPMODE_ADHOC_MASK = 0x00020000,
     132               
     133        AR9271_CLOCK_CONTROL = 0x50040,
     134        AR9271_MAX_CPU_CLOCK = 0x304,
    113135               
    114136        AR9271_RESET_POWER_DOWN_CONTROL = 0x50044,
     
    117139   
    118140        /* FW Addresses */
    119         AR9271_FW_ADDRESS =     0x501000,
    120         AR9271_FW_OFFSET =      0x903000,
    121        
    122         /* MAC Registers */
    123         AR9271_STATION_ID0 = 0x8000, /**< STA Address Lower 32 Bits */
    124         AR9271_STATION_ID1 = 0x8004, /**< STA Address Upper 16 Bits */
    125         AR9271_STATION_BSSID0 = 0x8008, /**< BSSID Lower 32 Bits */
    126         AR9271_STATION_BSSID1 = 0x800C, /**< BSSID Upper 16 Bits */
     141        AR9271_FW_ADDRESS = 0x501000,
     142        AR9271_FW_OFFSET = 0x903000,
    127143} ar9271_registers_t;
    128144
     
    151167} ar9271_t;
    152168
     169/**
     170 * AR9271 hardware init values.
     171 *
     172 * Taken from Linux sources, some values omitted.
     173 */
     174static const uint32_t ar9271_init_array[][2] = {
     175        {0x0000000c, 0x00000000},
     176        {0x00000030, 0x00020045},
     177        {0x00000034, 0x00000005},
     178        {0x00000040, 0x00000000},
     179        {0x00000044, 0x00000008},
     180        {0x00000048, 0x00000008},
     181        {0x0000004c, 0x00000010},
     182        {0x00000050, 0x00000000},
     183        {0x00000054, 0x0000001f},
     184        {0x00000800, 0x00000000},
     185        {0x00000804, 0x00000000},
     186        {0x00000808, 0x00000000},
     187        {0x0000080c, 0x00000000},
     188        {0x00000810, 0x00000000},
     189        {0x00000814, 0x00000000},
     190        {0x00000818, 0x00000000},
     191        {0x0000081c, 0x00000000},
     192        {0x00000820, 0x00000000},
     193        {0x00000824, 0x00000000},
     194        {0x00001040, 0x002ffc0f},
     195        {0x00001044, 0x002ffc0f},
     196        {0x00001048, 0x002ffc0f},
     197        {0x0000104c, 0x002ffc0f},
     198        {0x00001050, 0x002ffc0f},
     199        {0x00001054, 0x002ffc0f},
     200        {0x00001058, 0x002ffc0f},
     201        {0x0000105c, 0x002ffc0f},
     202        {0x00001060, 0x002ffc0f},
     203        {0x00001064, 0x002ffc0f},
     204        {0x00001230, 0x00000000},
     205        {0x00001270, 0x00000000},
     206        {0x00001038, 0x00000000},
     207        {0x00001078, 0x00000000},
     208        {0x000010b8, 0x00000000},
     209        {0x000010f8, 0x00000000},
     210        {0x00001138, 0x00000000},
     211        {0x00001178, 0x00000000},
     212        {0x000011b8, 0x00000000},
     213        {0x000011f8, 0x00000000},
     214        {0x00001238, 0x00000000},
     215        {0x00001278, 0x00000000},
     216        {0x000012b8, 0x00000000},
     217        {0x000012f8, 0x00000000},
     218        {0x00001338, 0x00000000},
     219        {0x00001378, 0x00000000},
     220        {0x000013b8, 0x00000000},
     221        {0x000013f8, 0x00000000},
     222        {0x00001438, 0x00000000},
     223        {0x00001478, 0x00000000},
     224        {0x000014b8, 0x00000000},
     225        {0x000014f8, 0x00000000},
     226        {0x00001538, 0x00000000},
     227        {0x00001578, 0x00000000},
     228        {0x000015b8, 0x00000000},
     229        {0x000015f8, 0x00000000},
     230        {0x00001638, 0x00000000},
     231        {0x00001678, 0x00000000},
     232        {0x000016b8, 0x00000000},
     233        {0x000016f8, 0x00000000},
     234        {0x00001738, 0x00000000},
     235        {0x00001778, 0x00000000},
     236        {0x000017b8, 0x00000000},
     237        {0x000017f8, 0x00000000},
     238        {0x0000103c, 0x00000000},
     239        {0x0000107c, 0x00000000},
     240        {0x000010bc, 0x00000000},
     241        {0x000010fc, 0x00000000},
     242        {0x0000113c, 0x00000000},
     243        {0x0000117c, 0x00000000},
     244        {0x000011bc, 0x00000000},
     245        {0x000011fc, 0x00000000},
     246        {0x0000123c, 0x00000000},
     247        {0x0000127c, 0x00000000},
     248        {0x000012bc, 0x00000000},
     249        {0x000012fc, 0x00000000},
     250        {0x0000133c, 0x00000000},
     251        {0x0000137c, 0x00000000},
     252        {0x000013bc, 0x00000000},
     253        {0x000013fc, 0x00000000},
     254        {0x0000143c, 0x00000000},
     255        {0x0000147c, 0x00000000},
     256        {0x00004030, 0x00000002},
     257        {0x0000403c, 0x00000002},
     258        {0x00004024, 0x0000001f},
     259        {0x00004060, 0x00000000},
     260        {0x00004064, 0x00000000},
     261        {0x00008018, 0x00000700},
     262        {0x00008020, 0x00000000},
     263        {0x00008038, 0x00000000},
     264        {0x00008048, 0x00000000},
     265        {0x00008054, 0x00000000},
     266        {0x00008058, 0x00000000},
     267        {0x0000805c, 0x000fc78f},
     268        {0x00008060, 0x0000000f},
     269        {0x00008064, 0x00000000},
     270        {0x00008070, 0x00000000},
     271        {0x000080b0, 0x00000000},
     272        {0x000080b4, 0x00000000},
     273        {0x000080b8, 0x00000000},
     274        {0x000080bc, 0x00000000},
     275        {0x000080c0, 0x2a80001a},
     276        {0x000080c4, 0x05dc01e0},
     277        {0x000080c8, 0x1f402710},
     278        {0x000080cc, 0x01f40000},
     279        {0x000080d0, 0x00001e00},
     280        {0x000080d4, 0x00000000},
     281        {0x000080d8, 0x00400000},
     282        {0x000080e0, 0xffffffff},
     283        {0x000080e4, 0x0000ffff},
     284        {0x000080e8, 0x003f3f3f},
     285        {0x000080ec, 0x00000000},
     286        {0x000080f0, 0x00000000},
     287        {0x000080f4, 0x00000000},
     288        {0x000080f8, 0x00000000},
     289        {0x000080fc, 0x00020000},
     290        {0x00008100, 0x00020000},
     291        {0x00008104, 0x00000001},
     292        {0x00008108, 0x00000052},
     293        {0x0000810c, 0x00000000},
     294        {0x00008110, 0x00000168},
     295        {0x00008118, 0x000100aa},
     296        {0x0000811c, 0x00003210},
     297        {0x00008120, 0x08f04810},
     298        {0x00008124, 0x00000000},
     299        {0x00008128, 0x00000000},
     300        {0x0000812c, 0x00000000},
     301        {0x00008130, 0x00000000},
     302        {0x00008134, 0x00000000},
     303        {0x00008138, 0x00000000},
     304        {0x0000813c, 0x00000000},
     305        {0x00008144, 0xffffffff},
     306        {0x00008168, 0x00000000},
     307        {0x0000816c, 0x00000000},
     308        {0x00008170, 0x32143320},
     309        {0x00008174, 0xfaa4fa50},
     310        {0x00008178, 0x00000100},
     311        {0x0000817c, 0x00000000},
     312        {0x000081c0, 0x00000000},
     313        {0x000081d0, 0x0000320a},
     314        {0x000081ec, 0x00000000},
     315        {0x000081f0, 0x00000000},
     316        {0x000081f4, 0x00000000},
     317        {0x000081f8, 0x00000000},
     318        {0x000081fc, 0x00000000},
     319        {0x00008200, 0x00000000},
     320        {0x00008204, 0x00000000},
     321        {0x00008208, 0x00000000},
     322        {0x0000820c, 0x00000000},
     323        {0x00008210, 0x00000000},
     324        {0x00008214, 0x00000000},
     325        {0x00008218, 0x00000000},
     326        {0x0000821c, 0x00000000},
     327        {0x00008220, 0x00000000},
     328        {0x00008224, 0x00000000},
     329        {0x00008228, 0x00000000},
     330        {0x0000822c, 0x00000000},
     331        {0x00008230, 0x00000000},
     332        {0x00008234, 0x00000000},
     333        {0x00008238, 0x00000000},
     334        {0x0000823c, 0x00000000},
     335        {0x00008240, 0x00100000},
     336        {0x00008244, 0x0010f400},
     337        {0x00008248, 0x00000100},
     338        {0x0000824c, 0x0001e800},
     339        {0x00008250, 0x00000000},
     340        {0x00008254, 0x00000000},
     341        {0x00008258, 0x00000000},
     342        {0x0000825c, 0x400000ff},
     343        {0x00008260, 0x00080922},
     344        {0x00008264, 0x88a00010},
     345        {0x00008270, 0x00000000},
     346        {0x00008274, 0x40000000},
     347        {0x00008278, 0x003e4180},
     348        {0x0000827c, 0x00000000},
     349        {0x00008284, 0x0000002c},
     350        {0x00008288, 0x0000002c},
     351        {0x0000828c, 0x00000000},
     352        {0x00008294, 0x00000000},
     353        {0x00008298, 0x00000000},
     354        {0x0000829c, 0x00000000},
     355        {0x00008300, 0x00000040},
     356        {0x00008314, 0x00000000},
     357        {0x00008328, 0x00000000},
     358        {0x0000832c, 0x00000001},
     359        {0x00008330, 0x00000302},
     360        {0x00008334, 0x00000e00},
     361        {0x00008338, 0x00ff0000},
     362        {0x0000833c, 0x00000000},
     363        {0x00008340, 0x00010380},
     364        {0x00008344, 0x00581043},
     365        {0x00007010, 0x00000030},
     366        {0x00009808, 0x00000000},
     367        {0x0000980c, 0xafe68e30},
     368        {0x00009810, 0xfd14e000},
     369        {0x00009814, 0x9c0a9f6b},
     370        {0x0000981c, 0x00000000},
     371        {0x0000982c, 0x0000a000},
     372        {0x00009830, 0x00000000},
     373        {0x0000983c, 0x00200400},
     374        {0x0000984c, 0x0040233c},
     375        {0x00009854, 0x00000044},
     376        {0x00009900, 0x00000000},
     377        {0x00009904, 0x00000000},
     378        {0x00009908, 0x00000000},
     379        {0x0000990c, 0x00000000},
     380        {0x0000991c, 0x10000fff},
     381        {0x00009920, 0x04900000},
     382        {0x00009928, 0x00000001},
     383        {0x0000992c, 0x00000004},
     384        {0x00009934, 0x1e1f2022},
     385        {0x00009938, 0x0a0b0c0d},
     386        {0x0000993c, 0x00000000},
     387        {0x00009940, 0x14750604},
     388        {0x00009948, 0x9280c00a},
     389        {0x0000994c, 0x00020028},
     390        {0x00009954, 0x5f3ca3de},
     391        {0x00009958, 0x0108ecff},
     392        {0x00009968, 0x000003ce},
     393        {0x00009970, 0x192bb514},
     394        {0x00009974, 0x00000000},
     395        {0x00009978, 0x00000001},
     396        {0x0000997c, 0x00000000},
     397        {0x00009980, 0x00000000},
     398        {0x00009984, 0x00000000},
     399        {0x00009988, 0x00000000},
     400        {0x0000998c, 0x00000000},
     401        {0x00009990, 0x00000000},
     402        {0x00009994, 0x00000000},
     403        {0x00009998, 0x00000000},
     404        {0x0000999c, 0x00000000},
     405        {0x000099a0, 0x00000000},
     406        {0x000099a4, 0x00000001},
     407        {0x000099a8, 0x201fff00},
     408        {0x000099ac, 0x2def0400},
     409        {0x000099b0, 0x03051000},
     410        {0x000099b4, 0x00000820},
     411        {0x000099dc, 0x00000000},
     412        {0x000099e0, 0x00000000},
     413        {0x000099e4, 0xaaaaaaaa},
     414        {0x000099e8, 0x3c466478},
     415        {0x000099ec, 0x0cc80caa},
     416        {0x000099f0, 0x00000000},
     417        {0x0000a208, 0x803e68c8},
     418        {0x0000a210, 0x4080a333},
     419        {0x0000a214, 0x00206c10},
     420        {0x0000a218, 0x009c4060},
     421        {0x0000a220, 0x01834061},
     422        {0x0000a224, 0x00000400},
     423        {0x0000a228, 0x000003b5},
     424        {0x0000a22c, 0x00000000},
     425        {0x0000a234, 0x20202020},
     426        {0x0000a238, 0x20202020},
     427        {0x0000a244, 0x00000000},
     428        {0x0000a248, 0xfffffffc},
     429        {0x0000a24c, 0x00000000},
     430        {0x0000a254, 0x00000000},
     431        {0x0000a258, 0x0ccb5380},
     432        {0x0000a25c, 0x15151501},
     433        {0x0000a260, 0xdfa90f01},
     434        {0x0000a268, 0x00000000},
     435        {0x0000a26c, 0x0ebae9e6},
     436        {0x0000a388, 0x0c000000},
     437        {0x0000a38c, 0x20202020},
     438        {0x0000a390, 0x20202020},
     439        {0x0000a39c, 0x00000001},
     440        {0x0000a3a0, 0x00000000},
     441        {0x0000a3a4, 0x00000000},
     442        {0x0000a3a8, 0x00000000},
     443        {0x0000a3ac, 0x00000000},
     444        {0x0000a3b0, 0x00000000},
     445        {0x0000a3b4, 0x00000000},
     446        {0x0000a3b8, 0x00000000},
     447        {0x0000a3bc, 0x00000000},
     448        {0x0000a3c0, 0x00000000},
     449        {0x0000a3c4, 0x00000000},
     450        {0x0000a3cc, 0x20202020},
     451        {0x0000a3d0, 0x20202020},
     452        {0x0000a3d4, 0x20202020},
     453        {0x0000a3e4, 0x00000000},
     454        {0x0000a3e8, 0x18c43433},
     455        {0x0000a3ec, 0x00f70081},
     456        {0x0000a3f0, 0x01036a2f},
     457        {0x0000a3f4, 0x00000000},
     458        {0x0000d270, 0x0d820820},
     459        {0x0000d35c, 0x07ffffef},
     460        {0x0000d360, 0x0fffffe7},
     461        {0x0000d364, 0x17ffffe5},
     462        {0x0000d368, 0x1fffffe4},
     463        {0x0000d36c, 0x37ffffe3},
     464        {0x0000d370, 0x3fffffe3},
     465        {0x0000d374, 0x57ffffe3},
     466        {0x0000d378, 0x5fffffe2},
     467        {0x0000d37c, 0x7fffffe2},
     468        {0x0000d380, 0x7f3c7bba},
     469        {0x0000d384, 0xf3307ff0}
     470};
     471
    153472#endif
  • uspace/drv/bus/usb/ar9271/ath.h

    rab365c4 r56c0930  
    4848/** Atheros wifi device structure */
    4949typedef struct ath {
     50        /** Maximum length of data response message. */
     51        size_t data_response_length;
     52       
     53        /** Maximum length of control response message. */
     54        size_t ctrl_response_length;
     55       
    5056        /** Implementation specific data. */
    5157        void *specific_data;
  • uspace/drv/bus/usb/ar9271/ath_usb.c

    rab365c4 r56c0930  
    8282        ath_usb->input_ctrl_pipe_number = 2;
    8383        ath_usb->output_ctrl_pipe_number = 3;
     84       
     85        ath->ctrl_response_length = 64;
     86        ath->data_response_length = 512;
    8487       
    8588        ath->specific_data = ath_usb;
  • uspace/drv/bus/usb/ar9271/htc.c

    rab365c4 r56c0930  
    3939#include "wmi.h"
    4040#include "htc.h"
     41#include "nic/nic.h"
     42#include "ar9271.h"
    4143
    4244/**
     
    6466}
    6567
    66 /**
    67  * Send HTC message to USB device.
     68int htc_init_new_vif(htc_device_t *htc_device)
     69{
     70        htc_vif_msg_t vif_msg;
     71        htc_sta_msg_t sta_msg;
     72       
     73        nic_address_t addr;
     74        nic_t *nic = nic_get_from_ddf_dev(htc_device->ieee80211_dev->ddf_dev);
     75        nic_query_address(nic, &addr);
     76       
     77        memcpy(&vif_msg.addr, &addr.address, ETH_ADDR);
     78        memcpy(&sta_msg.addr, &addr.address, ETH_ADDR);
     79       
     80        ieee80211_operating_mode_t op_mode =
     81                htc_device->ieee80211_dev->current_op_mode;
     82       
     83        switch(op_mode) {
     84                case IEEE80211_OPMODE_ADHOC:
     85                        vif_msg.op_mode = HTC_OPMODE_ADHOC;
     86                        break;
     87                case IEEE80211_OPMODE_AP:
     88                        vif_msg.op_mode = HTC_OPMODE_AP;
     89                        break;
     90                case IEEE80211_OPMODE_MESH:
     91                        vif_msg.op_mode = HTC_OPMODE_MESH;
     92                        break;
     93                case IEEE80211_OPMODE_STATION:
     94                        vif_msg.op_mode = HTC_OPMODE_STATION;
     95                        break;
     96        }
     97       
     98        vif_msg.index = 0;
     99        vif_msg.rts_thres = host2uint16_t_be(HTC_RTS_THRESHOLD);
     100       
     101        int rc = wmi_send_command(htc_device, WMI_VAP_CREATE,
     102                (uint8_t *) &vif_msg, sizeof(vif_msg), NULL);
     103        if(rc != EOK) {
     104                usb_log_error("Failed to send VAP create command.\n");
     105                return rc;
     106        }
     107       
     108        sta_msg.is_vif_sta = 1;
     109        sta_msg.max_ampdu = host2uint16_t_be(HTC_MAX_AMPDU);
     110        sta_msg.sta_index = 0;
     111        sta_msg.vif_index = 0;
     112       
     113        rc = wmi_send_command(htc_device, WMI_NODE_CREATE,
     114                (uint8_t *) &sta_msg, sizeof(sta_msg), NULL);
     115        if(rc != EOK) {
     116                usb_log_error("Failed to send NODE create command.\n");
     117                return rc;
     118        }
     119       
     120        /* Write first 4 bytes of MAC address. */
     121        uint32_t id0;
     122        memcpy(&id0, &addr.address, 4);
     123        id0 = host2uint32_t_le(id0);
     124        rc = wmi_reg_write(htc_device, AR9271_STATION_ID0, id0);
     125        if(rc != EOK)
     126                return rc;
     127       
     128        /* Write last 2 bytes of MAC address (and preserve existing data). */
     129        uint32_t id1;
     130        rc = wmi_reg_read(htc_device, AR9271_STATION_ID1, &id1);
     131        if(rc != EOK)
     132                return rc;
     133        uint16_t id1_addr;
     134        memcpy(&id1_addr, &addr.address[4], 2);
     135        id1 = (id1 & ~AR9271_STATION_ID1_MASK) | host2uint16_t_le(id1_addr);
     136        rc = wmi_reg_write(htc_device, AR9271_STATION_ID1, id1);
     137        if(rc != EOK)
     138                return rc;
     139       
     140        /* TODO: Set BSSID mask for AP mode. */
     141       
     142        return EOK;
     143}
     144
     145static void htc_config_frame_header(htc_frame_header_t *header,
     146        size_t buffer_size, uint8_t endpoint_id)
     147{
     148        header->endpoint_id = endpoint_id;
     149        header->flags = 0;
     150        header->payload_length =
     151                host2uint16_t_be(buffer_size - sizeof(htc_frame_header_t));
     152       
     153        header->control_bytes[0] = 0x02;
     154        header->control_bytes[1] = 0x88;
     155        header->control_bytes[2] = 0xFF;
     156        header->control_bytes[3] = 0xFF;
     157}
     158
     159/**
     160 * Send control HTC message to USB device.
    68161 *
    69162 * @param htc_device HTC device structure.
     
    75168 * @return EOK if succeed, negative error code otherwise.
    76169 */
    77 int htc_send_message(htc_device_t *htc_device, void *buffer,
     170int htc_send_control_message(htc_device_t *htc_device, void *buffer,
    78171        size_t buffer_size, uint8_t endpoint_id)
    79172{
    80         htc_frame_header_t *htc_header = (htc_frame_header_t *) buffer;
    81         htc_header->endpoint_id = endpoint_id;
    82         htc_header->flags = 0;
    83         htc_header->payload_length =
    84                 host2uint16_t_be(buffer_size - sizeof(htc_frame_header_t));
    85        
    86         htc_header->control_bytes[0] = 0x02;
    87         htc_header->control_bytes[1] = 0x88;
    88         htc_header->control_bytes[2] = 0xFF;
    89         htc_header->control_bytes[3] = 0xFF;
     173        htc_config_frame_header((htc_frame_header_t *) buffer, buffer_size,
     174                endpoint_id);
    90175       
    91176        ath_t *ath_device = htc_device->ath_device;
     
    96181
    97182/**
    98  * Read HTC message from USB device.
     183 * Send data HTC message to USB device.
     184 *
     185 * @param htc_device HTC device structure.
     186 * @param buffer Buffer with data to be sent to USB device (without HTC frame
     187 *              header).
     188 * @param buffer_size Size of buffer (including HTC frame header).
     189 * @param endpoint_id Destination endpoint.
     190 *
     191 * @return EOK if succeed, negative error code otherwise.
     192 */
     193int htc_send_data_message(htc_device_t *htc_device, void *buffer,
     194        size_t buffer_size, uint8_t endpoint_id)
     195{
     196        htc_config_frame_header((htc_frame_header_t *) buffer, buffer_size,
     197                endpoint_id);
     198       
     199        ath_t *ath_device = htc_device->ath_device;
     200       
     201        return ath_device->ops->send_data_message(ath_device, buffer,
     202                buffer_size);
     203}
     204
     205/**
     206 * Read HTC data message from USB device.
    99207 *
    100208 * @param htc_device HTC device structure.
     
    105213 * @return EOK if succeed, negative error code otherwise.
    106214 */
    107 int htc_read_message(htc_device_t *htc_device, void *buffer,
     215int htc_read_data_message(htc_device_t *htc_device, void *buffer,
     216        size_t buffer_size, size_t *transferred_size)
     217{
     218        ath_t *ath_device = htc_device->ath_device;
     219       
     220        return ath_device->ops->read_data_message(ath_device, buffer,
     221                buffer_size, transferred_size);
     222}
     223
     224/**
     225 * Read HTC control message from USB device.
     226 *
     227 * @param htc_device HTC device structure.
     228 * @param buffer Buffer where data from USB device will be stored.
     229 * @param buffer_size Size of buffer.
     230 * @param transferred_size Real size of read data.
     231 *
     232 * @return EOK if succeed, negative error code otherwise.
     233 */
     234int htc_read_control_message(htc_device_t *htc_device, void *buffer,
    108235        size_t buffer_size, size_t *transferred_size)
    109236{
     
    145272       
    146273        /* Send HTC message. */
    147         int rc = htc_send_message(htc_device, buffer, buffer_size,
     274        int rc = htc_send_control_message(htc_device, buffer, buffer_size,
    148275                htc_device->endpoints.ctrl_endpoint);
    149276        if(rc != EOK) {
     
    155282        free(buffer);
    156283       
    157         buffer_size = MAX_RESPONSE_LENGTH;
     284        buffer_size = htc_device->ath_device->ctrl_response_length;
    158285        buffer = malloc(buffer_size);
    159286       
    160287        /* Read response from device. */
    161         rc = htc_read_message(htc_device, buffer, buffer_size, NULL);
     288        rc = htc_read_control_message(htc_device, buffer, buffer_size, NULL);
    162289        if(rc != EOK) {
    163290                free(buffer);
     
    208335
    209336        /* Send HTC message. */
    210         int rc = htc_send_message(htc_device, buffer, buffer_size,
     337        int rc = htc_send_control_message(htc_device, buffer, buffer_size,
    211338                htc_device->endpoints.ctrl_endpoint);
    212339        if(rc != EOK) {
     
    219346        free(buffer);
    220347       
    221         buffer_size = MAX_RESPONSE_LENGTH;
     348        buffer_size = htc_device->ath_device->ctrl_response_length;
    222349        buffer = malloc(buffer_size);
    223350
    224351        /* Check response from device. */
    225         rc = htc_read_message(htc_device, buffer, buffer_size, NULL);
     352        rc = htc_read_control_message(htc_device, buffer, buffer_size, NULL);
    226353        if(rc != EOK) {
    227354                usb_log_error("Failed to receive HTC config response message. "
     
    254381
    255382        /* Send HTC message. */
    256         int rc = htc_send_message(htc_device, buffer, buffer_size,
     383        int rc = htc_send_control_message(htc_device, buffer, buffer_size,
    257384                htc_device->endpoints.ctrl_endpoint);
    258385        if(rc != EOK) {
     
    277404static int htc_check_ready(htc_device_t *htc_device)
    278405{
    279         size_t buffer_size = MAX_RESPONSE_LENGTH;
     406        size_t buffer_size = htc_device->ath_device->ctrl_response_length;
    280407        void *buffer = malloc(buffer_size);
    281408
    282409        /* Read response from device. */
    283         int rc = htc_read_message(htc_device, buffer, buffer_size, NULL);
     410        int rc = htc_read_control_message(htc_device, buffer, buffer_size,
     411                NULL);
    284412        if(rc != EOK) {
    285413                free(buffer);
     
    310438 * @return EOK if succeed, negative error code otherwise.
    311439 */
    312 int htc_device_init(ath_t *ath_device, htc_device_t *htc_device)
    313 {
    314         if(ath_device == NULL || htc_device == NULL) {
    315                 return EINVAL;
    316         }
    317        
     440int htc_device_init(ath_t *ath_device, ieee80211_dev_t *ieee80211_dev,
     441        htc_device_t *htc_device)
     442{
    318443        fibril_mutex_initialize(&htc_device->rx_lock);
    319444        fibril_mutex_initialize(&htc_device->tx_lock);
     
    322447       
    323448        htc_device->ath_device = ath_device;
     449        htc_device->ieee80211_dev = ieee80211_dev;
    324450       
    325451        return EOK;
  • uspace/drv/bus/usb/ar9271/htc.h

    rab365c4 r56c0930  
    3737#define ATHEROS_HTC_H
    3838
     39#include <ieee80211.h>
    3940#include <usb/dev/driver.h>
    4041#include <sys/types.h>
     42#include <nic.h>
    4143
    4244#include "ath.h"
    4345
    44 #define MAX_RESPONSE_LENGTH 64
     46#define HTC_RTS_THRESHOLD 2304
     47#define HTC_MAX_AMPDU 0xFFFF
    4548
    4649/**
     
    6568        HTC_SERVICE_NO_MORE_EP
    6669} htc_response_status_code_t;
     70
     71/**
     72 * HTC operating mode definition
     73 */
     74typedef enum {
     75        HTC_OPMODE_ADHOC = 0,
     76        HTC_OPMODE_STATION = 1,
     77        HTC_OPMODE_MESH = 2,
     78        HTC_OPMODE_AP = 6
     79} htc_operating_mode_t;
    6780
    6881/**
     
    98111        fibril_mutex_t tx_lock;
    99112       
     113        /** Pointer to related IEEE 802.11 device */
     114        ieee80211_dev_t *ieee80211_dev;
     115       
    100116        /** Pointer to Atheros WiFi device structure */
    101117        ath_t *ath_device;
     
    113129        /* Message payload starts after the header. */
    114130} __attribute__((packed)) htc_frame_header_t;
     131
     132/**
     133 * HTC management TX frame header structure
     134 */
     135typedef struct {
     136        uint8_t node_idx;
     137        uint8_t vif_idx;
     138        uint8_t tidno;
     139        uint8_t flags;
     140        uint8_t key_type;
     141        uint8_t keyix;
     142        uint8_t cookie;
     143        uint8_t pad;
     144} __attribute__((packed)) htc_tx_management_header_t;
    115145
    116146/**
     
    163193
    164194/**
     195 * HTC new virtual interface message
     196 */
     197typedef struct {
     198        uint8_t index;
     199        uint8_t op_mode;
     200        uint8_t addr[ETH_ADDR];
     201        uint8_t ath_cap;
     202        uint16_t rts_thres;             /**< Big Endian value! */
     203        uint8_t pad;
     204} __attribute__((packed)) htc_vif_msg_t;
     205
     206/**
     207 * HTC new station message
     208 */
     209typedef struct {
     210        uint8_t addr[ETH_ADDR];
     211        uint8_t bssid[ETH_ADDR];
     212        uint8_t sta_index;
     213        uint8_t vif_index;
     214        uint8_t is_vif_sta;
     215               
     216        uint16_t flags;         /**< Big Endian value! */
     217        uint16_t ht_cap;        /**< Big Endian value! */
     218        uint16_t max_ampdu;     /**< Big Endian value! */
     219       
     220        uint8_t pad;
     221} __attribute__((packed)) htc_sta_msg_t;
     222
     223/**
    165224 * HTC setup complete message structure
    166225 */
     
    169228} __attribute__((packed)) htc_setup_complete_msg_t;
    170229
    171 extern int htc_device_init(ath_t *ath_device, htc_device_t *htc_device);
     230extern int htc_device_init(ath_t *ath_device, ieee80211_dev_t *ieee80211_dev,
     231        htc_device_t *htc_device);
    172232extern int htc_init(htc_device_t *htc_device);
    173 extern int htc_read_message(htc_device_t *htc_device, void *buffer,
     233extern int htc_init_new_vif(htc_device_t *htc_device);
     234extern int htc_read_control_message(htc_device_t *htc_device, void *buffer,
    174235        size_t buffer_size, size_t *transferred_size);
    175 extern int htc_send_message(htc_device_t *htc_device, void *buffer,
     236extern int htc_read_data_message(htc_device_t *htc_device, void *buffer,
     237        size_t buffer_size, size_t *transferred_size);
     238extern int htc_send_control_message(htc_device_t *htc_device, void *buffer,
    176239        size_t buffer_size, uint8_t endpoint_id);
     240extern int htc_send_data_message(htc_device_t *htc_device, void *buffer,
     241        size_t buffer_size, uint8_t endpoint_id);
    177242
    178243#endif  /* ATHEROS_HTC_H */
  • uspace/drv/bus/usb/ar9271/hw.c

    rab365c4 r56c0930  
    245245        gpio_shift = 2 * gpio;
    246246       
    247         rc = wmi_reg_clear_set_bit(ar9271->htc_device, AR9271_GPIO_OE_OUT,
     247        rc = wmi_reg_set_clear_bit(ar9271->htc_device, AR9271_GPIO_OE_OUT,
    248248                AR9271_GPIO_OE_OUT_ALWAYS << gpio_shift,
    249249                AR9271_GPIO_OE_OUT_ALWAYS << gpio_shift);
     
    258258static int hw_gpio_set_value(ar9271_t *ar9271, uint32_t gpio, uint32_t value)
    259259{
    260         int rc = wmi_reg_clear_set_bit(ar9271->htc_device, AR9271_GPIO_IN_OUT,
     260        int rc = wmi_reg_set_clear_bit(ar9271->htc_device, AR9271_GPIO_IN_OUT,
    261261                (~value & 1) << gpio, 1 << gpio);
    262262        if(rc != EOK) {
     
    317317
    318318static int hw_set_operating_mode(ar9271_t *ar9271,
    319         ieee80211_operating_mode_t opmode)
     319        ieee80211_operating_mode_t op_mode)
    320320{
    321321        uint32_t set_bit = 0x10000000;
    322322       
    323323        /* NOTICE: Fall-through switch statement! */
    324         switch(opmode) {
     324        switch(op_mode) {
    325325                case IEEE80211_OPMODE_ADHOC:
    326326                        set_bit |= AR9271_OPMODE_ADHOC_MASK;
     
    333333        }
    334334       
    335         wmi_reg_clear_set_bit(ar9271->htc_device, AR9271_STATION_ID1,
     335        wmi_reg_set_clear_bit(ar9271->htc_device, AR9271_STATION_ID1,
    336336                set_bit,
    337337                AR9271_OPMODE_STATION_AP_MASK | AR9271_OPMODE_ADHOC_MASK);
     338       
     339        ar9271->ieee80211_dev->current_op_mode = op_mode;
    338340       
    339341        return EOK;
     
    352354}
    353355
    354 static int hw_set_channel(ar9271_t *ar9271, uint16_t freq)
     356static int hw_set_freq(ar9271_t *ar9271, uint16_t freq)
    355357{
    356358        /* Not supported channel frequency. */
    357         if(freq < IEEE80211_FIRST_CHANNEL || freq > IEEE80211_MAX_CHANNEL) {
     359        if(freq < IEEE80211_FIRST_FREQ || freq > IEEE80211_MAX_FREQ) {
    358360                return EINVAL;
    359361        }
    360362       
    361363        /* Not supported channel frequency. */
    362         if((freq - IEEE80211_FIRST_CHANNEL) % IEEE80211_CHANNEL_GAP != 0) {
     364        if((freq - IEEE80211_FIRST_FREQ) % IEEE80211_CHANNEL_GAP != 0) {
    363365                return EINVAL;
    364366        }
    365367       
    366         uint32_t result;
    367         wmi_reg_read(ar9271->htc_device, AR9271_PHY_CCK_TX_CTRL, &result);
     368        uint32_t tx_control;
     369        wmi_reg_read(ar9271->htc_device, AR9271_PHY_CCK_TX_CTRL, &tx_control);
    368370        wmi_reg_write(ar9271->htc_device, AR9271_PHY_CCK_TX_CTRL,
    369                 result & ~AR9271_PHY_CCK_TX_CTRL_JAPAN);
     371                tx_control & ~AR9271_PHY_CCK_TX_CTRL_JAPAN);
    370372       
    371373        /* Some magic here. */
     
    377379                to_write);
    378380       
     381        ar9271->ieee80211_dev->current_freq = freq;
     382       
     383        return EOK;
     384}
     385
     386static int hw_set_rx_filter(ar9271_t *ar9271)
     387{
     388        uint32_t filter_bits;
     389        int rc = wmi_reg_read(ar9271->htc_device, AR9271_RX_FILTER,
     390                &filter_bits);
     391        if(rc != EOK) {
     392                usb_log_error("Failed to read RX filter.\n");
     393                return EINVAL;
     394        }
     395       
     396        /* TODO: Do proper filtering here. */
     397       
     398        filter_bits |= AR9271_RX_FILTER_UNI | AR9271_RX_FILTER_MULTI |
     399                AR9271_RX_FILTER_BROAD | AR9271_RX_FILTER_BEACON |
     400                AR9271_RX_FILTER_MYBEACON | AR9271_RX_FILTER_PROMISCUOUS;
     401       
     402        rc = wmi_reg_write(ar9271->htc_device, AR9271_RX_FILTER, filter_bits);
     403        if(rc != EOK) {
     404                usb_log_error("Failed to write RX filter.\n");
     405                return EINVAL;
     406        }
     407       
     408        return EOK;
     409}
     410
     411int hw_rx_init(ar9271_t *ar9271)
     412{
     413        int rc = wmi_reg_write(ar9271->htc_device, AR9271_COMMAND,
     414                AR9271_COMMAND_RX_ENABLE);
     415        if(rc != EOK) {
     416                usb_log_error("Failed to send RX enable command.\n");
     417                return EINVAL;
     418        }
     419       
     420        rc = hw_set_rx_filter(ar9271);
     421        if(rc != EOK) {
     422                usb_log_error("Failed to set RX filtering.\n");
     423                return EINVAL;
     424        }
     425       
     426        return EOK;
     427}
     428
     429static int hw_activate_phy(ar9271_t *ar9271)
     430{
     431        int rc = wmi_reg_write(ar9271->htc_device, AR9271_PHY_ACTIVE, 1);
     432        if(rc != EOK) {
     433                usb_log_error("Failed to activate set PHY active.\n");
     434                return rc;
     435        }
     436       
     437        udelay(1000);
     438       
     439        return EOK;
     440}
     441
     442static int hw_init_pll(ar9271_t *ar9271)
     443{
     444        uint32_t pll;
     445       
     446        /* Some magic here. */
     447        pll = (0x5 << 10) & 0x00003C00;
     448        pll |= (0x2 << 14) & 0x0000C000; /**< 0x2 ~ quarter rate (0x1 half) */
     449        pll |= 0x58 & 0x000003FF;
     450       
     451        return wmi_reg_write(ar9271->htc_device, AR9271_RTC_PLL_CONTROL, pll);
     452}
     453
     454static int hw_calibrate(ar9271_t *ar9271)
     455{
     456        wmi_reg_set_bit(ar9271->htc_device, AR9271_CARRIER_LEAK_CONTROL,
     457                AR9271_CARRIER_LEAK_CALIB);
     458        wmi_reg_clear_bit(ar9271->htc_device, AR9271_ADC_CONTROL,
     459                AR9271_ADC_CONTROL_OFF_PWDADC);
     460        wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
     461                AR9271_AGC_CONTROL_TX_CALIB);
     462        wmi_reg_set_bit(ar9271->htc_device, AR9271_PHY_TPCRG1,
     463                AR9271_PHY_TPCRG1_PD_CALIB);
     464        wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
     465                AR9271_AGC_CONTROL_CALIB);
     466       
     467        int rc = hw_read_wait(ar9271, AR9271_AGC_CONTROL,
     468                AR9271_AGC_CONTROL_CALIB, 0);
     469        if(rc != EOK) {
     470                usb_log_error("Failed to wait on calibrate completion.\n");
     471                return rc;
     472        }
     473       
     474        wmi_reg_set_bit(ar9271->htc_device, AR9271_ADC_CONTROL,
     475                AR9271_ADC_CONTROL_OFF_PWDADC);
     476        wmi_reg_clear_bit(ar9271->htc_device, AR9271_CARRIER_LEAK_CONTROL,
     477                AR9271_CARRIER_LEAK_CALIB);
     478        wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
     479                AR9271_AGC_CONTROL_TX_CALIB);
     480       
     481        return EOK;
     482}
     483
     484static int hw_set_init_values(ar9271_t *ar9271)
     485{
     486        int size = sizeof(ar9271_init_array) / sizeof(ar9271_init_array[0]);
     487       
     488        for(int i = 0; i < size; i++) {
     489                uint32_t reg_offset = ar9271_init_array[i][0];
     490                uint32_t reg_value = ar9271_init_array[i][1];
     491                wmi_reg_write(ar9271->htc_device, reg_offset, reg_value);
     492        }
     493       
    379494        return EOK;
    380495}
     
    382497int hw_reset(ar9271_t *ar9271)
    383498{
    384         int rc = wmi_reg_write(ar9271->htc_device,
     499        /* Set physical layer as deactivated. */
     500        int rc = wmi_reg_write(ar9271->htc_device, AR9271_PHY_ACTIVE, 0);
     501        if(rc != EOK) {
     502                usb_log_error("Failed to set PHY deactivated.\n");
     503                return rc;
     504        }
     505       
     506        rc = wmi_reg_write(ar9271->htc_device,
    385507                AR9271_RESET_POWER_DOWN_CONTROL,
    386508                AR9271_RADIO_RF_RESET);
     
    391513       
    392514        udelay(50);
     515       
     516        /* TODO: There should be cold reset only if RX or TX is enabled. */
     517       
     518        rc = hw_init_pll(ar9271);
     519        if(rc != EOK) {
     520                usb_log_error("Failed to init PLL.\n");
     521                return rc;
     522        }
     523       
     524        udelay(500);
     525       
     526        rc = wmi_reg_write(ar9271->htc_device,
     527                AR9271_CLOCK_CONTROL,
     528                AR9271_MAX_CPU_CLOCK);
     529        if(rc != EOK) {
     530                usb_log_error("Failed to set CPU clock.\n");
     531                return rc;
     532        }
     533       
     534        udelay(100);
    393535       
    394536        rc = wmi_reg_write(ar9271->htc_device,
     
    403545        udelay(50);
    404546       
    405         /* Perform cold reset of device. */
    406         rc = hw_set_reset(ar9271, true);
    407         if(rc != EOK) {
    408                 usb_log_error("Failed to HW cold reset.\n");
    409                 return rc;
    410         }
     547        rc = hw_set_init_values(ar9271);
     548        if(rc != EOK) {
     549                usb_log_error("Failed to set device init values.\n");
     550                return rc;
     551        }
     552       
     553        /* TODO: There should probably be TX power settings. */
    411554       
    412555        /* Set physical layer mode. */
     
    418561        }
    419562       
     563        /* TODO: Init EEPROM here. */
     564       
    420565        /* Set device operating mode. */
    421566        rc = hw_set_operating_mode(ar9271, IEEE80211_OPMODE_STATION);
     
    425570        }
    426571       
    427         /* Set channel. */
    428         rc = hw_set_channel(ar9271, IEEE80211_FIRST_CHANNEL);
     572        /* Set channel frequency. */
     573        rc = hw_set_freq(ar9271, IEEE80211_FIRST_FREQ);
    429574        if(rc != EOK) {
    430575                usb_log_error("Failed to set channel.\n");
     
    444589        }
    445590       
     591        /* TODO: Maybe resetting TX queues will be necessary afterwards here. */
     592       
     593        /* TODO: Setting RX, TX timeouts and others may be necessary here. */
     594       
    446595        /* Activate physical layer. */
    447         rc = wmi_reg_write(ar9271->htc_device, AR9271_PHY_ACTIVE, 1);
     596        rc = hw_activate_phy(ar9271);
    448597        if(rc != EOK) {
    449598                usb_log_error("Failed to activate physical layer.\n");
    450599                return rc;
    451600        }
     601       
     602        /* Calibration. */
     603        rc = hw_calibrate(ar9271);
     604        if(rc != EOK) {
     605                usb_log_error("Failed to calibrate device.\n");
     606                return rc;
     607        }
     608       
     609        usb_log_info("HW reset done.\n");
    452610       
    453611        return EOK;
  • uspace/drv/bus/usb/ar9271/hw.h

    rab365c4 r56c0930  
    3838#include "ar9271.h"
    3939
    40 #define HW_WAIT_LOOPS 100
     40#define HW_WAIT_LOOPS 1000
    4141#define HW_WAIT_TIME_US 10
    4242
    4343extern int hw_init(ar9271_t *ar9271);
     44extern int hw_rx_init(ar9271_t *ar9271);
    4445extern int hw_reset(ar9271_t *ar9271);
    4546
  • uspace/drv/bus/usb/ar9271/wmi.c

    rab365c4 r56c0930  
    5454        uint32_t cmd_value = host2uint32_t_be(reg_offset);
    5555       
    56         size_t buffer_size = MAX_RESPONSE_LENGTH;
    57         void *resp_buffer = malloc(buffer_size);
     56        void *resp_buffer =
     57                malloc(htc_device->ath_device->ctrl_response_length);
    5858       
    5959        int rc = wmi_send_command(htc_device, WMI_REG_READ,
     
    9090        };
    9191       
    92         void *resp_buffer = malloc(MAX_RESPONSE_LENGTH);
     92        void *resp_buffer =
     93                malloc(htc_device->ath_device->ctrl_response_length);
    9394       
    9495        int rc = wmi_send_command(htc_device, WMI_REG_WRITE,
     
    115116 * @return EOK if succeed, negative error code otherwise.
    116117 */
    117 int wmi_reg_clear_set_bit(htc_device_t *htc_device, uint32_t reg_offset,
     118int wmi_reg_set_clear_bit(htc_device_t *htc_device, uint32_t reg_offset,
    118119        uint32_t set_bit, uint32_t clear_bit)
    119120{
     
    152153        uint32_t set_bit)
    153154{
    154         return wmi_reg_clear_set_bit(htc_device, reg_offset, set_bit, 0);
     155        return wmi_reg_set_clear_bit(htc_device, reg_offset, set_bit, 0);
    155156}
    156157
     
    167168        uint32_t clear_bit)
    168169{
    169         return wmi_reg_clear_set_bit(htc_device, reg_offset, 0, clear_bit);
     170        return wmi_reg_set_clear_bit(htc_device, reg_offset, 0, clear_bit);
    170171}
    171172
     
    184185        size_t buffer_size = sizeof(wmi_reg_t) * elements;
    185186        void *buffer = malloc(buffer_size);
    186         void *resp_buffer = malloc(MAX_RESPONSE_LENGTH);
     187        void *resp_buffer =
     188                malloc(htc_device->ath_device->ctrl_response_length);
    187189       
    188190        /* Convert values to correct endianness. */
     
    240242       
    241243        /* Send message. */
    242         int rc = htc_send_message(htc_device, buffer, buffer_size,
     244        int rc = htc_send_control_message(htc_device, buffer, buffer_size,
    243245                htc_device->endpoints.wmi_endpoint);
    244246        if(rc != EOK) {
     
    251253       
    252254        bool clean_resp_buffer = false;
     255        size_t response_buffer_size =
     256                htc_device->ath_device->ctrl_response_length;
    253257        if(response_buffer == NULL) {
    254                 response_buffer = malloc(MAX_RESPONSE_LENGTH);
     258                response_buffer = malloc(response_buffer_size);
    255259                clean_resp_buffer = true;
    256260        }
    257261       
    258262        /* Read response. */
    259         rc = htc_read_message(htc_device, response_buffer, MAX_RESPONSE_LENGTH,
    260                 NULL);
     263        rc = htc_read_control_message(htc_device, response_buffer,
     264                response_buffer_size, NULL);
    261265        if(rc != EOK) {
    262266                free(buffer);
  • uspace/drv/bus/usb/ar9271/wmi.h

    rab365c4 r56c0930  
    4949    uint16_t command_id;                /**< Big Endian value! */
    5050    uint16_t sequence_number;           /**< Big Endian value! */
    51 } __attribute__((packed)) wmi_command_header_t; 
     51} __attribute__((packed)) wmi_command_header_t;
    5252
    5353/**
     
    117117extern int wmi_reg_write(htc_device_t *htc_device, uint32_t reg_offset,
    118118        uint32_t val);
    119 extern int wmi_reg_clear_set_bit(htc_device_t *htc_device, uint32_t reg_offset,
     119extern int wmi_reg_set_clear_bit(htc_device_t *htc_device, uint32_t reg_offset,
    120120        uint32_t set_bit, uint32_t clear_bit);
    121121extern int wmi_reg_set_bit(htc_device_t *htc_device, uint32_t reg_offset,
  • uspace/lib/net/ieee80211/ieee80211.c

    rab365c4 r56c0930  
    3737
    3838#include <errno.h>
    39 #include <nic.h>
     39#include <byteorder.h>
    4040
    4141#include <ieee80211_impl.h>
     
    4848static driver_ops_t ieee80211_nic_driver_ops;
    4949
     50bool ieee80211_is_data_frame(ieee80211_header_t *header)
     51{
     52        return (header->frame_ctrl &
     53                host2uint16_t_le(IEEE80211_FRAME_CTRL_FRAME_TYPE)) ==
     54                host2uint16_t_le(IEEE80211_FRAME_CTRL_DATA_FRAME);
     55}
     56
    5057static int ieee80211_open(ddf_fun_t *fun)
    5158{
     
    5360        ieee80211_dev_t *ieee80211_dev = nic_get_specific(nic_data);
    5461       
     62        if(ieee80211_dev->started) {
     63                return EOK;
     64        } else {
     65                ieee80211_dev->started = true;
     66        }
     67       
    5568        int rc = ieee80211_dev->ops->start(ieee80211_dev);
    5669        if(rc != EOK)
    5770                return rc;
     71       
     72        /*
     73        rc = ieee80211_dev->ops->scan(ieee80211_dev);
     74        if(rc != EOK)
     75                return rc;
     76         */
    5877       
    5978        return EOK;
     
    7089        /* IEEE802.11 start operation must be implemented. */
    7190        if(!ieee80211_ops->start)
     91                return EINVAL;
     92       
     93        /* IEEE802.11 TX handler must be implemented. */
     94        if(!ieee80211_ops->tx_handler)
    7295                return EINVAL;
    7396       
     
    93116        ieee80211_dev->ddf_dev = ddf_dev;
    94117        ieee80211_dev->driver_data = driver_data;
     118        ieee80211_dev->started = false;
     119        ieee80211_dev->current_op_mode = IEEE80211_OPMODE_STATION;
    95120       
    96121        /* Bind NIC to device */
  • uspace/lib/net/ieee80211/ieee80211_impl.c

    rab365c4 r56c0930  
    4040#include <ieee80211_impl.h>
    4141
     42static int ieee80211_freq_to_channel(uint16_t freq)
     43{
     44        return (freq - IEEE80211_FIRST_FREQ) / IEEE80211_CHANNEL_GAP + 1;
     45}
     46
     47static int ieee80211_probe_request(ieee80211_dev_t *ieee80211_dev)
     48{
     49        size_t buffer_size = sizeof(ieee80211_header_t);
     50        void *buffer = malloc(buffer_size);
     51       
     52        /* TODO */
     53       
     54        ieee80211_freq_to_channel(ieee80211_dev->current_freq);
     55       
     56        ieee80211_dev->ops->tx_handler(ieee80211_dev, buffer, buffer_size);
     57       
     58        free(buffer);
     59       
     60        return EOK;
     61}
     62
    4263/**
    4364 * Default implementation of IEEE802.11 scan function.
     
    4970int ieee80211_scan_impl(ieee80211_dev_t *ieee80211_dev)
    5071{
    51         /** TODO */
     72        /* TODO */
     73        int rc = ieee80211_probe_request(ieee80211_dev);
     74        if(rc != EOK)
     75                return rc;
    5276       
    5377        return EOK;
  • uspace/lib/net/include/ieee80211.h

    rab365c4 r56c0930  
    4141#include <ddf/driver.h>
    4242#include <sys/types.h>
     43#include <nic.h>
    4344
    4445/** Initial channel frequency. */
    45 #define IEEE80211_FIRST_CHANNEL 2412
     46#define IEEE80211_FIRST_FREQ 2412
    4647
    4748/** Max supported channel frequency. */
    48 #define IEEE80211_MAX_CHANNEL 2472
     49#define IEEE80211_MAX_FREQ 2472
    4950
    5051/* Gap between IEEE80211 channels in MHz. */
    5152#define IEEE80211_CHANNEL_GAP 5
     53
     54#define IEEE80211_FRAME_CTRL_FRAME_TYPE 0x000C
     55#define IEEE80211_FRAME_CTRL_DATA_FRAME 0x0008
    5256
    5357struct ieee80211_dev;
     
    6569        int (*start)(struct ieee80211_dev *);
    6670        int (*scan)(struct ieee80211_dev *);
     71        int (*tx_handler)(struct ieee80211_dev *, void *, size_t);
    6772} ieee80211_ops_t;
    6873
     
    7782        /** Pointer to driver specific data. */
    7883        void *driver_data;
     84       
     85        /** Current operating frequency. */
     86        uint16_t current_freq;
     87       
     88        /** Current operating mode. */
     89        ieee80211_operating_mode_t current_op_mode;
     90       
     91        /* TODO: Probably to be removed later - nic.open function is now
     92         * executed multiple times, have to find out reason and fix it.
     93         */
     94        /** Indicates whether driver has already started. */
     95        bool started;
    7996} ieee80211_dev_t;
    8097
     98/** IEEE 802.11 header structure. */
     99typedef struct {
     100        uint16_t frame_ctrl;            /**< Little Endian value! */
     101        uint16_t duration_id;           /**< Little Endian value! */
     102        uint8_t address1[ETH_ADDR];
     103        uint8_t address2[ETH_ADDR];
     104        uint8_t address3[ETH_ADDR];
     105        uint16_t seq_ctrl;              /**< Little Endian value! */
     106        uint8_t address4[ETH_ADDR];
     107} __attribute__((packed)) __attribute__ ((aligned(2))) ieee80211_header_t;
     108
     109extern bool ieee80211_is_data_frame(ieee80211_header_t *header);
    81110extern int ieee80211_device_init(ieee80211_dev_t *ieee80211_dev,
    82111        void *driver_data, ddf_dev_t *ddf_dev);
Note: See TracChangeset for help on using the changeset viewer.