staticint mv88e6xxx_port_ptp_read(struct mv88e6xxx_chip *chip, int port, int addr, u16 *data, int len)
{ if (!chip->info->ops->avb_ops->port_ptp_read) return -EOPNOTSUPP;
staticint mv88e6xxx_port_ptp_write(struct mv88e6xxx_chip *chip, int port, int addr, u16 data)
{ if (!chip->info->ops->avb_ops->port_ptp_write) return -EOPNOTSUPP;
/* TX_TSTAMP_TIMEOUT: This limits the time spent polling for a TX * timestamp. When working properly, hardware will produce a timestamp * within 1ms. Software may enounter delays due to MDIO contention, so * the timeout is set accordingly.
*/ #define TX_TSTAMP_TIMEOUT msecs_to_jiffies(40)
int mv88e6xxx_get_ts_info(struct dsa_switch *ds, int port, struct kernel_ethtool_ts_info *info)
{ conststruct mv88e6xxx_ptp_ops *ptp_ops; struct mv88e6xxx_chip *chip;
/* Prevent the TX/RX paths from trying to interact with the * timestamp hardware while we reconfigure it.
*/
clear_bit_unlock(MV88E6XXX_HWTSTAMP_ENABLED, &ps->state);
switch (config->tx_type) { case HWTSTAMP_TX_OFF:
tstamp_enable = false; break; case HWTSTAMP_TX_ON:
tstamp_enable = true; break; default: return -ERANGE;
}
/* The switch supports timestamping both L2 and L4; one cannot be * disabled independently of the other.
*/
switch (config->rx_filter) { case HWTSTAMP_FILTER_NONE:
tstamp_enable = false; break; case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: case HWTSTAMP_FILTER_PTP_V2_EVENT: case HWTSTAMP_FILTER_PTP_V2_SYNC: case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; break; case HWTSTAMP_FILTER_ALL: default:
config->rx_filter = HWTSTAMP_FILTER_NONE; return -ERANGE;
}
mv88e6xxx_reg_lock(chip); if (tstamp_enable) {
chip->enable_count += 1; if (chip->enable_count == 1 && ptp_ops->global_enable)
ptp_ops->global_enable(chip); if (ptp_ops->port_enable)
ptp_ops->port_enable(chip, port);
} else { if (ptp_ops->port_disable)
ptp_ops->port_disable(chip, port);
chip->enable_count -= 1; if (chip->enable_count == 0 && ptp_ops->global_disable)
ptp_ops->global_disable(chip);
}
mv88e6xxx_reg_unlock(chip);
/* Once hardware has been configured, enable timestamp checks * in the RX/TX paths.
*/ if (tstamp_enable)
set_bit(MV88E6XXX_HWTSTAMP_ENABLED, &ps->state);
return 0;
}
int mv88e6xxx_port_hwtstamp_set(struct dsa_switch *ds, int port, struct kernel_hwtstamp_config *config, struct netlink_ext_ack *extack)
{ struct mv88e6xxx_chip *chip = ds->priv; struct mv88e6xxx_port_hwtstamp *ps = &chip->port_hwtstamp[port]; int err;
if (!chip->info->ptp_support) return -EOPNOTSUPP;
err = mv88e6xxx_set_hwtstamp_config(chip, port, config); if (err) return err;
/* Save the chosen configuration to be returned later. */
ps->tstamp_config = *config;
return 0;
}
int mv88e6xxx_port_hwtstamp_get(struct dsa_switch *ds, int port, struct kernel_hwtstamp_config *config)
{ struct mv88e6xxx_chip *chip = ds->priv; struct mv88e6xxx_port_hwtstamp *ps = &chip->port_hwtstamp[port];
if (!chip->info->ptp_support) return -EOPNOTSUPP;
*config = ps->tstamp_config;
return 0;
}
/* Returns a pointer to the PTP header if the caller should time stamp, * or NULL if the caller should not.
*/ staticstruct ptp_header *mv88e6xxx_should_tstamp(struct mv88e6xxx_chip *chip, int port, struct sk_buff *skb, unsignedint type)
{ struct mv88e6xxx_port_hwtstamp *ps = &chip->port_hwtstamp[port]; struct ptp_header *hdr;
if (!chip->info->ptp_support) return NULL;
hdr = ptp_parse_header(skb, type); if (!hdr) return NULL;
if (!test_bit(MV88E6XXX_HWTSTAMP_ENABLED, &ps->state)) return NULL;
return hdr;
}
staticint mv88e6xxx_ts_valid(u16 status)
{ if (!(status & MV88E6XXX_PTP_TS_VALID)) return 0; if (status & MV88E6XXX_PTP_TS_STATUS_MASK) return 0; return 1;
}
/* The latched timestamp belongs to one of the received frames. */
__skb_queue_head_init(&received);
spin_lock_irqsave(&rxq->lock, flags);
skb_queue_splice_tail_init(rxq, &received);
spin_unlock_irqrestore(&rxq->lock, flags);
mv88e6xxx_reg_lock(chip);
err = mv88e6xxx_port_ptp_read(chip, ps->port_id,
reg, buf, ARRAY_SIZE(buf));
mv88e6xxx_reg_unlock(chip); if (err)
pr_err("failed to get the receive time stamp\n");
if (status & MV88E6XXX_PTP_TS_VALID) {
mv88e6xxx_reg_lock(chip);
err = mv88e6xxx_port_ptp_write(chip, ps->port_id, reg, 0);
mv88e6xxx_reg_unlock(chip); if (err)
pr_err("failed to clear the receive status\n");
} /* Since the device can only handle one time stamp at a time, * we purge any extra frames from the queue.
*/ for ( ; skb; skb = __skb_dequeue(&received)) { if (mv88e6xxx_ts_valid(status) && seq_match(skb, seq_id)) {
ns = timehi << 16 | timelo;
if (!(departure_block[0] & MV88E6XXX_PTP_TS_VALID)) { if (time_is_before_jiffies(ps->tx_tstamp_start +
TX_TSTAMP_TIMEOUT)) {
dev_warn(chip->dev, "p%d: clearing tx timestamp hang\n",
ps->port_id); goto free_and_clear_skb;
} /* The timestamp should be available quickly, while getting it * is high priority and time bounded to only 10ms. A poll is * warranted so restart the work.
*/ return 1;
}
/* We have the timestamp; go ahead and clear valid now */
mv88e6xxx_reg_lock(chip);
mv88e6xxx_port_ptp_write(chip, ps->port_id, ptp_ops->dep_sts_reg, 0);
mv88e6xxx_reg_unlock(chip);
status = departure_block[0] & MV88E6XXX_PTP_TS_STATUS_MASK; if (status != MV88E6XXX_PTP_TS_STATUS_NORMAL) {
dev_warn(chip->dev, "p%d: tx timestamp overrun\n", ps->port_id); goto free_and_clear_skb;
}
dev_dbg(chip->dev, "p%d: txtstamp %llx status 0x%04x skb ID 0x%04x hw ID 0x%04x\n",
ps->port_id, ktime_to_ns(shhwtstamps.hwtstamp),
departure_block[0], ps->tx_seq_id, departure_block[3]);
/* skb_complete_tx_timestamp() will free up the client to make * another timestamp-able transmit. We have to be ready for it * -- by clearing the ps->tx_skb "flag" -- beforehand.
*/
if (ptp_ops->port_disable) return ptp_ops->port_disable(chip, port);
return 0;
}
int mv88e6xxx_hwtstamp_setup(struct mv88e6xxx_chip *chip)
{ conststruct mv88e6xxx_ptp_ops *ptp_ops = chip->info->ops->ptp_ops; int err; int i;
/* Disable timestamping on all ports. */ for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
err = mv88e6xxx_hwtstamp_port_setup(chip, i); if (err) return err;
}
/* Disable PTP globally */ if (ptp_ops->global_disable) {
err = ptp_ops->global_disable(chip); if (err) return err;
}
/* Set the ethertype of L2 PTP messages */
err = mv88e6xxx_ptp_write(chip, MV88E6XXX_PTP_GC_ETYPE, ETH_P_1588); if (err) return err;
/* MV88E6XXX_PTP_MSG_TYPE is a mask of PTP message types to * timestamp. This affects all ports that have timestamping enabled, * but the timestamp config is per-port; thus we configure all events * here and only support the HWTSTAMP_FILTER_*_EVENT filter types.
*/
err = mv88e6xxx_ptp_write(chip, MV88E6XXX_PTP_MSGTYPE,
MV88E6XXX_PTP_MSGTYPE_ALL_EVENT); if (err) return err;
/* Use ARRIVAL1 for peer delay response messages. */
err = mv88e6xxx_ptp_write(chip, MV88E6XXX_PTP_TS_ARRIVAL_PTR,
MV88E6XXX_PTP_MSGTYPE_PDLAY_RES); if (err) return err;
/* 88E6341 devices default to timestamping at the PHY, but this has * a hardware issue that results in unreliable timestamps. Force * these devices to timestamp at the MAC.
*/ if (chip->info->family == MV88E6XXX_FAMILY_6341) {
u16 val = MV88E6341_PTP_CFG_UPDATE |
MV88E6341_PTP_CFG_MODE_IDX |
MV88E6341_PTP_CFG_MODE_TS_AT_MAC;
err = mv88e6xxx_ptp_write(chip, MV88E6341_PTP_CFG, val); if (err) return err;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.