File: dev_c2600_wic.c

package info (click to toggle)
dynamips 0.2.7-0.2.8RC2-2
  • links: PTS
  • area: non-free
  • in suites: lenny
  • size: 3,840 kB
  • ctags: 9,893
  • sloc: ansic: 69,846; makefile: 239; sh: 124; perl: 20
file content (229 lines) | stat: -rw-r--r-- 5,647 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*  
 * Cisco router simulation platform.
 * Copyright (c) 2007 Christophe Fillot (cf@utc.fr)
 *
 * WIC Modules.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include <assert.h>

#include "utils.h"
#include "net.h"
#include "net_io.h"
#include "ptask.h"
#include "vm.h"
#include "dev_mpc860.h"
#include "dev_c2600.h"
#include "dev_wic_serial.h"

/* Get the SCC channel associated to a WIC sub-slot */
static int dev_c2600_mb_wic_get_scc_chan(struct cisco_card *card,u_int port_id,
                                         u_int *scc_chan)
{
   u_int cid;

   cid = card->subslot_id + port_id;
   
   switch(cid) {
      /* WIC 0 port 0 mapped to MPC860 SCC1 */
      case 0x10:
         *scc_chan = 0;
         break;

      /* WIC 0 port 1 mapped to MPC860 SCC4 */
      case 0x11:
         *scc_chan = 3;
         break;

      /* WIC 1 port 0 mapped to MPC860 SCC2 */
      case 0x20:
         *scc_chan = 1;
         break;

      /* WIC 1 port 1 mapped to MPC860 SCC3 */
      case 0x21:
         *scc_chan = 2;
         break;

      default:
         return(-1);
   }

   return(0);
}

/* Initialize a WIC-1T in the specified slot */
static int dev_c2600_mb_wic1t_init(vm_instance_t *vm,struct cisco_card *card)
{
   struct wic_serial_data *wic_data;
   m_uint64_t phys_addr;
   u_int wic_id;

   /* Create the WIC device */
   wic_id = (card->subslot_id >> 4) - 1;
   
   if (c2600_get_onboard_wic_addr(wic_id,&phys_addr) == -1) {
      vm_error(vm,"WIC","invalid slot %u (subslot_id=%u)\n",
               wic_id,card->subslot_id);
      return(-1);
   }

   wic_data = dev_wic_serial_init(vm,card->dev_name,WIC_SERIAL_MODEL_1T,
                                  phys_addr,C2600_WIC_SIZE);

   if (!wic_data)
      return(-1);

   /* Set the EEPROM */
   cisco_card_set_eeprom(vm,card,cisco_eeprom_find_wic("WIC-1T"));

   /* Store device info into the router structure */
   card->drv_info = wic_data;
   return(0);
}

/* Remove a WIC-1T from the specified slot */
static int 
dev_c2600_mb_wic1t_shutdown(vm_instance_t *vm,struct cisco_card *card)
{ 
   /* Remove the WIC device */
   dev_wic_serial_remove(card->drv_info);

   /* Remove the WIC EEPROM */
   cisco_card_unset_eeprom(card);
   return(0);
}

/* Bind a Network IO descriptor */
static int 
dev_c2600_mb_wic1t_set_nio(vm_instance_t *vm,struct cisco_card *card,
                           u_int port_id,netio_desc_t *nio)
{
   u_int scc_chan;

   if ((port_id > 0) || 
       (dev_c2600_mb_wic_get_scc_chan(card,port_id,&scc_chan) == -1))
      return(-1);

   return(mpc860_scc_set_nio(VM_C2600(vm)->mpc_data,scc_chan,nio));
}

/* Unbind a Network IO descriptor */
static int 
dev_c2600_mb_wic1t_unset_nio(vm_instance_t *vm,struct cisco_card *card,
                             u_int port_id)
{
   u_int scc_chan;

   if ((port_id > 0) || 
       (dev_c2600_mb_wic_get_scc_chan(card,port_id,&scc_chan) == -1))
      return(-1);

   return(mpc860_scc_unset_nio(VM_C2600(vm)->mpc_data,scc_chan));
}

/* Initialize a WIC-2T in the specified slot */
static int dev_c2600_mb_wic2t_init(vm_instance_t *vm,struct cisco_card *card)
{
   struct wic_serial_data *wic_data;
   m_uint64_t phys_addr;
   u_int wic_id;

   /* Create the WIC device */
   wic_id = (card->subslot_id >> 4) - 1;
   
   if (c2600_get_onboard_wic_addr(wic_id,&phys_addr) == -1) {
      vm_error(vm,"WIC","invalid slot %u (subslot_id=%u)\n",
               wic_id,card->subslot_id);
      return(-1);
   }

   wic_data = dev_wic_serial_init(vm,card->dev_name,WIC_SERIAL_MODEL_2T,
                                  phys_addr,C2600_WIC_SIZE);

   if (!wic_data)
      return(-1);

   /* Set the EEPROM */
   cisco_card_set_eeprom(vm,card,cisco_eeprom_find_wic("WIC-2T"));

   /* Store device info into the router structure */
   card->drv_info = wic_data;
   return(0);
}

/* Remove a WIC-2T from the specified slot */
static int 
dev_c2600_mb_wic2t_shutdown(vm_instance_t *vm,struct cisco_card *card)
{
   /* Remove the WIC device */
   dev_wic_serial_remove(card->drv_info);

   /* Remove the WIC EEPROM */
   cisco_card_unset_eeprom(card);
   return(0);
}

/* Bind a Network IO descriptor */
static int 
dev_c2600_mb_wic2t_set_nio(vm_instance_t *vm,struct cisco_card *card,
                           u_int port_id,netio_desc_t *nio)
{
   u_int scc_chan;

   if ((port_id > 1) || 
       (dev_c2600_mb_wic_get_scc_chan(card,port_id,&scc_chan) == -1))
      return(-1);
   
   return(mpc860_scc_set_nio(VM_C2600(vm)->mpc_data,scc_chan,nio));
}

/* Unbind a Network IO descriptor */
static int 
dev_c2600_mb_wic2t_unset_nio(vm_instance_t *vm,struct cisco_card *card,
                             u_int port_id)
{
   u_int scc_chan;

   if ((port_id > 1) || 
       (dev_c2600_mb_wic_get_scc_chan(card,port_id,&scc_chan) == -1))
      return(-1);

   return(mpc860_scc_unset_nio(VM_C2600(vm)->mpc_data,scc_chan));
}

/* Cisco 2600 WIC-1T driver (for mainboard) */
struct cisco_card_driver dev_c2600_mb_wic1t_driver = {
   "WIC-1T", 1, 0,
   dev_c2600_mb_wic1t_init,
   dev_c2600_mb_wic1t_shutdown,
   NULL,
   dev_c2600_mb_wic1t_set_nio,
   dev_c2600_mb_wic1t_unset_nio,
   NULL,
};

/* Cisco 2600 WIC-2T driver (for mainboard) */
struct cisco_card_driver dev_c2600_mb_wic2t_driver = {
   "WIC-2T", 1, 0,
   dev_c2600_mb_wic2t_init,
   dev_c2600_mb_wic2t_shutdown,
   NULL,
   dev_c2600_mb_wic2t_set_nio,
   dev_c2600_mb_wic2t_unset_nio,
   NULL,
};

/* WIC drivers (mainbord slots) */
struct cisco_card_driver *dev_c2600_mb_wic_drivers[] = {
   &dev_c2600_mb_wic1t_driver,
   &dev_c2600_mb_wic2t_driver,
   NULL,
};