1 // SPDX-License-Identifier: GPL-2.0-only
3 * Intel IXP4xx Ethernet driver for Linux
5 * Copyright (C) 2007 Krzysztof Halasa <khc@pm.waw.pl>
7 * Ethernet port config (0x00 is not present on IXP42X):
9 * logical port 0x00 0x10 0x20
10 * NPE 0 (NPE-A) 1 (NPE-B) 2 (NPE-C)
11 * physical PortId 2 0 1
13 * RX-free queue 26 27 28
14 * TX-done queue is always 31, per-port RX and TX-ready queues are configurable
17 * bits 0 -> 1 - NPE ID (RX and TX-done)
18 * bits 0 -> 2 - priority (TX, per 802.1D)
19 * bits 3 -> 4 - port ID (user-set?)
20 * bits 5 -> 31 - physical descriptor address
23 #include <linux/delay.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/dmapool.h>
26 #include <linux/etherdevice.h>
28 #include <linux/kernel.h>
29 #include <linux/net_tstamp.h>
31 #include <linux/of_mdio.h>
32 #include <linux/phy.h>
33 #include <linux/platform_data/eth_ixp4xx.h>
34 #include <linux/platform_device.h>
35 #include <linux/ptp_classify.h>
36 #include <linux/slab.h>
37 #include <linux/module.h>
38 #include <linux/soc/ixp4xx/npe.h>
39 #include <linux/soc/ixp4xx/qmgr.h>
40 #include <mach/hardware.h>
41 #include <linux/soc/ixp4xx/cpu.h>
43 #include "ixp46x_ts.h"
48 #define DEBUG_PKT_BYTES 0
52 #define DRV_NAME "ixp4xx_eth"
56 #define RX_DESCS 64 /* also length of all RX queues */
57 #define TX_DESCS 16 /* also length of all TX queues */
58 #define TXDONE_QUEUE_LEN 64 /* dwords */
60 #define POOL_ALLOC_SIZE (sizeof(struct desc) * (RX_DESCS + TX_DESCS))
61 #define REGS_SIZE 0x1000
62 #define MAX_MRU 1536 /* 0x600 */
63 #define RX_BUFF_SIZE ALIGN((NET_IP_ALIGN) + MAX_MRU, 4)
65 #define NAPI_WEIGHT 16
66 #define MDIO_INTERVAL (3 * HZ)
67 #define MAX_MDIO_RETRIES 100 /* microseconds, typically 30 cycles */
68 #define MAX_CLOSE_WAIT 1000 /* microseconds, typically 2-3 cycles */
70 #define NPE_ID(port_id) ((port_id) >> 4)
71 #define PHYSICAL_ID(port_id) ((NPE_ID(port_id) + 2) % 3)
72 #define TX_QUEUE(port_id) (NPE_ID(port_id) + 23)
73 #define RXFREE_QUEUE(port_id) (NPE_ID(port_id) + 26)
74 #define TXDONE_QUEUE 31
76 #define PTP_SLAVE_MODE 1
77 #define PTP_MASTER_MODE 2
78 #define PORT2CHANNEL(p) NPE_ID(p->id)
80 /* TX Control Registers */
81 #define TX_CNTRL0_TX_EN 0x01
82 #define TX_CNTRL0_HALFDUPLEX 0x02
83 #define TX_CNTRL0_RETRY 0x04
84 #define TX_CNTRL0_PAD_EN 0x08
85 #define TX_CNTRL0_APPEND_FCS 0x10
86 #define TX_CNTRL0_2DEFER 0x20
87 #define TX_CNTRL0_RMII 0x40 /* reduced MII */
88 #define TX_CNTRL1_RETRIES 0x0F /* 4 bits */
90 /* RX Control Registers */
91 #define RX_CNTRL0_RX_EN 0x01
92 #define RX_CNTRL0_PADSTRIP_EN 0x02
93 #define RX_CNTRL0_SEND_FCS 0x04
94 #define RX_CNTRL0_PAUSE_EN 0x08
95 #define RX_CNTRL0_LOOP_EN 0x10
96 #define RX_CNTRL0_ADDR_FLTR_EN 0x20
97 #define RX_CNTRL0_RX_RUNT_EN 0x40
98 #define RX_CNTRL0_BCAST_DIS 0x80
99 #define RX_CNTRL1_DEFER_EN 0x01
101 /* Core Control Register */
102 #define CORE_RESET 0x01
103 #define CORE_RX_FIFO_FLUSH 0x02
104 #define CORE_TX_FIFO_FLUSH 0x04
105 #define CORE_SEND_JAM 0x08
106 #define CORE_MDC_EN 0x10 /* MDIO using NPE-B ETH-0 only */
108 #define DEFAULT_TX_CNTRL0 (TX_CNTRL0_TX_EN | TX_CNTRL0_RETRY | \
109 TX_CNTRL0_PAD_EN | TX_CNTRL0_APPEND_FCS | \
111 #define DEFAULT_RX_CNTRL0 RX_CNTRL0_RX_EN
112 #define DEFAULT_CORE_CNTRL CORE_MDC_EN
115 /* NPE message codes */
116 #define NPE_GETSTATUS 0x00
117 #define NPE_EDB_SETPORTADDRESS 0x01
118 #define NPE_EDB_GETMACADDRESSDATABASE 0x02
119 #define NPE_EDB_SETMACADDRESSSDATABASE 0x03
120 #define NPE_GETSTATS 0x04
121 #define NPE_RESETSTATS 0x05
122 #define NPE_SETMAXFRAMELENGTHS 0x06
123 #define NPE_VLAN_SETRXTAGMODE 0x07
124 #define NPE_VLAN_SETDEFAULTRXVID 0x08
125 #define NPE_VLAN_SETPORTVLANTABLEENTRY 0x09
126 #define NPE_VLAN_SETPORTVLANTABLERANGE 0x0A
127 #define NPE_VLAN_SETRXQOSENTRY 0x0B
128 #define NPE_VLAN_SETPORTIDEXTRACTIONMODE 0x0C
129 #define NPE_STP_SETBLOCKINGSTATE 0x0D
130 #define NPE_FW_SETFIREWALLMODE 0x0E
131 #define NPE_PC_SETFRAMECONTROLDURATIONID 0x0F
132 #define NPE_PC_SETAPMACTABLE 0x11
133 #define NPE_SETLOOPBACK_MODE 0x12
134 #define NPE_PC_SETBSSIDTABLE 0x13
135 #define NPE_ADDRESS_FILTER_CONFIG 0x14
136 #define NPE_APPENDFCSCONFIG 0x15
137 #define NPE_NOTIFY_MAC_RECOVERY_DONE 0x16
138 #define NPE_MAC_RECOVERY_START 0x17
142 typedef struct sk_buff buffer_t;
143 #define free_buffer dev_kfree_skb
144 #define free_buffer_irq dev_consume_skb_irq
146 typedef void buffer_t;
147 #define free_buffer kfree
148 #define free_buffer_irq kfree
152 u32 tx_control[2], __res1[2]; /* 000 */
153 u32 rx_control[2], __res2[2]; /* 010 */
154 u32 random_seed, __res3[3]; /* 020 */
155 u32 partial_empty_threshold, __res4; /* 030 */
156 u32 partial_full_threshold, __res5; /* 038 */
157 u32 tx_start_bytes, __res6[3]; /* 040 */
158 u32 tx_deferral, rx_deferral, __res7[2];/* 050 */
159 u32 tx_2part_deferral[2], __res8[2]; /* 060 */
160 u32 slot_time, __res9[3]; /* 070 */
161 u32 mdio_command[4]; /* 080 */
162 u32 mdio_status[4]; /* 090 */
163 u32 mcast_mask[6], __res10[2]; /* 0A0 */
164 u32 mcast_addr[6], __res11[2]; /* 0C0 */
165 u32 int_clock_threshold, __res12[3]; /* 0E0 */
166 u32 hw_addr[6], __res13[61]; /* 0F0 */
167 u32 core_control; /* 1FC */
171 struct eth_regs __iomem *regs;
173 struct net_device *netdev;
174 struct napi_struct napi;
175 struct eth_plat_info *plat;
176 buffer_t *rx_buff_tab[RX_DESCS], *tx_buff_tab[TX_DESCS];
177 struct desc *desc_tab; /* coherent */
179 int id; /* logical port ID */
186 /* NPE message structure */
189 u8 cmd, eth_id, byte2, byte3;
190 u8 byte4, byte5, byte6, byte7;
192 u8 byte3, byte2, eth_id, cmd;
193 u8 byte7, byte6, byte5, byte4;
197 /* Ethernet packet descriptor */
199 u32 next; /* pointer to next buffer, unused */
202 u16 buf_len; /* buffer length */
203 u16 pkt_len; /* packet length */
204 u32 data; /* pointer to data buffer in RAM */
212 u16 pkt_len; /* packet length */
213 u16 buf_len; /* buffer length */
214 u32 data; /* pointer to data buffer in RAM */
224 u8 dst_mac_0, dst_mac_1, dst_mac_2, dst_mac_3;
225 u8 dst_mac_4, dst_mac_5, src_mac_0, src_mac_1;
226 u8 src_mac_2, src_mac_3, src_mac_4, src_mac_5;
228 u8 dst_mac_3, dst_mac_2, dst_mac_1, dst_mac_0;
229 u8 src_mac_1, src_mac_0, dst_mac_5, dst_mac_4;
230 u8 src_mac_5, src_mac_4, src_mac_3, src_mac_2;
235 #define rx_desc_phys(port, n) ((port)->desc_tab_phys + \
236 (n) * sizeof(struct desc))
237 #define rx_desc_ptr(port, n) (&(port)->desc_tab[n])
239 #define tx_desc_phys(port, n) ((port)->desc_tab_phys + \
240 ((n) + RX_DESCS) * sizeof(struct desc))
241 #define tx_desc_ptr(port, n) (&(port)->desc_tab[(n) + RX_DESCS])
244 static inline void memcpy_swab32(u32 *dest, u32 *src, int cnt)
247 for (i = 0; i < cnt; i++)
248 dest[i] = swab32(src[i]);
252 static DEFINE_SPINLOCK(mdio_lock);
253 static struct eth_regs __iomem *mdio_regs; /* mdio command and status only */
254 static struct mii_bus *mdio_bus;
255 static struct device_node *mdio_bus_np;
256 static int ports_open;
257 static struct port *npe_port_tab[MAX_NPES];
258 static struct dma_pool *dma_pool;
260 static int ixp_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)
262 u8 *data = skb->data;
267 if (ptp_classify_raw(skb) != PTP_CLASS_V1_IPV4)
270 offset = ETH_HLEN + IPV4_HLEN(data) + UDP_HLEN;
272 if (skb->len < offset + OFF_PTP_SEQUENCE_ID + sizeof(seqid))
275 hi = (u16 *)(data + offset + OFF_PTP_SOURCE_UUID);
276 id = (u16 *)(data + offset + OFF_PTP_SEQUENCE_ID);
278 memcpy(&lo, &hi[1], sizeof(lo));
280 return (uid_hi == ntohs(*hi) &&
281 uid_lo == ntohl(lo) &&
282 seqid == ntohs(*id));
285 static void ixp_rx_timestamp(struct port *port, struct sk_buff *skb)
287 struct skb_shared_hwtstamps *shhwtstamps;
288 struct ixp46x_ts_regs *regs;
293 if (!port->hwts_rx_en)
296 ch = PORT2CHANNEL(port);
298 regs = (struct ixp46x_ts_regs __iomem *) IXP4XX_TIMESYNC_BASE_VIRT;
300 val = __raw_readl(®s->channel[ch].ch_event);
302 if (!(val & RX_SNAPSHOT_LOCKED))
305 lo = __raw_readl(®s->channel[ch].src_uuid_lo);
306 hi = __raw_readl(®s->channel[ch].src_uuid_hi);
309 seq = (hi >> 16) & 0xffff;
311 if (!ixp_ptp_match(skb, htons(uid), htonl(lo), htons(seq)))
314 lo = __raw_readl(®s->channel[ch].rx_snap_lo);
315 hi = __raw_readl(®s->channel[ch].rx_snap_hi);
316 ns = ((u64) hi) << 32;
318 ns <<= TICKS_NS_SHIFT;
320 shhwtstamps = skb_hwtstamps(skb);
321 memset(shhwtstamps, 0, sizeof(*shhwtstamps));
322 shhwtstamps->hwtstamp = ns_to_ktime(ns);
324 __raw_writel(RX_SNAPSHOT_LOCKED, ®s->channel[ch].ch_event);
327 static void ixp_tx_timestamp(struct port *port, struct sk_buff *skb)
329 struct skb_shared_hwtstamps shhwtstamps;
330 struct ixp46x_ts_regs *regs;
331 struct skb_shared_info *shtx;
333 u32 ch, cnt, hi, lo, val;
335 shtx = skb_shinfo(skb);
336 if (unlikely(shtx->tx_flags & SKBTX_HW_TSTAMP && port->hwts_tx_en))
337 shtx->tx_flags |= SKBTX_IN_PROGRESS;
341 ch = PORT2CHANNEL(port);
343 regs = (struct ixp46x_ts_regs __iomem *) IXP4XX_TIMESYNC_BASE_VIRT;
346 * This really stinks, but we have to poll for the Tx time stamp.
347 * Usually, the time stamp is ready after 4 to 6 microseconds.
349 for (cnt = 0; cnt < 100; cnt++) {
350 val = __raw_readl(®s->channel[ch].ch_event);
351 if (val & TX_SNAPSHOT_LOCKED)
355 if (!(val & TX_SNAPSHOT_LOCKED)) {
356 shtx->tx_flags &= ~SKBTX_IN_PROGRESS;
360 lo = __raw_readl(®s->channel[ch].tx_snap_lo);
361 hi = __raw_readl(®s->channel[ch].tx_snap_hi);
362 ns = ((u64) hi) << 32;
364 ns <<= TICKS_NS_SHIFT;
366 memset(&shhwtstamps, 0, sizeof(shhwtstamps));
367 shhwtstamps.hwtstamp = ns_to_ktime(ns);
368 skb_tstamp_tx(skb, &shhwtstamps);
370 __raw_writel(TX_SNAPSHOT_LOCKED, ®s->channel[ch].ch_event);
373 static int hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
375 struct hwtstamp_config cfg;
376 struct ixp46x_ts_regs *regs;
377 struct port *port = netdev_priv(netdev);
380 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
383 if (cfg.flags) /* reserved for future extensions */
386 ch = PORT2CHANNEL(port);
387 regs = (struct ixp46x_ts_regs __iomem *) IXP4XX_TIMESYNC_BASE_VIRT;
389 if (cfg.tx_type != HWTSTAMP_TX_OFF && cfg.tx_type != HWTSTAMP_TX_ON)
392 switch (cfg.rx_filter) {
393 case HWTSTAMP_FILTER_NONE:
394 port->hwts_rx_en = 0;
396 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
397 port->hwts_rx_en = PTP_SLAVE_MODE;
398 __raw_writel(0, ®s->channel[ch].ch_control);
400 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
401 port->hwts_rx_en = PTP_MASTER_MODE;
402 __raw_writel(MASTER_MODE, ®s->channel[ch].ch_control);
408 port->hwts_tx_en = cfg.tx_type == HWTSTAMP_TX_ON;
410 /* Clear out any old time stamps. */
411 __raw_writel(TX_SNAPSHOT_LOCKED | RX_SNAPSHOT_LOCKED,
412 ®s->channel[ch].ch_event);
414 return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
417 static int hwtstamp_get(struct net_device *netdev, struct ifreq *ifr)
419 struct hwtstamp_config cfg;
420 struct port *port = netdev_priv(netdev);
423 cfg.tx_type = port->hwts_tx_en ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF;
425 switch (port->hwts_rx_en) {
427 cfg.rx_filter = HWTSTAMP_FILTER_NONE;
430 cfg.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_SYNC;
432 case PTP_MASTER_MODE:
433 cfg.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ;
440 return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
443 static int ixp4xx_mdio_cmd(struct mii_bus *bus, int phy_id, int location,
448 if (__raw_readl(&mdio_regs->mdio_command[3]) & 0x80) {
449 printk(KERN_ERR "%s: MII not ready to transmit\n", bus->name);
454 __raw_writel(cmd & 0xFF, &mdio_regs->mdio_command[0]);
455 __raw_writel(cmd >> 8, &mdio_regs->mdio_command[1]);
457 __raw_writel(((phy_id << 5) | location) & 0xFF,
458 &mdio_regs->mdio_command[2]);
459 __raw_writel((phy_id >> 3) | (write << 2) | 0x80 /* GO */,
460 &mdio_regs->mdio_command[3]);
462 while ((cycles < MAX_MDIO_RETRIES) &&
463 (__raw_readl(&mdio_regs->mdio_command[3]) & 0x80)) {
468 if (cycles == MAX_MDIO_RETRIES) {
469 printk(KERN_ERR "%s #%i: MII write failed\n", bus->name,
475 printk(KERN_DEBUG "%s #%i: mdio_%s() took %i cycles\n", bus->name,
476 phy_id, write ? "write" : "read", cycles);
482 if (__raw_readl(&mdio_regs->mdio_status[3]) & 0x80) {
484 printk(KERN_DEBUG "%s #%i: MII read failed\n", bus->name,
487 return 0xFFFF; /* don't return error */
490 return (__raw_readl(&mdio_regs->mdio_status[0]) & 0xFF) |
491 ((__raw_readl(&mdio_regs->mdio_status[1]) & 0xFF) << 8);
494 static int ixp4xx_mdio_read(struct mii_bus *bus, int phy_id, int location)
499 spin_lock_irqsave(&mdio_lock, flags);
500 ret = ixp4xx_mdio_cmd(bus, phy_id, location, 0, 0);
501 spin_unlock_irqrestore(&mdio_lock, flags);
503 printk(KERN_DEBUG "%s #%i: MII read [%i] -> 0x%X\n", bus->name,
504 phy_id, location, ret);
509 static int ixp4xx_mdio_write(struct mii_bus *bus, int phy_id, int location,
515 spin_lock_irqsave(&mdio_lock, flags);
516 ret = ixp4xx_mdio_cmd(bus, phy_id, location, 1, val);
517 spin_unlock_irqrestore(&mdio_lock, flags);
519 printk(KERN_DEBUG "%s #%i: MII write [%i] <- 0x%X, err = %i\n",
520 bus->name, phy_id, location, val, ret);
525 static int ixp4xx_mdio_register(struct eth_regs __iomem *regs)
529 if (!(mdio_bus = mdiobus_alloc()))
533 __raw_writel(DEFAULT_CORE_CNTRL, &mdio_regs->core_control);
534 mdio_bus->name = "IXP4xx MII Bus";
535 mdio_bus->read = &ixp4xx_mdio_read;
536 mdio_bus->write = &ixp4xx_mdio_write;
537 snprintf(mdio_bus->id, MII_BUS_ID_SIZE, "ixp4xx-eth-0");
539 err = of_mdiobus_register(mdio_bus, mdio_bus_np);
541 mdiobus_free(mdio_bus);
545 static void ixp4xx_mdio_remove(void)
547 mdiobus_unregister(mdio_bus);
548 mdiobus_free(mdio_bus);
552 static void ixp4xx_adjust_link(struct net_device *dev)
554 struct port *port = netdev_priv(dev);
555 struct phy_device *phydev = dev->phydev;
560 printk(KERN_INFO "%s: link down\n", dev->name);
565 if (port->speed == phydev->speed && port->duplex == phydev->duplex)
568 port->speed = phydev->speed;
569 port->duplex = phydev->duplex;
572 __raw_writel(DEFAULT_TX_CNTRL0 & ~TX_CNTRL0_HALFDUPLEX,
573 &port->regs->tx_control[0]);
575 __raw_writel(DEFAULT_TX_CNTRL0 | TX_CNTRL0_HALFDUPLEX,
576 &port->regs->tx_control[0]);
578 netdev_info(dev, "%s: link up, speed %u Mb/s, %s duplex\n",
579 dev->name, port->speed, port->duplex ? "full" : "half");
583 static inline void debug_pkt(struct net_device *dev, const char *func,
589 netdev_debug(dev, "%s(%i) ", func, len);
590 for (i = 0; i < len; i++) {
591 if (i >= DEBUG_PKT_BYTES)
594 ((i == 6) || (i == 12) || (i >= 14)) ? " " : "",
602 static inline void debug_desc(u32 phys, struct desc *desc)
605 printk(KERN_DEBUG "%X: %X %3X %3X %08X %2X < %2X %4X %X"
606 " %X %X %02X%02X%02X%02X%02X%02X < %02X%02X%02X%02X%02X%02X\n",
607 phys, desc->next, desc->buf_len, desc->pkt_len,
608 desc->data, desc->dest_id, desc->src_id, desc->flags,
609 desc->qos, desc->padlen, desc->vlan_tci,
610 desc->dst_mac_0, desc->dst_mac_1, desc->dst_mac_2,
611 desc->dst_mac_3, desc->dst_mac_4, desc->dst_mac_5,
612 desc->src_mac_0, desc->src_mac_1, desc->src_mac_2,
613 desc->src_mac_3, desc->src_mac_4, desc->src_mac_5);
617 static inline int queue_get_desc(unsigned int queue, struct port *port,
620 u32 phys, tab_phys, n_desc;
623 if (!(phys = qmgr_get_entry(queue)))
626 phys &= ~0x1F; /* mask out non-address bits */
627 tab_phys = is_tx ? tx_desc_phys(port, 0) : rx_desc_phys(port, 0);
628 tab = is_tx ? tx_desc_ptr(port, 0) : rx_desc_ptr(port, 0);
629 n_desc = (phys - tab_phys) / sizeof(struct desc);
630 BUG_ON(n_desc >= (is_tx ? TX_DESCS : RX_DESCS));
631 debug_desc(phys, &tab[n_desc]);
632 BUG_ON(tab[n_desc].next);
636 static inline void queue_put_desc(unsigned int queue, u32 phys,
639 debug_desc(phys, desc);
641 qmgr_put_entry(queue, phys);
642 /* Don't check for queue overflow here, we've allocated sufficient
643 length and queues >= 32 don't support this check anyway. */
647 static inline void dma_unmap_tx(struct port *port, struct desc *desc)
650 dma_unmap_single(&port->netdev->dev, desc->data,
651 desc->buf_len, DMA_TO_DEVICE);
653 dma_unmap_single(&port->netdev->dev, desc->data & ~3,
654 ALIGN((desc->data & 3) + desc->buf_len, 4),
660 static void eth_rx_irq(void *pdev)
662 struct net_device *dev = pdev;
663 struct port *port = netdev_priv(dev);
666 printk(KERN_DEBUG "%s: eth_rx_irq\n", dev->name);
668 qmgr_disable_irq(port->plat->rxq);
669 napi_schedule(&port->napi);
672 static int eth_poll(struct napi_struct *napi, int budget)
674 struct port *port = container_of(napi, struct port, napi);
675 struct net_device *dev = port->netdev;
676 unsigned int rxq = port->plat->rxq, rxfreeq = RXFREE_QUEUE(port->id);
680 netdev_debug(dev, "eth_poll\n");
683 while (received < budget) {
688 struct sk_buff *temp;
692 if ((n = queue_get_desc(rxq, port, 0)) < 0) {
694 netdev_debug(dev, "eth_poll napi_complete\n");
697 qmgr_enable_irq(rxq);
698 if (!qmgr_stat_below_low_watermark(rxq) &&
699 napi_reschedule(napi)) { /* not empty again */
701 netdev_debug(dev, "eth_poll napi_reschedule succeeded\n");
703 qmgr_disable_irq(rxq);
707 netdev_debug(dev, "eth_poll all done\n");
709 return received; /* all work done */
712 desc = rx_desc_ptr(port, n);
715 if ((skb = netdev_alloc_skb(dev, RX_BUFF_SIZE))) {
716 phys = dma_map_single(&dev->dev, skb->data,
717 RX_BUFF_SIZE, DMA_FROM_DEVICE);
718 if (dma_mapping_error(&dev->dev, phys)) {
724 skb = netdev_alloc_skb(dev,
725 ALIGN(NET_IP_ALIGN + desc->pkt_len, 4));
729 dev->stats.rx_dropped++;
730 /* put the desc back on RX-ready queue */
731 desc->buf_len = MAX_MRU;
733 queue_put_desc(rxfreeq, rx_desc_phys(port, n), desc);
737 /* process received frame */
740 skb = port->rx_buff_tab[n];
741 dma_unmap_single(&dev->dev, desc->data - NET_IP_ALIGN,
742 RX_BUFF_SIZE, DMA_FROM_DEVICE);
744 dma_sync_single_for_cpu(&dev->dev, desc->data - NET_IP_ALIGN,
745 RX_BUFF_SIZE, DMA_FROM_DEVICE);
746 memcpy_swab32((u32 *)skb->data, (u32 *)port->rx_buff_tab[n],
747 ALIGN(NET_IP_ALIGN + desc->pkt_len, 4) / 4);
749 skb_reserve(skb, NET_IP_ALIGN);
750 skb_put(skb, desc->pkt_len);
752 debug_pkt(dev, "eth_poll", skb->data, skb->len);
754 ixp_rx_timestamp(port, skb);
755 skb->protocol = eth_type_trans(skb, dev);
756 dev->stats.rx_packets++;
757 dev->stats.rx_bytes += skb->len;
758 netif_receive_skb(skb);
760 /* put the new buffer on RX-free queue */
762 port->rx_buff_tab[n] = temp;
763 desc->data = phys + NET_IP_ALIGN;
765 desc->buf_len = MAX_MRU;
767 queue_put_desc(rxfreeq, rx_desc_phys(port, n), desc);
772 netdev_debug(dev, "eth_poll(): end, not all work done\n");
774 return received; /* not all work done */
778 static void eth_txdone_irq(void *unused)
783 printk(KERN_DEBUG DRV_NAME ": eth_txdone_irq\n");
785 while ((phys = qmgr_get_entry(TXDONE_QUEUE)) != 0) {
792 BUG_ON(npe_id >= MAX_NPES);
793 port = npe_port_tab[npe_id];
795 phys &= ~0x1F; /* mask out non-address bits */
796 n_desc = (phys - tx_desc_phys(port, 0)) / sizeof(struct desc);
797 BUG_ON(n_desc >= TX_DESCS);
798 desc = tx_desc_ptr(port, n_desc);
799 debug_desc(phys, desc);
801 if (port->tx_buff_tab[n_desc]) { /* not the draining packet */
802 port->netdev->stats.tx_packets++;
803 port->netdev->stats.tx_bytes += desc->pkt_len;
805 dma_unmap_tx(port, desc);
807 printk(KERN_DEBUG "%s: eth_txdone_irq free %p\n",
808 port->netdev->name, port->tx_buff_tab[n_desc]);
810 free_buffer_irq(port->tx_buff_tab[n_desc]);
811 port->tx_buff_tab[n_desc] = NULL;
814 start = qmgr_stat_below_low_watermark(port->plat->txreadyq);
815 queue_put_desc(port->plat->txreadyq, phys, desc);
816 if (start) { /* TX-ready queue was empty */
818 printk(KERN_DEBUG "%s: eth_txdone_irq xmit ready\n",
821 netif_wake_queue(port->netdev);
826 static int eth_xmit(struct sk_buff *skb, struct net_device *dev)
828 struct port *port = netdev_priv(dev);
829 unsigned int txreadyq = port->plat->txreadyq;
830 int len, offset, bytes, n;
836 netdev_debug(dev, "eth_xmit\n");
839 if (unlikely(skb->len > MAX_MRU)) {
841 dev->stats.tx_errors++;
845 debug_pkt(dev, "eth_xmit", skb->data, skb->len);
849 offset = 0; /* no need to keep alignment */
853 offset = (int)skb->data & 3; /* keep 32-bit alignment */
854 bytes = ALIGN(offset + len, 4);
855 if (!(mem = kmalloc(bytes, GFP_ATOMIC))) {
857 dev->stats.tx_dropped++;
860 memcpy_swab32(mem, (u32 *)((int)skb->data & ~3), bytes / 4);
863 phys = dma_map_single(&dev->dev, mem, bytes, DMA_TO_DEVICE);
864 if (dma_mapping_error(&dev->dev, phys)) {
869 dev->stats.tx_dropped++;
873 n = queue_get_desc(txreadyq, port, 1);
875 desc = tx_desc_ptr(port, n);
878 port->tx_buff_tab[n] = skb;
880 port->tx_buff_tab[n] = mem;
882 desc->data = phys + offset;
883 desc->buf_len = desc->pkt_len = len;
885 /* NPE firmware pads short frames with zeros internally */
887 queue_put_desc(TX_QUEUE(port->id), tx_desc_phys(port, n), desc);
889 if (qmgr_stat_below_low_watermark(txreadyq)) { /* empty */
891 netdev_debug(dev, "eth_xmit queue full\n");
893 netif_stop_queue(dev);
894 /* we could miss TX ready interrupt */
895 /* really empty in fact */
896 if (!qmgr_stat_below_low_watermark(txreadyq)) {
898 netdev_debug(dev, "eth_xmit ready again\n");
900 netif_wake_queue(dev);
905 netdev_debug(dev, "eth_xmit end\n");
908 ixp_tx_timestamp(port, skb);
909 skb_tx_timestamp(skb);
918 static void eth_set_mcast_list(struct net_device *dev)
920 struct port *port = netdev_priv(dev);
921 struct netdev_hw_addr *ha;
922 u8 diffs[ETH_ALEN], *addr;
924 static const u8 allmulti[] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 };
926 if ((dev->flags & IFF_ALLMULTI) && !(dev->flags & IFF_PROMISC)) {
927 for (i = 0; i < ETH_ALEN; i++) {
928 __raw_writel(allmulti[i], &port->regs->mcast_addr[i]);
929 __raw_writel(allmulti[i], &port->regs->mcast_mask[i]);
931 __raw_writel(DEFAULT_RX_CNTRL0 | RX_CNTRL0_ADDR_FLTR_EN,
932 &port->regs->rx_control[0]);
936 if ((dev->flags & IFF_PROMISC) || netdev_mc_empty(dev)) {
937 __raw_writel(DEFAULT_RX_CNTRL0 & ~RX_CNTRL0_ADDR_FLTR_EN,
938 &port->regs->rx_control[0]);
942 eth_zero_addr(diffs);
945 netdev_for_each_mc_addr(ha, dev) {
947 addr = ha->addr; /* first MAC address */
948 for (i = 0; i < ETH_ALEN; i++)
949 diffs[i] |= addr[i] ^ ha->addr[i];
952 for (i = 0; i < ETH_ALEN; i++) {
953 __raw_writel(addr[i], &port->regs->mcast_addr[i]);
954 __raw_writel(~diffs[i], &port->regs->mcast_mask[i]);
957 __raw_writel(DEFAULT_RX_CNTRL0 | RX_CNTRL0_ADDR_FLTR_EN,
958 &port->regs->rx_control[0]);
962 static int eth_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
964 if (!netif_running(dev))
967 if (cpu_is_ixp46x()) {
968 if (cmd == SIOCSHWTSTAMP)
969 return hwtstamp_set(dev, req);
970 if (cmd == SIOCGHWTSTAMP)
971 return hwtstamp_get(dev, req);
974 return phy_mii_ioctl(dev->phydev, req, cmd);
977 /* ethtool support */
979 static void ixp4xx_get_drvinfo(struct net_device *dev,
980 struct ethtool_drvinfo *info)
982 struct port *port = netdev_priv(dev);
984 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
985 snprintf(info->fw_version, sizeof(info->fw_version), "%u:%u:%u:%u",
986 port->firmware[0], port->firmware[1],
987 port->firmware[2], port->firmware[3]);
988 strlcpy(info->bus_info, "internal", sizeof(info->bus_info));
991 int ixp46x_phc_index = -1;
992 EXPORT_SYMBOL_GPL(ixp46x_phc_index);
994 static int ixp4xx_get_ts_info(struct net_device *dev,
995 struct ethtool_ts_info *info)
997 if (!cpu_is_ixp46x()) {
998 info->so_timestamping =
999 SOF_TIMESTAMPING_TX_SOFTWARE |
1000 SOF_TIMESTAMPING_RX_SOFTWARE |
1001 SOF_TIMESTAMPING_SOFTWARE;
1002 info->phc_index = -1;
1005 info->so_timestamping =
1006 SOF_TIMESTAMPING_TX_HARDWARE |
1007 SOF_TIMESTAMPING_RX_HARDWARE |
1008 SOF_TIMESTAMPING_RAW_HARDWARE;
1009 info->phc_index = ixp46x_phc_index;
1011 (1 << HWTSTAMP_TX_OFF) |
1012 (1 << HWTSTAMP_TX_ON);
1014 (1 << HWTSTAMP_FILTER_NONE) |
1015 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1016 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ);
1020 static const struct ethtool_ops ixp4xx_ethtool_ops = {
1021 .get_drvinfo = ixp4xx_get_drvinfo,
1022 .nway_reset = phy_ethtool_nway_reset,
1023 .get_link = ethtool_op_get_link,
1024 .get_ts_info = ixp4xx_get_ts_info,
1025 .get_link_ksettings = phy_ethtool_get_link_ksettings,
1026 .set_link_ksettings = phy_ethtool_set_link_ksettings,
1030 static int request_queues(struct port *port)
1034 err = qmgr_request_queue(RXFREE_QUEUE(port->id), RX_DESCS, 0, 0,
1035 "%s:RX-free", port->netdev->name);
1039 err = qmgr_request_queue(port->plat->rxq, RX_DESCS, 0, 0,
1040 "%s:RX", port->netdev->name);
1044 err = qmgr_request_queue(TX_QUEUE(port->id), TX_DESCS, 0, 0,
1045 "%s:TX", port->netdev->name);
1049 err = qmgr_request_queue(port->plat->txreadyq, TX_DESCS, 0, 0,
1050 "%s:TX-ready", port->netdev->name);
1054 /* TX-done queue handles skbs sent out by the NPEs */
1056 err = qmgr_request_queue(TXDONE_QUEUE, TXDONE_QUEUE_LEN, 0, 0,
1057 "%s:TX-done", DRV_NAME);
1064 qmgr_release_queue(port->plat->txreadyq);
1066 qmgr_release_queue(TX_QUEUE(port->id));
1068 qmgr_release_queue(port->plat->rxq);
1070 qmgr_release_queue(RXFREE_QUEUE(port->id));
1071 printk(KERN_DEBUG "%s: unable to request hardware queues\n",
1072 port->netdev->name);
1076 static void release_queues(struct port *port)
1078 qmgr_release_queue(RXFREE_QUEUE(port->id));
1079 qmgr_release_queue(port->plat->rxq);
1080 qmgr_release_queue(TX_QUEUE(port->id));
1081 qmgr_release_queue(port->plat->txreadyq);
1084 qmgr_release_queue(TXDONE_QUEUE);
1087 static int init_queues(struct port *port)
1092 dma_pool = dma_pool_create(DRV_NAME, &port->netdev->dev,
1093 POOL_ALLOC_SIZE, 32, 0);
1098 if (!(port->desc_tab = dma_pool_alloc(dma_pool, GFP_KERNEL,
1099 &port->desc_tab_phys)))
1101 memset(port->desc_tab, 0, POOL_ALLOC_SIZE);
1102 memset(port->rx_buff_tab, 0, sizeof(port->rx_buff_tab)); /* tables */
1103 memset(port->tx_buff_tab, 0, sizeof(port->tx_buff_tab));
1105 /* Setup RX buffers */
1106 for (i = 0; i < RX_DESCS; i++) {
1107 struct desc *desc = rx_desc_ptr(port, i);
1108 buffer_t *buff; /* skb or kmalloc()ated memory */
1111 if (!(buff = netdev_alloc_skb(port->netdev, RX_BUFF_SIZE)))
1115 if (!(buff = kmalloc(RX_BUFF_SIZE, GFP_KERNEL)))
1119 desc->buf_len = MAX_MRU;
1120 desc->data = dma_map_single(&port->netdev->dev, data,
1121 RX_BUFF_SIZE, DMA_FROM_DEVICE);
1122 if (dma_mapping_error(&port->netdev->dev, desc->data)) {
1126 desc->data += NET_IP_ALIGN;
1127 port->rx_buff_tab[i] = buff;
1133 static void destroy_queues(struct port *port)
1137 if (port->desc_tab) {
1138 for (i = 0; i < RX_DESCS; i++) {
1139 struct desc *desc = rx_desc_ptr(port, i);
1140 buffer_t *buff = port->rx_buff_tab[i];
1142 dma_unmap_single(&port->netdev->dev,
1143 desc->data - NET_IP_ALIGN,
1144 RX_BUFF_SIZE, DMA_FROM_DEVICE);
1148 for (i = 0; i < TX_DESCS; i++) {
1149 struct desc *desc = tx_desc_ptr(port, i);
1150 buffer_t *buff = port->tx_buff_tab[i];
1152 dma_unmap_tx(port, desc);
1156 dma_pool_free(dma_pool, port->desc_tab, port->desc_tab_phys);
1157 port->desc_tab = NULL;
1160 if (!ports_open && dma_pool) {
1161 dma_pool_destroy(dma_pool);
1166 static int eth_open(struct net_device *dev)
1168 struct port *port = netdev_priv(dev);
1169 struct npe *npe = port->npe;
1173 if (!npe_running(npe)) {
1174 err = npe_load_firmware(npe, npe_name(npe), &dev->dev);
1178 if (npe_recv_message(npe, &msg, "ETH_GET_STATUS")) {
1179 netdev_err(dev, "%s not responding\n", npe_name(npe));
1182 port->firmware[0] = msg.byte4;
1183 port->firmware[1] = msg.byte5;
1184 port->firmware[2] = msg.byte6;
1185 port->firmware[3] = msg.byte7;
1188 memset(&msg, 0, sizeof(msg));
1189 msg.cmd = NPE_VLAN_SETRXQOSENTRY;
1190 msg.eth_id = port->id;
1191 msg.byte5 = port->plat->rxq | 0x80;
1192 msg.byte7 = port->plat->rxq << 4;
1193 for (i = 0; i < 8; i++) {
1195 if (npe_send_recv_message(port->npe, &msg, "ETH_SET_RXQ"))
1199 msg.cmd = NPE_EDB_SETPORTADDRESS;
1200 msg.eth_id = PHYSICAL_ID(port->id);
1201 msg.byte2 = dev->dev_addr[0];
1202 msg.byte3 = dev->dev_addr[1];
1203 msg.byte4 = dev->dev_addr[2];
1204 msg.byte5 = dev->dev_addr[3];
1205 msg.byte6 = dev->dev_addr[4];
1206 msg.byte7 = dev->dev_addr[5];
1207 if (npe_send_recv_message(port->npe, &msg, "ETH_SET_MAC"))
1210 memset(&msg, 0, sizeof(msg));
1211 msg.cmd = NPE_FW_SETFIREWALLMODE;
1212 msg.eth_id = port->id;
1213 if (npe_send_recv_message(port->npe, &msg, "ETH_SET_FIREWALL_MODE"))
1216 if ((err = request_queues(port)) != 0)
1219 if ((err = init_queues(port)) != 0) {
1220 destroy_queues(port);
1221 release_queues(port);
1225 port->speed = 0; /* force "link up" message */
1226 phy_start(dev->phydev);
1228 for (i = 0; i < ETH_ALEN; i++)
1229 __raw_writel(dev->dev_addr[i], &port->regs->hw_addr[i]);
1230 __raw_writel(0x08, &port->regs->random_seed);
1231 __raw_writel(0x12, &port->regs->partial_empty_threshold);
1232 __raw_writel(0x30, &port->regs->partial_full_threshold);
1233 __raw_writel(0x08, &port->regs->tx_start_bytes);
1234 __raw_writel(0x15, &port->regs->tx_deferral);
1235 __raw_writel(0x08, &port->regs->tx_2part_deferral[0]);
1236 __raw_writel(0x07, &port->regs->tx_2part_deferral[1]);
1237 __raw_writel(0x80, &port->regs->slot_time);
1238 __raw_writel(0x01, &port->regs->int_clock_threshold);
1240 /* Populate queues with buffers, no failure after this point */
1241 for (i = 0; i < TX_DESCS; i++)
1242 queue_put_desc(port->plat->txreadyq,
1243 tx_desc_phys(port, i), tx_desc_ptr(port, i));
1245 for (i = 0; i < RX_DESCS; i++)
1246 queue_put_desc(RXFREE_QUEUE(port->id),
1247 rx_desc_phys(port, i), rx_desc_ptr(port, i));
1249 __raw_writel(TX_CNTRL1_RETRIES, &port->regs->tx_control[1]);
1250 __raw_writel(DEFAULT_TX_CNTRL0, &port->regs->tx_control[0]);
1251 __raw_writel(0, &port->regs->rx_control[1]);
1252 __raw_writel(DEFAULT_RX_CNTRL0, &port->regs->rx_control[0]);
1254 napi_enable(&port->napi);
1255 eth_set_mcast_list(dev);
1256 netif_start_queue(dev);
1258 qmgr_set_irq(port->plat->rxq, QUEUE_IRQ_SRC_NOT_EMPTY,
1261 qmgr_set_irq(TXDONE_QUEUE, QUEUE_IRQ_SRC_NOT_EMPTY,
1262 eth_txdone_irq, NULL);
1263 qmgr_enable_irq(TXDONE_QUEUE);
1266 /* we may already have RX data, enables IRQ */
1267 napi_schedule(&port->napi);
1271 static int eth_close(struct net_device *dev)
1273 struct port *port = netdev_priv(dev);
1275 int buffs = RX_DESCS; /* allocated RX buffers */
1279 qmgr_disable_irq(port->plat->rxq);
1280 napi_disable(&port->napi);
1281 netif_stop_queue(dev);
1283 while (queue_get_desc(RXFREE_QUEUE(port->id), port, 0) >= 0)
1286 memset(&msg, 0, sizeof(msg));
1287 msg.cmd = NPE_SETLOOPBACK_MODE;
1288 msg.eth_id = port->id;
1290 if (npe_send_recv_message(port->npe, &msg, "ETH_ENABLE_LOOPBACK"))
1291 netdev_crit(dev, "unable to enable loopback\n");
1294 do { /* drain RX buffers */
1295 while (queue_get_desc(port->plat->rxq, port, 0) >= 0)
1299 if (qmgr_stat_empty(TX_QUEUE(port->id))) {
1300 /* we have to inject some packet */
1303 int n = queue_get_desc(port->plat->txreadyq, port, 1);
1305 desc = tx_desc_ptr(port, n);
1306 phys = tx_desc_phys(port, n);
1307 desc->buf_len = desc->pkt_len = 1;
1309 queue_put_desc(TX_QUEUE(port->id), phys, desc);
1312 } while (++i < MAX_CLOSE_WAIT);
1315 netdev_crit(dev, "unable to drain RX queue, %i buffer(s)"
1316 " left in NPE\n", buffs);
1319 netdev_debug(dev, "draining RX queue took %i cycles\n", i);
1323 while (queue_get_desc(TX_QUEUE(port->id), port, 1) >= 0)
1324 buffs--; /* cancel TX */
1328 while (queue_get_desc(port->plat->txreadyq, port, 1) >= 0)
1332 } while (++i < MAX_CLOSE_WAIT);
1335 netdev_crit(dev, "unable to drain TX queue, %i buffer(s) "
1336 "left in NPE\n", buffs);
1339 netdev_debug(dev, "draining TX queues took %i cycles\n", i);
1343 if (npe_send_recv_message(port->npe, &msg, "ETH_DISABLE_LOOPBACK"))
1344 netdev_crit(dev, "unable to disable loopback\n");
1346 phy_stop(dev->phydev);
1349 qmgr_disable_irq(TXDONE_QUEUE);
1350 destroy_queues(port);
1351 release_queues(port);
1355 static const struct net_device_ops ixp4xx_netdev_ops = {
1356 .ndo_open = eth_open,
1357 .ndo_stop = eth_close,
1358 .ndo_start_xmit = eth_xmit,
1359 .ndo_set_rx_mode = eth_set_mcast_list,
1360 .ndo_eth_ioctl = eth_ioctl,
1361 .ndo_set_mac_address = eth_mac_addr,
1362 .ndo_validate_addr = eth_validate_addr,
1366 static struct eth_plat_info *ixp4xx_of_get_platdata(struct device *dev)
1368 struct device_node *np = dev->of_node;
1369 struct of_phandle_args queue_spec;
1370 struct of_phandle_args npe_spec;
1371 struct device_node *mdio_np;
1372 struct eth_plat_info *plat;
1375 plat = devm_kzalloc(dev, sizeof(*plat), GFP_KERNEL);
1379 ret = of_parse_phandle_with_fixed_args(np, "intel,npe-handle", 1, 0,
1382 dev_err(dev, "no NPE engine specified\n");
1385 /* NPE ID 0x00, 0x10, 0x20... */
1386 plat->npe = (npe_spec.args[0] << 4);
1388 /* Check if this device has an MDIO bus */
1389 mdio_np = of_get_child_by_name(np, "mdio");
1391 plat->has_mdio = true;
1392 mdio_bus_np = mdio_np;
1393 /* DO NOT put the mdio_np, it will be used */
1396 /* Get the rx queue as a resource from queue manager */
1397 ret = of_parse_phandle_with_fixed_args(np, "queue-rx", 1, 0,
1400 dev_err(dev, "no rx queue phandle\n");
1403 plat->rxq = queue_spec.args[0];
1405 /* Get the txready queue as resource from queue manager */
1406 ret = of_parse_phandle_with_fixed_args(np, "queue-txready", 1, 0,
1409 dev_err(dev, "no txready queue phandle\n");
1412 plat->txreadyq = queue_spec.args[0];
1417 static struct eth_plat_info *ixp4xx_of_get_platdata(struct device *dev)
1423 static int ixp4xx_eth_probe(struct platform_device *pdev)
1425 struct phy_device *phydev = NULL;
1426 struct device *dev = &pdev->dev;
1427 struct device_node *np = dev->of_node;
1428 struct eth_plat_info *plat;
1429 struct net_device *ndev;
1434 plat = ixp4xx_of_get_platdata(dev);
1438 plat = dev_get_platdata(dev);
1441 plat->npe = pdev->id;
1442 switch (plat->npe) {
1443 case IXP4XX_ETH_NPEA:
1444 /* If the MDIO bus is not up yet, defer probe */
1446 case IXP4XX_ETH_NPEB:
1447 /* On all except IXP43x, NPE-B is used for the MDIO bus.
1448 * If there is no NPE-B in the feature set, bail out,
1449 * else we have the MDIO bus here.
1451 if (!cpu_is_ixp43x()) {
1452 if (!(ixp4xx_read_feature_bits() &
1453 IXP4XX_FEATURE_NPEB_ETH0))
1455 /* Else register the MDIO bus on NPE-B */
1456 plat->has_mdio = true;
1459 case IXP4XX_ETH_NPEC:
1460 /* IXP43x lacks NPE-B and uses NPE-C for the MDIO bus
1461 * access, if there is no NPE-C, no bus, nothing works,
1464 if (cpu_is_ixp43x()) {
1465 if (!(ixp4xx_read_feature_bits() &
1466 IXP4XX_FEATURE_NPEC_ETH))
1468 /* Else register the MDIO bus on NPE-B */
1469 plat->has_mdio = true;
1477 if (!(ndev = devm_alloc_etherdev(dev, sizeof(struct port))))
1480 SET_NETDEV_DEV(ndev, dev);
1481 port = netdev_priv(ndev);
1482 port->netdev = ndev;
1483 port->id = plat->npe;
1485 /* Get the port resource and remap */
1486 port->regs = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
1487 if (IS_ERR(port->regs))
1488 return PTR_ERR(port->regs);
1490 /* Register the MDIO bus if we have it */
1491 if (plat->has_mdio) {
1492 err = ixp4xx_mdio_register(port->regs);
1494 dev_err(dev, "failed to register MDIO bus\n");
1498 /* If the instance with the MDIO bus has not yet appeared,
1499 * defer probing until it gets probed.
1502 return -EPROBE_DEFER;
1504 ndev->netdev_ops = &ixp4xx_netdev_ops;
1505 ndev->ethtool_ops = &ixp4xx_ethtool_ops;
1506 ndev->tx_queue_len = 100;
1507 /* Inherit the DMA masks from the platform device */
1508 ndev->dev.dma_mask = dev->dma_mask;
1509 ndev->dev.coherent_dma_mask = dev->coherent_dma_mask;
1511 netif_napi_add(ndev, &port->napi, eth_poll, NAPI_WEIGHT);
1513 if (!(port->npe = npe_request(NPE_ID(port->id))))
1517 npe_port_tab[NPE_ID(port->id)] = port;
1518 memcpy(ndev->dev_addr, plat->hwaddr, ETH_ALEN);
1520 platform_set_drvdata(pdev, ndev);
1522 __raw_writel(DEFAULT_CORE_CNTRL | CORE_RESET,
1523 &port->regs->core_control);
1525 __raw_writel(DEFAULT_CORE_CNTRL, &port->regs->core_control);
1529 phydev = of_phy_get_and_connect(ndev, np, ixp4xx_adjust_link);
1531 phydev = mdiobus_get_phy(mdio_bus, plat->phy);
1534 dev_err(dev, "could not connect phydev (%d)\n", err);
1537 err = phy_connect_direct(ndev, phydev, ixp4xx_adjust_link,
1538 PHY_INTERFACE_MODE_MII);
1545 dev_err(dev, "no phydev\n");
1549 phydev->irq = PHY_POLL;
1551 if ((err = register_netdev(ndev)))
1554 netdev_info(ndev, "%s: MII PHY %i on %s\n", ndev->name, plat->phy,
1555 npe_name(port->npe));
1560 phy_disconnect(phydev);
1562 npe_port_tab[NPE_ID(port->id)] = NULL;
1563 npe_release(port->npe);
1567 static int ixp4xx_eth_remove(struct platform_device *pdev)
1569 struct net_device *ndev = platform_get_drvdata(pdev);
1570 struct phy_device *phydev = ndev->phydev;
1571 struct port *port = netdev_priv(ndev);
1573 unregister_netdev(ndev);
1574 phy_disconnect(phydev);
1575 ixp4xx_mdio_remove();
1576 npe_port_tab[NPE_ID(port->id)] = NULL;
1577 npe_release(port->npe);
1581 static const struct of_device_id ixp4xx_eth_of_match[] = {
1583 .compatible = "intel,ixp4xx-ethernet",
1588 static struct platform_driver ixp4xx_eth_driver = {
1591 .of_match_table = of_match_ptr(ixp4xx_eth_of_match),
1593 .probe = ixp4xx_eth_probe,
1594 .remove = ixp4xx_eth_remove,
1596 module_platform_driver(ixp4xx_eth_driver);
1598 MODULE_AUTHOR("Krzysztof Halasa");
1599 MODULE_DESCRIPTION("Intel IXP4xx Ethernet driver");
1600 MODULE_LICENSE("GPL v2");
1601 MODULE_ALIAS("platform:ixp4xx_eth");