18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright(c) 2016 Intel Corporation.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This file is provided under a dual BSD/GPLv2 license.  When using or
58c2ecf20Sopenharmony_ci * redistributing this file, you may do so under either license.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * GPL LICENSE SUMMARY
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
108c2ecf20Sopenharmony_ci * it under the terms of version 2 of the GNU General Public License as
118c2ecf20Sopenharmony_ci * published by the Free Software Foundation.
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful, but
148c2ecf20Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of
158c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
168c2ecf20Sopenharmony_ci * General Public License for more details.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci * BSD LICENSE
198c2ecf20Sopenharmony_ci *
208c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
218c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions
228c2ecf20Sopenharmony_ci * are met:
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci *  - Redistributions of source code must retain the above copyright
258c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
268c2ecf20Sopenharmony_ci *  - Redistributions in binary form must reproduce the above copyright
278c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer in
288c2ecf20Sopenharmony_ci *    the documentation and/or other materials provided with the
298c2ecf20Sopenharmony_ci *    distribution.
308c2ecf20Sopenharmony_ci *  - Neither the name of Intel Corporation nor the names of its
318c2ecf20Sopenharmony_ci *    contributors may be used to endorse or promote products derived
328c2ecf20Sopenharmony_ci *    from this software without specific prior written permission.
338c2ecf20Sopenharmony_ci *
348c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
358c2ecf20Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
368c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
378c2ecf20Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
388c2ecf20Sopenharmony_ci * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
398c2ecf20Sopenharmony_ci * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
408c2ecf20Sopenharmony_ci * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
418c2ecf20Sopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
428c2ecf20Sopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
438c2ecf20Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
448c2ecf20Sopenharmony_ci * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
458c2ecf20Sopenharmony_ci *
468c2ecf20Sopenharmony_ci */
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#ifndef HFI1_SDMA_TXREQ_H
498c2ecf20Sopenharmony_ci#define HFI1_SDMA_TXREQ_H
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/* increased for AHG */
528c2ecf20Sopenharmony_ci#define NUM_DESC 6
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci/*
558c2ecf20Sopenharmony_ci * struct sdma_desc - canonical fragment descriptor
568c2ecf20Sopenharmony_ci *
578c2ecf20Sopenharmony_ci * This is the descriptor carried in the tx request
588c2ecf20Sopenharmony_ci * corresponding to each fragment.
598c2ecf20Sopenharmony_ci *
608c2ecf20Sopenharmony_ci */
618c2ecf20Sopenharmony_cistruct sdma_desc {
628c2ecf20Sopenharmony_ci	/* private:  don't use directly */
638c2ecf20Sopenharmony_ci	u64 qw[2];
648c2ecf20Sopenharmony_ci	void *pinning_ctx;
658c2ecf20Sopenharmony_ci	/* Release reference to @pinning_ctx. May be called in interrupt context. Must not sleep. */
668c2ecf20Sopenharmony_ci	void (*ctx_put)(void *ctx);
678c2ecf20Sopenharmony_ci};
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/**
708c2ecf20Sopenharmony_ci * struct sdma_txreq - the sdma_txreq structure (one per packet)
718c2ecf20Sopenharmony_ci * @list: for use by user and by queuing for wait
728c2ecf20Sopenharmony_ci *
738c2ecf20Sopenharmony_ci * This is the representation of a packet which consists of some
748c2ecf20Sopenharmony_ci * number of fragments.   Storage is provided to within the structure.
758c2ecf20Sopenharmony_ci * for all fragments.
768c2ecf20Sopenharmony_ci *
778c2ecf20Sopenharmony_ci * The storage for the descriptors are automatically extended as needed
788c2ecf20Sopenharmony_ci * when the currently allocation is exceeded.
798c2ecf20Sopenharmony_ci *
808c2ecf20Sopenharmony_ci * The user (Verbs or PSM) may overload this structure with fields
818c2ecf20Sopenharmony_ci * specific to their use by putting this struct first in their struct.
828c2ecf20Sopenharmony_ci * The method of allocation of the overloaded structure is user dependent
838c2ecf20Sopenharmony_ci *
848c2ecf20Sopenharmony_ci * The list is the only public field in the structure.
858c2ecf20Sopenharmony_ci *
868c2ecf20Sopenharmony_ci */
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci#define SDMA_TXREQ_S_OK        0
898c2ecf20Sopenharmony_ci#define SDMA_TXREQ_S_SENDERROR 1
908c2ecf20Sopenharmony_ci#define SDMA_TXREQ_S_ABORTED   2
918c2ecf20Sopenharmony_ci#define SDMA_TXREQ_S_SHUTDOWN  3
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/* flags bits */
948c2ecf20Sopenharmony_ci#define SDMA_TXREQ_F_URGENT       0x0001
958c2ecf20Sopenharmony_ci#define SDMA_TXREQ_F_AHG_COPY     0x0002
968c2ecf20Sopenharmony_ci#define SDMA_TXREQ_F_USE_AHG      0x0004
978c2ecf20Sopenharmony_ci#define SDMA_TXREQ_F_VIP          0x0010
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_cistruct sdma_txreq;
1008c2ecf20Sopenharmony_citypedef void (*callback_t)(struct sdma_txreq *, int);
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_cistruct iowait;
1038c2ecf20Sopenharmony_cistruct sdma_txreq {
1048c2ecf20Sopenharmony_ci	struct list_head list;
1058c2ecf20Sopenharmony_ci	/* private: */
1068c2ecf20Sopenharmony_ci	struct sdma_desc *descp;
1078c2ecf20Sopenharmony_ci	/* private: */
1088c2ecf20Sopenharmony_ci	void *coalesce_buf;
1098c2ecf20Sopenharmony_ci	/* private: */
1108c2ecf20Sopenharmony_ci	struct iowait *wait;
1118c2ecf20Sopenharmony_ci	/* private: */
1128c2ecf20Sopenharmony_ci	callback_t                  complete;
1138c2ecf20Sopenharmony_ci#ifdef CONFIG_HFI1_DEBUG_SDMA_ORDER
1148c2ecf20Sopenharmony_ci	u64 sn;
1158c2ecf20Sopenharmony_ci#endif
1168c2ecf20Sopenharmony_ci	/* private: - used in coalesce/pad processing */
1178c2ecf20Sopenharmony_ci	u16                         packet_len;
1188c2ecf20Sopenharmony_ci	/* private: - down-counted to trigger last */
1198c2ecf20Sopenharmony_ci	u16                         tlen;
1208c2ecf20Sopenharmony_ci	/* private: */
1218c2ecf20Sopenharmony_ci	u16                         num_desc;
1228c2ecf20Sopenharmony_ci	/* private: */
1238c2ecf20Sopenharmony_ci	u16                         desc_limit;
1248c2ecf20Sopenharmony_ci	/* private: */
1258c2ecf20Sopenharmony_ci	u16                         next_descq_idx;
1268c2ecf20Sopenharmony_ci	/* private: */
1278c2ecf20Sopenharmony_ci	u16 coalesce_idx;
1288c2ecf20Sopenharmony_ci	/* private: flags */
1298c2ecf20Sopenharmony_ci	u16                         flags;
1308c2ecf20Sopenharmony_ci	/* private: */
1318c2ecf20Sopenharmony_ci	struct sdma_desc descs[NUM_DESC];
1328c2ecf20Sopenharmony_ci};
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_cistatic inline int sdma_txreq_built(struct sdma_txreq *tx)
1358c2ecf20Sopenharmony_ci{
1368c2ecf20Sopenharmony_ci	return tx->num_desc;
1378c2ecf20Sopenharmony_ci}
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci#endif                          /* HFI1_SDMA_TXREQ_H */
140