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 #include <linux/delay.h> 21967dd82fSFlorian Fainelli #include <linux/export.h> 22967dd82fSFlorian Fainelli #include <linux/gpio.h> 23967dd82fSFlorian Fainelli #include <linux/kernel.h> 24967dd82fSFlorian Fainelli #include <linux/module.h> 25967dd82fSFlorian Fainelli #include <linux/platform_data/b53.h> 26967dd82fSFlorian Fainelli #include <linux/phy.h> 275e004460SFlorian Fainelli #include <linux/phylink.h> 281da6df85SFlorian Fainelli #include <linux/etherdevice.h> 29ff39c2d6SFlorian Fainelli #include <linux/if_bridge.h> 30967dd82fSFlorian Fainelli #include <net/dsa.h> 31967dd82fSFlorian Fainelli 32967dd82fSFlorian Fainelli #include "b53_regs.h" 33967dd82fSFlorian Fainelli #include "b53_priv.h" 34967dd82fSFlorian Fainelli 35967dd82fSFlorian Fainelli struct b53_mib_desc { 36967dd82fSFlorian Fainelli u8 size; 37967dd82fSFlorian Fainelli u8 offset; 38967dd82fSFlorian Fainelli const char *name; 39967dd82fSFlorian Fainelli }; 40967dd82fSFlorian Fainelli 41967dd82fSFlorian Fainelli /* BCM5365 MIB counters */ 42967dd82fSFlorian Fainelli static const struct b53_mib_desc b53_mibs_65[] = { 43967dd82fSFlorian Fainelli { 8, 0x00, "TxOctets" }, 44967dd82fSFlorian Fainelli { 4, 0x08, "TxDropPkts" }, 45967dd82fSFlorian Fainelli { 4, 0x10, "TxBroadcastPkts" }, 46967dd82fSFlorian Fainelli { 4, 0x14, "TxMulticastPkts" }, 47967dd82fSFlorian Fainelli { 4, 0x18, "TxUnicastPkts" }, 48967dd82fSFlorian Fainelli { 4, 0x1c, "TxCollisions" }, 49967dd82fSFlorian Fainelli { 4, 0x20, "TxSingleCollision" }, 50967dd82fSFlorian Fainelli { 4, 0x24, "TxMultipleCollision" }, 51967dd82fSFlorian Fainelli { 4, 0x28, "TxDeferredTransmit" }, 52967dd82fSFlorian Fainelli { 4, 0x2c, "TxLateCollision" }, 53967dd82fSFlorian Fainelli { 4, 0x30, "TxExcessiveCollision" }, 54967dd82fSFlorian Fainelli { 4, 0x38, "TxPausePkts" }, 55967dd82fSFlorian Fainelli { 8, 0x44, "RxOctets" }, 56967dd82fSFlorian Fainelli { 4, 0x4c, "RxUndersizePkts" }, 57967dd82fSFlorian Fainelli { 4, 0x50, "RxPausePkts" }, 58967dd82fSFlorian Fainelli { 4, 0x54, "Pkts64Octets" }, 59967dd82fSFlorian Fainelli { 4, 0x58, "Pkts65to127Octets" }, 60967dd82fSFlorian Fainelli { 4, 0x5c, "Pkts128to255Octets" }, 61967dd82fSFlorian Fainelli { 4, 0x60, "Pkts256to511Octets" }, 62967dd82fSFlorian Fainelli { 4, 0x64, "Pkts512to1023Octets" }, 63967dd82fSFlorian Fainelli { 4, 0x68, "Pkts1024to1522Octets" }, 64967dd82fSFlorian Fainelli { 4, 0x6c, "RxOversizePkts" }, 65967dd82fSFlorian Fainelli { 4, 0x70, "RxJabbers" }, 66967dd82fSFlorian Fainelli { 4, 0x74, "RxAlignmentErrors" }, 67967dd82fSFlorian Fainelli { 4, 0x78, "RxFCSErrors" }, 68967dd82fSFlorian Fainelli { 8, 0x7c, "RxGoodOctets" }, 69967dd82fSFlorian Fainelli { 4, 0x84, "RxDropPkts" }, 70967dd82fSFlorian Fainelli { 4, 0x88, "RxUnicastPkts" }, 71967dd82fSFlorian Fainelli { 4, 0x8c, "RxMulticastPkts" }, 72967dd82fSFlorian Fainelli { 4, 0x90, "RxBroadcastPkts" }, 73967dd82fSFlorian Fainelli { 4, 0x94, "RxSAChanges" }, 74967dd82fSFlorian Fainelli { 4, 0x98, "RxFragments" }, 75967dd82fSFlorian Fainelli }; 76967dd82fSFlorian Fainelli 77967dd82fSFlorian Fainelli #define B53_MIBS_65_SIZE ARRAY_SIZE(b53_mibs_65) 78967dd82fSFlorian Fainelli 79967dd82fSFlorian Fainelli /* BCM63xx MIB counters */ 80967dd82fSFlorian Fainelli static const struct b53_mib_desc b53_mibs_63xx[] = { 81967dd82fSFlorian Fainelli { 8, 0x00, "TxOctets" }, 82967dd82fSFlorian Fainelli { 4, 0x08, "TxDropPkts" }, 83967dd82fSFlorian Fainelli { 4, 0x0c, "TxQoSPkts" }, 84967dd82fSFlorian Fainelli { 4, 0x10, "TxBroadcastPkts" }, 85967dd82fSFlorian Fainelli { 4, 0x14, "TxMulticastPkts" }, 86967dd82fSFlorian Fainelli { 4, 0x18, "TxUnicastPkts" }, 87967dd82fSFlorian Fainelli { 4, 0x1c, "TxCollisions" }, 88967dd82fSFlorian Fainelli { 4, 0x20, "TxSingleCollision" }, 89967dd82fSFlorian Fainelli { 4, 0x24, "TxMultipleCollision" }, 90967dd82fSFlorian Fainelli { 4, 0x28, "TxDeferredTransmit" }, 91967dd82fSFlorian Fainelli { 4, 0x2c, "TxLateCollision" }, 92967dd82fSFlorian Fainelli { 4, 0x30, "TxExcessiveCollision" }, 93967dd82fSFlorian Fainelli { 4, 0x38, "TxPausePkts" }, 94967dd82fSFlorian Fainelli { 8, 0x3c, "TxQoSOctets" }, 95967dd82fSFlorian Fainelli { 8, 0x44, "RxOctets" }, 96967dd82fSFlorian Fainelli { 4, 0x4c, "RxUndersizePkts" }, 97967dd82fSFlorian Fainelli { 4, 0x50, "RxPausePkts" }, 98967dd82fSFlorian Fainelli { 4, 0x54, "Pkts64Octets" }, 99967dd82fSFlorian Fainelli { 4, 0x58, "Pkts65to127Octets" }, 100967dd82fSFlorian Fainelli { 4, 0x5c, "Pkts128to255Octets" }, 101967dd82fSFlorian Fainelli { 4, 0x60, "Pkts256to511Octets" }, 102967dd82fSFlorian Fainelli { 4, 0x64, "Pkts512to1023Octets" }, 103967dd82fSFlorian Fainelli { 4, 0x68, "Pkts1024to1522Octets" }, 104967dd82fSFlorian Fainelli { 4, 0x6c, "RxOversizePkts" }, 105967dd82fSFlorian Fainelli { 4, 0x70, "RxJabbers" }, 106967dd82fSFlorian Fainelli { 4, 0x74, "RxAlignmentErrors" }, 107967dd82fSFlorian Fainelli { 4, 0x78, "RxFCSErrors" }, 108967dd82fSFlorian Fainelli { 8, 0x7c, "RxGoodOctets" }, 109967dd82fSFlorian Fainelli { 4, 0x84, "RxDropPkts" }, 110967dd82fSFlorian Fainelli { 4, 0x88, "RxUnicastPkts" }, 111967dd82fSFlorian Fainelli { 4, 0x8c, "RxMulticastPkts" }, 112967dd82fSFlorian Fainelli { 4, 0x90, "RxBroadcastPkts" }, 113967dd82fSFlorian Fainelli { 4, 0x94, "RxSAChanges" }, 114967dd82fSFlorian Fainelli { 4, 0x98, "RxFragments" }, 115967dd82fSFlorian Fainelli { 4, 0xa0, "RxSymbolErrors" }, 116967dd82fSFlorian Fainelli { 4, 0xa4, "RxQoSPkts" }, 117967dd82fSFlorian Fainelli { 8, 0xa8, "RxQoSOctets" }, 118967dd82fSFlorian Fainelli { 4, 0xb0, "Pkts1523to2047Octets" }, 119967dd82fSFlorian Fainelli { 4, 0xb4, "Pkts2048to4095Octets" }, 120967dd82fSFlorian Fainelli { 4, 0xb8, "Pkts4096to8191Octets" }, 121967dd82fSFlorian Fainelli { 4, 0xbc, "Pkts8192to9728Octets" }, 122967dd82fSFlorian Fainelli { 4, 0xc0, "RxDiscarded" }, 123967dd82fSFlorian Fainelli }; 124967dd82fSFlorian Fainelli 125967dd82fSFlorian Fainelli #define B53_MIBS_63XX_SIZE ARRAY_SIZE(b53_mibs_63xx) 126967dd82fSFlorian Fainelli 127967dd82fSFlorian Fainelli /* MIB counters */ 128967dd82fSFlorian Fainelli static const struct b53_mib_desc b53_mibs[] = { 129967dd82fSFlorian Fainelli { 8, 0x00, "TxOctets" }, 130967dd82fSFlorian Fainelli { 4, 0x08, "TxDropPkts" }, 131967dd82fSFlorian Fainelli { 4, 0x10, "TxBroadcastPkts" }, 132967dd82fSFlorian Fainelli { 4, 0x14, "TxMulticastPkts" }, 133967dd82fSFlorian Fainelli { 4, 0x18, "TxUnicastPkts" }, 134967dd82fSFlorian Fainelli { 4, 0x1c, "TxCollisions" }, 135967dd82fSFlorian Fainelli { 4, 0x20, "TxSingleCollision" }, 136967dd82fSFlorian Fainelli { 4, 0x24, "TxMultipleCollision" }, 137967dd82fSFlorian Fainelli { 4, 0x28, "TxDeferredTransmit" }, 138967dd82fSFlorian Fainelli { 4, 0x2c, "TxLateCollision" }, 139967dd82fSFlorian Fainelli { 4, 0x30, "TxExcessiveCollision" }, 140967dd82fSFlorian Fainelli { 4, 0x38, "TxPausePkts" }, 141967dd82fSFlorian Fainelli { 8, 0x50, "RxOctets" }, 142967dd82fSFlorian Fainelli { 4, 0x58, "RxUndersizePkts" }, 143967dd82fSFlorian Fainelli { 4, 0x5c, "RxPausePkts" }, 144967dd82fSFlorian Fainelli { 4, 0x60, "Pkts64Octets" }, 145967dd82fSFlorian Fainelli { 4, 0x64, "Pkts65to127Octets" }, 146967dd82fSFlorian Fainelli { 4, 0x68, "Pkts128to255Octets" }, 147967dd82fSFlorian Fainelli { 4, 0x6c, "Pkts256to511Octets" }, 148967dd82fSFlorian Fainelli { 4, 0x70, "Pkts512to1023Octets" }, 149967dd82fSFlorian Fainelli { 4, 0x74, "Pkts1024to1522Octets" }, 150967dd82fSFlorian Fainelli { 4, 0x78, "RxOversizePkts" }, 151967dd82fSFlorian Fainelli { 4, 0x7c, "RxJabbers" }, 152967dd82fSFlorian Fainelli { 4, 0x80, "RxAlignmentErrors" }, 153967dd82fSFlorian Fainelli { 4, 0x84, "RxFCSErrors" }, 154967dd82fSFlorian Fainelli { 8, 0x88, "RxGoodOctets" }, 155967dd82fSFlorian Fainelli { 4, 0x90, "RxDropPkts" }, 156967dd82fSFlorian Fainelli { 4, 0x94, "RxUnicastPkts" }, 157967dd82fSFlorian Fainelli { 4, 0x98, "RxMulticastPkts" }, 158967dd82fSFlorian Fainelli { 4, 0x9c, "RxBroadcastPkts" }, 159967dd82fSFlorian Fainelli { 4, 0xa0, "RxSAChanges" }, 160967dd82fSFlorian Fainelli { 4, 0xa4, "RxFragments" }, 161967dd82fSFlorian Fainelli { 4, 0xa8, "RxJumboPkts" }, 162967dd82fSFlorian Fainelli { 4, 0xac, "RxSymbolErrors" }, 163967dd82fSFlorian Fainelli { 4, 0xc0, "RxDiscarded" }, 164967dd82fSFlorian Fainelli }; 165967dd82fSFlorian Fainelli 166967dd82fSFlorian Fainelli #define B53_MIBS_SIZE ARRAY_SIZE(b53_mibs) 167967dd82fSFlorian Fainelli 168bde5d132SFlorian Fainelli static const struct b53_mib_desc b53_mibs_58xx[] = { 169bde5d132SFlorian Fainelli { 8, 0x00, "TxOctets" }, 170bde5d132SFlorian Fainelli { 4, 0x08, "TxDropPkts" }, 171bde5d132SFlorian Fainelli { 4, 0x0c, "TxQPKTQ0" }, 172bde5d132SFlorian Fainelli { 4, 0x10, "TxBroadcastPkts" }, 173bde5d132SFlorian Fainelli { 4, 0x14, "TxMulticastPkts" }, 174bde5d132SFlorian Fainelli { 4, 0x18, "TxUnicastPKts" }, 175bde5d132SFlorian Fainelli { 4, 0x1c, "TxCollisions" }, 176bde5d132SFlorian Fainelli { 4, 0x20, "TxSingleCollision" }, 177bde5d132SFlorian Fainelli { 4, 0x24, "TxMultipleCollision" }, 178bde5d132SFlorian Fainelli { 4, 0x28, "TxDeferredCollision" }, 179bde5d132SFlorian Fainelli { 4, 0x2c, "TxLateCollision" }, 180bde5d132SFlorian Fainelli { 4, 0x30, "TxExcessiveCollision" }, 181bde5d132SFlorian Fainelli { 4, 0x34, "TxFrameInDisc" }, 182bde5d132SFlorian Fainelli { 4, 0x38, "TxPausePkts" }, 183bde5d132SFlorian Fainelli { 4, 0x3c, "TxQPKTQ1" }, 184bde5d132SFlorian Fainelli { 4, 0x40, "TxQPKTQ2" }, 185bde5d132SFlorian Fainelli { 4, 0x44, "TxQPKTQ3" }, 186bde5d132SFlorian Fainelli { 4, 0x48, "TxQPKTQ4" }, 187bde5d132SFlorian Fainelli { 4, 0x4c, "TxQPKTQ5" }, 188bde5d132SFlorian Fainelli { 8, 0x50, "RxOctets" }, 189bde5d132SFlorian Fainelli { 4, 0x58, "RxUndersizePkts" }, 190bde5d132SFlorian Fainelli { 4, 0x5c, "RxPausePkts" }, 191bde5d132SFlorian Fainelli { 4, 0x60, "RxPkts64Octets" }, 192bde5d132SFlorian Fainelli { 4, 0x64, "RxPkts65to127Octets" }, 193bde5d132SFlorian Fainelli { 4, 0x68, "RxPkts128to255Octets" }, 194bde5d132SFlorian Fainelli { 4, 0x6c, "RxPkts256to511Octets" }, 195bde5d132SFlorian Fainelli { 4, 0x70, "RxPkts512to1023Octets" }, 196bde5d132SFlorian Fainelli { 4, 0x74, "RxPkts1024toMaxPktsOctets" }, 197bde5d132SFlorian Fainelli { 4, 0x78, "RxOversizePkts" }, 198bde5d132SFlorian Fainelli { 4, 0x7c, "RxJabbers" }, 199bde5d132SFlorian Fainelli { 4, 0x80, "RxAlignmentErrors" }, 200bde5d132SFlorian Fainelli { 4, 0x84, "RxFCSErrors" }, 201bde5d132SFlorian Fainelli { 8, 0x88, "RxGoodOctets" }, 202bde5d132SFlorian Fainelli { 4, 0x90, "RxDropPkts" }, 203bde5d132SFlorian Fainelli { 4, 0x94, "RxUnicastPkts" }, 204bde5d132SFlorian Fainelli { 4, 0x98, "RxMulticastPkts" }, 205bde5d132SFlorian Fainelli { 4, 0x9c, "RxBroadcastPkts" }, 206bde5d132SFlorian Fainelli { 4, 0xa0, "RxSAChanges" }, 207bde5d132SFlorian Fainelli { 4, 0xa4, "RxFragments" }, 208bde5d132SFlorian Fainelli { 4, 0xa8, "RxJumboPkt" }, 209bde5d132SFlorian Fainelli { 4, 0xac, "RxSymblErr" }, 210bde5d132SFlorian Fainelli { 4, 0xb0, "InRangeErrCount" }, 211bde5d132SFlorian Fainelli { 4, 0xb4, "OutRangeErrCount" }, 212bde5d132SFlorian Fainelli { 4, 0xb8, "EEELpiEvent" }, 213bde5d132SFlorian Fainelli { 4, 0xbc, "EEELpiDuration" }, 214bde5d132SFlorian Fainelli { 4, 0xc0, "RxDiscard" }, 215bde5d132SFlorian Fainelli { 4, 0xc8, "TxQPKTQ6" }, 216bde5d132SFlorian Fainelli { 4, 0xcc, "TxQPKTQ7" }, 217bde5d132SFlorian Fainelli { 4, 0xd0, "TxPkts64Octets" }, 218bde5d132SFlorian Fainelli { 4, 0xd4, "TxPkts65to127Octets" }, 219bde5d132SFlorian Fainelli { 4, 0xd8, "TxPkts128to255Octets" }, 220bde5d132SFlorian Fainelli { 4, 0xdc, "TxPkts256to511Ocets" }, 221bde5d132SFlorian Fainelli { 4, 0xe0, "TxPkts512to1023Ocets" }, 222bde5d132SFlorian Fainelli { 4, 0xe4, "TxPkts1024toMaxPktOcets" }, 223bde5d132SFlorian Fainelli }; 224bde5d132SFlorian Fainelli 225bde5d132SFlorian Fainelli #define B53_MIBS_58XX_SIZE ARRAY_SIZE(b53_mibs_58xx) 226bde5d132SFlorian Fainelli 227967dd82fSFlorian Fainelli static int b53_do_vlan_op(struct b53_device *dev, u8 op) 228967dd82fSFlorian Fainelli { 229967dd82fSFlorian Fainelli unsigned int i; 230967dd82fSFlorian Fainelli 231967dd82fSFlorian Fainelli b53_write8(dev, B53_ARLIO_PAGE, dev->vta_regs[0], VTA_START_CMD | op); 232967dd82fSFlorian Fainelli 233967dd82fSFlorian Fainelli for (i = 0; i < 10; i++) { 234967dd82fSFlorian Fainelli u8 vta; 235967dd82fSFlorian Fainelli 236967dd82fSFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, dev->vta_regs[0], &vta); 237967dd82fSFlorian Fainelli if (!(vta & VTA_START_CMD)) 238967dd82fSFlorian Fainelli return 0; 239967dd82fSFlorian Fainelli 240967dd82fSFlorian Fainelli usleep_range(100, 200); 241967dd82fSFlorian Fainelli } 242967dd82fSFlorian Fainelli 243967dd82fSFlorian Fainelli return -EIO; 244967dd82fSFlorian Fainelli } 245967dd82fSFlorian Fainelli 246a2482d2cSFlorian Fainelli static void b53_set_vlan_entry(struct b53_device *dev, u16 vid, 247a2482d2cSFlorian Fainelli struct b53_vlan *vlan) 248967dd82fSFlorian Fainelli { 249967dd82fSFlorian Fainelli if (is5325(dev)) { 250967dd82fSFlorian Fainelli u32 entry = 0; 251967dd82fSFlorian Fainelli 252a2482d2cSFlorian Fainelli if (vlan->members) { 253a2482d2cSFlorian Fainelli entry = ((vlan->untag & VA_UNTAG_MASK_25) << 254a2482d2cSFlorian Fainelli VA_UNTAG_S_25) | vlan->members; 255967dd82fSFlorian Fainelli if (dev->core_rev >= 3) 256967dd82fSFlorian Fainelli entry |= VA_VALID_25_R4 | vid << VA_VID_HIGH_S; 257967dd82fSFlorian Fainelli else 258967dd82fSFlorian Fainelli entry |= VA_VALID_25; 259967dd82fSFlorian Fainelli } 260967dd82fSFlorian Fainelli 261967dd82fSFlorian Fainelli b53_write32(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_25, entry); 262967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, vid | 263967dd82fSFlorian Fainelli VTA_RW_STATE_WR | VTA_RW_OP_EN); 264967dd82fSFlorian Fainelli } else if (is5365(dev)) { 265967dd82fSFlorian Fainelli u16 entry = 0; 266967dd82fSFlorian Fainelli 267a2482d2cSFlorian Fainelli if (vlan->members) 268a2482d2cSFlorian Fainelli entry = ((vlan->untag & VA_UNTAG_MASK_65) << 269a2482d2cSFlorian Fainelli VA_UNTAG_S_65) | vlan->members | VA_VALID_65; 270967dd82fSFlorian Fainelli 271967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_65, entry); 272967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_65, vid | 273967dd82fSFlorian Fainelli VTA_RW_STATE_WR | VTA_RW_OP_EN); 274967dd82fSFlorian Fainelli } else { 275967dd82fSFlorian Fainelli b53_write16(dev, B53_ARLIO_PAGE, dev->vta_regs[1], vid); 276967dd82fSFlorian Fainelli b53_write32(dev, B53_ARLIO_PAGE, dev->vta_regs[2], 277a2482d2cSFlorian Fainelli (vlan->untag << VTE_UNTAG_S) | vlan->members); 278967dd82fSFlorian Fainelli 279967dd82fSFlorian Fainelli b53_do_vlan_op(dev, VTA_CMD_WRITE); 280967dd82fSFlorian Fainelli } 281a2482d2cSFlorian Fainelli 282a2482d2cSFlorian Fainelli dev_dbg(dev->ds->dev, "VID: %d, members: 0x%04x, untag: 0x%04x\n", 283a2482d2cSFlorian Fainelli vid, vlan->members, vlan->untag); 284967dd82fSFlorian Fainelli } 285967dd82fSFlorian Fainelli 286a2482d2cSFlorian Fainelli static void b53_get_vlan_entry(struct b53_device *dev, u16 vid, 287a2482d2cSFlorian Fainelli struct b53_vlan *vlan) 288a2482d2cSFlorian Fainelli { 289a2482d2cSFlorian Fainelli if (is5325(dev)) { 290a2482d2cSFlorian Fainelli u32 entry = 0; 291a2482d2cSFlorian Fainelli 292a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, vid | 293a2482d2cSFlorian Fainelli VTA_RW_STATE_RD | VTA_RW_OP_EN); 294a2482d2cSFlorian Fainelli b53_read32(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_25, &entry); 295a2482d2cSFlorian Fainelli 296a2482d2cSFlorian Fainelli if (dev->core_rev >= 3) 297a2482d2cSFlorian Fainelli vlan->valid = !!(entry & VA_VALID_25_R4); 298a2482d2cSFlorian Fainelli else 299a2482d2cSFlorian Fainelli vlan->valid = !!(entry & VA_VALID_25); 300a2482d2cSFlorian Fainelli vlan->members = entry & VA_MEMBER_MASK; 301a2482d2cSFlorian Fainelli vlan->untag = (entry >> VA_UNTAG_S_25) & VA_UNTAG_MASK_25; 302a2482d2cSFlorian Fainelli 303a2482d2cSFlorian Fainelli } else if (is5365(dev)) { 304a2482d2cSFlorian Fainelli u16 entry = 0; 305a2482d2cSFlorian Fainelli 306a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_65, vid | 307a2482d2cSFlorian Fainelli VTA_RW_STATE_WR | VTA_RW_OP_EN); 308a2482d2cSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_65, &entry); 309a2482d2cSFlorian Fainelli 310a2482d2cSFlorian Fainelli vlan->valid = !!(entry & VA_VALID_65); 311a2482d2cSFlorian Fainelli vlan->members = entry & VA_MEMBER_MASK; 312a2482d2cSFlorian Fainelli vlan->untag = (entry >> VA_UNTAG_S_65) & VA_UNTAG_MASK_65; 313a2482d2cSFlorian Fainelli } else { 314a2482d2cSFlorian Fainelli u32 entry = 0; 315a2482d2cSFlorian Fainelli 316a2482d2cSFlorian Fainelli b53_write16(dev, B53_ARLIO_PAGE, dev->vta_regs[1], vid); 317a2482d2cSFlorian Fainelli b53_do_vlan_op(dev, VTA_CMD_READ); 318a2482d2cSFlorian Fainelli b53_read32(dev, B53_ARLIO_PAGE, dev->vta_regs[2], &entry); 319a2482d2cSFlorian Fainelli vlan->members = entry & VTE_MEMBERS; 320a2482d2cSFlorian Fainelli vlan->untag = (entry >> VTE_UNTAG_S) & VTE_MEMBERS; 321a2482d2cSFlorian Fainelli vlan->valid = true; 322a2482d2cSFlorian Fainelli } 323a2482d2cSFlorian Fainelli } 324a2482d2cSFlorian Fainelli 325a2482d2cSFlorian Fainelli static void b53_set_forwarding(struct b53_device *dev, int enable) 326967dd82fSFlorian Fainelli { 327967dd82fSFlorian Fainelli u8 mgmt; 328967dd82fSFlorian Fainelli 329967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); 330967dd82fSFlorian Fainelli 331967dd82fSFlorian Fainelli if (enable) 332967dd82fSFlorian Fainelli mgmt |= SM_SW_FWD_EN; 333967dd82fSFlorian Fainelli else 334967dd82fSFlorian Fainelli mgmt &= ~SM_SW_FWD_EN; 335967dd82fSFlorian Fainelli 336967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt); 337a424f0deSFlorian Fainelli 3387edc58d6SFlorian Fainelli /* Include IMP port in dumb forwarding mode 339a424f0deSFlorian Fainelli */ 340a424f0deSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, &mgmt); 341a424f0deSFlorian Fainelli mgmt |= B53_MII_DUMB_FWDG_EN; 342a424f0deSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, mgmt); 34353568438SFlorian Fainelli 34453568438SFlorian Fainelli /* Look at B53_UC_FWD_EN and B53_MC_FWD_EN to decide whether 34553568438SFlorian Fainelli * frames should be flooded or not. 34653568438SFlorian Fainelli */ 34753568438SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_IP_MULTICAST_CTRL, &mgmt); 34863cc54a6SFlorian Fainelli mgmt |= B53_UC_FWD_EN | B53_MC_FWD_EN | B53_IPMC_FWD_EN; 34953568438SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_IP_MULTICAST_CTRL, mgmt); 350a424f0deSFlorian Fainelli } 351967dd82fSFlorian Fainelli 352ee47ed08SFlorian Fainelli static void b53_enable_vlan(struct b53_device *dev, int port, bool enable, 353dad8d7c6SFlorian Fainelli bool enable_filtering) 354967dd82fSFlorian Fainelli { 355967dd82fSFlorian Fainelli u8 mgmt, vc0, vc1, vc4 = 0, vc5; 356967dd82fSFlorian Fainelli 357967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); 358967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL0, &vc0); 359967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL1, &vc1); 360967dd82fSFlorian Fainelli 361967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) { 362967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4); 363967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_25, &vc5); 364967dd82fSFlorian Fainelli } else if (is63xx(dev)) { 365967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_63XX, &vc4); 366967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_63XX, &vc5); 367967dd82fSFlorian Fainelli } else { 368967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, &vc4); 369967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, &vc5); 370967dd82fSFlorian Fainelli } 371967dd82fSFlorian Fainelli 372967dd82fSFlorian Fainelli if (enable) { 373967dd82fSFlorian Fainelli vc0 |= VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID; 374967dd82fSFlorian Fainelli vc1 |= VC1_RX_MCST_UNTAG_EN | VC1_RX_MCST_FWD_EN; 375967dd82fSFlorian Fainelli vc4 &= ~VC4_ING_VID_CHECK_MASK; 376dad8d7c6SFlorian Fainelli if (enable_filtering) { 377967dd82fSFlorian Fainelli vc4 |= VC4_ING_VID_VIO_DROP << VC4_ING_VID_CHECK_S; 378967dd82fSFlorian Fainelli vc5 |= VC5_DROP_VTABLE_MISS; 379dad8d7c6SFlorian Fainelli } else { 380dad8d7c6SFlorian Fainelli vc4 |= VC4_ING_VID_VIO_FWD << VC4_ING_VID_CHECK_S; 381dad8d7c6SFlorian Fainelli vc5 &= ~VC5_DROP_VTABLE_MISS; 382dad8d7c6SFlorian Fainelli } 383967dd82fSFlorian Fainelli 384967dd82fSFlorian Fainelli if (is5325(dev)) 385967dd82fSFlorian Fainelli vc0 &= ~VC0_RESERVED_1; 386967dd82fSFlorian Fainelli 387967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 388967dd82fSFlorian Fainelli vc1 |= VC1_RX_MCST_TAG_EN; 389967dd82fSFlorian Fainelli 390967dd82fSFlorian Fainelli } else { 391967dd82fSFlorian Fainelli vc0 &= ~(VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID); 392967dd82fSFlorian Fainelli vc1 &= ~(VC1_RX_MCST_UNTAG_EN | VC1_RX_MCST_FWD_EN); 393967dd82fSFlorian Fainelli vc4 &= ~VC4_ING_VID_CHECK_MASK; 394967dd82fSFlorian Fainelli vc5 &= ~VC5_DROP_VTABLE_MISS; 395967dd82fSFlorian Fainelli 396967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 397967dd82fSFlorian Fainelli vc4 |= VC4_ING_VID_VIO_FWD << VC4_ING_VID_CHECK_S; 398967dd82fSFlorian Fainelli else 399967dd82fSFlorian Fainelli vc4 |= VC4_ING_VID_VIO_TO_IMP << VC4_ING_VID_CHECK_S; 400967dd82fSFlorian Fainelli 401967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 402967dd82fSFlorian Fainelli vc1 &= ~VC1_RX_MCST_TAG_EN; 403a2482d2cSFlorian Fainelli } 404967dd82fSFlorian Fainelli 405967dd82fSFlorian Fainelli if (!is5325(dev) && !is5365(dev)) 406967dd82fSFlorian Fainelli vc5 &= ~VC5_VID_FFF_EN; 407967dd82fSFlorian Fainelli 408967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL0, vc0); 409967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL1, vc1); 410967dd82fSFlorian Fainelli 411967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) { 412967dd82fSFlorian Fainelli /* enable the high 8 bit vid check on 5325 */ 413967dd82fSFlorian Fainelli if (is5325(dev) && enable) 414967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 415967dd82fSFlorian Fainelli VC3_HIGH_8BIT_EN); 416967dd82fSFlorian Fainelli else 417967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 0); 418967dd82fSFlorian Fainelli 419967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, vc4); 420967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_25, vc5); 421967dd82fSFlorian Fainelli } else if (is63xx(dev)) { 422967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3_63XX, 0); 423967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_63XX, vc4); 424967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_63XX, vc5); 425967dd82fSFlorian Fainelli } else { 426967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 0); 427967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, vc4); 428967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, vc5); 429967dd82fSFlorian Fainelli } 430967dd82fSFlorian Fainelli 431967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt); 432dad8d7c6SFlorian Fainelli 433dad8d7c6SFlorian Fainelli dev->vlan_enabled = enable; 434ee47ed08SFlorian Fainelli 435ee47ed08SFlorian Fainelli dev_dbg(dev->dev, "Port %d VLAN enabled: %d, filtering: %d\n", 436ee47ed08SFlorian Fainelli port, enable, enable_filtering); 437967dd82fSFlorian Fainelli } 438967dd82fSFlorian Fainelli 439967dd82fSFlorian Fainelli static int b53_set_jumbo(struct b53_device *dev, bool enable, bool allow_10_100) 440967dd82fSFlorian Fainelli { 441967dd82fSFlorian Fainelli u32 port_mask = 0; 442967dd82fSFlorian Fainelli u16 max_size = JMS_MIN_SIZE; 443967dd82fSFlorian Fainelli 444967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 445967dd82fSFlorian Fainelli return -EINVAL; 446967dd82fSFlorian Fainelli 447967dd82fSFlorian Fainelli if (enable) { 448967dd82fSFlorian Fainelli port_mask = dev->enabled_ports; 449967dd82fSFlorian Fainelli max_size = JMS_MAX_SIZE; 450967dd82fSFlorian Fainelli if (allow_10_100) 451967dd82fSFlorian Fainelli port_mask |= JPM_10_100_JUMBO_EN; 452967dd82fSFlorian Fainelli } 453967dd82fSFlorian Fainelli 454967dd82fSFlorian Fainelli b53_write32(dev, B53_JUMBO_PAGE, dev->jumbo_pm_reg, port_mask); 455967dd82fSFlorian Fainelli return b53_write16(dev, B53_JUMBO_PAGE, dev->jumbo_size_reg, max_size); 456967dd82fSFlorian Fainelli } 457967dd82fSFlorian Fainelli 458ff39c2d6SFlorian Fainelli static int b53_flush_arl(struct b53_device *dev, u8 mask) 459967dd82fSFlorian Fainelli { 460967dd82fSFlorian Fainelli unsigned int i; 461967dd82fSFlorian Fainelli 462967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, 463ff39c2d6SFlorian Fainelli FAST_AGE_DONE | FAST_AGE_DYNAMIC | mask); 464967dd82fSFlorian Fainelli 465967dd82fSFlorian Fainelli for (i = 0; i < 10; i++) { 466967dd82fSFlorian Fainelli u8 fast_age_ctrl; 467967dd82fSFlorian Fainelli 468967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, 469967dd82fSFlorian Fainelli &fast_age_ctrl); 470967dd82fSFlorian Fainelli 471967dd82fSFlorian Fainelli if (!(fast_age_ctrl & FAST_AGE_DONE)) 472967dd82fSFlorian Fainelli goto out; 473967dd82fSFlorian Fainelli 474967dd82fSFlorian Fainelli msleep(1); 475967dd82fSFlorian Fainelli } 476967dd82fSFlorian Fainelli 477967dd82fSFlorian Fainelli return -ETIMEDOUT; 478967dd82fSFlorian Fainelli out: 479967dd82fSFlorian Fainelli /* Only age dynamic entries (default behavior) */ 480967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, FAST_AGE_DYNAMIC); 481967dd82fSFlorian Fainelli return 0; 482967dd82fSFlorian Fainelli } 483967dd82fSFlorian Fainelli 484ff39c2d6SFlorian Fainelli static int b53_fast_age_port(struct b53_device *dev, int port) 485ff39c2d6SFlorian Fainelli { 486ff39c2d6SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_PORT_CTRL, port); 487ff39c2d6SFlorian Fainelli 488ff39c2d6SFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_PORT); 489ff39c2d6SFlorian Fainelli } 490ff39c2d6SFlorian Fainelli 491a2482d2cSFlorian Fainelli static int b53_fast_age_vlan(struct b53_device *dev, u16 vid) 492a2482d2cSFlorian Fainelli { 493a2482d2cSFlorian Fainelli b53_write16(dev, B53_CTRL_PAGE, B53_FAST_AGE_VID_CTRL, vid); 494a2482d2cSFlorian Fainelli 495a2482d2cSFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_VLAN); 496a2482d2cSFlorian Fainelli } 497a2482d2cSFlorian Fainelli 498aac02867SFlorian Fainelli void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port) 499ff39c2d6SFlorian Fainelli { 50004bed143SVivien Didelot struct b53_device *dev = ds->priv; 501ff39c2d6SFlorian Fainelli unsigned int i; 502ff39c2d6SFlorian Fainelli u16 pvlan; 503ff39c2d6SFlorian Fainelli 504ff39c2d6SFlorian Fainelli /* Enable the IMP port to be in the same VLAN as the other ports 505ff39c2d6SFlorian Fainelli * on a per-port basis such that we only have Port i and IMP in 506ff39c2d6SFlorian Fainelli * the same VLAN. 507ff39c2d6SFlorian Fainelli */ 508ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) { 509ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &pvlan); 510ff39c2d6SFlorian Fainelli pvlan |= BIT(cpu_port); 511ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), pvlan); 512ff39c2d6SFlorian Fainelli } 513ff39c2d6SFlorian Fainelli } 514aac02867SFlorian Fainelli EXPORT_SYMBOL(b53_imp_vlan_setup); 515ff39c2d6SFlorian Fainelli 516a8b659e7SVladimir Oltean static void b53_port_set_ucast_flood(struct b53_device *dev, int port, 517a8b659e7SVladimir Oltean bool unicast) 518a8b659e7SVladimir Oltean { 519a8b659e7SVladimir Oltean u16 uc; 520a8b659e7SVladimir Oltean 521a8b659e7SVladimir Oltean b53_read16(dev, B53_CTRL_PAGE, B53_UC_FLOOD_MASK, &uc); 522a8b659e7SVladimir Oltean if (unicast) 523a8b659e7SVladimir Oltean uc |= BIT(port); 524a8b659e7SVladimir Oltean else 525a8b659e7SVladimir Oltean uc &= ~BIT(port); 526a8b659e7SVladimir Oltean b53_write16(dev, B53_CTRL_PAGE, B53_UC_FLOOD_MASK, uc); 527a8b659e7SVladimir Oltean } 528a8b659e7SVladimir Oltean 529a8b659e7SVladimir Oltean static void b53_port_set_mcast_flood(struct b53_device *dev, int port, 530a8b659e7SVladimir Oltean bool multicast) 531a8b659e7SVladimir Oltean { 532a8b659e7SVladimir Oltean u16 mc; 533a8b659e7SVladimir Oltean 534a8b659e7SVladimir Oltean b53_read16(dev, B53_CTRL_PAGE, B53_MC_FLOOD_MASK, &mc); 535a8b659e7SVladimir Oltean if (multicast) 536a8b659e7SVladimir Oltean mc |= BIT(port); 537a8b659e7SVladimir Oltean else 538a8b659e7SVladimir Oltean mc &= ~BIT(port); 539a8b659e7SVladimir Oltean b53_write16(dev, B53_CTRL_PAGE, B53_MC_FLOOD_MASK, mc); 540a8b659e7SVladimir Oltean 541a8b659e7SVladimir Oltean b53_read16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, &mc); 542a8b659e7SVladimir Oltean if (multicast) 543a8b659e7SVladimir Oltean mc |= BIT(port); 544a8b659e7SVladimir Oltean else 545a8b659e7SVladimir Oltean mc &= ~BIT(port); 546a8b659e7SVladimir Oltean b53_write16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, mc); 547a8b659e7SVladimir Oltean } 548a8b659e7SVladimir Oltean 549f9b3827eSFlorian Fainelli static void b53_port_set_learning(struct b53_device *dev, int port, 550f9b3827eSFlorian Fainelli bool learning) 551f9b3827eSFlorian Fainelli { 552f9b3827eSFlorian Fainelli u16 reg; 553f9b3827eSFlorian Fainelli 554f9b3827eSFlorian Fainelli b53_read16(dev, B53_CTRL_PAGE, B53_DIS_LEARNING, ®); 555f9b3827eSFlorian Fainelli if (learning) 556f9b3827eSFlorian Fainelli reg &= ~BIT(port); 557f9b3827eSFlorian Fainelli else 558f9b3827eSFlorian Fainelli reg |= BIT(port); 559f9b3827eSFlorian Fainelli b53_write16(dev, B53_CTRL_PAGE, B53_DIS_LEARNING, reg); 560f9b3827eSFlorian Fainelli } 561f9b3827eSFlorian Fainelli 562f86ad77fSFlorian Fainelli int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy) 563967dd82fSFlorian Fainelli { 56404bed143SVivien Didelot struct b53_device *dev = ds->priv; 56574be4babSVivien Didelot unsigned int cpu_port; 5668ca7c160SFlorian Fainelli int ret = 0; 567ff39c2d6SFlorian Fainelli u16 pvlan; 568967dd82fSFlorian Fainelli 56974be4babSVivien Didelot if (!dsa_is_user_port(ds, port)) 57074be4babSVivien Didelot return 0; 57174be4babSVivien Didelot 57268bb8ea8SVivien Didelot cpu_port = dsa_to_port(ds, port)->cpu_dp->index; 57374be4babSVivien Didelot 574a8b659e7SVladimir Oltean b53_port_set_ucast_flood(dev, port, true); 575a8b659e7SVladimir Oltean b53_port_set_mcast_flood(dev, port, true); 576f9b3827eSFlorian Fainelli b53_port_set_learning(dev, port, false); 57763cc54a6SFlorian Fainelli 5788ca7c160SFlorian Fainelli if (dev->ops->irq_enable) 5798ca7c160SFlorian Fainelli ret = dev->ops->irq_enable(dev, port); 5808ca7c160SFlorian Fainelli if (ret) 5818ca7c160SFlorian Fainelli return ret; 5828ca7c160SFlorian Fainelli 583967dd82fSFlorian Fainelli /* Clear the Rx and Tx disable bits and set to no spanning tree */ 584967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), 0); 585967dd82fSFlorian Fainelli 586ff39c2d6SFlorian Fainelli /* Set this port, and only this one to be in the default VLAN, 587ff39c2d6SFlorian Fainelli * if member of a bridge, restore its membership prior to 588ff39c2d6SFlorian Fainelli * bringing down this port. 589ff39c2d6SFlorian Fainelli */ 590ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); 591ff39c2d6SFlorian Fainelli pvlan &= ~0x1ff; 592ff39c2d6SFlorian Fainelli pvlan |= BIT(port); 593ff39c2d6SFlorian Fainelli pvlan |= dev->ports[port].vlan_ctl_mask; 594ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); 595ff39c2d6SFlorian Fainelli 596ff39c2d6SFlorian Fainelli b53_imp_vlan_setup(ds, cpu_port); 597ff39c2d6SFlorian Fainelli 598f43a2dbeSFlorian Fainelli /* If EEE was enabled, restore it */ 599f43a2dbeSFlorian Fainelli if (dev->ports[port].eee.eee_enabled) 600f43a2dbeSFlorian Fainelli b53_eee_enable_set(ds, port, true); 601f43a2dbeSFlorian Fainelli 602967dd82fSFlorian Fainelli return 0; 603967dd82fSFlorian Fainelli } 604f86ad77fSFlorian Fainelli EXPORT_SYMBOL(b53_enable_port); 605967dd82fSFlorian Fainelli 60675104db0SAndrew Lunn void b53_disable_port(struct dsa_switch *ds, int port) 607967dd82fSFlorian Fainelli { 60804bed143SVivien Didelot struct b53_device *dev = ds->priv; 609967dd82fSFlorian Fainelli u8 reg; 610967dd82fSFlorian Fainelli 611967dd82fSFlorian Fainelli /* Disable Tx/Rx for the port */ 612967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), ®); 613967dd82fSFlorian Fainelli reg |= PORT_CTRL_RX_DISABLE | PORT_CTRL_TX_DISABLE; 614967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg); 6158ca7c160SFlorian Fainelli 6168ca7c160SFlorian Fainelli if (dev->ops->irq_disable) 6178ca7c160SFlorian Fainelli dev->ops->irq_disable(dev, port); 618967dd82fSFlorian Fainelli } 619f86ad77fSFlorian Fainelli EXPORT_SYMBOL(b53_disable_port); 620967dd82fSFlorian Fainelli 621b409a9efSFlorian Fainelli void b53_brcm_hdr_setup(struct dsa_switch *ds, int port) 622b409a9efSFlorian Fainelli { 623b409a9efSFlorian Fainelli struct b53_device *dev = ds->priv; 6244d776482SFlorian Fainelli bool tag_en = !(dev->tag_protocol == DSA_TAG_PROTO_NONE); 625b409a9efSFlorian Fainelli u8 hdr_ctl, val; 626b409a9efSFlorian Fainelli u16 reg; 627b409a9efSFlorian Fainelli 628b409a9efSFlorian Fainelli /* Resolve which bit controls the Broadcom tag */ 629b409a9efSFlorian Fainelli switch (port) { 630b409a9efSFlorian Fainelli case 8: 631b409a9efSFlorian Fainelli val = BRCM_HDR_P8_EN; 632b409a9efSFlorian Fainelli break; 633b409a9efSFlorian Fainelli case 7: 634b409a9efSFlorian Fainelli val = BRCM_HDR_P7_EN; 635b409a9efSFlorian Fainelli break; 636b409a9efSFlorian Fainelli case 5: 637b409a9efSFlorian Fainelli val = BRCM_HDR_P5_EN; 638b409a9efSFlorian Fainelli break; 639b409a9efSFlorian Fainelli default: 640b409a9efSFlorian Fainelli val = 0; 641b409a9efSFlorian Fainelli break; 642b409a9efSFlorian Fainelli } 643b409a9efSFlorian Fainelli 6448fab459eSFlorian Fainelli /* Enable management mode if tagging is requested */ 6458fab459eSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &hdr_ctl); 6468fab459eSFlorian Fainelli if (tag_en) 6478fab459eSFlorian Fainelli hdr_ctl |= SM_SW_FWD_MODE; 6488fab459eSFlorian Fainelli else 6498fab459eSFlorian Fainelli hdr_ctl &= ~SM_SW_FWD_MODE; 6508fab459eSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, hdr_ctl); 6518fab459eSFlorian Fainelli 6528fab459eSFlorian Fainelli /* Configure the appropriate IMP port */ 6538fab459eSFlorian Fainelli b53_read8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &hdr_ctl); 6548fab459eSFlorian Fainelli if (port == 8) 6558fab459eSFlorian Fainelli hdr_ctl |= GC_FRM_MGMT_PORT_MII; 6568fab459eSFlorian Fainelli else if (port == 5) 6578fab459eSFlorian Fainelli hdr_ctl |= GC_FRM_MGMT_PORT_M; 6588fab459eSFlorian Fainelli b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, hdr_ctl); 6598fab459eSFlorian Fainelli 660b409a9efSFlorian Fainelli /* Enable Broadcom tags for IMP port */ 661b409a9efSFlorian Fainelli b53_read8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, &hdr_ctl); 662cdb583cfSFlorian Fainelli if (tag_en) 663b409a9efSFlorian Fainelli hdr_ctl |= val; 664cdb583cfSFlorian Fainelli else 665cdb583cfSFlorian Fainelli hdr_ctl &= ~val; 666b409a9efSFlorian Fainelli b53_write8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, hdr_ctl); 667b409a9efSFlorian Fainelli 668b409a9efSFlorian Fainelli /* Registers below are only accessible on newer devices */ 669b409a9efSFlorian Fainelli if (!is58xx(dev)) 670b409a9efSFlorian Fainelli return; 671b409a9efSFlorian Fainelli 672b409a9efSFlorian Fainelli /* Enable reception Broadcom tag for CPU TX (switch RX) to 673b409a9efSFlorian Fainelli * allow us to tag outgoing frames 674b409a9efSFlorian Fainelli */ 675b409a9efSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, ®); 676cdb583cfSFlorian Fainelli if (tag_en) 677b409a9efSFlorian Fainelli reg &= ~BIT(port); 678cdb583cfSFlorian Fainelli else 679cdb583cfSFlorian Fainelli reg |= BIT(port); 680b409a9efSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, reg); 681b409a9efSFlorian Fainelli 682b409a9efSFlorian Fainelli /* Enable transmission of Broadcom tags from the switch (CPU RX) to 683b409a9efSFlorian Fainelli * allow delivering frames to the per-port net_devices 684b409a9efSFlorian Fainelli */ 685b409a9efSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, ®); 686cdb583cfSFlorian Fainelli if (tag_en) 687b409a9efSFlorian Fainelli reg &= ~BIT(port); 688cdb583cfSFlorian Fainelli else 689cdb583cfSFlorian Fainelli reg |= BIT(port); 690b409a9efSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, reg); 691b409a9efSFlorian Fainelli } 692b409a9efSFlorian Fainelli EXPORT_SYMBOL(b53_brcm_hdr_setup); 693b409a9efSFlorian Fainelli 694299752a7SFlorian Fainelli static void b53_enable_cpu_port(struct b53_device *dev, int port) 695967dd82fSFlorian Fainelli { 696967dd82fSFlorian Fainelli u8 port_ctrl; 697967dd82fSFlorian Fainelli 698967dd82fSFlorian Fainelli /* BCM5325 CPU port is at 8 */ 699299752a7SFlorian Fainelli if ((is5325(dev) || is5365(dev)) && port == B53_CPU_PORT_25) 700299752a7SFlorian Fainelli port = B53_CPU_PORT; 701967dd82fSFlorian Fainelli 702967dd82fSFlorian Fainelli port_ctrl = PORT_CTRL_RX_BCST_EN | 703967dd82fSFlorian Fainelli PORT_CTRL_RX_MCST_EN | 704967dd82fSFlorian Fainelli PORT_CTRL_RX_UCST_EN; 705299752a7SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), port_ctrl); 7067edc58d6SFlorian Fainelli 7077edc58d6SFlorian Fainelli b53_brcm_hdr_setup(dev->ds, port); 70863cc54a6SFlorian Fainelli 709a8b659e7SVladimir Oltean b53_port_set_ucast_flood(dev, port, true); 710a8b659e7SVladimir Oltean b53_port_set_mcast_flood(dev, port, true); 711f9b3827eSFlorian Fainelli b53_port_set_learning(dev, port, false); 712967dd82fSFlorian Fainelli } 713967dd82fSFlorian Fainelli 714967dd82fSFlorian Fainelli static void b53_enable_mib(struct b53_device *dev) 715967dd82fSFlorian Fainelli { 716967dd82fSFlorian Fainelli u8 gc; 717967dd82fSFlorian Fainelli 718967dd82fSFlorian Fainelli b53_read8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc); 719967dd82fSFlorian Fainelli gc &= ~(GC_RESET_MIB | GC_MIB_AC_EN); 720967dd82fSFlorian Fainelli b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc); 721967dd82fSFlorian Fainelli } 722967dd82fSFlorian Fainelli 723fea83353SFlorian Fainelli static u16 b53_default_pvid(struct b53_device *dev) 724fea83353SFlorian Fainelli { 725fea83353SFlorian Fainelli if (is5325(dev) || is5365(dev)) 726fea83353SFlorian Fainelli return 1; 727fea83353SFlorian Fainelli else 728fea83353SFlorian Fainelli return 0; 729fea83353SFlorian Fainelli } 730fea83353SFlorian Fainelli 7315c1a6eafSFlorian Fainelli int b53_configure_vlan(struct dsa_switch *ds) 732967dd82fSFlorian Fainelli { 7335c1a6eafSFlorian Fainelli struct b53_device *dev = ds->priv; 734a2482d2cSFlorian Fainelli struct b53_vlan vl = { 0 }; 735d7a0b1f7SFlorian Fainelli struct b53_vlan *v; 736fea83353SFlorian Fainelli int i, def_vid; 737d7a0b1f7SFlorian Fainelli u16 vid; 738fea83353SFlorian Fainelli 739fea83353SFlorian Fainelli def_vid = b53_default_pvid(dev); 740967dd82fSFlorian Fainelli 741967dd82fSFlorian Fainelli /* clear all vlan entries */ 742967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) { 743fea83353SFlorian Fainelli for (i = def_vid; i < dev->num_vlans; i++) 744a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, i, &vl); 745967dd82fSFlorian Fainelli } else { 746967dd82fSFlorian Fainelli b53_do_vlan_op(dev, VTA_CMD_CLEAR); 747967dd82fSFlorian Fainelli } 748967dd82fSFlorian Fainelli 749ee47ed08SFlorian Fainelli b53_enable_vlan(dev, -1, dev->vlan_enabled, ds->vlan_filtering); 750967dd82fSFlorian Fainelli 751967dd82fSFlorian Fainelli b53_for_each_port(dev, i) 752967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, 753fea83353SFlorian Fainelli B53_VLAN_PORT_DEF_TAG(i), def_vid); 754967dd82fSFlorian Fainelli 755d7a0b1f7SFlorian Fainelli /* Upon initial call we have not set-up any VLANs, but upon 756d7a0b1f7SFlorian Fainelli * system resume, we need to restore all VLAN entries. 757d7a0b1f7SFlorian Fainelli */ 758d7a0b1f7SFlorian Fainelli for (vid = def_vid; vid < dev->num_vlans; vid++) { 759d7a0b1f7SFlorian Fainelli v = &dev->vlans[vid]; 760d7a0b1f7SFlorian Fainelli 761d7a0b1f7SFlorian Fainelli if (!v->members) 762d7a0b1f7SFlorian Fainelli continue; 763d7a0b1f7SFlorian Fainelli 764d7a0b1f7SFlorian Fainelli b53_set_vlan_entry(dev, vid, v); 765d7a0b1f7SFlorian Fainelli b53_fast_age_vlan(dev, vid); 766d7a0b1f7SFlorian Fainelli } 767d7a0b1f7SFlorian Fainelli 768967dd82fSFlorian Fainelli return 0; 769967dd82fSFlorian Fainelli } 7705c1a6eafSFlorian Fainelli EXPORT_SYMBOL(b53_configure_vlan); 771967dd82fSFlorian Fainelli 772967dd82fSFlorian Fainelli static void b53_switch_reset_gpio(struct b53_device *dev) 773967dd82fSFlorian Fainelli { 774967dd82fSFlorian Fainelli int gpio = dev->reset_gpio; 775967dd82fSFlorian Fainelli 776967dd82fSFlorian Fainelli if (gpio < 0) 777967dd82fSFlorian Fainelli return; 778967dd82fSFlorian Fainelli 779967dd82fSFlorian Fainelli /* Reset sequence: RESET low(50ms)->high(20ms) 780967dd82fSFlorian Fainelli */ 781967dd82fSFlorian Fainelli gpio_set_value(gpio, 0); 782967dd82fSFlorian Fainelli mdelay(50); 783967dd82fSFlorian Fainelli 784967dd82fSFlorian Fainelli gpio_set_value(gpio, 1); 785967dd82fSFlorian Fainelli mdelay(20); 786967dd82fSFlorian Fainelli 787967dd82fSFlorian Fainelli dev->current_page = 0xff; 788967dd82fSFlorian Fainelli } 789967dd82fSFlorian Fainelli 790967dd82fSFlorian Fainelli static int b53_switch_reset(struct b53_device *dev) 791967dd82fSFlorian Fainelli { 7923fb22b05SFlorian Fainelli unsigned int timeout = 1000; 7933fb22b05SFlorian Fainelli u8 mgmt, reg; 794967dd82fSFlorian Fainelli 795967dd82fSFlorian Fainelli b53_switch_reset_gpio(dev); 796967dd82fSFlorian Fainelli 797967dd82fSFlorian Fainelli if (is539x(dev)) { 798967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x83); 799967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x00); 800967dd82fSFlorian Fainelli } 801967dd82fSFlorian Fainelli 8023fb22b05SFlorian Fainelli /* This is specific to 58xx devices here, do not use is58xx() which 8033fb22b05SFlorian Fainelli * covers the larger Starfigther 2 family, including 7445/7278 which 8043fb22b05SFlorian Fainelli * still use this driver as a library and need to perform the reset 8053fb22b05SFlorian Fainelli * earlier. 8063fb22b05SFlorian Fainelli */ 8075040cc99SArun Parameswaran if (dev->chip_id == BCM58XX_DEVICE_ID || 8085040cc99SArun Parameswaran dev->chip_id == BCM583XX_DEVICE_ID) { 8093fb22b05SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, ®); 8103fb22b05SFlorian Fainelli reg |= SW_RST | EN_SW_RST | EN_CH_RST; 8113fb22b05SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, reg); 8123fb22b05SFlorian Fainelli 8133fb22b05SFlorian Fainelli do { 8143fb22b05SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, ®); 8153fb22b05SFlorian Fainelli if (!(reg & SW_RST)) 8163fb22b05SFlorian Fainelli break; 8173fb22b05SFlorian Fainelli 8183fb22b05SFlorian Fainelli usleep_range(1000, 2000); 8193fb22b05SFlorian Fainelli } while (timeout-- > 0); 8203fb22b05SFlorian Fainelli 821434d2312SPaul Barker if (timeout == 0) { 822434d2312SPaul Barker dev_err(dev->dev, 823434d2312SPaul Barker "Timeout waiting for SW_RST to clear!\n"); 8243fb22b05SFlorian Fainelli return -ETIMEDOUT; 8253fb22b05SFlorian Fainelli } 826434d2312SPaul Barker } 8273fb22b05SFlorian Fainelli 828967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); 829967dd82fSFlorian Fainelli 830967dd82fSFlorian Fainelli if (!(mgmt & SM_SW_FWD_EN)) { 831967dd82fSFlorian Fainelli mgmt &= ~SM_SW_FWD_MODE; 832967dd82fSFlorian Fainelli mgmt |= SM_SW_FWD_EN; 833967dd82fSFlorian Fainelli 834967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt); 835967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); 836967dd82fSFlorian Fainelli 837967dd82fSFlorian Fainelli if (!(mgmt & SM_SW_FWD_EN)) { 838967dd82fSFlorian Fainelli dev_err(dev->dev, "Failed to enable switch!\n"); 839967dd82fSFlorian Fainelli return -EINVAL; 840967dd82fSFlorian Fainelli } 841967dd82fSFlorian Fainelli } 842967dd82fSFlorian Fainelli 843967dd82fSFlorian Fainelli b53_enable_mib(dev); 844967dd82fSFlorian Fainelli 845ff39c2d6SFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_STATIC); 846967dd82fSFlorian Fainelli } 847967dd82fSFlorian Fainelli 848967dd82fSFlorian Fainelli static int b53_phy_read16(struct dsa_switch *ds, int addr, int reg) 849967dd82fSFlorian Fainelli { 85004bed143SVivien Didelot struct b53_device *priv = ds->priv; 851967dd82fSFlorian Fainelli u16 value = 0; 852967dd82fSFlorian Fainelli int ret; 853967dd82fSFlorian Fainelli 854967dd82fSFlorian Fainelli if (priv->ops->phy_read16) 855967dd82fSFlorian Fainelli ret = priv->ops->phy_read16(priv, addr, reg, &value); 856967dd82fSFlorian Fainelli else 857967dd82fSFlorian Fainelli ret = b53_read16(priv, B53_PORT_MII_PAGE(addr), 858967dd82fSFlorian Fainelli reg * 2, &value); 859967dd82fSFlorian Fainelli 860967dd82fSFlorian Fainelli return ret ? ret : value; 861967dd82fSFlorian Fainelli } 862967dd82fSFlorian Fainelli 863967dd82fSFlorian Fainelli static int b53_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val) 864967dd82fSFlorian Fainelli { 86504bed143SVivien Didelot struct b53_device *priv = ds->priv; 866967dd82fSFlorian Fainelli 867967dd82fSFlorian Fainelli if (priv->ops->phy_write16) 868967dd82fSFlorian Fainelli return priv->ops->phy_write16(priv, addr, reg, val); 869967dd82fSFlorian Fainelli 870967dd82fSFlorian Fainelli return b53_write16(priv, B53_PORT_MII_PAGE(addr), reg * 2, val); 871967dd82fSFlorian Fainelli } 872967dd82fSFlorian Fainelli 873967dd82fSFlorian Fainelli static int b53_reset_switch(struct b53_device *priv) 874967dd82fSFlorian Fainelli { 875967dd82fSFlorian Fainelli /* reset vlans */ 876a2482d2cSFlorian Fainelli memset(priv->vlans, 0, sizeof(*priv->vlans) * priv->num_vlans); 877967dd82fSFlorian Fainelli memset(priv->ports, 0, sizeof(*priv->ports) * priv->num_ports); 878967dd82fSFlorian Fainelli 8790e01491dSFlorian Fainelli priv->serdes_lane = B53_INVALID_LANE; 8800e01491dSFlorian Fainelli 881967dd82fSFlorian Fainelli return b53_switch_reset(priv); 882967dd82fSFlorian Fainelli } 883967dd82fSFlorian Fainelli 884967dd82fSFlorian Fainelli static int b53_apply_config(struct b53_device *priv) 885967dd82fSFlorian Fainelli { 886967dd82fSFlorian Fainelli /* disable switching */ 887967dd82fSFlorian Fainelli b53_set_forwarding(priv, 0); 888967dd82fSFlorian Fainelli 8895c1a6eafSFlorian Fainelli b53_configure_vlan(priv->ds); 890967dd82fSFlorian Fainelli 891967dd82fSFlorian Fainelli /* enable switching */ 892967dd82fSFlorian Fainelli b53_set_forwarding(priv, 1); 893967dd82fSFlorian Fainelli 894967dd82fSFlorian Fainelli return 0; 895967dd82fSFlorian Fainelli } 896967dd82fSFlorian Fainelli 897967dd82fSFlorian Fainelli static void b53_reset_mib(struct b53_device *priv) 898967dd82fSFlorian Fainelli { 899967dd82fSFlorian Fainelli u8 gc; 900967dd82fSFlorian Fainelli 901967dd82fSFlorian Fainelli b53_read8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc); 902967dd82fSFlorian Fainelli 903967dd82fSFlorian Fainelli b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc | GC_RESET_MIB); 904967dd82fSFlorian Fainelli msleep(1); 905967dd82fSFlorian Fainelli b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc & ~GC_RESET_MIB); 906967dd82fSFlorian Fainelli msleep(1); 907967dd82fSFlorian Fainelli } 908967dd82fSFlorian Fainelli 909967dd82fSFlorian Fainelli static const struct b53_mib_desc *b53_get_mib(struct b53_device *dev) 910967dd82fSFlorian Fainelli { 911967dd82fSFlorian Fainelli if (is5365(dev)) 912967dd82fSFlorian Fainelli return b53_mibs_65; 913967dd82fSFlorian Fainelli else if (is63xx(dev)) 914967dd82fSFlorian Fainelli return b53_mibs_63xx; 915bde5d132SFlorian Fainelli else if (is58xx(dev)) 916bde5d132SFlorian Fainelli return b53_mibs_58xx; 917967dd82fSFlorian Fainelli else 918967dd82fSFlorian Fainelli return b53_mibs; 919967dd82fSFlorian Fainelli } 920967dd82fSFlorian Fainelli 921967dd82fSFlorian Fainelli static unsigned int b53_get_mib_size(struct b53_device *dev) 922967dd82fSFlorian Fainelli { 923967dd82fSFlorian Fainelli if (is5365(dev)) 924967dd82fSFlorian Fainelli return B53_MIBS_65_SIZE; 925967dd82fSFlorian Fainelli else if (is63xx(dev)) 926967dd82fSFlorian Fainelli return B53_MIBS_63XX_SIZE; 927bde5d132SFlorian Fainelli else if (is58xx(dev)) 928bde5d132SFlorian Fainelli return B53_MIBS_58XX_SIZE; 929967dd82fSFlorian Fainelli else 930967dd82fSFlorian Fainelli return B53_MIBS_SIZE; 931967dd82fSFlorian Fainelli } 932967dd82fSFlorian Fainelli 933c7d28c9dSFlorian Fainelli static struct phy_device *b53_get_phy_device(struct dsa_switch *ds, int port) 934c7d28c9dSFlorian Fainelli { 935c7d28c9dSFlorian Fainelli /* These ports typically do not have built-in PHYs */ 936c7d28c9dSFlorian Fainelli switch (port) { 937c7d28c9dSFlorian Fainelli case B53_CPU_PORT_25: 938c7d28c9dSFlorian Fainelli case 7: 939c7d28c9dSFlorian Fainelli case B53_CPU_PORT: 940c7d28c9dSFlorian Fainelli return NULL; 941c7d28c9dSFlorian Fainelli } 942c7d28c9dSFlorian Fainelli 943c7d28c9dSFlorian Fainelli return mdiobus_get_phy(ds->slave_mii_bus, port); 944c7d28c9dSFlorian Fainelli } 945c7d28c9dSFlorian Fainelli 94689f09048SFlorian Fainelli void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset, 94789f09048SFlorian Fainelli uint8_t *data) 948967dd82fSFlorian Fainelli { 94904bed143SVivien Didelot struct b53_device *dev = ds->priv; 950967dd82fSFlorian Fainelli const struct b53_mib_desc *mibs = b53_get_mib(dev); 951967dd82fSFlorian Fainelli unsigned int mib_size = b53_get_mib_size(dev); 952c7d28c9dSFlorian Fainelli struct phy_device *phydev; 953967dd82fSFlorian Fainelli unsigned int i; 954967dd82fSFlorian Fainelli 955c7d28c9dSFlorian Fainelli if (stringset == ETH_SS_STATS) { 956967dd82fSFlorian Fainelli for (i = 0; i < mib_size; i++) 957cd526676SFlorian Fainelli strlcpy(data + i * ETH_GSTRING_LEN, 958967dd82fSFlorian Fainelli mibs[i].name, ETH_GSTRING_LEN); 959c7d28c9dSFlorian Fainelli } else if (stringset == ETH_SS_PHY_STATS) { 960c7d28c9dSFlorian Fainelli phydev = b53_get_phy_device(ds, port); 961c7d28c9dSFlorian Fainelli if (!phydev) 962c7d28c9dSFlorian Fainelli return; 963c7d28c9dSFlorian Fainelli 964c7d28c9dSFlorian Fainelli phy_ethtool_get_strings(phydev, data); 965c7d28c9dSFlorian Fainelli } 966967dd82fSFlorian Fainelli } 9673117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_strings); 968967dd82fSFlorian Fainelli 9693117455dSFlorian Fainelli void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data) 970967dd82fSFlorian Fainelli { 97104bed143SVivien Didelot struct b53_device *dev = ds->priv; 972967dd82fSFlorian Fainelli const struct b53_mib_desc *mibs = b53_get_mib(dev); 973967dd82fSFlorian Fainelli unsigned int mib_size = b53_get_mib_size(dev); 974967dd82fSFlorian Fainelli const struct b53_mib_desc *s; 975967dd82fSFlorian Fainelli unsigned int i; 976967dd82fSFlorian Fainelli u64 val = 0; 977967dd82fSFlorian Fainelli 978967dd82fSFlorian Fainelli if (is5365(dev) && port == 5) 979967dd82fSFlorian Fainelli port = 8; 980967dd82fSFlorian Fainelli 981967dd82fSFlorian Fainelli mutex_lock(&dev->stats_mutex); 982967dd82fSFlorian Fainelli 983967dd82fSFlorian Fainelli for (i = 0; i < mib_size; i++) { 984967dd82fSFlorian Fainelli s = &mibs[i]; 985967dd82fSFlorian Fainelli 98651dca8a1SFlorian Fainelli if (s->size == 8) { 987967dd82fSFlorian Fainelli b53_read64(dev, B53_MIB_PAGE(port), s->offset, &val); 988967dd82fSFlorian Fainelli } else { 989967dd82fSFlorian Fainelli u32 val32; 990967dd82fSFlorian Fainelli 991967dd82fSFlorian Fainelli b53_read32(dev, B53_MIB_PAGE(port), s->offset, 992967dd82fSFlorian Fainelli &val32); 993967dd82fSFlorian Fainelli val = val32; 994967dd82fSFlorian Fainelli } 995967dd82fSFlorian Fainelli data[i] = (u64)val; 996967dd82fSFlorian Fainelli } 997967dd82fSFlorian Fainelli 998967dd82fSFlorian Fainelli mutex_unlock(&dev->stats_mutex); 999967dd82fSFlorian Fainelli } 10003117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_ethtool_stats); 1001967dd82fSFlorian Fainelli 1002c7d28c9dSFlorian Fainelli void b53_get_ethtool_phy_stats(struct dsa_switch *ds, int port, uint64_t *data) 1003c7d28c9dSFlorian Fainelli { 1004c7d28c9dSFlorian Fainelli struct phy_device *phydev; 1005c7d28c9dSFlorian Fainelli 1006c7d28c9dSFlorian Fainelli phydev = b53_get_phy_device(ds, port); 1007c7d28c9dSFlorian Fainelli if (!phydev) 1008c7d28c9dSFlorian Fainelli return; 1009c7d28c9dSFlorian Fainelli 1010c7d28c9dSFlorian Fainelli phy_ethtool_get_stats(phydev, NULL, data); 1011c7d28c9dSFlorian Fainelli } 1012c7d28c9dSFlorian Fainelli EXPORT_SYMBOL(b53_get_ethtool_phy_stats); 1013c7d28c9dSFlorian Fainelli 101489f09048SFlorian Fainelli int b53_get_sset_count(struct dsa_switch *ds, int port, int sset) 1015967dd82fSFlorian Fainelli { 101604bed143SVivien Didelot struct b53_device *dev = ds->priv; 1017c7d28c9dSFlorian Fainelli struct phy_device *phydev; 1018967dd82fSFlorian Fainelli 1019c7d28c9dSFlorian Fainelli if (sset == ETH_SS_STATS) { 1020c7d28c9dSFlorian Fainelli return b53_get_mib_size(dev); 1021c7d28c9dSFlorian Fainelli } else if (sset == ETH_SS_PHY_STATS) { 1022c7d28c9dSFlorian Fainelli phydev = b53_get_phy_device(ds, port); 1023c7d28c9dSFlorian Fainelli if (!phydev) 102489f09048SFlorian Fainelli return 0; 102589f09048SFlorian Fainelli 1026c7d28c9dSFlorian Fainelli return phy_ethtool_get_sset_count(phydev); 1027c7d28c9dSFlorian Fainelli } 1028c7d28c9dSFlorian Fainelli 1029c7d28c9dSFlorian Fainelli return 0; 1030967dd82fSFlorian Fainelli } 10313117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_sset_count); 1032967dd82fSFlorian Fainelli 10334f6a5cafSFlorian Fainelli enum b53_devlink_resource_id { 10344f6a5cafSFlorian Fainelli B53_DEVLINK_PARAM_ID_VLAN_TABLE, 10354f6a5cafSFlorian Fainelli }; 10364f6a5cafSFlorian Fainelli 10374f6a5cafSFlorian Fainelli static u64 b53_devlink_vlan_table_get(void *priv) 10384f6a5cafSFlorian Fainelli { 10394f6a5cafSFlorian Fainelli struct b53_device *dev = priv; 10404f6a5cafSFlorian Fainelli struct b53_vlan *vl; 10414f6a5cafSFlorian Fainelli unsigned int i; 10424f6a5cafSFlorian Fainelli u64 count = 0; 10434f6a5cafSFlorian Fainelli 10444f6a5cafSFlorian Fainelli for (i = 0; i < dev->num_vlans; i++) { 10454f6a5cafSFlorian Fainelli vl = &dev->vlans[i]; 10464f6a5cafSFlorian Fainelli if (vl->members) 10474f6a5cafSFlorian Fainelli count++; 10484f6a5cafSFlorian Fainelli } 10494f6a5cafSFlorian Fainelli 10504f6a5cafSFlorian Fainelli return count; 10514f6a5cafSFlorian Fainelli } 10524f6a5cafSFlorian Fainelli 10534f6a5cafSFlorian Fainelli int b53_setup_devlink_resources(struct dsa_switch *ds) 10544f6a5cafSFlorian Fainelli { 10554f6a5cafSFlorian Fainelli struct devlink_resource_size_params size_params; 10564f6a5cafSFlorian Fainelli struct b53_device *dev = ds->priv; 10574f6a5cafSFlorian Fainelli int err; 10584f6a5cafSFlorian Fainelli 10594f6a5cafSFlorian Fainelli devlink_resource_size_params_init(&size_params, dev->num_vlans, 10604f6a5cafSFlorian Fainelli dev->num_vlans, 10614f6a5cafSFlorian Fainelli 1, DEVLINK_RESOURCE_UNIT_ENTRY); 10624f6a5cafSFlorian Fainelli 10634f6a5cafSFlorian Fainelli err = dsa_devlink_resource_register(ds, "VLAN", dev->num_vlans, 10644f6a5cafSFlorian Fainelli B53_DEVLINK_PARAM_ID_VLAN_TABLE, 10654f6a5cafSFlorian Fainelli DEVLINK_RESOURCE_ID_PARENT_TOP, 10664f6a5cafSFlorian Fainelli &size_params); 10674f6a5cafSFlorian Fainelli if (err) 10684f6a5cafSFlorian Fainelli goto out; 10694f6a5cafSFlorian Fainelli 10704f6a5cafSFlorian Fainelli dsa_devlink_resource_occ_get_register(ds, 10714f6a5cafSFlorian Fainelli B53_DEVLINK_PARAM_ID_VLAN_TABLE, 10724f6a5cafSFlorian Fainelli b53_devlink_vlan_table_get, dev); 10734f6a5cafSFlorian Fainelli 10744f6a5cafSFlorian Fainelli return 0; 10754f6a5cafSFlorian Fainelli out: 10764f6a5cafSFlorian Fainelli dsa_devlink_resources_unregister(ds); 10774f6a5cafSFlorian Fainelli return err; 10784f6a5cafSFlorian Fainelli } 10794f6a5cafSFlorian Fainelli EXPORT_SYMBOL(b53_setup_devlink_resources); 10804f6a5cafSFlorian Fainelli 1081967dd82fSFlorian Fainelli static int b53_setup(struct dsa_switch *ds) 1082967dd82fSFlorian Fainelli { 108304bed143SVivien Didelot struct b53_device *dev = ds->priv; 1084967dd82fSFlorian Fainelli unsigned int port; 1085967dd82fSFlorian Fainelli int ret; 1086967dd82fSFlorian Fainelli 1087967dd82fSFlorian Fainelli ret = b53_reset_switch(dev); 1088967dd82fSFlorian Fainelli if (ret) { 1089967dd82fSFlorian Fainelli dev_err(ds->dev, "failed to reset switch\n"); 1090967dd82fSFlorian Fainelli return ret; 1091967dd82fSFlorian Fainelli } 1092967dd82fSFlorian Fainelli 1093967dd82fSFlorian Fainelli b53_reset_mib(dev); 1094967dd82fSFlorian Fainelli 1095967dd82fSFlorian Fainelli ret = b53_apply_config(dev); 10964f6a5cafSFlorian Fainelli if (ret) { 1097967dd82fSFlorian Fainelli dev_err(ds->dev, "failed to apply configuration\n"); 10984f6a5cafSFlorian Fainelli return ret; 10994f6a5cafSFlorian Fainelli } 1100967dd82fSFlorian Fainelli 110175dad252SBenedikt Spranger /* Configure IMP/CPU port, disable all other ports. Enabled 110234c8befdSFlorian Fainelli * ports will be configured with .port_enable 110334c8befdSFlorian Fainelli */ 1104967dd82fSFlorian Fainelli for (port = 0; port < dev->num_ports; port++) { 110534c8befdSFlorian Fainelli if (dsa_is_cpu_port(ds, port)) 1106299752a7SFlorian Fainelli b53_enable_cpu_port(dev, port); 110775dad252SBenedikt Spranger else 110875104db0SAndrew Lunn b53_disable_port(ds, port); 1109967dd82fSFlorian Fainelli } 1110967dd82fSFlorian Fainelli 11117228b23eSVladimir Oltean /* Let DSA handle the case were multiple bridges span the same switch 11127228b23eSVladimir Oltean * device and different VLAN awareness settings are requested, which 11137228b23eSVladimir Oltean * would be breaking filtering semantics for any of the other bridge 11147228b23eSVladimir Oltean * devices. (not hardware supported) 11157228b23eSVladimir Oltean */ 11167228b23eSVladimir Oltean ds->vlan_filtering_is_global = true; 11177228b23eSVladimir Oltean 11184f6a5cafSFlorian Fainelli return b53_setup_devlink_resources(ds); 11194f6a5cafSFlorian Fainelli } 11204f6a5cafSFlorian Fainelli 11214f6a5cafSFlorian Fainelli static void b53_teardown(struct dsa_switch *ds) 11224f6a5cafSFlorian Fainelli { 11234f6a5cafSFlorian Fainelli dsa_devlink_resources_unregister(ds); 1124967dd82fSFlorian Fainelli } 1125967dd82fSFlorian Fainelli 11265e004460SFlorian Fainelli static void b53_force_link(struct b53_device *dev, int port, int link) 1127967dd82fSFlorian Fainelli { 11285e004460SFlorian Fainelli u8 reg, val, off; 1129967dd82fSFlorian Fainelli 1130967dd82fSFlorian Fainelli /* Override the port settings */ 1131967dd82fSFlorian Fainelli if (port == dev->cpu_port) { 1132967dd82fSFlorian Fainelli off = B53_PORT_OVERRIDE_CTRL; 11335e004460SFlorian Fainelli val = PORT_OVERRIDE_EN; 1134967dd82fSFlorian Fainelli } else { 1135967dd82fSFlorian Fainelli off = B53_GMII_PORT_OVERRIDE_CTRL(port); 11365e004460SFlorian Fainelli val = GMII_PO_EN; 1137967dd82fSFlorian Fainelli } 1138967dd82fSFlorian Fainelli 11395e004460SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, off, ®); 11405e004460SFlorian Fainelli reg |= val; 11415e004460SFlorian Fainelli if (link) 1142967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_LINK; 11435e004460SFlorian Fainelli else 11445e004460SFlorian Fainelli reg &= ~PORT_OVERRIDE_LINK; 11455e004460SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, off, reg); 11465e004460SFlorian Fainelli } 1147967dd82fSFlorian Fainelli 11485e004460SFlorian Fainelli static void b53_force_port_config(struct b53_device *dev, int port, 11493cad1c8bSRussell King int speed, int duplex, 11503cad1c8bSRussell King bool tx_pause, bool rx_pause) 11515e004460SFlorian Fainelli { 11525e004460SFlorian Fainelli u8 reg, val, off; 11535e004460SFlorian Fainelli 11545e004460SFlorian Fainelli /* Override the port settings */ 11555e004460SFlorian Fainelli if (port == dev->cpu_port) { 11565e004460SFlorian Fainelli off = B53_PORT_OVERRIDE_CTRL; 11575e004460SFlorian Fainelli val = PORT_OVERRIDE_EN; 11585e004460SFlorian Fainelli } else { 11595e004460SFlorian Fainelli off = B53_GMII_PORT_OVERRIDE_CTRL(port); 11605e004460SFlorian Fainelli val = GMII_PO_EN; 11615e004460SFlorian Fainelli } 11625e004460SFlorian Fainelli 11635e004460SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, off, ®); 11645e004460SFlorian Fainelli reg |= val; 11655e004460SFlorian Fainelli if (duplex == DUPLEX_FULL) 1166967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_FULL_DUPLEX; 11675e004460SFlorian Fainelli else 11685e004460SFlorian Fainelli reg &= ~PORT_OVERRIDE_FULL_DUPLEX; 1169967dd82fSFlorian Fainelli 11705e004460SFlorian Fainelli switch (speed) { 1171967dd82fSFlorian Fainelli case 2000: 1172967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_2000M; 1173df561f66SGustavo A. R. Silva fallthrough; 1174967dd82fSFlorian Fainelli case SPEED_1000: 1175967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_1000M; 1176967dd82fSFlorian Fainelli break; 1177967dd82fSFlorian Fainelli case SPEED_100: 1178967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_100M; 1179967dd82fSFlorian Fainelli break; 1180967dd82fSFlorian Fainelli case SPEED_10: 1181967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_10M; 1182967dd82fSFlorian Fainelli break; 1183967dd82fSFlorian Fainelli default: 11845e004460SFlorian Fainelli dev_err(dev->dev, "unknown speed: %d\n", speed); 1185967dd82fSFlorian Fainelli return; 1186967dd82fSFlorian Fainelli } 1187967dd82fSFlorian Fainelli 11883cad1c8bSRussell King if (rx_pause) 11895e004460SFlorian Fainelli reg |= PORT_OVERRIDE_RX_FLOW; 11903cad1c8bSRussell King if (tx_pause) 11915e004460SFlorian Fainelli reg |= PORT_OVERRIDE_TX_FLOW; 11925e004460SFlorian Fainelli 11935e004460SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, off, reg); 11945e004460SFlorian Fainelli } 11955e004460SFlorian Fainelli 11965e004460SFlorian Fainelli static void b53_adjust_link(struct dsa_switch *ds, int port, 11975e004460SFlorian Fainelli struct phy_device *phydev) 11985e004460SFlorian Fainelli { 11995e004460SFlorian Fainelli struct b53_device *dev = ds->priv; 12005e004460SFlorian Fainelli struct ethtool_eee *p = &dev->ports[port].eee; 12015e004460SFlorian Fainelli u8 rgmii_ctrl = 0, reg = 0, off; 12023cad1c8bSRussell King bool tx_pause = false; 12033cad1c8bSRussell King bool rx_pause = false; 12045e004460SFlorian Fainelli 12055e004460SFlorian Fainelli if (!phy_is_pseudo_fixed_link(phydev)) 12065e004460SFlorian Fainelli return; 12075e004460SFlorian Fainelli 1208967dd82fSFlorian Fainelli /* Enable flow control on BCM5301x's CPU port */ 1209967dd82fSFlorian Fainelli if (is5301x(dev) && port == dev->cpu_port) 12103cad1c8bSRussell King tx_pause = rx_pause = true; 1211967dd82fSFlorian Fainelli 1212967dd82fSFlorian Fainelli if (phydev->pause) { 1213967dd82fSFlorian Fainelli if (phydev->asym_pause) 12143cad1c8bSRussell King tx_pause = true; 12153cad1c8bSRussell King rx_pause = true; 1216967dd82fSFlorian Fainelli } 1217967dd82fSFlorian Fainelli 12183cad1c8bSRussell King b53_force_port_config(dev, port, phydev->speed, phydev->duplex, 12193cad1c8bSRussell King tx_pause, rx_pause); 12205e004460SFlorian Fainelli b53_force_link(dev, port, phydev->link); 1221967dd82fSFlorian Fainelli 1222967dd82fSFlorian Fainelli if (is531x5(dev) && phy_interface_is_rgmii(phydev)) { 1223967dd82fSFlorian Fainelli if (port == 8) 1224967dd82fSFlorian Fainelli off = B53_RGMII_CTRL_IMP; 1225967dd82fSFlorian Fainelli else 1226967dd82fSFlorian Fainelli off = B53_RGMII_CTRL_P(port); 1227967dd82fSFlorian Fainelli 1228967dd82fSFlorian Fainelli /* Configure the port RGMII clock delay by DLL disabled and 1229967dd82fSFlorian Fainelli * tx_clk aligned timing (restoring to reset defaults) 1230967dd82fSFlorian Fainelli */ 1231967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, off, &rgmii_ctrl); 1232967dd82fSFlorian Fainelli rgmii_ctrl &= ~(RGMII_CTRL_DLL_RXC | RGMII_CTRL_DLL_TXC | 1233967dd82fSFlorian Fainelli RGMII_CTRL_TIMING_SEL); 1234967dd82fSFlorian Fainelli 1235967dd82fSFlorian Fainelli /* PHY_INTERFACE_MODE_RGMII_TXID means TX internal delay, make 1236967dd82fSFlorian Fainelli * sure that we enable the port TX clock internal delay to 1237967dd82fSFlorian Fainelli * account for this internal delay that is inserted, otherwise 1238967dd82fSFlorian Fainelli * the switch won't be able to receive correctly. 1239967dd82fSFlorian Fainelli * 1240967dd82fSFlorian Fainelli * PHY_INTERFACE_MODE_RGMII means that we are not introducing 1241967dd82fSFlorian Fainelli * any delay neither on transmission nor reception, so the 1242967dd82fSFlorian Fainelli * BCM53125 must also be configured accordingly to account for 1243967dd82fSFlorian Fainelli * the lack of delay and introduce 1244967dd82fSFlorian Fainelli * 1245967dd82fSFlorian Fainelli * The BCM53125 switch has its RX clock and TX clock control 1246967dd82fSFlorian Fainelli * swapped, hence the reason why we modify the TX clock path in 1247967dd82fSFlorian Fainelli * the "RGMII" case 1248967dd82fSFlorian Fainelli */ 1249967dd82fSFlorian Fainelli if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) 1250967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_DLL_TXC; 1251967dd82fSFlorian Fainelli if (phydev->interface == PHY_INTERFACE_MODE_RGMII) 1252967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_DLL_TXC | RGMII_CTRL_DLL_RXC; 1253967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_TIMING_SEL; 1254967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, off, rgmii_ctrl); 1255967dd82fSFlorian Fainelli 1256967dd82fSFlorian Fainelli dev_info(ds->dev, "Configured port %d for %s\n", port, 1257967dd82fSFlorian Fainelli phy_modes(phydev->interface)); 1258967dd82fSFlorian Fainelli } 1259967dd82fSFlorian Fainelli 1260967dd82fSFlorian Fainelli /* configure MII port if necessary */ 1261967dd82fSFlorian Fainelli if (is5325(dev)) { 1262967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, 1263967dd82fSFlorian Fainelli ®); 1264967dd82fSFlorian Fainelli 1265967dd82fSFlorian Fainelli /* reverse mii needs to be enabled */ 1266967dd82fSFlorian Fainelli if (!(reg & PORT_OVERRIDE_RV_MII_25)) { 1267967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, 1268967dd82fSFlorian Fainelli reg | PORT_OVERRIDE_RV_MII_25); 1269967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, 1270967dd82fSFlorian Fainelli ®); 1271967dd82fSFlorian Fainelli 1272967dd82fSFlorian Fainelli if (!(reg & PORT_OVERRIDE_RV_MII_25)) { 1273967dd82fSFlorian Fainelli dev_err(ds->dev, 1274967dd82fSFlorian Fainelli "Failed to enable reverse MII mode\n"); 1275967dd82fSFlorian Fainelli return; 1276967dd82fSFlorian Fainelli } 1277967dd82fSFlorian Fainelli } 1278967dd82fSFlorian Fainelli } else if (is5301x(dev)) { 1279967dd82fSFlorian Fainelli if (port != dev->cpu_port) { 12805e004460SFlorian Fainelli b53_force_port_config(dev, dev->cpu_port, 2000, 12813cad1c8bSRussell King DUPLEX_FULL, true, true); 12825e004460SFlorian Fainelli b53_force_link(dev, dev->cpu_port, 1); 1283967dd82fSFlorian Fainelli } 1284967dd82fSFlorian Fainelli } 1285f43a2dbeSFlorian Fainelli 1286f43a2dbeSFlorian Fainelli /* Re-negotiate EEE if it was enabled already */ 1287f43a2dbeSFlorian Fainelli p->eee_enabled = b53_eee_init(ds, port, phydev); 1288967dd82fSFlorian Fainelli } 1289967dd82fSFlorian Fainelli 1290a8e8b985SFlorian Fainelli void b53_port_event(struct dsa_switch *ds, int port) 1291a8e8b985SFlorian Fainelli { 1292a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1293a8e8b985SFlorian Fainelli bool link; 1294a8e8b985SFlorian Fainelli u16 sts; 1295a8e8b985SFlorian Fainelli 1296a8e8b985SFlorian Fainelli b53_read16(dev, B53_STAT_PAGE, B53_LINK_STAT, &sts); 1297a8e8b985SFlorian Fainelli link = !!(sts & BIT(port)); 1298a8e8b985SFlorian Fainelli dsa_port_phylink_mac_change(ds, port, link); 1299a8e8b985SFlorian Fainelli } 1300a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_port_event); 1301a8e8b985SFlorian Fainelli 1302a8e8b985SFlorian Fainelli void b53_phylink_validate(struct dsa_switch *ds, int port, 1303a8e8b985SFlorian Fainelli unsigned long *supported, 1304a8e8b985SFlorian Fainelli struct phylink_link_state *state) 1305a8e8b985SFlorian Fainelli { 1306a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1307a8e8b985SFlorian Fainelli __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, }; 1308a8e8b985SFlorian Fainelli 13090e01491dSFlorian Fainelli if (dev->ops->serdes_phylink_validate) 13100e01491dSFlorian Fainelli dev->ops->serdes_phylink_validate(dev, port, mask, state); 13110e01491dSFlorian Fainelli 1312a8e8b985SFlorian Fainelli /* Allow all the expected bits */ 1313a8e8b985SFlorian Fainelli phylink_set(mask, Autoneg); 1314a8e8b985SFlorian Fainelli phylink_set_port_modes(mask); 1315a8e8b985SFlorian Fainelli phylink_set(mask, Pause); 1316a8e8b985SFlorian Fainelli phylink_set(mask, Asym_Pause); 1317a8e8b985SFlorian Fainelli 1318a8e8b985SFlorian Fainelli /* With the exclusion of 5325/5365, MII, Reverse MII and 802.3z, we 1319a8e8b985SFlorian Fainelli * support Gigabit, including Half duplex. 1320a8e8b985SFlorian Fainelli */ 1321a8e8b985SFlorian Fainelli if (state->interface != PHY_INTERFACE_MODE_MII && 1322a8e8b985SFlorian Fainelli state->interface != PHY_INTERFACE_MODE_REVMII && 1323a8e8b985SFlorian Fainelli !phy_interface_mode_is_8023z(state->interface) && 1324a8e8b985SFlorian Fainelli !(is5325(dev) || is5365(dev))) { 1325a8e8b985SFlorian Fainelli phylink_set(mask, 1000baseT_Full); 1326a8e8b985SFlorian Fainelli phylink_set(mask, 1000baseT_Half); 1327a8e8b985SFlorian Fainelli } 1328a8e8b985SFlorian Fainelli 1329a8e8b985SFlorian Fainelli if (!phy_interface_mode_is_8023z(state->interface)) { 1330a8e8b985SFlorian Fainelli phylink_set(mask, 10baseT_Half); 1331a8e8b985SFlorian Fainelli phylink_set(mask, 10baseT_Full); 1332a8e8b985SFlorian Fainelli phylink_set(mask, 100baseT_Half); 1333a8e8b985SFlorian Fainelli phylink_set(mask, 100baseT_Full); 1334a8e8b985SFlorian Fainelli } 1335a8e8b985SFlorian Fainelli 1336a8e8b985SFlorian Fainelli bitmap_and(supported, supported, mask, 1337a8e8b985SFlorian Fainelli __ETHTOOL_LINK_MODE_MASK_NBITS); 1338a8e8b985SFlorian Fainelli bitmap_and(state->advertising, state->advertising, mask, 1339a8e8b985SFlorian Fainelli __ETHTOOL_LINK_MODE_MASK_NBITS); 1340a8e8b985SFlorian Fainelli 1341a8e8b985SFlorian Fainelli phylink_helper_basex_speed(state); 1342a8e8b985SFlorian Fainelli } 1343a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_validate); 1344a8e8b985SFlorian Fainelli 1345a8e8b985SFlorian Fainelli int b53_phylink_mac_link_state(struct dsa_switch *ds, int port, 1346a8e8b985SFlorian Fainelli struct phylink_link_state *state) 1347a8e8b985SFlorian Fainelli { 13480e01491dSFlorian Fainelli struct b53_device *dev = ds->priv; 1349a8e8b985SFlorian Fainelli int ret = -EOPNOTSUPP; 1350a8e8b985SFlorian Fainelli 135155a4d2eaSFlorian Fainelli if ((phy_interface_mode_is_8023z(state->interface) || 135255a4d2eaSFlorian Fainelli state->interface == PHY_INTERFACE_MODE_SGMII) && 13530e01491dSFlorian Fainelli dev->ops->serdes_link_state) 13540e01491dSFlorian Fainelli ret = dev->ops->serdes_link_state(dev, port, state); 13550e01491dSFlorian Fainelli 1356a8e8b985SFlorian Fainelli return ret; 1357a8e8b985SFlorian Fainelli } 1358a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_state); 1359a8e8b985SFlorian Fainelli 1360a8e8b985SFlorian Fainelli void b53_phylink_mac_config(struct dsa_switch *ds, int port, 1361a8e8b985SFlorian Fainelli unsigned int mode, 1362a8e8b985SFlorian Fainelli const struct phylink_link_state *state) 1363a8e8b985SFlorian Fainelli { 1364a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1365a8e8b985SFlorian Fainelli 1366ab017b79SRussell King if (mode == MLO_AN_PHY || mode == MLO_AN_FIXED) 1367a8e8b985SFlorian Fainelli return; 1368a8e8b985SFlorian Fainelli 136955a4d2eaSFlorian Fainelli if ((phy_interface_mode_is_8023z(state->interface) || 137055a4d2eaSFlorian Fainelli state->interface == PHY_INTERFACE_MODE_SGMII) && 13710e01491dSFlorian Fainelli dev->ops->serdes_config) 13720e01491dSFlorian Fainelli dev->ops->serdes_config(dev, port, mode, state); 1373a8e8b985SFlorian Fainelli } 1374a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_config); 1375a8e8b985SFlorian Fainelli 1376a8e8b985SFlorian Fainelli void b53_phylink_mac_an_restart(struct dsa_switch *ds, int port) 1377a8e8b985SFlorian Fainelli { 13780e01491dSFlorian Fainelli struct b53_device *dev = ds->priv; 13790e01491dSFlorian Fainelli 13800e01491dSFlorian Fainelli if (dev->ops->serdes_an_restart) 13810e01491dSFlorian Fainelli dev->ops->serdes_an_restart(dev, port); 1382a8e8b985SFlorian Fainelli } 1383a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_an_restart); 1384a8e8b985SFlorian Fainelli 1385a8e8b985SFlorian Fainelli void b53_phylink_mac_link_down(struct dsa_switch *ds, int port, 1386a8e8b985SFlorian Fainelli unsigned int mode, 1387a8e8b985SFlorian Fainelli phy_interface_t interface) 1388a8e8b985SFlorian Fainelli { 1389a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1390a8e8b985SFlorian Fainelli 1391a8e8b985SFlorian Fainelli if (mode == MLO_AN_PHY) 1392a8e8b985SFlorian Fainelli return; 1393a8e8b985SFlorian Fainelli 1394a8e8b985SFlorian Fainelli if (mode == MLO_AN_FIXED) { 1395a8e8b985SFlorian Fainelli b53_force_link(dev, port, false); 1396a8e8b985SFlorian Fainelli return; 1397a8e8b985SFlorian Fainelli } 13980e01491dSFlorian Fainelli 13990e01491dSFlorian Fainelli if (phy_interface_mode_is_8023z(interface) && 14000e01491dSFlorian Fainelli dev->ops->serdes_link_set) 14010e01491dSFlorian Fainelli dev->ops->serdes_link_set(dev, port, mode, interface, false); 1402a8e8b985SFlorian Fainelli } 1403a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_down); 1404a8e8b985SFlorian Fainelli 1405a8e8b985SFlorian Fainelli void b53_phylink_mac_link_up(struct dsa_switch *ds, int port, 1406a8e8b985SFlorian Fainelli unsigned int mode, 1407a8e8b985SFlorian Fainelli phy_interface_t interface, 14085b502a7bSRussell King struct phy_device *phydev, 14095b502a7bSRussell King int speed, int duplex, 14105b502a7bSRussell King bool tx_pause, bool rx_pause) 1411a8e8b985SFlorian Fainelli { 1412a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1413a8e8b985SFlorian Fainelli 1414a8e8b985SFlorian Fainelli if (mode == MLO_AN_PHY) 1415a8e8b985SFlorian Fainelli return; 1416a8e8b985SFlorian Fainelli 1417a8e8b985SFlorian Fainelli if (mode == MLO_AN_FIXED) { 1418ab017b79SRussell King b53_force_port_config(dev, port, speed, duplex, 1419ab017b79SRussell King tx_pause, rx_pause); 1420a8e8b985SFlorian Fainelli b53_force_link(dev, port, true); 1421a8e8b985SFlorian Fainelli return; 1422a8e8b985SFlorian Fainelli } 14230e01491dSFlorian Fainelli 14240e01491dSFlorian Fainelli if (phy_interface_mode_is_8023z(interface) && 14250e01491dSFlorian Fainelli dev->ops->serdes_link_set) 14260e01491dSFlorian Fainelli dev->ops->serdes_link_set(dev, port, mode, interface, true); 1427a8e8b985SFlorian Fainelli } 1428a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_up); 1429a8e8b985SFlorian Fainelli 143089153ed6SVladimir Oltean int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering, 143189153ed6SVladimir Oltean struct netlink_ext_ack *extack) 1432a2482d2cSFlorian Fainelli { 1433dad8d7c6SFlorian Fainelli struct b53_device *dev = ds->priv; 1434dad8d7c6SFlorian Fainelli 1435ee47ed08SFlorian Fainelli b53_enable_vlan(dev, port, dev->vlan_enabled, vlan_filtering); 1436dad8d7c6SFlorian Fainelli 1437a2482d2cSFlorian Fainelli return 0; 1438a2482d2cSFlorian Fainelli } 14393117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_filtering); 1440a2482d2cSFlorian Fainelli 14411958d581SVladimir Oltean static int b53_vlan_prepare(struct dsa_switch *ds, int port, 144280e02360SVivien Didelot const struct switchdev_obj_port_vlan *vlan) 1443a2482d2cSFlorian Fainelli { 144404bed143SVivien Didelot struct b53_device *dev = ds->priv; 1445a2482d2cSFlorian Fainelli 1446b7a9e0daSVladimir Oltean if ((is5325(dev) || is5365(dev)) && vlan->vid == 0) 1447a2482d2cSFlorian Fainelli return -EOPNOTSUPP; 1448a2482d2cSFlorian Fainelli 144988631864SFlorian Fainelli /* Port 7 on 7278 connects to the ASP's UniMAC which is not capable of 145088631864SFlorian Fainelli * receiving VLAN tagged frames at all, we can still allow the port to 145188631864SFlorian Fainelli * be configured for egress untagged. 145288631864SFlorian Fainelli */ 145388631864SFlorian Fainelli if (dev->chip_id == BCM7278_DEVICE_ID && port == 7 && 145488631864SFlorian Fainelli !(vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED)) 145588631864SFlorian Fainelli return -EINVAL; 145688631864SFlorian Fainelli 14570fe2f273SJakub Kicinski if (vlan->vid >= dev->num_vlans) 1458a2482d2cSFlorian Fainelli return -ERANGE; 1459a2482d2cSFlorian Fainelli 1460ee47ed08SFlorian Fainelli b53_enable_vlan(dev, port, true, ds->vlan_filtering); 1461a2482d2cSFlorian Fainelli 1462a2482d2cSFlorian Fainelli return 0; 1463a2482d2cSFlorian Fainelli } 1464a2482d2cSFlorian Fainelli 14651958d581SVladimir Oltean int b53_vlan_add(struct dsa_switch *ds, int port, 146631046a5fSVladimir Oltean const struct switchdev_obj_port_vlan *vlan, 146731046a5fSVladimir Oltean struct netlink_ext_ack *extack) 1468a2482d2cSFlorian Fainelli { 146904bed143SVivien Didelot struct b53_device *dev = ds->priv; 1470a2482d2cSFlorian Fainelli bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; 1471a2482d2cSFlorian Fainelli bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID; 1472a2482d2cSFlorian Fainelli struct b53_vlan *vl; 14731958d581SVladimir Oltean int err; 14741958d581SVladimir Oltean 14751958d581SVladimir Oltean err = b53_vlan_prepare(ds, port, vlan); 14761958d581SVladimir Oltean if (err) 14771958d581SVladimir Oltean return err; 1478a2482d2cSFlorian Fainelli 1479b7a9e0daSVladimir Oltean vl = &dev->vlans[vlan->vid]; 1480a2482d2cSFlorian Fainelli 1481b7a9e0daSVladimir Oltean b53_get_vlan_entry(dev, vlan->vid, vl); 1482a2482d2cSFlorian Fainelli 1483b7a9e0daSVladimir Oltean if (vlan->vid == 0 && vlan->vid == b53_default_pvid(dev)) 1484d965a543SFlorian Fainelli untagged = true; 1485d965a543SFlorian Fainelli 1486c499696eSFlorian Fainelli vl->members |= BIT(port); 1487ca893194SFlorian Fainelli if (untagged && !dsa_is_cpu_port(ds, port)) 1488e47112d9SFlorian Fainelli vl->untag |= BIT(port); 1489a2482d2cSFlorian Fainelli else 1490e47112d9SFlorian Fainelli vl->untag &= ~BIT(port); 1491a2482d2cSFlorian Fainelli 1492b7a9e0daSVladimir Oltean b53_set_vlan_entry(dev, vlan->vid, vl); 1493b7a9e0daSVladimir Oltean b53_fast_age_vlan(dev, vlan->vid); 1494a2482d2cSFlorian Fainelli 149510163aaeSFlorian Fainelli if (pvid && !dsa_is_cpu_port(ds, port)) { 1496a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), 1497b7a9e0daSVladimir Oltean vlan->vid); 1498b7a9e0daSVladimir Oltean b53_fast_age_vlan(dev, vlan->vid); 1499a2482d2cSFlorian Fainelli } 15001958d581SVladimir Oltean 15011958d581SVladimir Oltean return 0; 1502a2482d2cSFlorian Fainelli } 15033117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_add); 1504a2482d2cSFlorian Fainelli 15053117455dSFlorian Fainelli int b53_vlan_del(struct dsa_switch *ds, int port, 1506a2482d2cSFlorian Fainelli const struct switchdev_obj_port_vlan *vlan) 1507a2482d2cSFlorian Fainelli { 150804bed143SVivien Didelot struct b53_device *dev = ds->priv; 1509a2482d2cSFlorian Fainelli bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; 1510a2482d2cSFlorian Fainelli struct b53_vlan *vl; 1511a2482d2cSFlorian Fainelli u16 pvid; 1512a2482d2cSFlorian Fainelli 1513a2482d2cSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid); 1514a2482d2cSFlorian Fainelli 1515b7a9e0daSVladimir Oltean vl = &dev->vlans[vlan->vid]; 1516a2482d2cSFlorian Fainelli 1517b7a9e0daSVladimir Oltean b53_get_vlan_entry(dev, vlan->vid, vl); 1518a2482d2cSFlorian Fainelli 1519a2482d2cSFlorian Fainelli vl->members &= ~BIT(port); 1520a2482d2cSFlorian Fainelli 1521b7a9e0daSVladimir Oltean if (pvid == vlan->vid) 1522fea83353SFlorian Fainelli pvid = b53_default_pvid(dev); 1523a2482d2cSFlorian Fainelli 1524ca893194SFlorian Fainelli if (untagged && !dsa_is_cpu_port(ds, port)) 1525a2482d2cSFlorian Fainelli vl->untag &= ~(BIT(port)); 1526a2482d2cSFlorian Fainelli 1527b7a9e0daSVladimir Oltean b53_set_vlan_entry(dev, vlan->vid, vl); 1528b7a9e0daSVladimir Oltean b53_fast_age_vlan(dev, vlan->vid); 1529a2482d2cSFlorian Fainelli 1530a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), pvid); 1531a2482d2cSFlorian Fainelli b53_fast_age_vlan(dev, pvid); 1532a2482d2cSFlorian Fainelli 1533a2482d2cSFlorian Fainelli return 0; 1534a2482d2cSFlorian Fainelli } 15353117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_del); 1536a2482d2cSFlorian Fainelli 15371da6df85SFlorian Fainelli /* Address Resolution Logic routines */ 15381da6df85SFlorian Fainelli static int b53_arl_op_wait(struct b53_device *dev) 15391da6df85SFlorian Fainelli { 15401da6df85SFlorian Fainelli unsigned int timeout = 10; 15411da6df85SFlorian Fainelli u8 reg; 15421da6df85SFlorian Fainelli 15431da6df85SFlorian Fainelli do { 15441da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, ®); 15451da6df85SFlorian Fainelli if (!(reg & ARLTBL_START_DONE)) 15461da6df85SFlorian Fainelli return 0; 15471da6df85SFlorian Fainelli 15481da6df85SFlorian Fainelli usleep_range(1000, 2000); 15491da6df85SFlorian Fainelli } while (timeout--); 15501da6df85SFlorian Fainelli 15511da6df85SFlorian Fainelli dev_warn(dev->dev, "timeout waiting for ARL to finish: 0x%02x\n", reg); 15521da6df85SFlorian Fainelli 15531da6df85SFlorian Fainelli return -ETIMEDOUT; 15541da6df85SFlorian Fainelli } 15551da6df85SFlorian Fainelli 15561da6df85SFlorian Fainelli static int b53_arl_rw_op(struct b53_device *dev, unsigned int op) 15571da6df85SFlorian Fainelli { 15581da6df85SFlorian Fainelli u8 reg; 15591da6df85SFlorian Fainelli 15601da6df85SFlorian Fainelli if (op > ARLTBL_RW) 15611da6df85SFlorian Fainelli return -EINVAL; 15621da6df85SFlorian Fainelli 15631da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, ®); 15641da6df85SFlorian Fainelli reg |= ARLTBL_START_DONE; 15651da6df85SFlorian Fainelli if (op) 15661da6df85SFlorian Fainelli reg |= ARLTBL_RW; 15671da6df85SFlorian Fainelli else 15681da6df85SFlorian Fainelli reg &= ~ARLTBL_RW; 156964fec949SFlorian Fainelli if (dev->vlan_enabled) 157064fec949SFlorian Fainelli reg &= ~ARLTBL_IVL_SVL_SELECT; 157164fec949SFlorian Fainelli else 157264fec949SFlorian Fainelli reg |= ARLTBL_IVL_SVL_SELECT; 15731da6df85SFlorian Fainelli b53_write8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, reg); 15741da6df85SFlorian Fainelli 15751da6df85SFlorian Fainelli return b53_arl_op_wait(dev); 15761da6df85SFlorian Fainelli } 15771da6df85SFlorian Fainelli 15781da6df85SFlorian Fainelli static int b53_arl_read(struct b53_device *dev, u64 mac, 1579ef2a0bd9SFlorian Fainelli u16 vid, struct b53_arl_entry *ent, u8 *idx) 15801da6df85SFlorian Fainelli { 15816344dbdeSFlorian Fainelli DECLARE_BITMAP(free_bins, B53_ARLTBL_MAX_BIN_ENTRIES); 15821da6df85SFlorian Fainelli unsigned int i; 15831da6df85SFlorian Fainelli int ret; 15841da6df85SFlorian Fainelli 15851da6df85SFlorian Fainelli ret = b53_arl_op_wait(dev); 15861da6df85SFlorian Fainelli if (ret) 15871da6df85SFlorian Fainelli return ret; 15881da6df85SFlorian Fainelli 1589673e69a6SFlorian Fainelli bitmap_zero(free_bins, dev->num_arl_bins); 15906344dbdeSFlorian Fainelli 15911da6df85SFlorian Fainelli /* Read the bins */ 1592673e69a6SFlorian Fainelli for (i = 0; i < dev->num_arl_bins; i++) { 15931da6df85SFlorian Fainelli u64 mac_vid; 15941da6df85SFlorian Fainelli u32 fwd_entry; 15951da6df85SFlorian Fainelli 15961da6df85SFlorian Fainelli b53_read64(dev, B53_ARLIO_PAGE, 15971da6df85SFlorian Fainelli B53_ARLTBL_MAC_VID_ENTRY(i), &mac_vid); 15981da6df85SFlorian Fainelli b53_read32(dev, B53_ARLIO_PAGE, 15991da6df85SFlorian Fainelli B53_ARLTBL_DATA_ENTRY(i), &fwd_entry); 16001da6df85SFlorian Fainelli b53_arl_to_entry(ent, mac_vid, fwd_entry); 16011da6df85SFlorian Fainelli 16026344dbdeSFlorian Fainelli if (!(fwd_entry & ARLTBL_VALID)) { 16036344dbdeSFlorian Fainelli set_bit(i, free_bins); 16041da6df85SFlorian Fainelli continue; 16056344dbdeSFlorian Fainelli } 16061da6df85SFlorian Fainelli if ((mac_vid & ARLTBL_MAC_MASK) != mac) 16071da6df85SFlorian Fainelli continue; 16082e97b0cdSFlorian Fainelli if (dev->vlan_enabled && 16092e97b0cdSFlorian Fainelli ((mac_vid >> ARLTBL_VID_S) & ARLTBL_VID_MASK) != vid) 16102e97b0cdSFlorian Fainelli continue; 16111da6df85SFlorian Fainelli *idx = i; 16126344dbdeSFlorian Fainelli return 0; 16131da6df85SFlorian Fainelli } 16141da6df85SFlorian Fainelli 1615673e69a6SFlorian Fainelli if (bitmap_weight(free_bins, dev->num_arl_bins) == 0) 16166344dbdeSFlorian Fainelli return -ENOSPC; 16176344dbdeSFlorian Fainelli 1618673e69a6SFlorian Fainelli *idx = find_first_bit(free_bins, dev->num_arl_bins); 16196344dbdeSFlorian Fainelli 16201da6df85SFlorian Fainelli return -ENOENT; 16211da6df85SFlorian Fainelli } 16221da6df85SFlorian Fainelli 16231da6df85SFlorian Fainelli static int b53_arl_op(struct b53_device *dev, int op, int port, 16241da6df85SFlorian Fainelli const unsigned char *addr, u16 vid, bool is_valid) 16251da6df85SFlorian Fainelli { 16261da6df85SFlorian Fainelli struct b53_arl_entry ent; 16271da6df85SFlorian Fainelli u32 fwd_entry; 16281da6df85SFlorian Fainelli u64 mac, mac_vid = 0; 16291da6df85SFlorian Fainelli u8 idx = 0; 16301da6df85SFlorian Fainelli int ret; 16311da6df85SFlorian Fainelli 16321da6df85SFlorian Fainelli /* Convert the array into a 64-bit MAC */ 16334b92ea81SFlorian Fainelli mac = ether_addr_to_u64(addr); 16341da6df85SFlorian Fainelli 16351da6df85SFlorian Fainelli /* Perform a read for the given MAC and VID */ 16361da6df85SFlorian Fainelli b53_write48(dev, B53_ARLIO_PAGE, B53_MAC_ADDR_IDX, mac); 16371da6df85SFlorian Fainelli b53_write16(dev, B53_ARLIO_PAGE, B53_VLAN_ID_IDX, vid); 16381da6df85SFlorian Fainelli 16391da6df85SFlorian Fainelli /* Issue a read operation for this MAC */ 16401da6df85SFlorian Fainelli ret = b53_arl_rw_op(dev, 1); 16411da6df85SFlorian Fainelli if (ret) 16421da6df85SFlorian Fainelli return ret; 16431da6df85SFlorian Fainelli 1644ef2a0bd9SFlorian Fainelli ret = b53_arl_read(dev, mac, vid, &ent, &idx); 1645ef2a0bd9SFlorian Fainelli 16461da6df85SFlorian Fainelli /* If this is a read, just finish now */ 16471da6df85SFlorian Fainelli if (op) 16481da6df85SFlorian Fainelli return ret; 16491da6df85SFlorian Fainelli 16506344dbdeSFlorian Fainelli switch (ret) { 1651774d977aSTom Rix case -ETIMEDOUT: 1652774d977aSTom Rix return ret; 16536344dbdeSFlorian Fainelli case -ENOSPC: 16546344dbdeSFlorian Fainelli dev_dbg(dev->dev, "{%pM,%.4d} no space left in ARL\n", 16556344dbdeSFlorian Fainelli addr, vid); 16566344dbdeSFlorian Fainelli return is_valid ? ret : 0; 16576344dbdeSFlorian Fainelli case -ENOENT: 16581da6df85SFlorian Fainelli /* We could not find a matching MAC, so reset to a new entry */ 16596344dbdeSFlorian Fainelli dev_dbg(dev->dev, "{%pM,%.4d} not found, using idx: %d\n", 16606344dbdeSFlorian Fainelli addr, vid, idx); 16611da6df85SFlorian Fainelli fwd_entry = 0; 16626344dbdeSFlorian Fainelli break; 16636344dbdeSFlorian Fainelli default: 16646344dbdeSFlorian Fainelli dev_dbg(dev->dev, "{%pM,%.4d} found, using idx: %d\n", 16656344dbdeSFlorian Fainelli addr, vid, idx); 16666344dbdeSFlorian Fainelli break; 16671da6df85SFlorian Fainelli } 16681da6df85SFlorian Fainelli 16695d65b64aSFlorian Fainelli /* For multicast address, the port is a bitmask and the validity 16705d65b64aSFlorian Fainelli * is determined by having at least one port being still active 16715d65b64aSFlorian Fainelli */ 16725d65b64aSFlorian Fainelli if (!is_multicast_ether_addr(addr)) { 16731da6df85SFlorian Fainelli ent.port = port; 16741da6df85SFlorian Fainelli ent.is_valid = is_valid; 16755d65b64aSFlorian Fainelli } else { 16765d65b64aSFlorian Fainelli if (is_valid) 16775d65b64aSFlorian Fainelli ent.port |= BIT(port); 16785d65b64aSFlorian Fainelli else 16795d65b64aSFlorian Fainelli ent.port &= ~BIT(port); 16805d65b64aSFlorian Fainelli 16815d65b64aSFlorian Fainelli ent.is_valid = !!(ent.port); 16825d65b64aSFlorian Fainelli } 16835d65b64aSFlorian Fainelli 16841da6df85SFlorian Fainelli ent.vid = vid; 16851da6df85SFlorian Fainelli ent.is_static = true; 16865d65b64aSFlorian Fainelli ent.is_age = false; 16871da6df85SFlorian Fainelli memcpy(ent.mac, addr, ETH_ALEN); 16881da6df85SFlorian Fainelli b53_arl_from_entry(&mac_vid, &fwd_entry, &ent); 16891da6df85SFlorian Fainelli 16901da6df85SFlorian Fainelli b53_write64(dev, B53_ARLIO_PAGE, 16911da6df85SFlorian Fainelli B53_ARLTBL_MAC_VID_ENTRY(idx), mac_vid); 16921da6df85SFlorian Fainelli b53_write32(dev, B53_ARLIO_PAGE, 16931da6df85SFlorian Fainelli B53_ARLTBL_DATA_ENTRY(idx), fwd_entry); 16941da6df85SFlorian Fainelli 16951da6df85SFlorian Fainelli return b53_arl_rw_op(dev, 0); 16961da6df85SFlorian Fainelli } 16971da6df85SFlorian Fainelli 16981b6dd556SArkadi Sharshevsky int b53_fdb_add(struct dsa_switch *ds, int port, 16996c2c1dcbSArkadi Sharshevsky const unsigned char *addr, u16 vid) 17001da6df85SFlorian Fainelli { 170104bed143SVivien Didelot struct b53_device *priv = ds->priv; 17021da6df85SFlorian Fainelli 17031da6df85SFlorian Fainelli /* 5325 and 5365 require some more massaging, but could 17041da6df85SFlorian Fainelli * be supported eventually 17051da6df85SFlorian Fainelli */ 17061da6df85SFlorian Fainelli if (is5325(priv) || is5365(priv)) 17071da6df85SFlorian Fainelli return -EOPNOTSUPP; 17081da6df85SFlorian Fainelli 17091b6dd556SArkadi Sharshevsky return b53_arl_op(priv, 0, port, addr, vid, true); 17101da6df85SFlorian Fainelli } 17113117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_add); 17121da6df85SFlorian Fainelli 17133117455dSFlorian Fainelli int b53_fdb_del(struct dsa_switch *ds, int port, 17146c2c1dcbSArkadi Sharshevsky const unsigned char *addr, u16 vid) 17151da6df85SFlorian Fainelli { 171604bed143SVivien Didelot struct b53_device *priv = ds->priv; 17171da6df85SFlorian Fainelli 17186c2c1dcbSArkadi Sharshevsky return b53_arl_op(priv, 0, port, addr, vid, false); 17191da6df85SFlorian Fainelli } 17203117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_del); 17211da6df85SFlorian Fainelli 17221da6df85SFlorian Fainelli static int b53_arl_search_wait(struct b53_device *dev) 17231da6df85SFlorian Fainelli { 17241da6df85SFlorian Fainelli unsigned int timeout = 1000; 17251da6df85SFlorian Fainelli u8 reg; 17261da6df85SFlorian Fainelli 17271da6df85SFlorian Fainelli do { 17281da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, ®); 17291da6df85SFlorian Fainelli if (!(reg & ARL_SRCH_STDN)) 17301da6df85SFlorian Fainelli return 0; 17311da6df85SFlorian Fainelli 17321da6df85SFlorian Fainelli if (reg & ARL_SRCH_VLID) 17331da6df85SFlorian Fainelli return 0; 17341da6df85SFlorian Fainelli 17351da6df85SFlorian Fainelli usleep_range(1000, 2000); 17361da6df85SFlorian Fainelli } while (timeout--); 17371da6df85SFlorian Fainelli 17381da6df85SFlorian Fainelli return -ETIMEDOUT; 17391da6df85SFlorian Fainelli } 17401da6df85SFlorian Fainelli 17411da6df85SFlorian Fainelli static void b53_arl_search_rd(struct b53_device *dev, u8 idx, 17421da6df85SFlorian Fainelli struct b53_arl_entry *ent) 17431da6df85SFlorian Fainelli { 17441da6df85SFlorian Fainelli u64 mac_vid; 17451da6df85SFlorian Fainelli u32 fwd_entry; 17461da6df85SFlorian Fainelli 17471da6df85SFlorian Fainelli b53_read64(dev, B53_ARLIO_PAGE, 17481da6df85SFlorian Fainelli B53_ARL_SRCH_RSTL_MACVID(idx), &mac_vid); 17491da6df85SFlorian Fainelli b53_read32(dev, B53_ARLIO_PAGE, 17501da6df85SFlorian Fainelli B53_ARL_SRCH_RSTL(idx), &fwd_entry); 17511da6df85SFlorian Fainelli b53_arl_to_entry(ent, mac_vid, fwd_entry); 17521da6df85SFlorian Fainelli } 17531da6df85SFlorian Fainelli 1754e6cbef0cSVivien Didelot static int b53_fdb_copy(int port, const struct b53_arl_entry *ent, 17552bedde1aSArkadi Sharshevsky dsa_fdb_dump_cb_t *cb, void *data) 17561da6df85SFlorian Fainelli { 17571da6df85SFlorian Fainelli if (!ent->is_valid) 17581da6df85SFlorian Fainelli return 0; 17591da6df85SFlorian Fainelli 17601da6df85SFlorian Fainelli if (port != ent->port) 17611da6df85SFlorian Fainelli return 0; 17621da6df85SFlorian Fainelli 17632bedde1aSArkadi Sharshevsky return cb(ent->mac, ent->vid, ent->is_static, data); 17641da6df85SFlorian Fainelli } 17651da6df85SFlorian Fainelli 17663117455dSFlorian Fainelli int b53_fdb_dump(struct dsa_switch *ds, int port, 17672bedde1aSArkadi Sharshevsky dsa_fdb_dump_cb_t *cb, void *data) 17681da6df85SFlorian Fainelli { 176904bed143SVivien Didelot struct b53_device *priv = ds->priv; 17701da6df85SFlorian Fainelli struct b53_arl_entry results[2]; 17711da6df85SFlorian Fainelli unsigned int count = 0; 17721da6df85SFlorian Fainelli int ret; 17731da6df85SFlorian Fainelli u8 reg; 17741da6df85SFlorian Fainelli 17751da6df85SFlorian Fainelli /* Start search operation */ 17761da6df85SFlorian Fainelli reg = ARL_SRCH_STDN; 17771da6df85SFlorian Fainelli b53_write8(priv, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, reg); 17781da6df85SFlorian Fainelli 17791da6df85SFlorian Fainelli do { 17801da6df85SFlorian Fainelli ret = b53_arl_search_wait(priv); 17811da6df85SFlorian Fainelli if (ret) 17821da6df85SFlorian Fainelli return ret; 17831da6df85SFlorian Fainelli 17841da6df85SFlorian Fainelli b53_arl_search_rd(priv, 0, &results[0]); 17852bedde1aSArkadi Sharshevsky ret = b53_fdb_copy(port, &results[0], cb, data); 17861da6df85SFlorian Fainelli if (ret) 17871da6df85SFlorian Fainelli return ret; 17881da6df85SFlorian Fainelli 1789673e69a6SFlorian Fainelli if (priv->num_arl_bins > 2) { 17901da6df85SFlorian Fainelli b53_arl_search_rd(priv, 1, &results[1]); 17912bedde1aSArkadi Sharshevsky ret = b53_fdb_copy(port, &results[1], cb, data); 17921da6df85SFlorian Fainelli if (ret) 17931da6df85SFlorian Fainelli return ret; 17941da6df85SFlorian Fainelli 17951da6df85SFlorian Fainelli if (!results[0].is_valid && !results[1].is_valid) 17961da6df85SFlorian Fainelli break; 17971da6df85SFlorian Fainelli } 17981da6df85SFlorian Fainelli 1799cd169d79SFlorian Fainelli } while (count++ < b53_max_arl_entries(priv) / 2); 18001da6df85SFlorian Fainelli 18011da6df85SFlorian Fainelli return 0; 18021da6df85SFlorian Fainelli } 18033117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_dump); 18041da6df85SFlorian Fainelli 1805a52b2da7SVladimir Oltean int b53_mdb_add(struct dsa_switch *ds, int port, 18065d65b64aSFlorian Fainelli const struct switchdev_obj_port_mdb *mdb) 18075d65b64aSFlorian Fainelli { 18085d65b64aSFlorian Fainelli struct b53_device *priv = ds->priv; 18095d65b64aSFlorian Fainelli 18105d65b64aSFlorian Fainelli /* 5325 and 5365 require some more massaging, but could 18115d65b64aSFlorian Fainelli * be supported eventually 18125d65b64aSFlorian Fainelli */ 18135d65b64aSFlorian Fainelli if (is5325(priv) || is5365(priv)) 18145d65b64aSFlorian Fainelli return -EOPNOTSUPP; 18155d65b64aSFlorian Fainelli 1816a52b2da7SVladimir Oltean return b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, true); 18175d65b64aSFlorian Fainelli } 18185d65b64aSFlorian Fainelli EXPORT_SYMBOL(b53_mdb_add); 18195d65b64aSFlorian Fainelli 18205d65b64aSFlorian Fainelli int b53_mdb_del(struct dsa_switch *ds, int port, 18215d65b64aSFlorian Fainelli const struct switchdev_obj_port_mdb *mdb) 18225d65b64aSFlorian Fainelli { 18235d65b64aSFlorian Fainelli struct b53_device *priv = ds->priv; 18245d65b64aSFlorian Fainelli int ret; 18255d65b64aSFlorian Fainelli 18265d65b64aSFlorian Fainelli ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, false); 18275d65b64aSFlorian Fainelli if (ret) 18285d65b64aSFlorian Fainelli dev_err(ds->dev, "failed to delete MDB entry\n"); 18295d65b64aSFlorian Fainelli 18305d65b64aSFlorian Fainelli return ret; 18315d65b64aSFlorian Fainelli } 18325d65b64aSFlorian Fainelli EXPORT_SYMBOL(b53_mdb_del); 18335d65b64aSFlorian Fainelli 1834ddd3a0c8SVivien Didelot int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br) 1835ff39c2d6SFlorian Fainelli { 183604bed143SVivien Didelot struct b53_device *dev = ds->priv; 183768bb8ea8SVivien Didelot s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index; 1838ff39c2d6SFlorian Fainelli u16 pvlan, reg; 1839ff39c2d6SFlorian Fainelli unsigned int i; 1840ff39c2d6SFlorian Fainelli 184131bfc2d4SFlorian Fainelli /* On 7278, port 7 which connects to the ASP should only receive 184231bfc2d4SFlorian Fainelli * traffic from matching CFP rules. 184331bfc2d4SFlorian Fainelli */ 184431bfc2d4SFlorian Fainelli if (dev->chip_id == BCM7278_DEVICE_ID && port == 7) 184531bfc2d4SFlorian Fainelli return -EINVAL; 184631bfc2d4SFlorian Fainelli 184748aea33aSFlorian Fainelli /* Make this port leave the all VLANs join since we will have proper 184848aea33aSFlorian Fainelli * VLAN entries from now on 184948aea33aSFlorian Fainelli */ 185048aea33aSFlorian Fainelli if (is58xx(dev)) { 185148aea33aSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, ®); 185248aea33aSFlorian Fainelli reg &= ~BIT(port); 185348aea33aSFlorian Fainelli if ((reg & BIT(cpu_port)) == BIT(cpu_port)) 185448aea33aSFlorian Fainelli reg &= ~BIT(cpu_port); 185548aea33aSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg); 185648aea33aSFlorian Fainelli } 185748aea33aSFlorian Fainelli 1858ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); 1859ff39c2d6SFlorian Fainelli 1860ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) { 1861c8652c83SVivien Didelot if (dsa_to_port(ds, i)->bridge_dev != br) 1862ff39c2d6SFlorian Fainelli continue; 1863ff39c2d6SFlorian Fainelli 1864ff39c2d6SFlorian Fainelli /* Add this local port to the remote port VLAN control 1865ff39c2d6SFlorian Fainelli * membership and update the remote port bitmask 1866ff39c2d6SFlorian Fainelli */ 1867ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), ®); 1868ff39c2d6SFlorian Fainelli reg |= BIT(port); 1869ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg); 1870ff39c2d6SFlorian Fainelli dev->ports[i].vlan_ctl_mask = reg; 1871ff39c2d6SFlorian Fainelli 1872ff39c2d6SFlorian Fainelli pvlan |= BIT(i); 1873ff39c2d6SFlorian Fainelli } 1874ff39c2d6SFlorian Fainelli 1875ff39c2d6SFlorian Fainelli /* Configure the local port VLAN control membership to include 1876ff39c2d6SFlorian Fainelli * remote ports and update the local port bitmask 1877ff39c2d6SFlorian Fainelli */ 1878ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); 1879ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = pvlan; 1880ff39c2d6SFlorian Fainelli 1881ff39c2d6SFlorian Fainelli return 0; 1882ff39c2d6SFlorian Fainelli } 18833117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_join); 1884ff39c2d6SFlorian Fainelli 1885f123f2fbSVivien Didelot void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *br) 1886ff39c2d6SFlorian Fainelli { 188704bed143SVivien Didelot struct b53_device *dev = ds->priv; 1888a2482d2cSFlorian Fainelli struct b53_vlan *vl = &dev->vlans[0]; 188968bb8ea8SVivien Didelot s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index; 1890ff39c2d6SFlorian Fainelli unsigned int i; 1891a2482d2cSFlorian Fainelli u16 pvlan, reg, pvid; 1892ff39c2d6SFlorian Fainelli 1893ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); 1894ff39c2d6SFlorian Fainelli 1895ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) { 1896ff39c2d6SFlorian Fainelli /* Don't touch the remaining ports */ 1897c8652c83SVivien Didelot if (dsa_to_port(ds, i)->bridge_dev != br) 1898ff39c2d6SFlorian Fainelli continue; 1899ff39c2d6SFlorian Fainelli 1900ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), ®); 1901ff39c2d6SFlorian Fainelli reg &= ~BIT(port); 1902ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg); 1903ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = reg; 1904ff39c2d6SFlorian Fainelli 1905ff39c2d6SFlorian Fainelli /* Prevent self removal to preserve isolation */ 1906ff39c2d6SFlorian Fainelli if (port != i) 1907ff39c2d6SFlorian Fainelli pvlan &= ~BIT(i); 1908ff39c2d6SFlorian Fainelli } 1909ff39c2d6SFlorian Fainelli 1910ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); 1911ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = pvlan; 1912a2482d2cSFlorian Fainelli 1913fea83353SFlorian Fainelli pvid = b53_default_pvid(dev); 1914a2482d2cSFlorian Fainelli 191548aea33aSFlorian Fainelli /* Make this port join all VLANs without VLAN entries */ 191648aea33aSFlorian Fainelli if (is58xx(dev)) { 191748aea33aSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, ®); 191848aea33aSFlorian Fainelli reg |= BIT(port); 191948aea33aSFlorian Fainelli if (!(reg & BIT(cpu_port))) 192048aea33aSFlorian Fainelli reg |= BIT(cpu_port); 192148aea33aSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg); 192248aea33aSFlorian Fainelli } else { 1923a2482d2cSFlorian Fainelli b53_get_vlan_entry(dev, pvid, vl); 1924c499696eSFlorian Fainelli vl->members |= BIT(port) | BIT(cpu_port); 1925c499696eSFlorian Fainelli vl->untag |= BIT(port) | BIT(cpu_port); 1926a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, pvid, vl); 1927ff39c2d6SFlorian Fainelli } 192848aea33aSFlorian Fainelli } 19293117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_leave); 1930ff39c2d6SFlorian Fainelli 19313117455dSFlorian Fainelli void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state) 1932ff39c2d6SFlorian Fainelli { 193304bed143SVivien Didelot struct b53_device *dev = ds->priv; 1934597698f1SVivien Didelot u8 hw_state; 1935ff39c2d6SFlorian Fainelli u8 reg; 1936ff39c2d6SFlorian Fainelli 1937ff39c2d6SFlorian Fainelli switch (state) { 1938ff39c2d6SFlorian Fainelli case BR_STATE_DISABLED: 1939ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_DIS_STATE; 1940ff39c2d6SFlorian Fainelli break; 1941ff39c2d6SFlorian Fainelli case BR_STATE_LISTENING: 1942ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_LISTEN_STATE; 1943ff39c2d6SFlorian Fainelli break; 1944ff39c2d6SFlorian Fainelli case BR_STATE_LEARNING: 1945ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_LEARN_STATE; 1946ff39c2d6SFlorian Fainelli break; 1947ff39c2d6SFlorian Fainelli case BR_STATE_FORWARDING: 1948ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_FWD_STATE; 1949ff39c2d6SFlorian Fainelli break; 1950ff39c2d6SFlorian Fainelli case BR_STATE_BLOCKING: 1951ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_BLOCK_STATE; 1952ff39c2d6SFlorian Fainelli break; 1953ff39c2d6SFlorian Fainelli default: 1954ff39c2d6SFlorian Fainelli dev_err(ds->dev, "invalid STP state: %d\n", state); 1955ff39c2d6SFlorian Fainelli return; 1956ff39c2d6SFlorian Fainelli } 1957ff39c2d6SFlorian Fainelli 1958ff39c2d6SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), ®); 1959ff39c2d6SFlorian Fainelli reg &= ~PORT_CTRL_STP_STATE_MASK; 1960ff39c2d6SFlorian Fainelli reg |= hw_state; 1961ff39c2d6SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg); 1962ff39c2d6SFlorian Fainelli } 19633117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_set_stp_state); 1964ff39c2d6SFlorian Fainelli 19653117455dSFlorian Fainelli void b53_br_fast_age(struct dsa_switch *ds, int port) 1966597698f1SVivien Didelot { 1967597698f1SVivien Didelot struct b53_device *dev = ds->priv; 1968597698f1SVivien Didelot 1969597698f1SVivien Didelot if (b53_fast_age_port(dev, port)) 1970597698f1SVivien Didelot dev_err(ds->dev, "fast ageing failed\n"); 1971597698f1SVivien Didelot } 19723117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_fast_age); 1973597698f1SVivien Didelot 1974e6dd86edSFlorian Fainelli int b53_br_flags_pre(struct dsa_switch *ds, int port, 1975a8b659e7SVladimir Oltean struct switchdev_brport_flags flags, 1976a8b659e7SVladimir Oltean struct netlink_ext_ack *extack) 197753568438SFlorian Fainelli { 1978f9b3827eSFlorian Fainelli if (flags.mask & ~(BR_FLOOD | BR_MCAST_FLOOD | BR_LEARNING)) 1979a8b659e7SVladimir Oltean return -EINVAL; 198053568438SFlorian Fainelli 198153568438SFlorian Fainelli return 0; 198253568438SFlorian Fainelli } 1983e6dd86edSFlorian Fainelli EXPORT_SYMBOL(b53_br_flags_pre); 1984a8b659e7SVladimir Oltean 1985e6dd86edSFlorian Fainelli int b53_br_flags(struct dsa_switch *ds, int port, 1986a8b659e7SVladimir Oltean struct switchdev_brport_flags flags, 1987a8b659e7SVladimir Oltean struct netlink_ext_ack *extack) 1988a8b659e7SVladimir Oltean { 1989a8b659e7SVladimir Oltean if (flags.mask & BR_FLOOD) 1990a8b659e7SVladimir Oltean b53_port_set_ucast_flood(ds->priv, port, 1991a8b659e7SVladimir Oltean !!(flags.val & BR_FLOOD)); 1992a8b659e7SVladimir Oltean if (flags.mask & BR_MCAST_FLOOD) 1993a8b659e7SVladimir Oltean b53_port_set_mcast_flood(ds->priv, port, 1994a8b659e7SVladimir Oltean !!(flags.val & BR_MCAST_FLOOD)); 1995f9b3827eSFlorian Fainelli if (flags.mask & BR_LEARNING) 1996f9b3827eSFlorian Fainelli b53_port_set_learning(ds->priv, port, 1997f9b3827eSFlorian Fainelli !!(flags.val & BR_LEARNING)); 1998a8b659e7SVladimir Oltean 1999a8b659e7SVladimir Oltean return 0; 2000a8b659e7SVladimir Oltean } 2001e6dd86edSFlorian Fainelli EXPORT_SYMBOL(b53_br_flags); 2002a8b659e7SVladimir Oltean 2003e6dd86edSFlorian Fainelli int b53_set_mrouter(struct dsa_switch *ds, int port, bool mrouter, 2004a8b659e7SVladimir Oltean struct netlink_ext_ack *extack) 2005a8b659e7SVladimir Oltean { 2006a8b659e7SVladimir Oltean b53_port_set_mcast_flood(ds->priv, port, mrouter); 2007a8b659e7SVladimir Oltean 2008a8b659e7SVladimir Oltean return 0; 2009a8b659e7SVladimir Oltean } 2010e6dd86edSFlorian Fainelli EXPORT_SYMBOL(b53_set_mrouter); 201153568438SFlorian Fainelli 2012c7d28c9dSFlorian Fainelli static bool b53_possible_cpu_port(struct dsa_switch *ds, int port) 20137edc58d6SFlorian Fainelli { 20147edc58d6SFlorian Fainelli /* Broadcom switches will accept enabling Broadcom tags on the 20157edc58d6SFlorian Fainelli * following ports: 5, 7 and 8, any other port is not supported 20167edc58d6SFlorian Fainelli */ 20175ed4e3ebSFlorian Fainelli switch (port) { 20185ed4e3ebSFlorian Fainelli case B53_CPU_PORT_25: 20195ed4e3ebSFlorian Fainelli case 7: 20205ed4e3ebSFlorian Fainelli case B53_CPU_PORT: 20217edc58d6SFlorian Fainelli return true; 20227edc58d6SFlorian Fainelli } 20237edc58d6SFlorian Fainelli 20245ed4e3ebSFlorian Fainelli return false; 20255ed4e3ebSFlorian Fainelli } 20265ed4e3ebSFlorian Fainelli 20278fab459eSFlorian Fainelli static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port, 20288fab459eSFlorian Fainelli enum dsa_tag_protocol tag_protocol) 2029c7d28c9dSFlorian Fainelli { 2030c7d28c9dSFlorian Fainelli bool ret = b53_possible_cpu_port(ds, port); 2031c7d28c9dSFlorian Fainelli 20328fab459eSFlorian Fainelli if (!ret) { 2033c7d28c9dSFlorian Fainelli dev_warn(ds->dev, "Port %d is not Broadcom tag capable\n", 2034c7d28c9dSFlorian Fainelli port); 2035c7d28c9dSFlorian Fainelli return ret; 2036c7d28c9dSFlorian Fainelli } 2037c7d28c9dSFlorian Fainelli 20388fab459eSFlorian Fainelli switch (tag_protocol) { 20398fab459eSFlorian Fainelli case DSA_TAG_PROTO_BRCM: 20408fab459eSFlorian Fainelli case DSA_TAG_PROTO_BRCM_PREPEND: 20418fab459eSFlorian Fainelli dev_warn(ds->dev, 20428fab459eSFlorian Fainelli "Port %d is stacked to Broadcom tag switch\n", port); 20438fab459eSFlorian Fainelli ret = false; 20448fab459eSFlorian Fainelli break; 20458fab459eSFlorian Fainelli default: 20468fab459eSFlorian Fainelli ret = true; 20478fab459eSFlorian Fainelli break; 20488fab459eSFlorian Fainelli } 20498fab459eSFlorian Fainelli 20508fab459eSFlorian Fainelli return ret; 20518fab459eSFlorian Fainelli } 20528fab459eSFlorian Fainelli 20534d776482SFlorian Fainelli enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port, 20544d776482SFlorian Fainelli enum dsa_tag_protocol mprot) 20557b314362SAndrew Lunn { 20567edc58d6SFlorian Fainelli struct b53_device *dev = ds->priv; 20577edc58d6SFlorian Fainelli 2058*46c5176cSÁlvaro Fernández Rojas if (!b53_can_enable_brcm_tags(ds, port, mprot)) { 20594d776482SFlorian Fainelli dev->tag_protocol = DSA_TAG_PROTO_NONE; 20604d776482SFlorian Fainelli goto out; 20614d776482SFlorian Fainelli } 206211606039SFlorian Fainelli 2063*46c5176cSÁlvaro Fernández Rojas /* Older models require a different 6 byte tag */ 2064*46c5176cSÁlvaro Fernández Rojas if (is5325(dev) || is5365(dev) || is63xx(dev)) { 2065*46c5176cSÁlvaro Fernández Rojas dev->tag_protocol = DSA_TAG_PROTO_BRCM_LEGACY; 2066*46c5176cSÁlvaro Fernández Rojas goto out; 2067*46c5176cSÁlvaro Fernández Rojas } 2068*46c5176cSÁlvaro Fernández Rojas 206911606039SFlorian Fainelli /* Broadcom BCM58xx chips have a flow accelerator on Port 8 207011606039SFlorian Fainelli * which requires us to use the prepended Broadcom tag type 207111606039SFlorian Fainelli */ 20724d776482SFlorian Fainelli if (dev->chip_id == BCM58XX_DEVICE_ID && port == B53_CPU_PORT) { 20734d776482SFlorian Fainelli dev->tag_protocol = DSA_TAG_PROTO_BRCM_PREPEND; 20744d776482SFlorian Fainelli goto out; 20754d776482SFlorian Fainelli } 207611606039SFlorian Fainelli 20774d776482SFlorian Fainelli dev->tag_protocol = DSA_TAG_PROTO_BRCM; 20784d776482SFlorian Fainelli out: 20794d776482SFlorian Fainelli return dev->tag_protocol; 20807b314362SAndrew Lunn } 20819f66816aSFlorian Fainelli EXPORT_SYMBOL(b53_get_tag_protocol); 20827b314362SAndrew Lunn 2083ed3af5fdSFlorian Fainelli int b53_mirror_add(struct dsa_switch *ds, int port, 2084ed3af5fdSFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror, bool ingress) 2085ed3af5fdSFlorian Fainelli { 2086ed3af5fdSFlorian Fainelli struct b53_device *dev = ds->priv; 2087ed3af5fdSFlorian Fainelli u16 reg, loc; 2088ed3af5fdSFlorian Fainelli 2089ed3af5fdSFlorian Fainelli if (ingress) 2090ed3af5fdSFlorian Fainelli loc = B53_IG_MIR_CTL; 2091ed3af5fdSFlorian Fainelli else 2092ed3af5fdSFlorian Fainelli loc = B53_EG_MIR_CTL; 2093ed3af5fdSFlorian Fainelli 2094ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, loc, ®); 2095ed3af5fdSFlorian Fainelli reg |= BIT(port); 2096ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, loc, reg); 2097ed3af5fdSFlorian Fainelli 2098ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®); 2099ed3af5fdSFlorian Fainelli reg &= ~CAP_PORT_MASK; 2100ed3af5fdSFlorian Fainelli reg |= mirror->to_local_port; 2101ed3af5fdSFlorian Fainelli reg |= MIRROR_EN; 2102ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg); 2103ed3af5fdSFlorian Fainelli 2104ed3af5fdSFlorian Fainelli return 0; 2105ed3af5fdSFlorian Fainelli } 2106ed3af5fdSFlorian Fainelli EXPORT_SYMBOL(b53_mirror_add); 2107ed3af5fdSFlorian Fainelli 2108ed3af5fdSFlorian Fainelli void b53_mirror_del(struct dsa_switch *ds, int port, 2109ed3af5fdSFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror) 2110ed3af5fdSFlorian Fainelli { 2111ed3af5fdSFlorian Fainelli struct b53_device *dev = ds->priv; 2112ed3af5fdSFlorian Fainelli bool loc_disable = false, other_loc_disable = false; 2113ed3af5fdSFlorian Fainelli u16 reg, loc; 2114ed3af5fdSFlorian Fainelli 2115ed3af5fdSFlorian Fainelli if (mirror->ingress) 2116ed3af5fdSFlorian Fainelli loc = B53_IG_MIR_CTL; 2117ed3af5fdSFlorian Fainelli else 2118ed3af5fdSFlorian Fainelli loc = B53_EG_MIR_CTL; 2119ed3af5fdSFlorian Fainelli 2120ed3af5fdSFlorian Fainelli /* Update the desired ingress/egress register */ 2121ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, loc, ®); 2122ed3af5fdSFlorian Fainelli reg &= ~BIT(port); 2123ed3af5fdSFlorian Fainelli if (!(reg & MIRROR_MASK)) 2124ed3af5fdSFlorian Fainelli loc_disable = true; 2125ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, loc, reg); 2126ed3af5fdSFlorian Fainelli 2127ed3af5fdSFlorian Fainelli /* Now look at the other one to know if we can disable mirroring 2128ed3af5fdSFlorian Fainelli * entirely 2129ed3af5fdSFlorian Fainelli */ 2130ed3af5fdSFlorian Fainelli if (mirror->ingress) 2131ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_EG_MIR_CTL, ®); 2132ed3af5fdSFlorian Fainelli else 2133ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_IG_MIR_CTL, ®); 2134ed3af5fdSFlorian Fainelli if (!(reg & MIRROR_MASK)) 2135ed3af5fdSFlorian Fainelli other_loc_disable = true; 2136ed3af5fdSFlorian Fainelli 2137ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®); 2138ed3af5fdSFlorian Fainelli /* Both no longer have ports, let's disable mirroring */ 2139ed3af5fdSFlorian Fainelli if (loc_disable && other_loc_disable) { 2140ed3af5fdSFlorian Fainelli reg &= ~MIRROR_EN; 2141ed3af5fdSFlorian Fainelli reg &= ~mirror->to_local_port; 2142ed3af5fdSFlorian Fainelli } 2143ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg); 2144ed3af5fdSFlorian Fainelli } 2145ed3af5fdSFlorian Fainelli EXPORT_SYMBOL(b53_mirror_del); 2146ed3af5fdSFlorian Fainelli 214722256b0aSFlorian Fainelli void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable) 214822256b0aSFlorian Fainelli { 214922256b0aSFlorian Fainelli struct b53_device *dev = ds->priv; 215022256b0aSFlorian Fainelli u16 reg; 215122256b0aSFlorian Fainelli 215222256b0aSFlorian Fainelli b53_read16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, ®); 215322256b0aSFlorian Fainelli if (enable) 215422256b0aSFlorian Fainelli reg |= BIT(port); 215522256b0aSFlorian Fainelli else 215622256b0aSFlorian Fainelli reg &= ~BIT(port); 215722256b0aSFlorian Fainelli b53_write16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, reg); 215822256b0aSFlorian Fainelli } 215922256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_eee_enable_set); 216022256b0aSFlorian Fainelli 216122256b0aSFlorian Fainelli 216222256b0aSFlorian Fainelli /* Returns 0 if EEE was not enabled, or 1 otherwise 216322256b0aSFlorian Fainelli */ 216422256b0aSFlorian Fainelli int b53_eee_init(struct dsa_switch *ds, int port, struct phy_device *phy) 216522256b0aSFlorian Fainelli { 216622256b0aSFlorian Fainelli int ret; 216722256b0aSFlorian Fainelli 216822256b0aSFlorian Fainelli ret = phy_init_eee(phy, 0); 216922256b0aSFlorian Fainelli if (ret) 217022256b0aSFlorian Fainelli return 0; 217122256b0aSFlorian Fainelli 217222256b0aSFlorian Fainelli b53_eee_enable_set(ds, port, true); 217322256b0aSFlorian Fainelli 217422256b0aSFlorian Fainelli return 1; 217522256b0aSFlorian Fainelli } 217622256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_eee_init); 217722256b0aSFlorian Fainelli 217822256b0aSFlorian Fainelli int b53_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e) 217922256b0aSFlorian Fainelli { 218022256b0aSFlorian Fainelli struct b53_device *dev = ds->priv; 218122256b0aSFlorian Fainelli struct ethtool_eee *p = &dev->ports[port].eee; 218222256b0aSFlorian Fainelli u16 reg; 218322256b0aSFlorian Fainelli 218422256b0aSFlorian Fainelli if (is5325(dev) || is5365(dev)) 218522256b0aSFlorian Fainelli return -EOPNOTSUPP; 218622256b0aSFlorian Fainelli 218722256b0aSFlorian Fainelli b53_read16(dev, B53_EEE_PAGE, B53_EEE_LPI_INDICATE, ®); 218822256b0aSFlorian Fainelli e->eee_enabled = p->eee_enabled; 218922256b0aSFlorian Fainelli e->eee_active = !!(reg & BIT(port)); 219022256b0aSFlorian Fainelli 219122256b0aSFlorian Fainelli return 0; 219222256b0aSFlorian Fainelli } 219322256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_get_mac_eee); 219422256b0aSFlorian Fainelli 219522256b0aSFlorian Fainelli int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e) 219622256b0aSFlorian Fainelli { 219722256b0aSFlorian Fainelli struct b53_device *dev = ds->priv; 219822256b0aSFlorian Fainelli struct ethtool_eee *p = &dev->ports[port].eee; 219922256b0aSFlorian Fainelli 220022256b0aSFlorian Fainelli if (is5325(dev) || is5365(dev)) 220122256b0aSFlorian Fainelli return -EOPNOTSUPP; 220222256b0aSFlorian Fainelli 220322256b0aSFlorian Fainelli p->eee_enabled = e->eee_enabled; 220422256b0aSFlorian Fainelli b53_eee_enable_set(ds, port, e->eee_enabled); 220522256b0aSFlorian Fainelli 220622256b0aSFlorian Fainelli return 0; 220722256b0aSFlorian Fainelli } 220822256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_set_mac_eee); 220922256b0aSFlorian Fainelli 22106ae5834bSMurali Krishna Policharla static int b53_change_mtu(struct dsa_switch *ds, int port, int mtu) 22116ae5834bSMurali Krishna Policharla { 22126ae5834bSMurali Krishna Policharla struct b53_device *dev = ds->priv; 22136ae5834bSMurali Krishna Policharla bool enable_jumbo; 22146ae5834bSMurali Krishna Policharla bool allow_10_100; 22156ae5834bSMurali Krishna Policharla 22166ae5834bSMurali Krishna Policharla if (is5325(dev) || is5365(dev)) 22176ae5834bSMurali Krishna Policharla return -EOPNOTSUPP; 22186ae5834bSMurali Krishna Policharla 22196ae5834bSMurali Krishna Policharla enable_jumbo = (mtu >= JMS_MIN_SIZE); 22206ae5834bSMurali Krishna Policharla allow_10_100 = (dev->chip_id == BCM583XX_DEVICE_ID); 22216ae5834bSMurali Krishna Policharla 22226ae5834bSMurali Krishna Policharla return b53_set_jumbo(dev, enable_jumbo, allow_10_100); 22236ae5834bSMurali Krishna Policharla } 22246ae5834bSMurali Krishna Policharla 22256ae5834bSMurali Krishna Policharla static int b53_get_max_mtu(struct dsa_switch *ds, int port) 22266ae5834bSMurali Krishna Policharla { 22276ae5834bSMurali Krishna Policharla return JMS_MAX_SIZE; 22286ae5834bSMurali Krishna Policharla } 22296ae5834bSMurali Krishna Policharla 2230a82f67afSFlorian Fainelli static const struct dsa_switch_ops b53_switch_ops = { 22317b314362SAndrew Lunn .get_tag_protocol = b53_get_tag_protocol, 2232967dd82fSFlorian Fainelli .setup = b53_setup, 22334f6a5cafSFlorian Fainelli .teardown = b53_teardown, 2234967dd82fSFlorian Fainelli .get_strings = b53_get_strings, 2235967dd82fSFlorian Fainelli .get_ethtool_stats = b53_get_ethtool_stats, 2236967dd82fSFlorian Fainelli .get_sset_count = b53_get_sset_count, 2237c7d28c9dSFlorian Fainelli .get_ethtool_phy_stats = b53_get_ethtool_phy_stats, 2238967dd82fSFlorian Fainelli .phy_read = b53_phy_read16, 2239967dd82fSFlorian Fainelli .phy_write = b53_phy_write16, 2240967dd82fSFlorian Fainelli .adjust_link = b53_adjust_link, 2241a8e8b985SFlorian Fainelli .phylink_validate = b53_phylink_validate, 2242a8e8b985SFlorian Fainelli .phylink_mac_link_state = b53_phylink_mac_link_state, 2243a8e8b985SFlorian Fainelli .phylink_mac_config = b53_phylink_mac_config, 2244a8e8b985SFlorian Fainelli .phylink_mac_an_restart = b53_phylink_mac_an_restart, 2245a8e8b985SFlorian Fainelli .phylink_mac_link_down = b53_phylink_mac_link_down, 2246a8e8b985SFlorian Fainelli .phylink_mac_link_up = b53_phylink_mac_link_up, 2247967dd82fSFlorian Fainelli .port_enable = b53_enable_port, 2248967dd82fSFlorian Fainelli .port_disable = b53_disable_port, 2249f43a2dbeSFlorian Fainelli .get_mac_eee = b53_get_mac_eee, 2250f43a2dbeSFlorian Fainelli .set_mac_eee = b53_set_mac_eee, 2251ff39c2d6SFlorian Fainelli .port_bridge_join = b53_br_join, 2252ff39c2d6SFlorian Fainelli .port_bridge_leave = b53_br_leave, 2253a8b659e7SVladimir Oltean .port_pre_bridge_flags = b53_br_flags_pre, 2254a8b659e7SVladimir Oltean .port_bridge_flags = b53_br_flags, 2255a8b659e7SVladimir Oltean .port_set_mrouter = b53_set_mrouter, 2256ff39c2d6SFlorian Fainelli .port_stp_state_set = b53_br_set_stp_state, 2257597698f1SVivien Didelot .port_fast_age = b53_br_fast_age, 2258a2482d2cSFlorian Fainelli .port_vlan_filtering = b53_vlan_filtering, 2259a2482d2cSFlorian Fainelli .port_vlan_add = b53_vlan_add, 2260a2482d2cSFlorian Fainelli .port_vlan_del = b53_vlan_del, 22611da6df85SFlorian Fainelli .port_fdb_dump = b53_fdb_dump, 22621da6df85SFlorian Fainelli .port_fdb_add = b53_fdb_add, 22631da6df85SFlorian Fainelli .port_fdb_del = b53_fdb_del, 2264ed3af5fdSFlorian Fainelli .port_mirror_add = b53_mirror_add, 2265ed3af5fdSFlorian Fainelli .port_mirror_del = b53_mirror_del, 22665d65b64aSFlorian Fainelli .port_mdb_add = b53_mdb_add, 22675d65b64aSFlorian Fainelli .port_mdb_del = b53_mdb_del, 22686ae5834bSMurali Krishna Policharla .port_max_mtu = b53_get_max_mtu, 22696ae5834bSMurali Krishna Policharla .port_change_mtu = b53_change_mtu, 2270967dd82fSFlorian Fainelli }; 2271967dd82fSFlorian Fainelli 2272967dd82fSFlorian Fainelli struct b53_chip_data { 2273967dd82fSFlorian Fainelli u32 chip_id; 2274967dd82fSFlorian Fainelli const char *dev_name; 2275967dd82fSFlorian Fainelli u16 vlans; 2276967dd82fSFlorian Fainelli u16 enabled_ports; 2277967dd82fSFlorian Fainelli u8 cpu_port; 2278967dd82fSFlorian Fainelli u8 vta_regs[3]; 2279673e69a6SFlorian Fainelli u8 arl_bins; 2280e3da4038SFlorian Fainelli u16 arl_buckets; 2281967dd82fSFlorian Fainelli u8 duplex_reg; 2282967dd82fSFlorian Fainelli u8 jumbo_pm_reg; 2283967dd82fSFlorian Fainelli u8 jumbo_size_reg; 2284967dd82fSFlorian Fainelli }; 2285967dd82fSFlorian Fainelli 2286967dd82fSFlorian Fainelli #define B53_VTA_REGS \ 2287967dd82fSFlorian Fainelli { B53_VT_ACCESS, B53_VT_INDEX, B53_VT_ENTRY } 2288967dd82fSFlorian Fainelli #define B53_VTA_REGS_9798 \ 2289967dd82fSFlorian Fainelli { B53_VT_ACCESS_9798, B53_VT_INDEX_9798, B53_VT_ENTRY_9798 } 2290967dd82fSFlorian Fainelli #define B53_VTA_REGS_63XX \ 2291967dd82fSFlorian Fainelli { B53_VT_ACCESS_63XX, B53_VT_INDEX_63XX, B53_VT_ENTRY_63XX } 2292967dd82fSFlorian Fainelli 2293967dd82fSFlorian Fainelli static const struct b53_chip_data b53_switch_chips[] = { 2294967dd82fSFlorian Fainelli { 2295967dd82fSFlorian Fainelli .chip_id = BCM5325_DEVICE_ID, 2296967dd82fSFlorian Fainelli .dev_name = "BCM5325", 2297967dd82fSFlorian Fainelli .vlans = 16, 2298967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 2299673e69a6SFlorian Fainelli .arl_bins = 2, 2300e3da4038SFlorian Fainelli .arl_buckets = 1024, 2301967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, 2302967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_FE, 2303967dd82fSFlorian Fainelli }, 2304967dd82fSFlorian Fainelli { 2305967dd82fSFlorian Fainelli .chip_id = BCM5365_DEVICE_ID, 2306967dd82fSFlorian Fainelli .dev_name = "BCM5365", 2307967dd82fSFlorian Fainelli .vlans = 256, 2308967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 2309673e69a6SFlorian Fainelli .arl_bins = 2, 2310e3da4038SFlorian Fainelli .arl_buckets = 1024, 2311967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, 2312967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_FE, 2313967dd82fSFlorian Fainelli }, 2314967dd82fSFlorian Fainelli { 2315a95691bcSDamien Thébault .chip_id = BCM5389_DEVICE_ID, 2316a95691bcSDamien Thébault .dev_name = "BCM5389", 2317a95691bcSDamien Thébault .vlans = 4096, 2318a95691bcSDamien Thébault .enabled_ports = 0x1f, 2319673e69a6SFlorian Fainelli .arl_bins = 4, 2320e3da4038SFlorian Fainelli .arl_buckets = 1024, 2321a95691bcSDamien Thébault .cpu_port = B53_CPU_PORT, 2322a95691bcSDamien Thébault .vta_regs = B53_VTA_REGS, 2323a95691bcSDamien Thébault .duplex_reg = B53_DUPLEX_STAT_GE, 2324a95691bcSDamien Thébault .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2325a95691bcSDamien Thébault .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2326a95691bcSDamien Thébault }, 2327a95691bcSDamien Thébault { 2328967dd82fSFlorian Fainelli .chip_id = BCM5395_DEVICE_ID, 2329967dd82fSFlorian Fainelli .dev_name = "BCM5395", 2330967dd82fSFlorian Fainelli .vlans = 4096, 2331967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 2332673e69a6SFlorian Fainelli .arl_bins = 4, 2333e3da4038SFlorian Fainelli .arl_buckets = 1024, 2334967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2335967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2336967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2337967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2338967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2339967dd82fSFlorian Fainelli }, 2340967dd82fSFlorian Fainelli { 2341967dd82fSFlorian Fainelli .chip_id = BCM5397_DEVICE_ID, 2342967dd82fSFlorian Fainelli .dev_name = "BCM5397", 2343967dd82fSFlorian Fainelli .vlans = 4096, 2344967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 2345673e69a6SFlorian Fainelli .arl_bins = 4, 2346e3da4038SFlorian Fainelli .arl_buckets = 1024, 2347967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2348967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_9798, 2349967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2350967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2351967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2352967dd82fSFlorian Fainelli }, 2353967dd82fSFlorian Fainelli { 2354967dd82fSFlorian Fainelli .chip_id = BCM5398_DEVICE_ID, 2355967dd82fSFlorian Fainelli .dev_name = "BCM5398", 2356967dd82fSFlorian Fainelli .vlans = 4096, 2357967dd82fSFlorian Fainelli .enabled_ports = 0x7f, 2358673e69a6SFlorian Fainelli .arl_bins = 4, 2359e3da4038SFlorian Fainelli .arl_buckets = 1024, 2360967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2361967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_9798, 2362967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2363967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2364967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2365967dd82fSFlorian Fainelli }, 2366967dd82fSFlorian Fainelli { 2367967dd82fSFlorian Fainelli .chip_id = BCM53115_DEVICE_ID, 2368967dd82fSFlorian Fainelli .dev_name = "BCM53115", 2369967dd82fSFlorian Fainelli .vlans = 4096, 2370967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 2371673e69a6SFlorian Fainelli .arl_bins = 4, 2372e3da4038SFlorian Fainelli .arl_buckets = 1024, 2373967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2374967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2375967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2376967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2377967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2378967dd82fSFlorian Fainelli }, 2379967dd82fSFlorian Fainelli { 2380967dd82fSFlorian Fainelli .chip_id = BCM53125_DEVICE_ID, 2381967dd82fSFlorian Fainelli .dev_name = "BCM53125", 2382967dd82fSFlorian Fainelli .vlans = 4096, 2383967dd82fSFlorian Fainelli .enabled_ports = 0xff, 2384673e69a6SFlorian Fainelli .arl_bins = 4, 2385e3da4038SFlorian Fainelli .arl_buckets = 1024, 2386967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2387967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2388967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2389967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2390967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2391967dd82fSFlorian Fainelli }, 2392967dd82fSFlorian Fainelli { 2393967dd82fSFlorian Fainelli .chip_id = BCM53128_DEVICE_ID, 2394967dd82fSFlorian Fainelli .dev_name = "BCM53128", 2395967dd82fSFlorian Fainelli .vlans = 4096, 2396967dd82fSFlorian Fainelli .enabled_ports = 0x1ff, 2397673e69a6SFlorian Fainelli .arl_bins = 4, 2398e3da4038SFlorian Fainelli .arl_buckets = 1024, 2399967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2400967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2401967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2402967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2403967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2404967dd82fSFlorian Fainelli }, 2405967dd82fSFlorian Fainelli { 2406967dd82fSFlorian Fainelli .chip_id = BCM63XX_DEVICE_ID, 2407967dd82fSFlorian Fainelli .dev_name = "BCM63xx", 2408967dd82fSFlorian Fainelli .vlans = 4096, 2409967dd82fSFlorian Fainelli .enabled_ports = 0, /* pdata must provide them */ 2410673e69a6SFlorian Fainelli .arl_bins = 4, 2411e3da4038SFlorian Fainelli .arl_buckets = 1024, 2412967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2413967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_63XX, 2414967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_63XX, 2415967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK_63XX, 2416967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE_63XX, 2417967dd82fSFlorian Fainelli }, 2418967dd82fSFlorian Fainelli { 2419967dd82fSFlorian Fainelli .chip_id = BCM53010_DEVICE_ID, 2420967dd82fSFlorian Fainelli .dev_name = "BCM53010", 2421967dd82fSFlorian Fainelli .vlans = 4096, 2422967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 2423673e69a6SFlorian Fainelli .arl_bins = 4, 2424e3da4038SFlorian Fainelli .arl_buckets = 1024, 2425967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2426967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2427967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2428967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2429967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2430967dd82fSFlorian Fainelli }, 2431967dd82fSFlorian Fainelli { 2432967dd82fSFlorian Fainelli .chip_id = BCM53011_DEVICE_ID, 2433967dd82fSFlorian Fainelli .dev_name = "BCM53011", 2434967dd82fSFlorian Fainelli .vlans = 4096, 2435967dd82fSFlorian Fainelli .enabled_ports = 0x1bf, 2436673e69a6SFlorian Fainelli .arl_bins = 4, 2437e3da4038SFlorian Fainelli .arl_buckets = 1024, 2438967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2439967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2440967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2441967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2442967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2443967dd82fSFlorian Fainelli }, 2444967dd82fSFlorian Fainelli { 2445967dd82fSFlorian Fainelli .chip_id = BCM53012_DEVICE_ID, 2446967dd82fSFlorian Fainelli .dev_name = "BCM53012", 2447967dd82fSFlorian Fainelli .vlans = 4096, 2448967dd82fSFlorian Fainelli .enabled_ports = 0x1bf, 2449673e69a6SFlorian Fainelli .arl_bins = 4, 2450e3da4038SFlorian Fainelli .arl_buckets = 1024, 2451967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2452967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2453967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2454967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2455967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2456967dd82fSFlorian Fainelli }, 2457967dd82fSFlorian Fainelli { 2458967dd82fSFlorian Fainelli .chip_id = BCM53018_DEVICE_ID, 2459967dd82fSFlorian Fainelli .dev_name = "BCM53018", 2460967dd82fSFlorian Fainelli .vlans = 4096, 2461967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 2462673e69a6SFlorian Fainelli .arl_bins = 4, 2463e3da4038SFlorian Fainelli .arl_buckets = 1024, 2464967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2465967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2466967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2467967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2468967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2469967dd82fSFlorian Fainelli }, 2470967dd82fSFlorian Fainelli { 2471967dd82fSFlorian Fainelli .chip_id = BCM53019_DEVICE_ID, 2472967dd82fSFlorian Fainelli .dev_name = "BCM53019", 2473967dd82fSFlorian Fainelli .vlans = 4096, 2474967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 2475673e69a6SFlorian Fainelli .arl_bins = 4, 2476e3da4038SFlorian Fainelli .arl_buckets = 1024, 2477967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2478967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2479967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2480967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2481967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2482967dd82fSFlorian Fainelli }, 2483991a36bbSFlorian Fainelli { 2484991a36bbSFlorian Fainelli .chip_id = BCM58XX_DEVICE_ID, 2485991a36bbSFlorian Fainelli .dev_name = "BCM585xx/586xx/88312", 2486991a36bbSFlorian Fainelli .vlans = 4096, 2487991a36bbSFlorian Fainelli .enabled_ports = 0x1ff, 2488673e69a6SFlorian Fainelli .arl_bins = 4, 2489e3da4038SFlorian Fainelli .arl_buckets = 1024, 2490bfcda65cSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2491991a36bbSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2492991a36bbSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2493991a36bbSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2494991a36bbSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2495991a36bbSFlorian Fainelli }, 2496130401d9SFlorian Fainelli { 24975040cc99SArun Parameswaran .chip_id = BCM583XX_DEVICE_ID, 24985040cc99SArun Parameswaran .dev_name = "BCM583xx/11360", 24995040cc99SArun Parameswaran .vlans = 4096, 25005040cc99SArun Parameswaran .enabled_ports = 0x103, 2501673e69a6SFlorian Fainelli .arl_bins = 4, 2502e3da4038SFlorian Fainelli .arl_buckets = 1024, 25035040cc99SArun Parameswaran .cpu_port = B53_CPU_PORT, 25045040cc99SArun Parameswaran .vta_regs = B53_VTA_REGS, 25055040cc99SArun Parameswaran .duplex_reg = B53_DUPLEX_STAT_GE, 25065040cc99SArun Parameswaran .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 25075040cc99SArun Parameswaran .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 25085040cc99SArun Parameswaran }, 250973b7a604SRafał Miłecki /* Starfighter 2 */ 251073b7a604SRafał Miłecki { 251173b7a604SRafał Miłecki .chip_id = BCM4908_DEVICE_ID, 251273b7a604SRafał Miłecki .dev_name = "BCM4908", 251373b7a604SRafał Miłecki .vlans = 4096, 251473b7a604SRafał Miłecki .enabled_ports = 0x1bf, 251573b7a604SRafał Miłecki .arl_bins = 4, 251673b7a604SRafał Miłecki .arl_buckets = 256, 251773b7a604SRafał Miłecki .cpu_port = 8, /* TODO: ports 4, 5, 8 */ 251873b7a604SRafał Miłecki .vta_regs = B53_VTA_REGS, 251973b7a604SRafał Miłecki .duplex_reg = B53_DUPLEX_STAT_GE, 252073b7a604SRafał Miłecki .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 252173b7a604SRafał Miłecki .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 252273b7a604SRafał Miłecki }, 25235040cc99SArun Parameswaran { 2524130401d9SFlorian Fainelli .chip_id = BCM7445_DEVICE_ID, 2525130401d9SFlorian Fainelli .dev_name = "BCM7445", 2526130401d9SFlorian Fainelli .vlans = 4096, 2527130401d9SFlorian Fainelli .enabled_ports = 0x1ff, 2528673e69a6SFlorian Fainelli .arl_bins = 4, 2529e3da4038SFlorian Fainelli .arl_buckets = 1024, 2530130401d9SFlorian Fainelli .cpu_port = B53_CPU_PORT, 2531130401d9SFlorian Fainelli .vta_regs = B53_VTA_REGS, 2532130401d9SFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2533130401d9SFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2534130401d9SFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2535130401d9SFlorian Fainelli }, 25360fe99338SFlorian Fainelli { 25370fe99338SFlorian Fainelli .chip_id = BCM7278_DEVICE_ID, 25380fe99338SFlorian Fainelli .dev_name = "BCM7278", 25390fe99338SFlorian Fainelli .vlans = 4096, 25400fe99338SFlorian Fainelli .enabled_ports = 0x1ff, 2541673e69a6SFlorian Fainelli .arl_bins = 4, 2542e3da4038SFlorian Fainelli .arl_buckets = 256, 25430fe99338SFlorian Fainelli .cpu_port = B53_CPU_PORT, 25440fe99338SFlorian Fainelli .vta_regs = B53_VTA_REGS, 25450fe99338SFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 25460fe99338SFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 25470fe99338SFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 25480fe99338SFlorian Fainelli }, 2549967dd82fSFlorian Fainelli }; 2550967dd82fSFlorian Fainelli 2551967dd82fSFlorian Fainelli static int b53_switch_init(struct b53_device *dev) 2552967dd82fSFlorian Fainelli { 2553967dd82fSFlorian Fainelli unsigned int i; 2554967dd82fSFlorian Fainelli int ret; 2555967dd82fSFlorian Fainelli 2556967dd82fSFlorian Fainelli for (i = 0; i < ARRAY_SIZE(b53_switch_chips); i++) { 2557967dd82fSFlorian Fainelli const struct b53_chip_data *chip = &b53_switch_chips[i]; 2558967dd82fSFlorian Fainelli 2559967dd82fSFlorian Fainelli if (chip->chip_id == dev->chip_id) { 2560967dd82fSFlorian Fainelli if (!dev->enabled_ports) 2561967dd82fSFlorian Fainelli dev->enabled_ports = chip->enabled_ports; 2562967dd82fSFlorian Fainelli dev->name = chip->dev_name; 2563967dd82fSFlorian Fainelli dev->duplex_reg = chip->duplex_reg; 2564967dd82fSFlorian Fainelli dev->vta_regs[0] = chip->vta_regs[0]; 2565967dd82fSFlorian Fainelli dev->vta_regs[1] = chip->vta_regs[1]; 2566967dd82fSFlorian Fainelli dev->vta_regs[2] = chip->vta_regs[2]; 2567967dd82fSFlorian Fainelli dev->jumbo_pm_reg = chip->jumbo_pm_reg; 2568967dd82fSFlorian Fainelli dev->cpu_port = chip->cpu_port; 2569967dd82fSFlorian Fainelli dev->num_vlans = chip->vlans; 2570673e69a6SFlorian Fainelli dev->num_arl_bins = chip->arl_bins; 2571e3da4038SFlorian Fainelli dev->num_arl_buckets = chip->arl_buckets; 2572967dd82fSFlorian Fainelli break; 2573967dd82fSFlorian Fainelli } 2574967dd82fSFlorian Fainelli } 2575967dd82fSFlorian Fainelli 2576967dd82fSFlorian Fainelli /* check which BCM5325x version we have */ 2577967dd82fSFlorian Fainelli if (is5325(dev)) { 2578967dd82fSFlorian Fainelli u8 vc4; 2579967dd82fSFlorian Fainelli 2580967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4); 2581967dd82fSFlorian Fainelli 2582967dd82fSFlorian Fainelli /* check reserved bits */ 2583967dd82fSFlorian Fainelli switch (vc4 & 3) { 2584967dd82fSFlorian Fainelli case 1: 2585967dd82fSFlorian Fainelli /* BCM5325E */ 2586967dd82fSFlorian Fainelli break; 2587967dd82fSFlorian Fainelli case 3: 2588967dd82fSFlorian Fainelli /* BCM5325F - do not use port 4 */ 2589967dd82fSFlorian Fainelli dev->enabled_ports &= ~BIT(4); 2590967dd82fSFlorian Fainelli break; 2591967dd82fSFlorian Fainelli default: 2592967dd82fSFlorian Fainelli /* On the BCM47XX SoCs this is the supported internal switch.*/ 2593967dd82fSFlorian Fainelli #ifndef CONFIG_BCM47XX 2594967dd82fSFlorian Fainelli /* BCM5325M */ 2595967dd82fSFlorian Fainelli return -EINVAL; 2596967dd82fSFlorian Fainelli #else 2597967dd82fSFlorian Fainelli break; 2598967dd82fSFlorian Fainelli #endif 2599967dd82fSFlorian Fainelli } 2600967dd82fSFlorian Fainelli } else if (dev->chip_id == BCM53115_DEVICE_ID) { 2601967dd82fSFlorian Fainelli u64 strap_value; 2602967dd82fSFlorian Fainelli 2603967dd82fSFlorian Fainelli b53_read48(dev, B53_STAT_PAGE, B53_STRAP_VALUE, &strap_value); 2604967dd82fSFlorian Fainelli /* use second IMP port if GMII is enabled */ 2605967dd82fSFlorian Fainelli if (strap_value & SV_GMII_CTRL_115) 2606967dd82fSFlorian Fainelli dev->cpu_port = 5; 2607967dd82fSFlorian Fainelli } 2608967dd82fSFlorian Fainelli 2609967dd82fSFlorian Fainelli /* cpu port is always last */ 2610967dd82fSFlorian Fainelli dev->num_ports = dev->cpu_port + 1; 2611967dd82fSFlorian Fainelli dev->enabled_ports |= BIT(dev->cpu_port); 2612967dd82fSFlorian Fainelli 2613c7d28c9dSFlorian Fainelli /* Include non standard CPU port built-in PHYs to be probed */ 2614c7d28c9dSFlorian Fainelli if (is539x(dev) || is531x5(dev)) { 2615c7d28c9dSFlorian Fainelli for (i = 0; i < dev->num_ports; i++) { 2616c7d28c9dSFlorian Fainelli if (!(dev->ds->phys_mii_mask & BIT(i)) && 2617c7d28c9dSFlorian Fainelli !b53_possible_cpu_port(dev->ds, i)) 2618c7d28c9dSFlorian Fainelli dev->ds->phys_mii_mask |= BIT(i); 2619c7d28c9dSFlorian Fainelli } 2620c7d28c9dSFlorian Fainelli } 2621c7d28c9dSFlorian Fainelli 2622a86854d0SKees Cook dev->ports = devm_kcalloc(dev->dev, 2623a86854d0SKees Cook dev->num_ports, sizeof(struct b53_port), 2624967dd82fSFlorian Fainelli GFP_KERNEL); 2625967dd82fSFlorian Fainelli if (!dev->ports) 2626967dd82fSFlorian Fainelli return -ENOMEM; 2627967dd82fSFlorian Fainelli 2628a86854d0SKees Cook dev->vlans = devm_kcalloc(dev->dev, 2629a86854d0SKees Cook dev->num_vlans, sizeof(struct b53_vlan), 2630a2482d2cSFlorian Fainelli GFP_KERNEL); 2631a2482d2cSFlorian Fainelli if (!dev->vlans) 2632a2482d2cSFlorian Fainelli return -ENOMEM; 2633a2482d2cSFlorian Fainelli 2634967dd82fSFlorian Fainelli dev->reset_gpio = b53_switch_get_reset_gpio(dev); 2635967dd82fSFlorian Fainelli if (dev->reset_gpio >= 0) { 2636967dd82fSFlorian Fainelli ret = devm_gpio_request_one(dev->dev, dev->reset_gpio, 2637967dd82fSFlorian Fainelli GPIOF_OUT_INIT_HIGH, "robo_reset"); 2638967dd82fSFlorian Fainelli if (ret) 2639967dd82fSFlorian Fainelli return ret; 2640967dd82fSFlorian Fainelli } 2641967dd82fSFlorian Fainelli 2642967dd82fSFlorian Fainelli return 0; 2643967dd82fSFlorian Fainelli } 2644967dd82fSFlorian Fainelli 26450dff88d3SJulia Lawall struct b53_device *b53_switch_alloc(struct device *base, 26460dff88d3SJulia Lawall const struct b53_io_ops *ops, 2647967dd82fSFlorian Fainelli void *priv) 2648967dd82fSFlorian Fainelli { 2649967dd82fSFlorian Fainelli struct dsa_switch *ds; 2650967dd82fSFlorian Fainelli struct b53_device *dev; 2651967dd82fSFlorian Fainelli 26527e99e347SVivien Didelot ds = devm_kzalloc(base, sizeof(*ds), GFP_KERNEL); 2653967dd82fSFlorian Fainelli if (!ds) 2654967dd82fSFlorian Fainelli return NULL; 2655967dd82fSFlorian Fainelli 26567e99e347SVivien Didelot ds->dev = base; 26577e99e347SVivien Didelot ds->num_ports = DSA_MAX_PORTS; 26587e99e347SVivien Didelot 2659a0c02161SVivien Didelot dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL); 2660a0c02161SVivien Didelot if (!dev) 2661a0c02161SVivien Didelot return NULL; 2662967dd82fSFlorian Fainelli 2663967dd82fSFlorian Fainelli ds->priv = dev; 2664967dd82fSFlorian Fainelli dev->dev = base; 2665967dd82fSFlorian Fainelli 2666967dd82fSFlorian Fainelli dev->ds = ds; 2667967dd82fSFlorian Fainelli dev->priv = priv; 2668967dd82fSFlorian Fainelli dev->ops = ops; 2669485ebd61SFlorian Fainelli ds->ops = &b53_switch_ops; 26701c5ad5a9SFlorian Fainelli ds->untag_bridge_pvid = true; 26710ee2af4eSVladimir Oltean dev->vlan_enabled = true; 2672967dd82fSFlorian Fainelli mutex_init(&dev->reg_mutex); 2673967dd82fSFlorian Fainelli mutex_init(&dev->stats_mutex); 2674967dd82fSFlorian Fainelli 2675967dd82fSFlorian Fainelli return dev; 2676967dd82fSFlorian Fainelli } 2677967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_alloc); 2678967dd82fSFlorian Fainelli 2679967dd82fSFlorian Fainelli int b53_switch_detect(struct b53_device *dev) 2680967dd82fSFlorian Fainelli { 2681967dd82fSFlorian Fainelli u32 id32; 2682967dd82fSFlorian Fainelli u16 tmp; 2683967dd82fSFlorian Fainelli u8 id8; 2684967dd82fSFlorian Fainelli int ret; 2685967dd82fSFlorian Fainelli 2686967dd82fSFlorian Fainelli ret = b53_read8(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id8); 2687967dd82fSFlorian Fainelli if (ret) 2688967dd82fSFlorian Fainelli return ret; 2689967dd82fSFlorian Fainelli 2690967dd82fSFlorian Fainelli switch (id8) { 2691967dd82fSFlorian Fainelli case 0: 2692967dd82fSFlorian Fainelli /* BCM5325 and BCM5365 do not have this register so reads 2693967dd82fSFlorian Fainelli * return 0. But the read operation did succeed, so assume this 2694967dd82fSFlorian Fainelli * is one of them. 2695967dd82fSFlorian Fainelli * 2696967dd82fSFlorian Fainelli * Next check if we can write to the 5325's VTA register; for 2697967dd82fSFlorian Fainelli * 5365 it is read only. 2698967dd82fSFlorian Fainelli */ 2699967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, 0xf); 2700967dd82fSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, &tmp); 2701967dd82fSFlorian Fainelli 2702967dd82fSFlorian Fainelli if (tmp == 0xf) 2703967dd82fSFlorian Fainelli dev->chip_id = BCM5325_DEVICE_ID; 2704967dd82fSFlorian Fainelli else 2705967dd82fSFlorian Fainelli dev->chip_id = BCM5365_DEVICE_ID; 2706967dd82fSFlorian Fainelli break; 2707a95691bcSDamien Thébault case BCM5389_DEVICE_ID: 2708967dd82fSFlorian Fainelli case BCM5395_DEVICE_ID: 2709967dd82fSFlorian Fainelli case BCM5397_DEVICE_ID: 2710967dd82fSFlorian Fainelli case BCM5398_DEVICE_ID: 2711967dd82fSFlorian Fainelli dev->chip_id = id8; 2712967dd82fSFlorian Fainelli break; 2713967dd82fSFlorian Fainelli default: 2714967dd82fSFlorian Fainelli ret = b53_read32(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id32); 2715967dd82fSFlorian Fainelli if (ret) 2716967dd82fSFlorian Fainelli return ret; 2717967dd82fSFlorian Fainelli 2718967dd82fSFlorian Fainelli switch (id32) { 2719967dd82fSFlorian Fainelli case BCM53115_DEVICE_ID: 2720967dd82fSFlorian Fainelli case BCM53125_DEVICE_ID: 2721967dd82fSFlorian Fainelli case BCM53128_DEVICE_ID: 2722967dd82fSFlorian Fainelli case BCM53010_DEVICE_ID: 2723967dd82fSFlorian Fainelli case BCM53011_DEVICE_ID: 2724967dd82fSFlorian Fainelli case BCM53012_DEVICE_ID: 2725967dd82fSFlorian Fainelli case BCM53018_DEVICE_ID: 2726967dd82fSFlorian Fainelli case BCM53019_DEVICE_ID: 2727967dd82fSFlorian Fainelli dev->chip_id = id32; 2728967dd82fSFlorian Fainelli break; 2729967dd82fSFlorian Fainelli default: 27303b33438cSPaul Barker dev_err(dev->dev, 27313b33438cSPaul Barker "unsupported switch detected (BCM53%02x/BCM%x)\n", 2732967dd82fSFlorian Fainelli id8, id32); 2733967dd82fSFlorian Fainelli return -ENODEV; 2734967dd82fSFlorian Fainelli } 2735967dd82fSFlorian Fainelli } 2736967dd82fSFlorian Fainelli 2737967dd82fSFlorian Fainelli if (dev->chip_id == BCM5325_DEVICE_ID) 2738967dd82fSFlorian Fainelli return b53_read8(dev, B53_STAT_PAGE, B53_REV_ID_25, 2739967dd82fSFlorian Fainelli &dev->core_rev); 2740967dd82fSFlorian Fainelli else 2741967dd82fSFlorian Fainelli return b53_read8(dev, B53_MGMT_PAGE, B53_REV_ID, 2742967dd82fSFlorian Fainelli &dev->core_rev); 2743967dd82fSFlorian Fainelli } 2744967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_detect); 2745967dd82fSFlorian Fainelli 2746967dd82fSFlorian Fainelli int b53_switch_register(struct b53_device *dev) 2747967dd82fSFlorian Fainelli { 2748967dd82fSFlorian Fainelli int ret; 2749967dd82fSFlorian Fainelli 2750967dd82fSFlorian Fainelli if (dev->pdata) { 2751967dd82fSFlorian Fainelli dev->chip_id = dev->pdata->chip_id; 2752967dd82fSFlorian Fainelli dev->enabled_ports = dev->pdata->enabled_ports; 2753967dd82fSFlorian Fainelli } 2754967dd82fSFlorian Fainelli 2755967dd82fSFlorian Fainelli if (!dev->chip_id && b53_switch_detect(dev)) 2756967dd82fSFlorian Fainelli return -EINVAL; 2757967dd82fSFlorian Fainelli 2758967dd82fSFlorian Fainelli ret = b53_switch_init(dev); 2759967dd82fSFlorian Fainelli if (ret) 2760967dd82fSFlorian Fainelli return ret; 2761967dd82fSFlorian Fainelli 27623b33438cSPaul Barker dev_info(dev->dev, "found switch: %s, rev %i\n", 27633b33438cSPaul Barker dev->name, dev->core_rev); 2764967dd82fSFlorian Fainelli 276523c9ee49SVivien Didelot return dsa_register_switch(dev->ds); 2766967dd82fSFlorian Fainelli } 2767967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_register); 2768967dd82fSFlorian Fainelli 2769967dd82fSFlorian Fainelli MODULE_AUTHOR("Jonas Gorski <jogo@openwrt.org>"); 2770967dd82fSFlorian Fainelli MODULE_DESCRIPTION("B53 switch library"); 2771967dd82fSFlorian Fainelli MODULE_LICENSE("Dual BSD/GPL"); 2772