/drivers/scsi/bfa/include/cs/bfa_checksum.h

https://bitbucket.org/abioy/linux · C Header · 60 lines · 30 code · 11 blank · 19 comment · 3 complexity · fb269961530ee71a6c5554801d5cdfe5 MD5 · raw file

  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. * bfa_checksum.h BFA checksum utilities
  19. */
  20. #ifndef __BFA_CHECKSUM_H__
  21. #define __BFA_CHECKSUM_H__
  22. static inline u32
  23. bfa_checksum_u32(u32 *buf, int sz)
  24. {
  25. int i, m = sz >> 2;
  26. u32 sum = 0;
  27. for (i = 0; i < m; i++)
  28. sum ^= buf[i];
  29. return sum;
  30. }
  31. static inline u16
  32. bfa_checksum_u16(u16 *buf, int sz)
  33. {
  34. int i, m = sz >> 1;
  35. u16 sum = 0;
  36. for (i = 0; i < m; i++)
  37. sum ^= buf[i];
  38. return sum;
  39. }
  40. static inline u8
  41. bfa_checksum_u8(u8 *buf, int sz)
  42. {
  43. int i;
  44. u8 sum = 0;
  45. for (i = 0; i < sz; i++)
  46. sum ^= buf[i];
  47. return sum;
  48. }
  49. #endif