~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux-2.6.17/drivers/ieee1394/pcilynx.c

Version: ~ [ 2.6.16 ] ~ [ 2.6.17 ] ~
Architecture: ~ [ ia64 ] ~ [ i386 ] ~ [ arm ] ~ [ ppc ] ~ [ sparc64 ] ~

  1 /*
  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>
  6  *
  7  * This program is free software; you can redistribute it and/or modify
  8  * it under the terms of the GNU General Public License as published by
  9  * the Free Software Foundation; either version 2 of the License, or
 10  * (at your option) any later version.
 11  *
 12  * This program is distributed in the hope that it will be useful,
 13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15  * GNU General Public License for more details.
 16  *
 17  * You should have received a copy of the GNU General Public License
 18  * along with this program; if not, write to the Free Software Foundation,
 19  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 20  */
 21 
 22 /*
 23  * Contributions:
 24  *
 25  * Manfred Weihs <weihs@ict.tuwien.ac.at>
 26  *        reading bus info block (containing GUID) from serial
 27  *            eeprom via i2c and storing it in config ROM
 28  *        Reworked code for initiating bus resets
 29  *            (long, short, with or without hold-off)
 30  *        Enhancements in async and iso send code
 31  */
 32 
 33 #include <linux/config.h>
 34 #include <linux/kernel.h>
 35 #include <linux/slab.h>
 36 #include <linux/interrupt.h>
 37 #include <linux/wait.h>
 38 #include <linux/errno.h>
 39 #include <linux/module.h>
 40 #include <linux/moduleparam.h>
 41 #include <linux/init.h>
 42 #include <linux/pci.h>
 43 #include <linux/fs.h>
 44 #include <linux/poll.h>
 45 #include <linux/kdev_t.h>
 46 #include <linux/dma-mapping.h>
 47 #include <asm/byteorder.h>
 48 #include <asm/atomic.h>
 49 #include <asm/io.h>
 50 #include <asm/uaccess.h>
 51 #include <asm/irq.h>
 52 
 53 #include "csr1212.h"
 54 #include "ieee1394.h"
 55 #include "ieee1394_types.h"
 56 #include "hosts.h"
 57 #include "ieee1394_core.h"
 58 #include "highlevel.h"
 59 #include "pcilynx.h"
 60 
 61 #include <linux/i2c.h>
 62 #include <linux/i2c-algo-bit.h>
 63 
 64 /* print general (card independent) information */
 65 #define PRINT_G(level, fmt, args...) printk(level "pcilynx: " fmt "\n" , ## args)
 66 /* print card specific information */
 67 #define PRINT(level, card, fmt, args...) printk(level "pcilynx%d: " fmt "\n" , card , ## args)
 68 
 69 #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
 70 #define PRINT_GD(level, fmt, args...) printk(level "pcilynx: " fmt "\n" , ## args)
 71 #define PRINTD(level, card, fmt, args...) printk(level "pcilynx%d: " fmt "\n" , card , ## args)
 72 #else
 73 #define PRINT_GD(level, fmt, args...) do {} while (0)
 74 #define PRINTD(level, card, fmt, args...) do {} while (0)
 75 #endif
 76 
 77 
 78 /* Module Parameters */
 79 static int skip_eeprom;
 80 module_param(skip_eeprom, int, 0444);
 81 MODULE_PARM_DESC(skip_eeprom, "Use generic bus info block instead of serial eeprom (default = 0).");
 82 
 83 
 84 static struct hpsb_host_driver lynx_driver;
 85 static unsigned int card_id;
 86 
 87 
 88 
 89 /*
 90  * I2C stuff
 91  */
 92 
 93 /* the i2c stuff was inspired by i2c-philips-par.c */
 94 
 95 static void bit_setscl(void *data, int state)
 96 {
 97         if (state) {
 98                   ((struct ti_lynx *) data)->i2c_driven_state |= 0x00000040;
 99         } else {
100                   ((struct ti_lynx *) data)->i2c_driven_state &= ~0x00000040;
101         }
102         reg_write((struct ti_lynx *) data, SERIAL_EEPROM_CONTROL, ((struct ti_lynx *) data)->i2c_driven_state);
103 }
104 
105 static void bit_setsda(void *data, int state)
106 {
107         if (state) {
108                   ((struct ti_lynx *) data)->i2c_driven_state |= 0x00000010;
109         } else {
110                   ((struct ti_lynx *) data)->i2c_driven_state &= ~0x00000010;
111         }
112         reg_write((struct ti_lynx *) data, SERIAL_EEPROM_CONTROL, ((struct ti_lynx *) data)->i2c_driven_state);
113 }
114 
115 static int bit_getscl(void *data)
116 {
117         return reg_read((struct ti_lynx *) data, SERIAL_EEPROM_CONTROL) & 0x00000040;
118 }
119 
120 static int bit_getsda(void *data)
121 {
122         return reg_read((struct ti_lynx *) data, SERIAL_EEPROM_CONTROL) & 0x00000010;
123 }
124 
125 static int bit_reg(struct i2c_client *client)
126 {
127         return 0;
128 }
129 
130 static int bit_unreg(struct i2c_client *client)
131 {
132         return 0;
133 }
134 
135 static struct i2c_algo_bit_data bit_data = {
136         .setsda                 = bit_setsda,
137         .setscl                 = bit_setscl,
138         .getsda                 = bit_getsda,
139         .getscl                 = bit_getscl,
140         .udelay                 = 5,
141         .mdelay                 = 5,
142         .timeout                = 100,
143 };
144 
145 static struct i2c_adapter bit_ops = {
146         .id                     = 0xAA, //FIXME: probably we should get an id in i2c-id.h
147         .client_register        = bit_reg,
148         .client_unregister      = bit_unreg,
149         .name                   = "PCILynx I2C",
150 };
151 
152 
153 
154 /*
155  * PCL handling functions.
156  */
157 
158 static pcl_t alloc_pcl(struct ti_lynx *lynx)
159 {
160         u8 m;
161         int i, j;
162 
163         spin_lock(&lynx->lock);
164         /* FIXME - use ffz() to make this readable */
165         for (i = 0; i < (LOCALRAM_SIZE / 1024); i++) {
166                 m = lynx->pcl_bmap[i];
167                 for (j = 0; j < 8; j++) {
168                         if (m & 1<<j) {
169                                 continue;
170                         }
171                         m |= 1<<j;
172                         lynx->pcl_bmap[i] = m;
173                         spin_unlock(&lynx->lock);
174                         return 8 * i + j;
175                 }
176         }
177         spin_unlock(&lynx->lock);
178 
179         return -1;
180 }
181 
182 
183 #if 0
184 static void free_pcl(struct ti_lynx *lynx, pcl_t pclid)
185 {
186         int off, bit;
187 
188         off = pclid / 8;
189         bit = pclid % 8;
190 
191         if (pclid < 0) {
192                 return;
193         }
194 
195         spin_lock(&lynx->lock);
196         if (lynx->pcl_bmap[off] & 1<<bit) {
197                 lynx->pcl_bmap[off] &= ~(1<<bit);
198         } else {
199                 PRINT(KERN_ERR, lynx->id,
200                       "attempted to free unallocated PCL %d", pclid);
201         }
202         spin_unlock(&lynx->lock);
203 }
204 
205 /* functions useful for debugging */
206 static void pretty_print_pcl(const struct ti_pcl *pcl)
207 {
208         int i;
209 
210         printk("PCL next %08x, userdata %08x, status %08x, remtrans %08x, nextbuf %08x\n",
211                pcl->next, pcl->user_data, pcl->pcl_status,
212                pcl->remaining_transfer_count, pcl->next_data_buffer);
213 
214         printk("PCL");
215         for (i=0; i<13; i++) {
216                 printk(" c%x:%08x d%x:%08x",
217                        i, pcl->buffer[i].control, i, pcl->buffer[i].pointer);
218                 if (!(i & 0x3) && (i != 12)) printk("\nPCL");
219         }
220         printk("\n");
221 }
222 
223 static void print_pcl(const struct ti_lynx *lynx, pcl_t pclid)
224 {
225         struct ti_pcl pcl;
226 
227         get_pcl(lynx, pclid, &pcl);
228         pretty_print_pcl(&pcl);
229 }
230 #endif
231 
232 
233 
234 /***********************************
235  * IEEE-1394 functionality section *
236  ***********************************/
237 
238 
239 static int get_phy_reg(struct ti_lynx *lynx, int addr)
240 {
241         int retval;
242         int i = 0;
243 
244         unsigned long flags;
245 
246         if (addr > 15) {
247                 PRINT(KERN_ERR, lynx->id,
248                       "%s: PHY register address %d out of range",
249                       __FUNCTION__, addr);
250                 return -1;
251         }
252 
253         spin_lock_irqsave(&lynx->phy_reg_lock, flags);
254 
255         reg_write(lynx, LINK_PHY, LINK_PHY_READ | LINK_PHY_ADDR(addr));
256         do {
257                 retval = reg_read(lynx, LINK_PHY);
258 
259                 if (i > 10000) {
260                         PRINT(KERN_ERR, lynx->id, "%s: runaway loop, aborting",
261                               __FUNCTION__);
262                         retval = -1;
263                         break;
264                 }
265                 i++;
266         } while ((retval & 0xf00) != LINK_PHY_RADDR(addr));
267 
268         reg_write(lynx, LINK_INT_STATUS, LINK_INT_PHY_REG_RCVD);
269         spin_unlock_irqrestore(&lynx->phy_reg_lock, flags);
270 
271         if (retval != -1) {
272                 return retval & 0xff;
273         } else {
274                 return -1;
275         }
276 }
277 
278 static int set_phy_reg(struct ti_lynx *lynx, int addr, int val)
279 {
280         unsigned long flags;
281 
282         if (addr > 15) {
283                 PRINT(KERN_ERR, lynx->id,
284                       "%s: PHY register address %d out of range", __FUNCTION__, addr);
285                 return -1;
286         }
287 
288         if (val > 0xff) {
289                 PRINT(KERN_ERR, lynx->id,
290                       "%s: PHY register value %d out of range", __FUNCTION__, val);
291                 return -1;
292         }
293 
294         spin_lock_irqsave(&lynx->phy_reg_lock, flags);
295 
296         reg_write(lynx, LINK_PHY, LINK_PHY_WRITE | LINK_PHY_ADDR(addr)
297                   | LINK_PHY_WDATA(val));
298 
299         spin_unlock_irqrestore(&lynx->phy_reg_lock, flags);
300 
301         return 0;
302 }
303 
304 static int sel_phy_reg_page(struct ti_lynx *lynx, int page)
305 {
306         int reg;
307 
308         if (page > 7) {
309                 PRINT(KERN_ERR, lynx->id,
310                       "%s: PHY page %d out of range", __FUNCTION__, page);
311                 return -1;
312         }
313 
314         reg = get_phy_reg(lynx, 7);
315         if (reg != -1) {
316                 reg &= 0x1f;
317                 reg |= (page << 5);
318                 set_phy_reg(lynx, 7, reg);
319                 return 0;
320         } else {
321                 return -1;
322         }
323 }
324 
325 #if 0 /* not needed at this time */
326 static int sel_phy_reg_port(struct ti_lynx *lynx, int port)
327 {
328         int reg;
329 
330         if (port > 15) {
331                 PRINT(KERN_ERR, lynx->id,
332                       "%s: PHY port %d out of range", __FUNCTION__, port);
333                 return -1;
334         }
335 
336         reg = get_phy_reg(lynx, 7);
337         if (reg != -1) {
338                 reg &= 0xf0;
339                 reg |= port;
340                 set_phy_reg(lynx, 7, reg);
341                 return 0;
342         } else {
343                 return -1;
344         }
345 }
346 #endif
347 
348 static u32 get_phy_vendorid(struct ti_lynx *lynx)
349 {
350         u32 pvid = 0;
351         sel_phy_reg_page(lynx, 1);
352         pvid |= (get_phy_reg(lynx, 10) << 16);
353         pvid |= (get_phy_reg(lynx, 11) << 8);
354         pvid |= get_phy_reg(lynx, 12);
355         PRINT(KERN_INFO, lynx->id, "PHY vendor id 0x%06x", pvid);
356         return pvid;
357 }
358 
359 static u32 get_phy_productid(struct ti_lynx *lynx)
360 {
361         u32 id = 0;
362         sel_phy_reg_page(lynx, 1);
363         id |= (get_phy_reg(lynx, 13) << 16);
364         id |= (get_phy_reg(lynx, 14) << 8);
365         id |= get_phy_reg(lynx, 15);
366         PRINT(KERN_INFO, lynx->id, "PHY product id 0x%06x", id);
367         return id;
368 }
369 
370 static quadlet_t generate_own_selfid(struct ti_lynx *lynx,
371                                      struct hpsb_host *host)
372 {
373         quadlet_t lsid;
374         char phyreg[7];
375         int i;
376 
377         phyreg[0] = lynx->phy_reg0;
378         for (i = 1; i < 7; i++) {
379                 phyreg[i] = get_phy_reg(lynx, i);
380         }
381 
382         /* FIXME? We assume a TSB21LV03A phy here.  This code doesn't support
383            more than 3 ports on the PHY anyway. */
384 
385         lsid = 0x80400000 | ((phyreg[0] & 0xfc) << 22);
386         lsid |= (phyreg[1] & 0x3f) << 16; /* gap count */
387         lsid |= (phyreg[2] & 0xc0) << 8; /* max speed */
388         if (!hpsb_disable_irm)
389                 lsid |= (phyreg[6] & 0x01) << 11; /* contender (phy dependent) */
390         /* lsid |= 1 << 11; *//* set contender (hack) */
391         lsid |= (phyreg[6] & 0x10) >> 3; /* initiated reset */
392 
393         for (i = 0; i < (phyreg[2] & 0xf); i++) { /* ports */
394                 if (phyreg[3 + i] & 0x4) {
395                         lsid |= (((phyreg[3 + i] & 0x8) | 0x10) >> 3)
396                                 << (6 - i*2);
397                 } else {
398                         lsid |= 1 << (6 - i*2);
399                 }
400         }
401 
402         cpu_to_be32s(&lsid);
403         PRINT(KERN_DEBUG, lynx->id, "generated own selfid 0x%x", lsid);
404         return lsid;
405 }
406 
407 static void handle_selfid(struct ti_lynx *lynx, struct hpsb_host *host)
408 {
409         quadlet_t *q = lynx->rcv_page;
410         int phyid, isroot, size;
411         quadlet_t lsid = 0;
412         int i;
413 
414         if (lynx->phy_reg0 == -1 || lynx->selfid_size == -1) return;
415 
416         size = lynx->selfid_size;
417         phyid = lynx->phy_reg0;
418 
419         i = (size > 16 ? 16 : size) / 4 - 1;
420         while (i >= 0) {
421                 cpu_to_be32s(&q[i]);
422                 i--;
423         }
424 
425         if (!lynx->phyic.reg_1394a) {
426                 lsid = generate_own_selfid(lynx, host);
427         }
428 
429         isroot = (phyid & 2) != 0;
430         phyid >>= 2;
431         PRINT(KERN_INFO, lynx->id, "SelfID process finished (phyid %d, %s)",
432               phyid, (isroot ? "root" : "not root"));
433         reg_write(lynx, LINK_ID, (0xffc0 | phyid) << 16);
434 
435         if (!lynx->phyic.reg_1394a && !size) {
436                 hpsb_selfid_received(host, lsid);
437         }
438 
439         while (size > 0) {
440                 struct selfid *sid = (struct selfid *)q;
441 
442                 if (!lynx->phyic.reg_1394a && !sid->extended
443                     && (sid->phy_id == (phyid + 1))) {
444                         hpsb_selfid_received(host, lsid);
445                 }
446 
447                 if (q[0] == ~q[1]) {
448                         PRINT(KERN_DEBUG, lynx->id, "SelfID packet 0x%x rcvd",
449                               q[0]);
450                         hpsb_selfid_received(host, q[0]);
451                 } else {
452                         PRINT(KERN_INFO, lynx->id,
453                               "inconsistent selfid 0x%x/0x%x", q[0], q[1]);
454                 }
455                 q += 2;
456                 size -= 8;
457         }
458 
459         if (!lynx->phyic.reg_1394a && isroot && phyid != 0) {
460                 hpsb_selfid_received(host, lsid);
461         }
462 
463         hpsb_selfid_complete(host, phyid, isroot);
464 
465         if (host->in_bus_reset) return; /* in bus reset again */
466 
467         if (isroot) reg_set_bits(lynx, LINK_CONTROL, LINK_CONTROL_CYCMASTER); //FIXME: I do not think, we need this here
468         reg_set_bits(lynx, LINK_CONTROL,
469                      LINK_CONTROL_RCV_CMP_VALID | LINK_CONTROL_TX_ASYNC_EN
470                      | LINK_CONTROL_RX_ASYNC_EN | LINK_CONTROL_CYCTIMEREN);
471 }
472 
473 
474 
475 /* This must be called with the respective queue_lock held. */
476 static void send_next(struct ti_lynx *lynx, int what)
477 {
478         struct ti_pcl pcl;
479         struct lynx_send_data *d;
480         struct hpsb_packet *packet;
481 
482         d = (what == hpsb_iso ? &lynx->iso_send : &lynx->async);
483         if (!list_empty(&d->pcl_queue)) {
484                 PRINT(KERN_ERR, lynx->id, "trying to queue a new packet in nonempty fifo");
485                 BUG();
486         }
487 
488         packet = driver_packet(d->queue.next);
489         list_move_tail(&packet->driver_list, &d->pcl_queue);
490 
491         d->header_dma = pci_map_single(lynx->dev, packet->header,
492                                        packet->header_size, PCI_DMA_TODEVICE);
493         if (packet->data_size) {
494                 d->data_dma = pci_map_single(lynx->dev, packet->data,
495                                              packet->data_size,
496                                              PCI_DMA_TODEVICE);
497         } else {
498                 d->data_dma = 0;
499         }
500 
501         pcl.next = PCL_NEXT_INVALID;
502         pcl.async_error_next = PCL_NEXT_INVALID;
503         pcl.pcl_status = 0;
504         pcl.buffer[0].control = packet->speed_code << 14 | packet->header_size;
505 #ifndef __BIG_ENDIAN
506         pcl.buffer[0].control |= PCL_BIGENDIAN;
507 #endif
508         pcl.buffer[0].pointer = d->header_dma;
509         pcl.buffer[1].control = PCL_LAST_BUFF | packet->data_size;
510         pcl.buffer[1].pointer = d->data_dma;
511 
512         switch (packet->type) {
513         case hpsb_async:
514                 pcl.buffer[0].control |= PCL_CMD_XMT;
515                 break;
516         case hpsb_iso:
517                 pcl.buffer[0].control |= PCL_CMD_XMT | PCL_ISOMODE;
518                 break;
519         case hpsb_raw:
520                 pcl.buffer[0].control |= PCL_CMD_UNFXMT;
521                 break;
522         }
523 
524         put_pcl(lynx, d->pcl, &pcl);
525         run_pcl(lynx, d->pcl_start, d->channel);
526 }
527 
528 
529 /* called from subsystem core */
530 static int lynx_transmit(struct hpsb_host *host, struct hpsb_packet *packet)
531 {
532         struct ti_lynx *lynx = host->hostdata;
533         struct lynx_send_data *d;
534         unsigned long flags;
535 
536         if (packet->data_size >= 4096) {
537                 PRINT(KERN_ERR, lynx->id, "transmit packet data too big (%Zd)",
538                       packet->data_size);
539                 return -EOVERFLOW;
540         }
541 
542         switch (packet->type) {
543         case hpsb_async:
544         case hpsb_raw:
545                 d = &lynx->async;
546                 break;
547         case hpsb_iso:
548                 d = &lynx->iso_send;
549                 break;
550         default:
551                 PRINT(KERN_ERR, lynx->id, "invalid packet type %d",
552                       packet->type);
553                 return -EINVAL;
554         }
555 
556         if (packet->tcode == TCODE_WRITEQ
557             || packet->tcode == TCODE_READQ_RESPONSE) {
558                 cpu_to_be32s(&packet->header[3]);
559         }
560 
561         spin_lock_irqsave(&d->queue_lock, flags);
562 
563         list_add_tail(&packet->driver_list, &d->queue);
564         if (list_empty(&d->pcl_queue))
565                 send_next(lynx, packet->type);
566 
567         spin_unlock_irqrestore(&d->queue_lock, flags);
568 
569         return 0;
570 }
571 
572 
573 /* called from subsystem core */
574 static int lynx_devctl(struct hpsb_host *host, enum devctl_cmd cmd, int arg)
575 {
576         struct ti_lynx *lynx = host->hostdata;
577         int retval = 0;
578         struct hpsb_packet *packet;
579         LIST_HEAD(packet_list);
580         unsigned long flags;
581         int phy_reg;
582 
583         switch (cmd) {
584         case RESET_BUS:
585                 if (reg_read(lynx, LINK_INT_STATUS) & LINK_INT_PHY_BUSRESET) {
586                         retval = 0;
587                         break;
588                 }
589 
590                 switch (arg) {
591                 case SHORT_RESET:
592                         if (lynx->phyic.reg_1394a) {
593                                 phy_reg = get_phy_reg(lynx, 5);
594                                 if (phy_reg == -1) {
595                                         PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
596                                         retval = -1;
597                                         break;
598                                 }
599                                 phy_reg |= 0x40;
600 
601                                 PRINT(KERN_INFO, lynx->id, "resetting bus (short bus reset) on request");
602 
603                                 lynx->selfid_size = -1;
604                                 lynx->phy_reg0 = -1;
605                                 set_phy_reg(lynx, 5, phy_reg); /* set ISBR */
606                                 break;
607                         } else {
608                                 PRINT(KERN_INFO, lynx->id, "cannot do short bus reset, because of old phy");
609                                 /* fall through to long bus reset */
610                         }
611                 case LONG_RESET:
612                         phy_reg = get_phy_reg(lynx, 1);
613                         if (phy_reg == -1) {
614                                 PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
615                                 retval = -1;
616                                 break;
617                         }
618                         phy_reg |= 0x40;
619 
620                         PRINT(KERN_INFO, lynx->id, "resetting bus (long bus reset) on request");
621 
622                         lynx->selfid_size = -1;
623                         lynx->phy_reg0 = -1;
624                         set_phy_reg(lynx, 1, phy_reg); /* clear RHB, set IBR */
625                         break;
626                 case SHORT_RESET_NO_FORCE_ROOT:
627                         if (lynx->phyic.reg_1394a) {
628                                 phy_reg = get_phy_reg(lynx, 1);
629                                 if (phy_reg == -1) {
630                                         PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
631                                         retval = -1;
632                                         break;
633                                 }
634                                 if (phy_reg & 0x80) {
635                                         phy_reg &= ~0x80;
636                                         set_phy_reg(lynx, 1, phy_reg); /* clear RHB */
637                                 }
638 
639                                 phy_reg = get_phy_reg(lynx, 5);
640                                 if (phy_reg == -1) {
641                                         PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
642                                         retval = -1;
643                                         break;
644                                 }
645                                 phy_reg |= 0x40;
646 
647                                 PRINT(KERN_INFO, lynx->id, "resetting bus (short bus reset, no force_root) on request");
648 
649                                 lynx->selfid_size = -1;
650                                 lynx->phy_reg0 = -1;
651                                 set_phy_reg(lynx, 5, phy_reg); /* set ISBR */
652                                 break;
653                         } else {
654                                 PRINT(KERN_INFO, lynx->id, "cannot do short bus reset, because of old phy");
655                                 /* fall through to long bus reset */
656                         }
657                 case LONG_RESET_NO_FORCE_ROOT:
658                         phy_reg = get_phy_reg(lynx, 1);
659                         if (phy_reg == -1) {
660                                 PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
661                                 retval = -1;
662                                 break;
663                         }
664                         phy_reg &= ~0x80;
665                         phy_reg |= 0x40;
666 
667                         PRINT(KERN_INFO, lynx->id, "resetting bus (long bus reset, no force_root) on request");
668 
669                         lynx->selfid_size = -1;
670                         lynx->phy_reg0 = -1;
671                         set_phy_reg(lynx, 1, phy_reg); /* clear RHB, set IBR */
672                         break;
673                 case SHORT_RESET_FORCE_ROOT:
674                         if (lynx->phyic.reg_1394a) {
675                                 phy_reg = get_phy_reg(lynx, 1);
676                                 if (phy_reg == -1) {
677                                         PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
678                                         retval = -1;
679                                         break;
680                                 }
681                                 if (!(phy_reg & 0x80)) {
682                                         phy_reg |= 0x80;
683                                         set_phy_reg(lynx, 1, phy_reg); /* set RHB */
684                                 }
685 
686                                 phy_reg = get_phy_reg(lynx, 5);
687                                 if (phy_reg == -1) {
688                                         PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
689                                         retval = -1;
690                                         break;
691                                 }
692                                 phy_reg |= 0x40;
693 
694                                 PRINT(KERN_INFO, lynx->id, "resetting bus (short bus reset, force_root set) on request");
695 
696                                 lynx->selfid_size = -1;
697                                 lynx->phy_reg0 = -1;
698                                 set_phy_reg(lynx, 5, phy_reg); /* set ISBR */
699                                 break;
700                         } else {
701                                 PRINT(KERN_INFO, lynx->id, "cannot do short bus reset, because of old phy");
702                                 /* fall through to long bus reset */
703                         }
704                 case LONG_RESET_FORCE_ROOT:
705                         phy_reg = get_phy_reg(lynx, 1);
706                         if (phy_reg == -1) {
707                                 PRINT(KERN_ERR, lynx->id, "cannot reset bus, because read phy reg failed");
708                                 retval = -1;
709                                 break;
710                         }
711                         phy_reg |= 0xc0;
712 
713                         PRINT(KERN_INFO, lynx->id, "resetting bus (long bus reset, force_root set) on request");
714 
715                         lynx->selfid_size = -1;
716                         lynx->phy_reg0 = -1;
717                         set_phy_reg(lynx, 1, phy_reg); /* set IBR and RHB */
718                         break;
719                 default:
720                         PRINT(KERN_ERR, lynx->id, "unknown argument for reset_bus command %d", arg);
721                         retval = -1;
722                 }
723 
724                 break;
725 
726         case GET_CYCLE_COUNTER:
727                 retval = reg_read(lynx, CYCLE_TIMER);
728                 break;
729 
730         case SET_CYCLE_COUNTER:
731                 reg_write(lynx, CYCLE_TIMER, arg);
732                 break;
733 
734         case SET_BUS_ID:
735                 reg_write(lynx, LINK_ID,
736                           (arg << 22) | (reg_read(lynx, LINK_ID) & 0x003f0000));
737                 break;
738 
739         case ACT_CYCLE_MASTER:
740                 if (arg) {
741                         reg_set_bits(lynx, LINK_CONTROL,
742                                      LINK_CONTROL_CYCMASTER);
743                 } else {
744                         reg_clear_bits(lynx, LINK_CONTROL,
745                                        LINK_CONTROL_CYCMASTER);
746                 }
747                 break;
748 
749         case CANCEL_REQUESTS:
750                 spin_lock_irqsave(&lynx->async.queue_lock, flags);
751 
752                 reg_write(lynx, DMA_CHAN_CTRL(CHANNEL_ASYNC_SEND), 0);
753                 list_splice(&lynx->async.queue, &packet_list);
754                 INIT_LIST_HEAD(&lynx->async.queue);
755 
756                 if (list_empty(&lynx->async.pcl_queue)) {
757                         spin_unlock_irqrestore(&lynx->async.queue_lock, flags);
758                         PRINTD(KERN_DEBUG, lynx->id, "no async packet in PCL to cancel");
759                 } else {
760                         struct ti_pcl pcl;
761                         u32 ack;
762                         struct hpsb_packet *packet;
763 
764                         PRINT(KERN_INFO, lynx->id, "cancelling async packet, that was already in PCL");
765 
766                         get_pcl(lynx, lynx->async.pcl, &pcl);
767 
768                         packet = driver_packet(lynx->async.pcl_queue.next);
769                         list_del_init(&packet->driver_list);
770 
771                         pci_unmap_single(lynx->dev, lynx->async.header_dma,
772                                          packet->header_size, PCI_DMA_TODEVICE);
773                         if (packet->data_size) {
774                                 pci_unmap_single(lynx->dev, lynx->async.data_dma,
775                                                  packet->data_size, PCI_DMA_TODEVICE);
776                         }
777 
778                         spin_unlock_irqrestore(&lynx->async.queue_lock, flags);
779 
780                         if (pcl.pcl_status & DMA_CHAN_STAT_PKTCMPL) {
781                                 if (pcl.pcl_status & DMA_CHAN_STAT_SPECIALACK) {
782                                         ack = (pcl.pcl_status >> 15) & 0xf;
783                                         PRINTD(KERN_INFO, lynx->id, "special ack %d", ack);
784                                         ack = (ack == 1 ? ACKX_TIMEOUT : ACKX_SEND_ERROR);
785                                 } else {
786                                         ack = (pcl.pcl_status >> 15) & 0xf;
787                                 }
788                         } else {
789                                 PRINT(KERN_INFO, lynx->id, "async packet was not completed");
790                                 ack = ACKX_ABORTED;
791                         }
792                         hpsb_packet_sent(host, packet, ack);
793                 }
794 
795                 while (!list_empty(&packet_list)) {
796                         packet = driver_packet(packet_list.next);
797                         list_del_init(&packet->driver_list);
798                         hpsb_packet_sent(host, packet, ACKX_ABORTED);
799                 }
800 
801                 break;
802 
803         case ISO_LISTEN_CHANNEL:
804                 spin_lock_irqsave(&lynx->iso_rcv.lock, flags);
805 
806                 if (lynx->iso_rcv.chan_count++ == 0) {
807                         reg_write(lynx, DMA_WORD1_CMP_ENABLE(CHANNEL_ISO_RCV),
808                                   DMA_WORD1_CMP_ENABLE_MASTER);
809                 }
810 
811                 spin_unlock_irqrestore(&lynx->iso_rcv.lock, flags);
812                 break;
813 
814         case ISO_UNLISTEN_CHANNEL:
815                 spin_lock_irqsave(&lynx->iso_rcv.lock, flags);
816 
817                 if (--lynx->iso_rcv.chan_count == 0) {
818                         reg_write(lynx, DMA_WORD1_CMP_ENABLE(CHANNEL_ISO_RCV),
819                                   0);
820                 }
821 
822                 spin_unlock_irqrestore(&lynx->iso_rcv.lock, flags);
823                 break;
824 
825         default:
826                 PRINT(KERN_ERR, lynx->id, "unknown devctl command %d", cmd);
827                 retval = -1;
828         }
829 
830         return retval;
831 }
832 
833 
834 /***************************************
835  * IEEE-1394 functionality section END *
836  ***************************************/
837 
838 
839 /********************************************************
840  * Global stuff (interrupt handler, init/shutdown code) *
841  ********************************************************/
842 
843 
844 static irqreturn_t lynx_irq_handler(int irq, void *dev_id,
845                              struct pt_regs *regs_are_unused)
846 {
847         struct ti_lynx *lynx = (struct ti_lynx *)dev_id;
848         struct hpsb_host *host = lynx->host;
849         u32 intmask;
850         u32 linkint;
851 
852         linkint = reg_read(lynx, LINK_INT_STATUS);
853         intmask = reg_read(lynx, PCI_INT_STATUS);
854 
855         if (!(intmask & PCI_INT_INT_PEND))
856                 return IRQ_NONE;
857 
858         PRINTD(KERN_DEBUG, lynx->id, "interrupt: 0x%08x / 0x%08x", intmask,
859                linkint);
860 
861         reg_write(lynx, LINK_INT_STATUS, linkint);
862         reg_write(lynx, PCI_INT_STATUS, intmask);
863 
864         if (intmask & PCI_INT_1394) {
865                 if (linkint & LINK_INT_PHY_TIMEOUT) {
866                         PRINT(KERN_INFO, lynx->id, "PHY timeout occurred");
867                 }
868                 if (linkint & LINK_INT_PHY_BUSRESET) {
869                         PRINT(KERN_INFO, lynx->id, "bus reset interrupt");
870                         lynx->selfid_size = -1;
871                         lynx->phy_reg0 = -1;
872                         if (!host->in_bus_reset)
873                                 hpsb_bus_reset(host);
874                 }
875                 if (linkint & LINK_INT_PHY_REG_RCVD) {
876                         u32 reg;
877 
878                         spin_lock(&lynx->phy_reg_lock);
879                         reg = reg_read(lynx, LINK_PHY);
880                         spin_unlock(&lynx->phy_reg_lock);
881 
882                         if (!host->in_bus_reset) {
883                                 PRINT(KERN_INFO, lynx->id,
884                                       "phy reg received without reset");
885                         } else if (reg & 0xf00) {
886                                 PRINT(KERN_INFO, lynx->id,
887                                       "unsolicited phy reg %d received",
888                                       (reg >> 8) & 0xf);
889                         } else {
890                                 lynx->phy_reg0 = reg & 0xff;
891                                 handle_selfid(lynx, host);
892                         }
893                 }
894                 if (linkint & LINK_INT_ISO_STUCK) {
895                         PRINT(KERN_INFO, lynx->id, "isochronous transmitter stuck");
896                 }
897                 if (linkint & LINK_INT_ASYNC_STUCK) {
898                         PRINT(KERN_INFO, lynx->id, "asynchronous transmitter stuck");
899                 }
900                 if (linkint & LINK_INT_SENT_REJECT) {
901                         PRINT(KERN_INFO, lynx->id, "sent reject");
902                 }
903                 if (linkint & LINK_INT_TX_INVALID_TC) {
904                         PRINT(KERN_INFO, lynx->id, "invalid transaction code");
905                 }
906                 if (linkint & LINK_INT_GRF_OVERFLOW) {
907                         /* flush FIFO if overflow happens during reset */
908                         if (host->in_bus_reset)
909                                 reg_write(lynx, FIFO_CONTROL,
910                                           FIFO_CONTROL_GRF_FLUSH);
911                         PRINT(KERN_INFO, lynx->id, "GRF overflow");
912                 }
913                 if (linkint & LINK_INT_ITF_UNDERFLOW) {
914                         PRINT(KERN_INFO, lynx->id, "ITF underflow");
915                 }
916                 if (linkint & LINK_INT_ATF_UNDERFLOW) {
917                         PRINT(KERN_INFO, lynx->id, "ATF underflow");
918                 }
919         }
920 
921         if (intmask & PCI_INT_DMA_HLT(CHANNEL_ISO_RCV)) {
922                 PRINTD(KERN_DEBUG, lynx->id, "iso receive");
923 
924                 spin_lock(&lynx->iso_rcv.lock);
925 
926                 lynx->iso_rcv.stat[lynx->iso_rcv.next] =
927                         reg_read(lynx, DMA_CHAN_STAT(CHANNEL_ISO_RCV));
928 
929                 lynx->iso_rcv.used++;
930                 lynx->iso_rcv.next = (lynx->iso_rcv.next + 1) % NUM_ISORCV_PCL;
931 
932                 if ((lynx->iso_rcv.next == lynx->iso_rcv.last)
933                     || !lynx->iso_rcv.chan_count) {
934                         PRINTD(KERN_DEBUG, lynx->id, "stopped");
935                         reg_write(lynx, DMA_WORD1_CMP_ENABLE(CHANNEL_ISO_RCV), 0);
936                 }
937 
938                 run_sub_pcl(lynx, lynx->iso_rcv.pcl_start, lynx->iso_rcv.next,
939                             CHANNEL_ISO_RCV);
940 
941                 spin_unlock(&lynx->iso_rcv.lock);
942 
943                 tasklet_schedule(&lynx->iso_rcv.tq);
944         }
945 
946         if (intmask & PCI_INT_DMA_HLT(CHANNEL_ASYNC_SEND)) {
947                 PRINTD(KERN_DEBUG, lynx->id, "async sent");
948                 spin_lock(&lynx->async.queue_lock);
949 
950                 if (list_empty(&lynx->async.pcl_queue)) {
951                         spin_unlock(&lynx->async.queue_lock);
952                         PRINT(KERN_WARNING, lynx->id, "async dma halted, but no queued packet (maybe it was cancelled)");
953                 } else {
954                         struct ti_pcl pcl;
955                         u32 ack;
956                         struct hpsb_packet *packet;
957 
958                         get_pcl(lynx, lynx->async.pcl, &pcl);
959 
960                         packet = driver_packet(lynx->async.pcl_queue.next);
961                         list_del_init(&packet->driver_list);
962 
963                         pci_unmap_single(lynx->dev, lynx->async.header_dma,
964                                          packet->header_size, PCI_DMA_TODEVICE);
965                         if (packet->data_size) {
966                                 pci_unmap_single(lynx->dev, lynx->async.data_dma,
967                                                  packet->data_size, PCI_DMA_TODEVICE);
968                         }
969 
970                         if (!list_empty(&lynx->async.queue)) {
971                                 send_next(lynx, hpsb_async);
972                         }
973 
974                         spin_unlock(&lynx->async.