Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * B53 common definitions
0003  *
0004  * Copyright (C) 2011-2013 Jonas Gorski <jogo@openwrt.org>
0005  *
0006  * Permission to use, copy, modify, and/or distribute this software for any
0007  * purpose with or without fee is hereby granted, provided that the above
0008  * copyright notice and this permission notice appear in all copies.
0009  *
0010  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
0011  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
0012  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
0013  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
0014  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
0015  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
0016  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
0017  */
0018 
0019 #ifndef __B53_PRIV_H
0020 #define __B53_PRIV_H
0021 
0022 #include <linux/kernel.h>
0023 #include <linux/mutex.h>
0024 #include <linux/phylink.h>
0025 #include <linux/etherdevice.h>
0026 #include <net/dsa.h>
0027 
0028 #include "b53_regs.h"
0029 
0030 struct b53_device;
0031 struct net_device;
0032 
0033 struct b53_io_ops {
0034     int (*read8)(struct b53_device *dev, u8 page, u8 reg, u8 *value);
0035     int (*read16)(struct b53_device *dev, u8 page, u8 reg, u16 *value);
0036     int (*read32)(struct b53_device *dev, u8 page, u8 reg, u32 *value);
0037     int (*read48)(struct b53_device *dev, u8 page, u8 reg, u64 *value);
0038     int (*read64)(struct b53_device *dev, u8 page, u8 reg, u64 *value);
0039     int (*write8)(struct b53_device *dev, u8 page, u8 reg, u8 value);
0040     int (*write16)(struct b53_device *dev, u8 page, u8 reg, u16 value);
0041     int (*write32)(struct b53_device *dev, u8 page, u8 reg, u32 value);
0042     int (*write48)(struct b53_device *dev, u8 page, u8 reg, u64 value);
0043     int (*write64)(struct b53_device *dev, u8 page, u8 reg, u64 value);
0044     int (*phy_read16)(struct b53_device *dev, int addr, int reg, u16 *value);
0045     int (*phy_write16)(struct b53_device *dev, int addr, int reg, u16 value);
0046     int (*irq_enable)(struct b53_device *dev, int port);
0047     void (*irq_disable)(struct b53_device *dev, int port);
0048     void (*phylink_get_caps)(struct b53_device *dev, int port,
0049                  struct phylink_config *config);
0050     struct phylink_pcs *(*phylink_mac_select_pcs)(struct b53_device *dev,
0051                               int port,
0052                               phy_interface_t interface);
0053     u8 (*serdes_map_lane)(struct b53_device *dev, int port);
0054     void (*serdes_link_set)(struct b53_device *dev, int port,
0055                 unsigned int mode, phy_interface_t interface,
0056                 bool link_up);
0057 };
0058 
0059 #define B53_INVALID_LANE    0xff
0060 
0061 enum {
0062     BCM4908_DEVICE_ID = 0x4908,
0063     BCM5325_DEVICE_ID = 0x25,
0064     BCM5365_DEVICE_ID = 0x65,
0065     BCM5389_DEVICE_ID = 0x89,
0066     BCM5395_DEVICE_ID = 0x95,
0067     BCM5397_DEVICE_ID = 0x97,
0068     BCM5398_DEVICE_ID = 0x98,
0069     BCM53115_DEVICE_ID = 0x53115,
0070     BCM53125_DEVICE_ID = 0x53125,
0071     BCM53128_DEVICE_ID = 0x53128,
0072     BCM63XX_DEVICE_ID = 0x6300,
0073     BCM53010_DEVICE_ID = 0x53010,
0074     BCM53011_DEVICE_ID = 0x53011,
0075     BCM53012_DEVICE_ID = 0x53012,
0076     BCM53018_DEVICE_ID = 0x53018,
0077     BCM53019_DEVICE_ID = 0x53019,
0078     BCM58XX_DEVICE_ID = 0x5800,
0079     BCM583XX_DEVICE_ID = 0x58300,
0080     BCM7445_DEVICE_ID = 0x7445,
0081     BCM7278_DEVICE_ID = 0x7278,
0082 };
0083 
0084 struct b53_pcs {
0085     struct phylink_pcs pcs;
0086     struct b53_device *dev;
0087     u8 lane;
0088 };
0089 
0090 #define B53_N_PORTS 9
0091 #define B53_N_PORTS_25  6
0092 #define B53_N_PCS   2
0093 
0094 struct b53_port {
0095     u16     vlan_ctl_mask;
0096     struct ethtool_eee eee;
0097 };
0098 
0099 struct b53_vlan {
0100     u16 members;
0101     u16 untag;
0102     bool valid;
0103 };
0104 
0105 struct b53_device {
0106     struct dsa_switch *ds;
0107     struct b53_platform_data *pdata;
0108     const char *name;
0109 
0110     struct mutex reg_mutex;
0111     struct mutex stats_mutex;
0112     struct mutex arl_mutex;
0113     const struct b53_io_ops *ops;
0114 
0115     /* chip specific data */
0116     u32 chip_id;
0117     u8 core_rev;
0118     u8 vta_regs[3];
0119     u8 duplex_reg;
0120     u8 jumbo_pm_reg;
0121     u8 jumbo_size_reg;
0122     int reset_gpio;
0123     u8 num_arl_bins;
0124     u16 num_arl_buckets;
0125     enum dsa_tag_protocol tag_protocol;
0126 
0127     /* used ports mask */
0128     u16 enabled_ports;
0129     unsigned int imp_port;
0130 
0131     /* connect specific data */
0132     u8 current_page;
0133     struct device *dev;
0134     u8 serdes_lane;
0135 
0136     /* Master MDIO bus we got probed from */
0137     struct mii_bus *bus;
0138 
0139     void *priv;
0140 
0141     /* run time configuration */
0142     bool enable_jumbo;
0143 
0144     unsigned int num_vlans;
0145     struct b53_vlan *vlans;
0146     bool vlan_enabled;
0147     unsigned int num_ports;
0148     struct b53_port *ports;
0149 
0150     struct b53_pcs pcs[B53_N_PCS];
0151 };
0152 
0153 #define b53_for_each_port(dev, i) \
0154     for (i = 0; i < B53_N_PORTS; i++) \
0155         if (dev->enabled_ports & BIT(i))
0156 
0157 
0158 static inline int is5325(struct b53_device *dev)
0159 {
0160     return dev->chip_id == BCM5325_DEVICE_ID;
0161 }
0162 
0163 static inline int is5365(struct b53_device *dev)
0164 {
0165 #ifdef CONFIG_BCM47XX
0166     return dev->chip_id == BCM5365_DEVICE_ID;
0167 #else
0168     return 0;
0169 #endif
0170 }
0171 
0172 static inline int is5397_98(struct b53_device *dev)
0173 {
0174     return dev->chip_id == BCM5397_DEVICE_ID ||
0175         dev->chip_id == BCM5398_DEVICE_ID;
0176 }
0177 
0178 static inline int is539x(struct b53_device *dev)
0179 {
0180     return dev->chip_id == BCM5395_DEVICE_ID ||
0181         dev->chip_id == BCM5397_DEVICE_ID ||
0182         dev->chip_id == BCM5398_DEVICE_ID;
0183 }
0184 
0185 static inline int is531x5(struct b53_device *dev)
0186 {
0187     return dev->chip_id == BCM53115_DEVICE_ID ||
0188         dev->chip_id == BCM53125_DEVICE_ID ||
0189         dev->chip_id == BCM53128_DEVICE_ID;
0190 }
0191 
0192 static inline int is63xx(struct b53_device *dev)
0193 {
0194     return dev->chip_id == BCM63XX_DEVICE_ID;
0195 }
0196 
0197 static inline int is5301x(struct b53_device *dev)
0198 {
0199     return dev->chip_id == BCM53010_DEVICE_ID ||
0200         dev->chip_id == BCM53011_DEVICE_ID ||
0201         dev->chip_id == BCM53012_DEVICE_ID ||
0202         dev->chip_id == BCM53018_DEVICE_ID ||
0203         dev->chip_id == BCM53019_DEVICE_ID;
0204 }
0205 
0206 static inline int is58xx(struct b53_device *dev)
0207 {
0208     return dev->chip_id == BCM58XX_DEVICE_ID ||
0209         dev->chip_id == BCM583XX_DEVICE_ID ||
0210         dev->chip_id == BCM7445_DEVICE_ID ||
0211         dev->chip_id == BCM7278_DEVICE_ID;
0212 }
0213 
0214 #define B53_CPU_PORT_25 5
0215 #define B53_CPU_PORT    8
0216 
0217 static inline unsigned int b53_max_arl_entries(struct b53_device *dev)
0218 {
0219     return dev->num_arl_buckets * dev->num_arl_bins;
0220 }
0221 
0222 struct b53_device *b53_switch_alloc(struct device *base,
0223                     const struct b53_io_ops *ops,
0224                     void *priv);
0225 
0226 int b53_switch_detect(struct b53_device *dev);
0227 
0228 int b53_switch_register(struct b53_device *dev);
0229 
0230 static inline void b53_switch_remove(struct b53_device *dev)
0231 {
0232     dsa_unregister_switch(dev->ds);
0233 }
0234 
0235 static inline void b53_switch_shutdown(struct b53_device *dev)
0236 {
0237     dsa_switch_shutdown(dev->ds);
0238 }
0239 
0240 #define b53_build_op(type_op_size, val_type)                \
0241 static inline int b53_##type_op_size(struct b53_device *dev, u8 page,   \
0242                      u8 reg, val_type val)      \
0243 {                                   \
0244     int ret;                            \
0245                                     \
0246     mutex_lock(&dev->reg_mutex);                    \
0247     ret = dev->ops->type_op_size(dev, page, reg, val);      \
0248     mutex_unlock(&dev->reg_mutex);                  \
0249                                     \
0250     return ret;                         \
0251 }
0252 
0253 b53_build_op(read8, u8 *);
0254 b53_build_op(read16, u16 *);
0255 b53_build_op(read32, u32 *);
0256 b53_build_op(read48, u64 *);
0257 b53_build_op(read64, u64 *);
0258 
0259 b53_build_op(write8, u8);
0260 b53_build_op(write16, u16);
0261 b53_build_op(write32, u32);
0262 b53_build_op(write48, u64);
0263 b53_build_op(write64, u64);
0264 
0265 struct b53_arl_entry {
0266     u16 port;
0267     u8 mac[ETH_ALEN];
0268     u16 vid;
0269     u8 is_valid:1;
0270     u8 is_age:1;
0271     u8 is_static:1;
0272 };
0273 
0274 static inline void b53_arl_to_entry(struct b53_arl_entry *ent,
0275                     u64 mac_vid, u32 fwd_entry)
0276 {
0277     memset(ent, 0, sizeof(*ent));
0278     ent->port = fwd_entry & ARLTBL_DATA_PORT_ID_MASK;
0279     ent->is_valid = !!(fwd_entry & ARLTBL_VALID);
0280     ent->is_age = !!(fwd_entry & ARLTBL_AGE);
0281     ent->is_static = !!(fwd_entry & ARLTBL_STATIC);
0282     u64_to_ether_addr(mac_vid, ent->mac);
0283     ent->vid = mac_vid >> ARLTBL_VID_S;
0284 }
0285 
0286 static inline void b53_arl_from_entry(u64 *mac_vid, u32 *fwd_entry,
0287                       const struct b53_arl_entry *ent)
0288 {
0289     *mac_vid = ether_addr_to_u64(ent->mac);
0290     *mac_vid |= (u64)(ent->vid & ARLTBL_VID_MASK) << ARLTBL_VID_S;
0291     *fwd_entry = ent->port & ARLTBL_DATA_PORT_ID_MASK;
0292     if (ent->is_valid)
0293         *fwd_entry |= ARLTBL_VALID;
0294     if (ent->is_static)
0295         *fwd_entry |= ARLTBL_STATIC;
0296     if (ent->is_age)
0297         *fwd_entry |= ARLTBL_AGE;
0298 }
0299 
0300 #ifdef CONFIG_BCM47XX
0301 
0302 #include <linux/bcm47xx_nvram.h>
0303 #include <bcm47xx_board.h>
0304 static inline int b53_switch_get_reset_gpio(struct b53_device *dev)
0305 {
0306     enum bcm47xx_board board = bcm47xx_board_get();
0307 
0308     switch (board) {
0309     case BCM47XX_BOARD_LINKSYS_WRT300NV11:
0310     case BCM47XX_BOARD_LINKSYS_WRT310NV1:
0311         return 8;
0312     default:
0313         return bcm47xx_nvram_gpio_pin("robo_reset");
0314     }
0315 }
0316 #else
0317 static inline int b53_switch_get_reset_gpio(struct b53_device *dev)
0318 {
0319     return -ENOENT;
0320 }
0321 #endif
0322 
0323 /* Exported functions towards other drivers */
0324 void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port);
0325 int b53_configure_vlan(struct dsa_switch *ds);
0326 void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset,
0327              uint8_t *data);
0328 void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data);
0329 int b53_get_sset_count(struct dsa_switch *ds, int port, int sset);
0330 void b53_get_ethtool_phy_stats(struct dsa_switch *ds, int port, uint64_t *data);
0331 int b53_br_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge,
0332         bool *tx_fwd_offload, struct netlink_ext_ack *extack);
0333 void b53_br_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge);
0334 void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state);
0335 void b53_br_fast_age(struct dsa_switch *ds, int port);
0336 int b53_br_flags_pre(struct dsa_switch *ds, int port,
0337              struct switchdev_brport_flags flags,
0338              struct netlink_ext_ack *extack);
0339 int b53_br_flags(struct dsa_switch *ds, int port,
0340          struct switchdev_brport_flags flags,
0341          struct netlink_ext_ack *extack);
0342 int b53_setup_devlink_resources(struct dsa_switch *ds);
0343 void b53_port_event(struct dsa_switch *ds, int port);
0344 void b53_phylink_mac_config(struct dsa_switch *ds, int port,
0345                 unsigned int mode,
0346                 const struct phylink_link_state *state);
0347 void b53_phylink_mac_link_down(struct dsa_switch *ds, int port,
0348                    unsigned int mode,
0349                    phy_interface_t interface);
0350 void b53_phylink_mac_link_up(struct dsa_switch *ds, int port,
0351                  unsigned int mode,
0352                  phy_interface_t interface,
0353                  struct phy_device *phydev,
0354                  int speed, int duplex,
0355                  bool tx_pause, bool rx_pause);
0356 int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering,
0357                struct netlink_ext_ack *extack);
0358 int b53_vlan_add(struct dsa_switch *ds, int port,
0359          const struct switchdev_obj_port_vlan *vlan,
0360          struct netlink_ext_ack *extack);
0361 int b53_vlan_del(struct dsa_switch *ds, int port,
0362          const struct switchdev_obj_port_vlan *vlan);
0363 int b53_fdb_add(struct dsa_switch *ds, int port,
0364         const unsigned char *addr, u16 vid,
0365         struct dsa_db db);
0366 int b53_fdb_del(struct dsa_switch *ds, int port,
0367         const unsigned char *addr, u16 vid,
0368         struct dsa_db db);
0369 int b53_fdb_dump(struct dsa_switch *ds, int port,
0370          dsa_fdb_dump_cb_t *cb, void *data);
0371 int b53_mdb_add(struct dsa_switch *ds, int port,
0372         const struct switchdev_obj_port_mdb *mdb,
0373         struct dsa_db db);
0374 int b53_mdb_del(struct dsa_switch *ds, int port,
0375         const struct switchdev_obj_port_mdb *mdb,
0376         struct dsa_db db);
0377 int b53_mirror_add(struct dsa_switch *ds, int port,
0378            struct dsa_mall_mirror_tc_entry *mirror, bool ingress,
0379            struct netlink_ext_ack *extack);
0380 enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port,
0381                        enum dsa_tag_protocol mprot);
0382 void b53_mirror_del(struct dsa_switch *ds, int port,
0383             struct dsa_mall_mirror_tc_entry *mirror);
0384 int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy);
0385 void b53_disable_port(struct dsa_switch *ds, int port);
0386 void b53_brcm_hdr_setup(struct dsa_switch *ds, int port);
0387 void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable);
0388 int b53_eee_init(struct dsa_switch *ds, int port, struct phy_device *phy);
0389 int b53_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e);
0390 int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e);
0391 
0392 #endif