Commit 6afae645 authored by David S. Miller's avatar David S. Miller

Merge branch 'hwtstamp'

Ben Hutchings says:

====================
net_tstamp: Validate hwtstamp_config completely before applying it

This series fixes very similar bugs in 6 implementations of
SIOCSHWTSTAMP.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents b4e09b29 a5be8cd3
...@@ -13618,16 +13618,9 @@ static int tg3_hwtstamp_ioctl(struct net_device *dev, ...@@ -13618,16 +13618,9 @@ static int tg3_hwtstamp_ioctl(struct net_device *dev,
if (stmpconf.flags) if (stmpconf.flags)
return -EINVAL; return -EINVAL;
switch (stmpconf.tx_type) { if (stmpconf.tx_type != HWTSTAMP_TX_ON &&
case HWTSTAMP_TX_ON: stmpconf.tx_type != HWTSTAMP_TX_OFF)
tg3_flag_set(tp, TX_TSTAMP_EN);
break;
case HWTSTAMP_TX_OFF:
tg3_flag_clear(tp, TX_TSTAMP_EN);
break;
default:
return -ERANGE; return -ERANGE;
}
switch (stmpconf.rx_filter) { switch (stmpconf.rx_filter) {
case HWTSTAMP_FILTER_NONE: case HWTSTAMP_FILTER_NONE:
...@@ -13689,6 +13682,11 @@ static int tg3_hwtstamp_ioctl(struct net_device *dev, ...@@ -13689,6 +13682,11 @@ static int tg3_hwtstamp_ioctl(struct net_device *dev,
tw32(TG3_RX_PTP_CTL, tw32(TG3_RX_PTP_CTL,
tp->rxptpctl | TG3_RX_PTP_CTL_HWTS_INTERLOCK); tp->rxptpctl | TG3_RX_PTP_CTL_HWTS_INTERLOCK);
if (stmpconf.tx_type == HWTSTAMP_TX_ON)
tg3_flag_set(tp, TX_TSTAMP_EN);
else
tg3_flag_clear(tp, TX_TSTAMP_EN);
return copy_to_user(ifr->ifr_data, &stmpconf, sizeof(stmpconf)) ? return copy_to_user(ifr->ifr_data, &stmpconf, sizeof(stmpconf)) ?
-EFAULT : 0; -EFAULT : 0;
} }
......
...@@ -3482,10 +3482,10 @@ s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca) ...@@ -3482,10 +3482,10 @@ s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
* specified. Matching the kind of event packet is not supported, with the * specified. Matching the kind of event packet is not supported, with the
* exception of "all V2 events regardless of level 2 or 4". * exception of "all V2 events regardless of level 2 or 4".
**/ **/
static int e1000e_config_hwtstamp(struct e1000_adapter *adapter) static int e1000e_config_hwtstamp(struct e1000_adapter *adapter,
struct hwtstamp_config *config)
{ {
struct e1000_hw *hw = &adapter->hw; struct e1000_hw *hw = &adapter->hw;
struct hwtstamp_config *config = &adapter->hwtstamp_config;
u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED; u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED; u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
u32 rxmtrl = 0; u32 rxmtrl = 0;
...@@ -3586,6 +3586,8 @@ static int e1000e_config_hwtstamp(struct e1000_adapter *adapter) ...@@ -3586,6 +3586,8 @@ static int e1000e_config_hwtstamp(struct e1000_adapter *adapter)
return -ERANGE; return -ERANGE;
} }
adapter->hwtstamp_config = *config;
/* enable/disable Tx h/w time stamping */ /* enable/disable Tx h/w time stamping */
regval = er32(TSYNCTXCTL); regval = er32(TSYNCTXCTL);
regval &= ~E1000_TSYNCTXCTL_ENABLED; regval &= ~E1000_TSYNCTXCTL_ENABLED;
...@@ -3874,7 +3876,7 @@ void e1000e_reset(struct e1000_adapter *adapter) ...@@ -3874,7 +3876,7 @@ void e1000e_reset(struct e1000_adapter *adapter)
e1000e_reset_adaptive(hw); e1000e_reset_adaptive(hw);
/* initialize systim and reset the ns time counter */ /* initialize systim and reset the ns time counter */
e1000e_config_hwtstamp(adapter); e1000e_config_hwtstamp(adapter, &adapter->hwtstamp_config);
/* Set EEE advertisement as appropriate */ /* Set EEE advertisement as appropriate */
if (adapter->flags2 & FLAG2_HAS_EEE) { if (adapter->flags2 & FLAG2_HAS_EEE) {
...@@ -5797,14 +5799,10 @@ static int e1000e_hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr) ...@@ -5797,14 +5799,10 @@ static int e1000e_hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr)
if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
return -EFAULT; return -EFAULT;
adapter->hwtstamp_config = config; ret_val = e1000e_config_hwtstamp(adapter, &config);
ret_val = e1000e_config_hwtstamp(adapter);
if (ret_val) if (ret_val)
return ret_val; return ret_val;
config = adapter->hwtstamp_config;
switch (config.rx_filter) { switch (config.rx_filter) {
case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
......
...@@ -245,16 +245,8 @@ static int hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) ...@@ -245,16 +245,8 @@ static int hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
/* Get ieee1588's dev information */ /* Get ieee1588's dev information */
pdev = adapter->ptp_pdev; pdev = adapter->ptp_pdev;
switch (cfg.tx_type) { if (cfg.tx_type != HWTSTAMP_TX_OFF && cfg.tx_type != HWTSTAMP_TX_ON)
case HWTSTAMP_TX_OFF:
adapter->hwts_tx_en = 0;
break;
case HWTSTAMP_TX_ON:
adapter->hwts_tx_en = 1;
break;
default:
return -ERANGE; return -ERANGE;
}
switch (cfg.rx_filter) { switch (cfg.rx_filter) {
case HWTSTAMP_FILTER_NONE: case HWTSTAMP_FILTER_NONE:
...@@ -284,6 +276,8 @@ static int hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) ...@@ -284,6 +276,8 @@ static int hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
return -ERANGE; return -ERANGE;
} }
adapter->hwts_tx_en = cfg.tx_type == HWTSTAMP_TX_ON;
/* Clear out any old time stamps. */ /* Clear out any old time stamps. */
pch_ch_event_write(pdev, TX_SNAPSHOT_LOCKED | RX_SNAPSHOT_LOCKED); pch_ch_event_write(pdev, TX_SNAPSHOT_LOCKED | RX_SNAPSHOT_LOCKED);
......
...@@ -435,16 +435,9 @@ static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr) ...@@ -435,16 +435,9 @@ static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
if (config.flags) if (config.flags)
return -EINVAL; return -EINVAL;
switch (config.tx_type) { if (config.tx_type != HWTSTAMP_TX_OFF &&
case HWTSTAMP_TX_OFF: config.tx_type != HWTSTAMP_TX_ON)
priv->hwts_tx_en = 0;
break;
case HWTSTAMP_TX_ON:
priv->hwts_tx_en = 1;
break;
default:
return -ERANGE; return -ERANGE;
}
if (priv->adv_ts) { if (priv->adv_ts) {
switch (config.rx_filter) { switch (config.rx_filter) {
...@@ -576,6 +569,7 @@ static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr) ...@@ -576,6 +569,7 @@ static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
} }
} }
priv->hwts_rx_en = ((config.rx_filter == HWTSTAMP_FILTER_NONE) ? 0 : 1); priv->hwts_rx_en = ((config.rx_filter == HWTSTAMP_FILTER_NONE) ? 0 : 1);
priv->hwts_tx_en = config.tx_type == HWTSTAMP_TX_ON;
if (!priv->hwts_tx_en && !priv->hwts_rx_en) if (!priv->hwts_tx_en && !priv->hwts_rx_en)
priv->hw->ptp->config_hw_tstamping(priv->ioaddr, 0); priv->hw->ptp->config_hw_tstamping(priv->ioaddr, 0);
......
...@@ -1323,6 +1323,10 @@ static int cpsw_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr) ...@@ -1323,6 +1323,10 @@ static int cpsw_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
struct cpts *cpts = priv->cpts; struct cpts *cpts = priv->cpts;
struct hwtstamp_config cfg; struct hwtstamp_config cfg;
if (priv->version != CPSW_VERSION_1 &&
priv->version != CPSW_VERSION_2)
return -EOPNOTSUPP;
if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
return -EFAULT; return -EFAULT;
...@@ -1330,16 +1334,8 @@ static int cpsw_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr) ...@@ -1330,16 +1334,8 @@ static int cpsw_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
if (cfg.flags) if (cfg.flags)
return -EINVAL; return -EINVAL;
switch (cfg.tx_type) { if (cfg.tx_type != HWTSTAMP_TX_OFF && cfg.tx_type != HWTSTAMP_TX_ON)
case HWTSTAMP_TX_OFF:
cpts->tx_enable = 0;
break;
case HWTSTAMP_TX_ON:
cpts->tx_enable = 1;
break;
default:
return -ERANGE; return -ERANGE;
}
switch (cfg.rx_filter) { switch (cfg.rx_filter) {
case HWTSTAMP_FILTER_NONE: case HWTSTAMP_FILTER_NONE:
...@@ -1366,6 +1362,8 @@ static int cpsw_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr) ...@@ -1366,6 +1362,8 @@ static int cpsw_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
return -ERANGE; return -ERANGE;
} }
cpts->tx_enable = cfg.tx_type == HWTSTAMP_TX_ON;
switch (priv->version) { switch (priv->version) {
case CPSW_VERSION_1: case CPSW_VERSION_1:
cpsw_hwtstamp_v1(priv); cpsw_hwtstamp_v1(priv);
...@@ -1374,7 +1372,7 @@ static int cpsw_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr) ...@@ -1374,7 +1372,7 @@ static int cpsw_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
cpsw_hwtstamp_v2(priv); cpsw_hwtstamp_v2(priv);
break; break;
default: default:
return -ENOTSUPP; WARN_ON(1);
} }
return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
......
...@@ -389,16 +389,8 @@ static int hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) ...@@ -389,16 +389,8 @@ static int hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
ch = PORT2CHANNEL(port); ch = PORT2CHANNEL(port);
regs = (struct ixp46x_ts_regs __iomem *) IXP4XX_TIMESYNC_BASE_VIRT; regs = (struct ixp46x_ts_regs __iomem *) IXP4XX_TIMESYNC_BASE_VIRT;
switch (cfg.tx_type) { if (cfg.tx_type != HWTSTAMP_TX_OFF && cfg.tx_type != HWTSTAMP_TX_ON)
case HWTSTAMP_TX_OFF:
port->hwts_tx_en = 0;
break;
case HWTSTAMP_TX_ON:
port->hwts_tx_en = 1;
break;
default:
return -ERANGE; return -ERANGE;
}
switch (cfg.rx_filter) { switch (cfg.rx_filter) {
case HWTSTAMP_FILTER_NONE: case HWTSTAMP_FILTER_NONE:
...@@ -416,6 +408,8 @@ static int hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) ...@@ -416,6 +408,8 @@ static int hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
return -ERANGE; return -ERANGE;
} }
port->hwts_tx_en = cfg.tx_type == HWTSTAMP_TX_ON;
/* Clear out any old time stamps. */ /* Clear out any old time stamps. */
__raw_writel(TX_SNAPSHOT_LOCKED | RX_SNAPSHOT_LOCKED, __raw_writel(TX_SNAPSHOT_LOCKED | RX_SNAPSHOT_LOCKED,
&regs->channel[ch].ch_event); &regs->channel[ch].ch_event);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment