/*1* This file is part of the Chelsio T6 Crypto driver for Linux.2*3* Copyright (c) 2003-2016 Chelsio Communications, Inc. All rights reserved.4*5* This software is available to you under a choice of one of two6* licenses. You may choose to be licensed under the terms of the GNU7* General Public License (GPL) Version 2, available from the file8* COPYING in the main directory of this source tree, or the9* OpenIB.org BSD license below:10*11* Redistribution and use in source and binary forms, with or12* without modification, are permitted provided that the following13* conditions are met:14*15* - Redistributions of source code must retain the above16* copyright notice, this list of conditions and the following17* 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 materials22* provided with the distribution.23*24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE31* SOFTWARE.32*33*/3435#ifndef __CHCR_CORE_H__36#define __CHCR_CORE_H__3738#include <crypto/algapi.h>39#include <net/tls.h>40#include "t4_hw.h"41#include "cxgb4.h"42#include "t4_msg.h"43#include "cxgb4_uld.h"4445#define DRV_MODULE_NAME "chcr"46#define DRV_DESC "Chelsio T6 Crypto Co-processor Driver"4748#define MAX_PENDING_REQ_TO_HW 2049#define CHCR_TEST_RESPONSE_TIMEOUT 100050#define WQ_DETACH_TM (msecs_to_jiffies(50))51#define PAD_ERROR_BIT 152#define CHK_PAD_ERR_BIT(x) (((x) >> PAD_ERROR_BIT) & 1)5354#define MAC_ERROR_BIT 055#define CHK_MAC_ERR_BIT(x) (((x) >> MAC_ERROR_BIT) & 1)56#define MAX_SALT 457#define CIP_WR_MIN_LEN (sizeof(struct chcr_wr) + \58sizeof(struct cpl_rx_phys_dsgl) + \59sizeof(struct ulptx_sgl) + 16) //IV6061#define HASH_WR_MIN_LEN (sizeof(struct chcr_wr) + \62DUMMY_BYTES + \63sizeof(struct ulptx_sgl))64struct uld_ctx;6566struct _key_ctx {67__be32 ctx_hdr;68u8 salt[MAX_SALT];69__be64 iv_to_auth;70unsigned char key[];71};7273#define WQ_RETRY 574struct chcr_driver_data {75struct list_head act_dev;76struct list_head inact_dev;77atomic_t dev_count;78struct mutex drv_mutex;79struct uld_ctx *last_dev;80};8182enum chcr_state {83CHCR_INIT = 0,84CHCR_ATTACH,85CHCR_DETACH,86};87struct chcr_wr {88struct fw_crypto_lookaside_wr wreq;89struct ulp_txpkt ulptx;90struct ulptx_idata sc_imm;91struct cpl_tx_sec_pdu sec_cpl;92struct _key_ctx key_ctx;93};9495struct chcr_dev {96spinlock_t lock_chcr_dev;97enum chcr_state state;98atomic_t inflight;99int wqretry;100struct delayed_work detach_work;101struct completion detach_comp;102};103104struct uld_ctx {105struct list_head entry;106struct cxgb4_lld_info lldi;107struct chcr_dev dev;108};109110/*111* sgl_len - calculates the size of an SGL of the given capacity112* @n: the number of SGL entries113* Calculates the number of flits needed for a scatter/gather list that114* can hold the given number of entries.115*/116static inline unsigned int sgl_len(unsigned int n)117{118n--;119return (3 * n) / 2 + (n & 1) + 2;120}121122static inline void *padap(struct chcr_dev *dev)123{124struct uld_ctx *u_ctx = container_of(dev, struct uld_ctx, dev);125126return pci_get_drvdata(u_ctx->lldi.pdev);127}128129struct uld_ctx *assign_chcr_device(void);130int chcr_send_wr(struct sk_buff *skb);131int start_crypto(void);132int stop_crypto(void);133int chcr_uld_rx_handler(void *handle, const __be64 *rsp,134const struct pkt_gl *pgl);135int chcr_handle_resp(struct crypto_async_request *req, unsigned char *input,136int err);137#endif /* __CHCR_CORE_H__ */138139140