1 /*
2  * Copyright (c) 2024, sakumisu
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #ifndef USBH_RTL8152_H
7 #define USBH_RTL8152_H
8 
9 struct usbh_rtl8152 {
10     struct usbh_hubport *hport;
11     struct usb_endpoint_descriptor *bulkin;  /* Bulk IN endpoint */
12     struct usb_endpoint_descriptor *bulkout; /* Bulk OUT endpoint */
13     struct usb_endpoint_descriptor *intin;   /* INTR IN endpoint  */
14     struct usbh_urb bulkout_urb;
15     struct usbh_urb bulkin_urb;
16     struct usbh_urb intin_urb;
17 
18     uint8_t intf;
19 
20     uint8_t mac[6];
21     bool connect_status;
22     uint32_t speed[2];
23 
24     uint8_t version;
25     uint8_t eee_adv;
26     uint8_t eee_en;
27     uint8_t supports_gmii;
28     uint16_t min_mtu;
29     uint16_t max_mtu;
30     uint16_t ocp_base;
31     uint32_t saved_wolopts;
32     uint32_t rx_buf_sz;
33 
34     struct rtl_ops {
35         void (*init)(struct usbh_rtl8152 *tp);
36         int (*enable)(struct usbh_rtl8152 *tp);
37         void (*disable)(struct usbh_rtl8152 *tp);
38         void (*up)(struct usbh_rtl8152 *tp);
39         void (*down)(struct usbh_rtl8152 *tp);
40         void (*unload)(struct usbh_rtl8152 *tp);
41         bool (*in_nway)(struct usbh_rtl8152 *tp);
42         void (*hw_phy_cfg)(struct usbh_rtl8152 *tp);
43         void (*autosuspend_en)(struct usbh_rtl8152 *tp, bool enable);
44         void (*change_mtu)(struct usbh_rtl8152 *tp);
45     } rtl_ops;
46 
47     void *user_data;
48 };
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 int usbh_rtl8152_get_connect_status(struct usbh_rtl8152 *rtl8152_class);
55 
56 void usbh_rtl8152_run(struct usbh_rtl8152 *rtl8152_class);
57 void usbh_rtl8152_stop(struct usbh_rtl8152 *rtl8152_class);
58 
59 uint8_t *usbh_rtl8152_get_eth_txbuf(void);
60 int usbh_rtl8152_eth_output(uint32_t buflen);
61 void usbh_rtl8152_eth_input(uint8_t *buf, uint32_t buflen);
62 void usbh_rtl8152_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV);
63 
64 #ifdef __cplusplus
65 }
66 #endif
67 
68 #endif /* USBH_RTL8152_H */