^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Functions for incremental construction of fcx enabled I/O control blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright IBM Corp. 2008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author(s): Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <asm/fcx.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <asm/itcw.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * struct itcw - incremental tcw helper data type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * This structure serves as a handle for the incremental construction of a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * tcw and associated tccb, tsb, data tidaw-list plus an optional interrogate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * tcw and associated data. The data structures are contained inside a single
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * contiguous buffer provided by the user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * The itcw construction functions take care of overall data integrity:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * - reset unused fields to zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * - fill in required pointers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * - ensure required alignment for data structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * - prevent data structures to cross 4k-byte boundary where required
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * - calculate tccb-related length fields
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * - optionally provide ready-made interrogate tcw and associated structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * Restrictions apply to the itcws created with these construction functions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * - tida only supported for data address, not for tccb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * - only contiguous tidaw-lists (no ttic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * - total number of bytes required per itcw may not exceed 4k bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * - either read or write operation (may not work with r=0 and w=0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * Example:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * struct itcw *itcw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * void *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * size = itcw_calc_size(1, 2, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * buffer = kmalloc(size, GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * if (!buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * itcw = itcw_init(buffer, size, ITCW_OP_READ, 1, 2, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * if (IS_ERR(itcw))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * return PTR_ER(itcw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * itcw_add_dcw(itcw, 0x2, 0, NULL, 0, 72);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * itcw_add_tidaw(itcw, 0, 0x30000, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * itcw_add_tidaw(itcw, 0, 0x40000, 52);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * itcw_finalize(itcw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct itcw {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct tcw *tcw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct tcw *intrg_tcw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) int num_tidaws;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) int max_tidaws;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) int intrg_num_tidaws;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) int intrg_max_tidaws;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * itcw_get_tcw - return pointer to tcw associated with the itcw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * @itcw: address of the itcw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * Return pointer to the tcw associated with the itcw.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct tcw *itcw_get_tcw(struct itcw *itcw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return itcw->tcw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) EXPORT_SYMBOL(itcw_get_tcw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * itcw_calc_size - return the size of an itcw with the given parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * @intrg: if non-zero, add an interrogate tcw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * @max_tidaws: maximum number of tidaws to be used for data addressing or zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * if no tida is to be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * @intrg_max_tidaws: maximum number of tidaws to be used for data addressing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * by the interrogate tcw, if specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * Calculate and return the number of bytes required to hold an itcw with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * given parameters and assuming tccbs with maximum size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * Note that the resulting size also contains bytes needed for alignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * padding as well as padding to ensure that data structures don't cross a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * 4k-boundary where required.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) size_t itcw_calc_size(int intrg, int max_tidaws, int intrg_max_tidaws)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) int cross_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* Main data. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) len = sizeof(struct itcw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) len += /* TCW */ sizeof(struct tcw) + /* TCCB */ TCCB_MAX_SIZE +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /* TSB */ sizeof(struct tsb) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /* TIDAL */ max_tidaws * sizeof(struct tidaw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /* Interrogate data. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (intrg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) len += /* TCW */ sizeof(struct tcw) + /* TCCB */ TCCB_MAX_SIZE +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /* TSB */ sizeof(struct tsb) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /* TIDAL */ intrg_max_tidaws * sizeof(struct tidaw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /* Maximum required alignment padding. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) len += /* Initial TCW */ 63 + /* Interrogate TCCB */ 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /* TIDAW lists may not cross a 4k boundary. To cross a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * boundary we need to add a TTIC TIDAW. We need to reserve
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * one additional TIDAW for a TTIC that we may need to add due
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * to the placement of the data chunk in memory, and a further
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * TIDAW for each page boundary that the TIDAW list may cross
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * due to it's own size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (max_tidaws) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) cross_count = 1 + ((max_tidaws * sizeof(struct tidaw) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) >> PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) len += cross_count * sizeof(struct tidaw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (intrg_max_tidaws) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) cross_count = 1 + ((intrg_max_tidaws * sizeof(struct tidaw) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) >> PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) len += cross_count * sizeof(struct tidaw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) EXPORT_SYMBOL(itcw_calc_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #define CROSS4K(x, l) (((x) & ~4095) != ((x + l) & ~4095))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static inline void *fit_chunk(addr_t *start, addr_t end, size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int align, int check_4k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) addr_t addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) addr = ALIGN(*start, align);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (check_4k && CROSS4K(addr, len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) addr = ALIGN(addr, 4096);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) addr = ALIGN(addr, align);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (addr + len > end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return ERR_PTR(-ENOSPC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) *start = addr + len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return (void *) addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * itcw_init - initialize incremental tcw data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * @buffer: address of buffer to use for data structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * @size: number of bytes in buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * @op: %ITCW_OP_READ for a read operation tcw, %ITCW_OP_WRITE for a write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * operation tcw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * @intrg: if non-zero, add and initialize an interrogate tcw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * @max_tidaws: maximum number of tidaws to be used for data addressing or zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * if no tida is to be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * @intrg_max_tidaws: maximum number of tidaws to be used for data addressing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * by the interrogate tcw, if specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * Prepare the specified buffer to be used as an incremental tcw, i.e. a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * helper data structure that can be used to construct a valid tcw by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * successive calls to other helper functions. Note: the buffer needs to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * located below the 2G address limit. The resulting tcw has the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * restrictions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * - no tccb tidal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * - input/output tidal is contiguous (no ttic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * - total data should not exceed 4k
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * - tcw specifies either read or write operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * On success, return pointer to the resulting incremental tcw data structure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * ERR_PTR otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct itcw *itcw_init(void *buffer, size_t size, int op, int intrg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) int max_tidaws, int intrg_max_tidaws)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct itcw *itcw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) void *chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) addr_t start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) addr_t end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) int cross_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /* Check for 2G limit. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) start = (addr_t) buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) end = start + size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (end > (1 << 31))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) memset(buffer, 0, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /* ITCW. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) chunk = fit_chunk(&start, end, sizeof(struct itcw), 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (IS_ERR(chunk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) itcw = chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /* allow for TTIC tidaws that may be needed to cross a page boundary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) cross_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (max_tidaws)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) cross_count = 1 + ((max_tidaws * sizeof(struct tidaw) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) >> PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) itcw->max_tidaws = max_tidaws + cross_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) cross_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (intrg_max_tidaws)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) cross_count = 1 + ((intrg_max_tidaws * sizeof(struct tidaw) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) >> PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) itcw->intrg_max_tidaws = intrg_max_tidaws + cross_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /* Main TCW. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) chunk = fit_chunk(&start, end, sizeof(struct tcw), 64, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (IS_ERR(chunk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) return chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) itcw->tcw = chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) tcw_init(itcw->tcw, (op == ITCW_OP_READ) ? 1 : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) (op == ITCW_OP_WRITE) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /* Interrogate TCW. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (intrg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) chunk = fit_chunk(&start, end, sizeof(struct tcw), 64, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (IS_ERR(chunk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) itcw->intrg_tcw = chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) tcw_init(itcw->intrg_tcw, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) tcw_set_intrg(itcw->tcw, itcw->intrg_tcw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /* Data TIDAL. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (max_tidaws > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) chunk = fit_chunk(&start, end, sizeof(struct tidaw) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) itcw->max_tidaws, 16, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (IS_ERR(chunk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) tcw_set_data(itcw->tcw, chunk, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /* Interrogate data TIDAL. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (intrg && (intrg_max_tidaws > 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) chunk = fit_chunk(&start, end, sizeof(struct tidaw) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) itcw->intrg_max_tidaws, 16, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (IS_ERR(chunk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) tcw_set_data(itcw->intrg_tcw, chunk, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /* TSB. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) chunk = fit_chunk(&start, end, sizeof(struct tsb), 8, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (IS_ERR(chunk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) tsb_init(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) tcw_set_tsb(itcw->tcw, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /* Interrogate TSB. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (intrg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) chunk = fit_chunk(&start, end, sizeof(struct tsb), 8, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (IS_ERR(chunk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) tsb_init(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) tcw_set_tsb(itcw->intrg_tcw, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /* TCCB. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) chunk = fit_chunk(&start, end, TCCB_MAX_SIZE, 8, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (IS_ERR(chunk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) tccb_init(chunk, TCCB_MAX_SIZE, TCCB_SAC_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) tcw_set_tccb(itcw->tcw, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /* Interrogate TCCB. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (intrg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) chunk = fit_chunk(&start, end, TCCB_MAX_SIZE, 8, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (IS_ERR(chunk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) tccb_init(chunk, TCCB_MAX_SIZE, TCCB_SAC_INTRG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) tcw_set_tccb(itcw->intrg_tcw, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) tccb_add_dcw(chunk, TCCB_MAX_SIZE, DCW_CMD_INTRG, 0, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) sizeof(struct dcw_intrg_data), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) tcw_finalize(itcw->intrg_tcw, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) return itcw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) EXPORT_SYMBOL(itcw_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * itcw_add_dcw - add a dcw to the itcw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * @itcw: address of the itcw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * @cmd: the dcw command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * @flags: flags for the dcw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * @cd: address of control data for this dcw or NULL if none is required
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * @cd_count: number of control data bytes for this dcw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * @count: number of data bytes for this dcw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * Add a new dcw to the specified itcw by writing the dcw information specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * by @cmd, @flags, @cd, @cd_count and @count to the tca of the tccb. Return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * a pointer to the newly added dcw on success or -%ENOSPC if the new dcw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) * would exceed the available space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) * Note: the tcal field of the tccb header will be updated to reflect added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) * content.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) struct dcw *itcw_add_dcw(struct itcw *itcw, u8 cmd, u8 flags, void *cd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) u8 cd_count, u32 count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return tccb_add_dcw(tcw_get_tccb(itcw->tcw), TCCB_MAX_SIZE, cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) flags, cd, cd_count, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) EXPORT_SYMBOL(itcw_add_dcw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * itcw_add_tidaw - add a tidaw to the itcw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * @itcw: address of the itcw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * @flags: flags for the new tidaw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * @addr: address value for the new tidaw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * @count: count value for the new tidaw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * Add a new tidaw to the input/output data tidaw-list of the specified itcw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * (depending on the value of the r-flag and w-flag). Return a pointer to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * the new tidaw on success or -%ENOSPC if the new tidaw would exceed the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * available space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * Note: TTIC tidaws are automatically added when needed, so explicitly calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * this interface with the TTIC flag is not supported. The last-tidaw flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) * for the last tidaw in the list will be set by itcw_finalize.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) struct tidaw *itcw_add_tidaw(struct itcw *itcw, u8 flags, void *addr, u32 count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) struct tidaw *following;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) if (itcw->num_tidaws >= itcw->max_tidaws)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) return ERR_PTR(-ENOSPC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * Is the tidaw, which follows the one we are about to fill, on the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * page? Then we have to insert a TTIC tidaw first, that points to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * tidaw on the new page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) following = ((struct tidaw *) tcw_get_data(itcw->tcw))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) + itcw->num_tidaws + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) if (itcw->num_tidaws && !((unsigned long) following & ~PAGE_MASK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) tcw_add_tidaw(itcw->tcw, itcw->num_tidaws++,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) TIDAW_FLAGS_TTIC, following, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) if (itcw->num_tidaws >= itcw->max_tidaws)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) return ERR_PTR(-ENOSPC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) return tcw_add_tidaw(itcw->tcw, itcw->num_tidaws++, flags, addr, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) EXPORT_SYMBOL(itcw_add_tidaw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) * itcw_set_data - set data address and tida flag of the itcw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) * @itcw: address of the itcw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * @addr: the data address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * @use_tidal: zero of the data address specifies a contiguous block of data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) * non-zero if it specifies a list if tidaws.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) * Set the input/output data address of the itcw (depending on the value of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) * r-flag and w-flag). If @use_tidal is non-zero, the corresponding tida flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) * is set as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) void itcw_set_data(struct itcw *itcw, void *addr, int use_tidal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) tcw_set_data(itcw->tcw, addr, use_tidal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) EXPORT_SYMBOL(itcw_set_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * itcw_finalize - calculate length and count fields of the itcw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * @itcw: address of the itcw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) * Calculate tcw input-/output-count and tccbl fields and add a tcat the tccb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * In case input- or output-tida is used, the tidaw-list must be stored in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * continuous storage (no ttic). The tcal field in the tccb must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * up-to-date.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) void itcw_finalize(struct itcw *itcw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) tcw_finalize(itcw->tcw, itcw->num_tidaws);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) EXPORT_SYMBOL(itcw_finalize);