2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted (subject to the limitations in the
7 * disclaimer below) provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
17 * * Neither the name of Qualcomm Atheros nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22 * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <adf_os_types.h>
37 #include <adf_os_pci.h>
38 #include <adf_os_dma.h>
39 #include <adf_os_timer.h>
40 #include <adf_os_lock.h>
41 #include <adf_os_io.h>
42 #include <adf_os_mem.h>
43 #include <adf_os_util.h>
44 #include <adf_os_stdtypes.h>
45 #include <adf_os_defer.h>
46 #include <adf_os_atomic.h>
49 #include <adf_net_wcmd.h>
50 #include <adf_os_irq.h>
52 #include <if_ath_pci.h>
54 #include "ieee80211_var.h"
55 #include "if_athrate.h"
56 #include "if_athvar.h"
60 #include "ah_internal.h"
62 static a_int32_t ath_numrxbufs = -1;
63 static a_int32_t ath_numrxdescs = -1;
65 #if defined(PROJECT_MAGPIE)
66 uint32_t *init_htc_handle = 0;
69 #define RX_ENDPOINT_ID 3
70 #define ATH_CABQ_HANDLING_THRESHOLD 9000
74 void owl_tgt_tx_tasklet(TQUEUE_ARG data);
75 static void ath_tgt_send_beacon(struct ath_softc_tgt *sc,adf_nbuf_t bc_hdr,adf_nbuf_t nbuf,HTC_ENDPOINT_ID EndPt);
76 static void ath_hal_reg_write_tgt(void *Context, A_UINT16 Command, A_UINT16 SeqNo, A_UINT8 *data, a_int32_t datalen);
77 static void ath_hal_reg_rmw_tgt(void *Context, A_UINT16 Command, A_UINT16 SeqNo, A_UINT8 *data, a_int32_t datalen);
78 extern struct ath_tx_buf* ath_tgt_tx_prepare(struct ath_softc_tgt *sc, adf_nbuf_t skb, ath_data_hdr_t *dh);
79 extern void ath_tgt_send_mgt(struct ath_softc_tgt *sc,adf_nbuf_t mgt_hdr, adf_nbuf_t skb,HTC_ENDPOINT_ID EndPt);
80 extern HAL_BOOL ath_hal_wait(struct ath_hal *ah, a_uint32_t reg, a_uint32_t mask, a_uint32_t val);
81 extern void owltgt_tx_processq(struct ath_softc_tgt *sc, struct ath_txq *txq, owl_txq_state_t txqstate);
82 void owl_tgt_node_init(struct ath_node_target * an);
83 void ath_tgt_tx_sched_normal(struct ath_softc_tgt *sc, struct ath_buf *bf);
84 void ath_tgt_tx_sched_nonaggr(struct ath_softc_tgt *sc,struct ath_buf * bf_host);
87 * Extend a 32 bit TSF to nearest 64 bit TSF value.
88 * When the adapter is a STATION, its local TSF is periodically modified by
89 * the hardware to match the BSS TSF (as received in beacon packets), and
90 * rstamp may appear to be from the future or from the past (with reference
91 * to the current local TSF) because of jitter. This is mostly noticable in
92 * highly congested channels. The code uses signed modulo arithmetic to
93 * handle both past/future cases and signed-extension to avoid branches.
95 * extend(0x0000001200000004, 0x00000006) == 0x0000001200000006
96 * extend(0x0000001200000004, 0x00000002) == 0x0000001200000002
97 * extend(0x0000001200000004, 0xfffffffe) == 0x00000011fffffffe ! tsfhigh--
98 * extend(0x000000127ffffffe, 0x80000002) == 0x0000001280000002
99 * extend(0x0000001280000002, 0x7ffffffe) == 0x000000127ffffffe
100 * extend(0x00000012fffffffc, 0xfffffffe) == 0x00000012fffffffe
101 * extend(0x00000012fffffffc, 0xfffffffa) == 0x00000012fffffffa
102 * extend(0x00000012fffffffc, 0x00000002) == 0x0000001300000002 ! tsfhigh++
104 static u_int64_t ath_extend_tsf(struct ath_softc_tgt *sc, u_int32_t rstamp)
106 struct ath_hal *ah = sc->sc_ah;
109 a_int64_t tsf_delta; /* signed int64 */
111 tsf = ah->ah_getTsf64(ah);
112 tsf_low = tsf & 0xffffffffUL;
114 tsf_delta = (a_int32_t)((rstamp - tsf_low) & 0xffffffffUL);
116 return (tsf + (u_int64_t)tsf_delta);
119 static a_int32_t ath_rate_setup(struct ath_softc_tgt *sc, a_uint32_t mode)
121 struct ath_hal *ah = sc->sc_ah;
122 const HAL_RATE_TABLE *rt;
125 case IEEE80211_MODE_11NA:
126 sc->sc_rates[mode] = ah->ah_getRateTable(ah, HAL_MODE_11NA);
128 case IEEE80211_MODE_11NG:
129 sc->sc_rates[mode] = ah->ah_getRateTable(ah, HAL_MODE_11NG);
134 rt = sc->sc_rates[mode];
141 static void ath_setcurmode(struct ath_softc_tgt *sc,
142 enum ieee80211_phymode mode)
144 const HAL_RATE_TABLE *rt;
147 adf_os_mem_set(sc->sc_rixmap, 0xff, sizeof(sc->sc_rixmap));
149 rt = sc->sc_rates[mode];
150 adf_os_assert(rt != NULL);
152 for (i = 0; i < rt->rateCount; i++) {
153 sc->sc_rixmap[rt->info[i].rateCode] = i;
156 sc->sc_currates = rt;
157 sc->sc_curmode = mode;
158 sc->sc_protrix = ((mode == IEEE80211_MODE_11NG) ? 3 : 0);
162 void wmi_event(wmi_handle_t handle, WMI_EVENT_ID evt_id,
163 void *buffer, a_int32_t Length)
165 adf_nbuf_t netbuf = ADF_NBUF_NULL;
168 netbuf = WMI_AllocEvent(handle, WMI_EVT_CLASS_CMD_EVENT,
169 sizeof(WMI_CMD_HDR) + Length);
171 if (netbuf == ADF_NBUF_NULL) {
172 adf_os_print("Buf null\n");
176 if (buffer != NULL && Length != 0 && Length < WMI_SVC_MAX_BUFFERED_EVENT_SIZE) {
177 pData = adf_nbuf_put_tail(netbuf, Length);
178 adf_os_mem_copy(pData, buffer, Length);
181 WMI_SendEvent(handle, netbuf, evt_id, 0, Length);
184 void wmi_cmd_rsp(void *pContext, WMI_COMMAND_ID cmd_id, A_UINT16 SeqNo,
185 void *buffer, a_int32_t Length)
187 adf_nbuf_t netbuf = ADF_NBUF_NULL;
190 netbuf = WMI_AllocEvent(pContext, WMI_EVT_CLASS_CMD_REPLY,
191 sizeof(WMI_CMD_HDR) + Length);
193 if (netbuf == ADF_NBUF_NULL) {
198 if (Length != 0 && buffer != NULL) {
199 pData = (A_UINT8 *)adf_nbuf_put_tail(netbuf, Length);
200 adf_os_mem_copy(pData, buffer, Length);
203 WMI_SendEvent(pContext, netbuf, cmd_id, SeqNo, Length);
206 static void ath_node_vdelete_tgt(struct ath_softc_tgt *sc, a_uint8_t vap_index)
210 for (i = 0; i < TARGET_NODE_MAX; i++) {
211 if(sc->sc_sta[i].ni.ni_vapindex == vap_index)
212 sc->sc_sta[i].an_valid = 0;
216 a_uint8_t ath_get_minrateidx(struct ath_softc_tgt *sc, struct ath_vap_target *avp)
218 if (sc->sc_curmode == IEEE80211_MODE_11NG)
219 return avp->av_minrateidx[0];
220 else if (sc->sc_curmode == IEEE80211_MODE_11NA)
221 return avp->av_minrateidx[1];
230 static adf_nbuf_t ath_alloc_skb_align(struct ath_softc_tgt *sc,
231 a_uint32_t size, a_uint32_t align)
235 skb = BUF_Pool_alloc_buf_align(sc->pool_handle, POOL_ID_WLAN_RX_BUF,
236 RX_HEADER_SPACE, align);
240 static a_int32_t ath_rxdesc_init(struct ath_softc_tgt *sc, struct ath_rx_desc *ds)
242 struct ath_hal *ah = sc->sc_ah;
243 struct ath_rx_desc *ds_held;
247 if (!sc->sc_rxdesc_held) {
248 sc->sc_rxdesc_held = ds;
252 ds_held = sc->sc_rxdesc_held;
253 sc->sc_rxdesc_held = ds;
256 if (ds->ds_nbuf == ADF_NBUF_NULL) {
257 ds->ds_nbuf = ath_alloc_skb_align(sc, sc->sc_rxbufsize, sc->sc_cachelsz);
258 if (ds->ds_nbuf == ADF_NBUF_NULL) {
259 sc->sc_rxdesc_held = ds;
260 sc->sc_rx_stats.ast_rx_nobuf++;
263 adf_nbuf_map(sc->sc_dev, ds->ds_dmap, ds->ds_nbuf, ADF_OS_DMA_FROM_DEVICE);
264 adf_nbuf_dmamap_info(ds->ds_dmap, &ds->ds_dmap_info);
265 ds->ds_data = ds->ds_dmap_info.dma_segs[0].paddr;
269 adf_nbuf_peek_header(ds->ds_nbuf, &anbdata, &anblen);
271 ah->ah_setupRxDesc(ds, adf_nbuf_tailroom(ds->ds_nbuf), 0);
273 if (sc->sc_rxlink == NULL) {
274 ah->ah_setRxDP(ah, ds->ds_daddr);
277 *sc->sc_rxlink = ds->ds_daddr;
279 sc->sc_rxlink = &ds->ds_link;
280 ah->ah_enableReceive(ah);
285 static void ath_rx_complete(struct ath_softc_tgt *sc, adf_nbuf_t buf)
287 struct ath_rx_desc *ds;
289 adf_nbuf_queue_t nbuf_head;
291 adf_nbuf_split_to_frag(buf, &nbuf_head);
292 ds = asf_tailq_first(&sc->sc_rxdesc_idle);
295 struct ath_rx_desc *ds_tmp;
296 buf_tmp = adf_nbuf_queue_remove(&nbuf_head);
298 if (buf_tmp == NULL) {
302 BUF_Pool_free_buf(sc->pool_handle, POOL_ID_WLAN_RX_BUF, buf_tmp);
305 ds = asf_tailq_next(ds, ds_list);
307 ath_rxdesc_init(sc, ds_tmp);
309 asf_tailq_remove(&sc->sc_rxdesc_idle, ds_tmp, ds_list);
310 asf_tailq_insert_tail(&sc->sc_rxdesc, ds_tmp, ds_list);
314 static void tgt_HTCSendCompleteHandler(HTC_ENDPOINT_ID Endpt, adf_nbuf_t buf, void *ServiceCtx)
316 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)ServiceCtx;
318 if (Endpt == RX_ENDPOINT_ID) {
319 sc->sc_rx_stats.ast_rx_done++;
320 ath_rx_complete(sc, buf);
324 static void ath_uapsd_processtriggers(struct ath_softc_tgt *sc)
326 struct ath_hal *ah = sc->sc_ah;
327 struct ath_rx_buf *bf = NULL;
328 struct ath_rx_desc *ds, *ds_head, *ds_tail, *ds_tmp;
331 a_uint16_t frame_len = 0;
333 #define PA2DESC(_sc, _pa) \
334 ((struct ath_desc *)((caddr_t)(_sc)->sc_rxdma.dd_desc + \
335 ((_pa) - (_sc)->sc_rxdma.dd_desc_paddr)))
337 bf = asf_tailq_first(&sc->sc_rxbuf);
339 ds = asf_tailq_first(&sc->sc_rxdesc);
345 if (cnt == ath_numrxbufs - 1) {
346 adf_os_print("VERY LONG PACKET!!!!!\n");
350 struct ath_rx_desc *ds_rmv;
351 adf_nbuf_unmap(sc->sc_dev, ds_tmp->ds_dmap, ADF_OS_DMA_FROM_DEVICE);
353 ds_tmp = asf_tailq_next(ds_tmp, ds_list);
355 if (ds_tmp == NULL) {
356 adf_os_print("ds_tmp is NULL\n");
360 BUF_Pool_free_buf(sc->pool_handle, POOL_ID_WLAN_RX_BUF, ds_rmv->ds_nbuf);
361 ds_rmv->ds_nbuf = ADF_NBUF_NULL;
363 if (ath_rxdesc_init(sc, ds_rmv) == 0) {
364 asf_tailq_remove(&sc->sc_rxdesc, ds_rmv, ds_list);
365 asf_tailq_insert_tail(&sc->sc_rxdesc, ds_rmv, ds_list);
368 asf_tailq_remove(&sc->sc_rxdesc, ds_rmv, ds_list);
369 asf_tailq_insert_tail(&sc->sc_rxdesc_idle, ds_rmv, ds_list);
372 if (ds_rmv == ds_tail) {
379 if (ds->ds_link == 0) {
383 if (bf->bf_status & ATH_BUFSTATUS_DONE) {
387 retval = ah->ah_procRxDescFast(ah, ds, ds->ds_daddr,
388 PA2DESC(sc, ds->ds_link), &bf->bf_rx_status);
389 if (HAL_EINPROGRESS == retval) {
393 if (adf_nbuf_len(ds->ds_nbuf) == 0) {
394 adf_nbuf_put_tail(ds->ds_nbuf, bf->bf_rx_status.rs_datalen);
397 frame_len += bf->bf_rx_status.rs_datalen;
399 if (bf->bf_rx_status.rs_more == 0) {
400 adf_nbuf_queue_t nbuf_head;
401 adf_nbuf_queue_init(&nbuf_head);
406 ds = asf_tailq_next(ds, ds_list);
409 ds_head = asf_tailq_next(ds_tail, ds_list);
412 struct ath_rx_desc *ds_rmv;
414 adf_nbuf_unmap(sc->sc_dev, ds_tmp->ds_dmap, ADF_OS_DMA_FROM_DEVICE);
415 adf_nbuf_queue_add(&nbuf_head, ds_tmp->ds_nbuf);
416 ds_tmp->ds_nbuf = ADF_NBUF_NULL;
419 ds_tmp = asf_tailq_next(ds_tmp, ds_list);
420 if (ds_tmp == NULL) {
424 if (ath_rxdesc_init(sc, ds_rmv) == 0) {
425 asf_tailq_remove(&sc->sc_rxdesc, ds_rmv, ds_list);
426 asf_tailq_insert_tail(&sc->sc_rxdesc, ds_rmv, ds_list);
428 asf_tailq_remove(&sc->sc_rxdesc, ds_rmv, ds_list);
429 asf_tailq_insert_tail(&sc->sc_rxdesc_idle, ds_rmv, ds_list);
432 if (ds_rmv == ds_tail) {
438 bf->bf_rx_status.rs_datalen = frame_len;
441 bf->bf_skb = adf_nbuf_create_frm_frag(&nbuf_head);
443 bf->bf_status |= ATH_BUFSTATUS_DONE;
445 bf = (struct ath_rx_buf *)asf_tailq_next(bf, bf_list);
448 ds = asf_tailq_next(ds, ds_list);
455 static a_int32_t ath_startrecv(struct ath_softc_tgt *sc)
457 struct ath_hal *ah = sc->sc_ah;
458 struct ath_rx_desc *ds;
460 sc->sc_rxbufsize = 1024+512+128;
461 sc->sc_rxlink = NULL;
463 sc->sc_rxdesc_held = NULL;
465 asf_tailq_foreach(ds, &sc->sc_rxdesc, ds_list) {
466 a_int32_t error = ath_rxdesc_init(sc, ds);
472 ds = asf_tailq_first(&sc->sc_rxdesc);
473 ah->ah_setRxDP(ah, ds->ds_daddr);
478 static void ath_tgt_rx_tasklet(TQUEUE_ARG data)
480 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)data;
481 struct ath_rx_buf *bf = NULL;
482 struct ath_hal *ah = sc->sc_ah;
483 struct rx_frame_header *rxhdr;
484 struct ath_rx_status *rxstats;
485 adf_nbuf_t skb = ADF_NBUF_NULL;
488 bf = asf_tailq_first(&sc->sc_rxbuf);
493 if (!(bf->bf_status & ATH_BUFSTATUS_DONE)) {
502 asf_tailq_remove(&sc->sc_rxbuf, bf, bf_list);
506 rxhdr = (struct rx_frame_header *)adf_nbuf_push_head(skb,
507 sizeof(struct rx_frame_header));
508 rxstats = (struct ath_rx_status *)(&rxhdr->rx_stats[0]);
509 adf_os_mem_copy(rxstats, &(bf->bf_rx_status),
510 sizeof(struct ath_rx_status));
512 rxstats->rs_tstamp = ath_extend_tsf(sc, (u_int32_t)rxstats->rs_tstamp);
514 HTC_SendMsg(sc->tgt_htc_handle, RX_ENDPOINT_ID, skb);
515 sc->sc_rx_stats.ast_rx_send++;
517 bf->bf_status &= ~ATH_BUFSTATUS_DONE;
518 asf_tailq_insert_tail(&sc->sc_rxbuf, bf, bf_list);
522 sc->sc_imask |= HAL_INT_RX;
523 ah->ah_setInterrupts(ah, sc->sc_imask);
526 /*******************/
527 /* Beacon Handling */
528 /*******************/
531 * Setup the beacon frame for transmit.
532 * FIXME: Short Preamble.
534 static void ath_beacon_setup(struct ath_softc_tgt *sc,
535 struct ath_tx_buf *bf,
536 struct ath_vap_target *avp)
538 adf_nbuf_t skb = bf->bf_skb;
539 struct ath_hal *ah = sc->sc_ah;
540 struct ath_tx_desc *ds;
542 const HAL_RATE_TABLE *rt;
544 HAL_11N_RATE_SERIES series[4] = {{ 0 }};
546 flags = HAL_TXDESC_NOACK;
550 ds->ds_data = bf->bf_dmamap_info.dma_segs[0].paddr;
552 rix = ath_get_minrateidx(sc, avp);
553 rt = sc->sc_currates;
554 rate = rt->info[rix].rateCode;
556 ah->ah_setupTxDesc(ds
557 , adf_nbuf_len(skb) + IEEE80211_CRC_LEN
558 , sizeof(struct ieee80211_frame)
559 , HAL_PKT_TYPE_BEACON
562 , HAL_TXKEYIX_INVALID
568 , asf_roundup(adf_nbuf_len(skb), 4)
574 series[0].Rate = rate;
575 series[0].ChSel = sc->sc_ic.ic_tx_chainmask;
576 series[0].RateFlags = 0;
577 ah->ah_set11nRateScenario(ds, 0, 0, series, 4, 0);
580 static void ath_tgt_send_beacon(struct ath_softc_tgt *sc, adf_nbuf_t bc_hdr,
581 adf_nbuf_t nbuf, HTC_ENDPOINT_ID EndPt)
583 struct ath_hal *ah = sc->sc_ah;
584 struct ath_tx_buf *bf;
585 a_uint8_t vap_index, *anbdata;
586 ath_beacon_hdr_t *bhdr = NULL;
590 adf_nbuf_peek_header(nbuf, &anbdata, &anblen);
591 bhdr = (ath_beacon_hdr_t *)anbdata;
593 adf_os_print("found bc_hdr! 0x%x\n", bc_hdr);
597 vap_index = bhdr->vap_index;
598 adf_os_assert(vap_index < TARGET_VAP_MAX);
600 adf_nbuf_pull_head(nbuf, sizeof(ath_beacon_hdr_t));
602 bf = sc->sc_vap[vap_index].av_bcbuf;
604 bf->bf_endpt = EndPt;
607 adf_nbuf_unmap(sc->sc_dev, bf->bf_dmamap, ADF_OS_DMA_TO_DEVICE);
608 adf_nbuf_push_head(bf->bf_skb, sizeof(ath_beacon_hdr_t));
609 ath_free_tx_skb(sc->tgt_htc_handle, bf->bf_endpt, bf->bf_skb);
614 adf_nbuf_map(sc->sc_dev, bf->bf_dmamap, nbuf, ADF_OS_DMA_TO_DEVICE);
615 adf_nbuf_dmamap_info(bf->bf_dmamap,&bf->bf_dmamap_info);
617 ath_beacon_setup(sc, bf, &sc->sc_vap[vap_index]);
618 ah->ah_stopTxDma(ah, sc->sc_bhalq);
619 ah->ah_setTxDP(ah, sc->sc_bhalq, ATH_BUF_GET_DESC_PHY_ADDR(bf));
620 ah->ah_startTxDma(ah, sc->sc_bhalq);
627 static void ath_tx_stopdma(struct ath_softc_tgt *sc, struct ath_txq *txq)
629 struct ath_hal *ah = sc->sc_ah;
631 ah->ah_stopTxDma(ah, txq->axq_qnum);
634 static void owltgt_txq_drain(struct ath_softc_tgt *sc, struct ath_txq *txq)
636 owltgt_tx_processq(sc, txq, OWL_TXQ_STOPPED);
639 static void ath_tx_draintxq(struct ath_softc_tgt *sc, struct ath_txq *txq)
641 owltgt_txq_drain(sc, txq);
644 static void ath_draintxq(struct ath_softc_tgt *sc, HAL_BOOL drain_softq)
646 struct ath_hal *ah = sc->sc_ah;
648 struct ath_txq *txq = NULL;
649 struct ath_atx_tid *tid = NULL;
651 ath_tx_status_clear(sc);
652 sc->sc_tx_draining = 1;
654 ah->ah_stopTxDma(ah, sc->sc_bhalq);
656 for (i = 0; i < HAL_NUM_TX_QUEUES; i++)
657 if (ATH_TXQ_SETUP(sc, i))
658 ath_tx_stopdma(sc, ATH_TXQ(sc, i));
660 for (i = 0; i < HAL_NUM_TX_QUEUES; i++)
661 if (ATH_TXQ_SETUP(sc, i)) {
662 owltgt_tx_processq(sc, ATH_TXQ(sc,i), OWL_TXQ_STOPPED);
665 while (!asf_tailq_empty(&txq->axq_tidq)){
666 TAILQ_DEQ(&txq->axq_tidq, tid, tid_qelem);
669 tid->sched = AH_FALSE;
670 ath_tgt_tid_drain(sc,tid);
674 sc->sc_tx_draining = 0;
677 static void ath_tgt_txq_setup(struct ath_softc_tgt *sc)
684 for (qnum=0;qnum<HAL_NUM_TX_QUEUES;qnum++) {
685 txq= &sc->sc_txq[qnum];
686 txq->axq_qnum = qnum;
687 txq->axq_link = NULL;
688 asf_tailq_init(&txq->axq_q);
690 txq->axq_linkbuf = NULL;
691 asf_tailq_init(&txq->axq_tidq);
692 sc->sc_txqsetup |= 1<<qnum;
695 sc->sc_uapsdq = &sc->sc_txq[UAPSDQ_NUM];
696 sc->sc_cabq = &sc->sc_txq[CABQ_NUM];
698 sc->sc_ac2q[WME_AC_BE] = &sc->sc_txq[0];
699 sc->sc_ac2q[WME_AC_BK] = &sc->sc_txq[1];
700 sc->sc_ac2q[WME_AC_VI] = &sc->sc_txq[2];
701 sc->sc_ac2q[WME_AC_VO] = &sc->sc_txq[3];
707 static void tgt_HTCRecv_beaconhandler(HTC_ENDPOINT_ID EndPt, adf_nbuf_t hdr_buf,
708 adf_nbuf_t buf, void *ServiceCtx)
710 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)ServiceCtx;
712 ath_tgt_send_beacon(sc, hdr_buf, buf, EndPt);
715 static void tgt_HTCRecv_uapsdhandler(HTC_ENDPOINT_ID EndPt, adf_nbuf_t hdr_buf,
716 adf_nbuf_t buf, void *ServiceCtx)
720 static void tgt_HTCRecv_mgmthandler(HTC_ENDPOINT_ID EndPt, adf_nbuf_t hdr_buf,
721 adf_nbuf_t buf, void *ServiceCtx)
723 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)ServiceCtx;
725 ath_tgt_send_mgt(sc,hdr_buf,buf,EndPt);
728 static void tgt_HTCRecvMessageHandler(HTC_ENDPOINT_ID EndPt,
729 adf_nbuf_t hdr_buf, adf_nbuf_t buf,
732 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)ServiceCtx;
733 struct ath_tx_buf *bf;
737 struct ath_node_target *an;
738 struct ath_atx_tid *tid;
741 adf_nbuf_peek_header(buf, &data, &len);
742 adf_nbuf_pull_head(buf, sizeof(ath_data_hdr_t));
744 adf_nbuf_peek_header(hdr_buf, &data, &len);
747 adf_os_assert(len >= sizeof(ath_data_hdr_t));
748 dh = (ath_data_hdr_t *)data;
750 an = &sc->sc_sta[dh->ni_index];
751 tid = ATH_AN_2_TID(an, dh->tidno);
753 sc->sc_tx_stats.tx_tgt++;
755 bf = ath_tgt_tx_prepare(sc, buf, dh);
757 ath_free_tx_skb(sc->tgt_htc_handle,EndPt,buf);
761 bf->bf_endpt = EndPt;
762 bf->bf_cookie = dh->cookie;
763 bf->vap_index = dh->vap_index;
765 if (tid->flag & TID_AGGR_ENABLED)
766 ath_tgt_handle_aggr(sc, bf);
768 ath_tgt_handle_normal(sc, bf);
771 static void tgt_HTCRecv_cabhandler(HTC_ENDPOINT_ID EndPt, adf_nbuf_t hdr_buf,
772 adf_nbuf_t buf, void *ServiceCtx)
774 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)ServiceCtx;
775 struct ath_hal *ah = sc->sc_ah;
779 #ifdef ATH_ENABLE_CABQ
780 tsf = ah->ah_getTsf64(ah);
781 tmp = tsf - sc->sc_swba_tsf;
783 if ( tmp > ATH_CABQ_HANDLING_THRESHOLD ) {
784 HTC_ReturnBuffers(sc->tgt_htc_handle, EndPt, buf);
788 tgt_HTCRecvMessageHandler(EndPt, hdr_buf, buf, ServiceCtx);
792 /***********************/
793 /* Descriptor Handling */
794 /***********************/
796 static a_int32_t ath_descdma_setup(struct ath_softc_tgt *sc,
797 struct ath_descdma *dd, ath_bufhead *head,
798 const char *name, a_int32_t nbuf, a_int32_t ndesc,
799 a_uint32_t bfSize, a_uint32_t descSize)
801 #define DS2PHYS(_dd, _ds) \
802 ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
806 a_int32_t i, bsize, error;
811 dd->dd_desc_len = descSize * nbuf * ndesc;
813 dd->dd_desc = adf_os_dmamem_alloc(sc->sc_dev,
814 dd->dd_desc_len, 1, &dd->dd_desc_dmamap);
815 dd->dd_desc_paddr = adf_os_dmamem_map2addr(dd->dd_desc_dmamap);
816 if (dd->dd_desc == NULL) {
822 bsize = bfSize * nbuf;
823 bf = adf_os_mem_alloc(bsize);
828 adf_os_mem_set(bf, 0, bsize);
831 bf_addr = (a_uint8_t *)bf;
832 ds_addr = (a_uint8_t *)ds;
834 asf_tailq_init(head);
836 for (i = 0; i < nbuf; i++) {
839 if (adf_nbuf_dmamap_create( sc->sc_dev, &bf->bf_dmamap) != A_STATUS_OK) {
843 bf->bf_desc = bf->bf_descarr = bf->bf_lastds = ds;
844 for (j = 0; j < ndesc; j++)
845 ATH_BUF_SET_DESC_PHY_ADDR_WITH_IDX(bf, j, (ds_addr + (j*descSize)));
847 ATH_BUF_SET_DESC_PHY_ADDR(bf, ATH_BUF_GET_DESC_PHY_ADDR_WITH_IDX(bf, 0));
849 adf_nbuf_queue_init(&bf->bf_skbhead);
850 asf_tailq_insert_tail(head, bf, bf_list);
853 ds_addr += (ndesc * descSize);
854 bf = (struct ath_buf *)bf_addr;
855 ds = (struct ath_desc *)ds_addr;
860 adf_os_dmamem_free(sc->sc_dev, dd->dd_desc_len,
861 1, dd->dd_desc, dd->dd_desc_dmamap);
863 adf_os_mem_set(dd, 0, sizeof(*dd));
870 static void ath_descdma_cleanup(struct ath_softc_tgt *sc,
871 struct ath_descdma *dd,
872 ath_bufhead *head, a_int32_t dir)
876 asf_tailq_foreach(bf, head, bf_list) {
877 if (adf_nbuf_queue_len(&bf->bf_skbhead) != 0) {
878 adf_nbuf_unmap(sc->sc_dev, bf->bf_dmamap, dir);
879 while(adf_nbuf_queue_len(&bf->bf_skbhead) != 0) {
881 adf_nbuf_queue_remove(&bf->bf_skbhead));
884 } else if (bf->bf_skb != NULL) {
885 adf_nbuf_unmap(sc->sc_dev,bf->bf_dmamap, dir);
886 ath_free_rx_skb(sc, bf->bf_skb);
890 adf_nbuf_dmamap_destroy(sc->sc_dev, bf->bf_dmamap);
895 adf_os_dmamem_free(sc->sc_dev, dd->dd_desc_len,
896 1, dd->dd_desc, dd->dd_desc_dmamap);
898 asf_tailq_init(head);
899 adf_os_mem_free(dd->dd_bufptr);
900 adf_os_mem_set(dd, 0, sizeof(*dd));
903 static a_int32_t ath_desc_alloc(struct ath_softc_tgt *sc)
905 #define DS2PHYS(_dd, _ds) \
906 ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
909 struct ath_tx_buf *bf;
911 if(ath_numrxbufs == -1)
912 ath_numrxbufs = ATH_RXBUF;
914 if (ath_numrxdescs == -1)
915 ath_numrxdescs = ATH_RXDESC;
917 error = ath_descdma_setup(sc, &sc->sc_rxdma, (ath_bufhead *)&sc->sc_rxbuf,
918 "rx", ath_numrxdescs, 1,
919 sizeof(struct ath_rx_buf),
920 sizeof(struct ath_rx_desc));
925 struct ath_descdma *dd = &sc->sc_rxdma;
926 struct ath_rx_desc *ds = (struct ath_rx_desc *)dd->dd_desc;
927 struct ath_rx_desc *ds_prev = NULL;
929 asf_tailq_init(&sc->sc_rxdesc);
930 asf_tailq_init(&sc->sc_rxdesc_idle);
932 for (i = 0; i < ath_numrxdescs; i++, ds++) {
934 if (ds->ds_nbuf != ADF_NBUF_NULL) {
935 ds->ds_nbuf = ADF_NBUF_NULL;
938 if (adf_nbuf_dmamap_create(sc->sc_dev, &ds->ds_dmap) != A_STATUS_OK) {
942 ds->ds_daddr = DS2PHYS(&sc->sc_rxdma, ds);
945 ds_prev->ds_link = ds->ds_daddr;
951 asf_tailq_insert_tail(&sc->sc_rxdesc, ds, ds_list);
954 error = ath_descdma_setup(sc, &sc->sc_txdma, (ath_bufhead *)&sc->sc_txbuf,
955 "tx", ATH_TXBUF + 1, ATH_TXDESC,
956 sizeof(struct ath_tx_buf),
957 sizeof(struct ath_tx_desc));
959 ath_descdma_cleanup(sc, &sc->sc_rxdma, (ath_bufhead *)&sc->sc_rxbuf,
960 ADF_OS_DMA_FROM_DEVICE);
964 error = ath_descdma_setup(sc, &sc->sc_bdma, (ath_bufhead *)&sc->sc_bbuf,
965 "beacon", ATH_BCBUF, 1,
966 sizeof(struct ath_tx_buf),
967 sizeof(struct ath_tx_desc));
969 ath_descdma_cleanup(sc, &sc->sc_txdma, (ath_bufhead *)&sc->sc_txbuf,
970 ADF_OS_DMA_TO_DEVICE);
971 ath_descdma_cleanup(sc, &sc->sc_rxdma, (ath_bufhead *)&sc->sc_rxbuf,
972 ADF_OS_DMA_FROM_DEVICE);
976 bf = asf_tailq_first(&sc->sc_txbuf);
977 bf->bf_isaggr = bf->bf_isretried = bf->bf_retries = 0;
978 asf_tailq_remove(&sc->sc_txbuf, bf, bf_list);
980 sc->sc_txbuf_held = bf;
987 static void ath_desc_free(struct ath_softc_tgt *sc)
989 asf_tailq_insert_tail(&sc->sc_txbuf, sc->sc_txbuf_held, bf_list);
991 sc->sc_txbuf_held = NULL;
993 if (sc->sc_txdma.dd_desc_len != 0)
994 ath_descdma_cleanup(sc, &sc->sc_txdma, (ath_bufhead *)&sc->sc_txbuf,
995 ADF_OS_DMA_TO_DEVICE);
996 if (sc->sc_rxdma.dd_desc_len != 0)
997 ath_descdma_cleanup(sc, &sc->sc_rxdma, (ath_bufhead *)&sc->sc_rxbuf,
998 ADF_OS_DMA_FROM_DEVICE);
1001 /**********************/
1002 /* Interrupt Handling */
1003 /**********************/
1005 adf_os_irq_resp_t ath_intr(adf_drv_handle_t hdl)
1007 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)hdl;
1008 struct ath_hal *ah = sc->sc_ah;
1012 return ADF_OS_IRQ_NONE;
1014 if (!ah->ah_isInterruptPending(ah))
1015 return ADF_OS_IRQ_NONE;
1017 ah->ah_getPendingInterrupts(ah, &status);
1019 status &= sc->sc_imask;
1021 if (status & HAL_INT_FATAL) {
1022 ah->ah_setInterrupts(ah, 0);
1023 ATH_SCHEDULE_TQUEUE(sc->sc_dev, &sc->sc_fataltq);
1025 if (status & HAL_INT_SWBA) {
1026 WMI_SWBA_EVENT swbaEvt;
1027 struct ath_txq *txq = ATH_TXQ(sc, 8);
1029 swbaEvt.tsf = ah->ah_getTsf64(ah);
1030 swbaEvt.beaconPendingCount = ah->ah_numTxPending(ah, sc->sc_bhalq);
1031 sc->sc_swba_tsf = ah->ah_getTsf64(ah);
1033 wmi_event(sc->tgt_wmi_handle,
1036 sizeof(WMI_SWBA_EVENT));
1038 ath_tx_draintxq(sc, txq);
1041 if (status & HAL_INT_RXORN)
1042 sc->sc_int_stats.ast_rxorn++;
1044 if (status & HAL_INT_RXEOL)
1045 sc->sc_int_stats.ast_rxeol++;
1047 if (status & (HAL_INT_RX | HAL_INT_RXEOL | HAL_INT_RXORN)) {
1048 if (status & HAL_INT_RX)
1049 sc->sc_int_stats.ast_rx++;
1051 ath_uapsd_processtriggers(sc);
1053 sc->sc_imask &= ~HAL_INT_RX;
1054 ah->ah_setInterrupts(ah, sc->sc_imask);
1056 ATH_SCHEDULE_TQUEUE(sc->sc_dev, &sc->sc_rxtq);
1059 if (status & HAL_INT_TXURN) {
1060 sc->sc_int_stats.ast_txurn++;
1061 ah->ah_updateTxTrigLevel(ah, AH_TRUE);
1064 ATH_SCHEDULE_TQUEUE(sc->sc_dev, &sc->sc_txtq);
1066 if (status & HAL_INT_BMISS) {
1067 ATH_SCHEDULE_TQUEUE(sc->sc_dev, &sc->sc_bmisstq);
1070 if (status & HAL_INT_GTT)
1071 sc->sc_int_stats.ast_txto++;
1073 if (status & HAL_INT_CST)
1074 sc->sc_int_stats.ast_cst++;
1077 return ADF_OS_IRQ_HANDLED;
1080 static void ath_fatal_tasklet(TQUEUE_ARG data )
1082 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)data;
1084 wmi_event(sc->tgt_wmi_handle, WMI_FATAL_EVENTID, NULL, 0);
1087 static void ath_bmiss_tasklet(TQUEUE_ARG data)
1089 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)data;
1091 wmi_event(sc->tgt_wmi_handle, WMI_BMISS_EVENTID, NULL, 0);
1098 static void ath_enable_intr_tgt(void *Context, A_UINT16 Command,
1099 A_UINT16 SeqNo, A_UINT8 *data, a_int32_t datalen)
1101 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1102 struct ath_hal *ah = sc->sc_ah;
1103 a_uint32_t intr = 0;
1106 intr = (*(a_uint32_t *)data);
1108 intr = adf_os_ntohl(intr);
1110 if (intr & HAL_INT_SWBA) {
1111 sc->sc_imask |= HAL_INT_SWBA;
1113 sc->sc_imask &= ~HAL_INT_SWBA;
1116 if (intr & HAL_INT_BMISS) {
1117 sc->sc_imask |= HAL_INT_BMISS;
1120 ah->ah_setInterrupts(ah, sc->sc_imask);
1121 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo,NULL, 0);
1124 static void ath_init_tgt(void *Context, A_UINT16 Command,
1125 A_UINT16 SeqNo, A_UINT8 *data, a_int32_t datalen)
1127 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1128 struct ath_hal *ah = sc->sc_ah;
1130 sc->sc_imask = HAL_INT_RX | HAL_INT_TX
1131 | HAL_INT_RXEOL | HAL_INT_RXORN
1132 | HAL_INT_FATAL | HAL_INT_GLOBAL;
1134 sc->sc_imask |= HAL_INT_GTT;
1136 if (ath_hal_getcapability(ah, HAL_CAP_HT))
1137 sc->sc_imask |= HAL_INT_CST;
1139 adf_os_setup_intr(sc->sc_dev, ath_intr);
1140 ah->ah_setInterrupts(ah, sc->sc_imask);
1142 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1145 static void ath_int_stats_tgt(void *Context,A_UINT16 Command, A_UINT16 SeqNo,
1146 A_UINT8 *data, a_int32_t datalen)
1148 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1150 struct fusion_stats {
1152 a_uint32_t ast_rxorn;
1153 a_uint32_t ast_rxeol;
1154 a_uint32_t ast_txurn;
1155 a_uint32_t ast_txto;
1159 struct fusion_stats stats;
1161 stats.ast_rx = sc->sc_int_stats.ast_rx;
1162 stats.ast_rxorn = sc->sc_int_stats.ast_rxorn;
1163 stats.ast_rxeol = sc->sc_int_stats.ast_rxeol;
1164 stats.ast_txurn = sc->sc_int_stats.ast_txurn;
1165 stats.ast_txto = sc->sc_int_stats.ast_txto;
1166 stats.ast_cst = sc->sc_int_stats.ast_cst;
1168 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, &stats, sizeof(stats));
1171 static void ath_tx_stats_tgt(void *Context,A_UINT16 Command, A_UINT16 SeqNo,
1172 A_UINT8 *data, a_int32_t datalen)
1174 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1176 struct fusion_stats {
1177 a_uint32_t ast_tx_xretries;
1178 a_uint32_t ast_tx_fifoerr;
1179 a_uint32_t ast_tx_filtered;
1180 a_uint32_t ast_tx_timer_exp;
1181 a_uint32_t ast_tx_shortretry;
1182 a_uint32_t ast_tx_longretry;
1184 a_uint32_t tx_qnull;
1185 a_uint32_t tx_noskbs;
1186 a_uint32_t tx_nobufs;
1189 struct fusion_stats stats;
1191 stats.ast_tx_xretries = sc->sc_tx_stats.ast_tx_xretries;
1192 stats.ast_tx_fifoerr = sc->sc_tx_stats.ast_tx_fifoerr;
1193 stats.ast_tx_filtered = sc->sc_tx_stats.ast_tx_filtered;
1194 stats.ast_tx_timer_exp = sc->sc_tx_stats.ast_tx_timer_exp;
1195 stats.ast_tx_shortretry = sc->sc_tx_stats.ast_tx_shortretry;
1196 stats.ast_tx_longretry = sc->sc_tx_stats.ast_tx_longretry;
1197 stats.tx_qnull = sc->sc_tx_stats.tx_qnull;
1198 stats.tx_noskbs = sc->sc_tx_stats.tx_noskbs;
1199 stats.tx_nobufs = sc->sc_tx_stats.tx_nobufs;
1201 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, &stats, sizeof(stats));
1204 static void ath_rx_stats_tgt(void *Context,A_UINT16 Command, A_UINT16 SeqNo,
1205 A_UINT8 *data, a_int32_t datalen)
1207 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1209 struct fusion_stats {
1210 a_uint32_t ast_rx_nobuf;
1211 a_uint32_t ast_rx_send;
1212 a_uint32_t ast_rx_done;
1215 struct fusion_stats stats;
1217 stats.ast_rx_nobuf = sc->sc_rx_stats.ast_rx_nobuf;
1218 stats.ast_rx_send = sc->sc_rx_stats.ast_rx_send;
1219 stats.ast_rx_done = sc->sc_rx_stats.ast_rx_done;
1221 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, &stats, sizeof(stats));
1224 static void ath_get_tgt_version(void *Context,A_UINT16 Command, A_UINT16 SeqNo,
1225 A_UINT8 *data, a_int32_t datalen)
1227 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1228 struct wmi_fw_version ver;
1230 ver.major = ATH_VERSION_MAJOR;
1231 ver.minor = ATH_VERSION_MINOR;
1233 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, &ver, sizeof(ver));
1236 static void ath_enable_aggr_tgt(void *Context,A_UINT16 Command, A_UINT16 SeqNo,
1237 A_UINT8 *data, a_int32_t datalen)
1239 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1240 struct ath_aggr_info *aggr = (struct ath_aggr_info *)data;
1241 a_uint8_t nodeindex = aggr->nodeindex;
1242 a_uint8_t tidno = aggr->tidno;
1243 struct ath_node_target *an = NULL ;
1244 struct ath_atx_tid *tid = NULL;
1246 if (nodeindex >= TARGET_NODE_MAX) {
1250 an = &sc->sc_sta[nodeindex];
1251 if (!an->an_valid) {
1255 if (tidno >= WME_NUM_TID) {
1256 adf_os_print("[%s] enable_aggr with invalid tid %d(node = %d)\n",
1257 __FUNCTION__, tidno, nodeindex);
1261 tid = ATH_AN_2_TID(an, tidno);
1263 if (aggr->aggr_enable) {
1264 tid->flag |= TID_AGGR_ENABLED;
1265 } else if ( tid->flag & TID_AGGR_ENABLED ) {
1266 tid->flag &= ~TID_AGGR_ENABLED;
1267 ath_tgt_tx_cleanup(sc, an, tid, 1);
1270 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1273 static void ath_ic_update_tgt(void *Context,A_UINT16 Command, A_UINT16 SeqNo,
1274 A_UINT8 *data, a_int32_t datalen)
1276 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1277 struct ieee80211com_target *ic = (struct ieee80211com_target * )data;
1278 struct ieee80211com_target *ictgt = &sc->sc_ic ;
1280 adf_os_mem_copy(ictgt, ic, sizeof(struct ieee80211com_target));
1282 ictgt->ic_ampdu_limit = adf_os_ntohl(ic->ic_ampdu_limit);
1284 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1287 static void ath_vap_create_tgt(void *Context, A_UINT16 Command, A_UINT16 SeqNo,
1288 A_UINT8 *data, a_int32_t datalen)
1290 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1291 struct ieee80211vap_target *vap;
1292 a_uint8_t vap_index;
1294 vap = (struct ieee80211vap_target *)data;
1296 vap->iv_rtsthreshold = adf_os_ntohs(vap->iv_rtsthreshold);
1297 vap->iv_opmode = adf_os_ntohl(vap->iv_opmode);
1299 vap_index = vap->iv_vapindex;
1301 adf_os_assert(sc->sc_vap[vap_index].av_valid == 0);
1303 adf_os_mem_copy(&(sc->sc_vap[vap_index].av_vap), vap,
1306 sc->sc_vap[vap_index].av_bcbuf = asf_tailq_first(&(sc->sc_bbuf));
1307 sc->sc_vap[vap_index].av_valid = 1;
1309 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1312 static void ath_node_create_tgt(void *Context, A_UINT16 Command,
1313 A_UINT16 SeqNo, A_UINT8 *data, a_int32_t datalen)
1315 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1316 struct ieee80211_node_target *node;
1317 a_uint8_t vap_index;
1318 a_uint8_t node_index;
1320 node = (struct ieee80211_node_target *)data;
1322 node_index = node->ni_nodeindex;
1324 node->ni_htcap = adf_os_ntohs(node->ni_htcap);
1325 node->ni_flags = adf_os_ntohs(node->ni_flags);
1326 node->ni_maxampdu = adf_os_ntohs(node->ni_maxampdu);
1328 adf_os_mem_copy(&(sc->sc_sta[node_index].ni), node,
1331 vap_index = sc->sc_sta[node_index].ni.ni_vapindex;
1332 sc->sc_sta[node_index].ni.ni_vap = &(sc->sc_vap[vap_index].av_vap);
1333 if(sc->sc_sta[node_index].ni.ni_is_vapnode == 1)
1334 sc->sc_vap[vap_index].av_vap.iv_nodeindex = node_index;
1336 sc->sc_sta[node_index].an_valid = 1;
1337 sc->sc_sta[node_index].ni.ni_txseqmgmt = 0;
1338 sc->sc_sta[node_index].ni.ni_iv16 = 0;
1339 sc->sc_sta[node_index].ni.ni_iv32 = 0;
1341 owl_tgt_node_init(&sc->sc_sta[node_index]);
1343 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1346 static void ath_node_cleanup_tgt(void *Context, A_UINT16 Command,
1347 A_UINT16 SeqNo, A_UINT8 *data, a_int32_t datalen)
1349 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1350 a_uint8_t node_index;
1351 a_uint8_t *nodedata;
1353 nodedata = (a_uint8_t *)data;
1354 node_index = *nodedata;
1355 sc->sc_sta[node_index].an_valid = 0;
1357 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1360 static void ath_node_update_tgt(void *Context, A_UINT16 Command,
1361 A_UINT16 SeqNo, A_UINT8 *data, a_int32_t datalen)
1363 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1364 struct ieee80211_node_target *node;
1365 a_uint8_t vap_index;
1366 a_uint8_t node_index;
1368 node = (struct ieee80211_node_target *)data;
1370 node_index = node->ni_nodeindex;
1372 node->ni_htcap = adf_os_ntohs(node->ni_htcap);
1373 node->ni_flags = adf_os_ntohs(node->ni_flags);
1374 node->ni_maxampdu = adf_os_ntohs(node->ni_maxampdu);
1376 adf_os_mem_copy(&(sc->sc_sta[node_index].ni), node,
1379 vap_index = sc->sc_sta[node_index].ni.ni_vapindex;
1380 sc->sc_sta[node_index].ni.ni_vap = &(sc->sc_vap[vap_index].av_vap);
1382 sc->sc_sta[node_index].ni.ni_txseqmgmt = 0;
1383 sc->sc_sta[node_index].ni.ni_iv16 = 0;
1384 sc->sc_sta[node_index].ni.ni_iv32 = 0;
1386 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1389 static a_int32_t ath_reg_read_filter(struct ath_hal *ah, a_int32_t addr)
1391 if ((addr & 0xffffe000) == 0x2000) {
1392 /* SEEPROM registers */
1394 if (!ath_hal_wait(ah, 0x407c, 0x00030000, 0))
1395 adf_os_print("SEEPROM Read fail: 0x%08x\n", addr);
1397 return ioread32_mac(0x407c) & 0x0000ffff;
1398 } else if (addr > 0xffff)
1400 return ioread32(addr);
1403 return ioread32_mac(addr);
1406 static void ath_hal_reg_read_tgt(void *Context, A_UINT16 Command,
1407 A_UINT16 SeqNo, A_UINT8 *data, a_int32_t datalen)
1409 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1410 struct ath_hal *ah = sc->sc_ah;
1415 for (i = 0; i < datalen; i += sizeof(a_int32_t)) {
1416 addr = *(a_uint32_t *)(data + i);
1417 addr = adf_os_ntohl(addr);
1419 val[i/sizeof(a_int32_t)] =
1420 adf_os_ntohl(ath_reg_read_filter(ah, addr));
1423 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, &val[0], datalen);
1426 static void ath_pll_reset_ones(struct ath_hal *ah)
1428 static uint8_t reset_pll = 0;
1430 if(reset_pll == 0) {
1431 #if defined(PROJECT_K2)
1432 /* here we write to core register */
1433 iowrite32(MAGPIE_REG_RST_PWDN_CTRL_ADDR, 0x0);
1434 /* and here to mac register */
1435 iowrite32_mac(0x786c,
1436 ioread32_mac(0x786c) | 0x6000000);
1437 iowrite32_mac(0x786c,
1438 ioread32_mac(0x786c) & (~0x6000000));
1440 iowrite32(MAGPIE_REG_RST_PWDN_CTRL_ADDR, 0x20);
1442 #elif defined(PROJECT_MAGPIE) && !defined (FPGA)
1443 iowrite32_mac(0x7890,
1444 ioread32_mac(0x7890) | 0x1800000);
1445 iowrite32_mac(0x7890,
1446 ioread32_mac(0x7890) & (~0x1800000));
1452 static void ath_hal_reg_write_filter(struct ath_hal *ah,
1453 a_uint32_t reg, a_uint32_t val)
1456 iowrite32(reg, val);
1457 #if defined(PROJECT_K2)
1458 if(reg == 0x50040) {
1459 static uint8_t flg=0;
1462 /* reinit clock and uart.
1463 * TODO: Independent on what host will
1464 * here set. We do our own decision. Why? */
1466 A_UART_HWINIT(117*1000*1000, 19200);
1473 ath_pll_reset_ones(ah);
1475 iowrite32_mac(reg, val);
1479 static void ath_hal_reg_write_tgt(void *Context, A_UINT16 Command,
1480 A_UINT16 SeqNo, A_UINT8 *data, a_int32_t datalen)
1482 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1483 struct ath_hal *ah = sc->sc_ah;
1485 struct registerWrite {
1490 for (i = 0; i < datalen; i += sizeof(struct registerWrite)) {
1491 t = (struct registerWrite *)(data+i);
1493 ath_hal_reg_write_filter(ah, t->reg, t->val);
1496 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1499 static void ath_hal_reg_rmw_tgt(void *Context, A_UINT16 Command,
1500 A_UINT16 SeqNo, A_UINT8 *data,
1503 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1504 struct ath_hal *ah = sc->sc_ah;
1505 struct register_rmw *buf = (struct register_rmw *)data;
1508 for (i = 0; i < datalen;
1509 i += sizeof(struct register_rmw)) {
1511 buf = (struct register_rmw *)(data + i);
1513 val = ath_reg_read_filter(ah, buf->reg);
1516 ath_hal_reg_write_filter(ah, buf->reg, val);
1518 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1521 static void ath_vap_delete_tgt(void *Context, A_UINT16 Command,
1522 A_UINT16 SeqNo, A_UINT8 *data, a_int32_t datalen)
1524 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1525 a_uint8_t vap_index;
1527 vap_index = *(a_uint8_t *)data;
1529 sc->sc_vap[vap_index].av_valid = 0;
1530 sc->sc_vap[vap_index].av_bcbuf = NULL;
1531 ath_node_vdelete_tgt(sc, vap_index);
1532 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1535 static void ath_disable_intr_tgt(void *Context, A_UINT16 Command,
1536 A_UINT16 SeqNo, A_UINT8 *data, a_int32_t datalen)
1538 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1539 struct ath_hal *ah = sc->sc_ah;
1541 ah->ah_setInterrupts(ah, 0);
1542 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo,NULL, 0);
1545 static void ath_flushrecv_tgt(void *Context, A_UINT16 Command,
1546 A_UINT16 SeqNo, A_UINT8 *data, a_int32_t datalen)
1548 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1549 struct ath_rx_buf *bf;
1551 asf_tailq_foreach(bf, &sc->sc_rxbuf, bf_list)
1552 if (bf->bf_skb != NULL) {
1553 adf_nbuf_unmap(sc->sc_dev, bf->bf_dmamap,
1554 ADF_OS_DMA_FROM_DEVICE);
1555 ath_free_rx_skb(sc, adf_nbuf_queue_remove(&bf->bf_skbhead));
1559 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1562 static void ath_tx_draintxq_tgt(void *Context, A_UINT16 Command, A_UINT16 SeqNo,
1563 A_UINT8 *data, a_int32_t datalen)
1565 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1566 a_uint32_t q = *(a_uint32_t *)data;
1567 struct ath_txq *txq = NULL;
1569 q = adf_os_ntohl(q);
1570 txq = ATH_TXQ(sc, q);
1572 ath_tx_draintxq(sc, txq);
1573 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1576 static void ath_draintxq_tgt(void *Context, A_UINT16 Command,
1577 A_UINT16 SeqNo, A_UINT8 *data, a_int32_t datalen)
1579 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1580 HAL_BOOL b = (HAL_BOOL) *(a_int32_t *)data;
1582 ath_draintxq(Context, b);
1583 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1586 static void ath_aborttx_dma_tgt(void *Context, A_UINT16 Command,
1587 A_UINT16 SeqNo, A_UINT8 *data, a_int32_t datalen)
1589 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1590 struct ath_hal *ah = sc->sc_ah;
1592 ah->ah_abortTxDma(sc->sc_ah);
1593 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1596 static void ath_aborttxq_tgt(void *Context, A_UINT16 Command,
1597 A_UINT16 SeqNo, A_UINT8 *data, a_int32_t datalen)
1600 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1603 for (i = 0; i < HAL_NUM_TX_QUEUES; i++) {
1604 if (ATH_TXQ_SETUP(sc, i))
1605 ath_tx_draintxq(sc, ATH_TXQ(sc,i));
1608 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1611 static void ath_stop_tx_dma_tgt(void *Context, A_UINT16 Command,
1612 A_UINT16 SeqNo, A_UINT8 *data, a_int32_t datalen)
1614 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1615 struct ath_hal *ah = sc->sc_ah;
1621 q = *(a_uint32_t *)data;
1623 q = adf_os_ntohl(q);
1624 ah->ah_stopTxDma(ah, q);
1626 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1629 static void ath_startrecv_tgt(void *Context, A_UINT16 Command,
1630 A_UINT16 SeqNo, A_UINT8 *data, a_int32_t datalen)
1633 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1636 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1639 static void ath_stoprecv_tgt(void *Context, A_UINT16 Command,
1640 A_UINT16 SeqNo, A_UINT8 *data, a_int32_t datalen)
1642 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1643 struct ath_hal *ah = sc->sc_ah;
1645 ah->ah_stopPcuReceive(ah);
1646 ah->ah_setRxFilter(ah, 0);
1647 ah->ah_stopDmaReceive(ah);
1649 sc->sc_rxlink = NULL;
1650 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1653 static void ath_setcurmode_tgt(void *Context, A_UINT16 Command,
1654 A_UINT16 SeqNo, A_UINT8 *data, a_int32_t datalen)
1656 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1659 mode= *((a_uint16_t *)data);
1660 mode = adf_os_ntohs(mode);
1662 ath_setcurmode(sc, mode);
1664 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1667 static void ath_detach_tgt(void *Context, A_UINT16 Command, A_UINT16 SeqNo,
1668 A_UINT8 *data, a_int32_t datalen)
1670 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1671 struct ath_hal *ah = sc->sc_ah;
1675 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1676 adf_os_mem_free(sc);
1679 static void handle_echo_command(void *pContext, A_UINT16 Command,
1680 A_UINT16 SeqNo, A_UINT8 *buffer, a_int32_t Length)
1682 wmi_cmd_rsp(pContext, WMI_ECHO_CMDID, SeqNo, buffer, Length);
1685 static void handle_rc_state_change_cmd(void *Context, A_UINT16 Command,
1686 A_UINT16 SeqNo, A_UINT8 *buffer, a_int32_t Length)
1689 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1690 struct wmi_rc_state_change_cmd *wmi_data = (struct wmi_rc_state_change_cmd *)buffer;
1692 a_uint32_t capflag = adf_os_ntohl(wmi_data->capflag);
1694 ath_rate_newstate(sc, &sc->sc_vap[wmi_data->vap_index].av_vap,
1695 wmi_data->vap_state,
1699 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1702 static void handle_rc_rate_update_cmd(void *Context, A_UINT16 Command,
1703 A_UINT16 SeqNo, A_UINT8 *buffer, a_int32_t Length)
1705 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1706 struct wmi_rc_rate_update_cmd *wmi_data = (struct wmi_rc_rate_update_cmd *)buffer;
1708 a_uint32_t capflag = adf_os_ntohl(wmi_data->capflag);
1710 ath_rate_node_update(sc, &sc->sc_sta[wmi_data->node_index],
1715 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1718 static void dispatch_magpie_sys_cmds(void *pContext, A_UINT16 Command,
1719 A_UINT16 SeqNo, A_UINT8 *buffer, a_int32_t Length)
1724 static void ath_rc_mask_tgt(void *Context, A_UINT16 Command,
1725 A_UINT16 SeqNo, A_UINT8 *buffer, a_int32_t Length)
1727 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)Context;
1728 struct wmi_rc_rate_mask_cmd *wmi_data = (struct wmi_rc_rate_mask_cmd *)buffer;
1731 idx = wmi_data->vap_index;
1732 band = wmi_data->band;
1734 sc->sc_vap[idx].av_rate_mask[band] = adf_os_ntohl(wmi_data->mask);
1736 if (sc->sc_vap[idx].av_rate_mask[band]) {
1737 for (i = 0; i < RATE_TABLE_SIZE; i++) {
1738 if ((1 << i) & sc->sc_vap[idx].av_rate_mask[band]) {
1739 sc->sc_vap[idx].av_minrateidx[band] = i;
1744 sc->sc_vap[idx].av_minrateidx[band] = 0;
1747 wmi_cmd_rsp(sc->tgt_wmi_handle, Command, SeqNo, NULL, 0);
1750 static WMI_DISPATCH_ENTRY Magpie_Sys_DispatchEntries[] =
1752 {handle_echo_command, WMI_ECHO_CMDID, 0},
1753 {dispatch_magpie_sys_cmds, WMI_ACCESS_MEMORY_CMDID, 0},
1754 {ath_get_tgt_version, WMI_GET_FW_VERSION, 0},
1755 {ath_disable_intr_tgt, WMI_DISABLE_INTR_CMDID, 0},
1756 {ath_enable_intr_tgt, WMI_ENABLE_INTR_CMDID, 0},
1757 {ath_init_tgt, WMI_ATH_INIT_CMDID, 0},
1758 {ath_aborttxq_tgt, WMI_ABORT_TXQ_CMDID, 0},
1759 {ath_stop_tx_dma_tgt, WMI_STOP_TX_DMA_CMDID, 0},
1760 {ath_aborttx_dma_tgt, WMI_ABORT_TX_DMA_CMDID, 0},
1761 {ath_tx_draintxq_tgt, WMI_DRAIN_TXQ_CMDID, 0},
1762 {ath_draintxq_tgt, WMI_DRAIN_TXQ_ALL_CMDID, 0},
1763 {ath_startrecv_tgt, WMI_START_RECV_CMDID, 0},
1764 {ath_stoprecv_tgt, WMI_STOP_RECV_CMDID, 0},
1765 {ath_flushrecv_tgt, WMI_FLUSH_RECV_CMDID, 0},
1766 {ath_setcurmode_tgt, WMI_SET_MODE_CMDID, 0},
1767 {ath_node_create_tgt, WMI_NODE_CREATE_CMDID, 0},
1768 {ath_node_cleanup_tgt, WMI_NODE_REMOVE_CMDID, 0},
1769 {ath_vap_delete_tgt, WMI_VAP_REMOVE_CMDID, 0},
1770 {ath_vap_create_tgt, WMI_VAP_CREATE_CMDID, 0},
1771 {ath_hal_reg_read_tgt, WMI_REG_READ_CMDID, 0},
1772 {ath_hal_reg_write_tgt, WMI_REG_WRITE_CMDID, 0},
1773 {handle_rc_state_change_cmd, WMI_RC_STATE_CHANGE_CMDID, 0},
1774 {handle_rc_rate_update_cmd, WMI_RC_RATE_UPDATE_CMDID, 0},
1775 {ath_ic_update_tgt, WMI_TARGET_IC_UPDATE_CMDID, 0},
1776 {ath_enable_aggr_tgt, WMI_TX_AGGR_ENABLE_CMDID, 0},
1777 {ath_detach_tgt, WMI_TGT_DETACH_CMDID, 0},
1778 {ath_node_update_tgt, WMI_NODE_UPDATE_CMDID, 0},
1779 {ath_int_stats_tgt, WMI_INT_STATS_CMDID, 0},
1780 {ath_tx_stats_tgt, WMI_TX_STATS_CMDID, 0},
1781 {ath_rx_stats_tgt, WMI_RX_STATS_CMDID, 0},
1782 {ath_rc_mask_tgt, WMI_BITRATE_MASK_CMDID, 0},
1783 {ath_hal_reg_rmw_tgt, WMI_REG_RMW_CMDID, 0},
1790 static void htc_setup_comp(void)
1794 static A_UINT8 tgt_ServiceConnect(HTC_SERVICE *pService,
1795 HTC_ENDPOINT_ID eid,
1799 a_int32_t *pLengthOut)
1801 struct ath_softc_tgt *sc = (struct ath_softc_tgt *)pService->ServiceCtx;
1803 switch(pService->ServiceID) {
1804 case WMI_CONTROL_SVC:
1805 sc->wmi_command_ep= eid;
1807 case WMI_BEACON_SVC:
1819 case WMI_DATA_VO_SVC:
1820 sc->data_VO_ep = eid;
1822 case WMI_DATA_VI_SVC:
1823 sc->data_VI_ep = eid;
1825 case WMI_DATA_BE_SVC:
1826 sc->data_BE_ep = eid;
1828 case WMI_DATA_BK_SVC:
1829 sc->data_BK_ep = eid;
1835 return HTC_SERVICE_SUCCESS;
1838 static void tgt_reg_service(struct ath_softc_tgt *sc, HTC_SERVICE *svc,
1839 int svcId, HTC_SERVICE_ProcessRecvMsg recvMsg)
1841 svc->ProcessRecvMsg = recvMsg;
1842 svc->ProcessSendBufferComplete = tgt_HTCSendCompleteHandler;
1843 svc->ProcessConnect = tgt_ServiceConnect;
1844 svc->MaxSvcMsgSize = 1600;
1845 svc->TrailerSpcCheckLimit = 0;
1846 svc->ServiceID = svcId;
1847 svc->ServiceCtx = sc;
1848 HTC_RegisterService(sc->tgt_htc_handle, svc);
1851 static void tgt_hif_htc_wmi_init(struct ath_softc_tgt *sc)
1853 HTC_CONFIG htc_conf;
1854 WMI_SVC_CONFIG wmiConfig;
1855 WMI_DISPATCH_TABLE *Magpie_Sys_Commands_Tbl;
1857 /* Init dynamic buf pool */
1858 sc->pool_handle = BUF_Pool_init(sc->sc_hdl);
1860 /* Init target-side HIF */
1861 sc->tgt_hif_handle = HIF_init(0);
1863 /* Init target-side HTC */
1864 htc_conf.HIFHandle = sc->tgt_hif_handle;
1865 htc_conf.CreditSize = 320;
1866 htc_conf.CreditNumber = ATH_TXBUF;
1867 htc_conf.OSHandle = sc->sc_hdl;
1868 htc_conf.PoolHandle = sc->pool_handle;
1869 sc->tgt_htc_handle = HTC_init(htc_setup_comp, &htc_conf);
1870 #if defined(PROJECT_MAGPIE)
1871 init_htc_handle = sc->tgt_htc_handle;
1874 tgt_reg_service(sc, &sc->htc_beacon_service, WMI_BEACON_SVC, tgt_HTCRecv_beaconhandler);
1875 tgt_reg_service(sc, &sc->htc_cab_service, WMI_CAB_SVC, tgt_HTCRecv_cabhandler);
1876 tgt_reg_service(sc, &sc->htc_uapsd_service, WMI_UAPSD_SVC, tgt_HTCRecv_uapsdhandler);
1877 tgt_reg_service(sc, &sc->htc_mgmt_service, WMI_MGMT_SVC, tgt_HTCRecv_mgmthandler);
1878 tgt_reg_service(sc, &sc->htc_data_BE_service, WMI_DATA_BE_SVC, tgt_HTCRecvMessageHandler);
1879 tgt_reg_service(sc, &sc->htc_data_BK_service, WMI_DATA_BK_SVC, tgt_HTCRecvMessageHandler);
1880 tgt_reg_service(sc, &sc->htc_data_VI_service, WMI_DATA_VI_SVC, tgt_HTCRecvMessageHandler);
1881 tgt_reg_service(sc, &sc->htc_data_VO_service, WMI_DATA_VO_SVC, tgt_HTCRecvMessageHandler);
1883 /* Init target-side WMI */
1884 Magpie_Sys_Commands_Tbl = (WMI_DISPATCH_TABLE *)adf_os_mem_alloc(sizeof(WMI_DISPATCH_TABLE));
1885 adf_os_mem_zero(Magpie_Sys_Commands_Tbl, sizeof(WMI_DISPATCH_TABLE));
1886 Magpie_Sys_Commands_Tbl->NumberOfEntries = WMI_DISPATCH_ENTRY_COUNT(Magpie_Sys_DispatchEntries);
1887 Magpie_Sys_Commands_Tbl->pTable = Magpie_Sys_DispatchEntries;
1889 adf_os_mem_zero(&wmiConfig, sizeof(WMI_SVC_CONFIG));
1890 wmiConfig.HtcHandle = sc->tgt_htc_handle;
1891 wmiConfig.PoolHandle = sc->pool_handle;
1892 wmiConfig.MaxCmdReplyEvts = ATH_WMI_MAX_CMD_REPLY;
1893 wmiConfig.MaxEventEvts = ATH_WMI_MAX_EVENTS;
1895 sc->tgt_wmi_handle = WMI_Init(&wmiConfig);
1896 Magpie_Sys_Commands_Tbl->pContext = sc;
1897 WMI_RegisterDispatchTable(sc->tgt_wmi_handle, Magpie_Sys_Commands_Tbl);
1899 HTC_NotifyTargetInserted(sc->tgt_htc_handle);
1901 /* Start HTC messages exchange */
1902 HTC_Ready(sc->tgt_htc_handle);
1905 a_int32_t ath_tgt_attach(a_uint32_t devid, struct ath_softc_tgt *sc, adf_os_device_t osdev)
1909 a_int32_t error = 0, i, flags = 0;
1912 adf_os_pci_config_read8(osdev, ATH_PCI_CACHE_LINE_SIZE, &csz);
1916 sc->sc_cachelsz = csz << 2;
1921 ATH_INIT_TQUEUE(sc->sc_dev, &sc->sc_rxtq, ath_tgt_rx_tasklet, sc);
1922 ATH_INIT_TQUEUE(sc->sc_dev, &sc->sc_txtq, owl_tgt_tx_tasklet, sc);
1923 ATH_INIT_TQUEUE(sc->sc_dev, &sc->sc_bmisstq, ath_bmiss_tasklet, sc);
1924 ATH_INIT_TQUEUE(sc->sc_dev, &sc->sc_fataltq, ath_fatal_tasklet, sc);
1926 flags |= AH_USE_EEPROM;
1927 ah = _ath_hal_attach_tgt(devid, sc, sc->sc_dev, flags, &status);
1934 tgt_hif_htc_wmi_init(sc);
1936 sc->sc_bhalq = HAL_NUM_TX_QUEUES - 1;
1938 ath_rate_setup(sc, IEEE80211_MODE_11NA);
1939 ath_rate_setup(sc, IEEE80211_MODE_11NG);
1941 sc->sc_rc = ath_rate_attach(sc);
1942 if (sc->sc_rc == NULL) {
1947 for (i=0; i < TARGET_NODE_MAX; i++) {
1948 sc->sc_sta[i].an_rcnode = adf_os_mem_alloc(sc->sc_rc->arc_space);
1951 error = ath_desc_alloc(sc);
1956 BUF_Pool_create_pool(sc->pool_handle, POOL_ID_WLAN_RX_BUF, ath_numrxdescs, 1664);
1958 ath_tgt_txq_setup(sc);
1960 ah->ah_setInterrupts(ah, 0);
1970 static void tgt_hif_htc_wmi_shutdown(struct ath_softc_tgt *sc)
1972 HTC_NotifyTargetDetached(sc->tgt_htc_handle);
1974 WMI_Shutdown(sc->tgt_wmi_handle);
1975 HTC_Shutdown(sc->tgt_htc_handle);
1976 HIF_shutdown(sc->tgt_hif_handle);
1977 BUF_Pool_shutdown(sc->pool_handle);
1980 a_int32_t ath_detach(struct ath_softc_tgt *sc)
1982 tgt_hif_htc_wmi_shutdown(sc);