162306a36Sopenharmony_ci/***********************license start************************************
262306a36Sopenharmony_ci * Copyright (c) 2003-2017 Cavium, Inc.
362306a36Sopenharmony_ci * All rights reserved.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * License: one of 'Cavium License' or 'GNU General Public License Version 2'
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * This file is provided under the terms of the Cavium License (see below)
862306a36Sopenharmony_ci * or under the terms of GNU General Public License, Version 2, as
962306a36Sopenharmony_ci * published by the Free Software Foundation. When using or redistributing
1062306a36Sopenharmony_ci * this file, you may do so under either license.
1162306a36Sopenharmony_ci *
1262306a36Sopenharmony_ci * Cavium License:  Redistribution and use in source and binary forms, with
1362306a36Sopenharmony_ci * or without modification, are permitted provided that the following
1462306a36Sopenharmony_ci * conditions are met:
1562306a36Sopenharmony_ci *
1662306a36Sopenharmony_ci *  * Redistributions of source code must retain the above copyright
1762306a36Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
1862306a36Sopenharmony_ci *
1962306a36Sopenharmony_ci *  * Redistributions in binary form must reproduce the above
2062306a36Sopenharmony_ci *    copyright notice, this list of conditions and the following
2162306a36Sopenharmony_ci *    disclaimer in the documentation and/or other materials provided
2262306a36Sopenharmony_ci *    with the distribution.
2362306a36Sopenharmony_ci *
2462306a36Sopenharmony_ci *  * Neither the name of Cavium Inc. nor the names of its contributors may be
2562306a36Sopenharmony_ci *    used to endorse or promote products derived from this software without
2662306a36Sopenharmony_ci *    specific prior written permission.
2762306a36Sopenharmony_ci *
2862306a36Sopenharmony_ci * This Software, including technical data, may be subject to U.S. export
2962306a36Sopenharmony_ci * control laws, including the U.S. Export Administration Act and its
3062306a36Sopenharmony_ci * associated regulations, and may be subject to export or import
3162306a36Sopenharmony_ci * regulations in other countries.
3262306a36Sopenharmony_ci *
3362306a36Sopenharmony_ci * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
3462306a36Sopenharmony_ci * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS
3562306a36Sopenharmony_ci * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH
3662306a36Sopenharmony_ci * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
3762306a36Sopenharmony_ci * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
3862306a36Sopenharmony_ci * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY)
3962306a36Sopenharmony_ci * WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A
4062306a36Sopenharmony_ci * PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET
4162306a36Sopenharmony_ci * ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE
4262306a36Sopenharmony_ci * ENTIRE  RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES
4362306a36Sopenharmony_ci * WITH YOU.
4462306a36Sopenharmony_ci ***********************license end**************************************/
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci#ifndef __ZIP_MAIN_H__
4762306a36Sopenharmony_ci#define __ZIP_MAIN_H__
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci#include "zip_device.h"
5062306a36Sopenharmony_ci#include "zip_regs.h"
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci/* PCI device IDs */
5362306a36Sopenharmony_ci#define PCI_DEVICE_ID_THUNDERX_ZIP   0xA01A
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci/* ZIP device BARs */
5662306a36Sopenharmony_ci#define PCI_CFG_ZIP_PF_BAR0   0  /* Base addr for normal regs */
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci/* Maximum available zip queues */
5962306a36Sopenharmony_ci#define ZIP_MAX_NUM_QUEUES    8
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci#define ZIP_128B_ALIGN        7
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci/* Command queue buffer size */
6462306a36Sopenharmony_ci#define ZIP_CMD_QBUF_SIZE     (8064 + 8)
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_cistruct zip_registers {
6762306a36Sopenharmony_ci	char  *reg_name;
6862306a36Sopenharmony_ci	u64   reg_offset;
6962306a36Sopenharmony_ci};
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci/* ZIP Compression - Decompression stats */
7262306a36Sopenharmony_cistruct zip_stats {
7362306a36Sopenharmony_ci	atomic64_t    comp_req_submit;
7462306a36Sopenharmony_ci	atomic64_t    comp_req_complete;
7562306a36Sopenharmony_ci	atomic64_t    decomp_req_submit;
7662306a36Sopenharmony_ci	atomic64_t    decomp_req_complete;
7762306a36Sopenharmony_ci	atomic64_t    comp_in_bytes;
7862306a36Sopenharmony_ci	atomic64_t    comp_out_bytes;
7962306a36Sopenharmony_ci	atomic64_t    decomp_in_bytes;
8062306a36Sopenharmony_ci	atomic64_t    decomp_out_bytes;
8162306a36Sopenharmony_ci	atomic64_t    decomp_bad_reqs;
8262306a36Sopenharmony_ci};
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci/* ZIP Instruction Queue */
8562306a36Sopenharmony_cistruct zip_iq {
8662306a36Sopenharmony_ci	u64        *sw_head;
8762306a36Sopenharmony_ci	u64        *sw_tail;
8862306a36Sopenharmony_ci	u64        *hw_tail;
8962306a36Sopenharmony_ci	u64        done_cnt;
9062306a36Sopenharmony_ci	u64        pend_cnt;
9162306a36Sopenharmony_ci	u64        free_flag;
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci	/* ZIP IQ lock */
9462306a36Sopenharmony_ci	spinlock_t  lock;
9562306a36Sopenharmony_ci};
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci/* ZIP Device */
9862306a36Sopenharmony_cistruct zip_device {
9962306a36Sopenharmony_ci	u32               index;
10062306a36Sopenharmony_ci	void __iomem      *reg_base;
10162306a36Sopenharmony_ci	struct pci_dev    *pdev;
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci	/* Different ZIP Constants */
10462306a36Sopenharmony_ci	u64               depth;
10562306a36Sopenharmony_ci	u64               onfsize;
10662306a36Sopenharmony_ci	u64               ctxsize;
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci	struct zip_iq     iq[ZIP_MAX_NUM_QUEUES];
10962306a36Sopenharmony_ci	struct zip_stats  stats;
11062306a36Sopenharmony_ci};
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci/* Prototypes */
11362306a36Sopenharmony_cistruct zip_device *zip_get_device(int node_id);
11462306a36Sopenharmony_ciint zip_get_node_id(void);
11562306a36Sopenharmony_civoid zip_reg_write(u64 val, u64 __iomem *addr);
11662306a36Sopenharmony_ciu64 zip_reg_read(u64 __iomem *addr);
11762306a36Sopenharmony_civoid zip_update_cmd_bufs(struct zip_device *zip_dev, u32 queue);
11862306a36Sopenharmony_ciu32 zip_load_instr(union zip_inst_s *instr, struct zip_device *zip_dev);
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci#endif /* ZIP_MAIN_H */
121