reservation.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * WUSB cluster reservation management
  3. *
  4. * Copyright (C) 2007 Cambridge Silicon Radio Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License version
  8. * 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/uwb.h>
  20. #include "wusbhc.h"
  21. /*
  22. * WUSB cluster reservations are multicast reservations with the
  23. * broadcast cluster ID (BCID) as the target DevAddr.
  24. *
  25. * FIXME: consider adjusting the reservation depending on what devices
  26. * are attached.
  27. */
  28. static int wusbhc_bwa_set(struct wusbhc *wusbhc, u8 stream,
  29. const struct uwb_mas_bm *mas)
  30. {
  31. if (mas == NULL)
  32. mas = &uwb_mas_bm_zero;
  33. return wusbhc->bwa_set(wusbhc, stream, mas);
  34. }
  35. /**
  36. * wusbhc_rsv_complete_cb - WUSB HC reservation complete callback
  37. * @rsv: the reservation
  38. *
  39. * Either set or clear the HC's view of the reservation.
  40. *
  41. * FIXME: when a reservation is denied the HC should be stopped.
  42. */
  43. static void wusbhc_rsv_complete_cb(struct uwb_rsv *rsv)
  44. {
  45. struct wusbhc *wusbhc = rsv->pal_priv;
  46. struct device *dev = wusbhc->dev;
  47. struct uwb_mas_bm mas;
  48. char buf[72];
  49. dev_dbg(dev, "%s: state = %d\n", __func__, rsv->state);
  50. switch (rsv->state) {
  51. case UWB_RSV_STATE_O_ESTABLISHED:
  52. uwb_rsv_get_usable_mas(rsv, &mas);
  53. bitmap_scnprintf(buf, sizeof(buf), mas.bm, UWB_NUM_MAS);
  54. dev_dbg(dev, "established reservation: %s\n", buf);
  55. wusbhc_bwa_set(wusbhc, rsv->stream, &mas);
  56. break;
  57. case UWB_RSV_STATE_NONE:
  58. dev_dbg(dev, "removed reservation\n");
  59. wusbhc_bwa_set(wusbhc, 0, NULL);
  60. break;
  61. default:
  62. dev_dbg(dev, "unexpected reservation state: %d\n", rsv->state);
  63. break;
  64. }
  65. }
  66. /**
  67. * wusbhc_rsv_establish - establish a reservation for the cluster
  68. * @wusbhc: the WUSB HC requesting a bandwidth reservation
  69. */
  70. int wusbhc_rsv_establish(struct wusbhc *wusbhc)
  71. {
  72. struct uwb_rc *rc = wusbhc->uwb_rc;
  73. struct uwb_rsv *rsv;
  74. struct uwb_dev_addr bcid;
  75. int ret;
  76. if (rc == NULL)
  77. return -ENODEV;
  78. rsv = uwb_rsv_create(rc, wusbhc_rsv_complete_cb, wusbhc);
  79. if (rsv == NULL)
  80. return -ENOMEM;
  81. bcid.data[0] = wusbhc->cluster_id;
  82. bcid.data[1] = 0;
  83. rsv->target.type = UWB_RSV_TARGET_DEVADDR;
  84. rsv->target.devaddr = bcid;
  85. rsv->type = UWB_DRP_TYPE_PRIVATE;
  86. rsv->max_mas = 256; /* try to get as much as possible */
  87. rsv->min_mas = 15; /* one MAS per zone */
  88. rsv->max_interval = 1; /* max latency is one zone */
  89. rsv->is_multicast = true;
  90. ret = uwb_rsv_establish(rsv);
  91. if (ret == 0)
  92. wusbhc->rsv = rsv;
  93. else
  94. uwb_rsv_destroy(rsv);
  95. return ret;
  96. }
  97. /**
  98. * wusbhc_rsv_terminate - terminate the cluster reservation
  99. * @wusbhc: the WUSB host whose reservation is to be terminated
  100. */
  101. void wusbhc_rsv_terminate(struct wusbhc *wusbhc)
  102. {
  103. if (wusbhc->rsv) {
  104. uwb_rsv_terminate(wusbhc->rsv);
  105. uwb_rsv_destroy(wusbhc->rsv);
  106. wusbhc->rsv = NULL;
  107. }
  108. }