• Home
  • Raw
  • Download

Lines Matching refs:sc

57 static void sc_wait_for_packet_egress(struct send_context *sc, int pause);
561 static void cr_group_addresses(struct send_context *sc, dma_addr_t *dma) in cr_group_addresses() argument
563 u32 gc = group_context(sc->hw_context, sc->group); in cr_group_addresses()
564 u32 index = sc->hw_context & 0x7; in cr_group_addresses()
566 sc->hw_free = &sc->dd->cr_base[sc->node].va[gc].cr[index]; in cr_group_addresses()
568 &((struct credit_return *)sc->dd->cr_base[sc->node].dma)[gc]; in cr_group_addresses()
577 struct send_context *sc; in sc_halted() local
579 sc = container_of(work, struct send_context, halt_work); in sc_halted()
580 sc_restart(sc); in sc_halted()
593 u32 sc_mtu_to_threshold(struct send_context *sc, u32 mtu, u32 hdrqentsize) in sc_mtu_to_threshold() argument
603 if (sc->credits <= release_credits) in sc_mtu_to_threshold()
606 threshold = sc->credits - release_credits; in sc_mtu_to_threshold()
618 u32 sc_percent_to_threshold(struct send_context *sc, u32 percent) in sc_percent_to_threshold() argument
620 return (sc->credits * percent) / 100; in sc_percent_to_threshold()
626 void sc_set_cr_threshold(struct send_context *sc, u32 new_threshold) in sc_set_cr_threshold() argument
632 spin_lock_irqsave(&sc->credit_ctrl_lock, flags); in sc_set_cr_threshold()
634 old_threshold = (sc->credit_ctrl >> in sc_set_cr_threshold()
639 sc->credit_ctrl = in sc_set_cr_threshold()
640 (sc->credit_ctrl in sc_set_cr_threshold()
645 write_kctxt_csr(sc->dd, sc->hw_context, in sc_set_cr_threshold()
646 SC(CREDIT_CTRL), sc->credit_ctrl); in sc_set_cr_threshold()
652 spin_unlock_irqrestore(&sc->credit_ctrl_lock, flags); in sc_set_cr_threshold()
655 sc_return_credits(sc); in sc_set_cr_threshold()
663 void set_pio_integrity(struct send_context *sc) in set_pio_integrity() argument
665 struct hfi1_devdata *dd = sc->dd; in set_pio_integrity()
666 u32 hw_context = sc->hw_context; in set_pio_integrity()
667 int type = sc->type; in set_pio_integrity()
674 static u32 get_buffers_allocated(struct send_context *sc) in get_buffers_allocated() argument
680 ret += *per_cpu_ptr(sc->buffers_allocated, cpu); in get_buffers_allocated()
684 static void reset_buffers_allocated(struct send_context *sc) in reset_buffers_allocated() argument
689 (*per_cpu_ptr(sc->buffers_allocated, cpu)) = 0; in reset_buffers_allocated()
700 struct send_context *sc = NULL; in sc_alloc() local
714 sc = kzalloc_node(sizeof(*sc), GFP_KERNEL, numa); in sc_alloc()
715 if (!sc) in sc_alloc()
718 sc->buffers_allocated = alloc_percpu(u32); in sc_alloc()
719 if (!sc->buffers_allocated) { in sc_alloc()
720 kfree(sc); in sc_alloc()
731 free_percpu(sc->buffers_allocated); in sc_alloc()
732 kfree(sc); in sc_alloc()
737 sci->sc = sc; in sc_alloc()
739 sc->dd = dd; in sc_alloc()
740 sc->node = numa; in sc_alloc()
741 sc->type = type; in sc_alloc()
742 spin_lock_init(&sc->alloc_lock); in sc_alloc()
743 spin_lock_init(&sc->release_lock); in sc_alloc()
744 spin_lock_init(&sc->credit_ctrl_lock); in sc_alloc()
745 seqlock_init(&sc->waitlock); in sc_alloc()
746 INIT_LIST_HEAD(&sc->piowait); in sc_alloc()
747 INIT_WORK(&sc->halt_work, sc_halted); in sc_alloc()
748 init_waitqueue_head(&sc->halt_wait); in sc_alloc()
751 sc->group = 0; in sc_alloc()
753 sc->sw_index = sw_index; in sc_alloc()
754 sc->hw_context = hw_context; in sc_alloc()
755 cr_group_addresses(sc, &dma); in sc_alloc()
756 sc->credits = sci->credits; in sc_alloc()
757 sc->size = sc->credits * PIO_BLOCK_SIZE; in sc_alloc()
762 sc->base_addr = dd->piobase + ((hw_context & PIO_ADDR_CONTEXT_MASK) in sc_alloc()
772 set_pio_integrity(sc); in sc_alloc()
813 thresh = sc_percent_to_threshold(sc, 50); in sc_alloc()
815 thresh = sc_percent_to_threshold(sc, in sc_alloc()
818 thresh = min(sc_percent_to_threshold(sc, 50), in sc_alloc()
819 sc_mtu_to_threshold(sc, hfi1_max_mtu, in sc_alloc()
830 sc->credit_ctrl = reg; in sc_alloc()
854 sc->sr_size = sci->credits + 1; in sc_alloc()
855 sc->sr = kcalloc_node(sc->sr_size, in sc_alloc()
858 if (!sc->sr) { in sc_alloc()
859 sc_free(sc); in sc_alloc()
869 sc->group, in sc_alloc()
870 sc->credits, in sc_alloc()
871 sc->credit_ctrl, in sc_alloc()
874 return sc; in sc_alloc()
878 void sc_free(struct send_context *sc) in sc_free() argument
885 if (!sc) in sc_free()
888 sc->flags |= SCF_IN_FREE; /* ensure no restarts */ in sc_free()
889 dd = sc->dd; in sc_free()
890 if (!list_empty(&sc->piowait)) in sc_free()
892 sw_index = sc->sw_index; in sc_free()
893 hw_context = sc->hw_context; in sc_free()
894 sc_disable(sc); /* make sure the HW is disabled */ in sc_free()
895 flush_work(&sc->halt_work); in sc_free()
898 dd->send_contexts[sw_index].sc = NULL; in sc_free()
913 kfree(sc->sr); in sc_free()
914 free_percpu(sc->buffers_allocated); in sc_free()
915 kfree(sc); in sc_free()
919 void sc_disable(struct send_context *sc) in sc_disable() argument
925 if (!sc) in sc_disable()
929 spin_lock_irq(&sc->alloc_lock); in sc_disable()
930 reg = read_kctxt_csr(sc->dd, sc->hw_context, SC(CTRL)); in sc_disable()
932 sc->flags &= ~SCF_ENABLED; in sc_disable()
933 sc_wait_for_packet_egress(sc, 1); in sc_disable()
934 write_kctxt_csr(sc->dd, sc->hw_context, SC(CTRL), reg); in sc_disable()
944 spin_lock(&sc->release_lock); in sc_disable()
945 if (sc->sr) { /* this context has a shadow ring */ in sc_disable()
946 while (sc->sr_tail != sc->sr_head) { in sc_disable()
947 pbuf = &sc->sr[sc->sr_tail].pbuf; in sc_disable()
950 sc->sr_tail++; in sc_disable()
951 if (sc->sr_tail >= sc->sr_size) in sc_disable()
952 sc->sr_tail = 0; in sc_disable()
955 spin_unlock(&sc->release_lock); in sc_disable()
957 write_seqlock(&sc->waitlock); in sc_disable()
958 list_splice_init(&sc->piowait, &wake_list); in sc_disable()
959 write_sequnlock(&sc->waitlock); in sc_disable()
973 spin_unlock_irq(&sc->alloc_lock); in sc_disable()
1011 static void sc_wait_for_packet_egress(struct send_context *sc, int pause) in sc_wait_for_packet_egress() argument
1013 struct hfi1_devdata *dd = sc->dd; in sc_wait_for_packet_egress()
1020 reg = read_csr(dd, sc->hw_context * 8 + in sc_wait_for_packet_egress()
1023 if (sc->flags & SCF_HALTED || in sc_wait_for_packet_egress()
1024 is_sc_halted(dd, sc->hw_context) || egress_halted(reg)) in sc_wait_for_packet_egress()
1036 __func__, sc->sw_index, in sc_wait_for_packet_egress()
1037 sc->hw_context, (u32)reg); in sc_wait_for_packet_egress()
1056 struct send_context *sc = dd->send_contexts[i].sc; in sc_wait() local
1058 if (!sc) in sc_wait()
1060 sc_wait_for_packet_egress(sc, 0); in sc_wait()
1073 int sc_restart(struct send_context *sc) in sc_restart() argument
1075 struct hfi1_devdata *dd = sc->dd; in sc_restart()
1081 if (!(sc->flags & SCF_HALTED) || (sc->flags & SCF_IN_FREE)) in sc_restart()
1084 dd_dev_info(dd, "restarting send context %u(%u)\n", sc->sw_index, in sc_restart()
1085 sc->hw_context); in sc_restart()
1095 reg = read_kctxt_csr(dd, sc->hw_context, SC(STATUS)); in sc_restart()
1100 __func__, sc->sw_index, sc->hw_context); in sc_restart()
1117 if (sc->type != SC_USER) { in sc_restart()
1121 count = get_buffers_allocated(sc); in sc_restart()
1127 __func__, sc->sw_index, in sc_restart()
1128 sc->hw_context, count); in sc_restart()
1144 sc_disable(sc); in sc_restart()
1152 return sc_enable(sc); in sc_restart()
1162 struct send_context *sc; in pio_freeze() local
1166 sc = dd->send_contexts[i].sc; in pio_freeze()
1172 if (!sc || !(sc->flags & SCF_FROZEN) || sc->type == SC_USER) in pio_freeze()
1176 sc_disable(sc); in pio_freeze()
1189 struct send_context *sc; in pio_kernel_unfreeze() local
1193 sc = dd->send_contexts[i].sc; in pio_kernel_unfreeze()
1194 if (!sc || !(sc->flags & SCF_FROZEN) || sc->type == SC_USER) in pio_kernel_unfreeze()
1196 if (sc->flags & SCF_LINK_DOWN) in pio_kernel_unfreeze()
1199 sc_enable(sc); /* will clear the sc frozen flag */ in pio_kernel_unfreeze()
1217 struct send_context *sc; in pio_kernel_linkup() local
1221 sc = dd->send_contexts[i].sc; in pio_kernel_linkup()
1222 if (!sc || !(sc->flags & SCF_LINK_DOWN) || sc->type == SC_USER) in pio_kernel_linkup()
1225 sc_enable(sc); /* will clear the sc link down flag */ in pio_kernel_linkup()
1285 int sc_enable(struct send_context *sc) in sc_enable() argument
1292 if (!sc) in sc_enable()
1294 dd = sc->dd; in sc_enable()
1303 spin_lock_irqsave(&sc->alloc_lock, flags); in sc_enable()
1304 sc_ctrl = read_kctxt_csr(dd, sc->hw_context, SC(CTRL)); in sc_enable()
1310 *sc->hw_free = 0; in sc_enable()
1311 sc->free = 0; in sc_enable()
1312 sc->alloc_free = 0; in sc_enable()
1313 sc->fill = 0; in sc_enable()
1314 sc->fill_wrap = 0; in sc_enable()
1315 sc->sr_head = 0; in sc_enable()
1316 sc->sr_tail = 0; in sc_enable()
1317 sc->flags = 0; in sc_enable()
1319 reset_buffers_allocated(sc); in sc_enable()
1327 reg = read_kctxt_csr(dd, sc->hw_context, SC(ERR_STATUS)); in sc_enable()
1329 write_kctxt_csr(dd, sc->hw_context, SC(ERR_CLEAR), reg); in sc_enable()
1343 pio = ((sc->hw_context & SEND_PIO_INIT_CTXT_PIO_CTXT_NUM_MASK) << in sc_enable()
1357 sc->sw_index, sc->hw_context, ret); in sc_enable()
1365 write_kctxt_csr(dd, sc->hw_context, SC(CTRL), sc_ctrl); in sc_enable()
1370 read_kctxt_csr(dd, sc->hw_context, SC(CTRL)); in sc_enable()
1371 sc->flags |= SCF_ENABLED; in sc_enable()
1374 spin_unlock_irqrestore(&sc->alloc_lock, flags); in sc_enable()
1380 void sc_return_credits(struct send_context *sc) in sc_return_credits() argument
1382 if (!sc) in sc_return_credits()
1386 write_kctxt_csr(sc->dd, sc->hw_context, SC(CREDIT_FORCE), in sc_return_credits()
1392 read_kctxt_csr(sc->dd, sc->hw_context, SC(CREDIT_FORCE)); in sc_return_credits()
1394 write_kctxt_csr(sc->dd, sc->hw_context, SC(CREDIT_FORCE), 0); in sc_return_credits()
1398 void sc_flush(struct send_context *sc) in sc_flush() argument
1400 if (!sc) in sc_flush()
1403 sc_wait_for_packet_egress(sc, 1); in sc_flush()
1407 void sc_drop(struct send_context *sc) in sc_drop() argument
1409 if (!sc) in sc_drop()
1412 dd_dev_info(sc->dd, "%s: context %u(%u) - not implemented\n", in sc_drop()
1413 __func__, sc->sw_index, sc->hw_context); in sc_drop()
1424 void sc_stop(struct send_context *sc, int flag) in sc_stop() argument
1429 spin_lock_irqsave(&sc->alloc_lock, flags); in sc_stop()
1431 sc->flags |= flag; in sc_stop()
1432 sc->flags &= ~SCF_ENABLED; in sc_stop()
1433 spin_unlock_irqrestore(&sc->alloc_lock, flags); in sc_stop()
1434 wake_up(&sc->halt_wait); in sc_stop()
1451 struct pio_buf *sc_buffer_alloc(struct send_context *sc, u32 dw_len, in sc_buffer_alloc() argument
1462 spin_lock_irqsave(&sc->alloc_lock, flags); in sc_buffer_alloc()
1463 if (!(sc->flags & SCF_ENABLED)) { in sc_buffer_alloc()
1464 spin_unlock_irqrestore(&sc->alloc_lock, flags); in sc_buffer_alloc()
1469 avail = (unsigned long)sc->credits - (sc->fill - sc->alloc_free); in sc_buffer_alloc()
1473 spin_unlock_irqrestore(&sc->alloc_lock, flags); in sc_buffer_alloc()
1477 sc->alloc_free = READ_ONCE(sc->free); in sc_buffer_alloc()
1479 (unsigned long)sc->credits - in sc_buffer_alloc()
1480 (sc->fill - sc->alloc_free); in sc_buffer_alloc()
1483 sc_release_update(sc); in sc_buffer_alloc()
1484 sc->alloc_free = READ_ONCE(sc->free); in sc_buffer_alloc()
1493 this_cpu_inc(*sc->buffers_allocated); in sc_buffer_alloc()
1496 head = sc->sr_head; in sc_buffer_alloc()
1499 sc->fill += blocks; in sc_buffer_alloc()
1500 fill_wrap = sc->fill_wrap; in sc_buffer_alloc()
1501 sc->fill_wrap += blocks; in sc_buffer_alloc()
1502 if (sc->fill_wrap >= sc->credits) in sc_buffer_alloc()
1503 sc->fill_wrap = sc->fill_wrap - sc->credits; in sc_buffer_alloc()
1512 pbuf = &sc->sr[head].pbuf; in sc_buffer_alloc()
1513 pbuf->sent_at = sc->fill; in sc_buffer_alloc()
1516 pbuf->sc = sc; /* could be filled in at sc->sr init time */ in sc_buffer_alloc()
1521 if (next >= sc->sr_size) in sc_buffer_alloc()
1528 sc->sr_head = next; in sc_buffer_alloc()
1529 spin_unlock_irqrestore(&sc->alloc_lock, flags); in sc_buffer_alloc()
1532 pbuf->start = sc->base_addr + fill_wrap * PIO_BLOCK_SIZE; in sc_buffer_alloc()
1533 pbuf->end = sc->base_addr + sc->size; in sc_buffer_alloc()
1552 void sc_add_credit_return_intr(struct send_context *sc) in sc_add_credit_return_intr() argument
1557 spin_lock_irqsave(&sc->credit_ctrl_lock, flags); in sc_add_credit_return_intr()
1558 if (sc->credit_intr_count == 0) { in sc_add_credit_return_intr()
1559 sc->credit_ctrl |= SC(CREDIT_CTRL_CREDIT_INTR_SMASK); in sc_add_credit_return_intr()
1560 write_kctxt_csr(sc->dd, sc->hw_context, in sc_add_credit_return_intr()
1561 SC(CREDIT_CTRL), sc->credit_ctrl); in sc_add_credit_return_intr()
1563 sc->credit_intr_count++; in sc_add_credit_return_intr()
1564 spin_unlock_irqrestore(&sc->credit_ctrl_lock, flags); in sc_add_credit_return_intr()
1571 void sc_del_credit_return_intr(struct send_context *sc) in sc_del_credit_return_intr() argument
1575 WARN_ON(sc->credit_intr_count == 0); in sc_del_credit_return_intr()
1578 spin_lock_irqsave(&sc->credit_ctrl_lock, flags); in sc_del_credit_return_intr()
1579 sc->credit_intr_count--; in sc_del_credit_return_intr()
1580 if (sc->credit_intr_count == 0) { in sc_del_credit_return_intr()
1581 sc->credit_ctrl &= ~SC(CREDIT_CTRL_CREDIT_INTR_SMASK); in sc_del_credit_return_intr()
1582 write_kctxt_csr(sc->dd, sc->hw_context, in sc_del_credit_return_intr()
1583 SC(CREDIT_CTRL), sc->credit_ctrl); in sc_del_credit_return_intr()
1585 spin_unlock_irqrestore(&sc->credit_ctrl_lock, flags); in sc_del_credit_return_intr()
1592 void hfi1_sc_wantpiobuf_intr(struct send_context *sc, u32 needint) in hfi1_sc_wantpiobuf_intr() argument
1595 sc_add_credit_return_intr(sc); in hfi1_sc_wantpiobuf_intr()
1597 sc_del_credit_return_intr(sc); in hfi1_sc_wantpiobuf_intr()
1598 trace_hfi1_wantpiointr(sc, needint, sc->credit_ctrl); in hfi1_sc_wantpiobuf_intr()
1600 sc_return_credits(sc); in hfi1_sc_wantpiobuf_intr()
1611 static void sc_piobufavail(struct send_context *sc) in sc_piobufavail() argument
1613 struct hfi1_devdata *dd = sc->dd; in sc_piobufavail()
1621 if (dd->send_contexts[sc->sw_index].type != SC_KERNEL && in sc_piobufavail()
1622 dd->send_contexts[sc->sw_index].type != SC_VL15) in sc_piobufavail()
1624 list = &sc->piowait; in sc_piobufavail()
1631 write_seqlock_irqsave(&sc->waitlock, flags); in sc_piobufavail()
1658 hfi1_sc_wantpiobuf_intr(sc, 0); in sc_piobufavail()
1660 hfi1_sc_wantpiobuf_intr(sc, 1); in sc_piobufavail()
1662 write_sequnlock_irqrestore(&sc->waitlock, flags); in sc_piobufavail()
1698 void sc_release_update(struct send_context *sc) in sc_release_update() argument
1709 if (!sc) in sc_release_update()
1712 spin_lock_irqsave(&sc->release_lock, flags); in sc_release_update()
1714 hw_free = le64_to_cpu(*sc->hw_free); /* volatile read */ in sc_release_update()
1715 old_free = sc->free; in sc_release_update()
1720 trace_hfi1_piofree(sc, extra); in sc_release_update()
1724 head = READ_ONCE(sc->sr_head); /* snapshot the head */ in sc_release_update()
1725 tail = sc->sr_tail; in sc_release_update()
1727 pbuf = &sc->sr[tail].pbuf; in sc_release_update()
1740 if (tail >= sc->sr_size) in sc_release_update()
1743 sc->sr_tail = tail; in sc_release_update()
1746 sc->free = free; in sc_release_update()
1747 spin_unlock_irqrestore(&sc->release_lock, flags); in sc_release_update()
1748 sc_piobufavail(sc); in sc_release_update()
1762 struct send_context *sc; in sc_group_release_update() local
1773 sc = dd->send_contexts[sw_index].sc; in sc_group_release_update()
1774 if (unlikely(!sc)) in sc_group_release_update()
1777 gc = group_context(hw_context, sc->group); in sc_group_release_update()
1778 gc_end = gc + group_size(sc->group); in sc_group_release_update()
1787 sc_release_update(dd->send_contexts[sw_index].sc); in sc_group_release_update()
1823 return dd->vld[0].sc; in pio_select_send_context_vl()
1830 rval = !rval ? dd->vld[0].sc : rval; in pio_select_send_context_vl()
2024 dd->vld[15].sc = sc_alloc(dd, SC_VL15, in init_pervl_scs()
2026 if (!dd->vld[15].sc) in init_pervl_scs()
2029 hfi1_init_ctxt(dd->vld[15].sc); in init_pervl_scs()
2038 dd->kernel_send_context[0] = dd->vld[15].sc; in init_pervl_scs()
2048 dd->vld[i].sc = sc_alloc(dd, SC_KERNEL, in init_pervl_scs()
2050 if (!dd->vld[i].sc) in init_pervl_scs()
2052 dd->kernel_send_context[i + 1] = dd->vld[i].sc; in init_pervl_scs()
2053 hfi1_init_ctxt(dd->vld[i].sc); in init_pervl_scs()
2065 sc_enable(dd->vld[15].sc); in init_pervl_scs()
2066 ctxt = dd->vld[15].sc->hw_context; in init_pervl_scs()
2071 dd->vld[15].sc->sw_index, ctxt); in init_pervl_scs()
2074 sc_enable(dd->vld[i].sc); in init_pervl_scs()
2075 ctxt = dd->vld[i].sc->hw_context; in init_pervl_scs()
2092 sc_free(dd->vld[i].sc); in init_pervl_scs()
2093 dd->vld[i].sc = NULL; in init_pervl_scs()
2103 sc_free(dd->vld[15].sc); in init_pervl_scs()
2166 struct send_context *sc = sci->sc; in seqfile_dump_sci() local
2172 sc->flags, sc->sw_index, sc->hw_context, sc->group); in seqfile_dump_sci()
2174 sc->sr_size, sc->credits, sc->sr_head, sc->sr_tail); in seqfile_dump_sci()
2176 sc->fill, sc->free, sc->fill_wrap, sc->alloc_free); in seqfile_dump_sci()
2178 sc->credit_intr_count, sc->credit_ctrl); in seqfile_dump_sci()
2179 reg = read_kctxt_csr(sc->dd, sc->hw_context, SC(CREDIT_STATUS)); in seqfile_dump_sci()
2181 (le64_to_cpu(*sc->hw_free) & CR_COUNTER_SMASK) >> in seqfile_dump_sci()