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