// SPDX-License-Identifier: GPL-2.0-or-later /* ------------------------------------------------------------ * ibmvscsi.c * (C) Copyright IBM Corporation 1994, 2004 * Authors: Colin DeVilbiss (devilbis@us.ibm.com) * Santiago Leon (santil@us.ibm.com) * Dave Boutcher (sleddog@us.ibm.com) * * ------------------------------------------------------------ * Emulation of a SCSI host adapter for Virtual I/O devices * * This driver supports the SCSI adapter implemented by the IBM * Power5 firmware. That SCSI adapter is not a physical adapter, * but allows Linux SCSI peripheral drivers to directly * access devices in another logical partition on the physical system. * * The virtual adapter(s) are present in the open firmware device * tree just like real adapters. * * One of the capabilities provided on these systems is the ability * to DMA between partitions. The architecture states that for VSCSI, * the server side is allowed to DMA to and from the client. The client * is never trusted to DMA to or from the server directly. * * Messages are sent between partitions on a "Command/Response Queue" * (CRQ), which is just a buffer of 16 byte entries in the receiver's * Senders cannot access the buffer directly, but send messages by * making a hypervisor call and passing in the 16 bytes. The hypervisor * puts the message in the next 16 byte space in round-robin fashion, * turns on the high order bit of the message (the valid bit), and * generates an interrupt to the receiver (if interrupts are turned on.) * The receiver just turns off the valid bit when they have copied out * the message. * * The VSCSI client builds a SCSI Remote Protocol (SRP) Information Unit * (IU) (as defined in the T10 standard available at www.t10.org), gets * a DMA address for the message, and sends it to the server as the * payload of a CRQ message. The server DMAs the SRP IU and processes it, * including doing any additional data transfers. When it is done, it * DMAs the SRP response back to the same address as the request came from, * and sends a CRQ message back to inform the client that the request has * completed. * * TODO: This is currently pretty tied to the IBM pSeries hypervisor * interfaces. It would be really nice to abstract this above an RDMA * layer.
*/
/* ------------------------------------------------------------ * Routines for managing the command/response queue
*/ /** * ibmvscsi_handle_event: - Interrupt handler for crq events * @irq: number of irq to handle, not used * @dev_instance: ibmvscsi_host_data of host that received interrupt * * Disables interrupts and schedules srp_task * Always returns IRQ_HANDLED
*/ static irqreturn_t ibmvscsi_handle_event(int irq, void *dev_instance)
{ struct ibmvscsi_host_data *hostdata =
(struct ibmvscsi_host_data *)dev_instance;
vio_disable_interrupts(to_vio_dev(hostdata->dev));
tasklet_schedule(&hostdata->srp_task); return IRQ_HANDLED;
}
/** * ibmvscsi_release_crq_queue() - Deallocates data and unregisters CRQ * @queue: crq_queue to initialize and register * @hostdata: ibmvscsi_host_data of host * @max_requests: maximum requests (unused) * * Frees irq, deallocates a page for messages, unmaps dma, and unregisters * the crq with the hypervisor.
*/ staticvoid ibmvscsi_release_crq_queue(struct crq_queue *queue, struct ibmvscsi_host_data *hostdata, int max_requests)
{ long rc = 0; struct vio_dev *vdev = to_vio_dev(hostdata->dev);
free_irq(vdev->irq, (void *)hostdata);
tasklet_kill(&hostdata->srp_task); do { if (rc)
msleep(100);
rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
} while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));
dma_unmap_single(hostdata->dev,
queue->msg_token,
queue->size * sizeof(*queue->msgs), DMA_BIDIRECTIONAL);
free_page((unsignedlong)queue->msgs);
}
/** * crq_queue_next_crq: - Returns the next entry in message queue * @queue: crq_queue to use * * Returns pointer to next entry in queue, or NULL if there are no new * entried in the CRQ.
*/ staticstruct viosrp_crq *crq_queue_next_crq(struct crq_queue *queue)
{ struct viosrp_crq *crq; unsignedlong flags;
spin_lock_irqsave(&queue->lock, flags);
crq = &queue->msgs[queue->cur]; if (crq->valid != VIOSRP_CRQ_FREE) { if (++queue->cur == queue->size)
queue->cur = 0;
/* Ensure the read of the valid bit occurs before reading any * other bits of the CRQ entry
*/
rmb();
} else
crq = NULL;
spin_unlock_irqrestore(&queue->lock, flags);
return crq;
}
/** * ibmvscsi_send_crq: - Send a CRQ * @hostdata: the adapter * @word1: the first 64 bits of the data * @word2: the second 64 bits of the data
*/ staticint ibmvscsi_send_crq(struct ibmvscsi_host_data *hostdata,
u64 word1, u64 word2)
{ struct vio_dev *vdev = to_vio_dev(hostdata->dev);
/* * Ensure the command buffer is flushed to memory before handing it * over to the VIOS to prevent it from fetching any stale data.
*/
mb(); return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address, word1, word2);
}
while (!done) { /* Pull all the valid messages off the CRQ */ while ((crq = crq_queue_next_crq(&hostdata->queue)) != NULL) {
ibmvscsi_handle_crq(crq, hostdata);
crq->valid = VIOSRP_CRQ_FREE;
wmb();
}
/** * ibmvscsi_reset_crq_queue() - resets a crq after a failure * @queue: crq_queue to initialize and register * @hostdata: ibmvscsi_host_data of host
*/ staticint ibmvscsi_reset_crq_queue(struct crq_queue *queue, struct ibmvscsi_host_data *hostdata)
{ int rc = 0; struct vio_dev *vdev = to_vio_dev(hostdata->dev);
/* Close the CRQ */ do { if (rc)
msleep(100);
rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
} while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));
/* Clean out the queue */
memset(queue->msgs, 0x00, PAGE_SIZE);
queue->cur = 0;
set_adapter_info(hostdata);
/* And re-open it again */
rc = plpar_hcall_norets(H_REG_CRQ,
vdev->unit_address,
queue->msg_token, PAGE_SIZE); if (rc == H_CLOSED) { /* Adapter is good, but other end is not ready */
dev_warn(hostdata->dev, "Partner adapter not ready\n");
} elseif (rc != 0) {
dev_warn(hostdata->dev, "couldn't register crq--rc 0x%x\n", rc);
} return rc;
}
/** * ibmvscsi_init_crq_queue() - Initializes and registers CRQ with hypervisor * @queue: crq_queue to initialize and register * @hostdata: ibmvscsi_host_data of host * @max_requests: maximum requests (unused) * * Allocates a page for messages, maps it for dma, and registers * the crq with the hypervisor. * Returns zero on success.
*/ staticint ibmvscsi_init_crq_queue(struct crq_queue *queue, struct ibmvscsi_host_data *hostdata, int max_requests)
{ int rc; int retrc; struct vio_dev *vdev = to_vio_dev(hostdata->dev);
retrc = rc = plpar_hcall_norets(H_REG_CRQ,
vdev->unit_address,
queue->msg_token, PAGE_SIZE); if (rc == H_RESOURCE) /* maybe kexecing and resource is busy. try a reset */
rc = ibmvscsi_reset_crq_queue(queue,
hostdata);
if (rc == H_CLOSED) { /* Adapter is good, but other end is not ready */
dev_warn(hostdata->dev, "Partner adapter not ready\n");
retrc = 0;
} elseif (rc != 0) {
dev_warn(hostdata->dev, "Error %d opening adapter\n", rc); goto reg_crq_failed;
}
/* ------------------------------------------------------------ * Routines for the event pool and event structs
*/ /** * initialize_event_pool: - Allocates and initializes the event pool for a host * @pool: event_pool to be initialized * @size: Number of events in pool * @hostdata: ibmvscsi_host_data who owns the event pool * * Returns zero on success.
*/ staticint initialize_event_pool(struct event_pool *pool, int size, struct ibmvscsi_host_data *hostdata)
{ int i;
/** * release_event_pool() - Frees memory of an event pool of a host * @pool: event_pool to be released * @hostdata: ibmvscsi_host_data who owns the even pool * * Returns zero on success.
*/ staticvoid release_event_pool(struct event_pool *pool, struct ibmvscsi_host_data *hostdata)
{ int i, in_use = 0; for (i = 0; i < pool->size; ++i) { if (atomic_read(&pool->events[i].free) != 1)
++in_use; if (pool->events[i].ext_list) {
dma_free_coherent(hostdata->dev,
SG_ALL * sizeof(struct srp_direct_buf),
pool->events[i].ext_list,
pool->events[i].ext_list_token);
}
} if (in_use)
dev_warn(hostdata->dev, "releasing event pool with %d " "events still in use?\n", in_use);
kfree(pool->events);
dma_free_coherent(hostdata->dev,
pool->size * sizeof(*pool->iu_storage),
pool->iu_storage, pool->iu_token);
}
/** * valid_event_struct: - Determines if event is valid. * @pool: event_pool that contains the event * @evt: srp_event_struct to be checked for validity * * Returns zero if event is invalid, one otherwise.
*/ staticint valid_event_struct(struct event_pool *pool, struct srp_event_struct *evt)
{ int index = evt - pool->events; if (index < 0 || index >= pool->size) /* outside of bounds */ return 0; if (evt != pool->events + index) /* unaligned */ return 0; return 1;
}
/** * free_event_struct() - Changes status of event to "free" * @pool: event_pool that contains the event * @evt: srp_event_struct to be modified
*/ staticvoid free_event_struct(struct event_pool *pool, struct srp_event_struct *evt)
{ if (!valid_event_struct(pool, evt)) {
dev_err(evt->hostdata->dev, "Freeing invalid event_struct %p " "(not in pool %p)\n", evt, pool->events); return;
} if (atomic_inc_return(&evt->free) != 1) {
dev_err(evt->hostdata->dev, "Freeing event_struct %p " "which is not in use!\n", evt); return;
}
}
/** * get_event_struct() - Gets the next free event in pool * @pool: event_pool that contains the events to be searched * * Returns the next event in "free" state, and NULL if none are free. * Note that no synchronization is done here, we assume the host_lock * will syncrhonze things.
*/ staticstruct srp_event_struct *get_event_struct(struct event_pool *pool)
{ int i; int poolsize = pool->size; int offset = pool->next;
for (i = 0; i < poolsize; i++) {
offset = (offset + 1) % poolsize; if (!atomic_dec_if_positive(&pool->events[offset].free)) {
pool->next = offset; return &pool->events[offset];
}
}
printk(KERN_ERR "ibmvscsi: found no event struct in pool!\n"); return NULL;
}
/** * init_event_struct: Initialize fields in an event struct that are always * required. * @evt_struct: The event * @done: Routine to call when the event is responded to * @format: SRP or MAD format * @timeout: timeout value set in the CRQ
*/ staticvoid init_event_struct(struct srp_event_struct *evt_struct, void (*done) (struct srp_event_struct *),
u8 format, int timeout)
{
evt_struct->cmnd = NULL;
evt_struct->cmnd_done = NULL;
evt_struct->sync_srp = NULL;
evt_struct->crq.format = format;
evt_struct->crq.timeout = cpu_to_be16(timeout);
evt_struct->done = done;
}
/* ------------------------------------------------------------ * Routines for receiving SCSI responses from the hosting partition
*/
/* * set_srp_direction: Set the fields in the srp related to data * direction and number of buffers based on the direction in * the scsi_cmnd and the number of buffers
*/ staticvoid set_srp_direction(struct scsi_cmnd *cmd, struct srp_cmd *srp_cmd, int numbuf)
{
u8 fmt;
/** * unmap_cmd_data: - Unmap data pointed in srp_cmd based on the format * @cmd: srp_cmd whose additional_data member will be unmapped * @evt_struct: the event * @dev: device for which the memory is mapped
*/ staticvoid unmap_cmd_data(struct srp_cmd *cmd, struct srp_event_struct *evt_struct, struct device *dev)
{
u8 out_fmt, in_fmt;
/** * map_sg_data: - Maps dma for a scatterlist and initializes descriptor fields * @cmd: struct scsi_cmnd with the scatterlist * @evt_struct: struct srp_event_struct to map * @srp_cmd: srp_cmd that contains the memory descriptor * @dev: device for which to map dma memory * * Called by map_data_for_srp_cmd() when building srp cmd from scsi cmd. * Returns 1 on success.
*/ staticint map_sg_data(struct scsi_cmnd *cmd, struct srp_event_struct *evt_struct, struct srp_cmd *srp_cmd, struct device *dev)
{
/** * map_data_for_srp_cmd: - Calls functions to map data for srp cmds * @cmd: struct scsi_cmnd with the memory to be mapped * @evt_struct: struct srp_event_struct to map * @srp_cmd: srp_cmd that contains the memory descriptor * @dev: dma device for which to map dma memory * * Called by scsi_cmd_to_srp_cmd() when converting scsi cmds to srp cmds * Returns 1 on success.
*/ staticint map_data_for_srp_cmd(struct scsi_cmnd *cmd, struct srp_event_struct *evt_struct, struct srp_cmd *srp_cmd, struct device *dev)
{ switch (cmd->sc_data_direction) { case DMA_FROM_DEVICE: case DMA_TO_DEVICE: break; case DMA_NONE: return 1; case DMA_BIDIRECTIONAL:
sdev_printk(KERN_ERR, cmd->device, "Can't map DMA_BIDIRECTIONAL to read/write\n"); return 0; default:
sdev_printk(KERN_ERR, cmd->device, "Unknown data direction 0x%02x; can't map!\n",
cmd->sc_data_direction); return 0;
}
/** * purge_requests: Our virtual adapter just shut down. purge any sent requests * @hostdata: the adapter * @error_code: error code to return as the 'result'
*/ staticvoid purge_requests(struct ibmvscsi_host_data *hostdata, int error_code)
{ struct srp_event_struct *evt; unsignedlong flags;
/** * ibmvscsi_set_request_limit - Set the adapter request_limit in response to * an adapter failure, reset, or SRP Login. Done under host lock to prevent * race with SCSI command submission. * @hostdata: adapter to adjust * @limit: new request limit
*/ staticvoid ibmvscsi_set_request_limit(struct ibmvscsi_host_data *hostdata, int limit)
{ unsignedlong flags;
/** * ibmvscsi_reset_host - Reset the connection to the server * @hostdata: struct ibmvscsi_host_data to reset
*/ staticvoid ibmvscsi_reset_host(struct ibmvscsi_host_data *hostdata)
{
scsi_block_requests(hostdata->host);
ibmvscsi_set_request_limit(hostdata, 0);
/** * ibmvscsi_timeout - Internal command timeout handler * @t: struct srp_event_struct that timed out * * Called when an internally generated command times out
*/ staticvoid ibmvscsi_timeout(struct timer_list *t)
{ struct srp_event_struct *evt_struct = timer_container_of(evt_struct,
t, timer); struct ibmvscsi_host_data *hostdata = evt_struct->hostdata;
dev_err(hostdata->dev, "Command timed out (%x). Resetting connection\n",
evt_struct->iu.srp.cmd.opcode);
ibmvscsi_reset_host(hostdata);
}
/* ------------------------------------------------------------ * Routines for sending and receiving SRPs
*/ /** * ibmvscsi_send_srp_event: - Transforms event to u64 array and calls send_crq() * @evt_struct: evt_struct to be sent * @hostdata: ibmvscsi_host_data of host * @timeout: timeout in seconds - 0 means do not time command * * Returns the value returned from ibmvscsi_send_crq(). (Zero for success) * Note that this routine assumes that host_lock is held for synchronization
*/ staticint ibmvscsi_send_srp_event(struct srp_event_struct *evt_struct, struct ibmvscsi_host_data *hostdata, unsignedlong timeout)
{
__be64 *crq_as_u64 = (__be64 *)&evt_struct->crq; int request_status = 0; int rc; int srp_req = 0;
/* If we have exhausted our request limit, just fail this request, * unless it is for a reset or abort. * Note that there are rare cases involving driver generated requests * (such as task management requests) that the mid layer may think we * can handle more requests (can_queue) when we actually can't
*/ if (evt_struct->crq.format == VIOSRP_SRP_FORMAT) {
srp_req = 1;
request_status =
atomic_dec_if_positive(&hostdata->request_limit); /* If request limit was -1 when we started, it is now even * less than that
*/ if (request_status < -1) goto send_error; /* Otherwise, we may have run out of requests. */ /* If request limit was 0 when we started the adapter is in the * process of performing a login with the server adapter, or * we may have run out of requests.
*/ elseif (request_status == -1 &&
evt_struct->iu.srp.login_req.opcode != SRP_LOGIN_REQ) goto send_busy; /* Abort and reset calls should make it through. * Nothing except abort and reset should use the last two * slots unless we had two or less to begin with.
*/ elseif (request_status < 2 &&
evt_struct->iu.srp.cmd.opcode != SRP_TSK_MGMT) { /* In the case that we have less than two requests * available, check the server limit as a combination * of the request limit and the number of requests * in-flight (the size of the send list). If the * server limit is greater than 2, return busy so * that the last two are reserved for reset and abort.
*/ int server_limit = request_status; struct srp_event_struct *tmp_evt;
/* Copy the IU into the transfer area */
*evt_struct->xfer_iu = evt_struct->iu;
evt_struct->xfer_iu->srp.rsp.tag = (u64)evt_struct;
/* Add this to the sent list. We need to do this * before we actually send * in case it comes back REALLY fast
*/
list_add_tail(&evt_struct->list, &hostdata->sent);
/* If send_crq returns H_CLOSED, return SCSI_MLQUEUE_HOST_BUSY. * Firmware will send a CRQ with a transport event (0xFF) to * tell this client what has happened to the transport. This * will be handled in ibmvscsi_handle_crq()
*/ if (rc == H_CLOSED) {
dev_warn(hostdata->dev, "send warning. " "Receive queue closed, will retry.\n"); goto send_busy;
}
dev_err(hostdata->dev, "send error %d\n", rc); if (srp_req)
atomic_inc(&hostdata->request_limit); goto send_error;
}
/** * handle_cmd_rsp: - Handle responses from commands * @evt_struct: srp_event_struct to be handled * * Used as a callback by when sending scsi cmds. * Gets called by ibmvscsi_handle_crq()
*/ staticvoid handle_cmd_rsp(struct srp_event_struct *evt_struct)
{ struct srp_rsp *rsp = &evt_struct->xfer_iu->srp.rsp; struct scsi_cmnd *cmnd = evt_struct->cmnd;
if (unlikely(rsp->opcode != SRP_RSP)) { if (printk_ratelimit())
dev_warn(evt_struct->hostdata->dev, "bad SRP RSP type %#02x\n", rsp->opcode);
}
if (cmnd) {
cmnd->result |= rsp->status; if (scsi_status_is_check_condition(cmnd->result))
memcpy(cmnd->sense_buffer,
rsp->data,
be32_to_cpu(rsp->sense_data_len));
unmap_cmd_data(&evt_struct->iu.srp.cmd,
evt_struct,
evt_struct->hostdata->dev);
/* Set up the actual SRP IU */
BUILD_BUG_ON(sizeof(evt_struct->iu.srp) != SRP_MAX_IU_LEN);
memset(&evt_struct->iu.srp, 0x00, sizeof(evt_struct->iu.srp));
srp_cmd = &evt_struct->iu.srp.cmd;
srp_cmd->opcode = SRP_CMD;
memcpy(srp_cmd->cdb, cmnd->cmnd, sizeof(srp_cmd->cdb));
int_to_scsilun(lun, &srp_cmd->lun);
if (!map_data_for_srp_cmd(cmnd, evt_struct, srp_cmd, hostdata->dev)) { if (!firmware_has_feature(FW_FEATURE_CMO))
sdev_printk(KERN_ERR, cmnd->device, "couldn't convert cmd to srp_cmd\n");
free_event_struct(&hostdata->pool, evt_struct); return SCSI_MLQUEUE_HOST_BUSY;
}
/* ------------------------------------------------------------ * Routines for driver initialization
*/
/** * map_persist_bufs: - Pre-map persistent data for adapter logins * @hostdata: ibmvscsi_host_data of host * * Map the capabilities and adapter info DMA buffers to avoid runtime failures. * Return 1 on error, 0 on success.
*/ staticint map_persist_bufs(struct ibmvscsi_host_data *hostdata)
{
/* Now we know what the real request-limit is. * This value is set rather than added to request_limit because * request_limit could have been set to -1 by this client.
*/
ibmvscsi_set_request_limit(hostdata,
be32_to_cpu(evt_struct->xfer_iu->srp.login_rsp.req_lim_delta));
/* If we had any pending I/Os, kick them */
hostdata->action = IBMVSCSI_HOST_ACTION_UNBLOCK;
wake_up(&hostdata->work_wait_q);
}
/** * send_srp_login: - Sends the srp login * @hostdata: ibmvscsi_host_data of host * * Returns zero if successful.
*/ staticint send_srp_login(struct ibmvscsi_host_data *hostdata)
{ int rc; unsignedlong flags; struct srp_login_req *login; struct srp_event_struct *evt_struct = get_event_struct(&hostdata->pool);
/* Start out with a request limit of 0, since this is negotiated in * the login request we are just sending and login requests always * get sent by the driver regardless of request_limit.
*/
ibmvscsi_set_request_limit(hostdata, 0);
/** * capabilities_rsp: - Handle response to MAD adapter capabilities request * @evt_struct: srp_event_struct with the response * * Used as a "done" callback by when sending adapter_info.
*/ staticvoid capabilities_rsp(struct srp_event_struct *evt_struct)
{ struct ibmvscsi_host_data *hostdata = evt_struct->hostdata;
if (evt_struct->xfer_iu->mad.capabilities.common.status) {
dev_err(hostdata->dev, "error 0x%X getting capabilities info\n",
evt_struct->xfer_iu->mad.capabilities.common.status);
} else { if (hostdata->caps.migration.common.server_support !=
cpu_to_be16(SERVER_SUPPORTS_CAP))
dev_info(hostdata->dev, "Partition migration not supported\n");
if (client_reserve) { if (hostdata->caps.reserve.common.server_support ==
cpu_to_be16(SERVER_SUPPORTS_CAP))
dev_info(hostdata->dev, "Client reserve enabled\n"); else
dev_info(hostdata->dev, "Client reserve not supported\n");
}
}
send_srp_login(hostdata);
}
/** * send_mad_capabilities: - Sends the mad capabilities request * and stores the result so it can be retrieved with * @hostdata: ibmvscsi_host_data of host
*/ staticvoid send_mad_capabilities(struct ibmvscsi_host_data *hostdata)
{ struct viosrp_capabilities *req; struct srp_event_struct *evt_struct; unsignedlong flags; struct device_node *of_node = hostdata->dev->of_node; constchar *location;
/** * fast_fail_rsp: - Handle response to MAD enable fast fail * @evt_struct: srp_event_struct with the response * * Used as a "done" callback by when sending enable fast fail. Gets called * by ibmvscsi_handle_crq()
*/ staticvoid fast_fail_rsp(struct srp_event_struct *evt_struct)
{ struct ibmvscsi_host_data *hostdata = evt_struct->hostdata;
u16 status = be16_to_cpu(evt_struct->xfer_iu->mad.fast_fail.common.status);
if (status == VIOSRP_MAD_NOT_SUPPORTED)
dev_err(hostdata->dev, "fast_fail not supported in server\n"); elseif (status == VIOSRP_MAD_FAILED)
dev_err(hostdata->dev, "fast_fail request failed\n"); elseif (status != VIOSRP_MAD_SUCCESS)
dev_err(hostdata->dev, "error 0x%X enabling fast_fail\n", status);
send_mad_capabilities(hostdata);
}
/** * enable_fast_fail() - Start host initialization * @hostdata: ibmvscsi_host_data of host * * Returns zero if successful.
*/ staticint enable_fast_fail(struct ibmvscsi_host_data *hostdata)
{ int rc; unsignedlong flags; struct viosrp_fast_fail *fast_fail_mad; struct srp_event_struct *evt_struct;
if (!fast_fail) {
send_mad_capabilities(hostdata); return 0;
}
/** * adapter_info_rsp: - Handle response to MAD adapter info request * @evt_struct: srp_event_struct with the response * * Used as a "done" callback by when sending adapter_info. Gets called * by ibmvscsi_handle_crq()
*/ staticvoid adapter_info_rsp(struct srp_event_struct *evt_struct)
{ struct ibmvscsi_host_data *hostdata = evt_struct->hostdata;
if (hostdata->madapter_info.port_max_txu[0])
hostdata->host->max_sectors =
be32_to_cpu(hostdata->madapter_info.port_max_txu[0]) >> 9;
if (be32_to_cpu(hostdata->madapter_info.os_type) == SRP_MAD_OS_AIX &&
strcmp(hostdata->madapter_info.srp_version, "1.6a") <= 0) {
dev_err(hostdata->dev, "host (Ver. %s) doesn't support large transfers\n",
hostdata->madapter_info.srp_version);
dev_err(hostdata->dev, "limiting scatterlists to %d\n",
MAX_INDIRECT_BUFS);
hostdata->host->sg_tablesize = MAX_INDIRECT_BUFS;
}
if (be32_to_cpu(hostdata->madapter_info.os_type) == SRP_MAD_OS_AIX) {
enable_fast_fail(hostdata); return;
}
}
send_srp_login(hostdata);
}
/** * send_mad_adapter_info: - Sends the mad adapter info request * and stores the result so it can be retrieved with * sysfs. We COULD consider causing a failure if the * returned SRP version doesn't match ours. * @hostdata: ibmvscsi_host_data of host * * Returns zero if successful.
*/ staticvoid send_mad_adapter_info(struct ibmvscsi_host_data *hostdata)
{ struct viosrp_adapter_info *req; struct srp_event_struct *evt_struct; unsignedlong flags;
/* * sync_completion: Signal that a synchronous command has completed * Note that after returning from this call, the evt_struct is freed. * the caller waiting on this completion shouldn't touch the evt_struct * again.
*/ staticvoid sync_completion(struct srp_event_struct *evt_struct)
{ /* copy the response back */ if (evt_struct->sync_srp)
*evt_struct->sync_srp = *evt_struct->xfer_iu;
complete(&evt_struct->comp);
}
/* * ibmvscsi_eh_abort_handler: Abort a command...from scsi host template * send this over to the server and wait synchronously for the response
*/ staticint ibmvscsi_eh_abort_handler(struct scsi_cmnd *cmd)
{ struct ibmvscsi_host_data *hostdata = shost_priv(cmd->device->host); struct srp_tsk_mgmt *tsk_mgmt; struct srp_event_struct *evt; struct srp_event_struct *tmp_evt, *found_evt; union viosrp_iu srp_rsp; int rsp_rc; unsignedlong flags;
u16 lun = lun_from_dev(cmd->device); unsignedlong wait_switch = 0;
/* First, find this command in our sent list so we can figure * out the correct tag
*/
spin_lock_irqsave(hostdata->host->host_lock, flags);
wait_switch = jiffies + (init_timeout * HZ); do {
found_evt = NULL;
list_for_each_entry(tmp_evt, &hostdata->sent, list) { if (tmp_evt->cmnd == cmd) {
found_evt = tmp_evt; break;
}
}
if (!found_evt) {
spin_unlock_irqrestore(hostdata->host->host_lock, flags); return SUCCESS;
}
evt = get_event_struct(&hostdata->pool); if (evt == NULL) {
spin_unlock_irqrestore(hostdata->host->host_lock, flags);
sdev_printk(KERN_ERR, cmd->device, "failed to allocate abort event\n"); return FAILED;
}
/* make sure we got a good response */ if (unlikely(srp_rsp.srp.rsp.opcode != SRP_RSP)) { if (printk_ratelimit())
sdev_printk(KERN_WARNING, cmd->device, "abort bad SRP RSP type %d\n",
srp_rsp.srp.rsp.opcode); return FAILED;
}
if (rsp_rc) { if (printk_ratelimit())
sdev_printk(KERN_WARNING, cmd->device, "abort code %d for task tag 0x%llx\n",
rsp_rc, tsk_mgmt->task_tag); return FAILED;
}
/* Because we dropped the spinlock above, it's possible * The event is no longer in our list. Make sure it didn't * complete while we were aborting
*/
spin_lock_irqsave(hostdata->host->host_lock, flags);
found_evt = NULL;
list_for_each_entry(tmp_evt, &hostdata->sent, list) { if (tmp_evt->cmnd == cmd) {
found_evt = tmp_evt; break;
}
}
if (found_evt == NULL) {
spin_unlock_irqrestore(hostdata->host->host_lock, flags);
sdev_printk(KERN_INFO, cmd->device, "aborted task tag 0x%llx completed\n",
tsk_mgmt->task_tag); return SUCCESS;
}
sdev_printk(KERN_INFO, cmd->device, "successfully aborted task tag 0x%llx\n",
tsk_mgmt->task_tag);
/* * ibmvscsi_eh_device_reset_handler: Reset a single LUN...from scsi host * template send this over to the server and wait synchronously for the * response
*/ staticint ibmvscsi_eh_device_reset_handler(struct scsi_cmnd *cmd)
{ struct ibmvscsi_host_data *hostdata = shost_priv(cmd->device->host); struct srp_tsk_mgmt *tsk_mgmt; struct srp_event_struct *evt; struct srp_event_struct *tmp_evt, *pos; union viosrp_iu srp_rsp; int rsp_rc; unsignedlong flags;
u16 lun = lun_from_dev(cmd->device); unsignedlong wait_switch = 0;
/* make sure we got a good response */ if (unlikely(srp_rsp.srp.rsp.opcode != SRP_RSP)) { if (printk_ratelimit())
sdev_printk(KERN_WARNING, cmd->device, "reset bad SRP RSP type %d\n",
srp_rsp.srp.rsp.opcode); return FAILED;
}
if (rsp_rc) { if (printk_ratelimit())
sdev_printk(KERN_WARNING, cmd->device, "reset code %d for task tag 0x%llx\n",
rsp_rc, tsk_mgmt->task_tag); return FAILED;
}
/* We need to find all commands for this LUN that have not yet been * responded to, and fail them with DID_RESET
*/
spin_lock_irqsave(hostdata->host->host_lock, flags);
list_for_each_entry_safe(tmp_evt, pos, &hostdata->sent, list) { if ((tmp_evt->cmnd) && (tmp_evt->cmnd->device == cmd->device)) { if (tmp_evt->cmnd)
tmp_evt->cmnd->result = (DID_RESET << 16);
list_del(&tmp_evt->list);
unmap_cmd_data(&tmp_evt->iu.srp.cmd, tmp_evt,
tmp_evt->hostdata->dev);
free_event_struct(&tmp_evt->hostdata->pool,
tmp_evt);
atomic_inc(&hostdata->request_limit); if (tmp_evt->cmnd_done)
tmp_evt->cmnd_done(tmp_evt->cmnd); elseif (tmp_evt->done)
tmp_evt->done(tmp_evt);
}
}
spin_unlock_irqrestore(hostdata->host->host_lock, flags); return SUCCESS;
}
/** * ibmvscsi_eh_host_reset_handler - Reset the connection to the server * @cmd: struct scsi_cmnd having problems
*/ staticint ibmvscsi_eh_host_reset_handler(struct scsi_cmnd *cmd)
{ unsignedlong wait_switch = 0; struct ibmvscsi_host_data *hostdata = shost_priv(cmd->device->host);
dev_err(hostdata->dev, "Resetting connection due to error recovery\n");
/* Now login */
init_adapter(hostdata); break; default:
dev_err(hostdata->dev, "unknown crq message type: %d\n", crq->format);
} return; case VIOSRP_CRQ_XPORT_EVENT: /* Hypervisor telling us the connection is closed */
scsi_block_requests(hostdata->host);
ibmvscsi_set_request_limit(hostdata, 0); if (crq->format == 0x06) { /* We need to re-setup the interpartition connection */
dev_info(hostdata->dev, "Re-enabling adapter!\n");
hostdata->client_migrated = 1;
hostdata->action = IBMVSCSI_HOST_ACTION_REENABLE;
purge_requests(hostdata, DID_REQUEUE);
wake_up(&hostdata->work_wait_q);
} else {
dev_err(hostdata->dev, "Virtual adapter failed rc %d!\n",
crq->format);
ibmvscsi_reset_host(hostdata);
} return; case VIOSRP_CRQ_CMD_RSP: /* real payload */ break; default:
dev_err(hostdata->dev, "got an invalid message type 0x%02x\n",
crq->valid); return;
}
/* The only kind of payload CRQs we should get are responses to * things we send. Make sure this response is to something we * actually sent
*/ if (!valid_event_struct(&hostdata->pool, evt_struct)) {
dev_err(hostdata->dev, "returned correlation_token 0x%p is invalid!\n",
evt_struct); return;
}
if (crq->format == VIOSRP_SRP_FORMAT)
atomic_add(be32_to_cpu(evt_struct->xfer_iu->srp.rsp.req_lim_delta),
&hostdata->request_limit);
timer_delete(&evt_struct->timer);
if ((crq->status != VIOSRP_OK && crq->status != VIOSRP_OK2) && evt_struct->cmnd)
evt_struct->cmnd->result = DID_ERROR << 16; if (evt_struct->done)
evt_struct->done(evt_struct); else
dev_err(hostdata->dev, "returned done() is NULL; not running it!\n");
/* * Lock the host_lock before messing with these structures, since we * are running in a task context
*/
spin_lock_irqsave(evt_struct->hostdata->host->host_lock, flags);
list_del(&evt_struct->list);
free_event_struct(&evt_struct->hostdata->pool, evt_struct);
spin_unlock_irqrestore(evt_struct->hostdata->host->host_lock, flags);
}
/** * ibmvscsi_sdev_configure: Set the "allow_restart" flag for each disk. * @sdev: struct scsi_device device to configure * @lim: Request queue limits * * Enable allow_restart for a device if it is a disk. Adjust the * queue_depth here also as is required by the documentation for * struct scsi_host_template.
*/ staticint ibmvscsi_sdev_configure(struct scsi_device *sdev, struct queue_limits *lim)
{ struct Scsi_Host *shost = sdev->host; unsignedlong lock_flags = 0;
/** * ibmvscsi_get_desired_dma - Calculate IO memory desired by the driver * * @vdev: struct vio_dev for the device whose desired IO mem is to be returned * * Return value: * Number of bytes of IO data the driver will need to perform well.
*/ staticunsignedlong ibmvscsi_get_desired_dma(struct vio_dev *vdev)
{ /* iu_storage data allocated in initialize_event_pool */ unsignedlong desired_io = max_events * sizeof(union viosrp_iu);
/* add io space for sg data */
desired_io += (IBMVSCSI_MAX_SECTORS_DEFAULT * 512 *
IBMVSCSI_CMDS_PER_LUN_DEFAULT);
if (rc) {
ibmvscsi_set_request_limit(hostdata, -1);
dev_err(hostdata->dev, "error after %s\n", action);
}
scsi_unblock_requests(hostdata->host);
}
staticint __ibmvscsi_work_to_do(struct ibmvscsi_host_data *hostdata)
{ if (kthread_should_stop()) return 1; switch (hostdata->action) { case IBMVSCSI_HOST_ACTION_NONE: return 0; case IBMVSCSI_HOST_ACTION_RESET: case IBMVSCSI_HOST_ACTION_REENABLE: case IBMVSCSI_HOST_ACTION_UNBLOCK: default: break;
}
return 1;
}
staticint ibmvscsi_work_to_do(struct ibmvscsi_host_data *hostdata)
{ unsignedlong flags; int rc;
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.