xref: /linux-6.15/include/linux/wwan.h (revision f42cfb46)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (c) 2021, Linaro Ltd <[email protected]> */
3 
4 #ifndef __WWAN_H
5 #define __WWAN_H
6 
7 #include <linux/device.h>
8 #include <linux/kernel.h>
9 #include <linux/skbuff.h>
10 #include <linux/netlink.h>
11 
12 /**
13  * enum wwan_port_type - WWAN port types
14  * @WWAN_PORT_AT: AT commands
15  * @WWAN_PORT_MBIM: Mobile Broadband Interface Model control
16  * @WWAN_PORT_QMI: Qcom modem/MSM interface for modem control
17  * @WWAN_PORT_QCDM: Qcom Modem diagnostic interface
18  * @WWAN_PORT_FIREHOSE: XML based command protocol
19  *
20  * @WWAN_PORT_MAX: Highest supported port types
21  * @WWAN_PORT_UNKNOWN: Special value to indicate an unknown port type
22  * @__WWAN_PORT_MAX: Internal use
23  */
24 enum wwan_port_type {
25 	WWAN_PORT_AT,
26 	WWAN_PORT_MBIM,
27 	WWAN_PORT_QMI,
28 	WWAN_PORT_QCDM,
29 	WWAN_PORT_FIREHOSE,
30 
31 	/* Add new port types above this line */
32 
33 	__WWAN_PORT_MAX,
34 	WWAN_PORT_MAX = __WWAN_PORT_MAX - 1,
35 	WWAN_PORT_UNKNOWN,
36 };
37 
38 struct wwan_port;
39 
40 /** struct wwan_port_ops - The WWAN port operations
41  * @start: The routine for starting the WWAN port device.
42  * @stop: The routine for stopping the WWAN port device.
43  * @tx: The routine that sends WWAN port protocol data to the device.
44  *
45  * The wwan_port_ops structure contains a list of low-level operations
46  * that control a WWAN port device. All functions are mandatory.
47  */
48 struct wwan_port_ops {
49 	int (*start)(struct wwan_port *port);
50 	void (*stop)(struct wwan_port *port);
51 	int (*tx)(struct wwan_port *port, struct sk_buff *skb);
52 };
53 
54 /**
55  * wwan_create_port - Add a new WWAN port
56  * @parent: Device to use as parent and shared by all WWAN ports
57  * @type: WWAN port type
58  * @ops: WWAN port operations
59  * @drvdata: Pointer to caller driver data
60  *
61  * Allocate and register a new WWAN port. The port will be automatically exposed
62  * to user as a character device and attached to the right virtual WWAN device,
63  * based on the parent pointer. The parent pointer is the device shared by all
64  * components of a same WWAN modem (e.g. USB dev, PCI dev, MHI controller...).
65  *
66  * drvdata will be placed in the WWAN port device driver data and can be
67  * retrieved with wwan_port_get_drvdata().
68  *
69  * This function must be balanced with a call to wwan_remove_port().
70  *
71  * Returns a valid pointer to wwan_port on success or PTR_ERR on failure
72  */
73 struct wwan_port *wwan_create_port(struct device *parent,
74 				   enum wwan_port_type type,
75 				   const struct wwan_port_ops *ops,
76 				   void *drvdata);
77 
78 /**
79  * wwan_remove_port - Remove a WWAN port
80  * @port: WWAN port to remove
81  *
82  * Remove a previously created port.
83  */
84 void wwan_remove_port(struct wwan_port *port);
85 
86 /**
87  * wwan_port_rx - Receive data from the WWAN port
88  * @port: WWAN port for which data is received
89  * @skb: Pointer to the rx buffer
90  *
91  * A port driver calls this function upon data reception (MBIM, AT...).
92  */
93 void wwan_port_rx(struct wwan_port *port, struct sk_buff *skb);
94 
95 /**
96  * wwan_port_txoff - Stop TX on WWAN port
97  * @port: WWAN port for which TX must be stopped
98  *
99  * Used for TX flow control, a port driver calls this function to indicate TX
100  * is temporary unavailable (e.g. due to ring buffer fullness).
101  */
102 void wwan_port_txoff(struct wwan_port *port);
103 
104 
105 /**
106  * wwan_port_txon - Restart TX on WWAN port
107  * @port: WWAN port for which TX must be restarted
108  *
109  * Used for TX flow control, a port driver calls this function to indicate TX
110  * is available again.
111  */
112 void wwan_port_txon(struct wwan_port *port);
113 
114 /**
115  * wwan_port_get_drvdata - Retrieve driver data from a WWAN port
116  * @port: Related WWAN port
117  */
118 void *wwan_port_get_drvdata(struct wwan_port *port);
119 
120 /**
121  * struct wwan_ops - WWAN device ops
122  * @owner: module owner of the WWAN ops
123  * @priv_size: size of private netdev data area
124  * @setup: set up a new netdev
125  * @newlink: register the new netdev
126  * @dellink: remove the given netdev
127  */
128 struct wwan_ops {
129 	struct module *owner;
130 	unsigned int priv_size;
131 	void (*setup)(struct net_device *dev);
132 	int (*newlink)(void *ctxt, struct net_device *dev,
133 		       u32 if_id, struct netlink_ext_ack *extack);
134 	void (*dellink)(void *ctxt, struct net_device *dev,
135 			struct list_head *head);
136 };
137 
138 int wwan_register_ops(struct device *parent, const struct wwan_ops *ops,
139 		      void *ctxt);
140 
141 void wwan_unregister_ops(struct device *parent);
142 
143 #endif /* __WWAN_H */
144