1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or https://opensource.org/licenses/CDDL-1.0. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (c) 2014 by Chunwei Chen. All rights reserved. 23 * Copyright (c) 2016, 2019 by Delphix. All rights reserved. 24 * Copyright (c) 2023, 2024, Klara Inc. 25 */ 26 27 #ifndef _ABD_IMPL_H 28 #define _ABD_IMPL_H 29 30 #include <sys/abd.h> 31 #include <sys/abd_impl_os.h> 32 #include <sys/wmsum.h> 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 typedef enum abd_stats_op { 39 ABDSTAT_INCR, /* Increase abdstat values */ 40 ABDSTAT_DECR /* Decrease abdstat values */ 41 } abd_stats_op_t; 42 43 /* forward declarations */ 44 struct scatterlist; 45 struct page; 46 47 struct abd_iter { 48 /* public interface */ 49 union { 50 /* for abd_iter_map()/abd_iter_unmap() */ 51 struct { 52 /* addr corresponding to iter_pos */ 53 void *iter_mapaddr; 54 /* length of data valid at mapaddr */ 55 size_t iter_mapsize; 56 }; 57 /* for abd_iter_page() */ 58 struct { 59 /* current page */ 60 struct page *iter_page; 61 /* offset of data in page */ 62 size_t iter_page_doff; 63 /* size of data in page */ 64 size_t iter_page_dsize; 65 }; 66 }; 67 68 /* private */ 69 abd_t *iter_abd; /* ABD being iterated through */ 70 size_t iter_pos; 71 size_t iter_offset; /* offset in current sg/abd_buf, */ 72 /* abd_offset included */ 73 struct scatterlist *iter_sg; /* current sg */ 74 }; 75 76 extern abd_t *abd_zero_scatter; 77 78 abd_t *abd_gang_get_offset(abd_t *, size_t *); 79 abd_t *abd_alloc_struct(size_t); 80 void abd_free_struct(abd_t *); 81 82 /* 83 * OS specific functions 84 */ 85 86 abd_t *abd_alloc_struct_impl(size_t); 87 abd_t *abd_get_offset_scatter(abd_t *, abd_t *, size_t, size_t); 88 void abd_free_struct_impl(abd_t *); 89 void abd_alloc_chunks(abd_t *, size_t); 90 void abd_free_chunks(abd_t *); 91 void abd_update_scatter_stats(abd_t *, abd_stats_op_t); 92 void abd_update_linear_stats(abd_t *, abd_stats_op_t); 93 void abd_verify_scatter(abd_t *); 94 void abd_free_linear_page(abd_t *); 95 /* OS specific abd_iter functions */ 96 void abd_iter_init(struct abd_iter *, abd_t *); 97 boolean_t abd_iter_at_end(struct abd_iter *); 98 void abd_iter_advance(struct abd_iter *, size_t); 99 void abd_iter_map(struct abd_iter *); 100 void abd_iter_unmap(struct abd_iter *); 101 void abd_iter_page(struct abd_iter *); 102 103 /* 104 * Helper macros 105 */ 106 #define ABDSTAT_INCR(stat, val) \ 107 wmsum_add(&abd_sums.stat, (val)) 108 #define ABDSTAT_BUMP(stat) ABDSTAT_INCR(stat, 1) 109 #define ABDSTAT_BUMPDOWN(stat) ABDSTAT_INCR(stat, -1) 110 111 #define ABD_SCATTER(abd) (abd->abd_u.abd_scatter) 112 #define ABD_LINEAR_BUF(abd) (abd->abd_u.abd_linear.abd_buf) 113 #define ABD_GANG(abd) (abd->abd_u.abd_gang) 114 115 #ifdef __cplusplus 116 } 117 #endif 118 119 #endif /* _ABD_IMPL_H */ 120