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 352dad8d7c6SFlorian Fainelli static void b53_enable_vlan(struct b53_device *dev, 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; 434967dd82fSFlorian Fainelli } 435967dd82fSFlorian Fainelli 436967dd82fSFlorian Fainelli static int b53_set_jumbo(struct b53_device *dev, bool enable, bool allow_10_100) 437967dd82fSFlorian Fainelli { 438967dd82fSFlorian Fainelli u32 port_mask = 0; 439967dd82fSFlorian Fainelli u16 max_size = JMS_MIN_SIZE; 440967dd82fSFlorian Fainelli 441967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 442967dd82fSFlorian Fainelli return -EINVAL; 443967dd82fSFlorian Fainelli 444967dd82fSFlorian Fainelli if (enable) { 445967dd82fSFlorian Fainelli port_mask = dev->enabled_ports; 446967dd82fSFlorian Fainelli max_size = JMS_MAX_SIZE; 447967dd82fSFlorian Fainelli if (allow_10_100) 448967dd82fSFlorian Fainelli port_mask |= JPM_10_100_JUMBO_EN; 449967dd82fSFlorian Fainelli } 450967dd82fSFlorian Fainelli 451967dd82fSFlorian Fainelli b53_write32(dev, B53_JUMBO_PAGE, dev->jumbo_pm_reg, port_mask); 452967dd82fSFlorian Fainelli return b53_write16(dev, B53_JUMBO_PAGE, dev->jumbo_size_reg, max_size); 453967dd82fSFlorian Fainelli } 454967dd82fSFlorian Fainelli 455ff39c2d6SFlorian Fainelli static int b53_flush_arl(struct b53_device *dev, u8 mask) 456967dd82fSFlorian Fainelli { 457967dd82fSFlorian Fainelli unsigned int i; 458967dd82fSFlorian Fainelli 459967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, 460ff39c2d6SFlorian Fainelli FAST_AGE_DONE | FAST_AGE_DYNAMIC | mask); 461967dd82fSFlorian Fainelli 462967dd82fSFlorian Fainelli for (i = 0; i < 10; i++) { 463967dd82fSFlorian Fainelli u8 fast_age_ctrl; 464967dd82fSFlorian Fainelli 465967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, 466967dd82fSFlorian Fainelli &fast_age_ctrl); 467967dd82fSFlorian Fainelli 468967dd82fSFlorian Fainelli if (!(fast_age_ctrl & FAST_AGE_DONE)) 469967dd82fSFlorian Fainelli goto out; 470967dd82fSFlorian Fainelli 471967dd82fSFlorian Fainelli msleep(1); 472967dd82fSFlorian Fainelli } 473967dd82fSFlorian Fainelli 474967dd82fSFlorian Fainelli return -ETIMEDOUT; 475967dd82fSFlorian Fainelli out: 476967dd82fSFlorian Fainelli /* Only age dynamic entries (default behavior) */ 477967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, FAST_AGE_DYNAMIC); 478967dd82fSFlorian Fainelli return 0; 479967dd82fSFlorian Fainelli } 480967dd82fSFlorian Fainelli 481ff39c2d6SFlorian Fainelli static int b53_fast_age_port(struct b53_device *dev, int port) 482ff39c2d6SFlorian Fainelli { 483ff39c2d6SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_PORT_CTRL, port); 484ff39c2d6SFlorian Fainelli 485ff39c2d6SFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_PORT); 486ff39c2d6SFlorian Fainelli } 487ff39c2d6SFlorian Fainelli 488a2482d2cSFlorian Fainelli static int b53_fast_age_vlan(struct b53_device *dev, u16 vid) 489a2482d2cSFlorian Fainelli { 490a2482d2cSFlorian Fainelli b53_write16(dev, B53_CTRL_PAGE, B53_FAST_AGE_VID_CTRL, vid); 491a2482d2cSFlorian Fainelli 492a2482d2cSFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_VLAN); 493a2482d2cSFlorian Fainelli } 494a2482d2cSFlorian Fainelli 495aac02867SFlorian Fainelli void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port) 496ff39c2d6SFlorian Fainelli { 49704bed143SVivien Didelot struct b53_device *dev = ds->priv; 498ff39c2d6SFlorian Fainelli unsigned int i; 499ff39c2d6SFlorian Fainelli u16 pvlan; 500ff39c2d6SFlorian Fainelli 501ff39c2d6SFlorian Fainelli /* Enable the IMP port to be in the same VLAN as the other ports 502ff39c2d6SFlorian Fainelli * on a per-port basis such that we only have Port i and IMP in 503ff39c2d6SFlorian Fainelli * the same VLAN. 504ff39c2d6SFlorian Fainelli */ 505ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) { 506ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &pvlan); 507ff39c2d6SFlorian Fainelli pvlan |= BIT(cpu_port); 508ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), pvlan); 509ff39c2d6SFlorian Fainelli } 510ff39c2d6SFlorian Fainelli } 511aac02867SFlorian Fainelli EXPORT_SYMBOL(b53_imp_vlan_setup); 512ff39c2d6SFlorian Fainelli 513a8b659e7SVladimir Oltean static void b53_port_set_ucast_flood(struct b53_device *dev, int port, 514a8b659e7SVladimir Oltean bool unicast) 515a8b659e7SVladimir Oltean { 516a8b659e7SVladimir Oltean u16 uc; 517a8b659e7SVladimir Oltean 518a8b659e7SVladimir Oltean b53_read16(dev, B53_CTRL_PAGE, B53_UC_FLOOD_MASK, &uc); 519a8b659e7SVladimir Oltean if (unicast) 520a8b659e7SVladimir Oltean uc |= BIT(port); 521a8b659e7SVladimir Oltean else 522a8b659e7SVladimir Oltean uc &= ~BIT(port); 523a8b659e7SVladimir Oltean b53_write16(dev, B53_CTRL_PAGE, B53_UC_FLOOD_MASK, uc); 524a8b659e7SVladimir Oltean } 525a8b659e7SVladimir Oltean 526a8b659e7SVladimir Oltean static void b53_port_set_mcast_flood(struct b53_device *dev, int port, 527a8b659e7SVladimir Oltean bool multicast) 528a8b659e7SVladimir Oltean { 529a8b659e7SVladimir Oltean u16 mc; 530a8b659e7SVladimir Oltean 531a8b659e7SVladimir Oltean b53_read16(dev, B53_CTRL_PAGE, B53_MC_FLOOD_MASK, &mc); 532a8b659e7SVladimir Oltean if (multicast) 533a8b659e7SVladimir Oltean mc |= BIT(port); 534a8b659e7SVladimir Oltean else 535a8b659e7SVladimir Oltean mc &= ~BIT(port); 536a8b659e7SVladimir Oltean b53_write16(dev, B53_CTRL_PAGE, B53_MC_FLOOD_MASK, mc); 537a8b659e7SVladimir Oltean 538a8b659e7SVladimir Oltean b53_read16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, &mc); 539a8b659e7SVladimir Oltean if (multicast) 540a8b659e7SVladimir Oltean mc |= BIT(port); 541a8b659e7SVladimir Oltean else 542a8b659e7SVladimir Oltean mc &= ~BIT(port); 543a8b659e7SVladimir Oltean b53_write16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, mc); 544a8b659e7SVladimir Oltean } 545a8b659e7SVladimir Oltean 546f86ad77fSFlorian Fainelli int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy) 547967dd82fSFlorian Fainelli { 54804bed143SVivien Didelot struct b53_device *dev = ds->priv; 54974be4babSVivien Didelot unsigned int cpu_port; 5508ca7c160SFlorian Fainelli int ret = 0; 551ff39c2d6SFlorian Fainelli u16 pvlan; 552967dd82fSFlorian Fainelli 55374be4babSVivien Didelot if (!dsa_is_user_port(ds, port)) 55474be4babSVivien Didelot return 0; 55574be4babSVivien Didelot 55668bb8ea8SVivien Didelot cpu_port = dsa_to_port(ds, port)->cpu_dp->index; 55774be4babSVivien Didelot 558a8b659e7SVladimir Oltean b53_port_set_ucast_flood(dev, port, true); 559a8b659e7SVladimir Oltean b53_port_set_mcast_flood(dev, port, true); 56063cc54a6SFlorian Fainelli 5618ca7c160SFlorian Fainelli if (dev->ops->irq_enable) 5628ca7c160SFlorian Fainelli ret = dev->ops->irq_enable(dev, port); 5638ca7c160SFlorian Fainelli if (ret) 5648ca7c160SFlorian Fainelli return ret; 5658ca7c160SFlorian Fainelli 566967dd82fSFlorian Fainelli /* Clear the Rx and Tx disable bits and set to no spanning tree */ 567967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), 0); 568967dd82fSFlorian Fainelli 569ff39c2d6SFlorian Fainelli /* Set this port, and only this one to be in the default VLAN, 570ff39c2d6SFlorian Fainelli * if member of a bridge, restore its membership prior to 571ff39c2d6SFlorian Fainelli * bringing down this port. 572ff39c2d6SFlorian Fainelli */ 573ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); 574ff39c2d6SFlorian Fainelli pvlan &= ~0x1ff; 575ff39c2d6SFlorian Fainelli pvlan |= BIT(port); 576ff39c2d6SFlorian Fainelli pvlan |= dev->ports[port].vlan_ctl_mask; 577ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); 578ff39c2d6SFlorian Fainelli 579ff39c2d6SFlorian Fainelli b53_imp_vlan_setup(ds, cpu_port); 580ff39c2d6SFlorian Fainelli 581f43a2dbeSFlorian Fainelli /* If EEE was enabled, restore it */ 582f43a2dbeSFlorian Fainelli if (dev->ports[port].eee.eee_enabled) 583f43a2dbeSFlorian Fainelli b53_eee_enable_set(ds, port, true); 584f43a2dbeSFlorian Fainelli 585967dd82fSFlorian Fainelli return 0; 586967dd82fSFlorian Fainelli } 587f86ad77fSFlorian Fainelli EXPORT_SYMBOL(b53_enable_port); 588967dd82fSFlorian Fainelli 58975104db0SAndrew Lunn void b53_disable_port(struct dsa_switch *ds, int port) 590967dd82fSFlorian Fainelli { 59104bed143SVivien Didelot struct b53_device *dev = ds->priv; 592967dd82fSFlorian Fainelli u8 reg; 593967dd82fSFlorian Fainelli 594967dd82fSFlorian Fainelli /* Disable Tx/Rx for the port */ 595967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), ®); 596967dd82fSFlorian Fainelli reg |= PORT_CTRL_RX_DISABLE | PORT_CTRL_TX_DISABLE; 597967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg); 5988ca7c160SFlorian Fainelli 5998ca7c160SFlorian Fainelli if (dev->ops->irq_disable) 6008ca7c160SFlorian Fainelli dev->ops->irq_disable(dev, port); 601967dd82fSFlorian Fainelli } 602f86ad77fSFlorian Fainelli EXPORT_SYMBOL(b53_disable_port); 603967dd82fSFlorian Fainelli 604b409a9efSFlorian Fainelli void b53_brcm_hdr_setup(struct dsa_switch *ds, int port) 605b409a9efSFlorian Fainelli { 606b409a9efSFlorian Fainelli struct b53_device *dev = ds->priv; 6074d776482SFlorian Fainelli bool tag_en = !(dev->tag_protocol == DSA_TAG_PROTO_NONE); 608b409a9efSFlorian Fainelli u8 hdr_ctl, val; 609b409a9efSFlorian Fainelli u16 reg; 610b409a9efSFlorian Fainelli 611b409a9efSFlorian Fainelli /* Resolve which bit controls the Broadcom tag */ 612b409a9efSFlorian Fainelli switch (port) { 613b409a9efSFlorian Fainelli case 8: 614b409a9efSFlorian Fainelli val = BRCM_HDR_P8_EN; 615b409a9efSFlorian Fainelli break; 616b409a9efSFlorian Fainelli case 7: 617b409a9efSFlorian Fainelli val = BRCM_HDR_P7_EN; 618b409a9efSFlorian Fainelli break; 619b409a9efSFlorian Fainelli case 5: 620b409a9efSFlorian Fainelli val = BRCM_HDR_P5_EN; 621b409a9efSFlorian Fainelli break; 622b409a9efSFlorian Fainelli default: 623b409a9efSFlorian Fainelli val = 0; 624b409a9efSFlorian Fainelli break; 625b409a9efSFlorian Fainelli } 626b409a9efSFlorian Fainelli 6278fab459eSFlorian Fainelli /* Enable management mode if tagging is requested */ 6288fab459eSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &hdr_ctl); 6298fab459eSFlorian Fainelli if (tag_en) 6308fab459eSFlorian Fainelli hdr_ctl |= SM_SW_FWD_MODE; 6318fab459eSFlorian Fainelli else 6328fab459eSFlorian Fainelli hdr_ctl &= ~SM_SW_FWD_MODE; 6338fab459eSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, hdr_ctl); 6348fab459eSFlorian Fainelli 6358fab459eSFlorian Fainelli /* Configure the appropriate IMP port */ 6368fab459eSFlorian Fainelli b53_read8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &hdr_ctl); 6378fab459eSFlorian Fainelli if (port == 8) 6388fab459eSFlorian Fainelli hdr_ctl |= GC_FRM_MGMT_PORT_MII; 6398fab459eSFlorian Fainelli else if (port == 5) 6408fab459eSFlorian Fainelli hdr_ctl |= GC_FRM_MGMT_PORT_M; 6418fab459eSFlorian Fainelli b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, hdr_ctl); 6428fab459eSFlorian Fainelli 643b409a9efSFlorian Fainelli /* Enable Broadcom tags for IMP port */ 644b409a9efSFlorian Fainelli b53_read8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, &hdr_ctl); 645cdb583cfSFlorian Fainelli if (tag_en) 646b409a9efSFlorian Fainelli hdr_ctl |= val; 647cdb583cfSFlorian Fainelli else 648cdb583cfSFlorian Fainelli hdr_ctl &= ~val; 649b409a9efSFlorian Fainelli b53_write8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, hdr_ctl); 650b409a9efSFlorian Fainelli 651b409a9efSFlorian Fainelli /* Registers below are only accessible on newer devices */ 652b409a9efSFlorian Fainelli if (!is58xx(dev)) 653b409a9efSFlorian Fainelli return; 654b409a9efSFlorian Fainelli 655b409a9efSFlorian Fainelli /* Enable reception Broadcom tag for CPU TX (switch RX) to 656b409a9efSFlorian Fainelli * allow us to tag outgoing frames 657b409a9efSFlorian Fainelli */ 658b409a9efSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, ®); 659cdb583cfSFlorian Fainelli if (tag_en) 660b409a9efSFlorian Fainelli reg &= ~BIT(port); 661cdb583cfSFlorian Fainelli else 662cdb583cfSFlorian Fainelli reg |= BIT(port); 663b409a9efSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, reg); 664b409a9efSFlorian Fainelli 665b409a9efSFlorian Fainelli /* Enable transmission of Broadcom tags from the switch (CPU RX) to 666b409a9efSFlorian Fainelli * allow delivering frames to the per-port net_devices 667b409a9efSFlorian Fainelli */ 668b409a9efSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, ®); 669cdb583cfSFlorian Fainelli if (tag_en) 670b409a9efSFlorian Fainelli reg &= ~BIT(port); 671cdb583cfSFlorian Fainelli else 672cdb583cfSFlorian Fainelli reg |= BIT(port); 673b409a9efSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, reg); 674b409a9efSFlorian Fainelli } 675b409a9efSFlorian Fainelli EXPORT_SYMBOL(b53_brcm_hdr_setup); 676b409a9efSFlorian Fainelli 677299752a7SFlorian Fainelli static void b53_enable_cpu_port(struct b53_device *dev, int port) 678967dd82fSFlorian Fainelli { 679967dd82fSFlorian Fainelli u8 port_ctrl; 680967dd82fSFlorian Fainelli 681967dd82fSFlorian Fainelli /* BCM5325 CPU port is at 8 */ 682299752a7SFlorian Fainelli if ((is5325(dev) || is5365(dev)) && port == B53_CPU_PORT_25) 683299752a7SFlorian Fainelli port = B53_CPU_PORT; 684967dd82fSFlorian Fainelli 685967dd82fSFlorian Fainelli port_ctrl = PORT_CTRL_RX_BCST_EN | 686967dd82fSFlorian Fainelli PORT_CTRL_RX_MCST_EN | 687967dd82fSFlorian Fainelli PORT_CTRL_RX_UCST_EN; 688299752a7SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), port_ctrl); 6897edc58d6SFlorian Fainelli 6907edc58d6SFlorian Fainelli b53_brcm_hdr_setup(dev->ds, port); 69163cc54a6SFlorian Fainelli 692a8b659e7SVladimir Oltean b53_port_set_ucast_flood(dev, port, true); 693a8b659e7SVladimir Oltean b53_port_set_mcast_flood(dev, port, true); 694967dd82fSFlorian Fainelli } 695967dd82fSFlorian Fainelli 696967dd82fSFlorian Fainelli static void b53_enable_mib(struct b53_device *dev) 697967dd82fSFlorian Fainelli { 698967dd82fSFlorian Fainelli u8 gc; 699967dd82fSFlorian Fainelli 700967dd82fSFlorian Fainelli b53_read8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc); 701967dd82fSFlorian Fainelli gc &= ~(GC_RESET_MIB | GC_MIB_AC_EN); 702967dd82fSFlorian Fainelli b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc); 703967dd82fSFlorian Fainelli } 704967dd82fSFlorian Fainelli 705fea83353SFlorian Fainelli static u16 b53_default_pvid(struct b53_device *dev) 706fea83353SFlorian Fainelli { 707fea83353SFlorian Fainelli if (is5325(dev) || is5365(dev)) 708fea83353SFlorian Fainelli return 1; 709fea83353SFlorian Fainelli else 710fea83353SFlorian Fainelli return 0; 711fea83353SFlorian Fainelli } 712fea83353SFlorian Fainelli 7135c1a6eafSFlorian Fainelli int b53_configure_vlan(struct dsa_switch *ds) 714967dd82fSFlorian Fainelli { 7155c1a6eafSFlorian Fainelli struct b53_device *dev = ds->priv; 716a2482d2cSFlorian Fainelli struct b53_vlan vl = { 0 }; 717d7a0b1f7SFlorian Fainelli struct b53_vlan *v; 718fea83353SFlorian Fainelli int i, def_vid; 719d7a0b1f7SFlorian Fainelli u16 vid; 720fea83353SFlorian Fainelli 721fea83353SFlorian Fainelli def_vid = b53_default_pvid(dev); 722967dd82fSFlorian Fainelli 723967dd82fSFlorian Fainelli /* clear all vlan entries */ 724967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) { 725fea83353SFlorian Fainelli for (i = def_vid; i < dev->num_vlans; i++) 726a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, i, &vl); 727967dd82fSFlorian Fainelli } else { 728967dd82fSFlorian Fainelli b53_do_vlan_op(dev, VTA_CMD_CLEAR); 729967dd82fSFlorian Fainelli } 730967dd82fSFlorian Fainelli 731df373702SFlorian Fainelli b53_enable_vlan(dev, dev->vlan_enabled, ds->vlan_filtering); 732967dd82fSFlorian Fainelli 733967dd82fSFlorian Fainelli b53_for_each_port(dev, i) 734967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, 735fea83353SFlorian Fainelli B53_VLAN_PORT_DEF_TAG(i), def_vid); 736967dd82fSFlorian Fainelli 737d7a0b1f7SFlorian Fainelli /* Upon initial call we have not set-up any VLANs, but upon 738d7a0b1f7SFlorian Fainelli * system resume, we need to restore all VLAN entries. 739d7a0b1f7SFlorian Fainelli */ 740d7a0b1f7SFlorian Fainelli for (vid = def_vid; vid < dev->num_vlans; vid++) { 741d7a0b1f7SFlorian Fainelli v = &dev->vlans[vid]; 742d7a0b1f7SFlorian Fainelli 743d7a0b1f7SFlorian Fainelli if (!v->members) 744d7a0b1f7SFlorian Fainelli continue; 745d7a0b1f7SFlorian Fainelli 746d7a0b1f7SFlorian Fainelli b53_set_vlan_entry(dev, vid, v); 747d7a0b1f7SFlorian Fainelli b53_fast_age_vlan(dev, vid); 748d7a0b1f7SFlorian Fainelli } 749d7a0b1f7SFlorian Fainelli 750967dd82fSFlorian Fainelli return 0; 751967dd82fSFlorian Fainelli } 7525c1a6eafSFlorian Fainelli EXPORT_SYMBOL(b53_configure_vlan); 753967dd82fSFlorian Fainelli 754967dd82fSFlorian Fainelli static void b53_switch_reset_gpio(struct b53_device *dev) 755967dd82fSFlorian Fainelli { 756967dd82fSFlorian Fainelli int gpio = dev->reset_gpio; 757967dd82fSFlorian Fainelli 758967dd82fSFlorian Fainelli if (gpio < 0) 759967dd82fSFlorian Fainelli return; 760967dd82fSFlorian Fainelli 761967dd82fSFlorian Fainelli /* Reset sequence: RESET low(50ms)->high(20ms) 762967dd82fSFlorian Fainelli */ 763967dd82fSFlorian Fainelli gpio_set_value(gpio, 0); 764967dd82fSFlorian Fainelli mdelay(50); 765967dd82fSFlorian Fainelli 766967dd82fSFlorian Fainelli gpio_set_value(gpio, 1); 767967dd82fSFlorian Fainelli mdelay(20); 768967dd82fSFlorian Fainelli 769967dd82fSFlorian Fainelli dev->current_page = 0xff; 770967dd82fSFlorian Fainelli } 771967dd82fSFlorian Fainelli 772967dd82fSFlorian Fainelli static int b53_switch_reset(struct b53_device *dev) 773967dd82fSFlorian Fainelli { 7743fb22b05SFlorian Fainelli unsigned int timeout = 1000; 7753fb22b05SFlorian Fainelli u8 mgmt, reg; 776967dd82fSFlorian Fainelli 777967dd82fSFlorian Fainelli b53_switch_reset_gpio(dev); 778967dd82fSFlorian Fainelli 779967dd82fSFlorian Fainelli if (is539x(dev)) { 780967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x83); 781967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x00); 782967dd82fSFlorian Fainelli } 783967dd82fSFlorian Fainelli 7843fb22b05SFlorian Fainelli /* This is specific to 58xx devices here, do not use is58xx() which 7853fb22b05SFlorian Fainelli * covers the larger Starfigther 2 family, including 7445/7278 which 7863fb22b05SFlorian Fainelli * still use this driver as a library and need to perform the reset 7873fb22b05SFlorian Fainelli * earlier. 7883fb22b05SFlorian Fainelli */ 7895040cc99SArun Parameswaran if (dev->chip_id == BCM58XX_DEVICE_ID || 7905040cc99SArun Parameswaran dev->chip_id == BCM583XX_DEVICE_ID) { 7913fb22b05SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, ®); 7923fb22b05SFlorian Fainelli reg |= SW_RST | EN_SW_RST | EN_CH_RST; 7933fb22b05SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, reg); 7943fb22b05SFlorian Fainelli 7953fb22b05SFlorian Fainelli do { 7963fb22b05SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, ®); 7973fb22b05SFlorian Fainelli if (!(reg & SW_RST)) 7983fb22b05SFlorian Fainelli break; 7993fb22b05SFlorian Fainelli 8003fb22b05SFlorian Fainelli usleep_range(1000, 2000); 8013fb22b05SFlorian Fainelli } while (timeout-- > 0); 8023fb22b05SFlorian Fainelli 803434d2312SPaul Barker if (timeout == 0) { 804434d2312SPaul Barker dev_err(dev->dev, 805434d2312SPaul Barker "Timeout waiting for SW_RST to clear!\n"); 8063fb22b05SFlorian Fainelli return -ETIMEDOUT; 8073fb22b05SFlorian Fainelli } 808434d2312SPaul Barker } 8093fb22b05SFlorian Fainelli 810967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); 811967dd82fSFlorian Fainelli 812967dd82fSFlorian Fainelli if (!(mgmt & SM_SW_FWD_EN)) { 813967dd82fSFlorian Fainelli mgmt &= ~SM_SW_FWD_MODE; 814967dd82fSFlorian Fainelli mgmt |= SM_SW_FWD_EN; 815967dd82fSFlorian Fainelli 816967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt); 817967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); 818967dd82fSFlorian Fainelli 819967dd82fSFlorian Fainelli if (!(mgmt & SM_SW_FWD_EN)) { 820967dd82fSFlorian Fainelli dev_err(dev->dev, "Failed to enable switch!\n"); 821967dd82fSFlorian Fainelli return -EINVAL; 822967dd82fSFlorian Fainelli } 823967dd82fSFlorian Fainelli } 824967dd82fSFlorian Fainelli 825967dd82fSFlorian Fainelli b53_enable_mib(dev); 826967dd82fSFlorian Fainelli 827ff39c2d6SFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_STATIC); 828967dd82fSFlorian Fainelli } 829967dd82fSFlorian Fainelli 830967dd82fSFlorian Fainelli static int b53_phy_read16(struct dsa_switch *ds, int addr, int reg) 831967dd82fSFlorian Fainelli { 83204bed143SVivien Didelot struct b53_device *priv = ds->priv; 833967dd82fSFlorian Fainelli u16 value = 0; 834967dd82fSFlorian Fainelli int ret; 835967dd82fSFlorian Fainelli 836967dd82fSFlorian Fainelli if (priv->ops->phy_read16) 837967dd82fSFlorian Fainelli ret = priv->ops->phy_read16(priv, addr, reg, &value); 838967dd82fSFlorian Fainelli else 839967dd82fSFlorian Fainelli ret = b53_read16(priv, B53_PORT_MII_PAGE(addr), 840967dd82fSFlorian Fainelli reg * 2, &value); 841967dd82fSFlorian Fainelli 842967dd82fSFlorian Fainelli return ret ? ret : value; 843967dd82fSFlorian Fainelli } 844967dd82fSFlorian Fainelli 845967dd82fSFlorian Fainelli static int b53_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val) 846967dd82fSFlorian Fainelli { 84704bed143SVivien Didelot struct b53_device *priv = ds->priv; 848967dd82fSFlorian Fainelli 849967dd82fSFlorian Fainelli if (priv->ops->phy_write16) 850967dd82fSFlorian Fainelli return priv->ops->phy_write16(priv, addr, reg, val); 851967dd82fSFlorian Fainelli 852967dd82fSFlorian Fainelli return b53_write16(priv, B53_PORT_MII_PAGE(addr), reg * 2, val); 853967dd82fSFlorian Fainelli } 854967dd82fSFlorian Fainelli 855967dd82fSFlorian Fainelli static int b53_reset_switch(struct b53_device *priv) 856967dd82fSFlorian Fainelli { 857967dd82fSFlorian Fainelli /* reset vlans */ 858a2482d2cSFlorian Fainelli memset(priv->vlans, 0, sizeof(*priv->vlans) * priv->num_vlans); 859967dd82fSFlorian Fainelli memset(priv->ports, 0, sizeof(*priv->ports) * priv->num_ports); 860967dd82fSFlorian Fainelli 8610e01491dSFlorian Fainelli priv->serdes_lane = B53_INVALID_LANE; 8620e01491dSFlorian Fainelli 863967dd82fSFlorian Fainelli return b53_switch_reset(priv); 864967dd82fSFlorian Fainelli } 865967dd82fSFlorian Fainelli 866967dd82fSFlorian Fainelli static int b53_apply_config(struct b53_device *priv) 867967dd82fSFlorian Fainelli { 868967dd82fSFlorian Fainelli /* disable switching */ 869967dd82fSFlorian Fainelli b53_set_forwarding(priv, 0); 870967dd82fSFlorian Fainelli 8715c1a6eafSFlorian Fainelli b53_configure_vlan(priv->ds); 872967dd82fSFlorian Fainelli 873967dd82fSFlorian Fainelli /* enable switching */ 874967dd82fSFlorian Fainelli b53_set_forwarding(priv, 1); 875967dd82fSFlorian Fainelli 876967dd82fSFlorian Fainelli return 0; 877967dd82fSFlorian Fainelli } 878967dd82fSFlorian Fainelli 879967dd82fSFlorian Fainelli static void b53_reset_mib(struct b53_device *priv) 880967dd82fSFlorian Fainelli { 881967dd82fSFlorian Fainelli u8 gc; 882967dd82fSFlorian Fainelli 883967dd82fSFlorian Fainelli b53_read8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc); 884967dd82fSFlorian Fainelli 885967dd82fSFlorian Fainelli b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc | GC_RESET_MIB); 886967dd82fSFlorian Fainelli msleep(1); 887967dd82fSFlorian Fainelli b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc & ~GC_RESET_MIB); 888967dd82fSFlorian Fainelli msleep(1); 889967dd82fSFlorian Fainelli } 890967dd82fSFlorian Fainelli 891967dd82fSFlorian Fainelli static const struct b53_mib_desc *b53_get_mib(struct b53_device *dev) 892967dd82fSFlorian Fainelli { 893967dd82fSFlorian Fainelli if (is5365(dev)) 894967dd82fSFlorian Fainelli return b53_mibs_65; 895967dd82fSFlorian Fainelli else if (is63xx(dev)) 896967dd82fSFlorian Fainelli return b53_mibs_63xx; 897bde5d132SFlorian Fainelli else if (is58xx(dev)) 898bde5d132SFlorian Fainelli return b53_mibs_58xx; 899967dd82fSFlorian Fainelli else 900967dd82fSFlorian Fainelli return b53_mibs; 901967dd82fSFlorian Fainelli } 902967dd82fSFlorian Fainelli 903967dd82fSFlorian Fainelli static unsigned int b53_get_mib_size(struct b53_device *dev) 904967dd82fSFlorian Fainelli { 905967dd82fSFlorian Fainelli if (is5365(dev)) 906967dd82fSFlorian Fainelli return B53_MIBS_65_SIZE; 907967dd82fSFlorian Fainelli else if (is63xx(dev)) 908967dd82fSFlorian Fainelli return B53_MIBS_63XX_SIZE; 909bde5d132SFlorian Fainelli else if (is58xx(dev)) 910bde5d132SFlorian Fainelli return B53_MIBS_58XX_SIZE; 911967dd82fSFlorian Fainelli else 912967dd82fSFlorian Fainelli return B53_MIBS_SIZE; 913967dd82fSFlorian Fainelli } 914967dd82fSFlorian Fainelli 915c7d28c9dSFlorian Fainelli static struct phy_device *b53_get_phy_device(struct dsa_switch *ds, int port) 916c7d28c9dSFlorian Fainelli { 917c7d28c9dSFlorian Fainelli /* These ports typically do not have built-in PHYs */ 918c7d28c9dSFlorian Fainelli switch (port) { 919c7d28c9dSFlorian Fainelli case B53_CPU_PORT_25: 920c7d28c9dSFlorian Fainelli case 7: 921c7d28c9dSFlorian Fainelli case B53_CPU_PORT: 922c7d28c9dSFlorian Fainelli return NULL; 923c7d28c9dSFlorian Fainelli } 924c7d28c9dSFlorian Fainelli 925c7d28c9dSFlorian Fainelli return mdiobus_get_phy(ds->slave_mii_bus, port); 926c7d28c9dSFlorian Fainelli } 927c7d28c9dSFlorian Fainelli 92889f09048SFlorian Fainelli void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset, 92989f09048SFlorian Fainelli uint8_t *data) 930967dd82fSFlorian Fainelli { 93104bed143SVivien Didelot struct b53_device *dev = ds->priv; 932967dd82fSFlorian Fainelli const struct b53_mib_desc *mibs = b53_get_mib(dev); 933967dd82fSFlorian Fainelli unsigned int mib_size = b53_get_mib_size(dev); 934c7d28c9dSFlorian Fainelli struct phy_device *phydev; 935967dd82fSFlorian Fainelli unsigned int i; 936967dd82fSFlorian Fainelli 937c7d28c9dSFlorian Fainelli if (stringset == ETH_SS_STATS) { 938967dd82fSFlorian Fainelli for (i = 0; i < mib_size; i++) 939cd526676SFlorian Fainelli strlcpy(data + i * ETH_GSTRING_LEN, 940967dd82fSFlorian Fainelli mibs[i].name, ETH_GSTRING_LEN); 941c7d28c9dSFlorian Fainelli } else if (stringset == ETH_SS_PHY_STATS) { 942c7d28c9dSFlorian Fainelli phydev = b53_get_phy_device(ds, port); 943c7d28c9dSFlorian Fainelli if (!phydev) 944c7d28c9dSFlorian Fainelli return; 945c7d28c9dSFlorian Fainelli 946c7d28c9dSFlorian Fainelli phy_ethtool_get_strings(phydev, data); 947c7d28c9dSFlorian Fainelli } 948967dd82fSFlorian Fainelli } 9493117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_strings); 950967dd82fSFlorian Fainelli 9513117455dSFlorian Fainelli void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data) 952967dd82fSFlorian Fainelli { 95304bed143SVivien Didelot struct b53_device *dev = ds->priv; 954967dd82fSFlorian Fainelli const struct b53_mib_desc *mibs = b53_get_mib(dev); 955967dd82fSFlorian Fainelli unsigned int mib_size = b53_get_mib_size(dev); 956967dd82fSFlorian Fainelli const struct b53_mib_desc *s; 957967dd82fSFlorian Fainelli unsigned int i; 958967dd82fSFlorian Fainelli u64 val = 0; 959967dd82fSFlorian Fainelli 960967dd82fSFlorian Fainelli if (is5365(dev) && port == 5) 961967dd82fSFlorian Fainelli port = 8; 962967dd82fSFlorian Fainelli 963967dd82fSFlorian Fainelli mutex_lock(&dev->stats_mutex); 964967dd82fSFlorian Fainelli 965967dd82fSFlorian Fainelli for (i = 0; i < mib_size; i++) { 966967dd82fSFlorian Fainelli s = &mibs[i]; 967967dd82fSFlorian Fainelli 96851dca8a1SFlorian Fainelli if (s->size == 8) { 969967dd82fSFlorian Fainelli b53_read64(dev, B53_MIB_PAGE(port), s->offset, &val); 970967dd82fSFlorian Fainelli } else { 971967dd82fSFlorian Fainelli u32 val32; 972967dd82fSFlorian Fainelli 973967dd82fSFlorian Fainelli b53_read32(dev, B53_MIB_PAGE(port), s->offset, 974967dd82fSFlorian Fainelli &val32); 975967dd82fSFlorian Fainelli val = val32; 976967dd82fSFlorian Fainelli } 977967dd82fSFlorian Fainelli data[i] = (u64)val; 978967dd82fSFlorian Fainelli } 979967dd82fSFlorian Fainelli 980967dd82fSFlorian Fainelli mutex_unlock(&dev->stats_mutex); 981967dd82fSFlorian Fainelli } 9823117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_ethtool_stats); 983967dd82fSFlorian Fainelli 984c7d28c9dSFlorian Fainelli void b53_get_ethtool_phy_stats(struct dsa_switch *ds, int port, uint64_t *data) 985c7d28c9dSFlorian Fainelli { 986c7d28c9dSFlorian Fainelli struct phy_device *phydev; 987c7d28c9dSFlorian Fainelli 988c7d28c9dSFlorian Fainelli phydev = b53_get_phy_device(ds, port); 989c7d28c9dSFlorian Fainelli if (!phydev) 990c7d28c9dSFlorian Fainelli return; 991c7d28c9dSFlorian Fainelli 992c7d28c9dSFlorian Fainelli phy_ethtool_get_stats(phydev, NULL, data); 993c7d28c9dSFlorian Fainelli } 994c7d28c9dSFlorian Fainelli EXPORT_SYMBOL(b53_get_ethtool_phy_stats); 995c7d28c9dSFlorian Fainelli 99689f09048SFlorian Fainelli int b53_get_sset_count(struct dsa_switch *ds, int port, int sset) 997967dd82fSFlorian Fainelli { 99804bed143SVivien Didelot struct b53_device *dev = ds->priv; 999c7d28c9dSFlorian Fainelli struct phy_device *phydev; 1000967dd82fSFlorian Fainelli 1001c7d28c9dSFlorian Fainelli if (sset == ETH_SS_STATS) { 1002c7d28c9dSFlorian Fainelli return b53_get_mib_size(dev); 1003c7d28c9dSFlorian Fainelli } else if (sset == ETH_SS_PHY_STATS) { 1004c7d28c9dSFlorian Fainelli phydev = b53_get_phy_device(ds, port); 1005c7d28c9dSFlorian Fainelli if (!phydev) 100689f09048SFlorian Fainelli return 0; 100789f09048SFlorian Fainelli 1008c7d28c9dSFlorian Fainelli return phy_ethtool_get_sset_count(phydev); 1009c7d28c9dSFlorian Fainelli } 1010c7d28c9dSFlorian Fainelli 1011c7d28c9dSFlorian Fainelli return 0; 1012967dd82fSFlorian Fainelli } 10133117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_sset_count); 1014967dd82fSFlorian Fainelli 10154f6a5cafSFlorian Fainelli enum b53_devlink_resource_id { 10164f6a5cafSFlorian Fainelli B53_DEVLINK_PARAM_ID_VLAN_TABLE, 10174f6a5cafSFlorian Fainelli }; 10184f6a5cafSFlorian Fainelli 10194f6a5cafSFlorian Fainelli static u64 b53_devlink_vlan_table_get(void *priv) 10204f6a5cafSFlorian Fainelli { 10214f6a5cafSFlorian Fainelli struct b53_device *dev = priv; 10224f6a5cafSFlorian Fainelli struct b53_vlan *vl; 10234f6a5cafSFlorian Fainelli unsigned int i; 10244f6a5cafSFlorian Fainelli u64 count = 0; 10254f6a5cafSFlorian Fainelli 10264f6a5cafSFlorian Fainelli for (i = 0; i < dev->num_vlans; i++) { 10274f6a5cafSFlorian Fainelli vl = &dev->vlans[i]; 10284f6a5cafSFlorian Fainelli if (vl->members) 10294f6a5cafSFlorian Fainelli count++; 10304f6a5cafSFlorian Fainelli } 10314f6a5cafSFlorian Fainelli 10324f6a5cafSFlorian Fainelli return count; 10334f6a5cafSFlorian Fainelli } 10344f6a5cafSFlorian Fainelli 10354f6a5cafSFlorian Fainelli int b53_setup_devlink_resources(struct dsa_switch *ds) 10364f6a5cafSFlorian Fainelli { 10374f6a5cafSFlorian Fainelli struct devlink_resource_size_params size_params; 10384f6a5cafSFlorian Fainelli struct b53_device *dev = ds->priv; 10394f6a5cafSFlorian Fainelli int err; 10404f6a5cafSFlorian Fainelli 10414f6a5cafSFlorian Fainelli devlink_resource_size_params_init(&size_params, dev->num_vlans, 10424f6a5cafSFlorian Fainelli dev->num_vlans, 10434f6a5cafSFlorian Fainelli 1, DEVLINK_RESOURCE_UNIT_ENTRY); 10444f6a5cafSFlorian Fainelli 10454f6a5cafSFlorian Fainelli err = dsa_devlink_resource_register(ds, "VLAN", dev->num_vlans, 10464f6a5cafSFlorian Fainelli B53_DEVLINK_PARAM_ID_VLAN_TABLE, 10474f6a5cafSFlorian Fainelli DEVLINK_RESOURCE_ID_PARENT_TOP, 10484f6a5cafSFlorian Fainelli &size_params); 10494f6a5cafSFlorian Fainelli if (err) 10504f6a5cafSFlorian Fainelli goto out; 10514f6a5cafSFlorian Fainelli 10524f6a5cafSFlorian Fainelli dsa_devlink_resource_occ_get_register(ds, 10534f6a5cafSFlorian Fainelli B53_DEVLINK_PARAM_ID_VLAN_TABLE, 10544f6a5cafSFlorian Fainelli b53_devlink_vlan_table_get, dev); 10554f6a5cafSFlorian Fainelli 10564f6a5cafSFlorian Fainelli return 0; 10574f6a5cafSFlorian Fainelli out: 10584f6a5cafSFlorian Fainelli dsa_devlink_resources_unregister(ds); 10594f6a5cafSFlorian Fainelli return err; 10604f6a5cafSFlorian Fainelli } 10614f6a5cafSFlorian Fainelli EXPORT_SYMBOL(b53_setup_devlink_resources); 10624f6a5cafSFlorian Fainelli 1063967dd82fSFlorian Fainelli static int b53_setup(struct dsa_switch *ds) 1064967dd82fSFlorian Fainelli { 106504bed143SVivien Didelot struct b53_device *dev = ds->priv; 1066967dd82fSFlorian Fainelli unsigned int port; 1067967dd82fSFlorian Fainelli int ret; 1068967dd82fSFlorian Fainelli 1069967dd82fSFlorian Fainelli ret = b53_reset_switch(dev); 1070967dd82fSFlorian Fainelli if (ret) { 1071967dd82fSFlorian Fainelli dev_err(ds->dev, "failed to reset switch\n"); 1072967dd82fSFlorian Fainelli return ret; 1073967dd82fSFlorian Fainelli } 1074967dd82fSFlorian Fainelli 1075967dd82fSFlorian Fainelli b53_reset_mib(dev); 1076967dd82fSFlorian Fainelli 1077967dd82fSFlorian Fainelli ret = b53_apply_config(dev); 10784f6a5cafSFlorian Fainelli if (ret) { 1079967dd82fSFlorian Fainelli dev_err(ds->dev, "failed to apply configuration\n"); 10804f6a5cafSFlorian Fainelli return ret; 10814f6a5cafSFlorian Fainelli } 1082967dd82fSFlorian Fainelli 108375dad252SBenedikt Spranger /* Configure IMP/CPU port, disable all other ports. Enabled 108434c8befdSFlorian Fainelli * ports will be configured with .port_enable 108534c8befdSFlorian Fainelli */ 1086967dd82fSFlorian Fainelli for (port = 0; port < dev->num_ports; port++) { 108734c8befdSFlorian Fainelli if (dsa_is_cpu_port(ds, port)) 1088299752a7SFlorian Fainelli b53_enable_cpu_port(dev, port); 108975dad252SBenedikt Spranger else 109075104db0SAndrew Lunn b53_disable_port(ds, port); 1091967dd82fSFlorian Fainelli } 1092967dd82fSFlorian Fainelli 10937228b23eSVladimir Oltean /* Let DSA handle the case were multiple bridges span the same switch 10947228b23eSVladimir Oltean * device and different VLAN awareness settings are requested, which 10957228b23eSVladimir Oltean * would be breaking filtering semantics for any of the other bridge 10967228b23eSVladimir Oltean * devices. (not hardware supported) 10977228b23eSVladimir Oltean */ 10987228b23eSVladimir Oltean ds->vlan_filtering_is_global = true; 10997228b23eSVladimir Oltean 11004f6a5cafSFlorian Fainelli return b53_setup_devlink_resources(ds); 11014f6a5cafSFlorian Fainelli } 11024f6a5cafSFlorian Fainelli 11034f6a5cafSFlorian Fainelli static void b53_teardown(struct dsa_switch *ds) 11044f6a5cafSFlorian Fainelli { 11054f6a5cafSFlorian Fainelli dsa_devlink_resources_unregister(ds); 1106967dd82fSFlorian Fainelli } 1107967dd82fSFlorian Fainelli 11085e004460SFlorian Fainelli static void b53_force_link(struct b53_device *dev, int port, int link) 1109967dd82fSFlorian Fainelli { 11105e004460SFlorian Fainelli u8 reg, val, off; 1111967dd82fSFlorian Fainelli 1112967dd82fSFlorian Fainelli /* Override the port settings */ 1113967dd82fSFlorian Fainelli if (port == dev->cpu_port) { 1114967dd82fSFlorian Fainelli off = B53_PORT_OVERRIDE_CTRL; 11155e004460SFlorian Fainelli val = PORT_OVERRIDE_EN; 1116967dd82fSFlorian Fainelli } else { 1117967dd82fSFlorian Fainelli off = B53_GMII_PORT_OVERRIDE_CTRL(port); 11185e004460SFlorian Fainelli val = GMII_PO_EN; 1119967dd82fSFlorian Fainelli } 1120967dd82fSFlorian Fainelli 11215e004460SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, off, ®); 11225e004460SFlorian Fainelli reg |= val; 11235e004460SFlorian Fainelli if (link) 1124967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_LINK; 11255e004460SFlorian Fainelli else 11265e004460SFlorian Fainelli reg &= ~PORT_OVERRIDE_LINK; 11275e004460SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, off, reg); 11285e004460SFlorian Fainelli } 1129967dd82fSFlorian Fainelli 11305e004460SFlorian Fainelli static void b53_force_port_config(struct b53_device *dev, int port, 11313cad1c8bSRussell King int speed, int duplex, 11323cad1c8bSRussell King bool tx_pause, bool rx_pause) 11335e004460SFlorian Fainelli { 11345e004460SFlorian Fainelli u8 reg, val, off; 11355e004460SFlorian Fainelli 11365e004460SFlorian Fainelli /* Override the port settings */ 11375e004460SFlorian Fainelli if (port == dev->cpu_port) { 11385e004460SFlorian Fainelli off = B53_PORT_OVERRIDE_CTRL; 11395e004460SFlorian Fainelli val = PORT_OVERRIDE_EN; 11405e004460SFlorian Fainelli } else { 11415e004460SFlorian Fainelli off = B53_GMII_PORT_OVERRIDE_CTRL(port); 11425e004460SFlorian Fainelli val = GMII_PO_EN; 11435e004460SFlorian Fainelli } 11445e004460SFlorian Fainelli 11455e004460SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, off, ®); 11465e004460SFlorian Fainelli reg |= val; 11475e004460SFlorian Fainelli if (duplex == DUPLEX_FULL) 1148967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_FULL_DUPLEX; 11495e004460SFlorian Fainelli else 11505e004460SFlorian Fainelli reg &= ~PORT_OVERRIDE_FULL_DUPLEX; 1151967dd82fSFlorian Fainelli 11525e004460SFlorian Fainelli switch (speed) { 1153967dd82fSFlorian Fainelli case 2000: 1154967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_2000M; 1155df561f66SGustavo A. R. Silva fallthrough; 1156967dd82fSFlorian Fainelli case SPEED_1000: 1157967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_1000M; 1158967dd82fSFlorian Fainelli break; 1159967dd82fSFlorian Fainelli case SPEED_100: 1160967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_100M; 1161967dd82fSFlorian Fainelli break; 1162967dd82fSFlorian Fainelli case SPEED_10: 1163967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_10M; 1164967dd82fSFlorian Fainelli break; 1165967dd82fSFlorian Fainelli default: 11665e004460SFlorian Fainelli dev_err(dev->dev, "unknown speed: %d\n", speed); 1167967dd82fSFlorian Fainelli return; 1168967dd82fSFlorian Fainelli } 1169967dd82fSFlorian Fainelli 11703cad1c8bSRussell King if (rx_pause) 11715e004460SFlorian Fainelli reg |= PORT_OVERRIDE_RX_FLOW; 11723cad1c8bSRussell King if (tx_pause) 11735e004460SFlorian Fainelli reg |= PORT_OVERRIDE_TX_FLOW; 11745e004460SFlorian Fainelli 11755e004460SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, off, reg); 11765e004460SFlorian Fainelli } 11775e004460SFlorian Fainelli 11785e004460SFlorian Fainelli static void b53_adjust_link(struct dsa_switch *ds, int port, 11795e004460SFlorian Fainelli struct phy_device *phydev) 11805e004460SFlorian Fainelli { 11815e004460SFlorian Fainelli struct b53_device *dev = ds->priv; 11825e004460SFlorian Fainelli struct ethtool_eee *p = &dev->ports[port].eee; 11835e004460SFlorian Fainelli u8 rgmii_ctrl = 0, reg = 0, off; 11843cad1c8bSRussell King bool tx_pause = false; 11853cad1c8bSRussell King bool rx_pause = false; 11865e004460SFlorian Fainelli 11875e004460SFlorian Fainelli if (!phy_is_pseudo_fixed_link(phydev)) 11885e004460SFlorian Fainelli return; 11895e004460SFlorian Fainelli 1190967dd82fSFlorian Fainelli /* Enable flow control on BCM5301x's CPU port */ 1191967dd82fSFlorian Fainelli if (is5301x(dev) && port == dev->cpu_port) 11923cad1c8bSRussell King tx_pause = rx_pause = true; 1193967dd82fSFlorian Fainelli 1194967dd82fSFlorian Fainelli if (phydev->pause) { 1195967dd82fSFlorian Fainelli if (phydev->asym_pause) 11963cad1c8bSRussell King tx_pause = true; 11973cad1c8bSRussell King rx_pause = true; 1198967dd82fSFlorian Fainelli } 1199967dd82fSFlorian Fainelli 12003cad1c8bSRussell King b53_force_port_config(dev, port, phydev->speed, phydev->duplex, 12013cad1c8bSRussell King tx_pause, rx_pause); 12025e004460SFlorian Fainelli b53_force_link(dev, port, phydev->link); 1203967dd82fSFlorian Fainelli 1204967dd82fSFlorian Fainelli if (is531x5(dev) && phy_interface_is_rgmii(phydev)) { 1205967dd82fSFlorian Fainelli if (port == 8) 1206967dd82fSFlorian Fainelli off = B53_RGMII_CTRL_IMP; 1207967dd82fSFlorian Fainelli else 1208967dd82fSFlorian Fainelli off = B53_RGMII_CTRL_P(port); 1209967dd82fSFlorian Fainelli 1210967dd82fSFlorian Fainelli /* Configure the port RGMII clock delay by DLL disabled and 1211967dd82fSFlorian Fainelli * tx_clk aligned timing (restoring to reset defaults) 1212967dd82fSFlorian Fainelli */ 1213967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, off, &rgmii_ctrl); 1214967dd82fSFlorian Fainelli rgmii_ctrl &= ~(RGMII_CTRL_DLL_RXC | RGMII_CTRL_DLL_TXC | 1215967dd82fSFlorian Fainelli RGMII_CTRL_TIMING_SEL); 1216967dd82fSFlorian Fainelli 1217967dd82fSFlorian Fainelli /* PHY_INTERFACE_MODE_RGMII_TXID means TX internal delay, make 1218967dd82fSFlorian Fainelli * sure that we enable the port TX clock internal delay to 1219967dd82fSFlorian Fainelli * account for this internal delay that is inserted, otherwise 1220967dd82fSFlorian Fainelli * the switch won't be able to receive correctly. 1221967dd82fSFlorian Fainelli * 1222967dd82fSFlorian Fainelli * PHY_INTERFACE_MODE_RGMII means that we are not introducing 1223967dd82fSFlorian Fainelli * any delay neither on transmission nor reception, so the 1224967dd82fSFlorian Fainelli * BCM53125 must also be configured accordingly to account for 1225967dd82fSFlorian Fainelli * the lack of delay and introduce 1226967dd82fSFlorian Fainelli * 1227967dd82fSFlorian Fainelli * The BCM53125 switch has its RX clock and TX clock control 1228967dd82fSFlorian Fainelli * swapped, hence the reason why we modify the TX clock path in 1229967dd82fSFlorian Fainelli * the "RGMII" case 1230967dd82fSFlorian Fainelli */ 1231967dd82fSFlorian Fainelli if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) 1232967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_DLL_TXC; 1233967dd82fSFlorian Fainelli if (phydev->interface == PHY_INTERFACE_MODE_RGMII) 1234967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_DLL_TXC | RGMII_CTRL_DLL_RXC; 1235967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_TIMING_SEL; 1236967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, off, rgmii_ctrl); 1237967dd82fSFlorian Fainelli 1238967dd82fSFlorian Fainelli dev_info(ds->dev, "Configured port %d for %s\n", port, 1239967dd82fSFlorian Fainelli phy_modes(phydev->interface)); 1240967dd82fSFlorian Fainelli } 1241967dd82fSFlorian Fainelli 1242967dd82fSFlorian Fainelli /* configure MII port if necessary */ 1243967dd82fSFlorian Fainelli if (is5325(dev)) { 1244967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, 1245967dd82fSFlorian Fainelli ®); 1246967dd82fSFlorian Fainelli 1247967dd82fSFlorian Fainelli /* reverse mii needs to be enabled */ 1248967dd82fSFlorian Fainelli if (!(reg & PORT_OVERRIDE_RV_MII_25)) { 1249967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, 1250967dd82fSFlorian Fainelli reg | PORT_OVERRIDE_RV_MII_25); 1251967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, 1252967dd82fSFlorian Fainelli ®); 1253967dd82fSFlorian Fainelli 1254967dd82fSFlorian Fainelli if (!(reg & PORT_OVERRIDE_RV_MII_25)) { 1255967dd82fSFlorian Fainelli dev_err(ds->dev, 1256967dd82fSFlorian Fainelli "Failed to enable reverse MII mode\n"); 1257967dd82fSFlorian Fainelli return; 1258967dd82fSFlorian Fainelli } 1259967dd82fSFlorian Fainelli } 1260967dd82fSFlorian Fainelli } else if (is5301x(dev)) { 1261967dd82fSFlorian Fainelli if (port != dev->cpu_port) { 12625e004460SFlorian Fainelli b53_force_port_config(dev, dev->cpu_port, 2000, 12633cad1c8bSRussell King DUPLEX_FULL, true, true); 12645e004460SFlorian Fainelli b53_force_link(dev, dev->cpu_port, 1); 1265967dd82fSFlorian Fainelli } 1266967dd82fSFlorian Fainelli } 1267f43a2dbeSFlorian Fainelli 1268f43a2dbeSFlorian Fainelli /* Re-negotiate EEE if it was enabled already */ 1269f43a2dbeSFlorian Fainelli p->eee_enabled = b53_eee_init(ds, port, phydev); 1270967dd82fSFlorian Fainelli } 1271967dd82fSFlorian Fainelli 1272a8e8b985SFlorian Fainelli void b53_port_event(struct dsa_switch *ds, int port) 1273a8e8b985SFlorian Fainelli { 1274a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1275a8e8b985SFlorian Fainelli bool link; 1276a8e8b985SFlorian Fainelli u16 sts; 1277a8e8b985SFlorian Fainelli 1278a8e8b985SFlorian Fainelli b53_read16(dev, B53_STAT_PAGE, B53_LINK_STAT, &sts); 1279a8e8b985SFlorian Fainelli link = !!(sts & BIT(port)); 1280a8e8b985SFlorian Fainelli dsa_port_phylink_mac_change(ds, port, link); 1281a8e8b985SFlorian Fainelli } 1282a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_port_event); 1283a8e8b985SFlorian Fainelli 1284a8e8b985SFlorian Fainelli void b53_phylink_validate(struct dsa_switch *ds, int port, 1285a8e8b985SFlorian Fainelli unsigned long *supported, 1286a8e8b985SFlorian Fainelli struct phylink_link_state *state) 1287a8e8b985SFlorian Fainelli { 1288a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1289a8e8b985SFlorian Fainelli __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, }; 1290a8e8b985SFlorian Fainelli 12910e01491dSFlorian Fainelli if (dev->ops->serdes_phylink_validate) 12920e01491dSFlorian Fainelli dev->ops->serdes_phylink_validate(dev, port, mask, state); 12930e01491dSFlorian Fainelli 1294a8e8b985SFlorian Fainelli /* Allow all the expected bits */ 1295a8e8b985SFlorian Fainelli phylink_set(mask, Autoneg); 1296a8e8b985SFlorian Fainelli phylink_set_port_modes(mask); 1297a8e8b985SFlorian Fainelli phylink_set(mask, Pause); 1298a8e8b985SFlorian Fainelli phylink_set(mask, Asym_Pause); 1299a8e8b985SFlorian Fainelli 1300a8e8b985SFlorian Fainelli /* With the exclusion of 5325/5365, MII, Reverse MII and 802.3z, we 1301a8e8b985SFlorian Fainelli * support Gigabit, including Half duplex. 1302a8e8b985SFlorian Fainelli */ 1303a8e8b985SFlorian Fainelli if (state->interface != PHY_INTERFACE_MODE_MII && 1304a8e8b985SFlorian Fainelli state->interface != PHY_INTERFACE_MODE_REVMII && 1305a8e8b985SFlorian Fainelli !phy_interface_mode_is_8023z(state->interface) && 1306a8e8b985SFlorian Fainelli !(is5325(dev) || is5365(dev))) { 1307a8e8b985SFlorian Fainelli phylink_set(mask, 1000baseT_Full); 1308a8e8b985SFlorian Fainelli phylink_set(mask, 1000baseT_Half); 1309a8e8b985SFlorian Fainelli } 1310a8e8b985SFlorian Fainelli 1311a8e8b985SFlorian Fainelli if (!phy_interface_mode_is_8023z(state->interface)) { 1312a8e8b985SFlorian Fainelli phylink_set(mask, 10baseT_Half); 1313a8e8b985SFlorian Fainelli phylink_set(mask, 10baseT_Full); 1314a8e8b985SFlorian Fainelli phylink_set(mask, 100baseT_Half); 1315a8e8b985SFlorian Fainelli phylink_set(mask, 100baseT_Full); 1316a8e8b985SFlorian Fainelli } 1317a8e8b985SFlorian Fainelli 1318a8e8b985SFlorian Fainelli bitmap_and(supported, supported, mask, 1319a8e8b985SFlorian Fainelli __ETHTOOL_LINK_MODE_MASK_NBITS); 1320a8e8b985SFlorian Fainelli bitmap_and(state->advertising, state->advertising, mask, 1321a8e8b985SFlorian Fainelli __ETHTOOL_LINK_MODE_MASK_NBITS); 1322a8e8b985SFlorian Fainelli 1323a8e8b985SFlorian Fainelli phylink_helper_basex_speed(state); 1324a8e8b985SFlorian Fainelli } 1325a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_validate); 1326a8e8b985SFlorian Fainelli 1327a8e8b985SFlorian Fainelli int b53_phylink_mac_link_state(struct dsa_switch *ds, int port, 1328a8e8b985SFlorian Fainelli struct phylink_link_state *state) 1329a8e8b985SFlorian Fainelli { 13300e01491dSFlorian Fainelli struct b53_device *dev = ds->priv; 1331a8e8b985SFlorian Fainelli int ret = -EOPNOTSUPP; 1332a8e8b985SFlorian Fainelli 133355a4d2eaSFlorian Fainelli if ((phy_interface_mode_is_8023z(state->interface) || 133455a4d2eaSFlorian Fainelli state->interface == PHY_INTERFACE_MODE_SGMII) && 13350e01491dSFlorian Fainelli dev->ops->serdes_link_state) 13360e01491dSFlorian Fainelli ret = dev->ops->serdes_link_state(dev, port, state); 13370e01491dSFlorian Fainelli 1338a8e8b985SFlorian Fainelli return ret; 1339a8e8b985SFlorian Fainelli } 1340a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_state); 1341a8e8b985SFlorian Fainelli 1342a8e8b985SFlorian Fainelli void b53_phylink_mac_config(struct dsa_switch *ds, int port, 1343a8e8b985SFlorian Fainelli unsigned int mode, 1344a8e8b985SFlorian Fainelli const struct phylink_link_state *state) 1345a8e8b985SFlorian Fainelli { 1346a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1347a8e8b985SFlorian Fainelli 1348ab017b79SRussell King if (mode == MLO_AN_PHY || mode == MLO_AN_FIXED) 1349a8e8b985SFlorian Fainelli return; 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_config) 13540e01491dSFlorian Fainelli dev->ops->serdes_config(dev, port, mode, state); 1355a8e8b985SFlorian Fainelli } 1356a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_config); 1357a8e8b985SFlorian Fainelli 1358a8e8b985SFlorian Fainelli void b53_phylink_mac_an_restart(struct dsa_switch *ds, int port) 1359a8e8b985SFlorian Fainelli { 13600e01491dSFlorian Fainelli struct b53_device *dev = ds->priv; 13610e01491dSFlorian Fainelli 13620e01491dSFlorian Fainelli if (dev->ops->serdes_an_restart) 13630e01491dSFlorian Fainelli dev->ops->serdes_an_restart(dev, port); 1364a8e8b985SFlorian Fainelli } 1365a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_an_restart); 1366a8e8b985SFlorian Fainelli 1367a8e8b985SFlorian Fainelli void b53_phylink_mac_link_down(struct dsa_switch *ds, int port, 1368a8e8b985SFlorian Fainelli unsigned int mode, 1369a8e8b985SFlorian Fainelli phy_interface_t interface) 1370a8e8b985SFlorian Fainelli { 1371a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1372a8e8b985SFlorian Fainelli 1373a8e8b985SFlorian Fainelli if (mode == MLO_AN_PHY) 1374a8e8b985SFlorian Fainelli return; 1375a8e8b985SFlorian Fainelli 1376a8e8b985SFlorian Fainelli if (mode == MLO_AN_FIXED) { 1377a8e8b985SFlorian Fainelli b53_force_link(dev, port, false); 1378a8e8b985SFlorian Fainelli return; 1379a8e8b985SFlorian Fainelli } 13800e01491dSFlorian Fainelli 13810e01491dSFlorian Fainelli if (phy_interface_mode_is_8023z(interface) && 13820e01491dSFlorian Fainelli dev->ops->serdes_link_set) 13830e01491dSFlorian Fainelli dev->ops->serdes_link_set(dev, port, mode, interface, false); 1384a8e8b985SFlorian Fainelli } 1385a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_down); 1386a8e8b985SFlorian Fainelli 1387a8e8b985SFlorian Fainelli void b53_phylink_mac_link_up(struct dsa_switch *ds, int port, 1388a8e8b985SFlorian Fainelli unsigned int mode, 1389a8e8b985SFlorian Fainelli phy_interface_t interface, 13905b502a7bSRussell King struct phy_device *phydev, 13915b502a7bSRussell King int speed, int duplex, 13925b502a7bSRussell King bool tx_pause, bool rx_pause) 1393a8e8b985SFlorian Fainelli { 1394a8e8b985SFlorian Fainelli struct b53_device *dev = ds->priv; 1395a8e8b985SFlorian Fainelli 1396a8e8b985SFlorian Fainelli if (mode == MLO_AN_PHY) 1397a8e8b985SFlorian Fainelli return; 1398a8e8b985SFlorian Fainelli 1399a8e8b985SFlorian Fainelli if (mode == MLO_AN_FIXED) { 1400ab017b79SRussell King b53_force_port_config(dev, port, speed, duplex, 1401ab017b79SRussell King tx_pause, rx_pause); 1402a8e8b985SFlorian Fainelli b53_force_link(dev, port, true); 1403a8e8b985SFlorian Fainelli return; 1404a8e8b985SFlorian Fainelli } 14050e01491dSFlorian Fainelli 14060e01491dSFlorian Fainelli if (phy_interface_mode_is_8023z(interface) && 14070e01491dSFlorian Fainelli dev->ops->serdes_link_set) 14080e01491dSFlorian Fainelli dev->ops->serdes_link_set(dev, port, mode, interface, true); 1409a8e8b985SFlorian Fainelli } 1410a8e8b985SFlorian Fainelli EXPORT_SYMBOL(b53_phylink_mac_link_up); 1411a8e8b985SFlorian Fainelli 1412*89153ed6SVladimir Oltean int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering, 1413*89153ed6SVladimir Oltean struct netlink_ext_ack *extack) 1414a2482d2cSFlorian Fainelli { 1415dad8d7c6SFlorian Fainelli struct b53_device *dev = ds->priv; 1416dad8d7c6SFlorian Fainelli 1417dad8d7c6SFlorian Fainelli b53_enable_vlan(dev, dev->vlan_enabled, vlan_filtering); 1418dad8d7c6SFlorian Fainelli 1419a2482d2cSFlorian Fainelli return 0; 1420a2482d2cSFlorian Fainelli } 14213117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_filtering); 1422a2482d2cSFlorian Fainelli 14231958d581SVladimir Oltean static int b53_vlan_prepare(struct dsa_switch *ds, int port, 142480e02360SVivien Didelot const struct switchdev_obj_port_vlan *vlan) 1425a2482d2cSFlorian Fainelli { 142604bed143SVivien Didelot struct b53_device *dev = ds->priv; 1427a2482d2cSFlorian Fainelli 1428b7a9e0daSVladimir Oltean if ((is5325(dev) || is5365(dev)) && vlan->vid == 0) 1429a2482d2cSFlorian Fainelli return -EOPNOTSUPP; 1430a2482d2cSFlorian Fainelli 143188631864SFlorian Fainelli /* Port 7 on 7278 connects to the ASP's UniMAC which is not capable of 143288631864SFlorian Fainelli * receiving VLAN tagged frames at all, we can still allow the port to 143388631864SFlorian Fainelli * be configured for egress untagged. 143488631864SFlorian Fainelli */ 143588631864SFlorian Fainelli if (dev->chip_id == BCM7278_DEVICE_ID && port == 7 && 143688631864SFlorian Fainelli !(vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED)) 143788631864SFlorian Fainelli return -EINVAL; 143888631864SFlorian Fainelli 14390fe2f273SJakub Kicinski if (vlan->vid >= dev->num_vlans) 1440a2482d2cSFlorian Fainelli return -ERANGE; 1441a2482d2cSFlorian Fainelli 1442e74f014eSVladimir Oltean b53_enable_vlan(dev, true, ds->vlan_filtering); 1443a2482d2cSFlorian Fainelli 1444a2482d2cSFlorian Fainelli return 0; 1445a2482d2cSFlorian Fainelli } 1446a2482d2cSFlorian Fainelli 14471958d581SVladimir Oltean int b53_vlan_add(struct dsa_switch *ds, int port, 144831046a5fSVladimir Oltean const struct switchdev_obj_port_vlan *vlan, 144931046a5fSVladimir Oltean struct netlink_ext_ack *extack) 1450a2482d2cSFlorian Fainelli { 145104bed143SVivien Didelot struct b53_device *dev = ds->priv; 1452a2482d2cSFlorian Fainelli bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; 1453a2482d2cSFlorian Fainelli bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID; 1454a2482d2cSFlorian Fainelli struct b53_vlan *vl; 14551958d581SVladimir Oltean int err; 14561958d581SVladimir Oltean 14571958d581SVladimir Oltean err = b53_vlan_prepare(ds, port, vlan); 14581958d581SVladimir Oltean if (err) 14591958d581SVladimir Oltean return err; 1460a2482d2cSFlorian Fainelli 1461b7a9e0daSVladimir Oltean vl = &dev->vlans[vlan->vid]; 1462a2482d2cSFlorian Fainelli 1463b7a9e0daSVladimir Oltean b53_get_vlan_entry(dev, vlan->vid, vl); 1464a2482d2cSFlorian Fainelli 1465b7a9e0daSVladimir Oltean if (vlan->vid == 0 && vlan->vid == b53_default_pvid(dev)) 1466d965a543SFlorian Fainelli untagged = true; 1467d965a543SFlorian Fainelli 1468c499696eSFlorian Fainelli vl->members |= BIT(port); 1469ca893194SFlorian Fainelli if (untagged && !dsa_is_cpu_port(ds, port)) 1470e47112d9SFlorian Fainelli vl->untag |= BIT(port); 1471a2482d2cSFlorian Fainelli else 1472e47112d9SFlorian Fainelli vl->untag &= ~BIT(port); 1473a2482d2cSFlorian Fainelli 1474b7a9e0daSVladimir Oltean b53_set_vlan_entry(dev, vlan->vid, vl); 1475b7a9e0daSVladimir Oltean b53_fast_age_vlan(dev, vlan->vid); 1476a2482d2cSFlorian Fainelli 147710163aaeSFlorian Fainelli if (pvid && !dsa_is_cpu_port(ds, port)) { 1478a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), 1479b7a9e0daSVladimir Oltean vlan->vid); 1480b7a9e0daSVladimir Oltean b53_fast_age_vlan(dev, vlan->vid); 1481a2482d2cSFlorian Fainelli } 14821958d581SVladimir Oltean 14831958d581SVladimir Oltean return 0; 1484a2482d2cSFlorian Fainelli } 14853117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_add); 1486a2482d2cSFlorian Fainelli 14873117455dSFlorian Fainelli int b53_vlan_del(struct dsa_switch *ds, int port, 1488a2482d2cSFlorian Fainelli const struct switchdev_obj_port_vlan *vlan) 1489a2482d2cSFlorian Fainelli { 149004bed143SVivien Didelot struct b53_device *dev = ds->priv; 1491a2482d2cSFlorian Fainelli bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; 1492a2482d2cSFlorian Fainelli struct b53_vlan *vl; 1493a2482d2cSFlorian Fainelli u16 pvid; 1494a2482d2cSFlorian Fainelli 1495a2482d2cSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid); 1496a2482d2cSFlorian Fainelli 1497b7a9e0daSVladimir Oltean vl = &dev->vlans[vlan->vid]; 1498a2482d2cSFlorian Fainelli 1499b7a9e0daSVladimir Oltean b53_get_vlan_entry(dev, vlan->vid, vl); 1500a2482d2cSFlorian Fainelli 1501a2482d2cSFlorian Fainelli vl->members &= ~BIT(port); 1502a2482d2cSFlorian Fainelli 1503b7a9e0daSVladimir Oltean if (pvid == vlan->vid) 1504fea83353SFlorian Fainelli pvid = b53_default_pvid(dev); 1505a2482d2cSFlorian Fainelli 1506ca893194SFlorian Fainelli if (untagged && !dsa_is_cpu_port(ds, port)) 1507a2482d2cSFlorian Fainelli vl->untag &= ~(BIT(port)); 1508a2482d2cSFlorian Fainelli 1509b7a9e0daSVladimir Oltean b53_set_vlan_entry(dev, vlan->vid, vl); 1510b7a9e0daSVladimir Oltean b53_fast_age_vlan(dev, vlan->vid); 1511a2482d2cSFlorian Fainelli 1512a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), pvid); 1513a2482d2cSFlorian Fainelli b53_fast_age_vlan(dev, pvid); 1514a2482d2cSFlorian Fainelli 1515a2482d2cSFlorian Fainelli return 0; 1516a2482d2cSFlorian Fainelli } 15173117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_del); 1518a2482d2cSFlorian Fainelli 15191da6df85SFlorian Fainelli /* Address Resolution Logic routines */ 15201da6df85SFlorian Fainelli static int b53_arl_op_wait(struct b53_device *dev) 15211da6df85SFlorian Fainelli { 15221da6df85SFlorian Fainelli unsigned int timeout = 10; 15231da6df85SFlorian Fainelli u8 reg; 15241da6df85SFlorian Fainelli 15251da6df85SFlorian Fainelli do { 15261da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, ®); 15271da6df85SFlorian Fainelli if (!(reg & ARLTBL_START_DONE)) 15281da6df85SFlorian Fainelli return 0; 15291da6df85SFlorian Fainelli 15301da6df85SFlorian Fainelli usleep_range(1000, 2000); 15311da6df85SFlorian Fainelli } while (timeout--); 15321da6df85SFlorian Fainelli 15331da6df85SFlorian Fainelli dev_warn(dev->dev, "timeout waiting for ARL to finish: 0x%02x\n", reg); 15341da6df85SFlorian Fainelli 15351da6df85SFlorian Fainelli return -ETIMEDOUT; 15361da6df85SFlorian Fainelli } 15371da6df85SFlorian Fainelli 15381da6df85SFlorian Fainelli static int b53_arl_rw_op(struct b53_device *dev, unsigned int op) 15391da6df85SFlorian Fainelli { 15401da6df85SFlorian Fainelli u8 reg; 15411da6df85SFlorian Fainelli 15421da6df85SFlorian Fainelli if (op > ARLTBL_RW) 15431da6df85SFlorian Fainelli return -EINVAL; 15441da6df85SFlorian Fainelli 15451da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, ®); 15461da6df85SFlorian Fainelli reg |= ARLTBL_START_DONE; 15471da6df85SFlorian Fainelli if (op) 15481da6df85SFlorian Fainelli reg |= ARLTBL_RW; 15491da6df85SFlorian Fainelli else 15501da6df85SFlorian Fainelli reg &= ~ARLTBL_RW; 155164fec949SFlorian Fainelli if (dev->vlan_enabled) 155264fec949SFlorian Fainelli reg &= ~ARLTBL_IVL_SVL_SELECT; 155364fec949SFlorian Fainelli else 155464fec949SFlorian Fainelli reg |= ARLTBL_IVL_SVL_SELECT; 15551da6df85SFlorian Fainelli b53_write8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, reg); 15561da6df85SFlorian Fainelli 15571da6df85SFlorian Fainelli return b53_arl_op_wait(dev); 15581da6df85SFlorian Fainelli } 15591da6df85SFlorian Fainelli 15601da6df85SFlorian Fainelli static int b53_arl_read(struct b53_device *dev, u64 mac, 1561ef2a0bd9SFlorian Fainelli u16 vid, struct b53_arl_entry *ent, u8 *idx) 15621da6df85SFlorian Fainelli { 15636344dbdeSFlorian Fainelli DECLARE_BITMAP(free_bins, B53_ARLTBL_MAX_BIN_ENTRIES); 15641da6df85SFlorian Fainelli unsigned int i; 15651da6df85SFlorian Fainelli int ret; 15661da6df85SFlorian Fainelli 15671da6df85SFlorian Fainelli ret = b53_arl_op_wait(dev); 15681da6df85SFlorian Fainelli if (ret) 15691da6df85SFlorian Fainelli return ret; 15701da6df85SFlorian Fainelli 1571673e69a6SFlorian Fainelli bitmap_zero(free_bins, dev->num_arl_bins); 15726344dbdeSFlorian Fainelli 15731da6df85SFlorian Fainelli /* Read the bins */ 1574673e69a6SFlorian Fainelli for (i = 0; i < dev->num_arl_bins; i++) { 15751da6df85SFlorian Fainelli u64 mac_vid; 15761da6df85SFlorian Fainelli u32 fwd_entry; 15771da6df85SFlorian Fainelli 15781da6df85SFlorian Fainelli b53_read64(dev, B53_ARLIO_PAGE, 15791da6df85SFlorian Fainelli B53_ARLTBL_MAC_VID_ENTRY(i), &mac_vid); 15801da6df85SFlorian Fainelli b53_read32(dev, B53_ARLIO_PAGE, 15811da6df85SFlorian Fainelli B53_ARLTBL_DATA_ENTRY(i), &fwd_entry); 15821da6df85SFlorian Fainelli b53_arl_to_entry(ent, mac_vid, fwd_entry); 15831da6df85SFlorian Fainelli 15846344dbdeSFlorian Fainelli if (!(fwd_entry & ARLTBL_VALID)) { 15856344dbdeSFlorian Fainelli set_bit(i, free_bins); 15861da6df85SFlorian Fainelli continue; 15876344dbdeSFlorian Fainelli } 15881da6df85SFlorian Fainelli if ((mac_vid & ARLTBL_MAC_MASK) != mac) 15891da6df85SFlorian Fainelli continue; 15902e97b0cdSFlorian Fainelli if (dev->vlan_enabled && 15912e97b0cdSFlorian Fainelli ((mac_vid >> ARLTBL_VID_S) & ARLTBL_VID_MASK) != vid) 15922e97b0cdSFlorian Fainelli continue; 15931da6df85SFlorian Fainelli *idx = i; 15946344dbdeSFlorian Fainelli return 0; 15951da6df85SFlorian Fainelli } 15961da6df85SFlorian Fainelli 1597673e69a6SFlorian Fainelli if (bitmap_weight(free_bins, dev->num_arl_bins) == 0) 15986344dbdeSFlorian Fainelli return -ENOSPC; 15996344dbdeSFlorian Fainelli 1600673e69a6SFlorian Fainelli *idx = find_first_bit(free_bins, dev->num_arl_bins); 16016344dbdeSFlorian Fainelli 16021da6df85SFlorian Fainelli return -ENOENT; 16031da6df85SFlorian Fainelli } 16041da6df85SFlorian Fainelli 16051da6df85SFlorian Fainelli static int b53_arl_op(struct b53_device *dev, int op, int port, 16061da6df85SFlorian Fainelli const unsigned char *addr, u16 vid, bool is_valid) 16071da6df85SFlorian Fainelli { 16081da6df85SFlorian Fainelli struct b53_arl_entry ent; 16091da6df85SFlorian Fainelli u32 fwd_entry; 16101da6df85SFlorian Fainelli u64 mac, mac_vid = 0; 16111da6df85SFlorian Fainelli u8 idx = 0; 16121da6df85SFlorian Fainelli int ret; 16131da6df85SFlorian Fainelli 16141da6df85SFlorian Fainelli /* Convert the array into a 64-bit MAC */ 16154b92ea81SFlorian Fainelli mac = ether_addr_to_u64(addr); 16161da6df85SFlorian Fainelli 16171da6df85SFlorian Fainelli /* Perform a read for the given MAC and VID */ 16181da6df85SFlorian Fainelli b53_write48(dev, B53_ARLIO_PAGE, B53_MAC_ADDR_IDX, mac); 16191da6df85SFlorian Fainelli b53_write16(dev, B53_ARLIO_PAGE, B53_VLAN_ID_IDX, vid); 16201da6df85SFlorian Fainelli 16211da6df85SFlorian Fainelli /* Issue a read operation for this MAC */ 16221da6df85SFlorian Fainelli ret = b53_arl_rw_op(dev, 1); 16231da6df85SFlorian Fainelli if (ret) 16241da6df85SFlorian Fainelli return ret; 16251da6df85SFlorian Fainelli 1626ef2a0bd9SFlorian Fainelli ret = b53_arl_read(dev, mac, vid, &ent, &idx); 1627ef2a0bd9SFlorian Fainelli 16281da6df85SFlorian Fainelli /* If this is a read, just finish now */ 16291da6df85SFlorian Fainelli if (op) 16301da6df85SFlorian Fainelli return ret; 16311da6df85SFlorian Fainelli 16326344dbdeSFlorian Fainelli switch (ret) { 1633774d977aSTom Rix case -ETIMEDOUT: 1634774d977aSTom Rix return ret; 16356344dbdeSFlorian Fainelli case -ENOSPC: 16366344dbdeSFlorian Fainelli dev_dbg(dev->dev, "{%pM,%.4d} no space left in ARL\n", 16376344dbdeSFlorian Fainelli addr, vid); 16386344dbdeSFlorian Fainelli return is_valid ? ret : 0; 16396344dbdeSFlorian Fainelli case -ENOENT: 16401da6df85SFlorian Fainelli /* We could not find a matching MAC, so reset to a new entry */ 16416344dbdeSFlorian Fainelli dev_dbg(dev->dev, "{%pM,%.4d} not found, using idx: %d\n", 16426344dbdeSFlorian Fainelli addr, vid, idx); 16431da6df85SFlorian Fainelli fwd_entry = 0; 16446344dbdeSFlorian Fainelli break; 16456344dbdeSFlorian Fainelli default: 16466344dbdeSFlorian Fainelli dev_dbg(dev->dev, "{%pM,%.4d} found, using idx: %d\n", 16476344dbdeSFlorian Fainelli addr, vid, idx); 16486344dbdeSFlorian Fainelli break; 16491da6df85SFlorian Fainelli } 16501da6df85SFlorian Fainelli 16515d65b64aSFlorian Fainelli /* For multicast address, the port is a bitmask and the validity 16525d65b64aSFlorian Fainelli * is determined by having at least one port being still active 16535d65b64aSFlorian Fainelli */ 16545d65b64aSFlorian Fainelli if (!is_multicast_ether_addr(addr)) { 16551da6df85SFlorian Fainelli ent.port = port; 16561da6df85SFlorian Fainelli ent.is_valid = is_valid; 16575d65b64aSFlorian Fainelli } else { 16585d65b64aSFlorian Fainelli if (is_valid) 16595d65b64aSFlorian Fainelli ent.port |= BIT(port); 16605d65b64aSFlorian Fainelli else 16615d65b64aSFlorian Fainelli ent.port &= ~BIT(port); 16625d65b64aSFlorian Fainelli 16635d65b64aSFlorian Fainelli ent.is_valid = !!(ent.port); 16645d65b64aSFlorian Fainelli } 16655d65b64aSFlorian Fainelli 16661da6df85SFlorian Fainelli ent.vid = vid; 16671da6df85SFlorian Fainelli ent.is_static = true; 16685d65b64aSFlorian Fainelli ent.is_age = false; 16691da6df85SFlorian Fainelli memcpy(ent.mac, addr, ETH_ALEN); 16701da6df85SFlorian Fainelli b53_arl_from_entry(&mac_vid, &fwd_entry, &ent); 16711da6df85SFlorian Fainelli 16721da6df85SFlorian Fainelli b53_write64(dev, B53_ARLIO_PAGE, 16731da6df85SFlorian Fainelli B53_ARLTBL_MAC_VID_ENTRY(idx), mac_vid); 16741da6df85SFlorian Fainelli b53_write32(dev, B53_ARLIO_PAGE, 16751da6df85SFlorian Fainelli B53_ARLTBL_DATA_ENTRY(idx), fwd_entry); 16761da6df85SFlorian Fainelli 16771da6df85SFlorian Fainelli return b53_arl_rw_op(dev, 0); 16781da6df85SFlorian Fainelli } 16791da6df85SFlorian Fainelli 16801b6dd556SArkadi Sharshevsky int b53_fdb_add(struct dsa_switch *ds, int port, 16816c2c1dcbSArkadi Sharshevsky const unsigned char *addr, u16 vid) 16821da6df85SFlorian Fainelli { 168304bed143SVivien Didelot struct b53_device *priv = ds->priv; 16841da6df85SFlorian Fainelli 16851da6df85SFlorian Fainelli /* 5325 and 5365 require some more massaging, but could 16861da6df85SFlorian Fainelli * be supported eventually 16871da6df85SFlorian Fainelli */ 16881da6df85SFlorian Fainelli if (is5325(priv) || is5365(priv)) 16891da6df85SFlorian Fainelli return -EOPNOTSUPP; 16901da6df85SFlorian Fainelli 16911b6dd556SArkadi Sharshevsky return b53_arl_op(priv, 0, port, addr, vid, true); 16921da6df85SFlorian Fainelli } 16933117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_add); 16941da6df85SFlorian Fainelli 16953117455dSFlorian Fainelli int b53_fdb_del(struct dsa_switch *ds, int port, 16966c2c1dcbSArkadi Sharshevsky const unsigned char *addr, u16 vid) 16971da6df85SFlorian Fainelli { 169804bed143SVivien Didelot struct b53_device *priv = ds->priv; 16991da6df85SFlorian Fainelli 17006c2c1dcbSArkadi Sharshevsky return b53_arl_op(priv, 0, port, addr, vid, false); 17011da6df85SFlorian Fainelli } 17023117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_del); 17031da6df85SFlorian Fainelli 17041da6df85SFlorian Fainelli static int b53_arl_search_wait(struct b53_device *dev) 17051da6df85SFlorian Fainelli { 17061da6df85SFlorian Fainelli unsigned int timeout = 1000; 17071da6df85SFlorian Fainelli u8 reg; 17081da6df85SFlorian Fainelli 17091da6df85SFlorian Fainelli do { 17101da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, ®); 17111da6df85SFlorian Fainelli if (!(reg & ARL_SRCH_STDN)) 17121da6df85SFlorian Fainelli return 0; 17131da6df85SFlorian Fainelli 17141da6df85SFlorian Fainelli if (reg & ARL_SRCH_VLID) 17151da6df85SFlorian Fainelli return 0; 17161da6df85SFlorian Fainelli 17171da6df85SFlorian Fainelli usleep_range(1000, 2000); 17181da6df85SFlorian Fainelli } while (timeout--); 17191da6df85SFlorian Fainelli 17201da6df85SFlorian Fainelli return -ETIMEDOUT; 17211da6df85SFlorian Fainelli } 17221da6df85SFlorian Fainelli 17231da6df85SFlorian Fainelli static void b53_arl_search_rd(struct b53_device *dev, u8 idx, 17241da6df85SFlorian Fainelli struct b53_arl_entry *ent) 17251da6df85SFlorian Fainelli { 17261da6df85SFlorian Fainelli u64 mac_vid; 17271da6df85SFlorian Fainelli u32 fwd_entry; 17281da6df85SFlorian Fainelli 17291da6df85SFlorian Fainelli b53_read64(dev, B53_ARLIO_PAGE, 17301da6df85SFlorian Fainelli B53_ARL_SRCH_RSTL_MACVID(idx), &mac_vid); 17311da6df85SFlorian Fainelli b53_read32(dev, B53_ARLIO_PAGE, 17321da6df85SFlorian Fainelli B53_ARL_SRCH_RSTL(idx), &fwd_entry); 17331da6df85SFlorian Fainelli b53_arl_to_entry(ent, mac_vid, fwd_entry); 17341da6df85SFlorian Fainelli } 17351da6df85SFlorian Fainelli 1736e6cbef0cSVivien Didelot static int b53_fdb_copy(int port, const struct b53_arl_entry *ent, 17372bedde1aSArkadi Sharshevsky dsa_fdb_dump_cb_t *cb, void *data) 17381da6df85SFlorian Fainelli { 17391da6df85SFlorian Fainelli if (!ent->is_valid) 17401da6df85SFlorian Fainelli return 0; 17411da6df85SFlorian Fainelli 17421da6df85SFlorian Fainelli if (port != ent->port) 17431da6df85SFlorian Fainelli return 0; 17441da6df85SFlorian Fainelli 17452bedde1aSArkadi Sharshevsky return cb(ent->mac, ent->vid, ent->is_static, data); 17461da6df85SFlorian Fainelli } 17471da6df85SFlorian Fainelli 17483117455dSFlorian Fainelli int b53_fdb_dump(struct dsa_switch *ds, int port, 17492bedde1aSArkadi Sharshevsky dsa_fdb_dump_cb_t *cb, void *data) 17501da6df85SFlorian Fainelli { 175104bed143SVivien Didelot struct b53_device *priv = ds->priv; 17521da6df85SFlorian Fainelli struct b53_arl_entry results[2]; 17531da6df85SFlorian Fainelli unsigned int count = 0; 17541da6df85SFlorian Fainelli int ret; 17551da6df85SFlorian Fainelli u8 reg; 17561da6df85SFlorian Fainelli 17571da6df85SFlorian Fainelli /* Start search operation */ 17581da6df85SFlorian Fainelli reg = ARL_SRCH_STDN; 17591da6df85SFlorian Fainelli b53_write8(priv, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, reg); 17601da6df85SFlorian Fainelli 17611da6df85SFlorian Fainelli do { 17621da6df85SFlorian Fainelli ret = b53_arl_search_wait(priv); 17631da6df85SFlorian Fainelli if (ret) 17641da6df85SFlorian Fainelli return ret; 17651da6df85SFlorian Fainelli 17661da6df85SFlorian Fainelli b53_arl_search_rd(priv, 0, &results[0]); 17672bedde1aSArkadi Sharshevsky ret = b53_fdb_copy(port, &results[0], cb, data); 17681da6df85SFlorian Fainelli if (ret) 17691da6df85SFlorian Fainelli return ret; 17701da6df85SFlorian Fainelli 1771673e69a6SFlorian Fainelli if (priv->num_arl_bins > 2) { 17721da6df85SFlorian Fainelli b53_arl_search_rd(priv, 1, &results[1]); 17732bedde1aSArkadi Sharshevsky ret = b53_fdb_copy(port, &results[1], cb, data); 17741da6df85SFlorian Fainelli if (ret) 17751da6df85SFlorian Fainelli return ret; 17761da6df85SFlorian Fainelli 17771da6df85SFlorian Fainelli if (!results[0].is_valid && !results[1].is_valid) 17781da6df85SFlorian Fainelli break; 17791da6df85SFlorian Fainelli } 17801da6df85SFlorian Fainelli 1781cd169d79SFlorian Fainelli } while (count++ < b53_max_arl_entries(priv) / 2); 17821da6df85SFlorian Fainelli 17831da6df85SFlorian Fainelli return 0; 17841da6df85SFlorian Fainelli } 17853117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_dump); 17861da6df85SFlorian Fainelli 1787a52b2da7SVladimir Oltean int b53_mdb_add(struct dsa_switch *ds, int port, 17885d65b64aSFlorian Fainelli const struct switchdev_obj_port_mdb *mdb) 17895d65b64aSFlorian Fainelli { 17905d65b64aSFlorian Fainelli struct b53_device *priv = ds->priv; 17915d65b64aSFlorian Fainelli 17925d65b64aSFlorian Fainelli /* 5325 and 5365 require some more massaging, but could 17935d65b64aSFlorian Fainelli * be supported eventually 17945d65b64aSFlorian Fainelli */ 17955d65b64aSFlorian Fainelli if (is5325(priv) || is5365(priv)) 17965d65b64aSFlorian Fainelli return -EOPNOTSUPP; 17975d65b64aSFlorian Fainelli 1798a52b2da7SVladimir Oltean return b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, true); 17995d65b64aSFlorian Fainelli } 18005d65b64aSFlorian Fainelli EXPORT_SYMBOL(b53_mdb_add); 18015d65b64aSFlorian Fainelli 18025d65b64aSFlorian Fainelli int b53_mdb_del(struct dsa_switch *ds, int port, 18035d65b64aSFlorian Fainelli const struct switchdev_obj_port_mdb *mdb) 18045d65b64aSFlorian Fainelli { 18055d65b64aSFlorian Fainelli struct b53_device *priv = ds->priv; 18065d65b64aSFlorian Fainelli int ret; 18075d65b64aSFlorian Fainelli 18085d65b64aSFlorian Fainelli ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, false); 18095d65b64aSFlorian Fainelli if (ret) 18105d65b64aSFlorian Fainelli dev_err(ds->dev, "failed to delete MDB entry\n"); 18115d65b64aSFlorian Fainelli 18125d65b64aSFlorian Fainelli return ret; 18135d65b64aSFlorian Fainelli } 18145d65b64aSFlorian Fainelli EXPORT_SYMBOL(b53_mdb_del); 18155d65b64aSFlorian Fainelli 1816ddd3a0c8SVivien Didelot int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br) 1817ff39c2d6SFlorian Fainelli { 181804bed143SVivien Didelot struct b53_device *dev = ds->priv; 181968bb8ea8SVivien Didelot s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index; 1820ff39c2d6SFlorian Fainelli u16 pvlan, reg; 1821ff39c2d6SFlorian Fainelli unsigned int i; 1822ff39c2d6SFlorian Fainelli 182331bfc2d4SFlorian Fainelli /* On 7278, port 7 which connects to the ASP should only receive 182431bfc2d4SFlorian Fainelli * traffic from matching CFP rules. 182531bfc2d4SFlorian Fainelli */ 182631bfc2d4SFlorian Fainelli if (dev->chip_id == BCM7278_DEVICE_ID && port == 7) 182731bfc2d4SFlorian Fainelli return -EINVAL; 182831bfc2d4SFlorian Fainelli 182948aea33aSFlorian Fainelli /* Make this port leave the all VLANs join since we will have proper 183048aea33aSFlorian Fainelli * VLAN entries from now on 183148aea33aSFlorian Fainelli */ 183248aea33aSFlorian Fainelli if (is58xx(dev)) { 183348aea33aSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, ®); 183448aea33aSFlorian Fainelli reg &= ~BIT(port); 183548aea33aSFlorian Fainelli if ((reg & BIT(cpu_port)) == BIT(cpu_port)) 183648aea33aSFlorian Fainelli reg &= ~BIT(cpu_port); 183748aea33aSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg); 183848aea33aSFlorian Fainelli } 183948aea33aSFlorian Fainelli 1840ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); 1841ff39c2d6SFlorian Fainelli 1842ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) { 1843c8652c83SVivien Didelot if (dsa_to_port(ds, i)->bridge_dev != br) 1844ff39c2d6SFlorian Fainelli continue; 1845ff39c2d6SFlorian Fainelli 1846ff39c2d6SFlorian Fainelli /* Add this local port to the remote port VLAN control 1847ff39c2d6SFlorian Fainelli * membership and update the remote port bitmask 1848ff39c2d6SFlorian Fainelli */ 1849ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), ®); 1850ff39c2d6SFlorian Fainelli reg |= BIT(port); 1851ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg); 1852ff39c2d6SFlorian Fainelli dev->ports[i].vlan_ctl_mask = reg; 1853ff39c2d6SFlorian Fainelli 1854ff39c2d6SFlorian Fainelli pvlan |= BIT(i); 1855ff39c2d6SFlorian Fainelli } 1856ff39c2d6SFlorian Fainelli 1857ff39c2d6SFlorian Fainelli /* Configure the local port VLAN control membership to include 1858ff39c2d6SFlorian Fainelli * remote ports and update the local port bitmask 1859ff39c2d6SFlorian Fainelli */ 1860ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); 1861ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = pvlan; 1862ff39c2d6SFlorian Fainelli 1863ff39c2d6SFlorian Fainelli return 0; 1864ff39c2d6SFlorian Fainelli } 18653117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_join); 1866ff39c2d6SFlorian Fainelli 1867f123f2fbSVivien Didelot void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *br) 1868ff39c2d6SFlorian Fainelli { 186904bed143SVivien Didelot struct b53_device *dev = ds->priv; 1870a2482d2cSFlorian Fainelli struct b53_vlan *vl = &dev->vlans[0]; 187168bb8ea8SVivien Didelot s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index; 1872ff39c2d6SFlorian Fainelli unsigned int i; 1873a2482d2cSFlorian Fainelli u16 pvlan, reg, pvid; 1874ff39c2d6SFlorian Fainelli 1875ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); 1876ff39c2d6SFlorian Fainelli 1877ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) { 1878ff39c2d6SFlorian Fainelli /* Don't touch the remaining ports */ 1879c8652c83SVivien Didelot if (dsa_to_port(ds, i)->bridge_dev != br) 1880ff39c2d6SFlorian Fainelli continue; 1881ff39c2d6SFlorian Fainelli 1882ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), ®); 1883ff39c2d6SFlorian Fainelli reg &= ~BIT(port); 1884ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg); 1885ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = reg; 1886ff39c2d6SFlorian Fainelli 1887ff39c2d6SFlorian Fainelli /* Prevent self removal to preserve isolation */ 1888ff39c2d6SFlorian Fainelli if (port != i) 1889ff39c2d6SFlorian Fainelli pvlan &= ~BIT(i); 1890ff39c2d6SFlorian Fainelli } 1891ff39c2d6SFlorian Fainelli 1892ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); 1893ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = pvlan; 1894a2482d2cSFlorian Fainelli 1895fea83353SFlorian Fainelli pvid = b53_default_pvid(dev); 1896a2482d2cSFlorian Fainelli 189748aea33aSFlorian Fainelli /* Make this port join all VLANs without VLAN entries */ 189848aea33aSFlorian Fainelli if (is58xx(dev)) { 189948aea33aSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, ®); 190048aea33aSFlorian Fainelli reg |= BIT(port); 190148aea33aSFlorian Fainelli if (!(reg & BIT(cpu_port))) 190248aea33aSFlorian Fainelli reg |= BIT(cpu_port); 190348aea33aSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg); 190448aea33aSFlorian Fainelli } else { 1905a2482d2cSFlorian Fainelli b53_get_vlan_entry(dev, pvid, vl); 1906c499696eSFlorian Fainelli vl->members |= BIT(port) | BIT(cpu_port); 1907c499696eSFlorian Fainelli vl->untag |= BIT(port) | BIT(cpu_port); 1908a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, pvid, vl); 1909ff39c2d6SFlorian Fainelli } 191048aea33aSFlorian Fainelli } 19113117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_leave); 1912ff39c2d6SFlorian Fainelli 19133117455dSFlorian Fainelli void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state) 1914ff39c2d6SFlorian Fainelli { 191504bed143SVivien Didelot struct b53_device *dev = ds->priv; 1916597698f1SVivien Didelot u8 hw_state; 1917ff39c2d6SFlorian Fainelli u8 reg; 1918ff39c2d6SFlorian Fainelli 1919ff39c2d6SFlorian Fainelli switch (state) { 1920ff39c2d6SFlorian Fainelli case BR_STATE_DISABLED: 1921ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_DIS_STATE; 1922ff39c2d6SFlorian Fainelli break; 1923ff39c2d6SFlorian Fainelli case BR_STATE_LISTENING: 1924ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_LISTEN_STATE; 1925ff39c2d6SFlorian Fainelli break; 1926ff39c2d6SFlorian Fainelli case BR_STATE_LEARNING: 1927ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_LEARN_STATE; 1928ff39c2d6SFlorian Fainelli break; 1929ff39c2d6SFlorian Fainelli case BR_STATE_FORWARDING: 1930ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_FWD_STATE; 1931ff39c2d6SFlorian Fainelli break; 1932ff39c2d6SFlorian Fainelli case BR_STATE_BLOCKING: 1933ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_BLOCK_STATE; 1934ff39c2d6SFlorian Fainelli break; 1935ff39c2d6SFlorian Fainelli default: 1936ff39c2d6SFlorian Fainelli dev_err(ds->dev, "invalid STP state: %d\n", state); 1937ff39c2d6SFlorian Fainelli return; 1938ff39c2d6SFlorian Fainelli } 1939ff39c2d6SFlorian Fainelli 1940ff39c2d6SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), ®); 1941ff39c2d6SFlorian Fainelli reg &= ~PORT_CTRL_STP_STATE_MASK; 1942ff39c2d6SFlorian Fainelli reg |= hw_state; 1943ff39c2d6SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg); 1944ff39c2d6SFlorian Fainelli } 19453117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_set_stp_state); 1946ff39c2d6SFlorian Fainelli 19473117455dSFlorian Fainelli void b53_br_fast_age(struct dsa_switch *ds, int port) 1948597698f1SVivien Didelot { 1949597698f1SVivien Didelot struct b53_device *dev = ds->priv; 1950597698f1SVivien Didelot 1951597698f1SVivien Didelot if (b53_fast_age_port(dev, port)) 1952597698f1SVivien Didelot dev_err(ds->dev, "fast ageing failed\n"); 1953597698f1SVivien Didelot } 19543117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_fast_age); 1955597698f1SVivien Didelot 1956a8b659e7SVladimir Oltean static int b53_br_flags_pre(struct dsa_switch *ds, int port, 1957a8b659e7SVladimir Oltean struct switchdev_brport_flags flags, 1958a8b659e7SVladimir Oltean struct netlink_ext_ack *extack) 195953568438SFlorian Fainelli { 1960a8b659e7SVladimir Oltean if (flags.mask & ~(BR_FLOOD | BR_MCAST_FLOOD)) 1961a8b659e7SVladimir Oltean return -EINVAL; 196253568438SFlorian Fainelli 196353568438SFlorian Fainelli return 0; 196453568438SFlorian Fainelli } 1965a8b659e7SVladimir Oltean 1966a8b659e7SVladimir Oltean static int b53_br_flags(struct dsa_switch *ds, int port, 1967a8b659e7SVladimir Oltean struct switchdev_brport_flags flags, 1968a8b659e7SVladimir Oltean struct netlink_ext_ack *extack) 1969a8b659e7SVladimir Oltean { 1970a8b659e7SVladimir Oltean if (flags.mask & BR_FLOOD) 1971a8b659e7SVladimir Oltean b53_port_set_ucast_flood(ds->priv, port, 1972a8b659e7SVladimir Oltean !!(flags.val & BR_FLOOD)); 1973a8b659e7SVladimir Oltean if (flags.mask & BR_MCAST_FLOOD) 1974a8b659e7SVladimir Oltean b53_port_set_mcast_flood(ds->priv, port, 1975a8b659e7SVladimir Oltean !!(flags.val & BR_MCAST_FLOOD)); 1976a8b659e7SVladimir Oltean 1977a8b659e7SVladimir Oltean return 0; 1978a8b659e7SVladimir Oltean } 1979a8b659e7SVladimir Oltean 1980a8b659e7SVladimir Oltean static int b53_set_mrouter(struct dsa_switch *ds, int port, bool mrouter, 1981a8b659e7SVladimir Oltean struct netlink_ext_ack *extack) 1982a8b659e7SVladimir Oltean { 1983a8b659e7SVladimir Oltean b53_port_set_mcast_flood(ds->priv, port, mrouter); 1984a8b659e7SVladimir Oltean 1985a8b659e7SVladimir Oltean return 0; 1986a8b659e7SVladimir Oltean } 198753568438SFlorian Fainelli 1988c7d28c9dSFlorian Fainelli static bool b53_possible_cpu_port(struct dsa_switch *ds, int port) 19897edc58d6SFlorian Fainelli { 19907edc58d6SFlorian Fainelli /* Broadcom switches will accept enabling Broadcom tags on the 19917edc58d6SFlorian Fainelli * following ports: 5, 7 and 8, any other port is not supported 19927edc58d6SFlorian Fainelli */ 19935ed4e3ebSFlorian Fainelli switch (port) { 19945ed4e3ebSFlorian Fainelli case B53_CPU_PORT_25: 19955ed4e3ebSFlorian Fainelli case 7: 19965ed4e3ebSFlorian Fainelli case B53_CPU_PORT: 19977edc58d6SFlorian Fainelli return true; 19987edc58d6SFlorian Fainelli } 19997edc58d6SFlorian Fainelli 20005ed4e3ebSFlorian Fainelli return false; 20015ed4e3ebSFlorian Fainelli } 20025ed4e3ebSFlorian Fainelli 20038fab459eSFlorian Fainelli static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port, 20048fab459eSFlorian Fainelli enum dsa_tag_protocol tag_protocol) 2005c7d28c9dSFlorian Fainelli { 2006c7d28c9dSFlorian Fainelli bool ret = b53_possible_cpu_port(ds, port); 2007c7d28c9dSFlorian Fainelli 20088fab459eSFlorian Fainelli if (!ret) { 2009c7d28c9dSFlorian Fainelli dev_warn(ds->dev, "Port %d is not Broadcom tag capable\n", 2010c7d28c9dSFlorian Fainelli port); 2011c7d28c9dSFlorian Fainelli return ret; 2012c7d28c9dSFlorian Fainelli } 2013c7d28c9dSFlorian Fainelli 20148fab459eSFlorian Fainelli switch (tag_protocol) { 20158fab459eSFlorian Fainelli case DSA_TAG_PROTO_BRCM: 20168fab459eSFlorian Fainelli case DSA_TAG_PROTO_BRCM_PREPEND: 20178fab459eSFlorian Fainelli dev_warn(ds->dev, 20188fab459eSFlorian Fainelli "Port %d is stacked to Broadcom tag switch\n", port); 20198fab459eSFlorian Fainelli ret = false; 20208fab459eSFlorian Fainelli break; 20218fab459eSFlorian Fainelli default: 20228fab459eSFlorian Fainelli ret = true; 20238fab459eSFlorian Fainelli break; 20248fab459eSFlorian Fainelli } 20258fab459eSFlorian Fainelli 20268fab459eSFlorian Fainelli return ret; 20278fab459eSFlorian Fainelli } 20288fab459eSFlorian Fainelli 20294d776482SFlorian Fainelli enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port, 20304d776482SFlorian Fainelli enum dsa_tag_protocol mprot) 20317b314362SAndrew Lunn { 20327edc58d6SFlorian Fainelli struct b53_device *dev = ds->priv; 20337edc58d6SFlorian Fainelli 203454e98b5dSFlorian Fainelli /* Older models (5325, 5365) support a different tag format that we do 20358fab459eSFlorian Fainelli * not support in net/dsa/tag_brcm.c yet. 20367edc58d6SFlorian Fainelli */ 20378fab459eSFlorian Fainelli if (is5325(dev) || is5365(dev) || 20388fab459eSFlorian Fainelli !b53_can_enable_brcm_tags(ds, port, mprot)) { 20394d776482SFlorian Fainelli dev->tag_protocol = DSA_TAG_PROTO_NONE; 20404d776482SFlorian Fainelli goto out; 20414d776482SFlorian Fainelli } 204211606039SFlorian Fainelli 204311606039SFlorian Fainelli /* Broadcom BCM58xx chips have a flow accelerator on Port 8 204411606039SFlorian Fainelli * which requires us to use the prepended Broadcom tag type 204511606039SFlorian Fainelli */ 20464d776482SFlorian Fainelli if (dev->chip_id == BCM58XX_DEVICE_ID && port == B53_CPU_PORT) { 20474d776482SFlorian Fainelli dev->tag_protocol = DSA_TAG_PROTO_BRCM_PREPEND; 20484d776482SFlorian Fainelli goto out; 20494d776482SFlorian Fainelli } 205011606039SFlorian Fainelli 20514d776482SFlorian Fainelli dev->tag_protocol = DSA_TAG_PROTO_BRCM; 20524d776482SFlorian Fainelli out: 20534d776482SFlorian Fainelli return dev->tag_protocol; 20547b314362SAndrew Lunn } 20559f66816aSFlorian Fainelli EXPORT_SYMBOL(b53_get_tag_protocol); 20567b314362SAndrew Lunn 2057ed3af5fdSFlorian Fainelli int b53_mirror_add(struct dsa_switch *ds, int port, 2058ed3af5fdSFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror, bool ingress) 2059ed3af5fdSFlorian Fainelli { 2060ed3af5fdSFlorian Fainelli struct b53_device *dev = ds->priv; 2061ed3af5fdSFlorian Fainelli u16 reg, loc; 2062ed3af5fdSFlorian Fainelli 2063ed3af5fdSFlorian Fainelli if (ingress) 2064ed3af5fdSFlorian Fainelli loc = B53_IG_MIR_CTL; 2065ed3af5fdSFlorian Fainelli else 2066ed3af5fdSFlorian Fainelli loc = B53_EG_MIR_CTL; 2067ed3af5fdSFlorian Fainelli 2068ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, loc, ®); 2069ed3af5fdSFlorian Fainelli reg |= BIT(port); 2070ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, loc, reg); 2071ed3af5fdSFlorian Fainelli 2072ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®); 2073ed3af5fdSFlorian Fainelli reg &= ~CAP_PORT_MASK; 2074ed3af5fdSFlorian Fainelli reg |= mirror->to_local_port; 2075ed3af5fdSFlorian Fainelli reg |= MIRROR_EN; 2076ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg); 2077ed3af5fdSFlorian Fainelli 2078ed3af5fdSFlorian Fainelli return 0; 2079ed3af5fdSFlorian Fainelli } 2080ed3af5fdSFlorian Fainelli EXPORT_SYMBOL(b53_mirror_add); 2081ed3af5fdSFlorian Fainelli 2082ed3af5fdSFlorian Fainelli void b53_mirror_del(struct dsa_switch *ds, int port, 2083ed3af5fdSFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror) 2084ed3af5fdSFlorian Fainelli { 2085ed3af5fdSFlorian Fainelli struct b53_device *dev = ds->priv; 2086ed3af5fdSFlorian Fainelli bool loc_disable = false, other_loc_disable = false; 2087ed3af5fdSFlorian Fainelli u16 reg, loc; 2088ed3af5fdSFlorian Fainelli 2089ed3af5fdSFlorian Fainelli if (mirror->ingress) 2090ed3af5fdSFlorian Fainelli loc = B53_IG_MIR_CTL; 2091ed3af5fdSFlorian Fainelli else 2092ed3af5fdSFlorian Fainelli loc = B53_EG_MIR_CTL; 2093ed3af5fdSFlorian Fainelli 2094ed3af5fdSFlorian Fainelli /* Update the desired ingress/egress register */ 2095ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, loc, ®); 2096ed3af5fdSFlorian Fainelli reg &= ~BIT(port); 2097ed3af5fdSFlorian Fainelli if (!(reg & MIRROR_MASK)) 2098ed3af5fdSFlorian Fainelli loc_disable = true; 2099ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, loc, reg); 2100ed3af5fdSFlorian Fainelli 2101ed3af5fdSFlorian Fainelli /* Now look at the other one to know if we can disable mirroring 2102ed3af5fdSFlorian Fainelli * entirely 2103ed3af5fdSFlorian Fainelli */ 2104ed3af5fdSFlorian Fainelli if (mirror->ingress) 2105ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_EG_MIR_CTL, ®); 2106ed3af5fdSFlorian Fainelli else 2107ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_IG_MIR_CTL, ®); 2108ed3af5fdSFlorian Fainelli if (!(reg & MIRROR_MASK)) 2109ed3af5fdSFlorian Fainelli other_loc_disable = true; 2110ed3af5fdSFlorian Fainelli 2111ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®); 2112ed3af5fdSFlorian Fainelli /* Both no longer have ports, let's disable mirroring */ 2113ed3af5fdSFlorian Fainelli if (loc_disable && other_loc_disable) { 2114ed3af5fdSFlorian Fainelli reg &= ~MIRROR_EN; 2115ed3af5fdSFlorian Fainelli reg &= ~mirror->to_local_port; 2116ed3af5fdSFlorian Fainelli } 2117ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg); 2118ed3af5fdSFlorian Fainelli } 2119ed3af5fdSFlorian Fainelli EXPORT_SYMBOL(b53_mirror_del); 2120ed3af5fdSFlorian Fainelli 212122256b0aSFlorian Fainelli void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable) 212222256b0aSFlorian Fainelli { 212322256b0aSFlorian Fainelli struct b53_device *dev = ds->priv; 212422256b0aSFlorian Fainelli u16 reg; 212522256b0aSFlorian Fainelli 212622256b0aSFlorian Fainelli b53_read16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, ®); 212722256b0aSFlorian Fainelli if (enable) 212822256b0aSFlorian Fainelli reg |= BIT(port); 212922256b0aSFlorian Fainelli else 213022256b0aSFlorian Fainelli reg &= ~BIT(port); 213122256b0aSFlorian Fainelli b53_write16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, reg); 213222256b0aSFlorian Fainelli } 213322256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_eee_enable_set); 213422256b0aSFlorian Fainelli 213522256b0aSFlorian Fainelli 213622256b0aSFlorian Fainelli /* Returns 0 if EEE was not enabled, or 1 otherwise 213722256b0aSFlorian Fainelli */ 213822256b0aSFlorian Fainelli int b53_eee_init(struct dsa_switch *ds, int port, struct phy_device *phy) 213922256b0aSFlorian Fainelli { 214022256b0aSFlorian Fainelli int ret; 214122256b0aSFlorian Fainelli 214222256b0aSFlorian Fainelli ret = phy_init_eee(phy, 0); 214322256b0aSFlorian Fainelli if (ret) 214422256b0aSFlorian Fainelli return 0; 214522256b0aSFlorian Fainelli 214622256b0aSFlorian Fainelli b53_eee_enable_set(ds, port, true); 214722256b0aSFlorian Fainelli 214822256b0aSFlorian Fainelli return 1; 214922256b0aSFlorian Fainelli } 215022256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_eee_init); 215122256b0aSFlorian Fainelli 215222256b0aSFlorian Fainelli int b53_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e) 215322256b0aSFlorian Fainelli { 215422256b0aSFlorian Fainelli struct b53_device *dev = ds->priv; 215522256b0aSFlorian Fainelli struct ethtool_eee *p = &dev->ports[port].eee; 215622256b0aSFlorian Fainelli u16 reg; 215722256b0aSFlorian Fainelli 215822256b0aSFlorian Fainelli if (is5325(dev) || is5365(dev)) 215922256b0aSFlorian Fainelli return -EOPNOTSUPP; 216022256b0aSFlorian Fainelli 216122256b0aSFlorian Fainelli b53_read16(dev, B53_EEE_PAGE, B53_EEE_LPI_INDICATE, ®); 216222256b0aSFlorian Fainelli e->eee_enabled = p->eee_enabled; 216322256b0aSFlorian Fainelli e->eee_active = !!(reg & BIT(port)); 216422256b0aSFlorian Fainelli 216522256b0aSFlorian Fainelli return 0; 216622256b0aSFlorian Fainelli } 216722256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_get_mac_eee); 216822256b0aSFlorian Fainelli 216922256b0aSFlorian Fainelli int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e) 217022256b0aSFlorian Fainelli { 217122256b0aSFlorian Fainelli struct b53_device *dev = ds->priv; 217222256b0aSFlorian Fainelli struct ethtool_eee *p = &dev->ports[port].eee; 217322256b0aSFlorian Fainelli 217422256b0aSFlorian Fainelli if (is5325(dev) || is5365(dev)) 217522256b0aSFlorian Fainelli return -EOPNOTSUPP; 217622256b0aSFlorian Fainelli 217722256b0aSFlorian Fainelli p->eee_enabled = e->eee_enabled; 217822256b0aSFlorian Fainelli b53_eee_enable_set(ds, port, e->eee_enabled); 217922256b0aSFlorian Fainelli 218022256b0aSFlorian Fainelli return 0; 218122256b0aSFlorian Fainelli } 218222256b0aSFlorian Fainelli EXPORT_SYMBOL(b53_set_mac_eee); 218322256b0aSFlorian Fainelli 21846ae5834bSMurali Krishna Policharla static int b53_change_mtu(struct dsa_switch *ds, int port, int mtu) 21856ae5834bSMurali Krishna Policharla { 21866ae5834bSMurali Krishna Policharla struct b53_device *dev = ds->priv; 21876ae5834bSMurali Krishna Policharla bool enable_jumbo; 21886ae5834bSMurali Krishna Policharla bool allow_10_100; 21896ae5834bSMurali Krishna Policharla 21906ae5834bSMurali Krishna Policharla if (is5325(dev) || is5365(dev)) 21916ae5834bSMurali Krishna Policharla return -EOPNOTSUPP; 21926ae5834bSMurali Krishna Policharla 21936ae5834bSMurali Krishna Policharla enable_jumbo = (mtu >= JMS_MIN_SIZE); 21946ae5834bSMurali Krishna Policharla allow_10_100 = (dev->chip_id == BCM583XX_DEVICE_ID); 21956ae5834bSMurali Krishna Policharla 21966ae5834bSMurali Krishna Policharla return b53_set_jumbo(dev, enable_jumbo, allow_10_100); 21976ae5834bSMurali Krishna Policharla } 21986ae5834bSMurali Krishna Policharla 21996ae5834bSMurali Krishna Policharla static int b53_get_max_mtu(struct dsa_switch *ds, int port) 22006ae5834bSMurali Krishna Policharla { 22016ae5834bSMurali Krishna Policharla return JMS_MAX_SIZE; 22026ae5834bSMurali Krishna Policharla } 22036ae5834bSMurali Krishna Policharla 2204a82f67afSFlorian Fainelli static const struct dsa_switch_ops b53_switch_ops = { 22057b314362SAndrew Lunn .get_tag_protocol = b53_get_tag_protocol, 2206967dd82fSFlorian Fainelli .setup = b53_setup, 22074f6a5cafSFlorian Fainelli .teardown = b53_teardown, 2208967dd82fSFlorian Fainelli .get_strings = b53_get_strings, 2209967dd82fSFlorian Fainelli .get_ethtool_stats = b53_get_ethtool_stats, 2210967dd82fSFlorian Fainelli .get_sset_count = b53_get_sset_count, 2211c7d28c9dSFlorian Fainelli .get_ethtool_phy_stats = b53_get_ethtool_phy_stats, 2212967dd82fSFlorian Fainelli .phy_read = b53_phy_read16, 2213967dd82fSFlorian Fainelli .phy_write = b53_phy_write16, 2214967dd82fSFlorian Fainelli .adjust_link = b53_adjust_link, 2215a8e8b985SFlorian Fainelli .phylink_validate = b53_phylink_validate, 2216a8e8b985SFlorian Fainelli .phylink_mac_link_state = b53_phylink_mac_link_state, 2217a8e8b985SFlorian Fainelli .phylink_mac_config = b53_phylink_mac_config, 2218a8e8b985SFlorian Fainelli .phylink_mac_an_restart = b53_phylink_mac_an_restart, 2219a8e8b985SFlorian Fainelli .phylink_mac_link_down = b53_phylink_mac_link_down, 2220a8e8b985SFlorian Fainelli .phylink_mac_link_up = b53_phylink_mac_link_up, 2221967dd82fSFlorian Fainelli .port_enable = b53_enable_port, 2222967dd82fSFlorian Fainelli .port_disable = b53_disable_port, 2223f43a2dbeSFlorian Fainelli .get_mac_eee = b53_get_mac_eee, 2224f43a2dbeSFlorian Fainelli .set_mac_eee = b53_set_mac_eee, 2225ff39c2d6SFlorian Fainelli .port_bridge_join = b53_br_join, 2226ff39c2d6SFlorian Fainelli .port_bridge_leave = b53_br_leave, 2227a8b659e7SVladimir Oltean .port_pre_bridge_flags = b53_br_flags_pre, 2228a8b659e7SVladimir Oltean .port_bridge_flags = b53_br_flags, 2229a8b659e7SVladimir Oltean .port_set_mrouter = b53_set_mrouter, 2230ff39c2d6SFlorian Fainelli .port_stp_state_set = b53_br_set_stp_state, 2231597698f1SVivien Didelot .port_fast_age = b53_br_fast_age, 2232a2482d2cSFlorian Fainelli .port_vlan_filtering = b53_vlan_filtering, 2233a2482d2cSFlorian Fainelli .port_vlan_add = b53_vlan_add, 2234a2482d2cSFlorian Fainelli .port_vlan_del = b53_vlan_del, 22351da6df85SFlorian Fainelli .port_fdb_dump = b53_fdb_dump, 22361da6df85SFlorian Fainelli .port_fdb_add = b53_fdb_add, 22371da6df85SFlorian Fainelli .port_fdb_del = b53_fdb_del, 2238ed3af5fdSFlorian Fainelli .port_mirror_add = b53_mirror_add, 2239ed3af5fdSFlorian Fainelli .port_mirror_del = b53_mirror_del, 22405d65b64aSFlorian Fainelli .port_mdb_add = b53_mdb_add, 22415d65b64aSFlorian Fainelli .port_mdb_del = b53_mdb_del, 22426ae5834bSMurali Krishna Policharla .port_max_mtu = b53_get_max_mtu, 22436ae5834bSMurali Krishna Policharla .port_change_mtu = b53_change_mtu, 2244967dd82fSFlorian Fainelli }; 2245967dd82fSFlorian Fainelli 2246967dd82fSFlorian Fainelli struct b53_chip_data { 2247967dd82fSFlorian Fainelli u32 chip_id; 2248967dd82fSFlorian Fainelli const char *dev_name; 2249967dd82fSFlorian Fainelli u16 vlans; 2250967dd82fSFlorian Fainelli u16 enabled_ports; 2251967dd82fSFlorian Fainelli u8 cpu_port; 2252967dd82fSFlorian Fainelli u8 vta_regs[3]; 2253673e69a6SFlorian Fainelli u8 arl_bins; 2254e3da4038SFlorian Fainelli u16 arl_buckets; 2255967dd82fSFlorian Fainelli u8 duplex_reg; 2256967dd82fSFlorian Fainelli u8 jumbo_pm_reg; 2257967dd82fSFlorian Fainelli u8 jumbo_size_reg; 2258967dd82fSFlorian Fainelli }; 2259967dd82fSFlorian Fainelli 2260967dd82fSFlorian Fainelli #define B53_VTA_REGS \ 2261967dd82fSFlorian Fainelli { B53_VT_ACCESS, B53_VT_INDEX, B53_VT_ENTRY } 2262967dd82fSFlorian Fainelli #define B53_VTA_REGS_9798 \ 2263967dd82fSFlorian Fainelli { B53_VT_ACCESS_9798, B53_VT_INDEX_9798, B53_VT_ENTRY_9798 } 2264967dd82fSFlorian Fainelli #define B53_VTA_REGS_63XX \ 2265967dd82fSFlorian Fainelli { B53_VT_ACCESS_63XX, B53_VT_INDEX_63XX, B53_VT_ENTRY_63XX } 2266967dd82fSFlorian Fainelli 2267967dd82fSFlorian Fainelli static const struct b53_chip_data b53_switch_chips[] = { 2268967dd82fSFlorian Fainelli { 2269967dd82fSFlorian Fainelli .chip_id = BCM5325_DEVICE_ID, 2270967dd82fSFlorian Fainelli .dev_name = "BCM5325", 2271967dd82fSFlorian Fainelli .vlans = 16, 2272967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 2273673e69a6SFlorian Fainelli .arl_bins = 2, 2274e3da4038SFlorian Fainelli .arl_buckets = 1024, 2275967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, 2276967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_FE, 2277967dd82fSFlorian Fainelli }, 2278967dd82fSFlorian Fainelli { 2279967dd82fSFlorian Fainelli .chip_id = BCM5365_DEVICE_ID, 2280967dd82fSFlorian Fainelli .dev_name = "BCM5365", 2281967dd82fSFlorian Fainelli .vlans = 256, 2282967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 2283673e69a6SFlorian Fainelli .arl_bins = 2, 2284e3da4038SFlorian Fainelli .arl_buckets = 1024, 2285967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, 2286967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_FE, 2287967dd82fSFlorian Fainelli }, 2288967dd82fSFlorian Fainelli { 2289a95691bcSDamien Thébault .chip_id = BCM5389_DEVICE_ID, 2290a95691bcSDamien Thébault .dev_name = "BCM5389", 2291a95691bcSDamien Thébault .vlans = 4096, 2292a95691bcSDamien Thébault .enabled_ports = 0x1f, 2293673e69a6SFlorian Fainelli .arl_bins = 4, 2294e3da4038SFlorian Fainelli .arl_buckets = 1024, 2295a95691bcSDamien Thébault .cpu_port = B53_CPU_PORT, 2296a95691bcSDamien Thébault .vta_regs = B53_VTA_REGS, 2297a95691bcSDamien Thébault .duplex_reg = B53_DUPLEX_STAT_GE, 2298a95691bcSDamien Thébault .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2299a95691bcSDamien Thébault .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2300a95691bcSDamien Thébault }, 2301a95691bcSDamien Thébault { 2302967dd82fSFlorian Fainelli .chip_id = BCM5395_DEVICE_ID, 2303967dd82fSFlorian Fainelli .dev_name = "BCM5395", 2304967dd82fSFlorian Fainelli .vlans = 4096, 2305967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 2306673e69a6SFlorian Fainelli .arl_bins = 4, 2307e3da4038SFlorian Fainelli .arl_buckets = 1024, 2308967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2309967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2310967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2311967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2312967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2313967dd82fSFlorian Fainelli }, 2314967dd82fSFlorian Fainelli { 2315967dd82fSFlorian Fainelli .chip_id = BCM5397_DEVICE_ID, 2316967dd82fSFlorian Fainelli .dev_name = "BCM5397", 2317967dd82fSFlorian Fainelli .vlans = 4096, 2318967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 2319673e69a6SFlorian Fainelli .arl_bins = 4, 2320e3da4038SFlorian Fainelli .arl_buckets = 1024, 2321967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2322967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_9798, 2323967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2324967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2325967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2326967dd82fSFlorian Fainelli }, 2327967dd82fSFlorian Fainelli { 2328967dd82fSFlorian Fainelli .chip_id = BCM5398_DEVICE_ID, 2329967dd82fSFlorian Fainelli .dev_name = "BCM5398", 2330967dd82fSFlorian Fainelli .vlans = 4096, 2331967dd82fSFlorian Fainelli .enabled_ports = 0x7f, 2332673e69a6SFlorian Fainelli .arl_bins = 4, 2333e3da4038SFlorian Fainelli .arl_buckets = 1024, 2334967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2335967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_9798, 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 = BCM53115_DEVICE_ID, 2342967dd82fSFlorian Fainelli .dev_name = "BCM53115", 2343967dd82fSFlorian Fainelli .vlans = 4096, 2344967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 2345673e69a6SFlorian Fainelli .arl_bins = 4, 2346e3da4038SFlorian Fainelli .arl_buckets = 1024, 2347967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2348967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 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 = BCM53125_DEVICE_ID, 2355967dd82fSFlorian Fainelli .dev_name = "BCM53125", 2356967dd82fSFlorian Fainelli .vlans = 4096, 2357967dd82fSFlorian Fainelli .enabled_ports = 0xff, 2358673e69a6SFlorian Fainelli .arl_bins = 4, 2359e3da4038SFlorian Fainelli .arl_buckets = 1024, 2360967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2361967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 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 = BCM53128_DEVICE_ID, 2368967dd82fSFlorian Fainelli .dev_name = "BCM53128", 2369967dd82fSFlorian Fainelli .vlans = 4096, 2370967dd82fSFlorian Fainelli .enabled_ports = 0x1ff, 2371673e69a6SFlorian Fainelli .arl_bins = 4, 2372e3da4038SFlorian Fainelli .arl_buckets = 1024, 2373967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2374967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 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 = BCM63XX_DEVICE_ID, 2381967dd82fSFlorian Fainelli .dev_name = "BCM63xx", 2382967dd82fSFlorian Fainelli .vlans = 4096, 2383967dd82fSFlorian Fainelli .enabled_ports = 0, /* pdata must provide them */ 2384673e69a6SFlorian Fainelli .arl_bins = 4, 2385e3da4038SFlorian Fainelli .arl_buckets = 1024, 2386967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2387967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_63XX, 2388967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_63XX, 2389967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK_63XX, 2390967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE_63XX, 2391967dd82fSFlorian Fainelli }, 2392967dd82fSFlorian Fainelli { 2393967dd82fSFlorian Fainelli .chip_id = BCM53010_DEVICE_ID, 2394967dd82fSFlorian Fainelli .dev_name = "BCM53010", 2395967dd82fSFlorian Fainelli .vlans = 4096, 2396967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 2397673e69a6SFlorian Fainelli .arl_bins = 4, 2398e3da4038SFlorian Fainelli .arl_buckets = 1024, 2399967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 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 = BCM53011_DEVICE_ID, 2407967dd82fSFlorian Fainelli .dev_name = "BCM53011", 2408967dd82fSFlorian Fainelli .vlans = 4096, 2409967dd82fSFlorian Fainelli .enabled_ports = 0x1bf, 2410673e69a6SFlorian Fainelli .arl_bins = 4, 2411e3da4038SFlorian Fainelli .arl_buckets = 1024, 2412967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 2413967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2414967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2415967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2416967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2417967dd82fSFlorian Fainelli }, 2418967dd82fSFlorian Fainelli { 2419967dd82fSFlorian Fainelli .chip_id = BCM53012_DEVICE_ID, 2420967dd82fSFlorian Fainelli .dev_name = "BCM53012", 2421967dd82fSFlorian Fainelli .vlans = 4096, 2422967dd82fSFlorian Fainelli .enabled_ports = 0x1bf, 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 = BCM53018_DEVICE_ID, 2433967dd82fSFlorian Fainelli .dev_name = "BCM53018", 2434967dd82fSFlorian Fainelli .vlans = 4096, 2435967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 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 = BCM53019_DEVICE_ID, 2446967dd82fSFlorian Fainelli .dev_name = "BCM53019", 2447967dd82fSFlorian Fainelli .vlans = 4096, 2448967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 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 }, 2457991a36bbSFlorian Fainelli { 2458991a36bbSFlorian Fainelli .chip_id = BCM58XX_DEVICE_ID, 2459991a36bbSFlorian Fainelli .dev_name = "BCM585xx/586xx/88312", 2460991a36bbSFlorian Fainelli .vlans = 4096, 2461991a36bbSFlorian Fainelli .enabled_ports = 0x1ff, 2462673e69a6SFlorian Fainelli .arl_bins = 4, 2463e3da4038SFlorian Fainelli .arl_buckets = 1024, 2464bfcda65cSFlorian Fainelli .cpu_port = B53_CPU_PORT, 2465991a36bbSFlorian Fainelli .vta_regs = B53_VTA_REGS, 2466991a36bbSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2467991a36bbSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2468991a36bbSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2469991a36bbSFlorian Fainelli }, 2470130401d9SFlorian Fainelli { 24715040cc99SArun Parameswaran .chip_id = BCM583XX_DEVICE_ID, 24725040cc99SArun Parameswaran .dev_name = "BCM583xx/11360", 24735040cc99SArun Parameswaran .vlans = 4096, 24745040cc99SArun Parameswaran .enabled_ports = 0x103, 2475673e69a6SFlorian Fainelli .arl_bins = 4, 2476e3da4038SFlorian Fainelli .arl_buckets = 1024, 24775040cc99SArun Parameswaran .cpu_port = B53_CPU_PORT, 24785040cc99SArun Parameswaran .vta_regs = B53_VTA_REGS, 24795040cc99SArun Parameswaran .duplex_reg = B53_DUPLEX_STAT_GE, 24805040cc99SArun Parameswaran .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 24815040cc99SArun Parameswaran .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 24825040cc99SArun Parameswaran }, 248373b7a604SRafał Miłecki /* Starfighter 2 */ 248473b7a604SRafał Miłecki { 248573b7a604SRafał Miłecki .chip_id = BCM4908_DEVICE_ID, 248673b7a604SRafał Miłecki .dev_name = "BCM4908", 248773b7a604SRafał Miłecki .vlans = 4096, 248873b7a604SRafał Miłecki .enabled_ports = 0x1bf, 248973b7a604SRafał Miłecki .arl_bins = 4, 249073b7a604SRafał Miłecki .arl_buckets = 256, 249173b7a604SRafał Miłecki .cpu_port = 8, /* TODO: ports 4, 5, 8 */ 249273b7a604SRafał Miłecki .vta_regs = B53_VTA_REGS, 249373b7a604SRafał Miłecki .duplex_reg = B53_DUPLEX_STAT_GE, 249473b7a604SRafał Miłecki .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 249573b7a604SRafał Miłecki .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 249673b7a604SRafał Miłecki }, 24975040cc99SArun Parameswaran { 2498130401d9SFlorian Fainelli .chip_id = BCM7445_DEVICE_ID, 2499130401d9SFlorian Fainelli .dev_name = "BCM7445", 2500130401d9SFlorian Fainelli .vlans = 4096, 2501130401d9SFlorian Fainelli .enabled_ports = 0x1ff, 2502673e69a6SFlorian Fainelli .arl_bins = 4, 2503e3da4038SFlorian Fainelli .arl_buckets = 1024, 2504130401d9SFlorian Fainelli .cpu_port = B53_CPU_PORT, 2505130401d9SFlorian Fainelli .vta_regs = B53_VTA_REGS, 2506130401d9SFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 2507130401d9SFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 2508130401d9SFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 2509130401d9SFlorian Fainelli }, 25100fe99338SFlorian Fainelli { 25110fe99338SFlorian Fainelli .chip_id = BCM7278_DEVICE_ID, 25120fe99338SFlorian Fainelli .dev_name = "BCM7278", 25130fe99338SFlorian Fainelli .vlans = 4096, 25140fe99338SFlorian Fainelli .enabled_ports = 0x1ff, 2515673e69a6SFlorian Fainelli .arl_bins = 4, 2516e3da4038SFlorian Fainelli .arl_buckets = 256, 25170fe99338SFlorian Fainelli .cpu_port = B53_CPU_PORT, 25180fe99338SFlorian Fainelli .vta_regs = B53_VTA_REGS, 25190fe99338SFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 25200fe99338SFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 25210fe99338SFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 25220fe99338SFlorian Fainelli }, 2523967dd82fSFlorian Fainelli }; 2524967dd82fSFlorian Fainelli 2525967dd82fSFlorian Fainelli static int b53_switch_init(struct b53_device *dev) 2526967dd82fSFlorian Fainelli { 2527967dd82fSFlorian Fainelli unsigned int i; 2528967dd82fSFlorian Fainelli int ret; 2529967dd82fSFlorian Fainelli 2530967dd82fSFlorian Fainelli for (i = 0; i < ARRAY_SIZE(b53_switch_chips); i++) { 2531967dd82fSFlorian Fainelli const struct b53_chip_data *chip = &b53_switch_chips[i]; 2532967dd82fSFlorian Fainelli 2533967dd82fSFlorian Fainelli if (chip->chip_id == dev->chip_id) { 2534967dd82fSFlorian Fainelli if (!dev->enabled_ports) 2535967dd82fSFlorian Fainelli dev->enabled_ports = chip->enabled_ports; 2536967dd82fSFlorian Fainelli dev->name = chip->dev_name; 2537967dd82fSFlorian Fainelli dev->duplex_reg = chip->duplex_reg; 2538967dd82fSFlorian Fainelli dev->vta_regs[0] = chip->vta_regs[0]; 2539967dd82fSFlorian Fainelli dev->vta_regs[1] = chip->vta_regs[1]; 2540967dd82fSFlorian Fainelli dev->vta_regs[2] = chip->vta_regs[2]; 2541967dd82fSFlorian Fainelli dev->jumbo_pm_reg = chip->jumbo_pm_reg; 2542967dd82fSFlorian Fainelli dev->cpu_port = chip->cpu_port; 2543967dd82fSFlorian Fainelli dev->num_vlans = chip->vlans; 2544673e69a6SFlorian Fainelli dev->num_arl_bins = chip->arl_bins; 2545e3da4038SFlorian Fainelli dev->num_arl_buckets = chip->arl_buckets; 2546967dd82fSFlorian Fainelli break; 2547967dd82fSFlorian Fainelli } 2548967dd82fSFlorian Fainelli } 2549967dd82fSFlorian Fainelli 2550967dd82fSFlorian Fainelli /* check which BCM5325x version we have */ 2551967dd82fSFlorian Fainelli if (is5325(dev)) { 2552967dd82fSFlorian Fainelli u8 vc4; 2553967dd82fSFlorian Fainelli 2554967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4); 2555967dd82fSFlorian Fainelli 2556967dd82fSFlorian Fainelli /* check reserved bits */ 2557967dd82fSFlorian Fainelli switch (vc4 & 3) { 2558967dd82fSFlorian Fainelli case 1: 2559967dd82fSFlorian Fainelli /* BCM5325E */ 2560967dd82fSFlorian Fainelli break; 2561967dd82fSFlorian Fainelli case 3: 2562967dd82fSFlorian Fainelli /* BCM5325F - do not use port 4 */ 2563967dd82fSFlorian Fainelli dev->enabled_ports &= ~BIT(4); 2564967dd82fSFlorian Fainelli break; 2565967dd82fSFlorian Fainelli default: 2566967dd82fSFlorian Fainelli /* On the BCM47XX SoCs this is the supported internal switch.*/ 2567967dd82fSFlorian Fainelli #ifndef CONFIG_BCM47XX 2568967dd82fSFlorian Fainelli /* BCM5325M */ 2569967dd82fSFlorian Fainelli return -EINVAL; 2570967dd82fSFlorian Fainelli #else 2571967dd82fSFlorian Fainelli break; 2572967dd82fSFlorian Fainelli #endif 2573967dd82fSFlorian Fainelli } 2574967dd82fSFlorian Fainelli } else if (dev->chip_id == BCM53115_DEVICE_ID) { 2575967dd82fSFlorian Fainelli u64 strap_value; 2576967dd82fSFlorian Fainelli 2577967dd82fSFlorian Fainelli b53_read48(dev, B53_STAT_PAGE, B53_STRAP_VALUE, &strap_value); 2578967dd82fSFlorian Fainelli /* use second IMP port if GMII is enabled */ 2579967dd82fSFlorian Fainelli if (strap_value & SV_GMII_CTRL_115) 2580967dd82fSFlorian Fainelli dev->cpu_port = 5; 2581967dd82fSFlorian Fainelli } 2582967dd82fSFlorian Fainelli 2583967dd82fSFlorian Fainelli /* cpu port is always last */ 2584967dd82fSFlorian Fainelli dev->num_ports = dev->cpu_port + 1; 2585967dd82fSFlorian Fainelli dev->enabled_ports |= BIT(dev->cpu_port); 2586967dd82fSFlorian Fainelli 2587c7d28c9dSFlorian Fainelli /* Include non standard CPU port built-in PHYs to be probed */ 2588c7d28c9dSFlorian Fainelli if (is539x(dev) || is531x5(dev)) { 2589c7d28c9dSFlorian Fainelli for (i = 0; i < dev->num_ports; i++) { 2590c7d28c9dSFlorian Fainelli if (!(dev->ds->phys_mii_mask & BIT(i)) && 2591c7d28c9dSFlorian Fainelli !b53_possible_cpu_port(dev->ds, i)) 2592c7d28c9dSFlorian Fainelli dev->ds->phys_mii_mask |= BIT(i); 2593c7d28c9dSFlorian Fainelli } 2594c7d28c9dSFlorian Fainelli } 2595c7d28c9dSFlorian Fainelli 2596a86854d0SKees Cook dev->ports = devm_kcalloc(dev->dev, 2597a86854d0SKees Cook dev->num_ports, sizeof(struct b53_port), 2598967dd82fSFlorian Fainelli GFP_KERNEL); 2599967dd82fSFlorian Fainelli if (!dev->ports) 2600967dd82fSFlorian Fainelli return -ENOMEM; 2601967dd82fSFlorian Fainelli 2602a86854d0SKees Cook dev->vlans = devm_kcalloc(dev->dev, 2603a86854d0SKees Cook dev->num_vlans, sizeof(struct b53_vlan), 2604a2482d2cSFlorian Fainelli GFP_KERNEL); 2605a2482d2cSFlorian Fainelli if (!dev->vlans) 2606a2482d2cSFlorian Fainelli return -ENOMEM; 2607a2482d2cSFlorian Fainelli 2608967dd82fSFlorian Fainelli dev->reset_gpio = b53_switch_get_reset_gpio(dev); 2609967dd82fSFlorian Fainelli if (dev->reset_gpio >= 0) { 2610967dd82fSFlorian Fainelli ret = devm_gpio_request_one(dev->dev, dev->reset_gpio, 2611967dd82fSFlorian Fainelli GPIOF_OUT_INIT_HIGH, "robo_reset"); 2612967dd82fSFlorian Fainelli if (ret) 2613967dd82fSFlorian Fainelli return ret; 2614967dd82fSFlorian Fainelli } 2615967dd82fSFlorian Fainelli 2616967dd82fSFlorian Fainelli return 0; 2617967dd82fSFlorian Fainelli } 2618967dd82fSFlorian Fainelli 26190dff88d3SJulia Lawall struct b53_device *b53_switch_alloc(struct device *base, 26200dff88d3SJulia Lawall const struct b53_io_ops *ops, 2621967dd82fSFlorian Fainelli void *priv) 2622967dd82fSFlorian Fainelli { 2623967dd82fSFlorian Fainelli struct dsa_switch *ds; 2624967dd82fSFlorian Fainelli struct b53_device *dev; 2625967dd82fSFlorian Fainelli 26267e99e347SVivien Didelot ds = devm_kzalloc(base, sizeof(*ds), GFP_KERNEL); 2627967dd82fSFlorian Fainelli if (!ds) 2628967dd82fSFlorian Fainelli return NULL; 2629967dd82fSFlorian Fainelli 26307e99e347SVivien Didelot ds->dev = base; 26317e99e347SVivien Didelot ds->num_ports = DSA_MAX_PORTS; 26327e99e347SVivien Didelot 2633a0c02161SVivien Didelot dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL); 2634a0c02161SVivien Didelot if (!dev) 2635a0c02161SVivien Didelot return NULL; 2636967dd82fSFlorian Fainelli 2637967dd82fSFlorian Fainelli ds->priv = dev; 2638967dd82fSFlorian Fainelli dev->dev = base; 2639967dd82fSFlorian Fainelli 2640967dd82fSFlorian Fainelli dev->ds = ds; 2641967dd82fSFlorian Fainelli dev->priv = priv; 2642967dd82fSFlorian Fainelli dev->ops = ops; 2643485ebd61SFlorian Fainelli ds->ops = &b53_switch_ops; 26441c5ad5a9SFlorian Fainelli ds->untag_bridge_pvid = true; 26450ee2af4eSVladimir Oltean dev->vlan_enabled = true; 2646967dd82fSFlorian Fainelli mutex_init(&dev->reg_mutex); 2647967dd82fSFlorian Fainelli mutex_init(&dev->stats_mutex); 2648967dd82fSFlorian Fainelli 2649967dd82fSFlorian Fainelli return dev; 2650967dd82fSFlorian Fainelli } 2651967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_alloc); 2652967dd82fSFlorian Fainelli 2653967dd82fSFlorian Fainelli int b53_switch_detect(struct b53_device *dev) 2654967dd82fSFlorian Fainelli { 2655967dd82fSFlorian Fainelli u32 id32; 2656967dd82fSFlorian Fainelli u16 tmp; 2657967dd82fSFlorian Fainelli u8 id8; 2658967dd82fSFlorian Fainelli int ret; 2659967dd82fSFlorian Fainelli 2660967dd82fSFlorian Fainelli ret = b53_read8(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id8); 2661967dd82fSFlorian Fainelli if (ret) 2662967dd82fSFlorian Fainelli return ret; 2663967dd82fSFlorian Fainelli 2664967dd82fSFlorian Fainelli switch (id8) { 2665967dd82fSFlorian Fainelli case 0: 2666967dd82fSFlorian Fainelli /* BCM5325 and BCM5365 do not have this register so reads 2667967dd82fSFlorian Fainelli * return 0. But the read operation did succeed, so assume this 2668967dd82fSFlorian Fainelli * is one of them. 2669967dd82fSFlorian Fainelli * 2670967dd82fSFlorian Fainelli * Next check if we can write to the 5325's VTA register; for 2671967dd82fSFlorian Fainelli * 5365 it is read only. 2672967dd82fSFlorian Fainelli */ 2673967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, 0xf); 2674967dd82fSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, &tmp); 2675967dd82fSFlorian Fainelli 2676967dd82fSFlorian Fainelli if (tmp == 0xf) 2677967dd82fSFlorian Fainelli dev->chip_id = BCM5325_DEVICE_ID; 2678967dd82fSFlorian Fainelli else 2679967dd82fSFlorian Fainelli dev->chip_id = BCM5365_DEVICE_ID; 2680967dd82fSFlorian Fainelli break; 2681a95691bcSDamien Thébault case BCM5389_DEVICE_ID: 2682967dd82fSFlorian Fainelli case BCM5395_DEVICE_ID: 2683967dd82fSFlorian Fainelli case BCM5397_DEVICE_ID: 2684967dd82fSFlorian Fainelli case BCM5398_DEVICE_ID: 2685967dd82fSFlorian Fainelli dev->chip_id = id8; 2686967dd82fSFlorian Fainelli break; 2687967dd82fSFlorian Fainelli default: 2688967dd82fSFlorian Fainelli ret = b53_read32(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id32); 2689967dd82fSFlorian Fainelli if (ret) 2690967dd82fSFlorian Fainelli return ret; 2691967dd82fSFlorian Fainelli 2692967dd82fSFlorian Fainelli switch (id32) { 2693967dd82fSFlorian Fainelli case BCM53115_DEVICE_ID: 2694967dd82fSFlorian Fainelli case BCM53125_DEVICE_ID: 2695967dd82fSFlorian Fainelli case BCM53128_DEVICE_ID: 2696967dd82fSFlorian Fainelli case BCM53010_DEVICE_ID: 2697967dd82fSFlorian Fainelli case BCM53011_DEVICE_ID: 2698967dd82fSFlorian Fainelli case BCM53012_DEVICE_ID: 2699967dd82fSFlorian Fainelli case BCM53018_DEVICE_ID: 2700967dd82fSFlorian Fainelli case BCM53019_DEVICE_ID: 2701967dd82fSFlorian Fainelli dev->chip_id = id32; 2702967dd82fSFlorian Fainelli break; 2703967dd82fSFlorian Fainelli default: 27043b33438cSPaul Barker dev_err(dev->dev, 27053b33438cSPaul Barker "unsupported switch detected (BCM53%02x/BCM%x)\n", 2706967dd82fSFlorian Fainelli id8, id32); 2707967dd82fSFlorian Fainelli return -ENODEV; 2708967dd82fSFlorian Fainelli } 2709967dd82fSFlorian Fainelli } 2710967dd82fSFlorian Fainelli 2711967dd82fSFlorian Fainelli if (dev->chip_id == BCM5325_DEVICE_ID) 2712967dd82fSFlorian Fainelli return b53_read8(dev, B53_STAT_PAGE, B53_REV_ID_25, 2713967dd82fSFlorian Fainelli &dev->core_rev); 2714967dd82fSFlorian Fainelli else 2715967dd82fSFlorian Fainelli return b53_read8(dev, B53_MGMT_PAGE, B53_REV_ID, 2716967dd82fSFlorian Fainelli &dev->core_rev); 2717967dd82fSFlorian Fainelli } 2718967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_detect); 2719967dd82fSFlorian Fainelli 2720967dd82fSFlorian Fainelli int b53_switch_register(struct b53_device *dev) 2721967dd82fSFlorian Fainelli { 2722967dd82fSFlorian Fainelli int ret; 2723967dd82fSFlorian Fainelli 2724967dd82fSFlorian Fainelli if (dev->pdata) { 2725967dd82fSFlorian Fainelli dev->chip_id = dev->pdata->chip_id; 2726967dd82fSFlorian Fainelli dev->enabled_ports = dev->pdata->enabled_ports; 2727967dd82fSFlorian Fainelli } 2728967dd82fSFlorian Fainelli 2729967dd82fSFlorian Fainelli if (!dev->chip_id && b53_switch_detect(dev)) 2730967dd82fSFlorian Fainelli return -EINVAL; 2731967dd82fSFlorian Fainelli 2732967dd82fSFlorian Fainelli ret = b53_switch_init(dev); 2733967dd82fSFlorian Fainelli if (ret) 2734967dd82fSFlorian Fainelli return ret; 2735967dd82fSFlorian Fainelli 27363b33438cSPaul Barker dev_info(dev->dev, "found switch: %s, rev %i\n", 27373b33438cSPaul Barker dev->name, dev->core_rev); 2738967dd82fSFlorian Fainelli 273923c9ee49SVivien Didelot return dsa_register_switch(dev->ds); 2740967dd82fSFlorian Fainelli } 2741967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_register); 2742967dd82fSFlorian Fainelli 2743967dd82fSFlorian Fainelli MODULE_AUTHOR("Jonas Gorski <jogo@openwrt.org>"); 2744967dd82fSFlorian Fainelli MODULE_DESCRIPTION("B53 switch library"); 2745967dd82fSFlorian Fainelli MODULE_LICENSE("Dual BSD/GPL"); 2746