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_insert_slave_dev
- 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_lock_slave_queue
- eql_unlock_slave_queue
- eql_is_locked_slave_queue
- 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 "Equalizer: $Revision: 3.12 $ $Date: 1995/01/19 $ 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 #ifdef MODULE
106 #include <linux/module.h>
107 #include <linux/version.h>
108 #endif
109
110 #include <linux/config.h>
111 #include <linux/kernel.h>
112 #include <linux/sched.h>
113 #include <linux/types.h>
114 #include <linux/fcntl.h>
115 #include <linux/interrupt.h>
116 #include <linux/ptrace.h>
117 #include <linux/ioport.h>
118 #include <linux/in.h>
119 #include <linux/malloc.h>
120 #include <linux/string.h>
121 #include <asm/system.h>
122 #include <asm/bitops.h>
123 #include <asm/io.h>
124 #include <asm/dma.h>
125 #include <linux/errno.h>
126
127 #include <linux/netdevice.h>
128 #include <linux/if.h>
129 #include <linux/if_arp.h>
130 #include <linux/timer.h>
131
132 #include <linux/if_eql.h>
133
134 #ifndef EQL_DEBUG
135
136
137
138
139
140
141 #define EQL_DEBUG 1
142 #endif
143 static unsigned int eql_debug = EQL_DEBUG;
144
145 int eql_init(struct device *dev);
146 static int eql_open(struct device *dev);
147 static int eql_close(struct device *dev);
148 static int eql_ioctl(struct device *dev, struct ifreq *ifr, int cmd);
149 static int eql_slave_xmit(struct sk_buff *skb, struct device *dev);
150
151 static struct enet_statistics *eql_get_stats(struct device *dev);
152 static int eql_header(struct sk_buff *skb, struct device *dev,
153 unsigned short type, void *daddr, void *saddr,
154 unsigned len);
155 static int eql_rebuild_header(void *buff, struct device *dev,
156 unsigned long raddr, struct sk_buff *skb);
157
158
159
160 static int eql_enslave(struct device *dev, slaving_request_t *srq);
161 static int eql_emancipate(struct device *dev, slaving_request_t *srq);
162
163 static int eql_g_slave_cfg(struct device *dev, slave_config_t *sc);
164 static int eql_s_slave_cfg(struct device *dev, slave_config_t *sc);
165
166 static int eql_g_master_cfg(struct device *dev, master_config_t *mc);
167 static int eql_s_master_cfg(struct device *dev, master_config_t *mc);
168
169 static inline int eql_is_slave(struct device *dev);
170 static inline int eql_is_master(struct device *dev);
171
172 static slave_t *eql_new_slave(void);
173 static void eql_delete_slave(slave_t *slave);
174
175
176 static inline int eql_number_slaves(slave_queue_t *queue);
177
178 static inline int eql_is_empty(slave_queue_t *queue);
179 static inline int eql_is_full(slave_queue_t *queue);
180
181 static slave_queue_t *eql_new_slave_queue(struct device *dev);
182 static void eql_delete_slave_queue(slave_queue_t *queue);
183
184 static int eql_insert_slave(slave_queue_t *queue, slave_t *slave);
185 static slave_t *eql_remove_slave(slave_queue_t *queue, slave_t *slave);
186
187
188 static int eql_remove_slave_dev(slave_queue_t *queue, struct device *dev);
189
190 static inline struct device *eql_best_slave_dev(slave_queue_t *queue);
191 static inline slave_t *eql_best_slave(slave_queue_t *queue);
192 static inline slave_t *eql_first_slave(slave_queue_t *queue);
193 static inline slave_t *eql_next_slave(slave_queue_t *queue, slave_t *slave);
194
195 static inline void eql_set_best_slave(slave_queue_t *queue, slave_t *slave);
196 static inline void eql_schedule_slaves(slave_queue_t *queue);
197
198 static slave_t *eql_find_slave_dev(slave_queue_t *queue, struct device *dev);
199
200
201
202
203 static void eql_timer(unsigned long param);
204
205
206
207
208
209 int
210 eql_init(struct device *dev)
211 {
212 static unsigned version_printed = 0;
213
214 equalizer_t *eql = 0;
215 int i;
216
217 if ( version_printed++ == 0 && eql_debug > 0)
218 printk(version);
219
220
221 dev->priv = kmalloc (sizeof (equalizer_t), GFP_KERNEL);
222 memset (dev->priv, 0, sizeof (equalizer_t));
223 eql = (equalizer_t *) dev->priv;
224
225 eql->stats = kmalloc (sizeof (struct enet_statistics), GFP_KERNEL);
226 memset (eql->stats, 0, sizeof (struct enet_statistics));
227
228 init_timer (&eql->timer);
229 eql->timer.data = (unsigned long) dev->priv;
230 eql->timer.expires = jiffies+EQL_DEFAULT_RESCHED_IVAL;
231 eql->timer.function = &eql_timer;
232 eql->timer_on = 0;
233
234 dev->open = eql_open;
235 dev->stop = eql_close;
236 dev->do_ioctl = eql_ioctl;
237 dev->hard_start_xmit = eql_slave_xmit;
238 dev->get_stats = eql_get_stats;
239
240
241
242
243 for (i = 0; i < DEV_NUMBUFFS; i++)
244 skb_queue_head_init(&dev->buffs[i]);
245
246 dev->hard_header = eql_header;
247 dev->rebuild_header = eql_rebuild_header;
248
249
250 dev->mtu = EQL_DEFAULT_MTU;
251 dev->flags = IFF_MASTER;
252
253 dev->family = AF_INET;
254 dev->pa_addr = 0;
255 dev->pa_brdaddr = 0;
256 dev->pa_mask = 0;
257 dev->pa_alen = 4;
258
259 dev->type = ARPHRD_SLIP;
260
261 return 0;
262 }
263
264
265 static
266 int
267 eql_open(struct device *dev)
268 {
269 equalizer_t *eql = (equalizer_t *) dev->priv;
270 slave_queue_t *new_queue;
271
272 #ifdef EQL_DEBUG
273 if (eql_debug >= 5)
274 printk ("%s: open\n", dev->name);
275 #endif
276
277 new_queue = eql_new_slave_queue (dev);
278
279 if (new_queue != 0)
280 {
281 new_queue->master_dev = dev;
282 eql->queue = new_queue;
283 eql->queue->lock = 0;
284 eql->min_slaves = 1;
285 eql->max_slaves = EQL_DEFAULT_MAX_SLAVES;
286
287 printk ("%s: adding timer\n", dev->name);
288 eql->timer_on = 1;
289 add_timer (&eql->timer);
290
291 #ifdef MODULE
292 MOD_INC_USE_COUNT;
293 #endif
294 return 0;
295 }
296 return 1;
297 }
298
299
300 static
301 int
302 eql_close(struct device *dev)
303 {
304 equalizer_t *eql = (equalizer_t *) dev->priv;
305
306 #ifdef EQL_DEBUG
307 if ( eql_debug >= 5)
308 printk ("%s: close\n", dev->name);
309 #endif
310
311
312 printk ("%s: stopping timer\n", dev->name);
313 eql->timer_on = 0;
314 del_timer (&eql->timer);
315
316 eql_delete_slave_queue (eql->queue);
317
318 #ifdef MODULE
319 MOD_DEC_USE_COUNT;
320 #endif
321
322 return 0;
323 }
324
325
326 static
327 int
328 eql_ioctl(struct device *dev, struct ifreq *ifr, int cmd)
329 {
330 if(!suser() && cmd!=EQL_GETMASTRCFG && cmd!=EQL_GETSLAVECFG)
331 return -EPERM;
332 switch (cmd)
333 {
334 case EQL_ENSLAVE:
335 return eql_enslave (dev, (slaving_request_t *) ifr->ifr_data);
336 case EQL_EMANCIPATE:
337 return eql_emancipate (dev, (slaving_request_t *) ifr->ifr_data);
338
339 case EQL_GETSLAVECFG:
340 return eql_g_slave_cfg (dev, (slave_config_t *) ifr->ifr_data);
341 case EQL_SETSLAVECFG:
342 return eql_s_slave_cfg (dev, (slave_config_t *) ifr->ifr_data);
343
344 case EQL_GETMASTRCFG:
345 return eql_g_master_cfg (dev, (master_config_t *) ifr->ifr_data);
346 case EQL_SETMASTRCFG:
347 return eql_s_master_cfg (dev, (master_config_t *) ifr->ifr_data);
348
349 default:
350 return -EOPNOTSUPP;
351 }
352 }
353
354
355 static
356 int
357 eql_slave_xmit(struct sk_buff *skb, struct device *dev)
358 {
359 equalizer_t *eql = (equalizer_t *) dev->priv;
360 struct device *slave_dev = 0;
361 slave_t *slave;
362
363 if (skb == NULL)
364 {
365 return 0;
366 }
367
368 eql_schedule_slaves (eql->queue);
369
370 slave_dev = eql_best_slave_dev (eql->queue);
371 slave = eql_best_slave (eql->queue);
372
373 if ( slave_dev != 0 )
374 {
375 #ifdef EQL_DEBUG
376 if (eql_debug >= 100)
377 printk ("%s: %d slaves xmitng %ld B %s\n",
378 dev->name, eql_number_slaves (eql->queue), skb->len,
379 slave_dev->name);
380 #endif
381
382 dev_queue_xmit (skb, slave_dev, 1);
383 eql->stats->tx_packets++;
384 slave->bytes_queued += skb->len;
385 }
386 else
387 {
388
389
390
391 eql->stats->tx_dropped++;
392 dev_kfree_skb(skb, FREE_WRITE);
393 }
394 return 0;
395 }
396
397
398 static
399 struct enet_statistics *
400 eql_get_stats(struct device *dev)
401 {
402 equalizer_t *eql = (equalizer_t *) dev->priv;
403
404 return eql->stats;
405 }
406
407
408 static
409 int
410 eql_header(struct sk_buff *skb, struct device *dev,
411 unsigned short type, void *daddr, void *saddr,
412 unsigned len)
413 {
414 return 0;
415 }
416
417
418 static
419 int
420 eql_rebuild_header(void *buff, struct device *dev,
421 unsigned long raddr, struct sk_buff *skb)
422 {
423 return 0;
424 }
425
426
427
428
429
430
431
432
433 static int
434 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) return err;
443
444 memcpy_fromfs (&srq, srqp, sizeof (slaving_request_t));
445
446 #ifdef EQL_DEBUG
447 if (eql_debug >= 20)
448 printk ("%s: enslave '%s' %ld bps\n", dev->name,
449 srq.slave_name, srq.priority);
450 #endif
451
452 master_dev = dev;
453 slave_dev = dev_get (srq.slave_name);
454
455 if (master_dev != 0 && slave_dev != 0)
456 {
457 if (! eql_is_master (slave_dev) &&
458 ! eql_is_slave (slave_dev) )
459 {
460 slave_t *s = eql_new_slave ();
461 equalizer_t *eql = (equalizer_t *) master_dev->priv;
462
463 s->dev = slave_dev;
464 s->priority = srq.priority;
465 s->priority_bps = srq.priority;
466 s->priority_Bps = srq.priority / 8;
467
468 slave_dev->flags |= IFF_SLAVE;
469
470 eql_insert_slave (eql->queue, s);
471
472 return 0;
473 }
474 return -EINVAL;
475 }
476 return -EINVAL;
477 }
478
479
480
481 static
482 int
483 eql_emancipate(struct device *dev, slaving_request_t *srqp)
484 {
485 struct device *master_dev;
486 struct device *slave_dev;
487 slaving_request_t srq;
488 int err;
489
490 err = verify_area(VERIFY_READ, (void *)srqp, sizeof (slaving_request_t));
491 if (err) return err;
492
493 memcpy_fromfs (&srq, srqp, sizeof (slaving_request_t));
494
495 #ifdef EQL_DEBUG
496 if (eql_debug >= 20)
497 printk ("%s: emancipate `%s`\n", dev->name, srq.slave_name);
498 #endif
499
500
501 master_dev = dev;
502 slave_dev = dev_get (srq.slave_name);
503
504 if ( eql_is_slave (slave_dev) )
505 {
506 equalizer_t *eql = (equalizer_t *) master_dev->priv;
507 slave_dev->flags = slave_dev->flags & ~IFF_SLAVE;
508
509 eql_remove_slave_dev (eql->queue, slave_dev);
510
511 return 0;
512 }
513 return -EINVAL;
514 }
515
516
517 static
518 int
519 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) return err;
529
530 memcpy_fromfs (&sc, scp, sizeof (slave_config_t));
531
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
537 eql = (equalizer_t *) dev->priv;
538 slave_dev = dev_get (sc.slave_name);
539
540 if ( eql_is_slave (slave_dev) )
541 {
542 slave = eql_find_slave_dev (eql->queue, slave_dev);
543 if (slave != 0)
544 {
545 sc.priority = slave->priority;
546
547 err = verify_area(VERIFY_WRITE, (void *)scp, sizeof (slave_config_t));
548 if (err) return err;
549
550 memcpy_tofs (scp, &sc, sizeof (slave_config_t));
551 return 0;
552 }
553 }
554 return -EINVAL;
555 }
556
557
558 static
559 int
560 eql_s_slave_cfg(struct device *dev, slave_config_t *scp)
561 {
562 slave_t *slave;
563 equalizer_t *eql;
564 struct device *slave_dev;
565 slave_config_t sc;
566 int err;
567
568 err = verify_area(VERIFY_READ, (void *)scp, sizeof (slave_config_t));
569 if (err) return err;
570
571 #ifdef EQL_DEBUG
572 if (eql_debug >= 20)
573 printk ("%s: set config for slave `%s'\n", dev->name, sc.slave_name);
574 #endif
575
576 memcpy_fromfs (&sc, scp, sizeof (slave_config_t));
577
578 eql = (equalizer_t *) dev->priv;
579 slave_dev = dev_get (sc.slave_name);
580
581 if ( eql_is_slave (slave_dev) )
582 {
583 slave = eql_find_slave_dev (eql->queue, slave_dev);
584 if (slave != 0)
585 {
586 slave->priority = sc.priority;
587 slave->priority_bps = sc.priority;
588 slave->priority_Bps = sc.priority / 8;
589 return 0;
590 }
591 }
592 return -EINVAL;
593 }
594
595
596 static
597 int
598 eql_g_master_cfg(struct device *dev, master_config_t *mcp)
599 {
600 equalizer_t *eql;
601 master_config_t mc;
602
603 #if EQL_DEBUG
604 if (eql_debug >= 20)
605 printk ("%s: get master config\n", dev->name);
606 #endif
607
608 if ( eql_is_master (dev) )
609 {
610 int err;
611
612 err = verify_area(VERIFY_WRITE, (void *)mcp, sizeof (master_config_t));
613 if (err) return err;
614
615 eql = (equalizer_t *) dev->priv;
616 mc.max_slaves = eql->max_slaves;
617 mc.min_slaves = eql->min_slaves;
618 memcpy_tofs (mcp, &mc, sizeof (master_config_t));
619 return 0;
620 }
621 return -EINVAL;
622 }
623
624
625 static
626 int
627 eql_s_master_cfg(struct device *dev, master_config_t *mcp)
628 {
629 equalizer_t *eql;
630 master_config_t mc;
631 int err;
632
633 err = verify_area(VERIFY_READ, (void *)mcp, sizeof (master_config_t));
634 if (err) return err;
635
636 #if EQL_DEBUG
637 if (eql_debug >= 20)
638 printk ("%s: set master config\n", dev->name);
639 #endif
640
641 memcpy_fromfs (&mc, mcp, sizeof (master_config_t));
642
643 if ( eql_is_master (dev) )
644 {
645 eql = (equalizer_t *) dev->priv;
646 eql->max_slaves = mc.max_slaves;
647 eql->min_slaves = mc.min_slaves;
648 return 0;
649 }
650 return -EINVAL;
651 }
652
653
654
655
656
657 static inline
658 int
659 eql_is_slave(struct device *dev)
660 {
661 if (dev)
662 {
663 if ((dev->flags & IFF_SLAVE) == IFF_SLAVE)
664 return 1;
665 }
666 return 0;
667 }
668
669
670 static inline
671 int
672 eql_is_master(struct device *dev)
673 {
674 if (dev)
675 {
676 if ((dev->flags & IFF_MASTER) == IFF_MASTER)
677 return 1;
678 }
679 return 0;
680 }
681
682
683 static
684 slave_t *
685 eql_new_slave(void)
686 {
687 slave_t *slave;
688
689 slave = (slave_t *) kmalloc (sizeof (slave_t), GFP_KERNEL);
690 if (slave)
691 {
692 memset(slave, 0, sizeof (slave_t));
693 return slave;
694 }
695 return 0;
696 }
697
698
699 static
700 void
701 eql_delete_slave(slave_t *slave)
702 {
703 kfree (slave);
704 }
705
706
707 #if 0
708
709 static
710 long
711 slave_Bps(slave_t *slave)
712 {
713 return (slave->priority_Bps);
714 }
715
716 static
717 long
718 slave_bps(slave_t *slave)
719 {
720 return (slave->priority_bps);
721 }
722 #endif
723
724
725 static inline
726 int
727 eql_number_slaves(slave_queue_t *queue)
728 {
729 return queue->num_slaves;
730 }
731
732
733 static inline
734 int
735 eql_is_empty(slave_queue_t *queue)
736 {
737 if (eql_number_slaves (queue) == 0)
738 return 1;
739 return 0;
740 }
741
742
743 static inline
744 int
745 eql_is_full(slave_queue_t *queue)
746 {
747 equalizer_t *eql = (equalizer_t *) queue->master_dev->priv;
748
749 if (eql_number_slaves (queue) == eql->max_slaves)
750 return 1;
751 return 0;
752 }
753
754
755 static
756 slave_queue_t *
757 eql_new_slave_queue(struct device *dev)
758 {
759 slave_queue_t *queue;
760 slave_t *head_slave;
761 slave_t *tail_slave;
762
763 queue = (slave_queue_t *) kmalloc (sizeof (slave_queue_t), GFP_KERNEL);
764 memset (queue, 0, sizeof (slave_queue_t));
765
766 head_slave = eql_new_slave ();
767 tail_slave = eql_new_slave ();
768
769 if ( head_slave != 0 &&
770 tail_slave != 0 )
771 {
772 head_slave->next = tail_slave;
773 tail_slave->next = 0;
774 queue->head = head_slave;
775 queue->num_slaves = 0;
776 queue->master_dev = dev;
777 }
778 else
779 {
780 kfree (queue);
781 return 0;
782 }
783 return queue;
784 }
785
786
787 static
788 void
789 eql_delete_slave_queue(slave_queue_t *queue)
790 {
791 slave_t *zapped;
792
793
794
795
796 while ( ! eql_is_empty (queue) )
797 {
798 zapped = eql_remove_slave (queue, queue->head->next);
799 eql_delete_slave (zapped);
800 }
801 kfree (queue->head->next);
802 kfree (queue->head);
803 kfree (queue);
804 }
805
806
807 static
808 int
809 eql_insert_slave(slave_queue_t *queue, slave_t *slave)
810 {
811 cli ();
812
813 if ( ! eql_is_full (queue) )
814 {
815 slave_t *duplicate_slave = 0;
816
817 duplicate_slave = eql_find_slave_dev (queue, slave->dev);
818
819 if (duplicate_slave != 0)
820 {
821
822
823 eql_delete_slave (eql_remove_slave (queue, duplicate_slave));
824 }
825
826 slave->next = queue->head->next;
827 queue->head->next = slave;
828 queue->num_slaves++;
829 sti ();
830 return 0;
831 }
832
833 sti ();
834
835 return 1;
836 }
837
838
839 static
840 slave_t *
841 eql_remove_slave(slave_queue_t *queue, slave_t *slave)
842 {
843 slave_t *prev;
844 slave_t *current;
845
846 cli ();
847
848 prev = queue->head;
849 current = queue->head->next;
850 while (current != slave &&
851 current->dev != 0 )
852 {
853
854 prev = current;
855 current = current->next;
856 }
857
858 if (current == slave)
859 {
860 prev->next = current->next;
861 queue->num_slaves--;
862 sti();
863 return current;
864 }
865
866 sti ();
867
868 return 0;
869 }
870
871
872 #if 0
873 static
874 int
875 eql_insert_slave_dev(slave_queue_t *queue, struct device *dev)
876 {
877 slave_t *slave;
878
879 cli ();
880
881 if ( ! eql_is_full (queue) )
882 {
883 slave = eql_new_slave ();
884 slave->dev = dev;
885 slave->priority = EQL_DEFAULT_SLAVE_PRIORITY;
886 slave->priority_bps = EQL_DEFAULT_SLAVE_PRIORITY;
887 slave->priority_Bps = EQL_DEFAULT_SLAVE_PRIORITY / 8;
888 slave->next = queue->head->next;
889 queue->head->next = slave;
890 sti ();
891 return 0;
892 }
893 sti ();
894 return 1;
895 }
896 #endif
897
898
899 static
900 int
901 eql_remove_slave_dev(slave_queue_t *queue, struct device *dev)
902 {
903 slave_t *prev;
904 slave_t *current;
905 slave_t *target;
906
907 target = eql_find_slave_dev (queue, dev);
908
909 if (target != 0)
910 {
911 cli ();
912
913 prev = queue->head;
914 current = prev->next;
915 while (current != target)
916 {
917 prev = current;
918 current = current->next;
919 }
920 prev->next = current->next;
921 queue->num_slaves--;
922
923 sti ();
924
925 eql_delete_slave (current);
926 return 0;
927 }
928 return 1;
929 }
930
931
932 static inline
933 struct device *
934 eql_best_slave_dev(slave_queue_t *queue)
935 {
936 if (queue->best_slave != 0)
937 {
938 if (queue->best_slave->dev != 0)
939 return queue->best_slave->dev;
940 else
941 return 0;
942 }
943 else
944 return 0;
945 }
946
947
948 static inline
949 slave_t *
950 eql_best_slave(slave_queue_t *queue)
951 {
952 return queue->best_slave;
953 }
954
955 static inline
956 void
957 eql_schedule_slaves(slave_queue_t *queue)
958 {
959 struct device *master_dev = queue->master_dev;
960 slave_t *best_slave = 0;
961 slave_t *slave_corpse = 0;
962
963 #ifdef EQL_DEBUG
964 if (eql_debug >= 100)
965 printk ("%s: schedule %d slaves\n",
966 master_dev->name, eql_number_slaves (queue));
967 #endif
968
969 if ( eql_is_empty (queue) )
970 {
971
972 eql_set_best_slave (queue, (slave_t *) 0);
973 return;
974 }
975 else
976 {
977 unsigned long best_load = (unsigned long) ULONG_MAX;
978 slave_t *slave = 0;
979 int i;
980
981 cli ();
982
983 for (i = 1, slave = eql_first_slave (queue);
984 i <= eql_number_slaves (queue);
985 i++, slave = eql_next_slave (queue, slave))
986 {
987
988
989
990
991
992 unsigned long slave_load;
993 unsigned long bytes_queued;
994 unsigned long priority_Bps;
995
996 if (slave != 0)
997 {
998 bytes_queued = slave->bytes_queued;
999 priority_Bps = slave->priority_Bps;
1000
1001 if ( slave->dev != 0)
1002 {
1003 if ((slave->dev->flags & IFF_UP) == IFF_UP )
1004 {
1005 slave_load = (ULONG_MAX - (ULONG_MAX / 2)) -
1006 (priority_Bps) + bytes_queued * 8;
1007
1008 if (slave_load < best_load)
1009 {
1010 best_load = slave_load;
1011 best_slave = slave;
1012 }
1013 }
1014 else
1015 {
1016
1017
1018
1019
1020 slave_corpse = slave;
1021 }
1022 }
1023 }
1024 }
1025
1026 sti ();
1027
1028 eql_set_best_slave (queue, best_slave);
1029 }
1030
1031 if (slave_corpse != 0)
1032 {
1033 printk ("eql: scheduler found dead slave, burying...\n");
1034 eql_delete_slave (eql_remove_slave (queue, slave_corpse));
1035 }
1036
1037 return;
1038 }
1039
1040
1041 static
1042 slave_t *
1043 eql_find_slave_dev(slave_queue_t *queue, struct device *dev)
1044 {
1045 slave_t *slave = 0;
1046
1047 slave = eql_first_slave(queue);
1048
1049 while (slave != 0 && slave->dev != dev && slave != 0)
1050 {
1051 #if 0
1052 if (slave->dev != 0)
1053 printk ("eql: find_slave_dev; looked at '%s'...\n", slave->dev->name);
1054 else
1055 printk ("eql: find_slave_dev; looked at nothing...\n");
1056 #endif
1057
1058 slave = slave->next;
1059 }
1060
1061 return slave;
1062 }
1063
1064
1065 static inline
1066 slave_t *
1067 eql_first_slave(slave_queue_t *queue)
1068 {
1069 return queue->head->next;
1070 }
1071
1072
1073 static inline
1074 slave_t *
1075 eql_next_slave(slave_queue_t *queue, slave_t *slave)
1076 {
1077 return slave->next;
1078 }
1079
1080
1081 static inline
1082 void
1083 eql_set_best_slave(slave_queue_t *queue, slave_t *slave)
1084 {
1085 queue->best_slave = slave;
1086 }
1087
1088
1089 #if 0
1090 static inline
1091 int
1092 eql_lock_slave_queue(slave_queue_t *queue)
1093 {
1094 int result = 0;
1095
1096 printk ("eql: lock == %d\n", queue->lock);
1097 if (queue->lock)
1098 {
1099 printk ("eql: lock_slave-q sleeping for lock\n");
1100 sleep_on (&eql_queue_lock);
1101 printk ("eql: lock_slave-q woken up\n");
1102 queue->lock = 1;
1103 }
1104 queue->lock = 1;
1105 return result;
1106 }
1107
1108 static inline
1109 int
1110 eql_unlock_slave_queue(slave_queue_t *queue)
1111 {
1112 int result = 0;
1113
1114 if (queue->lock != 0)
1115 {
1116 queue->lock = 0;
1117 printk ("eql: unlock_slave-q waking up lock waiters\n");
1118 wake_up (&eql_queue_lock);
1119 }
1120 return result;
1121 }
1122 #endif
1123
1124 static inline
1125 int
1126 eql_is_locked_slave_queue(slave_queue_t *queue)
1127 {
1128 return test_bit(1, (void *) &queue->lock);
1129 }
1130
1131 static
1132 void
1133 eql_timer(unsigned long param)
1134 {
1135 equalizer_t *eql = (equalizer_t *) param;
1136 slave_t *slave;
1137 slave_t *slave_corpse = 0;
1138 int i;
1139
1140 if ( ! eql_is_empty (eql->queue) )
1141 {
1142 cli ();
1143
1144 for (i = 1, slave = eql_first_slave (eql->queue);
1145 i <= eql_number_slaves (eql->queue);
1146 i++, slave = eql_next_slave (eql->queue, slave))
1147 {
1148 if (slave != 0)
1149 {
1150 if ((slave->dev->flags & IFF_UP) == IFF_UP )
1151 {
1152 slave->bytes_queued -= slave->priority_Bps;
1153
1154 if (slave->bytes_queued < 0)
1155 slave->bytes_queued = 0;
1156 }
1157 else
1158 {
1159 slave_corpse = slave;
1160 }
1161 }
1162 }
1163
1164 sti ();
1165
1166 if (slave_corpse != 0)
1167 {
1168 printk ("eql: timer found dead slave, burying...\n");
1169 eql_delete_slave (eql_remove_slave (eql->queue, slave_corpse));
1170 }
1171
1172 }
1173
1174 if (eql->timer_on != 0)
1175 {
1176 eql->timer.expires = jiffies+EQL_DEFAULT_RESCHED_IVAL;
1177 add_timer (&eql->timer);
1178 }
1179 }
1180
1181 #ifdef MODULE
1182 char kernel_version[] = UTS_RELEASE;
1183 static struct device dev_eql = {
1184 "eql", 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, eql_init };
1185
1186 int init_module(void)
1187 {
1188 if (register_netdev(&dev_eql) != 0) {
1189 printk("eql: register_netdev() returned non-zero.\n");
1190 return -EIO;
1191 }
1192 return 0;
1193 }
1194
1195 void
1196 cleanup_module(void)
1197 {
1198 if (MOD_IN_USE)
1199 printk("eql: device busy, remove delayed\n");
1200 else
1201 {
1202 unregister_netdev(&dev_eql);
1203 }
1204 }
1205 #endif
1206
1207
1208
1209
1210
1211
1212
1213