2 * UDI Ne2000 NIC Driver
3 * By John Hodge (thePowersGang)
10 #include "ne2000_common.h"
29 #define NE2K_NUM_INTR_EVENT_CBS 4
32 // --- Programmed IO ---
33 #include "ne2000_pio.h"
37 void ne2k_usage_ind(udi_usage_cb_t *cb, udi_ubit8_t resource_level)
41 void ne2k_enumerate_req(udi_enumerate_cb_t *cb, udi_ubit8_t enumeration_level)
43 ne2k_rdata_t *rdata = UDI_GCB(cb)->context;
44 udi_instance_attr_list_t *attr_list = cb->attr_list;
46 switch(enumeration_level)
48 case UDI_ENUMERATE_START:
49 case UDI_ENUMERATE_START_RESCAN:
50 // Emit the ND binding
51 DPT_SET_ATTR32(attr_list, "if_num", 0);
53 DPT_SET_ATTR_STRING(attr_list, "if_media", "eth", 3);
55 NE2K_SET_ATTR_STRFMT(attr_list, "identifier", 2*6+1, "%02X%02X%02X%02X%02X%02X",
56 rdata->macaddr[0], rdata->macaddr[1], rdata->macaddr[2],
57 rdata->macaddr[3], rdata->macaddr[4], rdata->macaddr[5] );
59 cb->attr_valid_length = attr_list - cb->attr_list;
60 udi_enumerate_ack(cb, UDI_ENUMERATE_OK, NE2K_OPS_CTRL);
62 case UDI_ENUMERATE_NEXT:
63 udi_enumerate_ack(cb, UDI_ENUMERATE_DONE, 0);
67 void ne2k_devmgmt_req(udi_mgmt_cb_t *cb, udi_ubit8_t mgmt_op, udi_ubit8_t parent_ID)
70 void ne2k_final_cleanup_req(udi_mgmt_cb_t *cb)
74 void ne2k_bus_dev_channel_event_ind(udi_channel_event_cb_t *cb)
76 udi_cb_t *gcb = UDI_GCB(cb);
77 ne2k_rdata_t *rdata = gcb->context;
81 case UDI_CHANNEL_CLOSED:
83 case UDI_CHANNEL_BOUND: {
84 rdata->active_cb = gcb;
85 udi_bus_bind_cb_t *bus_bind_cb = UDI_MCB(cb->params.parent_bound.bind_cb, udi_bus_bind_cb_t);
86 udi_bus_bind_req( bus_bind_cb );
87 // continue at ne2k_bus_dev_bus_bind_ack
91 void ne2k_bus_dev_bus_bind_ack(udi_bus_bind_cb_t *cb,
92 udi_dma_constraints_t dma_constraints, udi_ubit8_t perferred_endianness, udi_status_t status)
94 udi_cb_t *gcb = UDI_GCB(cb);
95 ne2k_rdata_t *rdata = gcb->context;
98 rdata->init.pio_index = -1;
99 ne2k_bus_dev_bind__pio_map(gcb, UDI_NULL_PIO_HANDLE);
101 void ne2k_bus_dev_bind__pio_map(udi_cb_t *gcb, udi_pio_handle_t new_pio_handle)
103 ne2k_rdata_t *rdata = gcb->context;
105 if( rdata->init.pio_index != (udi_index_t)-1 )
107 rdata->pio_handles[rdata->init.pio_index] = new_pio_handle;
108 udi_debug_printf("PIO %i = %p\n", rdata->init.pio_index, new_pio_handle);
110 rdata->init.pio_index ++;
111 if( rdata->init.pio_index < NE2K_NUM_PIO_OPS )
113 udi_pio_map(ne2k_bus_dev_bind__pio_map, gcb,
114 UDI_PCI_BAR_0, 0, 0x20,
115 ne2k_pio_ops[rdata->init.pio_index].trans_list,
116 ne2k_pio_ops[rdata->init.pio_index].list_length,
117 UDI_PIO_LITTLE_ENDIAN, 0, 0
122 // Next: Bind interrupt
123 // - spawn_idx = Interrupt number (0)
124 udi_channel_spawn(ne2k_bus_dev_bind__intr_chanel, gcb, gcb->channel,
125 0, NE2K_OPS_IRQ, rdata);
128 void ne2k_bus_dev_bind__intr_chanel(udi_cb_t *gcb, udi_channel_t new_channel)
130 ne2k_rdata_t *rdata = gcb->context;
132 rdata->interrupt_channel = new_channel;
134 udi_cb_alloc(ne2k_bus_dev_bind__intr_attach, gcb, NE2K_CB_INTR, gcb->channel);
137 void ne2k_bus_dev_bind__intr_attach(udi_cb_t *gcb, udi_cb_t *new_cb)
139 ne2k_rdata_t *rdata = gcb->context;
143 udi_channel_event_complete( UDI_MCB(rdata->active_cb, udi_channel_event_cb_t),
144 UDI_STAT_RESOURCE_UNAVAIL );
147 udi_intr_attach_cb_t *intr_cb = UDI_MCB(new_cb, udi_intr_attach_cb_t);
148 intr_cb->interrupt_idx = 0;
149 intr_cb->min_event_pend = 2;
150 intr_cb->preprocessing_handle = rdata->pio_handles[NE2K_PIO_IRQACK];
151 udi_intr_attach_req(intr_cb);
152 // continued in ne2k_bus_dev_intr_attach_ack
154 void ne2k_bus_dev_bus_unbind_ack(udi_bus_bind_cb_t *cb)
157 void ne2k_bus_dev_intr_attach_ack(udi_intr_attach_cb_t *intr_attach_cb, udi_status_t status)
159 udi_cb_t *gcb = UDI_GCB(intr_attach_cb);
160 ne2k_rdata_t *rdata = gcb->context;
161 // continuing from ne2k_bus_dev_bind__intr_attach
162 if( status != UDI_OK ) {
164 udi_cb_free( UDI_GCB(intr_attach_cb) );
168 rdata->intr_attach_cb = intr_attach_cb;
170 rdata->init.n_intr_event_cb = 0;
171 udi_cb_alloc(ne2k_bus_dev_bind__intr_event_cb, gcb, NE2K_CB_INTR_EVENT, rdata->interrupt_channel);
174 void ne2k_bus_dev_bind__intr_event_cb(udi_cb_t *gcb, udi_cb_t *new_cb)
176 ne2k_rdata_t *rdata = gcb->context;
178 udi_intr_event_cb_t *intr_event_cb = UDI_MCB(new_cb, udi_intr_event_cb_t);
179 udi_intr_event_rdy(intr_event_cb);
180 rdata->init.n_intr_event_cb ++;
182 if( rdata->init.n_intr_event_cb < NE2K_NUM_INTR_EVENT_CBS )
184 udi_cb_alloc(ne2k_bus_dev_bind__intr_event_cb, gcb,
185 NE2K_CB_INTR_EVENT, rdata->interrupt_channel);
190 udi_pio_trans(ne2k_bus_dev_bind__card_reset, gcb,
191 rdata->pio_handles[NE2K_PIO_RESET], 0, NULL, &rdata->macaddr);
195 void ne2k_bus_dev_bind__card_reset(udi_cb_t *gcb, udi_buf_t *new_buf, udi_status_t status, udi_ubit16_t result)
197 ne2k_rdata_t *rdata = gcb->context;
199 udi_channel_event_complete( UDI_MCB(rdata->active_cb, udi_channel_event_cb_t), UDI_OK );
202 void ne2k_bus_dev_intr_detach_ack(udi_intr_detach_cb_t *intr_detach_cb)
206 void ne2k_nd_ctrl_channel_event_ind(udi_channel_event_cb_t *cb)
209 void ne2k_nd_ctrl_bind_req(udi_nic_bind_cb_t *cb, udi_index_t tx_chan_index, udi_index_t rx_chan_index)
211 udi_cb_t *gcb = UDI_GCB(cb);
212 ne2k_rdata_t *rdata = gcb->context;
213 rdata->init.rx_chan_index = rx_chan_index;
214 udi_channel_spawn(ne2k_nd_ctrl_bind__tx_chan_ok, gcb, gcb->channel, tx_chan_index, NE2K_OPS_TX, rdata);
217 void ne2k_nd_ctrl_bind__tx_chan_ok(udi_cb_t *gcb, udi_channel_t new_channel)
219 ne2k_rdata_t *rdata = gcb->context;
220 rdata->tx_channel = new_channel;
221 udi_channel_spawn(ne2k_nd_ctrl_bind__rx_chan_ok, gcb, gcb->channel,
222 rdata->init.rx_chan_index, NE2K_OPS_RX, rdata);
225 void ne2k_nd_ctrl_bind__rx_chan_ok(udi_cb_t *gcb, udi_channel_t new_channel)
227 ne2k_rdata_t *rdata = gcb->context;
228 rdata->rx_channel = new_channel;
230 udi_nic_bind_cb_t *cb = UDI_MCB(gcb, udi_nic_bind_cb_t);
231 cb->media_type = UDI_NIC_ETHER;
232 cb->min_pdu_size = 0;
233 cb->max_pdu_size = 0;
234 cb->rx_hw_threshold = 2;
235 cb->capabilities = 0;
236 cb->max_perfect_multicast = 0;
237 cb->max_total_multicast = 0;
238 cb->mac_addr_len = 6;
239 memcpy(cb->mac_addr, rdata->macaddr, 6);
240 udi_nsr_bind_ack( cb, UDI_OK );
243 void ne2k_nd_ctrl_unbind_req(udi_nic_cb_t *cb)
246 void ne2k_nd_ctrl_enable_req(udi_nic_cb_t *cb)
250 void ne2k_nd_ctrl_disable_req(udi_nic_cb_t *cb)
253 void ne2k_nd_ctrl_ctrl_req(udi_nic_ctrl_cb_t *cb)
256 void ne2k_nd_ctrl_info_req(udi_nic_info_cb_t *cb, udi_boolean_t reset_statistics)
260 void ne2k_bus_irq_channel_event_ind(udi_channel_event_cb_t *cb)
263 void ne2k_bus_irq_intr_event_ind(udi_intr_event_cb_t *cb, udi_ubit8_t flags)
265 if( cb->intr_result & 0x01 )
267 ne2k_intr__rx_ok( UDI_GCB(cb) );
269 if( cb->intr_result & 0x40 )
271 // ne2k_intr__rdma( UDI_GCB(cb) );
274 udi_intr_event_rdy(cb);
277 // === Definition structures ===
278 udi_mgmt_ops_t ne2k_mgmt_ops = {
282 ne2k_final_cleanup_req
284 udi_ubit8_t ne2k_mgmt_op_flags[4] = {0,0,0,0};
285 udi_bus_device_ops_t ne2k_bus_dev_ops = {
286 ne2k_bus_dev_channel_event_ind,
287 ne2k_bus_dev_bus_bind_ack,
288 ne2k_bus_dev_bus_unbind_ack,
289 ne2k_bus_dev_intr_attach_ack,
290 ne2k_bus_dev_intr_detach_ack
292 udi_ubit8_t ne2k_bus_dev_ops_flags[5] = {0};
293 udi_nd_ctrl_ops_t ne2k_nd_ctrl_ops = {
294 ne2k_nd_ctrl_channel_event_ind,
295 ne2k_nd_ctrl_bind_req,
296 ne2k_nd_ctrl_unbind_req,
297 ne2k_nd_ctrl_enable_req,
298 ne2k_nd_ctrl_disable_req,
299 ne2k_nd_ctrl_ctrl_req,
300 ne2k_nd_ctrl_info_req
302 udi_ubit8_t ne2k_nd_ctrl_ops_flags[7] = {0};
303 udi_nd_tx_ops_t ne2k_nd_tx_ops = {
304 ne2k_nd_tx_channel_event_ind,
306 ne2k_nd_tx_exp_tx_req
308 udi_ubit8_t ne2k_nd_tx_ops_flags[3] = {0};
309 udi_nd_rx_ops_t ne2k_nd_rx_ops = {
310 ne2k_nd_rx_channel_event_ind,
313 udi_ubit8_t ne2k_nd_rx_ops_flags[2] = {0};
314 udi_intr_handler_ops_t ne2k_bus_irq_ops = {
315 ne2k_bus_irq_channel_event_ind,
316 ne2k_bus_irq_intr_event_ind
318 udi_ubit8_t ne2k_bus_irq_ops_flags[2] = {0};
320 udi_primary_init_t ne2k_pri_init = {
321 .mgmt_ops = &ne2k_mgmt_ops,
322 .mgmt_op_flags = ne2k_mgmt_op_flags,
323 .mgmt_scratch_requirement = 0,
324 .enumeration_attr_list_length = 4,
325 .rdata_size = sizeof(ne2k_rdata_t),
326 .child_data_size = 0,
327 .per_parent_paths = 0
329 udi_ops_init_t ne2k_ops_list[] = {
331 NE2K_OPS_DEV, NE2K_META_BUS, UDI_BUS_DEVICE_OPS_NUM,
333 (udi_ops_vector_t*)&ne2k_bus_dev_ops,
334 ne2k_bus_dev_ops_flags
337 NE2K_OPS_CTRL, NE2K_META_NIC, UDI_ND_CTRL_OPS_NUM,
339 (udi_ops_vector_t*)&ne2k_nd_ctrl_ops,
340 ne2k_nd_ctrl_ops_flags
343 NE2K_OPS_TX, NE2K_META_NIC, UDI_ND_TX_OPS_NUM,
345 (udi_ops_vector_t*)&ne2k_nd_tx_ops,
349 NE2K_OPS_RX, NE2K_META_NIC, UDI_ND_RX_OPS_NUM,
351 (udi_ops_vector_t*)&ne2k_nd_rx_ops,
355 NE2K_OPS_IRQ, NE2K_META_BUS, UDI_BUS_INTR_HANDLER_OPS_NUM,
357 (udi_ops_vector_t*)&ne2k_bus_irq_ops,
358 ne2k_bus_irq_ops_flags
362 udi_cb_init_t ne2k_cb_init_list[] = {
363 {NE2K_CB_BUS_BIND, NE2K_META_BUS, UDI_BUS_BIND_CB_NUM, 0, 0,NULL},
364 {NE2K_CB_INTR, NE2K_META_BUS, UDI_BUS_INTR_ATTACH_CB_NUM, 0, 0,NULL},
365 {NE2K_CB_INTR_EVENT, NE2K_META_BUS, UDI_BUS_INTR_EVENT_CB_NUM, 0, 0,NULL},
368 const udi_init_t udi_init_info = {
369 .primary_init_info = &ne2k_pri_init,
370 .ops_init_list = ne2k_ops_list,
371 .cb_init_list = ne2k_cb_init_list,