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