Skip to content

Commit

Permalink
[netdevice] Add "bustype" and "busloc" settings
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Jul 12, 2013
1 parent 9f3bbac commit c0cff94
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/net/netdev_settings.c
Expand Up @@ -40,6 +40,16 @@ struct setting mac_setting __setting ( SETTING_NETDEV ) = {
.description = "MAC address",
.type = &setting_type_hex,
};
struct setting bustype_setting __setting ( SETTING_NETDEV ) = {
.name = "bustype",
.description = "Bus type",
.type = &setting_type_string,
};
struct setting busloc_setting __setting ( SETTING_NETDEV ) = {
.name = "busloc",
.description = "Bus location",
.type = &setting_type_uint32,
};
struct setting busid_setting __setting ( SETTING_NETDEV ) = {
.name = "busid",
.description = "Bus ID",
Expand Down Expand Up @@ -93,6 +103,54 @@ static int netdev_fetch_mac ( struct net_device *netdev, void *data,
return netdev->ll_protocol->ll_addr_len;
}

/**
* Fetch bus type setting
*
* @v netdev Network device
* @v data Buffer to fill with setting data
* @v len Length of buffer
* @ret len Length of setting data, or negative error
*/
static int netdev_fetch_bustype ( struct net_device *netdev, void *data,
size_t len ) {
static const char *bustypes[] = {
[BUS_TYPE_PCI] = "PCI",
[BUS_TYPE_ISAPNP] = "ISAPNP",
[BUS_TYPE_EISA] = "EISA",
[BUS_TYPE_MCA] = "MCA",
[BUS_TYPE_ISA] = "ISA",
};
struct device_description *desc = &netdev->dev->desc;
const char *bustype;

assert ( desc->bus_type < ( sizeof ( bustypes ) /
sizeof ( bustypes[0] ) ) );
bustype = bustypes[desc->bus_type];
assert ( bustypes != NULL );
strncpy ( data, bustype, len );
return strlen ( bustype );
}

/**
* Fetch bus location setting
*
* @v netdev Network device
* @v data Buffer to fill with setting data
* @v len Length of buffer
* @ret len Length of setting data, or negative error
*/
static int netdev_fetch_busloc ( struct net_device *netdev, void *data,
size_t len ) {
struct device_description *desc = &netdev->dev->desc;
uint32_t busloc;

busloc = cpu_to_be32 ( desc->location );
if ( len > sizeof ( busloc ) )
len = sizeof ( busloc );
memcpy ( data, &busloc, len );
return sizeof ( busloc );
}

/**
* Fetch bus ID setting
*
Expand Down Expand Up @@ -157,6 +215,8 @@ struct netdev_setting_operation {
/** Network device settings */
static struct netdev_setting_operation netdev_setting_operations[] = {
{ &mac_setting, netdev_store_mac, netdev_fetch_mac },
{ &bustype_setting, NULL, netdev_fetch_bustype },
{ &busloc_setting, NULL, netdev_fetch_busloc },
{ &busid_setting, NULL, netdev_fetch_busid },
{ &chip_setting, NULL, netdev_fetch_chip },
};
Expand Down

0 comments on commit c0cff94

Please sign in to comment.