/[dynamips]/trunk/dev_nm_16esw.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_nm_16esw.c

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

upstream/dynamips-0.2.6-RC4/dev_nm_16esw.c revision 5 by dpavlin, Sat Oct 6 16:08:03 2007 UTC upstream/dynamips-0.2.7-RC1/dev_nm_16esw.c revision 7 by dpavlin, Sat Oct 6 16:23:47 2007 UTC
# Line 31  Line 31 
31  #define DEBUG_UNKNOWN    0  #define DEBUG_UNKNOWN    0
32  #define DEBUG_MII        0  #define DEBUG_MII        0
33  #define DEBUG_MEM        0  #define DEBUG_MEM        0
34  #define DEBUG_REG        1  #define DEBUG_REG        0
35  #define DEBUG_TRANSMIT   0  #define DEBUG_TRANSMIT   0
36  #define DEBUG_RECEIVE    0  #define DEBUG_RECEIVE    0
37  #define DEBUG_FORWARD    0  #define DEBUG_FORWARD    0
# Line 1395  static void bcm5600_handle_schan_cmd(str Line 1395  static void bcm5600_handle_schan_cmd(str
1395     switch(cmd) {     switch(cmd) {
1396        case BCM5600_SCHAN_CMD_EXEC:        case BCM5600_SCHAN_CMD_EXEC:
1397           bcm5600_handle_gen_cmd(d);           bcm5600_handle_gen_cmd(d);
1398           d->schan_cmd_res = 0xFFFFFFFF;           d->schan_cmd_res = 0x00008002;
1399           break;           break;
1400    
1401        case BCM5600_SCHAN_CMD_READ_MII:        case BCM5600_SCHAN_CMD_READ_MII:
1402           bcm5600_mii_read(d);           bcm5600_mii_read(d);
1403           d->schan_cmd_res = 0xFFFFFFFF;           d->schan_cmd_res = 0x00048000;
1404           break;           break;
1405    
1406        case BCM5600_SCHAN_CMD_WRITE_MII:        case BCM5600_SCHAN_CMD_WRITE_MII:
1407           bcm5600_mii_write(d);           bcm5600_mii_write(d);
1408           d->schan_cmd_res = 0xFFFFFFFF;           d->schan_cmd_res = 0x00048000;
1409           break;           break;
1410    
1411        case BCM5600_SCHAN_CMD_LINKSCAN:        case BCM5600_SCHAN_CMD_LINKSCAN:
# Line 1423  static void bcm5600_handle_schan_cmd(str Line 1423  static void bcm5600_handle_schan_cmd(str
1423  /*  /*
1424   * dev_bcm5605_access()   * dev_bcm5605_access()
1425   */   */
1426  void *dev_bcm5605_access(cpu_mips_t *cpu,struct vdevice *dev,m_uint32_t offset,  void *dev_bcm5605_access(cpu_gen_t *cpu,struct vdevice *dev,m_uint32_t offset,
1427                           u_int op_size,u_int op_type,m_uint64_t *data)                           u_int op_size,u_int op_type,m_uint64_t *data)
1428  {  {
1429     struct nm_16esw_data *d = dev->priv_data;     struct nm_16esw_data *d = dev->priv_data;
# Line 1434  void *dev_bcm5605_access(cpu_mips_t *cpu Line 1434  void *dev_bcm5605_access(cpu_mips_t *cpu
1434    
1435  #if DEBUG_ACCESS  #if DEBUG_ACCESS
1436     if (op_type == MTS_READ) {     if (op_type == MTS_READ) {
1437        BCM_LOG(d,"read  access to offset=0x%x, pc=0x%llx\n",offset,cpu->pc);        BCM_LOG(d,"read  access to offset=0x%x, pc=0x%llx\n",
1438                  offset,cpu_get_pc(cpu));
1439     } else {     } else {
1440        BCM_LOG(d,"write access to offset=0x%x, pc=0x%llx, val=0x%llx\n",        BCM_LOG(d,"write access to offset=0x%x, pc=0x%llx, val=0x%llx\n",
1441                offset,cpu->pc,*data);                offset,cpu_get_pc(cpu),*data);
1442     }     }
1443  #endif  #endif
1444    
# Line 1545  void *dev_bcm5605_access(cpu_mips_t *cpu Line 1546  void *dev_bcm5605_access(cpu_mips_t *cpu
1546        default:        default:
1547           if (op_type == MTS_READ) {           if (op_type == MTS_READ) {
1548              BCM_LOG(d,"read from unknown addr 0x%x, pc=0x%llx (size=%u)\n",              BCM_LOG(d,"read from unknown addr 0x%x, pc=0x%llx (size=%u)\n",
1549                      offset,cpu->pc,op_size);                      offset,cpu_get_pc(cpu),op_size);
1550           } else {           } else {
1551              BCM_LOG(d,"write to unknown addr 0x%x, value=0x%llx, "              BCM_LOG(d,"write to unknown addr 0x%x, value=0x%llx, "
1552                      "pc=0x%llx (size=%u)\n",offset,*data,cpu->pc,op_size);                      "pc=0x%llx (size=%u)\n",
1553                        offset,*data,cpu_get_pc(cpu),op_size);
1554           }           }
1555  #endif  #endif
1556     }     }
# Line 2058  static int bcm5600_forward_pkt(struct nm Line 2060  static int bcm5600_forward_pkt(struct nm
2060     return(TRUE);     return(TRUE);
2061  }  }
2062    
2063    /* Determine if the specified MAC address matches a BPDU */
2064    static inline int bcm5600_is_bpdu(n_eth_addr_t *m)
2065    {
2066       /* PVST+ */
2067       if (!memcmp(m,"\x01\x00\x0c\xcc\xcc\xcd",6))
2068          return(TRUE);
2069    
2070       /* Classical 802.1D */
2071       if (!memcmp(m,"\x01\x80\xc2\x00\x00",5) && !(m->eth_addr_byte[5] & 0xF0))
2072          return(TRUE);
2073    
2074       return(FALSE);
2075    }
2076    
2077  /* Handle a received packet */  /* Handle a received packet */
2078  static int bcm5600_handle_rx_pkt(struct nm_16esw_data *d,struct bcm5600_pkt *p)  static int bcm5600_handle_rx_pkt(struct nm_16esw_data *d,struct bcm5600_pkt *p)
2079  {  {
# Line 2077  static int bcm5600_handle_rx_pkt(struct Line 2093  static int bcm5600_handle_rx_pkt(struct
2093     /* Analyze the Ethernet header */     /* Analyze the Ethernet header */
2094     eth_hdr = (n_eth_dot1q_hdr_t *)p->pkt;     eth_hdr = (n_eth_dot1q_hdr_t *)p->pkt;
2095    
2096       /* Determine VLAN */
2097       if (ntohs(eth_hdr->type) != N_ETH_PROTO_DOT1Q) {
2098          p->orig_vlan = -1;
2099          p->real_vlan = port_entry[0] & BCM5600_PTABLE_VLAN_TAG_MASK;
2100    
2101         /* TODO: 802.1p/CoS remarking */
2102         if (port_entry[4] & BCM5600_PTABLE_RPE_FLAG) {
2103         }
2104       } else {
2105          p->orig_vlan = p->real_vlan = ntohs(eth_hdr->vlan_id) & 0xFFF;
2106       }
2107    
2108       /* Check that this VLAN exists */
2109       if (!(p->vlan_entry = bcm5600_vtable_get_entry_by_vlan(d,p->real_vlan)))
2110          return(FALSE);
2111    
2112     /* Check for the reserved addresses (BPDU for spanning-tree) */     /* Check for the reserved addresses (BPDU for spanning-tree) */
2113     if (!memcmp(&eth_hdr->daddr,"\x01\x80\xc2\x00\x00",5) ||     if (bcm5600_is_bpdu(&eth_hdr->daddr)) {
        !memcmp(&eth_hdr->daddr,"\x01\x00\x0c\xcc\xcc\xcd",6))  
    {  
2114  #if DEBUG_RECEIVE  #if DEBUG_RECEIVE
2115        BCM_LOG(d,"Received a BPDU packet:\n");        BCM_LOG(d,"Received a BPDU packet:\n");
2116        mem_dump(d->vm->log_fd,p->pkt,p->pkt_len);        mem_dump(d->vm->log_fd,p->pkt,p->pkt_len);
2117  #endif  #endif
       p->orig_vlan = 0;  
2118        p->egress_bitmap |= 1 << d->cpu_port;        p->egress_bitmap |= 1 << d->cpu_port;
2119        return(bcm5600_forward_pkt(d,p));        return(bcm5600_forward_pkt(d,p));
2120     }     }
2121    
2122       /* Check that this port is a member of this VLAN */
2123       if (!(p->vlan_entry[1] & (1 << p->ingress_port)))
2124          return(FALSE);
2125    
2126     /* Discard packet ? */     /* Discard packet ? */
2127     discard = port_entry[0] & BCM5600_PTABLE_PRT_DIS_MASK;     discard = port_entry[0] & BCM5600_PTABLE_PRT_DIS_MASK;
2128     discard >>= BCM5600_PTABLE_PRT_DIS_SHIFT;     discard >>= BCM5600_PTABLE_PRT_DIS_SHIFT;
2129    
2130     if (discard) {     if ((p->orig_vlan == -1) && discard) {
2131        if (discard != 0x20) {        if (discard != 0x20) {
2132           printf("\n\n\n"           printf("\n\n\n"
2133                  "-----------------------------------------------------------"                  "-----------------------------------------------------------"
# Line 2113  static int bcm5600_handle_rx_pkt(struct Line 2146  static int bcm5600_handle_rx_pkt(struct
2146     if (port_entry[1] & BCM5600_PTABLE_MI_FLAG)     if (port_entry[1] & BCM5600_PTABLE_MI_FLAG)
2147        bcm5600_mirror_pkt(d,p,0);        bcm5600_mirror_pkt(d,p,0);
2148    
    /* Determine VLAN */  
    if (ntohs(eth_hdr->type) != N_ETH_PROTO_DOT1Q) {  
       p->orig_vlan = -1;  
       p->real_vlan = port_entry[0] & BCM5600_PTABLE_VLAN_TAG_MASK;  
   
      if (!(p->vlan_entry = bcm5600_vtable_get_entry_by_vlan(d,p->real_vlan)))  
         return(FALSE);  
   
      /* TODO: 802.1p/CoS remarking */  
      if (port_entry[4] & BCM5600_PTABLE_RPE_FLAG) {  
      }  
    } else {  
       p->orig_vlan = p->real_vlan = ntohs(eth_hdr->vlan_id) & 0xFFF;  
   
       /* Check that this VLAN exists */  
       if (!(p->vlan_entry = bcm5600_vtable_get_entry_by_vlan(d,p->real_vlan)))  
          return(FALSE);  
   
       /* Check that this port is a member of this VLAN */  
       if (!(p->vlan_entry[1] & (1 << p->ingress_port)))  
          return(FALSE);  
    }  
   
2149  #if DEBUG_RECEIVE  #if DEBUG_RECEIVE
2150     BCM_LOG(d,"%s: received a packet on VLAN %u\n",     BCM_LOG(d,"%s: received a packet on VLAN %u\n",
2151             d->ports[p->ingress_port].name,p->real_vlan);             d->ports[p->ingress_port].name,p->real_vlan);
# Line 2353  static int dev_bcm5600_handle_rxring(net Line 2363  static int dev_bcm5600_handle_rxring(net
2363  }  }
2364    
2365  /* pci_bcm5605_read() */  /* pci_bcm5605_read() */
2366  static m_uint32_t pci_bcm5605_read(cpu_mips_t *cpu,struct pci_device *dev,  static m_uint32_t pci_bcm5605_read(cpu_gen_t *cpu,struct pci_device *dev,
2367                                     int reg)                                     int reg)
2368  {  {
2369     struct nm_16esw_data *d = dev->priv_data;     struct nm_16esw_data *d = dev->priv_data;
# Line 2367  static m_uint32_t pci_bcm5605_read(cpu_m Line 2377  static m_uint32_t pci_bcm5605_read(cpu_m
2377  }  }
2378    
2379  /* pci_bcm5605_write() */  /* pci_bcm5605_write() */
2380  static void pci_bcm5605_write(cpu_mips_t *cpu,struct pci_device *dev,  static void pci_bcm5605_write(cpu_gen_t *cpu,struct pci_device *dev,
2381                                int reg,m_uint32_t value)                                int reg,m_uint32_t value)
2382  {  {
2383     struct nm_16esw_data *d = dev->priv_data;     struct nm_16esw_data *d = dev->priv_data;

Legend:
Removed from v.5  
changed lines
  Added in v.7

  ViewVC Help
Powered by ViewVC 1.1.26