/* * Evict a registration. This means delete it from the unused list, * add it to the free list, and deregister the associated memory. * Return 1 if success, 0 if nothing to evict. */ int dreg_evict() { void *buf; dreg_entry *d; aint_t bufint; d = dreg_unused_tail; if (d == NULL) { /* no entries left on unused list, return failure */ return 0; } DREG_REMOVE_FROM_UNUSED_LIST(d); assert(d->refcount == 0); bufint = d->pagenum << DREG_PAGEBITS; buf = (void *) bufint; d->is_valid = 0; if (deregister_memory(d->memhandle)) { error_abort_all(IBV_RETURN_ERR, "Deregister fails\n"); } dreg_remove (d); DREG_ADD_TO_FREE_LIST(d); dreg_stat_evicted++; return 1; }
/* * Decrement reference count on a dreg entry. If ref count goes to * zero, don't free it, but put it on the unused list so we * can evict it if necessary. Put on head of unused list. */ void dreg_decr_refcount(dreg_entry * d) { void *buf; aint_t bufint; assert(d->refcount > 0); d->refcount--; if (d->refcount == 0) { if(viadev_use_dreg_cache) { DREG_ADD_TO_UNUSED_LIST(d); } else { bufint = d->pagenum << DREG_PAGEBITS; buf = (void *) bufint; d->is_valid = 0; if (deregister_memory(d->memhandle)) { error_abort_all(IBV_RETURN_ERR, "deregister fails\n"); } d->memhandle = NULL; dreg_remove (d); DREG_ADD_TO_FREE_LIST(d); } } T_PRINT("decr_refcount: entry " AINT_FORMAT " refcount" AINT_FORMAT " memhandle" AINT_FORMAT, (aint_t) d, (aint_t) d->refcount, (aint_t) d->memhandle); }
static long acdb_ioctl(struct file *f, unsigned int cmd, unsigned long arg) { int32_t result = 0; int32_t size; int32_t map_fd; uint32_t topology; uint32_t data[MAX_IOCTL_DATA]; struct msm_spk_prot_status prot_status; struct msm_spk_prot_status acdb_spk_status; pr_debug("%s\n", __func__); mutex_lock(&acdb_data.acdb_mutex); switch (cmd) { case AUDIO_REGISTER_PMEM: pr_debug("AUDIO_REGISTER_PMEM\n"); result = deregister_memory(); if (result < 0) pr_err("%s: deregister_memory failed returned %d!\n", __func__, result); if (copy_from_user(&map_fd, (void *)arg, sizeof(map_fd))) { pr_err("%s: fail to copy memory handle!\n", __func__); result = -EFAULT; } else { acdb_data.map_handle = map_fd; result = register_memory(); } goto done; case AUDIO_DEREGISTER_PMEM: pr_debug("AUDIO_DEREGISTER_PMEM\n"); result = deregister_memory(); goto done; case AUDIO_SET_VOICE_RX_TOPOLOGY: if (copy_from_user(&topology, (void *)arg, sizeof(topology))) { pr_err("%s: fail to copy topology!\n", __func__); result = -EFAULT; } store_voice_rx_topology(topology); goto done; case AUDIO_SET_VOICE_TX_TOPOLOGY: if (copy_from_user(&topology, (void *)arg, sizeof(topology))) { pr_err("%s: fail to copy topology!\n", __func__); result = -EFAULT; } store_voice_tx_topology(topology); goto done; case AUDIO_SET_ADM_RX_TOPOLOGY: if (copy_from_user(&topology, (void *)arg, sizeof(topology))) { pr_err("%s: fail to copy topology!\n", __func__); result = -EFAULT; } store_adm_rx_topology(topology); goto done; case AUDIO_SET_ADM_TX_TOPOLOGY: if (copy_from_user(&topology, (void *)arg, sizeof(topology))) { pr_err("%s: fail to copy topology!\n", __func__); result = -EFAULT; } store_adm_tx_topology(topology); goto done; case AUDIO_SET_ASM_TOPOLOGY: if (copy_from_user(&topology, (void *)arg, sizeof(topology))) { pr_err("%s: fail to copy topology!\n", __func__); result = -EFAULT; } store_asm_topology(topology); goto done; case AUDIO_SET_SPEAKER_PROT: if (copy_from_user(&acdb_data.spk_prot_cfg, (void *)arg, sizeof(acdb_data.spk_prot_cfg))) { pr_err("%s fail to copy spk_prot_cfg\n", __func__); result = -EFAULT; } goto done; case AUDIO_GET_SPEAKER_PROT: /*Indicates calibration was succesfull*/ if (acdb_data.spk_prot_cfg.mode == MSM_SPKR_PROT_CALIBRATED) { prot_status.r0 = acdb_data.spk_prot_cfg.r0; prot_status.status = 0; } else if (acdb_data.spk_prot_cfg.mode == MSM_SPKR_PROT_CALIBRATION_IN_PROGRESS) { /*Call AFE to query the status*/ acdb_spk_status.status = -EINVAL; acdb_spk_status.r0 = -1; get_spk_protection_status(&acdb_spk_status); prot_status.r0 = acdb_spk_status.r0; prot_status.status = acdb_spk_status.status; if (!acdb_spk_status.status) { acdb_data.spk_prot_cfg.mode = MSM_SPKR_PROT_CALIBRATED; acdb_data.spk_prot_cfg.r0 = prot_status.r0; } } else { /*Indicates calibration data is invalid*/ prot_status.status = -EINVAL; prot_status.r0 = -1; } if (copy_to_user((void *)arg, &prot_status, sizeof(prot_status))) { pr_err("%s: Failed to update prot_status\n", __func__); } goto done; case AUDIO_REGISTER_VOCPROC_VOL_TABLE: result = register_vocvol_table(); goto done; case AUDIO_DEREGISTER_VOCPROC_VOL_TABLE: result = deregister_vocvol_table(); goto done; case AUDIO_SET_HW_DELAY_RX: result = store_hw_delay(RX_CAL, (void *)arg); goto done; case AUDIO_SET_HW_DELAY_TX: result = store_hw_delay(TX_CAL, (void *)arg); goto done; case AUDIO_SET_META_INFO: result = store_meta_info((void *)arg); goto done; } if (copy_from_user(&size, (void *) arg, sizeof(size))) { result = -EFAULT; goto done; } if ((size <= 0) || (size > sizeof(data))) { pr_err("%s: Invalid size sent to driver: %d\n", __func__, size); result = -EFAULT; goto done; } switch (cmd) { case AUDIO_SET_VOCPROC_COL_CAL: result = store_voice_col_data(VOCPROC_CAL, size, (uint32_t *)arg); goto done; case AUDIO_SET_VOCSTRM_COL_CAL: result = store_voice_col_data(VOCSTRM_CAL, size, (uint32_t *)arg); goto done; case AUDIO_SET_VOCVOL_COL_CAL: result = store_voice_col_data(VOCVOL_CAL, size, (uint32_t *)arg); goto done; } if (copy_from_user(data, (void *)(arg + sizeof(size)), size)) { pr_err("%s: fail to copy table size %d\n", __func__, size); result = -EFAULT; goto done; } if (data == NULL) { pr_err("%s: NULL pointer sent to driver!\n", __func__); result = -EFAULT; goto done; } if (size > sizeof(struct cal_block)) pr_err("%s: More cal data for ioctl 0x%x then expected, size received: %d\n", __func__, cmd, size); switch (cmd) { case AUDIO_SET_AUDPROC_TX_CAL: result = store_audproc_cal(TX_CAL, (struct cal_block *)data); goto done; case AUDIO_SET_AUDPROC_RX_CAL: result = store_audproc_cal(RX_CAL, (struct cal_block *)data); goto done; case AUDIO_SET_AUDPROC_TX_STREAM_CAL: result = store_audstrm_cal(TX_CAL, (struct cal_block *)data); goto done; case AUDIO_SET_AUDPROC_RX_STREAM_CAL: result = store_audstrm_cal(RX_CAL, (struct cal_block *)data); goto done; case AUDIO_SET_AUDPROC_TX_VOL_CAL: result = store_audvol_cal(TX_CAL, (struct cal_block *)data); goto done; case AUDIO_SET_AUDPROC_RX_VOL_CAL: result = store_audvol_cal(RX_CAL, (struct cal_block *)data); goto done; case AUDIO_SET_AFE_TX_CAL: result = store_afe_cal(TX_CAL, (struct cal_block *)data); goto done; case AUDIO_SET_AFE_RX_CAL: result = store_afe_cal(RX_CAL, (struct cal_block *)data); goto done; case AUDIO_SET_VOCPROC_CAL: result = store_vocproc_cal((struct cal_block *)data); goto done; case AUDIO_SET_VOCPROC_STREAM_CAL: result = store_vocstrm_cal((struct cal_block *)data); goto done; case AUDIO_SET_VOCPROC_VOL_CAL: result = store_vocvol_cal((struct cal_block *)data); goto done; case AUDIO_SET_VOCPROC_DEV_CFG_CAL: result = store_vocproc_dev_cfg_cal((struct cal_block *)data); goto done; case AUDIO_SET_SIDETONE_CAL: store_sidetone_cal((struct sidetone_cal *)data); goto done; case AUDIO_SET_ANC_CAL: result = store_anc_cal((struct cal_block *)data); goto done; case AUDIO_SET_LSM_CAL: result = store_lsm_cal((struct cal_block *)data); goto done; case AUDIO_SET_ADM_CUSTOM_TOPOLOGY: result = store_adm_custom_topology((struct cal_block *)data); goto done; case AUDIO_SET_ASM_CUSTOM_TOPOLOGY: result = store_asm_custom_topology((struct cal_block *)data); goto done; case AUDIO_SET_AANC_CAL: result = store_aanc_cal((struct cal_block *)data); goto done; case AUDIO_LISTEN_SET_ULP_LSM_CAL: result = store_ulp_lsm_cal((struct cal_block *) data); goto done; case AUDIO_LISTEN_SET_ULP_AFE_CAL: result = store_ulp_afe_cal((struct cal_block *) data); goto done; default: pr_err("ACDB=> ACDB ioctl not found!\n"); result = -EFAULT; goto done; } done: mutex_unlock(&acdb_data.acdb_mutex); return result; }
static long acdb_ioctl(struct file *f, unsigned int cmd, unsigned long arg) { int32_t result = 0; int32_t size; int32_t map_fd; uint32_t topology; struct cal_block data[MAX_NETWORKS]; pr_debug("%s\n", __func__); switch (cmd) { case AUDIO_REGISTER_PMEM: pr_debug("AUDIO_REGISTER_PMEM\n"); if (atomic_read(&acdb_data.mem_len)) { deregister_memory(); pr_debug("Remove the existing memory\n"); } if (copy_from_user(&map_fd, (void *)arg, sizeof(map_fd))) { pr_err("%s: fail to copy memory handle!\n", __func__); result = -EFAULT; } else { atomic_set(&acdb_data.map_handle, map_fd); result = register_memory(); } goto done; case AUDIO_DEREGISTER_PMEM: pr_debug("AUDIO_DEREGISTER_PMEM\n"); deregister_memory(); goto done; case AUDIO_SET_VOICE_RX_TOPOLOGY: if (copy_from_user(&topology, (void *)arg, sizeof(topology))) { pr_err("%s: fail to copy topology!\n", __func__); result = -EFAULT; } store_voice_rx_topology(topology); goto done; case AUDIO_SET_VOICE_TX_TOPOLOGY: if (copy_from_user(&topology, (void *)arg, sizeof(topology))) { pr_err("%s: fail to copy topology!\n", __func__); result = -EFAULT; } store_voice_tx_topology(topology); goto done; case AUDIO_SET_ADM_RX_TOPOLOGY: if (copy_from_user(&topology, (void *)arg, sizeof(topology))) { pr_err("%s: fail to copy topology!\n", __func__); result = -EFAULT; } store_adm_rx_topology(topology); goto done; case AUDIO_SET_ADM_TX_TOPOLOGY: if (copy_from_user(&topology, (void *)arg, sizeof(topology))) { pr_err("%s: fail to copy topology!\n", __func__); result = -EFAULT; } store_adm_tx_topology(topology); goto done; case AUDIO_SET_ASM_TOPOLOGY: if (copy_from_user(&topology, (void *)arg, sizeof(topology))) { pr_err("%s: fail to copy topology!\n", __func__); result = -EFAULT; } store_asm_topology(topology); goto done; } if (copy_from_user(&size, (void *) arg, sizeof(size))) { result = -EFAULT; goto done; } if (size <= 0) { pr_err("%s: Invalid size sent to driver: %d\n", __func__, size); result = -EFAULT; goto done; } if (copy_from_user(data, (void *)(arg + sizeof(size)), size)) { pr_err("%s: fail to copy table size %d\n", __func__, size); result = -EFAULT; goto done; } if (data == NULL) { pr_err("%s: NULL pointer sent to driver!\n", __func__); result = -EFAULT; goto done; } switch (cmd) { case AUDIO_SET_AUDPROC_TX_CAL: if (size > sizeof(struct cal_block)) pr_err("%s: More Audproc Cal then expected, " "size received: %d\n", __func__, size); store_audproc_cal(TX_CAL, data); break; case AUDIO_SET_AUDPROC_RX_CAL: if (size > sizeof(struct cal_block)) pr_err("%s: More Audproc Cal then expected, " "size received: %d\n", __func__, size); store_audproc_cal(RX_CAL, data); break; case AUDIO_SET_AUDPROC_TX_STREAM_CAL: if (size > sizeof(struct cal_block)) pr_err("%s: More Audproc Cal then expected, " "size received: %d\n", __func__, size); store_audstrm_cal(TX_CAL, data); break; case AUDIO_SET_AUDPROC_RX_STREAM_CAL: if (size > sizeof(struct cal_block)) pr_err("%s: More Audproc Cal then expected, " "size received: %d\n", __func__, size); store_audstrm_cal(RX_CAL, data); break; case AUDIO_SET_AUDPROC_TX_VOL_CAL: if (size > sizeof(struct cal_block)) pr_err("%s: More Audproc Cal then expected, " "size received: %d\n", __func__, size); store_audvol_cal(TX_CAL, data); break; case AUDIO_SET_AUDPROC_RX_VOL_CAL: if (size > sizeof(struct cal_block)) pr_err("%s: More Audproc Cal then expected, " "size received: %d\n", __func__, size); store_audvol_cal(RX_CAL, data); break; case AUDIO_SET_AFE_TX_CAL: if (size > sizeof(struct cal_block)) pr_err("%s: More AFE Cal then expected, " "size received: %d\n", __func__, size); store_afe_cal(TX_CAL, data); break; case AUDIO_SET_AFE_RX_CAL: if (size > sizeof(struct cal_block)) pr_err("%s: More AFE Cal then expected, " "size received: %d\n", __func__, size); store_afe_cal(RX_CAL, data); break; case AUDIO_SET_VOCPROC_CAL: store_vocproc_cal(size / sizeof(struct cal_block), data); break; case AUDIO_SET_VOCPROC_STREAM_CAL: store_vocstrm_cal(size / sizeof(struct cal_block), data); break; case AUDIO_SET_VOCPROC_VOL_CAL: store_vocvol_cal(size / sizeof(struct cal_block), data); break; case AUDIO_SET_SIDETONE_CAL: if (size > sizeof(struct sidetone_cal)) pr_err("%s: More sidetone cal then expected, " "size received: %d\n", __func__, size); store_sidetone_cal((struct sidetone_cal *)data); break; case AUDIO_SET_ANC_CAL: store_anc_cal(data); break; default: pr_err("ACDB=> ACDB ioctl not found!\n"); } done: return result; }
int MPIDI_nem_ib_recv_addr_reply(MPIDI_VC_t * vc, void *vstart) { int hca_index; int ret; MPIDI_nem_ib_pkt_address_reply *pkt = vstart; DEBUG_PRINT("Received addr reply packet. reply data :%d\n", pkt->reply_data); if (pkt->reply_data == RDMA_FP_SENDBUFF_ALLOC_FAILED || pkt->reply_data == RDMA_FP_MAX_SEND_CONN_REACHED) { DEBUG_PRINT("RDMA FP setup failed. clean up recv buffers\n "); /* de-regster the recv buffers */ for (hca_index = 0; hca_index < ib_hca_num_hcas; hca_index++) { if (VC_FIELD(vc, connection)->rfp.RDMA_recv_buf_mr[hca_index]) { ret = deregister_memory(VC_FIELD(vc, connection)->rfp.RDMA_recv_buf_mr[hca_index]); if (ret) { MPIU_Error_printf("Failed to deregister mr (%d)\n", ret); } else { VC_FIELD(vc, connection)->rfp.RDMA_recv_buf_mr[hca_index] = NULL; } } } /* deallocate recv RDMA buffers */ if (VC_FIELD(vc, connection)->rfp.RDMA_recv_buf_DMA) { MPIU_Free(VC_FIELD(vc, connection)->rfp.RDMA_recv_buf_DMA); VC_FIELD(vc, connection)->rfp.RDMA_recv_buf_DMA = NULL; } /* deallocate vbuf struct buffers */ if (VC_FIELD(vc, connection)->rfp.RDMA_recv_buf) { MPIU_Free(VC_FIELD(vc, connection)->rfp.RDMA_recv_buf); VC_FIELD(vc, connection)->rfp.RDMA_recv_buf = NULL; } /* set flag to mark that FP setup is failed/rejected. we sholdn't try further on this vc */ VC_FIELD(vc, connection)->rfp.rdma_failed = 1; } else if (pkt->reply_data == RDMA_FP_SUCCESS) { /* set pointers */ VC_FIELD(vc, connection)->rfp.p_RDMA_recv = 0; VC_FIELD(vc, connection)->rfp.p_RDMA_recv_tail = num_rdma_buffer - 1; /* Add the connection to the RDMA polling list */ MPIU_Assert(process_info.polling_group_size < rdma_polling_set_limit); process_info.polling_set [process_info.polling_group_size] = vc; process_info.polling_group_size++; VC_FIELD(vc, cmanager)->num_channels += 1; VC_FIELD(vc, cmanager)->num_local_pollings = 1; VC_FIELD(vc, connection)->rfp.in_polling_set = 1; } else { ibv_va_error_abort(GEN_EXIT_ERR, "Invalid reply data received. reply_data: pkt->reply_data%d\n", pkt->reply_data); } rdma_pending_conn_request--; return MPI_SUCCESS; }