Lines Matching +full:port +full:- +full:id

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2010-2016 Solarflare Communications Inc.
59 struct sfxge_port *port = &sc->port; in sfxge_mac_stat_update() local
60 efsys_mem_t *esmp = &(port->mac_stats.dma_buf); in sfxge_mac_stat_update()
66 SFXGE_PORT_LOCK_ASSERT_OWNED(port); in sfxge_mac_stat_update()
68 if (__predict_false(port->init_state != SFXGE_PORT_STARTED)) { in sfxge_mac_stat_update()
73 min_ticks = (unsigned int)hz * port->stats_update_period_ms / 1000; in sfxge_mac_stat_update()
76 if ((unsigned int)(now - port->mac_stats.update_time) < min_ticks) { in sfxge_mac_stat_update()
81 port->mac_stats.update_time = now; in sfxge_mac_stat_update()
89 if ((rc = efx_mac_stats_update(sc->enp, esmp, in sfxge_mac_stat_update()
90 port->mac_stats.decode_buf, NULL)) != EAGAIN) in sfxge_mac_stat_update()
108 SFXGE_PORT_LOCK(&sc->port); in sfxge_get_counter()
113 mac_stats = (uint64_t *)sc->port.mac_stats.decode_buf; in sfxge_get_counter()
145 SFXGE_PORT_UNLOCK(&sc->port); in sfxge_get_counter()
154 SFXGE_PORT_UNLOCK(&sc->port); in sfxge_get_counter()
158 SFXGE_PORT_UNLOCK(&sc->port); in sfxge_get_counter()
167 unsigned int id = arg2; in sfxge_mac_stat_handler() local
171 SFXGE_PORT_LOCK(&sc->port); in sfxge_mac_stat_handler()
173 val = ((uint64_t *)sc->port.mac_stats.decode_buf)[id]; in sfxge_mac_stat_handler()
174 SFXGE_PORT_UNLOCK(&sc->port); in sfxge_mac_stat_handler()
184 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->dev); in sfxge_mac_stat_init()
186 unsigned int id; in sfxge_mac_stat_init() local
189 stat_list = SYSCTL_CHILDREN(sc->stats_node); in sfxge_mac_stat_init()
192 for (id = 0; id < EFX_MAC_NSTATS; id++) { in sfxge_mac_stat_init()
193 name = efx_mac_stat_name(sc->enp, id); in sfxge_mac_stat_init()
196 sc, id, sfxge_mac_stat_handler, "Q", ""); in sfxge_mac_stat_init()
205 struct ifmedia_entry *ifm = sc->media.ifm_cur; in sfxge_port_wanted_fc()
207 if (ifm->ifm_media == (IFM_ETHER | IFM_AUTO)) in sfxge_port_wanted_fc()
209 return (((ifm->ifm_media & IFM_ETH_RXPAUSE) ? EFX_FCNTL_RESPOND : 0) | in sfxge_port_wanted_fc()
210 ((ifm->ifm_media & IFM_ETH_TXPAUSE) ? EFX_FCNTL_GENERATE : 0)); in sfxge_port_wanted_fc()
218 efx_mac_fcntl_get(sc->enp, &wanted_fc, &link_fc); in sfxge_port_link_fc_ifm()
228 return (sc->port.wanted_fc); in sfxge_port_wanted_fc()
241 struct sfxge_port *port; in sfxge_port_wanted_fc_handler() local
246 port = &sc->port; in sfxge_port_wanted_fc_handler()
248 if (req->newptr != NULL) { in sfxge_port_wanted_fc_handler()
252 SFXGE_PORT_LOCK(port); in sfxge_port_wanted_fc_handler()
254 if (port->wanted_fc != fcntl) { in sfxge_port_wanted_fc_handler()
255 if (port->init_state == SFXGE_PORT_STARTED) in sfxge_port_wanted_fc_handler()
256 error = efx_mac_fcntl_set(sc->enp, in sfxge_port_wanted_fc_handler()
257 port->wanted_fc, in sfxge_port_wanted_fc_handler()
260 port->wanted_fc = fcntl; in sfxge_port_wanted_fc_handler()
263 SFXGE_PORT_UNLOCK(port); in sfxge_port_wanted_fc_handler()
265 SFXGE_PORT_LOCK(port); in sfxge_port_wanted_fc_handler()
266 fcntl = port->wanted_fc; in sfxge_port_wanted_fc_handler()
267 SFXGE_PORT_UNLOCK(port); in sfxge_port_wanted_fc_handler()
279 struct sfxge_port *port; in sfxge_port_link_fc_handler() local
283 port = &sc->port; in sfxge_port_link_fc_handler()
285 SFXGE_PORT_LOCK(port); in sfxge_port_link_fc_handler()
286 if (__predict_true(port->init_state == SFXGE_PORT_STARTED) && in sfxge_port_link_fc_handler()
288 efx_mac_fcntl_get(sc->enp, &wanted_fc, &link_fc); in sfxge_port_link_fc_handler()
291 SFXGE_PORT_UNLOCK(port); in sfxge_port_link_fc_handler()
315 struct sfxge_port *port; in sfxge_mac_link_update() local
318 port = &sc->port; in sfxge_mac_link_update()
320 if (port->link_mode == mode) in sfxge_mac_link_update()
323 port->link_mode = mode; in sfxge_mac_link_update()
327 if_setbaudrate(sc->ifnet, sfxge_link_baudrate[port->link_mode]); in sfxge_mac_link_update()
328 if_link_state_change(sc->ifnet, link_state); in sfxge_mac_link_update()
336 struct sfxge_port *port; in sfxge_mac_poll_work() local
340 enp = sc->enp; in sfxge_mac_poll_work()
341 port = &sc->port; in sfxge_mac_poll_work()
343 SFXGE_PORT_LOCK(port); in sfxge_mac_poll_work()
345 if (__predict_false(port->init_state != SFXGE_PORT_STARTED)) in sfxge_mac_poll_work()
353 SFXGE_PORT_UNLOCK(port); in sfxge_mac_poll_work()
373 if_t ifp = sc->ifnet; in sfxge_mac_multicast_list_set()
374 struct sfxge_port *port = &sc->port; in sfxge_mac_multicast_list_set() local
377 mtx_assert(&port->lock, MA_OWNED); in sfxge_mac_multicast_list_set()
379 port->mcast_count = if_foreach_llmaddr(ifp, sfxge_copy_maddr, in sfxge_mac_multicast_list_set()
380 port->mcast_addrs); in sfxge_mac_multicast_list_set()
381 if (port->mcast_count == EFX_MAC_MULTICAST_LIST_MAX) { in sfxge_mac_multicast_list_set()
382 device_printf(sc->dev, "Too many multicast addresses\n"); in sfxge_mac_multicast_list_set()
387 rc = efx_mac_multicast_list_set(sc->enp, port->mcast_addrs, in sfxge_mac_multicast_list_set()
388 port->mcast_count); in sfxge_mac_multicast_list_set()
390 device_printf(sc->dev, in sfxge_mac_multicast_list_set()
400 if_t ifp = sc->ifnet; in sfxge_mac_filter_set_locked()
401 struct sfxge_port *port = &sc->port; in sfxge_mac_filter_set_locked() local
405 mtx_assert(&port->lock, MA_OWNED); in sfxge_mac_filter_set_locked()
414 rc = efx_mac_filter_set(sc->enp, !!(if_getflags(ifp) & IFF_PROMISC), in sfxge_mac_filter_set_locked()
415 (port->mcast_count > 0), all_mulcst, B_TRUE); in sfxge_mac_filter_set_locked()
423 struct sfxge_port *port = &sc->port; in sfxge_mac_filter_set() local
426 SFXGE_PORT_LOCK(port); in sfxge_mac_filter_set()
430 * checks IFF_DRV_RUNNING flag which implies port started, but in sfxge_mac_filter_set()
433 * results in failure where kernel complains that non-sleepable in sfxge_mac_filter_set()
437 if (__predict_true(port->init_state == SFXGE_PORT_STARTED)) in sfxge_mac_filter_set()
441 SFXGE_PORT_UNLOCK(port); in sfxge_mac_filter_set()
448 struct sfxge_port *port; in sfxge_port_stop() local
451 port = &sc->port; in sfxge_port_stop()
452 enp = sc->enp; in sfxge_port_stop()
454 SFXGE_PORT_LOCK(port); in sfxge_port_stop()
456 KASSERT(port->init_state == SFXGE_PORT_STARTED, in sfxge_port_stop()
457 ("port not started")); in sfxge_port_stop()
459 port->init_state = SFXGE_PORT_INITIALIZED; in sfxge_port_stop()
461 port->mac_stats.update_time = 0; in sfxge_port_stop()
466 (void)efx_mac_stats_periodic(enp, &port->mac_stats.dma_buf, 0, B_FALSE); in sfxge_port_stop()
468 port->link_mode = EFX_LINK_UNKNOWN; in sfxge_port_stop()
470 /* Destroy the common code port object. */ in sfxge_port_stop()
475 SFXGE_PORT_UNLOCK(port); in sfxge_port_stop()
483 if_t ifp = sc->ifnet; in sfxge_port_start()
484 struct sfxge_port *port; in sfxge_port_start() local
490 port = &sc->port; in sfxge_port_start()
491 enp = sc->enp; in sfxge_port_start()
493 SFXGE_PORT_LOCK(port); in sfxge_port_start()
495 KASSERT(port->init_state == SFXGE_PORT_INITIALIZED, in sfxge_port_start()
496 ("port not initialized")); in sfxge_port_start()
502 /* Initialize the port object in the common code. */ in sfxge_port_start()
503 if ((rc = efx_port_init(sc->enp)) != 0) in sfxge_port_start()
525 if ((rc = efx_mac_stats_periodic(enp, &port->mac_stats.dma_buf, in sfxge_port_start()
526 port->stats_update_period_ms, in sfxge_port_start()
533 if ((rc = sfxge_phy_cap_mask(sc, sc->media.ifm_cur->ifm_media, in sfxge_port_start()
537 if ((rc = efx_phy_adv_cap_set(sc->enp, phy_cap_mask)) != 0) in sfxge_port_start()
540 port->init_state = SFXGE_PORT_STARTED; in sfxge_port_start()
543 SFXGE_PORT_UNLOCK(port); in sfxge_port_start()
552 (void)efx_mac_stats_periodic(enp, &port->mac_stats.dma_buf, 0, B_FALSE); in sfxge_port_start()
562 SFXGE_PORT_UNLOCK(port); in sfxge_port_start()
570 struct sfxge_port *port = &sc->port; in sfxge_phy_stat_update() local
571 efsys_mem_t *esmp = &port->phy_stats.dma_buf; in sfxge_phy_stat_update()
576 SFXGE_PORT_LOCK_ASSERT_OWNED(port); in sfxge_phy_stat_update()
578 if (__predict_false(port->init_state != SFXGE_PORT_STARTED)) { in sfxge_phy_stat_update()
584 if ((unsigned int)(now - port->phy_stats.update_time) < (unsigned int)hz) { in sfxge_phy_stat_update()
589 port->phy_stats.update_time = now; in sfxge_phy_stat_update()
597 bus_dmamap_sync(esmp->esm_tag, esmp->esm_map, in sfxge_phy_stat_update()
601 if ((rc = efx_phy_stats_update(sc->enp, esmp, in sfxge_phy_stat_update()
602 port->phy_stats.decode_buf)) != EAGAIN) in sfxge_phy_stat_update()
617 unsigned int id = arg2; in sfxge_phy_stat_handler() local
621 SFXGE_PORT_LOCK(&sc->port); in sfxge_phy_stat_handler()
623 val = ((uint32_t *)sc->port.phy_stats.decode_buf)[id]; in sfxge_phy_stat_handler()
624 SFXGE_PORT_UNLOCK(&sc->port); in sfxge_phy_stat_handler()
634 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->dev); in sfxge_phy_stat_init()
636 unsigned int id; in sfxge_phy_stat_init() local
638 uint64_t stat_mask = efx_nic_cfg_get(sc->enp)->enc_phy_stat_mask; in sfxge_phy_stat_init()
640 stat_list = SYSCTL_CHILDREN(sc->stats_node); in sfxge_phy_stat_init()
643 for (id = 0; id < EFX_PHY_NSTATS; id++) { in sfxge_phy_stat_init()
644 if (!(stat_mask & ((uint64_t)1 << id))) in sfxge_phy_stat_init()
646 name = efx_phy_stat_name(sc->enp, id); in sfxge_phy_stat_init()
649 sc, id, sfxge_phy_stat_handler, in sfxge_phy_stat_init()
650 id == EFX_PHY_STAT_OUI ? "IX" : "IU", ""); in sfxge_phy_stat_init()
657 struct sfxge_port *port; in sfxge_port_fini() local
660 port = &sc->port; in sfxge_port_fini()
661 esmp = &port->mac_stats.dma_buf; in sfxge_port_fini()
663 KASSERT(port->init_state == SFXGE_PORT_INITIALIZED, in sfxge_port_fini()
664 ("Port not initialized")); in sfxge_port_fini()
666 port->init_state = SFXGE_PORT_UNINITIALIZED; in sfxge_port_fini()
668 port->link_mode = EFX_LINK_UNKNOWN; in sfxge_port_fini()
671 sfxge_dma_free(&port->phy_stats.dma_buf); in sfxge_port_fini()
672 free(port->phy_stats.decode_buf, M_SFXGE); in sfxge_port_fini()
675 free(port->mac_stats.decode_buf, M_SFXGE); in sfxge_port_fini()
677 SFXGE_PORT_LOCK_DESTROY(port); in sfxge_port_fini()
679 port->sc = NULL; in sfxge_port_fini()
688 device_printf(sc->dev, in sfxge_port_stats_update_period_ms()
693 device_printf(sc->dev, in sfxge_port_stats_update_period_ms()
706 struct sfxge_port *port; in sfxge_port_stats_update_period_ms_handler() local
711 port = &sc->port; in sfxge_port_stats_update_period_ms_handler()
713 if (req->newptr != NULL) { in sfxge_port_stats_update_period_ms_handler()
721 SFXGE_PORT_LOCK(port); in sfxge_port_stats_update_period_ms_handler()
723 if (port->stats_update_period_ms != period_ms) { in sfxge_port_stats_update_period_ms_handler()
724 if (port->init_state == SFXGE_PORT_STARTED) in sfxge_port_stats_update_period_ms_handler()
725 error = efx_mac_stats_periodic(sc->enp, in sfxge_port_stats_update_period_ms_handler()
726 &port->mac_stats.dma_buf, in sfxge_port_stats_update_period_ms_handler()
729 port->stats_update_period_ms = period_ms; in sfxge_port_stats_update_period_ms_handler()
732 SFXGE_PORT_UNLOCK(port); in sfxge_port_stats_update_period_ms_handler()
734 SFXGE_PORT_LOCK(port); in sfxge_port_stats_update_period_ms_handler()
735 period_ms = port->stats_update_period_ms; in sfxge_port_stats_update_period_ms_handler()
736 SFXGE_PORT_UNLOCK(port); in sfxge_port_stats_update_period_ms_handler()
747 struct sfxge_port *port; in sfxge_port_init() local
755 port = &sc->port; in sfxge_port_init()
756 mac_stats_buf = &port->mac_stats.dma_buf; in sfxge_port_init()
757 phy_stats_buf = &port->phy_stats.dma_buf; in sfxge_port_init()
759 KASSERT(port->init_state == SFXGE_PORT_UNINITIALIZED, in sfxge_port_init()
760 ("Port already initialized")); in sfxge_port_init()
762 port->sc = sc; in sfxge_port_init()
764 SFXGE_PORT_LOCK_INIT(port, device_get_nameunit(sc->dev)); in sfxge_port_init()
766 DBGPRINT(sc->dev, "alloc PHY stats"); in sfxge_port_init()
767 port->phy_stats.decode_buf = malloc(EFX_PHY_NSTATS * sizeof(uint32_t), in sfxge_port_init()
773 DBGPRINT(sc->dev, "init sysctl"); in sfxge_port_init()
774 sysctl_ctx = device_get_sysctl_ctx(sc->dev); in sfxge_port_init()
775 sysctl_tree = device_get_sysctl_tree(sc->dev); in sfxge_port_init()
780 port->wanted_fc = EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE; in sfxge_port_init()
789 DBGPRINT(sc->dev, "alloc MAC stats"); in sfxge_port_init()
790 port->mac_stats.decode_buf = malloc(EFX_MAC_NSTATS * sizeof(uint64_t), in sfxge_port_init()
792 mac_nstats = efx_nic_cfg_get(sc->enp)->enc_mac_stats_nstats; in sfxge_port_init()
797 port->stats_update_period_ms = sfxge_port_stats_update_period_ms(sc); in sfxge_port_init()
806 port->init_state = SFXGE_PORT_INITIALIZED; in sfxge_port_init()
808 DBGPRINT(sc->dev, "success"); in sfxge_port_init()
812 free(port->mac_stats.decode_buf, M_SFXGE); in sfxge_port_init()
815 free(port->phy_stats.decode_buf, M_SFXGE); in sfxge_port_init()
816 SFXGE_PORT_LOCK_DESTROY(port); in sfxge_port_init()
817 port->sc = NULL; in sfxge_port_init()
818 DBGPRINT(sc->dev, "failed %d", rc); in sfxge_port_init()
868 ifmr->ifm_status = IFM_AVALID; in sfxge_media_status()
869 ifmr->ifm_active = IFM_ETHER; in sfxge_media_status()
872 ifmr->ifm_status |= IFM_ACTIVE; in sfxge_media_status()
874 efx_phy_media_type_get(sc->enp, &medium_type); in sfxge_media_status()
875 mode = sc->port.link_mode; in sfxge_media_status()
876 ifmr->ifm_active |= sfxge_link_mode[medium_type][mode]; in sfxge_media_status()
877 ifmr->ifm_active |= sfxge_port_link_fc_ifm(sc); in sfxge_media_status()
925 efx_phy_media_type_get(sc->enp, &medium_type); in sfxge_phy_cap_mask()
927 if_printf(sc->ifnet, "unexpected media type %d\n", medium_type); in sfxge_phy_cap_mask()
931 efx_phy_adv_cap_get(sc->enp, EFX_PHY_CAP_PERM, &cap_mask); in sfxge_phy_cap_mask()
953 if_printf(sc->ifnet, in sfxge_phy_cap_mask()
983 ifm = sc->media.ifm_cur; in sfxge_media_change()
992 rc = efx_mac_fcntl_set(sc->enp, sfxge_port_wanted_fc(sc), B_TRUE); in sfxge_media_change()
996 if ((rc = sfxge_phy_cap_mask(sc, ifm->ifm_media, &phy_cap_mask)) != 0) in sfxge_media_change()
999 rc = efx_phy_adv_cap_set(sc->enp, phy_cap_mask); in sfxge_media_change()
1016 * We need port state to initialise the ifmedia list. in sfxge_port_ifmedia_init()
1020 if ((rc = efx_filter_init(sc->enp)) != 0) in sfxge_port_ifmedia_init()
1022 if ((rc = efx_port_init(sc->enp)) != 0) in sfxge_port_ifmedia_init()
1029 ifmedia_init(&sc->media, IFM_IMASK, sfxge_media_change, in sfxge_port_ifmedia_init()
1035 * and disabling auto-negotiation. 1000BASE-T and 10GBASE-T in sfxge_port_ifmedia_init()
1037 * 100BASE-TX it is useful even if the link mode is forced. in sfxge_port_ifmedia_init()
1038 * Therefore we never disable auto-negotiation. in sfxge_port_ifmedia_init()
1043 efx_phy_media_type_get(sc->enp, &medium_type); in sfxge_port_ifmedia_init()
1044 efx_phy_adv_cap_get(sc->enp, EFX_PHY_CAP_PERM, &cap_mask); in sfxge_port_ifmedia_init()
1055 /* No flow-control */ in sfxge_port_ifmedia_init()
1056 ifmedia_add(&sc->media, mode_ifm, 0, NULL); in sfxge_port_ifmedia_init()
1059 /* Respond-only. If using AN, we implicitly in sfxge_port_ifmedia_init()
1064 ifmedia_add(&sc->media, mode_ifm, 0, NULL); in sfxge_port_ifmedia_init()
1068 ifmedia_add(&sc->media, mode_ifm, 0, NULL); in sfxge_port_ifmedia_init()
1081 ifmedia_add(&sc->media, mode_ifm, 0, NULL); in sfxge_port_ifmedia_init()
1086 ifmedia_set(&sc->media, best_mode_ifm); in sfxge_port_ifmedia_init()
1088 /* Now discard port state until interface is started. */ in sfxge_port_ifmedia_init()
1089 efx_port_fini(sc->enp); in sfxge_port_ifmedia_init()
1091 efx_filter_fini(sc->enp); in sfxge_port_ifmedia_init()