Lines Matching +full:send +full:- +full:migration
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* ------------------------------------------------------------
9 * ------------------------------------------------------------
27 * Senders cannot access the buffer directly, but send messages by
29 * puts the message in the next 16 byte space in round-robin fashion,
51 #include <linux/dma-mapping.h>
83 static unsigned int partition_number = -1;
112 /* ------------------------------------------------------------
116 * ibmvscsi_handle_event: - Interrupt handler for crq events
127 vio_disable_interrupts(to_vio_dev(hostdata->dev)); in ibmvscsi_handle_event()
128 tasklet_schedule(&hostdata->srp_task); in ibmvscsi_handle_event()
133 * ibmvscsi_release_crq_queue() - Deallocates data and unregisters CRQ
146 struct vio_dev *vdev = to_vio_dev(hostdata->dev); in ibmvscsi_release_crq_queue()
147 free_irq(vdev->irq, (void *)hostdata); in ibmvscsi_release_crq_queue()
148 tasklet_kill(&hostdata->srp_task); in ibmvscsi_release_crq_queue()
152 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); in ibmvscsi_release_crq_queue()
154 dma_unmap_single(hostdata->dev, in ibmvscsi_release_crq_queue()
155 queue->msg_token, in ibmvscsi_release_crq_queue()
156 queue->size * sizeof(*queue->msgs), DMA_BIDIRECTIONAL); in ibmvscsi_release_crq_queue()
157 free_page((unsigned long)queue->msgs); in ibmvscsi_release_crq_queue()
161 * crq_queue_next_crq: - Returns the next entry in message queue
172 spin_lock_irqsave(&queue->lock, flags); in crq_queue_next_crq()
173 crq = &queue->msgs[queue->cur]; in crq_queue_next_crq()
174 if (crq->valid != VIOSRP_CRQ_FREE) { in crq_queue_next_crq()
175 if (++queue->cur == queue->size) in crq_queue_next_crq()
176 queue->cur = 0; in crq_queue_next_crq()
184 spin_unlock_irqrestore(&queue->lock, flags); in crq_queue_next_crq()
190 * ibmvscsi_send_crq: - Send a CRQ
198 struct vio_dev *vdev = to_vio_dev(hostdata->dev); in ibmvscsi_send_crq()
205 return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address, word1, word2); in ibmvscsi_send_crq()
209 * ibmvscsi_task: - Process srps asynchronously
215 struct vio_dev *vdev = to_vio_dev(hostdata->dev); in ibmvscsi_task()
221 while ((crq = crq_queue_next_crq(&hostdata->queue)) != NULL) { in ibmvscsi_task()
223 crq->valid = VIOSRP_CRQ_FREE; in ibmvscsi_task()
228 crq = crq_queue_next_crq(&hostdata->queue); in ibmvscsi_task()
232 crq->valid = VIOSRP_CRQ_FREE; in ibmvscsi_task()
251 ppartition_name = of_get_property(of_root, "ibm,partition-name", NULL); in gather_partition_info()
255 p_number_ptr = of_get_property(of_root, "ibm,partition-no", NULL); in gather_partition_info()
263 memset(&hostdata->madapter_info, 0x00, in set_adapter_info()
264 sizeof(hostdata->madapter_info)); in set_adapter_info()
266 dev_info(hostdata->dev, "SRP_VERSION: %s\n", SRP_VERSION); in set_adapter_info()
267 strcpy(hostdata->madapter_info.srp_version, SRP_VERSION); in set_adapter_info()
269 strscpy(hostdata->madapter_info.partition_name, partition_name, in set_adapter_info()
270 sizeof(hostdata->madapter_info.partition_name)); in set_adapter_info()
272 hostdata->madapter_info.partition_number = in set_adapter_info()
275 hostdata->madapter_info.mad_version = cpu_to_be32(SRP_MAD_VERSION_1); in set_adapter_info()
276 hostdata->madapter_info.os_type = cpu_to_be32(SRP_MAD_OS_LINUX); in set_adapter_info()
280 * ibmvscsi_reset_crq_queue() - resets a crq after a failure
288 struct vio_dev *vdev = to_vio_dev(hostdata->dev); in ibmvscsi_reset_crq_queue()
294 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); in ibmvscsi_reset_crq_queue()
298 memset(queue->msgs, 0x00, PAGE_SIZE); in ibmvscsi_reset_crq_queue()
299 queue->cur = 0; in ibmvscsi_reset_crq_queue()
303 /* And re-open it again */ in ibmvscsi_reset_crq_queue()
305 vdev->unit_address, in ibmvscsi_reset_crq_queue()
306 queue->msg_token, PAGE_SIZE); in ibmvscsi_reset_crq_queue()
309 dev_warn(hostdata->dev, "Partner adapter not ready\n"); in ibmvscsi_reset_crq_queue()
311 dev_warn(hostdata->dev, "couldn't register crq--rc 0x%x\n", rc); in ibmvscsi_reset_crq_queue()
317 * ibmvscsi_init_crq_queue() - Initializes and registers CRQ with hypervisor
332 struct vio_dev *vdev = to_vio_dev(hostdata->dev); in ibmvscsi_init_crq_queue()
334 queue->msgs = (struct viosrp_crq *)get_zeroed_page(GFP_KERNEL); in ibmvscsi_init_crq_queue()
336 if (!queue->msgs) in ibmvscsi_init_crq_queue()
338 queue->size = PAGE_SIZE / sizeof(*queue->msgs); in ibmvscsi_init_crq_queue()
340 queue->msg_token = dma_map_single(hostdata->dev, queue->msgs, in ibmvscsi_init_crq_queue()
341 queue->size * sizeof(*queue->msgs), in ibmvscsi_init_crq_queue()
344 if (dma_mapping_error(hostdata->dev, queue->msg_token)) in ibmvscsi_init_crq_queue()
351 vdev->unit_address, in ibmvscsi_init_crq_queue()
352 queue->msg_token, PAGE_SIZE); in ibmvscsi_init_crq_queue()
360 dev_warn(hostdata->dev, "Partner adapter not ready\n"); in ibmvscsi_init_crq_queue()
363 dev_warn(hostdata->dev, "Error %d opening adapter\n", rc); in ibmvscsi_init_crq_queue()
367 queue->cur = 0; in ibmvscsi_init_crq_queue()
368 spin_lock_init(&queue->lock); in ibmvscsi_init_crq_queue()
370 tasklet_init(&hostdata->srp_task, (void *)ibmvscsi_task, in ibmvscsi_init_crq_queue()
373 if (request_irq(vdev->irq, in ibmvscsi_init_crq_queue()
376 dev_err(hostdata->dev, "couldn't register irq 0x%x\n", in ibmvscsi_init_crq_queue()
377 vdev->irq); in ibmvscsi_init_crq_queue()
383 dev_err(hostdata->dev, "Error %d enabling interrupts!!!\n", rc); in ibmvscsi_init_crq_queue()
390 tasklet_kill(&hostdata->srp_task); in ibmvscsi_init_crq_queue()
395 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); in ibmvscsi_init_crq_queue()
398 dma_unmap_single(hostdata->dev, in ibmvscsi_init_crq_queue()
399 queue->msg_token, in ibmvscsi_init_crq_queue()
400 queue->size * sizeof(*queue->msgs), DMA_BIDIRECTIONAL); in ibmvscsi_init_crq_queue()
402 free_page((unsigned long)queue->msgs); in ibmvscsi_init_crq_queue()
404 return -1; in ibmvscsi_init_crq_queue()
408 * ibmvscsi_reenable_crq_queue() - reenables a crq after
416 struct vio_dev *vdev = to_vio_dev(hostdata->dev); in ibmvscsi_reenable_crq_queue()
420 /* Re-enable the CRQ */ in ibmvscsi_reenable_crq_queue()
424 rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address); in ibmvscsi_reenable_crq_queue()
428 dev_err(hostdata->dev, "Error %d enabling adapter\n", rc); in ibmvscsi_reenable_crq_queue()
432 /* ------------------------------------------------------------
436 * initialize_event_pool: - Allocates and initializes the event pool for a host
448 pool->size = size; in initialize_event_pool()
449 pool->next = 0; in initialize_event_pool()
450 pool->events = kcalloc(pool->size, sizeof(*pool->events), GFP_KERNEL); in initialize_event_pool()
451 if (!pool->events) in initialize_event_pool()
452 return -ENOMEM; in initialize_event_pool()
454 pool->iu_storage = in initialize_event_pool()
455 dma_alloc_coherent(hostdata->dev, in initialize_event_pool()
456 pool->size * sizeof(*pool->iu_storage), in initialize_event_pool()
457 &pool->iu_token, GFP_KERNEL); in initialize_event_pool()
458 if (!pool->iu_storage) { in initialize_event_pool()
459 kfree(pool->events); in initialize_event_pool()
460 return -ENOMEM; in initialize_event_pool()
463 for (i = 0; i < pool->size; ++i) { in initialize_event_pool()
464 struct srp_event_struct *evt = &pool->events[i]; in initialize_event_pool()
465 memset(&evt->crq, 0x00, sizeof(evt->crq)); in initialize_event_pool()
466 atomic_set(&evt->free, 1); in initialize_event_pool()
467 evt->crq.valid = VIOSRP_CRQ_CMD_RSP; in initialize_event_pool()
468 evt->crq.IU_length = cpu_to_be16(sizeof(*evt->xfer_iu)); in initialize_event_pool()
469 evt->crq.IU_data_ptr = cpu_to_be64(pool->iu_token + in initialize_event_pool()
470 sizeof(*evt->xfer_iu) * i); in initialize_event_pool()
471 evt->xfer_iu = pool->iu_storage + i; in initialize_event_pool()
472 evt->hostdata = hostdata; in initialize_event_pool()
473 evt->ext_list = NULL; in initialize_event_pool()
474 evt->ext_list_token = 0; in initialize_event_pool()
481 * release_event_pool() - Frees memory of an event pool of a host
491 for (i = 0; i < pool->size; ++i) { in release_event_pool()
492 if (atomic_read(&pool->events[i].free) != 1) in release_event_pool()
494 if (pool->events[i].ext_list) { in release_event_pool()
495 dma_free_coherent(hostdata->dev, in release_event_pool()
497 pool->events[i].ext_list, in release_event_pool()
498 pool->events[i].ext_list_token); in release_event_pool()
502 dev_warn(hostdata->dev, "releasing event pool with %d " in release_event_pool()
504 kfree(pool->events); in release_event_pool()
505 dma_free_coherent(hostdata->dev, in release_event_pool()
506 pool->size * sizeof(*pool->iu_storage), in release_event_pool()
507 pool->iu_storage, pool->iu_token); in release_event_pool()
511 * valid_event_struct: - Determines if event is valid.
520 int index = evt - pool->events; in valid_event_struct()
521 if (index < 0 || index >= pool->size) /* outside of bounds */ in valid_event_struct()
523 if (evt != pool->events + index) /* unaligned */ in valid_event_struct()
529 * free_event_struct() - Changes status of event to "free"
537 dev_err(evt->hostdata->dev, "Freeing invalid event_struct %p " in free_event_struct()
538 "(not in pool %p)\n", evt, pool->events); in free_event_struct()
541 if (atomic_inc_return(&evt->free) != 1) { in free_event_struct()
542 dev_err(evt->hostdata->dev, "Freeing event_struct %p " in free_event_struct()
549 * get_event_struct() - Gets the next free event in pool
559 int poolsize = pool->size; in get_event_struct()
560 int offset = pool->next; in get_event_struct()
564 if (!atomic_dec_if_positive(&pool->events[offset].free)) { in get_event_struct()
565 pool->next = offset; in get_event_struct()
566 return &pool->events[offset]; in get_event_struct()
587 evt_struct->cmnd = NULL; in init_event_struct()
588 evt_struct->cmnd_done = NULL; in init_event_struct()
589 evt_struct->sync_srp = NULL; in init_event_struct()
590 evt_struct->crq.format = format; in init_event_struct()
591 evt_struct->crq.timeout = cpu_to_be16(timeout); in init_event_struct()
592 evt_struct->done = done; in init_event_struct()
595 /* ------------------------------------------------------------
619 if (cmd->sc_data_direction == DMA_TO_DEVICE) in set_srp_direction()
620 srp_cmd->data_out_desc_cnt = numbuf; in set_srp_direction()
622 srp_cmd->data_in_desc_cnt = numbuf; in set_srp_direction()
625 if (cmd->sc_data_direction == DMA_TO_DEVICE) in set_srp_direction()
626 srp_cmd->buf_fmt = fmt << 4; in set_srp_direction()
628 srp_cmd->buf_fmt = fmt; in set_srp_direction()
632 * unmap_cmd_data: - Unmap data pointed in srp_cmd based on the format
643 out_fmt = cmd->buf_fmt >> 4; in unmap_cmd_data()
644 in_fmt = cmd->buf_fmt & ((1U << 4) - 1); in unmap_cmd_data()
649 if (evt_struct->cmnd) in unmap_cmd_data()
650 scsi_dma_unmap(evt_struct->cmnd); in unmap_cmd_data()
662 descr->va = cpu_to_be64(sg_dma_address(sg)); in map_sg_list()
663 descr->len = cpu_to_be32(sg_dma_len(sg)); in map_sg_list()
664 descr->key = 0; in map_sg_list()
671 * map_sg_data: - Maps dma for a scatterlist and initializes descriptor fields
688 (struct srp_direct_buf *) srp_cmd->add_data; in map_sg_data()
706 indirect->table_desc.va = 0; in map_sg_data()
707 indirect->table_desc.len = cpu_to_be32(sg_mapped * in map_sg_data()
709 indirect->table_desc.key = 0; in map_sg_data()
713 &indirect->desc_list[0]); in map_sg_data()
714 indirect->len = cpu_to_be32(total_length); in map_sg_data()
719 if (!evt_struct->ext_list) { in map_sg_data()
720 evt_struct->ext_list = dma_alloc_coherent(dev, in map_sg_data()
722 &evt_struct->ext_list_token, 0); in map_sg_data()
723 if (!evt_struct->ext_list) { in map_sg_data()
725 sdev_printk(KERN_ERR, cmd->device, in map_sg_data()
733 total_length = map_sg_list(cmd, sg_mapped, evt_struct->ext_list); in map_sg_data()
735 indirect->len = cpu_to_be32(total_length); in map_sg_data()
736 indirect->table_desc.va = cpu_to_be64(evt_struct->ext_list_token); in map_sg_data()
737 indirect->table_desc.len = cpu_to_be32(sg_mapped * in map_sg_data()
738 sizeof(indirect->desc_list[0])); in map_sg_data()
739 memcpy(indirect->desc_list, evt_struct->ext_list, in map_sg_data()
745 * map_data_for_srp_cmd: - Calls functions to map data for srp cmds
758 switch (cmd->sc_data_direction) { in map_data_for_srp_cmd()
765 sdev_printk(KERN_ERR, cmd->device, in map_data_for_srp_cmd()
769 sdev_printk(KERN_ERR, cmd->device, in map_data_for_srp_cmd()
771 cmd->sc_data_direction); in map_data_for_srp_cmd()
788 spin_lock_irqsave(hostdata->host->host_lock, flags); in purge_requests()
789 while (!list_empty(&hostdata->sent)) { in purge_requests()
790 evt = list_first_entry(&hostdata->sent, struct srp_event_struct, list); in purge_requests()
791 list_del(&evt->list); in purge_requests()
792 timer_delete(&evt->timer); in purge_requests()
794 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in purge_requests()
795 if (evt->cmnd) { in purge_requests()
796 evt->cmnd->result = (error_code << 16); in purge_requests()
797 unmap_cmd_data(&evt->iu.srp.cmd, evt, in purge_requests()
798 evt->hostdata->dev); in purge_requests()
799 if (evt->cmnd_done) in purge_requests()
800 evt->cmnd_done(evt->cmnd); in purge_requests()
801 } else if (evt->done && evt->crq.format != VIOSRP_MAD_FORMAT && in purge_requests()
802 evt->iu.srp.login_req.opcode != SRP_LOGIN_REQ) in purge_requests()
803 evt->done(evt); in purge_requests()
804 free_event_struct(&evt->hostdata->pool, evt); in purge_requests()
805 spin_lock_irqsave(hostdata->host->host_lock, flags); in purge_requests()
807 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in purge_requests()
811 * ibmvscsi_set_request_limit - Set the adapter request_limit in response to
821 spin_lock_irqsave(hostdata->host->host_lock, flags); in ibmvscsi_set_request_limit()
822 atomic_set(&hostdata->request_limit, limit); in ibmvscsi_set_request_limit()
823 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in ibmvscsi_set_request_limit()
827 * ibmvscsi_reset_host - Reset the connection to the server
832 scsi_block_requests(hostdata->host); in ibmvscsi_reset_host()
836 hostdata->action = IBMVSCSI_HOST_ACTION_RESET; in ibmvscsi_reset_host()
837 wake_up(&hostdata->work_wait_q); in ibmvscsi_reset_host()
841 * ibmvscsi_timeout - Internal command timeout handler
849 struct ibmvscsi_host_data *hostdata = evt_struct->hostdata; in ibmvscsi_timeout()
851 dev_err(hostdata->dev, "Command timed out (%x). Resetting connection\n", in ibmvscsi_timeout()
852 evt_struct->iu.srp.cmd.opcode); in ibmvscsi_timeout()
858 /* ------------------------------------------------------------
862 * ibmvscsi_send_srp_event: - Transforms event to u64 array and calls send_crq()
865 * @timeout: timeout in seconds - 0 means do not time command
874 __be64 *crq_as_u64 = (__be64 *)&evt_struct->crq; in ibmvscsi_send_srp_event()
885 if (evt_struct->crq.format == VIOSRP_SRP_FORMAT) { in ibmvscsi_send_srp_event()
888 atomic_dec_if_positive(&hostdata->request_limit); in ibmvscsi_send_srp_event()
889 /* If request limit was -1 when we started, it is now even in ibmvscsi_send_srp_event()
892 if (request_status < -1) in ibmvscsi_send_srp_event()
899 else if (request_status == -1 && in ibmvscsi_send_srp_event()
900 evt_struct->iu.srp.login_req.opcode != SRP_LOGIN_REQ) in ibmvscsi_send_srp_event()
907 evt_struct->iu.srp.cmd.opcode != SRP_TSK_MGMT) { in ibmvscsi_send_srp_event()
911 * in-flight (the size of the send list). If the in ibmvscsi_send_srp_event()
918 list_for_each_entry(tmp_evt, &hostdata->sent, list) { in ibmvscsi_send_srp_event()
928 *evt_struct->xfer_iu = evt_struct->iu; in ibmvscsi_send_srp_event()
929 evt_struct->xfer_iu->srp.rsp.tag = (u64)evt_struct; in ibmvscsi_send_srp_event()
932 * before we actually send in ibmvscsi_send_srp_event()
935 list_add_tail(&evt_struct->list, &hostdata->sent); in ibmvscsi_send_srp_event()
937 timer_setup(&evt_struct->timer, ibmvscsi_timeout, 0); in ibmvscsi_send_srp_event()
939 evt_struct->timer.expires = jiffies + (timeout * HZ); in ibmvscsi_send_srp_event()
940 add_timer(&evt_struct->timer); in ibmvscsi_send_srp_event()
946 list_del(&evt_struct->list); in ibmvscsi_send_srp_event()
947 timer_delete(&evt_struct->timer); in ibmvscsi_send_srp_event()
950 * Firmware will send a CRQ with a transport event (0xFF) to in ibmvscsi_send_srp_event()
955 dev_warn(hostdata->dev, "send warning. " in ibmvscsi_send_srp_event()
959 dev_err(hostdata->dev, "send error %d\n", rc); in ibmvscsi_send_srp_event()
961 atomic_inc(&hostdata->request_limit); in ibmvscsi_send_srp_event()
968 unmap_cmd_data(&evt_struct->iu.srp.cmd, evt_struct, hostdata->dev); in ibmvscsi_send_srp_event()
970 free_event_struct(&hostdata->pool, evt_struct); in ibmvscsi_send_srp_event()
971 if (srp_req && request_status != -1) in ibmvscsi_send_srp_event()
972 atomic_inc(&hostdata->request_limit); in ibmvscsi_send_srp_event()
976 unmap_cmd_data(&evt_struct->iu.srp.cmd, evt_struct, hostdata->dev); in ibmvscsi_send_srp_event()
978 if (evt_struct->cmnd != NULL) { in ibmvscsi_send_srp_event()
979 evt_struct->cmnd->result = DID_ERROR << 16; in ibmvscsi_send_srp_event()
980 evt_struct->cmnd_done(evt_struct->cmnd); in ibmvscsi_send_srp_event()
981 } else if (evt_struct->done) in ibmvscsi_send_srp_event()
982 evt_struct->done(evt_struct); in ibmvscsi_send_srp_event()
984 free_event_struct(&hostdata->pool, evt_struct); in ibmvscsi_send_srp_event()
989 * handle_cmd_rsp: - Handle responses from commands
997 struct srp_rsp *rsp = &evt_struct->xfer_iu->srp.rsp; in handle_cmd_rsp()
998 struct scsi_cmnd *cmnd = evt_struct->cmnd; in handle_cmd_rsp()
1000 if (unlikely(rsp->opcode != SRP_RSP)) { in handle_cmd_rsp()
1002 dev_warn(evt_struct->hostdata->dev, in handle_cmd_rsp()
1003 "bad SRP RSP type %#02x\n", rsp->opcode); in handle_cmd_rsp()
1007 cmnd->result |= rsp->status; in handle_cmd_rsp()
1008 if (scsi_status_is_check_condition(cmnd->result)) in handle_cmd_rsp()
1009 memcpy(cmnd->sense_buffer, in handle_cmd_rsp()
1010 rsp->data, in handle_cmd_rsp()
1011 be32_to_cpu(rsp->sense_data_len)); in handle_cmd_rsp()
1012 unmap_cmd_data(&evt_struct->iu.srp.cmd, in handle_cmd_rsp()
1014 evt_struct->hostdata->dev); in handle_cmd_rsp()
1016 if (rsp->flags & SRP_RSP_FLAG_DOOVER) in handle_cmd_rsp()
1018 be32_to_cpu(rsp->data_out_res_cnt)); in handle_cmd_rsp()
1019 else if (rsp->flags & SRP_RSP_FLAG_DIOVER) in handle_cmd_rsp()
1020 scsi_set_resid(cmnd, be32_to_cpu(rsp->data_in_res_cnt)); in handle_cmd_rsp()
1023 if (evt_struct->cmnd_done) in handle_cmd_rsp()
1024 evt_struct->cmnd_done(cmnd); in handle_cmd_rsp()
1028 * lun_from_dev: - Returns the lun of the scsi device
1034 return (0x2 << 14) | (dev->id << 8) | (dev->channel << 5) | dev->lun; in lun_from_dev()
1038 * ibmvscsi_queuecommand_lck() - The queuecommand function of the scsi template
1048 struct ibmvscsi_host_data *hostdata = shost_priv(cmnd->device->host); in ibmvscsi_queuecommand_lck()
1049 u16 lun = lun_from_dev(cmnd->device); in ibmvscsi_queuecommand_lck()
1052 cmnd->result = (DID_OK << 16); in ibmvscsi_queuecommand_lck()
1053 evt_struct = get_event_struct(&hostdata->pool); in ibmvscsi_queuecommand_lck()
1058 BUILD_BUG_ON(sizeof(evt_struct->iu.srp) != SRP_MAX_IU_LEN); in ibmvscsi_queuecommand_lck()
1059 memset(&evt_struct->iu.srp, 0x00, sizeof(evt_struct->iu.srp)); in ibmvscsi_queuecommand_lck()
1060 srp_cmd = &evt_struct->iu.srp.cmd; in ibmvscsi_queuecommand_lck()
1061 srp_cmd->opcode = SRP_CMD; in ibmvscsi_queuecommand_lck()
1062 memcpy(srp_cmd->cdb, cmnd->cmnd, sizeof(srp_cmd->cdb)); in ibmvscsi_queuecommand_lck()
1063 int_to_scsilun(lun, &srp_cmd->lun); in ibmvscsi_queuecommand_lck()
1065 if (!map_data_for_srp_cmd(cmnd, evt_struct, srp_cmd, hostdata->dev)) { in ibmvscsi_queuecommand_lck()
1067 sdev_printk(KERN_ERR, cmnd->device, in ibmvscsi_queuecommand_lck()
1069 free_event_struct(&hostdata->pool, evt_struct); in ibmvscsi_queuecommand_lck()
1076 scsi_cmd_to_rq(cmnd)->timeout / HZ); in ibmvscsi_queuecommand_lck()
1078 evt_struct->cmnd = cmnd; in ibmvscsi_queuecommand_lck()
1079 evt_struct->cmnd_done = done; in ibmvscsi_queuecommand_lck()
1082 indirect = (struct srp_indirect_buf *) srp_cmd->add_data; in ibmvscsi_queuecommand_lck()
1083 out_fmt = srp_cmd->buf_fmt >> 4; in ibmvscsi_queuecommand_lck()
1084 in_fmt = srp_cmd->buf_fmt & ((1U << 4) - 1); in ibmvscsi_queuecommand_lck()
1087 indirect->table_desc.va == 0) { in ibmvscsi_queuecommand_lck()
1088 indirect->table_desc.va = in ibmvscsi_queuecommand_lck()
1089 cpu_to_be64(be64_to_cpu(evt_struct->crq.IU_data_ptr) + in ibmvscsi_queuecommand_lck()
1099 /* ------------------------------------------------------------ in DEF_SCSI_QCMD()
1104 * map_persist_bufs: - Pre-map persistent data for adapter logins in DEF_SCSI_QCMD()
1113 hostdata->caps_addr = dma_map_single(hostdata->dev, &hostdata->caps, in DEF_SCSI_QCMD()
1114 sizeof(hostdata->caps), DMA_BIDIRECTIONAL); in DEF_SCSI_QCMD()
1116 if (dma_mapping_error(hostdata->dev, hostdata->caps_addr)) { in DEF_SCSI_QCMD()
1117 dev_err(hostdata->dev, "Unable to map capabilities buffer!\n"); in DEF_SCSI_QCMD()
1121 hostdata->adapter_info_addr = dma_map_single(hostdata->dev, in DEF_SCSI_QCMD()
1122 &hostdata->madapter_info, in DEF_SCSI_QCMD()
1123 sizeof(hostdata->madapter_info), in DEF_SCSI_QCMD()
1125 if (dma_mapping_error(hostdata->dev, hostdata->adapter_info_addr)) { in DEF_SCSI_QCMD()
1126 dev_err(hostdata->dev, "Unable to map adapter info buffer!\n"); in DEF_SCSI_QCMD()
1127 dma_unmap_single(hostdata->dev, hostdata->caps_addr, in DEF_SCSI_QCMD()
1128 sizeof(hostdata->caps), DMA_BIDIRECTIONAL); in DEF_SCSI_QCMD()
1136 * unmap_persist_bufs: - Unmap persistent data needed for adapter logins
1143 dma_unmap_single(hostdata->dev, hostdata->caps_addr, in unmap_persist_bufs()
1144 sizeof(hostdata->caps), DMA_BIDIRECTIONAL); in unmap_persist_bufs()
1146 dma_unmap_single(hostdata->dev, hostdata->adapter_info_addr, in unmap_persist_bufs()
1147 sizeof(hostdata->madapter_info), DMA_BIDIRECTIONAL); in unmap_persist_bufs()
1151 * login_rsp: - Handle response to SRP login request
1159 struct ibmvscsi_host_data *hostdata = evt_struct->hostdata; in login_rsp()
1160 switch (evt_struct->xfer_iu->srp.login_rsp.opcode) { in login_rsp()
1164 dev_info(hostdata->dev, "SRP_LOGIN_REJ reason %u\n", in login_rsp()
1165 evt_struct->xfer_iu->srp.login_rej.reason); in login_rsp()
1167 ibmvscsi_set_request_limit(hostdata, -1); in login_rsp()
1170 dev_err(hostdata->dev, "Invalid login response typecode 0x%02x!\n", in login_rsp()
1171 evt_struct->xfer_iu->srp.login_rsp.opcode); in login_rsp()
1173 ibmvscsi_set_request_limit(hostdata, -1); in login_rsp()
1177 dev_info(hostdata->dev, "SRP_LOGIN succeeded\n"); in login_rsp()
1178 hostdata->client_migrated = 0; in login_rsp()
1180 /* Now we know what the real request-limit is. in login_rsp()
1182 * request_limit could have been set to -1 by this client. in login_rsp()
1185 be32_to_cpu(evt_struct->xfer_iu->srp.login_rsp.req_lim_delta)); in login_rsp()
1188 hostdata->action = IBMVSCSI_HOST_ACTION_UNBLOCK; in login_rsp()
1189 wake_up(&hostdata->work_wait_q); in login_rsp()
1193 * send_srp_login: - Sends the srp login
1203 struct srp_event_struct *evt_struct = get_event_struct(&hostdata->pool); in send_srp_login()
1209 login = &evt_struct->iu.srp.login_req; in send_srp_login()
1211 login->opcode = SRP_LOGIN_REQ; in send_srp_login()
1212 login->req_it_iu_len = cpu_to_be32(sizeof(union srp_iu)); in send_srp_login()
1213 login->req_buf_fmt = cpu_to_be16(SRP_BUF_FORMAT_DIRECT | in send_srp_login()
1222 spin_lock_irqsave(hostdata->host->host_lock, flags); in send_srp_login()
1224 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in send_srp_login()
1225 dev_info(hostdata->dev, "sent SRP login\n"); in send_srp_login()
1230 * capabilities_rsp: - Handle response to MAD adapter capabilities request
1237 struct ibmvscsi_host_data *hostdata = evt_struct->hostdata; in capabilities_rsp()
1239 if (evt_struct->xfer_iu->mad.capabilities.common.status) { in capabilities_rsp()
1240 dev_err(hostdata->dev, "error 0x%X getting capabilities info\n", in capabilities_rsp()
1241 evt_struct->xfer_iu->mad.capabilities.common.status); in capabilities_rsp()
1243 if (hostdata->caps.migration.common.server_support != in capabilities_rsp()
1245 dev_info(hostdata->dev, "Partition migration not supported\n"); in capabilities_rsp()
1248 if (hostdata->caps.reserve.common.server_support == in capabilities_rsp()
1250 dev_info(hostdata->dev, "Client reserve enabled\n"); in capabilities_rsp()
1252 dev_info(hostdata->dev, "Client reserve not supported\n"); in capabilities_rsp()
1260 * send_mad_capabilities: - Sends the mad capabilities request
1269 struct device_node *of_node = hostdata->dev->of_node; in send_mad_capabilities()
1272 evt_struct = get_event_struct(&hostdata->pool); in send_mad_capabilities()
1278 req = &evt_struct->iu.mad.capabilities; in send_mad_capabilities()
1281 hostdata->caps.flags = cpu_to_be32(CAP_LIST_SUPPORTED); in send_mad_capabilities()
1282 if (hostdata->client_migrated) in send_mad_capabilities()
1283 hostdata->caps.flags |= cpu_to_be32(CLIENT_MIGRATED); in send_mad_capabilities()
1285 strscpy(hostdata->caps.name, dev_name(&hostdata->host->shost_gendev), in send_mad_capabilities()
1286 sizeof(hostdata->caps.name)); in send_mad_capabilities()
1288 location = of_get_property(of_node, "ibm,loc-code", NULL); in send_mad_capabilities()
1289 location = location ? location : dev_name(hostdata->dev); in send_mad_capabilities()
1290 strscpy(hostdata->caps.loc, location, sizeof(hostdata->caps.loc)); in send_mad_capabilities()
1292 req->common.type = cpu_to_be32(VIOSRP_CAPABILITIES_TYPE); in send_mad_capabilities()
1293 req->buffer = cpu_to_be64(hostdata->caps_addr); in send_mad_capabilities()
1295 hostdata->caps.migration.common.cap_type = in send_mad_capabilities()
1297 hostdata->caps.migration.common.length = in send_mad_capabilities()
1298 cpu_to_be16(sizeof(hostdata->caps.migration)); in send_mad_capabilities()
1299 hostdata->caps.migration.common.server_support = in send_mad_capabilities()
1301 hostdata->caps.migration.ecl = cpu_to_be32(1); in send_mad_capabilities()
1304 hostdata->caps.reserve.common.cap_type = in send_mad_capabilities()
1306 hostdata->caps.reserve.common.length = in send_mad_capabilities()
1307 cpu_to_be16(sizeof(hostdata->caps.reserve)); in send_mad_capabilities()
1308 hostdata->caps.reserve.common.server_support = in send_mad_capabilities()
1310 hostdata->caps.reserve.type = in send_mad_capabilities()
1312 req->common.length = in send_mad_capabilities()
1313 cpu_to_be16(sizeof(hostdata->caps)); in send_mad_capabilities()
1315 req->common.length = cpu_to_be16(sizeof(hostdata->caps) - in send_mad_capabilities()
1316 sizeof(hostdata->caps.reserve)); in send_mad_capabilities()
1318 spin_lock_irqsave(hostdata->host->host_lock, flags); in send_mad_capabilities()
1320 dev_err(hostdata->dev, "couldn't send CAPABILITIES_REQ!\n"); in send_mad_capabilities()
1321 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in send_mad_capabilities()
1325 * fast_fail_rsp: - Handle response to MAD enable fast fail
1333 struct ibmvscsi_host_data *hostdata = evt_struct->hostdata; in fast_fail_rsp()
1334 u16 status = be16_to_cpu(evt_struct->xfer_iu->mad.fast_fail.common.status); in fast_fail_rsp()
1337 dev_err(hostdata->dev, "fast_fail not supported in server\n"); in fast_fail_rsp()
1339 dev_err(hostdata->dev, "fast_fail request failed\n"); in fast_fail_rsp()
1341 dev_err(hostdata->dev, "error 0x%X enabling fast_fail\n", status); in fast_fail_rsp()
1347 * enable_fast_fail() - Start host initialization
1364 evt_struct = get_event_struct(&hostdata->pool); in enable_fast_fail()
1369 fast_fail_mad = &evt_struct->iu.mad.fast_fail; in enable_fast_fail()
1371 fast_fail_mad->common.type = cpu_to_be32(VIOSRP_ENABLE_FAST_FAIL); in enable_fast_fail()
1372 fast_fail_mad->common.length = cpu_to_be16(sizeof(*fast_fail_mad)); in enable_fast_fail()
1374 spin_lock_irqsave(hostdata->host->host_lock, flags); in enable_fast_fail()
1376 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in enable_fast_fail()
1381 * adapter_info_rsp: - Handle response to MAD adapter info request
1389 struct ibmvscsi_host_data *hostdata = evt_struct->hostdata; in adapter_info_rsp()
1391 if (evt_struct->xfer_iu->mad.adapter_info.common.status) { in adapter_info_rsp()
1392 dev_err(hostdata->dev, "error %d getting adapter info\n", in adapter_info_rsp()
1393 evt_struct->xfer_iu->mad.adapter_info.common.status); in adapter_info_rsp()
1395 dev_info(hostdata->dev, "host srp version: %s, " in adapter_info_rsp()
1397 hostdata->madapter_info.srp_version, in adapter_info_rsp()
1398 hostdata->madapter_info.partition_name, in adapter_info_rsp()
1399 be32_to_cpu(hostdata->madapter_info.partition_number), in adapter_info_rsp()
1400 be32_to_cpu(hostdata->madapter_info.os_type), in adapter_info_rsp()
1401 be32_to_cpu(hostdata->madapter_info.port_max_txu[0])); in adapter_info_rsp()
1403 if (hostdata->madapter_info.port_max_txu[0]) in adapter_info_rsp()
1404 hostdata->host->max_sectors = in adapter_info_rsp()
1405 be32_to_cpu(hostdata->madapter_info.port_max_txu[0]) >> 9; in adapter_info_rsp()
1407 if (be32_to_cpu(hostdata->madapter_info.os_type) == SRP_MAD_OS_AIX && in adapter_info_rsp()
1408 strcmp(hostdata->madapter_info.srp_version, "1.6a") <= 0) { in adapter_info_rsp()
1409 dev_err(hostdata->dev, "host (Ver. %s) doesn't support large transfers\n", in adapter_info_rsp()
1410 hostdata->madapter_info.srp_version); in adapter_info_rsp()
1411 dev_err(hostdata->dev, "limiting scatterlists to %d\n", in adapter_info_rsp()
1413 hostdata->host->sg_tablesize = MAX_INDIRECT_BUFS; in adapter_info_rsp()
1416 if (be32_to_cpu(hostdata->madapter_info.os_type) == SRP_MAD_OS_AIX) { in adapter_info_rsp()
1426 * send_mad_adapter_info: - Sends the mad adapter info request
1440 evt_struct = get_event_struct(&hostdata->pool); in send_mad_adapter_info()
1448 req = &evt_struct->iu.mad.adapter_info; in send_mad_adapter_info()
1451 req->common.type = cpu_to_be32(VIOSRP_ADAPTER_INFO_TYPE); in send_mad_adapter_info()
1452 req->common.length = cpu_to_be16(sizeof(hostdata->madapter_info)); in send_mad_adapter_info()
1453 req->buffer = cpu_to_be64(hostdata->adapter_info_addr); in send_mad_adapter_info()
1455 spin_lock_irqsave(hostdata->host->host_lock, flags); in send_mad_adapter_info()
1457 dev_err(hostdata->dev, "couldn't send ADAPTER_INFO_REQ!\n"); in send_mad_adapter_info()
1458 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in send_mad_adapter_info()
1462 * init_adapter() - Start virtual adapter initialization sequence
1478 if (evt_struct->sync_srp) in sync_completion()
1479 *evt_struct->sync_srp = *evt_struct->xfer_iu; in sync_completion()
1481 complete(&evt_struct->comp); in sync_completion()
1486 * send this over to the server and wait synchronously for the response
1490 struct ibmvscsi_host_data *hostdata = shost_priv(cmd->device->host); in ibmvscsi_eh_abort_handler()
1497 u16 lun = lun_from_dev(cmd->device); in ibmvscsi_eh_abort_handler()
1503 spin_lock_irqsave(hostdata->host->host_lock, flags); in ibmvscsi_eh_abort_handler()
1507 list_for_each_entry(tmp_evt, &hostdata->sent, list) { in ibmvscsi_eh_abort_handler()
1508 if (tmp_evt->cmnd == cmd) { in ibmvscsi_eh_abort_handler()
1515 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in ibmvscsi_eh_abort_handler()
1519 evt = get_event_struct(&hostdata->pool); in ibmvscsi_eh_abort_handler()
1521 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in ibmvscsi_eh_abort_handler()
1522 sdev_printk(KERN_ERR, cmd->device, in ibmvscsi_eh_abort_handler()
1532 tsk_mgmt = &evt->iu.srp.tsk_mgmt; in ibmvscsi_eh_abort_handler()
1536 tsk_mgmt->opcode = SRP_TSK_MGMT; in ibmvscsi_eh_abort_handler()
1537 int_to_scsilun(lun, &tsk_mgmt->lun); in ibmvscsi_eh_abort_handler()
1538 tsk_mgmt->tsk_mgmt_func = SRP_TSK_ABORT_TASK; in ibmvscsi_eh_abort_handler()
1539 tsk_mgmt->task_tag = (u64) found_evt; in ibmvscsi_eh_abort_handler()
1541 evt->sync_srp = &srp_rsp; in ibmvscsi_eh_abort_handler()
1543 init_completion(&evt->comp); in ibmvscsi_eh_abort_handler()
1549 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in ibmvscsi_eh_abort_handler()
1551 spin_lock_irqsave(hostdata->host->host_lock, flags); in ibmvscsi_eh_abort_handler()
1554 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in ibmvscsi_eh_abort_handler()
1557 sdev_printk(KERN_ERR, cmd->device, in ibmvscsi_eh_abort_handler()
1558 "failed to send abort() event. rc=%d\n", rsp_rc); in ibmvscsi_eh_abort_handler()
1562 sdev_printk(KERN_INFO, cmd->device, in ibmvscsi_eh_abort_handler()
1566 wait_for_completion(&evt->comp); in ibmvscsi_eh_abort_handler()
1571 sdev_printk(KERN_WARNING, cmd->device, "abort bad SRP RSP type %d\n", in ibmvscsi_eh_abort_handler()
1583 sdev_printk(KERN_WARNING, cmd->device, in ibmvscsi_eh_abort_handler()
1585 rsp_rc, tsk_mgmt->task_tag); in ibmvscsi_eh_abort_handler()
1593 spin_lock_irqsave(hostdata->host->host_lock, flags); in ibmvscsi_eh_abort_handler()
1595 list_for_each_entry(tmp_evt, &hostdata->sent, list) { in ibmvscsi_eh_abort_handler()
1596 if (tmp_evt->cmnd == cmd) { in ibmvscsi_eh_abort_handler()
1603 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in ibmvscsi_eh_abort_handler()
1604 sdev_printk(KERN_INFO, cmd->device, "aborted task tag 0x%llx completed\n", in ibmvscsi_eh_abort_handler()
1605 tsk_mgmt->task_tag); in ibmvscsi_eh_abort_handler()
1609 sdev_printk(KERN_INFO, cmd->device, "successfully aborted task tag 0x%llx\n", in ibmvscsi_eh_abort_handler()
1610 tsk_mgmt->task_tag); in ibmvscsi_eh_abort_handler()
1612 cmd->result = (DID_ABORT << 16); in ibmvscsi_eh_abort_handler()
1613 list_del(&found_evt->list); in ibmvscsi_eh_abort_handler()
1614 unmap_cmd_data(&found_evt->iu.srp.cmd, found_evt, in ibmvscsi_eh_abort_handler()
1615 found_evt->hostdata->dev); in ibmvscsi_eh_abort_handler()
1616 free_event_struct(&found_evt->hostdata->pool, found_evt); in ibmvscsi_eh_abort_handler()
1617 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in ibmvscsi_eh_abort_handler()
1618 atomic_inc(&hostdata->request_limit); in ibmvscsi_eh_abort_handler()
1624 * template send this over to the server and wait synchronously for the
1629 struct ibmvscsi_host_data *hostdata = shost_priv(cmd->device->host); in ibmvscsi_eh_device_reset_handler()
1636 u16 lun = lun_from_dev(cmd->device); in ibmvscsi_eh_device_reset_handler()
1639 spin_lock_irqsave(hostdata->host->host_lock, flags); in ibmvscsi_eh_device_reset_handler()
1642 evt = get_event_struct(&hostdata->pool); in ibmvscsi_eh_device_reset_handler()
1644 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in ibmvscsi_eh_device_reset_handler()
1645 sdev_printk(KERN_ERR, cmd->device, in ibmvscsi_eh_device_reset_handler()
1655 tsk_mgmt = &evt->iu.srp.tsk_mgmt; in ibmvscsi_eh_device_reset_handler()
1659 tsk_mgmt->opcode = SRP_TSK_MGMT; in ibmvscsi_eh_device_reset_handler()
1660 int_to_scsilun(lun, &tsk_mgmt->lun); in ibmvscsi_eh_device_reset_handler()
1661 tsk_mgmt->tsk_mgmt_func = SRP_TSK_LUN_RESET; in ibmvscsi_eh_device_reset_handler()
1663 evt->sync_srp = &srp_rsp; in ibmvscsi_eh_device_reset_handler()
1665 init_completion(&evt->comp); in ibmvscsi_eh_device_reset_handler()
1671 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in ibmvscsi_eh_device_reset_handler()
1673 spin_lock_irqsave(hostdata->host->host_lock, flags); in ibmvscsi_eh_device_reset_handler()
1676 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in ibmvscsi_eh_device_reset_handler()
1679 sdev_printk(KERN_ERR, cmd->device, in ibmvscsi_eh_device_reset_handler()
1680 "failed to send reset event. rc=%d\n", rsp_rc); in ibmvscsi_eh_device_reset_handler()
1684 sdev_printk(KERN_INFO, cmd->device, "resetting device. lun 0x%llx\n", in ibmvscsi_eh_device_reset_handler()
1687 wait_for_completion(&evt->comp); in ibmvscsi_eh_device_reset_handler()
1692 sdev_printk(KERN_WARNING, cmd->device, "reset bad SRP RSP type %d\n", in ibmvscsi_eh_device_reset_handler()
1704 sdev_printk(KERN_WARNING, cmd->device, in ibmvscsi_eh_device_reset_handler()
1706 rsp_rc, tsk_mgmt->task_tag); in ibmvscsi_eh_device_reset_handler()
1713 spin_lock_irqsave(hostdata->host->host_lock, flags); in ibmvscsi_eh_device_reset_handler()
1714 list_for_each_entry_safe(tmp_evt, pos, &hostdata->sent, list) { in ibmvscsi_eh_device_reset_handler()
1715 if ((tmp_evt->cmnd) && (tmp_evt->cmnd->device == cmd->device)) { in ibmvscsi_eh_device_reset_handler()
1716 if (tmp_evt->cmnd) in ibmvscsi_eh_device_reset_handler()
1717 tmp_evt->cmnd->result = (DID_RESET << 16); in ibmvscsi_eh_device_reset_handler()
1718 list_del(&tmp_evt->list); in ibmvscsi_eh_device_reset_handler()
1719 unmap_cmd_data(&tmp_evt->iu.srp.cmd, tmp_evt, in ibmvscsi_eh_device_reset_handler()
1720 tmp_evt->hostdata->dev); in ibmvscsi_eh_device_reset_handler()
1721 free_event_struct(&tmp_evt->hostdata->pool, in ibmvscsi_eh_device_reset_handler()
1723 atomic_inc(&hostdata->request_limit); in ibmvscsi_eh_device_reset_handler()
1724 if (tmp_evt->cmnd_done) in ibmvscsi_eh_device_reset_handler()
1725 tmp_evt->cmnd_done(tmp_evt->cmnd); in ibmvscsi_eh_device_reset_handler()
1726 else if (tmp_evt->done) in ibmvscsi_eh_device_reset_handler()
1727 tmp_evt->done(tmp_evt); in ibmvscsi_eh_device_reset_handler()
1730 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in ibmvscsi_eh_device_reset_handler()
1735 * ibmvscsi_eh_host_reset_handler - Reset the connection to the server
1741 struct ibmvscsi_host_data *hostdata = shost_priv(cmd->device->host); in ibmvscsi_eh_host_reset_handler()
1743 dev_err(hostdata->dev, "Resetting connection due to error recovery\n"); in ibmvscsi_eh_host_reset_handler()
1749 atomic_read(&hostdata->request_limit) < 2;) { in ibmvscsi_eh_host_reset_handler()
1754 if (atomic_read(&hostdata->request_limit) <= 0) in ibmvscsi_eh_host_reset_handler()
1761 * ibmvscsi_handle_crq: - Handles and frees received events in the CRQ
1773 (__force struct srp_event_struct *)crq->IU_data_ptr; in ibmvscsi_handle_crq()
1774 switch (crq->valid) { in ibmvscsi_handle_crq()
1776 switch (crq->format) { in ibmvscsi_handle_crq()
1778 dev_info(hostdata->dev, "partner initialized\n"); in ibmvscsi_handle_crq()
1779 /* Send back a response */ in ibmvscsi_handle_crq()
1785 dev_err(hostdata->dev, "Unable to send init rsp. rc=%ld\n", rc); in ibmvscsi_handle_crq()
1790 dev_info(hostdata->dev, "partner initialization complete\n"); in ibmvscsi_handle_crq()
1796 dev_err(hostdata->dev, "unknown crq message type: %d\n", crq->format); in ibmvscsi_handle_crq()
1800 scsi_block_requests(hostdata->host); in ibmvscsi_handle_crq()
1802 if (crq->format == 0x06) { in ibmvscsi_handle_crq()
1803 /* We need to re-setup the interpartition connection */ in ibmvscsi_handle_crq()
1804 dev_info(hostdata->dev, "Re-enabling adapter!\n"); in ibmvscsi_handle_crq()
1805 hostdata->client_migrated = 1; in ibmvscsi_handle_crq()
1806 hostdata->action = IBMVSCSI_HOST_ACTION_REENABLE; in ibmvscsi_handle_crq()
1808 wake_up(&hostdata->work_wait_q); in ibmvscsi_handle_crq()
1810 dev_err(hostdata->dev, "Virtual adapter failed rc %d!\n", in ibmvscsi_handle_crq()
1811 crq->format); in ibmvscsi_handle_crq()
1818 dev_err(hostdata->dev, "got an invalid message type 0x%02x\n", in ibmvscsi_handle_crq()
1819 crq->valid); in ibmvscsi_handle_crq()
1824 * things we send. Make sure this response is to something we in ibmvscsi_handle_crq()
1827 if (!valid_event_struct(&hostdata->pool, evt_struct)) { in ibmvscsi_handle_crq()
1828 dev_err(hostdata->dev, "returned correlation_token 0x%p is invalid!\n", in ibmvscsi_handle_crq()
1833 if (atomic_read(&evt_struct->free)) { in ibmvscsi_handle_crq()
1834 dev_err(hostdata->dev, "received duplicate correlation_token 0x%p!\n", in ibmvscsi_handle_crq()
1839 if (crq->format == VIOSRP_SRP_FORMAT) in ibmvscsi_handle_crq()
1840 atomic_add(be32_to_cpu(evt_struct->xfer_iu->srp.rsp.req_lim_delta), in ibmvscsi_handle_crq()
1841 &hostdata->request_limit); in ibmvscsi_handle_crq()
1843 timer_delete(&evt_struct->timer); in ibmvscsi_handle_crq()
1845 if ((crq->status != VIOSRP_OK && crq->status != VIOSRP_OK2) && evt_struct->cmnd) in ibmvscsi_handle_crq()
1846 evt_struct->cmnd->result = DID_ERROR << 16; in ibmvscsi_handle_crq()
1847 if (evt_struct->done) in ibmvscsi_handle_crq()
1848 evt_struct->done(evt_struct); in ibmvscsi_handle_crq()
1850 dev_err(hostdata->dev, "returned done() is NULL; not running it!\n"); in ibmvscsi_handle_crq()
1856 spin_lock_irqsave(evt_struct->hostdata->host->host_lock, flags); in ibmvscsi_handle_crq()
1857 list_del(&evt_struct->list); in ibmvscsi_handle_crq()
1858 free_event_struct(&evt_struct->hostdata->pool, evt_struct); in ibmvscsi_handle_crq()
1859 spin_unlock_irqrestore(evt_struct->hostdata->host->host_lock, flags); in ibmvscsi_handle_crq()
1874 struct Scsi_Host *shost = sdev->host; in ibmvscsi_sdev_configure()
1877 spin_lock_irqsave(shost->host_lock, lock_flags); in ibmvscsi_sdev_configure()
1878 if (sdev->type == TYPE_DISK) { in ibmvscsi_sdev_configure()
1879 sdev->allow_restart = 1; in ibmvscsi_sdev_configure()
1880 blk_queue_rq_timeout(sdev->request_queue, 120 * HZ); in ibmvscsi_sdev_configure()
1882 spin_unlock_irqrestore(shost->host_lock, lock_flags); in ibmvscsi_sdev_configure()
1887 * ibmvscsi_change_queue_depth - Change the device's queue depth
1901 /* ------------------------------------------------------------
1911 len = snprintf(buf, sizeof(hostdata->caps.loc), "%s\n", in show_host_vhost_loc()
1912 hostdata->caps.loc); in show_host_vhost_loc()
1931 len = snprintf(buf, sizeof(hostdata->caps.name), "%s\n", in show_host_vhost_name()
1932 hostdata->caps.name); in show_host_vhost_name()
1952 hostdata->madapter_info.srp_version); in show_host_srp_version()
1973 hostdata->madapter_info.partition_name); in show_host_partition_name()
1994 be32_to_cpu(hostdata->madapter_info.partition_number)); in show_host_partition_number()
2014 be32_to_cpu(hostdata->madapter_info.mad_version)); in show_host_mad_version()
2034 be32_to_cpu(hostdata->madapter_info.os_type)); in show_host_os_type()
2064 dev_info(hostdata->dev, "Initiating adapter reset!\n"); in ibmvscsi_host_reset()
2084 /* ------------------------------------------------------------
2101 .this_id = -1,
2107 * ibmvscsi_get_desired_dma - Calculate IO memory desired by the driver
2132 spin_lock_irqsave(hostdata->host->host_lock, flags); in ibmvscsi_do_work()
2133 switch (hostdata->action) { in ibmvscsi_do_work()
2138 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in ibmvscsi_do_work()
2139 rc = ibmvscsi_reset_crq_queue(&hostdata->queue, hostdata); in ibmvscsi_do_work()
2140 spin_lock_irqsave(hostdata->host->host_lock, flags); in ibmvscsi_do_work()
2143 vio_enable_interrupts(to_vio_dev(hostdata->dev)); in ibmvscsi_do_work()
2147 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in ibmvscsi_do_work()
2148 rc = ibmvscsi_reenable_crq_queue(&hostdata->queue, hostdata); in ibmvscsi_do_work()
2149 spin_lock_irqsave(hostdata->host->host_lock, flags); in ibmvscsi_do_work()
2155 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in ibmvscsi_do_work()
2159 hostdata->action = IBMVSCSI_HOST_ACTION_NONE; in ibmvscsi_do_work()
2160 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in ibmvscsi_do_work()
2163 ibmvscsi_set_request_limit(hostdata, -1); in ibmvscsi_do_work()
2164 dev_err(hostdata->dev, "error after %s\n", action); in ibmvscsi_do_work()
2167 scsi_unblock_requests(hostdata->host); in ibmvscsi_do_work()
2174 switch (hostdata->action) { in __ibmvscsi_work_to_do()
2192 spin_lock_irqsave(hostdata->host->host_lock, flags); in ibmvscsi_work_to_do()
2194 spin_unlock_irqrestore(hostdata->host->host_lock, flags); in ibmvscsi_work_to_do()
2207 rc = wait_event_interruptible(hostdata->work_wait_q, in ibmvscsi_work()
2228 struct device *dev = &vdev->dev; in ibmvscsi_probe()
2234 dev_set_drvdata(&vdev->dev, NULL); in ibmvscsi_probe()
2238 dev_err(&vdev->dev, "couldn't allocate host data\n"); in ibmvscsi_probe()
2242 host->transportt = ibmvscsi_transport_template; in ibmvscsi_probe()
2245 INIT_LIST_HEAD(&hostdata->sent); in ibmvscsi_probe()
2246 init_waitqueue_head(&hostdata->work_wait_q); in ibmvscsi_probe()
2247 hostdata->host = host; in ibmvscsi_probe()
2248 hostdata->dev = dev; in ibmvscsi_probe()
2249 ibmvscsi_set_request_limit(hostdata, -1); in ibmvscsi_probe()
2250 hostdata->host->max_sectors = IBMVSCSI_MAX_SECTORS_DEFAULT; in ibmvscsi_probe()
2253 dev_err(&vdev->dev, "couldn't map persistent buffers\n"); in ibmvscsi_probe()
2257 hostdata->work_thread = kthread_run(ibmvscsi_work, hostdata, "%s_%d", in ibmvscsi_probe()
2258 "ibmvscsi", host->host_no); in ibmvscsi_probe()
2260 if (IS_ERR(hostdata->work_thread)) { in ibmvscsi_probe()
2261 dev_err(&vdev->dev, "couldn't initialize kthread. rc=%ld\n", in ibmvscsi_probe()
2262 PTR_ERR(hostdata->work_thread)); in ibmvscsi_probe()
2266 rc = ibmvscsi_init_crq_queue(&hostdata->queue, hostdata, max_events); in ibmvscsi_probe()
2268 dev_err(&vdev->dev, "couldn't initialize crq. rc=%d\n", rc); in ibmvscsi_probe()
2271 if (initialize_event_pool(&hostdata->pool, max_events, hostdata) != 0) { in ibmvscsi_probe()
2272 dev_err(&vdev->dev, "couldn't initialize event pool\n"); in ibmvscsi_probe()
2276 host->max_lun = IBMVSCSI_MAX_LUN; in ibmvscsi_probe()
2277 host->max_id = max_id; in ibmvscsi_probe()
2278 host->max_channel = max_channel; in ibmvscsi_probe()
2279 host->max_cmd_len = 16; in ibmvscsi_probe()
2283 host->max_id, host->max_lun, host->max_channel); in ibmvscsi_probe()
2285 if (scsi_add_host(hostdata->host, hostdata->dev)) in ibmvscsi_probe()
2289 memcpy(ids.port_id, hostdata->madapter_info.partition_name, in ibmvscsi_probe()
2296 /* Try to send an initialization message. Note that this is allowed in ibmvscsi_probe()
2310 atomic_read(&hostdata->request_limit) < 2;) { in ibmvscsi_probe()
2316 if (atomic_read(&hostdata->request_limit) > 0) in ibmvscsi_probe()
2320 dev_set_drvdata(&vdev->dev, hostdata); in ibmvscsi_probe()
2322 list_add_tail(&hostdata->host_list, &ibmvscsi_head); in ibmvscsi_probe()
2327 scsi_remove_host(hostdata->host); in ibmvscsi_probe()
2329 release_event_pool(&hostdata->pool, hostdata); in ibmvscsi_probe()
2331 ibmvscsi_release_crq_queue(&hostdata->queue, hostdata, max_events); in ibmvscsi_probe()
2333 kthread_stop(hostdata->work_thread); in ibmvscsi_probe()
2339 return -1; in ibmvscsi_probe()
2344 struct ibmvscsi_host_data *hostdata = dev_get_drvdata(&vdev->dev); in ibmvscsi_remove()
2346 srp_remove_host(hostdata->host); in ibmvscsi_remove()
2347 scsi_remove_host(hostdata->host); in ibmvscsi_remove()
2350 release_event_pool(&hostdata->pool, hostdata); in ibmvscsi_remove()
2352 ibmvscsi_release_crq_queue(&hostdata->queue, hostdata, in ibmvscsi_remove()
2355 kthread_stop(hostdata->work_thread); in ibmvscsi_remove()
2359 list_del(&hostdata->host_list); in ibmvscsi_remove()
2362 scsi_host_put(hostdata->host); in ibmvscsi_remove()
2375 vio_disable_interrupts(to_vio_dev(hostdata->dev)); in ibmvscsi_resume()
2376 tasklet_schedule(&hostdata->srp_task); in ibmvscsi_resume()
2386 {"vscsi", "IBM,v-scsi"},
2416 return -ENODEV; in ibmvscsi_module_init()
2421 return -ENOMEM; in ibmvscsi_module_init()