| 1 |
/* |
| 2 |
* Cisco router simulation platform. |
| 3 |
* Copyright (c) 2006 Christophe Fillot ([email protected]) |
| 4 |
* |
| 5 |
* Serial Network Modules. |
| 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_mueslix.h" |
| 22 |
#include "dev_c3600.h" |
| 23 |
#include "dev_c3600_bay.h" |
| 24 |
|
| 25 |
/* ====================================================================== */ |
| 26 |
/* NM-4T */ |
| 27 |
/* ====================================================================== */ |
| 28 |
|
| 29 |
/* |
| 30 |
* dev_c3600_nm_4t_init() |
| 31 |
* |
| 32 |
* Add a NM-4T network module into specified slot. |
| 33 |
*/ |
| 34 |
int dev_c3600_nm_4t_init(vm_instance_t *vm,struct cisco_card *card) |
| 35 |
{ |
| 36 |
struct nm_bay_info *bay_info; |
| 37 |
struct mueslix_data *data; |
| 38 |
u_int slot = card->slot_id; |
| 39 |
u_int chassis_id; |
| 40 |
|
| 41 |
/* Set the PCI bus */ |
| 42 |
card->pci_bus = vm->slots_pci_bus[slot]; |
| 43 |
|
| 44 |
/* Set the EEPROM */ |
| 45 |
cisco_card_set_eeprom(vm,card,cisco_eeprom_find_nm("NM-4T")); |
| 46 |
c3600_set_slot_eeprom(VM_C3600(vm),slot,&card->eeprom); |
| 47 |
|
| 48 |
/* Get PCI bus info about this bay */ |
| 49 |
chassis_id = c3600_chassis_get_id(VM_C3600(vm)); |
| 50 |
bay_info = c3600_nm_get_bay_info(chassis_id,slot); |
| 51 |
|
| 52 |
if (!bay_info) { |
| 53 |
vm_error(vm,"unable to get info for NM bay %u\n",slot); |
| 54 |
return(-1); |
| 55 |
} |
| 56 |
|
| 57 |
/* Create the Mueslix chip */ |
| 58 |
data = dev_mueslix_init(vm,card->dev_name,0, |
| 59 |
card->pci_bus,bay_info->pci_device, |
| 60 |
c3600_net_irq_for_slot_port(slot,0)); |
| 61 |
if (!data) return(-1); |
| 62 |
|
| 63 |
/* Store device info into the router structure */ |
| 64 |
card->drv_info = data; |
| 65 |
return(0); |
| 66 |
} |
| 67 |
|
| 68 |
/* Remove a NM-4T from the specified slot */ |
| 69 |
int dev_c3600_nm_4t_shutdown(vm_instance_t *vm,struct cisco_card *card) |
| 70 |
{ |
| 71 |
/* Remove the NM EEPROM */ |
| 72 |
cisco_card_unset_eeprom(card); |
| 73 |
c3600_set_slot_eeprom(VM_C3600(vm),card->slot_id,NULL); |
| 74 |
|
| 75 |
/* Remove the mueslix driver */ |
| 76 |
dev_mueslix_remove(card->drv_info); |
| 77 |
return(0); |
| 78 |
} |
| 79 |
|
| 80 |
/* Bind a Network IO descriptor to a specific port */ |
| 81 |
int dev_c3600_nm_4t_set_nio(vm_instance_t *vm,struct cisco_card *card, |
| 82 |
u_int port_id,netio_desc_t *nio) |
| 83 |
{ |
| 84 |
struct mueslix_data *d = card->drv_info; |
| 85 |
|
| 86 |
if (!d || (port_id >= MUESLIX_NR_CHANNELS)) |
| 87 |
return(-1); |
| 88 |
|
| 89 |
return(dev_mueslix_set_nio(d,port_id,nio)); |
| 90 |
} |
| 91 |
|
| 92 |
/* Unbind a Network IO descriptor to a specific port */ |
| 93 |
int dev_c3600_nm_4t_unset_nio(vm_instance_t *vm,struct cisco_card *card, |
| 94 |
u_int port_id) |
| 95 |
{ |
| 96 |
struct mueslix_data *d = card->drv_info; |
| 97 |
|
| 98 |
if (!d || (port_id >= MUESLIX_NR_CHANNELS)) |
| 99 |
return(-1); |
| 100 |
|
| 101 |
return(dev_mueslix_unset_nio(d,port_id)); |
| 102 |
} |
| 103 |
|
| 104 |
/* NM-4T driver */ |
| 105 |
struct cisco_card_driver dev_c3600_nm_4t_driver = { |
| 106 |
"NM-4T", 1, 0, |
| 107 |
dev_c3600_nm_4t_init, |
| 108 |
dev_c3600_nm_4t_shutdown, |
| 109 |
NULL, |
| 110 |
dev_c3600_nm_4t_set_nio, |
| 111 |
dev_c3600_nm_4t_unset_nio, |
| 112 |
NULL, |
| 113 |
}; |