// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright(c) 2007 Yuri Tikhonov <[email protected]> * Copyright(c) 2009 Intel Corporation */ #include <linux/kernel.h> #include <linux/interrupt.h> #include <linux/module.h> #include <linux/dma-mapping.h> #include <linux/raid/pq.h> #include <linux/async_tx.h> #include <linux/gfp.h> /* * struct pq_scribble_page - space to hold throwaway P or Q buffer for * synchronous gen_syndrome */ static struct page *pq_scribble_page; /* the struct page *blocks[] parameter passed to async_gen_syndrome() * and async_syndrome_val() contains the 'P' destination address at * blocks[disks-2] and the 'Q' destination address at blocks[disks-1] * * note: these are macros as they are used as lvalues */ #define P(b, d) … #define Q(b, d) … #define MAX_DISKS … /* * do_async_gen_syndrome - asynchronously calculate P and/or Q */ static __async_inline struct dma_async_tx_descriptor * do_async_gen_syndrome(struct dma_chan *chan, const unsigned char *scfs, int disks, struct dmaengine_unmap_data *unmap, enum dma_ctrl_flags dma_flags, struct async_submit_ctl *submit) { … } /* * do_sync_gen_syndrome - synchronously calculate a raid6 syndrome */ static void do_sync_gen_syndrome(struct page **blocks, unsigned int *offsets, int disks, size_t len, struct async_submit_ctl *submit) { … } static inline bool is_dma_pq_aligned_offs(struct dma_device *dev, unsigned int *offs, int src_cnt, size_t len) { … } /** * async_gen_syndrome - asynchronously calculate a raid6 syndrome * @blocks: source blocks from idx 0..disks-3, P @ disks-2 and Q @ disks-1 * @offsets: offset array into each block (src and dest) to start transaction * @disks: number of blocks (including missing P or Q, see below) * @len: length of operation in bytes * @submit: submission/completion modifiers * * General note: This routine assumes a field of GF(2^8) with a * primitive polynomial of 0x11d and a generator of {02}. * * 'disks' note: callers can optionally omit either P or Q (but not * both) from the calculation by setting blocks[disks-2] or * blocks[disks-1] to NULL. When P or Q is omitted 'len' must be <= * PAGE_SIZE as a temporary buffer of this size is used in the * synchronous path. 'disks' always accounts for both destination * buffers. If any source buffers (blocks[i] where i < disks - 2) are * set to NULL those buffers will be replaced with the raid6_zero_page * in the synchronous path and omitted in the hardware-asynchronous * path. */ struct dma_async_tx_descriptor * async_gen_syndrome(struct page **blocks, unsigned int *offsets, int disks, size_t len, struct async_submit_ctl *submit) { … } EXPORT_SYMBOL_GPL(…); static inline struct dma_chan * pq_val_chan(struct async_submit_ctl *submit, struct page **blocks, int disks, size_t len) { … } /** * async_syndrome_val - asynchronously validate a raid6 syndrome * @blocks: source blocks from idx 0..disks-3, P @ disks-2 and Q @ disks-1 * @offsets: common offset into each block (src and dest) to start transaction * @disks: number of blocks (including missing P or Q, see below) * @len: length of operation in bytes * @pqres: on val failure SUM_CHECK_P_RESULT and/or SUM_CHECK_Q_RESULT are set * @spare: temporary result buffer for the synchronous case * @s_off: spare buffer page offset * @submit: submission / completion modifiers * * The same notes from async_gen_syndrome apply to the 'blocks', * and 'disks' parameters of this routine. The synchronous path * requires a temporary result buffer and submit->scribble to be * specified. */ struct dma_async_tx_descriptor * async_syndrome_val(struct page **blocks, unsigned int *offsets, int disks, size_t len, enum sum_check_flags *pqres, struct page *spare, unsigned int s_off, struct async_submit_ctl *submit) { … } EXPORT_SYMBOL_GPL(…); static int __init async_pq_init(void) { … } static void __exit async_pq_exit(void) { … } module_init(…) …; module_exit(async_pq_exit); MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …;