/[dynamips]/upstream/dynamips-0.2.8-RC1/dev_c3745_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 /upstream/dynamips-0.2.8-RC1/dev_c3745_eth.c

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

upstream/dynamips-0.2.7/dev_c3745_eth.c revision 10 by dpavlin, Sat Oct 6 16:29:14 2007 UTC upstream/dynamips-0.2.8-RC1/dev_c3745_eth.c revision 11 by dpavlin, Sat Oct 6 16:33:40 2007 UTC
# Line 29  struct nm_eth_data { Line 29  struct nm_eth_data {
29     struct am79c971_data *port[8];     struct am79c971_data *port[8];
30  };  };
31    
32    /* Return sub-slot info for integrated WIC slots (on motherboard) */
33    static int dev_c3745_mb_get_sub_info(vm_instance_t *vm,struct cisco_card *card,
34                                         u_int port_id,
35                                         struct cisco_card_driver ***drv_array,
36                                         u_int *subcard_type)
37    {
38       /* 3 integrated WIC slots */
39       if ((port_id & 0x0F) >= 3)
40          return(-1);
41    
42       *drv_array = dev_c3745_mb_wic_drivers;
43       *subcard_type = CISCO_CARD_TYPE_WIC;
44       return(0);
45    }
46    
47  /*  /*
48   * dev_c3745_nm_eth_init()   * dev_c3745_nm_eth_init()
49   *   *
50   * Add an Ethernet Network Module into specified slot.   * Add an Ethernet Network Module into specified slot.
51   */   */
52  static int dev_c3745_nm_eth_init(c3745_t *router,char *name,u_int nm_bay,  static int dev_c3745_nm_eth_init(vm_instance_t *vm,struct cisco_card *card,
53                                   int nr_port,int interface_type,                                   int nr_port,int interface_type,
54                                   const struct cisco_eeprom *eeprom)                                   const struct cisco_eeprom *eeprom)
55  {  {
56     struct nm_eth_data *data;     struct nm_eth_data *data;
57       u_int slot = card->slot_id;
58     int i;     int i;
59    
60     /* Allocate the private data structure */     /* Allocate the private data structure */
61     if (!(data = malloc(sizeof(*data)))) {     if (!(data = malloc(sizeof(*data)))) {
62        fprintf(stderr,"%s: out of memory\n",name);        vm_error(vm,"%s: out of memory.\n",card->dev_name);
63        return(-1);        return(-1);
64     }     }
65    
66     memset(data,0,sizeof(*data));     memset(data,0,sizeof(*data));
67     data->nr_port = nr_port;     data->nr_port = nr_port;
68    
69       /* Set the PCI bus */
70       card->pci_bus = vm->slots_pci_bus[slot];
71    
72     /* Set the EEPROM */     /* Set the EEPROM */
73     c3745_nm_set_eeprom(router,nm_bay,eeprom);     cisco_card_set_eeprom(vm,card,eeprom);
74       c3745_set_slot_eeprom(VM_C3745(vm),slot,&card->eeprom);
75    
76     /* Create the AMD Am971c971 chip(s) */     /* Create the AMD Am971c971 chip(s) */
77     for(i=0;i<data->nr_port;i++) {     for(i=0;i<data->nr_port;i++) {
78        data->port[i] = dev_am79c971_init(router->vm,name,interface_type,        data->port[i] = dev_am79c971_init(vm,card->dev_name,interface_type,
79                                          router->nm_bay[nm_bay].pci_map,0,                                          card->pci_bus,0,
80                                          c3745_net_irq_for_slot_port(nm_bay,0));                                          c3745_net_irq_for_slot_port(slot,0));
81     }     }
82    
83     /* Store device info into the router structure */     /* Store device info into the router structure */
84     return(c3745_nm_set_drvinfo(router,nm_bay,data));     card->drv_info = data;
85       return(0);
86  }  }
87    
88  /* Remove an Ethernet NM from the specified slot */  /* Remove an Ethernet NM from the specified slot */
89  static int dev_c3745_nm_eth_shutdown(c3745_t *router,u_int nm_bay)  static int dev_c3745_nm_eth_shutdown(vm_instance_t *vm,struct cisco_card *card)
90  {  {
91     struct c3745_nm_bay *bay;     struct nm_eth_data *data = card->drv_info;
    struct nm_eth_data *data;  
92     int i;     int i;
93    
    if (!(bay = c3745_nm_get_info(router,nm_bay)))  
       return(-1);  
   
    data = bay->drv_info;  
   
94     /* Remove the NM EEPROM */     /* Remove the NM EEPROM */
95     c3745_nm_unset_eeprom(router,nm_bay);     cisco_card_unset_eeprom(card);
96       c3745_set_slot_eeprom(VM_C3745(vm),card->slot_id,NULL);
97    
98     /* Remove the AMD Am79c971 chips */     /* Remove the AMD Am79c971 chips */
99     for(i=0;i<data->nr_port;i++)     for(i=0;i<data->nr_port;i++)
# Line 88  static int dev_c3745_nm_eth_shutdown(c37 Line 104  static int dev_c3745_nm_eth_shutdown(c37
104  }  }
105    
106  /* Bind a Network IO descriptor */  /* Bind a Network IO descriptor */
107  static int dev_c3745_nm_eth_set_nio(c3745_t *router,u_int nm_bay,  static int dev_c3745_nm_eth_set_nio(vm_instance_t *vm,struct cisco_card *card,
108                                      u_int port_id,netio_desc_t *nio)                                      u_int port_id,netio_desc_t *nio)
109  {  {
110     struct nm_eth_data *d;     struct nm_eth_data *d = card->drv_info;
   
    d = c3745_nm_get_drvinfo(router,nm_bay);  
111    
112     if (!d || (port_id >= d->nr_port))     if (!d || (port_id >= d->nr_port))
113        return(-1);        return(-1);
# Line 103  static int dev_c3745_nm_eth_set_nio(c374 Line 117  static int dev_c3745_nm_eth_set_nio(c374
117  }  }
118    
119  /* Unbind a Network IO descriptor */  /* Unbind a Network IO descriptor */
120  static int dev_c3745_nm_eth_unset_nio(c3745_t *router,u_int nm_bay,  static int dev_c3745_nm_eth_unset_nio(vm_instance_t *vm,
121                                          struct cisco_card *card,
122                                        u_int port_id)                                        u_int port_id)
123  {  {
124     struct nm_eth_data *d;     struct nm_eth_data *d = card->drv_info;
   
    d = c3745_nm_get_drvinfo(router,nm_bay);  
125    
126     if (!d || (port_id >= d->nr_port))     if (!d || (port_id >= d->nr_port))
127        return(-1);        return(-1);
# Line 126  static int dev_c3745_nm_eth_unset_nio(c3 Line 139  static int dev_c3745_nm_eth_unset_nio(c3
139   *   *
140   * Add a NM-1FE-TX Network Module into specified slot.   * Add a NM-1FE-TX Network Module into specified slot.
141   */   */
142  static int dev_c3745_nm_1fe_tx_init(c3745_t *router,char *name,u_int nm_bay)  static int dev_c3745_nm_1fe_tx_init(vm_instance_t *vm,struct cisco_card *card)
143  {  {
144     return(dev_c3745_nm_eth_init(router,name,nm_bay,1,AM79C971_TYPE_100BASE_TX,     return(dev_c3745_nm_eth_init(vm,card,1,AM79C971_TYPE_100BASE_TX,
145                                  cisco_eeprom_find_nm("NM-1FE-TX")));                                  cisco_eeprom_find_nm("NM-1FE-TX")));
146  }  }
147    
# Line 137  static int dev_c3745_nm_1fe_tx_init(c374 Line 150  static int dev_c3745_nm_1fe_tx_init(c374
150  /* ====================================================================== */  /* ====================================================================== */
151    
152  /* Add a NM-16ESW */  /* Add a NM-16ESW */
153  static int dev_c3745_nm_16esw_init(c3745_t *router,char *name,u_int nm_bay)  static int dev_c3745_nm_16esw_init(vm_instance_t *vm,struct cisco_card *card)
154  {  {
155     struct nm_16esw_data *data;     struct nm_16esw_data *data;
156       u_int slot = card->slot_id;
157    
158       /* Set the PCI bus */
159       card->pci_bus = vm->slots_pci_bus[slot];
160    
161     /* Set the EEPROM */     /* Set the EEPROM */
162     c3745_nm_set_eeprom(router,nm_bay,cisco_eeprom_find_nm("NM-16ESW"));     cisco_card_set_eeprom(vm,card,cisco_eeprom_find_nm("NM-16ESW"));
163     dev_nm_16esw_burn_mac_addr(router->vm,nm_bay,     dev_nm_16esw_burn_mac_addr(vm,slot,&card->eeprom);
164                                &router->nm_bay[nm_bay].eeprom);     c3745_set_slot_eeprom(VM_C3745(vm),slot,&card->eeprom);
165    
166     /* Create the device */     /* Create the device */
167     data = dev_nm_16esw_init(router->vm,name,nm_bay,     data = dev_nm_16esw_init(vm,card->dev_name,slot,card->pci_bus,0,
168                              router->nm_bay[nm_bay].pci_map,0,                              c3745_net_irq_for_slot_port(slot,0));
                             c3745_net_irq_for_slot_port(nm_bay,0));  
169    
170     /* Store device info into the router structure */     /* Store device info into the router structure */
171     return(c3745_nm_set_drvinfo(router,nm_bay,data));     card->drv_info = data;
172       return(0);
173  }  }
174    
175  /* Remove a NM-16ESW from the specified slot */  /* Remove a NM-16ESW from the specified slot */
176  static int dev_c3745_nm_16esw_shutdown(c3745_t *router,u_int nm_bay)  static int
177    dev_c3745_nm_16esw_shutdown(vm_instance_t *vm,struct cisco_card *card)
178  {  {
179     struct c3745_nm_bay *bay;     struct nm_16esw_data *data = card->drv_info;
    struct nm_16esw_data *data;  
   
    if (!(bay = c3745_nm_get_info(router,nm_bay)))  
       return(-1);  
   
    data = bay->drv_info;  
180    
181     /* Remove the NM EEPROM */     /* Remove the NM EEPROM */
182     c3745_nm_unset_eeprom(router,nm_bay);     cisco_card_unset_eeprom(card);
183       c3745_set_slot_eeprom(VM_C3745(vm),card->slot_id,NULL);
184    
185     /* Remove the BCM5600 chip */     /* Remove the BCM5600 chip */
186     dev_nm_16esw_remove(data);     dev_nm_16esw_remove(data);
# Line 175  static int dev_c3745_nm_16esw_shutdown(c Line 188  static int dev_c3745_nm_16esw_shutdown(c
188  }  }
189    
190  /* Bind a Network IO descriptor */  /* Bind a Network IO descriptor */
191  static int dev_c3745_nm_16esw_set_nio(c3745_t *router,u_int nm_bay,  static int
192                                        u_int port_id,netio_desc_t *nio)  dev_c3745_nm_16esw_set_nio(vm_instance_t *vm,struct cisco_card *card,
193                               u_int port_id,netio_desc_t *nio)
194  {  {
195     struct nm_16esw_data *d;     struct nm_16esw_data *d = card->drv_info;
   
    d = c3745_nm_get_drvinfo(router,nm_bay);  
196     dev_nm_16esw_set_nio(d,port_id,nio);     dev_nm_16esw_set_nio(d,port_id,nio);
197     return(0);     return(0);
198  }  }
199    
200  /* Unbind a Network IO descriptor */  /* Unbind a Network IO descriptor */
201  static int dev_c3745_nm_16esw_unset_nio(c3745_t *router,u_int nm_bay,  static int dev_c3745_nm_16esw_unset_nio(vm_instance_t *vm,
202                                            struct cisco_card *card,
203                                          u_int port_id)                                          u_int port_id)
204  {  {
205     struct nm_16esw_data *d;     struct nm_16esw_data *d = card->drv_info;
   
    d = c3745_nm_get_drvinfo(router,nm_bay);  
206     dev_nm_16esw_unset_nio(d,port_id);     dev_nm_16esw_unset_nio(d,port_id);
207     return(0);     return(0);
208  }  }
209    
210  /* Show debug info */  /* Show debug info */
211  static int dev_c3745_nm_16esw_show_info(c3745_t *router,u_int nm_bay)  static int
212    dev_c3745_nm_16esw_show_info(vm_instance_t *vm,struct cisco_card *card)
213  {  {
214     struct nm_16esw_data *d;     struct nm_16esw_data *d = card->drv_info;
   
    d = c3745_nm_get_drvinfo(router,nm_bay);  
215     dev_nm_16esw_show_info(d);     dev_nm_16esw_show_info(d);
216     return(0);     return(0);
217  }  }
# Line 211  static int dev_c3745_nm_16esw_show_info( Line 221  static int dev_c3745_nm_16esw_show_info(
221  /* ====================================================================== */  /* ====================================================================== */
222    
223  /* Initialize Ethernet part of the GT96100 controller */  /* Initialize Ethernet part of the GT96100 controller */
224  static int dev_c3745_gt96100_fe_init(c3745_t *router,char *name,u_int nm_bay)  static int dev_c3745_gt96100_fe_init(vm_instance_t *vm,struct cisco_card *card)
225  {  {
226     vm_obj_t *obj;     if (card->slot_id != 0) {
227          vm_error(vm,"dev_c3745_gt96100_fe_init: bad slot %u specified.\n",
228     if (nm_bay != 0) {                 card->slot_id);
       fprintf(stderr,"dev_c3745_gt96100_fe_init: bad slot specified.\n");  
       return(-1);  
    }  
   
    if (!(obj = vm_object_find(router->vm,"gt96100"))) {  
       fprintf(stderr,"dev_c3745_gt96100_fe_init: unable to find "  
               "system controller!\n");  
229        return(-1);        return(-1);
230     }     }
231    
232     /* Store device info into the router structure */     /* Store device info into the router structure */
233     return(c3745_nm_set_drvinfo(router,0,obj->data));     card->drv_info = VM_C3745(vm)->gt_data;
234       return(0);
235  }  }
236    
237  /* Nothing to do, we never remove the system controller */  /* Nothing to do, we never remove the system controller */
238  static int dev_c3745_gt96100_fe_shutdown(c3745_t *router,u_int nm_bay)  static int
239    dev_c3745_gt96100_fe_shutdown(vm_instance_t *vm,struct cisco_card *card)
240  {    {  
241     return(0);     return(0);
242  }  }
243    
244  /* Bind a Network IO descriptor */  /* Bind a Network IO descriptor */
245  static int dev_c3745_gt96100_fe_set_nio(c3745_t *router,u_int nm_bay,  static int
246                                          u_int port_id,netio_desc_t *nio)  dev_c3745_gt96100_fe_set_nio(vm_instance_t *vm,struct cisco_card *card,
247                                 u_int port_id,netio_desc_t *nio)
248  {  {
249     struct gt_data *d;     struct gt_data *d = card->drv_info;
250       dev_gt96100_eth_set_nio(d,port_id,nio);
    if (!(d = c3745_nm_get_drvinfo(router,nm_bay)))  
       return(-1);  
   
    dev_gt96100_set_nio(d,port_id,nio);  
251     return(0);     return(0);
252  }  }
253    
254  /* Unbind a Network IO descriptor */  /* Unbind a Network IO descriptor */
255  static int dev_c3745_gt96100_fe_unset_nio(c3745_t *router,u_int nm_bay,  static int dev_c3745_gt96100_fe_unset_nio(vm_instance_t *vm,
256                                          u_int port_id)                                            struct cisco_card *card,
257                                              u_int port_id)
258  {  {
259     struct gt_data *d;     struct gt_data *d = card->drv_info;
260       dev_gt96100_eth_unset_nio(d,port_id);
    if (!(d = c3745_nm_get_drvinfo(router,nm_bay)))  
       return(-1);  
   
    dev_gt96100_unset_nio(d,port_id);  
261     return(0);     return(0);
262  }  }
263    
264  /* ====================================================================== */  /* ====================================================================== */
265    
266  /* NM-1FE-TX driver */  /* NM-1FE-TX driver */
267  struct c3745_nm_driver dev_c3745_nm_1fe_tx_driver = {  struct cisco_card_driver dev_c3745_nm_1fe_tx_driver = {
268     "NM-1FE-TX", 1, 0,     "NM-1FE-TX", 1, 0,
269     dev_c3745_nm_1fe_tx_init,     dev_c3745_nm_1fe_tx_init,
270     dev_c3745_nm_eth_shutdown,     dev_c3745_nm_eth_shutdown,
271       NULL,
272     dev_c3745_nm_eth_set_nio,     dev_c3745_nm_eth_set_nio,
273     dev_c3745_nm_eth_unset_nio,     dev_c3745_nm_eth_unset_nio,
274     NULL,     NULL,
275  };  };
276    
277  /* NM-16ESW driver */  /* NM-16ESW driver */
278  struct c3745_nm_driver dev_c3745_nm_16esw_driver = {  struct cisco_card_driver dev_c3745_nm_16esw_driver = {
279     "NM-16ESW", 1, 0,     "NM-16ESW", 1, 0,
280     dev_c3745_nm_16esw_init,     dev_c3745_nm_16esw_init,
281     dev_c3745_nm_16esw_shutdown,     dev_c3745_nm_16esw_shutdown,
282       NULL,
283     dev_c3745_nm_16esw_set_nio,     dev_c3745_nm_16esw_set_nio,
284     dev_c3745_nm_16esw_unset_nio,     dev_c3745_nm_16esw_unset_nio,
285     dev_c3745_nm_16esw_show_info,     dev_c3745_nm_16esw_show_info,
286  };  };
287    
288  /* GT96100 FastEthernet integrated ports */  /* GT96100 FastEthernet integrated ports */
289  struct c3745_nm_driver dev_c3745_gt96100_fe_driver = {  struct cisco_card_driver dev_c3745_gt96100_fe_driver = {
290     "GT96100-FE", 1, 0,     "GT96100-FE", 1, 0,
291     dev_c3745_gt96100_fe_init,     dev_c3745_gt96100_fe_init,
292     dev_c3745_gt96100_fe_shutdown,     dev_c3745_gt96100_fe_shutdown,
293       dev_c3745_mb_get_sub_info,
294     dev_c3745_gt96100_fe_set_nio,     dev_c3745_gt96100_fe_set_nio,
295     dev_c3745_gt96100_fe_unset_nio,     dev_c3745_gt96100_fe_unset_nio,
296     NULL,     NULL,

Legend:
Removed from v.10  
changed lines
  Added in v.11

  ViewVC Help
Powered by ViewVC 1.1.26