From patchwork Thu Jun 18 14:26:14 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 28870 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id 8A0D9B72B7 for ; Fri, 19 Jun 2009 00:26:53 +1000 (EST) Received: by ozlabs.org (Postfix) id 76E3ADDDA2; Fri, 19 Jun 2009 00:26:53 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id EB7EADDD04 for ; Fri, 19 Jun 2009 00:26:52 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761642AbZFRO0r (ORCPT ); Thu, 18 Jun 2009 10:26:47 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1761572AbZFRO0q (ORCPT ); Thu, 18 Jun 2009 10:26:46 -0400 Received: from mail-ew0-f210.google.com ([209.85.219.210]:58265 "EHLO mail-ew0-f210.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754835AbZFRO0h (ORCPT ); Thu, 18 Jun 2009 10:26:37 -0400 Received: by mail-ew0-f210.google.com with SMTP id 6so1590231ewy.37 for ; Thu, 18 Jun 2009 07:26:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references; bh=zyxeAObmyMT1ZhD1O3Cu1vrbnW58vRFw3FIOqx1R23o=; b=o9cpKhIG1VpA5fF/6x8L1cT9ws6a/SGymhgorpCkBqtjT5bzN60L3LQBLr9Uv826O/ oysJYoEcJN8xM5rw/dcB09/MmdrRL/QkZn3BBH85A7LKK+Qs3SZH22pyEcfSzV2TrLGP 6z5v1+UnquPW6H702b579OKQknKMO5XdpE1BM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=JXT39LCvZd57i8WLlJF/rMytGSd8ckQGyvFsVLHpUxqwJvdqYOR3AxJgoGUENizyyP 0yOWwmeHjd5BH9y+sBf0VXGnBjAExDYDMH7VWRNGWpNsUxF3zUSzsRvg12nkv5PuMxbm 0gvpN/g2MKqPkDMUmCTW+b6f3vkdfpSTELoHA= Received: by 10.216.39.194 with SMTP id d44mr441898web.116.1245335200090; Thu, 18 Jun 2009 07:26:40 -0700 (PDT) Received: from localhost.localdomain (iap-pxy-mow1.siemens.ru [212.248.25.26]) by mx.google.com with ESMTPS id i34sm4844309gve.13.2009.06.18.07.26.38 (version=SSLv3 cipher=RC4-MD5); Thu, 18 Jun 2009 07:26:39 -0700 (PDT) From: Dmitry Eremin-Solenikov To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Sergey Lapin , Darren Salt Subject: [PATCH 2/5] crc-itu-t: add bit-reversed calculation Date: Thu, 18 Jun 2009 18:26:14 +0400 Message-Id: <1245335177-16810-3-git-send-email-dbaryshkov@gmail.com> X-Mailer: git-send-email 1.6.3.1 In-Reply-To: <1245335177-16810-2-git-send-email-dbaryshkov@gmail.com> References: <1245335177-16810-1-git-send-email-dbaryshkov@gmail.com> <1245335177-16810-2-git-send-email-dbaryshkov@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Darren Salt Changes since original patch by Darren: * add 'select BITREVERSE' * fix kerneldoc Signed-off-by: Darren Salt Signed-off-by: Dmitry Eremin-Solenikov --- include/linux/crc-itu-t.h | 10 ++++++++++ lib/Kconfig | 1 + lib/crc-itu-t.c | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 0 deletions(-) diff --git a/include/linux/crc-itu-t.h b/include/linux/crc-itu-t.h index 84920f3..7b2b7ba 100644 --- a/include/linux/crc-itu-t.h +++ b/include/linux/crc-itu-t.h @@ -6,6 +6,9 @@ * Poly 0x0x1021 (x^16 + x^12 + x^15 + 1) * Init 0 * + * The bit-reversed buffer variants may be non-standard, but some firmware + * loaders require them. + * * This source code is licensed under the GNU General Public License, * Version 2. See the file COPYING for more details. */ @@ -14,15 +17,22 @@ #define CRC_ITU_T_H #include +#include extern u16 const crc_itu_t_table[256]; extern u16 crc_itu_t(u16 crc, const u8 *buffer, size_t len); +extern u16 crc_itu_t_bitreversed(u16 crc, const u8 *buffer, size_t len); static inline u16 crc_itu_t_byte(u16 crc, const u8 data) { return (crc << 8) ^ crc_itu_t_table[((crc >> 8) ^ data) & 0xff]; } +static inline u16 crc_itu_t_bitreversed_byte(u16 crc, const u8 data) +{ + return (crc << 8) ^ crc_itu_t_table[((crc >> 8) ^ bitrev8(data)) & 0xff]; +} + #endif /* CRC_ITU_T_H */ diff --git a/lib/Kconfig b/lib/Kconfig index 8ade0a7..0ec01c3 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -45,6 +45,7 @@ config CRC_T10DIF config CRC_ITU_T tristate "CRC ITU-T V.41 functions" + select BITREVERSE help This option is provided for the case where no in-kernel-tree modules require CRC ITU-T V.41 functions, but a module built outside diff --git a/lib/crc-itu-t.c b/lib/crc-itu-t.c index a63472b..a1422d8 100644 --- a/lib/crc-itu-t.c +++ b/lib/crc-itu-t.c @@ -64,6 +64,23 @@ u16 crc_itu_t(u16 crc, const u8 *buffer, size_t len) } EXPORT_SYMBOL(crc_itu_t); +/** + * crc_itu_t_bitreversed - Compute the CRC-ITU-T for the bit-reversed data buffer; + * + * @crc: previous CRC value + * @buffer: data pointer + * @len: number of bytes in the buffer + * + * Returns the updated CRC value + */ +u16 crc_itu_t_bitreversed(u16 crc, const u8 *buffer, size_t len) +{ + while (len--) + crc = crc_itu_t_bitreversed_byte(crc, *buffer++); + return crc; +} +EXPORT_SYMBOL(crc_itu_t_bitreversed); + MODULE_DESCRIPTION("CRC ITU-T V.41 calculations"); MODULE_LICENSE("GPL");