Browse Source

[netdevice] Add "bustype" and "busloc" settings

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
c0cff94320
1 changed files with 60 additions and 0 deletions
  1. 60
    0
      src/net/netdev_settings.c

+ 60
- 0
src/net/netdev_settings.c View File

@@ -40,6 +40,16 @@ struct setting mac_setting __setting ( SETTING_NETDEV ) = {
40 40
 	.description = "MAC address",
41 41
 	.type = &setting_type_hex,
42 42
 };
43
+struct setting bustype_setting __setting ( SETTING_NETDEV ) = {
44
+	.name = "bustype",
45
+	.description = "Bus type",
46
+	.type = &setting_type_string,
47
+};
48
+struct setting busloc_setting __setting ( SETTING_NETDEV ) = {
49
+	.name = "busloc",
50
+	.description = "Bus location",
51
+	.type = &setting_type_uint32,
52
+};
43 53
 struct setting busid_setting __setting ( SETTING_NETDEV ) = {
44 54
 	.name = "busid",
45 55
 	.description = "Bus ID",
@@ -93,6 +103,54 @@ static int netdev_fetch_mac ( struct net_device *netdev, void *data,
93 103
 	return netdev->ll_protocol->ll_addr_len;
94 104
 }
95 105
 
106
+/**
107
+ * Fetch bus type setting
108
+ *
109
+ * @v netdev		Network device
110
+ * @v data		Buffer to fill with setting data
111
+ * @v len		Length of buffer
112
+ * @ret len		Length of setting data, or negative error
113
+ */
114
+static int netdev_fetch_bustype ( struct net_device *netdev, void *data,
115
+				  size_t len ) {
116
+	static const char *bustypes[] = {
117
+		[BUS_TYPE_PCI] = "PCI",
118
+		[BUS_TYPE_ISAPNP] = "ISAPNP",
119
+		[BUS_TYPE_EISA] = "EISA",
120
+		[BUS_TYPE_MCA] = "MCA",
121
+		[BUS_TYPE_ISA] = "ISA",
122
+	};
123
+	struct device_description *desc = &netdev->dev->desc;
124
+	const char *bustype;
125
+
126
+	assert ( desc->bus_type < ( sizeof ( bustypes ) /
127
+				    sizeof ( bustypes[0] ) ) );
128
+	bustype = bustypes[desc->bus_type];
129
+	assert ( bustypes != NULL );
130
+	strncpy ( data, bustype, len );
131
+	return strlen ( bustype );
132
+}
133
+
134
+/**
135
+ * Fetch bus location setting
136
+ *
137
+ * @v netdev		Network device
138
+ * @v data		Buffer to fill with setting data
139
+ * @v len		Length of buffer
140
+ * @ret len		Length of setting data, or negative error
141
+ */
142
+static int netdev_fetch_busloc ( struct net_device *netdev, void *data,
143
+				 size_t len ) {
144
+	struct device_description *desc = &netdev->dev->desc;
145
+	uint32_t busloc;
146
+
147
+	busloc = cpu_to_be32 ( desc->location );
148
+	if ( len > sizeof ( busloc ) )
149
+		len = sizeof ( busloc );
150
+	memcpy ( data, &busloc, len );
151
+	return sizeof ( busloc );
152
+}
153
+
96 154
 /**
97 155
  * Fetch bus ID setting
98 156
  *
@@ -157,6 +215,8 @@ struct netdev_setting_operation {
157 215
 /** Network device settings */
158 216
 static struct netdev_setting_operation netdev_setting_operations[] = {
159 217
 	{ &mac_setting, netdev_store_mac, netdev_fetch_mac },
218
+	{ &bustype_setting, NULL, netdev_fetch_bustype },
219
+	{ &busloc_setting, NULL, netdev_fetch_busloc },
160 220
 	{ &busid_setting, NULL, netdev_fetch_busid },
161 221
 	{ &chip_setting, NULL, netdev_fetch_chip },
162 222
 };

Loading…
Cancel
Save