xref: /freebsd/sys/dev/rtwn/rtl8192c/r92c_beacon.c (revision ebacd8013fe5f7fdf9f6a5b286f6680dd2891036)
1 /*-
2  * Copyright (c) 2015-2016 Andriy Voskoboinyk <avos@FreeBSD.org>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #include <sys/cdefs.h>
18 __FBSDID("$FreeBSD$");
19 
20 #include "opt_wlan.h"
21 
22 #include <sys/param.h>
23 #include <sys/lock.h>
24 #include <sys/mutex.h>
25 #include <sys/mbuf.h>
26 #include <sys/kernel.h>
27 #include <sys/socket.h>
28 #include <sys/systm.h>
29 #include <sys/malloc.h>
30 #include <sys/queue.h>
31 #include <sys/taskqueue.h>
32 #include <sys/bus.h>
33 #include <sys/endian.h>
34 #include <sys/linker.h>
35 
36 #include <net/if.h>
37 #include <net/ethernet.h>
38 #include <net/if_media.h>
39 
40 #include <net80211/ieee80211_var.h>
41 #include <net80211/ieee80211_radiotap.h>
42 
43 #include <dev/rtwn/if_rtwnvar.h>
44 #include <dev/rtwn/if_rtwnreg.h>
45 
46 #include <dev/rtwn/if_rtwn_ridx.h>
47 
48 #include <dev/rtwn/rtl8192c/r92c.h>
49 #include <dev/rtwn/rtl8192c/r92c_var.h>
50 #include <dev/rtwn/rtl8192c/r92c_reg.h>
51 #include <dev/rtwn/rtl8192c/r92c_tx_desc.h>
52 
53 void
54 r92c_beacon_init(struct rtwn_softc *sc, void *buf, int id)
55 {
56 	struct r92c_tx_desc *txd = (struct r92c_tx_desc *)buf;
57 
58 	/*
59 	 * NB: there is no need to setup HWSEQ_EN bit;
60 	 * QSEL_BEACON already implies it.
61 	 */
62 	txd->flags0 |= R92C_FLAGS0_BMCAST | R92C_FLAGS0_FSG | R92C_FLAGS0_LSG;
63 	txd->txdw1 |= htole32(
64 	    SM(R92C_TXDW1_QSEL, R92C_TXDW1_QSEL_BEACON) |
65 	    SM(R92C_TXDW1_RAID, R92C_RAID_11B));
66 
67 	rtwn_r92c_tx_setup_macid(sc, buf, id);
68 	txd->txdw4 |= htole32(R92C_TXDW4_DRVRATE);
69 	txd->txdw4 |= htole32(SM(R92C_TXDW4_SEQ_SEL, id));
70 	txd->txdw4 |= htole32(SM(R92C_TXDW4_PORT_ID, id));
71 	txd->txdw5 |= htole32(SM(R92C_TXDW5_DATARATE, RTWN_RIDX_CCK1));
72 }
73 
74 void
75 r92c_beacon_enable(struct rtwn_softc *sc, int id, int enable)
76 {
77 
78 	if (enable) {
79 		rtwn_setbits_1(sc, R92C_BCN_CTRL(id),
80 		    0, R92C_BCN_CTRL_EN_BCN);
81 	} else {
82 		rtwn_setbits_1(sc, R92C_BCN_CTRL(id),
83 		    R92C_BCN_CTRL_EN_BCN, 0);
84 	}
85 }
86