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

Diff of /trunk/dev_c3600_eth.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

upstream/dynamips-0.2.6-RC1/dev_c3600_eth.c revision 2 by dpavlin, Sat Oct 6 16:03:58 2007 UTC trunk/dev_c3600_eth.c revision 12 by dpavlin, Sat Oct 6 16:45:40 2007 UTC
# Line 19  Line 19 
19  #include "net_io.h"  #include "net_io.h"
20  #include "ptask.h"  #include "ptask.h"
21  #include "dev_am79c971.h"  #include "dev_am79c971.h"
22    #include "dev_nm_16esw.h"
23  #include "dev_c3600.h"  #include "dev_c3600.h"
24  #include "dev_c3600_bay.h"  #include "dev_c3600_bay.h"
25    
# Line 33  struct nm_eth_data { Line 34  struct nm_eth_data {
34   *   *
35   * Add an Ethernet Network Module into specified slot.   * Add an Ethernet Network Module into specified slot.
36   */   */
37  static int dev_c3600_nm_eth_init(c3600_t *router,char *name,u_int nm_bay,  static int dev_c3600_nm_eth_init(vm_instance_t *vm,struct cisco_card *card,
38                                   int nr_port,int interface_type,                                   int nr_port,int interface_type,
39                                   const struct c3600_eeprom *eeprom)                                   const struct cisco_eeprom *eeprom)
40  {  {
41     struct nm_bay_info *bay_info;     struct nm_bay_info *bay_info;
42     struct nm_eth_data *data;     struct nm_eth_data *data;
43       u_int slot = card->slot_id;
44       u_int chassis_id;
45     int i;     int i;
46    
47     /* Allocate the private data structure */     /* Allocate the private data structure */
48     if (!(data = malloc(sizeof(*data)))) {     if (!(data = malloc(sizeof(*data)))) {
49        fprintf(stderr,"%s: out of memory\n",name);        vm_error(vm,"%s: out of memory.\n",card->dev_name);
50        return(-1);        return(-1);
51     }     }
52    
53     memset(data,0,sizeof(*data));     memset(data,0,sizeof(*data));
54     data->nr_port = nr_port;     data->nr_port = nr_port;
55    
56       /* Set the PCI bus */
57       card->pci_bus = vm->slots_pci_bus[slot];
58    
59     /* Set the EEPROM */     /* Set the EEPROM */
60     c3600_nm_set_eeprom(router,nm_bay,eeprom);     cisco_card_set_eeprom(vm,card,eeprom);
61       c3600_set_slot_eeprom(VM_C3600(vm),slot,&card->eeprom);
62    
63     /* Get PCI bus info about this bay */     /* Get PCI bus info about this bay */
64     bay_info = c3600_nm_get_bay_info(c3600_chassis_get_id(router),nm_bay);     chassis_id = c3600_chassis_get_id(VM_C3600(vm));
65       bay_info = c3600_nm_get_bay_info(chassis_id,slot);
66                
67     if (!bay_info) {     if (!bay_info) {
68        fprintf(stderr,"%s: unable to get info for NM bay %u\n",name,nm_bay);        vm_error(vm,"unable to get info for NM bay %u\n",slot);
69        return(-1);        return(-1);
70     }     }
71    
72     /* Create the AMD Am971c971 chip(s) */     /* Create the AMD Am971c971 chip(s) */
73     for(i=0;i<data->nr_port;i++) {     for(i=0;i<data->nr_port;i++) {
74        data->port[i] = dev_am79c971_init(router->vm,name,interface_type,        data->port[i] = dev_am79c971_init(vm,card->dev_name,interface_type,
75                                          router->nm_bay[nm_bay].pci_map,                                          card->pci_bus,bay_info->pci_device+i,
76                                          bay_info->pci_device + i,                                          c3600_net_irq_for_slot_port(slot,i));
                                         C3600_NETIO_IRQ);  
77     }     }
78    
79     /* Store device info into the router structure */     /* Store device info into the router structure */
80     return(c3600_nm_set_drvinfo(router,nm_bay,data));     card->drv_info = data;
81       return(0);
82  }  }
83    
84  /* Remove an Ethernet NM from the specified slot */  /* Remove an Ethernet NM from the specified slot */
85  static int dev_c3600_nm_eth_shutdown(c3600_t *router,u_int nm_bay)  static int dev_c3600_nm_eth_shutdown(vm_instance_t *vm,struct cisco_card *card)
86  {  {
87     struct c3600_nm_bay *bay;     struct nm_eth_data *data = card->drv_info;
    struct nm_eth_data *data;  
88     int i;     int i;
89    
    if (!(bay = c3600_nm_get_info(router,nm_bay)))  
       return(-1);  
   
    data = bay->drv_info;  
   
90     /* Remove the NM EEPROM */     /* Remove the NM EEPROM */
91     c3600_nm_unset_eeprom(router,nm_bay);     cisco_card_unset_eeprom(card);
92       c3600_set_slot_eeprom(VM_C3600(vm),card->slot_id,NULL);
93    
94     /* Remove the AMD Am79c971 chips */     /* Remove the AMD Am79c971 chips */
95     for(i=0;i<data->nr_port;i++)     for(i=0;i<data->nr_port;i++)
# Line 97  static int dev_c3600_nm_eth_shutdown(c36 Line 100  static int dev_c3600_nm_eth_shutdown(c36
100  }  }
101    
102  /* Bind a Network IO descriptor */  /* Bind a Network IO descriptor */
103  static int dev_c3600_nm_eth_set_nio(c3600_t *router,u_int nm_bay,  static int dev_c3600_nm_eth_set_nio(vm_instance_t *vm,struct cisco_card *card,
104                                      u_int port_id,netio_desc_t *nio)                                      u_int port_id,netio_desc_t *nio)
105  {  {
106     struct nm_eth_data *d;     struct nm_eth_data *d = card->drv_info;
   
    d = c3600_nm_get_drvinfo(router,nm_bay);  
107    
108     if (!d || (port_id >= d->nr_port))     if (!d || (port_id >= d->nr_port))
109        return(-1);        return(-1);
# Line 112  static int dev_c3600_nm_eth_set_nio(c360 Line 113  static int dev_c3600_nm_eth_set_nio(c360
113  }  }
114    
115  /* Unbind a Network IO descriptor */  /* Unbind a Network IO descriptor */
116  static int dev_c3600_nm_eth_unset_nio(c3600_t *router,u_int nm_bay,  static int dev_c3600_nm_eth_unset_nio(vm_instance_t *vm,
117                                          struct cisco_card *card,
118                                        u_int port_id)                                        u_int port_id)
119  {  {
120     struct nm_eth_data *d;     struct nm_eth_data *d = card->drv_info;
   
    d = c3600_nm_get_drvinfo(router,nm_bay);  
121    
122     if (!d || (port_id >= d->nr_port))     if (!d || (port_id >= d->nr_port))
123        return(-1);        return(-1);
# Line 130  static int dev_c3600_nm_eth_unset_nio(c3 Line 130  static int dev_c3600_nm_eth_unset_nio(c3
130  /* NM-1E                                                                  */  /* NM-1E                                                                  */
131  /* ====================================================================== */  /* ====================================================================== */
132    
 /* NM-1E: 1 Ethernet Network Module EEPROM */  
 static const m_uint16_t eeprom_c3600_nm_1e_data[16] = {  
    0x0143, 0x0100, 0x0075, 0xCD81, 0x500D, 0xA201, 0x0000, 0x0000,  
    0x5800, 0x0000, 0x9803, 0x2000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,  
 };  
   
 static const struct c3600_eeprom eeprom_c3600_nm_1e = {  
    "NM-1E", (m_uint16_t *)eeprom_c3600_nm_1e_data,  
    sizeof(eeprom_c3600_nm_1e_data)/2,  
 };  
   
133  /*  /*
134   * dev_c3600_nm_1e_init()   * dev_c3600_nm_1e_init()
135   *   *
136   * Add a NM-1E Network Module into specified slot.   * Add a NM-1E Network Module into specified slot.
137   */   */
138  static int dev_c3600_nm_1e_init(c3600_t *router,char *name,u_int nm_bay)  static int dev_c3600_nm_1e_init(vm_instance_t *vm,struct cisco_card *card)
139  {  {
140     return(dev_c3600_nm_eth_init(router,name,nm_bay,1,AM79C971_TYPE_10BASE_T,     return(dev_c3600_nm_eth_init(vm,card,1,AM79C971_TYPE_10BASE_T,
141                                  &eeprom_c3600_nm_1e));                                  cisco_eeprom_find_nm("NM-1E")));
142  }  }
143    
144  /* ====================================================================== */  /* ====================================================================== */
145  /* NM-4E                                                                  */  /* NM-4E                                                                  */
146  /* ====================================================================== */  /* ====================================================================== */
147    
 /* NM-4E: 4 Ethernet Network Module EEPROM */  
 static const m_uint16_t eeprom_c3600_nm_4e_data[16] = {  
    0x0142, 0x0100, 0x0075, 0xCD81, 0x500D, 0xA201, 0x0000, 0x0000,  
    0x5800, 0x0000, 0x9803, 0x2000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,  
 };  
   
 static const struct c3600_eeprom eeprom_c3600_nm_4e = {  
    "NM-4E", (m_uint16_t *)eeprom_c3600_nm_4e_data,  
    sizeof(eeprom_c3600_nm_4e_data)/2,  
 };  
   
148  /*  /*
149   * dev_c3600_nm_4e_init()   * dev_c3600_nm_4e_init()
150   *   *
151   * Add a NM-4E Network Module into specified slot.   * Add a NM-4E Network Module into specified slot.
152   */   */
153  static int dev_c3600_nm_4e_init(c3600_t *router,char *name,u_int nm_bay)  static int dev_c3600_nm_4e_init(vm_instance_t *vm,struct cisco_card *card)
154  {  {
155     return(dev_c3600_nm_eth_init(router,name,nm_bay,4,AM79C971_TYPE_10BASE_T,     return(dev_c3600_nm_eth_init(vm,card,4,AM79C971_TYPE_10BASE_T,
156                                  &eeprom_c3600_nm_4e));                                  cisco_eeprom_find_nm("NM-4E")));
157  }  }
158    
159  /* ====================================================================== */  /* ====================================================================== */
160  /* NM-1FE-TX                                                              */  /* NM-1FE-TX                                                              */
161  /* ====================================================================== */  /* ====================================================================== */
162    
 /* NM-1FE-TX: 1 FastEthernet Network Module EEPROM */  
 static const m_uint16_t eeprom_c3600_nm_1fe_tx_data[16] = {  
    0x0144, 0x0100, 0x0075, 0xCD81, 0x500D, 0xA201, 0x0000, 0x0000,  
    0x5800, 0x0000, 0x9803, 0x2000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,  
 };  
   
 static const struct c3600_eeprom eeprom_c3600_nm_1fe_tx = {  
    "NM-1FE-TX", (m_uint16_t *)eeprom_c3600_nm_1fe_tx_data,  
    sizeof(eeprom_c3600_nm_1fe_tx_data)/2,  
 };  
   
163  /*  /*
164   * dev_c3600_nm_1fe_tx_init()   * dev_c3600_nm_1fe_tx_init()
165   *   *
166   * Add a NM-1FE-TX Network Module into specified slot.   * Add a NM-1FE-TX Network Module into specified slot.
167   */   */
168  static int dev_c3600_nm_1fe_tx_init(c3600_t *router,char *name,u_int nm_bay)  static int dev_c3600_nm_1fe_tx_init(vm_instance_t *vm,struct cisco_card *card)
169    {
170       return(dev_c3600_nm_eth_init(vm,card,1,AM79C971_TYPE_100BASE_TX,
171                                    cisco_eeprom_find_nm("NM-1FE-TX")));
172    }
173    
174    /* ====================================================================== */
175    /* NM-16ESW                                                               */
176    /* ====================================================================== */
177    
178    /* Add a NM-16ESW */
179    static int dev_c3600_nm_16esw_init(vm_instance_t *vm,struct cisco_card *card)
180    {
181       struct nm_bay_info *bay_info;
182       struct nm_16esw_data *data;
183       u_int slot = card->slot_id;
184       u_int chassis_id;
185    
186       /* Set the PCI bus */
187       card->pci_bus = vm->slots_pci_bus[slot];
188    
189       /* Set the EEPROM */
190       cisco_card_set_eeprom(vm,card,cisco_eeprom_find_nm("NM-16ESW"));
191       dev_nm_16esw_burn_mac_addr(vm,slot,&card->eeprom);
192       c3600_set_slot_eeprom(VM_C3600(vm),slot,&card->eeprom);
193    
194       /* Get PCI bus info about this bay */
195       chassis_id = c3600_chassis_get_id(VM_C3600(vm));
196       bay_info = c3600_nm_get_bay_info(chassis_id,slot);
197          
198       if (!bay_info) {
199          vm_error(vm,"unable to get info for NM bay %u\n",slot);
200          return(-1);
201       }
202    
203       /* Create the device */
204       data = dev_nm_16esw_init(vm,card->dev_name,slot,
205                                card->pci_bus,bay_info->pci_device,
206                                c3600_net_irq_for_slot_port(slot,0));
207    
208       /* Store device info into the router structure */
209       card->drv_info = data;
210       return(0);
211    }
212    
213    /* Remove a NM-16ESW from the specified slot */
214    static int
215    dev_c3600_nm_16esw_shutdown(vm_instance_t *vm,struct cisco_card *card)
216    {
217       struct nm_16esw_data *data = card->drv_info;
218    
219       /* Remove the NM EEPROM */
220       cisco_card_unset_eeprom(card);
221       c3600_set_slot_eeprom(VM_C3600(vm),card->slot_id,NULL);
222    
223       /* Remove the BCM5600 chip */
224       dev_nm_16esw_remove(data);
225       return(0);
226    }
227    
228    /* Bind a Network IO descriptor */
229    static int
230    dev_c3600_nm_16esw_set_nio(vm_instance_t *vm,struct cisco_card *card,
231                               u_int port_id,netio_desc_t *nio)
232  {  {
233     return(dev_c3600_nm_eth_init(router,name,nm_bay,1,AM79C971_TYPE_100BASE_TX,     struct nm_16esw_data *d = card->drv_info;
234                                  &eeprom_c3600_nm_1fe_tx));     dev_nm_16esw_set_nio(d,port_id,nio);
235       return(0);
236    }
237    
238    /* Unbind a Network IO descriptor */
239    static int dev_c3600_nm_16esw_unset_nio(vm_instance_t *vm,
240                                            struct cisco_card *card,
241                                            u_int port_id)
242    {
243       struct nm_16esw_data *d = card->drv_info;
244       dev_nm_16esw_unset_nio(d,port_id);
245       return(0);
246    }
247    
248    /* Show debug info */
249    static int
250    dev_c3600_nm_16esw_show_info(vm_instance_t *vm,struct cisco_card *card)
251    {
252       struct nm_16esw_data *d = card->drv_info;
253       dev_nm_16esw_show_info(d);
254       return(0);
255  }  }
256    
257  /* ====================================================================== */  /* ====================================================================== */
# Line 224  static m_uint16_t eeprom_c3600_leopard_2 Line 274  static m_uint16_t eeprom_c3600_leopard_2
274     0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFF00,     0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFF00,
275  };  };
276    
277  static const struct c3600_eeprom eeprom_c3600_leopard_2fe = {  static const struct cisco_eeprom eeprom_c3600_leopard_2fe = {
278     "Leopard-2FE", (m_uint16_t *)eeprom_c3600_leopard_2fe_data,     "Leopard-2FE", (m_uint16_t *)eeprom_c3600_leopard_2fe_data,
279     sizeof(eeprom_c3600_leopard_2fe_data)/2,     sizeof(eeprom_c3600_leopard_2fe_data)/2,
280  };  };
# Line 234  static const struct c3600_eeprom eeprom_ Line 284  static const struct c3600_eeprom eeprom_
284   *   *
285   * Add Leopard-2FE (only Cisco 3660, in slot 0).   * Add Leopard-2FE (only Cisco 3660, in slot 0).
286   */   */
287  static int dev_c3600_leopard_2fe_init(c3600_t *router,char *name,u_int nm_bay)  static int
288    dev_c3600_leopard_2fe_init(vm_instance_t *vm,struct cisco_card *card)
289  {  {
290     if (nm_bay != 0) {     if (card->slot_id != 0) {
291        fprintf(stderr,"C3600 %s: Leopard-2FE can only be put in slot 0\n",        vm_error(vm,"dev_c3600_leopard_2fe_init: bad slot %u specified.\n",
292                router->vm->name);                 card->slot_id);
293        return(-1);        return(-1);
294     }     }
295    
296     return(dev_c3600_nm_eth_init(router,name,0,2,AM79C971_TYPE_100BASE_TX,     return(dev_c3600_nm_eth_init(vm,card,2,AM79C971_TYPE_100BASE_TX,
297                                  &eeprom_c3600_leopard_2fe));                                  &eeprom_c3600_leopard_2fe));
298  }  }
299    
300  /* ====================================================================== */  /* ====================================================================== */
301    
302  /* NM-1FE-TX driver */  /* NM-1FE-TX driver */
303  struct c3600_nm_driver dev_c3600_nm_1fe_tx_driver = {  struct cisco_card_driver dev_c3600_nm_1fe_tx_driver = {
304     "NM-1FE-TX", 1, 0,     "NM-1FE-TX", 1, 0,
305     dev_c3600_nm_1fe_tx_init,     dev_c3600_nm_1fe_tx_init,
306     dev_c3600_nm_eth_shutdown,     dev_c3600_nm_eth_shutdown,
307       NULL,
308     dev_c3600_nm_eth_set_nio,     dev_c3600_nm_eth_set_nio,
309     dev_c3600_nm_eth_unset_nio,     dev_c3600_nm_eth_unset_nio,
310     NULL,     NULL,
311  };  };
312    
313  /* NM-1E driver */  /* NM-1E driver */
314  struct c3600_nm_driver dev_c3600_nm_1e_driver = {  struct cisco_card_driver dev_c3600_nm_1e_driver = {
315     "NM-1E", 1, 0,     "NM-1E", 1, 0,
316     dev_c3600_nm_1e_init,     dev_c3600_nm_1e_init,
317     dev_c3600_nm_eth_shutdown,     dev_c3600_nm_eth_shutdown,
318       NULL,
319     dev_c3600_nm_eth_set_nio,     dev_c3600_nm_eth_set_nio,
320     dev_c3600_nm_eth_unset_nio,     dev_c3600_nm_eth_unset_nio,
321     NULL,     NULL,
322  };  };
323    
324  /* NM-4E driver */  /* NM-4E driver */
325  struct c3600_nm_driver dev_c3600_nm_4e_driver = {  struct cisco_card_driver dev_c3600_nm_4e_driver = {
326     "NM-4E", 1, 0,     "NM-4E", 1, 0,
327     dev_c3600_nm_4e_init,     dev_c3600_nm_4e_init,
328     dev_c3600_nm_eth_shutdown,     dev_c3600_nm_eth_shutdown,
329       NULL,
330     dev_c3600_nm_eth_set_nio,     dev_c3600_nm_eth_set_nio,
331     dev_c3600_nm_eth_unset_nio,     dev_c3600_nm_eth_unset_nio,
332     NULL,     NULL,
333  };  };
334    
335    /* NM-16ESW driver */
336    struct cisco_card_driver dev_c3600_nm_16esw_driver = {
337       "NM-16ESW", 1, 0,
338       dev_c3600_nm_16esw_init,
339       dev_c3600_nm_16esw_shutdown,
340       NULL,
341       dev_c3600_nm_16esw_set_nio,
342       dev_c3600_nm_16esw_unset_nio,
343       dev_c3600_nm_16esw_show_info,
344    };
345    
346  /* Leopard-2FE driver */  /* Leopard-2FE driver */
347  struct c3600_nm_driver dev_c3600_leopard_2fe_driver = {  struct cisco_card_driver dev_c3600_leopard_2fe_driver = {
348     "Leopard-2FE", 1, 0,     "Leopard-2FE", 1, 0,
349     dev_c3600_leopard_2fe_init,     dev_c3600_leopard_2fe_init,
350     dev_c3600_nm_eth_shutdown,     dev_c3600_nm_eth_shutdown,
351       NULL,
352     dev_c3600_nm_eth_set_nio,     dev_c3600_nm_eth_set_nio,
353     dev_c3600_nm_eth_unset_nio,     dev_c3600_nm_eth_unset_nio,
354     NULL,     NULL,

Legend:
Removed from v.2  
changed lines
  Added in v.12

  ViewVC Help
Powered by ViewVC 1.1.26