static int pp_check_ntb(struct ntb_dev *ntb) { u64 pmask; if (ntb_db_is_unsafe(ntb)) { dev_dbg(&ntb->dev, "Doorbell is unsafe\n"); if (!unsafe) return -EINVAL; } if (ntb_spad_is_unsafe(ntb)) { dev_dbg(&ntb->dev, "Scratchpad is unsafe\n"); if (!unsafe) return -EINVAL; } pmask = GENMASK_ULL(ntb_peer_port_count(ntb), 0); if ((ntb_db_valid_mask(ntb) & pmask) != pmask) { dev_err(&ntb->dev, "Unsupported DB configuration\n"); return -EINVAL; } if (ntb_spad_count(ntb) < 1 && ntb_msg_count(ntb) < 1) { dev_err(&ntb->dev, "Scratchpads and messages unsupported\n"); return -EINVAL; } else if (ntb_spad_count(ntb) < 1) { dev_dbg(&ntb->dev, "Scratchpads unsupported\n"); } else if (ntb_msg_count(ntb) < 1) { dev_dbg(&ntb->dev, "Messages unsupported\n"); } return 0; }
static void pp_init_flds(struct pp_ctx *pp) { int pidx, lport, pcnt; /* Find global port index */ lport = ntb_port_number(pp->ntb); pcnt = ntb_peer_port_count(pp->ntb); for (pidx = 0; pidx < pcnt; pidx++) { if (lport < ntb_peer_port_number(pp->ntb, pidx)) break; } pp->in_db = BIT_ULL(lport); pp->pmask = GENMASK_ULL(pidx, 0) >> 1; pp->nmask = GENMASK_ULL(pcnt - 1, pidx); dev_dbg(&pp->ntb->dev, "Inbound db %#llx, prev %#llx, next %#llx\n", pp->in_db, pp->pmask, pp->nmask); }
static int tool_probe(struct ntb_client *self, struct ntb_dev *ntb) { struct tool_ctx *tc; int rc; int i; if (!ntb->ops->mw_set_trans) { dev_dbg(&ntb->dev, "need inbound MW based NTB API\n"); rc = -EINVAL; goto err_tc; } if (ntb_spad_count(ntb) < 1) { dev_dbg(&ntb->dev, "no enough scratchpads\n"); rc = -EINVAL; goto err_tc; } if (ntb_db_is_unsafe(ntb)) dev_dbg(&ntb->dev, "doorbell is unsafe\n"); if (ntb_spad_is_unsafe(ntb)) dev_dbg(&ntb->dev, "scratchpad is unsafe\n"); if (ntb_peer_port_count(ntb) != NTB_DEF_PEER_CNT) dev_warn(&ntb->dev, "multi-port NTB is unsupported\n"); tc = kzalloc(sizeof(*tc), GFP_KERNEL); if (!tc) { rc = -ENOMEM; goto err_tc; } tc->ntb = ntb; init_waitqueue_head(&tc->link_wq); tc->mw_count = min(ntb_peer_mw_count(tc->ntb), MAX_MWS); for (i = 0; i < tc->mw_count; i++) { rc = tool_init_mw(tc, i); if (rc) goto err_ctx; } tool_setup_dbgfs(tc); rc = ntb_set_ctx(ntb, tc, &tool_ops); if (rc) goto err_ctx; ntb_link_enable(ntb, NTB_SPEED_AUTO, NTB_WIDTH_AUTO); ntb_link_event(ntb); return 0; err_ctx: tool_free_mws(tc); debugfs_remove_recursive(tc->dbgfs); kfree(tc); err_tc: return rc; }