Example #1
0
int __init
blktap_ring_init(void)
{
	dev_t dev = 0;
	int err;

	cdev_init(&blktap_ring_cdev, &blktap_ring_file_operations);
	blktap_ring_cdev.owner = THIS_MODULE;

	err = alloc_chrdev_region(&dev, 0, MAX_BLKTAP_DEVICE, "blktap2");
	if (err < 0) {
		BTERR("error registering ring devices: %d\n", err);
		return err;
	}

	err = cdev_add(&blktap_ring_cdev, dev, MAX_BLKTAP_DEVICE);
	if (err) {
		BTERR("error adding ring device: %d\n", err);
		unregister_chrdev_region(dev, MAX_BLKTAP_DEVICE);
		return err;
	}

	blktap_ring_major = MAJOR(dev);
	BTINFO("blktap ring major: %d\n", blktap_ring_major);

	return 0;
}
Example #2
0
static struct blktap *
blktap_control_allocate_tap(void)
{
	int err, minor;
	struct blktap *tap;

	/*
	 * This is called only from the ioctl, which
	 * means we should always have interrupts enabled.
	 */
	BUG_ON(irqs_disabled());

	spin_lock_irq(&blktap_control_lock);

	for (minor = 0; minor < MAX_BLKTAP_DEVICE; minor++) {
		tap = blktaps[minor];
		if (!tap)
			goto found;

		if (!tap->dev_inuse) {
			blktap_control_initialize_tap(tap);
			goto found;
		}
	}

	tap = NULL;

found:
	spin_unlock_irq(&blktap_control_lock);

	if (!tap) {
		tap = blktap_control_create_tap();
		if (!tap)
			return NULL;
	}

	err = blktap_ring_create(tap);
	if (err) {
		BTERR("ring creation failed: %d\n", err);
		clear_bit(BLKTAP_CONTROL, &tap->dev_inuse);
		return NULL;
	}

	BTINFO("allocated tap %p\n", tap);
	return tap;
}
Example #3
0
static int ericsson(int fd, struct uart_t *u, struct termios *ti)
{
    struct timespec 			tm = {0, 50000};
    int					err;
    struct Ericsson_Set_UART_Speed		cmd;
    uint8_t					buf[HCI_MAX_EVENT_SIZE];
    struct Command_Complete_Status		*ccs = (void*)buf;

    switch (u->speed) {
    case 57600:
        cmd.speed = 0x03;
        break;
    case 115200:
        cmd.speed = 0x02;
        break;
    case 230400:
        cmd.speed = 0x01;
        break;
    case 460800:
        cmd.speed = 0x00;
        break;
    case 921600:
        cmd.speed = 0x20;
        break;
    default:
        cmd.speed = 0x03;
        u->speed = 57600;
        break;
    }
#if 0
    err = hci_exec_cmd(fd, HCI_C_ERICSSON_SET_UART_SPEED, &cmd, sizeof(cmd),
                       COMMAND_COMPLETE_MASK, 0, ccs);
#else
    ccs->Status = 0;
    err = hci_exec_cmd1(fd, HCI_C_ERICSSON_SET_UART_SPEED, &cmd, sizeof(cmd),
                        COMMAND_COMPLETE_MASK, HCI_SKIP_STATUS);
    nanosleep(&tm, NULL);
#endif
    BTINFO("err: %d, status: %#x\n", err, ccs->Status);
    if (err)
        return err;
    return ccs->Status;
}
Example #4
0
/* Initialize UART device */
int init_uart(char *dev, struct uart_t *u)
{
    struct termios	ti;
    int		fd, err;
    int 		to = 20, speed;

    /* now device ready for initialization */
    signal(SIGALRM, &sig_alarm);
    alarm(to);

    BTINFO("Initializing UART");

    if (uart_rate)
        speed = uart_speed(uart_rate > 0 ? uart_rate : u->init_speed);
    else
        speed = 0;
    err = hci_setup_uart(dev, u->proto, speed, u->flags);
    if (err)
        return err;

    /* Vendor specific initialization */
    if (u->init) {
        fd = _hci_open(dev);
        if (fd < 0) {
            BTERROR("unable to open: %s\n", dev);
            return fd;
        }
        err =  u->init(fd, u, &ti);
        close(fd);
    }

    /* Set actual baudrate */
    if (!err) {
        err = hci_setup_uart(dev, u->proto, uart_speed(u->speed), u->flags);
        if (err)
            BTERROR("Can't setup uart");
    }
    alarm(0);
    return err;
}
Example #5
0
int sdpreg_unregister(struct btservice *svc)
{
	int		status;
	sdpsvc_t	*svcRec = svc->svcRec;

	if (!svcRec)
		return 0;
	status = sdp_delete_service(srvHandle, svcRec);
	switch (status) {
		case 0:
			BTINFO("service %s deleted", svc->name);
			break;
		case SDP_ERR_INVALID_ARG:
			BTERROR("Error: You cannot delete service %s", svc->name);
			break;
		default:
			BTERROR("Something went wrong. sdp_delete_service() returned: %d\n", status);
			break;
	}
	sdp_free_svc(svcRec);
	svc->svcRec = NULL;
	return 0;
}
Example #6
0
static int csr(int fd, struct uart_t *u, struct termios *ti)
{
    struct timespec tm = {0, 10000000};	/* 10ms - be generous */
    static int csr_seq = 0;	/* Sequence number of command */
    int  divisor;
    int					err;
    struct CSR_Get_Build_ID			cmd1;
    struct CSR_Get_Build_ID_Event		cce;
    struct CSR_Set_UART_Speed		cmd2;

    /* Try to read the build ID of the CSR chip */
    cmd1.bcc.channel = 0xc2;			/* first+last+channel=BCC */
    cmd1.bcc.type = __htob16(0x0000);		/* type = GET-REQ */
    cmd1.bcc.len = __htob16(5 + 4);			/* ??? */
    cmd1.bcc.seq_num = __htob16(csr_seq);		/* seq num */
    csr_seq++;
    cmd1.bcc.var_id = __htob16(0x2819);		/* var_id = CSR_CMD_BUILD_ID */
    cmd1.bcc.status = __htob16(0x0000);		/* status = STATUS_OK */
    /* CSR BCC payload */
    memset(cmd1.data, 0, sizeof(cmd1.data));

    /* Send command */
    err = hci_exec_cmd1(fd, HCI_C_CSR_COMMAND, &cmd1, sizeof(cmd1),
                        ALL_EVENTS_MASK, HCI_SKIP_STATUS);
    if (err)
        return err;

    do {
#if 0	// it's here in original code
        /* Send command */
        err = hci_exec_cmd(fd, &cmd1, ALL_EVENTS_MASK, HCI_SKIP_STATUS, NULL);
        if (err)
            return err;

#endif
        err = hci_recv_event(fd, &cce, sizeof(cce), 20);
        if (err < 0) {
            return err;
        }
    } while (cce.hci.EventCode != 0xFF);

    /* Display that to user */
    BTINFO("CSR build ID 0x%02X-0x%02X\n", cce.data[12], cce.data[11]);

    /* Now, create the command that will set the UART speed */
    cmd2.bcc.channel = 0xc2;
    cmd2.bcc.type = __htob16(0x0002);	// SET-REQ
    cmd2.bcc.len = __htob16(5 + 4);
    cmd2.bcc.seq_num = __htob16(csr_seq);
    csr_seq++;
    cmd2.bcc.var_id = __htob16(0x6802);	// CONFIG_UART
    cmd2.bcc.status = __htob16(0x0000);	// STATUS_OK

    switch (u->speed) {
    case 9600:
        divisor = 0x0027;
        break;
    /* Various speeds ommited */
    case 57600:
        divisor = 0x00EC;
        break;
    case 115200:
        divisor = 0x01D8;
        break;
    /* For Brainbox Pcmcia cards */
    case 460800:
        divisor = 0x075F;
        break;
    case 921600:
        divisor = 0x0EBF;
        break;
    default:
        /* Safe default */
        divisor = 0x01D8;
        u->speed = 115200;
        break;
    }
    /* No parity, one stop bit -> divisor |= 0x0000; */
    cmd2.speed = __htob16(divisor);
    memset(cmd2.extra, 0, sizeof(cmd2.extra));

    err = hci_exec_cmd1(fd, HCI_C_CSR_COMMAND, &cmd2, sizeof(cmd2),
                        ALL_EVENTS_MASK, HCI_SKIP_STATUS);
    if (err)
        return err;

#if 0	// no wait for response in original code
    do {
        err = hci_recv_event(fd, &cce, sizeof(cce), 20);
        if (err < 0) {
            return err;
        }

    } while (cce.hci.EventCode != 0xFF);
#endif
    nanosleep(&tm, NULL);
    return 0;
}