1967dd82fSFlorian Fainelli /* 2967dd82fSFlorian Fainelli * B53 switch driver main logic 3967dd82fSFlorian Fainelli * 4967dd82fSFlorian Fainelli * Copyright (C) 2011-2013 Jonas Gorski <jogo@openwrt.org> 5967dd82fSFlorian Fainelli * Copyright (C) 2016 Florian Fainelli <f.fainelli@gmail.com> 6967dd82fSFlorian Fainelli * 7967dd82fSFlorian Fainelli * Permission to use, copy, modify, and/or distribute this software for any 8967dd82fSFlorian Fainelli * purpose with or without fee is hereby granted, provided that the above 9967dd82fSFlorian Fainelli * copyright notice and this permission notice appear in all copies. 10967dd82fSFlorian Fainelli * 11967dd82fSFlorian Fainelli * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12967dd82fSFlorian Fainelli * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13967dd82fSFlorian Fainelli * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14967dd82fSFlorian Fainelli * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15967dd82fSFlorian Fainelli * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16967dd82fSFlorian Fainelli * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17967dd82fSFlorian Fainelli * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18967dd82fSFlorian Fainelli */ 19967dd82fSFlorian Fainelli 20967dd82fSFlorian Fainelli #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 21967dd82fSFlorian Fainelli 22967dd82fSFlorian Fainelli #include <linux/delay.h> 23967dd82fSFlorian Fainelli #include <linux/export.h> 24967dd82fSFlorian Fainelli #include <linux/gpio.h> 25967dd82fSFlorian Fainelli #include <linux/kernel.h> 26967dd82fSFlorian Fainelli #include <linux/module.h> 27967dd82fSFlorian Fainelli #include <linux/platform_data/b53.h> 28967dd82fSFlorian Fainelli #include <linux/phy.h> 291da6df85SFlorian Fainelli #include <linux/etherdevice.h> 30ff39c2d6SFlorian Fainelli #include <linux/if_bridge.h> 31967dd82fSFlorian Fainelli #include <net/dsa.h> 32967dd82fSFlorian Fainelli 33967dd82fSFlorian Fainelli #include "b53_regs.h" 34967dd82fSFlorian Fainelli #include "b53_priv.h" 35967dd82fSFlorian Fainelli 36967dd82fSFlorian Fainelli struct b53_mib_desc { 37967dd82fSFlorian Fainelli u8 size; 38967dd82fSFlorian Fainelli u8 offset; 39967dd82fSFlorian Fainelli const char *name; 40967dd82fSFlorian Fainelli }; 41967dd82fSFlorian Fainelli 42967dd82fSFlorian Fainelli /* BCM5365 MIB counters */ 43967dd82fSFlorian Fainelli static const struct b53_mib_desc b53_mibs_65[] = { 44967dd82fSFlorian Fainelli { 8, 0x00, "TxOctets" }, 45967dd82fSFlorian Fainelli { 4, 0x08, "TxDropPkts" }, 46967dd82fSFlorian Fainelli { 4, 0x10, "TxBroadcastPkts" }, 47967dd82fSFlorian Fainelli { 4, 0x14, "TxMulticastPkts" }, 48967dd82fSFlorian Fainelli { 4, 0x18, "TxUnicastPkts" }, 49967dd82fSFlorian Fainelli { 4, 0x1c, "TxCollisions" }, 50967dd82fSFlorian Fainelli { 4, 0x20, "TxSingleCollision" }, 51967dd82fSFlorian Fainelli { 4, 0x24, "TxMultipleCollision" }, 52967dd82fSFlorian Fainelli { 4, 0x28, "TxDeferredTransmit" }, 53967dd82fSFlorian Fainelli { 4, 0x2c, "TxLateCollision" }, 54967dd82fSFlorian Fainelli { 4, 0x30, "TxExcessiveCollision" }, 55967dd82fSFlorian Fainelli { 4, 0x38, "TxPausePkts" }, 56967dd82fSFlorian Fainelli { 8, 0x44, "RxOctets" }, 57967dd82fSFlorian Fainelli { 4, 0x4c, "RxUndersizePkts" }, 58967dd82fSFlorian Fainelli { 4, 0x50, "RxPausePkts" }, 59967dd82fSFlorian Fainelli { 4, 0x54, "Pkts64Octets" }, 60967dd82fSFlorian Fainelli { 4, 0x58, "Pkts65to127Octets" }, 61967dd82fSFlorian Fainelli { 4, 0x5c, "Pkts128to255Octets" }, 62967dd82fSFlorian Fainelli { 4, 0x60, "Pkts256to511Octets" }, 63967dd82fSFlorian Fainelli { 4, 0x64, "Pkts512to1023Octets" }, 64967dd82fSFlorian Fainelli { 4, 0x68, "Pkts1024to1522Octets" }, 65967dd82fSFlorian Fainelli { 4, 0x6c, "RxOversizePkts" }, 66967dd82fSFlorian Fainelli { 4, 0x70, "RxJabbers" }, 67967dd82fSFlorian Fainelli { 4, 0x74, "RxAlignmentErrors" }, 68967dd82fSFlorian Fainelli { 4, 0x78, "RxFCSErrors" }, 69967dd82fSFlorian Fainelli { 8, 0x7c, "RxGoodOctets" }, 70967dd82fSFlorian Fainelli { 4, 0x84, "RxDropPkts" }, 71967dd82fSFlorian Fainelli { 4, 0x88, "RxUnicastPkts" }, 72967dd82fSFlorian Fainelli { 4, 0x8c, "RxMulticastPkts" }, 73967dd82fSFlorian Fainelli { 4, 0x90, "RxBroadcastPkts" }, 74967dd82fSFlorian Fainelli { 4, 0x94, "RxSAChanges" }, 75967dd82fSFlorian Fainelli { 4, 0x98, "RxFragments" }, 76967dd82fSFlorian Fainelli }; 77967dd82fSFlorian Fainelli 78967dd82fSFlorian Fainelli #define B53_MIBS_65_SIZE ARRAY_SIZE(b53_mibs_65) 79967dd82fSFlorian Fainelli 80967dd82fSFlorian Fainelli /* BCM63xx MIB counters */ 81967dd82fSFlorian Fainelli static const struct b53_mib_desc b53_mibs_63xx[] = { 82967dd82fSFlorian Fainelli { 8, 0x00, "TxOctets" }, 83967dd82fSFlorian Fainelli { 4, 0x08, "TxDropPkts" }, 84967dd82fSFlorian Fainelli { 4, 0x0c, "TxQoSPkts" }, 85967dd82fSFlorian Fainelli { 4, 0x10, "TxBroadcastPkts" }, 86967dd82fSFlorian Fainelli { 4, 0x14, "TxMulticastPkts" }, 87967dd82fSFlorian Fainelli { 4, 0x18, "TxUnicastPkts" }, 88967dd82fSFlorian Fainelli { 4, 0x1c, "TxCollisions" }, 89967dd82fSFlorian Fainelli { 4, 0x20, "TxSingleCollision" }, 90967dd82fSFlorian Fainelli { 4, 0x24, "TxMultipleCollision" }, 91967dd82fSFlorian Fainelli { 4, 0x28, "TxDeferredTransmit" }, 92967dd82fSFlorian Fainelli { 4, 0x2c, "TxLateCollision" }, 93967dd82fSFlorian Fainelli { 4, 0x30, "TxExcessiveCollision" }, 94967dd82fSFlorian Fainelli { 4, 0x38, "TxPausePkts" }, 95967dd82fSFlorian Fainelli { 8, 0x3c, "TxQoSOctets" }, 96967dd82fSFlorian Fainelli { 8, 0x44, "RxOctets" }, 97967dd82fSFlorian Fainelli { 4, 0x4c, "RxUndersizePkts" }, 98967dd82fSFlorian Fainelli { 4, 0x50, "RxPausePkts" }, 99967dd82fSFlorian Fainelli { 4, 0x54, "Pkts64Octets" }, 100967dd82fSFlorian Fainelli { 4, 0x58, "Pkts65to127Octets" }, 101967dd82fSFlorian Fainelli { 4, 0x5c, "Pkts128to255Octets" }, 102967dd82fSFlorian Fainelli { 4, 0x60, "Pkts256to511Octets" }, 103967dd82fSFlorian Fainelli { 4, 0x64, "Pkts512to1023Octets" }, 104967dd82fSFlorian Fainelli { 4, 0x68, "Pkts1024to1522Octets" }, 105967dd82fSFlorian Fainelli { 4, 0x6c, "RxOversizePkts" }, 106967dd82fSFlorian Fainelli { 4, 0x70, "RxJabbers" }, 107967dd82fSFlorian Fainelli { 4, 0x74, "RxAlignmentErrors" }, 108967dd82fSFlorian Fainelli { 4, 0x78, "RxFCSErrors" }, 109967dd82fSFlorian Fainelli { 8, 0x7c, "RxGoodOctets" }, 110967dd82fSFlorian Fainelli { 4, 0x84, "RxDropPkts" }, 111967dd82fSFlorian Fainelli { 4, 0x88, "RxUnicastPkts" }, 112967dd82fSFlorian Fainelli { 4, 0x8c, "RxMulticastPkts" }, 113967dd82fSFlorian Fainelli { 4, 0x90, "RxBroadcastPkts" }, 114967dd82fSFlorian Fainelli { 4, 0x94, "RxSAChanges" }, 115967dd82fSFlorian Fainelli { 4, 0x98, "RxFragments" }, 116967dd82fSFlorian Fainelli { 4, 0xa0, "RxSymbolErrors" }, 117967dd82fSFlorian Fainelli { 4, 0xa4, "RxQoSPkts" }, 118967dd82fSFlorian Fainelli { 8, 0xa8, "RxQoSOctets" }, 119967dd82fSFlorian Fainelli { 4, 0xb0, "Pkts1523to2047Octets" }, 120967dd82fSFlorian Fainelli { 4, 0xb4, "Pkts2048to4095Octets" }, 121967dd82fSFlorian Fainelli { 4, 0xb8, "Pkts4096to8191Octets" }, 122967dd82fSFlorian Fainelli { 4, 0xbc, "Pkts8192to9728Octets" }, 123967dd82fSFlorian Fainelli { 4, 0xc0, "RxDiscarded" }, 124967dd82fSFlorian Fainelli }; 125967dd82fSFlorian Fainelli 126967dd82fSFlorian Fainelli #define B53_MIBS_63XX_SIZE ARRAY_SIZE(b53_mibs_63xx) 127967dd82fSFlorian Fainelli 128967dd82fSFlorian Fainelli /* MIB counters */ 129967dd82fSFlorian Fainelli static const struct b53_mib_desc b53_mibs[] = { 130967dd82fSFlorian Fainelli { 8, 0x00, "TxOctets" }, 131967dd82fSFlorian Fainelli { 4, 0x08, "TxDropPkts" }, 132967dd82fSFlorian Fainelli { 4, 0x10, "TxBroadcastPkts" }, 133967dd82fSFlorian Fainelli { 4, 0x14, "TxMulticastPkts" }, 134967dd82fSFlorian Fainelli { 4, 0x18, "TxUnicastPkts" }, 135967dd82fSFlorian Fainelli { 4, 0x1c, "TxCollisions" }, 136967dd82fSFlorian Fainelli { 4, 0x20, "TxSingleCollision" }, 137967dd82fSFlorian Fainelli { 4, 0x24, "TxMultipleCollision" }, 138967dd82fSFlorian Fainelli { 4, 0x28, "TxDeferredTransmit" }, 139967dd82fSFlorian Fainelli { 4, 0x2c, "TxLateCollision" }, 140967dd82fSFlorian Fainelli { 4, 0x30, "TxExcessiveCollision" }, 141967dd82fSFlorian Fainelli { 4, 0x38, "TxPausePkts" }, 142967dd82fSFlorian Fainelli { 8, 0x50, "RxOctets" }, 143967dd82fSFlorian Fainelli { 4, 0x58, "RxUndersizePkts" }, 144967dd82fSFlorian Fainelli { 4, 0x5c, "RxPausePkts" }, 145967dd82fSFlorian Fainelli { 4, 0x60, "Pkts64Octets" }, 146967dd82fSFlorian Fainelli { 4, 0x64, "Pkts65to127Octets" }, 147967dd82fSFlorian Fainelli { 4, 0x68, "Pkts128to255Octets" }, 148967dd82fSFlorian Fainelli { 4, 0x6c, "Pkts256to511Octets" }, 149967dd82fSFlorian Fainelli { 4, 0x70, "Pkts512to1023Octets" }, 150967dd82fSFlorian Fainelli { 4, 0x74, "Pkts1024to1522Octets" }, 151967dd82fSFlorian Fainelli { 4, 0x78, "RxOversizePkts" }, 152967dd82fSFlorian Fainelli { 4, 0x7c, "RxJabbers" }, 153967dd82fSFlorian Fainelli { 4, 0x80, "RxAlignmentErrors" }, 154967dd82fSFlorian Fainelli { 4, 0x84, "RxFCSErrors" }, 155967dd82fSFlorian Fainelli { 8, 0x88, "RxGoodOctets" }, 156967dd82fSFlorian Fainelli { 4, 0x90, "RxDropPkts" }, 157967dd82fSFlorian Fainelli { 4, 0x94, "RxUnicastPkts" }, 158967dd82fSFlorian Fainelli { 4, 0x98, "RxMulticastPkts" }, 159967dd82fSFlorian Fainelli { 4, 0x9c, "RxBroadcastPkts" }, 160967dd82fSFlorian Fainelli { 4, 0xa0, "RxSAChanges" }, 161967dd82fSFlorian Fainelli { 4, 0xa4, "RxFragments" }, 162967dd82fSFlorian Fainelli { 4, 0xa8, "RxJumboPkts" }, 163967dd82fSFlorian Fainelli { 4, 0xac, "RxSymbolErrors" }, 164967dd82fSFlorian Fainelli { 4, 0xc0, "RxDiscarded" }, 165967dd82fSFlorian Fainelli }; 166967dd82fSFlorian Fainelli 167967dd82fSFlorian Fainelli #define B53_MIBS_SIZE ARRAY_SIZE(b53_mibs) 168967dd82fSFlorian Fainelli 169bde5d132SFlorian Fainelli static const struct b53_mib_desc b53_mibs_58xx[] = { 170bde5d132SFlorian Fainelli { 8, 0x00, "TxOctets" }, 171bde5d132SFlorian Fainelli { 4, 0x08, "TxDropPkts" }, 172bde5d132SFlorian Fainelli { 4, 0x0c, "TxQPKTQ0" }, 173bde5d132SFlorian Fainelli { 4, 0x10, "TxBroadcastPkts" }, 174bde5d132SFlorian Fainelli { 4, 0x14, "TxMulticastPkts" }, 175bde5d132SFlorian Fainelli { 4, 0x18, "TxUnicastPKts" }, 176bde5d132SFlorian Fainelli { 4, 0x1c, "TxCollisions" }, 177bde5d132SFlorian Fainelli { 4, 0x20, "TxSingleCollision" }, 178bde5d132SFlorian Fainelli { 4, 0x24, "TxMultipleCollision" }, 179bde5d132SFlorian Fainelli { 4, 0x28, "TxDeferredCollision" }, 180bde5d132SFlorian Fainelli { 4, 0x2c, "TxLateCollision" }, 181bde5d132SFlorian Fainelli { 4, 0x30, "TxExcessiveCollision" }, 182bde5d132SFlorian Fainelli { 4, 0x34, "TxFrameInDisc" }, 183bde5d132SFlorian Fainelli { 4, 0x38, "TxPausePkts" }, 184bde5d132SFlorian Fainelli { 4, 0x3c, "TxQPKTQ1" }, 185bde5d132SFlorian Fainelli { 4, 0x40, "TxQPKTQ2" }, 186bde5d132SFlorian Fainelli { 4, 0x44, "TxQPKTQ3" }, 187bde5d132SFlorian Fainelli { 4, 0x48, "TxQPKTQ4" }, 188bde5d132SFlorian Fainelli { 4, 0x4c, "TxQPKTQ5" }, 189bde5d132SFlorian Fainelli { 8, 0x50, "RxOctets" }, 190bde5d132SFlorian Fainelli { 4, 0x58, "RxUndersizePkts" }, 191bde5d132SFlorian Fainelli { 4, 0x5c, "RxPausePkts" }, 192bde5d132SFlorian Fainelli { 4, 0x60, "RxPkts64Octets" }, 193bde5d132SFlorian Fainelli { 4, 0x64, "RxPkts65to127Octets" }, 194bde5d132SFlorian Fainelli { 4, 0x68, "RxPkts128to255Octets" }, 195bde5d132SFlorian Fainelli { 4, 0x6c, "RxPkts256to511Octets" }, 196bde5d132SFlorian Fainelli { 4, 0x70, "RxPkts512to1023Octets" }, 197bde5d132SFlorian Fainelli { 4, 0x74, "RxPkts1024toMaxPktsOctets" }, 198bde5d132SFlorian Fainelli { 4, 0x78, "RxOversizePkts" }, 199bde5d132SFlorian Fainelli { 4, 0x7c, "RxJabbers" }, 200bde5d132SFlorian Fainelli { 4, 0x80, "RxAlignmentErrors" }, 201bde5d132SFlorian Fainelli { 4, 0x84, "RxFCSErrors" }, 202bde5d132SFlorian Fainelli { 8, 0x88, "RxGoodOctets" }, 203bde5d132SFlorian Fainelli { 4, 0x90, "RxDropPkts" }, 204bde5d132SFlorian Fainelli { 4, 0x94, "RxUnicastPkts" }, 205bde5d132SFlorian Fainelli { 4, 0x98, "RxMulticastPkts" }, 206bde5d132SFlorian Fainelli { 4, 0x9c, "RxBroadcastPkts" }, 207bde5d132SFlorian Fainelli { 4, 0xa0, "RxSAChanges" }, 208bde5d132SFlorian Fainelli { 4, 0xa4, "RxFragments" }, 209bde5d132SFlorian Fainelli { 4, 0xa8, "RxJumboPkt" }, 210bde5d132SFlorian Fainelli { 4, 0xac, "RxSymblErr" }, 211bde5d132SFlorian Fainelli { 4, 0xb0, "InRangeErrCount" }, 212bde5d132SFlorian Fainelli { 4, 0xb4, "OutRangeErrCount" }, 213bde5d132SFlorian Fainelli { 4, 0xb8, "EEELpiEvent" }, 214bde5d132SFlorian Fainelli { 4, 0xbc, "EEELpiDuration" }, 215bde5d132SFlorian Fainelli { 4, 0xc0, "RxDiscard" }, 216bde5d132SFlorian Fainelli { 4, 0xc8, "TxQPKTQ6" }, 217bde5d132SFlorian Fainelli { 4, 0xcc, "TxQPKTQ7" }, 218bde5d132SFlorian Fainelli { 4, 0xd0, "TxPkts64Octets" }, 219bde5d132SFlorian Fainelli { 4, 0xd4, "TxPkts65to127Octets" }, 220bde5d132SFlorian Fainelli { 4, 0xd8, "TxPkts128to255Octets" }, 221bde5d132SFlorian Fainelli { 4, 0xdc, "TxPkts256to511Ocets" }, 222bde5d132SFlorian Fainelli { 4, 0xe0, "TxPkts512to1023Ocets" }, 223bde5d132SFlorian Fainelli { 4, 0xe4, "TxPkts1024toMaxPktOcets" }, 224bde5d132SFlorian Fainelli }; 225bde5d132SFlorian Fainelli 226bde5d132SFlorian Fainelli #define B53_MIBS_58XX_SIZE ARRAY_SIZE(b53_mibs_58xx) 227bde5d132SFlorian Fainelli 228967dd82fSFlorian Fainelli static int b53_do_vlan_op(struct b53_device *dev, u8 op) 229967dd82fSFlorian Fainelli { 230967dd82fSFlorian Fainelli unsigned int i; 231967dd82fSFlorian Fainelli 232967dd82fSFlorian Fainelli b53_write8(dev, B53_ARLIO_PAGE, dev->vta_regs[0], VTA_START_CMD | op); 233967dd82fSFlorian Fainelli 234967dd82fSFlorian Fainelli for (i = 0; i < 10; i++) { 235967dd82fSFlorian Fainelli u8 vta; 236967dd82fSFlorian Fainelli 237967dd82fSFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, dev->vta_regs[0], &vta); 238967dd82fSFlorian Fainelli if (!(vta & VTA_START_CMD)) 239967dd82fSFlorian Fainelli return 0; 240967dd82fSFlorian Fainelli 241967dd82fSFlorian Fainelli usleep_range(100, 200); 242967dd82fSFlorian Fainelli } 243967dd82fSFlorian Fainelli 244967dd82fSFlorian Fainelli return -EIO; 245967dd82fSFlorian Fainelli } 246967dd82fSFlorian Fainelli 247a2482d2cSFlorian Fainelli static void b53_set_vlan_entry(struct b53_device *dev, u16 vid, 248a2482d2cSFlorian Fainelli struct b53_vlan *vlan) 249967dd82fSFlorian Fainelli { 250967dd82fSFlorian Fainelli if (is5325(dev)) { 251967dd82fSFlorian Fainelli u32 entry = 0; 252967dd82fSFlorian Fainelli 253a2482d2cSFlorian Fainelli if (vlan->members) { 254a2482d2cSFlorian Fainelli entry = ((vlan->untag & VA_UNTAG_MASK_25) << 255a2482d2cSFlorian Fainelli VA_UNTAG_S_25) | vlan->members; 256967dd82fSFlorian Fainelli if (dev->core_rev >= 3) 257967dd82fSFlorian Fainelli entry |= VA_VALID_25_R4 | vid << VA_VID_HIGH_S; 258967dd82fSFlorian Fainelli else 259967dd82fSFlorian Fainelli entry |= VA_VALID_25; 260967dd82fSFlorian Fainelli } 261967dd82fSFlorian Fainelli 262967dd82fSFlorian Fainelli b53_write32(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_25, entry); 263967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, vid | 264967dd82fSFlorian Fainelli VTA_RW_STATE_WR | VTA_RW_OP_EN); 265967dd82fSFlorian Fainelli } else if (is5365(dev)) { 266967dd82fSFlorian Fainelli u16 entry = 0; 267967dd82fSFlorian Fainelli 268a2482d2cSFlorian Fainelli if (vlan->members) 269a2482d2cSFlorian Fainelli entry = ((vlan->untag & VA_UNTAG_MASK_65) << 270a2482d2cSFlorian Fainelli VA_UNTAG_S_65) | vlan->members | VA_VALID_65; 271967dd82fSFlorian Fainelli 272967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_65, entry); 273967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_65, vid | 274967dd82fSFlorian Fainelli VTA_RW_STATE_WR | VTA_RW_OP_EN); 275967dd82fSFlorian Fainelli } else { 276967dd82fSFlorian Fainelli b53_write16(dev, B53_ARLIO_PAGE, dev->vta_regs[1], vid); 277967dd82fSFlorian Fainelli b53_write32(dev, B53_ARLIO_PAGE, dev->vta_regs[2], 278a2482d2cSFlorian Fainelli (vlan->untag << VTE_UNTAG_S) | vlan->members); 279967dd82fSFlorian Fainelli 280967dd82fSFlorian Fainelli b53_do_vlan_op(dev, VTA_CMD_WRITE); 281967dd82fSFlorian Fainelli } 282a2482d2cSFlorian Fainelli 283a2482d2cSFlorian Fainelli dev_dbg(dev->ds->dev, "VID: %d, members: 0x%04x, untag: 0x%04x\n", 284a2482d2cSFlorian Fainelli vid, vlan->members, vlan->untag); 285967dd82fSFlorian Fainelli } 286967dd82fSFlorian Fainelli 287a2482d2cSFlorian Fainelli static void b53_get_vlan_entry(struct b53_device *dev, u16 vid, 288a2482d2cSFlorian Fainelli struct b53_vlan *vlan) 289a2482d2cSFlorian Fainelli { 290a2482d2cSFlorian Fainelli if (is5325(dev)) { 291a2482d2cSFlorian Fainelli u32 entry = 0; 292a2482d2cSFlorian Fainelli 293a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, vid | 294a2482d2cSFlorian Fainelli VTA_RW_STATE_RD | VTA_RW_OP_EN); 295a2482d2cSFlorian Fainelli b53_read32(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_25, &entry); 296a2482d2cSFlorian Fainelli 297a2482d2cSFlorian Fainelli if (dev->core_rev >= 3) 298a2482d2cSFlorian Fainelli vlan->valid = !!(entry & VA_VALID_25_R4); 299a2482d2cSFlorian Fainelli else 300a2482d2cSFlorian Fainelli vlan->valid = !!(entry & VA_VALID_25); 301a2482d2cSFlorian Fainelli vlan->members = entry & VA_MEMBER_MASK; 302a2482d2cSFlorian Fainelli vlan->untag = (entry >> VA_UNTAG_S_25) & VA_UNTAG_MASK_25; 303a2482d2cSFlorian Fainelli 304a2482d2cSFlorian Fainelli } else if (is5365(dev)) { 305a2482d2cSFlorian Fainelli u16 entry = 0; 306a2482d2cSFlorian Fainelli 307a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_65, vid | 308a2482d2cSFlorian Fainelli VTA_RW_STATE_WR | VTA_RW_OP_EN); 309a2482d2cSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_65, &entry); 310a2482d2cSFlorian Fainelli 311a2482d2cSFlorian Fainelli vlan->valid = !!(entry & VA_VALID_65); 312a2482d2cSFlorian Fainelli vlan->members = entry & VA_MEMBER_MASK; 313a2482d2cSFlorian Fainelli vlan->untag = (entry >> VA_UNTAG_S_65) & VA_UNTAG_MASK_65; 314a2482d2cSFlorian Fainelli } else { 315a2482d2cSFlorian Fainelli u32 entry = 0; 316a2482d2cSFlorian Fainelli 317a2482d2cSFlorian Fainelli b53_write16(dev, B53_ARLIO_PAGE, dev->vta_regs[1], vid); 318a2482d2cSFlorian Fainelli b53_do_vlan_op(dev, VTA_CMD_READ); 319a2482d2cSFlorian Fainelli b53_read32(dev, B53_ARLIO_PAGE, dev->vta_regs[2], &entry); 320a2482d2cSFlorian Fainelli vlan->members = entry & VTE_MEMBERS; 321a2482d2cSFlorian Fainelli vlan->untag = (entry >> VTE_UNTAG_S) & VTE_MEMBERS; 322a2482d2cSFlorian Fainelli vlan->valid = true; 323a2482d2cSFlorian Fainelli } 324a2482d2cSFlorian Fainelli } 325a2482d2cSFlorian Fainelli 326a2482d2cSFlorian Fainelli static void b53_set_forwarding(struct b53_device *dev, int enable) 327967dd82fSFlorian Fainelli { 328a424f0deSFlorian Fainelli struct dsa_switch *ds = dev->ds; 329967dd82fSFlorian Fainelli u8 mgmt; 330967dd82fSFlorian Fainelli 331967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); 332967dd82fSFlorian Fainelli 333967dd82fSFlorian Fainelli if (enable) 334967dd82fSFlorian Fainelli mgmt |= SM_SW_FWD_EN; 335967dd82fSFlorian Fainelli else 336967dd82fSFlorian Fainelli mgmt &= ~SM_SW_FWD_EN; 337967dd82fSFlorian Fainelli 338967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt); 339a424f0deSFlorian Fainelli 340a424f0deSFlorian Fainelli /* Include IMP port in dumb forwarding mode when no tagging protocol is 341a424f0deSFlorian Fainelli * set 342a424f0deSFlorian Fainelli */ 343a424f0deSFlorian Fainelli if (ds->ops->get_tag_protocol(ds) == DSA_TAG_PROTO_NONE) { 344a424f0deSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, &mgmt); 345a424f0deSFlorian Fainelli mgmt |= B53_MII_DUMB_FWDG_EN; 346a424f0deSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, mgmt); 347a424f0deSFlorian Fainelli } 348967dd82fSFlorian Fainelli } 349967dd82fSFlorian Fainelli 350a2482d2cSFlorian Fainelli static void b53_enable_vlan(struct b53_device *dev, bool enable) 351967dd82fSFlorian Fainelli { 352967dd82fSFlorian Fainelli u8 mgmt, vc0, vc1, vc4 = 0, vc5; 353967dd82fSFlorian Fainelli 354967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); 355967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL0, &vc0); 356967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL1, &vc1); 357967dd82fSFlorian Fainelli 358967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) { 359967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4); 360967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_25, &vc5); 361967dd82fSFlorian Fainelli } else if (is63xx(dev)) { 362967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_63XX, &vc4); 363967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_63XX, &vc5); 364967dd82fSFlorian Fainelli } else { 365967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, &vc4); 366967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, &vc5); 367967dd82fSFlorian Fainelli } 368967dd82fSFlorian Fainelli 369967dd82fSFlorian Fainelli mgmt &= ~SM_SW_FWD_MODE; 370967dd82fSFlorian Fainelli 371967dd82fSFlorian Fainelli if (enable) { 372967dd82fSFlorian Fainelli vc0 |= VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID; 373967dd82fSFlorian Fainelli vc1 |= VC1_RX_MCST_UNTAG_EN | VC1_RX_MCST_FWD_EN; 374967dd82fSFlorian Fainelli vc4 &= ~VC4_ING_VID_CHECK_MASK; 375967dd82fSFlorian Fainelli vc4 |= VC4_ING_VID_VIO_DROP << VC4_ING_VID_CHECK_S; 376967dd82fSFlorian Fainelli vc5 |= VC5_DROP_VTABLE_MISS; 377967dd82fSFlorian Fainelli 378967dd82fSFlorian Fainelli if (is5325(dev)) 379967dd82fSFlorian Fainelli vc0 &= ~VC0_RESERVED_1; 380967dd82fSFlorian Fainelli 381967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 382967dd82fSFlorian Fainelli vc1 |= VC1_RX_MCST_TAG_EN; 383967dd82fSFlorian Fainelli 384967dd82fSFlorian Fainelli } else { 385967dd82fSFlorian Fainelli vc0 &= ~(VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID); 386967dd82fSFlorian Fainelli vc1 &= ~(VC1_RX_MCST_UNTAG_EN | VC1_RX_MCST_FWD_EN); 387967dd82fSFlorian Fainelli vc4 &= ~VC4_ING_VID_CHECK_MASK; 388967dd82fSFlorian Fainelli vc5 &= ~VC5_DROP_VTABLE_MISS; 389967dd82fSFlorian Fainelli 390967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 391967dd82fSFlorian Fainelli vc4 |= VC4_ING_VID_VIO_FWD << VC4_ING_VID_CHECK_S; 392967dd82fSFlorian Fainelli else 393967dd82fSFlorian Fainelli vc4 |= VC4_ING_VID_VIO_TO_IMP << VC4_ING_VID_CHECK_S; 394967dd82fSFlorian Fainelli 395967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 396967dd82fSFlorian Fainelli vc1 &= ~VC1_RX_MCST_TAG_EN; 397a2482d2cSFlorian Fainelli } 398967dd82fSFlorian Fainelli 399967dd82fSFlorian Fainelli if (!is5325(dev) && !is5365(dev)) 400967dd82fSFlorian Fainelli vc5 &= ~VC5_VID_FFF_EN; 401967dd82fSFlorian Fainelli 402967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL0, vc0); 403967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL1, vc1); 404967dd82fSFlorian Fainelli 405967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) { 406967dd82fSFlorian Fainelli /* enable the high 8 bit vid check on 5325 */ 407967dd82fSFlorian Fainelli if (is5325(dev) && enable) 408967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 409967dd82fSFlorian Fainelli VC3_HIGH_8BIT_EN); 410967dd82fSFlorian Fainelli else 411967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 0); 412967dd82fSFlorian Fainelli 413967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, vc4); 414967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_25, vc5); 415967dd82fSFlorian Fainelli } else if (is63xx(dev)) { 416967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3_63XX, 0); 417967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_63XX, vc4); 418967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_63XX, vc5); 419967dd82fSFlorian Fainelli } else { 420967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 0); 421967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, vc4); 422967dd82fSFlorian Fainelli b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, vc5); 423967dd82fSFlorian Fainelli } 424967dd82fSFlorian Fainelli 425967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt); 426967dd82fSFlorian Fainelli } 427967dd82fSFlorian Fainelli 428967dd82fSFlorian Fainelli static int b53_set_jumbo(struct b53_device *dev, bool enable, bool allow_10_100) 429967dd82fSFlorian Fainelli { 430967dd82fSFlorian Fainelli u32 port_mask = 0; 431967dd82fSFlorian Fainelli u16 max_size = JMS_MIN_SIZE; 432967dd82fSFlorian Fainelli 433967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) 434967dd82fSFlorian Fainelli return -EINVAL; 435967dd82fSFlorian Fainelli 436967dd82fSFlorian Fainelli if (enable) { 437967dd82fSFlorian Fainelli port_mask = dev->enabled_ports; 438967dd82fSFlorian Fainelli max_size = JMS_MAX_SIZE; 439967dd82fSFlorian Fainelli if (allow_10_100) 440967dd82fSFlorian Fainelli port_mask |= JPM_10_100_JUMBO_EN; 441967dd82fSFlorian Fainelli } 442967dd82fSFlorian Fainelli 443967dd82fSFlorian Fainelli b53_write32(dev, B53_JUMBO_PAGE, dev->jumbo_pm_reg, port_mask); 444967dd82fSFlorian Fainelli return b53_write16(dev, B53_JUMBO_PAGE, dev->jumbo_size_reg, max_size); 445967dd82fSFlorian Fainelli } 446967dd82fSFlorian Fainelli 447ff39c2d6SFlorian Fainelli static int b53_flush_arl(struct b53_device *dev, u8 mask) 448967dd82fSFlorian Fainelli { 449967dd82fSFlorian Fainelli unsigned int i; 450967dd82fSFlorian Fainelli 451967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, 452ff39c2d6SFlorian Fainelli FAST_AGE_DONE | FAST_AGE_DYNAMIC | mask); 453967dd82fSFlorian Fainelli 454967dd82fSFlorian Fainelli for (i = 0; i < 10; i++) { 455967dd82fSFlorian Fainelli u8 fast_age_ctrl; 456967dd82fSFlorian Fainelli 457967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, 458967dd82fSFlorian Fainelli &fast_age_ctrl); 459967dd82fSFlorian Fainelli 460967dd82fSFlorian Fainelli if (!(fast_age_ctrl & FAST_AGE_DONE)) 461967dd82fSFlorian Fainelli goto out; 462967dd82fSFlorian Fainelli 463967dd82fSFlorian Fainelli msleep(1); 464967dd82fSFlorian Fainelli } 465967dd82fSFlorian Fainelli 466967dd82fSFlorian Fainelli return -ETIMEDOUT; 467967dd82fSFlorian Fainelli out: 468967dd82fSFlorian Fainelli /* Only age dynamic entries (default behavior) */ 469967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, FAST_AGE_DYNAMIC); 470967dd82fSFlorian Fainelli return 0; 471967dd82fSFlorian Fainelli } 472967dd82fSFlorian Fainelli 473ff39c2d6SFlorian Fainelli static int b53_fast_age_port(struct b53_device *dev, int port) 474ff39c2d6SFlorian Fainelli { 475ff39c2d6SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_PORT_CTRL, port); 476ff39c2d6SFlorian Fainelli 477ff39c2d6SFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_PORT); 478ff39c2d6SFlorian Fainelli } 479ff39c2d6SFlorian Fainelli 480a2482d2cSFlorian Fainelli static int b53_fast_age_vlan(struct b53_device *dev, u16 vid) 481a2482d2cSFlorian Fainelli { 482a2482d2cSFlorian Fainelli b53_write16(dev, B53_CTRL_PAGE, B53_FAST_AGE_VID_CTRL, vid); 483a2482d2cSFlorian Fainelli 484a2482d2cSFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_VLAN); 485a2482d2cSFlorian Fainelli } 486a2482d2cSFlorian Fainelli 487ff39c2d6SFlorian Fainelli static void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port) 488ff39c2d6SFlorian Fainelli { 48904bed143SVivien Didelot struct b53_device *dev = ds->priv; 490ff39c2d6SFlorian Fainelli unsigned int i; 491ff39c2d6SFlorian Fainelli u16 pvlan; 492ff39c2d6SFlorian Fainelli 493ff39c2d6SFlorian Fainelli /* Enable the IMP port to be in the same VLAN as the other ports 494ff39c2d6SFlorian Fainelli * on a per-port basis such that we only have Port i and IMP in 495ff39c2d6SFlorian Fainelli * the same VLAN. 496ff39c2d6SFlorian Fainelli */ 497ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) { 498ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &pvlan); 499ff39c2d6SFlorian Fainelli pvlan |= BIT(cpu_port); 500ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), pvlan); 501ff39c2d6SFlorian Fainelli } 502ff39c2d6SFlorian Fainelli } 503ff39c2d6SFlorian Fainelli 504967dd82fSFlorian Fainelli static int b53_enable_port(struct dsa_switch *ds, int port, 505967dd82fSFlorian Fainelli struct phy_device *phy) 506967dd82fSFlorian Fainelli { 50704bed143SVivien Didelot struct b53_device *dev = ds->priv; 508ff39c2d6SFlorian Fainelli unsigned int cpu_port = dev->cpu_port; 509ff39c2d6SFlorian Fainelli u16 pvlan; 510967dd82fSFlorian Fainelli 511967dd82fSFlorian Fainelli /* Clear the Rx and Tx disable bits and set to no spanning tree */ 512967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), 0); 513967dd82fSFlorian Fainelli 514ff39c2d6SFlorian Fainelli /* Set this port, and only this one to be in the default VLAN, 515ff39c2d6SFlorian Fainelli * if member of a bridge, restore its membership prior to 516ff39c2d6SFlorian Fainelli * bringing down this port. 517ff39c2d6SFlorian Fainelli */ 518ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); 519ff39c2d6SFlorian Fainelli pvlan &= ~0x1ff; 520ff39c2d6SFlorian Fainelli pvlan |= BIT(port); 521ff39c2d6SFlorian Fainelli pvlan |= dev->ports[port].vlan_ctl_mask; 522ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); 523ff39c2d6SFlorian Fainelli 524ff39c2d6SFlorian Fainelli b53_imp_vlan_setup(ds, cpu_port); 525ff39c2d6SFlorian Fainelli 526967dd82fSFlorian Fainelli return 0; 527967dd82fSFlorian Fainelli } 528967dd82fSFlorian Fainelli 529967dd82fSFlorian Fainelli static void b53_disable_port(struct dsa_switch *ds, int port, 530967dd82fSFlorian Fainelli struct phy_device *phy) 531967dd82fSFlorian Fainelli { 53204bed143SVivien Didelot struct b53_device *dev = ds->priv; 533967dd82fSFlorian Fainelli u8 reg; 534967dd82fSFlorian Fainelli 535967dd82fSFlorian Fainelli /* Disable Tx/Rx for the port */ 536967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), ®); 537967dd82fSFlorian Fainelli reg |= PORT_CTRL_RX_DISABLE | PORT_CTRL_TX_DISABLE; 538967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg); 539967dd82fSFlorian Fainelli } 540967dd82fSFlorian Fainelli 541967dd82fSFlorian Fainelli static void b53_enable_cpu_port(struct b53_device *dev) 542967dd82fSFlorian Fainelli { 543967dd82fSFlorian Fainelli unsigned int cpu_port = dev->cpu_port; 544967dd82fSFlorian Fainelli u8 port_ctrl; 545967dd82fSFlorian Fainelli 546967dd82fSFlorian Fainelli /* BCM5325 CPU port is at 8 */ 547967dd82fSFlorian Fainelli if ((is5325(dev) || is5365(dev)) && cpu_port == B53_CPU_PORT_25) 548967dd82fSFlorian Fainelli cpu_port = B53_CPU_PORT; 549967dd82fSFlorian Fainelli 550967dd82fSFlorian Fainelli port_ctrl = PORT_CTRL_RX_BCST_EN | 551967dd82fSFlorian Fainelli PORT_CTRL_RX_MCST_EN | 552967dd82fSFlorian Fainelli PORT_CTRL_RX_UCST_EN; 553967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(cpu_port), port_ctrl); 554967dd82fSFlorian Fainelli } 555967dd82fSFlorian Fainelli 556967dd82fSFlorian Fainelli static void b53_enable_mib(struct b53_device *dev) 557967dd82fSFlorian Fainelli { 558967dd82fSFlorian Fainelli u8 gc; 559967dd82fSFlorian Fainelli 560967dd82fSFlorian Fainelli b53_read8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc); 561967dd82fSFlorian Fainelli gc &= ~(GC_RESET_MIB | GC_MIB_AC_EN); 562967dd82fSFlorian Fainelli b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc); 563967dd82fSFlorian Fainelli } 564967dd82fSFlorian Fainelli 565967dd82fSFlorian Fainelli static int b53_configure_vlan(struct b53_device *dev) 566967dd82fSFlorian Fainelli { 567a2482d2cSFlorian Fainelli struct b53_vlan vl = { 0 }; 568967dd82fSFlorian Fainelli int i; 569967dd82fSFlorian Fainelli 570967dd82fSFlorian Fainelli /* clear all vlan entries */ 571967dd82fSFlorian Fainelli if (is5325(dev) || is5365(dev)) { 572967dd82fSFlorian Fainelli for (i = 1; i < dev->num_vlans; i++) 573a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, i, &vl); 574967dd82fSFlorian Fainelli } else { 575967dd82fSFlorian Fainelli b53_do_vlan_op(dev, VTA_CMD_CLEAR); 576967dd82fSFlorian Fainelli } 577967dd82fSFlorian Fainelli 578967dd82fSFlorian Fainelli b53_enable_vlan(dev, false); 579967dd82fSFlorian Fainelli 580967dd82fSFlorian Fainelli b53_for_each_port(dev, i) 581967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, 582967dd82fSFlorian Fainelli B53_VLAN_PORT_DEF_TAG(i), 1); 583967dd82fSFlorian Fainelli 584967dd82fSFlorian Fainelli if (!is5325(dev) && !is5365(dev)) 585967dd82fSFlorian Fainelli b53_set_jumbo(dev, dev->enable_jumbo, false); 586967dd82fSFlorian Fainelli 587967dd82fSFlorian Fainelli return 0; 588967dd82fSFlorian Fainelli } 589967dd82fSFlorian Fainelli 590967dd82fSFlorian Fainelli static void b53_switch_reset_gpio(struct b53_device *dev) 591967dd82fSFlorian Fainelli { 592967dd82fSFlorian Fainelli int gpio = dev->reset_gpio; 593967dd82fSFlorian Fainelli 594967dd82fSFlorian Fainelli if (gpio < 0) 595967dd82fSFlorian Fainelli return; 596967dd82fSFlorian Fainelli 597967dd82fSFlorian Fainelli /* Reset sequence: RESET low(50ms)->high(20ms) 598967dd82fSFlorian Fainelli */ 599967dd82fSFlorian Fainelli gpio_set_value(gpio, 0); 600967dd82fSFlorian Fainelli mdelay(50); 601967dd82fSFlorian Fainelli 602967dd82fSFlorian Fainelli gpio_set_value(gpio, 1); 603967dd82fSFlorian Fainelli mdelay(20); 604967dd82fSFlorian Fainelli 605967dd82fSFlorian Fainelli dev->current_page = 0xff; 606967dd82fSFlorian Fainelli } 607967dd82fSFlorian Fainelli 608967dd82fSFlorian Fainelli static int b53_switch_reset(struct b53_device *dev) 609967dd82fSFlorian Fainelli { 6103fb22b05SFlorian Fainelli unsigned int timeout = 1000; 6113fb22b05SFlorian Fainelli u8 mgmt, reg; 612967dd82fSFlorian Fainelli 613967dd82fSFlorian Fainelli b53_switch_reset_gpio(dev); 614967dd82fSFlorian Fainelli 615967dd82fSFlorian Fainelli if (is539x(dev)) { 616967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x83); 617967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x00); 618967dd82fSFlorian Fainelli } 619967dd82fSFlorian Fainelli 6203fb22b05SFlorian Fainelli /* This is specific to 58xx devices here, do not use is58xx() which 6213fb22b05SFlorian Fainelli * covers the larger Starfigther 2 family, including 7445/7278 which 6223fb22b05SFlorian Fainelli * still use this driver as a library and need to perform the reset 6233fb22b05SFlorian Fainelli * earlier. 6243fb22b05SFlorian Fainelli */ 6253fb22b05SFlorian Fainelli if (dev->chip_id == BCM58XX_DEVICE_ID) { 6263fb22b05SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, ®); 6273fb22b05SFlorian Fainelli reg |= SW_RST | EN_SW_RST | EN_CH_RST; 6283fb22b05SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, reg); 6293fb22b05SFlorian Fainelli 6303fb22b05SFlorian Fainelli do { 6313fb22b05SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, ®); 6323fb22b05SFlorian Fainelli if (!(reg & SW_RST)) 6333fb22b05SFlorian Fainelli break; 6343fb22b05SFlorian Fainelli 6353fb22b05SFlorian Fainelli usleep_range(1000, 2000); 6363fb22b05SFlorian Fainelli } while (timeout-- > 0); 6373fb22b05SFlorian Fainelli 6383fb22b05SFlorian Fainelli if (timeout == 0) 6393fb22b05SFlorian Fainelli return -ETIMEDOUT; 6403fb22b05SFlorian Fainelli } 6413fb22b05SFlorian Fainelli 642967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); 643967dd82fSFlorian Fainelli 644967dd82fSFlorian Fainelli if (!(mgmt & SM_SW_FWD_EN)) { 645967dd82fSFlorian Fainelli mgmt &= ~SM_SW_FWD_MODE; 646967dd82fSFlorian Fainelli mgmt |= SM_SW_FWD_EN; 647967dd82fSFlorian Fainelli 648967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt); 649967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt); 650967dd82fSFlorian Fainelli 651967dd82fSFlorian Fainelli if (!(mgmt & SM_SW_FWD_EN)) { 652967dd82fSFlorian Fainelli dev_err(dev->dev, "Failed to enable switch!\n"); 653967dd82fSFlorian Fainelli return -EINVAL; 654967dd82fSFlorian Fainelli } 655967dd82fSFlorian Fainelli } 656967dd82fSFlorian Fainelli 657967dd82fSFlorian Fainelli b53_enable_mib(dev); 658967dd82fSFlorian Fainelli 659ff39c2d6SFlorian Fainelli return b53_flush_arl(dev, FAST_AGE_STATIC); 660967dd82fSFlorian Fainelli } 661967dd82fSFlorian Fainelli 662967dd82fSFlorian Fainelli static int b53_phy_read16(struct dsa_switch *ds, int addr, int reg) 663967dd82fSFlorian Fainelli { 66404bed143SVivien Didelot struct b53_device *priv = ds->priv; 665967dd82fSFlorian Fainelli u16 value = 0; 666967dd82fSFlorian Fainelli int ret; 667967dd82fSFlorian Fainelli 668967dd82fSFlorian Fainelli if (priv->ops->phy_read16) 669967dd82fSFlorian Fainelli ret = priv->ops->phy_read16(priv, addr, reg, &value); 670967dd82fSFlorian Fainelli else 671967dd82fSFlorian Fainelli ret = b53_read16(priv, B53_PORT_MII_PAGE(addr), 672967dd82fSFlorian Fainelli reg * 2, &value); 673967dd82fSFlorian Fainelli 674967dd82fSFlorian Fainelli return ret ? ret : value; 675967dd82fSFlorian Fainelli } 676967dd82fSFlorian Fainelli 677967dd82fSFlorian Fainelli static int b53_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val) 678967dd82fSFlorian Fainelli { 67904bed143SVivien Didelot struct b53_device *priv = ds->priv; 680967dd82fSFlorian Fainelli 681967dd82fSFlorian Fainelli if (priv->ops->phy_write16) 682967dd82fSFlorian Fainelli return priv->ops->phy_write16(priv, addr, reg, val); 683967dd82fSFlorian Fainelli 684967dd82fSFlorian Fainelli return b53_write16(priv, B53_PORT_MII_PAGE(addr), reg * 2, val); 685967dd82fSFlorian Fainelli } 686967dd82fSFlorian Fainelli 687967dd82fSFlorian Fainelli static int b53_reset_switch(struct b53_device *priv) 688967dd82fSFlorian Fainelli { 689967dd82fSFlorian Fainelli /* reset vlans */ 690967dd82fSFlorian Fainelli priv->enable_jumbo = false; 691967dd82fSFlorian Fainelli 692a2482d2cSFlorian Fainelli memset(priv->vlans, 0, sizeof(*priv->vlans) * priv->num_vlans); 693967dd82fSFlorian Fainelli memset(priv->ports, 0, sizeof(*priv->ports) * priv->num_ports); 694967dd82fSFlorian Fainelli 695967dd82fSFlorian Fainelli return b53_switch_reset(priv); 696967dd82fSFlorian Fainelli } 697967dd82fSFlorian Fainelli 698967dd82fSFlorian Fainelli static int b53_apply_config(struct b53_device *priv) 699967dd82fSFlorian Fainelli { 700967dd82fSFlorian Fainelli /* disable switching */ 701967dd82fSFlorian Fainelli b53_set_forwarding(priv, 0); 702967dd82fSFlorian Fainelli 703967dd82fSFlorian Fainelli b53_configure_vlan(priv); 704967dd82fSFlorian Fainelli 705967dd82fSFlorian Fainelli /* enable switching */ 706967dd82fSFlorian Fainelli b53_set_forwarding(priv, 1); 707967dd82fSFlorian Fainelli 708967dd82fSFlorian Fainelli return 0; 709967dd82fSFlorian Fainelli } 710967dd82fSFlorian Fainelli 711967dd82fSFlorian Fainelli static void b53_reset_mib(struct b53_device *priv) 712967dd82fSFlorian Fainelli { 713967dd82fSFlorian Fainelli u8 gc; 714967dd82fSFlorian Fainelli 715967dd82fSFlorian Fainelli b53_read8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc); 716967dd82fSFlorian Fainelli 717967dd82fSFlorian Fainelli b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc | GC_RESET_MIB); 718967dd82fSFlorian Fainelli msleep(1); 719967dd82fSFlorian Fainelli b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc & ~GC_RESET_MIB); 720967dd82fSFlorian Fainelli msleep(1); 721967dd82fSFlorian Fainelli } 722967dd82fSFlorian Fainelli 723967dd82fSFlorian Fainelli static const struct b53_mib_desc *b53_get_mib(struct b53_device *dev) 724967dd82fSFlorian Fainelli { 725967dd82fSFlorian Fainelli if (is5365(dev)) 726967dd82fSFlorian Fainelli return b53_mibs_65; 727967dd82fSFlorian Fainelli else if (is63xx(dev)) 728967dd82fSFlorian Fainelli return b53_mibs_63xx; 729bde5d132SFlorian Fainelli else if (is58xx(dev)) 730bde5d132SFlorian Fainelli return b53_mibs_58xx; 731967dd82fSFlorian Fainelli else 732967dd82fSFlorian Fainelli return b53_mibs; 733967dd82fSFlorian Fainelli } 734967dd82fSFlorian Fainelli 735967dd82fSFlorian Fainelli static unsigned int b53_get_mib_size(struct b53_device *dev) 736967dd82fSFlorian Fainelli { 737967dd82fSFlorian Fainelli if (is5365(dev)) 738967dd82fSFlorian Fainelli return B53_MIBS_65_SIZE; 739967dd82fSFlorian Fainelli else if (is63xx(dev)) 740967dd82fSFlorian Fainelli return B53_MIBS_63XX_SIZE; 741bde5d132SFlorian Fainelli else if (is58xx(dev)) 742bde5d132SFlorian Fainelli return B53_MIBS_58XX_SIZE; 743967dd82fSFlorian Fainelli else 744967dd82fSFlorian Fainelli return B53_MIBS_SIZE; 745967dd82fSFlorian Fainelli } 746967dd82fSFlorian Fainelli 7473117455dSFlorian Fainelli void b53_get_strings(struct dsa_switch *ds, int port, uint8_t *data) 748967dd82fSFlorian Fainelli { 74904bed143SVivien Didelot struct b53_device *dev = ds->priv; 750967dd82fSFlorian Fainelli const struct b53_mib_desc *mibs = b53_get_mib(dev); 751967dd82fSFlorian Fainelli unsigned int mib_size = b53_get_mib_size(dev); 752967dd82fSFlorian Fainelli unsigned int i; 753967dd82fSFlorian Fainelli 754967dd82fSFlorian Fainelli for (i = 0; i < mib_size; i++) 755967dd82fSFlorian Fainelli memcpy(data + i * ETH_GSTRING_LEN, 756967dd82fSFlorian Fainelli mibs[i].name, ETH_GSTRING_LEN); 757967dd82fSFlorian Fainelli } 7583117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_strings); 759967dd82fSFlorian Fainelli 7603117455dSFlorian Fainelli void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data) 761967dd82fSFlorian Fainelli { 76204bed143SVivien Didelot struct b53_device *dev = ds->priv; 763967dd82fSFlorian Fainelli const struct b53_mib_desc *mibs = b53_get_mib(dev); 764967dd82fSFlorian Fainelli unsigned int mib_size = b53_get_mib_size(dev); 765967dd82fSFlorian Fainelli const struct b53_mib_desc *s; 766967dd82fSFlorian Fainelli unsigned int i; 767967dd82fSFlorian Fainelli u64 val = 0; 768967dd82fSFlorian Fainelli 769967dd82fSFlorian Fainelli if (is5365(dev) && port == 5) 770967dd82fSFlorian Fainelli port = 8; 771967dd82fSFlorian Fainelli 772967dd82fSFlorian Fainelli mutex_lock(&dev->stats_mutex); 773967dd82fSFlorian Fainelli 774967dd82fSFlorian Fainelli for (i = 0; i < mib_size; i++) { 775967dd82fSFlorian Fainelli s = &mibs[i]; 776967dd82fSFlorian Fainelli 77751dca8a1SFlorian Fainelli if (s->size == 8) { 778967dd82fSFlorian Fainelli b53_read64(dev, B53_MIB_PAGE(port), s->offset, &val); 779967dd82fSFlorian Fainelli } else { 780967dd82fSFlorian Fainelli u32 val32; 781967dd82fSFlorian Fainelli 782967dd82fSFlorian Fainelli b53_read32(dev, B53_MIB_PAGE(port), s->offset, 783967dd82fSFlorian Fainelli &val32); 784967dd82fSFlorian Fainelli val = val32; 785967dd82fSFlorian Fainelli } 786967dd82fSFlorian Fainelli data[i] = (u64)val; 787967dd82fSFlorian Fainelli } 788967dd82fSFlorian Fainelli 789967dd82fSFlorian Fainelli mutex_unlock(&dev->stats_mutex); 790967dd82fSFlorian Fainelli } 7913117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_ethtool_stats); 792967dd82fSFlorian Fainelli 7933117455dSFlorian Fainelli int b53_get_sset_count(struct dsa_switch *ds) 794967dd82fSFlorian Fainelli { 79504bed143SVivien Didelot struct b53_device *dev = ds->priv; 796967dd82fSFlorian Fainelli 797967dd82fSFlorian Fainelli return b53_get_mib_size(dev); 798967dd82fSFlorian Fainelli } 7993117455dSFlorian Fainelli EXPORT_SYMBOL(b53_get_sset_count); 800967dd82fSFlorian Fainelli 801967dd82fSFlorian Fainelli static int b53_setup(struct dsa_switch *ds) 802967dd82fSFlorian Fainelli { 80304bed143SVivien Didelot struct b53_device *dev = ds->priv; 804967dd82fSFlorian Fainelli unsigned int port; 805967dd82fSFlorian Fainelli int ret; 806967dd82fSFlorian Fainelli 807967dd82fSFlorian Fainelli ret = b53_reset_switch(dev); 808967dd82fSFlorian Fainelli if (ret) { 809967dd82fSFlorian Fainelli dev_err(ds->dev, "failed to reset switch\n"); 810967dd82fSFlorian Fainelli return ret; 811967dd82fSFlorian Fainelli } 812967dd82fSFlorian Fainelli 813967dd82fSFlorian Fainelli b53_reset_mib(dev); 814967dd82fSFlorian Fainelli 815967dd82fSFlorian Fainelli ret = b53_apply_config(dev); 816967dd82fSFlorian Fainelli if (ret) 817967dd82fSFlorian Fainelli dev_err(ds->dev, "failed to apply configuration\n"); 818967dd82fSFlorian Fainelli 819967dd82fSFlorian Fainelli for (port = 0; port < dev->num_ports; port++) { 820967dd82fSFlorian Fainelli if (BIT(port) & ds->enabled_port_mask) 821967dd82fSFlorian Fainelli b53_enable_port(ds, port, NULL); 822967dd82fSFlorian Fainelli else if (dsa_is_cpu_port(ds, port)) 823967dd82fSFlorian Fainelli b53_enable_cpu_port(dev); 824967dd82fSFlorian Fainelli else 825967dd82fSFlorian Fainelli b53_disable_port(ds, port, NULL); 826967dd82fSFlorian Fainelli } 827967dd82fSFlorian Fainelli 828967dd82fSFlorian Fainelli return ret; 829967dd82fSFlorian Fainelli } 830967dd82fSFlorian Fainelli 831967dd82fSFlorian Fainelli static void b53_adjust_link(struct dsa_switch *ds, int port, 832967dd82fSFlorian Fainelli struct phy_device *phydev) 833967dd82fSFlorian Fainelli { 83404bed143SVivien Didelot struct b53_device *dev = ds->priv; 835967dd82fSFlorian Fainelli u8 rgmii_ctrl = 0, reg = 0, off; 836967dd82fSFlorian Fainelli 837967dd82fSFlorian Fainelli if (!phy_is_pseudo_fixed_link(phydev)) 838967dd82fSFlorian Fainelli return; 839967dd82fSFlorian Fainelli 840967dd82fSFlorian Fainelli /* Override the port settings */ 841967dd82fSFlorian Fainelli if (port == dev->cpu_port) { 842967dd82fSFlorian Fainelli off = B53_PORT_OVERRIDE_CTRL; 843967dd82fSFlorian Fainelli reg = PORT_OVERRIDE_EN; 844967dd82fSFlorian Fainelli } else { 845967dd82fSFlorian Fainelli off = B53_GMII_PORT_OVERRIDE_CTRL(port); 846967dd82fSFlorian Fainelli reg = GMII_PO_EN; 847967dd82fSFlorian Fainelli } 848967dd82fSFlorian Fainelli 849967dd82fSFlorian Fainelli /* Set the link UP */ 850967dd82fSFlorian Fainelli if (phydev->link) 851967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_LINK; 852967dd82fSFlorian Fainelli 853967dd82fSFlorian Fainelli if (phydev->duplex == DUPLEX_FULL) 854967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_FULL_DUPLEX; 855967dd82fSFlorian Fainelli 856967dd82fSFlorian Fainelli switch (phydev->speed) { 857967dd82fSFlorian Fainelli case 2000: 858967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_2000M; 859967dd82fSFlorian Fainelli /* fallthrough */ 860967dd82fSFlorian Fainelli case SPEED_1000: 861967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_1000M; 862967dd82fSFlorian Fainelli break; 863967dd82fSFlorian Fainelli case SPEED_100: 864967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_100M; 865967dd82fSFlorian Fainelli break; 866967dd82fSFlorian Fainelli case SPEED_10: 867967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_SPEED_10M; 868967dd82fSFlorian Fainelli break; 869967dd82fSFlorian Fainelli default: 870967dd82fSFlorian Fainelli dev_err(ds->dev, "unknown speed: %d\n", phydev->speed); 871967dd82fSFlorian Fainelli return; 872967dd82fSFlorian Fainelli } 873967dd82fSFlorian Fainelli 874967dd82fSFlorian Fainelli /* Enable flow control on BCM5301x's CPU port */ 875967dd82fSFlorian Fainelli if (is5301x(dev) && port == dev->cpu_port) 876967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_RX_FLOW | PORT_OVERRIDE_TX_FLOW; 877967dd82fSFlorian Fainelli 878967dd82fSFlorian Fainelli if (phydev->pause) { 879967dd82fSFlorian Fainelli if (phydev->asym_pause) 880967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_TX_FLOW; 881967dd82fSFlorian Fainelli reg |= PORT_OVERRIDE_RX_FLOW; 882967dd82fSFlorian Fainelli } 883967dd82fSFlorian Fainelli 884967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, off, reg); 885967dd82fSFlorian Fainelli 886967dd82fSFlorian Fainelli if (is531x5(dev) && phy_interface_is_rgmii(phydev)) { 887967dd82fSFlorian Fainelli if (port == 8) 888967dd82fSFlorian Fainelli off = B53_RGMII_CTRL_IMP; 889967dd82fSFlorian Fainelli else 890967dd82fSFlorian Fainelli off = B53_RGMII_CTRL_P(port); 891967dd82fSFlorian Fainelli 892967dd82fSFlorian Fainelli /* Configure the port RGMII clock delay by DLL disabled and 893967dd82fSFlorian Fainelli * tx_clk aligned timing (restoring to reset defaults) 894967dd82fSFlorian Fainelli */ 895967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, off, &rgmii_ctrl); 896967dd82fSFlorian Fainelli rgmii_ctrl &= ~(RGMII_CTRL_DLL_RXC | RGMII_CTRL_DLL_TXC | 897967dd82fSFlorian Fainelli RGMII_CTRL_TIMING_SEL); 898967dd82fSFlorian Fainelli 899967dd82fSFlorian Fainelli /* PHY_INTERFACE_MODE_RGMII_TXID means TX internal delay, make 900967dd82fSFlorian Fainelli * sure that we enable the port TX clock internal delay to 901967dd82fSFlorian Fainelli * account for this internal delay that is inserted, otherwise 902967dd82fSFlorian Fainelli * the switch won't be able to receive correctly. 903967dd82fSFlorian Fainelli * 904967dd82fSFlorian Fainelli * PHY_INTERFACE_MODE_RGMII means that we are not introducing 905967dd82fSFlorian Fainelli * any delay neither on transmission nor reception, so the 906967dd82fSFlorian Fainelli * BCM53125 must also be configured accordingly to account for 907967dd82fSFlorian Fainelli * the lack of delay and introduce 908967dd82fSFlorian Fainelli * 909967dd82fSFlorian Fainelli * The BCM53125 switch has its RX clock and TX clock control 910967dd82fSFlorian Fainelli * swapped, hence the reason why we modify the TX clock path in 911967dd82fSFlorian Fainelli * the "RGMII" case 912967dd82fSFlorian Fainelli */ 913967dd82fSFlorian Fainelli if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) 914967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_DLL_TXC; 915967dd82fSFlorian Fainelli if (phydev->interface == PHY_INTERFACE_MODE_RGMII) 916967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_DLL_TXC | RGMII_CTRL_DLL_RXC; 917967dd82fSFlorian Fainelli rgmii_ctrl |= RGMII_CTRL_TIMING_SEL; 918967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, off, rgmii_ctrl); 919967dd82fSFlorian Fainelli 920967dd82fSFlorian Fainelli dev_info(ds->dev, "Configured port %d for %s\n", port, 921967dd82fSFlorian Fainelli phy_modes(phydev->interface)); 922967dd82fSFlorian Fainelli } 923967dd82fSFlorian Fainelli 924967dd82fSFlorian Fainelli /* configure MII port if necessary */ 925967dd82fSFlorian Fainelli if (is5325(dev)) { 926967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, 927967dd82fSFlorian Fainelli ®); 928967dd82fSFlorian Fainelli 929967dd82fSFlorian Fainelli /* reverse mii needs to be enabled */ 930967dd82fSFlorian Fainelli if (!(reg & PORT_OVERRIDE_RV_MII_25)) { 931967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, 932967dd82fSFlorian Fainelli reg | PORT_OVERRIDE_RV_MII_25); 933967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, 934967dd82fSFlorian Fainelli ®); 935967dd82fSFlorian Fainelli 936967dd82fSFlorian Fainelli if (!(reg & PORT_OVERRIDE_RV_MII_25)) { 937967dd82fSFlorian Fainelli dev_err(ds->dev, 938967dd82fSFlorian Fainelli "Failed to enable reverse MII mode\n"); 939967dd82fSFlorian Fainelli return; 940967dd82fSFlorian Fainelli } 941967dd82fSFlorian Fainelli } 942967dd82fSFlorian Fainelli } else if (is5301x(dev)) { 943967dd82fSFlorian Fainelli if (port != dev->cpu_port) { 944967dd82fSFlorian Fainelli u8 po_reg = B53_GMII_PORT_OVERRIDE_CTRL(dev->cpu_port); 945967dd82fSFlorian Fainelli u8 gmii_po; 946967dd82fSFlorian Fainelli 947967dd82fSFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, po_reg, &gmii_po); 948967dd82fSFlorian Fainelli gmii_po |= GMII_PO_LINK | 949967dd82fSFlorian Fainelli GMII_PO_RX_FLOW | 950967dd82fSFlorian Fainelli GMII_PO_TX_FLOW | 951967dd82fSFlorian Fainelli GMII_PO_EN | 952967dd82fSFlorian Fainelli GMII_PO_SPEED_2000M; 953967dd82fSFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, po_reg, gmii_po); 954967dd82fSFlorian Fainelli } 955967dd82fSFlorian Fainelli } 956967dd82fSFlorian Fainelli } 957967dd82fSFlorian Fainelli 9583117455dSFlorian Fainelli int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering) 959a2482d2cSFlorian Fainelli { 960a2482d2cSFlorian Fainelli return 0; 961a2482d2cSFlorian Fainelli } 9623117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_filtering); 963a2482d2cSFlorian Fainelli 9643117455dSFlorian Fainelli int b53_vlan_prepare(struct dsa_switch *ds, int port, 965a2482d2cSFlorian Fainelli const struct switchdev_obj_port_vlan *vlan, 966a2482d2cSFlorian Fainelli struct switchdev_trans *trans) 967a2482d2cSFlorian Fainelli { 96804bed143SVivien Didelot struct b53_device *dev = ds->priv; 969a2482d2cSFlorian Fainelli 970a2482d2cSFlorian Fainelli if ((is5325(dev) || is5365(dev)) && vlan->vid_begin == 0) 971a2482d2cSFlorian Fainelli return -EOPNOTSUPP; 972a2482d2cSFlorian Fainelli 973a2482d2cSFlorian Fainelli if (vlan->vid_end > dev->num_vlans) 974a2482d2cSFlorian Fainelli return -ERANGE; 975a2482d2cSFlorian Fainelli 976a2482d2cSFlorian Fainelli b53_enable_vlan(dev, true); 977a2482d2cSFlorian Fainelli 978a2482d2cSFlorian Fainelli return 0; 979a2482d2cSFlorian Fainelli } 9803117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_prepare); 981a2482d2cSFlorian Fainelli 9823117455dSFlorian Fainelli void b53_vlan_add(struct dsa_switch *ds, int port, 983a2482d2cSFlorian Fainelli const struct switchdev_obj_port_vlan *vlan, 984a2482d2cSFlorian Fainelli struct switchdev_trans *trans) 985a2482d2cSFlorian Fainelli { 98604bed143SVivien Didelot struct b53_device *dev = ds->priv; 987a2482d2cSFlorian Fainelli bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; 988a2482d2cSFlorian Fainelli bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID; 989a2482d2cSFlorian Fainelli unsigned int cpu_port = dev->cpu_port; 990a2482d2cSFlorian Fainelli struct b53_vlan *vl; 991a2482d2cSFlorian Fainelli u16 vid; 992a2482d2cSFlorian Fainelli 993a2482d2cSFlorian Fainelli for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) { 994a2482d2cSFlorian Fainelli vl = &dev->vlans[vid]; 995a2482d2cSFlorian Fainelli 996a2482d2cSFlorian Fainelli b53_get_vlan_entry(dev, vid, vl); 997a2482d2cSFlorian Fainelli 998a2482d2cSFlorian Fainelli vl->members |= BIT(port) | BIT(cpu_port); 999a2482d2cSFlorian Fainelli if (untagged) 1000e47112d9SFlorian Fainelli vl->untag |= BIT(port); 1001a2482d2cSFlorian Fainelli else 1002e47112d9SFlorian Fainelli vl->untag &= ~BIT(port); 1003e47112d9SFlorian Fainelli vl->untag &= ~BIT(cpu_port); 1004a2482d2cSFlorian Fainelli 1005a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, vid, vl); 1006a2482d2cSFlorian Fainelli b53_fast_age_vlan(dev, vid); 1007a2482d2cSFlorian Fainelli } 1008a2482d2cSFlorian Fainelli 1009a2482d2cSFlorian Fainelli if (pvid) { 1010a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), 1011a2482d2cSFlorian Fainelli vlan->vid_end); 1012a2482d2cSFlorian Fainelli b53_fast_age_vlan(dev, vid); 1013a2482d2cSFlorian Fainelli } 1014a2482d2cSFlorian Fainelli } 10153117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_add); 1016a2482d2cSFlorian Fainelli 10173117455dSFlorian Fainelli int b53_vlan_del(struct dsa_switch *ds, int port, 1018a2482d2cSFlorian Fainelli const struct switchdev_obj_port_vlan *vlan) 1019a2482d2cSFlorian Fainelli { 102004bed143SVivien Didelot struct b53_device *dev = ds->priv; 1021a2482d2cSFlorian Fainelli bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; 1022a2482d2cSFlorian Fainelli struct b53_vlan *vl; 1023a2482d2cSFlorian Fainelli u16 vid; 1024a2482d2cSFlorian Fainelli u16 pvid; 1025a2482d2cSFlorian Fainelli 1026a2482d2cSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid); 1027a2482d2cSFlorian Fainelli 1028a2482d2cSFlorian Fainelli for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) { 1029a2482d2cSFlorian Fainelli vl = &dev->vlans[vid]; 1030a2482d2cSFlorian Fainelli 1031a2482d2cSFlorian Fainelli b53_get_vlan_entry(dev, vid, vl); 1032a2482d2cSFlorian Fainelli 1033a2482d2cSFlorian Fainelli vl->members &= ~BIT(port); 1034a2482d2cSFlorian Fainelli 1035a2482d2cSFlorian Fainelli if (pvid == vid) { 1036a2482d2cSFlorian Fainelli if (is5325(dev) || is5365(dev)) 1037a2482d2cSFlorian Fainelli pvid = 1; 1038a2482d2cSFlorian Fainelli else 1039a2482d2cSFlorian Fainelli pvid = 0; 1040a2482d2cSFlorian Fainelli } 1041a2482d2cSFlorian Fainelli 1042e47112d9SFlorian Fainelli if (untagged) 1043a2482d2cSFlorian Fainelli vl->untag &= ~(BIT(port)); 1044a2482d2cSFlorian Fainelli 1045a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, vid, vl); 1046a2482d2cSFlorian Fainelli b53_fast_age_vlan(dev, vid); 1047a2482d2cSFlorian Fainelli } 1048a2482d2cSFlorian Fainelli 1049a2482d2cSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), pvid); 1050a2482d2cSFlorian Fainelli b53_fast_age_vlan(dev, pvid); 1051a2482d2cSFlorian Fainelli 1052a2482d2cSFlorian Fainelli return 0; 1053a2482d2cSFlorian Fainelli } 10543117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_del); 1055a2482d2cSFlorian Fainelli 10563117455dSFlorian Fainelli int b53_vlan_dump(struct dsa_switch *ds, int port, 1057a2482d2cSFlorian Fainelli struct switchdev_obj_port_vlan *vlan, 1058438ff537SVivien Didelot switchdev_obj_dump_cb_t *cb) 1059a2482d2cSFlorian Fainelli { 106004bed143SVivien Didelot struct b53_device *dev = ds->priv; 1061a2482d2cSFlorian Fainelli u16 vid, vid_start = 0, pvid; 1062a2482d2cSFlorian Fainelli struct b53_vlan *vl; 1063a2482d2cSFlorian Fainelli int err = 0; 1064a2482d2cSFlorian Fainelli 1065a2482d2cSFlorian Fainelli if (is5325(dev) || is5365(dev)) 1066a2482d2cSFlorian Fainelli vid_start = 1; 1067a2482d2cSFlorian Fainelli 1068a2482d2cSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid); 1069a2482d2cSFlorian Fainelli 1070a2482d2cSFlorian Fainelli /* Use our software cache for dumps, since we do not have any HW 1071a2482d2cSFlorian Fainelli * operation returning only the used/valid VLANs 1072a2482d2cSFlorian Fainelli */ 1073a2482d2cSFlorian Fainelli for (vid = vid_start; vid < dev->num_vlans; vid++) { 1074a2482d2cSFlorian Fainelli vl = &dev->vlans[vid]; 1075a2482d2cSFlorian Fainelli 1076a2482d2cSFlorian Fainelli if (!vl->valid) 1077a2482d2cSFlorian Fainelli continue; 1078a2482d2cSFlorian Fainelli 1079a2482d2cSFlorian Fainelli if (!(vl->members & BIT(port))) 1080a2482d2cSFlorian Fainelli continue; 1081a2482d2cSFlorian Fainelli 1082a2482d2cSFlorian Fainelli vlan->vid_begin = vlan->vid_end = vid; 1083a2482d2cSFlorian Fainelli vlan->flags = 0; 1084a2482d2cSFlorian Fainelli 1085a2482d2cSFlorian Fainelli if (vl->untag & BIT(port)) 1086a2482d2cSFlorian Fainelli vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED; 1087a2482d2cSFlorian Fainelli if (pvid == vid) 1088a2482d2cSFlorian Fainelli vlan->flags |= BRIDGE_VLAN_INFO_PVID; 1089a2482d2cSFlorian Fainelli 1090a2482d2cSFlorian Fainelli err = cb(&vlan->obj); 1091a2482d2cSFlorian Fainelli if (err) 1092a2482d2cSFlorian Fainelli break; 1093a2482d2cSFlorian Fainelli } 1094a2482d2cSFlorian Fainelli 1095a2482d2cSFlorian Fainelli return err; 1096a2482d2cSFlorian Fainelli } 10973117455dSFlorian Fainelli EXPORT_SYMBOL(b53_vlan_dump); 1098a2482d2cSFlorian Fainelli 10991da6df85SFlorian Fainelli /* Address Resolution Logic routines */ 11001da6df85SFlorian Fainelli static int b53_arl_op_wait(struct b53_device *dev) 11011da6df85SFlorian Fainelli { 11021da6df85SFlorian Fainelli unsigned int timeout = 10; 11031da6df85SFlorian Fainelli u8 reg; 11041da6df85SFlorian Fainelli 11051da6df85SFlorian Fainelli do { 11061da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, ®); 11071da6df85SFlorian Fainelli if (!(reg & ARLTBL_START_DONE)) 11081da6df85SFlorian Fainelli return 0; 11091da6df85SFlorian Fainelli 11101da6df85SFlorian Fainelli usleep_range(1000, 2000); 11111da6df85SFlorian Fainelli } while (timeout--); 11121da6df85SFlorian Fainelli 11131da6df85SFlorian Fainelli dev_warn(dev->dev, "timeout waiting for ARL to finish: 0x%02x\n", reg); 11141da6df85SFlorian Fainelli 11151da6df85SFlorian Fainelli return -ETIMEDOUT; 11161da6df85SFlorian Fainelli } 11171da6df85SFlorian Fainelli 11181da6df85SFlorian Fainelli static int b53_arl_rw_op(struct b53_device *dev, unsigned int op) 11191da6df85SFlorian Fainelli { 11201da6df85SFlorian Fainelli u8 reg; 11211da6df85SFlorian Fainelli 11221da6df85SFlorian Fainelli if (op > ARLTBL_RW) 11231da6df85SFlorian Fainelli return -EINVAL; 11241da6df85SFlorian Fainelli 11251da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, ®); 11261da6df85SFlorian Fainelli reg |= ARLTBL_START_DONE; 11271da6df85SFlorian Fainelli if (op) 11281da6df85SFlorian Fainelli reg |= ARLTBL_RW; 11291da6df85SFlorian Fainelli else 11301da6df85SFlorian Fainelli reg &= ~ARLTBL_RW; 11311da6df85SFlorian Fainelli b53_write8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, reg); 11321da6df85SFlorian Fainelli 11331da6df85SFlorian Fainelli return b53_arl_op_wait(dev); 11341da6df85SFlorian Fainelli } 11351da6df85SFlorian Fainelli 11361da6df85SFlorian Fainelli static int b53_arl_read(struct b53_device *dev, u64 mac, 11371da6df85SFlorian Fainelli u16 vid, struct b53_arl_entry *ent, u8 *idx, 11381da6df85SFlorian Fainelli bool is_valid) 11391da6df85SFlorian Fainelli { 11401da6df85SFlorian Fainelli unsigned int i; 11411da6df85SFlorian Fainelli int ret; 11421da6df85SFlorian Fainelli 11431da6df85SFlorian Fainelli ret = b53_arl_op_wait(dev); 11441da6df85SFlorian Fainelli if (ret) 11451da6df85SFlorian Fainelli return ret; 11461da6df85SFlorian Fainelli 11471da6df85SFlorian Fainelli /* Read the bins */ 11481da6df85SFlorian Fainelli for (i = 0; i < dev->num_arl_entries; i++) { 11491da6df85SFlorian Fainelli u64 mac_vid; 11501da6df85SFlorian Fainelli u32 fwd_entry; 11511da6df85SFlorian Fainelli 11521da6df85SFlorian Fainelli b53_read64(dev, B53_ARLIO_PAGE, 11531da6df85SFlorian Fainelli B53_ARLTBL_MAC_VID_ENTRY(i), &mac_vid); 11541da6df85SFlorian Fainelli b53_read32(dev, B53_ARLIO_PAGE, 11551da6df85SFlorian Fainelli B53_ARLTBL_DATA_ENTRY(i), &fwd_entry); 11561da6df85SFlorian Fainelli b53_arl_to_entry(ent, mac_vid, fwd_entry); 11571da6df85SFlorian Fainelli 11581da6df85SFlorian Fainelli if (!(fwd_entry & ARLTBL_VALID)) 11591da6df85SFlorian Fainelli continue; 11601da6df85SFlorian Fainelli if ((mac_vid & ARLTBL_MAC_MASK) != mac) 11611da6df85SFlorian Fainelli continue; 11621da6df85SFlorian Fainelli *idx = i; 11631da6df85SFlorian Fainelli } 11641da6df85SFlorian Fainelli 11651da6df85SFlorian Fainelli return -ENOENT; 11661da6df85SFlorian Fainelli } 11671da6df85SFlorian Fainelli 11681da6df85SFlorian Fainelli static int b53_arl_op(struct b53_device *dev, int op, int port, 11691da6df85SFlorian Fainelli const unsigned char *addr, u16 vid, bool is_valid) 11701da6df85SFlorian Fainelli { 11711da6df85SFlorian Fainelli struct b53_arl_entry ent; 11721da6df85SFlorian Fainelli u32 fwd_entry; 11731da6df85SFlorian Fainelli u64 mac, mac_vid = 0; 11741da6df85SFlorian Fainelli u8 idx = 0; 11751da6df85SFlorian Fainelli int ret; 11761da6df85SFlorian Fainelli 11771da6df85SFlorian Fainelli /* Convert the array into a 64-bit MAC */ 11784b92ea81SFlorian Fainelli mac = ether_addr_to_u64(addr); 11791da6df85SFlorian Fainelli 11801da6df85SFlorian Fainelli /* Perform a read for the given MAC and VID */ 11811da6df85SFlorian Fainelli b53_write48(dev, B53_ARLIO_PAGE, B53_MAC_ADDR_IDX, mac); 11821da6df85SFlorian Fainelli b53_write16(dev, B53_ARLIO_PAGE, B53_VLAN_ID_IDX, vid); 11831da6df85SFlorian Fainelli 11841da6df85SFlorian Fainelli /* Issue a read operation for this MAC */ 11851da6df85SFlorian Fainelli ret = b53_arl_rw_op(dev, 1); 11861da6df85SFlorian Fainelli if (ret) 11871da6df85SFlorian Fainelli return ret; 11881da6df85SFlorian Fainelli 11891da6df85SFlorian Fainelli ret = b53_arl_read(dev, mac, vid, &ent, &idx, is_valid); 11901da6df85SFlorian Fainelli /* If this is a read, just finish now */ 11911da6df85SFlorian Fainelli if (op) 11921da6df85SFlorian Fainelli return ret; 11931da6df85SFlorian Fainelli 11941da6df85SFlorian Fainelli /* We could not find a matching MAC, so reset to a new entry */ 11951da6df85SFlorian Fainelli if (ret) { 11961da6df85SFlorian Fainelli fwd_entry = 0; 11971da6df85SFlorian Fainelli idx = 1; 11981da6df85SFlorian Fainelli } 11991da6df85SFlorian Fainelli 12001da6df85SFlorian Fainelli memset(&ent, 0, sizeof(ent)); 12011da6df85SFlorian Fainelli ent.port = port; 12021da6df85SFlorian Fainelli ent.is_valid = is_valid; 12031da6df85SFlorian Fainelli ent.vid = vid; 12041da6df85SFlorian Fainelli ent.is_static = true; 12051da6df85SFlorian Fainelli memcpy(ent.mac, addr, ETH_ALEN); 12061da6df85SFlorian Fainelli b53_arl_from_entry(&mac_vid, &fwd_entry, &ent); 12071da6df85SFlorian Fainelli 12081da6df85SFlorian Fainelli b53_write64(dev, B53_ARLIO_PAGE, 12091da6df85SFlorian Fainelli B53_ARLTBL_MAC_VID_ENTRY(idx), mac_vid); 12101da6df85SFlorian Fainelli b53_write32(dev, B53_ARLIO_PAGE, 12111da6df85SFlorian Fainelli B53_ARLTBL_DATA_ENTRY(idx), fwd_entry); 12121da6df85SFlorian Fainelli 12131da6df85SFlorian Fainelli return b53_arl_rw_op(dev, 0); 12141da6df85SFlorian Fainelli } 12151da6df85SFlorian Fainelli 12163117455dSFlorian Fainelli int b53_fdb_prepare(struct dsa_switch *ds, int port, 12171da6df85SFlorian Fainelli const struct switchdev_obj_port_fdb *fdb, 12181da6df85SFlorian Fainelli struct switchdev_trans *trans) 12191da6df85SFlorian Fainelli { 122004bed143SVivien Didelot struct b53_device *priv = ds->priv; 12211da6df85SFlorian Fainelli 12221da6df85SFlorian Fainelli /* 5325 and 5365 require some more massaging, but could 12231da6df85SFlorian Fainelli * be supported eventually 12241da6df85SFlorian Fainelli */ 12251da6df85SFlorian Fainelli if (is5325(priv) || is5365(priv)) 12261da6df85SFlorian Fainelli return -EOPNOTSUPP; 12271da6df85SFlorian Fainelli 12281da6df85SFlorian Fainelli return 0; 12291da6df85SFlorian Fainelli } 12303117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_prepare); 12311da6df85SFlorian Fainelli 12323117455dSFlorian Fainelli void b53_fdb_add(struct dsa_switch *ds, int port, 12331da6df85SFlorian Fainelli const struct switchdev_obj_port_fdb *fdb, 12341da6df85SFlorian Fainelli struct switchdev_trans *trans) 12351da6df85SFlorian Fainelli { 123604bed143SVivien Didelot struct b53_device *priv = ds->priv; 12371da6df85SFlorian Fainelli 12381da6df85SFlorian Fainelli if (b53_arl_op(priv, 0, port, fdb->addr, fdb->vid, true)) 12391da6df85SFlorian Fainelli pr_err("%s: failed to add MAC address\n", __func__); 12401da6df85SFlorian Fainelli } 12413117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_add); 12421da6df85SFlorian Fainelli 12433117455dSFlorian Fainelli int b53_fdb_del(struct dsa_switch *ds, int port, 12441da6df85SFlorian Fainelli const struct switchdev_obj_port_fdb *fdb) 12451da6df85SFlorian Fainelli { 124604bed143SVivien Didelot struct b53_device *priv = ds->priv; 12471da6df85SFlorian Fainelli 12481da6df85SFlorian Fainelli return b53_arl_op(priv, 0, port, fdb->addr, fdb->vid, false); 12491da6df85SFlorian Fainelli } 12503117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_del); 12511da6df85SFlorian Fainelli 12521da6df85SFlorian Fainelli static int b53_arl_search_wait(struct b53_device *dev) 12531da6df85SFlorian Fainelli { 12541da6df85SFlorian Fainelli unsigned int timeout = 1000; 12551da6df85SFlorian Fainelli u8 reg; 12561da6df85SFlorian Fainelli 12571da6df85SFlorian Fainelli do { 12581da6df85SFlorian Fainelli b53_read8(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, ®); 12591da6df85SFlorian Fainelli if (!(reg & ARL_SRCH_STDN)) 12601da6df85SFlorian Fainelli return 0; 12611da6df85SFlorian Fainelli 12621da6df85SFlorian Fainelli if (reg & ARL_SRCH_VLID) 12631da6df85SFlorian Fainelli return 0; 12641da6df85SFlorian Fainelli 12651da6df85SFlorian Fainelli usleep_range(1000, 2000); 12661da6df85SFlorian Fainelli } while (timeout--); 12671da6df85SFlorian Fainelli 12681da6df85SFlorian Fainelli return -ETIMEDOUT; 12691da6df85SFlorian Fainelli } 12701da6df85SFlorian Fainelli 12711da6df85SFlorian Fainelli static void b53_arl_search_rd(struct b53_device *dev, u8 idx, 12721da6df85SFlorian Fainelli struct b53_arl_entry *ent) 12731da6df85SFlorian Fainelli { 12741da6df85SFlorian Fainelli u64 mac_vid; 12751da6df85SFlorian Fainelli u32 fwd_entry; 12761da6df85SFlorian Fainelli 12771da6df85SFlorian Fainelli b53_read64(dev, B53_ARLIO_PAGE, 12781da6df85SFlorian Fainelli B53_ARL_SRCH_RSTL_MACVID(idx), &mac_vid); 12791da6df85SFlorian Fainelli b53_read32(dev, B53_ARLIO_PAGE, 12801da6df85SFlorian Fainelli B53_ARL_SRCH_RSTL(idx), &fwd_entry); 12811da6df85SFlorian Fainelli b53_arl_to_entry(ent, mac_vid, fwd_entry); 12821da6df85SFlorian Fainelli } 12831da6df85SFlorian Fainelli 1284*e6cbef0cSVivien Didelot static int b53_fdb_copy(int port, const struct b53_arl_entry *ent, 12851da6df85SFlorian Fainelli struct switchdev_obj_port_fdb *fdb, 1286438ff537SVivien Didelot switchdev_obj_dump_cb_t *cb) 12871da6df85SFlorian Fainelli { 12881da6df85SFlorian Fainelli if (!ent->is_valid) 12891da6df85SFlorian Fainelli return 0; 12901da6df85SFlorian Fainelli 12911da6df85SFlorian Fainelli if (port != ent->port) 12921da6df85SFlorian Fainelli return 0; 12931da6df85SFlorian Fainelli 12941da6df85SFlorian Fainelli ether_addr_copy(fdb->addr, ent->mac); 12951da6df85SFlorian Fainelli fdb->vid = ent->vid; 12961da6df85SFlorian Fainelli fdb->ndm_state = ent->is_static ? NUD_NOARP : NUD_REACHABLE; 12971da6df85SFlorian Fainelli 12981da6df85SFlorian Fainelli return cb(&fdb->obj); 12991da6df85SFlorian Fainelli } 13001da6df85SFlorian Fainelli 13013117455dSFlorian Fainelli int b53_fdb_dump(struct dsa_switch *ds, int port, 13021da6df85SFlorian Fainelli struct switchdev_obj_port_fdb *fdb, 1303438ff537SVivien Didelot switchdev_obj_dump_cb_t *cb) 13041da6df85SFlorian Fainelli { 130504bed143SVivien Didelot struct b53_device *priv = ds->priv; 13061da6df85SFlorian Fainelli struct b53_arl_entry results[2]; 13071da6df85SFlorian Fainelli unsigned int count = 0; 13081da6df85SFlorian Fainelli int ret; 13091da6df85SFlorian Fainelli u8 reg; 13101da6df85SFlorian Fainelli 13111da6df85SFlorian Fainelli /* Start search operation */ 13121da6df85SFlorian Fainelli reg = ARL_SRCH_STDN; 13131da6df85SFlorian Fainelli b53_write8(priv, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, reg); 13141da6df85SFlorian Fainelli 13151da6df85SFlorian Fainelli do { 13161da6df85SFlorian Fainelli ret = b53_arl_search_wait(priv); 13171da6df85SFlorian Fainelli if (ret) 13181da6df85SFlorian Fainelli return ret; 13191da6df85SFlorian Fainelli 13201da6df85SFlorian Fainelli b53_arl_search_rd(priv, 0, &results[0]); 1321*e6cbef0cSVivien Didelot ret = b53_fdb_copy(port, &results[0], fdb, cb); 13221da6df85SFlorian Fainelli if (ret) 13231da6df85SFlorian Fainelli return ret; 13241da6df85SFlorian Fainelli 13251da6df85SFlorian Fainelli if (priv->num_arl_entries > 2) { 13261da6df85SFlorian Fainelli b53_arl_search_rd(priv, 1, &results[1]); 1327*e6cbef0cSVivien Didelot ret = b53_fdb_copy(port, &results[1], fdb, cb); 13281da6df85SFlorian Fainelli if (ret) 13291da6df85SFlorian Fainelli return ret; 13301da6df85SFlorian Fainelli 13311da6df85SFlorian Fainelli if (!results[0].is_valid && !results[1].is_valid) 13321da6df85SFlorian Fainelli break; 13331da6df85SFlorian Fainelli } 13341da6df85SFlorian Fainelli 13351da6df85SFlorian Fainelli } while (count++ < 1024); 13361da6df85SFlorian Fainelli 13371da6df85SFlorian Fainelli return 0; 13381da6df85SFlorian Fainelli } 13393117455dSFlorian Fainelli EXPORT_SYMBOL(b53_fdb_dump); 13401da6df85SFlorian Fainelli 1341ddd3a0c8SVivien Didelot int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br) 1342ff39c2d6SFlorian Fainelli { 134304bed143SVivien Didelot struct b53_device *dev = ds->priv; 13448b0d3ea5SVivien Didelot s8 cpu_port = ds->dst->cpu_dp->index; 1345ff39c2d6SFlorian Fainelli u16 pvlan, reg; 1346ff39c2d6SFlorian Fainelli unsigned int i; 1347ff39c2d6SFlorian Fainelli 134848aea33aSFlorian Fainelli /* Make this port leave the all VLANs join since we will have proper 134948aea33aSFlorian Fainelli * VLAN entries from now on 135048aea33aSFlorian Fainelli */ 135148aea33aSFlorian Fainelli if (is58xx(dev)) { 135248aea33aSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, ®); 135348aea33aSFlorian Fainelli reg &= ~BIT(port); 135448aea33aSFlorian Fainelli if ((reg & BIT(cpu_port)) == BIT(cpu_port)) 135548aea33aSFlorian Fainelli reg &= ~BIT(cpu_port); 135648aea33aSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg); 135748aea33aSFlorian Fainelli } 135848aea33aSFlorian Fainelli 1359ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); 1360ff39c2d6SFlorian Fainelli 1361ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) { 1362ddd3a0c8SVivien Didelot if (ds->ports[i].bridge_dev != br) 1363ff39c2d6SFlorian Fainelli continue; 1364ff39c2d6SFlorian Fainelli 1365ff39c2d6SFlorian Fainelli /* Add this local port to the remote port VLAN control 1366ff39c2d6SFlorian Fainelli * membership and update the remote port bitmask 1367ff39c2d6SFlorian Fainelli */ 1368ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), ®); 1369ff39c2d6SFlorian Fainelli reg |= BIT(port); 1370ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg); 1371ff39c2d6SFlorian Fainelli dev->ports[i].vlan_ctl_mask = reg; 1372ff39c2d6SFlorian Fainelli 1373ff39c2d6SFlorian Fainelli pvlan |= BIT(i); 1374ff39c2d6SFlorian Fainelli } 1375ff39c2d6SFlorian Fainelli 1376ff39c2d6SFlorian Fainelli /* Configure the local port VLAN control membership to include 1377ff39c2d6SFlorian Fainelli * remote ports and update the local port bitmask 1378ff39c2d6SFlorian Fainelli */ 1379ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); 1380ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = pvlan; 1381ff39c2d6SFlorian Fainelli 1382ff39c2d6SFlorian Fainelli return 0; 1383ff39c2d6SFlorian Fainelli } 13843117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_join); 1385ff39c2d6SFlorian Fainelli 1386f123f2fbSVivien Didelot void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *br) 1387ff39c2d6SFlorian Fainelli { 138804bed143SVivien Didelot struct b53_device *dev = ds->priv; 1389a2482d2cSFlorian Fainelli struct b53_vlan *vl = &dev->vlans[0]; 13908b0d3ea5SVivien Didelot s8 cpu_port = ds->dst->cpu_dp->index; 1391ff39c2d6SFlorian Fainelli unsigned int i; 1392a2482d2cSFlorian Fainelli u16 pvlan, reg, pvid; 1393ff39c2d6SFlorian Fainelli 1394ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); 1395ff39c2d6SFlorian Fainelli 1396ff39c2d6SFlorian Fainelli b53_for_each_port(dev, i) { 1397ff39c2d6SFlorian Fainelli /* Don't touch the remaining ports */ 1398ddd3a0c8SVivien Didelot if (ds->ports[i].bridge_dev != br) 1399ff39c2d6SFlorian Fainelli continue; 1400ff39c2d6SFlorian Fainelli 1401ff39c2d6SFlorian Fainelli b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), ®); 1402ff39c2d6SFlorian Fainelli reg &= ~BIT(port); 1403ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg); 1404ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = reg; 1405ff39c2d6SFlorian Fainelli 1406ff39c2d6SFlorian Fainelli /* Prevent self removal to preserve isolation */ 1407ff39c2d6SFlorian Fainelli if (port != i) 1408ff39c2d6SFlorian Fainelli pvlan &= ~BIT(i); 1409ff39c2d6SFlorian Fainelli } 1410ff39c2d6SFlorian Fainelli 1411ff39c2d6SFlorian Fainelli b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan); 1412ff39c2d6SFlorian Fainelli dev->ports[port].vlan_ctl_mask = pvlan; 1413a2482d2cSFlorian Fainelli 1414a2482d2cSFlorian Fainelli if (is5325(dev) || is5365(dev)) 1415a2482d2cSFlorian Fainelli pvid = 1; 1416a2482d2cSFlorian Fainelli else 1417a2482d2cSFlorian Fainelli pvid = 0; 1418a2482d2cSFlorian Fainelli 141948aea33aSFlorian Fainelli /* Make this port join all VLANs without VLAN entries */ 142048aea33aSFlorian Fainelli if (is58xx(dev)) { 142148aea33aSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, ®); 142248aea33aSFlorian Fainelli reg |= BIT(port); 142348aea33aSFlorian Fainelli if (!(reg & BIT(cpu_port))) 142448aea33aSFlorian Fainelli reg |= BIT(cpu_port); 142548aea33aSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg); 142648aea33aSFlorian Fainelli } else { 1427a2482d2cSFlorian Fainelli b53_get_vlan_entry(dev, pvid, vl); 1428a2482d2cSFlorian Fainelli vl->members |= BIT(port) | BIT(dev->cpu_port); 1429a2482d2cSFlorian Fainelli vl->untag |= BIT(port) | BIT(dev->cpu_port); 1430a2482d2cSFlorian Fainelli b53_set_vlan_entry(dev, pvid, vl); 1431ff39c2d6SFlorian Fainelli } 143248aea33aSFlorian Fainelli } 14333117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_leave); 1434ff39c2d6SFlorian Fainelli 14353117455dSFlorian Fainelli void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state) 1436ff39c2d6SFlorian Fainelli { 143704bed143SVivien Didelot struct b53_device *dev = ds->priv; 1438597698f1SVivien Didelot u8 hw_state; 1439ff39c2d6SFlorian Fainelli u8 reg; 1440ff39c2d6SFlorian Fainelli 1441ff39c2d6SFlorian Fainelli switch (state) { 1442ff39c2d6SFlorian Fainelli case BR_STATE_DISABLED: 1443ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_DIS_STATE; 1444ff39c2d6SFlorian Fainelli break; 1445ff39c2d6SFlorian Fainelli case BR_STATE_LISTENING: 1446ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_LISTEN_STATE; 1447ff39c2d6SFlorian Fainelli break; 1448ff39c2d6SFlorian Fainelli case BR_STATE_LEARNING: 1449ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_LEARN_STATE; 1450ff39c2d6SFlorian Fainelli break; 1451ff39c2d6SFlorian Fainelli case BR_STATE_FORWARDING: 1452ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_FWD_STATE; 1453ff39c2d6SFlorian Fainelli break; 1454ff39c2d6SFlorian Fainelli case BR_STATE_BLOCKING: 1455ff39c2d6SFlorian Fainelli hw_state = PORT_CTRL_BLOCK_STATE; 1456ff39c2d6SFlorian Fainelli break; 1457ff39c2d6SFlorian Fainelli default: 1458ff39c2d6SFlorian Fainelli dev_err(ds->dev, "invalid STP state: %d\n", state); 1459ff39c2d6SFlorian Fainelli return; 1460ff39c2d6SFlorian Fainelli } 1461ff39c2d6SFlorian Fainelli 1462ff39c2d6SFlorian Fainelli b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), ®); 1463ff39c2d6SFlorian Fainelli reg &= ~PORT_CTRL_STP_STATE_MASK; 1464ff39c2d6SFlorian Fainelli reg |= hw_state; 1465ff39c2d6SFlorian Fainelli b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg); 1466ff39c2d6SFlorian Fainelli } 14673117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_set_stp_state); 1468ff39c2d6SFlorian Fainelli 14693117455dSFlorian Fainelli void b53_br_fast_age(struct dsa_switch *ds, int port) 1470597698f1SVivien Didelot { 1471597698f1SVivien Didelot struct b53_device *dev = ds->priv; 1472597698f1SVivien Didelot 1473597698f1SVivien Didelot if (b53_fast_age_port(dev, port)) 1474597698f1SVivien Didelot dev_err(ds->dev, "fast ageing failed\n"); 1475597698f1SVivien Didelot } 14763117455dSFlorian Fainelli EXPORT_SYMBOL(b53_br_fast_age); 1477597698f1SVivien Didelot 14787b314362SAndrew Lunn static enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds) 14797b314362SAndrew Lunn { 14807b314362SAndrew Lunn return DSA_TAG_PROTO_NONE; 14817b314362SAndrew Lunn } 14827b314362SAndrew Lunn 1483ed3af5fdSFlorian Fainelli int b53_mirror_add(struct dsa_switch *ds, int port, 1484ed3af5fdSFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror, bool ingress) 1485ed3af5fdSFlorian Fainelli { 1486ed3af5fdSFlorian Fainelli struct b53_device *dev = ds->priv; 1487ed3af5fdSFlorian Fainelli u16 reg, loc; 1488ed3af5fdSFlorian Fainelli 1489ed3af5fdSFlorian Fainelli if (ingress) 1490ed3af5fdSFlorian Fainelli loc = B53_IG_MIR_CTL; 1491ed3af5fdSFlorian Fainelli else 1492ed3af5fdSFlorian Fainelli loc = B53_EG_MIR_CTL; 1493ed3af5fdSFlorian Fainelli 1494ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, loc, ®); 1495ed3af5fdSFlorian Fainelli reg &= ~MIRROR_MASK; 1496ed3af5fdSFlorian Fainelli reg |= BIT(port); 1497ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, loc, reg); 1498ed3af5fdSFlorian Fainelli 1499ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®); 1500ed3af5fdSFlorian Fainelli reg &= ~CAP_PORT_MASK; 1501ed3af5fdSFlorian Fainelli reg |= mirror->to_local_port; 1502ed3af5fdSFlorian Fainelli reg |= MIRROR_EN; 1503ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg); 1504ed3af5fdSFlorian Fainelli 1505ed3af5fdSFlorian Fainelli return 0; 1506ed3af5fdSFlorian Fainelli } 1507ed3af5fdSFlorian Fainelli EXPORT_SYMBOL(b53_mirror_add); 1508ed3af5fdSFlorian Fainelli 1509ed3af5fdSFlorian Fainelli void b53_mirror_del(struct dsa_switch *ds, int port, 1510ed3af5fdSFlorian Fainelli struct dsa_mall_mirror_tc_entry *mirror) 1511ed3af5fdSFlorian Fainelli { 1512ed3af5fdSFlorian Fainelli struct b53_device *dev = ds->priv; 1513ed3af5fdSFlorian Fainelli bool loc_disable = false, other_loc_disable = false; 1514ed3af5fdSFlorian Fainelli u16 reg, loc; 1515ed3af5fdSFlorian Fainelli 1516ed3af5fdSFlorian Fainelli if (mirror->ingress) 1517ed3af5fdSFlorian Fainelli loc = B53_IG_MIR_CTL; 1518ed3af5fdSFlorian Fainelli else 1519ed3af5fdSFlorian Fainelli loc = B53_EG_MIR_CTL; 1520ed3af5fdSFlorian Fainelli 1521ed3af5fdSFlorian Fainelli /* Update the desired ingress/egress register */ 1522ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, loc, ®); 1523ed3af5fdSFlorian Fainelli reg &= ~BIT(port); 1524ed3af5fdSFlorian Fainelli if (!(reg & MIRROR_MASK)) 1525ed3af5fdSFlorian Fainelli loc_disable = true; 1526ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, loc, reg); 1527ed3af5fdSFlorian Fainelli 1528ed3af5fdSFlorian Fainelli /* Now look at the other one to know if we can disable mirroring 1529ed3af5fdSFlorian Fainelli * entirely 1530ed3af5fdSFlorian Fainelli */ 1531ed3af5fdSFlorian Fainelli if (mirror->ingress) 1532ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_EG_MIR_CTL, ®); 1533ed3af5fdSFlorian Fainelli else 1534ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_IG_MIR_CTL, ®); 1535ed3af5fdSFlorian Fainelli if (!(reg & MIRROR_MASK)) 1536ed3af5fdSFlorian Fainelli other_loc_disable = true; 1537ed3af5fdSFlorian Fainelli 1538ed3af5fdSFlorian Fainelli b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®); 1539ed3af5fdSFlorian Fainelli /* Both no longer have ports, let's disable mirroring */ 1540ed3af5fdSFlorian Fainelli if (loc_disable && other_loc_disable) { 1541ed3af5fdSFlorian Fainelli reg &= ~MIRROR_EN; 1542ed3af5fdSFlorian Fainelli reg &= ~mirror->to_local_port; 1543ed3af5fdSFlorian Fainelli } 1544ed3af5fdSFlorian Fainelli b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg); 1545ed3af5fdSFlorian Fainelli } 1546ed3af5fdSFlorian Fainelli EXPORT_SYMBOL(b53_mirror_del); 1547ed3af5fdSFlorian Fainelli 1548a82f67afSFlorian Fainelli static const struct dsa_switch_ops b53_switch_ops = { 15497b314362SAndrew Lunn .get_tag_protocol = b53_get_tag_protocol, 1550967dd82fSFlorian Fainelli .setup = b53_setup, 1551967dd82fSFlorian Fainelli .get_strings = b53_get_strings, 1552967dd82fSFlorian Fainelli .get_ethtool_stats = b53_get_ethtool_stats, 1553967dd82fSFlorian Fainelli .get_sset_count = b53_get_sset_count, 1554967dd82fSFlorian Fainelli .phy_read = b53_phy_read16, 1555967dd82fSFlorian Fainelli .phy_write = b53_phy_write16, 1556967dd82fSFlorian Fainelli .adjust_link = b53_adjust_link, 1557967dd82fSFlorian Fainelli .port_enable = b53_enable_port, 1558967dd82fSFlorian Fainelli .port_disable = b53_disable_port, 1559ff39c2d6SFlorian Fainelli .port_bridge_join = b53_br_join, 1560ff39c2d6SFlorian Fainelli .port_bridge_leave = b53_br_leave, 1561ff39c2d6SFlorian Fainelli .port_stp_state_set = b53_br_set_stp_state, 1562597698f1SVivien Didelot .port_fast_age = b53_br_fast_age, 1563a2482d2cSFlorian Fainelli .port_vlan_filtering = b53_vlan_filtering, 1564a2482d2cSFlorian Fainelli .port_vlan_prepare = b53_vlan_prepare, 1565a2482d2cSFlorian Fainelli .port_vlan_add = b53_vlan_add, 1566a2482d2cSFlorian Fainelli .port_vlan_del = b53_vlan_del, 1567a2482d2cSFlorian Fainelli .port_vlan_dump = b53_vlan_dump, 15681da6df85SFlorian Fainelli .port_fdb_prepare = b53_fdb_prepare, 15691da6df85SFlorian Fainelli .port_fdb_dump = b53_fdb_dump, 15701da6df85SFlorian Fainelli .port_fdb_add = b53_fdb_add, 15711da6df85SFlorian Fainelli .port_fdb_del = b53_fdb_del, 1572ed3af5fdSFlorian Fainelli .port_mirror_add = b53_mirror_add, 1573ed3af5fdSFlorian Fainelli .port_mirror_del = b53_mirror_del, 1574967dd82fSFlorian Fainelli }; 1575967dd82fSFlorian Fainelli 1576967dd82fSFlorian Fainelli struct b53_chip_data { 1577967dd82fSFlorian Fainelli u32 chip_id; 1578967dd82fSFlorian Fainelli const char *dev_name; 1579967dd82fSFlorian Fainelli u16 vlans; 1580967dd82fSFlorian Fainelli u16 enabled_ports; 1581967dd82fSFlorian Fainelli u8 cpu_port; 1582967dd82fSFlorian Fainelli u8 vta_regs[3]; 15831da6df85SFlorian Fainelli u8 arl_entries; 1584967dd82fSFlorian Fainelli u8 duplex_reg; 1585967dd82fSFlorian Fainelli u8 jumbo_pm_reg; 1586967dd82fSFlorian Fainelli u8 jumbo_size_reg; 1587967dd82fSFlorian Fainelli }; 1588967dd82fSFlorian Fainelli 1589967dd82fSFlorian Fainelli #define B53_VTA_REGS \ 1590967dd82fSFlorian Fainelli { B53_VT_ACCESS, B53_VT_INDEX, B53_VT_ENTRY } 1591967dd82fSFlorian Fainelli #define B53_VTA_REGS_9798 \ 1592967dd82fSFlorian Fainelli { B53_VT_ACCESS_9798, B53_VT_INDEX_9798, B53_VT_ENTRY_9798 } 1593967dd82fSFlorian Fainelli #define B53_VTA_REGS_63XX \ 1594967dd82fSFlorian Fainelli { B53_VT_ACCESS_63XX, B53_VT_INDEX_63XX, B53_VT_ENTRY_63XX } 1595967dd82fSFlorian Fainelli 1596967dd82fSFlorian Fainelli static const struct b53_chip_data b53_switch_chips[] = { 1597967dd82fSFlorian Fainelli { 1598967dd82fSFlorian Fainelli .chip_id = BCM5325_DEVICE_ID, 1599967dd82fSFlorian Fainelli .dev_name = "BCM5325", 1600967dd82fSFlorian Fainelli .vlans = 16, 1601967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 16021da6df85SFlorian Fainelli .arl_entries = 2, 1603967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, 1604967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_FE, 1605967dd82fSFlorian Fainelli }, 1606967dd82fSFlorian Fainelli { 1607967dd82fSFlorian Fainelli .chip_id = BCM5365_DEVICE_ID, 1608967dd82fSFlorian Fainelli .dev_name = "BCM5365", 1609967dd82fSFlorian Fainelli .vlans = 256, 1610967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 16111da6df85SFlorian Fainelli .arl_entries = 2, 1612967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, 1613967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_FE, 1614967dd82fSFlorian Fainelli }, 1615967dd82fSFlorian Fainelli { 1616967dd82fSFlorian Fainelli .chip_id = BCM5395_DEVICE_ID, 1617967dd82fSFlorian Fainelli .dev_name = "BCM5395", 1618967dd82fSFlorian Fainelli .vlans = 4096, 1619967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 16201da6df85SFlorian Fainelli .arl_entries = 4, 1621967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 1622967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 1623967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 1624967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 1625967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 1626967dd82fSFlorian Fainelli }, 1627967dd82fSFlorian Fainelli { 1628967dd82fSFlorian Fainelli .chip_id = BCM5397_DEVICE_ID, 1629967dd82fSFlorian Fainelli .dev_name = "BCM5397", 1630967dd82fSFlorian Fainelli .vlans = 4096, 1631967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 16321da6df85SFlorian Fainelli .arl_entries = 4, 1633967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 1634967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_9798, 1635967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 1636967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 1637967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 1638967dd82fSFlorian Fainelli }, 1639967dd82fSFlorian Fainelli { 1640967dd82fSFlorian Fainelli .chip_id = BCM5398_DEVICE_ID, 1641967dd82fSFlorian Fainelli .dev_name = "BCM5398", 1642967dd82fSFlorian Fainelli .vlans = 4096, 1643967dd82fSFlorian Fainelli .enabled_ports = 0x7f, 16441da6df85SFlorian Fainelli .arl_entries = 4, 1645967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 1646967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_9798, 1647967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 1648967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 1649967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 1650967dd82fSFlorian Fainelli }, 1651967dd82fSFlorian Fainelli { 1652967dd82fSFlorian Fainelli .chip_id = BCM53115_DEVICE_ID, 1653967dd82fSFlorian Fainelli .dev_name = "BCM53115", 1654967dd82fSFlorian Fainelli .vlans = 4096, 1655967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 16561da6df85SFlorian Fainelli .arl_entries = 4, 1657967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 1658967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 1659967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 1660967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 1661967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 1662967dd82fSFlorian Fainelli }, 1663967dd82fSFlorian Fainelli { 1664967dd82fSFlorian Fainelli .chip_id = BCM53125_DEVICE_ID, 1665967dd82fSFlorian Fainelli .dev_name = "BCM53125", 1666967dd82fSFlorian Fainelli .vlans = 4096, 1667967dd82fSFlorian Fainelli .enabled_ports = 0xff, 1668967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 1669967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 1670967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 1671967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 1672967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 1673967dd82fSFlorian Fainelli }, 1674967dd82fSFlorian Fainelli { 1675967dd82fSFlorian Fainelli .chip_id = BCM53128_DEVICE_ID, 1676967dd82fSFlorian Fainelli .dev_name = "BCM53128", 1677967dd82fSFlorian Fainelli .vlans = 4096, 1678967dd82fSFlorian Fainelli .enabled_ports = 0x1ff, 16791da6df85SFlorian Fainelli .arl_entries = 4, 1680967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 1681967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 1682967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 1683967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 1684967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 1685967dd82fSFlorian Fainelli }, 1686967dd82fSFlorian Fainelli { 1687967dd82fSFlorian Fainelli .chip_id = BCM63XX_DEVICE_ID, 1688967dd82fSFlorian Fainelli .dev_name = "BCM63xx", 1689967dd82fSFlorian Fainelli .vlans = 4096, 1690967dd82fSFlorian Fainelli .enabled_ports = 0, /* pdata must provide them */ 16911da6df85SFlorian Fainelli .arl_entries = 4, 1692967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT, 1693967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS_63XX, 1694967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_63XX, 1695967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK_63XX, 1696967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE_63XX, 1697967dd82fSFlorian Fainelli }, 1698967dd82fSFlorian Fainelli { 1699967dd82fSFlorian Fainelli .chip_id = BCM53010_DEVICE_ID, 1700967dd82fSFlorian Fainelli .dev_name = "BCM53010", 1701967dd82fSFlorian Fainelli .vlans = 4096, 1702967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 17031da6df85SFlorian Fainelli .arl_entries = 4, 1704967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 1705967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 1706967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 1707967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 1708967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 1709967dd82fSFlorian Fainelli }, 1710967dd82fSFlorian Fainelli { 1711967dd82fSFlorian Fainelli .chip_id = BCM53011_DEVICE_ID, 1712967dd82fSFlorian Fainelli .dev_name = "BCM53011", 1713967dd82fSFlorian Fainelli .vlans = 4096, 1714967dd82fSFlorian Fainelli .enabled_ports = 0x1bf, 17151da6df85SFlorian Fainelli .arl_entries = 4, 1716967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 1717967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 1718967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 1719967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 1720967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 1721967dd82fSFlorian Fainelli }, 1722967dd82fSFlorian Fainelli { 1723967dd82fSFlorian Fainelli .chip_id = BCM53012_DEVICE_ID, 1724967dd82fSFlorian Fainelli .dev_name = "BCM53012", 1725967dd82fSFlorian Fainelli .vlans = 4096, 1726967dd82fSFlorian Fainelli .enabled_ports = 0x1bf, 17271da6df85SFlorian Fainelli .arl_entries = 4, 1728967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 1729967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 1730967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 1731967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 1732967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 1733967dd82fSFlorian Fainelli }, 1734967dd82fSFlorian Fainelli { 1735967dd82fSFlorian Fainelli .chip_id = BCM53018_DEVICE_ID, 1736967dd82fSFlorian Fainelli .dev_name = "BCM53018", 1737967dd82fSFlorian Fainelli .vlans = 4096, 1738967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 17391da6df85SFlorian Fainelli .arl_entries = 4, 1740967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 1741967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 1742967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 1743967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 1744967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 1745967dd82fSFlorian Fainelli }, 1746967dd82fSFlorian Fainelli { 1747967dd82fSFlorian Fainelli .chip_id = BCM53019_DEVICE_ID, 1748967dd82fSFlorian Fainelli .dev_name = "BCM53019", 1749967dd82fSFlorian Fainelli .vlans = 4096, 1750967dd82fSFlorian Fainelli .enabled_ports = 0x1f, 17511da6df85SFlorian Fainelli .arl_entries = 4, 1752967dd82fSFlorian Fainelli .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */ 1753967dd82fSFlorian Fainelli .vta_regs = B53_VTA_REGS, 1754967dd82fSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 1755967dd82fSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 1756967dd82fSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 1757967dd82fSFlorian Fainelli }, 1758991a36bbSFlorian Fainelli { 1759991a36bbSFlorian Fainelli .chip_id = BCM58XX_DEVICE_ID, 1760991a36bbSFlorian Fainelli .dev_name = "BCM585xx/586xx/88312", 1761991a36bbSFlorian Fainelli .vlans = 4096, 1762991a36bbSFlorian Fainelli .enabled_ports = 0x1ff, 1763991a36bbSFlorian Fainelli .arl_entries = 4, 1764bfcda65cSFlorian Fainelli .cpu_port = B53_CPU_PORT, 1765991a36bbSFlorian Fainelli .vta_regs = B53_VTA_REGS, 1766991a36bbSFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 1767991a36bbSFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 1768991a36bbSFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 1769991a36bbSFlorian Fainelli }, 1770130401d9SFlorian Fainelli { 1771130401d9SFlorian Fainelli .chip_id = BCM7445_DEVICE_ID, 1772130401d9SFlorian Fainelli .dev_name = "BCM7445", 1773130401d9SFlorian Fainelli .vlans = 4096, 1774130401d9SFlorian Fainelli .enabled_ports = 0x1ff, 1775130401d9SFlorian Fainelli .arl_entries = 4, 1776130401d9SFlorian Fainelli .cpu_port = B53_CPU_PORT, 1777130401d9SFlorian Fainelli .vta_regs = B53_VTA_REGS, 1778130401d9SFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 1779130401d9SFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 1780130401d9SFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 1781130401d9SFlorian Fainelli }, 17820fe99338SFlorian Fainelli { 17830fe99338SFlorian Fainelli .chip_id = BCM7278_DEVICE_ID, 17840fe99338SFlorian Fainelli .dev_name = "BCM7278", 17850fe99338SFlorian Fainelli .vlans = 4096, 17860fe99338SFlorian Fainelli .enabled_ports = 0x1ff, 17870fe99338SFlorian Fainelli .arl_entries= 4, 17880fe99338SFlorian Fainelli .cpu_port = B53_CPU_PORT, 17890fe99338SFlorian Fainelli .vta_regs = B53_VTA_REGS, 17900fe99338SFlorian Fainelli .duplex_reg = B53_DUPLEX_STAT_GE, 17910fe99338SFlorian Fainelli .jumbo_pm_reg = B53_JUMBO_PORT_MASK, 17920fe99338SFlorian Fainelli .jumbo_size_reg = B53_JUMBO_MAX_SIZE, 17930fe99338SFlorian Fainelli }, 1794967dd82fSFlorian Fainelli }; 1795967dd82fSFlorian Fainelli 1796967dd82fSFlorian Fainelli static int b53_switch_init(struct b53_device *dev) 1797967dd82fSFlorian Fainelli { 1798967dd82fSFlorian Fainelli unsigned int i; 1799967dd82fSFlorian Fainelli int ret; 1800967dd82fSFlorian Fainelli 1801967dd82fSFlorian Fainelli for (i = 0; i < ARRAY_SIZE(b53_switch_chips); i++) { 1802967dd82fSFlorian Fainelli const struct b53_chip_data *chip = &b53_switch_chips[i]; 1803967dd82fSFlorian Fainelli 1804967dd82fSFlorian Fainelli if (chip->chip_id == dev->chip_id) { 1805967dd82fSFlorian Fainelli if (!dev->enabled_ports) 1806967dd82fSFlorian Fainelli dev->enabled_ports = chip->enabled_ports; 1807967dd82fSFlorian Fainelli dev->name = chip->dev_name; 1808967dd82fSFlorian Fainelli dev->duplex_reg = chip->duplex_reg; 1809967dd82fSFlorian Fainelli dev->vta_regs[0] = chip->vta_regs[0]; 1810967dd82fSFlorian Fainelli dev->vta_regs[1] = chip->vta_regs[1]; 1811967dd82fSFlorian Fainelli dev->vta_regs[2] = chip->vta_regs[2]; 1812967dd82fSFlorian Fainelli dev->jumbo_pm_reg = chip->jumbo_pm_reg; 1813967dd82fSFlorian Fainelli dev->cpu_port = chip->cpu_port; 1814967dd82fSFlorian Fainelli dev->num_vlans = chip->vlans; 18151da6df85SFlorian Fainelli dev->num_arl_entries = chip->arl_entries; 1816967dd82fSFlorian Fainelli break; 1817967dd82fSFlorian Fainelli } 1818967dd82fSFlorian Fainelli } 1819967dd82fSFlorian Fainelli 1820967dd82fSFlorian Fainelli /* check which BCM5325x version we have */ 1821967dd82fSFlorian Fainelli if (is5325(dev)) { 1822967dd82fSFlorian Fainelli u8 vc4; 1823967dd82fSFlorian Fainelli 1824967dd82fSFlorian Fainelli b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4); 1825967dd82fSFlorian Fainelli 1826967dd82fSFlorian Fainelli /* check reserved bits */ 1827967dd82fSFlorian Fainelli switch (vc4 & 3) { 1828967dd82fSFlorian Fainelli case 1: 1829967dd82fSFlorian Fainelli /* BCM5325E */ 1830967dd82fSFlorian Fainelli break; 1831967dd82fSFlorian Fainelli case 3: 1832967dd82fSFlorian Fainelli /* BCM5325F - do not use port 4 */ 1833967dd82fSFlorian Fainelli dev->enabled_ports &= ~BIT(4); 1834967dd82fSFlorian Fainelli break; 1835967dd82fSFlorian Fainelli default: 1836967dd82fSFlorian Fainelli /* On the BCM47XX SoCs this is the supported internal switch.*/ 1837967dd82fSFlorian Fainelli #ifndef CONFIG_BCM47XX 1838967dd82fSFlorian Fainelli /* BCM5325M */ 1839967dd82fSFlorian Fainelli return -EINVAL; 1840967dd82fSFlorian Fainelli #else 1841967dd82fSFlorian Fainelli break; 1842967dd82fSFlorian Fainelli #endif 1843967dd82fSFlorian Fainelli } 1844967dd82fSFlorian Fainelli } else if (dev->chip_id == BCM53115_DEVICE_ID) { 1845967dd82fSFlorian Fainelli u64 strap_value; 1846967dd82fSFlorian Fainelli 1847967dd82fSFlorian Fainelli b53_read48(dev, B53_STAT_PAGE, B53_STRAP_VALUE, &strap_value); 1848967dd82fSFlorian Fainelli /* use second IMP port if GMII is enabled */ 1849967dd82fSFlorian Fainelli if (strap_value & SV_GMII_CTRL_115) 1850967dd82fSFlorian Fainelli dev->cpu_port = 5; 1851967dd82fSFlorian Fainelli } 1852967dd82fSFlorian Fainelli 1853967dd82fSFlorian Fainelli /* cpu port is always last */ 1854967dd82fSFlorian Fainelli dev->num_ports = dev->cpu_port + 1; 1855967dd82fSFlorian Fainelli dev->enabled_ports |= BIT(dev->cpu_port); 1856967dd82fSFlorian Fainelli 1857967dd82fSFlorian Fainelli dev->ports = devm_kzalloc(dev->dev, 1858967dd82fSFlorian Fainelli sizeof(struct b53_port) * dev->num_ports, 1859967dd82fSFlorian Fainelli GFP_KERNEL); 1860967dd82fSFlorian Fainelli if (!dev->ports) 1861967dd82fSFlorian Fainelli return -ENOMEM; 1862967dd82fSFlorian Fainelli 1863a2482d2cSFlorian Fainelli dev->vlans = devm_kzalloc(dev->dev, 1864a2482d2cSFlorian Fainelli sizeof(struct b53_vlan) * dev->num_vlans, 1865a2482d2cSFlorian Fainelli GFP_KERNEL); 1866a2482d2cSFlorian Fainelli if (!dev->vlans) 1867a2482d2cSFlorian Fainelli return -ENOMEM; 1868a2482d2cSFlorian Fainelli 1869967dd82fSFlorian Fainelli dev->reset_gpio = b53_switch_get_reset_gpio(dev); 1870967dd82fSFlorian Fainelli if (dev->reset_gpio >= 0) { 1871967dd82fSFlorian Fainelli ret = devm_gpio_request_one(dev->dev, dev->reset_gpio, 1872967dd82fSFlorian Fainelli GPIOF_OUT_INIT_HIGH, "robo_reset"); 1873967dd82fSFlorian Fainelli if (ret) 1874967dd82fSFlorian Fainelli return ret; 1875967dd82fSFlorian Fainelli } 1876967dd82fSFlorian Fainelli 1877967dd82fSFlorian Fainelli return 0; 1878967dd82fSFlorian Fainelli } 1879967dd82fSFlorian Fainelli 18800dff88d3SJulia Lawall struct b53_device *b53_switch_alloc(struct device *base, 18810dff88d3SJulia Lawall const struct b53_io_ops *ops, 1882967dd82fSFlorian Fainelli void *priv) 1883967dd82fSFlorian Fainelli { 1884967dd82fSFlorian Fainelli struct dsa_switch *ds; 1885967dd82fSFlorian Fainelli struct b53_device *dev; 1886967dd82fSFlorian Fainelli 1887a0c02161SVivien Didelot ds = dsa_switch_alloc(base, DSA_MAX_PORTS); 1888967dd82fSFlorian Fainelli if (!ds) 1889967dd82fSFlorian Fainelli return NULL; 1890967dd82fSFlorian Fainelli 1891a0c02161SVivien Didelot dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL); 1892a0c02161SVivien Didelot if (!dev) 1893a0c02161SVivien Didelot return NULL; 1894967dd82fSFlorian Fainelli 1895967dd82fSFlorian Fainelli ds->priv = dev; 1896967dd82fSFlorian Fainelli dev->dev = base; 1897967dd82fSFlorian Fainelli 1898967dd82fSFlorian Fainelli dev->ds = ds; 1899967dd82fSFlorian Fainelli dev->priv = priv; 1900967dd82fSFlorian Fainelli dev->ops = ops; 1901485ebd61SFlorian Fainelli ds->ops = &b53_switch_ops; 1902967dd82fSFlorian Fainelli mutex_init(&dev->reg_mutex); 1903967dd82fSFlorian Fainelli mutex_init(&dev->stats_mutex); 1904967dd82fSFlorian Fainelli 1905967dd82fSFlorian Fainelli return dev; 1906967dd82fSFlorian Fainelli } 1907967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_alloc); 1908967dd82fSFlorian Fainelli 1909967dd82fSFlorian Fainelli int b53_switch_detect(struct b53_device *dev) 1910967dd82fSFlorian Fainelli { 1911967dd82fSFlorian Fainelli u32 id32; 1912967dd82fSFlorian Fainelli u16 tmp; 1913967dd82fSFlorian Fainelli u8 id8; 1914967dd82fSFlorian Fainelli int ret; 1915967dd82fSFlorian Fainelli 1916967dd82fSFlorian Fainelli ret = b53_read8(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id8); 1917967dd82fSFlorian Fainelli if (ret) 1918967dd82fSFlorian Fainelli return ret; 1919967dd82fSFlorian Fainelli 1920967dd82fSFlorian Fainelli switch (id8) { 1921967dd82fSFlorian Fainelli case 0: 1922967dd82fSFlorian Fainelli /* BCM5325 and BCM5365 do not have this register so reads 1923967dd82fSFlorian Fainelli * return 0. But the read operation did succeed, so assume this 1924967dd82fSFlorian Fainelli * is one of them. 1925967dd82fSFlorian Fainelli * 1926967dd82fSFlorian Fainelli * Next check if we can write to the 5325's VTA register; for 1927967dd82fSFlorian Fainelli * 5365 it is read only. 1928967dd82fSFlorian Fainelli */ 1929967dd82fSFlorian Fainelli b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, 0xf); 1930967dd82fSFlorian Fainelli b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, &tmp); 1931967dd82fSFlorian Fainelli 1932967dd82fSFlorian Fainelli if (tmp == 0xf) 1933967dd82fSFlorian Fainelli dev->chip_id = BCM5325_DEVICE_ID; 1934967dd82fSFlorian Fainelli else 1935967dd82fSFlorian Fainelli dev->chip_id = BCM5365_DEVICE_ID; 1936967dd82fSFlorian Fainelli break; 1937967dd82fSFlorian Fainelli case BCM5395_DEVICE_ID: 1938967dd82fSFlorian Fainelli case BCM5397_DEVICE_ID: 1939967dd82fSFlorian Fainelli case BCM5398_DEVICE_ID: 1940967dd82fSFlorian Fainelli dev->chip_id = id8; 1941967dd82fSFlorian Fainelli break; 1942967dd82fSFlorian Fainelli default: 1943967dd82fSFlorian Fainelli ret = b53_read32(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id32); 1944967dd82fSFlorian Fainelli if (ret) 1945967dd82fSFlorian Fainelli return ret; 1946967dd82fSFlorian Fainelli 1947967dd82fSFlorian Fainelli switch (id32) { 1948967dd82fSFlorian Fainelli case BCM53115_DEVICE_ID: 1949967dd82fSFlorian Fainelli case BCM53125_DEVICE_ID: 1950967dd82fSFlorian Fainelli case BCM53128_DEVICE_ID: 1951967dd82fSFlorian Fainelli case BCM53010_DEVICE_ID: 1952967dd82fSFlorian Fainelli case BCM53011_DEVICE_ID: 1953967dd82fSFlorian Fainelli case BCM53012_DEVICE_ID: 1954967dd82fSFlorian Fainelli case BCM53018_DEVICE_ID: 1955967dd82fSFlorian Fainelli case BCM53019_DEVICE_ID: 1956967dd82fSFlorian Fainelli dev->chip_id = id32; 1957967dd82fSFlorian Fainelli break; 1958967dd82fSFlorian Fainelli default: 1959967dd82fSFlorian Fainelli pr_err("unsupported switch detected (BCM53%02x/BCM%x)\n", 1960967dd82fSFlorian Fainelli id8, id32); 1961967dd82fSFlorian Fainelli return -ENODEV; 1962967dd82fSFlorian Fainelli } 1963967dd82fSFlorian Fainelli } 1964967dd82fSFlorian Fainelli 1965967dd82fSFlorian Fainelli if (dev->chip_id == BCM5325_DEVICE_ID) 1966967dd82fSFlorian Fainelli return b53_read8(dev, B53_STAT_PAGE, B53_REV_ID_25, 1967967dd82fSFlorian Fainelli &dev->core_rev); 1968967dd82fSFlorian Fainelli else 1969967dd82fSFlorian Fainelli return b53_read8(dev, B53_MGMT_PAGE, B53_REV_ID, 1970967dd82fSFlorian Fainelli &dev->core_rev); 1971967dd82fSFlorian Fainelli } 1972967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_detect); 1973967dd82fSFlorian Fainelli 1974967dd82fSFlorian Fainelli int b53_switch_register(struct b53_device *dev) 1975967dd82fSFlorian Fainelli { 1976967dd82fSFlorian Fainelli int ret; 1977967dd82fSFlorian Fainelli 1978967dd82fSFlorian Fainelli if (dev->pdata) { 1979967dd82fSFlorian Fainelli dev->chip_id = dev->pdata->chip_id; 1980967dd82fSFlorian Fainelli dev->enabled_ports = dev->pdata->enabled_ports; 1981967dd82fSFlorian Fainelli } 1982967dd82fSFlorian Fainelli 1983967dd82fSFlorian Fainelli if (!dev->chip_id && b53_switch_detect(dev)) 1984967dd82fSFlorian Fainelli return -EINVAL; 1985967dd82fSFlorian Fainelli 1986967dd82fSFlorian Fainelli ret = b53_switch_init(dev); 1987967dd82fSFlorian Fainelli if (ret) 1988967dd82fSFlorian Fainelli return ret; 1989967dd82fSFlorian Fainelli 1990967dd82fSFlorian Fainelli pr_info("found switch: %s, rev %i\n", dev->name, dev->core_rev); 1991967dd82fSFlorian Fainelli 199255ed0ce0SFlorian Fainelli return dsa_register_switch(dev->ds, dev->ds->dev); 1993967dd82fSFlorian Fainelli } 1994967dd82fSFlorian Fainelli EXPORT_SYMBOL(b53_switch_register); 1995967dd82fSFlorian Fainelli 1996967dd82fSFlorian Fainelli MODULE_AUTHOR("Jonas Gorski <jogo@openwrt.org>"); 1997967dd82fSFlorian Fainelli MODULE_DESCRIPTION("B53 switch library"); 1998967dd82fSFlorian Fainelli MODULE_LICENSE("Dual BSD/GPL"); 1999