wwan.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Copyright (c) 2021, Linaro Ltd <loic.poulain@linaro.org> */
  3. #ifndef __WWAN_H
  4. #define __WWAN_H
  5. #include <linux/poll.h>
  6. #include <linux/netdevice.h>
  7. #include <linux/types.h>
  8. #include <linux/android_kabi.h>
  9. /**
  10. * enum wwan_port_type - WWAN port types
  11. * @WWAN_PORT_AT: AT commands
  12. * @WWAN_PORT_MBIM: Mobile Broadband Interface Model control
  13. * @WWAN_PORT_QMI: Qcom modem/MSM interface for modem control
  14. * @WWAN_PORT_QCDM: Qcom Modem diagnostic interface
  15. * @WWAN_PORT_FIREHOSE: XML based command protocol
  16. *
  17. * @WWAN_PORT_MAX: Highest supported port types
  18. * @WWAN_PORT_UNKNOWN: Special value to indicate an unknown port type
  19. * @__WWAN_PORT_MAX: Internal use
  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. /* Add new port types above this line */
  28. __WWAN_PORT_MAX,
  29. WWAN_PORT_MAX = __WWAN_PORT_MAX - 1,
  30. WWAN_PORT_UNKNOWN,
  31. };
  32. struct device;
  33. struct file;
  34. struct netlink_ext_ack;
  35. struct sk_buff;
  36. struct wwan_port;
  37. /** struct wwan_port_ops - The WWAN port operations
  38. * @start: The routine for starting the WWAN port device.
  39. * @stop: The routine for stopping the WWAN port device.
  40. * @tx: Non-blocking routine that sends WWAN port protocol data to the device.
  41. * @tx_blocking: Optional blocking routine that sends WWAN port protocol data
  42. * to the device.
  43. * @tx_poll: Optional routine that sets additional TX poll flags.
  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 unless specified.
  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. /* Optional operations */
  53. int (*tx_blocking)(struct wwan_port *port, struct sk_buff *skb);
  54. __poll_t (*tx_poll)(struct wwan_port *port, struct file *filp,
  55. poll_table *wait);
  56. ANDROID_KABI_RESERVE(1);
  57. ANDROID_KABI_RESERVE(2);
  58. };
  59. /**
  60. * wwan_create_port - Add a new WWAN port
  61. * @parent: Device to use as parent and shared by all WWAN ports
  62. * @type: WWAN port type
  63. * @ops: WWAN port operations
  64. * @drvdata: Pointer to caller driver data
  65. *
  66. * Allocate and register a new WWAN port. The port will be automatically exposed
  67. * to user as a character device and attached to the right virtual WWAN device,
  68. * based on the parent pointer. The parent pointer is the device shared by all
  69. * components of a same WWAN modem (e.g. USB dev, PCI dev, MHI controller...).
  70. *
  71. * drvdata will be placed in the WWAN port device driver data and can be
  72. * retrieved with wwan_port_get_drvdata().
  73. *
  74. * This function must be balanced with a call to wwan_remove_port().
  75. *
  76. * Returns a valid pointer to wwan_port on success or PTR_ERR on failure
  77. */
  78. struct wwan_port *wwan_create_port(struct device *parent,
  79. enum wwan_port_type type,
  80. const struct wwan_port_ops *ops,
  81. void *drvdata);
  82. /**
  83. * wwan_remove_port - Remove a WWAN port
  84. * @port: WWAN port to remove
  85. *
  86. * Remove a previously created port.
  87. */
  88. void wwan_remove_port(struct wwan_port *port);
  89. /**
  90. * wwan_port_rx - Receive data from the WWAN port
  91. * @port: WWAN port for which data is received
  92. * @skb: Pointer to the rx buffer
  93. *
  94. * A port driver calls this function upon data reception (MBIM, AT...).
  95. */
  96. void wwan_port_rx(struct wwan_port *port, struct sk_buff *skb);
  97. /**
  98. * wwan_port_txoff - Stop TX on WWAN port
  99. * @port: WWAN port for which TX must be stopped
  100. *
  101. * Used for TX flow control, a port driver calls this function to indicate TX
  102. * is temporary unavailable (e.g. due to ring buffer fullness).
  103. */
  104. void wwan_port_txoff(struct wwan_port *port);
  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. * wwan_port_get_drvdata - Retrieve driver data from a WWAN port
  115. * @port: Related WWAN port
  116. */
  117. void *wwan_port_get_drvdata(struct wwan_port *port);
  118. /**
  119. * struct wwan_netdev_priv - WWAN core network device private data
  120. * @link_id: WWAN device data link id
  121. * @drv_priv: driver private data area, size is determined in &wwan_ops
  122. */
  123. struct wwan_netdev_priv {
  124. u32 link_id;
  125. /* must be last */
  126. u8 drv_priv[] __aligned(sizeof(void *));
  127. };
  128. static inline void *wwan_netdev_drvpriv(struct net_device *dev)
  129. {
  130. return ((struct wwan_netdev_priv *)netdev_priv(dev))->drv_priv;
  131. }
  132. /*
  133. * Used to indicate that the WWAN core should not create a default network
  134. * link.
  135. */
  136. #define WWAN_NO_DEFAULT_LINK U32_MAX
  137. /**
  138. * struct wwan_ops - WWAN device ops
  139. * @priv_size: size of private netdev data area
  140. * @setup: set up a new netdev
  141. * @newlink: register the new netdev
  142. * @dellink: remove the given netdev
  143. */
  144. struct wwan_ops {
  145. unsigned int priv_size;
  146. void (*setup)(struct net_device *dev);
  147. int (*newlink)(void *ctxt, struct net_device *dev,
  148. u32 if_id, struct netlink_ext_ack *extack);
  149. void (*dellink)(void *ctxt, struct net_device *dev,
  150. struct list_head *head);
  151. ANDROID_KABI_RESERVE(1);
  152. ANDROID_KABI_RESERVE(2);
  153. };
  154. int wwan_register_ops(struct device *parent, const struct wwan_ops *ops,
  155. void *ctxt, u32 def_link_id);
  156. void wwan_unregister_ops(struct device *parent);
  157. #ifdef CONFIG_WWAN_DEBUGFS
  158. struct dentry *wwan_get_debugfs_dir(struct device *parent);
  159. void wwan_put_debugfs_dir(struct dentry *dir);
  160. #else
  161. static inline struct dentry *wwan_get_debugfs_dir(struct device *parent)
  162. {
  163. return ERR_PTR(-ENODEV);
  164. }
  165. static inline void wwan_put_debugfs_dir(struct dentry *dir) {}
  166. #endif
  167. #endif /* __WWAN_H */