1 diff --git a/drivers/net/arm/Kconfig b/drivers/net/arm/Kconfig
2 index f9cc2b6..9274d3f 100644
3 --- a/drivers/net/arm/Kconfig
4 +++ b/drivers/net/arm/Kconfig
5 @@ -47,3 +47,13 @@ config EP93XX_ETH
7 This is a driver for the ethernet hardware included in EP93xx CPUs.
8 Say Y if you are building a kernel for EP93xx based devices.
11 + tristate "IXP4xx Ethernet support"
12 + depends on NET_ETHERNET && ARM && ARCH_IXP4XX
17 + Say Y here if you want to use built-in Ethernet ports
18 + on IXP4xx processor.
19 diff --git a/drivers/net/arm/Makefile b/drivers/net/arm/Makefile
20 index a4c8682..7c812ac 100644
21 --- a/drivers/net/arm/Makefile
22 +++ b/drivers/net/arm/Makefile
23 @@ -9,3 +9,4 @@ obj-$(CONFIG_ARM_ETHER3) += ether3.o
24 obj-$(CONFIG_ARM_ETHER1) += ether1.o
25 obj-$(CONFIG_ARM_AT91_ETHER) += at91_ether.o
26 obj-$(CONFIG_EP93XX_ETH) += ep93xx_eth.o
27 +obj-$(CONFIG_IXP4XX_ETH) += ixp4xx_eth.o
28 diff --git a/drivers/net/arm/ixp4xx_eth.c b/drivers/net/arm/ixp4xx_eth.c
30 index 0000000..98131a7
32 +++ b/drivers/net/arm/ixp4xx_eth.c
35 + * Intel IXP4xx Ethernet driver for Linux
37 + * Copyright (C) 2007 Krzysztof Halasa <khc@pm.waw.pl>
39 + * This program is free software; you can redistribute it and/or modify it
40 + * under the terms of version 2 of the GNU General Public License
41 + * as published by the Free Software Foundation.
43 + * Ethernet port config (0x00 is not present on IXP42X):
45 + * logical port 0x00 0x10 0x20
46 + * NPE 0 (NPE-A) 1 (NPE-B) 2 (NPE-C)
47 + * physical PortId 2 0 1
49 + * RX-free queue 26 27 28
50 + * TX-done queue is always 31, per-port RX and TX-ready queues are configurable
54 + * bits 0 -> 1 - NPE ID (RX and TX-done)
55 + * bits 0 -> 2 - priority (TX, per 802.1D)
56 + * bits 3 -> 4 - port ID (user-set?)
57 + * bits 5 -> 31 - physical descriptor address
60 +#include <linux/delay.h>
61 +#include <linux/dma-mapping.h>
62 +#include <linux/dmapool.h>
63 +#include <linux/etherdevice.h>
64 +#include <linux/io.h>
65 +#include <linux/kernel.h>
66 +#include <linux/mii.h>
67 +#include <linux/platform_device.h>
68 +#include <asm/arch/npe.h>
69 +#include <asm/arch/qmgr.h>
71 +#define DEBUG_QUEUES 0
75 +#define DEBUG_PKT_BYTES 0
77 +#define DEBUG_CLOSE 0
79 +#define DRV_NAME "ixp4xx_eth"
83 +#define RX_DESCS 64 /* also length of all RX queues */
84 +#define TX_DESCS 16 /* also length of all TX queues */
85 +#define TXDONE_QUEUE_LEN 64 /* dwords */
87 +#define POOL_ALLOC_SIZE (sizeof(struct desc) * (RX_DESCS + TX_DESCS))
88 +#define REGS_SIZE 0x1000
89 +#define MAX_MRU 1536 /* 0x600 */
91 +#define MDIO_INTERVAL (3 * HZ)
92 +#define MAX_MDIO_RETRIES 100 /* microseconds, typically 30 cycles */
93 +#define MAX_MII_RESET_RETRIES 100 /* mdio_read() cycles, typically 4 */
94 +#define MAX_CLOSE_WAIT 1000 /* microseconds, typically 2-3 cycles */
96 +#define NPE_ID(port_id) ((port_id) >> 4)
97 +#define PHYSICAL_ID(port_id) ((NPE_ID(port_id) + 2) % 3)
98 +#define TX_QUEUE(port_id) (NPE_ID(port_id) + 23)
99 +#define RXFREE_QUEUE(port_id) (NPE_ID(port_id) + 26)
100 +#define TXDONE_QUEUE 31
102 +#define ETH_NAPI_WEIGHT 16
104 +/* TX Control Registers */
105 +#define TX_CNTRL0_TX_EN 0x01
106 +#define TX_CNTRL0_HALFDUPLEX 0x02
107 +#define TX_CNTRL0_RETRY 0x04
108 +#define TX_CNTRL0_PAD_EN 0x08
109 +#define TX_CNTRL0_APPEND_FCS 0x10
110 +#define TX_CNTRL0_2DEFER 0x20
111 +#define TX_CNTRL0_RMII 0x40 /* reduced MII */
112 +#define TX_CNTRL1_RETRIES 0x0F /* 4 bits */
114 +/* RX Control Registers */
115 +#define RX_CNTRL0_RX_EN 0x01
116 +#define RX_CNTRL0_PADSTRIP_EN 0x02
117 +#define RX_CNTRL0_SEND_FCS 0x04
118 +#define RX_CNTRL0_PAUSE_EN 0x08
119 +#define RX_CNTRL0_LOOP_EN 0x10
120 +#define RX_CNTRL0_ADDR_FLTR_EN 0x20
121 +#define RX_CNTRL0_RX_RUNT_EN 0x40
122 +#define RX_CNTRL0_BCAST_DIS 0x80
123 +#define RX_CNTRL1_DEFER_EN 0x01
125 +/* Core Control Register */
126 +#define CORE_RESET 0x01
127 +#define CORE_RX_FIFO_FLUSH 0x02
128 +#define CORE_TX_FIFO_FLUSH 0x04
129 +#define CORE_SEND_JAM 0x08
130 +#define CORE_MDC_EN 0x10 /* MDIO using NPE-B ETH-0 only */
132 +#define DEFAULT_TX_CNTRL0 (TX_CNTRL0_TX_EN | TX_CNTRL0_RETRY | \
133 + TX_CNTRL0_PAD_EN | TX_CNTRL0_APPEND_FCS | \
135 +#define DEFAULT_RX_CNTRL0 RX_CNTRL0_RX_EN
136 +#define DEFAULT_CORE_CNTRL CORE_MDC_EN
139 +/* NPE message codes */
140 +#define NPE_GETSTATUS 0x00
141 +#define NPE_EDB_SETPORTADDRESS 0x01
142 +#define NPE_EDB_GETMACADDRESSDATABASE 0x02
143 +#define NPE_EDB_SETMACADDRESSSDATABASE 0x03
144 +#define NPE_GETSTATS 0x04
145 +#define NPE_RESETSTATS 0x05
146 +#define NPE_SETMAXFRAMELENGTHS 0x06
147 +#define NPE_VLAN_SETRXTAGMODE 0x07
148 +#define NPE_VLAN_SETDEFAULTRXVID 0x08
149 +#define NPE_VLAN_SETPORTVLANTABLEENTRY 0x09
150 +#define NPE_VLAN_SETPORTVLANTABLERANGE 0x0A
151 +#define NPE_VLAN_SETRXQOSENTRY 0x0B
152 +#define NPE_VLAN_SETPORTIDEXTRACTIONMODE 0x0C
153 +#define NPE_STP_SETBLOCKINGSTATE 0x0D
154 +#define NPE_FW_SETFIREWALLMODE 0x0E
155 +#define NPE_PC_SETFRAMECONTROLDURATIONID 0x0F
156 +#define NPE_PC_SETAPMACTABLE 0x11
157 +#define NPE_SETLOOPBACK_MODE 0x12
158 +#define NPE_PC_SETBSSIDTABLE 0x13
159 +#define NPE_ADDRESS_FILTER_CONFIG 0x14
160 +#define NPE_APPENDFCSCONFIG 0x15
161 +#define NPE_NOTIFY_MAC_RECOVERY_DONE 0x16
162 +#define NPE_MAC_RECOVERY_START 0x17
166 +typedef struct sk_buff buffer_t;
167 +#define free_buffer dev_kfree_skb
168 +#define free_buffer_irq dev_kfree_skb_irq
170 +typedef void buffer_t;
171 +#define free_buffer kfree
172 +#define free_buffer_irq kfree
176 + u32 tx_control[2], __res1[2]; /* 000 */
177 + u32 rx_control[2], __res2[2]; /* 010 */
178 + u32 random_seed, __res3[3]; /* 020 */
179 + u32 partial_empty_threshold, __res4; /* 030 */
180 + u32 partial_full_threshold, __res5; /* 038 */
181 + u32 tx_start_bytes, __res6[3]; /* 040 */
182 + u32 tx_deferral, rx_deferral,__res7[2]; /* 050 */
183 + u32 tx_2part_deferral[2], __res8[2]; /* 060 */
184 + u32 slot_time, __res9[3]; /* 070 */
185 + u32 mdio_command[4]; /* 080 */
186 + u32 mdio_status[4]; /* 090 */
187 + u32 mcast_mask[6], __res10[2]; /* 0A0 */
188 + u32 mcast_addr[6], __res11[2]; /* 0C0 */
189 + u32 int_clock_threshold, __res12[3]; /* 0E0 */
190 + u32 hw_addr[6], __res13[61]; /* 0F0 */
191 + u32 core_control; /* 1FC */
195 + struct resource *mem_res;
196 + struct eth_regs __iomem *regs;
198 + struct net_device *netdev;
199 + struct napi_struct napi;
200 + struct net_device_stats stat;
201 + struct mii_if_info mii;
202 + struct delayed_work mdio_thread;
203 + struct eth_plat_info *plat;
204 + buffer_t *rx_buff_tab[RX_DESCS], *tx_buff_tab[TX_DESCS];
205 + struct desc *desc_tab; /* coherent */
207 + int id; /* logical port ID */
211 +/* NPE message structure */
214 + u8 cmd, eth_id, byte2, byte3;
215 + u8 byte4, byte5, byte6, byte7;
217 + u8 byte3, byte2, eth_id, cmd;
218 + u8 byte7, byte6, byte5, byte4;
222 +/* Ethernet packet descriptor */
224 + u32 next; /* pointer to next buffer, unused */
227 + u16 buf_len; /* buffer length */
228 + u16 pkt_len; /* packet length */
229 + u32 data; /* pointer to data buffer in RAM */
237 + u16 pkt_len; /* packet length */
238 + u16 buf_len; /* buffer length */
239 + u32 data; /* pointer to data buffer in RAM */
249 + u8 dst_mac_0, dst_mac_1, dst_mac_2, dst_mac_3;
250 + u8 dst_mac_4, dst_mac_5, src_mac_0, src_mac_1;
251 + u8 src_mac_2, src_mac_3, src_mac_4, src_mac_5;
253 + u8 dst_mac_3, dst_mac_2, dst_mac_1, dst_mac_0;
254 + u8 src_mac_1, src_mac_0, dst_mac_5, dst_mac_4;
255 + u8 src_mac_5, src_mac_4, src_mac_3, src_mac_2;
260 +#define rx_desc_phys(port, n) ((port)->desc_tab_phys + \
261 + (n) * sizeof(struct desc))
262 +#define rx_desc_ptr(port, n) (&(port)->desc_tab[n])
264 +#define tx_desc_phys(port, n) ((port)->desc_tab_phys + \
265 + ((n) + RX_DESCS) * sizeof(struct desc))
266 +#define tx_desc_ptr(port, n) (&(port)->desc_tab[(n) + RX_DESCS])
269 +static inline void memcpy_swab32(u32 *dest, u32 *src, int cnt)
272 + for (i = 0; i < cnt; i++)
273 + dest[i] = swab32(src[i]);
277 +static spinlock_t mdio_lock;
278 +static struct eth_regs __iomem *mdio_regs; /* mdio command and status only */
279 +static int ports_open;
280 +static struct port *npe_port_tab[MAX_NPES];
281 +static struct dma_pool *dma_pool;
284 +static u16 mdio_cmd(struct net_device *dev, int phy_id, int location,
285 + int write, u16 cmd)
289 + if (__raw_readl(&mdio_regs->mdio_command[3]) & 0x80) {
290 + printk(KERN_ERR "%s: MII not ready to transmit\n", dev->name);
295 + __raw_writel(cmd & 0xFF, &mdio_regs->mdio_command[0]);
296 + __raw_writel(cmd >> 8, &mdio_regs->mdio_command[1]);
298 + __raw_writel(((phy_id << 5) | location) & 0xFF,
299 + &mdio_regs->mdio_command[2]);
300 + __raw_writel((phy_id >> 3) | (write << 2) | 0x80 /* GO */,
301 + &mdio_regs->mdio_command[3]);
303 + while ((cycles < MAX_MDIO_RETRIES) &&
304 + (__raw_readl(&mdio_regs->mdio_command[3]) & 0x80)) {
309 + if (cycles == MAX_MDIO_RETRIES) {
310 + printk(KERN_ERR "%s: MII write failed\n", dev->name);
315 + printk(KERN_DEBUG "%s: mdio_cmd() took %i cycles\n", dev->name,
322 + if (__raw_readl(&mdio_regs->mdio_status[3]) & 0x80) {
323 + printk(KERN_ERR "%s: MII read failed\n", dev->name);
327 + return (__raw_readl(&mdio_regs->mdio_status[0]) & 0xFF) |
328 + (__raw_readl(&mdio_regs->mdio_status[1]) << 8);
331 +static int mdio_read(struct net_device *dev, int phy_id, int location)
333 + unsigned long flags;
336 + spin_lock_irqsave(&mdio_lock, flags);
337 + val = mdio_cmd(dev, phy_id, location, 0, 0);
338 + spin_unlock_irqrestore(&mdio_lock, flags);
342 +static void mdio_write(struct net_device *dev, int phy_id, int location,
345 + unsigned long flags;
347 + spin_lock_irqsave(&mdio_lock, flags);
348 + mdio_cmd(dev, phy_id, location, 1, val);
349 + spin_unlock_irqrestore(&mdio_lock, flags);
352 +static void phy_reset(struct net_device *dev, int phy_id)
354 + struct port *port = netdev_priv(dev);
357 + mdio_write(dev, phy_id, MII_BMCR, port->mii_bmcr | BMCR_RESET);
359 + while (cycles < MAX_MII_RESET_RETRIES) {
360 + if (!(mdio_read(dev, phy_id, MII_BMCR) & BMCR_RESET)) {
362 + printk(KERN_DEBUG "%s: phy_reset() took %i cycles\n",
363 + dev->name, cycles);
371 + printk(KERN_ERR "%s: MII reset failed\n", dev->name);
374 +static void eth_set_duplex(struct port *port)
376 + if (port->mii.full_duplex)
377 + __raw_writel(DEFAULT_TX_CNTRL0 & ~TX_CNTRL0_HALFDUPLEX,
378 + &port->regs->tx_control[0]);
380 + __raw_writel(DEFAULT_TX_CNTRL0 | TX_CNTRL0_HALFDUPLEX,
381 + &port->regs->tx_control[0]);
385 +static void phy_check_media(struct port *port, int init)
387 + if (mii_check_media(&port->mii, 1, init))
388 + eth_set_duplex(port);
389 + if (port->mii.force_media) { /* mii_check_media() doesn't work */
390 + struct net_device *dev = port->netdev;
391 + int cur_link = mii_link_ok(&port->mii);
392 + int prev_link = netif_carrier_ok(dev);
394 + if (!prev_link && cur_link) {
395 + printk(KERN_INFO "%s: link up\n", dev->name);
396 + netif_carrier_on(dev);
397 + } else if (prev_link && !cur_link) {
398 + printk(KERN_INFO "%s: link down\n", dev->name);
399 + netif_carrier_off(dev);
405 +static void mdio_thread(struct work_struct *work)
407 + struct port *port = container_of(work, struct port, mdio_thread.work);
409 + phy_check_media(port, 0);
410 + schedule_delayed_work(&port->mdio_thread, MDIO_INTERVAL);
414 +static inline void debug_pkt(struct net_device *dev, const char *func,
420 + printk(KERN_DEBUG "%s: %s(%i) ", dev->name, func, len);
421 + for (i = 0; i < len; i++) {
422 + if (i >= DEBUG_PKT_BYTES)
425 + ((i == 6) || (i == 12) || (i >= 14)) ? " " : "",
433 +static inline void debug_desc(u32 phys, struct desc *desc)
436 + printk(KERN_DEBUG "%X: %X %3X %3X %08X %2X < %2X %4X %X"
437 + " %X %X %02X%02X%02X%02X%02X%02X < %02X%02X%02X%02X%02X%02X\n",
438 + phys, desc->next, desc->buf_len, desc->pkt_len,
439 + desc->data, desc->dest_id, desc->src_id, desc->flags,
440 + desc->qos, desc->padlen, desc->vlan_tci,
441 + desc->dst_mac_0, desc->dst_mac_1, desc->dst_mac_2,
442 + desc->dst_mac_3, desc->dst_mac_4, desc->dst_mac_5,
443 + desc->src_mac_0, desc->src_mac_1, desc->src_mac_2,
444 + desc->src_mac_3, desc->src_mac_4, desc->src_mac_5);
448 +static inline void debug_queue(unsigned int queue, int is_get, u32 phys)
455 + { TX_QUEUE(0x10), "TX#0 " },
456 + { TX_QUEUE(0x20), "TX#1 " },
457 + { TX_QUEUE(0x00), "TX#2 " },
458 + { RXFREE_QUEUE(0x10), "RX-free#0 " },
459 + { RXFREE_QUEUE(0x20), "RX-free#1 " },
460 + { RXFREE_QUEUE(0x00), "RX-free#2 " },
461 + { TXDONE_QUEUE, "TX-done " },
465 + for (i = 0; i < ARRAY_SIZE(names); i++)
466 + if (names[i].queue == queue)
469 + printk(KERN_DEBUG "Queue %i %s%s %X\n", queue,
470 + i < ARRAY_SIZE(names) ? names[i].name : "",
471 + is_get ? "->" : "<-", phys);
475 +static inline u32 queue_get_entry(unsigned int queue)
477 + u32 phys = qmgr_get_entry(queue);
478 + debug_queue(queue, 1, phys);
482 +static inline int queue_get_desc(unsigned int queue, struct port *port,
485 + u32 phys, tab_phys, n_desc;
488 + if (!(phys = queue_get_entry(queue)))
491 + phys &= ~0x1F; /* mask out non-address bits */
492 + tab_phys = is_tx ? tx_desc_phys(port, 0) : rx_desc_phys(port, 0);
493 + tab = is_tx ? tx_desc_ptr(port, 0) : rx_desc_ptr(port, 0);
494 + n_desc = (phys - tab_phys) / sizeof(struct desc);
495 + BUG_ON(n_desc >= (is_tx ? TX_DESCS : RX_DESCS));
496 + debug_desc(phys, &tab[n_desc]);
497 + BUG_ON(tab[n_desc].next);
501 +static inline void queue_put_desc(unsigned int queue, u32 phys,
504 + debug_queue(queue, 0, phys);
505 + debug_desc(phys, desc);
506 + BUG_ON(phys & 0x1F);
507 + qmgr_put_entry(queue, phys);
508 + BUG_ON(qmgr_stat_overflow(queue));
512 +static inline void dma_unmap_tx(struct port *port, struct desc *desc)
515 + dma_unmap_single(&port->netdev->dev, desc->data,
516 + desc->buf_len, DMA_TO_DEVICE);
518 + dma_unmap_single(&port->netdev->dev, desc->data & ~3,
519 + ALIGN((desc->data & 3) + desc->buf_len, 4),
525 +static void eth_rx_irq(void *pdev)
527 + struct net_device *dev = pdev;
528 + struct port *port = netdev_priv(dev);
531 + printk(KERN_DEBUG "%s: eth_rx_irq\n", dev->name);
533 + qmgr_disable_irq(port->plat->rxq);
534 + netif_rx_schedule(dev, &port->napi);
537 +static int eth_poll(struct napi_struct *napi, int budget)
539 + struct port *port = container_of(napi, struct port, napi);
540 + struct net_device *dev = port->netdev;
541 + unsigned int rxq = port->plat->rxq, rxfreeq = RXFREE_QUEUE(port->id);
545 + printk(KERN_DEBUG "%s: eth_poll\n", dev->name);
548 + while (received < budget) {
549 + struct sk_buff *skb;
553 + struct sk_buff *temp;
557 + if ((n = queue_get_desc(rxq, port, 0)) < 0) {
558 + received = 0; /* No packet received */
560 + printk(KERN_DEBUG "%s: eth_poll netif_rx_complete\n",
563 + netif_rx_complete(dev, &port->napi);
564 + qmgr_enable_irq(rxq);
565 + if (!qmgr_stat_empty(rxq) &&
566 + netif_rx_reschedule(dev, &port->napi)) {
568 + printk(KERN_DEBUG "%s: eth_poll"
569 + " netif_rx_reschedule successed\n",
572 + qmgr_disable_irq(rxq);
576 + printk(KERN_DEBUG "%s: eth_poll all done\n",
579 + return 0; /* all work done */
582 + desc = rx_desc_ptr(port, n);
585 + if ((skb = netdev_alloc_skb(dev, MAX_MRU)) != NULL) {
586 + phys = dma_map_single(&dev->dev, skb->data,
587 + MAX_MRU, DMA_FROM_DEVICE);
588 + if (dma_mapping_error(phys)) {
589 + dev_kfree_skb(skb);
594 + skb = netdev_alloc_skb(dev, desc->pkt_len);
598 + port->stat.rx_dropped++;
599 + /* put the desc back on RX-ready queue */
600 + desc->buf_len = MAX_MRU;
602 + queue_put_desc(rxfreeq, rx_desc_phys(port, n), desc);
606 + /* process received frame */
609 + skb = port->rx_buff_tab[n];
610 + dma_unmap_single(&dev->dev, desc->data,
611 + MAX_MRU, DMA_FROM_DEVICE);
613 + dma_sync_single(&dev->dev, desc->data,
614 + MAX_MRU, DMA_FROM_DEVICE);
615 + memcpy_swab32((u32 *)skb->data, (u32 *)port->rx_buff_tab[n],
616 + ALIGN(desc->pkt_len, 4) / 4);
618 + skb_put(skb, desc->pkt_len);
620 + debug_pkt(dev, "eth_poll", skb->data, skb->len);
622 + skb->protocol = eth_type_trans(skb, dev);
623 + dev->last_rx = jiffies;
624 + port->stat.rx_packets++;
625 + port->stat.rx_bytes += skb->len;
626 + netif_receive_skb(skb);
628 + /* put the new buffer on RX-free queue */
630 + port->rx_buff_tab[n] = temp;
633 + desc->buf_len = MAX_MRU;
635 + queue_put_desc(rxfreeq, rx_desc_phys(port, n), desc);
640 + printk(KERN_DEBUG "eth_poll(): end, not all work done\n");
642 + return received; /* not all work done */
646 +static void eth_txdone_irq(void *unused)
651 + printk(KERN_DEBUG DRV_NAME ": eth_txdone_irq\n");
653 + while ((phys = queue_get_entry(TXDONE_QUEUE)) != 0) {
654 + u32 npe_id, n_desc;
660 + BUG_ON(npe_id >= MAX_NPES);
661 + port = npe_port_tab[npe_id];
663 + phys &= ~0x1F; /* mask out non-address bits */
664 + n_desc = (phys - tx_desc_phys(port, 0)) / sizeof(struct desc);
665 + BUG_ON(n_desc >= TX_DESCS);
666 + desc = tx_desc_ptr(port, n_desc);
667 + debug_desc(phys, desc);
669 + if (port->tx_buff_tab[n_desc]) { /* not the draining packet */
670 + port->stat.tx_packets++;
671 + port->stat.tx_bytes += desc->pkt_len;
673 + dma_unmap_tx(port, desc);
675 + printk(KERN_DEBUG "%s: eth_txdone_irq free %p\n",
676 + port->netdev->name, port->tx_buff_tab[n_desc]);
678 + free_buffer_irq(port->tx_buff_tab[n_desc]);
679 + port->tx_buff_tab[n_desc] = NULL;
682 + start = qmgr_stat_empty(port->plat->txreadyq);
683 + queue_put_desc(port->plat->txreadyq, phys, desc);
686 + printk(KERN_DEBUG "%s: eth_txdone_irq xmit ready\n",
687 + port->netdev->name);
689 + netif_wake_queue(port->netdev);
694 +static int eth_xmit(struct sk_buff *skb, struct net_device *dev)
696 + struct port *port = netdev_priv(dev);
697 + unsigned int txreadyq = port->plat->txreadyq;
698 + int len, offset, bytes, n;
704 + printk(KERN_DEBUG "%s: eth_xmit\n", dev->name);
707 + if (unlikely(skb->len > MAX_MRU)) {
708 + dev_kfree_skb(skb);
709 + port->stat.tx_errors++;
710 + return NETDEV_TX_OK;
713 + debug_pkt(dev, "eth_xmit", skb->data, skb->len);
717 + offset = 0; /* no need to keep alignment */
721 + offset = (int)skb->data & 3; /* keep 32-bit alignment */
722 + bytes = ALIGN(offset + len, 4);
723 + if (!(mem = kmalloc(bytes, GFP_ATOMIC))) {
724 + dev_kfree_skb(skb);
725 + port->stat.tx_dropped++;
726 + return NETDEV_TX_OK;
728 + memcpy_swab32(mem, (u32 *)((int)skb->data & ~3), bytes / 4);
729 + dev_kfree_skb(skb);
732 + phys = dma_map_single(&dev->dev, mem, bytes, DMA_TO_DEVICE);
733 + if (dma_mapping_error(phys)) {
735 + dev_kfree_skb(skb);
739 + port->stat.tx_dropped++;
740 + return NETDEV_TX_OK;
743 + n = queue_get_desc(txreadyq, port, 1);
745 + desc = tx_desc_ptr(port, n);
748 + port->tx_buff_tab[n] = skb;
750 + port->tx_buff_tab[n] = mem;
752 + desc->data = phys + offset;
753 + desc->buf_len = desc->pkt_len = len;
755 + /* NPE firmware pads short frames with zeros internally */
757 + queue_put_desc(TX_QUEUE(port->id), tx_desc_phys(port, n), desc);
758 + dev->trans_start = jiffies;
760 + if (qmgr_stat_empty(txreadyq)) {
762 + printk(KERN_DEBUG "%s: eth_xmit queue full\n", dev->name);
764 + netif_stop_queue(dev);
765 + /* we could miss TX ready interrupt */
766 + if (!qmgr_stat_empty(txreadyq)) {
768 + printk(KERN_DEBUG "%s: eth_xmit ready again\n",
771 + netif_wake_queue(dev);
776 + printk(KERN_DEBUG "%s: eth_xmit end\n", dev->name);
778 + return NETDEV_TX_OK;
782 +static struct net_device_stats *eth_stats(struct net_device *dev)
784 + struct port *port = netdev_priv(dev);
785 + return &port->stat;
788 +static void eth_set_mcast_list(struct net_device *dev)
790 + struct port *port = netdev_priv(dev);
791 + struct dev_mc_list *mclist = dev->mc_list;
792 + u8 diffs[ETH_ALEN], *addr;
793 + int cnt = dev->mc_count, i;
795 + if ((dev->flags & IFF_PROMISC) || !mclist || !cnt) {
796 + __raw_writel(DEFAULT_RX_CNTRL0 & ~RX_CNTRL0_ADDR_FLTR_EN,
797 + &port->regs->rx_control[0]);
801 + memset(diffs, 0, ETH_ALEN);
802 + addr = mclist->dmi_addr; /* first MAC address */
804 + while (--cnt && (mclist = mclist->next))
805 + for (i = 0; i < ETH_ALEN; i++)
806 + diffs[i] |= addr[i] ^ mclist->dmi_addr[i];
808 + for (i = 0; i < ETH_ALEN; i++) {
809 + __raw_writel(addr[i], &port->regs->mcast_addr[i]);
810 + __raw_writel(~diffs[i], &port->regs->mcast_mask[i]);
813 + __raw_writel(DEFAULT_RX_CNTRL0 | RX_CNTRL0_ADDR_FLTR_EN,
814 + &port->regs->rx_control[0]);
818 +static int eth_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
820 + struct port *port = netdev_priv(dev);
821 + unsigned int duplex_chg;
824 + if (!netif_running(dev))
826 + err = generic_mii_ioctl(&port->mii, if_mii(req), cmd, &duplex_chg);
828 + eth_set_duplex(port);
833 +static int request_queues(struct port *port)
837 + err = qmgr_request_queue(RXFREE_QUEUE(port->id), RX_DESCS, 0, 0);
841 + err = qmgr_request_queue(port->plat->rxq, RX_DESCS, 0, 0);
845 + err = qmgr_request_queue(TX_QUEUE(port->id), TX_DESCS, 0, 0);
849 + err = qmgr_request_queue(port->plat->txreadyq, TX_DESCS, 0, 0);
853 + /* TX-done queue handles skbs sent out by the NPEs */
855 + err = qmgr_request_queue(TXDONE_QUEUE, TXDONE_QUEUE_LEN, 0, 0);
862 + qmgr_release_queue(port->plat->txreadyq);
864 + qmgr_release_queue(TX_QUEUE(port->id));
866 + qmgr_release_queue(port->plat->rxq);
868 + qmgr_release_queue(RXFREE_QUEUE(port->id));
869 + printk(KERN_DEBUG "%s: unable to request hardware queues\n",
870 + port->netdev->name);
874 +static void release_queues(struct port *port)
876 + qmgr_release_queue(RXFREE_QUEUE(port->id));
877 + qmgr_release_queue(port->plat->rxq);
878 + qmgr_release_queue(TX_QUEUE(port->id));
879 + qmgr_release_queue(port->plat->txreadyq);
882 + qmgr_release_queue(TXDONE_QUEUE);
885 +static int init_queues(struct port *port)
890 + if (!(dma_pool = dma_pool_create(DRV_NAME, NULL,
891 + POOL_ALLOC_SIZE, 32, 0)))
894 + if (!(port->desc_tab = dma_pool_alloc(dma_pool, GFP_KERNEL,
895 + &port->desc_tab_phys)))
897 + memset(port->desc_tab, 0, POOL_ALLOC_SIZE);
898 + memset(port->rx_buff_tab, 0, sizeof(port->rx_buff_tab)); /* tables */
899 + memset(port->tx_buff_tab, 0, sizeof(port->tx_buff_tab));
901 + /* Setup RX buffers */
902 + for (i = 0; i < RX_DESCS; i++) {
903 + struct desc *desc = rx_desc_ptr(port, i);
907 + if (!(buff = netdev_alloc_skb(port->netdev, MAX_MRU)))
911 + if (!(buff = kmalloc(MAX_MRU, GFP_KERNEL)))
915 + desc->buf_len = MAX_MRU;
916 + desc->data = dma_map_single(&port->netdev->dev, data,
917 + MAX_MRU, DMA_FROM_DEVICE);
918 + if (dma_mapping_error(desc->data)) {
922 + port->rx_buff_tab[i] = buff;
928 +static void destroy_queues(struct port *port)
932 + if (port->desc_tab) {
933 + for (i = 0; i < RX_DESCS; i++) {
934 + struct desc *desc = rx_desc_ptr(port, i);
935 + buffer_t *buff = port->rx_buff_tab[i];
937 + dma_unmap_single(&port->netdev->dev,
938 + desc->data, MAX_MRU,
943 + for (i = 0; i < TX_DESCS; i++) {
944 + struct desc *desc = tx_desc_ptr(port, i);
945 + buffer_t *buff = port->tx_buff_tab[i];
947 + dma_unmap_tx(port, desc);
951 + dma_pool_free(dma_pool, port->desc_tab, port->desc_tab_phys);
952 + port->desc_tab = NULL;
955 + if (!ports_open && dma_pool) {
956 + dma_pool_destroy(dma_pool);
961 +static int eth_open(struct net_device *dev)
963 + struct port *port = netdev_priv(dev);
964 + struct npe *npe = port->npe;
968 + if (!npe_running(npe)) {
969 + err = npe_load_firmware(npe, npe_name(npe), &dev->dev);
973 + if (npe_recv_message(npe, &msg, "ETH_GET_STATUS")) {
974 + printk(KERN_ERR "%s: %s not responding\n", dev->name,
980 + mdio_write(dev, port->plat->phy, MII_BMCR, port->mii_bmcr);
982 + memset(&msg, 0, sizeof(msg));
983 + msg.cmd = NPE_VLAN_SETRXQOSENTRY;
984 + msg.eth_id = port->id;
985 + msg.byte5 = port->plat->rxq | 0x80;
986 + msg.byte7 = port->plat->rxq << 4;
987 + for (i = 0; i < 8; i++) {
989 + if (npe_send_recv_message(port->npe, &msg, "ETH_SET_RXQ"))
993 + msg.cmd = NPE_EDB_SETPORTADDRESS;
994 + msg.eth_id = PHYSICAL_ID(port->id);
995 + msg.byte2 = dev->dev_addr[0];
996 + msg.byte3 = dev->dev_addr[1];
997 + msg.byte4 = dev->dev_addr[2];
998 + msg.byte5 = dev->dev_addr[3];
999 + msg.byte6 = dev->dev_addr[4];
1000 + msg.byte7 = dev->dev_addr[5];
1001 + if (npe_send_recv_message(port->npe, &msg, "ETH_SET_MAC"))
1004 + memset(&msg, 0, sizeof(msg));
1005 + msg.cmd = NPE_FW_SETFIREWALLMODE;
1006 + msg.eth_id = port->id;
1007 + if (npe_send_recv_message(port->npe, &msg, "ETH_SET_FIREWALL_MODE"))
1010 + if ((err = request_queues(port)) != 0)
1013 + if ((err = init_queues(port)) != 0) {
1014 + destroy_queues(port);
1015 + release_queues(port);
1019 + for (i = 0; i < ETH_ALEN; i++)
1020 + __raw_writel(dev->dev_addr[i], &port->regs->hw_addr[i]);
1021 + __raw_writel(0x08, &port->regs->random_seed);
1022 + __raw_writel(0x12, &port->regs->partial_empty_threshold);
1023 + __raw_writel(0x30, &port->regs->partial_full_threshold);
1024 + __raw_writel(0x08, &port->regs->tx_start_bytes);
1025 + __raw_writel(0x15, &port->regs->tx_deferral);
1026 + __raw_writel(0x08, &port->regs->tx_2part_deferral[0]);
1027 + __raw_writel(0x07, &port->regs->tx_2part_deferral[1]);
1028 + __raw_writel(0x80, &port->regs->slot_time);
1029 + __raw_writel(0x01, &port->regs->int_clock_threshold);
1031 + /* Populate queues with buffers, no failure after this point */
1032 + for (i = 0; i < TX_DESCS; i++)
1033 + queue_put_desc(port->plat->txreadyq,
1034 + tx_desc_phys(port, i), tx_desc_ptr(port, i));
1036 + for (i = 0; i < RX_DESCS; i++)
1037 + queue_put_desc(RXFREE_QUEUE(port->id),
1038 + rx_desc_phys(port, i), rx_desc_ptr(port, i));
1040 + __raw_writel(TX_CNTRL1_RETRIES, &port->regs->tx_control[1]);
1041 + __raw_writel(DEFAULT_TX_CNTRL0, &port->regs->tx_control[0]);
1042 + __raw_writel(0, &port->regs->rx_control[1]);
1043 + __raw_writel(DEFAULT_RX_CNTRL0, &port->regs->rx_control[0]);
1045 + napi_enable(&port->napi); /* check location of this call */
1047 + phy_check_media(port, 1);
1048 + eth_set_mcast_list(dev);
1049 + netif_start_queue(dev);
1050 + schedule_delayed_work(&port->mdio_thread, MDIO_INTERVAL);
1052 + qmgr_set_irq(port->plat->rxq, QUEUE_IRQ_SRC_NOT_EMPTY,
1054 + if (!ports_open) {
1055 + qmgr_set_irq(TXDONE_QUEUE, QUEUE_IRQ_SRC_NOT_EMPTY,
1056 + eth_txdone_irq, NULL);
1057 + qmgr_enable_irq(TXDONE_QUEUE);
1060 + netif_rx_schedule(dev, &port->napi); /* we may already have RX data, enables IRQ */
1064 +static int eth_close(struct net_device *dev)
1066 + struct port *port = netdev_priv(dev);
1068 + int buffs = RX_DESCS; /* allocated RX buffers */
1072 + qmgr_disable_irq(port->plat->rxq);
1073 + netif_stop_queue(dev);
1075 + while (queue_get_desc(RXFREE_QUEUE(port->id), port, 0) >= 0)
1078 + memset(&msg, 0, sizeof(msg));
1079 + msg.cmd = NPE_SETLOOPBACK_MODE;
1080 + msg.eth_id = port->id;
1082 + if (npe_send_recv_message(port->npe, &msg, "ETH_ENABLE_LOOPBACK"))
1083 + printk(KERN_CRIT "%s: unable to enable loopback\n", dev->name);
1086 + do { /* drain RX buffers */
1087 + while (queue_get_desc(port->plat->rxq, port, 0) >= 0)
1091 + if (qmgr_stat_empty(TX_QUEUE(port->id))) {
1092 + /* we have to inject some packet */
1093 + struct desc *desc;
1095 + int n = queue_get_desc(port->plat->txreadyq, port, 1);
1097 + desc = tx_desc_ptr(port, n);
1098 + phys = tx_desc_phys(port, n);
1099 + desc->buf_len = desc->pkt_len = 1;
1101 + queue_put_desc(TX_QUEUE(port->id), phys, desc);
1104 + } while (++i < MAX_CLOSE_WAIT);
1107 + printk(KERN_CRIT "%s: unable to drain RX queue, %i buffer(s)"
1108 + " left in NPE\n", dev->name, buffs);
1111 + printk(KERN_DEBUG "Draining RX queue took %i cycles\n", i);
1115 + while (queue_get_desc(TX_QUEUE(port->id), port, 1) >= 0)
1116 + buffs--; /* cancel TX */
1120 + while (queue_get_desc(port->plat->txreadyq, port, 1) >= 0)
1124 + } while (++i < MAX_CLOSE_WAIT);
1127 + printk(KERN_CRIT "%s: unable to drain TX queue, %i buffer(s) "
1128 + "left in NPE\n", dev->name, buffs);
1131 + printk(KERN_DEBUG "Draining TX queues took %i cycles\n", i);
1135 + if (npe_send_recv_message(port->npe, &msg, "ETH_DISABLE_LOOPBACK"))
1136 + printk(KERN_CRIT "%s: unable to disable loopback\n",
1139 + port->mii_bmcr = mdio_read(dev, port->plat->phy, MII_BMCR) &
1140 + ~(BMCR_RESET | BMCR_PDOWN); /* may have been altered */
1141 + mdio_write(dev, port->plat->phy, MII_BMCR,
1142 + port->mii_bmcr | BMCR_PDOWN);
1145 + qmgr_disable_irq(TXDONE_QUEUE);
1146 + cancel_rearming_delayed_work(&port->mdio_thread);
1147 + napi_disable(&port->napi);
1148 + destroy_queues(port);
1149 + release_queues(port);
1153 +static int __devinit eth_init_one(struct platform_device *pdev)
1155 + struct port *port;
1156 + struct net_device *dev;
1157 + struct eth_plat_info *plat = pdev->dev.platform_data;
1161 + if (!(dev = alloc_etherdev(sizeof(struct port))))
1164 + SET_NETDEV_DEV(dev, &pdev->dev);
1165 + port = netdev_priv(dev);
1166 + port->netdev = dev;
1167 + port->id = pdev->id;
1169 + switch (port->id) {
1170 + case IXP4XX_ETH_NPEA:
1171 + port->regs = (struct eth_regs __iomem *)IXP4XX_EthA_BASE_VIRT;
1172 + regs_phys = IXP4XX_EthA_BASE_PHYS;
1174 + case IXP4XX_ETH_NPEB:
1175 + port->regs = (struct eth_regs __iomem *)IXP4XX_EthB_BASE_VIRT;
1176 + regs_phys = IXP4XX_EthB_BASE_PHYS;
1178 + case IXP4XX_ETH_NPEC:
1179 + port->regs = (struct eth_regs __iomem *)IXP4XX_EthC_BASE_VIRT;
1180 + regs_phys = IXP4XX_EthC_BASE_PHYS;
1187 + dev->open = eth_open;
1188 + dev->hard_start_xmit = eth_xmit;
1189 + dev->stop = eth_close;
1190 + dev->get_stats = eth_stats;
1191 + dev->do_ioctl = eth_ioctl;
1192 + dev->set_multicast_list = eth_set_mcast_list;
1193 + dev->tx_queue_len = 100;
1195 + netif_napi_add(dev, &port->napi, eth_poll, ETH_NAPI_WEIGHT);
1197 + if (!(port->npe = npe_request(NPE_ID(port->id)))) {
1202 + if (register_netdev(dev)) {
1207 + port->mem_res = request_mem_region(regs_phys, REGS_SIZE, dev->name);
1208 + if (!port->mem_res) {
1213 + port->plat = plat;
1214 + npe_port_tab[NPE_ID(port->id)] = port;
1215 + memcpy(dev->dev_addr, plat->hwaddr, ETH_ALEN);
1217 + platform_set_drvdata(pdev, dev);
1219 + __raw_writel(DEFAULT_CORE_CNTRL | CORE_RESET,
1220 + &port->regs->core_control);
1222 + __raw_writel(DEFAULT_CORE_CNTRL, &port->regs->core_control);
1225 + port->mii.dev = dev;
1226 + port->mii.mdio_read = mdio_read;
1227 + port->mii.mdio_write = mdio_write;
1228 + port->mii.phy_id = plat->phy;
1229 + port->mii.phy_id_mask = 0x1F;
1230 + port->mii.reg_num_mask = 0x1F;
1232 + printk(KERN_INFO "%s: MII PHY %i on %s\n", dev->name, plat->phy,
1233 + npe_name(port->npe));
1235 + phy_reset(dev, plat->phy);
1236 + port->mii_bmcr = mdio_read(dev, plat->phy, MII_BMCR) &
1237 + ~(BMCR_RESET | BMCR_PDOWN);
1238 + mdio_write(dev, plat->phy, MII_BMCR, port->mii_bmcr | BMCR_PDOWN);
1240 + INIT_DELAYED_WORK(&port->mdio_thread, mdio_thread);
1244 + unregister_netdev(dev);
1246 + npe_release(port->npe);
1252 +static int __devexit eth_remove_one(struct platform_device *pdev)
1254 + struct net_device *dev = platform_get_drvdata(pdev);
1255 + struct port *port = netdev_priv(dev);
1257 + unregister_netdev(dev);
1258 + npe_port_tab[NPE_ID(port->id)] = NULL;
1259 + platform_set_drvdata(pdev, NULL);
1260 + npe_release(port->npe);
1261 + release_resource(port->mem_res);
1266 +static struct platform_driver drv = {
1267 + .driver.name = DRV_NAME,
1268 + .probe = eth_init_one,
1269 + .remove = eth_remove_one,
1272 +static int __init eth_init_module(void)
1274 + if (!(ixp4xx_read_feature_bits() & IXP4XX_FEATURE_NPEB_ETH0))
1277 + /* All MII PHY accesses use NPE-B Ethernet registers */
1278 + spin_lock_init(&mdio_lock);
1279 + mdio_regs = (struct eth_regs __iomem *)IXP4XX_EthB_BASE_VIRT;
1280 + __raw_writel(DEFAULT_CORE_CNTRL, &mdio_regs->core_control);
1282 + return platform_driver_register(&drv);
1285 +static void __exit eth_cleanup_module(void)
1287 + platform_driver_unregister(&drv);
1290 +MODULE_AUTHOR("Krzysztof Halasa");
1291 +MODULE_DESCRIPTION("Intel IXP4xx Ethernet driver");
1292 +MODULE_LICENSE("GPL v2");
1293 +module_init(eth_init_module);
1294 +module_exit(eth_cleanup_module);
1295 diff --git a/drivers/net/wan/Kconfig b/drivers/net/wan/Kconfig
1296 index a3df09e..94e7aa7 100644
1297 --- a/drivers/net/wan/Kconfig
1298 +++ b/drivers/net/wan/Kconfig
1299 @@ -334,6 +334,15 @@ config DSCC4_PCI_RST
1301 Say Y if your card supports this feature.
1304 + tristate "IXP4xx HSS (synchronous serial port) support"
1305 + depends on HDLC && ARM && ARCH_IXP4XX
1307 + select IXP4XX_QMGR
1309 + Say Y here if you want to use built-in HSS ports
1310 + on IXP4xx processor.
1313 tristate "Frame Relay DLCI support"
1315 diff --git a/drivers/net/wan/Makefile b/drivers/net/wan/Makefile
1316 index d61fef3..1b1d116 100644
1317 --- a/drivers/net/wan/Makefile
1318 +++ b/drivers/net/wan/Makefile
1319 @@ -42,6 +42,7 @@ obj-$(CONFIG_C101) += c101.o
1320 obj-$(CONFIG_WANXL) += wanxl.o
1321 obj-$(CONFIG_PCI200SYN) += pci200syn.o
1322 obj-$(CONFIG_PC300TOO) += pc300too.o
1323 +obj-$(CONFIG_IXP4XX_HSS) += ixp4xx_hss.o
1325 clean-files := wanxlfw.inc
1326 $(obj)/wanxl.o: $(obj)/wanxlfw.inc
1327 diff --git a/drivers/net/wan/ixp4xx_hss.c b/drivers/net/wan/ixp4xx_hss.c
1328 new file mode 100644
1329 index 0000000..c4cdace
1331 +++ b/drivers/net/wan/ixp4xx_hss.c
1334 + * Intel IXP4xx HSS (synchronous serial port) driver for Linux
1336 + * Copyright (C) 2007 Krzysztof Halasa <khc@pm.waw.pl>
1338 + * This program is free software; you can redistribute it and/or modify it
1339 + * under the terms of version 2 of the GNU General Public License
1340 + * as published by the Free Software Foundation.
1343 +#include <linux/dma-mapping.h>
1344 +#include <linux/dmapool.h>
1345 +#include <linux/io.h>
1346 +#include <linux/kernel.h>
1347 +#include <linux/hdlc.h>
1348 +#include <linux/platform_device.h>
1349 +#include <asm/arch/npe.h>
1350 +#include <asm/arch/qmgr.h>
1352 +#define DEBUG_QUEUES 0
1353 +#define DEBUG_DESC 0
1356 +#define DEBUG_PKT_BYTES 0
1357 +#define DEBUG_CLOSE 0
1359 +#define DRV_NAME "ixp4xx_hss"
1361 +#define PKT_EXTRA_FLAGS 0 /* orig 1 */
1362 +#define FRAME_SYNC_OFFSET 0 /* unused, channelized only */
1363 +#define FRAME_SYNC_SIZE 1024
1364 +#define PKT_NUM_PIPES 1 /* 1, 2 or 4 */
1365 +#define PKT_PIPE_FIFO_SIZEW 4 /* total 4 dwords per HSS */
1367 +#define RX_DESCS 16 /* also length of all RX queues */
1368 +#define TX_DESCS 16 /* also length of all TX queues */
1370 +#define POOL_ALLOC_SIZE (sizeof(struct desc) * (RX_DESCS + TX_DESCS))
1371 +#define RX_SIZE (HDLC_MAX_MRU + 4) /* NPE needs more space */
1372 +#define MAX_CLOSE_WAIT 1000 /* microseconds */
1375 +#define HSS0_CHL_RXTRIG_QUEUE 12 /* orig size = 32 dwords */
1376 +#define HSS0_PKT_RX_QUEUE 13 /* orig size = 32 dwords */
1377 +#define HSS0_PKT_TX0_QUEUE 14 /* orig size = 16 dwords */
1378 +#define HSS0_PKT_TX1_QUEUE 15
1379 +#define HSS0_PKT_TX2_QUEUE 16
1380 +#define HSS0_PKT_TX3_QUEUE 17
1381 +#define HSS0_PKT_RXFREE0_QUEUE 18 /* orig size = 16 dwords */
1382 +#define HSS0_PKT_RXFREE1_QUEUE 19
1383 +#define HSS0_PKT_RXFREE2_QUEUE 20
1384 +#define HSS0_PKT_RXFREE3_QUEUE 21
1385 +#define HSS0_PKT_TXDONE_QUEUE 22 /* orig size = 64 dwords */
1387 +#define HSS1_CHL_RXTRIG_QUEUE 10
1388 +#define HSS1_PKT_RX_QUEUE 0
1389 +#define HSS1_PKT_TX0_QUEUE 5
1390 +#define HSS1_PKT_TX1_QUEUE 6
1391 +#define HSS1_PKT_TX2_QUEUE 7
1392 +#define HSS1_PKT_TX3_QUEUE 8
1393 +#define HSS1_PKT_RXFREE0_QUEUE 1
1394 +#define HSS1_PKT_RXFREE1_QUEUE 2
1395 +#define HSS1_PKT_RXFREE2_QUEUE 3
1396 +#define HSS1_PKT_RXFREE3_QUEUE 4
1397 +#define HSS1_PKT_TXDONE_QUEUE 9
1399 +#define NPE_PKT_MODE_HDLC 0
1400 +#define NPE_PKT_MODE_RAW 1
1401 +#define NPE_PKT_MODE_56KMODE 2
1402 +#define NPE_PKT_MODE_56KENDIAN_MSB 4
1404 +/* PKT_PIPE_HDLC_CFG_WRITE flags */
1405 +#define PKT_HDLC_IDLE_ONES 0x1 /* default = flags */
1406 +#define PKT_HDLC_CRC_32 0x2 /* default = CRC-16 */
1407 +#define PKT_HDLC_MSB_ENDIAN 0x4 /* default = LE */
1410 +/* hss_config, PCRs */
1411 +/* Frame sync sampling, default = active low */
1412 +#define PCR_FRM_SYNC_ACTIVE_HIGH 0x40000000
1413 +#define PCR_FRM_SYNC_FALLINGEDGE 0x80000000
1414 +#define PCR_FRM_SYNC_RISINGEDGE 0xC0000000
1416 +/* Frame sync pin: input (default) or output generated off a given clk edge */
1417 +#define PCR_FRM_SYNC_OUTPUT_FALLING 0x20000000
1418 +#define PCR_FRM_SYNC_OUTPUT_RISING 0x30000000
1420 +/* Frame and data clock sampling on edge, default = falling */
1421 +#define PCR_FCLK_EDGE_RISING 0x08000000
1422 +#define PCR_DCLK_EDGE_RISING 0x04000000
1424 +/* Clock direction, default = input */
1425 +#define PCR_SYNC_CLK_DIR_OUTPUT 0x02000000
1427 +/* Generate/Receive frame pulses, default = enabled */
1428 +#define PCR_FRM_PULSE_DISABLED 0x01000000
1430 + /* Data rate is full (default) or half the configured clk speed */
1431 +#define PCR_HALF_CLK_RATE 0x00200000
1433 +/* Invert data between NPE and HSS FIFOs? (default = no) */
1434 +#define PCR_DATA_POLARITY_INVERT 0x00100000
1436 +/* TX/RX endianness, default = LSB */
1437 +#define PCR_MSB_ENDIAN 0x00080000
1439 +/* Normal (default) / open drain mode (TX only) */
1440 +#define PCR_TX_PINS_OPEN_DRAIN 0x00040000
1442 +/* No framing bit transmitted and expected on RX? (default = framing bit) */
1443 +#define PCR_SOF_NO_FBIT 0x00020000
1445 +/* Drive data pins? */
1446 +#define PCR_TX_DATA_ENABLE 0x00010000
1448 +/* Voice 56k type: drive the data pins low (default), high, high Z */
1449 +#define PCR_TX_V56K_HIGH 0x00002000
1450 +#define PCR_TX_V56K_HIGH_IMP 0x00004000
1452 +/* Unassigned type: drive the data pins low (default), high, high Z */
1453 +#define PCR_TX_UNASS_HIGH 0x00000800
1454 +#define PCR_TX_UNASS_HIGH_IMP 0x00001000
1456 +/* T1 @ 1.544MHz only: Fbit dictated in FIFO (default) or high Z */
1457 +#define PCR_TX_FB_HIGH_IMP 0x00000400
1459 +/* 56k data endiannes - which bit unused: high (default) or low */
1460 +#define PCR_TX_56KE_BIT_0_UNUSED 0x00000200
1462 +/* 56k data transmission type: 32/8 bit data (default) or 56K data */
1463 +#define PCR_TX_56KS_56K_DATA 0x00000100
1465 +/* hss_config, cCR */
1466 +/* Number of packetized clients, default = 1 */
1467 +#define CCR_NPE_HFIFO_2_HDLC 0x04000000
1468 +#define CCR_NPE_HFIFO_3_OR_4HDLC 0x08000000
1470 +/* default = no loopback */
1471 +#define CCR_LOOPBACK 0x02000000
1473 +/* HSS number, default = 0 (first) */
1474 +#define CCR_SECOND_HSS 0x01000000
1477 +/* hss_config, clkCR: main:10, num:10, denom:12 */
1478 +#define CLK42X_SPEED_EXP ((0x3FF << 22) | ( 2 << 12) | 15) /*65 KHz*/
1480 +#define CLK42X_SPEED_512KHZ (( 130 << 22) | ( 2 << 12) | 15)
1481 +#define CLK42X_SPEED_1536KHZ (( 43 << 22) | ( 18 << 12) | 47)
1482 +#define CLK42X_SPEED_1544KHZ (( 43 << 22) | ( 33 << 12) | 192)
1483 +#define CLK42X_SPEED_2048KHZ (( 32 << 22) | ( 34 << 12) | 63)
1484 +#define CLK42X_SPEED_4096KHZ (( 16 << 22) | ( 34 << 12) | 127)
1485 +#define CLK42X_SPEED_8192KHZ (( 8 << 22) | ( 34 << 12) | 255)
1487 +#define CLK46X_SPEED_512KHZ (( 130 << 22) | ( 24 << 12) | 127)
1488 +#define CLK46X_SPEED_1536KHZ (( 43 << 22) | (152 << 12) | 383)
1489 +#define CLK46X_SPEED_1544KHZ (( 43 << 22) | ( 66 << 12) | 385)
1490 +#define CLK46X_SPEED_2048KHZ (( 32 << 22) | (280 << 12) | 511)
1491 +#define CLK46X_SPEED_4096KHZ (( 16 << 22) | (280 << 12) | 1023)
1492 +#define CLK46X_SPEED_8192KHZ (( 8 << 22) | (280 << 12) | 2047)
1495 +/* hss_config, LUT entries */
1496 +#define TDMMAP_UNASSIGNED 0
1497 +#define TDMMAP_HDLC 1 /* HDLC - packetized */
1498 +#define TDMMAP_VOICE56K 2 /* Voice56K - 7-bit channelized */
1499 +#define TDMMAP_VOICE64K 3 /* Voice64K - 8-bit channelized */
1501 +#define TIMESLOTS 128
1504 +/* offsets into HSS config */
1505 +#define HSS_CONFIG_TX_PCR 0x00
1506 +#define HSS_CONFIG_RX_PCR 0x04
1507 +#define HSS_CONFIG_CORE_CR 0x08
1508 +#define HSS_CONFIG_CLOCK_CR 0x0C
1509 +#define HSS_CONFIG_TX_FCR 0x10
1510 +#define HSS_CONFIG_RX_FCR 0x14
1511 +#define HSS_CONFIG_TX_LUT 0x18
1512 +#define HSS_CONFIG_RX_LUT 0x38
1515 +/* NPE command codes */
1516 +/* writes the ConfigWord value to the location specified by offset */
1517 +#define PORT_CONFIG_WRITE 0x40
1519 +/* triggers the NPE to load the contents of the configuration table */
1520 +#define PORT_CONFIG_LOAD 0x41
1522 +/* triggers the NPE to return an HssErrorReadResponse message */
1523 +#define PORT_ERROR_READ 0x42
1525 +/* reset NPE internal status and enable the HssChannelized operation */
1526 +#define CHAN_FLOW_ENABLE 0x43
1527 +#define CHAN_FLOW_DISABLE 0x44
1528 +#define CHAN_IDLE_PATTERN_WRITE 0x45
1529 +#define CHAN_NUM_CHANS_WRITE 0x46
1530 +#define CHAN_RX_BUF_ADDR_WRITE 0x47
1531 +#define CHAN_RX_BUF_CFG_WRITE 0x48
1532 +#define CHAN_TX_BLK_CFG_WRITE 0x49
1533 +#define CHAN_TX_BUF_ADDR_WRITE 0x4A
1534 +#define CHAN_TX_BUF_SIZE_WRITE 0x4B
1535 +#define CHAN_TSLOTSWITCH_ENABLE 0x4C
1536 +#define CHAN_TSLOTSWITCH_DISABLE 0x4D
1538 +/* downloads the gainWord value for a timeslot switching channel associated
1540 +#define CHAN_TSLOTSWITCH_GCT_DOWNLOAD 0x4E
1542 +/* triggers the NPE to reset internal status and enable the HssPacketized
1543 + operation for the flow specified by pPipe */
1544 +#define PKT_PIPE_FLOW_ENABLE 0x50
1545 +#define PKT_PIPE_FLOW_DISABLE 0x51
1546 +#define PKT_NUM_PIPES_WRITE 0x52
1547 +#define PKT_PIPE_FIFO_SIZEW_WRITE 0x53
1548 +#define PKT_PIPE_HDLC_CFG_WRITE 0x54
1549 +#define PKT_PIPE_IDLE_PATTERN_WRITE 0x55
1550 +#define PKT_PIPE_RX_SIZE_WRITE 0x56
1551 +#define PKT_PIPE_MODE_WRITE 0x57
1553 +/* HDLC packet status values - desc->status */
1554 +#define ERR_SHUTDOWN 1 /* stop or shutdown occurrance */
1555 +#define ERR_HDLC_ALIGN 2 /* HDLC alignment error */
1556 +#define ERR_HDLC_FCS 3 /* HDLC Frame Check Sum error */
1557 +#define ERR_RXFREE_Q_EMPTY 4 /* RX-free queue became empty while receiving
1558 + this packet (if buf_len < pkt_len) */
1559 +#define ERR_HDLC_TOO_LONG 5 /* HDLC frame size too long */
1560 +#define ERR_HDLC_ABORT 6 /* abort sequence received */
1561 +#define ERR_DISCONNECTING 7 /* disconnect is in progress */
1565 +typedef struct sk_buff buffer_t;
1566 +#define free_buffer dev_kfree_skb
1567 +#define free_buffer_irq dev_kfree_skb_irq
1569 +typedef void buffer_t;
1570 +#define free_buffer kfree
1571 +#define free_buffer_irq kfree
1576 + struct net_device *netdev;
1577 + struct hss_plat_info *plat;
1578 + buffer_t *rx_buff_tab[RX_DESCS], *tx_buff_tab[TX_DESCS];
1579 + struct desc *desc_tab; /* coherent */
1580 + u32 desc_tab_phys;
1582 + unsigned int clock_type, clock_rate, loopback;
1586 +/* NPE message structure */
1589 + u8 cmd, unused, hss_port, index;
1591 + struct { u8 data8a, data8b, data8c, data8d; };
1592 + struct { u16 data16a, data16b; };
1593 + struct { u32 data32; };
1596 + u8 index, hss_port, unused, cmd;
1598 + struct { u8 data8d, data8c, data8b, data8a; };
1599 + struct { u16 data16b, data16a; };
1600 + struct { u32 data32; };
1605 +/* HDLC packet descriptor */
1607 + u32 next; /* pointer to next buffer, unused */
1610 + u16 buf_len; /* buffer length */
1611 + u16 pkt_len; /* packet length */
1612 + u32 data; /* pointer to data buffer in RAM */
1617 + u16 pkt_len; /* packet length */
1618 + u16 buf_len; /* buffer length */
1619 + u32 data; /* pointer to data buffer in RAM */
1624 + u32 __reserved1[4];
1628 +#define rx_desc_phys(port, n) ((port)->desc_tab_phys + \
1629 + (n) * sizeof(struct desc))
1630 +#define rx_desc_ptr(port, n) (&(port)->desc_tab[n])
1632 +#define tx_desc_phys(port, n) ((port)->desc_tab_phys + \
1633 + ((n) + RX_DESCS) * sizeof(struct desc))
1634 +#define tx_desc_ptr(port, n) (&(port)->desc_tab[(n) + RX_DESCS])
1636 +/*****************************************************************************
1637 + * global variables
1638 + ****************************************************************************/
1640 +static int ports_open;
1641 +static struct dma_pool *dma_pool;
1643 +static const struct {
1644 + int tx, txdone, rx, rxfree;
1645 +}queue_ids[2] = {{ HSS0_PKT_TX0_QUEUE, HSS0_PKT_TXDONE_QUEUE,
1646 + HSS0_PKT_RX_QUEUE, HSS0_PKT_RXFREE0_QUEUE },
1647 + { HSS1_PKT_TX0_QUEUE, HSS1_PKT_TXDONE_QUEUE,
1648 + HSS1_PKT_RX_QUEUE, HSS1_PKT_RXFREE0_QUEUE },
1651 +/*****************************************************************************
1652 + * utility functions
1653 + ****************************************************************************/
1655 +static inline struct port* dev_to_port(struct net_device *dev)
1657 + return dev_to_hdlc(dev)->priv;
1661 +static inline void memcpy_swab32(u32 *dest, u32 *src, int cnt)
1664 + for (i = 0; i < cnt; i++)
1665 + dest[i] = swab32(src[i]);
1669 +static inline void debug_pkt(struct net_device *dev, const char *func,
1670 + u8 *data, int len)
1672 +#if DEBUG_PKT_BYTES
1675 + printk(KERN_DEBUG "%s: %s(%i) ", dev->name, func, len);
1676 + for (i = 0; i < len; i++) {
1677 + if (i >= DEBUG_PKT_BYTES)
1679 + printk("%s%02X", !(i % 4) ? " " : "", data[i]);
1686 +static inline void debug_desc(u32 phys, struct desc *desc)
1689 + printk(KERN_DEBUG "%X: %X %3X %3X %08X %X %X\n",
1690 + phys, desc->next, desc->buf_len, desc->pkt_len,
1691 + desc->data, desc->status, desc->error_count);
1695 +static inline void debug_queue(unsigned int queue, int is_get, u32 phys)
1702 + { HSS0_PKT_TX0_QUEUE, "TX#0 " },
1703 + { HSS0_PKT_TXDONE_QUEUE, "TX-done#0 " },
1704 + { HSS0_PKT_RX_QUEUE, "RX#0 " },
1705 + { HSS0_PKT_RXFREE0_QUEUE, "RX-free#0 " },
1706 + { HSS1_PKT_TX0_QUEUE, "TX#1 " },
1707 + { HSS1_PKT_TXDONE_QUEUE, "TX-done#1 " },
1708 + { HSS1_PKT_RX_QUEUE, "RX#1 " },
1709 + { HSS1_PKT_RXFREE0_QUEUE, "RX-free#1 " },
1713 + for (i = 0; i < ARRAY_SIZE(names); i++)
1714 + if (names[i].queue == queue)
1717 + printk(KERN_DEBUG "Queue %i %s%s %X\n", queue,
1718 + i < ARRAY_SIZE(names) ? names[i].name : "",
1719 + is_get ? "->" : "<-", phys);
1723 +static inline u32 queue_get_entry(unsigned int queue)
1725 + u32 phys = qmgr_get_entry(queue);
1726 + debug_queue(queue, 1, phys);
1730 +static inline int queue_get_desc(unsigned int queue, struct port *port,
1733 + u32 phys, tab_phys, n_desc;
1736 + if (!(phys = queue_get_entry(queue)))
1739 + BUG_ON(phys & 0x1F);
1740 + tab_phys = is_tx ? tx_desc_phys(port, 0) : rx_desc_phys(port, 0);
1741 + tab = is_tx ? tx_desc_ptr(port, 0) : rx_desc_ptr(port, 0);
1742 + n_desc = (phys - tab_phys) / sizeof(struct desc);
1743 + BUG_ON(n_desc >= (is_tx ? TX_DESCS : RX_DESCS));
1744 + debug_desc(phys, &tab[n_desc]);
1745 + BUG_ON(tab[n_desc].next);
1749 +static inline void queue_put_desc(unsigned int queue, u32 phys,
1750 + struct desc *desc)
1752 + debug_queue(queue, 0, phys);
1753 + debug_desc(phys, desc);
1754 + BUG_ON(phys & 0x1F);
1755 + qmgr_put_entry(queue, phys);
1756 + BUG_ON(qmgr_stat_overflow(queue));
1760 +static inline void dma_unmap_tx(struct port *port, struct desc *desc)
1763 + dma_unmap_single(&port->netdev->dev, desc->data,
1764 + desc->buf_len, DMA_TO_DEVICE);
1766 + dma_unmap_single(&port->netdev->dev, desc->data & ~3,
1767 + ALIGN((desc->data & 3) + desc->buf_len, 4),
1773 +static void hss_hdlc_set_carrier(void *pdev, int carrier)
1775 + struct net_device *dev = pdev;
1777 + netif_carrier_on(dev);
1779 + netif_carrier_off(dev);
1782 +static void hss_hdlc_rx_irq(void *pdev)
1784 + struct net_device *dev = pdev;
1785 + struct port *port = dev_to_port(dev);
1788 + printk(KERN_DEBUG "%s: hss_hdlc_rx_irq\n", dev->name);
1790 + qmgr_disable_irq(queue_ids[port->id].rx);
1791 + netif_rx_schedule(dev);
1794 +static int hss_hdlc_poll(struct net_device *dev, int *budget)
1796 + struct port *port = dev_to_port(dev);
1797 + unsigned int rxq = queue_ids[port->id].rx;
1798 + unsigned int rxfreeq = queue_ids[port->id].rxfree;
1799 + struct net_device_stats *stats = hdlc_stats(dev);
1800 + int quota = dev->quota, received = 0;
1803 + printk(KERN_DEBUG "%s: hss_hdlc_poll\n", dev->name);
1807 + struct sk_buff *skb;
1808 + struct desc *desc;
1811 + struct sk_buff *temp;
1815 + if ((n = queue_get_desc(rxq, port, 0)) < 0) {
1816 + dev->quota -= received; /* No packet received */
1817 + *budget -= received;
1820 + printk(KERN_DEBUG "%s: hss_hdlc_poll"
1821 + " netif_rx_complete\n", dev->name);
1823 + netif_rx_complete(dev);
1824 + qmgr_enable_irq(rxq);
1825 + if (!qmgr_stat_empty(rxq) &&
1826 + netif_rx_reschedule(dev, 0)) {
1828 + printk(KERN_DEBUG "%s: hss_hdlc_poll"
1829 + " netif_rx_reschedule successed\n",
1832 + qmgr_disable_irq(rxq);
1836 + printk(KERN_DEBUG "%s: hss_hdlc_poll all done\n",
1839 + return 0; /* all work done */
1842 + desc = rx_desc_ptr(port, n);
1844 + if (desc->error_count) /* FIXME - remove printk */
1845 + printk(KERN_DEBUG "%s: hss_hdlc_poll status 0x%02X"
1846 + " errors %u\n", dev->name, desc->status,
1847 + desc->error_count);
1850 + switch (desc->status) {
1853 + if ((skb = netdev_alloc_skb(dev, RX_SIZE)) != NULL) {
1854 + phys = dma_map_single(&dev->dev, skb->data,
1857 + if (dma_mapping_error(phys)) {
1858 + dev_kfree_skb(skb);
1863 + skb = netdev_alloc_skb(dev, desc->pkt_len);
1866 + stats->rx_dropped++;
1868 + case ERR_HDLC_ALIGN:
1869 + case ERR_HDLC_ABORT:
1870 + stats->rx_frame_errors++;
1871 + stats->rx_errors++;
1873 + case ERR_HDLC_FCS:
1874 + stats->rx_crc_errors++;
1875 + stats->rx_errors++;
1877 + case ERR_HDLC_TOO_LONG:
1878 + stats->rx_length_errors++;
1879 + stats->rx_errors++;
1881 + default: /* FIXME - remove printk */
1882 + printk(KERN_ERR "%s: hss_hdlc_poll: status 0x%02X"
1883 + " errors %u\n", dev->name, desc->status,
1884 + desc->error_count);
1885 + stats->rx_errors++;
1889 + /* put the desc back on RX-ready queue */
1890 + desc->buf_len = RX_SIZE;
1891 + desc->pkt_len = desc->status = 0;
1892 + queue_put_desc(rxfreeq, rx_desc_phys(port, n), desc);
1896 + /* process received frame */
1899 + skb = port->rx_buff_tab[n];
1900 + dma_unmap_single(&dev->dev, desc->data,
1901 + RX_SIZE, DMA_FROM_DEVICE);
1903 + dma_sync_single(&dev->dev, desc->data,
1904 + RX_SIZE, DMA_FROM_DEVICE);
1905 + memcpy_swab32((u32 *)skb->data, (u32 *)port->rx_buff_tab[n],
1906 + ALIGN(desc->pkt_len, 4) / 4);
1908 + skb_put(skb, desc->pkt_len);
1910 + debug_pkt(dev, "hss_hdlc_poll", skb->data, skb->len);
1912 + skb->protocol = hdlc_type_trans(skb, dev);
1913 + dev->last_rx = jiffies;
1914 + stats->rx_packets++;
1915 + stats->rx_bytes += skb->len;
1916 + netif_receive_skb(skb);
1918 + /* put the new buffer on RX-free queue */
1920 + port->rx_buff_tab[n] = temp;
1921 + desc->data = phys;
1923 + desc->buf_len = RX_SIZE;
1924 + desc->pkt_len = 0;
1925 + queue_put_desc(rxfreeq, rx_desc_phys(port, n), desc);
1929 + dev->quota -= received;
1930 + *budget -= received;
1932 + printk(KERN_DEBUG "hss_hdlc_poll: end, not all work done\n");
1934 + return 1; /* not all work done */
1938 +static void hss_hdlc_txdone_irq(void *pdev)
1940 + struct net_device *dev = pdev;
1941 + struct port *port = dev_to_port(dev);
1942 + struct net_device_stats *stats = hdlc_stats(dev);
1946 + printk(KERN_DEBUG DRV_NAME ": hss_hdlc_txdone_irq\n");
1948 + while ((n_desc = queue_get_desc(queue_ids[port->id].txdone,
1950 + struct desc *desc;
1953 + desc = tx_desc_ptr(port, n_desc);
1955 + stats->tx_packets++;
1956 + stats->tx_bytes += desc->pkt_len;
1958 + dma_unmap_tx(port, desc);
1960 + printk(KERN_DEBUG "%s: hss_hdlc_txdone_irq free %p\n",
1961 + port->netdev->name, port->tx_buff_tab[n_desc]);
1963 + free_buffer_irq(port->tx_buff_tab[n_desc]);
1964 + port->tx_buff_tab[n_desc] = NULL;
1966 + start = qmgr_stat_empty(port->plat->txreadyq);
1967 + queue_put_desc(port->plat->txreadyq,
1968 + tx_desc_phys(port, n_desc), desc);
1971 + printk(KERN_DEBUG "%s: hss_hdlc_txdone_irq xmit"
1972 + " ready\n", port->netdev->name);
1974 + netif_wake_queue(port->netdev);
1979 +static int hss_hdlc_xmit(struct sk_buff *skb, struct net_device *dev)
1981 + struct port *port = dev_to_port(dev);
1982 + struct net_device_stats *stats = hdlc_stats(dev);
1983 + unsigned int txreadyq = port->plat->txreadyq;
1984 + int len, offset, bytes, n;
1987 + struct desc *desc;
1990 + printk(KERN_DEBUG "%s: hss_hdlc_xmit\n", dev->name);
1993 + if (unlikely(skb->len > HDLC_MAX_MRU)) {
1994 + dev_kfree_skb(skb);
1995 + stats->tx_errors++;
1996 + return NETDEV_TX_OK;
1999 + debug_pkt(dev, "hss_hdlc_xmit", skb->data, skb->len);
2003 + offset = 0; /* no need to keep alignment */
2007 + offset = (int)skb->data & 3; /* keep 32-bit alignment */
2008 + bytes = ALIGN(offset + len, 4);
2009 + if (!(mem = kmalloc(bytes, GFP_ATOMIC))) {
2010 + dev_kfree_skb(skb);
2011 + stats->tx_dropped++;
2012 + return NETDEV_TX_OK;
2014 + memcpy_swab32(mem, (u32 *)((int)skb->data & ~3), bytes / 4);
2015 + dev_kfree_skb(skb);
2018 + phys = dma_map_single(&dev->dev, mem, bytes, DMA_TO_DEVICE);
2019 + if (dma_mapping_error(phys)) {
2021 + dev_kfree_skb(skb);
2025 + stats->tx_dropped++;
2026 + return NETDEV_TX_OK;
2029 + n = queue_get_desc(txreadyq, port, 1);
2031 + desc = tx_desc_ptr(port, n);
2034 + port->tx_buff_tab[n] = skb;
2036 + port->tx_buff_tab[n] = mem;
2038 + desc->data = phys + offset;
2039 + desc->buf_len = desc->pkt_len = len;
2042 + queue_put_desc(queue_ids[port->id].tx, tx_desc_phys(port, n), desc);
2043 + dev->trans_start = jiffies;
2045 + if (qmgr_stat_empty(txreadyq)) {
2047 + printk(KERN_DEBUG "%s: hss_hdlc_xmit queue full\n", dev->name);
2049 + netif_stop_queue(dev);
2050 + /* we could miss TX ready interrupt */
2051 + if (!qmgr_stat_empty(txreadyq)) {
2053 + printk(KERN_DEBUG "%s: hss_hdlc_xmit ready again\n",
2056 + netif_wake_queue(dev);
2061 + printk(KERN_DEBUG "%s: hss_hdlc_xmit end\n", dev->name);
2063 + return NETDEV_TX_OK;
2067 +static int request_hdlc_queues(struct port *port)
2071 + err = qmgr_request_queue(queue_ids[port->id].rxfree, RX_DESCS, 0, 0);
2075 + err = qmgr_request_queue(queue_ids[port->id].rx, RX_DESCS, 0, 0);
2079 + err = qmgr_request_queue(queue_ids[port->id].tx, TX_DESCS, 0, 0);
2083 + err = qmgr_request_queue(port->plat->txreadyq, TX_DESCS, 0, 0);
2087 + err = qmgr_request_queue(queue_ids[port->id].txdone, TX_DESCS, 0, 0);
2093 + qmgr_release_queue(port->plat->txreadyq);
2095 + qmgr_release_queue(queue_ids[port->id].tx);
2097 + qmgr_release_queue(queue_ids[port->id].rx);
2099 + qmgr_release_queue(queue_ids[port->id].rxfree);
2100 + printk(KERN_DEBUG "%s: unable to request hardware queues\n",
2101 + port->netdev->name);
2105 +static void release_hdlc_queues(struct port *port)
2107 + qmgr_release_queue(queue_ids[port->id].rxfree);
2108 + qmgr_release_queue(queue_ids[port->id].rx);
2109 + qmgr_release_queue(queue_ids[port->id].txdone);
2110 + qmgr_release_queue(queue_ids[port->id].tx);
2111 + qmgr_release_queue(port->plat->txreadyq);
2114 +static int init_hdlc_queues(struct port *port)
2119 + if (!(dma_pool = dma_pool_create(DRV_NAME, NULL,
2120 + POOL_ALLOC_SIZE, 32, 0)))
2123 + if (!(port->desc_tab = dma_pool_alloc(dma_pool, GFP_KERNEL,
2124 + &port->desc_tab_phys)))
2126 + memset(port->desc_tab, 0, POOL_ALLOC_SIZE);
2127 + memset(port->rx_buff_tab, 0, sizeof(port->rx_buff_tab)); /* tables */
2128 + memset(port->tx_buff_tab, 0, sizeof(port->tx_buff_tab));
2130 + /* Setup RX buffers */
2131 + for (i = 0; i < RX_DESCS; i++) {
2132 + struct desc *desc = rx_desc_ptr(port, i);
2136 + if (!(buff = netdev_alloc_skb(port->netdev, RX_SIZE)))
2138 + data = buff->data;
2140 + if (!(buff = kmalloc(RX_SIZE, GFP_KERNEL)))
2144 + desc->buf_len = RX_SIZE;
2145 + desc->data = dma_map_single(&port->netdev->dev, data,
2146 + RX_SIZE, DMA_FROM_DEVICE);
2147 + if (dma_mapping_error(desc->data)) {
2148 + free_buffer(buff);
2151 + port->rx_buff_tab[i] = buff;
2157 +static void destroy_hdlc_queues(struct port *port)
2161 + if (port->desc_tab) {
2162 + for (i = 0; i < RX_DESCS; i++) {
2163 + struct desc *desc = rx_desc_ptr(port, i);
2164 + buffer_t *buff = port->rx_buff_tab[i];
2166 + dma_unmap_single(&port->netdev->dev,
2167 + desc->data, RX_SIZE,
2169 + free_buffer(buff);
2172 + for (i = 0; i < TX_DESCS; i++) {
2173 + struct desc *desc = tx_desc_ptr(port, i);
2174 + buffer_t *buff = port->tx_buff_tab[i];
2176 + dma_unmap_tx(port, desc);
2177 + free_buffer(buff);
2180 + dma_pool_free(dma_pool, port->desc_tab, port->desc_tab_phys);
2181 + port->desc_tab = NULL;
2184 + if (!ports_open && dma_pool) {
2185 + dma_pool_destroy(dma_pool);
2190 +static int hss_hdlc_open(struct net_device *dev)
2192 + struct port *port = dev_to_port(dev);
2193 + struct npe *npe = port->npe;
2197 + if (!npe_running(npe)) {
2198 + err = npe_load_firmware(npe, npe_name(npe), &dev->dev);
2203 + if ((err = hdlc_open(dev)) != 0)
2206 + if (port->plat->open)
2207 + if ((err = port->plat->open(port->id, port->netdev,
2208 + hss_hdlc_set_carrier)) != 0)
2209 + goto err_hdlc_close;
2211 + /* HSS main configuration */
2212 + memset(&msg, 0, sizeof(msg));
2213 + msg.cmd = PORT_CONFIG_WRITE;
2214 + msg.hss_port = port->id;
2215 + msg.index = 0; /* offset in HSS config */
2217 + msg.data32 = PCR_FRM_PULSE_DISABLED |
2220 + PCR_TX_DATA_ENABLE;
2222 + if (port->clock_type == CLOCK_INT)
2223 + msg.data32 |= PCR_SYNC_CLK_DIR_OUTPUT;
2225 + if ((err = npe_send_message(npe, &msg, "HSS_SET_TX_PCR") != 0))
2226 + goto err_plat_close; /* 0: TX PCR */
2229 + msg.data32 ^= PCR_TX_DATA_ENABLE | PCR_DCLK_EDGE_RISING;
2230 + if ((err = npe_send_message(npe, &msg, "HSS_SET_RX_PCR") != 0))
2231 + goto err_plat_close; /* 4: RX PCR */
2234 + msg.data32 = (port->loopback ? CCR_LOOPBACK : 0) |
2235 + (port->id ? CCR_SECOND_HSS : 0);
2236 + if ((err = npe_send_message(npe, &msg, "HSS_SET_CORE_CR") != 0))
2237 + goto err_plat_close; /* 8: Core CR */
2240 + msg.data32 = CLK42X_SPEED_2048KHZ /* FIXME */;
2241 + if ((err = npe_send_message(npe, &msg, "HSS_SET_CLK_CR") != 0))
2242 + goto err_plat_close; /* 12: CLK CR */
2244 + msg.data32 = (FRAME_SYNC_OFFSET << 16) | (FRAME_SYNC_SIZE - 1);
2246 + if ((err = npe_send_message(npe, &msg, "HSS_SET_TX_FCR") != 0))
2247 + goto err_plat_close; /* 16: TX FCR */
2250 + if ((err = npe_send_message(npe, &msg, "HSS_SET_RX_FCR") != 0))
2251 + goto err_plat_close; /* 20: RX FCR */
2253 + msg.data32 = 0; /* Fill LUT with HDLC timeslots */
2254 + for (i = 0; i < 32 / LUT_BITS; i++)
2255 + msg.data32 |= TDMMAP_HDLC << (LUT_BITS * i);
2257 + for (i = 0; i < 2 /* TX and RX */ * TIMESLOTS * LUT_BITS / 8; i += 4) {
2258 + msg.index = 24 + i; /* 24 - 55: TX LUT, 56 - 87: RX LUT */
2259 + if ((err = npe_send_message(npe, &msg, "HSS_SET_LUT") != 0))
2260 + goto err_plat_close;
2263 + /* HDLC mode configuration */
2264 + memset(&msg, 0, sizeof(msg));
2265 + msg.cmd = PKT_NUM_PIPES_WRITE;
2266 + msg.hss_port = port->id;
2267 + msg.data8a = PKT_NUM_PIPES;
2268 + if ((err = npe_send_message(npe, &msg, "HSS_SET_PKT_PIPES") != 0))
2269 + goto err_plat_close;
2271 + memset(&msg, 0, sizeof(msg));
2272 + msg.cmd = PKT_PIPE_FIFO_SIZEW_WRITE;
2273 + msg.hss_port = port->id;
2274 + msg.data8a = PKT_PIPE_FIFO_SIZEW;
2275 + if ((err = npe_send_message(npe, &msg, "HSS_SET_PKT_FIFO") != 0))
2276 + goto err_plat_close;
2278 + memset(&msg, 0, sizeof(msg));
2279 + msg.cmd = PKT_PIPE_IDLE_PATTERN_WRITE;
2280 + msg.hss_port = port->id;
2281 + msg.data32 = 0x7F7F7F7F;
2282 + if ((err = npe_send_message(npe, &msg, "HSS_SET_PKT_IDLE") != 0))
2283 + goto err_plat_close;
2285 + memset(&msg, 0, sizeof(msg));
2286 + msg.cmd = PORT_CONFIG_LOAD;
2287 + msg.hss_port = port->id;
2288 + if ((err = npe_send_message(npe, &msg, "HSS_LOAD_CONFIG") != 0))
2289 + goto err_plat_close;
2290 + if ((err = npe_recv_message(npe, &msg, "HSS_LOAD_CONFIG") != 0))
2291 + goto err_plat_close;
2293 + /* HSS_LOAD_CONFIG for port #1 returns port_id = #4 */
2294 + if (msg.cmd != PORT_CONFIG_LOAD || msg.data32) {
2295 + printk(KERN_DEBUG "%s: unexpected message received in"
2296 + " response to HSS_LOAD_CONFIG\n", npe_name(npe));
2298 + goto err_plat_close;
2301 + memset(&msg, 0, sizeof(msg));
2302 + msg.cmd = PKT_PIPE_HDLC_CFG_WRITE;
2303 + msg.hss_port = port->id;
2304 + msg.data8a = port->hdlc_cfg; /* rx_cfg */
2305 + msg.data8b = port->hdlc_cfg | (PKT_EXTRA_FLAGS << 3); /* tx_cfg */
2306 + if ((err = npe_send_message(npe, &msg, "HSS_SET_HDLC_CFG") != 0))
2307 + goto err_plat_close;
2309 + memset(&msg, 0, sizeof(msg));
2310 + msg.cmd = PKT_PIPE_MODE_WRITE;
2311 + msg.hss_port = port->id;
2312 + msg.data8a = NPE_PKT_MODE_HDLC;
2313 + /* msg.data8b = inv_mask */
2314 + /* msg.data8c = or_mask */
2315 + if ((err = npe_send_message(npe, &msg, "HSS_SET_PKT_MODE") != 0))
2316 + goto err_plat_close;
2318 + memset(&msg, 0, sizeof(msg));
2319 + msg.cmd = PKT_PIPE_RX_SIZE_WRITE;
2320 + msg.hss_port = port->id;
2321 + msg.data16a = HDLC_MAX_MRU;
2322 + if ((err = npe_send_message(npe, &msg, "HSS_SET_PKT_RX_SIZE") != 0))
2323 + goto err_plat_close;
2325 + if ((err = request_hdlc_queues(port)) != 0)
2326 + goto err_plat_close;
2328 + if ((err = init_hdlc_queues(port)) != 0)
2329 + goto err_destroy_queues;
2331 + memset(&msg, 0, sizeof(msg));
2332 + msg.cmd = PKT_PIPE_FLOW_ENABLE;
2333 + msg.hss_port = port->id;
2334 + if ((err = npe_send_message(npe, &msg, "HSS_ENABLE_PKT_PIPE") != 0))
2335 + goto err_destroy_queues;
2337 + /* Populate queues with buffers, no failure after this point */
2338 + for (i = 0; i < TX_DESCS; i++)
2339 + queue_put_desc(port->plat->txreadyq,
2340 + tx_desc_phys(port, i), tx_desc_ptr(port, i));
2342 + for (i = 0; i < RX_DESCS; i++)
2343 + queue_put_desc(queue_ids[port->id].rxfree,
2344 + rx_desc_phys(port, i), rx_desc_ptr(port, i));
2346 + netif_start_queue(dev);
2348 + qmgr_set_irq(queue_ids[port->id].rx, QUEUE_IRQ_SRC_NOT_EMPTY,
2349 + hss_hdlc_rx_irq, dev);
2351 + qmgr_set_irq(queue_ids[port->id].txdone, QUEUE_IRQ_SRC_NOT_EMPTY,
2352 + hss_hdlc_txdone_irq, dev);
2353 + qmgr_enable_irq(queue_ids[port->id].txdone);
2356 + netif_rx_schedule(dev); /* we may already have RX data, enables IRQ */
2359 +err_destroy_queues:
2360 + destroy_hdlc_queues(port);
2361 + release_hdlc_queues(port);
2363 + if (port->plat->close)
2364 + port->plat->close(port->id, port->netdev);
2370 +static int hss_hdlc_close(struct net_device *dev)
2372 + struct port *port = dev_to_port(dev);
2373 + struct npe *npe = port->npe;
2375 + int buffs = RX_DESCS; /* allocated RX buffers */
2379 + qmgr_disable_irq(queue_ids[port->id].rx);
2380 + netif_stop_queue(dev);
2382 + memset(&msg, 0, sizeof(msg));
2383 + msg.cmd = PKT_PIPE_FLOW_DISABLE;
2384 + msg.hss_port = port->id;
2385 + if (npe_send_message(npe, &msg, "HSS_DISABLE_PKT_PIPE")) {
2386 + printk(KERN_CRIT "HSS-%i: unable to stop HDLC flow\n",
2388 + /* The upper level would ignore the error anyway */
2391 + while (queue_get_desc(queue_ids[port->id].rxfree, port, 0) >= 0)
2393 + while (queue_get_desc(queue_ids[port->id].rx, port, 0) >= 0)
2397 + printk(KERN_CRIT "%s: unable to drain RX queue, %i buffer(s)"
2398 + " left in NPE\n", dev->name, buffs);
2401 + while (queue_get_desc(queue_ids[port->id].tx, port, 1) >= 0)
2402 + buffs--; /* cancel TX */
2406 + while (queue_get_desc(port->plat->txreadyq, port, 1) >= 0)
2410 + } while (++i < MAX_CLOSE_WAIT);
2413 + printk(KERN_CRIT "%s: unable to drain TX queue, %i buffer(s) "
2414 + "left in NPE\n", dev->name, buffs);
2417 + printk(KERN_DEBUG "Draining TX queues took %i cycles\n", i);
2419 + qmgr_disable_irq(queue_ids[port->id].txdone);
2420 + destroy_hdlc_queues(port);
2421 + release_hdlc_queues(port);
2423 + if (port->plat->close)
2424 + port->plat->close(port->id, port->netdev);
2430 +static int hss_hdlc_attach(struct net_device *dev, unsigned short encoding,
2431 + unsigned short parity)
2433 + struct port *port = dev_to_port(dev);
2435 + if (encoding != ENCODING_NRZ)
2439 + case PARITY_CRC16_PR1_CCITT:
2440 + port->hdlc_cfg = 0;
2443 + case PARITY_CRC32_PR1_CCITT:
2444 + port->hdlc_cfg = PKT_HDLC_CRC_32;
2453 +static int hss_hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2455 + const size_t size = sizeof(sync_serial_settings);
2456 + sync_serial_settings new_line;
2458 + sync_serial_settings __user *line = ifr->ifr_settings.ifs_ifsu.sync;
2459 + struct port *port = dev_to_port(dev);
2461 + if (cmd != SIOCWANDEV)
2462 + return hdlc_ioctl(dev, ifr, cmd);
2464 + switch(ifr->ifr_settings.type) {
2465 + case IF_GET_IFACE:
2466 + ifr->ifr_settings.type = IF_IFACE_V35;
2467 + if (ifr->ifr_settings.size < size) {
2468 + ifr->ifr_settings.size = size; /* data size wanted */
2471 + memset(&new_line, 0, sizeof(new_line));
2472 + new_line.clock_type = port->clock_type;
2473 + new_line.clock_rate = port->clock_rate;
2474 + new_line.loopback = port->loopback;
2475 + if (copy_to_user(line, &new_line, size))
2479 + case IF_IFACE_SYNC_SERIAL:
2480 + case IF_IFACE_V35:
2481 + if(!capable(CAP_NET_ADMIN))
2483 + if (dev->flags & IFF_UP)
2484 + return -EBUSY; /* Cannot change parameters when open */
2486 + if (copy_from_user(&new_line, line, size))
2489 + clk = new_line.clock_type;
2490 + if (port->plat->set_clock)
2491 + clk = port->plat->set_clock(port->id, clk);
2493 + if (clk != CLOCK_EXT && clk != CLOCK_INT)
2494 + return -EINVAL; /* No such clock setting */
2496 + if (new_line.loopback != 0 && new_line.loopback != 1)
2499 + port->clock_type = clk; /* Update settings */
2500 + port->clock_rate = new_line.clock_rate;
2501 + port->loopback = new_line.loopback;
2505 + return hdlc_ioctl(dev, ifr, cmd);
2510 +static int __devinit hss_init_one(struct platform_device *pdev)
2512 + struct port *port;
2513 + struct net_device *dev;
2514 + hdlc_device *hdlc;
2517 + if ((port = kzalloc(sizeof(*port), GFP_KERNEL)) == NULL)
2519 + platform_set_drvdata(pdev, port);
2520 + port->id = pdev->id;
2522 + if ((port->npe = npe_request(0)) == NULL) {
2527 + port->plat = pdev->dev.platform_data;
2528 + if ((port->netdev = dev = alloc_hdlcdev(port)) == NULL) {
2533 + SET_MODULE_OWNER(net);
2534 + SET_NETDEV_DEV(dev, &pdev->dev);
2535 + hdlc = dev_to_hdlc(dev);
2536 + hdlc->attach = hss_hdlc_attach;
2537 + hdlc->xmit = hss_hdlc_xmit;
2538 + dev->open = hss_hdlc_open;
2539 + dev->poll = hss_hdlc_poll;
2540 + dev->stop = hss_hdlc_close;
2541 + dev->do_ioctl = hss_hdlc_ioctl;
2543 + dev->tx_queue_len = 100;
2544 + port->clock_type = CLOCK_EXT;
2545 + port->clock_rate = 2048000;
2547 + if (register_hdlc_device(dev)) {
2548 + printk(KERN_ERR "HSS-%i: unable to register HDLC device\n",
2551 + goto err_free_netdev;
2553 + printk(KERN_INFO "%s: HSS-%i\n", dev->name, port->id);
2559 + npe_release(port->npe);
2560 + platform_set_drvdata(pdev, NULL);
2566 +static int __devexit hss_remove_one(struct platform_device *pdev)
2568 + struct port *port = platform_get_drvdata(pdev);
2570 + unregister_hdlc_device(port->netdev);
2571 + free_netdev(port->netdev);
2572 + npe_release(port->npe);
2573 + platform_set_drvdata(pdev, NULL);
2578 +static struct platform_driver drv = {
2579 + .driver.name = DRV_NAME,
2580 + .probe = hss_init_one,
2581 + .remove = hss_remove_one,
2584 +static int __init hss_init_module(void)
2586 + if ((ixp4xx_read_feature_bits() &
2587 + (IXP4XX_FEATURE_HDLC | IXP4XX_FEATURE_HSS)) !=
2588 + (IXP4XX_FEATURE_HDLC | IXP4XX_FEATURE_HSS))
2590 + return platform_driver_register(&drv);
2593 +static void __exit hss_cleanup_module(void)
2595 + platform_driver_unregister(&drv);
2598 +MODULE_AUTHOR("Krzysztof Halasa");
2599 +MODULE_DESCRIPTION("Intel IXP4xx HSS driver");
2600 +MODULE_LICENSE("GPL v2");
2601 +module_init(hss_init_module);
2602 +module_exit(hss_cleanup_module);
2603 From: Krzysztof Halasa <khc@pm.waw.pl>
2604 Subject: Adds functions to read and write IXP4xx "feature" bits
2606 Adds functions to read and write IXP4xx "feature" (aka "fuse")
2607 bits, containing information about available/enabled CPU features.
2609 The uncompress.h included by boot/compressed/misc.c resides in
2610 a different space than rest of the kernel and thus can't use
2611 asm/hardware.h (including asm/arch/cpu.h - which, in turn, may use
2612 EXPORTed symbol "processor_id").
2614 Signed-off-by: Krzysztof Halasa <khc@pm.waw.pl>
2617 KernelVersion: 2.6.23
2619 diff --git a/include/asm-arm/arch-ixp4xx/ixp4xx-regs.h b/include/asm-arm/arch-ixp4xx/ixp4xx-regs.h
2620 index 5d949d7..c704fe8 100644
2621 --- a/include/asm-arm/arch-ixp4xx/ixp4xx-regs.h
2622 +++ b/include/asm-arm/arch-ixp4xx/ixp4xx-regs.h
2627 -#ifndef __ASM_ARCH_HARDWARE_H__
2628 -#error "Do not include this directly, instead #include <asm/hardware.h>"
2631 #ifndef _ASM_ARM_IXP4XX_H_
2632 #define _ASM_ARM_IXP4XX_H_
2634 @@ -607,4 +603,36 @@
2636 #define DCMD_LENGTH 0x01fff /* length mask (max = 8K - 1) */
2638 +/* "fuse" bits of IXP_EXP_CFG2 */
2639 +#define IXP4XX_FEATURE_RCOMP (1 << 0)
2640 +#define IXP4XX_FEATURE_USB_DEVICE (1 << 1)
2641 +#define IXP4XX_FEATURE_HASH (1 << 2)
2642 +#define IXP4XX_FEATURE_AES (1 << 3)
2643 +#define IXP4XX_FEATURE_DES (1 << 4)
2644 +#define IXP4XX_FEATURE_HDLC (1 << 5)
2645 +#define IXP4XX_FEATURE_AAL (1 << 6)
2646 +#define IXP4XX_FEATURE_HSS (1 << 7)
2647 +#define IXP4XX_FEATURE_UTOPIA (1 << 8)
2648 +#define IXP4XX_FEATURE_NPEB_ETH0 (1 << 9)
2649 +#define IXP4XX_FEATURE_NPEC_ETH (1 << 10)
2650 +#define IXP4XX_FEATURE_RESET_NPEA (1 << 11)
2651 +#define IXP4XX_FEATURE_RESET_NPEB (1 << 12)
2652 +#define IXP4XX_FEATURE_RESET_NPEC (1 << 13)
2653 +#define IXP4XX_FEATURE_PCI (1 << 14)
2654 +#define IXP4XX_FEATURE_ECC_TIMESYNC (1 << 15)
2655 +#define IXP4XX_FEATURE_UTOPIA_PHY_LIMIT (3 << 16)
2656 +#define IXP4XX_FEATURE_USB_HOST (1 << 18)
2657 +#define IXP4XX_FEATURE_NPEA_ETH (1 << 19)
2658 +#define IXP4XX_FEATURE_NPEB_ETH_1_TO_3 (1 << 20)
2659 +#define IXP4XX_FEATURE_RSA (1 << 21)
2660 +#define IXP4XX_FEATURE_XSCALE_MAX_FREQ (3 << 22)
2661 +#define IXP4XX_FEATURE_RESERVED (0xFF << 24)
2663 +#define IXP4XX_FEATURE_IXP46X_ONLY (IXP4XX_FEATURE_ECC_TIMESYNC | \
2664 + IXP4XX_FEATURE_USB_HOST | \
2665 + IXP4XX_FEATURE_NPEA_ETH | \
2666 + IXP4XX_FEATURE_NPEB_ETH_1_TO_3 | \
2667 + IXP4XX_FEATURE_RSA | \
2668 + IXP4XX_FEATURE_XSCALE_MAX_FREQ)
2671 diff --git a/include/asm-arm/arch-ixp4xx/cpu.h b/include/asm-arm/arch-ixp4xx/cpu.h
2672 index d2523b3..2fa3d6b 100644
2673 --- a/include/asm-arm/arch-ixp4xx/cpu.h
2674 +++ b/include/asm-arm/arch-ixp4xx/cpu.h
2675 @@ -28,4 +28,19 @@ extern unsigned int processor_id;
2676 #define cpu_is_ixp46x() ((processor_id & IXP4XX_PROCESSOR_ID_MASK) == \
2677 IXP465_PROCESSOR_ID_VALUE)
2679 +static inline u32 ixp4xx_read_feature_bits(void)
2681 + unsigned int val = ~*IXP4XX_EXP_CFG2;
2682 + val &= ~IXP4XX_FEATURE_RESERVED;
2683 + if (!cpu_is_ixp46x())
2684 + val &= ~IXP4XX_FEATURE_IXP46X_ONLY;
2689 +static inline void ixp4xx_write_feature_bits(u32 value)
2691 + *IXP4XX_EXP_CFG2 = ~value;
2694 #endif /* _ASM_ARCH_CPU_H */
2695 diff --git a/include/asm-arm/arch-ixp4xx/hardware.h b/include/asm-arm/arch-ixp4xx/hardware.h
2696 index 297ceda..73e8dc3 100644
2697 --- a/include/asm-arm/arch-ixp4xx/hardware.h
2698 +++ b/include/asm-arm/arch-ixp4xx/hardware.h
2701 #define pcibios_assign_all_busses() 1
2703 +/* Register locations and bits */
2704 +#include "ixp4xx-regs.h"
2706 #ifndef __ASSEMBLER__
2707 #include <asm/arch/cpu.h>
2710 -/* Register locations and bits */
2711 -#include "ixp4xx-regs.h"
2713 /* Platform helper functions and definitions */
2714 #include "platform.h"
2716 diff --git a/include/asm-arm/arch-ixp4xx/uncompress.h b/include/asm-arm/arch-ixp4xx/uncompress.h
2717 index f7a35b7..34ef48f 100644
2718 --- a/include/asm-arm/arch-ixp4xx/uncompress.h
2719 +++ b/include/asm-arm/arch-ixp4xx/uncompress.h
2721 #ifndef _ARCH_UNCOMPRESS_H_
2722 #define _ARCH_UNCOMPRESS_H_
2724 -#include <asm/hardware.h>
2725 +#include "ixp4xx-regs.h"
2726 #include <asm/mach-types.h>
2727 #include <linux/serial_reg.h>
2729 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2730 index 4de432e..c4c810b 100644
2731 --- a/arch/arm/kernel/setup.c
2732 +++ b/arch/arm/kernel/setup.c
2733 @@ -61,6 +61,7 @@ extern int root_mountflags;
2734 extern void _stext, _text, _etext, __data_start, _edata, _end;
2736 unsigned int processor_id;
2737 +EXPORT_SYMBOL(processor_id);
2738 unsigned int __machine_arch_type;
2739 EXPORT_SYMBOL(__machine_arch_type);
2743 From: Krzysztof Halasa <khc@pm.waw.pl>
2744 Subject: Adds drivers for IXP4xx QMgr and NPE features
2746 This patch adds drivers for IXP4xx hardware Queue Manager and for
2747 Network Processor Engines. Requires patch #4712 (reading/writing
2748 CPU feature (aka fuse) bits).
2750 Signed-off-by: Krzysztof Halasa <khc@pm.waw.pl>
2753 KernelVersion: 2.6.23
2755 diff --git a/arch/arm/mach-ixp4xx/Kconfig b/arch/arm/mach-ixp4xx/Kconfig
2756 index 61b2dfc..e774447 100644
2757 --- a/arch/arm/mach-ixp4xx/Kconfig
2758 +++ b/arch/arm/mach-ixp4xx/Kconfig
2759 @@ -189,6 +189,20 @@ config IXP4XX_INDIRECT_PCI
2760 need to use the indirect method instead. If you don't know
2761 what you need, leave this option unselected.
2764 + tristate "IXP4xx Queue Manager support"
2766 + This driver supports IXP4xx built-in hardware queue manager
2767 + and is automatically selected by Ethernet and HSS drivers.
2770 + tristate "IXP4xx Network Processor Engine support"
2774 + This driver supports IXP4xx built-in network coprocessors
2775 + and is automatically selected by Ethernet and HSS drivers.
2780 diff --git a/arch/arm/mach-ixp4xx/Makefile b/arch/arm/mach-ixp4xx/Makefile
2781 index 77e00ad..4bb97e1 100644
2782 --- a/arch/arm/mach-ixp4xx/Makefile
2783 +++ b/arch/arm/mach-ixp4xx/Makefile
2784 @@ -30,3 +30,5 @@ obj-$(CONFIG_MACH_GATEWAY7001) += gateway7001-setup.o
2785 obj-$(CONFIG_MACH_WG302V2) += wg302v2-setup.o
2787 obj-$(CONFIG_PCI) += $(obj-pci-$(CONFIG_PCI)) common-pci.o
2788 +obj-$(CONFIG_IXP4XX_QMGR) += ixp4xx_qmgr.o
2789 +obj-$(CONFIG_IXP4XX_NPE) += ixp4xx_npe.o
2790 diff --git a/include/asm-arm/arch-ixp4xx/qmgr.h b/include/asm-arm/arch-ixp4xx/qmgr.h
2791 new file mode 100644
2792 index 0000000..1e52b95
2794 +++ b/include/asm-arm/arch-ixp4xx/qmgr.h
2797 + * Copyright (C) 2007 Krzysztof Halasa <khc@pm.waw.pl>
2799 + * This program is free software; you can redistribute it and/or modify it
2800 + * under the terms of version 2 of the GNU General Public License
2801 + * as published by the Free Software Foundation.
2804 +#ifndef IXP4XX_QMGR_H
2805 +#define IXP4XX_QMGR_H
2807 +#include <linux/io.h>
2808 +#include <linux/kernel.h>
2810 +#define HALF_QUEUES 32
2811 +#define QUEUES 64 /* only 32 lower queues currently supported */
2812 +#define MAX_QUEUE_LENGTH 4 /* in dwords */
2814 +#define QUEUE_STAT1_EMPTY 1 /* queue status bits */
2815 +#define QUEUE_STAT1_NEARLY_EMPTY 2
2816 +#define QUEUE_STAT1_NEARLY_FULL 4
2817 +#define QUEUE_STAT1_FULL 8
2818 +#define QUEUE_STAT2_UNDERFLOW 1
2819 +#define QUEUE_STAT2_OVERFLOW 2
2821 +#define QUEUE_WATERMARK_0_ENTRIES 0
2822 +#define QUEUE_WATERMARK_1_ENTRY 1
2823 +#define QUEUE_WATERMARK_2_ENTRIES 2
2824 +#define QUEUE_WATERMARK_4_ENTRIES 3
2825 +#define QUEUE_WATERMARK_8_ENTRIES 4
2826 +#define QUEUE_WATERMARK_16_ENTRIES 5
2827 +#define QUEUE_WATERMARK_32_ENTRIES 6
2828 +#define QUEUE_WATERMARK_64_ENTRIES 7
2830 +/* queue interrupt request conditions */
2831 +#define QUEUE_IRQ_SRC_EMPTY 0
2832 +#define QUEUE_IRQ_SRC_NEARLY_EMPTY 1
2833 +#define QUEUE_IRQ_SRC_NEARLY_FULL 2
2834 +#define QUEUE_IRQ_SRC_FULL 3
2835 +#define QUEUE_IRQ_SRC_NOT_EMPTY 4
2836 +#define QUEUE_IRQ_SRC_NOT_NEARLY_EMPTY 5
2837 +#define QUEUE_IRQ_SRC_NOT_NEARLY_FULL 6
2838 +#define QUEUE_IRQ_SRC_NOT_FULL 7
2841 + u32 acc[QUEUES][MAX_QUEUE_LENGTH]; /* 0x000 - 0x3FF */
2842 + u32 stat1[4]; /* 0x400 - 0x40F */
2843 + u32 stat2[2]; /* 0x410 - 0x417 */
2844 + u32 statne_h; /* 0x418 - queue nearly empty */
2845 + u32 statf_h; /* 0x41C - queue full */
2846 + u32 irqsrc[4]; /* 0x420 - 0x42F IRC source */
2847 + u32 irqen[2]; /* 0x430 - 0x437 IRQ enabled */
2848 + u32 irqstat[2]; /* 0x438 - 0x43F - IRQ access only */
2849 + u32 reserved[1776];
2850 + u32 sram[2048]; /* 0x2000 - 0x3FFF - config and buffer */
2853 +void qmgr_set_irq(unsigned int queue, int src,
2854 + void (*handler)(void *pdev), void *pdev);
2855 +void qmgr_enable_irq(unsigned int queue);
2856 +void qmgr_disable_irq(unsigned int queue);
2858 +/* request_ and release_queue() must be called from non-IRQ context */
2859 +int qmgr_request_queue(unsigned int queue, unsigned int len /* dwords */,
2860 + unsigned int nearly_empty_watermark,
2861 + unsigned int nearly_full_watermark);
2862 +void qmgr_release_queue(unsigned int queue);
2865 +static inline void qmgr_put_entry(unsigned int queue, u32 val)
2867 + extern struct qmgr_regs __iomem *qmgr_regs;
2868 + __raw_writel(val, &qmgr_regs->acc[queue][0]);
2871 +static inline u32 qmgr_get_entry(unsigned int queue)
2873 + extern struct qmgr_regs __iomem *qmgr_regs;
2874 + return __raw_readl(&qmgr_regs->acc[queue][0]);
2877 +static inline int qmgr_get_stat1(unsigned int queue)
2879 + extern struct qmgr_regs __iomem *qmgr_regs;
2880 + return (__raw_readl(&qmgr_regs->stat1[queue >> 3])
2881 + >> ((queue & 7) << 2)) & 0xF;
2884 +static inline int qmgr_get_stat2(unsigned int queue)
2886 + extern struct qmgr_regs __iomem *qmgr_regs;
2887 + return (__raw_readl(&qmgr_regs->stat2[queue >> 4])
2888 + >> ((queue & 0xF) << 1)) & 0x3;
2891 +static inline int qmgr_stat_empty(unsigned int queue)
2893 + return !!(qmgr_get_stat1(queue) & QUEUE_STAT1_EMPTY);
2896 +static inline int qmgr_stat_nearly_empty(unsigned int queue)
2898 + return !!(qmgr_get_stat1(queue) & QUEUE_STAT1_NEARLY_EMPTY);
2901 +static inline int qmgr_stat_nearly_full(unsigned int queue)
2903 + return !!(qmgr_get_stat1(queue) & QUEUE_STAT1_NEARLY_FULL);
2906 +static inline int qmgr_stat_full(unsigned int queue)
2908 + return !!(qmgr_get_stat1(queue) & QUEUE_STAT1_FULL);
2911 +static inline int qmgr_stat_underflow(unsigned int queue)
2913 + return !!(qmgr_get_stat2(queue) & QUEUE_STAT2_UNDERFLOW);
2916 +static inline int qmgr_stat_overflow(unsigned int queue)
2918 + return !!(qmgr_get_stat2(queue) & QUEUE_STAT2_OVERFLOW);
2922 diff --git a/include/asm-arm/arch-ixp4xx/npe.h b/include/asm-arm/arch-ixp4xx/npe.h
2923 new file mode 100644
2924 index 0000000..37d0511
2926 +++ b/include/asm-arm/arch-ixp4xx/npe.h
2928 +#ifndef __IXP4XX_NPE_H
2929 +#define __IXP4XX_NPE_H
2931 +#include <linux/kernel.h>
2933 +extern const char *npe_names[];
2936 + u32 exec_addr, exec_data, exec_status_cmd, exec_count;
2937 + u32 action_points[4];
2938 + u32 watchpoint_fifo, watch_count;
2939 + u32 profile_count;
2940 + u32 messaging_status, messaging_control;
2941 + u32 mailbox_status, /*messaging_*/ in_out_fifo;
2945 + struct resource *mem_res;
2946 + struct npe_regs __iomem *regs;
2953 +static inline const char *npe_name(struct npe *npe)
2955 + return npe_names[npe->id];
2958 +int npe_running(struct npe *npe);
2959 +int npe_send_message(struct npe *npe, const void *msg, const char *what);
2960 +int npe_recv_message(struct npe *npe, void *msg, const char *what);
2961 +int npe_send_recv_message(struct npe *npe, void *msg, const char *what);
2962 +int npe_load_firmware(struct npe *npe, const char *name, struct device *dev);
2963 +struct npe *npe_request(int id);
2964 +void npe_release(struct npe *npe);
2966 +#endif /* __IXP4XX_NPE_H */
2967 diff --git a/arch/arm/mach-ixp4xx/ixp4xx_qmgr.c b/arch/arm/mach-ixp4xx/ixp4xx_qmgr.c
2968 new file mode 100644
2969 index 0000000..e833013
2971 +++ b/arch/arm/mach-ixp4xx/ixp4xx_qmgr.c
2974 + * Intel IXP4xx Queue Manager driver for Linux
2976 + * Copyright (C) 2007 Krzysztof Halasa <khc@pm.waw.pl>
2978 + * This program is free software; you can redistribute it and/or modify it
2979 + * under the terms of version 2 of the GNU General Public License
2980 + * as published by the Free Software Foundation.
2983 +#include <linux/ioport.h>
2984 +#include <linux/interrupt.h>
2985 +#include <linux/kernel.h>
2986 +#include <linux/module.h>
2987 +#include <asm/arch/qmgr.h>
2991 +struct qmgr_regs __iomem *qmgr_regs;
2992 +static struct resource *mem_res;
2993 +static spinlock_t qmgr_lock;
2994 +static u32 used_sram_bitmap[4]; /* 128 16-dword pages */
2995 +static void (*irq_handlers[HALF_QUEUES])(void *pdev);
2996 +static void *irq_pdevs[HALF_QUEUES];
2998 +void qmgr_set_irq(unsigned int queue, int src,
2999 + void (*handler)(void *pdev), void *pdev)
3001 + u32 __iomem *reg = &qmgr_regs->irqsrc[queue / 8]; /* 8 queues / u32 */
3002 + int bit = (queue % 8) * 4; /* 3 bits + 1 reserved bit per queue */
3003 + unsigned long flags;
3006 + spin_lock_irqsave(&qmgr_lock, flags);
3007 + __raw_writel((__raw_readl(reg) & ~(7 << bit)) | (src << bit), reg);
3008 + irq_handlers[queue] = handler;
3009 + irq_pdevs[queue] = pdev;
3010 + spin_unlock_irqrestore(&qmgr_lock, flags);
3014 +static irqreturn_t qmgr_irq1(int irq, void *pdev)
3017 + u32 val = __raw_readl(&qmgr_regs->irqstat[0]);
3018 + __raw_writel(val, &qmgr_regs->irqstat[0]); /* ACK */
3020 + for (i = 0; i < HALF_QUEUES; i++)
3021 + if (val & (1 << i))
3022 + irq_handlers[i](irq_pdevs[i]);
3024 + return val ? IRQ_HANDLED : 0;
3028 +void qmgr_enable_irq(unsigned int queue)
3030 + unsigned long flags;
3032 + spin_lock_irqsave(&qmgr_lock, flags);
3033 + __raw_writel(__raw_readl(&qmgr_regs->irqen[0]) | (1 << queue),
3034 + &qmgr_regs->irqen[0]);
3035 + spin_unlock_irqrestore(&qmgr_lock, flags);
3038 +void qmgr_disable_irq(unsigned int queue)
3040 + unsigned long flags;
3042 + spin_lock_irqsave(&qmgr_lock, flags);
3043 + __raw_writel(__raw_readl(&qmgr_regs->irqen[0]) & ~(1 << queue),
3044 + &qmgr_regs->irqen[0]);
3045 + spin_unlock_irqrestore(&qmgr_lock, flags);
3048 +static inline void shift_mask(u32 *mask)
3050 + mask[3] = mask[3] << 1 | mask[2] >> 31;
3051 + mask[2] = mask[2] << 1 | mask[1] >> 31;
3052 + mask[1] = mask[1] << 1 | mask[0] >> 31;
3056 +int qmgr_request_queue(unsigned int queue, unsigned int len /* dwords */,
3057 + unsigned int nearly_empty_watermark,
3058 + unsigned int nearly_full_watermark)
3060 + u32 cfg, addr = 0, mask[4]; /* in 16-dwords */
3063 + if (queue >= HALF_QUEUES)
3066 + if ((nearly_empty_watermark | nearly_full_watermark) & ~7)
3090 + cfg |= nearly_empty_watermark << 26;
3091 + cfg |= nearly_full_watermark << 29;
3092 + len /= 16; /* in 16-dwords: 1, 2, 4 or 8 */
3093 + mask[1] = mask[2] = mask[3] = 0;
3095 + if (!try_module_get(THIS_MODULE))
3098 + spin_lock_irq(&qmgr_lock);
3099 + if (__raw_readl(&qmgr_regs->sram[queue])) {
3105 + if (!(used_sram_bitmap[0] & mask[0]) &&
3106 + !(used_sram_bitmap[1] & mask[1]) &&
3107 + !(used_sram_bitmap[2] & mask[2]) &&
3108 + !(used_sram_bitmap[3] & mask[3]))
3109 + break; /* found free space */
3113 + if (addr + len > ARRAY_SIZE(qmgr_regs->sram)) {
3114 + printk(KERN_ERR "qmgr: no free SRAM space for"
3115 + " queue %i\n", queue);
3121 + used_sram_bitmap[0] |= mask[0];
3122 + used_sram_bitmap[1] |= mask[1];
3123 + used_sram_bitmap[2] |= mask[2];
3124 + used_sram_bitmap[3] |= mask[3];
3125 + __raw_writel(cfg | (addr << 14), &qmgr_regs->sram[queue]);
3126 + spin_unlock_irq(&qmgr_lock);
3129 + printk(KERN_DEBUG "qmgr: requested queue %i, addr = 0x%02X\n",
3135 + spin_unlock_irq(&qmgr_lock);
3136 + module_put(THIS_MODULE);
3140 +void qmgr_release_queue(unsigned int queue)
3142 + u32 cfg, addr, mask[4];
3144 + BUG_ON(queue >= HALF_QUEUES); /* not in valid range */
3146 + spin_lock_irq(&qmgr_lock);
3147 + cfg = __raw_readl(&qmgr_regs->sram[queue]);
3148 + addr = (cfg >> 14) & 0xFF;
3150 + BUG_ON(!addr); /* not requested */
3152 + switch ((cfg >> 24) & 3) {
3153 + case 0: mask[0] = 0x1; break;
3154 + case 1: mask[0] = 0x3; break;
3155 + case 2: mask[0] = 0xF; break;
3156 + case 3: mask[0] = 0xFF; break;
3162 + __raw_writel(0, &qmgr_regs->sram[queue]);
3164 + used_sram_bitmap[0] &= ~mask[0];
3165 + used_sram_bitmap[1] &= ~mask[1];
3166 + used_sram_bitmap[2] &= ~mask[2];
3167 + used_sram_bitmap[3] &= ~mask[3];
3168 + irq_handlers[queue] = NULL; /* catch IRQ bugs */
3169 + spin_unlock_irq(&qmgr_lock);
3171 + module_put(THIS_MODULE);
3173 + printk(KERN_DEBUG "qmgr: released queue %i\n", queue);
3177 +static int qmgr_init(void)
3180 + mem_res = request_mem_region(IXP4XX_QMGR_BASE_PHYS,
3181 + IXP4XX_QMGR_REGION_SIZE,
3182 + "IXP4xx Queue Manager");
3183 + if (mem_res == NULL)
3186 + qmgr_regs = ioremap(IXP4XX_QMGR_BASE_PHYS, IXP4XX_QMGR_REGION_SIZE);
3187 + if (qmgr_regs == NULL) {
3192 + /* reset qmgr registers */
3193 + for (i = 0; i < 4; i++) {
3194 + __raw_writel(0x33333333, &qmgr_regs->stat1[i]);
3195 + __raw_writel(0, &qmgr_regs->irqsrc[i]);
3197 + for (i = 0; i < 2; i++) {
3198 + __raw_writel(0, &qmgr_regs->stat2[i]);
3199 + __raw_writel(0xFFFFFFFF, &qmgr_regs->irqstat[i]); /* clear */
3200 + __raw_writel(0, &qmgr_regs->irqen[i]);
3203 + for (i = 0; i < QUEUES; i++)
3204 + __raw_writel(0, &qmgr_regs->sram[i]);
3206 + err = request_irq(IRQ_IXP4XX_QM1, qmgr_irq1, 0,
3207 + "IXP4xx Queue Manager", NULL);
3209 + printk(KERN_ERR "qmgr: failed to request IRQ%i\n",
3214 + used_sram_bitmap[0] = 0xF; /* 4 first pages reserved for config */
3215 + spin_lock_init(&qmgr_lock);
3217 + printk(KERN_INFO "IXP4xx Queue Manager initialized.\n");
3221 + iounmap(qmgr_regs);
3223 + release_mem_region(IXP4XX_QMGR_BASE_PHYS, IXP4XX_QMGR_REGION_SIZE);
3227 +static void qmgr_remove(void)
3229 + free_irq(IRQ_IXP4XX_QM1, NULL);
3230 + synchronize_irq(IRQ_IXP4XX_QM1);
3231 + iounmap(qmgr_regs);
3232 + release_mem_region(IXP4XX_QMGR_BASE_PHYS, IXP4XX_QMGR_REGION_SIZE);
3235 +module_init(qmgr_init);
3236 +module_exit(qmgr_remove);
3238 +MODULE_LICENSE("GPL v2");
3239 +MODULE_AUTHOR("Krzysztof Halasa");
3241 +EXPORT_SYMBOL(qmgr_regs);
3242 +EXPORT_SYMBOL(qmgr_set_irq);
3243 +EXPORT_SYMBOL(qmgr_enable_irq);
3244 +EXPORT_SYMBOL(qmgr_disable_irq);
3245 +EXPORT_SYMBOL(qmgr_request_queue);
3246 +EXPORT_SYMBOL(qmgr_release_queue);
3247 diff --git a/arch/arm/mach-ixp4xx/ixp4xx_npe.c b/arch/arm/mach-ixp4xx/ixp4xx_npe.c
3248 new file mode 100644
3249 index 0000000..83c137e
3251 +++ b/arch/arm/mach-ixp4xx/ixp4xx_npe.c
3254 + * Intel IXP4xx Network Processor Engine driver for Linux
3256 + * Copyright (C) 2007 Krzysztof Halasa <khc@pm.waw.pl>
3258 + * This program is free software; you can redistribute it and/or modify it
3259 + * under the terms of version 2 of the GNU General Public License
3260 + * as published by the Free Software Foundation.
3262 + * The code is based on publicly available information:
3263 + * - Intel IXP4xx Developer's Manual and other e-papers
3264 + * - Intel IXP400 Access Library Software (BSD license)
3265 + * - previous works by Christian Hohnstaedt <chohnstaedt@innominate.com>
3266 + * Thanks, Christian.
3269 +#include <linux/delay.h>
3270 +#include <linux/dma-mapping.h>
3271 +#include <linux/firmware.h>
3272 +#include <linux/io.h>
3273 +#include <linux/kernel.h>
3274 +#include <linux/module.h>
3275 +#include <linux/slab.h>
3276 +#include <asm/arch/npe.h>
3278 +#define DEBUG_MSG 0
3281 +#define NPE_COUNT 3
3282 +#define MAX_RETRIES 1000 /* microseconds */
3283 +#define NPE_42X_DATA_SIZE 0x800 /* in dwords */
3284 +#define NPE_46X_DATA_SIZE 0x1000
3285 +#define NPE_A_42X_INSTR_SIZE 0x1000
3286 +#define NPE_B_AND_C_42X_INSTR_SIZE 0x800
3287 +#define NPE_46X_INSTR_SIZE 0x1000
3288 +#define REGS_SIZE 0x1000
3290 +#define NPE_PHYS_REG 32
3292 +#define FW_MAGIC 0xFEEDF00D
3293 +#define FW_BLOCK_TYPE_INSTR 0x0
3294 +#define FW_BLOCK_TYPE_DATA 0x1
3295 +#define FW_BLOCK_TYPE_EOF 0xF
3297 +/* NPE exec status (read) and command (write) */
3298 +#define CMD_NPE_STEP 0x01
3299 +#define CMD_NPE_START 0x02
3300 +#define CMD_NPE_STOP 0x03
3301 +#define CMD_NPE_CLR_PIPE 0x04
3302 +#define CMD_CLR_PROFILE_CNT 0x0C
3303 +#define CMD_RD_INS_MEM 0x10 /* instruction memory */
3304 +#define CMD_WR_INS_MEM 0x11
3305 +#define CMD_RD_DATA_MEM 0x12 /* data memory */
3306 +#define CMD_WR_DATA_MEM 0x13
3307 +#define CMD_RD_ECS_REG 0x14 /* exec access register */
3308 +#define CMD_WR_ECS_REG 0x15
3310 +#define STAT_RUN 0x80000000
3311 +#define STAT_STOP 0x40000000
3312 +#define STAT_CLEAR 0x20000000
3313 +#define STAT_ECS_K 0x00800000 /* pipeline clean */
3315 +#define NPE_STEVT 0x1B
3316 +#define NPE_STARTPC 0x1C
3317 +#define NPE_REGMAP 0x1E
3318 +#define NPE_CINDEX 0x1F
3320 +#define INSTR_WR_REG_SHORT 0x0000C000
3321 +#define INSTR_WR_REG_BYTE 0x00004000
3322 +#define INSTR_RD_FIFO 0x0F888220
3323 +#define INSTR_RESET_MBOX 0x0FAC8210
3325 +#define ECS_BG_CTXT_REG_0 0x00 /* Background Executing Context */
3326 +#define ECS_BG_CTXT_REG_1 0x01 /* Stack level */
3327 +#define ECS_BG_CTXT_REG_2 0x02
3328 +#define ECS_PRI_1_CTXT_REG_0 0x04 /* Priority 1 Executing Context */
3329 +#define ECS_PRI_1_CTXT_REG_1 0x05 /* Stack level */
3330 +#define ECS_PRI_1_CTXT_REG_2 0x06
3331 +#define ECS_PRI_2_CTXT_REG_0 0x08 /* Priority 2 Executing Context */
3332 +#define ECS_PRI_2_CTXT_REG_1 0x09 /* Stack level */
3333 +#define ECS_PRI_2_CTXT_REG_2 0x0A
3334 +#define ECS_DBG_CTXT_REG_0 0x0C /* Debug Executing Context */
3335 +#define ECS_DBG_CTXT_REG_1 0x0D /* Stack level */
3336 +#define ECS_DBG_CTXT_REG_2 0x0E
3337 +#define ECS_INSTRUCT_REG 0x11 /* NPE Instruction Register */
3339 +#define ECS_REG_0_ACTIVE 0x80000000 /* all levels */
3340 +#define ECS_REG_0_NEXTPC_MASK 0x1FFF0000 /* BG/PRI1/PRI2 levels */
3341 +#define ECS_REG_0_LDUR_BITS 8
3342 +#define ECS_REG_0_LDUR_MASK 0x00000700 /* all levels */
3343 +#define ECS_REG_1_CCTXT_BITS 16
3344 +#define ECS_REG_1_CCTXT_MASK 0x000F0000 /* all levels */
3345 +#define ECS_REG_1_SELCTXT_BITS 0
3346 +#define ECS_REG_1_SELCTXT_MASK 0x0000000F /* all levels */
3347 +#define ECS_DBG_REG_2_IF 0x00100000 /* debug level */
3348 +#define ECS_DBG_REG_2_IE 0x00080000 /* debug level */
3350 +/* NPE watchpoint_fifo register bit */
3351 +#define WFIFO_VALID 0x80000000
3353 +/* NPE messaging_status register bit definitions */
3354 +#define MSGSTAT_OFNE 0x00010000 /* OutFifoNotEmpty */
3355 +#define MSGSTAT_IFNF 0x00020000 /* InFifoNotFull */
3356 +#define MSGSTAT_OFNF 0x00040000 /* OutFifoNotFull */
3357 +#define MSGSTAT_IFNE 0x00080000 /* InFifoNotEmpty */
3358 +#define MSGSTAT_MBINT 0x00100000 /* Mailbox interrupt */
3359 +#define MSGSTAT_IFINT 0x00200000 /* InFifo interrupt */
3360 +#define MSGSTAT_OFINT 0x00400000 /* OutFifo interrupt */
3361 +#define MSGSTAT_WFINT 0x00800000 /* WatchFifo interrupt */
3363 +/* NPE messaging_control register bit definitions */
3364 +#define MSGCTL_OUT_FIFO 0x00010000 /* enable output FIFO */
3365 +#define MSGCTL_IN_FIFO 0x00020000 /* enable input FIFO */
3366 +#define MSGCTL_OUT_FIFO_WRITE 0x01000000 /* enable FIFO + WRITE */
3367 +#define MSGCTL_IN_FIFO_WRITE 0x02000000
3369 +/* NPE mailbox_status value for reset */
3370 +#define RESET_MBOX_STAT 0x0000F0F0
3372 +const char *npe_names[] = { "NPE-A", "NPE-B", "NPE-C" };
3374 +#define print_npe(pri, npe, fmt, ...) \
3375 + printk(pri "%s: " fmt, npe_name(npe), ## __VA_ARGS__)
3378 +#define debug_msg(npe, fmt, ...) \
3379 + print_npe(KERN_DEBUG, npe, fmt, ## __VA_ARGS__)
3381 +#define debug_msg(npe, fmt, ...)
3387 + { ECS_BG_CTXT_REG_0, 0xA0000000 },
3388 + { ECS_BG_CTXT_REG_1, 0x01000000 },
3389 + { ECS_BG_CTXT_REG_2, 0x00008000 },
3390 + { ECS_PRI_1_CTXT_REG_0, 0x20000080 },
3391 + { ECS_PRI_1_CTXT_REG_1, 0x01000000 },
3392 + { ECS_PRI_1_CTXT_REG_2, 0x00008000 },
3393 + { ECS_PRI_2_CTXT_REG_0, 0x20000080 },
3394 + { ECS_PRI_2_CTXT_REG_1, 0x01000000 },
3395 + { ECS_PRI_2_CTXT_REG_2, 0x00008000 },
3396 + { ECS_DBG_CTXT_REG_0, 0x20000000 },
3397 + { ECS_DBG_CTXT_REG_1, 0x00000000 },
3398 + { ECS_DBG_CTXT_REG_2, 0x001E0000 },
3399 + { ECS_INSTRUCT_REG, 0x1003C00F },
3402 +static struct npe npe_tab[NPE_COUNT] = {
3405 + .regs = (struct npe_regs __iomem *)IXP4XX_NPEA_BASE_VIRT,
3406 + .regs_phys = IXP4XX_NPEA_BASE_PHYS,
3409 + .regs = (struct npe_regs __iomem *)IXP4XX_NPEB_BASE_VIRT,
3410 + .regs_phys = IXP4XX_NPEB_BASE_PHYS,
3413 + .regs = (struct npe_regs __iomem *)IXP4XX_NPEC_BASE_VIRT,
3414 + .regs_phys = IXP4XX_NPEC_BASE_PHYS,
3418 +int npe_running(struct npe *npe)
3420 + return (__raw_readl(&npe->regs->exec_status_cmd) & STAT_RUN) != 0;
3423 +static void npe_cmd_write(struct npe *npe, u32 addr, int cmd, u32 data)
3425 + __raw_writel(data, &npe->regs->exec_data);
3426 + __raw_writel(addr, &npe->regs->exec_addr);
3427 + __raw_writel(cmd, &npe->regs->exec_status_cmd);
3430 +static u32 npe_cmd_read(struct npe *npe, u32 addr, int cmd)
3432 + __raw_writel(addr, &npe->regs->exec_addr);
3433 + __raw_writel(cmd, &npe->regs->exec_status_cmd);
3434 + /* Iintroduce extra read cycles after issuing read command to NPE
3435 + so that we read the register after the NPE has updated it.
3436 + This is to overcome race condition between XScale and NPE */
3437 + __raw_readl(&npe->regs->exec_data);
3438 + __raw_readl(&npe->regs->exec_data);
3439 + return __raw_readl(&npe->regs->exec_data);
3442 +static void npe_clear_active(struct npe *npe, u32 reg)
3444 + u32 val = npe_cmd_read(npe, reg, CMD_RD_ECS_REG);
3445 + npe_cmd_write(npe, reg, CMD_WR_ECS_REG, val & ~ECS_REG_0_ACTIVE);
3448 +static void npe_start(struct npe *npe)
3450 + /* ensure only Background Context Stack Level is active */
3451 + npe_clear_active(npe, ECS_PRI_1_CTXT_REG_0);
3452 + npe_clear_active(npe, ECS_PRI_2_CTXT_REG_0);
3453 + npe_clear_active(npe, ECS_DBG_CTXT_REG_0);
3455 + __raw_writel(CMD_NPE_CLR_PIPE, &npe->regs->exec_status_cmd);
3456 + __raw_writel(CMD_NPE_START, &npe->regs->exec_status_cmd);
3459 +static void npe_stop(struct npe *npe)
3461 + __raw_writel(CMD_NPE_STOP, &npe->regs->exec_status_cmd);
3462 + __raw_writel(CMD_NPE_CLR_PIPE, &npe->regs->exec_status_cmd); /*FIXME?*/
3465 +static int __must_check npe_debug_instr(struct npe *npe, u32 instr, u32 ctx,
3471 + /* set the Active bit, and the LDUR, in the debug level */
3472 + npe_cmd_write(npe, ECS_DBG_CTXT_REG_0, CMD_WR_ECS_REG,
3473 + ECS_REG_0_ACTIVE | (ldur << ECS_REG_0_LDUR_BITS));
3475 + /* set CCTXT at ECS DEBUG L3 to specify in which context to execute
3476 + the instruction, and set SELCTXT at ECS DEBUG Level to specify
3477 + which context store to access.
3478 + Debug ECS Level Reg 1 has form 0x000n000n, where n = context number
3480 + npe_cmd_write(npe, ECS_DBG_CTXT_REG_1, CMD_WR_ECS_REG,
3481 + (ctx << ECS_REG_1_CCTXT_BITS) |
3482 + (ctx << ECS_REG_1_SELCTXT_BITS));
3484 + /* clear the pipeline */
3485 + __raw_writel(CMD_NPE_CLR_PIPE, &npe->regs->exec_status_cmd);
3487 + /* load NPE instruction into the instruction register */
3488 + npe_cmd_write(npe, ECS_INSTRUCT_REG, CMD_WR_ECS_REG, instr);
3490 + /* we need this value later to wait for completion of NPE execution
3492 + wc = __raw_readl(&npe->regs->watch_count);
3494 + /* issue a Step One command via the Execution Control register */
3495 + __raw_writel(CMD_NPE_STEP, &npe->regs->exec_status_cmd);
3497 + /* Watch Count register increments when NPE completes an instruction */
3498 + for (i = 0; i < MAX_RETRIES; i++) {
3499 + if (wc != __raw_readl(&npe->regs->watch_count))
3504 + print_npe(KERN_ERR, npe, "reset: npe_debug_instr(): timeout\n");
3505 + return -ETIMEDOUT;
3508 +static int __must_check npe_logical_reg_write8(struct npe *npe, u32 addr,
3511 + /* here we build the NPE assembler instruction: mov8 d0, #0 */
3512 + u32 instr = INSTR_WR_REG_BYTE | /* OpCode */
3513 + addr << 9 | /* base Operand */
3514 + (val & 0x1F) << 4 | /* lower 5 bits to immediate data */
3515 + (val & ~0x1F) << (18 - 5);/* higher 3 bits to CoProc instr. */
3516 + return npe_debug_instr(npe, instr, ctx, 1); /* execute it */
3519 +static int __must_check npe_logical_reg_write16(struct npe *npe, u32 addr,
3522 + /* here we build the NPE assembler instruction: mov16 d0, #0 */
3523 + u32 instr = INSTR_WR_REG_SHORT | /* OpCode */
3524 + addr << 9 | /* base Operand */
3525 + (val & 0x1F) << 4 | /* lower 5 bits to immediate data */
3526 + (val & ~0x1F) << (18 - 5);/* higher 11 bits to CoProc instr. */
3527 + return npe_debug_instr(npe, instr, ctx, 1); /* execute it */
3530 +static int __must_check npe_logical_reg_write32(struct npe *npe, u32 addr,
3533 + /* write in 16 bit steps first the high and then the low value */
3534 + if (npe_logical_reg_write16(npe, addr, val >> 16, ctx))
3535 + return -ETIMEDOUT;
3536 + return npe_logical_reg_write16(npe, addr + 2, val & 0xFFFF, ctx);
3539 +static int npe_reset(struct npe *npe)
3541 + u32 val, ctl, exec_count, ctx_reg2;
3544 + ctl = (__raw_readl(&npe->regs->messaging_control) | 0x3F000000) &
3547 + /* disable parity interrupt */
3548 + __raw_writel(ctl & 0x3F00FFFF, &npe->regs->messaging_control);
3550 + /* pre exec - debug instruction */
3551 + /* turn off the halt bit by clearing Execution Count register. */
3552 + exec_count = __raw_readl(&npe->regs->exec_count);
3553 + __raw_writel(0, &npe->regs->exec_count);
3554 + /* ensure that IF and IE are on (temporarily), so that we don't end up
3555 + stepping forever */
3556 + ctx_reg2 = npe_cmd_read(npe, ECS_DBG_CTXT_REG_2, CMD_RD_ECS_REG);
3557 + npe_cmd_write(npe, ECS_DBG_CTXT_REG_2, CMD_WR_ECS_REG, ctx_reg2 |
3558 + ECS_DBG_REG_2_IF | ECS_DBG_REG_2_IE);
3560 + /* clear the FIFOs */
3561 + while (__raw_readl(&npe->regs->watchpoint_fifo) & WFIFO_VALID)
3563 + while (__raw_readl(&npe->regs->messaging_status) & MSGSTAT_OFNE)
3564 + /* read from the outFIFO until empty */
3565 + print_npe(KERN_DEBUG, npe, "npe_reset: read FIFO = 0x%X\n",
3566 + __raw_readl(&npe->regs->in_out_fifo));
3568 + while (__raw_readl(&npe->regs->messaging_status) & MSGSTAT_IFNE)
3569 + /* step execution of the NPE intruction to read inFIFO using
3570 + the Debug Executing Context stack */
3571 + if (npe_debug_instr(npe, INSTR_RD_FIFO, 0, 0))
3572 + return -ETIMEDOUT;
3574 + /* reset the mailbox reg from the XScale side */
3575 + __raw_writel(RESET_MBOX_STAT, &npe->regs->mailbox_status);
3576 + /* from NPE side */
3577 + if (npe_debug_instr(npe, INSTR_RESET_MBOX, 0, 0))
3578 + return -ETIMEDOUT;
3580 + /* Reset the physical registers in the NPE register file */
3581 + for (val = 0; val < NPE_PHYS_REG; val++) {
3582 + if (npe_logical_reg_write16(npe, NPE_REGMAP, val >> 1, 0))
3583 + return -ETIMEDOUT;
3584 + /* address is either 0 or 4 */
3585 + if (npe_logical_reg_write32(npe, (val & 1) * 4, 0, 0))
3586 + return -ETIMEDOUT;
3589 + /* Reset the context store = each context's Context Store registers */
3591 + /* Context 0 has no STARTPC. Instead, this value is used to set NextPC
3592 + for Background ECS, to set where NPE starts executing code */
3593 + val = npe_cmd_read(npe, ECS_BG_CTXT_REG_0, CMD_RD_ECS_REG);
3594 + val &= ~ECS_REG_0_NEXTPC_MASK;
3595 + val |= (0 /* NextPC */ << 16) & ECS_REG_0_NEXTPC_MASK;
3596 + npe_cmd_write(npe, ECS_BG_CTXT_REG_0, CMD_WR_ECS_REG, val);
3598 + for (i = 0; i < 16; i++) {
3599 + if (i) { /* Context 0 has no STEVT nor STARTPC */
3600 + /* STEVT = off, 0x80 */
3601 + if (npe_logical_reg_write8(npe, NPE_STEVT, 0x80, i))
3602 + return -ETIMEDOUT;
3603 + if (npe_logical_reg_write16(npe, NPE_STARTPC, 0, i))
3604 + return -ETIMEDOUT;
3606 + /* REGMAP = d0->p0, d8->p2, d16->p4 */
3607 + if (npe_logical_reg_write16(npe, NPE_REGMAP, 0x820, i))
3608 + return -ETIMEDOUT;
3609 + if (npe_logical_reg_write8(npe, NPE_CINDEX, 0, i))
3610 + return -ETIMEDOUT;
3614 + /* clear active bit in debug level */
3615 + npe_cmd_write(npe, ECS_DBG_CTXT_REG_0, CMD_WR_ECS_REG, 0);
3616 + /* clear the pipeline */
3617 + __raw_writel(CMD_NPE_CLR_PIPE, &npe->regs->exec_status_cmd);
3618 + /* restore previous values */
3619 + __raw_writel(exec_count, &npe->regs->exec_count);
3620 + npe_cmd_write(npe, ECS_DBG_CTXT_REG_2, CMD_WR_ECS_REG, ctx_reg2);
3622 + /* write reset values to Execution Context Stack registers */
3623 + for (val = 0; val < ARRAY_SIZE(ecs_reset); val++)
3624 + npe_cmd_write(npe, ecs_reset[val].reg, CMD_WR_ECS_REG,
3625 + ecs_reset[val].val);
3627 + /* clear the profile counter */
3628 + __raw_writel(CMD_CLR_PROFILE_CNT, &npe->regs->exec_status_cmd);
3630 + __raw_writel(0, &npe->regs->exec_count);
3631 + __raw_writel(0, &npe->regs->action_points[0]);
3632 + __raw_writel(0, &npe->regs->action_points[1]);
3633 + __raw_writel(0, &npe->regs->action_points[2]);
3634 + __raw_writel(0, &npe->regs->action_points[3]);
3635 + __raw_writel(0, &npe->regs->watch_count);
3637 + val = ixp4xx_read_feature_bits();
3638 + /* reset the NPE */
3639 + ixp4xx_write_feature_bits(val &
3640 + ~(IXP4XX_FEATURE_RESET_NPEA << npe->id));
3641 + for (i = 0; i < MAX_RETRIES; i++) {
3642 + if (!(ixp4xx_read_feature_bits() &
3643 + (IXP4XX_FEATURE_RESET_NPEA << npe->id)))
3644 + break; /* reset completed */
3647 + if (i == MAX_RETRIES)
3648 + return -ETIMEDOUT;
3650 + /* deassert reset */
3651 + ixp4xx_write_feature_bits(val |
3652 + (IXP4XX_FEATURE_RESET_NPEA << npe->id));
3653 + for (i = 0; i < MAX_RETRIES; i++) {
3654 + if (ixp4xx_read_feature_bits() &
3655 + (IXP4XX_FEATURE_RESET_NPEA << npe->id))
3656 + break; /* NPE is back alive */
3659 + if (i == MAX_RETRIES)
3660 + return -ETIMEDOUT;
3664 + /* restore NPE configuration bus Control Register - parity settings */
3665 + __raw_writel(ctl, &npe->regs->messaging_control);
3670 +int npe_send_message(struct npe *npe, const void *msg, const char *what)
3672 + const u32 *send = msg;
3675 + debug_msg(npe, "Trying to send message %s [%08X:%08X]\n",
3676 + what, send[0], send[1]);
3678 + if (__raw_readl(&npe->regs->messaging_status) & MSGSTAT_IFNE) {
3679 + debug_msg(npe, "NPE input FIFO not empty\n");
3683 + __raw_writel(send[0], &npe->regs->in_out_fifo);
3685 + if (!(__raw_readl(&npe->regs->messaging_status) & MSGSTAT_IFNF)) {
3686 + debug_msg(npe, "NPE input FIFO full\n");
3690 + __raw_writel(send[1], &npe->regs->in_out_fifo);
3692 + while ((cycles < MAX_RETRIES) &&
3693 + (__raw_readl(&npe->regs->messaging_status) & MSGSTAT_IFNE)) {
3698 + if (cycles == MAX_RETRIES) {
3699 + debug_msg(npe, "Timeout sending message\n");
3700 + return -ETIMEDOUT;
3703 + debug_msg(npe, "Sending a message took %i cycles\n", cycles);
3707 +int npe_recv_message(struct npe *npe, void *msg, const char *what)
3710 + int cycles = 0, cnt = 0;
3712 + debug_msg(npe, "Trying to receive message %s\n", what);
3714 + while (cycles < MAX_RETRIES) {
3715 + if (__raw_readl(&npe->regs->messaging_status) & MSGSTAT_OFNE) {
3716 + recv[cnt++] = __raw_readl(&npe->regs->in_out_fifo);
3727 + debug_msg(npe, "Received [%08X]\n", recv[0]);
3730 + debug_msg(npe, "Received [%08X:%08X]\n", recv[0], recv[1]);
3734 + if (cycles == MAX_RETRIES) {
3735 + debug_msg(npe, "Timeout waiting for message\n");
3736 + return -ETIMEDOUT;
3739 + debug_msg(npe, "Receiving a message took %i cycles\n", cycles);
3743 +int npe_send_recv_message(struct npe *npe, void *msg, const char *what)
3746 + u32 *send = msg, recv[2];
3748 + if ((result = npe_send_message(npe, msg, what)) != 0)
3750 + if ((result = npe_recv_message(npe, recv, what)) != 0)
3753 + if ((recv[0] != send[0]) || (recv[1] != send[1])) {
3754 + debug_msg(npe, "Message %s: unexpected message received\n",
3762 +int npe_load_firmware(struct npe *npe, const char *name, struct device *dev)
3764 + const struct firmware *fw_entry;
3777 + struct dl_block blocks[0];
3781 + struct dl_codeblock {
3787 + int i, j, err, data_size, instr_size, blocks, table_end;
3790 + if ((err = request_firmware(&fw_entry, name, dev)) != 0)
3794 + if (fw_entry->size < sizeof(struct dl_image)) {
3795 + print_npe(KERN_ERR, npe, "incomplete firmware file\n");
3798 + image = (struct dl_image*)fw_entry->data;
3801 + print_npe(KERN_DEBUG, npe, "firmware: %08X %08X %08X (0x%X bytes)\n",
3802 + image->magic, image->id, image->size, image->size * 4);
3805 + if (image->magic == swab32(FW_MAGIC)) { /* swapped file */
3806 + image->id = swab32(image->id);
3807 + image->size = swab32(image->size);
3808 + } else if (image->magic != FW_MAGIC) {
3809 + print_npe(KERN_ERR, npe, "bad firmware file magic: 0x%X\n",
3813 + if ((image->size * 4 + sizeof(struct dl_image)) != fw_entry->size) {
3814 + print_npe(KERN_ERR, npe,
3815 + "inconsistent size of firmware file\n");
3818 + if (((image->id >> 24) & 0xF /* NPE ID */) != npe->id) {
3819 + print_npe(KERN_ERR, npe, "firmware file NPE ID mismatch\n");
3822 + if (image->magic == swab32(FW_MAGIC))
3823 + for (i = 0; i < image->size; i++)
3824 + image->data[i] = swab32(image->data[i]);
3826 + if (!cpu_is_ixp46x() && ((image->id >> 28) & 0xF /* device ID */)) {
3827 + print_npe(KERN_INFO, npe, "IXP46x firmware ignored on "
3832 + if (npe_running(npe)) {
3833 + print_npe(KERN_INFO, npe, "unable to load firmware, NPE is "
3834 + "already running\n");
3843 + print_npe(KERN_INFO, npe, "firmware functionality 0x%X, "
3844 + "revision 0x%X:%X\n", (image->id >> 16) & 0xFF,
3845 + (image->id >> 8) & 0xFF, image->id & 0xFF);
3847 + if (!cpu_is_ixp46x()) {
3849 + instr_size = NPE_A_42X_INSTR_SIZE;
3851 + instr_size = NPE_B_AND_C_42X_INSTR_SIZE;
3852 + data_size = NPE_42X_DATA_SIZE;
3854 + instr_size = NPE_46X_INSTR_SIZE;
3855 + data_size = NPE_46X_DATA_SIZE;
3858 + for (blocks = 0; blocks * sizeof(struct dl_block) / 4 < image->size;
3860 + if (image->blocks[blocks].type == FW_BLOCK_TYPE_EOF)
3862 + if (blocks * sizeof(struct dl_block) / 4 >= image->size) {
3863 + print_npe(KERN_INFO, npe, "firmware EOF block marker not "
3869 + print_npe(KERN_DEBUG, npe, "%i firmware blocks found\n", blocks);
3872 + table_end = blocks * sizeof(struct dl_block) / 4 + 1 /* EOF marker */;
3873 + for (i = 0, blk = image->blocks; i < blocks; i++, blk++) {
3874 + if (blk->offset > image->size - sizeof(struct dl_codeblock) / 4
3875 + || blk->offset < table_end) {
3876 + print_npe(KERN_INFO, npe, "invalid offset 0x%X of "
3877 + "firmware block #%i\n", blk->offset, i);
3881 + cb = (struct dl_codeblock*)&image->data[blk->offset];
3882 + if (blk->type == FW_BLOCK_TYPE_INSTR) {
3883 + if (cb->npe_addr + cb->size > instr_size)
3885 + cmd = CMD_WR_INS_MEM;
3886 + } else if (blk->type == FW_BLOCK_TYPE_DATA) {
3887 + if (cb->npe_addr + cb->size > data_size)
3889 + cmd = CMD_WR_DATA_MEM;
3891 + print_npe(KERN_INFO, npe, "invalid firmware block #%i "
3892 + "type 0x%X\n", i, blk->type);
3895 + if (blk->offset + sizeof(*cb) / 4 + cb->size > image->size) {
3896 + print_npe(KERN_INFO, npe, "firmware block #%i doesn't "
3897 + "fit in firmware image: type %c, start 0x%X,"
3898 + " length 0x%X\n", i,
3899 + blk->type == FW_BLOCK_TYPE_INSTR ? 'I' : 'D',
3900 + cb->npe_addr, cb->size);
3904 + for (j = 0; j < cb->size; j++)
3905 + npe_cmd_write(npe, cb->npe_addr + j, cmd, cb->data[j]);
3909 + if (!npe_running(npe))
3910 + print_npe(KERN_ERR, npe, "unable to start\n");
3911 + release_firmware(fw_entry);
3915 + print_npe(KERN_INFO, npe, "firmware block #%i doesn't fit in NPE "
3916 + "memory: type %c, start 0x%X, length 0x%X\n", i,
3917 + blk->type == FW_BLOCK_TYPE_INSTR ? 'I' : 'D',
3918 + cb->npe_addr, cb->size);
3920 + release_firmware(fw_entry);
3925 +struct npe *npe_request(int id)
3927 + if (id < NPE_COUNT)
3928 + if (npe_tab[id].valid)
3929 + if (try_module_get(THIS_MODULE))
3930 + return &npe_tab[id];
3934 +void npe_release(struct npe *npe)
3936 + module_put(THIS_MODULE);
3940 +static int __init npe_init_module(void)
3945 + for (i = 0; i < NPE_COUNT; i++) {
3946 + struct npe *npe = &npe_tab[i];
3947 + if (!(ixp4xx_read_feature_bits() &
3948 + (IXP4XX_FEATURE_RESET_NPEA << i)))
3949 + continue; /* NPE already disabled or not present */
3950 + if (!(npe->mem_res = request_mem_region(npe->regs_phys,
3952 + npe_name(npe)))) {
3953 + print_npe(KERN_ERR, npe,
3954 + "failed to request memory region\n");
3958 + if (npe_reset(npe))
3969 +static void __exit npe_cleanup_module(void)
3973 + for (i = 0; i < NPE_COUNT; i++)
3974 + if (npe_tab[i].mem_res) {
3975 + npe_reset(&npe_tab[i]);
3976 + release_resource(npe_tab[i].mem_res);
3980 +module_init(npe_init_module);
3981 +module_exit(npe_cleanup_module);
3983 +MODULE_AUTHOR("Krzysztof Halasa");
3984 +MODULE_LICENSE("GPL v2");
3986 +EXPORT_SYMBOL(npe_names);
3987 +EXPORT_SYMBOL(npe_running);
3988 +EXPORT_SYMBOL(npe_request);
3989 +EXPORT_SYMBOL(npe_release);
3990 +EXPORT_SYMBOL(npe_load_firmware);
3991 +EXPORT_SYMBOL(npe_send_message);
3992 +EXPORT_SYMBOL(npe_recv_message);
3993 +EXPORT_SYMBOL(npe_send_recv_message);
3996 From 35acb53f356e80efad803b9460986d9786dc9b96 Mon Sep 17 00:00:00 2001
3997 From: Krzysztof Halasa <khc@pm.waw.pl>
3998 Date: Tue, 29 Jan 2008 10:25:57 +1030
3999 Subject: Headers for IXP4xx built-in Ethernet and WAN drivers (Patch #4714)
4001 Adds platform structs and #defines required by drivers for
4002 IXP4xx built-in Ethernet and WAN (sync serial) ports.
4004 The actual drivers will reside in drivers/net/arm and
4005 drivers/net/wan and will be submitted separately.
4007 Signed-off-by: Krzysztof Halasa <khc@pm.waw.pl>
4008 Signed-off-by: Rod Whitby <rod@whitby.id.au>
4011 KernelVersion: 2.6.24-git5
4013 diff --git a/include/asm-arm/arch-ixp4xx/platform.h b/include/asm-arm/arch-ixp4xx/platform.h
4014 index 2ce28e3..a1f2b54 100644
4015 --- a/include/asm-arm/arch-ixp4xx/platform.h
4016 +++ b/include/asm-arm/arch-ixp4xx/platform.h
4017 @@ -91,6 +91,27 @@ struct ixp4xx_pata_data {
4021 +#define IXP4XX_ETH_NPEA 0x00
4022 +#define IXP4XX_ETH_NPEB 0x10
4023 +#define IXP4XX_ETH_NPEC 0x20
4025 +/* Information about built-in Ethernet MAC interfaces */
4026 +struct eth_plat_info {
4027 + u8 phy; /* MII PHY ID, 0 - 31 */
4028 + u8 rxq; /* configurable, currently 0 - 31 only */
4033 +/* Information about built-in HSS (synchronous serial) interfaces */
4034 +struct hss_plat_info {
4035 + int (*set_clock)(int port, unsigned int clock_type);
4036 + int (*open)(int port, void *pdev,
4037 + void (*set_carrier_cb)(void *pdev, int carrier));
4038 + void (*close)(int port, void *pdev);
4043 * Frequency of clock used for primary clocksource
4048 From 5a5be39c6411f2d6d8cead614f3f71af9fa4b4b4 Mon Sep 17 00:00:00 2001
4049 From: Krzysztof Halasa <khc@pm.waw.pl>
4050 Date: Fri, 1 Feb 2008 11:37:47 +1030
4051 Subject: Ethernet support for IXDP425 boards (Patch #4715)
4053 Adds IXDP425 platform support for two built-in 10/100 Ethernet ports.
4055 This patch will do nothing until the actual Ethernet driver is
4058 Signed-off-by: Krzysztof Halasa <khc@pm.waw.pl>
4061 KernelVersion: 2.6.23
4063 diff --git a/arch/arm/mach-ixp4xx/ixdp425-setup.c b/arch/arm/mach-ixp4xx/ixdp425-setup.c
4064 index e89070d..44584af 100644
4065 --- a/arch/arm/mach-ixp4xx/ixdp425-setup.c
4066 +++ b/arch/arm/mach-ixp4xx/ixdp425-setup.c
4067 @@ -177,6 +177,31 @@ static struct platform_device ixdp425_uart = {
4068 .resource = ixdp425_uart_resources
4071 +/* Built-in 10/100 Ethernet MAC interfaces */
4072 +static struct eth_plat_info ixdp425_plat_eth[] = {
4084 +static struct platform_device ixdp425_eth[] = {
4086 + .name = "ixp4xx_eth",
4087 + .id = IXP4XX_ETH_NPEB,
4088 + .dev.platform_data = ixdp425_plat_eth,
4090 + .name = "ixp4xx_eth",
4091 + .id = IXP4XX_ETH_NPEC,
4092 + .dev.platform_data = ixdp425_plat_eth + 1,
4096 static struct platform_device *ixdp425_devices[] __initdata = {
4099 @@ -184,7 +209,9 @@ static struct platform_device *ixdp425_devices[] __initdata = {
4100 defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
4101 &ixdp425_flash_nand,
4109 static void __init ixdp425_init(void)