xref: /OK3568_Linux_fs/kernel/Documentation/networking/caif/linux_caif.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun.. include:: <isonum.txt>
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun==========
5*4882a593SmuzhiyunLinux CAIF
6*4882a593Smuzhiyun==========
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunCopyright |copy| ST-Ericsson AB 2010
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun:Author: Sjur Brendeland/ sjur.brandeland@stericsson.com
11*4882a593Smuzhiyun:License terms: GNU General Public License (GPL) version 2
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun
14*4882a593SmuzhiyunIntroduction
15*4882a593Smuzhiyun============
16*4882a593Smuzhiyun
17*4882a593SmuzhiyunCAIF is a MUX protocol used by ST-Ericsson cellular modems for
18*4882a593Smuzhiyuncommunication between Modem and host. The host processes can open virtual AT
19*4882a593Smuzhiyunchannels, initiate GPRS Data connections, Video channels and Utility Channels.
20*4882a593SmuzhiyunThe Utility Channels are general purpose pipes between modem and host.
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunST-Ericsson modems support a number of transports between modem
23*4882a593Smuzhiyunand host. Currently, UART and Loopback are available for Linux.
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun
26*4882a593SmuzhiyunArchitecture
27*4882a593Smuzhiyun============
28*4882a593Smuzhiyun
29*4882a593SmuzhiyunThe implementation of CAIF is divided into:
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun* CAIF Socket Layer and GPRS IP Interface.
32*4882a593Smuzhiyun* CAIF Core Protocol Implementation
33*4882a593Smuzhiyun* CAIF Link Layer, implemented as NET devices.
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun::
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun  RTNL
38*4882a593Smuzhiyun   !
39*4882a593Smuzhiyun   !	      +------+	 +------+
40*4882a593Smuzhiyun   !	     +------+!	+------+!
41*4882a593Smuzhiyun   !	     !	IP  !!	!Socket!!
42*4882a593Smuzhiyun   +-------> !interf!+	! API  !+	<- CAIF Client APIs
43*4882a593Smuzhiyun   !	     +------+	+------!
44*4882a593Smuzhiyun   !		!	    !
45*4882a593Smuzhiyun   !		+-----------+
46*4882a593Smuzhiyun   !		      !
47*4882a593Smuzhiyun   !		   +------+		<- CAIF Core Protocol
48*4882a593Smuzhiyun   !		   ! CAIF !
49*4882a593Smuzhiyun   !		   ! Core !
50*4882a593Smuzhiyun   !		   +------+
51*4882a593Smuzhiyun   !	   +----------!---------+
52*4882a593Smuzhiyun   !	   !	      !		!
53*4882a593Smuzhiyun   !	+------+   +-----+   +------+
54*4882a593Smuzhiyun   +--> ! HSI  !   ! TTY !   ! USB  !	<- Link Layer (Net Devices)
55*4882a593Smuzhiyun	+------+   +-----+   +------+
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun
59*4882a593SmuzhiyunImplementation
60*4882a593Smuzhiyun==============
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun
63*4882a593SmuzhiyunCAIF Core Protocol Layer
64*4882a593Smuzhiyun------------------------
65*4882a593Smuzhiyun
66*4882a593SmuzhiyunCAIF Core layer implements the CAIF protocol as defined by ST-Ericsson.
67*4882a593SmuzhiyunIt implements the CAIF protocol stack in a layered approach, where
68*4882a593Smuzhiyuneach layer described in the specification is implemented as a separate layer.
69*4882a593SmuzhiyunThe architecture is inspired by the design patterns "Protocol Layer" and
70*4882a593Smuzhiyun"Protocol Packet".
71*4882a593Smuzhiyun
72*4882a593SmuzhiyunCAIF structure
73*4882a593Smuzhiyun^^^^^^^^^^^^^^
74*4882a593Smuzhiyun
75*4882a593SmuzhiyunThe Core CAIF implementation contains:
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun      -	Simple implementation of CAIF.
78*4882a593Smuzhiyun      -	Layered architecture (a la Streams), each layer in the CAIF
79*4882a593Smuzhiyun	specification is implemented in a separate c-file.
80*4882a593Smuzhiyun      -	Clients must call configuration function to add PHY layer.
81*4882a593Smuzhiyun      -	Clients must implement CAIF layer to consume/produce
82*4882a593Smuzhiyun	CAIF payload with receive and transmit functions.
83*4882a593Smuzhiyun      -	Clients must call configuration function to add and connect the
84*4882a593Smuzhiyun	Client layer.
85*4882a593Smuzhiyun      - When receiving / transmitting CAIF Packets (cfpkt), ownership is passed
86*4882a593Smuzhiyun	to the called function (except for framing layers' receive function)
87*4882a593Smuzhiyun
88*4882a593SmuzhiyunLayered Architecture
89*4882a593Smuzhiyun====================
90*4882a593Smuzhiyun
91*4882a593SmuzhiyunThe CAIF protocol can be divided into two parts: Support functions and Protocol
92*4882a593SmuzhiyunImplementation. The support functions include:
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun      - CFPKT CAIF Packet. Implementation of CAIF Protocol Packet. The
95*4882a593Smuzhiyun	CAIF Packet has functions for creating, destroying and adding content
96*4882a593Smuzhiyun	and for adding/extracting header and trailers to protocol packets.
97*4882a593Smuzhiyun
98*4882a593SmuzhiyunThe CAIF Protocol implementation contains:
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun      - CFCNFG CAIF Configuration layer. Configures the CAIF Protocol
101*4882a593Smuzhiyun	Stack and provides a Client interface for adding Link-Layer and
102*4882a593Smuzhiyun	Driver interfaces on top of the CAIF Stack.
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun      - CFCTRL CAIF Control layer. Encodes and Decodes control messages
105*4882a593Smuzhiyun	such as enumeration and channel setup. Also matches request and
106*4882a593Smuzhiyun	response messages.
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun      - CFSERVL General CAIF Service Layer functionality; handles flow
109*4882a593Smuzhiyun	control and remote shutdown requests.
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun      - CFVEI CAIF VEI layer. Handles CAIF AT Channels on VEI (Virtual
112*4882a593Smuzhiyun	External Interface). This layer encodes/decodes VEI frames.
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun      - CFDGML CAIF Datagram layer. Handles CAIF Datagram layer (IP
115*4882a593Smuzhiyun	traffic), encodes/decodes Datagram frames.
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun      - CFMUX CAIF Mux layer. Handles multiplexing between multiple
118*4882a593Smuzhiyun	physical bearers and multiple channels such as VEI, Datagram, etc.
119*4882a593Smuzhiyun	The MUX keeps track of the existing CAIF Channels and
120*4882a593Smuzhiyun	Physical Instances and selects the appropriate instance based
121*4882a593Smuzhiyun	on Channel-Id and Physical-ID.
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun      - CFFRML CAIF Framing layer. Handles Framing i.e. Frame length
124*4882a593Smuzhiyun	and frame checksum.
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun      - CFSERL CAIF Serial layer. Handles concatenation/split of frames
127*4882a593Smuzhiyun	into CAIF Frames with correct length.
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun::
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun		    +---------+
132*4882a593Smuzhiyun		    | Config  |
133*4882a593Smuzhiyun		    | CFCNFG  |
134*4882a593Smuzhiyun		    +---------+
135*4882a593Smuzhiyun			 !
136*4882a593Smuzhiyun    +---------+	    +---------+	    +---------+
137*4882a593Smuzhiyun    |	AT    |	    | Control |	    | Datagram|
138*4882a593Smuzhiyun    | CFVEIL  |	    | CFCTRL  |	    | CFDGML  |
139*4882a593Smuzhiyun    +---------+	    +---------+	    +---------+
140*4882a593Smuzhiyun	   \_____________!______________/
141*4882a593Smuzhiyun			 !
142*4882a593Smuzhiyun		    +---------+
143*4882a593Smuzhiyun		    |	MUX   |
144*4882a593Smuzhiyun		    |	      |
145*4882a593Smuzhiyun		    +---------+
146*4882a593Smuzhiyun		    _____!_____
147*4882a593Smuzhiyun		   /	       \
148*4882a593Smuzhiyun	    +---------+	    +---------+
149*4882a593Smuzhiyun	    | CFFRML  |	    | CFFRML  |
150*4882a593Smuzhiyun	    | Framing |	    | Framing |
151*4882a593Smuzhiyun	    +---------+	    +---------+
152*4882a593Smuzhiyun		 !		!
153*4882a593Smuzhiyun	    +---------+	    +---------+
154*4882a593Smuzhiyun	    |	      |	    | Serial  |
155*4882a593Smuzhiyun	    |	      |	    | CFSERL  |
156*4882a593Smuzhiyun	    +---------+	    +---------+
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun
159*4882a593SmuzhiyunIn this layered approach the following "rules" apply.
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun      - All layers embed the same structure "struct cflayer"
162*4882a593Smuzhiyun      - A layer does not depend on any other layer's private data.
163*4882a593Smuzhiyun      - Layers are stacked by setting the pointers::
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun		  layer->up , layer->dn
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun      -	In order to send data upwards, each layer should do::
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun		 layer->up->receive(layer->up, packet);
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun      - In order to send data downwards, each layer should do::
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun		 layer->dn->transmit(layer->dn, packet);
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun
176*4882a593SmuzhiyunCAIF Socket and IP interface
177*4882a593Smuzhiyun============================
178*4882a593Smuzhiyun
179*4882a593SmuzhiyunThe IP interface and CAIF socket API are implemented on top of the
180*4882a593SmuzhiyunCAIF Core protocol. The IP Interface and CAIF socket have an instance of
181*4882a593Smuzhiyun'struct cflayer', just like the CAIF Core protocol stack.
182*4882a593SmuzhiyunNet device and Socket implement the 'receive()' function defined by
183*4882a593Smuzhiyun'struct cflayer', just like the rest of the CAIF stack. In this way, transmit and
184*4882a593Smuzhiyunreceive of packets is handled as by the rest of the layers: the 'dn->transmit()'
185*4882a593Smuzhiyunfunction is called in order to transmit data.
186*4882a593Smuzhiyun
187*4882a593SmuzhiyunConfiguration of Link Layer
188*4882a593Smuzhiyun---------------------------
189*4882a593SmuzhiyunThe Link Layer is implemented as Linux network devices (struct net_device).
190*4882a593SmuzhiyunPayload handling and registration is done using standard Linux mechanisms.
191*4882a593Smuzhiyun
192*4882a593SmuzhiyunThe CAIF Protocol relies on a loss-less link layer without implementing
193*4882a593Smuzhiyunretransmission. This implies that packet drops must not happen.
194*4882a593SmuzhiyunTherefore a flow-control mechanism is implemented where the physical
195*4882a593Smuzhiyuninterface can initiate flow stop for all CAIF Channels.
196