Lines Matching refs:sc
15 static void sc_wait_for_packet_egress(struct send_context *sc, int pause);
519 static void cr_group_addresses(struct send_context *sc, dma_addr_t *dma) in cr_group_addresses() argument
521 u32 gc = group_context(sc->hw_context, sc->group); in cr_group_addresses()
522 u32 index = sc->hw_context & 0x7; in cr_group_addresses()
524 sc->hw_free = &sc->dd->cr_base[sc->node].va[gc].cr[index]; in cr_group_addresses()
526 &((struct credit_return *)sc->dd->cr_base[sc->node].dma)[gc]; in cr_group_addresses()
535 struct send_context *sc; in sc_halted() local
537 sc = container_of(work, struct send_context, halt_work); in sc_halted()
538 sc_restart(sc); in sc_halted()
551 u32 sc_mtu_to_threshold(struct send_context *sc, u32 mtu, u32 hdrqentsize) in sc_mtu_to_threshold() argument
561 if (sc->credits <= release_credits) in sc_mtu_to_threshold()
564 threshold = sc->credits - release_credits; in sc_mtu_to_threshold()
576 u32 sc_percent_to_threshold(struct send_context *sc, u32 percent) in sc_percent_to_threshold() argument
578 return (sc->credits * percent) / 100; in sc_percent_to_threshold()
584 void sc_set_cr_threshold(struct send_context *sc, u32 new_threshold) in sc_set_cr_threshold() argument
590 spin_lock_irqsave(&sc->credit_ctrl_lock, flags); in sc_set_cr_threshold()
592 old_threshold = (sc->credit_ctrl >> in sc_set_cr_threshold()
597 sc->credit_ctrl = in sc_set_cr_threshold()
598 (sc->credit_ctrl in sc_set_cr_threshold()
603 write_kctxt_csr(sc->dd, sc->hw_context, in sc_set_cr_threshold()
604 SC(CREDIT_CTRL), sc->credit_ctrl); in sc_set_cr_threshold()
610 spin_unlock_irqrestore(&sc->credit_ctrl_lock, flags); in sc_set_cr_threshold()
613 sc_return_credits(sc); in sc_set_cr_threshold()
621 void set_pio_integrity(struct send_context *sc) in set_pio_integrity() argument
623 struct hfi1_devdata *dd = sc->dd; in set_pio_integrity()
624 u32 hw_context = sc->hw_context; in set_pio_integrity()
625 int type = sc->type; in set_pio_integrity()
632 static u32 get_buffers_allocated(struct send_context *sc) in get_buffers_allocated() argument
638 ret += *per_cpu_ptr(sc->buffers_allocated, cpu); in get_buffers_allocated()
642 static void reset_buffers_allocated(struct send_context *sc) in reset_buffers_allocated() argument
647 (*per_cpu_ptr(sc->buffers_allocated, cpu)) = 0; in reset_buffers_allocated()
658 struct send_context *sc = NULL; in sc_alloc() local
672 sc = kzalloc_node(sizeof(*sc), GFP_KERNEL, numa); in sc_alloc()
673 if (!sc) in sc_alloc()
676 sc->buffers_allocated = alloc_percpu(u32); in sc_alloc()
677 if (!sc->buffers_allocated) { in sc_alloc()
678 kfree(sc); in sc_alloc()
689 free_percpu(sc->buffers_allocated); in sc_alloc()
690 kfree(sc); in sc_alloc()
695 sci->sc = sc; in sc_alloc()
697 sc->dd = dd; in sc_alloc()
698 sc->node = numa; in sc_alloc()
699 sc->type = type; in sc_alloc()
700 spin_lock_init(&sc->alloc_lock); in sc_alloc()
701 spin_lock_init(&sc->release_lock); in sc_alloc()
702 spin_lock_init(&sc->credit_ctrl_lock); in sc_alloc()
703 seqlock_init(&sc->waitlock); in sc_alloc()
704 INIT_LIST_HEAD(&sc->piowait); in sc_alloc()
705 INIT_WORK(&sc->halt_work, sc_halted); in sc_alloc()
706 init_waitqueue_head(&sc->halt_wait); in sc_alloc()
709 sc->group = 0; in sc_alloc()
711 sc->sw_index = sw_index; in sc_alloc()
712 sc->hw_context = hw_context; in sc_alloc()
713 cr_group_addresses(sc, &dma); in sc_alloc()
714 sc->credits = sci->credits; in sc_alloc()
715 sc->size = sc->credits * PIO_BLOCK_SIZE; in sc_alloc()
720 sc->base_addr = dd->piobase + ((hw_context & PIO_ADDR_CONTEXT_MASK) in sc_alloc()
730 set_pio_integrity(sc); in sc_alloc()
771 thresh = sc_percent_to_threshold(sc, 50); in sc_alloc()
773 thresh = sc_percent_to_threshold(sc, in sc_alloc()
776 thresh = min(sc_percent_to_threshold(sc, 50), in sc_alloc()
777 sc_mtu_to_threshold(sc, hfi1_max_mtu, in sc_alloc()
788 sc->credit_ctrl = reg; in sc_alloc()
812 sc->sr_size = sci->credits + 1; in sc_alloc()
813 sc->sr = kcalloc_node(sc->sr_size, in sc_alloc()
816 if (!sc->sr) { in sc_alloc()
817 sc_free(sc); in sc_alloc()
827 sc->group, in sc_alloc()
828 sc->credits, in sc_alloc()
829 sc->credit_ctrl, in sc_alloc()
832 return sc; in sc_alloc()
836 void sc_free(struct send_context *sc) in sc_free() argument
843 if (!sc) in sc_free()
846 sc->flags |= SCF_IN_FREE; /* ensure no restarts */ in sc_free()
847 dd = sc->dd; in sc_free()
848 if (!list_empty(&sc->piowait)) in sc_free()
850 sw_index = sc->sw_index; in sc_free()
851 hw_context = sc->hw_context; in sc_free()
852 sc_disable(sc); /* make sure the HW is disabled */ in sc_free()
853 flush_work(&sc->halt_work); in sc_free()
856 dd->send_contexts[sw_index].sc = NULL; in sc_free()
871 kfree(sc->sr); in sc_free()
872 free_percpu(sc->buffers_allocated); in sc_free()
873 kfree(sc); in sc_free()
877 void sc_disable(struct send_context *sc) in sc_disable() argument
883 if (!sc) in sc_disable()
887 spin_lock_irq(&sc->alloc_lock); in sc_disable()
888 reg = read_kctxt_csr(sc->dd, sc->hw_context, SC(CTRL)); in sc_disable()
890 sc->flags &= ~SCF_ENABLED; in sc_disable()
891 sc_wait_for_packet_egress(sc, 1); in sc_disable()
892 write_kctxt_csr(sc->dd, sc->hw_context, SC(CTRL), reg); in sc_disable()
902 spin_lock(&sc->release_lock); in sc_disable()
903 if (sc->sr) { /* this context has a shadow ring */ in sc_disable()
904 while (sc->sr_tail != sc->sr_head) { in sc_disable()
905 pbuf = &sc->sr[sc->sr_tail].pbuf; in sc_disable()
908 sc->sr_tail++; in sc_disable()
909 if (sc->sr_tail >= sc->sr_size) in sc_disable()
910 sc->sr_tail = 0; in sc_disable()
913 spin_unlock(&sc->release_lock); in sc_disable()
915 write_seqlock(&sc->waitlock); in sc_disable()
916 list_splice_init(&sc->piowait, &wake_list); in sc_disable()
917 write_sequnlock(&sc->waitlock); in sc_disable()
931 spin_unlock_irq(&sc->alloc_lock); in sc_disable()
969 static void sc_wait_for_packet_egress(struct send_context *sc, int pause) in sc_wait_for_packet_egress() argument
971 struct hfi1_devdata *dd = sc->dd; in sc_wait_for_packet_egress()
978 reg = read_csr(dd, sc->hw_context * 8 + in sc_wait_for_packet_egress()
981 if (sc->flags & SCF_HALTED || in sc_wait_for_packet_egress()
982 is_sc_halted(dd, sc->hw_context) || egress_halted(reg)) in sc_wait_for_packet_egress()
994 __func__, sc->sw_index, in sc_wait_for_packet_egress()
995 sc->hw_context, (u32)reg); in sc_wait_for_packet_egress()
1014 struct send_context *sc = dd->send_contexts[i].sc; in sc_wait() local
1016 if (!sc) in sc_wait()
1018 sc_wait_for_packet_egress(sc, 0); in sc_wait()
1031 int sc_restart(struct send_context *sc) in sc_restart() argument
1033 struct hfi1_devdata *dd = sc->dd; in sc_restart()
1039 if (!(sc->flags & SCF_HALTED) || (sc->flags & SCF_IN_FREE)) in sc_restart()
1042 dd_dev_info(dd, "restarting send context %u(%u)\n", sc->sw_index, in sc_restart()
1043 sc->hw_context); in sc_restart()
1053 reg = read_kctxt_csr(dd, sc->hw_context, SC(STATUS)); in sc_restart()
1058 __func__, sc->sw_index, sc->hw_context); in sc_restart()
1075 if (sc->type != SC_USER) { in sc_restart()
1079 count = get_buffers_allocated(sc); in sc_restart()
1085 __func__, sc->sw_index, in sc_restart()
1086 sc->hw_context, count); in sc_restart()
1102 sc_disable(sc); in sc_restart()
1110 return sc_enable(sc); in sc_restart()
1120 struct send_context *sc; in pio_freeze() local
1124 sc = dd->send_contexts[i].sc; in pio_freeze()
1130 if (!sc || !(sc->flags & SCF_FROZEN) || sc->type == SC_USER) in pio_freeze()
1134 sc_disable(sc); in pio_freeze()
1147 struct send_context *sc; in pio_kernel_unfreeze() local
1151 sc = dd->send_contexts[i].sc; in pio_kernel_unfreeze()
1152 if (!sc || !(sc->flags & SCF_FROZEN) || sc->type == SC_USER) in pio_kernel_unfreeze()
1154 if (sc->flags & SCF_LINK_DOWN) in pio_kernel_unfreeze()
1157 sc_enable(sc); /* will clear the sc frozen flag */ in pio_kernel_unfreeze()
1175 struct send_context *sc; in pio_kernel_linkup() local
1179 sc = dd->send_contexts[i].sc; in pio_kernel_linkup()
1180 if (!sc || !(sc->flags & SCF_LINK_DOWN) || sc->type == SC_USER) in pio_kernel_linkup()
1183 sc_enable(sc); /* will clear the sc link down flag */ in pio_kernel_linkup()
1243 int sc_enable(struct send_context *sc) in sc_enable() argument
1250 if (!sc) in sc_enable()
1252 dd = sc->dd; in sc_enable()
1261 spin_lock_irqsave(&sc->alloc_lock, flags); in sc_enable()
1262 sc_ctrl = read_kctxt_csr(dd, sc->hw_context, SC(CTRL)); in sc_enable()
1268 *sc->hw_free = 0; in sc_enable()
1269 sc->free = 0; in sc_enable()
1270 sc->alloc_free = 0; in sc_enable()
1271 sc->fill = 0; in sc_enable()
1272 sc->fill_wrap = 0; in sc_enable()
1273 sc->sr_head = 0; in sc_enable()
1274 sc->sr_tail = 0; in sc_enable()
1275 sc->flags = 0; in sc_enable()
1277 reset_buffers_allocated(sc); in sc_enable()
1285 reg = read_kctxt_csr(dd, sc->hw_context, SC(ERR_STATUS)); in sc_enable()
1287 write_kctxt_csr(dd, sc->hw_context, SC(ERR_CLEAR), reg); in sc_enable()
1301 pio = ((sc->hw_context & SEND_PIO_INIT_CTXT_PIO_CTXT_NUM_MASK) << in sc_enable()
1315 sc->sw_index, sc->hw_context, ret); in sc_enable()
1323 write_kctxt_csr(dd, sc->hw_context, SC(CTRL), sc_ctrl); in sc_enable()
1328 read_kctxt_csr(dd, sc->hw_context, SC(CTRL)); in sc_enable()
1329 sc->flags |= SCF_ENABLED; in sc_enable()
1332 spin_unlock_irqrestore(&sc->alloc_lock, flags); in sc_enable()
1338 void sc_return_credits(struct send_context *sc) in sc_return_credits() argument
1340 if (!sc) in sc_return_credits()
1344 write_kctxt_csr(sc->dd, sc->hw_context, SC(CREDIT_FORCE), in sc_return_credits()
1350 read_kctxt_csr(sc->dd, sc->hw_context, SC(CREDIT_FORCE)); in sc_return_credits()
1352 write_kctxt_csr(sc->dd, sc->hw_context, SC(CREDIT_FORCE), 0); in sc_return_credits()
1356 void sc_flush(struct send_context *sc) in sc_flush() argument
1358 if (!sc) in sc_flush()
1361 sc_wait_for_packet_egress(sc, 1); in sc_flush()
1365 void sc_drop(struct send_context *sc) in sc_drop() argument
1367 if (!sc) in sc_drop()
1370 dd_dev_info(sc->dd, "%s: context %u(%u) - not implemented\n", in sc_drop()
1371 __func__, sc->sw_index, sc->hw_context); in sc_drop()
1382 void sc_stop(struct send_context *sc, int flag) in sc_stop() argument
1387 spin_lock_irqsave(&sc->alloc_lock, flags); in sc_stop()
1389 sc->flags |= flag; in sc_stop()
1390 sc->flags &= ~SCF_ENABLED; in sc_stop()
1391 spin_unlock_irqrestore(&sc->alloc_lock, flags); in sc_stop()
1392 wake_up(&sc->halt_wait); in sc_stop()
1409 struct pio_buf *sc_buffer_alloc(struct send_context *sc, u32 dw_len, in sc_buffer_alloc() argument
1420 spin_lock_irqsave(&sc->alloc_lock, flags); in sc_buffer_alloc()
1421 if (!(sc->flags & SCF_ENABLED)) { in sc_buffer_alloc()
1422 spin_unlock_irqrestore(&sc->alloc_lock, flags); in sc_buffer_alloc()
1427 avail = (unsigned long)sc->credits - (sc->fill - sc->alloc_free); in sc_buffer_alloc()
1431 spin_unlock_irqrestore(&sc->alloc_lock, flags); in sc_buffer_alloc()
1435 sc->alloc_free = READ_ONCE(sc->free); in sc_buffer_alloc()
1437 (unsigned long)sc->credits - in sc_buffer_alloc()
1438 (sc->fill - sc->alloc_free); in sc_buffer_alloc()
1441 sc_release_update(sc); in sc_buffer_alloc()
1442 sc->alloc_free = READ_ONCE(sc->free); in sc_buffer_alloc()
1451 this_cpu_inc(*sc->buffers_allocated); in sc_buffer_alloc()
1454 head = sc->sr_head; in sc_buffer_alloc()
1457 sc->fill += blocks; in sc_buffer_alloc()
1458 fill_wrap = sc->fill_wrap; in sc_buffer_alloc()
1459 sc->fill_wrap += blocks; in sc_buffer_alloc()
1460 if (sc->fill_wrap >= sc->credits) in sc_buffer_alloc()
1461 sc->fill_wrap = sc->fill_wrap - sc->credits; in sc_buffer_alloc()
1470 pbuf = &sc->sr[head].pbuf; in sc_buffer_alloc()
1471 pbuf->sent_at = sc->fill; in sc_buffer_alloc()
1474 pbuf->sc = sc; /* could be filled in at sc->sr init time */ in sc_buffer_alloc()
1479 if (next >= sc->sr_size) in sc_buffer_alloc()
1486 sc->sr_head = next; in sc_buffer_alloc()
1487 spin_unlock_irqrestore(&sc->alloc_lock, flags); in sc_buffer_alloc()
1490 pbuf->start = sc->base_addr + fill_wrap * PIO_BLOCK_SIZE; in sc_buffer_alloc()
1491 pbuf->end = sc->base_addr + sc->size; in sc_buffer_alloc()
1510 void sc_add_credit_return_intr(struct send_context *sc) in sc_add_credit_return_intr() argument
1515 spin_lock_irqsave(&sc->credit_ctrl_lock, flags); in sc_add_credit_return_intr()
1516 if (sc->credit_intr_count == 0) { in sc_add_credit_return_intr()
1517 sc->credit_ctrl |= SC(CREDIT_CTRL_CREDIT_INTR_SMASK); in sc_add_credit_return_intr()
1518 write_kctxt_csr(sc->dd, sc->hw_context, in sc_add_credit_return_intr()
1519 SC(CREDIT_CTRL), sc->credit_ctrl); in sc_add_credit_return_intr()
1521 sc->credit_intr_count++; in sc_add_credit_return_intr()
1522 spin_unlock_irqrestore(&sc->credit_ctrl_lock, flags); in sc_add_credit_return_intr()
1529 void sc_del_credit_return_intr(struct send_context *sc) in sc_del_credit_return_intr() argument
1533 WARN_ON(sc->credit_intr_count == 0); in sc_del_credit_return_intr()
1536 spin_lock_irqsave(&sc->credit_ctrl_lock, flags); in sc_del_credit_return_intr()
1537 sc->credit_intr_count--; in sc_del_credit_return_intr()
1538 if (sc->credit_intr_count == 0) { in sc_del_credit_return_intr()
1539 sc->credit_ctrl &= ~SC(CREDIT_CTRL_CREDIT_INTR_SMASK); in sc_del_credit_return_intr()
1540 write_kctxt_csr(sc->dd, sc->hw_context, in sc_del_credit_return_intr()
1541 SC(CREDIT_CTRL), sc->credit_ctrl); in sc_del_credit_return_intr()
1543 spin_unlock_irqrestore(&sc->credit_ctrl_lock, flags); in sc_del_credit_return_intr()
1550 void hfi1_sc_wantpiobuf_intr(struct send_context *sc, u32 needint) in hfi1_sc_wantpiobuf_intr() argument
1553 sc_add_credit_return_intr(sc); in hfi1_sc_wantpiobuf_intr()
1555 sc_del_credit_return_intr(sc); in hfi1_sc_wantpiobuf_intr()
1556 trace_hfi1_wantpiointr(sc, needint, sc->credit_ctrl); in hfi1_sc_wantpiobuf_intr()
1558 sc_return_credits(sc); in hfi1_sc_wantpiobuf_intr()
1569 static void sc_piobufavail(struct send_context *sc) in sc_piobufavail() argument
1571 struct hfi1_devdata *dd = sc->dd; in sc_piobufavail()
1579 if (dd->send_contexts[sc->sw_index].type != SC_KERNEL && in sc_piobufavail()
1580 dd->send_contexts[sc->sw_index].type != SC_VL15) in sc_piobufavail()
1582 list = &sc->piowait; in sc_piobufavail()
1589 write_seqlock_irqsave(&sc->waitlock, flags); in sc_piobufavail()
1616 hfi1_sc_wantpiobuf_intr(sc, 0); in sc_piobufavail()
1618 hfi1_sc_wantpiobuf_intr(sc, 1); in sc_piobufavail()
1620 write_sequnlock_irqrestore(&sc->waitlock, flags); in sc_piobufavail()
1656 void sc_release_update(struct send_context *sc) in sc_release_update() argument
1667 if (!sc) in sc_release_update()
1670 spin_lock_irqsave(&sc->release_lock, flags); in sc_release_update()
1672 hw_free = le64_to_cpu(*sc->hw_free); /* volatile read */ in sc_release_update()
1673 old_free = sc->free; in sc_release_update()
1678 trace_hfi1_piofree(sc, extra); in sc_release_update()
1682 head = READ_ONCE(sc->sr_head); /* snapshot the head */ in sc_release_update()
1683 tail = sc->sr_tail; in sc_release_update()
1685 pbuf = &sc->sr[tail].pbuf; in sc_release_update()
1698 if (tail >= sc->sr_size) in sc_release_update()
1701 sc->sr_tail = tail; in sc_release_update()
1704 sc->free = free; in sc_release_update()
1705 spin_unlock_irqrestore(&sc->release_lock, flags); in sc_release_update()
1706 sc_piobufavail(sc); in sc_release_update()
1720 struct send_context *sc; in sc_group_release_update() local
1731 sc = dd->send_contexts[sw_index].sc; in sc_group_release_update()
1732 if (unlikely(!sc)) in sc_group_release_update()
1735 gc = group_context(hw_context, sc->group); in sc_group_release_update()
1736 gc_end = gc + group_size(sc->group); in sc_group_release_update()
1745 sc_release_update(dd->send_contexts[sw_index].sc); in sc_group_release_update()
1781 return dd->vld[0].sc; in pio_select_send_context_vl()
1788 rval = !rval ? dd->vld[0].sc : rval; in pio_select_send_context_vl()
1979 dd->vld[15].sc = sc_alloc(dd, SC_VL15, in init_pervl_scs()
1981 if (!dd->vld[15].sc) in init_pervl_scs()
1984 hfi1_init_ctxt(dd->vld[15].sc); in init_pervl_scs()
1993 dd->kernel_send_context[0] = dd->vld[15].sc; in init_pervl_scs()
2003 dd->vld[i].sc = sc_alloc(dd, SC_KERNEL, in init_pervl_scs()
2005 if (!dd->vld[i].sc) in init_pervl_scs()
2007 dd->kernel_send_context[i + 1] = dd->vld[i].sc; in init_pervl_scs()
2008 hfi1_init_ctxt(dd->vld[i].sc); in init_pervl_scs()
2020 sc_enable(dd->vld[15].sc); in init_pervl_scs()
2021 ctxt = dd->vld[15].sc->hw_context; in init_pervl_scs()
2026 dd->vld[15].sc->sw_index, ctxt); in init_pervl_scs()
2029 sc_enable(dd->vld[i].sc); in init_pervl_scs()
2030 ctxt = dd->vld[i].sc->hw_context; in init_pervl_scs()
2047 sc_free(dd->vld[i].sc); in init_pervl_scs()
2048 dd->vld[i].sc = NULL; in init_pervl_scs()
2058 sc_free(dd->vld[15].sc); in init_pervl_scs()
2125 struct send_context *sc = sci->sc; in seqfile_dump_sci() local
2131 sc->flags, sc->sw_index, sc->hw_context, sc->group); in seqfile_dump_sci()
2133 sc->sr_size, sc->credits, sc->sr_head, sc->sr_tail); in seqfile_dump_sci()
2135 sc->fill, sc->free, sc->fill_wrap, sc->alloc_free); in seqfile_dump_sci()
2137 sc->credit_intr_count, sc->credit_ctrl); in seqfile_dump_sci()
2138 reg = read_kctxt_csr(sc->dd, sc->hw_context, SC(CREDIT_STATUS)); in seqfile_dump_sci()
2140 (le64_to_cpu(*sc->hw_free) & CR_COUNTER_SMASK) >> in seqfile_dump_sci()