/* SPDX-License-Identifier: GPL-2.0 */
/*
* Thunderbolt driver - bus logic (NHI independent)
*
* Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
* Copyright (C) 2018, Intel Corporation
*/
#ifndef TB_H_
#define TB_H_
#include <linux/nvmem-provider.h>
#include <linux/pci.h>
#include <linux/thunderbolt.h>
#include <linux/uuid.h>
#include <linux/bitfield.h>
#include "tb_regs.h"
#include "ctl.h"
#include "dma_port.h"
/* Keep link controller awake during update */
#define QUIRK_FORCE_POWER_LINK_CONTROLLER BIT(0)
/* Disable CLx if not supported */
#define QUIRK_NO_CLX BIT(1)
/**
* struct tb_nvm - Structure holding NVM information
* @dev: Owner of the NVM
* @major: Major version number of the active NVM portion
* @minor: Minor version number of the active NVM portion
* @id: Identifier used with both NVM portions
* @active: Active portion NVMem device
* @active_size: Size in bytes of the active NVM
* @non_active: Non-active portion NVMem device
* @buf: Buffer where the NVM image is stored before it is written to
* the actual NVM flash device
* @buf_data_start: Where the actual image starts after skipping
* possible headers
* @buf_data_size: Number of bytes actually consumed by the new NVM
* image
* @authenticating: The device is authenticating the new NVM
* @flushed: The image has been flushed to the storage area
* @vops: Router vendor specific NVM operations (optional)
*
* The user of this structure needs to handle serialization of possible
* concurrent access.
*/
struct tb_nvm {
struct device *dev;
u32 major;
u32 minor;
int id;
struct nvmem_device *active;
size_t active_size;
struct nvmem_device *non_active;
void *buf;
void *buf_data_start;
size_t buf_data_size;
bool authenticating;
bool flushed;
const struct tb_nvm_vendor_ops *vops;
};
enum tb_nvm_write_ops {
WRITE_AND_AUTHENTICATE = 1,
WRITE_ONLY = 2,
AUTHENTICATE_ONLY = 3,
};
#define TB_SWITCH_KEY_SIZE 32
#define TB_SWITCH_MAX_DEPTH 6
#define USB4_SWITCH_MAX_DEPTH 5
/**
* enum tb_switch_tmu_mode - TMU mode
* @TB_SWITCH_TMU_MODE_OFF: TMU is off
* @TB_SWITCH_TMU_MODE_LOWRES: Uni-directional, normal mode
* @TB_SWITCH_TMU_MODE_HIFI_UNI: Uni-directional, HiFi mode
* @TB_SWITCH_TMU_MODE_HIFI_BI: Bi-directional, HiFi mode
* @TB_SWITCH_TMU_MODE_MEDRES_ENHANCED_UNI: Enhanced Uni-directional, MedRes mode
*
* Ordering is based on TMU accuracy level (highest last).
*/
enum tb_switch_tmu_mode {
TB_SWITCH_TMU_MODE_OFF,
TB_SWITCH_TMU_MODE_LOWRES,
TB_SWITCH_TMU_MODE_HIFI_UNI,
TB_SWITCH_TMU_MODE_HIFI_BI,
TB_SWITCH_TMU_MODE_MEDRES_ENHANCED_UNI,
};
/**
* struct tb_switch_tmu - Structure holding router TMU configuration
* @c