Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2005-2009 Brocade Communications Systems, Inc. |
| 3 | * All rights reserved |
| 4 | * www.brocade.com |
| 5 | * |
| 6 | * Linux driver for Brocade Fibre Channel Host Bus Adapter. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License (GPL) Version 2 as |
| 10 | * published by the Free Software Foundation |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * bfa_checksum.h BFA checksum utilities |
| 20 | */ |
| 21 | |
| 22 | #ifndef __BFA_CHECKSUM_H__ |
| 23 | #define __BFA_CHECKSUM_H__ |
| 24 | |
| 25 | static inline u32 |
| 26 | bfa_checksum_u32(u32 *buf, int sz) |
| 27 | { |
| 28 | int i, m = sz >> 2; |
| 29 | u32 sum = 0; |
| 30 | |
| 31 | for (i = 0; i < m; i++) |
| 32 | sum ^= buf[i]; |
| 33 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 34 | return sum; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | static inline u16 |
| 38 | bfa_checksum_u16(u16 *buf, int sz) |
| 39 | { |
| 40 | int i, m = sz >> 1; |
| 41 | u16 sum = 0; |
| 42 | |
| 43 | for (i = 0; i < m; i++) |
| 44 | sum ^= buf[i]; |
| 45 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 46 | return sum; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | static inline u8 |
| 50 | bfa_checksum_u8(u8 *buf, int sz) |
| 51 | { |
| 52 | int i; |
| 53 | u8 sum = 0; |
| 54 | |
| 55 | for (i = 0; i < sz; i++) |
| 56 | sum ^= buf[i]; |
| 57 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 58 | return sum; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 59 | } |
| 60 | #endif |