xref: /OK3568_Linux_fs/kernel/include/net/caif/caif_dev.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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_DEV_H_
8*4882a593Smuzhiyun #define CAIF_DEV_H_
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #include <net/caif/caif_layer.h>
11*4882a593Smuzhiyun #include <net/caif/cfcnfg.h>
12*4882a593Smuzhiyun #include <net/caif/caif_device.h>
13*4882a593Smuzhiyun #include <linux/caif/caif_socket.h>
14*4882a593Smuzhiyun #include <linux/if.h>
15*4882a593Smuzhiyun #include <linux/net.h>
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun /**
18*4882a593Smuzhiyun  * struct caif_param - CAIF parameters.
19*4882a593Smuzhiyun  * @size:	Length of data
20*4882a593Smuzhiyun  * @data:	Binary Data Blob
21*4882a593Smuzhiyun  */
22*4882a593Smuzhiyun struct caif_param {
23*4882a593Smuzhiyun 	u16  size;
24*4882a593Smuzhiyun 	u8   data[256];
25*4882a593Smuzhiyun };
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun /**
28*4882a593Smuzhiyun  * struct caif_connect_request - Request data for CAIF channel setup.
29*4882a593Smuzhiyun  * @protocol:		Type of CAIF protocol to use (at, datagram etc)
30*4882a593Smuzhiyun  * @sockaddr:		Socket address to connect.
31*4882a593Smuzhiyun  * @priority:		Priority of the connection.
32*4882a593Smuzhiyun  * @link_selector:	Link selector (high bandwidth or low latency)
33*4882a593Smuzhiyun  * @ifindex:		kernel index of the interface.
34*4882a593Smuzhiyun  * @param:		Connect Request parameters (CAIF_SO_REQ_PARAM).
35*4882a593Smuzhiyun  *
36*4882a593Smuzhiyun  * This struct is used when connecting a CAIF channel.
37*4882a593Smuzhiyun  * It contains all CAIF channel configuration options.
38*4882a593Smuzhiyun  */
39*4882a593Smuzhiyun struct caif_connect_request {
40*4882a593Smuzhiyun 	enum caif_protocol_type protocol;
41*4882a593Smuzhiyun 	struct sockaddr_caif sockaddr;
42*4882a593Smuzhiyun 	enum caif_channel_priority priority;
43*4882a593Smuzhiyun 	enum caif_link_selector link_selector;
44*4882a593Smuzhiyun 	int ifindex;
45*4882a593Smuzhiyun 	struct caif_param param;
46*4882a593Smuzhiyun };
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun /**
49*4882a593Smuzhiyun  * caif_connect_client - Connect a client to CAIF Core Stack.
50*4882a593Smuzhiyun  * @config:		Channel setup parameters, specifying what address
51*4882a593Smuzhiyun  *			to connect on the Modem.
52*4882a593Smuzhiyun  * @client_layer:	User implementation of client layer. This layer
53*4882a593Smuzhiyun  *			MUST have receive and control callback functions
54*4882a593Smuzhiyun  *			implemented.
55*4882a593Smuzhiyun  * @ifindex:		Link layer interface index used for this connection.
56*4882a593Smuzhiyun  * @headroom:		Head room needed by CAIF protocol.
57*4882a593Smuzhiyun  * @tailroom:		Tail room needed by CAIF protocol.
58*4882a593Smuzhiyun  *
59*4882a593Smuzhiyun  * This function connects a CAIF channel. The Client must implement
60*4882a593Smuzhiyun  * the struct cflayer. This layer represents the Client layer and holds
61*4882a593Smuzhiyun  * receive functions and control callback functions. Control callback
62*4882a593Smuzhiyun  * function will receive information about connect/disconnect responses,
63*4882a593Smuzhiyun  * flow control etc (see enum caif_control).
64*4882a593Smuzhiyun  * E.g. CAIF Socket will call this function for each socket it connects
65*4882a593Smuzhiyun  * and have one client_layer instance for each socket.
66*4882a593Smuzhiyun  */
67*4882a593Smuzhiyun int caif_connect_client(struct net *net,
68*4882a593Smuzhiyun 			struct caif_connect_request *conn_req,
69*4882a593Smuzhiyun 			struct cflayer *client_layer, int *ifindex,
70*4882a593Smuzhiyun 			int *headroom, int *tailroom);
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun /**
73*4882a593Smuzhiyun  * caif_disconnect_client - Disconnects a client from the CAIF stack.
74*4882a593Smuzhiyun  *
75*4882a593Smuzhiyun  * @client_layer: Client layer to be disconnected.
76*4882a593Smuzhiyun  */
77*4882a593Smuzhiyun int caif_disconnect_client(struct net *net, struct cflayer *client_layer);
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun /**
81*4882a593Smuzhiyun  * caif_client_register_refcnt - register ref-count functions provided by client.
82*4882a593Smuzhiyun  *
83*4882a593Smuzhiyun  * @adapt_layer: Client layer using CAIF Stack.
84*4882a593Smuzhiyun  * @hold:	Function provided by client layer increasing ref-count
85*4882a593Smuzhiyun  * @put:	Function provided by client layer decreasing ref-count
86*4882a593Smuzhiyun  *
87*4882a593Smuzhiyun  * Client of the CAIF Stack must register functions for reference counting.
88*4882a593Smuzhiyun  * These functions are called by the CAIF Stack for every upstream packet,
89*4882a593Smuzhiyun  * and must therefore be implemented efficiently.
90*4882a593Smuzhiyun  *
91*4882a593Smuzhiyun  * Client should call caif_free_client when reference count degrease to zero.
92*4882a593Smuzhiyun  */
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun void caif_client_register_refcnt(struct cflayer *adapt_layer,
95*4882a593Smuzhiyun 					void (*hold)(struct cflayer *lyr),
96*4882a593Smuzhiyun 					void (*put)(struct cflayer *lyr));
97*4882a593Smuzhiyun /**
98*4882a593Smuzhiyun  * caif_free_client - Free memory used to manage the client in the CAIF Stack.
99*4882a593Smuzhiyun  *
100*4882a593Smuzhiyun  * @client_layer: Client layer to be removed.
101*4882a593Smuzhiyun  *
102*4882a593Smuzhiyun  * This function must be called from client layer in order to free memory.
103*4882a593Smuzhiyun  * Caller must guarantee that no packets are in flight upstream when calling
104*4882a593Smuzhiyun  * this function.
105*4882a593Smuzhiyun  */
106*4882a593Smuzhiyun void caif_free_client(struct cflayer *adap_layer);
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun /**
109*4882a593Smuzhiyun  * struct caif_enroll_dev - Enroll a net-device as a CAIF Link layer
110*4882a593Smuzhiyun  * @dev:		Network device to enroll.
111*4882a593Smuzhiyun  * @caifdev:		Configuration information from CAIF Link Layer
112*4882a593Smuzhiyun  * @link_support:	Link layer support layer
113*4882a593Smuzhiyun  * @head_room:		Head room needed by link support layer
114*4882a593Smuzhiyun  * @layer:		Lowest layer in CAIF stack
115*4882a593Smuzhiyun  * @rcv_fun:		Receive function for CAIF stack.
116*4882a593Smuzhiyun  *
117*4882a593Smuzhiyun  * This function enroll a CAIF link layer into CAIF Stack and
118*4882a593Smuzhiyun  * expects the interface to be able to handle CAIF payload.
119*4882a593Smuzhiyun  * The link_support layer is used to add any Link Layer specific
120*4882a593Smuzhiyun  * framing.
121*4882a593Smuzhiyun  */
122*4882a593Smuzhiyun int caif_enroll_dev(struct net_device *dev, struct caif_dev_common *caifdev,
123*4882a593Smuzhiyun 			struct cflayer *link_support, int head_room,
124*4882a593Smuzhiyun 			struct cflayer **layer, int (**rcv_func)(
125*4882a593Smuzhiyun 				struct sk_buff *, struct net_device *,
126*4882a593Smuzhiyun 				struct packet_type *, struct net_device *));
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun #endif /* CAIF_DEV_H_ */
129