1967dd82fSFlorian Fainelli /* 2967dd82fSFlorian Fainelli * B53 switch driver main logic 3967dd82fSFlorian Fainelli * 4967dd82fSFlorian Fainelli * Copyright (C) 2011-2013 Jonas Gorski <jogo@openwrt.org> 5967dd82fSFlorian Fainelli * Copyright (C) 2016 Florian Fainelli <f.fainelli@gmail.com> 6967dd82fSFlorian Fainelli * 7967dd82fSFlorian Fainelli * Permission to use, copy, modify, and/or distribute this software for any 8967dd82fSFlorian Fainelli * purpose with or without fee is hereby granted, provided that the above 9967dd82fSFlorian Fainelli * copyright notice and this permission notice appear in all copies. 10967dd82fSFlorian Fainelli * 11967dd82fSFlorian Fainelli * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12967dd82fSFlorian Fainelli * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13967dd82fSFlorian Fainelli * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14967dd82fSFlorian Fainelli * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15967dd82fSFlorian Fainelli * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16967dd82fSFlorian Fainelli * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17967dd82fSFlorian Fainelli * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18967dd82fSFlorian Fainelli */ 19967dd82fSFlorian Fainelli 20967dd82fSFlorian Fainelli #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 21967dd82fSFlorian Fainelli 22967dd82fSFlorian Fainelli #include <linux/delay.h> 23967dd82fSFlorian Fainelli #include <linux/export.h> 24967dd82fSFlorian Fainelli #include <linux/gpio.h> 25967dd82fSFlorian Fainelli #include <linux/kernel.h> 26967dd82fSFlorian Fainelli #include <linux/module.h> 27967dd82fSFlorian Fainelli #include <linux/platform_data/b53.h> 28967dd82fSFlorian Fainelli #include <linux/phy.h> 295e004460SFlorian Fainelli #include <linux/phylink.h> 301da6df85SFlorian Fainelli #include <linux/etherdevice.h> 31ff39c2d6SFlorian Fainelli #include <linux/if_bridge.h> 32967dd82fSFlorian Fainelli #include <net/dsa.h> 33967dd82fSFlorian Fainelli 34967dd82fSFlorian Fainelli #include "b53_regs.h" 35967dd82fSFlorian Fainelli #include "b53_priv.h" 36967dd82fSFlorian Fainelli 37967dd82fSFlorian Fainelli struct b53_mib_desc { 38967dd82fSFlorian Fainelli u8 size; 39967dd82fSFlorian Fainelli u8 offset; 40967dd82fSFlorian Fainelli const char *name; 41967dd82fSFlorian Fainelli }; 42967dd82fSFlorian Fainelli 43967dd82fSFlorian Fainelli /* BCM5365 MIB counters */ 44967dd82fSFlorian Fainelli static const struct b53_mib_desc b53_mibs_65[] = { 45967dd82fSFlorian Fainelli { 8, 0x00, "TxOctets" }, 46967dd82fSFlorian Fainelli { 4, 0x08, "TxDropPkts" }, 47967dd82fSFlorian Fainelli { 4, 0x10, "TxBroadcastPkts" }, 48967dd82fSFlorian Fainelli { 4, 0x14, "TxMulticastPkts" }, 49967dd82fSFlorian Fainelli { 4, 0x18, "TxUnicastPkts" }, 50967dd82fSFlorian Fainelli { 4, 0x1c, "TxCollisions" }, 51967dd82fSFlorian Fainelli { 4, 0x20, "TxSingleCollision" }, 52967dd82fSFlorian Fainelli { 4, 0x24, "TxMultipleCollision" }, 53967dd82fSFlorian Fainelli { 4, 0x28, "TxDeferredTransmit" }, 54967dd82fSFlorian Fainelli { 4, 0x2c, "TxLateCollision" }, 55967dd82fSFlorian Fainelli { 4, 0x30, "TxExcessiveCollision" }, 56967dd82fSFlorian Fainelli { 4, 0x38, "TxPausePkts" }, 57967dd82fSFlorian Fainelli { 8, 0x44, "RxOctets" }, 58967dd82fSFlorian Fainelli { 4, 0x4c, "RxUndersizePkts" }, 59967dd82fSFlorian Fainelli { 4, 0x50, "RxPausePkts" }, 60967dd82fSFlorian Fainelli { 4, 0x54, "Pkts64Octets" }, 61967dd82fSFlorian Fainelli { 4, 0x58, "Pkts65to127Octets" }, 62967dd82fSFlorian Fainelli { 4, 0x5c, "Pkts128to255Octets" }, 63967dd82fSFlorian Fainelli { 4, 0x60, "Pkts256to511Octets" }, 64967dd82fSFlorian Fainelli { 4, 0x64, "Pkts512to1023Octets" }, 65967dd82fSFlorian Fainelli { 4, 0x68, "Pkts1024to1522Octets" }, 66967dd82fSFlorian Fainelli { 4, 0x6c, "RxOversizePkts" }, 67967dd82fSFlorian Fainelli { 4, 0x70, "RxJabbers" }, 68967dd82fSFlorian Fainelli { 4, 0x74, "RxAlignmentErrors" }, 69967dd82fSFlorian Fainelli { 4, 0x78, "RxFCSErrors" }, 70967dd82fSFlorian Fainelli { 8, 0x7c, "RxGoodOctets" }, 71967dd82fSFlorian Fainelli { 4, 0x84, "RxDropPkts" }, 72967dd82fSFlorian Fainelli { 4, 0x88, "RxUnicastPkts" }, 73967dd82fSFlorian Fainelli { 4, 0x8c, "RxMulticastPkts" }, 74967dd82fSFlorian Fainelli { 4, 0x90, "RxBroadcastPkts" }, 75967dd82fSFlorian Fainelli { 4, 0x94, "RxSAChanges" }, 76967dd82fSFlorian Fainelli { 4, 0x98, "RxFragments" }, 77967dd82fSFlorian Fainelli }; 78967dd82fSFlorian Fainelli 79967dd82fSFlorian Fainelli #define B53_MIBS_65_SIZE ARRAY_SIZE(b53_mibs_65) 80967dd82fSFlorian Fainelli 81967dd82fSFlorian Fainelli /* BCM63xx MIB counters */ 82967dd82fSFlorian Fainelli static const struct b53_mib_desc b53_mibs_63xx[] = { 83967dd82fSFlorian Fainelli { 8, 0x00, "TxOctets" }, 84967dd82fSFlorian Fainelli { 4, 0x08, "TxDropPkts" }, 85967dd82fSFlorian Fainelli { 4, 0x0c, "TxQoSPkts" }, 86967dd82fSFlorian Fainelli { 4, 0x10, "TxBroadcastPkts" }, 87967dd82fSFlorian Fainelli { 4, 0x14, "TxMulticastPkts" }, 88967dd82fSFlorian Fainelli { 4, 0x18, "TxUnicastPkts" }, 89967dd82fSFlorian Fainelli { 4, 0x1c, "TxCollisions" }, 90967dd82fSFlorian Fainelli { 4, 0x20, "TxSingleCollision" }, 91967dd82fSFlorian Fainelli { 4, 0x24, "TxMultipleCollision" }, 92967dd82fSFlorian Fainelli { 4, 0x28, "TxDeferredTransmit" }, 93967dd82fSFlorian Fainelli { 4, 0x2c, "TxLateCollision" }, 94967dd82fSFlorian Fainelli { 4, 0x30, "TxExcessiveCollision" }, 95967dd82fSFlorian Fainelli { 4, 0x38, "TxPausePkts" }, 96967dd82fSFlorian Fainelli { 8, 0x3c, "TxQoSOctets" }, 97967dd82fSFlorian Fainelli { 8, 0x44, "RxOctets" }, 98967dd82fSFlorian Fainelli { 4, 0x4c, "RxUndersizePkts" }, 99967dd82fSFlorian Fainelli { 4, 0x50, "RxPausePkts" }, 100967dd82fSFlorian Fainelli { 4, 0x54, "Pkts64Octets" }, 101967dd82fSFlorian Fainelli { 4, 0x58, "Pkts65to127Octets" }, 102967dd82fSFlorian Fainelli { 4, 0x5c, "Pkts128to255Octets" }, 103967dd82fSFlorian Fainelli { 4, 0x60, "Pkts256to511Octets" }, 104967dd82fSFlorian Fainelli { 4, 0x64, "Pkts512to1023Octets" }, 105967dd82fSFlorian Fainelli { 4, 0x68, "Pkts1024to1522Octets" }, 106967dd82fSFlorian Fainelli { 4, 0x6c, "RxOversizePkts" }, 107967dd82fSFlorian Fainelli { 4, 0x70, "RxJabbers" }, 108967dd82fSFlorian Fainelli { 4, 0x74, "RxAlignmentErrors" }, 109967dd82fSFlorian Fainelli { 4, 0x78, "RxFCSErrors" }, 110967dd82fSFlorian Fainelli { 8, 0x7c, "RxGoodOctets" }, 111967dd82fSFlorian Fainelli { 4, 0x84, "RxDropPkts" }, 112967dd82fSFlorian Fainelli { 4, 0x88, "RxUnicastPkts" }, 113967dd82fSFlorian Fainelli { 4, 0x8c, "RxMulticastPkts" }, 114967dd82fSFlorian Fainelli { 4, 0x90, "RxBroadcastPkts" }, 115967dd82fSFlorian Fainelli { 4, 0x94, "RxSAChanges" }, 116967dd82fSFlorian Fainelli { 4, 0x98, "RxFragments" }, 117967dd82fSFlorian Fainelli { 4, 0xa0, "RxSymbolErrors" }, 118967dd82fSFlorian Fainelli { 4, 0xa4, "RxQoSPkts" }, 119967dd82fSFlorian Fainelli { 8, 0xa8, "RxQoSOctets" }, 120967dd82fSFlorian Fainelli { 4, 0xb0, "Pkts1523to2047Octets" }, 121967dd82fSFlorian Fainelli { 4, 0xb4, "Pkts2048to4095Octets" }, 122967dd82fSFlorian Fainelli { 4, 0xb8, "Pkts4096to8191Octets" }, 123967dd82fSFlorian Fainelli { 4, 0xbc, "Pkts8192to9728Octets" }, 124967dd82fSFlorian Fainelli { 4, 0xc0, "RxDiscarded" }, 125967dd82fSFlorian Fainelli }; 126967dd82fSFlorian Fainelli 127967dd82fSFlorian Fainelli #define B53_MIBS_63XX_SIZE ARRAY_SIZE(b53_mibs_63xx) 128967dd82fSFlorian Fainelli 129967dd82fSFlorian Fainelli /* MIB counters */ 130967dd82fSFlorian Fainelli static const struct b53_mib_desc b53_mibs[] = { 131967dd82fSFlorian Fainelli { 8, 0x00, "TxOctets" }, 132967dd82fSFlorian Fainelli { 4, 0x08, "TxDropPkts" }, 133967dd82fSFlorian Fainelli { 4, 0x10, "TxBroadcastPkts" }, 134967dd82fSFlorian Fainelli { 4, 0x14, "TxMulticastPkts" }, 135967dd82fSFlorian Fainelli { 4, 0x18, "TxUnicastPkts" }, 136967dd82fSFlorian Fainelli { 4, 0x1c, "TxCollisions" }, 137967dd82fSFlorian Fainelli { 4, 0x20, "TxSingleCollision" }, 138967dd82fSFlorian Fainelli { 4, 0x24, "TxMultipleCollision" }, 139967dd82fSFlorian Fainelli { 4, 0x28, "TxDeferredTransmit" }, 140967dd82fSFlorian Fainelli { 4, 0x2c, "TxLateCollision" }, 141967dd82fSFlorian Fainelli { 4, 0x30, "TxExcessiveCollision" }, 142967dd82fSFlorian Fainelli { 4, 0x38, "TxPausePkts" }, 143967dd82fSFlorian Fainelli { 8, 0x50, "RxOctets" }, 144967dd82fSFlorian Fainelli { 4, 0x58, "RxUndersizePkts" }, 145967dd82fSFlorian Fainelli { 4, 0x5c, "RxPausePkts" }, 146967dd82fSFlorian Fainelli { 4, 0x60, "Pkts64Octets" }, 147967dd82fSFlorian Fainelli { 4, 0x64, "Pkts65to127Octets" }, 148967dd82fSFlorian Fainelli { 4, 0x68, "Pkts128to255Octets" }, 149967dd82fSFlorian Fainelli { 4, 0x6c, "Pkts256to511Octets" }, 150967dd82fSFlorian Fainelli { 4, 0x70, "Pkts512to1023Octets" }, 151967dd82fSFlorian Fainelli { 4, 0x74, "Pkts1024to1522Octets" }, 152967dd82fSFlorian Fainelli { 4, 0x78, "RxOversizePkts" }, 153967dd82fSFlorian Fainelli { 4, 0x7c, "RxJabbers" }, 154967dd82fSFlorian Fainelli { 4, 0x80, "RxAlignmentErrors" }, 155967dd82fSFlorian Fainelli { 4, 0x84, "RxFCSErrors" }, 156967dd82fSFlorian Fainelli { 8, 0x88, "RxGoodOctets" }, 157967dd82fSFlorian Fainelli { 4, 0x90, "RxDropPkts" }, 158967dd82fSFlorian Fainelli { 4, 0x94, "RxUnicastPkts" }, 159967dd82fSFlorian Fainelli { 4, 0x98, "RxMulticastPkts" }, 160967dd82fSFlorian Fainelli { 4, 0x9c, "RxBroadcastPkts" }, 161967dd82fSFlorian Fainelli { 4, 0xa0, "RxSAChanges" }, 162967dd82fSFlorian Fainelli { 4, 0xa4, "RxFragments" }, 163967dd82fSFlorian Fainelli { 4, 0xa8, "RxJumboPkts" }, 164967dd82fSFlorian Fainelli { 4, 0xac, "RxSymbolErrors" }, 165967dd82fSFlorian Fainelli { 4, 0xc0, "RxDiscarded" }, 166967dd82fSFlorian Fainelli }; 167967dd82fSFlorian Fainelli 168967dd82fSFlorian Fainelli #define B53_MIBS_SIZE ARRAY_SIZE(b53_mibs) 169967dd82fSFlorian Fainelli 170bde5d132SFlorian Fainelli static const struct b53_mib_desc b53_mibs_58xx[] = { 171bde5d132SFlorian Fainelli { 8, 0x00, "TxOctets" }, 172bde5d132SFlorian Fainelli { 4, 0x08, "TxDropPkts" }, 173bde5d132SFlorian Fainelli { 4, 0x0c, "TxQPKTQ0" }, 174bde5d132SFlorian Fainelli { 4, 0x10, "TxBroadcastPkts" }, 175bde5d132SFlorian Fainelli { 4, 0x14, "TxMulticastPkts" }, 176bde5d132SFlorian Fainelli { 4, 0x18, "TxUnicastPKts" }, 177bde5d132SFlorian Fainelli { 4, 0x1c, "TxCollisions" }, 178bde5d132SFlorian Fainelli { 4, 0x20, "TxSingleCollision" }, 179bde5d132SFlorian Fainelli { 4, 0x24, "TxMultipleCollision" }, 180bde5d132SFlorian Fainelli { 4, 0x28, "TxDeferredCollision" }, 181bde5d132SFlorian Fainelli { 4, 0x2c, "TxLateCollision" }, 182bde5d132SFlorian Fainelli { 4, 0x30, "TxExcessiveCollision" }, 183bde5d132SFlorian Fainelli { 4, 0x34, "TxFrameInDisc" }, 184bde5d132SFlorian Fainelli { 4, 0x38, "TxPausePkts" }, 185bde5d132SFlorian Fainelli { 4, 0x3c, "TxQPKTQ1" }, 186bde5d132SFlorian Fainelli { 4, 0x40, "TxQPKTQ2" }, 187bde5d132SFlorian Fainelli { 4, 0x44, "TxQPKTQ3" }, 188bde5d132SFlorian Fainelli { 4, 0x48, "TxQPKTQ4" }, 189bde5d132SFlorian Fainelli { 4, 0x4c, "TxQPKTQ5" }, 190bde5d132SFlorian Fainelli { 8, 0x50, "RxOctets" }, 191bde5d132SFlorian Fainelli { 4, 0x58, "RxUndersizePkts" }, 192bde5d132SFlorian Fainelli { 4, 0x5c, "RxPausePkts" }, 193bde5d132SFlorian Fainelli { 4, 0x60, "RxPkts64Octets" }, 194bde5d132SFlorian Fainelli { 4, 0x64, "RxPkts65to127Octets" }, 195bde5d132SFlorian Fainelli { 4, 0x68, "RxPkts128to255Octets" }, 196bde5d132SFlorian Fainelli { 4, 0x6c, "RxPkts256to511Octets" }, 197bde5d132SFlorian Fainelli { 4, 0x70, "RxPkts512to1023Octets" }, 198bde5d132SFlorian Fainelli { 4, 0x74, "RxPkts1024toMaxPktsOctets" }, 199bde5d132SFlorian Fainelli { 4, 0x78, "RxOversizePkts" }, 200bde5d132SFlorian Fainelli { 4, 0x7c, "RxJabbers" }, 201bde5d132SFlorian Fainelli { 4, 0x80, "RxAlignmentErrors" }, 202bde5d132SFlorian Fainelli { 4, 0x84, "RxFCSErrors" }, 203bde5d132SFlorian Fainelli { 8, 0x88, "RxGoodOctets" }, 204bde5d132SFlorian Fainelli { 4, 0x90, "RxDropPkts" }, 205bde5d132SFlorian Fainelli { 4, 0x94, "RxUnicastPkts" }, 206bde5d132SFlorian Fainelli { 4, 0x98, "RxMulticastPkts" }, 207bde5d132SFlorian Fainelli { 4, 0x9c, "RxBroadcastPkts" }, 208bde5d132SFlorian Fainelli { 4, 0xa0, "RxSAChanges" }, 209bde5d132SFlorian Fainelli { 4, 0xa4, "RxFragments" }, 210bde5d132SFlorian Fainelli { 4, 0xa8, "RxJumboPkt" }, 211bde5d132SFlorian Fainelli { 4, 0xac, "RxSymblErr" }, 212bde5d132SFlorian Fainelli { 4, 0xb0, "InRangeErrCount" }, 213bde5d132SFlorian Fainelli { 4, 0xb4, "OutRangeErrCount" }, 214bde5d132SFlorian Fainelli { 4, 0xb8, "EEELpiEvent" }, 215bde5d132SFlorian Fainelli { 4, 0xbc, "EEELpiDuration" }, 216bde5d132SFlorian Fainelli { 4, 0xc0, "RxDiscard" }, 217bde5d132SFlorian Fainelli { 4, 0xc8, "TxQPKTQ6" }, 218bde5d132SFlorian Fainelli { 4, 0xcc, "TxQPKTQ7" }, 219bde5d132SFlorian Fainelli { 4, 0xd0, "TxPkts64Octets" }, 220bde5d132SFlorian Fainelli { 4, 0xd4, "TxPkts65to127Octets" }, 221bde5d132SFlorian Fainelli { 4, 0xd8, "TxPkts128to255Octets" }, 222bde5d132SFlorian Fainelli { 4, 0xdc, "TxPkts256to511Ocets" }, 223bde5d132SFlorian Fainelli { 4, 0xe0, "TxPkts512to1023Ocets" }, 224bde5d132SFlorian Fainelli { 4, 0xe4, "TxPkts1024toMaxPktOcets" }, 225bde5d132SFlorian Fainelli }; 226bde5d132SFlorian Fainelli 227bde5d132SFlorian Fainelli #define B53_MIBS_58XX_SIZE ARRAY_SIZE(b53_mibs_58xx) 228bde5d132SFlorian Fainelli 229967dd82fSFlorian Fainelli static int b53_do_vlan_op(struct b53_device *dev, u8 op) 230967dd82fSFlorian Fainelli { 231967dd82fSFlorian Fainelli unsigned int i; 232967dd82fSFlorian Fainelli 233967dd82fSFlorian Fainelli b53_write8(dev, B53_ARLIO_PAGE, dev->vta_regs[0], VTA_START_CMD | op); 234967dd82fSFlorian Fainelli 235967dd82fSFlorian Fainelli for (i = 0; i < 10; i++) { 236967dd82fSFlorian Fainelli u8 vta; 237967dd82fSFlorian Fainelli 238967dd82fSFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, dev->vta_regs[0], &vta); 239967dd82fSFlorian Fainelli if (!(vta & VTA_START_CMD)) 240967dd82fSFlorian Fainelli return 0; 241967dd82fSFlorian Fainelli 242967dd82fSFlorian Fainelli usleep_range(100, 200); 243967dd82fSFlorian Fainelli } 244967dd82fSFlorian Fainelli 245967dd82fSFlorian Fainelli return -EIO; 246967dd82fSFlorian Fainelli } 247967dd82fSFlorian Fainelli 248a2482d2cSFlorian Fainelli static void b53_set_vlan_entry(struct b53_device *dev, u16 vid, 249a2482d2cSFlorian Fainelli struct b53_vlan *vlan) 250967dd82fSFlorian Fainelli { 251967dd82fSFlorian Fainelli if (is5325(dev)) { 252967dd82fSFlorian Fainelli u32 entry = 0; 253967dd82fSFlorian Fainelli 254a2482d2cSFlorian Fainelli if (vlan->members) { 255a2482d2cSFlorian Fainelli entry = ((vlan->untag & VA_UNTAG_MASK_25) << 256a2482d2cSFlorian Fainelli VA_UNTAG_S_25) | vlan->members; 257967dd82fSFlorian Fainelli if (dev->core_rev >= 3) 258967dd82fSFlorian Fainelli entry |= VA_VALID_25_R4 | vid << VA_VID_HIGH_S; 259967dd82fSFlorian Fainelli else 260967dd82fSFlorian Fainelli entry |= VA_VALID_25; 261967dd82fSFlorian Fainelli } 262967dd82fSFlorian Fainelli 263967dd82fSFlorian Fainelli b53_write32(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_25, entry); 264967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, vid | 265967dd82fSFlorian Fainelli VTA_RW_STATE_WR | VTA_RW_OP_EN); 266967dd82fSFlorian Fainelli } else if (is5365(dev)) { 267967dd82fSFlorian Fainelli u16 entry = 0; 268967dd82fSFlorian Fainelli 269a2482d2cSFlorian Fainelli if (vlan->members) 270a2482d2cSFlorian Fainelli entry = ((vlan->untag & VA_UNTAG_MASK_65) << 271a2482d2cSFlorian Fainelli VA_UNTAG_S_65) | vlan->members | VA_VALID_65; 272967dd82fSFlorian Fainelli 273967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_65, entry); 274967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_65, vid | 275967dd82fSFlorian Fainelli VTA_RW_STATE_WR | VTA_RW_OP_EN); 276967dd82fSFlorian Fainelli } else { 277967dd82fSFlorian Fainelli b53_write16(dev, B53_ARLIO_PAGE, dev->vta_regs[1], vid); 278967dd82fSFlorian Fainelli b53_write32(dev, B53_ARLIO_PAGE, dev->vta_regs[2], 279a2482d2cSFlorian Fainelli (vlan->untag << VTE_UNTAG_S) | vlan->members); 280967dd82fSFlorian Fainelli 281967dd82fSFlorian Fainelli b53_do_vlan_op(dev, VTA_CMD_WRITE); 282967dd82fSFlorian Fainelli } 283a2482d2cSFlorian Fainelli 284a2482d2cSFlorian Fainelli dev_dbg(dev->ds->dev, "VID: %d, members: 0x%04x, untag: 0x%04x\n", 285a2482d2cSFlorian Fainelli vid, vlan->members, vlan->untag); 286967dd82fSFlorian Fainelli } 287967dd82fSFlorian Fainelli 288a2482d2cSFlorian Fainelli static void b53_get_vlan_entry(struct b53_device *dev, u16 vid, 289a2482d2cSFlorian Fainelli struct b53_vlan *vlan) 290a2482d2cSFlorian Fainelli { 291a2482d2cSFlorian Fainelli if (is5325(dev)) { 292a2482d2cSFlorian Fainelli u32 entry = 0; 293a2482d2cSFlorian Fainelli 294a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, vid | 295a2482d2cSFlorian Fainelli VTA_RW_STATE_RD | VTA_RW_OP_EN); 296a2482d2cSFlorian Fainelli b53_read32(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_25, &entry); 297a2482d2cSFlorian Fainelli 298a2482d2cSFlorian Fainelli if (dev->core_rev >= 3) 299a2482d2cSFlorian Fainelli vlan->valid = !!(entry & VA_VALID_25_R4); 300a2482d2cSFlorian Fainelli else 301a2482d2cSFlorian Fainelli vlan->valid = !!(entry & VA_VALID_25); 302a2482d2cSFlorian Fainelli vlan->members = entry & VA_MEMBER_MASK; 303a2482d2cSFlorian Fainelli vlan->untag = (entry >> VA_UNTAG_S_25) & VA_UNTAG_MASK_25; 304a2482d2cSFlorian Fainelli 305a2482d2cSFlorian Fainelli } else if (is5365(dev)) { 306a2482d2cSFlorian Fainelli u16 entry = 0; 307a2482d2cSFlorian Fainelli 308a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_65, vid | 309a2482d2cSFlorian Fainelli VTA_RW_STATE_WR | VTA_RW_OP_EN); 310a2482d2cSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_65, &entry); 311a2482d2cSFlorian Fainelli 312a2482d2cSFlorian Fainelli vlan->valid = !!(entry & VA_VALID_65); 313a2482d2cSFlorian Fainelli vlan->members = entry & VA_MEMBER_MASK; 314a2482d2cSFlorian Fainelli vlan->untag = (entry >> VA_UNTAG_S_65) & VA_UNTAG_MASK_65; 315a2482d2cSFlorian Fainelli } else { 316a2482d2cSFlorian Fainelli u32 entry = 0; 317a2482d2cSFlorian Fainelli 318a2482d2cSFlorian Fainelli b53_write16(dev, B53_ARLIO_PAGE, dev->vta_regs[1], vid); 319a2482d2cSFlorian Fainelli b53_do_vlan_op(dev, VTA_CMD_READ); 320a2482d2cSFlorian Fainelli b53_read32(dev, B53_ARLIO_PAGE, dev->vta_regs[2], &entry); 321a2482d2cSFlorian Fainelli vlan->members = entry & VTE_MEMBERS; 322a2482d2cSFlorian Fainelli vlan->untag = (entry >> VTE_UNTAG_S) & VTE_MEMBERS; 323a2482d2cSFlorian Fainelli vlan->valid = true; 324a2482d2cSFlorian Fainelli } 325a2482d2cSFlorian Fainelli } 326a2482d2cSFlorian Fainelli 327a2482d2cSFlorian Fainelli static void b53_set_forwarding(struct b53_device *dev, int enable) 328967dd82fSFlorian Fainelli { 329967dd82fSFlorian Fainelli u8 mgmt; 330967dd82fSFlorian Fainelli 331967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); 332967dd82fSFlorian Fainelli 333967dd82fSFlorian Fainelli if (enable) 334967dd82fSFlorian Fainelli mgmt |= SM_SW_FWD_EN; 335967dd82fSFlorian Fainelli else 336967dd82fSFlorian Fainelli mgmt &= ~SM_SW_FWD_EN; 337967dd82fSFlorian Fainelli 338967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt); 339a424f0deSFlorian Fainelli 3407edc58d6SFlorian Fainelli /* Include IMP port in dumb forwarding mode 341a424f0deSFlorian Fainelli */ 342a424f0deSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, &mgmt); 343a424f0deSFlorian Fainelli mgmt |= B53_MII_DUMB_FWDG_EN; 344a424f0deSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, mgmt); 34553568438SFlorian Fainelli 34653568438SFlorian Fainelli /* Look at B53_UC_FWD_EN and B53_MC_FWD_EN to decide whether 34753568438SFlorian Fainelli * frames should be flooded or not. 34853568438SFlorian Fainelli */ 34953568438SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_IP_MULTICAST_CTRL, &mgmt); 35063cc54a6SFlorian Fainelli mgmt |= B53_UC_FWD_EN | B53_MC_FWD_EN | B53_IPMC_FWD_EN; 35153568438SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_IP_MULTICAST_CTRL, mgmt); 352a424f0deSFlorian Fainelli } 353967dd82fSFlorian Fainelli 354dad8d7c6SFlorian Fainelli static void b53_enable_vlan(struct b53_device *dev, bool enable, 355dad8d7c6SFlorian Fainelli bool enable_filtering) 356967dd82fSFlorian Fainelli { 357967dd82fSFlorian Fainelli u8 mgmt, vc0, vc1, vc4 = 0, vc5; 358967dd82fSFlorian Fainelli 359967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); 360967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL0, &vc0); 361967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL1, &vc1); 362967dd82fSFlorian Fainelli 363967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) { 364967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4); 365967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_25, &vc5); 366967dd82fSFlorian Fainelli } else if (is63xx(dev)) { 367967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_63XX, &vc4); 368967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_63XX, &vc5); 369967dd82fSFlorian Fainelli } else { 370967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, &vc4); 371967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, &vc5); 372967dd82fSFlorian Fainelli } 373967dd82fSFlorian Fainelli 374967dd82fSFlorian Fainelli if (enable) { 375967dd82fSFlorian Fainelli vc0 |= VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID; 376967dd82fSFlorian Fainelli vc1 |= VC1_RX_MCST_UNTAG_EN | VC1_RX_MCST_FWD_EN; 377967dd82fSFlorian Fainelli vc4 &= ~VC4_ING_VID_CHECK_MASK; 378dad8d7c6SFlorian Fainelli if (enable_filtering) { 379967dd82fSFlorian Fainelli vc4 |= VC4_ING_VID_VIO_DROP << VC4_ING_VID_CHECK_S; 380967dd82fSFlorian Fainelli vc5 |= VC5_DROP_VTABLE_MISS; 381dad8d7c6SFlorian Fainelli } else { 382dad8d7c6SFlorian Fainelli vc4 |= VC4_ING_VID_VIO_FWD << VC4_ING_VID_CHECK_S; 383dad8d7c6SFlorian Fainelli vc5 &= ~VC5_DROP_VTABLE_MISS; 384dad8d7c6SFlorian Fainelli } 385967dd82fSFlorian Fainelli 386967dd82fSFlorian Fainelli if (is5325(dev)) 387967dd82fSFlorian Fainelli vc0 &= ~VC0_RESERVED_1; 388967dd82fSFlorian Fainelli 389967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 390967dd82fSFlorian Fainelli vc1 |= VC1_RX_MCST_TAG_EN; 391967dd82fSFlorian Fainelli 392967dd82fSFlorian Fainelli } else { 393967dd82fSFlorian Fainelli vc0 &= ~(VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID); 394967dd82fSFlorian Fainelli vc1 &= ~(VC1_RX_MCST_UNTAG_EN | VC1_RX_MCST_FWD_EN); 395967dd82fSFlorian Fainelli vc4 &= ~VC4_ING_VID_CHECK_MASK; 396967dd82fSFlorian Fainelli vc5 &= ~VC5_DROP_VTABLE_MISS; 397967dd82fSFlorian Fainelli 398967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 399967dd82fSFlorian Fainelli vc4 |= VC4_ING_VID_VIO_FWD << VC4_ING_VID_CHECK_S; 400967dd82fSFlorian Fainelli else 401967dd82fSFlorian Fainelli vc4 |= VC4_ING_VID_VIO_TO_IMP << VC4_ING_VID_CHECK_S; 402967dd82fSFlorian Fainelli 403967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 404967dd82fSFlorian Fainelli vc1 &= ~VC1_RX_MCST_TAG_EN; 405a2482d2cSFlorian Fainelli } 406967dd82fSFlorian Fainelli 407967dd82fSFlorian Fainelli if (!is5325(dev) && !is5365(dev)) 408967dd82fSFlorian Fainelli vc5 &= ~VC5_VID_FFF_EN; 409967dd82fSFlorian Fainelli 410967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL0, vc0); 411967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL1, vc1); 412967dd82fSFlorian Fainelli 413967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) { 414967dd82fSFlorian Fainelli /* enable the high 8 bit vid check on 5325 */ 415967dd82fSFlorian Fainelli if (is5325(dev) && enable) 416967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 417967dd82fSFlorian Fainelli VC3_HIGH_8BIT_EN); 418967dd82fSFlorian Fainelli else 419967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 0); 420967dd82fSFlorian Fainelli 421967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, vc4); 422967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_25, vc5); 423967dd82fSFlorian Fainelli } else if (is63xx(dev)) { 424967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3_63XX, 0); 425967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_63XX, vc4); 426967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_63XX, vc5); 427967dd82fSFlorian Fainelli } else { 428967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 0); 429967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, vc4); 430967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, vc5); 431967dd82fSFlorian Fainelli } 432967dd82fSFlorian Fainelli 433967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt); 434dad8d7c6SFlorian Fainelli 435dad8d7c6SFlorian Fainelli dev->vlan_enabled = enable; 436967dd82fSFlorian Fainelli } 437967dd82fSFlorian Fainelli 438967dd82fSFlorian Fainelli static int b53_set_jumbo(struct b53_device *dev, bool enable, bool allow_10_100) 439967dd82fSFlorian Fainelli { 440967dd82fSFlorian Fainelli u32 port_mask = 0; 441967dd82fSFlorian Fainelli u16 max_size = JMS_MIN_SIZE; 442967dd82fSFlorian Fainelli 443967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 444967dd82fSFlorian Fainelli return -EINVAL; 445967dd82fSFlorian Fainelli 446967dd82fSFlorian Fainelli if (enable) { 447967dd82fSFlorian Fainelli port_mask = dev->enabled_ports; 448967dd82fSFlorian Fainelli max_size = JMS_MAX_SIZE; 449967dd82fSFlorian Fainelli if (allow_10_100) 450967dd82fSFlorian Fainelli port_mask |= JPM_10_100_JUMBO_EN; 451967dd82fSFlorian Fainelli } 452967dd82fSFlorian Fainelli 453967dd82fSFlorian Fainelli b53_write32(dev, B53_JUMBO_PAGE, dev->jumbo_pm_reg, port_mask); 454967dd82fSFlorian Fainelli return b53_write16(dev, B53_JUMBO_PAGE, dev->jumbo_size_reg, max_size); 455967dd82fSFlorian Fainelli } 456967dd82fSFlorian Fainelli 457ff39c2d6SFlorian Fainelli static int b53_flush_arl(struct b53_device *dev, u8 mask) 458967dd82fSFlorian Fainelli { 459967dd82fSFlorian Fainelli unsigned int i; 460967dd82fSFlorian Fainelli 461967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, 462ff39c2d6SFlorian Fainelli FAST_AGE_DONE | FAST_AGE_DYNAMIC | mask); 463967dd82fSFlorian Fainelli 464967dd82fSFlorian Fainelli for (i = 0; i < 10; i++) { 465967dd82fSFlorian Fainelli u8 fast_age_ctrl; 466967dd82fSFlorian Fainelli 467967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, 468967dd82fSFlorian Fainelli &fast_age_ctrl); 469967dd82fSFlorian Fainelli 470967dd82fSFlorian Fainelli if (!(fast_age_ctrl & FAST_AGE_DONE)) 471967dd82fSFlorian Fainelli goto out; 472967dd82fSFlorian Fainelli 473967dd82fSFlorian Fainelli msleep(1); 474967dd82fSFlorian Fainelli } 475967dd82fSFlorian Fainelli 476967dd82fSFlorian Fainelli return -ETIMEDOUT; 477967dd82fSFlorian Fainelli out: 478967dd82fSFlorian Fainelli /* Only age dynamic entries (default behavior) */ 479967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, FAST_AGE_DYNAMIC); 480967dd82fSFlorian Fainelli return 0; 481967dd82fSFlorian Fainelli } 482967dd82fSFlorian Fainelli 483ff39c2d6SFlorian Fainelli static int b53_fast_age_port(struct b53_device *dev, int port) 484ff39c2d6SFlorian Fainelli { 485ff39c2d6SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_PORT_CTRL, port); 486ff39c2d6SFlorian Fainelli 487ff39c2d6SFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_PORT); 488ff39c2d6SFlorian Fainelli } 489ff39c2d6SFlorian Fainelli 490a2482d2cSFlorian Fainelli static int b53_fast_age_vlan(struct b53_device *dev, u16 vid) 491a2482d2cSFlorian Fainelli { 492a2482d2cSFlorian Fainelli b53_write16(dev, B53_CTRL_PAGE, B53_FAST_AGE_VID_CTRL, vid); 493a2482d2cSFlorian Fainelli 494a2482d2cSFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_VLAN); 495a2482d2cSFlorian Fainelli } 496a2482d2cSFlorian Fainelli 497aac02867SFlorian Fainelli void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port) 498ff39c2d6SFlorian Fainelli { 49904bed143SVivien Didelot struct b53_device *dev = ds->priv; 500ff39c2d6SFlorian Fainelli unsigned int i; 501ff39c2d6SFlorian Fainelli u16 pvlan; 502ff39c2d6SFlorian Fainelli 503ff39c2d6SFlorian Fainelli /* Enable the IMP port to be in the same VLAN as the other ports 504ff39c2d6SFlorian Fainelli * on a per-port basis such that we only have Port i and IMP in 505ff39c2d6SFlorian Fainelli * the same VLAN. 506ff39c2d6SFlorian Fainelli */ 507ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) { 508ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &pvlan); 509ff39c2d6SFlorian Fainelli pvlan |= BIT(cpu_port); 510ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), pvlan); 511ff39c2d6SFlorian Fainelli } 512ff39c2d6SFlorian Fainelli } 513aac02867SFlorian Fainelli EXPORT_SYMBOL(b53_imp_vlan_setup); 514ff39c2d6SFlorian Fainelli 515f86ad77fSFlorian Fainelli int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy) 516967dd82fSFlorian Fainelli { 51704bed143SVivien Didelot struct b53_device *dev = ds->priv; 51874be4babSVivien Didelot unsigned int cpu_port; 5198ca7c160SFlorian Fainelli int ret = 0; 520ff39c2d6SFlorian Fainelli u16 pvlan; 521967dd82fSFlorian Fainelli 52274be4babSVivien Didelot if (!dsa_is_user_port(ds, port)) 52374be4babSVivien Didelot return 0; 52474be4babSVivien Didelot 52568bb8ea8SVivien Didelot cpu_port = dsa_to_port(ds, port)->cpu_dp->index; 52674be4babSVivien Didelot 52763cc54a6SFlorian Fainelli b53_br_egress_floods(ds, port, true, true); 52863cc54a6SFlorian Fainelli 5298ca7c160SFlorian Fainelli if (dev->ops->irq_enable) 5308ca7c160SFlorian Fainelli ret = dev->ops->irq_enable(dev, port); 5318ca7c160SFlorian Fainelli if (ret) 5328ca7c160SFlorian Fainelli return ret; 5338ca7c160SFlorian Fainelli 534967dd82fSFlorian Fainelli /* Clear the Rx and Tx disable bits and set to no spanning tree */ 535967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), 0); 536967dd82fSFlorian Fainelli 537ff39c2d6SFlorian Fainelli /* Set this port, and only this one to be in the default VLAN, 538ff39c2d6SFlorian Fainelli * if member of a bridge, restore its membership prior to 539ff39c2d6SFlorian Fainelli * bringing down this port. 540ff39c2d6SFlorian Fainelli */ 541ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); 542ff39c2d6SFlorian Fainelli pvlan &= ~0x1ff; 543ff39c2d6SFlorian Fainelli pvlan |= BIT(port); 544ff39c2d6SFlorian Fainelli pvlan |= dev->ports[port].vlan_ctl_mask; 545ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); 546ff39c2d6SFlorian Fainelli 547ff39c2d6SFlorian Fainelli b53_imp_vlan_setup(ds, cpu_port); 548ff39c2d6SFlorian Fainelli 549f43a2dbeSFlorian Fainelli /* If EEE was enabled, restore it */ 550f43a2dbeSFlorian Fainelli if (dev->ports[port].eee.eee_enabled) 551f43a2dbeSFlorian Fainelli b53_eee_enable_set(ds, port, true); 552f43a2dbeSFlorian Fainelli 553967dd82fSFlorian Fainelli return 0; 554967dd82fSFlorian Fainelli } 555f86ad77fSFlorian Fainelli EXPORT_SYMBOL(b53_enable_port); 556967dd82fSFlorian Fainelli 55775104db0SAndrew Lunn void b53_disable_port(struct dsa_switch *ds, int port) 558967dd82fSFlorian Fainelli { 55904bed143SVivien Didelot struct b53_device *dev = ds->priv; 560967dd82fSFlorian Fainelli u8 reg; 561967dd82fSFlorian Fainelli 562967dd82fSFlorian Fainelli /* Disable Tx/Rx for the port */ 563967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), ®); 564967dd82fSFlorian Fainelli reg |= PORT_CTRL_RX_DISABLE | PORT_CTRL_TX_DISABLE; 565967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg); 5668ca7c160SFlorian Fainelli 5678ca7c160SFlorian Fainelli if (dev->ops->irq_disable) 5688ca7c160SFlorian Fainelli dev->ops->irq_disable(dev, port); 569967dd82fSFlorian Fainelli } 570f86ad77fSFlorian Fainelli EXPORT_SYMBOL(b53_disable_port); 571967dd82fSFlorian Fainelli 572b409a9efSFlorian Fainelli void b53_brcm_hdr_setup(struct dsa_switch *ds, int port) 573b409a9efSFlorian Fainelli { 574b409a9efSFlorian Fainelli struct b53_device *dev = ds->priv; 5754d776482SFlorian Fainelli bool tag_en = !(dev->tag_protocol == DSA_TAG_PROTO_NONE); 576b409a9efSFlorian Fainelli u8 hdr_ctl, val; 577b409a9efSFlorian Fainelli u16 reg; 578b409a9efSFlorian Fainelli 579b409a9efSFlorian Fainelli /* Resolve which bit controls the Broadcom tag */ 580b409a9efSFlorian Fainelli switch (port) { 581b409a9efSFlorian Fainelli case 8: 582b409a9efSFlorian Fainelli val = BRCM_HDR_P8_EN; 583b409a9efSFlorian Fainelli break; 584b409a9efSFlorian Fainelli case 7: 585b409a9efSFlorian Fainelli val = BRCM_HDR_P7_EN; 586b409a9efSFlorian Fainelli break; 587b409a9efSFlorian Fainelli case 5: 588b409a9efSFlorian Fainelli val = BRCM_HDR_P5_EN; 589b409a9efSFlorian Fainelli break; 590b409a9efSFlorian Fainelli default: 591b409a9efSFlorian Fainelli val = 0; 592b409a9efSFlorian Fainelli break; 593b409a9efSFlorian Fainelli } 594b409a9efSFlorian Fainelli 5958fab459eSFlorian Fainelli /* Enable management mode if tagging is requested */ 5968fab459eSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &hdr_ctl); 5978fab459eSFlorian Fainelli if (tag_en) 5988fab459eSFlorian Fainelli hdr_ctl |= SM_SW_FWD_MODE; 5998fab459eSFlorian Fainelli else 6008fab459eSFlorian Fainelli hdr_ctl &= ~SM_SW_FWD_MODE; 6018fab459eSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, hdr_ctl); 6028fab459eSFlorian Fainelli 6038fab459eSFlorian Fainelli /* Configure the appropriate IMP port */ 6048fab459eSFlorian Fainelli b53_read8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &hdr_ctl); 6058fab459eSFlorian Fainelli if (port == 8) 6068fab459eSFlorian Fainelli hdr_ctl |= GC_FRM_MGMT_PORT_MII; 6078fab459eSFlorian Fainelli else if (port == 5) 6088fab459eSFlorian Fainelli hdr_ctl |= GC_FRM_MGMT_PORT_M; 6098fab459eSFlorian Fainelli b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, hdr_ctl); 6108fab459eSFlorian Fainelli 611b409a9efSFlorian Fainelli /* Enable Broadcom tags for IMP port */ 612b409a9efSFlorian Fainelli b53_read8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, &hdr_ctl); 613cdb583cfSFlorian Fainelli if (tag_en) 614b409a9efSFlorian Fainelli hdr_ctl |= val; 615cdb583cfSFlorian Fainelli else 616cdb583cfSFlorian Fainelli hdr_ctl &= ~val; 617b409a9efSFlorian Fainelli b53_write8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, hdr_ctl); 618b409a9efSFlorian Fainelli 619b409a9efSFlorian Fainelli /* Registers below are only accessible on newer devices */ 620b409a9efSFlorian Fainelli if (!is58xx(dev)) 621b409a9efSFlorian Fainelli return; 622b409a9efSFlorian Fainelli 623b409a9efSFlorian Fainelli /* Enable reception Broadcom tag for CPU TX (switch RX) to 624b409a9efSFlorian Fainelli * allow us to tag outgoing frames 625b409a9efSFlorian Fainelli */ 626b409a9efSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, ®); 627cdb583cfSFlorian Fainelli if (tag_en) 628b409a9efSFlorian Fainelli reg &= ~BIT(port); 629cdb583cfSFlorian Fainelli else 630cdb583cfSFlorian Fainelli reg |= BIT(port); 631b409a9efSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, reg); 632b409a9efSFlorian Fainelli 633b409a9efSFlorian Fainelli /* Enable transmission of Broadcom tags from the switch (CPU RX) to 634b409a9efSFlorian Fainelli * allow delivering frames to the per-port net_devices 635b409a9efSFlorian Fainelli */ 636b409a9efSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, ®); 637cdb583cfSFlorian Fainelli if (tag_en) 638b409a9efSFlorian Fainelli reg &= ~BIT(port); 639cdb583cfSFlorian Fainelli else 640cdb583cfSFlorian Fainelli reg |= BIT(port); 641b409a9efSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, reg); 642b409a9efSFlorian Fainelli } 643b409a9efSFlorian Fainelli EXPORT_SYMBOL(b53_brcm_hdr_setup); 644b409a9efSFlorian Fainelli 645299752a7SFlorian Fainelli static void b53_enable_cpu_port(struct b53_device *dev, int port) 646967dd82fSFlorian Fainelli { 647967dd82fSFlorian Fainelli u8 port_ctrl; 648967dd82fSFlorian Fainelli 649967dd82fSFlorian Fainelli /* BCM5325 CPU port is at 8 */ 650299752a7SFlorian Fainelli if ((is5325(dev) || is5365(dev)) && port == B53_CPU_PORT_25) 651299752a7SFlorian Fainelli port = B53_CPU_PORT; 652967dd82fSFlorian Fainelli 653967dd82fSFlorian Fainelli port_ctrl = PORT_CTRL_RX_BCST_EN | 654967dd82fSFlorian Fainelli PORT_CTRL_RX_MCST_EN | 655967dd82fSFlorian Fainelli PORT_CTRL_RX_UCST_EN; 656299752a7SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), port_ctrl); 6577edc58d6SFlorian Fainelli 6587edc58d6SFlorian Fainelli b53_brcm_hdr_setup(dev->ds, port); 65963cc54a6SFlorian Fainelli 66063cc54a6SFlorian Fainelli b53_br_egress_floods(dev->ds, port, true, true); 661967dd82fSFlorian Fainelli } 662967dd82fSFlorian Fainelli 663967dd82fSFlorian Fainelli static void b53_enable_mib(struct b53_device *dev) 664967dd82fSFlorian Fainelli { 665967dd82fSFlorian Fainelli u8 gc; 666967dd82fSFlorian Fainelli 667967dd82fSFlorian Fainelli b53_read8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc); 668967dd82fSFlorian Fainelli gc &= ~(GC_RESET_MIB | GC_MIB_AC_EN); 669967dd82fSFlorian Fainelli b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc); 670967dd82fSFlorian Fainelli } 671967dd82fSFlorian Fainelli 672fea83353SFlorian Fainelli static u16 b53_default_pvid(struct b53_device *dev) 673fea83353SFlorian Fainelli { 674fea83353SFlorian Fainelli if (is5325(dev) || is5365(dev)) 675fea83353SFlorian Fainelli return 1; 676fea83353SFlorian Fainelli else 677fea83353SFlorian Fainelli return 0; 678fea83353SFlorian Fainelli } 679fea83353SFlorian Fainelli 6805c1a6eafSFlorian Fainelli int b53_configure_vlan(struct dsa_switch *ds) 681967dd82fSFlorian Fainelli { 6825c1a6eafSFlorian Fainelli struct b53_device *dev = ds->priv; 683a2482d2cSFlorian Fainelli struct b53_vlan vl = { 0 }; 684d7a0b1f7SFlorian Fainelli struct b53_vlan *v; 685fea83353SFlorian Fainelli int i, def_vid; 686d7a0b1f7SFlorian Fainelli u16 vid; 687fea83353SFlorian Fainelli 688fea83353SFlorian Fainelli def_vid = b53_default_pvid(dev); 689967dd82fSFlorian Fainelli 690967dd82fSFlorian Fainelli /* clear all vlan entries */ 691967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) { 692fea83353SFlorian Fainelli for (i = def_vid; i < dev->num_vlans; i++) 693a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, i, &vl); 694967dd82fSFlorian Fainelli } else { 695967dd82fSFlorian Fainelli b53_do_vlan_op(dev, VTA_CMD_CLEAR); 696967dd82fSFlorian Fainelli } 697967dd82fSFlorian Fainelli 698df373702SFlorian Fainelli b53_enable_vlan(dev, dev->vlan_enabled, ds->vlan_filtering); 699967dd82fSFlorian Fainelli 700967dd82fSFlorian Fainelli b53_for_each_port(dev, i) 701967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, 702fea83353SFlorian Fainelli B53_VLAN_PORT_DEF_TAG(i), def_vid); 703967dd82fSFlorian Fainelli 704d7a0b1f7SFlorian Fainelli /* Upon initial call we have not set-up any VLANs, but upon 705d7a0b1f7SFlorian Fainelli * system resume, we need to restore all VLAN entries. 706d7a0b1f7SFlorian Fainelli */ 707d7a0b1f7SFlorian Fainelli for (vid = def_vid; vid < dev->num_vlans; vid++) { 708d7a0b1f7SFlorian Fainelli v = &dev->vlans[vid]; 709d7a0b1f7SFlorian Fainelli 710d7a0b1f7SFlorian Fainelli if (!v->members) 711d7a0b1f7SFlorian Fainelli continue; 712d7a0b1f7SFlorian Fainelli 713d7a0b1f7SFlorian Fainelli b53_set_vlan_entry(dev, vid, v); 714d7a0b1f7SFlorian Fainelli b53_fast_age_vlan(dev, vid); 715d7a0b1f7SFlorian Fainelli } 716d7a0b1f7SFlorian Fainelli 717967dd82fSFlorian Fainelli return 0; 718967dd82fSFlorian Fainelli } 7195c1a6eafSFlorian Fainelli EXPORT_SYMBOL(b53_configure_vlan); 720967dd82fSFlorian Fainelli 721967dd82fSFlorian Fainelli static void b53_switch_reset_gpio(struct b53_device *dev) 722967dd82fSFlorian Fainelli { 723967dd82fSFlorian Fainelli int gpio = dev->reset_gpio; 724967dd82fSFlorian Fainelli 725967dd82fSFlorian Fainelli if (gpio < 0) 726967dd82fSFlorian Fainelli return; 727967dd82fSFlorian Fainelli 728967dd82fSFlorian Fainelli /* Reset sequence: RESET low(50ms)->high(20ms) 729967dd82fSFlorian Fainelli */ 730967dd82fSFlorian Fainelli gpio_set_value(gpio, 0); 731967dd82fSFlorian Fainelli mdelay(50); 732967dd82fSFlorian Fainelli 733967dd82fSFlorian Fainelli gpio_set_value(gpio, 1); 734967dd82fSFlorian Fainelli mdelay(20); 735967dd82fSFlorian Fainelli 736967dd82fSFlorian Fainelli dev->current_page = 0xff; 737967dd82fSFlorian Fainelli } 738967dd82fSFlorian Fainelli 739967dd82fSFlorian Fainelli static int b53_switch_reset(struct b53_device *dev) 740967dd82fSFlorian Fainelli { 7413fb22b05SFlorian Fainelli unsigned int timeout = 1000; 7423fb22b05SFlorian Fainelli u8 mgmt, reg; 743967dd82fSFlorian Fainelli 744967dd82fSFlorian Fainelli b53_switch_reset_gpio(dev); 745967dd82fSFlorian Fainelli 746967dd82fSFlorian Fainelli if (is539x(dev)) { 747967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x83); 748967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x00); 749967dd82fSFlorian Fainelli } 750967dd82fSFlorian Fainelli 7513fb22b05SFlorian Fainelli /* This is specific to 58xx devices here, do not use is58xx() which 7523fb22b05SFlorian Fainelli * covers the larger Starfigther 2 family, including 7445/7278 which 7533fb22b05SFlorian Fainelli * still use this driver as a library and need to perform the reset 7543fb22b05SFlorian Fainelli * earlier. 7553fb22b05SFlorian Fainelli */ 7565040cc99SArun Parameswaran if (dev->chip_id == BCM58XX_DEVICE_ID || 7575040cc99SArun Parameswaran dev->chip_id == BCM583XX_DEVICE_ID) { 7583fb22b05SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, ®); 7593fb22b05SFlorian Fainelli reg |= SW_RST | EN_SW_RST | EN_CH_RST; 7603fb22b05SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, reg); 7613fb22b05SFlorian Fainelli 7623fb22b05SFlorian Fainelli do { 7633fb22b05SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, ®); 7643fb22b05SFlorian Fainelli if (!(reg & SW_RST)) 7653fb22b05SFlorian Fainelli break; 7663fb22b05SFlorian Fainelli 7673fb22b05SFlorian Fainelli usleep_range(1000, 2000); 7683fb22b05SFlorian Fainelli } while (timeout-- > 0); 7693fb22b05SFlorian Fainelli 7703fb22b05SFlorian Fainelli if (timeout == 0) 7713fb22b05SFlorian Fainelli return -ETIMEDOUT; 7723fb22b05SFlorian Fainelli } 7733fb22b05SFlorian Fainelli 774967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); 775967dd82fSFlorian Fainelli 776967dd82fSFlorian Fainelli if (!(mgmt & SM_SW_FWD_EN)) { 777967dd82fSFlorian Fainelli mgmt &= ~SM_SW_FWD_MODE; 778967dd82fSFlorian Fainelli mgmt |= SM_SW_FWD_EN; 779967dd82fSFlorian Fainelli 780967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt); 781967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); 782967dd82fSFlorian Fainelli 783967dd82fSFlorian Fainelli if (!(mgmt & SM_SW_FWD_EN)) { 784967dd82fSFlorian Fainelli dev_err(dev->dev, "Failed to enable switch!\n"); 785967dd82fSFlorian Fainelli return -EINVAL; 786967dd82fSFlorian Fainelli } 787967dd82fSFlorian Fainelli } 788967dd82fSFlorian Fainelli 789967dd82fSFlorian Fainelli b53_enable_mib(dev); 790967dd82fSFlorian Fainelli 791ff39c2d6SFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_STATIC); 792967dd82fSFlorian Fainelli } 793967dd82fSFlorian Fainelli 794967dd82fSFlorian Fainelli static int b53_phy_read16(struct dsa_switch *ds, int addr, int reg) 795967dd82fSFlorian Fainelli { 79604bed143SVivien Didelot struct b53_device *priv = ds->priv; 797967dd82fSFlorian Fainelli u16 value = 0; 798967dd82fSFlorian Fainelli int ret; 799967dd82fSFlorian Fainelli 800967dd82fSFlorian Fainelli if (priv->ops->phy_read16) 801967dd82fSFlorian Fainelli ret = priv->ops->phy_read16(priv, addr, reg, &value); 802967dd82fSFlorian Fainelli else 803967dd82fSFlorian Fainelli ret = b53_read16(priv, B53_PORT_MII_PAGE(addr), 804967dd82fSFlorian Fainelli reg * 2, &value); 805967dd82fSFlorian Fainelli 806967dd82fSFlorian Fainelli return ret ? ret : value; 807967dd82fSFlorian Fainelli } 808967dd82fSFlorian Fainelli 809967dd82fSFlorian Fainelli static int b53_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val) 810967dd82fSFlorian Fainelli { 81104bed143SVivien Didelot struct b53_device *priv = ds->priv; 812967dd82fSFlorian Fainelli 813967dd82fSFlorian Fainelli if (priv->ops->phy_write16) 814967dd82fSFlorian Fainelli return priv->ops->phy_write16(priv, addr, reg, val); 815967dd82fSFlorian Fainelli 816967dd82fSFlorian Fainelli return b53_write16(priv, B53_PORT_MII_PAGE(addr), reg * 2, val); 817967dd82fSFlorian Fainelli } 818967dd82fSFlorian Fainelli 819967dd82fSFlorian Fainelli static int b53_reset_switch(struct b53_device *priv) 820967dd82fSFlorian Fainelli { 821967dd82fSFlorian Fainelli /* reset vlans */ 822a2482d2cSFlorian Fainelli memset(priv->vlans, 0, sizeof(*priv->vlans) * priv->num_vlans); 823967dd82fSFlorian Fainelli memset(priv->ports, 0, sizeof(*priv->ports) * priv->num_ports); 824967dd82fSFlorian Fainelli 8250e01491dSFlorian Fainelli priv->serdes_lane = B53_INVALID_LANE; 8260e01491dSFlorian Fainelli 827967dd82fSFlorian Fainelli return b53_switch_reset(priv); 828967dd82fSFlorian Fainelli } 829967dd82fSFlorian Fainelli 830967dd82fSFlorian Fainelli static int b53_apply_config(struct b53_device *priv) 831967dd82fSFlorian Fainelli { 832967dd82fSFlorian Fainelli /* disable switching */ 833967dd82fSFlorian Fainelli b53_set_forwarding(priv, 0); 834967dd82fSFlorian Fainelli 8355c1a6eafSFlorian Fainelli b53_configure_vlan(priv->ds); 836967dd82fSFlorian Fainelli 837967dd82fSFlorian Fainelli /* enable switching */ 838967dd82fSFlorian Fainelli b53_set_forwarding(priv, 1); 839967dd82fSFlorian Fainelli 840967dd82fSFlorian Fainelli return 0; 841967dd82fSFlorian Fainelli } 842967dd82fSFlorian Fainelli 843967dd82fSFlorian Fainelli static void b53_reset_mib(struct b53_device *priv) 844967dd82fSFlorian Fainelli { 845967dd82fSFlorian Fainelli u8 gc; 846967dd82fSFlorian Fainelli 847967dd82fSFlorian Fainelli b53_read8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc); 848967dd82fSFlorian Fainelli 849967dd82fSFlorian Fainelli b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc | GC_RESET_MIB); 850967dd82fSFlorian Fainelli msleep(1); 851967dd82fSFlorian Fainelli b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc & ~GC_RESET_MIB); 852967dd82fSFlorian Fainelli msleep(1); 853967dd82fSFlorian Fainelli } 854967dd82fSFlorian Fainelli 855967dd82fSFlorian Fainelli static const struct b53_mib_desc *b53_get_mib(struct b53_device *dev) 856967dd82fSFlorian Fainelli { 857967dd82fSFlorian Fainelli if (is5365(dev)) 858967dd82fSFlorian Fainelli return b53_mibs_65; 859967dd82fSFlorian Fainelli else if (is63xx(dev)) 860967dd82fSFlorian Fainelli return b53_mibs_63xx; 861bde5d132SFlorian Fainelli else if (is58xx(dev)) 862bde5d132SFlorian Fainelli return b53_mibs_58xx; 863967dd82fSFlorian Fainelli else 864967dd82fSFlorian Fainelli return b53_mibs; 865967dd82fSFlorian Fainelli } 866967dd82fSFlorian Fainelli 867967dd82fSFlorian Fainelli static unsigned int b53_get_mib_size(struct b53_device *dev) 868967dd82fSFlorian Fainelli { 869967dd82fSFlorian Fainelli if (is5365(dev)) 870967dd82fSFlorian Fainelli return B53_MIBS_65_SIZE; 871967dd82fSFlorian Fainelli else if (is63xx(dev)) 872967dd82fSFlorian Fainelli return B53_MIBS_63XX_SIZE; 873bde5d132SFlorian Fainelli else if (is58xx(dev)) 874bde5d132SFlorian Fainelli return B53_MIBS_58XX_SIZE; 875967dd82fSFlorian Fainelli else 876967dd82fSFlorian Fainelli return B53_MIBS_SIZE; 877967dd82fSFlorian Fainelli } 878967dd82fSFlorian Fainelli 879c7d28c9dSFlorian Fainelli static struct phy_device *b53_get_phy_device(struct dsa_switch *ds, int port) 880c7d28c9dSFlorian Fainelli { 881c7d28c9dSFlorian Fainelli /* These ports typically do not have built-in PHYs */ 882c7d28c9dSFlorian Fainelli switch (port) { 883c7d28c9dSFlorian Fainelli case B53_CPU_PORT_25: 884c7d28c9dSFlorian Fainelli case 7: 885c7d28c9dSFlorian Fainelli case B53_CPU_PORT: 886c7d28c9dSFlorian Fainelli return NULL; 887c7d28c9dSFlorian Fainelli } 888c7d28c9dSFlorian Fainelli 889c7d28c9dSFlorian Fainelli return mdiobus_get_phy(ds->slave_mii_bus, port); 890c7d28c9dSFlorian Fainelli } 891c7d28c9dSFlorian Fainelli 89289f09048SFlorian Fainelli void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset, 89389f09048SFlorian Fainelli uint8_t *data) 894967dd82fSFlorian Fainelli { 89504bed143SVivien Didelot struct b53_device *dev = ds->priv; 896967dd82fSFlorian Fainelli const struct b53_mib_desc *mibs = b53_get_mib(dev); 897967dd82fSFlorian Fainelli unsigned int mib_size = b53_get_mib_size(dev); 898c7d28c9dSFlorian Fainelli struct phy_device *phydev; 899967dd82fSFlorian Fainelli unsigned int i; 900967dd82fSFlorian Fainelli 901c7d28c9dSFlorian Fainelli if (stringset == ETH_SS_STATS) { 902967dd82fSFlorian Fainelli for (i = 0; i < mib_size; i++) 903cd526676SFlorian Fainelli strlcpy(data + i * ETH_GSTRING_LEN, 904967dd82fSFlorian Fainelli mibs[i].name, ETH_GSTRING_LEN); 905c7d28c9dSFlorian Fainelli } else if (stringset == ETH_SS_PHY_STATS) { 906c7d28c9dSFlorian Fainelli phydev = b53_get_phy_device(ds, port); 907c7d28c9dSFlorian Fainelli if (!phydev) 908c7d28c9dSFlorian Fainelli return; 909c7d28c9dSFlorian Fainelli 910c7d28c9dSFlorian Fainelli phy_ethtool_get_strings(phydev, data); 911c7d28c9dSFlorian Fainelli } 912967dd82fSFlorian Fainelli } 9133117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_strings); 914967dd82fSFlorian Fainelli 9153117455dSFlorian Fainelli void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data) 916967dd82fSFlorian Fainelli { 91704bed143SVivien Didelot struct b53_device *dev = ds->priv; 918967dd82fSFlorian Fainelli const struct b53_mib_desc *mibs = b53_get_mib(dev); 919967dd82fSFlorian Fainelli unsigned int mib_size = b53_get_mib_size(dev); 920967dd82fSFlorian Fainelli const struct b53_mib_desc *s; 921967dd82fSFlorian Fainelli unsigned int i; 922967dd82fSFlorian Fainelli u64 val = 0; 923967dd82fSFlorian Fainelli 924967dd82fSFlorian Fainelli if (is5365(dev) && port == 5) 925967dd82fSFlorian Fainelli port = 8; 926967dd82fSFlorian Fainelli 927967dd82fSFlorian Fainelli mutex_lock(&dev->stats_mutex); 928967dd82fSFlorian Fainelli 929967dd82fSFlorian Fainelli for (i = 0; i < mib_size; i++) { 930967dd82fSFlorian Fainelli s = &mibs[i]; 931967dd82fSFlorian Fainelli 93251dca8a1SFlorian Fainelli if (s->size == 8) { 933967dd82fSFlorian Fainelli b53_read64(dev, B53_MIB_PAGE(port), s->offset, &val); 934967dd82fSFlorian Fainelli } else { 935967dd82fSFlorian Fainelli u32 val32; 936967dd82fSFlorian Fainelli 937967dd82fSFlorian Fainelli b53_read32(dev, B53_MIB_PAGE(port), s->offset, 938967dd82fSFlorian Fainelli &val32); 939967dd82fSFlorian Fainelli val = val32; 940967dd82fSFlorian Fainelli } 941967dd82fSFlorian Fainelli data[i] = (u64)val; 942967dd82fSFlorian Fainelli } 943967dd82fSFlorian Fainelli 944967dd82fSFlorian Fainelli mutex_unlock(&dev->stats_mutex); 945967dd82fSFlorian Fainelli } 9463117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_ethtool_stats); 947967dd82fSFlorian Fainelli 948c7d28c9dSFlorian Fainelli void b53_get_ethtool_phy_stats(struct dsa_switch *ds, int port, uint64_t *data) 949c7d28c9dSFlorian Fainelli { 950c7d28c9dSFlorian Fainelli struct phy_device *phydev; 951c7d28c9dSFlorian Fainelli 952c7d28c9dSFlorian Fainelli phydev = b53_get_phy_device(ds, port); 953c7d28c9dSFlorian Fainelli if (!phydev) 954c7d28c9dSFlorian Fainelli return; 955c7d28c9dSFlorian Fainelli 956c7d28c9dSFlorian Fainelli phy_ethtool_get_stats(phydev, NULL, data); 957c7d28c9dSFlorian Fainelli } 958c7d28c9dSFlorian Fainelli EXPORT_SYMBOL(b53_get_ethtool_phy_stats); 959c7d28c9dSFlorian Fainelli 96089f09048SFlorian Fainelli int b53_get_sset_count(struct dsa_switch *ds, int port, int sset) 961967dd82fSFlorian Fainelli { 96204bed143SVivien Didelot struct b53_device *dev = ds->priv; 963c7d28c9dSFlorian Fainelli struct phy_device *phydev; 964967dd82fSFlorian Fainelli 965c7d28c9dSFlorian Fainelli if (sset == ETH_SS_STATS) { 966c7d28c9dSFlorian Fainelli return b53_get_mib_size(dev); 967c7d28c9dSFlorian Fainelli } else if (sset == ETH_SS_PHY_STATS) { 968c7d28c9dSFlorian Fainelli phydev = b53_get_phy_device(ds, port); 969c7d28c9dSFlorian Fainelli if (!phydev) 97089f09048SFlorian Fainelli return 0; 97189f09048SFlorian Fainelli 972c7d28c9dSFlorian Fainelli return phy_ethtool_get_sset_count(phydev); 973c7d28c9dSFlorian Fainelli } 974c7d28c9dSFlorian Fainelli 975c7d28c9dSFlorian Fainelli return 0; 976967dd82fSFlorian Fainelli } 9773117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_sset_count); 978967dd82fSFlorian Fainelli 979967dd82fSFlorian Fainelli static int b53_setup(struct dsa_switch *ds) 980967dd82fSFlorian Fainelli { 98104bed143SVivien Didelot struct b53_device *dev = ds->priv; 982967dd82fSFlorian Fainelli unsigned int port; 983967dd82fSFlorian Fainelli int ret; 984967dd82fSFlorian Fainelli 985967dd82fSFlorian Fainelli ret = b53_reset_switch(dev); 986967dd82fSFlorian Fainelli if (ret) { 987967dd82fSFlorian Fainelli dev_err(ds->dev, "failed to reset switch\n"); 988967dd82fSFlorian Fainelli return ret; 989967dd82fSFlorian Fainelli } 990967dd82fSFlorian Fainelli 991967dd82fSFlorian Fainelli b53_reset_mib(dev); 992967dd82fSFlorian Fainelli 993967dd82fSFlorian Fainelli ret = b53_apply_config(dev); 994967dd82fSFlorian Fainelli if (ret) 995967dd82fSFlorian Fainelli dev_err(ds->dev, "failed to apply configuration\n"); 996967dd82fSFlorian Fainelli 99775dad252SBenedikt Spranger /* Configure IMP/CPU port, disable all other ports. Enabled 99834c8befdSFlorian Fainelli * ports will be configured with .port_enable 99934c8befdSFlorian Fainelli */ 1000967dd82fSFlorian Fainelli for (port = 0; port < dev->num_ports; port++) { 100134c8befdSFlorian Fainelli if (dsa_is_cpu_port(ds, port)) 1002299752a7SFlorian Fainelli b53_enable_cpu_port(dev, port); 100375dad252SBenedikt Spranger else 100475104db0SAndrew Lunn b53_disable_port(ds, port); 1005967dd82fSFlorian Fainelli } 1006967dd82fSFlorian Fainelli 10077228b23eSVladimir Oltean /* Let DSA handle the case were multiple bridges span the same switch 10087228b23eSVladimir Oltean * device and different VLAN awareness settings are requested, which 10097228b23eSVladimir Oltean * would be breaking filtering semantics for any of the other bridge 10107228b23eSVladimir Oltean * devices. (not hardware supported) 10117228b23eSVladimir Oltean */ 10127228b23eSVladimir Oltean ds->vlan_filtering_is_global = true; 10137228b23eSVladimir Oltean 1014967dd82fSFlorian Fainelli return ret; 1015967dd82fSFlorian Fainelli } 1016967dd82fSFlorian Fainelli 10175e004460SFlorian Fainelli static void b53_force_link(struct b53_device *dev, int port, int link) 1018967dd82fSFlorian Fainelli { 10195e004460SFlorian Fainelli u8 reg, val, off; 1020967dd82fSFlorian Fainelli 1021967dd82fSFlorian Fainelli /* Override the port settings */ 1022967dd82fSFlorian Fainelli if (port == dev->cpu_port) { 1023967dd82fSFlorian Fainelli off = B53_PORT_OVERRIDE_CTRL; 10245e004460SFlorian Fainelli val = PORT_OVERRIDE_EN; 1025967dd82fSFlorian Fainelli } else { 1026967dd82fSFlorian Fainelli off = B53_GMII_PORT_OVERRIDE_CTRL(port); 10275e004460SFlorian Fainelli val = GMII_PO_EN; 1028967dd82fSFlorian Fainelli } 1029967dd82fSFlorian Fainelli 10305e004460SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, off, ®); 10315e004460SFlorian Fainelli reg |= val; 10325e004460SFlorian Fainelli if (link) 1033967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_LINK; 10345e004460SFlorian Fainelli else 10355e004460SFlorian Fainelli reg &= ~PORT_OVERRIDE_LINK; 10365e004460SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, off, reg); 10375e004460SFlorian Fainelli } 1038967dd82fSFlorian Fainelli 10395e004460SFlorian Fainelli static void b53_force_port_config(struct b53_device *dev, int port, 10405e004460SFlorian Fainelli int speed, int duplex, int pause) 10415e004460SFlorian Fainelli { 10425e004460SFlorian Fainelli u8 reg, val, off; 10435e004460SFlorian Fainelli 10445e004460SFlorian Fainelli /* Override the port settings */ 10455e004460SFlorian Fainelli if (port == dev->cpu_port) { 10465e004460SFlorian Fainelli off = B53_PORT_OVERRIDE_CTRL; 10475e004460SFlorian Fainelli val = PORT_OVERRIDE_EN; 10485e004460SFlorian Fainelli } else { 10495e004460SFlorian Fainelli off = B53_GMII_PORT_OVERRIDE_CTRL(port); 10505e004460SFlorian Fainelli val = GMII_PO_EN; 10515e004460SFlorian Fainelli } 10525e004460SFlorian Fainelli 10535e004460SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, off, ®); 10545e004460SFlorian Fainelli reg |= val; 10555e004460SFlorian Fainelli if (duplex == DUPLEX_FULL) 1056967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_FULL_DUPLEX; 10575e004460SFlorian Fainelli else 10585e004460SFlorian Fainelli reg &= ~PORT_OVERRIDE_FULL_DUPLEX; 1059967dd82fSFlorian Fainelli 10605e004460SFlorian Fainelli switch (speed) { 1061967dd82fSFlorian Fainelli case 2000: 1062967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_2000M; 1063967dd82fSFlorian Fainelli /* fallthrough */ 1064967dd82fSFlorian Fainelli case SPEED_1000: 1065967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_1000M; 1066967dd82fSFlorian Fainelli break; 1067967dd82fSFlorian Fainelli case SPEED_100: 1068967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_100M; 1069967dd82fSFlorian Fainelli break; 1070967dd82fSFlorian Fainelli case SPEED_10: 1071967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_10M; 1072967dd82fSFlorian Fainelli break; 1073967dd82fSFlorian Fainelli default: 10745e004460SFlorian Fainelli dev_err(dev->dev, "unknown speed: %d\n", speed); 1075967dd82fSFlorian Fainelli return; 1076967dd82fSFlorian Fainelli } 1077967dd82fSFlorian Fainelli 10785e004460SFlorian Fainelli if (pause & MLO_PAUSE_RX) 10795e004460SFlorian Fainelli reg |= PORT_OVERRIDE_RX_FLOW; 10805e004460SFlorian Fainelli if (pause & MLO_PAUSE_TX) 10815e004460SFlorian Fainelli reg |= PORT_OVERRIDE_TX_FLOW; 10825e004460SFlorian Fainelli 10835e004460SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, off, reg); 10845e004460SFlorian Fainelli } 10855e004460SFlorian Fainelli 10865e004460SFlorian Fainelli static void b53_adjust_link(struct dsa_switch *ds, int port, 10875e004460SFlorian Fainelli struct phy_device *phydev) 10885e004460SFlorian Fainelli { 10895e004460SFlorian Fainelli struct b53_device *dev = ds->priv; 10905e004460SFlorian Fainelli struct ethtool_eee *p = &dev->ports[port].eee; 10915e004460SFlorian Fainelli u8 rgmii_ctrl = 0, reg = 0, off; 1092f973b768SDan Carpenter int pause = 0; 10935e004460SFlorian Fainelli 10945e004460SFlorian Fainelli if (!phy_is_pseudo_fixed_link(phydev)) 10955e004460SFlorian Fainelli return; 10965e004460SFlorian Fainelli 1097967dd82fSFlorian Fainelli /* Enable flow control on BCM5301x's CPU port */ 1098967dd82fSFlorian Fainelli if (is5301x(dev) && port == dev->cpu_port) 10995e004460SFlorian Fainelli pause = MLO_PAUSE_TXRX_MASK; 1100967dd82fSFlorian Fainelli 1101967dd82fSFlorian Fainelli if (phydev->pause) { 1102967dd82fSFlorian Fainelli if (phydev->asym_pause) 11035e004460SFlorian Fainelli pause |= MLO_PAUSE_TX; 11045e004460SFlorian Fainelli pause |= MLO_PAUSE_RX; 1105967dd82fSFlorian Fainelli } 1106967dd82fSFlorian Fainelli 11075e004460SFlorian Fainelli b53_force_port_config(dev, port, phydev->speed, phydev->duplex, pause); 11085e004460SFlorian Fainelli b53_force_link(dev, port, phydev->link); 1109967dd82fSFlorian Fainelli 1110967dd82fSFlorian Fainelli if (is531x5(dev) && phy_interface_is_rgmii(phydev)) { 1111967dd82fSFlorian Fainelli if (port == 8) 1112967dd82fSFlorian Fainelli off = B53_RGMII_CTRL_IMP; 1113967dd82fSFlorian Fainelli else 1114967dd82fSFlorian Fainelli off = B53_RGMII_CTRL_P(port); 1115967dd82fSFlorian Fainelli 1116967dd82fSFlorian Fainelli /* Configure the port RGMII clock delay by DLL disabled and 1117967dd82fSFlorian Fainelli * tx_clk aligned timing (restoring to reset defaults) 1118967dd82fSFlorian Fainelli */ 1119967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, off, &rgmii_ctrl); 1120967dd82fSFlorian Fainelli rgmii_ctrl &= ~(RGMII_CTRL_DLL_RXC | RGMII_CTRL_DLL_TXC | 1121967dd82fSFlorian Fainelli RGMII_CTRL_TIMING_SEL); 1122967dd82fSFlorian Fainelli 1123967dd82fSFlorian Fainelli /* PHY_INTERFACE_MODE_RGMII_TXID means TX internal delay, make 1124967dd82fSFlorian Fainelli * sure that we enable the port TX clock internal delay to 1125967dd82fSFlorian Fainelli * account for this internal delay that is inserted, otherwise 1126967dd82fSFlorian Fainelli * the switch won't be able to receive correctly. 1127967dd82fSFlorian Fainelli * 1128967dd82fSFlorian Fainelli * PHY_INTERFACE_MODE_RGMII means that we are not introducing 1129967dd82fSFlorian Fainelli * any delay neither on transmission nor reception, so the 1130967dd82fSFlorian Fainelli * BCM53125 must also be configured accordingly to account for 1131967dd82fSFlorian Fainelli * the lack of delay and introduce 1132967dd82fSFlorian Fainelli * 1133967dd82fSFlorian Fainelli * The BCM53125 switch has its RX clock and TX clock control 1134967dd82fSFlorian Fainelli * swapped, hence the reason why we modify the TX clock path in 1135967dd82fSFlorian Fainelli * the "RGMII" case 1136967dd82fSFlorian Fainelli */ 1137967dd82fSFlorian Fainelli if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) 1138967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_DLL_TXC; 1139967dd82fSFlorian Fainelli if (phydev->interface == PHY_INTERFACE_MODE_RGMII) 1140967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_DLL_TXC | RGMII_CTRL_DLL_RXC; 1141967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_TIMING_SEL; 1142967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, off, rgmii_ctrl); 1143967dd82fSFlorian Fainelli 1144967dd82fSFlorian Fainelli dev_info(ds->dev, "Configured port %d for %s\n", port, 1145967dd82fSFlorian Fainelli phy_modes(phydev->interface)); 1146967dd82fSFlorian Fainelli } 1147967dd82fSFlorian Fainelli 1148967dd82fSFlorian Fainelli /* configure MII port if necessary */ 1149967dd82fSFlorian Fainelli if (is5325(dev)) { 1150967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, 1151967dd82fSFlorian Fainelli ®); 1152967dd82fSFlorian Fainelli 1153967dd82fSFlorian Fainelli /* reverse mii needs to be enabled */ 1154967dd82fSFlorian Fainelli if (!(reg & PORT_OVERRIDE_RV_MII_25)) { 1155967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, 1156967dd82fSFlorian Fainelli reg | PORT_OVERRIDE_RV_MII_25); 1157967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, 1158967dd82fSFlorian Fainelli ®); 1159967dd82fSFlorian Fainelli 1160967dd82fSFlorian Fainelli if (!(reg & PORT_OVERRIDE_RV_MII_25)) { 1161967dd82fSFlorian Fainelli dev_err(ds->dev, 1162967dd82fSFlorian Fainelli "Failed to enable reverse MII mode\n"); 1163967dd82fSFlorian Fainelli return; 1164967dd82fSFlorian Fainelli } 1165967dd82fSFlorian Fainelli } 1166967dd82fSFlorian Fainelli } else if (is5301x(dev)) { 1167967dd82fSFlorian Fainelli if (port != dev->cpu_port) { 11685e004460SFlorian Fainelli b53_force_port_config(dev, dev->cpu_port, 2000, 11695e004460SFlorian Fainelli DUPLEX_FULL, MLO_PAUSE_TXRX_MASK); 11705e004460SFlorian Fainelli b53_force_link(dev, dev->cpu_port, 1); 1171967dd82fSFlorian Fainelli } 1172967dd82fSFlorian Fainelli } 1173f43a2dbeSFlorian Fainelli 1174f43a2dbeSFlorian Fainelli /* Re-negotiate EEE if it was enabled already */ 1175f43a2dbeSFlorian Fainelli p->eee_enabled = b53_eee_init(ds, port, phydev); 1176967dd82fSFlorian Fainelli } 1177967dd82fSFlorian Fainelli 1178a8e8b985SFlorian Fainelli void b53_port_event(struct dsa_switch *ds, int port) 1179a8e8b985SFlorian Fainelli { 1180a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1181a8e8b985SFlorian Fainelli bool link; 1182a8e8b985SFlorian Fainelli u16 sts; 1183a8e8b985SFlorian Fainelli 1184a8e8b985SFlorian Fainelli b53_read16(dev, B53_STAT_PAGE, B53_LINK_STAT, &sts); 1185a8e8b985SFlorian Fainelli link = !!(sts & BIT(port)); 1186a8e8b985SFlorian Fainelli dsa_port_phylink_mac_change(ds, port, link); 1187a8e8b985SFlorian Fainelli } 1188a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_port_event); 1189a8e8b985SFlorian Fainelli 1190a8e8b985SFlorian Fainelli void b53_phylink_validate(struct dsa_switch *ds, int port, 1191a8e8b985SFlorian Fainelli unsigned long *supported, 1192a8e8b985SFlorian Fainelli struct phylink_link_state *state) 1193a8e8b985SFlorian Fainelli { 1194a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1195a8e8b985SFlorian Fainelli __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, }; 1196a8e8b985SFlorian Fainelli 11970e01491dSFlorian Fainelli if (dev->ops->serdes_phylink_validate) 11980e01491dSFlorian Fainelli dev->ops->serdes_phylink_validate(dev, port, mask, state); 11990e01491dSFlorian Fainelli 1200a8e8b985SFlorian Fainelli /* Allow all the expected bits */ 1201a8e8b985SFlorian Fainelli phylink_set(mask, Autoneg); 1202a8e8b985SFlorian Fainelli phylink_set_port_modes(mask); 1203a8e8b985SFlorian Fainelli phylink_set(mask, Pause); 1204a8e8b985SFlorian Fainelli phylink_set(mask, Asym_Pause); 1205a8e8b985SFlorian Fainelli 1206a8e8b985SFlorian Fainelli /* With the exclusion of 5325/5365, MII, Reverse MII and 802.3z, we 1207a8e8b985SFlorian Fainelli * support Gigabit, including Half duplex. 1208a8e8b985SFlorian Fainelli */ 1209a8e8b985SFlorian Fainelli if (state->interface != PHY_INTERFACE_MODE_MII && 1210a8e8b985SFlorian Fainelli state->interface != PHY_INTERFACE_MODE_REVMII && 1211a8e8b985SFlorian Fainelli !phy_interface_mode_is_8023z(state->interface) && 1212a8e8b985SFlorian Fainelli !(is5325(dev) || is5365(dev))) { 1213a8e8b985SFlorian Fainelli phylink_set(mask, 1000baseT_Full); 1214a8e8b985SFlorian Fainelli phylink_set(mask, 1000baseT_Half); 1215a8e8b985SFlorian Fainelli } 1216a8e8b985SFlorian Fainelli 1217a8e8b985SFlorian Fainelli if (!phy_interface_mode_is_8023z(state->interface)) { 1218a8e8b985SFlorian Fainelli phylink_set(mask, 10baseT_Half); 1219a8e8b985SFlorian Fainelli phylink_set(mask, 10baseT_Full); 1220a8e8b985SFlorian Fainelli phylink_set(mask, 100baseT_Half); 1221a8e8b985SFlorian Fainelli phylink_set(mask, 100baseT_Full); 1222a8e8b985SFlorian Fainelli } 1223a8e8b985SFlorian Fainelli 1224a8e8b985SFlorian Fainelli bitmap_and(supported, supported, mask, 1225a8e8b985SFlorian Fainelli __ETHTOOL_LINK_MODE_MASK_NBITS); 1226a8e8b985SFlorian Fainelli bitmap_and(state->advertising, state->advertising, mask, 1227a8e8b985SFlorian Fainelli __ETHTOOL_LINK_MODE_MASK_NBITS); 1228a8e8b985SFlorian Fainelli 1229a8e8b985SFlorian Fainelli phylink_helper_basex_speed(state); 1230a8e8b985SFlorian Fainelli } 1231a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_validate); 1232a8e8b985SFlorian Fainelli 1233a8e8b985SFlorian Fainelli int b53_phylink_mac_link_state(struct dsa_switch *ds, int port, 1234a8e8b985SFlorian Fainelli struct phylink_link_state *state) 1235a8e8b985SFlorian Fainelli { 12360e01491dSFlorian Fainelli struct b53_device *dev = ds->priv; 1237a8e8b985SFlorian Fainelli int ret = -EOPNOTSUPP; 1238a8e8b985SFlorian Fainelli 123955a4d2eaSFlorian Fainelli if ((phy_interface_mode_is_8023z(state->interface) || 124055a4d2eaSFlorian Fainelli state->interface == PHY_INTERFACE_MODE_SGMII) && 12410e01491dSFlorian Fainelli dev->ops->serdes_link_state) 12420e01491dSFlorian Fainelli ret = dev->ops->serdes_link_state(dev, port, state); 12430e01491dSFlorian Fainelli 1244a8e8b985SFlorian Fainelli return ret; 1245a8e8b985SFlorian Fainelli } 1246a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_state); 1247a8e8b985SFlorian Fainelli 1248a8e8b985SFlorian Fainelli void b53_phylink_mac_config(struct dsa_switch *ds, int port, 1249a8e8b985SFlorian Fainelli unsigned int mode, 1250a8e8b985SFlorian Fainelli const struct phylink_link_state *state) 1251a8e8b985SFlorian Fainelli { 1252a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1253a8e8b985SFlorian Fainelli 1254a8e8b985SFlorian Fainelli if (mode == MLO_AN_PHY) 1255a8e8b985SFlorian Fainelli return; 1256a8e8b985SFlorian Fainelli 1257a8e8b985SFlorian Fainelli if (mode == MLO_AN_FIXED) { 1258a8e8b985SFlorian Fainelli b53_force_port_config(dev, port, state->speed, 1259a8e8b985SFlorian Fainelli state->duplex, state->pause); 1260a8e8b985SFlorian Fainelli return; 1261a8e8b985SFlorian Fainelli } 12620e01491dSFlorian Fainelli 126355a4d2eaSFlorian Fainelli if ((phy_interface_mode_is_8023z(state->interface) || 126455a4d2eaSFlorian Fainelli state->interface == PHY_INTERFACE_MODE_SGMII) && 12650e01491dSFlorian Fainelli dev->ops->serdes_config) 12660e01491dSFlorian Fainelli dev->ops->serdes_config(dev, port, mode, state); 1267a8e8b985SFlorian Fainelli } 1268a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_config); 1269a8e8b985SFlorian Fainelli 1270a8e8b985SFlorian Fainelli void b53_phylink_mac_an_restart(struct dsa_switch *ds, int port) 1271a8e8b985SFlorian Fainelli { 12720e01491dSFlorian Fainelli struct b53_device *dev = ds->priv; 12730e01491dSFlorian Fainelli 12740e01491dSFlorian Fainelli if (dev->ops->serdes_an_restart) 12750e01491dSFlorian Fainelli dev->ops->serdes_an_restart(dev, port); 1276a8e8b985SFlorian Fainelli } 1277a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_an_restart); 1278a8e8b985SFlorian Fainelli 1279a8e8b985SFlorian Fainelli void b53_phylink_mac_link_down(struct dsa_switch *ds, int port, 1280a8e8b985SFlorian Fainelli unsigned int mode, 1281a8e8b985SFlorian Fainelli phy_interface_t interface) 1282a8e8b985SFlorian Fainelli { 1283a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1284a8e8b985SFlorian Fainelli 1285a8e8b985SFlorian Fainelli if (mode == MLO_AN_PHY) 1286a8e8b985SFlorian Fainelli return; 1287a8e8b985SFlorian Fainelli 1288a8e8b985SFlorian Fainelli if (mode == MLO_AN_FIXED) { 1289a8e8b985SFlorian Fainelli b53_force_link(dev, port, false); 1290a8e8b985SFlorian Fainelli return; 1291a8e8b985SFlorian Fainelli } 12920e01491dSFlorian Fainelli 12930e01491dSFlorian Fainelli if (phy_interface_mode_is_8023z(interface) && 12940e01491dSFlorian Fainelli dev->ops->serdes_link_set) 12950e01491dSFlorian Fainelli dev->ops->serdes_link_set(dev, port, mode, interface, false); 1296a8e8b985SFlorian Fainelli } 1297a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_down); 1298a8e8b985SFlorian Fainelli 1299a8e8b985SFlorian Fainelli void b53_phylink_mac_link_up(struct dsa_switch *ds, int port, 1300a8e8b985SFlorian Fainelli unsigned int mode, 1301a8e8b985SFlorian Fainelli phy_interface_t interface, 13025b502a7bSRussell King struct phy_device *phydev, 13035b502a7bSRussell King int speed, int duplex, 13045b502a7bSRussell King bool tx_pause, bool rx_pause) 1305a8e8b985SFlorian Fainelli { 1306a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1307a8e8b985SFlorian Fainelli 1308a8e8b985SFlorian Fainelli if (mode == MLO_AN_PHY) 1309a8e8b985SFlorian Fainelli return; 1310a8e8b985SFlorian Fainelli 1311a8e8b985SFlorian Fainelli if (mode == MLO_AN_FIXED) { 1312a8e8b985SFlorian Fainelli b53_force_link(dev, port, true); 1313a8e8b985SFlorian Fainelli return; 1314a8e8b985SFlorian Fainelli } 13150e01491dSFlorian Fainelli 13160e01491dSFlorian Fainelli if (phy_interface_mode_is_8023z(interface) && 13170e01491dSFlorian Fainelli dev->ops->serdes_link_set) 13180e01491dSFlorian Fainelli dev->ops->serdes_link_set(dev, port, mode, interface, true); 1319a8e8b985SFlorian Fainelli } 1320a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_up); 1321a8e8b985SFlorian Fainelli 13223117455dSFlorian Fainelli int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering) 1323a2482d2cSFlorian Fainelli { 1324dad8d7c6SFlorian Fainelli struct b53_device *dev = ds->priv; 1325dad8d7c6SFlorian Fainelli u16 pvid, new_pvid; 1326dad8d7c6SFlorian Fainelli 1327dad8d7c6SFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid); 1328dad8d7c6SFlorian Fainelli new_pvid = pvid; 1329864cd7b0SVladimir Oltean if (!vlan_filtering) { 1330dad8d7c6SFlorian Fainelli /* Filtering is currently enabled, use the default PVID since 1331dad8d7c6SFlorian Fainelli * the bridge does not expect tagging anymore 1332dad8d7c6SFlorian Fainelli */ 1333dad8d7c6SFlorian Fainelli dev->ports[port].pvid = pvid; 1334dad8d7c6SFlorian Fainelli new_pvid = b53_default_pvid(dev); 1335864cd7b0SVladimir Oltean } else { 1336dad8d7c6SFlorian Fainelli /* Filtering is currently disabled, restore the previous PVID */ 1337dad8d7c6SFlorian Fainelli new_pvid = dev->ports[port].pvid; 1338dad8d7c6SFlorian Fainelli } 1339dad8d7c6SFlorian Fainelli 1340dad8d7c6SFlorian Fainelli if (pvid != new_pvid) 1341dad8d7c6SFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), 1342dad8d7c6SFlorian Fainelli new_pvid); 1343dad8d7c6SFlorian Fainelli 1344dad8d7c6SFlorian Fainelli b53_enable_vlan(dev, dev->vlan_enabled, vlan_filtering); 1345dad8d7c6SFlorian Fainelli 1346a2482d2cSFlorian Fainelli return 0; 1347a2482d2cSFlorian Fainelli } 13483117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_filtering); 1349a2482d2cSFlorian Fainelli 13503117455dSFlorian Fainelli int b53_vlan_prepare(struct dsa_switch *ds, int port, 135180e02360SVivien Didelot const struct switchdev_obj_port_vlan *vlan) 1352a2482d2cSFlorian Fainelli { 135304bed143SVivien Didelot struct b53_device *dev = ds->priv; 1354a2482d2cSFlorian Fainelli 1355a2482d2cSFlorian Fainelli if ((is5325(dev) || is5365(dev)) && vlan->vid_begin == 0) 1356a2482d2cSFlorian Fainelli return -EOPNOTSUPP; 1357a2482d2cSFlorian Fainelli 135888631864SFlorian Fainelli /* Port 7 on 7278 connects to the ASP's UniMAC which is not capable of 135988631864SFlorian Fainelli * receiving VLAN tagged frames at all, we can still allow the port to 136088631864SFlorian Fainelli * be configured for egress untagged. 136188631864SFlorian Fainelli */ 136288631864SFlorian Fainelli if (dev->chip_id == BCM7278_DEVICE_ID && port == 7 && 136388631864SFlorian Fainelli !(vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED)) 136488631864SFlorian Fainelli return -EINVAL; 136588631864SFlorian Fainelli 1366a2482d2cSFlorian Fainelli if (vlan->vid_end > dev->num_vlans) 1367a2482d2cSFlorian Fainelli return -ERANGE; 1368a2482d2cSFlorian Fainelli 1369e74f014eSVladimir Oltean b53_enable_vlan(dev, true, ds->vlan_filtering); 1370a2482d2cSFlorian Fainelli 1371a2482d2cSFlorian Fainelli return 0; 1372a2482d2cSFlorian Fainelli } 13733117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_prepare); 1374a2482d2cSFlorian Fainelli 13753117455dSFlorian Fainelli void b53_vlan_add(struct dsa_switch *ds, int port, 137680e02360SVivien Didelot const struct switchdev_obj_port_vlan *vlan) 1377a2482d2cSFlorian Fainelli { 137804bed143SVivien Didelot struct b53_device *dev = ds->priv; 1379a2482d2cSFlorian Fainelli bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; 1380a2482d2cSFlorian Fainelli bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID; 1381a2482d2cSFlorian Fainelli struct b53_vlan *vl; 1382a2482d2cSFlorian Fainelli u16 vid; 1383a2482d2cSFlorian Fainelli 1384a2482d2cSFlorian Fainelli for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) { 1385a2482d2cSFlorian Fainelli vl = &dev->vlans[vid]; 1386a2482d2cSFlorian Fainelli 1387a2482d2cSFlorian Fainelli b53_get_vlan_entry(dev, vid, vl); 1388a2482d2cSFlorian Fainelli 1389d965a543SFlorian Fainelli if (vid == 0 && vid == b53_default_pvid(dev)) 1390d965a543SFlorian Fainelli untagged = true; 1391d965a543SFlorian Fainelli 1392c499696eSFlorian Fainelli vl->members |= BIT(port); 1393ca893194SFlorian Fainelli if (untagged && !dsa_is_cpu_port(ds, port)) 1394e47112d9SFlorian Fainelli vl->untag |= BIT(port); 1395a2482d2cSFlorian Fainelli else 1396e47112d9SFlorian Fainelli vl->untag &= ~BIT(port); 1397a2482d2cSFlorian Fainelli 1398a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, vid, vl); 1399a2482d2cSFlorian Fainelli b53_fast_age_vlan(dev, vid); 1400a2482d2cSFlorian Fainelli } 1401a2482d2cSFlorian Fainelli 140210163aaeSFlorian Fainelli if (pvid && !dsa_is_cpu_port(ds, port)) { 1403a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), 1404a2482d2cSFlorian Fainelli vlan->vid_end); 1405a2482d2cSFlorian Fainelli b53_fast_age_vlan(dev, vid); 1406a2482d2cSFlorian Fainelli } 1407a2482d2cSFlorian Fainelli } 14083117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_add); 1409a2482d2cSFlorian Fainelli 14103117455dSFlorian Fainelli int b53_vlan_del(struct dsa_switch *ds, int port, 1411a2482d2cSFlorian Fainelli const struct switchdev_obj_port_vlan *vlan) 1412a2482d2cSFlorian Fainelli { 141304bed143SVivien Didelot struct b53_device *dev = ds->priv; 1414a2482d2cSFlorian Fainelli bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; 1415a2482d2cSFlorian Fainelli struct b53_vlan *vl; 1416a2482d2cSFlorian Fainelli u16 vid; 1417a2482d2cSFlorian Fainelli u16 pvid; 1418a2482d2cSFlorian Fainelli 1419a2482d2cSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid); 1420a2482d2cSFlorian Fainelli 1421a2482d2cSFlorian Fainelli for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) { 1422a2482d2cSFlorian Fainelli vl = &dev->vlans[vid]; 1423a2482d2cSFlorian Fainelli 1424a2482d2cSFlorian Fainelli b53_get_vlan_entry(dev, vid, vl); 1425a2482d2cSFlorian Fainelli 1426a2482d2cSFlorian Fainelli vl->members &= ~BIT(port); 1427a2482d2cSFlorian Fainelli 1428fea83353SFlorian Fainelli if (pvid == vid) 1429fea83353SFlorian Fainelli pvid = b53_default_pvid(dev); 1430a2482d2cSFlorian Fainelli 1431ca893194SFlorian Fainelli if (untagged && !dsa_is_cpu_port(ds, port)) 1432a2482d2cSFlorian Fainelli vl->untag &= ~(BIT(port)); 1433a2482d2cSFlorian Fainelli 1434a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, vid, vl); 1435a2482d2cSFlorian Fainelli b53_fast_age_vlan(dev, vid); 1436a2482d2cSFlorian Fainelli } 1437a2482d2cSFlorian Fainelli 1438a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), pvid); 1439a2482d2cSFlorian Fainelli b53_fast_age_vlan(dev, pvid); 1440a2482d2cSFlorian Fainelli 1441a2482d2cSFlorian Fainelli return 0; 1442a2482d2cSFlorian Fainelli } 14433117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_del); 1444a2482d2cSFlorian Fainelli 14451da6df85SFlorian Fainelli /* Address Resolution Logic routines */ 14461da6df85SFlorian Fainelli static int b53_arl_op_wait(struct b53_device *dev) 14471da6df85SFlorian Fainelli { 14481da6df85SFlorian Fainelli unsigned int timeout = 10; 14491da6df85SFlorian Fainelli u8 reg; 14501da6df85SFlorian Fainelli 14511da6df85SFlorian Fainelli do { 14521da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, ®); 14531da6df85SFlorian Fainelli if (!(reg & ARLTBL_START_DONE)) 14541da6df85SFlorian Fainelli return 0; 14551da6df85SFlorian Fainelli 14561da6df85SFlorian Fainelli usleep_range(1000, 2000); 14571da6df85SFlorian Fainelli } while (timeout--); 14581da6df85SFlorian Fainelli 14591da6df85SFlorian Fainelli dev_warn(dev->dev, "timeout waiting for ARL to finish: 0x%02x\n", reg); 14601da6df85SFlorian Fainelli 14611da6df85SFlorian Fainelli return -ETIMEDOUT; 14621da6df85SFlorian Fainelli } 14631da6df85SFlorian Fainelli 14641da6df85SFlorian Fainelli static int b53_arl_rw_op(struct b53_device *dev, unsigned int op) 14651da6df85SFlorian Fainelli { 14661da6df85SFlorian Fainelli u8 reg; 14671da6df85SFlorian Fainelli 14681da6df85SFlorian Fainelli if (op > ARLTBL_RW) 14691da6df85SFlorian Fainelli return -EINVAL; 14701da6df85SFlorian Fainelli 14711da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, ®); 14721da6df85SFlorian Fainelli reg |= ARLTBL_START_DONE; 14731da6df85SFlorian Fainelli if (op) 14741da6df85SFlorian Fainelli reg |= ARLTBL_RW; 14751da6df85SFlorian Fainelli else 14761da6df85SFlorian Fainelli reg &= ~ARLTBL_RW; 14771da6df85SFlorian Fainelli b53_write8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, reg); 14781da6df85SFlorian Fainelli 14791da6df85SFlorian Fainelli return b53_arl_op_wait(dev); 14801da6df85SFlorian Fainelli } 14811da6df85SFlorian Fainelli 14821da6df85SFlorian Fainelli static int b53_arl_read(struct b53_device *dev, u64 mac, 14831da6df85SFlorian Fainelli u16 vid, struct b53_arl_entry *ent, u8 *idx, 14841da6df85SFlorian Fainelli bool is_valid) 14851da6df85SFlorian Fainelli { 14861da6df85SFlorian Fainelli unsigned int i; 14871da6df85SFlorian Fainelli int ret; 14881da6df85SFlorian Fainelli 14891da6df85SFlorian Fainelli ret = b53_arl_op_wait(dev); 14901da6df85SFlorian Fainelli if (ret) 14911da6df85SFlorian Fainelli return ret; 14921da6df85SFlorian Fainelli 14931da6df85SFlorian Fainelli /* Read the bins */ 14941da6df85SFlorian Fainelli for (i = 0; i < dev->num_arl_entries; i++) { 14951da6df85SFlorian Fainelli u64 mac_vid; 14961da6df85SFlorian Fainelli u32 fwd_entry; 14971da6df85SFlorian Fainelli 14981da6df85SFlorian Fainelli b53_read64(dev, B53_ARLIO_PAGE, 14991da6df85SFlorian Fainelli B53_ARLTBL_MAC_VID_ENTRY(i), &mac_vid); 15001da6df85SFlorian Fainelli b53_read32(dev, B53_ARLIO_PAGE, 15011da6df85SFlorian Fainelli B53_ARLTBL_DATA_ENTRY(i), &fwd_entry); 15021da6df85SFlorian Fainelli b53_arl_to_entry(ent, mac_vid, fwd_entry); 15031da6df85SFlorian Fainelli 15041da6df85SFlorian Fainelli if (!(fwd_entry & ARLTBL_VALID)) 15051da6df85SFlorian Fainelli continue; 15061da6df85SFlorian Fainelli if ((mac_vid & ARLTBL_MAC_MASK) != mac) 15071da6df85SFlorian Fainelli continue; 15081da6df85SFlorian Fainelli *idx = i; 15091da6df85SFlorian Fainelli } 15101da6df85SFlorian Fainelli 15111da6df85SFlorian Fainelli return -ENOENT; 15121da6df85SFlorian Fainelli } 15131da6df85SFlorian Fainelli 15141da6df85SFlorian Fainelli static int b53_arl_op(struct b53_device *dev, int op, int port, 15151da6df85SFlorian Fainelli const unsigned char *addr, u16 vid, bool is_valid) 15161da6df85SFlorian Fainelli { 15171da6df85SFlorian Fainelli struct b53_arl_entry ent; 15181da6df85SFlorian Fainelli u32 fwd_entry; 15191da6df85SFlorian Fainelli u64 mac, mac_vid = 0; 15201da6df85SFlorian Fainelli u8 idx = 0; 15211da6df85SFlorian Fainelli int ret; 15221da6df85SFlorian Fainelli 15231da6df85SFlorian Fainelli /* Convert the array into a 64-bit MAC */ 15244b92ea81SFlorian Fainelli mac = ether_addr_to_u64(addr); 15251da6df85SFlorian Fainelli 15261da6df85SFlorian Fainelli /* Perform a read for the given MAC and VID */ 15271da6df85SFlorian Fainelli b53_write48(dev, B53_ARLIO_PAGE, B53_MAC_ADDR_IDX, mac); 15281da6df85SFlorian Fainelli b53_write16(dev, B53_ARLIO_PAGE, B53_VLAN_ID_IDX, vid); 15291da6df85SFlorian Fainelli 15301da6df85SFlorian Fainelli /* Issue a read operation for this MAC */ 15311da6df85SFlorian Fainelli ret = b53_arl_rw_op(dev, 1); 15321da6df85SFlorian Fainelli if (ret) 15331da6df85SFlorian Fainelli return ret; 15341da6df85SFlorian Fainelli 15351da6df85SFlorian Fainelli ret = b53_arl_read(dev, mac, vid, &ent, &idx, is_valid); 15361da6df85SFlorian Fainelli /* If this is a read, just finish now */ 15371da6df85SFlorian Fainelli if (op) 15381da6df85SFlorian Fainelli return ret; 15391da6df85SFlorian Fainelli 15401da6df85SFlorian Fainelli /* We could not find a matching MAC, so reset to a new entry */ 15411da6df85SFlorian Fainelli if (ret) { 15421da6df85SFlorian Fainelli fwd_entry = 0; 15431da6df85SFlorian Fainelli idx = 1; 15441da6df85SFlorian Fainelli } 15451da6df85SFlorian Fainelli 15465d65b64aSFlorian Fainelli /* For multicast address, the port is a bitmask and the validity 15475d65b64aSFlorian Fainelli * is determined by having at least one port being still active 15485d65b64aSFlorian Fainelli */ 15495d65b64aSFlorian Fainelli if (!is_multicast_ether_addr(addr)) { 15501da6df85SFlorian Fainelli ent.port = port; 15511da6df85SFlorian Fainelli ent.is_valid = is_valid; 15525d65b64aSFlorian Fainelli } else { 15535d65b64aSFlorian Fainelli if (is_valid) 15545d65b64aSFlorian Fainelli ent.port |= BIT(port); 15555d65b64aSFlorian Fainelli else 15565d65b64aSFlorian Fainelli ent.port &= ~BIT(port); 15575d65b64aSFlorian Fainelli 15585d65b64aSFlorian Fainelli ent.is_valid = !!(ent.port); 15595d65b64aSFlorian Fainelli } 15605d65b64aSFlorian Fainelli 15615d65b64aSFlorian Fainelli ent.is_valid = is_valid; 15621da6df85SFlorian Fainelli ent.vid = vid; 15631da6df85SFlorian Fainelli ent.is_static = true; 15645d65b64aSFlorian Fainelli ent.is_age = false; 15651da6df85SFlorian Fainelli memcpy(ent.mac, addr, ETH_ALEN); 15661da6df85SFlorian Fainelli b53_arl_from_entry(&mac_vid, &fwd_entry, &ent); 15671da6df85SFlorian Fainelli 15681da6df85SFlorian Fainelli b53_write64(dev, B53_ARLIO_PAGE, 15691da6df85SFlorian Fainelli B53_ARLTBL_MAC_VID_ENTRY(idx), mac_vid); 15701da6df85SFlorian Fainelli b53_write32(dev, B53_ARLIO_PAGE, 15711da6df85SFlorian Fainelli B53_ARLTBL_DATA_ENTRY(idx), fwd_entry); 15721da6df85SFlorian Fainelli 15731da6df85SFlorian Fainelli return b53_arl_rw_op(dev, 0); 15741da6df85SFlorian Fainelli } 15751da6df85SFlorian Fainelli 15761b6dd556SArkadi Sharshevsky int b53_fdb_add(struct dsa_switch *ds, int port, 15776c2c1dcbSArkadi Sharshevsky const unsigned char *addr, u16 vid) 15781da6df85SFlorian Fainelli { 157904bed143SVivien Didelot struct b53_device *priv = ds->priv; 15801da6df85SFlorian Fainelli 15811da6df85SFlorian Fainelli /* 5325 and 5365 require some more massaging, but could 15821da6df85SFlorian Fainelli * be supported eventually 15831da6df85SFlorian Fainelli */ 15841da6df85SFlorian Fainelli if (is5325(priv) || is5365(priv)) 15851da6df85SFlorian Fainelli return -EOPNOTSUPP; 15861da6df85SFlorian Fainelli 15871b6dd556SArkadi Sharshevsky return b53_arl_op(priv, 0, port, addr, vid, true); 15881da6df85SFlorian Fainelli } 15893117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_add); 15901da6df85SFlorian Fainelli 15913117455dSFlorian Fainelli int b53_fdb_del(struct dsa_switch *ds, int port, 15926c2c1dcbSArkadi Sharshevsky const unsigned char *addr, u16 vid) 15931da6df85SFlorian Fainelli { 159404bed143SVivien Didelot struct b53_device *priv = ds->priv; 15951da6df85SFlorian Fainelli 15966c2c1dcbSArkadi Sharshevsky return b53_arl_op(priv, 0, port, addr, vid, false); 15971da6df85SFlorian Fainelli } 15983117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_del); 15991da6df85SFlorian Fainelli 16001da6df85SFlorian Fainelli static int b53_arl_search_wait(struct b53_device *dev) 16011da6df85SFlorian Fainelli { 16021da6df85SFlorian Fainelli unsigned int timeout = 1000; 16031da6df85SFlorian Fainelli u8 reg; 16041da6df85SFlorian Fainelli 16051da6df85SFlorian Fainelli do { 16061da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, ®); 16071da6df85SFlorian Fainelli if (!(reg & ARL_SRCH_STDN)) 16081da6df85SFlorian Fainelli return 0; 16091da6df85SFlorian Fainelli 16101da6df85SFlorian Fainelli if (reg & ARL_SRCH_VLID) 16111da6df85SFlorian Fainelli return 0; 16121da6df85SFlorian Fainelli 16131da6df85SFlorian Fainelli usleep_range(1000, 2000); 16141da6df85SFlorian Fainelli } while (timeout--); 16151da6df85SFlorian Fainelli 16161da6df85SFlorian Fainelli return -ETIMEDOUT; 16171da6df85SFlorian Fainelli } 16181da6df85SFlorian Fainelli 16191da6df85SFlorian Fainelli static void b53_arl_search_rd(struct b53_device *dev, u8 idx, 16201da6df85SFlorian Fainelli struct b53_arl_entry *ent) 16211da6df85SFlorian Fainelli { 16221da6df85SFlorian Fainelli u64 mac_vid; 16231da6df85SFlorian Fainelli u32 fwd_entry; 16241da6df85SFlorian Fainelli 16251da6df85SFlorian Fainelli b53_read64(dev, B53_ARLIO_PAGE, 16261da6df85SFlorian Fainelli B53_ARL_SRCH_RSTL_MACVID(idx), &mac_vid); 16271da6df85SFlorian Fainelli b53_read32(dev, B53_ARLIO_PAGE, 16281da6df85SFlorian Fainelli B53_ARL_SRCH_RSTL(idx), &fwd_entry); 16291da6df85SFlorian Fainelli b53_arl_to_entry(ent, mac_vid, fwd_entry); 16301da6df85SFlorian Fainelli } 16311da6df85SFlorian Fainelli 1632e6cbef0cSVivien Didelot static int b53_fdb_copy(int port, const struct b53_arl_entry *ent, 16332bedde1aSArkadi Sharshevsky dsa_fdb_dump_cb_t *cb, void *data) 16341da6df85SFlorian Fainelli { 16351da6df85SFlorian Fainelli if (!ent->is_valid) 16361da6df85SFlorian Fainelli return 0; 16371da6df85SFlorian Fainelli 16381da6df85SFlorian Fainelli if (port != ent->port) 16391da6df85SFlorian Fainelli return 0; 16401da6df85SFlorian Fainelli 16412bedde1aSArkadi Sharshevsky return cb(ent->mac, ent->vid, ent->is_static, data); 16421da6df85SFlorian Fainelli } 16431da6df85SFlorian Fainelli 16443117455dSFlorian Fainelli int b53_fdb_dump(struct dsa_switch *ds, int port, 16452bedde1aSArkadi Sharshevsky dsa_fdb_dump_cb_t *cb, void *data) 16461da6df85SFlorian Fainelli { 164704bed143SVivien Didelot struct b53_device *priv = ds->priv; 16481da6df85SFlorian Fainelli struct b53_arl_entry results[2]; 16491da6df85SFlorian Fainelli unsigned int count = 0; 16501da6df85SFlorian Fainelli int ret; 16511da6df85SFlorian Fainelli u8 reg; 16521da6df85SFlorian Fainelli 16531da6df85SFlorian Fainelli /* Start search operation */ 16541da6df85SFlorian Fainelli reg = ARL_SRCH_STDN; 16551da6df85SFlorian Fainelli b53_write8(priv, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, reg); 16561da6df85SFlorian Fainelli 16571da6df85SFlorian Fainelli do { 16581da6df85SFlorian Fainelli ret = b53_arl_search_wait(priv); 16591da6df85SFlorian Fainelli if (ret) 16601da6df85SFlorian Fainelli return ret; 16611da6df85SFlorian Fainelli 16621da6df85SFlorian Fainelli b53_arl_search_rd(priv, 0, &results[0]); 16632bedde1aSArkadi Sharshevsky ret = b53_fdb_copy(port, &results[0], cb, data); 16641da6df85SFlorian Fainelli if (ret) 16651da6df85SFlorian Fainelli return ret; 16661da6df85SFlorian Fainelli 16671da6df85SFlorian Fainelli if (priv->num_arl_entries > 2) { 16681da6df85SFlorian Fainelli b53_arl_search_rd(priv, 1, &results[1]); 16692bedde1aSArkadi Sharshevsky ret = b53_fdb_copy(port, &results[1], cb, data); 16701da6df85SFlorian Fainelli if (ret) 16711da6df85SFlorian Fainelli return ret; 16721da6df85SFlorian Fainelli 16731da6df85SFlorian Fainelli if (!results[0].is_valid && !results[1].is_valid) 16741da6df85SFlorian Fainelli break; 16751da6df85SFlorian Fainelli } 16761da6df85SFlorian Fainelli 16771da6df85SFlorian Fainelli } while (count++ < 1024); 16781da6df85SFlorian Fainelli 16791da6df85SFlorian Fainelli return 0; 16801da6df85SFlorian Fainelli } 16813117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_dump); 16821da6df85SFlorian Fainelli 16835d65b64aSFlorian Fainelli int b53_mdb_prepare(struct dsa_switch *ds, int port, 16845d65b64aSFlorian Fainelli const struct switchdev_obj_port_mdb *mdb) 16855d65b64aSFlorian Fainelli { 16865d65b64aSFlorian Fainelli struct b53_device *priv = ds->priv; 16875d65b64aSFlorian Fainelli 16885d65b64aSFlorian Fainelli /* 5325 and 5365 require some more massaging, but could 16895d65b64aSFlorian Fainelli * be supported eventually 16905d65b64aSFlorian Fainelli */ 16915d65b64aSFlorian Fainelli if (is5325(priv) || is5365(priv)) 16925d65b64aSFlorian Fainelli return -EOPNOTSUPP; 16935d65b64aSFlorian Fainelli 16945d65b64aSFlorian Fainelli return 0; 16955d65b64aSFlorian Fainelli } 16965d65b64aSFlorian Fainelli EXPORT_SYMBOL(b53_mdb_prepare); 16975d65b64aSFlorian Fainelli 16985d65b64aSFlorian Fainelli void b53_mdb_add(struct dsa_switch *ds, int port, 16995d65b64aSFlorian Fainelli const struct switchdev_obj_port_mdb *mdb) 17005d65b64aSFlorian Fainelli { 17015d65b64aSFlorian Fainelli struct b53_device *priv = ds->priv; 17025d65b64aSFlorian Fainelli int ret; 17035d65b64aSFlorian Fainelli 17045d65b64aSFlorian Fainelli ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, true); 17055d65b64aSFlorian Fainelli if (ret) 17065d65b64aSFlorian Fainelli dev_err(ds->dev, "failed to add MDB entry\n"); 17075d65b64aSFlorian Fainelli } 17085d65b64aSFlorian Fainelli EXPORT_SYMBOL(b53_mdb_add); 17095d65b64aSFlorian Fainelli 17105d65b64aSFlorian Fainelli int b53_mdb_del(struct dsa_switch *ds, int port, 17115d65b64aSFlorian Fainelli const struct switchdev_obj_port_mdb *mdb) 17125d65b64aSFlorian Fainelli { 17135d65b64aSFlorian Fainelli struct b53_device *priv = ds->priv; 17145d65b64aSFlorian Fainelli int ret; 17155d65b64aSFlorian Fainelli 17165d65b64aSFlorian Fainelli ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, false); 17175d65b64aSFlorian Fainelli if (ret) 17185d65b64aSFlorian Fainelli dev_err(ds->dev, "failed to delete MDB entry\n"); 17195d65b64aSFlorian Fainelli 17205d65b64aSFlorian Fainelli return ret; 17215d65b64aSFlorian Fainelli } 17225d65b64aSFlorian Fainelli EXPORT_SYMBOL(b53_mdb_del); 17235d65b64aSFlorian Fainelli 1724ddd3a0c8SVivien Didelot int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br) 1725ff39c2d6SFlorian Fainelli { 172604bed143SVivien Didelot struct b53_device *dev = ds->priv; 172768bb8ea8SVivien Didelot s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index; 1728ff39c2d6SFlorian Fainelli u16 pvlan, reg; 1729ff39c2d6SFlorian Fainelli unsigned int i; 1730ff39c2d6SFlorian Fainelli 1731*31bfc2d4SFlorian Fainelli /* On 7278, port 7 which connects to the ASP should only receive 1732*31bfc2d4SFlorian Fainelli * traffic from matching CFP rules. 1733*31bfc2d4SFlorian Fainelli */ 1734*31bfc2d4SFlorian Fainelli if (dev->chip_id == BCM7278_DEVICE_ID && port == 7) 1735*31bfc2d4SFlorian Fainelli return -EINVAL; 1736*31bfc2d4SFlorian Fainelli 173748aea33aSFlorian Fainelli /* Make this port leave the all VLANs join since we will have proper 173848aea33aSFlorian Fainelli * VLAN entries from now on 173948aea33aSFlorian Fainelli */ 174048aea33aSFlorian Fainelli if (is58xx(dev)) { 174148aea33aSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, ®); 174248aea33aSFlorian Fainelli reg &= ~BIT(port); 174348aea33aSFlorian Fainelli if ((reg & BIT(cpu_port)) == BIT(cpu_port)) 174448aea33aSFlorian Fainelli reg &= ~BIT(cpu_port); 174548aea33aSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg); 174648aea33aSFlorian Fainelli } 174748aea33aSFlorian Fainelli 1748ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); 1749ff39c2d6SFlorian Fainelli 1750ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) { 1751c8652c83SVivien Didelot if (dsa_to_port(ds, i)->bridge_dev != br) 1752ff39c2d6SFlorian Fainelli continue; 1753ff39c2d6SFlorian Fainelli 1754ff39c2d6SFlorian Fainelli /* Add this local port to the remote port VLAN control 1755ff39c2d6SFlorian Fainelli * membership and update the remote port bitmask 1756ff39c2d6SFlorian Fainelli */ 1757ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), ®); 1758ff39c2d6SFlorian Fainelli reg |= BIT(port); 1759ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg); 1760ff39c2d6SFlorian Fainelli dev->ports[i].vlan_ctl_mask = reg; 1761ff39c2d6SFlorian Fainelli 1762ff39c2d6SFlorian Fainelli pvlan |= BIT(i); 1763ff39c2d6SFlorian Fainelli } 1764ff39c2d6SFlorian Fainelli 1765ff39c2d6SFlorian Fainelli /* Configure the local port VLAN control membership to include 1766ff39c2d6SFlorian Fainelli * remote ports and update the local port bitmask 1767ff39c2d6SFlorian Fainelli */ 1768ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); 1769ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = pvlan; 1770ff39c2d6SFlorian Fainelli 1771ff39c2d6SFlorian Fainelli return 0; 1772ff39c2d6SFlorian Fainelli } 17733117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_join); 1774ff39c2d6SFlorian Fainelli 1775f123f2fbSVivien Didelot void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *br) 1776ff39c2d6SFlorian Fainelli { 177704bed143SVivien Didelot struct b53_device *dev = ds->priv; 1778a2482d2cSFlorian Fainelli struct b53_vlan *vl = &dev->vlans[0]; 177968bb8ea8SVivien Didelot s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index; 1780ff39c2d6SFlorian Fainelli unsigned int i; 1781a2482d2cSFlorian Fainelli u16 pvlan, reg, pvid; 1782ff39c2d6SFlorian Fainelli 1783ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); 1784ff39c2d6SFlorian Fainelli 1785ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) { 1786ff39c2d6SFlorian Fainelli /* Don't touch the remaining ports */ 1787c8652c83SVivien Didelot if (dsa_to_port(ds, i)->bridge_dev != br) 1788ff39c2d6SFlorian Fainelli continue; 1789ff39c2d6SFlorian Fainelli 1790ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), ®); 1791ff39c2d6SFlorian Fainelli reg &= ~BIT(port); 1792ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg); 1793ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = reg; 1794ff39c2d6SFlorian Fainelli 1795ff39c2d6SFlorian Fainelli /* Prevent self removal to preserve isolation */ 1796ff39c2d6SFlorian Fainelli if (port != i) 1797ff39c2d6SFlorian Fainelli pvlan &= ~BIT(i); 1798ff39c2d6SFlorian Fainelli } 1799ff39c2d6SFlorian Fainelli 1800ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); 1801ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = pvlan; 1802a2482d2cSFlorian Fainelli 1803fea83353SFlorian Fainelli pvid = b53_default_pvid(dev); 1804a2482d2cSFlorian Fainelli 180548aea33aSFlorian Fainelli /* Make this port join all VLANs without VLAN entries */ 180648aea33aSFlorian Fainelli if (is58xx(dev)) { 180748aea33aSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, ®); 180848aea33aSFlorian Fainelli reg |= BIT(port); 180948aea33aSFlorian Fainelli if (!(reg & BIT(cpu_port))) 181048aea33aSFlorian Fainelli reg |= BIT(cpu_port); 181148aea33aSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg); 181248aea33aSFlorian Fainelli } else { 1813a2482d2cSFlorian Fainelli b53_get_vlan_entry(dev, pvid, vl); 1814c499696eSFlorian Fainelli vl->members |= BIT(port) | BIT(cpu_port); 1815c499696eSFlorian Fainelli vl->untag |= BIT(port) | BIT(cpu_port); 1816a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, pvid, vl); 1817ff39c2d6SFlorian Fainelli } 181848aea33aSFlorian Fainelli } 18193117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_leave); 1820ff39c2d6SFlorian Fainelli 18213117455dSFlorian Fainelli void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state) 1822ff39c2d6SFlorian Fainelli { 182304bed143SVivien Didelot struct b53_device *dev = ds->priv; 1824597698f1SVivien Didelot u8 hw_state; 1825ff39c2d6SFlorian Fainelli u8 reg; 1826ff39c2d6SFlorian Fainelli 1827ff39c2d6SFlorian Fainelli switch (state) { 1828ff39c2d6SFlorian Fainelli case BR_STATE_DISABLED: 1829ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_DIS_STATE; 1830ff39c2d6SFlorian Fainelli break; 1831ff39c2d6SFlorian Fainelli case BR_STATE_LISTENING: 1832ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_LISTEN_STATE; 1833ff39c2d6SFlorian Fainelli break; 1834ff39c2d6SFlorian Fainelli case BR_STATE_LEARNING: 1835ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_LEARN_STATE; 1836ff39c2d6SFlorian Fainelli break; 1837ff39c2d6SFlorian Fainelli case BR_STATE_FORWARDING: 1838ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_FWD_STATE; 1839ff39c2d6SFlorian Fainelli break; 1840ff39c2d6SFlorian Fainelli case BR_STATE_BLOCKING: 1841ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_BLOCK_STATE; 1842ff39c2d6SFlorian Fainelli break; 1843ff39c2d6SFlorian Fainelli default: 1844ff39c2d6SFlorian Fainelli dev_err(ds->dev, "invalid STP state: %d\n", state); 1845ff39c2d6SFlorian Fainelli return; 1846ff39c2d6SFlorian Fainelli } 1847ff39c2d6SFlorian Fainelli 1848ff39c2d6SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), ®); 1849ff39c2d6SFlorian Fainelli reg &= ~PORT_CTRL_STP_STATE_MASK; 1850ff39c2d6SFlorian Fainelli reg |= hw_state; 1851ff39c2d6SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg); 1852ff39c2d6SFlorian Fainelli } 18533117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_set_stp_state); 1854ff39c2d6SFlorian Fainelli 18553117455dSFlorian Fainelli void b53_br_fast_age(struct dsa_switch *ds, int port) 1856597698f1SVivien Didelot { 1857597698f1SVivien Didelot struct b53_device *dev = ds->priv; 1858597698f1SVivien Didelot 1859597698f1SVivien Didelot if (b53_fast_age_port(dev, port)) 1860597698f1SVivien Didelot dev_err(ds->dev, "fast ageing failed\n"); 1861597698f1SVivien Didelot } 18623117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_fast_age); 1863597698f1SVivien Didelot 186453568438SFlorian Fainelli int b53_br_egress_floods(struct dsa_switch *ds, int port, 186553568438SFlorian Fainelli bool unicast, bool multicast) 186653568438SFlorian Fainelli { 186753568438SFlorian Fainelli struct b53_device *dev = ds->priv; 186853568438SFlorian Fainelli u16 uc, mc; 186953568438SFlorian Fainelli 187063cc54a6SFlorian Fainelli b53_read16(dev, B53_CTRL_PAGE, B53_UC_FLOOD_MASK, &uc); 187153568438SFlorian Fainelli if (unicast) 187253568438SFlorian Fainelli uc |= BIT(port); 187353568438SFlorian Fainelli else 187453568438SFlorian Fainelli uc &= ~BIT(port); 187563cc54a6SFlorian Fainelli b53_write16(dev, B53_CTRL_PAGE, B53_UC_FLOOD_MASK, uc); 187653568438SFlorian Fainelli 187763cc54a6SFlorian Fainelli b53_read16(dev, B53_CTRL_PAGE, B53_MC_FLOOD_MASK, &mc); 187853568438SFlorian Fainelli if (multicast) 187953568438SFlorian Fainelli mc |= BIT(port); 188053568438SFlorian Fainelli else 188153568438SFlorian Fainelli mc &= ~BIT(port); 188263cc54a6SFlorian Fainelli b53_write16(dev, B53_CTRL_PAGE, B53_MC_FLOOD_MASK, mc); 188363cc54a6SFlorian Fainelli 188463cc54a6SFlorian Fainelli b53_read16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, &mc); 188563cc54a6SFlorian Fainelli if (multicast) 188663cc54a6SFlorian Fainelli mc |= BIT(port); 188763cc54a6SFlorian Fainelli else 188863cc54a6SFlorian Fainelli mc &= ~BIT(port); 188963cc54a6SFlorian Fainelli b53_write16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, mc); 189053568438SFlorian Fainelli 189153568438SFlorian Fainelli return 0; 189253568438SFlorian Fainelli 189353568438SFlorian Fainelli } 189453568438SFlorian Fainelli EXPORT_SYMBOL(b53_br_egress_floods); 189553568438SFlorian Fainelli 1896c7d28c9dSFlorian Fainelli static bool b53_possible_cpu_port(struct dsa_switch *ds, int port) 18977edc58d6SFlorian Fainelli { 18987edc58d6SFlorian Fainelli /* Broadcom switches will accept enabling Broadcom tags on the 18997edc58d6SFlorian Fainelli * following ports: 5, 7 and 8, any other port is not supported 19007edc58d6SFlorian Fainelli */ 19015ed4e3ebSFlorian Fainelli switch (port) { 19025ed4e3ebSFlorian Fainelli case B53_CPU_PORT_25: 19035ed4e3ebSFlorian Fainelli case 7: 19045ed4e3ebSFlorian Fainelli case B53_CPU_PORT: 19057edc58d6SFlorian Fainelli return true; 19067edc58d6SFlorian Fainelli } 19077edc58d6SFlorian Fainelli 19085ed4e3ebSFlorian Fainelli return false; 19095ed4e3ebSFlorian Fainelli } 19105ed4e3ebSFlorian Fainelli 19118fab459eSFlorian Fainelli static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port, 19128fab459eSFlorian Fainelli enum dsa_tag_protocol tag_protocol) 1913c7d28c9dSFlorian Fainelli { 1914c7d28c9dSFlorian Fainelli bool ret = b53_possible_cpu_port(ds, port); 1915c7d28c9dSFlorian Fainelli 19168fab459eSFlorian Fainelli if (!ret) { 1917c7d28c9dSFlorian Fainelli dev_warn(ds->dev, "Port %d is not Broadcom tag capable\n", 1918c7d28c9dSFlorian Fainelli port); 1919c7d28c9dSFlorian Fainelli return ret; 1920c7d28c9dSFlorian Fainelli } 1921c7d28c9dSFlorian Fainelli 19228fab459eSFlorian Fainelli switch (tag_protocol) { 19238fab459eSFlorian Fainelli case DSA_TAG_PROTO_BRCM: 19248fab459eSFlorian Fainelli case DSA_TAG_PROTO_BRCM_PREPEND: 19258fab459eSFlorian Fainelli dev_warn(ds->dev, 19268fab459eSFlorian Fainelli "Port %d is stacked to Broadcom tag switch\n", port); 19278fab459eSFlorian Fainelli ret = false; 19288fab459eSFlorian Fainelli break; 19298fab459eSFlorian Fainelli default: 19308fab459eSFlorian Fainelli ret = true; 19318fab459eSFlorian Fainelli break; 19328fab459eSFlorian Fainelli } 19338fab459eSFlorian Fainelli 19348fab459eSFlorian Fainelli return ret; 19358fab459eSFlorian Fainelli } 19368fab459eSFlorian Fainelli 19374d776482SFlorian Fainelli enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port, 19384d776482SFlorian Fainelli enum dsa_tag_protocol mprot) 19397b314362SAndrew Lunn { 19407edc58d6SFlorian Fainelli struct b53_device *dev = ds->priv; 19417edc58d6SFlorian Fainelli 194254e98b5dSFlorian Fainelli /* Older models (5325, 5365) support a different tag format that we do 19438fab459eSFlorian Fainelli * not support in net/dsa/tag_brcm.c yet. 19447edc58d6SFlorian Fainelli */ 19458fab459eSFlorian Fainelli if (is5325(dev) || is5365(dev) || 19468fab459eSFlorian Fainelli !b53_can_enable_brcm_tags(ds, port, mprot)) { 19474d776482SFlorian Fainelli dev->tag_protocol = DSA_TAG_PROTO_NONE; 19484d776482SFlorian Fainelli goto out; 19494d776482SFlorian Fainelli } 195011606039SFlorian Fainelli 195111606039SFlorian Fainelli /* Broadcom BCM58xx chips have a flow accelerator on Port 8 195211606039SFlorian Fainelli * which requires us to use the prepended Broadcom tag type 195311606039SFlorian Fainelli */ 19544d776482SFlorian Fainelli if (dev->chip_id == BCM58XX_DEVICE_ID && port == B53_CPU_PORT) { 19554d776482SFlorian Fainelli dev->tag_protocol = DSA_TAG_PROTO_BRCM_PREPEND; 19564d776482SFlorian Fainelli goto out; 19574d776482SFlorian Fainelli } 195811606039SFlorian Fainelli 19594d776482SFlorian Fainelli dev->tag_protocol = DSA_TAG_PROTO_BRCM; 19604d776482SFlorian Fainelli out: 19614d776482SFlorian Fainelli return dev->tag_protocol; 19627b314362SAndrew Lunn } 19639f66816aSFlorian Fainelli EXPORT_SYMBOL(b53_get_tag_protocol); 19647b314362SAndrew Lunn 1965ed3af5fdSFlorian Fainelli int b53_mirror_add(struct dsa_switch *ds, int port, 1966ed3af5fdSFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror, bool ingress) 1967ed3af5fdSFlorian Fainelli { 1968ed3af5fdSFlorian Fainelli struct b53_device *dev = ds->priv; 1969ed3af5fdSFlorian Fainelli u16 reg, loc; 1970ed3af5fdSFlorian Fainelli 1971ed3af5fdSFlorian Fainelli if (ingress) 1972ed3af5fdSFlorian Fainelli loc = B53_IG_MIR_CTL; 1973ed3af5fdSFlorian Fainelli else 1974ed3af5fdSFlorian Fainelli loc = B53_EG_MIR_CTL; 1975ed3af5fdSFlorian Fainelli 1976ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, loc, ®); 1977ed3af5fdSFlorian Fainelli reg |= BIT(port); 1978ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, loc, reg); 1979ed3af5fdSFlorian Fainelli 1980ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®); 1981ed3af5fdSFlorian Fainelli reg &= ~CAP_PORT_MASK; 1982ed3af5fdSFlorian Fainelli reg |= mirror->to_local_port; 1983ed3af5fdSFlorian Fainelli reg |= MIRROR_EN; 1984ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg); 1985ed3af5fdSFlorian Fainelli 1986ed3af5fdSFlorian Fainelli return 0; 1987ed3af5fdSFlorian Fainelli } 1988ed3af5fdSFlorian Fainelli EXPORT_SYMBOL(b53_mirror_add); 1989ed3af5fdSFlorian Fainelli 1990ed3af5fdSFlorian Fainelli void b53_mirror_del(struct dsa_switch *ds, int port, 1991ed3af5fdSFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror) 1992ed3af5fdSFlorian Fainelli { 1993ed3af5fdSFlorian Fainelli struct b53_device *dev = ds->priv; 1994ed3af5fdSFlorian Fainelli bool loc_disable = false, other_loc_disable = false; 1995ed3af5fdSFlorian Fainelli u16 reg, loc; 1996ed3af5fdSFlorian Fainelli 1997ed3af5fdSFlorian Fainelli if (mirror->ingress) 1998ed3af5fdSFlorian Fainelli loc = B53_IG_MIR_CTL; 1999ed3af5fdSFlorian Fainelli else 2000ed3af5fdSFlorian Fainelli loc = B53_EG_MIR_CTL; 2001ed3af5fdSFlorian Fainelli 2002ed3af5fdSFlorian Fainelli /* Update the desired ingress/egress register */ 2003ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, loc, ®); 2004ed3af5fdSFlorian Fainelli reg &= ~BIT(port); 2005ed3af5fdSFlorian Fainelli if (!(reg & MIRROR_MASK)) 2006ed3af5fdSFlorian Fainelli loc_disable = true; 2007ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, loc, reg); 2008ed3af5fdSFlorian Fainelli 2009ed3af5fdSFlorian Fainelli /* Now look at the other one to know if we can disable mirroring 2010ed3af5fdSFlorian Fainelli * entirely 2011ed3af5fdSFlorian Fainelli */ 2012ed3af5fdSFlorian Fainelli if (mirror->ingress) 2013ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_EG_MIR_CTL, ®); 2014ed3af5fdSFlorian Fainelli else 2015ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_IG_MIR_CTL, ®); 2016ed3af5fdSFlorian Fainelli if (!(reg & MIRROR_MASK)) 2017ed3af5fdSFlorian Fainelli other_loc_disable = true; 2018ed3af5fdSFlorian Fainelli 2019ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®); 2020ed3af5fdSFlorian Fainelli /* Both no longer have ports, let's disable mirroring */ 2021ed3af5fdSFlorian Fainelli if (loc_disable && other_loc_disable) { 2022ed3af5fdSFlorian Fainelli reg &= ~MIRROR_EN; 2023ed3af5fdSFlorian Fainelli reg &= ~mirror->to_local_port; 2024ed3af5fdSFlorian Fainelli } 2025ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg); 2026ed3af5fdSFlorian Fainelli } 2027ed3af5fdSFlorian Fainelli EXPORT_SYMBOL(b53_mirror_del); 2028ed3af5fdSFlorian Fainelli 202922256b0aSFlorian Fainelli void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable) 203022256b0aSFlorian Fainelli { 203122256b0aSFlorian Fainelli struct b53_device *dev = ds->priv; 203222256b0aSFlorian Fainelli u16 reg; 203322256b0aSFlorian Fainelli 203422256b0aSFlorian Fainelli b53_read16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, ®); 203522256b0aSFlorian Fainelli if (enable) 203622256b0aSFlorian Fainelli reg |= BIT(port); 203722256b0aSFlorian Fainelli else 203822256b0aSFlorian Fainelli reg &= ~BIT(port); 203922256b0aSFlorian Fainelli b53_write16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, reg); 204022256b0aSFlorian Fainelli } 204122256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_eee_enable_set); 204222256b0aSFlorian Fainelli 204322256b0aSFlorian Fainelli 204422256b0aSFlorian Fainelli /* Returns 0 if EEE was not enabled, or 1 otherwise 204522256b0aSFlorian Fainelli */ 204622256b0aSFlorian Fainelli int b53_eee_init(struct dsa_switch *ds, int port, struct phy_device *phy) 204722256b0aSFlorian Fainelli { 204822256b0aSFlorian Fainelli int ret; 204922256b0aSFlorian Fainelli 205022256b0aSFlorian Fainelli ret = phy_init_eee(phy, 0); 205122256b0aSFlorian Fainelli if (ret) 205222256b0aSFlorian Fainelli return 0; 205322256b0aSFlorian Fainelli 205422256b0aSFlorian Fainelli b53_eee_enable_set(ds, port, true); 205522256b0aSFlorian Fainelli 205622256b0aSFlorian Fainelli return 1; 205722256b0aSFlorian Fainelli } 205822256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_eee_init); 205922256b0aSFlorian Fainelli 206022256b0aSFlorian Fainelli int b53_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e) 206122256b0aSFlorian Fainelli { 206222256b0aSFlorian Fainelli struct b53_device *dev = ds->priv; 206322256b0aSFlorian Fainelli struct ethtool_eee *p = &dev->ports[port].eee; 206422256b0aSFlorian Fainelli u16 reg; 206522256b0aSFlorian Fainelli 206622256b0aSFlorian Fainelli if (is5325(dev) || is5365(dev)) 206722256b0aSFlorian Fainelli return -EOPNOTSUPP; 206822256b0aSFlorian Fainelli 206922256b0aSFlorian Fainelli b53_read16(dev, B53_EEE_PAGE, B53_EEE_LPI_INDICATE, ®); 207022256b0aSFlorian Fainelli e->eee_enabled = p->eee_enabled; 207122256b0aSFlorian Fainelli e->eee_active = !!(reg & BIT(port)); 207222256b0aSFlorian Fainelli 207322256b0aSFlorian Fainelli return 0; 207422256b0aSFlorian Fainelli } 207522256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_get_mac_eee); 207622256b0aSFlorian Fainelli 207722256b0aSFlorian Fainelli int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e) 207822256b0aSFlorian Fainelli { 207922256b0aSFlorian Fainelli struct b53_device *dev = ds->priv; 208022256b0aSFlorian Fainelli struct ethtool_eee *p = &dev->ports[port].eee; 208122256b0aSFlorian Fainelli 208222256b0aSFlorian Fainelli if (is5325(dev) || is5365(dev)) 208322256b0aSFlorian Fainelli return -EOPNOTSUPP; 208422256b0aSFlorian Fainelli 208522256b0aSFlorian Fainelli p->eee_enabled = e->eee_enabled; 208622256b0aSFlorian Fainelli b53_eee_enable_set(ds, port, e->eee_enabled); 208722256b0aSFlorian Fainelli 208822256b0aSFlorian Fainelli return 0; 208922256b0aSFlorian Fainelli } 209022256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_set_mac_eee); 209122256b0aSFlorian Fainelli 20926ae5834bSMurali Krishna Policharla static int b53_change_mtu(struct dsa_switch *ds, int port, int mtu) 20936ae5834bSMurali Krishna Policharla { 20946ae5834bSMurali Krishna Policharla struct b53_device *dev = ds->priv; 20956ae5834bSMurali Krishna Policharla bool enable_jumbo; 20966ae5834bSMurali Krishna Policharla bool allow_10_100; 20976ae5834bSMurali Krishna Policharla 20986ae5834bSMurali Krishna Policharla if (is5325(dev) || is5365(dev)) 20996ae5834bSMurali Krishna Policharla return -EOPNOTSUPP; 21006ae5834bSMurali Krishna Policharla 21016ae5834bSMurali Krishna Policharla enable_jumbo = (mtu >= JMS_MIN_SIZE); 21026ae5834bSMurali Krishna Policharla allow_10_100 = (dev->chip_id == BCM583XX_DEVICE_ID); 21036ae5834bSMurali Krishna Policharla 21046ae5834bSMurali Krishna Policharla return b53_set_jumbo(dev, enable_jumbo, allow_10_100); 21056ae5834bSMurali Krishna Policharla } 21066ae5834bSMurali Krishna Policharla 21076ae5834bSMurali Krishna Policharla static int b53_get_max_mtu(struct dsa_switch *ds, int port) 21086ae5834bSMurali Krishna Policharla { 21096ae5834bSMurali Krishna Policharla return JMS_MAX_SIZE; 21106ae5834bSMurali Krishna Policharla } 21116ae5834bSMurali Krishna Policharla 2112a82f67afSFlorian Fainelli static const struct dsa_switch_ops b53_switch_ops = { 21137b314362SAndrew Lunn .get_tag_protocol = b53_get_tag_protocol, 2114967dd82fSFlorian Fainelli .setup = b53_setup, 2115967dd82fSFlorian Fainelli .get_strings = b53_get_strings, 2116967dd82fSFlorian Fainelli .get_ethtool_stats = b53_get_ethtool_stats, 2117967dd82fSFlorian Fainelli .get_sset_count = b53_get_sset_count, 2118c7d28c9dSFlorian Fainelli .get_ethtool_phy_stats = b53_get_ethtool_phy_stats, 2119967dd82fSFlorian Fainelli .phy_read = b53_phy_read16, 2120967dd82fSFlorian Fainelli .phy_write = b53_phy_write16, 2121967dd82fSFlorian Fainelli .adjust_link = b53_adjust_link, 2122a8e8b985SFlorian Fainelli .phylink_validate = b53_phylink_validate, 2123a8e8b985SFlorian Fainelli .phylink_mac_link_state = b53_phylink_mac_link_state, 2124a8e8b985SFlorian Fainelli .phylink_mac_config = b53_phylink_mac_config, 2125a8e8b985SFlorian Fainelli .phylink_mac_an_restart = b53_phylink_mac_an_restart, 2126a8e8b985SFlorian Fainelli .phylink_mac_link_down = b53_phylink_mac_link_down, 2127a8e8b985SFlorian Fainelli .phylink_mac_link_up = b53_phylink_mac_link_up, 2128967dd82fSFlorian Fainelli .port_enable = b53_enable_port, 2129967dd82fSFlorian Fainelli .port_disable = b53_disable_port, 2130f43a2dbeSFlorian Fainelli .get_mac_eee = b53_get_mac_eee, 2131f43a2dbeSFlorian Fainelli .set_mac_eee = b53_set_mac_eee, 2132ff39c2d6SFlorian Fainelli .port_bridge_join = b53_br_join, 2133ff39c2d6SFlorian Fainelli .port_bridge_leave = b53_br_leave, 2134ff39c2d6SFlorian Fainelli .port_stp_state_set = b53_br_set_stp_state, 2135597698f1SVivien Didelot .port_fast_age = b53_br_fast_age, 213653568438SFlorian Fainelli .port_egress_floods = b53_br_egress_floods, 2137a2482d2cSFlorian Fainelli .port_vlan_filtering = b53_vlan_filtering, 2138a2482d2cSFlorian Fainelli .port_vlan_prepare = b53_vlan_prepare, 2139a2482d2cSFlorian Fainelli .port_vlan_add = b53_vlan_add, 2140a2482d2cSFlorian Fainelli .port_vlan_del = b53_vlan_del, 21411da6df85SFlorian Fainelli .port_fdb_dump = b53_fdb_dump, 21421da6df85SFlorian Fainelli .port_fdb_add = b53_fdb_add, 21431da6df85SFlorian Fainelli .port_fdb_del = b53_fdb_del, 2144ed3af5fdSFlorian Fainelli .port_mirror_add = b53_mirror_add, 2145ed3af5fdSFlorian Fainelli .port_mirror_del = b53_mirror_del, 21465d65b64aSFlorian Fainelli .port_mdb_prepare = b53_mdb_prepare, 21475d65b64aSFlorian Fainelli .port_mdb_add = b53_mdb_add, 21485d65b64aSFlorian Fainelli .port_mdb_del = b53_mdb_del, 21496ae5834bSMurali Krishna Policharla .port_max_mtu = b53_get_max_mtu, 21506ae5834bSMurali Krishna Policharla .port_change_mtu = b53_change_mtu, 2151967dd82fSFlorian Fainelli }; 2152967dd82fSFlorian Fainelli 2153967dd82fSFlorian Fainelli struct b53_chip_data { 2154967dd82fSFlorian Fainelli u32 chip_id; 2155967dd82fSFlorian Fainelli const char *dev_name; 2156967dd82fSFlorian Fainelli u16 vlans; 2157967dd82fSFlorian Fainelli u16 enabled_ports; 2158967dd82fSFlorian Fainelli u8 cpu_port; 2159967dd82fSFlorian Fainelli u8 vta_regs[3]; 21601da6df85SFlorian Fainelli u8 arl_entries; 2161967dd82fSFlorian Fainelli u8 duplex_reg; 2162967dd82fSFlorian Fainelli u8 jumbo_pm_reg; 2163967dd82fSFlorian Fainelli u8 jumbo_size_reg; 2164967dd82fSFlorian Fainelli }; 2165967dd82fSFlorian Fainelli 2166967dd82fSFlorian Fainelli #define B53_VTA_REGS \ 2167967dd82fSFlorian Fainelli { B53_VT_ACCESS, B53_VT_INDEX, B53_VT_ENTRY } 2168967dd82fSFlorian Fainelli #define B53_VTA_REGS_9798 \ 2169967dd82fSFlorian Fainelli { B53_VT_ACCESS_9798, B53_VT_INDEX_9798, B53_VT_ENTRY_9798 } 2170967dd82fSFlorian Fainelli #define B53_VTA_REGS_63XX \ 2171967dd82fSFlorian Fainelli { B53_VT_ACCESS_63XX, B53_VT_INDEX_63XX, B53_VT_ENTRY_63XX } 2172967dd82fSFlorian Fainelli 2173967dd82fSFlorian Fainelli static const struct b53_chip_data b53_switch_chips[] = { 2174967dd82fSFlorian Fainelli { 2175967dd82fSFlorian Fainelli .chip_id = BCM5325_DEVICE_ID, 2176967dd82fSFlorian Fainelli .dev_name = "BCM5325", 2177967dd82fSFlorian Fainelli .vlans = 16, 2178967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 21791da6df85SFlorian Fainelli .arl_entries = 2, 2180967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, 2181967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_FE, 2182967dd82fSFlorian Fainelli }, 2183967dd82fSFlorian Fainelli { 2184967dd82fSFlorian Fainelli .chip_id = BCM5365_DEVICE_ID, 2185967dd82fSFlorian Fainelli .dev_name = "BCM5365", 2186967dd82fSFlorian Fainelli .vlans = 256, 2187967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 21881da6df85SFlorian Fainelli .arl_entries = 2, 2189967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, 2190967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_FE, 2191967dd82fSFlorian Fainelli }, 2192967dd82fSFlorian Fainelli { 2193a95691bcSDamien Thébault .chip_id = BCM5389_DEVICE_ID, 2194a95691bcSDamien Thébault .dev_name = "BCM5389", 2195a95691bcSDamien Thébault .vlans = 4096, 2196a95691bcSDamien Thébault .enabled_ports = 0x1f, 2197a95691bcSDamien Thébault .arl_entries = 4, 2198a95691bcSDamien Thébault .cpu_port = B53_CPU_PORT, 2199a95691bcSDamien Thébault .vta_regs = B53_VTA_REGS, 2200a95691bcSDamien Thébault .duplex_reg = B53_DUPLEX_STAT_GE, 2201a95691bcSDamien Thébault .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2202a95691bcSDamien Thébault .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2203a95691bcSDamien Thébault }, 2204a95691bcSDamien Thébault { 2205967dd82fSFlorian Fainelli .chip_id = BCM5395_DEVICE_ID, 2206967dd82fSFlorian Fainelli .dev_name = "BCM5395", 2207967dd82fSFlorian Fainelli .vlans = 4096, 2208967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 22091da6df85SFlorian Fainelli .arl_entries = 4, 2210967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2211967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2212967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2213967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2214967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2215967dd82fSFlorian Fainelli }, 2216967dd82fSFlorian Fainelli { 2217967dd82fSFlorian Fainelli .chip_id = BCM5397_DEVICE_ID, 2218967dd82fSFlorian Fainelli .dev_name = "BCM5397", 2219967dd82fSFlorian Fainelli .vlans = 4096, 2220967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 22211da6df85SFlorian Fainelli .arl_entries = 4, 2222967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2223967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_9798, 2224967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2225967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2226967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2227967dd82fSFlorian Fainelli }, 2228967dd82fSFlorian Fainelli { 2229967dd82fSFlorian Fainelli .chip_id = BCM5398_DEVICE_ID, 2230967dd82fSFlorian Fainelli .dev_name = "BCM5398", 2231967dd82fSFlorian Fainelli .vlans = 4096, 2232967dd82fSFlorian Fainelli .enabled_ports = 0x7f, 22331da6df85SFlorian Fainelli .arl_entries = 4, 2234967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2235967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_9798, 2236967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2237967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2238967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2239967dd82fSFlorian Fainelli }, 2240967dd82fSFlorian Fainelli { 2241967dd82fSFlorian Fainelli .chip_id = BCM53115_DEVICE_ID, 2242967dd82fSFlorian Fainelli .dev_name = "BCM53115", 2243967dd82fSFlorian Fainelli .vlans = 4096, 2244967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 22451da6df85SFlorian Fainelli .arl_entries = 4, 2246967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2247967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2248967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2249967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2250967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2251967dd82fSFlorian Fainelli }, 2252967dd82fSFlorian Fainelli { 2253967dd82fSFlorian Fainelli .chip_id = BCM53125_DEVICE_ID, 2254967dd82fSFlorian Fainelli .dev_name = "BCM53125", 2255967dd82fSFlorian Fainelli .vlans = 4096, 2256967dd82fSFlorian Fainelli .enabled_ports = 0xff, 2257be35e8c5SFlorian Fainelli .arl_entries = 4, 2258967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2259967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2260967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2261967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2262967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2263967dd82fSFlorian Fainelli }, 2264967dd82fSFlorian Fainelli { 2265967dd82fSFlorian Fainelli .chip_id = BCM53128_DEVICE_ID, 2266967dd82fSFlorian Fainelli .dev_name = "BCM53128", 2267967dd82fSFlorian Fainelli .vlans = 4096, 2268967dd82fSFlorian Fainelli .enabled_ports = 0x1ff, 22691da6df85SFlorian Fainelli .arl_entries = 4, 2270967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2271967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2272967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2273967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2274967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2275967dd82fSFlorian Fainelli }, 2276967dd82fSFlorian Fainelli { 2277967dd82fSFlorian Fainelli .chip_id = BCM63XX_DEVICE_ID, 2278967dd82fSFlorian Fainelli .dev_name = "BCM63xx", 2279967dd82fSFlorian Fainelli .vlans = 4096, 2280967dd82fSFlorian Fainelli .enabled_ports = 0, /* pdata must provide them */ 22811da6df85SFlorian Fainelli .arl_entries = 4, 2282967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2283967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_63XX, 2284967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_63XX, 2285967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK_63XX, 2286967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE_63XX, 2287967dd82fSFlorian Fainelli }, 2288967dd82fSFlorian Fainelli { 2289967dd82fSFlorian Fainelli .chip_id = BCM53010_DEVICE_ID, 2290967dd82fSFlorian Fainelli .dev_name = "BCM53010", 2291967dd82fSFlorian Fainelli .vlans = 4096, 2292967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 22931da6df85SFlorian Fainelli .arl_entries = 4, 2294967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2295967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2296967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2297967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2298967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2299967dd82fSFlorian Fainelli }, 2300967dd82fSFlorian Fainelli { 2301967dd82fSFlorian Fainelli .chip_id = BCM53011_DEVICE_ID, 2302967dd82fSFlorian Fainelli .dev_name = "BCM53011", 2303967dd82fSFlorian Fainelli .vlans = 4096, 2304967dd82fSFlorian Fainelli .enabled_ports = 0x1bf, 23051da6df85SFlorian Fainelli .arl_entries = 4, 2306967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2307967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2308967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2309967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2310967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2311967dd82fSFlorian Fainelli }, 2312967dd82fSFlorian Fainelli { 2313967dd82fSFlorian Fainelli .chip_id = BCM53012_DEVICE_ID, 2314967dd82fSFlorian Fainelli .dev_name = "BCM53012", 2315967dd82fSFlorian Fainelli .vlans = 4096, 2316967dd82fSFlorian Fainelli .enabled_ports = 0x1bf, 23171da6df85SFlorian Fainelli .arl_entries = 4, 2318967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2319967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2320967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2321967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2322967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2323967dd82fSFlorian Fainelli }, 2324967dd82fSFlorian Fainelli { 2325967dd82fSFlorian Fainelli .chip_id = BCM53018_DEVICE_ID, 2326967dd82fSFlorian Fainelli .dev_name = "BCM53018", 2327967dd82fSFlorian Fainelli .vlans = 4096, 2328967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 23291da6df85SFlorian Fainelli .arl_entries = 4, 2330967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2331967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2332967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2333967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2334967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2335967dd82fSFlorian Fainelli }, 2336967dd82fSFlorian Fainelli { 2337967dd82fSFlorian Fainelli .chip_id = BCM53019_DEVICE_ID, 2338967dd82fSFlorian Fainelli .dev_name = "BCM53019", 2339967dd82fSFlorian Fainelli .vlans = 4096, 2340967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 23411da6df85SFlorian Fainelli .arl_entries = 4, 2342967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2343967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2344967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2345967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2346967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2347967dd82fSFlorian Fainelli }, 2348991a36bbSFlorian Fainelli { 2349991a36bbSFlorian Fainelli .chip_id = BCM58XX_DEVICE_ID, 2350991a36bbSFlorian Fainelli .dev_name = "BCM585xx/586xx/88312", 2351991a36bbSFlorian Fainelli .vlans = 4096, 2352991a36bbSFlorian Fainelli .enabled_ports = 0x1ff, 2353991a36bbSFlorian Fainelli .arl_entries = 4, 2354bfcda65cSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2355991a36bbSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2356991a36bbSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2357991a36bbSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2358991a36bbSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2359991a36bbSFlorian Fainelli }, 2360130401d9SFlorian Fainelli { 23615040cc99SArun Parameswaran .chip_id = BCM583XX_DEVICE_ID, 23625040cc99SArun Parameswaran .dev_name = "BCM583xx/11360", 23635040cc99SArun Parameswaran .vlans = 4096, 23645040cc99SArun Parameswaran .enabled_ports = 0x103, 23655040cc99SArun Parameswaran .arl_entries = 4, 23665040cc99SArun Parameswaran .cpu_port = B53_CPU_PORT, 23675040cc99SArun Parameswaran .vta_regs = B53_VTA_REGS, 23685040cc99SArun Parameswaran .duplex_reg = B53_DUPLEX_STAT_GE, 23695040cc99SArun Parameswaran .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 23705040cc99SArun Parameswaran .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 23715040cc99SArun Parameswaran }, 23725040cc99SArun Parameswaran { 2373130401d9SFlorian Fainelli .chip_id = BCM7445_DEVICE_ID, 2374130401d9SFlorian Fainelli .dev_name = "BCM7445", 2375130401d9SFlorian Fainelli .vlans = 4096, 2376130401d9SFlorian Fainelli .enabled_ports = 0x1ff, 2377130401d9SFlorian Fainelli .arl_entries = 4, 2378130401d9SFlorian Fainelli .cpu_port = B53_CPU_PORT, 2379130401d9SFlorian Fainelli .vta_regs = B53_VTA_REGS, 2380130401d9SFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2381130401d9SFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2382130401d9SFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2383130401d9SFlorian Fainelli }, 23840fe99338SFlorian Fainelli { 23850fe99338SFlorian Fainelli .chip_id = BCM7278_DEVICE_ID, 23860fe99338SFlorian Fainelli .dev_name = "BCM7278", 23870fe99338SFlorian Fainelli .vlans = 4096, 23880fe99338SFlorian Fainelli .enabled_ports = 0x1ff, 23890fe99338SFlorian Fainelli .arl_entries= 4, 23900fe99338SFlorian Fainelli .cpu_port = B53_CPU_PORT, 23910fe99338SFlorian Fainelli .vta_regs = B53_VTA_REGS, 23920fe99338SFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 23930fe99338SFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 23940fe99338SFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 23950fe99338SFlorian Fainelli }, 2396967dd82fSFlorian Fainelli }; 2397967dd82fSFlorian Fainelli 2398967dd82fSFlorian Fainelli static int b53_switch_init(struct b53_device *dev) 2399967dd82fSFlorian Fainelli { 2400967dd82fSFlorian Fainelli unsigned int i; 2401967dd82fSFlorian Fainelli int ret; 2402967dd82fSFlorian Fainelli 2403967dd82fSFlorian Fainelli for (i = 0; i < ARRAY_SIZE(b53_switch_chips); i++) { 2404967dd82fSFlorian Fainelli const struct b53_chip_data *chip = &b53_switch_chips[i]; 2405967dd82fSFlorian Fainelli 2406967dd82fSFlorian Fainelli if (chip->chip_id == dev->chip_id) { 2407967dd82fSFlorian Fainelli if (!dev->enabled_ports) 2408967dd82fSFlorian Fainelli dev->enabled_ports = chip->enabled_ports; 2409967dd82fSFlorian Fainelli dev->name = chip->dev_name; 2410967dd82fSFlorian Fainelli dev->duplex_reg = chip->duplex_reg; 2411967dd82fSFlorian Fainelli dev->vta_regs[0] = chip->vta_regs[0]; 2412967dd82fSFlorian Fainelli dev->vta_regs[1] = chip->vta_regs[1]; 2413967dd82fSFlorian Fainelli dev->vta_regs[2] = chip->vta_regs[2]; 2414967dd82fSFlorian Fainelli dev->jumbo_pm_reg = chip->jumbo_pm_reg; 2415967dd82fSFlorian Fainelli dev->cpu_port = chip->cpu_port; 2416967dd82fSFlorian Fainelli dev->num_vlans = chip->vlans; 24171da6df85SFlorian Fainelli dev->num_arl_entries = chip->arl_entries; 2418967dd82fSFlorian Fainelli break; 2419967dd82fSFlorian Fainelli } 2420967dd82fSFlorian Fainelli } 2421967dd82fSFlorian Fainelli 2422967dd82fSFlorian Fainelli /* check which BCM5325x version we have */ 2423967dd82fSFlorian Fainelli if (is5325(dev)) { 2424967dd82fSFlorian Fainelli u8 vc4; 2425967dd82fSFlorian Fainelli 2426967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4); 2427967dd82fSFlorian Fainelli 2428967dd82fSFlorian Fainelli /* check reserved bits */ 2429967dd82fSFlorian Fainelli switch (vc4 & 3) { 2430967dd82fSFlorian Fainelli case 1: 2431967dd82fSFlorian Fainelli /* BCM5325E */ 2432967dd82fSFlorian Fainelli break; 2433967dd82fSFlorian Fainelli case 3: 2434967dd82fSFlorian Fainelli /* BCM5325F - do not use port 4 */ 2435967dd82fSFlorian Fainelli dev->enabled_ports &= ~BIT(4); 2436967dd82fSFlorian Fainelli break; 2437967dd82fSFlorian Fainelli default: 2438967dd82fSFlorian Fainelli /* On the BCM47XX SoCs this is the supported internal switch.*/ 2439967dd82fSFlorian Fainelli #ifndef CONFIG_BCM47XX 2440967dd82fSFlorian Fainelli /* BCM5325M */ 2441967dd82fSFlorian Fainelli return -EINVAL; 2442967dd82fSFlorian Fainelli #else 2443967dd82fSFlorian Fainelli break; 2444967dd82fSFlorian Fainelli #endif 2445967dd82fSFlorian Fainelli } 2446967dd82fSFlorian Fainelli } else if (dev->chip_id == BCM53115_DEVICE_ID) { 2447967dd82fSFlorian Fainelli u64 strap_value; 2448967dd82fSFlorian Fainelli 2449967dd82fSFlorian Fainelli b53_read48(dev, B53_STAT_PAGE, B53_STRAP_VALUE, &strap_value); 2450967dd82fSFlorian Fainelli /* use second IMP port if GMII is enabled */ 2451967dd82fSFlorian Fainelli if (strap_value & SV_GMII_CTRL_115) 2452967dd82fSFlorian Fainelli dev->cpu_port = 5; 2453967dd82fSFlorian Fainelli } 2454967dd82fSFlorian Fainelli 2455967dd82fSFlorian Fainelli /* cpu port is always last */ 2456967dd82fSFlorian Fainelli dev->num_ports = dev->cpu_port + 1; 2457967dd82fSFlorian Fainelli dev->enabled_ports |= BIT(dev->cpu_port); 2458967dd82fSFlorian Fainelli 2459c7d28c9dSFlorian Fainelli /* Include non standard CPU port built-in PHYs to be probed */ 2460c7d28c9dSFlorian Fainelli if (is539x(dev) || is531x5(dev)) { 2461c7d28c9dSFlorian Fainelli for (i = 0; i < dev->num_ports; i++) { 2462c7d28c9dSFlorian Fainelli if (!(dev->ds->phys_mii_mask & BIT(i)) && 2463c7d28c9dSFlorian Fainelli !b53_possible_cpu_port(dev->ds, i)) 2464c7d28c9dSFlorian Fainelli dev->ds->phys_mii_mask |= BIT(i); 2465c7d28c9dSFlorian Fainelli } 2466c7d28c9dSFlorian Fainelli } 2467c7d28c9dSFlorian Fainelli 2468a86854d0SKees Cook dev->ports = devm_kcalloc(dev->dev, 2469a86854d0SKees Cook dev->num_ports, sizeof(struct b53_port), 2470967dd82fSFlorian Fainelli GFP_KERNEL); 2471967dd82fSFlorian Fainelli if (!dev->ports) 2472967dd82fSFlorian Fainelli return -ENOMEM; 2473967dd82fSFlorian Fainelli 2474a86854d0SKees Cook dev->vlans = devm_kcalloc(dev->dev, 2475a86854d0SKees Cook dev->num_vlans, sizeof(struct b53_vlan), 2476a2482d2cSFlorian Fainelli GFP_KERNEL); 2477a2482d2cSFlorian Fainelli if (!dev->vlans) 2478a2482d2cSFlorian Fainelli return -ENOMEM; 2479a2482d2cSFlorian Fainelli 2480967dd82fSFlorian Fainelli dev->reset_gpio = b53_switch_get_reset_gpio(dev); 2481967dd82fSFlorian Fainelli if (dev->reset_gpio >= 0) { 2482967dd82fSFlorian Fainelli ret = devm_gpio_request_one(dev->dev, dev->reset_gpio, 2483967dd82fSFlorian Fainelli GPIOF_OUT_INIT_HIGH, "robo_reset"); 2484967dd82fSFlorian Fainelli if (ret) 2485967dd82fSFlorian Fainelli return ret; 2486967dd82fSFlorian Fainelli } 2487967dd82fSFlorian Fainelli 2488967dd82fSFlorian Fainelli return 0; 2489967dd82fSFlorian Fainelli } 2490967dd82fSFlorian Fainelli 24910dff88d3SJulia Lawall struct b53_device *b53_switch_alloc(struct device *base, 24920dff88d3SJulia Lawall const struct b53_io_ops *ops, 2493967dd82fSFlorian Fainelli void *priv) 2494967dd82fSFlorian Fainelli { 2495967dd82fSFlorian Fainelli struct dsa_switch *ds; 2496967dd82fSFlorian Fainelli struct b53_device *dev; 2497967dd82fSFlorian Fainelli 24987e99e347SVivien Didelot ds = devm_kzalloc(base, sizeof(*ds), GFP_KERNEL); 2499967dd82fSFlorian Fainelli if (!ds) 2500967dd82fSFlorian Fainelli return NULL; 2501967dd82fSFlorian Fainelli 25027e99e347SVivien Didelot ds->dev = base; 25037e99e347SVivien Didelot ds->num_ports = DSA_MAX_PORTS; 25047e99e347SVivien Didelot 2505a0c02161SVivien Didelot dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL); 2506a0c02161SVivien Didelot if (!dev) 2507a0c02161SVivien Didelot return NULL; 2508967dd82fSFlorian Fainelli 2509967dd82fSFlorian Fainelli ds->priv = dev; 2510967dd82fSFlorian Fainelli dev->dev = base; 2511967dd82fSFlorian Fainelli 2512967dd82fSFlorian Fainelli dev->ds = ds; 2513967dd82fSFlorian Fainelli dev->priv = priv; 2514967dd82fSFlorian Fainelli dev->ops = ops; 2515485ebd61SFlorian Fainelli ds->ops = &b53_switch_ops; 2516967dd82fSFlorian Fainelli mutex_init(&dev->reg_mutex); 2517967dd82fSFlorian Fainelli mutex_init(&dev->stats_mutex); 2518967dd82fSFlorian Fainelli 2519967dd82fSFlorian Fainelli return dev; 2520967dd82fSFlorian Fainelli } 2521967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_alloc); 2522967dd82fSFlorian Fainelli 2523967dd82fSFlorian Fainelli int b53_switch_detect(struct b53_device *dev) 2524967dd82fSFlorian Fainelli { 2525967dd82fSFlorian Fainelli u32 id32; 2526967dd82fSFlorian Fainelli u16 tmp; 2527967dd82fSFlorian Fainelli u8 id8; 2528967dd82fSFlorian Fainelli int ret; 2529967dd82fSFlorian Fainelli 2530967dd82fSFlorian Fainelli ret = b53_read8(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id8); 2531967dd82fSFlorian Fainelli if (ret) 2532967dd82fSFlorian Fainelli return ret; 2533967dd82fSFlorian Fainelli 2534967dd82fSFlorian Fainelli switch (id8) { 2535967dd82fSFlorian Fainelli case 0: 2536967dd82fSFlorian Fainelli /* BCM5325 and BCM5365 do not have this register so reads 2537967dd82fSFlorian Fainelli * return 0. But the read operation did succeed, so assume this 2538967dd82fSFlorian Fainelli * is one of them. 2539967dd82fSFlorian Fainelli * 2540967dd82fSFlorian Fainelli * Next check if we can write to the 5325's VTA register; for 2541967dd82fSFlorian Fainelli * 5365 it is read only. 2542967dd82fSFlorian Fainelli */ 2543967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, 0xf); 2544967dd82fSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, &tmp); 2545967dd82fSFlorian Fainelli 2546967dd82fSFlorian Fainelli if (tmp == 0xf) 2547967dd82fSFlorian Fainelli dev->chip_id = BCM5325_DEVICE_ID; 2548967dd82fSFlorian Fainelli else 2549967dd82fSFlorian Fainelli dev->chip_id = BCM5365_DEVICE_ID; 2550967dd82fSFlorian Fainelli break; 2551a95691bcSDamien Thébault case BCM5389_DEVICE_ID: 2552967dd82fSFlorian Fainelli case BCM5395_DEVICE_ID: 2553967dd82fSFlorian Fainelli case BCM5397_DEVICE_ID: 2554967dd82fSFlorian Fainelli case BCM5398_DEVICE_ID: 2555967dd82fSFlorian Fainelli dev->chip_id = id8; 2556967dd82fSFlorian Fainelli break; 2557967dd82fSFlorian Fainelli default: 2558967dd82fSFlorian Fainelli ret = b53_read32(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id32); 2559967dd82fSFlorian Fainelli if (ret) 2560967dd82fSFlorian Fainelli return ret; 2561967dd82fSFlorian Fainelli 2562967dd82fSFlorian Fainelli switch (id32) { 2563967dd82fSFlorian Fainelli case BCM53115_DEVICE_ID: 2564967dd82fSFlorian Fainelli case BCM53125_DEVICE_ID: 2565967dd82fSFlorian Fainelli case BCM53128_DEVICE_ID: 2566967dd82fSFlorian Fainelli case BCM53010_DEVICE_ID: 2567967dd82fSFlorian Fainelli case BCM53011_DEVICE_ID: 2568967dd82fSFlorian Fainelli case BCM53012_DEVICE_ID: 2569967dd82fSFlorian Fainelli case BCM53018_DEVICE_ID: 2570967dd82fSFlorian Fainelli case BCM53019_DEVICE_ID: 2571967dd82fSFlorian Fainelli dev->chip_id = id32; 2572967dd82fSFlorian Fainelli break; 2573967dd82fSFlorian Fainelli default: 2574967dd82fSFlorian Fainelli pr_err("unsupported switch detected (BCM53%02x/BCM%x)\n", 2575967dd82fSFlorian Fainelli id8, id32); 2576967dd82fSFlorian Fainelli return -ENODEV; 2577967dd82fSFlorian Fainelli } 2578967dd82fSFlorian Fainelli } 2579967dd82fSFlorian Fainelli 2580967dd82fSFlorian Fainelli if (dev->chip_id == BCM5325_DEVICE_ID) 2581967dd82fSFlorian Fainelli return b53_read8(dev, B53_STAT_PAGE, B53_REV_ID_25, 2582967dd82fSFlorian Fainelli &dev->core_rev); 2583967dd82fSFlorian Fainelli else 2584967dd82fSFlorian Fainelli return b53_read8(dev, B53_MGMT_PAGE, B53_REV_ID, 2585967dd82fSFlorian Fainelli &dev->core_rev); 2586967dd82fSFlorian Fainelli } 2587967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_detect); 2588967dd82fSFlorian Fainelli 2589967dd82fSFlorian Fainelli int b53_switch_register(struct b53_device *dev) 2590967dd82fSFlorian Fainelli { 2591967dd82fSFlorian Fainelli int ret; 2592967dd82fSFlorian Fainelli 2593967dd82fSFlorian Fainelli if (dev->pdata) { 2594967dd82fSFlorian Fainelli dev->chip_id = dev->pdata->chip_id; 2595967dd82fSFlorian Fainelli dev->enabled_ports = dev->pdata->enabled_ports; 2596967dd82fSFlorian Fainelli } 2597967dd82fSFlorian Fainelli 2598967dd82fSFlorian Fainelli if (!dev->chip_id && b53_switch_detect(dev)) 2599967dd82fSFlorian Fainelli return -EINVAL; 2600967dd82fSFlorian Fainelli 2601967dd82fSFlorian Fainelli ret = b53_switch_init(dev); 2602967dd82fSFlorian Fainelli if (ret) 2603967dd82fSFlorian Fainelli return ret; 2604967dd82fSFlorian Fainelli 2605967dd82fSFlorian Fainelli pr_info("found switch: %s, rev %i\n", dev->name, dev->core_rev); 2606967dd82fSFlorian Fainelli 260723c9ee49SVivien Didelot return dsa_register_switch(dev->ds); 2608967dd82fSFlorian Fainelli } 2609967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_register); 2610967dd82fSFlorian Fainelli 2611967dd82fSFlorian Fainelli MODULE_AUTHOR("Jonas Gorski <jogo@openwrt.org>"); 2612967dd82fSFlorian Fainelli MODULE_DESCRIPTION("B53 switch library"); 2613967dd82fSFlorian Fainelli MODULE_LICENSE("Dual BSD/GPL"); 2614