From 9da18f07fef93afbb070146c55ed435b0355f276 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Mon, 30 Sep 2013 21:38:38 +0800 Subject: [PATCH] UDI/ne2000 - Working on a NE2k driver for UDI testing --- UDI/drivers/net_ne2000/ne2000_common.h | 62 ++++++++++ UDI/drivers/net_ne2000/ne2000_core.c | 164 +++++++++++++++++++++++++ UDI/drivers/net_ne2000/udiprops.txt | 39 ++++++ 3 files changed, 265 insertions(+) create mode 100644 UDI/drivers/net_ne2000/ne2000_common.h create mode 100644 UDI/drivers/net_ne2000/ne2000_core.c create mode 100644 UDI/drivers/net_ne2000/udiprops.txt diff --git a/UDI/drivers/net_ne2000/ne2000_common.h b/UDI/drivers/net_ne2000/ne2000_common.h new file mode 100644 index 00000000..bfbdeeb3 --- /dev/null +++ b/UDI/drivers/net_ne2000/ne2000_common.h @@ -0,0 +1,62 @@ +/* + * UDI Ne2000 NIC Driver + * By John Hodge (thePowersGang) + * + * ne2000_common.h + * - Shared definitions + */ +#ifndef _NE2000_COMMON_H_ +#define _NE2000_COMMON_H_ + +#include +#include + +// === MACROS === +/* Copied from http://projectudi.cvs.sourceforge.net/viewvc/projectudi/udiref/driver/udi_dpt/udi_dpt.h */ +#define DPT_SET_ATTR_BOOLEAN(attr, name, val) \ + udi_strcpy((attr)->attr_name, (name)); \ + (attr)->attr_type = UDI_ATTR_BOOLEAN; \ + (attr)->attr_length = sizeof(udi_boolean_t); \ + UDI_ATTR32_SET((attr)->attr_value, (val)) + +#define DPT_SET_ATTR32(attr, name, val) \ + udi_strcpy((attr)->attr_name, (name)); \ + (attr)->attr_type = UDI_ATTR_UBIT32; \ + (attr)->attr_length = sizeof(udi_ubit32_t); \ + UDI_ATTR32_SET((attr)->attr_value, (val)) + +#define DPT_SET_ATTR_ARRAY8(attr, name, val, len) \ + udi_strcpy((attr)->attr_name, (name)); \ + (attr)->attr_type = UDI_ATTR_ARRAY8; \ + (attr)->attr_length = (len); \ + udi_memcpy((attr)->attr_value, (val), (len)) + +#define DPT_SET_ATTR_STRING(attr, name, val, len) \ + udi_strcpy((attr)->attr_name, (name)); \ + (attr)->attr_type = UDI_ATTR_STRING; \ + (attr)->attr_length = (len); \ + udi_strncpy_rtrim((char *)(attr)->attr_value, (val), (len)) + +extern udi_channel_event_ind_op_t ne2k_bus_dev_channel_event_ind; +extern udi_bus_bind_ack_op_t ne2k_bus_dev_bus_bind_ack; +extern udi_bus_unbind_ack_op_t ne2k_bus_dev_bus_unbind_ack; +extern udi_intr_attach_ack_op_t ne2k_bus_dev_intr_attach_ack; +extern udi_intr_detach_ack_op_t ne2k_bus_dev_intr_detach_ack; + +extern udi_channel_event_ind_op_t ne2k_nd_ctrl_channel_event_ind; +extern udi_nd_bind_req_op_t ne2k_nd_ctrl_bind_req; +extern udi_nd_unbind_req_op_t ne2k_nd_ctrl_unbind_req; +extern udi_nd_enable_req_op_t ne2k_nd_ctrl_enable_req; +extern udi_nd_disable_req_op_t ne2k_nd_ctrl_disable_req; +extern udi_nd_ctrl_req_op_t ne2k_nd_ctrl_ctrl_req; +extern udi_nd_info_req_op_t ne2k_nd_ctrl_info_req; + +extern udi_channel_event_ind_op_t ne2k_nd_tx_channel_event_ind; +extern udi_nd_tx_req_op_t ne2k_nd_tx_tx_req; +extern udi_nd_exp_tx_req_op_t ne2k_nd_tx_exp_tx_req; + +extern udi_channel_event_ind_op_t ne2k_nd_rx_channel_event_ind; +extern udi_nd_rx_rdy_op_t ne2k_nd_rx_rx_rdy; + +#endif + diff --git a/UDI/drivers/net_ne2000/ne2000_core.c b/UDI/drivers/net_ne2000/ne2000_core.c new file mode 100644 index 00000000..3ee8dba0 --- /dev/null +++ b/UDI/drivers/net_ne2000/ne2000_core.c @@ -0,0 +1,164 @@ +/* + * UDI Ne2000 NIC Driver + * By John Hodge (thePowersGang) + * + * ne2000_core.c + * - UDI initialisation + */ +#include +#include +#include "ne2000_common.h" + +#define NE2K_META_BUS 1 +#define NE2K_META_NIC 2 + +// === CODE === +// --- Management +void ne2k_usage_ind(udi_usage_cb_t *cb, udi_ubit8_t resource_level) +{ +} +void ne2k_enumerate_req(udi_enumerate_cb_t *cb, udi_ubit8_t enumeration_level) +{ + udi_instance_attr_list_t *attr_list = cb->attr_list; + + switch(enumeration_level) + { + case UDI_ENUMERATE_START: + case UDI_ENUMERATE_START_RESCAN: + // TODO: Emit the ND binding + DPT_SET_ATTR32(attr_list, "if_num", 0); + attr_list ++; + DPT_SET_ATTR_STRING(attr_list, "if_media", "eth"); + attr_list ++; + //DPT_SET_ATTR_STRING(attr_list, "identifier", hexaddr); + //attr_list ++; + udi_enumerate_ack(cb, UDI_ENUMERATE_OK, 2); + break + case UDI_ENUMERATE_NEXT: + udi_enumerate_ack(cb, UDI_ENUMERATE_DONE, 0); + break; + } +} +void ne2k_devmgmt_req(udi_mgmt_cb_t *cb, udi_ubit8_t mgmt_op, udi_ubit8_t parent_ID) +{ +} +void ne2k_final_cleanup_req(udi_mgmt_cb_t *cb) +{ +} +// --- Bus +void ne2k_bus_dev_channel_event_ind(udi_channel_event_cb_t *cb) +{ +} +void ne2k_bus_dev_bus_bind_ack(udi_bus_bind_cb_t *cb, + udi_dma_constraints_t dma_constraints, udi_ubit8_t perferred_endianness, udi_status_t status) +{ +} +void ne2k_bus_dev_bus_unbind_ack(udi_bus_bind_cb_t *cb) +{ +} +void ne2k_bus_dev_intr_attach_ack(udi_intr_attach_cb_t *intr_attach_cb, udi_status_t status) +{ +} +void ne2k_bus_dev_intr_detach_ack(udi_intr_detach_cb_t *intr_detach_cb) +{ +} +// --- ND Common +void ne2k_nd_ctrl_channel_event_ind(udi_channel_event_cb_t *cb) +{ +} +void ne2k_nd_ctrl_bind_req(udi_nic_bind_cb_t *cb, udi_index_t tx_chan_index, udi_index_t rx_chan_index) +{ +} +void ne2k_nd_ctrl_unbind_req(udi_nic_cb_t *cb) +{ +} +void ne2k_nd_ctrl_enable_req(udi_nic_cb_t *cb) +{ +} +void ne2k_nd_ctrl_disable_req(udi_nic_cb_t *cb) +{ +} +void ne2k_nd_ctrl_ctrl_req(udi_nic_ctrl_cb_t *cb) +{ +} +void ne2k_nd_ctrl_info_req(udi_nic_info_cb_t *cb, udi_boolean_t reset_statistics) +{ +} + +// === Definition structures === +udi_mgmt_ops_t ne2k_mgmt_ops = { + ne2k_usage_ind, + ne2k_enumerate_req, + ne2k_devmgmt_req, + ne2k_final_cleanup_req +}; +udi_ubit8_t ne2k_mgmt_op_flags[4] = {0,0,0,0}; +udi_bus_device_ops_t ne2k_bus_dev_ops = { + ne2k_bus_dev_channel_event_ind, + ne2k_bus_dev_bus_bind_ack, + ne2k_bus_dev_bus_unbind_ack, + ne2k_bus_dev_intr_attach_ack, + ne2k_bus_dev_intr_detach_ack +}; +udi_ubit8_t ne2k_bus_dev_ops_flags[5] = {0}; +udi_nd_ctrl_ops_t ne2k_nd_ctrl_ops = { + ne2k_nd_ctrl_channel_event_ind, + ne2k_nd_ctrl_bind_req, + ne2k_nd_ctrl_unbind_req, + ne2k_nd_ctrl_enable_req, + ne2k_nd_ctrl_disable_req, + ne2k_nd_ctrl_ctrl_req, + ne2k_nd_ctrl_info_req +}; +udi_ubit8_t ne2k_nd_ctrl_ops_flags[7] = {0}; +udi_nd_tx_ops ne2k_nd_tx_ops = { + ne2k_nd_tx_channel_event_ind, + ne2k_nd_tx_tx_req, + ne2k_nd_tx_exp_tx_req +}; +udi_ubit8_t ne2k_nd_tx_ops_flags[3] = {0}; +udi_nd_rx_ops ne2k_nd_rx_ops = { + ne2k_nd_rx_channel_event_ind, + ne2k_nd_rx_rx_rdy +}; +udi_ubit8_t ne2k_nd_rx_ops_flags[2] = {0}; +const udi_primary_init_t ne2k_pri_init = { + .mgmt_ops = &ne2k_mgmt_ops, + .mgmt_op_flags = ne2k_mgmt_op_flags, + .mgmt_scratch_requirement = 0, + .enumeration_attr_list_length = 4, + .rdata_size = sizeof(ne2k_rdata_t), + .child_data_size = 0, + .per_parent_paths = 0 +}; +const udi_ops_init_t ne2k_ops_list[] = { + { + 1, NE2K_META_BUS, UDI_BUS_DEVICE_OPS_NUM, + 0, + (udi_ops_vector_t*)ne2k_bus_dev_ops, + ne2k_bus_dev_ops_flags + }, + { + 2, NE2K_META_NIC, UDI_ND_CTRL_OPS_NUM, + 0, + (udi_ops_vector_t*)ne2k_nd_ctrl_ops, + ne2k_nd_ctrl_ops_flags + }, + { + 3, NE2K_META_NIC, UDI_ND_TX_OPS_NUM, + 0, + (udi_ops_vector_t*)ne2k_nd_tx_ops, + ne2k_nd_tx_ops_flags + }, + { + 4, NE2K_META_NIC, UDI_ND_RX_OPS_NUM, + 0, + (udi_ops_vector_t*)ne2k_nd_rx_ops, + ne2k_nd_rx_ops_flags + }, + {0} +} +const udi_init_t udi_init_info = { + .primary_init_info = &ne2k_pri_init, + .ops_init_list = ne2k_ops_list +}; diff --git a/UDI/drivers/net_ne2000/udiprops.txt b/UDI/drivers/net_ne2000/udiprops.txt new file mode 100644 index 00000000..e6edadad --- /dev/null +++ b/UDI/drivers/net_ne2000/udiprops.txt @@ -0,0 +1,39 @@ +properties_version 0x101 +supplier 1 +contact 2 +name 3 +shortname ne2000 +release 5 1.0 + +requires udi 0x101 +requires udi_physio 0x101 +requires udi_bridge 0x101 +requires udi_nic 0x101 + +meta 1 udi_bridge +meta 2 udi_nic + +parent_bind_ops 1 0 1 0 +child_bind_ops 2 0 1 # Ctrl (TX and RX are set up via this) + +# Realtek 8029 +device 101 1 bus_type string pci pci_vendor_id ubit32 10ec pci_device_id ubit 8029 +# Realtek 8129 +device 102 1 bus_type string pci pci_vendor_id ubit32 10ec pci_device_id ubit 8129 + +#custom %media_type driver 0 0 + +# Messages +message 1 John Hodge (thePowersGang) +message 2 udi@mutabah.net +message 3 NE2000 LAN Driver +message 5 Ne2k +message 101 Realtek 8029 +message 102 Realtek 8129 + +module ne2000 +region 0 + +# Source-only udiprops +source_files ne2000_core.c ne2000_rx.c ne2000_tx.c +compile_options -- 2.20.1