Lines Matching +full:chip +full:- +full:reset
1 // SPDX-License-Identifier: GPL-2.0-only
195 /* the built-in PHYs are of type LAN911X */
211 regmap_reg_range(0x7c, 0x7e), /* MAC & reset */
248 * tries to detect and read an external EEPROM after reset and acts as in lan9303_read()
256 if (ret != -EAGAIN) in lan9303_read()
261 return -EIO; in lan9303_read()
264 static int lan9303_read_wait(struct lan9303 *chip, int offset, u32 mask) in lan9303_read_wait() argument
272 ret = lan9303_read(chip->regmap, offset, ®); in lan9303_read_wait()
274 dev_err(chip->dev, "%s failed to read offset %d: %d\n", in lan9303_read_wait()
283 return -ETIMEDOUT; in lan9303_read_wait()
286 static int lan9303_virt_phy_reg_read(struct lan9303 *chip, int regnum) in lan9303_virt_phy_reg_read() argument
292 return -EINVAL; in lan9303_virt_phy_reg_read()
294 ret = lan9303_read(chip->regmap, LAN9303_VIRT_PHY_BASE + regnum, &val); in lan9303_virt_phy_reg_read()
301 static int lan9303_virt_phy_reg_write(struct lan9303 *chip, int regnum, u16 val) in lan9303_virt_phy_reg_write() argument
304 return -EINVAL; in lan9303_virt_phy_reg_write()
306 return regmap_write(chip->regmap, LAN9303_VIRT_PHY_BASE + regnum, val); in lan9303_virt_phy_reg_write()
309 static int lan9303_indirect_phy_wait_for_completion(struct lan9303 *chip) in lan9303_indirect_phy_wait_for_completion() argument
311 return lan9303_read_wait(chip, LAN9303_PMI_ACCESS, in lan9303_indirect_phy_wait_for_completion()
315 static int lan9303_indirect_phy_read(struct lan9303 *chip, int addr, int regnum) in lan9303_indirect_phy_read() argument
323 mutex_lock(&chip->indirect_mutex); in lan9303_indirect_phy_read()
325 ret = lan9303_indirect_phy_wait_for_completion(chip); in lan9303_indirect_phy_read()
330 ret = regmap_write(chip->regmap, LAN9303_PMI_ACCESS, val); in lan9303_indirect_phy_read()
334 ret = lan9303_indirect_phy_wait_for_completion(chip); in lan9303_indirect_phy_read()
339 ret = lan9303_read(chip->regmap, LAN9303_PMI_DATA, &val); in lan9303_indirect_phy_read()
343 mutex_unlock(&chip->indirect_mutex); in lan9303_indirect_phy_read()
348 mutex_unlock(&chip->indirect_mutex); in lan9303_indirect_phy_read()
352 static int lan9303_indirect_phy_write(struct lan9303 *chip, int addr, in lan9303_indirect_phy_write() argument
362 mutex_lock(&chip->indirect_mutex); in lan9303_indirect_phy_write()
364 ret = lan9303_indirect_phy_wait_for_completion(chip); in lan9303_indirect_phy_write()
369 ret = regmap_write(chip->regmap, LAN9303_PMI_DATA, val); in lan9303_indirect_phy_write()
374 ret = regmap_write(chip->regmap, LAN9303_PMI_ACCESS, reg); in lan9303_indirect_phy_write()
377 mutex_unlock(&chip->indirect_mutex); in lan9303_indirect_phy_write()
387 static int lan9303_switch_wait_for_completion(struct lan9303 *chip) in lan9303_switch_wait_for_completion() argument
389 return lan9303_read_wait(chip, LAN9303_SWITCH_CSR_CMD, in lan9303_switch_wait_for_completion()
393 static int lan9303_write_switch_reg(struct lan9303 *chip, u16 regnum, u32 val) in lan9303_write_switch_reg() argument
402 mutex_lock(&chip->indirect_mutex); in lan9303_write_switch_reg()
404 ret = lan9303_switch_wait_for_completion(chip); in lan9303_write_switch_reg()
408 ret = regmap_write(chip->regmap, LAN9303_SWITCH_CSR_DATA, val); in lan9303_write_switch_reg()
410 dev_err(chip->dev, "Failed to write csr data reg: %d\n", ret); in lan9303_write_switch_reg()
415 ret = regmap_write(chip->regmap, LAN9303_SWITCH_CSR_CMD, reg); in lan9303_write_switch_reg()
417 dev_err(chip->dev, "Failed to write csr command reg: %d\n", in lan9303_write_switch_reg()
421 mutex_unlock(&chip->indirect_mutex); in lan9303_write_switch_reg()
425 static int lan9303_read_switch_reg(struct lan9303 *chip, u16 regnum, u32 *val) in lan9303_read_switch_reg() argument
435 mutex_lock(&chip->indirect_mutex); in lan9303_read_switch_reg()
437 ret = lan9303_switch_wait_for_completion(chip); in lan9303_read_switch_reg()
442 ret = regmap_write(chip->regmap, LAN9303_SWITCH_CSR_CMD, reg); in lan9303_read_switch_reg()
444 dev_err(chip->dev, "Failed to write csr command reg: %d\n", in lan9303_read_switch_reg()
449 ret = lan9303_switch_wait_for_completion(chip); in lan9303_read_switch_reg()
453 ret = lan9303_read(chip->regmap, LAN9303_SWITCH_CSR_DATA, val); in lan9303_read_switch_reg()
455 dev_err(chip->dev, "Failed to read csr data reg: %d\n", ret); in lan9303_read_switch_reg()
457 mutex_unlock(&chip->indirect_mutex); in lan9303_read_switch_reg()
461 static int lan9303_write_switch_reg_mask(struct lan9303 *chip, u16 regnum, in lan9303_write_switch_reg_mask() argument
467 ret = lan9303_read_switch_reg(chip, regnum, ®); in lan9303_write_switch_reg_mask()
473 return lan9303_write_switch_reg(chip, regnum, reg); in lan9303_write_switch_reg_mask()
476 static int lan9303_write_switch_port(struct lan9303 *chip, int port, in lan9303_write_switch_port() argument
480 chip, LAN9303_SWITCH_PORT_REG(port, regnum), val); in lan9303_write_switch_port()
483 static int lan9303_read_switch_port(struct lan9303 *chip, int port, in lan9303_read_switch_port() argument
487 chip, LAN9303_SWITCH_PORT_REG(port, regnum), val); in lan9303_read_switch_port()
490 static int lan9303_detect_phy_setup(struct lan9303 *chip) in lan9303_detect_phy_setup() argument
494 /* Calculate chip->phy_addr_base: in lan9303_detect_phy_setup()
496 * using IDs 0-1-2 or IDs 1-2-3. We cannot read back the in lan9303_detect_phy_setup()
500 * and the IDs are 0-1-2, else it contains something different from in lan9303_detect_phy_setup()
501 * 0x0000, which means 'phy_addr_sel_strap' is 1 and the IDs are 1-2-3. in lan9303_detect_phy_setup()
504 reg = chip->ops->phy_read(chip, 3, MII_LAN911X_SPECIAL_MODES); in lan9303_detect_phy_setup()
506 dev_err(chip->dev, "Failed to detect phy config: %d\n", reg); in lan9303_detect_phy_setup()
510 chip->phy_addr_base = reg != 0 && reg != 0xffff; in lan9303_detect_phy_setup()
512 dev_dbg(chip->dev, "Phy setup '%s' detected\n", in lan9303_detect_phy_setup()
513 chip->phy_addr_base ? "1-2-3" : "0-1-2"); in lan9303_detect_phy_setup()
518 /* Map ALR-port bits to port bitmap, and back */
524 lan9303_alr_cache_find_free(struct lan9303 *chip) in lan9303_alr_cache_find_free() argument
527 struct lan9303_alr_cache_entry *entr = chip->alr_cache; in lan9303_alr_cache_find_free()
530 if (entr->port_map == 0) in lan9303_alr_cache_find_free()
538 lan9303_alr_cache_find_mac(struct lan9303 *chip, const u8 *mac_addr) in lan9303_alr_cache_find_mac() argument
541 struct lan9303_alr_cache_entry *entr = chip->alr_cache; in lan9303_alr_cache_find_mac()
547 if (ether_addr_equal(entr->mac_addr, mac_addr)) in lan9303_alr_cache_find_mac()
553 static int lan9303_csr_reg_wait(struct lan9303 *chip, int regno, u32 mask) in lan9303_csr_reg_wait() argument
560 lan9303_read_switch_reg(chip, regno, ®); in lan9303_csr_reg_wait()
566 return -ETIMEDOUT; in lan9303_csr_reg_wait()
569 static int lan9303_alr_make_entry_raw(struct lan9303 *chip, u32 dat0, u32 dat1) in lan9303_alr_make_entry_raw() argument
571 lan9303_write_switch_reg(chip, LAN9303_SWE_ALR_WR_DAT_0, dat0); in lan9303_alr_make_entry_raw()
572 lan9303_write_switch_reg(chip, LAN9303_SWE_ALR_WR_DAT_1, dat1); in lan9303_alr_make_entry_raw()
573 lan9303_write_switch_reg(chip, LAN9303_SWE_ALR_CMD, in lan9303_alr_make_entry_raw()
575 lan9303_csr_reg_wait(chip, LAN9303_SWE_ALR_CMD_STS, ALR_STS_MAKE_PEND); in lan9303_alr_make_entry_raw()
576 lan9303_write_switch_reg(chip, LAN9303_SWE_ALR_CMD, 0); in lan9303_alr_make_entry_raw()
581 typedef int alr_loop_cb_t(struct lan9303 *chip, u32 dat0, u32 dat1,
584 static int lan9303_alr_loop(struct lan9303 *chip, alr_loop_cb_t *cb, void *ctx) in lan9303_alr_loop() argument
588 mutex_lock(&chip->alr_mutex); in lan9303_alr_loop()
589 lan9303_write_switch_reg(chip, LAN9303_SWE_ALR_CMD, in lan9303_alr_loop()
591 lan9303_write_switch_reg(chip, LAN9303_SWE_ALR_CMD, 0); in lan9303_alr_loop()
597 lan9303_read_switch_reg(chip, LAN9303_SWE_ALR_RD_DAT_0, &dat0); in lan9303_alr_loop()
598 lan9303_read_switch_reg(chip, LAN9303_SWE_ALR_RD_DAT_1, &dat1); in lan9303_alr_loop()
606 ret = cb(chip, dat0, dat1, portmap, ctx); in lan9303_alr_loop()
610 lan9303_write_switch_reg(chip, LAN9303_SWE_ALR_CMD, in lan9303_alr_loop()
612 lan9303_write_switch_reg(chip, LAN9303_SWE_ALR_CMD, 0); in lan9303_alr_loop()
614 mutex_unlock(&chip->alr_mutex); in lan9303_alr_loop()
633 /* Clear learned (non-static) entry on given port */
634 static int alr_loop_cb_del_port_learned(struct lan9303 *chip, u32 dat0, in alr_loop_cb_del_port_learned() argument
638 int port = del_ctx->port; in alr_loop_cb_del_port_learned()
645 lan9303_alr_make_entry_raw(chip, dat0, dat1); in alr_loop_cb_del_port_learned()
656 static int alr_loop_cb_fdb_port_dump(struct lan9303 *chip, u32 dat0, in alr_loop_cb_fdb_port_dump() argument
663 if ((BIT(dump_ctx->port) & portmap) == 0) in alr_loop_cb_fdb_port_dump()
668 return dump_ctx->cb(mac, 0, is_static, dump_ctx->data); in alr_loop_cb_fdb_port_dump()
672 static void lan9303_alr_set_entry(struct lan9303 *chip, const u8 *mac, in lan9303_alr_set_entry() argument
677 dev_dbg(chip->dev, "%s(%pM, %d)\n", __func__, mac, port_map); in lan9303_alr_set_entry()
698 lan9303_alr_make_entry_raw(chip, dat0, dat1); in lan9303_alr_set_entry()
702 static int lan9303_alr_add_port(struct lan9303 *chip, const u8 *mac, int port, in lan9303_alr_add_port() argument
707 mutex_lock(&chip->alr_mutex); in lan9303_alr_add_port()
708 entr = lan9303_alr_cache_find_mac(chip, mac); in lan9303_alr_add_port()
710 entr = lan9303_alr_cache_find_free(chip); in lan9303_alr_add_port()
712 mutex_unlock(&chip->alr_mutex); in lan9303_alr_add_port()
713 return -ENOSPC; in lan9303_alr_add_port()
715 ether_addr_copy(entr->mac_addr, mac); in lan9303_alr_add_port()
717 entr->port_map |= BIT(port); in lan9303_alr_add_port()
718 entr->stp_override = stp_override; in lan9303_alr_add_port()
719 lan9303_alr_set_entry(chip, mac, entr->port_map, stp_override); in lan9303_alr_add_port()
720 mutex_unlock(&chip->alr_mutex); in lan9303_alr_add_port()
726 static int lan9303_alr_del_port(struct lan9303 *chip, const u8 *mac, int port) in lan9303_alr_del_port() argument
730 mutex_lock(&chip->alr_mutex); in lan9303_alr_del_port()
731 entr = lan9303_alr_cache_find_mac(chip, mac); in lan9303_alr_del_port()
735 entr->port_map &= ~BIT(port); in lan9303_alr_del_port()
736 if (entr->port_map == 0) /* zero means its free again */ in lan9303_alr_del_port()
737 eth_zero_addr(entr->mac_addr); in lan9303_alr_del_port()
738 lan9303_alr_set_entry(chip, mac, entr->port_map, entr->stp_override); in lan9303_alr_del_port()
741 mutex_unlock(&chip->alr_mutex); in lan9303_alr_del_port()
745 static int lan9303_disable_processing_port(struct lan9303 *chip, in lan9303_disable_processing_port() argument
750 /* disable RX, but keep register reset default values else */ in lan9303_disable_processing_port()
751 ret = lan9303_write_switch_port(chip, port, LAN9303_MAC_RX_CFG_0, in lan9303_disable_processing_port()
756 /* disable TX, but keep register reset default values else */ in lan9303_disable_processing_port()
757 return lan9303_write_switch_port(chip, port, LAN9303_MAC_TX_CFG_0, in lan9303_disable_processing_port()
762 static int lan9303_enable_processing_port(struct lan9303 *chip, in lan9303_enable_processing_port() argument
767 /* enable RX and keep register reset default values else */ in lan9303_enable_processing_port()
768 ret = lan9303_write_switch_port(chip, port, LAN9303_MAC_RX_CFG_0, in lan9303_enable_processing_port()
774 /* enable TX and keep register reset default values else */ in lan9303_enable_processing_port()
775 return lan9303_write_switch_port(chip, port, LAN9303_MAC_TX_CFG_0, in lan9303_enable_processing_port()
782 static int lan9303_setup_tagging(struct lan9303 *chip) in lan9303_setup_tagging() argument
789 ret = lan9303_write_switch_reg(chip, LAN9303_SWE_INGRESS_PORT_TYPE, in lan9303_setup_tagging()
798 return lan9303_write_switch_reg(chip, LAN9303_BM_EGRSS_PORT_TYPE, val); in lan9303_setup_tagging()
802 * - do not forward packets between port 1 and 2
803 * - forward everything from port 1 to port 0
804 * - forward everything from port 2 to port 0
806 static int lan9303_separate_ports(struct lan9303 *chip) in lan9303_separate_ports() argument
810 lan9303_alr_del_port(chip, eth_stp_addr, 0); in lan9303_separate_ports()
811 ret = lan9303_write_switch_reg(chip, LAN9303_SWE_PORT_MIRROR, in lan9303_separate_ports()
821 return lan9303_write_switch_reg(chip, LAN9303_SWE_PORT_STATE, in lan9303_separate_ports()
827 static void lan9303_bridge_ports(struct lan9303 *chip) in lan9303_bridge_ports() argument
830 lan9303_write_switch_reg(chip, LAN9303_SWE_PORT_MIRROR, in lan9303_bridge_ports()
833 lan9303_write_switch_reg(chip, LAN9303_SWE_PORT_STATE, in lan9303_bridge_ports()
834 chip->swe_port_state); in lan9303_bridge_ports()
835 lan9303_alr_add_port(chip, eth_stp_addr, 0, true); in lan9303_bridge_ports()
838 static void lan9303_handle_reset(struct lan9303 *chip) in lan9303_handle_reset() argument
840 if (!chip->reset_gpio) in lan9303_handle_reset()
843 gpiod_set_value_cansleep(chip->reset_gpio, 1); in lan9303_handle_reset()
845 if (chip->reset_duration != 0) in lan9303_handle_reset()
846 msleep(chip->reset_duration); in lan9303_handle_reset()
848 /* release (deassert) reset and activate the device */ in lan9303_handle_reset()
849 gpiod_set_value_cansleep(chip->reset_gpio, 0); in lan9303_handle_reset()
853 static int lan9303_disable_processing(struct lan9303 *chip) in lan9303_disable_processing() argument
858 int ret = lan9303_disable_processing_port(chip, p); in lan9303_disable_processing()
867 static int lan9303_check_device(struct lan9303 *chip) in lan9303_check_device() argument
873 /* In I2C-managed configurations this polling loop will clash with in lan9303_check_device()
874 * switch's reading of EEPROM right after reset and this behaviour is in lan9303_check_device()
887 chip->regmap, LAN9303_HW_CFG, ®); in lan9303_check_device()
889 dev_err(chip->dev, "failed to read HW_CFG reg: %pe\n", in lan9303_check_device()
894 dev_err(chip->dev, "HW_CFG not ready: 0x%08x\n", reg); in lan9303_check_device()
898 ret = lan9303_read(chip->regmap, LAN9303_CHIP_REV, ®); in lan9303_check_device()
900 dev_err(chip->dev, "failed to read chip revision register: %d\n", in lan9303_check_device()
907 dev_err(chip->dev, "unexpected device found: LAN%4.4X\n", in lan9303_check_device()
909 return -ENODEV; in lan9303_check_device()
917 * at all for now until the LAN9303 device is re-programmed accordingly. in lan9303_check_device()
919 ret = lan9303_disable_processing(chip); in lan9303_check_device()
921 dev_warn(chip->dev, "failed to disable switching %d\n", ret); in lan9303_check_device()
923 dev_info(chip->dev, "Found LAN%4.4X rev. %u\n", (reg >> 16), reg & 0xffff); in lan9303_check_device()
925 ret = lan9303_detect_phy_setup(chip); in lan9303_check_device()
927 dev_err(chip->dev, in lan9303_check_device()
935 /* ---------------------------- DSA -----------------------------------*/
946 struct lan9303 *chip = ds->priv; in lan9303_setup() local
952 dev_err(chip->dev, "port 0 is not the CPU port\n"); in lan9303_setup()
953 return -EINVAL; in lan9303_setup()
957 ret = lan9303_read(chip->regmap, LAN9303_VIRT_SPECIAL_CTRL, ®); in lan9303_setup()
964 regmap_write(chip->regmap, LAN9303_VIRT_SPECIAL_CTRL, reg); in lan9303_setup()
967 ret = lan9303_setup_tagging(chip); in lan9303_setup()
969 dev_err(chip->dev, "failed to setup port tagging %d\n", ret); in lan9303_setup()
971 ret = lan9303_separate_ports(chip); in lan9303_setup()
973 dev_err(chip->dev, "failed to separate ports %d\n", ret); in lan9303_setup()
975 ret = lan9303_enable_processing_port(chip, 0); in lan9303_setup()
977 dev_err(chip->dev, "failed to re-enable switching %d\n", ret); in lan9303_setup()
980 ret = lan9303_write_switch_reg_mask(chip, LAN9303_SWE_GLB_INGRESS_CFG, in lan9303_setup()
986 dev_err(chip->dev, "failed to setup IGMP trap %d\n", ret); in lan9303_setup()
1052 struct lan9303 *chip = ds->priv; in lan9303_get_ethtool_stats() local
1060 chip, port, lan9303_mib[u].offset, ®); in lan9303_get_ethtool_stats()
1063 dev_warn(chip->dev, "Reading status port %d reg %u failed\n", in lan9303_get_ethtool_stats()
1081 struct lan9303 *chip = ds->priv; in lan9303_phy_read() local
1082 int phy_base = chip->phy_addr_base; in lan9303_phy_read()
1085 return lan9303_virt_phy_reg_read(chip, regnum); in lan9303_phy_read()
1087 return -ENODEV; in lan9303_phy_read()
1089 return chip->ops->phy_read(chip, phy_base + port, regnum); in lan9303_phy_read()
1095 struct lan9303 *chip = ds->priv; in lan9303_phy_write() local
1096 int phy_base = chip->phy_addr_base; in lan9303_phy_write()
1099 return lan9303_virt_phy_reg_write(chip, regnum, val); in lan9303_phy_write()
1101 return -ENODEV; in lan9303_phy_write()
1103 return chip->ops->phy_write(chip, phy_base + port, regnum, val); in lan9303_phy_write()
1110 struct lan9303 *chip = ds->priv; in lan9303_port_enable() local
1117 return lan9303_enable_processing_port(chip, port); in lan9303_port_enable()
1123 struct lan9303 *chip = ds->priv; in lan9303_port_disable() local
1130 lan9303_disable_processing_port(chip, port); in lan9303_port_disable()
1139 struct lan9303 *chip = ds->priv; in lan9303_port_bridge_join() local
1141 dev_dbg(chip->dev, "%s(port %d)\n", __func__, port); in lan9303_port_bridge_join()
1143 lan9303_bridge_ports(chip); in lan9303_port_bridge_join()
1144 chip->is_bridged = true; /* unleash stp_state_set() */ in lan9303_port_bridge_join()
1153 struct lan9303 *chip = ds->priv; in lan9303_port_bridge_leave() local
1155 dev_dbg(chip->dev, "%s(port %d)\n", __func__, port); in lan9303_port_bridge_leave()
1156 if (chip->is_bridged) { in lan9303_port_bridge_leave()
1157 lan9303_separate_ports(chip); in lan9303_port_bridge_leave()
1158 chip->is_bridged = false; in lan9303_port_bridge_leave()
1166 struct lan9303 *chip = ds->priv; in lan9303_port_stp_state_set() local
1168 dev_dbg(chip->dev, "%s(port %d, state %d)\n", in lan9303_port_stp_state_set()
1187 dev_err(chip->dev, "unknown stp state: port %d, state %d\n", in lan9303_port_stp_state_set()
1194 chip->swe_port_state = (chip->swe_port_state & ~portmask) | portstate; in lan9303_port_stp_state_set()
1196 if (chip->is_bridged) in lan9303_port_stp_state_set()
1197 lan9303_write_switch_reg(chip, LAN9303_SWE_PORT_STATE, in lan9303_port_stp_state_set()
1198 chip->swe_port_state); in lan9303_port_stp_state_set()
1204 struct lan9303 *chip = ds->priv; in lan9303_port_fast_age() local
1209 dev_dbg(chip->dev, "%s(%d)\n", __func__, port); in lan9303_port_fast_age()
1210 lan9303_alr_loop(chip, alr_loop_cb_del_port_learned, &del_ctx); in lan9303_port_fast_age()
1217 struct lan9303 *chip = ds->priv; in lan9303_port_fdb_add() local
1219 dev_dbg(chip->dev, "%s(%d, %pM, %d)\n", __func__, port, addr, vid); in lan9303_port_fdb_add()
1221 return lan9303_alr_add_port(chip, addr, port, false); in lan9303_port_fdb_add()
1228 struct lan9303 *chip = ds->priv; in lan9303_port_fdb_del() local
1230 dev_dbg(chip->dev, "%s(%d, %pM, %d)\n", __func__, port, addr, vid); in lan9303_port_fdb_del()
1231 lan9303_alr_del_port(chip, addr, port); in lan9303_port_fdb_del()
1239 struct lan9303 *chip = ds->priv; in lan9303_port_fdb_dump() local
1246 dev_dbg(chip->dev, "%s(%d)\n", __func__, port); in lan9303_port_fdb_dump()
1247 return lan9303_alr_loop(chip, alr_loop_cb_fdb_port_dump, &dump_ctx); in lan9303_port_fdb_dump()
1253 struct lan9303 *chip = ds->priv; in lan9303_port_mdb_prepare() local
1255 dev_dbg(chip->dev, "%s(%d, %pM, %d)\n", __func__, port, mdb->addr, in lan9303_port_mdb_prepare()
1256 mdb->vid); in lan9303_port_mdb_prepare()
1257 if (mdb->vid) in lan9303_port_mdb_prepare()
1258 return -EOPNOTSUPP; in lan9303_port_mdb_prepare()
1259 if (lan9303_alr_cache_find_mac(chip, mdb->addr)) in lan9303_port_mdb_prepare()
1261 if (!lan9303_alr_cache_find_free(chip)) in lan9303_port_mdb_prepare()
1262 return -ENOSPC; in lan9303_port_mdb_prepare()
1271 struct lan9303 *chip = ds->priv; in lan9303_port_mdb_add() local
1278 dev_dbg(chip->dev, "%s(%d, %pM, %d)\n", __func__, port, mdb->addr, in lan9303_port_mdb_add()
1279 mdb->vid); in lan9303_port_mdb_add()
1280 return lan9303_alr_add_port(chip, mdb->addr, port, false); in lan9303_port_mdb_add()
1287 struct lan9303 *chip = ds->priv; in lan9303_port_mdb_del() local
1289 dev_dbg(chip->dev, "%s(%d, %pM, %d)\n", __func__, port, mdb->addr, in lan9303_port_mdb_del()
1290 mdb->vid); in lan9303_port_mdb_del()
1291 if (mdb->vid) in lan9303_port_mdb_del()
1292 return -EOPNOTSUPP; in lan9303_port_mdb_del()
1293 lan9303_alr_del_port(chip, mdb->addr, port); in lan9303_port_mdb_del()
1301 struct lan9303 *chip = ds->priv; in lan9303_phylink_get_caps() local
1303 dev_dbg(chip->dev, "%s(%d) entered.", __func__, port); in lan9303_phylink_get_caps()
1305 config->mac_capabilities = MAC_10 | MAC_100 | MAC_ASYM_PAUSE | in lan9303_phylink_get_caps()
1310 config->supported_interfaces); in lan9303_phylink_get_caps()
1312 config->supported_interfaces); in lan9303_phylink_get_caps()
1315 config->supported_interfaces); in lan9303_phylink_get_caps()
1317 * phy-mode property is absent in lan9303_phylink_get_caps()
1320 config->supported_interfaces); in lan9303_phylink_get_caps()
1344 struct lan9303 *chip = dp->ds->priv; in lan9303_phylink_mac_link_up() local
1345 struct dsa_switch *ds = dp->ds; in lan9303_phylink_mac_link_up()
1346 int port = dp->index; in lan9303_phylink_mac_link_up()
1357 /* Disable auto-negotiation and force the speed/duplex settings. */ in lan9303_phylink_mac_link_up()
1367 lan9303_read(chip->regmap, flow_ctl_reg[port], ®); in lan9303_phylink_mac_link_up()
1373 regmap_write(chip->regmap, flow_ctl_reg[port], reg); in lan9303_phylink_mac_link_up()
1404 static int lan9303_register_switch(struct lan9303 *chip) in lan9303_register_switch() argument
1406 chip->ds = devm_kzalloc(chip->dev, sizeof(*chip->ds), GFP_KERNEL); in lan9303_register_switch()
1407 if (!chip->ds) in lan9303_register_switch()
1408 return -ENOMEM; in lan9303_register_switch()
1410 chip->ds->dev = chip->dev; in lan9303_register_switch()
1411 chip->ds->num_ports = LAN9303_NUM_PORTS; in lan9303_register_switch()
1412 chip->ds->priv = chip; in lan9303_register_switch()
1413 chip->ds->ops = &lan9303_switch_ops; in lan9303_register_switch()
1414 chip->ds->phylink_mac_ops = &lan9303_phylink_mac_ops; in lan9303_register_switch()
1415 chip->ds->phys_mii_mask = GENMASK(LAN9303_NUM_PORTS - 1, 0); in lan9303_register_switch()
1417 return dsa_register_switch(chip->ds); in lan9303_register_switch()
1420 static int lan9303_probe_reset_gpio(struct lan9303 *chip, in lan9303_probe_reset_gpio() argument
1423 chip->reset_gpio = devm_gpiod_get_optional(chip->dev, "reset", in lan9303_probe_reset_gpio()
1425 if (IS_ERR(chip->reset_gpio)) in lan9303_probe_reset_gpio()
1426 return PTR_ERR(chip->reset_gpio); in lan9303_probe_reset_gpio()
1428 if (!chip->reset_gpio) { in lan9303_probe_reset_gpio()
1429 dev_dbg(chip->dev, "No reset GPIO defined\n"); in lan9303_probe_reset_gpio()
1433 chip->reset_duration = 200; in lan9303_probe_reset_gpio()
1436 of_property_read_u32(np, "reset-duration", in lan9303_probe_reset_gpio()
1437 &chip->reset_duration); in lan9303_probe_reset_gpio()
1439 dev_dbg(chip->dev, "reset duration defaults to 200 ms\n"); in lan9303_probe_reset_gpio()
1442 /* A sane reset duration should not be longer than 1s */ in lan9303_probe_reset_gpio()
1443 if (chip->reset_duration > 1000) in lan9303_probe_reset_gpio()
1444 chip->reset_duration = 1000; in lan9303_probe_reset_gpio()
1449 int lan9303_probe(struct lan9303 *chip, struct device_node *np) in lan9303_probe() argument
1454 mutex_init(&chip->indirect_mutex); in lan9303_probe()
1455 mutex_init(&chip->alr_mutex); in lan9303_probe()
1457 ret = lan9303_probe_reset_gpio(chip, np); in lan9303_probe()
1461 lan9303_handle_reset(chip); in lan9303_probe()
1464 /* access is in 32-bit sync. */ in lan9303_probe()
1465 ret = lan9303_read(chip->regmap, LAN9303_BYTE_ORDER, ®); in lan9303_probe()
1467 dev_err(chip->dev, "failed to access the device: %d\n", in lan9303_probe()
1469 if (!chip->reset_gpio) { in lan9303_probe()
1470 dev_dbg(chip->dev, in lan9303_probe()
1471 "hint: maybe failed due to missing reset GPIO\n"); in lan9303_probe()
1476 ret = lan9303_check_device(chip); in lan9303_probe()
1480 ret = lan9303_register_switch(chip); in lan9303_probe()
1482 dev_dbg(chip->dev, "Failed to register switch: %d\n", ret); in lan9303_probe()
1490 int lan9303_remove(struct lan9303 *chip) in lan9303_remove() argument
1494 rc = lan9303_disable_processing(chip); in lan9303_remove()
1496 dev_warn(chip->dev, "shutting down failed\n"); in lan9303_remove()
1498 dsa_unregister_switch(chip->ds); in lan9303_remove()
1500 /* assert reset to the whole device to prevent it from doing anything */ in lan9303_remove()
1501 gpiod_set_value_cansleep(chip->reset_gpio, 1); in lan9303_remove()
1507 void lan9303_shutdown(struct lan9303 *chip) in lan9303_shutdown() argument
1509 dsa_switch_shutdown(chip->ds); in lan9303_shutdown()