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