1 /*- 2 * Copyright (c) 2017 Farhan Khan <khanzf@gmail.com> 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 #include "opt_wlan.h" 19 20 #include <sys/param.h> 21 #include <sys/lock.h> 22 #include <sys/mutex.h> 23 #include <sys/mbuf.h> 24 #include <sys/kernel.h> 25 #include <sys/socket.h> 26 #include <sys/systm.h> 27 #include <sys/malloc.h> 28 #include <sys/queue.h> 29 #include <sys/taskqueue.h> 30 #include <sys/bus.h> 31 #include <sys/endian.h> 32 #include <sys/linker.h> 33 34 #include <machine/bus.h> 35 #include <machine/resource.h> 36 #include <sys/rman.h> 37 38 #include <net/if.h> 39 #include <net/ethernet.h> 40 #include <net/if_media.h> 41 42 #include <net80211/ieee80211_var.h> 43 #include <net80211/ieee80211_radiotap.h> 44 45 #include <dev/rtwn/if_rtwnvar.h> 46 #include <dev/rtwn/if_rtwn_debug.h> 47 48 #include <dev/rtwn/pci/rtwn_pci_var.h> 49 50 #include <dev/rtwn/rtl8188e/pci/r88ee.h> 51 #include <dev/rtwn/rtl8188e/pci/r88ee_reg.h> 52 53 int 54 r88ee_get_intr_status(struct rtwn_pci_softc *pc, int *rings) 55 { 56 struct rtwn_softc *sc = &pc->pc_sc; 57 uint32_t status, status_ex; 58 int ret; 59 60 *rings = 0; 61 status = rtwn_read_4(sc, R88E_HISR); 62 status_ex = rtwn_read_4(sc, R88E_HISRE); 63 RTWN_DPRINTF(sc, RTWN_DEBUG_INTR, "%s: HISR %08X, HISRE %08X\n", 64 __func__, status, status_ex); 65 if ((status == 0 || status == 0xffffffff) && 66 (status_ex == 0 || status_ex == 0xffffffff)) 67 return (0); 68 69 /* Disable interrupts */ 70 rtwn_write_4(sc, R88E_HIMR, 0); 71 rtwn_write_4(sc, R88E_HIMRE, 0); 72 73 /* Ack interrupts */ 74 rtwn_write_4(sc, R88E_HISR, status); 75 rtwn_write_4(sc, R88E_HISRE, status_ex); 76 77 if (status & R88E_HIMR_HIGHDOK) 78 *rings |= (1 << RTWN_PCI_HIGH_QUEUE); 79 if (status & R88E_HIMR_MGNTDOK) 80 *rings |= (1 << RTWN_PCI_MGNT_QUEUE); 81 if (status & R88E_HIMR_BKDOK) 82 *rings |= (1 << RTWN_PCI_BK_QUEUE); 83 if (status & R88E_HIMR_BEDOK) 84 *rings |= (1 << RTWN_PCI_BE_QUEUE); 85 if (status & R88E_HIMR_VIDOK) 86 *rings |= (1 << RTWN_PCI_VI_QUEUE); 87 if (status & R88E_HIMR_VODOK) 88 *rings |= (1 << RTWN_PCI_VO_QUEUE); 89 90 ret = 0; 91 if (status_ex & R88E_HIMRE_RXERR) 92 ret |= RTWN_PCI_INTR_RX_ERROR; 93 if (status_ex & R88E_HIMRE_RXFOVW) 94 ret |= RTWN_PCI_INTR_RX_OVERFLOW; 95 if (status & R88E_HIMR_RDU) 96 ret |= RTWN_PCI_INTR_RX_DESC_UNAVAIL; 97 if (status & R88E_HIMR_ROK) 98 ret |= RTWN_PCI_INTR_RX_DONE; 99 if (status_ex & R88E_HIMRE_TXERR) 100 ret |= RTWN_PCI_INTR_TX_ERROR; 101 if (status_ex & R88E_HIMRE_TXFOVW) 102 ret |= RTWN_PCI_INTR_TX_OVERFLOW; 103 if (status & R88E_HIMR_TXRPT) 104 ret |= RTWN_PCI_INTR_TX_REPORT; 105 if (status & R88E_HIMR_PSTIMEOUT) 106 ret |= RTWN_PCI_INTR_PS_TIMEOUT; 107 108 return (ret); 109 } 110 111 #define R88E_INT_ENABLE (R88E_HIMR_ROK | R88E_HIMR_RDU | R88E_HIMR_VODOK | \ 112 R88E_HIMR_VIDOK | R88E_HIMR_BEDOK | \ 113 R88E_HIMR_BKDOK | R88E_HIMR_MGNTDOK | \ 114 R88E_HIMR_HIGHDOK | R88E_HIMR_TXRPT) 115 116 #define R88E_INT_ENABLE_EX (R88E_HIMRE_RXFOVW | R88E_HIMRE_RXERR) 117 118 void 119 r88ee_enable_intr(struct rtwn_pci_softc *pc) 120 { 121 struct rtwn_softc *sc = &pc->pc_sc; 122 123 /* Enable interrupts */ 124 rtwn_write_4(sc, R88E_HIMR, R88E_INT_ENABLE); 125 rtwn_write_4(sc, R88E_HIMRE, R88E_INT_ENABLE_EX); 126 } 127 128 void 129 r88ee_start_xfers(struct rtwn_softc *sc) 130 { 131 /* Clear pending interrupts. */ 132 rtwn_write_4(sc, R88E_HISR, 0xffffffff); 133 rtwn_write_4(sc, R88E_HISRE, 0xffffffff); 134 135 /* Enable interrupts. */ 136 rtwn_write_4(sc, R88E_HIMR, R88E_INT_ENABLE); 137 rtwn_write_4(sc, R88E_HIMRE, R88E_INT_ENABLE_EX); 138 } 139 140 #undef R88E_INT_ENABLE 141 #undef R88E_INT_ENABLE_EX 142