Changeset 56c0930 in mainline
- Timestamp:
- 2015-02-20T14:33:29Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4cb0148
- Parents:
- ab365c4
- Location:
- uspace
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ar9271/ar9271.c
rab365c4 r56c0930 101 101 /* IEEE802.11 callbacks */ 102 102 static int ar9271_ieee80211_start(ieee80211_dev_t *ieee80211_dev); 103 static int ar9271_ieee80211_tx_handler(ieee80211_dev_t *ieee80211_dev, 104 void *buffer, size_t buffer_size); 103 105 104 106 static driver_ops_t ar9271_driver_ops = { … … 112 114 113 115 static 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 120 static 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 157 static 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 175 static 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 191 static 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); 155 206 156 207 return EOK; … … 165 216 if(rc != EOK) { 166 217 usb_log_error("Failed to flush receiving buffer.\n"); 167 return EINVAL;218 return rc; 168 219 } 169 220 … … 171 222 if(rc != EOK) { 172 223 usb_log_error("Failed to do HW reset.\n"); 173 return EINVAL;224 return rc; 174 225 } 175 226 … … 179 230 if(rc != EOK) { 180 231 usb_log_error("Failed to set HTC mode.\n"); 181 return EINVAL;232 return rc; 182 233 } 183 234 … … 186 237 if(rc != EOK) { 187 238 usb_log_error("Failed to send ath init command.\n"); 188 return EINVAL;239 return rc; 189 240 } 190 241 … … 193 244 if(rc != EOK) { 194 245 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); 199 250 if(rc != EOK) { 200 251 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; 202 265 } 203 266 … … 220 283 free(ar9271->ath_device); 221 284 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; 223 305 } 224 306 … … 226 308 ar9271->htc_device = calloc(1, sizeof(htc_device_t)); 227 309 if(!ar9271->htc_device) { 310 free(ar9271->ieee80211_dev); 228 311 free(ar9271->ath_device); 229 312 usb_log_error("Failed to allocate memory for HTC device " … … 232 315 } 233 316 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); 235 319 if(rc != EOK) { 236 320 free(ar9271->htc_device); 321 free(ar9271->ieee80211_dev); 237 322 free(ar9271->ath_device); 238 323 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; 261 325 } 262 326 -
uspace/drv/bus/usb/ar9271/ar9271.h
rab365c4 r56c0930 40 40 #include "htc.h" 41 41 42 /** Max supported channel frequency. */ 43 #define AR9271_MAX_CHANNEL 2472 44 45 /** Number of transmisson queues */ 42 /** Number of transmission queues */ 46 43 #define AR9271_QUEUES_COUNT 10 47 44 … … 83 80 AR9271_RTC_RC_MAC_COLD = 0x00000002, 84 81 AR9271_RTC_RC_MASK = 0x00000003, 82 AR9271_RTC_PLL_CONTROL = 0x7014, 85 83 AR9271_RTC_RESET = 0x7040, 86 84 AR9271_RTC_STATUS = 0x7044, … … 92 90 AR9271_RTC_FORCE_WAKE_ON_INT = 0x00000002, 93 91 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 */ 94 102 AR9271_RX_FILTER = 0x803C, 95 103 AR9271_RX_FILTER_UNI = 0x00000001, … … 100 108 AR9271_RX_FILTER_PROMISCUOUS = 0x00000020, 101 109 AR9271_RX_FILTER_PROBEREQ = 0x00000080, 102 110 AR9271_RX_FILTER_MYBEACON = 0x00000200, 111 112 /* Physical layer registers */ 103 113 AR9271_PHY_BASE = 0x9800, 104 AR9271_PHY_ACTIVE = 0x981C, 114 AR9271_PHY_ACTIVE = 0x981C, 115 AR9271_ADC_CONTROL = 0x982C, 116 AR9271_AGC_CONTROL = 0x9860, 105 117 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, 106 124 AR9271_PHY_MODE_2G = 0x02, 107 125 AR9271_PHY_MODE_DYNAMIC = 0x04, 108 AR9271_PHY_CCK_TX_CTRL = 0xA204,109 126 AR9271_PHY_CCK_TX_CTRL_JAPAN = 0x00000010, 127 AR9271_PHY_TPCRG1_PD_CALIB = 0x00400000, 128 AR9271_CARRIER_LEAK_CALIB = 0x00000002, 110 129 111 130 AR9271_OPMODE_STATION_AP_MASK = 0x00010000, 112 131 AR9271_OPMODE_ADHOC_MASK = 0x00020000, 132 133 AR9271_CLOCK_CONTROL = 0x50040, 134 AR9271_MAX_CPU_CLOCK = 0x304, 113 135 114 136 AR9271_RESET_POWER_DOWN_CONTROL = 0x50044, … … 117 139 118 140 /* 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, 127 143 } ar9271_registers_t; 128 144 … … 151 167 } ar9271_t; 152 168 169 /** 170 * AR9271 hardware init values. 171 * 172 * Taken from Linux sources, some values omitted. 173 */ 174 static 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 153 472 #endif -
uspace/drv/bus/usb/ar9271/ath.h
rab365c4 r56c0930 48 48 /** Atheros wifi device structure */ 49 49 typedef 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 50 56 /** Implementation specific data. */ 51 57 void *specific_data; -
uspace/drv/bus/usb/ar9271/ath_usb.c
rab365c4 r56c0930 82 82 ath_usb->input_ctrl_pipe_number = 2; 83 83 ath_usb->output_ctrl_pipe_number = 3; 84 85 ath->ctrl_response_length = 64; 86 ath->data_response_length = 512; 84 87 85 88 ath->specific_data = ath_usb; -
uspace/drv/bus/usb/ar9271/htc.c
rab365c4 r56c0930 39 39 #include "wmi.h" 40 40 #include "htc.h" 41 #include "nic/nic.h" 42 #include "ar9271.h" 41 43 42 44 /** … … 64 66 } 65 67 66 /** 67 * Send HTC message to USB device. 68 int 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 145 static 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. 68 161 * 69 162 * @param htc_device HTC device structure. … … 75 168 * @return EOK if succeed, negative error code otherwise. 76 169 */ 77 int htc_send_ message(htc_device_t *htc_device, void *buffer,170 int htc_send_control_message(htc_device_t *htc_device, void *buffer, 78 171 size_t buffer_size, uint8_t endpoint_id) 79 172 { 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); 90 175 91 176 ath_t *ath_device = htc_device->ath_device; … … 96 181 97 182 /** 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 */ 193 int 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. 99 207 * 100 208 * @param htc_device HTC device structure. … … 105 213 * @return EOK if succeed, negative error code otherwise. 106 214 */ 107 int htc_read_message(htc_device_t *htc_device, void *buffer, 215 int 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 */ 234 int htc_read_control_message(htc_device_t *htc_device, void *buffer, 108 235 size_t buffer_size, size_t *transferred_size) 109 236 { … … 145 272 146 273 /* 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, 148 275 htc_device->endpoints.ctrl_endpoint); 149 276 if(rc != EOK) { … … 155 282 free(buffer); 156 283 157 buffer_size = MAX_RESPONSE_LENGTH;284 buffer_size = htc_device->ath_device->ctrl_response_length; 158 285 buffer = malloc(buffer_size); 159 286 160 287 /* 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); 162 289 if(rc != EOK) { 163 290 free(buffer); … … 208 335 209 336 /* 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, 211 338 htc_device->endpoints.ctrl_endpoint); 212 339 if(rc != EOK) { … … 219 346 free(buffer); 220 347 221 buffer_size = MAX_RESPONSE_LENGTH;348 buffer_size = htc_device->ath_device->ctrl_response_length; 222 349 buffer = malloc(buffer_size); 223 350 224 351 /* 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); 226 353 if(rc != EOK) { 227 354 usb_log_error("Failed to receive HTC config response message. " … … 254 381 255 382 /* 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, 257 384 htc_device->endpoints.ctrl_endpoint); 258 385 if(rc != EOK) { … … 277 404 static int htc_check_ready(htc_device_t *htc_device) 278 405 { 279 size_t buffer_size = MAX_RESPONSE_LENGTH;406 size_t buffer_size = htc_device->ath_device->ctrl_response_length; 280 407 void *buffer = malloc(buffer_size); 281 408 282 409 /* 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); 284 412 if(rc != EOK) { 285 413 free(buffer); … … 310 438 * @return EOK if succeed, negative error code otherwise. 311 439 */ 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 440 int htc_device_init(ath_t *ath_device, ieee80211_dev_t *ieee80211_dev, 441 htc_device_t *htc_device) 442 { 318 443 fibril_mutex_initialize(&htc_device->rx_lock); 319 444 fibril_mutex_initialize(&htc_device->tx_lock); … … 322 447 323 448 htc_device->ath_device = ath_device; 449 htc_device->ieee80211_dev = ieee80211_dev; 324 450 325 451 return EOK; -
uspace/drv/bus/usb/ar9271/htc.h
rab365c4 r56c0930 37 37 #define ATHEROS_HTC_H 38 38 39 #include <ieee80211.h> 39 40 #include <usb/dev/driver.h> 40 41 #include <sys/types.h> 42 #include <nic.h> 41 43 42 44 #include "ath.h" 43 45 44 #define MAX_RESPONSE_LENGTH 64 46 #define HTC_RTS_THRESHOLD 2304 47 #define HTC_MAX_AMPDU 0xFFFF 45 48 46 49 /** … … 65 68 HTC_SERVICE_NO_MORE_EP 66 69 } htc_response_status_code_t; 70 71 /** 72 * HTC operating mode definition 73 */ 74 typedef 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; 67 80 68 81 /** … … 98 111 fibril_mutex_t tx_lock; 99 112 113 /** Pointer to related IEEE 802.11 device */ 114 ieee80211_dev_t *ieee80211_dev; 115 100 116 /** Pointer to Atheros WiFi device structure */ 101 117 ath_t *ath_device; … … 113 129 /* Message payload starts after the header. */ 114 130 } __attribute__((packed)) htc_frame_header_t; 131 132 /** 133 * HTC management TX frame header structure 134 */ 135 typedef 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; 115 145 116 146 /** … … 163 193 164 194 /** 195 * HTC new virtual interface message 196 */ 197 typedef 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 */ 209 typedef 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 /** 165 224 * HTC setup complete message structure 166 225 */ … … 169 228 } __attribute__((packed)) htc_setup_complete_msg_t; 170 229 171 extern int htc_device_init(ath_t *ath_device, htc_device_t *htc_device); 230 extern int htc_device_init(ath_t *ath_device, ieee80211_dev_t *ieee80211_dev, 231 htc_device_t *htc_device); 172 232 extern int htc_init(htc_device_t *htc_device); 173 extern int htc_read_message(htc_device_t *htc_device, void *buffer, 233 extern int htc_init_new_vif(htc_device_t *htc_device); 234 extern int htc_read_control_message(htc_device_t *htc_device, void *buffer, 174 235 size_t buffer_size, size_t *transferred_size); 175 extern int htc_send_message(htc_device_t *htc_device, void *buffer, 236 extern int htc_read_data_message(htc_device_t *htc_device, void *buffer, 237 size_t buffer_size, size_t *transferred_size); 238 extern int htc_send_control_message(htc_device_t *htc_device, void *buffer, 176 239 size_t buffer_size, uint8_t endpoint_id); 240 extern int htc_send_data_message(htc_device_t *htc_device, void *buffer, 241 size_t buffer_size, uint8_t endpoint_id); 177 242 178 243 #endif /* ATHEROS_HTC_H */ -
uspace/drv/bus/usb/ar9271/hw.c
rab365c4 r56c0930 245 245 gpio_shift = 2 * gpio; 246 246 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, 248 248 AR9271_GPIO_OE_OUT_ALWAYS << gpio_shift, 249 249 AR9271_GPIO_OE_OUT_ALWAYS << gpio_shift); … … 258 258 static int hw_gpio_set_value(ar9271_t *ar9271, uint32_t gpio, uint32_t value) 259 259 { 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, 261 261 (~value & 1) << gpio, 1 << gpio); 262 262 if(rc != EOK) { … … 317 317 318 318 static int hw_set_operating_mode(ar9271_t *ar9271, 319 ieee80211_operating_mode_t op mode)319 ieee80211_operating_mode_t op_mode) 320 320 { 321 321 uint32_t set_bit = 0x10000000; 322 322 323 323 /* NOTICE: Fall-through switch statement! */ 324 switch(op mode) {324 switch(op_mode) { 325 325 case IEEE80211_OPMODE_ADHOC: 326 326 set_bit |= AR9271_OPMODE_ADHOC_MASK; … … 333 333 } 334 334 335 wmi_reg_ clear_set_bit(ar9271->htc_device, AR9271_STATION_ID1,335 wmi_reg_set_clear_bit(ar9271->htc_device, AR9271_STATION_ID1, 336 336 set_bit, 337 337 AR9271_OPMODE_STATION_AP_MASK | AR9271_OPMODE_ADHOC_MASK); 338 339 ar9271->ieee80211_dev->current_op_mode = op_mode; 338 340 339 341 return EOK; … … 352 354 } 353 355 354 static int hw_set_ channel(ar9271_t *ar9271, uint16_t freq)356 static int hw_set_freq(ar9271_t *ar9271, uint16_t freq) 355 357 { 356 358 /* Not supported channel frequency. */ 357 if(freq < IEEE80211_FIRST_ CHANNEL || freq > IEEE80211_MAX_CHANNEL) {359 if(freq < IEEE80211_FIRST_FREQ || freq > IEEE80211_MAX_FREQ) { 358 360 return EINVAL; 359 361 } 360 362 361 363 /* Not supported channel frequency. */ 362 if((freq - IEEE80211_FIRST_ CHANNEL) % IEEE80211_CHANNEL_GAP != 0) {364 if((freq - IEEE80211_FIRST_FREQ) % IEEE80211_CHANNEL_GAP != 0) { 363 365 return EINVAL; 364 366 } 365 367 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); 368 370 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); 370 372 371 373 /* Some magic here. */ … … 377 379 to_write); 378 380 381 ar9271->ieee80211_dev->current_freq = freq; 382 383 return EOK; 384 } 385 386 static 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 411 int 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 429 static 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 442 static 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 454 static 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 484 static 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 379 494 return EOK; 380 495 } … … 382 497 int hw_reset(ar9271_t *ar9271) 383 498 { 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, 385 507 AR9271_RESET_POWER_DOWN_CONTROL, 386 508 AR9271_RADIO_RF_RESET); … … 391 513 392 514 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); 393 535 394 536 rc = wmi_reg_write(ar9271->htc_device, … … 403 545 udelay(50); 404 546 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. */ 411 554 412 555 /* Set physical layer mode. */ … … 418 561 } 419 562 563 /* TODO: Init EEPROM here. */ 564 420 565 /* Set device operating mode. */ 421 566 rc = hw_set_operating_mode(ar9271, IEEE80211_OPMODE_STATION); … … 425 570 } 426 571 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); 429 574 if(rc != EOK) { 430 575 usb_log_error("Failed to set channel.\n"); … … 444 589 } 445 590 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 446 595 /* Activate physical layer. */ 447 rc = wmi_reg_write(ar9271->htc_device, AR9271_PHY_ACTIVE,1);596 rc = hw_activate_phy(ar9271); 448 597 if(rc != EOK) { 449 598 usb_log_error("Failed to activate physical layer.\n"); 450 599 return rc; 451 600 } 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"); 452 610 453 611 return EOK; -
uspace/drv/bus/usb/ar9271/hw.h
rab365c4 r56c0930 38 38 #include "ar9271.h" 39 39 40 #define HW_WAIT_LOOPS 100 40 #define HW_WAIT_LOOPS 1000 41 41 #define HW_WAIT_TIME_US 10 42 42 43 43 extern int hw_init(ar9271_t *ar9271); 44 extern int hw_rx_init(ar9271_t *ar9271); 44 45 extern int hw_reset(ar9271_t *ar9271); 45 46 -
uspace/drv/bus/usb/ar9271/wmi.c
rab365c4 r56c0930 54 54 uint32_t cmd_value = host2uint32_t_be(reg_offset); 55 55 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); 58 58 59 59 int rc = wmi_send_command(htc_device, WMI_REG_READ, … … 90 90 }; 91 91 92 void *resp_buffer = malloc(MAX_RESPONSE_LENGTH); 92 void *resp_buffer = 93 malloc(htc_device->ath_device->ctrl_response_length); 93 94 94 95 int rc = wmi_send_command(htc_device, WMI_REG_WRITE, … … 115 116 * @return EOK if succeed, negative error code otherwise. 116 117 */ 117 int wmi_reg_ clear_set_bit(htc_device_t *htc_device, uint32_t reg_offset,118 int wmi_reg_set_clear_bit(htc_device_t *htc_device, uint32_t reg_offset, 118 119 uint32_t set_bit, uint32_t clear_bit) 119 120 { … … 152 153 uint32_t set_bit) 153 154 { 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); 155 156 } 156 157 … … 167 168 uint32_t clear_bit) 168 169 { 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); 170 171 } 171 172 … … 184 185 size_t buffer_size = sizeof(wmi_reg_t) * elements; 185 186 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); 187 189 188 190 /* Convert values to correct endianness. */ … … 240 242 241 243 /* 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, 243 245 htc_device->endpoints.wmi_endpoint); 244 246 if(rc != EOK) { … … 251 253 252 254 bool clean_resp_buffer = false; 255 size_t response_buffer_size = 256 htc_device->ath_device->ctrl_response_length; 253 257 if(response_buffer == NULL) { 254 response_buffer = malloc( MAX_RESPONSE_LENGTH);258 response_buffer = malloc(response_buffer_size); 255 259 clean_resp_buffer = true; 256 260 } 257 261 258 262 /* 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); 261 265 if(rc != EOK) { 262 266 free(buffer); -
uspace/drv/bus/usb/ar9271/wmi.h
rab365c4 r56c0930 49 49 uint16_t command_id; /**< Big Endian value! */ 50 50 uint16_t sequence_number; /**< Big Endian value! */ 51 } __attribute__((packed)) wmi_command_header_t; 51 } __attribute__((packed)) wmi_command_header_t; 52 52 53 53 /** … … 117 117 extern int wmi_reg_write(htc_device_t *htc_device, uint32_t reg_offset, 118 118 uint32_t val); 119 extern int wmi_reg_ clear_set_bit(htc_device_t *htc_device, uint32_t reg_offset,119 extern int wmi_reg_set_clear_bit(htc_device_t *htc_device, uint32_t reg_offset, 120 120 uint32_t set_bit, uint32_t clear_bit); 121 121 extern int wmi_reg_set_bit(htc_device_t *htc_device, uint32_t reg_offset, -
uspace/lib/net/ieee80211/ieee80211.c
rab365c4 r56c0930 37 37 38 38 #include <errno.h> 39 #include < nic.h>39 #include <byteorder.h> 40 40 41 41 #include <ieee80211_impl.h> … … 48 48 static driver_ops_t ieee80211_nic_driver_ops; 49 49 50 bool 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 50 57 static int ieee80211_open(ddf_fun_t *fun) 51 58 { … … 53 60 ieee80211_dev_t *ieee80211_dev = nic_get_specific(nic_data); 54 61 62 if(ieee80211_dev->started) { 63 return EOK; 64 } else { 65 ieee80211_dev->started = true; 66 } 67 55 68 int rc = ieee80211_dev->ops->start(ieee80211_dev); 56 69 if(rc != EOK) 57 70 return rc; 71 72 /* 73 rc = ieee80211_dev->ops->scan(ieee80211_dev); 74 if(rc != EOK) 75 return rc; 76 */ 58 77 59 78 return EOK; … … 70 89 /* IEEE802.11 start operation must be implemented. */ 71 90 if(!ieee80211_ops->start) 91 return EINVAL; 92 93 /* IEEE802.11 TX handler must be implemented. */ 94 if(!ieee80211_ops->tx_handler) 72 95 return EINVAL; 73 96 … … 93 116 ieee80211_dev->ddf_dev = ddf_dev; 94 117 ieee80211_dev->driver_data = driver_data; 118 ieee80211_dev->started = false; 119 ieee80211_dev->current_op_mode = IEEE80211_OPMODE_STATION; 95 120 96 121 /* Bind NIC to device */ -
uspace/lib/net/ieee80211/ieee80211_impl.c
rab365c4 r56c0930 40 40 #include <ieee80211_impl.h> 41 41 42 static int ieee80211_freq_to_channel(uint16_t freq) 43 { 44 return (freq - IEEE80211_FIRST_FREQ) / IEEE80211_CHANNEL_GAP + 1; 45 } 46 47 static 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 42 63 /** 43 64 * Default implementation of IEEE802.11 scan function. … … 49 70 int ieee80211_scan_impl(ieee80211_dev_t *ieee80211_dev) 50 71 { 51 /** TODO */ 72 /* TODO */ 73 int rc = ieee80211_probe_request(ieee80211_dev); 74 if(rc != EOK) 75 return rc; 52 76 53 77 return EOK; -
uspace/lib/net/include/ieee80211.h
rab365c4 r56c0930 41 41 #include <ddf/driver.h> 42 42 #include <sys/types.h> 43 #include <nic.h> 43 44 44 45 /** Initial channel frequency. */ 45 #define IEEE80211_FIRST_ CHANNEL241246 #define IEEE80211_FIRST_FREQ 2412 46 47 47 48 /** Max supported channel frequency. */ 48 #define IEEE80211_MAX_ CHANNEL247249 #define IEEE80211_MAX_FREQ 2472 49 50 50 51 /* Gap between IEEE80211 channels in MHz. */ 51 52 #define IEEE80211_CHANNEL_GAP 5 53 54 #define IEEE80211_FRAME_CTRL_FRAME_TYPE 0x000C 55 #define IEEE80211_FRAME_CTRL_DATA_FRAME 0x0008 52 56 53 57 struct ieee80211_dev; … … 65 69 int (*start)(struct ieee80211_dev *); 66 70 int (*scan)(struct ieee80211_dev *); 71 int (*tx_handler)(struct ieee80211_dev *, void *, size_t); 67 72 } ieee80211_ops_t; 68 73 … … 77 82 /** Pointer to driver specific data. */ 78 83 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; 79 96 } ieee80211_dev_t; 80 97 98 /** IEEE 802.11 header structure. */ 99 typedef 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 109 extern bool ieee80211_is_data_frame(ieee80211_header_t *header); 81 110 extern int ieee80211_device_init(ieee80211_dev_t *ieee80211_dev, 82 111 void *driver_data, ddf_dev_t *ddf_dev);
Note:
See TracChangeset
for help on using the changeset viewer.