Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 91c1953d authored by Rahul Lakkireddy's avatar Rahul Lakkireddy Committed by David S. Miller
Browse files

cxgb4: use zlib deflate to compress firmware dump



Use zlib deflate to compress firmware dump. Collect and compress
as much firmware dump as possible into a 32 MB buffer.

Signed-off-by: default avatarRahul Lakkireddy <rahul.lakkireddy@chelsio.com>
Signed-off-by: default avatarVishal Kulkarni <vishal@chelsio.com>
Signed-off-by: default avatarGanesh Goudar <ganeshgr@chelsio.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 56cf2635
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -12,3 +12,4 @@ cxgb4-objs := cxgb4_main.o l2t.o smt.o t4_hw.o sge.o clip_tbl.o cxgb4_ethtool.o
cxgb4-$(CONFIG_CHELSIO_T4_DCB) +=  cxgb4_dcb.o
cxgb4-$(CONFIG_CHELSIO_T4_FCOE) +=  cxgb4_fcoe.o
cxgb4-$(CONFIG_DEBUG_FS) += cxgb4_debugfs.o
cxgb4-$(CONFIG_ZLIB_DEFLATE) += cudbg_zlib.o
+1 −0
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ struct cudbg_init {
	u8 compress_type; /* Type of compression to use */
	void *compress_buff; /* Compression buffer */
	u32 compress_buff_size; /* Compression buffer size */
	void *workspace; /* Workspace for zlib */
};

static inline unsigned int cudbg_mbytes_to_bytes(unsigned int size)
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ enum cudbg_dump_type {

enum cudbg_compression_type {
	CUDBG_COMPRESSION_NONE = 1,
	CUDBG_COMPRESSION_ZLIB,
};

struct cudbg_hdr {
+81 −0
Original line number Diff line number Diff line
/*
 *  Copyright (C) 2018 Chelsio Communications.  All rights reserved.
 *
 *  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.
 *
 *  The full GNU General Public License is included in this distribution in
 *  the file called "COPYING".
 *
 */

#include <linux/zlib.h>

#include "cxgb4.h"
#include "cudbg_if.h"
#include "cudbg_lib_common.h"
#include "cudbg_zlib.h"

static int cudbg_get_compress_hdr(struct cudbg_buffer *pdbg_buff,
				  struct cudbg_buffer *pin_buff)
{
	if (pdbg_buff->offset + sizeof(struct cudbg_compress_hdr) >
	    pdbg_buff->size)
		return CUDBG_STATUS_NO_MEM;

	pin_buff->data = (char *)pdbg_buff->data + pdbg_buff->offset;
	pin_buff->offset = 0;
	pin_buff->size = sizeof(struct cudbg_compress_hdr);
	pdbg_buff->offset += sizeof(struct cudbg_compress_hdr);
	return 0;
}

int cudbg_compress_buff(struct cudbg_init *pdbg_init,
			struct cudbg_buffer *pin_buff,
			struct cudbg_buffer *pout_buff)
{
	struct z_stream_s compress_stream = { 0 };
	struct cudbg_buffer temp_buff = { 0 };
	struct cudbg_compress_hdr *c_hdr;
	int rc;

	/* Write compression header to output buffer before compression */
	rc = cudbg_get_compress_hdr(pout_buff, &temp_buff);
	if (rc)
		return rc;

	c_hdr = (struct cudbg_compress_hdr *)temp_buff.data;
	c_hdr->compress_id = CUDBG_ZLIB_COMPRESS_ID;

	compress_stream.workspace = pdbg_init->workspace;
	rc = zlib_deflateInit2(&compress_stream, Z_DEFAULT_COMPRESSION,
			       Z_DEFLATED, CUDBG_ZLIB_WIN_BITS,
			       CUDBG_ZLIB_MEM_LVL, Z_DEFAULT_STRATEGY);
	if (rc != Z_OK)
		return CUDBG_SYSTEM_ERROR;

	compress_stream.next_in = pin_buff->data;
	compress_stream.avail_in = pin_buff->size;
	compress_stream.next_out = pout_buff->data + pout_buff->offset;
	compress_stream.avail_out = pout_buff->size - pout_buff->offset;

	rc = zlib_deflate(&compress_stream, Z_FINISH);
	if (rc != Z_STREAM_END)
		return CUDBG_SYSTEM_ERROR;

	rc = zlib_deflateEnd(&compress_stream);
	if (rc != Z_OK)
		return CUDBG_SYSTEM_ERROR;

	c_hdr->compress_size = compress_stream.total_out;
	c_hdr->decompress_size = pin_buff->size;
	pout_buff->offset += compress_stream.total_out;

	return 0;
}
+29 −0
Original line number Diff line number Diff line
@@ -18,10 +18,39 @@
#ifndef __CUDBG_ZLIB_H__
#define __CUDBG_ZLIB_H__

#include <linux/zlib.h>

#define CUDBG_ZLIB_COMPRESS_ID 17
#define CUDBG_ZLIB_WIN_BITS 12
#define CUDBG_ZLIB_MEM_LVL 4

struct cudbg_compress_hdr {
	u32 compress_id;
	u64 decompress_size;
	u64 compress_size;
	u64 rsvd[32];
};

static inline int cudbg_get_workspace_size(void)
{
#ifdef CONFIG_ZLIB_DEFLATE
	return zlib_deflate_workspacesize(CUDBG_ZLIB_WIN_BITS,
					  CUDBG_ZLIB_MEM_LVL);
#else
	return 0;
#endif /* CONFIG_ZLIB_DEFLATE */
}

#ifndef CONFIG_ZLIB_DEFLATE
static inline int cudbg_compress_buff(struct cudbg_init *pdbg_init,
				      struct cudbg_buffer *pin_buff,
				      struct cudbg_buffer *pout_buff)
{
	return 0;
}
#else
int cudbg_compress_buff(struct cudbg_init *pdbg_init,
			struct cudbg_buffer *pin_buff,
			struct cudbg_buffer *pout_buff);
#endif /* CONFIG_ZLIB_DEFLATE */
#endif /* __CUDBG_ZLIB_H__ */
Loading