exp_rcv.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause
  2. /*
  3. * Copyright(c) 2017 Intel Corporation.
  4. */
  5. #include "exp_rcv.h"
  6. #include "trace.h"
  7. /**
  8. * hfi1_exp_tid_set_init - initialize exp_tid_set
  9. * @set: the set
  10. */
  11. static void hfi1_exp_tid_set_init(struct exp_tid_set *set)
  12. {
  13. INIT_LIST_HEAD(&set->list);
  14. set->count = 0;
  15. }
  16. /**
  17. * hfi1_exp_tid_group_init - initialize rcd expected receive
  18. * @rcd: the rcd
  19. */
  20. void hfi1_exp_tid_group_init(struct hfi1_ctxtdata *rcd)
  21. {
  22. hfi1_exp_tid_set_init(&rcd->tid_group_list);
  23. hfi1_exp_tid_set_init(&rcd->tid_used_list);
  24. hfi1_exp_tid_set_init(&rcd->tid_full_list);
  25. }
  26. /**
  27. * hfi1_alloc_ctxt_rcv_groups - initialize expected receive groups
  28. * @rcd: the context to add the groupings to
  29. */
  30. int hfi1_alloc_ctxt_rcv_groups(struct hfi1_ctxtdata *rcd)
  31. {
  32. struct hfi1_devdata *dd = rcd->dd;
  33. u32 tidbase;
  34. struct tid_group *grp;
  35. int i;
  36. u32 ngroups;
  37. ngroups = rcd->expected_count / dd->rcv_entries.group_size;
  38. rcd->groups =
  39. kcalloc_node(ngroups, sizeof(*rcd->groups),
  40. GFP_KERNEL, rcd->numa_id);
  41. if (!rcd->groups)
  42. return -ENOMEM;
  43. tidbase = rcd->expected_base;
  44. for (i = 0; i < ngroups; i++) {
  45. grp = &rcd->groups[i];
  46. grp->size = dd->rcv_entries.group_size;
  47. grp->base = tidbase;
  48. tid_group_add_tail(grp, &rcd->tid_group_list);
  49. tidbase += dd->rcv_entries.group_size;
  50. }
  51. return 0;
  52. }
  53. /**
  54. * hfi1_free_ctxt_rcv_groups - free expected receive groups
  55. * @rcd: the context to free
  56. *
  57. * The routine dismantles the expect receive linked
  58. * list and clears any tids associated with the receive
  59. * context.
  60. *
  61. * This should only be called for kernel contexts and the
  62. * a base user context.
  63. */
  64. void hfi1_free_ctxt_rcv_groups(struct hfi1_ctxtdata *rcd)
  65. {
  66. kfree(rcd->groups);
  67. rcd->groups = NULL;
  68. hfi1_exp_tid_group_init(rcd);
  69. hfi1_clear_tids(rcd);
  70. }