This source file includes following definitions.
- hns_roce_pd_alloc
- hns_roce_pd_free
- hns_roce_init_pd_table
- hns_roce_cleanup_pd_table
- hns_roce_alloc_pd
- hns_roce_dealloc_pd
- hns_roce_uar_alloc
- hns_roce_uar_free
- hns_roce_init_uar_table
- hns_roce_cleanup_uar_table
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 #include <linux/platform_device.h>
34 #include <linux/pci.h>
35 #include <uapi/rdma/hns-abi.h>
36 #include "hns_roce_device.h"
37
38 static int hns_roce_pd_alloc(struct hns_roce_dev *hr_dev, unsigned long *pdn)
39 {
40 return hns_roce_bitmap_alloc(&hr_dev->pd_bitmap, pdn) ? -ENOMEM : 0;
41 }
42
43 static void hns_roce_pd_free(struct hns_roce_dev *hr_dev, unsigned long pdn)
44 {
45 hns_roce_bitmap_free(&hr_dev->pd_bitmap, pdn, BITMAP_NO_RR);
46 }
47
48 int hns_roce_init_pd_table(struct hns_roce_dev *hr_dev)
49 {
50 return hns_roce_bitmap_init(&hr_dev->pd_bitmap, hr_dev->caps.num_pds,
51 hr_dev->caps.num_pds - 1,
52 hr_dev->caps.reserved_pds, 0);
53 }
54
55 void hns_roce_cleanup_pd_table(struct hns_roce_dev *hr_dev)
56 {
57 hns_roce_bitmap_cleanup(&hr_dev->pd_bitmap);
58 }
59
60 int hns_roce_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata)
61 {
62 struct ib_device *ib_dev = ibpd->device;
63 struct hns_roce_dev *hr_dev = to_hr_dev(ib_dev);
64 struct device *dev = hr_dev->dev;
65 struct hns_roce_pd *pd = to_hr_pd(ibpd);
66 int ret;
67
68 ret = hns_roce_pd_alloc(to_hr_dev(ib_dev), &pd->pdn);
69 if (ret) {
70 dev_err(dev, "[alloc_pd]hns_roce_pd_alloc failed!\n");
71 return ret;
72 }
73
74 if (udata) {
75 struct hns_roce_ib_alloc_pd_resp uresp = {.pdn = pd->pdn};
76
77 if (ib_copy_to_udata(udata, &uresp, sizeof(uresp))) {
78 hns_roce_pd_free(to_hr_dev(ib_dev), pd->pdn);
79 dev_err(dev, "[alloc_pd]ib_copy_to_udata failed!\n");
80 return -EFAULT;
81 }
82 }
83
84 return 0;
85 }
86
87 void hns_roce_dealloc_pd(struct ib_pd *pd, struct ib_udata *udata)
88 {
89 hns_roce_pd_free(to_hr_dev(pd->device), to_hr_pd(pd)->pdn);
90 }
91
92 int hns_roce_uar_alloc(struct hns_roce_dev *hr_dev, struct hns_roce_uar *uar)
93 {
94 struct resource *res;
95 int ret;
96
97
98 ret = hns_roce_bitmap_alloc(&hr_dev->uar_table.bitmap, &uar->logic_idx);
99 if (ret == -1)
100 return -ENOMEM;
101
102 if (uar->logic_idx > 0 && hr_dev->caps.phy_num_uars > 1)
103 uar->index = (uar->logic_idx - 1) %
104 (hr_dev->caps.phy_num_uars - 1) + 1;
105 else
106 uar->index = 0;
107
108 if (!dev_is_pci(hr_dev->dev)) {
109 res = platform_get_resource(hr_dev->pdev, IORESOURCE_MEM, 0);
110 if (!res) {
111 dev_err(&hr_dev->pdev->dev, "memory resource not found!\n");
112 return -EINVAL;
113 }
114 uar->pfn = ((res->start) >> PAGE_SHIFT) + uar->index;
115 } else {
116 uar->pfn = ((pci_resource_start(hr_dev->pci_dev, 2))
117 >> PAGE_SHIFT);
118 }
119
120 return 0;
121 }
122
123 void hns_roce_uar_free(struct hns_roce_dev *hr_dev, struct hns_roce_uar *uar)
124 {
125 hns_roce_bitmap_free(&hr_dev->uar_table.bitmap, uar->logic_idx,
126 BITMAP_NO_RR);
127 }
128
129 int hns_roce_init_uar_table(struct hns_roce_dev *hr_dev)
130 {
131 return hns_roce_bitmap_init(&hr_dev->uar_table.bitmap,
132 hr_dev->caps.num_uars,
133 hr_dev->caps.num_uars - 1,
134 hr_dev->caps.reserved_uars, 0);
135 }
136
137 void hns_roce_cleanup_uar_table(struct hns_roce_dev *hr_dev)
138 {
139 hns_roce_bitmap_cleanup(&hr_dev->uar_table.bitmap);
140 }