Skip to content

Commit 446e230

Browse files
kmaincentdavem330
authored andcommitted
net: Convert PHYs hwtstamp callback to use kernel_hwtstamp_config
The PHYs hwtstamp callback are still getting the timestamp config from ifreq and using copy_from/to_user. Get rid of these functions by using timestamp configuration in parameter. This also allow to move on to kernel_hwtstamp_config and be similar to net devices using the new ndo_hwstamp_get/set. This adds the possibility to manipulate the timestamp configuration from the kernel which was not possible with the copy_from/to_user. Signed-off-by: Kory Maincent <kory.maincent@bootlin.com> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 18de1e5 commit 446e230

File tree

9 files changed

+82
-77
lines changed

9 files changed

+82
-77
lines changed

drivers/net/phy/bcm-phy-ptp.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -782,16 +782,13 @@ static void bcm_ptp_txtstamp(struct mii_timestamper *mii_ts,
782782
}
783783

784784
static int bcm_ptp_hwtstamp(struct mii_timestamper *mii_ts,
785-
struct ifreq *ifr)
785+
struct kernel_hwtstamp_config *cfg,
786+
struct netlink_ext_ack *extack)
786787
{
787788
struct bcm_ptp_private *priv = mii2priv(mii_ts);
788-
struct hwtstamp_config cfg;
789789
u16 mode, ctrl;
790790

791-
if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
792-
return -EFAULT;
793-
794-
switch (cfg.rx_filter) {
791+
switch (cfg->rx_filter) {
795792
case HWTSTAMP_FILTER_NONE:
796793
priv->hwts_rx = false;
797794
break;
@@ -804,14 +801,14 @@ static int bcm_ptp_hwtstamp(struct mii_timestamper *mii_ts,
804801
case HWTSTAMP_FILTER_PTP_V2_EVENT:
805802
case HWTSTAMP_FILTER_PTP_V2_SYNC:
806803
case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
807-
cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
804+
cfg->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
808805
priv->hwts_rx = true;
809806
break;
810807
default:
811808
return -ERANGE;
812809
}
813810

814-
priv->tx_type = cfg.tx_type;
811+
priv->tx_type = cfg->tx_type;
815812

816813
ctrl = priv->hwts_rx ? SLICE_RX_EN : 0;
817814
ctrl |= priv->tx_type != HWTSTAMP_TX_OFF ? SLICE_TX_EN : 0;
@@ -840,7 +837,7 @@ static int bcm_ptp_hwtstamp(struct mii_timestamper *mii_ts,
840837
/* purge existing data */
841838
skb_queue_purge(&priv->tx_queue);
842839

843-
return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
840+
return 0;
844841
}
845842

846843
static int bcm_ptp_ts_info(struct mii_timestamper *mii_ts,

drivers/net/phy/dp83640.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,22 +1207,20 @@ static irqreturn_t dp83640_handle_interrupt(struct phy_device *phydev)
12071207
return IRQ_HANDLED;
12081208
}
12091209

1210-
static int dp83640_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr)
1210+
static int dp83640_hwtstamp(struct mii_timestamper *mii_ts,
1211+
struct kernel_hwtstamp_config *cfg,
1212+
struct netlink_ext_ack *extack)
12111213
{
12121214
struct dp83640_private *dp83640 =
12131215
container_of(mii_ts, struct dp83640_private, mii_ts);
1214-
struct hwtstamp_config cfg;
12151216
u16 txcfg0, rxcfg0;
12161217

1217-
if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
1218-
return -EFAULT;
1219-
1220-
if (cfg.tx_type < 0 || cfg.tx_type > HWTSTAMP_TX_ONESTEP_SYNC)
1218+
if (cfg->tx_type < 0 || cfg->tx_type > HWTSTAMP_TX_ONESTEP_SYNC)
12211219
return -ERANGE;
12221220

1223-
dp83640->hwts_tx_en = cfg.tx_type;
1221+
dp83640->hwts_tx_en = cfg->tx_type;
12241222

1225-
switch (cfg.rx_filter) {
1223+
switch (cfg->rx_filter) {
12261224
case HWTSTAMP_FILTER_NONE:
12271225
dp83640->hwts_rx_en = 0;
12281226
dp83640->layer = 0;
@@ -1234,31 +1232,31 @@ static int dp83640_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr)
12341232
dp83640->hwts_rx_en = 1;
12351233
dp83640->layer = PTP_CLASS_L4;
12361234
dp83640->version = PTP_CLASS_V1;
1237-
cfg.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
1235+
cfg->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
12381236
break;
12391237
case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
12401238
case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
12411239
case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
12421240
dp83640->hwts_rx_en = 1;
12431241
dp83640->layer = PTP_CLASS_L4;
12441242
dp83640->version = PTP_CLASS_V2;
1245-
cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
1243+
cfg->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
12461244
break;
12471245
case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
12481246
case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
12491247
case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
12501248
dp83640->hwts_rx_en = 1;
12511249
dp83640->layer = PTP_CLASS_L2;
12521250
dp83640->version = PTP_CLASS_V2;
1253-
cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
1251+
cfg->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
12541252
break;
12551253
case HWTSTAMP_FILTER_PTP_V2_EVENT:
12561254
case HWTSTAMP_FILTER_PTP_V2_SYNC:
12571255
case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
12581256
dp83640->hwts_rx_en = 1;
12591257
dp83640->layer = PTP_CLASS_L4 | PTP_CLASS_L2;
12601258
dp83640->version = PTP_CLASS_V2;
1261-
cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
1259+
cfg->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
12621260
break;
12631261
default:
12641262
return -ERANGE;
@@ -1292,7 +1290,7 @@ static int dp83640_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr)
12921290

12931291
mutex_unlock(&dp83640->clock->extreg_lock);
12941292

1295-
return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
1293+
return 0;
12961294
}
12971295

12981296
static void rx_timestamp_work(struct work_struct *work)

drivers/net/phy/micrel.c

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,24 +2395,22 @@ static void lan8814_flush_fifo(struct phy_device *phydev, bool egress)
23952395
lanphy_read_page_reg(phydev, 5, PTP_TSU_INT_STS);
23962396
}
23972397

2398-
static int lan8814_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr)
2398+
static int lan8814_hwtstamp(struct mii_timestamper *mii_ts,
2399+
struct kernel_hwtstamp_config *config,
2400+
struct netlink_ext_ack *extack)
23992401
{
24002402
struct kszphy_ptp_priv *ptp_priv =
24012403
container_of(mii_ts, struct kszphy_ptp_priv, mii_ts);
24022404
struct phy_device *phydev = ptp_priv->phydev;
24032405
struct lan8814_shared_priv *shared = phydev->shared->priv;
24042406
struct lan8814_ptp_rx_ts *rx_ts, *tmp;
2405-
struct hwtstamp_config config;
24062407
int txcfg = 0, rxcfg = 0;
24072408
int pkt_ts_enable;
24082409

2409-
if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
2410-
return -EFAULT;
2410+
ptp_priv->hwts_tx_type = config->tx_type;
2411+
ptp_priv->rx_filter = config->rx_filter;
24112412

2412-
ptp_priv->hwts_tx_type = config.tx_type;
2413-
ptp_priv->rx_filter = config.rx_filter;
2414-
2415-
switch (config.rx_filter) {
2413+
switch (config->rx_filter) {
24162414
case HWTSTAMP_FILTER_NONE:
24172415
ptp_priv->layer = 0;
24182416
ptp_priv->version = 0;
@@ -2458,13 +2456,13 @@ static int lan8814_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr)
24582456
lanphy_write_page_reg(ptp_priv->phydev, 5, PTP_TX_MOD,
24592457
PTP_TX_MOD_TX_PTP_SYNC_TS_INSERT_);
24602458

2461-
if (config.rx_filter != HWTSTAMP_FILTER_NONE)
2459+
if (config->rx_filter != HWTSTAMP_FILTER_NONE)
24622460
lan8814_config_ts_intr(ptp_priv->phydev, true);
24632461
else
24642462
lan8814_config_ts_intr(ptp_priv->phydev, false);
24652463

24662464
mutex_lock(&shared->shared_lock);
2467-
if (config.rx_filter != HWTSTAMP_FILTER_NONE)
2465+
if (config->rx_filter != HWTSTAMP_FILTER_NONE)
24682466
shared->ref++;
24692467
else
24702468
shared->ref--;
@@ -2488,7 +2486,7 @@ static int lan8814_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr)
24882486
lan8814_flush_fifo(ptp_priv->phydev, false);
24892487
lan8814_flush_fifo(ptp_priv->phydev, true);
24902488

2491-
return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? -EFAULT : 0;
2489+
return 0;
24922490
}
24932491

24942492
static void lan8814_txtstamp(struct mii_timestamper *mii_ts,
@@ -3703,21 +3701,19 @@ static void lan8841_ptp_enable_processing(struct kszphy_ptp_priv *ptp_priv,
37033701
#define LAN8841_PTP_TX_TIMESTAMP_EN 443
37043702
#define LAN8841_PTP_TX_MOD 445
37053703

3706-
static int lan8841_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr)
3704+
static int lan8841_hwtstamp(struct mii_timestamper *mii_ts,
3705+
struct kernel_hwtstamp_config *config,
3706+
struct netlink_ext_ack *extack)
37073707
{
37083708
struct kszphy_ptp_priv *ptp_priv = container_of(mii_ts, struct kszphy_ptp_priv, mii_ts);
37093709
struct phy_device *phydev = ptp_priv->phydev;
3710-
struct hwtstamp_config config;
37113710
int txcfg = 0, rxcfg = 0;
37123711
int pkt_ts_enable;
37133712

3714-
if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
3715-
return -EFAULT;
3713+
ptp_priv->hwts_tx_type = config->tx_type;
3714+
ptp_priv->rx_filter = config->rx_filter;
37163715

3717-
ptp_priv->hwts_tx_type = config.tx_type;
3718-
ptp_priv->rx_filter = config.rx_filter;
3719-
3720-
switch (config.rx_filter) {
3716+
switch (config->rx_filter) {
37213717
case HWTSTAMP_FILTER_NONE:
37223718
ptp_priv->layer = 0;
37233719
ptp_priv->version = 0;
@@ -3771,13 +3767,13 @@ static int lan8841_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr)
37713767

37723768
/* Now enable/disable the timestamping */
37733769
lan8841_ptp_enable_processing(ptp_priv,
3774-
config.rx_filter != HWTSTAMP_FILTER_NONE);
3770+
config->rx_filter != HWTSTAMP_FILTER_NONE);
37753771

37763772
skb_queue_purge(&ptp_priv->tx_queue);
37773773

37783774
lan8841_ptp_flush_fifo(ptp_priv);
37793775

3780-
return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? -EFAULT : 0;
3776+
return 0;
37813777
}
37823778

37833779
static bool lan8841_rxtstamp(struct mii_timestamper *mii_ts,

drivers/net/phy/mscc/mscc_ptp.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,19 +1045,17 @@ static void vsc85xx_ts_reset_fifo(struct phy_device *phydev)
10451045
val);
10461046
}
10471047

1048-
static int vsc85xx_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr)
1048+
static int vsc85xx_hwtstamp(struct mii_timestamper *mii_ts,
1049+
struct kernel_hwtstamp_config *cfg,
1050+
struct netlink_ext_ack *extack)
10491051
{
10501052
struct vsc8531_private *vsc8531 =
10511053
container_of(mii_ts, struct vsc8531_private, mii_ts);
10521054
struct phy_device *phydev = vsc8531->ptp->phydev;
1053-
struct hwtstamp_config cfg;
10541055
bool one_step = false;
10551056
u32 val;
10561057

1057-
if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
1058-
return -EFAULT;
1059-
1060-
switch (cfg.tx_type) {
1058+
switch (cfg->tx_type) {
10611059
case HWTSTAMP_TX_ONESTEP_SYNC:
10621060
one_step = true;
10631061
break;
@@ -1069,9 +1067,9 @@ static int vsc85xx_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr)
10691067
return -ERANGE;
10701068
}
10711069

1072-
vsc8531->ptp->tx_type = cfg.tx_type;
1070+
vsc8531->ptp->tx_type = cfg->tx_type;
10731071

1074-
switch (cfg.rx_filter) {
1072+
switch (cfg->rx_filter) {
10751073
case HWTSTAMP_FILTER_NONE:
10761074
break;
10771075
case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
@@ -1084,7 +1082,7 @@ static int vsc85xx_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr)
10841082
return -ERANGE;
10851083
}
10861084

1087-
vsc8531->ptp->rx_filter = cfg.rx_filter;
1085+
vsc8531->ptp->rx_filter = cfg->rx_filter;
10881086

10891087
mutex_lock(&vsc8531->ts_lock);
10901088

@@ -1132,7 +1130,7 @@ static int vsc85xx_hwtstamp(struct mii_timestamper *mii_ts, struct ifreq *ifr)
11321130
vsc8531->ptp->configured = 1;
11331131
mutex_unlock(&vsc8531->ts_lock);
11341132

1135-
return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
1133+
return 0;
11361134
}
11371135

11381136
static int vsc85xx_ts_info(struct mii_timestamper *mii_ts,

drivers/net/phy/nxp-c45-tja11xx.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,32 +1022,29 @@ static bool nxp_c45_rxtstamp(struct mii_timestamper *mii_ts,
10221022
}
10231023

10241024
static int nxp_c45_hwtstamp(struct mii_timestamper *mii_ts,
1025-
struct ifreq *ifreq)
1025+
struct kernel_hwtstamp_config *cfg,
1026+
struct netlink_ext_ack *extack)
10261027
{
10271028
struct nxp_c45_phy *priv = container_of(mii_ts, struct nxp_c45_phy,
10281029
mii_ts);
10291030
struct phy_device *phydev = priv->phydev;
10301031
const struct nxp_c45_phy_data *data;
1031-
struct hwtstamp_config cfg;
10321032

1033-
if (copy_from_user(&cfg, ifreq->ifr_data, sizeof(cfg)))
1034-
return -EFAULT;
1035-
1036-
if (cfg.tx_type < 0 || cfg.tx_type > HWTSTAMP_TX_ON)
1033+
if (cfg->tx_type < 0 || cfg->tx_type > HWTSTAMP_TX_ON)
10371034
return -ERANGE;
10381035

10391036
data = nxp_c45_get_data(phydev);
1040-
priv->hwts_tx = cfg.tx_type;
1037+
priv->hwts_tx = cfg->tx_type;
10411038

1042-
switch (cfg.rx_filter) {
1039+
switch (cfg->rx_filter) {
10431040
case HWTSTAMP_FILTER_NONE:
10441041
priv->hwts_rx = 0;
10451042
break;
10461043
case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
10471044
case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
10481045
case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
10491046
priv->hwts_rx = 1;
1050-
cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
1047+
cfg->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
10511048
break;
10521049
default:
10531050
return -ERANGE;
@@ -1074,7 +1071,7 @@ static int nxp_c45_hwtstamp(struct mii_timestamper *mii_ts,
10741071
nxp_c45_clear_reg_field(phydev, &data->regmap->irq_egr_ts_en);
10751072

10761073
nxp_c45_no_ptp_irq:
1077-
return copy_to_user(ifreq->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
1074+
return 0;
10781075
}
10791076

10801077
static int nxp_c45_ts_info(struct mii_timestamper *mii_ts,

drivers/net/phy/phy.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,13 @@ EXPORT_SYMBOL(phy_ethtool_ksettings_get);
325325
int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
326326
{
327327
struct mii_ioctl_data *mii_data = if_mii(ifr);
328+
struct kernel_hwtstamp_config kernel_cfg;
329+
struct netlink_ext_ack extack = {};
328330
u16 val = mii_data->val_in;
329331
bool change_autoneg = false;
332+
struct hwtstamp_config cfg;
330333
int prtad, devad;
334+
int ret;
331335

332336
switch (cmd) {
333337
case SIOCGMIIPHY:
@@ -411,8 +415,21 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
411415
return 0;
412416

413417
case SIOCSHWTSTAMP:
414-
if (phydev->mii_ts && phydev->mii_ts->hwtstamp)
415-
return phydev->mii_ts->hwtstamp(phydev->mii_ts, ifr);
418+
if (phydev->mii_ts && phydev->mii_ts->hwtstamp) {
419+
if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
420+
return -EFAULT;
421+
422+
hwtstamp_config_to_kernel(&kernel_cfg, &cfg);
423+
ret = phydev->mii_ts->hwtstamp(phydev->mii_ts, &kernel_cfg, &extack);
424+
if (ret)
425+
return ret;
426+
427+
hwtstamp_config_from_kernel(&cfg, &kernel_cfg);
428+
if (copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)))
429+
return -EFAULT;
430+
431+
return 0;
432+
}
416433
fallthrough;
417434

418435
default:

0 commit comments

Comments
 (0)