1 /*
2  * Cisco 2691 simulation platform.
3  * Copyright (c) 2006 Christophe Fillot (cf@utc.fr)
4  *
5  * Generic Cisco 2691 routines and definitions (EEPROM,...).
6  */
7 
8 #ifndef __DEV_C2691_H__
9 #define __DEV_C2691_H__
10 
11 #include <pthread.h>
12 
13 #include "utils.h"
14 #include "net.h"
15 #include "device.h"
16 #include "pci_dev.h"
17 #include "nmc93cX6.h"
18 #include "net_io.h"
19 #include "vm.h"
20 
21 /* Default C2691 parameters */
22 #define C2691_DEFAULT_RAM_SIZE     128
23 #define C2691_DEFAULT_ROM_SIZE     2
24 #define C2691_DEFAULT_NVRAM_SIZE   112
25 #define C2691_DEFAULT_CONF_REG     0x2102
26 #define C2691_DEFAULT_CLOCK_DIV    8
27 #define C2691_DEFAULT_RAM_MMAP     1
28 #define C2691_DEFAULT_DISK0_SIZE   16
29 #define C2691_DEFAULT_DISK1_SIZE   0
30 #define C2691_DEFAULT_IOMEM_SIZE   5   /* Percents! */
31 
32 /* 2691 characteritics: 1 NM, 3 WIC, 2 AIM */
33 #define C2691_MAX_NM_BAYS   2
34 #define C2691_MAX_WIC_BAYS  3
35 
36 /* C2691 DUART Interrupt */
37 #define C2691_DUART_IRQ  5
38 
39 /* C2691 Network I/O Interrupt */
40 #define C2691_NETIO_IRQ  2
41 
42 /* C2691 GT64k DMA/Timer Interrupt */
43 #define C2691_GT96K_IRQ  3
44 
45 /* C2691 External Interrupt */
46 #define C2691_EXT_IRQ    6
47 
48 /* Network IRQ */
49 #define C2691_NETIO_IRQ_BASE       32
50 #define C2691_NETIO_IRQ_PORT_BITS  3
51 #define C2691_NETIO_IRQ_PORT_MASK  ((1 << C2691_NETIO_IRQ_PORT_BITS) - 1)
52 #define C2691_NETIO_IRQ_PER_SLOT   (1 << C2691_NETIO_IRQ_PORT_BITS)
53 #define C2691_NETIO_IRQ_END        \
54   (C2691_NETIO_IRQ_BASE + (C2691_MAX_NM_BAYS * C2691_NETIO_IRQ_PER_SLOT) - 1)
55 
56 /* C2691 common device addresses */
57 #define C2691_GT96K_ADDR      0x14000000ULL
58 #define C2691_IOFPGA_ADDR     0x1e800000ULL
59 #define C2691_BITBUCKET_ADDR  0x1ec00000ULL
60 #define C2691_ROM_ADDR        0x1fc00000ULL
61 #define C2691_SLOT0_ADDR      0x30000000ULL
62 #define C2691_SLOT1_ADDR      0x32000000ULL
63 #define C2691_DUART_ADDR      0x3c100000ULL
64 #define C2691_WIC_ADDR        0x3c200000ULL
65 #define C2691_BSWAP_ADDR      0xc0000000ULL
66 #define C2691_PCI_IO_ADDR     0x100000000ULL
67 
68 /* WIC interval in address space */
69 #define C2691_WIC_SIZE  0x2000
70 
71 /* Offset of simulated NVRAM in ROM flash */
72 #define C2691_NVRAM_OFFSET    0xE0000
73 #define C2691_NVRAM_SIZE      0x1C000 // with backup
74 
75 /* Reserved space for ROM in NVRAM */
76 #define C2691_NVRAM_ROM_RES_SIZE  0
77 
78 /* C2691 ELF Platform ID */
79 #define C2691_ELF_MACHINE_ID  0x66
80 
81 #define VM_C2691(vm) ((c2691_t *)vm->hw_data)
82 
83 /* C2691 router */
84 typedef struct c2691_router c2691_t;
85 
86 /* C2691 router */
87 struct c2691_router {
88    /* Chassis MAC address */
89    n_eth_addr_t mac_addr;
90 
91    char board_id[20];
92 
93    /* Associated VM instance */
94    vm_instance_t *vm;
95 
96    /* GT96100 data */
97    struct gt_data *gt_data;
98 
99    /* I/O FPGA */
100    struct c2691_iofpga_data *iofpga_data;
101 
102    /* Chassis information */
103    m_uint8_t oir_status;
104 
105    /*
106     * Mainboard EEPROM.
107     * It can be modified to change the chassis MAC address.
108     */
109    struct cisco_eeprom mb_eeprom;
110    struct nmc93cX6_group mb_eeprom_group;
111 
112    /* Network Module EEPROM */
113    struct nmc93cX6_group nm_eeprom_group;
114 };
115 
116 /* Get WIC device address for the specified onboard port */
117 int c2691_get_onboard_wic_addr(u_int slot,m_uint64_t *phys_addr);
118 
119 /* Set EEPROM for the specified slot */
120 int c2691_set_slot_eeprom(c2691_t *router,u_int slot,
121                           struct cisco_eeprom *eeprom);
122 
123 /* Get network IRQ for specified slot/port */
124 u_int c2691_net_irq_for_slot_port(u_int slot,u_int port);
125 
126 /* Set chassis MAC address */
127 int c2691_chassis_set_mac_addr(c2691_t *router,char *mac_addr);
128 
129 /* Set the system id */
130 int c2691_set_system_id(c2691_t *router,char *id);
131 
132 /* Burn the system id into the appropriate eeprom if possible */
133 int c2691_refresh_systemid(c2691_t *router);
134 
135 /* Show C2691 hardware info */
136 void c2691_show_hardware(c2691_t *router);
137 
138 /* Initialize EEPROM groups */
139 void c2691_init_eeprom_groups(c2691_t *router);
140 
141 /* dev_c2691_iofpga_init() */
142 int dev_c2691_iofpga_init(c2691_t *router,m_uint64_t paddr,m_uint32_t len);
143 
144 /* Register the c2691 platform */
145 int c2691_platform_register(void);
146 
147 /* Hypervisor C2691 initialization */
148 extern int hypervisor_c2691_init(vm_platform_t *platform);
149 
150 /* NM drivers */
151 extern struct cisco_card_driver dev_c2691_nm_1fe_tx_driver;
152 extern struct cisco_card_driver dev_c2691_gt96100_fe_driver;
153 extern struct cisco_card_driver dev_c2691_nm_4t_driver;
154 extern struct cisco_card_driver dev_c2691_nm_16esw_driver;
155 extern struct cisco_card_driver dev_c2691_nm_nam_driver;
156 extern struct cisco_card_driver dev_c2691_nm_cids_driver;
157 
158 /* WIC drivers */
159 extern struct cisco_card_driver *dev_c2691_mb_wic_drivers[];
160 
161 #endif
162