162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright(c) 2015 - 2018 Intel Corporation.
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#ifndef _HFI1_IOWAIT_H
762306a36Sopenharmony_ci#define _HFI1_IOWAIT_H
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <linux/list.h>
1062306a36Sopenharmony_ci#include <linux/workqueue.h>
1162306a36Sopenharmony_ci#include <linux/wait.h>
1262306a36Sopenharmony_ci#include <linux/sched.h>
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#include "sdma_txreq.h"
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci/*
1762306a36Sopenharmony_ci * typedef (*restart_t)() - restart callback
1862306a36Sopenharmony_ci * @work: pointer to work structure
1962306a36Sopenharmony_ci */
2062306a36Sopenharmony_citypedef void (*restart_t)(struct work_struct *work);
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#define IOWAIT_PENDING_IB  0x0
2362306a36Sopenharmony_ci#define IOWAIT_PENDING_TID 0x1
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci/*
2662306a36Sopenharmony_ci * A QP can have multiple Send Engines (SEs).
2762306a36Sopenharmony_ci *
2862306a36Sopenharmony_ci * The current use case is for supporting a TID RDMA
2962306a36Sopenharmony_ci * packet build/xmit mechanism independent from verbs.
3062306a36Sopenharmony_ci */
3162306a36Sopenharmony_ci#define IOWAIT_SES 2
3262306a36Sopenharmony_ci#define IOWAIT_IB_SE 0
3362306a36Sopenharmony_ci#define IOWAIT_TID_SE 1
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_cistruct sdma_txreq;
3662306a36Sopenharmony_cistruct sdma_engine;
3762306a36Sopenharmony_ci/**
3862306a36Sopenharmony_ci * @iowork: the work struct
3962306a36Sopenharmony_ci * @tx_head: list of prebuilt packets
4062306a36Sopenharmony_ci * @iow: the parent iowait structure
4162306a36Sopenharmony_ci *
4262306a36Sopenharmony_ci * This structure is the work item (process) specific
4362306a36Sopenharmony_ci * details associated with the each of the two SEs of the
4462306a36Sopenharmony_ci * QP.
4562306a36Sopenharmony_ci *
4662306a36Sopenharmony_ci * The workstruct and the queued TXs are unique to each
4762306a36Sopenharmony_ci * SE.
4862306a36Sopenharmony_ci */
4962306a36Sopenharmony_cistruct iowait;
5062306a36Sopenharmony_cistruct iowait_work {
5162306a36Sopenharmony_ci	struct work_struct iowork;
5262306a36Sopenharmony_ci	struct list_head tx_head;
5362306a36Sopenharmony_ci	struct iowait *iow;
5462306a36Sopenharmony_ci};
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci/**
5762306a36Sopenharmony_ci * @list: used to add/insert into QP/PQ wait lists
5862306a36Sopenharmony_ci * @tx_head: overflow list of sdma_txreq's
5962306a36Sopenharmony_ci * @sleep: no space callback
6062306a36Sopenharmony_ci * @wakeup: space callback wakeup
6162306a36Sopenharmony_ci * @sdma_drained: sdma count drained
6262306a36Sopenharmony_ci * @init_priority: callback to manipulate priority
6362306a36Sopenharmony_ci * @lock: lock protected head of wait queue
6462306a36Sopenharmony_ci * @iowork: workqueue overhead
6562306a36Sopenharmony_ci * @wait_dma: wait for sdma_busy == 0
6662306a36Sopenharmony_ci * @wait_pio: wait for pio_busy == 0
6762306a36Sopenharmony_ci * @sdma_busy: # of packets in flight
6862306a36Sopenharmony_ci * @count: total number of descriptors in tx_head'ed list
6962306a36Sopenharmony_ci * @tx_limit: limit for overflow queuing
7062306a36Sopenharmony_ci * @tx_count: number of tx entry's in tx_head'ed list
7162306a36Sopenharmony_ci * @flags: wait flags (one per QP)
7262306a36Sopenharmony_ci * @wait: SE array for multiple legs
7362306a36Sopenharmony_ci *
7462306a36Sopenharmony_ci * This is to be embedded in user's state structure
7562306a36Sopenharmony_ci * (QP or PQ).
7662306a36Sopenharmony_ci *
7762306a36Sopenharmony_ci * The sleep and wakeup members are a
7862306a36Sopenharmony_ci * bit misnamed.   They do not strictly
7962306a36Sopenharmony_ci * speaking sleep or wake up, but they
8062306a36Sopenharmony_ci * are callbacks for the ULP to implement
8162306a36Sopenharmony_ci * what ever queuing/dequeuing of
8262306a36Sopenharmony_ci * the embedded iowait and its containing struct
8362306a36Sopenharmony_ci * when a resource shortage like SDMA ring space
8462306a36Sopenharmony_ci * or PIO credit space is seen.
8562306a36Sopenharmony_ci *
8662306a36Sopenharmony_ci * Both potentially have locks help
8762306a36Sopenharmony_ci * so sleeping is not allowed and it is not
8862306a36Sopenharmony_ci * supported to submit txreqs from the wakeup
8962306a36Sopenharmony_ci * call directly because of lock conflicts.
9062306a36Sopenharmony_ci *
9162306a36Sopenharmony_ci * The wait_dma member along with the iow
9262306a36Sopenharmony_ci *
9362306a36Sopenharmony_ci * The lock field is used by waiters to record
9462306a36Sopenharmony_ci * the seqlock_t that guards the list head.
9562306a36Sopenharmony_ci * Waiters explicity know that, but the destroy
9662306a36Sopenharmony_ci * code that unwaits QPs does not.
9762306a36Sopenharmony_ci */
9862306a36Sopenharmony_cistruct iowait {
9962306a36Sopenharmony_ci	struct list_head list;
10062306a36Sopenharmony_ci	int (*sleep)(
10162306a36Sopenharmony_ci		struct sdma_engine *sde,
10262306a36Sopenharmony_ci		struct iowait_work *wait,
10362306a36Sopenharmony_ci		struct sdma_txreq *tx,
10462306a36Sopenharmony_ci		uint seq,
10562306a36Sopenharmony_ci		bool pkts_sent
10662306a36Sopenharmony_ci		);
10762306a36Sopenharmony_ci	void (*wakeup)(struct iowait *wait, int reason);
10862306a36Sopenharmony_ci	void (*sdma_drained)(struct iowait *wait);
10962306a36Sopenharmony_ci	void (*init_priority)(struct iowait *wait);
11062306a36Sopenharmony_ci	seqlock_t *lock;
11162306a36Sopenharmony_ci	wait_queue_head_t wait_dma;
11262306a36Sopenharmony_ci	wait_queue_head_t wait_pio;
11362306a36Sopenharmony_ci	atomic_t sdma_busy;
11462306a36Sopenharmony_ci	atomic_t pio_busy;
11562306a36Sopenharmony_ci	u32 count;
11662306a36Sopenharmony_ci	u32 tx_limit;
11762306a36Sopenharmony_ci	u32 tx_count;
11862306a36Sopenharmony_ci	u8 starved_cnt;
11962306a36Sopenharmony_ci	u8 priority;
12062306a36Sopenharmony_ci	unsigned long flags;
12162306a36Sopenharmony_ci	struct iowait_work wait[IOWAIT_SES];
12262306a36Sopenharmony_ci};
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci#define SDMA_AVAIL_REASON 0
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_civoid iowait_set_flag(struct iowait *wait, u32 flag);
12762306a36Sopenharmony_cibool iowait_flag_set(struct iowait *wait, u32 flag);
12862306a36Sopenharmony_civoid iowait_clear_flag(struct iowait *wait, u32 flag);
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_civoid iowait_init(struct iowait *wait, u32 tx_limit,
13162306a36Sopenharmony_ci		 void (*func)(struct work_struct *work),
13262306a36Sopenharmony_ci		 void (*tidfunc)(struct work_struct *work),
13362306a36Sopenharmony_ci		 int (*sleep)(struct sdma_engine *sde,
13462306a36Sopenharmony_ci			      struct iowait_work *wait,
13562306a36Sopenharmony_ci			      struct sdma_txreq *tx,
13662306a36Sopenharmony_ci			      uint seq,
13762306a36Sopenharmony_ci			      bool pkts_sent),
13862306a36Sopenharmony_ci		 void (*wakeup)(struct iowait *wait, int reason),
13962306a36Sopenharmony_ci		 void (*sdma_drained)(struct iowait *wait),
14062306a36Sopenharmony_ci		 void (*init_priority)(struct iowait *wait));
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci/**
14362306a36Sopenharmony_ci * iowait_schedule() - schedule the default send engine work
14462306a36Sopenharmony_ci * @wait: wait struct to schedule
14562306a36Sopenharmony_ci * @wq: workqueue for schedule
14662306a36Sopenharmony_ci * @cpu: cpu
14762306a36Sopenharmony_ci */
14862306a36Sopenharmony_cistatic inline bool iowait_schedule(struct iowait *wait,
14962306a36Sopenharmony_ci				   struct workqueue_struct *wq, int cpu)
15062306a36Sopenharmony_ci{
15162306a36Sopenharmony_ci	return !!queue_work_on(cpu, wq, &wait->wait[IOWAIT_IB_SE].iowork);
15262306a36Sopenharmony_ci}
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ci/**
15562306a36Sopenharmony_ci * iowait_tid_schedule - schedule the tid SE
15662306a36Sopenharmony_ci * @wait: the iowait structure
15762306a36Sopenharmony_ci * @wq: the work queue
15862306a36Sopenharmony_ci * @cpu: the cpu
15962306a36Sopenharmony_ci */
16062306a36Sopenharmony_cistatic inline bool iowait_tid_schedule(struct iowait *wait,
16162306a36Sopenharmony_ci				       struct workqueue_struct *wq, int cpu)
16262306a36Sopenharmony_ci{
16362306a36Sopenharmony_ci	return !!queue_work_on(cpu, wq, &wait->wait[IOWAIT_TID_SE].iowork);
16462306a36Sopenharmony_ci}
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_ci/**
16762306a36Sopenharmony_ci * iowait_sdma_drain() - wait for DMAs to drain
16862306a36Sopenharmony_ci *
16962306a36Sopenharmony_ci * @wait: iowait structure
17062306a36Sopenharmony_ci *
17162306a36Sopenharmony_ci * This will delay until the iowait sdmas have
17262306a36Sopenharmony_ci * completed.
17362306a36Sopenharmony_ci */
17462306a36Sopenharmony_cistatic inline void iowait_sdma_drain(struct iowait *wait)
17562306a36Sopenharmony_ci{
17662306a36Sopenharmony_ci	wait_event(wait->wait_dma, !atomic_read(&wait->sdma_busy));
17762306a36Sopenharmony_ci}
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci/**
18062306a36Sopenharmony_ci * iowait_sdma_pending() - return sdma pending count
18162306a36Sopenharmony_ci *
18262306a36Sopenharmony_ci * @wait: iowait structure
18362306a36Sopenharmony_ci *
18462306a36Sopenharmony_ci */
18562306a36Sopenharmony_cistatic inline int iowait_sdma_pending(struct iowait *wait)
18662306a36Sopenharmony_ci{
18762306a36Sopenharmony_ci	return atomic_read(&wait->sdma_busy);
18862306a36Sopenharmony_ci}
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci/**
19162306a36Sopenharmony_ci * iowait_sdma_inc - note sdma io pending
19262306a36Sopenharmony_ci * @wait: iowait structure
19362306a36Sopenharmony_ci */
19462306a36Sopenharmony_cistatic inline void iowait_sdma_inc(struct iowait *wait)
19562306a36Sopenharmony_ci{
19662306a36Sopenharmony_ci	atomic_inc(&wait->sdma_busy);
19762306a36Sopenharmony_ci}
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ci/**
20062306a36Sopenharmony_ci * iowait_sdma_add - add count to pending
20162306a36Sopenharmony_ci * @wait: iowait structure
20262306a36Sopenharmony_ci */
20362306a36Sopenharmony_cistatic inline void iowait_sdma_add(struct iowait *wait, int count)
20462306a36Sopenharmony_ci{
20562306a36Sopenharmony_ci	atomic_add(count, &wait->sdma_busy);
20662306a36Sopenharmony_ci}
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_ci/**
20962306a36Sopenharmony_ci * iowait_sdma_dec - note sdma complete
21062306a36Sopenharmony_ci * @wait: iowait structure
21162306a36Sopenharmony_ci */
21262306a36Sopenharmony_cistatic inline int iowait_sdma_dec(struct iowait *wait)
21362306a36Sopenharmony_ci{
21462306a36Sopenharmony_ci	if (!wait)
21562306a36Sopenharmony_ci		return 0;
21662306a36Sopenharmony_ci	return atomic_dec_and_test(&wait->sdma_busy);
21762306a36Sopenharmony_ci}
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci/**
22062306a36Sopenharmony_ci * iowait_pio_drain() - wait for pios to drain
22162306a36Sopenharmony_ci *
22262306a36Sopenharmony_ci * @wait: iowait structure
22362306a36Sopenharmony_ci *
22462306a36Sopenharmony_ci * This will delay until the iowait pios have
22562306a36Sopenharmony_ci * completed.
22662306a36Sopenharmony_ci */
22762306a36Sopenharmony_cistatic inline void iowait_pio_drain(struct iowait *wait)
22862306a36Sopenharmony_ci{
22962306a36Sopenharmony_ci	wait_event_timeout(wait->wait_pio,
23062306a36Sopenharmony_ci			   !atomic_read(&wait->pio_busy),
23162306a36Sopenharmony_ci			   HZ);
23262306a36Sopenharmony_ci}
23362306a36Sopenharmony_ci
23462306a36Sopenharmony_ci/**
23562306a36Sopenharmony_ci * iowait_pio_pending() - return pio pending count
23662306a36Sopenharmony_ci *
23762306a36Sopenharmony_ci * @wait: iowait structure
23862306a36Sopenharmony_ci *
23962306a36Sopenharmony_ci */
24062306a36Sopenharmony_cistatic inline int iowait_pio_pending(struct iowait *wait)
24162306a36Sopenharmony_ci{
24262306a36Sopenharmony_ci	return atomic_read(&wait->pio_busy);
24362306a36Sopenharmony_ci}
24462306a36Sopenharmony_ci
24562306a36Sopenharmony_ci/**
24662306a36Sopenharmony_ci * iowait_pio_inc - note pio pending
24762306a36Sopenharmony_ci * @wait: iowait structure
24862306a36Sopenharmony_ci */
24962306a36Sopenharmony_cistatic inline void iowait_pio_inc(struct iowait *wait)
25062306a36Sopenharmony_ci{
25162306a36Sopenharmony_ci	atomic_inc(&wait->pio_busy);
25262306a36Sopenharmony_ci}
25362306a36Sopenharmony_ci
25462306a36Sopenharmony_ci/**
25562306a36Sopenharmony_ci * iowait_pio_dec - note pio complete
25662306a36Sopenharmony_ci * @wait: iowait structure
25762306a36Sopenharmony_ci */
25862306a36Sopenharmony_cistatic inline int iowait_pio_dec(struct iowait *wait)
25962306a36Sopenharmony_ci{
26062306a36Sopenharmony_ci	if (!wait)
26162306a36Sopenharmony_ci		return 0;
26262306a36Sopenharmony_ci	return atomic_dec_and_test(&wait->pio_busy);
26362306a36Sopenharmony_ci}
26462306a36Sopenharmony_ci
26562306a36Sopenharmony_ci/**
26662306a36Sopenharmony_ci * iowait_drain_wakeup() - trigger iowait_drain() waiter
26762306a36Sopenharmony_ci *
26862306a36Sopenharmony_ci * @wait: iowait structure
26962306a36Sopenharmony_ci *
27062306a36Sopenharmony_ci * This will trigger any waiters.
27162306a36Sopenharmony_ci */
27262306a36Sopenharmony_cistatic inline void iowait_drain_wakeup(struct iowait *wait)
27362306a36Sopenharmony_ci{
27462306a36Sopenharmony_ci	wake_up(&wait->wait_dma);
27562306a36Sopenharmony_ci	wake_up(&wait->wait_pio);
27662306a36Sopenharmony_ci	if (wait->sdma_drained)
27762306a36Sopenharmony_ci		wait->sdma_drained(wait);
27862306a36Sopenharmony_ci}
27962306a36Sopenharmony_ci
28062306a36Sopenharmony_ci/**
28162306a36Sopenharmony_ci * iowait_get_txhead() - get packet off of iowait list
28262306a36Sopenharmony_ci *
28362306a36Sopenharmony_ci * @wait: iowait_work structure
28462306a36Sopenharmony_ci */
28562306a36Sopenharmony_cistatic inline struct sdma_txreq *iowait_get_txhead(struct iowait_work *wait)
28662306a36Sopenharmony_ci{
28762306a36Sopenharmony_ci	struct sdma_txreq *tx = NULL;
28862306a36Sopenharmony_ci
28962306a36Sopenharmony_ci	if (!list_empty(&wait->tx_head)) {
29062306a36Sopenharmony_ci		tx = list_first_entry(
29162306a36Sopenharmony_ci			&wait->tx_head,
29262306a36Sopenharmony_ci			struct sdma_txreq,
29362306a36Sopenharmony_ci			list);
29462306a36Sopenharmony_ci		list_del_init(&tx->list);
29562306a36Sopenharmony_ci	}
29662306a36Sopenharmony_ci	return tx;
29762306a36Sopenharmony_ci}
29862306a36Sopenharmony_ci
29962306a36Sopenharmony_cistatic inline u16 iowait_get_desc(struct iowait_work *w)
30062306a36Sopenharmony_ci{
30162306a36Sopenharmony_ci	u16 num_desc = 0;
30262306a36Sopenharmony_ci	struct sdma_txreq *tx = NULL;
30362306a36Sopenharmony_ci
30462306a36Sopenharmony_ci	if (!list_empty(&w->tx_head)) {
30562306a36Sopenharmony_ci		tx = list_first_entry(&w->tx_head, struct sdma_txreq,
30662306a36Sopenharmony_ci				      list);
30762306a36Sopenharmony_ci		num_desc = tx->num_desc;
30862306a36Sopenharmony_ci		if (tx->flags & SDMA_TXREQ_F_VIP)
30962306a36Sopenharmony_ci			w->iow->priority++;
31062306a36Sopenharmony_ci	}
31162306a36Sopenharmony_ci	return num_desc;
31262306a36Sopenharmony_ci}
31362306a36Sopenharmony_ci
31462306a36Sopenharmony_cistatic inline u32 iowait_get_all_desc(struct iowait *w)
31562306a36Sopenharmony_ci{
31662306a36Sopenharmony_ci	u32 num_desc = 0;
31762306a36Sopenharmony_ci
31862306a36Sopenharmony_ci	num_desc = iowait_get_desc(&w->wait[IOWAIT_IB_SE]);
31962306a36Sopenharmony_ci	num_desc += iowait_get_desc(&w->wait[IOWAIT_TID_SE]);
32062306a36Sopenharmony_ci	return num_desc;
32162306a36Sopenharmony_ci}
32262306a36Sopenharmony_ci
32362306a36Sopenharmony_cistatic inline void iowait_update_priority(struct iowait_work *w)
32462306a36Sopenharmony_ci{
32562306a36Sopenharmony_ci	struct sdma_txreq *tx = NULL;
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_ci	if (!list_empty(&w->tx_head)) {
32862306a36Sopenharmony_ci		tx = list_first_entry(&w->tx_head, struct sdma_txreq,
32962306a36Sopenharmony_ci				      list);
33062306a36Sopenharmony_ci		if (tx->flags & SDMA_TXREQ_F_VIP)
33162306a36Sopenharmony_ci			w->iow->priority++;
33262306a36Sopenharmony_ci	}
33362306a36Sopenharmony_ci}
33462306a36Sopenharmony_ci
33562306a36Sopenharmony_cistatic inline void iowait_update_all_priority(struct iowait *w)
33662306a36Sopenharmony_ci{
33762306a36Sopenharmony_ci	iowait_update_priority(&w->wait[IOWAIT_IB_SE]);
33862306a36Sopenharmony_ci	iowait_update_priority(&w->wait[IOWAIT_TID_SE]);
33962306a36Sopenharmony_ci}
34062306a36Sopenharmony_ci
34162306a36Sopenharmony_cistatic inline void iowait_init_priority(struct iowait *w)
34262306a36Sopenharmony_ci{
34362306a36Sopenharmony_ci	w->priority = 0;
34462306a36Sopenharmony_ci	if (w->init_priority)
34562306a36Sopenharmony_ci		w->init_priority(w);
34662306a36Sopenharmony_ci}
34762306a36Sopenharmony_ci
34862306a36Sopenharmony_cistatic inline void iowait_get_priority(struct iowait *w)
34962306a36Sopenharmony_ci{
35062306a36Sopenharmony_ci	iowait_init_priority(w);
35162306a36Sopenharmony_ci	iowait_update_all_priority(w);
35262306a36Sopenharmony_ci}
35362306a36Sopenharmony_ci
35462306a36Sopenharmony_ci/**
35562306a36Sopenharmony_ci * iowait_queue - Put the iowait on a wait queue
35662306a36Sopenharmony_ci * @pkts_sent: have some packets been sent before queuing?
35762306a36Sopenharmony_ci * @w: the iowait struct
35862306a36Sopenharmony_ci * @wait_head: the wait queue
35962306a36Sopenharmony_ci *
36062306a36Sopenharmony_ci * This function is called to insert an iowait struct into a
36162306a36Sopenharmony_ci * wait queue after a resource (eg, sdma descriptor or pio
36262306a36Sopenharmony_ci * buffer) is run out.
36362306a36Sopenharmony_ci */
36462306a36Sopenharmony_cistatic inline void iowait_queue(bool pkts_sent, struct iowait *w,
36562306a36Sopenharmony_ci				struct list_head *wait_head)
36662306a36Sopenharmony_ci{
36762306a36Sopenharmony_ci	/*
36862306a36Sopenharmony_ci	 * To play fair, insert the iowait at the tail of the wait queue if it
36962306a36Sopenharmony_ci	 * has already sent some packets; Otherwise, put it at the head.
37062306a36Sopenharmony_ci	 * However, if it has priority packets to send, also put it at the
37162306a36Sopenharmony_ci	 * head.
37262306a36Sopenharmony_ci	 */
37362306a36Sopenharmony_ci	if (pkts_sent)
37462306a36Sopenharmony_ci		w->starved_cnt = 0;
37562306a36Sopenharmony_ci	else
37662306a36Sopenharmony_ci		w->starved_cnt++;
37762306a36Sopenharmony_ci
37862306a36Sopenharmony_ci	if (w->priority > 0 || !pkts_sent)
37962306a36Sopenharmony_ci		list_add(&w->list, wait_head);
38062306a36Sopenharmony_ci	else
38162306a36Sopenharmony_ci		list_add_tail(&w->list, wait_head);
38262306a36Sopenharmony_ci}
38362306a36Sopenharmony_ci
38462306a36Sopenharmony_ci/**
38562306a36Sopenharmony_ci * iowait_starve_clear - clear the wait queue's starve count
38662306a36Sopenharmony_ci * @pkts_sent: have some packets been sent?
38762306a36Sopenharmony_ci * @w: the iowait struct
38862306a36Sopenharmony_ci *
38962306a36Sopenharmony_ci * This function is called to clear the starve count. If no
39062306a36Sopenharmony_ci * packets have been sent, the starve count will not be cleared.
39162306a36Sopenharmony_ci */
39262306a36Sopenharmony_cistatic inline void iowait_starve_clear(bool pkts_sent, struct iowait *w)
39362306a36Sopenharmony_ci{
39462306a36Sopenharmony_ci	if (pkts_sent)
39562306a36Sopenharmony_ci		w->starved_cnt = 0;
39662306a36Sopenharmony_ci}
39762306a36Sopenharmony_ci
39862306a36Sopenharmony_ci/* Update the top priority index */
39962306a36Sopenharmony_ciuint iowait_priority_update_top(struct iowait *w,
40062306a36Sopenharmony_ci				struct iowait *top,
40162306a36Sopenharmony_ci				uint idx, uint top_idx);
40262306a36Sopenharmony_ci
40362306a36Sopenharmony_ci/**
40462306a36Sopenharmony_ci * iowait_packet_queued() - determine if a packet is queued
40562306a36Sopenharmony_ci * @wait: the iowait_work structure
40662306a36Sopenharmony_ci */
40762306a36Sopenharmony_cistatic inline bool iowait_packet_queued(struct iowait_work *wait)
40862306a36Sopenharmony_ci{
40962306a36Sopenharmony_ci	return !list_empty(&wait->tx_head);
41062306a36Sopenharmony_ci}
41162306a36Sopenharmony_ci
41262306a36Sopenharmony_ci/**
41362306a36Sopenharmony_ci * inc_wait_count - increment wait counts
41462306a36Sopenharmony_ci * @w: the log work struct
41562306a36Sopenharmony_ci * @n: the count
41662306a36Sopenharmony_ci */
41762306a36Sopenharmony_cistatic inline void iowait_inc_wait_count(struct iowait_work *w, u16 n)
41862306a36Sopenharmony_ci{
41962306a36Sopenharmony_ci	if (!w)
42062306a36Sopenharmony_ci		return;
42162306a36Sopenharmony_ci	w->iow->tx_count++;
42262306a36Sopenharmony_ci	w->iow->count += n;
42362306a36Sopenharmony_ci}
42462306a36Sopenharmony_ci
42562306a36Sopenharmony_ci/**
42662306a36Sopenharmony_ci * iowait_get_tid_work - return iowait_work for tid SE
42762306a36Sopenharmony_ci * @w: the iowait struct
42862306a36Sopenharmony_ci */
42962306a36Sopenharmony_cistatic inline struct iowait_work *iowait_get_tid_work(struct iowait *w)
43062306a36Sopenharmony_ci{
43162306a36Sopenharmony_ci	return &w->wait[IOWAIT_TID_SE];
43262306a36Sopenharmony_ci}
43362306a36Sopenharmony_ci
43462306a36Sopenharmony_ci/**
43562306a36Sopenharmony_ci * iowait_get_ib_work - return iowait_work for ib SE
43662306a36Sopenharmony_ci * @w: the iowait struct
43762306a36Sopenharmony_ci */
43862306a36Sopenharmony_cistatic inline struct iowait_work *iowait_get_ib_work(struct iowait *w)
43962306a36Sopenharmony_ci{
44062306a36Sopenharmony_ci	return &w->wait[IOWAIT_IB_SE];
44162306a36Sopenharmony_ci}
44262306a36Sopenharmony_ci
44362306a36Sopenharmony_ci/**
44462306a36Sopenharmony_ci * iowait_ioww_to_iow - return iowait given iowait_work
44562306a36Sopenharmony_ci * @w: the iowait_work struct
44662306a36Sopenharmony_ci */
44762306a36Sopenharmony_cistatic inline struct iowait *iowait_ioww_to_iow(struct iowait_work *w)
44862306a36Sopenharmony_ci{
44962306a36Sopenharmony_ci	if (likely(w))
45062306a36Sopenharmony_ci		return w->iow;
45162306a36Sopenharmony_ci	return NULL;
45262306a36Sopenharmony_ci}
45362306a36Sopenharmony_ci
45462306a36Sopenharmony_civoid iowait_cancel_work(struct iowait *w);
45562306a36Sopenharmony_ciint iowait_set_work_flag(struct iowait_work *w);
45662306a36Sopenharmony_ci
45762306a36Sopenharmony_ci#endif
458