Vivien Didelot | 332aa5c | 2017-05-01 14:05:12 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Marvell 88E6xxx VLAN [Spanning Tree] Translation Unit (VTU [STU]) support |
| 3 | * |
| 4 | * Copyright (c) 2008 Marvell Semiconductor |
| 5 | * Copyright (c) 2015 CMC Electronics, Inc. |
| 6 | * Copyright (c) 2017 Savoir-faire Linux, Inc. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | */ |
| 13 | |
| 14 | #include "mv88e6xxx.h" |
| 15 | #include "global1.h" |
| 16 | |
Vivien Didelot | 8ee51f6 | 2017-05-01 14:05:14 -0400 | [diff] [blame] | 17 | /* Offset 0x02: VTU FID Register */ |
| 18 | |
| 19 | int mv88e6xxx_g1_vtu_fid_read(struct mv88e6xxx_chip *chip, |
| 20 | struct mv88e6xxx_vtu_entry *entry) |
| 21 | { |
| 22 | u16 val; |
| 23 | int err; |
| 24 | |
| 25 | err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_FID, &val); |
| 26 | if (err) |
| 27 | return err; |
| 28 | |
| 29 | entry->fid = val & GLOBAL_VTU_FID_MASK; |
| 30 | |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | int mv88e6xxx_g1_vtu_fid_write(struct mv88e6xxx_chip *chip, |
| 35 | struct mv88e6xxx_vtu_entry *entry) |
| 36 | { |
| 37 | u16 val = entry->fid & GLOBAL_VTU_FID_MASK; |
| 38 | |
| 39 | return mv88e6xxx_g1_write(chip, GLOBAL_VTU_FID, val); |
| 40 | } |
| 41 | |
Vivien Didelot | d2ca1ea | 2017-05-01 14:05:15 -0400 | [diff] [blame^] | 42 | /* Offset 0x03: VTU SID Register */ |
| 43 | |
| 44 | int mv88e6xxx_g1_vtu_sid_read(struct mv88e6xxx_chip *chip, |
| 45 | struct mv88e6xxx_vtu_entry *entry) |
| 46 | { |
| 47 | u16 val; |
| 48 | int err; |
| 49 | |
| 50 | err = mv88e6xxx_g1_read(chip, GLOBAL_VTU_SID, &val); |
| 51 | if (err) |
| 52 | return err; |
| 53 | |
| 54 | entry->sid = val & GLOBAL_VTU_SID_MASK; |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | int mv88e6xxx_g1_vtu_sid_write(struct mv88e6xxx_chip *chip, |
| 60 | struct mv88e6xxx_vtu_entry *entry) |
| 61 | { |
| 62 | u16 val = entry->sid & GLOBAL_VTU_SID_MASK; |
| 63 | |
| 64 | return mv88e6xxx_g1_write(chip, GLOBAL_VTU_SID, val); |
| 65 | } |
| 66 | |
Vivien Didelot | 332aa5c | 2017-05-01 14:05:12 -0400 | [diff] [blame] | 67 | /* Offset 0x05: VTU Operation Register */ |
| 68 | |
| 69 | int mv88e6xxx_g1_vtu_op_wait(struct mv88e6xxx_chip *chip) |
| 70 | { |
| 71 | return mv88e6xxx_g1_wait(chip, GLOBAL_VTU_OP, GLOBAL_VTU_OP_BUSY); |
| 72 | } |
| 73 | |
| 74 | int mv88e6xxx_g1_vtu_op(struct mv88e6xxx_chip *chip, u16 op) |
| 75 | { |
| 76 | int err; |
| 77 | |
| 78 | err = mv88e6xxx_g1_write(chip, GLOBAL_VTU_OP, op); |
| 79 | if (err) |
| 80 | return err; |
| 81 | |
| 82 | return mv88e6xxx_g1_vtu_op_wait(chip); |
| 83 | } |
Vivien Didelot | b486d7c | 2017-05-01 14:05:13 -0400 | [diff] [blame] | 84 | |
| 85 | /* VLAN Translation Unit Operations */ |
| 86 | |
| 87 | int mv88e6xxx_g1_vtu_flush(struct mv88e6xxx_chip *chip) |
| 88 | { |
| 89 | int err; |
| 90 | |
| 91 | err = mv88e6xxx_g1_vtu_op_wait(chip); |
| 92 | if (err) |
| 93 | return err; |
| 94 | |
| 95 | return mv88e6xxx_g1_vtu_op(chip, GLOBAL_VTU_OP_FLUSH_ALL); |
| 96 | } |