Lines Matching +full:pcs +full:- +full:handle

1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-or-later
3 * Copyright 2008 - 2015 Freescale Semiconductor Inc.
14 #include <linux/pcs-lynx.h>
56 #define IF_MODE_MASK 0x00000003 /* 30-31 Mask on i/f mode bits */
57 #define IF_MODE_10G 0x00000000 /* 30-31 10G interface */
58 #define IF_MODE_MII 0x00000001 /* 30-31 MII interface */
59 #define IF_MODE_GMII 0x00000002 /* 30-31 GMII (1G) interface */
62 #define IF_MODE_RGMII_1000 0x00004000 /* 10 - 1000Mbps RGMII */
63 #define IF_MODE_RGMII_100 0x00000000 /* 00 - 100Mbps RGMII */
64 #define IF_MODE_RGMII_10 0x00002000 /* 01 - 10Mbps RGMII */
71 /* 26-31 Hash table address code */
89 #define MEMAC_IEVNT_PCS 0x80000000 /* PCS (XG). Link sync (G) */
90 #define MEMAC_IEVNT_AN 0x40000000 /* Auto-negotiation */
117 /* Lower 32 bits of 48-bit MAC address */
119 /* Upper 16 bits of 48-bit MAC address */
127 struct mac_addr mac_addr0; /* 0x00C-0x010 MAC_ADDR_0...1 */
136 u32 tx_ipg_length; /* 0x044 Transmitter inter-packet-gap */
144 struct mac_addr mac_addr[MEMAC_NUM_OF_PADDRS];/* 0x80-0x0B4 mac padr */
309 iowrite32be(tmp0, &regs->mac_addr0.mac_addr_l); in add_addr_in_paddr()
310 iowrite32be(tmp1, &regs->mac_addr0.mac_addr_u); in add_addr_in_paddr()
312 iowrite32be(tmp0, &regs->mac_addr[paddr_num - 1].mac_addr_l); in add_addr_in_paddr()
313 iowrite32be(tmp1, &regs->mac_addr[paddr_num - 1].mac_addr_u); in add_addr_in_paddr()
322 tmp = ioread32be(&regs->command_config); in reset()
326 iowrite32be(tmp, &regs->command_config); in reset()
331 } while ((ioread32be(&regs->command_config) & CMD_CFG_SW_RESET) && in reset()
332 --count); in reset()
335 return -EBUSY; in reset()
345 tmp = ioread32be(&regs->imask); in set_exception()
351 iowrite32be(tmp, &regs->imask); in set_exception()
361 if (cfg->promiscuous_mode_enable) in init()
363 if (cfg->pause_ignore) in init()
373 iowrite32be(tmp, &regs->command_config); in init()
376 iowrite32be((u32)cfg->max_frame_length, &regs->maxfrm); in init()
379 iowrite32be((u32)cfg->pause_quanta, &regs->pause_quanta[0]); in init()
380 iowrite32be((u32)0, &regs->pause_thresh[0]); in init()
382 /* clear all pending events and set-up interrupts */ in init()
383 iowrite32be(0xffffffff, &regs->ievent); in init()
391 cfg->reset_on_init = false; in set_dflts()
392 cfg->promiscuous_mode_enable = false; in set_dflts()
393 cfg->pause_ignore = false; in set_dflts()
394 cfg->tx_ipg_length = DEFAULT_TX_IPG_LENGTH; in set_dflts()
395 cfg->max_frame_length = DEFAULT_FRAME_LENGTH; in set_dflts()
396 cfg->pause_quanta = DEFAULT_PAUSE_QUANTA; in set_dflts()
415 xor_val |= (mask1 << (5 - i)); in get_mac_addr_hash_code()
423 if (!memac->exception_cb) { in check_init_parameters()
425 return -EINVAL; in check_init_parameters()
427 if (!memac->event_cb) { in check_init_parameters()
429 return -EINVAL; in check_init_parameters()
460 static void memac_err_exception(void *handle) in memac_err_exception() argument
462 struct fman_mac *memac = (struct fman_mac *)handle; in memac_err_exception()
463 struct memac_regs __iomem *regs = memac->regs; in memac_err_exception()
466 event = ioread32be(&regs->ievent); in memac_err_exception()
467 imask = ioread32be(&regs->imask); in memac_err_exception()
472 * their corresponding location in the ievent - hence the >> 16 in memac_err_exception()
476 iowrite32be(event, &regs->ievent); in memac_err_exception()
479 memac->exception_cb(memac->dev_id, FM_MAC_EX_TS_FIFO_ECC_ERR); in memac_err_exception()
481 memac->exception_cb(memac->dev_id, FM_MAC_EX_10G_TX_ECC_ER); in memac_err_exception()
483 memac->exception_cb(memac->dev_id, FM_MAC_EX_10G_RX_ECC_ER); in memac_err_exception()
486 static void memac_exception(void *handle) in memac_exception() argument
488 struct fman_mac *memac = (struct fman_mac *)handle; in memac_exception()
489 struct memac_regs __iomem *regs = memac->regs; in memac_exception()
492 event = ioread32be(&regs->ievent); in memac_exception()
493 imask = ioread32be(&regs->imask); in memac_exception()
498 * their corresponding location in the ievent - hence the >> 16 in memac_exception()
502 iowrite32be(event, &regs->ievent); in memac_exception()
505 memac->exception_cb(memac->dev_id, in memac_exception()
511 fman_unregister_intr(memac->fm, FMAN_MOD_MAC, memac->mac_id, in free_init_resources()
514 fman_unregister_intr(memac->fm, FMAN_MOD_MAC, memac->mac_id, in free_init_resources()
518 free_hash_table(memac->multicast_addr_hash); in free_init_resources()
519 memac->multicast_addr_hash = NULL; in free_init_resources()
522 free_hash_table(memac->unicast_addr_hash); in free_init_resources()
523 memac->unicast_addr_hash = NULL; in free_init_resources()
530 ret = phy_init(memac->serdes); in memac_enable()
532 dev_err(memac->dev_id->dev, in memac_enable()
537 ret = phy_power_on(memac->serdes); in memac_enable()
539 dev_err(memac->dev_id->dev, in memac_enable()
541 phy_exit(memac->serdes); in memac_enable()
549 phy_power_off(memac->serdes); in memac_disable()
550 phy_exit(memac->serdes); in memac_disable()
555 struct memac_regs __iomem *regs = memac->regs; in memac_set_promiscuous()
558 tmp = ioread32be(&regs->command_config); in memac_set_promiscuous()
564 iowrite32be(tmp, &regs->command_config); in memac_set_promiscuous()
572 struct memac_regs __iomem *regs = memac->regs; in memac_set_tx_pause_frames()
575 tmp = ioread32be(&regs->tx_fifo_sections); in memac_set_tx_pause_frames()
578 iowrite32be(tmp, &regs->tx_fifo_sections); in memac_set_tx_pause_frames()
580 tmp = ioread32be(&regs->command_config); in memac_set_tx_pause_frames()
583 iowrite32be(tmp, &regs->command_config); in memac_set_tx_pause_frames()
585 tmp = ioread32be(&regs->pause_quanta[priority / 2]); in memac_set_tx_pause_frames()
591 iowrite32be(tmp, &regs->pause_quanta[priority / 2]); in memac_set_tx_pause_frames()
593 tmp = ioread32be(&regs->pause_thresh[priority / 2]); in memac_set_tx_pause_frames()
599 iowrite32be(tmp, &regs->pause_thresh[priority / 2]); in memac_set_tx_pause_frames()
606 struct memac_regs __iomem *regs = memac->regs; in memac_accept_rx_pause_frames()
609 tmp = ioread32be(&regs->command_config); in memac_accept_rx_pause_frames()
615 iowrite32be(tmp, &regs->command_config); in memac_accept_rx_pause_frames()
623 struct fman_mac *memac = fman_config_to_mac(config)->fman_mac; in memac_get_caps()
624 unsigned long caps = config->mac_capabilities; in memac_get_caps()
627 memac->rgmii_no_half_duplex) in memac_get_caps()
634 * memac_if_mode() - Convert an interface mode into an IF_MODE config
665 struct fman_mac *memac = fman_config_to_mac(config)->fman_mac; in memac_select_pcs()
670 return memac->sgmii_pcs; in memac_select_pcs()
672 return memac->qsgmii_pcs; in memac_select_pcs()
674 return memac->xfi_pcs; in memac_select_pcs()
683 struct fman_mac *memac = fman_config_to_mac(config)->fman_mac; in memac_prepare()
690 return phy_set_mode_ext(memac->serdes, PHY_MODE_ETHERNET, in memac_prepare()
701 struct memac_regs __iomem *regs = mac_dev->fman_mac->regs; in memac_mac_config()
702 u32 tmp = ioread32be(&regs->if_mode); in memac_mac_config()
705 tmp |= memac_if_mode(state->interface); in memac_mac_config()
708 iowrite32be(tmp, &regs->if_mode); in memac_mac_config()
716 struct fman_mac *memac = mac_dev->fman_mac; in memac_link_up()
717 struct memac_regs __iomem *regs = memac->regs; in memac_link_up()
739 iowrite32be(tmp, &regs->if_mode); in memac_link_up()
744 if (memac->fm_rev_info.major == 6 && in memac_link_up()
745 memac->fm_rev_info.minor == 4) in memac_link_up()
754 iowrite32be(tmp, &regs->tx_fifo_sections); in memac_link_up()
756 mac_dev->update_speed(mac_dev, speed); in memac_link_up()
758 tmp = ioread32be(&regs->command_config); in memac_link_up()
760 iowrite32be(tmp, &regs->command_config); in memac_link_up()
766 struct fman_mac *memac = fman_config_to_mac(config)->fman_mac; in memac_link_down()
767 struct memac_regs __iomem *regs = memac->regs; in memac_link_down()
771 tmp = ioread32be(&regs->command_config); in memac_link_down()
773 iowrite32be(tmp, &regs->command_config); in memac_link_down()
788 add_addr_in_paddr(memac->regs, (const u8 *)(*enet_addr), 0); in memac_modify_mac_address()
796 struct memac_regs __iomem *regs = memac->regs; in memac_add_hash_mac_address()
806 return -EINVAL; in memac_add_hash_mac_address()
813 return -ENOMEM; in memac_add_hash_mac_address()
814 hash_entry->addr = addr; in memac_add_hash_mac_address()
815 INIT_LIST_HEAD(&hash_entry->node); in memac_add_hash_mac_address()
817 list_add_tail(&hash_entry->node, in memac_add_hash_mac_address()
818 &memac->multicast_addr_hash->lsts[hash]); in memac_add_hash_mac_address()
819 iowrite32be(hash | HASH_CTRL_MCAST_EN, &regs->hashtable_ctrl); in memac_add_hash_mac_address()
827 struct memac_regs __iomem *regs = memac->regs; in memac_set_allmulti()
832 &regs->hashtable_ctrl); in memac_set_allmulti()
836 &regs->hashtable_ctrl); in memac_set_allmulti()
839 memac->allmulti_enabled = enable; in memac_set_allmulti()
852 struct memac_regs __iomem *regs = memac->regs; in memac_del_hash_mac_address()
862 list_for_each(pos, &memac->multicast_addr_hash->lsts[hash]) { in memac_del_hash_mac_address()
864 if (hash_entry && hash_entry->addr == addr) { in memac_del_hash_mac_address()
865 list_del_init(&hash_entry->node); in memac_del_hash_mac_address()
871 if (!memac->allmulti_enabled) { in memac_del_hash_mac_address()
872 if (list_empty(&memac->multicast_addr_hash->lsts[hash])) in memac_del_hash_mac_address()
874 &regs->hashtable_ctrl); in memac_del_hash_mac_address()
888 memac->exceptions |= bit_mask; in memac_set_exception()
890 memac->exceptions &= ~bit_mask; in memac_set_exception()
893 return -EINVAL; in memac_set_exception()
895 set_exception(memac->regs, bit_mask, enable); in memac_set_exception()
911 memac_drv_param = memac->memac_drv_param; in memac_init()
914 if (memac_drv_param->reset_on_init) { in memac_init()
915 err = reset(memac->regs); in memac_init()
923 if (memac->addr != 0) { in memac_init()
924 MAKE_ENET_ADDR_FROM_UINT64(memac->addr, eth_addr); in memac_init()
925 add_addr_in_paddr(memac->regs, (const u8 *)eth_addr, 0); in memac_init()
928 init(memac->regs, memac->memac_drv_param, memac->exceptions); in memac_init()
933 if ((memac->fm_rev_info.major == 6) && in memac_init()
934 ((memac->fm_rev_info.minor == 0) || in memac_init()
935 (memac->fm_rev_info.minor == 3))) { in memac_init()
936 /* MAC strips CRC from received frames - this workaround in memac_init()
939 reg32 = ioread32be(&memac->regs->command_config); in memac_init()
941 iowrite32be(reg32, &memac->regs->command_config); in memac_init()
945 err = fman_set_mac_max_frame(memac->fm, memac->mac_id, in memac_init()
946 memac_drv_param->max_frame_length); in memac_init()
952 memac->multicast_addr_hash = alloc_hash_table(HASH_TABLE_SIZE); in memac_init()
953 if (!memac->multicast_addr_hash) { in memac_init()
956 return -ENOMEM; in memac_init()
959 memac->unicast_addr_hash = alloc_hash_table(HASH_TABLE_SIZE); in memac_init()
960 if (!memac->unicast_addr_hash) { in memac_init()
963 return -ENOMEM; in memac_init()
966 fman_register_intr(memac->fm, FMAN_MOD_MAC, memac->mac_id, in memac_init()
969 fman_register_intr(memac->fm, FMAN_MOD_MAC, memac->mac_id, in memac_init()
975 static void pcs_put(struct phylink_pcs *pcs) in pcs_put() argument
977 if (IS_ERR_OR_NULL(pcs)) in pcs_put()
980 lynx_pcs_destroy(pcs); in pcs_put()
987 pcs_put(memac->sgmii_pcs); in memac_free()
988 pcs_put(memac->qsgmii_pcs); in memac_free()
989 pcs_put(memac->xfi_pcs); in memac_free()
990 kfree(memac->memac_drv_param); in memac_free()
1015 memac->memac_drv_param = memac_drv_param; in memac_config()
1019 memac->addr = ENET_ADDR_TO_UINT64(mac_dev->addr); in memac_config()
1021 memac->regs = mac_dev->vaddr; in memac_config()
1022 memac->mac_id = params->mac_id; in memac_config()
1023 memac->exceptions = (MEMAC_IMASK_TSECC_ER | MEMAC_IMASK_TECC_ER | in memac_config()
1025 memac->exception_cb = params->exception_cb; in memac_config()
1026 memac->event_cb = params->event_cb; in memac_config()
1027 memac->dev_id = mac_dev; in memac_config()
1028 memac->fm = params->fm; in memac_config()
1031 fman_get_revision(memac->fm, &memac->fm_rev_info); in memac_config()
1040 struct phylink_pcs *pcs; in memac_pcs_create() local
1042 node = of_parse_phandle(mac_node, "pcsphy-handle", index); in memac_pcs_create()
1044 return ERR_PTR(-ENODEV); in memac_pcs_create()
1046 pcs = lynx_pcs_create_fwnode(of_fwnode_handle(node)); in memac_pcs_create()
1049 return pcs; in memac_pcs_create()
1057 if (!mac_dev->fman_mac->serdes) in memac_supports()
1058 return mac_dev->phy_if == iface; in memac_supports()
1060 return !phy_validate(mac_dev->fman_mac->serdes, PHY_MODE_ETHERNET, in memac_supports()
1069 struct phylink_pcs *pcs; in memac_initialization() local
1077 * 10GBASE-R (aka XFI), so just convert it for them. in memac_initialization()
1079 if (mac_dev->phy_if == PHY_INTERFACE_MODE_XGMII) in memac_initialization()
1080 mac_dev->phy_if = PHY_INTERFACE_MODE_10GBASER; in memac_initialization()
1082 mac_dev->phylink_ops = &memac_mac_ops; in memac_initialization()
1083 mac_dev->set_promisc = memac_set_promiscuous; in memac_initialization()
1084 mac_dev->change_addr = memac_modify_mac_address; in memac_initialization()
1085 mac_dev->add_hash_mac_addr = memac_add_hash_mac_address; in memac_initialization()
1086 mac_dev->remove_hash_mac_addr = memac_del_hash_mac_address; in memac_initialization()
1087 mac_dev->set_exception = memac_set_exception; in memac_initialization()
1088 mac_dev->set_allmulti = memac_set_allmulti; in memac_initialization()
1089 mac_dev->set_tstamp = memac_set_tstamp; in memac_initialization()
1090 mac_dev->set_multi = fman_set_multi; in memac_initialization()
1091 mac_dev->enable = memac_enable; in memac_initialization()
1092 mac_dev->disable = memac_disable; in memac_initialization()
1094 mac_dev->fman_mac = memac_config(mac_dev, params); in memac_initialization()
1095 if (!mac_dev->fman_mac) in memac_initialization()
1096 return -EINVAL; in memac_initialization()
1098 memac = mac_dev->fman_mac; in memac_initialization()
1099 memac->memac_drv_param->max_frame_length = fman_get_max_frm(); in memac_initialization()
1100 memac->memac_drv_param->reset_on_init = true; in memac_initialization()
1102 err = of_property_match_string(mac_node, "pcs-handle-names", "xfi"); in memac_initialization()
1104 memac->xfi_pcs = memac_pcs_create(mac_node, err); in memac_initialization()
1105 if (IS_ERR(memac->xfi_pcs)) { in memac_initialization()
1106 err = PTR_ERR(memac->xfi_pcs); in memac_initialization()
1107 dev_err_probe(mac_dev->dev, err, "missing xfi pcs\n"); in memac_initialization()
1110 } else if (err != -EINVAL && err != -ENODATA) { in memac_initialization()
1114 err = of_property_match_string(mac_node, "pcs-handle-names", "qsgmii"); in memac_initialization()
1116 memac->qsgmii_pcs = memac_pcs_create(mac_node, err); in memac_initialization()
1117 if (IS_ERR(memac->qsgmii_pcs)) { in memac_initialization()
1118 err = PTR_ERR(memac->qsgmii_pcs); in memac_initialization()
1119 dev_err_probe(mac_dev->dev, err, in memac_initialization()
1120 "missing qsgmii pcs\n"); in memac_initialization()
1123 } else if (err != -EINVAL && err != -ENODATA) { in memac_initialization()
1127 /* For compatibility, if pcs-handle-names is missing, we assume this in memac_initialization()
1128 * phy is the first one in pcsphy-handle in memac_initialization()
1130 err = of_property_match_string(mac_node, "pcs-handle-names", "sgmii"); in memac_initialization()
1131 if (err == -EINVAL || err == -ENODATA) in memac_initialization()
1132 pcs = memac_pcs_create(mac_node, 0); in memac_initialization()
1136 pcs = memac_pcs_create(mac_node, err); in memac_initialization()
1138 if (IS_ERR(pcs)) { in memac_initialization()
1139 err = PTR_ERR(pcs); in memac_initialization()
1140 dev_err_probe(mac_dev->dev, err, "missing pcs\n"); in memac_initialization()
1144 /* If err is set here, it means that pcs-handle-names was missing above in memac_initialization()
1148 if (err && mac_dev->phy_if == PHY_INTERFACE_MODE_10GBASER) in memac_initialization()
1149 memac->xfi_pcs = pcs; in memac_initialization()
1151 memac->sgmii_pcs = pcs; in memac_initialization()
1153 memac->serdes = devm_of_phy_optional_get(mac_dev->dev, mac_node, in memac_initialization()
1155 if (!memac->serdes) { in memac_initialization()
1156 dev_dbg(mac_dev->dev, "could not get (optional) serdes\n"); in memac_initialization()
1157 } else if (IS_ERR(memac->serdes)) { in memac_initialization()
1158 err = PTR_ERR(memac->serdes); in memac_initialization()
1164 * - 1000BASE-KX in memac_initialization()
1165 * - 10GBASE-KR in memac_initialization()
1166 * - XAUI/HiGig in memac_initialization()
1168 supported = mac_dev->phylink_config.supported_interfaces; in memac_initialization()
1172 if (memac->sgmii_pcs && in memac_initialization()
1179 if (memac->sgmii_pcs && in memac_initialization()
1183 if (memac->qsgmii_pcs && in memac_initialization()
1186 else if (mac_dev->phy_if == PHY_INTERFACE_MODE_QSGMII) in memac_initialization()
1187 dev_warn(mac_dev->dev, "no QSGMII pcs specified\n"); in memac_initialization()
1189 if (memac->xfi_pcs && in memac_initialization()
1210 mac_dev->phylink_config.mac_capabilities = capabilities; in memac_initialization()
1221 memac->rgmii_no_half_duplex = true; in memac_initialization()
1227 * those configurations modes don't use in-band autonegotiation. in memac_initialization()
1230 mac_dev->phy_if != PHY_INTERFACE_MODE_MII && in memac_initialization()
1231 !phy_interface_mode_is_rgmii(mac_dev->phy_if)) in memac_initialization()
1232 mac_dev->phylink_config.default_an_inband = true; in memac_initialization()
1234 err = memac_init(mac_dev->fman_mac); in memac_initialization()
1238 dev_info(mac_dev->dev, "FMan MEMAC\n"); in memac_initialization()
1243 memac_free(mac_dev->fman_mac); in memac_initialization()