1 diff -urN linux-2.4.25/drivers/atm/Makefile linux-2.4.25-atmdd/drivers/atm/Makefile
2 --- linux-2.4.25/drivers/atm/Makefile 2004-02-23 15:18:29.000000000 +0100
3 +++ linux-2.4.25-atmdd/drivers/atm/Makefile 2004-02-29 22:51:26.000000000 +0100
7 obj-$(CONFIG_ATM_DUMMY) += adummy.o
8 +obj-$(CONFIG_ATM_DD) += atmdd.o
9 obj-$(CONFIG_ATM_TCP) += atmtcp.o
10 obj-$(CONFIG_ATM_FIRESTREAM) += firestream.o
11 obj-$(CONFIG_ATM_LANAI) += lanai.o
12 diff -urN linux-2.4.25/drivers/atm/Kconfig linux-2.4.25-atmdd/drivers/atm/Kconfig
13 --- linux-2.4.25/drivers/atm/Kcnfig 2003-08-25 13:44:41.000000000 +0200
14 +++ linux-2.4.25-atmdd/drivers/atm/Kconfig 2004-02-29 22:52:59.000000000 +0100
18 depends on NETDEVICES && ATM
21 + tristate "ATM loopback"
22 + depends on INET && ATM
24 + This is an example atm driver. It does not require any actual ATM
25 + hardware. It supports AAL5 and AAL0. Frames are merely looped back
26 + to the sender on the same VC they were sent.
29 tristate "ATM over TCP"
30 diff -urN linux-2.4.25/drivers/atm/atmdd.c linux-2.4.25-atmdd/drivers/atm/atmdd.c
31 --- linux-2.4.25/drivers/atm/atmdd.c 1970-01-01 01:00:00.000000000 +0100
32 +++ linux-2.4.25-atmdd/drivers/atm/atmdd.c 2004-02-29 22:58:11.000000000 +0100
35 +#######################################################################
38 +# Alex Zeffertt, Cambridge Broadband Ltd, ajz@cambridgebroadband.com
40 +# This program is free software; you can redistribute it and/or
41 +# modify it under the terms of the GNU General Public License as
42 +# published by the Free Software Foundation; either version 2 of
43 +# the License, or (at your option) any later version.
45 +# This program is distributed in the hope that it will be useful,
46 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
47 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 +# GNU General Public License for more details.
50 +# You should have received a copy of the GNU General Public License
51 +# along with this program; if not, write to the Free Software
52 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
54 +#######################################################################
57 +# This is an example atm driver. It does not require any actual ATM
58 +# hardware. It supports AAL5 and AAL0. frames are merely looped back
59 +# to the sender on the same VC they were sent.
61 +#######################################################################
64 +/*############ Includes ###############################################*/
66 +#include <linux/module.h>
67 +#include <linux/config.h>
68 +#include <linux/kernel.h>
69 +#include <linux/errno.h>
70 +#include <linux/atm.h>
71 +#include <linux/atmdev.h>
72 +#include <linux/skbuff.h>
73 +#include <linux/init.h>
74 +#include <linux/netdevice.h>
75 +#include <linux/sched.h> /* for xtime */
77 +/*############ Defines ################################################*/
79 +#define MYATMDD "atmdd"
80 +#define KLOG_PREAMBLE MYATMDD ": "
81 +#define MYATMDD_VPI_BITS 1 /* Allow ?.1.? but not ?.2.? */
82 +#define MYATMDD_VCI_BITS 11 /* Allow ?.?.2047 but not ?.?.2048 */
83 +#define MYATMDD_PCR 100000
86 +#define AAL5_MTU (1510+8) /* Default AAL5 Maximum Transmission Unit (and length of AAL5 buffers) */
87 +#define AAL5_BUFLEN (((AAL5_MTU + 47)/48)*48) /* Round up to n*48 bytes */
89 +# define DEBUG(format,args...) printk(format,##args)
91 +# define DEBUG(format,args...)
93 +/*############ Types ##################################################*/
95 +/* status flags shared between s/w and emulated h/w */
97 + RX_EMPTY, /* No sk_buff present */
98 + RX_FULL, /* sk_buff present and awaiting data */
99 + RX_RECVD, /* sk_buff present and contains valid data */
100 +} myatmdd_rxstatus_e;
102 +/* status flags shared between s/w and emulated h/w */
104 + TX_EMPTY, /* No sk_buff present */
105 + TX_FULL, /* sk_buff present and awaiting transmission */
106 + TX_SENT, /* sk_buff present and has been sent */
107 +} myatmdd_txstatus_e;
110 + struct sk_buff **start;
111 + struct sk_buff **end;
112 + struct sk_buff **head;
113 + struct sk_buff **tail;
115 + /* everything below this line emulates h/w */
116 + myatmdd_rxstatus_e *status;
117 + struct sk_buff **hw_ptr;
123 + struct sk_buff **start;
124 + struct sk_buff **end;
125 + struct sk_buff **head;
126 + struct sk_buff **tail;
128 + /* everything below this line emulates h/w */
129 + myatmdd_txstatus_e *status;
130 + struct sk_buff **hw_ptr;
136 +} myatmdd_devdata_t;
139 + myatmdd_rxq_t rxqueue;
140 + myatmdd_txq_t txqueue;
141 +} myatmdd_vccdata_t;
143 +/*############ Module paramters #######################################*/
145 +MODULE_AUTHOR("Alex Zeffertt, ajz@cambridgebroadband.com");
146 +MODULE_DESCRIPTION("Example ATM device driver (loopback)");
147 +#ifdef MODULE_LICENSE
148 +MODULE_LICENSE("GPL");
150 +/*#################### Forward declarations ###########################*/
152 +static void myatmdd_emulate_loopback_hardware(struct atm_vcc *vcc);
154 +static void myatmdd_free_tx_skb(struct sk_buff *skb);
156 +/* these functions will need modifying in a real ATM driver */
157 +static void myatmdd_rx_interrupt(struct atm_vcc *vcc);
158 +static void myatmdd_tx_interrupt(struct atm_vcc *vcc);
160 +/* functions for manipulating circular bufs */
161 +static int myatmdd_init_rxq(myatmdd_rxq_t *queue, int size);
162 +static int myatmdd_init_txq(myatmdd_txq_t *queue, int size);
163 +static int myatmdd_release_rxq(myatmdd_rxq_t *queue);
164 +static int myatmdd_release_txq(myatmdd_txq_t *queue);
165 +static int myatmdd_txq_enqueue(myatmdd_txq_t *queue, struct sk_buff *skb);
166 +static int myatmdd_rxq_enqueue(myatmdd_rxq_t *queue, struct sk_buff *skb /* empty buffer */);
167 +static struct sk_buff *myatmdd_txq_dequeue(myatmdd_txq_t *queue);
168 +static struct sk_buff *myatmdd_rxq_dequeue(myatmdd_rxq_t *queue, int *pkt_len);
170 +/* myatmdd_ops registered by ATM device */
171 +static int myatmdd_open(struct atm_vcc *vcc);
172 +static void myatmdd_close(struct atm_vcc *vcc);
173 +static int myatmdd_ioctl(struct atm_dev *dev, unsigned int cmd,void *arg);
174 +static int myatmdd_setsockopt(struct atm_vcc *vcc,int level,int optname, void *optval,int optlen);
175 +static int myatmdd_getsockopt(struct atm_vcc *vcc,int level,int optname, void *optval,int optlen);
176 +static int myatmdd_send(struct atm_vcc *vcc,struct sk_buff *skb);
177 +static int myatmdd_change_qos(struct atm_vcc *vcc,struct atm_qos *qos,int flgs);
178 +static int myatmdd_proc_read(struct atm_dev *dev,loff_t *pos,char *page);
180 +/* myatmdd_phy_ops registered by phy driver */
181 +static void myatmdd_phy_int(struct atm_dev *dev);
182 +static int myatmdd_phy_start(struct atm_dev *dev); /* <-- This is the only thing exported by PHY driver */
183 +static int myatmdd_phy_ioctl(struct atm_dev *dev,unsigned int cmd,void *arg);
185 +/*#################### Global scope variables #########################*/
187 +/* operations registered by the atm device */
188 +static const struct atmdev_ops myatmdd_ops =
190 + open: myatmdd_open,
191 + close: myatmdd_close,
192 + ioctl: myatmdd_ioctl,
193 + getsockopt: myatmdd_getsockopt,
194 + setsockopt: myatmdd_setsockopt,
195 + send: myatmdd_send,
196 + change_qos: myatmdd_change_qos,
197 + proc_read: myatmdd_proc_read,
198 + owner: THIS_MODULE,
201 +/* operations registered by the phy driver */
202 +static const struct atmphy_ops myatmdd_phy_ops = {
203 + start: myatmdd_phy_start,
204 + ioctl: myatmdd_phy_ioctl,
205 + interrupt: myatmdd_phy_int,
208 +struct atm_dev *myatmdd_dev;
210 +/*#################### Function definitions ###########################*/
214 +#########################################################
216 +# Function : myatmdd_rx_interrupt, and myatmdd_tx_interrupt
218 +# Purpose : handle interrupt from hardware. In first
219 +# case this means extract recvd buffers and pass
220 +# it up protocol stack. In 2nd case this means
221 +# free the sent buffers.
223 +# Args : pointer to private data of the VCC concerned
229 +##########################################################
232 +# AJZ 10Apr03 Created
233 +##########################################################
236 +static void myatmdd_rx_interrupt(struct atm_vcc *vcc)
238 + struct sk_buff *skb;
239 + myatmdd_vccdata_t *priv = vcc->dev_data;
242 + DEBUG("%s\n", __FUNCTION__);
244 + while ((skb = myatmdd_rxq_dequeue(&priv->rxqueue, &pkt_len)))
246 + struct sk_buff *newskb;
247 + struct timeval stamp;
249 + /* Get a new skb to replace the one just consumed */
250 + if (!(newskb = dev_alloc_skb(AAL5_BUFLEN)))
252 + atomic_inc(&vcc->stats->rx_err);
253 + printk(KERN_ERR KLOG_PREAMBLE "cannot receive packet - out of memory\n");
254 + /* put skb back in rx queue) */
255 + myatmdd_rxq_enqueue(&priv->rxqueue, skb);
258 + myatmdd_rxq_enqueue(&priv->rxqueue, newskb);
260 + if (!atm_charge (vcc, skb->truesize))
262 + /* Exceeded memory quota for this vcc
263 + * NOTE: if atm_charge succeeds you must then push or accounting will screw up
265 + dev_kfree_skb(skb);
266 + /* &vcc->stats->drop stats incremented in atm_charge */
270 + /* sk_buff passed all sanity checks! */
272 + /* Add received length to socket buffer */
273 + skb_put(skb, pkt_len);
275 + /* update device stats */
276 + atomic_inc(&vcc->stats->rx);
278 + /* add timestamp for upper layers to use */
279 + do_gettimeofday(&stamp);
280 + skb_set_timestamp(skb, &stamp);
282 + /* Point socket buffer at the right VCC before giving to socket layer */
283 + ATM_SKB(skb)->vcc = vcc;
285 + /* push socket buffer up to ATM layer */
286 + vcc->push(vcc, skb);
291 +static void myatmdd_tx_interrupt(struct atm_vcc *vcc)
293 + struct sk_buff *skb;
294 + myatmdd_vccdata_t *priv = vcc->dev_data;
296 + DEBUG("%s\n", __FUNCTION__);
298 + while ((skb = myatmdd_txq_dequeue(&priv->txqueue)))
300 + // Update channel stats and free the memory
301 + atomic_inc(&vcc->stats->tx);
302 + myatmdd_free_tx_skb(skb);
307 +#########################################################
309 +# Function : myatmdd_emulate_loopback_hardware
311 +# Purpose : emulate things normally done by hardware
312 +# i.e. copying tx bufs to rx bufs (we're modelling
313 +# a loopback system here), calling the tx done
314 +# interrupt, and calling the rx done interrupt.
316 +# Args : priv = data private to VCC
322 +##########################################################
325 +# AJZ 10Apr03 Created
326 +##########################################################
328 +static void myatmdd_emulate_loopback_hardware(struct atm_vcc *vcc)
330 + myatmdd_vccdata_t *priv = vcc->dev_data;
331 + struct sk_buff **ptxskb;
332 + struct sk_buff **prxskb;
334 + DEBUG("%s\n", __FUNCTION__);
336 + ptxskb = priv->txqueue.hw_ptr;
337 + prxskb = priv->rxqueue.hw_ptr;
339 + /* Send each tx buff waiting to go */
340 + while (priv->txqueue.status[ptxskb - priv->txqueue.start] == TX_FULL)
342 + struct sk_buff *txskb = *ptxskb;
343 + struct sk_buff *rxskb = *prxskb;
344 + int pkt_len = priv->txqueue.pkt_len[ptxskb - priv->txqueue.start];
346 + /* Is there an rx buffer? */
347 + if (priv->rxqueue.status[prxskb - priv->rxqueue.start] == RX_FULL)
349 + /* Yes - Is the length in range? */
350 + if (pkt_len <= AAL5_BUFLEN)
352 + /* Yes - do the copy */
353 + memcpy(rxskb->data, txskb->data,pkt_len);
354 + priv->rxqueue.pkt_len[prxskb - priv->rxqueue.start] = pkt_len;
356 + /* Indicate rx buffer recvd */
357 + priv->rxqueue.status[prxskb - priv->rxqueue.start] = RX_RECVD;
359 + /* increment and maybe wrap rx pointer */
360 + if (++prxskb == priv->rxqueue.end)
361 + prxskb = priv->rxqueue.start;
362 + priv->rxqueue.hw_ptr = prxskb;
366 + /* No - then h/w cannot do a recv */
367 + printk(KERN_ERR KLOG_PREAMBLE "recvd frame too long - discarded\n");
372 + /* No - then h/w cannot do a recv */
373 + printk(KERN_ERR KLOG_PREAMBLE "no rx buffers available\n");
376 + /* Indicate tx buffer sent */
377 + priv->txqueue.status[ptxskb - priv->txqueue.start] = TX_SENT;
379 + /* increment and maybe wrap tx pointer */
380 + if (++ptxskb == priv->txqueue.end)
381 + ptxskb = priv->txqueue.start;
382 + priv->txqueue.hw_ptr = ptxskb;
384 + /* Call tx ring interrupt handler */
385 + myatmdd_tx_interrupt(vcc);
387 + /* Call tx ring interrupt handler */
388 + myatmdd_rx_interrupt(vcc);
393 +#########################################################
395 +# Function : functions for manipulating circular buffs
405 +##########################################################
408 +# AJZ 10Apr03 Created
409 +##########################################################
412 +static int myatmdd_init_rxq(myatmdd_rxq_t *queue, int size)
414 + /* TODO - cope with kmalloc failure */
415 + struct sk_buff **pskb;
418 + DEBUG("%s\n", __FUNCTION__);
419 + queue->hw_ptr = queue->head = queue->tail =
420 + queue->start = kmalloc(size * sizeof(struct sk_buff *), GFP_KERNEL);
421 + queue->end = &queue->start[size];
422 + for (pskb = queue->start; pskb < queue->end; pskb++)
425 + queue->status = kmalloc(size * sizeof(myatmdd_rxstatus_e),GFP_KERNEL);
426 + for (i = 0; i < size; i++)
427 + queue->status[i] = RX_EMPTY;
429 + queue->pkt_len = kmalloc(size * sizeof(int),GFP_KERNEL);
430 + for (i = 0; i < size; i++)
431 + queue->pkt_len[i] = 0;
436 +static int myatmdd_init_txq(myatmdd_txq_t *queue, int size)
438 + /* TODO - cope with kmalloc failure */
439 + struct sk_buff **pskb;
442 + DEBUG("%s\n", __FUNCTION__);
443 + queue->hw_ptr = queue->head = queue->tail =
444 + queue->start = kmalloc(size * sizeof(struct sk_buff *), GFP_KERNEL);
445 + queue->end = &queue->start[size];
446 + for (pskb = queue->start; pskb < queue->end; pskb++)
449 + queue->status = kmalloc(size * sizeof(myatmdd_rxstatus_e),GFP_KERNEL);
450 + for (i = 0; i < size; i++)
451 + queue->status[i] = TX_EMPTY;
453 + queue->pkt_len = kmalloc(size * sizeof(int),GFP_KERNEL);
454 + for (i = 0; i < size; i++)
455 + queue->pkt_len[i] = 0;
460 +static int myatmdd_release_rxq(myatmdd_rxq_t *queue)
462 + struct sk_buff **pskb;
464 + DEBUG("%s\n", __FUNCTION__);
465 + for (pskb = queue->start; pskb < queue->end; pskb++)
467 + /* Is there an skb here */
469 + continue; /* No, so skip this entry in ring */
471 + /* Yes - free it */
472 + dev_kfree_skb(*pskb);
474 + kfree(queue->start);
475 + kfree(queue->status);
476 + kfree(queue->pkt_len);
481 +static int myatmdd_release_txq(myatmdd_txq_t *queue)
483 + struct sk_buff **pskb;
485 + DEBUG("%s\n", __FUNCTION__);
486 + /* Scan through all TX bd's and cleanup */
487 + for (pskb = queue->start; pskb < queue->end; pskb++)
489 + /* Is this buffer currently unused - i.e. no skb */
491 + continue; /* Yes, so ignore it */
493 + /* If we reach here, we have found a socket buffer that
494 + * exists in the TX ring and is waiting to be released.
496 + printk(KERN_WARNING KLOG_PREAMBLE "discarding unsent tx sk_buff\n");
497 + atomic_inc(&ATM_SKB(*pskb)->vcc->stats->tx_err);
498 + myatmdd_free_tx_skb(*pskb);
500 + kfree(queue->start);
501 + kfree(queue->status);
502 + kfree(queue->pkt_len);
507 +/* returns non-zero for "out of space" */
508 +static int myatmdd_txq_enqueue(myatmdd_txq_t *queue, struct sk_buff *skb)
510 + /* increment head and wrap */
511 + struct sk_buff **newhead = queue->head + 1;
512 + if (newhead == queue->end)
513 + newhead = queue->start;
515 + DEBUG("%s\n", __FUNCTION__);
517 + /* abort if tx ring full */
518 + if (newhead == queue->tail)
521 + /* all is okay if we're here */
522 + *queue->head = skb;
523 + /* Tell hardware there's a buffer to send */
524 + queue->status[queue->head - queue->start] = TX_FULL;
525 + queue->pkt_len[queue->head - queue->start] = skb->len;
526 + queue->head = newhead;
530 +/* returns non-zero for "out of space" */
531 +static int myatmdd_rxq_enqueue(myatmdd_rxq_t *queue, struct sk_buff *skb /* empty buffer */)
533 + /* increment head and wrap */
534 + struct sk_buff **newhead = queue->head + 1;
535 + if (newhead == queue->end)
536 + newhead = queue->start;
538 + DEBUG("%s\n", __FUNCTION__);
540 + /* abort if rx ring full */
541 + if (newhead == queue->tail)
544 + /* all is okay if we're here */
545 + *queue->head = skb;
546 + /* Tell hardware there's a buffer to send */
547 + queue->status[queue->head - queue->start] = RX_FULL;
548 + queue->head = newhead;
552 +static struct sk_buff *myatmdd_txq_dequeue(myatmdd_txq_t *queue)
554 + DEBUG("%s\n", __FUNCTION__);
555 + if (queue->tail != queue->head && queue->status[queue->tail - queue->start] == TX_SENT)
557 + struct sk_buff *skb = *queue->tail;
559 + /* increment tail and wrap */
560 + struct sk_buff **newtail = queue->tail + 1;
561 + if (newtail == queue->end)
562 + newtail = queue->start;
563 + *queue->tail = NULL;
564 + queue->status[queue->tail - queue->start] = TX_EMPTY;
565 + queue->tail = newtail;
571 +/* returns NULL for "no new recvd frames" */
572 +static struct sk_buff *myatmdd_rxq_dequeue(myatmdd_rxq_t *queue, int *pkt_len)
574 + DEBUG("%s\n", __FUNCTION__);
575 + if (queue->tail != queue->head && queue->status[queue->tail - queue->start] == RX_RECVD)
577 + struct sk_buff *skb = *queue->tail;
579 + /* increment tail and wrap */
580 + struct sk_buff **newtail = queue->tail + 1;
581 + if (newtail == queue->end)
582 + newtail = queue->start;
583 + *queue->tail = NULL;
584 + queue->status[queue->tail - queue->start] = RX_EMPTY;
585 + *pkt_len = queue->pkt_len[queue->tail - queue->start];
586 + queue->tail = newtail;
593 +#########################################################
595 +# Functions : Implementations of function ptrs in
596 +# myatmdd_phy_ops. This is the phy driver
597 +# start: myatmdd_phy_start,
598 +# ioctl: myatmdd_phy_ioctl,
599 +# interrupt: myatmdd_phy_int,
601 +# Purpose : See ATM device driver interface v0.1
603 +# Notes : Conforming to Linux ATM device driver i/f
604 +# interface. Draft version 0.1
606 +# Designed to work with multiple devices
607 +##########################################################
610 +# AJZ 10Apr03 Created
611 +##########################################################
613 +static int myatmdd_phy_start(struct atm_dev *dev)
615 + /* Provide ATM driver with a pointer via which it
616 + * may invoke PHY driver's IOCTL or interrupt
619 + dev->phy = &myatmdd_phy_ops;
621 + /* If required allocate phy private data and save
622 + * pointer in dev->phy_data;
625 + /* TODO Initialise PHY hardware... */
630 +/* Should be called by SAR driver when it needs to handle an interrupt
631 + * triggered by PHY.
633 +static void myatmdd_phy_int(struct atm_dev *dev)
635 + /* Handle interrupt triggered by PHY */
638 +/* Gets called by SAR driver IOCTL handler for IOCTLS it doesn't recognise */
639 +static int myatmdd_phy_ioctl(struct atm_dev *dev,unsigned int cmd,void *arg)
643 +// case SONET_GETSTATZ:
650 +#########################################################
652 +# Function : myatmdd_free_tx_skb
654 +# Purpose : frees an sk_buff.
656 +# Args : skb=pointer to socket buffer
658 +# Notes : Tries to use the upper layer pop() function
659 +# but uses dev_kfree_skb() if this doesn't exist
660 +##########################################################
663 +# AJZ 10Apr03 Created
664 +##########################################################
666 +static void myatmdd_free_tx_skb(struct sk_buff *skb)
668 + struct atm_vcc *vcc;
670 + DEBUG("%s\n", __FUNCTION__);
672 + /* See if we can use the VCC pop function */
673 + if (((vcc = ATM_SKB(skb)->vcc) != NULL) && (vcc->pop != NULL))
675 + /* Yes, so use ATM socket layer pop function */
676 + vcc->pop(vcc, skb);
680 + printk(KERN_WARNING KLOG_PREAMBLE "unable to call skb free function\n");
681 + /* No, so free socket buffer */
682 + dev_kfree_skb(skb);
687 +#########################################################
689 +# Functions : Implementations of function ptrs in
694 +# myatmdd_getsockopt(),
695 +# myatmdd_setsockopt(),
697 +# myatmdd_sg_send(),
698 +# myatmdd_change_qos(),
699 +# myatmdd_proc_read()
702 +# Purpose : See ATM device driver interface v0.1
704 +# Notes : Conforming to Linux ATM device driver i/f
705 +# interface. Draft version 0.1
707 +# Designed to work with multiple devices
708 +##########################################################
711 +# AJZ 10Apr03 Created
712 +##########################################################
714 +static int myatmdd_open(struct atm_vcc *vcc)
716 + myatmdd_vccdata_t *priv;
719 + DEBUG("%s\n", __FUNCTION__);
721 + /* Make sure we are opening a AAL0 or AAL5 connection */
722 + if ((vcc->qos.aal != ATM_AAL5) && (vcc->qos.aal != ATM_AAL0))
724 + printk(KERN_WARNING KLOG_PREAMBLE "invalid AAL\n");
728 + /* Address is in use */
729 + set_bit(ATM_VF_ADDR, &vcc->flags);
731 + /* Allocate some vcc-private memory */
732 + vcc->dev_data = kmalloc(sizeof(myatmdd_vccdata_t), GFP_KERNEL);
733 + if (vcc->dev_data == NULL)
735 + priv = vcc->dev_data;
737 + /* Setup the hardware for new VC... */
739 + /* Do not allow half open VCs - otherwise the example driver will not be able
740 + * to loop back frames sent !
742 + if (vcc->qos.rxtp.traffic_class == ATM_NONE || vcc->qos.txtp.traffic_class == ATM_NONE)
744 + kfree(vcc->dev_data);
748 + /* Create rx/tx queues for this VC */
749 + myatmdd_init_txq(&priv->txqueue, TXQ_SZ);
750 + myatmdd_init_rxq(&priv->rxqueue, RXQ_SZ);
752 + /* Fill rx queue with empty skbuffs */
753 + for (i = 0 ; i < RXQ_SZ - 1; i++)
755 + struct sk_buff *skb = dev_alloc_skb(AAL5_BUFLEN);
756 + myatmdd_rxq_enqueue(&priv->rxqueue,skb);
759 + /* Connection is now ready to receive data */
760 + set_bit(ATM_VF_READY, &vcc->flags);
765 +static void myatmdd_close(struct atm_vcc *vcc)
767 + myatmdd_vccdata_t *priv = vcc->dev_data;
769 + DEBUG("%s\n", __FUNCTION__);
771 + /* Indicate channel closed */
772 + clear_bit(ATM_VF_READY, &vcc->flags);
774 + /* TODO Uninitialise the hardware for this VC... */
776 + /* empty the rx and tx queues */
777 + myatmdd_release_txq(&priv->txqueue);
778 + myatmdd_release_rxq(&priv->rxqueue);
780 + /* Free the vcc-private memory */
781 + kfree(vcc->dev_data);
784 +static int myatmdd_ioctl(struct atm_dev *dev, unsigned int cmd,void *arg)
786 + /* myatmdd does not currently have an ioctl interface so pass ioctl onto PHY */
787 + if (dev->phy && dev->phy->ioctl) {
788 + return dev->phy->ioctl(dev, cmd, arg);
793 +static int myatmdd_getsockopt(struct atm_vcc *vcc,int level,int optname, void *optval,int optlen)
798 +static int myatmdd_setsockopt(struct atm_vcc *vcc,int level,int optname, void *optval,int optlen)
803 +/* Note may be called in either process or interrupt context! */
804 +static int myatmdd_send(struct atm_vcc *vcc,struct sk_buff *skb)
806 + myatmdd_vccdata_t *priv = vcc->dev_data;
808 + DEBUG("%s\n", __FUNCTION__);
810 + /* Assign VCC to socket buffer
811 + * Note: this must be done before attempting to call
812 + * myatmdd_free_tx_skb() as this may use ATM_SKB(skb)->vcc->pop()
814 + ATM_SKB(skb)->vcc = vcc;
816 + /* Setup hardware to send and arrange callback of myatmdd_send_complete... */
818 + /* In this example ATM device driver all VCs are looped back.
819 + * So copy to the rxq and emulate an rx interrupt
822 + /* Can we accept another skb to send ? */
823 + if (myatmdd_txq_enqueue(&priv->txqueue, skb))
825 + /* No - free socket buffer */
826 + myatmdd_free_tx_skb(skb);
828 + /* Update tx channel stats */
829 + atomic_inc(&vcc->stats->tx_err);
831 + /* Tell protocol layer to back off */
835 + /* This is the bit which copies the tx ring to the rx ring,
836 + * and triggers emulated rx and tx interrupts
838 + myatmdd_emulate_loopback_hardware(vcc);
843 +static int myatmdd_change_qos(struct atm_vcc *vcc,struct atm_qos *qos,int flgs)
848 +static int myatmdd_proc_read(struct atm_dev *dev,loff_t *pos,char *page)
850 + int left = (int) *pos;
853 + return sprintf(page, "1st line of stats\n");
855 + return sprintf(page, "2nd line of stats\n");
857 + return sprintf(page, "3rd line of stats\n");
863 +#########################################################
865 +# Function : myatmdd_init
867 +# Purpose : init the module, init and register the ATM device
871 +# Returns : return code
875 +##########################################################
878 +# AJZ 10Apr03 Created
879 +##########################################################
881 +int __init myatmdd_init(void)
883 + myatmdd_devdata_t *priv = kmalloc(sizeof(myatmdd_devdata_t),GFP_KERNEL);
888 + /* Register the new device */
889 + myatmdd_dev = atm_dev_register(MYATMDD,&myatmdd_ops,-1,NULL);
891 + /* Were we able to register this device? */
892 + if (myatmdd_dev == NULL)
894 + printk(KERN_ERR KLOG_PREAMBLE "failed to register CPM ATM device\n");
898 + /* Save pointer to device private data */
899 + myatmdd_dev->dev_data = priv;
901 + /* Initialise device parameters */
902 + myatmdd_dev->ci_range.vpi_bits = MYATMDD_VPI_BITS;
903 + myatmdd_dev->ci_range.vci_bits = MYATMDD_VCI_BITS;
904 + myatmdd_dev->link_rate = MYATMDD_PCR;
906 + /* Set up phy device */
907 + myatmdd_phy_start(myatmdd_dev);
909 + /* TODO Initialise SAR hardware... */
911 + /* Console output */
912 + printk(KERN_INFO KLOG_PREAMBLE "Initialised\n");
918 + * module_init() is called by insmod, if built as module,
919 + * or by do_initcalls(), if built as a resident driver.
921 +module_init(myatmdd_init);
924 +#########################################################
926 +# Function : myatmdd_exit
928 +# Purpose : delete module, uninit and dereg ATM device
936 +##########################################################
939 +# AJZ 10Apr03 Created
940 +##########################################################
944 +static void __exit myatmdd_exit(void)
946 + /* Disable SAR hardware... */
948 + /* Console output */
949 + printk(KERN_ERR KLOG_PREAMBLE "Uninitialised\n");
950 + kfree(myatmdd_dev->dev_data);
951 + atm_dev_deregister(myatmdd_dev);
953 +module_exit(myatmdd_exit);