Skip to content

Commit

Permalink
net: dsa: mv88e6xxx: introduce helpers for handling chip->reg_lock
Browse files Browse the repository at this point in the history
This is a no-op that simply moves all locking and unlocking of
->reg_lock into trivial helpers. I did that to be able to easily add
some ad hoc instrumentation to those helpers to get some information
on contention and hold times of the mutex. Perhaps others want to do
something similar at some point, so this frees them from doing the
'sed -i' yoga, and have a much smaller 'git diff' while fiddling.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Vivien Didelot <vivien.didelot@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Rasmus Villemoes authored and David S. Miller committed Jun 23, 2019
1 parent 3e5bfb1 commit c9acece
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 148 deletions.
176 changes: 88 additions & 88 deletions drivers/net/dsa/mv88e6xxx/chip.c

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions drivers/net/dsa/mv88e6xxx/chip.h
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,14 @@ int mv88e6xxx_port_setup_mac(struct mv88e6xxx_chip *chip, int port, int link,
phy_interface_t mode);
struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip);

static inline void mv88e6xxx_reg_lock(struct mv88e6xxx_chip *chip)
{
mutex_lock(&chip->reg_lock);
}

static inline void mv88e6xxx_reg_unlock(struct mv88e6xxx_chip *chip)
{
mutex_unlock(&chip->reg_lock);
}

#endif /* _MV88E6XXX_CHIP_H */
6 changes: 3 additions & 3 deletions drivers/net/dsa/mv88e6xxx/global1_atu.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ static irqreturn_t mv88e6xxx_g1_atu_prob_irq_thread_fn(int irq, void *dev_id)
int err;
u16 val;

mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);

err = mv88e6xxx_g1_atu_op(chip, 0,
MV88E6XXX_G1_ATU_OP_GET_CLR_VIOLATION);
Expand Down Expand Up @@ -364,12 +364,12 @@ static irqreturn_t mv88e6xxx_g1_atu_prob_irq_thread_fn(int irq, void *dev_id)
entry.mac, entry.portvec, spid);
chip->ports[spid].atu_full_violation++;
}
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);

return IRQ_HANDLED;

out:
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);

dev_err(chip->dev, "ATU problem: error %d while handling interrupt\n",
err);
Expand Down
6 changes: 3 additions & 3 deletions drivers/net/dsa/mv88e6xxx/global1_vtu.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ static irqreturn_t mv88e6xxx_g1_vtu_prob_irq_thread_fn(int irq, void *dev_id)
int err;
u16 val;

mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);

err = mv88e6xxx_g1_vtu_op(chip, MV88E6XXX_G1_VTU_OP_GET_CLR_VIOLATION);
if (err)
Expand Down Expand Up @@ -607,12 +607,12 @@ static irqreturn_t mv88e6xxx_g1_vtu_prob_irq_thread_fn(int irq, void *dev_id)
chip->ports[spid].vtu_miss_violation++;
}

mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);

return IRQ_HANDLED;

out:
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);

dev_err(chip->dev, "VTU problem: error %d while handling interrupt\n",
err);
Expand Down
20 changes: 10 additions & 10 deletions drivers/net/dsa/mv88e6xxx/global2.c
Original file line number Diff line number Diff line change
Expand Up @@ -893,20 +893,20 @@ static irqreturn_t mv88e6xxx_g2_watchdog_thread_fn(int irq, void *dev_id)
struct mv88e6xxx_chip *chip = dev_id;
irqreturn_t ret = IRQ_NONE;

mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);
if (chip->info->ops->watchdog_ops->irq_action)
ret = chip->info->ops->watchdog_ops->irq_action(chip, irq);
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);

return ret;
}

static void mv88e6xxx_g2_watchdog_free(struct mv88e6xxx_chip *chip)
{
mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);
if (chip->info->ops->watchdog_ops->irq_free)
chip->info->ops->watchdog_ops->irq_free(chip);
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);

free_irq(chip->watchdog_irq, chip);
irq_dispose_mapping(chip->watchdog_irq);
Expand All @@ -928,10 +928,10 @@ static int mv88e6xxx_g2_watchdog_setup(struct mv88e6xxx_chip *chip)
if (err)
return err;

mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);
if (chip->info->ops->watchdog_ops->irq_setup)
err = chip->info->ops->watchdog_ops->irq_setup(chip);
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);

return err;
}
Expand Down Expand Up @@ -986,9 +986,9 @@ static irqreturn_t mv88e6xxx_g2_irq_thread_fn(int irq, void *dev_id)
int err;
u16 reg;

mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);
err = mv88e6xxx_g2_int_source(chip, &reg);
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);
if (err)
goto out;

Expand All @@ -1007,7 +1007,7 @@ static void mv88e6xxx_g2_irq_bus_lock(struct irq_data *d)
{
struct mv88e6xxx_chip *chip = irq_data_get_irq_chip_data(d);

mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);
}

static void mv88e6xxx_g2_irq_bus_sync_unlock(struct irq_data *d)
Expand All @@ -1019,7 +1019,7 @@ static void mv88e6xxx_g2_irq_bus_sync_unlock(struct irq_data *d)
if (err)
dev_err(chip->dev, "failed to mask interrupts\n");

mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);
}

static const struct irq_chip mv88e6xxx_g2_irq_chip = {
Expand Down
28 changes: 14 additions & 14 deletions drivers/net/dsa/mv88e6xxx/hwtstamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static int mv88e6xxx_set_hwtstamp_config(struct mv88e6xxx_chip *chip, int port,
return -ERANGE;
}

mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);
if (tstamp_enable) {
chip->enable_count += 1;
if (chip->enable_count == 1 && ptp_ops->global_enable)
Expand All @@ -161,7 +161,7 @@ static int mv88e6xxx_set_hwtstamp_config(struct mv88e6xxx_chip *chip, int port,
if (chip->enable_count == 0 && ptp_ops->global_disable)
ptp_ops->global_disable(chip);
}
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);

/* Once hardware has been configured, enable timestamp checks
* in the RX/TX paths.
Expand Down Expand Up @@ -301,10 +301,10 @@ static void mv88e6xxx_get_rxts(struct mv88e6xxx_chip *chip,
skb_queue_splice_tail_init(rxq, &received);
spin_unlock_irqrestore(&rxq->lock, flags);

mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);
err = mv88e6xxx_port_ptp_read(chip, ps->port_id,
reg, buf, ARRAY_SIZE(buf));
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);
if (err)
pr_err("failed to get the receive time stamp\n");

Expand All @@ -314,9 +314,9 @@ static void mv88e6xxx_get_rxts(struct mv88e6xxx_chip *chip,
seq_id = buf[3];

if (status & MV88E6XXX_PTP_TS_VALID) {
mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);
err = mv88e6xxx_port_ptp_write(chip, ps->port_id, reg, 0);
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);
if (err)
pr_err("failed to clear the receive status\n");
}
Expand All @@ -327,9 +327,9 @@ static void mv88e6xxx_get_rxts(struct mv88e6xxx_chip *chip,
if (mv88e6xxx_ts_valid(status) && seq_match(skb, seq_id)) {
ns = timehi << 16 | timelo;

mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);
ns = timecounter_cyc2time(&chip->tstamp_tc, ns);
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);
shwt = skb_hwtstamps(skb);
memset(shwt, 0, sizeof(*shwt));
shwt->hwtstamp = ns_to_ktime(ns);
Expand Down Expand Up @@ -405,12 +405,12 @@ static int mv88e6xxx_txtstamp_work(struct mv88e6xxx_chip *chip,
if (!ps->tx_skb)
return 0;

mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);
err = mv88e6xxx_port_ptp_read(chip, ps->port_id,
ptp_ops->dep_sts_reg,
departure_block,
ARRAY_SIZE(departure_block));
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);

if (err)
goto free_and_clear_skb;
Expand All @@ -430,9 +430,9 @@ static int mv88e6xxx_txtstamp_work(struct mv88e6xxx_chip *chip,
}

/* We have the timestamp; go ahead and clear valid now */
mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);
mv88e6xxx_port_ptp_write(chip, ps->port_id, ptp_ops->dep_sts_reg, 0);
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);

status = departure_block[0] & MV88E6XXX_PTP_TS_STATUS_MASK;
if (status != MV88E6XXX_PTP_TS_STATUS_NORMAL) {
Expand All @@ -447,9 +447,9 @@ static int mv88e6xxx_txtstamp_work(struct mv88e6xxx_chip *chip,

memset(&shhwtstamps, 0, sizeof(shhwtstamps));
time_raw = ((u32)departure_block[2] << 16) | departure_block[1];
mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);
ns = timecounter_cyc2time(&chip->tstamp_tc, time_raw);
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);
shhwtstamps.hwtstamp = ns_to_ktime(ns);

dev_dbg(chip->dev,
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/dsa/mv88e6xxx/phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ static void mv88e6xxx_phy_ppu_reenable_work(struct work_struct *ugly)

chip = container_of(ugly, struct mv88e6xxx_chip, ppu_work);

mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);

if (mutex_trylock(&chip->ppu_mutex)) {
if (mv88e6xxx_phy_ppu_enable(chip) == 0)
chip->ppu_disabled = 0;
mutex_unlock(&chip->ppu_mutex);
}

mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);
}

static void mv88e6xxx_phy_ppu_reenable_timer(struct timer_list *t)
Expand Down
32 changes: 16 additions & 16 deletions drivers/net/dsa/mv88e6xxx/ptp.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ static void mv88e6352_tai_event_work(struct work_struct *ugly)
u32 raw_ts;
int err;

mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);
err = mv88e6xxx_tai_read(chip, MV88E6XXX_TAI_EVENT_STATUS,
status, ARRAY_SIZE(status));
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);

if (err) {
dev_err(chip->dev, "failed to read TAI status register\n");
Expand All @@ -158,18 +158,18 @@ static void mv88e6352_tai_event_work(struct work_struct *ugly)

/* Clear the valid bit so the next timestamp can come in */
status[0] &= ~MV88E6XXX_TAI_EVENT_STATUS_VALID;
mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);
err = mv88e6xxx_tai_write(chip, MV88E6XXX_TAI_EVENT_STATUS, status[0]);
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);

/* This is an external timestamp */
ev.type = PTP_CLOCK_EXTTS;

/* We only have one timestamping channel. */
ev.index = 0;
mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);
ev.timestamp = timecounter_cyc2time(&chip->tstamp_tc, raw_ts);
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);

ptp_clock_event(chip->ptp_clock, &ev);
out:
Expand All @@ -192,12 +192,12 @@ static int mv88e6xxx_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
adj *= scaled_ppm;
diff = div_u64(adj, CC_MULT_DEM);

mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);

timecounter_read(&chip->tstamp_tc);
chip->tstamp_cc.mult = neg_adj ? mult - diff : mult + diff;

mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);

return 0;
}
Expand All @@ -206,9 +206,9 @@ static int mv88e6xxx_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
{
struct mv88e6xxx_chip *chip = ptp_to_chip(ptp);

mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);
timecounter_adjtime(&chip->tstamp_tc, delta);
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);

return 0;
}
Expand All @@ -219,9 +219,9 @@ static int mv88e6xxx_ptp_gettime(struct ptp_clock_info *ptp,
struct mv88e6xxx_chip *chip = ptp_to_chip(ptp);
u64 ns;

mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);
ns = timecounter_read(&chip->tstamp_tc);
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);

*ts = ns_to_timespec64(ns);

Expand All @@ -236,9 +236,9 @@ static int mv88e6xxx_ptp_settime(struct ptp_clock_info *ptp,

ns = timespec64_to_ns(ts);

mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);
timecounter_init(&chip->tstamp_tc, &chip->tstamp_cc, ns);
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);

return 0;
}
Expand All @@ -256,7 +256,7 @@ static int mv88e6352_ptp_enable_extts(struct mv88e6xxx_chip *chip,
if (pin < 0)
return -EBUSY;

mutex_lock(&chip->reg_lock);
mv88e6xxx_reg_lock(chip);

if (on) {
func = MV88E6352_G2_SCRATCH_GPIO_PCTL_EVREQ;
Expand All @@ -278,7 +278,7 @@ static int mv88e6352_ptp_enable_extts(struct mv88e6xxx_chip *chip,
}

out:
mutex_unlock(&chip->reg_lock);
mv88e6xxx_reg_unlock(chip);

return err;
}
Expand Down
Loading

0 comments on commit c9acece

Please sign in to comment.