summaryrefslogtreecommitdiffstats
path: root/private/ntos/ndis/htdsu/receive.c
blob: 08ddb1ab9467ae0846311534527ceca433d9a339 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/***************************************************************************\
|* Copyright (c) 1994  Microsoft Corporation                               *|
|* Developed for Microsoft by TriplePoint, Inc. Beaverton, Oregon          *|
|*                                                                         *|
|* This file is part of the HT Communications DSU41 WAN Miniport Driver.   *|
\***************************************************************************/
#include "version.h"
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Module Name:

    receive.c

Abstract:

    This module contains the Miniport packet receive routines.

    This driver conforms to the NDIS 3.0 Miniport interface.

Author:

    Larry Hattery - TriplePoint, Inc. (larryh@tpi.com) Jun-94

Environment:

    Windows NT 3.5 kernel mode Miniport driver or equivalent.

Revision History:

---------------------------------------------------------------------------*/

#define  __FILEID__     6       // Unique file ID for error logging

#include "htdsu.h"


VOID
HtDsuReceivePacket(
    IN PHTDSU_ADAPTER   Adapter
    )

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Routine Description:

    This routine is called from HtDsuHandleInterrupt to handle a
    packet receive interrupt.  We enter here with interrupts enabled
    on the adapter and the processor, but the Adapter->Lock is held.

    We examine the adapter memory beginning where the adapter would have
    stored the next packet.
    As we find each good packet it is passed up to the protocol stack.
    This code assumes that the receive buffer holds a single packet.

    NOTE: The Adapter->Lock must be held before calling this routine.

Arguments:

    Adapter _ A pointer ot our adapter information structure.

Return Value:

    None.

---------------------------------------------------------------------------*/

{
    DBG_FUNC("HtDsuReceivePacket")

    NDIS_STATUS Status;

    /*
    // A pointer to our link information structure for the selected line device.
    */
    PHTDSU_LINK Link;

    /*
    // Holds the card line number on which the packet is received.
    */
    USHORT CardLine;

    /*
    // How many bytes were received in this packet.
    */
    USHORT BytesReceived;

    /*
    // Non-zero if there were any errors detected in the packet.
    */
    USHORT RxErrors;

    DBG_ENTER(Adapter);

    /*
    // If the packet is good, we pass it up to the protocol stack.
    // We just drop bad packets with no indication sent.
    */
    CardGetReceiveInfo(Adapter, &CardLine, &BytesReceived, &RxErrors);

    /*
    // Don't send any bad packets to the wrapper, just indicate the error.
    */
    if (RxErrors)
    {
        DBG_WARNING(Adapter, ("RxError=%Xh on line %d\n",RxErrors, CardLine));

        Link = GET_LINK_FROM_CARDLINE(Adapter, CardLine);

        if (RxErrors & HTDSU_CRC_ERROR)
        {
            LinkLineError(Link, WAN_ERROR_CRC);
        }
        else
        {
            LinkLineError(Link, WAN_ERROR_FRAMING);
        }
    }
    else if (BytesReceived)
    {
#if DBG
        if (Adapter->DbgFlags & (DBG_PACKETS_ON | DBG_HEADERS_ON))
        {
            DbgPrint("Rx:%03X:",BytesReceived);
            if (Adapter->DbgFlags & DBG_PACKETS_ON)
                DbgPrintData((PUCHAR)&(Adapter->AdapterRam->RxBuffer), BytesReceived+8, 0);
            else
                DbgPrintData((PUCHAR)&(Adapter->AdapterRam->RxBuffer), 0x10, 0);
        }
#endif
        /*
        // Is there someone up there who cares?
        */
        Link = GET_LINK_FROM_CARDLINE(Adapter, CardLine);

        if (Link->NdisLinkContext == NULL)
        {
            DBG_WARNING(Adapter, ("Packet recvd on disconnected line #%d",CardLine));
        }
        else
        {
            /*
            // We have to copy the data to a system buffer so it can be
            // accessed one byte at a time by the protocols.
            // The adapter memory only supports word wide access.
            */
            {
                // FIXME - can I use this much stack space?
                USHORT TempBuf[HTDSU_MAX_PACKET_SIZE / sizeof(USHORT) + 1];

                READ_REGISTER_BUFFER_USHORT(
                        &Adapter->AdapterRam->RxBuffer.Data[0],
                        &TempBuf[0],
                        (UINT)((BytesReceived + 1) / sizeof(USHORT))
                        );

                /*
                // Spec sez we have to release the spinlock before calling
                // up to indiciate the packet.
                */
                NdisReleaseSpinLock(&Adapter->Lock);

                NdisMWanIndicateReceive(
                        &Status,
                        Adapter->MiniportAdapterHandle,
                        Link->NdisLinkContext,
                        (PUCHAR) TempBuf,
                        BytesReceived
                        );
            }

            /*
            // Indicate receive complete if we had any that were accepted.
            */
            if (Status == NDIS_STATUS_SUCCESS)
            {
                NdisMWanIndicateReceiveComplete(
                        Adapter->MiniportAdapterHandle,
                        Link->NdisLinkContext
                        );
            }
            else
            {
                DBG_WARNING(Adapter,("NdisMWanIndicateReceive returned error 0x%X\n",
                            Status));
            }

            NdisAcquireSpinLock(&Adapter->Lock);
        }
    }

    /*
    // Tell the adapter we have processed this packet so it can re-use the
    // buffer.
    */
    CardReceiveComplete(Adapter);

    DBG_LEAVE(Adapter);
}