libata-sff: ap->[last_]ctl are SFF specific
[safe/jmp/linux-2.6] / drivers / ieee1394 / ieee1394_transactions.c
index 0833fc9..675b313 100644 (file)
  */
 
 #include <linux/bitops.h>
+#include <linux/compiler.h>
+#include <linux/hardirq.h>
 #include <linux/spinlock.h>
+#include <linux/string.h>
+#include <linux/sched.h>  /* because linux/wait.h is broken if CONFIG_SMP=n */
 #include <linux/wait.h>
 
 #include <asm/bug.h>
 #include <asm/errno.h>
+#include <asm/system.h>
 
 #include "ieee1394.h"
 #include "ieee1394_types.h"
@@ -32,7 +37,7 @@
 #ifndef HPSB_DEBUG_TLABELS
 static
 #endif
-spinlock_t hpsb_tlabel_lock = SPIN_LOCK_UNLOCKED;
+DEFINE_SPINLOCK(hpsb_tlabel_lock);
 
 static DECLARE_WAIT_QUEUE_HEAD(tlabel_wq);
 
@@ -84,18 +89,6 @@ static void fill_async_lock(struct hpsb_packet *packet, u64 addr, int extcode,
        packet->expect_response = 1;
 }
 
-static void fill_iso_packet(struct hpsb_packet *packet, int length, int channel,
-                           int tag, int sync)
-{
-       packet->header[0] = (length << 16) | (tag << 14) | (channel << 8)
-           | (TCODE_ISO_DATA << 4) | sync;
-
-       packet->header_size = 4;
-       packet->data_size = length;
-       packet->type = hpsb_iso;
-       packet->tcode = TCODE_ISO_DATA;
-}
-
 static void fill_phy_packet(struct hpsb_packet *packet, quadlet_t data)
 {
        packet->header[0] = data;
@@ -212,6 +205,15 @@ void hpsb_free_tlabel(struct hpsb_packet *packet)
        wake_up_interruptible(&tlabel_wq);
 }
 
+/**
+ * hpsb_packet_success - Make sense of the ack and reply codes
+ *
+ * Make sense of the ack and reply codes and return more convenient error codes:
+ * 0 = success.  -%EBUSY = node is busy, try again.  -%EAGAIN = error which can
+ * probably resolved by retry.  -%EREMOTEIO = node suffers from an internal
+ * error.  -%EACCES = this transaction is not allowed on requested address.
+ * -%EINVAL = invalid address at node.
+ */
 int hpsb_packet_success(struct hpsb_packet *packet)
 {
        switch (packet->ack_code) {
@@ -233,7 +235,6 @@ int hpsb_packet_success(struct hpsb_packet *packet)
                                 packet->node_id);
                        return -EAGAIN;
                }
-               BUG();
 
        case ACK_BUSY_X:
        case ACK_BUSY_A:
@@ -280,7 +281,6 @@ int hpsb_packet_success(struct hpsb_packet *packet)
                         packet->ack_code, packet->node_id, packet->tcode);
                return -EAGAIN;
        }
-       BUG();
 }
 
 struct hpsb_packet *hpsb_make_readpacket(struct hpsb_host *host, nodeid_t node,
@@ -364,6 +364,13 @@ struct hpsb_packet *hpsb_make_streampacket(struct hpsb_host *host, u8 * buffer,
        }
        packet->host = host;
 
+       /* Because it is too difficult to determine all PHY speeds and link
+        * speeds here, we use S100... */
+       packet->speed_code = IEEE1394_SPEED_100;
+
+       /* ...and prevent hpsb_send_packet() from overriding it. */
+       packet->node_id = LOCAL_BUS | ALL_NODES;
+
        if (hpsb_get_tlabel(packet)) {
                hpsb_free_packet(packet);
                return NULL;
@@ -470,29 +477,21 @@ struct hpsb_packet *hpsb_make_phypacket(struct hpsb_host *host, quadlet_t data)
        return p;
 }
 
-struct hpsb_packet *hpsb_make_isopacket(struct hpsb_host *host,
-                                       int length, int channel,
-                                       int tag, int sync)
-{
-       struct hpsb_packet *p;
-
-       p = hpsb_alloc_packet(length);
-       if (!p)
-               return NULL;
-
-       p->host = host;
-       fill_iso_packet(p, length, channel, tag, sync);
-
-       p->generation = get_hpsb_generation(host);
-
-       return p;
-}
-
 /*
  * FIXME - these functions should probably read from / write to user space to
  * avoid in kernel buffers for user space callers
  */
 
+/**
+ * hpsb_read - generic read function
+ *
+ * Recognizes the local node ID and act accordingly.  Automatically uses a
+ * quadlet read request if @length == 4 and and a block read request otherwise.
+ * It does not yet support lengths that are not a multiple of 4.
+ *
+ * You must explicitly specifiy the @generation for which the node ID is valid,
+ * to avoid sending packets to the wrong nodes when we race with a bus reset.
+ */
 int hpsb_read(struct hpsb_host *host, nodeid_t node, unsigned int generation,
              u64 addr, quadlet_t * buffer, size_t length)
 {
@@ -502,8 +501,6 @@ int hpsb_read(struct hpsb_host *host, nodeid_t node, unsigned int generation,
        if (length == 0)
                return -EINVAL;
 
-       BUG_ON(in_interrupt()); // We can't be called in an interrupt, yet
-
        packet = hpsb_make_readpacket(host, node, addr, length);
 
        if (!packet) {
@@ -532,6 +529,16 @@ int hpsb_read(struct hpsb_host *host, nodeid_t node, unsigned int generation,
        return retval;
 }
 
+/**
+ * hpsb_write - generic write function
+ *
+ * Recognizes the local node ID and act accordingly.  Automatically uses a
+ * quadlet write request if @length == 4 and and a block write request
+ * otherwise.  It does not yet support lengths that are not a multiple of 4.
+ *
+ * You must explicitly specifiy the @generation for which the node ID is valid,
+ * to avoid sending packets to the wrong nodes when we race with a bus reset.
+ */
 int hpsb_write(struct hpsb_host *host, nodeid_t node, unsigned int generation,
               u64 addr, quadlet_t * buffer, size_t length)
 {
@@ -541,8 +548,6 @@ int hpsb_write(struct hpsb_host *host, nodeid_t node, unsigned int generation,
        if (length == 0)
                return -EINVAL;
 
-       BUG_ON(in_interrupt()); // We can't be called in an interrupt, yet
-
        packet = hpsb_make_writepacket(host, node, addr, buffer, length);
 
        if (!packet)
@@ -562,16 +567,12 @@ int hpsb_write(struct hpsb_host *host, nodeid_t node, unsigned int generation,
        return retval;
 }
 
-#if 0
-
 int hpsb_lock(struct hpsb_host *host, nodeid_t node, unsigned int generation,
-             u64 addr, int extcode, quadlet_t * data, quadlet_t arg)
+             u64 addr, int extcode, quadlet_t *data, quadlet_t arg)
 {
        struct hpsb_packet *packet;
        int retval = 0;
 
-       BUG_ON(in_interrupt()); // We can't be called in an interrupt, yet
-
        packet = hpsb_make_lockpacket(host, node, addr, extcode, data, arg);
        if (!packet)
                return -ENOMEM;
@@ -583,49 +584,12 @@ int hpsb_lock(struct hpsb_host *host, nodeid_t node, unsigned int generation,
 
        retval = hpsb_packet_success(packet);
 
-       if (retval == 0) {
+       if (retval == 0)
                *data = packet->data[0];
-       }
 
-      hpsb_lock_fail:
+hpsb_lock_fail:
        hpsb_free_tlabel(packet);
        hpsb_free_packet(packet);
 
        return retval;
 }
-
-int hpsb_send_gasp(struct hpsb_host *host, int channel, unsigned int generation,
-                  quadlet_t * buffer, size_t length, u32 specifier_id,
-                  unsigned int version)
-{
-       struct hpsb_packet *packet;
-       int retval = 0;
-       u16 specifier_id_hi = (specifier_id & 0x00ffff00) >> 8;
-       u8 specifier_id_lo = specifier_id & 0xff;
-
-       HPSB_VERBOSE("Send GASP: channel = %d, length = %Zd", channel, length);
-
-       length += 8;
-
-       packet = hpsb_make_streampacket(host, NULL, length, channel, 3, 0);
-       if (!packet)
-               return -ENOMEM;
-
-       packet->data[0] = cpu_to_be32((host->node_id << 16) | specifier_id_hi);
-       packet->data[1] =
-           cpu_to_be32((specifier_id_lo << 24) | (version & 0x00ffffff));
-
-       memcpy(&(packet->data[2]), buffer, length - 8);
-
-       packet->generation = generation;
-
-       packet->no_waiter = 1;
-
-       retval = hpsb_send_packet(packet);
-       if (retval < 0)
-               hpsb_free_packet(packet);
-
-       return retval;
-}
-
-#endif                         /*  0  */