static void hsictty_write_callback(struct urb *urb) { struct usb_serial_port *port; struct hsictty_port_private *portdata; struct hsictty_intf_private *intfdata; int i; port = urb->context; intfdata = usb_get_serial_data(port->serial); portdata = usb_get_serial_port_data(port); if (urb->actual_length <= 0) { hsictty_error ("%s: write failed, write length: %d in channel:%d, endpoint:%d\n", __func__, urb->actual_length, portdata->channel, usb_pipeendpoint(urb->pipe)); } else { hsictty_dbg("%s: write length: %d in channel:%d, endpoint:%d\n", __func__, urb->actual_length, portdata->channel, usb_pipeendpoint(urb->pipe)); } #ifdef BACKUP_DATA_DUMP if (!dumped) backup_log(portdata->channel, 1, urb->transfer_buffer, urb->transfer_buffer_length); #endif usb_serial_port_softint(port); usb_autopm_put_interface_async(port->serial->interface); portdata = usb_get_serial_port_data(port); spin_lock(&intfdata->susp_lock); intfdata->in_flight--; spin_unlock(&intfdata->susp_lock); for (i = 0; i < N_OUT_URB; ++i) { if (portdata->out_urbs[i] == urb) { smp_mb__before_clear_bit(); hsictty_dbg ("%s: urb(%d) freed on channel:%d, endpoint:%d, in_flight:%d, pm use cnt:%d\n", __func__, i, portdata->channel, usb_pipeendpoint(urb->pipe), intfdata->in_flight, atomic_read(&port->serial->interface->dev.power. usage_count)); clear_bit(i, &portdata->out_busy); complete_all(&portdata->tx_notifier); break; } } }
void *log_open(const char *file_name, const char *version, const char *dir, uint32_t mode) { log_t *log = NULL; uint32_t i = 0; if ((NULL == file_name) || (NULL == version) || (NULL == dir)) { return NULL; } log = (log_t *)OS_MALLOC(sizeof(log_t)); if (NULL == log) { return NULL; } memset(log, 0, sizeof(log_t)); OS_RWLOCK_INIT(&log->rwlock); strncpy(log->dir, dir, LOG_NAME_LEN); log->dir[LOG_NAME_LEN - 1] = 0; strncpy(log->name, file_name, LOG_NAME_LEN); log->name[LOG_NAME_LEN - 1] = 0; strncpy(log->version, version, LOG_NAME_LEN); log->version[LOG_NAME_LEN - 1] = 0; log->mode = mode; for (i = 0; i < PIDS_NUM; i++) { log->levels[i] = DEFAULT_LEVEL; } if (0 > backup_log(log)) { OS_FREE(log); return NULL; } return log; }
void log_trace(void *log, uint32_t pid, uint32_t level, const char *format, ...) { log_t *tmp_log = (log_t *)log; va_list ap; if ((NULL == tmp_log) || (pid >= PIDS_NUM) || (level > tmp_log->levels[pid]) || (0 == (tmp_log->mode & LOG_TO_SCNFILE)) || ((0 == (tmp_log->mode & LOG_TO_SCREEN)) && (NULL == tmp_log->disk_hnd))) { return; } OS_RWLOCK_WRLOCK(&tmp_log->rwlock); os_get_date_time_string(tmp_log->date_time, DATA_TIME_STR_LEN); va_start(ap, format); OS_VSNPRINTF(tmp_log->buf, BUF_LEN, format, ap); va_end(ap); if (0 != (tmp_log->mode & LOG_TO_SCREEN)) { //OS_PRINT("%s %s", tmp_log->date_time, tmp_log->buf); } if (NULL != tmp_log->disk_hnd) { os_file_printf(tmp_log->disk_hnd, "%s %s", tmp_log->date_time, tmp_log->buf); tmp_log->total_lines++; } OS_RWLOCK_WRUNLOCK(&tmp_log->rwlock); if (tmp_log->total_lines > MAX_FILE_LINES) { backup_log(tmp_log); } }
static int rx_threadfn(void *x_) { struct hsictty_port_private *portdata = x_; long rc = 0; struct sched_param param = {.sched_priority = 50 }; sched_setscheduler(current, SCHED_FIFO, ¶m); while (!kthread_should_stop()) { if (portdata->thread_exit) { msleep(5); continue; } process_rx_data(portdata); rc = wait_for_completion_timeout(&portdata->rx_notifier, 5 * HZ); INIT_COMPLETION(portdata->rx_notifier); } return 0; } #endif static void hsictty_read_callback(struct urb *urb) { int endpoint; struct _HSICTTY_MSG *msg = NULL; int msg_index = -1; struct usb_serial_port *port; int status = urb->status; struct hsictty_port_private *portdata; unsigned long flags; int err = -1; u8 channel = 0; struct hsictty_intf_private *intfdata; static int error_times = 0; int error_times_limits = 50; hsictty_dbg("%s: %p\n", __func__, urb); endpoint = usb_pipeendpoint(urb->pipe); port = urb->context; portdata = usb_get_serial_port_data(port); intfdata = usb_get_serial_data(port->serial); channel = portdata->channel; if (status) { hsictty_dbg ("%s: nonzero status: %d on channel:%d, endpoint %02x.\n", __func__, status, channel, endpoint); if (intfdata->multi_channel_mode) { if (((status == -EPROTO) || (status == -EOVERFLOW)) && error_times++ < error_times_limits) { hsictty_error ("%s: an halted error detected, will try again, status: %d on channel:%d, endpoint %02x.\n", __func__, status, channel, endpoint); err = usb_submit_urb(urb, GFP_ATOMIC); if (err) { if (err != -EPERM) { printk(KERN_ERR "%s: resubmit read urb failed in channel:%d.\n" "(%d)", __func__, channel, err); /* busy also in error unless we are killed */ usb_mark_last_busy(port-> serial->dev); } } else { usb_mark_last_busy(port->serial->dev); } } else if (status == -EPROTO) { hsictty_error ("%s: unrecorvery halted error detected, please check the hsic connection\n", __func__); } } } else { error_times = 0; port = urb->context; portdata = usb_get_serial_port_data(port); if ((msg_index = get_read_msg_index(portdata)) < 0) { hsictty_error ("%s: get read msg fail in channel:%d, endpoint:%d.\n", __func__, channel, endpoint); err = usb_submit_urb(urb, GFP_ATOMIC); if (err) { if (err != -EPERM) { printk(KERN_ERR "%s: resubmit read urb failed in channel:%d.\n" "(%d)", __func__, channel, err); /* busy also in error unless we are killed */ usb_mark_last_busy(port->serial->dev); } } else usb_mark_last_busy(port->serial->dev); return; } msg = &portdata->read_msg[msg_index]; #ifdef BACKUP_DATA_DUMP if (!dumped) backup_log(portdata->channel, 0, urb->transfer_buffer, urb->actual_length); #endif INIT_LIST_HEAD(&msg->link); msg->urb = urb; wakeup_device(port, 0); wake_lock_timeout(&intfdata->rx_wakelock, HZ); spin_lock_irqsave(&portdata->pool_lock, flags); list_add_tail(&msg->link, &portdata->pool); spin_unlock_irqrestore(&portdata->pool_lock, flags); #ifdef USE_READ_WORK queue_work(intfdata->hsictty_read_wq, &(portdata->hsictty_read_work)); #else complete_all(&portdata->rx_notifier); #endif } }