/[dynamips]/trunk/dev_c2600_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_c2600_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: 5644 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_mpc860.h"
23     #include "dev_c2600.h"
24     #include "dev_wic_serial.h"
25    
26     /* Get the SCC channel associated to a WIC sub-slot */
27     static int dev_c2600_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     /* Initialize a WIC-1T in the specified slot */
63     static int dev_c2600_mb_wic1t_init(vm_instance_t *vm,struct cisco_card *card)
64     {
65     struct wic_serial_data *wic_data;
66     m_uint64_t phys_addr;
67     u_int wic_id;
68    
69     /* Create the WIC device */
70     wic_id = (card->subslot_id >> 4) - 1;
71    
72     if (c2600_get_onboard_wic_addr(wic_id,&phys_addr) == -1) {
73     vm_error(vm,"WIC","invalid slot %u (subslot_id=%u)\n",
74     wic_id,card->subslot_id);
75     return(-1);
76     }
77    
78     wic_data = dev_wic_serial_init(vm,card->dev_name,WIC_SERIAL_MODEL_1T,
79     phys_addr,C2600_WIC_SIZE);
80    
81     if (!wic_data)
82     return(-1);
83    
84     /* Set the EEPROM */
85     cisco_card_set_eeprom(vm,card,cisco_eeprom_find_wic("WIC-1T"));
86    
87     /* Store device info into the router structure */
88     card->drv_info = wic_data;
89     return(0);
90     }
91    
92     /* Remove a WIC-1T from the specified slot */
93     static int
94     dev_c2600_mb_wic1t_shutdown(vm_instance_t *vm,struct cisco_card *card)
95     {
96     /* Remove the WIC device */
97     dev_wic_serial_remove(card->drv_info);
98    
99     /* Remove the WIC EEPROM */
100     cisco_card_unset_eeprom(card);
101     return(0);
102     }
103    
104     /* Bind a Network IO descriptor */
105     static int
106     dev_c2600_mb_wic1t_set_nio(vm_instance_t *vm,struct cisco_card *card,
107     u_int port_id,netio_desc_t *nio)
108     {
109     u_int scc_chan;
110    
111     if ((port_id > 0) ||
112     (dev_c2600_mb_wic_get_scc_chan(card,port_id,&scc_chan) == -1))
113     return(-1);
114    
115     return(mpc860_scc_set_nio(VM_C2600(vm)->mpc_data,scc_chan,nio));
116     }
117    
118     /* Unbind a Network IO descriptor */
119     static int
120     dev_c2600_mb_wic1t_unset_nio(vm_instance_t *vm,struct cisco_card *card,
121     u_int port_id)
122     {
123     u_int scc_chan;
124    
125     if ((port_id > 0) ||
126     (dev_c2600_mb_wic_get_scc_chan(card,port_id,&scc_chan) == -1))
127     return(-1);
128    
129     return(mpc860_scc_unset_nio(VM_C2600(vm)->mpc_data,scc_chan));
130     }
131    
132     /* Initialize a WIC-2T in the specified slot */
133     static int dev_c2600_mb_wic2t_init(vm_instance_t *vm,struct cisco_card *card)
134     {
135     struct wic_serial_data *wic_data;
136     m_uint64_t phys_addr;
137     u_int wic_id;
138    
139     /* Create the WIC device */
140     wic_id = (card->subslot_id >> 4) - 1;
141    
142     if (c2600_get_onboard_wic_addr(wic_id,&phys_addr) == -1) {
143     vm_error(vm,"WIC","invalid slot %u (subslot_id=%u)\n",
144     wic_id,card->subslot_id);
145     return(-1);
146     }
147    
148     wic_data = dev_wic_serial_init(vm,card->dev_name,WIC_SERIAL_MODEL_2T,
149     phys_addr,C2600_WIC_SIZE);
150    
151     if (!wic_data)
152     return(-1);
153    
154     /* Set the EEPROM */
155     cisco_card_set_eeprom(vm,card,cisco_eeprom_find_wic("WIC-2T"));
156    
157     /* Store device info into the router structure */
158     card->drv_info = wic_data;
159     return(0);
160     }
161    
162     /* Remove a WIC-2T from the specified slot */
163     static int
164     dev_c2600_mb_wic2t_shutdown(vm_instance_t *vm,struct cisco_card *card)
165     {
166     /* Remove the WIC device */
167     dev_wic_serial_remove(card->drv_info);
168    
169     /* Remove the WIC EEPROM */
170     cisco_card_unset_eeprom(card);
171     return(0);
172     }
173    
174     /* Bind a Network IO descriptor */
175     static int
176     dev_c2600_mb_wic2t_set_nio(vm_instance_t *vm,struct cisco_card *card,
177     u_int port_id,netio_desc_t *nio)
178     {
179     u_int scc_chan;
180    
181     if ((port_id > 1) ||
182     (dev_c2600_mb_wic_get_scc_chan(card,port_id,&scc_chan) == -1))
183     return(-1);
184    
185     return(mpc860_scc_set_nio(VM_C2600(vm)->mpc_data,scc_chan,nio));
186     }
187    
188     /* Unbind a Network IO descriptor */
189     static int
190     dev_c2600_mb_wic2t_unset_nio(vm_instance_t *vm,struct cisco_card *card,
191     u_int port_id)
192     {
193     u_int scc_chan;
194    
195     if ((port_id > 1) ||
196     (dev_c2600_mb_wic_get_scc_chan(card,port_id,&scc_chan) == -1))
197     return(-1);
198    
199     return(mpc860_scc_unset_nio(VM_C2600(vm)->mpc_data,scc_chan));
200     }
201    
202     /* Cisco 2600 WIC-1T driver (for mainboard) */
203     struct cisco_card_driver dev_c2600_mb_wic1t_driver = {
204     "WIC-1T", 1, 0,
205     dev_c2600_mb_wic1t_init,
206     dev_c2600_mb_wic1t_shutdown,
207     NULL,
208     dev_c2600_mb_wic1t_set_nio,
209     dev_c2600_mb_wic1t_unset_nio,
210     NULL,
211     };
212    
213     /* Cisco 2600 WIC-2T driver (for mainboard) */
214     struct cisco_card_driver dev_c2600_mb_wic2t_driver = {
215     "WIC-2T", 1, 0,
216     dev_c2600_mb_wic2t_init,
217     dev_c2600_mb_wic2t_shutdown,
218     NULL,
219     dev_c2600_mb_wic2t_set_nio,
220     dev_c2600_mb_wic2t_unset_nio,
221     NULL,
222     };
223    
224     /* WIC drivers (mainbord slots) */
225     struct cisco_card_driver *dev_c2600_mb_wic_drivers[] = {
226     &dev_c2600_mb_wic1t_driver,
227     &dev_c2600_mb_wic2t_driver,
228     NULL,
229     };

  ViewVC Help
Powered by ViewVC 1.1.26