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 mgmt &= ~SM_SW_FWD_MODE; 375967dd82fSFlorian Fainelli 376967dd82fSFlorian Fainelli if (enable) { 377967dd82fSFlorian Fainelli vc0 |= VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID; 378967dd82fSFlorian Fainelli vc1 |= VC1_RX_MCST_UNTAG_EN | VC1_RX_MCST_FWD_EN; 379967dd82fSFlorian Fainelli vc4 &= ~VC4_ING_VID_CHECK_MASK; 380dad8d7c6SFlorian Fainelli if (enable_filtering) { 381967dd82fSFlorian Fainelli vc4 |= VC4_ING_VID_VIO_DROP << VC4_ING_VID_CHECK_S; 382967dd82fSFlorian Fainelli vc5 |= VC5_DROP_VTABLE_MISS; 383dad8d7c6SFlorian Fainelli } else { 384dad8d7c6SFlorian Fainelli vc4 |= VC4_ING_VID_VIO_FWD << VC4_ING_VID_CHECK_S; 385dad8d7c6SFlorian Fainelli vc5 &= ~VC5_DROP_VTABLE_MISS; 386dad8d7c6SFlorian Fainelli } 387967dd82fSFlorian Fainelli 388967dd82fSFlorian Fainelli if (is5325(dev)) 389967dd82fSFlorian Fainelli vc0 &= ~VC0_RESERVED_1; 390967dd82fSFlorian Fainelli 391967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 392967dd82fSFlorian Fainelli vc1 |= VC1_RX_MCST_TAG_EN; 393967dd82fSFlorian Fainelli 394967dd82fSFlorian Fainelli } else { 395967dd82fSFlorian Fainelli vc0 &= ~(VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID); 396967dd82fSFlorian Fainelli vc1 &= ~(VC1_RX_MCST_UNTAG_EN | VC1_RX_MCST_FWD_EN); 397967dd82fSFlorian Fainelli vc4 &= ~VC4_ING_VID_CHECK_MASK; 398967dd82fSFlorian Fainelli vc5 &= ~VC5_DROP_VTABLE_MISS; 399967dd82fSFlorian Fainelli 400967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 401967dd82fSFlorian Fainelli vc4 |= VC4_ING_VID_VIO_FWD << VC4_ING_VID_CHECK_S; 402967dd82fSFlorian Fainelli else 403967dd82fSFlorian Fainelli vc4 |= VC4_ING_VID_VIO_TO_IMP << VC4_ING_VID_CHECK_S; 404967dd82fSFlorian Fainelli 405967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 406967dd82fSFlorian Fainelli vc1 &= ~VC1_RX_MCST_TAG_EN; 407a2482d2cSFlorian Fainelli } 408967dd82fSFlorian Fainelli 409967dd82fSFlorian Fainelli if (!is5325(dev) && !is5365(dev)) 410967dd82fSFlorian Fainelli vc5 &= ~VC5_VID_FFF_EN; 411967dd82fSFlorian Fainelli 412967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL0, vc0); 413967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL1, vc1); 414967dd82fSFlorian Fainelli 415967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) { 416967dd82fSFlorian Fainelli /* enable the high 8 bit vid check on 5325 */ 417967dd82fSFlorian Fainelli if (is5325(dev) && enable) 418967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 419967dd82fSFlorian Fainelli VC3_HIGH_8BIT_EN); 420967dd82fSFlorian Fainelli else 421967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 0); 422967dd82fSFlorian Fainelli 423967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, vc4); 424967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_25, vc5); 425967dd82fSFlorian Fainelli } else if (is63xx(dev)) { 426967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3_63XX, 0); 427967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_63XX, vc4); 428967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_63XX, vc5); 429967dd82fSFlorian Fainelli } else { 430967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 0); 431967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, vc4); 432967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, vc5); 433967dd82fSFlorian Fainelli } 434967dd82fSFlorian Fainelli 435967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt); 436dad8d7c6SFlorian Fainelli 437dad8d7c6SFlorian Fainelli dev->vlan_enabled = enable; 438967dd82fSFlorian Fainelli } 439967dd82fSFlorian Fainelli 440967dd82fSFlorian Fainelli static int b53_set_jumbo(struct b53_device *dev, bool enable, bool allow_10_100) 441967dd82fSFlorian Fainelli { 442967dd82fSFlorian Fainelli u32 port_mask = 0; 443967dd82fSFlorian Fainelli u16 max_size = JMS_MIN_SIZE; 444967dd82fSFlorian Fainelli 445967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 446967dd82fSFlorian Fainelli return -EINVAL; 447967dd82fSFlorian Fainelli 448967dd82fSFlorian Fainelli if (enable) { 449967dd82fSFlorian Fainelli port_mask = dev->enabled_ports; 450967dd82fSFlorian Fainelli max_size = JMS_MAX_SIZE; 451967dd82fSFlorian Fainelli if (allow_10_100) 452967dd82fSFlorian Fainelli port_mask |= JPM_10_100_JUMBO_EN; 453967dd82fSFlorian Fainelli } 454967dd82fSFlorian Fainelli 455967dd82fSFlorian Fainelli b53_write32(dev, B53_JUMBO_PAGE, dev->jumbo_pm_reg, port_mask); 456967dd82fSFlorian Fainelli return b53_write16(dev, B53_JUMBO_PAGE, dev->jumbo_size_reg, max_size); 457967dd82fSFlorian Fainelli } 458967dd82fSFlorian Fainelli 459ff39c2d6SFlorian Fainelli static int b53_flush_arl(struct b53_device *dev, u8 mask) 460967dd82fSFlorian Fainelli { 461967dd82fSFlorian Fainelli unsigned int i; 462967dd82fSFlorian Fainelli 463967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, 464ff39c2d6SFlorian Fainelli FAST_AGE_DONE | FAST_AGE_DYNAMIC | mask); 465967dd82fSFlorian Fainelli 466967dd82fSFlorian Fainelli for (i = 0; i < 10; i++) { 467967dd82fSFlorian Fainelli u8 fast_age_ctrl; 468967dd82fSFlorian Fainelli 469967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, 470967dd82fSFlorian Fainelli &fast_age_ctrl); 471967dd82fSFlorian Fainelli 472967dd82fSFlorian Fainelli if (!(fast_age_ctrl & FAST_AGE_DONE)) 473967dd82fSFlorian Fainelli goto out; 474967dd82fSFlorian Fainelli 475967dd82fSFlorian Fainelli msleep(1); 476967dd82fSFlorian Fainelli } 477967dd82fSFlorian Fainelli 478967dd82fSFlorian Fainelli return -ETIMEDOUT; 479967dd82fSFlorian Fainelli out: 480967dd82fSFlorian Fainelli /* Only age dynamic entries (default behavior) */ 481967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, FAST_AGE_DYNAMIC); 482967dd82fSFlorian Fainelli return 0; 483967dd82fSFlorian Fainelli } 484967dd82fSFlorian Fainelli 485ff39c2d6SFlorian Fainelli static int b53_fast_age_port(struct b53_device *dev, int port) 486ff39c2d6SFlorian Fainelli { 487ff39c2d6SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_PORT_CTRL, port); 488ff39c2d6SFlorian Fainelli 489ff39c2d6SFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_PORT); 490ff39c2d6SFlorian Fainelli } 491ff39c2d6SFlorian Fainelli 492a2482d2cSFlorian Fainelli static int b53_fast_age_vlan(struct b53_device *dev, u16 vid) 493a2482d2cSFlorian Fainelli { 494a2482d2cSFlorian Fainelli b53_write16(dev, B53_CTRL_PAGE, B53_FAST_AGE_VID_CTRL, vid); 495a2482d2cSFlorian Fainelli 496a2482d2cSFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_VLAN); 497a2482d2cSFlorian Fainelli } 498a2482d2cSFlorian Fainelli 499aac02867SFlorian Fainelli void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port) 500ff39c2d6SFlorian Fainelli { 50104bed143SVivien Didelot struct b53_device *dev = ds->priv; 502ff39c2d6SFlorian Fainelli unsigned int i; 503ff39c2d6SFlorian Fainelli u16 pvlan; 504ff39c2d6SFlorian Fainelli 505ff39c2d6SFlorian Fainelli /* Enable the IMP port to be in the same VLAN as the other ports 506ff39c2d6SFlorian Fainelli * on a per-port basis such that we only have Port i and IMP in 507ff39c2d6SFlorian Fainelli * the same VLAN. 508ff39c2d6SFlorian Fainelli */ 509ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) { 510ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &pvlan); 511ff39c2d6SFlorian Fainelli pvlan |= BIT(cpu_port); 512ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), pvlan); 513ff39c2d6SFlorian Fainelli } 514ff39c2d6SFlorian Fainelli } 515aac02867SFlorian Fainelli EXPORT_SYMBOL(b53_imp_vlan_setup); 516ff39c2d6SFlorian Fainelli 517f86ad77fSFlorian Fainelli int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy) 518967dd82fSFlorian Fainelli { 51904bed143SVivien Didelot struct b53_device *dev = ds->priv; 52074be4babSVivien Didelot unsigned int cpu_port; 5218ca7c160SFlorian Fainelli int ret = 0; 522ff39c2d6SFlorian Fainelli u16 pvlan; 523967dd82fSFlorian Fainelli 52474be4babSVivien Didelot if (!dsa_is_user_port(ds, port)) 52574be4babSVivien Didelot return 0; 52674be4babSVivien Didelot 52768bb8ea8SVivien Didelot cpu_port = dsa_to_port(ds, port)->cpu_dp->index; 52874be4babSVivien Didelot 52963cc54a6SFlorian Fainelli b53_br_egress_floods(ds, port, true, true); 53063cc54a6SFlorian Fainelli 5318ca7c160SFlorian Fainelli if (dev->ops->irq_enable) 5328ca7c160SFlorian Fainelli ret = dev->ops->irq_enable(dev, port); 5338ca7c160SFlorian Fainelli if (ret) 5348ca7c160SFlorian Fainelli return ret; 5358ca7c160SFlorian Fainelli 536967dd82fSFlorian Fainelli /* Clear the Rx and Tx disable bits and set to no spanning tree */ 537967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), 0); 538967dd82fSFlorian Fainelli 539ff39c2d6SFlorian Fainelli /* Set this port, and only this one to be in the default VLAN, 540ff39c2d6SFlorian Fainelli * if member of a bridge, restore its membership prior to 541ff39c2d6SFlorian Fainelli * bringing down this port. 542ff39c2d6SFlorian Fainelli */ 543ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); 544ff39c2d6SFlorian Fainelli pvlan &= ~0x1ff; 545ff39c2d6SFlorian Fainelli pvlan |= BIT(port); 546ff39c2d6SFlorian Fainelli pvlan |= dev->ports[port].vlan_ctl_mask; 547ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); 548ff39c2d6SFlorian Fainelli 549ff39c2d6SFlorian Fainelli b53_imp_vlan_setup(ds, cpu_port); 550ff39c2d6SFlorian Fainelli 551f43a2dbeSFlorian Fainelli /* If EEE was enabled, restore it */ 552f43a2dbeSFlorian Fainelli if (dev->ports[port].eee.eee_enabled) 553f43a2dbeSFlorian Fainelli b53_eee_enable_set(ds, port, true); 554f43a2dbeSFlorian Fainelli 555967dd82fSFlorian Fainelli return 0; 556967dd82fSFlorian Fainelli } 557f86ad77fSFlorian Fainelli EXPORT_SYMBOL(b53_enable_port); 558967dd82fSFlorian Fainelli 55975104db0SAndrew Lunn void b53_disable_port(struct dsa_switch *ds, int port) 560967dd82fSFlorian Fainelli { 56104bed143SVivien Didelot struct b53_device *dev = ds->priv; 562967dd82fSFlorian Fainelli u8 reg; 563967dd82fSFlorian Fainelli 564967dd82fSFlorian Fainelli /* Disable Tx/Rx for the port */ 565967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), ®); 566967dd82fSFlorian Fainelli reg |= PORT_CTRL_RX_DISABLE | PORT_CTRL_TX_DISABLE; 567967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg); 5688ca7c160SFlorian Fainelli 5698ca7c160SFlorian Fainelli if (dev->ops->irq_disable) 5708ca7c160SFlorian Fainelli dev->ops->irq_disable(dev, port); 571967dd82fSFlorian Fainelli } 572f86ad77fSFlorian Fainelli EXPORT_SYMBOL(b53_disable_port); 573967dd82fSFlorian Fainelli 574b409a9efSFlorian Fainelli void b53_brcm_hdr_setup(struct dsa_switch *ds, int port) 575b409a9efSFlorian Fainelli { 576b409a9efSFlorian Fainelli struct b53_device *dev = ds->priv; 577*4d776482SFlorian Fainelli bool tag_en = !(dev->tag_protocol == DSA_TAG_PROTO_NONE); 578b409a9efSFlorian Fainelli u8 hdr_ctl, val; 579b409a9efSFlorian Fainelli u16 reg; 580b409a9efSFlorian Fainelli 581b409a9efSFlorian Fainelli /* Resolve which bit controls the Broadcom tag */ 582b409a9efSFlorian Fainelli switch (port) { 583b409a9efSFlorian Fainelli case 8: 584b409a9efSFlorian Fainelli val = BRCM_HDR_P8_EN; 585b409a9efSFlorian Fainelli break; 586b409a9efSFlorian Fainelli case 7: 587b409a9efSFlorian Fainelli val = BRCM_HDR_P7_EN; 588b409a9efSFlorian Fainelli break; 589b409a9efSFlorian Fainelli case 5: 590b409a9efSFlorian Fainelli val = BRCM_HDR_P5_EN; 591b409a9efSFlorian Fainelli break; 592b409a9efSFlorian Fainelli default: 593b409a9efSFlorian Fainelli val = 0; 594b409a9efSFlorian Fainelli break; 595b409a9efSFlorian Fainelli } 596b409a9efSFlorian Fainelli 597b409a9efSFlorian Fainelli /* Enable Broadcom tags for IMP port */ 598b409a9efSFlorian Fainelli b53_read8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, &hdr_ctl); 599cdb583cfSFlorian Fainelli if (tag_en) 600b409a9efSFlorian Fainelli hdr_ctl |= val; 601cdb583cfSFlorian Fainelli else 602cdb583cfSFlorian Fainelli hdr_ctl &= ~val; 603b409a9efSFlorian Fainelli b53_write8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, hdr_ctl); 604b409a9efSFlorian Fainelli 605b409a9efSFlorian Fainelli /* Registers below are only accessible on newer devices */ 606b409a9efSFlorian Fainelli if (!is58xx(dev)) 607b409a9efSFlorian Fainelli return; 608b409a9efSFlorian Fainelli 609b409a9efSFlorian Fainelli /* Enable reception Broadcom tag for CPU TX (switch RX) to 610b409a9efSFlorian Fainelli * allow us to tag outgoing frames 611b409a9efSFlorian Fainelli */ 612b409a9efSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, ®); 613cdb583cfSFlorian Fainelli if (tag_en) 614b409a9efSFlorian Fainelli reg &= ~BIT(port); 615cdb583cfSFlorian Fainelli else 616cdb583cfSFlorian Fainelli reg |= BIT(port); 617b409a9efSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, reg); 618b409a9efSFlorian Fainelli 619b409a9efSFlorian Fainelli /* Enable transmission of Broadcom tags from the switch (CPU RX) to 620b409a9efSFlorian Fainelli * allow delivering frames to the per-port net_devices 621b409a9efSFlorian Fainelli */ 622b409a9efSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, ®); 623cdb583cfSFlorian Fainelli if (tag_en) 624b409a9efSFlorian Fainelli reg &= ~BIT(port); 625cdb583cfSFlorian Fainelli else 626cdb583cfSFlorian Fainelli reg |= BIT(port); 627b409a9efSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, reg); 628b409a9efSFlorian Fainelli } 629b409a9efSFlorian Fainelli EXPORT_SYMBOL(b53_brcm_hdr_setup); 630b409a9efSFlorian Fainelli 631299752a7SFlorian Fainelli static void b53_enable_cpu_port(struct b53_device *dev, int port) 632967dd82fSFlorian Fainelli { 633967dd82fSFlorian Fainelli u8 port_ctrl; 634967dd82fSFlorian Fainelli 635967dd82fSFlorian Fainelli /* BCM5325 CPU port is at 8 */ 636299752a7SFlorian Fainelli if ((is5325(dev) || is5365(dev)) && port == B53_CPU_PORT_25) 637299752a7SFlorian Fainelli port = B53_CPU_PORT; 638967dd82fSFlorian Fainelli 639967dd82fSFlorian Fainelli port_ctrl = PORT_CTRL_RX_BCST_EN | 640967dd82fSFlorian Fainelli PORT_CTRL_RX_MCST_EN | 641967dd82fSFlorian Fainelli PORT_CTRL_RX_UCST_EN; 642299752a7SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), port_ctrl); 6437edc58d6SFlorian Fainelli 6447edc58d6SFlorian Fainelli b53_brcm_hdr_setup(dev->ds, port); 64563cc54a6SFlorian Fainelli 64663cc54a6SFlorian Fainelli b53_br_egress_floods(dev->ds, port, true, true); 647967dd82fSFlorian Fainelli } 648967dd82fSFlorian Fainelli 649967dd82fSFlorian Fainelli static void b53_enable_mib(struct b53_device *dev) 650967dd82fSFlorian Fainelli { 651967dd82fSFlorian Fainelli u8 gc; 652967dd82fSFlorian Fainelli 653967dd82fSFlorian Fainelli b53_read8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc); 654967dd82fSFlorian Fainelli gc &= ~(GC_RESET_MIB | GC_MIB_AC_EN); 655967dd82fSFlorian Fainelli b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc); 656967dd82fSFlorian Fainelli } 657967dd82fSFlorian Fainelli 658fea83353SFlorian Fainelli static u16 b53_default_pvid(struct b53_device *dev) 659fea83353SFlorian Fainelli { 660fea83353SFlorian Fainelli if (is5325(dev) || is5365(dev)) 661fea83353SFlorian Fainelli return 1; 662fea83353SFlorian Fainelli else 663fea83353SFlorian Fainelli return 0; 664fea83353SFlorian Fainelli } 665fea83353SFlorian Fainelli 6665c1a6eafSFlorian Fainelli int b53_configure_vlan(struct dsa_switch *ds) 667967dd82fSFlorian Fainelli { 6685c1a6eafSFlorian Fainelli struct b53_device *dev = ds->priv; 669a2482d2cSFlorian Fainelli struct b53_vlan vl = { 0 }; 670fea83353SFlorian Fainelli int i, def_vid; 671fea83353SFlorian Fainelli 672fea83353SFlorian Fainelli def_vid = b53_default_pvid(dev); 673967dd82fSFlorian Fainelli 674967dd82fSFlorian Fainelli /* clear all vlan entries */ 675967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) { 676fea83353SFlorian Fainelli for (i = def_vid; i < dev->num_vlans; i++) 677a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, i, &vl); 678967dd82fSFlorian Fainelli } else { 679967dd82fSFlorian Fainelli b53_do_vlan_op(dev, VTA_CMD_CLEAR); 680967dd82fSFlorian Fainelli } 681967dd82fSFlorian Fainelli 682e74f014eSVladimir Oltean b53_enable_vlan(dev, false, ds->vlan_filtering); 683967dd82fSFlorian Fainelli 684967dd82fSFlorian Fainelli b53_for_each_port(dev, i) 685967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, 686fea83353SFlorian Fainelli B53_VLAN_PORT_DEF_TAG(i), def_vid); 687967dd82fSFlorian Fainelli 688967dd82fSFlorian Fainelli if (!is5325(dev) && !is5365(dev)) 689967dd82fSFlorian Fainelli b53_set_jumbo(dev, dev->enable_jumbo, false); 690967dd82fSFlorian Fainelli 691967dd82fSFlorian Fainelli return 0; 692967dd82fSFlorian Fainelli } 6935c1a6eafSFlorian Fainelli EXPORT_SYMBOL(b53_configure_vlan); 694967dd82fSFlorian Fainelli 695967dd82fSFlorian Fainelli static void b53_switch_reset_gpio(struct b53_device *dev) 696967dd82fSFlorian Fainelli { 697967dd82fSFlorian Fainelli int gpio = dev->reset_gpio; 698967dd82fSFlorian Fainelli 699967dd82fSFlorian Fainelli if (gpio < 0) 700967dd82fSFlorian Fainelli return; 701967dd82fSFlorian Fainelli 702967dd82fSFlorian Fainelli /* Reset sequence: RESET low(50ms)->high(20ms) 703967dd82fSFlorian Fainelli */ 704967dd82fSFlorian Fainelli gpio_set_value(gpio, 0); 705967dd82fSFlorian Fainelli mdelay(50); 706967dd82fSFlorian Fainelli 707967dd82fSFlorian Fainelli gpio_set_value(gpio, 1); 708967dd82fSFlorian Fainelli mdelay(20); 709967dd82fSFlorian Fainelli 710967dd82fSFlorian Fainelli dev->current_page = 0xff; 711967dd82fSFlorian Fainelli } 712967dd82fSFlorian Fainelli 713967dd82fSFlorian Fainelli static int b53_switch_reset(struct b53_device *dev) 714967dd82fSFlorian Fainelli { 7153fb22b05SFlorian Fainelli unsigned int timeout = 1000; 7163fb22b05SFlorian Fainelli u8 mgmt, reg; 717967dd82fSFlorian Fainelli 718967dd82fSFlorian Fainelli b53_switch_reset_gpio(dev); 719967dd82fSFlorian Fainelli 720967dd82fSFlorian Fainelli if (is539x(dev)) { 721967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x83); 722967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x00); 723967dd82fSFlorian Fainelli } 724967dd82fSFlorian Fainelli 7253fb22b05SFlorian Fainelli /* This is specific to 58xx devices here, do not use is58xx() which 7263fb22b05SFlorian Fainelli * covers the larger Starfigther 2 family, including 7445/7278 which 7273fb22b05SFlorian Fainelli * still use this driver as a library and need to perform the reset 7283fb22b05SFlorian Fainelli * earlier. 7293fb22b05SFlorian Fainelli */ 7305040cc99SArun Parameswaran if (dev->chip_id == BCM58XX_DEVICE_ID || 7315040cc99SArun Parameswaran dev->chip_id == BCM583XX_DEVICE_ID) { 7323fb22b05SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, ®); 7333fb22b05SFlorian Fainelli reg |= SW_RST | EN_SW_RST | EN_CH_RST; 7343fb22b05SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, reg); 7353fb22b05SFlorian Fainelli 7363fb22b05SFlorian Fainelli do { 7373fb22b05SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, ®); 7383fb22b05SFlorian Fainelli if (!(reg & SW_RST)) 7393fb22b05SFlorian Fainelli break; 7403fb22b05SFlorian Fainelli 7413fb22b05SFlorian Fainelli usleep_range(1000, 2000); 7423fb22b05SFlorian Fainelli } while (timeout-- > 0); 7433fb22b05SFlorian Fainelli 7443fb22b05SFlorian Fainelli if (timeout == 0) 7453fb22b05SFlorian Fainelli return -ETIMEDOUT; 7463fb22b05SFlorian Fainelli } 7473fb22b05SFlorian Fainelli 748967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); 749967dd82fSFlorian Fainelli 750967dd82fSFlorian Fainelli if (!(mgmt & SM_SW_FWD_EN)) { 751967dd82fSFlorian Fainelli mgmt &= ~SM_SW_FWD_MODE; 752967dd82fSFlorian Fainelli mgmt |= SM_SW_FWD_EN; 753967dd82fSFlorian Fainelli 754967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt); 755967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); 756967dd82fSFlorian Fainelli 757967dd82fSFlorian Fainelli if (!(mgmt & SM_SW_FWD_EN)) { 758967dd82fSFlorian Fainelli dev_err(dev->dev, "Failed to enable switch!\n"); 759967dd82fSFlorian Fainelli return -EINVAL; 760967dd82fSFlorian Fainelli } 761967dd82fSFlorian Fainelli } 762967dd82fSFlorian Fainelli 763967dd82fSFlorian Fainelli b53_enable_mib(dev); 764967dd82fSFlorian Fainelli 765ff39c2d6SFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_STATIC); 766967dd82fSFlorian Fainelli } 767967dd82fSFlorian Fainelli 768967dd82fSFlorian Fainelli static int b53_phy_read16(struct dsa_switch *ds, int addr, int reg) 769967dd82fSFlorian Fainelli { 77004bed143SVivien Didelot struct b53_device *priv = ds->priv; 771967dd82fSFlorian Fainelli u16 value = 0; 772967dd82fSFlorian Fainelli int ret; 773967dd82fSFlorian Fainelli 774967dd82fSFlorian Fainelli if (priv->ops->phy_read16) 775967dd82fSFlorian Fainelli ret = priv->ops->phy_read16(priv, addr, reg, &value); 776967dd82fSFlorian Fainelli else 777967dd82fSFlorian Fainelli ret = b53_read16(priv, B53_PORT_MII_PAGE(addr), 778967dd82fSFlorian Fainelli reg * 2, &value); 779967dd82fSFlorian Fainelli 780967dd82fSFlorian Fainelli return ret ? ret : value; 781967dd82fSFlorian Fainelli } 782967dd82fSFlorian Fainelli 783967dd82fSFlorian Fainelli static int b53_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val) 784967dd82fSFlorian Fainelli { 78504bed143SVivien Didelot struct b53_device *priv = ds->priv; 786967dd82fSFlorian Fainelli 787967dd82fSFlorian Fainelli if (priv->ops->phy_write16) 788967dd82fSFlorian Fainelli return priv->ops->phy_write16(priv, addr, reg, val); 789967dd82fSFlorian Fainelli 790967dd82fSFlorian Fainelli return b53_write16(priv, B53_PORT_MII_PAGE(addr), reg * 2, val); 791967dd82fSFlorian Fainelli } 792967dd82fSFlorian Fainelli 793967dd82fSFlorian Fainelli static int b53_reset_switch(struct b53_device *priv) 794967dd82fSFlorian Fainelli { 795967dd82fSFlorian Fainelli /* reset vlans */ 796967dd82fSFlorian Fainelli priv->enable_jumbo = false; 797967dd82fSFlorian Fainelli 798a2482d2cSFlorian Fainelli memset(priv->vlans, 0, sizeof(*priv->vlans) * priv->num_vlans); 799967dd82fSFlorian Fainelli memset(priv->ports, 0, sizeof(*priv->ports) * priv->num_ports); 800967dd82fSFlorian Fainelli 8010e01491dSFlorian Fainelli priv->serdes_lane = B53_INVALID_LANE; 8020e01491dSFlorian Fainelli 803967dd82fSFlorian Fainelli return b53_switch_reset(priv); 804967dd82fSFlorian Fainelli } 805967dd82fSFlorian Fainelli 806967dd82fSFlorian Fainelli static int b53_apply_config(struct b53_device *priv) 807967dd82fSFlorian Fainelli { 808967dd82fSFlorian Fainelli /* disable switching */ 809967dd82fSFlorian Fainelli b53_set_forwarding(priv, 0); 810967dd82fSFlorian Fainelli 8115c1a6eafSFlorian Fainelli b53_configure_vlan(priv->ds); 812967dd82fSFlorian Fainelli 813967dd82fSFlorian Fainelli /* enable switching */ 814967dd82fSFlorian Fainelli b53_set_forwarding(priv, 1); 815967dd82fSFlorian Fainelli 816967dd82fSFlorian Fainelli return 0; 817967dd82fSFlorian Fainelli } 818967dd82fSFlorian Fainelli 819967dd82fSFlorian Fainelli static void b53_reset_mib(struct b53_device *priv) 820967dd82fSFlorian Fainelli { 821967dd82fSFlorian Fainelli u8 gc; 822967dd82fSFlorian Fainelli 823967dd82fSFlorian Fainelli b53_read8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc); 824967dd82fSFlorian Fainelli 825967dd82fSFlorian Fainelli b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc | GC_RESET_MIB); 826967dd82fSFlorian Fainelli msleep(1); 827967dd82fSFlorian Fainelli b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc & ~GC_RESET_MIB); 828967dd82fSFlorian Fainelli msleep(1); 829967dd82fSFlorian Fainelli } 830967dd82fSFlorian Fainelli 831967dd82fSFlorian Fainelli static const struct b53_mib_desc *b53_get_mib(struct b53_device *dev) 832967dd82fSFlorian Fainelli { 833967dd82fSFlorian Fainelli if (is5365(dev)) 834967dd82fSFlorian Fainelli return b53_mibs_65; 835967dd82fSFlorian Fainelli else if (is63xx(dev)) 836967dd82fSFlorian Fainelli return b53_mibs_63xx; 837bde5d132SFlorian Fainelli else if (is58xx(dev)) 838bde5d132SFlorian Fainelli return b53_mibs_58xx; 839967dd82fSFlorian Fainelli else 840967dd82fSFlorian Fainelli return b53_mibs; 841967dd82fSFlorian Fainelli } 842967dd82fSFlorian Fainelli 843967dd82fSFlorian Fainelli static unsigned int b53_get_mib_size(struct b53_device *dev) 844967dd82fSFlorian Fainelli { 845967dd82fSFlorian Fainelli if (is5365(dev)) 846967dd82fSFlorian Fainelli return B53_MIBS_65_SIZE; 847967dd82fSFlorian Fainelli else if (is63xx(dev)) 848967dd82fSFlorian Fainelli return B53_MIBS_63XX_SIZE; 849bde5d132SFlorian Fainelli else if (is58xx(dev)) 850bde5d132SFlorian Fainelli return B53_MIBS_58XX_SIZE; 851967dd82fSFlorian Fainelli else 852967dd82fSFlorian Fainelli return B53_MIBS_SIZE; 853967dd82fSFlorian Fainelli } 854967dd82fSFlorian Fainelli 855c7d28c9dSFlorian Fainelli static struct phy_device *b53_get_phy_device(struct dsa_switch *ds, int port) 856c7d28c9dSFlorian Fainelli { 857c7d28c9dSFlorian Fainelli /* These ports typically do not have built-in PHYs */ 858c7d28c9dSFlorian Fainelli switch (port) { 859c7d28c9dSFlorian Fainelli case B53_CPU_PORT_25: 860c7d28c9dSFlorian Fainelli case 7: 861c7d28c9dSFlorian Fainelli case B53_CPU_PORT: 862c7d28c9dSFlorian Fainelli return NULL; 863c7d28c9dSFlorian Fainelli } 864c7d28c9dSFlorian Fainelli 865c7d28c9dSFlorian Fainelli return mdiobus_get_phy(ds->slave_mii_bus, port); 866c7d28c9dSFlorian Fainelli } 867c7d28c9dSFlorian Fainelli 86889f09048SFlorian Fainelli void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset, 86989f09048SFlorian Fainelli uint8_t *data) 870967dd82fSFlorian Fainelli { 87104bed143SVivien Didelot struct b53_device *dev = ds->priv; 872967dd82fSFlorian Fainelli const struct b53_mib_desc *mibs = b53_get_mib(dev); 873967dd82fSFlorian Fainelli unsigned int mib_size = b53_get_mib_size(dev); 874c7d28c9dSFlorian Fainelli struct phy_device *phydev; 875967dd82fSFlorian Fainelli unsigned int i; 876967dd82fSFlorian Fainelli 877c7d28c9dSFlorian Fainelli if (stringset == ETH_SS_STATS) { 878967dd82fSFlorian Fainelli for (i = 0; i < mib_size; i++) 879cd526676SFlorian Fainelli strlcpy(data + i * ETH_GSTRING_LEN, 880967dd82fSFlorian Fainelli mibs[i].name, ETH_GSTRING_LEN); 881c7d28c9dSFlorian Fainelli } else if (stringset == ETH_SS_PHY_STATS) { 882c7d28c9dSFlorian Fainelli phydev = b53_get_phy_device(ds, port); 883c7d28c9dSFlorian Fainelli if (!phydev) 884c7d28c9dSFlorian Fainelli return; 885c7d28c9dSFlorian Fainelli 886c7d28c9dSFlorian Fainelli phy_ethtool_get_strings(phydev, data); 887c7d28c9dSFlorian Fainelli } 888967dd82fSFlorian Fainelli } 8893117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_strings); 890967dd82fSFlorian Fainelli 8913117455dSFlorian Fainelli void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data) 892967dd82fSFlorian Fainelli { 89304bed143SVivien Didelot struct b53_device *dev = ds->priv; 894967dd82fSFlorian Fainelli const struct b53_mib_desc *mibs = b53_get_mib(dev); 895967dd82fSFlorian Fainelli unsigned int mib_size = b53_get_mib_size(dev); 896967dd82fSFlorian Fainelli const struct b53_mib_desc *s; 897967dd82fSFlorian Fainelli unsigned int i; 898967dd82fSFlorian Fainelli u64 val = 0; 899967dd82fSFlorian Fainelli 900967dd82fSFlorian Fainelli if (is5365(dev) && port == 5) 901967dd82fSFlorian Fainelli port = 8; 902967dd82fSFlorian Fainelli 903967dd82fSFlorian Fainelli mutex_lock(&dev->stats_mutex); 904967dd82fSFlorian Fainelli 905967dd82fSFlorian Fainelli for (i = 0; i < mib_size; i++) { 906967dd82fSFlorian Fainelli s = &mibs[i]; 907967dd82fSFlorian Fainelli 90851dca8a1SFlorian Fainelli if (s->size == 8) { 909967dd82fSFlorian Fainelli b53_read64(dev, B53_MIB_PAGE(port), s->offset, &val); 910967dd82fSFlorian Fainelli } else { 911967dd82fSFlorian Fainelli u32 val32; 912967dd82fSFlorian Fainelli 913967dd82fSFlorian Fainelli b53_read32(dev, B53_MIB_PAGE(port), s->offset, 914967dd82fSFlorian Fainelli &val32); 915967dd82fSFlorian Fainelli val = val32; 916967dd82fSFlorian Fainelli } 917967dd82fSFlorian Fainelli data[i] = (u64)val; 918967dd82fSFlorian Fainelli } 919967dd82fSFlorian Fainelli 920967dd82fSFlorian Fainelli mutex_unlock(&dev->stats_mutex); 921967dd82fSFlorian Fainelli } 9223117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_ethtool_stats); 923967dd82fSFlorian Fainelli 924c7d28c9dSFlorian Fainelli void b53_get_ethtool_phy_stats(struct dsa_switch *ds, int port, uint64_t *data) 925c7d28c9dSFlorian Fainelli { 926c7d28c9dSFlorian Fainelli struct phy_device *phydev; 927c7d28c9dSFlorian Fainelli 928c7d28c9dSFlorian Fainelli phydev = b53_get_phy_device(ds, port); 929c7d28c9dSFlorian Fainelli if (!phydev) 930c7d28c9dSFlorian Fainelli return; 931c7d28c9dSFlorian Fainelli 932c7d28c9dSFlorian Fainelli phy_ethtool_get_stats(phydev, NULL, data); 933c7d28c9dSFlorian Fainelli } 934c7d28c9dSFlorian Fainelli EXPORT_SYMBOL(b53_get_ethtool_phy_stats); 935c7d28c9dSFlorian Fainelli 93689f09048SFlorian Fainelli int b53_get_sset_count(struct dsa_switch *ds, int port, int sset) 937967dd82fSFlorian Fainelli { 93804bed143SVivien Didelot struct b53_device *dev = ds->priv; 939c7d28c9dSFlorian Fainelli struct phy_device *phydev; 940967dd82fSFlorian Fainelli 941c7d28c9dSFlorian Fainelli if (sset == ETH_SS_STATS) { 942c7d28c9dSFlorian Fainelli return b53_get_mib_size(dev); 943c7d28c9dSFlorian Fainelli } else if (sset == ETH_SS_PHY_STATS) { 944c7d28c9dSFlorian Fainelli phydev = b53_get_phy_device(ds, port); 945c7d28c9dSFlorian Fainelli if (!phydev) 94689f09048SFlorian Fainelli return 0; 94789f09048SFlorian Fainelli 948c7d28c9dSFlorian Fainelli return phy_ethtool_get_sset_count(phydev); 949c7d28c9dSFlorian Fainelli } 950c7d28c9dSFlorian Fainelli 951c7d28c9dSFlorian Fainelli return 0; 952967dd82fSFlorian Fainelli } 9533117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_sset_count); 954967dd82fSFlorian Fainelli 955967dd82fSFlorian Fainelli static int b53_setup(struct dsa_switch *ds) 956967dd82fSFlorian Fainelli { 95704bed143SVivien Didelot struct b53_device *dev = ds->priv; 958967dd82fSFlorian Fainelli unsigned int port; 959967dd82fSFlorian Fainelli int ret; 960967dd82fSFlorian Fainelli 961967dd82fSFlorian Fainelli ret = b53_reset_switch(dev); 962967dd82fSFlorian Fainelli if (ret) { 963967dd82fSFlorian Fainelli dev_err(ds->dev, "failed to reset switch\n"); 964967dd82fSFlorian Fainelli return ret; 965967dd82fSFlorian Fainelli } 966967dd82fSFlorian Fainelli 967967dd82fSFlorian Fainelli b53_reset_mib(dev); 968967dd82fSFlorian Fainelli 969967dd82fSFlorian Fainelli ret = b53_apply_config(dev); 970967dd82fSFlorian Fainelli if (ret) 971967dd82fSFlorian Fainelli dev_err(ds->dev, "failed to apply configuration\n"); 972967dd82fSFlorian Fainelli 97375dad252SBenedikt Spranger /* Configure IMP/CPU port, disable all other ports. Enabled 97434c8befdSFlorian Fainelli * ports will be configured with .port_enable 97534c8befdSFlorian Fainelli */ 976967dd82fSFlorian Fainelli for (port = 0; port < dev->num_ports; port++) { 97734c8befdSFlorian Fainelli if (dsa_is_cpu_port(ds, port)) 978299752a7SFlorian Fainelli b53_enable_cpu_port(dev, port); 97975dad252SBenedikt Spranger else 98075104db0SAndrew Lunn b53_disable_port(ds, port); 981967dd82fSFlorian Fainelli } 982967dd82fSFlorian Fainelli 9837228b23eSVladimir Oltean /* Let DSA handle the case were multiple bridges span the same switch 9847228b23eSVladimir Oltean * device and different VLAN awareness settings are requested, which 9857228b23eSVladimir Oltean * would be breaking filtering semantics for any of the other bridge 9867228b23eSVladimir Oltean * devices. (not hardware supported) 9877228b23eSVladimir Oltean */ 9887228b23eSVladimir Oltean ds->vlan_filtering_is_global = true; 9897228b23eSVladimir Oltean 990967dd82fSFlorian Fainelli return ret; 991967dd82fSFlorian Fainelli } 992967dd82fSFlorian Fainelli 9935e004460SFlorian Fainelli static void b53_force_link(struct b53_device *dev, int port, int link) 994967dd82fSFlorian Fainelli { 9955e004460SFlorian Fainelli u8 reg, val, off; 996967dd82fSFlorian Fainelli 997967dd82fSFlorian Fainelli /* Override the port settings */ 998967dd82fSFlorian Fainelli if (port == dev->cpu_port) { 999967dd82fSFlorian Fainelli off = B53_PORT_OVERRIDE_CTRL; 10005e004460SFlorian Fainelli val = PORT_OVERRIDE_EN; 1001967dd82fSFlorian Fainelli } else { 1002967dd82fSFlorian Fainelli off = B53_GMII_PORT_OVERRIDE_CTRL(port); 10035e004460SFlorian Fainelli val = GMII_PO_EN; 1004967dd82fSFlorian Fainelli } 1005967dd82fSFlorian Fainelli 10065e004460SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, off, ®); 10075e004460SFlorian Fainelli reg |= val; 10085e004460SFlorian Fainelli if (link) 1009967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_LINK; 10105e004460SFlorian Fainelli else 10115e004460SFlorian Fainelli reg &= ~PORT_OVERRIDE_LINK; 10125e004460SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, off, reg); 10135e004460SFlorian Fainelli } 1014967dd82fSFlorian Fainelli 10155e004460SFlorian Fainelli static void b53_force_port_config(struct b53_device *dev, int port, 10165e004460SFlorian Fainelli int speed, int duplex, int pause) 10175e004460SFlorian Fainelli { 10185e004460SFlorian Fainelli u8 reg, val, off; 10195e004460SFlorian Fainelli 10205e004460SFlorian Fainelli /* Override the port settings */ 10215e004460SFlorian Fainelli if (port == dev->cpu_port) { 10225e004460SFlorian Fainelli off = B53_PORT_OVERRIDE_CTRL; 10235e004460SFlorian Fainelli val = PORT_OVERRIDE_EN; 10245e004460SFlorian Fainelli } else { 10255e004460SFlorian Fainelli off = B53_GMII_PORT_OVERRIDE_CTRL(port); 10265e004460SFlorian Fainelli val = GMII_PO_EN; 10275e004460SFlorian Fainelli } 10285e004460SFlorian Fainelli 10295e004460SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, off, ®); 10305e004460SFlorian Fainelli reg |= val; 10315e004460SFlorian Fainelli if (duplex == DUPLEX_FULL) 1032967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_FULL_DUPLEX; 10335e004460SFlorian Fainelli else 10345e004460SFlorian Fainelli reg &= ~PORT_OVERRIDE_FULL_DUPLEX; 1035967dd82fSFlorian Fainelli 10365e004460SFlorian Fainelli switch (speed) { 1037967dd82fSFlorian Fainelli case 2000: 1038967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_2000M; 1039967dd82fSFlorian Fainelli /* fallthrough */ 1040967dd82fSFlorian Fainelli case SPEED_1000: 1041967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_1000M; 1042967dd82fSFlorian Fainelli break; 1043967dd82fSFlorian Fainelli case SPEED_100: 1044967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_100M; 1045967dd82fSFlorian Fainelli break; 1046967dd82fSFlorian Fainelli case SPEED_10: 1047967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_10M; 1048967dd82fSFlorian Fainelli break; 1049967dd82fSFlorian Fainelli default: 10505e004460SFlorian Fainelli dev_err(dev->dev, "unknown speed: %d\n", speed); 1051967dd82fSFlorian Fainelli return; 1052967dd82fSFlorian Fainelli } 1053967dd82fSFlorian Fainelli 10545e004460SFlorian Fainelli if (pause & MLO_PAUSE_RX) 10555e004460SFlorian Fainelli reg |= PORT_OVERRIDE_RX_FLOW; 10565e004460SFlorian Fainelli if (pause & MLO_PAUSE_TX) 10575e004460SFlorian Fainelli reg |= PORT_OVERRIDE_TX_FLOW; 10585e004460SFlorian Fainelli 10595e004460SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, off, reg); 10605e004460SFlorian Fainelli } 10615e004460SFlorian Fainelli 10625e004460SFlorian Fainelli static void b53_adjust_link(struct dsa_switch *ds, int port, 10635e004460SFlorian Fainelli struct phy_device *phydev) 10645e004460SFlorian Fainelli { 10655e004460SFlorian Fainelli struct b53_device *dev = ds->priv; 10665e004460SFlorian Fainelli struct ethtool_eee *p = &dev->ports[port].eee; 10675e004460SFlorian Fainelli u8 rgmii_ctrl = 0, reg = 0, off; 1068f973b768SDan Carpenter int pause = 0; 10695e004460SFlorian Fainelli 10705e004460SFlorian Fainelli if (!phy_is_pseudo_fixed_link(phydev)) 10715e004460SFlorian Fainelli return; 10725e004460SFlorian Fainelli 1073967dd82fSFlorian Fainelli /* Enable flow control on BCM5301x's CPU port */ 1074967dd82fSFlorian Fainelli if (is5301x(dev) && port == dev->cpu_port) 10755e004460SFlorian Fainelli pause = MLO_PAUSE_TXRX_MASK; 1076967dd82fSFlorian Fainelli 1077967dd82fSFlorian Fainelli if (phydev->pause) { 1078967dd82fSFlorian Fainelli if (phydev->asym_pause) 10795e004460SFlorian Fainelli pause |= MLO_PAUSE_TX; 10805e004460SFlorian Fainelli pause |= MLO_PAUSE_RX; 1081967dd82fSFlorian Fainelli } 1082967dd82fSFlorian Fainelli 10835e004460SFlorian Fainelli b53_force_port_config(dev, port, phydev->speed, phydev->duplex, pause); 10845e004460SFlorian Fainelli b53_force_link(dev, port, phydev->link); 1085967dd82fSFlorian Fainelli 1086967dd82fSFlorian Fainelli if (is531x5(dev) && phy_interface_is_rgmii(phydev)) { 1087967dd82fSFlorian Fainelli if (port == 8) 1088967dd82fSFlorian Fainelli off = B53_RGMII_CTRL_IMP; 1089967dd82fSFlorian Fainelli else 1090967dd82fSFlorian Fainelli off = B53_RGMII_CTRL_P(port); 1091967dd82fSFlorian Fainelli 1092967dd82fSFlorian Fainelli /* Configure the port RGMII clock delay by DLL disabled and 1093967dd82fSFlorian Fainelli * tx_clk aligned timing (restoring to reset defaults) 1094967dd82fSFlorian Fainelli */ 1095967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, off, &rgmii_ctrl); 1096967dd82fSFlorian Fainelli rgmii_ctrl &= ~(RGMII_CTRL_DLL_RXC | RGMII_CTRL_DLL_TXC | 1097967dd82fSFlorian Fainelli RGMII_CTRL_TIMING_SEL); 1098967dd82fSFlorian Fainelli 1099967dd82fSFlorian Fainelli /* PHY_INTERFACE_MODE_RGMII_TXID means TX internal delay, make 1100967dd82fSFlorian Fainelli * sure that we enable the port TX clock internal delay to 1101967dd82fSFlorian Fainelli * account for this internal delay that is inserted, otherwise 1102967dd82fSFlorian Fainelli * the switch won't be able to receive correctly. 1103967dd82fSFlorian Fainelli * 1104967dd82fSFlorian Fainelli * PHY_INTERFACE_MODE_RGMII means that we are not introducing 1105967dd82fSFlorian Fainelli * any delay neither on transmission nor reception, so the 1106967dd82fSFlorian Fainelli * BCM53125 must also be configured accordingly to account for 1107967dd82fSFlorian Fainelli * the lack of delay and introduce 1108967dd82fSFlorian Fainelli * 1109967dd82fSFlorian Fainelli * The BCM53125 switch has its RX clock and TX clock control 1110967dd82fSFlorian Fainelli * swapped, hence the reason why we modify the TX clock path in 1111967dd82fSFlorian Fainelli * the "RGMII" case 1112967dd82fSFlorian Fainelli */ 1113967dd82fSFlorian Fainelli if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) 1114967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_DLL_TXC; 1115967dd82fSFlorian Fainelli if (phydev->interface == PHY_INTERFACE_MODE_RGMII) 1116967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_DLL_TXC | RGMII_CTRL_DLL_RXC; 1117967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_TIMING_SEL; 1118967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, off, rgmii_ctrl); 1119967dd82fSFlorian Fainelli 1120967dd82fSFlorian Fainelli dev_info(ds->dev, "Configured port %d for %s\n", port, 1121967dd82fSFlorian Fainelli phy_modes(phydev->interface)); 1122967dd82fSFlorian Fainelli } 1123967dd82fSFlorian Fainelli 1124967dd82fSFlorian Fainelli /* configure MII port if necessary */ 1125967dd82fSFlorian Fainelli if (is5325(dev)) { 1126967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, 1127967dd82fSFlorian Fainelli ®); 1128967dd82fSFlorian Fainelli 1129967dd82fSFlorian Fainelli /* reverse mii needs to be enabled */ 1130967dd82fSFlorian Fainelli if (!(reg & PORT_OVERRIDE_RV_MII_25)) { 1131967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, 1132967dd82fSFlorian Fainelli reg | PORT_OVERRIDE_RV_MII_25); 1133967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, 1134967dd82fSFlorian Fainelli ®); 1135967dd82fSFlorian Fainelli 1136967dd82fSFlorian Fainelli if (!(reg & PORT_OVERRIDE_RV_MII_25)) { 1137967dd82fSFlorian Fainelli dev_err(ds->dev, 1138967dd82fSFlorian Fainelli "Failed to enable reverse MII mode\n"); 1139967dd82fSFlorian Fainelli return; 1140967dd82fSFlorian Fainelli } 1141967dd82fSFlorian Fainelli } 1142967dd82fSFlorian Fainelli } else if (is5301x(dev)) { 1143967dd82fSFlorian Fainelli if (port != dev->cpu_port) { 11445e004460SFlorian Fainelli b53_force_port_config(dev, dev->cpu_port, 2000, 11455e004460SFlorian Fainelli DUPLEX_FULL, MLO_PAUSE_TXRX_MASK); 11465e004460SFlorian Fainelli b53_force_link(dev, dev->cpu_port, 1); 1147967dd82fSFlorian Fainelli } 1148967dd82fSFlorian Fainelli } 1149f43a2dbeSFlorian Fainelli 1150f43a2dbeSFlorian Fainelli /* Re-negotiate EEE if it was enabled already */ 1151f43a2dbeSFlorian Fainelli p->eee_enabled = b53_eee_init(ds, port, phydev); 1152967dd82fSFlorian Fainelli } 1153967dd82fSFlorian Fainelli 1154a8e8b985SFlorian Fainelli void b53_port_event(struct dsa_switch *ds, int port) 1155a8e8b985SFlorian Fainelli { 1156a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1157a8e8b985SFlorian Fainelli bool link; 1158a8e8b985SFlorian Fainelli u16 sts; 1159a8e8b985SFlorian Fainelli 1160a8e8b985SFlorian Fainelli b53_read16(dev, B53_STAT_PAGE, B53_LINK_STAT, &sts); 1161a8e8b985SFlorian Fainelli link = !!(sts & BIT(port)); 1162a8e8b985SFlorian Fainelli dsa_port_phylink_mac_change(ds, port, link); 1163a8e8b985SFlorian Fainelli } 1164a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_port_event); 1165a8e8b985SFlorian Fainelli 1166a8e8b985SFlorian Fainelli void b53_phylink_validate(struct dsa_switch *ds, int port, 1167a8e8b985SFlorian Fainelli unsigned long *supported, 1168a8e8b985SFlorian Fainelli struct phylink_link_state *state) 1169a8e8b985SFlorian Fainelli { 1170a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1171a8e8b985SFlorian Fainelli __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, }; 1172a8e8b985SFlorian Fainelli 11730e01491dSFlorian Fainelli if (dev->ops->serdes_phylink_validate) 11740e01491dSFlorian Fainelli dev->ops->serdes_phylink_validate(dev, port, mask, state); 11750e01491dSFlorian Fainelli 1176a8e8b985SFlorian Fainelli /* Allow all the expected bits */ 1177a8e8b985SFlorian Fainelli phylink_set(mask, Autoneg); 1178a8e8b985SFlorian Fainelli phylink_set_port_modes(mask); 1179a8e8b985SFlorian Fainelli phylink_set(mask, Pause); 1180a8e8b985SFlorian Fainelli phylink_set(mask, Asym_Pause); 1181a8e8b985SFlorian Fainelli 1182a8e8b985SFlorian Fainelli /* With the exclusion of 5325/5365, MII, Reverse MII and 802.3z, we 1183a8e8b985SFlorian Fainelli * support Gigabit, including Half duplex. 1184a8e8b985SFlorian Fainelli */ 1185a8e8b985SFlorian Fainelli if (state->interface != PHY_INTERFACE_MODE_MII && 1186a8e8b985SFlorian Fainelli state->interface != PHY_INTERFACE_MODE_REVMII && 1187a8e8b985SFlorian Fainelli !phy_interface_mode_is_8023z(state->interface) && 1188a8e8b985SFlorian Fainelli !(is5325(dev) || is5365(dev))) { 1189a8e8b985SFlorian Fainelli phylink_set(mask, 1000baseT_Full); 1190a8e8b985SFlorian Fainelli phylink_set(mask, 1000baseT_Half); 1191a8e8b985SFlorian Fainelli } 1192a8e8b985SFlorian Fainelli 1193a8e8b985SFlorian Fainelli if (!phy_interface_mode_is_8023z(state->interface)) { 1194a8e8b985SFlorian Fainelli phylink_set(mask, 10baseT_Half); 1195a8e8b985SFlorian Fainelli phylink_set(mask, 10baseT_Full); 1196a8e8b985SFlorian Fainelli phylink_set(mask, 100baseT_Half); 1197a8e8b985SFlorian Fainelli phylink_set(mask, 100baseT_Full); 1198a8e8b985SFlorian Fainelli } 1199a8e8b985SFlorian Fainelli 1200a8e8b985SFlorian Fainelli bitmap_and(supported, supported, mask, 1201a8e8b985SFlorian Fainelli __ETHTOOL_LINK_MODE_MASK_NBITS); 1202a8e8b985SFlorian Fainelli bitmap_and(state->advertising, state->advertising, mask, 1203a8e8b985SFlorian Fainelli __ETHTOOL_LINK_MODE_MASK_NBITS); 1204a8e8b985SFlorian Fainelli 1205a8e8b985SFlorian Fainelli phylink_helper_basex_speed(state); 1206a8e8b985SFlorian Fainelli } 1207a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_validate); 1208a8e8b985SFlorian Fainelli 1209a8e8b985SFlorian Fainelli int b53_phylink_mac_link_state(struct dsa_switch *ds, int port, 1210a8e8b985SFlorian Fainelli struct phylink_link_state *state) 1211a8e8b985SFlorian Fainelli { 12120e01491dSFlorian Fainelli struct b53_device *dev = ds->priv; 1213a8e8b985SFlorian Fainelli int ret = -EOPNOTSUPP; 1214a8e8b985SFlorian Fainelli 121555a4d2eaSFlorian Fainelli if ((phy_interface_mode_is_8023z(state->interface) || 121655a4d2eaSFlorian Fainelli state->interface == PHY_INTERFACE_MODE_SGMII) && 12170e01491dSFlorian Fainelli dev->ops->serdes_link_state) 12180e01491dSFlorian Fainelli ret = dev->ops->serdes_link_state(dev, port, state); 12190e01491dSFlorian Fainelli 1220a8e8b985SFlorian Fainelli return ret; 1221a8e8b985SFlorian Fainelli } 1222a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_state); 1223a8e8b985SFlorian Fainelli 1224a8e8b985SFlorian Fainelli void b53_phylink_mac_config(struct dsa_switch *ds, int port, 1225a8e8b985SFlorian Fainelli unsigned int mode, 1226a8e8b985SFlorian Fainelli const struct phylink_link_state *state) 1227a8e8b985SFlorian Fainelli { 1228a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1229a8e8b985SFlorian Fainelli 1230a8e8b985SFlorian Fainelli if (mode == MLO_AN_PHY) 1231a8e8b985SFlorian Fainelli return; 1232a8e8b985SFlorian Fainelli 1233a8e8b985SFlorian Fainelli if (mode == MLO_AN_FIXED) { 1234a8e8b985SFlorian Fainelli b53_force_port_config(dev, port, state->speed, 1235a8e8b985SFlorian Fainelli state->duplex, state->pause); 1236a8e8b985SFlorian Fainelli return; 1237a8e8b985SFlorian Fainelli } 12380e01491dSFlorian Fainelli 123955a4d2eaSFlorian Fainelli if ((phy_interface_mode_is_8023z(state->interface) || 124055a4d2eaSFlorian Fainelli state->interface == PHY_INTERFACE_MODE_SGMII) && 12410e01491dSFlorian Fainelli dev->ops->serdes_config) 12420e01491dSFlorian Fainelli dev->ops->serdes_config(dev, port, mode, state); 1243a8e8b985SFlorian Fainelli } 1244a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_config); 1245a8e8b985SFlorian Fainelli 1246a8e8b985SFlorian Fainelli void b53_phylink_mac_an_restart(struct dsa_switch *ds, int port) 1247a8e8b985SFlorian Fainelli { 12480e01491dSFlorian Fainelli struct b53_device *dev = ds->priv; 12490e01491dSFlorian Fainelli 12500e01491dSFlorian Fainelli if (dev->ops->serdes_an_restart) 12510e01491dSFlorian Fainelli dev->ops->serdes_an_restart(dev, port); 1252a8e8b985SFlorian Fainelli } 1253a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_an_restart); 1254a8e8b985SFlorian Fainelli 1255a8e8b985SFlorian Fainelli void b53_phylink_mac_link_down(struct dsa_switch *ds, int port, 1256a8e8b985SFlorian Fainelli unsigned int mode, 1257a8e8b985SFlorian Fainelli phy_interface_t interface) 1258a8e8b985SFlorian Fainelli { 1259a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1260a8e8b985SFlorian Fainelli 1261a8e8b985SFlorian Fainelli if (mode == MLO_AN_PHY) 1262a8e8b985SFlorian Fainelli return; 1263a8e8b985SFlorian Fainelli 1264a8e8b985SFlorian Fainelli if (mode == MLO_AN_FIXED) { 1265a8e8b985SFlorian Fainelli b53_force_link(dev, port, false); 1266a8e8b985SFlorian Fainelli return; 1267a8e8b985SFlorian Fainelli } 12680e01491dSFlorian Fainelli 12690e01491dSFlorian Fainelli if (phy_interface_mode_is_8023z(interface) && 12700e01491dSFlorian Fainelli dev->ops->serdes_link_set) 12710e01491dSFlorian Fainelli dev->ops->serdes_link_set(dev, port, mode, interface, false); 1272a8e8b985SFlorian Fainelli } 1273a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_down); 1274a8e8b985SFlorian Fainelli 1275a8e8b985SFlorian Fainelli void b53_phylink_mac_link_up(struct dsa_switch *ds, int port, 1276a8e8b985SFlorian Fainelli unsigned int mode, 1277a8e8b985SFlorian Fainelli phy_interface_t interface, 1278a8e8b985SFlorian Fainelli struct phy_device *phydev) 1279a8e8b985SFlorian Fainelli { 1280a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1281a8e8b985SFlorian Fainelli 1282a8e8b985SFlorian Fainelli if (mode == MLO_AN_PHY) 1283a8e8b985SFlorian Fainelli return; 1284a8e8b985SFlorian Fainelli 1285a8e8b985SFlorian Fainelli if (mode == MLO_AN_FIXED) { 1286a8e8b985SFlorian Fainelli b53_force_link(dev, port, true); 1287a8e8b985SFlorian Fainelli return; 1288a8e8b985SFlorian Fainelli } 12890e01491dSFlorian Fainelli 12900e01491dSFlorian Fainelli if (phy_interface_mode_is_8023z(interface) && 12910e01491dSFlorian Fainelli dev->ops->serdes_link_set) 12920e01491dSFlorian Fainelli dev->ops->serdes_link_set(dev, port, mode, interface, true); 1293a8e8b985SFlorian Fainelli } 1294a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_up); 1295a8e8b985SFlorian Fainelli 12963117455dSFlorian Fainelli int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering) 1297a2482d2cSFlorian Fainelli { 1298dad8d7c6SFlorian Fainelli struct b53_device *dev = ds->priv; 1299dad8d7c6SFlorian Fainelli u16 pvid, new_pvid; 1300dad8d7c6SFlorian Fainelli 1301dad8d7c6SFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid); 1302dad8d7c6SFlorian Fainelli new_pvid = pvid; 1303864cd7b0SVladimir Oltean if (!vlan_filtering) { 1304dad8d7c6SFlorian Fainelli /* Filtering is currently enabled, use the default PVID since 1305dad8d7c6SFlorian Fainelli * the bridge does not expect tagging anymore 1306dad8d7c6SFlorian Fainelli */ 1307dad8d7c6SFlorian Fainelli dev->ports[port].pvid = pvid; 1308dad8d7c6SFlorian Fainelli new_pvid = b53_default_pvid(dev); 1309864cd7b0SVladimir Oltean } else { 1310dad8d7c6SFlorian Fainelli /* Filtering is currently disabled, restore the previous PVID */ 1311dad8d7c6SFlorian Fainelli new_pvid = dev->ports[port].pvid; 1312dad8d7c6SFlorian Fainelli } 1313dad8d7c6SFlorian Fainelli 1314dad8d7c6SFlorian Fainelli if (pvid != new_pvid) 1315dad8d7c6SFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), 1316dad8d7c6SFlorian Fainelli new_pvid); 1317dad8d7c6SFlorian Fainelli 1318dad8d7c6SFlorian Fainelli b53_enable_vlan(dev, dev->vlan_enabled, vlan_filtering); 1319dad8d7c6SFlorian Fainelli 1320a2482d2cSFlorian Fainelli return 0; 1321a2482d2cSFlorian Fainelli } 13223117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_filtering); 1323a2482d2cSFlorian Fainelli 13243117455dSFlorian Fainelli int b53_vlan_prepare(struct dsa_switch *ds, int port, 132580e02360SVivien Didelot const struct switchdev_obj_port_vlan *vlan) 1326a2482d2cSFlorian Fainelli { 132704bed143SVivien Didelot struct b53_device *dev = ds->priv; 1328a2482d2cSFlorian Fainelli 1329a2482d2cSFlorian Fainelli if ((is5325(dev) || is5365(dev)) && vlan->vid_begin == 0) 1330a2482d2cSFlorian Fainelli return -EOPNOTSUPP; 1331a2482d2cSFlorian Fainelli 1332a2482d2cSFlorian Fainelli if (vlan->vid_end > dev->num_vlans) 1333a2482d2cSFlorian Fainelli return -ERANGE; 1334a2482d2cSFlorian Fainelli 1335e74f014eSVladimir Oltean b53_enable_vlan(dev, true, ds->vlan_filtering); 1336a2482d2cSFlorian Fainelli 1337a2482d2cSFlorian Fainelli return 0; 1338a2482d2cSFlorian Fainelli } 13393117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_prepare); 1340a2482d2cSFlorian Fainelli 13413117455dSFlorian Fainelli void b53_vlan_add(struct dsa_switch *ds, int port, 134280e02360SVivien Didelot const struct switchdev_obj_port_vlan *vlan) 1343a2482d2cSFlorian Fainelli { 134404bed143SVivien Didelot struct b53_device *dev = ds->priv; 1345a2482d2cSFlorian Fainelli bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; 1346a2482d2cSFlorian Fainelli bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID; 1347a2482d2cSFlorian Fainelli struct b53_vlan *vl; 1348a2482d2cSFlorian Fainelli u16 vid; 1349a2482d2cSFlorian Fainelli 1350a2482d2cSFlorian Fainelli for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) { 1351a2482d2cSFlorian Fainelli vl = &dev->vlans[vid]; 1352a2482d2cSFlorian Fainelli 1353a2482d2cSFlorian Fainelli b53_get_vlan_entry(dev, vid, vl); 1354a2482d2cSFlorian Fainelli 1355c499696eSFlorian Fainelli vl->members |= BIT(port); 1356ca893194SFlorian Fainelli if (untagged && !dsa_is_cpu_port(ds, port)) 1357e47112d9SFlorian Fainelli vl->untag |= BIT(port); 1358a2482d2cSFlorian Fainelli else 1359e47112d9SFlorian Fainelli vl->untag &= ~BIT(port); 1360a2482d2cSFlorian Fainelli 1361a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, vid, vl); 1362a2482d2cSFlorian Fainelli b53_fast_age_vlan(dev, vid); 1363a2482d2cSFlorian Fainelli } 1364a2482d2cSFlorian Fainelli 136510163aaeSFlorian Fainelli if (pvid && !dsa_is_cpu_port(ds, port)) { 1366a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), 1367a2482d2cSFlorian Fainelli vlan->vid_end); 1368a2482d2cSFlorian Fainelli b53_fast_age_vlan(dev, vid); 1369a2482d2cSFlorian Fainelli } 1370a2482d2cSFlorian Fainelli } 13713117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_add); 1372a2482d2cSFlorian Fainelli 13733117455dSFlorian Fainelli int b53_vlan_del(struct dsa_switch *ds, int port, 1374a2482d2cSFlorian Fainelli const struct switchdev_obj_port_vlan *vlan) 1375a2482d2cSFlorian Fainelli { 137604bed143SVivien Didelot struct b53_device *dev = ds->priv; 1377a2482d2cSFlorian Fainelli bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; 1378a2482d2cSFlorian Fainelli struct b53_vlan *vl; 1379a2482d2cSFlorian Fainelli u16 vid; 1380a2482d2cSFlorian Fainelli u16 pvid; 1381a2482d2cSFlorian Fainelli 1382a2482d2cSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid); 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 1389a2482d2cSFlorian Fainelli vl->members &= ~BIT(port); 1390a2482d2cSFlorian Fainelli 1391fea83353SFlorian Fainelli if (pvid == vid) 1392fea83353SFlorian Fainelli pvid = b53_default_pvid(dev); 1393a2482d2cSFlorian Fainelli 1394ca893194SFlorian Fainelli if (untagged && !dsa_is_cpu_port(ds, port)) 1395a2482d2cSFlorian Fainelli vl->untag &= ~(BIT(port)); 1396a2482d2cSFlorian Fainelli 1397a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, vid, vl); 1398a2482d2cSFlorian Fainelli b53_fast_age_vlan(dev, vid); 1399a2482d2cSFlorian Fainelli } 1400a2482d2cSFlorian Fainelli 1401a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), pvid); 1402a2482d2cSFlorian Fainelli b53_fast_age_vlan(dev, pvid); 1403a2482d2cSFlorian Fainelli 1404a2482d2cSFlorian Fainelli return 0; 1405a2482d2cSFlorian Fainelli } 14063117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_del); 1407a2482d2cSFlorian Fainelli 14081da6df85SFlorian Fainelli /* Address Resolution Logic routines */ 14091da6df85SFlorian Fainelli static int b53_arl_op_wait(struct b53_device *dev) 14101da6df85SFlorian Fainelli { 14111da6df85SFlorian Fainelli unsigned int timeout = 10; 14121da6df85SFlorian Fainelli u8 reg; 14131da6df85SFlorian Fainelli 14141da6df85SFlorian Fainelli do { 14151da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, ®); 14161da6df85SFlorian Fainelli if (!(reg & ARLTBL_START_DONE)) 14171da6df85SFlorian Fainelli return 0; 14181da6df85SFlorian Fainelli 14191da6df85SFlorian Fainelli usleep_range(1000, 2000); 14201da6df85SFlorian Fainelli } while (timeout--); 14211da6df85SFlorian Fainelli 14221da6df85SFlorian Fainelli dev_warn(dev->dev, "timeout waiting for ARL to finish: 0x%02x\n", reg); 14231da6df85SFlorian Fainelli 14241da6df85SFlorian Fainelli return -ETIMEDOUT; 14251da6df85SFlorian Fainelli } 14261da6df85SFlorian Fainelli 14271da6df85SFlorian Fainelli static int b53_arl_rw_op(struct b53_device *dev, unsigned int op) 14281da6df85SFlorian Fainelli { 14291da6df85SFlorian Fainelli u8 reg; 14301da6df85SFlorian Fainelli 14311da6df85SFlorian Fainelli if (op > ARLTBL_RW) 14321da6df85SFlorian Fainelli return -EINVAL; 14331da6df85SFlorian Fainelli 14341da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, ®); 14351da6df85SFlorian Fainelli reg |= ARLTBL_START_DONE; 14361da6df85SFlorian Fainelli if (op) 14371da6df85SFlorian Fainelli reg |= ARLTBL_RW; 14381da6df85SFlorian Fainelli else 14391da6df85SFlorian Fainelli reg &= ~ARLTBL_RW; 14401da6df85SFlorian Fainelli b53_write8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, reg); 14411da6df85SFlorian Fainelli 14421da6df85SFlorian Fainelli return b53_arl_op_wait(dev); 14431da6df85SFlorian Fainelli } 14441da6df85SFlorian Fainelli 14451da6df85SFlorian Fainelli static int b53_arl_read(struct b53_device *dev, u64 mac, 14461da6df85SFlorian Fainelli u16 vid, struct b53_arl_entry *ent, u8 *idx, 14471da6df85SFlorian Fainelli bool is_valid) 14481da6df85SFlorian Fainelli { 14491da6df85SFlorian Fainelli unsigned int i; 14501da6df85SFlorian Fainelli int ret; 14511da6df85SFlorian Fainelli 14521da6df85SFlorian Fainelli ret = b53_arl_op_wait(dev); 14531da6df85SFlorian Fainelli if (ret) 14541da6df85SFlorian Fainelli return ret; 14551da6df85SFlorian Fainelli 14561da6df85SFlorian Fainelli /* Read the bins */ 14571da6df85SFlorian Fainelli for (i = 0; i < dev->num_arl_entries; i++) { 14581da6df85SFlorian Fainelli u64 mac_vid; 14591da6df85SFlorian Fainelli u32 fwd_entry; 14601da6df85SFlorian Fainelli 14611da6df85SFlorian Fainelli b53_read64(dev, B53_ARLIO_PAGE, 14621da6df85SFlorian Fainelli B53_ARLTBL_MAC_VID_ENTRY(i), &mac_vid); 14631da6df85SFlorian Fainelli b53_read32(dev, B53_ARLIO_PAGE, 14641da6df85SFlorian Fainelli B53_ARLTBL_DATA_ENTRY(i), &fwd_entry); 14651da6df85SFlorian Fainelli b53_arl_to_entry(ent, mac_vid, fwd_entry); 14661da6df85SFlorian Fainelli 14671da6df85SFlorian Fainelli if (!(fwd_entry & ARLTBL_VALID)) 14681da6df85SFlorian Fainelli continue; 14691da6df85SFlorian Fainelli if ((mac_vid & ARLTBL_MAC_MASK) != mac) 14701da6df85SFlorian Fainelli continue; 14711da6df85SFlorian Fainelli *idx = i; 14721da6df85SFlorian Fainelli } 14731da6df85SFlorian Fainelli 14741da6df85SFlorian Fainelli return -ENOENT; 14751da6df85SFlorian Fainelli } 14761da6df85SFlorian Fainelli 14771da6df85SFlorian Fainelli static int b53_arl_op(struct b53_device *dev, int op, int port, 14781da6df85SFlorian Fainelli const unsigned char *addr, u16 vid, bool is_valid) 14791da6df85SFlorian Fainelli { 14801da6df85SFlorian Fainelli struct b53_arl_entry ent; 14811da6df85SFlorian Fainelli u32 fwd_entry; 14821da6df85SFlorian Fainelli u64 mac, mac_vid = 0; 14831da6df85SFlorian Fainelli u8 idx = 0; 14841da6df85SFlorian Fainelli int ret; 14851da6df85SFlorian Fainelli 14861da6df85SFlorian Fainelli /* Convert the array into a 64-bit MAC */ 14874b92ea81SFlorian Fainelli mac = ether_addr_to_u64(addr); 14881da6df85SFlorian Fainelli 14891da6df85SFlorian Fainelli /* Perform a read for the given MAC and VID */ 14901da6df85SFlorian Fainelli b53_write48(dev, B53_ARLIO_PAGE, B53_MAC_ADDR_IDX, mac); 14911da6df85SFlorian Fainelli b53_write16(dev, B53_ARLIO_PAGE, B53_VLAN_ID_IDX, vid); 14921da6df85SFlorian Fainelli 14931da6df85SFlorian Fainelli /* Issue a read operation for this MAC */ 14941da6df85SFlorian Fainelli ret = b53_arl_rw_op(dev, 1); 14951da6df85SFlorian Fainelli if (ret) 14961da6df85SFlorian Fainelli return ret; 14971da6df85SFlorian Fainelli 14981da6df85SFlorian Fainelli ret = b53_arl_read(dev, mac, vid, &ent, &idx, is_valid); 14991da6df85SFlorian Fainelli /* If this is a read, just finish now */ 15001da6df85SFlorian Fainelli if (op) 15011da6df85SFlorian Fainelli return ret; 15021da6df85SFlorian Fainelli 15031da6df85SFlorian Fainelli /* We could not find a matching MAC, so reset to a new entry */ 15041da6df85SFlorian Fainelli if (ret) { 15051da6df85SFlorian Fainelli fwd_entry = 0; 15061da6df85SFlorian Fainelli idx = 1; 15071da6df85SFlorian Fainelli } 15081da6df85SFlorian Fainelli 15095d65b64aSFlorian Fainelli /* For multicast address, the port is a bitmask and the validity 15105d65b64aSFlorian Fainelli * is determined by having at least one port being still active 15115d65b64aSFlorian Fainelli */ 15125d65b64aSFlorian Fainelli if (!is_multicast_ether_addr(addr)) { 15131da6df85SFlorian Fainelli ent.port = port; 15141da6df85SFlorian Fainelli ent.is_valid = is_valid; 15155d65b64aSFlorian Fainelli } else { 15165d65b64aSFlorian Fainelli if (is_valid) 15175d65b64aSFlorian Fainelli ent.port |= BIT(port); 15185d65b64aSFlorian Fainelli else 15195d65b64aSFlorian Fainelli ent.port &= ~BIT(port); 15205d65b64aSFlorian Fainelli 15215d65b64aSFlorian Fainelli ent.is_valid = !!(ent.port); 15225d65b64aSFlorian Fainelli } 15235d65b64aSFlorian Fainelli 15245d65b64aSFlorian Fainelli ent.is_valid = is_valid; 15251da6df85SFlorian Fainelli ent.vid = vid; 15261da6df85SFlorian Fainelli ent.is_static = true; 15275d65b64aSFlorian Fainelli ent.is_age = false; 15281da6df85SFlorian Fainelli memcpy(ent.mac, addr, ETH_ALEN); 15291da6df85SFlorian Fainelli b53_arl_from_entry(&mac_vid, &fwd_entry, &ent); 15301da6df85SFlorian Fainelli 15311da6df85SFlorian Fainelli b53_write64(dev, B53_ARLIO_PAGE, 15321da6df85SFlorian Fainelli B53_ARLTBL_MAC_VID_ENTRY(idx), mac_vid); 15331da6df85SFlorian Fainelli b53_write32(dev, B53_ARLIO_PAGE, 15341da6df85SFlorian Fainelli B53_ARLTBL_DATA_ENTRY(idx), fwd_entry); 15351da6df85SFlorian Fainelli 15361da6df85SFlorian Fainelli return b53_arl_rw_op(dev, 0); 15371da6df85SFlorian Fainelli } 15381da6df85SFlorian Fainelli 15391b6dd556SArkadi Sharshevsky int b53_fdb_add(struct dsa_switch *ds, int port, 15406c2c1dcbSArkadi Sharshevsky const unsigned char *addr, u16 vid) 15411da6df85SFlorian Fainelli { 154204bed143SVivien Didelot struct b53_device *priv = ds->priv; 15431da6df85SFlorian Fainelli 15441da6df85SFlorian Fainelli /* 5325 and 5365 require some more massaging, but could 15451da6df85SFlorian Fainelli * be supported eventually 15461da6df85SFlorian Fainelli */ 15471da6df85SFlorian Fainelli if (is5325(priv) || is5365(priv)) 15481da6df85SFlorian Fainelli return -EOPNOTSUPP; 15491da6df85SFlorian Fainelli 15501b6dd556SArkadi Sharshevsky return b53_arl_op(priv, 0, port, addr, vid, true); 15511da6df85SFlorian Fainelli } 15523117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_add); 15531da6df85SFlorian Fainelli 15543117455dSFlorian Fainelli int b53_fdb_del(struct dsa_switch *ds, int port, 15556c2c1dcbSArkadi Sharshevsky const unsigned char *addr, u16 vid) 15561da6df85SFlorian Fainelli { 155704bed143SVivien Didelot struct b53_device *priv = ds->priv; 15581da6df85SFlorian Fainelli 15596c2c1dcbSArkadi Sharshevsky return b53_arl_op(priv, 0, port, addr, vid, false); 15601da6df85SFlorian Fainelli } 15613117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_del); 15621da6df85SFlorian Fainelli 15631da6df85SFlorian Fainelli static int b53_arl_search_wait(struct b53_device *dev) 15641da6df85SFlorian Fainelli { 15651da6df85SFlorian Fainelli unsigned int timeout = 1000; 15661da6df85SFlorian Fainelli u8 reg; 15671da6df85SFlorian Fainelli 15681da6df85SFlorian Fainelli do { 15691da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, ®); 15701da6df85SFlorian Fainelli if (!(reg & ARL_SRCH_STDN)) 15711da6df85SFlorian Fainelli return 0; 15721da6df85SFlorian Fainelli 15731da6df85SFlorian Fainelli if (reg & ARL_SRCH_VLID) 15741da6df85SFlorian Fainelli return 0; 15751da6df85SFlorian Fainelli 15761da6df85SFlorian Fainelli usleep_range(1000, 2000); 15771da6df85SFlorian Fainelli } while (timeout--); 15781da6df85SFlorian Fainelli 15791da6df85SFlorian Fainelli return -ETIMEDOUT; 15801da6df85SFlorian Fainelli } 15811da6df85SFlorian Fainelli 15821da6df85SFlorian Fainelli static void b53_arl_search_rd(struct b53_device *dev, u8 idx, 15831da6df85SFlorian Fainelli struct b53_arl_entry *ent) 15841da6df85SFlorian Fainelli { 15851da6df85SFlorian Fainelli u64 mac_vid; 15861da6df85SFlorian Fainelli u32 fwd_entry; 15871da6df85SFlorian Fainelli 15881da6df85SFlorian Fainelli b53_read64(dev, B53_ARLIO_PAGE, 15891da6df85SFlorian Fainelli B53_ARL_SRCH_RSTL_MACVID(idx), &mac_vid); 15901da6df85SFlorian Fainelli b53_read32(dev, B53_ARLIO_PAGE, 15911da6df85SFlorian Fainelli B53_ARL_SRCH_RSTL(idx), &fwd_entry); 15921da6df85SFlorian Fainelli b53_arl_to_entry(ent, mac_vid, fwd_entry); 15931da6df85SFlorian Fainelli } 15941da6df85SFlorian Fainelli 1595e6cbef0cSVivien Didelot static int b53_fdb_copy(int port, const struct b53_arl_entry *ent, 15962bedde1aSArkadi Sharshevsky dsa_fdb_dump_cb_t *cb, void *data) 15971da6df85SFlorian Fainelli { 15981da6df85SFlorian Fainelli if (!ent->is_valid) 15991da6df85SFlorian Fainelli return 0; 16001da6df85SFlorian Fainelli 16011da6df85SFlorian Fainelli if (port != ent->port) 16021da6df85SFlorian Fainelli return 0; 16031da6df85SFlorian Fainelli 16042bedde1aSArkadi Sharshevsky return cb(ent->mac, ent->vid, ent->is_static, data); 16051da6df85SFlorian Fainelli } 16061da6df85SFlorian Fainelli 16073117455dSFlorian Fainelli int b53_fdb_dump(struct dsa_switch *ds, int port, 16082bedde1aSArkadi Sharshevsky dsa_fdb_dump_cb_t *cb, void *data) 16091da6df85SFlorian Fainelli { 161004bed143SVivien Didelot struct b53_device *priv = ds->priv; 16111da6df85SFlorian Fainelli struct b53_arl_entry results[2]; 16121da6df85SFlorian Fainelli unsigned int count = 0; 16131da6df85SFlorian Fainelli int ret; 16141da6df85SFlorian Fainelli u8 reg; 16151da6df85SFlorian Fainelli 16161da6df85SFlorian Fainelli /* Start search operation */ 16171da6df85SFlorian Fainelli reg = ARL_SRCH_STDN; 16181da6df85SFlorian Fainelli b53_write8(priv, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, reg); 16191da6df85SFlorian Fainelli 16201da6df85SFlorian Fainelli do { 16211da6df85SFlorian Fainelli ret = b53_arl_search_wait(priv); 16221da6df85SFlorian Fainelli if (ret) 16231da6df85SFlorian Fainelli return ret; 16241da6df85SFlorian Fainelli 16251da6df85SFlorian Fainelli b53_arl_search_rd(priv, 0, &results[0]); 16262bedde1aSArkadi Sharshevsky ret = b53_fdb_copy(port, &results[0], cb, data); 16271da6df85SFlorian Fainelli if (ret) 16281da6df85SFlorian Fainelli return ret; 16291da6df85SFlorian Fainelli 16301da6df85SFlorian Fainelli if (priv->num_arl_entries > 2) { 16311da6df85SFlorian Fainelli b53_arl_search_rd(priv, 1, &results[1]); 16322bedde1aSArkadi Sharshevsky ret = b53_fdb_copy(port, &results[1], cb, data); 16331da6df85SFlorian Fainelli if (ret) 16341da6df85SFlorian Fainelli return ret; 16351da6df85SFlorian Fainelli 16361da6df85SFlorian Fainelli if (!results[0].is_valid && !results[1].is_valid) 16371da6df85SFlorian Fainelli break; 16381da6df85SFlorian Fainelli } 16391da6df85SFlorian Fainelli 16401da6df85SFlorian Fainelli } while (count++ < 1024); 16411da6df85SFlorian Fainelli 16421da6df85SFlorian Fainelli return 0; 16431da6df85SFlorian Fainelli } 16443117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_dump); 16451da6df85SFlorian Fainelli 16465d65b64aSFlorian Fainelli int b53_mdb_prepare(struct dsa_switch *ds, int port, 16475d65b64aSFlorian Fainelli const struct switchdev_obj_port_mdb *mdb) 16485d65b64aSFlorian Fainelli { 16495d65b64aSFlorian Fainelli struct b53_device *priv = ds->priv; 16505d65b64aSFlorian Fainelli 16515d65b64aSFlorian Fainelli /* 5325 and 5365 require some more massaging, but could 16525d65b64aSFlorian Fainelli * be supported eventually 16535d65b64aSFlorian Fainelli */ 16545d65b64aSFlorian Fainelli if (is5325(priv) || is5365(priv)) 16555d65b64aSFlorian Fainelli return -EOPNOTSUPP; 16565d65b64aSFlorian Fainelli 16575d65b64aSFlorian Fainelli return 0; 16585d65b64aSFlorian Fainelli } 16595d65b64aSFlorian Fainelli EXPORT_SYMBOL(b53_mdb_prepare); 16605d65b64aSFlorian Fainelli 16615d65b64aSFlorian Fainelli void b53_mdb_add(struct dsa_switch *ds, int port, 16625d65b64aSFlorian Fainelli const struct switchdev_obj_port_mdb *mdb) 16635d65b64aSFlorian Fainelli { 16645d65b64aSFlorian Fainelli struct b53_device *priv = ds->priv; 16655d65b64aSFlorian Fainelli int ret; 16665d65b64aSFlorian Fainelli 16675d65b64aSFlorian Fainelli ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, true); 16685d65b64aSFlorian Fainelli if (ret) 16695d65b64aSFlorian Fainelli dev_err(ds->dev, "failed to add MDB entry\n"); 16705d65b64aSFlorian Fainelli } 16715d65b64aSFlorian Fainelli EXPORT_SYMBOL(b53_mdb_add); 16725d65b64aSFlorian Fainelli 16735d65b64aSFlorian Fainelli int b53_mdb_del(struct dsa_switch *ds, int port, 16745d65b64aSFlorian Fainelli const struct switchdev_obj_port_mdb *mdb) 16755d65b64aSFlorian Fainelli { 16765d65b64aSFlorian Fainelli struct b53_device *priv = ds->priv; 16775d65b64aSFlorian Fainelli int ret; 16785d65b64aSFlorian Fainelli 16795d65b64aSFlorian Fainelli ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, false); 16805d65b64aSFlorian Fainelli if (ret) 16815d65b64aSFlorian Fainelli dev_err(ds->dev, "failed to delete MDB entry\n"); 16825d65b64aSFlorian Fainelli 16835d65b64aSFlorian Fainelli return ret; 16845d65b64aSFlorian Fainelli } 16855d65b64aSFlorian Fainelli EXPORT_SYMBOL(b53_mdb_del); 16865d65b64aSFlorian Fainelli 1687ddd3a0c8SVivien Didelot int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br) 1688ff39c2d6SFlorian Fainelli { 168904bed143SVivien Didelot struct b53_device *dev = ds->priv; 169068bb8ea8SVivien Didelot s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index; 1691ff39c2d6SFlorian Fainelli u16 pvlan, reg; 1692ff39c2d6SFlorian Fainelli unsigned int i; 1693ff39c2d6SFlorian Fainelli 169448aea33aSFlorian Fainelli /* Make this port leave the all VLANs join since we will have proper 169548aea33aSFlorian Fainelli * VLAN entries from now on 169648aea33aSFlorian Fainelli */ 169748aea33aSFlorian Fainelli if (is58xx(dev)) { 169848aea33aSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, ®); 169948aea33aSFlorian Fainelli reg &= ~BIT(port); 170048aea33aSFlorian Fainelli if ((reg & BIT(cpu_port)) == BIT(cpu_port)) 170148aea33aSFlorian Fainelli reg &= ~BIT(cpu_port); 170248aea33aSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg); 170348aea33aSFlorian Fainelli } 170448aea33aSFlorian Fainelli 1705ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); 1706ff39c2d6SFlorian Fainelli 1707ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) { 1708c8652c83SVivien Didelot if (dsa_to_port(ds, i)->bridge_dev != br) 1709ff39c2d6SFlorian Fainelli continue; 1710ff39c2d6SFlorian Fainelli 1711ff39c2d6SFlorian Fainelli /* Add this local port to the remote port VLAN control 1712ff39c2d6SFlorian Fainelli * membership and update the remote port bitmask 1713ff39c2d6SFlorian Fainelli */ 1714ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), ®); 1715ff39c2d6SFlorian Fainelli reg |= BIT(port); 1716ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg); 1717ff39c2d6SFlorian Fainelli dev->ports[i].vlan_ctl_mask = reg; 1718ff39c2d6SFlorian Fainelli 1719ff39c2d6SFlorian Fainelli pvlan |= BIT(i); 1720ff39c2d6SFlorian Fainelli } 1721ff39c2d6SFlorian Fainelli 1722ff39c2d6SFlorian Fainelli /* Configure the local port VLAN control membership to include 1723ff39c2d6SFlorian Fainelli * remote ports and update the local port bitmask 1724ff39c2d6SFlorian Fainelli */ 1725ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); 1726ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = pvlan; 1727ff39c2d6SFlorian Fainelli 1728ff39c2d6SFlorian Fainelli return 0; 1729ff39c2d6SFlorian Fainelli } 17303117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_join); 1731ff39c2d6SFlorian Fainelli 1732f123f2fbSVivien Didelot void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *br) 1733ff39c2d6SFlorian Fainelli { 173404bed143SVivien Didelot struct b53_device *dev = ds->priv; 1735a2482d2cSFlorian Fainelli struct b53_vlan *vl = &dev->vlans[0]; 173668bb8ea8SVivien Didelot s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index; 1737ff39c2d6SFlorian Fainelli unsigned int i; 1738a2482d2cSFlorian Fainelli u16 pvlan, reg, pvid; 1739ff39c2d6SFlorian Fainelli 1740ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); 1741ff39c2d6SFlorian Fainelli 1742ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) { 1743ff39c2d6SFlorian Fainelli /* Don't touch the remaining ports */ 1744c8652c83SVivien Didelot if (dsa_to_port(ds, i)->bridge_dev != br) 1745ff39c2d6SFlorian Fainelli continue; 1746ff39c2d6SFlorian Fainelli 1747ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), ®); 1748ff39c2d6SFlorian Fainelli reg &= ~BIT(port); 1749ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg); 1750ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = reg; 1751ff39c2d6SFlorian Fainelli 1752ff39c2d6SFlorian Fainelli /* Prevent self removal to preserve isolation */ 1753ff39c2d6SFlorian Fainelli if (port != i) 1754ff39c2d6SFlorian Fainelli pvlan &= ~BIT(i); 1755ff39c2d6SFlorian Fainelli } 1756ff39c2d6SFlorian Fainelli 1757ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); 1758ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = pvlan; 1759a2482d2cSFlorian Fainelli 1760fea83353SFlorian Fainelli pvid = b53_default_pvid(dev); 1761a2482d2cSFlorian Fainelli 176248aea33aSFlorian Fainelli /* Make this port join all VLANs without VLAN entries */ 176348aea33aSFlorian Fainelli if (is58xx(dev)) { 176448aea33aSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, ®); 176548aea33aSFlorian Fainelli reg |= BIT(port); 176648aea33aSFlorian Fainelli if (!(reg & BIT(cpu_port))) 176748aea33aSFlorian Fainelli reg |= BIT(cpu_port); 176848aea33aSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg); 176948aea33aSFlorian Fainelli } else { 1770a2482d2cSFlorian Fainelli b53_get_vlan_entry(dev, pvid, vl); 1771c499696eSFlorian Fainelli vl->members |= BIT(port) | BIT(cpu_port); 1772c499696eSFlorian Fainelli vl->untag |= BIT(port) | BIT(cpu_port); 1773a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, pvid, vl); 1774ff39c2d6SFlorian Fainelli } 177548aea33aSFlorian Fainelli } 17763117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_leave); 1777ff39c2d6SFlorian Fainelli 17783117455dSFlorian Fainelli void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state) 1779ff39c2d6SFlorian Fainelli { 178004bed143SVivien Didelot struct b53_device *dev = ds->priv; 1781597698f1SVivien Didelot u8 hw_state; 1782ff39c2d6SFlorian Fainelli u8 reg; 1783ff39c2d6SFlorian Fainelli 1784ff39c2d6SFlorian Fainelli switch (state) { 1785ff39c2d6SFlorian Fainelli case BR_STATE_DISABLED: 1786ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_DIS_STATE; 1787ff39c2d6SFlorian Fainelli break; 1788ff39c2d6SFlorian Fainelli case BR_STATE_LISTENING: 1789ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_LISTEN_STATE; 1790ff39c2d6SFlorian Fainelli break; 1791ff39c2d6SFlorian Fainelli case BR_STATE_LEARNING: 1792ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_LEARN_STATE; 1793ff39c2d6SFlorian Fainelli break; 1794ff39c2d6SFlorian Fainelli case BR_STATE_FORWARDING: 1795ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_FWD_STATE; 1796ff39c2d6SFlorian Fainelli break; 1797ff39c2d6SFlorian Fainelli case BR_STATE_BLOCKING: 1798ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_BLOCK_STATE; 1799ff39c2d6SFlorian Fainelli break; 1800ff39c2d6SFlorian Fainelli default: 1801ff39c2d6SFlorian Fainelli dev_err(ds->dev, "invalid STP state: %d\n", state); 1802ff39c2d6SFlorian Fainelli return; 1803ff39c2d6SFlorian Fainelli } 1804ff39c2d6SFlorian Fainelli 1805ff39c2d6SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), ®); 1806ff39c2d6SFlorian Fainelli reg &= ~PORT_CTRL_STP_STATE_MASK; 1807ff39c2d6SFlorian Fainelli reg |= hw_state; 1808ff39c2d6SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg); 1809ff39c2d6SFlorian Fainelli } 18103117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_set_stp_state); 1811ff39c2d6SFlorian Fainelli 18123117455dSFlorian Fainelli void b53_br_fast_age(struct dsa_switch *ds, int port) 1813597698f1SVivien Didelot { 1814597698f1SVivien Didelot struct b53_device *dev = ds->priv; 1815597698f1SVivien Didelot 1816597698f1SVivien Didelot if (b53_fast_age_port(dev, port)) 1817597698f1SVivien Didelot dev_err(ds->dev, "fast ageing failed\n"); 1818597698f1SVivien Didelot } 18193117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_fast_age); 1820597698f1SVivien Didelot 182153568438SFlorian Fainelli int b53_br_egress_floods(struct dsa_switch *ds, int port, 182253568438SFlorian Fainelli bool unicast, bool multicast) 182353568438SFlorian Fainelli { 182453568438SFlorian Fainelli struct b53_device *dev = ds->priv; 182553568438SFlorian Fainelli u16 uc, mc; 182653568438SFlorian Fainelli 182763cc54a6SFlorian Fainelli b53_read16(dev, B53_CTRL_PAGE, B53_UC_FLOOD_MASK, &uc); 182853568438SFlorian Fainelli if (unicast) 182953568438SFlorian Fainelli uc |= BIT(port); 183053568438SFlorian Fainelli else 183153568438SFlorian Fainelli uc &= ~BIT(port); 183263cc54a6SFlorian Fainelli b53_write16(dev, B53_CTRL_PAGE, B53_UC_FLOOD_MASK, uc); 183353568438SFlorian Fainelli 183463cc54a6SFlorian Fainelli b53_read16(dev, B53_CTRL_PAGE, B53_MC_FLOOD_MASK, &mc); 183553568438SFlorian Fainelli if (multicast) 183653568438SFlorian Fainelli mc |= BIT(port); 183753568438SFlorian Fainelli else 183853568438SFlorian Fainelli mc &= ~BIT(port); 183963cc54a6SFlorian Fainelli b53_write16(dev, B53_CTRL_PAGE, B53_MC_FLOOD_MASK, mc); 184063cc54a6SFlorian Fainelli 184163cc54a6SFlorian Fainelli b53_read16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, &mc); 184263cc54a6SFlorian Fainelli if (multicast) 184363cc54a6SFlorian Fainelli mc |= BIT(port); 184463cc54a6SFlorian Fainelli else 184563cc54a6SFlorian Fainelli mc &= ~BIT(port); 184663cc54a6SFlorian Fainelli b53_write16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, mc); 184753568438SFlorian Fainelli 184853568438SFlorian Fainelli return 0; 184953568438SFlorian Fainelli 185053568438SFlorian Fainelli } 185153568438SFlorian Fainelli EXPORT_SYMBOL(b53_br_egress_floods); 185253568438SFlorian Fainelli 1853c7d28c9dSFlorian Fainelli static bool b53_possible_cpu_port(struct dsa_switch *ds, int port) 18547edc58d6SFlorian Fainelli { 18557edc58d6SFlorian Fainelli /* Broadcom switches will accept enabling Broadcom tags on the 18567edc58d6SFlorian Fainelli * following ports: 5, 7 and 8, any other port is not supported 18577edc58d6SFlorian Fainelli */ 18585ed4e3ebSFlorian Fainelli switch (port) { 18595ed4e3ebSFlorian Fainelli case B53_CPU_PORT_25: 18605ed4e3ebSFlorian Fainelli case 7: 18615ed4e3ebSFlorian Fainelli case B53_CPU_PORT: 18627edc58d6SFlorian Fainelli return true; 18637edc58d6SFlorian Fainelli } 18647edc58d6SFlorian Fainelli 18655ed4e3ebSFlorian Fainelli return false; 18665ed4e3ebSFlorian Fainelli } 18675ed4e3ebSFlorian Fainelli 1868c7d28c9dSFlorian Fainelli static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port) 1869c7d28c9dSFlorian Fainelli { 1870c7d28c9dSFlorian Fainelli bool ret = b53_possible_cpu_port(ds, port); 1871c7d28c9dSFlorian Fainelli 1872c7d28c9dSFlorian Fainelli if (!ret) 1873c7d28c9dSFlorian Fainelli dev_warn(ds->dev, "Port %d is not Broadcom tag capable\n", 1874c7d28c9dSFlorian Fainelli port); 1875c7d28c9dSFlorian Fainelli return ret; 1876c7d28c9dSFlorian Fainelli } 1877c7d28c9dSFlorian Fainelli 1878*4d776482SFlorian Fainelli enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port, 1879*4d776482SFlorian Fainelli enum dsa_tag_protocol mprot) 18807b314362SAndrew Lunn { 18817edc58d6SFlorian Fainelli struct b53_device *dev = ds->priv; 18827edc58d6SFlorian Fainelli 188354e98b5dSFlorian Fainelli /* Older models (5325, 5365) support a different tag format that we do 188454e98b5dSFlorian Fainelli * not support in net/dsa/tag_brcm.c yet. 539x and 531x5 require managed 188554e98b5dSFlorian Fainelli * mode to be turned on which means we need to specifically manage ARL 188654e98b5dSFlorian Fainelli * misses on multicast addresses (TBD). 18877edc58d6SFlorian Fainelli */ 188854e98b5dSFlorian Fainelli if (is5325(dev) || is5365(dev) || is539x(dev) || is531x5(dev) || 1889*4d776482SFlorian Fainelli !b53_can_enable_brcm_tags(ds, port)) { 1890*4d776482SFlorian Fainelli dev->tag_protocol = DSA_TAG_PROTO_NONE; 1891*4d776482SFlorian Fainelli goto out; 1892*4d776482SFlorian Fainelli } 189311606039SFlorian Fainelli 189411606039SFlorian Fainelli /* Broadcom BCM58xx chips have a flow accelerator on Port 8 189511606039SFlorian Fainelli * which requires us to use the prepended Broadcom tag type 189611606039SFlorian Fainelli */ 1897*4d776482SFlorian Fainelli if (dev->chip_id == BCM58XX_DEVICE_ID && port == B53_CPU_PORT) { 1898*4d776482SFlorian Fainelli dev->tag_protocol = DSA_TAG_PROTO_BRCM_PREPEND; 1899*4d776482SFlorian Fainelli goto out; 1900*4d776482SFlorian Fainelli } 190111606039SFlorian Fainelli 1902*4d776482SFlorian Fainelli dev->tag_protocol = DSA_TAG_PROTO_BRCM; 1903*4d776482SFlorian Fainelli out: 1904*4d776482SFlorian Fainelli return dev->tag_protocol; 19057b314362SAndrew Lunn } 19069f66816aSFlorian Fainelli EXPORT_SYMBOL(b53_get_tag_protocol); 19077b314362SAndrew Lunn 1908ed3af5fdSFlorian Fainelli int b53_mirror_add(struct dsa_switch *ds, int port, 1909ed3af5fdSFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror, bool ingress) 1910ed3af5fdSFlorian Fainelli { 1911ed3af5fdSFlorian Fainelli struct b53_device *dev = ds->priv; 1912ed3af5fdSFlorian Fainelli u16 reg, loc; 1913ed3af5fdSFlorian Fainelli 1914ed3af5fdSFlorian Fainelli if (ingress) 1915ed3af5fdSFlorian Fainelli loc = B53_IG_MIR_CTL; 1916ed3af5fdSFlorian Fainelli else 1917ed3af5fdSFlorian Fainelli loc = B53_EG_MIR_CTL; 1918ed3af5fdSFlorian Fainelli 1919ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, loc, ®); 1920ed3af5fdSFlorian Fainelli reg |= BIT(port); 1921ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, loc, reg); 1922ed3af5fdSFlorian Fainelli 1923ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®); 1924ed3af5fdSFlorian Fainelli reg &= ~CAP_PORT_MASK; 1925ed3af5fdSFlorian Fainelli reg |= mirror->to_local_port; 1926ed3af5fdSFlorian Fainelli reg |= MIRROR_EN; 1927ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg); 1928ed3af5fdSFlorian Fainelli 1929ed3af5fdSFlorian Fainelli return 0; 1930ed3af5fdSFlorian Fainelli } 1931ed3af5fdSFlorian Fainelli EXPORT_SYMBOL(b53_mirror_add); 1932ed3af5fdSFlorian Fainelli 1933ed3af5fdSFlorian Fainelli void b53_mirror_del(struct dsa_switch *ds, int port, 1934ed3af5fdSFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror) 1935ed3af5fdSFlorian Fainelli { 1936ed3af5fdSFlorian Fainelli struct b53_device *dev = ds->priv; 1937ed3af5fdSFlorian Fainelli bool loc_disable = false, other_loc_disable = false; 1938ed3af5fdSFlorian Fainelli u16 reg, loc; 1939ed3af5fdSFlorian Fainelli 1940ed3af5fdSFlorian Fainelli if (mirror->ingress) 1941ed3af5fdSFlorian Fainelli loc = B53_IG_MIR_CTL; 1942ed3af5fdSFlorian Fainelli else 1943ed3af5fdSFlorian Fainelli loc = B53_EG_MIR_CTL; 1944ed3af5fdSFlorian Fainelli 1945ed3af5fdSFlorian Fainelli /* Update the desired ingress/egress register */ 1946ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, loc, ®); 1947ed3af5fdSFlorian Fainelli reg &= ~BIT(port); 1948ed3af5fdSFlorian Fainelli if (!(reg & MIRROR_MASK)) 1949ed3af5fdSFlorian Fainelli loc_disable = true; 1950ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, loc, reg); 1951ed3af5fdSFlorian Fainelli 1952ed3af5fdSFlorian Fainelli /* Now look at the other one to know if we can disable mirroring 1953ed3af5fdSFlorian Fainelli * entirely 1954ed3af5fdSFlorian Fainelli */ 1955ed3af5fdSFlorian Fainelli if (mirror->ingress) 1956ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_EG_MIR_CTL, ®); 1957ed3af5fdSFlorian Fainelli else 1958ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_IG_MIR_CTL, ®); 1959ed3af5fdSFlorian Fainelli if (!(reg & MIRROR_MASK)) 1960ed3af5fdSFlorian Fainelli other_loc_disable = true; 1961ed3af5fdSFlorian Fainelli 1962ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®); 1963ed3af5fdSFlorian Fainelli /* Both no longer have ports, let's disable mirroring */ 1964ed3af5fdSFlorian Fainelli if (loc_disable && other_loc_disable) { 1965ed3af5fdSFlorian Fainelli reg &= ~MIRROR_EN; 1966ed3af5fdSFlorian Fainelli reg &= ~mirror->to_local_port; 1967ed3af5fdSFlorian Fainelli } 1968ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg); 1969ed3af5fdSFlorian Fainelli } 1970ed3af5fdSFlorian Fainelli EXPORT_SYMBOL(b53_mirror_del); 1971ed3af5fdSFlorian Fainelli 197222256b0aSFlorian Fainelli void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable) 197322256b0aSFlorian Fainelli { 197422256b0aSFlorian Fainelli struct b53_device *dev = ds->priv; 197522256b0aSFlorian Fainelli u16 reg; 197622256b0aSFlorian Fainelli 197722256b0aSFlorian Fainelli b53_read16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, ®); 197822256b0aSFlorian Fainelli if (enable) 197922256b0aSFlorian Fainelli reg |= BIT(port); 198022256b0aSFlorian Fainelli else 198122256b0aSFlorian Fainelli reg &= ~BIT(port); 198222256b0aSFlorian Fainelli b53_write16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, reg); 198322256b0aSFlorian Fainelli } 198422256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_eee_enable_set); 198522256b0aSFlorian Fainelli 198622256b0aSFlorian Fainelli 198722256b0aSFlorian Fainelli /* Returns 0 if EEE was not enabled, or 1 otherwise 198822256b0aSFlorian Fainelli */ 198922256b0aSFlorian Fainelli int b53_eee_init(struct dsa_switch *ds, int port, struct phy_device *phy) 199022256b0aSFlorian Fainelli { 199122256b0aSFlorian Fainelli int ret; 199222256b0aSFlorian Fainelli 199322256b0aSFlorian Fainelli ret = phy_init_eee(phy, 0); 199422256b0aSFlorian Fainelli if (ret) 199522256b0aSFlorian Fainelli return 0; 199622256b0aSFlorian Fainelli 199722256b0aSFlorian Fainelli b53_eee_enable_set(ds, port, true); 199822256b0aSFlorian Fainelli 199922256b0aSFlorian Fainelli return 1; 200022256b0aSFlorian Fainelli } 200122256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_eee_init); 200222256b0aSFlorian Fainelli 200322256b0aSFlorian Fainelli int b53_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e) 200422256b0aSFlorian Fainelli { 200522256b0aSFlorian Fainelli struct b53_device *dev = ds->priv; 200622256b0aSFlorian Fainelli struct ethtool_eee *p = &dev->ports[port].eee; 200722256b0aSFlorian Fainelli u16 reg; 200822256b0aSFlorian Fainelli 200922256b0aSFlorian Fainelli if (is5325(dev) || is5365(dev)) 201022256b0aSFlorian Fainelli return -EOPNOTSUPP; 201122256b0aSFlorian Fainelli 201222256b0aSFlorian Fainelli b53_read16(dev, B53_EEE_PAGE, B53_EEE_LPI_INDICATE, ®); 201322256b0aSFlorian Fainelli e->eee_enabled = p->eee_enabled; 201422256b0aSFlorian Fainelli e->eee_active = !!(reg & BIT(port)); 201522256b0aSFlorian Fainelli 201622256b0aSFlorian Fainelli return 0; 201722256b0aSFlorian Fainelli } 201822256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_get_mac_eee); 201922256b0aSFlorian Fainelli 202022256b0aSFlorian Fainelli int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e) 202122256b0aSFlorian Fainelli { 202222256b0aSFlorian Fainelli struct b53_device *dev = ds->priv; 202322256b0aSFlorian Fainelli struct ethtool_eee *p = &dev->ports[port].eee; 202422256b0aSFlorian Fainelli 202522256b0aSFlorian Fainelli if (is5325(dev) || is5365(dev)) 202622256b0aSFlorian Fainelli return -EOPNOTSUPP; 202722256b0aSFlorian Fainelli 202822256b0aSFlorian Fainelli p->eee_enabled = e->eee_enabled; 202922256b0aSFlorian Fainelli b53_eee_enable_set(ds, port, e->eee_enabled); 203022256b0aSFlorian Fainelli 203122256b0aSFlorian Fainelli return 0; 203222256b0aSFlorian Fainelli } 203322256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_set_mac_eee); 203422256b0aSFlorian Fainelli 2035a82f67afSFlorian Fainelli static const struct dsa_switch_ops b53_switch_ops = { 20367b314362SAndrew Lunn .get_tag_protocol = b53_get_tag_protocol, 2037967dd82fSFlorian Fainelli .setup = b53_setup, 2038967dd82fSFlorian Fainelli .get_strings = b53_get_strings, 2039967dd82fSFlorian Fainelli .get_ethtool_stats = b53_get_ethtool_stats, 2040967dd82fSFlorian Fainelli .get_sset_count = b53_get_sset_count, 2041c7d28c9dSFlorian Fainelli .get_ethtool_phy_stats = b53_get_ethtool_phy_stats, 2042967dd82fSFlorian Fainelli .phy_read = b53_phy_read16, 2043967dd82fSFlorian Fainelli .phy_write = b53_phy_write16, 2044967dd82fSFlorian Fainelli .adjust_link = b53_adjust_link, 2045a8e8b985SFlorian Fainelli .phylink_validate = b53_phylink_validate, 2046a8e8b985SFlorian Fainelli .phylink_mac_link_state = b53_phylink_mac_link_state, 2047a8e8b985SFlorian Fainelli .phylink_mac_config = b53_phylink_mac_config, 2048a8e8b985SFlorian Fainelli .phylink_mac_an_restart = b53_phylink_mac_an_restart, 2049a8e8b985SFlorian Fainelli .phylink_mac_link_down = b53_phylink_mac_link_down, 2050a8e8b985SFlorian Fainelli .phylink_mac_link_up = b53_phylink_mac_link_up, 2051967dd82fSFlorian Fainelli .port_enable = b53_enable_port, 2052967dd82fSFlorian Fainelli .port_disable = b53_disable_port, 2053f43a2dbeSFlorian Fainelli .get_mac_eee = b53_get_mac_eee, 2054f43a2dbeSFlorian Fainelli .set_mac_eee = b53_set_mac_eee, 2055ff39c2d6SFlorian Fainelli .port_bridge_join = b53_br_join, 2056ff39c2d6SFlorian Fainelli .port_bridge_leave = b53_br_leave, 2057ff39c2d6SFlorian Fainelli .port_stp_state_set = b53_br_set_stp_state, 2058597698f1SVivien Didelot .port_fast_age = b53_br_fast_age, 205953568438SFlorian Fainelli .port_egress_floods = b53_br_egress_floods, 2060a2482d2cSFlorian Fainelli .port_vlan_filtering = b53_vlan_filtering, 2061a2482d2cSFlorian Fainelli .port_vlan_prepare = b53_vlan_prepare, 2062a2482d2cSFlorian Fainelli .port_vlan_add = b53_vlan_add, 2063a2482d2cSFlorian Fainelli .port_vlan_del = b53_vlan_del, 20641da6df85SFlorian Fainelli .port_fdb_dump = b53_fdb_dump, 20651da6df85SFlorian Fainelli .port_fdb_add = b53_fdb_add, 20661da6df85SFlorian Fainelli .port_fdb_del = b53_fdb_del, 2067ed3af5fdSFlorian Fainelli .port_mirror_add = b53_mirror_add, 2068ed3af5fdSFlorian Fainelli .port_mirror_del = b53_mirror_del, 20695d65b64aSFlorian Fainelli .port_mdb_prepare = b53_mdb_prepare, 20705d65b64aSFlorian Fainelli .port_mdb_add = b53_mdb_add, 20715d65b64aSFlorian Fainelli .port_mdb_del = b53_mdb_del, 2072967dd82fSFlorian Fainelli }; 2073967dd82fSFlorian Fainelli 2074967dd82fSFlorian Fainelli struct b53_chip_data { 2075967dd82fSFlorian Fainelli u32 chip_id; 2076967dd82fSFlorian Fainelli const char *dev_name; 2077967dd82fSFlorian Fainelli u16 vlans; 2078967dd82fSFlorian Fainelli u16 enabled_ports; 2079967dd82fSFlorian Fainelli u8 cpu_port; 2080967dd82fSFlorian Fainelli u8 vta_regs[3]; 20811da6df85SFlorian Fainelli u8 arl_entries; 2082967dd82fSFlorian Fainelli u8 duplex_reg; 2083967dd82fSFlorian Fainelli u8 jumbo_pm_reg; 2084967dd82fSFlorian Fainelli u8 jumbo_size_reg; 2085967dd82fSFlorian Fainelli }; 2086967dd82fSFlorian Fainelli 2087967dd82fSFlorian Fainelli #define B53_VTA_REGS \ 2088967dd82fSFlorian Fainelli { B53_VT_ACCESS, B53_VT_INDEX, B53_VT_ENTRY } 2089967dd82fSFlorian Fainelli #define B53_VTA_REGS_9798 \ 2090967dd82fSFlorian Fainelli { B53_VT_ACCESS_9798, B53_VT_INDEX_9798, B53_VT_ENTRY_9798 } 2091967dd82fSFlorian Fainelli #define B53_VTA_REGS_63XX \ 2092967dd82fSFlorian Fainelli { B53_VT_ACCESS_63XX, B53_VT_INDEX_63XX, B53_VT_ENTRY_63XX } 2093967dd82fSFlorian Fainelli 2094967dd82fSFlorian Fainelli static const struct b53_chip_data b53_switch_chips[] = { 2095967dd82fSFlorian Fainelli { 2096967dd82fSFlorian Fainelli .chip_id = BCM5325_DEVICE_ID, 2097967dd82fSFlorian Fainelli .dev_name = "BCM5325", 2098967dd82fSFlorian Fainelli .vlans = 16, 2099967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 21001da6df85SFlorian Fainelli .arl_entries = 2, 2101967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, 2102967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_FE, 2103967dd82fSFlorian Fainelli }, 2104967dd82fSFlorian Fainelli { 2105967dd82fSFlorian Fainelli .chip_id = BCM5365_DEVICE_ID, 2106967dd82fSFlorian Fainelli .dev_name = "BCM5365", 2107967dd82fSFlorian Fainelli .vlans = 256, 2108967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 21091da6df85SFlorian Fainelli .arl_entries = 2, 2110967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, 2111967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_FE, 2112967dd82fSFlorian Fainelli }, 2113967dd82fSFlorian Fainelli { 2114a95691bcSDamien Thébault .chip_id = BCM5389_DEVICE_ID, 2115a95691bcSDamien Thébault .dev_name = "BCM5389", 2116a95691bcSDamien Thébault .vlans = 4096, 2117a95691bcSDamien Thébault .enabled_ports = 0x1f, 2118a95691bcSDamien Thébault .arl_entries = 4, 2119a95691bcSDamien Thébault .cpu_port = B53_CPU_PORT, 2120a95691bcSDamien Thébault .vta_regs = B53_VTA_REGS, 2121a95691bcSDamien Thébault .duplex_reg = B53_DUPLEX_STAT_GE, 2122a95691bcSDamien Thébault .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2123a95691bcSDamien Thébault .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2124a95691bcSDamien Thébault }, 2125a95691bcSDamien Thébault { 2126967dd82fSFlorian Fainelli .chip_id = BCM5395_DEVICE_ID, 2127967dd82fSFlorian Fainelli .dev_name = "BCM5395", 2128967dd82fSFlorian Fainelli .vlans = 4096, 2129967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 21301da6df85SFlorian Fainelli .arl_entries = 4, 2131967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2132967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2133967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2134967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2135967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2136967dd82fSFlorian Fainelli }, 2137967dd82fSFlorian Fainelli { 2138967dd82fSFlorian Fainelli .chip_id = BCM5397_DEVICE_ID, 2139967dd82fSFlorian Fainelli .dev_name = "BCM5397", 2140967dd82fSFlorian Fainelli .vlans = 4096, 2141967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 21421da6df85SFlorian Fainelli .arl_entries = 4, 2143967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2144967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_9798, 2145967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2146967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2147967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2148967dd82fSFlorian Fainelli }, 2149967dd82fSFlorian Fainelli { 2150967dd82fSFlorian Fainelli .chip_id = BCM5398_DEVICE_ID, 2151967dd82fSFlorian Fainelli .dev_name = "BCM5398", 2152967dd82fSFlorian Fainelli .vlans = 4096, 2153967dd82fSFlorian Fainelli .enabled_ports = 0x7f, 21541da6df85SFlorian Fainelli .arl_entries = 4, 2155967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2156967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_9798, 2157967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2158967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2159967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2160967dd82fSFlorian Fainelli }, 2161967dd82fSFlorian Fainelli { 2162967dd82fSFlorian Fainelli .chip_id = BCM53115_DEVICE_ID, 2163967dd82fSFlorian Fainelli .dev_name = "BCM53115", 2164967dd82fSFlorian Fainelli .vlans = 4096, 2165967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 21661da6df85SFlorian Fainelli .arl_entries = 4, 2167967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2168967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2169967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2170967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2171967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2172967dd82fSFlorian Fainelli }, 2173967dd82fSFlorian Fainelli { 2174967dd82fSFlorian Fainelli .chip_id = BCM53125_DEVICE_ID, 2175967dd82fSFlorian Fainelli .dev_name = "BCM53125", 2176967dd82fSFlorian Fainelli .vlans = 4096, 2177967dd82fSFlorian Fainelli .enabled_ports = 0xff, 2178be35e8c5SFlorian Fainelli .arl_entries = 4, 2179967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2180967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2181967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2182967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2183967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2184967dd82fSFlorian Fainelli }, 2185967dd82fSFlorian Fainelli { 2186967dd82fSFlorian Fainelli .chip_id = BCM53128_DEVICE_ID, 2187967dd82fSFlorian Fainelli .dev_name = "BCM53128", 2188967dd82fSFlorian Fainelli .vlans = 4096, 2189967dd82fSFlorian Fainelli .enabled_ports = 0x1ff, 21901da6df85SFlorian Fainelli .arl_entries = 4, 2191967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2192967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2193967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2194967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2195967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2196967dd82fSFlorian Fainelli }, 2197967dd82fSFlorian Fainelli { 2198967dd82fSFlorian Fainelli .chip_id = BCM63XX_DEVICE_ID, 2199967dd82fSFlorian Fainelli .dev_name = "BCM63xx", 2200967dd82fSFlorian Fainelli .vlans = 4096, 2201967dd82fSFlorian Fainelli .enabled_ports = 0, /* pdata must provide them */ 22021da6df85SFlorian Fainelli .arl_entries = 4, 2203967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2204967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_63XX, 2205967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_63XX, 2206967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK_63XX, 2207967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE_63XX, 2208967dd82fSFlorian Fainelli }, 2209967dd82fSFlorian Fainelli { 2210967dd82fSFlorian Fainelli .chip_id = BCM53010_DEVICE_ID, 2211967dd82fSFlorian Fainelli .dev_name = "BCM53010", 2212967dd82fSFlorian Fainelli .vlans = 4096, 2213967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 22141da6df85SFlorian Fainelli .arl_entries = 4, 2215967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2216967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2217967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2218967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2219967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2220967dd82fSFlorian Fainelli }, 2221967dd82fSFlorian Fainelli { 2222967dd82fSFlorian Fainelli .chip_id = BCM53011_DEVICE_ID, 2223967dd82fSFlorian Fainelli .dev_name = "BCM53011", 2224967dd82fSFlorian Fainelli .vlans = 4096, 2225967dd82fSFlorian Fainelli .enabled_ports = 0x1bf, 22261da6df85SFlorian Fainelli .arl_entries = 4, 2227967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2228967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2229967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2230967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2231967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2232967dd82fSFlorian Fainelli }, 2233967dd82fSFlorian Fainelli { 2234967dd82fSFlorian Fainelli .chip_id = BCM53012_DEVICE_ID, 2235967dd82fSFlorian Fainelli .dev_name = "BCM53012", 2236967dd82fSFlorian Fainelli .vlans = 4096, 2237967dd82fSFlorian Fainelli .enabled_ports = 0x1bf, 22381da6df85SFlorian Fainelli .arl_entries = 4, 2239967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2240967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2241967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2242967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2243967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2244967dd82fSFlorian Fainelli }, 2245967dd82fSFlorian Fainelli { 2246967dd82fSFlorian Fainelli .chip_id = BCM53018_DEVICE_ID, 2247967dd82fSFlorian Fainelli .dev_name = "BCM53018", 2248967dd82fSFlorian Fainelli .vlans = 4096, 2249967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 22501da6df85SFlorian Fainelli .arl_entries = 4, 2251967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2252967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2253967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2254967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2255967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2256967dd82fSFlorian Fainelli }, 2257967dd82fSFlorian Fainelli { 2258967dd82fSFlorian Fainelli .chip_id = BCM53019_DEVICE_ID, 2259967dd82fSFlorian Fainelli .dev_name = "BCM53019", 2260967dd82fSFlorian Fainelli .vlans = 4096, 2261967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 22621da6df85SFlorian Fainelli .arl_entries = 4, 2263967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2264967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2265967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2266967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2267967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2268967dd82fSFlorian Fainelli }, 2269991a36bbSFlorian Fainelli { 2270991a36bbSFlorian Fainelli .chip_id = BCM58XX_DEVICE_ID, 2271991a36bbSFlorian Fainelli .dev_name = "BCM585xx/586xx/88312", 2272991a36bbSFlorian Fainelli .vlans = 4096, 2273991a36bbSFlorian Fainelli .enabled_ports = 0x1ff, 2274991a36bbSFlorian Fainelli .arl_entries = 4, 2275bfcda65cSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2276991a36bbSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2277991a36bbSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2278991a36bbSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2279991a36bbSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2280991a36bbSFlorian Fainelli }, 2281130401d9SFlorian Fainelli { 22825040cc99SArun Parameswaran .chip_id = BCM583XX_DEVICE_ID, 22835040cc99SArun Parameswaran .dev_name = "BCM583xx/11360", 22845040cc99SArun Parameswaran .vlans = 4096, 22855040cc99SArun Parameswaran .enabled_ports = 0x103, 22865040cc99SArun Parameswaran .arl_entries = 4, 22875040cc99SArun Parameswaran .cpu_port = B53_CPU_PORT, 22885040cc99SArun Parameswaran .vta_regs = B53_VTA_REGS, 22895040cc99SArun Parameswaran .duplex_reg = B53_DUPLEX_STAT_GE, 22905040cc99SArun Parameswaran .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 22915040cc99SArun Parameswaran .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 22925040cc99SArun Parameswaran }, 22935040cc99SArun Parameswaran { 2294130401d9SFlorian Fainelli .chip_id = BCM7445_DEVICE_ID, 2295130401d9SFlorian Fainelli .dev_name = "BCM7445", 2296130401d9SFlorian Fainelli .vlans = 4096, 2297130401d9SFlorian Fainelli .enabled_ports = 0x1ff, 2298130401d9SFlorian Fainelli .arl_entries = 4, 2299130401d9SFlorian Fainelli .cpu_port = B53_CPU_PORT, 2300130401d9SFlorian Fainelli .vta_regs = B53_VTA_REGS, 2301130401d9SFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2302130401d9SFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2303130401d9SFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2304130401d9SFlorian Fainelli }, 23050fe99338SFlorian Fainelli { 23060fe99338SFlorian Fainelli .chip_id = BCM7278_DEVICE_ID, 23070fe99338SFlorian Fainelli .dev_name = "BCM7278", 23080fe99338SFlorian Fainelli .vlans = 4096, 23090fe99338SFlorian Fainelli .enabled_ports = 0x1ff, 23100fe99338SFlorian Fainelli .arl_entries= 4, 23110fe99338SFlorian Fainelli .cpu_port = B53_CPU_PORT, 23120fe99338SFlorian Fainelli .vta_regs = B53_VTA_REGS, 23130fe99338SFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 23140fe99338SFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 23150fe99338SFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 23160fe99338SFlorian Fainelli }, 2317967dd82fSFlorian Fainelli }; 2318967dd82fSFlorian Fainelli 2319967dd82fSFlorian Fainelli static int b53_switch_init(struct b53_device *dev) 2320967dd82fSFlorian Fainelli { 2321967dd82fSFlorian Fainelli unsigned int i; 2322967dd82fSFlorian Fainelli int ret; 2323967dd82fSFlorian Fainelli 2324967dd82fSFlorian Fainelli for (i = 0; i < ARRAY_SIZE(b53_switch_chips); i++) { 2325967dd82fSFlorian Fainelli const struct b53_chip_data *chip = &b53_switch_chips[i]; 2326967dd82fSFlorian Fainelli 2327967dd82fSFlorian Fainelli if (chip->chip_id == dev->chip_id) { 2328967dd82fSFlorian Fainelli if (!dev->enabled_ports) 2329967dd82fSFlorian Fainelli dev->enabled_ports = chip->enabled_ports; 2330967dd82fSFlorian Fainelli dev->name = chip->dev_name; 2331967dd82fSFlorian Fainelli dev->duplex_reg = chip->duplex_reg; 2332967dd82fSFlorian Fainelli dev->vta_regs[0] = chip->vta_regs[0]; 2333967dd82fSFlorian Fainelli dev->vta_regs[1] = chip->vta_regs[1]; 2334967dd82fSFlorian Fainelli dev->vta_regs[2] = chip->vta_regs[2]; 2335967dd82fSFlorian Fainelli dev->jumbo_pm_reg = chip->jumbo_pm_reg; 2336967dd82fSFlorian Fainelli dev->cpu_port = chip->cpu_port; 2337967dd82fSFlorian Fainelli dev->num_vlans = chip->vlans; 23381da6df85SFlorian Fainelli dev->num_arl_entries = chip->arl_entries; 2339967dd82fSFlorian Fainelli break; 2340967dd82fSFlorian Fainelli } 2341967dd82fSFlorian Fainelli } 2342967dd82fSFlorian Fainelli 2343967dd82fSFlorian Fainelli /* check which BCM5325x version we have */ 2344967dd82fSFlorian Fainelli if (is5325(dev)) { 2345967dd82fSFlorian Fainelli u8 vc4; 2346967dd82fSFlorian Fainelli 2347967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4); 2348967dd82fSFlorian Fainelli 2349967dd82fSFlorian Fainelli /* check reserved bits */ 2350967dd82fSFlorian Fainelli switch (vc4 & 3) { 2351967dd82fSFlorian Fainelli case 1: 2352967dd82fSFlorian Fainelli /* BCM5325E */ 2353967dd82fSFlorian Fainelli break; 2354967dd82fSFlorian Fainelli case 3: 2355967dd82fSFlorian Fainelli /* BCM5325F - do not use port 4 */ 2356967dd82fSFlorian Fainelli dev->enabled_ports &= ~BIT(4); 2357967dd82fSFlorian Fainelli break; 2358967dd82fSFlorian Fainelli default: 2359967dd82fSFlorian Fainelli /* On the BCM47XX SoCs this is the supported internal switch.*/ 2360967dd82fSFlorian Fainelli #ifndef CONFIG_BCM47XX 2361967dd82fSFlorian Fainelli /* BCM5325M */ 2362967dd82fSFlorian Fainelli return -EINVAL; 2363967dd82fSFlorian Fainelli #else 2364967dd82fSFlorian Fainelli break; 2365967dd82fSFlorian Fainelli #endif 2366967dd82fSFlorian Fainelli } 2367967dd82fSFlorian Fainelli } else if (dev->chip_id == BCM53115_DEVICE_ID) { 2368967dd82fSFlorian Fainelli u64 strap_value; 2369967dd82fSFlorian Fainelli 2370967dd82fSFlorian Fainelli b53_read48(dev, B53_STAT_PAGE, B53_STRAP_VALUE, &strap_value); 2371967dd82fSFlorian Fainelli /* use second IMP port if GMII is enabled */ 2372967dd82fSFlorian Fainelli if (strap_value & SV_GMII_CTRL_115) 2373967dd82fSFlorian Fainelli dev->cpu_port = 5; 2374967dd82fSFlorian Fainelli } 2375967dd82fSFlorian Fainelli 2376967dd82fSFlorian Fainelli /* cpu port is always last */ 2377967dd82fSFlorian Fainelli dev->num_ports = dev->cpu_port + 1; 2378967dd82fSFlorian Fainelli dev->enabled_ports |= BIT(dev->cpu_port); 2379967dd82fSFlorian Fainelli 2380c7d28c9dSFlorian Fainelli /* Include non standard CPU port built-in PHYs to be probed */ 2381c7d28c9dSFlorian Fainelli if (is539x(dev) || is531x5(dev)) { 2382c7d28c9dSFlorian Fainelli for (i = 0; i < dev->num_ports; i++) { 2383c7d28c9dSFlorian Fainelli if (!(dev->ds->phys_mii_mask & BIT(i)) && 2384c7d28c9dSFlorian Fainelli !b53_possible_cpu_port(dev->ds, i)) 2385c7d28c9dSFlorian Fainelli dev->ds->phys_mii_mask |= BIT(i); 2386c7d28c9dSFlorian Fainelli } 2387c7d28c9dSFlorian Fainelli } 2388c7d28c9dSFlorian Fainelli 2389a86854d0SKees Cook dev->ports = devm_kcalloc(dev->dev, 2390a86854d0SKees Cook dev->num_ports, sizeof(struct b53_port), 2391967dd82fSFlorian Fainelli GFP_KERNEL); 2392967dd82fSFlorian Fainelli if (!dev->ports) 2393967dd82fSFlorian Fainelli return -ENOMEM; 2394967dd82fSFlorian Fainelli 2395a86854d0SKees Cook dev->vlans = devm_kcalloc(dev->dev, 2396a86854d0SKees Cook dev->num_vlans, sizeof(struct b53_vlan), 2397a2482d2cSFlorian Fainelli GFP_KERNEL); 2398a2482d2cSFlorian Fainelli if (!dev->vlans) 2399a2482d2cSFlorian Fainelli return -ENOMEM; 2400a2482d2cSFlorian Fainelli 2401967dd82fSFlorian Fainelli dev->reset_gpio = b53_switch_get_reset_gpio(dev); 2402967dd82fSFlorian Fainelli if (dev->reset_gpio >= 0) { 2403967dd82fSFlorian Fainelli ret = devm_gpio_request_one(dev->dev, dev->reset_gpio, 2404967dd82fSFlorian Fainelli GPIOF_OUT_INIT_HIGH, "robo_reset"); 2405967dd82fSFlorian Fainelli if (ret) 2406967dd82fSFlorian Fainelli return ret; 2407967dd82fSFlorian Fainelli } 2408967dd82fSFlorian Fainelli 2409967dd82fSFlorian Fainelli return 0; 2410967dd82fSFlorian Fainelli } 2411967dd82fSFlorian Fainelli 24120dff88d3SJulia Lawall struct b53_device *b53_switch_alloc(struct device *base, 24130dff88d3SJulia Lawall const struct b53_io_ops *ops, 2414967dd82fSFlorian Fainelli void *priv) 2415967dd82fSFlorian Fainelli { 2416967dd82fSFlorian Fainelli struct dsa_switch *ds; 2417967dd82fSFlorian Fainelli struct b53_device *dev; 2418967dd82fSFlorian Fainelli 24197e99e347SVivien Didelot ds = devm_kzalloc(base, sizeof(*ds), GFP_KERNEL); 2420967dd82fSFlorian Fainelli if (!ds) 2421967dd82fSFlorian Fainelli return NULL; 2422967dd82fSFlorian Fainelli 24237e99e347SVivien Didelot ds->dev = base; 24247e99e347SVivien Didelot ds->num_ports = DSA_MAX_PORTS; 24257e99e347SVivien Didelot 2426a0c02161SVivien Didelot dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL); 2427a0c02161SVivien Didelot if (!dev) 2428a0c02161SVivien Didelot return NULL; 2429967dd82fSFlorian Fainelli 2430967dd82fSFlorian Fainelli ds->priv = dev; 2431967dd82fSFlorian Fainelli dev->dev = base; 2432967dd82fSFlorian Fainelli 2433967dd82fSFlorian Fainelli dev->ds = ds; 2434967dd82fSFlorian Fainelli dev->priv = priv; 2435967dd82fSFlorian Fainelli dev->ops = ops; 2436485ebd61SFlorian Fainelli ds->ops = &b53_switch_ops; 2437967dd82fSFlorian Fainelli mutex_init(&dev->reg_mutex); 2438967dd82fSFlorian Fainelli mutex_init(&dev->stats_mutex); 2439967dd82fSFlorian Fainelli 2440967dd82fSFlorian Fainelli return dev; 2441967dd82fSFlorian Fainelli } 2442967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_alloc); 2443967dd82fSFlorian Fainelli 2444967dd82fSFlorian Fainelli int b53_switch_detect(struct b53_device *dev) 2445967dd82fSFlorian Fainelli { 2446967dd82fSFlorian Fainelli u32 id32; 2447967dd82fSFlorian Fainelli u16 tmp; 2448967dd82fSFlorian Fainelli u8 id8; 2449967dd82fSFlorian Fainelli int ret; 2450967dd82fSFlorian Fainelli 2451967dd82fSFlorian Fainelli ret = b53_read8(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id8); 2452967dd82fSFlorian Fainelli if (ret) 2453967dd82fSFlorian Fainelli return ret; 2454967dd82fSFlorian Fainelli 2455967dd82fSFlorian Fainelli switch (id8) { 2456967dd82fSFlorian Fainelli case 0: 2457967dd82fSFlorian Fainelli /* BCM5325 and BCM5365 do not have this register so reads 2458967dd82fSFlorian Fainelli * return 0. But the read operation did succeed, so assume this 2459967dd82fSFlorian Fainelli * is one of them. 2460967dd82fSFlorian Fainelli * 2461967dd82fSFlorian Fainelli * Next check if we can write to the 5325's VTA register; for 2462967dd82fSFlorian Fainelli * 5365 it is read only. 2463967dd82fSFlorian Fainelli */ 2464967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, 0xf); 2465967dd82fSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, &tmp); 2466967dd82fSFlorian Fainelli 2467967dd82fSFlorian Fainelli if (tmp == 0xf) 2468967dd82fSFlorian Fainelli dev->chip_id = BCM5325_DEVICE_ID; 2469967dd82fSFlorian Fainelli else 2470967dd82fSFlorian Fainelli dev->chip_id = BCM5365_DEVICE_ID; 2471967dd82fSFlorian Fainelli break; 2472a95691bcSDamien Thébault case BCM5389_DEVICE_ID: 2473967dd82fSFlorian Fainelli case BCM5395_DEVICE_ID: 2474967dd82fSFlorian Fainelli case BCM5397_DEVICE_ID: 2475967dd82fSFlorian Fainelli case BCM5398_DEVICE_ID: 2476967dd82fSFlorian Fainelli dev->chip_id = id8; 2477967dd82fSFlorian Fainelli break; 2478967dd82fSFlorian Fainelli default: 2479967dd82fSFlorian Fainelli ret = b53_read32(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id32); 2480967dd82fSFlorian Fainelli if (ret) 2481967dd82fSFlorian Fainelli return ret; 2482967dd82fSFlorian Fainelli 2483967dd82fSFlorian Fainelli switch (id32) { 2484967dd82fSFlorian Fainelli case BCM53115_DEVICE_ID: 2485967dd82fSFlorian Fainelli case BCM53125_DEVICE_ID: 2486967dd82fSFlorian Fainelli case BCM53128_DEVICE_ID: 2487967dd82fSFlorian Fainelli case BCM53010_DEVICE_ID: 2488967dd82fSFlorian Fainelli case BCM53011_DEVICE_ID: 2489967dd82fSFlorian Fainelli case BCM53012_DEVICE_ID: 2490967dd82fSFlorian Fainelli case BCM53018_DEVICE_ID: 2491967dd82fSFlorian Fainelli case BCM53019_DEVICE_ID: 2492967dd82fSFlorian Fainelli dev->chip_id = id32; 2493967dd82fSFlorian Fainelli break; 2494967dd82fSFlorian Fainelli default: 2495967dd82fSFlorian Fainelli pr_err("unsupported switch detected (BCM53%02x/BCM%x)\n", 2496967dd82fSFlorian Fainelli id8, id32); 2497967dd82fSFlorian Fainelli return -ENODEV; 2498967dd82fSFlorian Fainelli } 2499967dd82fSFlorian Fainelli } 2500967dd82fSFlorian Fainelli 2501967dd82fSFlorian Fainelli if (dev->chip_id == BCM5325_DEVICE_ID) 2502967dd82fSFlorian Fainelli return b53_read8(dev, B53_STAT_PAGE, B53_REV_ID_25, 2503967dd82fSFlorian Fainelli &dev->core_rev); 2504967dd82fSFlorian Fainelli else 2505967dd82fSFlorian Fainelli return b53_read8(dev, B53_MGMT_PAGE, B53_REV_ID, 2506967dd82fSFlorian Fainelli &dev->core_rev); 2507967dd82fSFlorian Fainelli } 2508967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_detect); 2509967dd82fSFlorian Fainelli 2510967dd82fSFlorian Fainelli int b53_switch_register(struct b53_device *dev) 2511967dd82fSFlorian Fainelli { 2512967dd82fSFlorian Fainelli int ret; 2513967dd82fSFlorian Fainelli 2514967dd82fSFlorian Fainelli if (dev->pdata) { 2515967dd82fSFlorian Fainelli dev->chip_id = dev->pdata->chip_id; 2516967dd82fSFlorian Fainelli dev->enabled_ports = dev->pdata->enabled_ports; 2517967dd82fSFlorian Fainelli } 2518967dd82fSFlorian Fainelli 2519967dd82fSFlorian Fainelli if (!dev->chip_id && b53_switch_detect(dev)) 2520967dd82fSFlorian Fainelli return -EINVAL; 2521967dd82fSFlorian Fainelli 2522967dd82fSFlorian Fainelli ret = b53_switch_init(dev); 2523967dd82fSFlorian Fainelli if (ret) 2524967dd82fSFlorian Fainelli return ret; 2525967dd82fSFlorian Fainelli 2526967dd82fSFlorian Fainelli pr_info("found switch: %s, rev %i\n", dev->name, dev->core_rev); 2527967dd82fSFlorian Fainelli 252823c9ee49SVivien Didelot return dsa_register_switch(dev->ds); 2529967dd82fSFlorian Fainelli } 2530967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_register); 2531967dd82fSFlorian Fainelli 2532967dd82fSFlorian Fainelli MODULE_AUTHOR("Jonas Gorski <jogo@openwrt.org>"); 2533967dd82fSFlorian Fainelli MODULE_DESCRIPTION("B53 switch library"); 2534967dd82fSFlorian Fainelli MODULE_LICENSE("Dual BSD/GPL"); 2535