net:wireless:Support eswin usb wifi ECR6600U
[platform/kernel/linux-starfive.git] / drivers / net / wireless / eswin / fullmac / ecrnx_amt.c
1 /**
2  ******************************************************************************
3  *
4  * @file ecrnx_amt.c
5  *
6  * @brief Entry point of the ECRNX driver
7  *
8  * Copyright (C) ESWIN 2015-2020
9  *
10  ******************************************************************************
11  */
12  
13 #include "ecrnx_main.h"
14 #include "eswin_utils.h"
15 #include "ecrnx_calibration_data.h"
16
17 #ifdef CONFIG_ECRNX_WIFO_CAIL
18 #define AMT_GAIN_DELTA_MSG_FLAG ("gaindelta=")
19 #define AMT_GAIN_DELTA_MSG_BUFF_LEN 60 //strlen(AMT_GAIN_DELTA_MSG_FLAG) + sizeof(gain_delta)
20 static char gain_delta_msg_buf[AMT_GAIN_DELTA_MSG_BUFF_LEN];
21 extern bool set_gain;
22
23 struct ecrnx_iwpriv_amt_vif amt_vif;
24 #if defined(CONFIG_WIRELESS_EXT) && defined(CONFIG_WEXT_PRIV)
25 extern const struct iw_handler_def  ecrnx_wext_private_handler;
26 #endif
27
28 static int eswin_netdev_amt_open(struct net_device *ndev)
29 {
30         ECRNX_DBG("amt netdev open\n");
31
32         return 0;
33 }
34
35 static int eswin_netdev_amt_stop(struct net_device *ndev)
36 {
37         ECRNX_DBG("amt netdev stop\n");
38
39         return 0;
40 }
41
42 static netdev_tx_t eswin_netdev_amt_start_xmit(struct sk_buff *skb,
43                                             struct net_device *ndev)
44 {
45         if (skb)
46                 dev_kfree_skb_any(skb);
47
48         return NETDEV_TX_OK;
49 }
50
51 static const struct net_device_ops eswin_netdev_ops_amt = {
52         .ndo_open = eswin_netdev_amt_open,
53         .ndo_stop = eswin_netdev_amt_stop,
54         .ndo_start_xmit = eswin_netdev_amt_start_xmit
55 };
56
57 static int ecrnx_amt_gain_delta_msg_send(void)
58 {
59     if (set_gain != true)
60         return -1;
61
62     memcpy(gain_delta_msg_buf, AMT_GAIN_DELTA_MSG_FLAG, strlen(AMT_GAIN_DELTA_MSG_FLAG));
63     memcpy((gain_delta_msg_buf + strlen(AMT_GAIN_DELTA_MSG_FLAG)), gain_delta, GAIN_DELTA_CFG_BUF_SIZE);
64
65     host_send(gain_delta_msg_buf, sizeof(gain_delta_msg_buf), TX_FLAG_AMT_IWPRIV_IE);
66
67     return 0;
68 }
69
70 int ecrnx_amt_init(void)
71 {
72         struct net_device *ndev;
73 #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0))
74     ndev = alloc_netdev(0, "amt0", ether_setup);
75 #else
76         ndev = alloc_netdev(0, "amt0", NET_NAME_UNKNOWN, ether_setup);
77 #endif
78         if (!ndev) {
79                 ECRNX_DBG("alloc netdev fail !!");
80                 return -1;
81         }
82
83         amt_vif.ndev = ndev;
84         amt_vif.rxlen = 0;
85         init_waitqueue_head(&amt_vif.rxdataq);
86
87         ndev->netdev_ops = &eswin_netdev_ops_amt;
88 #if defined(CONFIG_WIRELESS_EXT) && defined(CONFIG_WEXT_PRIV)
89         ndev->wireless_handlers = &ecrnx_wext_private_handler;
90 #endif
91         /* clear the mac address */
92         memset(ndev->dev_addr, 0, ETH_ALEN);
93
94         if (register_netdev(ndev) != 0)
95         goto err_dev;
96
97     ecrnx_amt_gain_delta_msg_send();
98
99         ECRNX_PRINT(" %s:register the amt net device success\n", __func__);
100         return 0;
101
102 err_dev:
103         ECRNX_ERR(" %s couldn't register the amt net device!!",  __func__);
104         free_netdev(ndev);
105         amt_vif.ndev = NULL;
106     return -1;
107 }
108
109 void ecrnx_amt_deinit(void)
110 {
111     ECRNX_DBG(ECRNX_FN_ENTRY_STR);
112
113         if (amt_vif.ndev)
114                 unregister_netdev(amt_vif.ndev);
115
116         amt_vif.ndev = NULL;
117 }
118 #endif
119
120  
121
122