xref: /freebsd/sys/dev/rtwn/rtl8192c/pci/r92ce_rx.c (revision cdebaff820b2a4915a16cedfd511823d78aab171)
1 /*	$OpenBSD: if_rtwn.c,v 1.6 2015/08/28 00:03:53 deraadt Exp $	*/
2 
3 /*-
4  * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
5  * Copyright (c) 2015 Stefan Sperling <stsp@openbsd.org>
6  * Copyright (c) 2016 Andriy Voskoboinyk <avos@FreeBSD.org>
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 #include <sys/cdefs.h>
22 __FBSDID("$FreeBSD$");
23 
24 #include "opt_wlan.h"
25 
26 #include <sys/param.h>
27 #include <sys/lock.h>
28 #include <sys/mutex.h>
29 #include <sys/mbuf.h>
30 #include <sys/kernel.h>
31 #include <sys/socket.h>
32 #include <sys/systm.h>
33 #include <sys/malloc.h>
34 #include <sys/queue.h>
35 #include <sys/taskqueue.h>
36 #include <sys/bus.h>
37 #include <sys/endian.h>
38 #include <sys/linker.h>
39 
40 #include <machine/bus.h>
41 #include <machine/resource.h>
42 #include <sys/rman.h>
43 
44 #include <net/if.h>
45 #include <net/ethernet.h>
46 #include <net/if_media.h>
47 
48 #include <net80211/ieee80211_var.h>
49 #include <net80211/ieee80211_radiotap.h>
50 
51 #include <dev/rtwn/if_rtwnvar.h>
52 #include <dev/rtwn/if_rtwn_debug.h>
53 
54 #include <dev/rtwn/pci/rtwn_pci_var.h>
55 
56 #include <dev/rtwn/rtl8192c/pci/r92ce.h>
57 #include <dev/rtwn/rtl8192c/pci/r92ce_reg.h>
58 
59 
60 int
61 r92ce_classify_intr(struct rtwn_softc *sc, void *arg, int len __unused)
62 {
63 	uint32_t status;
64 	int *rings = arg;
65 	int ret;
66 
67 	*rings = 0;
68 	status = rtwn_read_4(sc, R92C_HISR);
69 	RTWN_DPRINTF(sc, RTWN_DEBUG_INTR, "%s: HISR %08X, HISRE %04X\n",
70 	    __func__, status, rtwn_read_2(sc, R92C_HISRE));
71 	if (status == 0 || status == 0xffffffff)
72 		return (0);
73 
74 	/* Disable interrupts. */
75 	rtwn_write_4(sc, R92C_HIMR, 0);
76 
77 	/* Ack interrupts. */
78 	rtwn_write_4(sc, R92C_HISR, status);
79 
80 	if (status & R92C_IMR_BDOK)
81 		*rings |= (1 << RTWN_PCI_BEACON_QUEUE);
82 	if (status & R92C_IMR_HIGHDOK)
83 		*rings |= (1 << RTWN_PCI_HIGH_QUEUE);
84 	if (status & R92C_IMR_MGNTDOK)
85 		*rings |= (1 << RTWN_PCI_MGNT_QUEUE);
86 	if (status & R92C_IMR_BKDOK)
87 		*rings |= (1 << RTWN_PCI_BK_QUEUE);
88 	if (status & R92C_IMR_BEDOK)
89 		*rings |= (1 << RTWN_PCI_BE_QUEUE);
90 	if (status & R92C_IMR_VIDOK)
91 		*rings |= (1 << RTWN_PCI_VI_QUEUE);
92 	if (status & R92C_IMR_VODOK)
93 		*rings |= (1 << RTWN_PCI_VO_QUEUE);
94 
95 	ret = 0;
96 	if (status & R92C_IMR_RXFOVW)
97 		ret |= RTWN_PCI_INTR_RX_OVERFLOW;
98 	if (status & R92C_IMR_RDU)
99 		ret |= RTWN_PCI_INTR_RX_DESC_UNAVAIL;
100 	if (status & R92C_IMR_ROK)
101 		ret |= RTWN_PCI_INTR_RX_DONE;
102 	if (status & R92C_IMR_TXFOVW)
103 		ret |= RTWN_PCI_INTR_TX_OVERFLOW;
104 	if (status & R92C_IMR_PSTIMEOUT)
105 		ret |= RTWN_PCI_INTR_PS_TIMEOUT;
106 
107 	return (ret);
108 }
109 
110 #define R92C_INT_ENABLE (R92C_IMR_ROK | R92C_IMR_VODOK | R92C_IMR_VIDOK | \
111 			R92C_IMR_BEDOK | R92C_IMR_BKDOK | R92C_IMR_MGNTDOK | \
112 			R92C_IMR_HIGHDOK | R92C_IMR_BDOK | R92C_IMR_RDU | \
113 			R92C_IMR_RXFOVW)
114 void
115 r92ce_enable_intr(struct rtwn_pci_softc *pc)
116 {
117 	struct rtwn_softc *sc = &pc->pc_sc;
118 
119 	/* Enable interrupts. */
120 	rtwn_write_4(sc, R92C_HIMR, R92C_INT_ENABLE);
121 }
122 
123 void
124 r92ce_start_xfers(struct rtwn_softc *sc)
125 {
126 	/* Clear pending interrupts. */
127 	rtwn_write_4(sc, R92C_HISR, 0xffffffff);
128 
129 	/* Enable interrupts. */
130 	rtwn_write_4(sc, R92C_HIMR, R92C_INT_ENABLE);
131 }
132 #undef R92C_INT_ENABLE
133