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); 345a424f0deSFlorian Fainelli } 346967dd82fSFlorian Fainelli 347*dad8d7c6SFlorian Fainelli static void b53_enable_vlan(struct b53_device *dev, bool enable, 348*dad8d7c6SFlorian Fainelli bool enable_filtering) 349967dd82fSFlorian Fainelli { 350967dd82fSFlorian Fainelli u8 mgmt, vc0, vc1, vc4 = 0, vc5; 351967dd82fSFlorian Fainelli 352967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); 353967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL0, &vc0); 354967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL1, &vc1); 355967dd82fSFlorian Fainelli 356967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) { 357967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4); 358967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_25, &vc5); 359967dd82fSFlorian Fainelli } else if (is63xx(dev)) { 360967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_63XX, &vc4); 361967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_63XX, &vc5); 362967dd82fSFlorian Fainelli } else { 363967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, &vc4); 364967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, &vc5); 365967dd82fSFlorian Fainelli } 366967dd82fSFlorian Fainelli 367967dd82fSFlorian Fainelli mgmt &= ~SM_SW_FWD_MODE; 368967dd82fSFlorian Fainelli 369967dd82fSFlorian Fainelli if (enable) { 370967dd82fSFlorian Fainelli vc0 |= VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID; 371967dd82fSFlorian Fainelli vc1 |= VC1_RX_MCST_UNTAG_EN | VC1_RX_MCST_FWD_EN; 372967dd82fSFlorian Fainelli vc4 &= ~VC4_ING_VID_CHECK_MASK; 373*dad8d7c6SFlorian Fainelli if (enable_filtering) { 374967dd82fSFlorian Fainelli vc4 |= VC4_ING_VID_VIO_DROP << VC4_ING_VID_CHECK_S; 375967dd82fSFlorian Fainelli vc5 |= VC5_DROP_VTABLE_MISS; 376*dad8d7c6SFlorian Fainelli } else { 377*dad8d7c6SFlorian Fainelli vc4 |= VC4_ING_VID_VIO_FWD << VC4_ING_VID_CHECK_S; 378*dad8d7c6SFlorian Fainelli vc5 &= ~VC5_DROP_VTABLE_MISS; 379*dad8d7c6SFlorian Fainelli } 380967dd82fSFlorian Fainelli 381967dd82fSFlorian Fainelli if (is5325(dev)) 382967dd82fSFlorian Fainelli vc0 &= ~VC0_RESERVED_1; 383967dd82fSFlorian Fainelli 384967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 385967dd82fSFlorian Fainelli vc1 |= VC1_RX_MCST_TAG_EN; 386967dd82fSFlorian Fainelli 387967dd82fSFlorian Fainelli } else { 388967dd82fSFlorian Fainelli vc0 &= ~(VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID); 389967dd82fSFlorian Fainelli vc1 &= ~(VC1_RX_MCST_UNTAG_EN | VC1_RX_MCST_FWD_EN); 390967dd82fSFlorian Fainelli vc4 &= ~VC4_ING_VID_CHECK_MASK; 391967dd82fSFlorian Fainelli vc5 &= ~VC5_DROP_VTABLE_MISS; 392967dd82fSFlorian Fainelli 393967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 394967dd82fSFlorian Fainelli vc4 |= VC4_ING_VID_VIO_FWD << VC4_ING_VID_CHECK_S; 395967dd82fSFlorian Fainelli else 396967dd82fSFlorian Fainelli vc4 |= VC4_ING_VID_VIO_TO_IMP << VC4_ING_VID_CHECK_S; 397967dd82fSFlorian Fainelli 398967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 399967dd82fSFlorian Fainelli vc1 &= ~VC1_RX_MCST_TAG_EN; 400a2482d2cSFlorian Fainelli } 401967dd82fSFlorian Fainelli 402967dd82fSFlorian Fainelli if (!is5325(dev) && !is5365(dev)) 403967dd82fSFlorian Fainelli vc5 &= ~VC5_VID_FFF_EN; 404967dd82fSFlorian Fainelli 405967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL0, vc0); 406967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL1, vc1); 407967dd82fSFlorian Fainelli 408967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) { 409967dd82fSFlorian Fainelli /* enable the high 8 bit vid check on 5325 */ 410967dd82fSFlorian Fainelli if (is5325(dev) && enable) 411967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 412967dd82fSFlorian Fainelli VC3_HIGH_8BIT_EN); 413967dd82fSFlorian Fainelli else 414967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 0); 415967dd82fSFlorian Fainelli 416967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, vc4); 417967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_25, vc5); 418967dd82fSFlorian Fainelli } else if (is63xx(dev)) { 419967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3_63XX, 0); 420967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_63XX, vc4); 421967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_63XX, vc5); 422967dd82fSFlorian Fainelli } else { 423967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 0); 424967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, vc4); 425967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, vc5); 426967dd82fSFlorian Fainelli } 427967dd82fSFlorian Fainelli 428967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt); 429*dad8d7c6SFlorian Fainelli 430*dad8d7c6SFlorian Fainelli dev->vlan_enabled = enable; 431*dad8d7c6SFlorian Fainelli dev->vlan_filtering_enabled = enable_filtering; 432967dd82fSFlorian Fainelli } 433967dd82fSFlorian Fainelli 434967dd82fSFlorian Fainelli static int b53_set_jumbo(struct b53_device *dev, bool enable, bool allow_10_100) 435967dd82fSFlorian Fainelli { 436967dd82fSFlorian Fainelli u32 port_mask = 0; 437967dd82fSFlorian Fainelli u16 max_size = JMS_MIN_SIZE; 438967dd82fSFlorian Fainelli 439967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 440967dd82fSFlorian Fainelli return -EINVAL; 441967dd82fSFlorian Fainelli 442967dd82fSFlorian Fainelli if (enable) { 443967dd82fSFlorian Fainelli port_mask = dev->enabled_ports; 444967dd82fSFlorian Fainelli max_size = JMS_MAX_SIZE; 445967dd82fSFlorian Fainelli if (allow_10_100) 446967dd82fSFlorian Fainelli port_mask |= JPM_10_100_JUMBO_EN; 447967dd82fSFlorian Fainelli } 448967dd82fSFlorian Fainelli 449967dd82fSFlorian Fainelli b53_write32(dev, B53_JUMBO_PAGE, dev->jumbo_pm_reg, port_mask); 450967dd82fSFlorian Fainelli return b53_write16(dev, B53_JUMBO_PAGE, dev->jumbo_size_reg, max_size); 451967dd82fSFlorian Fainelli } 452967dd82fSFlorian Fainelli 453ff39c2d6SFlorian Fainelli static int b53_flush_arl(struct b53_device *dev, u8 mask) 454967dd82fSFlorian Fainelli { 455967dd82fSFlorian Fainelli unsigned int i; 456967dd82fSFlorian Fainelli 457967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, 458ff39c2d6SFlorian Fainelli FAST_AGE_DONE | FAST_AGE_DYNAMIC | mask); 459967dd82fSFlorian Fainelli 460967dd82fSFlorian Fainelli for (i = 0; i < 10; i++) { 461967dd82fSFlorian Fainelli u8 fast_age_ctrl; 462967dd82fSFlorian Fainelli 463967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, 464967dd82fSFlorian Fainelli &fast_age_ctrl); 465967dd82fSFlorian Fainelli 466967dd82fSFlorian Fainelli if (!(fast_age_ctrl & FAST_AGE_DONE)) 467967dd82fSFlorian Fainelli goto out; 468967dd82fSFlorian Fainelli 469967dd82fSFlorian Fainelli msleep(1); 470967dd82fSFlorian Fainelli } 471967dd82fSFlorian Fainelli 472967dd82fSFlorian Fainelli return -ETIMEDOUT; 473967dd82fSFlorian Fainelli out: 474967dd82fSFlorian Fainelli /* Only age dynamic entries (default behavior) */ 475967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, FAST_AGE_DYNAMIC); 476967dd82fSFlorian Fainelli return 0; 477967dd82fSFlorian Fainelli } 478967dd82fSFlorian Fainelli 479ff39c2d6SFlorian Fainelli static int b53_fast_age_port(struct b53_device *dev, int port) 480ff39c2d6SFlorian Fainelli { 481ff39c2d6SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_PORT_CTRL, port); 482ff39c2d6SFlorian Fainelli 483ff39c2d6SFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_PORT); 484ff39c2d6SFlorian Fainelli } 485ff39c2d6SFlorian Fainelli 486a2482d2cSFlorian Fainelli static int b53_fast_age_vlan(struct b53_device *dev, u16 vid) 487a2482d2cSFlorian Fainelli { 488a2482d2cSFlorian Fainelli b53_write16(dev, B53_CTRL_PAGE, B53_FAST_AGE_VID_CTRL, vid); 489a2482d2cSFlorian Fainelli 490a2482d2cSFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_VLAN); 491a2482d2cSFlorian Fainelli } 492a2482d2cSFlorian Fainelli 493aac02867SFlorian Fainelli void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port) 494ff39c2d6SFlorian Fainelli { 49504bed143SVivien Didelot struct b53_device *dev = ds->priv; 496ff39c2d6SFlorian Fainelli unsigned int i; 497ff39c2d6SFlorian Fainelli u16 pvlan; 498ff39c2d6SFlorian Fainelli 499ff39c2d6SFlorian Fainelli /* Enable the IMP port to be in the same VLAN as the other ports 500ff39c2d6SFlorian Fainelli * on a per-port basis such that we only have Port i and IMP in 501ff39c2d6SFlorian Fainelli * the same VLAN. 502ff39c2d6SFlorian Fainelli */ 503ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) { 504ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &pvlan); 505ff39c2d6SFlorian Fainelli pvlan |= BIT(cpu_port); 506ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), pvlan); 507ff39c2d6SFlorian Fainelli } 508ff39c2d6SFlorian Fainelli } 509aac02867SFlorian Fainelli EXPORT_SYMBOL(b53_imp_vlan_setup); 510ff39c2d6SFlorian Fainelli 511f86ad77fSFlorian Fainelli int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy) 512967dd82fSFlorian Fainelli { 51304bed143SVivien Didelot struct b53_device *dev = ds->priv; 514c499696eSFlorian Fainelli unsigned int cpu_port = ds->ports[port].cpu_dp->index; 5158ca7c160SFlorian Fainelli int ret = 0; 516ff39c2d6SFlorian Fainelli u16 pvlan; 517967dd82fSFlorian Fainelli 5188ca7c160SFlorian Fainelli if (dev->ops->irq_enable) 5198ca7c160SFlorian Fainelli ret = dev->ops->irq_enable(dev, port); 5208ca7c160SFlorian Fainelli if (ret) 5218ca7c160SFlorian Fainelli return ret; 5228ca7c160SFlorian Fainelli 523967dd82fSFlorian Fainelli /* Clear the Rx and Tx disable bits and set to no spanning tree */ 524967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), 0); 525967dd82fSFlorian Fainelli 526ff39c2d6SFlorian Fainelli /* Set this port, and only this one to be in the default VLAN, 527ff39c2d6SFlorian Fainelli * if member of a bridge, restore its membership prior to 528ff39c2d6SFlorian Fainelli * bringing down this port. 529ff39c2d6SFlorian Fainelli */ 530ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); 531ff39c2d6SFlorian Fainelli pvlan &= ~0x1ff; 532ff39c2d6SFlorian Fainelli pvlan |= BIT(port); 533ff39c2d6SFlorian Fainelli pvlan |= dev->ports[port].vlan_ctl_mask; 534ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); 535ff39c2d6SFlorian Fainelli 536ff39c2d6SFlorian Fainelli b53_imp_vlan_setup(ds, cpu_port); 537ff39c2d6SFlorian Fainelli 538f43a2dbeSFlorian Fainelli /* If EEE was enabled, restore it */ 539f43a2dbeSFlorian Fainelli if (dev->ports[port].eee.eee_enabled) 540f43a2dbeSFlorian Fainelli b53_eee_enable_set(ds, port, true); 541f43a2dbeSFlorian Fainelli 542967dd82fSFlorian Fainelli return 0; 543967dd82fSFlorian Fainelli } 544f86ad77fSFlorian Fainelli EXPORT_SYMBOL(b53_enable_port); 545967dd82fSFlorian Fainelli 546f86ad77fSFlorian Fainelli void b53_disable_port(struct dsa_switch *ds, int port, struct phy_device *phy) 547967dd82fSFlorian Fainelli { 54804bed143SVivien Didelot struct b53_device *dev = ds->priv; 549967dd82fSFlorian Fainelli u8 reg; 550967dd82fSFlorian Fainelli 551967dd82fSFlorian Fainelli /* Disable Tx/Rx for the port */ 552967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), ®); 553967dd82fSFlorian Fainelli reg |= PORT_CTRL_RX_DISABLE | PORT_CTRL_TX_DISABLE; 554967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg); 5558ca7c160SFlorian Fainelli 5568ca7c160SFlorian Fainelli if (dev->ops->irq_disable) 5578ca7c160SFlorian Fainelli dev->ops->irq_disable(dev, port); 558967dd82fSFlorian Fainelli } 559f86ad77fSFlorian Fainelli EXPORT_SYMBOL(b53_disable_port); 560967dd82fSFlorian Fainelli 561b409a9efSFlorian Fainelli void b53_brcm_hdr_setup(struct dsa_switch *ds, int port) 562b409a9efSFlorian Fainelli { 56311606039SFlorian Fainelli bool tag_en = !(ds->ops->get_tag_protocol(ds, port) == 56411606039SFlorian Fainelli DSA_TAG_PROTO_NONE); 565b409a9efSFlorian Fainelli struct b53_device *dev = ds->priv; 566b409a9efSFlorian Fainelli u8 hdr_ctl, val; 567b409a9efSFlorian Fainelli u16 reg; 568b409a9efSFlorian Fainelli 569b409a9efSFlorian Fainelli /* Resolve which bit controls the Broadcom tag */ 570b409a9efSFlorian Fainelli switch (port) { 571b409a9efSFlorian Fainelli case 8: 572b409a9efSFlorian Fainelli val = BRCM_HDR_P8_EN; 573b409a9efSFlorian Fainelli break; 574b409a9efSFlorian Fainelli case 7: 575b409a9efSFlorian Fainelli val = BRCM_HDR_P7_EN; 576b409a9efSFlorian Fainelli break; 577b409a9efSFlorian Fainelli case 5: 578b409a9efSFlorian Fainelli val = BRCM_HDR_P5_EN; 579b409a9efSFlorian Fainelli break; 580b409a9efSFlorian Fainelli default: 581b409a9efSFlorian Fainelli val = 0; 582b409a9efSFlorian Fainelli break; 583b409a9efSFlorian Fainelli } 584b409a9efSFlorian Fainelli 585b409a9efSFlorian Fainelli /* Enable Broadcom tags for IMP port */ 586b409a9efSFlorian Fainelli b53_read8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, &hdr_ctl); 587cdb583cfSFlorian Fainelli if (tag_en) 588b409a9efSFlorian Fainelli hdr_ctl |= val; 589cdb583cfSFlorian Fainelli else 590cdb583cfSFlorian Fainelli hdr_ctl &= ~val; 591b409a9efSFlorian Fainelli b53_write8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, hdr_ctl); 592b409a9efSFlorian Fainelli 593b409a9efSFlorian Fainelli /* Registers below are only accessible on newer devices */ 594b409a9efSFlorian Fainelli if (!is58xx(dev)) 595b409a9efSFlorian Fainelli return; 596b409a9efSFlorian Fainelli 597b409a9efSFlorian Fainelli /* Enable reception Broadcom tag for CPU TX (switch RX) to 598b409a9efSFlorian Fainelli * allow us to tag outgoing frames 599b409a9efSFlorian Fainelli */ 600b409a9efSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, ®); 601cdb583cfSFlorian Fainelli if (tag_en) 602b409a9efSFlorian Fainelli reg &= ~BIT(port); 603cdb583cfSFlorian Fainelli else 604cdb583cfSFlorian Fainelli reg |= BIT(port); 605b409a9efSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, reg); 606b409a9efSFlorian Fainelli 607b409a9efSFlorian Fainelli /* Enable transmission of Broadcom tags from the switch (CPU RX) to 608b409a9efSFlorian Fainelli * allow delivering frames to the per-port net_devices 609b409a9efSFlorian Fainelli */ 610b409a9efSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, ®); 611cdb583cfSFlorian Fainelli if (tag_en) 612b409a9efSFlorian Fainelli reg &= ~BIT(port); 613cdb583cfSFlorian Fainelli else 614cdb583cfSFlorian Fainelli reg |= BIT(port); 615b409a9efSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, reg); 616b409a9efSFlorian Fainelli } 617b409a9efSFlorian Fainelli EXPORT_SYMBOL(b53_brcm_hdr_setup); 618b409a9efSFlorian Fainelli 619299752a7SFlorian Fainelli static void b53_enable_cpu_port(struct b53_device *dev, int port) 620967dd82fSFlorian Fainelli { 621967dd82fSFlorian Fainelli u8 port_ctrl; 622967dd82fSFlorian Fainelli 623967dd82fSFlorian Fainelli /* BCM5325 CPU port is at 8 */ 624299752a7SFlorian Fainelli if ((is5325(dev) || is5365(dev)) && port == B53_CPU_PORT_25) 625299752a7SFlorian Fainelli port = B53_CPU_PORT; 626967dd82fSFlorian Fainelli 627967dd82fSFlorian Fainelli port_ctrl = PORT_CTRL_RX_BCST_EN | 628967dd82fSFlorian Fainelli PORT_CTRL_RX_MCST_EN | 629967dd82fSFlorian Fainelli PORT_CTRL_RX_UCST_EN; 630299752a7SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), port_ctrl); 6317edc58d6SFlorian Fainelli 6327edc58d6SFlorian Fainelli b53_brcm_hdr_setup(dev->ds, port); 633967dd82fSFlorian Fainelli } 634967dd82fSFlorian Fainelli 635967dd82fSFlorian Fainelli static void b53_enable_mib(struct b53_device *dev) 636967dd82fSFlorian Fainelli { 637967dd82fSFlorian Fainelli u8 gc; 638967dd82fSFlorian Fainelli 639967dd82fSFlorian Fainelli b53_read8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc); 640967dd82fSFlorian Fainelli gc &= ~(GC_RESET_MIB | GC_MIB_AC_EN); 641967dd82fSFlorian Fainelli b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc); 642967dd82fSFlorian Fainelli } 643967dd82fSFlorian Fainelli 644fea83353SFlorian Fainelli static u16 b53_default_pvid(struct b53_device *dev) 645fea83353SFlorian Fainelli { 646fea83353SFlorian Fainelli if (is5325(dev) || is5365(dev)) 647fea83353SFlorian Fainelli return 1; 648fea83353SFlorian Fainelli else 649fea83353SFlorian Fainelli return 0; 650fea83353SFlorian Fainelli } 651fea83353SFlorian Fainelli 6525c1a6eafSFlorian Fainelli int b53_configure_vlan(struct dsa_switch *ds) 653967dd82fSFlorian Fainelli { 6545c1a6eafSFlorian Fainelli struct b53_device *dev = ds->priv; 655a2482d2cSFlorian Fainelli struct b53_vlan vl = { 0 }; 656fea83353SFlorian Fainelli int i, def_vid; 657fea83353SFlorian Fainelli 658fea83353SFlorian Fainelli def_vid = b53_default_pvid(dev); 659967dd82fSFlorian Fainelli 660967dd82fSFlorian Fainelli /* clear all vlan entries */ 661967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) { 662fea83353SFlorian Fainelli for (i = def_vid; i < dev->num_vlans; i++) 663a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, i, &vl); 664967dd82fSFlorian Fainelli } else { 665967dd82fSFlorian Fainelli b53_do_vlan_op(dev, VTA_CMD_CLEAR); 666967dd82fSFlorian Fainelli } 667967dd82fSFlorian Fainelli 668*dad8d7c6SFlorian Fainelli b53_enable_vlan(dev, false, dev->vlan_filtering_enabled); 669967dd82fSFlorian Fainelli 670967dd82fSFlorian Fainelli b53_for_each_port(dev, i) 671967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, 672fea83353SFlorian Fainelli B53_VLAN_PORT_DEF_TAG(i), def_vid); 673967dd82fSFlorian Fainelli 674967dd82fSFlorian Fainelli if (!is5325(dev) && !is5365(dev)) 675967dd82fSFlorian Fainelli b53_set_jumbo(dev, dev->enable_jumbo, false); 676967dd82fSFlorian Fainelli 677967dd82fSFlorian Fainelli return 0; 678967dd82fSFlorian Fainelli } 6795c1a6eafSFlorian Fainelli EXPORT_SYMBOL(b53_configure_vlan); 680967dd82fSFlorian Fainelli 681967dd82fSFlorian Fainelli static void b53_switch_reset_gpio(struct b53_device *dev) 682967dd82fSFlorian Fainelli { 683967dd82fSFlorian Fainelli int gpio = dev->reset_gpio; 684967dd82fSFlorian Fainelli 685967dd82fSFlorian Fainelli if (gpio < 0) 686967dd82fSFlorian Fainelli return; 687967dd82fSFlorian Fainelli 688967dd82fSFlorian Fainelli /* Reset sequence: RESET low(50ms)->high(20ms) 689967dd82fSFlorian Fainelli */ 690967dd82fSFlorian Fainelli gpio_set_value(gpio, 0); 691967dd82fSFlorian Fainelli mdelay(50); 692967dd82fSFlorian Fainelli 693967dd82fSFlorian Fainelli gpio_set_value(gpio, 1); 694967dd82fSFlorian Fainelli mdelay(20); 695967dd82fSFlorian Fainelli 696967dd82fSFlorian Fainelli dev->current_page = 0xff; 697967dd82fSFlorian Fainelli } 698967dd82fSFlorian Fainelli 699967dd82fSFlorian Fainelli static int b53_switch_reset(struct b53_device *dev) 700967dd82fSFlorian Fainelli { 7013fb22b05SFlorian Fainelli unsigned int timeout = 1000; 7023fb22b05SFlorian Fainelli u8 mgmt, reg; 703967dd82fSFlorian Fainelli 704967dd82fSFlorian Fainelli b53_switch_reset_gpio(dev); 705967dd82fSFlorian Fainelli 706967dd82fSFlorian Fainelli if (is539x(dev)) { 707967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x83); 708967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x00); 709967dd82fSFlorian Fainelli } 710967dd82fSFlorian Fainelli 7113fb22b05SFlorian Fainelli /* This is specific to 58xx devices here, do not use is58xx() which 7123fb22b05SFlorian Fainelli * covers the larger Starfigther 2 family, including 7445/7278 which 7133fb22b05SFlorian Fainelli * still use this driver as a library and need to perform the reset 7143fb22b05SFlorian Fainelli * earlier. 7153fb22b05SFlorian Fainelli */ 7165040cc99SArun Parameswaran if (dev->chip_id == BCM58XX_DEVICE_ID || 7175040cc99SArun Parameswaran dev->chip_id == BCM583XX_DEVICE_ID) { 7183fb22b05SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, ®); 7193fb22b05SFlorian Fainelli reg |= SW_RST | EN_SW_RST | EN_CH_RST; 7203fb22b05SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, reg); 7213fb22b05SFlorian Fainelli 7223fb22b05SFlorian Fainelli do { 7233fb22b05SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, ®); 7243fb22b05SFlorian Fainelli if (!(reg & SW_RST)) 7253fb22b05SFlorian Fainelli break; 7263fb22b05SFlorian Fainelli 7273fb22b05SFlorian Fainelli usleep_range(1000, 2000); 7283fb22b05SFlorian Fainelli } while (timeout-- > 0); 7293fb22b05SFlorian Fainelli 7303fb22b05SFlorian Fainelli if (timeout == 0) 7313fb22b05SFlorian Fainelli return -ETIMEDOUT; 7323fb22b05SFlorian Fainelli } 7333fb22b05SFlorian Fainelli 734967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); 735967dd82fSFlorian Fainelli 736967dd82fSFlorian Fainelli if (!(mgmt & SM_SW_FWD_EN)) { 737967dd82fSFlorian Fainelli mgmt &= ~SM_SW_FWD_MODE; 738967dd82fSFlorian Fainelli mgmt |= SM_SW_FWD_EN; 739967dd82fSFlorian Fainelli 740967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt); 741967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); 742967dd82fSFlorian Fainelli 743967dd82fSFlorian Fainelli if (!(mgmt & SM_SW_FWD_EN)) { 744967dd82fSFlorian Fainelli dev_err(dev->dev, "Failed to enable switch!\n"); 745967dd82fSFlorian Fainelli return -EINVAL; 746967dd82fSFlorian Fainelli } 747967dd82fSFlorian Fainelli } 748967dd82fSFlorian Fainelli 749967dd82fSFlorian Fainelli b53_enable_mib(dev); 750967dd82fSFlorian Fainelli 751ff39c2d6SFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_STATIC); 752967dd82fSFlorian Fainelli } 753967dd82fSFlorian Fainelli 754967dd82fSFlorian Fainelli static int b53_phy_read16(struct dsa_switch *ds, int addr, int reg) 755967dd82fSFlorian Fainelli { 75604bed143SVivien Didelot struct b53_device *priv = ds->priv; 757967dd82fSFlorian Fainelli u16 value = 0; 758967dd82fSFlorian Fainelli int ret; 759967dd82fSFlorian Fainelli 760967dd82fSFlorian Fainelli if (priv->ops->phy_read16) 761967dd82fSFlorian Fainelli ret = priv->ops->phy_read16(priv, addr, reg, &value); 762967dd82fSFlorian Fainelli else 763967dd82fSFlorian Fainelli ret = b53_read16(priv, B53_PORT_MII_PAGE(addr), 764967dd82fSFlorian Fainelli reg * 2, &value); 765967dd82fSFlorian Fainelli 766967dd82fSFlorian Fainelli return ret ? ret : value; 767967dd82fSFlorian Fainelli } 768967dd82fSFlorian Fainelli 769967dd82fSFlorian Fainelli static int b53_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val) 770967dd82fSFlorian Fainelli { 77104bed143SVivien Didelot struct b53_device *priv = ds->priv; 772967dd82fSFlorian Fainelli 773967dd82fSFlorian Fainelli if (priv->ops->phy_write16) 774967dd82fSFlorian Fainelli return priv->ops->phy_write16(priv, addr, reg, val); 775967dd82fSFlorian Fainelli 776967dd82fSFlorian Fainelli return b53_write16(priv, B53_PORT_MII_PAGE(addr), reg * 2, val); 777967dd82fSFlorian Fainelli } 778967dd82fSFlorian Fainelli 779967dd82fSFlorian Fainelli static int b53_reset_switch(struct b53_device *priv) 780967dd82fSFlorian Fainelli { 781967dd82fSFlorian Fainelli /* reset vlans */ 782967dd82fSFlorian Fainelli priv->enable_jumbo = false; 783967dd82fSFlorian Fainelli 784a2482d2cSFlorian Fainelli memset(priv->vlans, 0, sizeof(*priv->vlans) * priv->num_vlans); 785967dd82fSFlorian Fainelli memset(priv->ports, 0, sizeof(*priv->ports) * priv->num_ports); 786967dd82fSFlorian Fainelli 7870e01491dSFlorian Fainelli priv->serdes_lane = B53_INVALID_LANE; 7880e01491dSFlorian Fainelli 789967dd82fSFlorian Fainelli return b53_switch_reset(priv); 790967dd82fSFlorian Fainelli } 791967dd82fSFlorian Fainelli 792967dd82fSFlorian Fainelli static int b53_apply_config(struct b53_device *priv) 793967dd82fSFlorian Fainelli { 794967dd82fSFlorian Fainelli /* disable switching */ 795967dd82fSFlorian Fainelli b53_set_forwarding(priv, 0); 796967dd82fSFlorian Fainelli 7975c1a6eafSFlorian Fainelli b53_configure_vlan(priv->ds); 798967dd82fSFlorian Fainelli 799967dd82fSFlorian Fainelli /* enable switching */ 800967dd82fSFlorian Fainelli b53_set_forwarding(priv, 1); 801967dd82fSFlorian Fainelli 802967dd82fSFlorian Fainelli return 0; 803967dd82fSFlorian Fainelli } 804967dd82fSFlorian Fainelli 805967dd82fSFlorian Fainelli static void b53_reset_mib(struct b53_device *priv) 806967dd82fSFlorian Fainelli { 807967dd82fSFlorian Fainelli u8 gc; 808967dd82fSFlorian Fainelli 809967dd82fSFlorian Fainelli b53_read8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc); 810967dd82fSFlorian Fainelli 811967dd82fSFlorian Fainelli b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc | GC_RESET_MIB); 812967dd82fSFlorian Fainelli msleep(1); 813967dd82fSFlorian Fainelli b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc & ~GC_RESET_MIB); 814967dd82fSFlorian Fainelli msleep(1); 815967dd82fSFlorian Fainelli } 816967dd82fSFlorian Fainelli 817967dd82fSFlorian Fainelli static const struct b53_mib_desc *b53_get_mib(struct b53_device *dev) 818967dd82fSFlorian Fainelli { 819967dd82fSFlorian Fainelli if (is5365(dev)) 820967dd82fSFlorian Fainelli return b53_mibs_65; 821967dd82fSFlorian Fainelli else if (is63xx(dev)) 822967dd82fSFlorian Fainelli return b53_mibs_63xx; 823bde5d132SFlorian Fainelli else if (is58xx(dev)) 824bde5d132SFlorian Fainelli return b53_mibs_58xx; 825967dd82fSFlorian Fainelli else 826967dd82fSFlorian Fainelli return b53_mibs; 827967dd82fSFlorian Fainelli } 828967dd82fSFlorian Fainelli 829967dd82fSFlorian Fainelli static unsigned int b53_get_mib_size(struct b53_device *dev) 830967dd82fSFlorian Fainelli { 831967dd82fSFlorian Fainelli if (is5365(dev)) 832967dd82fSFlorian Fainelli return B53_MIBS_65_SIZE; 833967dd82fSFlorian Fainelli else if (is63xx(dev)) 834967dd82fSFlorian Fainelli return B53_MIBS_63XX_SIZE; 835bde5d132SFlorian Fainelli else if (is58xx(dev)) 836bde5d132SFlorian Fainelli return B53_MIBS_58XX_SIZE; 837967dd82fSFlorian Fainelli else 838967dd82fSFlorian Fainelli return B53_MIBS_SIZE; 839967dd82fSFlorian Fainelli } 840967dd82fSFlorian Fainelli 841c7d28c9dSFlorian Fainelli static struct phy_device *b53_get_phy_device(struct dsa_switch *ds, int port) 842c7d28c9dSFlorian Fainelli { 843c7d28c9dSFlorian Fainelli /* These ports typically do not have built-in PHYs */ 844c7d28c9dSFlorian Fainelli switch (port) { 845c7d28c9dSFlorian Fainelli case B53_CPU_PORT_25: 846c7d28c9dSFlorian Fainelli case 7: 847c7d28c9dSFlorian Fainelli case B53_CPU_PORT: 848c7d28c9dSFlorian Fainelli return NULL; 849c7d28c9dSFlorian Fainelli } 850c7d28c9dSFlorian Fainelli 851c7d28c9dSFlorian Fainelli return mdiobus_get_phy(ds->slave_mii_bus, port); 852c7d28c9dSFlorian Fainelli } 853c7d28c9dSFlorian Fainelli 85489f09048SFlorian Fainelli void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset, 85589f09048SFlorian Fainelli uint8_t *data) 856967dd82fSFlorian Fainelli { 85704bed143SVivien Didelot struct b53_device *dev = ds->priv; 858967dd82fSFlorian Fainelli const struct b53_mib_desc *mibs = b53_get_mib(dev); 859967dd82fSFlorian Fainelli unsigned int mib_size = b53_get_mib_size(dev); 860c7d28c9dSFlorian Fainelli struct phy_device *phydev; 861967dd82fSFlorian Fainelli unsigned int i; 862967dd82fSFlorian Fainelli 863c7d28c9dSFlorian Fainelli if (stringset == ETH_SS_STATS) { 864967dd82fSFlorian Fainelli for (i = 0; i < mib_size; i++) 865cd526676SFlorian Fainelli strlcpy(data + i * ETH_GSTRING_LEN, 866967dd82fSFlorian Fainelli mibs[i].name, ETH_GSTRING_LEN); 867c7d28c9dSFlorian Fainelli } else if (stringset == ETH_SS_PHY_STATS) { 868c7d28c9dSFlorian Fainelli phydev = b53_get_phy_device(ds, port); 869c7d28c9dSFlorian Fainelli if (!phydev) 870c7d28c9dSFlorian Fainelli return; 871c7d28c9dSFlorian Fainelli 872c7d28c9dSFlorian Fainelli phy_ethtool_get_strings(phydev, data); 873c7d28c9dSFlorian Fainelli } 874967dd82fSFlorian Fainelli } 8753117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_strings); 876967dd82fSFlorian Fainelli 8773117455dSFlorian Fainelli void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data) 878967dd82fSFlorian Fainelli { 87904bed143SVivien Didelot struct b53_device *dev = ds->priv; 880967dd82fSFlorian Fainelli const struct b53_mib_desc *mibs = b53_get_mib(dev); 881967dd82fSFlorian Fainelli unsigned int mib_size = b53_get_mib_size(dev); 882967dd82fSFlorian Fainelli const struct b53_mib_desc *s; 883967dd82fSFlorian Fainelli unsigned int i; 884967dd82fSFlorian Fainelli u64 val = 0; 885967dd82fSFlorian Fainelli 886967dd82fSFlorian Fainelli if (is5365(dev) && port == 5) 887967dd82fSFlorian Fainelli port = 8; 888967dd82fSFlorian Fainelli 889967dd82fSFlorian Fainelli mutex_lock(&dev->stats_mutex); 890967dd82fSFlorian Fainelli 891967dd82fSFlorian Fainelli for (i = 0; i < mib_size; i++) { 892967dd82fSFlorian Fainelli s = &mibs[i]; 893967dd82fSFlorian Fainelli 89451dca8a1SFlorian Fainelli if (s->size == 8) { 895967dd82fSFlorian Fainelli b53_read64(dev, B53_MIB_PAGE(port), s->offset, &val); 896967dd82fSFlorian Fainelli } else { 897967dd82fSFlorian Fainelli u32 val32; 898967dd82fSFlorian Fainelli 899967dd82fSFlorian Fainelli b53_read32(dev, B53_MIB_PAGE(port), s->offset, 900967dd82fSFlorian Fainelli &val32); 901967dd82fSFlorian Fainelli val = val32; 902967dd82fSFlorian Fainelli } 903967dd82fSFlorian Fainelli data[i] = (u64)val; 904967dd82fSFlorian Fainelli } 905967dd82fSFlorian Fainelli 906967dd82fSFlorian Fainelli mutex_unlock(&dev->stats_mutex); 907967dd82fSFlorian Fainelli } 9083117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_ethtool_stats); 909967dd82fSFlorian Fainelli 910c7d28c9dSFlorian Fainelli void b53_get_ethtool_phy_stats(struct dsa_switch *ds, int port, uint64_t *data) 911c7d28c9dSFlorian Fainelli { 912c7d28c9dSFlorian Fainelli struct phy_device *phydev; 913c7d28c9dSFlorian Fainelli 914c7d28c9dSFlorian Fainelli phydev = b53_get_phy_device(ds, port); 915c7d28c9dSFlorian Fainelli if (!phydev) 916c7d28c9dSFlorian Fainelli return; 917c7d28c9dSFlorian Fainelli 918c7d28c9dSFlorian Fainelli phy_ethtool_get_stats(phydev, NULL, data); 919c7d28c9dSFlorian Fainelli } 920c7d28c9dSFlorian Fainelli EXPORT_SYMBOL(b53_get_ethtool_phy_stats); 921c7d28c9dSFlorian Fainelli 92289f09048SFlorian Fainelli int b53_get_sset_count(struct dsa_switch *ds, int port, int sset) 923967dd82fSFlorian Fainelli { 92404bed143SVivien Didelot struct b53_device *dev = ds->priv; 925c7d28c9dSFlorian Fainelli struct phy_device *phydev; 926967dd82fSFlorian Fainelli 927c7d28c9dSFlorian Fainelli if (sset == ETH_SS_STATS) { 928c7d28c9dSFlorian Fainelli return b53_get_mib_size(dev); 929c7d28c9dSFlorian Fainelli } else if (sset == ETH_SS_PHY_STATS) { 930c7d28c9dSFlorian Fainelli phydev = b53_get_phy_device(ds, port); 931c7d28c9dSFlorian Fainelli if (!phydev) 93289f09048SFlorian Fainelli return 0; 93389f09048SFlorian Fainelli 934c7d28c9dSFlorian Fainelli return phy_ethtool_get_sset_count(phydev); 935c7d28c9dSFlorian Fainelli } 936c7d28c9dSFlorian Fainelli 937c7d28c9dSFlorian Fainelli return 0; 938967dd82fSFlorian Fainelli } 9393117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_sset_count); 940967dd82fSFlorian Fainelli 941967dd82fSFlorian Fainelli static int b53_setup(struct dsa_switch *ds) 942967dd82fSFlorian Fainelli { 94304bed143SVivien Didelot struct b53_device *dev = ds->priv; 944967dd82fSFlorian Fainelli unsigned int port; 945967dd82fSFlorian Fainelli int ret; 946967dd82fSFlorian Fainelli 947967dd82fSFlorian Fainelli ret = b53_reset_switch(dev); 948967dd82fSFlorian Fainelli if (ret) { 949967dd82fSFlorian Fainelli dev_err(ds->dev, "failed to reset switch\n"); 950967dd82fSFlorian Fainelli return ret; 951967dd82fSFlorian Fainelli } 952967dd82fSFlorian Fainelli 953967dd82fSFlorian Fainelli b53_reset_mib(dev); 954967dd82fSFlorian Fainelli 955967dd82fSFlorian Fainelli ret = b53_apply_config(dev); 956967dd82fSFlorian Fainelli if (ret) 957967dd82fSFlorian Fainelli dev_err(ds->dev, "failed to apply configuration\n"); 958967dd82fSFlorian Fainelli 95934c8befdSFlorian Fainelli /* Configure IMP/CPU port, disable unused ports. Enabled 96034c8befdSFlorian Fainelli * ports will be configured with .port_enable 96134c8befdSFlorian Fainelli */ 962967dd82fSFlorian Fainelli for (port = 0; port < dev->num_ports; port++) { 96334c8befdSFlorian Fainelli if (dsa_is_cpu_port(ds, port)) 964299752a7SFlorian Fainelli b53_enable_cpu_port(dev, port); 965bff7b688SVivien Didelot else if (dsa_is_unused_port(ds, port)) 966967dd82fSFlorian Fainelli b53_disable_port(ds, port, NULL); 967967dd82fSFlorian Fainelli } 968967dd82fSFlorian Fainelli 969967dd82fSFlorian Fainelli return ret; 970967dd82fSFlorian Fainelli } 971967dd82fSFlorian Fainelli 9725e004460SFlorian Fainelli static void b53_force_link(struct b53_device *dev, int port, int link) 973967dd82fSFlorian Fainelli { 9745e004460SFlorian Fainelli u8 reg, val, off; 975967dd82fSFlorian Fainelli 976967dd82fSFlorian Fainelli /* Override the port settings */ 977967dd82fSFlorian Fainelli if (port == dev->cpu_port) { 978967dd82fSFlorian Fainelli off = B53_PORT_OVERRIDE_CTRL; 9795e004460SFlorian Fainelli val = PORT_OVERRIDE_EN; 980967dd82fSFlorian Fainelli } else { 981967dd82fSFlorian Fainelli off = B53_GMII_PORT_OVERRIDE_CTRL(port); 9825e004460SFlorian Fainelli val = GMII_PO_EN; 983967dd82fSFlorian Fainelli } 984967dd82fSFlorian Fainelli 9855e004460SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, off, ®); 9865e004460SFlorian Fainelli reg |= val; 9875e004460SFlorian Fainelli if (link) 988967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_LINK; 9895e004460SFlorian Fainelli else 9905e004460SFlorian Fainelli reg &= ~PORT_OVERRIDE_LINK; 9915e004460SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, off, reg); 9925e004460SFlorian Fainelli } 993967dd82fSFlorian Fainelli 9945e004460SFlorian Fainelli static void b53_force_port_config(struct b53_device *dev, int port, 9955e004460SFlorian Fainelli int speed, int duplex, int pause) 9965e004460SFlorian Fainelli { 9975e004460SFlorian Fainelli u8 reg, val, off; 9985e004460SFlorian Fainelli 9995e004460SFlorian Fainelli /* Override the port settings */ 10005e004460SFlorian Fainelli if (port == dev->cpu_port) { 10015e004460SFlorian Fainelli off = B53_PORT_OVERRIDE_CTRL; 10025e004460SFlorian Fainelli val = PORT_OVERRIDE_EN; 10035e004460SFlorian Fainelli } else { 10045e004460SFlorian Fainelli off = B53_GMII_PORT_OVERRIDE_CTRL(port); 10055e004460SFlorian Fainelli val = GMII_PO_EN; 10065e004460SFlorian Fainelli } 10075e004460SFlorian Fainelli 10085e004460SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, off, ®); 10095e004460SFlorian Fainelli reg |= val; 10105e004460SFlorian Fainelli if (duplex == DUPLEX_FULL) 1011967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_FULL_DUPLEX; 10125e004460SFlorian Fainelli else 10135e004460SFlorian Fainelli reg &= ~PORT_OVERRIDE_FULL_DUPLEX; 1014967dd82fSFlorian Fainelli 10155e004460SFlorian Fainelli switch (speed) { 1016967dd82fSFlorian Fainelli case 2000: 1017967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_2000M; 1018967dd82fSFlorian Fainelli /* fallthrough */ 1019967dd82fSFlorian Fainelli case SPEED_1000: 1020967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_1000M; 1021967dd82fSFlorian Fainelli break; 1022967dd82fSFlorian Fainelli case SPEED_100: 1023967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_100M; 1024967dd82fSFlorian Fainelli break; 1025967dd82fSFlorian Fainelli case SPEED_10: 1026967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_10M; 1027967dd82fSFlorian Fainelli break; 1028967dd82fSFlorian Fainelli default: 10295e004460SFlorian Fainelli dev_err(dev->dev, "unknown speed: %d\n", speed); 1030967dd82fSFlorian Fainelli return; 1031967dd82fSFlorian Fainelli } 1032967dd82fSFlorian Fainelli 10335e004460SFlorian Fainelli if (pause & MLO_PAUSE_RX) 10345e004460SFlorian Fainelli reg |= PORT_OVERRIDE_RX_FLOW; 10355e004460SFlorian Fainelli if (pause & MLO_PAUSE_TX) 10365e004460SFlorian Fainelli reg |= PORT_OVERRIDE_TX_FLOW; 10375e004460SFlorian Fainelli 10385e004460SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, off, reg); 10395e004460SFlorian Fainelli } 10405e004460SFlorian Fainelli 10415e004460SFlorian Fainelli static void b53_adjust_link(struct dsa_switch *ds, int port, 10425e004460SFlorian Fainelli struct phy_device *phydev) 10435e004460SFlorian Fainelli { 10445e004460SFlorian Fainelli struct b53_device *dev = ds->priv; 10455e004460SFlorian Fainelli struct ethtool_eee *p = &dev->ports[port].eee; 10465e004460SFlorian Fainelli u8 rgmii_ctrl = 0, reg = 0, off; 1047f973b768SDan Carpenter int pause = 0; 10485e004460SFlorian Fainelli 10495e004460SFlorian Fainelli if (!phy_is_pseudo_fixed_link(phydev)) 10505e004460SFlorian Fainelli return; 10515e004460SFlorian Fainelli 1052967dd82fSFlorian Fainelli /* Enable flow control on BCM5301x's CPU port */ 1053967dd82fSFlorian Fainelli if (is5301x(dev) && port == dev->cpu_port) 10545e004460SFlorian Fainelli pause = MLO_PAUSE_TXRX_MASK; 1055967dd82fSFlorian Fainelli 1056967dd82fSFlorian Fainelli if (phydev->pause) { 1057967dd82fSFlorian Fainelli if (phydev->asym_pause) 10585e004460SFlorian Fainelli pause |= MLO_PAUSE_TX; 10595e004460SFlorian Fainelli pause |= MLO_PAUSE_RX; 1060967dd82fSFlorian Fainelli } 1061967dd82fSFlorian Fainelli 10625e004460SFlorian Fainelli b53_force_port_config(dev, port, phydev->speed, phydev->duplex, pause); 10635e004460SFlorian Fainelli b53_force_link(dev, port, phydev->link); 1064967dd82fSFlorian Fainelli 1065967dd82fSFlorian Fainelli if (is531x5(dev) && phy_interface_is_rgmii(phydev)) { 1066967dd82fSFlorian Fainelli if (port == 8) 1067967dd82fSFlorian Fainelli off = B53_RGMII_CTRL_IMP; 1068967dd82fSFlorian Fainelli else 1069967dd82fSFlorian Fainelli off = B53_RGMII_CTRL_P(port); 1070967dd82fSFlorian Fainelli 1071967dd82fSFlorian Fainelli /* Configure the port RGMII clock delay by DLL disabled and 1072967dd82fSFlorian Fainelli * tx_clk aligned timing (restoring to reset defaults) 1073967dd82fSFlorian Fainelli */ 1074967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, off, &rgmii_ctrl); 1075967dd82fSFlorian Fainelli rgmii_ctrl &= ~(RGMII_CTRL_DLL_RXC | RGMII_CTRL_DLL_TXC | 1076967dd82fSFlorian Fainelli RGMII_CTRL_TIMING_SEL); 1077967dd82fSFlorian Fainelli 1078967dd82fSFlorian Fainelli /* PHY_INTERFACE_MODE_RGMII_TXID means TX internal delay, make 1079967dd82fSFlorian Fainelli * sure that we enable the port TX clock internal delay to 1080967dd82fSFlorian Fainelli * account for this internal delay that is inserted, otherwise 1081967dd82fSFlorian Fainelli * the switch won't be able to receive correctly. 1082967dd82fSFlorian Fainelli * 1083967dd82fSFlorian Fainelli * PHY_INTERFACE_MODE_RGMII means that we are not introducing 1084967dd82fSFlorian Fainelli * any delay neither on transmission nor reception, so the 1085967dd82fSFlorian Fainelli * BCM53125 must also be configured accordingly to account for 1086967dd82fSFlorian Fainelli * the lack of delay and introduce 1087967dd82fSFlorian Fainelli * 1088967dd82fSFlorian Fainelli * The BCM53125 switch has its RX clock and TX clock control 1089967dd82fSFlorian Fainelli * swapped, hence the reason why we modify the TX clock path in 1090967dd82fSFlorian Fainelli * the "RGMII" case 1091967dd82fSFlorian Fainelli */ 1092967dd82fSFlorian Fainelli if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) 1093967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_DLL_TXC; 1094967dd82fSFlorian Fainelli if (phydev->interface == PHY_INTERFACE_MODE_RGMII) 1095967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_DLL_TXC | RGMII_CTRL_DLL_RXC; 1096967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_TIMING_SEL; 1097967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, off, rgmii_ctrl); 1098967dd82fSFlorian Fainelli 1099967dd82fSFlorian Fainelli dev_info(ds->dev, "Configured port %d for %s\n", port, 1100967dd82fSFlorian Fainelli phy_modes(phydev->interface)); 1101967dd82fSFlorian Fainelli } 1102967dd82fSFlorian Fainelli 1103967dd82fSFlorian Fainelli /* configure MII port if necessary */ 1104967dd82fSFlorian Fainelli if (is5325(dev)) { 1105967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, 1106967dd82fSFlorian Fainelli ®); 1107967dd82fSFlorian Fainelli 1108967dd82fSFlorian Fainelli /* reverse mii needs to be enabled */ 1109967dd82fSFlorian Fainelli if (!(reg & PORT_OVERRIDE_RV_MII_25)) { 1110967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, 1111967dd82fSFlorian Fainelli reg | PORT_OVERRIDE_RV_MII_25); 1112967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, 1113967dd82fSFlorian Fainelli ®); 1114967dd82fSFlorian Fainelli 1115967dd82fSFlorian Fainelli if (!(reg & PORT_OVERRIDE_RV_MII_25)) { 1116967dd82fSFlorian Fainelli dev_err(ds->dev, 1117967dd82fSFlorian Fainelli "Failed to enable reverse MII mode\n"); 1118967dd82fSFlorian Fainelli return; 1119967dd82fSFlorian Fainelli } 1120967dd82fSFlorian Fainelli } 1121967dd82fSFlorian Fainelli } else if (is5301x(dev)) { 1122967dd82fSFlorian Fainelli if (port != dev->cpu_port) { 11235e004460SFlorian Fainelli b53_force_port_config(dev, dev->cpu_port, 2000, 11245e004460SFlorian Fainelli DUPLEX_FULL, MLO_PAUSE_TXRX_MASK); 11255e004460SFlorian Fainelli b53_force_link(dev, dev->cpu_port, 1); 1126967dd82fSFlorian Fainelli } 1127967dd82fSFlorian Fainelli } 1128f43a2dbeSFlorian Fainelli 1129f43a2dbeSFlorian Fainelli /* Re-negotiate EEE if it was enabled already */ 1130f43a2dbeSFlorian Fainelli p->eee_enabled = b53_eee_init(ds, port, phydev); 1131967dd82fSFlorian Fainelli } 1132967dd82fSFlorian Fainelli 1133a8e8b985SFlorian Fainelli void b53_port_event(struct dsa_switch *ds, int port) 1134a8e8b985SFlorian Fainelli { 1135a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1136a8e8b985SFlorian Fainelli bool link; 1137a8e8b985SFlorian Fainelli u16 sts; 1138a8e8b985SFlorian Fainelli 1139a8e8b985SFlorian Fainelli b53_read16(dev, B53_STAT_PAGE, B53_LINK_STAT, &sts); 1140a8e8b985SFlorian Fainelli link = !!(sts & BIT(port)); 1141a8e8b985SFlorian Fainelli dsa_port_phylink_mac_change(ds, port, link); 1142a8e8b985SFlorian Fainelli } 1143a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_port_event); 1144a8e8b985SFlorian Fainelli 1145a8e8b985SFlorian Fainelli void b53_phylink_validate(struct dsa_switch *ds, int port, 1146a8e8b985SFlorian Fainelli unsigned long *supported, 1147a8e8b985SFlorian Fainelli struct phylink_link_state *state) 1148a8e8b985SFlorian Fainelli { 1149a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1150a8e8b985SFlorian Fainelli __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, }; 1151a8e8b985SFlorian Fainelli 11520e01491dSFlorian Fainelli if (dev->ops->serdes_phylink_validate) 11530e01491dSFlorian Fainelli dev->ops->serdes_phylink_validate(dev, port, mask, state); 11540e01491dSFlorian Fainelli 1155a8e8b985SFlorian Fainelli /* Allow all the expected bits */ 1156a8e8b985SFlorian Fainelli phylink_set(mask, Autoneg); 1157a8e8b985SFlorian Fainelli phylink_set_port_modes(mask); 1158a8e8b985SFlorian Fainelli phylink_set(mask, Pause); 1159a8e8b985SFlorian Fainelli phylink_set(mask, Asym_Pause); 1160a8e8b985SFlorian Fainelli 1161a8e8b985SFlorian Fainelli /* With the exclusion of 5325/5365, MII, Reverse MII and 802.3z, we 1162a8e8b985SFlorian Fainelli * support Gigabit, including Half duplex. 1163a8e8b985SFlorian Fainelli */ 1164a8e8b985SFlorian Fainelli if (state->interface != PHY_INTERFACE_MODE_MII && 1165a8e8b985SFlorian Fainelli state->interface != PHY_INTERFACE_MODE_REVMII && 1166a8e8b985SFlorian Fainelli !phy_interface_mode_is_8023z(state->interface) && 1167a8e8b985SFlorian Fainelli !(is5325(dev) || is5365(dev))) { 1168a8e8b985SFlorian Fainelli phylink_set(mask, 1000baseT_Full); 1169a8e8b985SFlorian Fainelli phylink_set(mask, 1000baseT_Half); 1170a8e8b985SFlorian Fainelli } 1171a8e8b985SFlorian Fainelli 1172a8e8b985SFlorian Fainelli if (!phy_interface_mode_is_8023z(state->interface)) { 1173a8e8b985SFlorian Fainelli phylink_set(mask, 10baseT_Half); 1174a8e8b985SFlorian Fainelli phylink_set(mask, 10baseT_Full); 1175a8e8b985SFlorian Fainelli phylink_set(mask, 100baseT_Half); 1176a8e8b985SFlorian Fainelli phylink_set(mask, 100baseT_Full); 1177a8e8b985SFlorian Fainelli } 1178a8e8b985SFlorian Fainelli 1179a8e8b985SFlorian Fainelli bitmap_and(supported, supported, mask, 1180a8e8b985SFlorian Fainelli __ETHTOOL_LINK_MODE_MASK_NBITS); 1181a8e8b985SFlorian Fainelli bitmap_and(state->advertising, state->advertising, mask, 1182a8e8b985SFlorian Fainelli __ETHTOOL_LINK_MODE_MASK_NBITS); 1183a8e8b985SFlorian Fainelli 1184a8e8b985SFlorian Fainelli phylink_helper_basex_speed(state); 1185a8e8b985SFlorian Fainelli } 1186a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_validate); 1187a8e8b985SFlorian Fainelli 1188a8e8b985SFlorian Fainelli int b53_phylink_mac_link_state(struct dsa_switch *ds, int port, 1189a8e8b985SFlorian Fainelli struct phylink_link_state *state) 1190a8e8b985SFlorian Fainelli { 11910e01491dSFlorian Fainelli struct b53_device *dev = ds->priv; 1192a8e8b985SFlorian Fainelli int ret = -EOPNOTSUPP; 1193a8e8b985SFlorian Fainelli 119455a4d2eaSFlorian Fainelli if ((phy_interface_mode_is_8023z(state->interface) || 119555a4d2eaSFlorian Fainelli state->interface == PHY_INTERFACE_MODE_SGMII) && 11960e01491dSFlorian Fainelli dev->ops->serdes_link_state) 11970e01491dSFlorian Fainelli ret = dev->ops->serdes_link_state(dev, port, state); 11980e01491dSFlorian Fainelli 1199a8e8b985SFlorian Fainelli return ret; 1200a8e8b985SFlorian Fainelli } 1201a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_state); 1202a8e8b985SFlorian Fainelli 1203a8e8b985SFlorian Fainelli void b53_phylink_mac_config(struct dsa_switch *ds, int port, 1204a8e8b985SFlorian Fainelli unsigned int mode, 1205a8e8b985SFlorian Fainelli const struct phylink_link_state *state) 1206a8e8b985SFlorian Fainelli { 1207a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1208a8e8b985SFlorian Fainelli 1209a8e8b985SFlorian Fainelli if (mode == MLO_AN_PHY) 1210a8e8b985SFlorian Fainelli return; 1211a8e8b985SFlorian Fainelli 1212a8e8b985SFlorian Fainelli if (mode == MLO_AN_FIXED) { 1213a8e8b985SFlorian Fainelli b53_force_port_config(dev, port, state->speed, 1214a8e8b985SFlorian Fainelli state->duplex, state->pause); 1215a8e8b985SFlorian Fainelli return; 1216a8e8b985SFlorian Fainelli } 12170e01491dSFlorian Fainelli 121855a4d2eaSFlorian Fainelli if ((phy_interface_mode_is_8023z(state->interface) || 121955a4d2eaSFlorian Fainelli state->interface == PHY_INTERFACE_MODE_SGMII) && 12200e01491dSFlorian Fainelli dev->ops->serdes_config) 12210e01491dSFlorian Fainelli dev->ops->serdes_config(dev, port, mode, state); 1222a8e8b985SFlorian Fainelli } 1223a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_config); 1224a8e8b985SFlorian Fainelli 1225a8e8b985SFlorian Fainelli void b53_phylink_mac_an_restart(struct dsa_switch *ds, int port) 1226a8e8b985SFlorian Fainelli { 12270e01491dSFlorian Fainelli struct b53_device *dev = ds->priv; 12280e01491dSFlorian Fainelli 12290e01491dSFlorian Fainelli if (dev->ops->serdes_an_restart) 12300e01491dSFlorian Fainelli dev->ops->serdes_an_restart(dev, port); 1231a8e8b985SFlorian Fainelli } 1232a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_an_restart); 1233a8e8b985SFlorian Fainelli 1234a8e8b985SFlorian Fainelli void b53_phylink_mac_link_down(struct dsa_switch *ds, int port, 1235a8e8b985SFlorian Fainelli unsigned int mode, 1236a8e8b985SFlorian Fainelli phy_interface_t interface) 1237a8e8b985SFlorian Fainelli { 1238a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1239a8e8b985SFlorian Fainelli 1240a8e8b985SFlorian Fainelli if (mode == MLO_AN_PHY) 1241a8e8b985SFlorian Fainelli return; 1242a8e8b985SFlorian Fainelli 1243a8e8b985SFlorian Fainelli if (mode == MLO_AN_FIXED) { 1244a8e8b985SFlorian Fainelli b53_force_link(dev, port, false); 1245a8e8b985SFlorian Fainelli return; 1246a8e8b985SFlorian Fainelli } 12470e01491dSFlorian Fainelli 12480e01491dSFlorian Fainelli if (phy_interface_mode_is_8023z(interface) && 12490e01491dSFlorian Fainelli dev->ops->serdes_link_set) 12500e01491dSFlorian Fainelli dev->ops->serdes_link_set(dev, port, mode, interface, false); 1251a8e8b985SFlorian Fainelli } 1252a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_down); 1253a8e8b985SFlorian Fainelli 1254a8e8b985SFlorian Fainelli void b53_phylink_mac_link_up(struct dsa_switch *ds, int port, 1255a8e8b985SFlorian Fainelli unsigned int mode, 1256a8e8b985SFlorian Fainelli phy_interface_t interface, 1257a8e8b985SFlorian Fainelli struct phy_device *phydev) 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, true); 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, true); 1272a8e8b985SFlorian Fainelli } 1273a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_up); 1274a8e8b985SFlorian Fainelli 12753117455dSFlorian Fainelli int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering) 1276a2482d2cSFlorian Fainelli { 1277*dad8d7c6SFlorian Fainelli struct b53_device *dev = ds->priv; 1278*dad8d7c6SFlorian Fainelli struct net_device *bridge_dev; 1279*dad8d7c6SFlorian Fainelli unsigned int i; 1280*dad8d7c6SFlorian Fainelli u16 pvid, new_pvid; 1281*dad8d7c6SFlorian Fainelli 1282*dad8d7c6SFlorian Fainelli /* Handle the case were multiple bridges span the same switch device 1283*dad8d7c6SFlorian Fainelli * and one of them has a different setting than what is being requested 1284*dad8d7c6SFlorian Fainelli * which would be breaking filtering semantics for any of the other 1285*dad8d7c6SFlorian Fainelli * bridge devices. 1286*dad8d7c6SFlorian Fainelli */ 1287*dad8d7c6SFlorian Fainelli b53_for_each_port(dev, i) { 1288*dad8d7c6SFlorian Fainelli bridge_dev = dsa_to_port(ds, i)->bridge_dev; 1289*dad8d7c6SFlorian Fainelli if (bridge_dev && 1290*dad8d7c6SFlorian Fainelli bridge_dev != dsa_to_port(ds, port)->bridge_dev && 1291*dad8d7c6SFlorian Fainelli br_vlan_enabled(bridge_dev) != vlan_filtering) { 1292*dad8d7c6SFlorian Fainelli netdev_err(bridge_dev, 1293*dad8d7c6SFlorian Fainelli "VLAN filtering is global to the switch!\n"); 1294*dad8d7c6SFlorian Fainelli return -EINVAL; 1295*dad8d7c6SFlorian Fainelli } 1296*dad8d7c6SFlorian Fainelli } 1297*dad8d7c6SFlorian Fainelli 1298*dad8d7c6SFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid); 1299*dad8d7c6SFlorian Fainelli new_pvid = pvid; 1300*dad8d7c6SFlorian Fainelli if (dev->vlan_filtering_enabled && !vlan_filtering) { 1301*dad8d7c6SFlorian Fainelli /* Filtering is currently enabled, use the default PVID since 1302*dad8d7c6SFlorian Fainelli * the bridge does not expect tagging anymore 1303*dad8d7c6SFlorian Fainelli */ 1304*dad8d7c6SFlorian Fainelli dev->ports[port].pvid = pvid; 1305*dad8d7c6SFlorian Fainelli new_pvid = b53_default_pvid(dev); 1306*dad8d7c6SFlorian Fainelli } else if (!dev->vlan_filtering_enabled && vlan_filtering) { 1307*dad8d7c6SFlorian Fainelli /* Filtering is currently disabled, restore the previous PVID */ 1308*dad8d7c6SFlorian Fainelli new_pvid = dev->ports[port].pvid; 1309*dad8d7c6SFlorian Fainelli } 1310*dad8d7c6SFlorian Fainelli 1311*dad8d7c6SFlorian Fainelli if (pvid != new_pvid) 1312*dad8d7c6SFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), 1313*dad8d7c6SFlorian Fainelli new_pvid); 1314*dad8d7c6SFlorian Fainelli 1315*dad8d7c6SFlorian Fainelli b53_enable_vlan(dev, dev->vlan_enabled, vlan_filtering); 1316*dad8d7c6SFlorian Fainelli 1317a2482d2cSFlorian Fainelli return 0; 1318a2482d2cSFlorian Fainelli } 13193117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_filtering); 1320a2482d2cSFlorian Fainelli 13213117455dSFlorian Fainelli int b53_vlan_prepare(struct dsa_switch *ds, int port, 132280e02360SVivien Didelot const struct switchdev_obj_port_vlan *vlan) 1323a2482d2cSFlorian Fainelli { 132404bed143SVivien Didelot struct b53_device *dev = ds->priv; 1325a2482d2cSFlorian Fainelli 1326a2482d2cSFlorian Fainelli if ((is5325(dev) || is5365(dev)) && vlan->vid_begin == 0) 1327a2482d2cSFlorian Fainelli return -EOPNOTSUPP; 1328a2482d2cSFlorian Fainelli 1329a2482d2cSFlorian Fainelli if (vlan->vid_end > dev->num_vlans) 1330a2482d2cSFlorian Fainelli return -ERANGE; 1331a2482d2cSFlorian Fainelli 1332*dad8d7c6SFlorian Fainelli b53_enable_vlan(dev, true, dev->vlan_filtering_enabled); 1333a2482d2cSFlorian Fainelli 1334a2482d2cSFlorian Fainelli return 0; 1335a2482d2cSFlorian Fainelli } 13363117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_prepare); 1337a2482d2cSFlorian Fainelli 13383117455dSFlorian Fainelli void b53_vlan_add(struct dsa_switch *ds, int port, 133980e02360SVivien Didelot const struct switchdev_obj_port_vlan *vlan) 1340a2482d2cSFlorian Fainelli { 134104bed143SVivien Didelot struct b53_device *dev = ds->priv; 1342a2482d2cSFlorian Fainelli bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; 1343a2482d2cSFlorian Fainelli bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID; 1344a2482d2cSFlorian Fainelli struct b53_vlan *vl; 1345a2482d2cSFlorian Fainelli u16 vid; 1346a2482d2cSFlorian Fainelli 1347a2482d2cSFlorian Fainelli for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) { 1348a2482d2cSFlorian Fainelli vl = &dev->vlans[vid]; 1349a2482d2cSFlorian Fainelli 1350a2482d2cSFlorian Fainelli b53_get_vlan_entry(dev, vid, vl); 1351a2482d2cSFlorian Fainelli 1352c499696eSFlorian Fainelli vl->members |= BIT(port); 1353ca893194SFlorian Fainelli if (untagged && !dsa_is_cpu_port(ds, port)) 1354e47112d9SFlorian Fainelli vl->untag |= BIT(port); 1355a2482d2cSFlorian Fainelli else 1356e47112d9SFlorian Fainelli vl->untag &= ~BIT(port); 1357a2482d2cSFlorian Fainelli 1358a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, vid, vl); 1359a2482d2cSFlorian Fainelli b53_fast_age_vlan(dev, vid); 1360a2482d2cSFlorian Fainelli } 1361a2482d2cSFlorian Fainelli 1362a2482d2cSFlorian Fainelli if (pvid) { 1363a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), 1364a2482d2cSFlorian Fainelli vlan->vid_end); 1365a2482d2cSFlorian Fainelli b53_fast_age_vlan(dev, vid); 1366a2482d2cSFlorian Fainelli } 1367a2482d2cSFlorian Fainelli } 13683117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_add); 1369a2482d2cSFlorian Fainelli 13703117455dSFlorian Fainelli int b53_vlan_del(struct dsa_switch *ds, int port, 1371a2482d2cSFlorian Fainelli const struct switchdev_obj_port_vlan *vlan) 1372a2482d2cSFlorian Fainelli { 137304bed143SVivien Didelot struct b53_device *dev = ds->priv; 1374a2482d2cSFlorian Fainelli bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; 1375a2482d2cSFlorian Fainelli struct b53_vlan *vl; 1376a2482d2cSFlorian Fainelli u16 vid; 1377a2482d2cSFlorian Fainelli u16 pvid; 1378a2482d2cSFlorian Fainelli 1379a2482d2cSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid); 1380a2482d2cSFlorian Fainelli 1381a2482d2cSFlorian Fainelli for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) { 1382a2482d2cSFlorian Fainelli vl = &dev->vlans[vid]; 1383a2482d2cSFlorian Fainelli 1384a2482d2cSFlorian Fainelli b53_get_vlan_entry(dev, vid, vl); 1385a2482d2cSFlorian Fainelli 1386a2482d2cSFlorian Fainelli vl->members &= ~BIT(port); 1387a2482d2cSFlorian Fainelli 1388fea83353SFlorian Fainelli if (pvid == vid) 1389fea83353SFlorian Fainelli pvid = b53_default_pvid(dev); 1390a2482d2cSFlorian Fainelli 1391ca893194SFlorian Fainelli if (untagged && !dsa_is_cpu_port(ds, port)) 1392a2482d2cSFlorian Fainelli vl->untag &= ~(BIT(port)); 1393a2482d2cSFlorian Fainelli 1394a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, vid, vl); 1395a2482d2cSFlorian Fainelli b53_fast_age_vlan(dev, vid); 1396a2482d2cSFlorian Fainelli } 1397a2482d2cSFlorian Fainelli 1398a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), pvid); 1399a2482d2cSFlorian Fainelli b53_fast_age_vlan(dev, pvid); 1400a2482d2cSFlorian Fainelli 1401a2482d2cSFlorian Fainelli return 0; 1402a2482d2cSFlorian Fainelli } 14033117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_del); 1404a2482d2cSFlorian Fainelli 14051da6df85SFlorian Fainelli /* Address Resolution Logic routines */ 14061da6df85SFlorian Fainelli static int b53_arl_op_wait(struct b53_device *dev) 14071da6df85SFlorian Fainelli { 14081da6df85SFlorian Fainelli unsigned int timeout = 10; 14091da6df85SFlorian Fainelli u8 reg; 14101da6df85SFlorian Fainelli 14111da6df85SFlorian Fainelli do { 14121da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, ®); 14131da6df85SFlorian Fainelli if (!(reg & ARLTBL_START_DONE)) 14141da6df85SFlorian Fainelli return 0; 14151da6df85SFlorian Fainelli 14161da6df85SFlorian Fainelli usleep_range(1000, 2000); 14171da6df85SFlorian Fainelli } while (timeout--); 14181da6df85SFlorian Fainelli 14191da6df85SFlorian Fainelli dev_warn(dev->dev, "timeout waiting for ARL to finish: 0x%02x\n", reg); 14201da6df85SFlorian Fainelli 14211da6df85SFlorian Fainelli return -ETIMEDOUT; 14221da6df85SFlorian Fainelli } 14231da6df85SFlorian Fainelli 14241da6df85SFlorian Fainelli static int b53_arl_rw_op(struct b53_device *dev, unsigned int op) 14251da6df85SFlorian Fainelli { 14261da6df85SFlorian Fainelli u8 reg; 14271da6df85SFlorian Fainelli 14281da6df85SFlorian Fainelli if (op > ARLTBL_RW) 14291da6df85SFlorian Fainelli return -EINVAL; 14301da6df85SFlorian Fainelli 14311da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, ®); 14321da6df85SFlorian Fainelli reg |= ARLTBL_START_DONE; 14331da6df85SFlorian Fainelli if (op) 14341da6df85SFlorian Fainelli reg |= ARLTBL_RW; 14351da6df85SFlorian Fainelli else 14361da6df85SFlorian Fainelli reg &= ~ARLTBL_RW; 14371da6df85SFlorian Fainelli b53_write8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, reg); 14381da6df85SFlorian Fainelli 14391da6df85SFlorian Fainelli return b53_arl_op_wait(dev); 14401da6df85SFlorian Fainelli } 14411da6df85SFlorian Fainelli 14421da6df85SFlorian Fainelli static int b53_arl_read(struct b53_device *dev, u64 mac, 14431da6df85SFlorian Fainelli u16 vid, struct b53_arl_entry *ent, u8 *idx, 14441da6df85SFlorian Fainelli bool is_valid) 14451da6df85SFlorian Fainelli { 14461da6df85SFlorian Fainelli unsigned int i; 14471da6df85SFlorian Fainelli int ret; 14481da6df85SFlorian Fainelli 14491da6df85SFlorian Fainelli ret = b53_arl_op_wait(dev); 14501da6df85SFlorian Fainelli if (ret) 14511da6df85SFlorian Fainelli return ret; 14521da6df85SFlorian Fainelli 14531da6df85SFlorian Fainelli /* Read the bins */ 14541da6df85SFlorian Fainelli for (i = 0; i < dev->num_arl_entries; i++) { 14551da6df85SFlorian Fainelli u64 mac_vid; 14561da6df85SFlorian Fainelli u32 fwd_entry; 14571da6df85SFlorian Fainelli 14581da6df85SFlorian Fainelli b53_read64(dev, B53_ARLIO_PAGE, 14591da6df85SFlorian Fainelli B53_ARLTBL_MAC_VID_ENTRY(i), &mac_vid); 14601da6df85SFlorian Fainelli b53_read32(dev, B53_ARLIO_PAGE, 14611da6df85SFlorian Fainelli B53_ARLTBL_DATA_ENTRY(i), &fwd_entry); 14621da6df85SFlorian Fainelli b53_arl_to_entry(ent, mac_vid, fwd_entry); 14631da6df85SFlorian Fainelli 14641da6df85SFlorian Fainelli if (!(fwd_entry & ARLTBL_VALID)) 14651da6df85SFlorian Fainelli continue; 14661da6df85SFlorian Fainelli if ((mac_vid & ARLTBL_MAC_MASK) != mac) 14671da6df85SFlorian Fainelli continue; 14681da6df85SFlorian Fainelli *idx = i; 14691da6df85SFlorian Fainelli } 14701da6df85SFlorian Fainelli 14711da6df85SFlorian Fainelli return -ENOENT; 14721da6df85SFlorian Fainelli } 14731da6df85SFlorian Fainelli 14741da6df85SFlorian Fainelli static int b53_arl_op(struct b53_device *dev, int op, int port, 14751da6df85SFlorian Fainelli const unsigned char *addr, u16 vid, bool is_valid) 14761da6df85SFlorian Fainelli { 14771da6df85SFlorian Fainelli struct b53_arl_entry ent; 14781da6df85SFlorian Fainelli u32 fwd_entry; 14791da6df85SFlorian Fainelli u64 mac, mac_vid = 0; 14801da6df85SFlorian Fainelli u8 idx = 0; 14811da6df85SFlorian Fainelli int ret; 14821da6df85SFlorian Fainelli 14831da6df85SFlorian Fainelli /* Convert the array into a 64-bit MAC */ 14844b92ea81SFlorian Fainelli mac = ether_addr_to_u64(addr); 14851da6df85SFlorian Fainelli 14861da6df85SFlorian Fainelli /* Perform a read for the given MAC and VID */ 14871da6df85SFlorian Fainelli b53_write48(dev, B53_ARLIO_PAGE, B53_MAC_ADDR_IDX, mac); 14881da6df85SFlorian Fainelli b53_write16(dev, B53_ARLIO_PAGE, B53_VLAN_ID_IDX, vid); 14891da6df85SFlorian Fainelli 14901da6df85SFlorian Fainelli /* Issue a read operation for this MAC */ 14911da6df85SFlorian Fainelli ret = b53_arl_rw_op(dev, 1); 14921da6df85SFlorian Fainelli if (ret) 14931da6df85SFlorian Fainelli return ret; 14941da6df85SFlorian Fainelli 14951da6df85SFlorian Fainelli ret = b53_arl_read(dev, mac, vid, &ent, &idx, is_valid); 14961da6df85SFlorian Fainelli /* If this is a read, just finish now */ 14971da6df85SFlorian Fainelli if (op) 14981da6df85SFlorian Fainelli return ret; 14991da6df85SFlorian Fainelli 15001da6df85SFlorian Fainelli /* We could not find a matching MAC, so reset to a new entry */ 15011da6df85SFlorian Fainelli if (ret) { 15021da6df85SFlorian Fainelli fwd_entry = 0; 15031da6df85SFlorian Fainelli idx = 1; 15041da6df85SFlorian Fainelli } 15051da6df85SFlorian Fainelli 15061da6df85SFlorian Fainelli memset(&ent, 0, sizeof(ent)); 15071da6df85SFlorian Fainelli ent.port = port; 15081da6df85SFlorian Fainelli ent.is_valid = is_valid; 15091da6df85SFlorian Fainelli ent.vid = vid; 15101da6df85SFlorian Fainelli ent.is_static = true; 15111da6df85SFlorian Fainelli memcpy(ent.mac, addr, ETH_ALEN); 15121da6df85SFlorian Fainelli b53_arl_from_entry(&mac_vid, &fwd_entry, &ent); 15131da6df85SFlorian Fainelli 15141da6df85SFlorian Fainelli b53_write64(dev, B53_ARLIO_PAGE, 15151da6df85SFlorian Fainelli B53_ARLTBL_MAC_VID_ENTRY(idx), mac_vid); 15161da6df85SFlorian Fainelli b53_write32(dev, B53_ARLIO_PAGE, 15171da6df85SFlorian Fainelli B53_ARLTBL_DATA_ENTRY(idx), fwd_entry); 15181da6df85SFlorian Fainelli 15191da6df85SFlorian Fainelli return b53_arl_rw_op(dev, 0); 15201da6df85SFlorian Fainelli } 15211da6df85SFlorian Fainelli 15221b6dd556SArkadi Sharshevsky int b53_fdb_add(struct dsa_switch *ds, int port, 15236c2c1dcbSArkadi Sharshevsky const unsigned char *addr, u16 vid) 15241da6df85SFlorian Fainelli { 152504bed143SVivien Didelot struct b53_device *priv = ds->priv; 15261da6df85SFlorian Fainelli 15271da6df85SFlorian Fainelli /* 5325 and 5365 require some more massaging, but could 15281da6df85SFlorian Fainelli * be supported eventually 15291da6df85SFlorian Fainelli */ 15301da6df85SFlorian Fainelli if (is5325(priv) || is5365(priv)) 15311da6df85SFlorian Fainelli return -EOPNOTSUPP; 15321da6df85SFlorian Fainelli 15331b6dd556SArkadi Sharshevsky return b53_arl_op(priv, 0, port, addr, vid, true); 15341da6df85SFlorian Fainelli } 15353117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_add); 15361da6df85SFlorian Fainelli 15373117455dSFlorian Fainelli int b53_fdb_del(struct dsa_switch *ds, int port, 15386c2c1dcbSArkadi Sharshevsky const unsigned char *addr, u16 vid) 15391da6df85SFlorian Fainelli { 154004bed143SVivien Didelot struct b53_device *priv = ds->priv; 15411da6df85SFlorian Fainelli 15426c2c1dcbSArkadi Sharshevsky return b53_arl_op(priv, 0, port, addr, vid, false); 15431da6df85SFlorian Fainelli } 15443117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_del); 15451da6df85SFlorian Fainelli 15461da6df85SFlorian Fainelli static int b53_arl_search_wait(struct b53_device *dev) 15471da6df85SFlorian Fainelli { 15481da6df85SFlorian Fainelli unsigned int timeout = 1000; 15491da6df85SFlorian Fainelli u8 reg; 15501da6df85SFlorian Fainelli 15511da6df85SFlorian Fainelli do { 15521da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, ®); 15531da6df85SFlorian Fainelli if (!(reg & ARL_SRCH_STDN)) 15541da6df85SFlorian Fainelli return 0; 15551da6df85SFlorian Fainelli 15561da6df85SFlorian Fainelli if (reg & ARL_SRCH_VLID) 15571da6df85SFlorian Fainelli return 0; 15581da6df85SFlorian Fainelli 15591da6df85SFlorian Fainelli usleep_range(1000, 2000); 15601da6df85SFlorian Fainelli } while (timeout--); 15611da6df85SFlorian Fainelli 15621da6df85SFlorian Fainelli return -ETIMEDOUT; 15631da6df85SFlorian Fainelli } 15641da6df85SFlorian Fainelli 15651da6df85SFlorian Fainelli static void b53_arl_search_rd(struct b53_device *dev, u8 idx, 15661da6df85SFlorian Fainelli struct b53_arl_entry *ent) 15671da6df85SFlorian Fainelli { 15681da6df85SFlorian Fainelli u64 mac_vid; 15691da6df85SFlorian Fainelli u32 fwd_entry; 15701da6df85SFlorian Fainelli 15711da6df85SFlorian Fainelli b53_read64(dev, B53_ARLIO_PAGE, 15721da6df85SFlorian Fainelli B53_ARL_SRCH_RSTL_MACVID(idx), &mac_vid); 15731da6df85SFlorian Fainelli b53_read32(dev, B53_ARLIO_PAGE, 15741da6df85SFlorian Fainelli B53_ARL_SRCH_RSTL(idx), &fwd_entry); 15751da6df85SFlorian Fainelli b53_arl_to_entry(ent, mac_vid, fwd_entry); 15761da6df85SFlorian Fainelli } 15771da6df85SFlorian Fainelli 1578e6cbef0cSVivien Didelot static int b53_fdb_copy(int port, const struct b53_arl_entry *ent, 15792bedde1aSArkadi Sharshevsky dsa_fdb_dump_cb_t *cb, void *data) 15801da6df85SFlorian Fainelli { 15811da6df85SFlorian Fainelli if (!ent->is_valid) 15821da6df85SFlorian Fainelli return 0; 15831da6df85SFlorian Fainelli 15841da6df85SFlorian Fainelli if (port != ent->port) 15851da6df85SFlorian Fainelli return 0; 15861da6df85SFlorian Fainelli 15872bedde1aSArkadi Sharshevsky return cb(ent->mac, ent->vid, ent->is_static, data); 15881da6df85SFlorian Fainelli } 15891da6df85SFlorian Fainelli 15903117455dSFlorian Fainelli int b53_fdb_dump(struct dsa_switch *ds, int port, 15912bedde1aSArkadi Sharshevsky dsa_fdb_dump_cb_t *cb, void *data) 15921da6df85SFlorian Fainelli { 159304bed143SVivien Didelot struct b53_device *priv = ds->priv; 15941da6df85SFlorian Fainelli struct b53_arl_entry results[2]; 15951da6df85SFlorian Fainelli unsigned int count = 0; 15961da6df85SFlorian Fainelli int ret; 15971da6df85SFlorian Fainelli u8 reg; 15981da6df85SFlorian Fainelli 15991da6df85SFlorian Fainelli /* Start search operation */ 16001da6df85SFlorian Fainelli reg = ARL_SRCH_STDN; 16011da6df85SFlorian Fainelli b53_write8(priv, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, reg); 16021da6df85SFlorian Fainelli 16031da6df85SFlorian Fainelli do { 16041da6df85SFlorian Fainelli ret = b53_arl_search_wait(priv); 16051da6df85SFlorian Fainelli if (ret) 16061da6df85SFlorian Fainelli return ret; 16071da6df85SFlorian Fainelli 16081da6df85SFlorian Fainelli b53_arl_search_rd(priv, 0, &results[0]); 16092bedde1aSArkadi Sharshevsky ret = b53_fdb_copy(port, &results[0], cb, data); 16101da6df85SFlorian Fainelli if (ret) 16111da6df85SFlorian Fainelli return ret; 16121da6df85SFlorian Fainelli 16131da6df85SFlorian Fainelli if (priv->num_arl_entries > 2) { 16141da6df85SFlorian Fainelli b53_arl_search_rd(priv, 1, &results[1]); 16152bedde1aSArkadi Sharshevsky ret = b53_fdb_copy(port, &results[1], cb, data); 16161da6df85SFlorian Fainelli if (ret) 16171da6df85SFlorian Fainelli return ret; 16181da6df85SFlorian Fainelli 16191da6df85SFlorian Fainelli if (!results[0].is_valid && !results[1].is_valid) 16201da6df85SFlorian Fainelli break; 16211da6df85SFlorian Fainelli } 16221da6df85SFlorian Fainelli 16231da6df85SFlorian Fainelli } while (count++ < 1024); 16241da6df85SFlorian Fainelli 16251da6df85SFlorian Fainelli return 0; 16261da6df85SFlorian Fainelli } 16273117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_dump); 16281da6df85SFlorian Fainelli 1629ddd3a0c8SVivien Didelot int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br) 1630ff39c2d6SFlorian Fainelli { 163104bed143SVivien Didelot struct b53_device *dev = ds->priv; 16320abfd494SVivien Didelot s8 cpu_port = ds->ports[port].cpu_dp->index; 1633ff39c2d6SFlorian Fainelli u16 pvlan, reg; 1634ff39c2d6SFlorian Fainelli unsigned int i; 1635ff39c2d6SFlorian Fainelli 163648aea33aSFlorian Fainelli /* Make this port leave the all VLANs join since we will have proper 163748aea33aSFlorian Fainelli * VLAN entries from now on 163848aea33aSFlorian Fainelli */ 163948aea33aSFlorian Fainelli if (is58xx(dev)) { 164048aea33aSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, ®); 164148aea33aSFlorian Fainelli reg &= ~BIT(port); 164248aea33aSFlorian Fainelli if ((reg & BIT(cpu_port)) == BIT(cpu_port)) 164348aea33aSFlorian Fainelli reg &= ~BIT(cpu_port); 164448aea33aSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg); 164548aea33aSFlorian Fainelli } 164648aea33aSFlorian Fainelli 1647ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); 1648ff39c2d6SFlorian Fainelli 1649ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) { 1650c8652c83SVivien Didelot if (dsa_to_port(ds, i)->bridge_dev != br) 1651ff39c2d6SFlorian Fainelli continue; 1652ff39c2d6SFlorian Fainelli 1653ff39c2d6SFlorian Fainelli /* Add this local port to the remote port VLAN control 1654ff39c2d6SFlorian Fainelli * membership and update the remote port bitmask 1655ff39c2d6SFlorian Fainelli */ 1656ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), ®); 1657ff39c2d6SFlorian Fainelli reg |= BIT(port); 1658ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg); 1659ff39c2d6SFlorian Fainelli dev->ports[i].vlan_ctl_mask = reg; 1660ff39c2d6SFlorian Fainelli 1661ff39c2d6SFlorian Fainelli pvlan |= BIT(i); 1662ff39c2d6SFlorian Fainelli } 1663ff39c2d6SFlorian Fainelli 1664ff39c2d6SFlorian Fainelli /* Configure the local port VLAN control membership to include 1665ff39c2d6SFlorian Fainelli * remote ports and update the local port bitmask 1666ff39c2d6SFlorian Fainelli */ 1667ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); 1668ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = pvlan; 1669ff39c2d6SFlorian Fainelli 1670ff39c2d6SFlorian Fainelli return 0; 1671ff39c2d6SFlorian Fainelli } 16723117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_join); 1673ff39c2d6SFlorian Fainelli 1674f123f2fbSVivien Didelot void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *br) 1675ff39c2d6SFlorian Fainelli { 167604bed143SVivien Didelot struct b53_device *dev = ds->priv; 1677a2482d2cSFlorian Fainelli struct b53_vlan *vl = &dev->vlans[0]; 16780abfd494SVivien Didelot s8 cpu_port = ds->ports[port].cpu_dp->index; 1679ff39c2d6SFlorian Fainelli unsigned int i; 1680a2482d2cSFlorian Fainelli u16 pvlan, reg, pvid; 1681ff39c2d6SFlorian Fainelli 1682ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); 1683ff39c2d6SFlorian Fainelli 1684ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) { 1685ff39c2d6SFlorian Fainelli /* Don't touch the remaining ports */ 1686c8652c83SVivien Didelot if (dsa_to_port(ds, i)->bridge_dev != br) 1687ff39c2d6SFlorian Fainelli continue; 1688ff39c2d6SFlorian Fainelli 1689ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), ®); 1690ff39c2d6SFlorian Fainelli reg &= ~BIT(port); 1691ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg); 1692ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = reg; 1693ff39c2d6SFlorian Fainelli 1694ff39c2d6SFlorian Fainelli /* Prevent self removal to preserve isolation */ 1695ff39c2d6SFlorian Fainelli if (port != i) 1696ff39c2d6SFlorian Fainelli pvlan &= ~BIT(i); 1697ff39c2d6SFlorian Fainelli } 1698ff39c2d6SFlorian Fainelli 1699ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); 1700ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = pvlan; 1701a2482d2cSFlorian Fainelli 1702fea83353SFlorian Fainelli pvid = b53_default_pvid(dev); 1703a2482d2cSFlorian Fainelli 170448aea33aSFlorian Fainelli /* Make this port join all VLANs without VLAN entries */ 170548aea33aSFlorian Fainelli if (is58xx(dev)) { 170648aea33aSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, ®); 170748aea33aSFlorian Fainelli reg |= BIT(port); 170848aea33aSFlorian Fainelli if (!(reg & BIT(cpu_port))) 170948aea33aSFlorian Fainelli reg |= BIT(cpu_port); 171048aea33aSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg); 171148aea33aSFlorian Fainelli } else { 1712a2482d2cSFlorian Fainelli b53_get_vlan_entry(dev, pvid, vl); 1713c499696eSFlorian Fainelli vl->members |= BIT(port) | BIT(cpu_port); 1714c499696eSFlorian Fainelli vl->untag |= BIT(port) | BIT(cpu_port); 1715a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, pvid, vl); 1716ff39c2d6SFlorian Fainelli } 171748aea33aSFlorian Fainelli } 17183117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_leave); 1719ff39c2d6SFlorian Fainelli 17203117455dSFlorian Fainelli void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state) 1721ff39c2d6SFlorian Fainelli { 172204bed143SVivien Didelot struct b53_device *dev = ds->priv; 1723597698f1SVivien Didelot u8 hw_state; 1724ff39c2d6SFlorian Fainelli u8 reg; 1725ff39c2d6SFlorian Fainelli 1726ff39c2d6SFlorian Fainelli switch (state) { 1727ff39c2d6SFlorian Fainelli case BR_STATE_DISABLED: 1728ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_DIS_STATE; 1729ff39c2d6SFlorian Fainelli break; 1730ff39c2d6SFlorian Fainelli case BR_STATE_LISTENING: 1731ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_LISTEN_STATE; 1732ff39c2d6SFlorian Fainelli break; 1733ff39c2d6SFlorian Fainelli case BR_STATE_LEARNING: 1734ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_LEARN_STATE; 1735ff39c2d6SFlorian Fainelli break; 1736ff39c2d6SFlorian Fainelli case BR_STATE_FORWARDING: 1737ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_FWD_STATE; 1738ff39c2d6SFlorian Fainelli break; 1739ff39c2d6SFlorian Fainelli case BR_STATE_BLOCKING: 1740ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_BLOCK_STATE; 1741ff39c2d6SFlorian Fainelli break; 1742ff39c2d6SFlorian Fainelli default: 1743ff39c2d6SFlorian Fainelli dev_err(ds->dev, "invalid STP state: %d\n", state); 1744ff39c2d6SFlorian Fainelli return; 1745ff39c2d6SFlorian Fainelli } 1746ff39c2d6SFlorian Fainelli 1747ff39c2d6SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), ®); 1748ff39c2d6SFlorian Fainelli reg &= ~PORT_CTRL_STP_STATE_MASK; 1749ff39c2d6SFlorian Fainelli reg |= hw_state; 1750ff39c2d6SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg); 1751ff39c2d6SFlorian Fainelli } 17523117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_set_stp_state); 1753ff39c2d6SFlorian Fainelli 17543117455dSFlorian Fainelli void b53_br_fast_age(struct dsa_switch *ds, int port) 1755597698f1SVivien Didelot { 1756597698f1SVivien Didelot struct b53_device *dev = ds->priv; 1757597698f1SVivien Didelot 1758597698f1SVivien Didelot if (b53_fast_age_port(dev, port)) 1759597698f1SVivien Didelot dev_err(ds->dev, "fast ageing failed\n"); 1760597698f1SVivien Didelot } 17613117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_fast_age); 1762597698f1SVivien Didelot 1763c7d28c9dSFlorian Fainelli static bool b53_possible_cpu_port(struct dsa_switch *ds, int port) 17647edc58d6SFlorian Fainelli { 17657edc58d6SFlorian Fainelli /* Broadcom switches will accept enabling Broadcom tags on the 17667edc58d6SFlorian Fainelli * following ports: 5, 7 and 8, any other port is not supported 17677edc58d6SFlorian Fainelli */ 17685ed4e3ebSFlorian Fainelli switch (port) { 17695ed4e3ebSFlorian Fainelli case B53_CPU_PORT_25: 17705ed4e3ebSFlorian Fainelli case 7: 17715ed4e3ebSFlorian Fainelli case B53_CPU_PORT: 17727edc58d6SFlorian Fainelli return true; 17737edc58d6SFlorian Fainelli } 17747edc58d6SFlorian Fainelli 17755ed4e3ebSFlorian Fainelli return false; 17765ed4e3ebSFlorian Fainelli } 17775ed4e3ebSFlorian Fainelli 1778c7d28c9dSFlorian Fainelli static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port) 1779c7d28c9dSFlorian Fainelli { 1780c7d28c9dSFlorian Fainelli bool ret = b53_possible_cpu_port(ds, port); 1781c7d28c9dSFlorian Fainelli 1782c7d28c9dSFlorian Fainelli if (!ret) 1783c7d28c9dSFlorian Fainelli dev_warn(ds->dev, "Port %d is not Broadcom tag capable\n", 1784c7d28c9dSFlorian Fainelli port); 1785c7d28c9dSFlorian Fainelli return ret; 1786c7d28c9dSFlorian Fainelli } 1787c7d28c9dSFlorian Fainelli 17889f66816aSFlorian Fainelli enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port) 17897b314362SAndrew Lunn { 17907edc58d6SFlorian Fainelli struct b53_device *dev = ds->priv; 17917edc58d6SFlorian Fainelli 179254e98b5dSFlorian Fainelli /* Older models (5325, 5365) support a different tag format that we do 179354e98b5dSFlorian Fainelli * not support in net/dsa/tag_brcm.c yet. 539x and 531x5 require managed 179454e98b5dSFlorian Fainelli * mode to be turned on which means we need to specifically manage ARL 179554e98b5dSFlorian Fainelli * misses on multicast addresses (TBD). 17967edc58d6SFlorian Fainelli */ 179754e98b5dSFlorian Fainelli if (is5325(dev) || is5365(dev) || is539x(dev) || is531x5(dev) || 179854e98b5dSFlorian Fainelli !b53_can_enable_brcm_tags(ds, port)) 17997b314362SAndrew Lunn return DSA_TAG_PROTO_NONE; 180011606039SFlorian Fainelli 180111606039SFlorian Fainelli /* Broadcom BCM58xx chips have a flow accelerator on Port 8 180211606039SFlorian Fainelli * which requires us to use the prepended Broadcom tag type 180311606039SFlorian Fainelli */ 180411606039SFlorian Fainelli if (dev->chip_id == BCM58XX_DEVICE_ID && port == B53_CPU_PORT) 180511606039SFlorian Fainelli return DSA_TAG_PROTO_BRCM_PREPEND; 180611606039SFlorian Fainelli 18077edc58d6SFlorian Fainelli return DSA_TAG_PROTO_BRCM; 18087b314362SAndrew Lunn } 18099f66816aSFlorian Fainelli EXPORT_SYMBOL(b53_get_tag_protocol); 18107b314362SAndrew Lunn 1811ed3af5fdSFlorian Fainelli int b53_mirror_add(struct dsa_switch *ds, int port, 1812ed3af5fdSFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror, bool ingress) 1813ed3af5fdSFlorian Fainelli { 1814ed3af5fdSFlorian Fainelli struct b53_device *dev = ds->priv; 1815ed3af5fdSFlorian Fainelli u16 reg, loc; 1816ed3af5fdSFlorian Fainelli 1817ed3af5fdSFlorian Fainelli if (ingress) 1818ed3af5fdSFlorian Fainelli loc = B53_IG_MIR_CTL; 1819ed3af5fdSFlorian Fainelli else 1820ed3af5fdSFlorian Fainelli loc = B53_EG_MIR_CTL; 1821ed3af5fdSFlorian Fainelli 1822ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, loc, ®); 1823ed3af5fdSFlorian Fainelli reg &= ~MIRROR_MASK; 1824ed3af5fdSFlorian Fainelli reg |= BIT(port); 1825ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, loc, reg); 1826ed3af5fdSFlorian Fainelli 1827ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®); 1828ed3af5fdSFlorian Fainelli reg &= ~CAP_PORT_MASK; 1829ed3af5fdSFlorian Fainelli reg |= mirror->to_local_port; 1830ed3af5fdSFlorian Fainelli reg |= MIRROR_EN; 1831ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg); 1832ed3af5fdSFlorian Fainelli 1833ed3af5fdSFlorian Fainelli return 0; 1834ed3af5fdSFlorian Fainelli } 1835ed3af5fdSFlorian Fainelli EXPORT_SYMBOL(b53_mirror_add); 1836ed3af5fdSFlorian Fainelli 1837ed3af5fdSFlorian Fainelli void b53_mirror_del(struct dsa_switch *ds, int port, 1838ed3af5fdSFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror) 1839ed3af5fdSFlorian Fainelli { 1840ed3af5fdSFlorian Fainelli struct b53_device *dev = ds->priv; 1841ed3af5fdSFlorian Fainelli bool loc_disable = false, other_loc_disable = false; 1842ed3af5fdSFlorian Fainelli u16 reg, loc; 1843ed3af5fdSFlorian Fainelli 1844ed3af5fdSFlorian Fainelli if (mirror->ingress) 1845ed3af5fdSFlorian Fainelli loc = B53_IG_MIR_CTL; 1846ed3af5fdSFlorian Fainelli else 1847ed3af5fdSFlorian Fainelli loc = B53_EG_MIR_CTL; 1848ed3af5fdSFlorian Fainelli 1849ed3af5fdSFlorian Fainelli /* Update the desired ingress/egress register */ 1850ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, loc, ®); 1851ed3af5fdSFlorian Fainelli reg &= ~BIT(port); 1852ed3af5fdSFlorian Fainelli if (!(reg & MIRROR_MASK)) 1853ed3af5fdSFlorian Fainelli loc_disable = true; 1854ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, loc, reg); 1855ed3af5fdSFlorian Fainelli 1856ed3af5fdSFlorian Fainelli /* Now look at the other one to know if we can disable mirroring 1857ed3af5fdSFlorian Fainelli * entirely 1858ed3af5fdSFlorian Fainelli */ 1859ed3af5fdSFlorian Fainelli if (mirror->ingress) 1860ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_EG_MIR_CTL, ®); 1861ed3af5fdSFlorian Fainelli else 1862ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_IG_MIR_CTL, ®); 1863ed3af5fdSFlorian Fainelli if (!(reg & MIRROR_MASK)) 1864ed3af5fdSFlorian Fainelli other_loc_disable = true; 1865ed3af5fdSFlorian Fainelli 1866ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®); 1867ed3af5fdSFlorian Fainelli /* Both no longer have ports, let's disable mirroring */ 1868ed3af5fdSFlorian Fainelli if (loc_disable && other_loc_disable) { 1869ed3af5fdSFlorian Fainelli reg &= ~MIRROR_EN; 1870ed3af5fdSFlorian Fainelli reg &= ~mirror->to_local_port; 1871ed3af5fdSFlorian Fainelli } 1872ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg); 1873ed3af5fdSFlorian Fainelli } 1874ed3af5fdSFlorian Fainelli EXPORT_SYMBOL(b53_mirror_del); 1875ed3af5fdSFlorian Fainelli 187622256b0aSFlorian Fainelli void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable) 187722256b0aSFlorian Fainelli { 187822256b0aSFlorian Fainelli struct b53_device *dev = ds->priv; 187922256b0aSFlorian Fainelli u16 reg; 188022256b0aSFlorian Fainelli 188122256b0aSFlorian Fainelli b53_read16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, ®); 188222256b0aSFlorian Fainelli if (enable) 188322256b0aSFlorian Fainelli reg |= BIT(port); 188422256b0aSFlorian Fainelli else 188522256b0aSFlorian Fainelli reg &= ~BIT(port); 188622256b0aSFlorian Fainelli b53_write16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, reg); 188722256b0aSFlorian Fainelli } 188822256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_eee_enable_set); 188922256b0aSFlorian Fainelli 189022256b0aSFlorian Fainelli 189122256b0aSFlorian Fainelli /* Returns 0 if EEE was not enabled, or 1 otherwise 189222256b0aSFlorian Fainelli */ 189322256b0aSFlorian Fainelli int b53_eee_init(struct dsa_switch *ds, int port, struct phy_device *phy) 189422256b0aSFlorian Fainelli { 189522256b0aSFlorian Fainelli int ret; 189622256b0aSFlorian Fainelli 189722256b0aSFlorian Fainelli ret = phy_init_eee(phy, 0); 189822256b0aSFlorian Fainelli if (ret) 189922256b0aSFlorian Fainelli return 0; 190022256b0aSFlorian Fainelli 190122256b0aSFlorian Fainelli b53_eee_enable_set(ds, port, true); 190222256b0aSFlorian Fainelli 190322256b0aSFlorian Fainelli return 1; 190422256b0aSFlorian Fainelli } 190522256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_eee_init); 190622256b0aSFlorian Fainelli 190722256b0aSFlorian Fainelli int b53_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e) 190822256b0aSFlorian Fainelli { 190922256b0aSFlorian Fainelli struct b53_device *dev = ds->priv; 191022256b0aSFlorian Fainelli struct ethtool_eee *p = &dev->ports[port].eee; 191122256b0aSFlorian Fainelli u16 reg; 191222256b0aSFlorian Fainelli 191322256b0aSFlorian Fainelli if (is5325(dev) || is5365(dev)) 191422256b0aSFlorian Fainelli return -EOPNOTSUPP; 191522256b0aSFlorian Fainelli 191622256b0aSFlorian Fainelli b53_read16(dev, B53_EEE_PAGE, B53_EEE_LPI_INDICATE, ®); 191722256b0aSFlorian Fainelli e->eee_enabled = p->eee_enabled; 191822256b0aSFlorian Fainelli e->eee_active = !!(reg & BIT(port)); 191922256b0aSFlorian Fainelli 192022256b0aSFlorian Fainelli return 0; 192122256b0aSFlorian Fainelli } 192222256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_get_mac_eee); 192322256b0aSFlorian Fainelli 192422256b0aSFlorian Fainelli int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e) 192522256b0aSFlorian Fainelli { 192622256b0aSFlorian Fainelli struct b53_device *dev = ds->priv; 192722256b0aSFlorian Fainelli struct ethtool_eee *p = &dev->ports[port].eee; 192822256b0aSFlorian Fainelli 192922256b0aSFlorian Fainelli if (is5325(dev) || is5365(dev)) 193022256b0aSFlorian Fainelli return -EOPNOTSUPP; 193122256b0aSFlorian Fainelli 193222256b0aSFlorian Fainelli p->eee_enabled = e->eee_enabled; 193322256b0aSFlorian Fainelli b53_eee_enable_set(ds, port, e->eee_enabled); 193422256b0aSFlorian Fainelli 193522256b0aSFlorian Fainelli return 0; 193622256b0aSFlorian Fainelli } 193722256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_set_mac_eee); 193822256b0aSFlorian Fainelli 1939a82f67afSFlorian Fainelli static const struct dsa_switch_ops b53_switch_ops = { 19407b314362SAndrew Lunn .get_tag_protocol = b53_get_tag_protocol, 1941967dd82fSFlorian Fainelli .setup = b53_setup, 1942967dd82fSFlorian Fainelli .get_strings = b53_get_strings, 1943967dd82fSFlorian Fainelli .get_ethtool_stats = b53_get_ethtool_stats, 1944967dd82fSFlorian Fainelli .get_sset_count = b53_get_sset_count, 1945c7d28c9dSFlorian Fainelli .get_ethtool_phy_stats = b53_get_ethtool_phy_stats, 1946967dd82fSFlorian Fainelli .phy_read = b53_phy_read16, 1947967dd82fSFlorian Fainelli .phy_write = b53_phy_write16, 1948967dd82fSFlorian Fainelli .adjust_link = b53_adjust_link, 1949a8e8b985SFlorian Fainelli .phylink_validate = b53_phylink_validate, 1950a8e8b985SFlorian Fainelli .phylink_mac_link_state = b53_phylink_mac_link_state, 1951a8e8b985SFlorian Fainelli .phylink_mac_config = b53_phylink_mac_config, 1952a8e8b985SFlorian Fainelli .phylink_mac_an_restart = b53_phylink_mac_an_restart, 1953a8e8b985SFlorian Fainelli .phylink_mac_link_down = b53_phylink_mac_link_down, 1954a8e8b985SFlorian Fainelli .phylink_mac_link_up = b53_phylink_mac_link_up, 1955967dd82fSFlorian Fainelli .port_enable = b53_enable_port, 1956967dd82fSFlorian Fainelli .port_disable = b53_disable_port, 1957f43a2dbeSFlorian Fainelli .get_mac_eee = b53_get_mac_eee, 1958f43a2dbeSFlorian Fainelli .set_mac_eee = b53_set_mac_eee, 1959ff39c2d6SFlorian Fainelli .port_bridge_join = b53_br_join, 1960ff39c2d6SFlorian Fainelli .port_bridge_leave = b53_br_leave, 1961ff39c2d6SFlorian Fainelli .port_stp_state_set = b53_br_set_stp_state, 1962597698f1SVivien Didelot .port_fast_age = b53_br_fast_age, 1963a2482d2cSFlorian Fainelli .port_vlan_filtering = b53_vlan_filtering, 1964a2482d2cSFlorian Fainelli .port_vlan_prepare = b53_vlan_prepare, 1965a2482d2cSFlorian Fainelli .port_vlan_add = b53_vlan_add, 1966a2482d2cSFlorian Fainelli .port_vlan_del = b53_vlan_del, 19671da6df85SFlorian Fainelli .port_fdb_dump = b53_fdb_dump, 19681da6df85SFlorian Fainelli .port_fdb_add = b53_fdb_add, 19691da6df85SFlorian Fainelli .port_fdb_del = b53_fdb_del, 1970ed3af5fdSFlorian Fainelli .port_mirror_add = b53_mirror_add, 1971ed3af5fdSFlorian Fainelli .port_mirror_del = b53_mirror_del, 1972967dd82fSFlorian Fainelli }; 1973967dd82fSFlorian Fainelli 1974967dd82fSFlorian Fainelli struct b53_chip_data { 1975967dd82fSFlorian Fainelli u32 chip_id; 1976967dd82fSFlorian Fainelli const char *dev_name; 1977967dd82fSFlorian Fainelli u16 vlans; 1978967dd82fSFlorian Fainelli u16 enabled_ports; 1979967dd82fSFlorian Fainelli u8 cpu_port; 1980967dd82fSFlorian Fainelli u8 vta_regs[3]; 19811da6df85SFlorian Fainelli u8 arl_entries; 1982967dd82fSFlorian Fainelli u8 duplex_reg; 1983967dd82fSFlorian Fainelli u8 jumbo_pm_reg; 1984967dd82fSFlorian Fainelli u8 jumbo_size_reg; 1985967dd82fSFlorian Fainelli }; 1986967dd82fSFlorian Fainelli 1987967dd82fSFlorian Fainelli #define B53_VTA_REGS \ 1988967dd82fSFlorian Fainelli { B53_VT_ACCESS, B53_VT_INDEX, B53_VT_ENTRY } 1989967dd82fSFlorian Fainelli #define B53_VTA_REGS_9798 \ 1990967dd82fSFlorian Fainelli { B53_VT_ACCESS_9798, B53_VT_INDEX_9798, B53_VT_ENTRY_9798 } 1991967dd82fSFlorian Fainelli #define B53_VTA_REGS_63XX \ 1992967dd82fSFlorian Fainelli { B53_VT_ACCESS_63XX, B53_VT_INDEX_63XX, B53_VT_ENTRY_63XX } 1993967dd82fSFlorian Fainelli 1994967dd82fSFlorian Fainelli static const struct b53_chip_data b53_switch_chips[] = { 1995967dd82fSFlorian Fainelli { 1996967dd82fSFlorian Fainelli .chip_id = BCM5325_DEVICE_ID, 1997967dd82fSFlorian Fainelli .dev_name = "BCM5325", 1998967dd82fSFlorian Fainelli .vlans = 16, 1999967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 20001da6df85SFlorian Fainelli .arl_entries = 2, 2001967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, 2002967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_FE, 2003967dd82fSFlorian Fainelli }, 2004967dd82fSFlorian Fainelli { 2005967dd82fSFlorian Fainelli .chip_id = BCM5365_DEVICE_ID, 2006967dd82fSFlorian Fainelli .dev_name = "BCM5365", 2007967dd82fSFlorian Fainelli .vlans = 256, 2008967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 20091da6df85SFlorian Fainelli .arl_entries = 2, 2010967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, 2011967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_FE, 2012967dd82fSFlorian Fainelli }, 2013967dd82fSFlorian Fainelli { 2014a95691bcSDamien Thébault .chip_id = BCM5389_DEVICE_ID, 2015a95691bcSDamien Thébault .dev_name = "BCM5389", 2016a95691bcSDamien Thébault .vlans = 4096, 2017a95691bcSDamien Thébault .enabled_ports = 0x1f, 2018a95691bcSDamien Thébault .arl_entries = 4, 2019a95691bcSDamien Thébault .cpu_port = B53_CPU_PORT, 2020a95691bcSDamien Thébault .vta_regs = B53_VTA_REGS, 2021a95691bcSDamien Thébault .duplex_reg = B53_DUPLEX_STAT_GE, 2022a95691bcSDamien Thébault .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2023a95691bcSDamien Thébault .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2024a95691bcSDamien Thébault }, 2025a95691bcSDamien Thébault { 2026967dd82fSFlorian Fainelli .chip_id = BCM5395_DEVICE_ID, 2027967dd82fSFlorian Fainelli .dev_name = "BCM5395", 2028967dd82fSFlorian Fainelli .vlans = 4096, 2029967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 20301da6df85SFlorian Fainelli .arl_entries = 4, 2031967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2032967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2033967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2034967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2035967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2036967dd82fSFlorian Fainelli }, 2037967dd82fSFlorian Fainelli { 2038967dd82fSFlorian Fainelli .chip_id = BCM5397_DEVICE_ID, 2039967dd82fSFlorian Fainelli .dev_name = "BCM5397", 2040967dd82fSFlorian Fainelli .vlans = 4096, 2041967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 20421da6df85SFlorian Fainelli .arl_entries = 4, 2043967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2044967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_9798, 2045967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2046967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2047967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2048967dd82fSFlorian Fainelli }, 2049967dd82fSFlorian Fainelli { 2050967dd82fSFlorian Fainelli .chip_id = BCM5398_DEVICE_ID, 2051967dd82fSFlorian Fainelli .dev_name = "BCM5398", 2052967dd82fSFlorian Fainelli .vlans = 4096, 2053967dd82fSFlorian Fainelli .enabled_ports = 0x7f, 20541da6df85SFlorian Fainelli .arl_entries = 4, 2055967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2056967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_9798, 2057967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2058967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2059967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2060967dd82fSFlorian Fainelli }, 2061967dd82fSFlorian Fainelli { 2062967dd82fSFlorian Fainelli .chip_id = BCM53115_DEVICE_ID, 2063967dd82fSFlorian Fainelli .dev_name = "BCM53115", 2064967dd82fSFlorian Fainelli .vlans = 4096, 2065967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 20661da6df85SFlorian Fainelli .arl_entries = 4, 2067967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2068967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2069967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2070967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2071967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2072967dd82fSFlorian Fainelli }, 2073967dd82fSFlorian Fainelli { 2074967dd82fSFlorian Fainelli .chip_id = BCM53125_DEVICE_ID, 2075967dd82fSFlorian Fainelli .dev_name = "BCM53125", 2076967dd82fSFlorian Fainelli .vlans = 4096, 2077967dd82fSFlorian Fainelli .enabled_ports = 0xff, 2078be35e8c5SFlorian Fainelli .arl_entries = 4, 2079967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2080967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2081967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2082967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2083967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2084967dd82fSFlorian Fainelli }, 2085967dd82fSFlorian Fainelli { 2086967dd82fSFlorian Fainelli .chip_id = BCM53128_DEVICE_ID, 2087967dd82fSFlorian Fainelli .dev_name = "BCM53128", 2088967dd82fSFlorian Fainelli .vlans = 4096, 2089967dd82fSFlorian Fainelli .enabled_ports = 0x1ff, 20901da6df85SFlorian Fainelli .arl_entries = 4, 2091967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2092967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2093967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2094967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2095967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2096967dd82fSFlorian Fainelli }, 2097967dd82fSFlorian Fainelli { 2098967dd82fSFlorian Fainelli .chip_id = BCM63XX_DEVICE_ID, 2099967dd82fSFlorian Fainelli .dev_name = "BCM63xx", 2100967dd82fSFlorian Fainelli .vlans = 4096, 2101967dd82fSFlorian Fainelli .enabled_ports = 0, /* pdata must provide them */ 21021da6df85SFlorian Fainelli .arl_entries = 4, 2103967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2104967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_63XX, 2105967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_63XX, 2106967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK_63XX, 2107967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE_63XX, 2108967dd82fSFlorian Fainelli }, 2109967dd82fSFlorian Fainelli { 2110967dd82fSFlorian Fainelli .chip_id = BCM53010_DEVICE_ID, 2111967dd82fSFlorian Fainelli .dev_name = "BCM53010", 2112967dd82fSFlorian Fainelli .vlans = 4096, 2113967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 21141da6df85SFlorian Fainelli .arl_entries = 4, 2115967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2116967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2117967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2118967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2119967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2120967dd82fSFlorian Fainelli }, 2121967dd82fSFlorian Fainelli { 2122967dd82fSFlorian Fainelli .chip_id = BCM53011_DEVICE_ID, 2123967dd82fSFlorian Fainelli .dev_name = "BCM53011", 2124967dd82fSFlorian Fainelli .vlans = 4096, 2125967dd82fSFlorian Fainelli .enabled_ports = 0x1bf, 21261da6df85SFlorian Fainelli .arl_entries = 4, 2127967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2128967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2129967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2130967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2131967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2132967dd82fSFlorian Fainelli }, 2133967dd82fSFlorian Fainelli { 2134967dd82fSFlorian Fainelli .chip_id = BCM53012_DEVICE_ID, 2135967dd82fSFlorian Fainelli .dev_name = "BCM53012", 2136967dd82fSFlorian Fainelli .vlans = 4096, 2137967dd82fSFlorian Fainelli .enabled_ports = 0x1bf, 21381da6df85SFlorian Fainelli .arl_entries = 4, 2139967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2140967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2141967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2142967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2143967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2144967dd82fSFlorian Fainelli }, 2145967dd82fSFlorian Fainelli { 2146967dd82fSFlorian Fainelli .chip_id = BCM53018_DEVICE_ID, 2147967dd82fSFlorian Fainelli .dev_name = "BCM53018", 2148967dd82fSFlorian Fainelli .vlans = 4096, 2149967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 21501da6df85SFlorian Fainelli .arl_entries = 4, 2151967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2152967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2153967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2154967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2155967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2156967dd82fSFlorian Fainelli }, 2157967dd82fSFlorian Fainelli { 2158967dd82fSFlorian Fainelli .chip_id = BCM53019_DEVICE_ID, 2159967dd82fSFlorian Fainelli .dev_name = "BCM53019", 2160967dd82fSFlorian Fainelli .vlans = 4096, 2161967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 21621da6df85SFlorian Fainelli .arl_entries = 4, 2163967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2164967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2165967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2166967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2167967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2168967dd82fSFlorian Fainelli }, 2169991a36bbSFlorian Fainelli { 2170991a36bbSFlorian Fainelli .chip_id = BCM58XX_DEVICE_ID, 2171991a36bbSFlorian Fainelli .dev_name = "BCM585xx/586xx/88312", 2172991a36bbSFlorian Fainelli .vlans = 4096, 2173991a36bbSFlorian Fainelli .enabled_ports = 0x1ff, 2174991a36bbSFlorian Fainelli .arl_entries = 4, 2175bfcda65cSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2176991a36bbSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2177991a36bbSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2178991a36bbSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2179991a36bbSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2180991a36bbSFlorian Fainelli }, 2181130401d9SFlorian Fainelli { 21825040cc99SArun Parameswaran .chip_id = BCM583XX_DEVICE_ID, 21835040cc99SArun Parameswaran .dev_name = "BCM583xx/11360", 21845040cc99SArun Parameswaran .vlans = 4096, 21855040cc99SArun Parameswaran .enabled_ports = 0x103, 21865040cc99SArun Parameswaran .arl_entries = 4, 21875040cc99SArun Parameswaran .cpu_port = B53_CPU_PORT, 21885040cc99SArun Parameswaran .vta_regs = B53_VTA_REGS, 21895040cc99SArun Parameswaran .duplex_reg = B53_DUPLEX_STAT_GE, 21905040cc99SArun Parameswaran .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 21915040cc99SArun Parameswaran .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 21925040cc99SArun Parameswaran }, 21935040cc99SArun Parameswaran { 2194130401d9SFlorian Fainelli .chip_id = BCM7445_DEVICE_ID, 2195130401d9SFlorian Fainelli .dev_name = "BCM7445", 2196130401d9SFlorian Fainelli .vlans = 4096, 2197130401d9SFlorian Fainelli .enabled_ports = 0x1ff, 2198130401d9SFlorian Fainelli .arl_entries = 4, 2199130401d9SFlorian Fainelli .cpu_port = B53_CPU_PORT, 2200130401d9SFlorian Fainelli .vta_regs = B53_VTA_REGS, 2201130401d9SFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2202130401d9SFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2203130401d9SFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2204130401d9SFlorian Fainelli }, 22050fe99338SFlorian Fainelli { 22060fe99338SFlorian Fainelli .chip_id = BCM7278_DEVICE_ID, 22070fe99338SFlorian Fainelli .dev_name = "BCM7278", 22080fe99338SFlorian Fainelli .vlans = 4096, 22090fe99338SFlorian Fainelli .enabled_ports = 0x1ff, 22100fe99338SFlorian Fainelli .arl_entries= 4, 22110fe99338SFlorian Fainelli .cpu_port = B53_CPU_PORT, 22120fe99338SFlorian Fainelli .vta_regs = B53_VTA_REGS, 22130fe99338SFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 22140fe99338SFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 22150fe99338SFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 22160fe99338SFlorian Fainelli }, 2217967dd82fSFlorian Fainelli }; 2218967dd82fSFlorian Fainelli 2219967dd82fSFlorian Fainelli static int b53_switch_init(struct b53_device *dev) 2220967dd82fSFlorian Fainelli { 2221967dd82fSFlorian Fainelli unsigned int i; 2222967dd82fSFlorian Fainelli int ret; 2223967dd82fSFlorian Fainelli 2224967dd82fSFlorian Fainelli for (i = 0; i < ARRAY_SIZE(b53_switch_chips); i++) { 2225967dd82fSFlorian Fainelli const struct b53_chip_data *chip = &b53_switch_chips[i]; 2226967dd82fSFlorian Fainelli 2227967dd82fSFlorian Fainelli if (chip->chip_id == dev->chip_id) { 2228967dd82fSFlorian Fainelli if (!dev->enabled_ports) 2229967dd82fSFlorian Fainelli dev->enabled_ports = chip->enabled_ports; 2230967dd82fSFlorian Fainelli dev->name = chip->dev_name; 2231967dd82fSFlorian Fainelli dev->duplex_reg = chip->duplex_reg; 2232967dd82fSFlorian Fainelli dev->vta_regs[0] = chip->vta_regs[0]; 2233967dd82fSFlorian Fainelli dev->vta_regs[1] = chip->vta_regs[1]; 2234967dd82fSFlorian Fainelli dev->vta_regs[2] = chip->vta_regs[2]; 2235967dd82fSFlorian Fainelli dev->jumbo_pm_reg = chip->jumbo_pm_reg; 2236967dd82fSFlorian Fainelli dev->cpu_port = chip->cpu_port; 2237967dd82fSFlorian Fainelli dev->num_vlans = chip->vlans; 22381da6df85SFlorian Fainelli dev->num_arl_entries = chip->arl_entries; 2239967dd82fSFlorian Fainelli break; 2240967dd82fSFlorian Fainelli } 2241967dd82fSFlorian Fainelli } 2242967dd82fSFlorian Fainelli 2243967dd82fSFlorian Fainelli /* check which BCM5325x version we have */ 2244967dd82fSFlorian Fainelli if (is5325(dev)) { 2245967dd82fSFlorian Fainelli u8 vc4; 2246967dd82fSFlorian Fainelli 2247967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4); 2248967dd82fSFlorian Fainelli 2249967dd82fSFlorian Fainelli /* check reserved bits */ 2250967dd82fSFlorian Fainelli switch (vc4 & 3) { 2251967dd82fSFlorian Fainelli case 1: 2252967dd82fSFlorian Fainelli /* BCM5325E */ 2253967dd82fSFlorian Fainelli break; 2254967dd82fSFlorian Fainelli case 3: 2255967dd82fSFlorian Fainelli /* BCM5325F - do not use port 4 */ 2256967dd82fSFlorian Fainelli dev->enabled_ports &= ~BIT(4); 2257967dd82fSFlorian Fainelli break; 2258967dd82fSFlorian Fainelli default: 2259967dd82fSFlorian Fainelli /* On the BCM47XX SoCs this is the supported internal switch.*/ 2260967dd82fSFlorian Fainelli #ifndef CONFIG_BCM47XX 2261967dd82fSFlorian Fainelli /* BCM5325M */ 2262967dd82fSFlorian Fainelli return -EINVAL; 2263967dd82fSFlorian Fainelli #else 2264967dd82fSFlorian Fainelli break; 2265967dd82fSFlorian Fainelli #endif 2266967dd82fSFlorian Fainelli } 2267967dd82fSFlorian Fainelli } else if (dev->chip_id == BCM53115_DEVICE_ID) { 2268967dd82fSFlorian Fainelli u64 strap_value; 2269967dd82fSFlorian Fainelli 2270967dd82fSFlorian Fainelli b53_read48(dev, B53_STAT_PAGE, B53_STRAP_VALUE, &strap_value); 2271967dd82fSFlorian Fainelli /* use second IMP port if GMII is enabled */ 2272967dd82fSFlorian Fainelli if (strap_value & SV_GMII_CTRL_115) 2273967dd82fSFlorian Fainelli dev->cpu_port = 5; 2274967dd82fSFlorian Fainelli } 2275967dd82fSFlorian Fainelli 2276967dd82fSFlorian Fainelli /* cpu port is always last */ 2277967dd82fSFlorian Fainelli dev->num_ports = dev->cpu_port + 1; 2278967dd82fSFlorian Fainelli dev->enabled_ports |= BIT(dev->cpu_port); 2279967dd82fSFlorian Fainelli 2280c7d28c9dSFlorian Fainelli /* Include non standard CPU port built-in PHYs to be probed */ 2281c7d28c9dSFlorian Fainelli if (is539x(dev) || is531x5(dev)) { 2282c7d28c9dSFlorian Fainelli for (i = 0; i < dev->num_ports; i++) { 2283c7d28c9dSFlorian Fainelli if (!(dev->ds->phys_mii_mask & BIT(i)) && 2284c7d28c9dSFlorian Fainelli !b53_possible_cpu_port(dev->ds, i)) 2285c7d28c9dSFlorian Fainelli dev->ds->phys_mii_mask |= BIT(i); 2286c7d28c9dSFlorian Fainelli } 2287c7d28c9dSFlorian Fainelli } 2288c7d28c9dSFlorian Fainelli 2289a86854d0SKees Cook dev->ports = devm_kcalloc(dev->dev, 2290a86854d0SKees Cook dev->num_ports, sizeof(struct b53_port), 2291967dd82fSFlorian Fainelli GFP_KERNEL); 2292967dd82fSFlorian Fainelli if (!dev->ports) 2293967dd82fSFlorian Fainelli return -ENOMEM; 2294967dd82fSFlorian Fainelli 2295a86854d0SKees Cook dev->vlans = devm_kcalloc(dev->dev, 2296a86854d0SKees Cook dev->num_vlans, sizeof(struct b53_vlan), 2297a2482d2cSFlorian Fainelli GFP_KERNEL); 2298a2482d2cSFlorian Fainelli if (!dev->vlans) 2299a2482d2cSFlorian Fainelli return -ENOMEM; 2300a2482d2cSFlorian Fainelli 2301967dd82fSFlorian Fainelli dev->reset_gpio = b53_switch_get_reset_gpio(dev); 2302967dd82fSFlorian Fainelli if (dev->reset_gpio >= 0) { 2303967dd82fSFlorian Fainelli ret = devm_gpio_request_one(dev->dev, dev->reset_gpio, 2304967dd82fSFlorian Fainelli GPIOF_OUT_INIT_HIGH, "robo_reset"); 2305967dd82fSFlorian Fainelli if (ret) 2306967dd82fSFlorian Fainelli return ret; 2307967dd82fSFlorian Fainelli } 2308967dd82fSFlorian Fainelli 2309967dd82fSFlorian Fainelli return 0; 2310967dd82fSFlorian Fainelli } 2311967dd82fSFlorian Fainelli 23120dff88d3SJulia Lawall struct b53_device *b53_switch_alloc(struct device *base, 23130dff88d3SJulia Lawall const struct b53_io_ops *ops, 2314967dd82fSFlorian Fainelli void *priv) 2315967dd82fSFlorian Fainelli { 2316967dd82fSFlorian Fainelli struct dsa_switch *ds; 2317967dd82fSFlorian Fainelli struct b53_device *dev; 2318967dd82fSFlorian Fainelli 2319a0c02161SVivien Didelot ds = dsa_switch_alloc(base, DSA_MAX_PORTS); 2320967dd82fSFlorian Fainelli if (!ds) 2321967dd82fSFlorian Fainelli return NULL; 2322967dd82fSFlorian Fainelli 2323a0c02161SVivien Didelot dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL); 2324a0c02161SVivien Didelot if (!dev) 2325a0c02161SVivien Didelot return NULL; 2326967dd82fSFlorian Fainelli 2327967dd82fSFlorian Fainelli ds->priv = dev; 2328967dd82fSFlorian Fainelli dev->dev = base; 2329967dd82fSFlorian Fainelli 2330967dd82fSFlorian Fainelli dev->ds = ds; 2331967dd82fSFlorian Fainelli dev->priv = priv; 2332967dd82fSFlorian Fainelli dev->ops = ops; 2333485ebd61SFlorian Fainelli ds->ops = &b53_switch_ops; 2334967dd82fSFlorian Fainelli mutex_init(&dev->reg_mutex); 2335967dd82fSFlorian Fainelli mutex_init(&dev->stats_mutex); 2336967dd82fSFlorian Fainelli 2337967dd82fSFlorian Fainelli return dev; 2338967dd82fSFlorian Fainelli } 2339967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_alloc); 2340967dd82fSFlorian Fainelli 2341967dd82fSFlorian Fainelli int b53_switch_detect(struct b53_device *dev) 2342967dd82fSFlorian Fainelli { 2343967dd82fSFlorian Fainelli u32 id32; 2344967dd82fSFlorian Fainelli u16 tmp; 2345967dd82fSFlorian Fainelli u8 id8; 2346967dd82fSFlorian Fainelli int ret; 2347967dd82fSFlorian Fainelli 2348967dd82fSFlorian Fainelli ret = b53_read8(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id8); 2349967dd82fSFlorian Fainelli if (ret) 2350967dd82fSFlorian Fainelli return ret; 2351967dd82fSFlorian Fainelli 2352967dd82fSFlorian Fainelli switch (id8) { 2353967dd82fSFlorian Fainelli case 0: 2354967dd82fSFlorian Fainelli /* BCM5325 and BCM5365 do not have this register so reads 2355967dd82fSFlorian Fainelli * return 0. But the read operation did succeed, so assume this 2356967dd82fSFlorian Fainelli * is one of them. 2357967dd82fSFlorian Fainelli * 2358967dd82fSFlorian Fainelli * Next check if we can write to the 5325's VTA register; for 2359967dd82fSFlorian Fainelli * 5365 it is read only. 2360967dd82fSFlorian Fainelli */ 2361967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, 0xf); 2362967dd82fSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, &tmp); 2363967dd82fSFlorian Fainelli 2364967dd82fSFlorian Fainelli if (tmp == 0xf) 2365967dd82fSFlorian Fainelli dev->chip_id = BCM5325_DEVICE_ID; 2366967dd82fSFlorian Fainelli else 2367967dd82fSFlorian Fainelli dev->chip_id = BCM5365_DEVICE_ID; 2368967dd82fSFlorian Fainelli break; 2369a95691bcSDamien Thébault case BCM5389_DEVICE_ID: 2370967dd82fSFlorian Fainelli case BCM5395_DEVICE_ID: 2371967dd82fSFlorian Fainelli case BCM5397_DEVICE_ID: 2372967dd82fSFlorian Fainelli case BCM5398_DEVICE_ID: 2373967dd82fSFlorian Fainelli dev->chip_id = id8; 2374967dd82fSFlorian Fainelli break; 2375967dd82fSFlorian Fainelli default: 2376967dd82fSFlorian Fainelli ret = b53_read32(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id32); 2377967dd82fSFlorian Fainelli if (ret) 2378967dd82fSFlorian Fainelli return ret; 2379967dd82fSFlorian Fainelli 2380967dd82fSFlorian Fainelli switch (id32) { 2381967dd82fSFlorian Fainelli case BCM53115_DEVICE_ID: 2382967dd82fSFlorian Fainelli case BCM53125_DEVICE_ID: 2383967dd82fSFlorian Fainelli case BCM53128_DEVICE_ID: 2384967dd82fSFlorian Fainelli case BCM53010_DEVICE_ID: 2385967dd82fSFlorian Fainelli case BCM53011_DEVICE_ID: 2386967dd82fSFlorian Fainelli case BCM53012_DEVICE_ID: 2387967dd82fSFlorian Fainelli case BCM53018_DEVICE_ID: 2388967dd82fSFlorian Fainelli case BCM53019_DEVICE_ID: 2389967dd82fSFlorian Fainelli dev->chip_id = id32; 2390967dd82fSFlorian Fainelli break; 2391967dd82fSFlorian Fainelli default: 2392967dd82fSFlorian Fainelli pr_err("unsupported switch detected (BCM53%02x/BCM%x)\n", 2393967dd82fSFlorian Fainelli id8, id32); 2394967dd82fSFlorian Fainelli return -ENODEV; 2395967dd82fSFlorian Fainelli } 2396967dd82fSFlorian Fainelli } 2397967dd82fSFlorian Fainelli 2398967dd82fSFlorian Fainelli if (dev->chip_id == BCM5325_DEVICE_ID) 2399967dd82fSFlorian Fainelli return b53_read8(dev, B53_STAT_PAGE, B53_REV_ID_25, 2400967dd82fSFlorian Fainelli &dev->core_rev); 2401967dd82fSFlorian Fainelli else 2402967dd82fSFlorian Fainelli return b53_read8(dev, B53_MGMT_PAGE, B53_REV_ID, 2403967dd82fSFlorian Fainelli &dev->core_rev); 2404967dd82fSFlorian Fainelli } 2405967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_detect); 2406967dd82fSFlorian Fainelli 2407967dd82fSFlorian Fainelli int b53_switch_register(struct b53_device *dev) 2408967dd82fSFlorian Fainelli { 2409967dd82fSFlorian Fainelli int ret; 2410967dd82fSFlorian Fainelli 2411967dd82fSFlorian Fainelli if (dev->pdata) { 2412967dd82fSFlorian Fainelli dev->chip_id = dev->pdata->chip_id; 2413967dd82fSFlorian Fainelli dev->enabled_ports = dev->pdata->enabled_ports; 2414967dd82fSFlorian Fainelli } 2415967dd82fSFlorian Fainelli 2416967dd82fSFlorian Fainelli if (!dev->chip_id && b53_switch_detect(dev)) 2417967dd82fSFlorian Fainelli return -EINVAL; 2418967dd82fSFlorian Fainelli 2419967dd82fSFlorian Fainelli ret = b53_switch_init(dev); 2420967dd82fSFlorian Fainelli if (ret) 2421967dd82fSFlorian Fainelli return ret; 2422967dd82fSFlorian Fainelli 2423967dd82fSFlorian Fainelli pr_info("found switch: %s, rev %i\n", dev->name, dev->core_rev); 2424967dd82fSFlorian Fainelli 242523c9ee49SVivien Didelot return dsa_register_switch(dev->ds); 2426967dd82fSFlorian Fainelli } 2427967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_register); 2428967dd82fSFlorian Fainelli 2429967dd82fSFlorian Fainelli MODULE_AUTHOR("Jonas Gorski <jogo@openwrt.org>"); 2430967dd82fSFlorian Fainelli MODULE_DESCRIPTION("B53 switch library"); 2431967dd82fSFlorian Fainelli MODULE_LICENSE("Dual BSD/GPL"); 2432