/*1* Copyright (C) ST-Ericsson AB 20102* Author: Sjur Brendeland / [email protected]3* License terms: GNU General Public License (GPL) version 24*/56#ifndef CAIF_LAYER_H_7#define CAIF_LAYER_H_89#include <linux/list.h>1011struct cflayer;12struct cfpkt;13struct cfpktq;14struct caif_payload_info;15struct caif_packet_funcs;1617#define CAIF_LAYER_NAME_SZ 161819/**20* caif_assert() - Assert function for CAIF.21* @assert: expression to evaluate.22*23* This function will print a error message and a do WARN_ON if the24* assertion failes. Normally this will do a stack up at the current location.25*/26#define caif_assert(assert) \27do { \28if (!(assert)) { \29pr_err("caif:Assert detected:'%s'\n", #assert); \30WARN_ON(!(assert)); \31} \32} while (0)3334/**35* enum caif_ctrlcmd - CAIF Stack Control Signaling sent in layer.ctrlcmd().36*37* @CAIF_CTRLCMD_FLOW_OFF_IND: Flow Control is OFF, transmit function38* should stop sending data39*40* @CAIF_CTRLCMD_FLOW_ON_IND: Flow Control is ON, transmit function41* can start sending data42*43* @CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND: Remote end modem has decided to close44* down channel45*46* @CAIF_CTRLCMD_INIT_RSP: Called initially when the layer below47* has finished initialization48*49* @CAIF_CTRLCMD_DEINIT_RSP: Called when de-initialization is50* complete51*52* @CAIF_CTRLCMD_INIT_FAIL_RSP: Called if initialization fails53*54* @_CAIF_CTRLCMD_PHYIF_FLOW_OFF_IND: CAIF Link layer temporarily cannot55* send more packets.56* @_CAIF_CTRLCMD_PHYIF_FLOW_ON_IND: Called if CAIF Link layer is able57* to send packets again.58* @_CAIF_CTRLCMD_PHYIF_DOWN_IND: Called if CAIF Link layer is going59* down.60*61* These commands are sent upwards in the CAIF stack to the CAIF Client.62* They are used for signaling originating from the modem or CAIF Link Layer.63* These are either responses (*_RSP) or events (*_IND).64*/65enum caif_ctrlcmd {66CAIF_CTRLCMD_FLOW_OFF_IND,67CAIF_CTRLCMD_FLOW_ON_IND,68CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND,69CAIF_CTRLCMD_INIT_RSP,70CAIF_CTRLCMD_DEINIT_RSP,71CAIF_CTRLCMD_INIT_FAIL_RSP,72_CAIF_CTRLCMD_PHYIF_FLOW_OFF_IND,73_CAIF_CTRLCMD_PHYIF_FLOW_ON_IND,74_CAIF_CTRLCMD_PHYIF_DOWN_IND,75};7677/**78* enum caif_modemcmd - Modem Control Signaling, sent from CAIF Client79* to the CAIF Link Layer or modem.80*81* @CAIF_MODEMCMD_FLOW_ON_REQ: Flow Control is ON, transmit function82* can start sending data.83*84* @CAIF_MODEMCMD_FLOW_OFF_REQ: Flow Control is OFF, transmit function85* should stop sending data.86*87* @_CAIF_MODEMCMD_PHYIF_USEFULL: Notify physical layer that it is in use88*89* @_CAIF_MODEMCMD_PHYIF_USELESS: Notify physical layer that it is90* no longer in use.91*92* These are requests sent 'downwards' in the stack.93* Flow ON, OFF can be indicated to the modem.94*/95enum caif_modemcmd {96CAIF_MODEMCMD_FLOW_ON_REQ = 0,97CAIF_MODEMCMD_FLOW_OFF_REQ = 1,98_CAIF_MODEMCMD_PHYIF_USEFULL = 3,99_CAIF_MODEMCMD_PHYIF_USELESS = 4100};101102/**103* enum caif_direction - CAIF Packet Direction.104* Indicate if a packet is to be sent out or to be received in.105* @CAIF_DIR_IN: Incoming packet received.106* @CAIF_DIR_OUT: Outgoing packet to be transmitted.107*/108enum caif_direction {109CAIF_DIR_IN = 0,110CAIF_DIR_OUT = 1111};112113/**114* struct cflayer - CAIF Stack layer.115* Defines the framework for the CAIF Core Stack.116* @up: Pointer up to the layer above.117* @dn: Pointer down to the layer below.118* @node: List node used when layer participate in a list.119* @receive: Packet receive function.120* @transmit: Packet transmit funciton.121* @ctrlcmd: Used for control signalling upwards in the stack.122* @modemcmd: Used for control signaling downwards in the stack.123* @prio: Priority of this layer.124* @id: The identity of this layer125* @type: The type of this layer126* @name: Name of the layer.127*128* This structure defines the layered structure in CAIF.129*130* It defines CAIF layering structure, used by all CAIF Layers and the131* layers interfacing CAIF.132*133* In order to integrate with CAIF an adaptation layer on top of the CAIF stack134* and PHY layer below the CAIF stack135* must be implemented. These layer must follow the design principles below.136*137* Principles for layering of protocol layers:138* - All layers must use this structure. If embedding it, then place this139* structure first in the layer specific structure.140*141* - Each layer should not depend on any others layer's private data.142*143* - In order to send data upwards do144* layer->up->receive(layer->up, packet);145*146* - In order to send data downwards do147* layer->dn->transmit(layer->dn, info, packet);148*/149struct cflayer {150struct cflayer *up;151struct cflayer *dn;152struct list_head node;153154/*155* receive() - Receive Function (non-blocking).156* Contract: Each layer must implement a receive function passing the157* CAIF packets upwards in the stack.158* Packet handling rules:159* - The CAIF packet (cfpkt) ownership is passed to the160* called receive function. This means that the the161* packet cannot be accessed after passing it to the162* above layer using up->receive().163*164* - If parsing of the packet fails, the packet must be165* destroyed and negative error code returned166* from the function.167* EXCEPTION: If the framing layer (cffrml) returns168* -EILSEQ, the packet is not freed.169*170* - If parsing succeeds (and above layers return OK) then171* the function must return a value >= 0.172*173* Returns result < 0 indicates an error, 0 or positive value174* indicates success.175*176* @layr: Pointer to the current layer the receive function is177* implemented for (this pointer).178* @cfpkt: Pointer to CaifPacket to be handled.179*/180int (*receive)(struct cflayer *layr, struct cfpkt *cfpkt);181182/*183* transmit() - Transmit Function (non-blocking).184* Contract: Each layer must implement a transmit function passing the185* CAIF packet downwards in the stack.186* Packet handling rules:187* - The CAIF packet (cfpkt) ownership is passed to the188* transmit function. This means that the the packet189* cannot be accessed after passing it to the below190* layer using dn->transmit().191*192* - Upon error the packet ownership is still passed on,193* so the packet shall be freed where error is detected.194* Callers of the transmit function shall not free packets,195* but errors shall be returned.196*197* - Return value less than zero means error, zero or198* greater than zero means OK.199*200* Returns result < 0 indicates an error, 0 or positive value201* indicates success.202*203* @layr: Pointer to the current layer the receive function204* isimplemented for (this pointer).205* @cfpkt: Pointer to CaifPacket to be handled.206*/207int (*transmit) (struct cflayer *layr, struct cfpkt *cfpkt);208209/*210* cttrlcmd() - Control Function upwards in CAIF Stack (non-blocking).211* Used for signaling responses (CAIF_CTRLCMD_*_RSP)212* and asynchronous events from the modem (CAIF_CTRLCMD_*_IND)213*214* @layr: Pointer to the current layer the receive function215* is implemented for (this pointer).216* @ctrl: Control Command.217*/218void (*ctrlcmd) (struct cflayer *layr, enum caif_ctrlcmd ctrl,219int phyid);220221/*222* modemctrl() - Control Function used for controlling the modem.223* Used to signal down-wards in the CAIF stack.224* Returns 0 on success, < 0 upon failure.225*226* @layr: Pointer to the current layer the receive function227* is implemented for (this pointer).228* @ctrl: Control Command.229*/230int (*modemcmd) (struct cflayer *layr, enum caif_modemcmd ctrl);231232unsigned short prio;233unsigned int id;234unsigned int type;235char name[CAIF_LAYER_NAME_SZ];236};237238/**239* layer_set_up() - Set the up pointer for a specified layer.240* @layr: Layer where up pointer shall be set.241* @above: Layer above.242*/243#define layer_set_up(layr, above) ((layr)->up = (struct cflayer *)(above))244245/**246* layer_set_dn() - Set the down pointer for a specified layer.247* @layr: Layer where down pointer shall be set.248* @below: Layer below.249*/250#define layer_set_dn(layr, below) ((layr)->dn = (struct cflayer *)(below))251252/**253* struct dev_info - Physical Device info information about physical layer.254* @dev: Pointer to native physical device.255* @id: Physical ID of the physical connection used by the256* logical CAIF connection. Used by service layers to257* identify their physical id to Caif MUX (CFMUXL)so258* that the MUX can add the correct physical ID to the259* packet.260*/261struct dev_info {262void *dev;263unsigned int id;264};265266/**267* struct caif_payload_info - Payload information embedded in packet (sk_buff).268*269* @dev_info: Information about the receiving device.270*271* @hdr_len: Header length, used to align pay load on 32bit boundary.272*273* @channel_id: Channel ID of the logical CAIF connection.274* Used by mux to insert channel id into the caif packet.275*/276struct caif_payload_info {277struct dev_info *dev_info;278unsigned short hdr_len;279unsigned short channel_id;280};281282#endif /* CAIF_LAYER_H_ */283284285