2 * carl9170 firmware - used by the ar9170 wireless device
4 * Host interface routines
6 * Copyright (c) 2000-2005 ZyDAS Technology Corporation
7 * Copyright (c) 2007-2009 Atheros Communications, Inc.
8 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
9 * Copyright 2009-2011 Christian Lamparter <chunkeey@googlemail.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 static bool length_check(struct dma_desc *desc)
33 volatile struct carl9170_tx_superframe *super = __get_super(desc);
35 if (unlikely(desc->totalLen < sizeof(struct carl9170_tx_superdesc)))
39 * check if the DMA is complete, or clipped.
41 * NB: The hardware aligns the descriptor length to
42 * a 4 byte boundary. This makes the direct comparison
43 * difficult, or unnecessary complex for a hot-path.
45 if (unlikely(super->s.len > desc->totalLen))
51 static void handle_download(void)
53 struct dma_desc *desc;
56 * Under normal conditions, all completed descs should have
57 * the AR9170_OWN_BITS_SE status flag set.
58 * However there seems to be a undocumented case where the flag
59 * is _SW ( handle_download_exception )
62 for_each_desc_not_bits(desc, &fw.pta.down_queue, AR9170_OWN_BITS_HW) {
63 if (unlikely((length_check(desc) == false))) {
65 * There is no easy way of telling what was lost.
67 * Therefore we just reclaim the data.
68 * The driver has to have some sort frame
72 wlan_tx_complete(__get_super(desc), false);
73 dma_reclaim(&fw.pta.down_queue, desc);
80 #ifdef CONFIG_CARL9170FW_DEBUG_LED_HEARTBEAT
81 xorl(AR9170_GPIO_REG_PORT_DATA, 2);
82 #endif /* CONFIG_CARL9170FW_DEBUG_LED_HEARTBEAT */
85 static void handle_upload(void)
87 struct dma_desc *desc;
89 for_each_desc_not_bits(desc, &fw.pta.up_queue, AR9170_OWN_BITS_HW) {
93 * DO NOT compare the descriptor addresses.
95 if (DESC_PAYLOAD(desc) == (void *) &dma_mem.reserved.rsp) {
96 fw.usb.int_desc = desc;
97 fw.usb.int_desc_available = 1;
99 dma_reclaim(&fw.wlan.rx_queue, desc);
100 wlan_trigger(AR9170_DMA_TRIGGER_RXQ);
104 #ifdef CONFIG_CARL9170FW_DEBUG_LED_HEARTBEAT
105 xorl(AR9170_GPIO_REG_PORT_DATA, 2);
106 #endif /* CONFIG_CARL9170FW_DEBUG_LED_HEARTBEAT */
109 static void handle_download_exception(void)
111 struct dma_desc *desc, *target;
113 /* actually, the queue should be stopped by now? */
114 usb_stop_down_queue();
116 target = (void *)((get(AR9170_PTA_REG_DN_CURR_ADDRH) << 16) |
117 get(AR9170_PTA_REG_DN_CURR_ADDRL));
120 * Put "forgotten" packets from the head of the queue, back
121 * to the current position
123 __while_desc_bits(desc, &fw.pta.down_queue, AR9170_OWN_BITS_HW) {
127 dma_reclaim(&fw.pta.down_queue,
128 dma_unlink_head(&fw.pta.down_queue));
131 __for_each_desc_continue(desc, &fw.pta.down_queue) {
132 if ((desc->status & AR9170_OWN_BITS) == AR9170_OWN_BITS_SW)
133 dma_fix_downqueue(desc);
137 usb_start_down_queue();
142 /* handle interrupts from DMA chip */
143 void handle_host_interface(void)
147 pta_int = get(AR9170_PTA_REG_INT_FLAG);
149 #define HANDLER(intr, flag, func) \
151 if ((intr & flag) != 0) { \
156 HANDLER(pta_int, AR9170_PTA_INT_FLAG_DN, handle_download);
158 HANDLER(pta_int, AR9170_PTA_INT_FLAG_UP, handle_upload);
160 /* This is just guesswork and MAGIC */
161 pta_int = get(AR9170_PTA_REG_DMA_STATUS);
162 HANDLER(pta_int, 0x1, handle_download_exception);