linux-stable/drivers/net/wireless/broadcom/brcm80211/brcmfmac/xtlv.c
Andy Shevchenko 22c033989c include/linux/unaligned: replace kernel.h with the necessary inclusions
When kernel.h is used in the headers it adds a lot into dependency hell,
especially when there are circular dependencies are involved.

Replace kernel.h inclusion with the list of what is really being used.

The rest of the changes are induced by the above and may not be split.

Link: https://lkml.kernel.org/r/20211209123823.20425-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Arend van Spriel <arend.vanspriel@broadcom.com>	[brcmfmac]
Acked-by: Kalle Valo <kvalo@kernel.org>
Cc: Arend van Spriel <aspriel@gmail.com>
Cc: Franky Lin <franky.lin@broadcom.com>
Cc: Hante Meuleman <hante.meuleman@broadcom.com>
Cc: Chi-hsien Lin <chi-hsien.lin@infineon.com>
Cc: Wright Feng <wright.feng@infineon.com>
Cc: Chung-hsien Hsu <chung-hsien.hsu@infineon.com>
Cc: Kalle Valo <kvalo@codeaurora.org>
Cc: David S. Miller <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-01-20 08:52:53 +02:00

84 lines
1.7 KiB
C

// SPDX-License-Identifier: ISC
/*
* Copyright (c) 2019 Broadcom
*/
#include <asm/unaligned.h>
#include <linux/math.h>
#include <linux/string.h>
#include <linux/bug.h>
#include "xtlv.h"
static int brcmf_xtlv_header_size(u16 opts)
{
int len = (int)offsetof(struct brcmf_xtlv, data);
if (opts & BRCMF_XTLV_OPTION_IDU8)
--len;
if (opts & BRCMF_XTLV_OPTION_LENU8)
--len;
return len;
}
int brcmf_xtlv_data_size(int dlen, u16 opts)
{
int hsz;
hsz = brcmf_xtlv_header_size(opts);
if (opts & BRCMF_XTLV_OPTION_ALIGN32)
return roundup(dlen + hsz, 4);
return dlen + hsz;
}
void brcmf_xtlv_pack_header(struct brcmf_xtlv *xtlv, u16 id, u16 len,
const u8 *data, u16 opts)
{
u8 *data_buf;
u16 mask = BRCMF_XTLV_OPTION_IDU8 | BRCMF_XTLV_OPTION_LENU8;
if (!(opts & mask)) {
u8 *idp = (u8 *)xtlv;
u8 *lenp = idp + sizeof(xtlv->id);
put_unaligned_le16(id, idp);
put_unaligned_le16(len, lenp);
data_buf = lenp + sizeof(u16);
} else if ((opts & mask) == mask) { /* u8 id and u8 len */
u8 *idp = (u8 *)xtlv;
u8 *lenp = idp + 1;
*idp = (u8)id;
*lenp = (u8)len;
data_buf = lenp + sizeof(u8);
} else if (opts & BRCMF_XTLV_OPTION_IDU8) { /* u8 id, u16 len */
u8 *idp = (u8 *)xtlv;
u8 *lenp = idp + 1;
*idp = (u8)id;
put_unaligned_le16(len, lenp);
data_buf = lenp + sizeof(u16);
} else if (opts & BRCMF_XTLV_OPTION_LENU8) { /* u16 id, u8 len */
u8 *idp = (u8 *)xtlv;
u8 *lenp = idp + sizeof(u16);
put_unaligned_le16(id, idp);
*lenp = (u8)len;
data_buf = lenp + sizeof(u8);
} else {
WARN(true, "Unexpected xtlv option");
return;
}
if (opts & BRCMF_XTLV_OPTION_LENU8) {
WARN_ON(len > 0x00ff);
len &= 0xff;
}
if (data)
memcpy(data_buf, data, len);
}