Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

919 lines
25 KiB

4 years ago
  1. /***************************************************************************
  2. *
  3. * DISPATCH.C
  4. *
  5. * FastMAC Plus based NDIS3 miniport driver dispatch routines. This module
  6. * contains all of the upper interface functions that are not purely
  7. * for initialization and closedown (i.e. DriverEntry, MadgeInitialize
  8. * and MadgeHalt) excluding MadgeSetInformation and MadgeQueryInformation.
  9. *
  10. * Copyright (c) Madge Networks Ltd 1994
  11. *
  12. * COMPANY CONFIDENTIAL
  13. *
  14. * Created: PBA 21/06/1994
  15. *
  16. ****************************************************************************/
  17. #include <ndis.h>
  18. #include "ftk_defs.h"
  19. #include "ftk_intr.h"
  20. #include "ftk_extr.h"
  21. #include "mdgmport.upd"
  22. #include "ndismod.h"
  23. /****************************************************************************
  24. *
  25. * Function - MadgeGetAdapterStatus
  26. *
  27. * Parameters - systemSpecific1 -> Unused.
  28. * context -> Actually a pointer to our NDIS3 level
  29. * adapter structure.
  30. * systemSpecific2 -> Unused.
  31. * systemSpecific3 -> Unused.
  32. *
  33. * Purpose - This function is called of a timer tick and notifies
  34. * open bindings of any interesting events.
  35. *
  36. * Returns - Nothing.
  37. *
  38. ****************************************************************************/
  39. VOID
  40. MadgeGetAdapterStatus(
  41. PVOID systemSpecific1,
  42. PVOID context,
  43. PVOID systemSpecific2,
  44. PVOID systemSpecific3
  45. )
  46. {
  47. PMADGE_ADAPTER ndisAdap;
  48. NDIS_STATUS notifyStatus;
  49. WORD ringStatus;
  50. //
  51. // Do some pre-calculation.
  52. //
  53. ndisAdap = (PMADGE_ADAPTER) context;
  54. notifyStatus = 0;
  55. ringStatus = ndisAdap->CurrentRingStatus;
  56. if (ndisAdap->CurrentRingState == NdisRingStateOpened)
  57. {
  58. //
  59. // WARNING: If the adapter has been shutdown, this will return zero
  60. // in the two fields.
  61. //
  62. driver_get_open_and_ring_status(
  63. ndisAdap->FtkAdapterHandle,
  64. &ndisAdap->CurrentRingStatus,
  65. &ndisAdap->LastOpenStatus
  66. );
  67. if (ringStatus != ndisAdap->CurrentRingStatus)
  68. {
  69. if (ndisAdap->CurrentRingStatus & RING_STATUS_RING_RECOVERY)
  70. {
  71. notifyStatus |= NDIS_RING_RING_RECOVERY;
  72. }
  73. if (ndisAdap->CurrentRingStatus & RING_STATUS_SINGLE_STATION)
  74. {
  75. notifyStatus |= NDIS_RING_SINGLE_STATION;
  76. }
  77. if (ndisAdap->CurrentRingStatus & RING_STATUS_COUNTER_OVERFLOW)
  78. {
  79. notifyStatus |= NDIS_RING_COUNTER_OVERFLOW;
  80. }
  81. if (ndisAdap->CurrentRingStatus & RING_STATUS_REMOVE_RECEIVED)
  82. {
  83. notifyStatus |= NDIS_RING_REMOVE_RECEIVED;
  84. }
  85. if (ndisAdap->CurrentRingStatus & RING_STATUS_AUTO_REMOVAL)
  86. {
  87. notifyStatus |= NDIS_RING_AUTO_REMOVAL_ERROR;
  88. }
  89. if (ndisAdap->CurrentRingStatus & RING_STATUS_LOBE_FAULT)
  90. {
  91. notifyStatus |= NDIS_RING_LOBE_WIRE_FAULT;
  92. }
  93. if (ndisAdap->CurrentRingStatus & RING_STATUS_TRANSMIT_BEACON)
  94. {
  95. notifyStatus |= NDIS_RING_TRANSMIT_BEACON;
  96. }
  97. if (ndisAdap->CurrentRingStatus & RING_STATUS_SOFT_ERROR)
  98. {
  99. notifyStatus |= NDIS_RING_SOFT_ERROR;
  100. }
  101. if (ndisAdap->CurrentRingStatus & RING_STATUS_HARD_ERROR)
  102. {
  103. notifyStatus |= NDIS_RING_HARD_ERROR;
  104. }
  105. if (ndisAdap->CurrentRingStatus & RING_STATUS_SIGNAL_LOSS)
  106. {
  107. notifyStatus |= NDIS_RING_SIGNAL_LOSS;
  108. }
  109. if (notifyStatus != 0)
  110. {
  111. NdisMIndicateStatus(
  112. ndisAdap->UsedInISR.MiniportHandle,
  113. NDIS_STATUS_RING_STATUS,
  114. (PVOID) &notifyStatus,
  115. sizeof(notifyStatus)
  116. );
  117. NdisMIndicateStatusComplete(
  118. ndisAdap->UsedInISR.MiniportHandle
  119. );
  120. MadgePrint2(
  121. "Ring Status %04x\n", ndisAdap->CurrentRingStatus);
  122. }
  123. }
  124. }
  125. //
  126. // Just before we go, clear the JustReadErrorLog flag, so that requests
  127. // for statistics will cause an SRB to be issued every now and then.
  128. //
  129. ndisAdap->JustReadErrorLog = 0;
  130. //
  131. // And finally re-arm the timer.
  132. //
  133. NdisMSetTimer(&ndisAdap->WakeUpTimer, EVERY_2_SECONDS);
  134. }
  135. /****************************************************************************
  136. *
  137. * Function - MadgeCheckForHang
  138. *
  139. * Parameters - adapterContext -> A pointer to our NDIS adapter structure.
  140. *
  141. * Purpose - Process a call from the NDIS3 wrapper to check if
  142. * an adapter has hung.
  143. *
  144. * Returns - We always return FALSE since the only action the wrapper
  145. * can take is to invoke a reset, which we don't support
  146. * anyway.
  147. *
  148. ****************************************************************************/
  149. BOOLEAN
  150. MadgeCheckForHang(NDIS_HANDLE adapterContext)
  151. {
  152. return FALSE;
  153. }
  154. /****************************************************************************
  155. *
  156. * Function - MadgeReset
  157. *
  158. * Parameters - adapterContext -> A pointer to our NDIS adapter structure.
  159. * addressReset -> Ignored.
  160. *
  161. * Purpose - Process a call from the NDIS3 wrapper to reset an
  162. * adapter.
  163. *
  164. * Returns - NDIS_STATUS_NOT_RESETTABLE as we don't support resets.
  165. *
  166. ****************************************************************************/
  167. NDIS_STATUS
  168. MadgeReset(PBOOLEAN addressReset, NDIS_HANDLE adapterContext)
  169. {
  170. MadgePrint1("MadgeReset\n");
  171. MadgePrint2(
  172. "ndisAdap = %x\n",
  173. PMADGE_ADAPTER_FROM_CONTEXT(adapterContext)
  174. );
  175. return NDIS_STATUS_NOT_RESETTABLE;
  176. }
  177. /****************************************************************************
  178. *
  179. * Function - MadgeDisableInterrupts
  180. *
  181. * Parameters - adapterContext -> A pointer to our NDIS adapter structure.
  182. *
  183. * Purpose - Process a call from the NDIS3 wrapper to turn adapter
  184. * interrupts off.
  185. *
  186. * Returns - Nothing.
  187. *
  188. ****************************************************************************/
  189. VOID
  190. MadgeDisableInterrupts(NDIS_HANDLE adapterContext)
  191. {
  192. // MadgePrint1("MadgeDisableInterrupts\n");
  193. //
  194. // Note: it is very difficult for use to disble interrupts at the
  195. // adapter so we don't. We use a spin lock to protect our DPR
  196. // routine.
  197. //
  198. }
  199. /****************************************************************************
  200. *
  201. * Function - MadgeEnableInterrupts
  202. *
  203. * Parameters - adapterContext -> A pointer to our NDIS adapter structure.
  204. *
  205. * Purpose - Process a call from the NDIS3 wrapper to turn adapter
  206. * interrupts on.
  207. *
  208. * Returns - Nothing.
  209. *
  210. ****************************************************************************/
  211. VOID
  212. MadgeEnableInterrupts(NDIS_HANDLE adapterContext)
  213. {
  214. // MadgePrint1("MadgeEnableInterrupts\n");
  215. //
  216. // Note: it is very difficult for use to disble interrupts at the
  217. // adapter so we don't. We use a spin lock to protect our DPR
  218. // routine.
  219. //
  220. }
  221. /****************************************************************************
  222. *
  223. * Function - MadgeSend
  224. *
  225. * Parameters - adapterContext -> Pointer to our NDIS level adapter
  226. * structure.
  227. * packet -> Pointer to the NDIS3 packet to send.
  228. * flags -> Optional flags.
  229. *
  230. * Purpose - Called by the NDIS3 wrapper when it wants us to send a
  231. * frame.
  232. *
  233. * Returns - NDIS3 status code.
  234. *
  235. ****************************************************************************/
  236. NDIS_STATUS
  237. MadgeSend(NDIS_HANDLE adapterContext, PNDIS_PACKET packet, UINT flags)
  238. {
  239. ULONG *pagePtr;
  240. UINT pageCount;
  241. UINT physFrags;
  242. UINT i;
  243. UINT size;
  244. UINT bytes;
  245. UINT count;
  246. NDIS_BUFFER *bufPtr;
  247. NDIS_STATUS retCode;
  248. PMADGE_ADAPTER ndisAdap;
  249. UINT totalPacketSize;
  250. WORD status;
  251. //
  252. // Set up a pointer to our adapter handle.
  253. //
  254. ndisAdap = PMADGE_ADAPTER_FROM_CONTEXT(adapterContext);
  255. //
  256. // Find out how long the frame is and where it's header is.
  257. //
  258. NdisQueryPacket(packet, NULL, NULL, NULL, &totalPacketSize);
  259. //
  260. // Make sure the frame isn't too long or two short.
  261. //
  262. if (totalPacketSize > ndisAdap->MaxFrameSize ||
  263. totalPacketSize < FRAME_HEADER_SIZE)
  264. {
  265. retCode = NDIS_STATUS_INVALID_PACKET;
  266. }
  267. //
  268. // Check that a PCMCIA adapter is still physically present.
  269. //
  270. else if (ndisAdap->AdapterRemoved)
  271. {
  272. MadgePrint1("MadgeSend aborting - adapter removed\n");
  273. retCode = NDIS_STATUS_SUCCESS;
  274. }
  275. //
  276. // Otherwise we need to send the frame over the ring.
  277. //
  278. else
  279. {
  280. status = rxtx_transmit_frame(
  281. ndisAdap->FtkAdapterHandle,
  282. (DWORD) packet,
  283. (WORD) totalPacketSize,
  284. TRUE
  285. );
  286. //
  287. // Check if the frame has been transmitted completely.
  288. //
  289. if (status == DRIVER_TRANSMIT_SUCCEED)
  290. {
  291. ndisAdap->FramesTransmitted++;
  292. retCode = NDIS_STATUS_SUCCESS;
  293. #ifdef OID_MADGE_MONITOR
  294. //
  295. // Update the appropriate parts of the monitor structure
  296. //
  297. (ndisAdap->MonitorInfo).TransmitFrames++;
  298. (ndisAdap->MonitorInfo).TransmitFrameSize[totalPacketSize/128]++;
  299. //
  300. // Find the number of physical fragments sent
  301. //
  302. NdisQueryPacket(packet,
  303. NULL,
  304. NULL,
  305. &bufPtr,
  306. &totalPacketSize);
  307. physFrags = 0;
  308. count = 0;
  309. while (bufPtr != NULL)
  310. {
  311. MDL *mdl = (MDL *) bufPtr;
  312. count++;
  313. pageCount = (((MDL *) bufPtr)->Size - sizeof(MDL)) / sizeof(ULONG);
  314. pagePtr = (ULONG *) (((MDL *) bufPtr) + 1);
  315. physFrags++; // First page.
  316. bytes = mdl->ByteCount;
  317. if (pageCount <= 1)
  318. {
  319. size = bytes;
  320. }
  321. else
  322. {
  323. size = 4096 - mdl->ByteOffset;
  324. bytes -= size;
  325. }
  326. for (i = 1; i < pageCount; i++)
  327. {
  328. if (pagePtr[i] != pagePtr[i - 1] + 1)
  329. {
  330. size = 0;
  331. physFrags++;
  332. }
  333. if (i == pageCount - 1)
  334. {
  335. size += bytes;
  336. }
  337. else
  338. {
  339. bytes -= 4096;
  340. size += 4096;
  341. }
  342. }
  343. NdisGetNextBuffer(bufPtr, &bufPtr);
  344. }
  345. if (count < 65)
  346. {
  347. (ndisAdap->MonitorInfo).NumberOfVFrags[count]++;
  348. }
  349. if (physFrags < 65)
  350. {
  351. (ndisAdap->MonitorInfo).NumberOfPFrags[physFrags]++;
  352. }
  353. #endif
  354. }
  355. //
  356. // Or not transmitted at all, in which case we must
  357. // queue it for later.
  358. //
  359. else
  360. {
  361. retCode = NDIS_STATUS_RESOURCES;
  362. }
  363. }
  364. return retCode;
  365. }
  366. /***************************************************************************
  367. *
  368. * Function - MadgeCopyFromPacketToBuffer
  369. *
  370. * Parameters - packet -> The NDIS3 packet to copy.
  371. * offset -> Starting offset into the packet.
  372. * bytesToCopy -> Number of bytes to copy.
  373. * destPtr -> Pointer to the destination buffer.
  374. * bytesCopied -> Pointer to a holder for the number of
  375. * bytes actually copied.
  376. *
  377. * Purpose - Copy data from an NDIS3 packet into a buffer.
  378. *
  379. * Returns - Nothing.
  380. *
  381. ****************************************************************************/
  382. VOID
  383. MadgeCopyFromPacketToBuffer(
  384. PNDIS_PACKET packet,
  385. UINT offset,
  386. UINT bytesToCopy,
  387. PCHAR destPtr,
  388. PUINT bytesCopied
  389. )
  390. {
  391. UINT bufferCount;
  392. PNDIS_BUFFER currentBuffer;
  393. PVOID currentPtr;
  394. UINT currentLength;
  395. UINT amountToMove;
  396. UINT localBytesCopied;
  397. *bytesCopied = 0;
  398. localBytesCopied = 0;
  399. if (bytesToCopy == 0)
  400. {
  401. return;
  402. }
  403. NdisQueryPacket(packet, NULL, &bufferCount, &currentBuffer, NULL);
  404. if (bufferCount == 0)
  405. {
  406. return;
  407. }
  408. NdisQueryBuffer(currentBuffer, &currentPtr, &currentLength);
  409. while (localBytesCopied < bytesToCopy)
  410. {
  411. if (currentLength == 0)
  412. {
  413. NdisGetNextBuffer(currentBuffer, &currentBuffer);
  414. if (currentBuffer == 0)
  415. {
  416. break;
  417. }
  418. NdisQueryBuffer(currentBuffer, &currentPtr, &currentLength);
  419. continue;
  420. }
  421. if (offset > 0)
  422. {
  423. if (offset > currentLength)
  424. {
  425. offset -= currentLength;
  426. currentLength = 0;
  427. continue;
  428. }
  429. else
  430. {
  431. currentPtr = (PCHAR) currentPtr + offset;
  432. currentLength -= offset;
  433. offset = 0;
  434. }
  435. }
  436. amountToMove =
  437. (currentLength <= (bytesToCopy - localBytesCopied))
  438. ? currentLength
  439. : bytesToCopy - localBytesCopied;
  440. MADGE_MOVE_MEMORY(destPtr, currentPtr, amountToMove);
  441. destPtr = (PCHAR) destPtr + amountToMove;
  442. currentPtr = (PCHAR) currentPtr + amountToMove;
  443. localBytesCopied += amountToMove;
  444. currentLength -= amountToMove;
  445. }
  446. *bytesCopied = localBytesCopied;
  447. }
  448. /****************************************************************************
  449. *
  450. * Function - MadgeTransferData
  451. *
  452. * Parameters - adapterContext -> Pointer to our NDIS level adapter
  453. * structure.
  454. * receiveContext -> Pointer to the start of the frame data.
  455. * byteOffset -> Offset to start copying from.
  456. * bytesToTransfer -> Number of bytes to copy.
  457. * packet -> NDIS packet for the data.
  458. * bytesTransferred -> Pointer to a holder for the number of
  459. * bytes actually copied.
  460. *
  461. * Purpose - Copy data from the received frame just indicated into an
  462. * NDIS packet. This function is called by the NDIS3 wrapper
  463. * in response to our indication frame rxtx_irq_received_frame.
  464. *
  465. * Returns - An NDIS3 status code.
  466. *
  467. ****************************************************************************/
  468. NDIS_STATUS
  469. MadgeTransferData(
  470. PNDIS_PACKET packet,
  471. PUINT bytesTransferred,
  472. NDIS_HANDLE adapterContext,
  473. NDIS_HANDLE receiveContext,
  474. UINT byteOffset,
  475. UINT bytesToTransfer
  476. )
  477. {
  478. PMADGE_ADAPTER ndisAdap;
  479. NDIS_STATUS retCode;
  480. //
  481. // Pre-calculate some values.
  482. //
  483. ndisAdap = PMADGE_ADAPTER_FROM_CONTEXT(adapterContext);
  484. //
  485. // Check that the data pointer is valid.
  486. //
  487. if ((PCHAR) receiveContext == NULL)
  488. {
  489. retCode = NDIS_STATUS_FAILURE;
  490. }
  491. //
  492. // If it is, copy from the frame from the receive buffer
  493. // into the packet.
  494. //
  495. else
  496. {
  497. MadgeCopyFromBufferToPacket(
  498. (PCHAR) receiveContext + byteOffset,
  499. bytesToTransfer,
  500. packet,
  501. 0,
  502. bytesTransferred
  503. );
  504. retCode = NDIS_STATUS_SUCCESS;
  505. #ifdef OID_MADGE_MONITOR
  506. //
  507. // Update the appropriate parts of the monitor structure
  508. //
  509. if ((ndisAdap->MonitorInfo).ReceiveFlag > 0)
  510. {
  511. (ndisAdap->MonitorInfo).TransferFrames++;
  512. (ndisAdap->MonitorInfo).TransferFrameSize[(ndisAdap->MonitorInfo).CurrentFrameSize/128]++;
  513. (ndisAdap->MonitorInfo).ReceiveFlag = 0;
  514. }
  515. #endif
  516. }
  517. return retCode;
  518. }
  519. /***************************************************************************
  520. *
  521. * Function - MadgeCopyFromBufferToPacket
  522. *
  523. * Parameters - srcPtr -> Pointer to the source buffer.
  524. * bytesToCopy -> Number of bytes to copy.
  525. * packet -> The NDIS3 destination packet.
  526. * offset -> Starting offset into the buffer.
  527. * bytesCopied -> Pointer to a holder for the number of
  528. * bytes actually copied.
  529. *
  530. * Purpose - Copy data from a buffer into an NDIS3 packet.
  531. *
  532. * Returns - Nothing.
  533. *
  534. ****************************************************************************/
  535. VOID
  536. MadgeCopyFromBufferToPacket(
  537. PCHAR srcPtr,
  538. UINT bytesToCopy,
  539. PNDIS_PACKET packet,
  540. UINT offset,
  541. PUINT bytesCopied
  542. )
  543. {
  544. UINT bufferCount;
  545. PNDIS_BUFFER currentBuffer;
  546. PVOID virtualAddress;
  547. UINT currentLength;
  548. UINT amountToMove;
  549. UINT localBytesCopied;
  550. *bytesCopied = 0;
  551. localBytesCopied = 0;
  552. if (bytesToCopy == 0)
  553. {
  554. return;
  555. }
  556. NdisQueryPacket(packet, NULL, &bufferCount, &currentBuffer, NULL);
  557. if (bufferCount == 0)
  558. {
  559. return;
  560. }
  561. NdisQueryBuffer(currentBuffer, &virtualAddress, &currentLength);
  562. while (localBytesCopied < bytesToCopy)
  563. {
  564. if (currentLength == 0)
  565. {
  566. NdisGetNextBuffer(currentBuffer, &currentBuffer);
  567. if (currentBuffer == NULL)
  568. {
  569. break;
  570. }
  571. NdisQueryBuffer(currentBuffer, &virtualAddress, &currentLength);
  572. continue;
  573. }
  574. if (offset > 0)
  575. {
  576. if (offset > currentLength)
  577. {
  578. offset -= currentLength;
  579. currentLength = 0;
  580. continue;
  581. }
  582. else
  583. {
  584. virtualAddress = (PCHAR) virtualAddress + offset;
  585. currentLength -= offset;
  586. offset = 0;
  587. }
  588. }
  589. amountToMove = (bytesToCopy - localBytesCopied < currentLength)
  590. ? bytesToCopy - localBytesCopied
  591. : currentLength;
  592. MADGE_MOVE_MEMORY(
  593. virtualAddress,
  594. srcPtr,
  595. amountToMove
  596. );
  597. srcPtr += amountToMove;
  598. localBytesCopied += amountToMove;
  599. currentLength -= amountToMove;
  600. }
  601. *bytesCopied = localBytesCopied;
  602. }
  603. /***************************************************************************
  604. *
  605. * Function - MadgeISR
  606. *
  607. * Parameters - interruptRecognised -> Pointer to an interrupt recognised
  608. * flag we set if we recognise the
  609. * interrupt.
  610. * queueDPR -> Pointer to DPR required flag we
  611. * set if we need a DPR.
  612. * adapterContext -> Pointer to our NDIS level adapter
  613. * structure.
  614. *
  615. * Purpose - Process an IRQ from an adapter. All we do is call the
  616. * HWI and schedule a DPR if required.
  617. *
  618. * Returns - Nothing.
  619. *
  620. ****************************************************************************/
  621. VOID
  622. MadgeISR(
  623. PBOOLEAN interruptRecognised,
  624. PBOOLEAN queueDPR,
  625. NDIS_HANDLE adapterContext
  626. )
  627. {
  628. PMADGE_ADAPTER ndisAdap;
  629. ndisAdap = PMADGE_ADAPTER_FROM_CONTEXT(adapterContext);
  630. hwi_interrupt_entry(
  631. ndisAdap->FtkAdapterHandle,
  632. (WORD) ndisAdap->UsedInISR.InterruptNumber
  633. );
  634. //
  635. // If ndisAdap->DprRequired is TRUE then we recognised the interrupt
  636. // and found something that requires further processing (e.g. received
  637. // a frame). If ndisAdap->DprRequired is FALSE then we either didn't
  638. // recognise the interrupt or we don't need any further processing.
  639. // The only operation that doesn't need further processing is ISA
  640. // PIO. Since ISA cards cannot share interrupt lines it doesn't
  641. // matter if we say we don't recognise the interrupt if we don't
  642. // need any further processing. Hence we can use ndisAdap->DprRequired
  643. // to set both *interruptRecognised and *queueDpr.
  644. //
  645. //
  646. // However ...
  647. // There is a race condition with ATULA based cards in PIO mode.
  648. // Normally we do not claim interrupts that are used for PIO transfers
  649. // to avoid the overhead of a DPR on PIO transfers. However, in some
  650. // instances if we do not claim the PIO interrupts used for the
  651. // initial "DMA" tests then WFWG (and possibly NT) permanently disables
  652. // our interrupts. To get around this we claim all interrupts until
  653. // our rx/tx buffers have been allocated since the optimisation of not
  654. // queuing a DPR for PIO interrupts doesn't matter until we have
  655. // rx/tx buffers in place.
  656. //
  657. *interruptRecognised =
  658. (ndisAdap->RxTxBufferState != MADGE_RXTX_INITIALIZED)
  659. ? TRUE
  660. : ndisAdap->DprRequired;
  661. *queueDPR = ndisAdap->DprRequired;
  662. ndisAdap->DprRequired = FALSE;
  663. }
  664. /*--------------------------------------------------------------------------
  665. |
  666. | Function - MadgeSyncSRBPending
  667. |
  668. | Parameters - synchonizedContext -> A pointer to an NDIS3 level adapter
  669. | structure.
  670. |
  671. | Purpose - Process a completed SRBs. This routine is always
  672. | syncronised with IRQs.
  673. |
  674. | Returns - TRUE if the SRB has actually completed or FALSE if not.
  675. |
  676. --------------------------------------------------------------------------*/
  677. STATIC BOOLEAN
  678. MadgeSyncSRBPending(PVOID synchronizeContext)
  679. {
  680. PMADGE_ADAPTER ndisAdap;
  681. BOOLEAN retCode;
  682. ndisAdap = PMADGE_ADAPTER_FROM_CONTEXT(synchronizeContext);
  683. retCode = ndisAdap->UsedInISR.SrbRequestCompleted;
  684. if (retCode)
  685. {
  686. ndisAdap->UsedInISR.SrbRequestCompleted = FALSE;
  687. ndisAdap->SrbRequestStatus = ndisAdap->UsedInISR.SrbRequestStatus;
  688. }
  689. return retCode;
  690. }
  691. /****************************************************************************
  692. *
  693. * Function - MadgeHandleInterrupt
  694. *
  695. * Parameters - adapterContext -> Pointer to our NDIS level adapter
  696. * structure.
  697. *
  698. * Purpose - Our DPR routine.
  699. *
  700. * Returns - Nothing.
  701. *
  702. ****************************************************************************/
  703. VOID
  704. MadgeHandleInterrupt(NDIS_HANDLE adapterContext)
  705. {
  706. PMADGE_ADAPTER ndisAdap;
  707. ndisAdap = PMADGE_ADAPTER_FROM_CONTEXT(adapterContext);
  708. //
  709. // Must do anything if we don't have tx/rx buffers.
  710. //
  711. if (ndisAdap->RxTxBufferState != MADGE_RXTX_INITIALIZED)
  712. {
  713. return;
  714. }
  715. //
  716. // I think this check is a bit paranoid. I think DPRs are guaranteed
  717. // to be single threaded. I suppose it might be needed on a multi-
  718. // processor. Just 'cos your've paraonoid doesn't mean they're not
  719. // out to get you!
  720. //
  721. if (!ndisAdap->DprInProgress)
  722. {
  723. ndisAdap->DprInProgress = TRUE;
  724. //
  725. // Handle completed SRBs first.
  726. //
  727. if (NdisMSynchronizeWithInterrupt(
  728. &ndisAdap->Interrupt,
  729. MadgeSyncSRBPending,
  730. adapterContext))
  731. {
  732. MadgeCompletePendingRequest(ndisAdap);
  733. }
  734. //
  735. // If the adapter has been removed then call the housekeeping
  736. // function.
  737. //
  738. if (ndisAdap->AdapterRemoved)
  739. {
  740. rxtx_adapter_removed(ndisAdap->FtkAdapterHandle);
  741. }
  742. //
  743. // Check for transmit completions.
  744. //
  745. rxtx_irq_tx_completion_check(
  746. ndisAdap->FtkAdapterHandle,
  747. adapter_record[ndisAdap->FtkAdapterHandle]
  748. );
  749. //
  750. // See if there are any received frames.
  751. //
  752. driver_get_outstanding_receive(ndisAdap->FtkAdapterHandle);
  753. ndisAdap->DprInProgress = FALSE;
  754. }
  755. //
  756. // This else should never be executed!
  757. //
  758. else
  759. {
  760. MadgePrint1("DPR reentered!!!!\n");
  761. }
  762. }
  763. /******** End of DISPATCH.C ************************************************/