1 |
/* |
2 |
* Cisco 3600 simulation platform. |
3 |
* Copyright (c) 2006 Christophe Fillot (cf@utc.fr) |
4 |
* |
5 |
* Generic Cisco 3600 routines and definitions (EEPROM,...). |
6 |
*/ |
7 |
|
8 |
#ifndef __DEV_C3600_H__ |
9 |
#define __DEV_C3600_H__ |
10 |
|
11 |
#include <pthread.h> |
12 |
|
13 |
#include "utils.h" |
14 |
#include "net.h" |
15 |
#include "device.h" |
16 |
#include "pci_dev.h" |
17 |
#include "nmc93c46.h" |
18 |
#include "net_io.h" |
19 |
#include "vm.h" |
20 |
|
21 |
/* Default C3600 parameters */ |
22 |
#define C3600_DEFAULT_CHASSIS "3640" |
23 |
#define C3600_DEFAULT_RAM_SIZE 128 |
24 |
#define C3600_DEFAULT_ROM_SIZE 2 |
25 |
#define C3600_DEFAULT_NVRAM_SIZE 128 |
26 |
#define C3600_DEFAULT_CONF_REG 0x2102 |
27 |
#define C3600_DEFAULT_CLOCK_DIV 4 |
28 |
#define C3600_DEFAULT_RAM_MMAP 1 |
29 |
#define C3600_DEFAULT_DISK0_SIZE 0 |
30 |
#define C3600_DEFAULT_DISK1_SIZE 0 |
31 |
#define C3600_DEFAULT_IOMEM_SIZE 5 /* Percents! */ |
32 |
|
33 |
/* 6 NM slots for the 3660 + integrated FastEthernet ports */ |
34 |
#define C3600_MAX_NM_BAYS 7 |
35 |
|
36 |
/* C3600 DUART Interrupt */ |
37 |
#define C3600_DUART_IRQ 5 |
38 |
|
39 |
/* C3600 Network I/O Interrupt */ |
40 |
#define C3600_NETIO_IRQ 2 |
41 |
|
42 |
/* C3600 GT64k DMA/Timer Interrupt */ |
43 |
#define C3600_GT64K_IRQ 4 |
44 |
|
45 |
/* C3600 External Interrupt */ |
46 |
#define C3600_EXT_IRQ 6 |
47 |
|
48 |
/* C3600 NM Management Interrupt handler */ |
49 |
#define C3600_NM_MGMT_IRQ 3 |
50 |
|
51 |
/* C3600 common device addresses */ |
52 |
#define C3600_GT64K_ADDR 0x14000000ULL |
53 |
#define C3600_IOFPGA_ADDR 0x1e800000ULL |
54 |
#define C3600_DUART_ADDR 0x1e840000ULL |
55 |
#define C3600_BITBUCKET_ADDR 0x1ec00000ULL |
56 |
#define C3600_NVRAM_ADDR 0x1fe00000ULL |
57 |
#define C3600_ROM_ADDR 0x1fc00000ULL |
58 |
#define C3600_BOOTFLASH_ADDR 0x30000000ULL |
59 |
#define C3600_PCI_IO_ADDR 0x100000000ULL |
60 |
|
61 |
/* Reserved space for ROM in NVRAM */ |
62 |
#define C3600_NVRAM_ROM_RES_SIZE 2048 |
63 |
|
64 |
/* C3600 ELF Platform ID */ |
65 |
#define C3620_ELF_MACHINE_ID 0x1e |
66 |
#define C3640_ELF_MACHINE_ID 0x1e |
67 |
//#define C3660_ELF_MACHINE_ID ???? |
68 |
|
69 |
/* C3600 router */ |
70 |
typedef struct c3600_router c3600_t; |
71 |
|
72 |
/* C3600 EEPROM */ |
73 |
struct c3600_eeprom { |
74 |
char *name; |
75 |
m_uint16_t *data; |
76 |
u_int len; |
77 |
}; |
78 |
|
79 |
/* Prototype of chassis driver initialization function */ |
80 |
typedef int (*c3600_chassis_init_fn)(c3600_t *router); |
81 |
|
82 |
/* Prototype of NM driver initialization function */ |
83 |
typedef int (*c3600_nm_init_fn)(c3600_t *router,char *name,u_int nm_bay); |
84 |
|
85 |
/* Prototype of NM driver shutdown function */ |
86 |
typedef int (*c3600_nm_shutdown_fn)(c3600_t *router,u_int nm_bay); |
87 |
|
88 |
/* Prototype of NM NIO set function */ |
89 |
typedef int (*c3600_nm_set_nio_fn)(c3600_t *router,u_int nm_bay,u_int port_id, |
90 |
netio_desc_t *nio); |
91 |
|
92 |
/* Prototype of NM NIO unset function */ |
93 |
typedef int (*c3600_nm_unset_nio_fn)(c3600_t *router,u_int nm_bay, |
94 |
u_int port_id); |
95 |
|
96 |
/* Prototype of NM NIO show info function */ |
97 |
typedef int (*c3600_nm_show_info_fn)(c3600_t *router,u_int nm_bay); |
98 |
|
99 |
/* C3600 Network Module Driver */ |
100 |
struct c3600_nm_driver { |
101 |
char *dev_type; |
102 |
int supported; |
103 |
int wic_slots; |
104 |
c3600_nm_init_fn nm_init; |
105 |
c3600_nm_shutdown_fn nm_shutdown; |
106 |
c3600_nm_set_nio_fn nm_set_nio; |
107 |
c3600_nm_unset_nio_fn nm_unset_nio; |
108 |
c3600_nm_show_info_fn nm_show_info; |
109 |
|
110 |
/* TODO: WAN Interface Cards (WIC) */ |
111 |
}; |
112 |
|
113 |
/* C3600 NIO binding to a slot/port */ |
114 |
struct c3600_nio_binding { |
115 |
netio_desc_t *nio; |
116 |
u_int port_id; |
117 |
struct c3600_nio_binding *prev,*next; |
118 |
}; |
119 |
|
120 |
/* C3600 NM bay */ |
121 |
struct c3600_nm_bay { |
122 |
char *dev_name; /* Device name */ |
123 |
char *dev_type; /* Device Type */ |
124 |
struct pci_bus *pci_map; /* PCI bus */ |
125 |
m_uint16_t *eeprom_data; /* NM EEPROM data */ |
126 |
u_int eeprom_data_len; /* NM EEPROM data length */ |
127 |
struct c3600_nm_driver *nm_driver; /* NM Driver */ |
128 |
void *drv_info; /* Private driver info */ |
129 |
struct c3600_nio_binding *nio_list; /* NIO bindings to ports */ |
130 |
}; |
131 |
|
132 |
/* C3600 Chassis Driver */ |
133 |
struct c3600_chassis_driver { |
134 |
char *chassis_type; |
135 |
int chassis_id; |
136 |
int supported; |
137 |
c3600_chassis_init_fn chassis_init; |
138 |
m_uint16_t *mb_eeprom; |
139 |
u_int mb_eeprom_len; |
140 |
}; |
141 |
|
142 |
/* C3600 router */ |
143 |
struct c3600_router { |
144 |
/* Chassis MAC address */ |
145 |
n_eth_addr_t mac_addr; |
146 |
|
147 |
/* Associated VM instance */ |
148 |
vm_instance_t *vm; |
149 |
|
150 |
/* IO memory size to be passed to Smart Init */ |
151 |
u_int nm_iomem_size; |
152 |
|
153 |
/* Chassis information */ |
154 |
struct c3600_chassis_driver *chassis_driver; |
155 |
struct c3600_nm_bay nm_bay[C3600_MAX_NM_BAYS]; |
156 |
m_uint8_t oir_status; |
157 |
|
158 |
/* |
159 |
* Mainboard EEPROM. |
160 |
* It can be modified to change the chassis MAC address. |
161 |
*/ |
162 |
m_uint16_t mb_eeprom_data[64]; |
163 |
struct nmc93c46_eeprom_def mb_eeprom; |
164 |
struct nmc93c46_group mb_eeprom_group; |
165 |
|
166 |
/* Network Module EEPROMs (3620/3640) */ |
167 |
struct nmc93c46_eeprom_def nm_eeprom; |
168 |
struct nmc93c46_group nm_eeprom_group; |
169 |
|
170 |
/* Cisco 3660 NM EEPROMs */ |
171 |
struct nmc93c46_eeprom_def c3660_nm_eeprom_def[C3600_MAX_NM_BAYS]; |
172 |
struct nmc93c46_group c3660_nm_eeprom_group[C3600_MAX_NM_BAYS]; |
173 |
}; |
174 |
|
175 |
/* Create a new router instance */ |
176 |
c3600_t *c3600_create_instance(char *name,int instance_id); |
177 |
|
178 |
/* Delete a router instance */ |
179 |
int c3600_delete_instance(char *name); |
180 |
|
181 |
/* Delete all router instances */ |
182 |
int c3600_delete_all_instances(void); |
183 |
|
184 |
/* Save configuration of a C3600 instance */ |
185 |
void c3600_save_config(c3600_t *router,FILE *fd); |
186 |
|
187 |
/* Save configurations of all C3600 instances */ |
188 |
void c3600_save_config_all(FILE *fd); |
189 |
|
190 |
/* Set NM EEPROM definition */ |
191 |
int c3600_nm_set_eeprom(c3600_t *router,u_int nm_bay, |
192 |
const struct c3600_eeprom *eeprom); |
193 |
|
194 |
/* Unset NM EEPROM definition (empty bay) */ |
195 |
int c3600_nm_unset_eeprom(c3600_t *router,u_int nm_bay); |
196 |
|
197 |
/* Check if a bay has a Network Module */ |
198 |
int c3600_nm_check_eeprom(c3600_t *router,u_int nm_bay); |
199 |
|
200 |
/* Get bay info */ |
201 |
struct c3600_nm_bay *c3600_nm_get_info(c3600_t *router,u_int nm_bay); |
202 |
|
203 |
/* Get NM type */ |
204 |
char *c3600_nm_get_type(c3600_t *router,u_int nm_bay); |
205 |
|
206 |
/* Get driver info about the specified slot */ |
207 |
void *c3600_nm_get_drvinfo(c3600_t *router,u_int nm_bay); |
208 |
|
209 |
/* Set driver info for the specified slot */ |
210 |
int c3600_nm_set_drvinfo(c3600_t *router,u_int nm_bay,void *drv_info); |
211 |
|
212 |
/* Add a NM binding */ |
213 |
int c3600_nm_add_binding(c3600_t *router,char *dev_type,u_int nm_bay); |
214 |
|
215 |
/* Remove a NM binding */ |
216 |
int c3600_nm_remove_binding(c3600_t *router,u_int nm_bay); |
217 |
|
218 |
/* Find a NIO binding */ |
219 |
struct c3600_nio_binding * |
220 |
c3600_nm_find_nio_binding(c3600_t *router,u_int nm_bay,u_int port_id); |
221 |
|
222 |
/* Add a network IO binding */ |
223 |
int c3600_nm_add_nio_binding(c3600_t *router,u_int nm_bay,u_int port_id, |
224 |
char *nio_name); |
225 |
|
226 |
/* Remove a NIO binding */ |
227 |
int c3600_nm_remove_nio_binding(c3600_t *router,u_int nm_bay,u_int port_id); |
228 |
|
229 |
/* Remove all NIO bindings for the specified NM */ |
230 |
int c3600_nm_remove_all_nio_bindings(c3600_t *router,u_int nm_bay); |
231 |
|
232 |
/* Enable a Network IO descriptor for a Network Module */ |
233 |
int c3600_nm_enable_nio(c3600_t *router,u_int nm_bay,u_int port_id); |
234 |
|
235 |
/* Disable Network IO descriptor of a Network Module */ |
236 |
int c3600_nm_disable_nio(c3600_t *router,u_int nm_bay,u_int port_id); |
237 |
|
238 |
/* Enable all NIO of the specified NM */ |
239 |
int c3600_nm_enable_all_nio(c3600_t *router,u_int nm_bay); |
240 |
|
241 |
/* Disable all NIO of the specified NM */ |
242 |
int c3600_nm_disable_all_nio(c3600_t *router,u_int nm_bay); |
243 |
|
244 |
/* Initialize a Network Module */ |
245 |
int c3600_nm_init(c3600_t *router,u_int nm_bay); |
246 |
|
247 |
/* Shutdown a Network Module */ |
248 |
int c3600_nm_shutdown(c3600_t *router,u_int nm_bay); |
249 |
|
250 |
/* Shutdown all NM of a router */ |
251 |
int c3600_nm_shutdown_all(c3600_t *router); |
252 |
|
253 |
/* Show info about all NMs */ |
254 |
int c3600_nm_show_all_info(c3600_t *router); |
255 |
|
256 |
/* Create a Network Module (command line) */ |
257 |
int c3600_cmd_nm_create(c3600_t *router,char *str); |
258 |
|
259 |
/* Add a Network IO descriptor binding (command line) */ |
260 |
int c3600_cmd_add_nio(c3600_t *router,char *str); |
261 |
|
262 |
/* Show the list of available NM drivers */ |
263 |
void c3600_nm_show_drivers(void); |
264 |
|
265 |
/* Set chassis MAC address */ |
266 |
int c3600_chassis_set_mac_addr(c3600_t *router,char *mac_addr); |
267 |
|
268 |
/* Set the chassis type */ |
269 |
int c3600_chassis_set_type(c3600_t *router,char *chassis_type); |
270 |
|
271 |
/* Get the chassis ID */ |
272 |
int c3600_chassis_get_id(c3600_t *router); |
273 |
|
274 |
/* Show the list of available chassis drivers */ |
275 |
void c3600_chassis_show_drivers(void); |
276 |
|
277 |
/* Show C3600 hardware info */ |
278 |
void c3600_show_hardware(c3600_t *router); |
279 |
|
280 |
/* Initialize default parameters for a C3600 */ |
281 |
void c3600_init_defaults(c3600_t *router); |
282 |
|
283 |
/* Initialize the C3600 Platform */ |
284 |
int c3600_init_platform(c3600_t *router); |
285 |
|
286 |
/* Initialize a Cisco 3600 instance */ |
287 |
int c3600_init_instance(c3600_t *router); |
288 |
|
289 |
/* Stop a Cisco 3600 instance */ |
290 |
int c3600_stop_instance(c3600_t *router); |
291 |
|
292 |
/* Initialize EEPROM groups */ |
293 |
void c3600_init_eeprom_groups(c3600_t *router); |
294 |
|
295 |
/* dev_c3600_iofpga_init() */ |
296 |
int dev_c3600_iofpga_init(c3600_t *router,m_uint64_t paddr,m_uint32_t len); |
297 |
|
298 |
/* NM drivers */ |
299 |
extern struct c3600_nm_driver dev_c3600_nm_1e_driver; |
300 |
extern struct c3600_nm_driver dev_c3600_nm_4e_driver; |
301 |
extern struct c3600_nm_driver dev_c3600_nm_1fe_tx_driver; |
302 |
extern struct c3600_nm_driver dev_c3600_nm_4t_driver; |
303 |
extern struct c3600_nm_driver dev_c3600_leopard_2fe_driver; |
304 |
extern struct c3600_nm_driver dev_c3600_nm_16esw_driver; |
305 |
|
306 |
#endif |