1 Index: linux-2.6.25.1/drivers/net/wan/Kconfig
2 ===================================================================
3 --- linux-2.6.25.1.orig/drivers/net/wan/Kconfig
4 +++ linux-2.6.25.1/drivers/net/wan/Kconfig
5 @@ -338,6 +338,15 @@ config DSCC4_PCI_RST
7 Say Y if your card supports this feature.
10 + tristate "IXP4xx HSS (synchronous serial port) support"
11 + depends on HDLC && ARM && ARCH_IXP4XX
15 + Say Y here if you want to use built-in HSS ports
16 + on IXP4xx processor.
19 tristate "Frame Relay DLCI support"
21 Index: linux-2.6.25.1/drivers/net/wan/Makefile
22 ===================================================================
23 --- linux-2.6.25.1.orig/drivers/net/wan/Makefile
24 +++ linux-2.6.25.1/drivers/net/wan/Makefile
25 @@ -42,6 +42,7 @@ obj-$(CONFIG_C101) += c101.o
26 obj-$(CONFIG_WANXL) += wanxl.o
27 obj-$(CONFIG_PCI200SYN) += pci200syn.o
28 obj-$(CONFIG_PC300TOO) += pc300too.o
29 +obj-$(CONFIG_IXP4XX_HSS) += ixp4xx_hss.o
31 clean-files := wanxlfw.inc
32 $(obj)/wanxl.o: $(obj)/wanxlfw.inc
33 Index: linux-2.6.25.1/drivers/net/wan/ixp4xx_hss.c
34 ===================================================================
36 +++ linux-2.6.25.1/drivers/net/wan/ixp4xx_hss.c
39 + * Intel IXP4xx HSS (synchronous serial port) driver for Linux
41 + * Copyright (C) 2007 Krzysztof Halasa <khc@pm.waw.pl>
43 + * This program is free software; you can redistribute it and/or modify it
44 + * under the terms of version 2 of the GNU General Public License
45 + * as published by the Free Software Foundation.
48 +#include <linux/bitops.h>
49 +#include <linux/cdev.h>
50 +#include <linux/dma-mapping.h>
51 +#include <linux/dmapool.h>
52 +#include <linux/fs.h>
53 +#include <linux/io.h>
54 +#include <linux/kernel.h>
55 +#include <linux/hdlc.h>
56 +#include <linux/platform_device.h>
57 +#include <linux/poll.h>
58 +#include <asm/arch/npe.h>
59 +#include <asm/arch/qmgr.h>
61 +#define DEBUG_QUEUES 0
65 +#define DEBUG_PKT_BYTES 0
66 +#define DEBUG_CLOSE 0
67 +#define DEBUG_FRAMER 0
69 +#define DRV_NAME "ixp4xx_hss"
71 +#define PKT_EXTRA_FLAGS 0 /* orig 1 */
72 +#define TX_FRAME_SYNC_OFFSET 0 /* channelized */
73 +#define PKT_NUM_PIPES 1 /* 1, 2 or 4 */
74 +#define PKT_PIPE_FIFO_SIZEW 4 /* total 4 dwords per HSS */
76 +#define RX_DESCS 16 /* also length of all RX queues */
77 +#define TX_DESCS 16 /* also length of all TX queues */
79 +#define POOL_ALLOC_SIZE (sizeof(struct desc) * (RX_DESCS + TX_DESCS))
80 +#define RX_SIZE (HDLC_MAX_MRU + 4) /* NPE needs more space */
81 +#define MAX_CLOSE_WAIT 1000 /* microseconds */
83 +#define MIN_FRAME_SIZE 16 /* bits */
84 +#define MAX_FRAME_SIZE 257 /* 256 bits + framing bit */
85 +#define MAX_CHANNELS (MAX_FRAME_SIZE / 8)
86 +#define MAX_CHAN_DEVICES 32
87 +#define CHANNEL_HDLC 0xFE
88 +#define CHANNEL_UNUSED 0xFF
90 +#define NAPI_WEIGHT 16
91 +#define CHAN_RX_TRIGGER 16 /* 8 RX frames = 1 ms @ E1 */
92 +#define CHAN_RX_FRAMES 64
93 +#define MAX_CHAN_RX_BAD_SYNC (CHAN_RX_TRIGGER / 2 /* pairs */ - 3)
94 +#define CHAN_TX_LIST_FRAMES 16 /* bytes/channel per list, 16 - 48 */
95 +#define CHAN_TX_LISTS 8
96 +#define CHAN_TX_FRAMES (CHAN_TX_LIST_FRAMES * CHAN_TX_LISTS)
97 +#define CHAN_QUEUE_LEN 16 /* minimum possible */
101 +#define HSS0_CHL_RXTRIG_QUEUE 12 /* orig size = 32 dwords */
102 +#define HSS0_PKT_RX_QUEUE 13 /* orig size = 32 dwords */
103 +#define HSS0_PKT_TX0_QUEUE 14 /* orig size = 16 dwords */
104 +#define HSS0_PKT_TX1_QUEUE 15
105 +#define HSS0_PKT_TX2_QUEUE 16
106 +#define HSS0_PKT_TX3_QUEUE 17
107 +#define HSS0_PKT_RXFREE0_QUEUE 18 /* orig size = 16 dwords */
108 +#define HSS0_PKT_RXFREE1_QUEUE 19
109 +#define HSS0_PKT_RXFREE2_QUEUE 20
110 +#define HSS0_PKT_RXFREE3_QUEUE 21
111 +#define HSS0_PKT_TXDONE_QUEUE 22 /* orig size = 64 dwords */
113 +#define HSS1_CHL_RXTRIG_QUEUE 10
114 +#define HSS1_PKT_RX_QUEUE 0
115 +#define HSS1_PKT_TX0_QUEUE 5
116 +#define HSS1_PKT_TX1_QUEUE 6
117 +#define HSS1_PKT_TX2_QUEUE 7
118 +#define HSS1_PKT_TX3_QUEUE 8
119 +#define HSS1_PKT_RXFREE0_QUEUE 1
120 +#define HSS1_PKT_RXFREE1_QUEUE 2
121 +#define HSS1_PKT_RXFREE2_QUEUE 3
122 +#define HSS1_PKT_RXFREE3_QUEUE 4
123 +#define HSS1_PKT_TXDONE_QUEUE 9
125 +#define NPE_PKT_MODE_HDLC 0
126 +#define NPE_PKT_MODE_RAW 1
127 +#define NPE_PKT_MODE_56KMODE 2
128 +#define NPE_PKT_MODE_56KENDIAN_MSB 4
130 +/* PKT_PIPE_HDLC_CFG_WRITE flags */
131 +#define PKT_HDLC_IDLE_ONES 0x1 /* default = flags */
132 +#define PKT_HDLC_CRC_32 0x2 /* default = CRC-16 */
133 +#define PKT_HDLC_MSB_ENDIAN 0x4 /* default = LE */
136 +/* hss_config, PCRs */
137 +/* Frame sync sampling, default = active low */
138 +#define PCR_FRM_SYNC_ACTIVE_HIGH 0x40000000
139 +#define PCR_FRM_SYNC_FALLINGEDGE 0x80000000
140 +#define PCR_FRM_SYNC_RISINGEDGE 0xC0000000
142 +/* Frame sync pin: input (default) or output generated off a given clk edge */
143 +#define PCR_FRM_SYNC_OUTPUT_FALLING 0x20000000
144 +#define PCR_FRM_SYNC_OUTPUT_RISING 0x30000000
146 +/* Frame and data clock sampling on edge, default = falling */
147 +#define PCR_FCLK_EDGE_RISING 0x08000000
148 +#define PCR_DCLK_EDGE_RISING 0x04000000
150 +/* Clock direction, default = input */
151 +#define PCR_SYNC_CLK_DIR_OUTPUT 0x02000000
153 +/* Generate/Receive frame pulses, default = enabled */
154 +#define PCR_FRM_PULSE_DISABLED 0x01000000
156 + /* Data rate is full (default) or half the configured clk speed */
157 +#define PCR_HALF_CLK_RATE 0x00200000
159 +/* Invert data between NPE and HSS FIFOs? (default = no) */
160 +#define PCR_DATA_POLARITY_INVERT 0x00100000
162 +/* TX/RX endianness, default = LSB */
163 +#define PCR_MSB_ENDIAN 0x00080000
165 +/* Normal (default) / open drain mode (TX only) */
166 +#define PCR_TX_PINS_OPEN_DRAIN 0x00040000
168 +/* No framing bit transmitted and expected on RX? (default = framing bit) */
169 +#define PCR_SOF_NO_FBIT 0x00020000
171 +/* Drive data pins? */
172 +#define PCR_TX_DATA_ENABLE 0x00010000
174 +/* Voice 56k type: drive the data pins low (default), high, high Z */
175 +#define PCR_TX_V56K_HIGH 0x00002000
176 +#define PCR_TX_V56K_HIGH_IMP 0x00004000
178 +/* Unassigned type: drive the data pins low (default), high, high Z */
179 +#define PCR_TX_UNASS_HIGH 0x00000800
180 +#define PCR_TX_UNASS_HIGH_IMP 0x00001000
182 +/* T1 @ 1.544MHz only: Fbit dictated in FIFO (default) or high Z */
183 +#define PCR_TX_FB_HIGH_IMP 0x00000400
185 +/* 56k data endiannes - which bit unused: high (default) or low */
186 +#define PCR_TX_56KE_BIT_0_UNUSED 0x00000200
188 +/* 56k data transmission type: 32/8 bit data (default) or 56K data */
189 +#define PCR_TX_56KS_56K_DATA 0x00000100
191 +/* hss_config, cCR */
192 +/* Number of packetized clients, default = 1 */
193 +#define CCR_NPE_HFIFO_2_HDLC 0x04000000
194 +#define CCR_NPE_HFIFO_3_OR_4HDLC 0x08000000
196 +/* default = no loopback */
197 +#define CCR_LOOPBACK 0x02000000
199 +/* HSS number, default = 0 (first) */
200 +#define CCR_SECOND_HSS 0x01000000
203 +/* hss_config, clkCR: main:10, num:10, denom:12 */
204 +#define CLK42X_SPEED_EXP ((0x3FF << 22) | ( 2 << 12) | 15) /*65 KHz*/
206 +#define CLK42X_SPEED_512KHZ (( 130 << 22) | ( 2 << 12) | 15)
207 +#define CLK42X_SPEED_1536KHZ (( 43 << 22) | ( 18 << 12) | 47)
208 +#define CLK42X_SPEED_1544KHZ (( 43 << 22) | ( 33 << 12) | 192)
209 +#define CLK42X_SPEED_2048KHZ (( 32 << 22) | ( 34 << 12) | 63)
210 +#define CLK42X_SPEED_4096KHZ (( 16 << 22) | ( 34 << 12) | 127)
211 +#define CLK42X_SPEED_8192KHZ (( 8 << 22) | ( 34 << 12) | 255)
213 +#define CLK46X_SPEED_512KHZ (( 130 << 22) | ( 24 << 12) | 127)
214 +#define CLK46X_SPEED_1536KHZ (( 43 << 22) | (152 << 12) | 383)
215 +#define CLK46X_SPEED_1544KHZ (( 43 << 22) | ( 66 << 12) | 385)
216 +#define CLK46X_SPEED_2048KHZ (( 32 << 22) | (280 << 12) | 511)
217 +#define CLK46X_SPEED_4096KHZ (( 16 << 22) | (280 << 12) | 1023)
218 +#define CLK46X_SPEED_8192KHZ (( 8 << 22) | (280 << 12) | 2047)
221 +/* hss_config, LUT entries */
222 +#define TDMMAP_UNASSIGNED 0
223 +#define TDMMAP_HDLC 1 /* HDLC - packetized */
224 +#define TDMMAP_VOICE56K 2 /* Voice56K - 7-bit channelized */
225 +#define TDMMAP_VOICE64K 3 /* Voice64K - 8-bit channelized */
227 +/* offsets into HSS config */
228 +#define HSS_CONFIG_TX_PCR 0x00 /* port configuration registers */
229 +#define HSS_CONFIG_RX_PCR 0x04
230 +#define HSS_CONFIG_CORE_CR 0x08 /* loopback control, HSS# */
231 +#define HSS_CONFIG_CLOCK_CR 0x0C /* clock generator control */
232 +#define HSS_CONFIG_TX_FCR 0x10 /* frame configuration registers */
233 +#define HSS_CONFIG_RX_FCR 0x14
234 +#define HSS_CONFIG_TX_LUT 0x18 /* channel look-up tables */
235 +#define HSS_CONFIG_RX_LUT 0x38
238 +/* NPE command codes */
239 +/* writes the ConfigWord value to the location specified by offset */
240 +#define PORT_CONFIG_WRITE 0x40
242 +/* triggers the NPE to load the contents of the configuration table */
243 +#define PORT_CONFIG_LOAD 0x41
245 +/* triggers the NPE to return an HssErrorReadResponse message */
246 +#define PORT_ERROR_READ 0x42
248 +/* reset NPE internal status and enable the HssChannelized operation */
249 +#define CHAN_FLOW_ENABLE 0x43
250 +#define CHAN_FLOW_DISABLE 0x44
251 +#define CHAN_IDLE_PATTERN_WRITE 0x45
252 +#define CHAN_NUM_CHANS_WRITE 0x46
253 +#define CHAN_RX_BUF_ADDR_WRITE 0x47
254 +#define CHAN_RX_BUF_CFG_WRITE 0x48
255 +#define CHAN_TX_BLK_CFG_WRITE 0x49
256 +#define CHAN_TX_BUF_ADDR_WRITE 0x4A
257 +#define CHAN_TX_BUF_SIZE_WRITE 0x4B
258 +#define CHAN_TSLOTSWITCH_ENABLE 0x4C
259 +#define CHAN_TSLOTSWITCH_DISABLE 0x4D
261 +/* downloads the gainWord value for a timeslot switching channel associated
263 +#define CHAN_TSLOTSWITCH_GCT_DOWNLOAD 0x4E
265 +/* triggers the NPE to reset internal status and enable the HssPacketized
266 + operation for the flow specified by pPipe */
267 +#define PKT_PIPE_FLOW_ENABLE 0x50
268 +#define PKT_PIPE_FLOW_DISABLE 0x51
269 +#define PKT_NUM_PIPES_WRITE 0x52
270 +#define PKT_PIPE_FIFO_SIZEW_WRITE 0x53
271 +#define PKT_PIPE_HDLC_CFG_WRITE 0x54
272 +#define PKT_PIPE_IDLE_PATTERN_WRITE 0x55
273 +#define PKT_PIPE_RX_SIZE_WRITE 0x56
274 +#define PKT_PIPE_MODE_WRITE 0x57
276 +/* HDLC packet status values - desc->status */
277 +#define ERR_SHUTDOWN 1 /* stop or shutdown occurrance */
278 +#define ERR_HDLC_ALIGN 2 /* HDLC alignment error */
279 +#define ERR_HDLC_FCS 3 /* HDLC Frame Check Sum error */
280 +#define ERR_RXFREE_Q_EMPTY 4 /* RX-free queue became empty while receiving
281 + this packet (if buf_len < pkt_len) */
282 +#define ERR_HDLC_TOO_LONG 5 /* HDLC frame size too long */
283 +#define ERR_HDLC_ABORT 6 /* abort sequence received */
284 +#define ERR_DISCONNECTING 7 /* disconnect is in progress */
287 +enum mode {MODE_HDLC = 0, MODE_RAW, MODE_G704};
288 +enum error_bit {TX_ERROR_BIT = 0, RX_ERROR_BIT = 1};
289 +enum alignment { NOT_ALIGNED = 0, EVEN_FIRST, ODD_FIRST };
292 +typedef struct sk_buff buffer_t;
293 +#define free_buffer dev_kfree_skb
294 +#define free_buffer_irq dev_kfree_skb_irq
296 +typedef void buffer_t;
297 +#define free_buffer kfree
298 +#define free_buffer_irq kfree
301 +struct chan_device {
303 + struct device *dev;
305 + unsigned int open_count, excl_open;
306 + unsigned int tx_first, tx_count, rx_first, rx_count; /* bytes */
307 + unsigned long errors_bitmap;
309 + u8 log_channels[MAX_CHANNELS];
313 + struct device *dev;
315 + struct net_device *netdev;
316 + struct napi_struct napi;
317 + struct hss_plat_info *plat;
318 + buffer_t *rx_buff_tab[RX_DESCS], *tx_buff_tab[TX_DESCS];
319 + struct desc *desc_tab; /* coherent */
322 + atomic_t chan_tx_irq_number, chan_rx_irq_number;
323 + wait_queue_head_t chan_tx_waitq, chan_rx_waitq;
326 + /* the following fields must be protected by npe_lock */
328 + unsigned int clock_type, clock_rate, loopback;
329 + unsigned int frame_size, frame_sync_offset;
331 + struct chan_device *chan_devices[MAX_CHAN_DEVICES];
333 + u32 chan_tx_buf_phys, chan_rx_buf_phys;
334 + unsigned int chan_open_count, hdlc_open;
335 + unsigned int chan_started, initialized, just_set_offset;
336 + enum alignment aligned, carrier;
337 + unsigned int chan_last_rx, chan_last_tx;
338 + /* assigned channels, may be invalid with given frame length or mode */
339 + u8 channels[MAX_CHANNELS];
343 +/* NPE message structure */
346 + u8 cmd, unused, hss_port, index;
348 + struct { u8 data8a, data8b, data8c, data8d; };
349 + struct { u16 data16a, data16b; };
350 + struct { u32 data32; };
353 + u8 index, hss_port, unused, cmd;
355 + struct { u8 data8d, data8c, data8b, data8a; };
356 + struct { u16 data16b, data16a; };
357 + struct { u32 data32; };
362 +/* HDLC packet descriptor */
364 + u32 next; /* pointer to next buffer, unused */
367 + u16 buf_len; /* buffer length */
368 + u16 pkt_len; /* packet length */
369 + u32 data; /* pointer to data buffer in RAM */
374 + u16 pkt_len; /* packet length */
375 + u16 buf_len; /* buffer length */
376 + u32 data; /* pointer to data buffer in RAM */
381 + u32 __reserved1[4];
385 +#define rx_desc_phys(port, n) ((port)->desc_tab_phys + \
386 + (n) * sizeof(struct desc))
387 +#define rx_desc_ptr(port, n) (&(port)->desc_tab[n])
389 +#define tx_desc_phys(port, n) ((port)->desc_tab_phys + \
390 + ((n) + RX_DESCS) * sizeof(struct desc))
391 +#define tx_desc_ptr(port, n) (&(port)->desc_tab[(n) + RX_DESCS])
393 +#define chan_tx_buf_len(port) (port->frame_size / 8 * CHAN_TX_FRAMES)
394 +#define chan_tx_lists_len(port) (port->frame_size / 8 * CHAN_TX_LISTS * \
396 +#define chan_rx_buf_len(port) (port->frame_size / 8 * CHAN_RX_FRAMES)
398 +#define chan_tx_buf(port) ((port)->chan_buf)
399 +#define chan_tx_lists(port) (chan_tx_buf(port) + chan_tx_buf_len(port))
400 +#define chan_rx_buf(port) (chan_tx_lists(port) + chan_tx_lists_len(port))
402 +#define chan_tx_lists_phys(port) ((port)->chan_tx_buf_phys + \
403 + chan_tx_buf_len(port))
405 +static int hss_prepare_chan(struct port *port);
406 +void hss_chan_stop(struct port *port);
408 +/*****************************************************************************
410 + ****************************************************************************/
412 +static struct class *hss_class;
413 +static int chan_major;
414 +static int ports_open;
415 +static struct dma_pool *dma_pool;
416 +static spinlock_t npe_lock;
418 +static const struct {
419 + int tx, txdone, rx, rxfree, chan;
420 +}queue_ids[2] = {{HSS0_PKT_TX0_QUEUE, HSS0_PKT_TXDONE_QUEUE, HSS0_PKT_RX_QUEUE,
421 + HSS0_PKT_RXFREE0_QUEUE, HSS0_CHL_RXTRIG_QUEUE},
422 + {HSS1_PKT_TX0_QUEUE, HSS1_PKT_TXDONE_QUEUE, HSS1_PKT_RX_QUEUE,
423 + HSS1_PKT_RXFREE0_QUEUE, HSS1_CHL_RXTRIG_QUEUE},
426 +/*****************************************************************************
427 + * utility functions
428 + ****************************************************************************/
430 +static inline struct port* dev_to_port(struct net_device *dev)
432 + return dev_to_hdlc(dev)->priv;
435 +static inline struct chan_device* inode_to_chan_dev(struct inode *inode)
437 + return container_of(inode->i_cdev, struct chan_device, cdev);
441 +static inline void memcpy_swab32(u32 *dest, u32 *src, int cnt)
444 + for (i = 0; i < cnt; i++)
445 + dest[i] = swab32(src[i]);
449 +static int get_number(const char **buf, size_t *len, unsigned int *ptr,
450 + unsigned int min, unsigned int max)
453 + unsigned long val = simple_strtoul(*buf, &endp, 10);
455 + if (endp == *buf || endp - *buf > *len || val < min || val > max)
457 + *len -= endp - *buf;
463 +static int parse_channels(const char **buf, size_t *len, u8 *channels)
465 + unsigned int ch, next = 0;
467 + if (*len && (*buf)[*len - 1] == '\n')
470 + memset(channels, 0, MAX_CHANNELS);
475 + /* Format: "A,B-C,...", A > B > C */
477 + if (get_number(buf, len, &ch, next, MAX_CHANNELS - 1))
483 + if (**buf == ',') {
492 + if (get_number(buf, len, &ch, next, MAX_CHANNELS - 1))
495 + channels[next++] = 1;
506 +static size_t print_channels(struct port *port, char *buf, u8 id)
508 + unsigned int ch, cnt = 0;
511 + for (ch = 0; ch < MAX_CHANNELS; ch++)
512 + if (port->channels[ch] == id) {
514 + sprintf(buf + len, "%s%u", len ? "," : "", ch);
515 + len += strlen(buf + len);
520 + sprintf(buf + len, "-%u", ch - 1);
521 + len += strlen(buf + len);
526 + sprintf(buf + len, "-%u", ch - 1);
527 + len += strlen(buf + len);
534 +static inline unsigned int sub_offset(unsigned int a, unsigned int b,
535 + unsigned int modulo)
537 + return (modulo /* make sure the result >= 0 */ + a - b) % modulo;
540 +/*****************************************************************************
542 + ****************************************************************************/
544 +static void hss_config_load(struct port *port)
549 + memset(&msg, 0, sizeof(msg));
550 + msg.cmd = PORT_CONFIG_LOAD;
551 + msg.hss_port = port->id;
552 + if (npe_send_message(port->npe, &msg, "HSS_LOAD_CONFIG"))
554 + if (npe_recv_message(port->npe, &msg, "HSS_LOAD_CONFIG"))
557 + /* HSS_LOAD_CONFIG for port #1 returns port_id = #4 */
558 + if (msg.cmd != PORT_CONFIG_LOAD || msg.data32)
561 + /* HDLC may stop working without this */
562 + npe_recv_message(port->npe, &msg, "FLUSH_IT");
566 + printk(KERN_CRIT "HSS-%i: unable to reload HSS configuration\n",
571 +static void hss_config_set_pcr(struct port *port)
576 + memset(&msg, 0, sizeof(msg));
577 + msg.cmd = PORT_CONFIG_WRITE;
578 + msg.hss_port = port->id;
579 + msg.index = HSS_CONFIG_TX_PCR;
580 + msg.data32 = PCR_FRM_SYNC_OUTPUT_RISING | PCR_MSB_ENDIAN |
581 + PCR_TX_DATA_ENABLE;
582 + if (port->frame_size % 8 == 0)
583 + msg.data32 |= PCR_SOF_NO_FBIT;
584 + if (port->clock_type == CLOCK_INT)
585 + msg.data32 |= PCR_SYNC_CLK_DIR_OUTPUT;
586 + if (npe_send_message(port->npe, &msg, "HSS_SET_TX_PCR"))
589 + msg.index = HSS_CONFIG_RX_PCR;
590 + msg.data32 ^= PCR_TX_DATA_ENABLE | PCR_DCLK_EDGE_RISING;
591 + if (npe_send_message(port->npe, &msg, "HSS_SET_RX_PCR"))
596 + printk(KERN_CRIT "HSS-%i: unable to set HSS PCR registers\n", port->id);
600 +static void hss_config_set_hdlc_cfg(struct port *port)
604 + memset(&msg, 0, sizeof(msg));
605 + msg.cmd = PKT_PIPE_HDLC_CFG_WRITE;
606 + msg.hss_port = port->id;
607 + msg.data8a = port->hdlc_cfg; /* rx_cfg */
608 + msg.data8b = port->hdlc_cfg | (PKT_EXTRA_FLAGS << 3); /* tx_cfg */
609 + if (npe_send_message(port->npe, &msg, "HSS_SET_HDLC_CFG")) {
610 + printk(KERN_CRIT "HSS-%i: unable to set HSS HDLC"
611 + " configuration\n", port->id);
616 +static void hss_config_set_core(struct port *port)
620 + memset(&msg, 0, sizeof(msg));
621 + msg.cmd = PORT_CONFIG_WRITE;
622 + msg.hss_port = port->id;
623 + msg.index = HSS_CONFIG_CORE_CR;
624 + msg.data32 = (port->loopback ? CCR_LOOPBACK : 0) |
625 + (port->id ? CCR_SECOND_HSS : 0);
626 + if (npe_send_message(port->npe, &msg, "HSS_SET_CORE_CR")) {
627 + printk(KERN_CRIT "HSS-%i: unable to set HSS core control"
628 + " register\n", port->id);
633 +static void hss_config_set_line(struct port *port)
637 + hss_config_set_pcr(port);
638 + hss_config_set_core(port);
640 + memset(&msg, 0, sizeof(msg));
641 + msg.cmd = PORT_CONFIG_WRITE;
642 + msg.hss_port = port->id;
643 + msg.index = HSS_CONFIG_CLOCK_CR;
644 + msg.data32 = CLK42X_SPEED_2048KHZ /* FIXME */;
645 + if (npe_send_message(port->npe, &msg, "HSS_SET_CLOCK_CR")) {
646 + printk(KERN_CRIT "HSS-%i: unable to set HSS clock control"
647 + " register\n", port->id);
652 +static void hss_config_set_rx_frame(struct port *port)
656 + memset(&msg, 0, sizeof(msg));
657 + msg.cmd = PORT_CONFIG_WRITE;
658 + msg.hss_port = port->id;
659 + msg.index = HSS_CONFIG_RX_FCR;
660 + msg.data16a = port->frame_sync_offset;
661 + msg.data16b = port->frame_size - 1;
662 + if (npe_send_message(port->npe, &msg, "HSS_SET_RX_FCR")) {
663 + printk(KERN_CRIT "HSS-%i: unable to set HSS RX frame size"
664 + " and offset\n", port->id);
669 +static void hss_config_set_frame(struct port *port)
673 + memset(&msg, 0, sizeof(msg));
674 + msg.cmd = PORT_CONFIG_WRITE;
675 + msg.hss_port = port->id;
676 + msg.index = HSS_CONFIG_TX_FCR;
677 + msg.data16a = TX_FRAME_SYNC_OFFSET;
678 + msg.data16b = port->frame_size - 1;
679 + if (npe_send_message(port->npe, &msg, "HSS_SET_TX_FCR")) {
680 + printk(KERN_CRIT "HSS-%i: unable to set HSS TX frame size"
681 + " and offset\n", port->id);
684 + hss_config_set_rx_frame(port);
687 +static void hss_config_set_lut(struct port *port)
690 + int chan_count = 0, log_chan = 0, i, ch;
691 + u32 lut[MAX_CHANNELS / 4];
693 + memset(lut, 0, sizeof(lut));
694 + for (i = 0; i < MAX_CHAN_DEVICES; i++)
695 + if (port->chan_devices[i])
696 + port->chan_devices[i]->chan_count = 0;
698 + memset(&msg, 0, sizeof(msg));
699 + msg.cmd = PORT_CONFIG_WRITE;
700 + msg.hss_port = port->id;
702 + for (ch = 0; ch < MAX_CHANNELS; ch++) {
703 + struct chan_device *chdev = NULL;
704 + unsigned int entry;
706 + if (port->channels[ch] < MAX_CHAN_DEVICES /* assigned */)
707 + chdev = port->chan_devices[port->channels[ch]];
709 + if (port->mode == MODE_G704 && ch == 0)
710 + entry = TDMMAP_VOICE64K; /* PCM-31 pattern */
711 + else if (port->mode == MODE_HDLC ||
712 + port->channels[ch] == CHANNEL_HDLC)
713 + entry = TDMMAP_HDLC;
714 + else if (chdev && chdev->open_count) {
715 + entry = TDMMAP_VOICE64K;
716 + chdev->log_channels[chdev->chan_count++] = log_chan;
718 + entry = TDMMAP_UNASSIGNED;
719 + if (entry == TDMMAP_VOICE64K) {
725 + msg.data32 |= entry << 30;
727 + if (ch % 16 == 15) {
728 + msg.index = HSS_CONFIG_TX_LUT + ((ch / 4) & ~3);
729 + if (npe_send_message(port->npe, &msg, "HSS_SET_TX_LUT"))
732 + msg.index += HSS_CONFIG_RX_LUT - HSS_CONFIG_TX_LUT;
733 + if (npe_send_message(port->npe, &msg, "HSS_SET_RX_LUT"))
737 + if (ch != MAX_CHANNELS) {
738 + printk(KERN_CRIT "HSS-%i: unable to set HSS channel look-up"
739 + " table\n", port->id);
743 + hss_config_set_frame(port);
748 + memset(&msg, 0, sizeof(msg));
749 + msg.cmd = CHAN_NUM_CHANS_WRITE;
750 + msg.hss_port = port->id;
751 + msg.data8a = chan_count;
752 + if (npe_send_message(port->npe, &msg, "CHAN_NUM_CHANS_WRITE")) {
753 + printk(KERN_CRIT "HSS-%i: unable to set HSS channel count\n",
758 + /* don't leak data */
759 + // FIXME memset(chan_tx_buf(port), 0, CHAN_TX_FRAMES * chan_count);
760 + if (port->mode == MODE_G704) /* G.704 PCM-31 sync pattern */
761 + for (i = 0; i < CHAN_TX_FRAMES; i += 4)
762 + *(u32*)(chan_tx_buf(port) + i) = 0x9BDF9BDF;
764 + for (i = 0; i < CHAN_TX_LISTS; i++) {
765 + u32 phys = port->chan_tx_buf_phys + i * CHAN_TX_LIST_FRAMES;
766 + u32 *list = ((u32 *)chan_tx_lists(port)) + i * chan_count;
767 + for (ch = 0; ch < chan_count; ch++)
768 + list[ch] = phys + ch * CHAN_TX_FRAMES;
770 + dma_sync_single(port->dev, port->chan_tx_buf_phys,
771 + chan_tx_buf_len(port) + chan_tx_lists_len(port),
775 +static u32 hss_config_get_status(struct port *port)
780 + memset(&msg, 0, sizeof(msg));
781 + msg.cmd = PORT_ERROR_READ;
782 + msg.hss_port = port->id;
783 + if (npe_send_message(port->npe, &msg, "PORT_ERROR_READ"))
785 + if (npe_recv_message(port->npe, &msg, "PORT_ERROR_READ"))
791 + printk(KERN_CRIT "HSS-%i: unable to read HSS status\n", port->id);
795 +static void hss_config_start_chan(struct port *port)
799 + port->chan_last_tx = 0;
800 + port->chan_last_rx = 0;
803 + memset(&msg, 0, sizeof(msg));
804 + msg.cmd = CHAN_RX_BUF_ADDR_WRITE;
805 + msg.hss_port = port->id;
806 + msg.data32 = port->chan_rx_buf_phys;
807 + if (npe_send_message(port->npe, &msg, "CHAN_RX_BUF_ADDR_WRITE"))
810 + memset(&msg, 0, sizeof(msg));
811 + msg.cmd = CHAN_TX_BUF_ADDR_WRITE;
812 + msg.hss_port = port->id;
813 + msg.data32 = chan_tx_lists_phys(port);
814 + if (npe_send_message(port->npe, &msg, "CHAN_TX_BUF_ADDR_WRITE"))
817 + memset(&msg, 0, sizeof(msg));
818 + msg.cmd = CHAN_FLOW_ENABLE;
819 + msg.hss_port = port->id;
820 + if (npe_send_message(port->npe, &msg, "CHAN_FLOW_ENABLE"))
822 + port->chan_started = 1;
826 + printk(KERN_CRIT "HSS-%i: unable to start channelized flow\n",
831 +static void hss_config_stop_chan(struct port *port)
835 + if (!port->chan_started)
838 + memset(&msg, 0, sizeof(msg));
839 + msg.cmd = CHAN_FLOW_DISABLE;
840 + msg.hss_port = port->id;
841 + if (npe_send_message(port->npe, &msg, "CHAN_FLOW_DISABLE")) {
842 + printk(KERN_CRIT "HSS-%i: unable to stop channelized flow\n",
846 + hss_config_get_status(port); /* make sure it's halted */
849 +static void hss_config_start_hdlc(struct port *port)
853 + memset(&msg, 0, sizeof(msg));
854 + msg.cmd = PKT_PIPE_FLOW_ENABLE;
855 + msg.hss_port = port->id;
857 + if (npe_send_message(port->npe, &msg, "HSS_ENABLE_PKT_PIPE")) {
858 + printk(KERN_CRIT "HSS-%i: unable to stop packetized flow\n",
864 +static void hss_config_stop_hdlc(struct port *port)
868 + memset(&msg, 0, sizeof(msg));
869 + msg.cmd = PKT_PIPE_FLOW_DISABLE;
870 + msg.hss_port = port->id;
871 + if (npe_send_message(port->npe, &msg, "HSS_DISABLE_PKT_PIPE")) {
872 + printk(KERN_CRIT "HSS-%i: unable to stop packetized flow\n",
876 + hss_config_get_status(port); /* make sure it's halted */
879 +static int hss_config_load_firmware(struct port *port)
883 + if (port->initialized)
886 + if (!npe_running(port->npe)) {
888 + if ((err = npe_load_firmware(port->npe, npe_name(port->npe),
894 + /* HSS main configuration */
895 + hss_config_set_line(port);
897 + hss_config_set_frame(port);
899 + /* HDLC mode configuration */
900 + memset(&msg, 0, sizeof(msg));
901 + msg.cmd = PKT_NUM_PIPES_WRITE;
902 + msg.hss_port = port->id;
903 + msg.data8a = PKT_NUM_PIPES;
904 + if (npe_send_message(port->npe, &msg, "HSS_SET_PKT_PIPES"))
907 + msg.cmd = PKT_PIPE_FIFO_SIZEW_WRITE;
908 + msg.data8a = PKT_PIPE_FIFO_SIZEW;
909 + if (npe_send_message(port->npe, &msg, "HSS_SET_PKT_FIFO"))
912 + msg.cmd = PKT_PIPE_MODE_WRITE;
913 + msg.data8a = NPE_PKT_MODE_HDLC;
914 + /* msg.data8b = inv_mask */
915 + /* msg.data8c = or_mask */
916 + if (npe_send_message(port->npe, &msg, "HSS_SET_PKT_MODE"))
919 + msg.cmd = PKT_PIPE_RX_SIZE_WRITE;
920 + msg.data16a = HDLC_MAX_MRU; /* including CRC */
921 + if (npe_send_message(port->npe, &msg, "HSS_SET_PKT_RX_SIZE"))
924 + msg.cmd = PKT_PIPE_IDLE_PATTERN_WRITE;
925 + msg.data32 = 0x7F7F7F7F; /* ??? FIXME */
926 + if (npe_send_message(port->npe, &msg, "HSS_SET_PKT_IDLE"))
929 + /* Channelized operation settings */
930 + memset(&msg, 0, sizeof(msg));
931 + msg.cmd = CHAN_TX_BLK_CFG_WRITE;
932 + msg.hss_port = port->id;
933 + msg.data8b = (CHAN_TX_LIST_FRAMES & ~7) / 2;
934 + msg.data8a = msg.data8b / 4;
935 + msg.data8d = CHAN_TX_LIST_FRAMES - msg.data8b;
936 + msg.data8c = msg.data8d / 4;
937 + if (npe_send_message(port->npe, &msg, "CHAN_TX_BLK_CFG_WRITE"))
940 + memset(&msg, 0, sizeof(msg));
941 + msg.cmd = CHAN_RX_BUF_CFG_WRITE;
942 + msg.hss_port = port->id;
943 + msg.data8a = CHAN_RX_TRIGGER / 8;
944 + msg.data8b = CHAN_RX_FRAMES;
945 + if (npe_send_message(port->npe, &msg, "CHAN_RX_BUF_CFG_WRITE"))
948 + memset(&msg, 0, sizeof(msg));
949 + msg.cmd = CHAN_TX_BUF_SIZE_WRITE;
950 + msg.hss_port = port->id;
951 + msg.data8a = CHAN_TX_LISTS;
952 + if (npe_send_message(port->npe, &msg, "CHAN_TX_BUF_SIZE_WRITE"))
955 + port->initialized = 1;
959 + printk(KERN_CRIT "HSS-%i: unable to start HSS operation\n", port->id);
963 +/*****************************************************************************
964 + * packetized (HDLC) operation
965 + ****************************************************************************/
967 +static inline void debug_pkt(struct net_device *dev, const char *func,
973 + printk(KERN_DEBUG "%s: %s(%i) ", dev->name, func, len);
974 + for (i = 0; i < len; i++) {
975 + if (i >= DEBUG_PKT_BYTES)
977 + printk(KERN_DEBUG "%s%02X", !(i % 4) ? " " : "", data[i]);
979 + printk(KERN_DEBUG "\n");
984 +static inline void debug_desc(u32 phys, struct desc *desc)
987 + printk(KERN_DEBUG "%X: %X %3X %3X %08X %X %X\n",
988 + phys, desc->next, desc->buf_len, desc->pkt_len,
989 + desc->data, desc->status, desc->error_count);
993 +static inline void debug_queue(unsigned int queue, int is_get, u32 phys)
1000 + { HSS0_PKT_TX0_QUEUE, "TX#0 " },
1001 + { HSS0_PKT_TXDONE_QUEUE, "TX-done#0 " },
1002 + { HSS0_PKT_RX_QUEUE, "RX#0 " },
1003 + { HSS0_PKT_RXFREE0_QUEUE, "RX-free#0 " },
1004 + { HSS1_PKT_TX0_QUEUE, "TX#1 " },
1005 + { HSS1_PKT_TXDONE_QUEUE, "TX-done#1 " },
1006 + { HSS1_PKT_RX_QUEUE, "RX#1 " },
1007 + { HSS1_PKT_RXFREE0_QUEUE, "RX-free#1 " },
1011 + for (i = 0; i < ARRAY_SIZE(names); i++)
1012 + if (names[i].queue == queue)
1015 + printk(KERN_DEBUG "Queue %i %s%s %X\n", queue,
1016 + i < ARRAY_SIZE(names) ? names[i].name : "",
1017 + is_get ? "->" : "<-", phys);
1021 +static inline u32 queue_get_entry(unsigned int queue)
1023 + u32 phys = qmgr_get_entry(queue);
1024 + debug_queue(queue, 1, phys);
1028 +static inline int queue_get_desc(unsigned int queue, struct port *port,
1031 + u32 phys, tab_phys, n_desc;
1034 + if (!(phys = queue_get_entry(queue)))
1037 + BUG_ON(phys & 0x1F);
1038 + tab_phys = is_tx ? tx_desc_phys(port, 0) : rx_desc_phys(port, 0);
1039 + tab = is_tx ? tx_desc_ptr(port, 0) : rx_desc_ptr(port, 0);
1040 + n_desc = (phys - tab_phys) / sizeof(struct desc);
1041 + BUG_ON(n_desc >= (is_tx ? TX_DESCS : RX_DESCS));
1042 + debug_desc(phys, &tab[n_desc]);
1043 + BUG_ON(tab[n_desc].next);
1047 +static inline void queue_put_desc(unsigned int queue, u32 phys,
1048 + struct desc *desc)
1050 + debug_queue(queue, 0, phys);
1051 + debug_desc(phys, desc);
1052 + BUG_ON(phys & 0x1F);
1053 + qmgr_put_entry(queue, phys);
1054 + BUG_ON(qmgr_stat_overflow(queue));
1058 +static inline void dma_unmap_tx(struct port *port, struct desc *desc)
1061 + dma_unmap_single(&port->netdev->dev, desc->data,
1062 + desc->buf_len, DMA_TO_DEVICE);
1064 + dma_unmap_single(&port->netdev->dev, desc->data & ~3,
1065 + ALIGN((desc->data & 3) + desc->buf_len, 4),
1071 +static void hss_hdlc_set_carrier(void *pdev, int carrier)
1073 + struct net_device *netdev = pdev;
1074 + struct port *port = dev_to_port(netdev);
1075 + unsigned long flags;
1077 + spin_lock_irqsave(&npe_lock, flags);
1078 + port->carrier = carrier;
1079 + if (!port->loopback) {
1081 + netif_carrier_on(netdev);
1083 + netif_carrier_off(netdev);
1085 + spin_unlock_irqrestore(&npe_lock, flags);
1088 +static void hss_hdlc_rx_irq(void *pdev)
1090 + struct net_device *dev = pdev;
1091 + struct port *port = dev_to_port(dev);
1094 + printk(KERN_DEBUG "%s: hss_hdlc_rx_irq\n", dev->name);
1096 + qmgr_disable_irq(queue_ids[port->id].rx);
1097 + netif_rx_schedule(dev, &port->napi);
1100 +static int hss_hdlc_poll(struct napi_struct *napi, int budget)
1102 + struct port *port = container_of(napi, struct port, napi);
1103 + struct net_device *dev = port->netdev;
1104 + unsigned int rxq = queue_ids[port->id].rx;
1105 + unsigned int rxfreeq = queue_ids[port->id].rxfree;
1106 + struct net_device_stats *stats = hdlc_stats(dev);
1110 + printk(KERN_DEBUG "%s: hss_hdlc_poll\n", dev->name);
1113 + while (received < budget) {
1114 + struct sk_buff *skb;
1115 + struct desc *desc;
1118 + struct sk_buff *temp;
1122 + if ((n = queue_get_desc(rxq, port, 0)) < 0) {
1123 + received = 0; /* No packet received */
1125 + printk(KERN_DEBUG "%s: hss_hdlc_poll"
1126 + " netif_rx_complete\n", dev->name);
1128 + netif_rx_complete(dev, napi);
1129 + qmgr_enable_irq(rxq);
1130 + if (!qmgr_stat_empty(rxq) &&
1131 + netif_rx_reschedule(dev, napi)) {
1133 + printk(KERN_DEBUG "%s: hss_hdlc_poll"
1134 + " netif_rx_reschedule succeeded\n",
1137 + qmgr_disable_irq(rxq);
1141 + printk(KERN_DEBUG "%s: hss_hdlc_poll all done\n",
1144 + return 0; /* all work done */
1147 + desc = rx_desc_ptr(port, n);
1148 +#if 0 /* FIXME - error_count counts modulo 256, perhaps we should use it */
1149 + if (desc->error_count)
1150 + printk(KERN_DEBUG "%s: hss_hdlc_poll status 0x%02X"
1151 + " errors %u\n", dev->name, desc->status,
1152 + desc->error_count);
1155 + switch (desc->status) {
1158 + if ((skb = netdev_alloc_skb(dev, RX_SIZE)) != NULL) {
1159 + phys = dma_map_single(&dev->dev, skb->data,
1162 + if (dma_mapping_error(phys)) {
1163 + dev_kfree_skb(skb);
1168 + skb = netdev_alloc_skb(dev, desc->pkt_len);
1171 + stats->rx_dropped++;
1173 + case ERR_HDLC_ALIGN:
1174 + case ERR_HDLC_ABORT:
1175 + stats->rx_frame_errors++;
1176 + stats->rx_errors++;
1178 + case ERR_HDLC_FCS:
1179 + stats->rx_crc_errors++;
1180 + stats->rx_errors++;
1182 + case ERR_HDLC_TOO_LONG:
1183 + stats->rx_length_errors++;
1184 + stats->rx_errors++;
1186 + default: /* FIXME - remove printk */
1187 + printk(KERN_ERR "%s: hss_hdlc_poll: status 0x%02X"
1188 + " errors %u\n", dev->name, desc->status,
1189 + desc->error_count);
1190 + stats->rx_errors++;
1194 + /* put the desc back on RX-ready queue */
1195 + desc->buf_len = RX_SIZE;
1196 + desc->pkt_len = desc->status = 0;
1197 + queue_put_desc(rxfreeq, rx_desc_phys(port, n), desc);
1201 + /* process received frame */
1204 + skb = port->rx_buff_tab[n];
1205 + dma_unmap_single(&dev->dev, desc->data,
1206 + RX_SIZE, DMA_FROM_DEVICE);
1208 + dma_sync_single(&dev->dev, desc->data,
1209 + RX_SIZE, DMA_FROM_DEVICE);
1210 + memcpy_swab32((u32 *)skb->data, (u32 *)port->rx_buff_tab[n],
1211 + ALIGN(desc->pkt_len, 4) / 4);
1213 + skb_put(skb, desc->pkt_len);
1215 + debug_pkt(dev, "hss_hdlc_poll", skb->data, skb->len);
1217 + skb->protocol = hdlc_type_trans(skb, dev);
1218 + dev->last_rx = jiffies;
1219 + stats->rx_packets++;
1220 + stats->rx_bytes += skb->len;
1221 + netif_receive_skb(skb);
1223 + /* put the new buffer on RX-free queue */
1225 + port->rx_buff_tab[n] = temp;
1226 + desc->data = phys;
1228 + desc->buf_len = RX_SIZE;
1229 + desc->pkt_len = 0;
1230 + queue_put_desc(rxfreeq, rx_desc_phys(port, n), desc);
1234 + printk(KERN_DEBUG "hss_hdlc_poll: end, not all work done\n");
1236 + return received; /* not all work done */
1240 +static void hss_hdlc_txdone_irq(void *pdev)
1242 + struct net_device *dev = pdev;
1243 + struct port *port = dev_to_port(dev);
1244 + struct net_device_stats *stats = hdlc_stats(dev);
1248 + printk(KERN_DEBUG DRV_NAME ": hss_hdlc_txdone_irq\n");
1250 + while ((n_desc = queue_get_desc(queue_ids[port->id].txdone,
1252 + struct desc *desc;
1255 + desc = tx_desc_ptr(port, n_desc);
1257 + stats->tx_packets++;
1258 + stats->tx_bytes += desc->pkt_len;
1260 + dma_unmap_tx(port, desc);
1262 + printk(KERN_DEBUG "%s: hss_hdlc_txdone_irq free %p\n",
1263 + dev->name, port->tx_buff_tab[n_desc]);
1265 + free_buffer_irq(port->tx_buff_tab[n_desc]);
1266 + port->tx_buff_tab[n_desc] = NULL;
1268 + start = qmgr_stat_empty(port->plat->txreadyq);
1269 + queue_put_desc(port->plat->txreadyq,
1270 + tx_desc_phys(port, n_desc), desc);
1273 + printk(KERN_DEBUG "%s: hss_hdlc_txdone_irq xmit"
1274 + " ready\n", dev->name);
1276 + netif_wake_queue(dev);
1281 +static int hss_hdlc_xmit(struct sk_buff *skb, struct net_device *dev)
1283 + struct port *port = dev_to_port(dev);
1284 + struct net_device_stats *stats = hdlc_stats(dev);
1285 + unsigned int txreadyq = port->plat->txreadyq;
1286 + int len, offset, bytes, n;
1289 + struct desc *desc;
1292 + printk(KERN_DEBUG "%s: hss_hdlc_xmit\n", dev->name);
1295 + if (unlikely(skb->len > HDLC_MAX_MRU)) {
1296 + dev_kfree_skb(skb);
1297 + stats->tx_errors++;
1298 + return NETDEV_TX_OK;
1301 + debug_pkt(dev, "hss_hdlc_xmit", skb->data, skb->len);
1305 + offset = 0; /* no need to keep alignment */
1309 + offset = (int)skb->data & 3; /* keep 32-bit alignment */
1310 + bytes = ALIGN(offset + len, 4);
1311 + if (!(mem = kmalloc(bytes, GFP_ATOMIC))) {
1312 + dev_kfree_skb(skb);
1313 + stats->tx_dropped++;
1314 + return NETDEV_TX_OK;
1316 + memcpy_swab32(mem, (u32 *)((int)skb->data & ~3), bytes / 4);
1317 + dev_kfree_skb(skb);
1320 + phys = dma_map_single(&dev->dev, mem, bytes, DMA_TO_DEVICE);
1321 + if (dma_mapping_error(phys)) {
1323 + dev_kfree_skb(skb);
1327 + stats->tx_dropped++;
1328 + return NETDEV_TX_OK;
1331 + n = queue_get_desc(txreadyq, port, 1);
1333 + desc = tx_desc_ptr(port, n);
1336 + port->tx_buff_tab[n] = skb;
1338 + port->tx_buff_tab[n] = mem;
1340 + desc->data = phys + offset;
1341 + desc->buf_len = desc->pkt_len = len;
1344 + queue_put_desc(queue_ids[port->id].tx, tx_desc_phys(port, n), desc);
1345 + dev->trans_start = jiffies;
1347 + if (qmgr_stat_empty(txreadyq)) {
1349 + printk(KERN_DEBUG "%s: hss_hdlc_xmit queue full\n", dev->name);
1351 + netif_stop_queue(dev);
1352 + /* we could miss TX ready interrupt */
1353 + if (!qmgr_stat_empty(txreadyq)) {
1355 + printk(KERN_DEBUG "%s: hss_hdlc_xmit ready again\n",
1358 + netif_wake_queue(dev);
1363 + printk(KERN_DEBUG "%s: hss_hdlc_xmit end\n", dev->name);
1365 + return NETDEV_TX_OK;
1369 +static int request_hdlc_queues(struct port *port)
1373 + err = qmgr_request_queue(queue_ids[port->id].rxfree, RX_DESCS, 0, 0);
1377 + err = qmgr_request_queue(queue_ids[port->id].rx, RX_DESCS, 0, 0);
1381 + err = qmgr_request_queue(queue_ids[port->id].tx, TX_DESCS, 0, 0);
1385 + err = qmgr_request_queue(port->plat->txreadyq, TX_DESCS, 0, 0);
1389 + err = qmgr_request_queue(queue_ids[port->id].txdone, TX_DESCS, 0, 0);
1395 + qmgr_release_queue(port->plat->txreadyq);
1397 + qmgr_release_queue(queue_ids[port->id].tx);
1399 + qmgr_release_queue(queue_ids[port->id].rx);
1401 + qmgr_release_queue(queue_ids[port->id].rxfree);
1402 + printk(KERN_DEBUG "%s: unable to request hardware queues\n",
1403 + port->netdev->name);
1407 +static void release_hdlc_queues(struct port *port)
1409 + qmgr_release_queue(queue_ids[port->id].rxfree);
1410 + qmgr_release_queue(queue_ids[port->id].rx);
1411 + qmgr_release_queue(queue_ids[port->id].txdone);
1412 + qmgr_release_queue(queue_ids[port->id].tx);
1413 + qmgr_release_queue(port->plat->txreadyq);
1416 +static int init_hdlc_queues(struct port *port)
1421 + if (!(dma_pool = dma_pool_create(DRV_NAME, NULL,
1422 + POOL_ALLOC_SIZE, 32, 0)))
1425 + if (!(port->desc_tab = dma_pool_alloc(dma_pool, GFP_KERNEL,
1426 + &port->desc_tab_phys)))
1428 + memset(port->desc_tab, 0, POOL_ALLOC_SIZE);
1429 + memset(port->rx_buff_tab, 0, sizeof(port->rx_buff_tab)); /* tables */
1430 + memset(port->tx_buff_tab, 0, sizeof(port->tx_buff_tab));
1432 + /* Setup RX buffers */
1433 + for (i = 0; i < RX_DESCS; i++) {
1434 + struct desc *desc = rx_desc_ptr(port, i);
1438 + if (!(buff = netdev_alloc_skb(port->netdev, RX_SIZE)))
1440 + data = buff->data;
1442 + if (!(buff = kmalloc(RX_SIZE, GFP_KERNEL)))
1446 + desc->buf_len = RX_SIZE;
1447 + desc->data = dma_map_single(&port->netdev->dev, data,
1448 + RX_SIZE, DMA_FROM_DEVICE);
1449 + if (dma_mapping_error(desc->data)) {
1450 + free_buffer(buff);
1453 + port->rx_buff_tab[i] = buff;
1459 +static void destroy_hdlc_queues(struct port *port)
1463 + if (port->desc_tab) {
1464 + for (i = 0; i < RX_DESCS; i++) {
1465 + struct desc *desc = rx_desc_ptr(port, i);
1466 + buffer_t *buff = port->rx_buff_tab[i];
1468 + dma_unmap_single(&port->netdev->dev,
1469 + desc->data, RX_SIZE,
1471 + free_buffer(buff);
1474 + for (i = 0; i < TX_DESCS; i++) {
1475 + struct desc *desc = tx_desc_ptr(port, i);
1476 + buffer_t *buff = port->tx_buff_tab[i];
1478 + dma_unmap_tx(port, desc);
1479 + free_buffer(buff);
1482 + dma_pool_free(dma_pool, port->desc_tab, port->desc_tab_phys);
1483 + port->desc_tab = NULL;
1486 + if (!ports_open && dma_pool) {
1487 + dma_pool_destroy(dma_pool);
1492 +static int hss_hdlc_open(struct net_device *dev)
1494 + struct port *port = dev_to_port(dev);
1495 + unsigned long flags;
1498 + if ((err = hdlc_open(dev)))
1501 + if ((err = request_hdlc_queues(port)))
1502 + goto err_hdlc_close;
1504 + if ((err = init_hdlc_queues(port)))
1505 + goto err_destroy_queues;
1507 + spin_lock_irqsave(&npe_lock, flags);
1509 + if (port->mode == MODE_G704 && port->channels[0] == CHANNEL_HDLC) {
1510 + err = -EBUSY; /* channel #0 is used for G.704 framing */
1513 + if (port->mode != MODE_HDLC)
1514 + for (i = port->frame_size / 8; i < MAX_CHANNELS; i++)
1515 + if (port->channels[i] == CHANNEL_HDLC) {
1516 + err = -ECHRNG; /* frame too short */
1520 + if ((err = hss_config_load_firmware(port)))
1523 + if (!port->chan_open_count && port->plat->open)
1524 + if ((err = port->plat->open(port->id, dev,
1525 + hss_hdlc_set_carrier)))
1528 + if (port->mode == MODE_G704 && !port->chan_open_count)
1529 + if ((err = hss_prepare_chan(port)))
1530 + goto err_plat_close;
1532 + spin_unlock_irqrestore(&npe_lock, flags);
1534 + /* Populate queues with buffers, no failure after this point */
1535 + for (i = 0; i < TX_DESCS; i++)
1536 + queue_put_desc(port->plat->txreadyq,
1537 + tx_desc_phys(port, i), tx_desc_ptr(port, i));
1539 + for (i = 0; i < RX_DESCS; i++)
1540 + queue_put_desc(queue_ids[port->id].rxfree,
1541 + rx_desc_phys(port, i), rx_desc_ptr(port, i));
1543 + napi_enable(&port->napi);
1544 + netif_start_queue(dev);
1546 + qmgr_set_irq(queue_ids[port->id].rx, QUEUE_IRQ_SRC_NOT_EMPTY,
1547 + hss_hdlc_rx_irq, dev);
1549 + qmgr_set_irq(queue_ids[port->id].txdone, QUEUE_IRQ_SRC_NOT_EMPTY,
1550 + hss_hdlc_txdone_irq, dev);
1551 + qmgr_enable_irq(queue_ids[port->id].txdone);
1554 + port->hdlc_open = 1;
1556 + hss_config_set_hdlc_cfg(port);
1557 + hss_config_set_lut(port);
1558 + hss_config_load(port);
1560 + if (port->mode == MODE_G704 && !port->chan_open_count)
1561 + hss_config_start_chan(port);
1563 + hss_config_start_hdlc(port);
1565 + /* we may already have RX data, enables IRQ */
1566 + netif_rx_schedule(dev, &port->napi);
1570 + if (!port->chan_open_count && port->plat->close)
1571 + port->plat->close(port->id, dev);
1573 + spin_unlock_irqrestore(&npe_lock, flags);
1574 +err_destroy_queues:
1575 + destroy_hdlc_queues(port);
1576 + release_hdlc_queues(port);
1582 +static int hss_hdlc_close(struct net_device *dev)
1584 + struct port *port = dev_to_port(dev);
1585 + unsigned long flags;
1586 + int i, buffs = RX_DESCS; /* allocated RX buffers */
1588 + spin_lock_irqsave(&npe_lock, flags);
1590 + port->hdlc_open = 0;
1591 + qmgr_disable_irq(queue_ids[port->id].rx);
1592 + netif_stop_queue(dev);
1593 + napi_disable(&port->napi);
1595 + hss_config_stop_hdlc(port);
1597 + if (port->mode == MODE_G704 && !port->chan_open_count)
1598 + hss_chan_stop(port);
1600 + while (queue_get_desc(queue_ids[port->id].rxfree, port, 0) >= 0)
1602 + while (queue_get_desc(queue_ids[port->id].rx, port, 0) >= 0)
1606 + printk(KERN_CRIT "%s: unable to drain RX queue, %i buffer(s)"
1607 + " left in NPE\n", dev->name, buffs);
1610 + while (queue_get_desc(queue_ids[port->id].tx, port, 1) >= 0)
1611 + buffs--; /* cancel TX */
1615 + while (queue_get_desc(port->plat->txreadyq, port, 1) >= 0)
1619 + } while (++i < MAX_CLOSE_WAIT);
1622 + printk(KERN_CRIT "%s: unable to drain TX queue, %i buffer(s) "
1623 + "left in NPE\n", dev->name, buffs);
1626 + printk(KERN_DEBUG "Draining TX queues took %i cycles\n", i);
1628 + qmgr_disable_irq(queue_ids[port->id].txdone);
1630 + if (!port->chan_open_count && port->plat->close)
1631 + port->plat->close(port->id, dev);
1632 + spin_unlock_irqrestore(&npe_lock, flags);
1634 + destroy_hdlc_queues(port);
1635 + release_hdlc_queues(port);
1641 +static int hss_hdlc_attach(struct net_device *dev, unsigned short encoding,
1642 + unsigned short parity)
1644 + struct port *port = dev_to_port(dev);
1646 + if (encoding != ENCODING_NRZ)
1650 + case PARITY_CRC16_PR1_CCITT:
1651 + port->hdlc_cfg = 0;
1654 + case PARITY_CRC32_PR1_CCITT:
1655 + port->hdlc_cfg = PKT_HDLC_CRC_32;
1664 +static int hss_hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1666 + const size_t size = sizeof(sync_serial_settings);
1667 + sync_serial_settings new_line;
1668 + sync_serial_settings __user *line = ifr->ifr_settings.ifs_ifsu.sync;
1669 + struct port *port = dev_to_port(dev);
1670 + unsigned long flags;
1673 + if (cmd != SIOCWANDEV)
1674 + return hdlc_ioctl(dev, ifr, cmd);
1676 + switch(ifr->ifr_settings.type) {
1677 + case IF_GET_IFACE:
1678 + ifr->ifr_settings.type = IF_IFACE_V35;
1679 + if (ifr->ifr_settings.size < size) {
1680 + ifr->ifr_settings.size = size; /* data size wanted */
1683 + memset(&new_line, 0, sizeof(new_line));
1684 + new_line.clock_type = port->clock_type;
1685 + new_line.clock_rate = port->clock_rate;
1686 + new_line.loopback = port->loopback;
1687 + if (copy_to_user(line, &new_line, size))
1690 + if (!port->chan_buf)
1693 + dma_sync_single(&dev->dev, port->chan_rx_buf_phys,
1694 + chan_rx_buf_len(port), DMA_FROM_DEVICE);
1695 + printk(KERN_DEBUG "RX:\n");
1696 + for (i = 0; i < chan_rx_buf_len(port); i++) {
1698 + printk(KERN_DEBUG "%03X ", i);
1699 + printk("%02X%c", chan_rx_buf(port)[i],
1700 + (i + 1) % 32 ? ' ' : '\n');
1704 + printk(KERN_DEBUG "TX:\n");
1705 + for (i = 0; i < /*CHAN_TX_FRAMES * 2*/ chan_tx_buf_len(port)
1706 + + chan_tx_lists_len(port); i++) {
1708 + printk(KERN_DEBUG "%03X ", i);
1709 + printk("%02X%c", chan_tx_buf(port)[i],
1710 + (i + 1) % 32 ? ' ' : '\n');
1713 + port->msg_count = 10;
1716 + case IF_IFACE_SYNC_SERIAL:
1717 + case IF_IFACE_V35:
1718 + if(!capable(CAP_NET_ADMIN))
1720 + if (copy_from_user(&new_line, line, size))
1723 + clk = new_line.clock_type;
1724 + if (port->plat->set_clock)
1725 + clk = port->plat->set_clock(port->id, clk);
1727 + if (clk != CLOCK_EXT && clk != CLOCK_INT)
1728 + return -EINVAL; /* No such clock setting */
1730 + if (new_line.loopback != 0 && new_line.loopback != 1)
1733 + port->clock_type = clk; /* Update settings */
1734 + /* FIXME port->clock_rate = new_line.clock_rate */;
1735 + port->loopback = new_line.loopback;
1737 + spin_lock_irqsave(&npe_lock, flags);
1739 + if (port->chan_open_count || port->hdlc_open) {
1740 + hss_config_set_line(port);
1741 + hss_config_load(port);
1743 + if (port->loopback || port->carrier)
1744 + netif_carrier_on(port->netdev);
1746 + netif_carrier_off(port->netdev);
1747 + spin_unlock_irqrestore(&npe_lock, flags);
1752 + return hdlc_ioctl(dev, ifr, cmd);
1756 +/*****************************************************************************
1757 + * channelized (G.704) operation
1758 + ****************************************************************************/
1760 +static void g704_rx_framer(struct port *port, unsigned int offset)
1762 + u8 *data = chan_rx_buf(port) + sub_offset(offset, CHAN_RX_TRIGGER,
1764 + unsigned int bit, frame, bad_even = 0, bad_odd = 0, cnt;
1765 + unsigned int is_first = port->just_set_offset;
1766 + u8 zeros_even, zeros_odd, ones_even, ones_odd;
1767 + enum alignment aligned;
1769 + port->just_set_offset = 0;
1770 + dma_sync_single(port->dev, port->chan_rx_buf_phys, CHAN_RX_FRAMES,
1773 + /* check if aligned first */
1774 + for (frame = 0; frame < CHAN_RX_TRIGGER &&
1775 + (bad_even <= MAX_CHAN_RX_BAD_SYNC ||
1776 + bad_odd <= MAX_CHAN_RX_BAD_SYNC); frame += 2) {
1777 + u8 ve = data[frame];
1778 + u8 vo = data[frame + 1];
1780 + if ((ve & 0x7F) != 0x1B || !(vo & 0x40))
1783 + if ((vo & 0x7F) != 0x1B || !(ve & 0x40))
1787 + if (bad_even <= MAX_CHAN_RX_BAD_SYNC)
1788 + aligned = EVEN_FIRST;
1789 + else if (bad_odd <= MAX_CHAN_RX_BAD_SYNC)
1790 + aligned = ODD_FIRST;
1792 + aligned = NOT_ALIGNED;
1794 + if (aligned != NOT_ALIGNED) {
1795 + if (aligned == port->aligned)
1796 + return; /* no change */
1797 + if (printk_ratelimit())
1798 + printk(KERN_INFO "HSS-%i: synchronized at %u (%s frame"
1799 + " first)\n", port->id, port->frame_sync_offset,
1800 + aligned == EVEN_FIRST ? "even" : "odd");
1801 + port->aligned = aligned;
1803 + atomic_inc(&port->chan_tx_irq_number);
1804 + wake_up_interruptible(&port->chan_tx_waitq);
1805 + atomic_inc(&port->chan_rx_irq_number);
1806 + wake_up_interruptible(&port->chan_rx_waitq);
1811 + if (port->aligned != NOT_ALIGNED && printk_ratelimit()) {
1812 + printk(KERN_INFO "HSS-%i: lost alignment\n", port->id);
1813 + port->aligned = NOT_ALIGNED;
1815 + for (cnt = 0; cnt < CHAN_RX_FRAMES; cnt++)
1816 + printk("%c%02X%s", cnt == offset ? '>' : ' ',
1817 + chan_rx_buf(port)[cnt],
1818 + (cnt + 1) % 32 ? "" : "\n");
1821 + for (cnt = 0; cnt < MAX_CHAN_DEVICES; cnt++)
1822 + if (port->chan_devices[cnt]) {
1823 + set_bit(TX_ERROR_BIT, &port->chan_devices[cnt]
1825 + set_bit(RX_ERROR_BIT, &port->chan_devices[cnt]
1828 + atomic_inc(&port->chan_tx_irq_number);
1829 + wake_up_interruptible(&port->chan_tx_waitq);
1830 + atomic_inc(&port->chan_rx_irq_number);
1831 + wake_up_interruptible(&port->chan_rx_waitq);
1837 + zeros_even = zeros_odd = 0;
1838 + ones_even = ones_odd = 0xFF;
1839 + for (frame = 0; frame < CHAN_RX_TRIGGER; frame += 2) {
1840 + zeros_even |= data[frame];
1841 + zeros_odd |= data[frame + 1];
1842 + ones_even &= data[frame];
1843 + ones_odd &= data[frame + 1];
1846 + for (bit = 0; bit < 7; bit++) {
1847 + if ((zeros_even & ~0x9B) == 0 && (ones_even & 0x1B) == 0x1B &&
1848 + (ones_odd & 0x40) == 0x40) {
1849 + aligned = EVEN_FIRST; /* maybe */
1852 + if ((zeros_odd & ~0x9B) == 0 && (ones_odd & 0x1B) == 0x1B &&
1853 + (ones_even & 0x40) == 0x40) {
1854 + aligned = ODD_FIRST; /* maybe */
1858 + ones_even = ones_even << 1 | 1;
1860 + ones_odd = ones_odd << 1 | 1;
1863 + port->frame_sync_offset += port->frame_size - bit;
1864 + port->frame_sync_offset %= port->frame_size;
1865 + port->just_set_offset = 1;
1869 + printk(KERN_DEBUG "HSS-%i: trying frame sync at %u\n",
1870 + port->id, port->frame_sync_offset);
1872 + printk(KERN_DEBUG "HSS-%i: found possible frame sync pattern at"
1873 + " %u (%s frame first)\n", port->id,
1874 + port->frame_sync_offset,
1875 + aligned == EVEN_FIRST ? "even" : "odd");
1878 + hss_config_set_rx_frame(port);
1879 + hss_config_load(port);
1882 +static void chan_process_tx_irq(struct chan_device *chan_dev, int offset)
1885 + unsigned int buff_len = CHAN_TX_FRAMES * chan_dev->chan_count;
1886 + unsigned int list_len = CHAN_TX_LIST_FRAMES * chan_dev->chan_count;
1887 + int eaten, last_offset = chan_dev->port->chan_last_tx * list_len;
1889 + offset *= list_len;
1890 + eaten = sub_offset(offset, last_offset, buff_len);
1892 + if (chan_dev->tx_count > eaten + 2 * list_len) {
1893 + /* two pages must be reserved for the transmitter */
1894 + chan_dev->tx_first += eaten;
1895 + chan_dev->tx_first %= buff_len;
1896 + chan_dev->tx_count -= eaten;
1900 + 1 tx_first (may still be transmited)
1901 + 2 tx_offset (currently reported by the NPE)
1902 + 3 tx_first + 2 * list_len (free to write here)
1907 + /* printk(KERN_DEBUG "TX buffer underflow\n"); */
1908 + chan_dev->tx_first = sub_offset(offset, list_len, buff_len);
1909 + chan_dev->tx_count = 2 * list_len; /* reserve */
1910 + set_bit(TX_ERROR_BIT, &chan_dev->errors_bitmap);
1914 +static void chan_process_rx_irq(struct chan_device *chan_dev, int offset)
1917 + unsigned int buff_len = CHAN_RX_FRAMES * chan_dev->chan_count;
1918 + unsigned int trig_len = CHAN_RX_TRIGGER * chan_dev->chan_count;
1919 + int last_offset = chan_dev->port->chan_last_rx * chan_dev->chan_count;
1921 + offset *= chan_dev->chan_count;
1922 + chan_dev->rx_count += sub_offset(offset, last_offset + trig_len,
1923 + buff_len) + trig_len;
1924 + if (chan_dev->rx_count > buff_len - 2 * trig_len) {
1925 + /* two pages - offset[0] and offset[1] are lost - FIXME check */
1926 + /* printk(KERN_DEBUG "RX buffer overflow\n"); */
1927 + chan_dev->rx_first = (offset + 2 * trig_len) % buff_len;
1928 + chan_dev->rx_count = buff_len - 2 * trig_len;
1929 + set_bit(RX_ERROR_BIT, &chan_dev->errors_bitmap);
1933 +static void hss_chan_irq(void *pdev)
1935 + struct port *port = pdev;
1939 + printk(KERN_DEBUG DRV_NAME ": hss_chan_irq\n");
1941 + spin_lock(&npe_lock);
1942 + while ((v = qmgr_get_entry(queue_ids[port->id].chan))) {
1943 + unsigned int first, errors, tx_list, rx_frame;
1947 + errors = (v >> 16) & 0xFF;
1948 + tx_list = (v >> 8) & 0xFF;
1949 + rx_frame = v & 0xFF;
1951 + if (port->msg_count) {
1952 + printk(KERN_DEBUG "chan_irq hss %i jiffies %lu first"
1953 + " 0x%02X errors 0x%02X tx_list 0x%02X rx_frame"
1954 + " 0x%02X\n", port->id, jiffies, first, errors,
1955 + tx_list, rx_frame);
1956 + port->msg_count--;
1959 + BUG_ON(rx_frame % CHAN_RX_TRIGGER);
1960 + BUG_ON(rx_frame >= CHAN_RX_FRAMES);
1961 + BUG_ON(tx_list >= CHAN_TX_LISTS);
1963 + bad = port->mode == MODE_G704 && port->aligned == NOT_ALIGNED;
1964 + if (!bad && tx_list != port->chan_last_tx) {
1965 + if (tx_list != (port->chan_last_tx + 1) % CHAN_TX_LISTS)
1966 + printk(KERN_DEBUG "Skipped an IRQ? Tx last %i"
1967 + " current %i\n", port->chan_last_tx,
1969 + for (i = 0; i < MAX_CHAN_DEVICES; i++) {
1970 + if (!port->chan_devices[i] ||
1971 + !port->chan_devices[i]->open_count)
1973 + chan_process_tx_irq(port->chan_devices[i],
1976 + atomic_inc(&port->chan_tx_irq_number);
1978 + printk(KERN_DEBUG "wakeing up TX jiff %lu\n",
1981 + wake_up_interruptible(&port->chan_tx_waitq);
1984 + if (rx_frame != (port->chan_last_rx + CHAN_RX_TRIGGER) %
1986 + printk(KERN_DEBUG "Skipped an IRQ? Rx last %i"
1987 + " current %i\n", port->chan_last_rx, rx_frame);
1989 + if (port->mode == MODE_G704)
1990 + g704_rx_framer(port, rx_frame);
1993 + (port->mode != MODE_G704 || port->aligned != NOT_ALIGNED)) {
1994 + for (i = 0; i < MAX_CHAN_DEVICES; i++) {
1995 + if (!port->chan_devices[i] ||
1996 + !port->chan_devices[i]->open_count)
1998 + chan_process_rx_irq(port->chan_devices[i],
2001 + atomic_inc(&port->chan_rx_irq_number);
2002 + wake_up_interruptible(&port->chan_rx_waitq);
2004 + port->chan_last_tx = tx_list;
2005 + port->chan_last_rx = rx_frame;
2007 + spin_unlock(&npe_lock);
2011 +static int hss_prepare_chan(struct port *port)
2015 + if ((err = hss_config_load_firmware(port)))
2018 + if ((err = qmgr_request_queue(queue_ids[port->id].chan,
2019 + CHAN_QUEUE_LEN, 0, 0)))
2022 + if (!(port->chan_buf = kmalloc(chan_tx_buf_len(port) +
2023 + chan_tx_lists_len(port) +
2024 + chan_rx_buf_len(port), GFP_KERNEL))) {
2025 + goto release_queue;
2029 + port->chan_tx_buf_phys = dma_map_single(port->dev, chan_tx_buf(port),
2030 + chan_tx_buf_len(port) +
2031 + chan_tx_lists_len(port),
2033 + if (dma_mapping_error(port->chan_tx_buf_phys)) {
2038 + port->chan_rx_buf_phys = dma_map_single(port->dev, chan_rx_buf(port),
2039 + chan_rx_buf_len(port),
2041 + if (dma_mapping_error(port->chan_rx_buf_phys)) {
2046 + qmgr_set_irq(queue_ids[port->id].chan, QUEUE_IRQ_SRC_NOT_EMPTY,
2047 + hss_chan_irq, port);
2048 + qmgr_enable_irq(queue_ids[port->id].chan);
2049 + hss_chan_irq(port);
2053 + dma_unmap_single(port->dev, port->chan_tx_buf_phys,
2054 + chan_tx_buf_len(port) + chan_tx_lists_len(port),
2057 + kfree(port->chan_buf);
2058 + port->chan_buf = NULL;
2060 + qmgr_release_queue(queue_ids[port->id].chan);
2064 +void hss_chan_stop(struct port *port)
2066 + if (!port->chan_open_count && !port->hdlc_open)
2067 + qmgr_disable_irq(queue_ids[port->id].chan);
2069 + hss_config_stop_chan(port);
2070 + hss_config_set_lut(port);
2071 + hss_config_load(port);
2073 + if (!port->chan_open_count && !port->hdlc_open) {
2074 + dma_unmap_single(port->dev, port->chan_tx_buf_phys,
2075 + chan_tx_buf_len(port) +
2076 + chan_tx_lists_len(port), DMA_TO_DEVICE);
2077 + dma_unmap_single(port->dev, port->chan_rx_buf_phys,
2078 + chan_rx_buf_len(port), DMA_FROM_DEVICE);
2079 + kfree(port->chan_buf);
2080 + port->chan_buf = NULL;
2081 + qmgr_release_queue(queue_ids[port->id].chan);
2085 +static int hss_chan_open(struct inode *inode, struct file *file)
2087 + struct chan_device *chan_dev = inode_to_chan_dev(inode);
2088 + struct port *port = chan_dev->port;
2089 + unsigned long flags;
2092 + spin_lock_irqsave(&npe_lock, flags);
2094 + if (chan_dev->open_count) {
2095 + if (chan_dev->excl_open || (file->f_flags & O_EXCL))
2098 + chan_dev->open_count++;
2102 + if (port->mode == MODE_HDLC) {
2107 + if (port->mode == MODE_G704 && port->channels[0] == chan_dev->id) {
2108 + err = -EBUSY; /* channel #0 is used for G.704 signaling */
2111 + for (i = MAX_CHANNELS; i > port->frame_size / 8; i--)
2112 + if (port->channels[i - 1] == chan_dev->id) {
2113 + err = -ECHRNG; /* frame too short */
2117 + chan_dev->rx_first = chan_dev->tx_first = 0;
2118 + chan_dev->rx_count = chan_dev->tx_count = 0;
2119 + clear_bit(TX_ERROR_BIT, &chan_dev->errors_bitmap);
2120 + clear_bit(RX_ERROR_BIT, &chan_dev->errors_bitmap);
2122 + if (!port->chan_open_count && !port->hdlc_open) {
2123 + if (port->plat->open)
2124 + if ((err = port->plat->open(port->id, port->netdev,
2125 + hss_hdlc_set_carrier)))
2127 + if ((err = hss_prepare_chan(port))) {
2128 + if (port->plat->close)
2129 + port->plat->close(port->id, port->netdev);
2134 + hss_config_stop_chan(port);
2135 + chan_dev->open_count++;
2136 + port->chan_open_count++;
2137 + chan_dev->excl_open = !!file->f_flags & O_EXCL;
2139 + hss_config_set_lut(port);
2140 + hss_config_load(port);
2141 + hss_config_start_chan(port);
2143 + spin_unlock_irqrestore(&npe_lock, flags);
2147 +static int hss_chan_release(struct inode *inode, struct file *file)
2149 + struct chan_device *chan_dev = inode_to_chan_dev(inode);
2150 + struct port *port = chan_dev->port;
2151 + unsigned long flags;
2153 + spin_lock_irqsave(&npe_lock, flags);
2155 + if (!--chan_dev->open_count) {
2156 + if (!--port->chan_open_count && !port->hdlc_open) {
2157 + hss_chan_stop(port);
2158 + if (port->plat->close)
2159 + port->plat->close(port->id, port->netdev);
2161 + hss_config_stop_chan(port);
2162 + hss_config_set_lut(port);
2163 + hss_config_set_line(port); //
2164 + hss_config_start_chan(port);
2168 + spin_unlock_irqrestore(&npe_lock, flags);
2172 +static ssize_t hss_chan_read(struct file *file, char __user *buf, size_t count,
2175 + struct chan_device *chan_dev = inode_to_chan_dev
2176 + (file->f_path.dentry->d_inode);
2177 + struct port *port = chan_dev->port;
2178 + unsigned long flags;
2180 + int res = 0, loops = 0;
2182 + spin_lock_irqsave(&npe_lock, flags);
2185 + int prev_irq = atomic_read(&port->chan_rx_irq_number);
2187 + if (test_and_clear_bit(RX_ERROR_BIT, &chan_dev->errors_bitmap)
2188 + || (port->mode == G704 && port->aligned == NOT_ALIGNED)) {
2194 + goto out; /* no need to wait */
2196 + if (chan_dev->rx_count)
2199 + spin_unlock_irqrestore(&npe_lock, flags);
2201 + if ((res = wait_event_interruptible
2202 + (port->chan_rx_waitq,
2203 + atomic_read(&port->chan_rx_irq_number) != prev_irq)))
2205 + spin_lock_irqsave(&npe_lock, flags);
2209 + dma_sync_single(port->dev, port->chan_rx_buf_phys,
2210 + chan_rx_buf_len(port), DMA_FROM_DEVICE);
2214 + printk(KERN_DEBUG "ENTRY rx_first %u rx_count %u count %i"
2215 + " last_rx %u loops %i\n", chan_dev->rx_first,
2216 + chan_dev->rx_count, count, port->chan_last_rx, loops);
2218 + rx_buf = chan_rx_buf(port);
2219 + while (chan_dev->rx_count > 0 && res < count) {
2220 + unsigned int chan = chan_dev->rx_first % chan_dev->chan_count;
2221 + unsigned int frame = chan_dev->rx_first / chan_dev->chan_count;
2223 + chan = chan_dev->log_channels[chan];
2224 + if (put_user(rx_buf[chan * CHAN_RX_FRAMES + frame], buf++)) {
2228 + chan_dev->rx_first++;
2229 + chan_dev->rx_first %= CHAN_RX_FRAMES * chan_dev->chan_count;
2230 + chan_dev->rx_count--;
2235 + printk(KERN_DEBUG "EXIT rx_first %u rx_count %u res %i\n",
2236 + chan_dev->rx_first, chan_dev->rx_count, res);
2238 + spin_unlock_irqrestore(&npe_lock, flags);
2242 +static ssize_t hss_chan_write(struct file *file, const char __user *buf,
2243 + size_t count, loff_t *f_pos)
2245 + struct chan_device *chan_dev = inode_to_chan_dev
2246 + (file->f_path.dentry->d_inode);
2247 + struct port *port = chan_dev->port;
2248 + unsigned long flags;
2250 + int res = 0, loops = 0;
2252 + spin_lock_irqsave(&npe_lock, flags);
2254 + int prev_irq = atomic_read(&port->chan_tx_irq_number);
2256 + if (test_and_clear_bit(TX_ERROR_BIT, &chan_dev->errors_bitmap)
2257 + || (port->mode == G704 && port->aligned == NOT_ALIGNED)) {
2263 + goto out; /* no need to wait */
2265 + if (chan_dev->tx_count < CHAN_TX_FRAMES * chan_dev->chan_count)
2268 + spin_unlock_irqrestore(&npe_lock, flags);
2270 + if ((res = wait_event_interruptible
2271 + (port->chan_tx_waitq,
2272 + atomic_read (&port->chan_tx_irq_number) != prev_irq)))
2274 + spin_lock_irqsave(&npe_lock, flags);
2280 + printk(KERN_DEBUG "ENTRY TX_first %u tx_count %u count %i"
2281 + " last_tx %u loops %i\n", chan_dev->tx_first,
2282 + chan_dev->tx_count, count, port->chan_last_tx, loops);
2284 + tx_buf = chan_tx_buf(port);
2285 + while (chan_dev->tx_count < CHAN_TX_FRAMES * chan_dev->chan_count &&
2287 + unsigned int tail, chan, frame;
2289 + tail = (chan_dev->tx_first + chan_dev->tx_count) %
2290 + (CHAN_TX_FRAMES * chan_dev->chan_count);
2291 + chan = tail % chan_dev->chan_count;
2292 + frame = tail / chan_dev->chan_count;
2293 + chan = chan_dev->log_channels[chan];
2295 + if (get_user(tx_buf[chan * CHAN_TX_FRAMES + frame], buf++)) {
2296 + printk(KERN_DEBUG "BUG? TX %u %u %u\n",
2297 + tail, chan, frame);
2301 + chan_dev->tx_count++;
2305 + dma_sync_single(port->dev, port->chan_tx_buf_phys,
2306 + chan_tx_buf_len(port), DMA_TO_DEVICE);
2309 + printk(KERN_DEBUG "EXIT TX_first %u tx_count %u res %i\n",
2310 + chan_dev->tx_first, chan_dev->tx_count, res);
2312 + spin_unlock_irqrestore(&npe_lock, flags);
2317 +static unsigned int hss_chan_poll(struct file *file, poll_table *wait)
2319 + struct chan_device *chan_dev = inode_to_chan_dev
2320 + (file->f_path.dentry->d_inode);
2321 + struct port *port = chan_dev->port;
2322 + unsigned long flags;
2323 + unsigned int mask = 0;
2325 + spin_lock_irqsave(&npe_lock, flags);
2326 + poll_wait(file, &port->chan_tx_waitq, wait);
2327 + poll_wait(file, &port->chan_rx_waitq, wait);
2329 + if (chan_dev->tx_count < CHAN_TX_FRAMES * chan_dev->chan_count)
2330 + mask |= POLLOUT | POLLWRNORM;
2331 + if (chan_dev->rx_count)
2332 + mask |= POLLIN | POLLRDNORM;
2333 + spin_unlock_irqrestore(&npe_lock, flags);
2337 +/*****************************************************************************
2338 + * channelized device sysfs attributes
2339 + ****************************************************************************/
2341 +static ssize_t chan_show_chan(struct device *dev, struct device_attribute *attr,
2344 + struct chan_device *chan_dev = dev_get_drvdata(dev);
2346 + return print_channels(chan_dev->port, buf, chan_dev->id);
2349 +static ssize_t chan_set_chan(struct device *dev, struct device_attribute *attr,
2350 + const char *buf, size_t len)
2352 + struct chan_device *chan_dev = dev_get_drvdata(dev);
2353 + struct port *port = chan_dev->port;
2354 + unsigned long flags;
2356 + size_t orig_len = len;
2359 + if (len && buf[len - 1] == '\n')
2362 + if (len != 7 || memcmp(buf, "destroy", 7))
2365 + spin_lock_irqsave(&npe_lock, flags);
2366 + cdev_del(&chan_dev->cdev);
2368 + for (ch = 0; ch < MAX_CHANNELS; ch++)
2369 + if (port->channels[ch] == chan_dev->id)
2370 + port->channels[ch] = CHANNEL_UNUSED;
2371 + port->chan_devices[chan_dev->id] = NULL;
2373 + spin_unlock_irqrestore(&npe_lock, flags);
2375 + if ((err = device_schedule_callback(dev, device_unregister)))
2380 +static struct device_attribute chan_attr =
2381 + __ATTR(channels, 0644, chan_show_chan, chan_set_chan);
2383 +/*****************************************************************************
2384 + * main sysfs attributes
2385 + ****************************************************************************/
2387 +static const struct file_operations chan_fops = {
2388 + .owner = THIS_MODULE,
2389 + .llseek = no_llseek,
2390 + .read = hss_chan_read,
2391 + .write = hss_chan_write,
2392 + .poll = hss_chan_poll,
2393 + .open = hss_chan_open,
2394 + .release = hss_chan_release,
2397 +static ssize_t create_chan(struct device *dev, struct device_attribute *attr,
2398 + const char *buf, size_t len)
2400 + struct port *port = dev_get_drvdata(dev);
2401 + struct chan_device *chan_dev;
2402 + u8 channels[MAX_CHANNELS];
2403 + size_t orig_len = len;
2404 + unsigned long flags;
2405 + unsigned int ch, id;
2408 + if ((err = parse_channels(&buf, &len, channels)) < 1)
2411 + if (!(chan_dev = kzalloc(sizeof(struct chan_device), GFP_KERNEL)))
2414 + spin_lock_irqsave(&npe_lock, flags);
2416 + if (port->mode != MODE_RAW && port->mode != MODE_G704) {
2421 + for (ch = 0; ch < MAX_CHANNELS; ch++)
2422 + if (channels[ch] && port->channels[ch] != CHANNEL_UNUSED) {
2423 + printk(KERN_DEBUG "Channel #%i already in use\n", ch);
2428 + for (id = 0; id < MAX_CHAN_DEVICES; id++)
2429 + if (port->chan_devices[id] == NULL)
2432 + if (id == MAX_CHAN_DEVICES) {
2437 + for (ch = 0; ch < MAX_CHANNELS; ch++)
2441 + minor = port->id * MAX_CHAN_DEVICES + ch;
2442 + chan_dev->id = id;
2443 + chan_dev->port = port;
2444 + chan_dev->dev = device_create(hss_class, dev, MKDEV(chan_major, minor),
2445 + "hss%uch%u", port->id, ch);
2446 + if (IS_ERR(chan_dev->dev)) {
2447 + err = PTR_ERR(chan_dev->dev);
2451 + cdev_init(&chan_dev->cdev, &chan_fops);
2452 + chan_dev->cdev.owner = THIS_MODULE;
2453 + if ((err = cdev_add(&chan_dev->cdev, MKDEV(chan_major, minor), 1)))
2454 + goto destroy_device;
2456 + for (ch = 0; ch < MAX_CHANNELS; ch++)
2458 + port->channels[ch] = id;
2459 + port->chan_devices[id] = chan_dev;
2460 + dev_set_drvdata(chan_dev->dev, chan_dev);
2461 + BUG_ON(device_create_file(chan_dev->dev, &chan_attr));
2463 + spin_unlock_irqrestore(&npe_lock, flags);
2467 + device_unregister(chan_dev->dev);
2470 + spin_unlock_irqrestore(&npe_lock, flags);
2474 +static ssize_t show_hdlc_chan(struct device *dev, struct device_attribute *attr,
2477 + return print_channels(dev_get_drvdata(dev), buf, CHANNEL_HDLC);
2480 +static ssize_t set_hdlc_chan(struct device *dev, struct device_attribute *attr,
2481 + const char *buf, size_t len)
2483 + struct port *port = dev_get_drvdata(dev);
2484 + u8 channels[MAX_CHANNELS];
2485 + size_t orig_len = len;
2486 + unsigned long flags;
2490 + if ((err = parse_channels(&buf, &len, channels)) < 0)
2493 + spin_lock_irqsave(&npe_lock, flags);
2495 + if (port->mode != MODE_RAW && port->mode != MODE_G704) {
2500 + for (ch = 0; ch < MAX_CHANNELS; ch++)
2501 + if (channels[ch] &&
2502 + port->channels[ch] != CHANNEL_UNUSED &&
2503 + port->channels[ch] != CHANNEL_HDLC) {
2504 + printk(KERN_DEBUG "Channel #%i already in use\n", ch);
2509 + for (ch = 0; ch < MAX_CHANNELS; ch++)
2511 + port->channels[ch] = CHANNEL_HDLC;
2512 + else if (port->channels[ch] == CHANNEL_HDLC)
2513 + port->channels[ch] = CHANNEL_UNUSED;
2515 + if (port->chan_open_count || port->hdlc_open) {
2516 + hss_config_set_lut(port);
2517 + hss_config_load(port);
2520 + spin_unlock_irqrestore(&npe_lock, flags);
2524 + spin_unlock_irqrestore(&npe_lock, flags);
2528 +static ssize_t show_clock_type(struct device *dev,
2529 + struct device_attribute *attr, char *buf)
2531 + struct port *port = dev_get_drvdata(dev);
2533 + strcpy(buf, port->clock_type == CLOCK_INT ? "int\n" : "ext\n");
2537 +static ssize_t set_clock_type(struct device *dev, struct device_attribute *attr,
2538 + const char *buf, size_t len)
2540 + struct port *port = dev_get_drvdata(dev);
2541 + size_t orig_len = len;
2542 + unsigned long flags;
2543 + unsigned int clk, err;
2545 + if (len && buf[len - 1] == '\n')
2550 + if (!memcmp(buf, "ext", 3))
2552 + else if (!memcmp(buf, "int", 3))
2557 + spin_lock_irqsave(&npe_lock, flags);
2558 + if (port->plat->set_clock)
2559 + clk = port->plat->set_clock(port->id, clk);
2560 + if (clk != CLOCK_EXT && clk != CLOCK_INT) {
2561 + err = -EINVAL; /* plat->set_clock shouldn't change the state */
2564 + port->clock_type = clk;
2565 + if (port->chan_open_count || port->hdlc_open) {
2566 + hss_config_set_line(port);
2567 + hss_config_load(port);
2569 + spin_unlock_irqrestore(&npe_lock, flags);
2573 + spin_unlock_irqrestore(&npe_lock, flags);
2577 +static ssize_t show_clock_rate(struct device *dev,
2578 + struct device_attribute *attr, char *buf)
2580 + struct port *port = dev_get_drvdata(dev);
2582 + sprintf(buf, "%u\n", port->clock_rate);
2583 + return strlen(buf) + 1;
2586 +static ssize_t set_clock_rate(struct device *dev, struct device_attribute *attr,
2587 + const char *buf, size_t len)
2590 + struct port *port = dev_get_drvdata(dev);
2591 + size_t orig_len = len;
2592 + unsigned long flags;
2593 + unsigned int rate;
2595 + if (len && buf[len - 1] == '\n')
2598 + if (get_number(&buf, &len, &rate, 1, 0xFFFFFFFFu))
2603 + spin_lock_irqsave(&npe_lock, flags);
2604 + port->clock_rate = rate;
2605 + spin_unlock_irqrestore(&npe_lock, flags);
2608 + return -EINVAL; /* FIXME not yet supported */
2611 +static ssize_t show_frame_size(struct device *dev,
2612 + struct device_attribute *attr, char *buf)
2614 + struct port *port = dev_get_drvdata(dev);
2616 + if (port->mode != MODE_RAW && port->mode != MODE_G704)
2619 + sprintf(buf, "%u\n", port->frame_size);
2620 + return strlen(buf) + 1;
2623 +static ssize_t set_frame_size(struct device *dev, struct device_attribute *attr,
2624 + const char *buf, size_t len)
2626 + struct port *port = dev_get_drvdata(dev);
2628 + unsigned long flags;
2629 + unsigned int size;
2631 + if (len && buf[len - 1] == '\n')
2634 + if (get_number(&buf, &len, &size, MIN_FRAME_SIZE, MAX_FRAME_SIZE))
2636 + if (len || size % 8 > 1)
2639 + spin_lock_irqsave(&npe_lock, flags);
2640 + if (port->mode != MODE_RAW && port->mode != MODE_G704)
2642 + else if (!port->chan_open_count && !port->hdlc_open)
2645 + port->frame_size = size;
2646 + port->frame_sync_offset = 0;
2648 + spin_unlock_irqrestore(&npe_lock, flags);
2652 +static ssize_t show_frame_offset(struct device *dev,
2653 + struct device_attribute *attr, char *buf)
2655 + struct port *port = dev_get_drvdata(dev);
2657 + sprintf(buf, "%u\n", port->frame_sync_offset);
2658 + return strlen(buf) + 1;
2661 +static ssize_t set_frame_offset(struct device *dev,
2662 + struct device_attribute *attr,
2663 + const char *buf, size_t len)
2665 + struct port *port = dev_get_drvdata(dev);
2666 + size_t orig_len = len;
2667 + unsigned long flags;
2668 + unsigned int offset;
2670 + if (len && buf[len - 1] == '\n')
2673 + if (get_number(&buf, &len, &offset, 0, port->frame_size - 1))
2678 + spin_lock_irqsave(&npe_lock, flags);
2680 + port->frame_sync_offset = offset;
2681 + if (port->chan_open_count || port->hdlc_open) {
2682 + hss_config_set_rx_frame(port);
2683 + hss_config_load(port);
2686 + spin_unlock_irqrestore(&npe_lock, flags);
2690 +static ssize_t show_loopback(struct device *dev, struct device_attribute *attr,
2693 + struct port *port = dev_get_drvdata(dev);
2695 + sprintf(buf, "%u\n", port->loopback);
2696 + return strlen(buf) + 1;
2699 +static ssize_t set_loopback(struct device *dev, struct device_attribute *attr,
2700 + const char *buf, size_t len)
2702 + struct port *port = dev_get_drvdata(dev);
2703 + size_t orig_len = len;
2704 + unsigned long flags;
2707 + if (len && buf[len - 1] == '\n')
2710 + if (get_number(&buf, &len, &lb, 0, 1))
2715 + spin_lock_irqsave(&npe_lock, flags);
2717 + if (port->loopback != lb) {
2718 + port->loopback = lb;
2719 + if (port->chan_open_count || port->hdlc_open) {
2720 + hss_config_set_core(port);
2721 + hss_config_load(port);
2723 + if (port->loopback || port->carrier)
2724 + netif_carrier_on(port->netdev);
2726 + netif_carrier_off(port->netdev);
2729 + spin_unlock_irqrestore(&npe_lock, flags);
2733 +static ssize_t show_mode(struct device *dev, struct device_attribute *attr,
2736 + struct port *port = dev_get_drvdata(dev);
2738 + switch(port->mode) {
2740 + strcpy(buf, "raw\n");
2743 + strcpy(buf, "g704\n");
2746 + strcpy(buf, "hdlc\n");
2749 + return strlen(buf) + 1;
2752 +static ssize_t set_mode(struct device *dev, struct device_attribute *attr,
2753 + const char *buf, size_t len)
2755 + struct port *port = dev_get_drvdata(dev);
2757 + unsigned long flags;
2759 + if (len && buf[len - 1] == '\n')
2762 + spin_lock_irqsave(&npe_lock, flags);
2764 + if (port->chan_open_count || port->hdlc_open) {
2766 + } else if (len == 4 && !memcmp(buf, "hdlc", 4))
2767 + port->mode = MODE_HDLC;
2768 + else if (len == 3 && !memcmp(buf, "raw", 3))
2769 + port->mode = MODE_RAW;
2770 + else if (len == 4 && !memcmp(buf, "g704", 4))
2771 + port->mode = MODE_G704;
2775 + spin_unlock_irqrestore(&npe_lock, flags);
2779 +static struct device_attribute hss_attrs[] = {
2780 + __ATTR(create_chan, 0200, NULL, create_chan),
2781 + __ATTR(hdlc_chan, 0644, show_hdlc_chan, set_hdlc_chan),
2782 + __ATTR(clock_type, 0644, show_clock_type, set_clock_type),
2783 + __ATTR(clock_rate, 0644, show_clock_rate, set_clock_rate),
2784 + __ATTR(frame_size, 0644, show_frame_size, set_frame_size),
2785 + __ATTR(frame_offset, 0644, show_frame_offset, set_frame_offset),
2786 + __ATTR(loopback, 0644, show_loopback, set_loopback),
2787 + __ATTR(mode, 0644, show_mode, set_mode),
2790 +/*****************************************************************************
2792 + ****************************************************************************/
2794 +static int __devinit hss_init_one(struct platform_device *pdev)
2796 + struct port *port;
2797 + struct net_device *dev;
2798 + hdlc_device *hdlc;
2801 + if ((port = kzalloc(sizeof(*port), GFP_KERNEL)) == NULL)
2803 + platform_set_drvdata(pdev, port);
2804 + port->id = pdev->id;
2806 + if ((port->npe = npe_request(0)) == NULL) {
2811 + port->dev = &pdev->dev;
2812 + port->plat = pdev->dev.platform_data;
2813 + if ((port->netdev = dev = alloc_hdlcdev(port)) == NULL) {
2818 + SET_NETDEV_DEV(dev, &pdev->dev);
2819 + hdlc = dev_to_hdlc(dev);
2820 + hdlc->attach = hss_hdlc_attach;
2821 + hdlc->xmit = hss_hdlc_xmit;
2822 + dev->open = hss_hdlc_open;
2823 + dev->stop = hss_hdlc_close;
2824 + dev->do_ioctl = hss_hdlc_ioctl;
2825 + dev->tx_queue_len = 100;
2826 + port->clock_type = CLOCK_EXT;
2827 + port->clock_rate = 2048000;
2828 + port->frame_size = 256; /* E1 */
2829 + memset(port->channels, CHANNEL_UNUSED, sizeof(port->channels));
2830 + init_waitqueue_head(&port->chan_tx_waitq);
2831 + init_waitqueue_head(&port->chan_rx_waitq);
2832 + netif_napi_add(dev, &port->napi, hss_hdlc_poll, NAPI_WEIGHT);
2834 + if ((err = register_hdlc_device(dev))) /* HDLC mode by default */
2835 + goto err_free_netdev;
2837 + for (i = 0; i < ARRAY_SIZE(hss_attrs); i++)
2838 + BUG_ON(device_create_file(port->dev, &hss_attrs[i]));
2840 + printk(KERN_INFO "%s: HSS-%i\n", dev->name, port->id);
2846 + npe_release(port->npe);
2847 + platform_set_drvdata(pdev, NULL);
2853 +static int __devexit hss_remove_one(struct platform_device *pdev)
2855 + struct port *port = platform_get_drvdata(pdev);
2858 + for (i = 0; i < ARRAY_SIZE(hss_attrs); i++)
2859 + device_remove_file(port->dev, &hss_attrs[i]);
2861 + unregister_hdlc_device(port->netdev);
2862 + free_netdev(port->netdev);
2863 + npe_release(port->npe);
2864 + platform_set_drvdata(pdev, NULL);
2869 +static struct platform_driver drv = {
2870 + .driver.name = DRV_NAME,
2871 + .probe = hss_init_one,
2872 + .remove = hss_remove_one,
2875 +static int __init hss_init_module(void)
2880 + if ((ixp4xx_read_feature_bits() &
2881 + (IXP4XX_FEATURE_HDLC | IXP4XX_FEATURE_HSS)) !=
2882 + (IXP4XX_FEATURE_HDLC | IXP4XX_FEATURE_HSS))
2885 + if ((err = alloc_chrdev_region(&rdev, 0, HSS_COUNT * MAX_CHAN_DEVICES,
2889 + spin_lock_init(&npe_lock);
2891 + if (IS_ERR(hss_class = class_create(THIS_MODULE, "hss"))) {
2892 + printk(KERN_ERR "Can't register device class 'hss'\n");
2893 + err = PTR_ERR(hss_class);
2896 + if ((err = platform_driver_register(&drv)))
2897 + goto destroy_class;
2899 + chan_major = MAJOR(rdev);
2903 + class_destroy(hss_class);
2905 + unregister_chrdev_region(MKDEV(chan_major, 0),
2906 + HSS_COUNT * MAX_CHAN_DEVICES);
2910 +static void __exit hss_cleanup_module(void)
2912 + platform_driver_unregister(&drv);
2913 + class_destroy(hss_class);
2914 + unregister_chrdev_region(MKDEV(chan_major, 0),
2915 + HSS_COUNT * MAX_CHAN_DEVICES);
2918 +MODULE_AUTHOR("Krzysztof Halasa");
2919 +MODULE_DESCRIPTION("Intel IXP4xx HSS driver");
2920 +MODULE_LICENSE("GPL v2");
2921 +MODULE_ALIAS("platform:ixp4xx_hss");
2922 +module_init(hss_init_module);
2923 +module_exit(hss_cleanup_module);