qos.c 22 KB

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