2 * UDI Ne2000 NIC Driver
3 * By John Hodge (thePowersGang)
10 #include "ne2000_common.h"
28 #define NE2K_NUM_INTR_EVENT_CBS 4
31 #define PIO_op_RI(op, reg, sz, val) {UDI_PIO_##op+UDI_PIO_DIRECT+UDI_PIO_##reg, UDI_PIO_##sz##BYTE, val}
32 #define PIO_MOV_RI1(reg, val) PIO_op_RI(LOAD_IMM, reg, 1, val)
33 #define PIO_OUT_RI1(reg, ofs) PIO_op_RI(OUT, reg, 1, ofs)
34 #define PIO_IN_RI1(reg, ofs) PIO_op_RI(IN, reg, 1, ofs)
35 // --- Programmed IO ---
36 #include "ne2000_pio.h"
40 void ne2k_usage_ind(udi_usage_cb_t *cb, udi_ubit8_t resource_level)
43 void ne2k_enumerate_req(udi_enumerate_cb_t *cb, udi_ubit8_t enumeration_level)
45 ne2k_rdata_t *rdata = UDI_GCB(cb)->context;
46 udi_instance_attr_list_t *attr_list = cb->attr_list;
48 switch(enumeration_level)
50 case UDI_ENUMERATE_START:
51 case UDI_ENUMERATE_START_RESCAN:
52 // Emit the ND binding
53 DPT_SET_ATTR32(attr_list, "if_num", 0);
55 DPT_SET_ATTR_STRING(attr_list, "if_media", "eth", 3);
57 NE2K_SET_ATTR_STRFMT(attr_list, "identifier", 2*6+1, "%2X%2X%2X%2X%2X%2X",
58 rdata->macaddr[0], rdata->macaddr[1], rdata->macaddr[2],
59 rdata->macaddr[3], rdata->macaddr[4], rdata->macaddr[5] );
61 cb->attr_valid_length = attr_list - cb->attr_list;
62 udi_enumerate_ack(cb, UDI_ENUMERATE_OK, NE2K_OPS_CTRL);
64 case UDI_ENUMERATE_NEXT:
65 udi_enumerate_ack(cb, UDI_ENUMERATE_DONE, 0);
69 void ne2k_devmgmt_req(udi_mgmt_cb_t *cb, udi_ubit8_t mgmt_op, udi_ubit8_t parent_ID)
72 void ne2k_final_cleanup_req(udi_mgmt_cb_t *cb)
76 void ne2k_bus_dev_channel_event_ind(udi_channel_event_cb_t *cb)
80 case UDI_CHANNEL_CLOSED:
82 case UDI_CHANNEL_BOUND: {
83 udi_bus_bind_cb_t *bus_bind_cb = UDI_MCB(cb->params.parent_bound.bind_cb, udi_bus_bind_cb_t);
84 udi_bus_bind_req( bus_bind_cb );
85 // continue at ne2k_bus_dev_bus_bind_ack
89 void ne2k_bus_dev_bus_bind_ack(udi_bus_bind_cb_t *cb,
90 udi_dma_constraints_t dma_constraints, udi_ubit8_t perferred_endianness, udi_status_t status)
92 udi_cb_t *gcb = UDI_GCB(cb);
93 ne2k_rdata_t *rdata = gcb->context;
94 rdata->active_cb = gcb;
97 rdata->init.pio_index = -1;
98 ne2k_bus_dev_bind__pio_map(gcb, UDI_NULL_PIO_HANDLE);
100 void ne2k_bus_dev_bind__pio_map(udi_cb_t *gcb, udi_pio_handle_t new_pio_handle)
102 ne2k_rdata_t *rdata = gcb->context;
104 if( rdata->init.pio_index != -1 )
106 rdata->pio_handles[rdata->init.pio_index] = new_pio_handle;
108 rdata->init.pio_index ++;
109 if( rdata->init.pio_index < NE2K_NUM_PIO_OPS )
111 udi_pio_map(ne2k_bus_dev_bind__pio_map, gcb,
112 UDI_PCI_BAR_0, 0, 0x20,
113 ne2k_pio_ops[rdata->init.pio_index].trans_list,
114 ne2k_pio_ops[rdata->init.pio_index].list_length,
115 UDI_PIO_LITTLE_ENDIAN, 0, 0
120 // Next: Bind interrupt
121 udi_channel_spawn(ne2k_bus_dev_bind__intr_chanel, gcb, gcb->channel,
122 0, NE2K_OPS_IRQ, rdata);
124 void ne2k_bus_dev_bind__intr_chanel(udi_cb_t *gcb, udi_channel_t new_channel)
126 ne2k_rdata_t *rdata = gcb->context;
128 rdata->interrupt_channel = new_channel;
130 udi_cb_alloc(ne2k_bus_dev_bind__intr_attach, gcb, NE2K_CB_INTR, gcb->channel);
132 void ne2k_bus_dev_bind__intr_attach(udi_cb_t *gcb, udi_cb_t *new_cb)
134 ne2k_rdata_t *rdata = gcb->context;
135 udi_intr_attach_cb_t *intr_cb = UDI_MCB(new_cb, udi_intr_attach_cb_t);
136 intr_cb->interrupt_idx = 0;
137 intr_cb->min_event_pend = 2;
138 intr_cb->preprocessing_handle = rdata->pio_handles[NE2K_PIO_IRQACK];
139 udi_intr_attach_req(intr_cb);
140 // continued in ne2k_bus_dev_intr_attach_ack
142 void ne2k_bus_dev_bus_unbind_ack(udi_bus_bind_cb_t *cb)
145 void ne2k_bus_dev_intr_attach_ack(udi_intr_attach_cb_t *intr_attach_cb, udi_status_t status)
147 udi_cb_t *gcb = UDI_GCB(intr_attach_cb);
148 ne2k_rdata_t *rdata = gcb->context;
149 // continuing from ne2k_bus_dev_bind__intr_attach
150 if( status != UDI_OK ) {
152 udi_cb_free( UDI_GCB(intr_attach_cb) );
156 rdata->intr_attach_cb = intr_attach_cb;
158 rdata->init.n_intr_event_cb = 0;
159 udi_cb_alloc(ne2k_bus_dev_bind__intr_event_cb, gcb, NE2K_CB_INTR_EVENT, rdata->interrupt_channel);
162 void ne2k_bus_dev_bind__intr_event_cb(udi_cb_t *gcb, udi_cb_t *new_cb)
164 ne2k_rdata_t *rdata = gcb->context;
166 udi_intr_event_cb_t *intr_event_cb = UDI_MCB(new_cb, udi_intr_event_cb_t);
167 udi_intr_event_rdy(intr_event_cb);
168 rdata->init.n_intr_event_cb ++;
170 if( rdata->init.n_intr_event_cb < NE2K_NUM_INTR_EVENT_CBS )
172 udi_cb_alloc(ne2k_bus_dev_bind__intr_event_cb, gcb,
173 NE2K_CB_INTR_EVENT, rdata->interrupt_channel);
178 udi_pio_trans(ne2k_bus_dev_bind__card_reset, gcb,
179 rdata->pio_handles[NE2K_PIO_RESET], 0, NULL, &rdata->macaddr);
183 void ne2k_bus_dev_bind__card_reset(udi_cb_t *gcb, udi_buf_t *new_buf, udi_status_t status, udi_ubit16_t result)
185 ne2k_rdata_t *rdata = gcb->context;
187 udi_channel_event_complete( UDI_MCB(rdata->active_cb, udi_channel_event_cb_t), UDI_OK );
190 void ne2k_bus_dev_intr_detach_ack(udi_intr_detach_cb_t *intr_detach_cb)
194 void ne2k_nd_ctrl_channel_event_ind(udi_channel_event_cb_t *cb)
197 void ne2k_nd_ctrl_bind_req(udi_nic_bind_cb_t *cb, udi_index_t tx_chan_index, udi_index_t rx_chan_index)
199 udi_cb_t *gcb = UDI_GCB(cb);
200 ne2k_rdata_t *rdata = gcb->context;
201 rdata->init.rx_chan_index = rx_chan_index;
202 udi_channel_spawn(ne2k_nd_ctrl_bind__tx_chan_ok, gcb, gcb->channel, tx_chan_index, NE2K_OPS_TX, rdata);
205 void ne2k_nd_ctrl_bind__tx_chan_ok(udi_cb_t *gcb, udi_channel_t new_channel)
207 ne2k_rdata_t *rdata = gcb->context;
208 rdata->tx_channel = new_channel;
209 udi_channel_spawn(ne2k_nd_ctrl_bind__rx_chan_ok, gcb, gcb->channel,
210 rdata->init.rx_chan_index, NE2K_OPS_RX, rdata);
213 void ne2k_nd_ctrl_bind__rx_chan_ok(udi_cb_t *cb, udi_channel_t new_channel)
215 ne2k_rdata_t *rdata = cb->context;
216 rdata->rx_channel = new_channel;
217 udi_nsr_bind_ack( UDI_MCB(cb, udi_nic_bind_cb_t), UDI_OK );
220 void ne2k_nd_ctrl_unbind_req(udi_nic_cb_t *cb)
223 void ne2k_nd_ctrl_enable_req(udi_nic_cb_t *cb)
227 void ne2k_nd_ctrl_disable_req(udi_nic_cb_t *cb)
230 void ne2k_nd_ctrl_ctrl_req(udi_nic_ctrl_cb_t *cb)
233 void ne2k_nd_ctrl_info_req(udi_nic_info_cb_t *cb, udi_boolean_t reset_statistics)
237 void ne2k_bus_irq_channel_event_ind(udi_channel_event_cb_t *cb)
240 void ne2k_bus_irq_intr_event_ind(udi_intr_event_cb_t *cb, udi_ubit8_t flags)
242 if( cb->intr_result & 0x01 )
244 ne2k_intr__rx_ok( UDI_GCB(cb) );
247 udi_intr_event_rdy(cb);
250 // === Definition structures ===
251 udi_mgmt_ops_t ne2k_mgmt_ops = {
255 ne2k_final_cleanup_req
257 udi_ubit8_t ne2k_mgmt_op_flags[4] = {0,0,0,0};
258 udi_bus_device_ops_t ne2k_bus_dev_ops = {
259 ne2k_bus_dev_channel_event_ind,
260 ne2k_bus_dev_bus_bind_ack,
261 ne2k_bus_dev_bus_unbind_ack,
262 ne2k_bus_dev_intr_attach_ack,
263 ne2k_bus_dev_intr_detach_ack
265 udi_ubit8_t ne2k_bus_dev_ops_flags[5] = {0};
266 udi_nd_ctrl_ops_t ne2k_nd_ctrl_ops = {
267 ne2k_nd_ctrl_channel_event_ind,
268 ne2k_nd_ctrl_bind_req,
269 ne2k_nd_ctrl_unbind_req,
270 ne2k_nd_ctrl_enable_req,
271 ne2k_nd_ctrl_disable_req,
272 ne2k_nd_ctrl_ctrl_req,
273 ne2k_nd_ctrl_info_req
275 udi_ubit8_t ne2k_nd_ctrl_ops_flags[7] = {0};
276 udi_nd_tx_ops_t ne2k_nd_tx_ops = {
277 ne2k_nd_tx_channel_event_ind,
279 ne2k_nd_tx_exp_tx_req
281 udi_ubit8_t ne2k_nd_tx_ops_flags[3] = {0};
282 udi_nd_rx_ops_t ne2k_nd_rx_ops = {
283 ne2k_nd_rx_channel_event_ind,
286 udi_ubit8_t ne2k_nd_rx_ops_flags[2] = {0};
287 udi_intr_handler_ops_t ne2k_bus_irq_ops = {
288 ne2k_bus_irq_channel_event_ind,
289 ne2k_bus_irq_intr_event_ind
291 udi_ubit8_t ne2k_bus_irq_ops_flags[2] = {0};
293 udi_primary_init_t ne2k_pri_init = {
294 .mgmt_ops = &ne2k_mgmt_ops,
295 .mgmt_op_flags = ne2k_mgmt_op_flags,
296 .mgmt_scratch_requirement = 0,
297 .enumeration_attr_list_length = 4,
298 .rdata_size = sizeof(ne2k_rdata_t),
299 .child_data_size = 0,
300 .per_parent_paths = 0
302 udi_ops_init_t ne2k_ops_list[] = {
304 NE2K_OPS_DEV, NE2K_META_BUS, UDI_BUS_DEVICE_OPS_NUM,
306 (udi_ops_vector_t*)&ne2k_bus_dev_ops,
307 ne2k_bus_dev_ops_flags
310 NE2K_OPS_CTRL, NE2K_META_NIC, UDI_ND_CTRL_OPS_NUM,
312 (udi_ops_vector_t*)&ne2k_nd_ctrl_ops,
313 ne2k_nd_ctrl_ops_flags
316 NE2K_OPS_TX, NE2K_META_NIC, UDI_ND_TX_OPS_NUM,
318 (udi_ops_vector_t*)&ne2k_nd_tx_ops,
322 NE2K_OPS_RX, NE2K_META_NIC, UDI_ND_RX_OPS_NUM,
324 (udi_ops_vector_t*)&ne2k_nd_rx_ops,
328 NE2K_OPS_IRQ, NE2K_META_BUS, UDI_BUS_INTR_HANDLER_OPS_NUM,
330 (udi_ops_vector_t*)&ne2k_bus_irq_ops,
331 ne2k_bus_irq_ops_flags
335 const udi_init_t udi_init_info = {
336 .primary_init_info = &ne2k_pri_init,
337 .ops_init_list = ne2k_ops_list