/[dynamips]/trunk/dev_c7200_serial.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_c7200_serial.c

Parent Directory Parent Directory | Revision Log Revision Log


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

1 /*
2 * Cisco router simulation platform.
3 * Copyright (C) 2005,2006 Christophe Fillot. All rights reserved.
4 *
5 * Serial Interfaces (Mueslix).
6 *
7 * EEPROM types:
8 * - 0x0C: PA-4T+
9 * - 0x0D: PA-8T-V35
10 * - 0x0E: PA-8T-X21
11 * - 0x0F: PA-8T-232
12 * - 0x10: PA-2H (HSSI)
13 * - 0x40: PA-4E1G/120
14 *
15 * It seems that the PA-8T is a combination of two PA-4T+.
16 *
17 * Note: "debug serial mueslix" gives more technical info.
18 */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <errno.h>
25 #include <assert.h>
26
27 #include "cpu.h"
28 #include "vm.h"
29 #include "dynamips.h"
30 #include "memory.h"
31 #include "device.h"
32 #include "net.h"
33 #include "net_io.h"
34 #include "ptask.h"
35 #include "dev_mueslix.h"
36 #include "dev_c7200.h"
37
38 /* ====================================================================== */
39 /* PA-4T+ */
40 /* ====================================================================== */
41
42 /*
43 * dev_c7200_pa_4t_init()
44 *
45 * Add a PA-4T port adapter into specified slot.
46 */
47 static int dev_c7200_pa_4t_init(vm_instance_t *vm,struct cisco_card *card)
48 {
49 struct mueslix_data *data;
50 u_int slot = card->slot_id;
51
52 /* Set the PCI bus */
53 card->pci_bus = vm->slots_pci_bus[slot];
54
55 /* Set the EEPROM */
56 cisco_card_set_eeprom(vm,card,cisco_eeprom_find_pa("PA-4T+"));
57 c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom);
58
59 /* Create the Mueslix chip */
60 data = dev_mueslix_init(vm,card->dev_name,1,
61 card->pci_bus,0,
62 c7200_net_irq_for_slot_port(slot,0));
63 if (!data) return(-1);
64
65 /* Store device info into the router structure */
66 card->drv_info = data;
67 return(0);
68 }
69
70 /* Remove a PA-4T+ from the specified slot */
71 static int dev_c7200_pa_4t_shutdown(vm_instance_t *vm,struct cisco_card *card)
72 {
73 /* Remove the PA EEPROM */
74 cisco_card_unset_eeprom(card);
75 c7200_set_slot_eeprom(VM_C7200(vm),card->slot_id,NULL);
76
77 /* Remove the Mueslix chip */
78 dev_mueslix_remove(card->drv_info);
79 return(0);
80 }
81
82 /* Bind a Network IO descriptor to a specific port */
83 static int dev_c7200_pa_4t_set_nio(vm_instance_t *vm,struct cisco_card *card,
84 u_int port_id,netio_desc_t *nio)
85 {
86 struct mueslix_data *data = card->drv_info;
87
88 if (!data || (port_id >= MUESLIX_NR_CHANNELS))
89 return(-1);
90
91 return(dev_mueslix_set_nio(data,port_id,nio));
92 }
93
94 /* Unbind a Network IO descriptor to a specific port */
95 static int dev_c7200_pa_4t_unset_nio(vm_instance_t *vm,struct cisco_card *card,
96 u_int port_id)
97 {
98 struct mueslix_data *data = card->drv_info;
99
100 if (!data || (port_id >= MUESLIX_NR_CHANNELS))
101 return(-1);
102
103 return(dev_mueslix_unset_nio(data,port_id));
104 }
105
106 /* PA-4T+ driver */
107 struct cisco_card_driver dev_c7200_pa_4t_driver = {
108 "PA-4T+", 1, 0,
109 dev_c7200_pa_4t_init,
110 dev_c7200_pa_4t_shutdown,
111 NULL,
112 dev_c7200_pa_4t_set_nio,
113 dev_c7200_pa_4t_unset_nio,
114 };
115
116 /* ====================================================================== */
117 /* PA-8T */
118 /* ====================================================================== */
119
120 /* PA-8T data */
121 struct pa8t_data {
122 struct mueslix_data *mueslix[2];
123 };
124
125 /*
126 * dev_c7200_pa_8t_init()
127 *
128 * Add a PA-8T port adapter into specified slot.
129 */
130 static int dev_c7200_pa_8t_init(vm_instance_t *vm,struct cisco_card *card)
131 {
132 struct pa8t_data *data;
133 u_int slot = card->slot_id;
134
135 /* Allocate the private data structure for the PA-8T */
136 if (!(data = malloc(sizeof(*data)))) {
137 vm_log(vm,"%s: out of memory\n",card->dev_name);
138 return(-1);
139 }
140
141 /* Set the PCI bus */
142 card->pci_bus = vm->slots_pci_bus[slot];
143
144 /* Set the EEPROM */
145 cisco_card_set_eeprom(vm,card,cisco_eeprom_find_pa("PA-8T"));
146 c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom);
147
148 /* Create the 1st Mueslix chip */
149 data->mueslix[0] = dev_mueslix_init(vm,card->dev_name,1,
150 card->pci_bus,0,
151 c7200_net_irq_for_slot_port(slot,0));
152 if (!data->mueslix[0]) return(-1);
153
154 /* Create the 2nd Mueslix chip */
155 data->mueslix[1] = dev_mueslix_init(vm,card->dev_name,1,
156 card->pci_bus,1,
157 c7200_net_irq_for_slot_port(slot,1));
158 if (!data->mueslix[1]) return(-1);
159
160 /* Store device info into the router structure */
161 card->drv_info = data;
162 return(0);
163 }
164
165 /* Remove a PA-8T from the specified slot */
166 static int dev_c7200_pa_8t_shutdown(vm_instance_t *vm,struct cisco_card *card)
167 {
168 struct pa8t_data *data = card->drv_info;
169
170 /* Remove the PA EEPROM */
171 cisco_card_unset_eeprom(card);
172 c7200_set_slot_eeprom(VM_C7200(vm),card->slot_id,NULL);
173
174 /* Remove the two Mueslix chips */
175 dev_mueslix_remove(data->mueslix[0]);
176 dev_mueslix_remove(data->mueslix[1]);
177 free(data);
178 return(0);
179 }
180
181 /* Bind a Network IO descriptor to a specific port */
182 static int dev_c7200_pa_8t_set_nio(vm_instance_t *vm,struct cisco_card *card,
183 u_int port_id,netio_desc_t *nio)
184 {
185 struct pa8t_data *d = card->drv_info;
186
187 if (!d || (port_id >= (MUESLIX_NR_CHANNELS*2)))
188 return(-1);
189
190 return(dev_mueslix_set_nio(d->mueslix[port_id>>2],(port_id&0x03),nio));
191 }
192
193 /* Bind a Network IO descriptor to a specific port */
194 static int dev_c7200_pa_8t_unset_nio(vm_instance_t *vm,struct cisco_card *card,
195 u_int port_id)
196 {
197 struct pa8t_data *d = card->drv_info;
198
199 if (!d || (port_id >= (MUESLIX_NR_CHANNELS*2)))
200 return(-1);
201
202 return(dev_mueslix_unset_nio(d->mueslix[port_id>>2],port_id&0x03));
203 }
204
205 /* PA-8T driver */
206 struct cisco_card_driver dev_c7200_pa_8t_driver = {
207 "PA-8T", 1, 0,
208 dev_c7200_pa_8t_init,
209 dev_c7200_pa_8t_shutdown,
210 NULL,
211 dev_c7200_pa_8t_set_nio,
212 dev_c7200_pa_8t_unset_nio,
213 };

  ViewVC Help
Powered by ViewVC 1.1.26