1/* 2 * Copyright 2014 Cisco Systems, Inc. All rights reserved. 3 * 4 * This program is free software; you may redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; version 2 of the License. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 9 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 10 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 11 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 12 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 13 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 14 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 15 * SOFTWARE. 16 */ 17 18#ifndef _WQ_ENET_DESC_H_ 19#define _WQ_ENET_DESC_H_ 20 21/* Ethernet work queue descriptor: 16B */ 22struct wq_enet_desc { 23 __le64 address; 24 __le16 length; 25 __le16 mss_loopback; 26 __le16 header_length_flags; 27 __le16 vlan_tag; 28}; 29 30#define WQ_ENET_ADDR_BITS 64 31#define WQ_ENET_LEN_BITS 14 32#define WQ_ENET_LEN_MASK ((1 << WQ_ENET_LEN_BITS) - 1) 33#define WQ_ENET_MSS_BITS 14 34#define WQ_ENET_MSS_MASK ((1 << WQ_ENET_MSS_BITS) - 1) 35#define WQ_ENET_MSS_SHIFT 2 36#define WQ_ENET_LOOPBACK_SHIFT 1 37#define WQ_ENET_HDRLEN_BITS 10 38#define WQ_ENET_HDRLEN_MASK ((1 << WQ_ENET_HDRLEN_BITS) - 1) 39#define WQ_ENET_FLAGS_OM_BITS 2 40#define WQ_ENET_FLAGS_OM_MASK ((1 << WQ_ENET_FLAGS_OM_BITS) - 1) 41#define WQ_ENET_FLAGS_EOP_SHIFT 12 42#define WQ_ENET_FLAGS_CQ_ENTRY_SHIFT 13 43#define WQ_ENET_FLAGS_FCOE_ENCAP_SHIFT 14 44#define WQ_ENET_FLAGS_VLAN_TAG_INSERT_SHIFT 15 45 46#define WQ_ENET_OFFLOAD_MODE_CSUM 0 47#define WQ_ENET_OFFLOAD_MODE_RESERVED 1 48#define WQ_ENET_OFFLOAD_MODE_CSUM_L4 2 49#define WQ_ENET_OFFLOAD_MODE_TSO 3 50 51static inline void wq_enet_desc_enc(struct wq_enet_desc *desc, 52 u64 address, u16 length, u16 mss, u16 header_length, 53 u8 offload_mode, u8 eop, u8 cq_entry, u8 fcoe_encap, 54 u8 vlan_tag_insert, u16 vlan_tag, u8 loopback) 55{ 56 desc->address = cpu_to_le64(address); 57 desc->length = cpu_to_le16(length & WQ_ENET_LEN_MASK); 58 desc->mss_loopback = cpu_to_le16((mss & WQ_ENET_MSS_MASK) << 59 WQ_ENET_MSS_SHIFT | (loopback & 1) << WQ_ENET_LOOPBACK_SHIFT); 60 desc->header_length_flags = cpu_to_le16( 61 (header_length & WQ_ENET_HDRLEN_MASK) | 62 (offload_mode & WQ_ENET_FLAGS_OM_MASK) << WQ_ENET_HDRLEN_BITS | 63 (eop & 1) << WQ_ENET_FLAGS_EOP_SHIFT | 64 (cq_entry & 1) << WQ_ENET_FLAGS_CQ_ENTRY_SHIFT | 65 (fcoe_encap & 1) << WQ_ENET_FLAGS_FCOE_ENCAP_SHIFT | 66 (vlan_tag_insert & 1) << WQ_ENET_FLAGS_VLAN_TAG_INSERT_SHIFT); 67 desc->vlan_tag = cpu_to_le16(vlan_tag); 68} 69 70static inline void wq_enet_desc_dec(struct wq_enet_desc *desc, 71 u64 *address, u16 *length, u16 *mss, u16 *header_length, 72 u8 *offload_mode, u8 *eop, u8 *cq_entry, u8 *fcoe_encap, 73 u8 *vlan_tag_insert, u16 *vlan_tag, u8 *loopback) 74{ 75 *address = le64_to_cpu(desc->address); 76 *length = le16_to_cpu(desc->length) & WQ_ENET_LEN_MASK; 77 *mss = (le16_to_cpu(desc->mss_loopback) >> WQ_ENET_MSS_SHIFT) & 78 WQ_ENET_MSS_MASK; 79 *loopback = (u8)((le16_to_cpu(desc->mss_loopback) >> 80 WQ_ENET_LOOPBACK_SHIFT) & 1); 81 *header_length = le16_to_cpu(desc->header_length_flags) & 82 WQ_ENET_HDRLEN_MASK; 83 *offload_mode = (u8)((le16_to_cpu(desc->header_length_flags) >> 84 WQ_ENET_HDRLEN_BITS) & WQ_ENET_FLAGS_OM_MASK); 85 *eop = (u8)((le16_to_cpu(desc->header_length_flags) >> 86 WQ_ENET_FLAGS_EOP_SHIFT) & 1); 87 *cq_entry = (u8)((le16_to_cpu(desc->header_length_flags) >> 88 WQ_ENET_FLAGS_CQ_ENTRY_SHIFT) & 1); 89 *fcoe_encap = (u8)((le16_to_cpu(desc->header_length_flags) >> 90 WQ_ENET_FLAGS_FCOE_ENCAP_SHIFT) & 1); 91 *vlan_tag_insert = (u8)((le16_to_cpu(desc->header_length_flags) >> 92 WQ_ENET_FLAGS_VLAN_TAG_INSERT_SHIFT) & 1); 93 *vlan_tag = le16_to_cpu(desc->vlan_tag); 94} 95 96#endif /* _WQ_ENET_DESC_H_ */ 97