2 * carl9170user - userspace testing utility for ar9170 devices
4 * xmit - related functions
6 * Copyright 2009, 2010 Christian Lamparter <chunkeey@googlemail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
39 #include "ieee80211.h"
42 struct frame *carlu_alloc_frame(struct carlu *ar, unsigned int size)
45 unsigned int total_len;
47 total_len = ar->extra_headroom + sizeof(struct _carl9170_tx_superframe) + size;
49 tmp = frame_alloc(total_len);
53 frame_reserve(tmp, sizeof(struct _carl9170_tx_superframe) + ar->extra_headroom);
60 static int carlu_alloc_dev_mem(struct carlu *ar,
63 struct _carl9170_tx_superframe *txp = (void *)frame->data;
64 unsigned int len, chunks;
66 len = roundup(frame->len, ar->dma_chunk_size);
67 chunks = len / ar->dma_chunk_size;
69 SDL_mutexP(ar->mem_lock);
70 if (ar->tx_pending >= ar->dma_chunks ||
71 ar->used_dma_chunks + chunks >= ar->dma_chunks) {
72 SDL_mutexV(ar->mem_lock);
76 ar->used_dma_chunks += chunks;
78 txp->s.cookie = ar->cookie++;
79 SDL_mutexV(ar->mem_lock);
84 static void carlu_free_dev_mem(struct carlu *ar,
87 struct _carl9170_tx_superframe *txp = (void *)frame->data;
88 unsigned int len, chunks;
90 len = roundup(frame->len, ar->dma_chunk_size);
91 chunks = len / ar->dma_chunk_size;
93 SDL_mutexP(ar->mem_lock);
94 ar->used_dma_chunks -= chunks;
96 SDL_mutexV(ar->mem_lock);
99 void carlu_free_frame(struct carlu *ar __unused,
105 static struct frame *carlu_find_frame(struct carlu *ar,
106 unsigned int queue, uint8_t cookie)
108 struct frame *frame = NULL;
110 BUG_ON(queue >= __AR9170_NUM_TXQ);
111 BUG_ON(SDL_mutexP(ar->tx_sent_queue[queue].lock) != 0);
112 FRAME_WALK(frame, &ar->tx_sent_queue[queue]) {
113 struct _carl9170_tx_superframe *super;
115 super = (void *) frame->data;
116 if (super->s.cookie == cookie) {
117 __frame_unlink(&ar->tx_sent_queue[queue], frame);
118 SDL_mutexV(ar->tx_sent_queue[queue].lock);
122 SDL_mutexV(ar->tx_sent_queue[queue].lock);
127 static void carlu_tx_fb_cb(struct carlu *ar,
131 ar->tx_fb_cb(ar, frame);
133 carlu_free_frame(ar, frame);
137 void carlu_tx_feedback(struct carlu *ar,
138 struct carl9170_rsp *cmd)
140 unsigned int i, n, k;
142 struct carlu_tx_info *tx_info;
146 for (i = 0; i < n; i++) {
147 frame = carlu_find_frame(ar, cmd->tx_status[i].queue,
148 cmd->tx_status[i].cookie);
150 carlu_free_dev_mem(ar, frame);
151 tx_info = get_tx_info(frame);
153 k = cmd->tx_status[i].rix;
154 tx_info->rates[k].cnt = cmd->tx_status[i].tries;
155 for (k++; k < CARL9170_TX_MAX_RATES; k++) {
156 tx_info->rates[k].rix = -1;
157 tx_info->rates[k].cnt = -1;
160 carlu_tx_fb_cb(ar, frame);
162 err("Found no frame for cookie %d.\n",
163 cmd->tx_status[i].cookie);
168 int carlu_tx(struct carlu *ar, struct frame *frame)
170 struct _carl9170_tx_superframe *txp;
171 unsigned int len, queue;
176 txp = (void *) frame_push(frame, sizeof(struct _carl9170_tx_superframe));
181 err = carlu_alloc_dev_mem(ar, frame);
185 txp->s.len = cpu_to_le16(frame->len);
187 queue = ar9170_qmap[frame->queue % ARRAY_SIZE(ar9170_qmap)];
189 SET_VAL(CARL9170_TX_SUPER_MISC_QUEUE, txp->s.misc, queue);
191 txp->f.length = len + FCS_LEN; /* + I(C)V_LEN */
193 txp->f.mac_control = cpu_to_le16(AR9170_TX_MAC_HW_DURATION |
194 AR9170_TX_MAC_BACKOFF);
195 txp->f.mac_control |= cpu_to_le16(queue << AR9170_TX_MAC_QOS_S);
197 txp->f.phy_control = cpu_to_le32(AR9170_TX_PHY_MOD_CCK | AR9170_TX_PHY_BW_20MHZ |
198 ((17 * 2) << AR9170_TX_PHY_TX_PWR_S) |
199 (AR9170_TX_PHY_TXCHAIN_1 << AR9170_TX_PHY_TXCHAIN_S) |
200 (11 << AR9170_TX_PHY_MCS_S));
202 frame_queue_tail(&ar->tx_sent_queue[queue], frame);
203 carlusb_tx(ar, frame);
207 frame_pull(frame, sizeof(struct _carl9170_tx_superframe));