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

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