37
/** Network device named settings */
38
/** Network device predefined settings */
38
39
struct setting mac_setting __setting ( SETTING_NETDEV ) = {
40
41
.description = "MAC address",
41
42
.type = &setting_type_hex,
44
struct setting bustype_setting __setting ( SETTING_NETDEV ) = {
46
.description = "Bus type",
47
.type = &setting_type_string,
49
struct setting busloc_setting __setting ( SETTING_NETDEV ) = {
51
.description = "Bus location",
52
.type = &setting_type_uint32,
43
54
struct setting busid_setting __setting ( SETTING_NETDEV ) = {
45
56
.description = "Bus ID",
108
* Fetch bus type setting
110
* @v netdev Network device
111
* @v data Buffer to fill with setting data
112
* @v len Length of buffer
113
* @ret len Length of setting data, or negative error
115
static int netdev_fetch_bustype ( struct net_device *netdev, void *data,
117
static const char *bustypes[] = {
118
[BUS_TYPE_PCI] = "PCI",
119
[BUS_TYPE_ISAPNP] = "ISAPNP",
120
[BUS_TYPE_EISA] = "EISA",
121
[BUS_TYPE_MCA] = "MCA",
122
[BUS_TYPE_ISA] = "ISA",
123
[BUS_TYPE_TAP] = "TAP",
125
struct device_description *desc = &netdev->dev->desc;
128
assert ( desc->bus_type < ( sizeof ( bustypes ) /
129
sizeof ( bustypes[0] ) ) );
130
bustype = bustypes[desc->bus_type];
131
assert ( bustype != NULL );
132
strncpy ( data, bustype, len );
133
return strlen ( bustype );
137
* Fetch bus location setting
139
* @v netdev Network device
140
* @v data Buffer to fill with setting data
141
* @v len Length of buffer
142
* @ret len Length of setting data, or negative error
144
static int netdev_fetch_busloc ( struct net_device *netdev, void *data,
146
struct device_description *desc = &netdev->dev->desc;
149
busloc = cpu_to_be32 ( desc->location );
150
if ( len > sizeof ( busloc ) )
151
len = sizeof ( busloc );
152
memcpy ( data, &busloc, len );
153
return sizeof ( busloc );
97
157
* Fetch bus ID setting
99
159
* @v netdev Network device
157
217
/** Network device settings */
158
218
static struct netdev_setting_operation netdev_setting_operations[] = {
159
219
{ &mac_setting, netdev_store_mac, netdev_fetch_mac },
220
{ &bustype_setting, NULL, netdev_fetch_bustype },
221
{ &busloc_setting, NULL, netdev_fetch_busloc },
160
222
{ &busid_setting, NULL, netdev_fetch_busid },
161
223
{ &chip_setting, NULL, netdev_fetch_chip },
235
297
.fetch = netdev_fetch,
236
298
.clear = netdev_clear,
302
* Redirect "netX" settings block
304
* @v settings Settings block
305
* @ret settings Underlying settings block
307
static struct settings * netdev_redirect ( struct settings *settings ) {
308
struct net_device *netdev;
310
/* Redirect to most recently opened network device */
311
netdev = last_opened_netdev();
313
return netdev_settings ( netdev );
319
/** "netX" settings operations */
320
static struct settings_operations netdev_redirect_settings_operations = {
321
.redirect = netdev_redirect,
324
/** "netX" settings */
325
static struct settings netdev_redirect_settings = {
327
.siblings = LIST_HEAD_INIT ( netdev_redirect_settings.siblings ),
328
.children = LIST_HEAD_INIT ( netdev_redirect_settings.children ),
329
.op = &netdev_redirect_settings_operations,
332
/** Initialise "netX" settings */
333
static void netdev_redirect_settings_init ( void ) {
336
if ( ( rc = register_settings ( &netdev_redirect_settings, NULL,
338
DBG ( "Could not register netX settings: %s\n",
344
/** "netX" settings initialiser */
345
struct init_fn netdev_redirect_settings_init_fn __init_fn ( INIT_LATE ) = {
346
.initialise = netdev_redirect_settings_init,