Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 1 | /* |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 2 | * Marvell 88E6xxx Switch Global 2 Registers support (device address |
| 3 | * 0x1C) |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 4 | * |
| 5 | * Copyright (c) 2008 Marvell Semiconductor |
| 6 | * |
Vivien Didelot | 4333d61 | 2017-03-28 15:10:36 -0400 | [diff] [blame] | 7 | * Copyright (c) 2016-2017 Savoir-faire Linux Inc. |
| 8 | * Vivien Didelot <vivien.didelot@savoirfairelinux.com> |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | */ |
| 15 | |
Florian Westphal | 282ccf6 | 2017-03-29 17:17:31 +0200 | [diff] [blame^] | 16 | #include <linux/interrupt.h> |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 17 | #include <linux/irqdomain.h> |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 18 | #include "mv88e6xxx.h" |
| 19 | #include "global2.h" |
| 20 | |
Vivien Didelot | 9fe850f | 2016-09-29 12:21:54 -0400 | [diff] [blame] | 21 | #define ADDR_GLOBAL2 0x1c |
| 22 | |
| 23 | static int mv88e6xxx_g2_read(struct mv88e6xxx_chip *chip, int reg, u16 *val) |
| 24 | { |
| 25 | return mv88e6xxx_read(chip, ADDR_GLOBAL2, reg, val); |
| 26 | } |
| 27 | |
| 28 | static int mv88e6xxx_g2_write(struct mv88e6xxx_chip *chip, int reg, u16 val) |
| 29 | { |
| 30 | return mv88e6xxx_write(chip, ADDR_GLOBAL2, reg, val); |
| 31 | } |
| 32 | |
| 33 | static int mv88e6xxx_g2_update(struct mv88e6xxx_chip *chip, int reg, u16 update) |
| 34 | { |
| 35 | return mv88e6xxx_update(chip, ADDR_GLOBAL2, reg, update); |
| 36 | } |
| 37 | |
| 38 | static int mv88e6xxx_g2_wait(struct mv88e6xxx_chip *chip, int reg, u16 mask) |
| 39 | { |
| 40 | return mv88e6xxx_wait(chip, ADDR_GLOBAL2, reg, mask); |
| 41 | } |
| 42 | |
Andrew Lunn | 6e55f69 | 2016-12-03 04:45:16 +0100 | [diff] [blame] | 43 | /* Offset 0x02: Management Enable 2x */ |
| 44 | /* Offset 0x03: Management Enable 0x */ |
| 45 | |
| 46 | int mv88e6095_g2_mgmt_rsvd2cpu(struct mv88e6xxx_chip *chip) |
| 47 | { |
| 48 | int err; |
| 49 | |
| 50 | /* Consider the frames with reserved multicast destination |
| 51 | * addresses matching 01:80:c2:00:00:2x as MGMT. |
| 52 | */ |
| 53 | if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_MGMT_EN_2X)) { |
| 54 | err = mv88e6xxx_g2_write(chip, GLOBAL2_MGMT_EN_2X, 0xffff); |
| 55 | if (err) |
| 56 | return err; |
| 57 | } |
| 58 | |
| 59 | /* Consider the frames with reserved multicast destination |
| 60 | * addresses matching 01:80:c2:00:00:0x as MGMT. |
| 61 | */ |
| 62 | if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_MGMT_EN_0X)) |
| 63 | return mv88e6xxx_g2_write(chip, GLOBAL2_MGMT_EN_0X, 0xffff); |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 68 | /* Offset 0x06: Device Mapping Table register */ |
| 69 | |
| 70 | static int mv88e6xxx_g2_device_mapping_write(struct mv88e6xxx_chip *chip, |
| 71 | int target, int port) |
| 72 | { |
| 73 | u16 val = (target << 8) | (port & 0xf); |
| 74 | |
Vivien Didelot | 9fe850f | 2016-09-29 12:21:54 -0400 | [diff] [blame] | 75 | return mv88e6xxx_g2_update(chip, GLOBAL2_DEVICE_MAPPING, val); |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | static int mv88e6xxx_g2_set_device_mapping(struct mv88e6xxx_chip *chip) |
| 79 | { |
| 80 | int target, port; |
| 81 | int err; |
| 82 | |
| 83 | /* Initialize the routing port to the 32 possible target devices */ |
| 84 | for (target = 0; target < 32; ++target) { |
| 85 | port = 0xf; |
| 86 | |
| 87 | if (target < DSA_MAX_SWITCHES) { |
| 88 | port = chip->ds->rtable[target]; |
| 89 | if (port == DSA_RTABLE_NONE) |
| 90 | port = 0xf; |
| 91 | } |
| 92 | |
| 93 | err = mv88e6xxx_g2_device_mapping_write(chip, target, port); |
| 94 | if (err) |
| 95 | break; |
| 96 | } |
| 97 | |
| 98 | return err; |
| 99 | } |
| 100 | |
| 101 | /* Offset 0x07: Trunk Mask Table register */ |
| 102 | |
| 103 | static int mv88e6xxx_g2_trunk_mask_write(struct mv88e6xxx_chip *chip, int num, |
| 104 | bool hask, u16 mask) |
| 105 | { |
Vivien Didelot | 370b4ff | 2016-09-29 12:21:57 -0400 | [diff] [blame] | 106 | const u16 port_mask = BIT(mv88e6xxx_num_ports(chip)) - 1; |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 107 | u16 val = (num << 12) | (mask & port_mask); |
| 108 | |
| 109 | if (hask) |
| 110 | val |= GLOBAL2_TRUNK_MASK_HASK; |
| 111 | |
Vivien Didelot | 9fe850f | 2016-09-29 12:21:54 -0400 | [diff] [blame] | 112 | return mv88e6xxx_g2_update(chip, GLOBAL2_TRUNK_MASK, val); |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /* Offset 0x08: Trunk Mapping Table register */ |
| 116 | |
| 117 | static int mv88e6xxx_g2_trunk_mapping_write(struct mv88e6xxx_chip *chip, int id, |
| 118 | u16 map) |
| 119 | { |
Vivien Didelot | 370b4ff | 2016-09-29 12:21:57 -0400 | [diff] [blame] | 120 | const u16 port_mask = BIT(mv88e6xxx_num_ports(chip)) - 1; |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 121 | u16 val = (id << 11) | (map & port_mask); |
| 122 | |
Vivien Didelot | 9fe850f | 2016-09-29 12:21:54 -0400 | [diff] [blame] | 123 | return mv88e6xxx_g2_update(chip, GLOBAL2_TRUNK_MAPPING, val); |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static int mv88e6xxx_g2_clear_trunk(struct mv88e6xxx_chip *chip) |
| 127 | { |
Vivien Didelot | 370b4ff | 2016-09-29 12:21:57 -0400 | [diff] [blame] | 128 | const u16 port_mask = BIT(mv88e6xxx_num_ports(chip)) - 1; |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 129 | int i, err; |
| 130 | |
| 131 | /* Clear all eight possible Trunk Mask vectors */ |
| 132 | for (i = 0; i < 8; ++i) { |
| 133 | err = mv88e6xxx_g2_trunk_mask_write(chip, i, false, port_mask); |
| 134 | if (err) |
| 135 | return err; |
| 136 | } |
| 137 | |
| 138 | /* Clear all sixteen possible Trunk ID routing vectors */ |
| 139 | for (i = 0; i < 16; ++i) { |
| 140 | err = mv88e6xxx_g2_trunk_mapping_write(chip, i, 0); |
| 141 | if (err) |
| 142 | return err; |
| 143 | } |
| 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | /* Offset 0x09: Ingress Rate Command register |
| 149 | * Offset 0x0A: Ingress Rate Data register |
| 150 | */ |
| 151 | |
| 152 | static int mv88e6xxx_g2_clear_irl(struct mv88e6xxx_chip *chip) |
| 153 | { |
| 154 | int port, err; |
| 155 | |
| 156 | /* Init all Ingress Rate Limit resources of all ports */ |
Vivien Didelot | 370b4ff | 2016-09-29 12:21:57 -0400 | [diff] [blame] | 157 | for (port = 0; port < mv88e6xxx_num_ports(chip); ++port) { |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 158 | /* XXX newer chips (like 88E6390) have different 2-bit ops */ |
Vivien Didelot | 9fe850f | 2016-09-29 12:21:54 -0400 | [diff] [blame] | 159 | err = mv88e6xxx_g2_write(chip, GLOBAL2_IRL_CMD, |
| 160 | GLOBAL2_IRL_CMD_OP_INIT_ALL | |
| 161 | (port << 8)); |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 162 | if (err) |
| 163 | break; |
| 164 | |
| 165 | /* Wait for the operation to complete */ |
Vivien Didelot | 9fe850f | 2016-09-29 12:21:54 -0400 | [diff] [blame] | 166 | err = mv88e6xxx_g2_wait(chip, GLOBAL2_IRL_CMD, |
| 167 | GLOBAL2_IRL_CMD_BUSY); |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 168 | if (err) |
| 169 | break; |
| 170 | } |
| 171 | |
| 172 | return err; |
| 173 | } |
| 174 | |
| 175 | /* Offset 0x0D: Switch MAC/WoL/WoF register */ |
| 176 | |
| 177 | static int mv88e6xxx_g2_switch_mac_write(struct mv88e6xxx_chip *chip, |
| 178 | unsigned int pointer, u8 data) |
| 179 | { |
| 180 | u16 val = (pointer << 8) | data; |
| 181 | |
Vivien Didelot | 9fe850f | 2016-09-29 12:21:54 -0400 | [diff] [blame] | 182 | return mv88e6xxx_g2_update(chip, GLOBAL2_SWITCH_MAC, val); |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | int mv88e6xxx_g2_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr) |
| 186 | { |
| 187 | int i, err; |
| 188 | |
| 189 | for (i = 0; i < 6; i++) { |
| 190 | err = mv88e6xxx_g2_switch_mac_write(chip, i, addr[i]); |
| 191 | if (err) |
| 192 | break; |
| 193 | } |
| 194 | |
| 195 | return err; |
| 196 | } |
| 197 | |
| 198 | /* Offset 0x0F: Priority Override Table */ |
| 199 | |
| 200 | static int mv88e6xxx_g2_pot_write(struct mv88e6xxx_chip *chip, int pointer, |
| 201 | u8 data) |
| 202 | { |
| 203 | u16 val = (pointer << 8) | (data & 0x7); |
| 204 | |
Vivien Didelot | 9fe850f | 2016-09-29 12:21:54 -0400 | [diff] [blame] | 205 | return mv88e6xxx_g2_update(chip, GLOBAL2_PRIO_OVERRIDE, val); |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | static int mv88e6xxx_g2_clear_pot(struct mv88e6xxx_chip *chip) |
| 209 | { |
| 210 | int i, err; |
| 211 | |
| 212 | /* Clear all sixteen possible Priority Override entries */ |
| 213 | for (i = 0; i < 16; i++) { |
| 214 | err = mv88e6xxx_g2_pot_write(chip, i, 0); |
| 215 | if (err) |
| 216 | break; |
| 217 | } |
| 218 | |
| 219 | return err; |
| 220 | } |
| 221 | |
| 222 | /* Offset 0x14: EEPROM Command |
Vivien Didelot | 98fc3c6 | 2017-01-12 18:07:16 -0500 | [diff] [blame] | 223 | * Offset 0x15: EEPROM Data (for 16-bit data access) |
| 224 | * Offset 0x15: EEPROM Addr (for 8-bit data access) |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 225 | */ |
| 226 | |
| 227 | static int mv88e6xxx_g2_eeprom_wait(struct mv88e6xxx_chip *chip) |
| 228 | { |
Vivien Didelot | 9fe850f | 2016-09-29 12:21:54 -0400 | [diff] [blame] | 229 | return mv88e6xxx_g2_wait(chip, GLOBAL2_EEPROM_CMD, |
| 230 | GLOBAL2_EEPROM_CMD_BUSY | |
| 231 | GLOBAL2_EEPROM_CMD_RUNNING); |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | static int mv88e6xxx_g2_eeprom_cmd(struct mv88e6xxx_chip *chip, u16 cmd) |
| 235 | { |
| 236 | int err; |
| 237 | |
Vivien Didelot | 9fe850f | 2016-09-29 12:21:54 -0400 | [diff] [blame] | 238 | err = mv88e6xxx_g2_write(chip, GLOBAL2_EEPROM_CMD, cmd); |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 239 | if (err) |
| 240 | return err; |
| 241 | |
| 242 | return mv88e6xxx_g2_eeprom_wait(chip); |
| 243 | } |
| 244 | |
Vivien Didelot | 98fc3c6 | 2017-01-12 18:07:16 -0500 | [diff] [blame] | 245 | static int mv88e6xxx_g2_eeprom_read8(struct mv88e6xxx_chip *chip, |
| 246 | u16 addr, u8 *data) |
| 247 | { |
| 248 | u16 cmd = GLOBAL2_EEPROM_CMD_OP_READ; |
| 249 | int err; |
| 250 | |
| 251 | err = mv88e6xxx_g2_eeprom_wait(chip); |
| 252 | if (err) |
| 253 | return err; |
| 254 | |
| 255 | err = mv88e6xxx_g2_write(chip, GLOBAL2_EEPROM_ADDR, addr); |
| 256 | if (err) |
| 257 | return err; |
| 258 | |
| 259 | err = mv88e6xxx_g2_eeprom_cmd(chip, cmd); |
| 260 | if (err) |
| 261 | return err; |
| 262 | |
| 263 | err = mv88e6xxx_g2_read(chip, GLOBAL2_EEPROM_CMD, &cmd); |
| 264 | if (err) |
| 265 | return err; |
| 266 | |
| 267 | *data = cmd & 0xff; |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | static int mv88e6xxx_g2_eeprom_write8(struct mv88e6xxx_chip *chip, |
| 273 | u16 addr, u8 data) |
| 274 | { |
| 275 | u16 cmd = GLOBAL2_EEPROM_CMD_OP_WRITE | GLOBAL2_EEPROM_CMD_WRITE_EN; |
| 276 | int err; |
| 277 | |
| 278 | err = mv88e6xxx_g2_eeprom_wait(chip); |
| 279 | if (err) |
| 280 | return err; |
| 281 | |
| 282 | err = mv88e6xxx_g2_write(chip, GLOBAL2_EEPROM_ADDR, addr); |
| 283 | if (err) |
| 284 | return err; |
| 285 | |
| 286 | return mv88e6xxx_g2_eeprom_cmd(chip, cmd | data); |
| 287 | } |
| 288 | |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 289 | static int mv88e6xxx_g2_eeprom_read16(struct mv88e6xxx_chip *chip, |
| 290 | u8 addr, u16 *data) |
| 291 | { |
| 292 | u16 cmd = GLOBAL2_EEPROM_CMD_OP_READ | addr; |
| 293 | int err; |
| 294 | |
| 295 | err = mv88e6xxx_g2_eeprom_wait(chip); |
| 296 | if (err) |
| 297 | return err; |
| 298 | |
| 299 | err = mv88e6xxx_g2_eeprom_cmd(chip, cmd); |
| 300 | if (err) |
| 301 | return err; |
| 302 | |
Vivien Didelot | 9fe850f | 2016-09-29 12:21:54 -0400 | [diff] [blame] | 303 | return mv88e6xxx_g2_read(chip, GLOBAL2_EEPROM_DATA, data); |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | static int mv88e6xxx_g2_eeprom_write16(struct mv88e6xxx_chip *chip, |
| 307 | u8 addr, u16 data) |
| 308 | { |
| 309 | u16 cmd = GLOBAL2_EEPROM_CMD_OP_WRITE | addr; |
| 310 | int err; |
| 311 | |
| 312 | err = mv88e6xxx_g2_eeprom_wait(chip); |
| 313 | if (err) |
| 314 | return err; |
| 315 | |
Vivien Didelot | 9fe850f | 2016-09-29 12:21:54 -0400 | [diff] [blame] | 316 | err = mv88e6xxx_g2_write(chip, GLOBAL2_EEPROM_DATA, data); |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 317 | if (err) |
| 318 | return err; |
| 319 | |
| 320 | return mv88e6xxx_g2_eeprom_cmd(chip, cmd); |
| 321 | } |
| 322 | |
Vivien Didelot | 98fc3c6 | 2017-01-12 18:07:16 -0500 | [diff] [blame] | 323 | int mv88e6xxx_g2_get_eeprom8(struct mv88e6xxx_chip *chip, |
| 324 | struct ethtool_eeprom *eeprom, u8 *data) |
| 325 | { |
| 326 | unsigned int offset = eeprom->offset; |
| 327 | unsigned int len = eeprom->len; |
| 328 | int err; |
| 329 | |
| 330 | eeprom->len = 0; |
| 331 | |
| 332 | while (len) { |
| 333 | err = mv88e6xxx_g2_eeprom_read8(chip, offset, data); |
| 334 | if (err) |
| 335 | return err; |
| 336 | |
| 337 | eeprom->len++; |
| 338 | offset++; |
| 339 | data++; |
| 340 | len--; |
| 341 | } |
| 342 | |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | int mv88e6xxx_g2_set_eeprom8(struct mv88e6xxx_chip *chip, |
| 347 | struct ethtool_eeprom *eeprom, u8 *data) |
| 348 | { |
| 349 | unsigned int offset = eeprom->offset; |
| 350 | unsigned int len = eeprom->len; |
| 351 | int err; |
| 352 | |
| 353 | eeprom->len = 0; |
| 354 | |
| 355 | while (len) { |
| 356 | err = mv88e6xxx_g2_eeprom_write8(chip, offset, *data); |
| 357 | if (err) |
| 358 | return err; |
| 359 | |
| 360 | eeprom->len++; |
| 361 | offset++; |
| 362 | data++; |
| 363 | len--; |
| 364 | } |
| 365 | |
| 366 | return 0; |
| 367 | } |
| 368 | |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 369 | int mv88e6xxx_g2_get_eeprom16(struct mv88e6xxx_chip *chip, |
| 370 | struct ethtool_eeprom *eeprom, u8 *data) |
| 371 | { |
| 372 | unsigned int offset = eeprom->offset; |
| 373 | unsigned int len = eeprom->len; |
| 374 | u16 val; |
| 375 | int err; |
| 376 | |
| 377 | eeprom->len = 0; |
| 378 | |
| 379 | if (offset & 1) { |
| 380 | err = mv88e6xxx_g2_eeprom_read16(chip, offset >> 1, &val); |
| 381 | if (err) |
| 382 | return err; |
| 383 | |
| 384 | *data++ = (val >> 8) & 0xff; |
| 385 | |
| 386 | offset++; |
| 387 | len--; |
| 388 | eeprom->len++; |
| 389 | } |
| 390 | |
| 391 | while (len >= 2) { |
| 392 | err = mv88e6xxx_g2_eeprom_read16(chip, offset >> 1, &val); |
| 393 | if (err) |
| 394 | return err; |
| 395 | |
| 396 | *data++ = val & 0xff; |
| 397 | *data++ = (val >> 8) & 0xff; |
| 398 | |
| 399 | offset += 2; |
| 400 | len -= 2; |
| 401 | eeprom->len += 2; |
| 402 | } |
| 403 | |
| 404 | if (len) { |
| 405 | err = mv88e6xxx_g2_eeprom_read16(chip, offset >> 1, &val); |
| 406 | if (err) |
| 407 | return err; |
| 408 | |
| 409 | *data++ = val & 0xff; |
| 410 | |
| 411 | offset++; |
| 412 | len--; |
| 413 | eeprom->len++; |
| 414 | } |
| 415 | |
| 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | int mv88e6xxx_g2_set_eeprom16(struct mv88e6xxx_chip *chip, |
| 420 | struct ethtool_eeprom *eeprom, u8 *data) |
| 421 | { |
| 422 | unsigned int offset = eeprom->offset; |
| 423 | unsigned int len = eeprom->len; |
| 424 | u16 val; |
| 425 | int err; |
| 426 | |
| 427 | /* Ensure the RO WriteEn bit is set */ |
Vivien Didelot | 9fe850f | 2016-09-29 12:21:54 -0400 | [diff] [blame] | 428 | err = mv88e6xxx_g2_read(chip, GLOBAL2_EEPROM_CMD, &val); |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 429 | if (err) |
| 430 | return err; |
| 431 | |
| 432 | if (!(val & GLOBAL2_EEPROM_CMD_WRITE_EN)) |
| 433 | return -EROFS; |
| 434 | |
| 435 | eeprom->len = 0; |
| 436 | |
| 437 | if (offset & 1) { |
| 438 | err = mv88e6xxx_g2_eeprom_read16(chip, offset >> 1, &val); |
| 439 | if (err) |
| 440 | return err; |
| 441 | |
| 442 | val = (*data++ << 8) | (val & 0xff); |
| 443 | |
| 444 | err = mv88e6xxx_g2_eeprom_write16(chip, offset >> 1, val); |
| 445 | if (err) |
| 446 | return err; |
| 447 | |
| 448 | offset++; |
| 449 | len--; |
| 450 | eeprom->len++; |
| 451 | } |
| 452 | |
| 453 | while (len >= 2) { |
| 454 | val = *data++; |
| 455 | val |= *data++ << 8; |
| 456 | |
| 457 | err = mv88e6xxx_g2_eeprom_write16(chip, offset >> 1, val); |
| 458 | if (err) |
| 459 | return err; |
| 460 | |
| 461 | offset += 2; |
| 462 | len -= 2; |
| 463 | eeprom->len += 2; |
| 464 | } |
| 465 | |
| 466 | if (len) { |
| 467 | err = mv88e6xxx_g2_eeprom_read16(chip, offset >> 1, &val); |
| 468 | if (err) |
| 469 | return err; |
| 470 | |
| 471 | val = (val & 0xff00) | *data++; |
| 472 | |
| 473 | err = mv88e6xxx_g2_eeprom_write16(chip, offset >> 1, val); |
| 474 | if (err) |
| 475 | return err; |
| 476 | |
| 477 | offset++; |
| 478 | len--; |
| 479 | eeprom->len++; |
| 480 | } |
| 481 | |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | /* Offset 0x18: SMI PHY Command Register |
| 486 | * Offset 0x19: SMI PHY Data Register |
| 487 | */ |
| 488 | |
| 489 | static int mv88e6xxx_g2_smi_phy_wait(struct mv88e6xxx_chip *chip) |
| 490 | { |
Vivien Didelot | 9fe850f | 2016-09-29 12:21:54 -0400 | [diff] [blame] | 491 | return mv88e6xxx_g2_wait(chip, GLOBAL2_SMI_PHY_CMD, |
| 492 | GLOBAL2_SMI_PHY_CMD_BUSY); |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | static int mv88e6xxx_g2_smi_phy_cmd(struct mv88e6xxx_chip *chip, u16 cmd) |
| 496 | { |
| 497 | int err; |
| 498 | |
Vivien Didelot | 9fe850f | 2016-09-29 12:21:54 -0400 | [diff] [blame] | 499 | err = mv88e6xxx_g2_write(chip, GLOBAL2_SMI_PHY_CMD, cmd); |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 500 | if (err) |
| 501 | return err; |
| 502 | |
| 503 | return mv88e6xxx_g2_smi_phy_wait(chip); |
| 504 | } |
| 505 | |
Andrew Lunn | cf3e80d | 2017-02-04 20:12:24 +0100 | [diff] [blame] | 506 | static int mv88e6xxx_g2_smi_phy_write_addr(struct mv88e6xxx_chip *chip, |
| 507 | int addr, int device, int reg, |
| 508 | bool external) |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 509 | { |
Andrew Lunn | cf3e80d | 2017-02-04 20:12:24 +0100 | [diff] [blame] | 510 | int cmd = SMI_CMD_OP_45_WRITE_ADDR | (addr << 5) | device; |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 511 | int err; |
| 512 | |
Andrew Lunn | cf3e80d | 2017-02-04 20:12:24 +0100 | [diff] [blame] | 513 | if (external) |
| 514 | cmd |= GLOBAL2_SMI_PHY_CMD_EXTERNAL; |
| 515 | |
| 516 | err = mv88e6xxx_g2_smi_phy_wait(chip); |
| 517 | if (err) |
| 518 | return err; |
| 519 | |
| 520 | err = mv88e6xxx_g2_write(chip, GLOBAL2_SMI_PHY_DATA, reg); |
| 521 | if (err) |
| 522 | return err; |
| 523 | |
| 524 | return mv88e6xxx_g2_smi_phy_cmd(chip, cmd); |
| 525 | } |
| 526 | |
| 527 | int mv88e6xxx_g2_smi_phy_read_c45(struct mv88e6xxx_chip *chip, int addr, |
| 528 | int reg_c45, u16 *val, bool external) |
| 529 | { |
| 530 | int device = (reg_c45 >> 16) & 0x1f; |
| 531 | int reg = reg_c45 & 0xffff; |
| 532 | int err; |
| 533 | u16 cmd; |
| 534 | |
| 535 | err = mv88e6xxx_g2_smi_phy_write_addr(chip, addr, device, reg, |
| 536 | external); |
| 537 | if (err) |
| 538 | return err; |
| 539 | |
| 540 | cmd = GLOBAL2_SMI_PHY_CMD_OP_45_READ_DATA | (addr << 5) | device; |
| 541 | |
| 542 | if (external) |
| 543 | cmd |= GLOBAL2_SMI_PHY_CMD_EXTERNAL; |
| 544 | |
| 545 | err = mv88e6xxx_g2_smi_phy_cmd(chip, cmd); |
| 546 | if (err) |
| 547 | return err; |
| 548 | |
| 549 | err = mv88e6xxx_g2_read(chip, GLOBAL2_SMI_PHY_DATA, val); |
| 550 | if (err) |
| 551 | return err; |
| 552 | |
| 553 | err = *val; |
| 554 | |
| 555 | return 0; |
| 556 | } |
| 557 | |
| 558 | int mv88e6xxx_g2_smi_phy_read_c22(struct mv88e6xxx_chip *chip, int addr, |
| 559 | int reg, u16 *val, bool external) |
| 560 | { |
| 561 | u16 cmd = GLOBAL2_SMI_PHY_CMD_OP_22_READ_DATA | (addr << 5) | reg; |
| 562 | int err; |
| 563 | |
| 564 | if (external) |
Andrew Lunn | c61a6a7 | 2017-01-24 14:53:51 +0100 | [diff] [blame] | 565 | cmd |= GLOBAL2_SMI_PHY_CMD_EXTERNAL; |
| 566 | |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 567 | err = mv88e6xxx_g2_smi_phy_wait(chip); |
| 568 | if (err) |
| 569 | return err; |
| 570 | |
| 571 | err = mv88e6xxx_g2_smi_phy_cmd(chip, cmd); |
| 572 | if (err) |
| 573 | return err; |
| 574 | |
Vivien Didelot | 9fe850f | 2016-09-29 12:21:54 -0400 | [diff] [blame] | 575 | return mv88e6xxx_g2_read(chip, GLOBAL2_SMI_PHY_DATA, val); |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 576 | } |
| 577 | |
Andrew Lunn | cf3e80d | 2017-02-04 20:12:24 +0100 | [diff] [blame] | 578 | int mv88e6xxx_g2_smi_phy_read(struct mv88e6xxx_chip *chip, |
| 579 | struct mii_bus *bus, |
| 580 | int addr, int reg, u16 *val) |
| 581 | { |
| 582 | struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv; |
| 583 | bool external = mdio_bus->external; |
| 584 | |
| 585 | if (reg & MII_ADDR_C45) |
| 586 | return mv88e6xxx_g2_smi_phy_read_c45(chip, addr, reg, val, |
| 587 | external); |
| 588 | return mv88e6xxx_g2_smi_phy_read_c22(chip, addr, reg, val, external); |
| 589 | } |
| 590 | |
| 591 | int mv88e6xxx_g2_smi_phy_write_c45(struct mv88e6xxx_chip *chip, int addr, |
| 592 | int reg_c45, u16 val, bool external) |
| 593 | { |
| 594 | int device = (reg_c45 >> 16) & 0x1f; |
| 595 | int reg = reg_c45 & 0xffff; |
| 596 | int err; |
| 597 | u16 cmd; |
| 598 | |
| 599 | err = mv88e6xxx_g2_smi_phy_write_addr(chip, addr, device, reg, |
| 600 | external); |
| 601 | if (err) |
| 602 | return err; |
| 603 | |
| 604 | cmd = GLOBAL2_SMI_PHY_CMD_OP_45_WRITE_DATA | (addr << 5) | device; |
| 605 | |
| 606 | if (external) |
| 607 | cmd |= GLOBAL2_SMI_PHY_CMD_EXTERNAL; |
| 608 | |
| 609 | err = mv88e6xxx_g2_write(chip, GLOBAL2_SMI_PHY_DATA, val); |
| 610 | if (err) |
| 611 | return err; |
| 612 | |
| 613 | err = mv88e6xxx_g2_smi_phy_cmd(chip, cmd); |
| 614 | if (err) |
| 615 | return err; |
| 616 | |
| 617 | return 0; |
| 618 | } |
| 619 | |
| 620 | int mv88e6xxx_g2_smi_phy_write_c22(struct mv88e6xxx_chip *chip, int addr, |
| 621 | int reg, u16 val, bool external) |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 622 | { |
| 623 | u16 cmd = GLOBAL2_SMI_PHY_CMD_OP_22_WRITE_DATA | (addr << 5) | reg; |
| 624 | int err; |
| 625 | |
Andrew Lunn | cf3e80d | 2017-02-04 20:12:24 +0100 | [diff] [blame] | 626 | if (external) |
Andrew Lunn | c61a6a7 | 2017-01-24 14:53:51 +0100 | [diff] [blame] | 627 | cmd |= GLOBAL2_SMI_PHY_CMD_EXTERNAL; |
| 628 | |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 629 | err = mv88e6xxx_g2_smi_phy_wait(chip); |
| 630 | if (err) |
| 631 | return err; |
| 632 | |
Vivien Didelot | 9fe850f | 2016-09-29 12:21:54 -0400 | [diff] [blame] | 633 | err = mv88e6xxx_g2_write(chip, GLOBAL2_SMI_PHY_DATA, val); |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 634 | if (err) |
| 635 | return err; |
| 636 | |
| 637 | return mv88e6xxx_g2_smi_phy_cmd(chip, cmd); |
| 638 | } |
| 639 | |
Andrew Lunn | cf3e80d | 2017-02-04 20:12:24 +0100 | [diff] [blame] | 640 | int mv88e6xxx_g2_smi_phy_write(struct mv88e6xxx_chip *chip, |
| 641 | struct mii_bus *bus, |
| 642 | int addr, int reg, u16 val) |
| 643 | { |
| 644 | struct mv88e6xxx_mdio_bus *mdio_bus = bus->priv; |
| 645 | bool external = mdio_bus->external; |
| 646 | |
| 647 | if (reg & MII_ADDR_C45) |
| 648 | return mv88e6xxx_g2_smi_phy_write_c45(chip, addr, reg, val, |
| 649 | external); |
| 650 | |
| 651 | return mv88e6xxx_g2_smi_phy_write_c22(chip, addr, reg, val, external); |
| 652 | } |
| 653 | |
Andrew Lunn | fcd2516 | 2017-02-09 00:03:42 +0100 | [diff] [blame] | 654 | static int mv88e6097_watchdog_action(struct mv88e6xxx_chip *chip, int irq) |
| 655 | { |
| 656 | u16 reg; |
| 657 | |
| 658 | mv88e6xxx_g2_read(chip, GLOBAL2_WDOG_CONTROL, ®); |
| 659 | |
| 660 | dev_info(chip->dev, "Watchdog event: 0x%04x", reg); |
| 661 | |
| 662 | return IRQ_HANDLED; |
| 663 | } |
| 664 | |
| 665 | static void mv88e6097_watchdog_free(struct mv88e6xxx_chip *chip) |
| 666 | { |
| 667 | u16 reg; |
| 668 | |
| 669 | mv88e6xxx_g2_read(chip, GLOBAL2_WDOG_CONTROL, ®); |
| 670 | |
| 671 | reg &= ~(GLOBAL2_WDOG_CONTROL_EGRESS_ENABLE | |
| 672 | GLOBAL2_WDOG_CONTROL_QC_ENABLE); |
| 673 | |
| 674 | mv88e6xxx_g2_write(chip, GLOBAL2_WDOG_CONTROL, reg); |
| 675 | } |
| 676 | |
| 677 | static int mv88e6097_watchdog_setup(struct mv88e6xxx_chip *chip) |
| 678 | { |
| 679 | return mv88e6xxx_g2_write(chip, GLOBAL2_WDOG_CONTROL, |
| 680 | GLOBAL2_WDOG_CONTROL_EGRESS_ENABLE | |
| 681 | GLOBAL2_WDOG_CONTROL_QC_ENABLE | |
| 682 | GLOBAL2_WDOG_CONTROL_SWRESET); |
| 683 | } |
| 684 | |
| 685 | const struct mv88e6xxx_irq_ops mv88e6097_watchdog_ops = { |
| 686 | .irq_action = mv88e6097_watchdog_action, |
| 687 | .irq_setup = mv88e6097_watchdog_setup, |
| 688 | .irq_free = mv88e6097_watchdog_free, |
| 689 | }; |
| 690 | |
Andrew Lunn | 6130373 | 2017-02-09 00:03:43 +0100 | [diff] [blame] | 691 | static int mv88e6390_watchdog_setup(struct mv88e6xxx_chip *chip) |
| 692 | { |
| 693 | return mv88e6xxx_g2_update(chip, GLOBAL2_WDOG_CONTROL, |
| 694 | GLOBAL2_WDOG_INT_ENABLE | |
| 695 | GLOBAL2_WDOG_CUT_THROUGH | |
| 696 | GLOBAL2_WDOG_QUEUE_CONTROLLER | |
| 697 | GLOBAL2_WDOG_EGRESS | |
| 698 | GLOBAL2_WDOG_FORCE_IRQ); |
| 699 | } |
| 700 | |
| 701 | static int mv88e6390_watchdog_action(struct mv88e6xxx_chip *chip, int irq) |
| 702 | { |
| 703 | int err; |
| 704 | u16 reg; |
| 705 | |
| 706 | mv88e6xxx_g2_write(chip, GLOBAL2_WDOG_CONTROL, GLOBAL2_WDOG_EVENT); |
| 707 | err = mv88e6xxx_g2_read(chip, GLOBAL2_WDOG_CONTROL, ®); |
| 708 | |
| 709 | dev_info(chip->dev, "Watchdog event: 0x%04x", |
| 710 | reg & GLOBAL2_WDOG_DATA_MASK); |
| 711 | |
| 712 | mv88e6xxx_g2_write(chip, GLOBAL2_WDOG_CONTROL, GLOBAL2_WDOG_HISTORY); |
| 713 | err = mv88e6xxx_g2_read(chip, GLOBAL2_WDOG_CONTROL, ®); |
| 714 | |
| 715 | dev_info(chip->dev, "Watchdog history: 0x%04x", |
| 716 | reg & GLOBAL2_WDOG_DATA_MASK); |
| 717 | |
| 718 | /* Trigger a software reset to try to recover the switch */ |
| 719 | if (chip->info->ops->reset) |
| 720 | chip->info->ops->reset(chip); |
| 721 | |
| 722 | mv88e6390_watchdog_setup(chip); |
| 723 | |
| 724 | return IRQ_HANDLED; |
| 725 | } |
| 726 | |
| 727 | static void mv88e6390_watchdog_free(struct mv88e6xxx_chip *chip) |
| 728 | { |
| 729 | mv88e6xxx_g2_update(chip, GLOBAL2_WDOG_CONTROL, |
| 730 | GLOBAL2_WDOG_INT_ENABLE); |
| 731 | } |
| 732 | |
| 733 | const struct mv88e6xxx_irq_ops mv88e6390_watchdog_ops = { |
| 734 | .irq_action = mv88e6390_watchdog_action, |
| 735 | .irq_setup = mv88e6390_watchdog_setup, |
| 736 | .irq_free = mv88e6390_watchdog_free, |
| 737 | }; |
| 738 | |
Andrew Lunn | fcd2516 | 2017-02-09 00:03:42 +0100 | [diff] [blame] | 739 | static irqreturn_t mv88e6xxx_g2_watchdog_thread_fn(int irq, void *dev_id) |
| 740 | { |
| 741 | struct mv88e6xxx_chip *chip = dev_id; |
| 742 | irqreturn_t ret = IRQ_NONE; |
| 743 | |
| 744 | mutex_lock(&chip->reg_lock); |
| 745 | if (chip->info->ops->watchdog_ops->irq_action) |
| 746 | ret = chip->info->ops->watchdog_ops->irq_action(chip, irq); |
| 747 | mutex_unlock(&chip->reg_lock); |
| 748 | |
| 749 | return ret; |
| 750 | } |
| 751 | |
| 752 | static void mv88e6xxx_g2_watchdog_free(struct mv88e6xxx_chip *chip) |
| 753 | { |
| 754 | mutex_lock(&chip->reg_lock); |
| 755 | if (chip->info->ops->watchdog_ops->irq_free) |
| 756 | chip->info->ops->watchdog_ops->irq_free(chip); |
| 757 | mutex_unlock(&chip->reg_lock); |
| 758 | |
| 759 | free_irq(chip->watchdog_irq, chip); |
| 760 | irq_dispose_mapping(chip->watchdog_irq); |
| 761 | } |
| 762 | |
| 763 | static int mv88e6xxx_g2_watchdog_setup(struct mv88e6xxx_chip *chip) |
| 764 | { |
| 765 | int err; |
| 766 | |
| 767 | chip->watchdog_irq = irq_find_mapping(chip->g2_irq.domain, |
| 768 | GLOBAL2_INT_SOURCE_WATCHDOG); |
| 769 | if (chip->watchdog_irq < 0) |
| 770 | return chip->watchdog_irq; |
| 771 | |
| 772 | err = request_threaded_irq(chip->watchdog_irq, NULL, |
| 773 | mv88e6xxx_g2_watchdog_thread_fn, |
| 774 | IRQF_ONESHOT | IRQF_TRIGGER_FALLING, |
| 775 | "mv88e6xxx-watchdog", chip); |
| 776 | if (err) |
| 777 | return err; |
| 778 | |
| 779 | mutex_lock(&chip->reg_lock); |
| 780 | if (chip->info->ops->watchdog_ops->irq_setup) |
| 781 | err = chip->info->ops->watchdog_ops->irq_setup(chip); |
| 782 | mutex_unlock(&chip->reg_lock); |
| 783 | |
| 784 | return err; |
| 785 | } |
| 786 | |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 787 | static void mv88e6xxx_g2_irq_mask(struct irq_data *d) |
| 788 | { |
| 789 | struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d); |
| 790 | unsigned int n = d->hwirq; |
| 791 | |
| 792 | chip->g2_irq.masked |= (1 << n); |
| 793 | } |
| 794 | |
| 795 | static void mv88e6xxx_g2_irq_unmask(struct irq_data *d) |
| 796 | { |
| 797 | struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d); |
| 798 | unsigned int n = d->hwirq; |
| 799 | |
| 800 | chip->g2_irq.masked &= ~(1 << n); |
| 801 | } |
| 802 | |
| 803 | static irqreturn_t mv88e6xxx_g2_irq_thread_fn(int irq, void *dev_id) |
| 804 | { |
| 805 | struct mv88e6xxx_chip *chip = dev_id; |
| 806 | unsigned int nhandled = 0; |
| 807 | unsigned int sub_irq; |
| 808 | unsigned int n; |
| 809 | int err; |
| 810 | u16 reg; |
| 811 | |
| 812 | mutex_lock(&chip->reg_lock); |
| 813 | err = mv88e6xxx_g2_read(chip, GLOBAL2_INT_SOURCE, ®); |
| 814 | mutex_unlock(&chip->reg_lock); |
| 815 | if (err) |
| 816 | goto out; |
| 817 | |
| 818 | for (n = 0; n < 16; ++n) { |
| 819 | if (reg & (1 << n)) { |
| 820 | sub_irq = irq_find_mapping(chip->g2_irq.domain, n); |
| 821 | handle_nested_irq(sub_irq); |
| 822 | ++nhandled; |
| 823 | } |
| 824 | } |
| 825 | out: |
| 826 | return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE); |
| 827 | } |
| 828 | |
| 829 | static void mv88e6xxx_g2_irq_bus_lock(struct irq_data *d) |
| 830 | { |
| 831 | struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d); |
| 832 | |
| 833 | mutex_lock(&chip->reg_lock); |
| 834 | } |
| 835 | |
| 836 | static void mv88e6xxx_g2_irq_bus_sync_unlock(struct irq_data *d) |
| 837 | { |
| 838 | struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d); |
| 839 | |
| 840 | mv88e6xxx_g2_write(chip, GLOBAL2_INT_MASK, ~chip->g2_irq.masked); |
| 841 | |
| 842 | mutex_unlock(&chip->reg_lock); |
| 843 | } |
| 844 | |
| 845 | static struct irq_chip mv88e6xxx_g2_irq_chip = { |
| 846 | .name = "mv88e6xxx-g2", |
| 847 | .irq_mask = mv88e6xxx_g2_irq_mask, |
| 848 | .irq_unmask = mv88e6xxx_g2_irq_unmask, |
| 849 | .irq_bus_lock = mv88e6xxx_g2_irq_bus_lock, |
| 850 | .irq_bus_sync_unlock = mv88e6xxx_g2_irq_bus_sync_unlock, |
| 851 | }; |
| 852 | |
| 853 | static int mv88e6xxx_g2_irq_domain_map(struct irq_domain *d, |
| 854 | unsigned int irq, |
| 855 | irq_hw_number_t hwirq) |
| 856 | { |
| 857 | struct mv88e6xxx_chip *chip = d->host_data; |
| 858 | |
| 859 | irq_set_chip_data(irq, d->host_data); |
| 860 | irq_set_chip_and_handler(irq, &chip->g2_irq.chip, handle_level_irq); |
| 861 | irq_set_noprobe(irq); |
| 862 | |
| 863 | return 0; |
| 864 | } |
| 865 | |
| 866 | static const struct irq_domain_ops mv88e6xxx_g2_irq_domain_ops = { |
| 867 | .map = mv88e6xxx_g2_irq_domain_map, |
| 868 | .xlate = irq_domain_xlate_twocell, |
| 869 | }; |
| 870 | |
| 871 | void mv88e6xxx_g2_irq_free(struct mv88e6xxx_chip *chip) |
| 872 | { |
| 873 | int irq, virq; |
| 874 | |
Andrew Lunn | fcd2516 | 2017-02-09 00:03:42 +0100 | [diff] [blame] | 875 | mv88e6xxx_g2_watchdog_free(chip); |
| 876 | |
Andrew Lunn | 8e757eb | 2016-11-20 20:14:18 +0100 | [diff] [blame] | 877 | free_irq(chip->device_irq, chip); |
| 878 | irq_dispose_mapping(chip->device_irq); |
| 879 | |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 880 | for (irq = 0; irq < 16; irq++) { |
| 881 | virq = irq_find_mapping(chip->g2_irq.domain, irq); |
| 882 | irq_dispose_mapping(virq); |
| 883 | } |
| 884 | |
| 885 | irq_domain_remove(chip->g2_irq.domain); |
| 886 | } |
| 887 | |
| 888 | int mv88e6xxx_g2_irq_setup(struct mv88e6xxx_chip *chip) |
| 889 | { |
Andrew Lunn | 8e757eb | 2016-11-20 20:14:18 +0100 | [diff] [blame] | 890 | int err, irq, virq; |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 891 | |
| 892 | if (!chip->dev->of_node) |
| 893 | return -EINVAL; |
| 894 | |
| 895 | chip->g2_irq.domain = irq_domain_add_simple( |
| 896 | chip->dev->of_node, 16, 0, &mv88e6xxx_g2_irq_domain_ops, chip); |
| 897 | if (!chip->g2_irq.domain) |
| 898 | return -ENOMEM; |
| 899 | |
| 900 | for (irq = 0; irq < 16; irq++) |
| 901 | irq_create_mapping(chip->g2_irq.domain, irq); |
| 902 | |
| 903 | chip->g2_irq.chip = mv88e6xxx_g2_irq_chip; |
| 904 | chip->g2_irq.masked = ~0; |
| 905 | |
Andrew Lunn | 8e757eb | 2016-11-20 20:14:18 +0100 | [diff] [blame] | 906 | chip->device_irq = irq_find_mapping(chip->g1_irq.domain, |
| 907 | GLOBAL_STATUS_IRQ_DEVICE); |
| 908 | if (chip->device_irq < 0) { |
| 909 | err = chip->device_irq; |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 910 | goto out; |
| 911 | } |
| 912 | |
Andrew Lunn | 8e757eb | 2016-11-20 20:14:18 +0100 | [diff] [blame] | 913 | err = request_threaded_irq(chip->device_irq, NULL, |
| 914 | mv88e6xxx_g2_irq_thread_fn, |
| 915 | IRQF_ONESHOT, "mv88e6xxx-g1", chip); |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 916 | if (err) |
| 917 | goto out; |
| 918 | |
Andrew Lunn | fcd2516 | 2017-02-09 00:03:42 +0100 | [diff] [blame] | 919 | return mv88e6xxx_g2_watchdog_setup(chip); |
Andrew Lunn | 8e757eb | 2016-11-20 20:14:18 +0100 | [diff] [blame] | 920 | |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 921 | out: |
Andrew Lunn | 8e757eb | 2016-11-20 20:14:18 +0100 | [diff] [blame] | 922 | for (irq = 0; irq < 16; irq++) { |
| 923 | virq = irq_find_mapping(chip->g2_irq.domain, irq); |
| 924 | irq_dispose_mapping(virq); |
| 925 | } |
| 926 | |
| 927 | irq_domain_remove(chip->g2_irq.domain); |
Andrew Lunn | dc30c35 | 2016-10-16 19:56:49 +0200 | [diff] [blame] | 928 | |
| 929 | return err; |
| 930 | } |
| 931 | |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 932 | int mv88e6xxx_g2_setup(struct mv88e6xxx_chip *chip) |
| 933 | { |
| 934 | u16 reg; |
| 935 | int err; |
| 936 | |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 937 | /* Ignore removed tag data on doubly tagged packets, disable |
| 938 | * flow control messages, force flow control priority to the |
| 939 | * highest, and send all special multicast frames to the CPU |
| 940 | * port at the highest priority. |
| 941 | */ |
| 942 | reg = GLOBAL2_SWITCH_MGMT_FORCE_FLOW_CTRL_PRI | (0x7 << 4); |
| 943 | if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_MGMT_EN_0X) || |
| 944 | mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_MGMT_EN_2X)) |
| 945 | reg |= GLOBAL2_SWITCH_MGMT_RSVD2CPU | 0x7; |
Vivien Didelot | 9fe850f | 2016-09-29 12:21:54 -0400 | [diff] [blame] | 946 | err = mv88e6xxx_g2_write(chip, GLOBAL2_SWITCH_MGMT, reg); |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 947 | if (err) |
| 948 | return err; |
| 949 | |
| 950 | /* Program the DSA routing table. */ |
| 951 | err = mv88e6xxx_g2_set_device_mapping(chip); |
| 952 | if (err) |
| 953 | return err; |
| 954 | |
| 955 | /* Clear all trunk masks and mapping. */ |
| 956 | err = mv88e6xxx_g2_clear_trunk(chip); |
| 957 | if (err) |
| 958 | return err; |
| 959 | |
| 960 | if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_IRL)) { |
| 961 | /* Disable ingress rate limiting by resetting all per port |
| 962 | * ingress rate limit resources to their initial state. |
| 963 | */ |
| 964 | err = mv88e6xxx_g2_clear_irl(chip); |
| 965 | if (err) |
| 966 | return err; |
| 967 | } |
| 968 | |
| 969 | if (mv88e6xxx_has(chip, MV88E6XXX_FLAGS_PVT)) { |
| 970 | /* Initialize Cross-chip Port VLAN Table to reset defaults */ |
Vivien Didelot | 9fe850f | 2016-09-29 12:21:54 -0400 | [diff] [blame] | 971 | err = mv88e6xxx_g2_write(chip, GLOBAL2_PVT_ADDR, |
| 972 | GLOBAL2_PVT_ADDR_OP_INIT_ONES); |
Vivien Didelot | ec56127 | 2016-09-02 14:45:33 -0400 | [diff] [blame] | 973 | if (err) |
| 974 | return err; |
| 975 | } |
| 976 | |
| 977 | if (mv88e6xxx_has(chip, MV88E6XXX_FLAG_G2_POT)) { |
| 978 | /* Clear the priority override table. */ |
| 979 | err = mv88e6xxx_g2_clear_pot(chip); |
| 980 | if (err) |
| 981 | return err; |
| 982 | } |
| 983 | |
| 984 | return 0; |
| 985 | } |