/[dynamips]/trunk/dev_c3725_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_c3725_wic.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (hide annotations)
Sat Oct 6 16:33:40 2007 UTC (16 years, 5 months ago) by dpavlin
Original Path: upstream/dynamips-0.2.8-RC1/dev_c3725_wic.c
File MIME type: text/plain
File size: 5950 byte(s)
dynamips-0.2.8-RC1

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_gt.h"
23     #include "dev_c3725.h"
24     #include "dev_wic_serial.h"
25    
26     /* Get the MPSC channel associated to a WIC sub-slot */
27     static int dev_c3725_mb_wic_get_mpsc_chan(struct cisco_card *card,
28     u_int port_id,
29     u_int *mpsc_chan)
30     {
31     u_int cid;
32    
33     cid = card->subslot_id + port_id;
34    
35     switch(cid) {
36     /* WIC 0 port 0 mapped to GT96100 MPSC1 */
37     case 0x10:
38     *mpsc_chan = 1;
39     break;
40    
41     /* WIC 0 port 1 mapped to GT96100 MPSC0 */
42     case 0x11:
43     *mpsc_chan = 0;
44     break;
45    
46     /* WIC 1 port 0 mapped to GT96100 MPSC4 */
47     case 0x20:
48     *mpsc_chan = 4;
49     break;
50    
51     /* WIC 1 port 1 mapped to GT96100 MPSC2 */
52     case 0x21:
53     *mpsc_chan = 2;
54     break;
55    
56     /* WIC 2 port 0 mapped to GT96100 MPSC5 */
57     case 0x30:
58     *mpsc_chan = 5;
59     break;
60    
61     /* WIC 2 port 1 mapped to GT96100 MPSC3 */
62     case 0x31:
63     *mpsc_chan = 3;
64     break;
65    
66     default:
67     return(-1);
68     }
69    
70     return(0);
71     }
72    
73     /* Initialize a WIC-1T in the specified slot */
74     static int dev_c3725_mb_wic1t_init(vm_instance_t *vm,struct cisco_card *card)
75     {
76     struct wic_serial_data *wic_data;
77     m_uint64_t phys_addr;
78     u_int wic_id;
79    
80     /* Create the WIC device */
81     wic_id = (card->subslot_id >> 4) - 1;
82    
83     if (c3725_get_onboard_wic_addr(wic_id,&phys_addr) == -1) {
84     vm_error(vm,"WIC","invalid slot %u (subslot_id=%u)\n",
85     wic_id,card->subslot_id);
86     return(-1);
87     }
88    
89     wic_data = dev_wic_serial_init(vm,card->dev_name,WIC_SERIAL_MODEL_1T,
90     phys_addr,C3725_WIC_SIZE);
91    
92     if (!wic_data)
93     return(-1);
94    
95     /* Set the EEPROM */
96     cisco_card_set_eeprom(vm,card,cisco_eeprom_find_wic("WIC-1T"));
97    
98     /* Store device info into the router structure */
99     card->drv_info = wic_data;
100     return(0);
101     }
102    
103     /* Remove a WIC-1T from the specified slot */
104     static int
105     dev_c3725_mb_wic1t_shutdown(vm_instance_t *vm,struct cisco_card *card)
106     {
107     /* Remove the WIC device */
108     dev_wic_serial_remove(card->drv_info);
109    
110     /* Remove the WIC EEPROM */
111     cisco_card_unset_eeprom(card);
112     return(0);
113     }
114    
115     /* Bind a Network IO descriptor */
116     static int
117     dev_c3725_mb_wic1t_set_nio(vm_instance_t *vm,struct cisco_card *card,
118     u_int port_id,netio_desc_t *nio)
119     {
120     u_int mpsc_chan;
121    
122     if ((port_id > 0) ||
123     (dev_c3725_mb_wic_get_mpsc_chan(card,port_id,&mpsc_chan) == -1))
124     return(-1);
125    
126     return(dev_gt96100_mpsc_set_nio(VM_C3725(vm)->gt_data,mpsc_chan,nio));
127     }
128    
129     /* Unbind a Network IO descriptor */
130     static int
131     dev_c3725_mb_wic1t_unset_nio(vm_instance_t *vm,struct cisco_card *card,
132     u_int port_id)
133     {
134     u_int mpsc_chan;
135    
136     if ((port_id > 0) ||
137     (dev_c3725_mb_wic_get_mpsc_chan(card,port_id,&mpsc_chan) == -1))
138     return(-1);
139    
140     return(dev_gt96100_mpsc_unset_nio(VM_C3725(vm)->gt_data,mpsc_chan));
141     }
142    
143     /* Initialize a WIC-2T in the specified slot */
144     static int dev_c3725_mb_wic2t_init(vm_instance_t *vm,struct cisco_card *card)
145     {
146     struct wic_serial_data *wic_data;
147     m_uint64_t phys_addr;
148     u_int wic_id;
149    
150     /* Create the WIC device */
151     wic_id = (card->subslot_id >> 4) - 1;
152    
153     if (c3725_get_onboard_wic_addr(wic_id,&phys_addr) == -1) {
154     vm_error(vm,"WIC","invalid slot %u (subslot_id=%u)\n",
155     wic_id,card->subslot_id);
156     return(-1);
157     }
158    
159     wic_data = dev_wic_serial_init(vm,card->dev_name,WIC_SERIAL_MODEL_2T,
160     phys_addr,C3725_WIC_SIZE);
161    
162     if (!wic_data)
163     return(-1);
164    
165     /* Set the EEPROM */
166     cisco_card_set_eeprom(vm,card,cisco_eeprom_find_wic("WIC-2T"));
167    
168     /* Store device info into the router structure */
169     card->drv_info = wic_data;
170     return(0);
171     }
172    
173     /* Remove a WIC-2T from the specified slot */
174     static int
175     dev_c3725_mb_wic2t_shutdown(vm_instance_t *vm,struct cisco_card *card)
176     {
177     /* Remove the WIC device */
178     dev_wic_serial_remove(card->drv_info);
179    
180     /* Remove the WIC EEPROM */
181     cisco_card_unset_eeprom(card);
182     return(0);
183     }
184    
185     /* Bind a Network IO descriptor */
186     static int
187     dev_c3725_mb_wic2t_set_nio(vm_instance_t *vm,struct cisco_card *card,
188     u_int port_id,netio_desc_t *nio)
189     {
190     u_int mpsc_chan;
191    
192     if ((port_id > 1) ||
193     (dev_c3725_mb_wic_get_mpsc_chan(card,port_id,&mpsc_chan) == -1))
194     return(-1);
195    
196     return(dev_gt96100_mpsc_set_nio(VM_C3725(vm)->gt_data,mpsc_chan,nio));
197     }
198    
199     /* Unbind a Network IO descriptor */
200     static int
201     dev_c3725_mb_wic2t_unset_nio(vm_instance_t *vm,struct cisco_card *card,
202     u_int port_id)
203     {
204     u_int mpsc_chan;
205    
206     if ((port_id > 1) ||
207     (dev_c3725_mb_wic_get_mpsc_chan(card,port_id,&mpsc_chan) == -1))
208     return(-1);
209    
210     return(dev_gt96100_mpsc_unset_nio(VM_C3725(vm)->gt_data,mpsc_chan));
211     }
212    
213     /* Cisco 3725 WIC-1T driver (for mainboard) */
214     struct cisco_card_driver dev_c3725_mb_wic1t_driver = {
215     "WIC-1T", 1, 0,
216     dev_c3725_mb_wic1t_init,
217     dev_c3725_mb_wic1t_shutdown,
218     NULL,
219     dev_c3725_mb_wic1t_set_nio,
220     dev_c3725_mb_wic1t_unset_nio,
221     NULL,
222     };
223    
224     /* Cisco 3725 WIC-2T driver (for mainboard) */
225     struct cisco_card_driver dev_c3725_mb_wic2t_driver = {
226     "WIC-2T", 1, 0,
227     dev_c3725_mb_wic2t_init,
228     dev_c3725_mb_wic2t_shutdown,
229     NULL,
230     dev_c3725_mb_wic2t_set_nio,
231     dev_c3725_mb_wic2t_unset_nio,
232     NULL,
233     };
234    
235     /* WIC drivers (mainbord slots) */
236     struct cisco_card_driver *dev_c3725_mb_wic_drivers[] = {
237     &dev_c3725_mb_wic1t_driver,
238     &dev_c3725_mb_wic2t_driver,
239     NULL,
240     };

  ViewVC Help
Powered by ViewVC 1.1.26