The branch main has been updated by bz:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=06a1103fe38677ba6213cae321255f53e9476dcd

commit 06a1103fe38677ba6213cae321255f53e9476dcd
Author:     Bjoern A. Zeeb <[email protected]>
AuthorDate: 2023-04-18 20:21:37 +0000
Commit:     Bjoern A. Zeeb <[email protected]>
CommitDate: 2023-04-23 21:31:07 +0000

    ath10k: ath11k: add specific LinuxKPI support
    
    Add files needed by ath1?k drivers to linuxkpi/linuxkpi_wlan.
    This contain (skeleton) implementations of what is needed to
    compile but specifically mhi/qmi/qrtr will need more work for
    ath11k.
    
    MFC after:      2 months
---
 sys/compat/linuxkpi/common/include/linux/mhi.h     | 198 +++++++++++++++++++++
 sys/compat/linuxkpi/common/include/linux/qrtr.h    |  41 +++++
 .../linuxkpi/common/include/linux/soc/qcom/qmi.h   | 174 ++++++++++++++++++
 sys/compat/linuxkpi/common/src/linux_mhi.c         |  94 ++++++++++
 sys/conf/files                                     |   2 +
 sys/modules/linuxkpi_wlan/Makefile                 |   3 +
 6 files changed, 512 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/mhi.h 
b/sys/compat/linuxkpi/common/include/linux/mhi.h
new file mode 100644
index 000000000000..3d3965d3f42a
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/mhi.h
@@ -0,0 +1,198 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef        _LINUXKPI_LINUX_MHI_H
+#define        _LINUXKPI_LINUX_MHI_H
+
+#include <linux/types.h>
+
+/* Modem Host Interface (MHI) */
+
+/* XXX FIXME */
+#define        MHI_DB_BRST_DISABLE     0
+#define        MHI_ER_CTRL             0
+
+enum mhi_callback {
+       MHI_CB_SYS_ERROR,
+};
+
+struct mhi_channel_config {
+       const char              *name;
+       int     auto_queue, dir, doorbell, doorbell_mode_switch, ee_mask, 
event_ring, lpm_notify, num, num_elements, offload_channel, pollcfg;
+};
+
+struct mhi_event_config {
+       int     client_managed, data_type, hardware_event, irq, 
irq_moderation_ms, mode, num_elements, offload_channel, priority;
+};
+
+struct mhi_device {
+};
+
+struct mhi_controller_config {
+       struct mhi_channel_config       *ch_cfg;
+       struct mhi_event_config         *event_cfg;
+
+       int     buf_len, max_channels, num_channels, num_events, use_bounce_buf;
+
+       uint32_t                        timeout_ms;
+};
+
+struct mhi_controller {
+       struct device                   *cntrl_dev;
+       struct mhi_device               *mhi_dev;
+       void                            *regs;
+       int                             *irq;
+       const char                      *fw_image;
+
+       bool                            fbc_download;
+       size_t                          sbl_size;
+       size_t                          seg_len;
+       size_t                          reg_len;
+       int                             nr_irqs;
+       unsigned long                   irq_flags;
+       uint32_t                        timeout_ms;
+
+       dma_addr_t                      iova_start;
+       dma_addr_t                      iova_stop;
+
+       int                             (*runtime_get)(struct mhi_controller *);
+       void                            (*runtime_put)(struct mhi_controller *);
+       void                            (*status_cb)(struct mhi_controller *, 
enum mhi_callback);
+       int                             (*read_reg)(struct mhi_controller *, 
void __iomem *, uint32_t *);
+       void                            (*write_reg)(struct mhi_controller *, 
void __iomem *, uint32_t);
+};
+
+/* -------------------------------------------------------------------------- 
*/
+
+struct mhi_controller *linuxkpi_mhi_alloc_controller(void);
+void linuxkpi_mhi_free_controller(struct mhi_controller *);
+int linuxkpi_mhi_register_controller(struct mhi_controller *,
+    struct mhi_controller_config *);
+void linuxkpi_mhi_unregister_controller(struct mhi_controller *);
+
+/* -------------------------------------------------------------------------- 
*/
+
+static inline struct mhi_controller *
+mhi_alloc_controller(void)
+{
+
+       /* Keep allocations internal to our implementation. */
+       return (linuxkpi_mhi_alloc_controller());
+}
+
+static inline void
+mhi_free_controller(struct mhi_controller *mhi_ctrl)
+{
+
+       linuxkpi_mhi_free_controller(mhi_ctrl);
+}
+
+static inline int
+mhi_register_controller(struct mhi_controller *mhi_ctrl,
+    struct mhi_controller_config *cfg)
+{
+
+       return (linuxkpi_mhi_register_controller(mhi_ctrl, cfg));
+}
+
+static inline void
+mhi_unregister_controller(struct mhi_controller *mhi_ctrl)
+{
+
+       linuxkpi_mhi_unregister_controller(mhi_ctrl);
+}
+
+/* -------------------------------------------------------------------------- 
*/
+
+static __inline void
+mhi_device_get_sync(struct mhi_device *mhi_dev)
+{
+       /* XXX TODO */
+}
+
+static __inline void
+mhi_device_put(struct mhi_device *mhi_dev)
+{
+       /* XXX TODO */
+}
+
+/* -------------------------------------------------------------------------- 
*/
+
+static __inline int
+mhi_prepare_for_power_up(struct mhi_controller *mhi_ctrl)
+{
+       /* XXX TODO */
+       return (0);
+}
+
+static __inline int
+mhi_async_power_up(struct mhi_controller *mhi_ctrl)
+{
+       /* XXX TODO */
+       return (0);
+}
+
+static __inline void
+mhi_power_down(struct mhi_controller *mhi_ctrl, bool x)
+{
+       /* XXX TODO */
+}
+
+static __inline void
+mhi_unprepare_after_power_down(struct mhi_controller *mhi_ctrl)
+{
+       /* XXX TODO */
+}
+
+/* -------------------------------------------------------------------------- 
*/
+
+static __inline int
+mhi_pm_suspend(struct mhi_controller *mhi_ctrl)
+{
+       /* XXX TODO */
+       return (0);
+}
+
+static __inline int
+mhi_pm_resume_force(struct mhi_controller *mhi_ctrl)
+{
+       /* XXX TODO */
+       return (0);
+}
+
+/* -------------------------------------------------------------------------- 
*/
+
+static __inline int
+mhi_force_rddm_mode(struct mhi_controller *mhi_ctrl)
+{
+       /* XXX TODO */
+       return (0);
+}
+
+#endif /* _LINUXKPI_LINUX_MHI_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/qrtr.h 
b/sys/compat/linuxkpi/common/include/linux/qrtr.h
new file mode 100644
index 000000000000..1d2af0efdce2
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/qrtr.h
@@ -0,0 +1,41 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef        _LINUXKPI_LINUX_QRTR_H
+#define        _LINUXKPI_LINUX_QRTR_H
+
+/* Qualcomm IPC Router (QRTR) */
+
+#include <sys/socket.h>
+
+struct sockaddr_qrtr {
+       sa_family_t             sq_family;
+       uint32_t                sq_node;
+       uint32_t                sq_port;
+};
+
+#endif /* _LINUXKPI_LINUX_QRTR_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/soc/qcom/qmi.h 
b/sys/compat/linuxkpi/common/include/linux/soc/qcom/qmi.h
new file mode 100644
index 000000000000..fc7cfc0480a9
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/soc/qcom/qmi.h
@@ -0,0 +1,174 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef        _LINUXKPI_LINUX_SOC_QCOM_QMI_H
+#define        _LINUXKPI_LINUX_SOC_QCOM_QMI_H
+
+/* QMI (Qualcomm MSM Interface) */
+
+#include <linux/qrtr.h>
+
+enum soc_qcom_qmi_data_type {
+       QMI_EOTI,
+       QMI_DATA_LEN,
+       QMI_OPT_FLAG,
+       QMI_UNSIGNED_1_BYTE,
+       QMI_UNSIGNED_2_BYTE,
+       QMI_UNSIGNED_4_BYTE,
+       QMI_UNSIGNED_8_BYTE,
+       QMI_SIGNED_4_BYTE_ENUM,
+       QMI_STRUCT,
+       QMI_STRING,
+};
+
+#define        QMI_RESULT_SUCCESS_V01  __LINE__
+#define        QMI_INDICATION          __LINE__
+
+struct qmi_handle;
+
+enum soc_qcom_qmi_array_type {
+       NO_ARRAY,
+       VAR_LEN_ARRAY,
+};
+
+/* Should this become an enum? */
+#define        QMI_COMMON_TLV_TYPE                     0
+
+struct qmi_elem_info {
+       enum soc_qcom_qmi_data_type             data_type;
+       uint32_t                                elem_len;
+       uint32_t                                elem_size;
+       enum soc_qcom_qmi_array_type            array_type;
+       uint8_t                                 tlv_type;
+       uint32_t                                offset;
+       struct qmi_elem_info                    *ei_array;
+};
+
+struct qmi_response_type_v01 {
+       uint16_t                                result;
+       uint16_t                                error;
+};
+
+struct qmi_txn {
+};
+
+struct qmi_service {
+       uint32_t                                node;
+       uint32_t                                port;
+};
+
+struct qmi_msg_handler {
+       uint32_t                type;
+       uint32_t                msg_id;
+       struct qmi_elem_info    *ei;
+       size_t                  decoded_size;
+       void    (*fn)(struct qmi_handle *, struct sockaddr_qrtr *, struct 
qmi_txn *, const void *);
+};
+
+struct qmi_ops {
+       int     (*new_server)(struct qmi_handle *, struct qmi_service *);
+       void    (*del_server)(struct qmi_handle *, struct qmi_service *);
+};
+
+struct qmi_handle {
+       int                             sock;
+
+       const struct qmi_msg_handler    *handler;
+       struct qmi_ops                  ops;
+};
+
+
+/* XXX-TODO need implementation somewhere... it is not in ath1xk* */
+extern struct qmi_elem_info qmi_response_type_v01_ei[];
+
+static inline int
+qmi_handle_init(struct qmi_handle *handle, size_t resp_len_max,
+    const struct qmi_ops *ops, const struct qmi_msg_handler *handler)
+{
+
+       handle->handler = handler;
+       if (ops != NULL)
+               handle->ops = *ops;
+
+        /* We will find out what else to do here. */
+       /* XXX TODO */
+
+       return (0);
+}
+
+static __inline int
+qmi_add_lookup(struct qmi_handle *handle, uint32_t service, uint32_t version,
+    uint32_t service_ins_id)
+{
+
+       /* XXX TODO */
+       return (0);
+}
+
+static __inline void
+qmi_handle_release(struct qmi_handle *handle)
+{
+
+       /* XXX TODO */
+}
+
+static __inline int
+qmi_send_request(struct qmi_handle *handle, void *x, struct qmi_txn *txn,
+    uint32_t msd_id, size_t len, struct qmi_elem_info *ei, void *req)
+{
+
+       /* XXX TODO */
+       return (-ENXIO);
+}
+
+static __inline void
+qmi_txn_cancel(struct qmi_txn *txn)
+{
+
+       /* XXX TODO */
+}
+
+static __inline int
+qmi_txn_init(struct qmi_handle *handle, struct qmi_txn *txn,
+    struct qmi_elem_info *ei, void *resp)
+{
+
+       /* XXX TODO */
+       return (-ENXIO);
+}
+
+static __inline int
+qmi_txn_wait(struct qmi_txn *txn, uint64_t jiffies)
+{
+
+       /* XXX TODO */
+       return (-ENXIO);
+}
+
+#endif /* _LINUXKPI_LINUX_SOC_QCOM_QMI_H */
diff --git a/sys/compat/linuxkpi/common/src/linux_mhi.c 
b/sys/compat/linuxkpi/common/src/linux_mhi.c
new file mode 100644
index 000000000000..698a2553c1ec
--- /dev/null
+++ b/sys/compat/linuxkpi/common/src/linux_mhi.c
@@ -0,0 +1,94 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+
+#include <linux/kernel.h>      /* pr_debug */
+#include <linux/mhi.h>
+
+static MALLOC_DEFINE(M_LKPIMHI, "lkpimhi", "LinuxKPI MHI compat");
+
+struct mhi_controller *
+linuxkpi_mhi_alloc_controller(void)
+{
+       struct mhi_controller *mhi_ctrl;
+
+       mhi_ctrl = malloc(sizeof(*mhi_ctrl), M_LKPIMHI, M_NOWAIT | M_ZERO);
+
+       return (mhi_ctrl);
+}
+
+void
+linuxkpi_mhi_free_controller(struct mhi_controller *mhi_ctrl)
+{
+
+       /* What else do we need to check that it is gone? */
+       free(mhi_ctrl, M_LKPIMHI);
+}
+
+int
+linuxkpi_mhi_register_controller(struct mhi_controller *mhi_ctrl,
+    struct mhi_controller_config *cfg)
+{
+
+       if (mhi_ctrl == NULL || cfg == NULL)
+               return (-EINVAL);
+
+#define        CHECK_FIELD(_f)                                         \
+       if (!mhi_ctrl->_f)                                      \
+               return (-ENXIO);
+       CHECK_FIELD(cntrl_dev);
+       CHECK_FIELD(regs);
+       CHECK_FIELD(irq);
+       CHECK_FIELD(reg_len);
+       CHECK_FIELD(nr_irqs);
+
+       CHECK_FIELD(runtime_get);
+       CHECK_FIELD(runtime_put);
+       CHECK_FIELD(status_cb);
+       CHECK_FIELD(read_reg);
+       CHECK_FIELD(write_reg);
+#undef CHECK_FIELD
+
+       printf("%s: XXX-BZ TODO\n", __func__);
+       return (0);
+}
+
+void
+linuxkpi_mhi_unregister_controller(struct mhi_controller *mhi_ctrl)
+{
+
+       pr_debug("%s: TODO\n", __func__);
+}
diff --git a/sys/conf/files b/sys/conf/files
index a78c37558227..6a36c46030ce 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -4564,6 +4564,8 @@ compat/linuxkpi/common/src/linux_kthread.c        
optional compat_linuxkpi \
        compile-with "${LINUXKPI_C}"
 compat/linuxkpi/common/src/linux_lock.c                optional 
compat_linuxkpi \
        compile-with "${LINUXKPI_C}"
+compat/linuxkpi/common/src/linux_mhi.c         optional compat_linuxkpi wlan \
+       compile-with "${LINUXKPI_C}"
 compat/linuxkpi/common/src/linux_netdev.c      optional compat_linuxkpi \
        compile-with "${LINUXKPI_C}"
 compat/linuxkpi/common/src/linux_page.c                optional 
compat_linuxkpi \
diff --git a/sys/modules/linuxkpi_wlan/Makefile 
b/sys/modules/linuxkpi_wlan/Makefile
index fccd1249bc72..ef86121366c3 100644
--- a/sys/modules/linuxkpi_wlan/Makefile
+++ b/sys/modules/linuxkpi_wlan/Makefile
@@ -5,6 +5,9 @@ KMOD=   linuxkpi_wlan
 SRCS=  linux_80211.c \
        linux_80211_macops.c
 
+# QCA ath11k support.
+SRCS+= linux_mhi.c
+
 SRCS+= opt_wlan.h
 SRCS+= ${LINUXKPI_GENSRCS}
 

Reply via email to