Lines Matching full:req
38 static int user_sdma_send_pkts(struct user_sdma_request *req, u16 maxpkts);
41 static void user_sdma_free_request(struct user_sdma_request *req);
42 static int check_header_template(struct user_sdma_request *req,
45 static int set_txreq_header(struct user_sdma_request *req,
47 static int set_txreq_header_ahg(struct user_sdma_request *req,
290 struct user_sdma_request *req; in hfi1_user_sdma_process_request() local
297 if (iovec[idx].iov_len < sizeof(info) + sizeof(req->hdr)) { in hfi1_user_sdma_process_request()
302 iovec[idx].iov_len, sizeof(info) + sizeof(req->hdr)); in hfi1_user_sdma_process_request()
352 req = pq->reqs + info.comp_idx; in hfi1_user_sdma_process_request()
353 req->data_iovs = req_iovcnt(info.ctrl) - 1; /* subtract header vector */ in hfi1_user_sdma_process_request()
354 req->data_len = 0; in hfi1_user_sdma_process_request()
355 req->pq = pq; in hfi1_user_sdma_process_request()
356 req->cq = cq; in hfi1_user_sdma_process_request()
357 req->ahg_idx = -1; in hfi1_user_sdma_process_request()
358 req->iov_idx = 0; in hfi1_user_sdma_process_request()
359 req->sent = 0; in hfi1_user_sdma_process_request()
360 req->seqnum = 0; in hfi1_user_sdma_process_request()
361 req->seqcomp = 0; in hfi1_user_sdma_process_request()
362 req->seqsubmitted = 0; in hfi1_user_sdma_process_request()
363 req->tids = NULL; in hfi1_user_sdma_process_request()
364 req->has_error = 0; in hfi1_user_sdma_process_request()
365 INIT_LIST_HEAD(&req->txps); in hfi1_user_sdma_process_request()
367 memcpy(&req->info, &info, sizeof(info)); in hfi1_user_sdma_process_request()
374 if (req->data_iovs < 2) { in hfi1_user_sdma_process_request()
375 SDMA_DBG(req, in hfi1_user_sdma_process_request()
380 req->data_iovs--; in hfi1_user_sdma_process_request()
383 if (!info.npkts || req->data_iovs > MAX_VECTORS_PER_REQ) { in hfi1_user_sdma_process_request()
384 SDMA_DBG(req, "Too many vectors (%u/%u)", req->data_iovs, in hfi1_user_sdma_process_request()
391 ret = copy_from_user(&req->hdr, iovec[idx].iov_base + sizeof(info), in hfi1_user_sdma_process_request()
392 sizeof(req->hdr)); in hfi1_user_sdma_process_request()
394 SDMA_DBG(req, "Failed to copy header template (%d)", ret); in hfi1_user_sdma_process_request()
401 req->hdr.pbc[2] = 0; in hfi1_user_sdma_process_request()
404 opcode = (be32_to_cpu(req->hdr.bth[0]) >> 24) & 0xff; in hfi1_user_sdma_process_request()
407 SDMA_DBG(req, "Invalid opcode (%d)", opcode); in hfi1_user_sdma_process_request()
416 vl = (le16_to_cpu(req->hdr.pbc[0]) >> 12) & 0xF; in hfi1_user_sdma_process_request()
417 sc = (((be16_to_cpu(req->hdr.lrh[0]) >> 12) & 0xF) | in hfi1_user_sdma_process_request()
418 (((le16_to_cpu(req->hdr.pbc[1]) >> 14) & 0x1) << 4)); in hfi1_user_sdma_process_request()
421 SDMA_DBG(req, "Invalid SC(%u)/VL(%u)", sc, vl); in hfi1_user_sdma_process_request()
427 pkey = (u16)be32_to_cpu(req->hdr.bth[0]); in hfi1_user_sdma_process_request()
428 slid = be16_to_cpu(req->hdr.lrh[3]); in hfi1_user_sdma_process_request()
439 if ((be16_to_cpu(req->hdr.lrh[0]) & 0x3) == HFI1_LRH_GRH) { in hfi1_user_sdma_process_request()
440 SDMA_DBG(req, "User tried to pass in a GRH"); in hfi1_user_sdma_process_request()
445 req->koffset = le32_to_cpu(req->hdr.kdeth.swdata[6]); in hfi1_user_sdma_process_request()
450 req->tidoffset = KDETH_GET(req->hdr.kdeth.ver_tid_offset, OFFSET) * in hfi1_user_sdma_process_request()
451 (KDETH_GET(req->hdr.kdeth.ver_tid_offset, OM) ? in hfi1_user_sdma_process_request()
454 info.comp_idx, req->tidoffset); in hfi1_user_sdma_process_request()
458 for (i = 0; i < req->data_iovs; i++) { in hfi1_user_sdma_process_request()
459 req->iovs[i].offset = 0; in hfi1_user_sdma_process_request()
460 INIT_LIST_HEAD(&req->iovs[i].list); in hfi1_user_sdma_process_request()
461 memcpy(&req->iovs[i].iov, in hfi1_user_sdma_process_request()
463 sizeof(req->iovs[i].iov)); in hfi1_user_sdma_process_request()
464 if (req->iovs[i].iov.iov_len == 0) { in hfi1_user_sdma_process_request()
468 req->data_len += req->iovs[i].iov.iov_len; in hfi1_user_sdma_process_request()
471 info.comp_idx, req->data_len); in hfi1_user_sdma_process_request()
472 if (pcount > req->info.npkts) in hfi1_user_sdma_process_request()
473 pcount = req->info.npkts; in hfi1_user_sdma_process_request()
482 if (req_opcode(req->info.ctrl) == EXPECTED) { in hfi1_user_sdma_process_request()
483 u16 ntids = iovec[idx].iov_len / sizeof(*req->tids); in hfi1_user_sdma_process_request()
498 ntids, sizeof(*req->tids)); in hfi1_user_sdma_process_request()
501 SDMA_DBG(req, "Failed to copy %d TIDs (%d)", in hfi1_user_sdma_process_request()
505 req->tids = tmp; in hfi1_user_sdma_process_request()
506 req->n_tids = ntids; in hfi1_user_sdma_process_request()
507 req->tididx = 0; in hfi1_user_sdma_process_request()
511 dlid = be16_to_cpu(req->hdr.lrh[1]); in hfi1_user_sdma_process_request()
514 req->sde = sdma_select_user_engine(dd, selector, vl); in hfi1_user_sdma_process_request()
516 if (!req->sde || !sdma_running(req->sde)) { in hfi1_user_sdma_process_request()
522 if (req->info.npkts > 1 && HFI1_CAP_IS_USET(SDMA_AHG)) in hfi1_user_sdma_process_request()
523 req->ahg_idx = sdma_ahg_alloc(req->sde); in hfi1_user_sdma_process_request()
534 while (req->seqsubmitted != req->info.npkts) { in hfi1_user_sdma_process_request()
535 ret = user_sdma_send_pkts(req, pcount); in hfi1_user_sdma_process_request()
559 if (req->seqsubmitted < req->info.npkts) { in hfi1_user_sdma_process_request()
560 if (req->seqsubmitted) in hfi1_user_sdma_process_request()
562 (req->seqcomp == req->seqsubmitted - 1)); in hfi1_user_sdma_process_request()
563 user_sdma_free_request(req); in hfi1_user_sdma_process_request()
570 static inline u32 compute_data_length(struct user_sdma_request *req, in compute_data_length() argument
587 if (!req->seqnum) { in compute_data_length()
588 if (req->data_len < sizeof(u32)) in compute_data_length()
589 len = req->data_len; in compute_data_length()
591 len = ((be16_to_cpu(req->hdr.lrh[2]) << 2) - in compute_data_length()
593 } else if (req_opcode(req->info.ctrl) == EXPECTED) { in compute_data_length()
594 u32 tidlen = EXP_TID_GET(req->tids[req->tididx], LEN) * in compute_data_length()
600 len = min(tidlen - req->tidoffset, (u32)req->info.fragsize); in compute_data_length()
602 if (unlikely(!len) && ++req->tididx < req->n_tids && in compute_data_length()
603 req->tids[req->tididx]) { in compute_data_length()
604 tidlen = EXP_TID_GET(req->tids[req->tididx], in compute_data_length()
606 req->tidoffset = 0; in compute_data_length()
607 len = min_t(u32, tidlen, req->info.fragsize); in compute_data_length()
614 len = min(len, req->data_len - req->sent); in compute_data_length()
616 len = min(req->data_len - req->sent, (u32)req->info.fragsize); in compute_data_length()
618 trace_hfi1_sdma_user_compute_length(req->pq->dd, in compute_data_length()
619 req->pq->ctxt, in compute_data_length()
620 req->pq->subctxt, in compute_data_length()
621 req->info.comp_idx, in compute_data_length()
639 static int user_sdma_txadd_ahg(struct user_sdma_request *req, in user_sdma_txadd_ahg() argument
644 u16 pbclen = le16_to_cpu(req->hdr.pbc[0]); in user_sdma_txadd_ahg()
645 u32 lrhlen = get_lrh_len(req->hdr, pad_len(datalen)); in user_sdma_txadd_ahg()
646 struct hfi1_user_sdma_pkt_q *pq = req->pq; in user_sdma_txadd_ahg()
656 memcpy(&tx->hdr, &req->hdr, sizeof(tx->hdr)); in user_sdma_txadd_ahg()
661 ret = check_header_template(req, &tx->hdr, lrhlen, datalen); in user_sdma_txadd_ahg()
665 sizeof(tx->hdr) + datalen, req->ahg_idx, in user_sdma_txadd_ahg()
675 static int user_sdma_send_pkts(struct user_sdma_request *req, u16 maxpkts) in user_sdma_send_pkts() argument
684 if (!req->pq) in user_sdma_send_pkts()
687 pq = req->pq; in user_sdma_send_pkts()
690 if (READ_ONCE(req->has_error)) in user_sdma_send_pkts()
696 if (unlikely(req->seqnum == req->info.npkts)) { in user_sdma_send_pkts()
697 if (!list_empty(&req->txps)) in user_sdma_send_pkts()
702 if (!maxpkts || maxpkts > req->info.npkts - req->seqnum) in user_sdma_send_pkts()
703 maxpkts = req->info.npkts - req->seqnum; in user_sdma_send_pkts()
713 if (READ_ONCE(req->has_error)) in user_sdma_send_pkts()
721 tx->req = req; in user_sdma_send_pkts()
728 if (req->seqnum == req->info.npkts - 1) in user_sdma_send_pkts()
737 if (req->data_len) { in user_sdma_send_pkts()
738 iovec = &req->iovs[req->iov_idx]; in user_sdma_send_pkts()
740 if (++req->iov_idx == req->data_iovs) { in user_sdma_send_pkts()
744 iovec = &req->iovs[req->iov_idx]; in user_sdma_send_pkts()
748 datalen = compute_data_length(req, tx); in user_sdma_send_pkts()
759 SDMA_DBG(req, in user_sdma_send_pkts()
768 if (req->ahg_idx >= 0) { in user_sdma_send_pkts()
769 if (!req->seqnum) { in user_sdma_send_pkts()
770 ret = user_sdma_txadd_ahg(req, tx, datalen); in user_sdma_send_pkts()
776 changes = set_txreq_header_ahg(req, tx, in user_sdma_send_pkts()
784 ret = sdma_txinit(&tx->txreq, 0, sizeof(req->hdr) + in user_sdma_send_pkts()
794 ret = set_txreq_header(req, tx, datalen); in user_sdma_send_pkts()
799 req->koffset += datalen; in user_sdma_send_pkts()
800 if (req_opcode(req->info.ctrl) == EXPECTED) in user_sdma_send_pkts()
801 req->tidoffset += datalen; in user_sdma_send_pkts()
802 req->sent += datalen; in user_sdma_send_pkts()
804 ret = hfi1_add_pages_to_sdma_packet(req, tx, iovec, in user_sdma_send_pkts()
808 iovec = &req->iovs[req->iov_idx]; in user_sdma_send_pkts()
810 list_add_tail(&tx->txreq.list, &req->txps); in user_sdma_send_pkts()
816 tx->seqnum = req->seqnum++; in user_sdma_send_pkts()
820 ret = sdma_send_txlist(req->sde, in user_sdma_send_pkts()
822 &req->txps, &count); in user_sdma_send_pkts()
823 req->seqsubmitted += count; in user_sdma_send_pkts()
824 if (req->seqsubmitted == req->info.npkts) { in user_sdma_send_pkts()
831 if (req->ahg_idx >= 0) in user_sdma_send_pkts()
832 sdma_ahg_free(req->sde, req->ahg_idx); in user_sdma_send_pkts()
843 static int check_header_template(struct user_sdma_request *req, in check_header_template() argument
857 if (req->info.fragsize % PIO_BLOCK_SIZE || lrhlen & 0x3 || in check_header_template()
858 lrhlen > get_lrh_len(*hdr, req->info.fragsize)) in check_header_template()
861 if (req_opcode(req->info.ctrl) == EXPECTED) { in check_header_template()
868 u32 tidval = req->tids[req->tididx], in check_header_template()
876 (KDETH_GET(req->hdr.kdeth.ver_tid_offset, OM) ? in check_header_template()
913 static int set_txreq_header(struct user_sdma_request *req, in set_txreq_header() argument
916 struct hfi1_user_sdma_pkt_q *pq = req->pq; in set_txreq_header()
924 memcpy(hdr, &req->hdr, sizeof(*hdr)); in set_txreq_header()
941 if (unlikely(req->seqnum == 2)) { in set_txreq_header()
949 req->hdr.pbc[0] = hdr->pbc[0]; in set_txreq_header()
950 req->hdr.lrh[2] = hdr->lrh[2]; in set_txreq_header()
958 if (unlikely(!req->seqnum)) { in set_txreq_header()
959 ret = check_header_template(req, hdr, lrhlen, datalen); in set_txreq_header()
967 (req_opcode(req->info.ctrl) == EXPECTED), in set_txreq_header()
968 req->seqnum)); in set_txreq_header()
975 hdr->kdeth.swdata[6] = cpu_to_le32(req->koffset); in set_txreq_header()
977 if (req_opcode(req->info.ctrl) == EXPECTED) { in set_txreq_header()
978 tidval = req->tids[req->tididx]; in set_txreq_header()
983 if ((req->tidoffset) == (EXP_TID_GET(tidval, LEN) * in set_txreq_header()
985 req->tidoffset = 0; in set_txreq_header()
990 if (++req->tididx > req->n_tids - 1 || in set_txreq_header()
991 !req->tids[req->tididx]) { in set_txreq_header()
994 tidval = req->tids[req->tididx]; in set_txreq_header()
1013 pq->dd, pq->ctxt, pq->subctxt, req->info.comp_idx, in set_txreq_header()
1014 req->tidoffset, req->tidoffset >> omfactor, in set_txreq_header()
1017 req->tidoffset >> omfactor); in set_txreq_header()
1023 req->info.comp_idx, hdr, tidval); in set_txreq_header()
1027 static int set_txreq_header_ahg(struct user_sdma_request *req, in set_txreq_header_ahg() argument
1033 struct hfi1_user_sdma_pkt_q *pq = req->pq; in set_txreq_header_ahg()
1034 struct hfi1_pkt_header *hdr = &req->hdr; in set_txreq_header_ahg()
1056 val32 = (be32_to_cpu(hdr->bth[2]) + req->seqnum) & in set_txreq_header_ahg()
1070 (__force u16)cpu_to_le16(req->koffset & 0xffff)); in set_txreq_header_ahg()
1074 (__force u16)cpu_to_le16(req->koffset >> 16)); in set_txreq_header_ahg()
1077 if (req_opcode(req->info.ctrl) == EXPECTED) { in set_txreq_header_ahg()
1080 tidval = req->tids[req->tididx]; in set_txreq_header_ahg()
1086 if ((req->tidoffset) == (EXP_TID_GET(tidval, LEN) * in set_txreq_header_ahg()
1088 req->tidoffset = 0; in set_txreq_header_ahg()
1093 if (++req->tididx > req->n_tids - 1 || in set_txreq_header_ahg()
1094 !req->tids[req->tididx]) in set_txreq_header_ahg()
1096 tidval = req->tids[req->tididx]; in set_txreq_header_ahg()
1106 ((req->tidoffset >> omfactor) in set_txreq_header_ahg()
1133 req->info.comp_idx, req->sde->this_idx, in set_txreq_header_ahg()
1134 req->ahg_idx, ahg, idx, tidval); in set_txreq_header_ahg()
1137 datalen, req->ahg_idx, idx, in set_txreq_header_ahg()
1138 ahg, sizeof(req->hdr), in set_txreq_header_ahg()
1158 struct user_sdma_request *req; in user_sdma_txreq_cb() local
1163 if (!tx->req) in user_sdma_txreq_cb()
1166 req = tx->req; in user_sdma_txreq_cb()
1167 pq = req->pq; in user_sdma_txreq_cb()
1168 cq = req->cq; in user_sdma_txreq_cb()
1171 SDMA_DBG(req, "SDMA completion with error %d", in user_sdma_txreq_cb()
1173 WRITE_ONCE(req->has_error, 1); in user_sdma_txreq_cb()
1177 req->seqcomp = tx->seqnum; in user_sdma_txreq_cb()
1181 if (req->seqcomp != req->info.npkts - 1) in user_sdma_txreq_cb()
1184 user_sdma_free_request(req); in user_sdma_txreq_cb()
1185 set_comp_state(pq, cq, req->info.comp_idx, state, status); in user_sdma_txreq_cb()
1195 static void user_sdma_free_request(struct user_sdma_request *req) in user_sdma_free_request() argument
1197 if (!list_empty(&req->txps)) { in user_sdma_free_request()
1200 list_for_each_entry_safe(t, p, &req->txps, list) { in user_sdma_free_request()
1204 sdma_txclean(req->pq->dd, t); in user_sdma_free_request()
1205 kmem_cache_free(req->pq->txreq_cache, tx); in user_sdma_free_request()
1209 kfree(req->tids); in user_sdma_free_request()
1210 clear_bit(req->info.comp_idx, req->pq->req_in_use); in user_sdma_free_request()