|
|
1.1 ! root 1: /*++ ! 2: ! 3: Copyright (c) 1990 Microsoft Corporation ! 4: ! 5: Module Name: ! 6: ! 7: lancesft.h ! 8: ! 9: Abstract: ! 10: ! 11: The main header for a LANCE (Local Area Network Controller ! 12: Am 7990) MAC driver. ! 13: ! 14: Author: ! 15: ! 16: Anthony V. Ercolano (tonye) creation-date 19-Jun-1990 ! 17: ! 18: Environment: ! 19: ! 20: This driver is expected to work in DOS, OS2 and NT at the equivalent ! 21: of kernal mode. ! 22: ! 23: Architecturally, there is an assumption in this driver that we are ! 24: on a little endian machine. ! 25: ! 26: Notes: ! 27: ! 28: optional-notes ! 29: ! 30: Revision History: ! 31: ! 32: 31-Jul-1992 R.D. Lanser: ! 33: ! 34: Changed DECST card type to DECTC for the DEC TurboChannel option ! 35: PMAD-AA (Lance ethernet). This option will be available for all ! 36: TurboChannel systems regardless of CPU type or system. ! 37: ! 38: Added InterruptRequestLevel to the _LANCE_ADAPTER structure because ! 39: 'lance.c' was passing the InterruptVector as the IRQL to the interrupt ! 40: connect routine which is not correct. This works on JAZZ because the ! 41: JAZZ HalGetInterruptVector is hardcoded to return a fixed IRQL for ! 42: EISA devices. ! 43: ! 44: Removed PhysicalBuffersContained and UsedLanceBuffer field from ! 45: _ADAPTER structure. SeanSe says that the code related to this ! 46: field was used for adevice that is no longer supported. I removed ! 47: the dependent code(or at least what was obvious) from 'send.c'. ! 48: ! 49: --*/ ! 50: ! 51: #ifndef _LANCESFT_ ! 52: #define _LANCESFT_ ! 53: ! 54: #define LANCE_NDIS_MAJOR_VERSION 3 ! 55: #define LANCE_NDIS_MINOR_VERSION 0 ! 56: ! 57: #if DBG ! 58: ! 59: #define LANCELOG 1 ! 60: #define LANCE_TRACE 0 ! 61: ! 62: #else ! 63: ! 64: #define LANCELOG 0 ! 65: #define LANCE_TRACE 0 ! 66: ! 67: #endif ! 68: ! 69: #if LANCELOG ! 70: ! 71: #define LOG_SIZE 256 ! 72: ! 73: #define TIMER '.' ! 74: #define IN_ISR 'i' ! 75: #define OUT_ISR 'I' ! 76: #define IN_DPC 'd' ! 77: #define OUT_DPC 'D' ! 78: #define RECEIVE 'R' ! 79: #define TRANSMIT 'x' ! 80: #define TRANSMIT_COMPLETE 'X' ! 81: #define PEND 'p' ! 82: #define UNPEND 'P' ! 83: #define INDICATE 'r' ! 84: #define IN_SEND 's' ! 85: #define OUT_SEND 'S' ! 86: #define START 'G' ! 87: #define RESET_STEP_1 '1' ! 88: #define RESET_STEP_2 '2' ! 89: #define RESET_SAVE_PACKET 'b' ! 90: #define RESET_RECOVER_PACKET 'B' ! 91: #define RESET_COMPLETE_PACKET 'c' ! 92: #define RESET_STEP_3 '3' ! 93: ! 94: ! 95: ! 96: extern UCHAR Log[LOG_SIZE]; ! 97: ! 98: extern UCHAR LogPlace; ! 99: extern UCHAR LogWrapped; ! 100: ! 101: ! 102: ! 103: #define LOG(c) { Log[LogPlace] = (c); Log[(LogPlace+3) % 255] ='\0'; \ ! 104: LogPlace = (LogPlace + 1) % 255; } ! 105: ! 106: #else ! 107: ! 108: #define LOG(c) ! 109: ! 110: #endif ! 111: ! 112: ! 113: ! 114: extern NDIS_PHYSICAL_ADDRESS HighestAcceptableMax; ! 115: ! 116: // ! 117: // ZZZ These macros are peculiar to NT. ! 118: // ! 119: ! 120: #define LANCE_ALLOC_PHYS(pp, s) NdisAllocateMemory((PVOID *)(pp),(s),0,HighestAcceptableMax) ! 121: #define LANCE_FREE_PHYS(p, s) NdisFreeMemory((PVOID)(p),(s),0) ! 122: #define LANCE_MOVE_MEMORY(Destination,Source,Length) NdisMoveMemory(Destination,Source,Length) ! 123: #define LANCE_ZERO_MEMORY(Destination,Length) NdisZeroMemory(Destination,Length) ! 124: ! 125: ! 126: ! 127: // ! 128: // Definitions for all the different card types. ! 129: // ! 130: ! 131: ! 132: #define LANCE_DE100 0x01 // DE100 card ! 133: #define LANCE_DE201 0x02 // DE201 card ! 134: #define LANCE_DEPCA 0x04 // Card in a Dec PC x86 machine ! 135: #define LANCE_DECST 0x08 // Card in a decstation ! 136: #define LANCE_DE422 0x10 // DE422 card ! 137: #define LANCE_DECTC 0x20 // TurboChannel PMAD-AA option ! 138: ! 139: #define LANCE_DE100_NAME LANCE_DEFAULT_NAME ! 140: #define LANCE_DE201_NAME LANCE_DEFAULT_NAME ! 141: #define LANCE_DEPCA_NAME LANCE_DEFAULT_NAME ! 142: #define LANCE_DECST_NAME LANCE_DEFAULT_NAME ! 143: #define LANCE_DE422_NAME LANCE_DEFAULT_NAME ! 144: #define LANCE_DECTC_NAME LANCE_DEFAULT_NAME ! 145: #define LANCE_DEFAULT_NAME "\\Device\\Lance01" ! 146: ! 147: ! 148: // ! 149: // This structure is passed as context from the receive interrupt ! 150: // processor. Eventually it will be used as a parameter to ! 151: // LanceTransferData. LanceTransferData can get two kinds of ! 152: // context. It will receive either an ndis packet or it will ! 153: // receive a LANCE_RECEIVE_CONTEXT. It will be able to tell ! 154: // the difference since the LANCE_RECEIVE_CONTEXT will have ! 155: // its low bit set. No pointer to an ndis packet can have its low ! 156: // bit set. ! 157: // ! 158: typedef union _LANCE_RECEIVE_CONTEXT { ! 159: ! 160: UINT WholeThing; ! 161: struct _INFO { ! 162: // ! 163: // Used to mark that this is context rather than a pointer ! 164: // to a packet. ! 165: // ! 166: UINT IsContext:1; ! 167: ! 168: // ! 169: // The first receive ring descriptor used to hold the packet. ! 170: // ! 171: UINT FirstBuffer:7; ! 172: ! 173: // ! 174: // The last receive ring descriptor used to hold the packet. ! 175: // ! 176: UINT LastBuffer:7; ! 177: } INFO; ! 178: ! 179: } LANCE_RECEIVE_CONTEXT,*PLANCE_RECEIVE_CONTEXT; ! 180: ! 181: ! 182: ! 183: ! 184: ! 185: ! 186: // ! 187: // This record type is inserted into the MacReserved portion ! 188: // of the packet header when the packet is going through the ! 189: // staged allocation of buffer space prior to the actual send. ! 190: // ! 191: typedef struct _LANCE_RESERVED { ! 192: ! 193: // ! 194: // Points to the next packet in the chain of queued packets ! 195: // being allocated, loopbacked, or waiting for the finish ! 196: // of transmission. ! 197: // ! 198: // The packet will either be on the stage list for allocation, ! 199: // the loopback list for loopback processing, on an adapter ! 200: // wide doubly linked list (see below) for post transmission ! 201: // processing. ! 202: // ! 203: // We always keep the packet on a list so that in case the ! 204: // the adapter is closing down or resetting, all the packets ! 205: // can easily be located and "canceled". ! 206: // ! 207: PNDIS_PACKET Next; ! 208: ! 209: // ! 210: // This field holds the binding handle of the open binding ! 211: // that submitted this packet for send. ! 212: // ! 213: NDIS_HANDLE MacBindingHandle; ! 214: ! 215: // ! 216: // This gives the index into the array of adapter buffer ! 217: // descriptors that contains the packet information. ! 218: // ! 219: USHORT LanceBuffersIndex; ! 220: ! 221: // ! 222: // When the hardware send is done this will record whether ! 223: // the send was successful or not. ! 224: // ! 225: BOOLEAN SuccessfulTransmit; ! 226: ! 227: } LANCE_RESERVED,*PLANCE_RESERVED; ! 228: ! 229: // ! 230: // This macro will return a pointer to the lance reserved portion ! 231: // of a packet given a pointer to a packet. ! 232: // ! 233: #define PLANCE_RESERVED_FROM_PACKET(Packet) \ ! 234: ((PLANCE_RESERVED)((Packet)->MacReserved)) ! 235: ! 236: // ! 237: // This structure is used to map entries in the ring descriptors ! 238: // back to the packets from which the data in the ring descriptor ! 239: // originated. ! 240: // ! 241: ! 242: typedef struct _LANCE_RING_TO_PACKET { ! 243: ! 244: // ! 245: // Points to the packet from which data is being transmitted ! 246: // through this ring entry. ! 247: // ! 248: PNDIS_PACKET OwningPacket; ! 249: ! 250: // ! 251: // Index of the ring entry that is being used by the packet. ! 252: // ! 253: UINT RingIndex; ! 254: ! 255: // ! 256: // When a packet is submitted to the hardware we record ! 257: // here whether it used adapter buffers and if so, the buffer ! 258: // index. ! 259: // ! 260: UINT LanceBuffersIndex; ! 261: ! 262: } LANCE_RING_TO_PACKET,*PLANCE_RING_TO_PACKET; ! 263: ! 264: // ! 265: // If an ndis packet does not meet the hardware contraints then ! 266: // an adapter buffer will be allocated. Enough data will be copied ! 267: // out of the ndis packet so that by using a combination of the ! 268: // adapter buffer and remaining ndis buffers the hardware ! 269: // constraints are satisfied. ! 270: // ! 271: // In the LANCE_ADAPTER structure three threaded lists are kept in ! 272: // one array. One points to a list of LANCE_BUFFER_DESCRIPTORS ! 273: // that point to small adapter buffers. Another is for medium sized ! 274: // buffers and the last for full sized (large) buffers. ! 275: // ! 276: // The allocation is controlled via a free list head and ! 277: // the free lists are "threaded" by a field in the adapter buffer ! 278: // descriptor. ! 279: // ! 280: typedef struct _LANCE_BUFFER_DESCRIPTOR { ! 281: ! 282: // ! 283: // A virtual pointer to a small, medium, or large buffer. ! 284: // ! 285: PVOID VirtualLanceBuffer; ! 286: ! 287: // ! 288: // Threads the elements of an array of these descriptors into ! 289: // a free list. -1 implies no more entries in the list. ! 290: // ! 291: INT Next; ! 292: ! 293: // ! 294: // Holds the amount of space (in bytes) available in the buffer ! 295: // ! 296: UINT BufferSize; ! 297: ! 298: // ! 299: // Holds the length of data placed into the buffer. This ! 300: // can (and likely will) be less that the actual buffers ! 301: // length. ! 302: // ! 303: UINT DataLength; ! 304: ! 305: } LANCE_BUFFER_DESCRIPTOR,*PLANCE_BUFFER_DESCRIPTOR; ! 306: ! 307: ! 308: ! 309: // ! 310: // Used to contain a queued operation. ! 311: // ! 312: ! 313: typedef struct _LANCE_PEND_DATA { ! 314: PNDIS_REQUEST Next; ! 315: struct _LANCE_OPEN * Open; ! 316: NDIS_REQUEST_TYPE RequestType; ! 317: } LANCE_PEND_DATA, * PLANCE_PEND_DATA; ! 318: ! 319: // ! 320: // This macro will return a pointer to the reserved area of ! 321: // a PNDIS_REQUEST. ! 322: // ! 323: #define PLANCE_PEND_DATA_FROM_PNDIS_REQUEST(Request) \ ! 324: ((PLANCE_PEND_DATA)((PVOID)((Request)->MacReserved))) ! 325: ! 326: // ! 327: // This macros returns the enclosing NdisRequest. ! 328: // ! 329: #define PNDIS_REQUEST_FROM_PLANCE_PEND_DATA(PendOp)\ ! 330: ((PNDIS_REQUEST)((PVOID)(PendOp))) ! 331: ! 332: ! 333: ! 334: // ! 335: // Define the size of the ethernet header. ! 336: // ! 337: #define LANCE_HEADER_SIZE 14 ! 338: ! 339: // ! 340: // Define Maximum number of bytes a protocol can read during a ! 341: // receive data indication. ! 342: // ! 343: #define LANCE_MAX_LOOKAHEAD ( 248 - LANCE_HEADER_SIZE ) ! 344: ! 345: ! 346: ! 347: ! 348: ! 349: typedef struct _LANCE_ADAPTER { ! 350: ! 351: // ! 352: // The card type of this adapter. ! 353: // ! 354: UCHAR LanceCard; ! 355: ! 356: // ! 357: // Holds the interrupt object for this adapter. ! 358: // ! 359: NDIS_INTERRUPT Interrupt; ! 360: ! 361: // ! 362: // Normal processing DPC. ! 363: // ! 364: PVOID InterruptDPC; ! 365: ! 366: // ! 367: // Dpc for handling loopback. ! 368: // ! 369: PVOID LoopbackDPC; ! 370: ! 371: // ! 372: // Non OS fields of the adapter. ! 373: // ! 374: ! 375: // ! 376: // Contains Address first byte of adapter memory is mapped to. ! 377: // ! 378: PVOID MmMappedBaseAddr; ! 379: ! 380: // ! 381: // Contains address of the hardware memory. ! 382: // ! 383: PVOID HardwareBaseAddr; ! 384: ! 385: // ! 386: // Offset for Init block from the Lance chip's point of view. ! 387: // ! 388: ULONG HardwareBaseOffset; ! 389: ! 390: // ! 391: // Amount of memory ! 392: // ! 393: ULONG AmountOfHardwareMemory; ! 394: ! 395: // ! 396: // For lance implementation that uses dual ported memory this ! 397: // field is used to point to the first available memory. ! 398: // ! 399: PVOID CurrentMemoryFirstFree; ! 400: ! 401: // ! 402: // Address of the first byte following the memory. ! 403: // ! 404: PVOID MemoryFirstUnavailable; ! 405: ! 406: // ! 407: // Pointer to the RAP register. ! 408: // ! 409: ULONG RAP; ! 410: ! 411: // ! 412: // Pointer to the RDP register. ! 413: // ! 414: ULONG RDP; ! 415: ! 416: // ! 417: // Pointer to the NICSR register. ! 418: // ! 419: ULONG Nicsr; ! 420: ! 421: // ! 422: // Slot Number the De422 is in. ! 423: // ! 424: UINT SlotNumber; ! 425: ! 426: // ! 427: // Default information to add to the NICSR register value ! 428: // ! 429: USHORT NicsrDefaultValue; ! 430: ! 431: // ! 432: // Have the interrupts from the card been turned off. ! 433: // ! 434: BOOLEAN InterruptsStopped; ! 435: ! 436: // ! 437: // Address in memory of the network address ! 438: // ! 439: ULONG NetworkHardwareAddress; ! 440: ! 441: // ! 442: // The network address from the hardware. ! 443: // ! 444: CHAR NetworkAddress[ETH_LENGTH_OF_ADDRESS]; ! 445: ! 446: // ! 447: // The network address from the hardware. ! 448: // ! 449: CHAR CurrentNetworkAddress[ETH_LENGTH_OF_ADDRESS]; ! 450: ! 451: // ! 452: // Interrupt number ! 453: // ! 454: CCHAR InterruptNumber; ! 455: ! 456: // ! 457: // IRQL ! 458: // ! 459: CCHAR InterruptRequestLevel; ! 460: ! 461: // The following fields are accessed by the ISR and must be aligned to the ! 462: // minimum granularity of the architecture on which it runs ! 463: ! 464: #if defined(_ALPHA_) ! 465: ! 466: union { ! 467: UQUAD _ForceQuadwordAlignment; ! 468: struct { ! 469: ! 470: #endif // defined(_ALPHA_) ! 471: ! 472: // ! 473: // Holds a value of CSR0 from one or more interrupts. ! 474: // This value is only set by the interrupt service routine ! 475: // and cleared by the interrupt synchronization routine. ! 476: // ! 477: USHORT CSR0Value; ! 478: ! 479: #if defined(_ALPHA_) ! 480: ! 481: }; ! 482: }; ! 483: ! 484: #endif // defined(_ALPHA_) ! 485: ! 486: // End of ISR access fields ! 487: ! 488: // ! 489: // Holds the number of transmit ring entries. ! 490: // ! 491: // NOTE NOTE NOTE ! 492: // ! 493: // There is code that depends on the number of transmit entries ! 494: // being a power of two. ! 495: // ! 496: UINT NumberOfTransmitRings; ! 497: ! 498: // ! 499: // Holds the number of receive ring entries. ! 500: // ! 501: UINT NumberOfReceiveRings; ! 502: ! 503: // ! 504: // Holds the size of receive buffers. ! 505: // ! 506: UINT SizeOfReceiveBuffer; ! 507: ! 508: // ! 509: // Holds number of each buffer size. ! 510: // ! 511: UINT NumberOfSmallBuffers; ! 512: UINT NumberOfMediumBuffers; ! 513: UINT NumberOfLargeBuffers; ! 514: ! 515: // ! 516: // The log base two of the number of transmit ring entries. ! 517: // ! 518: UINT LogNumberTransmitRings; ! 519: ! 520: // ! 521: // The log base two of the number of receive ring entries. ! 522: // ! 523: UINT LogNumberReceiveRings; ! 524: ! 525: // ! 526: // Keeps a reference count on the current number of uses of ! 527: // this adapter block. Uses is defined to be the number of ! 528: // routines currently within the "external" interface. ! 529: // ! 530: UINT References; ! 531: ! 532: // ! 533: // List head for all open bindings for this adapter. ! 534: // ! 535: LIST_ENTRY OpenBindings; ! 536: ! 537: // ! 538: // List head for all opens that had outstanding references ! 539: // when an attempt was made to close them. ! 540: // ! 541: LIST_ENTRY CloseList; ! 542: ! 543: // ! 544: // Spinlock to protect fields in this structure.. ! 545: // ! 546: NDIS_SPIN_LOCK Lock; ! 547: ! 548: // ! 549: // Handle given by NDIS when the MAC registered itself. ! 550: // ! 551: NDIS_HANDLE NdisMacHandle; ! 552: ! 553: // ! 554: // Handle given by NDIS when the adapter was registered. ! 555: // ! 556: NDIS_HANDLE NdisAdapterHandle; ! 557: ! 558: // ! 559: // Timer for Deferred Processing. ! 560: // ! 561: NDIS_TIMER DeferredTimer; ! 562: ! 563: // ! 564: // Flag if we have a ProcessInterrupt call in progress ! 565: // ! 566: BOOLEAN ProcessInterruptRunning; ! 567: ! 568: // ! 569: // Pointer to the filter database for the MAC. ! 570: // ! 571: PETH_FILTER FilterDB; ! 572: ! 573: // ! 574: // Pointer to the LANCE initialization block. ! 575: // ! 576: PLANCE_INITIALIZATION_BLOCK InitBlock; ! 577: ! 578: // ! 579: // Counter that records the number of transmit rings currently ! 580: // available for allocation. ! 581: // ! 582: UINT NumberOfAvailableRings; ! 583: ! 584: // ! 585: // Pointer to transmit descriptor ring entry that is the ! 586: // first ring entry available for allocation of transmit ! 587: // buffers. ! 588: // ! 589: // Can only be accessed when the adapter lock ! 590: // is held. ! 591: // ! 592: PLANCE_TRANSMIT_ENTRY AllocateableRing; ! 593: ! 594: // ! 595: // Pointer to a transmit descriptor ring entry that is the ! 596: // first ring entry that the MAC currently has made available ! 597: // for transmission. ! 598: // ! 599: // Can only be accessed when the adapter lock ! 600: // is held. ! 601: // ! 602: PLANCE_TRANSMIT_ENTRY TransmittingRing; ! 603: ! 604: // ! 605: // Pointer to the first packet that has been allocated to ! 606: // a transmit packet but has not yet been relinquished to ! 607: // the hardware. We need this pointer to keep the transmit ! 608: // post processing from running into a packet that has not ! 609: // been transmitted. ! 610: // ! 611: PLANCE_TRANSMIT_ENTRY FirstUncommittedRing; ! 612: ! 613: // ! 614: // Pointer to an array of structs that map transmit ring entries ! 615: // back to a packet. ! 616: // ! 617: PLANCE_RING_TO_PACKET RingToPacket; ! 618: ! 619: // ! 620: // Pointer to the transmit ring. ! 621: // ! 622: PLANCE_TRANSMIT_ENTRY TransmitRing; ! 623: ! 624: // ! 625: // Pointer to the last transmit ring entry. ! 626: // ! 627: PLANCE_TRANSMIT_ENTRY LastTransmitRingEntry; ! 628: ! 629: // ! 630: // Pointer to the receive ring. ! 631: // ! 632: PLANCE_RECEIVE_ENTRY ReceiveRing; ! 633: ! 634: // ! 635: // Pointer to the first packet on the loopback list. ! 636: // ! 637: // Can only be accessed when the adapter lock ! 638: // is held. ! 639: // ! 640: PNDIS_PACKET FirstLoopBack; ! 641: ! 642: // ! 643: // Pointer to the last packet on the loopback list. ! 644: // ! 645: // Can only be accessed when the adapter lock ! 646: // is held. ! 647: // ! 648: PNDIS_PACKET LastLoopBack; ! 649: ! 650: // ! 651: // Pointer to the first transmitting packet that is actually ! 652: // sending, or done with the living on the loopback queue. ! 653: // ! 654: // Can only be accessed when the adapter lock ! 655: // is held. ! 656: // ! 657: PNDIS_PACKET FirstFinishTransmit; ! 658: ! 659: // ! 660: // Pointer to the last transmitting packet that is actually ! 661: // sending, or done with the living on the loopback queue. ! 662: // ! 663: // Can only be accessed when the adapter lock ! 664: // is held. ! 665: // ! 666: PNDIS_PACKET LastFinishTransmit; ! 667: ! 668: // ! 669: // Listheads for the adapters buffers. If the list ! 670: // head is equal to -1 then there are no free elements ! 671: // on the list. ! 672: // ! 673: // The list heads must only be accessed when the ! 674: // adapter lock is held. ! 675: // ! 676: // Note that the listhead at index 0 will always be -1. ! 677: // ! 678: INT LanceBufferListHeads[4]; ! 679: ! 680: // ! 681: // Pointers to an array of adapter buffer descriptors. ! 682: // The array will actually be threaded together by ! 683: // three free lists. The lists will be for small, ! 684: // medium and full sized packets. ! 685: // ! 686: PLANCE_BUFFER_DESCRIPTOR LanceBuffers; ! 687: ! 688: // ! 689: // These fields let the send allocation code know that it's ! 690: // futile to even try to move a packet along to that stage. ! 691: // ! 692: // All of the stages would be closed to close a binding ! 693: // or to reset the adapter. ! 694: // ! 695: // These variables can only be accessed when the adapter ! 696: // lock is held. ! 697: // ! 698: BOOLEAN StageOpen; ! 699: ! 700: // ! 701: // These AlreadyProcessingStage variables are set up to keep ! 702: // more than one thread from accessing a particular thread ! 703: // a one time. ! 704: // ! 705: // These variables can only be accessed when the adapter ! 706: // lock is held. ! 707: // ! 708: BOOLEAN AlreadyProcessingStage; ! 709: ! 710: // ! 711: // Did we indicate a packet? Used to tell if NdisIndicateReceiveComplete ! 712: // should be called. ! 713: // ! 714: BOOLEAN IndicatedAPacket; ! 715: ! 716: // ! 717: // Pointers to the first and last packets at a particular stage ! 718: // of allocation. All packets in transmit are linked ! 719: // via there next field. ! 720: // ! 721: // Can only be accessed when the adapter lock ! 722: // is held. ! 723: // ! 724: PNDIS_PACKET FirstStage1Packet; ! 725: PNDIS_PACKET LastStage1Packet; ! 726: ! 727: // ! 728: // Pointer to an array of virtual addresses that describe ! 729: // the virtual address of each receive ring descriptor buffer. ! 730: // ! 731: PVOID *ReceiveVAs; ! 732: ! 733: // ! 734: // Index of the receive ring descriptor that started the ! 735: // last packet not completely received by the hardware. ! 736: // ! 737: UINT CurrentReceiveIndex; ! 738: ! 739: // ! 740: // Counters to hold the various number of errors/statistics for both ! 741: // reception and transmission. ! 742: // ! 743: // Can only be accessed when the adapter lock is held. ! 744: // ! 745: UINT OutOfReceiveBuffers; ! 746: UINT CRCError; ! 747: UINT FramingError; ! 748: UINT RetryFailure; ! 749: UINT LostCarrier; ! 750: UINT LateCollision; ! 751: UINT UnderFlow; ! 752: UINT Deferred; ! 753: UINT OneRetry; ! 754: UINT MoreThanOneRetry; ! 755: ! 756: // ! 757: // Holds counts of more global errors for the driver. If we ! 758: // get a memory error then the device needs to be reset. ! 759: // ! 760: UINT MemoryError; ! 761: UINT Babble; ! 762: UINT MissedPacket; ! 763: ! 764: // ! 765: // Holds other cool counts. ! 766: // ! 767: ! 768: ULONG Transmit; ! 769: ULONG Receive; ! 770: ! 771: // ! 772: // Flag that when enabled lets routines know that a reset ! 773: // is in progress. ! 774: // ! 775: BOOLEAN ResetInProgress; ! 776: ! 777: // ! 778: // Flag that when enabled lets routines know that a reset ! 779: // is in progress and the initialization needs doing. ! 780: // ! 781: BOOLEAN ResetInitStarted; ! 782: ! 783: // ! 784: // Pointer to the binding that initiated the reset. This ! 785: // will be null if the reset is initiated by the MAC itself. ! 786: // ! 787: struct _LANCE_OPEN *ResettingOpen; ! 788: ! 789: // ! 790: // The NdisRequest that is causing the reset (either set ! 791: // packet filter or set multicast list) ! 792: // ! 793: PNDIS_REQUEST ResetNdisRequest; ! 794: ! 795: // ! 796: // The type of the request that caused the adapter to reset. ! 797: // ! 798: NDIS_REQUEST_TYPE ResetRequestType; ! 799: ! 800: ! 801: // ! 802: // A queue of NdisRequests that were queued during a reset. ! 803: // ! 804: PNDIS_REQUEST PendQueue; ! 805: PNDIS_REQUEST PendQueueTail; ! 806: ! 807: // ! 808: // During an indication this is set to the current indications context ! 809: // ! 810: LANCE_RECEIVE_CONTEXT IndicatingMacReceiveContext; ! 811: ! 812: ! 813: // ! 814: // Look ahead information. ! 815: // ! 816: ! 817: ULONG MaxLookAhead; ! 818: ! 819: // ! 820: // Open information ! 821: // ! 822: UCHAR MaxMulticastList; ! 823: ! 824: // ! 825: // Will be true the first time that the hardware is initialized ! 826: // by the driver initialization. ! 827: // ! 828: BOOLEAN FirstInitialization; ! 829: ! 830: // ! 831: // Will be true if the hardware fails for some reason ! 832: // ! 833: BOOLEAN HardwareFailure; ! 834: ! 835: // ! 836: // For handling missing interrupts (caused by user mis-configs) ! 837: // ! 838: ! 839: PVOID WakeUpDpc; ! 840: NDIS_TIMER WakeUpTimer; ! 841: BOOLEAN WakeUpTimeout; ! 842: UCHAR TimeoutCount; ! 843: ! 844: // ! 845: // Lookahead buffer for loopback packets ! 846: // ! 847: UCHAR Lookahead[LANCE_MAX_LOOKAHEAD + LANCE_HEADER_SIZE]; ! 848: ! 849: } LANCE_ADAPTER,*PLANCE_ADAPTER; ! 850: ! 851: // ! 852: // Given a MacBindingHandle this macro returns a pointer to the ! 853: // LANCE_ADAPTER. ! 854: // ! 855: #define PLANCE_ADAPTER_FROM_BINDING_HANDLE(Handle) \ ! 856: (((PLANCE_OPEN)(Handle))->OwningLance) ! 857: ! 858: // ! 859: // Given a MacContextHandle return the PLANCE_ADAPTER ! 860: // it represents. ! 861: // ! 862: #define PLANCE_ADAPTER_FROM_CONTEXT_HANDLE(Handle) \ ! 863: ((PLANCE_ADAPTER)(Handle)) ! 864: ! 865: // ! 866: // Given a pointer to a LANCE_ADAPTER return the ! 867: // proper MacContextHandle. ! 868: // ! 869: #define CONTEXT_HANDLE_FROM_PLANCE_ADAPTER(Ptr) \ ! 870: ((NDIS_HANDLE)(Ptr)) ! 871: ! 872: ! 873: // ! 874: // One of these structures is created on each MacOpenAdapter. ! 875: // ! 876: typedef struct _LANCE_OPEN { ! 877: ! 878: // ! 879: // Linking structure for all of the open bindings of a particular ! 880: // adapter. This MUST be the first item in the structure. ! 881: // ! 882: LIST_ENTRY OpenList; ! 883: ! 884: // ! 885: // The Adapter that requested this open binding. ! 886: // ! 887: PLANCE_ADAPTER OwningLance; ! 888: ! 889: // ! 890: // Handle of this adapter in the filter database. ! 891: // ! 892: NDIS_HANDLE NdisFilterHandle; ! 893: ! 894: // ! 895: // Given by NDIS when the adapter was opened. ! 896: // ! 897: NDIS_HANDLE NdisBindingContext; ! 898: ! 899: // ! 900: // Minimum Number of bytes for a lookahead. ! 901: // ! 902: UINT LookAhead; ! 903: ! 904: // ! 905: // Counter of all the different reasons that a open binding ! 906: // couldn't be closed. This would be incremented each time ! 907: // for: ! 908: // ! 909: // While a particular interface routine is accessing this open ! 910: // ! 911: // During an indication. ! 912: // ! 913: // When the open causes a reset. ! 914: // ! 915: // A packet currently being sent. ! 916: // ! 917: // (Basically the above two mean any time the open has left ! 918: // some processing around to be accomplished later.) ! 919: // ! 920: // This field should only be accessed when the adapter lock is held. ! 921: // ! 922: UINT References; ! 923: ! 924: // ! 925: // A flag indicating that this binding is in the process of closing. ! 926: // ! 927: BOOLEAN BindingShuttingDown; ! 928: ! 929: LANCE_PEND_DATA CloseMulticastRequest; ! 930: ! 931: LANCE_PEND_DATA CloseFilterRequest; ! 932: ! 933: } LANCE_OPEN,*PLANCE_OPEN; ! 934: ! 935: // ! 936: // This macro returns a pointer to a PLANCE_OPEN given a MacBindingHandle. ! 937: // ! 938: #define PLANCE_OPEN_FROM_BINDING_HANDLE(Handle) \ ! 939: ((PLANCE_OPEN)(Handle)) ! 940: ! 941: // ! 942: // This macro returns a NDIS_HANDLE from a PLANCE_OPEN ! 943: // ! 944: #define BINDING_HANDLE_FROM_PLANCE_OPEN(Open) \ ! 945: ((NDIS_HANDLE)(Open)) ! 946: ! 947: ! 948: // ! 949: // This macro will act a "epilogue" to every routine in the ! 950: // *interface*. It will check whether any requests need ! 951: // to defer their processing. It will also decrement the reference ! 952: // count on the adapter. If the reference count is zero and there ! 953: // is deferred work to do it will insert the interrupt processing ! 954: // routine in the DPC queue. ! 955: // ! 956: // Note that we don't need to include checking for blocked receives ! 957: // since blocked receives imply that there will eventually be an ! 958: // interrupt. ! 959: // ! 960: // NOTE: This macro assumes that it is called with the lock acquired. ! 961: // ! 962: // ZZZ This routine is NT specific. ! 963: // ! 964: #define LANCE_DO_DEFERRED(Adapter) \ ! 965: { \ ! 966: PLANCE_ADAPTER _A = (Adapter); \ ! 967: _A->References--; \ ! 968: if ((!_A->References) && \ ! 969: (_A->ResetInProgress || \ ! 970: _A->FirstLoopBack || \ ! 971: (!IsListEmpty(&_A->CloseList)))) { \ ! 972: NdisReleaseSpinLock(&_A->Lock); \ ! 973: NdisSetTimer(&_A->DeferredTimer, 0);\ ! 974: } else { \ ! 975: NdisReleaseSpinLock(&_A->Lock); \ ! 976: } \ ! 977: } ! 978: ! 979: ! 980: ! 981: ! 982: // ! 983: // Procedures which log errors. ! 984: // ! 985: ! 986: typedef enum _LANCE_PROC_ID { ! 987: openAdapter, ! 988: processInterrupt ! 989: } LANCE_PROC_ID; ! 990: ! 991: ! 992: #define LANCE_ERRMSG_NDIS_ALLOC_MEM (ULONG)0x01 ! 993: ! 994: ! 995: ! 996: ! 997: ! 998: ! 999: ! 1000: ! 1001: ! 1002: ! 1003: ! 1004: ! 1005: ! 1006: ! 1007: // ! 1008: // This macro is used to "allocate" memory for the structures that ! 1009: // must be shared with the hardware. It assigns a pvoid that is ! 1010: // at least quadword aligned. ! 1011: // ! 1012: #define LANCE_ALLOCATE_MEMORY_FOR_HARDWARE(A,S,P) \ ! 1013: { \ ! 1014: PLANCE_ADAPTER _Adapter = (A); \ ! 1015: UINT _Size = (((S) + 7)/8)*8; \ ! 1016: PVOID _HighWater; \ ! 1017: if (!_Size) { \ ! 1018: *(P) = NULL; \ ! 1019: } else { \ ! 1020: _HighWater = ((PCHAR)_Adapter->CurrentMemoryFirstFree) + _Size; \ ! 1021: if (((PUCHAR)_HighWater) > \ ! 1022: (((PUCHAR)_Adapter->MemoryFirstUnavailable) + 1)) { \ ! 1023: *(P) = NULL; \ ! 1024: } else { \ ! 1025: *(P) = _Adapter->CurrentMemoryFirstFree; \ ! 1026: _Adapter->CurrentMemoryFirstFree = _HighWater; \ ! 1027: } \ ! 1028: } \ ! 1029: } ! 1030: ! 1031: // ! 1032: // We now convert the virtual address to the actual physical address. ! 1033: // ! 1034: #ifdef NDIS_NT ! 1035: ! 1036: #define LANCE_GET_HARDWARE_PHYSICAL_ADDRESS(A,P) \ ! 1037: (RtlConvertUlongToLargeInteger((ULONG) \ ! 1038: ((ULONG)((PVOID)P) - (ULONG)((PVOID)A->MmMappedBaseAddr) + (A->HardwareBaseOffset)))) ! 1039: ! 1040: #else ! 1041: ! 1042: #define LANCE_GET_HARDWARE_PHYSICAL_ADDRESS(A,P) \ ! 1043: ((ULONG)((PUCHAR)(A->HardwareBaseAddr) +\ ! 1044: ((ULONG)((PVOID)P) - (ULONG)((PVOID)A->MmMappedBaseAddr)))) ! 1045: ! 1046: #endif //NDIS_NT ! 1047: ! 1048: ! 1049: // ! 1050: // This macro is used to "deallocate the memory from the hardware. ! 1051: // Since this is hardware memory that is only allocated and deallocated ! 1052: // once this macro really doesn't do anything. ! 1053: // ! 1054: #define LANCE_DEALLOCATE_MEMORY_FOR_HARDWARE(A,P)\ ! 1055: {\ ! 1056: } ! 1057: ! 1058: ! 1059: ! 1060: ! 1061: ! 1062: // ! 1063: // These are routines for synchronizing with the ISR ! 1064: // ! 1065: ! 1066: ! 1067: // ! 1068: // This structure is used to synchronize reading and writing to ports ! 1069: // with the ISR. ! 1070: // ! 1071: ! 1072: typedef struct _LANCE_SYNCH_CONTEXT { ! 1073: ! 1074: // ! 1075: // Pointer to the lance adapter for which interrupts are ! 1076: // being synchronized. ! 1077: // ! 1078: PLANCE_ADAPTER Adapter; ! 1079: ! 1080: // ! 1081: // Pointer to a local variable that will receive the value ! 1082: // ! 1083: PUSHORT LocalRead; ! 1084: ! 1085: // ! 1086: // Value to write ! 1087: // ! 1088: USHORT LocalWrite; ! 1089: ! 1090: } LANCE_SYNCH_CONTEXT,*PLANCE_SYNCH_CONTEXT; ! 1091: ! 1092: ! 1093: ! 1094: #define LANCE_WRITE_RAP(A,C) { \ ! 1095: PLANCE_ADAPTER _A = A; \ ! 1096: LANCE_SYNCH_CONTEXT _C; \ ! 1097: _C.Adapter = _A; \ ! 1098: _C.LocalWrite = (C); \ ! 1099: NdisSynchronizeWithInterrupt( \ ! 1100: &(_A)->Interrupt, \ ! 1101: LanceSyncWriteRAP, \ ! 1102: &_C \ ! 1103: ); \ ! 1104: } ! 1105: ! 1106: ! 1107: #define LANCE_WRITE_RDP(A,C) { \ ! 1108: PLANCE_ADAPTER _A = A; \ ! 1109: LANCE_SYNCH_CONTEXT _C; \ ! 1110: _C.Adapter = _A; \ ! 1111: _C.LocalWrite = (C); \ ! 1112: NdisSynchronizeWithInterrupt( \ ! 1113: &(_A)->Interrupt, \ ! 1114: LanceSyncWriteRDP, \ ! 1115: &_C \ ! 1116: ); \ ! 1117: } ! 1118: ! 1119: #define LANCE_READ_RDP(A,C) { \ ! 1120: PLANCE_ADAPTER _A = A; \ ! 1121: LANCE_SYNCH_CONTEXT _C; \ ! 1122: _C.Adapter = _A; \ ! 1123: _C.LocalRead = (C); \ ! 1124: NdisSynchronizeWithInterrupt( \ ! 1125: &(_A)->Interrupt, \ ! 1126: LanceSyncReadRDP, \ ! 1127: &_C \ ! 1128: ); \ ! 1129: } ! 1130: ! 1131: #define LANCE_WRITE_NICSR(A,C) { \ ! 1132: PLANCE_ADAPTER _A = A; \ ! 1133: LANCE_SYNCH_CONTEXT _C; \ ! 1134: _C.Adapter = _A; \ ! 1135: _C.LocalWrite = (C | _A->NicsrDefaultValue); \ ! 1136: NdisSynchronizeWithInterrupt( \ ! 1137: &(_A)->Interrupt, \ ! 1138: LanceSyncWriteNicsr, \ ! 1139: &_C \ ! 1140: ); \ ! 1141: } ! 1142: ! 1143: ! 1144: ! 1145: BOOLEAN ! 1146: LanceSyncWriteRAP( ! 1147: IN PVOID Context ! 1148: ); ! 1149: ! 1150: BOOLEAN ! 1151: LanceSyncWriteRDP( ! 1152: IN PVOID Context ! 1153: ); ! 1154: ! 1155: BOOLEAN ! 1156: LanceSyncReadRDP( ! 1157: IN PVOID Context ! 1158: ); ! 1159: ! 1160: BOOLEAN ! 1161: LanceSyncWriteNicsr( ! 1162: IN PVOID Context ! 1163: ); ! 1164: ! 1165: BOOLEAN ! 1166: LanceSyncGetInterruptsStopped( ! 1167: IN PVOID Context ! 1168: ); ! 1169: ! 1170: BOOLEAN ! 1171: LanceSyncStopChip( ! 1172: IN PVOID Context ! 1173: ); ! 1174: ! 1175: ! 1176: // ! 1177: // We define the external interfaces to the lance driver. ! 1178: // These routines are only external to permit separate ! 1179: // compilation. Given a truely fast compiler they could ! 1180: // all reside in a single file and be static. ! 1181: // ! 1182: ! 1183: extern ! 1184: NDIS_STATUS ! 1185: LanceTransferData( ! 1186: IN NDIS_HANDLE MacBindingHandle, ! 1187: IN NDIS_HANDLE MacReceiveContext, ! 1188: IN UINT ByteOffset, ! 1189: IN UINT BytesToTransfer, ! 1190: OUT PNDIS_PACKET Packet, ! 1191: OUT PUINT BytesTransferred ! 1192: ); ! 1193: ! 1194: extern ! 1195: NDIS_STATUS ! 1196: LanceSend( ! 1197: IN NDIS_HANDLE MacBindingHandle, ! 1198: IN PNDIS_PACKET Packet ! 1199: ); ! 1200: ! 1201: ! 1202: extern ! 1203: VOID ! 1204: LanceStagedAllocation( ! 1205: IN PLANCE_ADAPTER Adapter ! 1206: ); ! 1207: ! 1208: extern ! 1209: VOID ! 1210: LanceCopyFromPacketToBuffer( ! 1211: IN PNDIS_PACKET Packet, ! 1212: IN UINT Offset, ! 1213: IN UINT BytesToCopy, ! 1214: OUT PCHAR Buffer, ! 1215: OUT PUINT BytesCopied ! 1216: ); ! 1217: ! 1218: extern ! 1219: VOID ! 1220: LanceCopyFromPacketToPacket( ! 1221: IN PNDIS_PACKET Destination, ! 1222: IN UINT DestinationOffset, ! 1223: IN UINT BytesToCopy, ! 1224: IN PNDIS_PACKET Source, ! 1225: IN UINT SourceOffset, ! 1226: OUT PUINT BytesCopied ! 1227: ); ! 1228: ! 1229: extern ! 1230: VOID ! 1231: LanceProcessLoopback( ! 1232: IN PLANCE_ADAPTER Adapter ! 1233: ); ! 1234: ! 1235: extern ! 1236: BOOLEAN ! 1237: LanceHardwareDetails( ! 1238: IN PLANCE_ADAPTER Adapter ! 1239: ); ! 1240: ! 1241: extern ! 1242: NDIS_STATUS ! 1243: LanceRegisterAdapter( ! 1244: IN PLANCE_ADAPTER Adapter ! 1245: ); ! 1246: ! 1247: NDIS_STATUS ! 1248: LanceAddAdapter( ! 1249: IN NDIS_HANDLE MacMacContext, ! 1250: IN NDIS_HANDLE ConfigurationHandle, ! 1251: IN PNDIS_STRING AdaptName ! 1252: ); ! 1253: ! 1254: VOID ! 1255: LanceRemoveAdapter( ! 1256: IN PVOID MacAdapterContext ! 1257: ); ! 1258: ! 1259: VOID ! 1260: SetupAllocate( ! 1261: IN PLANCE_ADAPTER Adapter, ! 1262: IN NDIS_HANDLE MacBindingHandle, ! 1263: IN PNDIS_PACKET Packet ! 1264: ); ! 1265: ! 1266: VOID ! 1267: LanceWakeUpDpc( ! 1268: IN PVOID SystemSpecific1, ! 1269: IN PVOID Context, ! 1270: IN PVOID SystemSpecific2, ! 1271: IN PVOID SystemSpecific3 ! 1272: ); ! 1273: ! 1274: #endif // _LANCESFT_ ! 1275:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.