Lines Matching defs:efx

41 #include "efx.h"
212 * @efx: The NIC context
285 struct efx_nic *efx;
347 void (*xmit_skb)(struct efx_nic *efx, struct sk_buff *skb);
358 bool efx_siena_ptp_use_mac_tx_timestamps(struct efx_nic *efx)
360 return efx_has_cap(efx, TX_MAC_TIMESTAMPING);
368 return efx_siena_ptp_use_mac_tx_timestamps(channel->efx);
396 size_t efx_siena_ptp_describe_stats(struct efx_nic *efx, u8 *strings)
398 if (!efx->ptp_data)
405 size_t efx_siena_ptp_update_stats(struct efx_nic *efx, u64 *stats)
412 if (!efx->ptp_data)
419 stats[i] = *(unsigned int *)((char *)efx->ptp_data +
429 rc = efx_siena_mcdi_rpc(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
539 struct efx_channel *efx_siena_ptp_channel(struct efx_nic *efx)
541 return efx->ptp_data ? efx->ptp_data->channel : NULL;
544 static u32 last_sync_timestamp_major(struct efx_nic *efx)
546 struct efx_channel *channel = efx_siena_ptp_channel(efx);
558 efx_ptp_mac_nic_to_ktime_correction(struct efx_nic *efx,
588 sync_timestamp = last_sync_timestamp_major(efx);
611 struct efx_nic *efx = tx_queue->efx;
612 struct efx_ptp_data *ptp = efx->ptp_data;
615 if (efx_siena_ptp_use_mac_tx_timestamps(efx))
616 kt = efx_ptp_mac_nic_to_ktime_correction(efx, ptp,
629 static int efx_ptp_get_attributes(struct efx_nic *efx)
633 struct efx_ptp_data *ptp = efx->ptp_data;
644 rc = efx_siena_mcdi_rpc_quiet(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
651 pci_info(efx->pci_dev, "no PTP support\n");
654 efx_siena_mcdi_display_error(efx, MC_CMD_PTP, sizeof(inbuf),
728 static int efx_ptp_get_timestamp_corrections(struct efx_nic *efx)
742 rc = efx_siena_mcdi_rpc_quiet(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
745 efx->ptp_data->ts_corrections.ptp_tx = MCDI_DWORD(outbuf,
747 efx->ptp_data->ts_corrections.ptp_rx = MCDI_DWORD(outbuf,
749 efx->ptp_data->ts_corrections.pps_out = MCDI_DWORD(outbuf,
751 efx->ptp_data->ts_corrections.pps_in = MCDI_DWORD(outbuf,
755 efx->ptp_data->ts_corrections.general_tx = MCDI_DWORD(
758 efx->ptp_data->ts_corrections.general_rx = MCDI_DWORD(
762 efx->ptp_data->ts_corrections.general_tx =
763 efx->ptp_data->ts_corrections.ptp_tx;
764 efx->ptp_data->ts_corrections.general_rx =
765 efx->ptp_data->ts_corrections.ptp_rx;
768 efx->ptp_data->ts_corrections.ptp_tx = 0;
769 efx->ptp_data->ts_corrections.ptp_rx = 0;
770 efx->ptp_data->ts_corrections.pps_out = 0;
771 efx->ptp_data->ts_corrections.pps_in = 0;
772 efx->ptp_data->ts_corrections.general_tx = 0;
773 efx->ptp_data->ts_corrections.general_rx = 0;
775 efx_siena_mcdi_display_error(efx, MC_CMD_PTP, sizeof(inbuf),
784 static int efx_ptp_enable(struct efx_nic *efx)
793 efx->ptp_data->channel ?
794 efx->ptp_data->channel->channel : 0);
795 MCDI_SET_DWORD(inbuf, PTP_IN_ENABLE_MODE, efx->ptp_data->mode);
797 rc = efx_siena_mcdi_rpc_quiet(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
801 efx_siena_mcdi_display_error(efx, MC_CMD_PTP,
812 static int efx_ptp_disable(struct efx_nic *efx)
820 rc = efx_siena_mcdi_rpc_quiet(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
827 pci_info(efx->pci_dev, "no PTP support\n");
829 efx_siena_mcdi_display_error(efx, MC_CMD_PTP,
846 static void efx_ptp_handle_no_channel(struct efx_nic *efx)
848 netif_err(efx, drv, efx->net_dev,
856 static void efx_ptp_send_times(struct efx_nic *efx,
861 struct efx_ptp_data *ptp = efx->ptp_data;
886 efx->type->ptp_write_host_time(efx, host_time);
922 efx_ptp_process_times(struct efx_nic *efx, MCDI_DECLARE_STRUCT_PTR(synch_buf),
932 struct efx_ptp_data *ptp = efx->ptp_data;
983 netif_warn(efx, drv, efx->net_dev,
998 netif_warn(efx, hw, efx->net_dev,
1025 static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
1027 struct efx_ptp_data *ptp = efx->ptp_data;
1045 rc = efx_siena_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
1062 efx_ptp_send_times(efx, &last_time);
1065 rc = efx_siena_mcdi_rpc_finish(efx, MC_CMD_PTP,
1070 rc = efx_ptp_process_times(efx, synch_buf, response_length,
1088 static void efx_ptp_xmit_skb_queue(struct efx_nic *efx, struct sk_buff *skb)
1090 struct efx_ptp_data *ptp_data = efx->ptp_data;
1104 static void efx_ptp_xmit_skb_mc(struct efx_nic *efx, struct sk_buff *skb)
1106 struct efx_ptp_data *ptp_data = efx->ptp_data;
1130 rc = efx_siena_mcdi_rpc(efx, MC_CMD_PTP, ptp_data->txbuf,
1152 static void efx_ptp_drop_time_expired_events(struct efx_nic *efx)
1154 struct efx_ptp_data *ptp = efx->ptp_data;
1170 netif_warn(efx, hw, efx->net_dev,
1177 static enum ptp_packet_state efx_ptp_match_rx(struct efx_nic *efx,
1180 struct efx_ptp_data *ptp = efx->ptp_data;
1226 static void efx_ptp_process_events(struct efx_nic *efx, struct sk_buff_head *q)
1228 struct efx_ptp_data *ptp = efx->ptp_data;
1237 } else if (efx_ptp_match_rx(efx, skb) ==
1253 static inline void efx_ptp_process_rx(struct efx_nic *efx, struct sk_buff *skb)
1260 static void efx_ptp_remove_multicast_filters(struct efx_nic *efx)
1262 struct efx_ptp_data *ptp = efx->ptp_data;
1265 efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED,
1267 efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED,
1273 static int efx_ptp_insert_multicast_filters(struct efx_nic *efx)
1275 struct efx_ptp_data *ptp = efx->ptp_data;
1294 rc = efx_filter_insert_filter(efx, &rxfilter, true);
1308 rc = efx_filter_insert_filter(efx, &rxfilter, true);
1317 efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED,
1322 static int efx_ptp_start(struct efx_nic *efx)
1324 struct efx_ptp_data *ptp = efx->ptp_data;
1329 rc = efx_ptp_insert_multicast_filters(efx);
1333 rc = efx_ptp_enable(efx);
1343 efx_ptp_remove_multicast_filters(efx);
1347 static int efx_ptp_stop(struct efx_nic *efx)
1349 struct efx_ptp_data *ptp = efx->ptp_data;
1357 rc = efx_ptp_disable(efx);
1359 efx_ptp_remove_multicast_filters(efx);
1362 efx_ptp_deliver_rx_queue(&efx->ptp_data->rxq);
1363 skb_queue_purge(&efx->ptp_data->txq);
1366 spin_lock_bh(&efx->ptp_data->evt_lock);
1367 list_for_each_safe(cursor, next, &efx->ptp_data->evt_list) {
1368 list_move(cursor, &efx->ptp_data->evt_free_list);
1370 spin_unlock_bh(&efx->ptp_data->evt_lock);
1375 static int efx_ptp_restart(struct efx_nic *efx)
1377 if (efx->ptp_data && efx->ptp_data->enabled)
1378 return efx_ptp_start(efx);
1386 struct efx_nic *efx = ptp->efx;
1389 if (efx_ptp_synchronize(efx, PTP_SYNC_ATTEMPTS))
1401 struct efx_nic *efx = ptp_data->efx;
1406 efx_ptp_stop(efx);
1407 efx_ptp_start(efx);
1411 efx_ptp_drop_time_expired_events(efx);
1414 efx_ptp_process_events(efx, &tempq);
1417 ptp_data->xmit_skb(efx, skb);
1420 efx_ptp_process_rx(efx, skb);
1440 static int efx_ptp_probe(struct efx_nic *efx, struct efx_channel *channel)
1447 efx->ptp_data = ptp;
1448 if (!efx->ptp_data)
1451 ptp->efx = efx;
1453 ptp->rx_ts_inline = efx_nic_rev(efx) >= EFX_REV_HUNT_A0;
1455 rc = efx_siena_alloc_buffer(efx, &ptp->start, sizeof(int), GFP_KERNEL);
1467 if (efx_siena_ptp_use_mac_tx_timestamps(efx)) {
1486 rc = efx_ptp_get_attributes(efx);
1491 rc = efx_ptp_get_timestamp_corrections(efx);
1495 if (efx->mcdi->fn_flags &
1499 &efx->pci_dev->dev);
1517 ptp_clock_unregister(efx->ptp_data->phc_clock);
1520 destroy_workqueue(efx->ptp_data->workwq);
1523 efx_siena_free_buffer(efx, &ptp->start);
1526 kfree(efx->ptp_data);
1527 efx->ptp_data = NULL;
1539 struct efx_nic *efx = channel->efx;
1545 rc = efx_ptp_probe(efx, channel);
1552 netif_warn(efx, drv, efx->net_dev,
1557 static void efx_ptp_remove(struct efx_nic *efx)
1559 if (!efx->ptp_data)
1562 (void)efx_ptp_disable(efx);
1564 cancel_work_sync(&efx->ptp_data->work);
1565 if (efx->ptp_data->pps_workwq)
1566 cancel_work_sync(&efx->ptp_data->pps_work);
1568 skb_queue_purge(&efx->ptp_data->rxq);
1569 skb_queue_purge(&efx->ptp_data->txq);
1571 if (efx->ptp_data->phc_clock) {
1572 destroy_workqueue(efx->ptp_data->pps_workwq);
1573 ptp_clock_unregister(efx->ptp_data->phc_clock);
1576 destroy_workqueue(efx->ptp_data->workwq);
1578 efx_siena_free_buffer(efx, &efx->ptp_data->start);
1579 kfree(efx->ptp_data);
1580 efx->ptp_data = NULL;
1585 efx_ptp_remove(channel->efx);
1591 snprintf(buf, len, "%s-ptp", channel->efx->name);
1597 bool efx_siena_ptp_is_ptp_tx(struct efx_nic *efx, struct sk_buff *skb)
1599 return efx->ptp_data &&
1600 efx->ptp_data->enabled &&
1618 struct efx_nic *efx = channel->efx;
1619 struct efx_ptp_data *ptp = efx->ptp_data;
1703 int efx_siena_ptp_tx(struct efx_nic *efx, struct sk_buff *skb)
1705 struct efx_ptp_data *ptp = efx->ptp_data;
1717 int efx_siena_ptp_get_mode(struct efx_nic *efx)
1719 return efx->ptp_data->mode;
1722 int efx_siena_ptp_change_mode(struct efx_nic *efx, bool enable_wanted,
1725 if ((enable_wanted != efx->ptp_data->enabled) ||
1726 (enable_wanted && (efx->ptp_data->mode != new_mode))) {
1731 if (efx->ptp_data->enabled &&
1732 (efx->ptp_data->mode != new_mode)) {
1733 efx->ptp_data->enabled = false;
1734 rc = efx_ptp_stop(efx);
1743 efx->ptp_data->mode = new_mode;
1744 if (netif_running(efx->net_dev))
1745 rc = efx_ptp_start(efx);
1747 rc = efx_ptp_synchronize(efx,
1750 efx_ptp_stop(efx);
1753 rc = efx_ptp_stop(efx);
1759 efx->ptp_data->enabled = enable_wanted;
1765 static int efx_ptp_ts_init(struct efx_nic *efx, struct hwtstamp_config *init)
1773 rc = efx->type->ptp_set_ts_config(efx, init);
1777 efx->ptp_data->config = *init;
1781 void efx_siena_ptp_get_ts_info(struct efx_nic *efx,
1784 struct efx_ptp_data *ptp = efx->ptp_data;
1785 struct efx_nic *primary = efx->primary;
1799 ts_info->rx_filters = ptp->efx->type->hwtstamp_filters;
1802 int efx_siena_ptp_set_ts_config(struct efx_nic *efx, struct ifreq *ifr)
1808 if (!efx->ptp_data)
1814 rc = efx_ptp_ts_init(efx, &config);
1822 int efx_siena_ptp_get_ts_config(struct efx_nic *efx, struct ifreq *ifr)
1824 if (!efx->ptp_data)
1827 return copy_to_user(ifr->ifr_data, &efx->ptp_data->config,
1828 sizeof(efx->ptp_data->config)) ? -EFAULT : 0;
1831 static void ptp_event_failure(struct efx_nic *efx, int expected_frag_len)
1833 struct efx_ptp_data *ptp = efx->ptp_data;
1835 netif_err(efx, hw, efx->net_dev,
1846 static void ptp_event_rx(struct efx_nic *efx, struct efx_ptp_data *ptp)
1854 ptp_event_failure(efx, 3);
1871 evt->hwtimestamp = efx->ptp_data->nic_to_kernel_time(
1881 netif_err(efx, rx_err, efx->net_dev, "PTP event queue overflow\n");
1886 static void ptp_event_fault(struct efx_nic *efx, struct efx_ptp_data *ptp)
1890 ptp_event_failure(efx, 1);
1894 netif_err(efx, hw, efx->net_dev, "PTP error %d\n", code);
1897 static void ptp_event_pps(struct efx_nic *efx, struct efx_ptp_data *ptp)
1903 void efx_siena_ptp_event(struct efx_nic *efx, efx_qword_t *ev)
1905 struct efx_ptp_data *ptp = efx->ptp_data;
1909 if (!efx->ptp_warned) {
1910 netif_warn(efx, drv, efx->net_dev,
1912 efx->ptp_warned = true;
1923 netif_err(efx, hw, efx->net_dev,
1933 ptp_event_rx(efx, ptp);
1936 ptp_event_fault(efx, ptp);
1939 ptp_event_pps(efx, ptp);
1942 netif_err(efx, hw, efx->net_dev,
1948 netif_err(efx, hw, efx->net_dev,
1956 struct efx_nic *efx = channel->efx;
1957 struct efx_ptp_data *ptp = efx->ptp_data;
1977 static inline u32 efx_rx_buf_timestamp_minor(struct efx_nic *efx, const u8 *eh)
1980 return __le32_to_cpup((const __le32 *)(eh + efx->rx_packet_ts_offset));
1982 const u8 *data = eh + efx->rx_packet_ts_offset;
1993 struct efx_nic *efx = channel->efx;
1994 struct efx_ptp_data *ptp = efx->ptp_data;
2002 pkt_timestamp_minor = efx_rx_buf_timestamp_minor(efx, skb_mac_header(skb));
2032 netif_vdbg(efx, drv, efx->net_dev,
2053 struct efx_nic *efx = ptp_data->efx;
2073 rc = efx_siena_mcdi_rpc(efx, MC_CMD_PTP, inadj, sizeof(inadj),
2088 struct efx_nic *efx = ptp_data->efx;
2091 efx->ptp_data->ns_to_nic_time(delta, &nic_major, &nic_minor);
2098 return efx_siena_mcdi_rpc(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
2107 struct efx_nic *efx = ptp_data->efx;
2116 rc = efx_siena_mcdi_rpc(efx, MC_CMD_PTP, inbuf, sizeof(inbuf),
2177 void efx_siena_ptp_defer_probe_with_channel(struct efx_nic *efx)
2182 if (efx_ptp_disable(efx) == 0)
2183 efx->extra_channel_type[EFX_EXTRA_CHANNEL_PTP] =
2187 void efx_siena_ptp_start_datapath(struct efx_nic *efx)
2189 if (efx_ptp_restart(efx))
2190 netif_err(efx, drv, efx->net_dev, "Failed to restart PTP.\n");
2192 if (efx->type->ptp_set_ts_sync_events)
2193 efx->type->ptp_set_ts_sync_events(efx, true, true);
2196 void efx_siena_ptp_stop_datapath(struct efx_nic *efx)
2199 if (efx->type->ptp_set_ts_sync_events)
2200 efx->type->ptp_set_ts_sync_events(efx, false, true);
2201 efx_ptp_stop(efx);