18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) ST-Ericsson AB 2010
48c2ecf20Sopenharmony_ci * Author:	Sjur Brendeland
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifndef CAIF_DEV_H_
88c2ecf20Sopenharmony_ci#define CAIF_DEV_H_
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <net/caif/caif_layer.h>
118c2ecf20Sopenharmony_ci#include <net/caif/cfcnfg.h>
128c2ecf20Sopenharmony_ci#include <net/caif/caif_device.h>
138c2ecf20Sopenharmony_ci#include <linux/caif/caif_socket.h>
148c2ecf20Sopenharmony_ci#include <linux/if.h>
158c2ecf20Sopenharmony_ci#include <linux/net.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/**
188c2ecf20Sopenharmony_ci * struct caif_param - CAIF parameters.
198c2ecf20Sopenharmony_ci * @size:	Length of data
208c2ecf20Sopenharmony_ci * @data:	Binary Data Blob
218c2ecf20Sopenharmony_ci */
228c2ecf20Sopenharmony_cistruct caif_param {
238c2ecf20Sopenharmony_ci	u16  size;
248c2ecf20Sopenharmony_ci	u8   data[256];
258c2ecf20Sopenharmony_ci};
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/**
288c2ecf20Sopenharmony_ci * struct caif_connect_request - Request data for CAIF channel setup.
298c2ecf20Sopenharmony_ci * @protocol:		Type of CAIF protocol to use (at, datagram etc)
308c2ecf20Sopenharmony_ci * @sockaddr:		Socket address to connect.
318c2ecf20Sopenharmony_ci * @priority:		Priority of the connection.
328c2ecf20Sopenharmony_ci * @link_selector:	Link selector (high bandwidth or low latency)
338c2ecf20Sopenharmony_ci * @ifindex:		kernel index of the interface.
348c2ecf20Sopenharmony_ci * @param:		Connect Request parameters (CAIF_SO_REQ_PARAM).
358c2ecf20Sopenharmony_ci *
368c2ecf20Sopenharmony_ci * This struct is used when connecting a CAIF channel.
378c2ecf20Sopenharmony_ci * It contains all CAIF channel configuration options.
388c2ecf20Sopenharmony_ci */
398c2ecf20Sopenharmony_cistruct caif_connect_request {
408c2ecf20Sopenharmony_ci	enum caif_protocol_type protocol;
418c2ecf20Sopenharmony_ci	struct sockaddr_caif sockaddr;
428c2ecf20Sopenharmony_ci	enum caif_channel_priority priority;
438c2ecf20Sopenharmony_ci	enum caif_link_selector link_selector;
448c2ecf20Sopenharmony_ci	int ifindex;
458c2ecf20Sopenharmony_ci	struct caif_param param;
468c2ecf20Sopenharmony_ci};
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/**
498c2ecf20Sopenharmony_ci * caif_connect_client - Connect a client to CAIF Core Stack.
508c2ecf20Sopenharmony_ci * @config:		Channel setup parameters, specifying what address
518c2ecf20Sopenharmony_ci *			to connect on the Modem.
528c2ecf20Sopenharmony_ci * @client_layer:	User implementation of client layer. This layer
538c2ecf20Sopenharmony_ci *			MUST have receive and control callback functions
548c2ecf20Sopenharmony_ci *			implemented.
558c2ecf20Sopenharmony_ci * @ifindex:		Link layer interface index used for this connection.
568c2ecf20Sopenharmony_ci * @headroom:		Head room needed by CAIF protocol.
578c2ecf20Sopenharmony_ci * @tailroom:		Tail room needed by CAIF protocol.
588c2ecf20Sopenharmony_ci *
598c2ecf20Sopenharmony_ci * This function connects a CAIF channel. The Client must implement
608c2ecf20Sopenharmony_ci * the struct cflayer. This layer represents the Client layer and holds
618c2ecf20Sopenharmony_ci * receive functions and control callback functions. Control callback
628c2ecf20Sopenharmony_ci * function will receive information about connect/disconnect responses,
638c2ecf20Sopenharmony_ci * flow control etc (see enum caif_control).
648c2ecf20Sopenharmony_ci * E.g. CAIF Socket will call this function for each socket it connects
658c2ecf20Sopenharmony_ci * and have one client_layer instance for each socket.
668c2ecf20Sopenharmony_ci */
678c2ecf20Sopenharmony_ciint caif_connect_client(struct net *net,
688c2ecf20Sopenharmony_ci			struct caif_connect_request *conn_req,
698c2ecf20Sopenharmony_ci			struct cflayer *client_layer, int *ifindex,
708c2ecf20Sopenharmony_ci			int *headroom, int *tailroom);
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/**
738c2ecf20Sopenharmony_ci * caif_disconnect_client - Disconnects a client from the CAIF stack.
748c2ecf20Sopenharmony_ci *
758c2ecf20Sopenharmony_ci * @client_layer: Client layer to be disconnected.
768c2ecf20Sopenharmony_ci */
778c2ecf20Sopenharmony_ciint caif_disconnect_client(struct net *net, struct cflayer *client_layer);
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci/**
818c2ecf20Sopenharmony_ci * caif_client_register_refcnt - register ref-count functions provided by client.
828c2ecf20Sopenharmony_ci *
838c2ecf20Sopenharmony_ci * @adapt_layer: Client layer using CAIF Stack.
848c2ecf20Sopenharmony_ci * @hold:	Function provided by client layer increasing ref-count
858c2ecf20Sopenharmony_ci * @put:	Function provided by client layer decreasing ref-count
868c2ecf20Sopenharmony_ci *
878c2ecf20Sopenharmony_ci * Client of the CAIF Stack must register functions for reference counting.
888c2ecf20Sopenharmony_ci * These functions are called by the CAIF Stack for every upstream packet,
898c2ecf20Sopenharmony_ci * and must therefore be implemented efficiently.
908c2ecf20Sopenharmony_ci *
918c2ecf20Sopenharmony_ci * Client should call caif_free_client when reference count degrease to zero.
928c2ecf20Sopenharmony_ci */
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_civoid caif_client_register_refcnt(struct cflayer *adapt_layer,
958c2ecf20Sopenharmony_ci					void (*hold)(struct cflayer *lyr),
968c2ecf20Sopenharmony_ci					void (*put)(struct cflayer *lyr));
978c2ecf20Sopenharmony_ci/**
988c2ecf20Sopenharmony_ci * caif_free_client - Free memory used to manage the client in the CAIF Stack.
998c2ecf20Sopenharmony_ci *
1008c2ecf20Sopenharmony_ci * @client_layer: Client layer to be removed.
1018c2ecf20Sopenharmony_ci *
1028c2ecf20Sopenharmony_ci * This function must be called from client layer in order to free memory.
1038c2ecf20Sopenharmony_ci * Caller must guarantee that no packets are in flight upstream when calling
1048c2ecf20Sopenharmony_ci * this function.
1058c2ecf20Sopenharmony_ci */
1068c2ecf20Sopenharmony_civoid caif_free_client(struct cflayer *adap_layer);
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci/**
1098c2ecf20Sopenharmony_ci * struct caif_enroll_dev - Enroll a net-device as a CAIF Link layer
1108c2ecf20Sopenharmony_ci * @dev:		Network device to enroll.
1118c2ecf20Sopenharmony_ci * @caifdev:		Configuration information from CAIF Link Layer
1128c2ecf20Sopenharmony_ci * @link_support:	Link layer support layer
1138c2ecf20Sopenharmony_ci * @head_room:		Head room needed by link support layer
1148c2ecf20Sopenharmony_ci * @layer:		Lowest layer in CAIF stack
1158c2ecf20Sopenharmony_ci * @rcv_fun:		Receive function for CAIF stack.
1168c2ecf20Sopenharmony_ci *
1178c2ecf20Sopenharmony_ci * This function enroll a CAIF link layer into CAIF Stack and
1188c2ecf20Sopenharmony_ci * expects the interface to be able to handle CAIF payload.
1198c2ecf20Sopenharmony_ci * The link_support layer is used to add any Link Layer specific
1208c2ecf20Sopenharmony_ci * framing.
1218c2ecf20Sopenharmony_ci */
1228c2ecf20Sopenharmony_ciint caif_enroll_dev(struct net_device *dev, struct caif_dev_common *caifdev,
1238c2ecf20Sopenharmony_ci			struct cflayer *link_support, int head_room,
1248c2ecf20Sopenharmony_ci			struct cflayer **layer, int (**rcv_func)(
1258c2ecf20Sopenharmony_ci				struct sk_buff *, struct net_device *,
1268c2ecf20Sopenharmony_ci				struct packet_type *, struct net_device *));
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci#endif /* CAIF_DEV_H_ */
129