qos.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  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 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 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 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. IRDA_WARNING("%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. IRDA_DEBUG(2, "%s()\n", __func__);
  313. /*
  314. * Make sure the mintt is sensible.
  315. * Main culprit : Ericsson T39. - Jean II
  316. */
  317. if (sysctl_min_tx_turn_time > qos->min_turn_time.value) {
  318. int i;
  319. IRDA_WARNING("%s(), Detected buggy peer, adjust mtt to %dus!\n",
  320. __func__, sysctl_min_tx_turn_time);
  321. /* We don't really need bits, but easier this way */
  322. i = value_highest_bit(sysctl_min_tx_turn_time, min_turn_times,
  323. 8, &qos->min_turn_time.bits);
  324. sysctl_min_tx_turn_time = index_value(i, min_turn_times);
  325. qos->min_turn_time.value = sysctl_min_tx_turn_time;
  326. }
  327. /*
  328. * Not allowed to use a max turn time less than 500 ms if the baudrate
  329. * is less than 115200
  330. */
  331. if ((qos->baud_rate.value < 115200) &&
  332. (qos->max_turn_time.value < 500))
  333. {
  334. IRDA_DEBUG(0,
  335. "%s(), adjusting max turn time from %d to 500 ms\n",
  336. __func__, qos->max_turn_time.value);
  337. qos->max_turn_time.value = 500;
  338. }
  339. /*
  340. * The data size must be adjusted according to the baud rate and max
  341. * turn time
  342. */
  343. index = value_index(qos->data_size.value, data_sizes, 6);
  344. line_capacity = irlap_max_line_capacity(qos->baud_rate.value,
  345. qos->max_turn_time.value);
  346. #ifdef CONFIG_IRDA_DYNAMIC_WINDOW
  347. while ((qos->data_size.value > line_capacity) && (index > 0)) {
  348. qos->data_size.value = data_sizes[index--];
  349. IRDA_DEBUG(2, "%s(), reducing data size to %d\n",
  350. __func__, qos->data_size.value);
  351. }
  352. #else /* Use method described in section 6.6.11 of IrLAP */
  353. while (irlap_requested_line_capacity(qos) > line_capacity) {
  354. IRDA_ASSERT(index != 0, return;);
  355. /* Must be able to send at least one frame */
  356. if (qos->window_size.value > 1) {
  357. qos->window_size.value--;
  358. IRDA_DEBUG(2, "%s(), reducing window size to %d\n",
  359. __func__, qos->window_size.value);
  360. } else if (index > 1) {
  361. qos->data_size.value = data_sizes[index--];
  362. IRDA_DEBUG(2, "%s(), reducing data size to %d\n",
  363. __func__, qos->data_size.value);
  364. } else {
  365. IRDA_WARNING("%s(), nothing more we can do!\n",
  366. __func__);
  367. }
  368. }
  369. #endif /* CONFIG_IRDA_DYNAMIC_WINDOW */
  370. /*
  371. * Fix tx data size according to user limits - Jean II
  372. */
  373. if (qos->data_size.value > sysctl_max_tx_data_size)
  374. /* Allow non discrete adjustement to avoid losing capacity */
  375. qos->data_size.value = sysctl_max_tx_data_size;
  376. /*
  377. * Override Tx window if user request it. - Jean II
  378. */
  379. if (qos->window_size.value > sysctl_max_tx_window)
  380. qos->window_size.value = sysctl_max_tx_window;
  381. }
  382. /*
  383. * Function irlap_negotiate (qos_device, qos_session, skb)
  384. *
  385. * Negotiate QoS values, not really that much negotiation :-)
  386. * We just set the QoS capabilities for the peer station
  387. *
  388. */
  389. int irlap_qos_negotiate(struct irlap_cb *self, struct sk_buff *skb)
  390. {
  391. int ret;
  392. ret = irda_param_extract_all(self, skb->data, skb->len,
  393. &irlap_param_info);
  394. /* Convert the negotiated bits to values */
  395. irda_qos_bits_to_value(&self->qos_tx);
  396. irda_qos_bits_to_value(&self->qos_rx);
  397. irlap_adjust_qos_settings(&self->qos_tx);
  398. IRDA_DEBUG(2, "Setting BAUD_RATE to %d bps.\n",
  399. self->qos_tx.baud_rate.value);
  400. IRDA_DEBUG(2, "Setting DATA_SIZE to %d bytes\n",
  401. self->qos_tx.data_size.value);
  402. IRDA_DEBUG(2, "Setting WINDOW_SIZE to %d\n",
  403. self->qos_tx.window_size.value);
  404. IRDA_DEBUG(2, "Setting XBOFS to %d\n",
  405. self->qos_tx.additional_bofs.value);
  406. IRDA_DEBUG(2, "Setting MAX_TURN_TIME to %d ms.\n",
  407. self->qos_tx.max_turn_time.value);
  408. IRDA_DEBUG(2, "Setting MIN_TURN_TIME to %d usecs.\n",
  409. self->qos_tx.min_turn_time.value);
  410. IRDA_DEBUG(2, "Setting LINK_DISC to %d secs.\n",
  411. self->qos_tx.link_disc_time.value);
  412. return ret;
  413. }
  414. /*
  415. * Function irlap_insert_negotiation_params (qos, fp)
  416. *
  417. * Insert QoS negotiaion pararameters into frame
  418. *
  419. */
  420. int irlap_insert_qos_negotiation_params(struct irlap_cb *self,
  421. struct sk_buff *skb)
  422. {
  423. int ret;
  424. /* Insert data rate */
  425. ret = irda_param_insert(self, PI_BAUD_RATE, skb_tail_pointer(skb),
  426. skb_tailroom(skb), &irlap_param_info);
  427. if (ret < 0)
  428. return ret;
  429. skb_put(skb, ret);
  430. /* Insert max turnaround time */
  431. ret = irda_param_insert(self, PI_MAX_TURN_TIME, skb_tail_pointer(skb),
  432. skb_tailroom(skb), &irlap_param_info);
  433. if (ret < 0)
  434. return ret;
  435. skb_put(skb, ret);
  436. /* Insert data size */
  437. ret = irda_param_insert(self, PI_DATA_SIZE, skb_tail_pointer(skb),
  438. skb_tailroom(skb), &irlap_param_info);
  439. if (ret < 0)
  440. return ret;
  441. skb_put(skb, ret);
  442. /* Insert window size */
  443. ret = irda_param_insert(self, PI_WINDOW_SIZE, skb_tail_pointer(skb),
  444. skb_tailroom(skb), &irlap_param_info);
  445. if (ret < 0)
  446. return ret;
  447. skb_put(skb, ret);
  448. /* Insert additional BOFs */
  449. ret = irda_param_insert(self, PI_ADD_BOFS, skb_tail_pointer(skb),
  450. skb_tailroom(skb), &irlap_param_info);
  451. if (ret < 0)
  452. return ret;
  453. skb_put(skb, ret);
  454. /* Insert minimum turnaround time */
  455. ret = irda_param_insert(self, PI_MIN_TURN_TIME, skb_tail_pointer(skb),
  456. skb_tailroom(skb), &irlap_param_info);
  457. if (ret < 0)
  458. return ret;
  459. skb_put(skb, ret);
  460. /* Insert link disconnect/threshold time */
  461. ret = irda_param_insert(self, PI_LINK_DISC, skb_tail_pointer(skb),
  462. skb_tailroom(skb), &irlap_param_info);
  463. if (ret < 0)
  464. return ret;
  465. skb_put(skb, ret);
  466. return 0;
  467. }
  468. /*
  469. * Function irlap_param_baud_rate (instance, param, get)
  470. *
  471. * Negotiate data-rate
  472. *
  473. */
  474. static int irlap_param_baud_rate(void *instance, irda_param_t *param, int get)
  475. {
  476. __u16 final;
  477. struct irlap_cb *self = (struct irlap_cb *) instance;
  478. IRDA_ASSERT(self != NULL, return -1;);
  479. IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
  480. if (get) {
  481. param->pv.i = self->qos_rx.baud_rate.bits;
  482. IRDA_DEBUG(2, "%s(), baud rate = 0x%02x\n",
  483. __func__, param->pv.i);
  484. } else {
  485. /*
  486. * Stations must agree on baud rate, so calculate
  487. * intersection
  488. */
  489. IRDA_DEBUG(2, "Requested BAUD_RATE: 0x%04x\n", (__u16) param->pv.i);
  490. final = (__u16) param->pv.i & self->qos_rx.baud_rate.bits;
  491. IRDA_DEBUG(2, "Final BAUD_RATE: 0x%04x\n", final);
  492. self->qos_tx.baud_rate.bits = final;
  493. self->qos_rx.baud_rate.bits = final;
  494. }
  495. return 0;
  496. }
  497. /*
  498. * Function irlap_param_link_disconnect (instance, param, get)
  499. *
  500. * Negotiate link disconnect/threshold time.
  501. *
  502. */
  503. static int irlap_param_link_disconnect(void *instance, irda_param_t *param,
  504. int get)
  505. {
  506. __u16 final;
  507. struct irlap_cb *self = (struct irlap_cb *) instance;
  508. IRDA_ASSERT(self != NULL, return -1;);
  509. IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
  510. if (get)
  511. param->pv.i = self->qos_rx.link_disc_time.bits;
  512. else {
  513. /*
  514. * Stations must agree on link disconnect/threshold
  515. * time.
  516. */
  517. IRDA_DEBUG(2, "LINK_DISC: %02x\n", (__u8) param->pv.i);
  518. final = (__u8) param->pv.i & self->qos_rx.link_disc_time.bits;
  519. IRDA_DEBUG(2, "Final LINK_DISC: %02x\n", final);
  520. self->qos_tx.link_disc_time.bits = final;
  521. self->qos_rx.link_disc_time.bits = final;
  522. }
  523. return 0;
  524. }
  525. /*
  526. * Function irlap_param_max_turn_time (instance, param, get)
  527. *
  528. * Negotiate the maximum turnaround time. This is a type 1 parameter and
  529. * will be negotiated independently for each station
  530. *
  531. */
  532. static int irlap_param_max_turn_time(void *instance, irda_param_t *param,
  533. int get)
  534. {
  535. struct irlap_cb *self = (struct irlap_cb *) instance;
  536. IRDA_ASSERT(self != NULL, return -1;);
  537. IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
  538. if (get)
  539. param->pv.i = self->qos_rx.max_turn_time.bits;
  540. else
  541. self->qos_tx.max_turn_time.bits = (__u8) param->pv.i;
  542. return 0;
  543. }
  544. /*
  545. * Function irlap_param_data_size (instance, param, get)
  546. *
  547. * Negotiate the data size. This is a type 1 parameter and
  548. * will be negotiated independently for each station
  549. *
  550. */
  551. static int irlap_param_data_size(void *instance, irda_param_t *param, int get)
  552. {
  553. struct irlap_cb *self = (struct irlap_cb *) instance;
  554. IRDA_ASSERT(self != NULL, return -1;);
  555. IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
  556. if (get)
  557. param->pv.i = self->qos_rx.data_size.bits;
  558. else
  559. self->qos_tx.data_size.bits = (__u8) param->pv.i;
  560. return 0;
  561. }
  562. /*
  563. * Function irlap_param_window_size (instance, param, get)
  564. *
  565. * Negotiate the window size. This is a type 1 parameter and
  566. * will be negotiated independently for each station
  567. *
  568. */
  569. static int irlap_param_window_size(void *instance, irda_param_t *param,
  570. int get)
  571. {
  572. struct irlap_cb *self = (struct irlap_cb *) instance;
  573. IRDA_ASSERT(self != NULL, return -1;);
  574. IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
  575. if (get)
  576. param->pv.i = self->qos_rx.window_size.bits;
  577. else
  578. self->qos_tx.window_size.bits = (__u8) param->pv.i;
  579. return 0;
  580. }
  581. /*
  582. * Function irlap_param_additional_bofs (instance, param, get)
  583. *
  584. * Negotiate additional BOF characters. This is a type 1 parameter and
  585. * will be negotiated independently for each station.
  586. */
  587. static int irlap_param_additional_bofs(void *instance, irda_param_t *param, int get)
  588. {
  589. struct irlap_cb *self = (struct irlap_cb *) instance;
  590. IRDA_ASSERT(self != NULL, return -1;);
  591. IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
  592. if (get)
  593. param->pv.i = self->qos_rx.additional_bofs.bits;
  594. else
  595. self->qos_tx.additional_bofs.bits = (__u8) param->pv.i;
  596. return 0;
  597. }
  598. /*
  599. * Function irlap_param_min_turn_time (instance, param, get)
  600. *
  601. * Negotiate the minimum turn around time. This is a type 1 parameter and
  602. * will be negotiated independently for each station
  603. */
  604. static int irlap_param_min_turn_time(void *instance, irda_param_t *param,
  605. int get)
  606. {
  607. struct irlap_cb *self = (struct irlap_cb *) instance;
  608. IRDA_ASSERT(self != NULL, return -1;);
  609. IRDA_ASSERT(self->magic == LAP_MAGIC, return -1;);
  610. if (get)
  611. param->pv.i = self->qos_rx.min_turn_time.bits;
  612. else
  613. self->qos_tx.min_turn_time.bits = (__u8) param->pv.i;
  614. return 0;
  615. }
  616. /*
  617. * Function irlap_max_line_capacity (speed, max_turn_time, min_turn_time)
  618. *
  619. * Calculate the maximum line capacity
  620. *
  621. */
  622. __u32 irlap_max_line_capacity(__u32 speed, __u32 max_turn_time)
  623. {
  624. __u32 line_capacity;
  625. int i,j;
  626. IRDA_DEBUG(2, "%s(), speed=%d, max_turn_time=%d\n",
  627. __func__, speed, max_turn_time);
  628. i = value_index(speed, baud_rates, 10);
  629. j = value_index(max_turn_time, max_turn_times, 4);
  630. IRDA_ASSERT(((i >=0) && (i <10)), return 0;);
  631. IRDA_ASSERT(((j >=0) && (j <4)), return 0;);
  632. line_capacity = max_line_capacities[i][j];
  633. IRDA_DEBUG(2, "%s(), line capacity=%d bytes\n",
  634. __func__, line_capacity);
  635. return line_capacity;
  636. }
  637. #ifndef CONFIG_IRDA_DYNAMIC_WINDOW
  638. static __u32 irlap_requested_line_capacity(struct qos_info *qos)
  639. {
  640. __u32 line_capacity;
  641. line_capacity = qos->window_size.value *
  642. (qos->data_size.value + 6 + qos->additional_bofs.value) +
  643. irlap_min_turn_time_in_bytes(qos->baud_rate.value,
  644. qos->min_turn_time.value);
  645. IRDA_DEBUG(2, "%s(), requested line capacity=%d\n",
  646. __func__, line_capacity);
  647. return line_capacity;
  648. }
  649. #endif
  650. void irda_qos_bits_to_value(struct qos_info *qos)
  651. {
  652. int index;
  653. IRDA_ASSERT(qos != NULL, return;);
  654. index = msb_index(qos->baud_rate.bits);
  655. qos->baud_rate.value = baud_rates[index];
  656. index = msb_index(qos->data_size.bits);
  657. qos->data_size.value = data_sizes[index];
  658. index = msb_index(qos->window_size.bits);
  659. qos->window_size.value = index+1;
  660. index = msb_index(qos->min_turn_time.bits);
  661. qos->min_turn_time.value = min_turn_times[index];
  662. index = msb_index(qos->max_turn_time.bits);
  663. qos->max_turn_time.value = max_turn_times[index];
  664. index = msb_index(qos->link_disc_time.bits);
  665. qos->link_disc_time.value = link_disc_times[index];
  666. index = msb_index(qos->additional_bofs.bits);
  667. qos->additional_bofs.value = add_bofs[index];
  668. }
  669. EXPORT_SYMBOL(irda_qos_bits_to_value);