Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /* Copyright (c) 2021, Linaro Ltd <loic.poulain@linaro.org> */
0003 
0004 #ifndef __WWAN_H
0005 #define __WWAN_H
0006 
0007 #include <linux/poll.h>
0008 #include <linux/netdevice.h>
0009 #include <linux/types.h>
0010 
0011 /**
0012  * enum wwan_port_type - WWAN port types
0013  * @WWAN_PORT_AT: AT commands
0014  * @WWAN_PORT_MBIM: Mobile Broadband Interface Model control
0015  * @WWAN_PORT_QMI: Qcom modem/MSM interface for modem control
0016  * @WWAN_PORT_QCDM: Qcom Modem diagnostic interface
0017  * @WWAN_PORT_FIREHOSE: XML based command protocol
0018  *
0019  * @WWAN_PORT_MAX: Highest supported port types
0020  * @WWAN_PORT_UNKNOWN: Special value to indicate an unknown port type
0021  * @__WWAN_PORT_MAX: Internal use
0022  */
0023 enum wwan_port_type {
0024     WWAN_PORT_AT,
0025     WWAN_PORT_MBIM,
0026     WWAN_PORT_QMI,
0027     WWAN_PORT_QCDM,
0028     WWAN_PORT_FIREHOSE,
0029 
0030     /* Add new port types above this line */
0031 
0032     __WWAN_PORT_MAX,
0033     WWAN_PORT_MAX = __WWAN_PORT_MAX - 1,
0034     WWAN_PORT_UNKNOWN,
0035 };
0036 
0037 struct device;
0038 struct file;
0039 struct netlink_ext_ack;
0040 struct sk_buff;
0041 struct wwan_port;
0042 
0043 /** struct wwan_port_ops - The WWAN port operations
0044  * @start: The routine for starting the WWAN port device.
0045  * @stop: The routine for stopping the WWAN port device.
0046  * @tx: Non-blocking routine that sends WWAN port protocol data to the device.
0047  * @tx_blocking: Optional blocking routine that sends WWAN port protocol data
0048  *               to the device.
0049  * @tx_poll: Optional routine that sets additional TX poll flags.
0050  *
0051  * The wwan_port_ops structure contains a list of low-level operations
0052  * that control a WWAN port device. All functions are mandatory unless specified.
0053  */
0054 struct wwan_port_ops {
0055     int (*start)(struct wwan_port *port);
0056     void (*stop)(struct wwan_port *port);
0057     int (*tx)(struct wwan_port *port, struct sk_buff *skb);
0058 
0059     /* Optional operations */
0060     int (*tx_blocking)(struct wwan_port *port, struct sk_buff *skb);
0061     __poll_t (*tx_poll)(struct wwan_port *port, struct file *filp,
0062                 poll_table *wait);
0063 };
0064 
0065 /**
0066  * wwan_create_port - Add a new WWAN port
0067  * @parent: Device to use as parent and shared by all WWAN ports
0068  * @type: WWAN port type
0069  * @ops: WWAN port operations
0070  * @drvdata: Pointer to caller driver data
0071  *
0072  * Allocate and register a new WWAN port. The port will be automatically exposed
0073  * to user as a character device and attached to the right virtual WWAN device,
0074  * based on the parent pointer. The parent pointer is the device shared by all
0075  * components of a same WWAN modem (e.g. USB dev, PCI dev, MHI controller...).
0076  *
0077  * drvdata will be placed in the WWAN port device driver data and can be
0078  * retrieved with wwan_port_get_drvdata().
0079  *
0080  * This function must be balanced with a call to wwan_remove_port().
0081  *
0082  * Returns a valid pointer to wwan_port on success or PTR_ERR on failure
0083  */
0084 struct wwan_port *wwan_create_port(struct device *parent,
0085                    enum wwan_port_type type,
0086                    const struct wwan_port_ops *ops,
0087                    void *drvdata);
0088 
0089 /**
0090  * wwan_remove_port - Remove a WWAN port
0091  * @port: WWAN port to remove
0092  *
0093  * Remove a previously created port.
0094  */
0095 void wwan_remove_port(struct wwan_port *port);
0096 
0097 /**
0098  * wwan_port_rx - Receive data from the WWAN port
0099  * @port: WWAN port for which data is received
0100  * @skb: Pointer to the rx buffer
0101  *
0102  * A port driver calls this function upon data reception (MBIM, AT...).
0103  */
0104 void wwan_port_rx(struct wwan_port *port, struct sk_buff *skb);
0105 
0106 /**
0107  * wwan_port_txoff - Stop TX on WWAN port
0108  * @port: WWAN port for which TX must be stopped
0109  *
0110  * Used for TX flow control, a port driver calls this function to indicate TX
0111  * is temporary unavailable (e.g. due to ring buffer fullness).
0112  */
0113 void wwan_port_txoff(struct wwan_port *port);
0114 
0115 
0116 /**
0117  * wwan_port_txon - Restart TX on WWAN port
0118  * @port: WWAN port for which TX must be restarted
0119  *
0120  * Used for TX flow control, a port driver calls this function to indicate TX
0121  * is available again.
0122  */
0123 void wwan_port_txon(struct wwan_port *port);
0124 
0125 /**
0126  * wwan_port_get_drvdata - Retrieve driver data from a WWAN port
0127  * @port: Related WWAN port
0128  */
0129 void *wwan_port_get_drvdata(struct wwan_port *port);
0130 
0131 /**
0132  * struct wwan_netdev_priv - WWAN core network device private data
0133  * @link_id: WWAN device data link id
0134  * @drv_priv: driver private data area, size is determined in &wwan_ops
0135  */
0136 struct wwan_netdev_priv {
0137     u32 link_id;
0138 
0139     /* must be last */
0140     u8 drv_priv[] __aligned(sizeof(void *));
0141 };
0142 
0143 static inline void *wwan_netdev_drvpriv(struct net_device *dev)
0144 {
0145     return ((struct wwan_netdev_priv *)netdev_priv(dev))->drv_priv;
0146 }
0147 
0148 /*
0149  * Used to indicate that the WWAN core should not create a default network
0150  * link.
0151  */
0152 #define WWAN_NO_DEFAULT_LINK        U32_MAX
0153 
0154 /**
0155  * struct wwan_ops - WWAN device ops
0156  * @priv_size: size of private netdev data area
0157  * @setup: set up a new netdev
0158  * @newlink: register the new netdev
0159  * @dellink: remove the given netdev
0160  */
0161 struct wwan_ops {
0162     unsigned int priv_size;
0163     void (*setup)(struct net_device *dev);
0164     int (*newlink)(void *ctxt, struct net_device *dev,
0165                u32 if_id, struct netlink_ext_ack *extack);
0166     void (*dellink)(void *ctxt, struct net_device *dev,
0167             struct list_head *head);
0168 };
0169 
0170 int wwan_register_ops(struct device *parent, const struct wwan_ops *ops,
0171               void *ctxt, u32 def_link_id);
0172 
0173 void wwan_unregister_ops(struct device *parent);
0174 
0175 #ifdef CONFIG_WWAN_DEBUGFS
0176 struct dentry *wwan_get_debugfs_dir(struct device *parent);
0177 void wwan_put_debugfs_dir(struct dentry *dir);
0178 #else
0179 static inline struct dentry *wwan_get_debugfs_dir(struct device *parent)
0180 {
0181     return ERR_PTR(-ENODEV);
0182 }
0183 static inline void wwan_put_debugfs_dir(struct dentry *dir) {}
0184 #endif
0185 
0186 #endif /* __WWAN_H */