/* SPDX-License-Identifier: GPL-2.0-only */1/*2* Copyright (C) ST-Ericsson AB 20103* Author: Sjur Brendeland4*/56#ifndef CAIF_LAYER_H_7#define CAIF_LAYER_H_89#include <linux/list.h>1011struct cflayer;12struct cfpkt;13struct caif_payload_info;1415#define CAIF_LAYER_NAME_SZ 161617/**18* caif_assert() - Assert function for CAIF.19* @assert: expression to evaluate.20*21* This function will print a error message and a do WARN_ON if the22* assertion fails. Normally this will do a stack up at the current location.23*/24#define caif_assert(assert) \25do { \26if (!(assert)) { \27pr_err("caif:Assert detected:'%s'\n", #assert); \28WARN_ON(!(assert)); \29} \30} while (0)3132/**33* enum caif_ctrlcmd - CAIF Stack Control Signaling sent in layer.ctrlcmd().34*35* @CAIF_CTRLCMD_FLOW_OFF_IND: Flow Control is OFF, transmit function36* should stop sending data37*38* @CAIF_CTRLCMD_FLOW_ON_IND: Flow Control is ON, transmit function39* can start sending data40*41* @CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND: Remote end modem has decided to close42* down channel43*44* @CAIF_CTRLCMD_INIT_RSP: Called initially when the layer below45* has finished initialization46*47* @CAIF_CTRLCMD_DEINIT_RSP: Called when de-initialization is48* complete49*50* @CAIF_CTRLCMD_INIT_FAIL_RSP: Called if initialization fails51*52* @_CAIF_CTRLCMD_PHYIF_FLOW_OFF_IND: CAIF Link layer temporarily cannot53* send more packets.54* @_CAIF_CTRLCMD_PHYIF_FLOW_ON_IND: Called if CAIF Link layer is able55* to send packets again.56* @_CAIF_CTRLCMD_PHYIF_DOWN_IND: Called if CAIF Link layer is going57* down.58*59* These commands are sent upwards in the CAIF stack to the CAIF Client.60* They are used for signaling originating from the modem or CAIF Link Layer.61* These are either responses (*_RSP) or events (*_IND).62*/63enum caif_ctrlcmd {64CAIF_CTRLCMD_FLOW_OFF_IND,65CAIF_CTRLCMD_FLOW_ON_IND,66CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND,67CAIF_CTRLCMD_INIT_RSP,68CAIF_CTRLCMD_DEINIT_RSP,69CAIF_CTRLCMD_INIT_FAIL_RSP,70_CAIF_CTRLCMD_PHYIF_FLOW_OFF_IND,71_CAIF_CTRLCMD_PHYIF_FLOW_ON_IND,72_CAIF_CTRLCMD_PHYIF_DOWN_IND,73};7475/**76* enum caif_modemcmd - Modem Control Signaling, sent from CAIF Client77* to the CAIF Link Layer or modem.78*79* @CAIF_MODEMCMD_FLOW_ON_REQ: Flow Control is ON, transmit function80* can start sending data.81*82* @CAIF_MODEMCMD_FLOW_OFF_REQ: Flow Control is OFF, transmit function83* should stop sending data.84*85* @_CAIF_MODEMCMD_PHYIF_USEFULL: Notify physical layer that it is in use86*87* @_CAIF_MODEMCMD_PHYIF_USELESS: Notify physical layer that it is88* no longer in use.89*90* These are requests sent 'downwards' in the stack.91* Flow ON, OFF can be indicated to the modem.92*/93enum caif_modemcmd {94CAIF_MODEMCMD_FLOW_ON_REQ = 0,95CAIF_MODEMCMD_FLOW_OFF_REQ = 1,96_CAIF_MODEMCMD_PHYIF_USEFULL = 3,97_CAIF_MODEMCMD_PHYIF_USELESS = 498};99100/**101* enum caif_direction - CAIF Packet Direction.102* Indicate if a packet is to be sent out or to be received in.103* @CAIF_DIR_IN: Incoming packet received.104* @CAIF_DIR_OUT: Outgoing packet to be transmitted.105*/106enum caif_direction {107CAIF_DIR_IN = 0,108CAIF_DIR_OUT = 1109};110111/**112* struct cflayer - CAIF Stack layer.113* Defines the framework for the CAIF Core Stack.114* @up: Pointer up to the layer above.115* @dn: Pointer down to the layer below.116* @node: List node used when layer participate in a list.117* @receive: Packet receive function.118* @transmit: Packet transmit function.119* @ctrlcmd: Used for control signalling upwards in the stack.120* @modemcmd: Used for control signaling downwards in the stack.121* @id: The identity of this layer122* @name: Name of the layer.123*124* This structure defines the layered structure in CAIF.125*126* It defines CAIF layering structure, used by all CAIF Layers and the127* layers interfacing CAIF.128*129* In order to integrate with CAIF an adaptation layer on top of the CAIF stack130* and PHY layer below the CAIF stack131* must be implemented. These layer must follow the design principles below.132*133* Principles for layering of protocol layers:134* - All layers must use this structure. If embedding it, then place this135* structure first in the layer specific structure.136*137* - Each layer should not depend on any others layer's private data.138*139* - In order to send data upwards do140* layer->up->receive(layer->up, packet);141*142* - In order to send data downwards do143* layer->dn->transmit(layer->dn, info, packet);144*/145struct cflayer {146struct cflayer *up;147struct cflayer *dn;148struct list_head node;149150/*151* receive() - Receive Function (non-blocking).152* Contract: Each layer must implement a receive function passing the153* CAIF packets upwards in the stack.154* Packet handling rules:155* - The CAIF packet (cfpkt) ownership is passed to the156* called receive function. This means that the157* packet cannot be accessed after passing it to the158* above layer using up->receive().159*160* - If parsing of the packet fails, the packet must be161* destroyed and negative error code returned162* from the function.163* EXCEPTION: If the framing layer (cffrml) returns164* -EILSEQ, the packet is not freed.165*166* - If parsing succeeds (and above layers return OK) then167* the function must return a value >= 0.168*169* Returns result < 0 indicates an error, 0 or positive value170* indicates success.171*172* @layr: Pointer to the current layer the receive function is173* implemented for (this pointer).174* @cfpkt: Pointer to CaifPacket to be handled.175*/176int (*receive)(struct cflayer *layr, struct cfpkt *cfpkt);177178/*179* transmit() - Transmit Function (non-blocking).180* Contract: Each layer must implement a transmit function passing the181* CAIF packet downwards in the stack.182* Packet handling rules:183* - The CAIF packet (cfpkt) ownership is passed to the184* transmit function. This means that the packet185* cannot be accessed after passing it to the below186* layer using dn->transmit().187*188* - Upon error the packet ownership is still passed on,189* so the packet shall be freed where error is detected.190* Callers of the transmit function shall not free packets,191* but errors shall be returned.192*193* - Return value less than zero means error, zero or194* greater than zero means OK.195*196* Returns result < 0 indicates an error, 0 or positive value197* indicates success.198*199* @layr: Pointer to the current layer the receive function200* isimplemented for (this pointer).201* @cfpkt: Pointer to CaifPacket to be handled.202*/203int (*transmit) (struct cflayer *layr, struct cfpkt *cfpkt);204205/*206* cttrlcmd() - Control Function upwards in CAIF Stack (non-blocking).207* Used for signaling responses (CAIF_CTRLCMD_*_RSP)208* and asynchronous events from the modem (CAIF_CTRLCMD_*_IND)209*210* @layr: Pointer to the current layer the receive function211* is implemented for (this pointer).212* @ctrl: Control Command.213*/214void (*ctrlcmd) (struct cflayer *layr, enum caif_ctrlcmd ctrl,215int phyid);216217/*218* modemctrl() - Control Function used for controlling the modem.219* Used to signal down-wards in the CAIF stack.220* Returns 0 on success, < 0 upon failure.221*222* @layr: Pointer to the current layer the receive function223* is implemented for (this pointer).224* @ctrl: Control Command.225*/226int (*modemcmd) (struct cflayer *layr, enum caif_modemcmd ctrl);227228unsigned int id;229char name[CAIF_LAYER_NAME_SZ];230};231232/**233* layer_set_up() - Set the up pointer for a specified layer.234* @layr: Layer where up pointer shall be set.235* @above: Layer above.236*/237#define layer_set_up(layr, above) ((layr)->up = (struct cflayer *)(above))238239/**240* layer_set_dn() - Set the down pointer for a specified layer.241* @layr: Layer where down pointer shall be set.242* @below: Layer below.243*/244#define layer_set_dn(layr, below) ((layr)->dn = (struct cflayer *)(below))245246/**247* struct dev_info - Physical Device info information about physical layer.248* @dev: Pointer to native physical device.249* @id: Physical ID of the physical connection used by the250* logical CAIF connection. Used by service layers to251* identify their physical id to Caif MUX (CFMUXL)so252* that the MUX can add the correct physical ID to the253* packet.254*/255struct dev_info {256void *dev;257unsigned int id;258};259260/**261* struct caif_payload_info - Payload information embedded in packet (sk_buff).262*263* @dev_info: Information about the receiving device.264*265* @hdr_len: Header length, used to align pay load on 32bit boundary.266*267* @channel_id: Channel ID of the logical CAIF connection.268* Used by mux to insert channel id into the caif packet.269*/270struct caif_payload_info {271struct dev_info *dev_info;272unsigned short hdr_len;273unsigned short channel_id;274};275276#endif /* CAIF_LAYER_H_ */277278279