file_ops.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720
  1. /*
  2. * Copyright(c) 2015-2017 Intel Corporation.
  3. *
  4. * This file is provided under a dual BSD/GPLv2 license. When using or
  5. * redistributing this file, you may do so under either license.
  6. *
  7. * GPL LICENSE SUMMARY
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * BSD LICENSE
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions
  22. * are met:
  23. *
  24. * - Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. * - Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in
  28. * the documentation and/or other materials provided with the
  29. * distribution.
  30. * - Neither the name of Intel Corporation nor the names of its
  31. * contributors may be used to endorse or promote products derived
  32. * from this software without specific prior written permission.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  35. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  37. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  38. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  39. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  41. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  42. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  44. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. *
  46. */
  47. #include <linux/poll.h>
  48. #include <linux/cdev.h>
  49. #include <linux/vmalloc.h>
  50. #include <linux/io.h>
  51. #include <linux/sched/mm.h>
  52. #include <linux/bitmap.h>
  53. #include <rdma/ib.h>
  54. #include "hfi.h"
  55. #include "pio.h"
  56. #include "device.h"
  57. #include "common.h"
  58. #include "trace.h"
  59. #include "mmu_rb.h"
  60. #include "user_sdma.h"
  61. #include "user_exp_rcv.h"
  62. #include "aspm.h"
  63. #undef pr_fmt
  64. #define pr_fmt(fmt) DRIVER_NAME ": " fmt
  65. #define SEND_CTXT_HALT_TIMEOUT 1000 /* msecs */
  66. /*
  67. * File operation functions
  68. */
  69. static int hfi1_file_open(struct inode *inode, struct file *fp);
  70. static int hfi1_file_close(struct inode *inode, struct file *fp);
  71. static ssize_t hfi1_write_iter(struct kiocb *kiocb, struct iov_iter *from);
  72. static __poll_t hfi1_poll(struct file *fp, struct poll_table_struct *pt);
  73. static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma);
  74. static u64 kvirt_to_phys(void *addr);
  75. static int assign_ctxt(struct hfi1_filedata *fd, unsigned long arg, u32 len);
  76. static void init_subctxts(struct hfi1_ctxtdata *uctxt,
  77. const struct hfi1_user_info *uinfo);
  78. static int init_user_ctxt(struct hfi1_filedata *fd,
  79. struct hfi1_ctxtdata *uctxt);
  80. static void user_init(struct hfi1_ctxtdata *uctxt);
  81. static int get_ctxt_info(struct hfi1_filedata *fd, unsigned long arg, u32 len);
  82. static int get_base_info(struct hfi1_filedata *fd, unsigned long arg, u32 len);
  83. static int user_exp_rcv_setup(struct hfi1_filedata *fd, unsigned long arg,
  84. u32 len);
  85. static int user_exp_rcv_clear(struct hfi1_filedata *fd, unsigned long arg,
  86. u32 len);
  87. static int user_exp_rcv_invalid(struct hfi1_filedata *fd, unsigned long arg,
  88. u32 len);
  89. static int setup_base_ctxt(struct hfi1_filedata *fd,
  90. struct hfi1_ctxtdata *uctxt);
  91. static int setup_subctxt(struct hfi1_ctxtdata *uctxt);
  92. static int find_sub_ctxt(struct hfi1_filedata *fd,
  93. const struct hfi1_user_info *uinfo);
  94. static int allocate_ctxt(struct hfi1_filedata *fd, struct hfi1_devdata *dd,
  95. struct hfi1_user_info *uinfo,
  96. struct hfi1_ctxtdata **cd);
  97. static void deallocate_ctxt(struct hfi1_ctxtdata *uctxt);
  98. static __poll_t poll_urgent(struct file *fp, struct poll_table_struct *pt);
  99. static __poll_t poll_next(struct file *fp, struct poll_table_struct *pt);
  100. static int user_event_ack(struct hfi1_ctxtdata *uctxt, u16 subctxt,
  101. unsigned long arg);
  102. static int set_ctxt_pkey(struct hfi1_ctxtdata *uctxt, unsigned long arg);
  103. static int ctxt_reset(struct hfi1_ctxtdata *uctxt);
  104. static int manage_rcvq(struct hfi1_ctxtdata *uctxt, u16 subctxt,
  105. unsigned long arg);
  106. static vm_fault_t vma_fault(struct vm_fault *vmf);
  107. static long hfi1_file_ioctl(struct file *fp, unsigned int cmd,
  108. unsigned long arg);
  109. static const struct file_operations hfi1_file_ops = {
  110. .owner = THIS_MODULE,
  111. .write_iter = hfi1_write_iter,
  112. .open = hfi1_file_open,
  113. .release = hfi1_file_close,
  114. .unlocked_ioctl = hfi1_file_ioctl,
  115. .poll = hfi1_poll,
  116. .mmap = hfi1_file_mmap,
  117. .llseek = noop_llseek,
  118. };
  119. static const struct vm_operations_struct vm_ops = {
  120. .fault = vma_fault,
  121. };
  122. /*
  123. * Types of memories mapped into user processes' space
  124. */
  125. enum mmap_types {
  126. PIO_BUFS = 1,
  127. PIO_BUFS_SOP,
  128. PIO_CRED,
  129. RCV_HDRQ,
  130. RCV_EGRBUF,
  131. UREGS,
  132. EVENTS,
  133. STATUS,
  134. RTAIL,
  135. SUBCTXT_UREGS,
  136. SUBCTXT_RCV_HDRQ,
  137. SUBCTXT_EGRBUF,
  138. SDMA_COMP
  139. };
  140. /*
  141. * Masks and offsets defining the mmap tokens
  142. */
  143. #define HFI1_MMAP_OFFSET_MASK 0xfffULL
  144. #define HFI1_MMAP_OFFSET_SHIFT 0
  145. #define HFI1_MMAP_SUBCTXT_MASK 0xfULL
  146. #define HFI1_MMAP_SUBCTXT_SHIFT 12
  147. #define HFI1_MMAP_CTXT_MASK 0xffULL
  148. #define HFI1_MMAP_CTXT_SHIFT 16
  149. #define HFI1_MMAP_TYPE_MASK 0xfULL
  150. #define HFI1_MMAP_TYPE_SHIFT 24
  151. #define HFI1_MMAP_MAGIC_MASK 0xffffffffULL
  152. #define HFI1_MMAP_MAGIC_SHIFT 32
  153. #define HFI1_MMAP_MAGIC 0xdabbad00
  154. #define HFI1_MMAP_TOKEN_SET(field, val) \
  155. (((val) & HFI1_MMAP_##field##_MASK) << HFI1_MMAP_##field##_SHIFT)
  156. #define HFI1_MMAP_TOKEN_GET(field, token) \
  157. (((token) >> HFI1_MMAP_##field##_SHIFT) & HFI1_MMAP_##field##_MASK)
  158. #define HFI1_MMAP_TOKEN(type, ctxt, subctxt, addr) \
  159. (HFI1_MMAP_TOKEN_SET(MAGIC, HFI1_MMAP_MAGIC) | \
  160. HFI1_MMAP_TOKEN_SET(TYPE, type) | \
  161. HFI1_MMAP_TOKEN_SET(CTXT, ctxt) | \
  162. HFI1_MMAP_TOKEN_SET(SUBCTXT, subctxt) | \
  163. HFI1_MMAP_TOKEN_SET(OFFSET, (offset_in_page(addr))))
  164. #define dbg(fmt, ...) \
  165. pr_info(fmt, ##__VA_ARGS__)
  166. static inline int is_valid_mmap(u64 token)
  167. {
  168. return (HFI1_MMAP_TOKEN_GET(MAGIC, token) == HFI1_MMAP_MAGIC);
  169. }
  170. static int hfi1_file_open(struct inode *inode, struct file *fp)
  171. {
  172. struct hfi1_filedata *fd;
  173. struct hfi1_devdata *dd = container_of(inode->i_cdev,
  174. struct hfi1_devdata,
  175. user_cdev);
  176. if (!((dd->flags & HFI1_PRESENT) && dd->kregbase1))
  177. return -EINVAL;
  178. if (!atomic_inc_not_zero(&dd->user_refcount))
  179. return -ENXIO;
  180. /* The real work is performed later in assign_ctxt() */
  181. fd = kzalloc(sizeof(*fd), GFP_KERNEL);
  182. if (!fd || init_srcu_struct(&fd->pq_srcu))
  183. goto nomem;
  184. spin_lock_init(&fd->pq_rcu_lock);
  185. spin_lock_init(&fd->tid_lock);
  186. spin_lock_init(&fd->invalid_lock);
  187. fd->rec_cpu_num = -1; /* no cpu affinity by default */
  188. fd->mm = current->mm;
  189. mmgrab(fd->mm);
  190. fd->dd = dd;
  191. kobject_get(&fd->dd->kobj);
  192. fp->private_data = fd;
  193. return 0;
  194. nomem:
  195. kfree(fd);
  196. fp->private_data = NULL;
  197. if (atomic_dec_and_test(&dd->user_refcount))
  198. complete(&dd->user_comp);
  199. return -ENOMEM;
  200. }
  201. static long hfi1_file_ioctl(struct file *fp, unsigned int cmd,
  202. unsigned long arg)
  203. {
  204. struct hfi1_filedata *fd = fp->private_data;
  205. struct hfi1_ctxtdata *uctxt = fd->uctxt;
  206. int ret = 0;
  207. int uval = 0;
  208. hfi1_cdbg(IOCTL, "IOCTL recv: 0x%x", cmd);
  209. if (cmd != HFI1_IOCTL_ASSIGN_CTXT &&
  210. cmd != HFI1_IOCTL_GET_VERS &&
  211. !uctxt)
  212. return -EINVAL;
  213. switch (cmd) {
  214. case HFI1_IOCTL_ASSIGN_CTXT:
  215. ret = assign_ctxt(fd, arg, _IOC_SIZE(cmd));
  216. break;
  217. case HFI1_IOCTL_CTXT_INFO:
  218. ret = get_ctxt_info(fd, arg, _IOC_SIZE(cmd));
  219. break;
  220. case HFI1_IOCTL_USER_INFO:
  221. ret = get_base_info(fd, arg, _IOC_SIZE(cmd));
  222. break;
  223. case HFI1_IOCTL_CREDIT_UPD:
  224. if (uctxt)
  225. sc_return_credits(uctxt->sc);
  226. break;
  227. case HFI1_IOCTL_TID_UPDATE:
  228. ret = user_exp_rcv_setup(fd, arg, _IOC_SIZE(cmd));
  229. break;
  230. case HFI1_IOCTL_TID_FREE:
  231. ret = user_exp_rcv_clear(fd, arg, _IOC_SIZE(cmd));
  232. break;
  233. case HFI1_IOCTL_TID_INVAL_READ:
  234. ret = user_exp_rcv_invalid(fd, arg, _IOC_SIZE(cmd));
  235. break;
  236. case HFI1_IOCTL_RECV_CTRL:
  237. ret = manage_rcvq(uctxt, fd->subctxt, arg);
  238. break;
  239. case HFI1_IOCTL_POLL_TYPE:
  240. if (get_user(uval, (int __user *)arg))
  241. return -EFAULT;
  242. uctxt->poll_type = (typeof(uctxt->poll_type))uval;
  243. break;
  244. case HFI1_IOCTL_ACK_EVENT:
  245. ret = user_event_ack(uctxt, fd->subctxt, arg);
  246. break;
  247. case HFI1_IOCTL_SET_PKEY:
  248. ret = set_ctxt_pkey(uctxt, arg);
  249. break;
  250. case HFI1_IOCTL_CTXT_RESET:
  251. ret = ctxt_reset(uctxt);
  252. break;
  253. case HFI1_IOCTL_GET_VERS:
  254. uval = HFI1_USER_SWVERSION;
  255. if (put_user(uval, (int __user *)arg))
  256. return -EFAULT;
  257. break;
  258. default:
  259. return -EINVAL;
  260. }
  261. return ret;
  262. }
  263. static ssize_t hfi1_write_iter(struct kiocb *kiocb, struct iov_iter *from)
  264. {
  265. struct hfi1_filedata *fd = kiocb->ki_filp->private_data;
  266. struct hfi1_user_sdma_pkt_q *pq;
  267. struct hfi1_user_sdma_comp_q *cq = fd->cq;
  268. int done = 0, reqs = 0;
  269. unsigned long dim = from->nr_segs;
  270. int idx;
  271. idx = srcu_read_lock(&fd->pq_srcu);
  272. pq = srcu_dereference(fd->pq, &fd->pq_srcu);
  273. if (!cq || !pq) {
  274. srcu_read_unlock(&fd->pq_srcu, idx);
  275. return -EIO;
  276. }
  277. if (!iter_is_iovec(from) || !dim) {
  278. srcu_read_unlock(&fd->pq_srcu, idx);
  279. return -EINVAL;
  280. }
  281. trace_hfi1_sdma_request(fd->dd, fd->uctxt->ctxt, fd->subctxt, dim);
  282. if (atomic_read(&pq->n_reqs) == pq->n_max_reqs) {
  283. srcu_read_unlock(&fd->pq_srcu, idx);
  284. return -ENOSPC;
  285. }
  286. while (dim) {
  287. int ret;
  288. unsigned long count = 0;
  289. ret = hfi1_user_sdma_process_request(
  290. fd, (struct iovec *)(from->iov + done),
  291. dim, &count);
  292. if (ret) {
  293. reqs = ret;
  294. break;
  295. }
  296. dim -= count;
  297. done += count;
  298. reqs++;
  299. }
  300. srcu_read_unlock(&fd->pq_srcu, idx);
  301. return reqs;
  302. }
  303. static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)
  304. {
  305. struct hfi1_filedata *fd = fp->private_data;
  306. struct hfi1_ctxtdata *uctxt = fd->uctxt;
  307. struct hfi1_devdata *dd;
  308. unsigned long flags;
  309. u64 token = vma->vm_pgoff << PAGE_SHIFT,
  310. memaddr = 0;
  311. void *memvirt = NULL;
  312. u8 subctxt, mapio = 0, vmf = 0, type;
  313. ssize_t memlen = 0;
  314. int ret = 0;
  315. u16 ctxt;
  316. if (!is_valid_mmap(token) || !uctxt ||
  317. !(vma->vm_flags & VM_SHARED)) {
  318. ret = -EINVAL;
  319. goto done;
  320. }
  321. dd = uctxt->dd;
  322. ctxt = HFI1_MMAP_TOKEN_GET(CTXT, token);
  323. subctxt = HFI1_MMAP_TOKEN_GET(SUBCTXT, token);
  324. type = HFI1_MMAP_TOKEN_GET(TYPE, token);
  325. if (ctxt != uctxt->ctxt || subctxt != fd->subctxt) {
  326. ret = -EINVAL;
  327. goto done;
  328. }
  329. flags = vma->vm_flags;
  330. switch (type) {
  331. case PIO_BUFS:
  332. case PIO_BUFS_SOP:
  333. memaddr = ((dd->physaddr + TXE_PIO_SEND) +
  334. /* chip pio base */
  335. (uctxt->sc->hw_context * BIT(16))) +
  336. /* 64K PIO space / ctxt */
  337. (type == PIO_BUFS_SOP ?
  338. (TXE_PIO_SIZE / 2) : 0); /* sop? */
  339. /*
  340. * Map only the amount allocated to the context, not the
  341. * entire available context's PIO space.
  342. */
  343. memlen = PAGE_ALIGN(uctxt->sc->credits * PIO_BLOCK_SIZE);
  344. flags &= ~VM_MAYREAD;
  345. flags |= VM_DONTCOPY | VM_DONTEXPAND;
  346. vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
  347. mapio = 1;
  348. break;
  349. case PIO_CRED:
  350. if (flags & VM_WRITE) {
  351. ret = -EPERM;
  352. goto done;
  353. }
  354. /*
  355. * The credit return location for this context could be on the
  356. * second or third page allocated for credit returns (if number
  357. * of enabled contexts > 64 and 128 respectively).
  358. */
  359. memvirt = dd->cr_base[uctxt->numa_id].va;
  360. memaddr = virt_to_phys(memvirt) +
  361. (((u64)uctxt->sc->hw_free -
  362. (u64)dd->cr_base[uctxt->numa_id].va) & PAGE_MASK);
  363. memlen = PAGE_SIZE;
  364. flags &= ~VM_MAYWRITE;
  365. flags |= VM_DONTCOPY | VM_DONTEXPAND;
  366. /*
  367. * The driver has already allocated memory for credit
  368. * returns and programmed it into the chip. Has that
  369. * memory been flagged as non-cached?
  370. */
  371. /* vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); */
  372. mapio = 1;
  373. break;
  374. case RCV_HDRQ:
  375. memlen = rcvhdrq_size(uctxt);
  376. memvirt = uctxt->rcvhdrq;
  377. break;
  378. case RCV_EGRBUF: {
  379. unsigned long addr;
  380. int i;
  381. /*
  382. * The RcvEgr buffer need to be handled differently
  383. * as multiple non-contiguous pages need to be mapped
  384. * into the user process.
  385. */
  386. memlen = uctxt->egrbufs.size;
  387. if ((vma->vm_end - vma->vm_start) != memlen) {
  388. dd_dev_err(dd, "Eager buffer map size invalid (%lu != %lu)\n",
  389. (vma->vm_end - vma->vm_start), memlen);
  390. ret = -EINVAL;
  391. goto done;
  392. }
  393. if (vma->vm_flags & VM_WRITE) {
  394. ret = -EPERM;
  395. goto done;
  396. }
  397. vma->vm_flags &= ~VM_MAYWRITE;
  398. addr = vma->vm_start;
  399. for (i = 0 ; i < uctxt->egrbufs.numbufs; i++) {
  400. memlen = uctxt->egrbufs.buffers[i].len;
  401. memvirt = uctxt->egrbufs.buffers[i].addr;
  402. ret = remap_pfn_range(
  403. vma, addr,
  404. /*
  405. * virt_to_pfn() does the same, but
  406. * it's not available on x86_64
  407. * when CONFIG_MMU is enabled.
  408. */
  409. PFN_DOWN(__pa(memvirt)),
  410. memlen,
  411. vma->vm_page_prot);
  412. if (ret < 0)
  413. goto done;
  414. addr += memlen;
  415. }
  416. ret = 0;
  417. goto done;
  418. }
  419. case UREGS:
  420. /*
  421. * Map only the page that contains this context's user
  422. * registers.
  423. */
  424. memaddr = (unsigned long)
  425. (dd->physaddr + RXE_PER_CONTEXT_USER)
  426. + (uctxt->ctxt * RXE_PER_CONTEXT_SIZE);
  427. /*
  428. * TidFlow table is on the same page as the rest of the
  429. * user registers.
  430. */
  431. memlen = PAGE_SIZE;
  432. flags |= VM_DONTCOPY | VM_DONTEXPAND;
  433. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  434. mapio = 1;
  435. break;
  436. case EVENTS:
  437. /*
  438. * Use the page where this context's flags are. User level
  439. * knows where it's own bitmap is within the page.
  440. */
  441. memaddr = (unsigned long)
  442. (dd->events + uctxt_offset(uctxt)) & PAGE_MASK;
  443. memlen = PAGE_SIZE;
  444. /*
  445. * v3.7 removes VM_RESERVED but the effect is kept by
  446. * using VM_IO.
  447. */
  448. flags |= VM_IO | VM_DONTEXPAND;
  449. vmf = 1;
  450. break;
  451. case STATUS:
  452. if (flags & VM_WRITE) {
  453. ret = -EPERM;
  454. goto done;
  455. }
  456. memaddr = kvirt_to_phys((void *)dd->status);
  457. memlen = PAGE_SIZE;
  458. flags |= VM_IO | VM_DONTEXPAND;
  459. break;
  460. case RTAIL:
  461. if (!HFI1_CAP_IS_USET(DMA_RTAIL)) {
  462. /*
  463. * If the memory allocation failed, the context alloc
  464. * also would have failed, so we would never get here
  465. */
  466. ret = -EINVAL;
  467. goto done;
  468. }
  469. if ((flags & VM_WRITE) || !uctxt->rcvhdrtail_kvaddr) {
  470. ret = -EPERM;
  471. goto done;
  472. }
  473. memlen = PAGE_SIZE;
  474. memvirt = (void *)uctxt->rcvhdrtail_kvaddr;
  475. flags &= ~VM_MAYWRITE;
  476. break;
  477. case SUBCTXT_UREGS:
  478. memaddr = (u64)uctxt->subctxt_uregbase;
  479. memlen = PAGE_SIZE;
  480. flags |= VM_IO | VM_DONTEXPAND;
  481. vmf = 1;
  482. break;
  483. case SUBCTXT_RCV_HDRQ:
  484. memaddr = (u64)uctxt->subctxt_rcvhdr_base;
  485. memlen = rcvhdrq_size(uctxt) * uctxt->subctxt_cnt;
  486. flags |= VM_IO | VM_DONTEXPAND;
  487. vmf = 1;
  488. break;
  489. case SUBCTXT_EGRBUF:
  490. memaddr = (u64)uctxt->subctxt_rcvegrbuf;
  491. memlen = uctxt->egrbufs.size * uctxt->subctxt_cnt;
  492. flags |= VM_IO | VM_DONTEXPAND;
  493. flags &= ~VM_MAYWRITE;
  494. vmf = 1;
  495. break;
  496. case SDMA_COMP: {
  497. struct hfi1_user_sdma_comp_q *cq = fd->cq;
  498. if (!cq) {
  499. ret = -EFAULT;
  500. goto done;
  501. }
  502. memaddr = (u64)cq->comps;
  503. memlen = PAGE_ALIGN(sizeof(*cq->comps) * cq->nentries);
  504. flags |= VM_IO | VM_DONTEXPAND;
  505. vmf = 1;
  506. break;
  507. }
  508. default:
  509. ret = -EINVAL;
  510. break;
  511. }
  512. if ((vma->vm_end - vma->vm_start) != memlen) {
  513. hfi1_cdbg(PROC, "%u:%u Memory size mismatch %lu:%lu",
  514. uctxt->ctxt, fd->subctxt,
  515. (vma->vm_end - vma->vm_start), memlen);
  516. ret = -EINVAL;
  517. goto done;
  518. }
  519. vma->vm_flags = flags;
  520. hfi1_cdbg(PROC,
  521. "%u:%u type:%u io/vf:%d/%d, addr:0x%llx, len:%lu(%lu), flags:0x%lx\n",
  522. ctxt, subctxt, type, mapio, vmf, memaddr, memlen,
  523. vma->vm_end - vma->vm_start, vma->vm_flags);
  524. if (vmf) {
  525. vma->vm_pgoff = PFN_DOWN(memaddr);
  526. vma->vm_ops = &vm_ops;
  527. ret = 0;
  528. } else if (mapio) {
  529. ret = io_remap_pfn_range(vma, vma->vm_start,
  530. PFN_DOWN(memaddr),
  531. memlen,
  532. vma->vm_page_prot);
  533. } else if (memvirt) {
  534. ret = remap_pfn_range(vma, vma->vm_start,
  535. PFN_DOWN(__pa(memvirt)),
  536. memlen,
  537. vma->vm_page_prot);
  538. } else {
  539. ret = remap_pfn_range(vma, vma->vm_start,
  540. PFN_DOWN(memaddr),
  541. memlen,
  542. vma->vm_page_prot);
  543. }
  544. done:
  545. return ret;
  546. }
  547. /*
  548. * Local (non-chip) user memory is not mapped right away but as it is
  549. * accessed by the user-level code.
  550. */
  551. static vm_fault_t vma_fault(struct vm_fault *vmf)
  552. {
  553. struct page *page;
  554. page = vmalloc_to_page((void *)(vmf->pgoff << PAGE_SHIFT));
  555. if (!page)
  556. return VM_FAULT_SIGBUS;
  557. get_page(page);
  558. vmf->page = page;
  559. return 0;
  560. }
  561. static __poll_t hfi1_poll(struct file *fp, struct poll_table_struct *pt)
  562. {
  563. struct hfi1_ctxtdata *uctxt;
  564. __poll_t pollflag;
  565. uctxt = ((struct hfi1_filedata *)fp->private_data)->uctxt;
  566. if (!uctxt)
  567. pollflag = EPOLLERR;
  568. else if (uctxt->poll_type == HFI1_POLL_TYPE_URGENT)
  569. pollflag = poll_urgent(fp, pt);
  570. else if (uctxt->poll_type == HFI1_POLL_TYPE_ANYRCV)
  571. pollflag = poll_next(fp, pt);
  572. else /* invalid */
  573. pollflag = EPOLLERR;
  574. return pollflag;
  575. }
  576. static int hfi1_file_close(struct inode *inode, struct file *fp)
  577. {
  578. struct hfi1_filedata *fdata = fp->private_data;
  579. struct hfi1_ctxtdata *uctxt = fdata->uctxt;
  580. struct hfi1_devdata *dd = container_of(inode->i_cdev,
  581. struct hfi1_devdata,
  582. user_cdev);
  583. unsigned long flags, *ev;
  584. fp->private_data = NULL;
  585. if (!uctxt)
  586. goto done;
  587. hfi1_cdbg(PROC, "closing ctxt %u:%u", uctxt->ctxt, fdata->subctxt);
  588. flush_wc();
  589. /* drain user sdma queue */
  590. hfi1_user_sdma_free_queues(fdata, uctxt);
  591. /* release the cpu */
  592. hfi1_put_proc_affinity(fdata->rec_cpu_num);
  593. /* clean up rcv side */
  594. hfi1_user_exp_rcv_free(fdata);
  595. /*
  596. * fdata->uctxt is used in the above cleanup. It is not ready to be
  597. * removed until here.
  598. */
  599. fdata->uctxt = NULL;
  600. hfi1_rcd_put(uctxt);
  601. /*
  602. * Clear any left over, unhandled events so the next process that
  603. * gets this context doesn't get confused.
  604. */
  605. ev = dd->events + uctxt_offset(uctxt) + fdata->subctxt;
  606. *ev = 0;
  607. spin_lock_irqsave(&dd->uctxt_lock, flags);
  608. __clear_bit(fdata->subctxt, uctxt->in_use_ctxts);
  609. if (!bitmap_empty(uctxt->in_use_ctxts, HFI1_MAX_SHARED_CTXTS)) {
  610. spin_unlock_irqrestore(&dd->uctxt_lock, flags);
  611. goto done;
  612. }
  613. spin_unlock_irqrestore(&dd->uctxt_lock, flags);
  614. /*
  615. * Disable receive context and interrupt available, reset all
  616. * RcvCtxtCtrl bits to default values.
  617. */
  618. hfi1_rcvctrl(dd, HFI1_RCVCTRL_CTXT_DIS |
  619. HFI1_RCVCTRL_TIDFLOW_DIS |
  620. HFI1_RCVCTRL_INTRAVAIL_DIS |
  621. HFI1_RCVCTRL_TAILUPD_DIS |
  622. HFI1_RCVCTRL_ONE_PKT_EGR_DIS |
  623. HFI1_RCVCTRL_NO_RHQ_DROP_DIS |
  624. HFI1_RCVCTRL_NO_EGR_DROP_DIS, uctxt);
  625. /* Clear the context's J_KEY */
  626. hfi1_clear_ctxt_jkey(dd, uctxt);
  627. /*
  628. * If a send context is allocated, reset context integrity
  629. * checks to default and disable the send context.
  630. */
  631. if (uctxt->sc) {
  632. sc_disable(uctxt->sc);
  633. set_pio_integrity(uctxt->sc);
  634. }
  635. hfi1_free_ctxt_rcv_groups(uctxt);
  636. hfi1_clear_ctxt_pkey(dd, uctxt);
  637. uctxt->event_flags = 0;
  638. deallocate_ctxt(uctxt);
  639. done:
  640. mmdrop(fdata->mm);
  641. kobject_put(&dd->kobj);
  642. if (atomic_dec_and_test(&dd->user_refcount))
  643. complete(&dd->user_comp);
  644. cleanup_srcu_struct(&fdata->pq_srcu);
  645. kfree(fdata);
  646. return 0;
  647. }
  648. /*
  649. * Convert kernel *virtual* addresses to physical addresses.
  650. * This is used to vmalloc'ed addresses.
  651. */
  652. static u64 kvirt_to_phys(void *addr)
  653. {
  654. struct page *page;
  655. u64 paddr = 0;
  656. page = vmalloc_to_page(addr);
  657. if (page)
  658. paddr = page_to_pfn(page) << PAGE_SHIFT;
  659. return paddr;
  660. }
  661. /**
  662. * complete_subctxt
  663. * @fd: valid filedata pointer
  664. *
  665. * Sub-context info can only be set up after the base context
  666. * has been completed. This is indicated by the clearing of the
  667. * HFI1_CTXT_BASE_UINIT bit.
  668. *
  669. * Wait for the bit to be cleared, and then complete the subcontext
  670. * initialization.
  671. *
  672. */
  673. static int complete_subctxt(struct hfi1_filedata *fd)
  674. {
  675. int ret;
  676. unsigned long flags;
  677. /*
  678. * sub-context info can only be set up after the base context
  679. * has been completed.
  680. */
  681. ret = wait_event_interruptible(
  682. fd->uctxt->wait,
  683. !test_bit(HFI1_CTXT_BASE_UNINIT, &fd->uctxt->event_flags));
  684. if (test_bit(HFI1_CTXT_BASE_FAILED, &fd->uctxt->event_flags))
  685. ret = -ENOMEM;
  686. /* Finish the sub-context init */
  687. if (!ret) {
  688. fd->rec_cpu_num = hfi1_get_proc_affinity(fd->uctxt->numa_id);
  689. ret = init_user_ctxt(fd, fd->uctxt);
  690. }
  691. if (ret) {
  692. spin_lock_irqsave(&fd->dd->uctxt_lock, flags);
  693. __clear_bit(fd->subctxt, fd->uctxt->in_use_ctxts);
  694. spin_unlock_irqrestore(&fd->dd->uctxt_lock, flags);
  695. hfi1_rcd_put(fd->uctxt);
  696. fd->uctxt = NULL;
  697. }
  698. return ret;
  699. }
  700. static int assign_ctxt(struct hfi1_filedata *fd, unsigned long arg, u32 len)
  701. {
  702. int ret;
  703. unsigned int swmajor;
  704. struct hfi1_ctxtdata *uctxt = NULL;
  705. struct hfi1_user_info uinfo;
  706. if (fd->uctxt)
  707. return -EINVAL;
  708. if (sizeof(uinfo) != len)
  709. return -EINVAL;
  710. if (copy_from_user(&uinfo, (void __user *)arg, sizeof(uinfo)))
  711. return -EFAULT;
  712. swmajor = uinfo.userversion >> 16;
  713. if (swmajor != HFI1_USER_SWMAJOR)
  714. return -ENODEV;
  715. if (uinfo.subctxt_cnt > HFI1_MAX_SHARED_CTXTS)
  716. return -EINVAL;
  717. /*
  718. * Acquire the mutex to protect against multiple creations of what
  719. * could be a shared base context.
  720. */
  721. mutex_lock(&hfi1_mutex);
  722. /*
  723. * Get a sub context if available (fd->uctxt will be set).
  724. * ret < 0 error, 0 no context, 1 sub-context found
  725. */
  726. ret = find_sub_ctxt(fd, &uinfo);
  727. /*
  728. * Allocate a base context if context sharing is not required or a
  729. * sub context wasn't found.
  730. */
  731. if (!ret)
  732. ret = allocate_ctxt(fd, fd->dd, &uinfo, &uctxt);
  733. mutex_unlock(&hfi1_mutex);
  734. /* Depending on the context type, finish the appropriate init */
  735. switch (ret) {
  736. case 0:
  737. ret = setup_base_ctxt(fd, uctxt);
  738. if (ret)
  739. deallocate_ctxt(uctxt);
  740. break;
  741. case 1:
  742. ret = complete_subctxt(fd);
  743. break;
  744. default:
  745. break;
  746. }
  747. return ret;
  748. }
  749. /**
  750. * match_ctxt
  751. * @fd: valid filedata pointer
  752. * @uinfo: user info to compare base context with
  753. * @uctxt: context to compare uinfo to.
  754. *
  755. * Compare the given context with the given information to see if it
  756. * can be used for a sub context.
  757. */
  758. static int match_ctxt(struct hfi1_filedata *fd,
  759. const struct hfi1_user_info *uinfo,
  760. struct hfi1_ctxtdata *uctxt)
  761. {
  762. struct hfi1_devdata *dd = fd->dd;
  763. unsigned long flags;
  764. u16 subctxt;
  765. /* Skip dynamically allocated kernel contexts */
  766. if (uctxt->sc && (uctxt->sc->type == SC_KERNEL))
  767. return 0;
  768. /* Skip ctxt if it doesn't match the requested one */
  769. if (memcmp(uctxt->uuid, uinfo->uuid, sizeof(uctxt->uuid)) ||
  770. uctxt->jkey != generate_jkey(current_uid()) ||
  771. uctxt->subctxt_id != uinfo->subctxt_id ||
  772. uctxt->subctxt_cnt != uinfo->subctxt_cnt)
  773. return 0;
  774. /* Verify the sharing process matches the base */
  775. if (uctxt->userversion != uinfo->userversion)
  776. return -EINVAL;
  777. /* Find an unused sub context */
  778. spin_lock_irqsave(&dd->uctxt_lock, flags);
  779. if (bitmap_empty(uctxt->in_use_ctxts, HFI1_MAX_SHARED_CTXTS)) {
  780. /* context is being closed, do not use */
  781. spin_unlock_irqrestore(&dd->uctxt_lock, flags);
  782. return 0;
  783. }
  784. subctxt = find_first_zero_bit(uctxt->in_use_ctxts,
  785. HFI1_MAX_SHARED_CTXTS);
  786. if (subctxt >= uctxt->subctxt_cnt) {
  787. spin_unlock_irqrestore(&dd->uctxt_lock, flags);
  788. return -EBUSY;
  789. }
  790. fd->subctxt = subctxt;
  791. __set_bit(fd->subctxt, uctxt->in_use_ctxts);
  792. spin_unlock_irqrestore(&dd->uctxt_lock, flags);
  793. fd->uctxt = uctxt;
  794. hfi1_rcd_get(uctxt);
  795. return 1;
  796. }
  797. /**
  798. * find_sub_ctxt
  799. * @fd: valid filedata pointer
  800. * @uinfo: matching info to use to find a possible context to share.
  801. *
  802. * The hfi1_mutex must be held when this function is called. It is
  803. * necessary to ensure serialized creation of shared contexts.
  804. *
  805. * Return:
  806. * 0 No sub-context found
  807. * 1 Subcontext found and allocated
  808. * errno EINVAL (incorrect parameters)
  809. * EBUSY (all sub contexts in use)
  810. */
  811. static int find_sub_ctxt(struct hfi1_filedata *fd,
  812. const struct hfi1_user_info *uinfo)
  813. {
  814. struct hfi1_ctxtdata *uctxt;
  815. struct hfi1_devdata *dd = fd->dd;
  816. u16 i;
  817. int ret;
  818. if (!uinfo->subctxt_cnt)
  819. return 0;
  820. for (i = dd->first_dyn_alloc_ctxt; i < dd->num_rcv_contexts; i++) {
  821. uctxt = hfi1_rcd_get_by_index(dd, i);
  822. if (uctxt) {
  823. ret = match_ctxt(fd, uinfo, uctxt);
  824. hfi1_rcd_put(uctxt);
  825. /* value of != 0 will return */
  826. if (ret)
  827. return ret;
  828. }
  829. }
  830. return 0;
  831. }
  832. static int allocate_ctxt(struct hfi1_filedata *fd, struct hfi1_devdata *dd,
  833. struct hfi1_user_info *uinfo,
  834. struct hfi1_ctxtdata **rcd)
  835. {
  836. struct hfi1_ctxtdata *uctxt;
  837. int ret, numa;
  838. if (dd->flags & HFI1_FROZEN) {
  839. /*
  840. * Pick an error that is unique from all other errors
  841. * that are returned so the user process knows that
  842. * it tried to allocate while the SPC was frozen. It
  843. * it should be able to retry with success in a short
  844. * while.
  845. */
  846. return -EIO;
  847. }
  848. if (!dd->freectxts)
  849. return -EBUSY;
  850. /*
  851. * If we don't have a NUMA node requested, preference is towards
  852. * device NUMA node.
  853. */
  854. fd->rec_cpu_num = hfi1_get_proc_affinity(dd->node);
  855. if (fd->rec_cpu_num != -1)
  856. numa = cpu_to_node(fd->rec_cpu_num);
  857. else
  858. numa = numa_node_id();
  859. ret = hfi1_create_ctxtdata(dd->pport, numa, &uctxt);
  860. if (ret < 0) {
  861. dd_dev_err(dd, "user ctxtdata allocation failed\n");
  862. return ret;
  863. }
  864. hfi1_cdbg(PROC, "[%u:%u] pid %u assigned to CPU %d (NUMA %u)",
  865. uctxt->ctxt, fd->subctxt, current->pid, fd->rec_cpu_num,
  866. uctxt->numa_id);
  867. /*
  868. * Allocate and enable a PIO send context.
  869. */
  870. uctxt->sc = sc_alloc(dd, SC_USER, uctxt->rcvhdrqentsize, dd->node);
  871. if (!uctxt->sc) {
  872. ret = -ENOMEM;
  873. goto ctxdata_free;
  874. }
  875. hfi1_cdbg(PROC, "allocated send context %u(%u)\n", uctxt->sc->sw_index,
  876. uctxt->sc->hw_context);
  877. ret = sc_enable(uctxt->sc);
  878. if (ret)
  879. goto ctxdata_free;
  880. /*
  881. * Setup sub context information if the user-level has requested
  882. * sub contexts.
  883. * This has to be done here so the rest of the sub-contexts find the
  884. * proper base context.
  885. * NOTE: _set_bit() can be used here because the context creation is
  886. * protected by the mutex (rather than the spin_lock), and will be the
  887. * very first instance of this context.
  888. */
  889. __set_bit(0, uctxt->in_use_ctxts);
  890. if (uinfo->subctxt_cnt)
  891. init_subctxts(uctxt, uinfo);
  892. uctxt->userversion = uinfo->userversion;
  893. uctxt->flags = hfi1_cap_mask; /* save current flag state */
  894. init_waitqueue_head(&uctxt->wait);
  895. strlcpy(uctxt->comm, current->comm, sizeof(uctxt->comm));
  896. memcpy(uctxt->uuid, uinfo->uuid, sizeof(uctxt->uuid));
  897. uctxt->jkey = generate_jkey(current_uid());
  898. hfi1_stats.sps_ctxts++;
  899. /*
  900. * Disable ASPM when there are open user/PSM contexts to avoid
  901. * issues with ASPM L1 exit latency
  902. */
  903. if (dd->freectxts-- == dd->num_user_contexts)
  904. aspm_disable_all(dd);
  905. *rcd = uctxt;
  906. return 0;
  907. ctxdata_free:
  908. hfi1_free_ctxt(uctxt);
  909. return ret;
  910. }
  911. static void deallocate_ctxt(struct hfi1_ctxtdata *uctxt)
  912. {
  913. mutex_lock(&hfi1_mutex);
  914. hfi1_stats.sps_ctxts--;
  915. if (++uctxt->dd->freectxts == uctxt->dd->num_user_contexts)
  916. aspm_enable_all(uctxt->dd);
  917. mutex_unlock(&hfi1_mutex);
  918. hfi1_free_ctxt(uctxt);
  919. }
  920. static void init_subctxts(struct hfi1_ctxtdata *uctxt,
  921. const struct hfi1_user_info *uinfo)
  922. {
  923. uctxt->subctxt_cnt = uinfo->subctxt_cnt;
  924. uctxt->subctxt_id = uinfo->subctxt_id;
  925. set_bit(HFI1_CTXT_BASE_UNINIT, &uctxt->event_flags);
  926. }
  927. static int setup_subctxt(struct hfi1_ctxtdata *uctxt)
  928. {
  929. int ret = 0;
  930. u16 num_subctxts = uctxt->subctxt_cnt;
  931. uctxt->subctxt_uregbase = vmalloc_user(PAGE_SIZE);
  932. if (!uctxt->subctxt_uregbase)
  933. return -ENOMEM;
  934. /* We can take the size of the RcvHdr Queue from the master */
  935. uctxt->subctxt_rcvhdr_base = vmalloc_user(rcvhdrq_size(uctxt) *
  936. num_subctxts);
  937. if (!uctxt->subctxt_rcvhdr_base) {
  938. ret = -ENOMEM;
  939. goto bail_ureg;
  940. }
  941. uctxt->subctxt_rcvegrbuf = vmalloc_user(uctxt->egrbufs.size *
  942. num_subctxts);
  943. if (!uctxt->subctxt_rcvegrbuf) {
  944. ret = -ENOMEM;
  945. goto bail_rhdr;
  946. }
  947. return 0;
  948. bail_rhdr:
  949. vfree(uctxt->subctxt_rcvhdr_base);
  950. uctxt->subctxt_rcvhdr_base = NULL;
  951. bail_ureg:
  952. vfree(uctxt->subctxt_uregbase);
  953. uctxt->subctxt_uregbase = NULL;
  954. return ret;
  955. }
  956. static void user_init(struct hfi1_ctxtdata *uctxt)
  957. {
  958. unsigned int rcvctrl_ops = 0;
  959. /* initialize poll variables... */
  960. uctxt->urgent = 0;
  961. uctxt->urgent_poll = 0;
  962. /*
  963. * Now enable the ctxt for receive.
  964. * For chips that are set to DMA the tail register to memory
  965. * when they change (and when the update bit transitions from
  966. * 0 to 1. So for those chips, we turn it off and then back on.
  967. * This will (very briefly) affect any other open ctxts, but the
  968. * duration is very short, and therefore isn't an issue. We
  969. * explicitly set the in-memory tail copy to 0 beforehand, so we
  970. * don't have to wait to be sure the DMA update has happened
  971. * (chip resets head/tail to 0 on transition to enable).
  972. */
  973. if (uctxt->rcvhdrtail_kvaddr)
  974. clear_rcvhdrtail(uctxt);
  975. /* Setup J_KEY before enabling the context */
  976. hfi1_set_ctxt_jkey(uctxt->dd, uctxt, uctxt->jkey);
  977. rcvctrl_ops = HFI1_RCVCTRL_CTXT_ENB;
  978. if (HFI1_CAP_UGET_MASK(uctxt->flags, HDRSUPP))
  979. rcvctrl_ops |= HFI1_RCVCTRL_TIDFLOW_ENB;
  980. /*
  981. * Ignore the bit in the flags for now until proper
  982. * support for multiple packet per rcv array entry is
  983. * added.
  984. */
  985. if (!HFI1_CAP_UGET_MASK(uctxt->flags, MULTI_PKT_EGR))
  986. rcvctrl_ops |= HFI1_RCVCTRL_ONE_PKT_EGR_ENB;
  987. if (HFI1_CAP_UGET_MASK(uctxt->flags, NODROP_EGR_FULL))
  988. rcvctrl_ops |= HFI1_RCVCTRL_NO_EGR_DROP_ENB;
  989. if (HFI1_CAP_UGET_MASK(uctxt->flags, NODROP_RHQ_FULL))
  990. rcvctrl_ops |= HFI1_RCVCTRL_NO_RHQ_DROP_ENB;
  991. /*
  992. * The RcvCtxtCtrl.TailUpd bit has to be explicitly written.
  993. * We can't rely on the correct value to be set from prior
  994. * uses of the chip or ctxt. Therefore, add the rcvctrl op
  995. * for both cases.
  996. */
  997. if (HFI1_CAP_UGET_MASK(uctxt->flags, DMA_RTAIL))
  998. rcvctrl_ops |= HFI1_RCVCTRL_TAILUPD_ENB;
  999. else
  1000. rcvctrl_ops |= HFI1_RCVCTRL_TAILUPD_DIS;
  1001. hfi1_rcvctrl(uctxt->dd, rcvctrl_ops, uctxt);
  1002. }
  1003. static int get_ctxt_info(struct hfi1_filedata *fd, unsigned long arg, u32 len)
  1004. {
  1005. struct hfi1_ctxt_info cinfo;
  1006. struct hfi1_ctxtdata *uctxt = fd->uctxt;
  1007. if (sizeof(cinfo) != len)
  1008. return -EINVAL;
  1009. memset(&cinfo, 0, sizeof(cinfo));
  1010. cinfo.runtime_flags = (((uctxt->flags >> HFI1_CAP_MISC_SHIFT) &
  1011. HFI1_CAP_MISC_MASK) << HFI1_CAP_USER_SHIFT) |
  1012. HFI1_CAP_UGET_MASK(uctxt->flags, MASK) |
  1013. HFI1_CAP_KGET_MASK(uctxt->flags, K2U);
  1014. /* adjust flag if this fd is not able to cache */
  1015. if (!fd->handler)
  1016. cinfo.runtime_flags |= HFI1_CAP_TID_UNMAP; /* no caching */
  1017. cinfo.num_active = hfi1_count_active_units();
  1018. cinfo.unit = uctxt->dd->unit;
  1019. cinfo.ctxt = uctxt->ctxt;
  1020. cinfo.subctxt = fd->subctxt;
  1021. cinfo.rcvtids = roundup(uctxt->egrbufs.alloced,
  1022. uctxt->dd->rcv_entries.group_size) +
  1023. uctxt->expected_count;
  1024. cinfo.credits = uctxt->sc->credits;
  1025. cinfo.numa_node = uctxt->numa_id;
  1026. cinfo.rec_cpu = fd->rec_cpu_num;
  1027. cinfo.send_ctxt = uctxt->sc->hw_context;
  1028. cinfo.egrtids = uctxt->egrbufs.alloced;
  1029. cinfo.rcvhdrq_cnt = uctxt->rcvhdrq_cnt;
  1030. cinfo.rcvhdrq_entsize = uctxt->rcvhdrqentsize << 2;
  1031. cinfo.sdma_ring_size = fd->cq->nentries;
  1032. cinfo.rcvegr_size = uctxt->egrbufs.rcvtid_size;
  1033. trace_hfi1_ctxt_info(uctxt->dd, uctxt->ctxt, fd->subctxt, &cinfo);
  1034. if (copy_to_user((void __user *)arg, &cinfo, len))
  1035. return -EFAULT;
  1036. return 0;
  1037. }
  1038. static int init_user_ctxt(struct hfi1_filedata *fd,
  1039. struct hfi1_ctxtdata *uctxt)
  1040. {
  1041. int ret;
  1042. ret = hfi1_user_sdma_alloc_queues(uctxt, fd);
  1043. if (ret)
  1044. return ret;
  1045. ret = hfi1_user_exp_rcv_init(fd, uctxt);
  1046. if (ret)
  1047. hfi1_user_sdma_free_queues(fd, uctxt);
  1048. return ret;
  1049. }
  1050. static int setup_base_ctxt(struct hfi1_filedata *fd,
  1051. struct hfi1_ctxtdata *uctxt)
  1052. {
  1053. struct hfi1_devdata *dd = uctxt->dd;
  1054. int ret = 0;
  1055. hfi1_init_ctxt(uctxt->sc);
  1056. /* Now allocate the RcvHdr queue and eager buffers. */
  1057. ret = hfi1_create_rcvhdrq(dd, uctxt);
  1058. if (ret)
  1059. goto done;
  1060. ret = hfi1_setup_eagerbufs(uctxt);
  1061. if (ret)
  1062. goto done;
  1063. /* If sub-contexts are enabled, do the appropriate setup */
  1064. if (uctxt->subctxt_cnt)
  1065. ret = setup_subctxt(uctxt);
  1066. if (ret)
  1067. goto done;
  1068. ret = hfi1_alloc_ctxt_rcv_groups(uctxt);
  1069. if (ret)
  1070. goto done;
  1071. ret = init_user_ctxt(fd, uctxt);
  1072. if (ret)
  1073. goto done;
  1074. user_init(uctxt);
  1075. /* Now that the context is set up, the fd can get a reference. */
  1076. fd->uctxt = uctxt;
  1077. hfi1_rcd_get(uctxt);
  1078. done:
  1079. if (uctxt->subctxt_cnt) {
  1080. /*
  1081. * On error, set the failed bit so sub-contexts will clean up
  1082. * correctly.
  1083. */
  1084. if (ret)
  1085. set_bit(HFI1_CTXT_BASE_FAILED, &uctxt->event_flags);
  1086. /*
  1087. * Base context is done (successfully or not), notify anybody
  1088. * using a sub-context that is waiting for this completion.
  1089. */
  1090. clear_bit(HFI1_CTXT_BASE_UNINIT, &uctxt->event_flags);
  1091. wake_up(&uctxt->wait);
  1092. }
  1093. return ret;
  1094. }
  1095. static int get_base_info(struct hfi1_filedata *fd, unsigned long arg, u32 len)
  1096. {
  1097. struct hfi1_base_info binfo;
  1098. struct hfi1_ctxtdata *uctxt = fd->uctxt;
  1099. struct hfi1_devdata *dd = uctxt->dd;
  1100. unsigned offset;
  1101. trace_hfi1_uctxtdata(uctxt->dd, uctxt, fd->subctxt);
  1102. if (sizeof(binfo) != len)
  1103. return -EINVAL;
  1104. memset(&binfo, 0, sizeof(binfo));
  1105. binfo.hw_version = dd->revision;
  1106. binfo.sw_version = HFI1_KERN_SWVERSION;
  1107. binfo.bthqp = kdeth_qp;
  1108. binfo.jkey = uctxt->jkey;
  1109. /*
  1110. * If more than 64 contexts are enabled the allocated credit
  1111. * return will span two or three contiguous pages. Since we only
  1112. * map the page containing the context's credit return address,
  1113. * we need to calculate the offset in the proper page.
  1114. */
  1115. offset = ((u64)uctxt->sc->hw_free -
  1116. (u64)dd->cr_base[uctxt->numa_id].va) % PAGE_SIZE;
  1117. binfo.sc_credits_addr = HFI1_MMAP_TOKEN(PIO_CRED, uctxt->ctxt,
  1118. fd->subctxt, offset);
  1119. binfo.pio_bufbase = HFI1_MMAP_TOKEN(PIO_BUFS, uctxt->ctxt,
  1120. fd->subctxt,
  1121. uctxt->sc->base_addr);
  1122. binfo.pio_bufbase_sop = HFI1_MMAP_TOKEN(PIO_BUFS_SOP,
  1123. uctxt->ctxt,
  1124. fd->subctxt,
  1125. uctxt->sc->base_addr);
  1126. binfo.rcvhdr_bufbase = HFI1_MMAP_TOKEN(RCV_HDRQ, uctxt->ctxt,
  1127. fd->subctxt,
  1128. uctxt->rcvhdrq);
  1129. binfo.rcvegr_bufbase = HFI1_MMAP_TOKEN(RCV_EGRBUF, uctxt->ctxt,
  1130. fd->subctxt,
  1131. uctxt->egrbufs.rcvtids[0].dma);
  1132. binfo.sdma_comp_bufbase = HFI1_MMAP_TOKEN(SDMA_COMP, uctxt->ctxt,
  1133. fd->subctxt, 0);
  1134. /*
  1135. * user regs are at
  1136. * (RXE_PER_CONTEXT_USER + (ctxt * RXE_PER_CONTEXT_SIZE))
  1137. */
  1138. binfo.user_regbase = HFI1_MMAP_TOKEN(UREGS, uctxt->ctxt,
  1139. fd->subctxt, 0);
  1140. offset = offset_in_page((uctxt_offset(uctxt) + fd->subctxt) *
  1141. sizeof(*dd->events));
  1142. binfo.events_bufbase = HFI1_MMAP_TOKEN(EVENTS, uctxt->ctxt,
  1143. fd->subctxt,
  1144. offset);
  1145. binfo.status_bufbase = HFI1_MMAP_TOKEN(STATUS, uctxt->ctxt,
  1146. fd->subctxt,
  1147. dd->status);
  1148. if (HFI1_CAP_IS_USET(DMA_RTAIL))
  1149. binfo.rcvhdrtail_base = HFI1_MMAP_TOKEN(RTAIL, uctxt->ctxt,
  1150. fd->subctxt, 0);
  1151. if (uctxt->subctxt_cnt) {
  1152. binfo.subctxt_uregbase = HFI1_MMAP_TOKEN(SUBCTXT_UREGS,
  1153. uctxt->ctxt,
  1154. fd->subctxt, 0);
  1155. binfo.subctxt_rcvhdrbuf = HFI1_MMAP_TOKEN(SUBCTXT_RCV_HDRQ,
  1156. uctxt->ctxt,
  1157. fd->subctxt, 0);
  1158. binfo.subctxt_rcvegrbuf = HFI1_MMAP_TOKEN(SUBCTXT_EGRBUF,
  1159. uctxt->ctxt,
  1160. fd->subctxt, 0);
  1161. }
  1162. if (copy_to_user((void __user *)arg, &binfo, len))
  1163. return -EFAULT;
  1164. return 0;
  1165. }
  1166. /**
  1167. * user_exp_rcv_setup - Set up the given tid rcv list
  1168. * @fd: file data of the current driver instance
  1169. * @arg: ioctl argumnent for user space information
  1170. * @len: length of data structure associated with ioctl command
  1171. *
  1172. * Wrapper to validate ioctl information before doing _rcv_setup.
  1173. *
  1174. */
  1175. static int user_exp_rcv_setup(struct hfi1_filedata *fd, unsigned long arg,
  1176. u32 len)
  1177. {
  1178. int ret;
  1179. unsigned long addr;
  1180. struct hfi1_tid_info tinfo;
  1181. if (sizeof(tinfo) != len)
  1182. return -EINVAL;
  1183. if (copy_from_user(&tinfo, (void __user *)arg, (sizeof(tinfo))))
  1184. return -EFAULT;
  1185. ret = hfi1_user_exp_rcv_setup(fd, &tinfo);
  1186. if (!ret) {
  1187. /*
  1188. * Copy the number of tidlist entries we used
  1189. * and the length of the buffer we registered.
  1190. */
  1191. addr = arg + offsetof(struct hfi1_tid_info, tidcnt);
  1192. if (copy_to_user((void __user *)addr, &tinfo.tidcnt,
  1193. sizeof(tinfo.tidcnt)))
  1194. return -EFAULT;
  1195. addr = arg + offsetof(struct hfi1_tid_info, length);
  1196. if (copy_to_user((void __user *)addr, &tinfo.length,
  1197. sizeof(tinfo.length)))
  1198. ret = -EFAULT;
  1199. }
  1200. return ret;
  1201. }
  1202. /**
  1203. * user_exp_rcv_clear - Clear the given tid rcv list
  1204. * @fd: file data of the current driver instance
  1205. * @arg: ioctl argumnent for user space information
  1206. * @len: length of data structure associated with ioctl command
  1207. *
  1208. * The hfi1_user_exp_rcv_clear() can be called from the error path. Because
  1209. * of this, we need to use this wrapper to copy the user space information
  1210. * before doing the clear.
  1211. */
  1212. static int user_exp_rcv_clear(struct hfi1_filedata *fd, unsigned long arg,
  1213. u32 len)
  1214. {
  1215. int ret;
  1216. unsigned long addr;
  1217. struct hfi1_tid_info tinfo;
  1218. if (sizeof(tinfo) != len)
  1219. return -EINVAL;
  1220. if (copy_from_user(&tinfo, (void __user *)arg, (sizeof(tinfo))))
  1221. return -EFAULT;
  1222. ret = hfi1_user_exp_rcv_clear(fd, &tinfo);
  1223. if (!ret) {
  1224. addr = arg + offsetof(struct hfi1_tid_info, tidcnt);
  1225. if (copy_to_user((void __user *)addr, &tinfo.tidcnt,
  1226. sizeof(tinfo.tidcnt)))
  1227. return -EFAULT;
  1228. }
  1229. return ret;
  1230. }
  1231. /**
  1232. * user_exp_rcv_invalid - Invalidate the given tid rcv list
  1233. * @fd: file data of the current driver instance
  1234. * @arg: ioctl argumnent for user space information
  1235. * @len: length of data structure associated with ioctl command
  1236. *
  1237. * Wrapper to validate ioctl information before doing _rcv_invalid.
  1238. *
  1239. */
  1240. static int user_exp_rcv_invalid(struct hfi1_filedata *fd, unsigned long arg,
  1241. u32 len)
  1242. {
  1243. int ret;
  1244. unsigned long addr;
  1245. struct hfi1_tid_info tinfo;
  1246. if (sizeof(tinfo) != len)
  1247. return -EINVAL;
  1248. if (!fd->invalid_tids)
  1249. return -EINVAL;
  1250. if (copy_from_user(&tinfo, (void __user *)arg, (sizeof(tinfo))))
  1251. return -EFAULT;
  1252. ret = hfi1_user_exp_rcv_invalid(fd, &tinfo);
  1253. if (ret)
  1254. return ret;
  1255. addr = arg + offsetof(struct hfi1_tid_info, tidcnt);
  1256. if (copy_to_user((void __user *)addr, &tinfo.tidcnt,
  1257. sizeof(tinfo.tidcnt)))
  1258. ret = -EFAULT;
  1259. return ret;
  1260. }
  1261. static __poll_t poll_urgent(struct file *fp,
  1262. struct poll_table_struct *pt)
  1263. {
  1264. struct hfi1_filedata *fd = fp->private_data;
  1265. struct hfi1_ctxtdata *uctxt = fd->uctxt;
  1266. struct hfi1_devdata *dd = uctxt->dd;
  1267. __poll_t pollflag;
  1268. poll_wait(fp, &uctxt->wait, pt);
  1269. spin_lock_irq(&dd->uctxt_lock);
  1270. if (uctxt->urgent != uctxt->urgent_poll) {
  1271. pollflag = EPOLLIN | EPOLLRDNORM;
  1272. uctxt->urgent_poll = uctxt->urgent;
  1273. } else {
  1274. pollflag = 0;
  1275. set_bit(HFI1_CTXT_WAITING_URG, &uctxt->event_flags);
  1276. }
  1277. spin_unlock_irq(&dd->uctxt_lock);
  1278. return pollflag;
  1279. }
  1280. static __poll_t poll_next(struct file *fp,
  1281. struct poll_table_struct *pt)
  1282. {
  1283. struct hfi1_filedata *fd = fp->private_data;
  1284. struct hfi1_ctxtdata *uctxt = fd->uctxt;
  1285. struct hfi1_devdata *dd = uctxt->dd;
  1286. __poll_t pollflag;
  1287. poll_wait(fp, &uctxt->wait, pt);
  1288. spin_lock_irq(&dd->uctxt_lock);
  1289. if (hdrqempty(uctxt)) {
  1290. set_bit(HFI1_CTXT_WAITING_RCV, &uctxt->event_flags);
  1291. hfi1_rcvctrl(dd, HFI1_RCVCTRL_INTRAVAIL_ENB, uctxt);
  1292. pollflag = 0;
  1293. } else {
  1294. pollflag = EPOLLIN | EPOLLRDNORM;
  1295. }
  1296. spin_unlock_irq(&dd->uctxt_lock);
  1297. return pollflag;
  1298. }
  1299. /*
  1300. * Find all user contexts in use, and set the specified bit in their
  1301. * event mask.
  1302. * See also find_ctxt() for a similar use, that is specific to send buffers.
  1303. */
  1304. int hfi1_set_uevent_bits(struct hfi1_pportdata *ppd, const int evtbit)
  1305. {
  1306. struct hfi1_ctxtdata *uctxt;
  1307. struct hfi1_devdata *dd = ppd->dd;
  1308. u16 ctxt;
  1309. if (!dd->events)
  1310. return -EINVAL;
  1311. for (ctxt = dd->first_dyn_alloc_ctxt; ctxt < dd->num_rcv_contexts;
  1312. ctxt++) {
  1313. uctxt = hfi1_rcd_get_by_index(dd, ctxt);
  1314. if (uctxt) {
  1315. unsigned long *evs;
  1316. int i;
  1317. /*
  1318. * subctxt_cnt is 0 if not shared, so do base
  1319. * separately, first, then remaining subctxt, if any
  1320. */
  1321. evs = dd->events + uctxt_offset(uctxt);
  1322. set_bit(evtbit, evs);
  1323. for (i = 1; i < uctxt->subctxt_cnt; i++)
  1324. set_bit(evtbit, evs + i);
  1325. hfi1_rcd_put(uctxt);
  1326. }
  1327. }
  1328. return 0;
  1329. }
  1330. /**
  1331. * manage_rcvq - manage a context's receive queue
  1332. * @uctxt: the context
  1333. * @subctxt: the sub-context
  1334. * @start_stop: action to carry out
  1335. *
  1336. * start_stop == 0 disables receive on the context, for use in queue
  1337. * overflow conditions. start_stop==1 re-enables, to be used to
  1338. * re-init the software copy of the head register
  1339. */
  1340. static int manage_rcvq(struct hfi1_ctxtdata *uctxt, u16 subctxt,
  1341. unsigned long arg)
  1342. {
  1343. struct hfi1_devdata *dd = uctxt->dd;
  1344. unsigned int rcvctrl_op;
  1345. int start_stop;
  1346. if (subctxt)
  1347. return 0;
  1348. if (get_user(start_stop, (int __user *)arg))
  1349. return -EFAULT;
  1350. /* atomically clear receive enable ctxt. */
  1351. if (start_stop) {
  1352. /*
  1353. * On enable, force in-memory copy of the tail register to
  1354. * 0, so that protocol code doesn't have to worry about
  1355. * whether or not the chip has yet updated the in-memory
  1356. * copy or not on return from the system call. The chip
  1357. * always resets it's tail register back to 0 on a
  1358. * transition from disabled to enabled.
  1359. */
  1360. if (uctxt->rcvhdrtail_kvaddr)
  1361. clear_rcvhdrtail(uctxt);
  1362. rcvctrl_op = HFI1_RCVCTRL_CTXT_ENB;
  1363. } else {
  1364. rcvctrl_op = HFI1_RCVCTRL_CTXT_DIS;
  1365. }
  1366. hfi1_rcvctrl(dd, rcvctrl_op, uctxt);
  1367. /* always; new head should be equal to new tail; see above */
  1368. return 0;
  1369. }
  1370. /*
  1371. * clear the event notifier events for this context.
  1372. * User process then performs actions appropriate to bit having been
  1373. * set, if desired, and checks again in future.
  1374. */
  1375. static int user_event_ack(struct hfi1_ctxtdata *uctxt, u16 subctxt,
  1376. unsigned long arg)
  1377. {
  1378. int i;
  1379. struct hfi1_devdata *dd = uctxt->dd;
  1380. unsigned long *evs;
  1381. unsigned long events;
  1382. if (!dd->events)
  1383. return 0;
  1384. if (get_user(events, (unsigned long __user *)arg))
  1385. return -EFAULT;
  1386. evs = dd->events + uctxt_offset(uctxt) + subctxt;
  1387. for (i = 0; i <= _HFI1_MAX_EVENT_BIT; i++) {
  1388. if (!test_bit(i, &events))
  1389. continue;
  1390. clear_bit(i, evs);
  1391. }
  1392. return 0;
  1393. }
  1394. static int set_ctxt_pkey(struct hfi1_ctxtdata *uctxt, unsigned long arg)
  1395. {
  1396. int i;
  1397. struct hfi1_pportdata *ppd = uctxt->ppd;
  1398. struct hfi1_devdata *dd = uctxt->dd;
  1399. u16 pkey;
  1400. if (!HFI1_CAP_IS_USET(PKEY_CHECK))
  1401. return -EPERM;
  1402. if (get_user(pkey, (u16 __user *)arg))
  1403. return -EFAULT;
  1404. if (pkey == LIM_MGMT_P_KEY || pkey == FULL_MGMT_P_KEY)
  1405. return -EINVAL;
  1406. for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++)
  1407. if (pkey == ppd->pkeys[i])
  1408. return hfi1_set_ctxt_pkey(dd, uctxt, pkey);
  1409. return -ENOENT;
  1410. }
  1411. /**
  1412. * ctxt_reset - Reset the user context
  1413. * @uctxt: valid user context
  1414. */
  1415. static int ctxt_reset(struct hfi1_ctxtdata *uctxt)
  1416. {
  1417. struct send_context *sc;
  1418. struct hfi1_devdata *dd;
  1419. int ret = 0;
  1420. if (!uctxt || !uctxt->dd || !uctxt->sc)
  1421. return -EINVAL;
  1422. /*
  1423. * There is no protection here. User level has to guarantee that
  1424. * no one will be writing to the send context while it is being
  1425. * re-initialized. If user level breaks that guarantee, it will
  1426. * break it's own context and no one else's.
  1427. */
  1428. dd = uctxt->dd;
  1429. sc = uctxt->sc;
  1430. /*
  1431. * Wait until the interrupt handler has marked the context as
  1432. * halted or frozen. Report error if we time out.
  1433. */
  1434. wait_event_interruptible_timeout(
  1435. sc->halt_wait, (sc->flags & SCF_HALTED),
  1436. msecs_to_jiffies(SEND_CTXT_HALT_TIMEOUT));
  1437. if (!(sc->flags & SCF_HALTED))
  1438. return -ENOLCK;
  1439. /*
  1440. * If the send context was halted due to a Freeze, wait until the
  1441. * device has been "unfrozen" before resetting the context.
  1442. */
  1443. if (sc->flags & SCF_FROZEN) {
  1444. wait_event_interruptible_timeout(
  1445. dd->event_queue,
  1446. !(READ_ONCE(dd->flags) & HFI1_FROZEN),
  1447. msecs_to_jiffies(SEND_CTXT_HALT_TIMEOUT));
  1448. if (dd->flags & HFI1_FROZEN)
  1449. return -ENOLCK;
  1450. if (dd->flags & HFI1_FORCED_FREEZE)
  1451. /*
  1452. * Don't allow context reset if we are into
  1453. * forced freeze
  1454. */
  1455. return -ENODEV;
  1456. sc_disable(sc);
  1457. ret = sc_enable(sc);
  1458. hfi1_rcvctrl(dd, HFI1_RCVCTRL_CTXT_ENB, uctxt);
  1459. } else {
  1460. ret = sc_restart(sc);
  1461. }
  1462. if (!ret)
  1463. sc_return_credits(sc);
  1464. return ret;
  1465. }
  1466. static void user_remove(struct hfi1_devdata *dd)
  1467. {
  1468. hfi1_cdev_cleanup(&dd->user_cdev, &dd->user_device);
  1469. }
  1470. static int user_add(struct hfi1_devdata *dd)
  1471. {
  1472. char name[10];
  1473. int ret;
  1474. snprintf(name, sizeof(name), "%s_%d", class_name(), dd->unit);
  1475. ret = hfi1_cdev_init(dd->unit, name, &hfi1_file_ops,
  1476. &dd->user_cdev, &dd->user_device,
  1477. true, &dd->kobj);
  1478. if (ret)
  1479. user_remove(dd);
  1480. return ret;
  1481. }
  1482. /*
  1483. * Create per-unit files in /dev
  1484. */
  1485. int hfi1_device_create(struct hfi1_devdata *dd)
  1486. {
  1487. return user_add(dd);
  1488. }
  1489. /*
  1490. * Remove per-unit files in /dev
  1491. * void, core kernel returns no errors for this stuff
  1492. */
  1493. void hfi1_device_remove(struct hfi1_devdata *dd)
  1494. {
  1495. user_remove(dd);
  1496. }