Lines Matching +full:my +full:- +full:drc +full:- +full:index

1 // SPDX-License-Identifier: GPL-2.0+
83 * h_request_vmc: - request a hypervisor virtual management channel device
84 * @vmc_index: drc index of the vmc device created
91 * 0 - Success
92 * Non-zero - Failure
114 * ibmvmc_handle_event: - Interrupt handler for crq events
127 vio_disable_interrupts(to_vio_dev(adapter->dev)); in ibmvmc_handle_event()
128 tasklet_schedule(&adapter->work_task); in ibmvmc_handle_event()
134 * ibmvmc_release_crq_queue - Release CRQ Queue
139 * 0 - Success
140 * Non-Zero - Failure
144 struct vio_dev *vdev = to_vio_dev(adapter->dev); in ibmvmc_release_crq_queue()
145 struct crq_queue *queue = &adapter->queue; in ibmvmc_release_crq_queue()
147 free_irq(vdev->irq, (void *)adapter); in ibmvmc_release_crq_queue()
148 tasklet_kill(&adapter->work_task); in ibmvmc_release_crq_queue()
150 if (adapter->reset_task) in ibmvmc_release_crq_queue()
151 kthread_stop(adapter->reset_task); in ibmvmc_release_crq_queue()
153 h_free_crq(vdev->unit_address); in ibmvmc_release_crq_queue()
154 dma_unmap_single(adapter->dev, in ibmvmc_release_crq_queue()
155 queue->msg_token, in ibmvmc_release_crq_queue()
156 queue->size * sizeof(*queue->msgs), DMA_BIDIRECTIONAL); in ibmvmc_release_crq_queue()
157 free_page((unsigned long)queue->msgs); in ibmvmc_release_crq_queue()
161 * ibmvmc_reset_crq_queue - Reset CRQ Queue
169 * 0 - Success
170 * Non-Zero - Failure
174 struct vio_dev *vdev = to_vio_dev(adapter->dev); in ibmvmc_reset_crq_queue()
175 struct crq_queue *queue = &adapter->queue; in ibmvmc_reset_crq_queue()
179 h_free_crq(vdev->unit_address); in ibmvmc_reset_crq_queue()
182 memset(queue->msgs, 0x00, PAGE_SIZE); in ibmvmc_reset_crq_queue()
183 queue->cur = 0; in ibmvmc_reset_crq_queue()
185 /* And re-open it again */ in ibmvmc_reset_crq_queue()
187 vdev->unit_address, in ibmvmc_reset_crq_queue()
188 queue->msg_token, PAGE_SIZE); in ibmvmc_reset_crq_queue()
191 dev_warn(adapter->dev, "Partner adapter not ready\n"); in ibmvmc_reset_crq_queue()
193 dev_err(adapter->dev, "couldn't register crq--rc 0x%x\n", rc); in ibmvmc_reset_crq_queue()
199 * crq_queue_next_crq: - Returns the next entry in message queue
210 spin_lock_irqsave(&queue->lock, flags); in crq_queue_next_crq()
211 crq = &queue->msgs[queue->cur]; in crq_queue_next_crq()
212 if (crq->valid & 0x80) { in crq_queue_next_crq()
213 if (++queue->cur == queue->size) in crq_queue_next_crq()
214 queue->cur = 0; in crq_queue_next_crq()
224 spin_unlock_irqrestore(&queue->lock, flags); in crq_queue_next_crq()
230 * ibmvmc_send_crq - Send CRQ
237 * 0 - Success
238 * Non-Zero - Failure
243 struct vio_dev *vdev = to_vio_dev(adapter->dev); in ibmvmc_send_crq()
246 dev_dbg(adapter->dev, "(0x%x, 0x%016llx, 0x%016llx)\n", in ibmvmc_send_crq()
247 vdev->unit_address, word1, word2); in ibmvmc_send_crq()
254 rc = plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address, word1, word2); in ibmvmc_send_crq()
255 dev_dbg(adapter->dev, "rc = 0x%lx\n", rc); in ibmvmc_send_crq()
261 * alloc_dma_buffer - Create DMA Buffer
284 *dma_handle = dma_map_single(&vdev->dev, buffer, size, in alloc_dma_buffer()
287 if (dma_mapping_error(&vdev->dev, *dma_handle)) { in alloc_dma_buffer()
297 * free_dma_buffer - Free DMA Buffer
310 dma_unmap_single(&vdev->dev, dma_handle, size, DMA_BIDIRECTIONAL); in free_dma_buffer()
317 * ibmvmc_get_valid_hmc_buffer - Retrieve Valid HMC Buffer
319 * @hmc_index: HMC Index Field
348 * ibmvmc_get_free_hmc_buffer - Get Free HMC Buffer
351 * @hmc_index: Hmc Index field
364 dev_info(adapter->dev, "get_free_hmc_buffer: invalid hmc_index=0x%x\n", in ibmvmc_get_free_hmc_buffer()
384 * ibmvmc_free_hmc_buffer - Free an HMC Buffer
395 spin_lock_irqsave(&hmc->lock, flags); in ibmvmc_free_hmc_buffer()
396 buffer->free = 1; in ibmvmc_free_hmc_buffer()
397 spin_unlock_irqrestore(&hmc->lock, flags); in ibmvmc_free_hmc_buffer()
401 * ibmvmc_count_hmc_buffers - Count HMC Buffers
403 * @hmc_index: HMC Index field
438 * ibmvmc_get_free_hmc - Get Free HMC
455 hmcs[i].index = i; in ibmvmc_get_free_hmc()
467 * ibmvmc_return_hmc - Return an HMC Connection
475 * 0 - Success
476 * Non-zero - Failure
486 if (!hmc || !hmc->adapter) in ibmvmc_return_hmc()
487 return -EIO; in ibmvmc_return_hmc()
490 if (hmc->file_session) { in ibmvmc_return_hmc()
491 struct ibmvmc_file_session *session = hmc->file_session; in ibmvmc_return_hmc()
493 session->valid = 0; in ibmvmc_return_hmc()
498 adapter = hmc->adapter; in ibmvmc_return_hmc()
499 vdev = to_vio_dev(adapter->dev); in ibmvmc_return_hmc()
501 spin_lock_irqsave(&hmc->lock, flags); in ibmvmc_return_hmc()
502 hmc->index = 0; in ibmvmc_return_hmc()
503 hmc->state = ibmhmc_state_free; in ibmvmc_return_hmc()
504 hmc->queue_head = 0; in ibmvmc_return_hmc()
505 hmc->queue_tail = 0; in ibmvmc_return_hmc()
506 buffer = hmc->buffer; in ibmvmc_return_hmc()
513 dev_dbg(adapter->dev, "Forgot buffer id 0x%lx\n", i); in ibmvmc_return_hmc()
517 hmc->queue_outbound_msgs[i] = VMC_INVALID_BUFFER_ID; in ibmvmc_return_hmc()
520 spin_unlock_irqrestore(&hmc->lock, flags); in ibmvmc_return_hmc()
526 * ibmvmc_send_open - Interface Open
540 * 0 - Success
541 * Non-zero - Failure
551 if (!hmc || !hmc->adapter) in ibmvmc_send_open()
552 return -EIO; in ibmvmc_send_open()
554 adapter = hmc->adapter; in ibmvmc_send_open()
556 dev_dbg(adapter->dev, "send_open: 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx\n", in ibmvmc_send_open()
557 (unsigned long)buffer->size, (unsigned long)adapter->liobn, in ibmvmc_send_open()
558 (unsigned long)buffer->dma_addr_local, in ibmvmc_send_open()
559 (unsigned long)adapter->riobn, in ibmvmc_send_open()
560 (unsigned long)buffer->dma_addr_remote); in ibmvmc_send_open()
562 rc = h_copy_rdma(buffer->size, in ibmvmc_send_open()
563 adapter->liobn, in ibmvmc_send_open()
564 buffer->dma_addr_local, in ibmvmc_send_open()
565 adapter->riobn, in ibmvmc_send_open()
566 buffer->dma_addr_remote); in ibmvmc_send_open()
568 dev_err(adapter->dev, "Error: In send_open, h_copy_rdma rc 0x%x\n", in ibmvmc_send_open()
570 return -EIO; in ibmvmc_send_open()
573 hmc->state = ibmhmc_state_opening; in ibmvmc_send_open()
579 crq_msg.hmc_session = hmc->session; in ibmvmc_send_open()
580 crq_msg.hmc_index = hmc->index; in ibmvmc_send_open()
581 crq_msg.var2.buffer_id = cpu_to_be16(buffer->id); in ibmvmc_send_open()
592 * ibmvmc_send_close - Interface Close
602 * 0 - Success
603 * Non-zero - Failure
612 if (!hmc || !hmc->adapter) in ibmvmc_send_close()
613 return -EIO; in ibmvmc_send_close()
615 adapter = hmc->adapter; in ibmvmc_send_close()
617 dev_info(adapter->dev, "CRQ send: close\n"); in ibmvmc_send_close()
623 crq_msg.hmc_session = hmc->session; in ibmvmc_send_close()
624 crq_msg.hmc_index = hmc->index; in ibmvmc_send_close()
636 * ibmvmc_send_capabilities - Send VMC Capabilities
649 * 0 - Success
656 dev_dbg(adapter->dev, "ibmvmc: CRQ send: capabilities\n"); in ibmvmc_send_capabilities()
665 crq_msg.crq_size = cpu_to_be16(adapter->queue.size); in ibmvmc_send_capabilities()
677 * ibmvmc_send_add_buffer_resp - Add Buffer Response
682 * @hmc_index: HMC Index field
690 * 0 - Success
699 dev_dbg(adapter->dev, "CRQ send: add_buffer_resp\n"); in ibmvmc_send_add_buffer_resp()
717 * ibmvmc_send_rem_buffer_resp - Remove Buffer Response
722 * @hmc_index: HMC Index field
731 * 0 - Success
740 dev_dbg(adapter->dev, "CRQ send: rem_buffer_resp\n"); in ibmvmc_send_rem_buffer_resp()
758 * ibmvmc_send_msg - Signal Message
774 * 0 - Success
775 * Non-zero - Failure
785 dev_dbg(adapter->dev, "CRQ send: rdma to HV\n"); in ibmvmc_send_msg()
787 adapter->liobn, in ibmvmc_send_msg()
788 buffer->dma_addr_local, in ibmvmc_send_msg()
789 adapter->riobn, in ibmvmc_send_msg()
790 buffer->dma_addr_remote); in ibmvmc_send_msg()
792 dev_err(adapter->dev, "Error in send_msg, h_copy_rdma rc 0x%x\n", in ibmvmc_send_msg()
801 crq_msg.hmc_session = hmc->session; in ibmvmc_send_msg()
802 crq_msg.hmc_index = hmc->index; in ibmvmc_send_msg()
803 crq_msg.var2.buffer_id = cpu_to_be16(buffer->id); in ibmvmc_send_msg()
805 dev_dbg(adapter->dev, "CRQ send: msg to HV 0x%llx 0x%llx\n", in ibmvmc_send_msg()
808 buffer->owner = VMC_BUF_OWNER_HV; in ibmvmc_send_msg()
816 * ibmvmc_open - Open Session
822 * 0 - Success
823 * Non-zero - Failure
835 return -ENOMEM; in ibmvmc_open()
837 session->file = file; in ibmvmc_open()
838 file->private_data = session; in ibmvmc_open()
844 * ibmvmc_close - Close Session
850 * 0 - Success
851 * Non-zero - Failure
863 session = file->private_data; in ibmvmc_close()
865 return -EIO; in ibmvmc_close()
867 hmc = session->hmc; in ibmvmc_close()
869 if (!hmc->adapter) in ibmvmc_close()
870 return -EIO; in ibmvmc_close()
873 dev_warn(hmc->adapter->dev, "close: state_failed\n"); in ibmvmc_close()
874 return -EIO; in ibmvmc_close()
877 spin_lock_irqsave(&hmc->lock, flags); in ibmvmc_close()
878 if (hmc->state >= ibmhmc_state_opening) { in ibmvmc_close()
881 dev_warn(hmc->adapter->dev, "close: send_close failed.\n"); in ibmvmc_close()
883 spin_unlock_irqrestore(&hmc->lock, flags); in ibmvmc_close()
892 * ibmvmc_read - Read
900 * 0 - Success
901 * Non-zero - Failure
925 return -EINVAL; in ibmvmc_read()
928 session = file->private_data; in ibmvmc_read()
931 return -EIO; in ibmvmc_read()
934 hmc = session->hmc; in ibmvmc_read()
937 return -EIO; in ibmvmc_read()
940 adapter = hmc->adapter; in ibmvmc_read()
943 return -EIO; in ibmvmc_read()
949 spin_lock_irqsave(&hmc->lock, flags); in ibmvmc_read()
950 if (hmc->queue_tail != hmc->queue_head) in ibmvmc_read()
954 spin_unlock_irqrestore(&hmc->lock, flags); in ibmvmc_read()
956 if (!session->valid) { in ibmvmc_read()
957 retval = -EBADFD; in ibmvmc_read()
960 if (file->f_flags & O_NONBLOCK) { in ibmvmc_read()
961 retval = -EAGAIN; in ibmvmc_read()
968 retval = -ERESTARTSYS; in ibmvmc_read()
973 buffer = &(hmc->buffer[hmc->queue_outbound_msgs[hmc->queue_tail]]); in ibmvmc_read()
974 hmc->queue_tail++; in ibmvmc_read()
975 if (hmc->queue_tail == ibmvmc_max_buf_pool_size) in ibmvmc_read()
976 hmc->queue_tail = 0; in ibmvmc_read()
977 spin_unlock_irqrestore(&hmc->lock, flags); in ibmvmc_read()
979 nbytes = min_t(size_t, nbytes, buffer->msg_len); in ibmvmc_read()
980 n = copy_to_user((void *)buf, buffer->real_addr_local, nbytes); in ibmvmc_read()
981 dev_dbg(adapter->dev, "read: copy to user nbytes = 0x%lx.\n", nbytes); in ibmvmc_read()
986 dev_warn(adapter->dev, "read: copy to user failed.\n"); in ibmvmc_read()
987 retval = -EFAULT; in ibmvmc_read()
992 dev_dbg(adapter->dev, "read: out %ld\n", retval); in ibmvmc_read()
997 * ibmvmc_poll - Poll
1011 session = file->private_data; in ibmvmc_poll()
1015 hmc = session->hmc; in ibmvmc_poll()
1021 if (hmc->queue_head != hmc->queue_tail) in ibmvmc_poll()
1028 * ibmvmc_write - Write
1036 * 0 - Success
1037 * Non-zero - Failure
1054 session = file->private_data; in ibmvmc_write()
1056 return -EIO; in ibmvmc_write()
1058 hmc = session->hmc; in ibmvmc_write()
1060 return -EIO; in ibmvmc_write()
1062 spin_lock_irqsave(&hmc->lock, flags); in ibmvmc_write()
1063 if (hmc->state == ibmhmc_state_free) { in ibmvmc_write()
1065 ret = -EIO; in ibmvmc_write()
1069 adapter = hmc->adapter; in ibmvmc_write()
1071 ret = -EIO; in ibmvmc_write()
1076 dev_warn(adapter->dev, "invalid buffer size 0x%lx\n", in ibmvmc_write()
1078 ret = -EIO; in ibmvmc_write()
1082 /* Waiting for the open resp message to the ioctl(1) - retry */ in ibmvmc_write()
1083 if (hmc->state == ibmhmc_state_opening) { in ibmvmc_write()
1084 ret = -EBUSY; in ibmvmc_write()
1091 if (hmc->state != ibmhmc_state_ready) { in ibmvmc_write()
1092 ret = -EIO; in ibmvmc_write()
1096 vmc_buffer = ibmvmc_get_valid_hmc_buffer(hmc->index); in ibmvmc_write()
1102 ret = -EBUSY; in ibmvmc_write()
1105 if (!vmc_buffer->real_addr_local) { in ibmvmc_write()
1106 dev_err(adapter->dev, "no buffer storage assigned\n"); in ibmvmc_write()
1107 ret = -EIO; in ibmvmc_write()
1110 buf = vmc_buffer->real_addr_local; in ibmvmc_write()
1113 bytes = min_t(size_t, c, vmc_buffer->size); in ibmvmc_write()
1115 bytes -= copy_from_user(buf, p, bytes); in ibmvmc_write()
1117 ret = -EFAULT; in ibmvmc_write()
1120 c -= bytes; in ibmvmc_write()
1130 dev_dbg(adapter->dev, "write: file = 0x%lx, count = 0x%lx\n", in ibmvmc_write()
1134 ret = p - buffer; in ibmvmc_write()
1136 spin_unlock_irqrestore(&hmc->lock, flags); in ibmvmc_write()
1141 * ibmvmc_setup_hmc - Setup the HMC
1146 * 0 - Success
1147 * Non-zero - Failure
1152 unsigned int valid, free, index; in ibmvmc_setup_hmc() local
1156 return -EIO; in ibmvmc_setup_hmc()
1161 return -EAGAIN; in ibmvmc_setup_hmc()
1167 for (index = 0; index <= ibmvmc.max_hmc_index; index++) { in ibmvmc_setup_hmc()
1169 ibmvmc_count_hmc_buffers(index, &valid, &free); in ibmvmc_setup_hmc()
1171 pr_warn("ibmvmc: buffers not ready for index %d\n", in ibmvmc_setup_hmc()
1172 index); in ibmvmc_setup_hmc()
1173 return -ENOBUFS; in ibmvmc_setup_hmc()
1181 return -EBUSY; in ibmvmc_setup_hmc()
1184 hmc->session = hmc->session + 1; in ibmvmc_setup_hmc()
1185 if (hmc->session == 0xff) in ibmvmc_setup_hmc()
1186 hmc->session = 1; in ibmvmc_setup_hmc()
1188 session->hmc = hmc; in ibmvmc_setup_hmc()
1189 hmc->adapter = &ibmvmc_adapter; in ibmvmc_setup_hmc()
1190 hmc->file_session = session; in ibmvmc_setup_hmc()
1191 session->valid = 1; in ibmvmc_setup_hmc()
1197 * ibmvmc_ioctl_sethmcid - IOCTL Set HMC ID
1205 * 0 - Success
1206 * Non-zero - Failure
1219 hmc = session->hmc; in ibmvmc_ioctl_sethmcid()
1225 hmc = session->hmc; in ibmvmc_ioctl_sethmcid()
1228 return -EIO; in ibmvmc_ioctl_sethmcid()
1232 if (hmc->state != ibmhmc_state_initial) { in ibmvmc_ioctl_sethmcid()
1234 hmc->state); in ibmvmc_ioctl_sethmcid()
1235 return -EIO; in ibmvmc_ioctl_sethmcid()
1238 bytes = copy_from_user(hmc->hmc_id, new_hmc_id, HMC_ID_LEN); in ibmvmc_ioctl_sethmcid()
1240 return -EFAULT; in ibmvmc_ioctl_sethmcid()
1243 spin_lock_irqsave(&hmc->lock, flags); in ibmvmc_ioctl_sethmcid()
1244 buffer = ibmvmc_get_valid_hmc_buffer(hmc->index); in ibmvmc_ioctl_sethmcid()
1245 spin_unlock_irqrestore(&hmc->lock, flags); in ibmvmc_ioctl_sethmcid()
1247 if (!buffer || !buffer->real_addr_local) { in ibmvmc_ioctl_sethmcid()
1249 return -EIO; in ibmvmc_ioctl_sethmcid()
1252 strscpy(print_buffer, hmc->hmc_id, sizeof(print_buffer)); in ibmvmc_ioctl_sethmcid()
1255 memcpy(buffer->real_addr_local, hmc->hmc_id, HMC_ID_LEN); in ibmvmc_ioctl_sethmcid()
1263 * ibmvmc_ioctl_query - IOCTL Query
1269 * 0 - Success
1270 * Non-zero - Failure
1286 return -EFAULT; in ibmvmc_ioctl_query()
1292 * ibmvmc_ioctl_requestvmc - IOCTL Request VMC
1295 * @ret_vmc_index: VMC Index
1298 * 0 - Success
1299 * Non-zero - Failure
1317 return -EPERM; in ibmvmc_ioctl_requestvmc()
1320 return -EPERM; in ibmvmc_ioctl_requestvmc()
1323 return -EIO; in ibmvmc_ioctl_requestvmc()
1326 return -ENODEV; in ibmvmc_ioctl_requestvmc()
1329 return -EPERM; in ibmvmc_ioctl_requestvmc()
1332 return -EINVAL; in ibmvmc_ioctl_requestvmc()
1335 /* Success, set the vmc index in global struct */ in ibmvmc_ioctl_requestvmc()
1342 return -EFAULT; in ibmvmc_ioctl_requestvmc()
1348 * ibmvmc_ioctl - IOCTL
1355 * 0 - Success
1356 * Non-zero - Failure
1361 struct ibmvmc_file_session *session = file->private_data; in ibmvmc_ioctl()
1369 return -EIO; in ibmvmc_ioctl()
1384 return -EINVAL; in ibmvmc_ioctl()
1399 * ibmvmc_add_buffer - Add Buffer
1422 * 0 - Success
1423 * Non-zero - Failure
1436 return -1; in ibmvmc_add_buffer()
1438 hmc_session = crq->hmc_session; in ibmvmc_add_buffer()
1439 hmc_index = crq->hmc_index; in ibmvmc_add_buffer()
1440 buffer_id = be16_to_cpu(crq->var2.buffer_id); in ibmvmc_add_buffer()
1443 dev_err(adapter->dev, "add_buffer: invalid hmc_index = 0x%x\n", in ibmvmc_add_buffer()
1447 return -1; in ibmvmc_add_buffer()
1451 dev_err(adapter->dev, "add_buffer: invalid buffer_id = 0x%x\n", in ibmvmc_add_buffer()
1455 return -1; in ibmvmc_add_buffer()
1461 if (buffer->real_addr_local || buffer->dma_addr_local) { in ibmvmc_add_buffer()
1462 dev_warn(adapter->dev, "add_buffer: already allocated id = 0x%lx\n", in ibmvmc_add_buffer()
1467 return -1; in ibmvmc_add_buffer()
1470 buffer->real_addr_local = alloc_dma_buffer(to_vio_dev(adapter->dev), in ibmvmc_add_buffer()
1472 &buffer->dma_addr_local); in ibmvmc_add_buffer()
1474 if (!buffer->real_addr_local) { in ibmvmc_add_buffer()
1475 dev_err(adapter->dev, "add_buffer: alloc_dma_buffer failed.\n"); in ibmvmc_add_buffer()
1479 return -1; in ibmvmc_add_buffer()
1482 buffer->dma_addr_remote = be32_to_cpu(crq->var3.lioba); in ibmvmc_add_buffer()
1483 buffer->size = ibmvmc.max_mtu; in ibmvmc_add_buffer()
1484 buffer->owner = crq->var1.owner; in ibmvmc_add_buffer()
1485 buffer->free = 1; in ibmvmc_add_buffer()
1488 buffer->valid = 1; in ibmvmc_add_buffer()
1489 buffer->id = buffer_id; in ibmvmc_add_buffer()
1491 dev_dbg(adapter->dev, "add_buffer: successfully added a buffer:\n"); in ibmvmc_add_buffer()
1492 dev_dbg(adapter->dev, " index: %d, session: %d, buffer: 0x%x, owner: %d\n", in ibmvmc_add_buffer()
1493 hmc_index, hmc_session, buffer_id, buffer->owner); in ibmvmc_add_buffer()
1494 dev_dbg(adapter->dev, " local: 0x%x, remote: 0x%x\n", in ibmvmc_add_buffer()
1495 (u32)buffer->dma_addr_local, in ibmvmc_add_buffer()
1496 (u32)buffer->dma_addr_remote); in ibmvmc_add_buffer()
1506 * ibmvmc_rem_buffer - Remove Buffer
1534 * 0 - Success
1535 * Non-zero - Failure
1553 return -1; in ibmvmc_rem_buffer()
1555 hmc_session = crq->hmc_session; in ibmvmc_rem_buffer()
1556 hmc_index = crq->hmc_index; in ibmvmc_rem_buffer()
1559 dev_warn(adapter->dev, "rem_buffer: invalid hmc_index = 0x%x\n", in ibmvmc_rem_buffer()
1563 return -1; in ibmvmc_rem_buffer()
1569 dev_info(adapter->dev, "rem_buffer: no buffer to remove\n"); in ibmvmc_rem_buffer()
1574 return -1; in ibmvmc_rem_buffer()
1577 buffer_id = buffer->id; in ibmvmc_rem_buffer()
1579 if (buffer->valid) in ibmvmc_rem_buffer()
1580 free_dma_buffer(to_vio_dev(adapter->dev), in ibmvmc_rem_buffer()
1582 buffer->real_addr_local, in ibmvmc_rem_buffer()
1583 buffer->dma_addr_local); in ibmvmc_rem_buffer()
1588 dev_dbg(adapter->dev, "rem_buffer: removed buffer 0x%x.\n", buffer_id); in ibmvmc_rem_buffer()
1608 return -1; in ibmvmc_recv_msg()
1611 dev_dbg(adapter->dev, "Recv_msg: msg from HV 0x%016llx 0x%016llx\n", in ibmvmc_recv_msg()
1615 hmc_session = crq->hmc_session; in ibmvmc_recv_msg()
1616 hmc_index = crq->hmc_index; in ibmvmc_recv_msg()
1617 buffer_id = be16_to_cpu(crq->var2.buffer_id); in ibmvmc_recv_msg()
1618 msg_len = be32_to_cpu(crq->var3.msg_len); in ibmvmc_recv_msg()
1621 dev_err(adapter->dev, "Recv_msg: invalid hmc_index = 0x%x\n", in ibmvmc_recv_msg()
1625 return -1; in ibmvmc_recv_msg()
1629 dev_err(adapter->dev, "Recv_msg: invalid buffer_id = 0x%x\n", in ibmvmc_recv_msg()
1633 return -1; in ibmvmc_recv_msg()
1637 spin_lock_irqsave(&hmc->lock, flags); in ibmvmc_recv_msg()
1639 if (hmc->state == ibmhmc_state_free) { in ibmvmc_recv_msg()
1640 dev_err(adapter->dev, "Recv_msg: invalid hmc state = 0x%x\n", in ibmvmc_recv_msg()
1641 hmc->state); in ibmvmc_recv_msg()
1643 spin_unlock_irqrestore(&hmc->lock, flags); in ibmvmc_recv_msg()
1644 return -1; in ibmvmc_recv_msg()
1647 buffer = &hmc->buffer[buffer_id]; in ibmvmc_recv_msg()
1649 if (buffer->valid == 0 || buffer->owner == VMC_BUF_OWNER_ALPHA) { in ibmvmc_recv_msg()
1650 dev_err(adapter->dev, "Recv_msg: not valid, or not HV. 0x%x 0x%x\n", in ibmvmc_recv_msg()
1651 buffer->valid, buffer->owner); in ibmvmc_recv_msg()
1652 spin_unlock_irqrestore(&hmc->lock, flags); in ibmvmc_recv_msg()
1653 return -1; in ibmvmc_recv_msg()
1658 adapter->riobn, in ibmvmc_recv_msg()
1659 buffer->dma_addr_remote, in ibmvmc_recv_msg()
1660 adapter->liobn, in ibmvmc_recv_msg()
1661 buffer->dma_addr_local); in ibmvmc_recv_msg()
1663 …dev_dbg(adapter->dev, "Recv_msg: msg_len = 0x%x, buffer_id = 0x%x, queue_head = 0x%x, hmc_idx = 0x… in ibmvmc_recv_msg()
1665 (unsigned int)hmc->queue_head, (unsigned int)hmc_index); in ibmvmc_recv_msg()
1666 buffer->msg_len = msg_len; in ibmvmc_recv_msg()
1667 buffer->free = 0; in ibmvmc_recv_msg()
1668 buffer->owner = VMC_BUF_OWNER_ALPHA; in ibmvmc_recv_msg()
1671 dev_err(adapter->dev, "Failure in recv_msg: h_copy_rdma = 0x%x\n", in ibmvmc_recv_msg()
1673 spin_unlock_irqrestore(&hmc->lock, flags); in ibmvmc_recv_msg()
1674 return -1; in ibmvmc_recv_msg()
1678 hmc->queue_outbound_msgs[hmc->queue_head] = buffer_id; in ibmvmc_recv_msg()
1679 hmc->queue_head++; in ibmvmc_recv_msg()
1680 if (hmc->queue_head == ibmvmc_max_buf_pool_size) in ibmvmc_recv_msg()
1681 hmc->queue_head = 0; in ibmvmc_recv_msg()
1683 if (hmc->queue_head == hmc->queue_tail) in ibmvmc_recv_msg()
1684 dev_err(adapter->dev, "outbound buffer queue wrapped.\n"); in ibmvmc_recv_msg()
1686 spin_unlock_irqrestore(&hmc->lock, flags); in ibmvmc_recv_msg()
1694 * ibmvmc_process_capabilities - Process Capabilities
1705 if ((be16_to_cpu(crq->version) >> 8) != in ibmvmc_process_capabilities()
1707 dev_err(adapter->dev, "init failed, incompatible versions 0x%x 0x%x\n", in ibmvmc_process_capabilities()
1708 be16_to_cpu(crq->version), in ibmvmc_process_capabilities()
1714 ibmvmc.max_mtu = min_t(u32, ibmvmc_max_mtu, be32_to_cpu(crq->max_mtu)); in ibmvmc_process_capabilities()
1716 be16_to_cpu(crq->pool_size)); in ibmvmc_process_capabilities()
1717 ibmvmc.max_hmc_index = min_t(u8, ibmvmc_max_hmcs, crq->max_hmc) - 1; in ibmvmc_process_capabilities()
1720 dev_info(adapter->dev, "Capabilities: mtu=0x%x, pool_size=0x%x, max_hmc=0x%x\n", in ibmvmc_process_capabilities()
1726 * ibmvmc_validate_hmc_session - Validate HMC Session
1732 * 0 - Success
1733 * Non-zero - Failure
1740 hmc_index = crq->hmc_index; in ibmvmc_validate_hmc_session()
1742 if (crq->hmc_session == 0) in ibmvmc_validate_hmc_session()
1746 return -1; in ibmvmc_validate_hmc_session()
1748 if (hmcs[hmc_index].session != crq->hmc_session) { in ibmvmc_validate_hmc_session()
1749 dev_warn(adapter->dev, "Drop, bad session: expected 0x%x, recv 0x%x\n", in ibmvmc_validate_hmc_session()
1750 hmcs[hmc_index].session, crq->hmc_session); in ibmvmc_validate_hmc_session()
1751 return -1; in ibmvmc_validate_hmc_session()
1758 * ibmvmc_reset - Reset
1772 dev_info(adapter->dev, "*** Reset to initial state.\n"); in ibmvmc_reset()
1783 /* The partner did not close their CRQ - instead, we're in ibmvmc_reset()
1793 dev_dbg(adapter->dev, "Device reset scheduled"); in ibmvmc_reset()
1794 wake_up_interruptible(&adapter->reset_wait_queue); in ibmvmc_reset()
1800 * ibmvmc_reset_task - Reset Task
1812 set_user_nice(current, -20); in ibmvmc_reset_task()
1815 wait_event_interruptible(adapter->reset_wait_queue, in ibmvmc_reset_task()
1822 dev_dbg(adapter->dev, "CRQ resetting in process context"); in ibmvmc_reset_task()
1823 tasklet_disable(&adapter->work_task); in ibmvmc_reset_task()
1828 dev_err(adapter->dev, "Error initializing CRQ. rc = 0x%x\n", in ibmvmc_reset_task()
1836 dev_warn(adapter->dev, "Failed to send initialize CRQ message\n"); in ibmvmc_reset_task()
1839 vio_enable_interrupts(to_vio_dev(adapter->dev)); in ibmvmc_reset_task()
1840 tasklet_enable(&adapter->work_task); in ibmvmc_reset_task()
1847 * ibmvmc_process_open_resp - Process Open Response
1862 hmc_index = crq->hmc_index; in ibmvmc_process_open_resp()
1864 /* Why would PHYP give an index > max negotiated? */ in ibmvmc_process_open_resp()
1869 if (crq->status) { in ibmvmc_process_open_resp()
1870 dev_warn(adapter->dev, "open_resp: failed - status 0x%x\n", in ibmvmc_process_open_resp()
1871 crq->status); in ibmvmc_process_open_resp()
1877 buffer_id = be16_to_cpu(crq->var2.buffer_id); in ibmvmc_process_open_resp()
1879 dev_err(adapter->dev, "open_resp: invalid buffer_id = 0x%x\n", in ibmvmc_process_open_resp()
1886 dev_dbg(adapter->dev, "open_resp: set hmc state = ready\n"); in ibmvmc_process_open_resp()
1889 dev_warn(adapter->dev, "open_resp: invalid hmc state (0x%x)\n", in ibmvmc_process_open_resp()
1895 * ibmvmc_process_close_resp - Process Close Response
1911 hmc_index = crq->hmc_index; in ibmvmc_process_close_resp()
1917 if (crq->status) { in ibmvmc_process_close_resp()
1918 dev_warn(adapter->dev, "close_resp: failed - status 0x%x\n", in ibmvmc_process_close_resp()
1919 crq->status); in ibmvmc_process_close_resp()
1928 * ibmvmc_crq_process - Process CRQ
1939 switch (crq->type) { in ibmvmc_crq_process()
1941 dev_dbg(adapter->dev, "CRQ recv: capabilities resp (0x%x)\n", in ibmvmc_crq_process()
1942 crq->type); in ibmvmc_crq_process()
1946 dev_warn(adapter->dev, "caps msg invalid in state 0x%x\n", in ibmvmc_crq_process()
1950 dev_dbg(adapter->dev, "CRQ recv: open resp (0x%x)\n", in ibmvmc_crq_process()
1951 crq->type); in ibmvmc_crq_process()
1956 dev_dbg(adapter->dev, "CRQ recv: add buf (0x%x)\n", in ibmvmc_crq_process()
1957 crq->type); in ibmvmc_crq_process()
1962 dev_dbg(adapter->dev, "CRQ recv: rem buf (0x%x)\n", in ibmvmc_crq_process()
1963 crq->type); in ibmvmc_crq_process()
1968 dev_dbg(adapter->dev, "CRQ recv: signal msg (0x%x)\n", in ibmvmc_crq_process()
1969 crq->type); in ibmvmc_crq_process()
1974 dev_dbg(adapter->dev, "CRQ recv: close resp (0x%x)\n", in ibmvmc_crq_process()
1975 crq->type); in ibmvmc_crq_process()
1984 dev_warn(adapter->dev, "CRQ recv: unexpected msg (0x%x)\n", in ibmvmc_crq_process()
1985 crq->type); in ibmvmc_crq_process()
1988 dev_warn(adapter->dev, "CRQ recv: unknown msg (0x%x)\n", in ibmvmc_crq_process()
1989 crq->type); in ibmvmc_crq_process()
1995 * ibmvmc_handle_crq_init - Handle CRQ Init
2007 switch (crq->type) { in ibmvmc_handle_crq_init()
2009 dev_dbg(adapter->dev, "CRQ recv: CRQ init msg - state 0x%x\n", in ibmvmc_handle_crq_init()
2017 dev_err(adapter->dev, " Unable to send init rsp\n"); in ibmvmc_handle_crq_init()
2019 dev_err(adapter->dev, "Invalid state 0x%x mtu = 0x%x\n", in ibmvmc_handle_crq_init()
2025 dev_dbg(adapter->dev, "CRQ recv: initialization resp msg - state 0x%x\n", in ibmvmc_handle_crq_init()
2031 dev_warn(adapter->dev, "Unknown crq message type 0x%lx\n", in ibmvmc_handle_crq_init()
2032 (unsigned long)crq->type); in ibmvmc_handle_crq_init()
2037 * ibmvmc_handle_crq - Handle CRQ
2049 switch (crq->valid) { in ibmvmc_handle_crq()
2054 dev_warn(adapter->dev, "CRQ recv: virtual adapter failed - resetting.\n"); in ibmvmc_handle_crq()
2061 dev_warn(adapter->dev, "CRQ recv: unknown msg 0x%02x.\n", in ibmvmc_handle_crq()
2062 crq->valid); in ibmvmc_handle_crq()
2071 struct vio_dev *vdev = to_vio_dev(adapter->dev); in ibmvmc_task()
2077 while ((crq = crq_queue_next_crq(&adapter->queue)) != NULL) { in ibmvmc_task()
2079 crq->valid = 0x00; in ibmvmc_task()
2081 * Interrupts will be re-enabled by the reset task. in ibmvmc_task()
2088 crq = crq_queue_next_crq(&adapter->queue); in ibmvmc_task()
2092 crq->valid = 0x00; in ibmvmc_task()
2094 * Interrupts will be re-enabled by the reset task. in ibmvmc_task()
2105 * ibmvmc_init_crq_queue - Init CRQ Queue
2110 * 0 - Success
2111 * Non-zero - Failure
2115 struct vio_dev *vdev = to_vio_dev(adapter->dev); in ibmvmc_init_crq_queue()
2116 struct crq_queue *queue = &adapter->queue; in ibmvmc_init_crq_queue()
2120 queue->msgs = (struct ibmvmc_crq_msg *)get_zeroed_page(GFP_KERNEL); in ibmvmc_init_crq_queue()
2122 if (!queue->msgs) in ibmvmc_init_crq_queue()
2125 queue->size = PAGE_SIZE / sizeof(*queue->msgs); in ibmvmc_init_crq_queue()
2127 queue->msg_token = dma_map_single(adapter->dev, queue->msgs, in ibmvmc_init_crq_queue()
2128 queue->size * sizeof(*queue->msgs), in ibmvmc_init_crq_queue()
2131 if (dma_mapping_error(adapter->dev, queue->msg_token)) in ibmvmc_init_crq_queue()
2135 vdev->unit_address, in ibmvmc_init_crq_queue()
2136 queue->msg_token, PAGE_SIZE); in ibmvmc_init_crq_queue()
2143 dev_warn(adapter->dev, "Partner adapter not ready\n"); in ibmvmc_init_crq_queue()
2146 dev_err(adapter->dev, "Error %d opening adapter\n", rc); in ibmvmc_init_crq_queue()
2150 queue->cur = 0; in ibmvmc_init_crq_queue()
2151 spin_lock_init(&queue->lock); in ibmvmc_init_crq_queue()
2153 tasklet_init(&adapter->work_task, ibmvmc_task, (unsigned long)adapter); in ibmvmc_init_crq_queue()
2155 if (request_irq(vdev->irq, in ibmvmc_init_crq_queue()
2158 dev_err(adapter->dev, "couldn't register irq 0x%x\n", in ibmvmc_init_crq_queue()
2159 vdev->irq); in ibmvmc_init_crq_queue()
2165 dev_err(adapter->dev, "Error %d enabling interrupts!!!\n", rc); in ibmvmc_init_crq_queue()
2175 tasklet_kill(&adapter->work_task); in ibmvmc_init_crq_queue()
2176 h_free_crq(vdev->unit_address); in ibmvmc_init_crq_queue()
2178 dma_unmap_single(adapter->dev, in ibmvmc_init_crq_queue()
2179 queue->msg_token, in ibmvmc_init_crq_queue()
2180 queue->size * sizeof(*queue->msgs), DMA_BIDIRECTIONAL); in ibmvmc_init_crq_queue()
2182 free_page((unsigned long)queue->msgs); in ibmvmc_init_crq_queue()
2184 return -ENOMEM; in ibmvmc_init_crq_queue()
2199 (const __be32 *)vio_get_attribute(vdev, "ibm,my-dma-window", in read_dma_window()
2202 dev_warn(adapter->dev, "Couldn't find ibm,my-dma-window property\n"); in read_dma_window()
2203 return -1; in read_dma_window()
2206 adapter->liobn = be32_to_cpu(*dma_window); in read_dma_window()
2209 prop = (const __be32 *)vio_get_attribute(vdev, "ibm,#dma-address-cells", in read_dma_window()
2212 dev_warn(adapter->dev, "Couldn't find ibm,#dma-address-cells property\n"); in read_dma_window()
2218 prop = (const __be32 *)vio_get_attribute(vdev, "ibm,#dma-size-cells", in read_dma_window()
2221 dev_warn(adapter->dev, "Couldn't find ibm,#dma-size-cells property\n"); in read_dma_window()
2228 adapter->riobn = be32_to_cpu(*dma_window); in read_dma_window()
2238 dev_set_drvdata(&vdev->dev, NULL); in ibmvmc_probe()
2240 adapter->dev = &vdev->dev; in ibmvmc_probe()
2242 dev_info(adapter->dev, "Probe for UA 0x%x\n", vdev->unit_address); in ibmvmc_probe()
2247 return -1; in ibmvmc_probe()
2250 dev_dbg(adapter->dev, "Probe: liobn 0x%x, riobn 0x%x\n", in ibmvmc_probe()
2251 adapter->liobn, adapter->riobn); in ibmvmc_probe()
2253 init_waitqueue_head(&adapter->reset_wait_queue); in ibmvmc_probe()
2254 adapter->reset_task = kthread_run(ibmvmc_reset_task, adapter, "ibmvmc"); in ibmvmc_probe()
2255 if (IS_ERR(adapter->reset_task)) { in ibmvmc_probe()
2256 dev_err(adapter->dev, "Failed to start reset thread\n"); in ibmvmc_probe()
2258 rc = PTR_ERR(adapter->reset_task); in ibmvmc_probe()
2259 adapter->reset_task = NULL; in ibmvmc_probe()
2265 dev_err(adapter->dev, "Error initializing CRQ. rc = 0x%x\n", in ibmvmc_probe()
2279 dev_warn(adapter->dev, "Failed to send initialize CRQ message\n"); in ibmvmc_probe()
2281 dev_set_drvdata(&vdev->dev, adapter); in ibmvmc_probe()
2286 kthread_stop(adapter->reset_task); in ibmvmc_probe()
2287 adapter->reset_task = NULL; in ibmvmc_probe()
2288 return -EPERM; in ibmvmc_probe()
2293 struct crq_server_adapter *adapter = dev_get_drvdata(&vdev->dev); in ibmvmc_remove()
2295 dev_info(adapter->dev, "Entering remove for UA 0x%x\n", in ibmvmc_remove()
2296 vdev->unit_address); in ibmvmc_remove()
2381 ibmvmc.max_hmc_index = ibmvmc_max_hmcs - 1; in ibmvmc_module_init()