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