int gsmd_ctrl_setup(enum ctrl_client client_num, unsigned int count,
					u8 *first_port_idx)
{
	int	i, start_port, allocated_ports;
	int	ret;

	pr_debug("%s: requested ports:%d\n", __func__, count);

	if (client_num >= NR_CTRL_CLIENTS) {
		pr_err("%s: Invalid client:%d\n", __func__, client_num);
		return -EINVAL;
	}

	if (!count || count > MAX_CTRL_PER_CLIENT) {
		pr_err("%s: Invalid num of ports count:%d\n",
				__func__, count);
		return -EINVAL;
	}

	if (!online_clients) {
		grmnet_ctrl_wq = alloc_workqueue("gsmd_ctrl",
			WQ_UNBOUND | WQ_MEM_RECLAIM, 1);
		if (!grmnet_ctrl_wq) {
			pr_err("%s: Unable to create workqueue grmnet_ctrl\n",
					__func__);
			return -ENOMEM;
		}
	}
	online_clients++;

	start_port = MAX_CTRL_PER_CLIENT * client_num;
	allocated_ports = 0;
	for (i = start_port; i < count + start_port; i++) {
		allocated_ports++;
		ret = grmnet_ctrl_smd_port_alloc(i);
		if (ret) {
			pr_err("%s: Unable to alloc port:%d\n", __func__, i);
			allocated_ports--;
			goto free_ctrl_smd_ports;
		}
	}
	if (first_port_idx)
		*first_port_idx = start_port;
	return 0;

free_ctrl_smd_ports:
	for (i = 0; i < allocated_ports; i++)
		grmnet_ctrl_smd_port_free(start_port + i);


	online_clients--;
	if (!online_clients)
		destroy_workqueue(grmnet_ctrl_wq);

	return ret;
}
int gsmd_ctrl_setup(unsigned int count)
{
	int	i;
	int	ret;

	pr_debug("%s: requested ports:%d\n", __func__, count);

	if (!count || count > NR_CTRL_SMD_PORTS) {
		pr_err("%s: Invalid num of ports count:%d\n",
				__func__, count);
		return -EINVAL;
	}

	grmnet_ctrl_wq = alloc_workqueue("gsmd_ctrl",
				WQ_UNBOUND | WQ_MEM_RECLAIM, 1);
	if (!grmnet_ctrl_wq) {
		pr_err("%s: Unable to create workqueue grmnet_ctrl\n",
				__func__);
		return -ENOMEM;
	}

	for (i = 0; i < count; i++) {
		n_rmnet_ctrl_ports++;
		ret = grmnet_ctrl_smd_port_alloc(i);
		if (ret) {
			pr_err("%s: Unable to alloc port:%d\n", __func__, i);
			n_rmnet_ctrl_ports--;
			goto free_ctrl_smd_ports;
		}
	}

	return 0;

free_ctrl_smd_ports:
	for (i = 0; i < n_rmnet_ctrl_ports; i++)
		grmnet_ctrl_smd_port_free(i);

	destroy_workqueue(grmnet_ctrl_wq);

	return ret;
}