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>
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/init.h>
41 #include <linux/pci.h>
43 #include <linux/poll.h>
44 #include <linux/irq.h>
45 #include <asm/byteorder.h>
46 #include <asm/atomic.h>
48 #include <asm/uaccess.h>
51 #include "ieee1394_types.h"
53 #include "ieee1394_core.h"
54 #include "highlevel.h"
57 #include <linux/i2c.h>
58 #include <linux/i2c-algo-bit.h>
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)
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)
69 #define PRINT_GD(level, fmt, args...) do {} while (0)
70 #define PRINTD(level, card, fmt, args...) do {} while (0)
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;
80 static struct hpsb_host_driver lynx_driver;
81 static unsigned int card_id;
89 /* the i2c stuff was inspired by i2c-philips-par.c */
91 static void bit_setscl(void *data, int state)
94 ((struct ti_lynx *) data)->i2c_driven_state |= 0x00000040;
96 ((struct ti_lynx *) data)->i2c_driven_state &= ~0x00000040;
98 reg_write((struct ti_lynx *) data, SERIAL_EEPROM_CONTROL, ((struct ti_lynx *) data)->i2c_driven_state);
101 static void bit_setsda(void *data, int state)
104 ((struct ti_lynx *) data)->i2c_driven_state |= 0x00000010;
106 ((struct ti_lynx *) data)->i2c_driven_state &= ~0x00000010;
108 reg_write((struct ti_lynx *) data, SERIAL_EEPROM_CONTROL, ((struct ti_lynx *) data)->i2c_driven_state);
111 static int bit_getscl(void *data)
113 return reg_read((struct ti_lynx *) data, SERIAL_EEPROM_CONTROL) & 0x00000040;
116 static int bit_getsda(void *data)
118 return reg_read((struct ti_lynx *) data, SERIAL_EEPROM_CONTROL) & 0x00000010;
121 static int bit_reg(struct i2c_client *client)
126 static int bit_unreg(struct i2c_client *client)
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,
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",
151 * PCL handling functions.
154 static pcl_t alloc_pcl(struct ti_lynx *lynx)
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++) {
168 lynx->pcl_bmap[i] = m;
169 spin_unlock(&lynx->lock);
173 spin_unlock(&lynx->lock);
180 static void free_pcl(struct ti_lynx *lynx, pcl_t pclid)
191 spin_lock(&lynx->lock);
192 if (lynx->pcl_bmap[off] & 1<<bit) {
193 lynx->pcl_bmap[off] &= ~(1<<bit);
195 PRINT(KERN_ERR, lynx->id,
196 "attempted to free unallocated PCL %d", pclid);
198 spin_unlock(&lynx->lock);
201 /* functions useful for debugging */
202 static void pretty_print_pcl(const struct ti_pcl *pcl)
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);
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");
219 static void print_pcl(const struct ti_lynx *lynx, pcl_t pclid)
223 get_pcl(lynx, pclid, &pcl);
224 pretty_print_pcl(&pcl);
230 /***********************************
231 * IEEE-1394 functionality section *
232 ***********************************/
235 static int get_phy_reg(struct ti_lynx *lynx, int addr)
243 PRINT(KERN_ERR, lynx->id,
244 "%s: PHY register address %d out of range",
249 spin_lock_irqsave(&lynx->phy_reg_lock, flags);
251 reg_write(lynx, LINK_PHY, LINK_PHY_READ | LINK_PHY_ADDR(addr));
253 retval = reg_read(lynx, LINK_PHY);
256 PRINT(KERN_ERR, lynx->id, "%s: runaway loop, aborting",
262 } while ((retval & 0xf00) != LINK_PHY_RADDR(addr));
264 reg_write(lynx, LINK_INT_STATUS, LINK_INT_PHY_REG_RCVD);
265 spin_unlock_irqrestore(&lynx->phy_reg_lock, flags);
268 return retval & 0xff;
274 static int set_phy_reg(struct ti_lynx *lynx, int addr, int val)
279 PRINT(KERN_ERR, lynx->id,
280 "%s: PHY register address %d out of range", __FUNCTION__, addr);
285 PRINT(KERN_ERR, lynx->id,
286 "%s: PHY register value %d out of range", __FUNCTION__, val);
290 spin_lock_irqsave(&lynx->phy_reg_lock, flags);
292 reg_write(lynx, LINK_PHY, LINK_PHY_WRITE | LINK_PHY_ADDR(addr)
293 | LINK_PHY_WDATA(val));
295 spin_unlock_irqrestore(&lynx->phy_reg_lock, flags);
300 static int sel_phy_reg_page(struct ti_lynx *lynx, int page)
305 PRINT(KERN_ERR, lynx->id,
306 "%s: PHY page %d out of range", __FUNCTION__, page);
310 reg = get_phy_reg(lynx, 7);
314 set_phy_reg(lynx, 7, reg);
321 #if 0 /* not needed at this time */
322 static int sel_phy_reg_port(struct ti_lynx *lynx, int port)
327 PRINT(KERN_ERR, lynx->id,
328 "%s: PHY port %d out of range", __FUNCTION__, port);
332 reg = get_phy_reg(lynx, 7);
336 set_phy_reg(lynx, 7, reg);
344 static u32 get_phy_vendorid(struct ti_lynx *lynx)
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);
355 static u32 get_phy_productid(struct ti_lynx *lynx)
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);
366 static quadlet_t generate_own_selfid(struct ti_lynx *lynx,
367 struct hpsb_host *host)
373 phyreg[0] = lynx->phy_reg0;
374 for (i = 1; i < 7; i++) {
375 phyreg[i] = get_phy_reg(lynx, i);
378 /* FIXME? We assume a TSB21LV03A phy here. This code doesn't support
379 more than 3 ports on the PHY anyway. */
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 */
388 for (i = 0; i < (phyreg[2] & 0xf); i++) { /* ports */
389 if (phyreg[3 + i] & 0x4) {
390 lsid |= (((phyreg[3 + i] & 0x8) | 0x10) >> 3)
393 lsid |= 1 << (6 - i*2);
398 PRINT(KERN_DEBUG, lynx->id, "generated own selfid 0x%x", lsid);
402 static void handle_selfid(struct ti_lynx *lynx, struct hpsb_host *host)
404 quadlet_t *q = lynx->rcv_page;
405 int phyid, isroot, size;
409 if (lynx->phy_reg0 == -1 || lynx->selfid_size == -1) return;
411 size = lynx->selfid_size;
412 phyid = lynx->phy_reg0;
414 i = (size > 16 ? 16 : size) / 4 - 1;
420 if (!lynx->phyic.reg_1394a) {
421 lsid = generate_own_selfid(lynx, host);
424 isroot = (phyid & 2) != 0;
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);
430 if (!lynx->phyic.reg_1394a && !size) {
431 hpsb_selfid_received(host, lsid);
435 struct selfid *sid = (struct selfid *)q;
437 if (!lynx->phyic.reg_1394a && !sid->extended
438 && (sid->phy_id == (phyid + 1))) {
439 hpsb_selfid_received(host, lsid);
443 PRINT(KERN_DEBUG, lynx->id, "SelfID packet 0x%x rcvd",
445 hpsb_selfid_received(host, q[0]);
447 PRINT(KERN_INFO, lynx->id,
448 "inconsistent selfid 0x%x/0x%x", q[0], q[1]);
454 if (!lynx->phyic.reg_1394a && isroot && phyid != 0) {
455 hpsb_selfid_received(host, lsid);
458 hpsb_selfid_complete(host, phyid, isroot);
460 if (host->in_bus_reset) return; /* in bus reset again */
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);
470 /* This must be called with the respective queue_lock held. */
471 static void send_next(struct ti_lynx *lynx, int what)
474 struct lynx_send_data *d;
475 struct hpsb_packet *packet;
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");
483 packet = driver_packet(d->queue.next);
484 list_del(&packet->driver_list);
485 list_add_tail(&packet->driver_list, &d->pcl_queue);
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,
497 pcl.next = PCL_NEXT_INVALID;
498 pcl.async_error_next = PCL_NEXT_INVALID;
501 pcl.buffer[0].control = packet->speed_code << 14 | packet->header_size;
503 pcl.buffer[0].control = packet->speed_code << 14 | packet->header_size
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;
510 switch (packet->type) {
512 pcl.buffer[0].control |= PCL_CMD_XMT;
515 pcl.buffer[0].control |= PCL_CMD_XMT | PCL_ISOMODE;
518 pcl.buffer[0].control |= PCL_CMD_UNFXMT;
522 if (!packet->data_be) {
523 pcl.buffer[1].control |= PCL_BIGENDIAN;
526 put_pcl(lynx, d->pcl, &pcl);
527 run_pcl(lynx, d->pcl_start, d->channel);
531 /* called from subsystem core */
532 static int lynx_transmit(struct hpsb_host *host, struct hpsb_packet *packet)
534 struct ti_lynx *lynx = host->hostdata;
535 struct lynx_send_data *d;
538 if (packet->data_size >= 4096) {
539 PRINT(KERN_ERR, lynx->id, "transmit packet data too big (%Zd)",
544 switch (packet->type) {
553 PRINT(KERN_ERR, lynx->id, "invalid packet type %d",
558 if (packet->tcode == TCODE_WRITEQ
559 || packet->tcode == TCODE_READQ_RESPONSE) {
560 cpu_to_be32s(&packet->header[3]);
563 spin_lock_irqsave(&d->queue_lock, flags);
565 list_add_tail(&packet->driver_list, &d->queue);
566 if (list_empty(&d->pcl_queue))
567 send_next(lynx, packet->type);
569 spin_unlock_irqrestore(&d->queue_lock, flags);
575 /* called from subsystem core */
576 static int lynx_devctl(struct hpsb_host *host, enum devctl_cmd cmd, int arg)
578 struct ti_lynx *lynx = host->hostdata;
580 struct hpsb_packet *packet;
581 LIST_HEAD(packet_list);
587 if (reg_read(lynx, LINK_INT_STATUS) & LINK_INT_PHY_BUSRESET) {
594 if (lynx->phyic.reg_1394a) {
595 phy_reg = get_phy_reg(lynx, 5);
597 PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
603 PRINT(KERN_INFO, lynx->id, "resetting bus (short bus reset) on request");
605 lynx->selfid_size = -1;
607 set_phy_reg(lynx, 5, phy_reg); /* set ISBR */
610 PRINT(KERN_INFO, lynx->id, "cannot do short bus reset, because of old phy");
611 /* fall through to long bus reset */
614 phy_reg = get_phy_reg(lynx, 1);
616 PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
622 PRINT(KERN_INFO, lynx->id, "resetting bus (long bus reset) on request");
624 lynx->selfid_size = -1;
626 set_phy_reg(lynx, 1, phy_reg); /* clear RHB, set IBR */
628 case SHORT_RESET_NO_FORCE_ROOT:
629 if (lynx->phyic.reg_1394a) {
630 phy_reg = get_phy_reg(lynx, 1);
632 PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
636 if (phy_reg & 0x80) {
638 set_phy_reg(lynx, 1, phy_reg); /* clear RHB */
641 phy_reg = get_phy_reg(lynx, 5);
643 PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
649 PRINT(KERN_INFO, lynx->id, "resetting bus (short bus reset, no force_root) on request");
651 lynx->selfid_size = -1;
653 set_phy_reg(lynx, 5, phy_reg); /* set ISBR */
656 PRINT(KERN_INFO, lynx->id, "cannot do short bus reset, because of old phy");
657 /* fall through to long bus reset */
659 case LONG_RESET_NO_FORCE_ROOT:
660 phy_reg = get_phy_reg(lynx, 1);
662 PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
669 PRINT(KERN_INFO, lynx->id, "resetting bus (long bus reset, no force_root) on request");
671 lynx->selfid_size = -1;
673 set_phy_reg(lynx, 1, phy_reg); /* clear RHB, set IBR */
675 case SHORT_RESET_FORCE_ROOT:
676 if (lynx->phyic.reg_1394a) {
677 phy_reg = get_phy_reg(lynx, 1);
679 PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
683 if (!(phy_reg & 0x80)) {
685 set_phy_reg(lynx, 1, phy_reg); /* set RHB */
688 phy_reg = get_phy_reg(lynx, 5);
690 PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
696 PRINT(KERN_INFO, lynx->id, "resetting bus (short bus reset, force_root set) on request");
698 lynx->selfid_size = -1;
700 set_phy_reg(lynx, 5, phy_reg); /* set ISBR */
703 PRINT(KERN_INFO, lynx->id, "cannot do short bus reset, because of old phy");
704 /* fall through to long bus reset */
706 case LONG_RESET_FORCE_ROOT:
707 phy_reg = get_phy_reg(lynx, 1);
709 PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
715 PRINT(KERN_INFO, lynx->id, "resetting bus (long bus reset, force_root set) on request");
717 lynx->selfid_size = -1;
719 set_phy_reg(lynx, 1, phy_reg); /* set IBR and RHB */
722 PRINT(KERN_ERR, lynx->id, "unknown argument for reset_bus command %d", arg);
728 case GET_CYCLE_COUNTER:
729 retval = reg_read(lynx, CYCLE_TIMER);
732 case SET_CYCLE_COUNTER:
733 reg_write(lynx, CYCLE_TIMER, arg);
737 reg_write(lynx, LINK_ID,
738 (arg << 22) | (reg_read(lynx, LINK_ID) & 0x003f0000));
741 case ACT_CYCLE_MASTER:
743 reg_set_bits(lynx, LINK_CONTROL,
744 LINK_CONTROL_CYCMASTER);
746 reg_clear_bits(lynx, LINK_CONTROL,
747 LINK_CONTROL_CYCMASTER);
751 case CANCEL_REQUESTS:
752 spin_lock_irqsave(&lynx->async.queue_lock, flags);
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);
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");
764 struct hpsb_packet *packet;
766 PRINT(KERN_INFO, lynx->id, "cancelling async packet, that was already in PCL");
768 get_pcl(lynx, lynx->async.pcl, &pcl);
770 packet = driver_packet(lynx->async.pcl_queue.next);
771 list_del(&packet->driver_list);
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);
780 spin_unlock_irqrestore(&lynx->async.queue_lock, flags);
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);
788 ack = (pcl.pcl_status >> 15) & 0xf;
791 PRINT(KERN_INFO, lynx->id, "async packet was not completed");
794 hpsb_packet_sent(host, packet, ack);
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);
815 case ISO_LISTEN_CHANNEL:
816 spin_lock_irqsave(&lynx->iso_rcv.lock, flags);
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);
823 spin_unlock_irqrestore(&lynx->iso_rcv.lock, flags);
826 case ISO_UNLISTEN_CHANNEL:
827 spin_lock_irqsave(&lynx->iso_rcv.lock, flags);
829 if (--lynx->iso_rcv.chan_count == 0) {
830 reg_write(lynx, DMA_WORD1_CMP_ENABLE(CHANNEL_ISO_RCV),
834 spin_unlock_irqrestore(&lynx->iso_rcv.lock, flags);
838 PRINT(KERN_ERR, lynx->id, "unknown devctl command %d", cmd);
846 /***************************************
847 * IEEE-1394 functionality section END *
848 ***************************************/
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.
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*);
864 static struct file_operations aux_ops = {
865 .owner = THIS_MODULE,
869 .llseek = mem_llseek,
871 .release = mem_release,
875 static void aux_setup_pcls(struct ti_lynx *lynx)
879 pcl.next = PCL_NEXT_INVALID;
880 pcl.user_data = pcl_bus(lynx, lynx->dmem_pcl);
881 put_pcl(lynx, lynx->dmem_pcl, &pcl);
884 static int mem_open(struct inode *inode, struct file *file)
886 int cid = MINOR(inode->i_rdev);
887 enum { t_rom, t_aux, t_ram } type;
890 if (cid < PCILYNX_MINOR_AUX_START) {
891 /* just for completeness */
893 } else if (cid < PCILYNX_MINOR_ROM_START) {
894 cid -= PCILYNX_MINOR_AUX_START;
895 if (cid >= num_of_cards || !cards[cid].aux_port)
898 } else if (cid < PCILYNX_MINOR_RAM_START) {
899 cid -= PCILYNX_MINOR_ROM_START;
900 if (cid >= num_of_cards || !cards[cid].local_rom)
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)
912 md = (struct memdata *)kmalloc(sizeof(struct memdata), SLAB_KERNEL);
916 md->lynx = &cards[cid];
927 atomic_set(&md->aux_intr_last_seen,
928 atomic_read(&cards[cid].aux_intr_seen));
933 file->private_data = md;
938 static int mem_release(struct inode *inode, struct file *file)
940 kfree(file->private_data);
944 static unsigned int aux_poll(struct file *file, poll_table *pt)
946 struct memdata *md = (struct memdata *)file->private_data;
950 /* reading and writing is always allowed */
951 mask = POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM;
953 if (md->type == aux) {
954 poll_wait(file, &cards[cid].aux_intr_wait, pt);
956 if (atomic_read(&md->aux_intr_last_seen)
957 != atomic_read(&cards[cid].aux_intr_seen)) {
959 atomic_inc(&md->aux_intr_last_seen);
966 loff_t mem_llseek(struct file *file, loff_t offs, int orig)
975 newoffs = offs + file->f_pos;
978 newoffs = PCILYNX_MAX_MEMORY + 1 + offs;
984 if (newoffs < 0 || newoffs > PCILYNX_MAX_MEMORY + 1) return -EINVAL;
986 file->f_pos = newoffs;
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
995 short mem_mindma = 2400;
996 MODULE_PARM(mem_mindma, "h");
998 static ssize_t mem_dmaread(struct memdata *md, u32 physbuf, ssize_t count,
1005 DECLARE_WAITQUEUE(wait, current);
1008 count = min(count, 53196);
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!");
1016 reg_write(md->lynx, LBUS_ADDR, md->type | offset);
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;
1026 pcl->buffer[i].control = min(count, 4092);
1027 pcl->buffer[i].pointer = physbuf + i * 4092;
1030 pcl->buffer[i].control |= PCL_LAST_BUFF;
1031 commit_pcl(md->lynx, md->lynx->dmem_pcl, &pcltmp);
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);
1038 while (reg_read(md->lynx, DMA_CHAN_CTRL(CHANNEL_LOCALBUS))
1039 & DMA_CHAN_CTRL_BUSY) {
1040 if (signal_pending(current)) {
1047 reg_write(md->lynx, DMA_CHAN_CTRL(CHANNEL_LOCALBUS), 0);
1048 remove_wait_queue(&md->lynx->mem_dma_intr_wait, &wait);
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!");
1058 static ssize_t mem_read(struct file *file, char *buffer, size_t count,
1061 struct memdata *md = (struct memdata *)file->private_data;
1064 loff_t off = *offset; /* avoid useless 64bit-arithmetic */
1072 if (off > PCILYNX_MAX_MEMORY)
1075 if (count > PCILYNX_MAX_MEMORY + 1 - off)
1076 count = PCILYNX_MAX_MEMORY + 1 - off;
1080 membase = md->lynx->local_rom;
1083 membase = md->lynx->local_ram;
1086 membase = md->lynx->aux_port;
1089 panic("pcilynx%d: unsupported md->type %d in %s",
1090 md->lynx->id, md->type, __FUNCTION__);
1093 down(&md->lynx->mem_dma_mutex);
1095 if (count < mem_mindma) {
1096 memcpy_fromio(md->lynx->mem_dma_buffer, membase+off, count);
1102 alignfix = 4 - (off % 4);
1103 if (alignfix != 4) {
1104 if (bcount < alignfix) {
1107 memcpy_fromio(md->lynx->mem_dma_buffer, membase+off,
1109 if (bcount == alignfix) {
1116 while (bcount >= 4) {
1117 retval = mem_dmaread(md, md->lynx->mem_dma_buffer_dma
1118 + count - bcount, bcount, off);
1119 if (retval < 0) return retval;
1126 memcpy_fromio(md->lynx->mem_dma_buffer + count - bcount,
1127 membase+off, bcount);
1132 retval = copy_to_user(buffer, md->lynx->mem_dma_buffer, count);
1133 up(&md->lynx->mem_dma_mutex);
1135 if (retval) return -EFAULT;
1141 static ssize_t mem_write(struct file *file, const char *buffer, size_t count,
1144 struct memdata *md = (struct memdata *)file->private_data;
1145 loff_t off = *offset;
1151 if (off > PCILYNX_MAX_MEMORY)
1154 if (count > PCILYNX_MAX_MEMORY + 1 - off)
1155 count = PCILYNX_MAX_MEMORY + 1 - off;
1157 /* FIXME: dereferencing pointers to PCI mem doesn't work everywhere */
1160 if (copy_from_user(md->lynx->aux_port+off, buffer, count))
1164 if (copy_from_user(md->lynx->local_ram+off, buffer, count))
1168 /* the ROM may be writeable */
1169 if (copy_from_user(md->lynx->local_rom+off, buffer, count))
1174 *offset = off + count;
1177 #endif /* CONFIG_IEEE1394_PCILYNX_PORTS */
1180 /********************************************************
1181 * Global stuff (interrupt handler, init/shutdown code) *
1182 ********************************************************/
1185 static void lynx_irq_handler(int irq, void *dev_id,
1186 struct pt_regs *regs_are_unused)
1188 struct ti_lynx *lynx = (struct ti_lynx *)dev_id;
1189 struct hpsb_host *host = lynx->host;
1193 linkint = reg_read(lynx, LINK_INT_STATUS);
1194 intmask = reg_read(lynx, PCI_INT_STATUS);
1196 if (!(intmask & PCI_INT_INT_PEND)) return;
1198 PRINTD(KERN_DEBUG, lynx->id, "interrupt: 0x%08x / 0x%08x", intmask,
1201 reg_write(lynx, LINK_INT_STATUS, linkint);
1202 reg_write(lynx, PCI_INT_STATUS, intmask);
1204 #ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1205 if (intmask & PCI_INT_AUX_INT) {
1206 atomic_inc(&lynx->aux_intr_seen);
1207 wake_up_interruptible(&lynx->aux_intr_wait);
1210 if (intmask & PCI_INT_DMA_HLT(CHANNEL_LOCALBUS)) {
1211 wake_up_interruptible(&lynx->mem_dma_intr_wait);
1216 if (intmask & PCI_INT_1394) {
1217 if (linkint & LINK_INT_PHY_TIMEOUT) {
1218 PRINT(KERN_INFO, lynx->id, "PHY timeout occurred");
1220 if (linkint & LINK_INT_PHY_BUSRESET) {
1221 PRINT(KERN_INFO, lynx->id, "bus reset interrupt");
1222 lynx->selfid_size = -1;
1223 lynx->phy_reg0 = -1;
1224 if (!host->in_bus_reset)
1225 hpsb_bus_reset(host);
1227 if (linkint & LINK_INT_PHY_REG_RCVD) {
1230 spin_lock(&lynx->phy_reg_lock);
1231 reg = reg_read(lynx, LINK_PHY);
1232 spin_unlock(&lynx->phy_reg_lock);
1234 if (!host->in_bus_reset) {
1235 PRINT(KERN_INFO, lynx->id,
1236 "phy reg received without reset");
1237 } else if (reg & 0xf00) {
1238 PRINT(KERN_INFO, lynx->id,
1239 "unsolicited phy reg %d received",
1242 lynx->phy_reg0 = reg & 0xff;
1243 handle_selfid(lynx, host);
1246 if (linkint & LINK_INT_ISO_STUCK) {
1247 PRINT(KERN_INFO, lynx->id, "isochronous transmitter stuck");
1249 if (linkint & LINK_INT_ASYNC_STUCK) {
1250 PRINT(KERN_INFO, lynx->id, "asynchronous transmitter stuck");
1252 if (linkint & LINK_INT_SENT_REJECT) {
1253 PRINT(KERN_INFO, lynx->id, "sent reject");
1255 if (linkint & LINK_INT_TX_INVALID_TC) {
1256 PRINT(KERN_INFO, lynx->id, "invalid transaction code");
1258 if (linkint & LINK_INT_GRF_OVERFLOW) {
1259 /* flush FIFO if overflow happens during reset */
1260 if (host->in_bus_reset)
1261 reg_write(lynx, FIFO_CONTROL,
1262 FIFO_CONTROL_GRF_FLUSH);
1263 PRINT(KERN_INFO, lynx->id, "GRF overflow");
1265 if (linkint & LINK_INT_ITF_UNDERFLOW) {
1266 PRINT(KERN_INFO, lynx->id, "ITF underflow");
1268 if (linkint & LINK_INT_ATF_UNDERFLOW) {
1269 PRINT(KERN_INFO, lynx->id, "ATF underflow");
1273 if (intmask & PCI_INT_DMA_HLT(CHANNEL_ISO_RCV)) {
1274 PRINTD(KERN_DEBUG, lynx->id, "iso receive");
1276 spin_lock(&lynx->iso_rcv.lock);
1278 lynx->iso_rcv.stat[lynx->iso_rcv.next] =
1279 reg_read(lynx, DMA_CHAN_STAT(CHANNEL_ISO_RCV));
1281 lynx->iso_rcv.used++;
1282 lynx->iso_rcv.next = (lynx->iso_rcv.next + 1) % NUM_ISORCV_PCL;
1284 if ((lynx->iso_rcv.next == lynx->iso_rcv.last)
1285 || !lynx->iso_rcv.chan_count) {
1286 PRINTD(KERN_DEBUG, lynx->id, "stopped");
1287 reg_write(lynx, DMA_WORD1_CMP_ENABLE(CHANNEL_ISO_RCV), 0);
1290 run_sub_pcl(lynx, lynx->iso_rcv.pcl_start, lynx->iso_rcv.next,
1293 spin_unlock(&lynx->iso_rcv.lock);
1295 tasklet_schedule(&lynx->iso_rcv.tq);
1298 if (intmask & PCI_INT_DMA_HLT(CHANNEL_ASYNC_SEND)) {
1299 PRINTD(KERN_DEBUG, lynx->id, "async sent");
1300 spin_lock(&lynx->async.queue_lock);
1302 if (list_empty(&lynx->async.pcl_queue)) {
1303 spin_unlock(&lynx->async.queue_lock);
1304 PRINT(KERN_WARNING, lynx->id, "async dma halted, but no queued packet (maybe it was cancelled)");
1308 struct hpsb_packet *packet;
1310 get_pcl(lynx, lynx->async.pcl, &pcl);
1312 packet = driver_packet(lynx->async.pcl_queue.next);
1313 list_del(&packet->driver_list);
1315 pci_unmap_single(lynx->dev, lynx->async.header_dma,
1316 packet->header_size, PCI_DMA_TODEVICE);
1317 if (packet->data_size) {
1318 pci_unmap_single(lynx->dev, lynx->async.data_dma,
1319 packet->data_size, PCI_DMA_TODEVICE);
1322 if (!list_empty(&lynx->async.queue)) {
1323 send_next(lynx, hpsb_async);
1326 spin_unlock(&lynx->async.queue_lock);
1328 if (pcl.pcl_status & DMA_CHAN_STAT_PKTCMPL) {
1329 if (pcl.pcl_status & DMA_CHAN_STAT_SPECIALACK) {
1330 ack = (pcl.pcl_status >> 15) & 0xf;
1331 PRINTD(KERN_INFO, lynx->id, "special ack %d", ack);
1332 ack = (ack == 1 ? ACKX_TIMEOUT : ACKX_SEND_ERROR);
1334 ack = (pcl.pcl_status >> 15) & 0xf;
1337 PRINT(KERN_INFO, lynx->id, "async packet was not completed");
1338 ack = ACKX_SEND_ERROR;
1340 hpsb_packet_sent(host, packet, ack);
1344 if (intmask & PCI_INT_DMA_HLT(CHANNEL_ISO_SEND)) {
1345 PRINTD(KERN_DEBUG, lynx->id, "iso sent");
1346 spin_lock(&lynx->iso_send.queue_lock);
1348 if (list_empty(&lynx->iso_send.pcl_queue)) {
1349 spin_unlock(&lynx->iso_send.queue_lock);
1350 PRINT(KERN_ERR, lynx->id, "iso send dma halted, but no queued packet");
1354 struct hpsb_packet *packet;
1356 get_pcl(lynx, lynx->iso_send.pcl, &pcl);
1358 packet = driver_packet(lynx->iso_send.pcl_queue.next);
1359 list_del(&packet->driver_list);
1361 pci_unmap_single(lynx->dev, lynx->iso_send.header_dma,
1362 packet->header_size, PCI_DMA_TODEVICE);
1363 if (packet->data_size) {
1364 pci_unmap_single(lynx->dev, lynx->iso_send.data_dma,
1365 packet->data_size, PCI_DMA_TODEVICE);
1368 if (!list_empty(&lynx->iso_send.queue)) {
1369 send_next(lynx, hpsb_iso);
1372 spin_unlock(&lynx->iso_send.queue_lock);
1374 if (pcl.pcl_status & DMA_CHAN_STAT_PKTCMPL) {
1375 if (pcl.pcl_status & DMA_CHAN_STAT_SPECIALACK) {
1376 ack = (pcl.pcl_status >> 15) & 0xf;
1377 PRINTD(KERN_INFO, lynx->id, "special ack %d", ack);
1378 ack = (ack == 1 ? ACKX_TIMEOUT : ACKX_SEND_ERROR);
1380 ack = (pcl.pcl_status >> 15) & 0xf;
1383 PRINT(KERN_INFO, lynx->id, "iso send packet was not completed");
1384 ack = ACKX_SEND_ERROR;
1387 hpsb_packet_sent(host, packet, ack); //FIXME: maybe we should just use ACK_COMPLETE and ACKX_SEND_ERROR
1391 if (intmask & PCI_INT_DMA_HLT(CHANNEL_ASYNC_RCV)) {
1392 /* general receive DMA completed */
1393 int stat = reg_read(lynx, DMA_CHAN_STAT(CHANNEL_ASYNC_RCV));
1395 PRINTD(KERN_DEBUG, lynx->id, "received packet size %d",
1398 if (stat & DMA_CHAN_STAT_SELFID) {
1399 lynx->selfid_size = stat & 0x1fff;
1400 handle_selfid(lynx, host);
1402 quadlet_t *q_data = lynx->rcv_page;
1403 if ((*q_data >> 4 & 0xf) == TCODE_READQ_RESPONSE
1404 || (*q_data >> 4 & 0xf) == TCODE_WRITEQ) {
1405 cpu_to_be32s(q_data + 3);
1407 hpsb_packet_received(host, q_data, stat & 0x1fff, 0);
1410 run_pcl(lynx, lynx->rcv_pcl_start, CHANNEL_ASYNC_RCV);
1415 static void iso_rcv_bh(struct ti_lynx *lynx)
1419 unsigned long flags;
1421 spin_lock_irqsave(&lynx->iso_rcv.lock, flags);
1423 while (lynx->iso_rcv.used) {
1424 idx = lynx->iso_rcv.last;
1425 spin_unlock_irqrestore(&lynx->iso_rcv.lock, flags);
1427 data = lynx->iso_rcv.page[idx / ISORCV_PER_PAGE]
1428 + (idx % ISORCV_PER_PAGE) * MAX_ISORCV_SIZE;
1430 if ((*data >> 16) + 4 != (lynx->iso_rcv.stat[idx] & 0x1fff)) {
1431 PRINT(KERN_ERR, lynx->id,
1432 "iso length mismatch 0x%08x/0x%08x", *data,
1433 lynx->iso_rcv.stat[idx]);
1436 if (lynx->iso_rcv.stat[idx]
1437 & (DMA_CHAN_STAT_PCIERR | DMA_CHAN_STAT_PKTERR)) {
1438 PRINT(KERN_INFO, lynx->id,
1439 "iso receive error on %d to 0x%p", idx, data);
1441 hpsb_packet_received(lynx->host, data,
1442 lynx->iso_rcv.stat[idx] & 0x1fff,
1446 spin_lock_irqsave(&lynx->iso_rcv.lock, flags);
1447 lynx->iso_rcv.last = (idx + 1) % NUM_ISORCV_PCL;
1448 lynx->iso_rcv.used--;
1451 if (lynx->iso_rcv.chan_count) {
1452 reg_write(lynx, DMA_WORD1_CMP_ENABLE(CHANNEL_ISO_RCV),
1453 DMA_WORD1_CMP_ENABLE_MASTER);
1455 spin_unlock_irqrestore(&lynx->iso_rcv.lock, flags);
1459 static void remove_card(struct pci_dev *dev)
1461 struct ti_lynx *lynx;
1464 lynx = pci_get_drvdata(dev);
1466 pci_set_drvdata(dev, NULL);
1468 switch (lynx->state) {
1470 reg_write(lynx, PCI_INT_ENABLE, 0);
1471 hpsb_remove_host(lynx->host);
1473 reg_write(lynx, PCI_INT_ENABLE, 0);
1474 free_irq(lynx->dev->irq, lynx);
1476 /* Disable IRM Contender and LCtrl */
1477 if (lynx->phyic.reg_1394a)
1478 set_phy_reg(lynx, 4, ~0xc0 & get_phy_reg(lynx, 4));
1480 /* Let all other nodes know to ignore us */
1481 lynx_devctl(lynx->host, RESET_BUS, LONG_RESET_NO_FORCE_ROOT);
1483 case have_iomappings:
1484 reg_set_bits(lynx, MISC_CONTROL, MISC_CONTROL_SWRESET);
1485 /* Fix buggy cards with autoboot pin not tied low: */
1486 reg_write(lynx, DMA0_CHAN_CTRL, 0);
1487 iounmap(lynx->registers);
1488 iounmap(lynx->local_rom);
1489 iounmap(lynx->local_ram);
1490 iounmap(lynx->aux_port);
1491 case have_1394_buffers:
1492 for (i = 0; i < ISORCV_PAGES; i++) {
1493 if (lynx->iso_rcv.page[i]) {
1494 pci_free_consistent(lynx->dev, PAGE_SIZE,
1495 lynx->iso_rcv.page[i],
1496 lynx->iso_rcv.page_dma[i]);
1499 pci_free_consistent(lynx->dev, PAGE_SIZE, lynx->rcv_page,
1500 lynx->rcv_page_dma);
1502 #ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1503 pci_free_consistent(lynx->dev, 65536, lynx->mem_dma_buffer,
1504 lynx->mem_dma_buffer_dma);
1507 #ifndef CONFIG_IEEE1394_PCILYNX_LOCALRAM
1508 pci_free_consistent(lynx->dev, LOCALRAM_SIZE, lynx->pcl_mem,
1512 /* do nothing - already freed */
1516 tasklet_kill(&lynx->iso_rcv.tq);
1517 hpsb_unref_host(lynx->host);
1521 static int __devinit add_card(struct pci_dev *dev,
1522 const struct pci_device_id *devid_is_unused)
1524 #define FAIL(fmt, args...) do { \
1525 PRINT_G(KERN_ERR, fmt , ## args); \
1531 struct hpsb_host *host;
1532 struct ti_lynx *lynx; /* shortcut to currently handled device */
1538 /* needed for i2c communication with serial eeprom */
1539 struct i2c_adapter i2c_adapter;
1540 struct i2c_algo_bit_data i2c_adapter_data;
1542 int got_valid_bus_info_block = 0; /* set to 1, if we were able to get a valid bus info block from serial eeprom */
1546 if (pci_set_dma_mask(dev, 0xffffffff))
1547 FAIL("DMA address limits not supported for PCILynx hardware");
1548 if (pci_enable_device(dev))
1549 FAIL("failed to enable PCILynx hardware");
1550 pci_set_master(dev);
1554 host = hpsb_alloc_host(&lynx_driver, sizeof(struct ti_lynx));
1555 if (!host) FAIL("failed to allocate control structure memory");
1557 lynx = host->hostdata;
1558 lynx->id = card_id++;
1560 lynx->state = clear;
1563 pci_set_drvdata(dev, lynx);
1565 lynx->lock = SPIN_LOCK_UNLOCKED;
1566 lynx->phy_reg_lock = SPIN_LOCK_UNLOCKED;
1568 #ifndef CONFIG_IEEE1394_PCILYNX_LOCALRAM
1569 lynx->pcl_mem = pci_alloc_consistent(dev, LOCALRAM_SIZE,
1570 &lynx->pcl_mem_dma);
1572 if (lynx->pcl_mem != NULL) {
1573 lynx->state = have_pcl_mem;
1574 PRINT(KERN_INFO, lynx->id,
1575 "allocated PCL memory %d Bytes @ 0x%p", LOCALRAM_SIZE,
1578 FAIL("failed to allocate PCL memory area");
1582 #ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1583 lynx->mem_dma_buffer = pci_alloc_consistent(dev, 65536,
1584 &lynx->mem_dma_buffer_dma);
1585 if (lynx->mem_dma_buffer == NULL) {
1586 FAIL("failed to allocate DMA buffer for aux");
1588 lynx->state = have_aux_buf;
1591 lynx->rcv_page = pci_alloc_consistent(dev, PAGE_SIZE,
1592 &lynx->rcv_page_dma);
1593 if (lynx->rcv_page == NULL) {
1594 FAIL("failed to allocate receive buffer");
1596 lynx->state = have_1394_buffers;
1598 for (i = 0; i < ISORCV_PAGES; i++) {
1599 lynx->iso_rcv.page[i] =
1600 pci_alloc_consistent(dev, PAGE_SIZE,
1601 &lynx->iso_rcv.page_dma[i]);
1602 if (lynx->iso_rcv.page[i] == NULL) {
1603 FAIL("failed to allocate iso receive buffers");
1607 lynx->registers = ioremap_nocache(pci_resource_start(dev,0),
1608 PCILYNX_MAX_REGISTER);
1609 lynx->local_ram = ioremap(pci_resource_start(dev,1), PCILYNX_MAX_MEMORY);
1610 lynx->aux_port = ioremap(pci_resource_start(dev,2), PCILYNX_MAX_MEMORY);
1611 lynx->local_rom = ioremap(pci_resource_start(dev,PCI_ROM_RESOURCE),
1612 PCILYNX_MAX_MEMORY);
1613 lynx->state = have_iomappings;
1615 if (lynx->registers == NULL) {
1616 FAIL("failed to remap registers - card not accessible");
1619 #ifdef CONFIG_IEEE1394_PCILYNX_LOCALRAM
1620 if (lynx->local_ram == NULL) {
1621 FAIL("failed to remap local RAM which is required for "
1626 reg_set_bits(lynx, MISC_CONTROL, MISC_CONTROL_SWRESET);
1627 /* Fix buggy cards with autoboot pin not tied low: */
1628 reg_write(lynx, DMA0_CHAN_CTRL, 0);
1631 sprintf (irq_buf, "%d", dev->irq);
1633 sprintf (irq_buf, "%s", __irq_itoa(dev->irq));
1636 if (!request_irq(dev->irq, lynx_irq_handler, SA_SHIRQ,
1637 PCILYNX_DRIVER_NAME, lynx)) {
1638 PRINT(KERN_INFO, lynx->id, "allocated interrupt %s", irq_buf);
1639 lynx->state = have_intr;
1641 FAIL("failed to allocate shared interrupt %s", irq_buf);
1644 /* alloc_pcl return values are not checked, it is expected that the
1645 * provided PCL space is sufficient for the initial allocations */
1646 #ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1647 if (lynx->aux_port != NULL) {
1648 lynx->dmem_pcl = alloc_pcl(lynx);
1649 aux_setup_pcls(lynx);
1650 sema_init(&lynx->mem_dma_mutex, 1);
1653 lynx->rcv_pcl = alloc_pcl(lynx);
1654 lynx->rcv_pcl_start = alloc_pcl(lynx);
1655 lynx->async.pcl = alloc_pcl(lynx);
1656 lynx->async.pcl_start = alloc_pcl(lynx);
1657 lynx->iso_send.pcl = alloc_pcl(lynx);
1658 lynx->iso_send.pcl_start = alloc_pcl(lynx);
1660 for (i = 0; i < NUM_ISORCV_PCL; i++) {
1661 lynx->iso_rcv.pcl[i] = alloc_pcl(lynx);
1663 lynx->iso_rcv.pcl_start = alloc_pcl(lynx);
1665 /* all allocations successful - simple init stuff follows */
1667 reg_write(lynx, PCI_INT_ENABLE, PCI_INT_DMA_ALL);
1669 #ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1670 reg_set_bits(lynx, PCI_INT_ENABLE, PCI_INT_AUX_INT);
1671 init_waitqueue_head(&lynx->mem_dma_intr_wait);
1672 init_waitqueue_head(&lynx->aux_intr_wait);
1675 tasklet_init(&lynx->iso_rcv.tq, (void (*)(unsigned long))iso_rcv_bh,
1676 (unsigned long)lynx);
1678 lynx->iso_rcv.lock = SPIN_LOCK_UNLOCKED;
1680 lynx->async.queue_lock = SPIN_LOCK_UNLOCKED;
1681 lynx->async.channel = CHANNEL_ASYNC_SEND;
1682 lynx->iso_send.queue_lock = SPIN_LOCK_UNLOCKED;
1683 lynx->iso_send.channel = CHANNEL_ISO_SEND;
1685 PRINT(KERN_INFO, lynx->id, "remapped memory spaces reg 0x%p, rom 0x%p, "
1686 "ram 0x%p, aux 0x%p", lynx->registers, lynx->local_rom,
1687 lynx->local_ram, lynx->aux_port);
1689 /* now, looking for PHY register set */
1690 if ((get_phy_reg(lynx, 2) & 0xe0) == 0xe0) {
1691 lynx->phyic.reg_1394a = 1;
1692 PRINT(KERN_INFO, lynx->id,
1693 "found 1394a conform PHY (using extended register set)");
1694 lynx->phyic.vendor = get_phy_vendorid(lynx);
1695 lynx->phyic.product = get_phy_productid(lynx);
1697 lynx->phyic.reg_1394a = 0;
1698 PRINT(KERN_INFO, lynx->id, "found old 1394 PHY");
1701 lynx->selfid_size = -1;
1702 lynx->phy_reg0 = -1;
1704 INIT_LIST_HEAD(&lynx->async.queue);
1705 INIT_LIST_HEAD(&lynx->async.pcl_queue);
1706 INIT_LIST_HEAD(&lynx->iso_send.queue);
1707 INIT_LIST_HEAD(&lynx->iso_send.pcl_queue);
1709 pcl.next = pcl_bus(lynx, lynx->rcv_pcl);
1710 put_pcl(lynx, lynx->rcv_pcl_start, &pcl);
1712 pcl.next = PCL_NEXT_INVALID;
1713 pcl.async_error_next = PCL_NEXT_INVALID;
1715 pcl.buffer[0].control = PCL_CMD_RCV | 16;
1716 pcl.buffer[1].control = PCL_LAST_BUFF | 4080;
1718 pcl.buffer[0].control = PCL_CMD_RCV | PCL_BIGENDIAN | 16;
1719 pcl.buffer[1].control = PCL_LAST_BUFF | 4080;
1721 pcl.buffer[0].pointer = lynx->rcv_page_dma;
1722 pcl.buffer[1].pointer = lynx->rcv_page_dma + 16;
1723 put_pcl(lynx, lynx->rcv_pcl, &pcl);
1725 pcl.next = pcl_bus(lynx, lynx->async.pcl);
1726 pcl.async_error_next = pcl_bus(lynx, lynx->async.pcl);
1727 put_pcl(lynx, lynx->async.pcl_start, &pcl);
1729 pcl.next = pcl_bus(lynx, lynx->iso_send.pcl);
1730 pcl.async_error_next = PCL_NEXT_INVALID;
1731 put_pcl(lynx, lynx->iso_send.pcl_start, &pcl);
1733 pcl.next = PCL_NEXT_INVALID;
1734 pcl.async_error_next = PCL_NEXT_INVALID;
1735 pcl.buffer[0].control = PCL_CMD_RCV | 4;
1736 #ifndef __BIG_ENDIAN
1737 pcl.buffer[0].control |= PCL_BIGENDIAN;
1739 pcl.buffer[1].control = PCL_LAST_BUFF | 2044;
1741 for (i = 0; i < NUM_ISORCV_PCL; i++) {
1742 int page = i / ISORCV_PER_PAGE;
1743 int sec = i % ISORCV_PER_PAGE;
1745 pcl.buffer[0].pointer = lynx->iso_rcv.page_dma[page]
1746 + sec * MAX_ISORCV_SIZE;
1747 pcl.buffer[1].pointer = pcl.buffer[0].pointer + 4;
1748 put_pcl(lynx, lynx->iso_rcv.pcl[i], &pcl);
1752 for (i = 0; i < NUM_ISORCV_PCL; i++) {
1753 pcli[i] = pcl_bus(lynx, lynx->iso_rcv.pcl[i]);
1755 put_pcl(lynx, lynx->iso_rcv.pcl_start, &pcl);
1757 /* FIFO sizes from left to right: ITF=48 ATF=48 GRF=160 */
1758 reg_write(lynx, FIFO_SIZES, 0x003030a0);
1759 /* 20 byte threshold before triggering PCI transfer */
1760 reg_write(lynx, DMA_GLOBAL_REGISTER, 0x2<<24);
1761 /* threshold on both send FIFOs before transmitting:
1762 FIFO size - cache line size - 1 */
1763 i = reg_read(lynx, PCI_LATENCY_CACHELINE) & 0xff;
1765 reg_write(lynx, FIFO_XMIT_THRESHOLD, (i << 8) | i);
1767 reg_set_bits(lynx, PCI_INT_ENABLE, PCI_INT_1394);
1769 reg_write(lynx, LINK_INT_ENABLE, LINK_INT_PHY_TIMEOUT
1770 | LINK_INT_PHY_REG_RCVD | LINK_INT_PHY_BUSRESET
1771 | LINK_INT_ISO_STUCK | LINK_INT_ASYNC_STUCK
1772 | LINK_INT_SENT_REJECT | LINK_INT_TX_INVALID_TC
1773 | LINK_INT_GRF_OVERFLOW | LINK_INT_ITF_UNDERFLOW
1774 | LINK_INT_ATF_UNDERFLOW);
1776 reg_write(lynx, DMA_WORD0_CMP_VALUE(CHANNEL_ASYNC_RCV), 0);
1777 reg_write(lynx, DMA_WORD0_CMP_ENABLE(CHANNEL_ASYNC_RCV), 0xa<<4);
1778 reg_write(lynx, DMA_WORD1_CMP_VALUE(CHANNEL_ASYNC_RCV), 0);
1779 reg_write(lynx, DMA_WORD1_CMP_ENABLE(CHANNEL_ASYNC_RCV),
1780 DMA_WORD1_CMP_MATCH_LOCAL_NODE | DMA_WORD1_CMP_MATCH_BROADCAST
1781 | DMA_WORD1_CMP_MATCH_EXACT | DMA_WORD1_CMP_MATCH_BUS_BCAST
1782 | DMA_WORD1_CMP_ENABLE_SELF_ID | DMA_WORD1_CMP_ENABLE_MASTER);
1784 run_pcl(lynx, lynx->rcv_pcl_start, CHANNEL_ASYNC_RCV);
1786 reg_write(lynx, DMA_WORD0_CMP_VALUE(CHANNEL_ISO_RCV), 0);
1787 reg_write(lynx, DMA_WORD0_CMP_ENABLE(CHANNEL_ISO_RCV), 0x9<<4);
1788 reg_write(lynx, DMA_WORD1_CMP_VALUE(CHANNEL_ISO_RCV), 0);
1789 reg_write(lynx, DMA_WORD1_CMP_ENABLE(CHANNEL_ISO_RCV), 0);
1791 run_sub_pcl(lynx, lynx->iso_rcv.pcl_start, 0, CHANNEL_ISO_RCV);
1793 reg_write(lynx, LINK_CONTROL, LINK_CONTROL_RCV_CMP_VALID
1794 | LINK_CONTROL_TX_ISO_EN | LINK_CONTROL_RX_ISO_EN
1795 | LINK_CONTROL_TX_ASYNC_EN | LINK_CONTROL_RX_ASYNC_EN
1796 | LINK_CONTROL_RESET_TX | LINK_CONTROL_RESET_RX);
1798 if (!lynx->phyic.reg_1394a) {
1799 /* attempt to enable contender bit -FIXME- would this work
1801 reg_set_bits(lynx, GPIO_CTRL_A, 0x1);
1802 reg_write(lynx, GPIO_DATA_BASE + 0x3c, 0x1);
1804 /* set the contender and LCtrl bit in the extended PHY register
1805 * set. (Should check that bis 0,1,2 (=0xE0) is set
1808 i = get_phy_reg(lynx, 4);
1809 if (i != -1) set_phy_reg(lynx, 4, i | 0xc0);
1815 i2c_adapter = bit_ops;
1816 i2c_adapter_data = bit_data;
1817 i2c_adapter.algo_data = &i2c_adapter_data;
1818 i2c_adapter_data.data = lynx;
1820 PRINTD(KERN_DEBUG, lynx->id,"original eeprom control: %d",
1821 reg_read(lynx, SERIAL_EEPROM_CONTROL));
1823 /* reset hardware to sane state */
1824 lynx->i2c_driven_state = 0x00000070;
1825 reg_write(lynx, SERIAL_EEPROM_CONTROL, lynx->i2c_driven_state);
1827 if (i2c_bit_add_bus(&i2c_adapter) < 0)
1829 PRINT(KERN_ERR, lynx->id, "unable to register i2c");
1834 unsigned char i2c_cmd = 0x10;
1835 struct i2c_msg msg[2] = { { 0x50, 0, 1, &i2c_cmd },
1836 { 0x50, I2C_M_RD, 20, (unsigned char*) lynx->config_rom }
1840 #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
1841 union i2c_smbus_data data;
1843 if (i2c_smbus_xfer(&i2c_adapter, 80, 0, I2C_SMBUS_WRITE, 0, I2C_SMBUS_BYTE,NULL))
1844 PRINT(KERN_ERR, lynx->id,"eeprom read start has failed");
1848 for (addr=0x00; addr < 0x100; addr++) {
1849 if (i2c_smbus_xfer(&i2c_adapter, 80, 0, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE,& data)) {
1850 PRINT(KERN_ERR, lynx->id, "unable to read i2c %x", addr);
1854 PRINT(KERN_DEBUG, lynx->id,"got serial eeprom data at %x: %x",addr, data.byte);
1859 /* we use i2c_transfer, because i2c_smbus_read_block_data does not work properly and we
1860 do it more efficiently in one transaction rather then using several reads */
1861 if (i2c_transfer(&i2c_adapter, msg, 2) < 0) {
1862 PRINT(KERN_ERR, lynx->id, "unable to read bus info block from i2c");
1866 PRINT(KERN_INFO, lynx->id, "got bus info block from serial eeprom");
1867 /* FIXME: probably we shoud rewrite the max_rec, max_ROM(1394a),
1868 * generation(1394a) and link_spd(1394a) field and recalculate
1871 for (i = 0; i < 5 ; i++)
1872 PRINTD(KERN_DEBUG, lynx->id, "Businfo block quadlet %i: %08x",
1873 i, be32_to_cpu(lynx->config_rom[i]));
1875 /* info_length, crc_length and 1394 magic number to check, if it is really a bus info block */
1876 if (((be32_to_cpu(lynx->config_rom[0]) & 0xffff0000) == 0x04040000) &&
1877 (lynx->config_rom[1] == __constant_cpu_to_be32(0x31333934)))
1879 PRINT(KERN_DEBUG, lynx->id, "read a valid bus info block from");
1880 got_valid_bus_info_block = 1;
1882 PRINT(KERN_WARNING, lynx->id, "read something from serial eeprom, but it does not seem to be a valid bus info block");
1887 i2c_bit_del_bus(&i2c_adapter);
1891 if (got_valid_bus_info_block) {
1892 memcpy(lynx->config_rom+5,lynx_csr_rom+5,sizeof(lynx_csr_rom)-20);
1894 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");
1895 memcpy(lynx->config_rom,lynx_csr_rom,sizeof(lynx_csr_rom));
1898 hpsb_add_host(host);
1899 lynx->state = is_host;
1907 static size_t get_lynx_rom(struct hpsb_host *host, quadlet_t **ptr)
1909 struct ti_lynx *lynx = host->hostdata;
1910 *ptr = lynx->config_rom;
1911 return sizeof(lynx_csr_rom);
1914 static struct pci_device_id pci_table[] __devinitdata = {
1916 .vendor = PCI_VENDOR_ID_TI,
1917 .device = PCI_DEVICE_ID_TI_PCILYNX,
1918 .subvendor = PCI_ANY_ID,
1919 .subdevice = PCI_ANY_ID,
1921 { } /* Terminating entry */
1924 static struct pci_driver lynx_pci_driver = {
1925 .name = PCILYNX_DRIVER_NAME,
1926 .id_table = pci_table,
1928 .remove = remove_card,
1931 static struct hpsb_host_driver lynx_driver = {
1932 .name = PCILYNX_DRIVER_NAME,
1933 .get_rom = get_lynx_rom,
1934 .transmit_packet = lynx_transmit,
1935 .devctl = lynx_devctl,
1939 MODULE_AUTHOR("Andreas E. Bombe <andreas.bombe@munich.netsurf.de>");
1940 MODULE_DESCRIPTION("driver for Texas Instruments PCI Lynx IEEE-1394 controller");
1941 MODULE_LICENSE("GPL");
1942 MODULE_SUPPORTED_DEVICE("pcilynx");
1943 MODULE_DEVICE_TABLE(pci, pci_table);
1945 static int __init pcilynx_init(void)
1949 #ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1950 if (register_chrdev(PCILYNX_MAJOR, PCILYNX_DRIVER_NAME, &aux_ops)) {
1951 PRINT_G(KERN_ERR, "allocation of char major number %d failed",
1957 ret = pci_module_init(&lynx_pci_driver);
1959 PRINT_G(KERN_ERR, "PCI module init failed");
1966 #ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1967 unregister_chrdev(PCILYNX_MAJOR, PCILYNX_DRIVER_NAME);
1973 static void __exit pcilynx_cleanup(void)
1975 pci_unregister_driver(&lynx_pci_driver);
1977 #ifdef CONFIG_IEEE1394_PCILYNX_PORTS
1978 unregister_chrdev(PCILYNX_MAJOR, PCILYNX_DRIVER_NAME);
1983 module_init(pcilynx_init);
1984 module_exit(pcilynx_cleanup);