246
255
static struct port *npe_port_tab[MAX_NPES];
247
256
static struct dma_pool *dma_pool;
258
static struct sock_filter ptp_filter[] = {
262
static int ixp_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
264
u8 *data = skb->data;
269
if (sk_run_filter(skb, ptp_filter) != PTP_CLASS_V1_IPV4)
272
offset = ETH_HLEN + IPV4_HLEN(data) + UDP_HLEN;
274
if (skb->len < offset + OFF_PTP_SEQUENCE_ID + sizeof(seqid))
277
hi = (u16 *)(data + offset + OFF_PTP_SOURCE_UUID);
278
id = (u16 *)(data + offset + OFF_PTP_SEQUENCE_ID);
280
memcpy(&lo, &hi[1], sizeof(lo));
282
return (uid_hi == ntohs(*hi) &&
283
uid_lo == ntohl(lo) &&
284
seqid == ntohs(*id));
287
static void ixp_rx_timestamp(struct port *port, struct sk_buff *skb)
289
struct skb_shared_hwtstamps *shhwtstamps;
290
struct ixp46x_ts_regs *regs;
295
if (!port->hwts_rx_en)
298
ch = PORT2CHANNEL(port);
300
regs = (struct ixp46x_ts_regs __iomem *) IXP4XX_TIMESYNC_BASE_VIRT;
302
val = __raw_readl(®s->channel[ch].ch_event);
304
if (!(val & RX_SNAPSHOT_LOCKED))
307
lo = __raw_readl(®s->channel[ch].src_uuid_lo);
308
hi = __raw_readl(®s->channel[ch].src_uuid_hi);
311
seq = (hi >> 16) & 0xffff;
313
if (!ixp_ptp_match(skb, htons(uid), htonl(lo), htons(seq)))
316
lo = __raw_readl(®s->channel[ch].rx_snap_lo);
317
hi = __raw_readl(®s->channel[ch].rx_snap_hi);
318
ns = ((u64) hi) << 32;
320
ns <<= TICKS_NS_SHIFT;
322
shhwtstamps = skb_hwtstamps(skb);
323
memset(shhwtstamps, 0, sizeof(*shhwtstamps));
324
shhwtstamps->hwtstamp = ns_to_ktime(ns);
326
__raw_writel(RX_SNAPSHOT_LOCKED, ®s->channel[ch].ch_event);
329
static void ixp_tx_timestamp(struct port *port, struct sk_buff *skb)
331
struct skb_shared_hwtstamps shhwtstamps;
332
struct ixp46x_ts_regs *regs;
333
struct skb_shared_info *shtx;
335
u32 ch, cnt, hi, lo, val;
337
shtx = skb_shinfo(skb);
338
if (unlikely(shtx->tx_flags & SKBTX_HW_TSTAMP && port->hwts_tx_en))
339
shtx->tx_flags |= SKBTX_IN_PROGRESS;
343
ch = PORT2CHANNEL(port);
345
regs = (struct ixp46x_ts_regs __iomem *) IXP4XX_TIMESYNC_BASE_VIRT;
348
* This really stinks, but we have to poll for the Tx time stamp.
349
* Usually, the time stamp is ready after 4 to 6 microseconds.
351
for (cnt = 0; cnt < 100; cnt++) {
352
val = __raw_readl(®s->channel[ch].ch_event);
353
if (val & TX_SNAPSHOT_LOCKED)
357
if (!(val & TX_SNAPSHOT_LOCKED)) {
358
shtx->tx_flags &= ~SKBTX_IN_PROGRESS;
362
lo = __raw_readl(®s->channel[ch].tx_snap_lo);
363
hi = __raw_readl(®s->channel[ch].tx_snap_hi);
364
ns = ((u64) hi) << 32;
366
ns <<= TICKS_NS_SHIFT;
368
memset(&shhwtstamps, 0, sizeof(shhwtstamps));
369
shhwtstamps.hwtstamp = ns_to_ktime(ns);
370
skb_tstamp_tx(skb, &shhwtstamps);
372
__raw_writel(TX_SNAPSHOT_LOCKED, ®s->channel[ch].ch_event);
375
static int hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
377
struct hwtstamp_config cfg;
378
struct ixp46x_ts_regs *regs;
379
struct port *port = netdev_priv(netdev);
382
if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
385
if (cfg.flags) /* reserved for future extensions */
388
ch = PORT2CHANNEL(port);
389
regs = (struct ixp46x_ts_regs __iomem *) IXP4XX_TIMESYNC_BASE_VIRT;
391
switch (cfg.tx_type) {
392
case HWTSTAMP_TX_OFF:
393
port->hwts_tx_en = 0;
396
port->hwts_tx_en = 1;
402
switch (cfg.rx_filter) {
403
case HWTSTAMP_FILTER_NONE:
404
port->hwts_rx_en = 0;
406
case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
407
port->hwts_rx_en = PTP_SLAVE_MODE;
408
__raw_writel(0, ®s->channel[ch].ch_control);
410
case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
411
port->hwts_rx_en = PTP_MASTER_MODE;
412
__raw_writel(MASTER_MODE, ®s->channel[ch].ch_control);
418
/* Clear out any old time stamps. */
419
__raw_writel(TX_SNAPSHOT_LOCKED | RX_SNAPSHOT_LOCKED,
420
®s->channel[ch].ch_event);
422
return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
250
425
static int ixp4xx_mdio_cmd(struct mii_bus *bus, int phy_id, int location,
251
426
int write, u16 cmd)