1/*
2 * RoboSwitch setup functions
3 *
4 * Copyright (C) 2015, 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 523408 2014-12-30 05:46:51Z $
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 DEVID53030	0x53030	/* 53030 */
44#define ROBO_IS_BCM5301X(id) ((id) == DEVID53010 || (id) == DEVID53011 || (id) == DEVID53012 || \
45(id) == DEVID53018 || (id) == DEVID53019 || (id) == DEVID53030)
46/* foxconn added start, zacker, 10/15/2010 */
47#define LAN_VLAN_ENTRY_IDX          (1)//LAN is VLAN ID 1
48#define WAN_VLAN_ENTRY_IDX          (2)//WAN is VLAN ID 2
49#define IPTV_VLAN_ENTRY_IDX         (3)//IPTV is VLAN ID 3
50#define LAN_VLAN_ENTRY_IDX_VAL      (0x30 + LAN_VLAN_ENTRY_IDX)//'1'
51#define WAN_VLAN_ENTRY_IDX_VAL      (0x30 + WAN_VLAN_ENTRY_IDX)//'2'
52#define IPTV_VLAN_ENTRY_IDX_VAL     (0x30 + IPTV_VLAN_ENTRY_IDX)//'3'
53#if defined(R7000)
54#define ROBO_LAN_PORTMAP            (0x1E)
55#define ROBO_WAN_PORTMAP            (0x1)
56#define ROBO_LAN_PORT_IDX_START     (1)
57#define ROBO_LAN_PORT_IDX_END       (4)
58#define ROBO_WAN_PORT               (0)
59#else
60#define ROBO_LAN_PORTMAP            (0x0F)
61#define ROBO_WAN_PORTMAP            (0x10)
62#define ROBO_LAN_PORT_IDX_START     (0)
63#define ROBO_LAN_PORT_IDX_END       (3)
64#define ROBO_WAN_PORT               (4)
65
66#endif
67#define ROBO_INVALID_PORT_SPEED     (0x03)
68
69/*foxconn Han edited start, 05/17/2013 for R7000 don't have to do this*/
70#if (defined R7000)
71#define ROBO_PORT_TO_LABEL_PORT(a)  (5-(a))
72#define LABEL_PORT_TO_ROBO_PORT(a)  (5-(a))
73#else
74/*foxconn Han edited end, 05/17/2013 for R7000 don't have to do this*/
75#define ROBO_PORT_TO_LABEL_PORT(a)  ((a) + 1)
76#define LABEL_PORT_TO_ROBO_PORT(a)  ((a) - 1) /* foxconn added, zacker, 12/13/2011 */
77#endif /*defined R7000*/
78/* foxconn added end, zacker, 10/15/2010 */
79
80/* Power save duty cycle times */
81#define MAX_NO_PHYS		5
82#define PWRSAVE_SLEEP_TIME	12
83#define PWRSAVE_WAKE_TIME	3
84
85/* Power save modes for the switch */
86#define ROBO_PWRSAVE_NORMAL 		0
87#define ROBO_PWRSAVE_AUTO		1
88#define ROBO_PWRSAVE_MANUAL		2
89#define ROBO_PWRSAVE_AUTO_MANUAL 	3
90
91#define ROBO_IS_PWRSAVE_MANUAL(r) ((r)->pwrsave_mode_manual)
92#define ROBO_IS_PWRSAVE_AUTO(r) ((r)->pwrsave_mode_auto)
93
94/* SRAB interface */
95/* Access switch registers through SRAB (Switch Register Access Bridge) */
96#define REG_VERSION_ID		0x40
97#define REG_CTRL_PORT0_GMIIPO	0x58	/* 53012: GMII Port0 Override register */
98#define REG_CTRL_PORT1_GMIIPO	0x59	/* 53012: GMII Port1 Override register */
99#define REG_CTRL_PORT2_GMIIPO	0x5a	/* 53012: GMII Port2 Override register */
100#define REG_CTRL_PORT3_GMIIPO	0x5b	/* 53012: GMII Port3 Override register */
101#define REG_CTRL_PORT4_GMIIPO	0x5c	/* 53012: GMII Port4 Override register */
102#define REG_CTRL_PORT5_GMIIPO	0x5d	/* 53012: GMII Port5 Override register */
103#define REG_CTRL_PORT7_GMIIPO	0x5f	/* 53012: GMII Port7 Override register */
104
105/* Command and status register of the SRAB */
106#define CFG_F_sra_rst_MASK		(1 << 2)
107#define CFG_F_sra_write_MASK		(1 << 1)
108#define CFG_F_sra_gordyn_MASK		(1 << 0)
109#define CFG_F_sra_page_R		24
110#define CFG_F_sra_offset_R		16
111
112/* Switch interface controls */
113#define CFG_F_sw_init_done_MASK		(1 << 6)
114#define CFG_F_rcareq_MASK		(1 << 3)
115#define CFG_F_rcagnt_MASK		(1 << 4)
116
117#ifndef PAD
118#define	_PADLINE(line)	pad ## line
119#define	_XSTR(line)	_PADLINE(line)
120#define	PAD		_XSTR(__LINE__)
121#endif	/* PAD */
122
123typedef volatile struct {
124	uint32	PAD[11];
125	uint32	cmdstat;	/* 0x2c, command and status register of the SRAB */
126	uint32	wd_h;		/* 0x30, high order word of write data to switch registe */
127	uint32	wd_l;		/* 0x34, low order word of write data to switch registe */
128	uint32	rd_h;		/* 0x38, high order word of read data from switch register */
129	uint32	rd_l;		/* 0x3c, low order word of read data from switch register */
130	uint32	ctrls;		/* 0x40, switch interface controls */
131	uint32	intr;		/* 0x44, the register captures interrupt pulses from the switch */
132} srabregs_t;
133
134/* Forward declaration */
135typedef struct robo_info_s robo_info_t;
136
137/* Device access/config oprands */
138typedef struct {
139	/* low level routines */
140	void (*enable_mgmtif)(robo_info_t *robo);	/* enable mgmt i/f, optional */
141	void (*disable_mgmtif)(robo_info_t *robo);	/* disable mgmt i/f, optional */
142	int (*write_reg)(robo_info_t *robo, uint8 page, uint8 reg, void *val, int len);
143	int (*read_reg)(robo_info_t *robo, uint8 page, uint8 reg, void *val, int len);
144	/* description */
145	char *desc;
146} dev_ops_t;
147
148
149typedef	uint16 (*miird_f)(void *h, int add, int off);
150typedef	void (*miiwr_f)(void *h, int add, int off, uint16 val);
151
152/* Private state per RoboSwitch */
153struct robo_info_s {
154	si_t	*sih;			/* SiliconBackplane handle */
155	char	*vars;			/* nvram variables handle */
156	void	*h;			/* dev handle */
157	uint32	devid;			/* Device id for the switch */
158	uint32	corerev;		/* Core rev of internal switch */
159
160	dev_ops_t *ops;			/* device ops */
161	uint8	page;			/* current page */
162
163	/* SPI */
164	uint32	ss, sck, mosi, miso;	/* GPIO mapping */
165
166	/* MII */
167	miird_f	miird;
168	miiwr_f	miiwr;
169
170	/* SRAB */
171	srabregs_t *srabregs;
172
173	uint16	prev_status;		/* link status of switch ports */
174	uint32	pwrsave_mode_manual; 	/* bitmap of ports in manual power save */
175	uint32	pwrsave_mode_auto; 	/* bitmap of ports in auto power save mode */
176	uint32	pwrsave_sleep_time;	/* sleep time for manual power save mode */
177	uint32	pwrsave_wake_time;	/* wakeup time for manual power save mode */
178	uint8	pwrsave_phys;		/* Phys that can be put into power save mode */
179	uint8	pwrsave_mode_phys[MAX_NO_PHYS];         /* Power save mode on the switch */
180	bool	eee_status;
181#ifdef PLC
182	/* PLC */
183	bool	plc_hw;			/* PLC chip */
184#endif /* PLC */
185#ifdef BCMFA
186	int		aux_pid;
187#endif /* BCMFA */
188
189};
190/* Foxconn add start by Lewis Min, 04/02/2008, for igmp snooping */
191#ifdef __CONFIG_IGMP_SNOOPING__
192struct igmp_snooping_table_s {
193	uint8   mh_mac[6];
194	uint16 port_mapping;
195};
196typedef struct igmp_snooping_table_s igmp_snooping_table_t;
197#endif
198/*Add end by foxconn lewis min for snooping function ,04/01/2008*/
199
200/* Power Save mode related functions */
201extern int32 robo_power_save_mode_get(robo_info_t *robo, int32 phy);
202extern int32 robo_power_save_mode_set(robo_info_t *robo, int32 mode, int32 phy);
203extern void robo_power_save_mode_update(robo_info_t *robo);
204extern int robo_power_save_mode(robo_info_t *robo, int mode, int phy);
205extern int robo_power_save_toggle(robo_info_t *robo, int normal);
206
207extern robo_info_t *bcm_robo_attach(si_t *sih, void *h, char *vars, miird_f miird, miiwr_f miiwr);
208extern void bcm_robo_detach(robo_info_t *robo);
209extern int bcm_robo_enable_device(robo_info_t *robo);
210extern int bcm_robo_config_vlan(robo_info_t *robo, uint8 *mac_addr);
211extern int bcm_robo_enable_switch(robo_info_t *robo);
212extern int bcm_robo_flow_control(robo_info_t *robo, bool set);
213
214
215extern void robo_watchdog(robo_info_t *robo);
216extern void robo_eee_advertise_init(robo_info_t *robo);
217/* foxconn added start, zacker, 01/13/2012, @iptv_igmp */
218#if defined(CONFIG_RUSSIA_IPTV)
219extern void set_iptv_ports(robo_info_t *robo);
220extern uint16 get_iptv_ports(void);
221extern int is_iptv_port(int port);
222#endif
223/* foxconn added end, zacker, 01/13/2012, @iptv_igmp */
224
225#ifdef PLC
226extern void robo_plc_hw_init(robo_info_t *robo);
227#endif /* PLC */
228
229void bcm_robo_snooping_add(uint32 mgrp_ip, int portid);
230void bcm_robo_snooping_del(uint32 mgrp_ip, int portid);
231#ifdef BCMFA
232extern void robo_fa_aux_init(robo_info_t *robo);
233extern void robo_fa_aux_enable(robo_info_t *robo, bool enable);
234extern void robo_fa_enable(robo_info_t *robo, bool on, bool bhdr);
235#endif
236
237#endif /* _bcm_robo_h_ */
238