mirror of
https://github.com/torvalds/linux.git
synced 2024-11-22 20:22:09 +00:00
a61127c213
Based on 1 normalized pattern(s): this program is free software you can redistribute it and or modify it under the terms and conditions of the gnu general public license version 2 as published by the free software foundation this program is distributed in the hope it will be useful but without any warranty without even the implied warranty of merchantability or fitness for a particular purpose see the gnu general public license for more details you should have received a copy of the gnu general public license along with this program if not write to the free software foundation inc 51 franklin st fifth floor boston ma 02110 1301 usa extracted by the scancode license scanner the SPDX license identifier GPL-2.0-only has been chosen to replace the boilerplate/reference in 111 file(s). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Alexios Zavras <alexios.zavras@intel.com> Reviewed-by: Allison Randal <allison@lohutok.net> Cc: linux-spdx@vger.kernel.org Link: https://lkml.kernel.org/r/20190530000436.567572064@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
80 lines
1.8 KiB
C
80 lines
1.8 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright(c) 2007 Intel Corporation. All rights reserved.
|
|
*
|
|
* Maintained at www.Open-FCoE.org
|
|
*/
|
|
|
|
/*
|
|
* Frame allocation.
|
|
*/
|
|
#include <linux/module.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/skbuff.h>
|
|
#include <linux/crc32.h>
|
|
#include <linux/gfp.h>
|
|
|
|
#include <scsi/fc_frame.h>
|
|
|
|
/*
|
|
* Check the CRC in a frame.
|
|
*/
|
|
u32 fc_frame_crc_check(struct fc_frame *fp)
|
|
{
|
|
u32 crc;
|
|
u32 error;
|
|
const u8 *bp;
|
|
unsigned int len;
|
|
|
|
WARN_ON(!fc_frame_is_linear(fp));
|
|
fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
|
|
len = (fr_len(fp) + 3) & ~3; /* round up length to include fill */
|
|
bp = (const u8 *) fr_hdr(fp);
|
|
crc = ~crc32(~0, bp, len);
|
|
error = crc ^ fr_crc(fp);
|
|
return error;
|
|
}
|
|
EXPORT_SYMBOL(fc_frame_crc_check);
|
|
|
|
/*
|
|
* Allocate a frame intended to be sent.
|
|
* Get an sk_buff for the frame and set the length.
|
|
*/
|
|
struct fc_frame *_fc_frame_alloc(size_t len)
|
|
{
|
|
struct fc_frame *fp;
|
|
struct sk_buff *skb;
|
|
|
|
WARN_ON((len % sizeof(u32)) != 0);
|
|
len += sizeof(struct fc_frame_header);
|
|
skb = alloc_skb_fclone(len + FC_FRAME_HEADROOM + FC_FRAME_TAILROOM +
|
|
NET_SKB_PAD, GFP_ATOMIC);
|
|
if (!skb)
|
|
return NULL;
|
|
skb_reserve(skb, NET_SKB_PAD + FC_FRAME_HEADROOM);
|
|
fp = (struct fc_frame *) skb;
|
|
fc_frame_init(fp);
|
|
skb_put(skb, len);
|
|
return fp;
|
|
}
|
|
EXPORT_SYMBOL(_fc_frame_alloc);
|
|
|
|
struct fc_frame *fc_frame_alloc_fill(struct fc_lport *lp, size_t payload_len)
|
|
{
|
|
struct fc_frame *fp;
|
|
size_t fill;
|
|
|
|
fill = payload_len % 4;
|
|
if (fill != 0)
|
|
fill = 4 - fill;
|
|
fp = _fc_frame_alloc(payload_len + fill);
|
|
if (fp) {
|
|
memset((char *) fr_hdr(fp) + payload_len, 0, fill);
|
|
/* trim is OK, we just allocated it so there are no fragments */
|
|
skb_trim(fp_skb(fp),
|
|
payload_len + sizeof(struct fc_frame_header));
|
|
}
|
|
return fp;
|
|
}
|
|
EXPORT_SYMBOL(fc_frame_alloc_fill);
|