v2.5.0.4 -> v2.5.0.5
[linux-flexiantxendom0-3.2.10.git] / net / irda / qos.c
1 /*********************************************************************
2  *                                
3  * Filename:      qos.c
4  * Version:       1.0
5  * Description:   IrLAP QoS parameter negotiation
6  * Status:        Stable
7  * Author:        Dag Brattli <dagb@cs.uit.no>
8  * Created at:    Tue Sep  9 00:00:26 1997
9  * Modified at:   Sun Jan 30 14:29:16 2000
10  * Modified by:   Dag Brattli <dagb@cs.uit.no>
11  * 
12  *     Copyright (c) 1998-2000 Dag Brattli <dagb@cs.uit.no>, 
13  *     All Rights Reserved.
14  *     Copyright (c) 2000-2001 Jean Tourrilhes <jt@hpl.hp.com>
15  *     
16  *     This program is free software; you can redistribute it and/or 
17  *     modify it under the terms of the GNU General Public License as 
18  *     published by the Free Software Foundation; either version 2 of 
19  *     the License, or (at your option) any later version.
20  * 
21  *     This program is distributed in the hope that it will be useful,
22  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
23  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  *     GNU General Public License for more details.
25  * 
26  *     You should have received a copy of the GNU General Public License 
27  *     along with this program; if not, write to the Free Software 
28  *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
29  *     MA 02111-1307 USA
30  *     
31  ********************************************************************/
32
33 #include <linux/config.h>
34 #include <asm/byteorder.h>
35
36 #include <net/irda/irda.h>
37 #include <net/irda/parameters.h>
38 #include <net/irda/qos.h>
39 #include <net/irda/irlap.h>
40
41 /*
42  * Maximum values of the baud rate we negociate with the other end.
43  * Most often, you don't have to change that, because Linux-IrDA will
44  * use the maximum offered by the link layer, which usually works fine.
45  * In some very rare cases, you may want to limit it to lower speeds...
46  */
47 int sysctl_max_baud_rate = 16000000;
48 /*
49  * Maximum value of the lap disconnect timer we negociate with the other end.
50  * Most often, the value below represent the best compromise, but some user
51  * may want to keep the LAP alive longuer or shorter in case of link failure.
52  * Remember that the threshold time (early warning) is fixed to 3s...
53  */
54 int sysctl_max_noreply_time = 12;
55 /*
56  * Minimum turn time to be applied before transmitting to the peer.
57  * Nonzero values (usec) are used as lower limit to the per-connection
58  * mtt value which was announced by the other end during negotiation.
59  * Might be helpful if the peer device provides too short mtt.
60  * Default is 10 which means using the unmodified value given by the peer
61  * except if it's 0 (0 is likely a bug in the other stack).
62  */
63 unsigned sysctl_min_tx_turn_time = 10;
64
65 static int irlap_param_baud_rate(void *instance, irda_param_t *param, int get);
66 static int irlap_param_link_disconnect(void *instance, irda_param_t *parm, 
67                                        int get);
68 static int irlap_param_max_turn_time(void *instance, irda_param_t *param, 
69                                      int get);
70 static int irlap_param_data_size(void *instance, irda_param_t *param, int get);
71 static int irlap_param_window_size(void *instance, irda_param_t *param, 
72                                    int get);
73 static int irlap_param_additional_bofs(void *instance, irda_param_t *parm, 
74                                        int get);
75 static int irlap_param_min_turn_time(void *instance, irda_param_t *param, 
76                                      int get);
77
78 __u32 min_turn_times[]  = { 10000, 5000, 1000, 500, 100, 50, 10, 0 }; /* us */
79 __u32 baud_rates[]      = { 2400, 9600, 19200, 38400, 57600, 115200, 576000, 
80                             1152000, 4000000, 16000000 };           /* bps */
81 __u32 data_sizes[]      = { 64, 128, 256, 512, 1024, 2048 };        /* bytes */
82 __u32 add_bofs[]        = { 48, 24, 12, 5, 3, 2, 1, 0 };            /* bytes */
83 __u32 max_turn_times[]  = { 500, 250, 100, 50 };                    /* ms */
84 __u32 link_disc_times[] = { 3, 8, 12, 16, 20, 25, 30, 40 };         /* secs */
85
86 __u32 max_line_capacities[10][4] = {
87        /* 500 ms     250 ms  100 ms  50 ms (max turn time) */
88         {    100,      0,      0,     0 }, /*     2400 bps */
89         {    400,      0,      0,     0 }, /*     9600 bps */
90         {    800,      0,      0,     0 }, /*    19200 bps */
91         {   1600,      0,      0,     0 }, /*    38400 bps */
92         {   2360,      0,      0,     0 }, /*    57600 bps */
93         {   4800,   2400,    960,   480 }, /*   115200 bps */
94         {  28800,  11520,   5760,  2880 }, /*   576000 bps */
95         {  57600,  28800,  11520,  5760 }, /*  1152000 bps */
96         { 200000, 100000,  40000, 20000 }, /*  4000000 bps */
97         { 800000, 400000, 160000, 80000 }, /* 16000000 bps */
98 };
99
100 static pi_minor_info_t pi_minor_call_table_type_0[] = {
101         { NULL, 0 },
102 /* 01 */{ irlap_param_baud_rate,       PV_INTEGER | PV_LITTLE_ENDIAN },
103         { NULL, 0 },
104         { NULL, 0 },
105         { NULL, 0 },
106         { NULL, 0 },
107         { NULL, 0 },
108         { NULL, 0 },
109 /* 08 */{ irlap_param_link_disconnect, PV_INT_8_BITS }
110 };
111
112 static pi_minor_info_t pi_minor_call_table_type_1[] = {
113         { NULL, 0 },
114         { NULL, 0 },
115 /* 82 */{ irlap_param_max_turn_time,   PV_INT_8_BITS },
116 /* 83 */{ irlap_param_data_size,       PV_INT_8_BITS },
117 /* 84 */{ irlap_param_window_size,     PV_INT_8_BITS },
118 /* 85 */{ irlap_param_additional_bofs, PV_INT_8_BITS },
119 /* 86 */{ irlap_param_min_turn_time,   PV_INT_8_BITS },
120 };
121
122 static pi_major_info_t pi_major_call_table[] = {
123         { pi_minor_call_table_type_0, 9 },
124         { pi_minor_call_table_type_1, 7 },
125 };
126
127 static pi_param_info_t irlap_param_info = { pi_major_call_table, 2, 0x7f, 7 };
128
129 /* ---------------------- LOCAL SUBROUTINES ---------------------- */
130 /* Note : we start with a bunch of local subroutines.
131  * As the compiler is "one pass", this is the only way to get them to
132  * inline properly...
133  * Jean II
134  */
135 /*
136  * Function value_index (value, array, size)
137  *
138  *    Returns the index to the value in the specified array
139  */
140 static inline int value_index(__u32 value, __u32 *array, int size)
141 {
142         int i;
143         
144         for (i=0; i < size; i++)
145                 if (array[i] == value)
146                         break;
147         return i;
148 }
149
150 /*
151  * Function index_value (index, array)
152  *
153  *    Returns value to index in array, easy!
154  *
155  */
156 static inline __u32 index_value(int index, __u32 *array) 
157 {
158         return array[index];
159 }
160
161 /*
162  * Function msb_index (word)
163  *
164  *    Returns index to most significant bit (MSB) in word
165  *
166  */
167 int msb_index (__u16 word) 
168 {
169         __u16 msb = 0x8000;
170         int index = 15;   /* Current MSB */
171         
172         while (msb) {
173                 if (word & msb)
174                         break;   /* Found it! */
175                 msb >>=1;
176                 index--;
177         }
178         return index;
179 }
180
181 static inline __u32 byte_value(__u8 byte, __u32 *array) 
182 {
183         int index;
184
185         ASSERT(array != NULL, return -1;);
186
187         index = msb_index(byte);
188
189         return index_value(index, array);
190 }
191
192 /*
193  * Function value_lower_bits (value, array)
194  *
195  *    Returns a bit field marking all possibility lower than value.
196  */
197 static inline int value_lower_bits(__u32 value, __u32 *array, int size, __u16 *field)
198 {
199         int     i;
200         __u16   mask = 0x1;
201         __u16   result = 0x0;
202
203         for (i=0; i < size; i++) {
204                 /* Add the current value to the bit field, shift mask */
205                 result |= mask;
206                 mask <<= 1;
207                 /* Finished ? */
208                 if (array[i] >= value)
209                         break;
210         }
211         /* Send back a valid index */
212         if(i >= size)
213           i = size - 1; /* Last item */
214         *field = result;
215         return i;
216 }
217
218 /*
219  * Function value_highest_bit (value, array)
220  *
221  *    Returns a bit field marking the highest possibility lower than value.
222  */
223 static inline int value_highest_bit(__u32 value, __u32 *array, int size, __u16 *field)
224 {
225         int     i;
226         __u16   mask = 0x1;
227         __u16   result = 0x0;
228
229         for (i=0; i < size; i++) {
230                 /* Finished ? */
231                 if (array[i] <= value)
232                         break;
233                 /* Shift mask */
234                 mask <<= 1;
235         }
236         /* Set the current value to the bit field */
237         result |= mask;
238         /* Send back a valid index */
239         if(i >= size)
240           i = size - 1; /* Last item */
241         *field = result;
242         return i;
243 }
244
245 /* -------------------------- MAIN CALLS -------------------------- */
246
247 /*
248  * Function irda_qos_compute_intersection (qos, new)
249  *
250  *    Compute the intersection of the old QoS capabilites with new ones
251  *
252  */
253 void irda_qos_compute_intersection(struct qos_info *qos, struct qos_info *new)
254 {
255         ASSERT(qos != NULL, return;);
256         ASSERT(new != NULL, return;);
257
258         /* Apply */
259         qos->baud_rate.bits       &= new->baud_rate.bits;
260         qos->window_size.bits     &= new->window_size.bits;
261         qos->min_turn_time.bits   &= new->min_turn_time.bits;
262         qos->max_turn_time.bits   &= new->max_turn_time.bits;
263         qos->data_size.bits       &= new->data_size.bits;
264         qos->link_disc_time.bits  &= new->link_disc_time.bits;
265         qos->additional_bofs.bits &= new->additional_bofs.bits;
266
267         irda_qos_bits_to_value(qos);
268 }
269
270 /*
271  * Function irda_init_max_qos_capabilies (qos)
272  *
273  *    The purpose of this function is for layers and drivers to be able to
274  *    set the maximum QoS possible and then "and in" their own limitations
275  * 
276  */
277 void irda_init_max_qos_capabilies(struct qos_info *qos)
278 {
279         int i;
280         /* 
281          *  These are the maximum supported values as specified on pages
282          *  39-43 in IrLAP
283          */
284
285         /* Use sysctl to set some configurable values... */
286         /* Set configured max speed */
287         i = value_lower_bits(sysctl_max_baud_rate, baud_rates, 10,
288                              &qos->baud_rate.bits);
289         sysctl_max_baud_rate = index_value(i, baud_rates);
290
291         /* Set configured max disc time */
292         i = value_lower_bits(sysctl_max_noreply_time, link_disc_times, 8,
293                              &qos->link_disc_time.bits);
294         sysctl_max_noreply_time = index_value(i, link_disc_times);
295
296         /* LSB is first byte, MSB is second byte */
297         qos->baud_rate.bits    &= 0x03ff;
298
299         qos->window_size.bits     = 0x7f;
300         qos->min_turn_time.bits   = 0xff;
301         qos->max_turn_time.bits   = 0x0f;
302         qos->data_size.bits       = 0x3f;
303         qos->link_disc_time.bits &= 0xff;
304         qos->additional_bofs.bits = 0xff;
305 }
306
307 /*
308  * Function irlap_adjust_qos_settings (qos)
309  *
310  *     Adjust QoS settings in case some values are not possible to use because
311  *     of other settings
312  */
313 void irlap_adjust_qos_settings(struct qos_info *qos)
314 {
315         __u32 line_capacity;
316         int index;
317
318         IRDA_DEBUG(2, __FUNCTION__ "()\n");
319
320         /*
321          * Make sure the mintt is sensible.
322          */
323         if (sysctl_min_tx_turn_time > qos->min_turn_time.value) {
324                 int i;
325
326                 /* We don't really need bits, but easier this way */
327                 i = value_highest_bit(sysctl_min_tx_turn_time, min_turn_times,
328                                       8, &qos->min_turn_time.bits);
329                 sysctl_min_tx_turn_time = index_value(i, min_turn_times);
330                 qos->min_turn_time.value = sysctl_min_tx_turn_time;
331         }
332
333         /* 
334          * Not allowed to use a max turn time less than 500 ms if the baudrate
335          * is less than 115200
336          */
337         if ((qos->baud_rate.value < 115200) && 
338             (qos->max_turn_time.value < 500))
339         {
340                 IRDA_DEBUG(0, __FUNCTION__ 
341                            "(), adjusting max turn time from %d to 500 ms\n",
342                            qos->max_turn_time.value);
343                 qos->max_turn_time.value = 500;
344         }
345         
346         /*
347          * The data size must be adjusted according to the baud rate and max 
348          * turn time
349          */
350         index = value_index(qos->data_size.value, data_sizes, 6);
351         line_capacity = irlap_max_line_capacity(qos->baud_rate.value, 
352                                                 qos->max_turn_time.value);
353
354 #ifdef CONFIG_IRDA_DYNAMIC_WINDOW
355         while ((qos->data_size.value > line_capacity) && (index > 0)) {
356                 qos->data_size.value = data_sizes[index--];
357                 IRDA_DEBUG(2, __FUNCTION__ 
358                            "(), redusing data size to %d\n",
359                            qos->data_size.value);
360         }
361 #else /* Use method descibed in section 6.6.11 of IrLAP */
362         while (irlap_requested_line_capacity(qos) > line_capacity) {
363                 ASSERT(index != 0, return;);
364
365                 /* Must be able to send at least one frame */
366                 if (qos->window_size.value > 1) {
367                         qos->window_size.value--;
368                         IRDA_DEBUG(2, __FUNCTION__ 
369                                    "(), redusing window size to %d\n",
370                                    qos->window_size.value);
371                 } else if (index > 1) {
372                         qos->data_size.value = data_sizes[index--];
373                         IRDA_DEBUG(2, __FUNCTION__ 
374                                    "(), redusing data size to %d\n",
375                                    qos->data_size.value);
376                 } else {
377                         WARNING(__FUNCTION__ "(), nothing more we can do!\n");
378                 }
379         }
380 #endif /* CONFIG_IRDA_DYNAMIC_WINDOW */
381 }
382
383 /*
384  * Function irlap_negotiate (qos_device, qos_session, skb)
385  *
386  *    Negotiate QoS values, not really that much negotiation :-)
387  *    We just set the QoS capabilities for the peer station
388  *
389  */
390 int irlap_qos_negotiate(struct irlap_cb *self, struct sk_buff *skb) 
391 {
392         int ret;
393         
394         ret = irda_param_extract_all(self, skb->data, skb->len, 
395                                      &irlap_param_info);
396         
397         /* Convert the negotiated bits to values */
398         irda_qos_bits_to_value(&self->qos_tx);
399         irda_qos_bits_to_value(&self->qos_rx);
400
401         irlap_adjust_qos_settings(&self->qos_tx);
402
403         IRDA_DEBUG(2, "Setting BAUD_RATE to %d bps.\n", 
404                    self->qos_tx.baud_rate.value);
405         IRDA_DEBUG(2, "Setting DATA_SIZE to %d bytes\n",
406                    self->qos_tx.data_size.value);
407         IRDA_DEBUG(2, "Setting WINDOW_SIZE to %d\n", 
408                    self->qos_tx.window_size.value);
409         IRDA_DEBUG(2, "Setting XBOFS to %d\n", 
410                    self->qos_tx.additional_bofs.value);
411         IRDA_DEBUG(2, "Setting MAX_TURN_TIME to %d ms.\n",
412                    self->qos_tx.max_turn_time.value);
413         IRDA_DEBUG(2, "Setting MIN_TURN_TIME to %d usecs.\n",
414                    self->qos_tx.min_turn_time.value);
415         IRDA_DEBUG(2, "Setting LINK_DISC to %d secs.\n", 
416                    self->qos_tx.link_disc_time.value);
417         return ret;
418 }
419
420 /*
421  * Function irlap_insert_negotiation_params (qos, fp)
422  *
423  *    Insert QoS negotiaion pararameters into frame
424  *
425  */
426 int irlap_insert_qos_negotiation_params(struct irlap_cb *self, 
427                                         struct sk_buff *skb)
428 {
429         int ret;
430
431         /* Insert data rate */
432         ret = irda_param_insert(self, PI_BAUD_RATE, skb->tail, 
433                                 skb_tailroom(skb), &irlap_param_info);
434         if (ret < 0)
435                 return ret;
436         skb_put(skb, ret);
437
438         /* Insert max turnaround time */
439         ret = irda_param_insert(self, PI_MAX_TURN_TIME, skb->tail, 
440                                 skb_tailroom(skb), &irlap_param_info);
441         if (ret < 0)
442                 return ret;
443         skb_put(skb, ret);
444
445         /* Insert data size */
446         ret = irda_param_insert(self, PI_DATA_SIZE, skb->tail, 
447                                 skb_tailroom(skb), &irlap_param_info);
448         if (ret < 0)
449                 return ret;
450         skb_put(skb, ret);
451
452         /* Insert window size */
453         ret = irda_param_insert(self, PI_WINDOW_SIZE, skb->tail, 
454                                 skb_tailroom(skb), &irlap_param_info);
455         if (ret < 0)
456                 return ret;
457         skb_put(skb, ret);
458
459         /* Insert additional BOFs */
460         ret = irda_param_insert(self, PI_ADD_BOFS, skb->tail, 
461                                 skb_tailroom(skb), &irlap_param_info);
462         if (ret < 0)
463                 return ret;
464         skb_put(skb, ret);
465
466         /* Insert minimum turnaround time */
467         ret = irda_param_insert(self, PI_MIN_TURN_TIME, skb->tail, 
468                                 skb_tailroom(skb), &irlap_param_info);
469         if (ret < 0)
470                 return ret;
471         skb_put(skb, ret);
472
473         /* Insert link disconnect/threshold time */
474         ret = irda_param_insert(self, PI_LINK_DISC, skb->tail, 
475                                 skb_tailroom(skb), &irlap_param_info);
476         if (ret < 0)
477                 return ret;
478         skb_put(skb, ret);
479
480         return 0;
481 }
482
483 /*
484  * Function irlap_param_baud_rate (instance, param, get)
485  *
486  *    Negotiate data-rate
487  *
488  */
489 static int irlap_param_baud_rate(void *instance, irda_param_t *param, int get)
490 {
491         __u16 final;
492
493         struct irlap_cb *self = (struct irlap_cb *) instance;
494
495         ASSERT(self != NULL, return -1;);
496         ASSERT(self->magic == LAP_MAGIC, return -1;);
497
498         if (get) {
499                 param->pv.i = self->qos_rx.baud_rate.bits;
500                 IRDA_DEBUG(2, __FUNCTION__ "(), baud rate = 0x%02x\n", 
501                            param->pv.i);                
502         } else {
503                 /* 
504                  *  Stations must agree on baud rate, so calculate
505                  *  intersection 
506                  */
507                 IRDA_DEBUG(2, "Requested BAUD_RATE: 0x%04x\n", (__u16) param->pv.i);
508                 final = (__u16) param->pv.i & self->qos_rx.baud_rate.bits;
509
510                 IRDA_DEBUG(2, "Final BAUD_RATE: 0x%04x\n", final);
511                 self->qos_tx.baud_rate.bits = final;
512                 self->qos_rx.baud_rate.bits = final;
513         }
514
515         return 0;
516 }
517
518 /*
519  * Function irlap_param_link_disconnect (instance, param, get)
520  *
521  *    Negotiate link disconnect/threshold time. 
522  *
523  */
524 static int irlap_param_link_disconnect(void *instance, irda_param_t *param, 
525                                        int get)
526 {
527         __u16 final;
528         
529         struct irlap_cb *self = (struct irlap_cb *) instance;
530         
531         ASSERT(self != NULL, return -1;);
532         ASSERT(self->magic == LAP_MAGIC, return -1;);
533         
534         if (get)
535                 param->pv.i = self->qos_rx.link_disc_time.bits;
536         else {
537                 /*  
538                  *  Stations must agree on link disconnect/threshold 
539                  *  time.
540                  */
541                 IRDA_DEBUG(2, "LINK_DISC: %02x\n", (__u8) param->pv.i);
542                 final = (__u8) param->pv.i & self->qos_rx.link_disc_time.bits;
543
544                 IRDA_DEBUG(2, "Final LINK_DISC: %02x\n", final);
545                 self->qos_tx.link_disc_time.bits = final;
546                 self->qos_rx.link_disc_time.bits = final;
547         }
548         return 0;
549 }
550
551 /*
552  * Function irlap_param_max_turn_time (instance, param, get)
553  *
554  *    Negotiate the maximum turnaround time. This is a type 1 parameter and
555  *    will be negotiated independently for each station
556  *
557  */
558 static int irlap_param_max_turn_time(void *instance, irda_param_t *param, 
559                                      int get)
560 {
561         struct irlap_cb *self = (struct irlap_cb *) instance;
562         
563         ASSERT(self != NULL, return -1;);
564         ASSERT(self->magic == LAP_MAGIC, return -1;);
565         
566         if (get)
567                 param->pv.i = self->qos_rx.max_turn_time.bits;
568         else
569                 self->qos_tx.max_turn_time.bits = (__u8) param->pv.i;
570
571         return 0;
572 }
573
574 /*
575  * Function irlap_param_data_size (instance, param, get)
576  *
577  *    Negotiate the data size. This is a type 1 parameter and
578  *    will be negotiated independently for each station
579  *
580  */
581 static int irlap_param_data_size(void *instance, irda_param_t *param, int get)
582 {
583         struct irlap_cb *self = (struct irlap_cb *) instance;
584         
585         ASSERT(self != NULL, return -1;);
586         ASSERT(self->magic == LAP_MAGIC, return -1;);
587         
588         if (get)
589                 param->pv.i = self->qos_rx.data_size.bits;
590         else
591                 self->qos_tx.data_size.bits = (__u8) param->pv.i;
592
593         return 0;
594 }
595
596 /*
597  * Function irlap_param_window_size (instance, param, get)
598  *
599  *    Negotiate the window size. This is a type 1 parameter and
600  *    will be negotiated independently for each station
601  *
602  */
603 static int irlap_param_window_size(void *instance, irda_param_t *param, 
604                                    int get)
605 {
606         struct irlap_cb *self = (struct irlap_cb *) instance;
607         
608         ASSERT(self != NULL, return -1;);
609         ASSERT(self->magic == LAP_MAGIC, return -1;);
610         
611         if (get)
612                 param->pv.i = self->qos_rx.window_size.bits;
613         else
614                 self->qos_tx.window_size.bits = (__u8) param->pv.i;
615
616         return 0;
617 }
618
619 /*
620  * Function irlap_param_additional_bofs (instance, param, get)
621  *
622  *    Negotiate additional BOF characters. This is a type 1 parameter and
623  *    will be negotiated independently for each station.
624  */
625 static int irlap_param_additional_bofs(void *instance, irda_param_t *param, int get)
626 {
627         struct irlap_cb *self = (struct irlap_cb *) instance;
628         
629         ASSERT(self != NULL, return -1;);
630         ASSERT(self->magic == LAP_MAGIC, return -1;);
631         
632         if (get)
633                 param->pv.i = self->qos_rx.additional_bofs.bits;
634         else
635                 self->qos_tx.additional_bofs.bits = (__u8) param->pv.i;
636
637         return 0;
638 }
639
640 /*
641  * Function irlap_param_min_turn_time (instance, param, get)
642  *
643  *    Negotiate the minimum turn around time. This is a type 1 parameter and
644  *    will be negotiated independently for each station
645  */
646 static int irlap_param_min_turn_time(void *instance, irda_param_t *param, 
647                                      int get)
648 {
649         struct irlap_cb *self = (struct irlap_cb *) instance;
650         
651         ASSERT(self != NULL, return -1;);
652         ASSERT(self->magic == LAP_MAGIC, return -1;);
653         
654         if (get)
655                 param->pv.i = self->qos_rx.min_turn_time.bits;
656         else
657                 self->qos_tx.min_turn_time.bits = (__u8) param->pv.i;
658
659         return 0;
660 }
661
662 /*
663  * Function irlap_max_line_capacity (speed, max_turn_time, min_turn_time)
664  *
665  *    Calculate the maximum line capacity
666  *
667  */
668 __u32 irlap_max_line_capacity(__u32 speed, __u32 max_turn_time)
669 {
670         __u32 line_capacity;
671         int i,j;
672
673         IRDA_DEBUG(2, __FUNCTION__ "(), speed=%d, max_turn_time=%d\n",
674                    speed, max_turn_time);
675
676         i = value_index(speed, baud_rates, 10);
677         j = value_index(max_turn_time, max_turn_times, 4);
678
679         ASSERT(((i >=0) && (i <=10)), return 0;);
680         ASSERT(((j >=0) && (j <=4)), return 0;);
681
682         line_capacity = max_line_capacities[i][j];
683
684         IRDA_DEBUG(2, __FUNCTION__ "(), line capacity=%d bytes\n", 
685                    line_capacity);
686         
687         return line_capacity;
688 }
689
690 __u32 irlap_requested_line_capacity(struct qos_info *qos)
691 {       __u32 line_capacity;
692         
693         line_capacity = qos->window_size.value * 
694                 (qos->data_size.value + 6 + qos->additional_bofs.value) +
695                 irlap_min_turn_time_in_bytes(qos->baud_rate.value, 
696                                              qos->min_turn_time.value);
697         
698         IRDA_DEBUG(2, __FUNCTION__ "(), requested line capacity=%d\n",
699                    line_capacity);
700         
701         return line_capacity;                                     
702 }
703
704 void irda_qos_bits_to_value(struct qos_info *qos)
705 {
706         int index;
707
708         ASSERT(qos != NULL, return;);
709         
710         index = msb_index(qos->baud_rate.bits);
711         qos->baud_rate.value = baud_rates[index];
712
713         index = msb_index(qos->data_size.bits);
714         qos->data_size.value = data_sizes[index];
715
716         index = msb_index(qos->window_size.bits);
717         qos->window_size.value = index+1;
718
719         index = msb_index(qos->min_turn_time.bits);
720         qos->min_turn_time.value = min_turn_times[index];
721         
722         index = msb_index(qos->max_turn_time.bits);
723         qos->max_turn_time.value = max_turn_times[index];
724
725         index = msb_index(qos->link_disc_time.bits);
726         qos->link_disc_time.value = link_disc_times[index];
727         
728         index = msb_index(qos->additional_bofs.bits);
729         qos->additional_bofs.value = add_bofs[index];
730 }