1 /* SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2018 Marvell International Ltd.
6 #ifndef __OCTEONTX_BCH_REGS_H__
7 #define __OCTEONTX_BCH_REGS_H__
16 u64 reserved_12_31:20;
18 u64 reserved_36_61:26;
36 u64 reserved_49_63:15;
48 /** Response from BCH instruction */
52 u16 num_errors:7; /** Number of errors in block */
53 u16 zero:6; /** Always zero, ignore */
54 u16 erased:1; /** Block is erased */
55 u16 uncorrectable:1;/** too many bits flipped */
56 u16 done:1; /** Block is done */
70 u64 reserved_22_63:42;
74 union bch_vqx_cmd_buf {
81 u64 reserved_48_63:16;
85 /* keep queue state indexed, even though just one supported here,
86 * for later generalization to similarly-shaped queues on other Cavium devices
99 dma_addr_t base_paddr;
102 extern struct bch_q octeontx_bch_q[QID_MAX];
104 /* with one dma-mapped area, virt<->phys conversions by +/- (vaddr-paddr) */
105 static inline dma_addr_t qphys(int qid, void *v)
107 struct bch_q *q = &octeontx_bch_q[qid];
108 int off = (u8 *)v - (u8 *)q->base_vaddr;
110 return q->base_paddr + off;
113 #define octeontx_ptr_to_phys(v) qphys(QID_BCH, (v))
115 static inline void *qvirt(int qid, dma_addr_t p)
117 struct bch_q *q = &octeontx_bch_q[qid];
118 int off = p - q->base_paddr;
120 return q->base_vaddr + off;
123 #define octeontx_phys_to_ptr(p) qvirt(QID_BCH, (p))
125 /* plenty for interleaved r/w on two planes with 16k page, ecc_size 1k */
126 /* QDEPTH >= 16, as successive chunks must align on 128-byte boundaries */
127 #define QDEPTH 256 /* u64s in a command queue chunk, incl next-pointer */
128 #define NQS 1 /* linked chunks in the chain */
131 * Write an arbitrary number of command words to a command queue.
132 * This is a generic function; the fixed number of command word
133 * functions yield higher performance.
135 * Could merge with crypto version for FPA use on cn83xx
137 static inline int octeontx_cmd_queue_write(int queue_id, bool use_locking,
138 int cmd_count, const u64 *cmds)
142 struct bch_q *qptr = &octeontx_bch_q[queue_id];
144 if (unlikely(cmd_count < 1 || cmd_count > 32))
149 cmd_ptr = qptr->base_vaddr;
151 while (cmd_count > 0) {
152 int slot = qptr->index % (QDEPTH * NQS);
154 if (slot % QDEPTH != QDEPTH - 1) {
155 cmd_ptr[slot] = *cmds++;
162 __iowmb(); /* flush commands before ringing bell */
167 #endif /* __OCTEONTX_BCH_REGS_H__ */