// SPDX-License-Identifier: GPL-2.0-or-later /* * SBP2 driver (SCSI over IEEE1394) * * Copyright (C) 2005-2007 Kristian Hoegsberg <krh@bitplanet.net>
*/
/* * The basic structure of this driver is based on the old storage driver, * drivers/ieee1394/sbp2.c, originally written by * James Goodwin <jamesg@filanet.com> * with later contributions and ongoing maintenance from * Ben Collins <bcollins@debian.org>, * Stefan Richter <stefanr@s5r6.in-berlin.de> * and many others.
*/
/* * So far only bridges from Oxford Semiconductor are known to support * concurrent logins. Depending on firmware, four or two concurrent logins * are possible on OXFW911 and newer Oxsemi bridges. * * Concurrent logins are useful together with cluster filesystems.
*/ staticbool sbp2_param_exclusive_login = 1;
module_param_named(exclusive_login, sbp2_param_exclusive_login, bool, 0644);
MODULE_PARM_DESC(exclusive_login, "Exclusive login to sbp2 device " "(default = Y, use N for concurrent initiators)");
/* * Flags for firmware oddities * * - 128kB max transfer * Limit transfer size. Necessary for some old bridges. * * - 36 byte inquiry * When scsi_mod probes the device, let the inquiry command look like that * from MS Windows. * * - skip mode page 8 * Suppress sending of mode_sense for mode page 8 if the device pretends to * support the SCSI Primary Block commands instead of Reduced Block Commands. * * - fix capacity * Tell sd_mod to correct the last sector number reported by read_capacity. * Avoids access beyond actual disk limits on devices with an off-by-one bug. * Don't use this with devices which don't have this bug. * * - delay inquiry * Wait extra SBP2_INQUIRY_DELAY seconds after login before SCSI inquiry. * * - power condition * Set the power condition field in the START STOP UNIT commands sent by * sd_mod on suspend, resume, and shutdown (if manage_system_start_stop or * manage_runtime_start_stop is on). * Some disks need this to spin down or to resume properly. * * - override internal blacklist * Instead of adding to the built-in blacklist, use only the workarounds * specified in the module load parameter. * Useful if a blacklist entry interfered with a non-broken device.
*/ #define SBP2_WORKAROUND_128K_MAX_TRANS 0x1 #define SBP2_WORKAROUND_INQUIRY_36 0x2 #define SBP2_WORKAROUND_MODE_SENSE_8 0x4 #define SBP2_WORKAROUND_FIX_CAPACITY 0x8 #define SBP2_WORKAROUND_DELAY_INQUIRY 0x10 #define SBP2_INQUIRY_DELAY 12 #define SBP2_WORKAROUND_POWER_CONDITION 0x20 #define SBP2_WORKAROUND_OVERRIDE 0x100
staticint sbp2_param_workarounds;
module_param_named(workarounds, sbp2_param_workarounds, int, 0644);
MODULE_PARM_DESC(workarounds, "Work around device bugs (default = 0" ", 128kB max transfer = " __stringify(SBP2_WORKAROUND_128K_MAX_TRANS) ", 36 byte inquiry = " __stringify(SBP2_WORKAROUND_INQUIRY_36) ", skip mode page 8 = " __stringify(SBP2_WORKAROUND_MODE_SENSE_8) ", fix capacity = " __stringify(SBP2_WORKAROUND_FIX_CAPACITY) ", delay inquiry = " __stringify(SBP2_WORKAROUND_DELAY_INQUIRY) ", set power condition in start stop unit = "
__stringify(SBP2_WORKAROUND_POWER_CONDITION) ", override internal blacklist = " __stringify(SBP2_WORKAROUND_OVERRIDE) ", or a combination)");
/* * We create one struct sbp2_logical_unit per SBP-2 Logical Unit Number Entry * and one struct scsi_device per sbp2_logical_unit.
*/ struct sbp2_logical_unit { struct sbp2_target *tgt; struct list_head link; struct fw_address_handler address_handler; struct list_head orb_list;
u64 command_block_agent_address;
u16 lun; int login_id;
/* * The generation is updated once we've logged in or reconnected * to the logical unit. Thus, I/O to the device will automatically * fail and get retried if it happens in a window where the device * is not ready, e.g. after a bus reset but before we reconnect.
*/ int generation; int retries;
work_func_t workfn; struct delayed_work work; bool has_sdev; bool blocked;
};
/* * We create one struct sbp2_target per IEEE 1212 Unit Directory * and one struct Scsi_Host per sbp2_target.
*/ struct sbp2_target { struct fw_unit *unit; struct list_head lu_list;
u64 management_agent_address;
u64 guid; int directory_id; int node_id; int address_high; unsignedint workarounds; unsignedint mgt_orb_timeout; unsignedint max_payload;
spinlock_t lock; int dont_block; /* counter for each logical unit */ int blocked; /* ditto */
};
/* * There is no transport protocol limit to the CDB length, but we implement * a fixed length only. 16 bytes is enough for disks larger than 2 TB.
*/ #define SBP2_MAX_CDB_SIZE 16
/* * The maximum SBP-2 data buffer size is 0xffff. We quadlet-align this * for compatibility with earlier versions of this driver.
*/ #define SBP2_MAX_SEG_SIZE 0xfffc
/* * This is a little tricky. We can get the status write for * the orb before we get this callback. The status write * handler above will assume the orb pointer transaction was * successful and set the rcode to RCODE_COMPLETE for the orb. * So this callback only sets the rcode if it hasn't already * been set and only does the cleanup if the transaction * failed and we didn't already get a status write.
*/
spin_lock_irqsave(&orb->lu->tgt->lock, flags);
if (orb->rcode == -1)
orb->rcode = rcode; if (orb->rcode != RCODE_COMPLETE) {
list_del(&orb->link);
spin_unlock_irqrestore(&orb->lu->tgt->lock, flags);
/* * Blocks lu->tgt if all of the following conditions are met: * - Login, INQUIRY, and high-level SCSI setup of all of the target's * logical units have been finished (indicated by dont_block == 0). * - lu->generation is stale. * * Note, scsi_block_requests() must be called while holding tgt->lock, * otherwise it might foil sbp2_[conditionally_]unblock()'s attempt to * unblock the target.
*/ staticvoid sbp2_conditionally_block(struct sbp2_logical_unit *lu)
{ struct sbp2_target *tgt = lu->tgt; struct fw_card *card = target_parent_device(tgt)->card; struct Scsi_Host *shost =
container_of((void *)tgt, struct Scsi_Host, hostdata[0]); unsignedlong flags;
/* * Unblocks lu->tgt as soon as all its logical units can be unblocked. * Note, it is harmless to run scsi_unblock_requests() outside the * tgt->lock protected section. On the other hand, running it inside * the section might clash with shost->host_lock.
*/ staticvoid sbp2_conditionally_unblock(struct sbp2_logical_unit *lu)
{ struct sbp2_target *tgt = lu->tgt; struct fw_card *card = target_parent_device(tgt)->card; struct Scsi_Host *shost =
container_of((void *)tgt, struct Scsi_Host, hostdata[0]); bool unblock = false;
/* * Prevents future blocking of tgt and unblocks it. * Note, it is harmless to run scsi_unblock_requests() outside the * tgt->lock protected section. On the other hand, running it inside * the section might clash with shost->host_lock.
*/ staticvoid sbp2_unblock(struct sbp2_target *tgt)
{ struct Scsi_Host *shost =
container_of((void *)tgt, struct Scsi_Host, hostdata[0]);
/* * 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.
*/ staticvoid sbp2_set_busy_timeout(struct sbp2_logical_unit *lu)
{ struct fw_device *device = target_parent_device(lu->tgt);
__be32 d = cpu_to_be32(SBP2_CYCLE_LIMIT | SBP2_RETRY_LIMIT);
generation = device->generation;
smp_rmb(); /* node IDs must not be older than generation */
node_id = device->node_id;
local_node_id = device->card->node_id;
/* If this is a re-login attempt, log out, or we might be rejected. */ if (lu->has_sdev)
sbp2_send_management_orb(lu, device->node_id, generation,
SBP2_LOGOUT_REQUEST, lu->login_id, NULL);
if (sbp2_send_management_orb(lu, node_id, generation,
SBP2_LOGIN_REQUEST, lu->lun, &response) < 0) { if (lu->retries++ < 5) {
sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5));
} else {
dev_err(tgt_dev(tgt), "failed to login to LUN %04x\n",
lu->lun); /* Let any waiting I/O fail from now on. */
sbp2_unblock(lu->tgt);
} return;
}
tgt->node_id = node_id;
tgt->address_high = local_node_id << 16;
smp_wmb(); /* node IDs must not be older than generation */
lu->generation = generation;
/* This was a re-login. */ if (lu->has_sdev) {
sbp2_cancel_orbs(lu);
sbp2_conditionally_unblock(lu);
return;
}
if (lu->tgt->workarounds & SBP2_WORKAROUND_DELAY_INQUIRY)
ssleep(SBP2_INQUIRY_DELAY);
shost = container_of((void *)tgt, struct Scsi_Host, hostdata[0]);
sdev = __scsi_add_device(shost, 0, 0, sbp2_lun2int(lu->lun), lu); /* * FIXME: We are unable to perform reconnects while in sbp2_login(). * Therefore __scsi_add_device() will get into trouble if a bus reset * happens in parallel. It will either fail or leave us with an * unusable sdev. As a workaround we check for this and retry the * whole login and SCSI probing.
*/
/* Reported error during __scsi_add_device() */ if (IS_ERR(sdev)) goto out_logout_login;
/* Unreported error during __scsi_add_device() */
smp_rmb(); /* get current card generation */ if (generation != device->card->generation) {
scsi_remove_device(sdev);
scsi_device_put(sdev); goto out_logout_login;
}
/* No error during __scsi_add_device() */
lu->has_sdev = true;
scsi_device_put(sdev);
sbp2_allow_block(tgt);
return;
out_logout_login:
smp_rmb(); /* generation may have changed */
generation = device->generation;
smp_rmb(); /* node_id must not be older than generation */
sbp2_send_management_orb(lu, device->node_id, generation,
SBP2_LOGOUT_REQUEST, lu->login_id, NULL); /* * If a bus reset happened, sbp2_update will have requeued * lu->work already. Reset the work from reconnect to login.
*/
lu->workfn = sbp2_login;
}
generation = device->generation;
smp_rmb(); /* node IDs must not be older than generation */
node_id = device->node_id;
local_node_id = device->card->node_id;
if (sbp2_send_management_orb(lu, node_id, generation,
SBP2_RECONNECT_REQUEST,
lu->login_id, NULL) < 0) { /* * If reconnect was impossible even though we are in the * current generation, fall back and try to log in again. * * We could check for "Function rejected" status, but * looking at the bus generation as simpler and more general.
*/
smp_rmb(); /* get current card generation */ if (generation == device->card->generation ||
lu->retries++ >= 5) {
dev_err(tgt_dev(tgt), "failed to reconnect\n");
lu->retries = 0;
lu->workfn = sbp2_login;
}
sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5));
return;
}
tgt->node_id = node_id;
tgt->address_high = local_node_id << 16;
smp_wmb(); /* node IDs must not be older than generation */
lu->generation = generation;
dev_notice(tgt_dev(tgt), "reconnected to LUN %04x (%d retries)\n",
lu->lun, lu->retries);
case CSR_DIRECTORY_ID:
tgt->directory_id = value; break;
case CSR_MODEL:
*model = value; break;
case SBP2_CSR_FIRMWARE_REVISION:
*firmware_revision = value; break;
case SBP2_CSR_UNIT_CHARACTERISTICS: /* the timeout value is stored in 500ms units */
tgt->mgt_orb_timeout = (value >> 8 & 0xff) * 500; break;
case SBP2_CSR_LOGICAL_UNIT_NUMBER: if (sbp2_add_logical_unit(tgt, value) < 0) return -ENOMEM; break;
case SBP2_CSR_UNIT_UNIQUE_ID:
sbp2_get_unit_unique_id(tgt, ci.p - 1 + value); break;
case SBP2_CSR_LOGICAL_UNIT_DIRECTORY: /* Adjust for the increment in the iterator */ if (sbp2_scan_logical_unit_dir(tgt, ci.p - 1 + value) < 0) return -ENOMEM; break;
}
} return 0;
}
/* * Per section 7.4.8 of the SBP-2 spec, a mgt_ORB_timeout value can be * provided in the config rom. Most devices do provide a value, which * we'll use for login management orbs, but with some sane limits.
*/ staticvoid sbp2_clamp_management_orb_timeout(struct sbp2_target *tgt)
{ unsignedint timeout = tgt->mgt_orb_timeout;
if (timeout > 40000)
dev_notice(tgt_dev(tgt), "%ds mgt_ORB_timeout limited to 40s\n",
timeout / 1000);
/* * At S100 we can do 512 bytes per packet, at S200 1024 bytes, * and so on up to 4096 bytes. The SBP-2 max_payload field * specifies the max payload size as 2 ^ (max_payload + 2), so * if we set this to max_speed + 7, we get the right value.
*/
tgt->max_payload = min3(device->max_speed + 7, 10U,
device->card->max_receive - 1);
/* Do the login in a workqueue so we can easily reschedule retries. */
list_for_each_entry(lu, &tgt->lu_list, link)
sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5));
list_for_each_entry_safe(lu, next, &tgt->lu_list, link) {
cancel_delayed_work_sync(&lu->work);
sdev = scsi_device_lookup(shost, 0, 0, sbp2_lun2int(lu->lun)); if (sdev) {
scsi_remove_device(sdev);
scsi_device_put(sdev);
} if (lu->login_id != INVALID_LOGIN_ID) { int generation, node_id; /* * tgt->node_id may be obsolete here if we failed * during initial login or after a bus reset where * the topology changed.
*/
generation = device->generation;
smp_rmb(); /* node_id vs. generation */
node_id = device->node_id;
sbp2_send_management_orb(lu, node_id, generation,
SBP2_LOGOUT_REQUEST,
lu->login_id, NULL);
}
fw_core_remove_address_handler(&lu->address_handler);
list_del(&lu->link);
kfree(lu);
}
scsi_remove_host(shost);
dev_notice(&unit->device, "released target %d:0:0\n", shost->host_no);
switch (sam_status) { case SAM_STAT_GOOD: case SAM_STAT_CHECK_CONDITION: case SAM_STAT_CONDITION_MET: case SAM_STAT_BUSY: case SAM_STAT_RESERVATION_CONFLICT: case SAM_STAT_COMMAND_TERMINATED: return DID_OK << 16 | sam_status;
if (status != NULL) { if (STATUS_GET_DEAD(*status))
sbp2_agent_reset_no_wait(base_orb->lu);
switch (STATUS_GET_RESPONSE(*status)) { case SBP2_STATUS_REQUEST_COMPLETE:
result = DID_OK << 16; break; case SBP2_STATUS_TRANSPORT_FAILURE:
result = DID_BUS_BUSY << 16; break; case SBP2_STATUS_ILLEGAL_REQUEST: case SBP2_STATUS_VENDOR_DEPENDENT: default:
result = DID_ERROR << 16; break;
}
if (result == DID_OK << 16 && STATUS_GET_LEN(*status) > 1)
result = sbp2_status_to_sense_data(STATUS_GET_DATA(*status),
orb->cmd->sense_buffer);
} else { /* * If the orb completes with status == NULL, something * went wrong, typically a bus reset happened mid-orb * or when sending the write (less likely).
*/
result = DID_BUS_BUSY << 16;
sbp2_conditionally_block(base_orb->lu);
}
staticint sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device, struct sbp2_logical_unit *lu)
{ struct scatterlist *sg = scsi_sglist(orb->cmd); int i, n;
n = scsi_dma_map(orb->cmd); if (n <= 0) goto fail;
/* * Handle the special case where there is only one element in * the scatter list by converting it to an immediate block * request. This is also a workaround for broken devices such * as the second generation iPod which doesn't support page * tables.
*/ if (n == 1) {
orb->request.data_descriptor.high =
cpu_to_be32(lu->tgt->address_high);
orb->request.data_descriptor.low =
cpu_to_be32(sg_dma_address(sg));
orb->request.misc |=
cpu_to_be32(COMMAND_ORB_DATA_SIZE(sg_dma_len(sg))); return 0;
}
/* * The data_descriptor pointer is the one case where we need * to fill in the node ID part of the address. All other * pointers assume that the data referenced reside on the * initiator (i.e. us), but data_descriptor can refer to data * on other nodes so we need to put our ID in descriptor.high.
*/
orb->request.data_descriptor.high = cpu_to_be32(lu->tgt->address_high);
orb->request.data_descriptor.low = cpu_to_be32(orb->page_table_bus);
orb->request.misc |= cpu_to_be32(COMMAND_ORB_PAGE_TABLE_PRESENT |
COMMAND_ORB_DATA_SIZE(n));
/* * Called by scsi stack when something has really gone wrong. Usually * called when a command has timed-out for some reason.
*/ staticint sbp2_scsi_abort(struct scsi_cmnd *cmd)
{ struct sbp2_logical_unit *lu = cmd->device->hostdata;
/* * Format of /sys/bus/scsi/devices/.../ieee1394_id: * u64 EUI-64 : u24 directory_ID : u16 LUN (all printed in hexadecimal) * * This is the concatenation of target port identifier and logical unit * identifier as per SAM-2...SAM-4 annex A.
*/ static ssize_t sbp2_sysfs_ieee1394_id_show(struct device *dev, struct device_attribute *attr, char *buf)
{ struct scsi_device *sdev = to_scsi_device(dev); struct sbp2_logical_unit *lu;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.