]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/net/dsa/mv88e6xxx/global1_atu.c
net: dsa: mv88e6xxx: move ATU ageing time setter
[mirror_ubuntu-bionic-kernel.git] / drivers / net / dsa / mv88e6xxx / global1_atu.c
1 /*
2 * Marvell 88E6xxx Address Translation Unit (ATU) support
3 *
4 * Copyright (c) 2008 Marvell Semiconductor
5 * Copyright (c) 2017 Savoir-faire Linux, Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13 #include "mv88e6xxx.h"
14 #include "global1.h"
15
16 /* Offset 0x0A: ATU Control Register */
17
18 int mv88e6xxx_g1_atu_set_age_time(struct mv88e6xxx_chip *chip,
19 unsigned int msecs)
20 {
21 const unsigned int coeff = chip->info->age_time_coeff;
22 const unsigned int min = 0x01 * coeff;
23 const unsigned int max = 0xff * coeff;
24 u8 age_time;
25 u16 val;
26 int err;
27
28 if (msecs < min || msecs > max)
29 return -ERANGE;
30
31 /* Round to nearest multiple of coeff */
32 age_time = (msecs + coeff / 2) / coeff;
33
34 err = mv88e6xxx_g1_read(chip, GLOBAL_ATU_CONTROL, &val);
35 if (err)
36 return err;
37
38 /* AgeTime is 11:4 bits */
39 val &= ~0xff0;
40 val |= age_time << 4;
41
42 return mv88e6xxx_g1_write(chip, GLOBAL_ATU_CONTROL, val);
43 }