xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 1 | /*******************************************************************************
|
| 2 | * Include header files *
|
| 3 | ******************************************************************************/
|
| 4 | #include <linux/module.h>
|
| 5 | #include <linux/etherdevice.h>
|
| 6 | #include <net/sock.h>
|
| 7 | #include <uapi/linux/sched/types.h>
|
| 8 | #include "zvnet_dev.h"
|
| 9 | #include "ram_config.h"
|
| 10 | #include <net/netfilter/nf_conntrack.h>
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 11 |
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 12 | /*******************************************************************************
|
| 13 | * Macro definitions *
|
| 14 | ******************************************************************************/
|
| 15 | #define USE_ZVNET_PACKET
|
| 16 |
|
| 17 | #define WATCHDOG_TIMEO (5*HZ)
|
| 18 | #define XMIT_RETRANS_TIMES 3
|
| 19 | #define ZVNET_SKB_PAD 128
|
| 20 | #define ZVNET_TMP_BUFF_LEN 2048
|
| 21 | #define ZVNET_FREE_BUFF_NUM 256
|
| 22 | #define ZVNET_XMIT_BUFF_NUM 64
|
| 23 | #define ZVNET_XMIT_MAX_QUEUE_NUM 2048
|
| 24 |
|
| 25 | /*******************************************************************************
|
| 26 | * Type definitions *
|
| 27 | ******************************************************************************/
|
| 28 | //AP´«µÝ¸øCAPµÄÊý¾Ý°üÐÅÏ¢£¬¸ÃÄÚÈÝдÈë¹²ÏíDDR
|
| 29 | struct T_zvnet_rpmsg
|
| 30 | {
|
| 31 | void *buff;//skb_headÖ¸Õ룬ÓÃÓÚÊÍ·Åʱ´«µÝ¸øºË¼ä£¬ÒÔ±ã¿ìËÙÊÍ·Å;
|
| 32 | void *head;//ºË¼äÄÜʹÓõĵØÖ·±ß½ç£¬²»ÄÜÔ½½ç£¬·ñÔòÄÚ´æÒç³öÒì³£;ÎïÀíµØÖ·
|
| 33 | unsigned short data_off;//ºË¼ä´«µÝÀ´µÄÊý¾Ý°üÊ×µØÖ·£¬Ö¸ÏòMACÖ¡Í·;ÎïÀíµØÖ·
|
| 34 | unsigned short len;//Êý¾Ý°üÓÐЧ³¤¶È£¬Ò»°ãΪMACÖ¡³¤¶È
|
| 35 | unsigned short end_off;//end offset
|
| 36 | unsigned char dev;//cid 1->8
|
| 37 | unsigned char flag;//0ÆÕͨ°ü£¬1¶þ´Îת·¢°ü£¬2¶þ´Îfastת·¢°ü
|
| 38 | };
|
| 39 | struct T_zvnet_pkt_stats
|
| 40 | {
|
| 41 | unsigned int pkt;
|
| 42 | unsigned int len;
|
| 43 | };
|
| 44 | //AP´«µÝ¸øCAPµÄCTÐÅÏ¢£¬¸ÃÄÚÈÝдÈë¹²ÏíDDR
|
| 45 | struct T_zvnet_rpmsg_ctstat
|
| 46 | {
|
| 47 | void *cap_nfct;
|
| 48 | unsigned char in;
|
| 49 | unsigned char out;
|
| 50 | unsigned short flag;
|
| 51 | struct T_zvnet_pkt_stats pkt[2];
|
| 52 | };
|
| 53 | /*******************************************************************************
|
| 54 | * Local variable definitions *
|
| 55 | ******************************************************************************/
|
| 56 | struct zvnet_device zvnet_dev[DDR_ZVNET_DEV_MAX];
|
| 57 | int *vir_addr_ap = NULL;
|
| 58 | struct sk_buff_head g_zvnet_skb_queue;
|
| 59 | struct zvnet_channel g_zvnet_chn_info;
|
| 60 |
|
| 61 | #ifdef USE_ZVNET_PACKET
|
| 62 | void *g_zvnet_free_buff[ZVNET_FREE_BUFF_NUM];
|
| 63 | int g_zvnet_free_num;
|
| 64 | spinlock_t g_zvnet_free_lock;
|
| 65 | struct semaphore g_zvnet_free_sem;
|
| 66 | struct semaphore g_zvnet_xmit_sem;
|
| 67 | struct sk_buff_head g_zvnet_skb_xmit_queue;
|
| 68 |
|
| 69 | unsigned int g_wrap_packet_size = 1000;
|
| 70 | module_param(g_wrap_packet_size, int, 0644);
|
| 71 | unsigned int g_wrap_num = 10;
|
| 72 | module_param(g_wrap_num, int, 0644);
|
| 73 | unsigned int g_wrap_timeout = 10;
|
| 74 | module_param(g_wrap_timeout, int, 0644);
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 75 | /*jb.qi add for debug network package on 20240806 start*/
|
xf.li | 1867bfa | 2024-08-20 02:32:16 -0700 | [diff] [blame] | 76 | unsigned int g_trace_limit = 0;
|
| 77 | module_param(g_trace_limit, int, 0644);
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 78 | /*jb.qi add for debug network package on 20240806 end*/
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 79 | #endif
|
| 80 |
|
| 81 | /*******************************************************************************
|
| 82 | * Global variable definitions *
|
| 83 | ******************************************************************************/
|
| 84 | extern int (*fast_from_driver)(struct sk_buff *skb, struct net_device* dev);
|
| 85 | extern void v7_dma_map_area(const void *, size_t, int);
|
| 86 | extern void *get_ct_for_ap(struct sk_buff *skb);
|
| 87 | extern void put_ct_for_ap(void *ct);
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 88 | extern spinlock_t fast_fw_spinlock;
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 89 | /*******************************************************************************
|
| 90 | * Local function declarations *
|
| 91 | ******************************************************************************/
|
| 92 | static int zvnet_open(struct net_device *net);
|
| 93 | static int zvnet_close(struct net_device *net);
|
| 94 | static netdev_tx_t zvnet_xmit(struct sk_buff *skb, struct net_device *net);
|
| 95 | static void zvnet_tx_timeout(struct net_device *net, unsigned int txqueue);
|
| 96 | static struct net_device_stats *zvnet_get_stats(struct net_device *net);
|
| 97 | static void v2xnet_init_netdev(struct net_device *net);
|
| 98 | static void zvnet_skb_return (struct zvnet *dev, struct sk_buff *skb);
|
| 99 | static void zvnet_bh (unsigned long param);
|
| 100 | static struct zvnet *v2xnet_dev_init(struct net_device *net, struct zvnet_device *zvnetdev);
|
| 101 |
|
| 102 | static int zvnet_channel_write(struct zvnet_channel *chninfo, void *buf, unsigned int len);
|
| 103 | static int zvnet_channel_read(struct zvnet_channel *chninfo, void *buf, unsigned int len);
|
| 104 | static int zvnet_channel_clear(struct zvnet_channel *chninfo);
|
| 105 | static int zvnet_read_header(struct zvnet_channel *chninfo, struct zvp_header *phzvp);
|
| 106 | static struct sk_buff *zvnet_direct_read_skb(struct zvnet_channel *chninfo);
|
| 107 | static struct sk_buff *zvnet_read_skb(struct zvnet_channel *chninfo, unsigned int tlen, struct zvnet *dev);
|
| 108 | static int zvnet_receive_thread(void *argv);
|
| 109 | static int rpmsgCreateChannel_v2xnet (T_RpMsg_CoreID dstCoreID, T_RpMsg_ChID chID, unsigned int size);
|
| 110 | static int zvnet_createIcpChannel(T_RpMsg_CoreID core_id, T_RpMsg_ChID channel_id, unsigned int channel_size);
|
| 111 | static int zvnet_channel_create(struct zvnet_device *zvnetdev);
|
| 112 |
|
| 113 | /*******************************************************************************
|
| 114 | * Local function implementations *
|
| 115 | ******************************************************************************/
|
| 116 |
|
| 117 | unsigned long virt_to_phys_ap(unsigned long virt)
|
| 118 | {
|
| 119 | if(virt >= (unsigned long)vir_addr_ap && virt <= ((unsigned long)vir_addr_ap+DDR_BASE_LEN_AP))
|
| 120 | return DDR_BASE_ADDR_AP + (virt - (unsigned long)vir_addr_ap);
|
| 121 | return NULL;
|
| 122 | }
|
| 123 |
|
| 124 | unsigned long phys_to_virt_ap(unsigned long phys)
|
| 125 | {
|
| 126 | if(phys >= DDR_BASE_ADDR_AP && phys <= (DDR_BASE_ADDR_AP + DDR_BASE_LEN_AP))
|
| 127 | return (unsigned long)vir_addr_ap + (phys - DDR_BASE_ADDR_AP);
|
| 128 | return NULL;
|
| 129 | }
|
| 130 |
|
| 131 | void check_skb_test(struct sk_buff *skb)
|
| 132 | {
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 133 | if(skb && vir_addr_ap){
|
| 134 | struct sk_buff *tmp_skb;
|
| 135 | if((skb->capHead && (virt_to_phys_ap(skb->head) == NULL))
|
| 136 | || ((skb->capHead == NULL) && virt_to_phys_ap(skb->head))){
|
| 137 | dump_stack();
|
| 138 | msleep(1000);
|
| 139 | panic("capHead err");
|
| 140 | }
|
| 141 | skb_queue_walk(&g_zvnet_skb_queue, tmp_skb) {
|
| 142 | if(tmp_skb == skb){
|
| 143 | dump_stack();
|
| 144 | msleep(1000);
|
| 145 | panic("dup free");
|
| 146 | }
|
| 147 | }
|
| 148 | }
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 149 | }
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 150 | /*jb.qi add for debug network package on 20240806 start*/
|
xf.li | 1867bfa | 2024-08-20 02:32:16 -0700 | [diff] [blame] | 151 | void zvnet_dump_packet(unsigned char * data, int len, int limit_len)
|
| 152 | {
|
| 153 | int i = 0;
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 154 |
|
| 155 | for(i = 0; i < len && i < limit_len; i=i+16)
|
xf.li | 1867bfa | 2024-08-20 02:32:16 -0700 | [diff] [blame] | 156 | {
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 157 | printk("0x%04x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",i,
|
| 158 | *(data+i),*(data+i+1),*(data+i+2),*(data+i+3),*(data+i+4),*(data+i+5),*(data+i+6),*(data+i+7),
|
| 159 | *(data+i+8),*(data+i+9),*(data+i+10),*(data+i+11),*(data+i+12),*(data+i+13),*(data+i+14),*(data+i+15));
|
xf.li | 1867bfa | 2024-08-20 02:32:16 -0700 | [diff] [blame] | 160 | }
|
| 161 | }
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 162 | /*jb.qi add for debug network package on 20240806 end*/
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 163 | int zvnet_get_index_by_netdev(struct net_device *net)
|
| 164 | {
|
| 165 | int i;
|
| 166 |
|
| 167 | for (i = 0; i < DDR_ZVNET_DEV_MAX; i++) {
|
| 168 | if(zvnet_dev[i].net == net)
|
| 169 | return i;
|
| 170 | }
|
| 171 | return -1;
|
| 172 | }
|
| 173 | #ifdef USE_ZVNET_PACKET
|
| 174 | void write_free_apbuf_packet(void)
|
| 175 | {
|
| 176 | int ret,size;
|
| 177 | unsigned long flags;
|
| 178 | void *buf[ZVNET_FREE_BUFF_NUM];
|
| 179 |
|
| 180 | spin_lock_irqsave(&g_zvnet_free_lock, flags);
|
| 181 | if(g_zvnet_free_num == 0){
|
| 182 | spin_unlock_irqrestore(&g_zvnet_free_lock, flags);
|
| 183 | return;
|
| 184 | }
|
| 185 | size = (g_zvnet_free_num << 2);
|
| 186 | memcpy(buf, g_zvnet_free_buff, size);
|
| 187 | g_zvnet_free_num = 0;
|
| 188 | spin_unlock_irqrestore(&g_zvnet_free_lock, flags);
|
| 189 | {
|
| 190 | T_RpMsg_Msg msg = { .coreID = CORE_PS0,
|
| 191 | .chID = 29,
|
| 192 | .flag = RPMSG_WRITE_INT|RPMSG_WRITE_IRQLOCK};
|
| 193 | if((size >> 2) > ZVNET_FREE_BUFF_NUM)
|
| 194 | panic("free packet err");
|
| 195 | msg.buf = &buf;
|
| 196 | msg.len = size;
|
| 197 | zv_info("tofree size=%d", size);
|
| 198 | ret = zvnetWrite(&msg);
|
| 199 | if(ret < 0)
|
| 200 | panic("err, ret:%d!!!!!!", ret);
|
| 201 | }
|
| 202 | }
|
| 203 | #endif
|
| 204 | //½«CAP²à´«µÝÀ´µÄcapbufÖ¸ÕëдÈëDDR£¬ÒÔICP·½Ê½Í¨ÖªCAP²à
|
| 205 | void write_free_apbuf(void *head)
|
| 206 | {
|
| 207 | #ifdef USE_ZVNET_PACKET
|
| 208 | unsigned long flags;
|
| 209 |
|
| 210 | zv_info("g_zvnet_free_num=%d skb=0x%x", g_zvnet_free_num, head);
|
| 211 | spin_lock_irqsave(&g_zvnet_free_lock, flags);
|
| 212 | g_zvnet_free_buff[g_zvnet_free_num] = head;
|
| 213 | g_zvnet_free_num++;
|
| 214 | if(g_zvnet_free_num == ZVNET_FREE_BUFF_NUM){
|
| 215 | int size;
|
| 216 | void *buf[ZVNET_FREE_BUFF_NUM];
|
| 217 |
|
| 218 | size = (g_zvnet_free_num << 2);
|
| 219 | memcpy(buf, g_zvnet_free_buff, size);
|
| 220 | g_zvnet_free_num = 0;
|
| 221 | spin_unlock_irqrestore(&g_zvnet_free_lock, flags);
|
| 222 | if((size >> 2) > ZVNET_FREE_BUFF_NUM)
|
| 223 | panic("free packet err");
|
| 224 | {
|
| 225 | int ret;
|
| 226 | T_RpMsg_Msg msg = { .coreID = CORE_PS0,
|
| 227 | .chID = 29,
|
| 228 | .flag = RPMSG_WRITE_INT|RPMSG_WRITE_IRQLOCK};
|
| 229 | msg.buf = &buf;
|
| 230 | msg.len = size;
|
| 231 | if(printk_ratelimit())
|
| 232 | zv_warn("tofree quick size=%d", size);
|
| 233 | ret = zvnetWrite(&msg);
|
| 234 | if(ret < 0)
|
| 235 | panic("err, ret:%d!!!!!!", ret);
|
| 236 | }
|
| 237 | return;
|
| 238 | }
|
| 239 | if(g_zvnet_free_num > g_wrap_num)
|
| 240 | up(&g_zvnet_free_sem);
|
| 241 | if(g_zvnet_free_num > ZVNET_FREE_BUFF_NUM)
|
| 242 | panic("free_buff err");
|
| 243 | spin_unlock_irqrestore(&g_zvnet_free_lock, flags);
|
| 244 | #else
|
| 245 | int ret = 0;
|
| 246 | long buf = (long)head;
|
| 247 |
|
| 248 | T_RpMsg_Msg msg = { .coreID = CORE_PS0,
|
| 249 | .chID = 29,
|
| 250 | .flag = RPMSG_WRITE_INT,
|
| 251 | .buf = NULL,
|
| 252 | .len = 4 };
|
| 253 | msg.buf = &buf;
|
| 254 | zv_info("tofree 0x%x", head);
|
| 255 | ret = zvnetWrite(&msg);
|
| 256 | if(ret < 0)
|
| 257 | panic("err, ret:%d!!!!!!", ret);
|
| 258 | #endif
|
| 259 | }
|
| 260 |
|
| 261 | struct sk_buff *skb_build_apbuf(struct T_zvnet_rpmsg *pbuf_temp)
|
| 262 | {
|
| 263 | struct skb_shared_info *shinfo;
|
| 264 | struct sk_buff *skb;
|
| 265 | zv_info("build 0x%x 0x%x %d %d", pbuf_temp->buff, pbuf_temp->head, pbuf_temp->data_off, pbuf_temp->len);
|
| 266 | if((unsigned long )pbuf_temp->head < DDR_BASE_ADDR_AP || (unsigned long )pbuf_temp->head > (DDR_BASE_ADDR_AP + DDR_BASE_LEN_AP)){
|
| 267 | zv_err("err 0x%x 0x%x %d %d", pbuf_temp->buff, pbuf_temp->head, pbuf_temp->data_off, pbuf_temp->len);
|
| 268 | panic("addr is not APBUF mem!!!");
|
| 269 | return NULL;
|
| 270 | }
|
| 271 | skb = kmem_cache_alloc(skbuff_head_cache, GFP_ATOMIC);
|
| 272 | if (!skb)
|
| 273 | {
|
| 274 | write_free_apbuf(pbuf_temp->buff);
|
| 275 | zv_err("alloc fail");
|
| 276 | return NULL;
|
| 277 | }
|
| 278 | memset(skb, 0, offsetof(struct sk_buff, tail));
|
| 279 |
|
| 280 | //ÅжÏÊÇ·ñÊÇapbuff
|
| 281 |
|
| 282 | if(pbuf_temp->dev < 0 || pbuf_temp->dev >= DDR_ZVNET_DEV_MAX)
|
| 283 | panic("dev index error!!!");
|
| 284 | skb->head = phys_to_virt_ap((unsigned long )pbuf_temp->head);
|
| 285 | skb->data = skb->head + pbuf_temp->data_off;
|
| 286 | skb->capHead = pbuf_temp->buff;
|
| 287 | //ÐèÒª¿¼ÂÇcacheÐÐ¶ÔÆë
|
| 288 | skb->truesize = SKB_TRUESIZE(skb->data - skb->head + pbuf_temp->len);//°´µÀÀíβ²¿»¹ÓпÉÓõÄÄÚ´æ¿Õ¼ä£¬ÔÝʱδ¿¼ÂÇ;SKB_DATA_ALIGN
|
| 289 |
|
| 290 | refcount_set(&skb->users, 1);
|
| 291 | skb_reset_tail_pointer(skb);
|
| 292 | skb->tail += pbuf_temp->len;
|
| 293 | skb->len = pbuf_temp->len;
|
| 294 | skb->end = skb->head + pbuf_temp->end_off;
|
| 295 | skb->mac_header = (typeof(skb->mac_header))~0U;
|
| 296 | skb->transport_header = (typeof(skb->transport_header))~0U;
|
| 297 | skb->dev = zvnet_dev[pbuf_temp->dev].net;
|
| 298 | if(skb->len == 0 || skb->len > 2000)
|
| 299 | panic("len ERR!!!!!!!!!!\n");
|
| 300 | v7_dma_map_area(skb->head, sizeof(struct skb_shared_info) + pbuf_temp->end_off, DMA_FROM_DEVICE);
|
| 301 | if(IFF_NOARP & skb->dev->flags)
|
| 302 | memcpy(skb->data, skb->dev->dev_addr, 6);
|
| 303 | atomic_set(&skb_shinfo(skb)->dataref, 1);
|
| 304 | /* make sure we initialize shinfo sequentially */
|
| 305 | skb_reset_network_header(skb);
|
| 306 | skb_set_kcov_handle(skb, kcov_common_handle());
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 307 | /*jb.qi add for debug network package on 20240806 start*/
|
xf.li | 1867bfa | 2024-08-20 02:32:16 -0700 | [diff] [blame] | 308 | if(unlikely(g_trace_limit > 0)){
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 309 | printk("-%s-dump_packet-start-%d\n", skb->dev->name, skb->len);
|
| 310 | zvnet_dump_packet(skb->data, skb->len, g_trace_limit);
|
| 311 | printk("-%s-dump_packet-end-\n", skb->dev->name);
|
| 312 | }
|
| 313 | /*jb.qi add for debug network package on 20240806 end*/
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 314 | return skb;
|
| 315 | }
|
| 316 |
|
| 317 | int eth_change_mtu(struct net_device *dev, int new_mtu)
|
| 318 | {
|
| 319 | netdev_warn(dev, "%s is deprecated!\n", __func__);
|
| 320 | dev->mtu = new_mtu;
|
| 321 | return 0;
|
| 322 | }
|
| 323 |
|
| 324 | static void skb_debug_test(struct sk_buff *skb)
|
| 325 | {
|
| 326 | int i;
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 327 | int vcount = skb->len/10;
|
| 328 | int rcount = skb->len%10;
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 329 | char tmp[64] = {0};
|
| 330 | char strbuf[64] = {0};
|
| 331 |
|
| 332 | zv_info("\n");
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 333 | for(i=0; i<vcount; i++) {
|
| 334 | zv_info("%d---0x%x,0x%x,0x%x,0x%x,0x%x,0x%x,0x%x,0x%x,0x%x,0x%x\n",i,skb->data[0+10*i],skb->data[1+10*i],skb->data[2+10*i],
|
| 335 | skb->data[3+10*i],skb->data[4+10*i],skb->data[5+10*i],skb->data[6+10*i],skb->data[7+10*i],skb->data[8+10*i],skb->data[9+10*i]);
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 336 | }
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 337 | if(vcount > 0) {
|
| 338 | memset(tmp,0,sizeof(tmp));
|
| 339 | memset(strbuf,0,sizeof(strbuf));
|
| 340 | sprintf(strbuf,"%d---",vcount);
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 341 |
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 342 | for(i=0; i<rcount; i++)
|
| 343 | {
|
| 344 | sprintf(tmp,"0x%x,",skb->data[10*vcount + i]);
|
| 345 | strcat(strbuf,tmp);
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 346 | }
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 347 | zv_info("%s ",strbuf);
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 348 | }
|
| 349 | zv_info("\n");
|
| 350 | }
|
| 351 |
|
| 352 | static int zvnet_open(struct net_device *net)
|
| 353 | {
|
| 354 | struct zvnet *dev = netdev_priv(net);
|
| 355 |
|
| 356 | if(net->flags & IFF_UP) {
|
| 357 | zv_dbg("%s has been opened!", dev->net->name);
|
| 358 | return -EBUSY;
|
| 359 | }
|
| 360 | netif_start_queue (net);
|
| 361 |
|
| 362 | return 0;
|
| 363 | }
|
| 364 |
|
| 365 | static int zvnet_close(struct net_device *net)
|
| 366 | {
|
| 367 | struct zvnet *dev = netdev_priv(net);
|
| 368 |
|
| 369 | zv_info("%s", dev->net->name);
|
| 370 | netif_stop_queue(net);
|
| 371 | tasklet_kill (&dev->bh);
|
| 372 |
|
| 373 | return 0;
|
| 374 | }
|
| 375 | #ifdef USE_ZVNET_PACKET
|
| 376 | static void zvnet_xmit_packet(void)
|
| 377 | {
|
| 378 | int i,j,k,ret,num;
|
| 379 | unsigned long flags;
|
| 380 | unsigned long flags1;
|
| 381 | struct sk_buff *skb, *tmp;
|
| 382 | T_RpMsg_Msg msg = { .coreID = CORE_PS0,
|
| 383 | .chID = 20,
|
| 384 | .flag = RPMSG_WRITE_INT};
|
| 385 | static struct T_zvnet_rpmsg buff[ZVNET_XMIT_MAX_QUEUE_NUM+1];
|
| 386 |
|
| 387 | spin_lock_irqsave(&g_zvnet_skb_xmit_queue.lock, flags);
|
| 388 | if (skb_queue_empty(&g_zvnet_skb_xmit_queue)) {
|
| 389 | spin_unlock_irqrestore(&g_zvnet_skb_xmit_queue.lock, flags);
|
| 390 | return;
|
| 391 | }
|
| 392 | i = 0;
|
| 393 | skb_queue_walk_safe(&g_zvnet_skb_xmit_queue, skb, tmp) {
|
| 394 | //buff[i].buff = skb;
|
| 395 | buff[i].data_off = skb->data - skb->head;
|
| 396 | //buff[i].head = virt_to_phys(skb->head);
|
| 397 | buff[i].len = skb->len;
|
| 398 | buff[i].end_off = skb->end - skb->head;
|
| 399 | buff[i].dev = zvnet_get_index_by_netdev(skb->dev);
|
| 400 | if(skb->capHead){
|
| 401 | buff[i].buff = skb->capHead;
|
| 402 | #ifdef CONFIG_FASTNAT_MODULE
|
| 403 | if(skb->isFastnat){
|
| 404 | buff[i].head = get_ct_for_ap(skb);
|
| 405 | buff[i].flag = 2;
|
| 406 | }else
|
| 407 | #endif
|
| 408 | {
|
| 409 | buff[i].head = NULL;
|
| 410 | buff[i].flag = 1;
|
| 411 | }
|
| 412 | __skb_unlink(skb, &g_zvnet_skb_xmit_queue);
|
| 413 | kfree_skb(skb);
|
| 414 | }else{
|
| 415 | buff[i].buff = skb;
|
| 416 | buff[i].head = virt_to_phys(skb->head);
|
| 417 | buff[i].flag = 0;
|
| 418 | }
|
| 419 | i++;
|
| 420 | zv_info("xmit skb=0x%x i=%d", skb, i);
|
| 421 | if(i > ZVNET_XMIT_MAX_QUEUE_NUM){
|
| 422 | panic("qlen:%d!", i);
|
| 423 | break;
|
| 424 | }
|
| 425 | }
|
| 426 | spin_lock_irqsave(&g_zvnet_skb_queue.lock, flags1);
|
| 427 | skb_queue_splice_tail_init(&g_zvnet_skb_xmit_queue, &g_zvnet_skb_queue);
|
| 428 | spin_unlock_irqrestore(&g_zvnet_skb_queue.lock, flags1);
|
| 429 | spin_unlock_irqrestore(&g_zvnet_skb_xmit_queue.lock, flags);
|
| 430 | zv_info("g_zvnet_skb_queue.qlen=%d i=%d", g_zvnet_skb_queue.qlen, i);
|
| 431 | for(j = 0; j < i; j = j + ZVNET_XMIT_BUFF_NUM){
|
| 432 | if(i <= (j + ZVNET_XMIT_BUFF_NUM)){
|
| 433 | msg.buf = (void *)&buff[j];
|
| 434 | msg.len = sizeof(struct T_zvnet_rpmsg)*(i-j);/*±¾´ÎÄÜÈ¡¹â*/
|
| 435 | ret = zvnetWrite(&msg);
|
| 436 | }else{
|
| 437 | msg.buf = (void *)&buff[j];
|
| 438 | msg.len = sizeof(struct T_zvnet_rpmsg)*ZVNET_XMIT_BUFF_NUM;
|
| 439 | ret = zvnetWrite(&msg);
|
| 440 | }
|
| 441 | zv_info("xmit write ret=%d size=%d i=%d j=%d", ret, msg.len, i, j);
|
| 442 | if(ret < 0) {
|
| 443 | if(printk_ratelimit())
|
| 444 | zv_warn("zvnet_channel_write ret=%d fail.",ret);
|
| 445 | num = msg.len / sizeof(struct T_zvnet_rpmsg);
|
| 446 | for(k = j; k < j+num; k++){
|
| 447 | if(buff[k].flag == 0){
|
| 448 | skb = (struct sk_buff *)buff[k].buff;
|
| 449 | skb_unlink(skb, &g_zvnet_skb_queue);
|
| 450 | skb->isToap = 0;
|
| 451 | kfree_skb(skb);
|
| 452 | }else{
|
| 453 | if(buff[k].head)
|
| 454 | put_ct_for_ap(buff[k].head);
|
| 455 | write_free_apbuf(buff[k].buff);
|
| 456 | }
|
| 457 | }
|
| 458 | }
|
| 459 | }
|
| 460 | }
|
| 461 | #endif
|
| 462 | static netdev_tx_t zvnet_xmit(struct sk_buff *skb, struct net_device *net)
|
| 463 | {
|
| 464 | #ifdef USE_ZVNET_PACKET
|
| 465 | struct sk_buff *data = NULL;
|
| 466 |
|
| 467 | //zv_info("g_zvnet_skb_xmit_queue.qlen=%d", g_zvnet_skb_xmit_queue.qlen);
|
| 468 | if(g_zvnet_skb_xmit_queue.qlen >= ZVNET_XMIT_MAX_QUEUE_NUM){
|
| 469 | net->stats.tx_errors++;
|
| 470 | net->stats.tx_dropped++;
|
| 471 | zv_err("write err, qlen:%d!", g_zvnet_skb_xmit_queue.qlen);
|
| 472 | kfree_skb(skb);
|
| 473 | return NET_XMIT_SUCCESS;
|
| 474 | }
|
| 475 |
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 476 | if(unlikely(skb_headroom(skb) < NET_SKB_PAD || skb->next//|| skb->capHead
|
| 477 | || skb->fclone || skb->cloned || (skb_shinfo(skb)->nr_frags) || skb->sk || (skb->indev == NULL)
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 478 | || (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) || (skb_has_frag_list(skb)))){
|
| 479 | int ret_len = skb->len;
|
| 480 |
|
| 481 | data = dev_alloc_skb(ret_len + NET_IP_ALIGN);
|
| 482 | if (unlikely(!data)) {
|
| 483 | zv_err("dev_alloc_skb fail,len %d",ret_len);
|
| 484 | net->stats.tx_errors++;
|
| 485 | net->stats.tx_dropped++;
|
| 486 | kfree_skb(skb);
|
| 487 | return NET_XMIT_SUCCESS;
|
| 488 | }
|
| 489 | skb_put(data,ret_len);
|
| 490 | skb_reserve(data, NET_IP_ALIGN);
|
| 491 | memcpy(data->data, skb->data, ret_len);
|
| 492 | zv_info("ap=0x%x next=0x%x clone=%d nr_frags=%d tx_flags=%d frag_list=0x%x", skb->capHead, skb->next, skb->cloned, (skb_shinfo(skb)->nr_frags), skb_shinfo(skb)->tx_flags, skb_shinfo(skb)->frag_list);
|
| 493 | kfree_skb(skb);
|
| 494 | }else{
|
| 495 | data = skb;
|
| 496 | }
|
| 497 | data->dev = net;
|
| 498 | data->isToap = 1;
|
| 499 | v7_dma_map_area(data->head, data->end - data->head + sizeof(struct skb_shared_info), DMA_TO_DEVICE);
|
| 500 | skb_queue_tail(&g_zvnet_skb_xmit_queue, data);
|
| 501 | if(data->len < g_wrap_packet_size || g_zvnet_skb_xmit_queue.qlen > g_wrap_num)
|
| 502 | up(&g_zvnet_xmit_sem);
|
| 503 | net->stats.tx_packets++;
|
| 504 | net->stats.tx_bytes += skb->len;
|
| 505 | #else
|
| 506 | struct zvnet *dev = netdev_priv(net);
|
| 507 | struct zvnet_device *zvnetdev = (struct zvnet_device *)dev->dev_priv;
|
| 508 | int ret = 0;
|
| 509 | struct zvp_header hzvp;
|
| 510 |
|
| 511 | if (!skb) {
|
| 512 | zv_err("err: skb == 0!");
|
| 513 | }
|
| 514 | #if 0
|
| 515 | if (skb->len > ZVNET_TMP_BUFF_LEN) {
|
| 516 | zv_err("err: skb->len(%d)>%d!", skb->len, ZVNET_TMP_BUFF_LEN);
|
| 517 | }
|
| 518 |
|
| 519 | send_header:
|
| 520 | ret = zvnet_channel_write(&(zvnetdev->chn_info), skb->data, skb->len);
|
| 521 |
|
| 522 | if((ret < 0) && (zvnetdev->retran_times < XMIT_RETRANS_TIMES)) {
|
| 523 | zvnetdev->retran_times ++;
|
| 524 | zv_warn("The retran_times is %d.",zvnetdev->retran_times);
|
| 525 | goto send_header;
|
| 526 | }
|
| 527 |
|
| 528 | if (ret >= 0) {
|
| 529 | net->stats.tx_packets++;
|
| 530 | net->stats.tx_bytes += skb->len;
|
| 531 | } else {
|
| 532 | net->stats.tx_errors++;
|
| 533 | net->stats.tx_dropped++;
|
| 534 | zv_err("write err, ret:%d!", ret);
|
| 535 | }
|
| 536 |
|
| 537 | exit:
|
| 538 | kfree_skb(skb);
|
| 539 | #else
|
| 540 | struct T_zvnet_rpmsg buff = {0};
|
| 541 | struct sk_buff *data = NULL;
|
| 542 | if(unlikely(skb_headroom(skb) < NET_SKB_PAD || skb->capHead || skb->next
|
| 543 | || skb->fclone || skb->cloned || (skb_shinfo(skb)->nr_frags)
|
| 544 | || (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) || (skb_has_frag_list(skb)))){
|
| 545 | int ret_len = skb->len;
|
| 546 |
|
| 547 | data = dev_alloc_skb(ret_len + NET_IP_ALIGN);
|
| 548 | if (unlikely(!data)) {
|
| 549 | zv_err("dev_alloc_skb fail,len %d",ret_len);
|
| 550 | net->stats.tx_errors++;
|
| 551 | net->stats.tx_dropped++;
|
| 552 | kfree_skb(skb);
|
| 553 | return NET_XMIT_SUCCESS;
|
| 554 | }
|
| 555 | skb_put(data,ret_len);
|
| 556 | skb_reserve(data, NET_IP_ALIGN);
|
| 557 | memcpy(data->data, skb->data, ret_len);
|
| 558 | data->isToap = 1;
|
| 559 | buff.buff = data;
|
| 560 | buff.data_off = data->data - data->head;
|
| 561 | buff.head = virt_to_phys(data->head);
|
| 562 | buff.len = ret_len;
|
| 563 | buff.end_off = data->end - data->head;
|
| 564 | buff.dev = zvnet_get_index_by_netdev(net);
|
| 565 | zv_info("alloc 0x%x 0x%x %d %d", buff.buff, buff.head, buff.data_off, buff.len);
|
| 566 | zv_info("ap=0x%x next=0x%x clone=%d nr_frags=%d tx_flags=%d frag_list=0x%x", skb->capHead, skb->next, skb->cloned, (skb_shinfo(skb)->nr_frags), skb_shinfo(skb)->tx_flags, skb_shinfo(skb)->frag_list);
|
| 567 | v7_dma_map_area(data->head, buff.end_off + sizeof(struct skb_shared_info), DMA_TO_DEVICE);
|
| 568 | }else{
|
| 569 | skb->isToap = 1;
|
| 570 | buff.buff = skb;
|
| 571 | buff.data_off = skb->data - skb->head;
|
| 572 | buff.head = virt_to_phys(skb->head);
|
| 573 | buff.len = skb->len;
|
| 574 | buff.end_off = skb->end - skb->head;
|
| 575 | buff.dev = zvnet_get_index_by_netdev(net);
|
| 576 | zv_info("transfer 0x%x %d 0x%x %d", buff.buff, buff.head, buff.data_off, buff.len);
|
| 577 | v7_dma_map_area(skb->head, buff.end_off + sizeof(struct skb_shared_info), DMA_TO_DEVICE);
|
| 578 | }
|
| 579 | send_header:
|
| 580 | ret = zvnet_channel_write(&g_zvnet_chn_info, &buff, sizeof(struct T_zvnet_rpmsg));
|
| 581 |
|
| 582 | if((ret < 0) && (zvnetdev->retran_times < XMIT_RETRANS_TIMES)) {
|
| 583 | zvnetdev->retran_times ++;
|
| 584 | zv_warn("The retran_times is %d.",zvnetdev->retran_times);
|
| 585 | goto send_header;
|
| 586 | }
|
| 587 |
|
| 588 | if (ret >= 0) {
|
| 589 | net->stats.tx_packets++;
|
| 590 | net->stats.tx_bytes += skb->len;
|
| 591 | if(data){
|
| 592 | kfree_skb(skb);
|
| 593 | skb_queue_tail(&g_zvnet_skb_queue, data);
|
| 594 | }else
|
| 595 | skb_queue_tail(&g_zvnet_skb_queue, skb);
|
| 596 | zvnetdev->retran_times = 0;
|
| 597 | } else {
|
| 598 | net->stats.tx_errors++;
|
| 599 | net->stats.tx_dropped++;
|
| 600 | zv_err("write err, ret:%d!", ret);
|
| 601 | if(data){
|
| 602 | data->isToap = 0;
|
| 603 | kfree_skb(data);
|
| 604 | }
|
| 605 | else
|
| 606 | skb->isToap = 0;
|
| 607 | kfree_skb(skb);
|
| 608 | }
|
| 609 | #endif
|
| 610 | #endif
|
| 611 | return NET_XMIT_SUCCESS;
|
| 612 | }
|
| 613 |
|
| 614 | /* Called by the kernel when transmit times out */
|
| 615 | static void zvnet_tx_timeout(struct net_device *net, unsigned int txqueue)
|
| 616 | {
|
| 617 | zv_warn("sent timeout!");
|
| 618 | net->stats.tx_errors++;
|
| 619 | netif_wake_queue(net);
|
| 620 | }
|
| 621 |
|
| 622 | static struct net_device_stats *zvnet_get_stats(struct net_device *net)
|
| 623 | {
|
| 624 | return &net->stats;
|
| 625 | }
|
| 626 |
|
| 627 | const struct net_device_ops zvnet_netdev_ops = {
|
| 628 | .ndo_open = zvnet_open,
|
| 629 | .ndo_stop = zvnet_close,
|
| 630 | .ndo_start_xmit = zvnet_xmit,
|
| 631 | .ndo_tx_timeout = zvnet_tx_timeout,
|
| 632 | .ndo_get_stats = zvnet_get_stats,
|
| 633 | .ndo_change_mtu = eth_change_mtu,
|
| 634 | .ndo_validate_addr = eth_validate_addr,
|
| 635 | };
|
| 636 |
|
| 637 | static void v2xnet_init_netdev(struct net_device *net)
|
| 638 | {
|
| 639 | u8 node_id [ETH_ALEN];
|
| 640 |
|
| 641 | random_ether_addr(node_id);
|
| 642 | memcpy (net->dev_addr, node_id, sizeof node_id);
|
| 643 |
|
| 644 | net->netdev_ops = &zvnet_netdev_ops;
|
| 645 | net->watchdog_timeo = WATCHDOG_TIMEO;
|
| 646 | net->flags |= IFF_NOARP;
|
| 647 | }
|
| 648 |
|
| 649 | static void zvnet_skb_return (struct zvnet *dev, struct sk_buff *skb)
|
| 650 | {
|
| 651 | int status;
|
| 652 |
|
| 653 | //zv_info("enter...");
|
| 654 |
|
| 655 | //skb->protocol = eth_type_trans(skb, dev->net);
|
| 656 |
|
| 657 | status = netif_rx (skb);
|
| 658 | if (status == NET_RX_SUCCESS) {
|
| 659 | dev->net->stats.rx_packets++;
|
| 660 | dev->net->stats.rx_bytes += skb->len;
|
| 661 | } else {
|
| 662 | dev->net->stats.rx_errors++;
|
| 663 | zv_err("netif_rx status %d.", status);
|
| 664 | }
|
| 665 | }
|
| 666 |
|
| 667 | static void zvnet_bh (unsigned long param)
|
| 668 | {
|
| 669 | struct zvnet *dev = (struct zvnet *)param;
|
| 670 | struct sk_buff *skb;
|
| 671 |
|
| 672 | while((skb = skb_dequeue(&dev->rxq)) != NULL) {
|
| 673 | if (skb->len)
|
| 674 | zvnet_skb_return(dev, skb);
|
| 675 | else {
|
| 676 | dev->net->stats.rx_errors++;
|
| 677 | dev_kfree_skb (skb);
|
| 678 | zv_err("drop!!!ddrnet_bh skb len == 0.");
|
| 679 | }
|
| 680 | }
|
| 681 | }
|
| 682 |
|
| 683 | static struct zvnet *v2xnet_dev_init(struct net_device *net, struct zvnet_device *zvnetdev)
|
| 684 | {
|
| 685 | struct zvnet *dev = NULL;
|
| 686 |
|
| 687 | dev = netdev_priv(net);
|
| 688 | if(!dev) {
|
| 689 | zv_err("dev is null.\n");
|
| 690 | return NULL;
|
| 691 | }
|
| 692 |
|
| 693 | dev->net = net;
|
| 694 | dev->bh.func = zvnet_bh;
|
| 695 | dev->bh.data = (unsigned long) dev;
|
| 696 |
|
| 697 | skb_queue_head_init (&dev->rxq);
|
| 698 |
|
| 699 | dev->dev_priv = zvnetdev;
|
| 700 |
|
| 701 | return dev;
|
| 702 | }
|
| 703 |
|
| 704 | /*·µ»ØÖµ´óÓÚµÈÓÚ0£¬±íʾдͨµÀ³É¹¦£»Ð¡ÓÚ0±íʾдͨµÀʧ°Ü*/
|
| 705 | static int zvnet_channel_write(struct zvnet_channel *chninfo, void *buf, unsigned int len)
|
| 706 | {
|
| 707 | T_RpMsg_Msg msg;
|
| 708 |
|
| 709 | if(NULL == buf) {
|
| 710 | return -EINVAL;
|
| 711 | }
|
| 712 | memset(&msg, 0, sizeof(msg));
|
| 713 | msg.coreID = chninfo->core_id;
|
| 714 | msg.chID = chninfo->channel_id;
|
| 715 | msg.flag |= RPMSG_WRITE_INT; //| RPMSG_WRITE_IRQLOCK;
|
| 716 | msg.buf = buf;
|
| 717 | msg.len = len;
|
| 718 |
|
| 719 | return zvnetWrite(&msg);
|
| 720 | }
|
| 721 |
|
| 722 | /*·µ»ØÖµ´óÓÚ0£¬±íʾ¶ÁȡͨµÀ³É¹¦£»Ð¡ÓÚµÈÓÚ0±íʾͨµÀÊý¾ÝΪ¿Õ»òʧ°Ü*/
|
| 723 | static int zvnet_channel_read(struct zvnet_channel *chninfo, void *buf, unsigned int len)
|
| 724 | {
|
| 725 | T_RpMsg_Msg msg;
|
| 726 | int ret = 0;
|
| 727 |
|
| 728 | if(NULL == buf) {
|
| 729 | return -EINVAL;
|
| 730 | }
|
| 731 |
|
| 732 | memset(&msg, 0, sizeof(msg));
|
| 733 | msg.coreID = chninfo->core_id;
|
| 734 | msg.chID = chninfo->channel_id;
|
| 735 | msg.buf = buf;
|
| 736 | msg.len = len;
|
| 737 |
|
| 738 | ret = zvnetRead(&msg);
|
| 739 | if (ret <= 0) {
|
| 740 | zv_err("rpm read err=%d!",ret);
|
| 741 | return ret;
|
| 742 | }
|
| 743 |
|
| 744 | return ret;
|
| 745 | }
|
| 746 |
|
| 747 | static int zvnet_channel_clear(struct zvnet_channel *chninfo)
|
| 748 | {
|
| 749 | char *tbuf = NULL;
|
| 750 | unsigned int tlen = chninfo->channel_size/2;
|
| 751 | int ret = 0;
|
| 752 |
|
| 753 | tbuf = (char *)kzalloc(tlen,GFP_ATOMIC);
|
| 754 | if(IS_ERR(tbuf)) {
|
| 755 | zv_err("kzalloc fail! %d byte.", tlen);
|
| 756 | return -ENOMEM;
|
| 757 | }
|
| 758 | ret = zvnet_channel_read(chninfo, tbuf, tlen);
|
| 759 | if(ret < 0) {
|
| 760 | zv_err("zvnet_channel_read fail!");
|
| 761 | ret = 0;
|
| 762 | }
|
| 763 | kfree(tbuf);
|
| 764 | zv_err("Drop channel data. %d byte.",ret);
|
| 765 |
|
| 766 | return ret;
|
| 767 | }
|
| 768 |
|
| 769 | static int zvnet_read_header(struct zvnet_channel *chninfo, struct zvp_header *phzvp)
|
| 770 | {
|
| 771 | return zvnet_channel_read(chninfo, phzvp, sizeof(struct zvp_header));
|
| 772 | }
|
| 773 |
|
| 774 | static struct sk_buff *zvnet_read_skb(struct zvnet_channel *chninfo, unsigned int tlen, struct zvnet *dev)
|
| 775 | {
|
| 776 | struct sk_buff *skb;
|
| 777 |
|
| 778 | if(NULL == chninfo || 0 >= tlen || NULL == dev) {
|
| 779 | return NULL;
|
| 780 | }
|
| 781 | skb = dev_alloc_skb(tlen);
|
| 782 | if (unlikely(!skb)) {
|
| 783 | zv_err("netdev_alloc_skb fail,len %d",tlen);
|
| 784 | return NULL;
|
| 785 | }
|
| 786 | skb_put(skb,tlen);
|
| 787 |
|
| 788 | if(zvnet_channel_read(chninfo, (void *)skb->data, tlen) != tlen) {
|
| 789 | zv_err("zvnet_channel_read fail.\n");
|
| 790 | kfree_skb(skb);
|
| 791 | return NULL;
|
| 792 | }
|
| 793 |
|
| 794 | zv_info("%s dev receive packet %d byte.",dev->net->name, tlen);
|
| 795 |
|
| 796 | skb->dev = dev->net;
|
| 797 |
|
| 798 | return skb;
|
| 799 | }
|
| 800 |
|
| 801 | static struct sk_buff *zvnet_direct_read_skb(struct zvnet_channel *chninfo)
|
| 802 | {
|
| 803 | struct sk_buff *skb;
|
| 804 | #if 0
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 805 | char skb_data[ZVNET_TMP_BUFF_LEN];
|
| 806 | int ret_len = 0;
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 807 |
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 808 | if(NULL == chninfo || NULL == dev) {
|
| 809 | zv_err("zvnet_channel_read null.\n");
|
| 810 | return NULL;
|
| 811 | }
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 812 |
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 813 | ret_len = zvnet_channel_read(chninfo, (void *)skb_data, sizeof(skb_data));
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 814 |
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 815 | if(ret_len <= 0) {
|
| 816 | zv_err("zvnet_channel_read fail.\n");
|
| 817 | return NULL;
|
| 818 | }
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 819 |
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 820 | skb = dev_alloc_skb(ret_len + ZVNET_SKB_PAD);
|
| 821 | if (unlikely(!skb)) {
|
| 822 | zv_err("netdev_alloc_skb fail,len %d",ret_len);
|
| 823 | return NULL;
|
| 824 | }
|
| 825 |
|
| 826 | skb_put(skb,ret_len);
|
| 827 | skb_reserve(skb, ZVNET_SKB_PAD);
|
| 828 | memcpy(skb->data, &skb_data[0], ret_len);
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 829 | #else
|
| 830 | struct T_zvnet_rpmsg buff = {0};
|
| 831 | int ret_len = 0;
|
| 832 | ret_len = zvnet_channel_read(chninfo, (void *)&buff, sizeof(struct T_zvnet_rpmsg));
|
| 833 |
|
| 834 | if(ret_len <= 0) {
|
| 835 | zv_err("rpm read err=%d", ret_len);
|
| 836 | msleep(1000);
|
| 837 | return NULL;
|
| 838 | }
|
| 839 | if(ret_len != sizeof(struct T_zvnet_rpmsg)) {
|
| 840 | panic("err, ret:%d!!!!!!", ret_len);
|
| 841 | }
|
| 842 | skb = skb_build_apbuf(&buff);
|
| 843 | if (unlikely(!skb)) {
|
| 844 | zv_err("netdev_alloc_skb fail,len %d",ret_len);
|
| 845 | return NULL;
|
| 846 | }
|
| 847 | #endif
|
| 848 | //skb->dev = dev->net;
|
| 849 | return skb;
|
| 850 | }
|
| 851 |
|
| 852 | static int zvnet_receive_thread(void *argv)
|
| 853 | {
|
| 854 | //struct zvnet_device *zvnetdev = (struct zvnet_device *)argv;
|
| 855 | //struct zvnet_channel *chninfo = NULL;
|
| 856 | struct zvnet *dev = NULL;
|
| 857 | int index,ret_len,i,num;
|
| 858 | unsigned long flags;
|
| 859 | struct sk_buff *skb = NULL;
|
| 860 | T_RpMsg_Msg msg = { .coreID = CORE_PS0,
|
| 861 | .chID = 20,
|
| 862 | .flag = 0};
|
| 863 | struct T_zvnet_rpmsg buff[ZVNET_XMIT_BUFF_NUM];
|
| 864 | //struct zvp_header hzvp;
|
| 865 | /*
|
| 866 | if(IS_ERR(zvnetdev)) {
|
| 867 | zv_err("The receive thread create fail!");
|
| 868 | return -EINVAL;
|
| 869 | }
|
| 870 | chninfo = &zvnetdev->chn_info;
|
| 871 | dev = zvnetdev->dev;
|
| 872 | */
|
| 873 | while(1) {
|
| 874 | /*
|
| 875 | if(unlikely(!(zvnetdev->net->flags & IFF_UP))) {
|
| 876 | msleep(1000);
|
| 877 | continue;
|
| 878 | }
|
| 879 | */
|
| 880 | //memset(&hzvp, 0, sizeof(hzvp));
|
| 881 | #ifdef USE_ZVNET_PACKET
|
| 882 | //ret_len = zvnet_channel_read(&g_zvnet_chn_info, (void *)buff, sizeof(struct T_zvnet_rpmsg)*ZVNET_XMIT_BUFF_NUM);
|
| 883 | msg.buf = (void *)(buff); // Êý¾Ý
|
| 884 | msg.len = sizeof(struct T_zvnet_rpmsg)*ZVNET_XMIT_BUFF_NUM;// ¶ÁÈ¡µÄ³¤¶È
|
| 885 | ret_len = zvnetRead(&msg); // ¶ÁÈ¡»·ÐζÓÁÐÖÐÒ»¸ö½Úµã£¬
|
| 886 | zv_info("zvnetRead ret=%d", ret_len);
|
| 887 | if(ret_len <= 0) {
|
| 888 | zv_err("rpm read err=%d", ret_len);
|
| 889 | msleep(1000);
|
| 890 | continue;
|
| 891 | }
|
| 892 | if((ret_len % sizeof(struct T_zvnet_rpmsg)) != 0) {
|
| 893 | panic("err, ret:%d!!!!!!", ret_len);
|
| 894 | }
|
| 895 | num = ret_len / sizeof(struct T_zvnet_rpmsg);
|
| 896 | for(i = 0; i < num; i++){
|
| 897 | skb = skb_build_apbuf(&buff[i]);
|
| 898 | if (unlikely(!skb)) {
|
| 899 | zv_err("skb_build_apbuf fail,len=%d i=%d",ret_len,i);
|
| 900 | continue;
|
| 901 | }
|
| 902 | if(unlikely(!(skb->dev->flags & IFF_UP))) {
|
| 903 | if(printk_ratelimit())
|
| 904 | zv_err("drop!!!%s is down.", skb->dev->name);
|
| 905 | dev_kfree_skb (skb);
|
| 906 | continue;
|
| 907 | }
|
| 908 | skb->protocol = eth_type_trans(skb, skb->dev);
|
| 909 | if (fast_from_driver && fast_from_driver(skb, skb->dev))
|
| 910 | {
|
| 911 | continue;
|
| 912 | }
|
| 913 | index = zvnet_get_index_by_netdev(skb->dev);
|
| 914 | if(index < 0)
|
| 915 | panic("");
|
| 916 | dev = zvnet_dev[index].dev;
|
| 917 | spin_lock_irqsave(&dev->rxq.lock, flags);
|
| 918 | __skb_queue_tail(&dev->rxq, skb);
|
| 919 | spin_unlock_irqrestore(&dev->rxq.lock, flags);
|
| 920 | tasklet_schedule(&dev->bh);
|
| 921 | }
|
| 922 | #else
|
| 923 | if(0 != (skb = zvnet_direct_read_skb(&g_zvnet_chn_info))) {
|
| 924 | //skb_debug_test(skb);
|
| 925 | if(unlikely(!(skb->dev->flags & IFF_UP))) {
|
| 926 | zv_err("drop!!!%s is down.", skb->dev->name);
|
| 927 | dev_kfree_skb (skb);
|
| 928 | continue;
|
| 929 | }
|
| 930 | skb->protocol = eth_type_trans(skb, skb->dev);
|
| 931 | #if 1
|
| 932 | if (fast_from_driver && fast_from_driver(skb, skb->dev))
|
| 933 | {
|
| 934 | continue;
|
| 935 | }
|
| 936 | #endif
|
| 937 | index = zvnet_get_index_by_netdev(skb->dev);
|
| 938 | if(index < 0)
|
| 939 | panic("");
|
| 940 | dev = zvnet_dev[index].dev;
|
| 941 | spin_lock_irqsave(&dev->rxq.lock, flags);
|
| 942 | __skb_queue_tail(&dev->rxq, skb);
|
| 943 | spin_unlock_irqrestore(&dev->rxq.lock, flags);
|
| 944 | tasklet_schedule(&dev->bh);
|
| 945 | }
|
| 946 | else {
|
| 947 | zv_err("zvnet_read_header fail.");
|
| 948 | msleep(1000);
|
| 949 | }
|
| 950 | #endif
|
| 951 | }
|
| 952 |
|
| 953 | zv_err("The receive thread exit!");
|
| 954 | return 0;
|
| 955 | }
|
| 956 |
|
| 957 | static int rpmsgCreateChannel_v2xnet (T_RpMsg_CoreID dstCoreID, T_RpMsg_ChID chID, unsigned int size)
|
| 958 | {
|
| 959 | return zvnetCreateChannel (dstCoreID, chID, size);
|
| 960 | }
|
| 961 |
|
| 962 | static int zvnet_createIcpChannel(T_RpMsg_CoreID core_id, T_RpMsg_ChID channel_id, unsigned int channel_size)
|
| 963 | {
|
| 964 | int retval;
|
| 965 |
|
| 966 | retval = rpmsgCreateChannel_v2xnet (core_id, channel_id, channel_size);
|
| 967 | if(retval != RPMSG_SUCCESS && retval != RPMSG_CHANNEL_ALREADY_EXIST)
|
| 968 | goto out;
|
| 969 |
|
| 970 | return retval;
|
| 971 |
|
| 972 | out:
|
| 973 | zv_err("could not create channel.");
|
| 974 | return retval;
|
| 975 | }
|
| 976 | /*
|
| 977 | static int zvnet_channel_create(struct zvnet_device *zvnetdev)
|
| 978 | {
|
| 979 | struct task_struct *th = NULL;
|
| 980 | int retval = 0;
|
| 981 | struct zvnet_channel *chninfo = NULL;
|
| 982 |
|
| 983 | if (IS_ERR(zvnetdev)) {
|
| 984 | return -EINVAL;
|
| 985 | }
|
| 986 | chninfo = &(zvnetdev->chn_info);
|
| 987 | retval = zvnet_createIcpChannel(chninfo->core_id, chninfo->channel_id, chninfo->channel_size);
|
| 988 | if(retval < 0) {
|
| 989 | zv_err("Create IcpChannel fail.");
|
| 990 | return retval;
|
| 991 | }
|
| 992 |
|
| 993 | th = kthread_run(zvnet_receive_thread, (void *)zvnetdev, "zvnet-recv%d", chninfo->channel_id);
|
| 994 | if (IS_ERR(th)) {
|
| 995 | zv_err("Unable to start receive thread.");
|
| 996 | return PTR_ERR(th);
|
| 997 | }
|
| 998 | chninfo->rcv_thread = th;
|
| 999 |
|
| 1000 | return 0;
|
| 1001 | }
|
| 1002 | */
|
| 1003 | static int zvnet_release_thread(void * nouse)
|
| 1004 | {
|
| 1005 | T_RpMsg_Msg msg = { .coreID = CORE_PS0,
|
| 1006 | .chID = 29,
|
| 1007 | .flag = 0};
|
| 1008 | void *buff[ZVNET_FREE_BUFF_NUM];
|
| 1009 | int i,num,retval;
|
| 1010 | struct sk_buff *skb;
|
| 1011 | struct sched_param param = { .sched_priority = 1 };
|
| 1012 | param.sched_priority = 37;
|
| 1013 | sched_setscheduler(current, SCHED_FIFO, ¶m);
|
| 1014 |
|
| 1015 | while(1) {
|
| 1016 | zv_info("g_zvnet_skb_queue.qlen=%d", g_zvnet_skb_queue.qlen);
|
| 1017 | #ifdef USE_ZVNET_PACKET
|
| 1018 | msg.buf = (unsigned char *)(buff); // Êý¾Ý
|
| 1019 | msg.len = 4*ZVNET_FREE_BUFF_NUM;// ¶ÁÈ¡µÄ³¤¶È
|
| 1020 | retval = zvnetRead(&msg); // ¶ÁÈ¡»·ÐζÓÁÐÖÐÒ»¸ö½Úµã£¬
|
| 1021 | zv_info("free read ret=%d", retval);
|
| 1022 | if (retval <= 0) {
|
| 1023 | zv_err("rpm read err=%d", retval);
|
| 1024 | msleep(1000);
|
| 1025 | continue;
|
| 1026 | }
|
| 1027 | if((retval%4) != 0) {
|
| 1028 | panic("err, ret:%d!!!!!!", retval);
|
| 1029 | }
|
| 1030 | num = retval>>2;
|
| 1031 | for(i = 0; i < num; i++){
|
| 1032 | skb = (struct sk_buff *)buff[i];
|
| 1033 | zv_info("free 0x%x", skb);
|
| 1034 | if (skb == NULL || skb->next == NULL || skb->prev == NULL) {
|
| 1035 | panic("rpm read=%d i=%d NULL", retval, i);
|
| 1036 | continue;
|
| 1037 | }
|
| 1038 | skb_unlink(skb, &g_zvnet_skb_queue);
|
| 1039 | if(skb->isToap != 1)
|
| 1040 | panic("");
|
| 1041 | skb->isToap = 0;
|
| 1042 | kfree_skb(skb);
|
| 1043 | }
|
| 1044 | #else
|
| 1045 | void *buff;
|
| 1046 | msg.coreID = CORE_PS0;
|
| 1047 | msg.chID = 29;
|
| 1048 | msg.buf = (unsigned char *)(&buff); // Êý¾Ý
|
| 1049 | msg.len = 4;// ¶ÁÈ¡µÄ³¤¶È
|
| 1050 | //msg.flag |= RPMSG_READ_POLL;
|
| 1051 |
|
| 1052 | retval = zvnetRead(&msg); // ¶ÁÈ¡»·ÐζÓÁÐÖÐÒ»¸ö½Úµã£¬
|
| 1053 | if (retval <= 0) {
|
| 1054 | zv_err("no msg or threand exited");
|
| 1055 | msleep(1000);
|
| 1056 | continue;
|
| 1057 | }
|
| 1058 | if(retval != 4) {
|
| 1059 | panic("err, ret:%d!!!!!!", retval);
|
| 1060 | }
|
| 1061 | zv_info("free 0x%x", buff);
|
| 1062 | skb = (struct sk_buff *)buff;
|
| 1063 | skb_unlink(skb, &g_zvnet_skb_queue);
|
| 1064 | if(skb->isToap != 1)
|
| 1065 | panic("");
|
| 1066 | skb->isToap = 0;
|
| 1067 | kfree_skb(skb);
|
| 1068 | #endif
|
| 1069 | }
|
| 1070 | zv_err("The realse thread exit!");
|
| 1071 | return 0;
|
| 1072 | }
|
| 1073 | #ifdef USE_ZVNET_PACKET
|
| 1074 | static int zvnet_xmit_warp_thread(void * nouse)
|
| 1075 | {
|
| 1076 | while(1) {
|
| 1077 | down_timeout(&g_zvnet_xmit_sem, msecs_to_jiffies(g_wrap_timeout));
|
| 1078 | zvnet_xmit_packet();
|
| 1079 | }
|
| 1080 | zv_err("The xmit warp thread exit!");
|
| 1081 | return 0;
|
| 1082 | }
|
| 1083 |
|
| 1084 | static int zvnet_free_warp_thread(void * nouse)
|
| 1085 | {
|
| 1086 | while(1) {
|
| 1087 | down_timeout(&g_zvnet_free_sem, msecs_to_jiffies(g_wrap_timeout));
|
| 1088 | write_free_apbuf_packet();
|
| 1089 | }
|
| 1090 | zv_err("The free warp thread exit!");
|
| 1091 | return 0;
|
| 1092 | }
|
| 1093 | #endif
|
| 1094 |
|
| 1095 | static int zvnet_update_thread(void * nouse)
|
| 1096 | {
|
| 1097 | T_RpMsg_Msg msg = { .coreID = CORE_PS0,
|
| 1098 | .chID = 21,
|
| 1099 | .flag = 0};
|
| 1100 | int ret_len = 0;
|
| 1101 | struct nf_conn *ct;
|
| 1102 |
|
| 1103 | while(1) {
|
| 1104 | struct T_zvnet_rpmsg_ctstat buff = {0};
|
| 1105 | msg.buf = (void *)(&buff); // Êý¾Ý
|
| 1106 | msg.len = sizeof(struct T_zvnet_rpmsg_ctstat);// ¶ÁÈ¡µÄ³¤¶È
|
| 1107 | ret_len = zvnetRead(&msg); // ¶ÁÈ¡»·ÐζÓÁÐÖÐÒ»¸ö½Úµã£¬
|
| 1108 |
|
| 1109 | if(ret_len <= 0) {
|
| 1110 | zv_err("rpm read err=%d", ret_len);
|
| 1111 | msleep(1000);
|
| 1112 | continue;
|
| 1113 | }
|
| 1114 | if(ret_len != sizeof(struct T_zvnet_rpmsg_ctstat)) {
|
| 1115 | panic("err, ret:%d!!!!!!", ret_len);
|
| 1116 | }
|
| 1117 | ct = (struct nf_conn *)buff.cap_nfct;
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 1118 |
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 1119 | WARN_ON(atomic_read(&ct->ct_general.use) == 0);
|
| 1120 | if(buff.flag){
|
| 1121 | BUG_ON(buff.in <= 0 || buff.out <= 0);
|
| 1122 | if(buff.pkt[0].pkt && buff.pkt[0].len){
|
| 1123 | zv_info("nf_update %x %s %s %d %d", buff.cap_nfct, ct->indev[0]->name, ct->outdev[0]->name, buff.in, buff.out);
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 1124 | zvnet_dev[buff.in-1].net->stats.rx_packets += buff.pkt[0].pkt;
|
| 1125 | zvnet_dev[buff.in-1].net->stats.rx_bytes += buff.pkt[0].len;
|
| 1126 | zvnet_dev[buff.out-1].net->stats.tx_packets += buff.pkt[0].pkt;
|
| 1127 | zvnet_dev[buff.out-1].net->stats.tx_bytes += buff.pkt[0].len;
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 1128 | }
|
| 1129 | if(buff.pkt[1].pkt && buff.pkt[1].len){
|
| 1130 | zv_info("nf_update %x %s %s %d %d", buff.cap_nfct, ct->indev[1]->name, ct->outdev[1]->name, buff.out, buff.in);
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 1131 | zvnet_dev[buff.out-1].net->stats.rx_packets += buff.pkt[1].pkt;
|
| 1132 | zvnet_dev[buff.out-1].net->stats.rx_bytes += buff.pkt[1].len;
|
| 1133 | zvnet_dev[buff.in-1].net->stats.tx_packets += buff.pkt[1].pkt;
|
| 1134 | zvnet_dev[buff.in-1].net->stats.tx_bytes += buff.pkt[1].len;
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 1135 | }
|
| 1136 | spin_lock_bh(&fast_fw_spinlock);
|
| 1137 | ct->packet_info[IP_CT_DIR_ORIGINAL].bytes += buff.pkt[IP_CT_DIR_ORIGINAL].len;
|
| 1138 | ct->packet_info[IP_CT_DIR_ORIGINAL].packets += buff.pkt[IP_CT_DIR_ORIGINAL].pkt;
|
| 1139 | ct->packet_info[IP_CT_DIR_REPLY].bytes += buff.pkt[IP_CT_DIR_REPLY].len;
|
| 1140 | ct->packet_info[IP_CT_DIR_REPLY].packets += buff.pkt[IP_CT_DIR_REPLY].pkt;
|
| 1141 | spin_unlock_bh(&fast_fw_spinlock);
|
| 1142 | zv_info("nf_update %x %d %d %d %d", buff.cap_nfct, buff.pkt[0].pkt, buff.pkt[0].len, buff.pkt[1].pkt, buff.pkt[1].len);
|
| 1143 | }else{
|
| 1144 | zv_info("nf_put %x", buff.cap_nfct);
|
| 1145 | nf_conntrack_put(buff.cap_nfct);
|
| 1146 | }
|
| 1147 | }
|
| 1148 | zv_err("The update thread exit!");
|
| 1149 | return 0;
|
| 1150 | }
|
| 1151 |
|
| 1152 | /*******************************************************************************
|
| 1153 | * Global function implementations *
|
| 1154 | ******************************************************************************/
|
| 1155 | static int __init zvnet_init(void)
|
| 1156 | {
|
| 1157 | int i;
|
| 1158 | int err = -ENOMEM;
|
| 1159 | struct zvnet *dev = NULL;
|
| 1160 | struct net_device *net = NULL;
|
| 1161 | struct zvnet_device *zvnetdev = NULL;
|
| 1162 |
|
| 1163 | #ifdef USE_ZVNET_PACKET
|
| 1164 | skb_queue_head_init(&g_zvnet_skb_xmit_queue);
|
| 1165 | spin_lock_init(&g_zvnet_free_lock);
|
| 1166 | sema_init(&g_zvnet_free_sem, 0);
|
| 1167 | sema_init(&g_zvnet_xmit_sem, 0);
|
| 1168 | #endif
|
| 1169 | skb_queue_head_init(&g_zvnet_skb_queue);
|
| 1170 | g_zvnet_chn_info.core_id = CORE_PS0;
|
| 1171 | g_zvnet_chn_info.channel_id = ICP_CHN_ZVNET1;
|
| 1172 | g_zvnet_chn_info.channel_size = ICP_CHANNEL_SIZE;
|
| 1173 | for (i = 0; i < DDR_ZVNET_DEV_MAX; i++) {
|
| 1174 | zvnetdev = &zvnet_dev[i];
|
| 1175 | memset(zvnetdev, 0, sizeof(struct zvnet_device));
|
| 1176 | net = alloc_etherdev(sizeof(struct zvnet));
|
| 1177 | if (!net) {
|
| 1178 | zv_err("could not allocate device.\n");
|
| 1179 | return err;
|
| 1180 | }
|
| 1181 |
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 1182 | net->needed_headroom += ZVNET_SKB_PAD;//NET_SKB_PAD;
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 1183 | sprintf(net->name, "%s%d", ZVNET_IFNAME_PREFIX, i);
|
| 1184 | dev = v2xnet_dev_init(net, zvnetdev);
|
| 1185 | v2xnet_init_netdev(net);
|
xf.li | a06dd22 | 2024-10-14 09:07:20 +0000 | [diff] [blame^] | 1186 | if(0 == i){
|
xf.li | 2f42418 | 2024-08-20 00:47:34 -0700 | [diff] [blame] | 1187 | net->flags = (net->flags & (~IFF_NOARP));
|
| 1188 | }
|
| 1189 | err = register_netdev(net);
|
| 1190 | if (err) {
|
| 1191 | zv_err("register_netdev error:%d :%d\n",err,i);
|
| 1192 | return err;
|
| 1193 | }
|
| 1194 | zvnetdev->dev = dev;
|
| 1195 | zvnetdev->net = net;
|
| 1196 | /*
|
| 1197 | zvnetdev->chn_info.core_id = CAP_ID;
|
| 1198 | zvnetdev->chn_info.channel_id = ICP_CHN_ZVNET1 + i;//zvnet_collect[i];
|
| 1199 | zvnetdev->chn_info.channel_size = ICP_CHANNEL_SIZE;
|
| 1200 | err = zvnet_channel_create(zvnetdev);
|
| 1201 | if(0 != err) {
|
| 1202 | zv_err("zvnet_channel_create error:%d :%d\n",err,i);
|
| 1203 | goto out_unregister_netdev;
|
| 1204 | }
|
| 1205 | */
|
| 1206 | }
|
| 1207 | {
|
| 1208 | struct task_struct *th = NULL;
|
| 1209 | int retval = 0;
|
| 1210 | retval = zvnet_createIcpChannel(CORE_PS0, 21, 64);
|
| 1211 | if(retval < 0) {
|
| 1212 | zv_err("Create IcpChannel channel_21 fail.");
|
| 1213 | return retval;
|
| 1214 | }
|
| 1215 |
|
| 1216 | th = kthread_run(zvnet_update_thread, 0, "zvnet-update%d", 21);
|
| 1217 | if (IS_ERR(th)) {
|
| 1218 | zv_err("Unable to start update thread.");
|
| 1219 | return PTR_ERR(th);
|
| 1220 | }
|
| 1221 | retval = zvnet_createIcpChannel(CORE_PS0, 20, ICP_CHANNEL_SIZE);
|
| 1222 | if(retval < 0) {
|
| 1223 | zv_err("Create IcpChannel channel_20 fail.");
|
| 1224 | return retval;
|
| 1225 | }
|
| 1226 |
|
| 1227 | th = kthread_run(zvnet_receive_thread, 0, "zvnet-recv%d", 20);
|
| 1228 | if (IS_ERR(th)) {
|
| 1229 | zv_err("Unable to start receive thread.");
|
| 1230 | return PTR_ERR(th);
|
| 1231 | }
|
| 1232 | g_zvnet_chn_info.rcv_thread = th;
|
| 1233 |
|
| 1234 | retval = zvnet_createIcpChannel(CORE_PS0, 29, ICP_CHANNEL_SIZE);
|
| 1235 | if(retval < 0) {
|
| 1236 | zv_err("Create IcpChannel channel_29 fail.");
|
| 1237 | return retval;
|
| 1238 | }
|
| 1239 |
|
| 1240 | th = kthread_run(zvnet_release_thread, 0, "zvnet-free%d", 29);
|
| 1241 | if (IS_ERR(th)) {
|
| 1242 | zv_err("Unable to start release thread.");
|
| 1243 | return PTR_ERR(th);
|
| 1244 | }
|
| 1245 | #ifdef USE_ZVNET_PACKET
|
| 1246 | th = kthread_run(zvnet_xmit_warp_thread, 0, "zvnet-xmit-wrap");
|
| 1247 | if (IS_ERR(th)) {
|
| 1248 | zv_err("Unable to start xmit_warp thread.");
|
| 1249 | return PTR_ERR(th);
|
| 1250 | }
|
| 1251 |
|
| 1252 | th = kthread_run(zvnet_free_warp_thread, 0, "zvnet-free-wrap");
|
| 1253 | if (IS_ERR(th)) {
|
| 1254 | zv_err("Unable to start free_warp thread.");
|
| 1255 | return PTR_ERR(th);
|
| 1256 | }
|
| 1257 | #endif
|
| 1258 | vir_addr_ap = ioremap_cache(DDR_BASE_ADDR_AP, DDR_BASE_LEN_AP);
|
| 1259 | zv_warn("vir_addr_ap vir=0x%x phy=0x%x len=0x%x", vir_addr_ap, DDR_BASE_ADDR_AP, DDR_BASE_LEN_AP);
|
| 1260 | if(vir_addr_ap == NULL)
|
| 1261 | {
|
| 1262 | zv_err("AP mmap failed.\n");
|
| 1263 | return -1;
|
| 1264 | }
|
| 1265 |
|
| 1266 | }
|
| 1267 | zv_dbg("success.\n");
|
| 1268 | return 0;
|
| 1269 |
|
| 1270 | }
|
| 1271 |
|
| 1272 | static void __exit zvnet_exit(void)
|
| 1273 | {
|
| 1274 | int i;
|
| 1275 | struct net_device *net;
|
| 1276 |
|
| 1277 | for (i = 0; i < DDR_ZVNET_DEV_MAX; i++) {
|
| 1278 | net = zvnet_dev[i].net;
|
| 1279 | unregister_netdev(net);
|
| 1280 | free_netdev(net);
|
| 1281 | zvnet_dev[i].net = NULL;
|
| 1282 | }
|
| 1283 | zv_warn("success.\n");
|
| 1284 | }
|
| 1285 |
|
| 1286 | late_initcall(zvnet_init);
|
| 1287 | module_exit(zvnet_exit);
|
| 1288 |
|
| 1289 | MODULE_AUTHOR("ZXIC");
|
| 1290 | MODULE_DESCRIPTION("ZXIC CAP LAN NET DEVICE");
|
| 1291 | MODULE_LICENSE("GPL");
|
| 1292 |
|