Linux v2.6.17-rc2
[linux-2.6/next.git] / net / irda / qos.c
blobddfb5c502a90468fcc25651080708fd287bfdee5
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>
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>
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.
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.
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
31 ********************************************************************/
33 #include <linux/config.h>
34 #include <asm/byteorder.h>
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 #include <net/irda/irlap_frame.h>
43 * Maximum values of the baud rate we negociate with the other end.
44 * Most often, you don't have to change that, because Linux-IrDA will
45 * use the maximum offered by the link layer, which usually works fine.
46 * In some very rare cases, you may want to limit it to lower speeds...
48 int sysctl_max_baud_rate = 16000000;
50 * Maximum value of the lap disconnect timer we negociate with the other end.
51 * Most often, the value below represent the best compromise, but some user
52 * may want to keep the LAP alive longuer or shorter in case of link failure.
53 * Remember that the threshold time (early warning) is fixed to 3s...
55 int sysctl_max_noreply_time = 12;
57 * Minimum turn time to be applied before transmitting to the peer.
58 * Nonzero values (usec) are used as lower limit to the per-connection
59 * mtt value which was announced by the other end during negotiation.
60 * Might be helpful if the peer device provides too short mtt.
61 * Default is 10us which means using the unmodified value given by the
62 * peer except if it's 0 (0 is likely a bug in the other stack).
64 unsigned sysctl_min_tx_turn_time = 10;
66 * Maximum data size to be used in transmission in payload of LAP frame.
67 * There is a bit of confusion in the IrDA spec :
68 * The LAP spec defines the payload of a LAP frame (I field) to be
69 * 2048 bytes max (IrLAP 1.1, chapt 6.6.5, p40).
70 * On the other hand, the PHY mention frames of 2048 bytes max (IrPHY
71 * 1.2, chapt 5.3.2.1, p41). But, this number includes the LAP header
72 * (2 bytes), and CRC (32 bits at 4 Mb/s). So, for the I field (LAP
73 * payload), that's only 2042 bytes. Oups !
74 * My nsc-ircc hardware has troubles receiving 2048 bytes frames at 4 Mb/s,
75 * so adjust to 2042... I don't know if this bug applies only for 2048
76 * bytes frames or all negotiated frame sizes, but you can use the sysctl
77 * to play with this value anyway.
78 * Jean II */
79 unsigned sysctl_max_tx_data_size = 2042;
81 * Maximum transmit window, i.e. number of LAP frames between turn-around.
82 * This allow to override what the peer told us. Some peers are buggy and
83 * don't always support what they tell us.
84 * Jean II */
85 unsigned sysctl_max_tx_window = 7;
87 static int irlap_param_baud_rate(void *instance, irda_param_t *param, int get);
88 static int irlap_param_link_disconnect(void *instance, irda_param_t *parm,
89 int get);
90 static int irlap_param_max_turn_time(void *instance, irda_param_t *param,
91 int get);
92 static int irlap_param_data_size(void *instance, irda_param_t *param, int get);
93 static int irlap_param_window_size(void *instance, irda_param_t *param,
94 int get);
95 static int irlap_param_additional_bofs(void *instance, irda_param_t *parm,
96 int get);
97 static int irlap_param_min_turn_time(void *instance, irda_param_t *param,
98 int get);
100 #ifndef CONFIG_IRDA_DYNAMIC_WINDOW
101 static __u32 irlap_requested_line_capacity(struct qos_info *qos);
102 #endif
104 static __u32 min_turn_times[] = { 10000, 5000, 1000, 500, 100, 50, 10, 0 }; /* us */
105 static __u32 baud_rates[] = { 2400, 9600, 19200, 38400, 57600, 115200, 576000,
106 1152000, 4000000, 16000000 }; /* bps */
107 static __u32 data_sizes[] = { 64, 128, 256, 512, 1024, 2048 }; /* bytes */
108 static __u32 add_bofs[] = { 48, 24, 12, 5, 3, 2, 1, 0 }; /* bytes */
109 static __u32 max_turn_times[] = { 500, 250, 100, 50 }; /* ms */
110 static __u32 link_disc_times[] = { 3, 8, 12, 16, 20, 25, 30, 40 }; /* secs */
112 static __u32 max_line_capacities[10][4] = {
113 /* 500 ms 250 ms 100 ms 50 ms (max turn time) */
114 { 100, 0, 0, 0 }, /* 2400 bps */
115 { 400, 0, 0, 0 }, /* 9600 bps */
116 { 800, 0, 0, 0 }, /* 19200 bps */
117 { 1600, 0, 0, 0 }, /* 38400 bps */
118 { 2360, 0, 0, 0 }, /* 57600 bps */
119 { 4800, 2400, 960, 480 }, /* 115200 bps */
120 { 28800, 11520, 5760, 2880 }, /* 576000 bps */
121 { 57600, 28800, 11520, 5760 }, /* 1152000 bps */
122 { 200000, 100000, 40000, 20000 }, /* 4000000 bps */
123 { 800000, 400000, 160000, 80000 }, /* 16000000 bps */
126 static pi_minor_info_t pi_minor_call_table_type_0[] = {
127 { NULL, 0 },
128 /* 01 */{ irlap_param_baud_rate, PV_INTEGER | PV_LITTLE_ENDIAN },
129 { NULL, 0 },
130 { NULL, 0 },
131 { NULL, 0 },
132 { NULL, 0 },
133 { NULL, 0 },
134 { NULL, 0 },
135 /* 08 */{ irlap_param_link_disconnect, PV_INT_8_BITS }
138 static pi_minor_info_t pi_minor_call_table_type_1[] = {
139 { NULL, 0 },
140 { NULL, 0 },
141 /* 82 */{ irlap_param_max_turn_time, PV_INT_8_BITS },
142 /* 83 */{ irlap_param_data_size, PV_INT_8_BITS },
143 /* 84 */{ irlap_param_window_size, PV_INT_8_BITS },
144 /* 85 */{ irlap_param_additional_bofs, PV_INT_8_BITS },
145 /* 86 */{ irlap_param_min_turn_time, PV_INT_8_BITS },
148 static pi_major_info_t pi_major_call_table[] = {
149 { pi_minor_call_table_type_0, 9 },
150 { pi_minor_call_table_type_1, 7 },
153 static pi_param_info_t irlap_param_info = { pi_major_call_table, 2, 0x7f, 7 };
155 /* ---------------------- LOCAL SUBROUTINES ---------------------- */
156 /* Note : we start with a bunch of local subroutines.
157 * As the compiler is "one pass", this is the only way to get them to
158 * inline properly...
159 * Jean II
162 * Function value_index (value, array, size)
164 * Returns the index to the value in the specified array
166 static inline int value_index(__u32 value, __u32 *array, int size)
168 int i;
170 for (i=0; i < size; i++)
171 if (array[i] == value)
172 break;
173 return i;
177 * Function index_value (index, array)
179 * Returns value to index in array, easy!
182 static inline __u32 index_value(int index, __u32 *array)
184 return array[index];
188 * Function msb_index (word)
190 * Returns index to most significant bit (MSB) in word
193 static int msb_index (__u16 word)
195 __u16 msb = 0x8000;
196 int index = 15; /* Current MSB */
198 /* Check for buggy peers.
199 * Note : there is a small probability that it could be us, but I
200 * would expect driver authors to catch that pretty early and be
201 * able to check precisely what's going on. If a end user sees this,
202 * it's very likely the peer. - Jean II */
203 if (word == 0) {
204 IRDA_WARNING("%s(), Detected buggy peer, adjust null PV to 0x1!\n",
205 __FUNCTION__);
206 /* The only safe choice (we don't know the array size) */
207 word = 0x1;
210 while (msb) {
211 if (word & msb)
212 break; /* Found it! */
213 msb >>=1;
214 index--;
216 return index;
220 * Function value_lower_bits (value, array)
222 * Returns a bit field marking all possibility lower than value.
224 static inline int value_lower_bits(__u32 value, __u32 *array, int size, __u16 *field)
226 int i;
227 __u16 mask = 0x1;
228 __u16 result = 0x0;
230 for (i=0; i < size; i++) {
231 /* Add the current value to the bit field, shift mask */
232 result |= mask;
233 mask <<= 1;
234 /* Finished ? */
235 if (array[i] >= value)
236 break;
238 /* Send back a valid index */
239 if(i >= size)
240 i = size - 1; /* Last item */
241 *field = result;
242 return i;
246 * Function value_highest_bit (value, array)
248 * Returns a bit field marking the highest possibility lower than value.
250 static inline int value_highest_bit(__u32 value, __u32 *array, int size, __u16 *field)
252 int i;
253 __u16 mask = 0x1;
254 __u16 result = 0x0;
256 for (i=0; i < size; i++) {
257 /* Finished ? */
258 if (array[i] <= value)
259 break;
260 /* Shift mask */
261 mask <<= 1;
263 /* Set the current value to the bit field */
264 result |= mask;
265 /* Send back a valid index */
266 if(i >= size)
267 i = size - 1; /* Last item */
268 *field = result;
269 return i;
272 /* -------------------------- MAIN CALLS -------------------------- */
275 * Function irda_qos_compute_intersection (qos, new)
277 * Compute the intersection of the old QoS capabilities with new ones
280 void irda_qos_compute_intersection(struct qos_info *qos, struct qos_info *new)
282 IRDA_ASSERT(qos != NULL, return;);
283 IRDA_ASSERT(new != NULL, return;);
285 /* Apply */
286 qos->baud_rate.bits &= new->baud_rate.bits;
287 qos->window_size.bits &= new->window_size.bits;
288 qos->min_turn_time.bits &= new->min_turn_time.bits;
289 qos->max_turn_time.bits &= new->max_turn_time.bits;
290 qos->data_size.bits &= new->data_size.bits;
291 qos->link_disc_time.bits &= new->link_disc_time.bits;
292 qos->additional_bofs.bits &= new->additional_bofs.bits;
294 irda_qos_bits_to_value(qos);
298 * Function irda_init_max_qos_capabilies (qos)
300 * The purpose of this function is for layers and drivers to be able to
301 * set the maximum QoS possible and then "and in" their own limitations
304 void irda_init_max_qos_capabilies(struct qos_info *qos)
306 int i;
308 * These are the maximum supported values as specified on pages
309 * 39-43 in IrLAP
312 /* Use sysctl to set some configurable values... */
313 /* Set configured max speed */
314 i = value_lower_bits(sysctl_max_baud_rate, baud_rates, 10,
315 &qos->baud_rate.bits);
316 sysctl_max_baud_rate = index_value(i, baud_rates);
318 /* Set configured max disc time */
319 i = value_lower_bits(sysctl_max_noreply_time, link_disc_times, 8,
320 &qos->link_disc_time.bits);
321 sysctl_max_noreply_time = index_value(i, link_disc_times);
323 /* LSB is first byte, MSB is second byte */
324 qos->baud_rate.bits &= 0x03ff;
326 qos->window_size.bits = 0x7f;
327 qos->min_turn_time.bits = 0xff;
328 qos->max_turn_time.bits = 0x0f;
329 qos->data_size.bits = 0x3f;
330 qos->link_disc_time.bits &= 0xff;
331 qos->additional_bofs.bits = 0xff;
333 EXPORT_SYMBOL(irda_init_max_qos_capabilies);
336 * Function irlap_adjust_qos_settings (qos)
338 * Adjust QoS settings in case some values are not possible to use because
339 * of other settings
341 static void irlap_adjust_qos_settings(struct qos_info *qos)
343 __u32 line_capacity;
344 int index;
346 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
349 * Make sure the mintt is sensible.
350 * Main culprit : Ericsson T39. - Jean II
352 if (sysctl_min_tx_turn_time > qos->min_turn_time.value) {
353 int i;
355 IRDA_WARNING("%s(), Detected buggy peer, adjust mtt to %dus!\n",
356 __FUNCTION__, sysctl_min_tx_turn_time);
358 /* We don't really need bits, but easier this way */
359 i = value_highest_bit(sysctl_min_tx_turn_time, min_turn_times,
360 8, &qos->min_turn_time.bits);
361 sysctl_min_tx_turn_time = index_value(i, min_turn_times);
362 qos->min_turn_time.value = sysctl_min_tx_turn_time;
366 * Not allowed to use a max turn time less than 500 ms if the baudrate
367 * is less than 115200
369 if ((qos->baud_rate.value < 115200) &&
370 (qos->max_turn_time.value < 500))
372 IRDA_DEBUG(0,
373 "%s(), adjusting max turn time from %d to 500 ms\n",
374 __FUNCTION__, qos->max_turn_time.value);
375 qos->max_turn_time.value = 500;
379 * The data size must be adjusted according to the baud rate and max
380 * turn time
382 index = value_index(qos->data_size.value, data_sizes, 6);
383 line_capacity = irlap_max_line_capacity(qos->baud_rate.value,
384 qos->max_turn_time.value);
386 #ifdef CONFIG_IRDA_DYNAMIC_WINDOW
387 while ((qos->data_size.value > line_capacity) && (index > 0)) {
388 qos->data_size.value = data_sizes[index--];
389 IRDA_DEBUG(2, "%s(), reducing data size to %d\n",
390 __FUNCTION__, qos->data_size.value);
392 #else /* Use method described in section 6.6.11 of IrLAP */
393 while (irlap_requested_line_capacity(qos) > line_capacity) {
394 IRDA_ASSERT(index != 0, return;);
396 /* Must be able to send at least one frame */
397 if (qos->window_size.value > 1) {
398 qos->window_size.value--;
399 IRDA_DEBUG(2, "%s(), reducing window size to %d\n",
400 __FUNCTION__, qos->window_size.value);
401 } else if (index > 1) {
402 qos->data_size.value = data_sizes[index--];
403 IRDA_DEBUG(2, "%s(), reducing data size to %d\n",
404 __FUNCTION__, qos->data_size.value);
405 } else {
406 IRDA_WARNING("%s(), nothing more we can do!\n",
407 __FUNCTION__);
410 #endif /* CONFIG_IRDA_DYNAMIC_WINDOW */
412 * Fix tx data size according to user limits - Jean II
414 if (qos->data_size.value > sysctl_max_tx_data_size)
415 /* Allow non discrete adjustement to avoid loosing capacity */
416 qos->data_size.value = sysctl_max_tx_data_size;
418 * Override Tx window if user request it. - Jean II
420 if (qos->window_size.value > sysctl_max_tx_window)
421 qos->window_size.value = sysctl_max_tx_window;
425 * Function irlap_negotiate (qos_device, qos_session, skb)
427 * Negotiate QoS values, not really that much negotiation :-)
428 * We just set the QoS capabilities for the peer station
431 int irlap_qos_negotiate(struct irlap_cb *self, struct sk_buff *skb)
433 int ret;
435 ret = irda_param_extract_all(self, skb->data, skb->len,
436 &irlap_param_info);
438 /* Convert the negotiated bits to values */
439 irda_qos_bits_to_value(&self->qos_tx);
440 irda_qos_bits_to_value(&self->qos_rx);
442 irlap_adjust_qos_settings(&self->qos_tx);
444 IRDA_DEBUG(2, "Setting BAUD_RATE to %d bps.\n",
445 self->qos_tx.baud_rate.value);
446 IRDA_DEBUG(2, "Setting DATA_SIZE to %d bytes\n",
447 self->qos_tx.data_size.value);
448 IRDA_DEBUG(2, "Setting WINDOW_SIZE to %d\n",
449 self->qos_tx.window_size.value);
450 IRDA_DEBUG(2, "Setting XBOFS to %d\n",
451 self->qos_tx.additional_bofs.value);
452 IRDA_DEBUG(2, "Setting MAX_TURN_TIME to %d ms.\n",
453 self->qos_tx.max_turn_time.value);
454 IRDA_DEBUG(2, "Setting MIN_TURN_TIME to %d usecs.\n",
455 self->qos_tx.min_turn_time.value);
456 IRDA_DEBUG(2, "Setting LINK_DISC to %d secs.\n",
457 self->qos_tx.link_disc_time.value);
458 return ret;
462 * Function irlap_insert_negotiation_params (qos, fp)
464 * Insert QoS negotiaion pararameters into frame
467 int irlap_insert_qos_negotiation_params(struct irlap_cb *self,
468 struct sk_buff *skb)
470 int ret;
472 /* Insert data rate */
473 ret = irda_param_insert(self, PI_BAUD_RATE, skb->tail,
474 skb_tailroom(skb), &irlap_param_info);
475 if (ret < 0)
476 return ret;
477 skb_put(skb, ret);
479 /* Insert max turnaround time */
480 ret = irda_param_insert(self, PI_MAX_TURN_TIME, skb->tail,
481 skb_tailroom(skb), &irlap_param_info);
482 if (ret < 0)
483 return ret;
484 skb_put(skb, ret);
486 /* Insert data size */
487 ret = irda_param_insert(self, PI_DATA_SIZE, skb->tail,
488 skb_tailroom(skb), &irlap_param_info);
489 if (ret < 0)
490 return ret;
491 skb_put(skb, ret);
493 /* Insert window size */
494 ret = irda_param_insert(self, PI_WINDOW_SIZE, skb->tail,
495 skb_tailroom(skb), &irlap_param_info);
496 if (ret < 0)
497 return ret;
498 skb_put(skb, ret);
500 /* Insert additional BOFs */
501 ret = irda_param_insert(self, PI_ADD_BOFS, skb->tail,
502 skb_tailroom(skb), &irlap_param_info);
503 if (ret < 0)
504 return ret;
505 skb_put(skb, ret);
507 /* Insert minimum turnaround time */
508 ret = irda_param_insert(self, PI_MIN_TURN_TIME, skb->tail,
509 skb_tailroom(skb), &irlap_param_info);
510 if (ret < 0)
511 return ret;
512 skb_put(skb, ret);
514 /* Insert link disconnect/threshold time */
515 ret = irda_param_insert(self, PI_LINK_DISC, skb->tail,
516 skb_tailroom(skb), &irlap_param_info);
517 if (ret < 0)
518 return ret;
519 skb_put(skb, ret);
521 return 0;
525 * Function irlap_param_baud_rate (instance, param, get)
527 * Negotiate data-rate
530 static int irlap_param_baud_rate(void *instance, irda_param_t *param, int get)
532 __u16 final;
534 struct irlap_cb *self = (struct irlap_cb *) instance;
536 IRDA_ASSERT(self != NULL, return -1;);
537 IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
539 if (get) {
540 param->pv.i = self->qos_rx.baud_rate.bits;
541 IRDA_DEBUG(2, "%s(), baud rate = 0x%02x\n",
542 __FUNCTION__, param->pv.i);
543 } else {
545 * Stations must agree on baud rate, so calculate
546 * intersection
548 IRDA_DEBUG(2, "Requested BAUD_RATE: 0x%04x\n", (__u16) param->pv.i);
549 final = (__u16) param->pv.i & self->qos_rx.baud_rate.bits;
551 IRDA_DEBUG(2, "Final BAUD_RATE: 0x%04x\n", final);
552 self->qos_tx.baud_rate.bits = final;
553 self->qos_rx.baud_rate.bits = final;
556 return 0;
560 * Function irlap_param_link_disconnect (instance, param, get)
562 * Negotiate link disconnect/threshold time.
565 static int irlap_param_link_disconnect(void *instance, irda_param_t *param,
566 int get)
568 __u16 final;
570 struct irlap_cb *self = (struct irlap_cb *) instance;
572 IRDA_ASSERT(self != NULL, return -1;);
573 IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
575 if (get)
576 param->pv.i = self->qos_rx.link_disc_time.bits;
577 else {
579 * Stations must agree on link disconnect/threshold
580 * time.
582 IRDA_DEBUG(2, "LINK_DISC: %02x\n", (__u8) param->pv.i);
583 final = (__u8) param->pv.i & self->qos_rx.link_disc_time.bits;
585 IRDA_DEBUG(2, "Final LINK_DISC: %02x\n", final);
586 self->qos_tx.link_disc_time.bits = final;
587 self->qos_rx.link_disc_time.bits = final;
589 return 0;
593 * Function irlap_param_max_turn_time (instance, param, get)
595 * Negotiate the maximum turnaround time. This is a type 1 parameter and
596 * will be negotiated independently for each station
599 static int irlap_param_max_turn_time(void *instance, irda_param_t *param,
600 int get)
602 struct irlap_cb *self = (struct irlap_cb *) instance;
604 IRDA_ASSERT(self != NULL, return -1;);
605 IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
607 if (get)
608 param->pv.i = self->qos_rx.max_turn_time.bits;
609 else
610 self->qos_tx.max_turn_time.bits = (__u8) param->pv.i;
612 return 0;
616 * Function irlap_param_data_size (instance, param, get)
618 * Negotiate the data size. This is a type 1 parameter and
619 * will be negotiated independently for each station
622 static int irlap_param_data_size(void *instance, irda_param_t *param, int get)
624 struct irlap_cb *self = (struct irlap_cb *) instance;
626 IRDA_ASSERT(self != NULL, return -1;);
627 IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
629 if (get)
630 param->pv.i = self->qos_rx.data_size.bits;
631 else
632 self->qos_tx.data_size.bits = (__u8) param->pv.i;
634 return 0;
638 * Function irlap_param_window_size (instance, param, get)
640 * Negotiate the window size. This is a type 1 parameter and
641 * will be negotiated independently for each station
644 static int irlap_param_window_size(void *instance, irda_param_t *param,
645 int get)
647 struct irlap_cb *self = (struct irlap_cb *) instance;
649 IRDA_ASSERT(self != NULL, return -1;);
650 IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
652 if (get)
653 param->pv.i = self->qos_rx.window_size.bits;
654 else
655 self->qos_tx.window_size.bits = (__u8) param->pv.i;
657 return 0;
661 * Function irlap_param_additional_bofs (instance, param, get)
663 * Negotiate additional BOF characters. This is a type 1 parameter and
664 * will be negotiated independently for each station.
666 static int irlap_param_additional_bofs(void *instance, irda_param_t *param, int get)
668 struct irlap_cb *self = (struct irlap_cb *) instance;
670 IRDA_ASSERT(self != NULL, return -1;);
671 IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
673 if (get)
674 param->pv.i = self->qos_rx.additional_bofs.bits;
675 else
676 self->qos_tx.additional_bofs.bits = (__u8) param->pv.i;
678 return 0;
682 * Function irlap_param_min_turn_time (instance, param, get)
684 * Negotiate the minimum turn around time. This is a type 1 parameter and
685 * will be negotiated independently for each station
687 static int irlap_param_min_turn_time(void *instance, irda_param_t *param,
688 int get)
690 struct irlap_cb *self = (struct irlap_cb *) instance;
692 IRDA_ASSERT(self != NULL, return -1;);
693 IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
695 if (get)
696 param->pv.i = self->qos_rx.min_turn_time.bits;
697 else
698 self->qos_tx.min_turn_time.bits = (__u8) param->pv.i;
700 return 0;
704 * Function irlap_max_line_capacity (speed, max_turn_time, min_turn_time)
706 * Calculate the maximum line capacity
709 __u32 irlap_max_line_capacity(__u32 speed, __u32 max_turn_time)
711 __u32 line_capacity;
712 int i,j;
714 IRDA_DEBUG(2, "%s(), speed=%d, max_turn_time=%d\n",
715 __FUNCTION__, speed, max_turn_time);
717 i = value_index(speed, baud_rates, 10);
718 j = value_index(max_turn_time, max_turn_times, 4);
720 IRDA_ASSERT(((i >=0) && (i <10)), return 0;);
721 IRDA_ASSERT(((j >=0) && (j <4)), return 0;);
723 line_capacity = max_line_capacities[i][j];
725 IRDA_DEBUG(2, "%s(), line capacity=%d bytes\n",
726 __FUNCTION__, line_capacity);
728 return line_capacity;
731 #ifndef CONFIG_IRDA_DYNAMIC_WINDOW
732 static __u32 irlap_requested_line_capacity(struct qos_info *qos)
734 __u32 line_capacity;
736 line_capacity = qos->window_size.value *
737 (qos->data_size.value + 6 + qos->additional_bofs.value) +
738 irlap_min_turn_time_in_bytes(qos->baud_rate.value,
739 qos->min_turn_time.value);
741 IRDA_DEBUG(2, "%s(), requested line capacity=%d\n",
742 __FUNCTION__, line_capacity);
744 return line_capacity;
746 #endif
748 void irda_qos_bits_to_value(struct qos_info *qos)
750 int index;
752 IRDA_ASSERT(qos != NULL, return;);
754 index = msb_index(qos->baud_rate.bits);
755 qos->baud_rate.value = baud_rates[index];
757 index = msb_index(qos->data_size.bits);
758 qos->data_size.value = data_sizes[index];
760 index = msb_index(qos->window_size.bits);
761 qos->window_size.value = index+1;
763 index = msb_index(qos->min_turn_time.bits);
764 qos->min_turn_time.value = min_turn_times[index];
766 index = msb_index(qos->max_turn_time.bits);
767 qos->max_turn_time.value = max_turn_times[index];
769 index = msb_index(qos->link_disc_time.bits);
770 qos->link_disc_time.value = link_disc_times[index];
772 index = msb_index(qos->additional_bofs.bits);
773 qos->additional_bofs.value = add_bofs[index];
775 EXPORT_SYMBOL(irda_qos_bits_to_value);