Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * |
| 20 | * File: int.c |
| 21 | * |
| 22 | * Purpose: Handle USB interrupt endpoint |
| 23 | * |
| 24 | * Author: Jerry Chen |
| 25 | * |
| 26 | * Date: Apr. 2, 2004 |
| 27 | * |
| 28 | * Functions: |
| 29 | * |
| 30 | * Revision History: |
| 31 | * 04-02-2004 Jerry Chen: Initial release |
| 32 | * |
| 33 | */ |
| 34 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 35 | #include "int.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 36 | #include "mib.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 37 | #include "tmacro.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 38 | #include "mac.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 39 | #include "power.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 40 | #include "bssdb.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 41 | #include "usbpipe.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 42 | |
| 43 | /*--------------------- Static Definitions -------------------------*/ |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 44 | /* static int msglevel = MSG_LEVEL_DEBUG; */ |
| 45 | static int msglevel = MSG_LEVEL_INFO; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 46 | |
| 47 | |
| 48 | /*--------------------- Static Classes ----------------------------*/ |
| 49 | |
| 50 | /*--------------------- Static Variables --------------------------*/ |
| 51 | |
| 52 | /*--------------------- Static Functions --------------------------*/ |
| 53 | |
| 54 | /*--------------------- Export Variables --------------------------*/ |
| 55 | |
| 56 | |
| 57 | /*--------------------- Export Functions --------------------------*/ |
| 58 | |
| 59 | |
| 60 | /*+ |
| 61 | * |
| 62 | * Function: InterruptPollingThread |
| 63 | * |
| 64 | * Synopsis: Thread running at IRQL PASSIVE_LEVEL. |
| 65 | * |
| 66 | * Arguments: Device Extension |
| 67 | * |
| 68 | * Returns: |
| 69 | * |
| 70 | * Algorithm: Call USBD for input data; |
| 71 | * |
| 72 | * History: dd-mm-yyyy Author Comment |
| 73 | * |
| 74 | * |
| 75 | * Notes: |
| 76 | * |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 77 | * USB reads are by nature 'Blocking', and when in a read, the device looks |
| 78 | * like it's in a 'stall' condition, so we deliberately time out every second |
| 79 | * if we've gotten no data |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 80 | * |
| 81 | -*/ |
Andres More | 8611a29 | 2010-05-01 14:25:00 -0300 | [diff] [blame] | 82 | void INTvWorkItem(void *Context) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 83 | { |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 84 | PSDevice pDevice = (PSDevice) Context; |
Andres More | 6487c49 | 2010-08-02 20:51:57 -0300 | [diff] [blame] | 85 | int ntStatus; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 86 | |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 87 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Interrupt Polling Thread\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 88 | |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 89 | spin_lock_irq(&pDevice->lock); |
| 90 | if (pDevice->fKillEventPollingThread != TRUE) |
| 91 | ntStatus = PIPEnsInterruptRead(pDevice); |
| 92 | spin_unlock_irq(&pDevice->lock); |
| 93 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 94 | |
Andres More | 6487c49 | 2010-08-02 20:51:57 -0300 | [diff] [blame] | 95 | int INTnsProcessData(PSDevice pDevice) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 96 | { |
Andres More | 6487c49 | 2010-08-02 20:51:57 -0300 | [diff] [blame] | 97 | int status = STATUS_SUCCESS; |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 98 | PSINTData pINTData; |
| 99 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
| 100 | struct net_device_stats *pStats = &pDevice->stats; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 101 | |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 102 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsInterruptProcessData\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 103 | |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 104 | pINTData = (PSINTData) pDevice->intBuf.pDataBuf; |
| 105 | if (pINTData->byTSR0 & TSR_VALID) { |
| 106 | STAvUpdateTDStatCounter(&(pDevice->scStatistic), |
| 107 | (BYTE) (pINTData->byPkt0 & 0x0F), |
| 108 | (BYTE) (pINTData->byPkt0>>4), |
| 109 | pINTData->byTSR0); |
| 110 | BSSvUpdateNodeTxCounter(pDevice, |
| 111 | &(pDevice->scStatistic), |
| 112 | pINTData->byTSR0, |
| 113 | pINTData->byPkt0); |
| 114 | /*DBG_PRN_GRP01(("TSR0 %02x\n", pINTData->byTSR0));*/ |
| 115 | } |
| 116 | if (pINTData->byTSR1 & TSR_VALID) { |
| 117 | STAvUpdateTDStatCounter(&(pDevice->scStatistic), |
| 118 | (BYTE) (pINTData->byPkt1 & 0x0F), |
| 119 | (BYTE) (pINTData->byPkt1>>4), |
| 120 | pINTData->byTSR1); |
| 121 | BSSvUpdateNodeTxCounter(pDevice, |
| 122 | &(pDevice->scStatistic), |
| 123 | pINTData->byTSR1, |
| 124 | pINTData->byPkt1); |
| 125 | /*DBG_PRN_GRP01(("TSR1 %02x\n", pINTData->byTSR1));*/ |
| 126 | } |
| 127 | if (pINTData->byTSR2 & TSR_VALID) { |
| 128 | STAvUpdateTDStatCounter(&(pDevice->scStatistic), |
| 129 | (BYTE) (pINTData->byPkt2 & 0x0F), |
| 130 | (BYTE) (pINTData->byPkt2>>4), |
| 131 | pINTData->byTSR2); |
| 132 | BSSvUpdateNodeTxCounter(pDevice, |
| 133 | &(pDevice->scStatistic), |
| 134 | pINTData->byTSR2, |
| 135 | pINTData->byPkt2); |
| 136 | /*DBG_PRN_GRP01(("TSR2 %02x\n", pINTData->byTSR2));*/ |
| 137 | } |
| 138 | if (pINTData->byTSR3 & TSR_VALID) { |
| 139 | STAvUpdateTDStatCounter(&(pDevice->scStatistic), |
| 140 | (BYTE) (pINTData->byPkt3 & 0x0F), |
| 141 | (BYTE) (pINTData->byPkt3>>4), |
| 142 | pINTData->byTSR3); |
| 143 | BSSvUpdateNodeTxCounter(pDevice, |
| 144 | &(pDevice->scStatistic), |
| 145 | pINTData->byTSR3, |
| 146 | pINTData->byPkt3); |
| 147 | /*DBG_PRN_GRP01(("TSR3 %02x\n", pINTData->byTSR3));*/ |
| 148 | } |
| 149 | if (pINTData->byISR0 != 0) { |
| 150 | if (pINTData->byISR0 & ISR_BNTX) { |
| 151 | if (pDevice->eOPMode == OP_MODE_AP) { |
| 152 | if (pMgmt->byDTIMCount > 0) { |
| 153 | pMgmt->byDTIMCount--; |
| 154 | pMgmt->sNodeDBTable[0].bRxPSPoll = |
| 155 | FALSE; |
| 156 | } else if (pMgmt->byDTIMCount == 0) { |
| 157 | /* check if mutltcast tx bufferring */ |
| 158 | pMgmt->byDTIMCount = |
| 159 | pMgmt->byDTIMPeriod-1; |
| 160 | pMgmt->sNodeDBTable[0].bRxPSPoll = TRUE; |
| 161 | if (pMgmt->sNodeDBTable[0].bPSEnable) |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 162 | bScheduleCommand((void *) pDevice, |
| 163 | WLAN_CMD_RX_PSPOLL, |
| 164 | NULL); |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 165 | } |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 166 | bScheduleCommand((void *) pDevice, |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 167 | WLAN_CMD_BECON_SEND, |
| 168 | NULL); |
| 169 | } /* if (pDevice->eOPMode == OP_MODE_AP) */ |
| 170 | pDevice->bBeaconSent = TRUE; |
| 171 | } else { |
| 172 | pDevice->bBeaconSent = FALSE; |
| 173 | } |
| 174 | if (pINTData->byISR0 & ISR_TBTT) { |
| 175 | if (pDevice->bEnablePSMode) |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 176 | bScheduleCommand((void *) pDevice, |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 177 | WLAN_CMD_TBTT_WAKEUP, |
| 178 | NULL); |
| 179 | if (pDevice->bChannelSwitch) { |
| 180 | pDevice->byChannelSwitchCount--; |
| 181 | if (pDevice->byChannelSwitchCount == 0) |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 182 | bScheduleCommand((void *) pDevice, |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 183 | WLAN_CMD_11H_CHSW, |
| 184 | NULL); |
| 185 | } |
| 186 | } |
| 187 | LODWORD(pDevice->qwCurrTSF) = pINTData->dwLoTSF; |
| 188 | HIDWORD(pDevice->qwCurrTSF) = pINTData->dwHiTSF; |
| 189 | /*DBG_PRN_GRP01(("ISR0 = %02x , |
| 190 | LoTsf = %08x, |
| 191 | HiTsf = %08x\n", |
| 192 | pINTData->byISR0, |
| 193 | pINTData->dwLoTSF, |
| 194 | pINTData->dwHiTSF)); */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 195 | |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 196 | STAvUpdate802_11Counter(&pDevice->s802_11Counter, |
| 197 | &pDevice->scStatistic, |
| 198 | pINTData->byRTSSuccess, |
| 199 | pINTData->byRTSFail, |
| 200 | pINTData->byACKFail, |
| 201 | pINTData->byFCSErr); |
| 202 | STAvUpdateIsrStatCounter(&pDevice->scStatistic, |
| 203 | pINTData->byISR0, |
| 204 | pINTData->byISR1); |
| 205 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 206 | |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 207 | if (pINTData->byISR1 != 0) |
| 208 | if (pINTData->byISR1 & ISR_GPIO3) |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 209 | bScheduleCommand((void *) pDevice, |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 210 | WLAN_CMD_RADIO, |
| 211 | NULL); |
| 212 | pDevice->intBuf.uDataLen = 0; |
| 213 | pDevice->intBuf.bInUse = FALSE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 214 | |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 215 | pStats->tx_packets = pDevice->scStatistic.ullTsrOK; |
| 216 | pStats->tx_bytes = pDevice->scStatistic.ullTxDirectedBytes + |
| 217 | pDevice->scStatistic.ullTxMulticastBytes + |
| 218 | pDevice->scStatistic.ullTxBroadcastBytes; |
| 219 | pStats->tx_errors = pDevice->scStatistic.dwTsrErr; |
| 220 | pStats->tx_dropped = pDevice->scStatistic.dwTsrErr; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 221 | |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 222 | return status; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 223 | } |