hc
2023-11-06 15ade055295d13f95d49e3d99b09f3bbfb4a43e7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * Copyright (C) 2016 Spreadtrum Communications Inc.
 *
 * Authors    : jinglong.chen
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
 
#ifndef __MCHN_H__
#define __MCHN_H__
 
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/interrupt.h>
 
#define HW_TYPE_SDIO 0
#define HW_TYPE_PCIE 1
#define MCHN_MAX_NUM 32
 
struct mbuf_t {
   struct __mbuf *next;
   unsigned char *buf;
   unsigned long  phy;
   unsigned short len;
   unsigned short rsvd;
   unsigned int   seq;
};
 
struct buffer_pool_t {
   int size;
   int free;
   int payload;
   void *head;
   char *mem;
   spinlock_t lock;
   unsigned long irq_flags;
};
 
struct mchn_ops_t {
   /*channel id*/
   int channel;
   /*hardware interface type*/
   int hif_type;
   /*inout=1 tx side, inout=0 rx side */
   int inout;
   /*set callback pop_link/push_link frequency */
   int intr_interval;
   /*data buffer size */
   int buf_size;
   /*mbuf pool size */
   int pool_size;
   /*The large number of trans */
   int once_max_trans;
   /*rx side threshold */
   int rx_threshold;
   /*tx timeout */
   int timeout;
   /*callback in top tophalf*/
   int cb_in_irq;
   /*pending link num*/
   int max_pending;
   /*pop link list, (1)chn id, (2)mbuf link head
    *(3) mbuf link tail (4)number of node
    */
   int (*pop_link)(int, mbuf_t *, mbuf_t *, int);
   /*ap don't need to implementation*/
   int (*push_link)(int, mbuf_t **, mbuf_t **, int *);
   /*(1)channel id (2)trans time, -1 express timeout*/
   int (*tx_complete)(int, int);
   int (*power_notify)(int, int);
};
 
struct mchn_info_t {
   mchn_ops_t *ops[MCHN_MAX_NUM];
   struct {
       buffer_pool_t pool;
   } chn_public[MCHN_MAX_NUM];
};
 
/*configuration channel*/
int mchn_init(struct mchn_ops_t *ops);
/*cancellation channel*/
int mchn_deinit(struct mchn_ops_t *ops);
/*push link list*/
int mchn_push_link(int channel, struct mbuf_t *head, struct mbuf_t *tail,
   int num);
/*push link list, Using a blocking mode, Timeout wait for tx_complete*/
int mchn_push_link_wait_complete(int chn, struct mbuf_t *head,
   struct mbuf_t *tail, int num, int timeout);
int mchn_hw_pop_link(int chn, void *head, void *tail, int num);
int mchn_hw_tx_complete(int chn, int timeout);
int mchn_hw_req_push_link(int chn, int need);
int mbuf_link_alloc(int chn, struct mbuf_t **head, struct mbuf_t **tail,
   int *num);
int mbuf_link_free(int chn, struct mbuf_t *head, struct mbuf_t *tail, int num);
int mchn_hw_max_pending(int chn);
struct mchn_info_t *mchn_info(void);
struct mchn_ops_t *mchn_ops(int channel);
#endif