This source file includes following definitions.
- ergo_interrupt
- ergo_irq_bh
- ergo_stopcard
- ergo_set_errlog_state
- ergo_testram
- ergo_writebootimg
- ergo_writebootseq
- ergo_waitpofready
- ergo_releasehardware
- ergo_inithardware
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <linux/signal.h>
18 #include <linux/kernel.h>
19 #include <linux/ioport.h>
20 #include <linux/interrupt.h>
21 #include <linux/vmalloc.h>
22 #include <linux/delay.h>
23 #include <asm/io.h>
24
25 #include "hysdn_defs.h"
26 #include "boardergo.h"
27
28 #define byteout(addr, val) outb(val, addr)
29 #define bytein(addr) inb(addr)
30
31
32
33
34 static irqreturn_t
35 ergo_interrupt(int intno, void *dev_id)
36 {
37 hysdn_card *card = dev_id;
38 tErgDpram *dpr;
39 unsigned long flags;
40 unsigned char volatile b;
41
42 if (!card)
43 return IRQ_NONE;
44 if (!card->irq_enabled)
45 return IRQ_NONE;
46
47 spin_lock_irqsave(&card->hysdn_lock, flags);
48
49 if (!(bytein(card->iobase + PCI9050_INTR_REG) & PCI9050_INTR_REG_STAT1)) {
50 spin_unlock_irqrestore(&card->hysdn_lock, flags);
51 return IRQ_NONE;
52 }
53
54 dpr = card->dpram;
55 b = dpr->ToPcInt;
56 b |= dpr->ToPcIntMetro;
57 b |= dpr->ToHyInt;
58
59
60 if (!card->hw_lock)
61 schedule_work(&card->irq_queue);
62 spin_unlock_irqrestore(&card->hysdn_lock, flags);
63 return IRQ_HANDLED;
64 }
65
66
67
68
69
70
71
72
73 static void
74 ergo_irq_bh(struct work_struct *ugli_api)
75 {
76 hysdn_card *card = container_of(ugli_api, hysdn_card, irq_queue);
77 tErgDpram *dpr;
78 int again;
79 unsigned long flags;
80
81 if (card->state != CARD_STATE_RUN)
82 return;
83
84 dpr = card->dpram;
85
86 spin_lock_irqsave(&card->hysdn_lock, flags);
87 if (card->hw_lock) {
88 spin_unlock_irqrestore(&card->hysdn_lock, flags);
89 return;
90 }
91 card->hw_lock = 1;
92
93 do {
94 again = 0;
95
96 if (!dpr->ToHyFlag) {
97
98
99 if (hysdn_sched_tx(card, dpr->ToHyBuf, &dpr->ToHySize, &dpr->ToHyChannel,
100 ERG_TO_HY_BUF_SIZE)) {
101 dpr->ToHyFlag = 1;
102 again = 1;
103 }
104 }
105 if (dpr->ToPcFlag) {
106
107
108 if (hysdn_sched_rx(card, dpr->ToPcBuf, dpr->ToPcSize, dpr->ToPcChannel)) {
109 dpr->ToPcFlag = 0;
110 again = 1;
111 }
112 }
113 if (again) {
114 dpr->ToHyInt = 1;
115 dpr->ToPcInt = 1;
116 } else
117 card->hw_lock = 0;
118 } while (again);
119
120 spin_unlock_irqrestore(&card->hysdn_lock, flags);
121 }
122
123
124
125
126
127 static void
128 ergo_stopcard(hysdn_card *card)
129 {
130 unsigned long flags;
131 unsigned char val;
132
133 hysdn_net_release(card);
134 #ifdef CONFIG_HYSDN_CAPI
135 hycapi_capi_stop(card);
136 #endif
137 spin_lock_irqsave(&card->hysdn_lock, flags);
138 val = bytein(card->iobase + PCI9050_INTR_REG);
139 val &= ~(PCI9050_INTR_REG_ENPCI | PCI9050_INTR_REG_EN1);
140 byteout(card->iobase + PCI9050_INTR_REG, val);
141 card->irq_enabled = 0;
142 byteout(card->iobase + PCI9050_USER_IO, PCI9050_E1_RESET);
143 card->state = CARD_STATE_UNUSED;
144 card->err_log_state = ERRLOG_STATE_OFF;
145
146 spin_unlock_irqrestore(&card->hysdn_lock, flags);
147 }
148
149
150
151
152 static void
153 ergo_set_errlog_state(hysdn_card *card, int on)
154 {
155 unsigned long flags;
156
157 if (card->state != CARD_STATE_RUN) {
158 card->err_log_state = ERRLOG_STATE_OFF;
159 return;
160 }
161 spin_lock_irqsave(&card->hysdn_lock, flags);
162
163 if (((card->err_log_state == ERRLOG_STATE_OFF) && !on) ||
164 ((card->err_log_state == ERRLOG_STATE_ON) && on)) {
165 spin_unlock_irqrestore(&card->hysdn_lock, flags);
166 return;
167 }
168 if (on)
169 card->err_log_state = ERRLOG_STATE_START;
170 else
171 card->err_log_state = ERRLOG_STATE_STOP;
172
173 spin_unlock_irqrestore(&card->hysdn_lock, flags);
174 schedule_work(&card->irq_queue);
175 }
176
177
178
179
180 static const char TestText[36] = "This Message is filler, why read it";
181
182 static int
183 ergo_testram(hysdn_card *card)
184 {
185 tErgDpram *dpr = card->dpram;
186
187 memset(dpr->TrapTable, 0, sizeof(dpr->TrapTable));
188 dpr->ToHyInt = 1;
189
190 memcpy(&dpr->ToHyBuf[ERG_TO_HY_BUF_SIZE - sizeof(TestText)], TestText,
191 sizeof(TestText));
192 if (memcmp(&dpr->ToHyBuf[ERG_TO_HY_BUF_SIZE - sizeof(TestText)], TestText,
193 sizeof(TestText)))
194 return (-1);
195
196 memcpy(&dpr->ToPcBuf[ERG_TO_PC_BUF_SIZE - sizeof(TestText)], TestText,
197 sizeof(TestText));
198 if (memcmp(&dpr->ToPcBuf[ERG_TO_PC_BUF_SIZE - sizeof(TestText)], TestText,
199 sizeof(TestText)))
200 return (-1);
201
202 return (0);
203 }
204
205
206
207
208
209
210
211
212
213 static int
214 ergo_writebootimg(struct HYSDN_CARD *card, unsigned char *buf,
215 unsigned long offs)
216 {
217 unsigned char *dst;
218 tErgDpram *dpram;
219 int cnt = (BOOT_IMG_SIZE >> 2);
220
221 if (card->debug_flags & LOG_POF_CARD)
222 hysdn_addlog(card, "ERGO: write bootldr offs=0x%lx ", offs);
223
224 dst = card->dpram;
225 dst += (offs + ERG_DPRAM_FILL_SIZE);
226 while (cnt--) {
227 *dst++ = *(buf + 1);
228 *dst++ = *buf;
229 dst += 2;
230 buf += 2;
231 }
232
233
234
235 if (offs) {
236 memset(card->dpram, 0, ERG_DPRAM_FILL_SIZE);
237 dpram = card->dpram;
238 dpram->ToHyNoDpramErrLog = 0xFF;
239 while (!dpram->ToHyNoDpramErrLog);
240
241 byteout(card->iobase + PCI9050_USER_IO, PCI9050_E1_RUN);
242
243
244 msleep_interruptible(20);
245
246 if (((tDpramBootSpooler *) card->dpram)->Len != DPRAM_SPOOLER_DATA_SIZE) {
247 if (card->debug_flags & LOG_POF_CARD)
248 hysdn_addlog(card, "ERGO: write bootldr no answer");
249 return (-ERR_BOOTIMG_FAIL);
250 }
251 }
252 return (0);
253 }
254
255
256
257
258
259
260 static int
261 ergo_writebootseq(struct HYSDN_CARD *card, unsigned char *buf, int len)
262 {
263 tDpramBootSpooler *sp = (tDpramBootSpooler *) card->dpram;
264 unsigned char *dst;
265 unsigned char buflen;
266 int nr_write;
267 unsigned char tmp_rdptr;
268 unsigned char wr_mirror;
269 int i;
270
271 if (card->debug_flags & LOG_POF_CARD)
272 hysdn_addlog(card, "ERGO: write boot seq len=%d ", len);
273
274 dst = sp->Data;
275 buflen = sp->Len;
276 wr_mirror = sp->WrPtr;
277
278
279 i = 0x1000;
280 while (len) {
281
282
283 do {
284 tmp_rdptr = sp->RdPtr;
285 i--;
286 } while (i && (tmp_rdptr != sp->RdPtr));
287
288 if (!i) {
289 if (card->debug_flags & LOG_POF_CARD)
290 hysdn_addlog(card, "ERGO: write boot seq timeout");
291 return (-ERR_BOOTSEQ_FAIL);
292 }
293 if ((nr_write = tmp_rdptr - wr_mirror - 1) < 0)
294 nr_write += buflen;
295
296 if (!nr_write)
297 continue;
298
299 if (nr_write > len)
300 nr_write = len;
301 i = 0x1000;
302
303
304 len -= nr_write;
305 while (nr_write--) {
306 *(dst + wr_mirror) = *buf++;
307 if (++wr_mirror >= buflen)
308 wr_mirror = 0;
309 sp->WrPtr = wr_mirror;
310 }
311
312 }
313 return (0);
314 }
315
316
317
318
319
320
321 static int
322 ergo_waitpofready(struct HYSDN_CARD *card)
323 {
324 tErgDpram *dpr = card->dpram;
325 int timecnt = 10000 / 50;
326 unsigned long flags;
327 int msg_size;
328 int i;
329
330 if (card->debug_flags & LOG_POF_CARD)
331 hysdn_addlog(card, "ERGO: waiting for pof ready");
332 while (timecnt--) {
333
334
335 if (dpr->ToPcFlag) {
336
337
338 if ((dpr->ToPcChannel != CHAN_SYSTEM) ||
339 (dpr->ToPcSize < MIN_RDY_MSG_SIZE) ||
340 (dpr->ToPcSize > MAX_RDY_MSG_SIZE) ||
341 ((*(unsigned long *) dpr->ToPcBuf) != RDY_MAGIC))
342 break;
343
344
345 msg_size = dpr->ToPcSize - RDY_MAGIC_SIZE;
346 if (msg_size > 0)
347 if (EvalSysrTokData(card, dpr->ToPcBuf + RDY_MAGIC_SIZE, msg_size))
348 break;
349
350 if (card->debug_flags & LOG_POF_RECORD)
351 hysdn_addlog(card, "ERGO: pof boot success");
352 spin_lock_irqsave(&card->hysdn_lock, flags);
353
354 card->state = CARD_STATE_RUN;
355
356 byteout(card->iobase + PCI9050_INTR_REG,
357 bytein(card->iobase + PCI9050_INTR_REG) |
358 (PCI9050_INTR_REG_ENPCI | PCI9050_INTR_REG_EN1));
359 card->irq_enabled = 1;
360
361 dpr->ToPcFlag = 0;
362 dpr->ToHyInt = 1;
363 dpr->ToPcInt = 1;
364
365 spin_unlock_irqrestore(&card->hysdn_lock, flags);
366 if ((hynet_enable & (1 << card->myid))
367 && (i = hysdn_net_create(card)))
368 {
369 ergo_stopcard(card);
370 card->state = CARD_STATE_BOOTERR;
371 return (i);
372 }
373 #ifdef CONFIG_HYSDN_CAPI
374 if ((i = hycapi_capi_create(card))) {
375 printk(KERN_WARNING "HYSDN: failed to create capi-interface.\n");
376 }
377 #endif
378 return (0);
379 }
380 msleep_interruptible(50);
381 }
382
383 if (card->debug_flags & LOG_POF_CARD)
384 hysdn_addlog(card, "ERGO: pof boot ready timeout");
385 return (-ERR_POF_TIMEOUT);
386 }
387
388
389
390
391
392
393
394
395 static void
396 ergo_releasehardware(hysdn_card *card)
397 {
398 ergo_stopcard(card);
399 free_irq(card->irq, card);
400 release_region(card->iobase + PCI9050_INTR_REG, 1);
401 release_region(card->iobase + PCI9050_USER_IO, 1);
402 iounmap(card->dpram);
403 card->dpram = NULL;
404 }
405
406
407
408
409
410
411
412 int
413 ergo_inithardware(hysdn_card *card)
414 {
415 if (!request_region(card->iobase + PCI9050_INTR_REG, 1, "HYSDN"))
416 return (-1);
417 if (!request_region(card->iobase + PCI9050_USER_IO, 1, "HYSDN")) {
418 release_region(card->iobase + PCI9050_INTR_REG, 1);
419 return (-1);
420 }
421 card->memend = card->membase + ERG_DPRAM_PAGE_SIZE - 1;
422 if (!(card->dpram = ioremap(card->membase, ERG_DPRAM_PAGE_SIZE))) {
423 release_region(card->iobase + PCI9050_INTR_REG, 1);
424 release_region(card->iobase + PCI9050_USER_IO, 1);
425 return (-1);
426 }
427
428 ergo_stopcard(card);
429 if (request_irq(card->irq, ergo_interrupt, IRQF_SHARED, "HYSDN", card)) {
430 ergo_releasehardware(card);
431 return (-1);
432 }
433
434 card->stopcard = ergo_stopcard;
435 card->releasehardware = ergo_releasehardware;
436 card->testram = ergo_testram;
437 card->writebootimg = ergo_writebootimg;
438 card->writebootseq = ergo_writebootseq;
439 card->waitpofready = ergo_waitpofready;
440 card->set_errlog_state = ergo_set_errlog_state;
441 INIT_WORK(&card->irq_queue, ergo_irq_bh);
442 spin_lock_init(&card->hysdn_lock);
443
444 return (0);
445 }