9b4b3c32370195dd8c62dd15049beb268517c408
[tpg/acess2.git] / UDI / drivers / net_ne2000 / ne2000_rx.c
1 /*
2  * UDI Ne2000 NIC Driver
3  * By John Hodge (thePowersGang)
4  *
5  * ne2000_rx.c
6  * - Receive Code
7  */
8 #define UDI_VERSION     0x101
9 #define UDI_NIC_VERSION 0x101
10 #include <udi.h>
11 #include <udi_nic.h>
12 #include "ne2000_common.h"
13
14 // === PROTOTYPES ===
15 udi_buf_write_call_t    ne2k_rx__buf_allocated;
16 udi_pio_trans_call_t    ne2k_rx__complete;
17
18 // === CODE ===
19 void ne2k_nd_rx_channel_event_ind(udi_channel_event_cb_t *cb)
20 {
21 }
22 void ne2k_nd_rx_rx_rdy(udi_nic_rx_cb_t *cb)
23 {
24         udi_cb_t        *gcb = UDI_GCB(cb);
25         ne2k_rdata_t    *rdata = gcb->context;
26         
27         // Add cb(s) to avaliable list
28         if( rdata->rx_next_cb ) {
29                 rdata->rx_last_cb->chain = cb;
30         }
31         else {
32                 rdata->rx_next_cb = cb;
33         }
34         rdata->rx_last_cb = cb;
35         // Follow new chain
36         while( rdata->rx_last_cb->chain ) {
37                 rdata->rx_last_cb = rdata->rx_last_cb->chain;
38         }
39         
40 }
41 void ne2k_intr__rx_ok(udi_cb_t *gcb)
42 {
43         ne2k_rdata_t    *rdata = gcb->context;
44         if( rdata->rx_next_cb )
45         {
46                 udi_nic_rx_cb_t *rx_cb = rdata->rx_next_cb;
47                 rdata->rx_next_cb = rx_cb->chain;
48                 rx_cb->chain = NULL;
49                 udi_debug_printf("ne2k_intr__rx_ok: Initialising buffer\n");
50                 udi_buf_write(ne2k_rx__buf_allocated, UDI_GCB(rx_cb), NULL, 1520, rx_cb->rx_buf, 0, 0, UDI_NULL_BUF_PATH);
51         }
52         else
53         {
54                 // Drop packet due to no free cbs
55                 udi_debug_printf("ne2k_intr__rx_ok: Dropped due to no free rx cbs\n");
56                 // TODO: Tell hardware to drop packet
57         }
58 }
59
60 void ne2k_rx__buf_allocated(udi_cb_t *gcb, udi_buf_t *new_buf)
61 {
62         ne2k_rdata_t    *rdata = gcb->context;
63         udi_nic_rx_cb_t *rx_cb = UDI_MCB(gcb, udi_nic_rx_cb_t);
64         
65         udi_debug_printf("ne2k_rx__buf_allocated: Buffer ready, cb=%p\n", rx_cb);
66         udi_pio_trans(ne2k_rx__complete, gcb,
67                 rdata->pio_handles[NE2K_PIO_RX], 0, rx_cb->rx_buf, &rdata->rx_next_page);
68 }
69
70 void ne2k_rx__complete(udi_cb_t *gcb, udi_buf_t *new_buf, udi_status_t status, udi_ubit16_t result)
71 {
72         udi_nic_rx_cb_t *rx_cb = UDI_MCB(gcb, udi_nic_rx_cb_t);
73         rx_cb->rx_buf->buf_size = result;
74         // TODO: Check result
75         udi_nsr_rx_ind( rx_cb );
76 }
77
78

UCC git Repository :: git.ucc.asn.au