linux/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.c

// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
/* Copyright (C) 2015-2018 Netronome Systems, Inc. */

/*
 * nfp_nsp.c
 * Author: Jakub Kicinski <[email protected]>
 *         Jason McMullan <[email protected]>
 */

#include <asm/unaligned.h>
#include <linux/bitfield.h>
#include <linux/delay.h>
#include <linux/firmware.h>
#include <linux/kernel.h>
#include <linux/kthread.h>
#include <linux/overflow.h>
#include <linux/sizes.h>
#include <linux/slab.h>

#define NFP_SUBSYS

#include "nfp.h"
#include "nfp_cpp.h"
#include "nfp_nsp.h"

#define NFP_NSP_TIMEOUT_DEFAULT
#define NFP_NSP_TIMEOUT_BOOT

/* Offsets relative to the CSR base */
#define NSP_STATUS
#define NSP_STATUS_MAGIC
#define NSP_STATUS_MAJOR
#define NSP_STATUS_MINOR
#define NSP_STATUS_CODE
#define NSP_STATUS_RESULT
#define NSP_STATUS_BUSY

#define NSP_COMMAND
#define NSP_COMMAND_OPTION
#define NSP_COMMAND_CODE
#define NSP_COMMAND_DMA_BUF
#define NSP_COMMAND_START

/* CPP address to retrieve the data from */
#define NSP_BUFFER
#define NSP_BUFFER_CPP
#define NSP_BUFFER_ADDRESS

#define NSP_DFLT_BUFFER
#define NSP_DFLT_BUFFER_CPP
#define NSP_DFLT_BUFFER_ADDRESS

#define NSP_DFLT_BUFFER_CONFIG
#define NSP_DFLT_BUFFER_DMA_CHUNK_ORDER
#define NSP_DFLT_BUFFER_SIZE_4KB
#define NSP_DFLT_BUFFER_SIZE_MB

#define NFP_CAP_CMD_DMA_SG

#define NSP_MAGIC
#define NSP_MAJOR
#define NSP_MINOR

#define NSP_CODE_MAJOR
#define NSP_CODE_MINOR

#define NFP_FW_LOAD_RET_MAJOR
#define NFP_FW_LOAD_RET_MINOR

#define NFP_HWINFO_LOOKUP_SIZE

#define NFP_VERSIONS_SIZE
#define NFP_VERSIONS_CNT_OFF
#define NFP_VERSIONS_BSP_OFF
#define NFP_VERSIONS_CPLD_OFF
#define NFP_VERSIONS_APP_OFF
#define NFP_VERSIONS_BUNDLE_OFF
#define NFP_VERSIONS_UNDI_OFF
#define NFP_VERSIONS_NCSI_OFF
#define NFP_VERSIONS_CFGR_OFF

#define NSP_SFF_EEPROM_BLOCK_LEN

enum nfp_nsp_cmd {};

struct nfp_nsp_dma_buf {};

static const struct {} nsp_errors[] =;

struct nfp_nsp {};

/**
 * struct nfp_nsp_command_arg - NFP command argument structure
 * @code:	NFP SP Command Code
 * @dma:	@buf points to a host buffer, not NSP buffer
 * @timeout_sec:Timeout value to wait for completion in seconds
 * @option:	NFP SP Command Argument
 * @buf:	NFP SP Buffer Address
 * @error_cb:	Callback for interpreting option if error occurred
 * @error_quiet:Don't print command error/warning. Protocol errors are still
 *		    logged.
 */
struct nfp_nsp_command_arg {};

/**
 * struct nfp_nsp_command_buf_arg - NFP command with buffer argument structure
 * @arg:	NFP command argument structure
 * @in_buf:	Buffer with data for input
 * @in_size:	Size of @in_buf
 * @out_buf:	Buffer for output data
 * @out_size:	Size of @out_buf
 */
struct nfp_nsp_command_buf_arg {};

struct nfp_cpp *nfp_nsp_cpp(struct nfp_nsp *state)
{}

bool nfp_nsp_config_modified(struct nfp_nsp *state)
{}

void nfp_nsp_config_set_modified(struct nfp_nsp *state, bool modified)
{}

void *nfp_nsp_config_entries(struct nfp_nsp *state)
{}

unsigned int nfp_nsp_config_idx(struct nfp_nsp *state)
{}

void
nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries, unsigned int idx)
{}

void nfp_nsp_config_clear_state(struct nfp_nsp *state)
{}

static void nfp_nsp_print_extended_error(struct nfp_nsp *state, u32 ret_val)
{}

static int nfp_nsp_check(struct nfp_nsp *state)
{}

/**
 * nfp_nsp_open() - Prepare for communication and lock the NSP resource.
 * @cpp:	NFP CPP Handle
 */
struct nfp_nsp *nfp_nsp_open(struct nfp_cpp *cpp)
{}

/**
 * nfp_nsp_close() - Clean up and unlock the NSP resource.
 * @state:	NFP SP state
 */
void nfp_nsp_close(struct nfp_nsp *state)
{}

u16 nfp_nsp_get_abi_ver_major(struct nfp_nsp *state)
{}

u16 nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state)
{}

static int
nfp_nsp_wait_reg(struct nfp_cpp *cpp, u64 *reg, u32 nsp_cpp, u64 addr,
		 u64 mask, u64 val, u32 timeout_sec)
{}

/**
 * __nfp_nsp_command() - Execute a command on the NFP Service Processor
 * @state:	NFP SP state
 * @arg:	NFP command argument structure
 *
 * Return: 0 for success with no result
 *
 *	 positive value for NSP completion with a result code
 *
 *	-EAGAIN if the NSP is not yet present
 *	-ENODEV if the NSP is not a supported model
 *	-EBUSY if the NSP is stuck
 *	-EINTR if interrupted while waiting for completion
 *	-ETIMEDOUT if the NSP took longer than @timeout_sec seconds to complete
 */
static int
__nfp_nsp_command(struct nfp_nsp *state, const struct nfp_nsp_command_arg *arg)
{}

static int nfp_nsp_command(struct nfp_nsp *state, u16 code)
{}

static int
nfp_nsp_command_buf_def(struct nfp_nsp *nsp,
			struct nfp_nsp_command_buf_arg *arg)
{}

static int
nfp_nsp_command_buf_dma_sg(struct nfp_nsp *nsp,
			   struct nfp_nsp_command_buf_arg *arg,
			   unsigned int max_size, unsigned int chunk_order,
			   unsigned int dma_order)
{}

static int
nfp_nsp_command_buf_dma(struct nfp_nsp *nsp,
			struct nfp_nsp_command_buf_arg *arg,
			unsigned int max_size, unsigned int dma_order)
{}

static int
nfp_nsp_command_buf(struct nfp_nsp *nsp, struct nfp_nsp_command_buf_arg *arg)
{}

int nfp_nsp_wait(struct nfp_nsp *state)
{}

int nfp_nsp_device_soft_reset(struct nfp_nsp *state)
{}

int nfp_nsp_mac_reinit(struct nfp_nsp *state)
{}

static void nfp_nsp_load_fw_extended_msg(struct nfp_nsp *state, u32 ret_val)
{}

int nfp_nsp_load_fw(struct nfp_nsp *state, const struct firmware *fw)
{}

int nfp_nsp_write_flash(struct nfp_nsp *state, const struct firmware *fw)
{}

int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, unsigned int size)
{}

int nfp_nsp_write_eth_table(struct nfp_nsp *state,
			    const void *buf, unsigned int size)
{}

int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, unsigned int size)
{}

int nfp_nsp_read_sensors(struct nfp_nsp *state, unsigned int sensor_mask,
			 void *buf, unsigned int size)
{}

int nfp_nsp_load_stored_fw(struct nfp_nsp *state)
{}

static int
__nfp_nsp_hwinfo_lookup(struct nfp_nsp *state, void *buf, unsigned int size,
			bool optional)
{}

int nfp_nsp_hwinfo_lookup(struct nfp_nsp *state, void *buf, unsigned int size)
{}

int nfp_nsp_hwinfo_lookup_optional(struct nfp_nsp *state, void *buf,
				   unsigned int size, const char *default_val)
{}

int nfp_nsp_hwinfo_set(struct nfp_nsp *state, void *buf, unsigned int size)
{}

int nfp_nsp_fw_loaded(struct nfp_nsp *state)
{}

int nfp_nsp_versions(struct nfp_nsp *state, void *buf, unsigned int size)
{}

const char *nfp_nsp_versions_get(enum nfp_nsp_versions id, bool flash,
				 const u8 *buf, unsigned int size)
{}

static int
__nfp_nsp_module_eeprom(struct nfp_nsp *state, void *buf, unsigned int size)
{}

int nfp_nsp_read_module_eeprom(struct nfp_nsp *state, int eth_index,
			       unsigned int offset, void *data,
			       unsigned int len, unsigned int *read_len)
{
	struct eeprom_buf {
		u8 metalen;
		__le16 length;
		__le16 offset;
		__le16 readlen;
		u8 eth_index;
		u8 data[];
	} __packed *buf;
	int bufsz, ret;

	BUILD_BUG_ON(offsetof(struct eeprom_buf, data) % 8);

	/* Buffer must be large enough and rounded to the next block size. */
	bufsz = struct_size(buf, data, round_up(len, NSP_SFF_EEPROM_BLOCK_LEN));
	buf = kzalloc(bufsz, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;

	buf->metalen =
		offsetof(struct eeprom_buf, data) / NSP_SFF_EEPROM_BLOCK_LEN;
	buf->length = cpu_to_le16(len);
	buf->offset = cpu_to_le16(offset);
	buf->eth_index = eth_index;

	ret = __nfp_nsp_module_eeprom(state, buf, bufsz);

	*read_len = min_t(unsigned int, len, le16_to_cpu(buf->readlen));
	if (*read_len)
		memcpy(data, buf->data, *read_len);

	if (!ret && *read_len < len)
		ret = -EIO;

	kfree(buf);

	return ret;
};

int nfp_nsp_read_media(struct nfp_nsp *state, void *buf, unsigned int size)
{}