brintos

brintos / linux-shallow public Read only

0
0
Text · 6.7 KiB · 54f6fb0 Raw
223 lines · c
1/***********************license start************************************2 * Copyright (c) 2003-2017 Cavium, Inc.3 * All rights reserved.4 *5 * License: one of 'Cavium License' or 'GNU General Public License Version 2'6 *7 * This file is provided under the terms of the Cavium License (see below)8 * or under the terms of GNU General Public License, Version 2, as9 * published by the Free Software Foundation. When using or redistributing10 * this file, you may do so under either license.11 *12 * Cavium License:  Redistribution and use in source and binary forms, with13 * or without modification, are permitted provided that the following14 * conditions are met:15 *16 *  * Redistributions of source code must retain the above copyright17 *    notice, this list of conditions and the following disclaimer.18 *19 *  * Redistributions in binary form must reproduce the above20 *    copyright notice, this list of conditions and the following21 *    disclaimer in the documentation and/or other materials provided22 *    with the distribution.23 *24 *  * Neither the name of Cavium Inc. nor the names of its contributors may be25 *    used to endorse or promote products derived from this software without26 *    specific prior written permission.27 *28 * This Software, including technical data, may be subject to U.S. export29 * control laws, including the U.S. Export Administration Act and its30 * associated regulations, and may be subject to export or import31 * regulations in other countries.32 *33 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"34 * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS35 * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH36 * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY37 * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT38 * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY)39 * WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A40 * PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET41 * ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE42 * ENTIRE  RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES43 * WITH YOU.44 ***********************license end**************************************/45 46#ifndef __COMMON_H__47#define __COMMON_H__48 49#include <linux/delay.h>50#include <linux/init.h>51#include <linux/interrupt.h>52#include <linux/io.h>53#include <linux/kernel.h>54#include <linux/module.h>55#include <linux/pci.h>56#include <linux/seq_file.h>57#include <linux/string.h>58#include <linux/types.h>59 60/* Device specific zlib function definitions */61#include "zip_device.h"62 63/* ZIP device definitions */64#include "zip_main.h"65 66/* ZIP memory allocation/deallocation related definitions */67#include "zip_mem.h"68 69/* Device specific structure definitions */70#include "zip_regs.h"71 72#define ZIP_ERROR    -173 74#define ZIP_FLUSH_FINISH  475 76#define RAW_FORMAT		0  /* for rawpipe */77#define ZLIB_FORMAT		1  /* for zpipe */78#define GZIP_FORMAT		2  /* for gzpipe */79#define LZS_FORMAT		3  /* for lzspipe */80 81/* Max number of ZIP devices supported */82#define MAX_ZIP_DEVICES		283 84/* Configures the number of zip queues to be used */85#define ZIP_NUM_QUEUES		286 87#define DYNAMIC_STOP_EXCESS	102488 89/* Maximum buffer sizes in direct mode */90#define MAX_INPUT_BUFFER_SIZE   (64 * 1024)91#define MAX_OUTPUT_BUFFER_SIZE  (64 * 1024)92 93/**94 * struct zip_operation - common data structure for comp and decomp operations95 * @input:               Next input byte is read from here96 * @output:              Next output byte written here97 * @ctx_addr:            Inflate context buffer address98 * @history:             Pointer to the history buffer99 * @input_len:           Number of bytes available at next_in100 * @input_total_len:     Total number of input bytes read101 * @output_len:          Remaining free space at next_out102 * @output_total_len:    Total number of bytes output so far103 * @csum:                Checksum value of the uncompressed data104 * @flush:               Flush flag105 * @format:              Format (depends on stream's wrap)106 * @speed:               Speed depends on stream's level107 * @ccode:               Compression code ( stream's strategy)108 * @lzs_flag:            Flag for LZS support109 * @begin_file:          Beginning of file indication for inflate110 * @history_len:         Size of the history data111 * @end_file:            Ending of the file indication for inflate112 * @compcode:            Completion status of the ZIP invocation113 * @bytes_read:          Input bytes read in current instruction114 * @bits_processed:      Total bits processed for entire file115 * @sizeofptr:           To distinguish between ILP32 and LP64116 * @sizeofzops:          Optional just for padding117 *118 * This structure is used to maintain the required meta data for the119 * comp and decomp operations.120 */121struct zip_operation {122	u8    *input;123	u8    *output;124	u64   ctx_addr;125	u64   history;126 127	u32   input_len;128	u32   input_total_len;129 130	u32   output_len;131	u32   output_total_len;132 133	u32   csum;134	u32   flush;135 136	u32   format;137	u32   speed;138	u32   ccode;139	u32   lzs_flag;140 141	u32   begin_file;142	u32   history_len;143 144	u32   end_file;145	u32   compcode;146	u32   bytes_read;147	u32   bits_processed;148 149	u32   sizeofptr;150	u32   sizeofzops;151};152 153static inline int zip_poll_result(union zip_zres_s *result)154{155	int retries = 1000;156 157	while (!result->s.compcode) {158		if (!--retries) {159			pr_err("ZIP ERR: request timed out");160			return -ETIMEDOUT;161		}162		udelay(10);163		/*164		 * Force re-reading of compcode which is updated165		 * by the ZIP coprocessor.166		 */167		rmb();168	}169	return 0;170}171 172/* error messages */173#define zip_err(fmt, args...) pr_err("ZIP ERR:%s():%d: " \174			      fmt "\n", __func__, __LINE__, ## args)175 176#ifdef MSG_ENABLE177/* Enable all messages */178#define zip_msg(fmt, args...) pr_info("ZIP_MSG:" fmt "\n", ## args)179#else180#define zip_msg(fmt, args...)181#endif182 183#if defined(ZIP_DEBUG_ENABLE) && defined(MSG_ENABLE)184 185#ifdef DEBUG_LEVEL186 187#define FILE_NAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : \188	strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)189 190#if DEBUG_LEVEL >= 4191 192#define zip_dbg(fmt, args...) pr_info("ZIP DBG: %s: %s() : %d: " \193			      fmt "\n", FILE_NAME, __func__, __LINE__, ## args)194 195#elif DEBUG_LEVEL >= 3196 197#define zip_dbg(fmt, args...) pr_info("ZIP DBG: %s: %s() : %d: " \198			      fmt "\n", FILE_NAME, __func__, __LINE__, ## args)199 200#elif DEBUG_LEVEL >= 2201 202#define zip_dbg(fmt, args...) pr_info("ZIP DBG: %s() : %d: " \203			      fmt "\n", __func__, __LINE__, ## args)204 205#else206 207#define zip_dbg(fmt, args...) pr_info("ZIP DBG:" fmt "\n", ## args)208 209#endif /* DEBUG LEVEL >=4 */210 211#else212 213#define zip_dbg(fmt, args...) pr_info("ZIP DBG:" fmt "\n", ## args)214 215#endif /* DEBUG_LEVEL */216#else217 218#define zip_dbg(fmt, args...)219 220#endif /* ZIP_DEBUG_ENABLE && MSG_ENABLE*/221 222#endif223