xref: /freebsd/sys/dev/rtwn/rtl8192c/pci/r92ce_rx.c (revision a03411e84728e9b267056fd31c7d1d9d1dc1b01e)
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 #include "opt_wlan.h"
23 
24 #include <sys/param.h>
25 #include <sys/lock.h>
26 #include <sys/mutex.h>
27 #include <sys/mbuf.h>
28 #include <sys/kernel.h>
29 #include <sys/socket.h>
30 #include <sys/systm.h>
31 #include <sys/malloc.h>
32 #include <sys/queue.h>
33 #include <sys/taskqueue.h>
34 #include <sys/bus.h>
35 #include <sys/endian.h>
36 #include <sys/linker.h>
37 
38 #include <machine/bus.h>
39 #include <machine/resource.h>
40 #include <sys/rman.h>
41 
42 #include <net/if.h>
43 #include <net/ethernet.h>
44 #include <net/if_media.h>
45 
46 #include <net80211/ieee80211_var.h>
47 #include <net80211/ieee80211_radiotap.h>
48 
49 #include <dev/rtwn/if_rtwnvar.h>
50 #include <dev/rtwn/if_rtwn_debug.h>
51 
52 #include <dev/rtwn/pci/rtwn_pci_var.h>
53 
54 #include <dev/rtwn/rtl8192c/pci/r92ce.h>
55 #include <dev/rtwn/rtl8192c/pci/r92ce_reg.h>
56 
57 int
58 r92ce_get_intr_status(struct rtwn_pci_softc *pc, int *rings)
59 {
60 	struct rtwn_softc *sc = &pc->pc_sc;
61 	uint32_t status;
62 	int ret;
63 
64 	*rings = 0;
65 	status = rtwn_read_4(sc, R92C_HISR);
66 	RTWN_DPRINTF(sc, RTWN_DEBUG_INTR, "%s: HISR %08X, HISRE %04X\n",
67 	    __func__, status, rtwn_read_2(sc, R92C_HISRE));
68 	if (status == 0 || status == 0xffffffff)
69 		return (0);
70 
71 	/* Disable interrupts. */
72 	rtwn_write_4(sc, R92C_HIMR, 0);
73 
74 	/* Ack interrupts. */
75 	rtwn_write_4(sc, R92C_HISR, status);
76 
77 	if (status & R92C_IMR_BDOK)
78 		*rings |= (1 << RTWN_PCI_BEACON_QUEUE);
79 	if (status & R92C_IMR_HIGHDOK)
80 		*rings |= (1 << RTWN_PCI_HIGH_QUEUE);
81 	if (status & R92C_IMR_MGNTDOK)
82 		*rings |= (1 << RTWN_PCI_MGNT_QUEUE);
83 	if (status & R92C_IMR_BKDOK)
84 		*rings |= (1 << RTWN_PCI_BK_QUEUE);
85 	if (status & R92C_IMR_BEDOK)
86 		*rings |= (1 << RTWN_PCI_BE_QUEUE);
87 	if (status & R92C_IMR_VIDOK)
88 		*rings |= (1 << RTWN_PCI_VI_QUEUE);
89 	if (status & R92C_IMR_VODOK)
90 		*rings |= (1 << RTWN_PCI_VO_QUEUE);
91 
92 	ret = 0;
93 	if (status & R92C_IMR_RXFOVW)
94 		ret |= RTWN_PCI_INTR_RX_OVERFLOW;
95 	if (status & R92C_IMR_RDU)
96 		ret |= RTWN_PCI_INTR_RX_DESC_UNAVAIL;
97 	if (status & R92C_IMR_ROK)
98 		ret |= RTWN_PCI_INTR_RX_DONE;
99 	if (status & R92C_IMR_TXFOVW)
100 		ret |= RTWN_PCI_INTR_TX_OVERFLOW;
101 	if (status & R92C_IMR_PSTIMEOUT)
102 		ret |= RTWN_PCI_INTR_PS_TIMEOUT;
103 
104 	return (ret);
105 }
106 
107 #define R92C_INT_ENABLE (R92C_IMR_ROK | R92C_IMR_VODOK | R92C_IMR_VIDOK | \
108 			R92C_IMR_BEDOK | R92C_IMR_BKDOK | R92C_IMR_MGNTDOK | \
109 			R92C_IMR_HIGHDOK | R92C_IMR_BDOK | R92C_IMR_RDU | \
110 			R92C_IMR_RXFOVW)
111 void
112 r92ce_enable_intr(struct rtwn_pci_softc *pc)
113 {
114 	struct rtwn_softc *sc = &pc->pc_sc;
115 
116 	/* Enable interrupts. */
117 	rtwn_write_4(sc, R92C_HIMR, R92C_INT_ENABLE);
118 }
119 
120 void
121 r92ce_start_xfers(struct rtwn_softc *sc)
122 {
123 	/* Clear pending interrupts. */
124 	rtwn_write_4(sc, R92C_HISR, 0xffffffff);
125 
126 	/* Enable interrupts. */
127 	rtwn_write_4(sc, R92C_HIMR, R92C_INT_ENABLE);
128 }
129 #undef R92C_INT_ENABLE
130