162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright 2008 Cisco Systems, Inc.  All rights reserved.
462306a36Sopenharmony_ci * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci#ifndef _RQ_ENET_DESC_H_
762306a36Sopenharmony_ci#define _RQ_ENET_DESC_H_
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci/* Ethernet receive queue descriptor: 16B */
1062306a36Sopenharmony_cistruct rq_enet_desc {
1162306a36Sopenharmony_ci	__le64 address;
1262306a36Sopenharmony_ci	__le16 length_type;
1362306a36Sopenharmony_ci	u8 reserved[6];
1462306a36Sopenharmony_ci};
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_cienum rq_enet_type_types {
1762306a36Sopenharmony_ci	RQ_ENET_TYPE_ONLY_SOP = 0,
1862306a36Sopenharmony_ci	RQ_ENET_TYPE_NOT_SOP = 1,
1962306a36Sopenharmony_ci	RQ_ENET_TYPE_RESV2 = 2,
2062306a36Sopenharmony_ci	RQ_ENET_TYPE_RESV3 = 3,
2162306a36Sopenharmony_ci};
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci#define RQ_ENET_ADDR_BITS		64
2462306a36Sopenharmony_ci#define RQ_ENET_LEN_BITS		14
2562306a36Sopenharmony_ci#define RQ_ENET_LEN_MASK		((1 << RQ_ENET_LEN_BITS) - 1)
2662306a36Sopenharmony_ci#define RQ_ENET_TYPE_BITS		2
2762306a36Sopenharmony_ci#define RQ_ENET_TYPE_MASK		((1 << RQ_ENET_TYPE_BITS) - 1)
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_cistatic inline void rq_enet_desc_enc(struct rq_enet_desc *desc,
3062306a36Sopenharmony_ci	u64 address, u8 type, u16 length)
3162306a36Sopenharmony_ci{
3262306a36Sopenharmony_ci	desc->address = cpu_to_le64(address);
3362306a36Sopenharmony_ci	desc->length_type = cpu_to_le16((length & RQ_ENET_LEN_MASK) |
3462306a36Sopenharmony_ci		((type & RQ_ENET_TYPE_MASK) << RQ_ENET_LEN_BITS));
3562306a36Sopenharmony_ci}
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_cistatic inline void rq_enet_desc_dec(struct rq_enet_desc *desc,
3862306a36Sopenharmony_ci	u64 *address, u8 *type, u16 *length)
3962306a36Sopenharmony_ci{
4062306a36Sopenharmony_ci	*address = le64_to_cpu(desc->address);
4162306a36Sopenharmony_ci	*length = le16_to_cpu(desc->length_type) & RQ_ENET_LEN_MASK;
4262306a36Sopenharmony_ci	*type = (u8)((le16_to_cpu(desc->length_type) >> RQ_ENET_LEN_BITS) &
4362306a36Sopenharmony_ci		RQ_ENET_TYPE_MASK);
4462306a36Sopenharmony_ci}
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci#endif /* _RQ_ENET_DESC_H_ */
47