1 |
dpavlin |
4 |
/* |
2 |
|
|
* Cisco 3745 simulation platform. |
3 |
|
|
* Copyright (c) 2006 Christophe Fillot (cf@utc.fr) |
4 |
|
|
* |
5 |
|
|
* Generic Cisco 3745 routines and definitions (EEPROM,...). |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
#ifndef __DEV_C3745_H__ |
9 |
|
|
#define __DEV_C3745_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 C3745 parameters */ |
22 |
|
|
#define C3745_DEFAULT_RAM_SIZE 128 |
23 |
|
|
#define C3745_DEFAULT_ROM_SIZE 2 |
24 |
|
|
#define C3745_DEFAULT_NVRAM_SIZE 128 |
25 |
|
|
#define C3745_DEFAULT_CONF_REG 0x2102 |
26 |
|
|
#define C3745_DEFAULT_CLOCK_DIV 8 |
27 |
|
|
#define C3745_DEFAULT_RAM_MMAP 1 |
28 |
|
|
#define C3745_DEFAULT_DISK0_SIZE 16 |
29 |
|
|
#define C3745_DEFAULT_DISK1_SIZE 0 |
30 |
|
|
#define C3745_DEFAULT_IOMEM_SIZE 5 /* Percents! */ |
31 |
|
|
|
32 |
|
|
/* 3745 characteritics: 2 NM, 3 WIC, 2 AIM */ |
33 |
|
|
#define C3745_MAX_NM_BAYS 5 |
34 |
|
|
|
35 |
|
|
/* C3745 DUART Interrupt */ |
36 |
|
|
#define C3745_DUART_IRQ 5 |
37 |
|
|
|
38 |
|
|
/* C3745 Network I/O Interrupt */ |
39 |
|
|
#define C3745_NETIO_IRQ 2 |
40 |
|
|
|
41 |
|
|
/* C3745 GT64k DMA/Timer Interrupt */ |
42 |
|
|
#define C3745_GT96K_IRQ 3 |
43 |
|
|
|
44 |
|
|
/* C3745 External Interrupt */ |
45 |
|
|
#define C3745_EXT_IRQ 6 |
46 |
|
|
|
47 |
|
|
/* C3745 common device addresses */ |
48 |
|
|
#define C3745_GT96K_ADDR 0x24000000ULL |
49 |
|
|
#define C3745_IOFPGA_ADDR 0x1fa00000ULL |
50 |
|
|
#define C3745_DUART_ADDR 0x3c100000ULL |
51 |
|
|
#define C3745_BITBUCKET_ADDR 0x1ec00000ULL |
52 |
|
|
#define C3745_ROM_ADDR 0x1fc00000ULL |
53 |
|
|
#define C3745_SLOT0_ADDR 0x30000000ULL |
54 |
|
|
#define C3745_SLOT1_ADDR 0x32000000ULL |
55 |
|
|
#define C3745_PCI_IO_ADDR 0x100000000ULL |
56 |
|
|
|
57 |
|
|
/* Offset of simulated NVRAM in ROM flash */ |
58 |
|
|
#define C3745_NVRAM_OFFSET 0xB0000 |
59 |
|
|
#define C3745_NVRAM_SIZE 0x20000 |
60 |
|
|
|
61 |
|
|
/* Reserved space for ROM in NVRAM */ |
62 |
|
|
#define C3745_NVRAM_ROM_RES_SIZE 2048 |
63 |
|
|
|
64 |
|
|
/* C3745 ELF Platform ID */ |
65 |
|
|
#define C3745_ELF_MACHINE_ID 0xFF /* ??? */ |
66 |
|
|
|
67 |
|
|
/* C3745 router */ |
68 |
|
|
typedef struct c3745_router c3745_t; |
69 |
|
|
|
70 |
|
|
/* Prototype of NM driver initialization function */ |
71 |
|
|
typedef int (*c3745_nm_init_fn)(c3745_t *router,char *name,u_int nm_bay); |
72 |
|
|
|
73 |
|
|
/* Prototype of NM driver shutdown function */ |
74 |
|
|
typedef int (*c3745_nm_shutdown_fn)(c3745_t *router,u_int nm_bay); |
75 |
|
|
|
76 |
|
|
/* Prototype of NM NIO set function */ |
77 |
|
|
typedef int (*c3745_nm_set_nio_fn)(c3745_t *router,u_int nm_bay,u_int port_id, |
78 |
|
|
netio_desc_t *nio); |
79 |
|
|
|
80 |
|
|
/* Prototype of NM NIO unset function */ |
81 |
|
|
typedef int (*c3745_nm_unset_nio_fn)(c3745_t *router,u_int nm_bay, |
82 |
|
|
u_int port_id); |
83 |
|
|
|
84 |
|
|
/* Prototype of NM NIO show info function */ |
85 |
|
|
typedef int (*c3745_nm_show_info_fn)(c3745_t *router,u_int nm_bay); |
86 |
|
|
|
87 |
|
|
/* C3745 Network Module Driver */ |
88 |
|
|
struct c3745_nm_driver { |
89 |
|
|
char *dev_type; |
90 |
|
|
int supported; |
91 |
|
|
int wic_slots; |
92 |
|
|
c3745_nm_init_fn nm_init; |
93 |
|
|
c3745_nm_shutdown_fn nm_shutdown; |
94 |
|
|
c3745_nm_set_nio_fn nm_set_nio; |
95 |
|
|
c3745_nm_unset_nio_fn nm_unset_nio; |
96 |
|
|
c3745_nm_show_info_fn nm_show_info; |
97 |
|
|
|
98 |
|
|
/* TODO: WAN Interface Cards (WIC) */ |
99 |
|
|
}; |
100 |
|
|
|
101 |
|
|
/* C3745 NIO binding to a slot/port */ |
102 |
|
|
struct c3745_nio_binding { |
103 |
|
|
netio_desc_t *nio; |
104 |
|
|
u_int port_id; |
105 |
|
|
struct c3745_nio_binding *prev,*next; |
106 |
|
|
}; |
107 |
|
|
|
108 |
|
|
/* C3745 NM bay */ |
109 |
|
|
struct c3745_nm_bay { |
110 |
|
|
char *dev_name; /* Device name */ |
111 |
|
|
char *dev_type; /* Device Type */ |
112 |
|
|
struct cisco_eeprom eeprom; /* NM EEPROM */ |
113 |
|
|
struct pci_bus *pci_map; /* PCI bus */ |
114 |
|
|
struct c3745_nm_driver *nm_driver; /* NM Driver */ |
115 |
|
|
void *drv_info; /* Private driver info */ |
116 |
|
|
struct c3745_nio_binding *nio_list; /* NIO bindings to ports */ |
117 |
|
|
}; |
118 |
|
|
|
119 |
|
|
/* C3745 router */ |
120 |
|
|
struct c3745_router { |
121 |
|
|
/* Chassis MAC address */ |
122 |
|
|
n_eth_addr_t mac_addr; |
123 |
|
|
|
124 |
|
|
/* Associated VM instance */ |
125 |
|
|
vm_instance_t *vm; |
126 |
|
|
|
127 |
|
|
/* IO memory size to be passed to Smart Init */ |
128 |
|
|
u_int nm_iomem_size; |
129 |
|
|
|
130 |
|
|
/* Chassis information */ |
131 |
|
|
struct c3745_nm_bay nm_bay[C3745_MAX_NM_BAYS]; |
132 |
|
|
m_uint8_t oir_status; |
133 |
|
|
|
134 |
|
|
/* |
135 |
|
|
* System EEPROMs. |
136 |
|
|
* It can be modified to change the chassis MAC address. |
137 |
|
|
*/ |
138 |
|
|
struct cisco_eeprom sys_eeprom[3]; |
139 |
|
|
struct nmc93c46_group sys_eeprom_group; |
140 |
|
|
|
141 |
|
|
/* Network Module EEPROMs */ |
142 |
|
|
struct nmc93c46_group nm_eeprom_group[4]; |
143 |
|
|
}; |
144 |
|
|
|
145 |
|
|
/* Create a new router instance */ |
146 |
|
|
c3745_t *c3745_create_instance(char *name,int instance_id); |
147 |
|
|
|
148 |
|
|
/* Delete a router instance */ |
149 |
|
|
int c3745_delete_instance(char *name); |
150 |
|
|
|
151 |
|
|
/* Delete all router instances */ |
152 |
|
|
int c3745_delete_all_instances(void); |
153 |
|
|
|
154 |
|
|
/* Save configuration of a C3745 instance */ |
155 |
|
|
void c3745_save_config(c3745_t *router,FILE *fd); |
156 |
|
|
|
157 |
|
|
/* Save configurations of all C3745 instances */ |
158 |
|
|
void c3745_save_config_all(FILE *fd); |
159 |
|
|
|
160 |
|
|
/* Set NM EEPROM definition */ |
161 |
|
|
int c3745_nm_set_eeprom(c3745_t *router,u_int nm_bay, |
162 |
|
|
const struct cisco_eeprom *eeprom); |
163 |
|
|
|
164 |
|
|
/* Unset NM EEPROM definition (empty bay) */ |
165 |
|
|
int c3745_nm_unset_eeprom(c3745_t *router,u_int nm_bay); |
166 |
|
|
|
167 |
|
|
/* Check if a bay has a Network Module */ |
168 |
|
|
int c3745_nm_check_eeprom(c3745_t *router,u_int nm_bay); |
169 |
|
|
|
170 |
|
|
/* Get bay info */ |
171 |
|
|
struct c3745_nm_bay *c3745_nm_get_info(c3745_t *router,u_int nm_bay); |
172 |
|
|
|
173 |
|
|
/* Get NM type */ |
174 |
|
|
char *c3745_nm_get_type(c3745_t *router,u_int nm_bay); |
175 |
|
|
|
176 |
|
|
/* Get driver info about the specified slot */ |
177 |
|
|
void *c3745_nm_get_drvinfo(c3745_t *router,u_int nm_bay); |
178 |
|
|
|
179 |
|
|
/* Set driver info for the specified slot */ |
180 |
|
|
int c3745_nm_set_drvinfo(c3745_t *router,u_int nm_bay,void *drv_info); |
181 |
|
|
|
182 |
|
|
/* Add a NM binding */ |
183 |
|
|
int c3745_nm_add_binding(c3745_t *router,char *dev_type,u_int nm_bay); |
184 |
|
|
|
185 |
|
|
/* Remove a NM binding */ |
186 |
|
|
int c3745_nm_remove_binding(c3745_t *router,u_int nm_bay); |
187 |
|
|
|
188 |
|
|
/* Find a NIO binding */ |
189 |
|
|
struct c3745_nio_binding * |
190 |
|
|
c3745_nm_find_nio_binding(c3745_t *router,u_int nm_bay,u_int port_id); |
191 |
|
|
|
192 |
|
|
/* Add a network IO binding */ |
193 |
|
|
int c3745_nm_add_nio_binding(c3745_t *router,u_int nm_bay,u_int port_id, |
194 |
|
|
char *nio_name); |
195 |
|
|
|
196 |
|
|
/* Remove a NIO binding */ |
197 |
|
|
int c3745_nm_remove_nio_binding(c3745_t *router,u_int nm_bay,u_int port_id); |
198 |
|
|
|
199 |
|
|
/* Remove all NIO bindings for the specified NM */ |
200 |
|
|
int c3745_nm_remove_all_nio_bindings(c3745_t *router,u_int nm_bay); |
201 |
|
|
|
202 |
|
|
/* Enable a Network IO descriptor for a Network Module */ |
203 |
|
|
int c3745_nm_enable_nio(c3745_t *router,u_int nm_bay,u_int port_id); |
204 |
|
|
|
205 |
|
|
/* Disable Network IO descriptor of a Network Module */ |
206 |
|
|
int c3745_nm_disable_nio(c3745_t *router,u_int nm_bay,u_int port_id); |
207 |
|
|
|
208 |
|
|
/* Enable all NIO of the specified NM */ |
209 |
|
|
int c3745_nm_enable_all_nio(c3745_t *router,u_int nm_bay); |
210 |
|
|
|
211 |
|
|
/* Disable all NIO of the specified NM */ |
212 |
|
|
int c3745_nm_disable_all_nio(c3745_t *router,u_int nm_bay); |
213 |
|
|
|
214 |
|
|
/* Initialize a Network Module */ |
215 |
|
|
int c3745_nm_init(c3745_t *router,u_int nm_bay); |
216 |
|
|
|
217 |
|
|
/* Shutdown a Network Module */ |
218 |
|
|
int c3745_nm_shutdown(c3745_t *router,u_int nm_bay); |
219 |
|
|
|
220 |
|
|
/* Shutdown all NM of a router */ |
221 |
|
|
int c3745_nm_shutdown_all(c3745_t *router); |
222 |
|
|
|
223 |
|
|
/* Show info about all NMs */ |
224 |
|
|
int c3745_nm_show_all_info(c3745_t *router); |
225 |
|
|
|
226 |
|
|
/* Create a Network Module (command line) */ |
227 |
|
|
int c3745_cmd_nm_create(c3745_t *router,char *str); |
228 |
|
|
|
229 |
|
|
/* Add a Network IO descriptor binding (command line) */ |
230 |
|
|
int c3745_cmd_add_nio(c3745_t *router,char *str); |
231 |
|
|
|
232 |
|
|
/* Show the list of available NM drivers */ |
233 |
|
|
void c3745_nm_show_drivers(void); |
234 |
|
|
|
235 |
|
|
/* Set chassis MAC address */ |
236 |
|
|
int c3745_chassis_set_mac_addr(c3745_t *router,char *mac_addr); |
237 |
|
|
|
238 |
|
|
/* Show C3745 hardware info */ |
239 |
|
|
void c3745_show_hardware(c3745_t *router); |
240 |
|
|
|
241 |
|
|
/* Initialize default parameters for a C3745 */ |
242 |
|
|
void c3745_init_defaults(c3745_t *router); |
243 |
|
|
|
244 |
|
|
/* Initialize the C3745 Platform */ |
245 |
|
|
int c3745_init_platform(c3745_t *router); |
246 |
|
|
|
247 |
|
|
/* Initialize a Cisco 3745 instance */ |
248 |
|
|
int c3745_init_instance(c3745_t *router); |
249 |
|
|
|
250 |
|
|
/* Stop a Cisco 3745 instance */ |
251 |
|
|
int c3745_stop_instance(c3745_t *router); |
252 |
|
|
|
253 |
|
|
/* Initialize EEPROM groups */ |
254 |
|
|
void c3745_init_eeprom_groups(c3745_t *router); |
255 |
|
|
|
256 |
|
|
/* dev_c3745_iofpga_init() */ |
257 |
|
|
int dev_c3745_iofpga_init(c3745_t *router,m_uint64_t paddr,m_uint32_t len); |
258 |
|
|
|
259 |
|
|
/* NM drivers */ |
260 |
|
|
extern struct c3745_nm_driver dev_c3745_nm_1fe_tx_driver; |
261 |
|
|
extern struct c3745_nm_driver dev_c3745_gt96100_fe_driver; |
262 |
|
|
extern struct c3745_nm_driver dev_c3745_nm_4t_driver; |
263 |
|
|
extern struct c3745_nm_driver dev_c3745_nm_16esw_driver; |
264 |
|
|
|
265 |
|
|
#endif |