]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[netdevice] Add "bustype" and "busloc" settings
authorMichael Brown <mcb30@ipxe.org>
Fri, 12 Jul 2013 20:25:35 +0000 (22:25 +0200)
committerMichael Brown <mcb30@ipxe.org>
Fri, 12 Jul 2013 20:38:19 +0000 (22:38 +0200)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/net/netdev_settings.c

index 028a62ca8f38531abd84d9b6120a8a7f99ba325d..3ea7ace50419f40aa4d8c3b56232d8ad5e850b50 100644 (file)
@@ -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",
@@ -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
  *
@@ -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 },
 };