cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

iosm_ipc_mux.h (13935B)


      1/* SPDX-License-Identifier: GPL-2.0-only
      2 *
      3 * Copyright (C) 2020-21 Intel Corporation.
      4 */
      5
      6#ifndef IOSM_IPC_MUX_H
      7#define IOSM_IPC_MUX_H
      8
      9#include "iosm_ipc_protocol.h"
     10
     11#define IPC_MEM_MAX_UL_DG_ENTRIES	100
     12#define IPC_MEM_MAX_TDS_MUX_AGGR_UL	60
     13
     14#define IPC_MEM_MAX_ADB_BUF_SIZE (16 * 1024)
     15#define IPC_MEM_MAX_UL_ADB_BUF_SIZE IPC_MEM_MAX_ADB_BUF_SIZE
     16#define IPC_MEM_MAX_DL_ADB_BUF_SIZE IPC_MEM_MAX_ADB_BUF_SIZE
     17
     18/* Size of the buffer for the IP MUX Lite data buffer. */
     19#define IPC_MEM_MAX_DL_MUX_LITE_BUF_SIZE (2 * 1024)
     20
     21/* TD counts for IP MUX Lite */
     22#define IPC_MEM_MAX_TDS_MUX_LITE_UL 800
     23#define IPC_MEM_MAX_TDS_MUX_LITE_DL 1200
     24
     25/* open session request (AP->CP) */
     26#define MUX_CMD_OPEN_SESSION 1
     27
     28/* response to open session request (CP->AP) */
     29#define MUX_CMD_OPEN_SESSION_RESP 2
     30
     31/* close session request (AP->CP) */
     32#define MUX_CMD_CLOSE_SESSION 3
     33
     34/* response to close session request (CP->AP) */
     35#define MUX_CMD_CLOSE_SESSION_RESP 4
     36
     37/* Flow control command with mask of the flow per queue/flow. */
     38#define MUX_LITE_CMD_FLOW_CTL 5
     39
     40/* ACK the flow control command. Shall have the same Transaction ID as the
     41 * matching FLOW_CTL command.
     42 */
     43#define MUX_LITE_CMD_FLOW_CTL_ACK 6
     44
     45/* Command for report packet indicating link quality metrics. */
     46#define MUX_LITE_CMD_LINK_STATUS_REPORT 7
     47
     48/* Response to a report packet */
     49#define MUX_LITE_CMD_LINK_STATUS_REPORT_RESP 8
     50
     51/* Used to reset a command/response state. */
     52#define MUX_CMD_INVALID 255
     53
     54/* command response : command processed successfully */
     55#define MUX_CMD_RESP_SUCCESS 0
     56
     57/* MUX for route link devices */
     58#define IPC_MEM_WWAN_MUX BIT(0)
     59
     60/* Initiated actions to change the state of the MUX object. */
     61enum mux_event {
     62	MUX_E_INACTIVE, /* No initiated actions. */
     63	MUX_E_MUX_SESSION_OPEN, /* Create the MUX channel and a session. */
     64	MUX_E_MUX_SESSION_CLOSE, /* Release a session. */
     65	MUX_E_MUX_CHANNEL_CLOSE, /* Release the MUX channel. */
     66	MUX_E_NO_ORDERS, /* No MUX order. */
     67	MUX_E_NOT_APPLICABLE, /* Defect IP MUX. */
     68};
     69
     70/* MUX session open command. */
     71struct mux_session_open {
     72	enum mux_event event;
     73	__le32 if_id;
     74};
     75
     76/* MUX session close command. */
     77struct mux_session_close {
     78	enum mux_event event;
     79	__le32 if_id;
     80};
     81
     82/* MUX channel close command. */
     83struct mux_channel_close {
     84	enum mux_event event;
     85};
     86
     87/* Default message type to find out the right message type. */
     88struct mux_common {
     89	enum mux_event event;
     90};
     91
     92/* List of ops in MUX mode. */
     93union mux_msg {
     94	struct mux_session_open session_open;
     95	struct mux_session_close session_close;
     96	struct mux_channel_close channel_close;
     97	struct mux_common common;
     98};
     99
    100/* Parameter definition of the open session command. */
    101struct mux_cmd_open_session {
    102	u8 flow_ctrl; /* 0: Flow control disabled (flow allowed). */
    103	/* 1: Flow control enabled (flow not allowed)*/
    104	u8 ipv4v6_hints; /* 0: IPv4/IPv6 hints not supported.*/
    105	/* 1: IPv4/IPv6 hints supported*/
    106	__le16 reserved2; /* Reserved. Set to zero. */
    107	__le32 dl_head_pad_len; /* Maximum length supported */
    108	/* for DL head padding on a datagram. */
    109};
    110
    111/* Parameter definition of the open session response. */
    112struct mux_cmd_open_session_resp {
    113	__le32 response; /* Response code */
    114	u8 flow_ctrl; /* 0: Flow control disabled (flow allowed). */
    115	/* 1: Flow control enabled (flow not allowed) */
    116	u8 ipv4v6_hints; /* 0: IPv4/IPv6 hints not supported */
    117	/* 1: IPv4/IPv6 hints supported */
    118	__le16 reserved2; /* Reserved. Set to zero. */
    119	__le32 ul_head_pad_len; /* Actual length supported for */
    120	/* UL head padding on adatagram.*/
    121};
    122
    123/* Parameter definition of the close session response code */
    124struct mux_cmd_close_session_resp {
    125	__le32 response;
    126};
    127
    128/* Parameter definition of the flow control command. */
    129struct mux_cmd_flow_ctl {
    130	__le32 mask; /* indicating the desired flow control */
    131	/* state for various flows/queues */
    132};
    133
    134/* Parameter definition of the link status report code*/
    135struct mux_cmd_link_status_report {
    136	u8 payload;
    137};
    138
    139/* Parameter definition of the link status report response code. */
    140struct mux_cmd_link_status_report_resp {
    141	__le32 response;
    142};
    143
    144/**
    145 * union mux_cmd_param - Union-definition of the command parameters.
    146 * @open_session:	Inband command for open session
    147 * @open_session_resp:	Inband command for open session response
    148 * @close_session_resp:	Inband command for close session response
    149 * @flow_ctl:		In-band flow control on the opened interfaces
    150 * @link_status:	In-band Link Status Report
    151 * @link_status_resp:	In-band command for link status report response
    152 */
    153union mux_cmd_param {
    154	struct mux_cmd_open_session open_session;
    155	struct mux_cmd_open_session_resp open_session_resp;
    156	struct mux_cmd_close_session_resp close_session_resp;
    157	struct mux_cmd_flow_ctl flow_ctl;
    158	struct mux_cmd_link_status_report link_status;
    159	struct mux_cmd_link_status_report_resp link_status_resp;
    160};
    161
    162/* States of the MUX object.. */
    163enum mux_state {
    164	MUX_S_INACTIVE, /* IP MUX is unused. */
    165	MUX_S_ACTIVE, /* IP MUX channel is available. */
    166	MUX_S_ERROR, /* Defect IP MUX. */
    167};
    168
    169/* Supported MUX protocols. */
    170enum ipc_mux_protocol {
    171	MUX_UNKNOWN,
    172	MUX_LITE,
    173	MUX_AGGREGATION,
    174};
    175
    176/* Supported UL data transfer methods. */
    177enum ipc_mux_ul_flow {
    178	MUX_UL_UNKNOWN,
    179	MUX_UL, /* Normal UL data transfer */
    180	MUX_UL_ON_CREDITS, /* UL data transfer will be based on credits */
    181};
    182
    183/* List of the MUX session. */
    184struct mux_session {
    185	struct iosm_wwan *wwan; /*Network i/f used for communication*/
    186	int if_id; /* i/f id for session open message.*/
    187	u32 flags;
    188	u32 ul_head_pad_len; /* Nr of bytes for UL head padding. */
    189	u32 dl_head_pad_len; /* Nr of bytes for DL head padding. */
    190	struct sk_buff_head ul_list; /* skb entries for an ADT. */
    191	u32 flow_ctl_mask; /* UL flow control */
    192	u32 flow_ctl_en_cnt; /* Flow control Enable cmd count */
    193	u32 flow_ctl_dis_cnt; /* Flow Control Disable cmd count */
    194	int ul_flow_credits; /* UL flow credits */
    195	u8 net_tx_stop:1,
    196	   flush:1; /* flush net interface ? */
    197};
    198
    199/**
    200 * struct mux_adth_dg - Structure of the datagram in the Aggregated Datagram
    201 *			Table Header.
    202 * @datagram_index :	Index (in bytes) to the k-th datagram in the table.
    203 *			Index shall count from the start of the block including
    204 *			the 16-byte header. This value shall be non-zero.
    205 * @datagram_length:	Length of the k-th datagram including the head padding.
    206 *			This value shall be non-zero.
    207 * @service_class:	Service class identifier for the datagram.
    208 * @reserved:		Reserved bytes. Set to zero
    209 */
    210struct mux_adth_dg {
    211	__le32 datagram_index;
    212	__le16 datagram_length;
    213	u8 service_class;
    214	u8 reserved;
    215};
    216
    217/**
    218 * struct mux_qlth_ql - Structure of the queue level in the Aggregated
    219 *			Datagram Queue Level Table Header.
    220 * @nr_of_bytes:	Number of bytes available to transmit in the queue.
    221 */
    222struct mux_qlth_ql {
    223	__le32 nr_of_bytes;
    224};
    225
    226/**
    227 * struct mux_qlth -    Structure of Aggregated Datagram Queue Level Table
    228 *			Header.
    229 * @signature:          Signature of the Queue Level Table Header
    230 *                      Value: 0x48544C51 (ASCII characters: 'Q' 'L' 'T' 'H')
    231 * @table_length:       Length (in bytes) of the datagram table. This length
    232 *                      shall include the queue level table header size.
    233 *                      Minimum value:0x10
    234 * @if_id:              ID of the interface the queue levels in the table
    235 *                      belong to.
    236 * @reserved:           Reserved byte. Set to zero.
    237 * @next_table_index:   Index (in bytes) to the next table in the buffer. Index
    238 *                      shall count from the start of the block including the
    239 *                      16-byte header. Value of zero indicates end of the list.
    240 * @reserved2:          Reserved bytes. Set to zero
    241 * @ql:                 Queue level table with variable length
    242 */
    243struct mux_qlth {
    244	__le32 signature;
    245	__le16 table_length;
    246	u8 if_id;
    247	u8 reserved;
    248	__le32 next_table_index;
    249	__le32 reserved2;
    250	struct mux_qlth_ql ql;
    251};
    252
    253/**
    254 * struct mux_adb - Structure of State of a single UL data block.
    255 * @dest_skb:		Current UL skb for the data block.
    256 * @buf:		ADB memory
    257 * @adgh:		ADGH pointer
    258 * @qlth_skb:		QLTH pointer
    259 * @next_table_index:	Pointer to next table index.
    260 * @free_list:		List of alloc. ADB for the UL sess.
    261 * @size:		Size of the ADB memory.
    262 * @if_cnt:		Statistic counter
    263 * @dg_cnt_total:	Datagram count total
    264 * @payload_size:	Payload Size
    265 * @dg:			Datagram table.
    266 * @pp_qlt:		Pointers to hold Queue Level Tables of session
    267 * @adbh:		ADBH pointer
    268 * @qlt_updated:	Queue level table updated
    269 * @dg_count:		Datagram count
    270 */
    271struct mux_adb {
    272	struct sk_buff *dest_skb;
    273	u8 *buf;
    274	struct mux_adgh *adgh;
    275	struct sk_buff *qlth_skb;
    276	u32 *next_table_index;
    277	struct sk_buff_head free_list;
    278	int size;
    279	u32 if_cnt;
    280	u32 dg_cnt_total;
    281	u32 payload_size;
    282	struct mux_adth_dg
    283		dg[IPC_MEM_MUX_IP_SESSION_ENTRIES][IPC_MEM_MAX_UL_DG_ENTRIES];
    284	struct mux_qlth *pp_qlt[IPC_MEM_MUX_IP_SESSION_ENTRIES];
    285	struct mux_adbh *adbh;
    286	u32 qlt_updated[IPC_MEM_MUX_IP_SESSION_ENTRIES];
    287	u32 dg_count[IPC_MEM_MUX_IP_SESSION_ENTRIES];
    288};
    289
    290/**
    291 * struct mux_acb - Structure of Temporary ACB state.
    292 * @skb:		Used UL skb.
    293 * @if_id:		Session id.
    294 * @buf_p:		Command buffer.
    295 * @wanted_response:	Wanted Response
    296 * @got_response:	Got response
    297 * @cmd:		command
    298 * @got_param:		Received command/response parameter
    299 */
    300struct mux_acb {
    301	struct sk_buff *skb; /* Used UL skb. */
    302	int if_id; /* Session id. */
    303	u8 *buf_p;
    304	u32 wanted_response;
    305	u32 got_response;
    306	u32 cmd;
    307	union mux_cmd_param got_param; /* Received command/response parameter */
    308};
    309
    310/**
    311 * struct iosm_mux - Structure of the data multiplexing over an IP channel.
    312 * @dev:		Pointer to device structure
    313 * @session:		Array of the MUX sessions.
    314 * @channel:		Reference to the IP MUX channel
    315 * @pcie:		Pointer to iosm_pcie struct
    316 * @imem:		Pointer to iosm_imem
    317 * @wwan:		Poinetr to iosm_wwan
    318 * @ipc_protocol:	Pointer to iosm_protocol
    319 * @channel_id:		Channel ID for MUX
    320 * @protocol:		Type of the MUX protocol
    321 * @ul_flow:		UL Flow type
    322 * @nr_sessions:	Number of sessions
    323 * @instance_id:	Instance ID
    324 * @state:		States of the MUX object
    325 * @event:		Initiated actions to change the state of the MUX object
    326 * @tx_transaction_id:	Transaction id for the ACB command.
    327 * @rr_next_session:	Next session number for round robin.
    328 * @ul_adb:		State of the UL ADB/ADGH.
    329 * @size_needed:	Variable to store the size needed during ADB preparation
    330 * @ul_data_pend_bytes:	Pending UL data to be processed in bytes
    331 * @acb:		Temporary ACB state
    332 * @wwan_q_offset:	This will hold the offset of the given instance
    333 *			Useful while passing or receiving packets from
    334 *			wwan/imem layer.
    335 * @adb_finish_timer:	Timer for forcefully finishing the ADB
    336 * @acb_tx_sequence_nr: Sequence number for the ACB header.
    337 * @params:		user configurable parameters
    338 * @adb_tx_sequence_nr: Sequence number for ADB header
    339 * @acc_adb_size:       Statistic data for logging
    340 * @acc_payload_size:   Statistic data for logging
    341 * @initialized:	MUX object is initialized
    342 * @ev_mux_net_transmit_pending:
    343 *			0 means inform the IPC tasklet to pass the
    344 *			accumulated uplink ADB to CP.
    345 * @adb_prep_ongoing:	Flag for ADB preparation status
    346 */
    347struct iosm_mux {
    348	struct device *dev;
    349	struct mux_session session[IPC_MEM_MUX_IP_SESSION_ENTRIES];
    350	struct ipc_mem_channel *channel;
    351	struct iosm_pcie *pcie;
    352	struct iosm_imem *imem;
    353	struct iosm_wwan *wwan;
    354	struct iosm_protocol *ipc_protocol;
    355	int channel_id;
    356	enum ipc_mux_protocol protocol;
    357	enum ipc_mux_ul_flow ul_flow;
    358	int nr_sessions;
    359	int instance_id;
    360	enum mux_state state;
    361	enum mux_event event;
    362	u32 tx_transaction_id;
    363	int rr_next_session;
    364	struct mux_adb ul_adb;
    365	int size_needed;
    366	long long ul_data_pend_bytes;
    367	struct mux_acb acb;
    368	int wwan_q_offset;
    369	struct hrtimer adb_finish_timer;
    370	u16 acb_tx_sequence_nr;
    371	struct ipc_params *params;
    372	u16 adb_tx_sequence_nr;
    373	unsigned long long acc_adb_size;
    374	unsigned long long acc_payload_size;
    375	u8 initialized:1,
    376	   ev_mux_net_transmit_pending:1,
    377	   adb_prep_ongoing;
    378} __packed;
    379
    380/* MUX configuration structure */
    381struct ipc_mux_config {
    382	enum ipc_mux_protocol protocol;
    383	enum ipc_mux_ul_flow ul_flow;
    384	int instance_id;
    385};
    386
    387/**
    388 * ipc_mux_init - Allocates and Init MUX instance
    389 * @mux_cfg:	Pointer to MUX configuration structure
    390 * @ipc_imem:	Pointer to imem data-struct
    391 *
    392 * Returns: Initialized mux pointer on success else NULL
    393 */
    394struct iosm_mux *ipc_mux_init(struct ipc_mux_config *mux_cfg,
    395			      struct iosm_imem *ipc_imem);
    396
    397/**
    398 * ipc_mux_deinit - Deallocates MUX instance
    399 * @ipc_mux:	Pointer to the MUX instance.
    400 */
    401void ipc_mux_deinit(struct iosm_mux *ipc_mux);
    402
    403/**
    404 * ipc_mux_check_n_restart_tx - Checks for pending UL date bytes and then
    405 *				it restarts the net interface tx queue if
    406 *				device has set flow control as off.
    407 * @ipc_mux:	Pointer to MUX data-struct
    408 */
    409void ipc_mux_check_n_restart_tx(struct iosm_mux *ipc_mux);
    410
    411/**
    412 * ipc_mux_get_active_protocol - Returns the active MUX protocol type.
    413 * @ipc_mux:	Pointer to MUX data-struct
    414 *
    415 * Returns: enum of type ipc_mux_protocol
    416 */
    417enum ipc_mux_protocol ipc_mux_get_active_protocol(struct iosm_mux *ipc_mux);
    418
    419/**
    420 * ipc_mux_open_session - Opens a MUX session for IP traffic.
    421 * @ipc_mux:	Pointer to MUX data-struct
    422 * @session_nr:	Interface ID or session number
    423 *
    424 * Returns: channel id on success, failure value on error
    425 */
    426int ipc_mux_open_session(struct iosm_mux *ipc_mux, int session_nr);
    427
    428/**
    429 * ipc_mux_close_session - Closes a MUX session.
    430 * @ipc_mux:	Pointer to MUX data-struct
    431 * @session_nr:	Interface ID or session number
    432 *
    433 * Returns: channel id on success, failure value on error
    434 */
    435int ipc_mux_close_session(struct iosm_mux *ipc_mux, int session_nr);
    436
    437/**
    438 * ipc_mux_get_max_sessions - Retuns the maximum sessions supported on the
    439 *			      provided MUX instance..
    440 * @ipc_mux:	Pointer to MUX data-struct
    441 *
    442 * Returns: Number of sessions supported on Success and failure value on error
    443 */
    444int ipc_mux_get_max_sessions(struct iosm_mux *ipc_mux);
    445#endif