Skip to content

Commit

Permalink
driver:crypto:add support for montage Mont-TSSE
Browse files Browse the repository at this point in the history
add Mont-TSSE driver

Signed-off-by: Carrie.Cai <[email protected]>
  • Loading branch information
caizhongfei committed May 28, 2024
1 parent 899e802 commit 5334ecc
Show file tree
Hide file tree
Showing 23 changed files with 2,071 additions and 0 deletions.
1 change: 1 addition & 0 deletions arch/x86/configs/deepin_x86_desktop_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5548,6 +5548,7 @@ CONFIG_CRYPTO_DEV_ASPEED=m
CONFIG_CRYPTO_DEV_ASPEED_HACE_HASH=y
CONFIG_CRYPTO_DEV_ASPEED_HACE_CRYPTO=y
CONFIG_CRYPTO_DEV_ASPEED_ACRY=y
CONFIG_CRYPTO_DEV_TSSE=m
CONFIG_PKCS8_PRIVATE_KEY_PARSER=m
CONFIG_PKCS7_TEST_KEY=m
CONFIG_SIGNED_PE_FILE_VERIFICATION=y
Expand Down
1 change: 1 addition & 0 deletions drivers/crypto/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -796,5 +796,6 @@ config CRYPTO_DEV_SA2UL

source "drivers/crypto/aspeed/Kconfig"
source "drivers/crypto/starfive/Kconfig"
source "drivers/crypto/montage/Kconfig"

endif # CRYPTO_HW
1 change: 1 addition & 0 deletions drivers/crypto/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ obj-y += hisilicon/
obj-$(CONFIG_CRYPTO_DEV_AMLOGIC_GXL) += amlogic/
obj-y += intel/
obj-y += starfive/
obj-y += montage/
3 changes: 3 additions & 0 deletions drivers/crypto/montage/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: GPL-2.0

source "drivers/crypto/montage/tsse/Kconfig"
3 changes: 3 additions & 0 deletions drivers/crypto/montage/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: GPL-2.0

obj-$(CONFIG_CRYPTO_DEV_TSSE) += tsse/
9 changes: 9 additions & 0 deletions drivers/crypto/montage/tsse/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: GPL-2.0-only
config CRYPTO_DEV_TSSE
tristate "Support for Montage(R) TSSE"
depends on X86 && PCI
select FW_LOADER
help
Support for Montage(R) TSSE for accelerating crypto workloads.

To compile this as a module, choose M here.
15 changes: 15 additions & 0 deletions drivers/crypto/montage/tsse/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-License-Identifier: GPL-2.0-or-later
#
# This file is part of tsse driver for Linux
#
# Copyright © 2023 Montage Technology. All rights reserved.

obj-m += tsse.o

tsse-objs := tsse_dev_mgr.o \
tsse_ipc.o \
tsse_fw_service.o \
tsse_service.o \
tsse_irq.o \
tsse_dev_drv.o \
tsse_vuart.o
102 changes: 102 additions & 0 deletions drivers/crypto/montage/tsse/tsse_dev.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* This file is part of tsse driver for Linux
*
* Copyright © 2023 Montage Technology. All rights reserved.
*/

#ifndef __TSSE_DEV_H__
#define __TSSE_DEV_H__
#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/pci-ats.h>
#include <linux/serial_core.h>
#include <linux/firmware.h>
#include "tsse_ipc.h"

#define TSSE_PCI_MAX_BARS 4
#define TSSE_FW_VERSION_LEN 32

struct tsse_bar {
void __iomem *virt_addr;
resource_size_t addr;
resource_size_t size;
};
struct tsse_dev_pci {
struct pci_dev *pci_dev;
struct tsse_bar bars[TSSE_PCI_MAX_BARS];
u8 revid;
};
enum tsse_dev_status_bit {
TSSE_DEV_STATUS_STARTING = 0,
TSSE_DEV_STATUS_STARTED = 1

};
struct tsse_qpairs_bank {
struct tsse_dev *tsse_dev;
void __iomem *reg_base;

u32 num_qparis;
u32 irq_vec;
};
struct tsse_dev {
struct module *owner;
struct dentry *debugfs_dir;
unsigned long status;
struct list_head list;
struct tsse_dev_pci tsse_pci_dev;
struct tsse_qpairs_bank qpairs_bank;
atomic_t ref_count;
bool is_vf;
int id;
u32 num_irqs;
u32 num_vfs;
struct uart_port *port;
struct tsse_ipc *ipc;
void *adi;
void *mbx_hw;
const struct firmware *fw;
char fw_version[TSSE_FW_VERSION_LEN];
bool fw_version_exist;
};
#define TSSEDEV_TO_DEV(tssedev) (&((tssedev)->tsse_pci_dev.pci_dev->dev))
#define TSSE_DEV_BARS(tssedev) ((tssedev)->tsse_pci_dev.bars)

#include "tsse_log.h"

struct list_head *tsse_devmgr_get_head(void);

int tsse_dev_get(struct tsse_dev *tsse_dev);
void tsse_dev_put(struct tsse_dev *tsse_dev);
int tsse_devmgr_add_dev(struct tsse_dev *tsse_dev);
void tsse_devmgr_rm_dev(struct tsse_dev *tdev);
int tsse_prepare_restart_dev(struct tsse_dev *tdev);
int tsse_start_dev(struct tsse_dev *tdev);

static inline struct tsse_dev *pci_to_tsse_dev(struct pci_dev *pci_dev)
{
return (struct tsse_dev *)pci_get_drvdata(pci_dev);
}

static inline int tsse_get_cur_node(void)
{
int cpu, node;

cpu = get_cpu();
node = topology_physical_package_id(cpu);
put_cpu();

return node;
}

static inline int tsse_dev_started(struct tsse_dev *tdev)
{
return test_bit(TSSE_DEV_STATUS_STARTED, &tdev->status);
}
static inline int tsse_dev_in_use(struct tsse_dev *tdev)
{
return atomic_read(&tdev->ref_count) != 0;
}
#endif
Loading

0 comments on commit 5334ecc

Please sign in to comment.