/[dynamips]/trunk/dev_c3600_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_c3600_eth.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Sat Oct 6 16:01:44 2007 UTC (16 years, 5 months ago) by dpavlin
Original Path: upstream/dynamips-0.2.5/dev_c3600_eth.c
File MIME type: text/plain
File size: 8508 byte(s)
import 0.2.5 from upstream

1 /*
2 * Cisco C3600 (Predator) 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_c3600.h"
23 #include "dev_c3600_bay.h"
24
25 /* Multi-Ethernet NM with Am79c971 chips */
26 struct nm_eth_data {
27 u_int nr_port;
28 struct am79c971_data *port[8];
29 };
30
31 /*
32 * dev_c3600_nm_eth_init()
33 *
34 * Add an Ethernet Network Module into specified slot.
35 */
36 static int dev_c3600_nm_eth_init(c3600_t *router,char *name,u_int nm_bay,
37 int nr_port,int interface_type,
38 const struct c3600_eeprom *eeprom)
39 {
40 struct nm_bay_info *bay_info;
41 struct nm_eth_data *data;
42 int i;
43
44 /* Allocate the private data structure */
45 if (!(data = malloc(sizeof(*data)))) {
46 fprintf(stderr,"%s: out of memory\n",name);
47 return(-1);
48 }
49
50 memset(data,0,sizeof(*data));
51 data->nr_port = nr_port;
52
53 /* Set the EEPROM */
54 c3600_nm_set_eeprom(router,nm_bay,eeprom);
55
56 /* Get PCI bus info about this bay */
57 bay_info = c3600_nm_get_bay_info(c3600_chassis_get_id(router),nm_bay);
58
59 if (!bay_info) {
60 fprintf(stderr,"%s: unable to get info for NM bay %u\n",name,nm_bay);
61 return(-1);
62 }
63
64 /* Create the AMD Am971c971 chip(s) */
65 for(i=0;i<data->nr_port;i++) {
66 data->port[i] = dev_am79c971_init(router->vm,name,interface_type,
67 router->nm_bay[nm_bay].pci_map,
68 bay_info->pci_device + i,
69 C3600_NETIO_IRQ);
70 }
71
72 /* Store device info into the router structure */
73 return(c3600_nm_set_drvinfo(router,nm_bay,data));
74 }
75
76 /* Remove an Ethernet NM from the specified slot */
77 static int dev_c3600_nm_eth_shutdown(c3600_t *router,u_int nm_bay)
78 {
79 struct c3600_nm_bay *bay;
80 struct nm_eth_data *data;
81 int i;
82
83 if (!(bay = c3600_nm_get_info(router,nm_bay)))
84 return(-1);
85
86 data = bay->drv_info;
87
88 /* Remove the NM EEPROM */
89 c3600_nm_unset_eeprom(router,nm_bay);
90
91 /* Remove the AMD Am79c971 chips */
92 for(i=0;i<data->nr_port;i++)
93 dev_am79c971_remove(data->port[i]);
94
95 free(data);
96 return(0);
97 }
98
99 /* Bind a Network IO descriptor */
100 static int dev_c3600_nm_eth_set_nio(c3600_t *router,u_int nm_bay,
101 u_int port_id,netio_desc_t *nio)
102 {
103 struct nm_eth_data *d;
104
105 d = c3600_nm_get_drvinfo(router,nm_bay);
106
107 if (!d || (port_id >= d->nr_port))
108 return(-1);
109
110 dev_am79c971_set_nio(d->port[port_id],nio);
111 return(0);
112 }
113
114 /* Unbind a Network IO descriptor */
115 static int dev_c3600_nm_eth_unset_nio(c3600_t *router,u_int nm_bay,
116 u_int port_id)
117 {
118 struct nm_eth_data *d;
119
120 d = c3600_nm_get_drvinfo(router,nm_bay);
121
122 if (!d || (port_id >= d->nr_port))
123 return(-1);
124
125 dev_am79c971_unset_nio(d->port[port_id]);
126 return(0);
127 }
128
129 /* ====================================================================== */
130 /* NM-1E */
131 /* ====================================================================== */
132
133 /* NM-1E: 1 Ethernet Network Module EEPROM */
134 static const m_uint16_t eeprom_c3600_nm_1e_data[16] = {
135 0x0143, 0x0100, 0x0075, 0xCD81, 0x500D, 0xA201, 0x0000, 0x0000,
136 0x5800, 0x0000, 0x9803, 0x2000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
137 };
138
139 static const struct c3600_eeprom eeprom_c3600_nm_1e = {
140 "NM-1E", (m_uint16_t *)eeprom_c3600_nm_1e_data,
141 sizeof(eeprom_c3600_nm_1e_data)/2,
142 };
143
144 /*
145 * dev_c3600_nm_1e_init()
146 *
147 * Add a NM-1E Network Module into specified slot.
148 */
149 static int dev_c3600_nm_1e_init(c3600_t *router,char *name,u_int nm_bay)
150 {
151 return(dev_c3600_nm_eth_init(router,name,nm_bay,1,AM79C971_TYPE_10BASE_T,
152 &eeprom_c3600_nm_1e));
153 }
154
155 /* ====================================================================== */
156 /* NM-4E */
157 /* ====================================================================== */
158
159 /* NM-4E: 4 Ethernet Network Module EEPROM */
160 static const m_uint16_t eeprom_c3600_nm_4e_data[16] = {
161 0x0142, 0x0100, 0x0075, 0xCD81, 0x500D, 0xA201, 0x0000, 0x0000,
162 0x5800, 0x0000, 0x9803, 0x2000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
163 };
164
165 static const struct c3600_eeprom eeprom_c3600_nm_4e = {
166 "NM-4E", (m_uint16_t *)eeprom_c3600_nm_4e_data,
167 sizeof(eeprom_c3600_nm_4e_data)/2,
168 };
169
170 /*
171 * dev_c3600_nm_4e_init()
172 *
173 * Add a NM-4E Network Module into specified slot.
174 */
175 static int dev_c3600_nm_4e_init(c3600_t *router,char *name,u_int nm_bay)
176 {
177 return(dev_c3600_nm_eth_init(router,name,nm_bay,4,AM79C971_TYPE_10BASE_T,
178 &eeprom_c3600_nm_4e));
179 }
180
181 /* ====================================================================== */
182 /* NM-1FE-TX */
183 /* ====================================================================== */
184
185 /* NM-1FE-TX: 1 FastEthernet Network Module EEPROM */
186 static const m_uint16_t eeprom_c3600_nm_1fe_tx_data[16] = {
187 0x0144, 0x0100, 0x0075, 0xCD81, 0x500D, 0xA201, 0x0000, 0x0000,
188 0x5800, 0x0000, 0x9803, 0x2000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
189 };
190
191 static const struct c3600_eeprom eeprom_c3600_nm_1fe_tx = {
192 "NM-1FE-TX", (m_uint16_t *)eeprom_c3600_nm_1fe_tx_data,
193 sizeof(eeprom_c3600_nm_1fe_tx_data)/2,
194 };
195
196 /*
197 * dev_c3600_nm_1fe_tx_init()
198 *
199 * Add a NM-1FE-TX Network Module into specified slot.
200 */
201 static int dev_c3600_nm_1fe_tx_init(c3600_t *router,char *name,u_int nm_bay)
202 {
203 return(dev_c3600_nm_eth_init(router,name,nm_bay,1,AM79C971_TYPE_100BASE_TX,
204 &eeprom_c3600_nm_1fe_tx));
205 }
206
207 /* ====================================================================== */
208 /* Leopard-2FE */
209 /* ====================================================================== */
210
211 /*
212 * Leopard-2FE: 2 FastEthernet ports on C3660 motherboard.
213 *
214 * Leopard-2FE is the FRU/Product Number displayed by "show diag".
215 */
216 static m_uint16_t eeprom_c3600_leopard_2fe_data[] = {
217 0x04FF, 0xC18B, 0x4A41, 0x4230, 0x3530, 0x3330, 0x3454, 0x3809,
218 0x3440, 0x00B3, 0xC046, 0x0320, 0x0012, 0x8104, 0x4241, 0x3085,
219 0x1C0C, 0xA202, 0x80FF, 0xFFFF, 0xFFC4, 0x08FF, 0xFFFF, 0xFFFF,
220 0xFFFF, 0xFFA1, 0xFFFF, 0xFFFF, 0x03FF, 0x04FF, 0xC508, 0xFFFF,
221 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
222 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
223 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
224 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFF00,
225 };
226
227 static const struct c3600_eeprom eeprom_c3600_leopard_2fe = {
228 "Leopard-2FE", (m_uint16_t *)eeprom_c3600_leopard_2fe_data,
229 sizeof(eeprom_c3600_leopard_2fe_data)/2,
230 };
231
232 /*
233 * dev_c3600_leopard_2fe_init()
234 *
235 * Add Leopard-2FE (only Cisco 3660, in slot 0).
236 */
237 static int dev_c3600_leopard_2fe_init(c3600_t *router,char *name,u_int nm_bay)
238 {
239 if (nm_bay != 0) {
240 fprintf(stderr,"C3600 %s: Leopard-2FE can only be put in slot 0\n",
241 router->vm->name);
242 return(-1);
243 }
244
245 return(dev_c3600_nm_eth_init(router,name,0,2,AM79C971_TYPE_100BASE_TX,
246 &eeprom_c3600_leopard_2fe));
247 }
248
249 /* ====================================================================== */
250
251 /* NM-1FE-TX driver */
252 struct c3600_nm_driver dev_c3600_nm_1fe_tx_driver = {
253 "NM-1FE-TX", 1, 0,
254 dev_c3600_nm_1fe_tx_init,
255 dev_c3600_nm_eth_shutdown,
256 dev_c3600_nm_eth_set_nio,
257 dev_c3600_nm_eth_unset_nio,
258 };
259
260 /* NM-1E driver */
261 struct c3600_nm_driver dev_c3600_nm_1e_driver = {
262 "NM-1E", 1, 0,
263 dev_c3600_nm_1e_init,
264 dev_c3600_nm_eth_shutdown,
265 dev_c3600_nm_eth_set_nio,
266 dev_c3600_nm_eth_unset_nio,
267 };
268
269 /* NM-4E driver */
270 struct c3600_nm_driver dev_c3600_nm_4e_driver = {
271 "NM-4E", 1, 0,
272 dev_c3600_nm_4e_init,
273 dev_c3600_nm_eth_shutdown,
274 dev_c3600_nm_eth_set_nio,
275 dev_c3600_nm_eth_unset_nio,
276 };
277
278 /* Leopard-2FE driver */
279 struct c3600_nm_driver dev_c3600_leopard_2fe_driver = {
280 "Leopard-2FE", 1, 0,
281 dev_c3600_leopard_2fe_init,
282 dev_c3600_nm_eth_shutdown,
283 dev_c3600_nm_eth_set_nio,
284 dev_c3600_nm_eth_unset_nio,
285 };

  ViewVC Help
Powered by ViewVC 1.1.26