xref: /freebsd/sys/dev/enic/rq_enet_desc.h (revision 9c067b844f85a224f0416e6eb46ba3ef82aec5c4)
1*9c067b84SDoug Ambrisko /* SPDX-License-Identifier: BSD-3-Clause
2*9c067b84SDoug Ambrisko  * Copyright 2008-2017 Cisco Systems, Inc.  All rights reserved.
3*9c067b84SDoug Ambrisko  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4*9c067b84SDoug Ambrisko  */
5*9c067b84SDoug Ambrisko 
6*9c067b84SDoug Ambrisko #ifndef _RQ_ENET_DESC_H_
7*9c067b84SDoug Ambrisko #define _RQ_ENET_DESC_H_
8*9c067b84SDoug Ambrisko 
9*9c067b84SDoug Ambrisko /* Ethernet receive queue descriptor: 16B */
10*9c067b84SDoug Ambrisko struct rq_enet_desc {
11*9c067b84SDoug Ambrisko 	__le64 address;
12*9c067b84SDoug Ambrisko 	__le16 length_type;
13*9c067b84SDoug Ambrisko 	u8 reserved[6];
14*9c067b84SDoug Ambrisko };
15*9c067b84SDoug Ambrisko 
16*9c067b84SDoug Ambrisko enum rq_enet_type_types {
17*9c067b84SDoug Ambrisko 	RQ_ENET_TYPE_ONLY_SOP = 0,
18*9c067b84SDoug Ambrisko 	RQ_ENET_TYPE_NOT_SOP = 1,
19*9c067b84SDoug Ambrisko 	RQ_ENET_TYPE_RESV2 = 2,
20*9c067b84SDoug Ambrisko 	RQ_ENET_TYPE_RESV3 = 3,
21*9c067b84SDoug Ambrisko };
22*9c067b84SDoug Ambrisko 
23*9c067b84SDoug Ambrisko #define RQ_ENET_ADDR_BITS		64
24*9c067b84SDoug Ambrisko #define RQ_ENET_LEN_BITS		14
25*9c067b84SDoug Ambrisko #define RQ_ENET_LEN_MASK		((1 << RQ_ENET_LEN_BITS) - 1)
26*9c067b84SDoug Ambrisko #define RQ_ENET_TYPE_BITS		2
27*9c067b84SDoug Ambrisko #define RQ_ENET_TYPE_MASK		((1 << RQ_ENET_TYPE_BITS) - 1)
28*9c067b84SDoug Ambrisko 
rq_enet_desc_enc(volatile struct rq_enet_desc * desc,u64 address,u8 type,u16 length)29*9c067b84SDoug Ambrisko static inline void rq_enet_desc_enc(volatile struct rq_enet_desc *desc,
30*9c067b84SDoug Ambrisko 	u64 address, u8 type, u16 length)
31*9c067b84SDoug Ambrisko {
32*9c067b84SDoug Ambrisko 	desc->address = cpu_to_le64(address);
33*9c067b84SDoug Ambrisko 	desc->length_type = cpu_to_le16((length & RQ_ENET_LEN_MASK) |
34*9c067b84SDoug Ambrisko 		((type & RQ_ENET_TYPE_MASK) << RQ_ENET_LEN_BITS));
35*9c067b84SDoug Ambrisko }
36*9c067b84SDoug Ambrisko 
rq_enet_desc_dec(struct rq_enet_desc * desc,u64 * address,u8 * type,u16 * length)37*9c067b84SDoug Ambrisko static inline void rq_enet_desc_dec(struct rq_enet_desc *desc,
38*9c067b84SDoug Ambrisko 	u64 *address, u8 *type, u16 *length)
39*9c067b84SDoug Ambrisko {
40*9c067b84SDoug Ambrisko 	*address = le64_to_cpu(desc->address);
41*9c067b84SDoug Ambrisko 	*length = le16_to_cpu(desc->length_type) & RQ_ENET_LEN_MASK;
42*9c067b84SDoug Ambrisko 	*type = (u8)((le16_to_cpu(desc->length_type) >> RQ_ENET_LEN_BITS) &
43*9c067b84SDoug Ambrisko 	    RQ_ENET_TYPE_MASK);
44*9c067b84SDoug Ambrisko }
45*9c067b84SDoug Ambrisko 
46*9c067b84SDoug Ambrisko #endif /* _RQ_ENET_DESC_H_ */
47