/[dynamips]/trunk/dev_c1700_wic.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

Annotation of /trunk/dev_c1700_wic.c

Parent Directory Parent Directory | Revision Log Revision Log


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

1 dpavlin 11 /*
2     * Cisco router simulation platform.
3     * Copyright (c) 2007 Christophe Fillot (cf@utc.fr)
4     *
5     * WIC 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 "vm.h"
22     #include "dev_nm_16esw.h"
23     #include "dev_mpc860.h"
24     #include "dev_c1700.h"
25    
26     /* Get the SCC channel associated to a WIC sub-slot */
27     static int dev_c1700_mb_wic_get_scc_chan(struct cisco_card *card,u_int port_id,
28     u_int *scc_chan)
29     {
30     u_int cid;
31    
32     cid = card->subslot_id + port_id;
33    
34     switch(cid) {
35     /* WIC 0 port 0 mapped to MPC860 SCC1 */
36     case 0x10:
37     *scc_chan = 0;
38     break;
39    
40     /* WIC 0 port 1 mapped to MPC860 SCC4 */
41     case 0x11:
42     *scc_chan = 3;
43     break;
44    
45     /* WIC 1 port 0 mapped to MPC860 SCC2 */
46     case 0x20:
47     *scc_chan = 1;
48     break;
49    
50     /* WIC 1 port 1 mapped to MPC860 SCC3 */
51     case 0x21:
52     *scc_chan = 2;
53     break;
54    
55     default:
56     return(-1);
57     }
58    
59     return(0);
60     }
61    
62     /* ======================================================================== */
63     /* WIC-1T */
64     /* ======================================================================== */
65    
66     /* Initialize a WIC-1T in the specified slot */
67     static int dev_c1700_mb_wic1t_init(vm_instance_t *vm,struct cisco_card *card)
68     {
69     /* Set the EEPROM */
70     cisco_card_set_eeprom(vm,card,cisco_eeprom_find_wic("WIC-1T"));
71    
72     /* Store device info into the router structure */
73     card->drv_info = VM_C1700(vm)->mpc_data;
74     return(0);
75     }
76    
77     /* Remove a WIC-1T from the specified slot */
78     static int
79     dev_c1700_mb_wic1t_shutdown(vm_instance_t *vm,struct cisco_card *card)
80     {
81     /* Remove the WIC EEPROM */
82     cisco_card_unset_eeprom(card);
83     return(0);
84     }
85    
86     /* Bind a Network IO descriptor */
87     static int
88     dev_c1700_mb_wic1t_set_nio(vm_instance_t *vm,struct cisco_card *card,
89     u_int port_id,netio_desc_t *nio)
90     {
91     struct mpc860_data *mpc_data = card->drv_info;
92     u_int scc_chan;
93    
94     if ((port_id > 0) ||
95     (dev_c1700_mb_wic_get_scc_chan(card,port_id,&scc_chan) == -1))
96     return(-1);
97    
98     return(mpc860_scc_set_nio(mpc_data,scc_chan,nio));
99     }
100    
101     /* Unbind a Network IO descriptor */
102     static int
103     dev_c1700_mb_wic1t_unset_nio(vm_instance_t *vm,struct cisco_card *card,
104     u_int port_id)
105     {
106     struct mpc860_data *mpc_data = card->drv_info;
107     u_int scc_chan;
108    
109     if ((port_id > 0) ||
110     (dev_c1700_mb_wic_get_scc_chan(card,port_id,&scc_chan) == -1))
111     return(-1);
112    
113     return(mpc860_scc_unset_nio(mpc_data,scc_chan));
114     }
115    
116     /* ======================================================================== */
117     /* WIC-2T */
118     /* ======================================================================== */
119    
120     /* Initialize a WIC-2T in the specified slot */
121     static int dev_c1700_mb_wic2t_init(vm_instance_t *vm,struct cisco_card *card)
122     {
123     /* Set the EEPROM */
124     cisco_card_set_eeprom(vm,card,cisco_eeprom_find_wic("WIC-2T"));
125    
126     /* Store device info into the router structure */
127     card->drv_info = VM_C1700(vm)->mpc_data;
128     return(0);
129     }
130    
131     /* Remove a WIC-2T from the specified slot */
132     static int
133     dev_c1700_mb_wic2t_shutdown(vm_instance_t *vm,struct cisco_card *card)
134     {
135     /* Remove the WIC EEPROM */
136     cisco_card_unset_eeprom(card);
137     return(0);
138     }
139    
140     /* Bind a Network IO descriptor */
141     static int
142     dev_c1700_mb_wic2t_set_nio(vm_instance_t *vm,struct cisco_card *card,
143     u_int port_id,netio_desc_t *nio)
144     {
145     struct mpc860_data *mpc_data = card->drv_info;
146     u_int scc_chan;
147    
148     if ((port_id > 1) ||
149     (dev_c1700_mb_wic_get_scc_chan(card,port_id,&scc_chan) == -1))
150     return(-1);
151    
152     return(mpc860_scc_set_nio(mpc_data,scc_chan,nio));
153     }
154    
155     /* Unbind a Network IO descriptor */
156     static int
157     dev_c1700_mb_wic2t_unset_nio(vm_instance_t *vm,struct cisco_card *card,
158     u_int port_id)
159     {
160     struct mpc860_data *mpc_data = card->drv_info;
161     u_int scc_chan;
162    
163     if ((port_id > 1) ||
164     (dev_c1700_mb_wic_get_scc_chan(card,port_id,&scc_chan) == -1))
165     return(-1);
166    
167     return(mpc860_scc_unset_nio(mpc_data,scc_chan));
168     }
169    
170     /* ======================================================================== */
171     /* WIC-1ENET */
172     /* ======================================================================== */
173    
174     /* Initialize a WIC-1ENET in the specified slot */
175     static int
176     dev_c1700_mb_wic1enet_init(vm_instance_t *vm,struct cisco_card *card)
177     {
178     m_uint8_t eeprom_ver;
179     size_t offset;
180     n_eth_addr_t addr;
181     m_uint16_t pid;
182    
183     pid = (m_uint16_t)getpid();
184    
185     /* Generate automatically the MAC address */
186     addr.eth_addr_byte[0] = vm_get_mac_addr_msb(vm);
187     addr.eth_addr_byte[1] = vm->instance_id & 0xFF;
188     addr.eth_addr_byte[2] = pid >> 8;
189     addr.eth_addr_byte[3] = pid & 0xFF;
190     addr.eth_addr_byte[4] = card->subslot_id;
191     addr.eth_addr_byte[5] = 0x00;
192    
193     /* Set the EEPROM */
194     cisco_card_set_eeprom(vm,card,cisco_eeprom_find_wic("WIC-1ENET"));
195    
196     /* Read EEPROM format version */
197     cisco_eeprom_get_byte(&card->eeprom,0,&eeprom_ver);
198    
199     if (eeprom_ver != 4)
200     return(-1);
201    
202     if (cisco_eeprom_v4_find_field(&card->eeprom,0xCF,&offset) == -1)
203     return(-1);
204    
205     cisco_eeprom_set_region(&card->eeprom,offset,addr.eth_addr_byte,6);
206    
207     /* Store device info into the router structure */
208     card->drv_info = VM_C1700(vm)->mpc_data;
209     return(0);
210     }
211    
212     /* Remove a WIC-1ENET from the specified slot */
213     static int
214     dev_c1700_mb_wic1enet_shutdown(vm_instance_t *vm,struct cisco_card *card)
215     {
216     /* Remove the WIC EEPROM */
217     cisco_card_unset_eeprom(card);
218     return(0);
219     }
220    
221     /* Bind a Network IO descriptor */
222     static int
223     dev_c1700_mb_wic1enet_set_nio(vm_instance_t *vm,struct cisco_card *card,
224     u_int port_id,netio_desc_t *nio)
225     {
226     struct mpc860_data *mpc_data = card->drv_info;
227     u_int scc_chan;
228    
229     if ((port_id > 0) ||
230     (dev_c1700_mb_wic_get_scc_chan(card,port_id,&scc_chan) == -1))
231     return(-1);
232    
233     return(mpc860_scc_set_nio(mpc_data,scc_chan,nio));
234     }
235    
236     /* Unbind a Network IO descriptor */
237     static int
238     dev_c1700_mb_wic1enet_unset_nio(vm_instance_t *vm,struct cisco_card *card,
239     u_int port_id)
240     {
241     struct mpc860_data *mpc_data = card->drv_info;
242     u_int scc_chan;
243    
244     if ((port_id > 0) ||
245     (dev_c1700_mb_wic_get_scc_chan(card,port_id,&scc_chan) == -1))
246     return(-1);
247    
248     return(mpc860_scc_unset_nio(mpc_data,scc_chan));
249     }
250    
251     /* ======================================================================== */
252    
253     /* Cisco 1700 WIC-1T driver */
254     struct cisco_card_driver dev_c1700_mb_wic1t_driver = {
255     "WIC-1T", 1, 0,
256     dev_c1700_mb_wic1t_init,
257     dev_c1700_mb_wic1t_shutdown,
258     NULL,
259     dev_c1700_mb_wic1t_set_nio,
260     dev_c1700_mb_wic1t_unset_nio,
261     NULL,
262     };
263    
264     /* Cisco 1700 WIC-2T driver */
265     struct cisco_card_driver dev_c1700_mb_wic2t_driver = {
266     "WIC-2T", 1, 0,
267     dev_c1700_mb_wic2t_init,
268     dev_c1700_mb_wic2t_shutdown,
269     NULL,
270     dev_c1700_mb_wic2t_set_nio,
271     dev_c1700_mb_wic2t_unset_nio,
272     NULL,
273     };
274    
275     /* Cisco 1700 WIC-1ENET driver */
276     struct cisco_card_driver dev_c1700_mb_wic1enet_driver = {
277     "WIC-1ENET", 1, 0,
278     dev_c1700_mb_wic1enet_init,
279     dev_c1700_mb_wic1enet_shutdown,
280     NULL,
281     dev_c1700_mb_wic1enet_set_nio,
282     dev_c1700_mb_wic1enet_unset_nio,
283     NULL,
284     };
285    
286     /* WIC drivers (mainbord slots) */
287     struct cisco_card_driver *dev_c1700_mb_wic_drivers[] = {
288     &dev_c1700_mb_wic1t_driver,
289     &dev_c1700_mb_wic2t_driver,
290     &dev_c1700_mb_wic1enet_driver,
291     NULL,
292     };

  ViewVC Help
Powered by ViewVC 1.1.26