1/*
2 * RoboSwitch setup functions
3 *
4 * Copyright (C) 2013, Broadcom Corporation. All Rights Reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 * $Id: bcmrobo.h 393340 2013-03-27 06:10:49Z $
19 */
20
21#ifndef _bcm_robo_h_
22#define _bcm_robo_h_
23
24#define	DEVID5325	0x25	/* 5325 (Not really but we fake it) */
25#define	DEVID5395	0x95	/* 5395 */
26#define	DEVID5397	0x97	/* 5397 */
27#define	DEVID5398	0x98	/* 5398 */
28#define	DEVID53115	0x3115	/* 53115 */
29#define	DEVID53125	0x3125	/* 53125 */
30
31/*
32 * MODELID:
33 * 0x53010: BCM4707, Select Low SKU device if SKU ID[1:0] = 01.
34 * 0x53011: BCM4708, Select Middle SKU device if SKU ID[1:0] = 10.
35 * 0x53012: BCM4709, Select High SKU device if SKU ID[1:0] = 00.
36 * Note: The SKU ID[1:0] is loaded from OTP configuration data.
37 */
38#define DEVID53010	0x53010	/* 53010 */
39#define DEVID53011	0x53011	/* 53011 */
40#define DEVID53012	0x53012	/* 53012 */
41#define DEVID53018	0x53018	/* 53018 */
42#define DEVID53019	0x53019	/* 53019 */
43#define ROBO_IS_BCM5301X(id) ((id) == DEVID53010 || (id) == DEVID53011 || (id) == DEVID53012 || \
44(id) == DEVID53018 || (id) == DEVID53019)
45/* foxconn added start, zacker, 10/15/2010 */
46#define LAN_VLAN_ENTRY_IDX          (1)//LAN is VLAN ID 1
47#define WAN_VLAN_ENTRY_IDX          (2)//WAN is VLAN ID 2
48#define IPTV_VLAN_ENTRY_IDX         (3)//IPTV is VLAN ID 3
49#define LAN_VLAN_ENTRY_IDX_VAL      (0x30 + LAN_VLAN_ENTRY_IDX)//'1'
50#define WAN_VLAN_ENTRY_IDX_VAL      (0x30 + WAN_VLAN_ENTRY_IDX)//'2'
51#define IPTV_VLAN_ENTRY_IDX_VAL     (0x30 + IPTV_VLAN_ENTRY_IDX)//'3'
52#define ROBO_LAN_PORTMAP            (0x0F)
53#define ROBO_WAN_PORTMAP            (0x10)
54#define ROBO_LAN_PORT_IDX_START     (0)
55#define ROBO_LAN_PORT_IDX_END       (3)
56#define ROBO_WAN_PORT               (4)
57#define ROBO_INVALID_PORT_SPEED     (0x03)
58#define ROBO_PORT_TO_LABEL_PORT(a)  ((a) + 1)
59#define LABEL_PORT_TO_ROBO_PORT(a)  ((a) - 1) /* foxconn added, zacker, 12/13/2011 */
60/* foxconn added end, zacker, 10/15/2010 */
61
62/* Power save duty cycle times */
63#define MAX_NO_PHYS		5
64#define PWRSAVE_SLEEP_TIME	12
65#define PWRSAVE_WAKE_TIME	3
66
67/* Power save modes for the switch */
68#define ROBO_PWRSAVE_NORMAL 		0
69#define ROBO_PWRSAVE_AUTO		1
70#define ROBO_PWRSAVE_MANUAL		2
71#define ROBO_PWRSAVE_AUTO_MANUAL 	3
72
73#define ROBO_IS_PWRSAVE_MANUAL(r) ((r)->pwrsave_mode_manual)
74#define ROBO_IS_PWRSAVE_AUTO(r) ((r)->pwrsave_mode_auto)
75
76/* SRAB interface */
77/* Access switch registers through SRAB (Switch Register Access Bridge) */
78#define REG_VERSION_ID		0x40
79#define REG_CTRL_PORT0_GMIIPO	0x58	/* 53012: GMII Port0 Override register */
80#define REG_CTRL_PORT1_GMIIPO	0x59	/* 53012: GMII Port1 Override register */
81#define REG_CTRL_PORT2_GMIIPO	0x5a	/* 53012: GMII Port2 Override register */
82#define REG_CTRL_PORT3_GMIIPO	0x5b	/* 53012: GMII Port3 Override register */
83#define REG_CTRL_PORT4_GMIIPO	0x5c	/* 53012: GMII Port4 Override register */
84#define REG_CTRL_PORT5_GMIIPO	0x5d	/* 53012: GMII Port5 Override register */
85#define REG_CTRL_PORT7_GMIIPO	0x5f	/* 53012: GMII Port7 Override register */
86
87/* Command and status register of the SRAB */
88#define CFG_F_sra_rst_MASK		(1 << 2)
89#define CFG_F_sra_write_MASK		(1 << 1)
90#define CFG_F_sra_gordyn_MASK		(1 << 0)
91#define CFG_F_sra_page_R		24
92#define CFG_F_sra_offset_R		16
93
94/* Switch interface controls */
95#define CFG_F_sw_init_done_MASK		(1 << 6)
96#define CFG_F_rcareq_MASK		(1 << 3)
97#define CFG_F_rcagnt_MASK		(1 << 4)
98
99#ifndef PAD
100#define	_PADLINE(line)	pad ## line
101#define	_XSTR(line)	_PADLINE(line)
102#define	PAD		_XSTR(__LINE__)
103#endif	/* PAD */
104
105typedef volatile struct {
106	uint32	PAD[11];
107	uint32	cmdstat;	/* 0x2c, command and status register of the SRAB */
108	uint32	wd_h;		/* 0x30, high order word of write data to switch registe */
109	uint32	wd_l;		/* 0x34, low order word of write data to switch registe */
110	uint32	rd_h;		/* 0x38, high order word of read data from switch register */
111	uint32	rd_l;		/* 0x3c, low order word of read data from switch register */
112	uint32	ctrls;		/* 0x40, switch interface controls */
113	uint32	intr;		/* 0x44, the register captures interrupt pulses from the switch */
114} srabregs_t;
115
116/* Forward declaration */
117typedef struct robo_info_s robo_info_t;
118
119/* Device access/config oprands */
120typedef struct {
121	/* low level routines */
122	void (*enable_mgmtif)(robo_info_t *robo);	/* enable mgmt i/f, optional */
123	void (*disable_mgmtif)(robo_info_t *robo);	/* disable mgmt i/f, optional */
124	int (*write_reg)(robo_info_t *robo, uint8 page, uint8 reg, void *val, int len);
125	int (*read_reg)(robo_info_t *robo, uint8 page, uint8 reg, void *val, int len);
126	/* description */
127	char *desc;
128} dev_ops_t;
129
130
131typedef	uint16 (*miird_f)(void *h, int add, int off);
132typedef	void (*miiwr_f)(void *h, int add, int off, uint16 val);
133
134/* Private state per RoboSwitch */
135struct robo_info_s {
136	si_t	*sih;			/* SiliconBackplane handle */
137	char	*vars;			/* nvram variables handle */
138	void	*h;			/* dev handle */
139	uint32	devid;			/* Device id for the switch */
140	uint32	corerev;		/* Core rev of internal switch */
141
142	dev_ops_t *ops;			/* device ops */
143	uint8	page;			/* current page */
144
145	/* SPI */
146	uint32	ss, sck, mosi, miso;	/* GPIO mapping */
147
148	/* MII */
149	miird_f	miird;
150	miiwr_f	miiwr;
151
152	/* SRAB */
153	srabregs_t *srabregs;
154
155	uint16	prev_status;		/* link status of switch ports */
156	uint32	pwrsave_mode_manual; 	/* bitmap of ports in manual power save */
157	uint32	pwrsave_mode_auto; 	/* bitmap of ports in auto power save mode */
158	uint32	pwrsave_sleep_time;	/* sleep time for manual power save mode */
159	uint32	pwrsave_wake_time;	/* wakeup time for manual power save mode */
160	uint8	pwrsave_phys;		/* Phys that can be put into power save mode */
161	uint8	pwrsave_mode_phys[MAX_NO_PHYS];         /* Power save mode on the switch */
162	bool	eee_status;
163#ifdef PLC
164	/* PLC */
165	bool	plc_hw;			/* PLC chip */
166#endif /* PLC */
167};
168/* Foxconn add start by Lewis Min, 04/02/2008, for igmp snooping */
169#ifdef __CONFIG_IGMP_SNOOPING__
170struct igmp_snooping_table_s {
171	uint8   mh_mac[6];
172	uint16 port_mapping;
173};
174typedef struct igmp_snooping_table_s igmp_snooping_table_t;
175#endif
176/*Add end by foxconn lewis min for snooping function ,04/01/2008*/
177
178/* Power Save mode related functions */
179extern int32 robo_power_save_mode_get(robo_info_t *robo, int32 phy);
180extern int32 robo_power_save_mode_set(robo_info_t *robo, int32 mode, int32 phy);
181extern void robo_power_save_mode_update(robo_info_t *robo);
182extern int robo_power_save_mode(robo_info_t *robo, int mode, int phy);
183extern int robo_power_save_toggle(robo_info_t *robo, int normal);
184
185extern robo_info_t *bcm_robo_attach(si_t *sih, void *h, char *vars, miird_f miird, miiwr_f miiwr);
186extern void bcm_robo_detach(robo_info_t *robo);
187extern int bcm_robo_enable_device(robo_info_t *robo);
188extern int bcm_robo_config_vlan(robo_info_t *robo, uint8 *mac_addr);
189extern int bcm_robo_enable_switch(robo_info_t *robo);
190
191
192extern void robo_watchdog(robo_info_t *robo);
193extern void robo_eee_advertise_init(robo_info_t *robo);
194
195#ifdef PLC
196extern void robo_plc_hw_init(robo_info_t *robo);
197#endif /* PLC */
198extern void *get_robo_ptr(void);    /* Foxconn added pling 11/24/2010 */
199
200/* foxconn added start, zacker, 01/13/2012, @iptv_igmp */
201#if defined(CONFIG_RUSSIA_IPTV)
202extern void set_iptv_ports(robo_info_t *robo);
203extern uint16 get_iptv_ports(void);
204extern int is_iptv_port(int port);
205#endif
206/* foxconn added end, zacker, 01/13/2012, @iptv_igmp */
207#endif /* _bcm_robo_h_ */
208