From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mms1.broadcom.com ([216.31.210.17]:4409 "EHLO mms1.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753658Ab1FOT0w convert rfc822-to-8bit (ORCPT ); Wed, 15 Jun 2011 15:26:52 -0400 Message-ID: <4DF9076F.3090304@broadcom.com> (sfid-20110615_212655_657627_F5EC89BF) Date: Wed, 15 Jun 2011 21:26:39 +0200 From: "Arend van Spriel" MIME-Version: 1.0 To: =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= cc: "linux-wireless@vger.kernel.org" , "John W. Linville" , "b43-dev@lists.infradead.org" Subject: Re: [RFC][WORTH IT?][PATCH] bcma: make use of crc8 lib References: <1308138814-12235-1-git-send-email-zajec5@gmail.com> <4DF8A0EF.5030702@broadcom.com> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Sender: linux-wireless-owner@vger.kernel.org List-ID: On 06/15/2011 08:29 PM, Rafał Miłecki wrote: > W dniu 15 czerwca 2011 14:09 użytkownik Arend van Spriel > napisał: >> On 06/15/2011 01:53 PM, Rafał Miłecki wrote: >>> static u8 bcma_sprom_crc(const u16 *sprom) >>> { >>> - int word; >>> - u8 crc = 0xFF; >>> + u8 crc; >>> + u8 sprom2[SSB_SPROMSIZE_WORDS_R4 * 2 - 1]; >>> + u8 table[CRC8_TABLE_SIZE]; >>> + u16 word; >>> >>> + /* u16 to u8 */ >>> for (word = 0; word< SSB_SPROMSIZE_WORDS_R4 - 1; word++) { >>> - crc = bcma_crc8(crc, sprom[word]& 0x00FF); >>> - crc = bcma_crc8(crc, (sprom[word]& 0xFF00)>> 8); >>> + sprom2[word * 2] = sprom[word]& 0x00FF; >>> + sprom2[(word * 2) + 1] = (sprom[word]& 0xFF00)>> 8; >>> } >>> - crc = bcma_crc8(crc, sprom[SSB_SPROMSIZE_WORDS_R4 - 1]& 0x00FF); >>> + /* 127th byte */ >>> + sprom2[(SSB_SPROMSIZE_WORDS_R4 * 2) - 2] = >>> + sprom[SSB_SPROMSIZE_WORDS_R4 - 1]& >>> 0x00FF; >>> + >>> + /* Prepare table, 0xAB is x^8 + x^7 + x^6 + x^4 + x^2 + 1 */ >>> + crc8_populate_lsb(table, 0xAB); >>> + >>> + /* Calculate */ >>> + crc = crc8(table, sprom2, (SSB_SPROMSIZE_WORDS_R4 * 2) - 1, 0xFF); >>> crc ^= 0xFF; >>> >>> return crc; >> You could do (I think): >> >> crc8_populate_lsb(table, 0xAB); >> for (word = 0; word< SSB_SPROMSIZE_WORDS_R4; word++) { >> u16 val = cpu_to_le16(sprom[word]); >> crc = crc8(table,&val, sizeof(u16), crc); >> } > Maybe not a perfect/optimal solution (crc8 focuses on tables, we do > double loop instead) but should work. Thanks for the tip. Agree. In brcm80211 we convert the entire sprom, calculate, and convert it back. Also not perfect I think as it loops over de sprom data twice. Gr. AvS -- Almost nobody dances sober, unless they happen to be insane. -- H.P. Lovecraft --