qos.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  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, see <http://www.gnu.org/licenses/>.
  28. *
  29. ********************************************************************/
  30. #include <linux/export.h>
  31. #include <asm/byteorder.h>
  32. #include <net/irda/irda.h>
  33. #include <net/irda/parameters.h>
  34. #include <net/irda/qos.h>
  35. #include <net/irda/irlap.h>
  36. #include <net/irda/irlap_frame.h>
  37. /*
  38. * Maximum values of the baud rate we negotiate with the other end.
  39. * Most often, you don't have to change that, because Linux-IrDA will
  40. * use the maximum offered by the link layer, which usually works fine.
  41. * In some very rare cases, you may want to limit it to lower speeds...
  42. */
  43. int sysctl_max_baud_rate = 16000000;
  44. /*
  45. * Maximum value of the lap disconnect timer we negotiate with the other end.
  46. * Most often, the value below represent the best compromise, but some user
  47. * may want to keep the LAP alive longer or shorter in case of link failure.
  48. * Remember that the threshold time (early warning) is fixed to 3s...
  49. */
  50. int sysctl_max_noreply_time = 12;
  51. /*
  52. * Minimum turn time to be applied before transmitting to the peer.
  53. * Nonzero values (usec) are used as lower limit to the per-connection
  54. * mtt value which was announced by the other end during negotiation.
  55. * Might be helpful if the peer device provides too short mtt.
  56. * Default is 10us which means using the unmodified value given by the
  57. * peer except if it's 0 (0 is likely a bug in the other stack).
  58. */
  59. unsigned int sysctl_min_tx_turn_time = 10;
  60. /*
  61. * Maximum data size to be used in transmission in payload of LAP frame.
  62. * There is a bit of confusion in the IrDA spec :
  63. * The LAP spec defines the payload of a LAP frame (I field) to be
  64. * 2048 bytes max (IrLAP 1.1, chapt 6.6.5, p40).
  65. * On the other hand, the PHY mention frames of 2048 bytes max (IrPHY
  66. * 1.2, chapt 5.3.2.1, p41). But, this number includes the LAP header
  67. * (2 bytes), and CRC (32 bits at 4 Mb/s). So, for the I field (LAP
  68. * payload), that's only 2042 bytes. Oups !
  69. * My nsc-ircc hardware has troubles receiving 2048 bytes frames at 4 Mb/s,
  70. * so adjust to 2042... I don't know if this bug applies only for 2048
  71. * bytes frames or all negotiated frame sizes, but you can use the sysctl
  72. * to play with this value anyway.
  73. * Jean II */
  74. unsigned int sysctl_max_tx_data_size = 2042;
  75. /*
  76. * Maximum transmit window, i.e. number of LAP frames between turn-around.
  77. * This allow to override what the peer told us. Some peers are buggy and
  78. * don't always support what they tell us.
  79. * Jean II */
  80. unsigned int sysctl_max_tx_window = 7;
  81. static int irlap_param_baud_rate(void *instance, irda_param_t *param, int get);
  82. static int irlap_param_link_disconnect(void *instance, irda_param_t *parm,
  83. int get);
  84. static int irlap_param_max_turn_time(void *instance, irda_param_t *param,
  85. int get);
  86. static int irlap_param_data_size(void *instance, irda_param_t *param, int get);
  87. static int irlap_param_window_size(void *instance, irda_param_t *param,
  88. int get);
  89. static int irlap_param_additional_bofs(void *instance, irda_param_t *parm,
  90. int get);
  91. static int irlap_param_min_turn_time(void *instance, irda_param_t *param,
  92. int get);
  93. #ifndef CONFIG_IRDA_DYNAMIC_WINDOW
  94. static __u32 irlap_requested_line_capacity(struct qos_info *qos);
  95. #endif
  96. static __u32 min_turn_times[] = { 10000, 5000, 1000, 500, 100, 50, 10, 0 }; /* us */
  97. static __u32 baud_rates[] = { 2400, 9600, 19200, 38400, 57600, 115200, 576000,
  98. 1152000, 4000000, 16000000 }; /* bps */
  99. static __u32 data_sizes[] = { 64, 128, 256, 512, 1024, 2048 }; /* bytes */
  100. static __u32 add_bofs[] = { 48, 24, 12, 5, 3, 2, 1, 0 }; /* bytes */
  101. static __u32 max_turn_times[] = { 500, 250, 100, 50 }; /* ms */
  102. static __u32 link_disc_times[] = { 3, 8, 12, 16, 20, 25, 30, 40 }; /* secs */
  103. static __u32 max_line_capacities[10][4] = {
  104. /* 500 ms 250 ms 100 ms 50 ms (max turn time) */
  105. { 100, 0, 0, 0 }, /* 2400 bps */
  106. { 400, 0, 0, 0 }, /* 9600 bps */
  107. { 800, 0, 0, 0 }, /* 19200 bps */
  108. { 1600, 0, 0, 0 }, /* 38400 bps */
  109. { 2360, 0, 0, 0 }, /* 57600 bps */
  110. { 4800, 2400, 960, 480 }, /* 115200 bps */
  111. { 28800, 11520, 5760, 2880 }, /* 576000 bps */
  112. { 57600, 28800, 11520, 5760 }, /* 1152000 bps */
  113. { 200000, 100000, 40000, 20000 }, /* 4000000 bps */
  114. { 800000, 400000, 160000, 80000 }, /* 16000000 bps */
  115. };
  116. static const pi_minor_info_t pi_minor_call_table_type_0[] = {
  117. { NULL, 0 },
  118. /* 01 */{ irlap_param_baud_rate, PV_INTEGER | PV_LITTLE_ENDIAN },
  119. { NULL, 0 },
  120. { NULL, 0 },
  121. { NULL, 0 },
  122. { NULL, 0 },
  123. { NULL, 0 },
  124. { NULL, 0 },
  125. /* 08 */{ irlap_param_link_disconnect, PV_INT_8_BITS }
  126. };
  127. static const pi_minor_info_t pi_minor_call_table_type_1[] = {
  128. { NULL, 0 },
  129. { NULL, 0 },
  130. /* 82 */{ irlap_param_max_turn_time, PV_INT_8_BITS },
  131. /* 83 */{ irlap_param_data_size, PV_INT_8_BITS },
  132. /* 84 */{ irlap_param_window_size, PV_INT_8_BITS },
  133. /* 85 */{ irlap_param_additional_bofs, PV_INT_8_BITS },
  134. /* 86 */{ irlap_param_min_turn_time, PV_INT_8_BITS },
  135. };
  136. static const pi_major_info_t pi_major_call_table[] = {
  137. { pi_minor_call_table_type_0, 9 },
  138. { pi_minor_call_table_type_1, 7 },
  139. };
  140. static pi_param_info_t irlap_param_info = { pi_major_call_table, 2, 0x7f, 7 };
  141. /* ---------------------- LOCAL SUBROUTINES ---------------------- */
  142. /* Note : we start with a bunch of local subroutines.
  143. * As the compiler is "one pass", this is the only way to get them to
  144. * inline properly...
  145. * Jean II
  146. */
  147. /*
  148. * Function value_index (value, array, size)
  149. *
  150. * Returns the index to the value in the specified array
  151. */
  152. static inline int value_index(__u32 value, __u32 *array, int size)
  153. {
  154. int i;
  155. for (i=0; i < size; i++)
  156. if (array[i] == value)
  157. break;
  158. return i;
  159. }
  160. /*
  161. * Function index_value (index, array)
  162. *
  163. * Returns value to index in array, easy!
  164. *
  165. */
  166. static inline __u32 index_value(int index, __u32 *array)
  167. {
  168. return array[index];
  169. }
  170. /*
  171. * Function msb_index (word)
  172. *
  173. * Returns index to most significant bit (MSB) in word
  174. *
  175. */
  176. static int msb_index (__u16 word)
  177. {
  178. __u16 msb = 0x8000;
  179. int index = 15; /* Current MSB */
  180. /* Check for buggy peers.
  181. * Note : there is a small probability that it could be us, but I
  182. * would expect driver authors to catch that pretty early and be
  183. * able to check precisely what's going on. If a end user sees this,
  184. * it's very likely the peer. - Jean II */
  185. if (word == 0) {
  186. net_warn_ratelimited("%s(), Detected buggy peer, adjust null PV to 0x1!\n",
  187. __func__);
  188. /* The only safe choice (we don't know the array size) */
  189. word = 0x1;
  190. }
  191. while (msb) {
  192. if (word & msb)
  193. break; /* Found it! */
  194. msb >>=1;
  195. index--;
  196. }
  197. return index;
  198. }
  199. /*
  200. * Function value_lower_bits (value, array)
  201. *
  202. * Returns a bit field marking all possibility lower than value.
  203. */
  204. static inline int value_lower_bits(__u32 value, __u32 *array, int size, __u16 *field)
  205. {
  206. int i;
  207. __u16 mask = 0x1;
  208. __u16 result = 0x0;
  209. for (i=0; i < size; i++) {
  210. /* Add the current value to the bit field, shift mask */
  211. result |= mask;
  212. mask <<= 1;
  213. /* Finished ? */
  214. if (array[i] >= value)
  215. break;
  216. }
  217. /* Send back a valid index */
  218. if(i >= size)
  219. i = size - 1; /* Last item */
  220. *field = result;
  221. return i;
  222. }
  223. /*
  224. * Function value_highest_bit (value, array)
  225. *
  226. * Returns a bit field marking the highest possibility lower than value.
  227. */
  228. static inline int value_highest_bit(__u32 value, __u32 *array, int size, __u16 *field)
  229. {
  230. int i;
  231. __u16 mask = 0x1;
  232. __u16 result = 0x0;
  233. for (i=0; i < size; i++) {
  234. /* Finished ? */
  235. if (array[i] <= value)
  236. break;
  237. /* Shift mask */
  238. mask <<= 1;
  239. }
  240. /* Set the current value to the bit field */
  241. result |= mask;
  242. /* Send back a valid index */
  243. if(i >= size)
  244. i = size - 1; /* Last item */
  245. *field = result;
  246. return i;
  247. }
  248. /* -------------------------- MAIN CALLS -------------------------- */
  249. /*
  250. * Function irda_qos_compute_intersection (qos, new)
  251. *
  252. * Compute the intersection of the old QoS capabilities with new ones
  253. *
  254. */
  255. void irda_qos_compute_intersection(struct qos_info *qos, struct qos_info *new)
  256. {
  257. IRDA_ASSERT(qos != NULL, return;);
  258. IRDA_ASSERT(new != NULL, return;);
  259. /* Apply */
  260. qos->baud_rate.bits &= new->baud_rate.bits;
  261. qos->window_size.bits &= new->window_size.bits;
  262. qos->min_turn_time.bits &= new->min_turn_time.bits;
  263. qos->max_turn_time.bits &= new->max_turn_time.bits;
  264. qos->data_size.bits &= new->data_size.bits;
  265. qos->link_disc_time.bits &= new->link_disc_time.bits;
  266. qos->additional_bofs.bits &= new->additional_bofs.bits;
  267. irda_qos_bits_to_value(qos);
  268. }
  269. /*
  270. * Function irda_init_max_qos_capabilies (qos)
  271. *
  272. * The purpose of this function is for layers and drivers to be able to
  273. * set the maximum QoS possible and then "and in" their own limitations
  274. *
  275. */
  276. void irda_init_max_qos_capabilies(struct qos_info *qos)
  277. {
  278. int i;
  279. /*
  280. * These are the maximum supported values as specified on pages
  281. * 39-43 in IrLAP
  282. */
  283. /* Use sysctl to set some configurable values... */
  284. /* Set configured max speed */
  285. i = value_lower_bits(sysctl_max_baud_rate, baud_rates, 10,
  286. &qos->baud_rate.bits);
  287. sysctl_max_baud_rate = index_value(i, baud_rates);
  288. /* Set configured max disc time */
  289. i = value_lower_bits(sysctl_max_noreply_time, link_disc_times, 8,
  290. &qos->link_disc_time.bits);
  291. sysctl_max_noreply_time = index_value(i, link_disc_times);
  292. /* LSB is first byte, MSB is second byte */
  293. qos->baud_rate.bits &= 0x03ff;
  294. qos->window_size.bits = 0x7f;
  295. qos->min_turn_time.bits = 0xff;
  296. qos->max_turn_time.bits = 0x0f;
  297. qos->data_size.bits = 0x3f;
  298. qos->link_disc_time.bits &= 0xff;
  299. qos->additional_bofs.bits = 0xff;
  300. }
  301. EXPORT_SYMBOL(irda_init_max_qos_capabilies);
  302. /*
  303. * Function irlap_adjust_qos_settings (qos)
  304. *
  305. * Adjust QoS settings in case some values are not possible to use because
  306. * of other settings
  307. */
  308. static void irlap_adjust_qos_settings(struct qos_info *qos)
  309. {
  310. __u32 line_capacity;
  311. int index;
  312. /*
  313. * Make sure the mintt is sensible.
  314. * Main culprit : Ericsson T39. - Jean II
  315. */
  316. if (sysctl_min_tx_turn_time > qos->min_turn_time.value) {
  317. int i;
  318. net_warn_ratelimited("%s(), Detected buggy peer, adjust mtt to %dus!\n",
  319. __func__, sysctl_min_tx_turn_time);
  320. /* We don't really need bits, but easier this way */
  321. i = value_highest_bit(sysctl_min_tx_turn_time, min_turn_times,
  322. 8, &qos->min_turn_time.bits);
  323. sysctl_min_tx_turn_time = index_value(i, min_turn_times);
  324. qos->min_turn_time.value = sysctl_min_tx_turn_time;
  325. }
  326. /*
  327. * Not allowed to use a max turn time less than 500 ms if the baudrate
  328. * is less than 115200
  329. */
  330. if ((qos->baud_rate.value < 115200) &&
  331. (qos->max_turn_time.value < 500))
  332. {
  333. pr_debug("%s(), adjusting max turn time from %d to 500 ms\n",
  334. __func__, qos->max_turn_time.value);
  335. qos->max_turn_time.value = 500;
  336. }
  337. /*
  338. * The data size must be adjusted according to the baud rate and max
  339. * turn time
  340. */
  341. index = value_index(qos->data_size.value, data_sizes, 6);
  342. line_capacity = irlap_max_line_capacity(qos->baud_rate.value,
  343. qos->max_turn_time.value);
  344. #ifdef CONFIG_IRDA_DYNAMIC_WINDOW
  345. while ((qos->data_size.value > line_capacity) && (index > 0)) {
  346. qos->data_size.value = data_sizes[index--];
  347. pr_debug("%s(), reducing data size to %d\n",
  348. __func__, qos->data_size.value);
  349. }
  350. #else /* Use method described in section 6.6.11 of IrLAP */
  351. while (irlap_requested_line_capacity(qos) > line_capacity) {
  352. IRDA_ASSERT(index != 0, return;);
  353. /* Must be able to send at least one frame */
  354. if (qos->window_size.value > 1) {
  355. qos->window_size.value--;
  356. pr_debug("%s(), reducing window size to %d\n",
  357. __func__, qos->window_size.value);
  358. } else if (index > 1) {
  359. qos->data_size.value = data_sizes[index--];
  360. pr_debug("%s(), reducing data size to %d\n",
  361. __func__, qos->data_size.value);
  362. } else {
  363. net_warn_ratelimited("%s(), nothing more we can do!\n",
  364. __func__);
  365. }
  366. }
  367. #endif /* CONFIG_IRDA_DYNAMIC_WINDOW */
  368. /*
  369. * Fix tx data size according to user limits - Jean II
  370. */
  371. if (qos->data_size.value > sysctl_max_tx_data_size)
  372. /* Allow non discrete adjustement to avoid losing capacity */
  373. qos->data_size.value = sysctl_max_tx_data_size;
  374. /*
  375. * Override Tx window if user request it. - Jean II
  376. */
  377. if (qos->window_size.value > sysctl_max_tx_window)
  378. qos->window_size.value = sysctl_max_tx_window;
  379. }
  380. /*
  381. * Function irlap_negotiate (qos_device, qos_session, skb)
  382. *
  383. * Negotiate QoS values, not really that much negotiation :-)
  384. * We just set the QoS capabilities for the peer station
  385. *
  386. */
  387. int irlap_qos_negotiate(struct irlap_cb *self, struct sk_buff *skb)
  388. {
  389. int ret;
  390. ret = irda_param_extract_all(self, skb->data, skb->len,
  391. &irlap_param_info);
  392. /* Convert the negotiated bits to values */
  393. irda_qos_bits_to_value(&self->qos_tx);
  394. irda_qos_bits_to_value(&self->qos_rx);
  395. irlap_adjust_qos_settings(&self->qos_tx);
  396. pr_debug("Setting BAUD_RATE to %d bps.\n",
  397. self->qos_tx.baud_rate.value);
  398. pr_debug("Setting DATA_SIZE to %d bytes\n",
  399. self->qos_tx.data_size.value);
  400. pr_debug("Setting WINDOW_SIZE to %d\n",
  401. self->qos_tx.window_size.value);
  402. pr_debug("Setting XBOFS to %d\n",
  403. self->qos_tx.additional_bofs.value);
  404. pr_debug("Setting MAX_TURN_TIME to %d ms.\n",
  405. self->qos_tx.max_turn_time.value);
  406. pr_debug("Setting MIN_TURN_TIME to %d usecs.\n",
  407. self->qos_tx.min_turn_time.value);
  408. pr_debug("Setting LINK_DISC to %d secs.\n",
  409. self->qos_tx.link_disc_time.value);
  410. return ret;
  411. }
  412. /*
  413. * Function irlap_insert_negotiation_params (qos, fp)
  414. *
  415. * Insert QoS negotiaion pararameters into frame
  416. *
  417. */
  418. int irlap_insert_qos_negotiation_params(struct irlap_cb *self,
  419. struct sk_buff *skb)
  420. {
  421. int ret;
  422. /* Insert data rate */
  423. ret = irda_param_insert(self, PI_BAUD_RATE, skb_tail_pointer(skb),
  424. skb_tailroom(skb), &irlap_param_info);
  425. if (ret < 0)
  426. return ret;
  427. skb_put(skb, ret);
  428. /* Insert max turnaround time */
  429. ret = irda_param_insert(self, PI_MAX_TURN_TIME, skb_tail_pointer(skb),
  430. skb_tailroom(skb), &irlap_param_info);
  431. if (ret < 0)
  432. return ret;
  433. skb_put(skb, ret);
  434. /* Insert data size */
  435. ret = irda_param_insert(self, PI_DATA_SIZE, skb_tail_pointer(skb),
  436. skb_tailroom(skb), &irlap_param_info);
  437. if (ret < 0)
  438. return ret;
  439. skb_put(skb, ret);
  440. /* Insert window size */
  441. ret = irda_param_insert(self, PI_WINDOW_SIZE, skb_tail_pointer(skb),
  442. skb_tailroom(skb), &irlap_param_info);
  443. if (ret < 0)
  444. return ret;
  445. skb_put(skb, ret);
  446. /* Insert additional BOFs */
  447. ret = irda_param_insert(self, PI_ADD_BOFS, skb_tail_pointer(skb),
  448. skb_tailroom(skb), &irlap_param_info);
  449. if (ret < 0)
  450. return ret;
  451. skb_put(skb, ret);
  452. /* Insert minimum turnaround time */
  453. ret = irda_param_insert(self, PI_MIN_TURN_TIME, skb_tail_pointer(skb),
  454. skb_tailroom(skb), &irlap_param_info);
  455. if (ret < 0)
  456. return ret;
  457. skb_put(skb, ret);
  458. /* Insert link disconnect/threshold time */
  459. ret = irda_param_insert(self, PI_LINK_DISC, skb_tail_pointer(skb),
  460. skb_tailroom(skb), &irlap_param_info);
  461. if (ret < 0)
  462. return ret;
  463. skb_put(skb, ret);
  464. return 0;
  465. }
  466. /*
  467. * Function irlap_param_baud_rate (instance, param, get)
  468. *
  469. * Negotiate data-rate
  470. *
  471. */
  472. static int irlap_param_baud_rate(void *instance, irda_param_t *param, int get)
  473. {
  474. __u16 final;
  475. struct irlap_cb *self = (struct irlap_cb *) instance;
  476. IRDA_ASSERT(self != NULL, return -1;);
  477. IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
  478. if (get) {
  479. param->pv.i = self->qos_rx.baud_rate.bits;
  480. pr_debug("%s(), baud rate = 0x%02x\n",
  481. __func__, param->pv.i);
  482. } else {
  483. /*
  484. * Stations must agree on baud rate, so calculate
  485. * intersection
  486. */
  487. pr_debug("Requested BAUD_RATE: 0x%04x\n", (__u16)param->pv.i);
  488. final = (__u16) param->pv.i & self->qos_rx.baud_rate.bits;
  489. pr_debug("Final BAUD_RATE: 0x%04x\n", final);
  490. self->qos_tx.baud_rate.bits = final;
  491. self->qos_rx.baud_rate.bits = final;
  492. }
  493. return 0;
  494. }
  495. /*
  496. * Function irlap_param_link_disconnect (instance, param, get)
  497. *
  498. * Negotiate link disconnect/threshold time.
  499. *
  500. */
  501. static int irlap_param_link_disconnect(void *instance, irda_param_t *param,
  502. int get)
  503. {
  504. __u16 final;
  505. struct irlap_cb *self = (struct irlap_cb *) instance;
  506. IRDA_ASSERT(self != NULL, return -1;);
  507. IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
  508. if (get)
  509. param->pv.i = self->qos_rx.link_disc_time.bits;
  510. else {
  511. /*
  512. * Stations must agree on link disconnect/threshold
  513. * time.
  514. */
  515. pr_debug("LINK_DISC: %02x\n", (__u8)param->pv.i);
  516. final = (__u8) param->pv.i & self->qos_rx.link_disc_time.bits;
  517. pr_debug("Final LINK_DISC: %02x\n", final);
  518. self->qos_tx.link_disc_time.bits = final;
  519. self->qos_rx.link_disc_time.bits = final;
  520. }
  521. return 0;
  522. }
  523. /*
  524. * Function irlap_param_max_turn_time (instance, param, get)
  525. *
  526. * Negotiate the maximum turnaround time. This is a type 1 parameter and
  527. * will be negotiated independently for each station
  528. *
  529. */
  530. static int irlap_param_max_turn_time(void *instance, irda_param_t *param,
  531. int get)
  532. {
  533. struct irlap_cb *self = (struct irlap_cb *) instance;
  534. IRDA_ASSERT(self != NULL, return -1;);
  535. IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
  536. if (get)
  537. param->pv.i = self->qos_rx.max_turn_time.bits;
  538. else
  539. self->qos_tx.max_turn_time.bits = (__u8) param->pv.i;
  540. return 0;
  541. }
  542. /*
  543. * Function irlap_param_data_size (instance, param, get)
  544. *
  545. * Negotiate the data size. This is a type 1 parameter and
  546. * will be negotiated independently for each station
  547. *
  548. */
  549. static int irlap_param_data_size(void *instance, irda_param_t *param, int get)
  550. {
  551. struct irlap_cb *self = (struct irlap_cb *) instance;
  552. IRDA_ASSERT(self != NULL, return -1;);
  553. IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
  554. if (get)
  555. param->pv.i = self->qos_rx.data_size.bits;
  556. else
  557. self->qos_tx.data_size.bits = (__u8) param->pv.i;
  558. return 0;
  559. }
  560. /*
  561. * Function irlap_param_window_size (instance, param, get)
  562. *
  563. * Negotiate the window size. This is a type 1 parameter and
  564. * will be negotiated independently for each station
  565. *
  566. */
  567. static int irlap_param_window_size(void *instance, irda_param_t *param,
  568. int get)
  569. {
  570. struct irlap_cb *self = (struct irlap_cb *) instance;
  571. IRDA_ASSERT(self != NULL, return -1;);
  572. IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
  573. if (get)
  574. param->pv.i = self->qos_rx.window_size.bits;
  575. else
  576. self->qos_tx.window_size.bits = (__u8) param->pv.i;
  577. return 0;
  578. }
  579. /*
  580. * Function irlap_param_additional_bofs (instance, param, get)
  581. *
  582. * Negotiate additional BOF characters. This is a type 1 parameter and
  583. * will be negotiated independently for each station.
  584. */
  585. static int irlap_param_additional_bofs(void *instance, irda_param_t *param, int get)
  586. {
  587. struct irlap_cb *self = (struct irlap_cb *) instance;
  588. IRDA_ASSERT(self != NULL, return -1;);
  589. IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
  590. if (get)
  591. param->pv.i = self->qos_rx.additional_bofs.bits;
  592. else
  593. self->qos_tx.additional_bofs.bits = (__u8) param->pv.i;
  594. return 0;
  595. }
  596. /*
  597. * Function irlap_param_min_turn_time (instance, param, get)
  598. *
  599. * Negotiate the minimum turn around time. This is a type 1 parameter and
  600. * will be negotiated independently for each station
  601. */
  602. static int irlap_param_min_turn_time(void *instance, irda_param_t *param,
  603. int get)
  604. {
  605. struct irlap_cb *self = (struct irlap_cb *) instance;
  606. IRDA_ASSERT(self != NULL, return -1;);
  607. IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
  608. if (get)
  609. param->pv.i = self->qos_rx.min_turn_time.bits;
  610. else
  611. self->qos_tx.min_turn_time.bits = (__u8) param->pv.i;
  612. return 0;
  613. }
  614. /*
  615. * Function irlap_max_line_capacity (speed, max_turn_time, min_turn_time)
  616. *
  617. * Calculate the maximum line capacity
  618. *
  619. */
  620. __u32 irlap_max_line_capacity(__u32 speed, __u32 max_turn_time)
  621. {
  622. __u32 line_capacity;
  623. int i,j;
  624. pr_debug("%s(), speed=%d, max_turn_time=%d\n",
  625. __func__, speed, max_turn_time);
  626. i = value_index(speed, baud_rates, 10);
  627. j = value_index(max_turn_time, max_turn_times, 4);
  628. IRDA_ASSERT(((i >=0) && (i <10)), return 0;);
  629. IRDA_ASSERT(((j >=0) && (j <4)), return 0;);
  630. line_capacity = max_line_capacities[i][j];
  631. pr_debug("%s(), line capacity=%d bytes\n",
  632. __func__, line_capacity);
  633. return line_capacity;
  634. }
  635. #ifndef CONFIG_IRDA_DYNAMIC_WINDOW
  636. static __u32 irlap_requested_line_capacity(struct qos_info *qos)
  637. {
  638. __u32 line_capacity;
  639. line_capacity = qos->window_size.value *
  640. (qos->data_size.value + 6 + qos->additional_bofs.value) +
  641. irlap_min_turn_time_in_bytes(qos->baud_rate.value,
  642. qos->min_turn_time.value);
  643. pr_debug("%s(), requested line capacity=%d\n",
  644. __func__, line_capacity);
  645. return line_capacity;
  646. }
  647. #endif
  648. void irda_qos_bits_to_value(struct qos_info *qos)
  649. {
  650. int index;
  651. IRDA_ASSERT(qos != NULL, return;);
  652. index = msb_index(qos->baud_rate.bits);
  653. qos->baud_rate.value = baud_rates[index];
  654. index = msb_index(qos->data_size.bits);
  655. qos->data_size.value = data_sizes[index];
  656. index = msb_index(qos->window_size.bits);
  657. qos->window_size.value = index+1;
  658. index = msb_index(qos->min_turn_time.bits);
  659. qos->min_turn_time.value = min_turn_times[index];
  660. index = msb_index(qos->max_turn_time.bits);
  661. qos->max_turn_time.value = max_turn_times[index];
  662. index = msb_index(qos->link_disc_time.bits);
  663. qos->link_disc_time.value = link_disc_times[index];
  664. index = msb_index(qos->additional_bofs.bits);
  665. qos->additional_bofs.value = add_bofs[index];
  666. }
  667. EXPORT_SYMBOL(irda_qos_bits_to_value);