Lines Matching refs:ar
45 static int ar5523_submit_rx_cmd(struct ar5523 *ar);
46 static void ar5523_data_tx_pkt_put(struct ar5523 *ar);
48 static void ar5523_read_reply(struct ar5523 *ar, struct ar5523_cmd_hdr *hdr, in ar5523_read_reply() argument
61 ar5523_dbg(ar, "Code = %d len = %d\n", be32_to_cpu(hdr->code) & 0xff, in ar5523_read_reply()
77 ar5523_err(ar, "olen too small %d < %d\n", in ar5523_read_reply()
94 struct ar5523 *ar = urb->context; in ar5523_cmd_rx_cb() local
95 struct ar5523_tx_cmd *cmd = &ar->tx_cmd; in ar5523_cmd_rx_cb()
96 struct ar5523_cmd_hdr *hdr = ar->rx_cmd_buf; in ar5523_cmd_rx_cb()
102 ar5523_err(ar, "RX USB error %d.\n", urb->status); in ar5523_cmd_rx_cb()
107 ar5523_err(ar, "RX USB too short.\n"); in ar5523_cmd_rx_cb()
111 ar5523_dbg(ar, "%s code %02x priv %d\n", __func__, in ar5523_cmd_rx_cb()
121 ar5523_err(ar, "Unexpected command id: %02x\n", in ar5523_cmd_rx_cb()
125 ar5523_read_reply(ar, hdr, cmd); in ar5523_cmd_rx_cb()
129 ar5523_dbg(ar, "WDCMSG_DEVICE_AVAIL\n"); in ar5523_cmd_rx_cb()
136 ar5523_dbg(ar, "WDCMSG_SEND_COMPLETE: %d pending\n", in ar5523_cmd_rx_cb()
137 atomic_read(&ar->tx_nr_pending)); in ar5523_cmd_rx_cb()
138 if (!test_bit(AR5523_HW_UP, &ar->flags)) in ar5523_cmd_rx_cb()
139 ar5523_dbg(ar, "Unexpected WDCMSG_SEND_COMPLETE\n"); in ar5523_cmd_rx_cb()
141 mod_timer(&ar->tx_wd_timer, in ar5523_cmd_rx_cb()
143 ar5523_data_tx_pkt_put(ar); in ar5523_cmd_rx_cb()
153 ar5523_err(ar, "Invalid reply to WDCMSG_TARGET_START"); in ar5523_cmd_rx_cb()
157 ar5523_err(ar, "Unexpected WDCMSG_TARGET_START reply"); in ar5523_cmd_rx_cb()
167 ar5523_dbg(ar, "WDCMSG_STATS_UPDATE\n"); in ar5523_cmd_rx_cb()
172 ar5523_submit_rx_cmd(ar); in ar5523_cmd_rx_cb()
175 static int ar5523_alloc_rx_cmd(struct ar5523 *ar) in ar5523_alloc_rx_cmd() argument
177 ar->rx_cmd_urb = usb_alloc_urb(0, GFP_KERNEL); in ar5523_alloc_rx_cmd()
178 if (!ar->rx_cmd_urb) in ar5523_alloc_rx_cmd()
181 ar->rx_cmd_buf = usb_alloc_coherent(ar->dev, AR5523_MAX_RXCMDSZ, in ar5523_alloc_rx_cmd()
183 &ar->rx_cmd_urb->transfer_dma); in ar5523_alloc_rx_cmd()
184 if (!ar->rx_cmd_buf) { in ar5523_alloc_rx_cmd()
185 usb_free_urb(ar->rx_cmd_urb); in ar5523_alloc_rx_cmd()
191 static void ar5523_cancel_rx_cmd(struct ar5523 *ar) in ar5523_cancel_rx_cmd() argument
193 usb_kill_urb(ar->rx_cmd_urb); in ar5523_cancel_rx_cmd()
196 static void ar5523_free_rx_cmd(struct ar5523 *ar) in ar5523_free_rx_cmd() argument
198 usb_free_coherent(ar->dev, AR5523_MAX_RXCMDSZ, in ar5523_free_rx_cmd()
199 ar->rx_cmd_buf, ar->rx_cmd_urb->transfer_dma); in ar5523_free_rx_cmd()
200 usb_free_urb(ar->rx_cmd_urb); in ar5523_free_rx_cmd()
203 static int ar5523_submit_rx_cmd(struct ar5523 *ar) in ar5523_submit_rx_cmd() argument
207 usb_fill_bulk_urb(ar->rx_cmd_urb, ar->dev, in ar5523_submit_rx_cmd()
208 ar5523_cmd_rx_pipe(ar->dev), ar->rx_cmd_buf, in ar5523_submit_rx_cmd()
209 AR5523_MAX_RXCMDSZ, ar5523_cmd_rx_cb, ar); in ar5523_submit_rx_cmd()
210 ar->rx_cmd_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in ar5523_submit_rx_cmd()
212 error = usb_submit_urb(ar->rx_cmd_urb, GFP_ATOMIC); in ar5523_submit_rx_cmd()
215 ar5523_err(ar, "error %d when submitting rx urb\n", in ar5523_submit_rx_cmd()
228 struct ar5523 *ar = cmd->ar; in ar5523_cmd_tx_cb() local
231 ar5523_err(ar, "Failed to TX command. Status = %d\n", in ar5523_cmd_tx_cb()
244 static void ar5523_cancel_tx_cmd(struct ar5523 *ar) in ar5523_cancel_tx_cmd() argument
246 usb_kill_urb(ar->tx_cmd.urb_tx); in ar5523_cancel_tx_cmd()
249 static int ar5523_cmd(struct ar5523 *ar, u32 code, const void *idata, in ar5523_cmd() argument
253 struct ar5523_tx_cmd *cmd = &ar->tx_cmd; in ar5523_cmd()
274 ar5523_dbg(ar, "do cmd %02x\n", code); in ar5523_cmd()
276 usb_fill_bulk_urb(cmd->urb_tx, ar->dev, ar5523_cmd_tx_pipe(ar->dev), in ar5523_cmd()
282 ar5523_err(ar, "could not send command 0x%x, error=%d\n", in ar5523_cmd()
288 ar5523_cancel_tx_cmd(ar); in ar5523_cmd()
290 ar5523_err(ar, "timeout waiting for command %02x reply\n", in ar5523_cmd()
297 static int ar5523_cmd_write(struct ar5523 *ar, u32 code, const void *data, in ar5523_cmd_write() argument
301 return ar5523_cmd(ar, code, data, len, NULL, 0, flags); in ar5523_cmd_write()
304 static int ar5523_cmd_read(struct ar5523 *ar, u32 code, const void *idata, in ar5523_cmd_read() argument
308 return ar5523_cmd(ar, code, idata, ilen, odata, olen, flags); in ar5523_cmd_read()
311 static int ar5523_config(struct ar5523 *ar, u32 reg, u32 val) in ar5523_config() argument
320 error = ar5523_cmd_write(ar, WDCMSG_TARGET_SET_CONFIG, &write, in ar5523_config()
323 ar5523_err(ar, "could not write register 0x%02x\n", reg); in ar5523_config()
327 static int ar5523_config_multi(struct ar5523 *ar, u32 reg, const void *data, in ar5523_config_multi() argument
338 error = ar5523_cmd_write(ar, WDCMSG_TARGET_SET_CONFIG, &write, in ar5523_config_multi()
341 ar5523_err(ar, "could not write %d bytes to register 0x%02x\n", in ar5523_config_multi()
346 static int ar5523_get_status(struct ar5523 *ar, u32 which, void *odata, in ar5523_get_status() argument
353 error = ar5523_cmd_read(ar, WDCMSG_TARGET_GET_STATUS, in ar5523_get_status()
356 ar5523_err(ar, "could not read EEPROM offset 0x%02x\n", which); in ar5523_get_status()
360 static int ar5523_get_capability(struct ar5523 *ar, u32 cap, u32 *val) in ar5523_get_capability() argument
366 error = ar5523_cmd_read(ar, WDCMSG_TARGET_GET_CAPABILITY, &cap_be, in ar5523_get_capability()
370 ar5523_err(ar, "could not read capability %u\n", cap); in ar5523_get_capability()
377 static int ar5523_get_devcap(struct ar5523 *ar) in ar5523_get_devcap() argument
380 error = ar5523_get_capability(ar, x, &cap); \ in ar5523_get_devcap()
383 ar5523_info(ar, "Cap: " \ in ar5523_get_devcap()
426 static int ar5523_set_ledsteady(struct ar5523 *ar, int lednum, int ledmode) in ar5523_set_ledsteady() argument
433 ar5523_dbg(ar, "set %s led %s (steady)\n", in ar5523_set_ledsteady()
436 return ar5523_cmd_write(ar, WDCMSG_SET_LED_STEADY, &led, sizeof(led), in ar5523_set_ledsteady()
440 static int ar5523_set_rxfilter(struct ar5523 *ar, u32 bits, u32 op) in ar5523_set_rxfilter() argument
447 ar5523_dbg(ar, "setting Rx filter=0x%x flags=0x%x\n", bits, op); in ar5523_set_rxfilter()
448 return ar5523_cmd_write(ar, WDCMSG_RX_FILTER, &rxfilter, in ar5523_set_rxfilter()
452 static int ar5523_reset_tx_queues(struct ar5523 *ar) in ar5523_reset_tx_queues() argument
456 ar5523_dbg(ar, "resetting Tx queue\n"); in ar5523_reset_tx_queues()
457 return ar5523_cmd_write(ar, WDCMSG_RELEASE_TX_QUEUE, in ar5523_reset_tx_queues()
461 static int ar5523_set_chan(struct ar5523 *ar) in ar5523_set_chan() argument
463 struct ieee80211_conf *conf = &ar->hw->conf; in ar5523_set_chan()
475 ar5523_dbg(ar, "set chan flags 0x%x freq %d\n", in ar5523_set_chan()
478 return ar5523_cmd_write(ar, WDCMSG_RESET, &reset, sizeof(reset), 0); in ar5523_set_chan()
481 static int ar5523_queue_init(struct ar5523 *ar) in ar5523_queue_init() argument
485 ar5523_dbg(ar, "setting up Tx queue\n"); in ar5523_queue_init()
495 return ar5523_cmd_write(ar, WDCMSG_SETUP_TX_QUEUE, &qinfo, in ar5523_queue_init()
499 static int ar5523_switch_chan(struct ar5523 *ar) in ar5523_switch_chan() argument
503 error = ar5523_set_chan(ar); in ar5523_switch_chan()
505 ar5523_err(ar, "could not set chan, error %d\n", error); in ar5523_switch_chan()
510 error = ar5523_reset_tx_queues(ar); in ar5523_switch_chan()
512 ar5523_err(ar, "could not reset Tx queues, error %d\n", in ar5523_switch_chan()
517 error = ar5523_queue_init(ar); in ar5523_switch_chan()
519 ar5523_err(ar, "could not init wme, error %d\n", error); in ar5523_switch_chan()
525 static void ar5523_rx_data_put(struct ar5523 *ar, in ar5523_rx_data_put() argument
529 spin_lock_irqsave(&ar->rx_data_list_lock, flags); in ar5523_rx_data_put()
530 list_move(&data->list, &ar->rx_data_free); in ar5523_rx_data_put()
531 spin_unlock_irqrestore(&ar->rx_data_list_lock, flags); in ar5523_rx_data_put()
537 struct ar5523 *ar = data->ar; in ar5523_data_rx_cb() local
540 struct ieee80211_hw *hw = ar->hw; in ar5523_data_rx_cb()
546 ar5523_dbg(ar, "%s\n", __func__); in ar5523_data_rx_cb()
550 ar5523_err(ar, "%s: USB err: %d\n", __func__, in ar5523_data_rx_cb()
556 ar5523_err(ar, "RX: wrong xfer size (usblen=%d)\n", usblen); in ar5523_data_rx_cb()
564 ar5523_dbg(ar, "RX: No final flag. s: %d f: %02x l: %d\n", in ar5523_data_rx_cb()
575 if (rxlen > ar->rxbufsz) { in ar5523_data_rx_cb()
576 ar5523_dbg(ar, "RX: Bad descriptor (len=%d)\n", in ar5523_data_rx_cb()
582 ar5523_dbg(ar, "RX: rxlen is 0\n"); in ar5523_data_rx_cb()
587 ar5523_dbg(ar, "Bad RX status (0x%x len = %d). Skip\n", in ar5523_data_rx_cb()
597 ar5523_dbg(ar, "eek, alignment workaround activated\n"); in ar5523_data_rx_cb()
619 ar5523_rx_data_put(ar, data); in ar5523_data_rx_cb()
620 if (atomic_inc_return(&ar->rx_data_free_cnt) >= in ar5523_data_rx_cb()
622 test_bit(AR5523_HW_UP, &ar->flags)) in ar5523_data_rx_cb()
623 queue_work(ar->wq, &ar->rx_refill_work); in ar5523_data_rx_cb()
628 struct ar5523 *ar = container_of(work, struct ar5523, rx_refill_work); in ar5523_rx_refill_work() local
633 ar5523_dbg(ar, "%s\n", __func__); in ar5523_rx_refill_work()
635 spin_lock_irqsave(&ar->rx_data_list_lock, flags); in ar5523_rx_refill_work()
637 if (!list_empty(&ar->rx_data_free)) in ar5523_rx_refill_work()
638 data = (struct ar5523_rx_data *) ar->rx_data_free.next; in ar5523_rx_refill_work()
641 spin_unlock_irqrestore(&ar->rx_data_list_lock, flags); in ar5523_rx_refill_work()
646 data->skb = alloc_skb(ar->rxbufsz, GFP_KERNEL); in ar5523_rx_refill_work()
648 ar5523_err(ar, "could not allocate rx skbuff\n"); in ar5523_rx_refill_work()
652 usb_fill_bulk_urb(data->urb, ar->dev, in ar5523_rx_refill_work()
653 ar5523_data_rx_pipe(ar->dev), data->skb->data, in ar5523_rx_refill_work()
654 ar->rxbufsz, ar5523_data_rx_cb, data); in ar5523_rx_refill_work()
656 spin_lock_irqsave(&ar->rx_data_list_lock, flags); in ar5523_rx_refill_work()
657 list_move(&data->list, &ar->rx_data_used); in ar5523_rx_refill_work()
658 spin_unlock_irqrestore(&ar->rx_data_list_lock, flags); in ar5523_rx_refill_work()
659 atomic_dec(&ar->rx_data_free_cnt); in ar5523_rx_refill_work()
665 ar5523_err(ar, "Err sending rx data urb %d\n", in ar5523_rx_refill_work()
667 ar5523_rx_data_put(ar, data); in ar5523_rx_refill_work()
668 atomic_inc(&ar->rx_data_free_cnt); in ar5523_rx_refill_work()
677 static void ar5523_cancel_rx_bufs(struct ar5523 *ar) in ar5523_cancel_rx_bufs() argument
683 spin_lock_irqsave(&ar->rx_data_list_lock, flags); in ar5523_cancel_rx_bufs()
684 if (!list_empty(&ar->rx_data_used)) in ar5523_cancel_rx_bufs()
685 data = (struct ar5523_rx_data *) ar->rx_data_used.next; in ar5523_cancel_rx_bufs()
688 spin_unlock_irqrestore(&ar->rx_data_list_lock, flags); in ar5523_cancel_rx_bufs()
694 list_move(&data->list, &ar->rx_data_free); in ar5523_cancel_rx_bufs()
695 atomic_inc(&ar->rx_data_free_cnt); in ar5523_cancel_rx_bufs()
699 static void ar5523_free_rx_bufs(struct ar5523 *ar) in ar5523_free_rx_bufs() argument
703 ar5523_cancel_rx_bufs(ar); in ar5523_free_rx_bufs()
704 while (!list_empty(&ar->rx_data_free)) { in ar5523_free_rx_bufs()
705 data = (struct ar5523_rx_data *) ar->rx_data_free.next; in ar5523_free_rx_bufs()
711 static int ar5523_alloc_rx_bufs(struct ar5523 *ar) in ar5523_alloc_rx_bufs() argument
716 struct ar5523_rx_data *data = &ar->rx_data[i]; in ar5523_alloc_rx_bufs()
718 data->ar = ar; in ar5523_alloc_rx_bufs()
722 list_add_tail(&data->list, &ar->rx_data_free); in ar5523_alloc_rx_bufs()
723 atomic_inc(&ar->rx_data_free_cnt); in ar5523_alloc_rx_bufs()
728 ar5523_free_rx_bufs(ar); in ar5523_alloc_rx_bufs()
732 static void ar5523_data_tx_pkt_put(struct ar5523 *ar) in ar5523_data_tx_pkt_put() argument
734 atomic_dec(&ar->tx_nr_total); in ar5523_data_tx_pkt_put()
735 if (!atomic_dec_return(&ar->tx_nr_pending)) { in ar5523_data_tx_pkt_put()
736 del_timer(&ar->tx_wd_timer); in ar5523_data_tx_pkt_put()
737 wake_up(&ar->tx_flush_waitq); in ar5523_data_tx_pkt_put()
740 if (atomic_read(&ar->tx_nr_total) < AR5523_TX_DATA_RESTART_COUNT) { in ar5523_data_tx_pkt_put()
741 ar5523_dbg(ar, "restart tx queue\n"); in ar5523_data_tx_pkt_put()
742 ieee80211_wake_queues(ar->hw); in ar5523_data_tx_pkt_put()
752 struct ar5523 *ar = data->ar; in ar5523_data_tx_cb() local
755 ar5523_dbg(ar, "data tx urb completed: %d\n", urb->status); in ar5523_data_tx_cb()
757 spin_lock_irqsave(&ar->tx_data_list_lock, flags); in ar5523_data_tx_cb()
759 spin_unlock_irqrestore(&ar->tx_data_list_lock, flags); in ar5523_data_tx_cb()
762 ar5523_dbg(ar, "%s: urb status: %d\n", __func__, urb->status); in ar5523_data_tx_cb()
763 ar5523_data_tx_pkt_put(ar); in ar5523_data_tx_cb()
764 ieee80211_free_txskb(ar->hw, skb); in ar5523_data_tx_cb()
767 ieee80211_tx_status_irqsafe(ar->hw, skb); in ar5523_data_tx_cb()
779 struct ar5523 *ar = hw->priv; in ar5523_tx() local
782 ar5523_dbg(ar, "tx called\n"); in ar5523_tx()
783 if (atomic_inc_return(&ar->tx_nr_total) >= AR5523_TX_DATA_COUNT) { in ar5523_tx()
784 ar5523_dbg(ar, "tx queue full\n"); in ar5523_tx()
785 ar5523_dbg(ar, "stop queues (tot %d pend %d)\n", in ar5523_tx()
786 atomic_read(&ar->tx_nr_total), in ar5523_tx()
787 atomic_read(&ar->tx_nr_pending)); in ar5523_tx()
791 spin_lock_irqsave(&ar->tx_data_list_lock, flags); in ar5523_tx()
792 list_add_tail(&data->list, &ar->tx_queue_pending); in ar5523_tx()
793 spin_unlock_irqrestore(&ar->tx_data_list_lock, flags); in ar5523_tx()
795 ieee80211_queue_work(ar->hw, &ar->tx_work); in ar5523_tx()
798 static void ar5523_tx_work_locked(struct ar5523 *ar) in ar5523_tx_work_locked() argument
813 ar5523_dbg(ar, "%s\n", __func__); in ar5523_tx_work_locked()
815 spin_lock_irqsave(&ar->tx_data_list_lock, flags); in ar5523_tx_work_locked()
816 if (!list_empty(&ar->tx_queue_pending)) { in ar5523_tx_work_locked()
818 ar->tx_queue_pending.next; in ar5523_tx_work_locked()
822 spin_unlock_irqrestore(&ar->tx_data_list_lock, flags); in ar5523_tx_work_locked()
836 ieee80211_free_txskb(ar->hw, skb); in ar5523_tx_work_locked()
840 data->ar = ar; in ar5523_tx_work_locked()
856 if (test_bit(AR5523_CONNECTED, &ar->flags)) in ar5523_tx_work_locked()
867 usb_fill_bulk_urb(urb, ar->dev, ar5523_data_tx_pipe(ar->dev), in ar5523_tx_work_locked()
870 spin_lock_irqsave(&ar->tx_data_list_lock, flags); in ar5523_tx_work_locked()
871 list_add_tail(&data->list, &ar->tx_queue_submitted); in ar5523_tx_work_locked()
872 spin_unlock_irqrestore(&ar->tx_data_list_lock, flags); in ar5523_tx_work_locked()
873 mod_timer(&ar->tx_wd_timer, jiffies + AR5523_TX_WD_TIMEOUT); in ar5523_tx_work_locked()
874 atomic_inc(&ar->tx_nr_pending); in ar5523_tx_work_locked()
876 ar5523_dbg(ar, "TX Frame (%d pending)\n", in ar5523_tx_work_locked()
877 atomic_read(&ar->tx_nr_pending)); in ar5523_tx_work_locked()
880 ar5523_err(ar, "error %d when submitting tx urb\n", in ar5523_tx_work_locked()
882 spin_lock_irqsave(&ar->tx_data_list_lock, flags); in ar5523_tx_work_locked()
884 spin_unlock_irqrestore(&ar->tx_data_list_lock, flags); in ar5523_tx_work_locked()
885 atomic_dec(&ar->tx_nr_pending); in ar5523_tx_work_locked()
886 ar5523_data_tx_pkt_put(ar); in ar5523_tx_work_locked()
888 ieee80211_free_txskb(ar->hw, skb); in ar5523_tx_work_locked()
895 struct ar5523 *ar = container_of(work, struct ar5523, tx_work); in ar5523_tx_work() local
897 ar5523_dbg(ar, "%s\n", __func__); in ar5523_tx_work()
898 mutex_lock(&ar->mutex); in ar5523_tx_work()
899 ar5523_tx_work_locked(ar); in ar5523_tx_work()
900 mutex_unlock(&ar->mutex); in ar5523_tx_work()
905 struct ar5523 *ar = from_timer(ar, t, tx_wd_timer); in ar5523_tx_wd_timer() local
907 ar5523_dbg(ar, "TX watchdog timer triggered\n"); in ar5523_tx_wd_timer()
908 ieee80211_queue_work(ar->hw, &ar->tx_wd_work); in ar5523_tx_wd_timer()
913 struct ar5523 *ar = container_of(work, struct ar5523, tx_wd_work); in ar5523_tx_wd_work() local
919 mutex_lock(&ar->mutex); in ar5523_tx_wd_work()
920 ar5523_err(ar, "TX queue stuck (tot %d pend %d)\n", in ar5523_tx_wd_work()
921 atomic_read(&ar->tx_nr_total), in ar5523_tx_wd_work()
922 atomic_read(&ar->tx_nr_pending)); in ar5523_tx_wd_work()
924 ar5523_err(ar, "Will restart dongle.\n"); in ar5523_tx_wd_work()
925 ar5523_cmd_write(ar, WDCMSG_TARGET_RESET, NULL, 0, 0); in ar5523_tx_wd_work()
926 mutex_unlock(&ar->mutex); in ar5523_tx_wd_work()
929 static void ar5523_flush_tx(struct ar5523 *ar) in ar5523_flush_tx() argument
931 ar5523_tx_work_locked(ar); in ar5523_flush_tx()
934 if (test_bit(AR5523_USB_DISCONNECTED, &ar->flags)) in ar5523_flush_tx()
936 if (!wait_event_timeout(ar->tx_flush_waitq, in ar5523_flush_tx()
937 !atomic_read(&ar->tx_nr_pending), AR5523_FLUSH_TIMEOUT)) in ar5523_flush_tx()
938 ar5523_err(ar, "flush timeout (tot %d pend %d)\n", in ar5523_flush_tx()
939 atomic_read(&ar->tx_nr_total), in ar5523_flush_tx()
940 atomic_read(&ar->tx_nr_pending)); in ar5523_flush_tx()
943 static void ar5523_free_tx_cmd(struct ar5523 *ar) in ar5523_free_tx_cmd() argument
945 struct ar5523_tx_cmd *cmd = &ar->tx_cmd; in ar5523_free_tx_cmd()
947 usb_free_coherent(ar->dev, AR5523_MAX_RXCMDSZ, cmd->buf_tx, in ar5523_free_tx_cmd()
952 static int ar5523_alloc_tx_cmd(struct ar5523 *ar) in ar5523_alloc_tx_cmd() argument
954 struct ar5523_tx_cmd *cmd = &ar->tx_cmd; in ar5523_alloc_tx_cmd()
956 cmd->ar = ar; in ar5523_alloc_tx_cmd()
962 cmd->buf_tx = usb_alloc_coherent(ar->dev, AR5523_MAX_TXCMDSZ, in ar5523_alloc_tx_cmd()
978 struct ar5523 *ar = container_of(work, struct ar5523, stat_work.work); in ar5523_stat_work() local
981 ar5523_dbg(ar, "%s\n", __func__); in ar5523_stat_work()
982 mutex_lock(&ar->mutex); in ar5523_stat_work()
988 error = ar5523_cmd_write(ar, WDCMSG_TARGET_GET_STATS, NULL, 0, 0); in ar5523_stat_work()
990 ar5523_err(ar, "could not query stats, error %d\n", error); in ar5523_stat_work()
991 mutex_unlock(&ar->mutex); in ar5523_stat_work()
992 ieee80211_queue_delayed_work(ar->hw, &ar->stat_work, HZ); in ar5523_stat_work()
1000 struct ar5523 *ar = hw->priv; in ar5523_start() local
1004 ar5523_dbg(ar, "start called\n"); in ar5523_start()
1006 mutex_lock(&ar->mutex); in ar5523_start()
1008 ar5523_cmd_write(ar, WDCMSG_BIND, &val, sizeof(val), 0); in ar5523_start()
1011 ar5523_config_multi(ar, CFG_MAC_ADDR, &ar->hw->wiphy->perm_addr, in ar5523_start()
1015 ar5523_config(ar, CFG_RATE_CONTROL_ENABLE, 0x00000001); in ar5523_start()
1016 ar5523_config(ar, CFG_DIVERSITY_CTL, 0x00000001); in ar5523_start()
1017 ar5523_config(ar, CFG_ABOLT, 0x0000003f); in ar5523_start()
1018 ar5523_config(ar, CFG_WME_ENABLED, 0x00000000); in ar5523_start()
1020 ar5523_config(ar, CFG_SERVICE_TYPE, 1); in ar5523_start()
1021 ar5523_config(ar, CFG_TP_SCALE, 0x00000000); in ar5523_start()
1022 ar5523_config(ar, CFG_TPC_HALF_DBM5, 0x0000003c); in ar5523_start()
1023 ar5523_config(ar, CFG_TPC_HALF_DBM2, 0x0000003c); in ar5523_start()
1024 ar5523_config(ar, CFG_OVERRD_TX_POWER, 0x00000000); in ar5523_start()
1025 ar5523_config(ar, CFG_GMODE_PROTECTION, 0x00000000); in ar5523_start()
1026 ar5523_config(ar, CFG_GMODE_PROTECT_RATE_INDEX, 0x00000003); in ar5523_start()
1027 ar5523_config(ar, CFG_PROTECTION_TYPE, 0x00000000); in ar5523_start()
1028 ar5523_config(ar, CFG_MODE_CTS, 0x00000002); in ar5523_start()
1030 error = ar5523_cmd_read(ar, WDCMSG_TARGET_START, NULL, 0, in ar5523_start()
1033 ar5523_dbg(ar, "could not start target, error %d\n", error); in ar5523_start()
1036 ar5523_dbg(ar, "WDCMSG_TARGET_START returns handle: 0x%x\n", in ar5523_start()
1039 ar5523_switch_chan(ar); in ar5523_start()
1042 ar5523_cmd_write(ar, WDCMSG_SET_PWR_MODE, &val, sizeof(val), 0); in ar5523_start()
1044 ar5523_cmd_write(ar, WDCMSG_RESET_KEY_CACHE, NULL, 0, 0); in ar5523_start()
1046 set_bit(AR5523_HW_UP, &ar->flags); in ar5523_start()
1047 queue_work(ar->wq, &ar->rx_refill_work); in ar5523_start()
1050 ar5523_set_rxfilter(ar, 0, UATH_FILTER_OP_INIT); in ar5523_start()
1051 ar5523_set_rxfilter(ar, in ar5523_start()
1056 ar5523_set_ledsteady(ar, UATH_LED_ACTIVITY, UATH_LED_ON); in ar5523_start()
1057 ar5523_dbg(ar, "start OK\n"); in ar5523_start()
1060 mutex_unlock(&ar->mutex); in ar5523_start()
1066 struct ar5523 *ar = hw->priv; in ar5523_stop() local
1068 ar5523_dbg(ar, "stop called\n"); in ar5523_stop()
1070 cancel_delayed_work_sync(&ar->stat_work); in ar5523_stop()
1071 mutex_lock(&ar->mutex); in ar5523_stop()
1072 clear_bit(AR5523_HW_UP, &ar->flags); in ar5523_stop()
1074 ar5523_set_ledsteady(ar, UATH_LED_LINK, UATH_LED_OFF); in ar5523_stop()
1075 ar5523_set_ledsteady(ar, UATH_LED_ACTIVITY, UATH_LED_OFF); in ar5523_stop()
1077 ar5523_cmd_write(ar, WDCMSG_TARGET_STOP, NULL, 0, 0); in ar5523_stop()
1079 del_timer_sync(&ar->tx_wd_timer); in ar5523_stop()
1080 cancel_work_sync(&ar->tx_wd_work); in ar5523_stop()
1081 cancel_work_sync(&ar->rx_refill_work); in ar5523_stop()
1082 ar5523_cancel_rx_bufs(ar); in ar5523_stop()
1083 mutex_unlock(&ar->mutex); in ar5523_stop()
1088 struct ar5523 *ar = hw->priv; in ar5523_set_rts_threshold() local
1091 ar5523_dbg(ar, "set_rts_threshold called\n"); in ar5523_set_rts_threshold()
1092 mutex_lock(&ar->mutex); in ar5523_set_rts_threshold()
1094 ret = ar5523_config(ar, CFG_USER_RTS_THRESHOLD, value); in ar5523_set_rts_threshold()
1096 mutex_unlock(&ar->mutex); in ar5523_set_rts_threshold()
1103 struct ar5523 *ar = hw->priv; in ar5523_flush() local
1105 ar5523_dbg(ar, "flush called\n"); in ar5523_flush()
1106 ar5523_flush_tx(ar); in ar5523_flush()
1112 struct ar5523 *ar = hw->priv; in ar5523_add_interface() local
1114 ar5523_dbg(ar, "add interface called\n"); in ar5523_add_interface()
1116 if (ar->vif) { in ar5523_add_interface()
1117 ar5523_dbg(ar, "invalid add_interface\n"); in ar5523_add_interface()
1123 ar->vif = vif; in ar5523_add_interface()
1134 struct ar5523 *ar = hw->priv; in ar5523_remove_interface() local
1136 ar5523_dbg(ar, "remove interface called\n"); in ar5523_remove_interface()
1137 ar->vif = NULL; in ar5523_remove_interface()
1142 struct ar5523 *ar = hw->priv; in ar5523_hwconfig() local
1144 ar5523_dbg(ar, "config called\n"); in ar5523_hwconfig()
1145 mutex_lock(&ar->mutex); in ar5523_hwconfig()
1147 ar5523_dbg(ar, "Do channel switch\n"); in ar5523_hwconfig()
1148 ar5523_flush_tx(ar); in ar5523_hwconfig()
1149 ar5523_switch_chan(ar); in ar5523_hwconfig()
1151 mutex_unlock(&ar->mutex); in ar5523_hwconfig()
1155 static int ar5523_get_wlan_mode(struct ar5523 *ar, in ar5523_get_wlan_mode() argument
1163 band = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band]; in ar5523_get_wlan_mode()
1164 sta = ieee80211_find_sta(ar->vif, bss_conf->bssid); in ar5523_get_wlan_mode()
1166 ar5523_info(ar, "STA not found!\n"); in ar5523_get_wlan_mode()
1169 sta_rate_set = sta->deflink.supp_rates[ar->hw->conf.chandef.chan->band]; in ar5523_get_wlan_mode()
1191 static void ar5523_create_rateset(struct ar5523 *ar, in ar5523_create_rateset() argument
1201 sta = ieee80211_find_sta(ar->vif, bss_conf->bssid); in ar5523_create_rateset()
1204 ar5523_info(ar, "STA not found. Cannot set rates\n"); in ar5523_create_rateset()
1207 sta_rate_set = sta->deflink.supp_rates[ar->hw->conf.chandef.chan->band]; in ar5523_create_rateset()
1209 ar5523_dbg(ar, "sta rate_set = %08x\n", sta_rate_set); in ar5523_create_rateset()
1211 band = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band]; in ar5523_create_rateset()
1214 ar5523_dbg(ar, "Considering rate %d : %d\n", in ar5523_create_rateset()
1229 static int ar5523_set_basic_rates(struct ar5523 *ar, in ar5523_set_basic_rates() argument
1237 ar5523_create_rateset(ar, bss, &rates.rateset, true); in ar5523_set_basic_rates()
1239 return ar5523_cmd_write(ar, WDCMSG_SET_BASIC_RATE, &rates, in ar5523_set_basic_rates()
1243 static int ar5523_create_connection(struct ar5523 *ar, in ar5523_create_connection() argument
1256 ar5523_create_rateset(ar, bss, &create.connattr.rateset, false); in ar5523_create_connection()
1258 wlan_mode = ar5523_get_wlan_mode(ar, bss); in ar5523_create_connection()
1261 return ar5523_cmd_write(ar, WDCMSG_CREATE_CONNECTION, &create, in ar5523_create_connection()
1265 static int ar5523_write_associd(struct ar5523 *ar, struct ieee80211_vif *vif) in ar5523_write_associd() argument
1275 return ar5523_cmd_write(ar, WDCMSG_WRITE_ASSOCID, &associd, in ar5523_write_associd()
1284 struct ar5523 *ar = hw->priv; in ar5523_bss_info_changed() local
1287 ar5523_dbg(ar, "bss_info_changed called\n"); in ar5523_bss_info_changed()
1288 mutex_lock(&ar->mutex); in ar5523_bss_info_changed()
1294 error = ar5523_create_connection(ar, vif, bss); in ar5523_bss_info_changed()
1296 ar5523_err(ar, "could not create connection\n"); in ar5523_bss_info_changed()
1300 error = ar5523_set_basic_rates(ar, bss); in ar5523_bss_info_changed()
1302 ar5523_err(ar, "could not set negotiated rate set\n"); in ar5523_bss_info_changed()
1306 error = ar5523_write_associd(ar, vif); in ar5523_bss_info_changed()
1308 ar5523_err(ar, "could not set association\n"); in ar5523_bss_info_changed()
1313 ar5523_set_ledsteady(ar, UATH_LED_LINK, UATH_LED_ON); in ar5523_bss_info_changed()
1314 set_bit(AR5523_CONNECTED, &ar->flags); in ar5523_bss_info_changed()
1315 ieee80211_queue_delayed_work(hw, &ar->stat_work, HZ); in ar5523_bss_info_changed()
1318 cancel_delayed_work(&ar->stat_work); in ar5523_bss_info_changed()
1319 clear_bit(AR5523_CONNECTED, &ar->flags); in ar5523_bss_info_changed()
1320 ar5523_set_ledsteady(ar, UATH_LED_LINK, UATH_LED_OFF); in ar5523_bss_info_changed()
1324 mutex_unlock(&ar->mutex); in ar5523_bss_info_changed()
1337 struct ar5523 *ar = hw->priv; in ar5523_configure_filter() local
1340 ar5523_dbg(ar, "configure_filter called\n"); in ar5523_configure_filter()
1341 mutex_lock(&ar->mutex); in ar5523_configure_filter()
1342 ar5523_flush_tx(ar); in ar5523_configure_filter()
1354 ar5523_set_rxfilter(ar, 0, UATH_FILTER_OP_INIT); in ar5523_configure_filter()
1355 ar5523_set_rxfilter(ar, filter, UATH_FILTER_OP_SET); in ar5523_configure_filter()
1357 mutex_unlock(&ar->mutex); in ar5523_configure_filter()
1374 static int ar5523_host_available(struct ar5523 *ar) in ar5523_host_available() argument
1383 return ar5523_cmd_read(ar, WDCMSG_HOST_AVAILABLE, in ar5523_host_available()
1387 static int ar5523_get_devstatus(struct ar5523 *ar) in ar5523_get_devstatus() argument
1393 error = ar5523_get_status(ar, ST_MAC_ADDR, macaddr, ETH_ALEN); in ar5523_get_devstatus()
1395 ar5523_err(ar, "could not read MAC address\n"); in ar5523_get_devstatus()
1399 SET_IEEE80211_PERM_ADDR(ar->hw, macaddr); in ar5523_get_devstatus()
1401 error = ar5523_get_status(ar, ST_SERIAL_NUMBER, in ar5523_get_devstatus()
1402 &ar->serial[0], sizeof(ar->serial)); in ar5523_get_devstatus()
1404 ar5523_err(ar, "could not read device serial number\n"); in ar5523_get_devstatus()
1412 static int ar5523_get_max_rxsz(struct ar5523 *ar) in ar5523_get_max_rxsz() argument
1418 error = ar5523_get_status(ar, ST_WDC_TRANSPORT_CHUNK_SIZE, &rxsize, in ar5523_get_max_rxsz()
1421 ar5523_err(ar, "could not read max RX size\n"); in ar5523_get_max_rxsz()
1425 ar->rxbufsz = be32_to_cpu(rxsize); in ar5523_get_max_rxsz()
1427 if (!ar->rxbufsz || ar->rxbufsz > AR5523_SANE_RXBUFSZ) { in ar5523_get_max_rxsz()
1428 ar5523_err(ar, "Bad rxbufsz from device. Using %d instead\n", in ar5523_get_max_rxsz()
1430 ar->rxbufsz = AR5523_SANE_RXBUFSZ; in ar5523_get_max_rxsz()
1433 ar5523_dbg(ar, "Max RX buf size: %d\n", ar->rxbufsz); in ar5523_get_max_rxsz()
1473 static int ar5523_init_modes(struct ar5523 *ar) in ar5523_init_modes() argument
1475 BUILD_BUG_ON(sizeof(ar->channels) != sizeof(ar5523_channels)); in ar5523_init_modes()
1476 BUILD_BUG_ON(sizeof(ar->rates) != sizeof(ar5523_rates)); in ar5523_init_modes()
1478 memcpy(ar->channels, ar5523_channels, sizeof(ar5523_channels)); in ar5523_init_modes()
1479 memcpy(ar->rates, ar5523_rates, sizeof(ar5523_rates)); in ar5523_init_modes()
1481 ar->band.band = NL80211_BAND_2GHZ; in ar5523_init_modes()
1482 ar->band.channels = ar->channels; in ar5523_init_modes()
1483 ar->band.n_channels = ARRAY_SIZE(ar5523_channels); in ar5523_init_modes()
1484 ar->band.bitrates = ar->rates; in ar5523_init_modes()
1485 ar->band.n_bitrates = ARRAY_SIZE(ar5523_rates); in ar5523_init_modes()
1486 ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = &ar->band; in ar5523_init_modes()
1590 struct ar5523 *ar; in ar5523_probe() local
1602 hw = ieee80211_alloc_hw(sizeof(*ar), &ar5523_ops); in ar5523_probe()
1607 ar = hw->priv; in ar5523_probe()
1608 ar->hw = hw; in ar5523_probe()
1609 ar->dev = dev; in ar5523_probe()
1610 mutex_init(&ar->mutex); in ar5523_probe()
1612 INIT_DELAYED_WORK(&ar->stat_work, ar5523_stat_work); in ar5523_probe()
1613 timer_setup(&ar->tx_wd_timer, ar5523_tx_wd_timer, 0); in ar5523_probe()
1614 INIT_WORK(&ar->tx_wd_work, ar5523_tx_wd_work); in ar5523_probe()
1615 INIT_WORK(&ar->tx_work, ar5523_tx_work); in ar5523_probe()
1616 INIT_LIST_HEAD(&ar->tx_queue_pending); in ar5523_probe()
1617 INIT_LIST_HEAD(&ar->tx_queue_submitted); in ar5523_probe()
1618 spin_lock_init(&ar->tx_data_list_lock); in ar5523_probe()
1619 atomic_set(&ar->tx_nr_total, 0); in ar5523_probe()
1620 atomic_set(&ar->tx_nr_pending, 0); in ar5523_probe()
1621 init_waitqueue_head(&ar->tx_flush_waitq); in ar5523_probe()
1623 atomic_set(&ar->rx_data_free_cnt, 0); in ar5523_probe()
1624 INIT_WORK(&ar->rx_refill_work, ar5523_rx_refill_work); in ar5523_probe()
1625 INIT_LIST_HEAD(&ar->rx_data_free); in ar5523_probe()
1626 INIT_LIST_HEAD(&ar->rx_data_used); in ar5523_probe()
1627 spin_lock_init(&ar->rx_data_list_lock); in ar5523_probe()
1629 ar->wq = create_singlethread_workqueue("ar5523"); in ar5523_probe()
1630 if (!ar->wq) { in ar5523_probe()
1631 ar5523_err(ar, "Could not create wq\n"); in ar5523_probe()
1635 error = ar5523_alloc_rx_bufs(ar); in ar5523_probe()
1637 ar5523_err(ar, "Could not allocate rx buffers\n"); in ar5523_probe()
1641 error = ar5523_alloc_rx_cmd(ar); in ar5523_probe()
1643 ar5523_err(ar, "Could not allocate rx command buffers\n"); in ar5523_probe()
1647 error = ar5523_alloc_tx_cmd(ar); in ar5523_probe()
1649 ar5523_err(ar, "Could not allocate tx command buffers\n"); in ar5523_probe()
1653 error = ar5523_submit_rx_cmd(ar); in ar5523_probe()
1655 ar5523_err(ar, "Failed to submit rx cmd\n"); in ar5523_probe()
1662 error = ar5523_host_available(ar); in ar5523_probe()
1664 ar5523_err(ar, "could not initialize adapter\n"); in ar5523_probe()
1668 error = ar5523_get_max_rxsz(ar); in ar5523_probe()
1670 ar5523_err(ar, "could not get caps from adapter\n"); in ar5523_probe()
1674 error = ar5523_get_devcap(ar); in ar5523_probe()
1676 ar5523_err(ar, "could not get caps from adapter\n"); in ar5523_probe()
1680 error = ar5523_get_devstatus(ar); in ar5523_probe()
1682 ar5523_err(ar, "could not get device status\n"); in ar5523_probe()
1686 ar5523_info(ar, "MAC/BBP AR5523, RF AR%c112\n", in ar5523_probe()
1689 ar->vif = NULL; in ar5523_probe()
1698 error = ar5523_init_modes(ar); in ar5523_probe()
1708 ar5523_err(ar, "could not register device\n"); in ar5523_probe()
1712 ar5523_info(ar, "Found and initialized AR5523 device\n"); in ar5523_probe()
1716 ar5523_cancel_rx_cmd(ar); in ar5523_probe()
1718 ar5523_free_tx_cmd(ar); in ar5523_probe()
1720 ar5523_free_rx_cmd(ar); in ar5523_probe()
1722 ar5523_free_rx_bufs(ar); in ar5523_probe()
1724 destroy_workqueue(ar->wq); in ar5523_probe()
1734 struct ar5523 *ar = hw->priv; in ar5523_disconnect() local
1736 ar5523_dbg(ar, "detaching\n"); in ar5523_disconnect()
1737 set_bit(AR5523_USB_DISCONNECTED, &ar->flags); in ar5523_disconnect()
1741 ar5523_cancel_rx_cmd(ar); in ar5523_disconnect()
1742 ar5523_free_tx_cmd(ar); in ar5523_disconnect()
1743 ar5523_free_rx_cmd(ar); in ar5523_disconnect()
1744 ar5523_free_rx_bufs(ar); in ar5523_disconnect()
1746 destroy_workqueue(ar->wq); in ar5523_disconnect()