OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [ieee1394/] [pcilynx.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 * ti_pcilynx.c - Texas Instruments PCILynx driver
3
 * Copyright (C) 1999,2000 Andreas Bombe <andreas.bombe@munich.netsurf.de>,
4
 *                         Stephan Linz <linz@mazet.de>
5
 *                         Manfred Weihs <weihs@ict.tuwien.ac.at>
6
 *
7
 * This program is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 2 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software Foundation,
19
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
 */
21
 
22
/*
23
 * Contributions:
24
 *
25
 * Manfred Weihs <weihs@ict.tuwien.ac.at>
26
 *        reading bus info block (containing GUID) from serial
27
 *            eeprom via i2c and storing it in config ROM
28
 *        Reworked code for initiating bus resets
29
 *            (long, short, with or without hold-off)
30
 *        Enhancements in async and iso send code
31
 */
32
 
33
#include <linux/config.h>
34
#include <linux/kernel.h>
35
#include <linux/slab.h>
36
#include <linux/interrupt.h>
37
#include <linux/wait.h>
38
#include <linux/errno.h>
39
#include <linux/module.h>
40
#include <linux/init.h>
41
#include <linux/pci.h>
42
#include <linux/fs.h>
43
#include <linux/poll.h>
44
#include <linux/irq.h>
45
#include <asm/byteorder.h>
46
#include <asm/atomic.h>
47
#include <asm/io.h>
48
#include <asm/uaccess.h>
49
 
50
#include "ieee1394.h"
51
#include "ieee1394_types.h"
52
#include "hosts.h"
53
#include "ieee1394_core.h"
54
#include "highlevel.h"
55
#include "pcilynx.h"
56
 
57
#include <linux/i2c.h>
58
#include <linux/i2c-algo-bit.h>
59
 
60
/* print general (card independent) information */
61
#define PRINT_G(level, fmt, args...) printk(level "pcilynx: " fmt "\n" , ## args)
62
/* print card specific information */
63
#define PRINT(level, card, fmt, args...) printk(level "pcilynx%d: " fmt "\n" , card , ## args)
64
 
65
#ifdef CONFIG_IEEE1394_VERBOSEDEBUG
66
#define PRINT_GD(level, fmt, args...) printk(level "pcilynx: " fmt "\n" , ## args)
67
#define PRINTD(level, card, fmt, args...) printk(level "pcilynx%d: " fmt "\n" , card , ## args)
68
#else
69
#define PRINT_GD(level, fmt, args...) do {} while (0)
70
#define PRINTD(level, card, fmt, args...) do {} while (0)
71
#endif
72
 
73
 
74
/* Module Parameters */
75
MODULE_PARM(skip_eeprom,"i");
76
MODULE_PARM_DESC(skip_eeprom, "Do not try to read bus info block from serial eeprom, but user generic one (default = 0).");
77
static int skip_eeprom = 0;
78
 
79
 
80
static struct hpsb_host_driver lynx_driver;
81
static unsigned int card_id;
82
 
83
 
84
 
85
/*
86
 * I2C stuff
87
 */
88
 
89
/* the i2c stuff was inspired by i2c-philips-par.c */
90
 
91
static void bit_setscl(void *data, int state)
92
{
93
        if (state) {
94
                  ((struct ti_lynx *) data)->i2c_driven_state |= 0x00000040;
95
        } else {
96
                  ((struct ti_lynx *) data)->i2c_driven_state &= ~0x00000040;
97
        }
98
        reg_write((struct ti_lynx *) data, SERIAL_EEPROM_CONTROL, ((struct ti_lynx *) data)->i2c_driven_state);
99
}
100
 
101
static void bit_setsda(void *data, int state)
102
{
103
        if (state) {
104
                  ((struct ti_lynx *) data)->i2c_driven_state |= 0x00000010;
105
        } else {
106
                  ((struct ti_lynx *) data)->i2c_driven_state &= ~0x00000010;
107
        }
108
        reg_write((struct ti_lynx *) data, SERIAL_EEPROM_CONTROL, ((struct ti_lynx *) data)->i2c_driven_state);
109
}
110
 
111
static int bit_getscl(void *data)
112
{
113
        return reg_read((struct ti_lynx *) data, SERIAL_EEPROM_CONTROL) & 0x00000040;
114
}
115
 
116
static int bit_getsda(void *data)
117
{
118
        return reg_read((struct ti_lynx *) data, SERIAL_EEPROM_CONTROL) & 0x00000010;
119
}
120
 
121
static int bit_reg(struct i2c_client *client)
122
{
123
        return 0;
124
}
125
 
126
static int bit_unreg(struct i2c_client *client)
127
{
128
        return 0;
129
}
130
 
131
static struct i2c_algo_bit_data bit_data = {
132
        .setsda                 = bit_setsda,
133
        .setscl                 = bit_setscl,
134
        .getsda                 = bit_getsda,
135
        .getscl                 = bit_getscl,
136
        .udelay                 = 5,
137
        .mdelay                 = 5,
138
        .timeout                = 100,
139
};
140
 
141
static struct i2c_adapter bit_ops = {
142
        .id                     = 0xAA, //FIXME: probably we should get an id in i2c-id.h
143
        .client_register        = bit_reg,
144
        .client_unregister      = bit_unreg,
145
        .name                   = "PCILynx I2C",
146
};
147
 
148
 
149
 
150
/*
151
 * PCL handling functions.
152
 */
153
 
154
static pcl_t alloc_pcl(struct ti_lynx *lynx)
155
{
156
        u8 m;
157
        int i, j;
158
 
159
        spin_lock(&lynx->lock);
160
        /* FIXME - use ffz() to make this readable */
161
        for (i = 0; i < (LOCALRAM_SIZE / 1024); i++) {
162
                m = lynx->pcl_bmap[i];
163
                for (j = 0; j < 8; j++) {
164
                        if (m & 1<<j) {
165
                                continue;
166
                        }
167
                        m |= 1<<j;
168
                        lynx->pcl_bmap[i] = m;
169
                        spin_unlock(&lynx->lock);
170
                        return 8 * i + j;
171
                }
172
        }
173
        spin_unlock(&lynx->lock);
174
 
175
        return -1;
176
}
177
 
178
 
179
#if 0
180
static void free_pcl(struct ti_lynx *lynx, pcl_t pclid)
181
{
182
        int off, bit;
183
 
184
        off = pclid / 8;
185
        bit = pclid % 8;
186
 
187
        if (pclid < 0) {
188
                return;
189
        }
190
 
191
        spin_lock(&lynx->lock);
192
        if (lynx->pcl_bmap[off] & 1<<bit) {
193
                lynx->pcl_bmap[off] &= ~(1<<bit);
194
        } else {
195
                PRINT(KERN_ERR, lynx->id,
196
                      "attempted to free unallocated PCL %d", pclid);
197
        }
198
        spin_unlock(&lynx->lock);
199
}
200
 
201
/* functions useful for debugging */
202
static void pretty_print_pcl(const struct ti_pcl *pcl)
203
{
204
        int i;
205
 
206
        printk("PCL next %08x, userdata %08x, status %08x, remtrans %08x, nextbuf %08x\n",
207
               pcl->next, pcl->user_data, pcl->pcl_status,
208
               pcl->remaining_transfer_count, pcl->next_data_buffer);
209
 
210
        printk("PCL");
211
        for (i=0; i<13; i++) {
212
                printk(" c%x:%08x d%x:%08x",
213
                       i, pcl->buffer[i].control, i, pcl->buffer[i].pointer);
214
                if (!(i & 0x3) && (i != 12)) printk("\nPCL");
215
        }
216
        printk("\n");
217
}
218
 
219
static void print_pcl(const struct ti_lynx *lynx, pcl_t pclid)
220
{
221
        struct ti_pcl pcl;
222
 
223
        get_pcl(lynx, pclid, &pcl);
224
        pretty_print_pcl(&pcl);
225
}
226
#endif
227
 
228
 
229
 
230
/***********************************
231
 * IEEE-1394 functionality section *
232
 ***********************************/
233
 
234
 
235
static int get_phy_reg(struct ti_lynx *lynx, int addr)
236
{
237
        int retval;
238
        int i = 0;
239
 
240
        unsigned long flags;
241
 
242
        if (addr > 15) {
243
                PRINT(KERN_ERR, lynx->id,
244
                      "%s: PHY register address %d out of range",
245
                      __FUNCTION__, addr);
246
                return -1;
247
        }
248
 
249
        spin_lock_irqsave(&lynx->phy_reg_lock, flags);
250
 
251
        reg_write(lynx, LINK_PHY, LINK_PHY_READ | LINK_PHY_ADDR(addr));
252
        do {
253
                retval = reg_read(lynx, LINK_PHY);
254
 
255
                if (i > 10000) {
256
                        PRINT(KERN_ERR, lynx->id, "%s: runaway loop, aborting",
257
                              __FUNCTION__);
258
                        retval = -1;
259
                        break;
260
                }
261
                i++;
262
        } while ((retval & 0xf00) != LINK_PHY_RADDR(addr));
263
 
264
        reg_write(lynx, LINK_INT_STATUS, LINK_INT_PHY_REG_RCVD);
265
        spin_unlock_irqrestore(&lynx->phy_reg_lock, flags);
266
 
267
        if (retval != -1) {
268
                return retval & 0xff;
269
        } else {
270
                return -1;
271
        }
272
}
273
 
274
static int set_phy_reg(struct ti_lynx *lynx, int addr, int val)
275
{
276
        unsigned long flags;
277
 
278
        if (addr > 15) {
279
                PRINT(KERN_ERR, lynx->id,
280
                      "%s: PHY register address %d out of range", __FUNCTION__, addr);
281
                return -1;
282
        }
283
 
284
        if (val > 0xff) {
285
                PRINT(KERN_ERR, lynx->id,
286
                      "%s: PHY register value %d out of range", __FUNCTION__, val);
287
                return -1;
288
        }
289
 
290
        spin_lock_irqsave(&lynx->phy_reg_lock, flags);
291
 
292
        reg_write(lynx, LINK_PHY, LINK_PHY_WRITE | LINK_PHY_ADDR(addr)
293
                  | LINK_PHY_WDATA(val));
294
 
295
        spin_unlock_irqrestore(&lynx->phy_reg_lock, flags);
296
 
297
        return 0;
298
}
299
 
300
static int sel_phy_reg_page(struct ti_lynx *lynx, int page)
301
{
302
        int reg;
303
 
304
        if (page > 7) {
305
                PRINT(KERN_ERR, lynx->id,
306
                      "%s: PHY page %d out of range", __FUNCTION__, page);
307
                return -1;
308
        }
309
 
310
        reg = get_phy_reg(lynx, 7);
311
        if (reg != -1) {
312
                reg &= 0x1f;
313
                reg |= (page << 5);
314
                set_phy_reg(lynx, 7, reg);
315
                return 0;
316
        } else {
317
                return -1;
318
        }
319
}
320
 
321
#if 0 /* not needed at this time */
322
static int sel_phy_reg_port(struct ti_lynx *lynx, int port)
323
{
324
        int reg;
325
 
326
        if (port > 15) {
327
                PRINT(KERN_ERR, lynx->id,
328
                      "%s: PHY port %d out of range", __FUNCTION__, port);
329
                return -1;
330
        }
331
 
332
        reg = get_phy_reg(lynx, 7);
333
        if (reg != -1) {
334
                reg &= 0xf0;
335
                reg |= port;
336
                set_phy_reg(lynx, 7, reg);
337
                return 0;
338
        } else {
339
                return -1;
340
        }
341
}
342
#endif
343
 
344
static u32 get_phy_vendorid(struct ti_lynx *lynx)
345
{
346
        u32 pvid = 0;
347
        sel_phy_reg_page(lynx, 1);
348
        pvid |= (get_phy_reg(lynx, 10) << 16);
349
        pvid |= (get_phy_reg(lynx, 11) << 8);
350
        pvid |= get_phy_reg(lynx, 12);
351
        PRINT(KERN_INFO, lynx->id, "PHY vendor id 0x%06x", pvid);
352
        return pvid;
353
}
354
 
355
static u32 get_phy_productid(struct ti_lynx *lynx)
356
{
357
        u32 id = 0;
358
        sel_phy_reg_page(lynx, 1);
359
        id |= (get_phy_reg(lynx, 13) << 16);
360
        id |= (get_phy_reg(lynx, 14) << 8);
361
        id |= get_phy_reg(lynx, 15);
362
        PRINT(KERN_INFO, lynx->id, "PHY product id 0x%06x", id);
363
        return id;
364
}
365
 
366
static quadlet_t generate_own_selfid(struct ti_lynx *lynx,
367
                                     struct hpsb_host *host)
368
{
369
        quadlet_t lsid;
370
        char phyreg[7];
371
        int i;
372
 
373
        phyreg[0] = lynx->phy_reg0;
374
        for (i = 1; i < 7; i++) {
375
                phyreg[i] = get_phy_reg(lynx, i);
376
        }
377
 
378
        /* FIXME? We assume a TSB21LV03A phy here.  This code doesn't support
379
           more than 3 ports on the PHY anyway. */
380
 
381
        lsid = 0x80400000 | ((phyreg[0] & 0xfc) << 22);
382
        lsid |= (phyreg[1] & 0x3f) << 16; /* gap count */
383
        lsid |= (phyreg[2] & 0xc0) << 8; /* max speed */
384
        lsid |= (phyreg[6] & 0x01) << 11; /* contender (phy dependent) */
385
        /* lsid |= 1 << 11; *//* set contender (hack) */
386
        lsid |= (phyreg[6] & 0x10) >> 3; /* initiated reset */
387
 
388
        for (i = 0; i < (phyreg[2] & 0xf); i++) { /* ports */
389
                if (phyreg[3 + i] & 0x4) {
390
                        lsid |= (((phyreg[3 + i] & 0x8) | 0x10) >> 3)
391
                                << (6 - i*2);
392
                } else {
393
                        lsid |= 1 << (6 - i*2);
394
                }
395
        }
396
 
397
        cpu_to_be32s(&lsid);
398
        PRINT(KERN_DEBUG, lynx->id, "generated own selfid 0x%x", lsid);
399
        return lsid;
400
}
401
 
402
static void handle_selfid(struct ti_lynx *lynx, struct hpsb_host *host)
403
{
404
        quadlet_t *q = lynx->rcv_page;
405
        int phyid, isroot, size;
406
        quadlet_t lsid = 0;
407
        int i;
408
 
409
        if (lynx->phy_reg0 == -1 || lynx->selfid_size == -1) return;
410
 
411
        size = lynx->selfid_size;
412
        phyid = lynx->phy_reg0;
413
 
414
        i = (size > 16 ? 16 : size) / 4 - 1;
415
        while (i >= 0) {
416
                cpu_to_be32s(&q[i]);
417
                i--;
418
        }
419
 
420
        if (!lynx->phyic.reg_1394a) {
421
                lsid = generate_own_selfid(lynx, host);
422
        }
423
 
424
        isroot = (phyid & 2) != 0;
425
        phyid >>= 2;
426
        PRINT(KERN_INFO, lynx->id, "SelfID process finished (phyid %d, %s)",
427
              phyid, (isroot ? "root" : "not root"));
428
        reg_write(lynx, LINK_ID, (0xffc0 | phyid) << 16);
429
 
430
        if (!lynx->phyic.reg_1394a && !size) {
431
                hpsb_selfid_received(host, lsid);
432
        }
433
 
434
        while (size > 0) {
435
                struct selfid *sid = (struct selfid *)q;
436
 
437
                if (!lynx->phyic.reg_1394a && !sid->extended
438
                    && (sid->phy_id == (phyid + 1))) {
439
                        hpsb_selfid_received(host, lsid);
440
                }
441
 
442
                if (q[0] == ~q[1]) {
443
                        PRINT(KERN_DEBUG, lynx->id, "SelfID packet 0x%x rcvd",
444
                              q[0]);
445
                        hpsb_selfid_received(host, q[0]);
446
                } else {
447
                        PRINT(KERN_INFO, lynx->id,
448
                              "inconsistent selfid 0x%x/0x%x", q[0], q[1]);
449
                }
450
                q += 2;
451
                size -= 8;
452
        }
453
 
454
        if (!lynx->phyic.reg_1394a && isroot && phyid != 0) {
455
                hpsb_selfid_received(host, lsid);
456
        }
457
 
458
        hpsb_selfid_complete(host, phyid, isroot);
459
 
460
        if (host->in_bus_reset) return; /* in bus reset again */
461
 
462
        if (isroot) reg_set_bits(lynx, LINK_CONTROL, LINK_CONTROL_CYCMASTER); //FIXME: I do not think, we need this here
463
        reg_set_bits(lynx, LINK_CONTROL,
464
                     LINK_CONTROL_RCV_CMP_VALID | LINK_CONTROL_TX_ASYNC_EN
465
                     | LINK_CONTROL_RX_ASYNC_EN | LINK_CONTROL_CYCTIMEREN);
466
}
467
 
468
 
469
 
470
/* This must be called with the respective queue_lock held. */
471
static void send_next(struct ti_lynx *lynx, int what)
472
{
473
        struct ti_pcl pcl;
474
        struct lynx_send_data *d;
475
        struct hpsb_packet *packet;
476
 
477
        d = (what == hpsb_iso ? &lynx->iso_send : &lynx->async);
478
        if (!list_empty(&d->pcl_queue)) {
479
                PRINT(KERN_ERR, lynx->id, "trying to queue a new packet in nonempty fifo");
480
                BUG();
481
        }
482
 
483
        packet = driver_packet(d->queue.next);
484
        list_del(&packet->driver_list);
485
        list_add_tail(&packet->driver_list, &d->pcl_queue);
486
 
487
        d->header_dma = pci_map_single(lynx->dev, packet->header,
488
                                       packet->header_size, PCI_DMA_TODEVICE);
489
        if (packet->data_size) {
490
                d->data_dma = pci_map_single(lynx->dev, packet->data,
491
                                             packet->data_size,
492
                                             PCI_DMA_TODEVICE);
493
        } else {
494
                d->data_dma = 0;
495
        }
496
 
497
        pcl.next = PCL_NEXT_INVALID;
498
        pcl.async_error_next = PCL_NEXT_INVALID;
499
        pcl.pcl_status = 0;
500
#ifdef __BIG_ENDIAN
501
        pcl.buffer[0].control = packet->speed_code << 14 | packet->header_size;
502
#else
503
        pcl.buffer[0].control = packet->speed_code << 14 | packet->header_size
504
                | PCL_BIGENDIAN;
505
#endif
506
        pcl.buffer[0].pointer = d->header_dma;
507
        pcl.buffer[1].control = PCL_LAST_BUFF | packet->data_size;
508
        pcl.buffer[1].pointer = d->data_dma;
509
 
510
        switch (packet->type) {
511
        case hpsb_async:
512
                pcl.buffer[0].control |= PCL_CMD_XMT;
513
                break;
514
        case hpsb_iso:
515
                pcl.buffer[0].control |= PCL_CMD_XMT | PCL_ISOMODE;
516
                break;
517
        case hpsb_raw:
518
                pcl.buffer[0].control |= PCL_CMD_UNFXMT;
519
                break;
520
        }
521
 
522
        if (!packet->data_be) {
523
                pcl.buffer[1].control |= PCL_BIGENDIAN;
524
        }
525
 
526
        put_pcl(lynx, d->pcl, &pcl);
527
        run_pcl(lynx, d->pcl_start, d->channel);
528
}
529
 
530
 
531
/* called from subsystem core */
532
static int lynx_transmit(struct hpsb_host *host, struct hpsb_packet *packet)
533
{
534
        struct ti_lynx *lynx = host->hostdata;
535
        struct lynx_send_data *d;
536
        unsigned long flags;
537
 
538
        if (packet->data_size >= 4096) {
539
                PRINT(KERN_ERR, lynx->id, "transmit packet data too big (%Zd)",
540
                      packet->data_size);
541
                return 0;
542
        }
543
 
544
        switch (packet->type) {
545
        case hpsb_async:
546
        case hpsb_raw:
547
                d = &lynx->async;
548
                break;
549
        case hpsb_iso:
550
                d = &lynx->iso_send;
551
                break;
552
        default:
553
                PRINT(KERN_ERR, lynx->id, "invalid packet type %d",
554
                      packet->type);
555
                return 0;
556
        }
557
 
558
        if (packet->tcode == TCODE_WRITEQ
559
            || packet->tcode == TCODE_READQ_RESPONSE) {
560
                cpu_to_be32s(&packet->header[3]);
561
        }
562
 
563
        spin_lock_irqsave(&d->queue_lock, flags);
564
 
565
        list_add_tail(&packet->driver_list, &d->queue);
566
        if (list_empty(&d->pcl_queue))
567
                send_next(lynx, packet->type);
568
 
569
        spin_unlock_irqrestore(&d->queue_lock, flags);
570
 
571
        return 1;
572
}
573
 
574
 
575
/* called from subsystem core */
576
static int lynx_devctl(struct hpsb_host *host, enum devctl_cmd cmd, int arg)
577
{
578
        struct ti_lynx *lynx = host->hostdata;
579
        int retval = 0;
580
        struct hpsb_packet *packet;
581
        LIST_HEAD(packet_list);
582
        unsigned long flags;
583
        int phy_reg;
584
 
585
        switch (cmd) {
586
        case RESET_BUS:
587
                if (reg_read(lynx, LINK_INT_STATUS) & LINK_INT_PHY_BUSRESET) {
588
                        retval = 0;
589
                        break;
590
                }
591
 
592
                switch (arg) {
593
                case SHORT_RESET:
594
                        if (lynx->phyic.reg_1394a) {
595
                                phy_reg = get_phy_reg(lynx, 5);
596
                                if (phy_reg == -1) {
597
                                        PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
598
                                        retval = -1;
599
                                        break;
600
                                }
601
                                phy_reg |= 0x40;
602
 
603
                                PRINT(KERN_INFO, lynx->id, "resetting bus (short bus reset) on request");
604
 
605
                                lynx->selfid_size = -1;
606
                                lynx->phy_reg0 = -1;
607
                                set_phy_reg(lynx, 5, phy_reg); /* set ISBR */
608
                                break;
609
                        } else {
610
                                PRINT(KERN_INFO, lynx->id, "cannot do short bus reset, because of old phy");
611
                                /* fall through to long bus reset */
612
                        }
613
                case LONG_RESET:
614
                        phy_reg = get_phy_reg(lynx, 1);
615
                        if (phy_reg == -1) {
616
                                PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
617
                                retval = -1;
618
                                break;
619
                        }
620
                        phy_reg |= 0x40;
621
 
622
                        PRINT(KERN_INFO, lynx->id, "resetting bus (long bus reset) on request");
623
 
624
                        lynx->selfid_size = -1;
625
                        lynx->phy_reg0 = -1;
626
                        set_phy_reg(lynx, 1, phy_reg); /* clear RHB, set IBR */
627
                        break;
628
                case SHORT_RESET_NO_FORCE_ROOT:
629
                        if (lynx->phyic.reg_1394a) {
630
                                phy_reg = get_phy_reg(lynx, 1);
631
                                if (phy_reg == -1) {
632
                                        PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
633
                                        retval = -1;
634
                                        break;
635
                                }
636
                                if (phy_reg & 0x80) {
637
                                        phy_reg &= ~0x80;
638
                                        set_phy_reg(lynx, 1, phy_reg); /* clear RHB */
639
                                }
640
 
641
                                phy_reg = get_phy_reg(lynx, 5);
642
                                if (phy_reg == -1) {
643
                                        PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
644
                                        retval = -1;
645
                                        break;
646
                                }
647
                                phy_reg |= 0x40;
648
 
649
                                PRINT(KERN_INFO, lynx->id, "resetting bus (short bus reset, no force_root) on request");
650
 
651
                                lynx->selfid_size = -1;
652
                                lynx->phy_reg0 = -1;
653
                                set_phy_reg(lynx, 5, phy_reg); /* set ISBR */
654
                                break;
655
                        } else {
656
                                PRINT(KERN_INFO, lynx->id, "cannot do short bus reset, because of old phy");
657
                                /* fall through to long bus reset */
658
                        }
659
                case LONG_RESET_NO_FORCE_ROOT:
660
                        phy_reg = get_phy_reg(lynx, 1);
661
                        if (phy_reg == -1) {
662
                                PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
663
                                retval = -1;
664
                                break;
665
                        }
666
                        phy_reg &= ~0x80;
667
                        phy_reg |= 0x40;
668
 
669
                        PRINT(KERN_INFO, lynx->id, "resetting bus (long bus reset, no force_root) on request");
670
 
671
                        lynx->selfid_size = -1;
672
                        lynx->phy_reg0 = -1;
673
                        set_phy_reg(lynx, 1, phy_reg); /* clear RHB, set IBR */
674
                        break;
675
                case SHORT_RESET_FORCE_ROOT:
676
                        if (lynx->phyic.reg_1394a) {
677
                                phy_reg = get_phy_reg(lynx, 1);
678
                                if (phy_reg == -1) {
679
                                        PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
680
                                        retval = -1;
681
                                        break;
682
                                }
683
                                if (!(phy_reg & 0x80)) {
684
                                        phy_reg |= 0x80;
685
                                        set_phy_reg(lynx, 1, phy_reg); /* set RHB */
686
                                }
687
 
688
                                phy_reg = get_phy_reg(lynx, 5);
689
                                if (phy_reg == -1) {
690
                                        PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
691
                                        retval = -1;
692
                                        break;
693
                                }
694
                                phy_reg |= 0x40;
695
 
696
                                PRINT(KERN_INFO, lynx->id, "resetting bus (short bus reset, force_root set) on request");
697
 
698
                                lynx->selfid_size = -1;
699
                                lynx->phy_reg0 = -1;
700
                                set_phy_reg(lynx, 5, phy_reg); /* set ISBR */
701
                                break;
702
                        } else {
703
                                PRINT(KERN_INFO, lynx->id, "cannot do short bus reset, because of old phy");
704
                                /* fall through to long bus reset */
705
                        }
706
                case LONG_RESET_FORCE_ROOT:
707
                        phy_reg = get_phy_reg(lynx, 1);
708
                        if (phy_reg == -1) {
709
                                PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
710
                                retval = -1;
711
                                break;
712
                        }
713
                        phy_reg |= 0xc0;
714
 
715
                        PRINT(KERN_INFO, lynx->id, "resetting bus (long bus reset, force_root set) on request");
716
 
717
                        lynx->selfid_size = -1;
718
                        lynx->phy_reg0 = -1;
719
                        set_phy_reg(lynx, 1, phy_reg); /* set IBR and RHB */
720
                        break;
721
                default:
722
                        PRINT(KERN_ERR, lynx->id, "unknown argument for reset_bus command %d", arg);
723
                        retval = -1;
724
                }
725
 
726
                break;
727
 
728
        case GET_CYCLE_COUNTER:
729
                retval = reg_read(lynx, CYCLE_TIMER);
730
                break;
731
 
732
        case SET_CYCLE_COUNTER:
733
                reg_write(lynx, CYCLE_TIMER, arg);
734
                break;
735
 
736
        case SET_BUS_ID:
737
                reg_write(lynx, LINK_ID,
738
                          (arg << 22) | (reg_read(lynx, LINK_ID) & 0x003f0000));
739
                break;
740
 
741
        case ACT_CYCLE_MASTER:
742
                if (arg) {
743
                        reg_set_bits(lynx, LINK_CONTROL,
744
                                     LINK_CONTROL_CYCMASTER);
745
                } else {
746
                        reg_clear_bits(lynx, LINK_CONTROL,
747
                                       LINK_CONTROL_CYCMASTER);
748
                }
749
                break;
750
 
751
        case CANCEL_REQUESTS:
752
                spin_lock_irqsave(&lynx->async.queue_lock, flags);
753
 
754
                reg_write(lynx, DMA_CHAN_CTRL(CHANNEL_ASYNC_SEND), 0);
755
                list_splice(&lynx->async.queue, &packet_list);
756
                INIT_LIST_HEAD(&lynx->async.queue);
757
 
758
                if (list_empty(&lynx->async.pcl_queue)) {
759
                        spin_unlock_irqrestore(&lynx->async.queue_lock, flags);
760
                        PRINTD(KERN_DEBUG, lynx->id, "no async packet in PCL to cancel");
761
                } else {
762
                        struct ti_pcl pcl;
763
                        u32 ack;
764
                        struct hpsb_packet *packet;
765
 
766
                        PRINT(KERN_INFO, lynx->id, "cancelling async packet, that was already in PCL");
767
 
768
                        get_pcl(lynx, lynx->async.pcl, &pcl);
769
 
770
                        packet = driver_packet(lynx->async.pcl_queue.next);
771
                        list_del(&packet->driver_list);
772
 
773
                        pci_unmap_single(lynx->dev, lynx->async.header_dma,
774
                                         packet->header_size, PCI_DMA_TODEVICE);
775
                        if (packet->data_size) {
776
                                pci_unmap_single(lynx->dev, lynx->async.data_dma,
777
                                                 packet->data_size, PCI_DMA_TODEVICE);
778
                        }
779
 
780
                        spin_unlock_irqrestore(&lynx->async.queue_lock, flags);
781
 
782
                        if (pcl.pcl_status & DMA_CHAN_STAT_PKTCMPL) {
783
                                if (pcl.pcl_status & DMA_CHAN_STAT_SPECIALACK) {
784
                                        ack = (pcl.pcl_status >> 15) & 0xf;
785
                                        PRINTD(KERN_INFO, lynx->id, "special ack %d", ack);
786
                                        ack = (ack == 1 ? ACKX_TIMEOUT : ACKX_SEND_ERROR);
787
                                } else {
788
                                        ack = (pcl.pcl_status >> 15) & 0xf;
789
                                }
790
                        } else {
791
                                PRINT(KERN_INFO, lynx->id, "async packet was not completed");
792
                                ack = ACKX_ABORTED;
793
                        }
794
                        hpsb_packet_sent(host, packet, ack);
795
                }
796
 
797
                while (!list_empty(&packet_list)) {
798
                        packet = driver_packet(packet_list.next);
799
                        list_del(&packet->driver_list);
800
                        hpsb_packet_sent(host, packet, ACKX_ABORTED);
801
                }
802
 
803
                break;
804
 
805
        case MODIFY_USAGE:
806
                if (arg) {
807
                        MOD_INC_USE_COUNT;
808
                } else {
809
                        MOD_DEC_USE_COUNT;
810
                }
811
 
812
                retval = 1;
813
                break;
814
 
815
        case ISO_LISTEN_CHANNEL:
816
                spin_lock_irqsave(&lynx->iso_rcv.lock, flags);
817
 
818
                if (lynx->iso_rcv.chan_count++ == 0) {
819
                        reg_write(lynx, DMA_WORD1_CMP_ENABLE(CHANNEL_ISO_RCV),
820
                                  DMA_WORD1_CMP_ENABLE_MASTER);
821
                }
822
 
823
                spin_unlock_irqrestore(&lynx->iso_rcv.lock, flags);
824
                break;
825
 
826
        case ISO_UNLISTEN_CHANNEL:
827
                spin_lock_irqsave(&lynx->iso_rcv.lock, flags);
828
 
829
                if (--lynx->iso_rcv.chan_count == 0) {
830
                        reg_write(lynx, DMA_WORD1_CMP_ENABLE(CHANNEL_ISO_RCV),
831
                                  0);
832
                }
833
 
834
                spin_unlock_irqrestore(&lynx->iso_rcv.lock, flags);
835
                break;
836
 
837
        default:
838
                PRINT(KERN_ERR, lynx->id, "unknown devctl command %d", cmd);
839
                retval = -1;
840
        }
841
 
842
        return retval;
843
}
844
 
845
 
846
/***************************************
847
 * IEEE-1394 functionality section END *
848
 ***************************************/
849
 
850
#ifdef CONFIG_IEEE1394_PCILYNX_PORTS
851
/* VFS functions for local bus / aux device access.  Access to those
852
 * is implemented as a character device instead of block devices
853
 * because buffers are not wanted for this.  Therefore llseek (from
854
 * VFS) can be used for these char devices with obvious effects.
855
 */
856
static int mem_open(struct inode*, struct file*);
857
static int mem_release(struct inode*, struct file*);
858
static unsigned int aux_poll(struct file*, struct poll_table_struct*);
859
static loff_t mem_llseek(struct file*, loff_t, int);
860
static ssize_t mem_read (struct file*, char*, size_t, loff_t*);
861
static ssize_t mem_write(struct file*, const char*, size_t, loff_t*);
862
 
863
 
864
static struct file_operations aux_ops = {
865
        .owner =        THIS_MODULE,
866
        .read =         mem_read,
867
        .write =        mem_write,
868
        .poll =         aux_poll,
869
        .llseek =       mem_llseek,
870
        .open =         mem_open,
871
        .release =      mem_release,
872
};
873
 
874
 
875
static void aux_setup_pcls(struct ti_lynx *lynx)
876
{
877
        struct ti_pcl pcl;
878
 
879
        pcl.next = PCL_NEXT_INVALID;
880
        pcl.user_data = pcl_bus(lynx, lynx->dmem_pcl);
881
        put_pcl(lynx, lynx->dmem_pcl, &pcl);
882
}
883
 
884
static int mem_open(struct inode *inode, struct file *file)
885
{
886
        int cid = MINOR(inode->i_rdev);
887
        enum { t_rom, t_aux, t_ram } type;
888
        struct memdata *md;
889
 
890
        if (cid < PCILYNX_MINOR_AUX_START) {
891
                /* just for completeness */
892
                return -ENXIO;
893
        } else if (cid < PCILYNX_MINOR_ROM_START) {
894
                cid -= PCILYNX_MINOR_AUX_START;
895
                if (cid >= num_of_cards || !cards[cid].aux_port)
896
                        return -ENXIO;
897
                type = t_aux;
898
        } else if (cid < PCILYNX_MINOR_RAM_START) {
899
                cid -= PCILYNX_MINOR_ROM_START;
900
                if (cid >= num_of_cards || !cards[cid].local_rom)
901
                        return -ENXIO;
902
                type = t_rom;
903
        } else {
904
                /* WARNING: Know what you are doing when opening RAM.
905
                 * It is currently used inside the driver! */
906
                cid -= PCILYNX_MINOR_RAM_START;
907
                if (cid >= num_of_cards || !cards[cid].local_ram)
908
                        return -ENXIO;
909
                type = t_ram;
910
        }
911
 
912
        md = (struct memdata *)kmalloc(sizeof(struct memdata), SLAB_KERNEL);
913
        if (md == NULL)
914
                return -ENOMEM;
915
 
916
        md->lynx = &cards[cid];
917
        md->cid = cid;
918
 
919
        switch (type) {
920
        case t_rom:
921
                md->type = rom;
922
                break;
923
        case t_ram:
924
                md->type = ram;
925
                break;
926
        case t_aux:
927
                atomic_set(&md->aux_intr_last_seen,
928
                           atomic_read(&cards[cid].aux_intr_seen));
929
                md->type = aux;
930
                break;
931
        }
932
 
933
        file->private_data = md;
934
 
935
        return 0;
936
}
937
 
938
static int mem_release(struct inode *inode, struct file *file)
939
{
940
        kfree(file->private_data);
941
        return 0;
942
}
943
 
944
static unsigned int aux_poll(struct file *file, poll_table *pt)
945
{
946
        struct memdata *md = (struct memdata *)file->private_data;
947
        int cid = md->cid;
948
        unsigned int mask;
949
 
950
        /* reading and writing is always allowed */
951
        mask = POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM;
952
 
953
        if (md->type == aux) {
954
                poll_wait(file, &cards[cid].aux_intr_wait, pt);
955
 
956
                if (atomic_read(&md->aux_intr_last_seen)
957
                    != atomic_read(&cards[cid].aux_intr_seen)) {
958
                        mask |= POLLPRI;
959
                        atomic_inc(&md->aux_intr_last_seen);
960
                }
961
        }
962
 
963
        return mask;
964
}
965
 
966
loff_t mem_llseek(struct file *file, loff_t offs, int orig)
967
{
968
        loff_t newoffs;
969
 
970
        switch (orig) {
971
        case 0:
972
                newoffs = offs;
973
                break;
974
        case 1:
975
                newoffs = offs + file->f_pos;
976
                break;
977
        case 2:
978
                newoffs = PCILYNX_MAX_MEMORY + 1 + offs;
979
                break;
980
        default:
981
                return -EINVAL;
982
        }
983
 
984
        if (newoffs < 0 || newoffs > PCILYNX_MAX_MEMORY + 1) return -EINVAL;
985
 
986
        file->f_pos = newoffs;
987
        return newoffs;
988
}
989
 
990
/*
991
 * do not DMA if count is too small because this will have a serious impact
992
 * on performance - the value 2400 was found by experiment and may not work
993
 * everywhere as good as here - use mem_mindma option for modules to change
994
 */
995
short mem_mindma = 2400;
996
MODULE_PARM(mem_mindma, "h");
997
 
998
static ssize_t mem_dmaread(struct memdata *md, u32 physbuf, ssize_t count,
999
                           int offset)
1000
{
1001
        pcltmp_t pcltmp;
1002
        struct ti_pcl *pcl;
1003
        size_t retval;
1004
        int i;
1005
        DECLARE_WAITQUEUE(wait, current);
1006
 
1007
        count &= ~3;
1008
        count = min(count, 53196);
1009
        retval = count;
1010
 
1011
        if (reg_read(md->lynx, DMA_CHAN_CTRL(CHANNEL_LOCALBUS))
1012
            & DMA_CHAN_CTRL_BUSY) {
1013
                PRINT(KERN_WARNING, md->lynx->id, "DMA ALREADY ACTIVE!");
1014
        }
1015
 
1016
        reg_write(md->lynx, LBUS_ADDR, md->type | offset);
1017
 
1018
        pcl = edit_pcl(md->lynx, md->lynx->dmem_pcl, &pcltmp);
1019
        pcl->buffer[0].control = PCL_CMD_LBUS_TO_PCI | min(count, 4092);
1020
        pcl->buffer[0].pointer = physbuf;
1021
        count -= 4092;
1022
 
1023
        i = 0;
1024
        while (count > 0) {
1025
                i++;
1026
                pcl->buffer[i].control = min(count, 4092);
1027
                pcl->buffer[i].pointer = physbuf + i * 4092;
1028
                count -= 4092;
1029
        }
1030
        pcl->buffer[i].control |= PCL_LAST_BUFF;
1031
        commit_pcl(md->lynx, md->lynx->dmem_pcl, &pcltmp);
1032
 
1033
        set_current_state(TASK_INTERRUPTIBLE);
1034
        add_wait_queue(&md->lynx->mem_dma_intr_wait, &wait);
1035
        run_sub_pcl(md->lynx, md->lynx->dmem_pcl, 2, CHANNEL_LOCALBUS);
1036
 
1037
        schedule();
1038
        while (reg_read(md->lynx, DMA_CHAN_CTRL(CHANNEL_LOCALBUS))
1039
               & DMA_CHAN_CTRL_BUSY) {
1040
                if (signal_pending(current)) {
1041
                        retval = -EINTR;
1042
                        break;
1043
                }
1044
                schedule();
1045
        }
1046
 
1047
        reg_write(md->lynx, DMA_CHAN_CTRL(CHANNEL_LOCALBUS), 0);
1048
        remove_wait_queue(&md->lynx->mem_dma_intr_wait, &wait);
1049
 
1050
        if (reg_read(md->lynx, DMA_CHAN_CTRL(CHANNEL_LOCALBUS))
1051
            & DMA_CHAN_CTRL_BUSY) {
1052
                PRINT(KERN_ERR, md->lynx->id, "DMA STILL ACTIVE!");
1053
        }
1054
 
1055
        return retval;
1056
}
1057
 
1058
static ssize_t mem_read(struct file *file, char *buffer, size_t count,
1059
                        loff_t *offset)
1060
{
1061
        struct memdata *md = (struct memdata *)file->private_data;
1062
        ssize_t bcount;
1063
        size_t alignfix;
1064
        loff_t off = *offset; /* avoid useless 64bit-arithmetic */
1065
        ssize_t retval;
1066
        void *membase;
1067
 
1068
        if ((off + count) > PCILYNX_MAX_MEMORY+1) {
1069
                count = PCILYNX_MAX_MEMORY+1 - off;
1070
        }
1071
        if (count == 0 || off > PCILYNX_MAX_MEMORY) {
1072
                return -ENOSPC;
1073
        }
1074
 
1075
        switch (md->type) {
1076
        case rom:
1077
                membase = md->lynx->local_rom;
1078
                break;
1079
        case ram:
1080
                membase = md->lynx->local_ram;
1081
                break;
1082
        case aux:
1083
                membase = md->lynx->aux_port;
1084
                break;
1085
        default:
1086
                panic("pcilynx%d: unsupported md->type %d in %s",
1087
                      md->lynx->id, md->type, __FUNCTION__);
1088
        }
1089
 
1090
        down(&md->lynx->mem_dma_mutex);
1091
 
1092
        if (count < mem_mindma) {
1093
                memcpy_fromio(md->lynx->mem_dma_buffer, membase+off, count);
1094
                goto out;
1095
        }
1096
 
1097
        bcount = count;
1098
        alignfix = 4 - (off % 4);
1099
        if (alignfix != 4) {
1100
                if (bcount < alignfix) {
1101
                        alignfix = bcount;
1102
                }
1103
                memcpy_fromio(md->lynx->mem_dma_buffer, membase+off,
1104
                              alignfix);
1105
                if (bcount == alignfix) {
1106
                        goto out;
1107
                }
1108
                bcount -= alignfix;
1109
                off += alignfix;
1110
        }
1111
 
1112
        while (bcount >= 4) {
1113
                retval = mem_dmaread(md, md->lynx->mem_dma_buffer_dma
1114
                                     + count - bcount, bcount, off);
1115
                if (retval < 0) return retval;
1116
 
1117
                bcount -= retval;
1118
                off += retval;
1119
        }
1120
 
1121
        if (bcount) {
1122
                memcpy_fromio(md->lynx->mem_dma_buffer + count - bcount,
1123
                              membase+off, bcount);
1124
        }
1125
 
1126
 out:
1127
        retval = copy_to_user(buffer, md->lynx->mem_dma_buffer, count);
1128
        up(&md->lynx->mem_dma_mutex);
1129
 
1130
        if (retval) return -EFAULT;
1131
        *offset += count;
1132
        return count;
1133
}
1134
 
1135
 
1136
static ssize_t mem_write(struct file *file, const char *buffer, size_t count,
1137
                         loff_t *offset)
1138
{
1139
        struct memdata *md = (struct memdata *)file->private_data;
1140
 
1141
        if (((*offset) + count) > PCILYNX_MAX_MEMORY+1) {
1142
                count = PCILYNX_MAX_MEMORY+1 - *offset;
1143
        }
1144
        if (count == 0 || *offset > PCILYNX_MAX_MEMORY) {
1145
                return -ENOSPC;
1146
        }
1147
 
1148
        /* FIXME: dereferencing pointers to PCI mem doesn't work everywhere */
1149
        switch (md->type) {
1150
        case aux:
1151
                if (copy_from_user(md->lynx->aux_port+(*offset), buffer, count))
1152
                        return -EFAULT;
1153
                break;
1154
        case ram:
1155
                if (copy_from_user(md->lynx->local_ram+(*offset), buffer, count))
1156
                        return -EFAULT;
1157
                break;
1158
        case rom:
1159
                /* the ROM may be writeable */
1160
                if (copy_from_user(md->lynx->local_rom+(*offset), buffer, count))
1161
                        return -EFAULT;
1162
                break;
1163
        }
1164
 
1165
        file->f_pos += count;
1166
        return count;
1167
}
1168
#endif /* CONFIG_IEEE1394_PCILYNX_PORTS */
1169
 
1170
 
1171
/********************************************************
1172
 * Global stuff (interrupt handler, init/shutdown code) *
1173
 ********************************************************/
1174
 
1175
 
1176
static void lynx_irq_handler(int irq, void *dev_id,
1177
                             struct pt_regs *regs_are_unused)
1178
{
1179
        struct ti_lynx *lynx = (struct ti_lynx *)dev_id;
1180
        struct hpsb_host *host = lynx->host;
1181
        u32 intmask;
1182
        u32 linkint;
1183
 
1184
        linkint = reg_read(lynx, LINK_INT_STATUS);
1185
        intmask = reg_read(lynx, PCI_INT_STATUS);
1186
 
1187
        if (!(intmask & PCI_INT_INT_PEND)) return;
1188
 
1189
        PRINTD(KERN_DEBUG, lynx->id, "interrupt: 0x%08x / 0x%08x", intmask,
1190
               linkint);
1191
 
1192
        reg_write(lynx, LINK_INT_STATUS, linkint);
1193
        reg_write(lynx, PCI_INT_STATUS, intmask);
1194
 
1195
#ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1196
        if (intmask & PCI_INT_AUX_INT) {
1197
                atomic_inc(&lynx->aux_intr_seen);
1198
                wake_up_interruptible(&lynx->aux_intr_wait);
1199
        }
1200
 
1201
        if (intmask & PCI_INT_DMA_HLT(CHANNEL_LOCALBUS)) {
1202
                wake_up_interruptible(&lynx->mem_dma_intr_wait);
1203
        }
1204
#endif
1205
 
1206
 
1207
        if (intmask & PCI_INT_1394) {
1208
                if (linkint & LINK_INT_PHY_TIMEOUT) {
1209
                        PRINT(KERN_INFO, lynx->id, "PHY timeout occurred");
1210
                }
1211
                if (linkint & LINK_INT_PHY_BUSRESET) {
1212
                        PRINT(KERN_INFO, lynx->id, "bus reset interrupt");
1213
                        lynx->selfid_size = -1;
1214
                        lynx->phy_reg0 = -1;
1215
                        if (!host->in_bus_reset)
1216
                                hpsb_bus_reset(host);
1217
                }
1218
                if (linkint & LINK_INT_PHY_REG_RCVD) {
1219
                        u32 reg;
1220
 
1221
                        spin_lock(&lynx->phy_reg_lock);
1222
                        reg = reg_read(lynx, LINK_PHY);
1223
                        spin_unlock(&lynx->phy_reg_lock);
1224
 
1225
                        if (!host->in_bus_reset) {
1226
                                PRINT(KERN_INFO, lynx->id,
1227
                                      "phy reg received without reset");
1228
                        } else if (reg & 0xf00) {
1229
                                PRINT(KERN_INFO, lynx->id,
1230
                                      "unsolicited phy reg %d received",
1231
                                      (reg >> 8) & 0xf);
1232
                        } else {
1233
                                lynx->phy_reg0 = reg & 0xff;
1234
                                handle_selfid(lynx, host);
1235
                        }
1236
                }
1237
                if (linkint & LINK_INT_ISO_STUCK) {
1238
                        PRINT(KERN_INFO, lynx->id, "isochronous transmitter stuck");
1239
                }
1240
                if (linkint & LINK_INT_ASYNC_STUCK) {
1241
                        PRINT(KERN_INFO, lynx->id, "asynchronous transmitter stuck");
1242
                }
1243
                if (linkint & LINK_INT_SENT_REJECT) {
1244
                        PRINT(KERN_INFO, lynx->id, "sent reject");
1245
                }
1246
                if (linkint & LINK_INT_TX_INVALID_TC) {
1247
                        PRINT(KERN_INFO, lynx->id, "invalid transaction code");
1248
                }
1249
                if (linkint & LINK_INT_GRF_OVERFLOW) {
1250
                        /* flush FIFO if overflow happens during reset */
1251
                        if (host->in_bus_reset)
1252
                                reg_write(lynx, FIFO_CONTROL,
1253
                                          FIFO_CONTROL_GRF_FLUSH);
1254
                        PRINT(KERN_INFO, lynx->id, "GRF overflow");
1255
                }
1256
                if (linkint & LINK_INT_ITF_UNDERFLOW) {
1257
                        PRINT(KERN_INFO, lynx->id, "ITF underflow");
1258
                }
1259
                if (linkint & LINK_INT_ATF_UNDERFLOW) {
1260
                        PRINT(KERN_INFO, lynx->id, "ATF underflow");
1261
                }
1262
        }
1263
 
1264
        if (intmask & PCI_INT_DMA_HLT(CHANNEL_ISO_RCV)) {
1265
                PRINTD(KERN_DEBUG, lynx->id, "iso receive");
1266
 
1267
                spin_lock(&lynx->iso_rcv.lock);
1268
 
1269
                lynx->iso_rcv.stat[lynx->iso_rcv.next] =
1270
                        reg_read(lynx, DMA_CHAN_STAT(CHANNEL_ISO_RCV));
1271
 
1272
                lynx->iso_rcv.used++;
1273
                lynx->iso_rcv.next = (lynx->iso_rcv.next + 1) % NUM_ISORCV_PCL;
1274
 
1275
                if ((lynx->iso_rcv.next == lynx->iso_rcv.last)
1276
                    || !lynx->iso_rcv.chan_count) {
1277
                        PRINTD(KERN_DEBUG, lynx->id, "stopped");
1278
                        reg_write(lynx, DMA_WORD1_CMP_ENABLE(CHANNEL_ISO_RCV), 0);
1279
                }
1280
 
1281
                run_sub_pcl(lynx, lynx->iso_rcv.pcl_start, lynx->iso_rcv.next,
1282
                            CHANNEL_ISO_RCV);
1283
 
1284
                spin_unlock(&lynx->iso_rcv.lock);
1285
 
1286
                tasklet_schedule(&lynx->iso_rcv.tq);
1287
        }
1288
 
1289
        if (intmask & PCI_INT_DMA_HLT(CHANNEL_ASYNC_SEND)) {
1290
                PRINTD(KERN_DEBUG, lynx->id, "async sent");
1291
                spin_lock(&lynx->async.queue_lock);
1292
 
1293
                if (list_empty(&lynx->async.pcl_queue)) {
1294
                        spin_unlock(&lynx->async.queue_lock);
1295
                        PRINT(KERN_WARNING, lynx->id, "async dma halted, but no queued packet (maybe it was cancelled)");
1296
                } else {
1297
                        struct ti_pcl pcl;
1298
                        u32 ack;
1299
                        struct hpsb_packet *packet;
1300
 
1301
                        get_pcl(lynx, lynx->async.pcl, &pcl);
1302
 
1303
                        packet = driver_packet(lynx->async.pcl_queue.next);
1304
                        list_del(&packet->driver_list);
1305
 
1306
                        pci_unmap_single(lynx->dev, lynx->async.header_dma,
1307
                                         packet->header_size, PCI_DMA_TODEVICE);
1308
                        if (packet->data_size) {
1309
                                pci_unmap_single(lynx->dev, lynx->async.data_dma,
1310
                                                 packet->data_size, PCI_DMA_TODEVICE);
1311
                        }
1312
 
1313
                        if (!list_empty(&lynx->async.queue)) {
1314
                                send_next(lynx, hpsb_async);
1315
                        }
1316
 
1317
                        spin_unlock(&lynx->async.queue_lock);
1318
 
1319
                        if (pcl.pcl_status & DMA_CHAN_STAT_PKTCMPL) {
1320
                                if (pcl.pcl_status & DMA_CHAN_STAT_SPECIALACK) {
1321
                                        ack = (pcl.pcl_status >> 15) & 0xf;
1322
                                        PRINTD(KERN_INFO, lynx->id, "special ack %d", ack);
1323
                                        ack = (ack == 1 ? ACKX_TIMEOUT : ACKX_SEND_ERROR);
1324
                                } else {
1325
                                        ack = (pcl.pcl_status >> 15) & 0xf;
1326
                                }
1327
                        } else {
1328
                                PRINT(KERN_INFO, lynx->id, "async packet was not completed");
1329
                                ack = ACKX_SEND_ERROR;
1330
                        }
1331
                        hpsb_packet_sent(host, packet, ack);
1332
                }
1333
        }
1334
 
1335
        if (intmask & PCI_INT_DMA_HLT(CHANNEL_ISO_SEND)) {
1336
                PRINTD(KERN_DEBUG, lynx->id, "iso sent");
1337
                spin_lock(&lynx->iso_send.queue_lock);
1338
 
1339
                if (list_empty(&lynx->iso_send.pcl_queue)) {
1340
                        spin_unlock(&lynx->iso_send.queue_lock);
1341
                        PRINT(KERN_ERR, lynx->id, "iso send dma halted, but no queued packet");
1342
                } else {
1343
                        struct ti_pcl pcl;
1344
                        u32 ack;
1345
                        struct hpsb_packet *packet;
1346
 
1347
                        get_pcl(lynx, lynx->iso_send.pcl, &pcl);
1348
 
1349
                        packet = driver_packet(lynx->iso_send.pcl_queue.next);
1350
                        list_del(&packet->driver_list);
1351
 
1352
                        pci_unmap_single(lynx->dev, lynx->iso_send.header_dma,
1353
                                         packet->header_size, PCI_DMA_TODEVICE);
1354
                        if (packet->data_size) {
1355
                                pci_unmap_single(lynx->dev, lynx->iso_send.data_dma,
1356
                                                 packet->data_size, PCI_DMA_TODEVICE);
1357
                        }
1358
 
1359
                        if (!list_empty(&lynx->iso_send.queue)) {
1360
                                send_next(lynx, hpsb_iso);
1361
                        }
1362
 
1363
                        spin_unlock(&lynx->iso_send.queue_lock);
1364
 
1365
                        if (pcl.pcl_status & DMA_CHAN_STAT_PKTCMPL) {
1366
                                if (pcl.pcl_status & DMA_CHAN_STAT_SPECIALACK) {
1367
                                        ack = (pcl.pcl_status >> 15) & 0xf;
1368
                                        PRINTD(KERN_INFO, lynx->id, "special ack %d", ack);
1369
                                        ack = (ack == 1 ? ACKX_TIMEOUT : ACKX_SEND_ERROR);
1370
                                } else {
1371
                                        ack = (pcl.pcl_status >> 15) & 0xf;
1372
                                }
1373
                        } else {
1374
                                PRINT(KERN_INFO, lynx->id, "iso send packet was not completed");
1375
                                ack = ACKX_SEND_ERROR;
1376
                        }
1377
 
1378
                        hpsb_packet_sent(host, packet, ack); //FIXME: maybe we should just use ACK_COMPLETE and ACKX_SEND_ERROR
1379
                }
1380
        }
1381
 
1382
        if (intmask & PCI_INT_DMA_HLT(CHANNEL_ASYNC_RCV)) {
1383
                /* general receive DMA completed */
1384
                int stat = reg_read(lynx, DMA_CHAN_STAT(CHANNEL_ASYNC_RCV));
1385
 
1386
                PRINTD(KERN_DEBUG, lynx->id, "received packet size %d",
1387
                       stat & 0x1fff);
1388
 
1389
                if (stat & DMA_CHAN_STAT_SELFID) {
1390
                        lynx->selfid_size = stat & 0x1fff;
1391
                        handle_selfid(lynx, host);
1392
                } else {
1393
                        quadlet_t *q_data = lynx->rcv_page;
1394
                        if ((*q_data >> 4 & 0xf) == TCODE_READQ_RESPONSE
1395
                            || (*q_data >> 4 & 0xf) == TCODE_WRITEQ) {
1396
                                cpu_to_be32s(q_data + 3);
1397
                        }
1398
                        hpsb_packet_received(host, q_data, stat & 0x1fff, 0);
1399
                }
1400
 
1401
                run_pcl(lynx, lynx->rcv_pcl_start, CHANNEL_ASYNC_RCV);
1402
        }
1403
}
1404
 
1405
 
1406
static void iso_rcv_bh(struct ti_lynx *lynx)
1407
{
1408
        unsigned int idx;
1409
        quadlet_t *data;
1410
        unsigned long flags;
1411
 
1412
        spin_lock_irqsave(&lynx->iso_rcv.lock, flags);
1413
 
1414
        while (lynx->iso_rcv.used) {
1415
                idx = lynx->iso_rcv.last;
1416
                spin_unlock_irqrestore(&lynx->iso_rcv.lock, flags);
1417
 
1418
                data = lynx->iso_rcv.page[idx / ISORCV_PER_PAGE]
1419
                        + (idx % ISORCV_PER_PAGE) * MAX_ISORCV_SIZE;
1420
 
1421
                if ((*data >> 16) + 4 != (lynx->iso_rcv.stat[idx] & 0x1fff)) {
1422
                        PRINT(KERN_ERR, lynx->id,
1423
                              "iso length mismatch 0x%08x/0x%08x", *data,
1424
                              lynx->iso_rcv.stat[idx]);
1425
                }
1426
 
1427
                if (lynx->iso_rcv.stat[idx]
1428
                    & (DMA_CHAN_STAT_PCIERR | DMA_CHAN_STAT_PKTERR)) {
1429
                        PRINT(KERN_INFO, lynx->id,
1430
                              "iso receive error on %d to 0x%p", idx, data);
1431
                } else {
1432
                        hpsb_packet_received(lynx->host, data,
1433
                                             lynx->iso_rcv.stat[idx] & 0x1fff,
1434
                                             0);
1435
                }
1436
 
1437
                spin_lock_irqsave(&lynx->iso_rcv.lock, flags);
1438
                lynx->iso_rcv.last = (idx + 1) % NUM_ISORCV_PCL;
1439
                lynx->iso_rcv.used--;
1440
        }
1441
 
1442
        if (lynx->iso_rcv.chan_count) {
1443
                reg_write(lynx, DMA_WORD1_CMP_ENABLE(CHANNEL_ISO_RCV),
1444
                          DMA_WORD1_CMP_ENABLE_MASTER);
1445
        }
1446
        spin_unlock_irqrestore(&lynx->iso_rcv.lock, flags);
1447
}
1448
 
1449
 
1450
static void remove_card(struct pci_dev *dev)
1451
{
1452
        struct ti_lynx *lynx;
1453
        int i;
1454
 
1455
        lynx = pci_get_drvdata(dev);
1456
        if (!lynx) return;
1457
        pci_set_drvdata(dev, NULL);
1458
 
1459
        switch (lynx->state) {
1460
        case is_host:
1461
                reg_write(lynx, PCI_INT_ENABLE, 0);
1462
                hpsb_remove_host(lynx->host);
1463
        case have_intr:
1464
                reg_write(lynx, PCI_INT_ENABLE, 0);
1465
                free_irq(lynx->dev->irq, lynx);
1466
 
1467
                /* Disable IRM Contender */
1468
                if (lynx->phyic.reg_1394a)
1469
                        set_phy_reg(lynx, 4, ~0xc0 & get_phy_reg(lynx, 4));
1470
 
1471
                /* Let all other nodes know to ignore us */
1472
                lynx_devctl(lynx->host, RESET_BUS, LONG_RESET_NO_FORCE_ROOT);
1473
 
1474
        case have_iomappings:
1475
                reg_set_bits(lynx, MISC_CONTROL, MISC_CONTROL_SWRESET);
1476
                /* Fix buggy cards with autoboot pin not tied low: */
1477
                reg_write(lynx, DMA0_CHAN_CTRL, 0);
1478
                iounmap(lynx->registers);
1479
                iounmap(lynx->local_rom);
1480
                iounmap(lynx->local_ram);
1481
                iounmap(lynx->aux_port);
1482
        case have_1394_buffers:
1483
                for (i = 0; i < ISORCV_PAGES; i++) {
1484
                        if (lynx->iso_rcv.page[i]) {
1485
                                pci_free_consistent(lynx->dev, PAGE_SIZE,
1486
                                                    lynx->iso_rcv.page[i],
1487
                                                    lynx->iso_rcv.page_dma[i]);
1488
                        }
1489
                }
1490
                pci_free_consistent(lynx->dev, PAGE_SIZE, lynx->rcv_page,
1491
                                    lynx->rcv_page_dma);
1492
        case have_aux_buf:
1493
#ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1494
                pci_free_consistent(lynx->dev, 65536, lynx->mem_dma_buffer,
1495
                                    lynx->mem_dma_buffer_dma);
1496
#endif
1497
        case have_pcl_mem:
1498
#ifndef CONFIG_IEEE1394_PCILYNX_LOCALRAM
1499
                pci_free_consistent(lynx->dev, LOCALRAM_SIZE, lynx->pcl_mem,
1500
                                    lynx->pcl_mem_dma);
1501
#endif
1502
        case clear:
1503
                /* do nothing - already freed */
1504
                ;
1505
        }
1506
 
1507
        tasklet_kill(&lynx->iso_rcv.tq);
1508
        hpsb_unref_host(lynx->host);
1509
}
1510
 
1511
 
1512
static int __devinit add_card(struct pci_dev *dev,
1513
                              const struct pci_device_id *devid_is_unused)
1514
{
1515
#define FAIL(fmt, args...) do { \
1516
        PRINT_G(KERN_ERR, fmt , ## args); \
1517
        remove_card(dev); \
1518
        return error; \
1519
        } while (0)
1520
 
1521
        char irq_buf[16];
1522
        struct hpsb_host *host;
1523
        struct ti_lynx *lynx; /* shortcut to currently handled device */
1524
        struct ti_pcl pcl;
1525
        u32 *pcli;
1526
        int i;
1527
        int error;
1528
 
1529
        /* needed for i2c communication with serial eeprom */
1530
        struct i2c_adapter i2c_adapter;
1531
        struct i2c_algo_bit_data i2c_adapter_data;
1532
 
1533
        int got_valid_bus_info_block = 0; /* set to 1, if we were able to get a valid bus info block from serial eeprom */
1534
 
1535
        error = -ENXIO;
1536
 
1537
        if (pci_set_dma_mask(dev, 0xffffffff))
1538
                FAIL("DMA address limits not supported for PCILynx hardware");
1539
        if (pci_enable_device(dev))
1540
                FAIL("failed to enable PCILynx hardware");
1541
        pci_set_master(dev);
1542
 
1543
        error = -ENOMEM;
1544
 
1545
        host = hpsb_alloc_host(&lynx_driver, sizeof(struct ti_lynx));
1546
        if (!host) FAIL("failed to allocate control structure memory");
1547
 
1548
        lynx = host->hostdata;
1549
        lynx->id = card_id++;
1550
        lynx->dev = dev;
1551
        lynx->state = clear;
1552
        lynx->host = host;
1553
        host->pdev = dev;
1554
        pci_set_drvdata(dev, lynx);
1555
 
1556
        lynx->lock = SPIN_LOCK_UNLOCKED;
1557
        lynx->phy_reg_lock = SPIN_LOCK_UNLOCKED;
1558
 
1559
#ifndef CONFIG_IEEE1394_PCILYNX_LOCALRAM
1560
        lynx->pcl_mem = pci_alloc_consistent(dev, LOCALRAM_SIZE,
1561
                                             &lynx->pcl_mem_dma);
1562
 
1563
        if (lynx->pcl_mem != NULL) {
1564
                lynx->state = have_pcl_mem;
1565
                PRINT(KERN_INFO, lynx->id,
1566
                      "allocated PCL memory %d Bytes @ 0x%p", LOCALRAM_SIZE,
1567
                      lynx->pcl_mem);
1568
        } else {
1569
                FAIL("failed to allocate PCL memory area");
1570
        }
1571
#endif
1572
 
1573
#ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1574
        lynx->mem_dma_buffer = pci_alloc_consistent(dev, 65536,
1575
                                                    &lynx->mem_dma_buffer_dma);
1576
        if (lynx->mem_dma_buffer == NULL) {
1577
                FAIL("failed to allocate DMA buffer for aux");
1578
        }
1579
        lynx->state = have_aux_buf;
1580
#endif
1581
 
1582
        lynx->rcv_page = pci_alloc_consistent(dev, PAGE_SIZE,
1583
                                              &lynx->rcv_page_dma);
1584
        if (lynx->rcv_page == NULL) {
1585
                FAIL("failed to allocate receive buffer");
1586
        }
1587
        lynx->state = have_1394_buffers;
1588
 
1589
        for (i = 0; i < ISORCV_PAGES; i++) {
1590
                lynx->iso_rcv.page[i] =
1591
                        pci_alloc_consistent(dev, PAGE_SIZE,
1592
                                             &lynx->iso_rcv.page_dma[i]);
1593
                if (lynx->iso_rcv.page[i] == NULL) {
1594
                        FAIL("failed to allocate iso receive buffers");
1595
                }
1596
        }
1597
 
1598
        lynx->registers = ioremap_nocache(pci_resource_start(dev,0),
1599
                                          PCILYNX_MAX_REGISTER);
1600
        lynx->local_ram = ioremap(pci_resource_start(dev,1), PCILYNX_MAX_MEMORY);
1601
        lynx->aux_port  = ioremap(pci_resource_start(dev,2), PCILYNX_MAX_MEMORY);
1602
        lynx->local_rom = ioremap(pci_resource_start(dev,PCI_ROM_RESOURCE),
1603
                                  PCILYNX_MAX_MEMORY);
1604
        lynx->state = have_iomappings;
1605
 
1606
        if (lynx->registers == NULL) {
1607
                FAIL("failed to remap registers - card not accessible");
1608
        }
1609
 
1610
#ifdef CONFIG_IEEE1394_PCILYNX_LOCALRAM
1611
        if (lynx->local_ram == NULL) {
1612
                FAIL("failed to remap local RAM which is required for "
1613
                     "operation");
1614
        }
1615
#endif
1616
 
1617
        reg_set_bits(lynx, MISC_CONTROL, MISC_CONTROL_SWRESET);
1618
        /* Fix buggy cards with autoboot pin not tied low: */
1619
        reg_write(lynx, DMA0_CHAN_CTRL, 0);
1620
 
1621
#ifndef __sparc__
1622
        sprintf (irq_buf, "%d", dev->irq);
1623
#else
1624
        sprintf (irq_buf, "%s", __irq_itoa(dev->irq));
1625
#endif
1626
 
1627
        if (!request_irq(dev->irq, lynx_irq_handler, SA_SHIRQ,
1628
                         PCILYNX_DRIVER_NAME, lynx)) {
1629
                PRINT(KERN_INFO, lynx->id, "allocated interrupt %s", irq_buf);
1630
                lynx->state = have_intr;
1631
        } else {
1632
                FAIL("failed to allocate shared interrupt %s", irq_buf);
1633
        }
1634
 
1635
        /* alloc_pcl return values are not checked, it is expected that the
1636
         * provided PCL space is sufficient for the initial allocations */
1637
#ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1638
        if (lynx->aux_port != NULL) {
1639
                lynx->dmem_pcl = alloc_pcl(lynx);
1640
                aux_setup_pcls(lynx);
1641
                sema_init(&lynx->mem_dma_mutex, 1);
1642
        }
1643
#endif
1644
        lynx->rcv_pcl = alloc_pcl(lynx);
1645
        lynx->rcv_pcl_start = alloc_pcl(lynx);
1646
        lynx->async.pcl = alloc_pcl(lynx);
1647
        lynx->async.pcl_start = alloc_pcl(lynx);
1648
        lynx->iso_send.pcl = alloc_pcl(lynx);
1649
        lynx->iso_send.pcl_start = alloc_pcl(lynx);
1650
 
1651
        for (i = 0; i < NUM_ISORCV_PCL; i++) {
1652
                lynx->iso_rcv.pcl[i] = alloc_pcl(lynx);
1653
        }
1654
        lynx->iso_rcv.pcl_start = alloc_pcl(lynx);
1655
 
1656
        /* all allocations successful - simple init stuff follows */
1657
 
1658
        reg_write(lynx, PCI_INT_ENABLE, PCI_INT_DMA_ALL);
1659
 
1660
#ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1661
        reg_set_bits(lynx, PCI_INT_ENABLE, PCI_INT_AUX_INT);
1662
        init_waitqueue_head(&lynx->mem_dma_intr_wait);
1663
        init_waitqueue_head(&lynx->aux_intr_wait);
1664
#endif
1665
 
1666
        tasklet_init(&lynx->iso_rcv.tq, (void (*)(unsigned long))iso_rcv_bh,
1667
                     (unsigned long)lynx);
1668
 
1669
        lynx->iso_rcv.lock = SPIN_LOCK_UNLOCKED;
1670
 
1671
        lynx->async.queue_lock = SPIN_LOCK_UNLOCKED;
1672
        lynx->async.channel = CHANNEL_ASYNC_SEND;
1673
        lynx->iso_send.queue_lock = SPIN_LOCK_UNLOCKED;
1674
        lynx->iso_send.channel = CHANNEL_ISO_SEND;
1675
 
1676
        PRINT(KERN_INFO, lynx->id, "remapped memory spaces reg 0x%p, rom 0x%p, "
1677
              "ram 0x%p, aux 0x%p", lynx->registers, lynx->local_rom,
1678
              lynx->local_ram, lynx->aux_port);
1679
 
1680
        /* now, looking for PHY register set */
1681
        if ((get_phy_reg(lynx, 2) & 0xe0) == 0xe0) {
1682
                lynx->phyic.reg_1394a = 1;
1683
                PRINT(KERN_INFO, lynx->id,
1684
                      "found 1394a conform PHY (using extended register set)");
1685
                lynx->phyic.vendor = get_phy_vendorid(lynx);
1686
                lynx->phyic.product = get_phy_productid(lynx);
1687
        } else {
1688
                lynx->phyic.reg_1394a = 0;
1689
                PRINT(KERN_INFO, lynx->id, "found old 1394 PHY");
1690
        }
1691
 
1692
        lynx->selfid_size = -1;
1693
        lynx->phy_reg0 = -1;
1694
 
1695
        INIT_LIST_HEAD(&lynx->async.queue);
1696
        INIT_LIST_HEAD(&lynx->async.pcl_queue);
1697
        INIT_LIST_HEAD(&lynx->iso_send.queue);
1698
        INIT_LIST_HEAD(&lynx->iso_send.pcl_queue);
1699
 
1700
        pcl.next = pcl_bus(lynx, lynx->rcv_pcl);
1701
        put_pcl(lynx, lynx->rcv_pcl_start, &pcl);
1702
 
1703
        pcl.next = PCL_NEXT_INVALID;
1704
        pcl.async_error_next = PCL_NEXT_INVALID;
1705
#ifdef __BIG_ENDIAN
1706
        pcl.buffer[0].control = PCL_CMD_RCV | 16;
1707
        pcl.buffer[1].control = PCL_LAST_BUFF | 4080;
1708
#else
1709
        pcl.buffer[0].control = PCL_CMD_RCV | PCL_BIGENDIAN | 16;
1710
        pcl.buffer[1].control = PCL_LAST_BUFF | 4080;
1711
#endif
1712
        pcl.buffer[0].pointer = lynx->rcv_page_dma;
1713
        pcl.buffer[1].pointer = lynx->rcv_page_dma + 16;
1714
        put_pcl(lynx, lynx->rcv_pcl, &pcl);
1715
 
1716
        pcl.next = pcl_bus(lynx, lynx->async.pcl);
1717
        pcl.async_error_next = pcl_bus(lynx, lynx->async.pcl);
1718
        put_pcl(lynx, lynx->async.pcl_start, &pcl);
1719
 
1720
        pcl.next = pcl_bus(lynx, lynx->iso_send.pcl);
1721
        pcl.async_error_next = PCL_NEXT_INVALID;
1722
        put_pcl(lynx, lynx->iso_send.pcl_start, &pcl);
1723
 
1724
        pcl.next = PCL_NEXT_INVALID;
1725
        pcl.async_error_next = PCL_NEXT_INVALID;
1726
        pcl.buffer[0].control = PCL_CMD_RCV | 4;
1727
#ifndef __BIG_ENDIAN
1728
        pcl.buffer[0].control |= PCL_BIGENDIAN;
1729
#endif
1730
        pcl.buffer[1].control = PCL_LAST_BUFF | 2044;
1731
 
1732
        for (i = 0; i < NUM_ISORCV_PCL; i++) {
1733
                int page = i / ISORCV_PER_PAGE;
1734
                int sec = i % ISORCV_PER_PAGE;
1735
 
1736
                pcl.buffer[0].pointer = lynx->iso_rcv.page_dma[page]
1737
                        + sec * MAX_ISORCV_SIZE;
1738
                pcl.buffer[1].pointer = pcl.buffer[0].pointer + 4;
1739
                put_pcl(lynx, lynx->iso_rcv.pcl[i], &pcl);
1740
        }
1741
 
1742
        pcli = (u32 *)&pcl;
1743
        for (i = 0; i < NUM_ISORCV_PCL; i++) {
1744
                pcli[i] = pcl_bus(lynx, lynx->iso_rcv.pcl[i]);
1745
        }
1746
        put_pcl(lynx, lynx->iso_rcv.pcl_start, &pcl);
1747
 
1748
        /* FIFO sizes from left to right: ITF=48 ATF=48 GRF=160 */
1749
        reg_write(lynx, FIFO_SIZES, 0x003030a0);
1750
        /* 20 byte threshold before triggering PCI transfer */
1751
        reg_write(lynx, DMA_GLOBAL_REGISTER, 0x2<<24);
1752
        /* threshold on both send FIFOs before transmitting:
1753
           FIFO size - cache line size - 1 */
1754
        i = reg_read(lynx, PCI_LATENCY_CACHELINE) & 0xff;
1755
        i = 0x30 - i - 1;
1756
        reg_write(lynx, FIFO_XMIT_THRESHOLD, (i << 8) | i);
1757
 
1758
        reg_set_bits(lynx, PCI_INT_ENABLE, PCI_INT_1394);
1759
 
1760
        reg_write(lynx, LINK_INT_ENABLE, LINK_INT_PHY_TIMEOUT
1761
                  | LINK_INT_PHY_REG_RCVD  | LINK_INT_PHY_BUSRESET
1762
                  | LINK_INT_ISO_STUCK     | LINK_INT_ASYNC_STUCK
1763
                  | LINK_INT_SENT_REJECT   | LINK_INT_TX_INVALID_TC
1764
                  | LINK_INT_GRF_OVERFLOW  | LINK_INT_ITF_UNDERFLOW
1765
                  | LINK_INT_ATF_UNDERFLOW);
1766
 
1767
        reg_write(lynx, DMA_WORD0_CMP_VALUE(CHANNEL_ASYNC_RCV), 0);
1768
        reg_write(lynx, DMA_WORD0_CMP_ENABLE(CHANNEL_ASYNC_RCV), 0xa<<4);
1769
        reg_write(lynx, DMA_WORD1_CMP_VALUE(CHANNEL_ASYNC_RCV), 0);
1770
        reg_write(lynx, DMA_WORD1_CMP_ENABLE(CHANNEL_ASYNC_RCV),
1771
                  DMA_WORD1_CMP_MATCH_LOCAL_NODE | DMA_WORD1_CMP_MATCH_BROADCAST
1772
                  | DMA_WORD1_CMP_MATCH_EXACT    | DMA_WORD1_CMP_MATCH_BUS_BCAST
1773
                  | DMA_WORD1_CMP_ENABLE_SELF_ID | DMA_WORD1_CMP_ENABLE_MASTER);
1774
 
1775
        run_pcl(lynx, lynx->rcv_pcl_start, CHANNEL_ASYNC_RCV);
1776
 
1777
        reg_write(lynx, DMA_WORD0_CMP_VALUE(CHANNEL_ISO_RCV), 0);
1778
        reg_write(lynx, DMA_WORD0_CMP_ENABLE(CHANNEL_ISO_RCV), 0x9<<4);
1779
        reg_write(lynx, DMA_WORD1_CMP_VALUE(CHANNEL_ISO_RCV), 0);
1780
        reg_write(lynx, DMA_WORD1_CMP_ENABLE(CHANNEL_ISO_RCV), 0);
1781
 
1782
        run_sub_pcl(lynx, lynx->iso_rcv.pcl_start, 0, CHANNEL_ISO_RCV);
1783
 
1784
        reg_write(lynx, LINK_CONTROL, LINK_CONTROL_RCV_CMP_VALID
1785
                  | LINK_CONTROL_TX_ISO_EN   | LINK_CONTROL_RX_ISO_EN
1786
                  | LINK_CONTROL_TX_ASYNC_EN | LINK_CONTROL_RX_ASYNC_EN
1787
                  | LINK_CONTROL_RESET_TX    | LINK_CONTROL_RESET_RX);
1788
 
1789
        if (!lynx->phyic.reg_1394a) {
1790
                /* attempt to enable contender bit -FIXME- would this work
1791
                 * elsewhere? */
1792
                reg_set_bits(lynx, GPIO_CTRL_A, 0x1);
1793
                reg_write(lynx, GPIO_DATA_BASE + 0x3c, 0x1);
1794
        } else {
1795
                /* set the contender bit in the extended PHY register
1796
                 * set. (Should check that bis 0,1,2 (=0xE0) is set
1797
                 * in register 2?)
1798
                 */
1799
                i = get_phy_reg(lynx, 4);
1800
                if (i != -1) set_phy_reg(lynx, 4, i | 0x40);
1801
        }
1802
 
1803
 
1804
        if (!skip_eeprom)
1805
        {
1806
                i2c_adapter = bit_ops;
1807
                i2c_adapter_data = bit_data;
1808
                i2c_adapter.algo_data = &i2c_adapter_data;
1809
                i2c_adapter_data.data = lynx;
1810
 
1811
                PRINTD(KERN_DEBUG, lynx->id,"original eeprom control: %d",
1812
                       reg_read(lynx, SERIAL_EEPROM_CONTROL));
1813
 
1814
                /* reset hardware to sane state */
1815
                lynx->i2c_driven_state = 0x00000070;
1816
                reg_write(lynx, SERIAL_EEPROM_CONTROL, lynx->i2c_driven_state);
1817
 
1818
                if (i2c_bit_add_bus(&i2c_adapter) < 0)
1819
                {
1820
                        PRINT(KERN_ERR, lynx->id,  "unable to register i2c");
1821
                }
1822
                else
1823
                {
1824
                        /* do i2c stuff */
1825
                        unsigned char i2c_cmd = 0x10;
1826
                        struct i2c_msg msg[2] = { { 0x50, 0, 1, &i2c_cmd },
1827
                                                  { 0x50, I2C_M_RD, 20, (unsigned char*) lynx->config_rom }
1828
                                                };
1829
 
1830
 
1831
#ifdef CONFIG_IEEE1394_VERBOSEDEBUG
1832
                        union i2c_smbus_data data;
1833
 
1834
                        if (i2c_smbus_xfer(&i2c_adapter, 80, 0, I2C_SMBUS_WRITE, 0, I2C_SMBUS_BYTE,NULL))
1835
                                PRINT(KERN_ERR, lynx->id,"eeprom read start has failed");
1836
                        else
1837
                        {
1838
                                u16 addr;
1839
                                for (addr=0x00; addr < 0x100; addr++) {
1840
                                        if (i2c_smbus_xfer(&i2c_adapter, 80, 0, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE,& data)) {
1841
                                                PRINT(KERN_ERR, lynx->id, "unable to read i2c %x", addr);
1842
                                                break;
1843
                                        }
1844
                                        else
1845
                                                PRINT(KERN_DEBUG, lynx->id,"got serial eeprom data at %x: %x",addr, data.byte);
1846
                                }
1847
                        }
1848
#endif
1849
 
1850
                        /* we use i2c_transfer, because i2c_smbus_read_block_data does not work properly and we
1851
                           do it more efficiently in one transaction rather then using several reads */
1852
                        if (i2c_transfer(&i2c_adapter, msg, 2) < 0) {
1853
                                PRINT(KERN_ERR, lynx->id, "unable to read bus info block from i2c");
1854
                        } else {
1855
                                int i;
1856
 
1857
                                PRINT(KERN_INFO, lynx->id, "got bus info block from serial eeprom");
1858
                                /* FIXME: probably we shoud rewrite the max_rec, max_ROM(1394a),
1859
                                 * generation(1394a) and link_spd(1394a) field and recalculate
1860
                                 * the CRC */
1861
 
1862
                                for (i = 0; i < 5 ; i++)
1863
                                        PRINTD(KERN_DEBUG, lynx->id, "Businfo block quadlet %i: %08x",
1864
                                               i, be32_to_cpu(lynx->config_rom[i]));
1865
 
1866
                                /* info_length, crc_length and 1394 magic number to check, if it is really a bus info block */
1867
                                if (((be32_to_cpu(lynx->config_rom[0]) & 0xffff0000) == 0x04040000) &&
1868
                                    (lynx->config_rom[1] == __constant_cpu_to_be32(0x31333934)))
1869
                                {
1870
                                        PRINT(KERN_DEBUG, lynx->id, "read a valid bus info block from");
1871
                                        got_valid_bus_info_block = 1;
1872
                                } else {
1873
                                        PRINT(KERN_WARNING, lynx->id, "read something from serial eeprom, but it does not seem to be a valid bus info block");
1874
                                }
1875
 
1876
                        }
1877
 
1878
                        i2c_bit_del_bus(&i2c_adapter);
1879
                }
1880
        }
1881
 
1882
        if (got_valid_bus_info_block) {
1883
                memcpy(lynx->config_rom+5,lynx_csr_rom+5,sizeof(lynx_csr_rom)-20);
1884
        } else {
1885
                PRINT(KERN_INFO, lynx->id, "since we did not get a bus info block from serial eeprom, we use a generic one with a hard coded GUID");
1886
                memcpy(lynx->config_rom,lynx_csr_rom,sizeof(lynx_csr_rom));
1887
        }
1888
 
1889
        hpsb_add_host(host);
1890
        lynx->state = is_host;
1891
 
1892
        return 0;
1893
#undef FAIL
1894
}
1895
 
1896
 
1897
 
1898
static size_t get_lynx_rom(struct hpsb_host *host, quadlet_t **ptr)
1899
{
1900
        struct ti_lynx *lynx = host->hostdata;
1901
        *ptr = lynx->config_rom;
1902
        return sizeof(lynx_csr_rom);
1903
}
1904
 
1905
static struct pci_device_id pci_table[] __devinitdata = {
1906
        {
1907
                .vendor =    PCI_VENDOR_ID_TI,
1908
                .device =    PCI_DEVICE_ID_TI_PCILYNX,
1909
                .subvendor = PCI_ANY_ID,
1910
                .subdevice = PCI_ANY_ID,
1911
        },
1912
        { }                     /* Terminating entry */
1913
};
1914
 
1915
static struct pci_driver lynx_pci_driver = {
1916
        .name =     PCILYNX_DRIVER_NAME,
1917
        .id_table = pci_table,
1918
        .probe =    add_card,
1919
        .remove =   remove_card,
1920
};
1921
 
1922
static struct hpsb_host_driver lynx_driver = {
1923
        .name =            PCILYNX_DRIVER_NAME,
1924
        .get_rom =         get_lynx_rom,
1925
        .transmit_packet = lynx_transmit,
1926
        .devctl =          lynx_devctl,
1927
        .isoctl =          NULL,
1928
};
1929
 
1930
MODULE_AUTHOR("Andreas E. Bombe <andreas.bombe@munich.netsurf.de>");
1931
MODULE_DESCRIPTION("driver for Texas Instruments PCI Lynx IEEE-1394 controller");
1932
MODULE_LICENSE("GPL");
1933
MODULE_SUPPORTED_DEVICE("pcilynx");
1934
MODULE_DEVICE_TABLE(pci, pci_table);
1935
 
1936
static int __init pcilynx_init(void)
1937
{
1938
        int ret;
1939
 
1940
#ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1941
        if (register_chrdev(PCILYNX_MAJOR, PCILYNX_DRIVER_NAME, &aux_ops)) {
1942
                PRINT_G(KERN_ERR, "allocation of char major number %d failed",
1943
                        PCILYNX_MAJOR);
1944
                return -EBUSY;
1945
        }
1946
#endif
1947
 
1948
        ret = pci_module_init(&lynx_pci_driver);
1949
        if (ret < 0) {
1950
                PRINT_G(KERN_ERR, "PCI module init failed");
1951
                goto free_char_dev;
1952
        }
1953
 
1954
        return 0;
1955
 
1956
 free_char_dev:
1957
#ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1958
        unregister_chrdev(PCILYNX_MAJOR, PCILYNX_DRIVER_NAME);
1959
#endif
1960
 
1961
        return ret;
1962
}
1963
 
1964
static void __exit pcilynx_cleanup(void)
1965
{
1966
        pci_unregister_driver(&lynx_pci_driver);
1967
 
1968
#ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1969
        unregister_chrdev(PCILYNX_MAJOR, PCILYNX_DRIVER_NAME);
1970
#endif
1971
}
1972
 
1973
 
1974
module_init(pcilynx_init);
1975
module_exit(pcilynx_cleanup);

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.