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
106
107
108
109 #include <linux/module.h>
110
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 eql_init(struct device *dev)
210 {
211 static unsigned version_printed = 0;
212
213 equalizer_t *eql = 0;
214 int i;
215
216 if ( version_printed++ == 0 && eql_debug > 0)
217 printk(version);
218
219
220
221 dev->priv = kmalloc (sizeof (equalizer_t), GFP_KERNEL);
222 if (dev->priv == NULL)
223 return -ENOMEM;
224 memset (dev->priv, 0, sizeof (equalizer_t));
225 eql = (equalizer_t *) dev->priv;
226
227 eql->stats = kmalloc (sizeof (struct enet_statistics), GFP_KERNEL);
228 if (eql->stats == NULL)
229 {
230 kfree(dev->priv);
231 dev->priv = NULL;
232 return -ENOMEM;
233 }
234 memset (eql->stats, 0, sizeof (struct enet_statistics));
235
236 init_timer (&eql->timer);
237 eql->timer.data = (unsigned long) dev->priv;
238 eql->timer.expires = jiffies+EQL_DEFAULT_RESCHED_IVAL;
239 eql->timer.function = &eql_timer;
240 eql->timer_on = 0;
241
242 dev->open = eql_open;
243 dev->stop = eql_close;
244 dev->do_ioctl = eql_ioctl;
245 dev->hard_start_xmit = eql_slave_xmit;
246 dev->get_stats = eql_get_stats;
247
248
249
250
251
252
253
254 for (i = 0; i < DEV_NUMBUFFS; i++)
255 skb_queue_head_init(&dev->buffs[i]);
256
257 dev->hard_header = eql_header;
258 dev->rebuild_header = eql_rebuild_header;
259
260
261
262
263
264
265 dev->mtu = EQL_DEFAULT_MTU;
266 dev->flags = IFF_MASTER;
267
268 dev->family = AF_INET;
269 dev->pa_addr = 0;
270 dev->pa_brdaddr = 0;
271 dev->pa_mask = 0;
272 dev->pa_alen = 4;
273
274 dev->type = ARPHRD_SLIP;
275 dev->tx_queue_len = 5;
276
277 return 0;
278 }
279
280 static int eql_open(struct device *dev)
281 {
282 equalizer_t *eql = (equalizer_t *) dev->priv;
283 slave_queue_t *new_queue;
284
285 #ifdef EQL_DEBUG
286 if (eql_debug >= 5)
287 printk ("%s: open\n", dev->name);
288 #endif
289
290 new_queue = eql_new_slave_queue (dev);
291
292 if (new_queue != 0)
293 {
294 new_queue->master_dev = dev;
295 eql->queue = new_queue;
296 eql->queue->lock = 0;
297 eql->min_slaves = 1;
298 eql->max_slaves = EQL_DEFAULT_MAX_SLAVES;
299
300 printk ("%s: adding timer\n", dev->name);
301 eql->timer_on = 1;
302 add_timer (&eql->timer);
303
304 MOD_INC_USE_COUNT;
305 return 0;
306 }
307 return 1;
308 }
309
310
311 static int eql_close(struct device *dev)
312 {
313 equalizer_t *eql = (equalizer_t *) dev->priv;
314
315 #ifdef EQL_DEBUG
316 if ( eql_debug >= 5)
317 printk ("%s: close\n", dev->name);
318 #endif
319
320
321
322
323
324 #ifdef EQL_DEBUG
325 printk ("%s: stopping timer\n", dev->name);
326 #endif
327 eql->timer_on = 0;
328 del_timer (&eql->timer);
329
330 eql_delete_slave_queue (eql->queue);
331
332 MOD_DEC_USE_COUNT;
333 return 0;
334 }
335
336
337 static int eql_ioctl(struct device *dev, struct ifreq *ifr, int cmd)
338 {
339 if(!suser() && cmd!=EQL_GETMASTRCFG && cmd!=EQL_GETSLAVECFG)
340 return -EPERM;
341 switch (cmd)
342 {
343 case EQL_ENSLAVE:
344 return eql_enslave (dev, (slaving_request_t *) ifr->ifr_data);
345 case EQL_EMANCIPATE:
346 return eql_emancipate (dev, (slaving_request_t *) ifr->ifr_data);
347 case EQL_GETSLAVECFG:
348 return eql_g_slave_cfg (dev, (slave_config_t *) ifr->ifr_data);
349 case EQL_SETSLAVECFG:
350 return eql_s_slave_cfg (dev, (slave_config_t *) ifr->ifr_data);
351 case EQL_GETMASTRCFG:
352 return eql_g_master_cfg (dev, (master_config_t *) ifr->ifr_data);
353 case EQL_SETMASTRCFG:
354 return eql_s_master_cfg (dev, (master_config_t *) ifr->ifr_data);
355 default:
356 return -EOPNOTSUPP;
357 }
358 }
359
360
361 static int eql_slave_xmit(struct sk_buff *skb, struct device *dev)
362 {
363 equalizer_t *eql = (equalizer_t *) dev->priv;
364 struct device *slave_dev = 0;
365 slave_t *slave;
366
367 if (skb == NULL)
368 return 0;
369
370 eql_schedule_slaves (eql->queue);
371
372 slave_dev = eql_best_slave_dev (eql->queue);
373 slave = eql_best_slave (eql->queue);
374
375 if ( slave_dev != 0 )
376 {
377 #ifdef EQL_DEBUG
378 if (eql_debug >= 100)
379 printk ("%s: %d slaves xmitng %ld B %s\n",
380 dev->name, eql_number_slaves (eql->queue), skb->len,
381 slave_dev->name);
382 #endif
383 dev_queue_xmit (skb, slave_dev, 1);
384 eql->stats->tx_packets++;
385 slave->bytes_queued += skb->len;
386 }
387 else
388 {
389
390
391
392
393
394 eql->stats->tx_dropped++;
395 dev_kfree_skb(skb, FREE_WRITE);
396 }
397 return 0;
398 }
399
400
401 static struct enet_statistics * eql_get_stats(struct device *dev)
402 {
403 equalizer_t *eql = (equalizer_t *) dev->priv;
404 return eql->stats;
405 }
406
407
408 static int eql_header(struct sk_buff *skb, struct device *dev,
409 unsigned short type, void *daddr, void *saddr,
410 unsigned len)
411 {
412 return 0;
413 }
414
415
416 static int eql_rebuild_header(void *buff, struct device *dev,
417 unsigned long raddr, struct sk_buff *skb)
418 {
419 return 0;
420 }
421
422
423
424
425
426 static int eql_enslave(struct device *dev, slaving_request_t *srqp)
427 {
428 struct device *master_dev;
429 struct device *slave_dev;
430 slaving_request_t srq;
431 int err;
432
433 err = verify_area(VERIFY_READ, (void *)srqp, sizeof (slaving_request_t));
434 if (err)
435 return err;
436 memcpy_fromfs (&srq, srqp, sizeof (slaving_request_t));
437
438 #ifdef EQL_DEBUG
439 if (eql_debug >= 20)
440 printk ("%s: enslave '%s' %ld bps\n", dev->name,
441 srq.slave_name, srq.priority);
442 #endif
443 master_dev = dev;
444 slave_dev = dev_get (srq.slave_name);
445
446 if (master_dev != 0 && slave_dev != 0)
447 {
448 if (! eql_is_master (slave_dev) &&
449 ! eql_is_slave (slave_dev) )
450 {
451 slave_t *s = eql_new_slave ();
452 equalizer_t *eql = (equalizer_t *) master_dev->priv;
453 s->dev = slave_dev;
454 s->priority = srq.priority;
455 s->priority_bps = srq.priority;
456 s->priority_Bps = srq.priority / 8;
457 slave_dev->flags |= IFF_SLAVE;
458 eql_insert_slave (eql->queue, s);
459 return 0;
460 }
461 return -EINVAL;
462 }
463 return -EINVAL;
464 }
465
466 static int eql_emancipate(struct device *dev, slaving_request_t *srqp)
467 {
468 struct device *master_dev;
469 struct device *slave_dev;
470 slaving_request_t srq;
471 int err;
472
473 err = verify_area(VERIFY_READ, (void *)srqp, sizeof (slaving_request_t));
474 if (err)
475 return err;
476
477 memcpy_fromfs (&srq, srqp, sizeof (slaving_request_t));
478 #ifdef EQL_DEBUG
479 if (eql_debug >= 20)
480 printk ("%s: emancipate `%s`\n", dev->name, srq.slave_name);
481 #endif
482 master_dev = dev;
483 slave_dev = dev_get (srq.slave_name);
484
485 if ( eql_is_slave (slave_dev) )
486 {
487 equalizer_t *eql = (equalizer_t *) master_dev->priv;
488 slave_dev->flags = slave_dev->flags & ~IFF_SLAVE;
489 eql_remove_slave_dev (eql->queue, slave_dev);
490 return 0;
491 }
492 return -EINVAL;
493 }
494
495
496 static int eql_g_slave_cfg(struct device *dev, slave_config_t *scp)
497 {
498 slave_t *slave;
499 equalizer_t *eql;
500 struct device *slave_dev;
501 slave_config_t sc;
502 int err;
503
504 err = verify_area(VERIFY_READ, (void *)scp, sizeof (slave_config_t));
505 if (err)
506 return err;
507
508 memcpy_fromfs (&sc, scp, sizeof (slave_config_t));
509 #ifdef EQL_DEBUG
510 if (eql_debug >= 20)
511 printk ("%s: get config for slave `%s'\n", dev->name, sc.slave_name);
512 #endif
513 eql = (equalizer_t *) dev->priv;
514 slave_dev = dev_get (sc.slave_name);
515
516 if ( eql_is_slave (slave_dev) )
517 {
518 slave = eql_find_slave_dev (eql->queue, slave_dev);
519 if (slave != 0)
520 {
521 sc.priority = slave->priority;
522 err = verify_area(VERIFY_WRITE, (void *)scp, sizeof (slave_config_t));
523 if (err)
524 return err;
525 memcpy_tofs (scp, &sc, sizeof (slave_config_t));
526 return 0;
527 }
528 }
529 return -EINVAL;
530 }
531
532
533 static int eql_s_slave_cfg(struct device *dev, slave_config_t *scp)
534 {
535 slave_t *slave;
536 equalizer_t *eql;
537 struct device *slave_dev;
538 slave_config_t sc;
539 int err;
540
541 err = verify_area(VERIFY_READ, (void *)scp, sizeof (slave_config_t));
542 if (err)
543 return err;
544
545 #ifdef EQL_DEBUG
546 if (eql_debug >= 20)
547 printk ("%s: set config for slave `%s'\n", dev->name, sc.slave_name);
548 #endif
549
550 memcpy_fromfs (&sc, scp, sizeof (slave_config_t));
551
552 eql = (equalizer_t *) dev->priv;
553 slave_dev = dev_get (sc.slave_name);
554
555 if ( eql_is_slave (slave_dev) )
556 {
557 slave = eql_find_slave_dev (eql->queue, slave_dev);
558 if (slave != 0)
559 {
560 slave->priority = sc.priority;
561 slave->priority_bps = sc.priority;
562 slave->priority_Bps = sc.priority / 8;
563 return 0;
564 }
565 }
566 return -EINVAL;
567 }
568
569
570 static int eql_g_master_cfg(struct device *dev, master_config_t *mcp)
571 {
572 equalizer_t *eql;
573 master_config_t mc;
574
575 #if EQL_DEBUG
576 if (eql_debug >= 20)
577 printk ("%s: get master config\n", dev->name);
578 #endif
579
580 if ( eql_is_master (dev) )
581 {
582 int err;
583 err = verify_area(VERIFY_WRITE, (void *)mcp, sizeof (master_config_t));
584 if (err)
585 return err;
586 eql = (equalizer_t *) dev->priv;
587 mc.max_slaves = eql->max_slaves;
588 mc.min_slaves = eql->min_slaves;
589 memcpy_tofs (mcp, &mc, sizeof (master_config_t));
590 return 0;
591 }
592 return -EINVAL;
593 }
594
595
596 static int eql_s_master_cfg(struct device *dev, master_config_t *mcp)
597 {
598 equalizer_t *eql;
599 master_config_t mc;
600 int err;
601
602 err = verify_area(VERIFY_READ, (void *)mcp, sizeof (master_config_t));
603 if (err)
604 return err;
605 #if EQL_DEBUG
606 if (eql_debug >= 20)
607 printk ("%s: set master config\n", dev->name);
608 #endif
609 memcpy_fromfs (&mc, mcp, sizeof (master_config_t));
610 if ( eql_is_master (dev) )
611 {
612 eql = (equalizer_t *) dev->priv;
613 eql->max_slaves = mc.max_slaves;
614 eql->min_slaves = mc.min_slaves;
615 return 0;
616 }
617 return -EINVAL;
618 }
619
620
621
622
623
624 static inline int eql_is_slave(struct device *dev)
625 {
626 if (dev)
627 {
628 if ((dev->flags & IFF_SLAVE) == IFF_SLAVE)
629 return 1;
630 }
631 return 0;
632 }
633
634
635 static inline int eql_is_master(struct device *dev)
636 {
637 if (dev)
638 {
639 if ((dev->flags & IFF_MASTER) == IFF_MASTER)
640 return 1;
641 }
642 return 0;
643 }
644
645
646 static slave_t *eql_new_slave(void)
647 {
648 slave_t *slave;
649
650 slave = (slave_t *) kmalloc (sizeof (slave_t), GFP_KERNEL);
651 if (slave)
652 {
653 memset(slave, 0, sizeof (slave_t));
654 return slave;
655 }
656 return 0;
657 }
658
659
660 static void eql_delete_slave(slave_t *slave)
661 {
662 kfree (slave);
663 }
664
665
666 #if 0
667
668 static long slave_Bps(slave_t *slave)
669 {
670 return (slave->priority_Bps);
671 }
672
673 static long slave_bps(slave_t *slave)
674 {
675 return (slave->priority_bps);
676 }
677
678 #endif
679
680 static inline int eql_number_slaves(slave_queue_t *queue)
681 {
682 return queue->num_slaves;
683 }
684
685 static inline int eql_is_empty(slave_queue_t *queue)
686 {
687 if (eql_number_slaves (queue) == 0)
688 return 1;
689 return 0;
690 }
691
692 static inline int eql_is_full(slave_queue_t *queue)
693 {
694 equalizer_t *eql = (equalizer_t *) queue->master_dev->priv;
695
696 if (eql_number_slaves (queue) == eql->max_slaves)
697 return 1;
698 return 0;
699 }
700
701 static slave_queue_t *eql_new_slave_queue(struct device *dev)
702 {
703 slave_queue_t *queue;
704 slave_t *head_slave;
705 slave_t *tail_slave;
706
707 queue = (slave_queue_t *) kmalloc (sizeof (slave_queue_t), GFP_KERNEL);
708 if (queue == NULL)
709 return 0;
710 memset (queue, 0, sizeof (slave_queue_t));
711 head_slave = eql_new_slave ();
712 tail_slave = eql_new_slave ();
713
714 if ( head_slave != 0 &&
715 tail_slave != 0 )
716 {
717 head_slave->next = tail_slave;
718 tail_slave->next = 0;
719 queue->head = head_slave;
720 queue->num_slaves = 0;
721 queue->master_dev = dev;
722 }
723 else
724 {
725 if (head_slave)
726 kfree(head_slave);
727 if (tail_slave)
728 kfree(tail_slave);
729 kfree (queue);
730 return 0;
731 }
732 return queue;
733 }
734
735
736 static void eql_delete_slave_queue(slave_queue_t *queue)
737 {
738 slave_t *zapped;
739
740
741
742
743
744
745 while ( ! eql_is_empty (queue) )
746 {
747 zapped = eql_remove_slave (queue, queue->head->next);
748 eql_delete_slave (zapped);
749 }
750 kfree (queue->head->next);
751 kfree (queue->head);
752 kfree (queue);
753 }
754
755 static int eql_insert_slave(slave_queue_t *queue, slave_t *slave)
756 {
757 cli ();
758
759 if ( ! eql_is_full (queue) )
760 {
761 slave_t *duplicate_slave = 0;
762 duplicate_slave = eql_find_slave_dev (queue, slave->dev);
763 if (duplicate_slave != 0)
764 {
765
766
767 eql_delete_slave (eql_remove_slave (queue, duplicate_slave));
768 }
769 slave->next = queue->head->next;
770 queue->head->next = slave;
771 queue->num_slaves++;
772 sti ();
773 return 0;
774 }
775 sti ();
776 return 1;
777 }
778
779
780 static slave_t *eql_remove_slave(slave_queue_t *queue, slave_t *slave)
781 {
782 slave_t *prev;
783 slave_t *curr;
784
785 cli ();
786
787 prev = queue->head;
788 curr = queue->head->next;
789 while (curr != slave &&
790 curr->dev != 0 )
791 {
792
793 prev = curr;
794 curr = curr->next;
795 }
796
797 if (curr == slave)
798 {
799 prev->next = curr->next;
800 queue->num_slaves--;
801 sti();
802 return curr;
803 }
804 sti ();
805 return 0;
806 }
807
808
809 #if 0
810 static int eql_insert_slave_dev(slave_queue_t *queue, struct device *dev)
811 {
812 slave_t *slave;
813 cli ();
814
815 if ( ! eql_is_full (queue) )
816 {
817 slave = eql_new_slave ();
818 slave->dev = dev;
819 slave->priority = EQL_DEFAULT_SLAVE_PRIORITY;
820 slave->priority_bps = EQL_DEFAULT_SLAVE_PRIORITY;
821 slave->priority_Bps = EQL_DEFAULT_SLAVE_PRIORITY / 8;
822 slave->next = queue->head->next;
823 queue->head->next = slave;
824 sti ();
825 return 0;
826 }
827 sti ();
828 return 1;
829 }
830 #endif
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 if (slave_load < best_load)
935 {
936 best_load = slave_load;
937 best_slave = slave;
938 }
939 }
940 else
941 {
942
943
944
945
946
947
948 slave_corpse = slave;
949 }
950 }
951 }
952 }
953 sti ();
954 eql_set_best_slave (queue, best_slave);
955 }
956 if (slave_corpse != 0)
957 {
958 printk ("eql: scheduler found dead slave, burying...\n");
959 eql_delete_slave (eql_remove_slave (queue, slave_corpse));
960 }
961 return;
962 }
963
964
965 static slave_t * eql_find_slave_dev(slave_queue_t *queue, struct device *dev)
966 {
967 slave_t *slave = 0;
968 slave = eql_first_slave(queue);
969
970 while (slave != 0 && slave->dev != dev && slave != 0)
971 {
972 #if 0
973 if (slave->dev != 0)
974 printk ("eql: find_slave_dev; looked at '%s'...\n", slave->dev->name);
975 else
976 printk ("eql: find_slave_dev; looked at nothing...\n");
977 #endif
978 slave = slave->next;
979 }
980 return slave;
981 }
982
983
984 static inline slave_t *eql_first_slave(slave_queue_t *queue)
985 {
986 return queue->head->next;
987 }
988
989
990 static inline slave_t *eql_next_slave(slave_queue_t *queue, slave_t *slave)
991 {
992 return slave->next;
993 }
994
995 static inline void eql_set_best_slave(slave_queue_t *queue, slave_t *slave)
996 {
997 queue->best_slave = slave;
998 }
999
1000 #if 0
1001 static inline int eql_lock_slave_queue(slave_queue_t *queue)
1002 {
1003 int result = 0;
1004
1005 printk ("eql: lock == %d\n", queue->lock);
1006 if (queue->lock)
1007 {
1008 printk ("eql: lock_slave-q sleeping for lock\n");
1009 sleep_on (&eql_queue_lock);
1010 printk ("eql: lock_slave-q woken up\n");
1011 queue->lock = 1;
1012 }
1013 queue->lock = 1;
1014 return result;
1015 }
1016
1017 static inline int eql_unlock_slave_queue(slave_queue_t *queue)
1018 {
1019 int result = 0;
1020
1021 if (queue->lock != 0)
1022 {
1023 queue->lock = 0;
1024 printk ("eql: unlock_slave-q waking up lock waiters\n");
1025 wake_up (&eql_queue_lock);
1026 }
1027 return result;
1028 }
1029 #endif
1030
1031 static inline int eql_is_locked_slave_queue(slave_queue_t *queue)
1032 {
1033 return test_bit(1, (void *) &queue->lock);
1034 }
1035
1036 static void eql_timer(unsigned long param)
1037 {
1038 equalizer_t *eql = (equalizer_t *) param;
1039 slave_t *slave;
1040 slave_t *slave_corpse = 0;
1041 int i;
1042
1043 if ( ! eql_is_empty (eql->queue) )
1044 {
1045 cli ();
1046 for (i = 1, slave = eql_first_slave (eql->queue);
1047 i <= eql_number_slaves (eql->queue);
1048 i++, slave = eql_next_slave (eql->queue, slave))
1049 {
1050 if (slave != 0)
1051 {
1052 if ((slave->dev->flags & IFF_UP) == IFF_UP )
1053 {
1054 slave->bytes_queued -= slave->priority_Bps;
1055 if (slave->bytes_queued < 0)
1056 slave->bytes_queued = 0;
1057 }
1058 else
1059 slave_corpse = slave;
1060 }
1061 }
1062 sti ();
1063 if (slave_corpse != 0)
1064 {
1065 printk ("eql: timer found dead slave, burying...\n");
1066 eql_delete_slave (eql_remove_slave (eql->queue, slave_corpse));
1067 }
1068 }
1069
1070 if (eql->timer_on != 0)
1071 {
1072 eql->timer.expires = jiffies+EQL_DEFAULT_RESCHED_IVAL;
1073 add_timer (&eql->timer);
1074 }
1075 }
1076
1077 #ifdef MODULE
1078 static struct device dev_eql =
1079 {
1080 "eql", 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, eql_init
1081 };
1082
1083 int init_module(void)
1084 {
1085 if (register_netdev(&dev_eql) != 0) {
1086 printk("eql: register_netdev() returned non-zero.\n");
1087 return -EIO;
1088 }
1089 return 0;
1090 }
1091
1092 void cleanup_module(void)
1093 {
1094 unregister_netdev(&dev_eql);
1095 }
1096 #endif
1097
1098
1099
1100
1101
1102
1103
1104