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 -------------------------*/ |
Jesper Juhl | ea15b7b | 2012-06-27 22:01:18 +0200 | [diff] [blame^] | 44 | static int msglevel = MSG_LEVEL_INFO; /* MSG_LEVEL_DEBUG */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 45 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 46 | /*--------------------- Static Classes ----------------------------*/ |
| 47 | |
| 48 | /*--------------------- Static Variables --------------------------*/ |
| 49 | |
| 50 | /*--------------------- Static Functions --------------------------*/ |
| 51 | |
| 52 | /*--------------------- Export Variables --------------------------*/ |
| 53 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 54 | /*--------------------- Export Functions --------------------------*/ |
| 55 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 56 | /*+ |
| 57 | * |
| 58 | * Function: InterruptPollingThread |
| 59 | * |
| 60 | * Synopsis: Thread running at IRQL PASSIVE_LEVEL. |
| 61 | * |
| 62 | * Arguments: Device Extension |
| 63 | * |
| 64 | * Returns: |
| 65 | * |
| 66 | * Algorithm: Call USBD for input data; |
| 67 | * |
| 68 | * History: dd-mm-yyyy Author Comment |
| 69 | * |
| 70 | * |
| 71 | * Notes: |
| 72 | * |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 73 | * USB reads are by nature 'Blocking', and when in a read, the device looks |
| 74 | * like it's in a 'stall' condition, so we deliberately time out every second |
| 75 | * if we've gotten no data |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 76 | * |
| 77 | -*/ |
Andres More | 8611a29 | 2010-05-01 14:25:00 -0300 | [diff] [blame] | 78 | void INTvWorkItem(void *Context) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 79 | { |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 80 | PSDevice pDevice = (PSDevice) Context; |
Andres More | 6487c49 | 2010-08-02 20:51:57 -0300 | [diff] [blame] | 81 | int ntStatus; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 82 | |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 83 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Interrupt Polling Thread\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 84 | |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 85 | spin_lock_irq(&pDevice->lock); |
| 86 | if (pDevice->fKillEventPollingThread != TRUE) |
| 87 | ntStatus = PIPEnsInterruptRead(pDevice); |
| 88 | spin_unlock_irq(&pDevice->lock); |
| 89 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 90 | |
Marcos Paulo de Souza | c25b3c9 | 2011-12-20 01:07:00 +0000 | [diff] [blame] | 91 | void INTnsProcessData(PSDevice pDevice) |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 92 | { |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 93 | PSINTData pINTData; |
| 94 | PSMgmtObject pMgmt = &(pDevice->sMgmtObj); |
| 95 | struct net_device_stats *pStats = &pDevice->stats; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 96 | |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 97 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsInterruptProcessData\n"); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 98 | |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 99 | pINTData = (PSINTData) pDevice->intBuf.pDataBuf; |
| 100 | if (pINTData->byTSR0 & TSR_VALID) { |
| 101 | STAvUpdateTDStatCounter(&(pDevice->scStatistic), |
| 102 | (BYTE) (pINTData->byPkt0 & 0x0F), |
| 103 | (BYTE) (pINTData->byPkt0>>4), |
| 104 | pINTData->byTSR0); |
| 105 | BSSvUpdateNodeTxCounter(pDevice, |
| 106 | &(pDevice->scStatistic), |
| 107 | pINTData->byTSR0, |
| 108 | pINTData->byPkt0); |
| 109 | /*DBG_PRN_GRP01(("TSR0 %02x\n", pINTData->byTSR0));*/ |
| 110 | } |
| 111 | if (pINTData->byTSR1 & TSR_VALID) { |
| 112 | STAvUpdateTDStatCounter(&(pDevice->scStatistic), |
| 113 | (BYTE) (pINTData->byPkt1 & 0x0F), |
| 114 | (BYTE) (pINTData->byPkt1>>4), |
| 115 | pINTData->byTSR1); |
| 116 | BSSvUpdateNodeTxCounter(pDevice, |
| 117 | &(pDevice->scStatistic), |
| 118 | pINTData->byTSR1, |
| 119 | pINTData->byPkt1); |
| 120 | /*DBG_PRN_GRP01(("TSR1 %02x\n", pINTData->byTSR1));*/ |
| 121 | } |
| 122 | if (pINTData->byTSR2 & TSR_VALID) { |
| 123 | STAvUpdateTDStatCounter(&(pDevice->scStatistic), |
| 124 | (BYTE) (pINTData->byPkt2 & 0x0F), |
| 125 | (BYTE) (pINTData->byPkt2>>4), |
| 126 | pINTData->byTSR2); |
| 127 | BSSvUpdateNodeTxCounter(pDevice, |
| 128 | &(pDevice->scStatistic), |
| 129 | pINTData->byTSR2, |
| 130 | pINTData->byPkt2); |
| 131 | /*DBG_PRN_GRP01(("TSR2 %02x\n", pINTData->byTSR2));*/ |
| 132 | } |
| 133 | if (pINTData->byTSR3 & TSR_VALID) { |
| 134 | STAvUpdateTDStatCounter(&(pDevice->scStatistic), |
| 135 | (BYTE) (pINTData->byPkt3 & 0x0F), |
| 136 | (BYTE) (pINTData->byPkt3>>4), |
| 137 | pINTData->byTSR3); |
| 138 | BSSvUpdateNodeTxCounter(pDevice, |
| 139 | &(pDevice->scStatistic), |
| 140 | pINTData->byTSR3, |
| 141 | pINTData->byPkt3); |
| 142 | /*DBG_PRN_GRP01(("TSR3 %02x\n", pINTData->byTSR3));*/ |
| 143 | } |
| 144 | if (pINTData->byISR0 != 0) { |
| 145 | if (pINTData->byISR0 & ISR_BNTX) { |
| 146 | if (pDevice->eOPMode == OP_MODE_AP) { |
| 147 | if (pMgmt->byDTIMCount > 0) { |
| 148 | pMgmt->byDTIMCount--; |
| 149 | pMgmt->sNodeDBTable[0].bRxPSPoll = |
| 150 | FALSE; |
| 151 | } else if (pMgmt->byDTIMCount == 0) { |
| 152 | /* check if mutltcast tx bufferring */ |
| 153 | pMgmt->byDTIMCount = |
| 154 | pMgmt->byDTIMPeriod-1; |
| 155 | pMgmt->sNodeDBTable[0].bRxPSPoll = TRUE; |
| 156 | if (pMgmt->sNodeDBTable[0].bPSEnable) |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 157 | bScheduleCommand((void *) pDevice, |
| 158 | WLAN_CMD_RX_PSPOLL, |
| 159 | NULL); |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 160 | } |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 161 | bScheduleCommand((void *) pDevice, |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 162 | WLAN_CMD_BECON_SEND, |
| 163 | NULL); |
| 164 | } /* if (pDevice->eOPMode == OP_MODE_AP) */ |
| 165 | pDevice->bBeaconSent = TRUE; |
| 166 | } else { |
| 167 | pDevice->bBeaconSent = FALSE; |
| 168 | } |
| 169 | if (pINTData->byISR0 & ISR_TBTT) { |
| 170 | if (pDevice->bEnablePSMode) |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 171 | bScheduleCommand((void *) pDevice, |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 172 | WLAN_CMD_TBTT_WAKEUP, |
| 173 | NULL); |
| 174 | if (pDevice->bChannelSwitch) { |
| 175 | pDevice->byChannelSwitchCount--; |
| 176 | if (pDevice->byChannelSwitchCount == 0) |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 177 | bScheduleCommand((void *) pDevice, |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 178 | WLAN_CMD_11H_CHSW, |
| 179 | NULL); |
| 180 | } |
| 181 | } |
| 182 | LODWORD(pDevice->qwCurrTSF) = pINTData->dwLoTSF; |
| 183 | HIDWORD(pDevice->qwCurrTSF) = pINTData->dwHiTSF; |
| 184 | /*DBG_PRN_GRP01(("ISR0 = %02x , |
| 185 | LoTsf = %08x, |
| 186 | HiTsf = %08x\n", |
| 187 | pINTData->byISR0, |
| 188 | pINTData->dwLoTSF, |
| 189 | pINTData->dwHiTSF)); */ |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 190 | |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 191 | STAvUpdate802_11Counter(&pDevice->s802_11Counter, |
| 192 | &pDevice->scStatistic, |
| 193 | pINTData->byRTSSuccess, |
| 194 | pINTData->byRTSFail, |
| 195 | pINTData->byACKFail, |
| 196 | pINTData->byFCSErr); |
| 197 | STAvUpdateIsrStatCounter(&pDevice->scStatistic, |
| 198 | pINTData->byISR0, |
| 199 | pINTData->byISR1); |
| 200 | } |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 201 | if (pINTData->byISR1 != 0) |
| 202 | if (pINTData->byISR1 & ISR_GPIO3) |
Andres More | 0cbd8d9 | 2010-05-06 20:34:29 -0300 | [diff] [blame] | 203 | bScheduleCommand((void *) pDevice, |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 204 | WLAN_CMD_RADIO, |
| 205 | NULL); |
| 206 | pDevice->intBuf.uDataLen = 0; |
| 207 | pDevice->intBuf.bInUse = FALSE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 208 | |
Daniel Kenji Toyama | ff8041b | 2010-03-30 00:28:19 +1100 | [diff] [blame] | 209 | pStats->tx_packets = pDevice->scStatistic.ullTsrOK; |
| 210 | pStats->tx_bytes = pDevice->scStatistic.ullTxDirectedBytes + |
| 211 | pDevice->scStatistic.ullTxMulticastBytes + |
| 212 | pDevice->scStatistic.ullTxBroadcastBytes; |
| 213 | pStats->tx_errors = pDevice->scStatistic.dwTsrErr; |
| 214 | pStats->tx_dropped = pDevice->scStatistic.dwTsrErr; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 215 | } |