From c71a82142fc496868cfa5f9d6b38232ef84f2ece Mon Sep 17 00:00:00 2001 From: huyx Date: Sat, 14 Sep 2024 15:34:30 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E9=BB=84=E8=93=9D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- OAT.xml | 1 - adapter/BUILD.gn | 10 +- adapter/khdf/linux/model/usb/host/Kconfig | 8 - adapter/khdf/linux/model/usb/host/Makefile | 3 - .../model/usb/host/include/usb_net_adapter.h | 115 -- .../model/usb/host/src/usb_net_adapter.c | 1220 ----------------- .../khdf/linux/platform/clock/clock_adapter.c | 3 +- adapter/uhdf2/hdi/test/BUILD.gn | 8 + .../servmgr/service_manager_hdi_c_test.cpp | 22 +- .../test/servmgr/service_manager_hdi_test.cpp | 16 + adapter/uhdf2/hdi/test/smq_test/BUILD.gn | 6 +- adapter/uhdf2/hdi/test/smq_test/smq_test.cpp | 13 +- adapter/uhdf2/host/devhost.c | 2 + adapter/uhdf2/host/test/BUILD.gn | 6 +- .../uhdf2/host/test/unittest/devmgr_test.cpp | 5 + .../test/unittest/sample1_driver/BUILD.gn | 44 +- .../host/test/unittest/sample_driver/BUILD.gn | 62 +- .../uhdf2/manager/src/devsvc_manager_stub.c | 2 +- adapter/uhdf2/test/unittest/manager/BUILD.gn | 4 + framework/README_zh.md | 2 +- .../unittest/common/devmgr_uevent_test.cpp | 6 +- .../common/hdf_remote_adapter_test.cpp | 1 + framework/include/platform/clock_if.h | 2 +- .../driver/include/sensor_platform_if.h | 4 +- .../model/usb/include/hdf_usb_net_manager.h | 72 - .../model/usb/include/hdf_usb_pnp_manage.h | 1 - .../platform/include/clock/clock_core.h | 2 +- .../support/platform/src/clock/clock_core.c | 2 +- .../support/platform/src/clock/clock_if.c | 2 +- .../support/platform/src/clock/clock_if_u.c | 2 +- .../test/unittest/common/hdf_clock_test.cpp | 2 +- .../platform/common/clock_driver_test.c | 2 +- .../unittest/platform/common/clock_test.c | 2 +- .../unittest/platform/common/clock_test.h | 2 +- .../platform/entry/hdf_clock_entry_test.c | 2 +- .../platform/entry/hdf_clock_entry_test.h | 2 +- .../unittest/platform/virtual/clock_virtual.c | 2 +- 37 files changed, 162 insertions(+), 1498 deletions(-) delete mode 100755 adapter/khdf/linux/model/usb/host/include/usb_net_adapter.h delete mode 100755 adapter/khdf/linux/model/usb/host/src/usb_net_adapter.c delete mode 100755 framework/model/usb/include/hdf_usb_net_manager.h diff --git a/OAT.xml b/OAT.xml index 8fb234daf..49f506f8f 100644 --- a/OAT.xml +++ b/OAT.xml @@ -67,7 +67,6 @@ Note:If the text contains special characters, please escape them according to th - diff --git a/adapter/BUILD.gn b/adapter/BUILD.gn index 6ac98abab..815188460 100644 --- a/adapter/BUILD.gn +++ b/adapter/BUILD.gn @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") hdf_adapter_path = "." if (defined(ohos_lite)) { @@ -37,8 +38,6 @@ if (defined(ohos_lite)) { "$hdf_adapter_path/uhdf2/hdi:libhdi", "$hdf_adapter_path/uhdf2/host:hdf_devhost", "$hdf_adapter_path/uhdf2/host:libhdf_host", - "$hdf_adapter_path/uhdf2/host/test/unittest/sample1_driver:libsample1_driver", - "$hdf_adapter_path/uhdf2/host/test/unittest/sample_driver:libsample_driver", "$hdf_adapter_path/uhdf2/ipc:libhdf_ipc_adapter", "$hdf_adapter_path/uhdf2/manager:hdf_devmgr", "$hdf_adapter_path/uhdf2/manager:hdf_devmgr.cfg", @@ -50,6 +49,13 @@ if (defined(ohos_lite)) { "$hdf_framework_path/tools/hdf_dbg:hdf_dbg", "$hdf_peripheral_path:hdf_peripheral.cfg", ] + + if (with_sample) { + deps += [ + "$hdf_adapter_path/uhdf2/host/test/unittest/sample1_driver:libsample1_driver", + "$hdf_adapter_path/uhdf2/host/test/unittest/sample_driver:libsample_driver", + ] + } } group("uhdf_test_entry") { testonly = true diff --git a/adapter/khdf/linux/model/usb/host/Kconfig b/adapter/khdf/linux/model/usb/host/Kconfig index 2378468c7..710f80dba 100755 --- a/adapter/khdf/linux/model/usb/host/Kconfig +++ b/adapter/khdf/linux/model/usb/host/Kconfig @@ -15,11 +15,3 @@ config DRIVERS_HDF_USB_PNP_NOTIFY depends on DRIVERS_HDF help Answer Y to choice HDF USB PNP Notify driver. - -config DRIVERS_HDF_USB_NET_ADAPTER - bool "Enable HDF USB NET ADAPTER driver" - default n - depends on DRIVERS_HDF - depends on DRIVERS_HDF_USB_PNP_NOTIFY - help - Answer Y to choice HDF NET ADAPTER driver. diff --git a/adapter/khdf/linux/model/usb/host/Makefile b/adapter/khdf/linux/model/usb/host/Makefile index 752d295db..c01643a5a 100644 --- a/adapter/khdf/linux/model/usb/host/Makefile +++ b/adapter/khdf/linux/model/usb/host/Makefile @@ -13,9 +13,6 @@ USB_PNP_NOTIFY_ROOT_DIR = ./ obj-$(CONFIG_DRIVERS_HDF_USB_PNP_NOTIFY) += \ $(USB_PNP_NOTIFY_ROOT_DIR)/src/usb_pnp_notify.o -obj-$(CONFIG_DRIVERS_HDF_USB_NET_ADAPTER) += \ - $(USB_PNP_NOTIFY_ROOT_DIR)/src/usb_net_adapter.o - ccflags-y += -Wno-incompatible-pointer-types-discards-qualifiers ccflags-y += -lm -lc -lgcc \ -I$(srctree)/drivers/hdf/khdf/model/usb/host/include \ diff --git a/adapter/khdf/linux/model/usb/host/include/usb_net_adapter.h b/adapter/khdf/linux/model/usb/host/include/usb_net_adapter.h deleted file mode 100755 index 349b05c93..000000000 --- a/adapter/khdf/linux/model/usb/host/include/usb_net_adapter.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2024 Archermind Technology (Nanjing) Co. Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#ifndef HDF_NET_USB_ADAPTER_H -#define HDF_NET_USB_ADAPTER_H - -#include "osal_mutex.h" -#include "hdf_log.h" -#include "hdf_usb_net_manager.h" - -#define MODULE_PARAM module_param -#define HARCH_LOG_TAG "[-net-hdf-]" -#define HARCH_NET_INFO_PRINT(fmt, ...) \ -do { \ - if (0) { \ - HDF_LOGI(HARCH_LOG_TAG"[%{public}s][%{public}d]:" fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__);} \ -} while (0) - -typedef struct pcpu_sw_netstats PcpuSwNetstats; -typedef struct net_device NetDevice; -typedef struct timer_list TimerList; -typedef struct work_struct WorkStruct; -typedef struct tasklet_struct TaskletStruct; -typedef struct device_type DeviceType; -typedef struct ethtool_ops EthtoolOps; -typedef struct rndis_data_hdr RndisDataHdr; -typedef struct sk_buff SkBuff; -typedef struct sk_buff_head SkBuffHead; -typedef struct net_device_ops NetDeviceOps; - -struct rndis_data_hdr { - __le32 msg_type; /* RNDIS_MSG_PACKET */ - __le32 msg_len; /* rndis_data_hdr + data_len + pad */ - __le32 data_offset; /* 36 -- right after header */ - __le32 data_len; /* ... real packet size */ - - __le32 oob_data_offset; /* zero */ - __le32 oob_data_len; /* zero */ - __le32 num_oob; /* zero */ - __le32 packet_data_offset; /* zero */ - - __le32 packet_data_len; /* zero */ - __le32 vc_handle; /* zero */ - __le32 reserved; /* zero */ -} __attribute__ ((packed)); - -struct UsbnetAdapter { - struct IDeviceIoService service; - struct HdfDeviceObject *deviceObject; - unsigned canDmaSg : 1; - NetDevice *net; - int32_t msg_enable; - struct UsbnetTransInfo usbnetInfo; - struct OsalMutex sendSkbClock; - - unsigned char pktCnt, pktErr; - - /* various kinds of pending driver work */ - wait_queue_head_t wait; - TimerList delay; - - SkBuffHead rxq; - SkBuffHead txq; - - SkBuffHead done; - SkBuffHead rxqPause; - TaskletStruct bh; - - struct pcpu_sw_netstats __percpu *stats64; - - WorkStruct kevent; - WorkStruct TxCompleteWorkqueue; - WorkStruct RxCompleteWorkqueue; - unsigned int txLen; - unsigned int rxLen; - unsigned long flags; -# define EVENT_TX_HALT 0 -# define EVENT_RX_HALT 1 -# define EVENT_RX_MEMORY 2 -# define EVENT_STS_SPLIT 3 -# define EVENT_LINK_RESET 4 -# define EVENT_RX_PAUSED 5 -# define EVENT_DEV_ASLEEP 6 -# define EVENT_DEV_OPEN 7 -# define EVENT_DEVICE_REPORT_IDLE 8 -# define EVENT_NO_RUNTIME_PM 9 -# define EVENT_RX_KILL 10 -# define EVENT_LINK_CHANGE 11 -# define EVENT_SET_RX_MODE 12 -# define EVENT_NO_IP_ALIGN 13 -}; - -/* we record the state for each of our queued skbs */ -enum SkbState { - ILLEGAL = 0, - TX_START, - TX_DONE, - RX_START, - RX_DONE, - RX_CLEANUP, - UNLINK_START -}; - -struct SkbData { /* skb->cb is one of these */ - enum SkbState state; - long length; - unsigned long packets; -}; - -#endif diff --git a/adapter/khdf/linux/model/usb/host/src/usb_net_adapter.c b/adapter/khdf/linux/model/usb/host/src/usb_net_adapter.c deleted file mode 100755 index b8957f550..000000000 --- a/adapter/khdf/linux/model/usb/host/src/usb_net_adapter.c +++ /dev/null @@ -1,1220 +0,0 @@ -/* - * Copyright (c) 2024 Archermind Technology (Nanjing) Co. Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include -#include -#include - -#include -#include -#include -#if defined(CONFIG_DRIVERS_HDF_IMX8MM_ETHERNET) -#include -#include -#endif - -#include -#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) -#include -#else -#include -#endif -#include "osal_mem.h" -#include "securec.h" - -#include "hdf_device_desc.h" -#include "usb_net_adapter.h" - -#define HDF_LOG_TAG UsbnetAdapter -#define TX_TIMEOUT_JIFFIES (5*HZ) -#define RNDIS_MSG_PACKET 0x00000001 /* 1-N packets */ - -// between wakeups -#define UNLINK_TIMEOUT_MS 3 -#define PKT_COUNT_CLEAR 30 -#define PKT_COUNT_RXKILL 20 -#define SHIFT_LINE_NUM 32 - -/* use ethtool to change the level for any given device */ -static int g_msgLevel = -1; -MODULE_PARAM(g_msgLevel, int, 0); -MODULE_PARM_DESC(g_msgLevel, "Override default message level"); - -static inline int UsbnetAdapterGetTxQlen(struct UsbnetAdapter *usbNet) -{ - return usbNet->usbnetInfo.txQlen; -} - -static int printf_char_buffer(char *buff, int size, bool isPrint) -{ - if (isPrint) { - int i = 0; - printk("===-harch-=== printf_char_buffer begin\n"); - for (i = 0; i < size; i++) { - printk(KERN_CONT"%02x ", buff[i]); - if ((i + 1) % SHIFT_LINE_NUM == 0) { - printk(KERN_CONT"\n"); - } - } - printk("===-harch-=== printf_char_buffer end\n"); - } - return 0; -} - -static int32_t UsbnetAdapterSendBufToUsb(const struct HdfDeviceObject *device, uint32_t id, - const void *buf, uint32_t writeSize) -{ - HARCH_NET_INFO_PRINT("writeSize=%d", writeSize); - int32_t ret = HDF_SUCCESS; - if ((device == NULL) || (buf == NULL)) { - HDF_LOGE("%s param is null", __func__); - return HDF_ERR_INVALID_PARAM; - } - - struct HdfSBuf *data = HdfSbufObtainDefaultSize(); - if (data == NULL) { - HDF_LOGE("fail to obtain sbuf data"); - return HDF_FAILURE; - } - - if (!HdfSbufWriteBuffer(data, buf, writeSize)) { - HDF_LOGE("fail to write sbuf"); - ret = HDF_FAILURE; - goto out; - } - - if (HdfDeviceSendEvent(device, id, data) != HDF_SUCCESS) { - HDF_LOGE("%s: send sensor data event failed", __func__); - ret = HDF_FAILURE; - goto out; - } - ret = HDF_SUCCESS; - -out: - HdfSbufRecycle(data); - return ret; -} - -static void RxComplete(WorkStruct *work) -{ - unsigned long flags = 0; - struct UsbnetAdapter *usbNet = container_of(work, struct UsbnetAdapter, RxCompleteWorkqueue); - PcpuSwNetstats *stats64 = this_cpu_ptr(usbNet->stats64); - - HARCH_NET_INFO_PRINT("rx_complete stats64->rx_packets = %lu,usbNet stats64->rx_bytes = %lu", - stats64->rx_packets, stats64->rx_bytes); - - HARCH_NET_INFO_PRINT("rx_complete stats64->tx_packets = %lu,usbNet stats64->tx_bytes = %lu", - stats64->tx_packets, stats64->tx_bytes); - - flags = u64_stats_update_begin_irqsave(&stats64->syncp); -#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) - stats64->rx_packets++; - stats64->rx_bytes += usbNet->rxLen; -#else - u64_stats_inc(&stats64->rx_packets); - u64_stats_add(&stats64->rx_bytes, usbNet->rxLen); -#endif - u64_stats_update_end_irqrestore(&stats64->syncp, flags); - - HARCH_NET_INFO_PRINT("rx_complete stats64->rx_packets = %lu,usbNet stats64->rx_bytes = %lu", - stats64->rx_packets, stats64->rx_bytes); - - HARCH_NET_INFO_PRINT("rx_complete stats64->tx_packets = %lu,usbNet stats64->tx_bytes = %lu", - stats64->tx_packets, stats64->tx_bytes); -} - -/* Passes this packet up the stack, updating its accounting. - * Some link protocols batch packets, so their rx_fixup paths - * can return clones as well as just modify the original skb. - */ -static void UsbnetAdapterSkbReturn(struct UsbnetAdapter *usbNet, SkBuff *skb) -{ - if (test_bit(EVENT_RX_PAUSED, &usbNet->flags)) { - skb_queue_tail(&usbNet->rxqPause, skb); - return; - } - - /* only update if unset to allow minidriver rx_fixup override */ - if (skb->protocol == 0) { - skb->protocol = eth_type_trans (skb, usbNet->net); - } - - usbNet->rxLen = skb->len; - schedule_work_on(0, &usbNet->RxCompleteWorkqueue); - HARCH_NET_INFO_PRINT("< rx, len %zu, type 0x%x\n", skb->len + sizeof (struct ethhdr), skb->protocol); - (void)memset_s(skb->cb, sizeof(struct SkbData), 0, sizeof(struct SkbData)); - - if (skb_defer_rx_timestamp(skb)) { - return; - } - HARCH_NET_INFO_PRINT("-------rx before netif_rx"); - printf_char_buffer(skb->data, skb->len, false); - - int status = NET_RX_SUCCESS; - status = netif_rx (skb); - - HARCH_NET_INFO_PRINT("netif_rx status %d\n", status); - if (status != NET_RX_SUCCESS) { - HARCH_NET_INFO_PRINT("netif_rx status %d\n", status); - } -} - - -/* - * DATA -- host must not write zlps - */ -static int RndisRxFixup(struct UsbnetAdapter *usbNet, SkBuff *skb) -{ - /* This check is no longer done by usbnet */ - if (skb->len < usbNet->net->hard_header_len) { - return 0; - } - /* peripheral may have batched packets to us... */ - while (likely(skb->len)) { - RndisDataHdr *hdr = (void *)skb->data; - SkBuff *skb2 = NULL; - u32 msg_type = 0; - u32 msg_len = 0; - u32 data_len = 0; - u32 data_offset = 0; - - msg_type = le32_to_cpu(hdr->msg_type); - msg_len = le32_to_cpu(hdr->msg_len); - data_offset = le32_to_cpu(hdr->data_offset); - data_len = le32_to_cpu(hdr->data_len); - unsigned int totalLen = data_offset + data_len + 8; - - /* don't choke if we see oob, per-packet data, etc */ - if (unlikely(msg_type != RNDIS_MSG_PACKET || skb->len < msg_len - || totalLen > msg_len)) { - usbNet->net->stats.rx_frame_errors++; - netdev_dbg(usbNet->net, "bad rndis message %d/%d/%d/%d, len %d\n", - le32_to_cpu(hdr->msg_type), msg_len, data_offset, data_len, skb->len); - return 0; - } - unsigned int offset = 8 + data_offset; - skb_pull(skb, offset); - - /* at most one packet left? */ - if (likely((data_len - skb->len) <= sizeof(RndisDataHdr))) { - skb_trim(skb, data_len); - break; - } - - /* try to return all the packets in the batch */ - skb2 = skb_clone(skb, GFP_ATOMIC); - if (unlikely(!skb2)) { - break; - } - skb_pull(skb, msg_len - sizeof(RndisDataHdr)); - skb_trim(skb2, data_len); - UsbnetAdapterSkbReturn(usbNet, skb2); - } - return 1; -} - -static void UsbnetAdapterRxProcess(struct UsbnetAdapter *usbNet, SkBuff *skb) -{ - HARCH_NET_INFO_PRINT("-------rx before fix"); - printf_char_buffer(skb->data, skb->len, false); - - if (!RndisRxFixup(usbNet, skb)) { - /* With RX_ASSEMBLE, rx_fixup() must update counters */ - if (!(usbNet->usbnetInfo.usbFlags & FLAG_RX_ASSEMBLE)) { - usbNet->net->stats.rx_errors++; - } - goto done; - } - // else network stack removes extra byte if we forced a short packet - HARCH_NET_INFO_PRINT("--------rx after fix"); - printf_char_buffer(skb->data, skb->len, false); - - /* all data was already cloned from skb inside the driver */ - if (usbNet->usbnetInfo.usbFlags & FLAG_MULTI_PACKET) { - HARCH_NET_INFO_PRINT("usbNet->driver_info->flags = %d", usbNet->usbnetInfo.usbFlags); - goto done; - } - - if (skb->len < ETH_HLEN) { - usbNet->net->stats.rx_errors++; - usbNet->net->stats.rx_length_errors++; - HARCH_NET_INFO_PRINT("rx length %d\n", skb->len); - } else { - HARCH_NET_INFO_PRINT("UsbnetAdapterSkbReturn"); - UsbnetAdapterSkbReturn(usbNet, skb); - return; - } - -done: - skb_queue_tail(&usbNet->done, skb); -} - -static void UsbnetAdapterBh(TimerList *t) -{ - HARCH_NET_INFO_PRINT("begin"); - struct UsbnetAdapter *usbNet = from_timer(usbNet, t, delay); - - SkBuff *skb = NULL; - struct SkbData *entry = NULL; - - while ((skb = skb_dequeue (&usbNet->done))) { - entry = (struct SkbData *) skb->cb; - HARCH_NET_INFO_PRINT("entry->state = %d", entry->state); - - switch (entry->state) { - case RX_DONE: - HARCH_NET_INFO_PRINT("rx_done"); - entry->state = RX_CLEANUP; - UsbnetAdapterRxProcess (usbNet, skb); - continue; - case TX_DONE: - HARCH_NET_INFO_PRINT("tx_done"); - /* fall-through */ - fallthrough; - case RX_CLEANUP: - HARCH_NET_INFO_PRINT("rx_cleanup"); - dev_kfree_skb (skb); - continue; - default: - HARCH_NET_INFO_PRINT("bogus skb state %d\n", entry->state); - /* fall-through */ - } - } - HARCH_NET_INFO_PRINT(); - /* restart RX again after disabling due to high error rate */ - clear_bit(EVENT_RX_KILL, &usbNet->flags); - - /* waiting for all pending urbs to complete? - * only then can we forgo submitting anew - */ - if (waitqueue_active(&usbNet->wait)) { - HARCH_NET_INFO_PRINT("waitqueue_active"); - if (usbNet->rxq.qlen + usbNet->txq.qlen + usbNet->done.qlen == 0) { - HARCH_NET_INFO_PRINT(); - wake_up_all(&usbNet->wait); - } - } - - if (usbNet->txq.qlen < UsbnetAdapterGetTxQlen(usbNet)) { - netif_wake_queue (usbNet->net); - HARCH_NET_INFO_PRINT("usbNet->txq.qlen = %d, TX_QLEN (usbNet) = %d", - usbNet->txq.qlen, UsbnetAdapterGetTxQlen(usbNet)); - } - HARCH_NET_INFO_PRINT("end"); -} - -static void UsbnetAdapterBhTasklet(unsigned long data) -{ - HARCH_NET_INFO_PRINT("begin"); - TimerList *t = (TimerList *)data; - - UsbnetAdapterBh(t); - HARCH_NET_INFO_PRINT("end"); -} - -/* The caller must hold list->lock */ -static void UsbnetAdapterQueueSkb(SkBuffHead *list, - SkBuff *newsk, enum SkbState state) -{ - struct SkbData *entry = (struct SkbData *) newsk->cb; - - __skb_queue_tail(list, newsk); - entry->state = state; -} - -static enum SkbState UsbnetAdapterDeferBh(struct UsbnetAdapter *usbNet, SkBuff *skb, - SkBuffHead *list, enum SkbState state) -{ - unsigned long flags = 0; - enum SkbState old_state = ILLEGAL; - struct SkbData *entry = (struct SkbData *) skb->cb; - - spin_lock_irqsave(&list->lock, flags); - old_state = entry->state; - entry->state = state; - __skb_unlink(skb, list); - - /* UsbnetAdapterDeferBh() is never called with list == &usbNet->done. - * spin_lock_nested() tells lockdep that it is OK to take - * usbNet->done.lock here with list->lock held. - */ - spin_lock_nested(&usbNet->done.lock, SINGLE_DEPTH_NESTING); - - __skb_queue_tail(&usbNet->done, skb); - if (usbNet->done.qlen == 1) { - tasklet_schedule(&usbNet->bh); - } - - spin_unlock(&usbNet->done.lock); - spin_unlock_irqrestore(&list->lock, flags); - return old_state; -} - -static int32_t UsbnetAdapterOpen(NetDevice *net) -{ - HARCH_NET_INFO_PRINT("begin"); - if (NULL == net) { - HDF_LOGE("net device object is invalid"); - return HDF_FAILURE; - } - struct UsbnetAdapter *usbNet = netdev_priv(net); - if (NULL == usbNet) { - HDF_LOGE("usb net adapter object is invalid"); - return HDF_FAILURE; - } - - set_bit(EVENT_DEV_OPEN, &usbNet->flags); - - netif_start_queue (net); - - /* set device param, if find usb net host need, then it should send to it */ - /* reset rx error state */ - usbNet->pktCnt = 0; - usbNet->pktErr = 0; - clear_bit(EVENT_RX_KILL, &usbNet->flags); - - /* send info to usb start usb function */ - /* need transform usb_net_host change about usbNet->driverInfo->flags and set it on usb_net_host */ - OsalMutexLock(&usbNet->sendSkbClock); - int32_t ret = UsbnetAdapterSendBufToUsb(usbNet->deviceObject, USB_NET_OPEN_USB, - (const void *)&usbNet->flags, sizeof(usbNet->flags)); - if (ret != HDF_SUCCESS) { - HDF_LOGE("fail to UsbnetAdapterSendBufToUsb SendEvent!"); - OsalMutexUnlock(&usbNet->sendSkbClock); - return HDF_FAILURE; - } - OsalMutexUnlock(&usbNet->sendSkbClock); - - tasklet_schedule (&usbNet->bh); - return HDF_SUCCESS; -} - -static void WaitSkbQueueEmpty(SkBuffHead *q) -{ - unsigned long flags = 0; - HARCH_NET_INFO_PRINT(); - spin_lock_irqsave(&q->lock, flags); - while (!skb_queue_empty(q)) { - spin_unlock_irqrestore(&q->lock, flags); - schedule_timeout(msecs_to_jiffies(UNLINK_TIMEOUT_MS)); - set_current_state(TASK_UNINTERRUPTIBLE); - spin_lock_irqsave(&q->lock, flags); - } - spin_unlock_irqrestore(&q->lock, flags); -} - -// precondition: never called in_interrupt -static void UsbnetAdapterTerminateUrbs(struct UsbnetAdapter *usbNet) -{ - HARCH_NET_INFO_PRINT(); - - DECLARE_WAITQUEUE(wait, current); - /* ensure there are no more active urbs */ - add_wait_queue(&usbNet->wait, &wait); - set_current_state(TASK_UNINTERRUPTIBLE); - /* maybe wait for deletions to finish. */ - WaitSkbQueueEmpty(&usbNet->rxq); - WaitSkbQueueEmpty(&usbNet->txq); - - WaitSkbQueueEmpty(&usbNet->done); - set_current_state(TASK_RUNNING); - remove_wait_queue(&usbNet->wait, &wait); -} - -static int32_t UsbnetAdapterStop(NetDevice *net) -{ - HARCH_NET_INFO_PRINT("begin"); - if (NULL == net) { - HDF_LOGE("net device object is invalid"); - return HDF_FAILURE; - } - - struct UsbnetAdapter *usbNet = netdev_priv(net); - if (NULL == usbNet) { - HDF_LOGE("usb net adapter object is invalid"); - return HDF_FAILURE; - } - - PcpuSwNetstats *stats64 = this_cpu_ptr(usbNet->stats64); - - HARCH_NET_INFO_PRINT("usbNet stats64->rx_packets = %lu,usbNet stats64->rx_bytes = %lu", - stats64->rx_packets, stats64->rx_bytes); - - HARCH_NET_INFO_PRINT("usbNet stats64->tx_packets = %lu,usbNet stats64->tx_bytes = %lu", - stats64->tx_packets, stats64->tx_bytes); - - /* 1. clear_bit EVENT_DEV_OPEN dev->flags */ - clear_bit(EVENT_DEV_OPEN, &usbNet->flags); - /* 2. netif_stop_queue net */ - netif_stop_queue (net); - HARCH_NET_INFO_PRINT("stop stats: rx/tx %lu/%lu, errs %lu/%lu\n", - net->stats.rx_packets, net->stats.tx_packets, - net->stats.rx_errors, net->stats.tx_errors); - - /* 3. pm = usb_autopm_get_interface(dev->intf); do nothing */ - /* 4. if (info->stop) { no stop interface impl in rndis driver info */ - /* 5. if (!(info->flags & FLAG_AVOID_UNLINK_URBS)) do nothing*/ - if (!(usbNet->usbnetInfo.usbFlags & FLAG_AVOID_UNLINK_URBS)) { - UsbnetAdapterTerminateUrbs(usbNet); - } - - /* 6. usbnet_status_stop none */ - /* 7. usbnet_purge_paused_rxq none */ - skb_queue_purge(&usbNet->rxqPause); - /* 8. test_and_clear_bit and no manage_power interface impl in rndis driver info*/ - /* 9. dev flags */ - usbNet->flags = 0; - OsalMutexLock(&usbNet->sendSkbClock); - int32_t ret = UsbnetAdapterSendBufToUsb(usbNet->deviceObject, USB_NET_CLOSE_USB, - (const void *)&usbNet->flags, sizeof(usbNet->flags)); - if (ret != HDF_SUCCESS) { - HDF_LOGE("fail to UsbnetAdapterSendBufToUsb SendEvent!"); - OsalMutexUnlock(&usbNet->sendSkbClock); - return HDF_FAILURE; - } - OsalMutexUnlock(&usbNet->sendSkbClock); - /* 10. del_timer_sync */ - del_timer_sync (&usbNet->delay); - /* 11. tasklet_kill */ - tasklet_kill (&usbNet->bh); - /* 12. cancel_work_sync dev->kevent */ - cancel_work_sync(&usbNet->TxCompleteWorkqueue); - cancel_work_sync(&usbNet->RxCompleteWorkqueue); - return HDF_SUCCESS; -} - -static SkBuff *RndisTxFixup(SkBuff *skb, gfp_t flags) -{ - RndisDataHdr *hdr = NULL; - SkBuff *skb2 = NULL; - unsigned len = skb->len; - - if (likely(!skb_cloned(skb))) { - int room = skb_headroom(skb); - /* enough head room as-is? */ - if (unlikely((sizeof(RndisDataHdr)) <= room)) { - goto fill; - } - /* enough room, but needs to be readjusted? */ - room += skb_tailroom(skb); - if (likely((sizeof(RndisDataHdr)) <= room)) { - skb->data = memmove_s(skb->head + sizeof(RndisDataHdr), len, skb->data, len); - skb_set_tail_pointer(skb, len); - goto fill; - } - } - - /* create a new skb, with the correct size (and tailpad) */ - skb2 = skb_copy_expand(skb, sizeof(RndisDataHdr), 1, flags); - dev_kfree_skb_any(skb); - if (unlikely(!skb2)) { - return skb2; - } - skb = skb2; - - /* fill out the RNDIS header. we won't bother trying to batch - * packets; Linux minimizes wasted bandwidth through tx queues. - */ -fill: - HARCH_NET_INFO_PRINT("%s:%d fill skb by rndis host", __func__, __LINE__); - hdr = __skb_push(skb, sizeof(*hdr)); - (void)memset_s(hdr, sizeof(*hdr), 0, sizeof(*hdr)); - hdr->msg_type = cpu_to_le32(RNDIS_MSG_PACKET); - hdr->msg_len = cpu_to_le32(skb->len); - unsigned int offset = sizeof(*hdr) - 8; - hdr->data_offset = cpu_to_le32(offset); - hdr->data_len = cpu_to_le32(len); - - return skb; -} - -static void TxComplete(WorkStruct *work) -{ - unsigned long flags = 0; - struct UsbnetAdapter *usbNet = container_of(work, struct UsbnetAdapter, TxCompleteWorkqueue); - PcpuSwNetstats *stats64 = this_cpu_ptr(usbNet->stats64); - HARCH_NET_INFO_PRINT ("tx_complete stats64->rx_packets = %lu,usbNet stats64->rx_bytes = %lu", - stats64->rx_packets, stats64->rx_bytes); - - HARCH_NET_INFO_PRINT ("tx_complete stats64->tx_packets = %lu,usbNet stats64->tx_bytes = %lu", - stats64->tx_packets, stats64->tx_bytes); - - flags = u64_stats_update_begin_irqsave(&stats64->syncp); -#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) - stats64->tx_packets++; - stats64->tx_bytes += usbNet->txLen; -#else - u64_stats_inc(&stats64->tx_packets); - u64_stats_add(&stats64->tx_bytes, usbNet->txLen); -#endif - u64_stats_update_end_irqrestore(&stats64->syncp, flags); - - HARCH_NET_INFO_PRINT ("tx_complete stats64->rx_packets = %lu,usbNet stats64->rx_bytes = %lu", - stats64->rx_packets, stats64->rx_bytes); - - HARCH_NET_INFO_PRINT ("tx_complete stats64->tx_packets = %lu,usbNet stats64->tx_bytes = %lu", - stats64->tx_packets, stats64->tx_bytes); -} - -static netdev_tx_t UsbnetAdapterStartXmit(SkBuff *skb, NetDevice *net) -{ - HARCH_NET_INFO_PRINT ("netif_running=%d, netif_device_present=%d, netif_carrier_ok=%d", netif_running(net), - netif_device_present(net), netif_carrier_ok(net)); - HARCH_NET_INFO_PRINT ("skb->data = %x, len = %d", skb->data, skb->len); - struct UsbnetAdapter *usbNet = netdev_priv(net); - //1.time tamp - if (skb) { - skb_tx_timestamp(skb); - } - //2.fix up - SkBuff* skbFixup = RndisTxFixup(skb, GFP_ATOMIC); - if (NULL == skbFixup) { - if (usbNet->usbnetInfo.usbFlags & FLAG_MULTI_PACKET) { - goto not_drop; - } - HDF_LOGE("fail to tx fixup by rndis host"); - goto drop; - } - HARCH_NET_INFO_PRINT("skb_fixup->data = %x, len = %d", skbFixup->data, skbFixup->len); - /* print org skb data info */ - printf_char_buffer(skbFixup->data, skbFixup->len, false); - //3.send msg to usb - unsigned long flags = 0; - spin_lock_irqsave(&usbNet->txq.lock, flags); - if (netif_queue_stopped(usbNet->net)) { - goto drop; - } - - int32_t ret = UsbnetAdapterSendBufToUsb(usbNet->deviceObject, USB_NET_SEND_DATA_TO_USB, - (unsigned char *)(skbFixup->data), skbFixup->len); - if (ret != HDF_SUCCESS) { - HDF_LOGE("fail to UsbnetHost SendEvent!"); -drop: - net->stats.tx_dropped++; -not_drop: - spin_unlock_irqrestore(&usbNet->txq.lock, flags); - if (skbFixup) { - dev_kfree_skb_any (skbFixup); - } - } else { - netif_trans_update(usbNet->net); - UsbnetAdapterQueueSkb(&usbNet->txq, skbFixup, TX_START); - - if (usbNet->txq.qlen >= UsbnetAdapterGetTxQlen(usbNet)) { - HARCH_NET_INFO_PRINT("usbNet->txq.qlen = %d, TX_QLEN (usbNet) = %d", - usbNet->txq.qlen, UsbnetAdapterGetTxQlen(usbNet)); - netif_stop_queue (usbNet->net); - } - spin_unlock_irqrestore(&usbNet->txq.lock, flags); - usbNet->txLen = skbFixup->len; - schedule_work_on(0, &usbNet->TxCompleteWorkqueue); - - enum SkbState state = UsbnetAdapterDeferBh(usbNet, skbFixup, &usbNet->txq, TX_DONE); - HARCH_NET_INFO_PRINT("state= %d", state); - } - return NETDEV_TX_OK; -} - -static void UsbnetAdapterTXTimeout(NetDevice *net, unsigned int txqueue) -{ - //send to device - HARCH_NET_INFO_PRINT("begin"); - if (NULL == net) { - HDF_LOGE("%s net device object is invalid", __func__); - return; - } - struct UsbnetAdapter *usbNet = netdev_priv(net); - if (NULL == usbNet) { - HDF_LOGE("%s UsbnetAdapter object is invalid", __func__); - return; - } - /* 1. unlink_urbs (dev, &dev->txq); maybe later be used */ - - /* 2. tasklet_schedule (&dev->bh) */ - tasklet_schedule (&usbNet->bh); - - /* 3. if (dev->driver_info->recover) none, rndis host no recover impl */ - - return; -} - -/* some work can't be done in tasklets, so we use keventd - * - * NOTE: annoying asymmetry: if it's active, schedule_work() fails, - * but tasklet_schedule() doesn't. hope the failure is rare. - */ -static void UsbnetAdapterDeferKevent(struct UsbnetAdapter *usbNet, int work) -{ - HARCH_NET_INFO_PRINT("begin"); - if (NULL == usbNet) { - HDF_LOGE("%s UsbnetAdapter object is invalid", __func__); - return; - } - set_bit (work, &usbNet->flags); - /* need update flags to usb_net_host */ - OsalMutexLock(&usbNet->sendSkbClock); - int32_t ret = UsbnetAdapterSendBufToUsb(usbNet->deviceObject, USB_NET_UPDATE_FLAGS, - (const void *)&usbNet->flags, sizeof(usbNet->flags)); - if (ret != HDF_SUCCESS) { - HDF_LOGE("fail to UsbnetAdapterSendBufToUsb SendEvent!"); - OsalMutexUnlock(&usbNet->sendSkbClock); - return; - } - OsalMutexUnlock(&usbNet->sendSkbClock); - - if (!schedule_work (&usbNet->kevent)) { - HARCH_NET_INFO_PRINT("kevent %d may have been dropped\n", work); - } else { - HARCH_NET_INFO_PRINT("kevent %d scheduled\n", work); - } -} - -static void UsbnetAdapterSetRxMode(NetDevice *net) -{ - return; -} - -static void UsbnetAdapterPauseRx(struct UsbnetAdapter *usbNet) -{ - HARCH_NET_INFO_PRINT("begin"); - if (NULL == usbNet) { - HDF_LOGE("%s UsbnetAdapter object is invalid", __func__); - return; - } - set_bit(EVENT_RX_PAUSED, &usbNet->flags); - /* need update flags to usb_net_host */ - OsalMutexLock(&usbNet->sendSkbClock); - int32_t ret = UsbnetAdapterSendBufToUsb(usbNet->deviceObject, USB_NET_UPDATE_FLAGS, - (const void *)&usbNet->flags, sizeof(usbNet->flags)); - if (ret != HDF_SUCCESS) { - HDF_LOGE("fail to UsbnetAdapterSendBufToUsb SendEvent!"); - OsalMutexUnlock(&usbNet->sendSkbClock); - return; - } - OsalMutexUnlock(&usbNet->sendSkbClock); - - HARCH_NET_INFO_PRINT("paused rx queue enabled\n"); -} - -static void UsbnetAdapterUnlinkRxUrbs(struct UsbnetAdapter *usbNet) -{ - HARCH_NET_INFO_PRINT("begin"); - if (NULL == usbNet) { - HDF_LOGE("%s UsbnetAdapter object is invalid", __func__); - return; - } - - if (netif_running(usbNet->net)) { - /* unlink_urbs usbNet usbNet->rxq */ - tasklet_schedule(&usbNet->bh); - } -} - -static void UsbnetAdapterResumeRx(struct UsbnetAdapter *usbNet) -{ - HARCH_NET_INFO_PRINT("begin"); - int num = 0; - SkBuff *skb = NULL; - if (NULL == usbNet) { - HDF_LOGE("%s UsbnetAdapter object is invalid", __func__); - return; - } - - clear_bit(EVENT_RX_PAUSED, &usbNet->flags); - /* need update flags to usb_net_host */ - OsalMutexLock(&usbNet->sendSkbClock); - int32_t ret = UsbnetAdapterSendBufToUsb(usbNet->deviceObject, USB_NET_UPDATE_FLAGS, - (const void *)&usbNet->flags, sizeof(usbNet->flags)); - if (ret != HDF_SUCCESS) { - HDF_LOGE("fail to UsbnetAdapterSendBufToUsb SendEvent!"); - OsalMutexUnlock(&usbNet->sendSkbClock); - return; - } - OsalMutexUnlock(&usbNet->sendSkbClock); - - while ((skb = skb_dequeue(&usbNet->rxqPause)) != NULL) { - UsbnetAdapterSkbReturn(usbNet, skb); - num++; - } - - tasklet_schedule(&usbNet->bh); - HARCH_NET_INFO_PRINT("paused rx queue disabled, %d skbs requeued\n", num); -} - - -static int32_t UsbnetAdapterChangeMtu(NetDevice *net, int newMtu) -{ - //send to device - HARCH_NET_INFO_PRINT("begin"); - if (NULL == net) { - HDF_LOGE("%s net device object is invalid", __func__); - return HDF_FAILURE; - } - - struct UsbnetAdapter *usbNet = netdev_priv(net); - if (NULL == usbNet) { - HDF_LOGE("%s UsbnetAdapter object is invalid", __func__); - return HDF_FAILURE; - } - - /* 1. ll_mtu old_hard_mtu old_rx_urb_size */ - HARCH_NET_INFO_PRINT("newMtu:%d", newMtu); - int llMtu = newMtu + net->hard_header_len; - int oldHardMtu = usbNet->usbnetInfo.hardMtu; - int oldRxUrbSize = usbNet->usbnetInfo.rxUrbSize; - - /* 2. no second zero-length packet read wanted after mtu-sized packets */ - if ((llMtu % usbNet->usbnetInfo.maxpacket) == 0) { - HARCH_NET_INFO_PRINT(""); - return -EDOM; - } - - /* 3. set usbNet->hard_mtu */ - net->mtu = newMtu; - usbNet->usbnetInfo.hardMtu = net->mtu + net->hard_header_len; - - /* 4. pause and resume usbnet */ - if (usbNet->usbnetInfo.rxUrbSize == oldHardMtu) { - usbNet->usbnetInfo.rxUrbSize = usbNet->usbnetInfo.hardMtu; - if (usbNet->usbnetInfo.rxUrbSize > oldRxUrbSize) { - UsbnetAdapterPauseRx(usbNet); - UsbnetAdapterUnlinkRxUrbs(usbNet); - UsbnetAdapterResumeRx(usbNet); - } - } - - /* need transmit hard_mtu to usb net host, UsbnetHostUpdateMaxQlen need this param */ - HARCH_NET_INFO_PRINT("name = %s, flags = %d, usbFlags = %x mtu = %d, hardHeaderLen = %d,\ - link = %d needReset = %d, hardMtu = %d, rxUrbSize = %d, maxpacket =%d", - usbNet->usbnetInfo.name,usbNet->usbnetInfo.flags,usbNet->usbnetInfo.usbFlags,\ - usbNet->usbnetInfo.mtu,usbNet->usbnetInfo.hardHeaderLen,usbNet->usbnetInfo.link,\ - usbNet->usbnetInfo.needReset,usbNet->usbnetInfo.hardMtu,usbNet->usbnetInfo.rxUrbSize,\ - usbNet->usbnetInfo.maxpacket); - /* 5. max qlen depend on hard_mtu and rx_urb_size */ - /* need update flags to usb_net_host */ - OsalMutexLock(&usbNet->sendSkbClock); - int32_t ret = UsbnetAdapterSendBufToUsb(usbNet->deviceObject, USB_NET_UPDATE_MAXQLEN, - (const void *)&usbNet->usbnetInfo, sizeof(usbNet->usbnetInfo)); - if (ret != HDF_SUCCESS) { - HDF_LOGE("fail to UsbnetAdapterSendBufToUsb SendEvent!"); - OsalMutexUnlock(&usbNet->sendSkbClock); - return ret; - } - OsalMutexUnlock(&usbNet->sendSkbClock); - return HDF_SUCCESS; -} - -static void UsbnetAdapterGetStats64(NetDevice *net, struct rtnl_link_stats64 *stats) -{ - //send to device - HARCH_NET_INFO_PRINT("begin"); - - struct UsbnetAdapter *usbNet = netdev_priv(net); - netdev_stats_to_stats64(stats, &net->stats); - dev_fetch_sw_netstats(stats, usbNet->stats64); - - PcpuSwNetstats *stats64 = this_cpu_ptr(usbNet->stats64); - - HARCH_NET_INFO_PRINT ("usbNet stats64->rx_packets = %lu,usbNet stats64->rx_bytes = %lu", - stats64->rx_packets, stats64->rx_bytes); - - HARCH_NET_INFO_PRINT ("usbNet stats64->tx_packets = %lu,usbNet stats64->tx_bytes = %lu", - stats64->tx_packets, stats64->tx_bytes); - - HARCH_NET_INFO_PRINT("end"); - return; -} - -static NetDeviceOps g_UsbnetAdapterDeviceOps = { - .ndo_open = UsbnetAdapterOpen, - .ndo_stop = UsbnetAdapterStop, - .ndo_start_xmit = UsbnetAdapterStartXmit, - .ndo_tx_timeout = UsbnetAdapterTXTimeout, - .ndo_set_rx_mode = UsbnetAdapterSetRxMode, - .ndo_change_mtu = UsbnetAdapterChangeMtu, - .ndo_get_stats64 = UsbnetAdapterGetStats64, - .ndo_set_mac_address = eth_mac_addr, - .ndo_validate_addr = eth_validate_addr, -}; - -/* drivers may override default ethtool_ops in their bind() routine */ -static const EthtoolOps g_UsbnetAdapterEthtoolOps = { -}; - -static void UsbnetAdapterLinkChange(struct UsbnetAdapter *usbNet, bool link, bool need_reset) -{ - HARCH_NET_INFO_PRINT("begin"); - /* update link after link is reseted */ - if (link && !need_reset) { - netif_carrier_on(usbNet->net); - } else { - netif_carrier_off(usbNet->net); - } -} - -static int32_t UsbnetAdapterSetSkb(struct UsbnetAdapter *usbNet, gfp_t flags, - uint32_t infoSize, unsigned char *buff, SkBuff *skb) -{ - if (!skb) { - HARCH_NET_INFO_PRINT("no rx skb\n"); - UsbnetAdapterDeferKevent(usbNet, EVENT_RX_MEMORY); - return HDF_DEV_ERR_NO_MEMORY; - } - - skb_put(skb, infoSize); - if (memcpy_s(skb->data, infoSize, buff, infoSize) != EOK) { - HARCH_NET_INFO_PRINT("memcpy_s error "); - return HDF_ERR_INVALID_PARAM; - } - - printf_char_buffer(skb->data, skb->len, false); - return HDF_SUCCESS; -} - -static void UsbnetAdapterSetUsbNetInfo(struct UsbnetAdapter *usbNet, SkBuff *skb, enum SkbState state) -{ - unsigned long lockflags = 0; - spin_lock_irqsave (&usbNet->rxq.lock, lockflags); - UsbnetAdapterQueueSkb(&usbNet->rxq, skb, RX_START); - spin_unlock_irqrestore (&usbNet->rxq.lock, lockflags); - - PcpuSwNetstats *stats64 = this_cpu_ptr(usbNet->stats64); - HARCH_NET_INFO_PRINT("usbNet stats64->rx_packets = %lu,usbNet stats64->rx_bytes = %lu", - stats64->rx_packets, stats64->rx_bytes); - - if (++usbNet->pktCnt > PKT_COUNT_CLEAR) { - HARCH_NET_INFO_PRINT("usbNet->pktCnt = %d, pktErr = %d", usbNet->pktCnt, usbNet->pktErr); - usbNet->pktCnt = 0; - usbNet->pktErr = 0; - } else { - HARCH_NET_INFO_PRINT("usbNet->pktCnt = %d,pktErr = %d", usbNet->pktCnt, usbNet->pktErr); - if (state == RX_CLEANUP) { - usbNet->pktErr++; - } - - if (usbNet->pktErr > PKT_COUNT_RXKILL) { - set_bit(EVENT_RX_KILL, &usbNet->flags); - } - } -} - -static int32_t UsbnetAdapterRxComplete(struct HdfDeviceObject *device, struct HdfSBuf *data, gfp_t flags) -{ - HARCH_NET_INFO_PRINT("begin"); - unsigned char *buff = NULL; - uint32_t infoSize = 0; - bool flag = HdfSbufReadBuffer(data, (const void **)(&(buff)), &infoSize); - if ((!flag) || buff == NULL) { - HDF_LOGE("%s: fail to read infoTable in event data, flag = %d", __func__, flag); - return HDF_ERR_INVALID_PARAM; - } - - NetDevice *net = (NetDevice *)device->priv; - if (net == NULL) { - return HDF_ERR_INVALID_PARAM; - } - printf_char_buffer(buff, infoSize, false); - struct UsbnetAdapter *usbNet = netdev_priv(net); - if (usbNet == NULL) { - return HDF_ERR_INVALID_PARAM; - } - - SkBuff *skb = NULL; - uint32_t skb_size = sizeof(struct iphdr) + sizeof(struct udphdr) + infoSize; - size_t size = skb_size > usbNet->usbnetInfo.rxUrbSize ? usbNet->usbnetInfo.rxUrbSize : skb_size; - if (test_bit(EVENT_NO_IP_ALIGN, &usbNet->flags)) { - skb = __netdev_alloc_skb(usbNet->net, size, flags); - } else { - skb = __netdev_alloc_skb_ip_align(usbNet->net, size, flags); - } - int32_t ret = UsbnetAdapterSetSkb(usbNet, flags, infoSize, buff, skb); - if (ret != HDF_SUCCESS || skb == NULL) { - HDF_LOGE("%s: fail to set skb, flag = %d", __func__, flag); - return ret; - } - HARCH_NET_INFO_PRINT("infoSize= %d, size = %d, skb->len = %d", infoSize, size, skb->len); - - struct SkbData *entry = (struct SkbData *)skb->cb; - entry->length = 0; - - //success recv - enum SkbState state = RX_DONE; - UsbnetAdapterSetUsbNetInfo(usbNet, skb, state); - - state = UsbnetAdapterDeferBh(usbNet, skb, &usbNet->rxq, state); - HARCH_NET_INFO_PRINT("usbNet->pktCnt = %d, pktErr = %d, state = %d", usbNet->pktCnt, usbNet->pktErr, state); - return HDF_SUCCESS; -} - -// precondition: never called in_interrupt -static DeviceType wlanType = { - .name = "wlan", -}; - -static DeviceType wwanType = { - .name = "wwan", -}; - -static void UsbnetAdapterSetUsbNet(struct HdfDeviceObject *device, - NetDevice *net, struct UsbnetTransInfo *uNetTransInfo) -{ - struct UsbnetAdapter *usbNet = netdev_priv(net); - usbNet->deviceObject = device; - - //info from usb - if (memcpy_s(&(usbNet->usbnetInfo), sizeof(struct UsbnetTransInfo), - uNetTransInfo, sizeof(struct UsbnetTransInfo)) != EOK) { - HARCH_NET_INFO_PRINT("memcpy_s error "); - } - - HARCH_NET_INFO_PRINT("name = %s, flags = %d, usbFlags = %x, mtu = %d, \ - hardHeaderLen = %d, link = %d, needReset = %d, \ - hardMtu = %d, rxUrbSize = %d, maxpacket = %d", - usbNet->usbnetInfo.name, usbNet->usbnetInfo.flags, - usbNet->usbnetInfo.usbFlags, usbNet->usbnetInfo.mtu, - usbNet->usbnetInfo.hardHeaderLen, usbNet->usbnetInfo.link, - usbNet->usbnetInfo.needReset, usbNet->usbnetInfo.hardMtu, - usbNet->usbnetInfo.rxUrbSize, usbNet->usbnetInfo.maxpacket); - - usbNet->stats64 = netdev_alloc_pcpu_stats(PcpuSwNetstats); - if (!usbNet->stats64) { - return; - } - - usbNet->msg_enable = netif_msg_init (g_msgLevel, NETIF_MSG_DRV - | NETIF_MSG_PROBE | NETIF_MSG_LINK| NETIF_MSG_RX_ERR|NETIF_MSG_TX_ERR); - - OsalMutexInit(&usbNet->sendSkbClock); - - init_waitqueue_head(&usbNet->wait); - skb_queue_head_init (&usbNet->rxq); - skb_queue_head_init (&usbNet->txq); - skb_queue_head_init (&usbNet->done); - skb_queue_head_init(&usbNet->rxqPause); - - // init work for tx_complete rx_complete - INIT_WORK(&usbNet->TxCompleteWorkqueue, TxComplete); - INIT_WORK(&usbNet->RxCompleteWorkqueue, RxComplete); - - usbNet->bh.func = (void (*)(unsigned long))UsbnetAdapterBhTasklet; - usbNet->bh.data = (unsigned long)&usbNet->delay; //TimerList delay; - - timer_setup(&usbNet->delay, UsbnetAdapterBh, 0); - - usbNet->net = net; -} - - -static void UsbnetAdapterSetNetDevice(struct UsbnetAdapter *usbNet, NetDevice *net) -{ - // 1.addr - static u8 node_id[ETH_ALEN]; - if (usbNet->usbnetInfo.isGetmacAddr) { - if (memcpy_s(node_id, ETH_ALEN, usbNet->usbnetInfo.macAddr, ETH_ALEN) != EOK) { - return; - } - } else { - eth_random_addr(node_id); - } - memcpy_s(net->dev_addr, sizeof(node_id)/sizeof(node_id[0]), node_id, sizeof(node_id)/sizeof(node_id[0])); - HARCH_NET_INFO_PRINT("macAddr addr %pM", net->dev_addr); - // 2. mtu - net->min_mtu = 0; - net->max_mtu = ETH_MAX_MTU; - net->netdev_ops = &g_UsbnetAdapterDeviceOps; - net->watchdog_timeo = TX_TIMEOUT_JIFFIES; - net->ethtool_ops = &g_UsbnetAdapterEthtoolOps; - - //3. name and mtu - strcpy_s (net->name, sizeof(net->name)/sizeof(net->name[0]), "usb%d"); - if (usbNet->usbnetInfo.isBindDevice) { - if ((usbNet->usbnetInfo.usbFlags & HDF_FLAG_ETHER) != 0 && - ((usbNet->usbnetInfo.usbFlags & HDF_FLAG_POINTTOPOINT) == 0 || - (net->dev_addr[0] & 0x02) == 0)) { - HARCH_NET_INFO_PRINT(); - strcpy_s (net->name, sizeof(net->name)/sizeof(net->name[0]), "eth%d"); - } - - /* WLAN devices should always be named "wlan%d" */ - if ((usbNet->usbnetInfo.usbFlags & FLAG_WLAN) != 0) { - HARCH_NET_INFO_PRINT(); - strcpy_s(net->name, sizeof(net->name)/sizeof(net->name[0]), "wlan%d"); - } - /* WWAN devices should always be named "wwan%d" */ - if ((usbNet->usbnetInfo.usbFlags & FLAG_WWAN) != 0) { - HARCH_NET_INFO_PRINT(); - strcpy_s(net->name, sizeof(net->name)/sizeof(net->name[0]), "wwan%d"); - } - - /* devices that cannot do ARP */ - if ((usbNet->usbnetInfo.usbFlags & FLAG_NOARP) != 0) { - net->flags |= IFF_NOARP; - } - - HARCH_NET_INFO_PRINT("usbNet->usbnetInfo.mtu = %d, net->name= %s", usbNet->usbnetInfo.mtu, net->name); - /* maybe the remote can't receive an Ethernet MTU */ - net->mtu = usbNet->usbnetInfo.mtu; - net->hard_header_len = usbNet->usbnetInfo.hardHeaderLen; - } - - /* let userspace know we have a random address */ - if (ether_addr_equal(net->dev_addr, node_id)) { - net->addr_assign_type = NET_ADDR_RANDOM; - } -} - -static int32_t UsbnetAdapterProbe(struct HdfDeviceObject *device, struct HdfSBuf *data) -{ - HARCH_NET_INFO_PRINT("begin"); - int ret = HDF_SUCCESS; - uint32_t infoSize = 0; - struct UsbnetTransInfo *uNetTransInfo = NULL; - - bool flag = HdfSbufReadBuffer(data, (const void **)(&(uNetTransInfo)), &infoSize); - if ((!flag) || uNetTransInfo == NULL) { - ret = HDF_ERR_INVALID_PARAM; - HDF_LOGE("%s: fail to read infoTable in event data, flag = %d", __func__, flag); - return ret; - } - NetDevice *net = alloc_etherdev(sizeof(struct UsbnetAdapter)); - if (net == NULL) { - HARCH_NET_INFO_PRINT(); - goto out; - } - device->priv = net; - struct UsbnetAdapter *usbNet = netdev_priv(net); - UsbnetAdapterSetUsbNet(device, net, uNetTransInfo); - UsbnetAdapterSetNetDevice(usbNet, net); - HARCH_NET_INFO_PRINT("after usbNet->usbnetInfo.mtu = %d, net->name= %s", usbNet->usbnetInfo.mtu, net->name); - ret = register_netdev(net); - if (ret) { - goto out0; - } - HARCH_NET_INFO_PRINT("register net %pM\n", net->dev_addr); - netif_device_attach(net); - HARCH_NET_INFO_PRINT("netif_device_attach net %pM\n", net->dev_addr); - - if (usbNet->usbnetInfo.usbFlags & FLAG_LINK_INTR) { - HARCH_NET_INFO_PRINT(); - UsbnetAdapterLinkChange(usbNet, 0, 0); - } - return HDF_SUCCESS; - -out0: - cancel_work_sync(&usbNet->TxCompleteWorkqueue); - cancel_work_sync(&usbNet->RxCompleteWorkqueue); - free_netdev(net); -out: - return ret; -} - - -static int32_t UsbnetAdapterDisconnect(struct HdfDeviceObject *device) -{ - HARCH_NET_INFO_PRINT("begin"); - if (device == NULL) { - HDF_LOGI("%s: device is null", __func__); - return HDF_ERR_INVALID_OBJECT; - } - - //free net - NetDevice *net = (NetDevice *)device->priv; - unregister_netdev (net); - - struct UsbnetAdapter *usbNet = netdev_priv(net); - if (usbNet->stats64) { - free_percpu(usbNet->stats64); - } - - UsbnetAdapterTerminateUrbs(usbNet); - skb_queue_purge(&usbNet->rxqPause); - OsalMutexDestroy(&usbNet->sendSkbClock); - - free_netdev(net); - return HDF_SUCCESS; -} - -static int32_t UsbnetAdapterDispatch( - struct HdfDeviceIoClient *client, int32_t cmd, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - HARCH_NET_INFO_PRINT("begin, received cmd = %d", cmd); - - int32_t ret = HDF_ERR_INVALID_PARAM; - switch (cmd) { - case USB_NET_REGISTER_NET: - //add new usbnet device - ret = UsbnetAdapterProbe(client->device, data); - break; - case USB_NET_CLOSE_NET: - ret = UsbnetAdapterDisconnect(client->device); - break; - case USB_NET_RECIVE_DATA_FROM_USB: - ret = UsbnetAdapterRxComplete(client->device, data, GFP_ATOMIC); - break; - default: - HDF_LOGI("%s: no this cmd: %d", __func__, cmd); - break; - } - - if (!HdfSbufWriteInt32(reply, ret)) { - HDF_LOGE("%s: reply int32 fail", __func__); - } - - return ret; -} - -static int32_t UsbnetAdapterBind(struct HdfDeviceObject *device) -{ - HARCH_NET_INFO_PRINT("begin"); - static struct IDeviceIoService UsbnetAdapterService = { - .Dispatch = UsbnetAdapterDispatch, - }; - - if (device == NULL) { - HARCH_NET_INFO_PRINT("device is NULL!"); - return HDF_ERR_INVALID_OBJECT; - } - device->service = &UsbnetAdapterService; - return HDF_SUCCESS; -} - -static int32_t UsbnetAdapterInit(struct HdfDeviceObject *device) -{ - HARCH_NET_INFO_PRINT("begin"); - if (device == NULL) { - HARCH_NET_INFO_PRINT("device is null!"); - return HDF_FAILURE; - } - - HARCH_NET_INFO_PRINT("UsbnetAdapterInit Init success"); - return HDF_SUCCESS; -} - -static void UsbnetAdapterRelease(struct HdfDeviceObject *device) -{ - HARCH_NET_INFO_PRINT("begin"); - return; -} - -struct HdfDriverEntry g_UsbnetAdapterEntry = { - .moduleVersion = 1, - .Bind = UsbnetAdapterBind, - .Init = UsbnetAdapterInit, - .Release = UsbnetAdapterRelease, - .moduleName = "HDF_USB_NET", -}; - -HDF_INIT(g_UsbnetAdapterEntry); diff --git a/adapter/khdf/linux/platform/clock/clock_adapter.c b/adapter/khdf/linux/platform/clock/clock_adapter.c index b635322c9..a58b84b00 100644 --- a/adapter/khdf/linux/platform/clock/clock_adapter.c +++ b/adapter/khdf/linux/platform/clock/clock_adapter.c @@ -1,7 +1,6 @@ /* - * clock driver adapter of linux * - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and diff --git a/adapter/uhdf2/hdi/test/BUILD.gn b/adapter/uhdf2/hdi/test/BUILD.gn index 0335d56a1..fe366586f 100644 --- a/adapter/uhdf2/hdi/test/BUILD.gn +++ b/adapter/uhdf2/hdi/test/BUILD.gn @@ -35,6 +35,10 @@ ohos_unittest("HdiServiceManagerTest") { "$hdf_uhdf_path/utils/include", ] + if (with_sample) { + defines = [ "SAMPLE_DRIVER" ] + } + external_deps = [ "c_utils:utils", "hilog:libhilog", @@ -50,6 +54,10 @@ ohos_unittest("HdiServiceManagerTestCC") { ] sources = [ "servmgr/service_manager_hdi_test.cpp" ] + if (with_sample) { + defines = [ "SAMPLE_DRIVER" ] + } + deps = [ "$hdf_uhdf_path/hdi:libhdi", "$hdf_uhdf_path/utils:libhdf_utils", diff --git a/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp b/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp index dc732f6d7..2dff1f3f3 100644 --- a/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp +++ b/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp @@ -34,30 +34,38 @@ namespace OHOS { using namespace testing::ext; +#ifdef SAMPLE_DRIVER static constexpr const char *TEST_SERVICE_NAME = "sample_driver_service"; static constexpr const char *TEST1_SERVICE_NAME = "sample1_driver_service"; static constexpr const char *TEST_SERVICE_INTERFACE_DESC = "hdf.test.sampele_service"; -static constexpr const char *TEST_SERVICE_INTERFACE_DESC_INVALID = "____"; -static constexpr const char *TEST_SERVICE_INTERFACE_DESC_VOID = ""; -static constexpr const char *TEST_SERVICE_INTERFACE_DESC_NULL = nullptr; static constexpr int PAYLOAD_NUM = 1234; static constexpr int WAIT_LOAD_UNLOAD_TIME = 300; static constexpr int INVALID_DISPATCH_CODE = -1; +#endif + +static constexpr const char *TEST_SERVICE_INTERFACE_DESC_INVALID = "____"; +static constexpr const char *TEST_SERVICE_INTERFACE_DESC_VOID = ""; +static constexpr const char *TEST_SERVICE_INTERFACE_DESC_NULL = nullptr; + class HdfServiceMangerHdiCTest : public testing::Test { public: static void SetUpTestCase() { +#ifdef SAMPLE_DRIVER struct HDIDeviceManager *devmgr = HDIDeviceManagerGet(); if (devmgr != nullptr) { devmgr->LoadDevice(devmgr, TEST_SERVICE_NAME); } } +#endif static void TearDownTestCase() { +#ifdef SAMPLE_DRIVER struct HDIDeviceManager *devmgr = HDIDeviceManagerGet(); if (devmgr != nullptr) { devmgr->UnloadDevice(devmgr, TEST_SERVICE_NAME); } +#endif } void SetUp() {}; void TearDown() {}; @@ -70,6 +78,7 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest001, TestSize.Level1) HDIServiceManagerRelease(servmgr); } +#ifdef SAMPLE_DRIVER HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest002, TestSize.Level1) { struct HDIServiceManager *servmgr = HDIServiceManagerGet(); @@ -544,6 +553,7 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest010, TestSize.Level1) OsalMSleep(WAIT_COUNT); ASSERT_FALSE(ssd.callbacked); } +#endif /* * Test shared mem interface @@ -575,6 +585,7 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest011, TestSize.Level1) close(memFd); } +#ifdef SAMPLE_DRIVER /* * Test get service set by interfacedesc */ @@ -605,6 +616,7 @@ HWTEST_F(HdfServiceMangerHdiCTest, ListServiceByInterfaceDescTest001, TestSize.L ret = HdiServiceSetRelease(serviceSet); ASSERT_TRUE(ret == HDF_SUCCESS); } +#endif HWTEST_F(HdfServiceMangerHdiCTest, ListServiceByInterfaceDescTest002, TestSize.Level1) { @@ -637,6 +649,7 @@ HWTEST_F(HdfServiceMangerHdiCTest, ListServiceByInterfaceDescTest004, TestSize.L ASSERT_TRUE(serviceSet == nullptr); } +#ifdef SAMPLE_DRIVER HWTEST_F(HdfServiceMangerHdiCTest, ListServiceByInterfaceDescTest005, TestSize.Level1) { struct HDIDeviceManager *devmgr = HDIDeviceManagerGet(); @@ -678,6 +691,7 @@ HWTEST_F(HdfServiceMangerHdiCTest, ListServiceByInterfaceDescTest005, TestSize.L ASSERT_TRUE(ret == HDF_SUCCESS); HDIDeviceManagerRelease(devmgr); } +#endif HWTEST_F(HdfServiceMangerHdiCTest, DevMgrQueryUsableDeviceTest, TestSize.Level1) { @@ -726,6 +740,7 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest018, TestSize.Level1) HDIServiceManagerRelease(NULL); } +#ifdef SAMPLE_DRIVER HWTEST_F(HdfServiceMangerHdiCTest, RemoteServiceTest001, TestSize.Level1) { struct HDIServiceManager *servmgr = HDIServiceManagerGet(); ASSERT_TRUE(servmgr != nullptr); @@ -761,6 +776,7 @@ HWTEST_F(HdfServiceMangerHdiCTest, RemoteServiceTest003, TestSize.Level1) { int status = HdfRemoteServiceDefaultDispatch(sampleService, INVALID_DISPATCH_CODE, dataSbuf, replySbuf); ASSERT_TRUE(status != HDF_SUCCESS); } +#endif HWTEST_F(HdfServiceMangerHdiCTest, DevMgrTest, TestSize.Level1) { diff --git a/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp b/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp index 49dd3fedf..e3fb386aa 100644 --- a/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp +++ b/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp @@ -46,17 +46,21 @@ using OHOS::HDI::ServiceManager::V1_0::ServiceStatus; using OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub; using OHOS::HDI::DeviceManager::V1_0::HdiDevHostInfo; using OHOS::HDI::ServiceManager::V1_0::HdiServiceInfo; +#ifdef SAMPLE_DRIVER static constexpr const char *TEST_SERVICE_NAME = "sample_driver_service"; static constexpr const char *TEST1_SERVICE_NAME = "sample1_driver_service"; static constexpr const char16_t *TEST_SERVICE_INTERFACE_DESC = u"hdf.test.sampele_service"; static constexpr const char *TEST_SERVICE_INTERFACE_DESC_N = "hdf.test.sampele_service"; +#endif static constexpr const char *TEST_SERVICE_INTERFACE_DESC_INVALID = "___"; static constexpr const char *TEST_SERVICE_INTERFACE_DESC_VOID = ""; static constexpr const char *TEST_SERVICE_INTERFACE_DESC_NULL = nullptr; +#ifdef SAMPLE_DRIVER static constexpr int PAYLOAD_NUM = 1234; static constexpr int SMQ_TEST_QUEUE_SIZE = 10; static constexpr int SMQ_TEST_WAIT_TIME = 100; static constexpr int WAIT_LOAD_UNLOAD_TIME = 300; +#endif static constexpr int DEVICE_SERVICE_MANAGER_SA_ID = 5100; static constexpr int INVALID_CODE = 100; static constexpr int ERROR_CODE_WITH_INVALID_CODE = 305; @@ -65,19 +69,23 @@ class HdfServiceMangerHdiTest : public testing::Test { public: static void SetUpTestCase() { +#ifdef SAMPLE_DRIVER auto devmgr = IDeviceManager::Get(); if (devmgr != nullptr) { HDF_LOGI("%{public}s:%{public}d", __func__, __LINE__); devmgr->LoadDevice(TEST_SERVICE_NAME); } +#endif } static void TearDownTestCase() { +#ifdef SAMPLE_DRIVER auto devmgr = IDeviceManager::Get(); if (devmgr != nullptr) { HDF_LOGI("%{public}s:%{public}d", __func__, __LINE__); devmgr->UnloadDevice(TEST_SERVICE_NAME); } +#endif } void TestServiceListenerStop(const sptr& devmgr, const sptr& servmgr); void TestSampleService(sptr& sampleService, const sptr& devmgr, @@ -92,6 +100,7 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest001, TestSize.Level1) ASSERT_TRUE(servmgr != nullptr); } +#ifdef SAMPLE_DRIVER HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest002, TestSize.Level1) { auto servmgr = IServiceManager::Get(); @@ -278,6 +287,7 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest007, TestSize.Level1) sampleService = servmgr->GetService(TEST_SERVICE_NAME); ASSERT_TRUE(sampleService == nullptr); } +#endif class ServStatListener : public OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub { public: @@ -293,6 +303,7 @@ private: StatusCallback callback_; }; +#ifdef SAMPLE_DRIVER /* * Test service start status listener */ @@ -676,6 +687,7 @@ HWTEST_F(HdfServiceMangerHdiTest, ListServiceByInterfaceDescTest001, TestSize.Le ASSERT_FALSE(serviceNames.empty()); ASSERT_TRUE(serviceNames.front().compare(TEST_SERVICE_NAME) == 0); } +#endif HWTEST_F(HdfServiceMangerHdiTest, ListServiceByInterfaceDescTest002, TestSize.Level1) { @@ -707,6 +719,7 @@ HWTEST_F(HdfServiceMangerHdiTest, ListServiceByInterfaceDescTest004, TestSize.Le ASSERT_TRUE(serviceNames.empty()); } +#ifdef SAMPLE_DRIVER HWTEST_F(HdfServiceMangerHdiTest, ListServiceByInterfaceDescTest005, TestSize.Level1) { auto devmgr = IDeviceManager::Get(); @@ -731,6 +744,7 @@ HWTEST_F(HdfServiceMangerHdiTest, ListServiceByInterfaceDescTest005, TestSize.Le ret = devmgr->UnloadDevice(TEST1_SERVICE_NAME); ASSERT_EQ(ret, HDF_SUCCESS); } +#endif HWTEST_F(HdfServiceMangerHdiTest, ListAllServiceTest, TestSize.Level1) { @@ -754,6 +768,7 @@ HWTEST_F(HdfServiceMangerHdiTest, ListAllDeviceTest, TestSize.Level1) ASSERT_TRUE(deviceInfos.size() != 0); } +#ifdef SAMPLE_DRIVER HWTEST_F(HdfServiceMangerHdiTest, EndSampleHostTest, TestSize.Level1) { auto servmgr = IServiceManager::Get(); @@ -859,6 +874,7 @@ HWTEST_F(HdfServiceMangerHdiTest, InjectPmTest, TestSize.Level1) ret = devmgr->UnloadDevice(TEST_SERVICE_NAME); ASSERT_TRUE(ret == HDF_SUCCESS); } +#endif HWTEST_F(HdfServiceMangerHdiTest, ListenerTest001, TestSize.Level1) { diff --git a/adapter/uhdf2/hdi/test/smq_test/BUILD.gn b/adapter/uhdf2/hdi/test/smq_test/BUILD.gn index cb44ac55e..066f6a9bb 100644 --- a/adapter/uhdf2/hdi/test/smq_test/BUILD.gn +++ b/adapter/uhdf2/hdi/test/smq_test/BUILD.gn @@ -9,7 +9,7 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -# limitations under the License. +# limitations under the License. import("//build/test.gni") import("./../../../../../adapter/uhdf2/uhdf.gni") @@ -33,6 +33,10 @@ ohos_unittest("HdiSmqTest") { "$hdf_uhdf_path/utils/include", ] + if (with_sample) { + defines = [ "SAMPLE_DRIVER" ] + } + external_deps = [ "c_utils:utils", "hilog:libhilog", diff --git a/adapter/uhdf2/hdi/test/smq_test/smq_test.cpp b/adapter/uhdf2/hdi/test/smq_test/smq_test.cpp index 1f624f42d..f2584fc9f 100644 --- a/adapter/uhdf2/hdi/test/smq_test/smq_test.cpp +++ b/adapter/uhdf2/hdi/test/smq_test/smq_test.cpp @@ -37,14 +37,18 @@ using OHOS::HDI::Base::SharedMemQueueMeta; using OHOS::HDI::Base::SmqType; using OHOS::HDI::DeviceManager::V1_0::IDeviceManager; using OHOS::HDI::ServiceManager::V1_0::IServiceManager; + +#ifdef SAMPLE_DRIVER static constexpr const char *TEST_SERVICE_HOST_NAME = "sample_host"; static constexpr const char *SERVICE_NAME = "sample_driver_service"; static constexpr const char16_t *TEST_SERVICE_INTERFACE_DESC = u"hdf.test.sampele_service"; static constexpr int SMQ_TEST_QUEUE_SIZE = 10; static constexpr uint32_t HOST_PID_BUFF_SIZE = 20; static constexpr uint32_t CMD_RESULT_BUFF_SIZE = 1024; +#endif } // namespace +#ifdef SAMPLE_DRIVER static std::vector Split(const std::string &src, const std::string &limit) { std::vector result; @@ -169,31 +173,37 @@ static void PrintFds(const std::string &info, const std::set &fds) } std::cout << std::endl; } +#endif class SmqTest : public testing::Test { public: static void SetUpTestCase() { +#ifdef SAMPLE_DRIVER auto devmgr = IDeviceManager::Get(); if (devmgr != nullptr) { HDF_LOGI("%{public}s:%{public}d", __func__, __LINE__); devmgr->LoadDevice(SERVICE_NAME); } +#endif } static void TearDownTestCase() { +#ifdef SAMPLE_DRIVER auto devmgr = IDeviceManager::Get(); if (devmgr != nullptr) { HDF_LOGI("%{public}s:%{public}d", __func__, __LINE__); devmgr->UnloadDevice(SERVICE_NAME); } +#endif } void SetUp() {}; void TearDown() {}; }; +#ifdef SAMPLE_DRIVER HWTEST_F(SmqTest, SmqTest001, TestSize.Level1) { std::set fds1; @@ -295,4 +305,5 @@ HWTEST_F(SmqTest, SmqTest002, TestSize.Level1) if (!servHostUnclosedFds.empty()) { PrintFds("sample_host unclosed fds:", servHostUnclosedFds); } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/adapter/uhdf2/host/devhost.c b/adapter/uhdf2/host/devhost.c index 0e782eda6..8f0d3652f 100644 --- a/adapter/uhdf2/host/devhost.c +++ b/adapter/uhdf2/host/devhost.c @@ -194,6 +194,8 @@ int main(int argc, char **argv) HDF_LOGI("%{public}s start loop", hostName); looper->Start(looper); } + + DevHostServiceFreeInstance(instance); HdfPowerManagerExit(); DevHostDumpDeInit(); HDF_LOGI("hdf device host %{public}s %{public}d %{public}d exit", hostName, hostId, status); diff --git a/adapter/uhdf2/host/test/BUILD.gn b/adapter/uhdf2/host/test/BUILD.gn index 7b949f61b..4295296c7 100644 --- a/adapter/uhdf2/host/test/BUILD.gn +++ b/adapter/uhdf2/host/test/BUILD.gn @@ -40,12 +40,16 @@ ohos_unittest("DevMgrTest") { deps = [ "$hdf_uhdf_path/hdi:libhdi", - "$hdf_uhdf_path/host/test/unittest/sample_driver:sample_driver", "$hdf_uhdf_path/utils:libhdf_utils", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] + if (with_sample) { + defines = [ "SAMPLE_DRIVER" ] + deps += [ "$hdf_uhdf_path/host/test/unittest/sample_driver:sample_driver" ] + } + if (is_standard_system) { external_deps = [ "c_utils:utils", diff --git a/adapter/uhdf2/host/test/unittest/devmgr_test.cpp b/adapter/uhdf2/host/test/unittest/devmgr_test.cpp index 0b5562e16..45ea7f5c1 100644 --- a/adapter/uhdf2/host/test/unittest/devmgr_test.cpp +++ b/adapter/uhdf2/host/test/unittest/devmgr_test.cpp @@ -62,6 +62,7 @@ void DevMgrTest::TearDown() { } +#ifdef SAMPLE_DRIVER /* * @tc.name: DriverLoaderTest * @tc.desc: driver load test @@ -86,6 +87,8 @@ HWTEST_F(DevMgrTest, DriverLoaderTest, TestSize.Level1) ASSERT_TRUE(sampleService != nullptr); } +#endif + /* * @tc.name: DriverUnLoaderTest * @tc.desc: driver unload test @@ -111,6 +114,7 @@ HWTEST_F(DevMgrTest, DriverUnLoaderTest, TestSize.Level1) ASSERT_TRUE(sampleService == nullptr); } +#ifdef SAMPLE_DRIVER HWTEST_F(DevMgrTest, DriverTest, TestSize.Level1) { ASSERT_TRUE(servmgr != nullptr); @@ -142,6 +146,7 @@ HWTEST_F(DevMgrTest, DriverTest, TestSize.Level1) ASSERT_TRUE(sampleService == nullptr); } } +#endif HWTEST_F(DevMgrTest, DevMgrDumpErrorTest, TestSize.Level1) { diff --git a/adapter/uhdf2/host/test/unittest/sample1_driver/BUILD.gn b/adapter/uhdf2/host/test/unittest/sample1_driver/BUILD.gn index 385c5194c..c4a4ebfd8 100755 --- a/adapter/uhdf2/host/test/unittest/sample1_driver/BUILD.gn +++ b/adapter/uhdf2/host/test/unittest/sample1_driver/BUILD.gn @@ -13,29 +13,31 @@ import("//build/ohos.gni") import("./../../../../uhdf.gni") -group("sample1_driver") { - deps = [ ":libsample1_driver" ] -} +if (with_sample) { + group("sample1_driver") { + deps = [ ":libsample1_driver" ] + } -ohos_shared_library("libsample1_driver") { - include_dirs = [ - "$hdf_framework_path/core/host/include", - "$hdf_framework_path/core/shared/include", - ] - sources = [ "sample1_driver.c" ] + ohos_shared_library("libsample1_driver") { + include_dirs = [ + "$hdf_framework_path/core/host/include", + "$hdf_framework_path/core/shared/include", + ] + sources = [ "sample1_driver.c" ] - deps = [ - "./../../../../host:libhdf_host", - "./../../../../utils:libhdf_utils", - ] + deps = [ + "./../../../../host:libhdf_host", + "./../../../../utils:libhdf_utils", + ] - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] - shlib_type = "hdi" - install_images = [ chipset_base_dir ] - subsystem_name = "hdf" - part_name = "hdf_core" + shlib_type = "hdi" + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "hdf_core" + } } diff --git a/adapter/uhdf2/host/test/unittest/sample_driver/BUILD.gn b/adapter/uhdf2/host/test/unittest/sample_driver/BUILD.gn index c576e2bc1..4ab4bafd7 100644 --- a/adapter/uhdf2/host/test/unittest/sample_driver/BUILD.gn +++ b/adapter/uhdf2/host/test/unittest/sample_driver/BUILD.gn @@ -13,36 +13,38 @@ import("//build/ohos.gni") import("./../../../../uhdf.gni") -group("sample_driver") { - deps = [ ":libsample_driver" ] -} +if (with_sample) { + group("sample_driver") { + deps = [ ":libsample_driver" ] + } -ohos_shared_library("libsample_driver") { - sources = [ - "sample_driver.cpp", - "sample_hdi_service.cpp", - "sample_hdi_service_stub.cpp", - ] - include_dirs = [ - "$hdf_uhdf_path/host/include", - "$hdf_framework_path/core/shared/include", - "$hdf_framework_path/core/host/include", - "$hdf_framework_path/utils/include", - ] - deps = [ - "./../../../../hdi:libhdi", - "./../../../../host:libhdf_host", - "./../../../../ipc:libhdf_ipc_adapter", - "./../../../../utils:libhdf_utils", - ] - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - ] + ohos_shared_library("libsample_driver") { + sources = [ + "sample_driver.cpp", + "sample_hdi_service.cpp", + "sample_hdi_service_stub.cpp", + ] + include_dirs = [ + "$hdf_uhdf_path/host/include", + "$hdf_framework_path/core/shared/include", + "$hdf_framework_path/core/host/include", + "$hdf_framework_path/utils/include", + ] + deps = [ + "./../../../../hdi:libhdi", + "./../../../../host:libhdf_host", + "./../../../../ipc:libhdf_ipc_adapter", + "./../../../../utils:libhdf_utils", + ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_single", + ] - shlib_type = "hdi" - install_images = [ chipset_base_dir ] - subsystem_name = "hdf" - part_name = "hdf_core" + shlib_type = "hdi" + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "hdf_core" + } } diff --git a/adapter/uhdf2/manager/src/devsvc_manager_stub.c b/adapter/uhdf2/manager/src/devsvc_manager_stub.c index 9ed2cd7d9..2ae604e6e 100644 --- a/adapter/uhdf2/manager/src/devsvc_manager_stub.c +++ b/adapter/uhdf2/manager/src/devsvc_manager_stub.c @@ -353,7 +353,7 @@ static int32_t DevSvcManagerStubGetService(struct IDevSvcManager *super, struct if (remoteService != NULL) { HdfSbufWriteRemoteService(reply, remoteService); ret = HDF_SUCCESS; - HDF_LOGD("StubGetService service %{public}s found", name); + HDF_LOGD("StubGetService service %{public}s found!", name); } else { HDF_LOGE("StubGetService %{public}s remoteService is null", name); ret = HDF_FAILURE; diff --git a/adapter/uhdf2/test/unittest/manager/BUILD.gn b/adapter/uhdf2/test/unittest/manager/BUILD.gn index 1e5b77551..6365a0f72 100644 --- a/adapter/uhdf2/test/unittest/manager/BUILD.gn +++ b/adapter/uhdf2/test/unittest/manager/BUILD.gn @@ -194,6 +194,10 @@ ohos_unittest("hdf_adapter_uhdf_test_uevent") { defines = [ "__USER__" ] sources = [ "$hdf_framework_path/core/manager/test/unittest/common/devmgr_uevent_test.cpp" ] + if (with_sample) { + defines += [ "SAMPLE_DRIVER" ] + } + if (is_standard_system) { external_deps = [ "c_utils:utils", diff --git a/framework/README_zh.md b/framework/README_zh.md index 9adac731b..1b9a80849 100644 --- a/framework/README_zh.md +++ b/framework/README_zh.md @@ -136,7 +136,7 @@ Sensor驱动模型主要由以下两部分组成: ### Display框架模型说明 -基于OpenHarmony驱动框架的Display驱动模型,对下屏蔽了芯片平台差异,方便操作系统跨平台迁移;向上抽象了外设驱动公共业务逻辑,通过配置或差异化适配接口,实现了一套驱动模型兼容不同的外设器件,使得三方厂商可以高效、便捷的切入OpenHarmony驱动生态。 +基于OpenHarmony驱动框架的Display驱动模型,对下屏蔽了芯片平台差异,方便操作系统跨平台迁移;向上抽象了外设驱动公共业务逻辑,通过配置或差异化适配接口,实现了一套驱动模型兼容不同的外设器件,使得三方厂商可以高效、便捷的切入鸿蒙驱动生态。 Display驱动模型主要由以下两部分组成: diff --git a/framework/core/manager/test/unittest/common/devmgr_uevent_test.cpp b/framework/core/manager/test/unittest/common/devmgr_uevent_test.cpp index 71b3abb4f..8ce84cfc8 100644 --- a/framework/core/manager/test/unittest/common/devmgr_uevent_test.cpp +++ b/framework/core/manager/test/unittest/common/devmgr_uevent_test.cpp @@ -15,10 +15,12 @@ #include using namespace testing::ext; +#ifdef SAMPLE_DRIVER static constexpr const char *TEST_SERVICE_NAME = "sample_driver_service"; -static constexpr const char *TEST_DEV_NODE = "/sys/devices/virtual/hdf/hdf_uevent_ut/uevent"; static constexpr const char *ADD_EVENT_CMD = "echo \"add\" > /sys/devices/virtual/hdf/hdf_uevent_ut/uevent"; static constexpr const char *REMOVE_EVENT_CMD = "echo \"remove\" > /sys/devices/virtual/hdf/hdf_uevent_ut/uevent"; +#endif +static constexpr const char *TEST_DEV_NODE = "/sys/devices/virtual/hdf/hdf_uevent_ut/uevent"; class DevmgrUeventTest : public testing::Test { public: @@ -55,6 +57,7 @@ void DevmgrUeventTest::SetUp() {} void DevmgrUeventTest::TearDown() {} +#ifdef SAMPLE_DRIVER /** * @tc.name: DevmgrUeventTestAdd * @tc.desc: trigger add uevent @@ -207,6 +210,7 @@ HWTEST_F(DevmgrUeventTest, DevmgrUeventStressTest, TestSize.Level3) ASSERT_TRUE(sampleService == nullptr); } } +#endif HWTEST_F(DevmgrUeventTest, HdiProxyBrokerTest001, TestSize.Level1) { diff --git a/framework/core/manager/test/unittest/common/hdf_remote_adapter_test.cpp b/framework/core/manager/test/unittest/common/hdf_remote_adapter_test.cpp index f744bdc60..3b35cef29 100644 --- a/framework/core/manager/test/unittest/common/hdf_remote_adapter_test.cpp +++ b/framework/core/manager/test/unittest/common/hdf_remote_adapter_test.cpp @@ -107,6 +107,7 @@ HWTEST_F(HdfRemoteAdapterTest, HdfRemoteAdapterTest004, TestSize.Level1) #ifdef WITH_SELINUX char *callingSid = HdfRemoteGetCallingSid(); ASSERT_TRUE(callingSid != nullptr); + delete callingSid; #endif } diff --git a/framework/include/platform/clock_if.h b/framework/include/platform/clock_if.h index 682504b20..f852bb425 100644 --- a/framework/include/platform/clock_if.h +++ b/framework/include/platform/clock_if.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/model/sensor/driver/include/sensor_platform_if.h b/framework/model/sensor/driver/include/sensor_platform_if.h index 85ee52221..3ac92b5d8 100755 --- a/framework/model/sensor/driver/include/sensor_platform_if.h +++ b/framework/model/sensor/driver/include/sensor_platform_if.h @@ -85,13 +85,13 @@ struct SensorBusCfg { }; }; -enum SENSORConfigValueIndex { +enum SensorConfigValueIndex { SENSOR_ADDR_INDEX, SENSOR_VALUE_INDEX, SENSOR_VALUE_BUTT, }; -enum SENSORConfigShortValueIndex { +enum SensorConfigShortValueIndex { SENSOR_SHORT_VALUE_INDEX0, SENSOR_SHORT_VALUE_INDEX1, SENSOR_SHORT_VALUE_INDEX2, diff --git a/framework/model/usb/include/hdf_usb_net_manager.h b/framework/model/usb/include/hdf_usb_net_manager.h deleted file mode 100755 index 652b57915..000000000 --- a/framework/model/usb/include/hdf_usb_net_manager.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2024 Archermind Technology (Nanjing) Co. Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#ifndef HDF_USB_NET_MANAGE_H -#define HDF_USB_NET_MANAGE_H - -#include "hdf_base.h" -#include "hdf_device_desc.h" - - -#define MAC_ADDR_SIZE 6 -#define IFNAMSIZ 16 - -/* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */ -#define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */ -#define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */ -#define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */ - -#define HDF_FLAG_NO_SETINT 0x0010 /* device can't set_interface() */ -#define HDF_FLAG_ETHER 0x0020 /* maybe use "eth%d" names */ - -#define FLAG_FRAMING_AX 0x0040 /* AX88772/178 packets */ -#define FLAG_WLAN 0x0080 /* use "wlan%d" names */ -#define FLAG_AVOID_UNLINK_URBS 0x0100 /* don't unlink urbs at usbnet_stop() */ -#define FLAG_SEND_ZLP 0x0200 /* hw requires ZLPs are sent */ -#define FLAG_WWAN 0x0400 /* use "wwan%d" names */ - -#define FLAG_LINK_INTR 0x0800 /* updates link (carrier) status */ -#define HDF_FLAG_POINTTOPOINT 0x1000 /* possibly use "usb%d" names */ - -/* - * Indicates to usbnet, that USB driver accumulates multiple IP packets. - * Affects statistic (counters) and short packet handling. - */ -#define FLAG_MULTI_PACKET 0x2000 -#define FLAG_RX_ASSEMBLE 0x4000 /* rx packets may span >1 frames */ -#define FLAG_NOARP 0x8000 /* device can't do ARP */ - -enum UsbnetServiceCmd { - USB_NET_REGISTER_NET, - USB_NET_CLOSE_NET, - USB_NET_SEND_DATA_TO_USB, - USB_NET_RECIVE_DATA_FROM_USB, - USB_NET_OPEN_USB, - USB_NET_CLOSE_USB, - USB_NET_UPDATE_FLAGS, - USB_NET_UPDATE_MAXQLEN -}; - -struct UsbnetTransInfo { - uint8_t isBindDevice; - char name[IFNAMSIZ]; /**< Network device name {@link IFNAMSIZ} */ - uint8_t isGetmacAddr; - uint8_t macAddr[MAC_ADDR_SIZE]; /**< MAC address {@link MAC_ADDR_SIZE} */ - uint32_t flags; /**< Network port status */ - uint32_t mtu; /**< Maximum transmission unit */ - uint16_t hardHeaderLen; /**< Header length */ - uint8_t link; - uint8_t needReset; - uint32_t usbFlags; /**< usb device match flags */ - uint32_t rxUrbSize; /* size for rx urbs */ - uint32_t hardMtu; /* count any extra framing */ - uint32_t maxpacket; - int txQlen; -}; - -#endif \ No newline at end of file diff --git a/framework/model/usb/include/hdf_usb_pnp_manage.h b/framework/model/usb/include/hdf_usb_pnp_manage.h index 943707dda..0f0c811d1 100644 --- a/framework/model/usb/include/hdf_usb_pnp_manage.h +++ b/framework/model/usb/include/hdf_usb_pnp_manage.h @@ -54,7 +54,6 @@ enum { }; struct UsbPnpNotifyServiceInfo { - uint8_t curInterfaceNumber; uint32_t length; int32_t devNum; diff --git a/framework/support/platform/include/clock/clock_core.h b/framework/support/platform/include/clock/clock_core.h index 7e21c73d6..ac366f70a 100644 --- a/framework/support/platform/include/clock/clock_core.h +++ b/framework/support/platform/include/clock/clock_core.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/support/platform/src/clock/clock_core.c b/framework/support/platform/src/clock/clock_core.c index 58e4f6dcf..b4968f160 100644 --- a/framework/support/platform/src/clock/clock_core.c +++ b/framework/support/platform/src/clock/clock_core.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/support/platform/src/clock/clock_if.c b/framework/support/platform/src/clock/clock_if.c index 910014209..6600af99f 100644 --- a/framework/support/platform/src/clock/clock_if.c +++ b/framework/support/platform/src/clock/clock_if.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/support/platform/src/clock/clock_if_u.c b/framework/support/platform/src/clock/clock_if_u.c index 1888469d6..a225ccd04 100644 --- a/framework/support/platform/src/clock/clock_if_u.c +++ b/framework/support/platform/src/clock/clock_if_u.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/support/platform/test/unittest/common/hdf_clock_test.cpp b/framework/support/platform/test/unittest/common/hdf_clock_test.cpp index 3efa85e70..6085799c2 100644 --- a/framework/support/platform/test/unittest/common/hdf_clock_test.cpp +++ b/framework/support/platform/test/unittest/common/hdf_clock_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/test/unittest/platform/common/clock_driver_test.c b/framework/test/unittest/platform/common/clock_driver_test.c index ad58a6835..c0f41cafb 100644 --- a/framework/test/unittest/platform/common/clock_driver_test.c +++ b/framework/test/unittest/platform/common/clock_driver_test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/test/unittest/platform/common/clock_test.c b/framework/test/unittest/platform/common/clock_test.c index 74e9c8d0e..f8695a4b9 100644 --- a/framework/test/unittest/platform/common/clock_test.c +++ b/framework/test/unittest/platform/common/clock_test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/test/unittest/platform/common/clock_test.h b/framework/test/unittest/platform/common/clock_test.h index b836a8088..805ea439a 100644 --- a/framework/test/unittest/platform/common/clock_test.h +++ b/framework/test/unittest/platform/common/clock_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/test/unittest/platform/entry/hdf_clock_entry_test.c b/framework/test/unittest/platform/entry/hdf_clock_entry_test.c index 5902e8b0a..8f6df3d86 100644 --- a/framework/test/unittest/platform/entry/hdf_clock_entry_test.c +++ b/framework/test/unittest/platform/entry/hdf_clock_entry_test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/test/unittest/platform/entry/hdf_clock_entry_test.h b/framework/test/unittest/platform/entry/hdf_clock_entry_test.h index ebb60efe2..49c0a4745 100644 --- a/framework/test/unittest/platform/entry/hdf_clock_entry_test.h +++ b/framework/test/unittest/platform/entry/hdf_clock_entry_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/test/unittest/platform/virtual/clock_virtual.c b/framework/test/unittest/platform/virtual/clock_virtual.c index c4ed40092..77e62e3cb 100644 --- a/framework/test/unittest/platform/virtual/clock_virtual.c +++ b/framework/test/unittest/platform/virtual/clock_virtual.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. -- Gitee From c62483204407cbb1b3546c6107f9b51540ec9971 Mon Sep 17 00:00:00 2001 From: huyx Date: Sat, 14 Sep 2024 16:02:59 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E9=BB=84=E8=93=9D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adapter/BUILD.gn b/adapter/BUILD.gn index 815188460..72aa7c730 100644 --- a/adapter/BUILD.gn +++ b/adapter/BUILD.gn @@ -52,8 +52,8 @@ if (defined(ohos_lite)) { if (with_sample) { deps += [ - "$hdf_adapter_path/uhdf2/host/test/unittest/sample1_driver:libsample1_driver", - "$hdf_adapter_path/uhdf2/host/test/unittest/sample_driver:libsample_driver", + "$hdf_adapter_path/uhdf2/host/test/unittest/sample1_driver:libsample1_driver", + "$hdf_adapter_path/uhdf2/host/test/unittest/sample_driver:libsample_driver", ] } } -- Gitee From 1bda29eada5d25cfa935a24d6be2d97efce54d81 Mon Sep 17 00:00:00 2001 From: huyx Date: Sat, 14 Sep 2024 16:18:52 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E9=BB=84=E8=93=9D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/hdi/test/BUILD.gn | 8 ++++---- adapter/uhdf2/hdi/test/smq_test/BUILD.gn | 2 +- adapter/uhdf2/host/test/unittest/sample1_driver/BUILD.gn | 1 + adapter/uhdf2/host/test/unittest/sample_driver/BUILD.gn | 1 + 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/adapter/uhdf2/hdi/test/BUILD.gn b/adapter/uhdf2/hdi/test/BUILD.gn index fe366586f..5b4240dc8 100644 --- a/adapter/uhdf2/hdi/test/BUILD.gn +++ b/adapter/uhdf2/hdi/test/BUILD.gn @@ -36,8 +36,8 @@ ohos_unittest("HdiServiceManagerTest") { ] if (with_sample) { - defines = [ "SAMPLE_DRIVER" ] - } + defines = [ "SAMPLE_DRIVER" ] + } external_deps = [ "c_utils:utils", @@ -55,8 +55,8 @@ ohos_unittest("HdiServiceManagerTestCC") { sources = [ "servmgr/service_manager_hdi_test.cpp" ] if (with_sample) { - defines = [ "SAMPLE_DRIVER" ] - } + defines = [ "SAMPLE_DRIVER" ] + } deps = [ "$hdf_uhdf_path/hdi:libhdi", diff --git a/adapter/uhdf2/hdi/test/smq_test/BUILD.gn b/adapter/uhdf2/hdi/test/smq_test/BUILD.gn index 066f6a9bb..97543818b 100644 --- a/adapter/uhdf2/hdi/test/smq_test/BUILD.gn +++ b/adapter/uhdf2/hdi/test/smq_test/BUILD.gn @@ -36,7 +36,7 @@ ohos_unittest("HdiSmqTest") { if (with_sample) { defines = [ "SAMPLE_DRIVER" ] } - + external_deps = [ "c_utils:utils", "hilog:libhilog", diff --git a/adapter/uhdf2/host/test/unittest/sample1_driver/BUILD.gn b/adapter/uhdf2/host/test/unittest/sample1_driver/BUILD.gn index c4a4ebfd8..4fe7fc389 100755 --- a/adapter/uhdf2/host/test/unittest/sample1_driver/BUILD.gn +++ b/adapter/uhdf2/host/test/unittest/sample1_driver/BUILD.gn @@ -13,6 +13,7 @@ import("//build/ohos.gni") import("./../../../../uhdf.gni") + if (with_sample) { group("sample1_driver") { deps = [ ":libsample1_driver" ] diff --git a/adapter/uhdf2/host/test/unittest/sample_driver/BUILD.gn b/adapter/uhdf2/host/test/unittest/sample_driver/BUILD.gn index 4ab4bafd7..9bdbc5433 100644 --- a/adapter/uhdf2/host/test/unittest/sample_driver/BUILD.gn +++ b/adapter/uhdf2/host/test/unittest/sample_driver/BUILD.gn @@ -13,6 +13,7 @@ import("//build/ohos.gni") import("./../../../../uhdf.gni") + if (with_sample) { group("sample_driver") { deps = [ ":libsample_driver" ] -- Gitee From 43eb65817c2d0bc422e41390da4fe6a47cd18053 Mon Sep 17 00:00:00 2001 From: huyx Date: Sun, 15 Sep 2024 09:08:06 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E9=BB=84=E8=93=9D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- .../model/usb/host/include/usb_net_adapter.h | 115 ++ .../model/usb/host/src/usb_net_adapter.c | 1220 +++++++++++++++++ .../model/usb/include/hdf_usb_net_manager.h | 72 + 3 files changed, 1407 insertions(+) create mode 100644 adapter/khdf/linux/model/usb/host/include/usb_net_adapter.h create mode 100644 adapter/khdf/linux/model/usb/host/src/usb_net_adapter.c create mode 100644 framework/model/usb/include/hdf_usb_net_manager.h diff --git a/adapter/khdf/linux/model/usb/host/include/usb_net_adapter.h b/adapter/khdf/linux/model/usb/host/include/usb_net_adapter.h new file mode 100644 index 000000000..349b05c93 --- /dev/null +++ b/adapter/khdf/linux/model/usb/host/include/usb_net_adapter.h @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2024 Archermind Technology (Nanjing) Co. Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef HDF_NET_USB_ADAPTER_H +#define HDF_NET_USB_ADAPTER_H + +#include "osal_mutex.h" +#include "hdf_log.h" +#include "hdf_usb_net_manager.h" + +#define MODULE_PARAM module_param +#define HARCH_LOG_TAG "[-net-hdf-]" +#define HARCH_NET_INFO_PRINT(fmt, ...) \ +do { \ + if (0) { \ + HDF_LOGI(HARCH_LOG_TAG"[%{public}s][%{public}d]:" fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__);} \ +} while (0) + +typedef struct pcpu_sw_netstats PcpuSwNetstats; +typedef struct net_device NetDevice; +typedef struct timer_list TimerList; +typedef struct work_struct WorkStruct; +typedef struct tasklet_struct TaskletStruct; +typedef struct device_type DeviceType; +typedef struct ethtool_ops EthtoolOps; +typedef struct rndis_data_hdr RndisDataHdr; +typedef struct sk_buff SkBuff; +typedef struct sk_buff_head SkBuffHead; +typedef struct net_device_ops NetDeviceOps; + +struct rndis_data_hdr { + __le32 msg_type; /* RNDIS_MSG_PACKET */ + __le32 msg_len; /* rndis_data_hdr + data_len + pad */ + __le32 data_offset; /* 36 -- right after header */ + __le32 data_len; /* ... real packet size */ + + __le32 oob_data_offset; /* zero */ + __le32 oob_data_len; /* zero */ + __le32 num_oob; /* zero */ + __le32 packet_data_offset; /* zero */ + + __le32 packet_data_len; /* zero */ + __le32 vc_handle; /* zero */ + __le32 reserved; /* zero */ +} __attribute__ ((packed)); + +struct UsbnetAdapter { + struct IDeviceIoService service; + struct HdfDeviceObject *deviceObject; + unsigned canDmaSg : 1; + NetDevice *net; + int32_t msg_enable; + struct UsbnetTransInfo usbnetInfo; + struct OsalMutex sendSkbClock; + + unsigned char pktCnt, pktErr; + + /* various kinds of pending driver work */ + wait_queue_head_t wait; + TimerList delay; + + SkBuffHead rxq; + SkBuffHead txq; + + SkBuffHead done; + SkBuffHead rxqPause; + TaskletStruct bh; + + struct pcpu_sw_netstats __percpu *stats64; + + WorkStruct kevent; + WorkStruct TxCompleteWorkqueue; + WorkStruct RxCompleteWorkqueue; + unsigned int txLen; + unsigned int rxLen; + unsigned long flags; +# define EVENT_TX_HALT 0 +# define EVENT_RX_HALT 1 +# define EVENT_RX_MEMORY 2 +# define EVENT_STS_SPLIT 3 +# define EVENT_LINK_RESET 4 +# define EVENT_RX_PAUSED 5 +# define EVENT_DEV_ASLEEP 6 +# define EVENT_DEV_OPEN 7 +# define EVENT_DEVICE_REPORT_IDLE 8 +# define EVENT_NO_RUNTIME_PM 9 +# define EVENT_RX_KILL 10 +# define EVENT_LINK_CHANGE 11 +# define EVENT_SET_RX_MODE 12 +# define EVENT_NO_IP_ALIGN 13 +}; + +/* we record the state for each of our queued skbs */ +enum SkbState { + ILLEGAL = 0, + TX_START, + TX_DONE, + RX_START, + RX_DONE, + RX_CLEANUP, + UNLINK_START +}; + +struct SkbData { /* skb->cb is one of these */ + enum SkbState state; + long length; + unsigned long packets; +}; + +#endif diff --git a/adapter/khdf/linux/model/usb/host/src/usb_net_adapter.c b/adapter/khdf/linux/model/usb/host/src/usb_net_adapter.c new file mode 100644 index 000000000..b8957f550 --- /dev/null +++ b/adapter/khdf/linux/model/usb/host/src/usb_net_adapter.c @@ -0,0 +1,1220 @@ +/* + * Copyright (c) 2024 Archermind Technology (Nanjing) Co. Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include + +#include +#include +#include +#if defined(CONFIG_DRIVERS_HDF_IMX8MM_ETHERNET) +#include +#include +#endif + +#include +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) +#include +#else +#include +#endif +#include "osal_mem.h" +#include "securec.h" + +#include "hdf_device_desc.h" +#include "usb_net_adapter.h" + +#define HDF_LOG_TAG UsbnetAdapter +#define TX_TIMEOUT_JIFFIES (5*HZ) +#define RNDIS_MSG_PACKET 0x00000001 /* 1-N packets */ + +// between wakeups +#define UNLINK_TIMEOUT_MS 3 +#define PKT_COUNT_CLEAR 30 +#define PKT_COUNT_RXKILL 20 +#define SHIFT_LINE_NUM 32 + +/* use ethtool to change the level for any given device */ +static int g_msgLevel = -1; +MODULE_PARAM(g_msgLevel, int, 0); +MODULE_PARM_DESC(g_msgLevel, "Override default message level"); + +static inline int UsbnetAdapterGetTxQlen(struct UsbnetAdapter *usbNet) +{ + return usbNet->usbnetInfo.txQlen; +} + +static int printf_char_buffer(char *buff, int size, bool isPrint) +{ + if (isPrint) { + int i = 0; + printk("===-harch-=== printf_char_buffer begin\n"); + for (i = 0; i < size; i++) { + printk(KERN_CONT"%02x ", buff[i]); + if ((i + 1) % SHIFT_LINE_NUM == 0) { + printk(KERN_CONT"\n"); + } + } + printk("===-harch-=== printf_char_buffer end\n"); + } + return 0; +} + +static int32_t UsbnetAdapterSendBufToUsb(const struct HdfDeviceObject *device, uint32_t id, + const void *buf, uint32_t writeSize) +{ + HARCH_NET_INFO_PRINT("writeSize=%d", writeSize); + int32_t ret = HDF_SUCCESS; + if ((device == NULL) || (buf == NULL)) { + HDF_LOGE("%s param is null", __func__); + return HDF_ERR_INVALID_PARAM; + } + + struct HdfSBuf *data = HdfSbufObtainDefaultSize(); + if (data == NULL) { + HDF_LOGE("fail to obtain sbuf data"); + return HDF_FAILURE; + } + + if (!HdfSbufWriteBuffer(data, buf, writeSize)) { + HDF_LOGE("fail to write sbuf"); + ret = HDF_FAILURE; + goto out; + } + + if (HdfDeviceSendEvent(device, id, data) != HDF_SUCCESS) { + HDF_LOGE("%s: send sensor data event failed", __func__); + ret = HDF_FAILURE; + goto out; + } + ret = HDF_SUCCESS; + +out: + HdfSbufRecycle(data); + return ret; +} + +static void RxComplete(WorkStruct *work) +{ + unsigned long flags = 0; + struct UsbnetAdapter *usbNet = container_of(work, struct UsbnetAdapter, RxCompleteWorkqueue); + PcpuSwNetstats *stats64 = this_cpu_ptr(usbNet->stats64); + + HARCH_NET_INFO_PRINT("rx_complete stats64->rx_packets = %lu,usbNet stats64->rx_bytes = %lu", + stats64->rx_packets, stats64->rx_bytes); + + HARCH_NET_INFO_PRINT("rx_complete stats64->tx_packets = %lu,usbNet stats64->tx_bytes = %lu", + stats64->tx_packets, stats64->tx_bytes); + + flags = u64_stats_update_begin_irqsave(&stats64->syncp); +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) + stats64->rx_packets++; + stats64->rx_bytes += usbNet->rxLen; +#else + u64_stats_inc(&stats64->rx_packets); + u64_stats_add(&stats64->rx_bytes, usbNet->rxLen); +#endif + u64_stats_update_end_irqrestore(&stats64->syncp, flags); + + HARCH_NET_INFO_PRINT("rx_complete stats64->rx_packets = %lu,usbNet stats64->rx_bytes = %lu", + stats64->rx_packets, stats64->rx_bytes); + + HARCH_NET_INFO_PRINT("rx_complete stats64->tx_packets = %lu,usbNet stats64->tx_bytes = %lu", + stats64->tx_packets, stats64->tx_bytes); +} + +/* Passes this packet up the stack, updating its accounting. + * Some link protocols batch packets, so their rx_fixup paths + * can return clones as well as just modify the original skb. + */ +static void UsbnetAdapterSkbReturn(struct UsbnetAdapter *usbNet, SkBuff *skb) +{ + if (test_bit(EVENT_RX_PAUSED, &usbNet->flags)) { + skb_queue_tail(&usbNet->rxqPause, skb); + return; + } + + /* only update if unset to allow minidriver rx_fixup override */ + if (skb->protocol == 0) { + skb->protocol = eth_type_trans (skb, usbNet->net); + } + + usbNet->rxLen = skb->len; + schedule_work_on(0, &usbNet->RxCompleteWorkqueue); + HARCH_NET_INFO_PRINT("< rx, len %zu, type 0x%x\n", skb->len + sizeof (struct ethhdr), skb->protocol); + (void)memset_s(skb->cb, sizeof(struct SkbData), 0, sizeof(struct SkbData)); + + if (skb_defer_rx_timestamp(skb)) { + return; + } + HARCH_NET_INFO_PRINT("-------rx before netif_rx"); + printf_char_buffer(skb->data, skb->len, false); + + int status = NET_RX_SUCCESS; + status = netif_rx (skb); + + HARCH_NET_INFO_PRINT("netif_rx status %d\n", status); + if (status != NET_RX_SUCCESS) { + HARCH_NET_INFO_PRINT("netif_rx status %d\n", status); + } +} + + +/* + * DATA -- host must not write zlps + */ +static int RndisRxFixup(struct UsbnetAdapter *usbNet, SkBuff *skb) +{ + /* This check is no longer done by usbnet */ + if (skb->len < usbNet->net->hard_header_len) { + return 0; + } + /* peripheral may have batched packets to us... */ + while (likely(skb->len)) { + RndisDataHdr *hdr = (void *)skb->data; + SkBuff *skb2 = NULL; + u32 msg_type = 0; + u32 msg_len = 0; + u32 data_len = 0; + u32 data_offset = 0; + + msg_type = le32_to_cpu(hdr->msg_type); + msg_len = le32_to_cpu(hdr->msg_len); + data_offset = le32_to_cpu(hdr->data_offset); + data_len = le32_to_cpu(hdr->data_len); + unsigned int totalLen = data_offset + data_len + 8; + + /* don't choke if we see oob, per-packet data, etc */ + if (unlikely(msg_type != RNDIS_MSG_PACKET || skb->len < msg_len + || totalLen > msg_len)) { + usbNet->net->stats.rx_frame_errors++; + netdev_dbg(usbNet->net, "bad rndis message %d/%d/%d/%d, len %d\n", + le32_to_cpu(hdr->msg_type), msg_len, data_offset, data_len, skb->len); + return 0; + } + unsigned int offset = 8 + data_offset; + skb_pull(skb, offset); + + /* at most one packet left? */ + if (likely((data_len - skb->len) <= sizeof(RndisDataHdr))) { + skb_trim(skb, data_len); + break; + } + + /* try to return all the packets in the batch */ + skb2 = skb_clone(skb, GFP_ATOMIC); + if (unlikely(!skb2)) { + break; + } + skb_pull(skb, msg_len - sizeof(RndisDataHdr)); + skb_trim(skb2, data_len); + UsbnetAdapterSkbReturn(usbNet, skb2); + } + return 1; +} + +static void UsbnetAdapterRxProcess(struct UsbnetAdapter *usbNet, SkBuff *skb) +{ + HARCH_NET_INFO_PRINT("-------rx before fix"); + printf_char_buffer(skb->data, skb->len, false); + + if (!RndisRxFixup(usbNet, skb)) { + /* With RX_ASSEMBLE, rx_fixup() must update counters */ + if (!(usbNet->usbnetInfo.usbFlags & FLAG_RX_ASSEMBLE)) { + usbNet->net->stats.rx_errors++; + } + goto done; + } + // else network stack removes extra byte if we forced a short packet + HARCH_NET_INFO_PRINT("--------rx after fix"); + printf_char_buffer(skb->data, skb->len, false); + + /* all data was already cloned from skb inside the driver */ + if (usbNet->usbnetInfo.usbFlags & FLAG_MULTI_PACKET) { + HARCH_NET_INFO_PRINT("usbNet->driver_info->flags = %d", usbNet->usbnetInfo.usbFlags); + goto done; + } + + if (skb->len < ETH_HLEN) { + usbNet->net->stats.rx_errors++; + usbNet->net->stats.rx_length_errors++; + HARCH_NET_INFO_PRINT("rx length %d\n", skb->len); + } else { + HARCH_NET_INFO_PRINT("UsbnetAdapterSkbReturn"); + UsbnetAdapterSkbReturn(usbNet, skb); + return; + } + +done: + skb_queue_tail(&usbNet->done, skb); +} + +static void UsbnetAdapterBh(TimerList *t) +{ + HARCH_NET_INFO_PRINT("begin"); + struct UsbnetAdapter *usbNet = from_timer(usbNet, t, delay); + + SkBuff *skb = NULL; + struct SkbData *entry = NULL; + + while ((skb = skb_dequeue (&usbNet->done))) { + entry = (struct SkbData *) skb->cb; + HARCH_NET_INFO_PRINT("entry->state = %d", entry->state); + + switch (entry->state) { + case RX_DONE: + HARCH_NET_INFO_PRINT("rx_done"); + entry->state = RX_CLEANUP; + UsbnetAdapterRxProcess (usbNet, skb); + continue; + case TX_DONE: + HARCH_NET_INFO_PRINT("tx_done"); + /* fall-through */ + fallthrough; + case RX_CLEANUP: + HARCH_NET_INFO_PRINT("rx_cleanup"); + dev_kfree_skb (skb); + continue; + default: + HARCH_NET_INFO_PRINT("bogus skb state %d\n", entry->state); + /* fall-through */ + } + } + HARCH_NET_INFO_PRINT(); + /* restart RX again after disabling due to high error rate */ + clear_bit(EVENT_RX_KILL, &usbNet->flags); + + /* waiting for all pending urbs to complete? + * only then can we forgo submitting anew + */ + if (waitqueue_active(&usbNet->wait)) { + HARCH_NET_INFO_PRINT("waitqueue_active"); + if (usbNet->rxq.qlen + usbNet->txq.qlen + usbNet->done.qlen == 0) { + HARCH_NET_INFO_PRINT(); + wake_up_all(&usbNet->wait); + } + } + + if (usbNet->txq.qlen < UsbnetAdapterGetTxQlen(usbNet)) { + netif_wake_queue (usbNet->net); + HARCH_NET_INFO_PRINT("usbNet->txq.qlen = %d, TX_QLEN (usbNet) = %d", + usbNet->txq.qlen, UsbnetAdapterGetTxQlen(usbNet)); + } + HARCH_NET_INFO_PRINT("end"); +} + +static void UsbnetAdapterBhTasklet(unsigned long data) +{ + HARCH_NET_INFO_PRINT("begin"); + TimerList *t = (TimerList *)data; + + UsbnetAdapterBh(t); + HARCH_NET_INFO_PRINT("end"); +} + +/* The caller must hold list->lock */ +static void UsbnetAdapterQueueSkb(SkBuffHead *list, + SkBuff *newsk, enum SkbState state) +{ + struct SkbData *entry = (struct SkbData *) newsk->cb; + + __skb_queue_tail(list, newsk); + entry->state = state; +} + +static enum SkbState UsbnetAdapterDeferBh(struct UsbnetAdapter *usbNet, SkBuff *skb, + SkBuffHead *list, enum SkbState state) +{ + unsigned long flags = 0; + enum SkbState old_state = ILLEGAL; + struct SkbData *entry = (struct SkbData *) skb->cb; + + spin_lock_irqsave(&list->lock, flags); + old_state = entry->state; + entry->state = state; + __skb_unlink(skb, list); + + /* UsbnetAdapterDeferBh() is never called with list == &usbNet->done. + * spin_lock_nested() tells lockdep that it is OK to take + * usbNet->done.lock here with list->lock held. + */ + spin_lock_nested(&usbNet->done.lock, SINGLE_DEPTH_NESTING); + + __skb_queue_tail(&usbNet->done, skb); + if (usbNet->done.qlen == 1) { + tasklet_schedule(&usbNet->bh); + } + + spin_unlock(&usbNet->done.lock); + spin_unlock_irqrestore(&list->lock, flags); + return old_state; +} + +static int32_t UsbnetAdapterOpen(NetDevice *net) +{ + HARCH_NET_INFO_PRINT("begin"); + if (NULL == net) { + HDF_LOGE("net device object is invalid"); + return HDF_FAILURE; + } + struct UsbnetAdapter *usbNet = netdev_priv(net); + if (NULL == usbNet) { + HDF_LOGE("usb net adapter object is invalid"); + return HDF_FAILURE; + } + + set_bit(EVENT_DEV_OPEN, &usbNet->flags); + + netif_start_queue (net); + + /* set device param, if find usb net host need, then it should send to it */ + /* reset rx error state */ + usbNet->pktCnt = 0; + usbNet->pktErr = 0; + clear_bit(EVENT_RX_KILL, &usbNet->flags); + + /* send info to usb start usb function */ + /* need transform usb_net_host change about usbNet->driverInfo->flags and set it on usb_net_host */ + OsalMutexLock(&usbNet->sendSkbClock); + int32_t ret = UsbnetAdapterSendBufToUsb(usbNet->deviceObject, USB_NET_OPEN_USB, + (const void *)&usbNet->flags, sizeof(usbNet->flags)); + if (ret != HDF_SUCCESS) { + HDF_LOGE("fail to UsbnetAdapterSendBufToUsb SendEvent!"); + OsalMutexUnlock(&usbNet->sendSkbClock); + return HDF_FAILURE; + } + OsalMutexUnlock(&usbNet->sendSkbClock); + + tasklet_schedule (&usbNet->bh); + return HDF_SUCCESS; +} + +static void WaitSkbQueueEmpty(SkBuffHead *q) +{ + unsigned long flags = 0; + HARCH_NET_INFO_PRINT(); + spin_lock_irqsave(&q->lock, flags); + while (!skb_queue_empty(q)) { + spin_unlock_irqrestore(&q->lock, flags); + schedule_timeout(msecs_to_jiffies(UNLINK_TIMEOUT_MS)); + set_current_state(TASK_UNINTERRUPTIBLE); + spin_lock_irqsave(&q->lock, flags); + } + spin_unlock_irqrestore(&q->lock, flags); +} + +// precondition: never called in_interrupt +static void UsbnetAdapterTerminateUrbs(struct UsbnetAdapter *usbNet) +{ + HARCH_NET_INFO_PRINT(); + + DECLARE_WAITQUEUE(wait, current); + /* ensure there are no more active urbs */ + add_wait_queue(&usbNet->wait, &wait); + set_current_state(TASK_UNINTERRUPTIBLE); + /* maybe wait for deletions to finish. */ + WaitSkbQueueEmpty(&usbNet->rxq); + WaitSkbQueueEmpty(&usbNet->txq); + + WaitSkbQueueEmpty(&usbNet->done); + set_current_state(TASK_RUNNING); + remove_wait_queue(&usbNet->wait, &wait); +} + +static int32_t UsbnetAdapterStop(NetDevice *net) +{ + HARCH_NET_INFO_PRINT("begin"); + if (NULL == net) { + HDF_LOGE("net device object is invalid"); + return HDF_FAILURE; + } + + struct UsbnetAdapter *usbNet = netdev_priv(net); + if (NULL == usbNet) { + HDF_LOGE("usb net adapter object is invalid"); + return HDF_FAILURE; + } + + PcpuSwNetstats *stats64 = this_cpu_ptr(usbNet->stats64); + + HARCH_NET_INFO_PRINT("usbNet stats64->rx_packets = %lu,usbNet stats64->rx_bytes = %lu", + stats64->rx_packets, stats64->rx_bytes); + + HARCH_NET_INFO_PRINT("usbNet stats64->tx_packets = %lu,usbNet stats64->tx_bytes = %lu", + stats64->tx_packets, stats64->tx_bytes); + + /* 1. clear_bit EVENT_DEV_OPEN dev->flags */ + clear_bit(EVENT_DEV_OPEN, &usbNet->flags); + /* 2. netif_stop_queue net */ + netif_stop_queue (net); + HARCH_NET_INFO_PRINT("stop stats: rx/tx %lu/%lu, errs %lu/%lu\n", + net->stats.rx_packets, net->stats.tx_packets, + net->stats.rx_errors, net->stats.tx_errors); + + /* 3. pm = usb_autopm_get_interface(dev->intf); do nothing */ + /* 4. if (info->stop) { no stop interface impl in rndis driver info */ + /* 5. if (!(info->flags & FLAG_AVOID_UNLINK_URBS)) do nothing*/ + if (!(usbNet->usbnetInfo.usbFlags & FLAG_AVOID_UNLINK_URBS)) { + UsbnetAdapterTerminateUrbs(usbNet); + } + + /* 6. usbnet_status_stop none */ + /* 7. usbnet_purge_paused_rxq none */ + skb_queue_purge(&usbNet->rxqPause); + /* 8. test_and_clear_bit and no manage_power interface impl in rndis driver info*/ + /* 9. dev flags */ + usbNet->flags = 0; + OsalMutexLock(&usbNet->sendSkbClock); + int32_t ret = UsbnetAdapterSendBufToUsb(usbNet->deviceObject, USB_NET_CLOSE_USB, + (const void *)&usbNet->flags, sizeof(usbNet->flags)); + if (ret != HDF_SUCCESS) { + HDF_LOGE("fail to UsbnetAdapterSendBufToUsb SendEvent!"); + OsalMutexUnlock(&usbNet->sendSkbClock); + return HDF_FAILURE; + } + OsalMutexUnlock(&usbNet->sendSkbClock); + /* 10. del_timer_sync */ + del_timer_sync (&usbNet->delay); + /* 11. tasklet_kill */ + tasklet_kill (&usbNet->bh); + /* 12. cancel_work_sync dev->kevent */ + cancel_work_sync(&usbNet->TxCompleteWorkqueue); + cancel_work_sync(&usbNet->RxCompleteWorkqueue); + return HDF_SUCCESS; +} + +static SkBuff *RndisTxFixup(SkBuff *skb, gfp_t flags) +{ + RndisDataHdr *hdr = NULL; + SkBuff *skb2 = NULL; + unsigned len = skb->len; + + if (likely(!skb_cloned(skb))) { + int room = skb_headroom(skb); + /* enough head room as-is? */ + if (unlikely((sizeof(RndisDataHdr)) <= room)) { + goto fill; + } + /* enough room, but needs to be readjusted? */ + room += skb_tailroom(skb); + if (likely((sizeof(RndisDataHdr)) <= room)) { + skb->data = memmove_s(skb->head + sizeof(RndisDataHdr), len, skb->data, len); + skb_set_tail_pointer(skb, len); + goto fill; + } + } + + /* create a new skb, with the correct size (and tailpad) */ + skb2 = skb_copy_expand(skb, sizeof(RndisDataHdr), 1, flags); + dev_kfree_skb_any(skb); + if (unlikely(!skb2)) { + return skb2; + } + skb = skb2; + + /* fill out the RNDIS header. we won't bother trying to batch + * packets; Linux minimizes wasted bandwidth through tx queues. + */ +fill: + HARCH_NET_INFO_PRINT("%s:%d fill skb by rndis host", __func__, __LINE__); + hdr = __skb_push(skb, sizeof(*hdr)); + (void)memset_s(hdr, sizeof(*hdr), 0, sizeof(*hdr)); + hdr->msg_type = cpu_to_le32(RNDIS_MSG_PACKET); + hdr->msg_len = cpu_to_le32(skb->len); + unsigned int offset = sizeof(*hdr) - 8; + hdr->data_offset = cpu_to_le32(offset); + hdr->data_len = cpu_to_le32(len); + + return skb; +} + +static void TxComplete(WorkStruct *work) +{ + unsigned long flags = 0; + struct UsbnetAdapter *usbNet = container_of(work, struct UsbnetAdapter, TxCompleteWorkqueue); + PcpuSwNetstats *stats64 = this_cpu_ptr(usbNet->stats64); + HARCH_NET_INFO_PRINT ("tx_complete stats64->rx_packets = %lu,usbNet stats64->rx_bytes = %lu", + stats64->rx_packets, stats64->rx_bytes); + + HARCH_NET_INFO_PRINT ("tx_complete stats64->tx_packets = %lu,usbNet stats64->tx_bytes = %lu", + stats64->tx_packets, stats64->tx_bytes); + + flags = u64_stats_update_begin_irqsave(&stats64->syncp); +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) + stats64->tx_packets++; + stats64->tx_bytes += usbNet->txLen; +#else + u64_stats_inc(&stats64->tx_packets); + u64_stats_add(&stats64->tx_bytes, usbNet->txLen); +#endif + u64_stats_update_end_irqrestore(&stats64->syncp, flags); + + HARCH_NET_INFO_PRINT ("tx_complete stats64->rx_packets = %lu,usbNet stats64->rx_bytes = %lu", + stats64->rx_packets, stats64->rx_bytes); + + HARCH_NET_INFO_PRINT ("tx_complete stats64->tx_packets = %lu,usbNet stats64->tx_bytes = %lu", + stats64->tx_packets, stats64->tx_bytes); +} + +static netdev_tx_t UsbnetAdapterStartXmit(SkBuff *skb, NetDevice *net) +{ + HARCH_NET_INFO_PRINT ("netif_running=%d, netif_device_present=%d, netif_carrier_ok=%d", netif_running(net), + netif_device_present(net), netif_carrier_ok(net)); + HARCH_NET_INFO_PRINT ("skb->data = %x, len = %d", skb->data, skb->len); + struct UsbnetAdapter *usbNet = netdev_priv(net); + //1.time tamp + if (skb) { + skb_tx_timestamp(skb); + } + //2.fix up + SkBuff* skbFixup = RndisTxFixup(skb, GFP_ATOMIC); + if (NULL == skbFixup) { + if (usbNet->usbnetInfo.usbFlags & FLAG_MULTI_PACKET) { + goto not_drop; + } + HDF_LOGE("fail to tx fixup by rndis host"); + goto drop; + } + HARCH_NET_INFO_PRINT("skb_fixup->data = %x, len = %d", skbFixup->data, skbFixup->len); + /* print org skb data info */ + printf_char_buffer(skbFixup->data, skbFixup->len, false); + //3.send msg to usb + unsigned long flags = 0; + spin_lock_irqsave(&usbNet->txq.lock, flags); + if (netif_queue_stopped(usbNet->net)) { + goto drop; + } + + int32_t ret = UsbnetAdapterSendBufToUsb(usbNet->deviceObject, USB_NET_SEND_DATA_TO_USB, + (unsigned char *)(skbFixup->data), skbFixup->len); + if (ret != HDF_SUCCESS) { + HDF_LOGE("fail to UsbnetHost SendEvent!"); +drop: + net->stats.tx_dropped++; +not_drop: + spin_unlock_irqrestore(&usbNet->txq.lock, flags); + if (skbFixup) { + dev_kfree_skb_any (skbFixup); + } + } else { + netif_trans_update(usbNet->net); + UsbnetAdapterQueueSkb(&usbNet->txq, skbFixup, TX_START); + + if (usbNet->txq.qlen >= UsbnetAdapterGetTxQlen(usbNet)) { + HARCH_NET_INFO_PRINT("usbNet->txq.qlen = %d, TX_QLEN (usbNet) = %d", + usbNet->txq.qlen, UsbnetAdapterGetTxQlen(usbNet)); + netif_stop_queue (usbNet->net); + } + spin_unlock_irqrestore(&usbNet->txq.lock, flags); + usbNet->txLen = skbFixup->len; + schedule_work_on(0, &usbNet->TxCompleteWorkqueue); + + enum SkbState state = UsbnetAdapterDeferBh(usbNet, skbFixup, &usbNet->txq, TX_DONE); + HARCH_NET_INFO_PRINT("state= %d", state); + } + return NETDEV_TX_OK; +} + +static void UsbnetAdapterTXTimeout(NetDevice *net, unsigned int txqueue) +{ + //send to device + HARCH_NET_INFO_PRINT("begin"); + if (NULL == net) { + HDF_LOGE("%s net device object is invalid", __func__); + return; + } + struct UsbnetAdapter *usbNet = netdev_priv(net); + if (NULL == usbNet) { + HDF_LOGE("%s UsbnetAdapter object is invalid", __func__); + return; + } + /* 1. unlink_urbs (dev, &dev->txq); maybe later be used */ + + /* 2. tasklet_schedule (&dev->bh) */ + tasklet_schedule (&usbNet->bh); + + /* 3. if (dev->driver_info->recover) none, rndis host no recover impl */ + + return; +} + +/* some work can't be done in tasklets, so we use keventd + * + * NOTE: annoying asymmetry: if it's active, schedule_work() fails, + * but tasklet_schedule() doesn't. hope the failure is rare. + */ +static void UsbnetAdapterDeferKevent(struct UsbnetAdapter *usbNet, int work) +{ + HARCH_NET_INFO_PRINT("begin"); + if (NULL == usbNet) { + HDF_LOGE("%s UsbnetAdapter object is invalid", __func__); + return; + } + set_bit (work, &usbNet->flags); + /* need update flags to usb_net_host */ + OsalMutexLock(&usbNet->sendSkbClock); + int32_t ret = UsbnetAdapterSendBufToUsb(usbNet->deviceObject, USB_NET_UPDATE_FLAGS, + (const void *)&usbNet->flags, sizeof(usbNet->flags)); + if (ret != HDF_SUCCESS) { + HDF_LOGE("fail to UsbnetAdapterSendBufToUsb SendEvent!"); + OsalMutexUnlock(&usbNet->sendSkbClock); + return; + } + OsalMutexUnlock(&usbNet->sendSkbClock); + + if (!schedule_work (&usbNet->kevent)) { + HARCH_NET_INFO_PRINT("kevent %d may have been dropped\n", work); + } else { + HARCH_NET_INFO_PRINT("kevent %d scheduled\n", work); + } +} + +static void UsbnetAdapterSetRxMode(NetDevice *net) +{ + return; +} + +static void UsbnetAdapterPauseRx(struct UsbnetAdapter *usbNet) +{ + HARCH_NET_INFO_PRINT("begin"); + if (NULL == usbNet) { + HDF_LOGE("%s UsbnetAdapter object is invalid", __func__); + return; + } + set_bit(EVENT_RX_PAUSED, &usbNet->flags); + /* need update flags to usb_net_host */ + OsalMutexLock(&usbNet->sendSkbClock); + int32_t ret = UsbnetAdapterSendBufToUsb(usbNet->deviceObject, USB_NET_UPDATE_FLAGS, + (const void *)&usbNet->flags, sizeof(usbNet->flags)); + if (ret != HDF_SUCCESS) { + HDF_LOGE("fail to UsbnetAdapterSendBufToUsb SendEvent!"); + OsalMutexUnlock(&usbNet->sendSkbClock); + return; + } + OsalMutexUnlock(&usbNet->sendSkbClock); + + HARCH_NET_INFO_PRINT("paused rx queue enabled\n"); +} + +static void UsbnetAdapterUnlinkRxUrbs(struct UsbnetAdapter *usbNet) +{ + HARCH_NET_INFO_PRINT("begin"); + if (NULL == usbNet) { + HDF_LOGE("%s UsbnetAdapter object is invalid", __func__); + return; + } + + if (netif_running(usbNet->net)) { + /* unlink_urbs usbNet usbNet->rxq */ + tasklet_schedule(&usbNet->bh); + } +} + +static void UsbnetAdapterResumeRx(struct UsbnetAdapter *usbNet) +{ + HARCH_NET_INFO_PRINT("begin"); + int num = 0; + SkBuff *skb = NULL; + if (NULL == usbNet) { + HDF_LOGE("%s UsbnetAdapter object is invalid", __func__); + return; + } + + clear_bit(EVENT_RX_PAUSED, &usbNet->flags); + /* need update flags to usb_net_host */ + OsalMutexLock(&usbNet->sendSkbClock); + int32_t ret = UsbnetAdapterSendBufToUsb(usbNet->deviceObject, USB_NET_UPDATE_FLAGS, + (const void *)&usbNet->flags, sizeof(usbNet->flags)); + if (ret != HDF_SUCCESS) { + HDF_LOGE("fail to UsbnetAdapterSendBufToUsb SendEvent!"); + OsalMutexUnlock(&usbNet->sendSkbClock); + return; + } + OsalMutexUnlock(&usbNet->sendSkbClock); + + while ((skb = skb_dequeue(&usbNet->rxqPause)) != NULL) { + UsbnetAdapterSkbReturn(usbNet, skb); + num++; + } + + tasklet_schedule(&usbNet->bh); + HARCH_NET_INFO_PRINT("paused rx queue disabled, %d skbs requeued\n", num); +} + + +static int32_t UsbnetAdapterChangeMtu(NetDevice *net, int newMtu) +{ + //send to device + HARCH_NET_INFO_PRINT("begin"); + if (NULL == net) { + HDF_LOGE("%s net device object is invalid", __func__); + return HDF_FAILURE; + } + + struct UsbnetAdapter *usbNet = netdev_priv(net); + if (NULL == usbNet) { + HDF_LOGE("%s UsbnetAdapter object is invalid", __func__); + return HDF_FAILURE; + } + + /* 1. ll_mtu old_hard_mtu old_rx_urb_size */ + HARCH_NET_INFO_PRINT("newMtu:%d", newMtu); + int llMtu = newMtu + net->hard_header_len; + int oldHardMtu = usbNet->usbnetInfo.hardMtu; + int oldRxUrbSize = usbNet->usbnetInfo.rxUrbSize; + + /* 2. no second zero-length packet read wanted after mtu-sized packets */ + if ((llMtu % usbNet->usbnetInfo.maxpacket) == 0) { + HARCH_NET_INFO_PRINT(""); + return -EDOM; + } + + /* 3. set usbNet->hard_mtu */ + net->mtu = newMtu; + usbNet->usbnetInfo.hardMtu = net->mtu + net->hard_header_len; + + /* 4. pause and resume usbnet */ + if (usbNet->usbnetInfo.rxUrbSize == oldHardMtu) { + usbNet->usbnetInfo.rxUrbSize = usbNet->usbnetInfo.hardMtu; + if (usbNet->usbnetInfo.rxUrbSize > oldRxUrbSize) { + UsbnetAdapterPauseRx(usbNet); + UsbnetAdapterUnlinkRxUrbs(usbNet); + UsbnetAdapterResumeRx(usbNet); + } + } + + /* need transmit hard_mtu to usb net host, UsbnetHostUpdateMaxQlen need this param */ + HARCH_NET_INFO_PRINT("name = %s, flags = %d, usbFlags = %x mtu = %d, hardHeaderLen = %d,\ + link = %d needReset = %d, hardMtu = %d, rxUrbSize = %d, maxpacket =%d", + usbNet->usbnetInfo.name,usbNet->usbnetInfo.flags,usbNet->usbnetInfo.usbFlags,\ + usbNet->usbnetInfo.mtu,usbNet->usbnetInfo.hardHeaderLen,usbNet->usbnetInfo.link,\ + usbNet->usbnetInfo.needReset,usbNet->usbnetInfo.hardMtu,usbNet->usbnetInfo.rxUrbSize,\ + usbNet->usbnetInfo.maxpacket); + /* 5. max qlen depend on hard_mtu and rx_urb_size */ + /* need update flags to usb_net_host */ + OsalMutexLock(&usbNet->sendSkbClock); + int32_t ret = UsbnetAdapterSendBufToUsb(usbNet->deviceObject, USB_NET_UPDATE_MAXQLEN, + (const void *)&usbNet->usbnetInfo, sizeof(usbNet->usbnetInfo)); + if (ret != HDF_SUCCESS) { + HDF_LOGE("fail to UsbnetAdapterSendBufToUsb SendEvent!"); + OsalMutexUnlock(&usbNet->sendSkbClock); + return ret; + } + OsalMutexUnlock(&usbNet->sendSkbClock); + return HDF_SUCCESS; +} + +static void UsbnetAdapterGetStats64(NetDevice *net, struct rtnl_link_stats64 *stats) +{ + //send to device + HARCH_NET_INFO_PRINT("begin"); + + struct UsbnetAdapter *usbNet = netdev_priv(net); + netdev_stats_to_stats64(stats, &net->stats); + dev_fetch_sw_netstats(stats, usbNet->stats64); + + PcpuSwNetstats *stats64 = this_cpu_ptr(usbNet->stats64); + + HARCH_NET_INFO_PRINT ("usbNet stats64->rx_packets = %lu,usbNet stats64->rx_bytes = %lu", + stats64->rx_packets, stats64->rx_bytes); + + HARCH_NET_INFO_PRINT ("usbNet stats64->tx_packets = %lu,usbNet stats64->tx_bytes = %lu", + stats64->tx_packets, stats64->tx_bytes); + + HARCH_NET_INFO_PRINT("end"); + return; +} + +static NetDeviceOps g_UsbnetAdapterDeviceOps = { + .ndo_open = UsbnetAdapterOpen, + .ndo_stop = UsbnetAdapterStop, + .ndo_start_xmit = UsbnetAdapterStartXmit, + .ndo_tx_timeout = UsbnetAdapterTXTimeout, + .ndo_set_rx_mode = UsbnetAdapterSetRxMode, + .ndo_change_mtu = UsbnetAdapterChangeMtu, + .ndo_get_stats64 = UsbnetAdapterGetStats64, + .ndo_set_mac_address = eth_mac_addr, + .ndo_validate_addr = eth_validate_addr, +}; + +/* drivers may override default ethtool_ops in their bind() routine */ +static const EthtoolOps g_UsbnetAdapterEthtoolOps = { +}; + +static void UsbnetAdapterLinkChange(struct UsbnetAdapter *usbNet, bool link, bool need_reset) +{ + HARCH_NET_INFO_PRINT("begin"); + /* update link after link is reseted */ + if (link && !need_reset) { + netif_carrier_on(usbNet->net); + } else { + netif_carrier_off(usbNet->net); + } +} + +static int32_t UsbnetAdapterSetSkb(struct UsbnetAdapter *usbNet, gfp_t flags, + uint32_t infoSize, unsigned char *buff, SkBuff *skb) +{ + if (!skb) { + HARCH_NET_INFO_PRINT("no rx skb\n"); + UsbnetAdapterDeferKevent(usbNet, EVENT_RX_MEMORY); + return HDF_DEV_ERR_NO_MEMORY; + } + + skb_put(skb, infoSize); + if (memcpy_s(skb->data, infoSize, buff, infoSize) != EOK) { + HARCH_NET_INFO_PRINT("memcpy_s error "); + return HDF_ERR_INVALID_PARAM; + } + + printf_char_buffer(skb->data, skb->len, false); + return HDF_SUCCESS; +} + +static void UsbnetAdapterSetUsbNetInfo(struct UsbnetAdapter *usbNet, SkBuff *skb, enum SkbState state) +{ + unsigned long lockflags = 0; + spin_lock_irqsave (&usbNet->rxq.lock, lockflags); + UsbnetAdapterQueueSkb(&usbNet->rxq, skb, RX_START); + spin_unlock_irqrestore (&usbNet->rxq.lock, lockflags); + + PcpuSwNetstats *stats64 = this_cpu_ptr(usbNet->stats64); + HARCH_NET_INFO_PRINT("usbNet stats64->rx_packets = %lu,usbNet stats64->rx_bytes = %lu", + stats64->rx_packets, stats64->rx_bytes); + + if (++usbNet->pktCnt > PKT_COUNT_CLEAR) { + HARCH_NET_INFO_PRINT("usbNet->pktCnt = %d, pktErr = %d", usbNet->pktCnt, usbNet->pktErr); + usbNet->pktCnt = 0; + usbNet->pktErr = 0; + } else { + HARCH_NET_INFO_PRINT("usbNet->pktCnt = %d,pktErr = %d", usbNet->pktCnt, usbNet->pktErr); + if (state == RX_CLEANUP) { + usbNet->pktErr++; + } + + if (usbNet->pktErr > PKT_COUNT_RXKILL) { + set_bit(EVENT_RX_KILL, &usbNet->flags); + } + } +} + +static int32_t UsbnetAdapterRxComplete(struct HdfDeviceObject *device, struct HdfSBuf *data, gfp_t flags) +{ + HARCH_NET_INFO_PRINT("begin"); + unsigned char *buff = NULL; + uint32_t infoSize = 0; + bool flag = HdfSbufReadBuffer(data, (const void **)(&(buff)), &infoSize); + if ((!flag) || buff == NULL) { + HDF_LOGE("%s: fail to read infoTable in event data, flag = %d", __func__, flag); + return HDF_ERR_INVALID_PARAM; + } + + NetDevice *net = (NetDevice *)device->priv; + if (net == NULL) { + return HDF_ERR_INVALID_PARAM; + } + printf_char_buffer(buff, infoSize, false); + struct UsbnetAdapter *usbNet = netdev_priv(net); + if (usbNet == NULL) { + return HDF_ERR_INVALID_PARAM; + } + + SkBuff *skb = NULL; + uint32_t skb_size = sizeof(struct iphdr) + sizeof(struct udphdr) + infoSize; + size_t size = skb_size > usbNet->usbnetInfo.rxUrbSize ? usbNet->usbnetInfo.rxUrbSize : skb_size; + if (test_bit(EVENT_NO_IP_ALIGN, &usbNet->flags)) { + skb = __netdev_alloc_skb(usbNet->net, size, flags); + } else { + skb = __netdev_alloc_skb_ip_align(usbNet->net, size, flags); + } + int32_t ret = UsbnetAdapterSetSkb(usbNet, flags, infoSize, buff, skb); + if (ret != HDF_SUCCESS || skb == NULL) { + HDF_LOGE("%s: fail to set skb, flag = %d", __func__, flag); + return ret; + } + HARCH_NET_INFO_PRINT("infoSize= %d, size = %d, skb->len = %d", infoSize, size, skb->len); + + struct SkbData *entry = (struct SkbData *)skb->cb; + entry->length = 0; + + //success recv + enum SkbState state = RX_DONE; + UsbnetAdapterSetUsbNetInfo(usbNet, skb, state); + + state = UsbnetAdapterDeferBh(usbNet, skb, &usbNet->rxq, state); + HARCH_NET_INFO_PRINT("usbNet->pktCnt = %d, pktErr = %d, state = %d", usbNet->pktCnt, usbNet->pktErr, state); + return HDF_SUCCESS; +} + +// precondition: never called in_interrupt +static DeviceType wlanType = { + .name = "wlan", +}; + +static DeviceType wwanType = { + .name = "wwan", +}; + +static void UsbnetAdapterSetUsbNet(struct HdfDeviceObject *device, + NetDevice *net, struct UsbnetTransInfo *uNetTransInfo) +{ + struct UsbnetAdapter *usbNet = netdev_priv(net); + usbNet->deviceObject = device; + + //info from usb + if (memcpy_s(&(usbNet->usbnetInfo), sizeof(struct UsbnetTransInfo), + uNetTransInfo, sizeof(struct UsbnetTransInfo)) != EOK) { + HARCH_NET_INFO_PRINT("memcpy_s error "); + } + + HARCH_NET_INFO_PRINT("name = %s, flags = %d, usbFlags = %x, mtu = %d, \ + hardHeaderLen = %d, link = %d, needReset = %d, \ + hardMtu = %d, rxUrbSize = %d, maxpacket = %d", + usbNet->usbnetInfo.name, usbNet->usbnetInfo.flags, + usbNet->usbnetInfo.usbFlags, usbNet->usbnetInfo.mtu, + usbNet->usbnetInfo.hardHeaderLen, usbNet->usbnetInfo.link, + usbNet->usbnetInfo.needReset, usbNet->usbnetInfo.hardMtu, + usbNet->usbnetInfo.rxUrbSize, usbNet->usbnetInfo.maxpacket); + + usbNet->stats64 = netdev_alloc_pcpu_stats(PcpuSwNetstats); + if (!usbNet->stats64) { + return; + } + + usbNet->msg_enable = netif_msg_init (g_msgLevel, NETIF_MSG_DRV + | NETIF_MSG_PROBE | NETIF_MSG_LINK| NETIF_MSG_RX_ERR|NETIF_MSG_TX_ERR); + + OsalMutexInit(&usbNet->sendSkbClock); + + init_waitqueue_head(&usbNet->wait); + skb_queue_head_init (&usbNet->rxq); + skb_queue_head_init (&usbNet->txq); + skb_queue_head_init (&usbNet->done); + skb_queue_head_init(&usbNet->rxqPause); + + // init work for tx_complete rx_complete + INIT_WORK(&usbNet->TxCompleteWorkqueue, TxComplete); + INIT_WORK(&usbNet->RxCompleteWorkqueue, RxComplete); + + usbNet->bh.func = (void (*)(unsigned long))UsbnetAdapterBhTasklet; + usbNet->bh.data = (unsigned long)&usbNet->delay; //TimerList delay; + + timer_setup(&usbNet->delay, UsbnetAdapterBh, 0); + + usbNet->net = net; +} + + +static void UsbnetAdapterSetNetDevice(struct UsbnetAdapter *usbNet, NetDevice *net) +{ + // 1.addr + static u8 node_id[ETH_ALEN]; + if (usbNet->usbnetInfo.isGetmacAddr) { + if (memcpy_s(node_id, ETH_ALEN, usbNet->usbnetInfo.macAddr, ETH_ALEN) != EOK) { + return; + } + } else { + eth_random_addr(node_id); + } + memcpy_s(net->dev_addr, sizeof(node_id)/sizeof(node_id[0]), node_id, sizeof(node_id)/sizeof(node_id[0])); + HARCH_NET_INFO_PRINT("macAddr addr %pM", net->dev_addr); + // 2. mtu + net->min_mtu = 0; + net->max_mtu = ETH_MAX_MTU; + net->netdev_ops = &g_UsbnetAdapterDeviceOps; + net->watchdog_timeo = TX_TIMEOUT_JIFFIES; + net->ethtool_ops = &g_UsbnetAdapterEthtoolOps; + + //3. name and mtu + strcpy_s (net->name, sizeof(net->name)/sizeof(net->name[0]), "usb%d"); + if (usbNet->usbnetInfo.isBindDevice) { + if ((usbNet->usbnetInfo.usbFlags & HDF_FLAG_ETHER) != 0 && + ((usbNet->usbnetInfo.usbFlags & HDF_FLAG_POINTTOPOINT) == 0 || + (net->dev_addr[0] & 0x02) == 0)) { + HARCH_NET_INFO_PRINT(); + strcpy_s (net->name, sizeof(net->name)/sizeof(net->name[0]), "eth%d"); + } + + /* WLAN devices should always be named "wlan%d" */ + if ((usbNet->usbnetInfo.usbFlags & FLAG_WLAN) != 0) { + HARCH_NET_INFO_PRINT(); + strcpy_s(net->name, sizeof(net->name)/sizeof(net->name[0]), "wlan%d"); + } + /* WWAN devices should always be named "wwan%d" */ + if ((usbNet->usbnetInfo.usbFlags & FLAG_WWAN) != 0) { + HARCH_NET_INFO_PRINT(); + strcpy_s(net->name, sizeof(net->name)/sizeof(net->name[0]), "wwan%d"); + } + + /* devices that cannot do ARP */ + if ((usbNet->usbnetInfo.usbFlags & FLAG_NOARP) != 0) { + net->flags |= IFF_NOARP; + } + + HARCH_NET_INFO_PRINT("usbNet->usbnetInfo.mtu = %d, net->name= %s", usbNet->usbnetInfo.mtu, net->name); + /* maybe the remote can't receive an Ethernet MTU */ + net->mtu = usbNet->usbnetInfo.mtu; + net->hard_header_len = usbNet->usbnetInfo.hardHeaderLen; + } + + /* let userspace know we have a random address */ + if (ether_addr_equal(net->dev_addr, node_id)) { + net->addr_assign_type = NET_ADDR_RANDOM; + } +} + +static int32_t UsbnetAdapterProbe(struct HdfDeviceObject *device, struct HdfSBuf *data) +{ + HARCH_NET_INFO_PRINT("begin"); + int ret = HDF_SUCCESS; + uint32_t infoSize = 0; + struct UsbnetTransInfo *uNetTransInfo = NULL; + + bool flag = HdfSbufReadBuffer(data, (const void **)(&(uNetTransInfo)), &infoSize); + if ((!flag) || uNetTransInfo == NULL) { + ret = HDF_ERR_INVALID_PARAM; + HDF_LOGE("%s: fail to read infoTable in event data, flag = %d", __func__, flag); + return ret; + } + NetDevice *net = alloc_etherdev(sizeof(struct UsbnetAdapter)); + if (net == NULL) { + HARCH_NET_INFO_PRINT(); + goto out; + } + device->priv = net; + struct UsbnetAdapter *usbNet = netdev_priv(net); + UsbnetAdapterSetUsbNet(device, net, uNetTransInfo); + UsbnetAdapterSetNetDevice(usbNet, net); + HARCH_NET_INFO_PRINT("after usbNet->usbnetInfo.mtu = %d, net->name= %s", usbNet->usbnetInfo.mtu, net->name); + ret = register_netdev(net); + if (ret) { + goto out0; + } + HARCH_NET_INFO_PRINT("register net %pM\n", net->dev_addr); + netif_device_attach(net); + HARCH_NET_INFO_PRINT("netif_device_attach net %pM\n", net->dev_addr); + + if (usbNet->usbnetInfo.usbFlags & FLAG_LINK_INTR) { + HARCH_NET_INFO_PRINT(); + UsbnetAdapterLinkChange(usbNet, 0, 0); + } + return HDF_SUCCESS; + +out0: + cancel_work_sync(&usbNet->TxCompleteWorkqueue); + cancel_work_sync(&usbNet->RxCompleteWorkqueue); + free_netdev(net); +out: + return ret; +} + + +static int32_t UsbnetAdapterDisconnect(struct HdfDeviceObject *device) +{ + HARCH_NET_INFO_PRINT("begin"); + if (device == NULL) { + HDF_LOGI("%s: device is null", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + //free net + NetDevice *net = (NetDevice *)device->priv; + unregister_netdev (net); + + struct UsbnetAdapter *usbNet = netdev_priv(net); + if (usbNet->stats64) { + free_percpu(usbNet->stats64); + } + + UsbnetAdapterTerminateUrbs(usbNet); + skb_queue_purge(&usbNet->rxqPause); + OsalMutexDestroy(&usbNet->sendSkbClock); + + free_netdev(net); + return HDF_SUCCESS; +} + +static int32_t UsbnetAdapterDispatch( + struct HdfDeviceIoClient *client, int32_t cmd, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + HARCH_NET_INFO_PRINT("begin, received cmd = %d", cmd); + + int32_t ret = HDF_ERR_INVALID_PARAM; + switch (cmd) { + case USB_NET_REGISTER_NET: + //add new usbnet device + ret = UsbnetAdapterProbe(client->device, data); + break; + case USB_NET_CLOSE_NET: + ret = UsbnetAdapterDisconnect(client->device); + break; + case USB_NET_RECIVE_DATA_FROM_USB: + ret = UsbnetAdapterRxComplete(client->device, data, GFP_ATOMIC); + break; + default: + HDF_LOGI("%s: no this cmd: %d", __func__, cmd); + break; + } + + if (!HdfSbufWriteInt32(reply, ret)) { + HDF_LOGE("%s: reply int32 fail", __func__); + } + + return ret; +} + +static int32_t UsbnetAdapterBind(struct HdfDeviceObject *device) +{ + HARCH_NET_INFO_PRINT("begin"); + static struct IDeviceIoService UsbnetAdapterService = { + .Dispatch = UsbnetAdapterDispatch, + }; + + if (device == NULL) { + HARCH_NET_INFO_PRINT("device is NULL!"); + return HDF_ERR_INVALID_OBJECT; + } + device->service = &UsbnetAdapterService; + return HDF_SUCCESS; +} + +static int32_t UsbnetAdapterInit(struct HdfDeviceObject *device) +{ + HARCH_NET_INFO_PRINT("begin"); + if (device == NULL) { + HARCH_NET_INFO_PRINT("device is null!"); + return HDF_FAILURE; + } + + HARCH_NET_INFO_PRINT("UsbnetAdapterInit Init success"); + return HDF_SUCCESS; +} + +static void UsbnetAdapterRelease(struct HdfDeviceObject *device) +{ + HARCH_NET_INFO_PRINT("begin"); + return; +} + +struct HdfDriverEntry g_UsbnetAdapterEntry = { + .moduleVersion = 1, + .Bind = UsbnetAdapterBind, + .Init = UsbnetAdapterInit, + .Release = UsbnetAdapterRelease, + .moduleName = "HDF_USB_NET", +}; + +HDF_INIT(g_UsbnetAdapterEntry); diff --git a/framework/model/usb/include/hdf_usb_net_manager.h b/framework/model/usb/include/hdf_usb_net_manager.h new file mode 100644 index 000000000..652b57915 --- /dev/null +++ b/framework/model/usb/include/hdf_usb_net_manager.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2024 Archermind Technology (Nanjing) Co. Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef HDF_USB_NET_MANAGE_H +#define HDF_USB_NET_MANAGE_H + +#include "hdf_base.h" +#include "hdf_device_desc.h" + + +#define MAC_ADDR_SIZE 6 +#define IFNAMSIZ 16 + +/* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */ +#define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */ +#define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */ +#define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */ + +#define HDF_FLAG_NO_SETINT 0x0010 /* device can't set_interface() */ +#define HDF_FLAG_ETHER 0x0020 /* maybe use "eth%d" names */ + +#define FLAG_FRAMING_AX 0x0040 /* AX88772/178 packets */ +#define FLAG_WLAN 0x0080 /* use "wlan%d" names */ +#define FLAG_AVOID_UNLINK_URBS 0x0100 /* don't unlink urbs at usbnet_stop() */ +#define FLAG_SEND_ZLP 0x0200 /* hw requires ZLPs are sent */ +#define FLAG_WWAN 0x0400 /* use "wwan%d" names */ + +#define FLAG_LINK_INTR 0x0800 /* updates link (carrier) status */ +#define HDF_FLAG_POINTTOPOINT 0x1000 /* possibly use "usb%d" names */ + +/* + * Indicates to usbnet, that USB driver accumulates multiple IP packets. + * Affects statistic (counters) and short packet handling. + */ +#define FLAG_MULTI_PACKET 0x2000 +#define FLAG_RX_ASSEMBLE 0x4000 /* rx packets may span >1 frames */ +#define FLAG_NOARP 0x8000 /* device can't do ARP */ + +enum UsbnetServiceCmd { + USB_NET_REGISTER_NET, + USB_NET_CLOSE_NET, + USB_NET_SEND_DATA_TO_USB, + USB_NET_RECIVE_DATA_FROM_USB, + USB_NET_OPEN_USB, + USB_NET_CLOSE_USB, + USB_NET_UPDATE_FLAGS, + USB_NET_UPDATE_MAXQLEN +}; + +struct UsbnetTransInfo { + uint8_t isBindDevice; + char name[IFNAMSIZ]; /**< Network device name {@link IFNAMSIZ} */ + uint8_t isGetmacAddr; + uint8_t macAddr[MAC_ADDR_SIZE]; /**< MAC address {@link MAC_ADDR_SIZE} */ + uint32_t flags; /**< Network port status */ + uint32_t mtu; /**< Maximum transmission unit */ + uint16_t hardHeaderLen; /**< Header length */ + uint8_t link; + uint8_t needReset; + uint32_t usbFlags; /**< usb device match flags */ + uint32_t rxUrbSize; /* size for rx urbs */ + uint32_t hardMtu; /* count any extra framing */ + uint32_t maxpacket; + int txQlen; +}; + +#endif \ No newline at end of file -- Gitee From f3fed4f9839c5c9b3a048adc48b8524f03843679 Mon Sep 17 00:00:00 2001 From: huyx Date: Sun, 15 Sep 2024 10:30:57 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E9=BB=84=E8=93=9D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/khdf/linux/platform/clock/clock_adapter.c | 3 ++- framework/include/platform/clock_if.h | 2 +- framework/support/platform/include/clock/clock_core.h | 2 +- framework/support/platform/src/clock/clock_core.c | 2 +- framework/support/platform/src/clock/clock_if.c | 2 +- framework/support/platform/src/clock/clock_if_u.c | 2 +- .../support/platform/test/unittest/common/hdf_clock_test.cpp | 2 +- framework/test/unittest/platform/common/clock_driver_test.c | 2 +- framework/test/unittest/platform/common/clock_test.c | 2 +- framework/test/unittest/platform/common/clock_test.h | 2 +- framework/test/unittest/platform/entry/hdf_clock_entry_test.c | 2 +- framework/test/unittest/platform/entry/hdf_clock_entry_test.h | 2 +- framework/test/unittest/platform/virtual/clock_virtual.c | 2 +- 13 files changed, 14 insertions(+), 13 deletions(-) diff --git a/adapter/khdf/linux/platform/clock/clock_adapter.c b/adapter/khdf/linux/platform/clock/clock_adapter.c index a58b84b00..b635322c9 100644 --- a/adapter/khdf/linux/platform/clock/clock_adapter.c +++ b/adapter/khdf/linux/platform/clock/clock_adapter.c @@ -1,6 +1,7 @@ /* + * clock driver adapter of linux * - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. + * Copyright (c) 2023 Huawei Device Co., Ltd. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and diff --git a/framework/include/platform/clock_if.h b/framework/include/platform/clock_if.h index f852bb425..682504b20 100644 --- a/framework/include/platform/clock_if.h +++ b/framework/include/platform/clock_if.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. + * Copyright (c) 2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/support/platform/include/clock/clock_core.h b/framework/support/platform/include/clock/clock_core.h index ac366f70a..7e21c73d6 100644 --- a/framework/support/platform/include/clock/clock_core.h +++ b/framework/support/platform/include/clock/clock_core.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. + * Copyright (c) 2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/support/platform/src/clock/clock_core.c b/framework/support/platform/src/clock/clock_core.c index b4968f160..58e4f6dcf 100644 --- a/framework/support/platform/src/clock/clock_core.c +++ b/framework/support/platform/src/clock/clock_core.c @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. + * Copyright (c) 2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/support/platform/src/clock/clock_if.c b/framework/support/platform/src/clock/clock_if.c index 6600af99f..910014209 100644 --- a/framework/support/platform/src/clock/clock_if.c +++ b/framework/support/platform/src/clock/clock_if.c @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. + * Copyright (c) 2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/support/platform/src/clock/clock_if_u.c b/framework/support/platform/src/clock/clock_if_u.c index a225ccd04..1888469d6 100644 --- a/framework/support/platform/src/clock/clock_if_u.c +++ b/framework/support/platform/src/clock/clock_if_u.c @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. + * Copyright (c) 2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/support/platform/test/unittest/common/hdf_clock_test.cpp b/framework/support/platform/test/unittest/common/hdf_clock_test.cpp index 6085799c2..3efa85e70 100644 --- a/framework/support/platform/test/unittest/common/hdf_clock_test.cpp +++ b/framework/support/platform/test/unittest/common/hdf_clock_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. + * Copyright (c) 2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/test/unittest/platform/common/clock_driver_test.c b/framework/test/unittest/platform/common/clock_driver_test.c index c0f41cafb..ad58a6835 100644 --- a/framework/test/unittest/platform/common/clock_driver_test.c +++ b/framework/test/unittest/platform/common/clock_driver_test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. + * Copyright (c) 2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/test/unittest/platform/common/clock_test.c b/framework/test/unittest/platform/common/clock_test.c index f8695a4b9..74e9c8d0e 100644 --- a/framework/test/unittest/platform/common/clock_test.c +++ b/framework/test/unittest/platform/common/clock_test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. + * Copyright (c) 2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/test/unittest/platform/common/clock_test.h b/framework/test/unittest/platform/common/clock_test.h index 805ea439a..b836a8088 100644 --- a/framework/test/unittest/platform/common/clock_test.h +++ b/framework/test/unittest/platform/common/clock_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. + * Copyright (c) 2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/test/unittest/platform/entry/hdf_clock_entry_test.c b/framework/test/unittest/platform/entry/hdf_clock_entry_test.c index 8f6df3d86..5902e8b0a 100644 --- a/framework/test/unittest/platform/entry/hdf_clock_entry_test.c +++ b/framework/test/unittest/platform/entry/hdf_clock_entry_test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. + * Copyright (c) 2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/test/unittest/platform/entry/hdf_clock_entry_test.h b/framework/test/unittest/platform/entry/hdf_clock_entry_test.h index 49c0a4745..ebb60efe2 100644 --- a/framework/test/unittest/platform/entry/hdf_clock_entry_test.h +++ b/framework/test/unittest/platform/entry/hdf_clock_entry_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. + * Copyright (c) 2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. diff --git a/framework/test/unittest/platform/virtual/clock_virtual.c b/framework/test/unittest/platform/virtual/clock_virtual.c index 77e62e3cb..c4ed40092 100644 --- a/framework/test/unittest/platform/virtual/clock_virtual.c +++ b/framework/test/unittest/platform/virtual/clock_virtual.c @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. + * Copyright (c) 2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. -- Gitee From ead4863dc5c755e096d5117e15ff7f355853648f Mon Sep 17 00:00:00 2001 From: huyx Date: Sun, 15 Sep 2024 11:20:02 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E9=BB=84=E8=93=9D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- OAT.xml | 1 + README_zh.md | 2 +- framework/model/usb/include/hdf_usb_pnp_manage.h | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/OAT.xml b/OAT.xml index 49f506f8f..8fb234daf 100644 --- a/OAT.xml +++ b/OAT.xml @@ -67,6 +67,7 @@ Note:If the text contains special characters, please escape them according to th + diff --git a/README_zh.md b/README_zh.md index 6bd22f948..6ef3689fa 100644 --- a/README_zh.md +++ b/README_zh.md @@ -136,7 +136,7 @@ Sensor驱动模型主要由以下两部分组成: ### Display框架模型说明 -基于OpenHarmony驱动框架的Display驱动模型,对下屏蔽了芯片平台差异,方便操作系统跨平台迁移;向上抽象了外设驱动公共业务逻辑,通过配置或差异化适配接口,实现了一套驱动模型兼容不同的外设器件,使得三方厂商可以高效、便捷的切入鸿蒙驱动生态。 +基于OpenHarmony驱动框架的Display驱动模型,对下屏蔽了芯片平台差异,方便操作系统跨平台迁移;向上抽象了外设驱动公共业务逻辑,通过配置或差异化适配接口,实现了一套驱动模型兼容不同的外设器件,使得三方厂商可以高效、便捷的切入OpenHarmony驱动生态。 Display驱动模型主要由以下两部分组成: diff --git a/framework/model/usb/include/hdf_usb_pnp_manage.h b/framework/model/usb/include/hdf_usb_pnp_manage.h index 0f0c811d1..943707dda 100644 --- a/framework/model/usb/include/hdf_usb_pnp_manage.h +++ b/framework/model/usb/include/hdf_usb_pnp_manage.h @@ -54,6 +54,7 @@ enum { }; struct UsbPnpNotifyServiceInfo { + uint8_t curInterfaceNumber; uint32_t length; int32_t devNum; -- Gitee From a3de665afa5a011444badbebc011165c16969df5 Mon Sep 17 00:00:00 2001 From: huyx Date: Sun, 15 Sep 2024 11:23:51 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E9=BB=84=E8=93=9D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- README_zh.md | 2 +- framework/README_zh.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README_zh.md b/README_zh.md index 6ef3689fa..6bd22f948 100644 --- a/README_zh.md +++ b/README_zh.md @@ -136,7 +136,7 @@ Sensor驱动模型主要由以下两部分组成: ### Display框架模型说明 -基于OpenHarmony驱动框架的Display驱动模型,对下屏蔽了芯片平台差异,方便操作系统跨平台迁移;向上抽象了外设驱动公共业务逻辑,通过配置或差异化适配接口,实现了一套驱动模型兼容不同的外设器件,使得三方厂商可以高效、便捷的切入OpenHarmony驱动生态。 +基于OpenHarmony驱动框架的Display驱动模型,对下屏蔽了芯片平台差异,方便操作系统跨平台迁移;向上抽象了外设驱动公共业务逻辑,通过配置或差异化适配接口,实现了一套驱动模型兼容不同的外设器件,使得三方厂商可以高效、便捷的切入鸿蒙驱动生态。 Display驱动模型主要由以下两部分组成: diff --git a/framework/README_zh.md b/framework/README_zh.md index 1b9a80849..9adac731b 100644 --- a/framework/README_zh.md +++ b/framework/README_zh.md @@ -136,7 +136,7 @@ Sensor驱动模型主要由以下两部分组成: ### Display框架模型说明 -基于OpenHarmony驱动框架的Display驱动模型,对下屏蔽了芯片平台差异,方便操作系统跨平台迁移;向上抽象了外设驱动公共业务逻辑,通过配置或差异化适配接口,实现了一套驱动模型兼容不同的外设器件,使得三方厂商可以高效、便捷的切入鸿蒙驱动生态。 +基于OpenHarmony驱动框架的Display驱动模型,对下屏蔽了芯片平台差异,方便操作系统跨平台迁移;向上抽象了外设驱动公共业务逻辑,通过配置或差异化适配接口,实现了一套驱动模型兼容不同的外设器件,使得三方厂商可以高效、便捷的切入OpenHarmony驱动生态。 Display驱动模型主要由以下两部分组成: -- Gitee From 3cebeeaccb0c9b95a6355ceb0778273a9b29b8ad Mon Sep 17 00:00:00 2001 From: huyx Date: Sun, 15 Sep 2024 11:48:12 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E9=BB=84=E8=93=9D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp b/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp index 2dff1f3f3..291c9ac7f 100644 --- a/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp +++ b/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp @@ -56,8 +56,8 @@ public: if (devmgr != nullptr) { devmgr->LoadDevice(devmgr, TEST_SERVICE_NAME); } - } #endif + } static void TearDownTestCase() { #ifdef SAMPLE_DRIVER -- Gitee