Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux...
[pandora-kernel.git] / drivers / firewire / fw-sbp2.c
index 3021602..b2458bb 100644 (file)
@@ -153,6 +153,7 @@ struct sbp2_target {
        struct list_head lu_list;
 
        u64 management_agent_address;
+       u64 guid;
        int directory_id;
        int node_id;
        int address_high;
@@ -173,10 +174,8 @@ struct sbp2_target {
 #define SBP2_ORB_TIMEOUT               2000U   /* Timeout in ms */
 #define SBP2_ORB_NULL                  0x80000000
 #define SBP2_MAX_SG_ELEMENT_LENGTH     0xf000
-#define SBP2_RETRY_LIMIT               0xf     /* 15 retries */
-
-#define SBP2_DIRECTION_TO_MEDIA                0x0
-#define SBP2_DIRECTION_FROM_MEDIA      0x1
+#define SBP2_RETRY_LIMIT               0xf             /* 15 retries */
+#define SBP2_CYCLE_LIMIT               (0xc8 << 12)    /* 200 125us cycles */
 
 /* Unit directory keys */
 #define SBP2_CSR_UNIT_CHARACTERISTICS  0x3a
@@ -273,7 +272,7 @@ struct sbp2_login_response {
 #define COMMAND_ORB_PAGE_TABLE_PRESENT ((1) << 19)
 #define COMMAND_ORB_MAX_PAYLOAD(v)     ((v) << 20)
 #define COMMAND_ORB_SPEED(v)           ((v) << 24)
-#define COMMAND_ORB_DIRECTION(v)       ((v) << 27)
+#define COMMAND_ORB_DIRECTION          ((1) << 27)
 #define COMMAND_ORB_REQUEST_FORMAT(v)  ((v) << 29)
 #define COMMAND_ORB_NOTIFY             ((1) << 31)
 
@@ -696,10 +695,8 @@ static void sbp2_conditionally_block(struct sbp2_logical_unit *lu)
        if (!tgt->dont_block && !lu->blocked &&
            lu->generation != card->generation) {
                lu->blocked = true;
-               if (++tgt->blocked == 1) {
+               if (++tgt->blocked == 1)
                        scsi_block_requests(shost);
-                       fw_notify("blocked %s\n", lu->tgt->bus_id);
-               }
        }
        spin_unlock_irqrestore(&card->lock, flags);
 }
@@ -726,10 +723,8 @@ static void sbp2_conditionally_unblock(struct sbp2_logical_unit *lu)
        }
        spin_unlock_irqrestore(&card->lock, flags);
 
-       if (unblock) {
+       if (unblock)
                scsi_unblock_requests(shost);
-               fw_notify("unblocked %s\n", lu->tgt->bus_id);
-       }
 }
 
 /*
@@ -789,7 +784,7 @@ static void sbp2_release_target(struct kref *kref)
                kfree(lu);
        }
        scsi_remove_host(shost);
-       fw_notify("released %s\n", tgt->bus_id);
+       fw_notify("released %s, target %d:0:0\n", tgt->bus_id, shost->host_no);
 
        fw_unit_put(tgt->unit);
        scsi_host_put(shost);
@@ -820,6 +815,22 @@ complete_set_busy_timeout(struct fw_card *card, int rcode,
        complete(done);
 }
 
+/*
+ * Write retransmit retry values into the BUSY_TIMEOUT register.
+ * - The single-phase retry protocol is supported by all SBP-2 devices, but the
+ *   default retry_limit value is 0 (i.e. never retry transmission). We write a
+ *   saner value after logging into the device.
+ * - The dual-phase retry protocol is optional to implement, and if not
+ *   supported, writes to the dual-phase portion of the register will be
+ *   ignored. We try to write the original 1394-1995 default here.
+ * - In the case of devices that are also SBP-3-compliant, all writes are
+ *   ignored, as the register is read-only, but contains single-phase retry of
+ *   15, which is what we're trying to set for all SBP-2 device anyway, so this
+ *   write attempt is safe and yields more consistent behavior for all devices.
+ *
+ * See section 8.3.2.3.5 of the 1394-1995 spec, section 6.2 of the SBP-2 spec,
+ * and section 6.4 of the SBP-3 spec for further details.
+ */
 static void sbp2_set_busy_timeout(struct sbp2_logical_unit *lu)
 {
        struct fw_device *device = fw_device(lu->tgt->unit->device.parent);
@@ -827,8 +838,7 @@ static void sbp2_set_busy_timeout(struct sbp2_logical_unit *lu)
        struct fw_transaction t;
        static __be32 busy_timeout;
 
-       /* FIXME: we should try to set dual-phase cycle_limit too */
-       busy_timeout = cpu_to_be32(SBP2_RETRY_LIMIT);
+       busy_timeout = cpu_to_be32(SBP2_CYCLE_LIMIT | SBP2_RETRY_LIMIT);
 
        fw_send_request(device->card, &t, TCODE_WRITE_QUADLET_REQUEST,
                        lu->tgt->node_id, lu->generation, device->max_speed,
@@ -1105,6 +1115,7 @@ static int sbp2_probe(struct device *dev)
        kref_init(&tgt->kref);
        INIT_LIST_HEAD(&tgt->lu_list);
        tgt->bus_id = unit->device.bus_id;
+       tgt->guid = (u64)device->config_rom[3] << 32 | device->config_rom[4];
 
        if (fw_device_enable_phys_dma(device) < 0)
                goto fail_shost_put;
@@ -1457,7 +1468,6 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
        orb->cmd  = cmd;
 
        orb->request.next.high   = cpu_to_be32(SBP2_ORB_NULL);
-       orb->request.next.low    = 0x0;
        /*
         * At speed 100 we can do 512 bytes per packet, at speed 200,
         * 1024 bytes per packet etc.  The SBP-2 max_payload field
@@ -1472,18 +1482,12 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
                COMMAND_ORB_NOTIFY);
 
        if (cmd->sc_data_direction == DMA_FROM_DEVICE)
-               orb->request.misc |= cpu_to_be32(
-                       COMMAND_ORB_DIRECTION(SBP2_DIRECTION_FROM_MEDIA));
-       else if (cmd->sc_data_direction == DMA_TO_DEVICE)
-               orb->request.misc |= cpu_to_be32(
-                       COMMAND_ORB_DIRECTION(SBP2_DIRECTION_TO_MEDIA));
+               orb->request.misc |= cpu_to_be32(COMMAND_ORB_DIRECTION);
 
        if (scsi_sg_count(cmd) && sbp2_map_scatterlist(orb, device, lu) < 0)
                goto out;
 
-       memset(orb->request.command_block,
-              0, sizeof(orb->request.command_block));
-       memcpy(orb->request.command_block, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd));
+       memcpy(orb->request.command_block, cmd->cmnd, cmd->cmd_len);
 
        orb->base.callback = complete_command_orb;
        orb->base.request_bus =
@@ -1569,16 +1573,14 @@ sbp2_sysfs_ieee1394_id_show(struct device *dev, struct device_attribute *attr,
 {
        struct scsi_device *sdev = to_scsi_device(dev);
        struct sbp2_logical_unit *lu;
-       struct fw_device *device;
 
        if (!sdev)
                return 0;
 
        lu = sdev->hostdata;
-       device = fw_device(lu->tgt->unit->device.parent);
 
-       return sprintf(buf, "%08x%08x:%06x:%04x\n",
-                       device->config_rom[3], device->config_rom[4],
+       return sprintf(buf, "%016llx:%06x:%04x\n",
+                       (unsigned long long)lu->tgt->guid,
                        lu->tgt->directory_id, lu->lun);
 }