Loic Poulain | 9a44c1cc | 2021-04-16 10:36:33 +0200 | [diff] [blame] | 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> |
Stephan Gerhold | 31c143f | 2021-06-18 19:36:11 +0200 | [diff] [blame] | 9 | #include <linux/poll.h> |
Loic Poulain | 9a44c1cc | 2021-04-16 10:36:33 +0200 | [diff] [blame] | 10 | #include <linux/skbuff.h> |
Johannes Berg | 88b7105 | 2021-06-12 10:20:56 +0200 | [diff] [blame] | 11 | #include <linux/netlink.h> |
Sergey Ryazanov | 6994092 | 2021-06-22 01:51:00 +0300 | [diff] [blame] | 12 | #include <linux/netdevice.h> |
Loic Poulain | 9a44c1cc | 2021-04-16 10:36:33 +0200 | [diff] [blame] | 13 | |
| 14 | /** |
| 15 | * enum wwan_port_type - WWAN port types |
| 16 | * @WWAN_PORT_AT: AT commands |
| 17 | * @WWAN_PORT_MBIM: Mobile Broadband Interface Model control |
| 18 | * @WWAN_PORT_QMI: Qcom modem/MSM interface for modem control |
| 19 | * @WWAN_PORT_QCDM: Qcom Modem diagnostic interface |
| 20 | * @WWAN_PORT_FIREHOSE: XML based command protocol |
Sergey Ryazanov | b64d76b | 2021-06-08 07:02:34 +0300 | [diff] [blame] | 21 | * |
| 22 | * @WWAN_PORT_MAX: Highest supported port types |
| 23 | * @WWAN_PORT_UNKNOWN: Special value to indicate an unknown port type |
| 24 | * @__WWAN_PORT_MAX: Internal use |
Loic Poulain | 9a44c1cc | 2021-04-16 10:36:33 +0200 | [diff] [blame] | 25 | */ |
| 26 | enum wwan_port_type { |
| 27 | WWAN_PORT_AT, |
| 28 | WWAN_PORT_MBIM, |
| 29 | WWAN_PORT_QMI, |
| 30 | WWAN_PORT_QCDM, |
| 31 | WWAN_PORT_FIREHOSE, |
Sergey Ryazanov | b64d76b | 2021-06-08 07:02:34 +0300 | [diff] [blame] | 32 | |
| 33 | /* Add new port types above this line */ |
| 34 | |
| 35 | __WWAN_PORT_MAX, |
| 36 | WWAN_PORT_MAX = __WWAN_PORT_MAX - 1, |
Loic Poulain | bf30396 | 2021-05-11 16:42:22 +0200 | [diff] [blame] | 37 | WWAN_PORT_UNKNOWN, |
Loic Poulain | 9a44c1cc | 2021-04-16 10:36:33 +0200 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | struct wwan_port; |
| 41 | |
| 42 | /** struct wwan_port_ops - The WWAN port operations |
| 43 | * @start: The routine for starting the WWAN port device. |
| 44 | * @stop: The routine for stopping the WWAN port device. |
Stephan Gerhold | 31c143f | 2021-06-18 19:36:11 +0200 | [diff] [blame] | 45 | * @tx: Non-blocking routine that sends WWAN port protocol data to the device. |
| 46 | * @tx_blocking: Optional blocking routine that sends WWAN port protocol data |
| 47 | * to the device. |
| 48 | * @tx_poll: Optional routine that sets additional TX poll flags. |
Loic Poulain | 9a44c1cc | 2021-04-16 10:36:33 +0200 | [diff] [blame] | 49 | * |
| 50 | * The wwan_port_ops structure contains a list of low-level operations |
Stephan Gerhold | 31c143f | 2021-06-18 19:36:11 +0200 | [diff] [blame] | 51 | * that control a WWAN port device. All functions are mandatory unless specified. |
Loic Poulain | 9a44c1cc | 2021-04-16 10:36:33 +0200 | [diff] [blame] | 52 | */ |
| 53 | struct wwan_port_ops { |
| 54 | int (*start)(struct wwan_port *port); |
| 55 | void (*stop)(struct wwan_port *port); |
| 56 | int (*tx)(struct wwan_port *port, struct sk_buff *skb); |
Stephan Gerhold | 31c143f | 2021-06-18 19:36:11 +0200 | [diff] [blame] | 57 | |
| 58 | /* Optional operations */ |
| 59 | int (*tx_blocking)(struct wwan_port *port, struct sk_buff *skb); |
| 60 | __poll_t (*tx_poll)(struct wwan_port *port, struct file *filp, |
| 61 | poll_table *wait); |
Loic Poulain | 9a44c1cc | 2021-04-16 10:36:33 +0200 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | /** |
| 65 | * wwan_create_port - Add a new WWAN port |
| 66 | * @parent: Device to use as parent and shared by all WWAN ports |
| 67 | * @type: WWAN port type |
| 68 | * @ops: WWAN port operations |
| 69 | * @drvdata: Pointer to caller driver data |
| 70 | * |
| 71 | * Allocate and register a new WWAN port. The port will be automatically exposed |
| 72 | * to user as a character device and attached to the right virtual WWAN device, |
| 73 | * based on the parent pointer. The parent pointer is the device shared by all |
| 74 | * components of a same WWAN modem (e.g. USB dev, PCI dev, MHI controller...). |
| 75 | * |
| 76 | * drvdata will be placed in the WWAN port device driver data and can be |
| 77 | * retrieved with wwan_port_get_drvdata(). |
| 78 | * |
| 79 | * This function must be balanced with a call to wwan_remove_port(). |
| 80 | * |
| 81 | * Returns a valid pointer to wwan_port on success or PTR_ERR on failure |
| 82 | */ |
| 83 | struct wwan_port *wwan_create_port(struct device *parent, |
| 84 | enum wwan_port_type type, |
| 85 | const struct wwan_port_ops *ops, |
| 86 | void *drvdata); |
| 87 | |
| 88 | /** |
| 89 | * wwan_remove_port - Remove a WWAN port |
| 90 | * @port: WWAN port to remove |
| 91 | * |
| 92 | * Remove a previously created port. |
| 93 | */ |
| 94 | void wwan_remove_port(struct wwan_port *port); |
| 95 | |
| 96 | /** |
| 97 | * wwan_port_rx - Receive data from the WWAN port |
| 98 | * @port: WWAN port for which data is received |
| 99 | * @skb: Pointer to the rx buffer |
| 100 | * |
| 101 | * A port driver calls this function upon data reception (MBIM, AT...). |
| 102 | */ |
| 103 | void wwan_port_rx(struct wwan_port *port, struct sk_buff *skb); |
| 104 | |
| 105 | /** |
| 106 | * wwan_port_txoff - Stop TX on WWAN port |
| 107 | * @port: WWAN port for which TX must be stopped |
| 108 | * |
| 109 | * Used for TX flow control, a port driver calls this function to indicate TX |
| 110 | * is temporary unavailable (e.g. due to ring buffer fullness). |
| 111 | */ |
| 112 | void wwan_port_txoff(struct wwan_port *port); |
| 113 | |
| 114 | |
| 115 | /** |
| 116 | * wwan_port_txon - Restart TX on WWAN port |
| 117 | * @port: WWAN port for which TX must be restarted |
| 118 | * |
| 119 | * Used for TX flow control, a port driver calls this function to indicate TX |
| 120 | * is available again. |
| 121 | */ |
| 122 | void wwan_port_txon(struct wwan_port *port); |
| 123 | |
| 124 | /** |
| 125 | * wwan_port_get_drvdata - Retrieve driver data from a WWAN port |
| 126 | * @port: Related WWAN port |
| 127 | */ |
| 128 | void *wwan_port_get_drvdata(struct wwan_port *port); |
| 129 | |
Sergey Ryazanov | 6994092 | 2021-06-22 01:51:00 +0300 | [diff] [blame] | 130 | /** |
| 131 | * struct wwan_netdev_priv - WWAN core network device private data |
| 132 | * @link_id: WWAN device data link id |
| 133 | * @drv_priv: driver private data area, size is determined in &wwan_ops |
| 134 | */ |
| 135 | struct wwan_netdev_priv { |
| 136 | u32 link_id; |
| 137 | |
| 138 | /* must be last */ |
| 139 | u8 drv_priv[] __aligned(sizeof(void *)); |
| 140 | }; |
| 141 | |
| 142 | static inline void *wwan_netdev_drvpriv(struct net_device *dev) |
| 143 | { |
| 144 | return ((struct wwan_netdev_priv *)netdev_priv(dev))->drv_priv; |
| 145 | } |
| 146 | |
Sergey Ryazanov | ca37429 | 2021-06-22 01:50:58 +0300 | [diff] [blame] | 147 | /* |
| 148 | * Used to indicate that the WWAN core should not create a default network |
| 149 | * link. |
| 150 | */ |
| 151 | #define WWAN_NO_DEFAULT_LINK U32_MAX |
| 152 | |
Johannes Berg | 88b7105 | 2021-06-12 10:20:56 +0200 | [diff] [blame] | 153 | /** |
| 154 | * struct wwan_ops - WWAN device ops |
Johannes Berg | 88b7105 | 2021-06-12 10:20:56 +0200 | [diff] [blame] | 155 | * @priv_size: size of private netdev data area |
| 156 | * @setup: set up a new netdev |
| 157 | * @newlink: register the new netdev |
| 158 | * @dellink: remove the given netdev |
| 159 | */ |
| 160 | struct wwan_ops { |
Johannes Berg | 88b7105 | 2021-06-12 10:20:56 +0200 | [diff] [blame] | 161 | unsigned int priv_size; |
| 162 | void (*setup)(struct net_device *dev); |
| 163 | int (*newlink)(void *ctxt, struct net_device *dev, |
| 164 | u32 if_id, struct netlink_ext_ack *extack); |
| 165 | void (*dellink)(void *ctxt, struct net_device *dev, |
| 166 | struct list_head *head); |
| 167 | }; |
| 168 | |
| 169 | int wwan_register_ops(struct device *parent, const struct wwan_ops *ops, |
Sergey Ryazanov | ca37429 | 2021-06-22 01:50:58 +0300 | [diff] [blame] | 170 | void *ctxt, u32 def_link_id); |
Johannes Berg | 88b7105 | 2021-06-12 10:20:56 +0200 | [diff] [blame] | 171 | |
| 172 | void wwan_unregister_ops(struct device *parent); |
| 173 | |
Sergey Ryazanov | 283e6f5a | 2021-12-07 12:21:40 +0300 | [diff] [blame^] | 174 | #ifdef CONFIG_WWAN_DEBUGFS |
M Chetan Kumar | c480467 | 2021-11-20 21:51:54 +0530 | [diff] [blame] | 175 | struct dentry *wwan_get_debugfs_dir(struct device *parent); |
Sergey Ryazanov | 283e6f5a | 2021-12-07 12:21:40 +0300 | [diff] [blame^] | 176 | #else |
| 177 | static inline struct dentry *wwan_get_debugfs_dir(struct device *parent) |
| 178 | { |
| 179 | return ERR_PTR(-ENODEV); |
| 180 | } |
| 181 | #endif |
M Chetan Kumar | c480467 | 2021-11-20 21:51:54 +0530 | [diff] [blame] | 182 | |
Loic Poulain | 9a44c1cc | 2021-04-16 10:36:33 +0200 | [diff] [blame] | 183 | #endif /* __WWAN_H */ |