1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * Copyright (C) ST-Ericsson AB 2010 4*4882a593Smuzhiyun * Author: Sjur Brendeland 5*4882a593Smuzhiyun */ 6*4882a593Smuzhiyun 7*4882a593Smuzhiyun #ifndef CAIF_LAYER_H_ 8*4882a593Smuzhiyun #define CAIF_LAYER_H_ 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun #include <linux/list.h> 11*4882a593Smuzhiyun 12*4882a593Smuzhiyun struct cflayer; 13*4882a593Smuzhiyun struct cfpkt; 14*4882a593Smuzhiyun struct cfpktq; 15*4882a593Smuzhiyun struct caif_payload_info; 16*4882a593Smuzhiyun struct caif_packet_funcs; 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun #define CAIF_LAYER_NAME_SZ 16 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun /** 21*4882a593Smuzhiyun * caif_assert() - Assert function for CAIF. 22*4882a593Smuzhiyun * @assert: expression to evaluate. 23*4882a593Smuzhiyun * 24*4882a593Smuzhiyun * This function will print a error message and a do WARN_ON if the 25*4882a593Smuzhiyun * assertion failes. Normally this will do a stack up at the current location. 26*4882a593Smuzhiyun */ 27*4882a593Smuzhiyun #define caif_assert(assert) \ 28*4882a593Smuzhiyun do { \ 29*4882a593Smuzhiyun if (!(assert)) { \ 30*4882a593Smuzhiyun pr_err("caif:Assert detected:'%s'\n", #assert); \ 31*4882a593Smuzhiyun WARN_ON(!(assert)); \ 32*4882a593Smuzhiyun } \ 33*4882a593Smuzhiyun } while (0) 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun /** 36*4882a593Smuzhiyun * enum caif_ctrlcmd - CAIF Stack Control Signaling sent in layer.ctrlcmd(). 37*4882a593Smuzhiyun * 38*4882a593Smuzhiyun * @CAIF_CTRLCMD_FLOW_OFF_IND: Flow Control is OFF, transmit function 39*4882a593Smuzhiyun * should stop sending data 40*4882a593Smuzhiyun * 41*4882a593Smuzhiyun * @CAIF_CTRLCMD_FLOW_ON_IND: Flow Control is ON, transmit function 42*4882a593Smuzhiyun * can start sending data 43*4882a593Smuzhiyun * 44*4882a593Smuzhiyun * @CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND: Remote end modem has decided to close 45*4882a593Smuzhiyun * down channel 46*4882a593Smuzhiyun * 47*4882a593Smuzhiyun * @CAIF_CTRLCMD_INIT_RSP: Called initially when the layer below 48*4882a593Smuzhiyun * has finished initialization 49*4882a593Smuzhiyun * 50*4882a593Smuzhiyun * @CAIF_CTRLCMD_DEINIT_RSP: Called when de-initialization is 51*4882a593Smuzhiyun * complete 52*4882a593Smuzhiyun * 53*4882a593Smuzhiyun * @CAIF_CTRLCMD_INIT_FAIL_RSP: Called if initialization fails 54*4882a593Smuzhiyun * 55*4882a593Smuzhiyun * @_CAIF_CTRLCMD_PHYIF_FLOW_OFF_IND: CAIF Link layer temporarily cannot 56*4882a593Smuzhiyun * send more packets. 57*4882a593Smuzhiyun * @_CAIF_CTRLCMD_PHYIF_FLOW_ON_IND: Called if CAIF Link layer is able 58*4882a593Smuzhiyun * to send packets again. 59*4882a593Smuzhiyun * @_CAIF_CTRLCMD_PHYIF_DOWN_IND: Called if CAIF Link layer is going 60*4882a593Smuzhiyun * down. 61*4882a593Smuzhiyun * 62*4882a593Smuzhiyun * These commands are sent upwards in the CAIF stack to the CAIF Client. 63*4882a593Smuzhiyun * They are used for signaling originating from the modem or CAIF Link Layer. 64*4882a593Smuzhiyun * These are either responses (*_RSP) or events (*_IND). 65*4882a593Smuzhiyun */ 66*4882a593Smuzhiyun enum caif_ctrlcmd { 67*4882a593Smuzhiyun CAIF_CTRLCMD_FLOW_OFF_IND, 68*4882a593Smuzhiyun CAIF_CTRLCMD_FLOW_ON_IND, 69*4882a593Smuzhiyun CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND, 70*4882a593Smuzhiyun CAIF_CTRLCMD_INIT_RSP, 71*4882a593Smuzhiyun CAIF_CTRLCMD_DEINIT_RSP, 72*4882a593Smuzhiyun CAIF_CTRLCMD_INIT_FAIL_RSP, 73*4882a593Smuzhiyun _CAIF_CTRLCMD_PHYIF_FLOW_OFF_IND, 74*4882a593Smuzhiyun _CAIF_CTRLCMD_PHYIF_FLOW_ON_IND, 75*4882a593Smuzhiyun _CAIF_CTRLCMD_PHYIF_DOWN_IND, 76*4882a593Smuzhiyun }; 77*4882a593Smuzhiyun 78*4882a593Smuzhiyun /** 79*4882a593Smuzhiyun * enum caif_modemcmd - Modem Control Signaling, sent from CAIF Client 80*4882a593Smuzhiyun * to the CAIF Link Layer or modem. 81*4882a593Smuzhiyun * 82*4882a593Smuzhiyun * @CAIF_MODEMCMD_FLOW_ON_REQ: Flow Control is ON, transmit function 83*4882a593Smuzhiyun * can start sending data. 84*4882a593Smuzhiyun * 85*4882a593Smuzhiyun * @CAIF_MODEMCMD_FLOW_OFF_REQ: Flow Control is OFF, transmit function 86*4882a593Smuzhiyun * should stop sending data. 87*4882a593Smuzhiyun * 88*4882a593Smuzhiyun * @_CAIF_MODEMCMD_PHYIF_USEFULL: Notify physical layer that it is in use 89*4882a593Smuzhiyun * 90*4882a593Smuzhiyun * @_CAIF_MODEMCMD_PHYIF_USELESS: Notify physical layer that it is 91*4882a593Smuzhiyun * no longer in use. 92*4882a593Smuzhiyun * 93*4882a593Smuzhiyun * These are requests sent 'downwards' in the stack. 94*4882a593Smuzhiyun * Flow ON, OFF can be indicated to the modem. 95*4882a593Smuzhiyun */ 96*4882a593Smuzhiyun enum caif_modemcmd { 97*4882a593Smuzhiyun CAIF_MODEMCMD_FLOW_ON_REQ = 0, 98*4882a593Smuzhiyun CAIF_MODEMCMD_FLOW_OFF_REQ = 1, 99*4882a593Smuzhiyun _CAIF_MODEMCMD_PHYIF_USEFULL = 3, 100*4882a593Smuzhiyun _CAIF_MODEMCMD_PHYIF_USELESS = 4 101*4882a593Smuzhiyun }; 102*4882a593Smuzhiyun 103*4882a593Smuzhiyun /** 104*4882a593Smuzhiyun * enum caif_direction - CAIF Packet Direction. 105*4882a593Smuzhiyun * Indicate if a packet is to be sent out or to be received in. 106*4882a593Smuzhiyun * @CAIF_DIR_IN: Incoming packet received. 107*4882a593Smuzhiyun * @CAIF_DIR_OUT: Outgoing packet to be transmitted. 108*4882a593Smuzhiyun */ 109*4882a593Smuzhiyun enum caif_direction { 110*4882a593Smuzhiyun CAIF_DIR_IN = 0, 111*4882a593Smuzhiyun CAIF_DIR_OUT = 1 112*4882a593Smuzhiyun }; 113*4882a593Smuzhiyun 114*4882a593Smuzhiyun /** 115*4882a593Smuzhiyun * struct cflayer - CAIF Stack layer. 116*4882a593Smuzhiyun * Defines the framework for the CAIF Core Stack. 117*4882a593Smuzhiyun * @up: Pointer up to the layer above. 118*4882a593Smuzhiyun * @dn: Pointer down to the layer below. 119*4882a593Smuzhiyun * @node: List node used when layer participate in a list. 120*4882a593Smuzhiyun * @receive: Packet receive function. 121*4882a593Smuzhiyun * @transmit: Packet transmit funciton. 122*4882a593Smuzhiyun * @ctrlcmd: Used for control signalling upwards in the stack. 123*4882a593Smuzhiyun * @modemcmd: Used for control signaling downwards in the stack. 124*4882a593Smuzhiyun * @id: The identity of this layer 125*4882a593Smuzhiyun * @name: Name of the layer. 126*4882a593Smuzhiyun * 127*4882a593Smuzhiyun * This structure defines the layered structure in CAIF. 128*4882a593Smuzhiyun * 129*4882a593Smuzhiyun * It defines CAIF layering structure, used by all CAIF Layers and the 130*4882a593Smuzhiyun * layers interfacing CAIF. 131*4882a593Smuzhiyun * 132*4882a593Smuzhiyun * In order to integrate with CAIF an adaptation layer on top of the CAIF stack 133*4882a593Smuzhiyun * and PHY layer below the CAIF stack 134*4882a593Smuzhiyun * must be implemented. These layer must follow the design principles below. 135*4882a593Smuzhiyun * 136*4882a593Smuzhiyun * Principles for layering of protocol layers: 137*4882a593Smuzhiyun * - All layers must use this structure. If embedding it, then place this 138*4882a593Smuzhiyun * structure first in the layer specific structure. 139*4882a593Smuzhiyun * 140*4882a593Smuzhiyun * - Each layer should not depend on any others layer's private data. 141*4882a593Smuzhiyun * 142*4882a593Smuzhiyun * - In order to send data upwards do 143*4882a593Smuzhiyun * layer->up->receive(layer->up, packet); 144*4882a593Smuzhiyun * 145*4882a593Smuzhiyun * - In order to send data downwards do 146*4882a593Smuzhiyun * layer->dn->transmit(layer->dn, info, packet); 147*4882a593Smuzhiyun */ 148*4882a593Smuzhiyun struct cflayer { 149*4882a593Smuzhiyun struct cflayer *up; 150*4882a593Smuzhiyun struct cflayer *dn; 151*4882a593Smuzhiyun struct list_head node; 152*4882a593Smuzhiyun 153*4882a593Smuzhiyun /* 154*4882a593Smuzhiyun * receive() - Receive Function (non-blocking). 155*4882a593Smuzhiyun * Contract: Each layer must implement a receive function passing the 156*4882a593Smuzhiyun * CAIF packets upwards in the stack. 157*4882a593Smuzhiyun * Packet handling rules: 158*4882a593Smuzhiyun * - The CAIF packet (cfpkt) ownership is passed to the 159*4882a593Smuzhiyun * called receive function. This means that the 160*4882a593Smuzhiyun * packet cannot be accessed after passing it to the 161*4882a593Smuzhiyun * above layer using up->receive(). 162*4882a593Smuzhiyun * 163*4882a593Smuzhiyun * - If parsing of the packet fails, the packet must be 164*4882a593Smuzhiyun * destroyed and negative error code returned 165*4882a593Smuzhiyun * from the function. 166*4882a593Smuzhiyun * EXCEPTION: If the framing layer (cffrml) returns 167*4882a593Smuzhiyun * -EILSEQ, the packet is not freed. 168*4882a593Smuzhiyun * 169*4882a593Smuzhiyun * - If parsing succeeds (and above layers return OK) then 170*4882a593Smuzhiyun * the function must return a value >= 0. 171*4882a593Smuzhiyun * 172*4882a593Smuzhiyun * Returns result < 0 indicates an error, 0 or positive value 173*4882a593Smuzhiyun * indicates success. 174*4882a593Smuzhiyun * 175*4882a593Smuzhiyun * @layr: Pointer to the current layer the receive function is 176*4882a593Smuzhiyun * implemented for (this pointer). 177*4882a593Smuzhiyun * @cfpkt: Pointer to CaifPacket to be handled. 178*4882a593Smuzhiyun */ 179*4882a593Smuzhiyun int (*receive)(struct cflayer *layr, struct cfpkt *cfpkt); 180*4882a593Smuzhiyun 181*4882a593Smuzhiyun /* 182*4882a593Smuzhiyun * transmit() - Transmit Function (non-blocking). 183*4882a593Smuzhiyun * Contract: Each layer must implement a transmit function passing the 184*4882a593Smuzhiyun * CAIF packet downwards in the stack. 185*4882a593Smuzhiyun * Packet handling rules: 186*4882a593Smuzhiyun * - The CAIF packet (cfpkt) ownership is passed to the 187*4882a593Smuzhiyun * transmit function. This means that the packet 188*4882a593Smuzhiyun * cannot be accessed after passing it to the below 189*4882a593Smuzhiyun * layer using dn->transmit(). 190*4882a593Smuzhiyun * 191*4882a593Smuzhiyun * - Upon error the packet ownership is still passed on, 192*4882a593Smuzhiyun * so the packet shall be freed where error is detected. 193*4882a593Smuzhiyun * Callers of the transmit function shall not free packets, 194*4882a593Smuzhiyun * but errors shall be returned. 195*4882a593Smuzhiyun * 196*4882a593Smuzhiyun * - Return value less than zero means error, zero or 197*4882a593Smuzhiyun * greater than zero means OK. 198*4882a593Smuzhiyun * 199*4882a593Smuzhiyun * Returns result < 0 indicates an error, 0 or positive value 200*4882a593Smuzhiyun * indicates success. 201*4882a593Smuzhiyun * 202*4882a593Smuzhiyun * @layr: Pointer to the current layer the receive function 203*4882a593Smuzhiyun * isimplemented for (this pointer). 204*4882a593Smuzhiyun * @cfpkt: Pointer to CaifPacket to be handled. 205*4882a593Smuzhiyun */ 206*4882a593Smuzhiyun int (*transmit) (struct cflayer *layr, struct cfpkt *cfpkt); 207*4882a593Smuzhiyun 208*4882a593Smuzhiyun /* 209*4882a593Smuzhiyun * cttrlcmd() - Control Function upwards in CAIF Stack (non-blocking). 210*4882a593Smuzhiyun * Used for signaling responses (CAIF_CTRLCMD_*_RSP) 211*4882a593Smuzhiyun * and asynchronous events from the modem (CAIF_CTRLCMD_*_IND) 212*4882a593Smuzhiyun * 213*4882a593Smuzhiyun * @layr: Pointer to the current layer the receive function 214*4882a593Smuzhiyun * is implemented for (this pointer). 215*4882a593Smuzhiyun * @ctrl: Control Command. 216*4882a593Smuzhiyun */ 217*4882a593Smuzhiyun void (*ctrlcmd) (struct cflayer *layr, enum caif_ctrlcmd ctrl, 218*4882a593Smuzhiyun int phyid); 219*4882a593Smuzhiyun 220*4882a593Smuzhiyun /* 221*4882a593Smuzhiyun * modemctrl() - Control Function used for controlling the modem. 222*4882a593Smuzhiyun * Used to signal down-wards in the CAIF stack. 223*4882a593Smuzhiyun * Returns 0 on success, < 0 upon failure. 224*4882a593Smuzhiyun * 225*4882a593Smuzhiyun * @layr: Pointer to the current layer the receive function 226*4882a593Smuzhiyun * is implemented for (this pointer). 227*4882a593Smuzhiyun * @ctrl: Control Command. 228*4882a593Smuzhiyun */ 229*4882a593Smuzhiyun int (*modemcmd) (struct cflayer *layr, enum caif_modemcmd ctrl); 230*4882a593Smuzhiyun 231*4882a593Smuzhiyun unsigned int id; 232*4882a593Smuzhiyun char name[CAIF_LAYER_NAME_SZ]; 233*4882a593Smuzhiyun }; 234*4882a593Smuzhiyun 235*4882a593Smuzhiyun /** 236*4882a593Smuzhiyun * layer_set_up() - Set the up pointer for a specified layer. 237*4882a593Smuzhiyun * @layr: Layer where up pointer shall be set. 238*4882a593Smuzhiyun * @above: Layer above. 239*4882a593Smuzhiyun */ 240*4882a593Smuzhiyun #define layer_set_up(layr, above) ((layr)->up = (struct cflayer *)(above)) 241*4882a593Smuzhiyun 242*4882a593Smuzhiyun /** 243*4882a593Smuzhiyun * layer_set_dn() - Set the down pointer for a specified layer. 244*4882a593Smuzhiyun * @layr: Layer where down pointer shall be set. 245*4882a593Smuzhiyun * @below: Layer below. 246*4882a593Smuzhiyun */ 247*4882a593Smuzhiyun #define layer_set_dn(layr, below) ((layr)->dn = (struct cflayer *)(below)) 248*4882a593Smuzhiyun 249*4882a593Smuzhiyun /** 250*4882a593Smuzhiyun * struct dev_info - Physical Device info information about physical layer. 251*4882a593Smuzhiyun * @dev: Pointer to native physical device. 252*4882a593Smuzhiyun * @id: Physical ID of the physical connection used by the 253*4882a593Smuzhiyun * logical CAIF connection. Used by service layers to 254*4882a593Smuzhiyun * identify their physical id to Caif MUX (CFMUXL)so 255*4882a593Smuzhiyun * that the MUX can add the correct physical ID to the 256*4882a593Smuzhiyun * packet. 257*4882a593Smuzhiyun */ 258*4882a593Smuzhiyun struct dev_info { 259*4882a593Smuzhiyun void *dev; 260*4882a593Smuzhiyun unsigned int id; 261*4882a593Smuzhiyun }; 262*4882a593Smuzhiyun 263*4882a593Smuzhiyun /** 264*4882a593Smuzhiyun * struct caif_payload_info - Payload information embedded in packet (sk_buff). 265*4882a593Smuzhiyun * 266*4882a593Smuzhiyun * @dev_info: Information about the receiving device. 267*4882a593Smuzhiyun * 268*4882a593Smuzhiyun * @hdr_len: Header length, used to align pay load on 32bit boundary. 269*4882a593Smuzhiyun * 270*4882a593Smuzhiyun * @channel_id: Channel ID of the logical CAIF connection. 271*4882a593Smuzhiyun * Used by mux to insert channel id into the caif packet. 272*4882a593Smuzhiyun */ 273*4882a593Smuzhiyun struct caif_payload_info { 274*4882a593Smuzhiyun struct dev_info *dev_info; 275*4882a593Smuzhiyun unsigned short hdr_len; 276*4882a593Smuzhiyun unsigned short channel_id; 277*4882a593Smuzhiyun }; 278*4882a593Smuzhiyun 279*4882a593Smuzhiyun #endif /* CAIF_LAYER_H_ */ 280