- /*
- * Enable timestamping of received PTP packets.
- */
- tsync_ctl = port_id_pci_reg_read(pi, IGBE_82576_TSYNCRXCTL);
- tsync_ctl |= IGBE_82576_TSYNCRXCTL_RXTS_ENABLE;
- port_id_pci_reg_write(pi, IGBE_82576_TSYNCRXCTL, tsync_ctl);
-
- /*
- * Enable Timestamping of transmitted PTP packets.
- */
- tsync_ctl = port_id_pci_reg_read(pi, IGBE_82576_TSYNCTXCTL);
- tsync_ctl |= IGBE_82576_TSYNCTXCTL_TXTS_ENABLE;
- port_id_pci_reg_write(pi, IGBE_82576_TSYNCTXCTL, tsync_ctl);
-}
-
-static void
-igbe_82576_ieee1588_stop(portid_t pi)
-{
- uint32_t tsync_ctl;
-
- /*
- * Disable Timestamping of transmitted PTP packets.
- */
- tsync_ctl = port_id_pci_reg_read(pi, IGBE_82576_TSYNCTXCTL);
- tsync_ctl &= ~IGBE_82576_TSYNCTXCTL_TXTS_ENABLE;
- port_id_pci_reg_write(pi, IGBE_82576_TSYNCTXCTL, tsync_ctl);
-
- /*
- * Disable timestamping of received PTP packets.
- */
- tsync_ctl = port_id_pci_reg_read(pi, IGBE_82576_TSYNCRXCTL);
- tsync_ctl &= ~IGBE_82576_TSYNCRXCTL_RXTS_ENABLE;
- port_id_pci_reg_write(pi, IGBE_82576_TSYNCRXCTL, tsync_ctl);
-
- /*
- * Disable L2 filtering of IEEE1588 Ethernet types.
- */
- port_id_pci_reg_write(pi, IGBE_82576_ETQF(ETQF_FILTER_1588_REG), 0);
-
- /*
- * Stop incrementation of the System Time registers.
- */
- port_id_pci_reg_write(pi, IGBE_82576_TIMINCA, 0);
-}
-
-/**
- * Return the 64-bit value contained in the RX IEEE1588 timestamp registers
- * of a 1GbE 82576 port.
- *
- * @param pi
- * The port identifier.
- *
- * @param tmst
- * The address of a 64-bit variable to return the value of the RX timestamp.
- *
- * @return
- * -1: the RXSTMPL and RXSTMPH registers of the port are not valid.
- * 0: the variable pointed to by the "tmst" parameter contains the value
- * of the RXSTMPL and RXSTMPH registers of the port.
- */
-static int
-igbe_82576_rx_timestamp_read(portid_t pi, uint64_t *tmst)
-{
- uint32_t tsync_rxctl;
- uint32_t rx_stmpl;
- uint32_t rx_stmph;
-
- tsync_rxctl = port_id_pci_reg_read(pi, IGBE_82576_TSYNCRXCTL);
- if ((tsync_rxctl & 0x01) == 0)
- return (-1);
-
- rx_stmpl = port_id_pci_reg_read(pi, IGBE_82576_RXSTMPL);
- rx_stmph = port_id_pci_reg_read(pi, IGBE_82576_RXSTMPH);
- *tmst = (uint64_t)(((uint64_t) rx_stmph << 32) | rx_stmpl);
- return (0);
-}
-
-/**
- * Return the 64-bit value contained in the TX IEEE1588 timestamp registers
- * of a 1GbE 82576 port.
- *
- * @param pi
- * The port identifier.
- *
- * @param tmst
- * The address of a 64-bit variable to return the value of the TX timestamp.
- *
- * @return
- * -1: the TXSTMPL and TXSTMPH registers of the port are not valid.
- * 0: the variable pointed to by the "tmst" parameter contains the value
- * of the TXSTMPL and TXSTMPH registers of the port.
- */
-static int
-igbe_82576_tx_timestamp_read(portid_t pi, uint64_t *tmst)
-{
- uint32_t tsync_txctl;
- uint32_t tx_stmpl;
- uint32_t tx_stmph;
-
- tsync_txctl = port_id_pci_reg_read(pi, IGBE_82576_TSYNCTXCTL);
- if ((tsync_txctl & 0x01) == 0)
- return (-1);
-
- tx_stmpl = port_id_pci_reg_read(pi, IGBE_82576_TXSTMPL);
- tx_stmph = port_id_pci_reg_read(pi, IGBE_82576_TXSTMPH);
- *tmst = (uint64_t)(((uint64_t) tx_stmph << 32) | tx_stmpl);
- return (0);
-}
-
-static struct port_ieee1588_ops igbe_82576_ieee1588_ops = {
- .ieee1588_start = igbe_82576_ieee1588_start,
- .ieee1588_stop = igbe_82576_ieee1588_stop,
- .rx_tmst_read = igbe_82576_rx_timestamp_read,
- .tx_tmst_read = igbe_82576_tx_timestamp_read,
-};
-
-/**
- * 10GbE 82599 IEEE1588 operations.
- */
-static void
-ixgbe_82599_ieee1588_start(portid_t pi)
-{
- uint32_t tsync_ctl;
-
- /*
- * Start incrementation of the System Time registers used to
- * timestamp PTP packets.
- */
- port_id_pci_reg_write(pi, IXGBE_82599_TIMINCA, IEEE1588_TIMINCA_INIT);
-
- /*
- * Enable L2 filtering of IEEE1588 Ethernet frame types.
- */
- port_id_pci_reg_write(pi, IXGBE_82599_ETQF(ETQF_FILTER_1588_REG),
- (ETHER_TYPE_1588 |
- IXGBE_82599_ETQF_FILTER_ENABLE |
- IXGBE_82599_ETQF_1588_TIMESTAMP));
-
- /*
- * Enable timestamping of received PTP packets.
- */
- tsync_ctl = port_id_pci_reg_read(pi, IXGBE_82599_TSYNCRXCTL);
- tsync_ctl |= IXGBE_82599_TSYNCRXCTL_RXTS_ENABLE;
- port_id_pci_reg_write(pi, IXGBE_82599_TSYNCRXCTL, tsync_ctl);
-
- /*
- * Enable Timestamping of transmitted PTP packets.
- */
- tsync_ctl = port_id_pci_reg_read(pi, IXGBE_82599_TSYNCTXCTL);
- tsync_ctl |= IXGBE_82599_TSYNCTXCTL_TXTS_ENABLE;
- port_id_pci_reg_write(pi, IXGBE_82599_TSYNCTXCTL, tsync_ctl);
-}
-
-static void
-ixgbe_82599_ieee1588_stop(portid_t pi)
-{
- uint32_t tsync_ctl;
-
- /*
- * Disable Timestamping of transmitted PTP packets.
- */
- tsync_ctl = port_id_pci_reg_read(pi, IXGBE_82599_TSYNCTXCTL);
- tsync_ctl &= ~IXGBE_82599_TSYNCTXCTL_TXTS_ENABLE;
- port_id_pci_reg_write(pi, IXGBE_82599_TSYNCTXCTL, tsync_ctl);
-
- /*
- * Disable timestamping of received PTP packets.
- */
- tsync_ctl = port_id_pci_reg_read(pi, IXGBE_82599_TSYNCRXCTL);
- tsync_ctl &= ~IXGBE_82599_TSYNCRXCTL_RXTS_ENABLE;
- port_id_pci_reg_write(pi, IXGBE_82599_TSYNCRXCTL, tsync_ctl);
-
- /*
- * Disable L2 filtering of IEEE1588 Ethernet frame types.
- */
- port_id_pci_reg_write(pi, IXGBE_82599_ETQF(ETQF_FILTER_1588_REG), 0);
-
- /*
- * Stop incrementation of the System Time registers.
- */
- port_id_pci_reg_write(pi, IXGBE_82599_TIMINCA, 0);
-}
-
-/**
- * Return the 64-bit value contained in the RX IEEE1588 timestamp registers
- * of a 10GbE 82599 port.
- *
- * @param pi
- * The port identifier.
- *
- * @param tmst
- * The address of a 64-bit variable to return the value of the TX timestamp.
- *
- * @return
- * -1: the RX timestamp registers of the port are not valid.
- * 0: the variable pointed to by the "tmst" parameter contains the value
- * of the RXSTMPL and RXSTMPH registers of the port.
- */
-static int
-ixgbe_82599_rx_timestamp_read(portid_t pi, uint64_t *tmst)
-{
- uint32_t tsync_rxctl;
- uint32_t rx_stmpl;
- uint32_t rx_stmph;
-
- tsync_rxctl = port_id_pci_reg_read(pi, IXGBE_82599_TSYNCRXCTL);
- if ((tsync_rxctl & 0x01) == 0)
- return (-1);
-
- rx_stmpl = port_id_pci_reg_read(pi, IXGBE_82599_RXSTMPL);
- rx_stmph = port_id_pci_reg_read(pi, IXGBE_82599_RXSTMPH);
- *tmst = (uint64_t)(((uint64_t) rx_stmph << 32) | rx_stmpl);
- return (0);
-}
-
-/**
- * Return the 64-bit value contained in the TX IEEE1588 timestamp registers
- * of a 10GbE 82599 port.
- *
- * @param pi
- * The port identifier.
- *
- * @param tmst
- * The address of a 64-bit variable to return the value of the TX timestamp.
- *
- * @return
- * -1: the TXSTMPL and TXSTMPH registers of the port are not valid.
- * 0: the variable pointed to by the "tmst" parameter contains the value
- * of the TXSTMPL and TXSTMPH registers of the port.
- */
-static int
-ixgbe_82599_tx_timestamp_read(portid_t pi, uint64_t *tmst)
-{
- uint32_t tsync_txctl;
- uint32_t tx_stmpl;
- uint32_t tx_stmph;
-
- tsync_txctl = port_id_pci_reg_read(pi, IXGBE_82599_TSYNCTXCTL);
- if ((tsync_txctl & 0x01) == 0)
- return (-1);
-
- tx_stmpl = port_id_pci_reg_read(pi, IXGBE_82599_TXSTMPL);
- tx_stmph = port_id_pci_reg_read(pi, IXGBE_82599_TXSTMPH);
- *tmst = (uint64_t)(((uint64_t) tx_stmph << 32) | tx_stmpl);
- return (0);
-}
-
-static struct port_ieee1588_ops ixgbe_82599_ieee1588_ops = {
- .ieee1588_start = ixgbe_82599_ieee1588_start,
- .ieee1588_stop = ixgbe_82599_ieee1588_stop,
- .rx_tmst_read = ixgbe_82599_rx_timestamp_read,
- .tx_tmst_read = ixgbe_82599_tx_timestamp_read,
-};
-
-static void
-port_ieee1588_rx_timestamp_check(portid_t pi)
-{
- struct port_ieee1588_ops *ieee_ops;
- uint64_t rx_tmst;
-
- ieee_ops = (struct port_ieee1588_ops *)ports[pi].fwd_ctx;
- if (ieee_ops->rx_tmst_read(pi, &rx_tmst) < 0) {
- printf("Port %u: RX timestamp registers not valid\n",
- (unsigned) pi);