1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
|
/*
* Cisco router simulation platform.
* Copyright (c) 2007 Christophe Fillot (cf@utc.fr)
*
* WIC Modules.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include <assert.h>
#include "utils.h"
#include "net.h"
#include "net_io.h"
#include "ptask.h"
#include "vm.h"
#include "dev_nm_16esw.h"
#include "dev_mpc860.h"
#include "dev_c1700.h"
#include "dev_wic_serial.h"
/* Get the SCC channel associated to a WIC sub-slot */
static int dev_c1700_mb_wic_get_scc_chan(struct cisco_card *card,u_int port_id,
u_int *scc_chan)
{
u_int cid;
cid = card->subslot_id + port_id;
switch(cid) {
/* WIC 0 port 0 mapped to MPC860 SCC1 */
case 0x10:
*scc_chan = 0;
break;
/* WIC 0 port 1 mapped to MPC860 SCC4 */
case 0x11:
*scc_chan = 3;
break;
/* WIC 1 port 0 mapped to MPC860 SCC2 */
case 0x20:
*scc_chan = 1;
break;
/* WIC 1 port 1 mapped to MPC860 SCC3 */
case 0x21:
*scc_chan = 2;
break;
default:
return(-1);
}
return(0);
}
/* ======================================================================== */
/* WIC-1T */
/* ======================================================================== */
/* Initialize a WIC-1T in the specified slot */
static int dev_c1700_mb_wic1t_init(vm_instance_t *vm,struct cisco_card *card)
{
struct wic_serial_data *wic_data;
m_uint64_t phys_addr;
u_int wic_id;
/* Create the WIC device */
wic_id = (card->subslot_id >> 4) - 1;
if (c1700_get_onboard_wic_addr(wic_id,&phys_addr) == -1) {
vm_error(vm,"WIC","invalid slot %u (subslot_id=%u)\n",
wic_id,card->subslot_id);
return(-1);
}
wic_data = dev_wic_serial_init(vm,card->dev_name,WIC_SERIAL_MODEL_1T,
phys_addr,C1700_WIC_SIZE);
if (!wic_data)
return(-1);
/* Set the EEPROM */
cisco_card_set_eeprom(vm,card,cisco_eeprom_find_wic("WIC-1T"));
/* Store device info into the router structure */
card->drv_info = wic_data;
return(0);
}
/* Remove a WIC-1T from the specified slot */
static int
dev_c1700_mb_wic1t_shutdown(vm_instance_t *vm,struct cisco_card *card)
{
/* Remove the WIC device */
dev_wic_serial_remove(card->drv_info);
/* Remove the WIC EEPROM */
cisco_card_unset_eeprom(card);
return(0);
}
/* Bind a Network IO descriptor */
static int
dev_c1700_mb_wic1t_set_nio(vm_instance_t *vm,struct cisco_card *card,
u_int port_id,netio_desc_t *nio)
{
u_int scc_chan;
if ((port_id > 0) ||
(dev_c1700_mb_wic_get_scc_chan(card,port_id,&scc_chan) == -1))
return(-1);
return(mpc860_scc_set_nio(VM_C1700(vm)->mpc_data,scc_chan,nio));
}
/* Unbind a Network IO descriptor */
static int
dev_c1700_mb_wic1t_unset_nio(vm_instance_t *vm,struct cisco_card *card,
u_int port_id)
{
u_int scc_chan;
if ((port_id > 0) ||
(dev_c1700_mb_wic_get_scc_chan(card,port_id,&scc_chan) == -1))
return(-1);
return(mpc860_scc_unset_nio(VM_C1700(vm)->mpc_data,scc_chan));
}
/* ======================================================================== */
/* WIC-2T */
/* ======================================================================== */
/* Initialize a WIC-2T in the specified slot */
static int dev_c1700_mb_wic2t_init(vm_instance_t *vm,struct cisco_card *card)
{
struct wic_serial_data *wic_data;
m_uint64_t phys_addr;
u_int wic_id;
/* Create the WIC device */
wic_id = (card->subslot_id >> 4) - 1;
if (c1700_get_onboard_wic_addr(wic_id,&phys_addr) == -1) {
vm_error(vm,"WIC","invalid slot %u (subslot_id=%u)\n",
wic_id,card->subslot_id);
return(-1);
}
wic_data = dev_wic_serial_init(vm,card->dev_name,WIC_SERIAL_MODEL_2T,
phys_addr,C1700_WIC_SIZE);
if (!wic_data)
return(-1);
/* Set the EEPROM */
cisco_card_set_eeprom(vm,card,cisco_eeprom_find_wic("WIC-2T"));
/* Store device info into the router structure */
card->drv_info = wic_data;
return(0);
}
/* Remove a WIC-2T from the specified slot */
static int
dev_c1700_mb_wic2t_shutdown(vm_instance_t *vm,struct cisco_card *card)
{
/* Remove the WIC device */
dev_wic_serial_remove(card->drv_info);
/* Remove the WIC EEPROM */
cisco_card_unset_eeprom(card);
return(0);
}
/* Bind a Network IO descriptor */
static int
dev_c1700_mb_wic2t_set_nio(vm_instance_t *vm,struct cisco_card *card,
u_int port_id,netio_desc_t *nio)
{
u_int scc_chan;
if ((port_id > 1) ||
(dev_c1700_mb_wic_get_scc_chan(card,port_id,&scc_chan) == -1))
return(-1);
return(mpc860_scc_set_nio(VM_C1700(vm)->mpc_data,scc_chan,nio));
}
/* Unbind a Network IO descriptor */
static int
dev_c1700_mb_wic2t_unset_nio(vm_instance_t *vm,struct cisco_card *card,
u_int port_id)
{
u_int scc_chan;
if ((port_id > 1) ||
(dev_c1700_mb_wic_get_scc_chan(card,port_id,&scc_chan) == -1))
return(-1);
return(mpc860_scc_unset_nio(VM_C1700(vm)->mpc_data,scc_chan));
}
/* ======================================================================== */
/* WIC-1ENET */
/* ======================================================================== */
/* Initialize a WIC-1ENET in the specified slot */
static int
dev_c1700_mb_wic1enet_init(vm_instance_t *vm,struct cisco_card *card)
{
m_uint8_t eeprom_ver;
size_t offset;
n_eth_addr_t addr;
m_uint16_t pid;
pid = (m_uint16_t)getpid();
/* Generate automatically the MAC address */
addr.eth_addr_byte[0] = vm_get_mac_addr_msb(vm);
addr.eth_addr_byte[1] = vm->instance_id & 0xFF;
addr.eth_addr_byte[2] = pid >> 8;
addr.eth_addr_byte[3] = pid & 0xFF;
addr.eth_addr_byte[4] = card->subslot_id;
addr.eth_addr_byte[5] = 0x00;
/* Set the EEPROM */
cisco_card_set_eeprom(vm,card,cisco_eeprom_find_wic("WIC-1ENET"));
/* Read EEPROM format version */
cisco_eeprom_get_byte(&card->eeprom,0,&eeprom_ver);
if (eeprom_ver != 4)
return(-1);
if (cisco_eeprom_v4_find_field(&card->eeprom,0xCF,&offset) == -1)
return(-1);
cisco_eeprom_set_region(&card->eeprom,offset,addr.eth_addr_byte,6);
/* Store device info into the router structure */
card->drv_info = VM_C1700(vm)->mpc_data;
return(0);
}
/* Remove a WIC-1ENET from the specified slot */
static int
dev_c1700_mb_wic1enet_shutdown(vm_instance_t *vm,struct cisco_card *card)
{
/* Remove the WIC EEPROM */
cisco_card_unset_eeprom(card);
return(0);
}
/* Bind a Network IO descriptor */
static int
dev_c1700_mb_wic1enet_set_nio(vm_instance_t *vm,struct cisco_card *card,
u_int port_id,netio_desc_t *nio)
{
struct mpc860_data *mpc_data = card->drv_info;
u_int scc_chan;
if ((port_id > 0) ||
(dev_c1700_mb_wic_get_scc_chan(card,port_id,&scc_chan) == -1))
return(-1);
return(mpc860_scc_set_nio(mpc_data,scc_chan,nio));
}
/* Unbind a Network IO descriptor */
static int
dev_c1700_mb_wic1enet_unset_nio(vm_instance_t *vm,struct cisco_card *card,
u_int port_id)
{
struct mpc860_data *mpc_data = card->drv_info;
u_int scc_chan;
if ((port_id > 0) ||
(dev_c1700_mb_wic_get_scc_chan(card,port_id,&scc_chan) == -1))
return(-1);
return(mpc860_scc_unset_nio(mpc_data,scc_chan));
}
/* ======================================================================== */
/* Cisco 1700 WIC-1T driver */
struct cisco_card_driver dev_c1700_mb_wic1t_driver = {
"WIC-1T", 1, 0,
dev_c1700_mb_wic1t_init,
dev_c1700_mb_wic1t_shutdown,
NULL,
dev_c1700_mb_wic1t_set_nio,
dev_c1700_mb_wic1t_unset_nio,
NULL,
};
/* Cisco 1700 WIC-2T driver */
struct cisco_card_driver dev_c1700_mb_wic2t_driver = {
"WIC-2T", 1, 0,
dev_c1700_mb_wic2t_init,
dev_c1700_mb_wic2t_shutdown,
NULL,
dev_c1700_mb_wic2t_set_nio,
dev_c1700_mb_wic2t_unset_nio,
NULL,
};
/* Cisco 1700 WIC-1ENET driver */
struct cisco_card_driver dev_c1700_mb_wic1enet_driver = {
"WIC-1ENET", 1, 0,
dev_c1700_mb_wic1enet_init,
dev_c1700_mb_wic1enet_shutdown,
NULL,
dev_c1700_mb_wic1enet_set_nio,
dev_c1700_mb_wic1enet_unset_nio,
NULL,
};
/* WIC drivers (mainbord slots) */
struct cisco_card_driver *dev_c1700_mb_wic_drivers[] = {
&dev_c1700_mb_wic1t_driver,
&dev_c1700_mb_wic2t_driver,
&dev_c1700_mb_wic1enet_driver,
NULL,
};
|