Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause
0002 /*
0003  * Copyright(c) 2017 Intel Corporation.
0004  */
0005 
0006 #include "exp_rcv.h"
0007 #include "trace.h"
0008 
0009 /**
0010  * hfi1_exp_tid_set_init - initialize exp_tid_set
0011  * @set: the set
0012  */
0013 static void hfi1_exp_tid_set_init(struct exp_tid_set *set)
0014 {
0015     INIT_LIST_HEAD(&set->list);
0016     set->count = 0;
0017 }
0018 
0019 /**
0020  * hfi1_exp_tid_group_init - initialize rcd expected receive
0021  * @rcd: the rcd
0022  */
0023 void hfi1_exp_tid_group_init(struct hfi1_ctxtdata *rcd)
0024 {
0025     hfi1_exp_tid_set_init(&rcd->tid_group_list);
0026     hfi1_exp_tid_set_init(&rcd->tid_used_list);
0027     hfi1_exp_tid_set_init(&rcd->tid_full_list);
0028 }
0029 
0030 /**
0031  * hfi1_alloc_ctxt_rcv_groups - initialize expected receive groups
0032  * @rcd: the context to add the groupings to
0033  */
0034 int hfi1_alloc_ctxt_rcv_groups(struct hfi1_ctxtdata *rcd)
0035 {
0036     struct hfi1_devdata *dd = rcd->dd;
0037     u32 tidbase;
0038     struct tid_group *grp;
0039     int i;
0040     u32 ngroups;
0041 
0042     ngroups = rcd->expected_count / dd->rcv_entries.group_size;
0043     rcd->groups =
0044         kcalloc_node(ngroups, sizeof(*rcd->groups),
0045                  GFP_KERNEL, rcd->numa_id);
0046     if (!rcd->groups)
0047         return -ENOMEM;
0048     tidbase = rcd->expected_base;
0049     for (i = 0; i < ngroups; i++) {
0050         grp = &rcd->groups[i];
0051         grp->size = dd->rcv_entries.group_size;
0052         grp->base = tidbase;
0053         tid_group_add_tail(grp, &rcd->tid_group_list);
0054         tidbase += dd->rcv_entries.group_size;
0055     }
0056 
0057     return 0;
0058 }
0059 
0060 /**
0061  * hfi1_free_ctxt_rcv_groups - free  expected receive groups
0062  * @rcd: the context to free
0063  *
0064  * The routine dismantles the expect receive linked
0065  * list and clears any tids associated with the receive
0066  * context.
0067  *
0068  * This should only be called for kernel contexts and the
0069  * a base user context.
0070  */
0071 void hfi1_free_ctxt_rcv_groups(struct hfi1_ctxtdata *rcd)
0072 {
0073     kfree(rcd->groups);
0074     rcd->groups = NULL;
0075     hfi1_exp_tid_group_init(rcd);
0076 
0077     hfi1_clear_tids(rcd);
0078 }