1 |
/* |
2 |
* Cisco C3725 simulation platform. |
3 |
* Copyright (c) 2006 Christophe Fillot (cf@utc.fr) |
4 |
* |
5 |
* Ethernet 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_am79c971.h" |
22 |
#include "dev_nm_16esw.h" |
23 |
#include "dev_gt.h" |
24 |
#include "dev_c3725.h" |
25 |
|
26 |
/* Multi-Ethernet NM with Am79c971 chips */ |
27 |
struct nm_eth_data { |
28 |
u_int nr_port; |
29 |
struct am79c971_data *port[8]; |
30 |
}; |
31 |
|
32 |
/* Return sub-slot info for integrated WIC slots (on motherboard) */ |
33 |
static int dev_c3725_mb_get_sub_info(vm_instance_t *vm,struct cisco_card *card, |
34 |
u_int port_id, |
35 |
struct cisco_card_driver ***drv_array, |
36 |
u_int *subcard_type) |
37 |
{ |
38 |
/* 3 integrated WIC slots */ |
39 |
if ((port_id & 0x0F) >= 3) |
40 |
return(-1); |
41 |
|
42 |
*drv_array = dev_c3725_mb_wic_drivers; |
43 |
*subcard_type = CISCO_CARD_TYPE_WIC; |
44 |
return(0); |
45 |
} |
46 |
|
47 |
/* |
48 |
* dev_c3725_nm_eth_init() |
49 |
* |
50 |
* Add an Ethernet Network Module into specified slot. |
51 |
*/ |
52 |
static int dev_c3725_nm_eth_init(vm_instance_t *vm,struct cisco_card *card, |
53 |
int nr_port,int interface_type, |
54 |
const struct cisco_eeprom *eeprom) |
55 |
{ |
56 |
struct nm_eth_data *data; |
57 |
u_int slot = card->slot_id; |
58 |
int i; |
59 |
|
60 |
/* Allocate the private data structure */ |
61 |
if (!(data = malloc(sizeof(*data)))) { |
62 |
vm_error(vm,"%s: out of memory.\n",card->dev_name); |
63 |
return(-1); |
64 |
} |
65 |
|
66 |
memset(data,0,sizeof(*data)); |
67 |
data->nr_port = nr_port; |
68 |
|
69 |
/* Set the PCI bus */ |
70 |
card->pci_bus = vm->slots_pci_bus[slot]; |
71 |
|
72 |
/* Set the EEPROM */ |
73 |
cisco_card_set_eeprom(vm,card,eeprom); |
74 |
c3725_set_slot_eeprom(VM_C3725(vm),slot,&card->eeprom); |
75 |
|
76 |
/* Create the AMD Am971c971 chip(s) */ |
77 |
for(i=0;i<data->nr_port;i++) { |
78 |
data->port[i] = dev_am79c971_init(vm,card->dev_name,interface_type, |
79 |
card->pci_bus, |
80 |
c3725_nm_get_pci_device(slot), |
81 |
c3725_net_irq_for_slot_port(slot,i)); |
82 |
} |
83 |
|
84 |
/* Store device info into the router structure */ |
85 |
card->drv_info = data; |
86 |
return(0); |
87 |
} |
88 |
|
89 |
/* Remove an Ethernet NM from the specified slot */ |
90 |
static int dev_c3725_nm_eth_shutdown(vm_instance_t *vm,struct cisco_card *card) |
91 |
{ |
92 |
struct nm_eth_data *data = card->drv_info; |
93 |
int i; |
94 |
|
95 |
/* Remove the NM EEPROM */ |
96 |
cisco_card_unset_eeprom(card); |
97 |
c3725_set_slot_eeprom(VM_C3725(vm),card->slot_id,NULL); |
98 |
|
99 |
/* Remove the AMD Am79c971 chips */ |
100 |
for(i=0;i<data->nr_port;i++) |
101 |
dev_am79c971_remove(data->port[i]); |
102 |
|
103 |
free(data); |
104 |
return(0); |
105 |
} |
106 |
|
107 |
static int dev_c3725_nm_eth_set_nio(vm_instance_t *vm,struct cisco_card *card, |
108 |
u_int port_id,netio_desc_t *nio) |
109 |
{ |
110 |
struct nm_eth_data *d = card->drv_info; |
111 |
|
112 |
if (!d || (port_id >= d->nr_port)) |
113 |
return(-1); |
114 |
|
115 |
dev_am79c971_set_nio(d->port[port_id],nio); |
116 |
return(0); |
117 |
} |
118 |
|
119 |
/* Unbind a Network IO descriptor */ |
120 |
static int dev_c3725_nm_eth_unset_nio(vm_instance_t *vm, |
121 |
struct cisco_card *card, |
122 |
u_int port_id) |
123 |
{ |
124 |
struct nm_eth_data *d = card->drv_info; |
125 |
|
126 |
if (!d || (port_id >= d->nr_port)) |
127 |
return(-1); |
128 |
|
129 |
dev_am79c971_unset_nio(d->port[port_id]); |
130 |
return(0); |
131 |
} |
132 |
|
133 |
/* ====================================================================== */ |
134 |
/* NM-1FE-TX */ |
135 |
/* ====================================================================== */ |
136 |
|
137 |
/* |
138 |
* dev_c3725_nm_1fe_tx_init() |
139 |
* |
140 |
* Add a NM-1FE-TX Network Module into specified slot. |
141 |
*/ |
142 |
static int dev_c3725_nm_1fe_tx_init(vm_instance_t *vm,struct cisco_card *card) |
143 |
{ |
144 |
return(dev_c3725_nm_eth_init(vm,card,1,AM79C971_TYPE_100BASE_TX, |
145 |
cisco_eeprom_find_nm("NM-1FE-TX"))); |
146 |
} |
147 |
|
148 |
/* ====================================================================== */ |
149 |
/* NM-16ESW */ |
150 |
/* ====================================================================== */ |
151 |
|
152 |
/* Add a NM-16ESW */ |
153 |
static int dev_c3725_nm_16esw_init(vm_instance_t *vm,struct cisco_card *card) |
154 |
{ |
155 |
struct nm_16esw_data *data; |
156 |
u_int slot = card->slot_id; |
157 |
|
158 |
/* Set the PCI bus */ |
159 |
card->pci_bus = vm->slots_pci_bus[slot]; |
160 |
|
161 |
/* Set the EEPROM */ |
162 |
cisco_card_set_eeprom(vm,card,cisco_eeprom_find_nm("NM-16ESW")); |
163 |
dev_nm_16esw_burn_mac_addr(vm,slot,&card->eeprom); |
164 |
c3725_set_slot_eeprom(VM_C3725(vm),slot,&card->eeprom); |
165 |
|
166 |
/* Create the device */ |
167 |
data = dev_nm_16esw_init(vm,card->dev_name,slot, |
168 |
card->pci_bus,c3725_nm_get_pci_device(slot), |
169 |
c3725_net_irq_for_slot_port(slot,0)); |
170 |
|
171 |
/* Store device info into the router structure */ |
172 |
card->drv_info = data; |
173 |
return(0); |
174 |
} |
175 |
|
176 |
/* Remove a NM-16ESW from the specified slot */ |
177 |
static int |
178 |
dev_c3725_nm_16esw_shutdown(vm_instance_t *vm,struct cisco_card *card) |
179 |
{ |
180 |
struct nm_16esw_data *data = card->drv_info; |
181 |
|
182 |
/* Remove the NM EEPROM */ |
183 |
cisco_card_unset_eeprom(card); |
184 |
c3725_set_slot_eeprom(VM_C3725(vm),card->slot_id,NULL); |
185 |
|
186 |
/* Remove the BCM5600 chip */ |
187 |
dev_nm_16esw_remove(data); |
188 |
return(0); |
189 |
} |
190 |
|
191 |
/* Bind a Network IO descriptor */ |
192 |
static int |
193 |
dev_c3725_nm_16esw_set_nio(vm_instance_t *vm,struct cisco_card *card, |
194 |
u_int port_id,netio_desc_t *nio) |
195 |
{ |
196 |
struct nm_16esw_data *d = card->drv_info; |
197 |
dev_nm_16esw_set_nio(d,port_id,nio); |
198 |
return(0); |
199 |
} |
200 |
|
201 |
/* Unbind a Network IO descriptor */ |
202 |
static int dev_c3725_nm_16esw_unset_nio(vm_instance_t *vm, |
203 |
struct cisco_card *card, |
204 |
u_int port_id) |
205 |
{ |
206 |
struct nm_16esw_data *d = card->drv_info; |
207 |
dev_nm_16esw_unset_nio(d,port_id); |
208 |
return(0); |
209 |
} |
210 |
|
211 |
/* Show debug info */ |
212 |
static int |
213 |
dev_c3725_nm_16esw_show_info(vm_instance_t *vm,struct cisco_card *card) |
214 |
{ |
215 |
struct nm_16esw_data *d = card->drv_info; |
216 |
dev_nm_16esw_show_info(d); |
217 |
return(0); |
218 |
} |
219 |
|
220 |
|
221 |
/* ====================================================================== */ |
222 |
/* GT96100 - Integrated Ethernet ports */ |
223 |
/* ====================================================================== */ |
224 |
|
225 |
/* Initialize Ethernet part of the GT96100 controller */ |
226 |
static int dev_c3725_gt96100_fe_init(vm_instance_t *vm,struct cisco_card *card) |
227 |
{ |
228 |
if (card->slot_id != 0) { |
229 |
vm_error(vm,"dev_c3725_gt96100_fe_init: bad slot %u specified.\n", |
230 |
card->slot_id); |
231 |
return(-1); |
232 |
} |
233 |
|
234 |
/* Store device info into the router structure */ |
235 |
card->drv_info = VM_C3725(vm)->gt_data; |
236 |
return(0); |
237 |
} |
238 |
|
239 |
/* Nothing to do, we never remove the system controller */ |
240 |
static int |
241 |
dev_c3725_gt96100_fe_shutdown(vm_instance_t *vm,struct cisco_card *card) |
242 |
{ |
243 |
return(0); |
244 |
} |
245 |
|
246 |
/* Bind a Network IO descriptor */ |
247 |
static int |
248 |
dev_c3725_gt96100_fe_set_nio(vm_instance_t *vm,struct cisco_card *card, |
249 |
u_int port_id,netio_desc_t *nio) |
250 |
{ |
251 |
struct gt_data *d = card->drv_info; |
252 |
dev_gt96100_eth_set_nio(d,port_id,nio); |
253 |
return(0); |
254 |
} |
255 |
|
256 |
/* Unbind a Network IO descriptor */ |
257 |
static int dev_c3725_gt96100_fe_unset_nio(vm_instance_t *vm, |
258 |
struct cisco_card *card, |
259 |
u_int port_id) |
260 |
{ |
261 |
struct gt_data *d = card->drv_info; |
262 |
dev_gt96100_eth_unset_nio(d,port_id); |
263 |
return(0); |
264 |
} |
265 |
|
266 |
/* Show debug info */ |
267 |
static int |
268 |
dev_c3725_gt96100_show_info(vm_instance_t *vm,struct cisco_card *card) |
269 |
{ |
270 |
struct gt_data *d = card->drv_info; |
271 |
dev_gt96100_show_info(d); |
272 |
return(0); |
273 |
} |
274 |
|
275 |
/* ====================================================================== */ |
276 |
|
277 |
/* NM-1FE-TX driver */ |
278 |
struct cisco_card_driver dev_c3725_nm_1fe_tx_driver = { |
279 |
"NM-1FE-TX", 1, 0, |
280 |
dev_c3725_nm_1fe_tx_init, |
281 |
dev_c3725_nm_eth_shutdown, |
282 |
NULL, |
283 |
dev_c3725_nm_eth_set_nio, |
284 |
dev_c3725_nm_eth_unset_nio, |
285 |
NULL, |
286 |
}; |
287 |
|
288 |
/* NM-16ESW driver */ |
289 |
struct cisco_card_driver dev_c3725_nm_16esw_driver = { |
290 |
"NM-16ESW", 1, 0, |
291 |
dev_c3725_nm_16esw_init, |
292 |
dev_c3725_nm_16esw_shutdown, |
293 |
NULL, |
294 |
dev_c3725_nm_16esw_set_nio, |
295 |
dev_c3725_nm_16esw_unset_nio, |
296 |
dev_c3725_nm_16esw_show_info, |
297 |
}; |
298 |
|
299 |
/* GT96100 FastEthernet integrated ports */ |
300 |
struct cisco_card_driver dev_c3725_gt96100_fe_driver = { |
301 |
"GT96100-FE", 1, 0, |
302 |
dev_c3725_gt96100_fe_init, |
303 |
dev_c3725_gt96100_fe_shutdown, |
304 |
dev_c3725_mb_get_sub_info, |
305 |
dev_c3725_gt96100_fe_set_nio, |
306 |
dev_c3725_gt96100_fe_unset_nio, |
307 |
dev_c3725_gt96100_show_info, |
308 |
}; |