|
1 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
2 | 2 | /* |
3 | 3 | * aQuantia Corporation Network Driver |
4 | | - * Copyright (C) 2014-2017 aQuantia Corporation. All rights reserved |
| 4 | + * Copyright (C) 2014-2019 aQuantia Corporation. All rights reserved |
5 | 5 | */ |
6 | 6 |
|
7 | 7 | /* File aq_main.c: Main file for aQuantia Linux driver. */ |
|
10 | 10 | #include "aq_nic.h" |
11 | 11 | #include "aq_pci_func.h" |
12 | 12 | #include "aq_ethtool.h" |
| 13 | +#include "aq_ptp.h" |
13 | 14 | #include "aq_filters.h" |
14 | 15 |
|
15 | 16 | #include <linux/netdevice.h> |
16 | 17 | #include <linux/module.h> |
| 18 | +#include <linux/ip.h> |
| 19 | +#include <linux/udp.h> |
17 | 20 |
|
18 | 21 | MODULE_LICENSE("GPL v2"); |
19 | 22 | MODULE_VERSION(AQ_CFG_DRV_VERSION); |
@@ -93,6 +96,24 @@ static int aq_ndev_start_xmit(struct sk_buff *skb, struct net_device *ndev) |
93 | 96 | { |
94 | 97 | struct aq_nic_s *aq_nic = netdev_priv(ndev); |
95 | 98 |
|
| 99 | + if (unlikely(aq_utils_obj_test(&aq_nic->flags, AQ_NIC_PTP_DPATH_UP))) { |
| 100 | + /* Hardware adds the Timestamp for PTPv2 802.AS1 |
| 101 | + * and PTPv2 IPv4 UDP. |
| 102 | + * We have to push even general 320 port messages to the ptp |
| 103 | + * queue explicitly. This is a limitation of current firmware |
| 104 | + * and hardware PTP design of the chip. Otherwise ptp stream |
| 105 | + * will fail to sync |
| 106 | + */ |
| 107 | + if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) || |
| 108 | + unlikely((ip_hdr(skb)->version == 4) && |
| 109 | + (ip_hdr(skb)->protocol == IPPROTO_UDP) && |
| 110 | + ((udp_hdr(skb)->dest == htons(319)) || |
| 111 | + (udp_hdr(skb)->dest == htons(320)))) || |
| 112 | + unlikely(eth_hdr(skb)->h_proto == htons(ETH_P_1588))) |
| 113 | + return aq_ptp_xmit(aq_nic, skb); |
| 114 | + } |
| 115 | + |
| 116 | + skb_tx_timestamp(skb); |
96 | 117 | return aq_nic_xmit(aq_nic, skb); |
97 | 118 | } |
98 | 119 |
|
@@ -197,6 +218,87 @@ static void aq_ndev_set_multicast_settings(struct net_device *ndev) |
197 | 218 | (void)aq_nic_set_multicast_list(aq_nic, ndev); |
198 | 219 | } |
199 | 220 |
|
| 221 | +static int aq_ndev_config_hwtstamp(struct aq_nic_s *aq_nic, |
| 222 | + struct hwtstamp_config *config) |
| 223 | +{ |
| 224 | + if (config->flags) |
| 225 | + return -EINVAL; |
| 226 | + |
| 227 | + switch (config->tx_type) { |
| 228 | + case HWTSTAMP_TX_OFF: |
| 229 | + case HWTSTAMP_TX_ON: |
| 230 | + break; |
| 231 | + default: |
| 232 | + return -ERANGE; |
| 233 | + } |
| 234 | + |
| 235 | + switch (config->rx_filter) { |
| 236 | + case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 237 | + case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 238 | + case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 239 | + case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
| 240 | + case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 241 | + case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 242 | + case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 243 | + case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 244 | + config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; |
| 245 | + break; |
| 246 | + case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 247 | + case HWTSTAMP_FILTER_NONE: |
| 248 | + break; |
| 249 | + default: |
| 250 | + return -ERANGE; |
| 251 | + } |
| 252 | + |
| 253 | + return aq_ptp_hwtstamp_config_set(aq_nic->aq_ptp, config); |
| 254 | +} |
| 255 | + |
| 256 | +static int aq_ndev_hwtstamp_set(struct aq_nic_s *aq_nic, struct ifreq *ifr) |
| 257 | +{ |
| 258 | + struct hwtstamp_config config; |
| 259 | + int ret_val; |
| 260 | + |
| 261 | + if (!aq_nic->aq_ptp) |
| 262 | + return -EOPNOTSUPP; |
| 263 | + |
| 264 | + if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) |
| 265 | + return -EFAULT; |
| 266 | + |
| 267 | + ret_val = aq_ndev_config_hwtstamp(aq_nic, &config); |
| 268 | + if (ret_val) |
| 269 | + return ret_val; |
| 270 | + |
| 271 | + return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? |
| 272 | + -EFAULT : 0; |
| 273 | +} |
| 274 | + |
| 275 | +static int aq_ndev_hwtstamp_get(struct aq_nic_s *aq_nic, struct ifreq *ifr) |
| 276 | +{ |
| 277 | + struct hwtstamp_config config; |
| 278 | + |
| 279 | + if (!aq_nic->aq_ptp) |
| 280 | + return -EOPNOTSUPP; |
| 281 | + |
| 282 | + aq_ptp_hwtstamp_config_get(aq_nic->aq_ptp, &config); |
| 283 | + return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? |
| 284 | + -EFAULT : 0; |
| 285 | +} |
| 286 | + |
| 287 | +static int aq_ndev_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 288 | +{ |
| 289 | + struct aq_nic_s *aq_nic = netdev_priv(netdev); |
| 290 | + |
| 291 | + switch (cmd) { |
| 292 | + case SIOCSHWTSTAMP: |
| 293 | + return aq_ndev_hwtstamp_set(aq_nic, ifr); |
| 294 | + |
| 295 | + case SIOCGHWTSTAMP: |
| 296 | + return aq_ndev_hwtstamp_get(aq_nic, ifr); |
| 297 | + } |
| 298 | + |
| 299 | + return -EOPNOTSUPP; |
| 300 | +} |
| 301 | + |
200 | 302 | static int aq_ndo_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, |
201 | 303 | u16 vid) |
202 | 304 | { |
@@ -234,6 +336,7 @@ static const struct net_device_ops aq_ndev_ops = { |
234 | 336 | .ndo_change_mtu = aq_ndev_change_mtu, |
235 | 337 | .ndo_set_mac_address = aq_ndev_set_mac_address, |
236 | 338 | .ndo_set_features = aq_ndev_set_features, |
| 339 | + .ndo_do_ioctl = aq_ndev_ioctl, |
237 | 340 | .ndo_vlan_rx_add_vid = aq_ndo_vlan_rx_add_vid, |
238 | 341 | .ndo_vlan_rx_kill_vid = aq_ndo_vlan_rx_kill_vid, |
239 | 342 | }; |
|
0 commit comments