Changeset ab365c4 in mainline
- Timestamp:
- 2015-02-13T12:15:00Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 56c0930
- Parents:
- 462054a
- Location:
- uspace
- Files:
-
- 4 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/Makefile.common
r462054a rab365c4 258 258 259 259 ifeq ($(CONFIG_DEBUG),y) 260 #GCC_CFLAGS += -Werror260 GCC_CFLAGS += -Werror 261 261 ICC_CFLAGS += -Werror 262 262 endif -
uspace/drv/bus/usb/ar9271/Makefile
r462054a rab365c4 33 33 $(LIBUSB_PREFIX)/libusb.a \ 34 34 $(LIBDRV_PREFIX)/libdrv.a \ 35 $(LIBNIC_PREFIX)/libnic.a 35 $(LIBNIC_PREFIX)/libnic.a \ 36 $(LIBNET_PREFIX)/libnet.a 36 37 37 38 EXTRA_CFLAGS += \ … … 40 41 -I$(LIBUSBDEV_PREFIX)/include \ 41 42 -I$(LIBDRV_PREFIX)/include \ 42 -I$(LIBNIC_PREFIX)/include 43 -I$(LIBNIC_PREFIX)/include \ 44 -I$(LIBNET_PREFIX)/include \ 43 45 44 46 BINARY = ar9271 -
uspace/drv/bus/usb/ar9271/ar9271.c
r462054a rab365c4 33 33 */ 34 34 35 #include <ieee80211.h> 35 36 #include <usb/classes/classes.h> 36 37 #include <usb/dev/request.h> … … 95 96 }; 96 97 97 /** Network interface options for AR9271 driver. */98 static nic_iface_t ar9271_nic_iface;99 100 /** Basic device operations for AR9271 NIC driver. */101 static ddf_dev_ops_t ar9271_nic_dev_ops;102 103 /** Basic driver operations for AR9271 NIC driver. */104 static driver_ops_t ar9271_nic_driver_ops;105 106 98 /* Callback when new device is to be controlled by this driver. */ 107 99 static int ar9271_add_device(ddf_dev_t *); 100 101 /* IEEE802.11 callbacks */ 102 static int ar9271_ieee80211_start(ieee80211_dev_t *ieee80211_dev); 108 103 109 104 static driver_ops_t ar9271_driver_ops = { … … 116 111 }; 117 112 118 /* The default implementation callbacks */ 119 static int ar9271_on_activating(nic_t *); 120 static int ar9271_on_stopping(nic_t *); 121 static void ar9271_send_frame(nic_t *, void *, size_t); 113 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 } 155 156 return EOK; 157 } 158 159 static int ar9271_ieee80211_start(ieee80211_dev_t *ieee80211_dev) 160 { 161 ar9271_t *ar9271 = (ar9271_t *) ieee80211_dev->driver_data; 162 163 int rc = wmi_send_command(ar9271->htc_device, WMI_FLUSH_RECV, NULL, 0, 164 NULL); 165 if(rc != EOK) { 166 usb_log_error("Failed to flush receiving buffer.\n"); 167 return EINVAL; 168 } 169 170 rc = hw_reset(ar9271); 171 if(rc != EOK) { 172 usb_log_error("Failed to do HW reset.\n"); 173 return EINVAL; 174 } 175 176 uint16_t htc_mode = host2uint16_t_be(1); 177 rc = wmi_send_command(ar9271->htc_device, WMI_SET_MODE, 178 (uint8_t *) &htc_mode, sizeof(htc_mode), NULL); 179 if(rc != EOK) { 180 usb_log_error("Failed to set HTC mode.\n"); 181 return EINVAL; 182 } 183 184 rc = wmi_send_command(ar9271->htc_device, WMI_ATH_INIT, NULL, 0, 185 NULL); 186 if(rc != EOK) { 187 usb_log_error("Failed to send ath init command.\n"); 188 return EINVAL; 189 } 190 191 rc = wmi_send_command(ar9271->htc_device, WMI_START_RECV, NULL, 0, 192 NULL); 193 if(rc != EOK) { 194 usb_log_error("Failed to send receiving init command.\n"); 195 return EINVAL; 196 } 197 198 rc = ar9271_rx_init(ar9271); 199 if(rc != EOK) { 200 usb_log_error("Failed to initialize RX.\n"); 201 return EINVAL; 202 } 203 204 return EOK; 205 } 122 206 123 207 static int ar9271_init(ar9271_t *ar9271, usb_device_t *usb_device) … … 125 209 ar9271->usb_device = usb_device; 126 210 127 a th_t *ath_device = malloc(sizeof(ath_t));128 if (!a th_device) {211 ar9271->ath_device = calloc(1, sizeof(ath_t)); 212 if (!ar9271->ath_device) { 129 213 usb_log_error("Failed to allocate memory for ath device " 130 214 "structure.\n"); … … 132 216 } 133 217 134 int rc = ath_usb_init(a th_device, usb_device);135 if(rc != EOK) { 136 free(a th_device);218 int rc = ath_usb_init(ar9271->ath_device, usb_device); 219 if(rc != EOK) { 220 free(ar9271->ath_device); 137 221 usb_log_error("Failed to initialize ath device.\n"); 138 222 return EINVAL; … … 140 224 141 225 /* HTC device structure initialization. */ 142 ar9271->htc_device = malloc(sizeof(htc_device_t));226 ar9271->htc_device = calloc(1, sizeof(htc_device_t)); 143 227 if(!ar9271->htc_device) { 144 free(a th_device);228 free(ar9271->ath_device); 145 229 usb_log_error("Failed to allocate memory for HTC device " 146 230 "structure.\n"); … … 148 232 } 149 233 150 memset(ar9271->htc_device, 0, sizeof(htc_device_t)); 151 152 rc = htc_device_init(ath_device, ar9271->htc_device); 234 rc = htc_device_init(ar9271->ath_device, ar9271->htc_device); 153 235 if(rc != EOK) { 154 236 free(ar9271->htc_device); 155 free(ath_device); 156 usb_log_error("Failed to initialize HTC device.\n"); 237 free(ar9271->ath_device); 238 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"); 157 260 return EINVAL; 158 261 } … … 255 358 } 256 359 257 /** Force receiving all frames in the receive buffer258 *259 * @param nic NIC data260 */261 static void ar9271_poll(nic_t *nic)262 {263 assert(nic);264 }265 266 /** Set polling mode267 *268 * @param device Device to set269 * @param mode Mode to set270 * @param period Period for NIC_POLL_PERIODIC271 *272 * @return EOK if succeed, ENOTSUP if the mode is not supported273 */274 static int ar9271_poll_mode_change(nic_t *nic, nic_poll_mode_t mode,275 const struct timeval *period)276 {277 assert(nic);278 return EOK;279 }280 281 /** Set multicast frames acceptance mode282 *283 * @param nic NIC device to update284 * @param mode Mode to set285 * @param addr Address list (used in mode = NIC_MULTICAST_LIST)286 * @param addr_cnt Length of address list (used in mode = NIC_MULTICAST_LIST)287 *288 * @return EOK if succeed, negative error code otherwise289 */290 static int ar9271_on_multicast_mode_change(nic_t *nic,291 nic_multicast_mode_t mode, const nic_address_t *addr, size_t addr_cnt)292 {293 assert(nic);294 return EOK;295 }296 297 /** Set unicast frames acceptance mode298 *299 * @param nic NIC device to update300 * @param mode Mode to set301 * @param addr Address list (used in mode = NIC_MULTICAST_LIST)302 * @param addr_cnt Length of address list (used in mode = NIC_MULTICAST_LIST)303 *304 * @return EOK if succeed, negative error code otherwise305 */306 static int ar9271_on_unicast_mode_change(nic_t *nic, nic_unicast_mode_t mode,307 const nic_address_t *addr, size_t addr_cnt)308 {309 assert(nic);310 return EOK;311 }312 313 /** Set broadcast frames acceptance mode314 *315 * @param nic NIC device to update316 * @param mode Mode to set317 *318 * @return EOK if succeed, negative error code otherwise319 */320 static int ar9271_on_broadcast_mode_change(nic_t *nic,321 nic_broadcast_mode_t mode)322 {323 assert(nic);324 return EOK;325 }326 327 /** Activate the device to receive and transmit frames328 *329 * @param nic NIC driver data330 *331 * @return EOK if activated successfully, negative error code otherwise332 */333 static int ar9271_on_activating(nic_t *nic)334 {335 assert(nic);336 return EOK;337 }338 339 /** Callback for NIC_STATE_STOPPED change340 *341 * @param nic NIC driver data342 *343 * @return EOK if succeed, negative error code otherwise344 */345 static int ar9271_on_stopping(nic_t *nic)346 {347 assert(nic);348 return EOK;349 }350 351 /** Send frame352 *353 * @param nic NIC driver data structure354 * @param data Frame data355 * @param size Frame size in bytes356 */357 static void ar9271_send_frame(nic_t *nic, void *data, size_t size)358 {359 assert(nic);360 }361 362 360 /** Create driver data structure. 363 361 * … … 385 383 386 384 /* AR9271 structure initialization. */ 387 ar9271_t *ar9271 = malloc(sizeof(ar9271_t));385 ar9271_t *ar9271 = calloc(1, sizeof(ar9271_t)); 388 386 if (!ar9271) { 389 387 free(usb_device); … … 393 391 } 394 392 395 memset(ar9271, 0, sizeof(ar9271_t)); 396 397 ar9271->ddf_device = dev; 393 ar9271->ddf_dev = dev; 398 394 399 395 rc = ar9271_init(ar9271, usb_device); … … 406 402 } 407 403 408 /* NIC framework initialization. */409 nic_t *nic = nic_create_and_bind(dev);410 if (!nic) {411 free(ar9271);412 free(usb_device);413 usb_log_error("Failed to create and bind NIC data.\n");414 return NULL;415 }416 417 nic_set_specific(nic, ar9271);418 nic_set_send_frame_handler(nic, ar9271_send_frame);419 nic_set_state_change_handlers(nic, ar9271_on_activating,420 NULL, ar9271_on_stopping);421 nic_set_filtering_change_handlers(nic,422 ar9271_on_unicast_mode_change, ar9271_on_multicast_mode_change,423 ar9271_on_broadcast_mode_change, NULL, NULL);424 nic_set_poll_handlers(nic, ar9271_poll_mode_change, ar9271_poll);425 426 404 return ar9271; 427 405 } … … 447 425 { 448 426 assert(dev); 449 ddf_fun_t *fun;450 427 451 428 /* Allocate driver data for the device. */ … … 477 454 } 478 455 479 nic_t *nic = nic_get_from_ddf_dev(dev); 480 481 /* Create AR9271 function.*/ 482 fun = ddf_fun_create(nic_get_ddf_dev(nic), fun_exposed, "port0"); 483 if (fun == NULL) { 456 /* Initialize AR9271 IEEE 802.11 framework. */ 457 rc = ieee80211_init(ar9271->ieee80211_dev, &ar9271_ieee80211_ops); 458 if(rc != EOK) { 484 459 ar9271_delete_dev_data(ar9271); 485 usb_log_error("Failed creating device function.\n"); 486 } 487 488 nic_set_ddf_fun(nic, fun); 489 ddf_fun_set_ops(fun, &ar9271_nic_dev_ops); 490 491 rc = ddf_fun_bind(fun); 492 if (rc != EOK) { 493 ddf_fun_destroy(fun); 494 ar9271_delete_dev_data(ar9271); 495 usb_log_error("Failed binding device function.\n"); 496 return rc; 497 } 498 rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC); 499 if (rc != EOK) { 500 ddf_fun_unbind(fun); 501 ar9271_delete_dev_data(ar9271); 502 usb_log_error("Failed adding function to category.\n"); 460 usb_log_error("Failed to initialize IEEE80211 framework.\n"); 503 461 return rc; 504 462 } … … 516 474 return 1; 517 475 518 nic_driver_implement(&ar9271_nic_driver_ops, &ar9271_nic_dev_ops,519 &ar9271_nic_iface);520 521 476 usb_log_info("HelenOS AR9271 driver started.\n"); 522 477 -
uspace/drv/bus/usb/ar9271/ar9271.h
r462054a rab365c4 40 40 #include "htc.h" 41 41 42 /** Max supported channel frequency. */ 43 #define AR9271_MAX_CHANNEL 2472 44 45 /** Number of transmisson queues */ 46 #define AR9271_QUEUES_COUNT 10 47 42 48 /** Number of GPIO pin used for handling led light */ 43 49 #define AR9271_LED_PIN 15 … … 45 51 /** AR9271 Registers */ 46 52 typedef enum { 53 /* ATH command register */ 54 AR9271_COMMAND = 0x0008, 55 AR9271_COMMAND_RX_ENABLE = 0x00000004, 56 57 /* ATH config register */ 58 AR9271_CONFIG = 0x0014, 59 AR9271_CONFIG_ADHOC = 0x00000020, 60 61 AR9271_QUEUE_BASE_MASK = 0x1000, 62 47 63 /* EEPROM Addresses */ 48 64 AR9271_EEPROM_BASE = 0x2100, … … 64 80 /* Wakeup related registers */ 65 81 AR9271_RTC_RC = 0x7000, 82 AR9271_RTC_RC_MAC_WARM = 0x00000001, 83 AR9271_RTC_RC_MAC_COLD = 0x00000002, 66 84 AR9271_RTC_RC_MASK = 0x00000003, 67 85 AR9271_RTC_RESET = 0x7040, 68 86 AR9271_RTC_STATUS = 0x7044, 69 87 AR9271_RTC_STATUS_MASK = 0x0000000F, 88 AR9271_RTC_STATUS_SHUTDOWN = 0x00000001, 70 89 AR9271_RTC_STATUS_ON = 0x00000002, 71 90 AR9271_RTC_FORCE_WAKE = 0x704C, 72 91 AR9271_RTC_FORCE_WAKE_ENABLE = 0x00000001, 73 92 AR9271_RTC_FORCE_WAKE_ON_INT = 0x00000002, 93 94 AR9271_RX_FILTER = 0x803C, 95 AR9271_RX_FILTER_UNI = 0x00000001, 96 AR9271_RX_FILTER_MULTI = 0x00000002, 97 AR9271_RX_FILTER_BROAD = 0x00000004, 98 AR9271_RX_FILTER_CONTROL = 0x00000008, 99 AR9271_RX_FILTER_BEACON = 0x00000010, 100 AR9271_RX_FILTER_PROMISCUOUS = 0x00000020, 101 AR9271_RX_FILTER_PROBEREQ = 0x00000080, 102 103 AR9271_PHY_BASE = 0x9800, 104 AR9271_PHY_ACTIVE = 0x981C, 105 AR9271_PHY_MODE = 0xA200, 106 AR9271_PHY_MODE_2G = 0x02, 107 AR9271_PHY_MODE_DYNAMIC = 0x04, 108 AR9271_PHY_CCK_TX_CTRL = 0xA204, 109 AR9271_PHY_CCK_TX_CTRL_JAPAN = 0x00000010, 110 111 AR9271_OPMODE_STATION_AP_MASK = 0x00010000, 112 AR9271_OPMODE_ADHOC_MASK = 0x00020000, 113 114 AR9271_RESET_POWER_DOWN_CONTROL = 0x50044, 115 AR9271_RADIO_RF_RESET = 0x20, 116 AR9271_GATE_MAC_CONTROL = 0x4000, 74 117 75 118 /* FW Addresses */ … … 78 121 79 122 /* MAC Registers */ 80 AR9271_ MAC_PCU_STA_ADDR_L32= 0x8000, /**< STA Address Lower 32 Bits */81 AR9271_ MAC_PCU_STA_ADDR_U16= 0x8004, /**< STA Address Upper 16 Bits */82 AR9271_ MAC_PCU_BSSID_L32= 0x8008, /**< BSSID Lower 32 Bits */83 AR9271_ MAC_PCU_BSSID_U16= 0x800C, /**< BSSID Upper 16 Bits */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 */ 84 127 } ar9271_registers_t; 85 128 … … 92 135 /** AR9271 device data */ 93 136 typedef struct { 94 /** DDF device pointer*/95 ddf_dev_t *ddf_dev ice;137 /** Backing DDF device */ 138 ddf_dev_t *ddf_dev; 96 139 97 140 /** USB device data */ 98 141 usb_device_t *usb_device; 142 143 /** IEEE 802.11 device data */ 144 ieee80211_dev_t *ieee80211_dev; 145 146 /** ATH device data */ 147 ath_t *ath_device; 99 148 100 149 /** HTC device data */ -
uspace/drv/bus/usb/ar9271/htc.c
r462054a rab365c4 35 35 #include <usb/debug.h> 36 36 #include <byteorder.h> 37 #include <errno.h> 37 38 38 39 #include "wmi.h" -
uspace/drv/bus/usb/ar9271/htc.h
r462054a rab365c4 39 39 #include <usb/dev/driver.h> 40 40 #include <sys/types.h> 41 #include <errno.h>42 41 43 42 #include "ath.h" … … 171 170 172 171 extern int htc_device_init(ath_t *ath_device, htc_device_t *htc_device); 173 extern int htc_init(htc_device_t *htc_device);172 extern int htc_init(htc_device_t *htc_device); 174 173 extern int htc_read_message(htc_device_t *htc_device, void *buffer, 175 174 size_t buffer_size, size_t *transferred_size); … … 177 176 size_t buffer_size, uint8_t endpoint_id); 178 177 179 #endif /* HTC_H */178 #endif /* ATHEROS_HTC_H */ 180 179 -
uspace/drv/bus/usb/ar9271/hw.c
r462054a rab365c4 36 36 #include <unistd.h> 37 37 #include <nic.h> 38 #include <ieee80211.h> 38 39 39 40 #include "hw.h" … … 76 77 static int hw_reset_power_on(ar9271_t *ar9271) 77 78 { 78 int rc = wmi_reg_write(ar9271->htc_device, AR9271_RTC_FORCE_WAKE,79 AR9271_RTC_FORCE_WAKE_ENABLE | AR9271_RTC_FORCE_WAKE_ON_INT);80 if(rc != EOK) {81 usb_log_error("Failed to bring up RTC register.\n");82 return rc;83 }84 85 79 wmi_reg_t buffer[] = { 86 80 { … … 99 93 }; 100 94 101 rc = wmi_reg_buffer_write(ar9271->htc_device, buffer,95 int rc = wmi_reg_buffer_write(ar9271->htc_device, buffer, 102 96 sizeof(buffer) / sizeof(wmi_reg_t)); 103 97 if(rc != EOK) { … … 132 126 } 133 127 134 static int hw_warm_reset(ar9271_t *ar9271) 135 { 128 static int hw_set_reset(ar9271_t *ar9271, bool cold) 129 { 130 uint32_t reset_value = AR9271_RTC_RC_MAC_WARM; 131 132 if(cold) { 133 reset_value |= AR9271_RTC_RC_MAC_COLD; 134 } 135 136 136 wmi_reg_t buffer[] = { 137 137 { … … 146 146 { 147 147 .offset = AR9271_RTC_RC, 148 .value = 1148 .value = reset_value 149 149 } 150 150 }; … … 202 202 } 203 203 204 nic_t *nic = nic_get_from_ddf_dev(ar9271->ddf_dev ice);204 nic_t *nic = nic_get_from_ddf_dev(ar9271->ddf_dev); 205 205 206 206 rc = nic_report_address(nic, &ar9271_address); … … 269 269 270 270 /** 271 * Hardware resetof AR9271 device.271 * Hardware init procedure of AR9271 device. 272 272 * 273 273 * @param ar9271 Device structure. … … 275 275 * @return EOK if succeed, negative error code otherwise. 276 276 */ 277 static int hw_ reset(ar9271_t *ar9271)277 static int hw_init_proc(ar9271_t *ar9271) 278 278 { 279 279 int rc = hw_reset_power_on(ar9271); … … 283 283 } 284 284 285 rc = hw_ warm_reset(ar9271);285 rc = hw_set_reset(ar9271, false); 286 286 if(rc != EOK) { 287 287 usb_log_error("Failed to HW warm reset.\n"); … … 310 310 if(rc != EOK) { 311 311 usb_log_error("Failed to init bring up GPIO led.\n"); 312 return rc; 313 } 314 315 return EOK; 316 } 317 318 static int hw_set_operating_mode(ar9271_t *ar9271, 319 ieee80211_operating_mode_t opmode) 320 { 321 uint32_t set_bit = 0x10000000; 322 323 /* NOTICE: Fall-through switch statement! */ 324 switch(opmode) { 325 case IEEE80211_OPMODE_ADHOC: 326 set_bit |= AR9271_OPMODE_ADHOC_MASK; 327 case IEEE80211_OPMODE_MESH: 328 case IEEE80211_OPMODE_AP: 329 set_bit |= AR9271_OPMODE_STATION_AP_MASK; 330 case IEEE80211_OPMODE_STATION: 331 wmi_reg_clear_bit(ar9271->htc_device, AR9271_CONFIG, 332 AR9271_CONFIG_ADHOC); 333 } 334 335 wmi_reg_clear_set_bit(ar9271->htc_device, AR9271_STATION_ID1, 336 set_bit, 337 AR9271_OPMODE_STATION_AP_MASK | AR9271_OPMODE_ADHOC_MASK); 338 339 return EOK; 340 } 341 342 static uint32_t hw_reverse_bits(uint32_t value, uint32_t count) 343 { 344 uint32_t ret_val = 0; 345 346 for(size_t i = 0; i < count; i++) { 347 ret_val = (ret_val << 1) | (value & 1); 348 value >>= 1; 349 } 350 351 return ret_val; 352 } 353 354 static int hw_set_channel(ar9271_t *ar9271, uint16_t freq) 355 { 356 /* Not supported channel frequency. */ 357 if(freq < IEEE80211_FIRST_CHANNEL || freq > IEEE80211_MAX_CHANNEL) { 358 return EINVAL; 359 } 360 361 /* Not supported channel frequency. */ 362 if((freq - IEEE80211_FIRST_CHANNEL) % IEEE80211_CHANNEL_GAP != 0) { 363 return EINVAL; 364 } 365 366 uint32_t result; 367 wmi_reg_read(ar9271->htc_device, AR9271_PHY_CCK_TX_CTRL, &result); 368 wmi_reg_write(ar9271->htc_device, AR9271_PHY_CCK_TX_CTRL, 369 result & ~AR9271_PHY_CCK_TX_CTRL_JAPAN); 370 371 /* Some magic here. */ 372 uint32_t channel = hw_reverse_bits( 373 (((((freq - 672) * 2 - 3040) / 10) << 2) & 0xFF), 8); 374 uint32_t to_write = (channel << 8) | 33; 375 376 wmi_reg_write(ar9271->htc_device, AR9271_PHY_BASE + (0x37 << 2), 377 to_write); 378 379 return EOK; 380 } 381 382 int hw_reset(ar9271_t *ar9271) 383 { 384 int rc = wmi_reg_write(ar9271->htc_device, 385 AR9271_RESET_POWER_DOWN_CONTROL, 386 AR9271_RADIO_RF_RESET); 387 if(rc != EOK) { 388 usb_log_error("Failed to reset radio rf.\n"); 389 return rc; 390 } 391 392 udelay(50); 393 394 rc = wmi_reg_write(ar9271->htc_device, 395 AR9271_RESET_POWER_DOWN_CONTROL, 396 AR9271_GATE_MAC_CONTROL); 397 if(rc != EOK) { 398 usb_log_error("Failed to set the gate reset controls for MAC." 399 "\n"); 400 return rc; 401 } 402 403 udelay(50); 404 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 } 411 412 /* Set physical layer mode. */ 413 rc = wmi_reg_write(ar9271->htc_device, AR9271_PHY_MODE, 414 AR9271_PHY_MODE_DYNAMIC | AR9271_PHY_MODE_2G); 415 if(rc != EOK) { 416 usb_log_error("Failed to set physical layer mode.\n"); 417 return rc; 418 } 419 420 /* Set device operating mode. */ 421 rc = hw_set_operating_mode(ar9271, IEEE80211_OPMODE_STATION); 422 if(rc != EOK) { 423 usb_log_error("Failed to set opmode to station.\n"); 424 return rc; 425 } 426 427 /* Set channel. */ 428 rc = hw_set_channel(ar9271, IEEE80211_FIRST_CHANNEL); 429 if(rc != EOK) { 430 usb_log_error("Failed to set channel.\n"); 431 return rc; 432 } 433 434 /* Initialize transmission queues. */ 435 for(int i = 0; i < AR9271_QUEUES_COUNT; i++) { 436 rc = wmi_reg_write(ar9271->htc_device, 437 AR9271_QUEUE_BASE_MASK + (i << 2), 438 1 << i); 439 if(rc != EOK) { 440 usb_log_error("Failed to initialize transmission queue." 441 "\n"); 442 return rc; 443 } 444 } 445 446 /* Activate physical layer. */ 447 rc = wmi_reg_write(ar9271->htc_device, AR9271_PHY_ACTIVE, 1); 448 if(rc != EOK) { 449 usb_log_error("Failed to activate physical layer.\n"); 312 450 return rc; 313 451 } … … 325 463 int hw_init(ar9271_t *ar9271) 326 464 { 327 int rc = hw_ reset(ar9271);465 int rc = hw_init_proc(ar9271); 328 466 if(rc != EOK) { 329 467 usb_log_error("Failed to HW reset device.\n"); -
uspace/drv/bus/usb/ar9271/hw.h
r462054a rab365c4 42 42 43 43 extern int hw_init(ar9271_t *ar9271); 44 extern int hw_reset(ar9271_t *ar9271); 44 45 45 46 #endif /* ATHEROS_HW_H */ -
uspace/drv/bus/usb/ar9271/wmi.c
r462054a rab365c4 250 250 free(buffer); 251 251 252 bool clean_resp_buffer = false; 253 if(response_buffer == NULL) { 254 response_buffer = malloc(MAX_RESPONSE_LENGTH); 255 clean_resp_buffer = true; 256 } 257 252 258 /* Read response. */ 253 259 rc = htc_read_message(htc_device, response_buffer, MAX_RESPONSE_LENGTH, … … 260 266 } 261 267 262 return rc; 263 } 268 if(clean_resp_buffer) { 269 free(response_buffer); 270 } 271 272 return rc; 273 } -
uspace/drv/bus/usb/ar9271/wmi.h
r462054a rab365c4 102 102 WMI_TX_STATS, 103 103 WMI_RX_STATS, 104 WMI_BITRATE_MASK, 105 WMI_REG_RMW, 104 WMI_BITRATE_MASK 106 105 } wmi_command_t; 107 106 -
uspace/lib/net/Makefile
r462054a rab365c4 29 29 30 30 USPACE_PREFIX = ../.. 31 EXTRA_CFLAGS = -Iinclude32 31 LIBRARY = libnet 33 32 33 LIBS = \ 34 $(LIBDRV_PREFIX)/libdrv.a \ 35 $(LIBNIC_PREFIX)/libnic.a 36 37 EXTRA_CFLAGS += \ 38 -Iinclude \ 39 -I$(LIBDRV_PREFIX)/include \ 40 -I$(LIBNIC_PREFIX)/include 41 34 42 SOURCES = \ 35 tl/socket_core.c 43 tl/socket_core.c \ 44 ieee80211/ieee80211.c \ 45 ieee80211/ieee80211_impl.c 36 46 37 47 include $(USPACE_PREFIX)/Makefile.common
Note:
See TracChangeset
for help on using the changeset viewer.