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 if ATM_DRIVERS && 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 "Dummy ATM driver"
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/kernel.h>
68 +#include <linux/errno.h>
69 +#include <linux/atm.h>
70 +#include <linux/atmdev.h>
71 +#include <linux/skbuff.h>
72 +#include <linux/init.h>
73 +#include <linux/netdevice.h>
74 +#include <linux/sched.h> /* for xtime */
76 +/*############ Defines ################################################*/
78 +#define MYATMDD "atmdd"
79 +#define KLOG_PREAMBLE MYATMDD ": "
80 +#define MYATMDD_VPI_BITS 1 /* Allow ?.1.? but not ?.2.? */
81 +#define MYATMDD_VCI_BITS 11 /* Allow ?.?.2047 but not ?.?.2048 */
82 +#define MYATMDD_PCR 100000
85 +#define AAL5_MTU (1510+8) /* Default AAL5 Maximum Transmission Unit (and length of AAL5 buffers) */
86 +#define AAL5_BUFLEN (((AAL5_MTU + 47)/48)*48) /* Round up to n*48 bytes */
88 +# define DEBUG(format,args...) printk(format,##args)
90 +# define DEBUG(format,args...)
92 +/*############ Types ##################################################*/
94 +/* status flags shared between s/w and emulated h/w */
96 + RX_EMPTY, /* No sk_buff present */
97 + RX_FULL, /* sk_buff present and awaiting data */
98 + RX_RECVD, /* sk_buff present and contains valid data */
99 +} myatmdd_rxstatus_e;
101 +/* status flags shared between s/w and emulated h/w */
103 + TX_EMPTY, /* No sk_buff present */
104 + TX_FULL, /* sk_buff present and awaiting transmission */
105 + TX_SENT, /* sk_buff present and has been sent */
106 +} myatmdd_txstatus_e;
109 + struct sk_buff **start;
110 + struct sk_buff **end;
111 + struct sk_buff **head;
112 + struct sk_buff **tail;
114 + /* everything below this line emulates h/w */
115 + myatmdd_rxstatus_e *status;
116 + struct sk_buff **hw_ptr;
122 + struct sk_buff **start;
123 + struct sk_buff **end;
124 + struct sk_buff **head;
125 + struct sk_buff **tail;
127 + /* everything below this line emulates h/w */
128 + myatmdd_txstatus_e *status;
129 + struct sk_buff **hw_ptr;
135 +} myatmdd_devdata_t;
138 + myatmdd_rxq_t rxqueue;
139 + myatmdd_txq_t txqueue;
140 +} myatmdd_vccdata_t;
142 +/*############ Module paramters #######################################*/
144 +MODULE_AUTHOR("Alex Zeffertt, ajz@cambridgebroadband.com");
145 +MODULE_DESCRIPTION("Example ATM device driver (loopback)");
146 +#ifdef MODULE_LICENSE
147 +MODULE_LICENSE("GPL");
149 +/*#################### Forward declarations ###########################*/
151 +static void myatmdd_emulate_loopback_hardware(struct atm_vcc *vcc);
153 +static void myatmdd_free_tx_skb(struct sk_buff *skb);
155 +/* these functions will need modifying in a real ATM driver */
156 +static void myatmdd_rx_interrupt(struct atm_vcc *vcc);
157 +static void myatmdd_tx_interrupt(struct atm_vcc *vcc);
159 +/* functions for manipulating circular bufs */
160 +static int myatmdd_init_rxq(myatmdd_rxq_t *queue, int size);
161 +static int myatmdd_init_txq(myatmdd_txq_t *queue, int size);
162 +static int myatmdd_release_rxq(myatmdd_rxq_t *queue);
163 +static int myatmdd_release_txq(myatmdd_txq_t *queue);
164 +static int myatmdd_txq_enqueue(myatmdd_txq_t *queue, struct sk_buff *skb);
165 +static int myatmdd_rxq_enqueue(myatmdd_rxq_t *queue, struct sk_buff *skb /* empty buffer */);
166 +static struct sk_buff *myatmdd_txq_dequeue(myatmdd_txq_t *queue);
167 +static struct sk_buff *myatmdd_rxq_dequeue(myatmdd_rxq_t *queue, int *pkt_len);
169 +/* myatmdd_ops registered by ATM device */
170 +static int myatmdd_open(struct atm_vcc *vcc);
171 +static void myatmdd_close(struct atm_vcc *vcc);
172 +static int myatmdd_ioctl(struct atm_dev *dev, unsigned int cmd,void *arg);
173 +static int myatmdd_setsockopt(struct atm_vcc *vcc,int level,int optname, void __user *optval,unsigned int optlen);
174 +static int myatmdd_getsockopt(struct atm_vcc *vcc,int level,int optname, void __user *optval,int optlen);
175 +static int myatmdd_send(struct atm_vcc *vcc,struct sk_buff *skb);
176 +static int myatmdd_change_qos(struct atm_vcc *vcc,struct atm_qos *qos,int flgs);
177 +static int myatmdd_proc_read(struct atm_dev *dev,loff_t *pos,char *page);
179 +/* myatmdd_phy_ops registered by phy driver */
180 +static void myatmdd_phy_int(struct atm_dev *dev);
181 +static int myatmdd_phy_start(struct atm_dev *dev); /* <-- This is the only thing exported by PHY driver */
182 +static int myatmdd_phy_ioctl(struct atm_dev *dev,unsigned int cmd,void *arg);
184 +/*#################### Global scope variables #########################*/
186 +/* operations registered by the atm device */
187 +static const struct atmdev_ops myatmdd_ops =
189 + open: myatmdd_open,
190 + close: myatmdd_close,
191 + ioctl: myatmdd_ioctl,
192 + getsockopt: myatmdd_getsockopt,
193 + setsockopt: myatmdd_setsockopt,
194 + send: myatmdd_send,
195 + change_qos: myatmdd_change_qos,
196 + proc_read: myatmdd_proc_read,
197 + owner: THIS_MODULE,
200 +/* operations registered by the phy driver */
201 +static const struct atmphy_ops myatmdd_phy_ops = {
202 + start: myatmdd_phy_start,
203 + ioctl: myatmdd_phy_ioctl,
204 + interrupt: myatmdd_phy_int,
207 +struct atm_dev *myatmdd_dev;
209 +/*#################### Function definitions ###########################*/
213 +#########################################################
215 +# Function : myatmdd_rx_interrupt, and myatmdd_tx_interrupt
217 +# Purpose : handle interrupt from hardware. In first
218 +# case this means extract recvd buffers and pass
219 +# it up protocol stack. In 2nd case this means
220 +# free the sent buffers.
222 +# Args : pointer to private data of the VCC concerned
228 +##########################################################
231 +# AJZ 10Apr03 Created
232 +##########################################################
235 +static void myatmdd_rx_interrupt(struct atm_vcc *vcc)
237 + struct sk_buff *skb;
238 + myatmdd_vccdata_t *priv = vcc->dev_data;
241 + DEBUG("%s\n", __FUNCTION__);
243 + while ((skb = myatmdd_rxq_dequeue(&priv->rxqueue, &pkt_len)))
245 + struct sk_buff *newskb;
247 + /* Get a new skb to replace the one just consumed */
248 + if (!(newskb = dev_alloc_skb(AAL5_BUFLEN)))
250 + atomic_inc(&vcc->stats->rx_err);
251 + printk(KERN_ERR KLOG_PREAMBLE "cannot receive packet - out of memory\n");
252 + /* put skb back in rx queue) */
253 + myatmdd_rxq_enqueue(&priv->rxqueue, skb);
256 + myatmdd_rxq_enqueue(&priv->rxqueue, newskb);
258 + if (!atm_charge (vcc, skb->truesize))
260 + /* Exceeded memory quota for this vcc
261 + * NOTE: if atm_charge succeeds you must then push or accounting will screw up
263 + dev_kfree_skb(skb);
264 + /* &vcc->stats->drop stats incremented in atm_charge */
268 + /* sk_buff passed all sanity checks! */
270 + /* Add received length to socket buffer */
271 + skb_put(skb, pkt_len);
273 + /* update device stats */
274 + atomic_inc(&vcc->stats->rx);
276 + /* add timestamp for upper layers to use */
277 + ktime_t kt = ktime_get_real();
280 + /* Point socket buffer at the right VCC before giving to socket layer */
281 + ATM_SKB(skb)->vcc = vcc;
283 + /* push socket buffer up to ATM layer */
284 + vcc->push(vcc, skb);
289 +static void myatmdd_tx_interrupt(struct atm_vcc *vcc)
291 + struct sk_buff *skb;
292 + myatmdd_vccdata_t *priv = vcc->dev_data;
294 + DEBUG("%s\n", __FUNCTION__);
296 + while ((skb = myatmdd_txq_dequeue(&priv->txqueue)))
298 + // Update channel stats and free the memory
299 + atomic_inc(&vcc->stats->tx);
300 + myatmdd_free_tx_skb(skb);
305 +#########################################################
307 +# Function : myatmdd_emulate_loopback_hardware
309 +# Purpose : emulate things normally done by hardware
310 +# i.e. copying tx bufs to rx bufs (we're modelling
311 +# a loopback system here), calling the tx done
312 +# interrupt, and calling the rx done interrupt.
314 +# Args : priv = data private to VCC
320 +##########################################################
323 +# AJZ 10Apr03 Created
324 +##########################################################
326 +static void myatmdd_emulate_loopback_hardware(struct atm_vcc *vcc)
328 + myatmdd_vccdata_t *priv = vcc->dev_data;
329 + struct sk_buff **ptxskb;
330 + struct sk_buff **prxskb;
332 + DEBUG("%s\n", __FUNCTION__);
334 + ptxskb = priv->txqueue.hw_ptr;
335 + prxskb = priv->rxqueue.hw_ptr;
337 + /* Send each tx buff waiting to go */
338 + while (priv->txqueue.status[ptxskb - priv->txqueue.start] == TX_FULL)
340 + struct sk_buff *txskb = *ptxskb;
341 + struct sk_buff *rxskb = *prxskb;
342 + int pkt_len = priv->txqueue.pkt_len[ptxskb - priv->txqueue.start];
344 + /* Is there an rx buffer? */
345 + if (priv->rxqueue.status[prxskb - priv->rxqueue.start] == RX_FULL)
347 + /* Yes - Is the length in range? */
348 + if (pkt_len <= AAL5_BUFLEN)
350 + /* Yes - do the copy */
351 + memcpy(rxskb->data, txskb->data,pkt_len);
352 + priv->rxqueue.pkt_len[prxskb - priv->rxqueue.start] = pkt_len;
354 + /* Indicate rx buffer recvd */
355 + priv->rxqueue.status[prxskb - priv->rxqueue.start] = RX_RECVD;
357 + /* increment and maybe wrap rx pointer */
358 + if (++prxskb == priv->rxqueue.end)
359 + prxskb = priv->rxqueue.start;
360 + priv->rxqueue.hw_ptr = prxskb;
364 + /* No - then h/w cannot do a recv */
365 + printk(KERN_ERR KLOG_PREAMBLE "recvd frame too long - discarded\n");
370 + /* No - then h/w cannot do a recv */
371 + printk(KERN_ERR KLOG_PREAMBLE "no rx buffers available\n");
374 + /* Indicate tx buffer sent */
375 + priv->txqueue.status[ptxskb - priv->txqueue.start] = TX_SENT;
377 + /* increment and maybe wrap tx pointer */
378 + if (++ptxskb == priv->txqueue.end)
379 + ptxskb = priv->txqueue.start;
380 + priv->txqueue.hw_ptr = ptxskb;
382 + /* Call tx ring interrupt handler */
383 + myatmdd_tx_interrupt(vcc);
385 + /* Call tx ring interrupt handler */
386 + myatmdd_rx_interrupt(vcc);
391 +#########################################################
393 +# Function : functions for manipulating circular buffs
403 +##########################################################
406 +# AJZ 10Apr03 Created
407 +##########################################################
410 +static int myatmdd_init_rxq(myatmdd_rxq_t *queue, int size)
412 + /* TODO - cope with kmalloc failure */
413 + struct sk_buff **pskb;
416 + DEBUG("%s\n", __FUNCTION__);
417 + queue->hw_ptr = queue->head = queue->tail =
418 + queue->start = kmalloc(size * sizeof(struct sk_buff *), GFP_KERNEL);
419 + queue->end = &queue->start[size];
420 + for (pskb = queue->start; pskb < queue->end; pskb++)
423 + queue->status = kmalloc(size * sizeof(myatmdd_rxstatus_e),GFP_KERNEL);
424 + for (i = 0; i < size; i++)
425 + queue->status[i] = RX_EMPTY;
427 + queue->pkt_len = kmalloc(size * sizeof(int),GFP_KERNEL);
428 + for (i = 0; i < size; i++)
429 + queue->pkt_len[i] = 0;
434 +static int myatmdd_init_txq(myatmdd_txq_t *queue, int size)
436 + /* TODO - cope with kmalloc failure */
437 + struct sk_buff **pskb;
440 + DEBUG("%s\n", __FUNCTION__);
441 + queue->hw_ptr = queue->head = queue->tail =
442 + queue->start = kmalloc(size * sizeof(struct sk_buff *), GFP_KERNEL);
443 + queue->end = &queue->start[size];
444 + for (pskb = queue->start; pskb < queue->end; pskb++)
447 + queue->status = kmalloc(size * sizeof(myatmdd_rxstatus_e),GFP_KERNEL);
448 + for (i = 0; i < size; i++)
449 + queue->status[i] = TX_EMPTY;
451 + queue->pkt_len = kmalloc(size * sizeof(int),GFP_KERNEL);
452 + for (i = 0; i < size; i++)
453 + queue->pkt_len[i] = 0;
458 +static int myatmdd_release_rxq(myatmdd_rxq_t *queue)
460 + struct sk_buff **pskb;
462 + DEBUG("%s\n", __FUNCTION__);
463 + for (pskb = queue->start; pskb < queue->end; pskb++)
465 + /* Is there an skb here */
467 + continue; /* No, so skip this entry in ring */
469 + /* Yes - free it */
470 + dev_kfree_skb(*pskb);
472 + kfree(queue->start);
473 + kfree(queue->status);
474 + kfree(queue->pkt_len);
479 +static int myatmdd_release_txq(myatmdd_txq_t *queue)
481 + struct sk_buff **pskb;
483 + DEBUG("%s\n", __FUNCTION__);
484 + /* Scan through all TX bd's and cleanup */
485 + for (pskb = queue->start; pskb < queue->end; pskb++)
487 + /* Is this buffer currently unused - i.e. no skb */
489 + continue; /* Yes, so ignore it */
491 + /* If we reach here, we have found a socket buffer that
492 + * exists in the TX ring and is waiting to be released.
494 + printk(KERN_WARNING KLOG_PREAMBLE "discarding unsent tx sk_buff\n");
495 + atomic_inc(&ATM_SKB(*pskb)->vcc->stats->tx_err);
496 + myatmdd_free_tx_skb(*pskb);
498 + kfree(queue->start);
499 + kfree(queue->status);
500 + kfree(queue->pkt_len);
505 +/* returns non-zero for "out of space" */
506 +static int myatmdd_txq_enqueue(myatmdd_txq_t *queue, struct sk_buff *skb)
508 + /* increment head and wrap */
509 + struct sk_buff **newhead = queue->head + 1;
510 + if (newhead == queue->end)
511 + newhead = queue->start;
513 + DEBUG("%s\n", __FUNCTION__);
515 + /* abort if tx ring full */
516 + if (newhead == queue->tail)
519 + /* all is okay if we're here */
520 + *queue->head = skb;
521 + /* Tell hardware there's a buffer to send */
522 + queue->status[queue->head - queue->start] = TX_FULL;
523 + queue->pkt_len[queue->head - queue->start] = skb->len;
524 + queue->head = newhead;
528 +/* returns non-zero for "out of space" */
529 +static int myatmdd_rxq_enqueue(myatmdd_rxq_t *queue, struct sk_buff *skb /* empty buffer */)
531 + /* increment head and wrap */
532 + struct sk_buff **newhead = queue->head + 1;
533 + if (newhead == queue->end)
534 + newhead = queue->start;
536 + DEBUG("%s\n", __FUNCTION__);
538 + /* abort if rx ring full */
539 + if (newhead == queue->tail)
542 + /* all is okay if we're here */
543 + *queue->head = skb;
544 + /* Tell hardware there's a buffer to send */
545 + queue->status[queue->head - queue->start] = RX_FULL;
546 + queue->head = newhead;
550 +static struct sk_buff *myatmdd_txq_dequeue(myatmdd_txq_t *queue)
552 + DEBUG("%s\n", __FUNCTION__);
553 + if (queue->tail != queue->head && queue->status[queue->tail - queue->start] == TX_SENT)
555 + struct sk_buff *skb = *queue->tail;
557 + /* increment tail and wrap */
558 + struct sk_buff **newtail = queue->tail + 1;
559 + if (newtail == queue->end)
560 + newtail = queue->start;
561 + *queue->tail = NULL;
562 + queue->status[queue->tail - queue->start] = TX_EMPTY;
563 + queue->tail = newtail;
569 +/* returns NULL for "no new recvd frames" */
570 +static struct sk_buff *myatmdd_rxq_dequeue(myatmdd_rxq_t *queue, int *pkt_len)
572 + DEBUG("%s\n", __FUNCTION__);
573 + if (queue->tail != queue->head && queue->status[queue->tail - queue->start] == RX_RECVD)
575 + struct sk_buff *skb = *queue->tail;
577 + /* increment tail and wrap */
578 + struct sk_buff **newtail = queue->tail + 1;
579 + if (newtail == queue->end)
580 + newtail = queue->start;
581 + *queue->tail = NULL;
582 + queue->status[queue->tail - queue->start] = RX_EMPTY;
583 + *pkt_len = queue->pkt_len[queue->tail - queue->start];
584 + queue->tail = newtail;
591 +#########################################################
593 +# Functions : Implementations of function ptrs in
594 +# myatmdd_phy_ops. This is the phy driver
595 +# start: myatmdd_phy_start,
596 +# ioctl: myatmdd_phy_ioctl,
597 +# interrupt: myatmdd_phy_int,
599 +# Purpose : See ATM device driver interface v0.1
601 +# Notes : Conforming to Linux ATM device driver i/f
602 +# interface. Draft version 0.1
604 +# Designed to work with multiple devices
605 +##########################################################
608 +# AJZ 10Apr03 Created
609 +##########################################################
611 +static int myatmdd_phy_start(struct atm_dev *dev)
613 + /* Provide ATM driver with a pointer via which it
614 + * may invoke PHY driver's IOCTL or interrupt
617 + dev->phy = &myatmdd_phy_ops;
619 + /* If required allocate phy private data and save
620 + * pointer in dev->phy_data;
623 + /* TODO Initialise PHY hardware... */
628 +/* Should be called by SAR driver when it needs to handle an interrupt
629 + * triggered by PHY.
631 +static void myatmdd_phy_int(struct atm_dev *dev)
633 + /* Handle interrupt triggered by PHY */
636 +/* Gets called by SAR driver IOCTL handler for IOCTLS it doesn't recognise */
637 +static int myatmdd_phy_ioctl(struct atm_dev *dev,unsigned int cmd,void *arg)
641 +// case SONET_GETSTATZ:
648 +#########################################################
650 +# Function : myatmdd_free_tx_skb
652 +# Purpose : frees an sk_buff.
654 +# Args : skb=pointer to socket buffer
656 +# Notes : Tries to use the upper layer pop() function
657 +# but uses dev_kfree_skb() if this doesn't exist
658 +##########################################################
661 +# AJZ 10Apr03 Created
662 +##########################################################
664 +static void myatmdd_free_tx_skb(struct sk_buff *skb)
666 + struct atm_vcc *vcc;
668 + DEBUG("%s\n", __FUNCTION__);
670 + /* See if we can use the VCC pop function */
671 + if (((vcc = ATM_SKB(skb)->vcc) != NULL) && (vcc->pop != NULL))
673 + /* Yes, so use ATM socket layer pop function */
674 + vcc->pop(vcc, skb);
678 + printk(KERN_WARNING KLOG_PREAMBLE "unable to call skb free function\n");
679 + /* No, so free socket buffer */
680 + dev_kfree_skb(skb);
685 +#########################################################
687 +# Functions : Implementations of function ptrs in
692 +# myatmdd_getsockopt(),
693 +# myatmdd_setsockopt(),
695 +# myatmdd_sg_send(),
696 +# myatmdd_change_qos(),
697 +# myatmdd_proc_read()
700 +# Purpose : See ATM device driver interface v0.1
702 +# Notes : Conforming to Linux ATM device driver i/f
703 +# interface. Draft version 0.1
705 +# Designed to work with multiple devices
706 +##########################################################
709 +# AJZ 10Apr03 Created
710 +##########################################################
712 +static int myatmdd_open(struct atm_vcc *vcc)
714 + myatmdd_vccdata_t *priv;
717 + DEBUG("%s\n", __FUNCTION__);
719 + /* Make sure we are opening a AAL0 or AAL5 connection */
720 + if ((vcc->qos.aal != ATM_AAL5) && (vcc->qos.aal != ATM_AAL0))
722 + printk(KERN_WARNING KLOG_PREAMBLE "invalid AAL\n");
726 + /* Address is in use */
727 + set_bit(ATM_VF_ADDR, &vcc->flags);
729 + /* Allocate some vcc-private memory */
730 + vcc->dev_data = kmalloc(sizeof(myatmdd_vccdata_t), GFP_KERNEL);
731 + if (vcc->dev_data == NULL)
733 + priv = vcc->dev_data;
735 + /* Setup the hardware for new VC... */
737 + /* Do not allow half open VCs - otherwise the example driver will not be able
738 + * to loop back frames sent !
740 + if (vcc->qos.rxtp.traffic_class == ATM_NONE || vcc->qos.txtp.traffic_class == ATM_NONE)
742 + kfree(vcc->dev_data);
746 + /* Create rx/tx queues for this VC */
747 + myatmdd_init_txq(&priv->txqueue, TXQ_SZ);
748 + myatmdd_init_rxq(&priv->rxqueue, RXQ_SZ);
750 + /* Fill rx queue with empty skbuffs */
751 + for (i = 0 ; i < RXQ_SZ - 1; i++)
753 + struct sk_buff *skb = dev_alloc_skb(AAL5_BUFLEN);
754 + myatmdd_rxq_enqueue(&priv->rxqueue,skb);
757 + /* Connection is now ready to receive data */
758 + set_bit(ATM_VF_READY, &vcc->flags);
763 +static void myatmdd_close(struct atm_vcc *vcc)
765 + myatmdd_vccdata_t *priv = vcc->dev_data;
767 + DEBUG("%s\n", __FUNCTION__);
769 + /* Indicate channel closed */
770 + clear_bit(ATM_VF_READY, &vcc->flags);
772 + /* TODO Uninitialise the hardware for this VC... */
774 + /* empty the rx and tx queues */
775 + myatmdd_release_txq(&priv->txqueue);
776 + myatmdd_release_rxq(&priv->rxqueue);
778 + /* Free the vcc-private memory */
779 + kfree(vcc->dev_data);
782 +static int myatmdd_ioctl(struct atm_dev *dev, unsigned int cmd,void *arg)
784 + /* myatmdd does not currently have an ioctl interface so pass ioctl onto PHY */
785 + if (dev->phy && dev->phy->ioctl) {
786 + return dev->phy->ioctl(dev, cmd, arg);
791 +static int myatmdd_getsockopt(struct atm_vcc *vcc,int level,int optname, void __user *optval,int optlen)
796 +static int myatmdd_setsockopt(struct atm_vcc *vcc,int level,int optname, void __user *optval,unsigned int optlen)
801 +/* Note may be called in either process or interrupt context! */
802 +static int myatmdd_send(struct atm_vcc *vcc,struct sk_buff *skb)
804 + myatmdd_vccdata_t *priv = vcc->dev_data;
806 + DEBUG("%s\n", __FUNCTION__);
808 + /* Assign VCC to socket buffer
809 + * Note: this must be done before attempting to call
810 + * myatmdd_free_tx_skb() as this may use ATM_SKB(skb)->vcc->pop()
812 + ATM_SKB(skb)->vcc = vcc;
814 + /* Setup hardware to send and arrange callback of myatmdd_send_complete... */
816 + /* In this example ATM device driver all VCs are looped back.
817 + * So copy to the rxq and emulate an rx interrupt
820 + /* Can we accept another skb to send ? */
821 + if (myatmdd_txq_enqueue(&priv->txqueue, skb))
823 + /* No - free socket buffer */
824 + myatmdd_free_tx_skb(skb);
826 + /* Update tx channel stats */
827 + atomic_inc(&vcc->stats->tx_err);
829 + /* Tell protocol layer to back off */
833 + /* This is the bit which copies the tx ring to the rx ring,
834 + * and triggers emulated rx and tx interrupts
836 + myatmdd_emulate_loopback_hardware(vcc);
841 +static int myatmdd_change_qos(struct atm_vcc *vcc,struct atm_qos *qos,int flgs)
846 +static int myatmdd_proc_read(struct atm_dev *dev,loff_t *pos,char *page)
848 + int left = (int) *pos;
851 + return sprintf(page, "1st line of stats\n");
853 + return sprintf(page, "2nd line of stats\n");
855 + return sprintf(page, "3rd line of stats\n");
861 +#########################################################
863 +# Function : myatmdd_init
865 +# Purpose : init the module, init and register the ATM device
869 +# Returns : return code
873 +##########################################################
876 +# AJZ 10Apr03 Created
877 +##########################################################
879 +int __init myatmdd_init(void)
881 + myatmdd_devdata_t *priv = kmalloc(sizeof(myatmdd_devdata_t),GFP_KERNEL);
886 + /* Register the new device */
887 + myatmdd_dev = atm_dev_register(MYATMDD,NULL,&myatmdd_ops,-1,NULL);
889 + /* Were we able to register this device? */
890 + if (myatmdd_dev == NULL)
892 + printk(KERN_ERR KLOG_PREAMBLE "failed to register CPM ATM device\n");
896 + /* Save pointer to device private data */
897 + myatmdd_dev->dev_data = priv;
899 + /* Initialise device parameters */
900 + myatmdd_dev->ci_range.vpi_bits = MYATMDD_VPI_BITS;
901 + myatmdd_dev->ci_range.vci_bits = MYATMDD_VCI_BITS;
902 + myatmdd_dev->link_rate = MYATMDD_PCR;
904 + /* Set up phy device */
905 + myatmdd_phy_start(myatmdd_dev);
907 + /* TODO Initialise SAR hardware... */
909 + /* Console output */
910 + printk(KERN_INFO KLOG_PREAMBLE "Initialised\n");
916 + * module_init() is called by insmod, if built as module,
917 + * or by do_initcalls(), if built as a resident driver.
919 +module_init(myatmdd_init);
922 +#########################################################
924 +# Function : myatmdd_exit
926 +# Purpose : delete module, uninit and dereg ATM device
934 +##########################################################
937 +# AJZ 10Apr03 Created
938 +##########################################################
942 +static void __exit myatmdd_exit(void)
944 + /* Disable SAR hardware... */
946 + /* Console output */
947 + printk(KERN_ERR KLOG_PREAMBLE "Uninitialised\n");
948 + kfree(myatmdd_dev->dev_data);
949 + atm_dev_deregister(myatmdd_dev);
951 +module_exit(myatmdd_exit);