Lines Matching full:req
80 static int user_sdma_send_pkts(struct user_sdma_request *req, u16 maxpkts);
83 static void user_sdma_free_request(struct user_sdma_request *req, bool unpin);
84 static int pin_vector_pages(struct user_sdma_request *req,
88 static int check_header_template(struct user_sdma_request *req,
91 static int set_txreq_header(struct user_sdma_request *req,
93 static int set_txreq_header_ahg(struct user_sdma_request *req,
355 struct user_sdma_request *req; in hfi1_user_sdma_process_request() local
362 if (iovec[idx].iov_len < sizeof(info) + sizeof(req->hdr)) { in hfi1_user_sdma_process_request()
367 iovec[idx].iov_len, sizeof(info) + sizeof(req->hdr)); in hfi1_user_sdma_process_request()
417 req = pq->reqs + info.comp_idx; in hfi1_user_sdma_process_request()
418 req->data_iovs = req_iovcnt(info.ctrl) - 1; /* subtract header vector */ in hfi1_user_sdma_process_request()
419 req->data_len = 0; in hfi1_user_sdma_process_request()
420 req->pq = pq; in hfi1_user_sdma_process_request()
421 req->cq = cq; in hfi1_user_sdma_process_request()
422 req->ahg_idx = -1; in hfi1_user_sdma_process_request()
423 req->iov_idx = 0; in hfi1_user_sdma_process_request()
424 req->sent = 0; in hfi1_user_sdma_process_request()
425 req->seqnum = 0; in hfi1_user_sdma_process_request()
426 req->seqcomp = 0; in hfi1_user_sdma_process_request()
427 req->seqsubmitted = 0; in hfi1_user_sdma_process_request()
428 req->tids = NULL; in hfi1_user_sdma_process_request()
429 req->has_error = 0; in hfi1_user_sdma_process_request()
430 INIT_LIST_HEAD(&req->txps); in hfi1_user_sdma_process_request()
432 memcpy(&req->info, &info, sizeof(info)); in hfi1_user_sdma_process_request()
439 if (req->data_iovs < 2) { in hfi1_user_sdma_process_request()
440 SDMA_DBG(req, in hfi1_user_sdma_process_request()
445 req->data_iovs--; in hfi1_user_sdma_process_request()
448 if (!info.npkts || req->data_iovs > MAX_VECTORS_PER_REQ) { in hfi1_user_sdma_process_request()
449 SDMA_DBG(req, "Too many vectors (%u/%u)", req->data_iovs, in hfi1_user_sdma_process_request()
455 ret = copy_from_user(&req->hdr, iovec[idx].iov_base + sizeof(info), in hfi1_user_sdma_process_request()
456 sizeof(req->hdr)); in hfi1_user_sdma_process_request()
458 SDMA_DBG(req, "Failed to copy header template (%d)", ret); in hfi1_user_sdma_process_request()
465 req->hdr.pbc[2] = 0; in hfi1_user_sdma_process_request()
468 opcode = (be32_to_cpu(req->hdr.bth[0]) >> 24) & 0xff; in hfi1_user_sdma_process_request()
471 SDMA_DBG(req, "Invalid opcode (%d)", opcode); in hfi1_user_sdma_process_request()
480 vl = (le16_to_cpu(req->hdr.pbc[0]) >> 12) & 0xF; in hfi1_user_sdma_process_request()
481 sc = (((be16_to_cpu(req->hdr.lrh[0]) >> 12) & 0xF) | in hfi1_user_sdma_process_request()
482 (((le16_to_cpu(req->hdr.pbc[1]) >> 14) & 0x1) << 4)); in hfi1_user_sdma_process_request()
485 SDMA_DBG(req, "Invalid SC(%u)/VL(%u)", sc, vl); in hfi1_user_sdma_process_request()
491 pkey = (u16)be32_to_cpu(req->hdr.bth[0]); in hfi1_user_sdma_process_request()
492 slid = be16_to_cpu(req->hdr.lrh[3]); in hfi1_user_sdma_process_request()
503 if ((be16_to_cpu(req->hdr.lrh[0]) & 0x3) == HFI1_LRH_GRH) { in hfi1_user_sdma_process_request()
504 SDMA_DBG(req, "User tried to pass in a GRH"); in hfi1_user_sdma_process_request()
509 req->koffset = le32_to_cpu(req->hdr.kdeth.swdata[6]); in hfi1_user_sdma_process_request()
514 req->tidoffset = KDETH_GET(req->hdr.kdeth.ver_tid_offset, OFFSET) * in hfi1_user_sdma_process_request()
515 (KDETH_GET(req->hdr.kdeth.ver_tid_offset, OM) ? in hfi1_user_sdma_process_request()
518 info.comp_idx, req->tidoffset); in hfi1_user_sdma_process_request()
522 for (i = 0; i < req->data_iovs; i++) { in hfi1_user_sdma_process_request()
523 req->iovs[i].offset = 0; in hfi1_user_sdma_process_request()
524 INIT_LIST_HEAD(&req->iovs[i].list); in hfi1_user_sdma_process_request()
525 memcpy(&req->iovs[i].iov, in hfi1_user_sdma_process_request()
527 sizeof(req->iovs[i].iov)); in hfi1_user_sdma_process_request()
528 ret = pin_vector_pages(req, &req->iovs[i]); in hfi1_user_sdma_process_request()
530 req->data_iovs = i; in hfi1_user_sdma_process_request()
533 req->data_len += req->iovs[i].iov.iov_len; in hfi1_user_sdma_process_request()
536 info.comp_idx, req->data_len); in hfi1_user_sdma_process_request()
537 if (pcount > req->info.npkts) in hfi1_user_sdma_process_request()
538 pcount = req->info.npkts; in hfi1_user_sdma_process_request()
547 if (req_opcode(req->info.ctrl) == EXPECTED) { in hfi1_user_sdma_process_request()
548 u16 ntids = iovec[idx].iov_len / sizeof(*req->tids); in hfi1_user_sdma_process_request()
563 ntids * sizeof(*req->tids)); in hfi1_user_sdma_process_request()
566 SDMA_DBG(req, "Failed to copy %d TIDs (%d)", in hfi1_user_sdma_process_request()
570 req->tids = tmp; in hfi1_user_sdma_process_request()
571 req->n_tids = ntids; in hfi1_user_sdma_process_request()
572 req->tididx = 0; in hfi1_user_sdma_process_request()
576 dlid = be16_to_cpu(req->hdr.lrh[1]); in hfi1_user_sdma_process_request()
579 req->sde = sdma_select_user_engine(dd, selector, vl); in hfi1_user_sdma_process_request()
581 if (!req->sde || !sdma_running(req->sde)) { in hfi1_user_sdma_process_request()
587 if (req->info.npkts > 1 && HFI1_CAP_IS_USET(SDMA_AHG)) in hfi1_user_sdma_process_request()
588 req->ahg_idx = sdma_ahg_alloc(req->sde); in hfi1_user_sdma_process_request()
599 while (req->seqsubmitted != req->info.npkts) { in hfi1_user_sdma_process_request()
600 ret = user_sdma_send_pkts(req, pcount); in hfi1_user_sdma_process_request()
620 if (req->seqsubmitted < req->info.npkts) { in hfi1_user_sdma_process_request()
621 if (req->seqsubmitted) in hfi1_user_sdma_process_request()
623 (req->seqcomp == req->seqsubmitted - 1)); in hfi1_user_sdma_process_request()
624 user_sdma_free_request(req, true); in hfi1_user_sdma_process_request()
631 static inline u32 compute_data_length(struct user_sdma_request *req, in compute_data_length() argument
648 if (!req->seqnum) { in compute_data_length()
649 if (req->data_len < sizeof(u32)) in compute_data_length()
650 len = req->data_len; in compute_data_length()
652 len = ((be16_to_cpu(req->hdr.lrh[2]) << 2) - in compute_data_length()
654 } else if (req_opcode(req->info.ctrl) == EXPECTED) { in compute_data_length()
655 u32 tidlen = EXP_TID_GET(req->tids[req->tididx], LEN) * in compute_data_length()
661 len = min(tidlen - req->tidoffset, (u32)req->info.fragsize); in compute_data_length()
663 if (unlikely(!len) && ++req->tididx < req->n_tids && in compute_data_length()
664 req->tids[req->tididx]) { in compute_data_length()
665 tidlen = EXP_TID_GET(req->tids[req->tididx], in compute_data_length()
667 req->tidoffset = 0; in compute_data_length()
668 len = min_t(u32, tidlen, req->info.fragsize); in compute_data_length()
675 len = min(len, req->data_len - req->sent); in compute_data_length()
677 len = min(req->data_len - req->sent, (u32)req->info.fragsize); in compute_data_length()
679 trace_hfi1_sdma_user_compute_length(req->pq->dd, in compute_data_length()
680 req->pq->ctxt, in compute_data_length()
681 req->pq->subctxt, in compute_data_length()
682 req->info.comp_idx, in compute_data_length()
700 static int user_sdma_txadd_ahg(struct user_sdma_request *req, in user_sdma_txadd_ahg() argument
705 u16 pbclen = le16_to_cpu(req->hdr.pbc[0]); in user_sdma_txadd_ahg()
706 u32 lrhlen = get_lrh_len(req->hdr, pad_len(datalen)); in user_sdma_txadd_ahg()
707 struct hfi1_user_sdma_pkt_q *pq = req->pq; in user_sdma_txadd_ahg()
717 memcpy(&tx->hdr, &req->hdr, sizeof(tx->hdr)); in user_sdma_txadd_ahg()
722 ret = check_header_template(req, &tx->hdr, lrhlen, datalen); in user_sdma_txadd_ahg()
726 sizeof(tx->hdr) + datalen, req->ahg_idx, in user_sdma_txadd_ahg()
736 static int user_sdma_txadd(struct user_sdma_request *req, in user_sdma_txadd() argument
747 struct hfi1_user_sdma_pkt_q *pq = req->pq; in user_sdma_txadd()
753 len = offset + req->info.fragsize > PAGE_SIZE ? in user_sdma_txadd()
754 PAGE_SIZE - offset : req->info.fragsize; in user_sdma_txadd()
759 SDMA_DBG(req, "SDMA txreq add page failed %d\n", ret); in user_sdma_txadd()
766 req->iov_idx < req->data_iovs - 1)) { in user_sdma_txadd()
768 iovec = &req->iovs[++req->iov_idx]; in user_sdma_txadd()
778 static int user_sdma_send_pkts(struct user_sdma_request *req, u16 maxpkts) in user_sdma_send_pkts() argument
787 if (!req->pq) in user_sdma_send_pkts()
790 pq = req->pq; in user_sdma_send_pkts()
793 if (READ_ONCE(req->has_error)) in user_sdma_send_pkts()
799 if (unlikely(req->seqnum == req->info.npkts)) { in user_sdma_send_pkts()
800 if (!list_empty(&req->txps)) in user_sdma_send_pkts()
805 if (!maxpkts || maxpkts > req->info.npkts - req->seqnum) in user_sdma_send_pkts()
806 maxpkts = req->info.npkts - req->seqnum; in user_sdma_send_pkts()
817 if (READ_ONCE(req->has_error)) in user_sdma_send_pkts()
825 tx->req = req; in user_sdma_send_pkts()
832 if (req->seqnum == req->info.npkts - 1) in user_sdma_send_pkts()
841 if (req->data_len) { in user_sdma_send_pkts()
842 iovec = &req->iovs[req->iov_idx]; in user_sdma_send_pkts()
844 if (++req->iov_idx == req->data_iovs) { in user_sdma_send_pkts()
848 iovec = &req->iovs[req->iov_idx]; in user_sdma_send_pkts()
852 datalen = compute_data_length(req, tx); in user_sdma_send_pkts()
863 SDMA_DBG(req, in user_sdma_send_pkts()
872 if (req->ahg_idx >= 0) { in user_sdma_send_pkts()
873 if (!req->seqnum) { in user_sdma_send_pkts()
874 ret = user_sdma_txadd_ahg(req, tx, datalen); in user_sdma_send_pkts()
880 changes = set_txreq_header_ahg(req, tx, in user_sdma_send_pkts()
888 ret = sdma_txinit(&tx->txreq, 0, sizeof(req->hdr) + in user_sdma_send_pkts()
898 ret = set_txreq_header(req, tx, datalen); in user_sdma_send_pkts()
908 (req->sent + data_sent) < req->data_len) { in user_sdma_send_pkts()
909 ret = user_sdma_txadd(req, tx, iovec, datalen, in user_sdma_send_pkts()
918 req->koffset += datalen; in user_sdma_send_pkts()
919 if (req_opcode(req->info.ctrl) == EXPECTED) in user_sdma_send_pkts()
920 req->tidoffset += datalen; in user_sdma_send_pkts()
921 req->sent += data_sent; in user_sdma_send_pkts()
922 if (req->data_len) in user_sdma_send_pkts()
924 list_add_tail(&tx->txreq.list, &req->txps); in user_sdma_send_pkts()
930 tx->seqnum = req->seqnum++; in user_sdma_send_pkts()
934 ret = sdma_send_txlist(req->sde, in user_sdma_send_pkts()
936 &req->txps, &count); in user_sdma_send_pkts()
937 req->seqsubmitted += count; in user_sdma_send_pkts()
938 if (req->seqsubmitted == req->info.npkts) { in user_sdma_send_pkts()
945 if (req->ahg_idx >= 0) in user_sdma_send_pkts()
946 sdma_ahg_free(req->sde, req->ahg_idx); in user_sdma_send_pkts()
967 static int pin_sdma_pages(struct user_sdma_request *req, in pin_sdma_pages() argument
974 struct hfi1_user_sdma_pkt_q *pq = req->pq; in pin_sdma_pages()
1017 static int pin_vector_pages(struct user_sdma_request *req, in pin_vector_pages() argument
1021 struct hfi1_user_sdma_pkt_q *pq = req->pq; in pin_vector_pages()
1056 pinned = pin_sdma_pages(req, iovec, node, npages); in pin_vector_pages()
1068 ret = hfi1_mmu_rb_insert(req->pq->handler, &node->rb); in pin_vector_pages()
1087 static int check_header_template(struct user_sdma_request *req, in check_header_template() argument
1101 if (req->info.fragsize % PIO_BLOCK_SIZE || lrhlen & 0x3 || in check_header_template()
1102 lrhlen > get_lrh_len(*hdr, req->info.fragsize)) in check_header_template()
1105 if (req_opcode(req->info.ctrl) == EXPECTED) { in check_header_template()
1112 u32 tidval = req->tids[req->tididx], in check_header_template()
1120 (KDETH_GET(req->hdr.kdeth.ver_tid_offset, OM) ? in check_header_template()
1157 static int set_txreq_header(struct user_sdma_request *req, in set_txreq_header() argument
1160 struct hfi1_user_sdma_pkt_q *pq = req->pq; in set_txreq_header()
1168 memcpy(hdr, &req->hdr, sizeof(*hdr)); in set_txreq_header()
1185 if (unlikely(req->seqnum == 2)) { in set_txreq_header()
1193 req->hdr.pbc[0] = hdr->pbc[0]; in set_txreq_header()
1194 req->hdr.lrh[2] = hdr->lrh[2]; in set_txreq_header()
1202 if (unlikely(!req->seqnum)) { in set_txreq_header()
1203 ret = check_header_template(req, hdr, lrhlen, datalen); in set_txreq_header()
1211 (req_opcode(req->info.ctrl) == EXPECTED), in set_txreq_header()
1212 req->seqnum)); in set_txreq_header()
1219 hdr->kdeth.swdata[6] = cpu_to_le32(req->koffset); in set_txreq_header()
1221 if (req_opcode(req->info.ctrl) == EXPECTED) { in set_txreq_header()
1222 tidval = req->tids[req->tididx]; in set_txreq_header()
1227 if ((req->tidoffset) == (EXP_TID_GET(tidval, LEN) * in set_txreq_header()
1229 req->tidoffset = 0; in set_txreq_header()
1234 if (++req->tididx > req->n_tids - 1 || in set_txreq_header()
1235 !req->tids[req->tididx]) { in set_txreq_header()
1238 tidval = req->tids[req->tididx]; in set_txreq_header()
1257 pq->dd, pq->ctxt, pq->subctxt, req->info.comp_idx, in set_txreq_header()
1258 req->tidoffset, req->tidoffset >> omfactor, in set_txreq_header()
1261 req->tidoffset >> omfactor); in set_txreq_header()
1267 req->info.comp_idx, hdr, tidval); in set_txreq_header()
1271 static int set_txreq_header_ahg(struct user_sdma_request *req, in set_txreq_header_ahg() argument
1277 struct hfi1_user_sdma_pkt_q *pq = req->pq; in set_txreq_header_ahg()
1278 struct hfi1_pkt_header *hdr = &req->hdr; in set_txreq_header_ahg()
1300 val32 = (be32_to_cpu(hdr->bth[2]) + req->seqnum) & in set_txreq_header_ahg()
1314 (__force u16)cpu_to_le16(req->koffset & 0xffff)); in set_txreq_header_ahg()
1318 (__force u16)cpu_to_le16(req->koffset >> 16)); in set_txreq_header_ahg()
1321 if (req_opcode(req->info.ctrl) == EXPECTED) { in set_txreq_header_ahg()
1324 tidval = req->tids[req->tididx]; in set_txreq_header_ahg()
1330 if ((req->tidoffset) == (EXP_TID_GET(tidval, LEN) * in set_txreq_header_ahg()
1332 req->tidoffset = 0; in set_txreq_header_ahg()
1337 if (++req->tididx > req->n_tids - 1 || in set_txreq_header_ahg()
1338 !req->tids[req->tididx]) in set_txreq_header_ahg()
1340 tidval = req->tids[req->tididx]; in set_txreq_header_ahg()
1350 ((req->tidoffset >> omfactor) in set_txreq_header_ahg()
1377 req->info.comp_idx, req->sde->this_idx, in set_txreq_header_ahg()
1378 req->ahg_idx, ahg, idx, tidval); in set_txreq_header_ahg()
1381 datalen, req->ahg_idx, idx, in set_txreq_header_ahg()
1382 ahg, sizeof(req->hdr), in set_txreq_header_ahg()
1402 struct user_sdma_request *req; in user_sdma_txreq_cb() local
1407 if (!tx->req) in user_sdma_txreq_cb()
1410 req = tx->req; in user_sdma_txreq_cb()
1411 pq = req->pq; in user_sdma_txreq_cb()
1412 cq = req->cq; in user_sdma_txreq_cb()
1415 SDMA_DBG(req, "SDMA completion with error %d", in user_sdma_txreq_cb()
1417 WRITE_ONCE(req->has_error, 1); in user_sdma_txreq_cb()
1421 req->seqcomp = tx->seqnum; in user_sdma_txreq_cb()
1425 if (req->seqcomp != req->info.npkts - 1) in user_sdma_txreq_cb()
1428 user_sdma_free_request(req, false); in user_sdma_txreq_cb()
1429 set_comp_state(pq, cq, req->info.comp_idx, state, status); in user_sdma_txreq_cb()
1439 static void user_sdma_free_request(struct user_sdma_request *req, bool unpin) in user_sdma_free_request() argument
1443 if (!list_empty(&req->txps)) { in user_sdma_free_request()
1446 list_for_each_entry_safe(t, p, &req->txps, list) { in user_sdma_free_request()
1450 sdma_txclean(req->pq->dd, t); in user_sdma_free_request()
1451 kmem_cache_free(req->pq->txreq_cache, tx); in user_sdma_free_request()
1455 for (i = 0; i < req->data_iovs; i++) { in user_sdma_free_request()
1456 struct sdma_mmu_node *node = req->iovs[i].node; in user_sdma_free_request()
1461 req->iovs[i].node = NULL; in user_sdma_free_request()
1464 hfi1_mmu_rb_remove(req->pq->handler, in user_sdma_free_request()
1470 kfree(req->tids); in user_sdma_free_request()
1471 clear_bit(req->info.comp_idx, req->pq->req_in_use); in user_sdma_free_request()