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