xref: /linux/drivers/misc/genwqe/card_ddcb.h (revision 58e16d792a6a8c6b750f637a4649967fcac853dc)
1*3e0a4e85SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2eaf4722dSFrank Haverkamp #ifndef __CARD_DDCB_H__
3eaf4722dSFrank Haverkamp #define __CARD_DDCB_H__
4eaf4722dSFrank Haverkamp 
5eaf4722dSFrank Haverkamp /**
6eaf4722dSFrank Haverkamp  * IBM Accelerator Family 'GenWQE'
7eaf4722dSFrank Haverkamp  *
8eaf4722dSFrank Haverkamp  * (C) Copyright IBM Corp. 2013
9eaf4722dSFrank Haverkamp  *
10eaf4722dSFrank Haverkamp  * Author: Frank Haverkamp <haver@linux.vnet.ibm.com>
11eaf4722dSFrank Haverkamp  * Author: Joerg-Stephan Vogt <jsvogt@de.ibm.com>
1226d8f6f1SFrank Haverkamp  * Author: Michael Jung <mijung@gmx.net>
13eaf4722dSFrank Haverkamp  * Author: Michael Ruettger <michael@ibmra.de>
14eaf4722dSFrank Haverkamp  */
15eaf4722dSFrank Haverkamp 
16eaf4722dSFrank Haverkamp #include <linux/types.h>
17eaf4722dSFrank Haverkamp #include <asm/byteorder.h>
18eaf4722dSFrank Haverkamp 
19eaf4722dSFrank Haverkamp #include "genwqe_driver.h"
20eaf4722dSFrank Haverkamp #include "card_base.h"
21eaf4722dSFrank Haverkamp 
22eaf4722dSFrank Haverkamp /**
23eaf4722dSFrank Haverkamp  * struct ddcb - Device Driver Control Block DDCB
24eaf4722dSFrank Haverkamp  * @hsi:        Hardware software interlock
25eaf4722dSFrank Haverkamp  * @shi:        Software hardware interlock. Hsi and shi are used to interlock
26eaf4722dSFrank Haverkamp  *              software and hardware activities. We are using a compare and
27eaf4722dSFrank Haverkamp  *              swap operation to ensure that there are no races when
28eaf4722dSFrank Haverkamp  *              activating new DDCBs on the queue, or when we need to
29eaf4722dSFrank Haverkamp  *              purge a DDCB from a running queue.
30eaf4722dSFrank Haverkamp  * @acfunc:     Accelerator function addresses a unit within the chip
31eaf4722dSFrank Haverkamp  * @cmd:        Command to work on
32eaf4722dSFrank Haverkamp  * @cmdopts_16: Options for the command
33eaf4722dSFrank Haverkamp  * @asiv:       Input data
34eaf4722dSFrank Haverkamp  * @asv:        Output data
35eaf4722dSFrank Haverkamp  *
36eaf4722dSFrank Haverkamp  * The DDCB data format is big endian. Multiple consequtive DDBCs form
37eaf4722dSFrank Haverkamp  * a DDCB queue.
38eaf4722dSFrank Haverkamp  */
39eaf4722dSFrank Haverkamp #define ASIV_LENGTH		104 /* Old specification without ATS field */
40eaf4722dSFrank Haverkamp #define ASIV_LENGTH_ATS		96  /* New specification with ATS field */
41eaf4722dSFrank Haverkamp #define ASV_LENGTH		64
42eaf4722dSFrank Haverkamp 
43eaf4722dSFrank Haverkamp struct ddcb {
44eaf4722dSFrank Haverkamp 	union {
45eaf4722dSFrank Haverkamp 		__be32 icrc_hsi_shi_32;	/* iCRC, Hardware/SW interlock */
46eaf4722dSFrank Haverkamp 		struct {
47eaf4722dSFrank Haverkamp 			__be16	icrc_16;
48eaf4722dSFrank Haverkamp 			u8	hsi;
49eaf4722dSFrank Haverkamp 			u8	shi;
50eaf4722dSFrank Haverkamp 		};
51eaf4722dSFrank Haverkamp 	};
52eaf4722dSFrank Haverkamp 	u8  pre;		/* Preamble */
53eaf4722dSFrank Haverkamp 	u8  xdir;		/* Execution Directives */
54eaf4722dSFrank Haverkamp 	__be16 seqnum_16;	/* Sequence Number */
55eaf4722dSFrank Haverkamp 
56eaf4722dSFrank Haverkamp 	u8  acfunc;		/* Accelerator Function.. */
57eaf4722dSFrank Haverkamp 	u8  cmd;		/* Command. */
58eaf4722dSFrank Haverkamp 	__be16 cmdopts_16;	/* Command Options */
59eaf4722dSFrank Haverkamp 	u8  sur;		/* Status Update Rate */
60eaf4722dSFrank Haverkamp 	u8  psp;		/* Protection Section Pointer */
61eaf4722dSFrank Haverkamp 	__be16 rsvd_0e_16;	/* Reserved invariant */
62eaf4722dSFrank Haverkamp 
63eaf4722dSFrank Haverkamp 	__be64 fwiv_64;		/* Firmware Invariant. */
64eaf4722dSFrank Haverkamp 
65eaf4722dSFrank Haverkamp 	union {
66eaf4722dSFrank Haverkamp 		struct {
67eaf4722dSFrank Haverkamp 			__be64 ats_64;  /* Address Translation Spec */
68eaf4722dSFrank Haverkamp 			u8     asiv[ASIV_LENGTH_ATS]; /* New ASIV */
69eaf4722dSFrank Haverkamp 		} n;
70eaf4722dSFrank Haverkamp 		u8  __asiv[ASIV_LENGTH];	/* obsolete */
71eaf4722dSFrank Haverkamp 	};
72eaf4722dSFrank Haverkamp 	u8     asv[ASV_LENGTH];	/* Appl Spec Variant */
73eaf4722dSFrank Haverkamp 
74eaf4722dSFrank Haverkamp 	__be16 rsvd_c0_16;	/* Reserved Variant */
75eaf4722dSFrank Haverkamp 	__be16 vcrc_16;		/* Variant CRC */
76eaf4722dSFrank Haverkamp 	__be32 rsvd_32;		/* Reserved unprotected */
77eaf4722dSFrank Haverkamp 
78eaf4722dSFrank Haverkamp 	__be64 deque_ts_64;	/* Deque Time Stamp. */
79eaf4722dSFrank Haverkamp 
80eaf4722dSFrank Haverkamp 	__be16 retc_16;		/* Return Code */
81eaf4722dSFrank Haverkamp 	__be16 attn_16;		/* Attention/Extended Error Codes */
82eaf4722dSFrank Haverkamp 	__be32 progress_32;	/* Progress indicator. */
83eaf4722dSFrank Haverkamp 
84eaf4722dSFrank Haverkamp 	__be64 cmplt_ts_64;	/* Completion Time Stamp. */
85eaf4722dSFrank Haverkamp 
86eaf4722dSFrank Haverkamp 	/* The following layout matches the new service layer format */
87eaf4722dSFrank Haverkamp 	__be32 ibdc_32;		/* Inbound Data Count  (* 256) */
88eaf4722dSFrank Haverkamp 	__be32 obdc_32;		/* Outbound Data Count (* 256) */
89eaf4722dSFrank Haverkamp 
90eaf4722dSFrank Haverkamp 	__be64 rsvd_SLH_64;	/* Reserved for hardware */
91eaf4722dSFrank Haverkamp 	union {			/* private data for driver */
92eaf4722dSFrank Haverkamp 		u8	priv[8];
93eaf4722dSFrank Haverkamp 		__be64	priv_64;
94eaf4722dSFrank Haverkamp 	};
95eaf4722dSFrank Haverkamp 	__be64 disp_ts_64;	/* Dispatch TimeStamp */
96eaf4722dSFrank Haverkamp } __attribute__((__packed__));
97eaf4722dSFrank Haverkamp 
98eaf4722dSFrank Haverkamp /* CRC polynomials for DDCB */
99eaf4722dSFrank Haverkamp #define CRC16_POLYNOMIAL	0x1021
100eaf4722dSFrank Haverkamp 
101eaf4722dSFrank Haverkamp /*
102eaf4722dSFrank Haverkamp  * SHI: Software to Hardware Interlock
103eaf4722dSFrank Haverkamp  *   This 1 byte field is written by software to interlock the
104eaf4722dSFrank Haverkamp  *   movement of one queue entry to another with the hardware in the
105eaf4722dSFrank Haverkamp  *   chip.
106eaf4722dSFrank Haverkamp  */
107eaf4722dSFrank Haverkamp #define DDCB_SHI_INTR		0x04 /* Bit 2 */
108eaf4722dSFrank Haverkamp #define DDCB_SHI_PURGE		0x02 /* Bit 1 */
109eaf4722dSFrank Haverkamp #define DDCB_SHI_NEXT		0x01 /* Bit 0 */
110eaf4722dSFrank Haverkamp 
111eaf4722dSFrank Haverkamp /*
112eaf4722dSFrank Haverkamp  * HSI: Hardware to Software interlock
113eaf4722dSFrank Haverkamp  * This 1 byte field is written by hardware to interlock the movement
114eaf4722dSFrank Haverkamp  * of one queue entry to another with the software in the chip.
115eaf4722dSFrank Haverkamp  */
116eaf4722dSFrank Haverkamp #define DDCB_HSI_COMPLETED	0x40 /* Bit 6 */
117eaf4722dSFrank Haverkamp #define DDCB_HSI_FETCHED	0x04 /* Bit 2 */
118eaf4722dSFrank Haverkamp 
119eaf4722dSFrank Haverkamp /*
120eaf4722dSFrank Haverkamp  * Accessing HSI/SHI is done 32-bit wide
121eaf4722dSFrank Haverkamp  *   Normally 16-bit access would work too, but on some platforms the
122eaf4722dSFrank Haverkamp  *   16 compare and swap operation is not supported. Therefore
123eaf4722dSFrank Haverkamp  *   switching to 32-bit such that those platforms will work too.
124eaf4722dSFrank Haverkamp  *
125eaf4722dSFrank Haverkamp  *                                         iCRC HSI/SHI
126eaf4722dSFrank Haverkamp  */
127eaf4722dSFrank Haverkamp #define DDCB_INTR_BE32		cpu_to_be32(0x00000004)
128eaf4722dSFrank Haverkamp #define DDCB_PURGE_BE32		cpu_to_be32(0x00000002)
129eaf4722dSFrank Haverkamp #define DDCB_NEXT_BE32		cpu_to_be32(0x00000001)
130eaf4722dSFrank Haverkamp #define DDCB_COMPLETED_BE32	cpu_to_be32(0x00004000)
131eaf4722dSFrank Haverkamp #define DDCB_FETCHED_BE32	cpu_to_be32(0x00000400)
132eaf4722dSFrank Haverkamp 
133eaf4722dSFrank Haverkamp /* Definitions of DDCB presets */
134eaf4722dSFrank Haverkamp #define DDCB_PRESET_PRE		0x80
135eaf4722dSFrank Haverkamp #define ICRC_LENGTH(n)		((n) + 8 + 8 + 8)  /* used ASIV + hdr fields */
136eaf4722dSFrank Haverkamp #define VCRC_LENGTH(n)		((n))		   /* used ASV */
137eaf4722dSFrank Haverkamp 
138eaf4722dSFrank Haverkamp /*
139eaf4722dSFrank Haverkamp  * Genwqe Scatter Gather list
140eaf4722dSFrank Haverkamp  *   Each element has up to 8 entries.
141eaf4722dSFrank Haverkamp  *   The chaining element is element 0 cause of prefetching needs.
142eaf4722dSFrank Haverkamp  */
143eaf4722dSFrank Haverkamp 
144eaf4722dSFrank Haverkamp /*
145eaf4722dSFrank Haverkamp  * 0b0110 Chained descriptor. The descriptor is describing the next
146eaf4722dSFrank Haverkamp  * descriptor list.
147eaf4722dSFrank Haverkamp  */
148eaf4722dSFrank Haverkamp #define SG_CHAINED		(0x6)
149eaf4722dSFrank Haverkamp 
150eaf4722dSFrank Haverkamp /*
151eaf4722dSFrank Haverkamp  * 0b0010 First entry of a descriptor list. Start from a Buffer-Empty
152eaf4722dSFrank Haverkamp  * condition.
153eaf4722dSFrank Haverkamp  */
154eaf4722dSFrank Haverkamp #define SG_DATA			(0x2)
155eaf4722dSFrank Haverkamp 
156eaf4722dSFrank Haverkamp /*
157eaf4722dSFrank Haverkamp  * 0b0000 Early terminator. This is the last entry on the list
158eaf4722dSFrank Haverkamp  * irregardless of the length indicated.
159eaf4722dSFrank Haverkamp  */
160eaf4722dSFrank Haverkamp #define SG_END_LIST		(0x0)
161eaf4722dSFrank Haverkamp 
162eaf4722dSFrank Haverkamp /**
163eaf4722dSFrank Haverkamp  * struct sglist - Scatter gather list
164eaf4722dSFrank Haverkamp  * @target_addr:       Either a dma addr of memory to work on or a
165eaf4722dSFrank Haverkamp  *                     dma addr or a subsequent sglist block.
166eaf4722dSFrank Haverkamp  * @len:               Length of the data block.
167eaf4722dSFrank Haverkamp  * @flags:             See above.
168eaf4722dSFrank Haverkamp  *
169eaf4722dSFrank Haverkamp  * Depending on the command the GenWQE card can use a scatter gather
170eaf4722dSFrank Haverkamp  * list to describe the memory it works on. Always 8 sg_entry's form
171eaf4722dSFrank Haverkamp  * a block.
172eaf4722dSFrank Haverkamp  */
173eaf4722dSFrank Haverkamp struct sg_entry {
174eaf4722dSFrank Haverkamp 	__be64 target_addr;
175eaf4722dSFrank Haverkamp 	__be32 len;
176eaf4722dSFrank Haverkamp 	__be32 flags;
177eaf4722dSFrank Haverkamp };
178eaf4722dSFrank Haverkamp 
179eaf4722dSFrank Haverkamp #endif /* __CARD_DDCB_H__ */
180