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 11 /** 12 * enum wwan_port_type - WWAN port types 13 * @WWAN_PORT_AT: AT commands 14 * @WWAN_PORT_MBIM: Mobile Broadband Interface Model control 15 * @WWAN_PORT_QMI: Qcom modem/MSM interface for modem control 16 * @WWAN_PORT_QCDM: Qcom Modem diagnostic interface 17 * @WWAN_PORT_FIREHOSE: XML based command protocol 18 * @WWAN_PORT_UNKNOWN: Unknown port type 19 * @WWAN_PORT_MAX: Number of supported port types 20 */ 21 enum wwan_port_type { 22 WWAN_PORT_AT, 23 WWAN_PORT_MBIM, 24 WWAN_PORT_QMI, 25 WWAN_PORT_QCDM, 26 WWAN_PORT_FIREHOSE, 27 WWAN_PORT_UNKNOWN, 28 WWAN_PORT_MAX = WWAN_PORT_UNKNOWN, 29 }; 30 31 struct wwan_port; 32 33 /** struct wwan_port_ops - The WWAN port operations 34 * @start: The routine for starting the WWAN port device. 35 * @stop: The routine for stopping the WWAN port device. 36 * @tx: The routine that sends WWAN port protocol data to the device. 37 * 38 * The wwan_port_ops structure contains a list of low-level operations 39 * that control a WWAN port device. All functions are mandatory. 40 */ 41 struct wwan_port_ops { 42 int (*start)(struct wwan_port *port); 43 void (*stop)(struct wwan_port *port); 44 int (*tx)(struct wwan_port *port, struct sk_buff *skb); 45 }; 46 47 /** 48 * wwan_create_port - Add a new WWAN port 49 * @parent: Device to use as parent and shared by all WWAN ports 50 * @type: WWAN port type 51 * @ops: WWAN port operations 52 * @drvdata: Pointer to caller driver data 53 * 54 * Allocate and register a new WWAN port. The port will be automatically exposed 55 * to user as a character device and attached to the right virtual WWAN device, 56 * based on the parent pointer. The parent pointer is the device shared by all 57 * components of a same WWAN modem (e.g. USB dev, PCI dev, MHI controller...). 58 * 59 * drvdata will be placed in the WWAN port device driver data and can be 60 * retrieved with wwan_port_get_drvdata(). 61 * 62 * This function must be balanced with a call to wwan_remove_port(). 63 * 64 * Returns a valid pointer to wwan_port on success or PTR_ERR on failure 65 */ 66 struct wwan_port *wwan_create_port(struct device *parent, 67 enum wwan_port_type type, 68 const struct wwan_port_ops *ops, 69 void *drvdata); 70 71 /** 72 * wwan_remove_port - Remove a WWAN port 73 * @port: WWAN port to remove 74 * 75 * Remove a previously created port. 76 */ 77 void wwan_remove_port(struct wwan_port *port); 78 79 /** 80 * wwan_port_rx - Receive data from the WWAN port 81 * @port: WWAN port for which data is received 82 * @skb: Pointer to the rx buffer 83 * 84 * A port driver calls this function upon data reception (MBIM, AT...). 85 */ 86 void wwan_port_rx(struct wwan_port *port, struct sk_buff *skb); 87 88 /** 89 * wwan_port_txoff - Stop TX on WWAN port 90 * @port: WWAN port for which TX must be stopped 91 * 92 * Used for TX flow control, a port driver calls this function to indicate TX 93 * is temporary unavailable (e.g. due to ring buffer fullness). 94 */ 95 void wwan_port_txoff(struct wwan_port *port); 96 97 98 /** 99 * wwan_port_txon - Restart TX on WWAN port 100 * @port: WWAN port for which TX must be restarted 101 * 102 * Used for TX flow control, a port driver calls this function to indicate TX 103 * is available again. 104 */ 105 void wwan_port_txon(struct wwan_port *port); 106 107 /** 108 * wwan_port_get_drvdata - Retrieve driver data from a WWAN port 109 * @port: Related WWAN port 110 */ 111 void *wwan_port_get_drvdata(struct wwan_port *port); 112 113 #endif /* __WWAN_H */ 114