Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Quick'n'dirty IP checksum ... |
| 7 | * |
| 8 | * Copyright (C) 1998, 1999 Ralf Baechle |
| 9 | * Copyright (C) 1999 Silicon Graphics, Inc. |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 10 | * Copyright (C) 2007 Maciej W. Rozycki |
Markos Chandras | ac85227 | 2013-12-12 16:21:00 +0000 | [diff] [blame] | 11 | * Copyright (C) 2014 Imagination Technologies Ltd. |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 12 | */ |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 13 | #include <linux/errno.h> |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 14 | #include <asm/asm.h> |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 15 | #include <asm/asm-offsets.h> |
Paul Burton | 2313004 | 2016-11-07 11:14:13 +0000 | [diff] [blame] | 16 | #include <asm/export.h> |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 17 | #include <asm/regdef.h> |
| 18 | |
| 19 | #ifdef CONFIG_64BIT |
Atsushi Nemoto | 52ffe76 | 2006-12-08 01:04:31 +0900 | [diff] [blame] | 20 | /* |
| 21 | * As we are sharing code base with the mips32 tree (which use the o32 ABI |
| 22 | * register definitions). We need to redefine the register definitions from |
| 23 | * the n64 ABI register naming to the o32 ABI register naming. |
| 24 | */ |
| 25 | #undef t0 |
| 26 | #undef t1 |
| 27 | #undef t2 |
| 28 | #undef t3 |
| 29 | #define t0 $8 |
| 30 | #define t1 $9 |
| 31 | #define t2 $10 |
| 32 | #define t3 $11 |
| 33 | #define t4 $12 |
| 34 | #define t5 $13 |
| 35 | #define t6 $14 |
| 36 | #define t7 $15 |
Atsushi Nemoto | ed99e2b | 2006-12-08 01:04:51 +0900 | [diff] [blame] | 37 | |
| 38 | #define USE_DOUBLE |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 39 | #endif |
| 40 | |
Atsushi Nemoto | ed99e2b | 2006-12-08 01:04:51 +0900 | [diff] [blame] | 41 | #ifdef USE_DOUBLE |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 42 | |
Atsushi Nemoto | ed99e2b | 2006-12-08 01:04:51 +0900 | [diff] [blame] | 43 | #define LOAD ld |
Atsushi Nemoto | b80a1b8 | 2008-09-20 17:20:04 +0200 | [diff] [blame] | 44 | #define LOAD32 lwu |
Atsushi Nemoto | ed99e2b | 2006-12-08 01:04:51 +0900 | [diff] [blame] | 45 | #define ADD daddu |
| 46 | #define NBYTES 8 |
| 47 | |
| 48 | #else |
| 49 | |
| 50 | #define LOAD lw |
Atsushi Nemoto | b80a1b8 | 2008-09-20 17:20:04 +0200 | [diff] [blame] | 51 | #define LOAD32 lw |
Atsushi Nemoto | ed99e2b | 2006-12-08 01:04:51 +0900 | [diff] [blame] | 52 | #define ADD addu |
| 53 | #define NBYTES 4 |
| 54 | |
| 55 | #endif /* USE_DOUBLE */ |
| 56 | |
| 57 | #define UNIT(unit) ((unit)*NBYTES) |
| 58 | |
| 59 | #define ADDC(sum,reg) \ |
Maciej W. Rozycki | 44ba138 | 2014-04-04 03:32:54 +0100 | [diff] [blame] | 60 | .set push; \ |
| 61 | .set noat; \ |
Atsushi Nemoto | ed99e2b | 2006-12-08 01:04:51 +0900 | [diff] [blame] | 62 | ADD sum, reg; \ |
| 63 | sltu v1, sum, reg; \ |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 64 | ADD sum, v1; \ |
Maciej W. Rozycki | 44ba138 | 2014-04-04 03:32:54 +0100 | [diff] [blame] | 65 | .set pop |
Atsushi Nemoto | ed99e2b | 2006-12-08 01:04:51 +0900 | [diff] [blame] | 66 | |
Atsushi Nemoto | b80a1b8 | 2008-09-20 17:20:04 +0200 | [diff] [blame] | 67 | #define ADDC32(sum,reg) \ |
Maciej W. Rozycki | 44ba138 | 2014-04-04 03:32:54 +0100 | [diff] [blame] | 68 | .set push; \ |
| 69 | .set noat; \ |
Atsushi Nemoto | b80a1b8 | 2008-09-20 17:20:04 +0200 | [diff] [blame] | 70 | addu sum, reg; \ |
| 71 | sltu v1, sum, reg; \ |
| 72 | addu sum, v1; \ |
Maciej W. Rozycki | 44ba138 | 2014-04-04 03:32:54 +0100 | [diff] [blame] | 73 | .set pop |
Atsushi Nemoto | b80a1b8 | 2008-09-20 17:20:04 +0200 | [diff] [blame] | 74 | |
Atsushi Nemoto | ed99e2b | 2006-12-08 01:04:51 +0900 | [diff] [blame] | 75 | #define CSUM_BIGCHUNK1(src, offset, sum, _t0, _t1, _t2, _t3) \ |
| 76 | LOAD _t0, (offset + UNIT(0))(src); \ |
| 77 | LOAD _t1, (offset + UNIT(1))(src); \ |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 78 | LOAD _t2, (offset + UNIT(2))(src); \ |
| 79 | LOAD _t3, (offset + UNIT(3))(src); \ |
Chen Jie | 615eb60 | 2015-03-27 01:07:24 +0800 | [diff] [blame] | 80 | ADDC(_t0, _t1); \ |
| 81 | ADDC(_t2, _t3); \ |
Atsushi Nemoto | ed99e2b | 2006-12-08 01:04:51 +0900 | [diff] [blame] | 82 | ADDC(sum, _t0); \ |
Chen Jie | 615eb60 | 2015-03-27 01:07:24 +0800 | [diff] [blame] | 83 | ADDC(sum, _t2) |
Atsushi Nemoto | ed99e2b | 2006-12-08 01:04:51 +0900 | [diff] [blame] | 84 | |
| 85 | #ifdef USE_DOUBLE |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 86 | #define CSUM_BIGCHUNK(src, offset, sum, _t0, _t1, _t2, _t3) \ |
Atsushi Nemoto | ed99e2b | 2006-12-08 01:04:51 +0900 | [diff] [blame] | 87 | CSUM_BIGCHUNK1(src, offset, sum, _t0, _t1, _t2, _t3) |
| 88 | #else |
| 89 | #define CSUM_BIGCHUNK(src, offset, sum, _t0, _t1, _t2, _t3) \ |
| 90 | CSUM_BIGCHUNK1(src, offset, sum, _t0, _t1, _t2, _t3); \ |
| 91 | CSUM_BIGCHUNK1(src, offset + 0x10, sum, _t0, _t1, _t2, _t3) |
| 92 | #endif |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 93 | |
| 94 | /* |
| 95 | * a0: source address |
| 96 | * a1: length of the area to checksum |
| 97 | * a2: partial checksum |
| 98 | */ |
| 99 | |
| 100 | #define src a0 |
| 101 | #define sum v0 |
| 102 | |
| 103 | .text |
| 104 | .set noreorder |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 105 | .align 5 |
| 106 | LEAF(csum_partial) |
Paul Burton | 2313004 | 2016-11-07 11:14:13 +0000 | [diff] [blame] | 107 | EXPORT_SYMBOL(csum_partial) |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 108 | move sum, zero |
Atsushi Nemoto | 52ffe76 | 2006-12-08 01:04:31 +0900 | [diff] [blame] | 109 | move t7, zero |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 110 | |
| 111 | sltiu t8, a1, 0x8 |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 112 | bnez t8, .Lsmall_csumcpy /* < 8 bytes to copy */ |
Atsushi Nemoto | 52ffe76 | 2006-12-08 01:04:31 +0900 | [diff] [blame] | 113 | move t2, a1 |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 114 | |
Atsushi Nemoto | 773ff78 | 2006-12-08 01:04:45 +0900 | [diff] [blame] | 115 | andi t7, src, 0x1 /* odd buffer? */ |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 116 | |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 117 | .Lhword_align: |
| 118 | beqz t7, .Lword_align |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 119 | andi t8, src, 0x2 |
| 120 | |
Atsushi Nemoto | 52ffe76 | 2006-12-08 01:04:31 +0900 | [diff] [blame] | 121 | lbu t0, (src) |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 122 | LONG_SUBU a1, a1, 0x1 |
| 123 | #ifdef __MIPSEL__ |
Atsushi Nemoto | 52ffe76 | 2006-12-08 01:04:31 +0900 | [diff] [blame] | 124 | sll t0, t0, 8 |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 125 | #endif |
Atsushi Nemoto | 52ffe76 | 2006-12-08 01:04:31 +0900 | [diff] [blame] | 126 | ADDC(sum, t0) |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 127 | PTR_ADDU src, src, 0x1 |
| 128 | andi t8, src, 0x2 |
| 129 | |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 130 | .Lword_align: |
| 131 | beqz t8, .Ldword_align |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 132 | sltiu t8, a1, 56 |
| 133 | |
Atsushi Nemoto | 52ffe76 | 2006-12-08 01:04:31 +0900 | [diff] [blame] | 134 | lhu t0, (src) |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 135 | LONG_SUBU a1, a1, 0x2 |
Atsushi Nemoto | 52ffe76 | 2006-12-08 01:04:31 +0900 | [diff] [blame] | 136 | ADDC(sum, t0) |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 137 | sltiu t8, a1, 56 |
| 138 | PTR_ADDU src, src, 0x2 |
| 139 | |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 140 | .Ldword_align: |
| 141 | bnez t8, .Ldo_end_words |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 142 | move t8, a1 |
| 143 | |
| 144 | andi t8, src, 0x4 |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 145 | beqz t8, .Lqword_align |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 146 | andi t8, src, 0x8 |
| 147 | |
Atsushi Nemoto | b80a1b8 | 2008-09-20 17:20:04 +0200 | [diff] [blame] | 148 | LOAD32 t0, 0x00(src) |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 149 | LONG_SUBU a1, a1, 0x4 |
Atsushi Nemoto | 52ffe76 | 2006-12-08 01:04:31 +0900 | [diff] [blame] | 150 | ADDC(sum, t0) |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 151 | PTR_ADDU src, src, 0x4 |
| 152 | andi t8, src, 0x8 |
| 153 | |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 154 | .Lqword_align: |
| 155 | beqz t8, .Loword_align |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 156 | andi t8, src, 0x10 |
| 157 | |
Atsushi Nemoto | ed99e2b | 2006-12-08 01:04:51 +0900 | [diff] [blame] | 158 | #ifdef USE_DOUBLE |
| 159 | ld t0, 0x00(src) |
| 160 | LONG_SUBU a1, a1, 0x8 |
| 161 | ADDC(sum, t0) |
| 162 | #else |
Atsushi Nemoto | 52ffe76 | 2006-12-08 01:04:31 +0900 | [diff] [blame] | 163 | lw t0, 0x00(src) |
| 164 | lw t1, 0x04(src) |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 165 | LONG_SUBU a1, a1, 0x8 |
Atsushi Nemoto | 52ffe76 | 2006-12-08 01:04:31 +0900 | [diff] [blame] | 166 | ADDC(sum, t0) |
| 167 | ADDC(sum, t1) |
Atsushi Nemoto | ed99e2b | 2006-12-08 01:04:51 +0900 | [diff] [blame] | 168 | #endif |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 169 | PTR_ADDU src, src, 0x8 |
| 170 | andi t8, src, 0x10 |
| 171 | |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 172 | .Loword_align: |
| 173 | beqz t8, .Lbegin_movement |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 174 | LONG_SRL t8, a1, 0x7 |
| 175 | |
Atsushi Nemoto | ed99e2b | 2006-12-08 01:04:51 +0900 | [diff] [blame] | 176 | #ifdef USE_DOUBLE |
| 177 | ld t0, 0x00(src) |
| 178 | ld t1, 0x08(src) |
Atsushi Nemoto | 52ffe76 | 2006-12-08 01:04:31 +0900 | [diff] [blame] | 179 | ADDC(sum, t0) |
| 180 | ADDC(sum, t1) |
Atsushi Nemoto | ed99e2b | 2006-12-08 01:04:51 +0900 | [diff] [blame] | 181 | #else |
| 182 | CSUM_BIGCHUNK1(src, 0x00, sum, t0, t1, t3, t4) |
| 183 | #endif |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 184 | LONG_SUBU a1, a1, 0x10 |
| 185 | PTR_ADDU src, src, 0x10 |
| 186 | LONG_SRL t8, a1, 0x7 |
| 187 | |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 188 | .Lbegin_movement: |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 189 | beqz t8, 1f |
Atsushi Nemoto | 52ffe76 | 2006-12-08 01:04:31 +0900 | [diff] [blame] | 190 | andi t2, a1, 0x40 |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 191 | |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 192 | .Lmove_128bytes: |
Atsushi Nemoto | 52ffe76 | 2006-12-08 01:04:31 +0900 | [diff] [blame] | 193 | CSUM_BIGCHUNK(src, 0x00, sum, t0, t1, t3, t4) |
| 194 | CSUM_BIGCHUNK(src, 0x20, sum, t0, t1, t3, t4) |
| 195 | CSUM_BIGCHUNK(src, 0x40, sum, t0, t1, t3, t4) |
| 196 | CSUM_BIGCHUNK(src, 0x60, sum, t0, t1, t3, t4) |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 197 | LONG_SUBU t8, t8, 0x01 |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 198 | .set reorder /* DADDI_WAR */ |
| 199 | PTR_ADDU src, src, 0x80 |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 200 | bnez t8, .Lmove_128bytes |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 201 | .set noreorder |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 202 | |
| 203 | 1: |
Atsushi Nemoto | 52ffe76 | 2006-12-08 01:04:31 +0900 | [diff] [blame] | 204 | beqz t2, 1f |
| 205 | andi t2, a1, 0x20 |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 206 | |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 207 | .Lmove_64bytes: |
Atsushi Nemoto | 52ffe76 | 2006-12-08 01:04:31 +0900 | [diff] [blame] | 208 | CSUM_BIGCHUNK(src, 0x00, sum, t0, t1, t3, t4) |
| 209 | CSUM_BIGCHUNK(src, 0x20, sum, t0, t1, t3, t4) |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 210 | PTR_ADDU src, src, 0x40 |
| 211 | |
| 212 | 1: |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 213 | beqz t2, .Ldo_end_words |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 214 | andi t8, a1, 0x1c |
| 215 | |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 216 | .Lmove_32bytes: |
Atsushi Nemoto | 52ffe76 | 2006-12-08 01:04:31 +0900 | [diff] [blame] | 217 | CSUM_BIGCHUNK(src, 0x00, sum, t0, t1, t3, t4) |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 218 | andi t8, a1, 0x1c |
| 219 | PTR_ADDU src, src, 0x20 |
| 220 | |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 221 | .Ldo_end_words: |
| 222 | beqz t8, .Lsmall_csumcpy |
Atsushi Nemoto | 773ff78 | 2006-12-08 01:04:45 +0900 | [diff] [blame] | 223 | andi t2, a1, 0x3 |
| 224 | LONG_SRL t8, t8, 0x2 |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 225 | |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 226 | .Lend_words: |
Atsushi Nemoto | b80a1b8 | 2008-09-20 17:20:04 +0200 | [diff] [blame] | 227 | LOAD32 t0, (src) |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 228 | LONG_SUBU t8, t8, 0x1 |
Atsushi Nemoto | 52ffe76 | 2006-12-08 01:04:31 +0900 | [diff] [blame] | 229 | ADDC(sum, t0) |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 230 | .set reorder /* DADDI_WAR */ |
| 231 | PTR_ADDU src, src, 0x4 |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 232 | bnez t8, .Lend_words |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 233 | .set noreorder |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 234 | |
Atsushi Nemoto | 773ff78 | 2006-12-08 01:04:45 +0900 | [diff] [blame] | 235 | /* unknown src alignment and < 8 bytes to go */ |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 236 | .Lsmall_csumcpy: |
Atsushi Nemoto | 773ff78 | 2006-12-08 01:04:45 +0900 | [diff] [blame] | 237 | move a1, t2 |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 238 | |
Atsushi Nemoto | 773ff78 | 2006-12-08 01:04:45 +0900 | [diff] [blame] | 239 | andi t0, a1, 4 |
| 240 | beqz t0, 1f |
| 241 | andi t0, a1, 2 |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 242 | |
Atsushi Nemoto | 773ff78 | 2006-12-08 01:04:45 +0900 | [diff] [blame] | 243 | /* Still a full word to go */ |
| 244 | ulw t1, (src) |
| 245 | PTR_ADDIU src, 4 |
Atsushi Nemoto | b80a1b8 | 2008-09-20 17:20:04 +0200 | [diff] [blame] | 246 | #ifdef USE_DOUBLE |
| 247 | dsll t1, t1, 32 /* clear lower 32bit */ |
| 248 | #endif |
Atsushi Nemoto | 773ff78 | 2006-12-08 01:04:45 +0900 | [diff] [blame] | 249 | ADDC(sum, t1) |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 250 | |
Atsushi Nemoto | 773ff78 | 2006-12-08 01:04:45 +0900 | [diff] [blame] | 251 | 1: move t1, zero |
| 252 | beqz t0, 1f |
| 253 | andi t0, a1, 1 |
| 254 | |
| 255 | /* Still a halfword to go */ |
| 256 | ulhu t1, (src) |
| 257 | PTR_ADDIU src, 2 |
| 258 | |
| 259 | 1: beqz t0, 1f |
| 260 | sll t1, t1, 16 |
| 261 | |
| 262 | lbu t2, (src) |
| 263 | nop |
| 264 | |
| 265 | #ifdef __MIPSEB__ |
| 266 | sll t2, t2, 8 |
| 267 | #endif |
| 268 | or t1, t2 |
| 269 | |
| 270 | 1: ADDC(sum, t1) |
| 271 | |
| 272 | /* fold checksum */ |
Atsushi Nemoto | ed99e2b | 2006-12-08 01:04:51 +0900 | [diff] [blame] | 273 | #ifdef USE_DOUBLE |
| 274 | dsll32 v1, sum, 0 |
| 275 | daddu sum, v1 |
| 276 | sltu v1, sum, v1 |
| 277 | dsra32 sum, sum, 0 |
| 278 | addu sum, v1 |
| 279 | #endif |
Atsushi Nemoto | 773ff78 | 2006-12-08 01:04:45 +0900 | [diff] [blame] | 280 | |
| 281 | /* odd buffer alignment? */ |
Serge Semin | ab7c01f | 2020-05-21 17:07:14 +0300 | [diff] [blame] | 282 | #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR5) || \ |
| 283 | defined(CONFIG_CPU_LOONGSON64) |
Chen Jie | 3c09bae | 2014-08-15 16:56:58 +0800 | [diff] [blame] | 284 | .set push |
| 285 | .set arch=mips32r2 |
Ralf Baechle | b65a75b | 2008-10-11 16:18:53 +0100 | [diff] [blame] | 286 | wsbh v1, sum |
| 287 | movn sum, v1, t7 |
Chen Jie | 3c09bae | 2014-08-15 16:56:58 +0800 | [diff] [blame] | 288 | .set pop |
Ralf Baechle | b65a75b | 2008-10-11 16:18:53 +0100 | [diff] [blame] | 289 | #else |
| 290 | beqz t7, 1f /* odd buffer alignment? */ |
| 291 | lui v1, 0x00ff |
| 292 | addu v1, 0x00ff |
| 293 | and t0, sum, v1 |
| 294 | sll t0, t0, 8 |
Atsushi Nemoto | 773ff78 | 2006-12-08 01:04:45 +0900 | [diff] [blame] | 295 | srl sum, sum, 8 |
Ralf Baechle | b65a75b | 2008-10-11 16:18:53 +0100 | [diff] [blame] | 296 | and sum, sum, v1 |
| 297 | or sum, sum, t0 |
Atsushi Nemoto | 773ff78 | 2006-12-08 01:04:45 +0900 | [diff] [blame] | 298 | 1: |
Ralf Baechle | b65a75b | 2008-10-11 16:18:53 +0100 | [diff] [blame] | 299 | #endif |
Atsushi Nemoto | 773ff78 | 2006-12-08 01:04:45 +0900 | [diff] [blame] | 300 | .set reorder |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 301 | /* Add the passed partial csum. */ |
Atsushi Nemoto | b80a1b8 | 2008-09-20 17:20:04 +0200 | [diff] [blame] | 302 | ADDC32(sum, a2) |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 303 | jr ra |
Atsushi Nemoto | 773ff78 | 2006-12-08 01:04:45 +0900 | [diff] [blame] | 304 | .set noreorder |
Atsushi Nemoto | 0bcdda0 | 2006-12-04 00:42:59 +0900 | [diff] [blame] | 305 | END(csum_partial) |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 306 | |
| 307 | |
| 308 | /* |
| 309 | * checksum and copy routines based on memcpy.S |
| 310 | * |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 311 | * csum_partial_copy_nocheck(src, dst, len) |
| 312 | * __csum_partial_copy_kernel(src, dst, len) |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 313 | * |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 314 | * See "Spec" in memcpy.S for details. Unlike __copy_user, all |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 315 | * function in this file use the standard calling convention. |
| 316 | */ |
| 317 | |
| 318 | #define src a0 |
| 319 | #define dst a1 |
| 320 | #define len a2 |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 321 | #define sum v0 |
| 322 | #define odd t8 |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 323 | |
| 324 | /* |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 325 | * All exception handlers simply return 0. |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 326 | */ |
| 327 | |
Markos Chandras | 2ab82e6 | 2014-01-16 17:02:13 +0000 | [diff] [blame] | 328 | /* Instruction type */ |
| 329 | #define LD_INSN 1 |
| 330 | #define ST_INSN 2 |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 331 | #define LEGACY_MODE 1 |
| 332 | #define EVA_MODE 2 |
| 333 | #define USEROP 1 |
| 334 | #define KERNELOP 2 |
Markos Chandras | 2ab82e6 | 2014-01-16 17:02:13 +0000 | [diff] [blame] | 335 | |
| 336 | /* |
| 337 | * Wrapper to add an entry in the exception table |
| 338 | * in case the insn causes a memory exception. |
| 339 | * Arguments: |
| 340 | * insn : Load/store instruction |
| 341 | * type : Instruction type |
| 342 | * reg : Register |
| 343 | * addr : Address |
| 344 | * handler : Exception handler |
| 345 | */ |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 346 | #define EXC(insn, type, reg, addr) \ |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 347 | .if \mode == LEGACY_MODE; \ |
| 348 | 9: insn reg, addr; \ |
| 349 | .section __ex_table,"a"; \ |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 350 | PTR 9b, .L_exc; \ |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 351 | .previous; \ |
Markos Chandras | 6f85ceb | 2014-01-17 11:36:16 +0000 | [diff] [blame] | 352 | /* This is enabled in EVA mode */ \ |
| 353 | .else; \ |
| 354 | /* If loading from user or storing to user */ \ |
| 355 | .if ((\from == USEROP) && (type == LD_INSN)) || \ |
| 356 | ((\to == USEROP) && (type == ST_INSN)); \ |
| 357 | 9: __BUILD_EVA_INSN(insn##e, reg, addr); \ |
| 358 | .section __ex_table,"a"; \ |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 359 | PTR 9b, .L_exc; \ |
Markos Chandras | 6f85ceb | 2014-01-17 11:36:16 +0000 | [diff] [blame] | 360 | .previous; \ |
| 361 | .else; \ |
| 362 | /* EVA without exception */ \ |
| 363 | insn reg, addr; \ |
| 364 | .endif; \ |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 365 | .endif |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 366 | |
Markos Chandras | 2ab82e6 | 2014-01-16 17:02:13 +0000 | [diff] [blame] | 367 | #undef LOAD |
| 368 | |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 369 | #ifdef USE_DOUBLE |
| 370 | |
Markos Chandras | 2ab82e6 | 2014-01-16 17:02:13 +0000 | [diff] [blame] | 371 | #define LOADK ld /* No exception */ |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 372 | #define LOAD(reg, addr) EXC(ld, LD_INSN, reg, addr) |
| 373 | #define LOADBU(reg, addr) EXC(lbu, LD_INSN, reg, addr) |
| 374 | #define LOADL(reg, addr) EXC(ldl, LD_INSN, reg, addr) |
| 375 | #define LOADR(reg, addr) EXC(ldr, LD_INSN, reg, addr) |
| 376 | #define STOREB(reg, addr) EXC(sb, ST_INSN, reg, addr) |
| 377 | #define STOREL(reg, addr) EXC(sdl, ST_INSN, reg, addr) |
| 378 | #define STORER(reg, addr) EXC(sdr, ST_INSN, reg, addr) |
| 379 | #define STORE(reg, addr) EXC(sd, ST_INSN, reg, addr) |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 380 | #define ADD daddu |
| 381 | #define SUB dsubu |
| 382 | #define SRL dsrl |
| 383 | #define SLL dsll |
| 384 | #define SLLV dsllv |
| 385 | #define SRLV dsrlv |
| 386 | #define NBYTES 8 |
| 387 | #define LOG_NBYTES 3 |
| 388 | |
| 389 | #else |
| 390 | |
Markos Chandras | 2ab82e6 | 2014-01-16 17:02:13 +0000 | [diff] [blame] | 391 | #define LOADK lw /* No exception */ |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 392 | #define LOAD(reg, addr) EXC(lw, LD_INSN, reg, addr) |
| 393 | #define LOADBU(reg, addr) EXC(lbu, LD_INSN, reg, addr) |
| 394 | #define LOADL(reg, addr) EXC(lwl, LD_INSN, reg, addr) |
| 395 | #define LOADR(reg, addr) EXC(lwr, LD_INSN, reg, addr) |
| 396 | #define STOREB(reg, addr) EXC(sb, ST_INSN, reg, addr) |
| 397 | #define STOREL(reg, addr) EXC(swl, ST_INSN, reg, addr) |
| 398 | #define STORER(reg, addr) EXC(swr, ST_INSN, reg, addr) |
| 399 | #define STORE(reg, addr) EXC(sw, ST_INSN, reg, addr) |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 400 | #define ADD addu |
| 401 | #define SUB subu |
| 402 | #define SRL srl |
| 403 | #define SLL sll |
| 404 | #define SLLV sllv |
| 405 | #define SRLV srlv |
| 406 | #define NBYTES 4 |
| 407 | #define LOG_NBYTES 2 |
| 408 | |
| 409 | #endif /* USE_DOUBLE */ |
| 410 | |
| 411 | #ifdef CONFIG_CPU_LITTLE_ENDIAN |
| 412 | #define LDFIRST LOADR |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 413 | #define LDREST LOADL |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 414 | #define STFIRST STORER |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 415 | #define STREST STOREL |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 416 | #define SHIFT_DISCARD SLLV |
| 417 | #define SHIFT_DISCARD_REVERT SRLV |
| 418 | #else |
| 419 | #define LDFIRST LOADL |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 420 | #define LDREST LOADR |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 421 | #define STFIRST STOREL |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 422 | #define STREST STORER |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 423 | #define SHIFT_DISCARD SRLV |
| 424 | #define SHIFT_DISCARD_REVERT SLLV |
| 425 | #endif |
| 426 | |
| 427 | #define FIRST(unit) ((unit)*NBYTES) |
| 428 | #define REST(unit) (FIRST(unit)+NBYTES-1) |
| 429 | |
| 430 | #define ADDRMASK (NBYTES-1) |
| 431 | |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 432 | #ifndef CONFIG_CPU_DADDI_WORKAROUNDS |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 433 | .set noat |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 434 | #else |
| 435 | .set at=v1 |
| 436 | #endif |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 437 | |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 438 | .macro __BUILD_CSUM_PARTIAL_COPY_USER mode, from, to |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 439 | |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 440 | li sum, -1 |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 441 | move odd, zero |
| 442 | /* |
| 443 | * Note: dst & src may be unaligned, len may be 0 |
| 444 | * Temps |
| 445 | */ |
| 446 | /* |
| 447 | * The "issue break"s below are very approximate. |
| 448 | * Issue delays for dcache fills will perturb the schedule, as will |
| 449 | * load queue full replay traps, etc. |
| 450 | * |
| 451 | * If len < NBYTES use byte operations. |
| 452 | */ |
| 453 | sltu t2, len, NBYTES |
| 454 | and t1, dst, ADDRMASK |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 455 | bnez t2, .Lcopy_bytes_checklen\@ |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 456 | and t0, src, ADDRMASK |
| 457 | andi odd, dst, 0x1 /* odd buffer? */ |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 458 | bnez t1, .Ldst_unaligned\@ |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 459 | nop |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 460 | bnez t0, .Lsrc_unaligned_dst_aligned\@ |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 461 | /* |
| 462 | * use delay slot for fall-through |
| 463 | * src and dst are aligned; need to compute rem |
| 464 | */ |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 465 | .Lboth_aligned\@: |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 466 | SRL t0, len, LOG_NBYTES+3 # +3 for 8 units/iter |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 467 | beqz t0, .Lcleanup_both_aligned\@ # len < 8*NBYTES |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 468 | nop |
| 469 | SUB len, 8*NBYTES # subtract here for bgez loop |
| 470 | .align 4 |
| 471 | 1: |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 472 | LOAD(t0, UNIT(0)(src)) |
| 473 | LOAD(t1, UNIT(1)(src)) |
| 474 | LOAD(t2, UNIT(2)(src)) |
| 475 | LOAD(t3, UNIT(3)(src)) |
| 476 | LOAD(t4, UNIT(4)(src)) |
| 477 | LOAD(t5, UNIT(5)(src)) |
| 478 | LOAD(t6, UNIT(6)(src)) |
| 479 | LOAD(t7, UNIT(7)(src)) |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 480 | SUB len, len, 8*NBYTES |
| 481 | ADD src, src, 8*NBYTES |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 482 | STORE(t0, UNIT(0)(dst)) |
Chen Jie | 615eb60 | 2015-03-27 01:07:24 +0800 | [diff] [blame] | 483 | ADDC(t0, t1) |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 484 | STORE(t1, UNIT(1)(dst)) |
Chen Jie | 615eb60 | 2015-03-27 01:07:24 +0800 | [diff] [blame] | 485 | ADDC(sum, t0) |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 486 | STORE(t2, UNIT(2)(dst)) |
Chen Jie | 615eb60 | 2015-03-27 01:07:24 +0800 | [diff] [blame] | 487 | ADDC(t2, t3) |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 488 | STORE(t3, UNIT(3)(dst)) |
Chen Jie | 615eb60 | 2015-03-27 01:07:24 +0800 | [diff] [blame] | 489 | ADDC(sum, t2) |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 490 | STORE(t4, UNIT(4)(dst)) |
Chen Jie | 615eb60 | 2015-03-27 01:07:24 +0800 | [diff] [blame] | 491 | ADDC(t4, t5) |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 492 | STORE(t5, UNIT(5)(dst)) |
Chen Jie | 615eb60 | 2015-03-27 01:07:24 +0800 | [diff] [blame] | 493 | ADDC(sum, t4) |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 494 | STORE(t6, UNIT(6)(dst)) |
Chen Jie | 615eb60 | 2015-03-27 01:07:24 +0800 | [diff] [blame] | 495 | ADDC(t6, t7) |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 496 | STORE(t7, UNIT(7)(dst)) |
Chen Jie | 615eb60 | 2015-03-27 01:07:24 +0800 | [diff] [blame] | 497 | ADDC(sum, t6) |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 498 | .set reorder /* DADDI_WAR */ |
| 499 | ADD dst, dst, 8*NBYTES |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 500 | bgez len, 1b |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 501 | .set noreorder |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 502 | ADD len, 8*NBYTES # revert len (see above) |
| 503 | |
| 504 | /* |
| 505 | * len == the number of bytes left to copy < 8*NBYTES |
| 506 | */ |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 507 | .Lcleanup_both_aligned\@: |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 508 | #define rem t7 |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 509 | beqz len, .Ldone\@ |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 510 | sltu t0, len, 4*NBYTES |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 511 | bnez t0, .Lless_than_4units\@ |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 512 | and rem, len, (NBYTES-1) # rem = len % NBYTES |
| 513 | /* |
| 514 | * len >= 4*NBYTES |
| 515 | */ |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 516 | LOAD(t0, UNIT(0)(src)) |
| 517 | LOAD(t1, UNIT(1)(src)) |
| 518 | LOAD(t2, UNIT(2)(src)) |
| 519 | LOAD(t3, UNIT(3)(src)) |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 520 | SUB len, len, 4*NBYTES |
| 521 | ADD src, src, 4*NBYTES |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 522 | STORE(t0, UNIT(0)(dst)) |
Chen Jie | 615eb60 | 2015-03-27 01:07:24 +0800 | [diff] [blame] | 523 | ADDC(t0, t1) |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 524 | STORE(t1, UNIT(1)(dst)) |
Chen Jie | 615eb60 | 2015-03-27 01:07:24 +0800 | [diff] [blame] | 525 | ADDC(sum, t0) |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 526 | STORE(t2, UNIT(2)(dst)) |
Chen Jie | 615eb60 | 2015-03-27 01:07:24 +0800 | [diff] [blame] | 527 | ADDC(t2, t3) |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 528 | STORE(t3, UNIT(3)(dst)) |
Chen Jie | 615eb60 | 2015-03-27 01:07:24 +0800 | [diff] [blame] | 529 | ADDC(sum, t2) |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 530 | .set reorder /* DADDI_WAR */ |
| 531 | ADD dst, dst, 4*NBYTES |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 532 | beqz len, .Ldone\@ |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 533 | .set noreorder |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 534 | .Lless_than_4units\@: |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 535 | /* |
| 536 | * rem = len % NBYTES |
| 537 | */ |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 538 | beq rem, len, .Lcopy_bytes\@ |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 539 | nop |
| 540 | 1: |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 541 | LOAD(t0, 0(src)) |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 542 | ADD src, src, NBYTES |
| 543 | SUB len, len, NBYTES |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 544 | STORE(t0, 0(dst)) |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 545 | ADDC(sum, t0) |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 546 | .set reorder /* DADDI_WAR */ |
| 547 | ADD dst, dst, NBYTES |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 548 | bne rem, len, 1b |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 549 | .set noreorder |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 550 | |
| 551 | /* |
| 552 | * src and dst are aligned, need to copy rem bytes (rem < NBYTES) |
| 553 | * A loop would do only a byte at a time with possible branch |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 554 | * mispredicts. Can't do an explicit LOAD dst,mask,or,STORE |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 555 | * because can't assume read-access to dst. Instead, use |
| 556 | * STREST dst, which doesn't require read access to dst. |
| 557 | * |
| 558 | * This code should perform better than a simple loop on modern, |
| 559 | * wide-issue mips processors because the code has fewer branches and |
| 560 | * more instruction-level parallelism. |
| 561 | */ |
| 562 | #define bits t2 |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 563 | beqz len, .Ldone\@ |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 564 | ADD t1, dst, len # t1 is just past last byte of dst |
| 565 | li bits, 8*NBYTES |
| 566 | SLL rem, len, 3 # rem = number of bits to keep |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 567 | LOAD(t0, 0(src)) |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 568 | SUB bits, bits, rem # bits = number of bits to discard |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 569 | SHIFT_DISCARD t0, t0, bits |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 570 | STREST(t0, -1(t1)) |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 571 | SHIFT_DISCARD_REVERT t0, t0, bits |
| 572 | .set reorder |
| 573 | ADDC(sum, t0) |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 574 | b .Ldone\@ |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 575 | .set noreorder |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 576 | .Ldst_unaligned\@: |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 577 | /* |
| 578 | * dst is unaligned |
| 579 | * t0 = src & ADDRMASK |
| 580 | * t1 = dst & ADDRMASK; T1 > 0 |
| 581 | * len >= NBYTES |
| 582 | * |
| 583 | * Copy enough bytes to align dst |
| 584 | * Set match = (src and dst have same alignment) |
| 585 | */ |
| 586 | #define match rem |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 587 | LDFIRST(t3, FIRST(0)(src)) |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 588 | ADD t2, zero, NBYTES |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 589 | LDREST(t3, REST(0)(src)) |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 590 | SUB t2, t2, t1 # t2 = number of bytes copied |
| 591 | xor match, t0, t1 |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 592 | STFIRST(t3, FIRST(0)(dst)) |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 593 | SLL t4, t1, 3 # t4 = number of bits to discard |
| 594 | SHIFT_DISCARD t3, t3, t4 |
| 595 | /* no SHIFT_DISCARD_REVERT to handle odd buffer properly */ |
| 596 | ADDC(sum, t3) |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 597 | beq len, t2, .Ldone\@ |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 598 | SUB len, len, t2 |
| 599 | ADD dst, dst, t2 |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 600 | beqz match, .Lboth_aligned\@ |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 601 | ADD src, src, t2 |
| 602 | |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 603 | .Lsrc_unaligned_dst_aligned\@: |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 604 | SRL t0, len, LOG_NBYTES+2 # +2 for 4 units/iter |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 605 | beqz t0, .Lcleanup_src_unaligned\@ |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 606 | and rem, len, (4*NBYTES-1) # rem = len % 4*NBYTES |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 607 | 1: |
| 608 | /* |
| 609 | * Avoid consecutive LD*'s to the same register since some mips |
| 610 | * implementations can't issue them in the same cycle. |
| 611 | * It's OK to load FIRST(N+1) before REST(N) because the two addresses |
| 612 | * are to the same unit (unless src is aligned, but it's not). |
| 613 | */ |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 614 | LDFIRST(t0, FIRST(0)(src)) |
| 615 | LDFIRST(t1, FIRST(1)(src)) |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 616 | SUB len, len, 4*NBYTES |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 617 | LDREST(t0, REST(0)(src)) |
| 618 | LDREST(t1, REST(1)(src)) |
| 619 | LDFIRST(t2, FIRST(2)(src)) |
| 620 | LDFIRST(t3, FIRST(3)(src)) |
| 621 | LDREST(t2, REST(2)(src)) |
| 622 | LDREST(t3, REST(3)(src)) |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 623 | ADD src, src, 4*NBYTES |
| 624 | #ifdef CONFIG_CPU_SB1 |
| 625 | nop # improves slotting |
| 626 | #endif |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 627 | STORE(t0, UNIT(0)(dst)) |
Chen Jie | 615eb60 | 2015-03-27 01:07:24 +0800 | [diff] [blame] | 628 | ADDC(t0, t1) |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 629 | STORE(t1, UNIT(1)(dst)) |
Chen Jie | 615eb60 | 2015-03-27 01:07:24 +0800 | [diff] [blame] | 630 | ADDC(sum, t0) |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 631 | STORE(t2, UNIT(2)(dst)) |
Chen Jie | 615eb60 | 2015-03-27 01:07:24 +0800 | [diff] [blame] | 632 | ADDC(t2, t3) |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 633 | STORE(t3, UNIT(3)(dst)) |
Chen Jie | 615eb60 | 2015-03-27 01:07:24 +0800 | [diff] [blame] | 634 | ADDC(sum, t2) |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 635 | .set reorder /* DADDI_WAR */ |
| 636 | ADD dst, dst, 4*NBYTES |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 637 | bne len, rem, 1b |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 638 | .set noreorder |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 639 | |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 640 | .Lcleanup_src_unaligned\@: |
| 641 | beqz len, .Ldone\@ |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 642 | and rem, len, NBYTES-1 # rem = len % NBYTES |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 643 | beq rem, len, .Lcopy_bytes\@ |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 644 | nop |
| 645 | 1: |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 646 | LDFIRST(t0, FIRST(0)(src)) |
| 647 | LDREST(t0, REST(0)(src)) |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 648 | ADD src, src, NBYTES |
| 649 | SUB len, len, NBYTES |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 650 | STORE(t0, 0(dst)) |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 651 | ADDC(sum, t0) |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 652 | .set reorder /* DADDI_WAR */ |
| 653 | ADD dst, dst, NBYTES |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 654 | bne len, rem, 1b |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 655 | .set noreorder |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 656 | |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 657 | .Lcopy_bytes_checklen\@: |
| 658 | beqz len, .Ldone\@ |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 659 | nop |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 660 | .Lcopy_bytes\@: |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 661 | /* 0 < len < NBYTES */ |
| 662 | #ifdef CONFIG_CPU_LITTLE_ENDIAN |
| 663 | #define SHIFT_START 0 |
| 664 | #define SHIFT_INC 8 |
| 665 | #else |
| 666 | #define SHIFT_START 8*(NBYTES-1) |
| 667 | #define SHIFT_INC -8 |
| 668 | #endif |
| 669 | move t2, zero # partial word |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 670 | li t3, SHIFT_START # shift |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 671 | #define COPY_BYTE(N) \ |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 672 | LOADBU(t0, N(src)); \ |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 673 | SUB len, len, 1; \ |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 674 | STOREB(t0, N(dst)); \ |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 675 | SLLV t0, t0, t3; \ |
| 676 | addu t3, SHIFT_INC; \ |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 677 | beqz len, .Lcopy_bytes_done\@; \ |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 678 | or t2, t0 |
| 679 | |
| 680 | COPY_BYTE(0) |
| 681 | COPY_BYTE(1) |
| 682 | #ifdef USE_DOUBLE |
| 683 | COPY_BYTE(2) |
| 684 | COPY_BYTE(3) |
| 685 | COPY_BYTE(4) |
| 686 | COPY_BYTE(5) |
| 687 | #endif |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 688 | LOADBU(t0, NBYTES-2(src)) |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 689 | SUB len, len, 1 |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 690 | STOREB(t0, NBYTES-2(dst)) |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 691 | SLLV t0, t0, t3 |
| 692 | or t2, t0 |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 693 | .Lcopy_bytes_done\@: |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 694 | ADDC(sum, t2) |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 695 | .Ldone\@: |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 696 | /* fold checksum */ |
Maciej W. Rozycki | 44ba138 | 2014-04-04 03:32:54 +0100 | [diff] [blame] | 697 | .set push |
| 698 | .set noat |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 699 | #ifdef USE_DOUBLE |
| 700 | dsll32 v1, sum, 0 |
| 701 | daddu sum, v1 |
| 702 | sltu v1, sum, v1 |
| 703 | dsra32 sum, sum, 0 |
| 704 | addu sum, v1 |
| 705 | #endif |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 706 | |
Serge Semin | ab7c01f | 2020-05-21 17:07:14 +0300 | [diff] [blame] | 707 | #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR5) || \ |
| 708 | defined(CONFIG_CPU_LOONGSON64) |
Chen Jie | 3c09bae | 2014-08-15 16:56:58 +0800 | [diff] [blame] | 709 | .set push |
| 710 | .set arch=mips32r2 |
Ralf Baechle | b65a75b | 2008-10-11 16:18:53 +0100 | [diff] [blame] | 711 | wsbh v1, sum |
| 712 | movn sum, v1, odd |
Chen Jie | 3c09bae | 2014-08-15 16:56:58 +0800 | [diff] [blame] | 713 | .set pop |
Ralf Baechle | b65a75b | 2008-10-11 16:18:53 +0100 | [diff] [blame] | 714 | #else |
| 715 | beqz odd, 1f /* odd buffer alignment? */ |
| 716 | lui v1, 0x00ff |
| 717 | addu v1, 0x00ff |
| 718 | and t0, sum, v1 |
| 719 | sll t0, t0, 8 |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 720 | srl sum, sum, 8 |
Ralf Baechle | b65a75b | 2008-10-11 16:18:53 +0100 | [diff] [blame] | 721 | and sum, sum, v1 |
| 722 | or sum, sum, t0 |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 723 | 1: |
Ralf Baechle | b65a75b | 2008-10-11 16:18:53 +0100 | [diff] [blame] | 724 | #endif |
Maciej W. Rozycki | 44ba138 | 2014-04-04 03:32:54 +0100 | [diff] [blame] | 725 | .set pop |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 726 | .set reorder |
Atsushi Nemoto | f860c90 | 2006-12-13 01:22:06 +0900 | [diff] [blame] | 727 | jr ra |
| 728 | .set noreorder |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 729 | .endm |
| 730 | |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 731 | .set noreorder |
| 732 | .L_exc: |
| 733 | jr ra |
| 734 | li v0, 0 |
| 735 | |
| 736 | FEXPORT(__csum_partial_copy_nocheck) |
| 737 | EXPORT_SYMBOL(__csum_partial_copy_nocheck) |
Markos Chandras | 6f85ceb | 2014-01-17 11:36:16 +0000 | [diff] [blame] | 738 | #ifndef CONFIG_EVA |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 739 | FEXPORT(__csum_partial_copy_to_user) |
Paul Burton | 2313004 | 2016-11-07 11:14:13 +0000 | [diff] [blame] | 740 | EXPORT_SYMBOL(__csum_partial_copy_to_user) |
Markos Chandras | e89fb56 | 2014-01-17 10:48:46 +0000 | [diff] [blame] | 741 | FEXPORT(__csum_partial_copy_from_user) |
Paul Burton | 2313004 | 2016-11-07 11:14:13 +0000 | [diff] [blame] | 742 | EXPORT_SYMBOL(__csum_partial_copy_from_user) |
Markos Chandras | 6f85ceb | 2014-01-17 11:36:16 +0000 | [diff] [blame] | 743 | #endif |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 744 | __BUILD_CSUM_PARTIAL_COPY_USER LEGACY_MODE USEROP USEROP |
Markos Chandras | 6f85ceb | 2014-01-17 11:36:16 +0000 | [diff] [blame] | 745 | |
| 746 | #ifdef CONFIG_EVA |
| 747 | LEAF(__csum_partial_copy_to_user) |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 748 | __BUILD_CSUM_PARTIAL_COPY_USER EVA_MODE KERNELOP USEROP |
Markos Chandras | 6f85ceb | 2014-01-17 11:36:16 +0000 | [diff] [blame] | 749 | END(__csum_partial_copy_to_user) |
| 750 | |
| 751 | LEAF(__csum_partial_copy_from_user) |
Al Viro | 1cd95ab | 2020-07-19 17:37:15 -0400 | [diff] [blame] | 752 | __BUILD_CSUM_PARTIAL_COPY_USER EVA_MODE USEROP KERNELOP |
Markos Chandras | 6f85ceb | 2014-01-17 11:36:16 +0000 | [diff] [blame] | 753 | END(__csum_partial_copy_from_user) |
| 754 | #endif |