This source file includes following definitions.
- eql_init
- eql_open
- eql_close
- eql_ioctl
- eql_slave_xmit
- eql_get_stats
- eql_header
- eql_rebuild_header
- eql_enslave
- eql_emancipate
- eql_g_slave_cfg
- eql_s_slave_cfg
- eql_g_master_cfg
- eql_s_master_cfg
- eql_is_slave
- eql_is_master
- eql_new_slave
- eql_delete_slave
- slave_Bps
- slave_bps
- eql_number_slaves
- eql_is_empty
- eql_is_full
- eql_new_slave_queue
- eql_delete_slave_queue
- eql_insert_slave
- eql_remove_slave
- eql_remove_slave_dev
- eql_best_slave_dev
- eql_best_slave
- eql_schedule_slaves
- eql_find_slave_dev
- eql_first_slave
- eql_next_slave
- eql_set_best_slave
- eql_timer
- init_module
- cleanup_module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 static const char *version =
20 "Equalizer1996: $Revision: 1.2 $ $Date: 1996/04/11 17:51:52 $ Simon Janes (simon@ncm.com)\n";
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115 #include <linux/module.h>
116
117 #include <linux/kernel.h>
118 #include <linux/sched.h>
119 #include <linux/types.h>
120 #include <linux/fcntl.h>
121 #include <linux/interrupt.h>
122 #include <linux/ptrace.h>
123 #include <linux/ioport.h>
124 #include <linux/in.h>
125 #include <linux/malloc.h>
126 #include <linux/string.h>
127 #include <asm/system.h>
128 #include <asm/bitops.h>
129 #include <asm/io.h>
130 #include <asm/dma.h>
131 #include <linux/errno.h>
132
133 #include <linux/netdevice.h>
134 #include <linux/if.h>
135 #include <linux/if_arp.h>
136 #include <linux/timer.h>
137
138 #include <linux/if_eql.h>
139
140 #ifndef EQL_DEBUG
141
142
143
144
145
146
147 #define EQL_DEBUG 1
148 #endif
149 static unsigned int eql_debug = EQL_DEBUG;
150
151 int eql_init(struct device *dev);
152 static int eql_open(struct device *dev);
153 static int eql_close(struct device *dev);
154 static int eql_ioctl(struct device *dev, struct ifreq *ifr, int cmd);
155 static int eql_slave_xmit(struct sk_buff *skb, struct device *dev);
156
157 static struct enet_statistics *eql_get_stats(struct device *dev);
158 static int eql_header(struct sk_buff *skb, struct device *dev,
159 unsigned short type, void *daddr, void *saddr,
160 unsigned len);
161 static int eql_rebuild_header(void *buff, struct device *dev,
162 unsigned long raddr, struct sk_buff *skb);
163
164
165
166 static int eql_enslave(struct device *dev, slaving_request_t *srq);
167 static int eql_emancipate(struct device *dev, slaving_request_t *srq);
168
169 static int eql_g_slave_cfg(struct device *dev, slave_config_t *sc);
170 static int eql_s_slave_cfg(struct device *dev, slave_config_t *sc);
171
172 static int eql_g_master_cfg(struct device *dev, master_config_t *mc);
173 static int eql_s_master_cfg(struct device *dev, master_config_t *mc);
174
175 static inline int eql_is_slave(struct device *dev);
176 static inline int eql_is_master(struct device *dev);
177
178 static slave_t *eql_new_slave(void);
179 static void eql_delete_slave(slave_t *slave);
180
181
182 static inline int eql_number_slaves(slave_queue_t *queue);
183
184 static inline int eql_is_empty(slave_queue_t *queue);
185 static inline int eql_is_full(slave_queue_t *queue);
186
187 static slave_queue_t *eql_new_slave_queue(struct device *dev);
188 static void eql_delete_slave_queue(slave_queue_t *queue);
189
190 static int eql_insert_slave(slave_queue_t *queue, slave_t *slave);
191 static slave_t *eql_remove_slave(slave_queue_t *queue, slave_t *slave);
192
193
194 static int eql_remove_slave_dev(slave_queue_t *queue, struct device *dev);
195
196 static inline struct device *eql_best_slave_dev(slave_queue_t *queue);
197 static inline slave_t *eql_best_slave(slave_queue_t *queue);
198 static inline slave_t *eql_first_slave(slave_queue_t *queue);
199 static inline slave_t *eql_next_slave(slave_queue_t *queue, slave_t *slave);
200
201 static inline void eql_set_best_slave(slave_queue_t *queue, slave_t *slave);
202 static inline void eql_schedule_slaves(slave_queue_t *queue);
203
204 static slave_t *eql_find_slave_dev(slave_queue_t *queue, struct device *dev);
205
206
207
208
209 static void eql_timer(unsigned long param);
210
211
212
213
214
215 int eql_init(struct device *dev)
216 {
217 static unsigned version_printed = 0;
218
219 equalizer_t *eql = 0;
220 int i;
221
222 if ( version_printed++ == 0 && eql_debug > 0)
223 printk(version);
224
225
226
227 dev->priv = kmalloc (sizeof (equalizer_t), GFP_KERNEL);
228 if (dev->priv == NULL)
229 return -ENOMEM;
230 memset (dev->priv, 0, sizeof (equalizer_t));
231 eql = (equalizer_t *) dev->priv;
232
233 eql->stats = kmalloc (sizeof (struct enet_statistics), GFP_KERNEL);
234 if (eql->stats == NULL)
235 {
236 kfree(dev->priv);
237 dev->priv = NULL;
238 return -ENOMEM;
239 }
240 memset (eql->stats, 0, sizeof (struct enet_statistics));
241
242 init_timer (&eql->timer);
243 eql->timer.data = (unsigned long) dev->priv;
244 eql->timer.expires = jiffies+EQL_DEFAULT_RESCHED_IVAL;
245 eql->timer.function = &eql_timer;
246 eql->timer_on = 0;
247
248 dev->open = eql_open;
249 dev->stop = eql_close;
250 dev->do_ioctl = eql_ioctl;
251 dev->hard_start_xmit = eql_slave_xmit;
252 dev->get_stats = eql_get_stats;
253
254
255
256
257
258
259
260 for (i = 0; i < DEV_NUMBUFFS; i++)
261 skb_queue_head_init(&dev->buffs[i]);
262
263 dev->hard_header = eql_header;
264 dev->rebuild_header = eql_rebuild_header;
265
266
267
268
269
270
271 dev->mtu = EQL_DEFAULT_MTU;
272 dev->flags = IFF_MASTER;
273
274 dev->family = AF_INET;
275 dev->pa_addr = 0;
276 dev->pa_brdaddr = 0;
277 dev->pa_mask = 0;
278 dev->pa_alen = 4;
279
280 dev->type = ARPHRD_SLIP;
281 dev->tx_queue_len = 5;
282
283 return 0;
284 }
285
286 static int eql_open(struct device *dev)
287 {
288 equalizer_t *eql = (equalizer_t *) dev->priv;
289 slave_queue_t *new_queue;
290
291 #ifdef EQL_DEBUG
292 if (eql_debug >= 5)
293 printk ("%s: open\n", dev->name);
294 #endif
295
296 printk ("%s: remember to turn off Van-Jacobson compression on your slave devices.\n", dev->name);
297
298 new_queue = eql_new_slave_queue (dev);
299
300 if (new_queue != 0)
301 {
302 new_queue->master_dev = dev;
303 eql->queue = new_queue;
304 eql->queue->lock = 0;
305 eql->min_slaves = 1;
306 eql->max_slaves = EQL_DEFAULT_MAX_SLAVES;
307
308 printk ("%s: adding timer\n", dev->name);
309 eql->timer_on = 1;
310 add_timer (&eql->timer);
311
312 MOD_INC_USE_COUNT;
313 return 0;
314 }
315 return 1;
316 }
317
318
319 static int eql_close(struct device *dev)
320 {
321 equalizer_t *eql = (equalizer_t *) dev->priv;
322
323 #ifdef EQL_DEBUG
324 if ( eql_debug >= 5)
325 printk ("%s: close\n", dev->name);
326 #endif
327
328
329
330
331
332 #ifdef EQL_DEBUG
333 printk ("%s: stopping timer\n", dev->name);
334 #endif
335 eql->timer_on = 0;
336 del_timer (&eql->timer);
337
338 eql_delete_slave_queue (eql->queue);
339
340 MOD_DEC_USE_COUNT;
341 return 0;
342 }
343
344
345 static int eql_ioctl(struct device *dev, struct ifreq *ifr, int cmd)
346 {
347 if(!suser() && cmd!=EQL_GETMASTRCFG && cmd!=EQL_GETSLAVECFG)
348 return -EPERM;
349 switch (cmd)
350 {
351 case EQL_ENSLAVE:
352 return eql_enslave (dev, (slaving_request_t *) ifr->ifr_data);
353 case EQL_EMANCIPATE:
354 return eql_emancipate (dev, (slaving_request_t *) ifr->ifr_data);
355 case EQL_GETSLAVECFG:
356 return eql_g_slave_cfg (dev, (slave_config_t *) ifr->ifr_data);
357 case EQL_SETSLAVECFG:
358 return eql_s_slave_cfg (dev, (slave_config_t *) ifr->ifr_data);
359 case EQL_GETMASTRCFG:
360 return eql_g_master_cfg (dev, (master_config_t *) ifr->ifr_data);
361 case EQL_SETMASTRCFG:
362 return eql_s_master_cfg (dev, (master_config_t *) ifr->ifr_data);
363 default:
364 return -EOPNOTSUPP;
365 }
366 }
367
368
369 static int eql_slave_xmit(struct sk_buff *skb, struct device *dev)
370 {
371 equalizer_t *eql = (equalizer_t *) dev->priv;
372 struct device *slave_dev = 0;
373 slave_t *slave;
374
375 if (skb == NULL)
376 return 0;
377
378 eql_schedule_slaves (eql->queue);
379
380 slave_dev = eql_best_slave_dev (eql->queue);
381 slave = eql_best_slave (eql->queue);
382
383 if ( slave_dev != 0 )
384 {
385 #ifdef EQL_DEBUG
386 if (eql_debug >= 100)
387 printk ("%s: %d slaves xmitng %ld B %s\n",
388 dev->name, eql_number_slaves (eql->queue), skb->len,
389 slave_dev->name);
390 #endif
391 dev_queue_xmit (skb, slave_dev, 1);
392 eql->stats->tx_packets++;
393 slave->bytes_queued += skb->len;
394 }
395 else
396 {
397
398
399
400
401
402 eql->stats->tx_dropped++;
403 dev_kfree_skb(skb, FREE_WRITE);
404 }
405 return 0;
406 }
407
408
409 static struct enet_statistics * eql_get_stats(struct device *dev)
410 {
411 equalizer_t *eql = (equalizer_t *) dev->priv;
412 return eql->stats;
413 }
414
415
416 static int eql_header(struct sk_buff *skb, struct device *dev,
417 unsigned short type, void *daddr, void *saddr,
418 unsigned len)
419 {
420 return 0;
421 }
422
423
424 static int eql_rebuild_header(void *buff, struct device *dev,
425 unsigned long raddr, struct sk_buff *skb)
426 {
427 return 0;
428 }
429
430
431
432
433
434 static int eql_enslave(struct device *dev, slaving_request_t *srqp)
435 {
436 struct device *master_dev;
437 struct device *slave_dev;
438 slaving_request_t srq;
439 int err;
440
441 err = verify_area(VERIFY_READ, (void *)srqp, sizeof (slaving_request_t));
442 if (err)
443 {
444 #ifdef EQL_DEBUG
445 if (eql_debug >= 20)
446 printk ("EQL enslave: error detected by verify_area\n");
447 #endif
448 return err;
449 }
450 memcpy_fromfs (&srq, srqp, sizeof (slaving_request_t));
451
452 #ifdef EQL_DEBUG
453 if (eql_debug >= 20)
454 printk ("%s: enslave '%s' %ld bps\n", dev->name,
455 srq.slave_name, srq.priority);
456 #endif
457 master_dev = dev;
458 slave_dev = dev_get (srq.slave_name);
459
460 if (master_dev != 0 && slave_dev != 0)
461 {
462 if (! eql_is_master (slave_dev) &&
463 ! eql_is_slave (slave_dev) )
464 {
465 slave_t *s = eql_new_slave ();
466 equalizer_t *eql = (equalizer_t *) master_dev->priv;
467 s->dev = slave_dev;
468 s->priority = srq.priority;
469 s->priority_bps = srq.priority;
470 s->priority_Bps = srq.priority / 8;
471 slave_dev->flags |= IFF_SLAVE;
472 eql_insert_slave (eql->queue, s);
473 return 0;
474 }
475 #ifdef EQL_DEBUG
476 if (eql_debug >= 20)
477 printk ("EQL enslave: slave is master or slave is already slave\n");
478 #endif
479
480 return -EINVAL;
481 }
482 #ifdef EQL_DEBUG
483 if (eql_debug >= 20)
484 printk ("EQL enslave: master or slave are NULL");
485 #endif
486 return -EINVAL;
487 }
488
489 static int eql_emancipate(struct device *dev, slaving_request_t *srqp)
490 {
491 struct device *master_dev;
492 struct device *slave_dev;
493 slaving_request_t srq;
494 int err;
495
496 err = verify_area(VERIFY_READ, (void *)srqp, sizeof (slaving_request_t));
497 if (err)
498 return err;
499
500 memcpy_fromfs (&srq, srqp, sizeof (slaving_request_t));
501 #ifdef EQL_DEBUG
502 if (eql_debug >= 20)
503 printk ("%s: emancipate `%s`\n", dev->name, srq.slave_name);
504 #endif
505 master_dev = dev;
506 slave_dev = dev_get (srq.slave_name);
507
508 if ( eql_is_slave (slave_dev) )
509 {
510 equalizer_t *eql = (equalizer_t *) master_dev->priv;
511 slave_dev->flags = slave_dev->flags & ~IFF_SLAVE;
512 eql_remove_slave_dev (eql->queue, slave_dev);
513 return 0;
514 }
515 return -EINVAL;
516 }
517
518
519 static int eql_g_slave_cfg(struct device *dev, slave_config_t *scp)
520 {
521 slave_t *slave;
522 equalizer_t *eql;
523 struct device *slave_dev;
524 slave_config_t sc;
525 int err;
526
527 err = verify_area(VERIFY_READ, (void *)scp, sizeof (slave_config_t));
528 if (err)
529 return err;
530
531 memcpy_fromfs (&sc, scp, sizeof (slave_config_t));
532 #ifdef EQL_DEBUG
533 if (eql_debug >= 20)
534 printk ("%s: get config for slave `%s'\n", dev->name, sc.slave_name);
535 #endif
536 eql = (equalizer_t *) dev->priv;
537 slave_dev = dev_get (sc.slave_name);
538
539 if ( eql_is_slave (slave_dev) )
540 {
541 slave = eql_find_slave_dev (eql->queue, slave_dev);
542 if (slave != 0)
543 {
544 sc.priority = slave->priority;
545 err = verify_area(VERIFY_WRITE, (void *)scp, sizeof (slave_config_t));
546 if (err)
547 return err;
548 memcpy_tofs (scp, &sc, sizeof (slave_config_t));
549 return 0;
550 }
551 }
552 return -EINVAL;
553 }
554
555
556 static int eql_s_slave_cfg(struct device *dev, slave_config_t *scp)
557 {
558 slave_t *slave;
559 equalizer_t *eql;
560 struct device *slave_dev;
561 slave_config_t sc;
562 int err;
563
564 err = verify_area(VERIFY_READ, (void *)scp, sizeof (slave_config_t));
565 if (err)
566 return err;
567
568 #ifdef EQL_DEBUG
569 if (eql_debug >= 20)
570 printk ("%s: set config for slave `%s'\n", dev->name, sc.slave_name);
571 #endif
572
573 memcpy_fromfs (&sc, scp, sizeof (slave_config_t));
574
575 eql = (equalizer_t *) dev->priv;
576 slave_dev = dev_get (sc.slave_name);
577
578 if ( eql_is_slave (slave_dev) )
579 {
580 slave = eql_find_slave_dev (eql->queue, slave_dev);
581 if (slave != 0)
582 {
583 slave->priority = sc.priority;
584 slave->priority_bps = sc.priority;
585 slave->priority_Bps = sc.priority / 8;
586 return 0;
587 }
588 }
589 return -EINVAL;
590 }
591
592
593 static int eql_g_master_cfg(struct device *dev, master_config_t *mcp)
594 {
595 equalizer_t *eql;
596 master_config_t mc;
597
598 #if EQL_DEBUG
599 if (eql_debug >= 20)
600 printk ("%s: get master config\n", dev->name);
601 #endif
602
603 if ( eql_is_master (dev) )
604 {
605 int err;
606 err = verify_area(VERIFY_WRITE, (void *)mcp, sizeof (master_config_t));
607 if (err)
608 return err;
609 eql = (equalizer_t *) dev->priv;
610 mc.max_slaves = eql->max_slaves;
611 mc.min_slaves = eql->min_slaves;
612 memcpy_tofs (mcp, &mc, sizeof (master_config_t));
613 return 0;
614 }
615 return -EINVAL;
616 }
617
618
619 static int eql_s_master_cfg(struct device *dev, master_config_t *mcp)
620 {
621 equalizer_t *eql;
622 master_config_t mc;
623 int err;
624
625 err = verify_area(VERIFY_READ, (void *)mcp, sizeof (master_config_t));
626 if (err)
627 return err;
628 #if EQL_DEBUG
629 if (eql_debug >= 20)
630 printk ("%s: set master config\n", dev->name);
631 #endif
632 memcpy_fromfs (&mc, mcp, sizeof (master_config_t));
633 if ( eql_is_master (dev) )
634 {
635 eql = (equalizer_t *) dev->priv;
636 eql->max_slaves = mc.max_slaves;
637 eql->min_slaves = mc.min_slaves;
638 return 0;
639 }
640 return -EINVAL;
641 }
642
643
644
645
646
647 static inline int eql_is_slave(struct device *dev)
648 {
649 if (dev)
650 {
651 if ((dev->flags & IFF_SLAVE) == IFF_SLAVE)
652 return 1;
653 }
654 return 0;
655 }
656
657
658 static inline int eql_is_master(struct device *dev)
659 {
660 if (dev)
661 {
662 if ((dev->flags & IFF_MASTER) == IFF_MASTER)
663 return 1;
664 }
665 return 0;
666 }
667
668
669 static slave_t *eql_new_slave(void)
670 {
671 slave_t *slave;
672
673 slave = (slave_t *) kmalloc (sizeof (slave_t), GFP_KERNEL);
674 if (slave)
675 {
676 memset(slave, 0, sizeof (slave_t));
677 return slave;
678 }
679 return 0;
680 }
681
682
683 static void eql_delete_slave(slave_t *slave)
684 {
685 kfree (slave);
686 }
687
688
689 #if 0
690
691 static long slave_Bps(slave_t *slave)
692 {
693 return (slave->priority_Bps);
694 }
695
696 static long slave_bps(slave_t *slave)
697 {
698 return (slave->priority_bps);
699 }
700
701 #endif
702
703 static inline int eql_number_slaves(slave_queue_t *queue)
704 {
705 return queue->num_slaves;
706 }
707
708 static inline int eql_is_empty(slave_queue_t *queue)
709 {
710 if (eql_number_slaves (queue) == 0)
711 return 1;
712 return 0;
713 }
714
715 static inline int eql_is_full(slave_queue_t *queue)
716 {
717 equalizer_t *eql = (equalizer_t *) queue->master_dev->priv;
718
719 if (eql_number_slaves (queue) == eql->max_slaves)
720 return 1;
721 return 0;
722 }
723
724 static slave_queue_t *eql_new_slave_queue(struct device *dev)
725 {
726 slave_queue_t *queue;
727 slave_t *head_slave;
728 slave_t *tail_slave;
729
730 queue = (slave_queue_t *) kmalloc (sizeof (slave_queue_t), GFP_KERNEL);
731 if (queue == NULL)
732 return 0;
733 memset (queue, 0, sizeof (slave_queue_t));
734 head_slave = eql_new_slave ();
735 tail_slave = eql_new_slave ();
736
737 if ( head_slave != 0 &&
738 tail_slave != 0 )
739 {
740 head_slave->next = tail_slave;
741 tail_slave->next = 0;
742 queue->head = head_slave;
743 queue->num_slaves = 0;
744 queue->master_dev = dev;
745 }
746 else
747 {
748 if (head_slave)
749 kfree(head_slave);
750 if (tail_slave)
751 kfree(tail_slave);
752 kfree (queue);
753 return 0;
754 }
755 return queue;
756 }
757
758
759 static void eql_delete_slave_queue(slave_queue_t *queue)
760 {
761 slave_t *zapped;
762
763
764
765
766
767
768 while ( ! eql_is_empty (queue) )
769 {
770 zapped = eql_remove_slave (queue, queue->head->next);
771 eql_delete_slave (zapped);
772 }
773 kfree (queue->head->next);
774 kfree (queue->head);
775 kfree (queue);
776 }
777
778 static int eql_insert_slave(slave_queue_t *queue, slave_t *slave)
779 {
780 cli ();
781
782 if ( ! eql_is_full (queue) )
783 {
784 slave_t *duplicate_slave = 0;
785 duplicate_slave = eql_find_slave_dev (queue, slave->dev);
786 if (duplicate_slave != 0)
787 {
788
789
790 eql_delete_slave (eql_remove_slave (queue, duplicate_slave));
791 }
792 slave->next = queue->head->next;
793 queue->head->next = slave;
794 queue->num_slaves++;
795 sti ();
796 return 0;
797 }
798 sti ();
799 return 1;
800 }
801
802
803 static slave_t *eql_remove_slave(slave_queue_t *queue, slave_t *slave)
804 {
805 slave_t *prev;
806 slave_t *curr;
807
808 cli ();
809
810 prev = queue->head;
811 curr = queue->head->next;
812 while (curr != slave &&
813 curr->dev != 0 )
814 {
815
816 prev = curr;
817 curr = curr->next;
818 }
819
820 if (curr == slave)
821 {
822 prev->next = curr->next;
823 queue->num_slaves--;
824 curr->dev->flags = curr->dev->flags & ~IFF_SLAVE;
825 sti();
826 return curr;
827 }
828 sti ();
829 return 0;
830 }
831
832
833 static int eql_remove_slave_dev(slave_queue_t *queue, struct device *dev)
834 {
835 slave_t *prev;
836 slave_t *curr;
837 slave_t *target;
838
839 target = eql_find_slave_dev (queue, dev);
840
841 if (target != 0)
842 {
843 cli ();
844 prev = queue->head;
845 curr = prev->next;
846 while (curr != target)
847 {
848 prev = curr;
849 curr = curr->next;
850 }
851 prev->next = curr->next;
852 queue->num_slaves--;
853 sti ();
854 eql_delete_slave (curr);
855 return 0;
856 }
857 return 1;
858 }
859
860
861 static inline struct device *eql_best_slave_dev(slave_queue_t *queue)
862 {
863 if (queue->best_slave != 0)
864 {
865 if (queue->best_slave->dev != 0)
866 return queue->best_slave->dev;
867 else
868 return 0;
869 }
870 else
871 return 0;
872 }
873
874
875 static inline slave_t *eql_best_slave(slave_queue_t *queue)
876 {
877 return queue->best_slave;
878 }
879
880 static inline void eql_schedule_slaves(slave_queue_t *queue)
881 {
882 struct device *master_dev = queue->master_dev;
883 slave_t *best_slave = 0;
884 slave_t *slave_corpse = 0;
885
886 #ifdef EQL_DEBUG
887 if (eql_debug >= 100)
888 printk ("%s: schedule %d slaves\n",
889 master_dev->name, eql_number_slaves (queue));
890 #endif
891 if ( eql_is_empty (queue) )
892 {
893
894
895
896 eql_set_best_slave (queue, (slave_t *) 0);
897 return;
898 }
899 else
900 {
901
902
903
904 unsigned long best_load = (unsigned long) ULONG_MAX;
905 slave_t *slave = 0;
906 int i;
907
908 cli ();
909 for (i = 1, slave = eql_first_slave (queue);
910 i <= eql_number_slaves (queue);
911 i++, slave = eql_next_slave (queue, slave))
912 {
913
914
915
916
917
918
919
920 unsigned long slave_load;
921 unsigned long bytes_queued;
922 unsigned long priority_Bps;
923
924 if (slave != 0)
925 {
926 bytes_queued = slave->bytes_queued;
927 priority_Bps = slave->priority_Bps;
928 if ( slave->dev != 0)
929 {
930 if ((slave->dev->flags & IFF_UP) == IFF_UP )
931 {
932 slave_load = (ULONG_MAX - (ULONG_MAX / 2)) -
933 (priority_Bps) + bytes_queued * 8;
934
935 if (slave_load < best_load)
936 {
937 best_load = slave_load;
938 best_slave = slave;
939 }
940 }
941 else
942 {
943
944
945
946
947
948
949 slave_corpse = slave;
950 }
951 }
952 }
953 }
954 sti ();
955 eql_set_best_slave (queue, best_slave);
956 }
957 if (slave_corpse != 0)
958 {
959 printk ("eql: scheduler found dead slave, burying...\n");
960 eql_delete_slave (eql_remove_slave (queue, slave_corpse));
961 }
962 return;
963 }
964
965
966 static slave_t * eql_find_slave_dev(slave_queue_t *queue, struct device *dev)
967 {
968 slave_t *slave = 0;
969 slave = eql_first_slave(queue);
970
971 while (slave != 0 && slave->dev != dev && slave != 0)
972 {
973 #if 0
974 if (slave->dev != 0)
975 printk ("eql: find_slave_dev; looked at '%s'...\n", slave->dev->name);
976 else
977 printk ("eql: find_slave_dev; looked at nothing...\n");
978 #endif
979 slave = slave->next;
980 }
981 return slave;
982 }
983
984
985 static inline slave_t *eql_first_slave(slave_queue_t *queue)
986 {
987 return queue->head->next;
988 }
989
990
991 static inline slave_t *eql_next_slave(slave_queue_t *queue, slave_t *slave)
992 {
993 return slave->next;
994 }
995
996 static inline void eql_set_best_slave(slave_queue_t *queue, slave_t *slave)
997 {
998 queue->best_slave = slave;
999 }
1000
1001 static void eql_timer(unsigned long param)
1002 {
1003 equalizer_t *eql = (equalizer_t *) param;
1004 slave_t *slave;
1005 slave_t *slave_corpse = 0;
1006 int i;
1007
1008 if ( ! eql_is_empty (eql->queue) )
1009 {
1010 cli ();
1011 for (i = 1, slave = eql_first_slave (eql->queue);
1012 i <= eql_number_slaves (eql->queue);
1013 i++, slave = eql_next_slave (eql->queue, slave))
1014 {
1015 if (slave != 0)
1016 {
1017 if ((slave->dev->flags & IFF_UP) == IFF_UP )
1018 {
1019 slave->bytes_queued -= slave->priority_Bps;
1020 if (slave->bytes_queued < 0)
1021 slave->bytes_queued = 0;
1022 }
1023 else
1024 slave_corpse = slave;
1025 }
1026 }
1027 sti ();
1028 if (slave_corpse != 0)
1029 {
1030 printk ("eql: timer found dead slave, burying...\n");
1031 eql_delete_slave (eql_remove_slave (eql->queue, slave_corpse));
1032 }
1033 }
1034
1035 if (eql->timer_on != 0)
1036 {
1037 eql->timer.expires = jiffies+EQL_DEFAULT_RESCHED_IVAL;
1038 add_timer (&eql->timer);
1039 }
1040 }
1041
1042 #ifdef MODULE
1043 static struct device dev_eql =
1044 {
1045 "eql", 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, eql_init
1046 };
1047
1048 int init_module(void)
1049 {
1050 if (register_netdev(&dev_eql) != 0) {
1051 printk("eql: register_netdev() returned non-zero.\n");
1052 return -EIO;
1053 }
1054 return 0;
1055 }
1056
1057 void cleanup_module(void)
1058 {
1059 unregister_netdev(&dev_eql);
1060 }
1061 #endif
1062
1063
1064
1065
1066
1067
1068
1069