| 1 |
/* |
| 2 |
* Cisco router simulation platform. |
| 3 |
* Copyright (c) 2006 Christophe Fillot ([email protected]) |
| 4 |
* |
| 5 |
* NM-16ESW ethernet switch module (experimental!) |
| 6 |
* |
| 7 |
* It's an attempt of proof of concept, so not optimized at all at this time. |
| 8 |
* Only L2 switching will be managed (no L3 at all). |
| 9 |
* |
| 10 |
* To do next: QoS features (CoS/DSCP handling). |
| 11 |
*/ |
| 12 |
|
| 13 |
#include <stdio.h> |
| 14 |
#include <stdlib.h> |
| 15 |
#include <string.h> |
| 16 |
#include <stdarg.h> |
| 17 |
#include <unistd.h> |
| 18 |
#include <time.h> |
| 19 |
#include <errno.h> |
| 20 |
#include <assert.h> |
| 21 |
|
| 22 |
#include "utils.h" |
| 23 |
#include "timer.h" |
| 24 |
#include "net.h" |
| 25 |
#include "net_io.h" |
| 26 |
#include "ptask.h" |
| 27 |
#include "dev_nm_16esw.h" |
| 28 |
|
| 29 |
/* Debugging flags */ |
| 30 |
#define DEBUG_ACCESS 0 |
| 31 |
#define DEBUG_UNKNOWN 0 |
| 32 |
#define DEBUG_MII 0 |
| 33 |
#define DEBUG_MEM 0 |
| 34 |
#define DEBUG_REG 0 |
| 35 |
#define DEBUG_TRANSMIT 0 |
| 36 |
#define DEBUG_RECEIVE 0 |
| 37 |
#define DEBUG_FORWARD 0 |
| 38 |
#define DEBUG_MIRROR 0 |
| 39 |
#define DEBUG_ARL 0 |
| 40 |
|
| 41 |
/* Invalid VLAN value */ |
| 42 |
#define VLAN_INVALID 0xFFF |
| 43 |
|
| 44 |
/* Maximum packet size */ |
| 45 |
#define BCM5600_MAX_PKT_SIZE 2048 |
| 46 |
|
| 47 |
/* PCI vendor/product codes */ |
| 48 |
#define BCM5605_PCI_VENDOR_ID 0x14e4 |
| 49 |
#define BCM5605_PCI_PRODUCT_ID 0x5605 |
| 50 |
|
| 51 |
/* "S-channel" commands */ |
| 52 |
#define BCM5600_SCHAN_CMD_LINKSCAN 0x13 |
| 53 |
#define BCM5600_SCHAN_CMD_EXEC 0x80 |
| 54 |
#define BCM5600_SCHAN_CMD_READ_MII 0x90 |
| 55 |
#define BCM5600_SCHAN_CMD_WRITE_MII 0x91 |
| 56 |
|
| 57 |
/* Opcodes */ |
| 58 |
#define BCM5600_OP_BP_WARN_STATUS 0x01 |
| 59 |
#define BCM5600_OP_BP_DISCARD_STATUS 0x02 |
| 60 |
#define BCM5600_OP_COS_QSTAT_NOTIFY 0x03 |
| 61 |
#define BCM5600_OP_HOL_STAT_NOTIFY 0x04 |
| 62 |
#define BCM5600_OP_GBP_FULL_NOTIFY 0x05 |
| 63 |
#define BCM5600_OP_GBP_AVAIL_NOTIFY 0x06 |
| 64 |
#define BCM5600_OP_READ_MEM_CMD 0x07 |
| 65 |
#define BCM5600_OP_READ_MEM_ACK 0x08 |
| 66 |
#define BCM5600_OP_WRITE_MEM_CMD 0x09 |
| 67 |
#define BCM5600_OP_WRITE_MEM_ACK 0x0A |
| 68 |
#define BCM5600_OP_READ_REG_CMD 0x0B |
| 69 |
#define BCM5600_OP_READ_REG_ACK 0x0C |
| 70 |
#define BCM5600_OP_WRITE_REG_CMD 0x0D |
| 71 |
#define BCM5600_OP_WRITE_REG_ACK 0x0E |
| 72 |
#define BCM5600_OP_ARL_INSERT_CMD 0x0F |
| 73 |
#define BCM5600_OP_ARL_INSERT_DONE 0x10 |
| 74 |
#define BCM5600_OP_ARL_DELETE_CMD 0x11 |
| 75 |
#define BCM5600_OP_ARL_DELETE_DONE 0x12 |
| 76 |
#define BCM5600_OP_LINKSTAT_NOTIFY 0x13 |
| 77 |
#define BCM5600_OP_MEM_FAIL_NOTIFY 0x14 |
| 78 |
#define BCM5600_OP_INIT_CFAP 0x15 |
| 79 |
#define BCM5600_OP_INIT_SFAP 0x16 |
| 80 |
#define BCM5600_OP_ENTER_DEBUG_MODE 0x17 |
| 81 |
#define BCM5600_OP_EXIT_DEBUG_MODE 0x18 |
| 82 |
#define BCM5600_OP_ARL_LOOKUP_CMD 0x19 |
| 83 |
|
| 84 |
/* Command details */ |
| 85 |
#define BCM5600_CMD_OP_MASK 0xFC000000 |
| 86 |
#define BCM5600_CMD_OP_SHIFT 26 |
| 87 |
#define BCM5600_CMD_DST_MASK 0x03F00000 |
| 88 |
#define BCM5600_CMD_DST_SHIFT 20 |
| 89 |
#define BCM5600_CMD_SRC_MASK 0x000FC000 |
| 90 |
#define BCM5600_CMD_SRC_SHIFT 14 |
| 91 |
#define BCM5600_CMD_LEN_MASK 0x00003F80 |
| 92 |
#define BCM5600_CMD_LEN_SHIFT 7 |
| 93 |
#define BCM5600_CMD_EBIT_MASK 0x00000040 |
| 94 |
#define BCM5600_CMD_EBIT_SHIFT 6 |
| 95 |
#define BCM5600_CMD_ECODE_MASK 0x00000030 |
| 96 |
#define BCM5600_CMD_ECODE_SHIFT 4 |
| 97 |
#define BCM5600_CMD_COS_MASK 0x0000000E |
| 98 |
#define BCM5600_CMD_COS_SHIFT 1 |
| 99 |
#define BCM5600_CMD_CPU_MASK 0x00000001 |
| 100 |
#define BCM5600_CMD_CPU_SHIFT 0 |
| 101 |
|
| 102 |
/* Memory zones */ |
| 103 |
#define BCM5600_ADDR_ARLCNT0 0x01000000 |
| 104 |
#define BCM5600_ADDR_ARLCNT1 0x01100000 |
| 105 |
#define BCM5600_ADDR_ARLCNT2 0x01200000 |
| 106 |
#define BCM5600_ADDR_ARL0 0x02000000 |
| 107 |
#define BCM5600_ADDR_ARL1 0x02100000 |
| 108 |
#define BCM5600_ADDR_ARL2 0x02200000 |
| 109 |
#define BCM5600_ADDR_PTABLE0 0x03000000 |
| 110 |
#define BCM5600_ADDR_PTABLE1 0x03100000 |
| 111 |
#define BCM5600_ADDR_PTABLE2 0x03200000 |
| 112 |
#define BCM5600_ADDR_VTABLE0 0x05000000 |
| 113 |
#define BCM5600_ADDR_VTABLE1 0x05100000 |
| 114 |
#define BCM5600_ADDR_VTABLE2 0x05200000 |
| 115 |
#define BCM5600_ADDR_TTR0 0x06000000 |
| 116 |
#define BCM5600_ADDR_TBMAP0 0x06010000 |
| 117 |
#define BCM5600_ADDR_TTR1 0x06100000 |
| 118 |
#define BCM5600_ADDR_TBMAP1 0x06110000 |
| 119 |
#define BCM5600_ADDR_TTR2 0x06200000 |
| 120 |
#define BCM5600_ADDR_TBMAP2 0x06210000 |
| 121 |
#define BCM5600_ADDR_IMASK0 0x07000000 |
| 122 |
#define BCM5600_ADDR_IRULE0 0x07020000 |
| 123 |
#define BCM5600_ADDR_IMASK1 0x07100000 |
| 124 |
#define BCM5600_ADDR_IRULE1 0x07120000 |
| 125 |
#define BCM5600_ADDR_IMASK2 0x07200000 |
| 126 |
#define BCM5600_ADDR_IRULE2 0x07220000 |
| 127 |
#define BCM5600_ADDR_GIMASK 0x07300000 |
| 128 |
#define BCM5600_ADDR_GIRULE 0x07320000 |
| 129 |
#define BCM5600_ADDR_MARL0 0x08000000 |
| 130 |
#define BCM5600_ADDR_MARL1 0x08100000 |
| 131 |
#define BCM5600_ADDR_MARL2 0x08200000 |
| 132 |
#define BCM5600_ADDR_L3 0x09000000 |
| 133 |
#define BCM5600_ADDR_DEFIP 0x09010000 |
| 134 |
#define BCM5600_ADDR_L3INTF 0x09020000 |
| 135 |
#define BCM5600_ADDR_IPMC 0x09030000 |
| 136 |
#define BCM5600_ADDR_CBPHDR 0x0A600000 |
| 137 |
#define BCM5600_ADDR_CAB0 0x0A610000 |
| 138 |
#define BCM5600_ADDR_CAB1 0x0A620000 |
| 139 |
#define BCM5600_ADDR_CAB2 0x0A630000 |
| 140 |
#define BCM5600_ADDR_CAB3 0x0A640000 |
| 141 |
#define BCM5600_ADDR_CCP 0x0A650000 |
| 142 |
#define BCM5600_ADDR_PPP 0x0A660000 |
| 143 |
#define BCM5600_ADDR_CFAP 0x0A670000 |
| 144 |
#define BCM5600_ADDR_SFAP 0x0A680000 |
| 145 |
#define BCM5600_ADDR_CBPDATA0 0x0A6A0000 |
| 146 |
#define BCM5600_ADDR_CBPDATA1 0x0A6B0000 |
| 147 |
#define BCM5600_ADDR_CBPDATA2 0x0A6C0000 |
| 148 |
#define BCM5600_ADDR_CBPDATA3 0x0A6D0000 |
| 149 |
#define BCM5600_ADDR_PID 0x0A900000 |
| 150 |
#define BCM5600_ADDR_XQ_BASE 0x0B600000 |
| 151 |
#define BCM5600_ADDR_GBP 0x12000000 |
| 152 |
|
| 153 |
/* Number of "Data Words" */ |
| 154 |
#define BCM5600_DW_MAX 32 |
| 155 |
|
| 156 |
/* === VTABLE definitions === */ |
| 157 |
/* Word 0 */ |
| 158 |
#define BCM5600_VTABLE_VLAN_TAG_MASK 0x00000FFF |
| 159 |
|
| 160 |
/* Word 1: Port bitmap */ |
| 161 |
#define BCM5600_VTABLE_PORT_BMAP_MASK 0x1FFFFFFF |
| 162 |
|
| 163 |
/* Word 2: Untagged port bitmap */ |
| 164 |
#define BCM5600_VTABLE_UT_PORT_BMAP_MASK 0x1FFFFFFF |
| 165 |
|
| 166 |
/* Word 3: Module bitmap */ |
| 167 |
#define BCM5600_VTABLE_MOD_BMAP_MASK 0xFFFFFFFF |
| 168 |
|
| 169 |
/* === PTABLE definitions === */ |
| 170 |
/* Word 0 */ |
| 171 |
#define BCM5600_PTABLE_VLAN_TAG_MASK 0x00000FFF |
| 172 |
#define BCM5600_PTABLE_SP_ST_MASK 0x00003000 |
| 173 |
#define BCM5600_PTABLE_SP_ST_SHIFT 12 |
| 174 |
#define BCM5600_PTABLE_PRT_DIS_MASK 0x000FC000 |
| 175 |
#define BCM5600_PTABLE_PRT_DIS_SHIFT 14 |
| 176 |
#define BCM5600_PTABLE_JUMBO_FLAG 0x00100000 |
| 177 |
#define BCM5600_PTABLE_RTAG_MASK 0x00E00000 |
| 178 |
#define BCM5600_PTABLE_RTAG_SHIFT 21 |
| 179 |
#define BCM5600_PTABLE_TGID_MASK 0x07000000 |
| 180 |
#define BCM5600_PTABLE_TGID_SHIFT 24 |
| 181 |
#define BCM5600_PTABLE_TRUNK_FLAG 0x08000000 |
| 182 |
#define BCM5600_PTABLE_CPU_FLAG 0x10000000 |
| 183 |
#define BCM5600_PTABLE_PTYPE_MASK 0x60000000 |
| 184 |
#define BCM5600_PTABLE_PTYPE_SHIFT 29 |
| 185 |
#define BCM5600_PTABLE_BPDU_FLAG 0x80000000 |
| 186 |
|
| 187 |
/* Word 1 */ |
| 188 |
#define BCM5600_PTABLE_PORT_BMAP_MASK 0x1FFFFFFF |
| 189 |
#define BCM5600_PTABLE_MI_FLAG 0x20000000 |
| 190 |
#define BCM5600_PTABLE_CML_MASK 0xC0000000 |
| 191 |
#define BCM5600_PTABLE_CML_SHIFT 30 |
| 192 |
|
| 193 |
/* Word 2 */ |
| 194 |
#define BCM5600_PTABLE_UT_PORT_BMAP_MASK 0x1FFFFFFF |
| 195 |
|
| 196 |
/* Word 4 */ |
| 197 |
#define BCM5600_PTABLE_DSCP_MASK 0x0000003F |
| 198 |
#define BCM5600_PTABLE_DSCP_SHIFT 0 |
| 199 |
#define BCM5600_PTABLE_DSE_MODE_MASK 0x000000C0 |
| 200 |
#define BCM5600_PTABLE_DSE_MODE_SHIFT 6 |
| 201 |
#define BCM5600_PTABLE_RPE_FLAG 0x00000100 |
| 202 |
#define BCM5600_PTABLE_PRI_MASK 0x00000E00 |
| 203 |
#define BCM5600_PTABLE_PRI_SHIFT 9 |
| 204 |
#define BCM5600_PTABLE_L3_DIS_FLAG 0x00001000 |
| 205 |
|
| 206 |
|
| 207 |
/* === ARL (Addess Resolution Logic) definitions === */ |
| 208 |
/* Word 0: MAC address LSB */ |
| 209 |
|
| 210 |
/* Word 1 */ |
| 211 |
#define BCM5600_ARL_MAC_MSB_MASK 0x0000FFFF |
| 212 |
#define BCM5600_ARL_VLAN_TAG_MASK 0x0FFF0000 |
| 213 |
#define BCM5600_ARL_VLAN_TAG_SHIFT 16 |
| 214 |
#define BCM5600_ARL_COS_DST_MASK 0x70000000 |
| 215 |
#define BCM5600_ARL_COS_DST_SHIFT 28 |
| 216 |
#define BCM5600_ARL_CPU_FLAG 0x80000000 |
| 217 |
|
| 218 |
/* Word 2 */ |
| 219 |
#define BCM5600_ARL_L3_FLAG 0x00000001 |
| 220 |
#define BCM5600_ARL_SD_DIS_MASK 0x00000006 |
| 221 |
#define BCM5600_ARL_SD_DIS_SHIFT 1 |
| 222 |
#define BCM5600_ARL_ST_FLAG 0x00000008 |
| 223 |
#define BCM5600_ARL_HIT_FLAG 0x00000010 |
| 224 |
#define BCM5600_ARL_COS_SRC_MASK 0x000000E0 |
| 225 |
#define BCM5600_ARL_COS_SRC_SHIFT 5 |
| 226 |
#define BCM5600_ARL_TRUNK_FLAG 0x00000100 |
| 227 |
#define BCM5600_ARL_TGID_MASK 0x00000E00 |
| 228 |
#define BCM5600_ARL_TGID_SHIFT 9 |
| 229 |
#define BCM5600_ARL_RTAG_MASK 0x00007000 |
| 230 |
#define BCM5600_ARL_RTAG_SHIFT 12 |
| 231 |
#define BCM5600_ARL_PORT_MASK 0x001F8000 |
| 232 |
#define BCM5600_ARL_PORT_SHIFT 15 |
| 233 |
#define BCM5600_ARL_SCP_FLAG 0x00200000 |
| 234 |
#define BCM5600_ARL_MOD_ID_MASK 0x07C00000 |
| 235 |
#define BCM5600_ARL_MOD_ID_SHIFT 22 |
| 236 |
|
| 237 |
/* === Multicast ARL definitions === */ |
| 238 |
/* Word 0: MAC address LSB */ |
| 239 |
|
| 240 |
/* Word 1 */ |
| 241 |
#define BCM5600_MARL_MAC_MSB_MASK 0x0000FFFF |
| 242 |
#define BCM5600_MARL_VLAN_TAG_MASK 0x0FFF0000 |
| 243 |
#define BCM5600_MARL_VLAN_TAG_SHIFT 16 |
| 244 |
#define BCM5600_MARL_COS_DST_MASK 0x70000000 |
| 245 |
#define BCM5600_MARL_COS_DST_SHIFT 28 |
| 246 |
|
| 247 |
/* Word 2 */ |
| 248 |
#define BCM5600_MARL_PORT_BMAP_MASK 0x1FFFFFFF |
| 249 |
|
| 250 |
/* Word 3 */ |
| 251 |
#define BCM5600_MARL_UT_PORT_BMAP_MASK 0x1FFFFFFF |
| 252 |
|
| 253 |
/* Word 4 */ |
| 254 |
#define BCM5600_MARL_MOD_BMAP_MASK 0xFFFFFFFF |
| 255 |
|
| 256 |
/* === Trunk bitmap === */ |
| 257 |
#define BCM5600_TBMAP_MASK 0x0FFFFFFF |
| 258 |
|
| 259 |
/* === Trunk table === */ |
| 260 |
/* Word 0 */ |
| 261 |
#define BCM5600_TTR_TP0_MASK 0x0000003F |
| 262 |
#define BCM5600_TTR_TP0_SHIFT 0 |
| 263 |
#define BCM5600_TTR_TP1_MASK 0x00000FC0 |
| 264 |
#define BCM5600_TTR_TP1_SHIFT 6 |
| 265 |
#define BCM5600_TTR_TP2_MASK 0x0003F000 |
| 266 |
#define BCM5600_TTR_TP2_SHIFT 12 |
| 267 |
#define BCM5600_TTR_TP3_MASK 0x00FC0000 |
| 268 |
#define BCM5600_TTR_TP3_SHIFT 18 |
| 269 |
#define BCM5600_TTR_TP4_MASK 0x3F000000 |
| 270 |
#define BCM5600_TTR_TP4_SHIFT 24 |
| 271 |
|
| 272 |
/* Word 1 */ |
| 273 |
#define BCM5600_TTR_TP5_MASK 0x0000003F |
| 274 |
#define BCM5600_TTR_TP5_SHIFT 0 |
| 275 |
#define BCM5600_TTR_TP6_MASK 0x00000FC0 |
| 276 |
#define BCM5600_TTR_TP6_SHIFT 6 |
| 277 |
#define BCM5600_TTR_TP7_MASK 0x0003F000 |
| 278 |
#define BCM5600_TTR_TP7_SHIFT 12 |
| 279 |
|
| 280 |
#define BCM5600_TTR_TG_SIZE_MASK 0x003C0000 |
| 281 |
#define BCM5600_TTR_TG_SIZE_SHIFT 18 |
| 282 |
|
| 283 |
/* Trunks (port aggregation) */ |
| 284 |
#define BCM5600_MAX_TRUNKS 6 |
| 285 |
#define BCM5600_MAX_PORTS_PER_TRUNK 8 |
| 286 |
|
| 287 |
/* ======================================================================= */ |
| 288 |
|
| 289 |
/* Transmit descriptor size */ |
| 290 |
#define BCM5600_TXD_SIZE 32 |
| 291 |
#define BCM5600_TXD_RING_CONT 0x80000000 /* ring is continuing */ |
| 292 |
#define BCM5600_TXD_UNKNOWN 0x04000000 /* valid packet (?) */ |
| 293 |
#define BCM5600_TXD_NEOP 0x00040000 /* end of packet if not set */ |
| 294 |
|
| 295 |
/* Receive descriptor size */ |
| 296 |
#define BCM5600_RXD_SIZE 32 |
| 297 |
#define BCM5600_RXD_RING_CONT 0x80000000 /* ring is continuing */ |
| 298 |
#define BCM5600_RXD_UNKNOWN 0x00040000 /* unknown */ |
| 299 |
|
| 300 |
/* Interrupt sources */ |
| 301 |
#define BCM5600_INTR_STAT_ITER_DONE 0x00100000 /* Unknown */ |
| 302 |
#define BCM5600_INTR_RX_UNDERRUN 0x00000400 /* RX ring underrun */ |
| 303 |
#define BCM5600_INTR_RX_AVAIL 0x00000200 /* packet available */ |
| 304 |
#define BCM5600_INTR_TX_UNDERRUN 0x00000100 /* TX ring underrun */ |
| 305 |
#define BCM5600_INTR_LINKSTAT_MOD 0x00000010 /* Link status modified */ |
| 306 |
|
| 307 |
/* ======================================================================= */ |
| 308 |
|
| 309 |
/* Port Mirroring */ |
| 310 |
#define BCM5600_MIRROR_ENABLE 0x40 |
| 311 |
#define BCM5600_MIRROR_PORT_MASK 0x3F |
| 312 |
|
| 313 |
/* ======================================================================= */ |
| 314 |
|
| 315 |
#define BCM5600_REG_HASH_SIZE 8192 |
| 316 |
|
| 317 |
/* BCM5600 register */ |
| 318 |
struct bcm5600_reg { |
| 319 |
m_uint32_t addr; |
| 320 |
m_uint32_t value; |
| 321 |
struct bcm5600_reg *next; |
| 322 |
}; |
| 323 |
|
| 324 |
/* BCM5600 table */ |
| 325 |
struct bcm5600_table { |
| 326 |
char *name; |
| 327 |
long offset; |
| 328 |
m_uint32_t addr; |
| 329 |
u_int min_index,max_index; |
| 330 |
u_int nr_words; |
| 331 |
}; |
| 332 |
|
| 333 |
/* BCM5600 in-transit packet */ |
| 334 |
struct bcm5600_pkt { |
| 335 |
/* Received packet data */ |
| 336 |
u_char *pkt; |
| 337 |
ssize_t pkt_len; |
| 338 |
|
| 339 |
/* Rewritten packet (802.1Q tag pushed or poped) */ |
| 340 |
u_char *rewr_pkt; |
| 341 |
int rewrite_done; |
| 342 |
|
| 343 |
/* Original VLAN (-1 for untagged packet) and Real VLAN */ |
| 344 |
int orig_vlan,real_vlan; |
| 345 |
|
| 346 |
/* VLAN entry */ |
| 347 |
m_uint32_t *vlan_entry; |
| 348 |
|
| 349 |
/* Ingress Port and Egress Port bitmap */ |
| 350 |
u_int ingress_port,egress_bitmap,egress_ut_bitmap; |
| 351 |
u_int egress_filter_bitmap; |
| 352 |
|
| 353 |
/* RX descriptor */ |
| 354 |
m_uint32_t rdes[4]; |
| 355 |
|
| 356 |
/* Packet sent to CPU */ |
| 357 |
u_int sent_to_cpu; |
| 358 |
}; |
| 359 |
|
| 360 |
/* BCM5600 physical port */ |
| 361 |
struct bcm5600_port { |
| 362 |
netio_desc_t *nio; |
| 363 |
u_int id; |
| 364 |
char name[32]; |
| 365 |
}; |
| 366 |
|
| 367 |
/* NM-16ESW private data */ |
| 368 |
struct nm_16esw_data { |
| 369 |
char *name; |
| 370 |
u_int nr_port; |
| 371 |
|
| 372 |
vm_instance_t *vm; |
| 373 |
struct vdevice *dev; |
| 374 |
struct pci_device *pci_dev; |
| 375 |
|
| 376 |
pthread_mutex_t lock; |
| 377 |
|
| 378 |
/* Ager task */ |
| 379 |
timer_id ager_tid; |
| 380 |
|
| 381 |
/* S-channel command and command result */ |
| 382 |
m_uint32_t schan_cmd,schan_cmd_res; |
| 383 |
|
| 384 |
/* Data Words */ |
| 385 |
m_uint32_t dw[BCM5600_DW_MAX]; |
| 386 |
|
| 387 |
/* Interrupt mask */ |
| 388 |
m_uint32_t intr_mask; |
| 389 |
|
| 390 |
/* MII registers */ |
| 391 |
m_uint16_t mii_regs[64][32]; |
| 392 |
m_uint32_t mii_input,mii_output; |
| 393 |
u_int mii_intr; |
| 394 |
|
| 395 |
/* RX/TX rings addresses */ |
| 396 |
m_uint32_t rx_ring_addr,tx_ring_addr; |
| 397 |
m_uint32_t tx_current,tx_end_scan; |
| 398 |
m_uint32_t rx_current,rx_end_scan; |
| 399 |
|
| 400 |
/* TX ring scanner task id */ |
| 401 |
ptask_id_t tx_tid; |
| 402 |
|
| 403 |
/* TX buffer */ |
| 404 |
u_char tx_buffer[BCM5600_MAX_PKT_SIZE]; |
| 405 |
u_int tx_bufsize; |
| 406 |
|
| 407 |
/* Port Mirroring */ |
| 408 |
u_int mirror_dst_port; |
| 409 |
u_int mirror_egress_ports; |
| 410 |
|
| 411 |
/* Registers hash table */ |
| 412 |
struct bcm5600_reg *reg_hash_table[BCM5600_REG_HASH_SIZE]; |
| 413 |
|
| 414 |
/* Most used tables... */ |
| 415 |
struct bcm5600_table *t_ptable,*t_vtable; |
| 416 |
struct bcm5600_table *t_arl,*t_marl; |
| 417 |
struct bcm5600_table *t_tbmap,*t_ttr; |
| 418 |
|
| 419 |
/* Ports (only 16 are "real" and usable) */ |
| 420 |
struct bcm5600_port ports[32]; |
| 421 |
|
| 422 |
/* CPU port */ |
| 423 |
u_int cpu_port; |
| 424 |
|
| 425 |
/* Current egress port of all trunks */ |
| 426 |
u_int trunk_last_egress_port[BCM5600_MAX_TRUNKS]; |
| 427 |
|
| 428 |
/* ARL count table */ |
| 429 |
m_uint32_t *arl_cnt; |
| 430 |
|
| 431 |
/* ARL (Address Resolution Logic) Table */ |
| 432 |
m_uint32_t *arl_table; |
| 433 |
|
| 434 |
/* Multicast ARL Table */ |
| 435 |
m_uint32_t *marl_table; |
| 436 |
|
| 437 |
/* VTABLE (VLAN Table) */ |
| 438 |
m_uint32_t *vtable; |
| 439 |
|
| 440 |
/* Trunks */ |
| 441 |
m_uint32_t *ttr,*tbmap; |
| 442 |
|
| 443 |
/* PTABLE (Port Table) */ |
| 444 |
m_uint32_t *ptable; |
| 445 |
}; |
| 446 |
|
| 447 |
/* NM-16ESW Port physical port mapping table (Cisco => BCM) */ |
| 448 |
static int nm16esw_port_mapping[] = { |
| 449 |
2, 0, 6, 4, 10, 8, 14, 12, 3, 1, 7, 5, 11, 9, 15, 13, |
| 450 |
}; |
| 451 |
|
| 452 |
/* Log a BCM message */ |
| 453 |
#define BCM_LOG(d,msg...) vm_log((d)->vm,(d)->name,msg) |
| 454 |
|
| 455 |
/* Lock/Unlock primitives */ |
| 456 |
#define BCM_LOCK(d) pthread_mutex_lock(&(d)->lock) |
| 457 |
#define BCM_UNLOCK(d) pthread_mutex_unlock(&(d)->lock) |
| 458 |
|
| 459 |
/* Trunk group info */ |
| 460 |
struct bcm5600_tg_info { |
| 461 |
u_int index,mask,shift; |
| 462 |
}; |
| 463 |
|
| 464 |
static struct bcm5600_tg_info tg_info[8] = { |
| 465 |
{ 0, BCM5600_TTR_TP0_MASK, BCM5600_TTR_TP0_SHIFT }, |
| 466 |
{ 0, BCM5600_TTR_TP1_MASK, BCM5600_TTR_TP1_SHIFT }, |
| 467 |
{ 0, BCM5600_TTR_TP2_MASK, BCM5600_TTR_TP2_SHIFT }, |
| 468 |
{ 0, BCM5600_TTR_TP3_MASK, BCM5600_TTR_TP3_SHIFT }, |
| 469 |
{ 0, BCM5600_TTR_TP4_MASK, BCM5600_TTR_TP4_SHIFT }, |
| 470 |
{ 1, BCM5600_TTR_TP5_MASK, BCM5600_TTR_TP5_SHIFT }, |
| 471 |
{ 1, BCM5600_TTR_TP6_MASK, BCM5600_TTR_TP6_SHIFT }, |
| 472 |
{ 1, BCM5600_TTR_TP7_MASK, BCM5600_TTR_TP7_SHIFT }, |
| 473 |
}; |
| 474 |
|
| 475 |
/* Return port status (up or down), based on the MII register */ |
| 476 |
static int bcm5600_mii_port_status(struct nm_16esw_data *d,u_int port) |
| 477 |
{ |
| 478 |
u_int mii_ctrl; |
| 479 |
|
| 480 |
mii_ctrl = d->mii_regs[port][0x00]; |
| 481 |
|
| 482 |
/* Isolate bit */ |
| 483 |
return(!(mii_ctrl & 0x400)); |
| 484 |
} |
| 485 |
|
| 486 |
/* Build port status bitmap */ |
| 487 |
static m_uint32_t bcm5600_mii_port_status_bmp(struct nm_16esw_data *d) |
| 488 |
{ |
| 489 |
m_uint32_t bmp; |
| 490 |
int i; |
| 491 |
|
| 492 |
for(i=0,bmp=0;i<d->nr_port;i++) |
| 493 |
if (bcm5600_mii_port_status(d,i)) |
| 494 |
bmp |= 1 << i; |
| 495 |
|
| 496 |
return(bmp); |
| 497 |
} |
| 498 |
|
| 499 |
/* Read a MII register */ |
| 500 |
static void bcm5600_mii_read(struct nm_16esw_data *d) |
| 501 |
{ |
| 502 |
m_uint8_t port,reg; |
| 503 |
|
| 504 |
port = (d->mii_input >> 16) & 0xFF; |
| 505 |
reg = (d->mii_input >> 24) & 0xFF; |
| 506 |
|
| 507 |
if ((port < 32) && (reg < 32)) { |
| 508 |
d->mii_output = d->mii_regs[port][reg]; |
| 509 |
|
| 510 |
switch(reg) { |
| 511 |
case 0x00: |
| 512 |
d->mii_output &= ~0x8200; |
| 513 |
break; |
| 514 |
case 0x01: |
| 515 |
if (d->ports[port].nio && bcm5600_mii_port_status(d,port)) |
| 516 |
d->mii_output = 0x782C; |
| 517 |
else |
| 518 |
d->mii_output = 0; |
| 519 |
break; |
| 520 |
case 0x02: |
| 521 |
d->mii_output = 0x40; |
| 522 |
break; |
| 523 |
case 0x03: |
| 524 |
d->mii_output = 0x61d4; |
| 525 |
break; |
| 526 |
case 0x04: |
| 527 |
d->mii_output = 0x1E1; |
| 528 |
break; |
| 529 |
case 0x05: |
| 530 |
d->mii_output = 0x41E1; |
| 531 |
break; |
| 532 |
default: |
| 533 |
d->mii_output = 0; |
| 534 |
} |
| 535 |
} |
| 536 |
} |
| 537 |
|
| 538 |
/* Write a MII register */ |
| 539 |
static void bcm5600_mii_write(struct nm_16esw_data *d) |
| 540 |
{ |
| 541 |
m_uint8_t port,reg; |
| 542 |
m_uint16_t isolation; |
| 543 |
|
| 544 |
port = (d->mii_input >> 16) & 0xFF; |
| 545 |
reg = (d->mii_input >> 24) & 0xFF; |
| 546 |
|
| 547 |
if ((port < 32) && (reg < 32)) |
| 548 |
{ |
| 549 |
#if DEBUG_MII |
| 550 |
BCM_LOG(d,"MII: port 0x%4.4x, reg 0x%2.2x: writing 0x%4.4x\n", |
| 551 |
port,reg,d->mii_input & 0xFFFF); |
| 552 |
#endif |
| 553 |
|
| 554 |
/* Check if PHY isolation status is changing */ |
| 555 |
if (reg == 0) { |
| 556 |
isolation = (d->mii_input ^ d->mii_regs[port][reg]) & 0x400; |
| 557 |
|
| 558 |
if (isolation) { |
| 559 |
#if DEBUG_MII |
| 560 |
BCM_LOG(d,"MII: port 0x%4.4x: generating IRQ\n",port); |
| 561 |
#endif |
| 562 |
d->mii_intr = TRUE; |
| 563 |
pci_dev_trigger_irq(d->vm,d->pci_dev); |
| 564 |
} |
| 565 |
} |
| 566 |
|
| 567 |
d->mii_regs[port][reg] = d->mii_input & 0xFFFF; |
| 568 |
} |
| 569 |
} |
| 570 |
|
| 571 |
/* Hash function for register */ |
| 572 |
static u_int bcm5600_reg_get_hash(m_uint32_t addr) |
| 573 |
{ |
| 574 |
return((addr ^ (addr >> 16)) & (BCM5600_REG_HASH_SIZE - 1)); |
| 575 |
} |
| 576 |
|
| 577 |
/* Find a register entry */ |
| 578 |
static struct bcm5600_reg *bcm5600_reg_find(struct nm_16esw_data *d, |
| 579 |
m_uint32_t addr) |
| 580 |
{ |
| 581 |
struct bcm5600_reg *reg; |
| 582 |
u_int h_index; |
| 583 |
|
| 584 |
h_index = bcm5600_reg_get_hash(addr); |
| 585 |
for(reg=d->reg_hash_table[h_index];reg;reg=reg->next) |
| 586 |
if (reg->addr == addr) |
| 587 |
return reg; |
| 588 |
|
| 589 |
return NULL; |
| 590 |
} |
| 591 |
|
| 592 |
/* Read a register */ |
| 593 |
static m_uint32_t bcm5600_reg_read(struct nm_16esw_data *d,m_uint32_t addr) |
| 594 |
{ |
| 595 |
struct bcm5600_reg *reg; |
| 596 |
|
| 597 |
if (!(reg = bcm5600_reg_find(d,addr))) |
| 598 |
return(0); |
| 599 |
|
| 600 |
return(reg->value); |
| 601 |
} |
| 602 |
|
| 603 |
/* Write a register */ |
| 604 |
static int bcm5600_reg_write(struct nm_16esw_data *d,m_uint32_t addr, |
| 605 |
m_uint32_t value) |
| 606 |
{ |
| 607 |
struct bcm5600_reg *reg; |
| 608 |
u_int h_index; |
| 609 |
|
| 610 |
if ((reg = bcm5600_reg_find(d,addr))) { |
| 611 |
reg->value = value; |
| 612 |
return(0); |
| 613 |
} |
| 614 |
|
| 615 |
/* create a new register */ |
| 616 |
if (!(reg = malloc(sizeof(*reg)))) |
| 617 |
return(-1); |
| 618 |
|
| 619 |
reg->addr = addr; |
| 620 |
reg->value = value; |
| 621 |
|
| 622 |
/* insert new register in hash table */ |
| 623 |
h_index = bcm5600_reg_get_hash(addr); |
| 624 |
reg->next = d->reg_hash_table[h_index]; |
| 625 |
d->reg_hash_table[h_index] = reg; |
| 626 |
|
| 627 |
return(0); |
| 628 |
} |
| 629 |
|
| 630 |
/* Register special handling */ |
| 631 |
static void bcm5600_reg_write_special(struct nm_16esw_data *d, |
| 632 |
m_uint32_t addr,m_uint32_t value) |
| 633 |
{ |
| 634 |
switch(addr) { |
| 635 |
case 0x80006: |
| 636 |
d->mirror_dst_port = value; |
| 637 |
break; |
| 638 |
|
| 639 |
case 0x8000d: |
| 640 |
d->mirror_egress_ports = value; |
| 641 |
break; |
| 642 |
|
| 643 |
case 0x80009: |
| 644 |
/* age timer */ |
| 645 |
break; |
| 646 |
} |
| 647 |
} |
| 648 |
|
| 649 |
/* Free memory used to store register info */ |
| 650 |
static void bcm5600_reg_free(struct nm_16esw_data *d) |
| 651 |
{ |
| 652 |
struct bcm5600_reg *reg,*next; |
| 653 |
int i; |
| 654 |
|
| 655 |
for(i=0;i<BCM5600_REG_HASH_SIZE;i++) |
| 656 |
for(reg=d->reg_hash_table[i];reg;reg=next) { |
| 657 |
next = reg->next; |
| 658 |
free(reg); |
| 659 |
} |
| 660 |
} |
| 661 |
|
| 662 |
/* Dump all known registers */ |
| 663 |
static void bcm5600_reg_dump(struct nm_16esw_data *d,int show_null) |
| 664 |
{ |
| 665 |
struct bcm5600_reg *reg; |
| 666 |
int i; |
| 667 |
|
| 668 |
printf("%s: dumping registers:\n",d->name); |
| 669 |
|
| 670 |
for(i=0;i<BCM5600_REG_HASH_SIZE;i++) |
| 671 |
for(reg=d->reg_hash_table[i];reg;reg=reg->next) { |
| 672 |
if (reg->value || show_null) |
| 673 |
printf(" 0x%8.8x: 0x%8.8x\n",reg->addr,reg->value); |
| 674 |
} |
| 675 |
} |
| 676 |
|
| 677 |
/* Fill a string buffer with all ports of the specified bitmap */ |
| 678 |
_maybe_used static char *bcm5600_port_bitmap_str(struct nm_16esw_data *d, |
| 679 |
char *buffer,m_uint32_t bitmap) |
| 680 |
{ |
| 681 |
char *ptr = buffer; |
| 682 |
int i; |
| 683 |
|
| 684 |
*ptr = 0; |
| 685 |
|
| 686 |
for(i=0;i<d->nr_port;i++) |
| 687 |
if (bitmap & (1 << i)) { |
| 688 |
ptr += sprintf(ptr,"%s ",d->ports[i].name); |
| 689 |
} |
| 690 |
|
| 691 |
return buffer; |
| 692 |
} |
| 693 |
|
| 694 |
/* BCM5600 tables */ |
| 695 |
#define BCM_OFFSET(x) (OFFSET(struct nm_16esw_data,x)) |
| 696 |
|
| 697 |
static struct bcm5600_table bcm5600_tables[] = { |
| 698 |
/* ARL tables */ |
| 699 |
{ "arlcnt0", BCM_OFFSET(arl_cnt), BCM5600_ADDR_ARLCNT0, 0, 0, 1 }, |
| 700 |
{ "arlcnt1", BCM_OFFSET(arl_cnt), BCM5600_ADDR_ARLCNT1, 0, 0, 1 }, |
| 701 |
{ "arlcnt2", BCM_OFFSET(arl_cnt), BCM5600_ADDR_ARLCNT2, 0, 0, 1 }, |
| 702 |
|
| 703 |
/* ARL tables */ |
| 704 |
{ "arl0", BCM_OFFSET(arl_table), BCM5600_ADDR_ARL0, 0, 8191, 3 }, |
| 705 |
{ "arl1", BCM_OFFSET(arl_table), BCM5600_ADDR_ARL1, 0, 8191, 3 }, |
| 706 |
{ "arl2", BCM_OFFSET(arl_table), BCM5600_ADDR_ARL2, 0, 8191, 3 }, |
| 707 |
|
| 708 |
/* Multicast ARL tables */ |
| 709 |
{ "marl0", BCM_OFFSET(marl_table), BCM5600_ADDR_MARL0, 1, 255, 5 }, |
| 710 |
{ "marl1", BCM_OFFSET(marl_table), BCM5600_ADDR_MARL1, 1, 255, 5 }, |
| 711 |
{ "marl2", BCM_OFFSET(marl_table), BCM5600_ADDR_MARL2, 1, 255, 5 }, |
| 712 |
|
| 713 |
/* PTABLE - Physical Ports */ |
| 714 |
{ "ptable0", BCM_OFFSET(ptable), BCM5600_ADDR_PTABLE0, 0, 31, 6 }, |
| 715 |
{ "ptable1", BCM_OFFSET(ptable), BCM5600_ADDR_PTABLE1, 0, 31, 6 }, |
| 716 |
{ "ptable2", BCM_OFFSET(ptable), BCM5600_ADDR_PTABLE2, 0, 31, 6 }, |
| 717 |
|
| 718 |
/* VTABLE - VLANs */ |
| 719 |
{ "vtable0", BCM_OFFSET(vtable), BCM5600_ADDR_VTABLE0, 1, 255, 4 }, |
| 720 |
{ "vtable1", BCM_OFFSET(vtable), BCM5600_ADDR_VTABLE1, 1, 255, 4 }, |
| 721 |
{ "vtable2", BCM_OFFSET(vtable), BCM5600_ADDR_VTABLE2, 1, 255, 4 }, |
| 722 |
|
| 723 |
/* TTR */ |
| 724 |
{ "ttr0", BCM_OFFSET(ttr), BCM5600_ADDR_TTR0, 0, 5, 3 }, |
| 725 |
{ "ttr1", BCM_OFFSET(ttr), BCM5600_ADDR_TTR1, 0, 5, 3 }, |
| 726 |
{ "ttr2", BCM_OFFSET(ttr), BCM5600_ADDR_TTR2, 0, 5, 3 }, |
| 727 |
|
| 728 |
/* TBMAP */ |
| 729 |
{ "tbmap0", BCM_OFFSET(tbmap), BCM5600_ADDR_TBMAP0, 0, 5, 1 }, |
| 730 |
{ "tbmap1", BCM_OFFSET(tbmap), BCM5600_ADDR_TBMAP1, 0, 5, 1 }, |
| 731 |
{ "tbmap2", BCM_OFFSET(tbmap), BCM5600_ADDR_TBMAP2, 0, 5, 1 }, |
| 732 |
|
| 733 |
{ NULL, -1, 0, 0, 0 }, |
| 734 |
}; |
| 735 |
|
| 736 |
/* Get table size (in number of words) */ |
| 737 |
static inline u_int bcm5600_table_get_size(struct bcm5600_table *table) |
| 738 |
{ |
| 739 |
return(table->nr_words * (table->max_index + 1)); |
| 740 |
} |
| 741 |
|
| 742 |
/* Create automatically tables */ |
| 743 |
static int bcm5600_table_create(struct nm_16esw_data *d) |
| 744 |
{ |
| 745 |
struct bcm5600_table *table; |
| 746 |
m_uint32_t *array; |
| 747 |
size_t nr_words; |
| 748 |
int i; |
| 749 |
|
| 750 |
for(i=0;bcm5600_tables[i].name;i++) |
| 751 |
{ |
| 752 |
table = &bcm5600_tables[i]; |
| 753 |
nr_words = bcm5600_table_get_size(table); |
| 754 |
|
| 755 |
if (!(array = calloc(nr_words,sizeof(m_uint32_t)))) { |
| 756 |
fprintf(stderr,"BCM5600: unable to create table '%s'\n",table->name); |
| 757 |
return(-1); |
| 758 |
} |
| 759 |
|
| 760 |
*(PTR_ADJUST(m_uint32_t **,d,table->offset)) = array; |
| 761 |
} |
| 762 |
|
| 763 |
return(0); |
| 764 |
} |
| 765 |
|
| 766 |
/* Free tables */ |
| 767 |
static void bcm5600_table_free(struct nm_16esw_data *d) |
| 768 |
{ |
| 769 |
struct bcm5600_table *table; |
| 770 |
m_uint32_t **array; |
| 771 |
int i; |
| 772 |
|
| 773 |
for(i=0;bcm5600_tables[i].name;i++) { |
| 774 |
table = &bcm5600_tables[i]; |
| 775 |
array = (PTR_ADJUST(m_uint32_t **,d,table->offset)); |
| 776 |
free(*array); |
| 777 |
|
| 778 |
/* avoid freeing the same table multiple times */ |
| 779 |
*array = NULL; |
| 780 |
} |
| 781 |
} |
| 782 |
|
| 783 |
/* Find a table given its address */ |
| 784 |
static struct bcm5600_table *bcm5600_table_find(struct nm_16esw_data *d, |
| 785 |
m_uint32_t addr) |
| 786 |
{ |
| 787 |
int i; |
| 788 |
|
| 789 |
for(i=0;bcm5600_tables[i].name;i++) |
| 790 |
if (bcm5600_tables[i].addr == addr) |
| 791 |
return(&bcm5600_tables[i]); |
| 792 |
|
| 793 |
#if DEBUG_UNKNOWN |
| 794 |
BCM_LOG(d,"unknown table at address 0x%8.8x\n",addr); |
| 795 |
#endif |
| 796 |
return NULL; |
| 797 |
} |
| 798 |
|
| 799 |
/* Get a table entry */ |
| 800 |
static inline m_uint32_t *bcm5600_table_get_entry(struct nm_16esw_data *d, |
| 801 |
struct bcm5600_table *table, |
| 802 |
m_uint32_t index) |
| 803 |
{ |
| 804 |
m_uint32_t *array; |
| 805 |
|
| 806 |
if ((index < table->min_index) || (index > table->max_index)) |
| 807 |
return NULL; |
| 808 |
|
| 809 |
array = *(PTR_ADJUST(m_uint32_t **,d,table->offset)); |
| 810 |
return(&array[index*table->nr_words]); |
| 811 |
} |
| 812 |
|
| 813 |
/* Read a table entry */ |
| 814 |
static int bcm5600_table_read_entry(struct nm_16esw_data *d) |
| 815 |
{ |
| 816 |
struct bcm5600_table *table; |
| 817 |
m_uint32_t addr,index,*entry; |
| 818 |
int i; |
| 819 |
|
| 820 |
addr = d->dw[1] & 0xFFFF0000; |
| 821 |
index = d->dw[1] & 0x0000FFFF; |
| 822 |
|
| 823 |
if (!(table = bcm5600_table_find(d,addr))) { |
| 824 |
#if DEBUG_UNKNOWN |
| 825 |
BCM_LOG(d,"unknown mem address at address 0x%8.8x\n",d->dw[1]); |
| 826 |
#endif |
| 827 |
return(-1); |
| 828 |
} |
| 829 |
|
| 830 |
if (!(entry = bcm5600_table_get_entry(d,table,index))) |
| 831 |
return(-1); |
| 832 |
|
| 833 |
#if DEBUG_MEM |
| 834 |
BCM_LOG(d,"READ_MEM: addr=0x%8.8x (table %s)\n",d->dw[1],table->name); |
| 835 |
#endif |
| 836 |
|
| 837 |
for(i=0;i<table->nr_words;i++) |
| 838 |
d->dw[i+1] = entry[i]; |
| 839 |
|
| 840 |
return(0); |
| 841 |
} |
| 842 |
|
| 843 |
/* Write a table entry */ |
| 844 |
static int bcm5600_table_write_entry(struct nm_16esw_data *d) |
| 845 |
{ |
| 846 |
struct bcm5600_table *table; |
| 847 |
m_uint32_t addr,index,*entry; |
| 848 |
int i; |
| 849 |
|
| 850 |
addr = d->dw[1] & 0xFFFF0000; |
| 851 |
index = d->dw[1] & 0x0000FFFF; |
| 852 |
|
| 853 |
if (!(table = bcm5600_table_find(d,addr))) |
| 854 |
return(-1); |
| 855 |
|
| 856 |
if (!(entry = bcm5600_table_get_entry(d,table,index))) |
| 857 |
return(-1); |
| 858 |
|
| 859 |
for(i=0;i<table->nr_words;i++) |
| 860 |
entry[i] = d->dw[i+2]; |
| 861 |
|
| 862 |
#if DEBUG_MEM |
| 863 |
{ |
| 864 |
char buffer[512],*ptr = buffer; |
| 865 |
|
| 866 |
for(i=0;i<table->nr_words;i++) |
| 867 |
ptr += sprintf(ptr,"data[%d]=0x%8.8x ",i,entry[i]); |
| 868 |
|
| 869 |
BCM_LOG(d,"WRITE_MEM: addr=0x%8.8x (table %s) %s\n", |
| 870 |
d->dw[1],table->name,buffer); |
| 871 |
} |
| 872 |
#endif |
| 873 |
return(0); |
| 874 |
} |
| 875 |
|
| 876 |
/* Dump a table (for debugging) */ |
| 877 |
_Unused static int bcm5600_table_dump(struct nm_16esw_data *d,m_uint32_t addr) |
| 878 |
{ |
| 879 |
struct bcm5600_table *table; |
| 880 |
m_uint32_t *entry; |
| 881 |
int i,j; |
| 882 |
|
| 883 |
if (!(table = bcm5600_table_find(d,addr))) |
| 884 |
return(-1); |
| 885 |
|
| 886 |
printf("%s: dumping table \"%s\":\n",d->name,table->name); |
| 887 |
|
| 888 |
for(i=table->min_index;i<=table->max_index;i++) { |
| 889 |
if (!(entry = bcm5600_table_get_entry(d,table,i))) |
| 890 |
break; |
| 891 |
|
| 892 |
printf(" %4d:",i); |
| 893 |
|
| 894 |
for(j=0;j<table->nr_words;j++) |
| 895 |
printf("0x%8.8x ",entry[j]); |
| 896 |
|
| 897 |
printf("\n"); |
| 898 |
} |
| 899 |
|
| 900 |
printf("\n"); |
| 901 |
return(0); |
| 902 |
} |
| 903 |
|
| 904 |
/* Dump the VLAN table */ |
| 905 |
static int bcm5600_dump_vtable(struct nm_16esw_data *d) |
| 906 |
{ |
| 907 |
struct bcm5600_table *table; |
| 908 |
struct bcm5600_port *port; |
| 909 |
m_uint32_t *entry,tbmp,ubmp; |
| 910 |
u_int vlan; |
| 911 |
int i,j; |
| 912 |
|
| 913 |
if (!(table = bcm5600_table_find(d,BCM5600_ADDR_VTABLE0))) |
| 914 |
return(-1); |
| 915 |
|
| 916 |
printf("%s: dumping VLAN table:\n",d->name); |
| 917 |
|
| 918 |
for(i=table->min_index;i<=table->max_index;i++) { |
| 919 |
if (!(entry = bcm5600_table_get_entry(d,table,i))) |
| 920 |
break; |
| 921 |
|
| 922 |
/* Extract the VLAN info */ |
| 923 |
vlan = entry[0] & BCM5600_VTABLE_VLAN_TAG_MASK; |
| 924 |
|
| 925 |
if (vlan == VLAN_INVALID) |
| 926 |
continue; |
| 927 |
|
| 928 |
printf(" VLAN %4u: ",vlan); |
| 929 |
|
| 930 |
for(j=0;j<d->nr_port;j++) { |
| 931 |
tbmp = entry[1] & (1 << j); |
| 932 |
ubmp = entry[2] & (1 << j); |
| 933 |
|
| 934 |
if (tbmp || ubmp) { |
| 935 |
port = &d->ports[j]; |
| 936 |
|
| 937 |
printf("%s (",port->name); |
| 938 |
|
| 939 |
if (tbmp) |
| 940 |
printf("T%s",ubmp ? "/" : ") "); |
| 941 |
|
| 942 |
if (ubmp) |
| 943 |
printf("UT) "); |
| 944 |
} |
| 945 |
} |
| 946 |
|
| 947 |
printf("\n"); |
| 948 |
} |
| 949 |
|
| 950 |
printf("\n"); |
| 951 |
return(0); |
| 952 |
} |
| 953 |
|
| 954 |
/* Dump the "trunk" ports */ |
| 955 |
static int bcm5600_dump_trunks(struct nm_16esw_data *d) |
| 956 |
{ |
| 957 |
struct bcm5600_table *table; |
| 958 |
struct bcm5600_port *port; |
| 959 |
m_uint32_t *entry; |
| 960 |
int i,j; |
| 961 |
|
| 962 |
if (!(table = bcm5600_table_find(d,BCM5600_ADDR_TBMAP0))) |
| 963 |
return(-1); |
| 964 |
|
| 965 |
printf("%s: trunk ports:\n",d->name); |
| 966 |
|
| 967 |
for(i=table->min_index;i<=table->max_index;i++) { |
| 968 |
if (!(entry = bcm5600_table_get_entry(d,table,i))) |
| 969 |
break; |
| 970 |
|
| 971 |
if (!entry[0]) |
| 972 |
continue; |
| 973 |
|
| 974 |
printf(" Trunk %d: ",i); |
| 975 |
|
| 976 |
for(j=0;j<d->nr_port;j++) { |
| 977 |
if (entry[0] & (1 << j)) { |
| 978 |
port = &d->ports[j]; |
| 979 |
printf("%s ",port->name); |
| 980 |
} |
| 981 |
} |
| 982 |
|
| 983 |
printf("\n"); |
| 984 |
} |
| 985 |
|
| 986 |
printf("\n"); |
| 987 |
return(0); |
| 988 |
} |
| 989 |
|
| 990 |
/* Dump the physical port info */ |
| 991 |
static int bcm5600_dump_ports(struct nm_16esw_data *d) |
| 992 |
{ |
| 993 |
struct bcm5600_table *table; |
| 994 |
struct bcm5600_port *port; |
| 995 |
m_uint32_t *entry; |
| 996 |
u_int vlan,tgid; |
| 997 |
int i; |
| 998 |
|
| 999 |
if (!(table = bcm5600_table_find(d,BCM5600_ADDR_PTABLE0))) |
| 1000 |
return(-1); |
| 1001 |
|
| 1002 |
printf("%s: physical ports:\n",d->name); |
| 1003 |
|
| 1004 |
for(i=0;i<d->nr_port;i++) { |
| 1005 |
if (!(entry = bcm5600_table_get_entry(d,table,i))) |
| 1006 |
break; |
| 1007 |
|
| 1008 |
port = &d->ports[i]; |
| 1009 |
vlan = entry[0] & BCM5600_PTABLE_VLAN_TAG_MASK; |
| 1010 |
|
| 1011 |
printf(" %-10s: VLAN %u",port->name,vlan); |
| 1012 |
|
| 1013 |
if (entry[0] & BCM5600_PTABLE_TRUNK_FLAG) { |
| 1014 |
tgid = entry[0] & BCM5600_PTABLE_TGID_MASK; |
| 1015 |
tgid >>= BCM5600_PTABLE_TGID_SHIFT; |
| 1016 |
|
| 1017 |
printf(", Trunk Group %u ",tgid); |
| 1018 |
} |
| 1019 |
|
| 1020 |
printf("\n"); |
| 1021 |
} |
| 1022 |
|
| 1023 |
printf("\n"); |
| 1024 |
return(0); |
| 1025 |
} |
| 1026 |
|
| 1027 |
/* Dump the physical port bitmaps */ |
| 1028 |
static int bcm5600_dump_port_bitmaps(struct nm_16esw_data *d) |
| 1029 |
{ |
| 1030 |
struct bcm5600_table *table; |
| 1031 |
struct bcm5600_port *port; |
| 1032 |
m_uint32_t *entry,tbmp,ubmp; |
| 1033 |
int i,j; |
| 1034 |
|
| 1035 |
if (!(table = bcm5600_table_find(d,BCM5600_ADDR_PTABLE0))) |
| 1036 |
return(-1); |
| 1037 |
|
| 1038 |
printf("%s: dumping bitmaps of the port table:\n",d->name); |
| 1039 |
|
| 1040 |
for(i=0;i<d->nr_port;i++) { |
| 1041 |
if (!(entry = bcm5600_table_get_entry(d,table,i))) |
| 1042 |
break; |
| 1043 |
|
| 1044 |
port = &d->ports[i]; |
| 1045 |
|
| 1046 |
printf(" %-10s: ",port->name); |
| 1047 |
|
| 1048 |
for(j=0;j<d->nr_port;j++) { |
| 1049 |
tbmp = entry[1] & (1 << j); |
| 1050 |
ubmp = entry[2] & (1 << j); |
| 1051 |
|
| 1052 |
if (tbmp || ubmp) { |
| 1053 |
printf("%s (",d->ports[j].name); |
| 1054 |
|
| 1055 |
if (tbmp) |
| 1056 |
printf("T%s",ubmp ? "/" : ") "); |
| 1057 |
|
| 1058 |
if (ubmp) |
| 1059 |
printf("UT) "); |
| 1060 |
} |
| 1061 |
} |
| 1062 |
|
| 1063 |
printf("\n"); |
| 1064 |
} |
| 1065 |
|
| 1066 |
printf("\n"); |
| 1067 |
return(0); |
| 1068 |
} |
| 1069 |
|
| 1070 |
/* Dump main tables */ |
| 1071 |
static void bcm5600_dump_main_tables(struct nm_16esw_data *d) |
| 1072 |
{ |
| 1073 |
bcm5600_dump_ports(d); |
| 1074 |
bcm5600_dump_port_bitmaps(d); |
| 1075 |
bcm5600_dump_vtable(d); |
| 1076 |
bcm5600_dump_trunks(d); |
| 1077 |
} |
| 1078 |
|
| 1079 |
/* Find a free ARL entry */ |
| 1080 |
static int bcm5600_find_free_arl_entry(struct nm_16esw_data *d) |
| 1081 |
{ |
| 1082 |
struct bcm5600_table *table = d->t_arl; |
| 1083 |
|
| 1084 |
if (d->arl_cnt[0] == table->max_index) |
| 1085 |
return(-1); |
| 1086 |
|
| 1087 |
return(d->arl_cnt[0] - 1); |
| 1088 |
} |
| 1089 |
|
| 1090 |
/* ARL Lookup. TODO: this must be optimized in the future. */ |
| 1091 |
static inline int bcm5600_gen_arl_lookup(struct nm_16esw_data *d, |
| 1092 |
struct bcm5600_table *table, |
| 1093 |
u_int index_start,u_int index_end, |
| 1094 |
n_eth_addr_t *mac_addr, |
| 1095 |
u_int vlan) |
| 1096 |
{ |
| 1097 |
m_uint32_t *entry,tmp[2],mask; |
| 1098 |
int i; |
| 1099 |
|
| 1100 |
tmp[0] = mac_addr->eth_addr_byte[2] << 24; |
| 1101 |
tmp[0] |= mac_addr->eth_addr_byte[3] << 16; |
| 1102 |
tmp[0] |= mac_addr->eth_addr_byte[4] << 8; |
| 1103 |
tmp[0] |= mac_addr->eth_addr_byte[5]; |
| 1104 |
|
| 1105 |
tmp[1] = (mac_addr->eth_addr_byte[0] << 8) | mac_addr->eth_addr_byte[1]; |
| 1106 |
tmp[1] |= vlan << BCM5600_ARL_VLAN_TAG_SHIFT; |
| 1107 |
|
| 1108 |
mask = BCM5600_ARL_VLAN_TAG_MASK | BCM5600_ARL_MAC_MSB_MASK; |
| 1109 |
|
| 1110 |
for(i=index_start;i<index_end;i++) { |
| 1111 |
entry = bcm5600_table_get_entry(d,table,i); |
| 1112 |
|
| 1113 |
if ((entry[0] == tmp[0]) && ((entry[1] & mask) == tmp[1])) |
| 1114 |
return(i); |
| 1115 |
} |
| 1116 |
|
| 1117 |
return(-1); |
| 1118 |
} |
| 1119 |
|
| 1120 |
/* ARL Lookup */ |
| 1121 |
static inline int bcm5600_arl_lookup(struct nm_16esw_data *d, |
| 1122 |
n_eth_addr_t *mac_addr, |
| 1123 |
u_int vlan) |
| 1124 |
{ |
| 1125 |
struct bcm5600_table *table = d->t_arl; |
| 1126 |
return(bcm5600_gen_arl_lookup(d,table,1,d->arl_cnt[0]-1,mac_addr,vlan)); |
| 1127 |
} |
| 1128 |
|
| 1129 |
/* MARL Lookup */ |
| 1130 |
static inline int bcm5600_marl_lookup(struct nm_16esw_data *d, |
| 1131 |
n_eth_addr_t *mac_addr, |
| 1132 |
u_int vlan) |
| 1133 |
{ |
| 1134 |
struct bcm5600_table *table = d->t_marl; |
| 1135 |
return(bcm5600_gen_arl_lookup(d,table,table->min_index,table->max_index+1, |
| 1136 |
mac_addr,vlan)); |
| 1137 |
} |
| 1138 |
|
| 1139 |
/* Invalidate an ARL entry */ |
| 1140 |
static void bcm5600_invalidate_arl_entry(m_uint32_t *entry) |
| 1141 |
{ |
| 1142 |
entry[0] = entry[1] = entry[2] = 0; |
| 1143 |
} |
| 1144 |
|
| 1145 |
/* Insert an entry into the ARL table */ |
| 1146 |
static int bcm5600_insert_arl_entry(struct nm_16esw_data *d) |
| 1147 |
{ |
| 1148 |
struct bcm5600_table *table = d->t_arl; |
| 1149 |
m_uint32_t *entry,mask; |
| 1150 |
int i,index; |
| 1151 |
|
| 1152 |
mask = BCM5600_ARL_VLAN_TAG_MASK | BCM5600_ARL_MAC_MSB_MASK; |
| 1153 |
|
| 1154 |
for(i=0;i<d->arl_cnt[0]-1;i++) { |
| 1155 |
entry = bcm5600_table_get_entry(d,table,i); |
| 1156 |
|
| 1157 |
/* If entry already exists, just modify it */ |
| 1158 |
if ((entry[0] == d->dw[1]) && ((entry[1] & mask) == (d->dw[2] & mask))) { |
| 1159 |
entry[0] = d->dw[1]; |
| 1160 |
entry[1] = d->dw[2]; |
| 1161 |
entry[2] = d->dw[3]; |
| 1162 |
d->dw[1] = i; |
| 1163 |
return(0); |
| 1164 |
} |
| 1165 |
} |
| 1166 |
|
| 1167 |
index = d->arl_cnt[0] - 1; |
| 1168 |
|
| 1169 |
entry = bcm5600_table_get_entry(d,table,index); |
| 1170 |
entry[0] = d->dw[1]; |
| 1171 |
entry[1] = d->dw[2]; |
| 1172 |
entry[2] = d->dw[3]; |
| 1173 |
d->dw[1] = index; |
| 1174 |
|
| 1175 |
d->arl_cnt[0]++; |
| 1176 |
return(0); |
| 1177 |
} |
| 1178 |
|
| 1179 |
/* Delete an entry from the ARL table */ |
| 1180 |
static int bcm5600_delete_arl_entry(struct nm_16esw_data *d) |
| 1181 |
{ |
| 1182 |
struct bcm5600_table *table; |
| 1183 |
m_uint32_t *entry,*last_entry,mac_msb; |
| 1184 |
u_int cvlan,vlan; |
| 1185 |
int i; |
| 1186 |
|
| 1187 |
if (!(table = bcm5600_table_find(d,BCM5600_ADDR_ARL0))) |
| 1188 |
return(-1); |
| 1189 |
|
| 1190 |
vlan = d->dw[2] & BCM5600_ARL_VLAN_TAG_MASK; |
| 1191 |
vlan >>= BCM5600_ARL_VLAN_TAG_SHIFT; |
| 1192 |
|
| 1193 |
mac_msb = d->dw[2] & BCM5600_ARL_MAC_MSB_MASK; |
| 1194 |
|
| 1195 |
for(i=table->min_index;i<=table->max_index;i++) { |
| 1196 |
entry = bcm5600_table_get_entry(d,table,i); |
| 1197 |
|
| 1198 |
/* compare VLANs and MAC addresses */ |
| 1199 |
cvlan = (entry[1] & BCM5600_ARL_VLAN_TAG_MASK); |
| 1200 |
cvlan >>= BCM5600_ARL_VLAN_TAG_SHIFT; |
| 1201 |
|
| 1202 |
if ((cvlan == vlan) && (entry[0] == d->dw[1]) && |
| 1203 |
((entry[1] & BCM5600_ARL_MAC_MSB_MASK) == mac_msb)) |
| 1204 |
{ |
| 1205 |
d->dw[1] = i; |
| 1206 |
|
| 1207 |
last_entry = bcm5600_table_get_entry(d,d->t_arl,d->arl_cnt[0]-2); |
| 1208 |
|
| 1209 |
entry[0] = last_entry[0]; |
| 1210 |
entry[1] = last_entry[1]; |
| 1211 |
entry[2] = last_entry[2]; |
| 1212 |
|
| 1213 |
d->arl_cnt[0]--; |
| 1214 |
return(i); |
| 1215 |
} |
| 1216 |
} |
| 1217 |
|
| 1218 |
return(0); |
| 1219 |
} |
| 1220 |
|
| 1221 |
/* Reset the ARL tables */ |
| 1222 |
static int bcm5600_reset_arl(struct nm_16esw_data *d) |
| 1223 |
{ |
| 1224 |
struct bcm5600_table *table; |
| 1225 |
m_uint32_t *entry; |
| 1226 |
int i; |
| 1227 |
|
| 1228 |
if (!(table = bcm5600_table_find(d,BCM5600_ADDR_ARL0))) |
| 1229 |
return(-1); |
| 1230 |
|
| 1231 |
for(i=table->min_index;i<=table->max_index;i++) { |
| 1232 |
entry = bcm5600_table_get_entry(d,table,i); |
| 1233 |
bcm5600_invalidate_arl_entry(entry); |
| 1234 |
} |
| 1235 |
|
| 1236 |
return(0); |
| 1237 |
} |
| 1238 |
|
| 1239 |
/* MAC Address Ager */ |
| 1240 |
static int bcm5600_arl_ager(struct nm_16esw_data *d) |
| 1241 |
{ |
| 1242 |
m_uint32_t *entry,*last_entry; |
| 1243 |
int i; |
| 1244 |
|
| 1245 |
BCM_LOCK(d); |
| 1246 |
|
| 1247 |
for(i=1;i<d->arl_cnt[0]-1;i++) { |
| 1248 |
entry = bcm5600_table_get_entry(d,d->t_arl,i); |
| 1249 |
assert(entry); |
| 1250 |
|
| 1251 |
if (entry[2] & BCM5600_ARL_ST_FLAG) |
| 1252 |
continue; |
| 1253 |
|
| 1254 |
/* The entry has expired, purge it */ |
| 1255 |
if (!(entry[2] & BCM5600_ARL_HIT_FLAG)) { |
| 1256 |
last_entry = bcm5600_table_get_entry(d,d->t_arl,d->arl_cnt[0]-2); |
| 1257 |
|
| 1258 |
entry[0] = last_entry[0]; |
| 1259 |
entry[1] = last_entry[1]; |
| 1260 |
entry[2] = last_entry[2]; |
| 1261 |
|
| 1262 |
d->arl_cnt[0]--; |
| 1263 |
i--; |
| 1264 |
} else { |
| 1265 |
entry[2] &= ~BCM5600_ARL_HIT_FLAG; |
| 1266 |
} |
| 1267 |
} |
| 1268 |
|
| 1269 |
BCM_UNLOCK(d); |
| 1270 |
return(TRUE); |
| 1271 |
} |
| 1272 |
|
| 1273 |
/* Get the VTABLE entry matching the specified VLAN */ |
| 1274 |
static m_uint32_t *bcm5600_vtable_get_entry_by_vlan(struct nm_16esw_data *d, |
| 1275 |
u_int vlan) |
| 1276 |
{ |
| 1277 |
struct bcm5600_table *table = d->t_vtable; |
| 1278 |
m_uint32_t *entry; |
| 1279 |
int i; |
| 1280 |
|
| 1281 |
for(i=table->min_index;i<=table->max_index;i++) { |
| 1282 |
if (!(entry = bcm5600_table_get_entry(d,table,i))) |
| 1283 |
break; |
| 1284 |
|
| 1285 |
if ((entry[0] & BCM5600_VTABLE_VLAN_TAG_MASK) == vlan) |
| 1286 |
return entry; |
| 1287 |
} |
| 1288 |
|
| 1289 |
return NULL; |
| 1290 |
} |
| 1291 |
|
| 1292 |
/* Read memory command */ |
| 1293 |
static void bcm5600_handle_read_mem_cmd(struct nm_16esw_data *d) |
| 1294 |
{ |
| 1295 |
int i; |
| 1296 |
|
| 1297 |
if (bcm5600_table_read_entry(d) != 0) { |
| 1298 |
for(i=1;i<BCM5600_DW_MAX;i++) |
| 1299 |
d->dw[i] = 0; |
| 1300 |
} |
| 1301 |
|
| 1302 |
d->dw[0] = BCM5600_OP_READ_MEM_ACK << BCM5600_CMD_OP_SHIFT; |
| 1303 |
} |
| 1304 |
|
| 1305 |
/* Write memory command */ |
| 1306 |
static void bcm5600_handle_write_mem_cmd(struct nm_16esw_data *d) |
| 1307 |
{ |
| 1308 |
bcm5600_table_write_entry(d); |
| 1309 |
d->dw[0] = BCM5600_OP_WRITE_MEM_ACK << BCM5600_CMD_OP_SHIFT; |
| 1310 |
} |
| 1311 |
|
| 1312 |
/* Handle a "general" command */ |
| 1313 |
static void bcm5600_handle_gen_cmd(struct nm_16esw_data *d) |
| 1314 |
{ |
| 1315 |
m_uint32_t op; |
| 1316 |
_maybe_used m_uint32_t src,dst,len; |
| 1317 |
|
| 1318 |
/* Extract the opcode */ |
| 1319 |
op = (d->dw[0] & BCM5600_CMD_OP_MASK) >> BCM5600_CMD_OP_SHIFT; |
| 1320 |
src = (d->dw[0] & BCM5600_CMD_SRC_MASK) >> BCM5600_CMD_SRC_SHIFT; |
| 1321 |
dst = (d->dw[0] & BCM5600_CMD_DST_MASK) >> BCM5600_CMD_DST_SHIFT; |
| 1322 |
len = (d->dw[0] & BCM5600_CMD_LEN_MASK) >> BCM5600_CMD_LEN_SHIFT; |
| 1323 |
|
| 1324 |
#if DEBUG_ACCESS |
| 1325 |
BCM_LOG(d,"gen_cmd: opcode 0x%2.2x [src=0x%2.2x,dst=0x%2.2x,len=0x%2.2x] " |
| 1326 |
"(dw[0]=0x%8.8x, dw[1]=0x%8.8x, dw[2]=0x%8.8x, dw[3]=0x%8.8x)\n", |
| 1327 |
op,src,dst,len,d->dw[0],d->dw[1],d->dw[2],d->dw[3]); |
| 1328 |
#endif |
| 1329 |
|
| 1330 |
switch(op) { |
| 1331 |
case BCM5600_OP_READ_MEM_CMD: |
| 1332 |
bcm5600_handle_read_mem_cmd(d); |
| 1333 |
break; |
| 1334 |
|
| 1335 |
case BCM5600_OP_WRITE_MEM_CMD: |
| 1336 |
bcm5600_handle_write_mem_cmd(d); |
| 1337 |
break; |
| 1338 |
|
| 1339 |
case BCM5600_OP_READ_REG_CMD: |
| 1340 |
d->dw[0] = BCM5600_OP_READ_REG_ACK << BCM5600_CMD_OP_SHIFT; |
| 1341 |
#if DEBUG_REG |
| 1342 |
BCM_LOG(d,"READ_REG: reg_addr=0x%8.8x\n",d->dw[1]); |
| 1343 |
#endif |
| 1344 |
d->dw[1] = bcm5600_reg_read(d,d->dw[1]); |
| 1345 |
break; |
| 1346 |
|
| 1347 |
case BCM5600_OP_WRITE_REG_CMD: |
| 1348 |
d->dw[0] = BCM5600_OP_WRITE_REG_ACK << BCM5600_CMD_OP_SHIFT; |
| 1349 |
#if DEBUG_REG |
| 1350 |
BCM_LOG(d,"WRITE_REG: reg_addr=0x%8.8x val=0x%8.8x\n", |
| 1351 |
d->dw[1],d->dw[2]); |
| 1352 |
#endif |
| 1353 |
bcm5600_reg_write(d,d->dw[1],d->dw[2]); |
| 1354 |
bcm5600_reg_write_special(d,d->dw[1],d->dw[2]); |
| 1355 |
break; |
| 1356 |
|
| 1357 |
case BCM5600_OP_ARL_INSERT_CMD: |
| 1358 |
d->dw[0] = BCM5600_OP_ARL_INSERT_DONE << BCM5600_CMD_OP_SHIFT; |
| 1359 |
|
| 1360 |
#if DEBUG_ARL |
| 1361 |
BCM_LOG(d,"ARL_INSERT_CMD " |
| 1362 |
"(dw[1]=0x%8.8x,dw[2]=0x%8.8x,dw[3]=0x%8.8x)\n", |
| 1363 |
d->dw[1],d->dw[2],d->dw[3]); |
| 1364 |
#endif |
| 1365 |
bcm5600_insert_arl_entry(d); |
| 1366 |
break; |
| 1367 |
|
| 1368 |
case BCM5600_OP_ARL_DELETE_CMD: |
| 1369 |
d->dw[0] = BCM5600_OP_ARL_DELETE_DONE << BCM5600_CMD_OP_SHIFT; |
| 1370 |
|
| 1371 |
#if DEBUG_ARL |
| 1372 |
BCM_LOG(d,"ARL_DELETE_CMD (dw[1]=0x%8.8x,dw[2]=0x%8.8x)\n", |
| 1373 |
d->dw[1],d->dw[2]); |
| 1374 |
#endif |
| 1375 |
bcm5600_delete_arl_entry(d); |
| 1376 |
break; |
| 1377 |
|
| 1378 |
case BCM5600_OP_ARL_LOOKUP_CMD: |
| 1379 |
d->dw[0] = BCM5600_OP_READ_MEM_ACK << BCM5600_CMD_OP_SHIFT; |
| 1380 |
break; |
| 1381 |
|
| 1382 |
default: |
| 1383 |
BCM_LOG(d,"unknown opcode 0x%8.8x (cmd=0x%8.8x)\n",op,d->dw[0]); |
| 1384 |
} |
| 1385 |
} |
| 1386 |
|
| 1387 |
/* Handle a s-channel command */ |
| 1388 |
static void bcm5600_handle_schan_cmd(struct nm_16esw_data *d,m_uint32_t cmd) |
| 1389 |
{ |
| 1390 |
d->schan_cmd = cmd; |
| 1391 |
|
| 1392 |
#if DEBUG_ACCESS |
| 1393 |
BCM_LOG(d,"s-chan command 0x%8.8x\n",cmd); |
| 1394 |
#endif |
| 1395 |
|
| 1396 |
switch(cmd) { |
| 1397 |
case BCM5600_SCHAN_CMD_EXEC: |
| 1398 |
bcm5600_handle_gen_cmd(d); |
| 1399 |
d->schan_cmd_res = 0x00008002; |
| 1400 |
break; |
| 1401 |
|
| 1402 |
case BCM5600_SCHAN_CMD_READ_MII: |
| 1403 |
bcm5600_mii_read(d); |
| 1404 |
d->schan_cmd_res = 0x00048000; |
| 1405 |
break; |
| 1406 |
|
| 1407 |
case BCM5600_SCHAN_CMD_WRITE_MII: |
| 1408 |
bcm5600_mii_write(d); |
| 1409 |
d->schan_cmd_res = 0x00048000; |
| 1410 |
break; |
| 1411 |
|
| 1412 |
case BCM5600_SCHAN_CMD_LINKSCAN: |
| 1413 |
d->schan_cmd_res = 0x0; |
| 1414 |
break; |
| 1415 |
|
| 1416 |
default: |
| 1417 |
#if DEBUG_UNKNOWN |
| 1418 |
BCM_LOG(d,"unknown s-chan command 0x%8.8x\n",cmd); |
| 1419 |
#endif |
| 1420 |
d->schan_cmd_res = 0xFFFFFFFF; |
| 1421 |
} |
| 1422 |
} |
| 1423 |
|
| 1424 |
/* |
| 1425 |
* dev_bcm5605_access() |
| 1426 |
*/ |
| 1427 |
void *dev_bcm5605_access(cpu_gen_t *cpu,struct vdevice *dev,m_uint32_t offset, |
| 1428 |
u_int op_size,u_int op_type,m_uint64_t *data) |
| 1429 |
{ |
| 1430 |
struct nm_16esw_data *d = dev->priv_data; |
| 1431 |
u_int reg; |
| 1432 |
|
| 1433 |
if (op_type == MTS_READ) |
| 1434 |
*data = 0; |
| 1435 |
|
| 1436 |
#if DEBUG_ACCESS |
| 1437 |
if (op_type == MTS_READ) { |
| 1438 |
BCM_LOG(d,"read access to offset=0x%x, pc=0x%llx\n", |
| 1439 |
offset,cpu_get_pc(cpu)); |
| 1440 |
} else { |
| 1441 |
BCM_LOG(d,"write access to offset=0x%x, pc=0x%llx, val=0x%llx\n", |
| 1442 |
offset,cpu_get_pc(cpu),*data); |
| 1443 |
} |
| 1444 |
#endif |
| 1445 |
|
| 1446 |
BCM_LOCK(d); |
| 1447 |
|
| 1448 |
switch(offset) { |
| 1449 |
case 0x50: |
| 1450 |
if (op_type == MTS_WRITE) { |
| 1451 |
bcm5600_handle_schan_cmd(d,*data); |
| 1452 |
} else { |
| 1453 |
*data = d->schan_cmd_res; |
| 1454 |
} |
| 1455 |
break; |
| 1456 |
|
| 1457 |
case 0x140: |
| 1458 |
if (op_type == MTS_READ) |
| 1459 |
*data = bcm5600_mii_port_status_bmp(d); |
| 1460 |
break; |
| 1461 |
|
| 1462 |
/* MII input register */ |
| 1463 |
case 0x158: |
| 1464 |
if (op_type == MTS_WRITE) |
| 1465 |
d->mii_input = *data; |
| 1466 |
break; |
| 1467 |
|
| 1468 |
/* MII output register */ |
| 1469 |
case 0x15c: |
| 1470 |
if (op_type == MTS_READ) |
| 1471 |
*data = d->mii_output; |
| 1472 |
break; |
| 1473 |
|
| 1474 |
/* Unknown (related to RX/TX rings ?) */ |
| 1475 |
case 0x104: |
| 1476 |
break; |
| 1477 |
|
| 1478 |
/* TX ring address */ |
| 1479 |
case 0x110: |
| 1480 |
if (op_type == MTS_READ) |
| 1481 |
*data = d->tx_ring_addr; |
| 1482 |
else { |
| 1483 |
d->tx_ring_addr = d->tx_current = *data; |
| 1484 |
d->tx_end_scan = 0; |
| 1485 |
#if DEBUG_TRANSMIT |
| 1486 |
BCM_LOG(d,"tx_ring_addr = 0x%8.8x\n",d->tx_ring_addr); |
| 1487 |
#endif |
| 1488 |
} |
| 1489 |
break; |
| 1490 |
|
| 1491 |
/* RX ring address */ |
| 1492 |
case 0x114: |
| 1493 |
if (op_type == MTS_READ) |
| 1494 |
*data = d->rx_ring_addr; |
| 1495 |
else { |
| 1496 |
d->rx_ring_addr = d->rx_current = *data; |
| 1497 |
d->rx_end_scan = 0; |
| 1498 |
#if DEBUG_RECEIVE |
| 1499 |
BCM_LOG(d,"rx_ring_addr = 0x%8.8x\n",d->rx_ring_addr); |
| 1500 |
#endif |
| 1501 |
} |
| 1502 |
break; |
| 1503 |
|
| 1504 |
/* Interrupt status */ |
| 1505 |
case 0x144: |
| 1506 |
if (op_type == MTS_READ) { |
| 1507 |
*data = 0; |
| 1508 |
|
| 1509 |
/* RX/TX underrun (end of rings reached) */ |
| 1510 |
if (d->tx_end_scan) |
| 1511 |
*data |= BCM5600_INTR_TX_UNDERRUN; |
| 1512 |
|
| 1513 |
if (d->rx_end_scan) |
| 1514 |
*data |= BCM5600_INTR_RX_UNDERRUN; |
| 1515 |
|
| 1516 |
/* RX packet available */ |
| 1517 |
*data |= BCM5600_INTR_RX_AVAIL; |
| 1518 |
|
| 1519 |
/* Link status changed */ |
| 1520 |
if (d->mii_intr) { |
| 1521 |
*data |= BCM5600_INTR_LINKSTAT_MOD; |
| 1522 |
d->mii_intr = FALSE; |
| 1523 |
} |
| 1524 |
|
| 1525 |
pci_dev_clear_irq(d->vm,d->pci_dev); |
| 1526 |
} |
| 1527 |
break; |
| 1528 |
|
| 1529 |
/* Interrupt mask */ |
| 1530 |
case 0x148: |
| 1531 |
if (op_type == MTS_READ) |
| 1532 |
*data = d->intr_mask; |
| 1533 |
else |
| 1534 |
d->intr_mask = *data; |
| 1535 |
break; |
| 1536 |
|
| 1537 |
/* Data Words */ |
| 1538 |
case 0x800 ... 0x850: |
| 1539 |
reg = (offset - 0x800) >> 2; |
| 1540 |
|
| 1541 |
if (op_type == MTS_READ) |
| 1542 |
*data = d->dw[reg]; |
| 1543 |
else |
| 1544 |
d->dw[reg] = *data; |
| 1545 |
break; |
| 1546 |
|
| 1547 |
#if DEBUG_UNKNOWN |
| 1548 |
/* Unknown offset */ |
| 1549 |
default: |
| 1550 |
if (op_type == MTS_READ) { |
| 1551 |
BCM_LOG(d,"read from unknown addr 0x%x, pc=0x%llx (size=%u)\n", |
| 1552 |
offset,cpu_get_pc(cpu),op_size); |
| 1553 |
} else { |
| 1554 |
BCM_LOG(d,"write to unknown addr 0x%x, value=0x%llx, " |
| 1555 |
"pc=0x%llx (size=%u)\n", |
| 1556 |
offset,*data,cpu_get_pc(cpu),op_size); |
| 1557 |
} |
| 1558 |
#endif |
| 1559 |
} |
| 1560 |
|
| 1561 |
BCM_UNLOCK(d); |
| 1562 |
return NULL; |
| 1563 |
} |
| 1564 |
|
| 1565 |
/* Show mirroring status */ |
| 1566 |
static int bcm5600_mirror_show_status(struct nm_16esw_data *d) |
| 1567 |
{ |
| 1568 |
m_uint32_t *port,dst_port; |
| 1569 |
int i; |
| 1570 |
|
| 1571 |
printf("Mirroring status: "); |
| 1572 |
|
| 1573 |
if (!(d->mirror_dst_port & BCM5600_MIRROR_ENABLE)) { |
| 1574 |
printf("disabled.\n\n"); |
| 1575 |
return(FALSE); |
| 1576 |
} |
| 1577 |
|
| 1578 |
printf("enabled. Dest port: "); |
| 1579 |
|
| 1580 |
dst_port = d->mirror_dst_port & BCM5600_MIRROR_PORT_MASK; |
| 1581 |
|
| 1582 |
if (dst_port < 32) |
| 1583 |
printf("%s\n",d->ports[dst_port].name); |
| 1584 |
else |
| 1585 |
printf("none set.\n"); |
| 1586 |
|
| 1587 |
/* Ingress info */ |
| 1588 |
printf(" Ingress Ports: "); |
| 1589 |
|
| 1590 |
for(i=0;i<d->nr_port;i++) { |
| 1591 |
port = bcm5600_table_get_entry(d,d->t_ptable,i); |
| 1592 |
if (port[1] & BCM5600_PTABLE_MI_FLAG) |
| 1593 |
printf("%s ",d->ports[i].name); |
| 1594 |
} |
| 1595 |
|
| 1596 |
printf("\n"); |
| 1597 |
|
| 1598 |
/* Egress info */ |
| 1599 |
printf(" Egress Ports: "); |
| 1600 |
|
| 1601 |
for(i=0;i<d->nr_port;i++) |
| 1602 |
if (d->mirror_egress_ports & (1 << i)) |
| 1603 |
printf("%s ",d->ports[i].name); |
| 1604 |
|
| 1605 |
printf("\n\n"); |
| 1606 |
return(TRUE); |
| 1607 |
} |
| 1608 |
|
| 1609 |
/* Mirror a packet */ |
| 1610 |
static int bcm5600_mirror_pkt(struct nm_16esw_data *d,struct bcm5600_pkt *p, |
| 1611 |
int reason) |
| 1612 |
{ |
| 1613 |
u_int mport; |
| 1614 |
|
| 1615 |
if (!(d->mirror_dst_port & BCM5600_MIRROR_ENABLE)) |
| 1616 |
return(FALSE); |
| 1617 |
|
| 1618 |
#if DEBUG_MIRROR |
| 1619 |
if (reason == 0) { |
| 1620 |
BCM_LOG(d,"mirroring packet on ingress port %s\n", |
| 1621 |
d->ports[p->ingress_port]); |
| 1622 |
} else { |
| 1623 |
BCM_LOG(d,"mirroring packet on egress port (input port %s)\n", |
| 1624 |
d->ports[p->ingress_port]); |
| 1625 |
} |
| 1626 |
mem_dump(d->vm->log_fd,pkt,pkt_len); |
| 1627 |
#endif |
| 1628 |
|
| 1629 |
mport = d->mirror_dst_port & BCM5600_MIRROR_PORT_MASK; |
| 1630 |
if (mport < 32) |
| 1631 |
netio_send(d->ports[mport].nio,p->pkt,p->pkt_len); |
| 1632 |
return(TRUE); |
| 1633 |
} |
| 1634 |
|
| 1635 |
/* Put a packet into the RX ring (tag it if necessary) */ |
| 1636 |
static int bcm5600_send_pkt_to_cpu(struct nm_16esw_data *d, |
| 1637 |
struct bcm5600_pkt *p) |
| 1638 |
{ |
| 1639 |
m_uint32_t pkt_addr,pkt_len,dot1q_data; |
| 1640 |
|
| 1641 |
/* If the packet was already sent to CPU, don't send it again */ |
| 1642 |
if (p->sent_to_cpu) |
| 1643 |
return(FALSE); |
| 1644 |
|
| 1645 |
pkt_addr = p->rdes[0]; |
| 1646 |
pkt_len = p->pkt_len; |
| 1647 |
|
| 1648 |
if (p->orig_vlan != -1) { |
| 1649 |
/* 802.1Q packet: copy it directly */ |
| 1650 |
physmem_copy_to_vm(d->vm,p->pkt,pkt_addr,pkt_len); |
| 1651 |
} else { |
| 1652 |
/* untagged packet: copy the dst and src addresses first */ |
| 1653 |
physmem_copy_to_vm(d->vm,p->pkt,pkt_addr,N_ETH_HLEN - 2); |
| 1654 |
|
| 1655 |
/* add the 802.1Q protocol field (0x8100) + VLAN info */ |
| 1656 |
dot1q_data = (N_ETH_PROTO_DOT1Q << 16) | p->real_vlan; |
| 1657 |
physmem_copy_u32_to_vm(d->vm,pkt_addr+N_ETH_HLEN-2,dot1q_data); |
| 1658 |
|
| 1659 |
/* copy the payload */ |
| 1660 |
physmem_copy_to_vm(d->vm,p->pkt+N_ETH_HLEN-2, |
| 1661 |
pkt_addr+sizeof(n_eth_dot1q_hdr_t), |
| 1662 |
pkt_len - (N_ETH_HLEN - 2)); |
| 1663 |
pkt_len += 4; |
| 1664 |
} |
| 1665 |
|
| 1666 |
physmem_copy_u32_to_vm(d->vm,d->rx_current+0x14,0x40000000 + (pkt_len+4)); |
| 1667 |
physmem_copy_u32_to_vm(d->vm,d->rx_current+0x18,0x100 + p->ingress_port); |
| 1668 |
p->sent_to_cpu = TRUE; |
| 1669 |
|
| 1670 |
#if DEBUG_RECEIVE |
| 1671 |
BCM_LOG(d,"sending packet to CPU (orig_vlan=%d).\n",p->orig_vlan); |
| 1672 |
#endif |
| 1673 |
return(TRUE); |
| 1674 |
} |
| 1675 |
|
| 1676 |
/* Source MAC address learning */ |
| 1677 |
static int bcm5600_src_mac_learning(struct nm_16esw_data *d, |
| 1678 |
struct bcm5600_pkt *p) |
| 1679 |
{ |
| 1680 |
n_eth_hdr_t *eth_hdr = (n_eth_hdr_t *)p->pkt; |
| 1681 |
n_eth_addr_t *src_mac = ð_hdr->saddr; |
| 1682 |
m_uint32_t *arl_entry,*src_port,*trunk; |
| 1683 |
u_int trunk_id,old_ingress_port; |
| 1684 |
int src_mac_index; |
| 1685 |
|
| 1686 |
trunk = NULL; |
| 1687 |
trunk_id = 0; |
| 1688 |
|
| 1689 |
/* Skip multicast sources */ |
| 1690 |
if (eth_addr_is_mcast(src_mac)) |
| 1691 |
return(FALSE); |
| 1692 |
|
| 1693 |
src_port = bcm5600_table_get_entry(d,d->t_ptable,p->ingress_port); |
| 1694 |
assert(src_port != NULL); |
| 1695 |
|
| 1696 |
/* |
| 1697 |
* The packet comes from a trunk port. Prevent sending the packet |
| 1698 |
* to the other ports of the trunk. |
| 1699 |
*/ |
| 1700 |
if (src_port[0] & BCM5600_PTABLE_TRUNK_FLAG) { |
| 1701 |
trunk_id = src_port[0] & BCM5600_PTABLE_TGID_MASK; |
| 1702 |
trunk_id >>= BCM5600_PTABLE_TGID_SHIFT; |
| 1703 |
|
| 1704 |
trunk = bcm5600_table_get_entry(d,d->t_tbmap,trunk_id); |
| 1705 |
assert(trunk != NULL); |
| 1706 |
|
| 1707 |
p->egress_filter_bitmap |= trunk[0] & BCM5600_TBMAP_MASK; |
| 1708 |
} |
| 1709 |
|
| 1710 |
/* Source MAC address learning */ |
| 1711 |
src_mac_index = bcm5600_arl_lookup(d,src_mac,p->real_vlan); |
| 1712 |
|
| 1713 |
if (src_mac_index != -1) { |
| 1714 |
arl_entry = bcm5600_table_get_entry(d,d->t_arl,src_mac_index); |
| 1715 |
assert(arl_entry != NULL); |
| 1716 |
|
| 1717 |
old_ingress_port = arl_entry[2] & BCM5600_ARL_PORT_MASK; |
| 1718 |
old_ingress_port >>= BCM5600_ARL_PORT_SHIFT; |
| 1719 |
|
| 1720 |
if (old_ingress_port != p->ingress_port) |
| 1721 |
{ |
| 1722 |
/* |
| 1723 |
* Determine if we have a station movement. |
| 1724 |
* If we have a trunk, check if the old ingress port is member |
| 1725 |
* of this trunk, in this case this is not a movement. |
| 1726 |
*/ |
| 1727 |
if (trunk != NULL) { |
| 1728 |
if (trunk[0] & (1 << old_ingress_port)) |
| 1729 |
arl_entry[2] |= BCM5600_ARL_HIT_FLAG; |
| 1730 |
else |
| 1731 |
arl_entry[2] &= ~BCM5600_ARL_HIT_FLAG; |
| 1732 |
} else { |
| 1733 |
arl_entry[2] &= ~(BCM5600_ARL_TRUNK_FLAG|BCM5600_ARL_HIT_FLAG); |
| 1734 |
arl_entry[2] &= ~BCM5600_ARL_TGID_MASK; |
| 1735 |
} |
| 1736 |
|
| 1737 |
/* Change the ingress port */ |
| 1738 |
arl_entry[2] &= ~BCM5600_ARL_PORT_MASK; |
| 1739 |
arl_entry[2] |= p->ingress_port << BCM5600_ARL_PORT_SHIFT; |
| 1740 |
return(TRUE); |
| 1741 |
} |
| 1742 |
|
| 1743 |
arl_entry[2] |= BCM5600_ARL_HIT_FLAG; |
| 1744 |
return(TRUE); |
| 1745 |
} |
| 1746 |
|
| 1747 |
#if DEBUG_FORWARD |
| 1748 |
BCM_LOG(d,"source MAC address unknown, learning it.\n"); |
| 1749 |
#endif |
| 1750 |
|
| 1751 |
/* Add the new learned MAC address */ |
| 1752 |
src_mac_index = bcm5600_find_free_arl_entry(d); |
| 1753 |
|
| 1754 |
if (src_mac_index == -1) { |
| 1755 |
BCM_LOG(d,"no free entries in ARL table!\n"); |
| 1756 |
return(FALSE); |
| 1757 |
} |
| 1758 |
|
| 1759 |
arl_entry = bcm5600_table_get_entry(d,d->t_arl,src_mac_index); |
| 1760 |
assert(arl_entry != NULL); |
| 1761 |
|
| 1762 |
/* Fill the new ARL entry */ |
| 1763 |
arl_entry[0] = src_mac->eth_addr_byte[2] << 24; |
| 1764 |
arl_entry[0] |= src_mac->eth_addr_byte[3] << 16; |
| 1765 |
arl_entry[0] |= src_mac->eth_addr_byte[4] << 8; |
| 1766 |
arl_entry[0] |= src_mac->eth_addr_byte[5]; |
| 1767 |
|
| 1768 |
arl_entry[1] = src_mac->eth_addr_byte[0] << 8; |
| 1769 |
arl_entry[1] |= src_mac->eth_addr_byte[1]; |
| 1770 |
arl_entry[1] |= p->real_vlan << BCM5600_ARL_VLAN_TAG_SHIFT; |
| 1771 |
|
| 1772 |
arl_entry[2] = BCM5600_ARL_HIT_FLAG; |
| 1773 |
arl_entry[2] |= p->ingress_port << BCM5600_ARL_PORT_SHIFT; |
| 1774 |
|
| 1775 |
if (trunk != NULL) { |
| 1776 |
arl_entry[2] |= BCM5600_ARL_TRUNK_FLAG; |
| 1777 |
arl_entry[2] |= (trunk_id << BCM5600_ARL_TGID_SHIFT); |
| 1778 |
} |
| 1779 |
|
| 1780 |
d->arl_cnt[0]++; |
| 1781 |
return(TRUE); |
| 1782 |
} |
| 1783 |
|
| 1784 |
/* Select an egress port the specified trunk */ |
| 1785 |
static int bcm5600_trunk_egress_port(struct nm_16esw_data *d, |
| 1786 |
struct bcm5600_pkt *p, |
| 1787 |
u_int trunk_id) |
| 1788 |
{ |
| 1789 |
_maybe_used n_eth_hdr_t *eth_hdr = (n_eth_hdr_t *)p->pkt; |
| 1790 |
_maybe_used u_int i, hash; |
| 1791 |
struct bcm5600_tg_info *tgi; |
| 1792 |
m_uint32_t *ttr_entry; |
| 1793 |
u_int nr_links; |
| 1794 |
u_int port_id; |
| 1795 |
|
| 1796 |
ttr_entry = bcm5600_table_get_entry(d,d->t_ttr,trunk_id); |
| 1797 |
assert(ttr_entry != NULL); |
| 1798 |
|
| 1799 |
nr_links = ttr_entry[1] & BCM5600_TTR_TG_SIZE_MASK; |
| 1800 |
nr_links >>= BCM5600_TTR_TG_SIZE_SHIFT; |
| 1801 |
|
| 1802 |
#if 0 |
| 1803 |
/* Hash on source and destination MAC addresses */ |
| 1804 |
for(i=0,hash=0;i<N_ETH_ALEN;i++) { |
| 1805 |
hash ^= eth_hdr->saddr.eth_addr_byte[i]; |
| 1806 |
hash ^= eth_hdr->daddr.eth_addr_byte[i]; |
| 1807 |
} |
| 1808 |
|
| 1809 |
hash ^= (hash >> 4); |
| 1810 |
port_id = hash % nr_links; |
| 1811 |
|
| 1812 |
/* Maximum of 8 ports per trunk */ |
| 1813 |
assert(hash < BCM5600_MAX_PORTS_PER_TRUNK); |
| 1814 |
#else |
| 1815 |
port_id = d->trunk_last_egress_port[trunk_id] + 1; |
| 1816 |
port_id %= nr_links; |
| 1817 |
#endif |
| 1818 |
|
| 1819 |
/* Save the latest port used for this trunk */ |
| 1820 |
d->trunk_last_egress_port[trunk_id] = port_id; |
| 1821 |
|
| 1822 |
/* Select the egress port */ |
| 1823 |
tgi = &tg_info[port_id]; |
| 1824 |
return((ttr_entry[tgi->index] & tgi->mask) >> tgi->shift); |
| 1825 |
} |
| 1826 |
|
| 1827 |
/* Destination address lookup (take the forwarding decision) */ |
| 1828 |
static int bcm5600_dst_mac_lookup(struct nm_16esw_data *d, |
| 1829 |
struct bcm5600_pkt *p) |
| 1830 |
{ |
| 1831 |
n_eth_hdr_t *eth_hdr = (n_eth_hdr_t *)p->pkt; |
| 1832 |
n_eth_addr_t *dst_mac = ð_hdr->daddr; |
| 1833 |
struct bcm5600_table *arl_table; |
| 1834 |
m_uint32_t *arl_entry; |
| 1835 |
u_int egress_port; |
| 1836 |
u_int trunk_id; |
| 1837 |
int dst_mac_index; |
| 1838 |
int is_mcast; |
| 1839 |
|
| 1840 |
/* Select the appropriate ARL table and do the lookup on dst MAC + VLAN */ |
| 1841 |
if (eth_addr_is_mcast(dst_mac)) { |
| 1842 |
is_mcast = TRUE; |
| 1843 |
arl_table = d->t_marl; |
| 1844 |
dst_mac_index = bcm5600_marl_lookup(d,dst_mac,p->real_vlan); |
| 1845 |
} else { |
| 1846 |
is_mcast = FALSE; |
| 1847 |
arl_table = d->t_arl; |
| 1848 |
dst_mac_index = bcm5600_arl_lookup(d,dst_mac,p->real_vlan); |
| 1849 |
} |
| 1850 |
|
| 1851 |
/* |
| 1852 |
* Destination Lookup Failure (DLF). |
| 1853 |
* |
| 1854 |
* Use the VLAN bitmap to compute the Egress port bitmap. |
| 1855 |
* Remove the ingress port from it. |
| 1856 |
*/ |
| 1857 |
if (dst_mac_index == -1) { |
| 1858 |
#if DEBUG_FORWARD |
| 1859 |
BCM_LOG(d,"Destination MAC address " |
| 1860 |
"%2.2x%2.2x.%2.2x%2.2x.%2.2x%2.2x unknown, flooding.\n", |
| 1861 |
dst_mac->eth_addr_byte[0],dst_mac->eth_addr_byte[1], |
| 1862 |
dst_mac->eth_addr_byte[2],dst_mac->eth_addr_byte[3], |
| 1863 |
dst_mac->eth_addr_byte[4],dst_mac->eth_addr_byte[5]); |
| 1864 |
#endif |
| 1865 |
p->egress_bitmap = p->vlan_entry[1] & BCM5600_VTABLE_PORT_BMAP_MASK; |
| 1866 |
|
| 1867 |
/* Add the CPU to the egress ports */ |
| 1868 |
p->egress_bitmap |= 1 << d->cpu_port; |
| 1869 |
|
| 1870 |
p->egress_ut_bitmap = p->vlan_entry[2]; |
| 1871 |
p->egress_ut_bitmap &= BCM5600_VTABLE_UT_PORT_BMAP_MASK; |
| 1872 |
return(TRUE); |
| 1873 |
} |
| 1874 |
|
| 1875 |
/* The MAC address was found in the ARL/MARL table */ |
| 1876 |
arl_entry = bcm5600_table_get_entry(d,arl_table,dst_mac_index); |
| 1877 |
assert(arl_entry != NULL); |
| 1878 |
|
| 1879 |
/* If the CPU bit is set, send a copy of the packet to the CPU */ |
| 1880 |
if (arl_entry[1] & BCM5600_ARL_CPU_FLAG) |
| 1881 |
bcm5600_send_pkt_to_cpu(d,p); |
| 1882 |
|
| 1883 |
if (!is_mcast) { |
| 1884 |
/* Unicast: send the packet to the port or trunk found in ARL table */ |
| 1885 |
if (arl_entry[2] & BCM5600_ARL_TRUNK_FLAG) { |
| 1886 |
trunk_id = arl_entry[2] & BCM5600_ARL_TGID_MASK; |
| 1887 |
trunk_id >>= BCM5600_ARL_TGID_SHIFT; |
| 1888 |
|
| 1889 |
/* Select an output port for this trunk */ |
| 1890 |
egress_port = bcm5600_trunk_egress_port(d,p,trunk_id); |
| 1891 |
|
| 1892 |
#if DEBUG_FORWARD |
| 1893 |
BCM_LOG(d,"Sending packet to trunk port %u, egress port %u\n", |
| 1894 |
trunk_id,egress_port); |
| 1895 |
#endif |
| 1896 |
} else { |
| 1897 |
egress_port = arl_entry[2] & BCM5600_ARL_PORT_MASK; |
| 1898 |
egress_port >>= BCM5600_ARL_PORT_SHIFT; |
| 1899 |
} |
| 1900 |
|
| 1901 |
p->egress_bitmap = 1 << egress_port; |
| 1902 |
p->egress_ut_bitmap = p->vlan_entry[2] & |
| 1903 |
BCM5600_VTABLE_UT_PORT_BMAP_MASK; |
| 1904 |
} else { |
| 1905 |
/* Multicast: send the packet to the egress ports found in MARL table */ |
| 1906 |
p->egress_bitmap = arl_entry[2] & BCM5600_MARL_PORT_BMAP_MASK; |
| 1907 |
p->egress_ut_bitmap = arl_entry[3] & BCM5600_MARL_UT_PORT_BMAP_MASK; |
| 1908 |
} |
| 1909 |
|
| 1910 |
#if DEBUG_FORWARD |
| 1911 |
{ |
| 1912 |
char buffer[1024]; |
| 1913 |
|
| 1914 |
BCM_LOG(d,"bitmap: 0x%8.8x, filter: 0x%8.8x\n", |
| 1915 |
p->egress_bitmap,p->egress_filter_bitmap); |
| 1916 |
|
| 1917 |
bcm5600_port_bitmap_str(d,buffer,p->egress_bitmap); |
| 1918 |
|
| 1919 |
/* without egress port filtering */ |
| 1920 |
if (*buffer) |
| 1921 |
BCM_LOG(d,"forwarding to egress port list w/o filter: %s\n",buffer); |
| 1922 |
else |
| 1923 |
BCM_LOG(d,"w/o filter: empty egress port list.\n"); |
| 1924 |
|
| 1925 |
/* with egress port filtering */ |
| 1926 |
bcm5600_port_bitmap_str(d,buffer, |
| 1927 |
p->egress_bitmap & ~p->egress_filter_bitmap); |
| 1928 |
|
| 1929 |
if (*buffer) |
| 1930 |
BCM_LOG(d,"forwarding to egress port list w/ filter: %s\n",buffer); |
| 1931 |
} |
| 1932 |
#endif |
| 1933 |
|
| 1934 |
return(p->egress_bitmap != 0); |
| 1935 |
} |
| 1936 |
|
| 1937 |
/* Prototype for a packet sending function */ |
| 1938 |
typedef void (*bcm5600_send_pkt_t)(struct nm_16esw_data *d, |
| 1939 |
struct bcm5600_pkt *p, |
| 1940 |
netio_desc_t *nio); |
| 1941 |
|
| 1942 |
/* Directly forward a packet (not rewritten) */ |
| 1943 |
static void bcm5600_send_pkt_direct(struct nm_16esw_data *d, |
| 1944 |
struct bcm5600_pkt *p, |
| 1945 |
netio_desc_t *nio) |
| 1946 |
{ |
| 1947 |
netio_send(nio,p->pkt,p->pkt_len); |
| 1948 |
} |
| 1949 |
|
| 1950 |
/* Send a packet with a 802.1Q tag */ |
| 1951 |
static void bcm5600_send_pkt_push_dot1q(struct nm_16esw_data *d, |
| 1952 |
struct bcm5600_pkt *p, |
| 1953 |
netio_desc_t *nio) |
| 1954 |
{ |
| 1955 |
n_eth_dot1q_hdr_t *hdr; |
| 1956 |
|
| 1957 |
if (!p->rewrite_done) { |
| 1958 |
memcpy(p->rewr_pkt,p->pkt,(N_ETH_HLEN - 2)); |
| 1959 |
|
| 1960 |
hdr = (n_eth_dot1q_hdr_t *)p->rewr_pkt; |
| 1961 |
hdr->type = htons(N_ETH_PROTO_DOT1Q); |
| 1962 |
hdr->vlan_id = htons(p->real_vlan); |
| 1963 |
|
| 1964 |
memcpy(p->rewr_pkt + sizeof(n_eth_dot1q_hdr_t), |
| 1965 |
p->pkt + (N_ETH_HLEN - 2), |
| 1966 |
p->pkt_len - (N_ETH_HLEN - 2)); |
| 1967 |
|
| 1968 |
p->rewrite_done = TRUE; |
| 1969 |
} |
| 1970 |
|
| 1971 |
netio_send(nio,p->rewr_pkt,p->pkt_len+4); |
| 1972 |
} |
| 1973 |
|
| 1974 |
/* Send a packet deleting its 802.1Q tag */ |
| 1975 |
static void bcm5600_send_pkt_pop_dot1q(struct nm_16esw_data *d, |
| 1976 |
struct bcm5600_pkt *p, |
| 1977 |
netio_desc_t *nio) |
| 1978 |
{ |
| 1979 |
if (!p->rewrite_done) { |
| 1980 |
memcpy(p->rewr_pkt,p->pkt,(N_ETH_HLEN - 2)); |
| 1981 |
|
| 1982 |
memcpy(p->rewr_pkt + (N_ETH_HLEN - 2), |
| 1983 |
p->pkt + sizeof(n_eth_dot1q_hdr_t), |
| 1984 |
p->pkt_len - sizeof(n_eth_dot1q_hdr_t)); |
| 1985 |
|
| 1986 |
p->rewrite_done = TRUE; |
| 1987 |
} |
| 1988 |
|
| 1989 |
netio_send(nio,p->rewr_pkt,p->pkt_len-4); |
| 1990 |
} |
| 1991 |
|
| 1992 |
/* Forward a packet on physical ports (egress bitmap must be defined) */ |
| 1993 |
static int bcm5600_forward_pkt(struct nm_16esw_data *d,struct bcm5600_pkt *p) |
| 1994 |
{ |
| 1995 |
u_char rewr_pkt[BCM5600_MAX_PKT_SIZE]; |
| 1996 |
bcm5600_send_pkt_t send_pkt; |
| 1997 |
u_int egress_untagged,trunk_id; |
| 1998 |
m_uint32_t *dst_port,*trunk; |
| 1999 |
int i; |
| 2000 |
|
| 2001 |
p->egress_bitmap &= ~p->egress_filter_bitmap; |
| 2002 |
|
| 2003 |
if (!p->egress_bitmap) |
| 2004 |
return(FALSE); |
| 2005 |
|
| 2006 |
/* Process egress mirroring (if enabled) */ |
| 2007 |
if (p->egress_bitmap & d->mirror_egress_ports) |
| 2008 |
bcm5600_mirror_pkt(d,p,1); |
| 2009 |
|
| 2010 |
/* No rewrite done at this time */ |
| 2011 |
p->rewr_pkt = rewr_pkt; |
| 2012 |
p->rewrite_done = FALSE; |
| 2013 |
|
| 2014 |
/* Forward to CPU port ? */ |
| 2015 |
if (p->egress_bitmap & (1 << d->cpu_port)) |
| 2016 |
bcm5600_send_pkt_to_cpu(d,p); |
| 2017 |
|
| 2018 |
for(i=0;i<d->nr_port;i++) { |
| 2019 |
if (!(p->egress_bitmap & (1 << i))) |
| 2020 |
continue; |
| 2021 |
|
| 2022 |
/* |
| 2023 |
* If this port is a member of a trunk, remove all other ports to avoid |
| 2024 |
* duplicate frames (typically, when a dest MAC address is unknown |
| 2025 |
* or for a broadcast/multicast). |
| 2026 |
*/ |
| 2027 |
dst_port = bcm5600_table_get_entry(d,d->t_ptable,i); |
| 2028 |
assert(dst_port != NULL); |
| 2029 |
|
| 2030 |
if (dst_port[0] & BCM5600_PTABLE_TRUNK_FLAG) { |
| 2031 |
trunk_id = dst_port[0] & BCM5600_PTABLE_TGID_MASK; |
| 2032 |
trunk_id >>= BCM5600_PTABLE_TGID_SHIFT; |
| 2033 |
|
| 2034 |
trunk = bcm5600_table_get_entry(d,d->t_tbmap,trunk_id); |
| 2035 |
assert(trunk != NULL); |
| 2036 |
|
| 2037 |
p->egress_bitmap &= ~trunk[0]; |
| 2038 |
} |
| 2039 |
|
| 2040 |
/* select the appropriate output vector */ |
| 2041 |
if (p->orig_vlan == 0) |
| 2042 |
send_pkt = bcm5600_send_pkt_direct; |
| 2043 |
else { |
| 2044 |
egress_untagged = p->egress_ut_bitmap & (1 << i); |
| 2045 |
|
| 2046 |
if (p->orig_vlan == -1) { |
| 2047 |
/* Untagged packet */ |
| 2048 |
if (egress_untagged) |
| 2049 |
send_pkt = bcm5600_send_pkt_direct; |
| 2050 |
else |
| 2051 |
send_pkt = bcm5600_send_pkt_push_dot1q; |
| 2052 |
} else { |
| 2053 |
/* Tagged packet */ |
| 2054 |
if (egress_untagged) |
| 2055 |
send_pkt = bcm5600_send_pkt_pop_dot1q; |
| 2056 |
else |
| 2057 |
send_pkt = bcm5600_send_pkt_direct; |
| 2058 |
} |
| 2059 |
} |
| 2060 |
|
| 2061 |
#if DEBUG_FORWARD > 1 |
| 2062 |
BCM_LOG(d,"forwarding on port %s (vector=%p)\n", |
| 2063 |
d->ports[i].name,send_pkt); |
| 2064 |
#endif |
| 2065 |
send_pkt(d,p,d->ports[i].nio); |
| 2066 |
} |
| 2067 |
|
| 2068 |
return(TRUE); |
| 2069 |
} |
| 2070 |
|
| 2071 |
/* Determine if the specified MAC address matches a BPDU */ |
| 2072 |
static inline int bcm5600_is_bpdu(n_eth_addr_t *m) |
| 2073 |
{ |
| 2074 |
/* PVST+ */ |
| 2075 |
if (!memcmp(m,"\x01\x00\x0c\xcc\xcc\xcd",6)) |
| 2076 |
return(TRUE); |
| 2077 |
|
| 2078 |
/* Classical 802.1D */ |
| 2079 |
if (!memcmp(m,"\x01\x80\xc2\x00\x00",5) && !(m->eth_addr_byte[5] & 0xF0)) |
| 2080 |
return(TRUE); |
| 2081 |
|
| 2082 |
/* |
| 2083 |
* CDP: this is cleary a hack, but IOS seems to program this address |
| 2084 |
* in BPDU registers. |
| 2085 |
*/ |
| 2086 |
if (!memcmp(m,"\x01\x00\x0c\xcc\xcc\xcc",6)) |
| 2087 |
return(TRUE); |
| 2088 |
|
| 2089 |
return(FALSE); |
| 2090 |
} |
| 2091 |
|
| 2092 |
/* Handle a received packet */ |
| 2093 |
static int bcm5600_handle_rx_pkt(struct nm_16esw_data *d,struct bcm5600_pkt *p) |
| 2094 |
{ |
| 2095 |
m_uint32_t *port_entry; |
| 2096 |
n_eth_dot1q_hdr_t *eth_hdr; |
| 2097 |
u_int discard; |
| 2098 |
|
| 2099 |
/* No egress port at this time */ |
| 2100 |
p->egress_bitmap = 0; |
| 2101 |
|
| 2102 |
/* Never send back frames to the source port */ |
| 2103 |
p->egress_filter_bitmap = 1 << p->ingress_port; |
| 2104 |
|
| 2105 |
if (!(port_entry = bcm5600_table_get_entry(d,d->t_ptable,p->ingress_port))) |
| 2106 |
return(FALSE); |
| 2107 |
|
| 2108 |
/* Analyze the Ethernet header */ |
| 2109 |
eth_hdr = (n_eth_dot1q_hdr_t *)p->pkt; |
| 2110 |
|
| 2111 |
/* Determine VLAN */ |
| 2112 |
if (ntohs(eth_hdr->type) != N_ETH_PROTO_DOT1Q) { |
| 2113 |
p->orig_vlan = -1; |
| 2114 |
p->real_vlan = port_entry[0] & BCM5600_PTABLE_VLAN_TAG_MASK; |
| 2115 |
|
| 2116 |
/* TODO: 802.1p/CoS remarking */ |
| 2117 |
if (port_entry[4] & BCM5600_PTABLE_RPE_FLAG) { |
| 2118 |
} |
| 2119 |
} else { |
| 2120 |
p->orig_vlan = p->real_vlan = ntohs(eth_hdr->vlan_id) & 0xFFF; |
| 2121 |
} |
| 2122 |
|
| 2123 |
/* Check that this VLAN exists */ |
| 2124 |
if (!(p->vlan_entry = bcm5600_vtable_get_entry_by_vlan(d,p->real_vlan))) |
| 2125 |
return(FALSE); |
| 2126 |
|
| 2127 |
/* Check for the reserved addresses (BPDU for spanning-tree) */ |
| 2128 |
if (bcm5600_is_bpdu(ð_hdr->daddr)) { |
| 2129 |
#if DEBUG_RECEIVE |
| 2130 |
BCM_LOG(d,"Received a BPDU packet:\n"); |
| 2131 |
mem_dump(d->vm->log_fd,p->pkt,p->pkt_len); |
| 2132 |
#endif |
| 2133 |
p->egress_bitmap |= 1 << d->cpu_port; |
| 2134 |
return(bcm5600_forward_pkt(d,p)); |
| 2135 |
} |
| 2136 |
|
| 2137 |
/* Check that this port is a member of this VLAN */ |
| 2138 |
if (!(p->vlan_entry[1] & (1 << p->ingress_port))) |
| 2139 |
return(FALSE); |
| 2140 |
|
| 2141 |
/* Discard packet ? */ |
| 2142 |
discard = port_entry[0] & BCM5600_PTABLE_PRT_DIS_MASK; |
| 2143 |
discard >>= BCM5600_PTABLE_PRT_DIS_SHIFT; |
| 2144 |
|
| 2145 |
if ((p->orig_vlan == -1) && discard) { |
| 2146 |
if (discard != 0x20) { |
| 2147 |
printf("\n\n\n" |
| 2148 |
"-----------------------------------------------------------" |
| 2149 |
"---------------------------------\n" |
| 2150 |
"Unspported feature: please post your current configuration " |
| 2151 |
"on http://www.ipflow.utc.fr/blog/\n" |
| 2152 |
"-----------------------------------------------------------" |
| 2153 |
"---------------------------------\n"); |
| 2154 |
} |
| 2155 |
|
| 2156 |
/* Drop the packet */ |
| 2157 |
return(FALSE); |
| 2158 |
} |
| 2159 |
|
| 2160 |
/* Mirroring on Ingress ? */ |
| 2161 |
if (port_entry[1] & BCM5600_PTABLE_MI_FLAG) |
| 2162 |
bcm5600_mirror_pkt(d,p,0); |
| 2163 |
|
| 2164 |
#if DEBUG_RECEIVE |
| 2165 |
BCM_LOG(d,"%s: received a packet on VLAN %u\n", |
| 2166 |
d->ports[p->ingress_port].name,p->real_vlan); |
| 2167 |
#endif |
| 2168 |
|
| 2169 |
/* Source MAC address learning */ |
| 2170 |
bcm5600_src_mac_learning(d,p); |
| 2171 |
|
| 2172 |
/* Take forwarding decision based on destination MAC address */ |
| 2173 |
if (!bcm5600_dst_mac_lookup(d,p)) |
| 2174 |
return(FALSE); |
| 2175 |
|
| 2176 |
/* Send the packet to the egress ports */ |
| 2177 |
return(bcm5600_forward_pkt(d,p)); |
| 2178 |
} |
| 2179 |
|
| 2180 |
/* Handle a packet to transmit */ |
| 2181 |
static int bcm5600_handle_tx_pkt(struct nm_16esw_data *d, |
| 2182 |
struct bcm5600_pkt *p, |
| 2183 |
u_int egress_bitmap) |
| 2184 |
{ |
| 2185 |
n_eth_dot1q_hdr_t *eth_hdr; |
| 2186 |
|
| 2187 |
/* Never send back frames to the source port */ |
| 2188 |
p->egress_filter_bitmap = 1 << p->ingress_port; |
| 2189 |
|
| 2190 |
/* We take the complete forwarding decision if bit 23 is set */ |
| 2191 |
if (egress_bitmap & (1 << 23)) { |
| 2192 |
/* No egress port at this time */ |
| 2193 |
p->egress_bitmap = 0; |
| 2194 |
|
| 2195 |
/* The packet must be tagged so that we can determine the VLAN */ |
| 2196 |
eth_hdr = (n_eth_dot1q_hdr_t *)p->pkt; |
| 2197 |
|
| 2198 |
if (ntohs(eth_hdr->type) != N_ETH_PROTO_DOT1Q) { |
| 2199 |
BCM_LOG(d,"bcm5600_handle_tx_pkt: untagged packet ?\n"); |
| 2200 |
return(FALSE); |
| 2201 |
} |
| 2202 |
|
| 2203 |
/* Find the appropriate, check it exists (just in case) */ |
| 2204 |
p->orig_vlan = p->real_vlan = ntohs(eth_hdr->vlan_id) & 0xFFF; |
| 2205 |
|
| 2206 |
if (!(p->vlan_entry = bcm5600_vtable_get_entry_by_vlan(d,p->real_vlan))) |
| 2207 |
return(FALSE); |
| 2208 |
|
| 2209 |
#if DEBUG_TRANSMIT |
| 2210 |
BCM_LOG(d,"Transmitting a packet from TX ring to VLAN %u\n", |
| 2211 |
p->real_vlan); |
| 2212 |
#endif |
| 2213 |
|
| 2214 |
/* Take forwarding decision based on destination MAC address */ |
| 2215 |
if (!bcm5600_dst_mac_lookup(d,p)) |
| 2216 |
return(FALSE); |
| 2217 |
} else { |
| 2218 |
#if DEBUG_TRANSMIT |
| 2219 |
BCM_LOG(d,"Transmitting natively a packet from TX ring.\n"); |
| 2220 |
#endif |
| 2221 |
/* The egress ports are specified, send the packet natively */ |
| 2222 |
p->orig_vlan = 0; |
| 2223 |
p->egress_bitmap = egress_bitmap; |
| 2224 |
} |
| 2225 |
|
| 2226 |
/* Send the packet to the egress ports */ |
| 2227 |
return(bcm5600_forward_pkt(d,p)); |
| 2228 |
} |
| 2229 |
|
| 2230 |
/* Handle the TX ring */ |
| 2231 |
static int dev_bcm5600_handle_txring(struct nm_16esw_data *d) |
| 2232 |
{ |
| 2233 |
struct bcm5600_pkt pkt_data; |
| 2234 |
m_uint32_t tdes[4],txd_len; |
| 2235 |
|
| 2236 |
BCM_LOCK(d); |
| 2237 |
|
| 2238 |
if (!d->tx_current || d->tx_end_scan) { |
| 2239 |
BCM_UNLOCK(d); |
| 2240 |
return(FALSE); |
| 2241 |
} |
| 2242 |
|
| 2243 |
/* Read the current TX descriptor */ |
| 2244 |
physmem_copy_from_vm(d->vm,tdes,d->tx_current,4*sizeof(m_uint32_t)); |
| 2245 |
tdes[0] = vmtoh32(tdes[0]); |
| 2246 |
tdes[1] = vmtoh32(tdes[1]); |
| 2247 |
tdes[2] = vmtoh32(tdes[2]); |
| 2248 |
tdes[3] = vmtoh32(tdes[3]); |
| 2249 |
|
| 2250 |
#if DEBUG_TRANSMIT |
| 2251 |
BCM_LOG(d,"=== TRANSMIT PATH ===\n"); |
| 2252 |
|
| 2253 |
BCM_LOG(d,"tx_current=0x%8.8x, " |
| 2254 |
"tdes[0]=0x%8.8x, tdes[1]=0x%8.8x, tdes[2]=0x%8.8x\n", |
| 2255 |
d->tx_current,tdes[0],tdes[1],tdes[2]); |
| 2256 |
#endif |
| 2257 |
|
| 2258 |
/* Get the buffer size */ |
| 2259 |
txd_len = tdes[1] & 0x7FF; |
| 2260 |
|
| 2261 |
/* Check buffer size */ |
| 2262 |
if ((d->tx_bufsize + txd_len) >= sizeof(d->tx_buffer)) |
| 2263 |
goto done; |
| 2264 |
|
| 2265 |
/* Copy the packet from memory */ |
| 2266 |
physmem_copy_from_vm(d->vm,d->tx_buffer+d->tx_bufsize,tdes[0],txd_len); |
| 2267 |
d->tx_bufsize += txd_len; |
| 2268 |
|
| 2269 |
/* Packet not complete: handle it later */ |
| 2270 |
if (tdes[1] & BCM5600_TXD_NEOP) |
| 2271 |
goto done; |
| 2272 |
|
| 2273 |
#if DEBUG_TRANSMIT |
| 2274 |
mem_dump(d->vm->log_fd,d->tx_buffer,d->tx_bufsize); |
| 2275 |
#endif |
| 2276 |
|
| 2277 |
/* Transmit the packet */ |
| 2278 |
pkt_data.ingress_port = d->cpu_port; |
| 2279 |
pkt_data.pkt = d->tx_buffer; |
| 2280 |
pkt_data.pkt_len = d->tx_bufsize - 4; |
| 2281 |
pkt_data.sent_to_cpu = TRUE; |
| 2282 |
bcm5600_handle_tx_pkt(d,&pkt_data,tdes[2]); |
| 2283 |
|
| 2284 |
/* Reset the TX buffer (packet fully transmitted) */ |
| 2285 |
d->tx_bufsize = 0; |
| 2286 |
|
| 2287 |
done: |
| 2288 |
/* We have reached end of ring: trigger the TX underrun interrupt */ |
| 2289 |
if (!(tdes[1] & BCM5600_TXD_RING_CONT)) { |
| 2290 |
d->tx_end_scan = 1; |
| 2291 |
pci_dev_trigger_irq(d->vm,d->pci_dev); |
| 2292 |
BCM_UNLOCK(d); |
| 2293 |
return(TRUE); |
| 2294 |
} |
| 2295 |
|
| 2296 |
/* Go to the next descriptor */ |
| 2297 |
d->tx_current += BCM5600_TXD_SIZE; |
| 2298 |
BCM_UNLOCK(d); |
| 2299 |
return(TRUE); |
| 2300 |
} |
| 2301 |
|
| 2302 |
/* Handle the RX ring */ |
| 2303 |
static int dev_bcm5600_handle_rxring(netio_desc_t *nio, |
| 2304 |
u_char *pkt,ssize_t pkt_len, |
| 2305 |
struct nm_16esw_data *d, |
| 2306 |
struct bcm5600_port *port) |
| 2307 |
{ |
| 2308 |
struct bcm5600_pkt pkt_data; |
| 2309 |
m_uint32_t rxd_len; |
| 2310 |
|
| 2311 |
#if DEBUG_RECEIVE |
| 2312 |
BCM_LOG(d,"=== RECEIVE PATH ===\n"); |
| 2313 |
|
| 2314 |
BCM_LOG(d,"%s: received a packet of %ld bytes.\n", |
| 2315 |
port->name,(u_long)pkt_len); |
| 2316 |
mem_dump(d->vm->log_fd,pkt,pkt_len); |
| 2317 |
#endif |
| 2318 |
|
| 2319 |
BCM_LOCK(d); |
| 2320 |
|
| 2321 |
if (!d->rx_current || d->rx_end_scan) { |
| 2322 |
BCM_UNLOCK(d); |
| 2323 |
return(FALSE); |
| 2324 |
} |
| 2325 |
|
| 2326 |
/* Read the current TX descriptor */ |
| 2327 |
physmem_copy_from_vm(d->vm,pkt_data.rdes,d->rx_current, |
| 2328 |
(4 * sizeof(m_uint32_t))); |
| 2329 |
|
| 2330 |
pkt_data.rdes[0] = vmtoh32(pkt_data.rdes[0]); |
| 2331 |
pkt_data.rdes[1] = vmtoh32(pkt_data.rdes[1]); |
| 2332 |
pkt_data.rdes[2] = vmtoh32(pkt_data.rdes[2]); |
| 2333 |
pkt_data.rdes[3] = vmtoh32(pkt_data.rdes[3]); |
| 2334 |
|
| 2335 |
#if DEBUG_RECEIVE |
| 2336 |
BCM_LOG(d,"rx_current=0x%8.8x, " |
| 2337 |
"rdes[0]=0x%8.8x, rdes[1]=0x%8.8x, rdes[2]=0x%8.8x\n", |
| 2338 |
d->rx_current,pkt_data.rdes[0],pkt_data.rdes[1],pkt_data.rdes[2]); |
| 2339 |
#endif |
| 2340 |
|
| 2341 |
/* Get the buffer size */ |
| 2342 |
rxd_len = pkt_data.rdes[1] & 0x7FF; |
| 2343 |
|
| 2344 |
if (pkt_len > rxd_len) { |
| 2345 |
BCM_UNLOCK(d); |
| 2346 |
return(FALSE); |
| 2347 |
} |
| 2348 |
|
| 2349 |
/* Fill the packet info */ |
| 2350 |
pkt_data.ingress_port = port->id; |
| 2351 |
pkt_data.pkt = pkt; |
| 2352 |
pkt_data.pkt_len = pkt_len; |
| 2353 |
pkt_data.sent_to_cpu = FALSE; |
| 2354 |
|
| 2355 |
/* Handle the packet */ |
| 2356 |
bcm5600_handle_rx_pkt(d,&pkt_data); |
| 2357 |
|
| 2358 |
/* Signal only an interrupt when a packet has been sent to the CPU */ |
| 2359 |
if (pkt_data.sent_to_cpu) { |
| 2360 |
/* We have reached end of ring: trigger the RX underrun interrupt */ |
| 2361 |
if (!(pkt_data.rdes[1] & BCM5600_RXD_RING_CONT)) { |
| 2362 |
d->rx_end_scan = 1; |
| 2363 |
pci_dev_trigger_irq(d->vm,d->pci_dev); |
| 2364 |
BCM_UNLOCK(d); |
| 2365 |
return(TRUE); |
| 2366 |
} |
| 2367 |
|
| 2368 |
/* A packet was received */ |
| 2369 |
pci_dev_trigger_irq(d->vm,d->pci_dev); |
| 2370 |
|
| 2371 |
/* Go to the next descriptor */ |
| 2372 |
d->rx_current += BCM5600_RXD_SIZE; |
| 2373 |
} |
| 2374 |
|
| 2375 |
BCM_UNLOCK(d); |
| 2376 |
return(TRUE); |
| 2377 |
} |
| 2378 |
|
| 2379 |
/* pci_bcm5605_read() */ |
| 2380 |
static m_uint32_t pci_bcm5605_read(cpu_gen_t *cpu,struct pci_device *dev, |
| 2381 |
int reg) |
| 2382 |
{ |
| 2383 |
struct nm_16esw_data *d = dev->priv_data; |
| 2384 |
|
| 2385 |
switch(reg) { |
| 2386 |
case PCI_REG_BAR0: |
| 2387 |
return(d->dev->phys_addr); |
| 2388 |
default: |
| 2389 |
return(0); |
| 2390 |
} |
| 2391 |
} |
| 2392 |
|
| 2393 |
/* pci_bcm5605_write() */ |
| 2394 |
static void pci_bcm5605_write(cpu_gen_t *cpu,struct pci_device *dev, |
| 2395 |
int reg,m_uint32_t value) |
| 2396 |
{ |
| 2397 |
struct nm_16esw_data *d = dev->priv_data; |
| 2398 |
|
| 2399 |
switch(reg) { |
| 2400 |
case PCI_REG_BAR0: |
| 2401 |
vm_map_device(cpu->vm,d->dev,(m_uint64_t)value); |
| 2402 |
BCM_LOG(d,"BCM5600 registers are mapped at 0x%x\n",value); |
| 2403 |
break; |
| 2404 |
} |
| 2405 |
} |
| 2406 |
|
| 2407 |
/* Rewrite the base MAC address */ |
| 2408 |
int dev_nm_16esw_burn_mac_addr(vm_instance_t *vm,u_int nm_bay, |
| 2409 |
struct cisco_eeprom *eeprom) |
| 2410 |
{ |
| 2411 |
m_uint8_t eeprom_ver; |
| 2412 |
size_t offset; |
| 2413 |
n_eth_addr_t addr; |
| 2414 |
m_uint16_t pid; |
| 2415 |
|
| 2416 |
pid = (m_uint16_t)getpid(); |
| 2417 |
|
| 2418 |
/* Generate automatically the MAC address */ |
| 2419 |
addr.eth_addr_byte[0] = vm_get_mac_addr_msb(vm); |
| 2420 |
addr.eth_addr_byte[1] = vm->instance_id & 0xFF; |
| 2421 |
addr.eth_addr_byte[2] = pid >> 8; |
| 2422 |
addr.eth_addr_byte[3] = pid & 0xFF; |
| 2423 |
addr.eth_addr_byte[4] = 0xF0 + nm_bay; |
| 2424 |
addr.eth_addr_byte[5] = 0x00; |
| 2425 |
|
| 2426 |
/* Read EEPROM format version */ |
| 2427 |
cisco_eeprom_get_byte(eeprom,0,&eeprom_ver); |
| 2428 |
|
| 2429 |
if (eeprom_ver != 4) |
| 2430 |
return(-1); |
| 2431 |
|
| 2432 |
if (cisco_eeprom_v4_find_field(eeprom,0xCF,&offset) == -1) |
| 2433 |
return(-1); |
| 2434 |
|
| 2435 |
cisco_eeprom_set_region(eeprom,offset,addr.eth_addr_byte,6); |
| 2436 |
return(0); |
| 2437 |
} |
| 2438 |
|
| 2439 |
/* Initialize a NM-16ESW module */ |
| 2440 |
struct nm_16esw_data * |
| 2441 |
dev_nm_16esw_init(vm_instance_t *vm,char *name,u_int nm_bay, |
| 2442 |
struct pci_bus *pci_bus,int pci_device,int irq) |
| 2443 |
{ |
| 2444 |
struct nm_16esw_data *data; |
| 2445 |
struct bcm5600_port *port; |
| 2446 |
struct vdevice *dev; |
| 2447 |
int i,port_id; |
| 2448 |
|
| 2449 |
/* Allocate the private data structure */ |
| 2450 |
if (!(data = malloc(sizeof(*data)))) { |
| 2451 |
fprintf(stderr,"%s: out of memory\n",name); |
| 2452 |
return NULL; |
| 2453 |
} |
| 2454 |
|
| 2455 |
memset(data,0,sizeof(*data)); |
| 2456 |
pthread_mutex_init(&data->lock,NULL); |
| 2457 |
data->name = name; |
| 2458 |
data->nr_port = 16; |
| 2459 |
data->vm = vm; |
| 2460 |
|
| 2461 |
/* Create the BCM5600 tables */ |
| 2462 |
if (bcm5600_table_create(data) == -1) |
| 2463 |
return NULL; |
| 2464 |
|
| 2465 |
/* Clear the various tables */ |
| 2466 |
bcm5600_reset_arl(data); |
| 2467 |
data->arl_cnt[0] = 1; |
| 2468 |
data->t_ptable = bcm5600_table_find(data,BCM5600_ADDR_PTABLE0); |
| 2469 |
data->t_vtable = bcm5600_table_find(data,BCM5600_ADDR_VTABLE0); |
| 2470 |
data->t_arl = bcm5600_table_find(data,BCM5600_ADDR_ARL0); |
| 2471 |
data->t_marl = bcm5600_table_find(data,BCM5600_ADDR_MARL0); |
| 2472 |
data->t_tbmap = bcm5600_table_find(data,BCM5600_ADDR_TBMAP0); |
| 2473 |
data->t_ttr = bcm5600_table_find(data,BCM5600_ADDR_TTR0); |
| 2474 |
|
| 2475 |
/* Initialize ports */ |
| 2476 |
data->cpu_port = 27; |
| 2477 |
|
| 2478 |
for(i=0;i<data->nr_port;i++) { |
| 2479 |
port_id = nm16esw_port_mapping[i]; |
| 2480 |
|
| 2481 |
port = &data->ports[port_id]; |
| 2482 |
port->id = port_id; |
| 2483 |
snprintf(port->name,sizeof(port->name),"Fa%u/%d",nm_bay,i); |
| 2484 |
} |
| 2485 |
|
| 2486 |
/* Create the BCM5605 PCI device */ |
| 2487 |
data->pci_dev = pci_dev_add(pci_bus,name, |
| 2488 |
BCM5605_PCI_VENDOR_ID,BCM5605_PCI_PRODUCT_ID, |
| 2489 |
pci_device,0,irq,data, |
| 2490 |
NULL,pci_bcm5605_read,pci_bcm5605_write); |
| 2491 |
|
| 2492 |
if (!data->pci_dev) { |
| 2493 |
fprintf(stderr,"%s: unable to create PCI device.\n",name); |
| 2494 |
return NULL; |
| 2495 |
} |
| 2496 |
|
| 2497 |
/* Create the BCM5605 device itself */ |
| 2498 |
if (!(dev = dev_create(name))) { |
| 2499 |
fprintf(stderr,"%s: unable to create device.\n",name); |
| 2500 |
return NULL; |
| 2501 |
} |
| 2502 |
|
| 2503 |
dev->phys_addr = 0; |
| 2504 |
dev->phys_len = 0x200000; |
| 2505 |
dev->handler = dev_bcm5605_access; |
| 2506 |
|
| 2507 |
/* Store device info */ |
| 2508 |
dev->priv_data = data; |
| 2509 |
data->dev = dev; |
| 2510 |
|
| 2511 |
/* Create the TX ring scanner */ |
| 2512 |
data->tx_tid = ptask_add((ptask_callback)dev_bcm5600_handle_txring, |
| 2513 |
data,NULL); |
| 2514 |
|
| 2515 |
/* Start the MAC address ager */ |
| 2516 |
data->ager_tid = timer_create_entry(15000,FALSE,10, |
| 2517 |
(timer_proc)bcm5600_arl_ager,data); |
| 2518 |
return data; |
| 2519 |
} |
| 2520 |
|
| 2521 |
/* Remove a NM-16ESW from the specified slot */ |
| 2522 |
int dev_nm_16esw_remove(struct nm_16esw_data *data) |
| 2523 |
{ |
| 2524 |
/* Stop the Ager */ |
| 2525 |
timer_remove(data->ager_tid); |
| 2526 |
|
| 2527 |
/* Stop the TX ring task */ |
| 2528 |
ptask_remove(data->tx_tid); |
| 2529 |
|
| 2530 |
/* Remove device + PCI stuff */ |
| 2531 |
pci_dev_remove(data->pci_dev); |
| 2532 |
vm_unbind_device(data->vm,data->dev); |
| 2533 |
cpu_group_rebuild_mts(data->vm->cpu_group); |
| 2534 |
free(data->dev); |
| 2535 |
|
| 2536 |
/* Free all tables and registers */ |
| 2537 |
bcm5600_table_free(data); |
| 2538 |
bcm5600_reg_free(data); |
| 2539 |
free(data); |
| 2540 |
return(0); |
| 2541 |
} |
| 2542 |
|
| 2543 |
/* Bind a Network IO descriptor */ |
| 2544 |
int dev_nm_16esw_set_nio(struct nm_16esw_data *d,u_int port_id, |
| 2545 |
netio_desc_t *nio) |
| 2546 |
{ |
| 2547 |
struct bcm5600_port *port; |
| 2548 |
|
| 2549 |
if (!d || (port_id >= d->nr_port)) |
| 2550 |
return(-1); |
| 2551 |
|
| 2552 |
/* define the new NIO */ |
| 2553 |
port = &d->ports[nm16esw_port_mapping[port_id]]; |
| 2554 |
port->nio = nio; |
| 2555 |
netio_rxl_add(nio,(netio_rx_handler_t)dev_bcm5600_handle_rxring,d,port); |
| 2556 |
return(0); |
| 2557 |
} |
| 2558 |
|
| 2559 |
/* Unbind a Network IO descriptor */ |
| 2560 |
int dev_nm_16esw_unset_nio(struct nm_16esw_data *d,u_int port_id) |
| 2561 |
{ |
| 2562 |
struct bcm5600_port *port; |
| 2563 |
|
| 2564 |
if (!d || (port_id >= d->nr_port)) |
| 2565 |
return(-1); |
| 2566 |
|
| 2567 |
port = &d->ports[nm16esw_port_mapping[port_id]]; |
| 2568 |
|
| 2569 |
if (port->nio) { |
| 2570 |
netio_rxl_remove(port->nio); |
| 2571 |
port->nio = NULL; |
| 2572 |
} |
| 2573 |
|
| 2574 |
return(0); |
| 2575 |
} |
| 2576 |
|
| 2577 |
/* Show debugging information */ |
| 2578 |
int dev_nm_16esw_show_info(struct nm_16esw_data *d) |
| 2579 |
{ |
| 2580 |
BCM_LOCK(d); |
| 2581 |
printf("ARL count = %u\n\n",d->arl_cnt[0]); |
| 2582 |
bcm5600_dump_main_tables(d); |
| 2583 |
bcm5600_mirror_show_status(d); |
| 2584 |
bcm5600_reg_dump(d,FALSE); |
| 2585 |
BCM_UNLOCK(d); |
| 2586 |
return(0); |
| 2587 |
} |