2 * 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>
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.
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.
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.
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
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/moduleparam.h>
41 #include <linux/init.h>
42 #include <linux/pci.h>
44 #include <linux/poll.h>
45 #include <linux/kdev_t.h>
46 #include <asm/byteorder.h>
47 #include <asm/atomic.h>
49 #include <asm/uaccess.h>
54 #include "ieee1394_types.h"
56 #include "ieee1394_core.h"
57 #include "highlevel.h"
60 #include <linux/i2c.h>
61 #include <linux/i2c-algo-bit.h>
63 /* print general (card independent) information */
64 #define PRINT_G(level, fmt, args...) printk(level "pcilynx: " fmt "\n" , ## args)
65 /* print card specific information */
66 #define PRINT(level, card, fmt, args...) printk(level "pcilynx%d: " fmt "\n" , card , ## args)
68 #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
69 #define PRINT_GD(level, fmt, args...) printk(level "pcilynx: " fmt "\n" , ## args)
70 #define PRINTD(level, card, fmt, args...) printk(level "pcilynx%d: " fmt "\n" , card , ## args)
72 #define PRINT_GD(level, fmt, args...) do {} while (0)
73 #define PRINTD(level, card, fmt, args...) do {} while (0)
77 /* Module Parameters */
78 static int skip_eeprom
= 0;
79 module_param(skip_eeprom
, int, 0444);
80 MODULE_PARM_DESC(skip_eeprom
, "Use generic bus info block instead of serial eeprom (default = 0).");
83 static struct hpsb_host_driver lynx_driver
;
84 static unsigned int card_id
;
92 /* the i2c stuff was inspired by i2c-philips-par.c */
94 static void bit_setscl(void *data
, int state
)
97 ((struct ti_lynx
*) data
)->i2c_driven_state
|= 0x00000040;
99 ((struct ti_lynx
*) data
)->i2c_driven_state
&= ~0x00000040;
101 reg_write((struct ti_lynx
*) data
, SERIAL_EEPROM_CONTROL
, ((struct ti_lynx
*) data
)->i2c_driven_state
);
104 static void bit_setsda(void *data
, int state
)
107 ((struct ti_lynx
*) data
)->i2c_driven_state
|= 0x00000010;
109 ((struct ti_lynx
*) data
)->i2c_driven_state
&= ~0x00000010;
111 reg_write((struct ti_lynx
*) data
, SERIAL_EEPROM_CONTROL
, ((struct ti_lynx
*) data
)->i2c_driven_state
);
114 static int bit_getscl(void *data
)
116 return reg_read((struct ti_lynx
*) data
, SERIAL_EEPROM_CONTROL
) & 0x00000040;
119 static int bit_getsda(void *data
)
121 return reg_read((struct ti_lynx
*) data
, SERIAL_EEPROM_CONTROL
) & 0x00000010;
124 static int bit_reg(struct i2c_client
*client
)
129 static int bit_unreg(struct i2c_client
*client
)
134 static struct i2c_algo_bit_data bit_data
= {
135 .setsda
= bit_setsda
,
136 .setscl
= bit_setscl
,
137 .getsda
= bit_getsda
,
138 .getscl
= bit_getscl
,
144 static struct i2c_adapter bit_ops
= {
145 .id
= 0xAA, //FIXME: probably we should get an id in i2c-id.h
146 .client_register
= bit_reg
,
147 .client_unregister
= bit_unreg
,
148 .name
= "PCILynx I2C",
154 * PCL handling functions.
157 static pcl_t
alloc_pcl(struct ti_lynx
*lynx
)
162 spin_lock(&lynx
->lock
);
163 /* FIXME - use ffz() to make this readable */
164 for (i
= 0; i
< (LOCALRAM_SIZE
/ 1024); i
++) {
165 m
= lynx
->pcl_bmap
[i
];
166 for (j
= 0; j
< 8; j
++) {
171 lynx
->pcl_bmap
[i
] = m
;
172 spin_unlock(&lynx
->lock
);
176 spin_unlock(&lynx
->lock
);
183 static void free_pcl(struct ti_lynx
*lynx
, pcl_t pclid
)
194 spin_lock(&lynx
->lock
);
195 if (lynx
->pcl_bmap
[off
] & 1<<bit
) {
196 lynx
->pcl_bmap
[off
] &= ~(1<<bit
);
198 PRINT(KERN_ERR
, lynx
->id
,
199 "attempted to free unallocated PCL %d", pclid
);
201 spin_unlock(&lynx
->lock
);
204 /* functions useful for debugging */
205 static void pretty_print_pcl(const struct ti_pcl
*pcl
)
209 printk("PCL next %08x, userdata %08x, status %08x, remtrans %08x, nextbuf %08x\n",
210 pcl
->next
, pcl
->user_data
, pcl
->pcl_status
,
211 pcl
->remaining_transfer_count
, pcl
->next_data_buffer
);
214 for (i
=0; i
<13; i
++) {
215 printk(" c%x:%08x d%x:%08x",
216 i
, pcl
->buffer
[i
].control
, i
, pcl
->buffer
[i
].pointer
);
217 if (!(i
& 0x3) && (i
!= 12)) printk("\nPCL");
222 static void print_pcl(const struct ti_lynx
*lynx
, pcl_t pclid
)
226 get_pcl(lynx
, pclid
, &pcl
);
227 pretty_print_pcl(&pcl
);
233 /***********************************
234 * IEEE-1394 functionality section *
235 ***********************************/
238 static int get_phy_reg(struct ti_lynx
*lynx
, int addr
)
246 PRINT(KERN_ERR
, lynx
->id
,
247 "%s: PHY register address %d out of range",
252 spin_lock_irqsave(&lynx
->phy_reg_lock
, flags
);
254 reg_write(lynx
, LINK_PHY
, LINK_PHY_READ
| LINK_PHY_ADDR(addr
));
256 retval
= reg_read(lynx
, LINK_PHY
);
259 PRINT(KERN_ERR
, lynx
->id
, "%s: runaway loop, aborting",
265 } while ((retval
& 0xf00) != LINK_PHY_RADDR(addr
));
267 reg_write(lynx
, LINK_INT_STATUS
, LINK_INT_PHY_REG_RCVD
);
268 spin_unlock_irqrestore(&lynx
->phy_reg_lock
, flags
);
271 return retval
& 0xff;
277 static int set_phy_reg(struct ti_lynx
*lynx
, int addr
, int val
)
282 PRINT(KERN_ERR
, lynx
->id
,
283 "%s: PHY register address %d out of range", __FUNCTION__
, addr
);
288 PRINT(KERN_ERR
, lynx
->id
,
289 "%s: PHY register value %d out of range", __FUNCTION__
, val
);
293 spin_lock_irqsave(&lynx
->phy_reg_lock
, flags
);
295 reg_write(lynx
, LINK_PHY
, LINK_PHY_WRITE
| LINK_PHY_ADDR(addr
)
296 | LINK_PHY_WDATA(val
));
298 spin_unlock_irqrestore(&lynx
->phy_reg_lock
, flags
);
303 static int sel_phy_reg_page(struct ti_lynx
*lynx
, int page
)
308 PRINT(KERN_ERR
, lynx
->id
,
309 "%s: PHY page %d out of range", __FUNCTION__
, page
);
313 reg
= get_phy_reg(lynx
, 7);
317 set_phy_reg(lynx
, 7, reg
);
324 #if 0 /* not needed at this time */
325 static int sel_phy_reg_port(struct ti_lynx
*lynx
, int port
)
330 PRINT(KERN_ERR
, lynx
->id
,
331 "%s: PHY port %d out of range", __FUNCTION__
, port
);
335 reg
= get_phy_reg(lynx
, 7);
339 set_phy_reg(lynx
, 7, reg
);
347 static u32
get_phy_vendorid(struct ti_lynx
*lynx
)
350 sel_phy_reg_page(lynx
, 1);
351 pvid
|= (get_phy_reg(lynx
, 10) << 16);
352 pvid
|= (get_phy_reg(lynx
, 11) << 8);
353 pvid
|= get_phy_reg(lynx
, 12);
354 PRINT(KERN_INFO
, lynx
->id
, "PHY vendor id 0x%06x", pvid
);
358 static u32
get_phy_productid(struct ti_lynx
*lynx
)
361 sel_phy_reg_page(lynx
, 1);
362 id
|= (get_phy_reg(lynx
, 13) << 16);
363 id
|= (get_phy_reg(lynx
, 14) << 8);
364 id
|= get_phy_reg(lynx
, 15);
365 PRINT(KERN_INFO
, lynx
->id
, "PHY product id 0x%06x", id
);
369 static quadlet_t
generate_own_selfid(struct ti_lynx
*lynx
,
370 struct hpsb_host
*host
)
376 phyreg
[0] = lynx
->phy_reg0
;
377 for (i
= 1; i
< 7; i
++) {
378 phyreg
[i
] = get_phy_reg(lynx
, i
);
381 /* FIXME? We assume a TSB21LV03A phy here. This code doesn't support
382 more than 3 ports on the PHY anyway. */
384 lsid
= 0x80400000 | ((phyreg
[0] & 0xfc) << 22);
385 lsid
|= (phyreg
[1] & 0x3f) << 16; /* gap count */
386 lsid
|= (phyreg
[2] & 0xc0) << 8; /* max speed */
387 if (!hpsb_disable_irm
)
388 lsid
|= (phyreg
[6] & 0x01) << 11; /* contender (phy dependent) */
389 /* lsid |= 1 << 11; *//* set contender (hack) */
390 lsid
|= (phyreg
[6] & 0x10) >> 3; /* initiated reset */
392 for (i
= 0; i
< (phyreg
[2] & 0xf); i
++) { /* ports */
393 if (phyreg
[3 + i
] & 0x4) {
394 lsid
|= (((phyreg
[3 + i
] & 0x8) | 0x10) >> 3)
397 lsid
|= 1 << (6 - i
*2);
402 PRINT(KERN_DEBUG
, lynx
->id
, "generated own selfid 0x%x", lsid
);
406 static void handle_selfid(struct ti_lynx
*lynx
, struct hpsb_host
*host
)
408 quadlet_t
*q
= lynx
->rcv_page
;
409 int phyid
, isroot
, size
;
413 if (lynx
->phy_reg0
== -1 || lynx
->selfid_size
== -1) return;
415 size
= lynx
->selfid_size
;
416 phyid
= lynx
->phy_reg0
;
418 i
= (size
> 16 ? 16 : size
) / 4 - 1;
424 if (!lynx
->phyic
.reg_1394a
) {
425 lsid
= generate_own_selfid(lynx
, host
);
428 isroot
= (phyid
& 2) != 0;
430 PRINT(KERN_INFO
, lynx
->id
, "SelfID process finished (phyid %d, %s)",
431 phyid
, (isroot
? "root" : "not root"));
432 reg_write(lynx
, LINK_ID
, (0xffc0 | phyid
) << 16);
434 if (!lynx
->phyic
.reg_1394a
&& !size
) {
435 hpsb_selfid_received(host
, lsid
);
439 struct selfid
*sid
= (struct selfid
*)q
;
441 if (!lynx
->phyic
.reg_1394a
&& !sid
->extended
442 && (sid
->phy_id
== (phyid
+ 1))) {
443 hpsb_selfid_received(host
, lsid
);
447 PRINT(KERN_DEBUG
, lynx
->id
, "SelfID packet 0x%x rcvd",
449 hpsb_selfid_received(host
, q
[0]);
451 PRINT(KERN_INFO
, lynx
->id
,
452 "inconsistent selfid 0x%x/0x%x", q
[0], q
[1]);
458 if (!lynx
->phyic
.reg_1394a
&& isroot
&& phyid
!= 0) {
459 hpsb_selfid_received(host
, lsid
);
462 hpsb_selfid_complete(host
, phyid
, isroot
);
464 if (host
->in_bus_reset
) return; /* in bus reset again */
466 if (isroot
) reg_set_bits(lynx
, LINK_CONTROL
, LINK_CONTROL_CYCMASTER
); //FIXME: I do not think, we need this here
467 reg_set_bits(lynx
, LINK_CONTROL
,
468 LINK_CONTROL_RCV_CMP_VALID
| LINK_CONTROL_TX_ASYNC_EN
469 | LINK_CONTROL_RX_ASYNC_EN
| LINK_CONTROL_CYCTIMEREN
);
474 /* This must be called with the respective queue_lock held. */
475 static void send_next(struct ti_lynx
*lynx
, int what
)
478 struct lynx_send_data
*d
;
479 struct hpsb_packet
*packet
;
481 d
= (what
== hpsb_iso
? &lynx
->iso_send
: &lynx
->async
);
482 if (!list_empty(&d
->pcl_queue
)) {
483 PRINT(KERN_ERR
, lynx
->id
, "trying to queue a new packet in nonempty fifo");
487 packet
= driver_packet(d
->queue
.next
);
488 list_move_tail(&packet
->driver_list
, &d
->pcl_queue
);
490 d
->header_dma
= pci_map_single(lynx
->dev
, packet
->header
,
491 packet
->header_size
, PCI_DMA_TODEVICE
);
492 if (packet
->data_size
) {
493 d
->data_dma
= pci_map_single(lynx
->dev
, packet
->data
,
500 pcl
.next
= PCL_NEXT_INVALID
;
501 pcl
.async_error_next
= PCL_NEXT_INVALID
;
503 pcl
.buffer
[0].control
= packet
->speed_code
<< 14 | packet
->header_size
;
505 pcl
.buffer
[0].control
|= PCL_BIGENDIAN
;
507 pcl
.buffer
[0].pointer
= d
->header_dma
;
508 pcl
.buffer
[1].control
= PCL_LAST_BUFF
| packet
->data_size
;
509 pcl
.buffer
[1].pointer
= d
->data_dma
;
511 switch (packet
->type
) {
513 pcl
.buffer
[0].control
|= PCL_CMD_XMT
;
516 pcl
.buffer
[0].control
|= PCL_CMD_XMT
| PCL_ISOMODE
;
519 pcl
.buffer
[0].control
|= PCL_CMD_UNFXMT
;
523 put_pcl(lynx
, d
->pcl
, &pcl
);
524 run_pcl(lynx
, d
->pcl_start
, d
->channel
);
528 /* called from subsystem core */
529 static int lynx_transmit(struct hpsb_host
*host
, struct hpsb_packet
*packet
)
531 struct ti_lynx
*lynx
= host
->hostdata
;
532 struct lynx_send_data
*d
;
535 if (packet
->data_size
>= 4096) {
536 PRINT(KERN_ERR
, lynx
->id
, "transmit packet data too big (%Zd)",
541 switch (packet
->type
) {
550 PRINT(KERN_ERR
, lynx
->id
, "invalid packet type %d",
555 if (packet
->tcode
== TCODE_WRITEQ
556 || packet
->tcode
== TCODE_READQ_RESPONSE
) {
557 cpu_to_be32s(&packet
->header
[3]);
560 spin_lock_irqsave(&d
->queue_lock
, flags
);
562 list_add_tail(&packet
->driver_list
, &d
->queue
);
563 if (list_empty(&d
->pcl_queue
))
564 send_next(lynx
, packet
->type
);
566 spin_unlock_irqrestore(&d
->queue_lock
, flags
);
572 /* called from subsystem core */
573 static int lynx_devctl(struct hpsb_host
*host
, enum devctl_cmd cmd
, int arg
)
575 struct ti_lynx
*lynx
= host
->hostdata
;
577 struct hpsb_packet
*packet
;
578 LIST_HEAD(packet_list
);
584 if (reg_read(lynx
, LINK_INT_STATUS
) & LINK_INT_PHY_BUSRESET
) {
591 if (lynx
->phyic
.reg_1394a
) {
592 phy_reg
= get_phy_reg(lynx
, 5);
594 PRINT(KERN_ERR
, lynx
->id
, "cannot reset bus, because read phy reg failed");
600 PRINT(KERN_INFO
, lynx
->id
, "resetting bus (short bus reset) on request");
602 lynx
->selfid_size
= -1;
604 set_phy_reg(lynx
, 5, phy_reg
); /* set ISBR */
607 PRINT(KERN_INFO
, lynx
->id
, "cannot do short bus reset, because of old phy");
608 /* fall through to long bus reset */
611 phy_reg
= get_phy_reg(lynx
, 1);
613 PRINT(KERN_ERR
, lynx
->id
, "cannot reset bus, because read phy reg failed");
619 PRINT(KERN_INFO
, lynx
->id
, "resetting bus (long bus reset) on request");
621 lynx
->selfid_size
= -1;
623 set_phy_reg(lynx
, 1, phy_reg
); /* clear RHB, set IBR */
625 case SHORT_RESET_NO_FORCE_ROOT
:
626 if (lynx
->phyic
.reg_1394a
) {
627 phy_reg
= get_phy_reg(lynx
, 1);
629 PRINT(KERN_ERR
, lynx
->id
, "cannot reset bus, because read phy reg failed");
633 if (phy_reg
& 0x80) {
635 set_phy_reg(lynx
, 1, phy_reg
); /* clear RHB */
638 phy_reg
= get_phy_reg(lynx
, 5);
640 PRINT(KERN_ERR
, lynx
->id
, "cannot reset bus, because read phy reg failed");
646 PRINT(KERN_INFO
, lynx
->id
, "resetting bus (short bus reset, no force_root) on request");
648 lynx
->selfid_size
= -1;
650 set_phy_reg(lynx
, 5, phy_reg
); /* set ISBR */
653 PRINT(KERN_INFO
, lynx
->id
, "cannot do short bus reset, because of old phy");
654 /* fall through to long bus reset */
656 case LONG_RESET_NO_FORCE_ROOT
:
657 phy_reg
= get_phy_reg(lynx
, 1);
659 PRINT(KERN_ERR
, lynx
->id
, "cannot reset bus, because read phy reg failed");
666 PRINT(KERN_INFO
, lynx
->id
, "resetting bus (long bus reset, no force_root) on request");
668 lynx
->selfid_size
= -1;
670 set_phy_reg(lynx
, 1, phy_reg
); /* clear RHB, set IBR */
672 case SHORT_RESET_FORCE_ROOT
:
673 if (lynx
->phyic
.reg_1394a
) {
674 phy_reg
= get_phy_reg(lynx
, 1);
676 PRINT(KERN_ERR
, lynx
->id
, "cannot reset bus, because read phy reg failed");
680 if (!(phy_reg
& 0x80)) {
682 set_phy_reg(lynx
, 1, phy_reg
); /* set RHB */
685 phy_reg
= get_phy_reg(lynx
, 5);
687 PRINT(KERN_ERR
, lynx
->id
, "cannot reset bus, because read phy reg failed");
693 PRINT(KERN_INFO
, lynx
->id
, "resetting bus (short bus reset, force_root set) on request");
695 lynx
->selfid_size
= -1;
697 set_phy_reg(lynx
, 5, phy_reg
); /* set ISBR */
700 PRINT(KERN_INFO
, lynx
->id
, "cannot do short bus reset, because of old phy");
701 /* fall through to long bus reset */
703 case LONG_RESET_FORCE_ROOT
:
704 phy_reg
= get_phy_reg(lynx
, 1);
706 PRINT(KERN_ERR
, lynx
->id
, "cannot reset bus, because read phy reg failed");
712 PRINT(KERN_INFO
, lynx
->id
, "resetting bus (long bus reset, force_root set) on request");
714 lynx
->selfid_size
= -1;
716 set_phy_reg(lynx
, 1, phy_reg
); /* set IBR and RHB */
719 PRINT(KERN_ERR
, lynx
->id
, "unknown argument for reset_bus command %d", arg
);
725 case GET_CYCLE_COUNTER
:
726 retval
= reg_read(lynx
, CYCLE_TIMER
);
729 case SET_CYCLE_COUNTER
:
730 reg_write(lynx
, CYCLE_TIMER
, arg
);
734 reg_write(lynx
, LINK_ID
,
735 (arg
<< 22) | (reg_read(lynx
, LINK_ID
) & 0x003f0000));
738 case ACT_CYCLE_MASTER
:
740 reg_set_bits(lynx
, LINK_CONTROL
,
741 LINK_CONTROL_CYCMASTER
);
743 reg_clear_bits(lynx
, LINK_CONTROL
,
744 LINK_CONTROL_CYCMASTER
);
748 case CANCEL_REQUESTS
:
749 spin_lock_irqsave(&lynx
->async
.queue_lock
, flags
);
751 reg_write(lynx
, DMA_CHAN_CTRL(CHANNEL_ASYNC_SEND
), 0);
752 list_splice(&lynx
->async
.queue
, &packet_list
);
753 INIT_LIST_HEAD(&lynx
->async
.queue
);
755 if (list_empty(&lynx
->async
.pcl_queue
)) {
756 spin_unlock_irqrestore(&lynx
->async
.queue_lock
, flags
);
757 PRINTD(KERN_DEBUG
, lynx
->id
, "no async packet in PCL to cancel");
761 struct hpsb_packet
*packet
;
763 PRINT(KERN_INFO
, lynx
->id
, "cancelling async packet, that was already in PCL");
765 get_pcl(lynx
, lynx
->async
.pcl
, &pcl
);
767 packet
= driver_packet(lynx
->async
.pcl_queue
.next
);
768 list_del_init(&packet
->driver_list
);
770 pci_unmap_single(lynx
->dev
, lynx
->async
.header_dma
,
771 packet
->header_size
, PCI_DMA_TODEVICE
);
772 if (packet
->data_size
) {
773 pci_unmap_single(lynx
->dev
, lynx
->async
.data_dma
,
774 packet
->data_size
, PCI_DMA_TODEVICE
);
777 spin_unlock_irqrestore(&lynx
->async
.queue_lock
, flags
);
779 if (pcl
.pcl_status
& DMA_CHAN_STAT_PKTCMPL
) {
780 if (pcl
.pcl_status
& DMA_CHAN_STAT_SPECIALACK
) {
781 ack
= (pcl
.pcl_status
>> 15) & 0xf;
782 PRINTD(KERN_INFO
, lynx
->id
, "special ack %d", ack
);
783 ack
= (ack
== 1 ? ACKX_TIMEOUT
: ACKX_SEND_ERROR
);
785 ack
= (pcl
.pcl_status
>> 15) & 0xf;
788 PRINT(KERN_INFO
, lynx
->id
, "async packet was not completed");
791 hpsb_packet_sent(host
, packet
, ack
);
794 while (!list_empty(&packet_list
)) {
795 packet
= driver_packet(packet_list
.next
);
796 list_del_init(&packet
->driver_list
);
797 hpsb_packet_sent(host
, packet
, ACKX_ABORTED
);
802 case ISO_LISTEN_CHANNEL
:
803 spin_lock_irqsave(&lynx
->iso_rcv
.lock
, flags
);
805 if (lynx
->iso_rcv
.chan_count
++ == 0) {
806 reg_write(lynx
, DMA_WORD1_CMP_ENABLE(CHANNEL_ISO_RCV
),
807 DMA_WORD1_CMP_ENABLE_MASTER
);
810 spin_unlock_irqrestore(&lynx
->iso_rcv
.lock
, flags
);
813 case ISO_UNLISTEN_CHANNEL
:
814 spin_lock_irqsave(&lynx
->iso_rcv
.lock
, flags
);
816 if (--lynx
->iso_rcv
.chan_count
== 0) {
817 reg_write(lynx
, DMA_WORD1_CMP_ENABLE(CHANNEL_ISO_RCV
),
821 spin_unlock_irqrestore(&lynx
->iso_rcv
.lock
, flags
);
825 PRINT(KERN_ERR
, lynx
->id
, "unknown devctl command %d", cmd
);
833 /***************************************
834 * IEEE-1394 functionality section END *
835 ***************************************/
837 #ifdef CONFIG_IEEE1394_PCILYNX_PORTS
838 /* VFS functions for local bus / aux device access. Access to those
839 * is implemented as a character device instead of block devices
840 * because buffers are not wanted for this. Therefore llseek (from
841 * VFS) can be used for these char devices with obvious effects.
843 static int mem_open(struct inode
*, struct file
*);
844 static int mem_release(struct inode
*, struct file
*);
845 static unsigned int aux_poll(struct file
*, struct poll_table_struct
*);
846 static loff_t
mem_llseek(struct file
*, loff_t
, int);
847 static ssize_t
mem_read (struct file
*, char*, size_t, loff_t
*);
848 static ssize_t
mem_write(struct file
*, const char*, size_t, loff_t
*);
851 static struct file_operations aux_ops
= {
852 .owner
= THIS_MODULE
,
856 .llseek
= mem_llseek
,
858 .release
= mem_release
,
862 static void aux_setup_pcls(struct ti_lynx
*lynx
)
866 pcl
.next
= PCL_NEXT_INVALID
;
867 pcl
.user_data
= pcl_bus(lynx
, lynx
->dmem_pcl
);
868 put_pcl(lynx
, lynx
->dmem_pcl
, &pcl
);
871 static int mem_open(struct inode
*inode
, struct file
*file
)
873 int cid
= iminor(inode
);
874 enum { t_rom
, t_aux
, t_ram
} type
;
877 if (cid
< PCILYNX_MINOR_AUX_START
) {
878 /* just for completeness */
880 } else if (cid
< PCILYNX_MINOR_ROM_START
) {
881 cid
-= PCILYNX_MINOR_AUX_START
;
882 if (cid
>= num_of_cards
|| !cards
[cid
].aux_port
)
885 } else if (cid
< PCILYNX_MINOR_RAM_START
) {
886 cid
-= PCILYNX_MINOR_ROM_START
;
887 if (cid
>= num_of_cards
|| !cards
[cid
].local_rom
)
891 /* WARNING: Know what you are doing when opening RAM.
892 * It is currently used inside the driver! */
893 cid
-= PCILYNX_MINOR_RAM_START
;
894 if (cid
>= num_of_cards
|| !cards
[cid
].local_ram
)
899 md
= (struct memdata
*)kmalloc(sizeof(struct memdata
), SLAB_KERNEL
);
903 md
->lynx
= &cards
[cid
];
914 atomic_set(&md
->aux_intr_last_seen
,
915 atomic_read(&cards
[cid
].aux_intr_seen
));
920 file
->private_data
= md
;
925 static int mem_release(struct inode
*inode
, struct file
*file
)
927 kfree(file
->private_data
);
931 static unsigned int aux_poll(struct file
*file
, poll_table
*pt
)
933 struct memdata
*md
= (struct memdata
*)file
->private_data
;
937 /* reading and writing is always allowed */
938 mask
= POLLIN
| POLLRDNORM
| POLLOUT
| POLLWRNORM
;
940 if (md
->type
== aux
) {
941 poll_wait(file
, &cards
[cid
].aux_intr_wait
, pt
);
943 if (atomic_read(&md
->aux_intr_last_seen
)
944 != atomic_read(&cards
[cid
].aux_intr_seen
)) {
946 atomic_inc(&md
->aux_intr_last_seen
);
953 loff_t
mem_llseek(struct file
*file
, loff_t offs
, int orig
)
962 newoffs
= offs
+ file
->f_pos
;
965 newoffs
= PCILYNX_MAX_MEMORY
+ 1 + offs
;
971 if (newoffs
< 0 || newoffs
> PCILYNX_MAX_MEMORY
+ 1) return -EINVAL
;
973 file
->f_pos
= newoffs
;
978 * do not DMA if count is too small because this will have a serious impact
979 * on performance - the value 2400 was found by experiment and may not work
980 * everywhere as good as here - use mem_mindma option for modules to change
982 static short mem_mindma
= 2400;
983 module_param(mem_mindma
, short, 0444);
984 MODULE_PARM_DESC(mem_mindma
, "Minimum amount of data required to use DMA");
986 static ssize_t
mem_dmaread(struct memdata
*md
, u32 physbuf
, ssize_t count
,
993 DECLARE_WAITQUEUE(wait
, current
);
996 count
= min(count
, 53196);
999 if (reg_read(md
->lynx
, DMA_CHAN_CTRL(CHANNEL_LOCALBUS
))
1000 & DMA_CHAN_CTRL_BUSY
) {
1001 PRINT(KERN_WARNING
, md
->lynx
->id
, "DMA ALREADY ACTIVE!");
1004 reg_write(md
->lynx
, LBUS_ADDR
, md
->type
| offset
);
1006 pcl
= edit_pcl(md
->lynx
, md
->lynx
->dmem_pcl
, &pcltmp
);
1007 pcl
->buffer
[0].control
= PCL_CMD_LBUS_TO_PCI
| min(count
, 4092);
1008 pcl
->buffer
[0].pointer
= physbuf
;
1014 pcl
->buffer
[i
].control
= min(count
, 4092);
1015 pcl
->buffer
[i
].pointer
= physbuf
+ i
* 4092;
1018 pcl
->buffer
[i
].control
|= PCL_LAST_BUFF
;
1019 commit_pcl(md
->lynx
, md
->lynx
->dmem_pcl
, &pcltmp
);
1021 set_current_state(TASK_INTERRUPTIBLE
);
1022 add_wait_queue(&md
->lynx
->mem_dma_intr_wait
, &wait
);
1023 run_sub_pcl(md
->lynx
, md
->lynx
->dmem_pcl
, 2, CHANNEL_LOCALBUS
);
1026 while (reg_read(md
->lynx
, DMA_CHAN_CTRL(CHANNEL_LOCALBUS
))
1027 & DMA_CHAN_CTRL_BUSY
) {
1028 if (signal_pending(current
)) {
1035 reg_write(md
->lynx
, DMA_CHAN_CTRL(CHANNEL_LOCALBUS
), 0);
1036 remove_wait_queue(&md
->lynx
->mem_dma_intr_wait
, &wait
);
1038 if (reg_read(md
->lynx
, DMA_CHAN_CTRL(CHANNEL_LOCALBUS
))
1039 & DMA_CHAN_CTRL_BUSY
) {
1040 PRINT(KERN_ERR
, md
->lynx
->id
, "DMA STILL ACTIVE!");
1046 static ssize_t
mem_read(struct file
*file
, char *buffer
, size_t count
,
1049 struct memdata
*md
= (struct memdata
*)file
->private_data
;
1052 loff_t off
= *offset
; /* avoid useless 64bit-arithmetic */
1056 if ((off
+ count
) > PCILYNX_MAX_MEMORY
+1) {
1057 count
= PCILYNX_MAX_MEMORY
+1 - off
;
1059 if (count
== 0 || off
> PCILYNX_MAX_MEMORY
) {
1065 membase
= md
->lynx
->local_rom
;
1068 membase
= md
->lynx
->local_ram
;
1071 membase
= md
->lynx
->aux_port
;
1074 panic("pcilynx%d: unsupported md->type %d in %s",
1075 md
->lynx
->id
, md
->type
, __FUNCTION__
);
1078 down(&md
->lynx
->mem_dma_mutex
);
1080 if (count
< mem_mindma
) {
1081 memcpy_fromio(md
->lynx
->mem_dma_buffer
, membase
+off
, count
);
1086 alignfix
= 4 - (off
% 4);
1087 if (alignfix
!= 4) {
1088 if (bcount
< alignfix
) {
1091 memcpy_fromio(md
->lynx
->mem_dma_buffer
, membase
+off
,
1093 if (bcount
== alignfix
) {
1100 while (bcount
>= 4) {
1101 retval
= mem_dmaread(md
, md
->lynx
->mem_dma_buffer_dma
1102 + count
- bcount
, bcount
, off
);
1103 if (retval
< 0) return retval
;
1110 memcpy_fromio(md
->lynx
->mem_dma_buffer
+ count
- bcount
,
1111 membase
+off
, bcount
);
1115 retval
= copy_to_user(buffer
, md
->lynx
->mem_dma_buffer
, count
);
1116 up(&md
->lynx
->mem_dma_mutex
);
1118 if (retval
) return -EFAULT
;
1124 static ssize_t
mem_write(struct file
*file
, const char *buffer
, size_t count
,
1127 struct memdata
*md
= (struct memdata
*)file
->private_data
;
1129 if (((*offset
) + count
) > PCILYNX_MAX_MEMORY
+1) {
1130 count
= PCILYNX_MAX_MEMORY
+1 - *offset
;
1132 if (count
== 0 || *offset
> PCILYNX_MAX_MEMORY
) {
1136 /* FIXME: dereferencing pointers to PCI mem doesn't work everywhere */
1139 if (copy_from_user(md
->lynx
->aux_port
+(*offset
), buffer
, count
))
1143 if (copy_from_user(md
->lynx
->local_ram
+(*offset
), buffer
, count
))
1147 /* the ROM may be writeable */
1148 if (copy_from_user(md
->lynx
->local_rom
+(*offset
), buffer
, count
))
1153 file
->f_pos
+= count
;
1156 #endif /* CONFIG_IEEE1394_PCILYNX_PORTS */
1159 /********************************************************
1160 * Global stuff (interrupt handler, init/shutdown code) *
1161 ********************************************************/
1164 static irqreturn_t
lynx_irq_handler(int irq
, void *dev_id
,
1165 struct pt_regs
*regs_are_unused
)
1167 struct ti_lynx
*lynx
= (struct ti_lynx
*)dev_id
;
1168 struct hpsb_host
*host
= lynx
->host
;
1172 linkint
= reg_read(lynx
, LINK_INT_STATUS
);
1173 intmask
= reg_read(lynx
, PCI_INT_STATUS
);
1175 if (!(intmask
& PCI_INT_INT_PEND
))
1178 PRINTD(KERN_DEBUG
, lynx
->id
, "interrupt: 0x%08x / 0x%08x", intmask
,
1181 reg_write(lynx
, LINK_INT_STATUS
, linkint
);
1182 reg_write(lynx
, PCI_INT_STATUS
, intmask
);
1184 #ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1185 if (intmask
& PCI_INT_AUX_INT
) {
1186 atomic_inc(&lynx
->aux_intr_seen
);
1187 wake_up_interruptible(&lynx
->aux_intr_wait
);
1190 if (intmask
& PCI_INT_DMA_HLT(CHANNEL_LOCALBUS
)) {
1191 wake_up_interruptible(&lynx
->mem_dma_intr_wait
);
1196 if (intmask
& PCI_INT_1394
) {
1197 if (linkint
& LINK_INT_PHY_TIMEOUT
) {
1198 PRINT(KERN_INFO
, lynx
->id
, "PHY timeout occurred");
1200 if (linkint
& LINK_INT_PHY_BUSRESET
) {
1201 PRINT(KERN_INFO
, lynx
->id
, "bus reset interrupt");
1202 lynx
->selfid_size
= -1;
1203 lynx
->phy_reg0
= -1;
1204 if (!host
->in_bus_reset
)
1205 hpsb_bus_reset(host
);
1207 if (linkint
& LINK_INT_PHY_REG_RCVD
) {
1210 spin_lock(&lynx
->phy_reg_lock
);
1211 reg
= reg_read(lynx
, LINK_PHY
);
1212 spin_unlock(&lynx
->phy_reg_lock
);
1214 if (!host
->in_bus_reset
) {
1215 PRINT(KERN_INFO
, lynx
->id
,
1216 "phy reg received without reset");
1217 } else if (reg
& 0xf00) {
1218 PRINT(KERN_INFO
, lynx
->id
,
1219 "unsolicited phy reg %d received",
1222 lynx
->phy_reg0
= reg
& 0xff;
1223 handle_selfid(lynx
, host
);
1226 if (linkint
& LINK_INT_ISO_STUCK
) {
1227 PRINT(KERN_INFO
, lynx
->id
, "isochronous transmitter stuck");
1229 if (linkint
& LINK_INT_ASYNC_STUCK
) {
1230 PRINT(KERN_INFO
, lynx
->id
, "asynchronous transmitter stuck");
1232 if (linkint
& LINK_INT_SENT_REJECT
) {
1233 PRINT(KERN_INFO
, lynx
->id
, "sent reject");
1235 if (linkint
& LINK_INT_TX_INVALID_TC
) {
1236 PRINT(KERN_INFO
, lynx
->id
, "invalid transaction code");
1238 if (linkint
& LINK_INT_GRF_OVERFLOW
) {
1239 /* flush FIFO if overflow happens during reset */
1240 if (host
->in_bus_reset
)
1241 reg_write(lynx
, FIFO_CONTROL
,
1242 FIFO_CONTROL_GRF_FLUSH
);
1243 PRINT(KERN_INFO
, lynx
->id
, "GRF overflow");
1245 if (linkint
& LINK_INT_ITF_UNDERFLOW
) {
1246 PRINT(KERN_INFO
, lynx
->id
, "ITF underflow");
1248 if (linkint
& LINK_INT_ATF_UNDERFLOW
) {
1249 PRINT(KERN_INFO
, lynx
->id
, "ATF underflow");
1253 if (intmask
& PCI_INT_DMA_HLT(CHANNEL_ISO_RCV
)) {
1254 PRINTD(KERN_DEBUG
, lynx
->id
, "iso receive");
1256 spin_lock(&lynx
->iso_rcv
.lock
);
1258 lynx
->iso_rcv
.stat
[lynx
->iso_rcv
.next
] =
1259 reg_read(lynx
, DMA_CHAN_STAT(CHANNEL_ISO_RCV
));
1261 lynx
->iso_rcv
.used
++;
1262 lynx
->iso_rcv
.next
= (lynx
->iso_rcv
.next
+ 1) % NUM_ISORCV_PCL
;
1264 if ((lynx
->iso_rcv
.next
== lynx
->iso_rcv
.last
)
1265 || !lynx
->iso_rcv
.chan_count
) {
1266 PRINTD(KERN_DEBUG
, lynx
->id
, "stopped");
1267 reg_write(lynx
, DMA_WORD1_CMP_ENABLE(CHANNEL_ISO_RCV
), 0);
1270 run_sub_pcl(lynx
, lynx
->iso_rcv
.pcl_start
, lynx
->iso_rcv
.next
,
1273 spin_unlock(&lynx
->iso_rcv
.lock
);
1275 tasklet_schedule(&lynx
->iso_rcv
.tq
);
1278 if (intmask
& PCI_INT_DMA_HLT(CHANNEL_ASYNC_SEND
)) {
1279 PRINTD(KERN_DEBUG
, lynx
->id
, "async sent");
1280 spin_lock(&lynx
->async
.queue_lock
);
1282 if (list_empty(&lynx
->async
.pcl_queue
)) {
1283 spin_unlock(&lynx
->async
.queue_lock
);
1284 PRINT(KERN_WARNING
, lynx
->id
, "async dma halted, but no queued packet (maybe it was cancelled)");
1288 struct hpsb_packet
*packet
;
1290 get_pcl(lynx
, lynx
->async
.pcl
, &pcl
);
1292 packet
= driver_packet(lynx
->async
.pcl_queue
.next
);
1293 list_del_init(&packet
->driver_list
);
1295 pci_unmap_single(lynx
->dev
, lynx
->async
.header_dma
,
1296 packet
->header_size
, PCI_DMA_TODEVICE
);
1297 if (packet
->data_size
) {
1298 pci_unmap_single(lynx
->dev
, lynx
->async
.data_dma
,
1299 packet
->data_size
, PCI_DMA_TODEVICE
);
1302 if (!list_empty(&lynx
->async
.queue
)) {
1303 send_next(lynx
, hpsb_async
);
1306 spin_unlock(&lynx
->async
.queue_lock
);
1308 if (pcl
.pcl_status
& DMA_CHAN_STAT_PKTCMPL
) {
1309 if (pcl
.pcl_status
& DMA_CHAN_STAT_SPECIALACK
) {
1310 ack
= (pcl
.pcl_status
>> 15) & 0xf;
1311 PRINTD(KERN_INFO
, lynx
->id
, "special ack %d", ack
);
1312 ack
= (ack
== 1 ? ACKX_TIMEOUT
: ACKX_SEND_ERROR
);
1314 ack
= (pcl
.pcl_status
>> 15) & 0xf;
1317 PRINT(KERN_INFO
, lynx
->id
, "async packet was not completed");
1318 ack
= ACKX_SEND_ERROR
;
1320 hpsb_packet_sent(host
, packet
, ack
);
1324 if (intmask
& PCI_INT_DMA_HLT(CHANNEL_ISO_SEND
)) {
1325 PRINTD(KERN_DEBUG
, lynx
->id
, "iso sent");
1326 spin_lock(&lynx
->iso_send
.queue_lock
);
1328 if (list_empty(&lynx
->iso_send
.pcl_queue
)) {
1329 spin_unlock(&lynx
->iso_send
.queue_lock
);
1330 PRINT(KERN_ERR
, lynx
->id
, "iso send dma halted, but no queued packet");
1334 struct hpsb_packet
*packet
;
1336 get_pcl(lynx
, lynx
->iso_send
.pcl
, &pcl
);
1338 packet
= driver_packet(lynx
->iso_send
.pcl_queue
.next
);
1339 list_del_init(&packet
->driver_list
);
1341 pci_unmap_single(lynx
->dev
, lynx
->iso_send
.header_dma
,
1342 packet
->header_size
, PCI_DMA_TODEVICE
);
1343 if (packet
->data_size
) {
1344 pci_unmap_single(lynx
->dev
, lynx
->iso_send
.data_dma
,
1345 packet
->data_size
, PCI_DMA_TODEVICE
);
1348 if (!list_empty(&lynx
->iso_send
.queue
)) {
1349 send_next(lynx
, hpsb_iso
);
1352 spin_unlock(&lynx
->iso_send
.queue_lock
);
1354 if (pcl
.pcl_status
& DMA_CHAN_STAT_PKTCMPL
) {
1355 if (pcl
.pcl_status
& DMA_CHAN_STAT_SPECIALACK
) {
1356 ack
= (pcl
.pcl_status
>> 15) & 0xf;
1357 PRINTD(KERN_INFO
, lynx
->id
, "special ack %d", ack
);
1358 ack
= (ack
== 1 ? ACKX_TIMEOUT
: ACKX_SEND_ERROR
);
1360 ack
= (pcl
.pcl_status
>> 15) & 0xf;
1363 PRINT(KERN_INFO
, lynx
->id
, "iso send packet was not completed");
1364 ack
= ACKX_SEND_ERROR
;
1367 hpsb_packet_sent(host
, packet
, ack
); //FIXME: maybe we should just use ACK_COMPLETE and ACKX_SEND_ERROR
1371 if (intmask
& PCI_INT_DMA_HLT(CHANNEL_ASYNC_RCV
)) {
1372 /* general receive DMA completed */
1373 int stat
= reg_read(lynx
, DMA_CHAN_STAT(CHANNEL_ASYNC_RCV
));
1375 PRINTD(KERN_DEBUG
, lynx
->id
, "received packet size %d",
1378 if (stat
& DMA_CHAN_STAT_SELFID
) {
1379 lynx
->selfid_size
= stat
& 0x1fff;
1380 handle_selfid(lynx
, host
);
1382 quadlet_t
*q_data
= lynx
->rcv_page
;
1383 if ((*q_data
>> 4 & 0xf) == TCODE_READQ_RESPONSE
1384 || (*q_data
>> 4 & 0xf) == TCODE_WRITEQ
) {
1385 cpu_to_be32s(q_data
+ 3);
1387 hpsb_packet_received(host
, q_data
, stat
& 0x1fff, 0);
1390 run_pcl(lynx
, lynx
->rcv_pcl_start
, CHANNEL_ASYNC_RCV
);
1397 static void iso_rcv_bh(struct ti_lynx
*lynx
)
1401 unsigned long flags
;
1403 spin_lock_irqsave(&lynx
->iso_rcv
.lock
, flags
);
1405 while (lynx
->iso_rcv
.used
) {
1406 idx
= lynx
->iso_rcv
.last
;
1407 spin_unlock_irqrestore(&lynx
->iso_rcv
.lock
, flags
);
1409 data
= lynx
->iso_rcv
.page
[idx
/ ISORCV_PER_PAGE
]
1410 + (idx
% ISORCV_PER_PAGE
) * MAX_ISORCV_SIZE
;
1412 if ((*data
>> 16) + 4 != (lynx
->iso_rcv
.stat
[idx
] & 0x1fff)) {
1413 PRINT(KERN_ERR
, lynx
->id
,
1414 "iso length mismatch 0x%08x/0x%08x", *data
,
1415 lynx
->iso_rcv
.stat
[idx
]);
1418 if (lynx
->iso_rcv
.stat
[idx
]
1419 & (DMA_CHAN_STAT_PCIERR
| DMA_CHAN_STAT_PKTERR
)) {
1420 PRINT(KERN_INFO
, lynx
->id
,
1421 "iso receive error on %d to 0x%p", idx
, data
);
1423 hpsb_packet_received(lynx
->host
, data
,
1424 lynx
->iso_rcv
.stat
[idx
] & 0x1fff,
1428 spin_lock_irqsave(&lynx
->iso_rcv
.lock
, flags
);
1429 lynx
->iso_rcv
.last
= (idx
+ 1) % NUM_ISORCV_PCL
;
1430 lynx
->iso_rcv
.used
--;
1433 if (lynx
->iso_rcv
.chan_count
) {
1434 reg_write(lynx
, DMA_WORD1_CMP_ENABLE(CHANNEL_ISO_RCV
),
1435 DMA_WORD1_CMP_ENABLE_MASTER
);
1437 spin_unlock_irqrestore(&lynx
->iso_rcv
.lock
, flags
);
1441 static void remove_card(struct pci_dev
*dev
)
1443 struct ti_lynx
*lynx
;
1444 struct device
*lynx_dev
;
1447 lynx
= pci_get_drvdata(dev
);
1449 pci_set_drvdata(dev
, NULL
);
1451 lynx_dev
= get_device(&lynx
->host
->device
);
1453 switch (lynx
->state
) {
1455 reg_write(lynx
, PCI_INT_ENABLE
, 0);
1456 hpsb_remove_host(lynx
->host
);
1458 reg_write(lynx
, PCI_INT_ENABLE
, 0);
1459 free_irq(lynx
->dev
->irq
, lynx
);
1461 /* Disable IRM Contender and LCtrl */
1462 if (lynx
->phyic
.reg_1394a
)
1463 set_phy_reg(lynx
, 4, ~0xc0 & get_phy_reg(lynx
, 4));
1465 /* Let all other nodes know to ignore us */
1466 lynx_devctl(lynx
->host
, RESET_BUS
, LONG_RESET_NO_FORCE_ROOT
);
1468 case have_iomappings
:
1469 reg_set_bits(lynx
, MISC_CONTROL
, MISC_CONTROL_SWRESET
);
1470 /* Fix buggy cards with autoboot pin not tied low: */
1471 reg_write(lynx
, DMA0_CHAN_CTRL
, 0);
1472 iounmap(lynx
->registers
);
1473 iounmap(lynx
->local_rom
);
1474 iounmap(lynx
->local_ram
);
1475 iounmap(lynx
->aux_port
);
1476 case have_1394_buffers
:
1477 for (i
= 0; i
< ISORCV_PAGES
; i
++) {
1478 if (lynx
->iso_rcv
.page
[i
]) {
1479 pci_free_consistent(lynx
->dev
, PAGE_SIZE
,
1480 lynx
->iso_rcv
.page
[i
],
1481 lynx
->iso_rcv
.page_dma
[i
]);
1484 pci_free_consistent(lynx
->dev
, PAGE_SIZE
, lynx
->rcv_page
,
1485 lynx
->rcv_page_dma
);
1487 #ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1488 pci_free_consistent(lynx
->dev
, 65536, lynx
->mem_dma_buffer
,
1489 lynx
->mem_dma_buffer_dma
);
1492 #ifndef CONFIG_IEEE1394_PCILYNX_LOCALRAM
1493 pci_free_consistent(lynx
->dev
, LOCALRAM_SIZE
, lynx
->pcl_mem
,
1497 /* do nothing - already freed */
1501 tasklet_kill(&lynx
->iso_rcv
.tq
);
1504 put_device(lynx_dev
);
1508 static int __devinit
add_card(struct pci_dev
*dev
,
1509 const struct pci_device_id
*devid_is_unused
)
1511 #define FAIL(fmt, args...) do { \
1512 PRINT_G(KERN_ERR, fmt , ## args); \
1518 struct hpsb_host
*host
;
1519 struct ti_lynx
*lynx
; /* shortcut to currently handled device */
1527 if (pci_set_dma_mask(dev
, 0xffffffff))
1528 FAIL("DMA address limits not supported for PCILynx hardware");
1529 if (pci_enable_device(dev
))
1530 FAIL("failed to enable PCILynx hardware");
1531 pci_set_master(dev
);
1535 host
= hpsb_alloc_host(&lynx_driver
, sizeof(struct ti_lynx
), &dev
->dev
);
1536 if (!host
) FAIL("failed to allocate control structure memory");
1538 lynx
= host
->hostdata
;
1539 lynx
->id
= card_id
++;
1541 lynx
->state
= clear
;
1544 pci_set_drvdata(dev
, lynx
);
1546 spin_lock_init(&lynx
->lock
);
1547 spin_lock_init(&lynx
->phy_reg_lock
);
1549 #ifndef CONFIG_IEEE1394_PCILYNX_LOCALRAM
1550 lynx
->pcl_mem
= pci_alloc_consistent(dev
, LOCALRAM_SIZE
,
1551 &lynx
->pcl_mem_dma
);
1553 if (lynx
->pcl_mem
!= NULL
) {
1554 lynx
->state
= have_pcl_mem
;
1555 PRINT(KERN_INFO
, lynx
->id
,
1556 "allocated PCL memory %d Bytes @ 0x%p", LOCALRAM_SIZE
,
1559 FAIL("failed to allocate PCL memory area");
1563 #ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1564 lynx
->mem_dma_buffer
= pci_alloc_consistent(dev
, 65536,
1565 &lynx
->mem_dma_buffer_dma
);
1566 if (lynx
->mem_dma_buffer
== NULL
) {
1567 FAIL("failed to allocate DMA buffer for aux");
1569 lynx
->state
= have_aux_buf
;
1572 lynx
->rcv_page
= pci_alloc_consistent(dev
, PAGE_SIZE
,
1573 &lynx
->rcv_page_dma
);
1574 if (lynx
->rcv_page
== NULL
) {
1575 FAIL("failed to allocate receive buffer");
1577 lynx
->state
= have_1394_buffers
;
1579 for (i
= 0; i
< ISORCV_PAGES
; i
++) {
1580 lynx
->iso_rcv
.page
[i
] =
1581 pci_alloc_consistent(dev
, PAGE_SIZE
,
1582 &lynx
->iso_rcv
.page_dma
[i
]);
1583 if (lynx
->iso_rcv
.page
[i
] == NULL
) {
1584 FAIL("failed to allocate iso receive buffers");
1588 lynx
->registers
= ioremap_nocache(pci_resource_start(dev
,0),
1589 PCILYNX_MAX_REGISTER
);
1590 lynx
->local_ram
= ioremap(pci_resource_start(dev
,1), PCILYNX_MAX_MEMORY
);
1591 lynx
->aux_port
= ioremap(pci_resource_start(dev
,2), PCILYNX_MAX_MEMORY
);
1592 lynx
->local_rom
= ioremap(pci_resource_start(dev
,PCI_ROM_RESOURCE
),
1593 PCILYNX_MAX_MEMORY
);
1594 lynx
->state
= have_iomappings
;
1596 if (lynx
->registers
== NULL
) {
1597 FAIL("failed to remap registers - card not accessible");
1600 #ifdef CONFIG_IEEE1394_PCILYNX_LOCALRAM
1601 if (lynx
->local_ram
== NULL
) {
1602 FAIL("failed to remap local RAM which is required for "
1607 reg_set_bits(lynx
, MISC_CONTROL
, MISC_CONTROL_SWRESET
);
1608 /* Fix buggy cards with autoboot pin not tied low: */
1609 reg_write(lynx
, DMA0_CHAN_CTRL
, 0);
1612 sprintf (irq_buf
, "%d", dev
->irq
);
1614 sprintf (irq_buf
, "%s", __irq_itoa(dev
->irq
));
1617 if (!request_irq(dev
->irq
, lynx_irq_handler
, SA_SHIRQ
,
1618 PCILYNX_DRIVER_NAME
, lynx
)) {
1619 PRINT(KERN_INFO
, lynx
->id
, "allocated interrupt %s", irq_buf
);
1620 lynx
->state
= have_intr
;
1622 FAIL("failed to allocate shared interrupt %s", irq_buf
);
1625 /* alloc_pcl return values are not checked, it is expected that the
1626 * provided PCL space is sufficient for the initial allocations */
1627 #ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1628 if (lynx
->aux_port
!= NULL
) {
1629 lynx
->dmem_pcl
= alloc_pcl(lynx
);
1630 aux_setup_pcls(lynx
);
1631 sema_init(&lynx
->mem_dma_mutex
, 1);
1634 lynx
->rcv_pcl
= alloc_pcl(lynx
);
1635 lynx
->rcv_pcl_start
= alloc_pcl(lynx
);
1636 lynx
->async
.pcl
= alloc_pcl(lynx
);
1637 lynx
->async
.pcl_start
= alloc_pcl(lynx
);
1638 lynx
->iso_send
.pcl
= alloc_pcl(lynx
);
1639 lynx
->iso_send
.pcl_start
= alloc_pcl(lynx
);
1641 for (i
= 0; i
< NUM_ISORCV_PCL
; i
++) {
1642 lynx
->iso_rcv
.pcl
[i
] = alloc_pcl(lynx
);
1644 lynx
->iso_rcv
.pcl_start
= alloc_pcl(lynx
);
1646 /* all allocations successful - simple init stuff follows */
1648 reg_write(lynx
, PCI_INT_ENABLE
, PCI_INT_DMA_ALL
);
1650 #ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1651 reg_set_bits(lynx
, PCI_INT_ENABLE
, PCI_INT_AUX_INT
);
1652 init_waitqueue_head(&lynx
->mem_dma_intr_wait
);
1653 init_waitqueue_head(&lynx
->aux_intr_wait
);
1656 tasklet_init(&lynx
->iso_rcv
.tq
, (void (*)(unsigned long))iso_rcv_bh
,
1657 (unsigned long)lynx
);
1659 spin_lock_init(&lynx
->iso_rcv
.lock
);
1661 spin_lock_init(&lynx
->async
.queue_lock
);
1662 lynx
->async
.channel
= CHANNEL_ASYNC_SEND
;
1663 spin_lock_init(&lynx
->iso_send
.queue_lock
);
1664 lynx
->iso_send
.channel
= CHANNEL_ISO_SEND
;
1666 PRINT(KERN_INFO
, lynx
->id
, "remapped memory spaces reg 0x%p, rom 0x%p, "
1667 "ram 0x%p, aux 0x%p", lynx
->registers
, lynx
->local_rom
,
1668 lynx
->local_ram
, lynx
->aux_port
);
1670 /* now, looking for PHY register set */
1671 if ((get_phy_reg(lynx
, 2) & 0xe0) == 0xe0) {
1672 lynx
->phyic
.reg_1394a
= 1;
1673 PRINT(KERN_INFO
, lynx
->id
,
1674 "found 1394a conform PHY (using extended register set)");
1675 lynx
->phyic
.vendor
= get_phy_vendorid(lynx
);
1676 lynx
->phyic
.product
= get_phy_productid(lynx
);
1678 lynx
->phyic
.reg_1394a
= 0;
1679 PRINT(KERN_INFO
, lynx
->id
, "found old 1394 PHY");
1682 lynx
->selfid_size
= -1;
1683 lynx
->phy_reg0
= -1;
1685 INIT_LIST_HEAD(&lynx
->async
.queue
);
1686 INIT_LIST_HEAD(&lynx
->async
.pcl_queue
);
1687 INIT_LIST_HEAD(&lynx
->iso_send
.queue
);
1688 INIT_LIST_HEAD(&lynx
->iso_send
.pcl_queue
);
1690 pcl
.next
= pcl_bus(lynx
, lynx
->rcv_pcl
);
1691 put_pcl(lynx
, lynx
->rcv_pcl_start
, &pcl
);
1693 pcl
.next
= PCL_NEXT_INVALID
;
1694 pcl
.async_error_next
= PCL_NEXT_INVALID
;
1696 pcl
.buffer
[0].control
= PCL_CMD_RCV
| 16;
1697 #ifndef __BIG_ENDIAN
1698 pcl
.buffer
[0].control
|= PCL_BIGENDIAN
;
1700 pcl
.buffer
[1].control
= PCL_LAST_BUFF
| 4080;
1702 pcl
.buffer
[0].pointer
= lynx
->rcv_page_dma
;
1703 pcl
.buffer
[1].pointer
= lynx
->rcv_page_dma
+ 16;
1704 put_pcl(lynx
, lynx
->rcv_pcl
, &pcl
);
1706 pcl
.next
= pcl_bus(lynx
, lynx
->async
.pcl
);
1707 pcl
.async_error_next
= pcl_bus(lynx
, lynx
->async
.pcl
);
1708 put_pcl(lynx
, lynx
->async
.pcl_start
, &pcl
);
1710 pcl
.next
= pcl_bus(lynx
, lynx
->iso_send
.pcl
);
1711 pcl
.async_error_next
= PCL_NEXT_INVALID
;
1712 put_pcl(lynx
, lynx
->iso_send
.pcl_start
, &pcl
);
1714 pcl
.next
= PCL_NEXT_INVALID
;
1715 pcl
.async_error_next
= PCL_NEXT_INVALID
;
1716 pcl
.buffer
[0].control
= PCL_CMD_RCV
| 4;
1717 #ifndef __BIG_ENDIAN
1718 pcl
.buffer
[0].control
|= PCL_BIGENDIAN
;
1720 pcl
.buffer
[1].control
= PCL_LAST_BUFF
| 2044;
1722 for (i
= 0; i
< NUM_ISORCV_PCL
; i
++) {
1723 int page
= i
/ ISORCV_PER_PAGE
;
1724 int sec
= i
% ISORCV_PER_PAGE
;
1726 pcl
.buffer
[0].pointer
= lynx
->iso_rcv
.page_dma
[page
]
1727 + sec
* MAX_ISORCV_SIZE
;
1728 pcl
.buffer
[1].pointer
= pcl
.buffer
[0].pointer
+ 4;
1729 put_pcl(lynx
, lynx
->iso_rcv
.pcl
[i
], &pcl
);
1733 for (i
= 0; i
< NUM_ISORCV_PCL
; i
++) {
1734 pcli
[i
] = pcl_bus(lynx
, lynx
->iso_rcv
.pcl
[i
]);
1736 put_pcl(lynx
, lynx
->iso_rcv
.pcl_start
, &pcl
);
1738 /* FIFO sizes from left to right: ITF=48 ATF=48 GRF=160 */
1739 reg_write(lynx
, FIFO_SIZES
, 0x003030a0);
1740 /* 20 byte threshold before triggering PCI transfer */
1741 reg_write(lynx
, DMA_GLOBAL_REGISTER
, 0x2<<24);
1742 /* threshold on both send FIFOs before transmitting:
1743 FIFO size - cache line size - 1 */
1744 i
= reg_read(lynx
, PCI_LATENCY_CACHELINE
) & 0xff;
1746 reg_write(lynx
, FIFO_XMIT_THRESHOLD
, (i
<< 8) | i
);
1748 reg_set_bits(lynx
, PCI_INT_ENABLE
, PCI_INT_1394
);
1750 reg_write(lynx
, LINK_INT_ENABLE
, LINK_INT_PHY_TIMEOUT
1751 | LINK_INT_PHY_REG_RCVD
| LINK_INT_PHY_BUSRESET
1752 | LINK_INT_ISO_STUCK
| LINK_INT_ASYNC_STUCK
1753 | LINK_INT_SENT_REJECT
| LINK_INT_TX_INVALID_TC
1754 | LINK_INT_GRF_OVERFLOW
| LINK_INT_ITF_UNDERFLOW
1755 | LINK_INT_ATF_UNDERFLOW
);
1757 reg_write(lynx
, DMA_WORD0_CMP_VALUE(CHANNEL_ASYNC_RCV
), 0);
1758 reg_write(lynx
, DMA_WORD0_CMP_ENABLE(CHANNEL_ASYNC_RCV
), 0xa<<4);
1759 reg_write(lynx
, DMA_WORD1_CMP_VALUE(CHANNEL_ASYNC_RCV
), 0);
1760 reg_write(lynx
, DMA_WORD1_CMP_ENABLE(CHANNEL_ASYNC_RCV
),
1761 DMA_WORD1_CMP_MATCH_LOCAL_NODE
| DMA_WORD1_CMP_MATCH_BROADCAST
1762 | DMA_WORD1_CMP_MATCH_EXACT
| DMA_WORD1_CMP_MATCH_BUS_BCAST
1763 | DMA_WORD1_CMP_ENABLE_SELF_ID
| DMA_WORD1_CMP_ENABLE_MASTER
);
1765 run_pcl(lynx
, lynx
->rcv_pcl_start
, CHANNEL_ASYNC_RCV
);
1767 reg_write(lynx
, DMA_WORD0_CMP_VALUE(CHANNEL_ISO_RCV
), 0);
1768 reg_write(lynx
, DMA_WORD0_CMP_ENABLE(CHANNEL_ISO_RCV
), 0x9<<4);
1769 reg_write(lynx
, DMA_WORD1_CMP_VALUE(CHANNEL_ISO_RCV
), 0);
1770 reg_write(lynx
, DMA_WORD1_CMP_ENABLE(CHANNEL_ISO_RCV
), 0);
1772 run_sub_pcl(lynx
, lynx
->iso_rcv
.pcl_start
, 0, CHANNEL_ISO_RCV
);
1774 reg_write(lynx
, LINK_CONTROL
, LINK_CONTROL_RCV_CMP_VALID
1775 | LINK_CONTROL_TX_ISO_EN
| LINK_CONTROL_RX_ISO_EN
1776 | LINK_CONTROL_TX_ASYNC_EN
| LINK_CONTROL_RX_ASYNC_EN
1777 | LINK_CONTROL_RESET_TX
| LINK_CONTROL_RESET_RX
);
1779 if (!lynx
->phyic
.reg_1394a
) {
1780 if (!hpsb_disable_irm
) {
1781 /* attempt to enable contender bit -FIXME- would this
1782 * work elsewhere? */
1783 reg_set_bits(lynx
, GPIO_CTRL_A
, 0x1);
1784 reg_write(lynx
, GPIO_DATA_BASE
+ 0x3c, 0x1);
1787 /* set the contender (if appropriate) and LCtrl bit in the
1788 * extended PHY register set. (Should check that PHY_02_EXTENDED
1789 * is set in register 2?)
1791 i
= get_phy_reg(lynx
, 4);
1793 if (hpsb_disable_irm
)
1794 i
&= !PHY_04_CONTENDER
;
1796 i
|= PHY_04_CONTENDER
;
1797 if (i
!= -1) set_phy_reg(lynx
, 4, i
);
1802 /* needed for i2c communication with serial eeprom */
1803 struct i2c_adapter
*i2c_ad
;
1804 struct i2c_algo_bit_data i2c_adapter_data
;
1807 i2c_ad
= kmalloc(sizeof(struct i2c_adapter
), SLAB_KERNEL
);
1808 if (!i2c_ad
) FAIL("failed to allocate I2C adapter memory");
1810 memcpy(i2c_ad
, &bit_ops
, sizeof(struct i2c_adapter
));
1811 i2c_adapter_data
= bit_data
;
1812 i2c_ad
->algo_data
= &i2c_adapter_data
;
1813 i2c_adapter_data
.data
= lynx
;
1815 PRINTD(KERN_DEBUG
, lynx
->id
,"original eeprom control: %d",
1816 reg_read(lynx
, SERIAL_EEPROM_CONTROL
));
1818 /* reset hardware to sane state */
1819 lynx
->i2c_driven_state
= 0x00000070;
1820 reg_write(lynx
, SERIAL_EEPROM_CONTROL
, lynx
->i2c_driven_state
);
1822 if (i2c_bit_add_bus(i2c_ad
) < 0)
1826 FAIL("unable to register i2c");
1831 unsigned char i2c_cmd
= 0x10;
1832 struct i2c_msg msg
[2] = { { 0x50, 0, 1, &i2c_cmd
},
1833 { 0x50, I2C_M_RD
, 20, (unsigned char*) lynx
->bus_info_block
}
1837 #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
1838 union i2c_smbus_data data
;
1840 if (i2c_smbus_xfer(i2c_ad
, 80, 0, I2C_SMBUS_WRITE
, 0, I2C_SMBUS_BYTE
,NULL
))
1841 PRINT(KERN_ERR
, lynx
->id
,"eeprom read start has failed");
1845 for (addr
=0x00; addr
< 0x100; addr
++) {
1846 if (i2c_smbus_xfer(i2c_ad
, 80, 0, I2C_SMBUS_READ
, 0, I2C_SMBUS_BYTE
,& data
)) {
1847 PRINT(KERN_ERR
, lynx
->id
, "unable to read i2c %x", addr
);
1851 PRINT(KERN_DEBUG
, lynx
->id
,"got serial eeprom data at %x: %x",addr
, data
.byte
);
1856 /* we use i2c_transfer, because i2c_smbus_read_block_data does not work properly and we
1857 do it more efficiently in one transaction rather then using several reads */
1858 if (i2c_transfer(i2c_ad
, msg
, 2) < 0) {
1859 PRINT(KERN_ERR
, lynx
->id
, "unable to read bus info block from i2c");
1863 PRINT(KERN_INFO
, lynx
->id
, "got bus info block from serial eeprom");
1864 /* FIXME: probably we shoud rewrite the max_rec, max_ROM(1394a),
1865 * generation(1394a) and link_spd(1394a) field and recalculate
1868 for (i
= 0; i
< 5 ; i
++)
1869 PRINTD(KERN_DEBUG
, lynx
->id
, "Businfo block quadlet %i: %08x",
1870 i
, be32_to_cpu(lynx
->bus_info_block
[i
]));
1872 /* info_length, crc_length and 1394 magic number to check, if it is really a bus info block */
1873 if (((be32_to_cpu(lynx
->bus_info_block
[0]) & 0xffff0000) == 0x04040000) &&
1874 (lynx
->bus_info_block
[1] == __constant_cpu_to_be32(0x31333934)))
1876 PRINT(KERN_DEBUG
, lynx
->id
, "read a valid bus info block from");
1880 FAIL("read something from serial eeprom, but it does not seem to be a valid bus info block");
1885 i2c_bit_del_bus(i2c_ad
);
1890 host
->csr
.guid_hi
= be32_to_cpu(lynx
->bus_info_block
[3]);
1891 host
->csr
.guid_lo
= be32_to_cpu(lynx
->bus_info_block
[4]);
1892 host
->csr
.cyc_clk_acc
= (be32_to_cpu(lynx
->bus_info_block
[2]) >> 16) & 0xff;
1893 host
->csr
.max_rec
= (be32_to_cpu(lynx
->bus_info_block
[2]) >> 12) & 0xf;
1894 if (!lynx
->phyic
.reg_1394a
)
1895 host
->csr
.lnk_spd
= (get_phy_reg(lynx
, 2) & 0xc0) >> 6;
1897 host
->csr
.lnk_spd
= be32_to_cpu(lynx
->bus_info_block
[2]) & 0x7;
1899 if (hpsb_add_host(host
)) {
1901 FAIL("Failed to register host with highlevel");
1904 lynx
->state
= is_host
;
1911 static struct pci_device_id pci_table
[] = {
1913 .vendor
= PCI_VENDOR_ID_TI
,
1914 .device
= PCI_DEVICE_ID_TI_PCILYNX
,
1915 .subvendor
= PCI_ANY_ID
,
1916 .subdevice
= PCI_ANY_ID
,
1918 { } /* Terminating entry */
1921 static struct pci_driver lynx_pci_driver
= {
1922 .name
= PCILYNX_DRIVER_NAME
,
1923 .id_table
= pci_table
,
1925 .remove
= remove_card
,
1928 static struct hpsb_host_driver lynx_driver
= {
1929 .owner
= THIS_MODULE
,
1930 .name
= PCILYNX_DRIVER_NAME
,
1931 .set_hw_config_rom
= NULL
,
1932 .transmit_packet
= lynx_transmit
,
1933 .devctl
= lynx_devctl
,
1937 MODULE_AUTHOR("Andreas E. Bombe <andreas.bombe@munich.netsurf.de>");
1938 MODULE_DESCRIPTION("driver for Texas Instruments PCI Lynx IEEE-1394 controller");
1939 MODULE_LICENSE("GPL");
1940 MODULE_SUPPORTED_DEVICE("pcilynx");
1941 MODULE_DEVICE_TABLE(pci
, pci_table
);
1943 static int __init
pcilynx_init(void)
1947 #ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1948 if (register_chrdev(PCILYNX_MAJOR
, PCILYNX_DRIVER_NAME
, &aux_ops
)) {
1949 PRINT_G(KERN_ERR
, "allocation of char major number %d failed",
1955 ret
= pci_register_driver(&lynx_pci_driver
);
1957 PRINT_G(KERN_ERR
, "PCI module init failed");
1964 #ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1965 unregister_chrdev(PCILYNX_MAJOR
, PCILYNX_DRIVER_NAME
);
1971 static void __exit
pcilynx_cleanup(void)
1973 pci_unregister_driver(&lynx_pci_driver
);
1975 #ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1976 unregister_chrdev(PCILYNX_MAJOR
, PCILYNX_DRIVER_NAME
);
1981 module_init(pcilynx_init
);
1982 module_exit(pcilynx_cleanup
);