-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net/mlx4_en: Add HW timestamping (TS) support
The patch allows to enable/disable HW timestamping for incoming and/or outgoing packets. It adds and initializes all structs and callbacks needed by kernel TS API. To enable/disable HW timestamping appropriate ioctl should be used. Currently HWTSTAMP_FILTER_ALL/NONE and HWTSAMP_TX_ON/OFF only are supported. When enabling TS on receive flow - VLAN stripping will be disabled. Also were made all relevant changes in RX/TX flows to consider TS request and plant HW timestamps into relevant structures. mlx4_ib was fixed to compile with new mlx4_cq_alloc() signature. Signed-off-by: Eugenia Emantayev <eugenia@mellanox.com> Signed-off-by: Amir Vadai <amirv@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
- Loading branch information
Amir Vadai
authored and
David S. Miller
committed
Apr 24, 2013
1 parent
ddd8a6c
commit ec693d4
Showing
15 changed files
with
375 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Copyright (c) 2012 Mellanox Technologies. All rights reserved. | ||
* | ||
* This software is available to you under a choice of one of two | ||
* licenses. You may choose to be licensed under the terms of the GNU | ||
* General Public License (GPL) Version 2, available from the file | ||
* COPYING in the main directory of this source tree, or the | ||
* OpenIB.org BSD license below: | ||
* | ||
* Redistribution and use in source and binary forms, with or | ||
* without modification, are permitted provided that the following | ||
* conditions are met: | ||
* | ||
* - Redistributions of source code must retain the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer. | ||
* | ||
* - Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials | ||
* provided with the distribution. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
*/ | ||
|
||
#include <linux/mlx4/device.h> | ||
|
||
#include "mlx4_en.h" | ||
|
||
int mlx4_en_timestamp_config(struct net_device *dev, int tx_type, int rx_filter) | ||
{ | ||
struct mlx4_en_priv *priv = netdev_priv(dev); | ||
struct mlx4_en_dev *mdev = priv->mdev; | ||
int port_up = 0; | ||
int err = 0; | ||
|
||
mutex_lock(&mdev->state_lock); | ||
if (priv->port_up) { | ||
port_up = 1; | ||
mlx4_en_stop_port(dev, 1); | ||
} | ||
|
||
mlx4_en_free_resources(priv); | ||
|
||
en_warn(priv, "Changing Time Stamp configuration\n"); | ||
|
||
priv->hwtstamp_config.tx_type = tx_type; | ||
priv->hwtstamp_config.rx_filter = rx_filter; | ||
|
||
if (rx_filter != HWTSTAMP_FILTER_NONE) | ||
dev->features &= ~NETIF_F_HW_VLAN_CTAG_RX; | ||
else | ||
dev->features |= NETIF_F_HW_VLAN_CTAG_RX; | ||
|
||
err = mlx4_en_alloc_resources(priv); | ||
if (err) { | ||
en_err(priv, "Failed reallocating port resources\n"); | ||
goto out; | ||
} | ||
if (port_up) { | ||
err = mlx4_en_start_port(dev); | ||
if (err) | ||
en_err(priv, "Failed starting port\n"); | ||
} | ||
|
||
out: | ||
mutex_unlock(&mdev->state_lock); | ||
netdev_features_change(dev); | ||
return err; | ||
} | ||
|
||
/* mlx4_en_read_clock - read raw cycle counter (to be used by time counter) | ||
*/ | ||
static cycle_t mlx4_en_read_clock(const struct cyclecounter *tc) | ||
{ | ||
struct mlx4_en_dev *mdev = | ||
container_of(tc, struct mlx4_en_dev, cycles); | ||
struct mlx4_dev *dev = mdev->dev; | ||
|
||
return mlx4_read_clock(dev) & tc->mask; | ||
} | ||
|
||
u64 mlx4_en_get_cqe_ts(struct mlx4_cqe *cqe) | ||
{ | ||
u64 hi, lo; | ||
struct mlx4_ts_cqe *ts_cqe = (struct mlx4_ts_cqe *)cqe; | ||
|
||
lo = (u64)be16_to_cpu(ts_cqe->timestamp_lo); | ||
hi = ((u64)be32_to_cpu(ts_cqe->timestamp_hi) + !lo) << 16; | ||
|
||
return hi | lo; | ||
} | ||
|
||
void mlx4_en_fill_hwtstamps(struct mlx4_en_dev *mdev, | ||
struct skb_shared_hwtstamps *hwts, | ||
u64 timestamp) | ||
{ | ||
u64 nsec; | ||
|
||
nsec = timecounter_cyc2time(&mdev->clock, timestamp); | ||
|
||
memset(hwts, 0, sizeof(struct skb_shared_hwtstamps)); | ||
hwts->hwtstamp = ns_to_ktime(nsec); | ||
} | ||
|
||
void mlx4_en_init_timestamp(struct mlx4_en_dev *mdev) | ||
{ | ||
struct mlx4_dev *dev = mdev->dev; | ||
|
||
memset(&mdev->cycles, 0, sizeof(mdev->cycles)); | ||
mdev->cycles.read = mlx4_en_read_clock; | ||
mdev->cycles.mask = CLOCKSOURCE_MASK(48); | ||
/* Using shift to make calculation more accurate. Since current HW | ||
* clock frequency is 427 MHz, and cycles are given using a 48 bits | ||
* register, the biggest shift when calculating using u64, is 14 | ||
* (max_cycles * multiplier < 2^64) | ||
*/ | ||
mdev->cycles.shift = 14; | ||
mdev->cycles.mult = | ||
clocksource_khz2mult(1000 * dev->caps.hca_core_clock, mdev->cycles.shift); | ||
|
||
timecounter_init(&mdev->clock, &mdev->cycles, | ||
ktime_to_ns(ktime_get_real())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.