Debian Codegraph @

drivers/dahdi/dahdi_dynamic_ethmf.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 * Dynamic Span Interface for DAHDI (Multi-Span Ethernet Interface)
3 *
4 * Written by Joseph Benden <[email protected]>
5 *
6 * Copyright (C) 2007-2010, Thralling Penguin LLC.
7 *
8 * All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 */
25
26 #include <linux/kernel.h>
27 #include <linux/errno.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/spinlock.h>
31 #include <linux/slab.h>
32 #include <linux/kmod.h>
33 #include <linux/sched.h>
34 #include <linux/interrupt.h>
35 #include <linux/moduleparam.h>
36 #include <linux/netdevice.h>
37 #include <linux/notifier.h>
38 #include <linux/crc32.h>
39 #include <linux/seq_file.h>
40
41 /**
42 * Undefine USE_PROC_FS, if you do not want the /proc/dahdi/dynamic-ethmf
43 * support. Undefining this would give a slight performance increase.
44 */
45 #define USE_PROC_FS
46
47 #ifdef USE_PROC_FS
48 # include <linux/proc_fs.h>
49 # include <asm/atomic.h>
50 #endif
51
52 #ifdef CONFIG_DEVFS_FS
53 # include <linux/devfs_fs_kernel.h>
54 #endif
55
56 #include <dahdi/kernel.h>
57 #include <dahdi/user.h>
58
59 #define ETH_P_ZTDETH 0xd00d
60 #define ETHMF_MAX_PER_SPAN_GROUP 8
61 #define ETHMF_MAX_GROUPS 16
62 #define ETHMF_FLAG_IGNORE_CHAN0 (1 << 3)
63 #define ETHMF_MAX_SPANS 4
64
65 struct ztdeth_header {
66 unsigned short subaddr;
67 };
68
69 /* Timer for enabling spans - used to combat a lock problem */
70 static struct timer_list timer;
71
72 /* Whether or not the timer has been deleted */
73 static atomic_t timer_deleted = ATOMIC_INIT(0);
74
75 /* Global error counter */
76 static atomic_t errcount = ATOMIC_INIT(0);
77
78 /* Whether or not we are in shutdown */
79 static atomic_t shutdown = ATOMIC_INIT(0);
80
81 static struct sk_buff_head skbs;
82
83 #ifdef USE_PROC_FS
84 struct ethmf_group {
85 unsigned int hash_addr;
86 atomic_t spans;
87 atomic_t rxframecount;
88 atomic_t txframecount;
89 atomic_t rxbytecount;
90 atomic_t txbytecount;
91 atomic_t devupcount;
92 atomic_t devdowncount;
93 };
94 static struct ethmf_group ethmf_groups[ETHMF_MAX_GROUPS];
95 #endif
96
97 struct ztdeth {
98 /* Destination MAC address */
99 unsigned char addr[ETH_ALEN];
100 /* Destination MAC address hash value */
101 unsigned int addr_hash;
102 /* span sub-address, in network byte order */
103 unsigned short subaddr;
104 /* DAHDI span associated with this TDMoE-mf span */
105 struct dahdi_span *span;
106 /* Ethernet interface name */
107 char ethdev[IFNAMSIZ];
108 /* Ethernet device reference */
109 struct net_device *dev;
110 /* trx buffer */
111 unsigned char *msgbuf;
112 /* trx buffer length */
113 int msgbuf_len;
114 /* wether or not this frame is ready for trx */
115 atomic_t ready;
116 /* delay counter, to ensure all spans are added, prior to usage */
117 atomic_t delay;
118 /* rvc buffer */
119 unsigned char *rcvbuf;
120 /* the number of channels in this span */
121 int real_channels;
122 /* use padding if 1, else no padding */
123 atomic_t no_front_padding;
124 /* counter to pseudo lock the rcvbuf */
125 atomic_t refcnt;
126
127 struct list_head list;
128 };
129
130 /**
131 * Lock for adding and removing items in ethmf_list
132 */
133 static DEFINE_SPINLOCK(ethmf_lock);
134
135 /**
136 * The active list of all running spans
137 */
138 static LIST_HEAD(ethmf_list);
139
140 static inline void ethmf_errors_inc(void)
141 {
142 #ifdef USE_PROC_FS
143 atomic_inc(&errcount);
144 #endif
145 }
146
147 #ifdef USE_PROC_FS
148 static inline int hashaddr_to_index(unsigned int hash_addr)
149 {
150 int i, z = -1;
151 for (i = 0; i < ETHMF_MAX_GROUPS; ++i) {
152 if (z == -1 && ethmf_groups[i].hash_addr == 0)
153 z = i;
154 if (ethmf_groups[i].hash_addr == hash_addr)
155 return i;
156 }
157 if (z != -1) {
158 ethmf_groups[z].hash_addr = hash_addr;
159 }
160 return z;
161 }
162 #endif
163
164 /**
165 * Find the Ztdeth Struct and DAHDI span for a given MAC address and subaddr.
166 *
167 * NOTE: RCU read lock must already be held.
168 */
169 static inline void find_ethmf(const unsigned char *addr,
170 const unsigned short subaddr, struct ztdeth **ze,
171 struct dahdi_span **span)
172 {
173 struct ztdeth *z;
174
175 list_for_each_entry_rcu(z, &ethmf_list, list) {
176 if (!atomic_read(&z->delay)) {
177 if (!memcmp(addr, z->addr, ETH_ALEN)
178 && z->subaddr == subaddr) {
179 *ze = z;
180 *span = z->span;
181 return;
182 }
183 }
184 }
185
186 /* no results */
187 *ze = NULL;
188 *span = NULL;
189 }
190
191 /**
192 * Determines if all spans are ready for transmit. If all spans are ready,
193 * we return the number of spans which indeed are ready and populate the
194 * array of pointers to those spans..
195 *
196 * NOTE: RCU read lock must already be held.
197 */
198 static inline int ethmf_trx_spans_ready(unsigned int addr_hash, struct ztdeth *(*ready_spans)[ETHMF_MAX_PER_SPAN_GROUP])
199 {
200 struct ztdeth *t;
201 int span_count = 0, spans_ready = 0;
202
203 list_for_each_entry_rcu(t, &ethmf_list, list) {
204 if (!atomic_read(&t->delay) && t->addr_hash == addr_hash) {
205 ++span_count;
206 if (atomic_read(&t->ready)) {
207 short subaddr = ntohs(t->subaddr);
208 if (subaddr < ETHMF_MAX_PER_SPAN_GROUP) {
209 (*ready_spans)[subaddr] = t;
210 ++spans_ready;
211 } else {
212 printk(KERN_ERR "More than %d spans per multi-frame group are not currently supported.",
213 ETHMF_MAX_PER_SPAN_GROUP);
214 }
215 }
216 }
217 }
218
219 if (span_count && spans_ready && span_count == spans_ready) {
220 return spans_ready;
221 }
222 return 0;
223 }
224
225 /**
226 * Ethernet receiving side processing function.
227 */
228 static int ztdethmf_rcv(struct sk_buff *skb, struct net_device *dev,
229 struct packet_type *pt, struct net_device *orig_dev)
230 {
231 int num_spans = 0, span_index = 0;
232 unsigned char *data;
233 struct dahdi_span *span;
234 struct ztdeth *z = NULL;
235 struct ztdeth_header *zh;
236 unsigned int samples, channels, rbslen, flags;
237 unsigned int skip = 0;
238
239 zh = (struct ztdeth_header *) skb_network_header(skb);
240 if (ntohs(zh->subaddr) & 0x8000) {
241 /* got a multi-span frame */
242 num_spans = ntohs(zh->subaddr) & 0xFF;
243
244 /* Currently max of 4 spans supported */
245 if (unlikely(num_spans > ETHMF_MAX_SPANS)) {
246 kfree_skb(skb);
247 return 0;
248 }
249
250 skb_pull(skb, sizeof(struct ztdeth_header));
251 #ifdef NEW_SKB_LINEARIZE
252 if (skb_is_nonlinear(skb))
253 skb_linearize(skb);
254 #else
255 if (skb_is_nonlinear(skb))
256 skb_linearize(skb, GFP_KERNEL);
257 #endif
258 data = (unsigned char *) skb->data;
259
260 rcu_read_lock();
261 do {
262 find_ethmf(eth_hdr(skb)->h_source,
263 htons(span_index), &z, &span);
264 if (unlikely(!z || !span)) {
265 /* The recv'd span does not belong to us */
266 /* ethmf_errors_inc(); */
267 ++span_index;
268 continue;
269 }
270
271 samples = data[(span_index * 6)] & 0xFF;
272 flags = data[((span_index * 6) + 1)] & 0xFF;
273 channels = data[((span_index * 6) + 5)] & 0xFF;
274
275 /* Precomputed defaults for most typical values */
276 if (channels == 24)
277 rbslen = 12;
278 else if (channels == 31)
279 rbslen = 16;
280 else
281 rbslen = ((channels + 3) / 4) * 2;
282
283 if (unlikely(samples != 8 || channels >= 32 || channels == 0)) {
284 ethmf_errors_inc();
285 ++span_index;
286 continue;
287 }
288
289 if (atomic_dec_and_test(&z->refcnt) == 0) {
290 memcpy(z->rcvbuf, data + 6*span_index, 6); /* TDM Header */
291 /*
292 * If we ignore channel zero we must skip the first eight bytes and
293 * ensure that ztdynamic doesn't get confused by this new flag
294 */
295 if (flags & ETHMF_FLAG_IGNORE_CHAN0) {
296 skip = 8;
297
298 /* Remove this flag since ztdynamic may not understand it */
299 z->rcvbuf[1] = flags & ~(ETHMF_FLAG_IGNORE_CHAN0);
300
301 /* Additionally, now we will transmit with front padding */
302 atomic_set(&z->no_front_padding, 0);
303 } else {
304 /* Disable front padding if we recv'd a packet without it */
305 atomic_set(&z->no_front_padding, 1);
306 }
307 memcpy(z->rcvbuf + 6, data + 6*num_spans + 16
308 *span_index, rbslen); /* RBS Header */
309
310 /* 256 == 32*8; if padding lengths change, this must be modified */
311 memcpy(z->rcvbuf + 6 + rbslen, data + 6*num_spans + 16
312 *num_spans + (256)*span_index + skip, channels
313 * 8); /* Payload */
314
315 dahdi_dynamic_receive(span, z->rcvbuf, 6 + rbslen
316 + channels*8);
317 } else {
318 ethmf_errors_inc();
319 printk(KERN_INFO "TDMoE span overflow detected. Span %d was dropped.", span_index);
320 }
321 atomic_inc(&z->refcnt);
322
323 #ifdef USE_PROC_FS
324 if (span_index == 0) {
325 atomic_inc(&(ethmf_groups[hashaddr_to_index(z->addr_hash)].rxframecount));
326 atomic_add(skb->len + z->dev->hard_header_len +
327 sizeof(struct ztdeth_header),
328 &(ethmf_groups[hashaddr_to_index(z->addr_hash)].rxbytecount));
329 }
330 #endif
331 ++span_index;
332 } while (!atomic_read(&shutdown) && span_index < num_spans);
333 rcu_read_unlock();
334 }
335
336 kfree_skb(skb);
337 return 0;
338 }
339
340 static int ztdethmf_notifier(struct notifier_block *block, unsigned long event,
341 void *ptr)
342 {
343 struct net_device *dev = ptr;
344 struct ztdeth *z;
345
346 switch (event) {
347 case NETDEV_GOING_DOWN:
348 case NETDEV_DOWN:
349 rcu_read_lock();
350 list_for_each_entry_rcu(z, &ethmf_list, list) {
351 /* Note that the device no longer exists */
352 if (z->dev == dev) {
353 z->dev = NULL;
354 #ifdef USE_PROC_FS
355 atomic_inc(&(ethmf_groups[hashaddr_to_index(z->addr_hash)].devdowncount));
356 #endif
357 }
358 }
359 rcu_read_unlock();
360 break;
361 case NETDEV_UP:
362 rcu_read_lock();
363 list_for_each_entry_rcu(z, &ethmf_list, list) {
364 /* Now that the device exists again, use it */
365 if (!strcmp(z->ethdev, dev->name)) {
366 z->dev = dev;
367 #ifdef USE_PROC_FS
368 atomic_inc(&(ethmf_groups[hashaddr_to_index(z->addr_hash)].devupcount));
369 #endif
370 }
371 }
372 rcu_read_unlock();
373 break;
374 }
375 return 0;
376 }
377
378 static void ztdethmf_transmit(struct dahdi_dynamic *dyn, u8 *msg, size_t msglen)
379 {
380 struct ztdeth *z = dyn->pvt, *ready_spans[ETHMF_MAX_PER_SPAN_GROUP];
381 struct sk_buff *skb;
382 struct ztdeth_header *zh;
383 struct net_device *dev;
384 unsigned char addr[ETH_ALEN];
385 int spans_ready = 0, index = 0;
386
387 if (atomic_read(&shutdown))
388 return;
389
390 rcu_read_lock();
391
392 if (unlikely(!z || !z->dev)) {
393 rcu_read_unlock();
394 return;
395 }
396
397 if (!atomic_read(&z->ready)) {
398 if (atomic_inc_return(&z->ready) == 1) {
399 memcpy(z->msgbuf, msg, msglen);
400 z->msgbuf_len = msglen;
401 }
402 }
403
404 spans_ready = ethmf_trx_spans_ready(z->addr_hash, &ready_spans);
405 if (spans_ready) {
406 int pad[ETHMF_MAX_SPANS], rbs[ETHMF_MAX_SPANS];
407
408 dev = z->dev;
409 memcpy(addr, z->addr, sizeof(z->addr));
410
411 for (index = 0; index < spans_ready; index++) {
412 int chan = ready_spans[index]->real_channels;
413 /* By default we pad to 32 channels, but if
414 * no_front_padding is false then we have a pad
415 * in the front of 8 bytes, so this implies one
416 * less channel
417 */
418 if (atomic_read(&(ready_spans[index]->no_front_padding)))
419 pad[index] = (32 - chan)*8;
420 else
421 pad[index] = (31 - chan)*8;
422
423 if (chan == 24)
424 rbs[index] = 12;
425 else if (chan == 31)
426 rbs[index] = 16;
427 else
428 /* Shouldn't this be index, not spans_ready? */
429 rbs[spans_ready] = ((chan + 3) / 4) * 2;
430 }
431
432 /* Allocate the standard size for a 32-chan frame */
433 skb = dev_alloc_skb(1112 + dev->hard_header_len
434 + sizeof(struct ztdeth_header) + 32);
435 if (unlikely(!skb)) {
436 rcu_read_unlock();
437 ethmf_errors_inc();
438 return;
439 }
440
441 /* Reserve header space */
442 skb_reserve(skb, dev->hard_header_len
443 + sizeof(struct ztdeth_header));
444 /* copy each spans header */
445 for (index = 0; index < spans_ready; index++) {
446 if (!atomic_read(&(ready_spans[index]->no_front_padding)))
447 ready_spans[index]->msgbuf[1]
448 |= ETHMF_FLAG_IGNORE_CHAN0;
449
450 memcpy(skb_put(skb, 6), ready_spans[index]->msgbuf, 6);
451 }
452
453 /* copy each spans RBS payload */
454 for (index = 0; index < spans_ready; index++) {
455 memcpy(skb_put(skb, 16), ready_spans[index]->msgbuf + 6,
456 rbs[index]);
457 }
458
459 /* copy each spans data/voice payload */
460 for (index = 0; index < spans_ready; index++) {
461 int chan = ready_spans[index]->real_channels;
462 if (!atomic_read(&(ready_spans[index]->no_front_padding))) {
463 /* This adds an additional (padded) channel to our total */
464 memset(skb_put(skb, 8), 0xA5, 8); /* ETHMF_IGNORE_CHAN0 */
465 }
466 memcpy(skb_put(skb, chan*8), ready_spans[index]->msgbuf
467 + (6 + rbs[index]), chan*8);
468 if (pad[index] > 0) {
469 memset(skb_put(skb, pad[index]), 0xDD, pad[index]);
470 }
471
472 /* mark span as ready for new data/voice */
473 atomic_set(&(ready_spans[index]->ready), 0);
474 }
475
476 /* Throw on header */
477 zh = (struct ztdeth_header *)skb_push(skb,
478 sizeof(struct ztdeth_header));
479 zh->subaddr = htons((unsigned short)(0x8000 | (unsigned char)(spans_ready & 0xFF)));
480
481 /* Setup protocol type */
482 skb->protocol = __constant_htons(ETH_P_ZTDETH);
483 skb_set_network_header(skb, 0);
484 skb->dev = dev;
485 dev_hard_header(skb, dev, ETH_P_ZTDETH, addr, dev->dev_addr, skb->len);
486 /* queue frame for delivery */
487 if (dev) {
488 skb_queue_tail(&skbs, skb);
489 }
490 #ifdef USE_PROC_FS
491 atomic_inc(&(ethmf_groups[hashaddr_to_index(z->addr_hash)].txframecount));
492 atomic_add(skb->len, &(ethmf_groups[hashaddr_to_index(z->addr_hash)].txbytecount));
493 #endif
494 }
495
496 rcu_read_unlock();
497
498 return;
499 }
500
501 static int ztdethmf_flush(void)
502 {
503 struct sk_buff *skb;
504
505 /* Handle all transmissions now */
506 while ((skb = skb_dequeue(&skbs))) {
507 dev_queue_xmit(skb);
508 }
509 return 0;
510 }
511
512 static struct packet_type ztdethmf_ptype = {
513 .type = __constant_htons(ETH_P_ZTDETH), /* Protocol */
514 .dev = NULL, /* Device (NULL = wildcard) */
515 .func = ztdethmf_rcv, /* Receiver */
516 };
517
518 static void ztdethmf_destroy(struct dahdi_dynamic *dyn)
519 {
520 struct ztdeth *z = dyn->pvt;
521 unsigned long flags;
522
523 atomic_set(&shutdown, 1);
524 synchronize_rcu();
525
526 spin_lock_irqsave(&ethmf_lock, flags);
527 list_del_rcu(&z->list);
528 spin_unlock_irqrestore(&ethmf_lock, flags);
529 synchronize_rcu();
530 atomic_dec(&(ethmf_groups[hashaddr_to_index(z->addr_hash)].spans));
531
532 if (z) { /* Successfully removed */
533 printk(KERN_INFO "Removed interface for %s\n",
534 z->span->name);
535 kfree(z->msgbuf);
536 kfree(z);
537 } else {
538 if (z && z->span) {
539 printk(KERN_ERR "Cannot find interface for %s\n",
540 z->span->name);
541 }
542 }
543 }
544
545 static int ztdethmf_create(struct dahdi_dynamic *dyn, const char *addr)
546 {
547 struct ztdeth *z;
548 char src[256];
549 char *src_ptr;
550 int x, bufsize, num_matched;
551 unsigned long flags;
552 struct dahdi_span *const span = &dyn->span;
553
554 BUG_ON(!span);
555 BUG_ON(!addr);
556
557 z = kmalloc(sizeof(struct ztdeth), GFP_KERNEL);
558 if (!z)
559 return -ENOMEM;
560
561 /* Zero it out */
562 memset(z, 0, sizeof(struct ztdeth));
563
564 /* set a delay for xmit/recv to workaround Zaptel problems */
565 atomic_set(&z->delay, 4);
566
567 /* create a msg buffer. MAX OF 31 CHANNELS!!!! */
568 bufsize = 31 * DAHDI_CHUNKSIZE + 31 / 4 + 48;
569 z->msgbuf = kmalloc(bufsize, GFP_KERNEL);
570 z->rcvbuf = kmalloc(bufsize, GFP_KERNEL);
571
572 /* Address should be <dev>/<macaddr>/subaddr */
573 strscpy(src, addr, sizeof(src));
574 /* replace all / with space; otherwise kernel sscanf does not work */
575 src_ptr = src;
576 while (*src_ptr) {
577 if (*src_ptr == '/')
578 *src_ptr = ' ';
579 ++src_ptr;
580 }
581 num_matched = sscanf(src,
582 "%16s %hhx:%hhx:%hhx:%hhx:%hhx:%hhx %hu",
583 z->ethdev, &z->addr[0], &z->addr[1],
584 &z->addr[2], &z->addr[3], &z->addr[4],
585 &z->addr[5], &z->subaddr);
586 if (8 != num_matched) {
587 printk(KERN_ERR "Only matched %d entries in '%s'\n", num_matched, src);
588 printk(KERN_ERR "Invalid TDMoE Multiframe address: %s\n", addr);
589 kfree(z);
590 return -EINVAL;
591 }
592 z->dev = dev_get_by_name(&init_net, z->ethdev);
593 if (!z->dev) {
594 printk(KERN_ERR "TDMoE Multiframe: Invalid device '%s'\n", z->ethdev);
595 kfree(z);
596 return -EINVAL;
597 }
598 z->span = span;
599 z->subaddr = htons(z->subaddr);
600 z->addr_hash = crc32_le(0, z->addr, ETH_ALEN);
601 z->real_channels = span->channels;
602
603 src[0] = '\0';
604 for (x = 0; x < 5; x++)
605 sprintf(src + strlen(src), "%02x:", z->dev->dev_addr[x]);
606 sprintf(src + strlen(src), "%02x", z->dev->dev_addr[5]);
607
608 printk(KERN_INFO "TDMoEmf: Added new interface for %s at %s "
609 "(addr=%s, src=%s, subaddr=%d)\n", span->name, z->dev->name,
610 addr, src, ntohs(z->subaddr));
611
612 atomic_set(&z->ready, 0);
613 atomic_set(&z->refcnt, 0);
614
615 spin_lock_irqsave(&ethmf_lock, flags);
616 list_add_rcu(&z->list, &ethmf_list);
617 spin_unlock_irqrestore(&ethmf_lock, flags);
618 atomic_inc(&(ethmf_groups[hashaddr_to_index(z->addr_hash)].spans));
619
620 /* enable the timer for enabling the spans */
621 mod_timer(&timer, jiffies + HZ);
622 atomic_set(&shutdown, 0);
623 dyn->pvt = z;
624 return 0;
625 }
626
627 static struct dahdi_dynamic_driver ztd_ethmf = {
628 .owner = THIS_MODULE,
629 .name = "ethmf",
630 .desc = "Ethernet",
631 .create = ztdethmf_create,
632 .destroy = ztdethmf_destroy,
633 .transmit = ztdethmf_transmit,
634 .flush = ztdethmf_flush,
635 };
636
637 static struct notifier_block ztdethmf_nblock = {
638 .notifier_call = ztdethmf_notifier,
639 };
640
641 /**
642 * Decrements each delay counter in the ethmf_list and returns the number of
643 * delay counters that are not equal to zero.
644 */
645 static int ethmf_delay_dec(void)
646 {
647 struct ztdeth *z;
648 int count_nonzero = 0;
649
650 rcu_read_lock();
651 list_for_each_entry_rcu(z, &ethmf_list, list) {
652 if (atomic_read(&z->delay)) {
653 atomic_dec(&z->delay);
654 ++count_nonzero;
655 } else
656 atomic_set(&z->delay, 0);
657 }
658 rcu_read_unlock();
659 return count_nonzero;
660 }
661
662 /**
663 * Timer callback function to allow all spans to be added, prior to any of
664 * them being used.
665 */
666 static void timer_callback(TIMER_DATA_TYPE unused)
667 {
668 if (ethmf_delay_dec()) {
669 if (!atomic_read(&timer_deleted))
670 mod_timer(&timer, jiffies + HZ);
671 } else {
672 printk(KERN_INFO "All TDMoE multiframe span groups are active.\n");
673 }
674 }
675
676 #ifdef USE_PROC_FS
677 static struct proc_dir_entry *proc_entry;
678 static const char *ztdethmf_procname = "dahdi/dynamic-ethmf";
679
680 static int ztdethmf_proc_show(struct seq_file *sfile, void *not_used)
681 {
682 struct ztdeth *z = NULL;
683 int i = 0;
684 unsigned int group = 0, c = 0;
685
686 rcu_read_lock();
687
688 seq_printf(sfile, "Errors: %d\n\n", atomic_read(&errcount));
689
690 for (group = 0; group < ETHMF_MAX_GROUPS; ++group) {
691 if (atomic_read(&(ethmf_groups[group].spans))) {
692 seq_printf(sfile, "Group #%d (0x%x)\n", i++,
693 ethmf_groups[group].hash_addr);
694 seq_printf(sfile, "Spans: %d\n",
695 atomic_read(&(ethmf_groups[group].spans)));
696
697 c = 1;
698 list_for_each_entry_rcu(z, &ethmf_list, list) {
699 if (z->addr_hash == ethmf_groups[group].hash_addr) {
700 if (c == 1) {
701 seq_printf(sfile,
702 " Device: %s (MAC: %02x:%02x:%02x:%02x:%02x:%02x)\n",
703 z->ethdev,
704 z->addr[0], z->addr[1], z->addr[2],
705 z->addr[3], z->addr[4], z->addr[5]);
706 }
707 seq_printf(sfile, " Span %d: subaddr=%u ready=%d delay=%d real_channels=%d no_front_padding=%d\n",
708 c++, ntohs(z->subaddr),
709 atomic_read(&z->ready), atomic_read(&z->delay),
710 z->real_channels, atomic_read(&z->no_front_padding));
711 }
712 }
713 seq_printf(sfile, " Device UPs: %u\n",
714 atomic_read(&(ethmf_groups[group].devupcount)));
715 seq_printf(sfile, " Device DOWNs: %u\n",
716 atomic_read(&(ethmf_groups[group].devdowncount)));
717 seq_printf(sfile, " Rx Frames: %u\n",
718 atomic_read(&(ethmf_groups[group].rxframecount)));
719 seq_printf(sfile, " Tx Frames: %u\n",
720 atomic_read(&(ethmf_groups[group].txframecount)));
721 seq_printf(sfile, " Rx Bytes: %u\n",
722 atomic_read(&(ethmf_groups[group].rxbytecount)));
723 seq_printf(sfile, " Tx Bytes: %u\n",
724 atomic_read(&(ethmf_groups[group].txbytecount)));
725 }
726 }
727 rcu_read_unlock();
728 return 0;
729 }
730
731 static int ztdethmf_proc_open(struct inode *inode, struct file *file)
732 {
733 return single_open(file, ztdethmf_proc_show, NULL);
734 }
735
736 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0)
737 static const struct proc_ops ztdethmf_proc_fops = {
738 .proc_open = ztdethmf_proc_open,
739 .proc_read = seq_read,
740 .proc_lseek = seq_lseek,
741 .proc_release = seq_release,
742 };
743 #else
744 static const struct file_operations ztdethmf_proc_fops = {
745 .open = ztdethmf_proc_open,
746 .read = seq_read,
747 .llseek = seq_lseek,
748 .release = seq_release,
749 };
750 #endif
751 #endif
752
753 static int __init ztdethmf_init(void)
754 {
755 timer_setup(&timer, timer_callback, 0);
756 mod_timer(&timer, jiffies + HZ);
757
758 dev_add_pack(&ztdethmf_ptype);
759 register_netdevice_notifier(&ztdethmf_nblock);
760 dahdi_dynamic_register_driver(&ztd_ethmf);
761
762 skb_queue_head_init(&skbs);
763
764 #ifdef USE_PROC_FS
765 proc_entry = proc_create_data(ztdethmf_procname, 0444, NULL,
766 &ztdethmf_proc_fops, NULL);
767 if (!proc_entry) {
768 printk(KERN_ALERT "create_proc_read_entry failed.\n");
769 }
770 #endif
771
772 return 0;
773 }
774
775 static void __exit ztdethmf_exit(void)
776 {
777 atomic_set(&timer_deleted, 1);
•778 timer_delete_sync(&timer);
779
780 dev_remove_pack(&ztdethmf_ptype);
781 unregister_netdevice_notifier(&ztdethmf_nblock);
782 dahdi_dynamic_unregister_driver(&ztd_ethmf);
783
784 #ifdef USE_PROC_FS
785 if (proc_entry)
786 remove_proc_entry(ztdethmf_procname, NULL);
787 #endif
788 }
789
790 MODULE_DESCRIPTION("DAHDI Dynamic TDMoEmf Support");
791 MODULE_AUTHOR("Joseph Benden <[email protected]>");
792 #ifdef MODULE_LICENSE
793 MODULE_LICENSE("GPL");
794 #endif
795
796 module_init(ztdethmf_init);
797 module_exit(ztdethmf_exit);