/[dynamips]/trunk/dev_c3745_eth.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/dev_c3745_eth.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (show annotations)
Sat Oct 6 16:45:40 2007 UTC (12 years ago) by dpavlin
File MIME type: text/plain
File size: 8431 byte(s)
make working copy

1 /*
2 * Cisco C3745 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_c3745.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_c3745_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_c3745_mb_wic_drivers;
43 *subcard_type = CISCO_CARD_TYPE_WIC;
44 return(0);
45 }
46
47 /*
48 * dev_c3745_nm_eth_init()
49 *
50 * Add an Ethernet Network Module into specified slot.
51 */
52 static int dev_c3745_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 c3745_set_slot_eeprom(VM_C3745(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,0,
80 c3745_net_irq_for_slot_port(slot,0));
81 }
82
83 /* Store device info into the router structure */
84 card->drv_info = data;
85 return(0);
86 }
87
88 /* Remove an Ethernet NM from the specified slot */
89 static int dev_c3745_nm_eth_shutdown(vm_instance_t *vm,struct cisco_card *card)
90 {
91 struct nm_eth_data *data = card->drv_info;
92 int i;
93
94 /* Remove the NM EEPROM */
95 cisco_card_unset_eeprom(card);
96 c3745_set_slot_eeprom(VM_C3745(vm),card->slot_id,NULL);
97
98 /* Remove the AMD Am79c971 chips */
99 for(i=0;i<data->nr_port;i++)
100 dev_am79c971_remove(data->port[i]);
101
102 free(data);
103 return(0);
104 }
105
106 /* Bind a Network IO descriptor */
107 static int dev_c3745_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_c3745_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_c3745_nm_1fe_tx_init()
139 *
140 * Add a NM-1FE-TX Network Module into specified slot.
141 */
142 static int dev_c3745_nm_1fe_tx_init(vm_instance_t *vm,struct cisco_card *card)
143 {
144 return(dev_c3745_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_c3745_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 c3745_set_slot_eeprom(VM_C3745(vm),slot,&card->eeprom);
165
166 /* Create the device */
167 data = dev_nm_16esw_init(vm,card->dev_name,slot,card->pci_bus,0,
168 c3745_net_irq_for_slot_port(slot,0));
169
170 /* Store device info into the router structure */
171 card->drv_info = data;
172 return(0);
173 }
174
175 /* Remove a NM-16ESW from the specified slot */
176 static int
177 dev_c3745_nm_16esw_shutdown(vm_instance_t *vm,struct cisco_card *card)
178 {
179 struct nm_16esw_data *data = card->drv_info;
180
181 /* Remove the NM EEPROM */
182 cisco_card_unset_eeprom(card);
183 c3745_set_slot_eeprom(VM_C3745(vm),card->slot_id,NULL);
184
185 /* Remove the BCM5600 chip */
186 dev_nm_16esw_remove(data);
187 return(0);
188 }
189
190 /* Bind a Network IO descriptor */
191 static int
192 dev_c3745_nm_16esw_set_nio(vm_instance_t *vm,struct cisco_card *card,
193 u_int port_id,netio_desc_t *nio)
194 {
195 struct nm_16esw_data *d = card->drv_info;
196 dev_nm_16esw_set_nio(d,port_id,nio);
197 return(0);
198 }
199
200 /* Unbind a Network IO descriptor */
201 static int dev_c3745_nm_16esw_unset_nio(vm_instance_t *vm,
202 struct cisco_card *card,
203 u_int port_id)
204 {
205 struct nm_16esw_data *d = card->drv_info;
206 dev_nm_16esw_unset_nio(d,port_id);
207 return(0);
208 }
209
210 /* Show debug info */
211 static int
212 dev_c3745_nm_16esw_show_info(vm_instance_t *vm,struct cisco_card *card)
213 {
214 struct nm_16esw_data *d = card->drv_info;
215 dev_nm_16esw_show_info(d);
216 return(0);
217 }
218
219 /* ====================================================================== */
220 /* GT96100 - Integrated Ethernet ports */
221 /* ====================================================================== */
222
223 /* Initialize Ethernet part of the GT96100 controller */
224 static int dev_c3745_gt96100_fe_init(vm_instance_t *vm,struct cisco_card *card)
225 {
226 if (card->slot_id != 0) {
227 vm_error(vm,"dev_c3745_gt96100_fe_init: bad slot %u specified.\n",
228 card->slot_id);
229 return(-1);
230 }
231
232 /* Store device info into the router structure */
233 card->drv_info = VM_C3745(vm)->gt_data;
234 return(0);
235 }
236
237 /* Nothing to do, we never remove the system controller */
238 static int
239 dev_c3745_gt96100_fe_shutdown(vm_instance_t *vm,struct cisco_card *card)
240 {
241 return(0);
242 }
243
244 /* Bind a Network IO descriptor */
245 static int
246 dev_c3745_gt96100_fe_set_nio(vm_instance_t *vm,struct cisco_card *card,
247 u_int port_id,netio_desc_t *nio)
248 {
249 struct gt_data *d = card->drv_info;
250 dev_gt96100_eth_set_nio(d,port_id,nio);
251 return(0);
252 }
253
254 /* Unbind a Network IO descriptor */
255 static int dev_c3745_gt96100_fe_unset_nio(vm_instance_t *vm,
256 struct cisco_card *card,
257 u_int port_id)
258 {
259 struct gt_data *d = card->drv_info;
260 dev_gt96100_eth_unset_nio(d,port_id);
261 return(0);
262 }
263
264 /* ====================================================================== */
265
266 /* NM-1FE-TX driver */
267 struct cisco_card_driver dev_c3745_nm_1fe_tx_driver = {
268 "NM-1FE-TX", 1, 0,
269 dev_c3745_nm_1fe_tx_init,
270 dev_c3745_nm_eth_shutdown,
271 NULL,
272 dev_c3745_nm_eth_set_nio,
273 dev_c3745_nm_eth_unset_nio,
274 NULL,
275 };
276
277 /* NM-16ESW driver */
278 struct cisco_card_driver dev_c3745_nm_16esw_driver = {
279 "NM-16ESW", 1, 0,
280 dev_c3745_nm_16esw_init,
281 dev_c3745_nm_16esw_shutdown,
282 NULL,
283 dev_c3745_nm_16esw_set_nio,
284 dev_c3745_nm_16esw_unset_nio,
285 dev_c3745_nm_16esw_show_info,
286 };
287
288 /* GT96100 FastEthernet integrated ports */
289 struct cisco_card_driver dev_c3745_gt96100_fe_driver = {
290 "GT96100-FE", 1, 0,
291 dev_c3745_gt96100_fe_init,
292 dev_c3745_gt96100_fe_shutdown,
293 dev_c3745_mb_get_sub_info,
294 dev_c3745_gt96100_fe_set_nio,
295 dev_c3745_gt96100_fe_unset_nio,
296 NULL,
297 };

  ViewVC Help
Powered by ViewVC 1.1.26