Vivien Didelot | a935c05 | 2016-09-29 12:21:53 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Marvell 88E6xxx Switch Global (1) Registers support |
| 3 | * |
| 4 | * Copyright (c) 2008 Marvell Semiconductor |
| 5 | * |
| 6 | * Copyright (c) 2016 Vivien Didelot <vivien.didelot@savoirfairelinux.com> |
| 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 | |
| 17 | int mv88e6xxx_g1_read(struct mv88e6xxx_chip *chip, int reg, u16 *val) |
| 18 | { |
| 19 | int addr = chip->info->global1_addr; |
| 20 | |
| 21 | return mv88e6xxx_read(chip, addr, reg, val); |
| 22 | } |
| 23 | |
| 24 | int mv88e6xxx_g1_write(struct mv88e6xxx_chip *chip, int reg, u16 val) |
| 25 | { |
| 26 | int addr = chip->info->global1_addr; |
| 27 | |
| 28 | return mv88e6xxx_write(chip, addr, reg, val); |
| 29 | } |
| 30 | |
| 31 | int mv88e6xxx_g1_wait(struct mv88e6xxx_chip *chip, int reg, u16 mask) |
| 32 | { |
| 33 | return mv88e6xxx_wait(chip, chip->info->global1_addr, reg, mask); |
| 34 | } |
Andrew Lunn | a605a0f | 2016-11-21 23:26:58 +0100 | [diff] [blame] | 35 | |
Andrew Lunn | de227387 | 2016-11-21 23:27:01 +0100 | [diff] [blame^] | 36 | /* Offset 0x1c: Global Control 2 */ |
| 37 | |
| 38 | int mv88e6390_g1_stats_set_histogram(struct mv88e6xxx_chip *chip) |
| 39 | { |
| 40 | u16 val; |
| 41 | int err; |
| 42 | |
| 43 | err = mv88e6xxx_g1_read(chip, GLOBAL_CONTROL_2, &val); |
| 44 | if (err) |
| 45 | return err; |
| 46 | |
| 47 | val |= GLOBAL_CONTROL_2_HIST_RX_TX; |
| 48 | |
| 49 | err = mv88e6xxx_g1_write(chip, GLOBAL_CONTROL_2, val); |
| 50 | |
| 51 | return err; |
| 52 | } |
| 53 | |
| 54 | /* Offset 0x1d: Statistics Operation 2 */ |
| 55 | |
Andrew Lunn | a605a0f | 2016-11-21 23:26:58 +0100 | [diff] [blame] | 56 | static int mv88e6xxx_g1_stats_wait(struct mv88e6xxx_chip *chip) |
| 57 | { |
| 58 | return mv88e6xxx_g1_wait(chip, GLOBAL_STATS_OP, GLOBAL_STATS_OP_BUSY); |
| 59 | } |
| 60 | |
| 61 | int mv88e6xxx_g1_stats_snapshot(struct mv88e6xxx_chip *chip, int port) |
| 62 | { |
| 63 | int err; |
| 64 | |
| 65 | /* Snapshot the hardware statistics counters for this port. */ |
| 66 | err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP, |
| 67 | GLOBAL_STATS_OP_CAPTURE_PORT | |
| 68 | GLOBAL_STATS_OP_HIST_RX_TX | port); |
| 69 | if (err) |
| 70 | return err; |
| 71 | |
| 72 | /* Wait for the snapshotting to complete. */ |
| 73 | return mv88e6xxx_g1_stats_wait(chip); |
| 74 | } |
| 75 | |
| 76 | int mv88e6320_g1_stats_snapshot(struct mv88e6xxx_chip *chip, int port) |
| 77 | { |
| 78 | port = (port + 1) << 5; |
| 79 | |
| 80 | return mv88e6xxx_g1_stats_snapshot(chip, port); |
| 81 | } |
Andrew Lunn | 7952347 | 2016-11-21 23:27:00 +0100 | [diff] [blame] | 82 | |
| 83 | int mv88e6390_g1_stats_snapshot(struct mv88e6xxx_chip *chip, int port) |
| 84 | { |
| 85 | int err; |
| 86 | |
| 87 | port = (port + 1) << 5; |
| 88 | |
| 89 | /* Snapshot the hardware statistics counters for this port. */ |
| 90 | err = mv88e6xxx_g1_write(chip, GLOBAL_STATS_OP, |
| 91 | GLOBAL_STATS_OP_CAPTURE_PORT | port); |
| 92 | if (err) |
| 93 | return err; |
| 94 | |
| 95 | /* Wait for the snapshotting to complete. */ |
| 96 | return mv88e6xxx_g1_stats_wait(chip); |
| 97 | } |