Skip to content

Commit 8562441

Browse files
grygoriySdavem330
authored andcommitted
net: ethernet: ti: cpts: add irq support
Add CPTS IRQ support, but do not enable it. By default, the CPTS driver will continue working using polling mode which is required for CPTS to continue working on platforms other than CPSW, like Keystone 2. The CPTS IRQ support is required to enable support for HW_TS_PUSH events. The CPSW CPTS IRQ and HW_TS_PUSH events support will be enabled in follow up patches. Signed-off-by: Grygorii Strashko <[email protected]> Acked-by: Richard Cochran <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ba10742 commit 8562441

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

drivers/net/ethernet/ti/cpts.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ static void cpts_purge_txq(struct cpts *cpts)
9999
*/
100100
static int cpts_fifo_read(struct cpts *cpts, int match)
101101
{
102+
bool need_schedule = false;
102103
struct cpts_event *event;
103104
unsigned long flags;
104105
int i, type = -1;
@@ -131,6 +132,8 @@ static int cpts_fifo_read(struct cpts *cpts, int match)
131132
cpts->cc.mult = cpts->mult_new;
132133
cpts->mult_new = 0;
133134
}
135+
if (!cpts->irq_poll)
136+
complete(&cpts->ts_push_complete);
134137
break;
135138
case CPTS_EV_TX:
136139
case CPTS_EV_RX:
@@ -139,6 +142,7 @@ static int cpts_fifo_read(struct cpts *cpts, int match)
139142

140143
list_del_init(&event->list);
141144
list_add_tail(&event->list, &cpts->events);
145+
need_schedule = true;
142146
break;
143147
case CPTS_EV_ROLL:
144148
case CPTS_EV_HALF:
@@ -154,9 +158,18 @@ static int cpts_fifo_read(struct cpts *cpts, int match)
154158

155159
spin_unlock_irqrestore(&cpts->lock, flags);
156160

161+
if (!cpts->irq_poll && need_schedule)
162+
ptp_schedule_worker(cpts->clock, 0);
163+
157164
return type == match ? 0 : -1;
158165
}
159166

167+
void cpts_misc_interrupt(struct cpts *cpts)
168+
{
169+
cpts_fifo_read(cpts, -1);
170+
}
171+
EXPORT_SYMBOL_GPL(cpts_misc_interrupt);
172+
160173
static u64 cpts_systim_read(const struct cyclecounter *cc)
161174
{
162175
struct cpts *cpts = container_of(cc, struct cpts, cc);
@@ -169,6 +182,8 @@ static void cpts_update_cur_time(struct cpts *cpts, int match,
169182
{
170183
unsigned long flags;
171184

185+
reinit_completion(&cpts->ts_push_complete);
186+
172187
/* use spin_lock_irqsave() here as it has to run very fast */
173188
spin_lock_irqsave(&cpts->lock, flags);
174189
ptp_read_system_prets(sts);
@@ -177,8 +192,12 @@ static void cpts_update_cur_time(struct cpts *cpts, int match,
177192
ptp_read_system_postts(sts);
178193
spin_unlock_irqrestore(&cpts->lock, flags);
179194

180-
if (cpts_fifo_read(cpts, match) && match != -1)
195+
if (cpts->irq_poll && cpts_fifo_read(cpts, match) && match != -1)
181196
dev_err(cpts->dev, "cpts: unable to obtain a time stamp\n");
197+
198+
if (!cpts->irq_poll &&
199+
!wait_for_completion_timeout(&cpts->ts_push_complete, HZ))
200+
dev_err(cpts->dev, "cpts: obtain a time stamp timeout\n");
182201
}
183202

184203
/* PTP clock operations */
@@ -708,8 +727,10 @@ struct cpts *cpts_create(struct device *dev, void __iomem *regs,
708727

709728
cpts->dev = dev;
710729
cpts->reg = (struct cpsw_cpts __iomem *)regs;
730+
cpts->irq_poll = true;
711731
spin_lock_init(&cpts->lock);
712732
mutex_init(&cpts->ptp_clk_mutex);
733+
init_completion(&cpts->ts_push_complete);
713734

714735
ret = cpts_of_parse(cpts, node);
715736
if (ret)

drivers/net/ethernet/ti/cpts.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ struct cpts {
118118
u64 cur_timestamp;
119119
u32 mult_new;
120120
struct mutex ptp_clk_mutex; /* sync PTP interface and worker */
121+
bool irq_poll;
122+
struct completion ts_push_complete;
121123
};
122124

123125
void cpts_rx_timestamp(struct cpts *cpts, struct sk_buff *skb);
@@ -127,6 +129,7 @@ void cpts_unregister(struct cpts *cpts);
127129
struct cpts *cpts_create(struct device *dev, void __iomem *regs,
128130
struct device_node *node);
129131
void cpts_release(struct cpts *cpts);
132+
void cpts_misc_interrupt(struct cpts *cpts);
130133

131134
static inline bool cpts_can_timestamp(struct cpts *cpts, struct sk_buff *skb)
132135
{
@@ -138,6 +141,11 @@ static inline bool cpts_can_timestamp(struct cpts *cpts, struct sk_buff *skb)
138141
return true;
139142
}
140143

144+
static inline void cpts_set_irqpoll(struct cpts *cpts, bool en)
145+
{
146+
cpts->irq_poll = en;
147+
}
148+
141149
#else
142150
struct cpts;
143151

@@ -173,6 +181,14 @@ static inline bool cpts_can_timestamp(struct cpts *cpts, struct sk_buff *skb)
173181
{
174182
return false;
175183
}
184+
185+
static inline void cpts_misc_interrupt(struct cpts *cpts)
186+
{
187+
}
188+
189+
static inline void cpts_set_irqpoll(struct cpts *cpts, bool en)
190+
{
191+
}
176192
#endif
177193

178194

0 commit comments

Comments
 (0)