^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* SCTP kernel implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * (C) Copyright Red Hat Inc. 2017
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * This file is part of the SCTP kernel implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * These functions manipulate sctp stream queue/scheduling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Please send any bug reports or fixes you make to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * email addresched(es):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * lksctp developers <linux-sctp@vger.kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Written or modified by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <net/sctp/sctp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <net/sctp/sm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <net/sctp/stream_sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /* Priority handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * RFC DRAFT ndata section 3.4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static void sctp_sched_prio_unsched_all(struct sctp_stream *stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static struct sctp_stream_priorities *sctp_sched_prio_new_head(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct sctp_stream *stream, int prio, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct sctp_stream_priorities *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) p = kmalloc(sizeof(*p), gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) INIT_LIST_HEAD(&p->prio_sched);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) INIT_LIST_HEAD(&p->active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) p->next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) p->prio = prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static struct sctp_stream_priorities *sctp_sched_prio_get_head(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct sctp_stream *stream, int prio, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct sctp_stream_priorities *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /* Look into scheduled priorities first, as they are sorted and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * we can find it fast IF it's scheduled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) list_for_each_entry(p, &stream->prio_list, prio_sched) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (p->prio == prio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if (p->prio > prio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /* No luck. So we search on all streams now. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) for (i = 0; i < stream->outcnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (!SCTP_SO(stream, i)->ext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) p = SCTP_SO(stream, i)->ext->prio_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /* Means all other streams won't be initialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (p->prio == prio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /* If not even there, allocate a new one. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return sctp_sched_prio_new_head(stream, prio, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static void sctp_sched_prio_next_stream(struct sctp_stream_priorities *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct list_head *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) pos = p->next->prio_list.next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (pos == &p->active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) pos = pos->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) p->next = list_entry(pos, struct sctp_stream_out_ext, prio_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static bool sctp_sched_prio_unsched(struct sctp_stream_out_ext *soute)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) bool scheduled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (!list_empty(&soute->prio_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct sctp_stream_priorities *prio_head = soute->prio_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /* Scheduled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) scheduled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (prio_head->next == soute)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /* Try to move to the next stream */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) sctp_sched_prio_next_stream(prio_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) list_del_init(&soute->prio_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /* Also unsched the priority if this was the last stream */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (list_empty(&prio_head->active)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) list_del_init(&prio_head->prio_sched);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /* If there is no stream left, clear next */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) prio_head->next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return scheduled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static void sctp_sched_prio_sched(struct sctp_stream *stream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct sctp_stream_out_ext *soute)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct sctp_stream_priorities *prio, *prio_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) prio_head = soute->prio_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /* Nothing to do if already scheduled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (!list_empty(&soute->prio_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /* Schedule the stream. If there is a next, we schedule the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * one before it, so it's the last in round robin order.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * If there isn't, we also have to schedule the priority.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (prio_head->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) list_add(&soute->prio_list, prio_head->next->prio_list.prev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) list_add(&soute->prio_list, &prio_head->active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) prio_head->next = soute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) list_for_each_entry(prio, &stream->prio_list, prio_sched) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (prio->prio > prio_head->prio) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) list_add(&prio_head->prio_sched, prio->prio_sched.prev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) list_add_tail(&prio_head->prio_sched, &stream->prio_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static int sctp_sched_prio_set(struct sctp_stream *stream, __u16 sid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) __u16 prio, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct sctp_stream_out *sout = SCTP_SO(stream, sid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct sctp_stream_out_ext *soute = sout->ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct sctp_stream_priorities *prio_head, *old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) bool reschedule = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) prio_head = sctp_sched_prio_get_head(stream, prio, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (!prio_head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) reschedule = sctp_sched_prio_unsched(soute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) old = soute->prio_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) soute->prio_head = prio_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (reschedule)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) sctp_sched_prio_sched(stream, soute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (!old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /* Happens when we set the priority for the first time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) for (i = 0; i < stream->outcnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) soute = SCTP_SO(stream, i)->ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (soute && soute->prio_head == old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /* It's still in use, nothing else to do here. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /* No hits, we are good to free it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) kfree(old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static int sctp_sched_prio_get(struct sctp_stream *stream, __u16 sid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) __u16 *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) *value = SCTP_SO(stream, sid)->ext->prio_head->prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static int sctp_sched_prio_init(struct sctp_stream *stream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) INIT_LIST_HEAD(&stream->prio_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static int sctp_sched_prio_init_sid(struct sctp_stream *stream, __u16 sid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) INIT_LIST_HEAD(&SCTP_SO(stream, sid)->ext->prio_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return sctp_sched_prio_set(stream, sid, 0, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static void sctp_sched_prio_free(struct sctp_stream *stream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) struct sctp_stream_priorities *prio, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) LIST_HEAD(list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /* As we don't keep a list of priorities, to avoid multiple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * frees we have to do it in 3 steps:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * 1. unsched everyone, so the lists are free to use in 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * 2. build the list of the priorities
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * 3. free the list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) sctp_sched_prio_unsched_all(stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) for (i = 0; i < stream->outcnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (!SCTP_SO(stream, i)->ext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) prio = SCTP_SO(stream, i)->ext->prio_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (prio && list_empty(&prio->prio_sched))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) list_add(&prio->prio_sched, &list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) list_for_each_entry_safe(prio, n, &list, prio_sched) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) list_del_init(&prio->prio_sched);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) kfree(prio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static void sctp_sched_prio_enqueue(struct sctp_outq *q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct sctp_datamsg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) struct sctp_stream *stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct sctp_chunk *ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) __u16 sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) ch = list_first_entry(&msg->chunks, struct sctp_chunk, frag_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) sid = sctp_chunk_stream_no(ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) stream = &q->asoc->stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) sctp_sched_prio_sched(stream, SCTP_SO(stream, sid)->ext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static struct sctp_chunk *sctp_sched_prio_dequeue(struct sctp_outq *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) struct sctp_stream *stream = &q->asoc->stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct sctp_stream_priorities *prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) struct sctp_stream_out_ext *soute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct sctp_chunk *ch = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /* Bail out quickly if queue is empty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (list_empty(&q->out_chunk_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) /* Find which chunk is next. It's easy, it's either the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * one or the first chunk on the next active stream.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (stream->out_curr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) soute = stream->out_curr->ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) prio = list_entry(stream->prio_list.next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) struct sctp_stream_priorities, prio_sched);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) soute = prio->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) ch = list_entry(soute->outq.next, struct sctp_chunk, stream_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) sctp_sched_dequeue_common(q, ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) return ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static void sctp_sched_prio_dequeue_done(struct sctp_outq *q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct sctp_chunk *ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct sctp_stream_priorities *prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) struct sctp_stream_out_ext *soute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) __u16 sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) /* Last chunk on that msg, move to the next stream on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * this priority.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) sid = sctp_chunk_stream_no(ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) soute = SCTP_SO(&q->asoc->stream, sid)->ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) prio = soute->prio_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) sctp_sched_prio_next_stream(prio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (list_empty(&soute->outq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) sctp_sched_prio_unsched(soute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static void sctp_sched_prio_sched_all(struct sctp_stream *stream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct sctp_stream_out *sout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct sctp_chunk *ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) asoc = container_of(stream, struct sctp_association, stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) list_for_each_entry(ch, &asoc->outqueue.out_chunk_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) __u16 sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) sid = sctp_chunk_stream_no(ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) sout = SCTP_SO(stream, sid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) if (sout->ext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) sctp_sched_prio_sched(stream, sout->ext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static void sctp_sched_prio_unsched_all(struct sctp_stream *stream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) struct sctp_stream_priorities *p, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) struct sctp_stream_out_ext *soute, *souttmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) list_for_each_entry_safe(p, tmp, &stream->prio_list, prio_sched)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) list_for_each_entry_safe(soute, souttmp, &p->active, prio_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) sctp_sched_prio_unsched(soute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static struct sctp_sched_ops sctp_sched_prio = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) .set = sctp_sched_prio_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) .get = sctp_sched_prio_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) .init = sctp_sched_prio_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) .init_sid = sctp_sched_prio_init_sid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) .free = sctp_sched_prio_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) .enqueue = sctp_sched_prio_enqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) .dequeue = sctp_sched_prio_dequeue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) .dequeue_done = sctp_sched_prio_dequeue_done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) .sched_all = sctp_sched_prio_sched_all,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) .unsched_all = sctp_sched_prio_unsched_all,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) void sctp_sched_ops_prio_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) sctp_sched_ops_register(SCTP_SS_PRIO, &sctp_sched_prio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }