| 1 |
/* |
| 2 |
* Cisco router simulation platform. |
| 3 |
* Copyright (c) 2005,2006 Christophe Fillot ([email protected]) |
| 4 |
* |
| 5 |
* Ethernet Port Adapters. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include <stdio.h> |
| 9 |
#include <stdlib.h> |
| 10 |
#include <string.h> |
| 11 |
#include <stdarg.h> |
| 12 |
#include <unistd.h> |
| 13 |
#include <time.h> |
| 14 |
#include <errno.h> |
| 15 |
#include <assert.h> |
| 16 |
|
| 17 |
#include "utils.h" |
| 18 |
#include "net.h" |
| 19 |
#include "net_io.h" |
| 20 |
#include "ptask.h" |
| 21 |
#include "dev_am79c971.h" |
| 22 |
#include "dev_dec21140.h" |
| 23 |
#include "dev_i8254x.h" |
| 24 |
#include "dev_mv64460.h" |
| 25 |
#include "dev_c7200.h" |
| 26 |
|
| 27 |
/* ====================================================================== */ |
| 28 |
/* C7200-IO-FE EEPROM */ |
| 29 |
/* ====================================================================== */ |
| 30 |
|
| 31 |
/* C7200-IO-FE: C7200 IOCard with one FastEthernet port EEPROM */ |
| 32 |
static const m_uint16_t eeprom_c7200_io_fe_data[] = { |
| 33 |
0x0183, 0x010E, 0xffff, 0xffff, 0x490B, 0x8C02, 0x0000, 0x0000, |
| 34 |
0x5000, 0x0000, 0x9812, 0x2800, 0x00FF, 0xFFFF, 0xFFFF, 0xFFFF, |
| 35 |
}; |
| 36 |
|
| 37 |
static const struct cisco_eeprom eeprom_c7200_io_fe = { |
| 38 |
"C7200-IO-FE", (m_uint16_t *)eeprom_c7200_io_fe_data, |
| 39 |
sizeof(eeprom_c7200_io_fe_data)/2, |
| 40 |
}; |
| 41 |
|
| 42 |
/* |
| 43 |
* dev_c7200_iocard_init() |
| 44 |
* |
| 45 |
* Add an IOcard into slot 0. |
| 46 |
*/ |
| 47 |
static int dev_c7200_iocard_init(vm_instance_t *vm,struct cisco_card *card) |
| 48 |
{ |
| 49 |
struct dec21140_data *data; |
| 50 |
u_int slot = card->slot_id; |
| 51 |
|
| 52 |
if (slot != 0) { |
| 53 |
vm_error(vm,"cannot put IOCARD in PA bay %u!\n",slot); |
| 54 |
return(-1); |
| 55 |
} |
| 56 |
|
| 57 |
/* Set the PCI bus */ |
| 58 |
card->pci_bus = vm->slots_pci_bus[slot]; |
| 59 |
|
| 60 |
/* Set the EEPROM */ |
| 61 |
cisco_card_set_eeprom(vm,card,&eeprom_c7200_io_fe); |
| 62 |
c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom); |
| 63 |
|
| 64 |
/* Create the DEC21140 chip */ |
| 65 |
data = dev_dec21140_init(vm,card->dev_name, |
| 66 |
card->pci_bus, |
| 67 |
VM_C7200(vm)->npe_driver->dec21140_pci_dev, |
| 68 |
c7200_net_irq_for_slot_port(slot,0)); |
| 69 |
if (!data) return(-1); |
| 70 |
|
| 71 |
/* Store device info into the router structure */ |
| 72 |
card->drv_info = data; |
| 73 |
return(0); |
| 74 |
} |
| 75 |
|
| 76 |
/* Remove an IOcard from slot 0 */ |
| 77 |
static int dev_c7200_iocard_shutdown(vm_instance_t *vm,struct cisco_card *card) |
| 78 |
{ |
| 79 |
/* Remove the PA EEPROM */ |
| 80 |
cisco_card_unset_eeprom(card); |
| 81 |
c7200_set_slot_eeprom(VM_C7200(vm),card->slot_id,NULL); |
| 82 |
|
| 83 |
/* Shutdown the DEC21140 */ |
| 84 |
dev_dec21140_remove(card->drv_info); |
| 85 |
return(0); |
| 86 |
} |
| 87 |
|
| 88 |
/* Bind a Network IO descriptor */ |
| 89 |
static int dev_c7200_iocard_set_nio(vm_instance_t *vm,struct cisco_card *card, |
| 90 |
u_int port_id,netio_desc_t *nio) |
| 91 |
{ |
| 92 |
struct dec21140_data *d = card->drv_info; |
| 93 |
|
| 94 |
if (!d || (port_id > 0)) |
| 95 |
return(-1); |
| 96 |
|
| 97 |
return(dev_dec21140_set_nio(d,nio)); |
| 98 |
} |
| 99 |
|
| 100 |
/* Unbind a Network IO descriptor */ |
| 101 |
static int dev_c7200_iocard_unset_nio(vm_instance_t *vm, |
| 102 |
struct cisco_card *card, |
| 103 |
u_int port_id) |
| 104 |
{ |
| 105 |
struct dec21140_data *d = card->drv_info; |
| 106 |
|
| 107 |
if (!d || (port_id > 0)) |
| 108 |
return(-1); |
| 109 |
|
| 110 |
dev_dec21140_unset_nio(d); |
| 111 |
return(0); |
| 112 |
} |
| 113 |
|
| 114 |
/* |
| 115 |
* dev_c7200_pa_fe_tx_init() |
| 116 |
* |
| 117 |
* Add a PA-FE-TX port adapter into specified slot. |
| 118 |
*/ |
| 119 |
static int dev_c7200_pa_fe_tx_init(vm_instance_t *vm,struct cisco_card *card) |
| 120 |
{ |
| 121 |
struct dec21140_data *data; |
| 122 |
u_int slot = card->slot_id; |
| 123 |
|
| 124 |
/* Set the PCI bus */ |
| 125 |
card->pci_bus = vm->slots_pci_bus[slot]; |
| 126 |
|
| 127 |
/* Set the EEPROM */ |
| 128 |
cisco_card_set_eeprom(vm,card,cisco_eeprom_find_pa("PA-FE-TX")); |
| 129 |
c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom); |
| 130 |
|
| 131 |
/* Create the DEC21140 chip */ |
| 132 |
data = dev_dec21140_init(vm,card->dev_name,card->pci_bus,0, |
| 133 |
c7200_net_irq_for_slot_port(slot,0)); |
| 134 |
if (!data) return(-1); |
| 135 |
|
| 136 |
/* Store device info into the router structure */ |
| 137 |
card->drv_info = data; |
| 138 |
return(0); |
| 139 |
} |
| 140 |
|
| 141 |
/* Remove a PA-FE-TX from the specified slot */ |
| 142 |
static int |
| 143 |
dev_c7200_pa_fe_tx_shutdown(vm_instance_t *vm,struct cisco_card *card) |
| 144 |
{ |
| 145 |
/* Remove the PA EEPROM */ |
| 146 |
cisco_card_unset_eeprom(card); |
| 147 |
c7200_set_slot_eeprom(VM_C7200(vm),card->slot_id,NULL); |
| 148 |
|
| 149 |
/* Shutdown the DEC21140 */ |
| 150 |
dev_dec21140_remove(card->drv_info); |
| 151 |
return(0); |
| 152 |
} |
| 153 |
|
| 154 |
/* Bind a Network IO descriptor */ |
| 155 |
static int |
| 156 |
dev_c7200_pa_fe_tx_set_nio(vm_instance_t *vm,struct cisco_card *card, |
| 157 |
u_int port_id,netio_desc_t *nio) |
| 158 |
{ |
| 159 |
struct dec21140_data *d = card->drv_info; |
| 160 |
|
| 161 |
if (!d || (port_id > 0)) |
| 162 |
return(-1); |
| 163 |
|
| 164 |
return(dev_dec21140_set_nio(d,nio)); |
| 165 |
} |
| 166 |
|
| 167 |
/* Unbind a Network IO descriptor */ |
| 168 |
static int |
| 169 |
dev_c7200_pa_fe_tx_unset_nio(vm_instance_t *vm,struct cisco_card *card, |
| 170 |
u_int port_id) |
| 171 |
{ |
| 172 |
struct dec21140_data *d = card->drv_info; |
| 173 |
|
| 174 |
if (!d || (port_id > 0)) |
| 175 |
return(-1); |
| 176 |
|
| 177 |
dev_dec21140_unset_nio(d); |
| 178 |
return(0); |
| 179 |
} |
| 180 |
|
| 181 |
/* C7200-IO-FE driver */ |
| 182 |
struct cisco_card_driver dev_c7200_iocard_fe_driver = { |
| 183 |
"C7200-IO-FE", 1, 0, |
| 184 |
dev_c7200_iocard_init, |
| 185 |
dev_c7200_iocard_shutdown, |
| 186 |
NULL, |
| 187 |
dev_c7200_iocard_set_nio, |
| 188 |
dev_c7200_iocard_unset_nio, |
| 189 |
NULL, |
| 190 |
}; |
| 191 |
|
| 192 |
/* PA-FE-TX driver */ |
| 193 |
struct cisco_card_driver dev_c7200_pa_fe_tx_driver = { |
| 194 |
"PA-FE-TX", 1, 0, |
| 195 |
dev_c7200_pa_fe_tx_init, |
| 196 |
dev_c7200_pa_fe_tx_shutdown, |
| 197 |
NULL, |
| 198 |
dev_c7200_pa_fe_tx_set_nio, |
| 199 |
dev_c7200_pa_fe_tx_unset_nio, |
| 200 |
NULL, |
| 201 |
}; |
| 202 |
|
| 203 |
/* ====================================================================== */ |
| 204 |
/* PA based on Intel i8254x chips */ |
| 205 |
/* ====================================================================== */ |
| 206 |
|
| 207 |
struct pa_i8254x_data { |
| 208 |
u_int nr_port; |
| 209 |
struct i8254x_data *port[2]; |
| 210 |
}; |
| 211 |
|
| 212 |
/* Remove a PA-2FE-TX from the specified slot */ |
| 213 |
static int |
| 214 |
dev_c7200_pa_i8254x_shutdown(vm_instance_t *vm,struct cisco_card *card) |
| 215 |
{ |
| 216 |
struct pa_i8254x_data *data = card->drv_info; |
| 217 |
int i; |
| 218 |
|
| 219 |
/* Remove the PA EEPROM */ |
| 220 |
cisco_card_unset_eeprom(card); |
| 221 |
c7200_set_slot_eeprom(VM_C7200(vm),card->slot_id,NULL); |
| 222 |
|
| 223 |
/* Remove the Intel i2854x chips */ |
| 224 |
for(i=0;i<data->nr_port;i++) |
| 225 |
dev_i8254x_remove(data->port[i]); |
| 226 |
|
| 227 |
free(data); |
| 228 |
return(0); |
| 229 |
} |
| 230 |
|
| 231 |
/* Bind a Network IO descriptor */ |
| 232 |
static int |
| 233 |
dev_c7200_pa_i8254x_set_nio(vm_instance_t *vm,struct cisco_card *card, |
| 234 |
u_int port_id,netio_desc_t *nio) |
| 235 |
{ |
| 236 |
struct pa_i8254x_data *d = card->drv_info; |
| 237 |
|
| 238 |
if (!d || (port_id >= d->nr_port)) |
| 239 |
return(-1); |
| 240 |
|
| 241 |
dev_i8254x_set_nio(d->port[port_id],nio); |
| 242 |
return(0); |
| 243 |
} |
| 244 |
|
| 245 |
/* Unbind a Network IO descriptor */ |
| 246 |
static int |
| 247 |
dev_c7200_pa_i8254x_unset_nio(vm_instance_t *vm,struct cisco_card *card, |
| 248 |
u_int port_id) |
| 249 |
{ |
| 250 |
struct pa_i8254x_data *d = card->drv_info; |
| 251 |
|
| 252 |
if (!d || (port_id >= d->nr_port)) |
| 253 |
return(-1); |
| 254 |
|
| 255 |
dev_i8254x_unset_nio(d->port[port_id]); |
| 256 |
return(0); |
| 257 |
} |
| 258 |
|
| 259 |
/* ====================================================================== */ |
| 260 |
/* PA-2FE-TX */ |
| 261 |
/* ====================================================================== */ |
| 262 |
|
| 263 |
/* |
| 264 |
* dev_c7200_pa_2fe_tx_init() |
| 265 |
* |
| 266 |
* Add a PA-2FE-TX port adapter into specified slot. |
| 267 |
*/ |
| 268 |
static int dev_c7200_pa_2fe_tx_init(vm_instance_t *vm,struct cisco_card *card) |
| 269 |
{ |
| 270 |
struct pa_i8254x_data *data; |
| 271 |
u_int slot = card->slot_id; |
| 272 |
int i; |
| 273 |
|
| 274 |
/* Allocate the private data structure for the PA-2FE-TX */ |
| 275 |
if (!(data = malloc(sizeof(*data)))) { |
| 276 |
vm_error(vm,"%s: out of memory\n",card->dev_name); |
| 277 |
return(-1); |
| 278 |
} |
| 279 |
|
| 280 |
/* 2 Ethernet ports */ |
| 281 |
memset(data,0,sizeof(*data)); |
| 282 |
data->nr_port = 2; |
| 283 |
|
| 284 |
/* Set the PCI bus */ |
| 285 |
card->pci_bus = vm->slots_pci_bus[slot]; |
| 286 |
|
| 287 |
/* Set the EEPROM */ |
| 288 |
cisco_card_set_eeprom(vm,card,cisco_eeprom_find_pa("PA-2FE-TX")); |
| 289 |
c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom); |
| 290 |
|
| 291 |
/* Create the Intel i8254x chips */ |
| 292 |
for(i=0;i<data->nr_port;i++) { |
| 293 |
data->port[i] = dev_i8254x_init(vm,card->dev_name,0, |
| 294 |
card->pci_bus,i, |
| 295 |
c7200_net_irq_for_slot_port(slot,i)); |
| 296 |
} |
| 297 |
|
| 298 |
/* Store device info into the router structure */ |
| 299 |
card->drv_info = data; |
| 300 |
return(0); |
| 301 |
} |
| 302 |
|
| 303 |
/* PA-2FE-TX driver */ |
| 304 |
struct cisco_card_driver dev_c7200_pa_2fe_tx_driver = { |
| 305 |
"PA-2FE-TX", 0, 0, |
| 306 |
dev_c7200_pa_2fe_tx_init, |
| 307 |
dev_c7200_pa_i8254x_shutdown, |
| 308 |
NULL, |
| 309 |
dev_c7200_pa_i8254x_set_nio, |
| 310 |
dev_c7200_pa_i8254x_unset_nio, |
| 311 |
NULL, |
| 312 |
}; |
| 313 |
|
| 314 |
/* ====================================================================== */ |
| 315 |
/* PA-GE */ |
| 316 |
/* ====================================================================== */ |
| 317 |
|
| 318 |
/* |
| 319 |
* dev_c7200_pa_ge_init() |
| 320 |
* |
| 321 |
* Add a PA-GE port adapter into specified slot. |
| 322 |
*/ |
| 323 |
static int dev_c7200_pa_ge_init(vm_instance_t *vm,struct cisco_card *card) |
| 324 |
{ |
| 325 |
struct pa_i8254x_data *data; |
| 326 |
u_int slot = card->slot_id; |
| 327 |
|
| 328 |
/* Allocate the private data structure for the PA-2FE-TX */ |
| 329 |
if (!(data = malloc(sizeof(*data)))) { |
| 330 |
vm_error(vm,"%s: out of memory\n",card->dev_name); |
| 331 |
return(-1); |
| 332 |
} |
| 333 |
|
| 334 |
/* 2 Ethernet ports */ |
| 335 |
memset(data,0,sizeof(*data)); |
| 336 |
data->nr_port = 1; |
| 337 |
|
| 338 |
/* Set the PCI bus */ |
| 339 |
card->pci_bus = vm->slots_pci_bus[slot]; |
| 340 |
|
| 341 |
/* Set the EEPROM */ |
| 342 |
cisco_card_set_eeprom(vm,card,cisco_eeprom_find_pa("PA-GE")); |
| 343 |
c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom); |
| 344 |
|
| 345 |
/* Create the Intel i8254x chip */ |
| 346 |
data->port[0] = dev_i8254x_init(vm,card->dev_name,0, |
| 347 |
card->pci_bus,0, |
| 348 |
c7200_net_irq_for_slot_port(slot,0)); |
| 349 |
|
| 350 |
/* Store device info into the router structure */ |
| 351 |
card->drv_info = data; |
| 352 |
return(0); |
| 353 |
} |
| 354 |
|
| 355 |
/* PA-GE driver */ |
| 356 |
struct cisco_card_driver dev_c7200_pa_ge_driver = { |
| 357 |
"PA-GE", 0, 0, |
| 358 |
dev_c7200_pa_ge_init, |
| 359 |
dev_c7200_pa_i8254x_shutdown, |
| 360 |
NULL, |
| 361 |
dev_c7200_pa_i8254x_set_nio, |
| 362 |
dev_c7200_pa_i8254x_unset_nio, |
| 363 |
NULL, |
| 364 |
}; |
| 365 |
|
| 366 |
/* ====================================================================== */ |
| 367 |
/* C7200-IO-2FE */ |
| 368 |
/* ====================================================================== */ |
| 369 |
|
| 370 |
/* C7200-IO-2FE/E: C7200 IOCard with two FastEthernet ports EEPROM */ |
| 371 |
static const m_uint16_t eeprom_c7200_io_2fe_data[] = { |
| 372 |
0x04FF, 0x4002, 0x1541, 0x0201, 0xC046, 0x0320, 0x001B, 0xCA06, |
| 373 |
0x8249, 0x138B, 0x0642, 0x4230, 0xC18B, 0x3030, 0x3030, 0x3030, |
| 374 |
0x3030, 0x0000, 0x0004, 0x0002, 0x0385, 0x1C0D, 0x7F03, 0xCB8F, |
| 375 |
0x4337, 0x3230, 0x302D, 0x492F, 0x4F2D, 0x3246, 0x452F, 0x4580, |
| 376 |
0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, |
| 377 |
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, |
| 378 |
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, |
| 379 |
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, |
| 380 |
}; |
| 381 |
|
| 382 |
static const struct cisco_eeprom eeprom_c7200_io_2fe = { |
| 383 |
"C7200-IO-2FE", (m_uint16_t *)eeprom_c7200_io_2fe_data, |
| 384 |
sizeof(eeprom_c7200_io_2fe_data)/2, |
| 385 |
}; |
| 386 |
|
| 387 |
/* |
| 388 |
* dev_c7200_pa_2fe_tx_init() |
| 389 |
* |
| 390 |
* Add a C7200-IO-2FE/E port adapter into specified slot. |
| 391 |
*/ |
| 392 |
static int dev_c7200_iocard_2fe_init(vm_instance_t *vm,struct cisco_card *card) |
| 393 |
{ |
| 394 |
struct pa_i8254x_data *data; |
| 395 |
u_int slot = card->slot_id; |
| 396 |
|
| 397 |
/* Allocate the private data structure for the iocard */ |
| 398 |
if (!(data = malloc(sizeof(*data)))) { |
| 399 |
vm_error(vm,"%s: out of memory\n",card->dev_name); |
| 400 |
return(-1); |
| 401 |
} |
| 402 |
|
| 403 |
/* 2 Ethernet ports */ |
| 404 |
memset(data,0,sizeof(*data)); |
| 405 |
data->nr_port = 2; |
| 406 |
|
| 407 |
/* Set the PCI bus */ |
| 408 |
card->pci_bus = vm->slots_pci_bus[slot]; |
| 409 |
|
| 410 |
/* Set the EEPROM */ |
| 411 |
cisco_card_set_eeprom(vm,card,&eeprom_c7200_io_2fe); |
| 412 |
c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom); |
| 413 |
|
| 414 |
/* Port Fa0/0 is on PCI Device 1 */ |
| 415 |
data->port[0] = dev_i8254x_init(vm,card->dev_name,0, |
| 416 |
card->pci_bus,1, |
| 417 |
c7200_net_irq_for_slot_port(slot,1)); |
| 418 |
|
| 419 |
/* Port Fa0/1 is on PCI Device 0 */ |
| 420 |
data->port[1] = dev_i8254x_init(vm,card->dev_name,0, |
| 421 |
card->pci_bus,0, |
| 422 |
c7200_net_irq_for_slot_port(slot,0)); |
| 423 |
|
| 424 |
if (!data->port[0] || !data->port[1]) { |
| 425 |
dev_i8254x_remove(data->port[0]); |
| 426 |
dev_i8254x_remove(data->port[1]); |
| 427 |
free(data); |
| 428 |
return(-1); |
| 429 |
} |
| 430 |
|
| 431 |
/* Store device info into the router structure */ |
| 432 |
card->drv_info = data; |
| 433 |
return(0); |
| 434 |
} |
| 435 |
|
| 436 |
/* C7200-IO-2FE driver */ |
| 437 |
struct cisco_card_driver dev_c7200_iocard_2fe_driver = { |
| 438 |
"C7200-IO-2FE", 0, 0, |
| 439 |
dev_c7200_iocard_2fe_init, |
| 440 |
dev_c7200_pa_i8254x_shutdown, |
| 441 |
NULL, |
| 442 |
dev_c7200_pa_i8254x_set_nio, |
| 443 |
dev_c7200_pa_i8254x_unset_nio, |
| 444 |
NULL, |
| 445 |
}; |
| 446 |
|
| 447 |
/* ====================================================================== */ |
| 448 |
/* C7200-IO-GE-E */ |
| 449 |
/* ====================================================================== */ |
| 450 |
|
| 451 |
/* |
| 452 |
* C7200-IO-GE+E: C7200 IOCard with 1 GigatEthernet ports |
| 453 |
* and 1 Ethernet port EEPROM. |
| 454 |
*/ |
| 455 |
static const m_uint16_t eeprom_c7200_io_ge_e_data[] = { |
| 456 |
0x04FF, 0x4002, 0x1641, 0x0201, 0xC046, 0x0320, 0x001B, 0xCA06, |
| 457 |
0x8249, 0x138B, 0x0642, 0x4230, 0xC18B, 0x3030, 0x3030, 0x3030, |
| 458 |
0x3030, 0x0000, 0x0004, 0x0002, 0x0385, 0x1C0D, 0x7F03, 0xCB8F, |
| 459 |
0x4337, 0x3230, 0x302D, 0x492F, 0x4F2D, 0x3246, 0x452F, 0x4580, |
| 460 |
0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, |
| 461 |
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, |
| 462 |
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, |
| 463 |
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, |
| 464 |
}; |
| 465 |
|
| 466 |
static const struct cisco_eeprom eeprom_c7200_io_ge_e = { |
| 467 |
"C7200-IO-GE-E", (m_uint16_t *)eeprom_c7200_io_ge_e_data, |
| 468 |
sizeof(eeprom_c7200_io_ge_e_data)/2, |
| 469 |
}; |
| 470 |
|
| 471 |
/* |
| 472 |
* dev_c7200_pa_ge_e_tx_init() |
| 473 |
* |
| 474 |
* Add a C7200-I/O-GE+E port adapter into specified slot. |
| 475 |
*/ |
| 476 |
static int |
| 477 |
dev_c7200_iocard_ge_e_init(vm_instance_t *vm,struct cisco_card *card) |
| 478 |
{ |
| 479 |
struct pa_i8254x_data *data; |
| 480 |
u_int slot = card->slot_id; |
| 481 |
|
| 482 |
/* Allocate the private data structure for the iocard */ |
| 483 |
if (!(data = malloc(sizeof(*data)))) { |
| 484 |
vm_error(vm,"%s: out of memory\n",card->dev_name); |
| 485 |
return(-1); |
| 486 |
} |
| 487 |
|
| 488 |
/* 2 Ethernet ports */ |
| 489 |
memset(data,0,sizeof(*data)); |
| 490 |
data->nr_port = 2; |
| 491 |
|
| 492 |
/* Set the PCI bus */ |
| 493 |
card->pci_bus = vm->slots_pci_bus[slot]; |
| 494 |
|
| 495 |
/* Set the EEPROM */ |
| 496 |
cisco_card_set_eeprom(vm,card,&eeprom_c7200_io_ge_e); |
| 497 |
c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom); |
| 498 |
|
| 499 |
/* Port Gi0/0 is on PCI Device 1 */ |
| 500 |
data->port[0] = dev_i8254x_init(vm,card->dev_name,0, |
| 501 |
card->pci_bus,1, |
| 502 |
c7200_net_irq_for_slot_port(slot,1)); |
| 503 |
|
| 504 |
/* Port e0/0 is on PCI Device 0 */ |
| 505 |
data->port[1] = dev_i8254x_init(vm,card->dev_name,0, |
| 506 |
card->pci_bus,0, |
| 507 |
c7200_net_irq_for_slot_port(slot,0)); |
| 508 |
|
| 509 |
/* Store device info into the router structure */ |
| 510 |
card->drv_info = data; |
| 511 |
return(0); |
| 512 |
} |
| 513 |
|
| 514 |
/* C7200-IO-GE-E driver */ |
| 515 |
struct cisco_card_driver dev_c7200_iocard_ge_e_driver = { |
| 516 |
"C7200-IO-GE-E", 0, 0, |
| 517 |
dev_c7200_iocard_ge_e_init, |
| 518 |
dev_c7200_pa_i8254x_shutdown, |
| 519 |
NULL, |
| 520 |
dev_c7200_pa_i8254x_set_nio, |
| 521 |
dev_c7200_pa_i8254x_unset_nio, |
| 522 |
NULL, |
| 523 |
}; |
| 524 |
|
| 525 |
/* ====================================================================== */ |
| 526 |
/* PA-4E / PA-8E */ |
| 527 |
/* ====================================================================== */ |
| 528 |
|
| 529 |
/* PA-4E/PA-8E data */ |
| 530 |
struct pa_4e8e_data { |
| 531 |
u_int nr_port; |
| 532 |
struct am79c971_data *port[8]; |
| 533 |
}; |
| 534 |
|
| 535 |
/* |
| 536 |
* dev_c7200_pa_4e_init() |
| 537 |
* |
| 538 |
* Add a PA-4E port adapter into specified slot. |
| 539 |
*/ |
| 540 |
static int dev_c7200_pa_4e_init(vm_instance_t *vm,struct cisco_card *card) |
| 541 |
{ |
| 542 |
struct pa_4e8e_data *data; |
| 543 |
u_int slot = card->slot_id; |
| 544 |
int i; |
| 545 |
|
| 546 |
/* Allocate the private data structure for the PA-4E */ |
| 547 |
if (!(data = malloc(sizeof(*data)))) { |
| 548 |
vm_error(vm,"%s: out of memory\n",card->dev_name); |
| 549 |
return(-1); |
| 550 |
} |
| 551 |
|
| 552 |
/* 4 Ethernet ports */ |
| 553 |
memset(data,0,sizeof(*data)); |
| 554 |
data->nr_port = 4; |
| 555 |
|
| 556 |
/* Set the PCI bus */ |
| 557 |
card->pci_bus = vm->slots_pci_bus[slot]; |
| 558 |
|
| 559 |
/* Set the EEPROM */ |
| 560 |
cisco_card_set_eeprom(vm,card,cisco_eeprom_find_pa("PA-4E")); |
| 561 |
c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom); |
| 562 |
|
| 563 |
/* Create the AMD Am79c971 chips */ |
| 564 |
for(i=0;i<data->nr_port;i++) { |
| 565 |
data->port[i] = dev_am79c971_init(vm,card->dev_name, |
| 566 |
AM79C971_TYPE_10BASE_T, |
| 567 |
card->pci_bus,i, |
| 568 |
c7200_net_irq_for_slot_port(slot,i)); |
| 569 |
} |
| 570 |
|
| 571 |
/* Store device info into the router structure */ |
| 572 |
card->drv_info = data; |
| 573 |
return(0); |
| 574 |
} |
| 575 |
|
| 576 |
/* |
| 577 |
* dev_c7200_pa_8e_init() |
| 578 |
* |
| 579 |
* Add a PA-8E port adapter into specified slot. |
| 580 |
*/ |
| 581 |
static int dev_c7200_pa_8e_init(vm_instance_t *vm,struct cisco_card *card) |
| 582 |
{ |
| 583 |
struct pa_4e8e_data *data; |
| 584 |
u_int slot = card->slot_id; |
| 585 |
int i; |
| 586 |
|
| 587 |
/* Allocate the private data structure for the PA-8E */ |
| 588 |
if (!(data = malloc(sizeof(*data)))) { |
| 589 |
vm_error(vm,"%s: out of memory\n",card->dev_name); |
| 590 |
return(-1); |
| 591 |
} |
| 592 |
|
| 593 |
/* 4 Ethernet ports */ |
| 594 |
memset(data,0,sizeof(*data)); |
| 595 |
data->nr_port = 8; |
| 596 |
|
| 597 |
/* Set the PCI bus */ |
| 598 |
card->pci_bus = vm->slots_pci_bus[slot]; |
| 599 |
|
| 600 |
/* Set the EEPROM */ |
| 601 |
cisco_card_set_eeprom(vm,card,cisco_eeprom_find_pa("PA-8E")); |
| 602 |
c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom); |
| 603 |
|
| 604 |
/* Create the AMD Am79c971 chips */ |
| 605 |
for(i=0;i<data->nr_port;i++) { |
| 606 |
data->port[i] = dev_am79c971_init(vm,card->dev_name, |
| 607 |
AM79C971_TYPE_10BASE_T, |
| 608 |
card->pci_bus,i, |
| 609 |
c7200_net_irq_for_slot_port(slot,i)); |
| 610 |
} |
| 611 |
|
| 612 |
/* Store device info into the router structure */ |
| 613 |
card->drv_info = data; |
| 614 |
return(0); |
| 615 |
} |
| 616 |
|
| 617 |
/* Remove a PA-4E/PA-8E from the specified slot */ |
| 618 |
static int |
| 619 |
dev_c7200_pa_4e8e_shutdown(vm_instance_t *vm,struct cisco_card *card) |
| 620 |
{ |
| 621 |
struct pa_4e8e_data *data = card->drv_info; |
| 622 |
int i; |
| 623 |
|
| 624 |
/* Remove the PA EEPROM */ |
| 625 |
cisco_card_unset_eeprom(card); |
| 626 |
c7200_set_slot_eeprom(VM_C7200(vm),card->slot_id,NULL); |
| 627 |
|
| 628 |
/* Remove the AMD Am79c971 chips */ |
| 629 |
for(i=0;i<data->nr_port;i++) |
| 630 |
dev_am79c971_remove(data->port[i]); |
| 631 |
|
| 632 |
free(data); |
| 633 |
return(0); |
| 634 |
} |
| 635 |
|
| 636 |
/* Bind a Network IO descriptor */ |
| 637 |
static int |
| 638 |
dev_c7200_pa_4e8e_set_nio(vm_instance_t *vm,struct cisco_card *card, |
| 639 |
u_int port_id,netio_desc_t *nio) |
| 640 |
{ |
| 641 |
struct pa_4e8e_data *d = card->drv_info; |
| 642 |
|
| 643 |
if (!d || (port_id >= d->nr_port)) |
| 644 |
return(-1); |
| 645 |
|
| 646 |
dev_am79c971_set_nio(d->port[port_id],nio); |
| 647 |
return(0); |
| 648 |
} |
| 649 |
|
| 650 |
/* Unbind a Network IO descriptor */ |
| 651 |
static int |
| 652 |
dev_c7200_pa_4e8e_unset_nio(vm_instance_t *vm,struct cisco_card *card, |
| 653 |
u_int port_id) |
| 654 |
{ |
| 655 |
struct pa_4e8e_data *d = card->drv_info; |
| 656 |
|
| 657 |
if (!d || (port_id >= d->nr_port)) |
| 658 |
return(-1); |
| 659 |
|
| 660 |
dev_am79c971_unset_nio(d->port[port_id]); |
| 661 |
return(0); |
| 662 |
} |
| 663 |
|
| 664 |
/* PA-4E driver */ |
| 665 |
struct cisco_card_driver dev_c7200_pa_4e_driver = { |
| 666 |
"PA-4E", 1, 0, |
| 667 |
dev_c7200_pa_4e_init, |
| 668 |
dev_c7200_pa_4e8e_shutdown, |
| 669 |
NULL, |
| 670 |
dev_c7200_pa_4e8e_set_nio, |
| 671 |
dev_c7200_pa_4e8e_unset_nio, |
| 672 |
NULL, |
| 673 |
}; |
| 674 |
|
| 675 |
/* PA-8E driver */ |
| 676 |
struct cisco_card_driver dev_c7200_pa_8e_driver = { |
| 677 |
"PA-8E", 1, 0, |
| 678 |
dev_c7200_pa_8e_init, |
| 679 |
dev_c7200_pa_4e8e_shutdown, |
| 680 |
NULL, |
| 681 |
dev_c7200_pa_4e8e_set_nio, |
| 682 |
dev_c7200_pa_4e8e_unset_nio, |
| 683 |
NULL, |
| 684 |
}; |
| 685 |
|
| 686 |
/* ====================================================================== */ |
| 687 |
/* NPE-G2 */ |
| 688 |
/* ====================================================================== */ |
| 689 |
|
| 690 |
/* Initialize NPE-G2 Ethernet ports */ |
| 691 |
static int dev_c7200_npeg2_init(vm_instance_t *vm,struct cisco_card *card) |
| 692 |
{ |
| 693 |
/* Nothing to do */ |
| 694 |
card->drv_info = VM_C7200(vm)->mv64460_sysctr; |
| 695 |
return(0); |
| 696 |
} |
| 697 |
|
| 698 |
/* Shutdown NPE-G2 Ethernet ports */ |
| 699 |
static int dev_c7200_npeg2_shutdown(vm_instance_t *vm,struct cisco_card *card) |
| 700 |
{ |
| 701 |
/* Nothing to do */ |
| 702 |
return(0); |
| 703 |
} |
| 704 |
|
| 705 |
/* Set a NIO descriptor */ |
| 706 |
static int dev_c7200_npeg2_set_nio(vm_instance_t *vm,struct cisco_card *card, |
| 707 |
u_int port_id,netio_desc_t *nio) |
| 708 |
{ |
| 709 |
c7200_t *router = VM_C7200(vm); |
| 710 |
struct mv64460_data *mv_data = router->mv64460_sysctr; |
| 711 |
|
| 712 |
if (!mv_data) |
| 713 |
return(-1); |
| 714 |
|
| 715 |
dev_mv64460_eth_set_nio(mv_data,port_id,nio); |
| 716 |
return(0); |
| 717 |
} |
| 718 |
|
| 719 |
/* Unbind a NIO descriptor */ |
| 720 |
static int dev_c7200_npeg2_unset_nio(vm_instance_t *vm, |
| 721 |
struct cisco_card *card, |
| 722 |
u_int port_id) |
| 723 |
{ |
| 724 |
c7200_t *router = VM_C7200(vm); |
| 725 |
struct mv64460_data *mv_data = router->mv64460_sysctr; |
| 726 |
|
| 727 |
if (!mv_data) |
| 728 |
return(-1); |
| 729 |
|
| 730 |
dev_mv64460_eth_unset_nio(mv_data,port_id); |
| 731 |
return(0); |
| 732 |
} |
| 733 |
|
| 734 |
/* NPE-G2 driver */ |
| 735 |
struct cisco_card_driver dev_c7200_npeg2_driver = { |
| 736 |
"NPE-G2", 1, 0, |
| 737 |
dev_c7200_npeg2_init, |
| 738 |
dev_c7200_npeg2_shutdown, |
| 739 |
NULL, |
| 740 |
dev_c7200_npeg2_set_nio, |
| 741 |
dev_c7200_npeg2_unset_nio, |
| 742 |
NULL, |
| 743 |
}; |