]> rtime.felk.cvut.cz Git - lisovros/linux_canprio.git/blob - drivers/net/can/softing/softing.h
Added socketcan from SVN r903
[lisovros/linux_canprio.git] / drivers / net / can / softing / softing.h
1 /*
2  * softing common interfaces
3  *
4  * by Kurt Van Dijck, 06-2008
5  */
6
7 #include <linux/interrupt.h>
8 #include <linux/netdevice.h>
9 #include <linux/can.h>
10 #include <linux/can/dev.h>
11
12 struct softing;
13 struct sofing_desc;
14
15 /* special attribute, so we should not rely on the ->priv pointers
16  * before knowing how to interpret these
17  */
18 struct softing_attribute;
19
20 struct softing_priv {
21         struct can_priv can;    /* must be the first member! */
22         struct net_device *netdev;
23         struct softing *card;
24         struct {
25                 int pending;
26                 /* variables wich hold the circular buffer */
27                 int echo_put;
28                 int echo_get;
29         } tx;
30         struct can_bittiming_const btr_const;
31         int index;
32         u8 output;
33         u16 chip;
34         struct attribute_group sysfs;
35 };
36 #define netdev2softing(netdev)  ((struct softing_priv *)netdev_priv(netdev))
37
38 /* the 'all cards have the same' fields definition */
39 extern const struct can_bittiming_const softing_btr_const;
40
41 struct softing_desc {
42         unsigned int manf;
43         unsigned int prod;
44         /* generation
45          * 1st with NEC or SJA1000
46          * 8bit, exclusive interrupt, ...
47          * 2nd only SJA11000
48          * 16bit, shared interrupt
49          */
50         int generation;
51         unsigned int freq;      /*crystal in MHz */
52         unsigned int max_brp;
53         unsigned int max_sjw;
54         unsigned long dpram_size;
55         char name[32];
56         struct {
57                 unsigned long offs;
58                 unsigned long addr;
59                 char fw[32];
60         } boot, load, app;
61 };
62
63 struct softing {
64         int nbus;
65         struct softing_priv *bus[2];
66         spinlock_t       spin; /* protect this structure & DPRAM access */
67
68         struct {
69                 /* indication of firmware status */
70                 int up;
71                 /* protection of the 'up' variable */
72                 struct mutex lock;
73         } fw;
74         struct {
75                 int nr;
76                 int requested;
77                 struct tasklet_struct bh;
78                 int svc_count;
79         } irq;
80         struct {
81                 int pending;
82                 int last_bus;
83                 /* keep the bus that last tx'd a message,
84                  * in order to let every netdev queue resume
85                  */
86         } tx;
87         struct {
88                 unsigned long phys;
89                 unsigned long size;
90                 unsigned char *virt;
91                 unsigned char *end;
92                 struct softing_fct  *fct;
93                 struct softing_info *info;
94                 struct softing_rx  *rx;
95                 struct softing_tx  *tx;
96                 struct softing_irq *irq;
97                 unsigned short *command;
98                 unsigned short *receipt;
99         } dpram;
100         struct {
101                 unsigned short manf;
102                 unsigned short prod;
103                 u32  serial, fw, hw, lic;
104                 u16  chip [2];
105                 u32  freq;
106                 const char *name;
107         } id;
108         const struct softing_desc               *desc;
109         struct {
110                 int (*reset)     (struct softing *, int);
111                 int (*enable_irq)(struct softing *, int);
112         } fn;
113         struct device *dev;
114         /* sysfs */
115         struct attribute_group sysfs;
116         struct softing_attribute *attr;
117         struct attribute **grp;
118 };
119
120 extern int      mk_softing(struct softing *);
121 /* fields that must be set already are :
122  * ncan
123  * id.manf
124  * id.prod
125  * fn.reset
126  * fn.enable_irq
127  */
128 extern void rm_softing(struct softing *);
129 /* usefull functions during operation */
130
131 extern const struct softing_desc *
132         softing_lookup_desc(unsigned int manf, unsigned int prod);
133
134 extern int softing_default_output(struct softing *card
135                         , struct softing_priv *priv);
136 extern u32 softing_time2usec(struct softing *card, u32 raw);
137
138 extern int softing_fct_cmd(struct softing *card
139                         , int cmd, int vector, const char *msg);
140
141 extern int softing_bootloader_command(struct softing *card
142                         , int command, const char *msg);
143
144 /* Load firmware after reset */
145 extern int softing_load_fw(const char *file, struct softing *card,
146                         unsigned char *virt, unsigned int size, int offset);
147
148 /* Load final application firmware after bootloader */
149 extern int softing_load_app_fw(const char *file, struct softing *card);
150
151 extern int softing_reset_chip(struct softing *card);
152
153 /* enable or disable irq
154  * only called with fw.lock locked
155  */
156 extern int softing_card_irq(struct softing *card, int enable);
157
158 /* called when tx queue is flushed */
159 extern void softing_flush_echo_skb(struct softing_priv *priv);
160
161 /* reinitaliase the card, apply -1 for bus[01] for 'no change' */
162 extern int softing_reinit(struct softing *card, int bus0, int bus1);
163
164 /* SOFTING DPRAM mappings */
165 struct softing_rx {
166         u8  fifo[16][32];
167         u8  dummy1;
168         u16 rd;
169         u16 dummy2;
170         u16 wr;
171         u16  dummy3;
172         u16 lost_msg;
173 } __attribute__((packed));
174
175 #define TXMAX   31
176 struct softing_tx {
177         u8  fifo[32][16];
178         u8  dummy1;
179         u16 rd;
180         u16 dummy2;
181         u16 wr;
182         u8  dummy3;
183 } __attribute__((packed));
184
185 struct softing_irq {
186         u8 to_host;
187         u8 to_card;
188 } __attribute__((packed));
189
190 struct softing_fct {
191         s16 param[20]; /* 0 is index */
192         s16 returned;
193         u8  dummy;
194         u16 host_access;
195 } __attribute__((packed));
196
197 struct softing_info {
198         u8  dummy1;
199         u16 bus_state;
200         u16 dummy2;
201         u16 bus_state2;
202         u16 dummy3;
203         u16 error_state;
204         u16 dummy4;
205         u16 error_state2;
206         u16 dummy5;
207         u16 reset;
208         u16 dummy6;
209         u16 clear_rcv_fifo;
210         u16 dummy7;
211         u16 dummyxx;
212         u16 dummy8;
213         u16 time_reset;
214         u8  dummy9;
215         u32 time;
216         u32 time_wrap;
217         u8  wr_start;
218         u8  wr_end;
219         u8  dummy10;
220         u16 dummy12;
221         u16 dummy12x;
222         u16 dummy13;
223         u16 reset_rcv_fifo;
224         u8  dummy14;
225         u8  reset_xmt_fifo;
226         u8  read_fifo_levels;
227         u16 rcv_fifo_level;
228         u16 xmt_fifo_level;
229 } __attribute__((packed));
230
231 /* DPRAM return codes */
232 #define RES_NONE 0
233 #define RES_OK   1
234 #define RES_NOK  2
235 #define RES_UNKNOWN 3
236 /* DPRAM flags */
237 #define CMD_TX          0x01
238 #define CMD_ACK 0x02
239 #define CMD_XTD 0x04
240 #define CMD_RTR 0x08
241 #define CMD_ERR 0x10
242 #define CMD_BUS2        0x80
243
244 /* debug */
245 extern int softing_debug;
246
247 #define mod_alert(fmt,arg...) { \
248         if (softing_debug >= 0) \
249                 printk(KERN_ALERT "[%s] %s:" fmt "\n" \
250                         , THIS_MODULE->name \
251                         , __func__ \
252                         , ##arg); \
253         }
254 #define mod_info(fmt,arg...) { \
255         if (softing_debug >= 1) \
256                 printk(KERN_INFO        "[%s] %s:" fmt "\n"\
257                         , THIS_MODULE->name \
258                         , __func__ \
259                         , ##arg); \
260         }
261 #define mod_trace(fmt,arg...) { \
262         if (softing_debug >= 2) \
263                 printk(KERN_DEBUG "[%s] %s:" fmt "\n" \
264                         , THIS_MODULE->name \
265                         , __func__ \
266                         , ##arg); \
267         }
268