Commit 70224973 authored by Dean Luick's avatar Dean Luick Committed by Greg Kroah-Hartman

staging/rdma/hfi1: Select only devices with active links

When looking for or validating a user device, only use devices
that are currently active.
Reviewed-by: default avatarMitko Haralanov <mitko.haralanov@intel.com>
Signed-off-by: default avatarDean Luick <dean.luick@intel.com>
Signed-off-by: default avatarJubin John <jubin.john@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 4ef98989
...@@ -850,6 +850,14 @@ static int assign_ctxt(struct file *fp, struct hfi1_user_info *uinfo) ...@@ -850,6 +850,14 @@ static int assign_ctxt(struct file *fp, struct hfi1_user_info *uinfo)
return ret; return ret;
} }
/* return true if the device available for general use */
static int usable_device(struct hfi1_devdata *dd)
{
struct hfi1_pportdata *ppd = dd->pport;
return driver_lstate(ppd) == IB_PORT_ACTIVE;
}
static int get_user_context(struct file *fp, struct hfi1_user_info *uinfo, static int get_user_context(struct file *fp, struct hfi1_user_info *uinfo,
int devno, unsigned alg) int devno, unsigned alg)
{ {
...@@ -879,7 +887,11 @@ static int get_user_context(struct file *fp, struct hfi1_user_info *uinfo, ...@@ -879,7 +887,11 @@ static int get_user_context(struct file *fp, struct hfi1_user_info *uinfo,
for (dev = 0; dev < devmax; dev++) { for (dev = 0; dev < devmax; dev++) {
pdd = hfi1_lookup(dev); pdd = hfi1_lookup(dev);
if (pdd && pdd->freectxts && if (!pdd)
continue;
if (!usable_device(pdd))
continue;
if (pdd->freectxts &&
pdd->freectxts > free) { pdd->freectxts > free) {
dd = pdd; dd = pdd;
free = pdd->freectxts; free = pdd->freectxts;
...@@ -888,7 +900,11 @@ static int get_user_context(struct file *fp, struct hfi1_user_info *uinfo, ...@@ -888,7 +900,11 @@ static int get_user_context(struct file *fp, struct hfi1_user_info *uinfo,
} else { } else {
for (dev = 0; dev < devmax; dev++) { for (dev = 0; dev < devmax; dev++) {
pdd = hfi1_lookup(dev); pdd = hfi1_lookup(dev);
if (pdd && pdd->freectxts) { if (!pdd)
continue;
if (!usable_device(pdd))
continue;
if (pdd->freectxts) {
dd = pdd; dd = pdd;
break; break;
} }
...@@ -913,7 +929,6 @@ static int find_shared_ctxt(struct file *fp, ...@@ -913,7 +929,6 @@ static int find_shared_ctxt(struct file *fp,
for (ndev = 0; ndev < devmax; ndev++) { for (ndev = 0; ndev < devmax; ndev++) {
struct hfi1_devdata *dd = hfi1_lookup(ndev); struct hfi1_devdata *dd = hfi1_lookup(ndev);
/* device portion of usable() */
if (!(dd && (dd->flags & HFI1_PRESENT) && dd->kregbase)) if (!(dd && (dd->flags & HFI1_PRESENT) && dd->kregbase))
continue; continue;
for (i = dd->first_user_ctxt; i < dd->num_rcv_contexts; i++) { for (i = dd->first_user_ctxt; i < dd->num_rcv_contexts; i++) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment