Date: Sun, 7 May 2017 00:26:57 +0000 (UTC) From: Alexander Motin <mav@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r317892 - in stable/11/sys/dev/ntb: . if_ntb Message-ID: <201705070026.v470QvVU033931@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mav Date: Sun May 7 00:26:57 2017 New Revision: 317892 URL: https://svnweb.freebsd.org/changeset/base/317892 Log: MFC r317340: Report NTB link speed to console and interface. Modified: stable/11/sys/dev/ntb/if_ntb/if_ntb.c stable/11/sys/dev/ntb/ntb.c stable/11/sys/dev/ntb/ntb_if.m stable/11/sys/dev/ntb/ntb_transport.c stable/11/sys/dev/ntb/ntb_transport.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/ntb/if_ntb/if_ntb.c ============================================================================== --- stable/11/sys/dev/ntb/if_ntb/if_ntb.c Sat May 6 23:05:49 2017 (r317891) +++ stable/11/sys/dev/ntb/if_ntb/if_ntb.c Sun May 7 00:26:57 2017 (r317892) @@ -225,6 +225,7 @@ ntb_net_init(void *arg) if_t ifp = sc->ifp; if_setdrvflagbits(ifp, IFF_DRV_RUNNING, IFF_DRV_OACTIVE); + if_setbaudrate(ifp, ntb_transport_link_speed(sc->queues[0].qp)); if_link_state_change(ifp, ntb_transport_link_query(sc->queues[0].qp) ? LINK_STATE_UP : LINK_STATE_DOWN); } @@ -474,20 +475,10 @@ static void ntb_net_event_handler(void *data, enum ntb_link_event status) { struct ntb_net_queue *q = data; - int new_state; - switch (status) { - case NTB_LINK_DOWN: - new_state = LINK_STATE_DOWN; - break; - case NTB_LINK_UP: - new_state = LINK_STATE_UP; - break; - default: - new_state = LINK_STATE_UNKNOWN; - break; - } - if_link_state_change(q->ifp, new_state); + if_setbaudrate(q->ifp, ntb_transport_link_speed(q->qp)); + if_link_state_change(q->ifp, (status == NTB_LINK_UP) ? LINK_STATE_UP : + LINK_STATE_DOWN); } /* Helper functions */ Modified: stable/11/sys/dev/ntb/ntb.c ============================================================================== --- stable/11/sys/dev/ntb/ntb.c Sat May 6 23:05:49 2017 (r317891) +++ stable/11/sys/dev/ntb/ntb.c Sun May 7 00:26:57 2017 (r317892) @@ -168,7 +168,15 @@ ntb_link_event(device_t dev) struct ntb_child **cpp = device_get_softc(dev); struct ntb_child *nc; struct rm_priotracker ctx_tracker; + enum ntb_speed speed; + enum ntb_width width; + if (NTB_LINK_IS_UP(dev, &speed, &width)) { + device_printf(dev, "Link is up (PCIe %d.x / x%d)\n", + (int)speed, (int)width); + } else { + device_printf(dev, "Link is down\n"); + } for (nc = *cpp; nc != NULL; nc = nc->next) { rm_rlock(&nc->ctx_lock, &ctx_tracker); if (nc->ctx_ops != NULL && nc->ctx_ops->link_event != NULL) Modified: stable/11/sys/dev/ntb/ntb_if.m ============================================================================== --- stable/11/sys/dev/ntb/ntb_if.m Sat May 6 23:05:49 2017 (r317891) +++ stable/11/sys/dev/ntb/ntb_if.m Sun May 7 00:26:57 2017 (r317892) @@ -38,6 +38,7 @@ HEADER { NTB_SPEED_GEN1 = 1, NTB_SPEED_GEN2 = 2, NTB_SPEED_GEN3 = 3, + NTB_SPEED_GEN4 = 4, }; enum ntb_width { Modified: stable/11/sys/dev/ntb/ntb_transport.c ============================================================================== --- stable/11/sys/dev/ntb/ntb_transport.c Sat May 6 23:05:49 2017 (r317891) +++ stable/11/sys/dev/ntb/ntb_transport.c Sun May 7 00:26:57 2017 (r317892) @@ -202,6 +202,8 @@ struct ntb_transport_ctx { unsigned qp_count; uint64_t qp_bitmap; volatile bool link_is_up; + enum ntb_speed link_speed; + enum ntb_width link_width; struct callout link_work; struct callout link_watchdog; struct task link_cleanup; @@ -1024,7 +1026,7 @@ ntb_transport_event_callback(void *data) { struct ntb_transport_ctx *nt = data; - if (ntb_link_is_up(nt->dev, NULL, NULL)) { + if (ntb_link_is_up(nt->dev, &nt->link_speed, &nt->link_width)) { ntb_printf(1, "HW link up\n"); callout_reset(&nt->link_work, 0, ntb_transport_link_work, nt); } else { @@ -1105,7 +1107,7 @@ free_mws: for (i = 0; i < nt->mw_count; i++) ntb_free_mw(nt, i); out: - if (ntb_link_is_up(dev, NULL, NULL)) + if (ntb_link_is_up(dev, &nt->link_speed, &nt->link_width)) callout_reset(&nt->link_work, NTB_LINK_DOWN_TIMEOUT * hz / 1000, ntb_transport_link_work, nt); } @@ -1379,6 +1381,43 @@ ntb_transport_link_query(struct ntb_tran return (qp->link_is_up); } +/** + * ntb_transport_link_speed - Query transport link speed + * @qp: NTB transport layer queue to be queried + * + * Query connection speed to the remote system of the NTB transport queue + * + * RETURNS: link speed in bits per second + */ +uint64_t +ntb_transport_link_speed(struct ntb_transport_qp *qp) +{ + struct ntb_transport_ctx *nt = qp->transport; + uint64_t rate; + + if (!nt->link_is_up) + return (0); + switch (nt->link_speed) { + case NTB_SPEED_GEN1: + rate = 2500000000 * 8 / 10; + break; + case NTB_SPEED_GEN2: + rate = 5000000000 * 8 / 10; + break; + case NTB_SPEED_GEN3: + rate = 8000000000 * 128 / 130; + break; + case NTB_SPEED_GEN4: + rate = 16000000000 * 128 / 130; + break; + default: + return (0); + } + if (nt->link_width <= 0) + return (0); + return (rate * nt->link_width); +} + static void ntb_send_link_down(struct ntb_transport_qp *qp) { Modified: stable/11/sys/dev/ntb/ntb_transport.h ============================================================================== --- stable/11/sys/dev/ntb/ntb_transport.h Sat May 6 23:05:49 2017 (r317891) +++ stable/11/sys/dev/ntb/ntb_transport.h Sun May 7 00:26:57 2017 (r317892) @@ -58,4 +58,5 @@ void *ntb_transport_rx_remove(struct ntb void ntb_transport_link_up(struct ntb_transport_qp *qp); void ntb_transport_link_down(struct ntb_transport_qp *qp); bool ntb_transport_link_query(struct ntb_transport_qp *qp); +uint64_t ntb_transport_link_speed(struct ntb_transport_qp *qp); unsigned int ntb_transport_tx_free_entry(struct ntb_transport_qp *qp);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201705070026.v470QvVU033931>