• Home
  • Raw
  • Download

Lines Matching refs:up

261 	struct ucan_priv *up;  member
314 static void ucan_release_context_array(struct ucan_priv *up) in ucan_release_context_array() argument
316 if (!up->context_array) in ucan_release_context_array()
320 up->available_tx_urbs = 0; in ucan_release_context_array()
322 kfree(up->context_array); in ucan_release_context_array()
323 up->context_array = NULL; in ucan_release_context_array()
326 static int ucan_alloc_context_array(struct ucan_priv *up) in ucan_alloc_context_array() argument
331 ucan_release_context_array(up); in ucan_alloc_context_array()
333 up->context_array = kcalloc(up->device_info.tx_fifo, in ucan_alloc_context_array()
334 sizeof(*up->context_array), in ucan_alloc_context_array()
336 if (!up->context_array) { in ucan_alloc_context_array()
337 netdev_err(up->netdev, in ucan_alloc_context_array()
342 for (i = 0; i < up->device_info.tx_fifo; i++) { in ucan_alloc_context_array()
343 up->context_array[i].allocated = false; in ucan_alloc_context_array()
344 up->context_array[i].up = up; in ucan_alloc_context_array()
348 up->available_tx_urbs = up->device_info.tx_fifo; in ucan_alloc_context_array()
353 static struct ucan_urb_context *ucan_alloc_context(struct ucan_priv *up) in ucan_alloc_context() argument
359 if (WARN_ON_ONCE(!up->context_array)) in ucan_alloc_context()
363 spin_lock_irqsave(&up->context_lock, flags); in ucan_alloc_context()
365 for (i = 0; i < up->device_info.tx_fifo; i++) { in ucan_alloc_context()
366 if (!up->context_array[i].allocated) { in ucan_alloc_context()
368 ret = &up->context_array[i]; in ucan_alloc_context()
369 up->context_array[i].allocated = true; in ucan_alloc_context()
372 up->available_tx_urbs--; in ucan_alloc_context()
373 if (!up->available_tx_urbs) in ucan_alloc_context()
374 netif_stop_queue(up->netdev); in ucan_alloc_context()
380 spin_unlock_irqrestore(&up->context_lock, flags); in ucan_alloc_context()
384 static bool ucan_release_context(struct ucan_priv *up, in ucan_release_context() argument
390 if (WARN_ON_ONCE(!up->context_array)) in ucan_release_context()
394 spin_lock_irqsave(&up->context_lock, flags); in ucan_release_context()
401 if (!up->available_tx_urbs) in ucan_release_context()
402 netif_wake_queue(up->netdev); in ucan_release_context()
403 up->available_tx_urbs++; in ucan_release_context()
408 spin_unlock_irqrestore(&up->context_lock, flags); in ucan_release_context()
412 static int ucan_ctrl_command_out(struct ucan_priv *up, in ucan_ctrl_command_out() argument
415 return usb_control_msg(up->udev, in ucan_ctrl_command_out()
416 usb_sndctrlpipe(up->udev, 0), in ucan_ctrl_command_out()
421 up->intf_index, in ucan_ctrl_command_out()
422 up->ctl_msg_buffer, in ucan_ctrl_command_out()
427 static int ucan_device_request_in(struct ucan_priv *up, in ucan_device_request_in() argument
430 return usb_control_msg(up->udev, in ucan_device_request_in()
431 usb_rcvctrlpipe(up->udev, 0), in ucan_device_request_in()
436 up->ctl_msg_buffer, in ucan_device_request_in()
444 static void ucan_parse_device_info(struct ucan_priv *up, in ucan_parse_device_info() argument
448 &up->device_info.bittiming_const; in ucan_parse_device_info()
452 up->can.clock.freq = le32_to_cpu(device_info->freq); in ucan_parse_device_info()
453 up->device_info.tx_fifo = device_info->tx_fifo; in ucan_parse_device_info()
466 up->can.ctrlmode_supported = 0; in ucan_parse_device_info()
469 up->can.ctrlmode_supported |= CAN_CTRLMODE_LOOPBACK; in ucan_parse_device_info()
471 up->can.ctrlmode_supported |= CAN_CTRLMODE_LISTENONLY; in ucan_parse_device_info()
473 up->can.ctrlmode_supported |= CAN_CTRLMODE_3_SAMPLES; in ucan_parse_device_info()
475 up->can.ctrlmode_supported |= CAN_CTRLMODE_ONE_SHOT; in ucan_parse_device_info()
477 up->can.ctrlmode_supported |= CAN_CTRLMODE_BERR_REPORTING; in ucan_parse_device_info()
483 static bool ucan_handle_error_frame(struct ucan_priv *up, in ucan_handle_error_frame() argument
487 enum can_state new_state = up->can.state; in ucan_handle_error_frame()
488 struct net_device_stats *net_stats = &up->netdev->stats; in ucan_handle_error_frame()
489 struct can_device_stats *can_stats = &up->can.can_stats; in ucan_handle_error_frame()
532 if (up->can.state == new_state) in ucan_handle_error_frame()
536 if (up->can.state > new_state) { in ucan_handle_error_frame()
537 up->can.state = new_state; in ucan_handle_error_frame()
542 up->can.state = new_state; in ucan_handle_error_frame()
546 can_bus_off(up->netdev); in ucan_handle_error_frame()
565 static void ucan_rx_can_msg(struct ucan_priv *up, struct ucan_message_in *m) in ucan_rx_can_msg() argument
571 struct net_device_stats *stats = &up->netdev->stats; in ucan_rx_can_msg()
578 netdev_warn(up->netdev, "invalid input message len: %d\n", len); in ucan_rx_can_msg()
585 bool busstate_changed = ucan_handle_error_frame(up, m, canid); in ucan_rx_can_msg()
588 if (!(up->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) && in ucan_rx_can_msg()
601 netdev_warn(up->netdev, in ucan_rx_can_msg()
609 skb = alloc_can_skb(up->netdev, &cf); in ucan_rx_can_msg()
632 static void ucan_tx_complete_msg(struct ucan_priv *up, in ucan_tx_complete_msg() argument
643 netdev_err(up->netdev, "invalid tx complete length\n"); in ucan_tx_complete_msg()
651 if (echo_index >= up->device_info.tx_fifo) { in ucan_tx_complete_msg()
652 up->netdev->stats.tx_errors++; in ucan_tx_complete_msg()
653 netdev_err(up->netdev, in ucan_tx_complete_msg()
660 context = &up->context_array[echo_index]; in ucan_tx_complete_msg()
666 if (!ucan_release_context(up, context)) in ucan_tx_complete_msg()
669 spin_lock_irqsave(&up->echo_skb_lock, flags); in ucan_tx_complete_msg()
673 up->netdev->stats.tx_packets++; in ucan_tx_complete_msg()
674 up->netdev->stats.tx_bytes += dlc; in ucan_tx_complete_msg()
675 can_get_echo_skb(up->netdev, echo_index, NULL); in ucan_tx_complete_msg()
677 up->netdev->stats.tx_dropped++; in ucan_tx_complete_msg()
678 can_free_echo_skb(up->netdev, echo_index, NULL); in ucan_tx_complete_msg()
680 spin_unlock_irqrestore(&up->echo_skb_lock, flags); in ucan_tx_complete_msg()
689 struct ucan_priv *up = urb->context; in ucan_read_bulk_callback() local
690 struct net_device *netdev = up->netdev; in ucan_read_bulk_callback()
696 if (WARN_ON(!up->context_array)) { in ucan_read_bulk_callback()
697 usb_free_coherent(up->udev, in ucan_read_bulk_callback()
698 up->in_ep_size, in ucan_read_bulk_callback()
714 usb_free_coherent(up->udev, in ucan_read_bulk_callback()
715 up->in_ep_size, in ucan_read_bulk_callback()
718 netdev_dbg(up->netdev, "not resubmitting urb; status: %d\n", in ucan_read_bulk_callback()
736 netdev_warn(up->netdev, in ucan_read_bulk_callback()
749 netdev_warn(up->netdev, in ucan_read_bulk_callback()
766 ucan_rx_can_msg(up, m); in ucan_read_bulk_callback()
769 ucan_tx_complete_msg(up, m); in ucan_read_bulk_callback()
772 netdev_warn(up->netdev, in ucan_read_bulk_callback()
786 usb_fill_bulk_urb(urb, up->udev, in ucan_read_bulk_callback()
787 usb_rcvbulkpipe(up->udev, in ucan_read_bulk_callback()
788 up->in_ep_addr), in ucan_read_bulk_callback()
790 up->in_ep_size, in ucan_read_bulk_callback()
792 up); in ucan_read_bulk_callback()
794 usb_anchor_urb(urb, &up->rx_urbs); in ucan_read_bulk_callback()
798 netdev_err(up->netdev, in ucan_read_bulk_callback()
803 usb_free_coherent(up->udev, in ucan_read_bulk_callback()
804 up->in_ep_size, in ucan_read_bulk_callback()
817 struct ucan_priv *up; in ucan_write_bulk_callback() local
830 up = context->up; in ucan_write_bulk_callback()
831 if (WARN_ON_ONCE(!up)) in ucan_write_bulk_callback()
835 if (!netif_device_present(up->netdev)) in ucan_write_bulk_callback()
840 netdev_warn(up->netdev, in ucan_write_bulk_callback()
845 spin_lock_irqsave(&up->echo_skb_lock, flags); in ucan_write_bulk_callback()
846 can_free_echo_skb(up->netdev, context - up->context_array, NULL); in ucan_write_bulk_callback()
847 spin_unlock_irqrestore(&up->echo_skb_lock, flags); in ucan_write_bulk_callback()
849 up->netdev->stats.tx_dropped++; in ucan_write_bulk_callback()
852 if (!ucan_release_context(up, context)) in ucan_write_bulk_callback()
853 netdev_err(up->netdev, in ucan_write_bulk_callback()
858 static void ucan_cleanup_rx_urbs(struct ucan_priv *up, struct urb **urbs) in ucan_cleanup_rx_urbs() argument
865 usb_free_coherent(up->udev, in ucan_cleanup_rx_urbs()
866 up->in_ep_size, in ucan_cleanup_rx_urbs()
876 static int ucan_prepare_and_anchor_rx_urbs(struct ucan_priv *up, in ucan_prepare_and_anchor_rx_urbs() argument
890 buf = usb_alloc_coherent(up->udev, in ucan_prepare_and_anchor_rx_urbs()
891 up->in_ep_size, in ucan_prepare_and_anchor_rx_urbs()
900 usb_fill_bulk_urb(urbs[i], up->udev, in ucan_prepare_and_anchor_rx_urbs()
901 usb_rcvbulkpipe(up->udev, in ucan_prepare_and_anchor_rx_urbs()
902 up->in_ep_addr), in ucan_prepare_and_anchor_rx_urbs()
904 up->in_ep_size, in ucan_prepare_and_anchor_rx_urbs()
906 up); in ucan_prepare_and_anchor_rx_urbs()
910 usb_anchor_urb(urbs[i], &up->rx_urbs); in ucan_prepare_and_anchor_rx_urbs()
916 ucan_cleanup_rx_urbs(up, urbs); in ucan_prepare_and_anchor_rx_urbs()
925 static int ucan_submit_rx_urbs(struct ucan_priv *up, struct urb **urbs) in ucan_submit_rx_urbs() argument
935 netdev_err(up->netdev, in ucan_submit_rx_urbs()
951 ucan_cleanup_rx_urbs(up, urbs); in ucan_submit_rx_urbs()
954 usb_kill_anchored_urbs(&up->rx_urbs); in ucan_submit_rx_urbs()
965 struct ucan_priv *up = netdev_priv(netdev); in ucan_open() local
967 ret = ucan_alloc_context_array(up); in ucan_open()
974 ret = ucan_prepare_and_anchor_rx_urbs(up, urbs); in ucan_open()
980 if (up->can.ctrlmode & CAN_CTRLMODE_LOOPBACK) in ucan_open()
982 if (up->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) in ucan_open()
984 if (up->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES) in ucan_open()
986 if (up->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT) in ucan_open()
993 up->ctl_msg_buffer->cmd_start.mode = cpu_to_le16(ctrlmode); in ucan_open()
996 ret = ucan_ctrl_command_out(up, UCAN_COMMAND_START, 0, 2); in ucan_open()
998 netdev_err(up->netdev, in ucan_open()
1010 ret = ucan_submit_rx_urbs(up, urbs); in ucan_open()
1014 up->can.state = CAN_STATE_ERROR_ACTIVE; in ucan_open()
1023 ret_cleanup = ucan_ctrl_command_out(up, UCAN_COMMAND_STOP, 0, 0); in ucan_open()
1025 netdev_err(up->netdev, in ucan_open()
1033 ret_cleanup = ucan_ctrl_command_out(up, UCAN_COMMAND_RESET, 0, 0); in ucan_open()
1035 netdev_err(up->netdev, in ucan_open()
1040 ucan_cleanup_rx_urbs(up, urbs); in ucan_open()
1043 ucan_release_context_array(up); in ucan_open()
1047 static struct urb *ucan_prepare_tx_urb(struct ucan_priv *up, in ucan_prepare_tx_urb() argument
1059 netdev_err(up->netdev, "no memory left for URBs\n"); in ucan_prepare_tx_urb()
1063 m = usb_alloc_coherent(up->udev, in ucan_prepare_tx_urb()
1068 netdev_err(up->netdev, "no memory left for USB buffer\n"); in ucan_prepare_tx_urb()
1094 usb_fill_bulk_urb(urb, up->udev, in ucan_prepare_tx_urb()
1095 usb_sndbulkpipe(up->udev, in ucan_prepare_tx_urb()
1096 up->out_ep_addr), in ucan_prepare_tx_urb()
1103 static void ucan_clean_up_tx_urb(struct ucan_priv *up, struct urb *urb) in ucan_clean_up_tx_urb() argument
1105 usb_free_coherent(up->udev, sizeof(struct ucan_message_out), in ucan_clean_up_tx_urb()
1119 struct ucan_priv *up = netdev_priv(netdev); in ucan_start_xmit() local
1127 context = ucan_alloc_context(up); in ucan_start_xmit()
1128 echo_index = context - up->context_array; in ucan_start_xmit()
1134 urb = ucan_prepare_tx_urb(up, context, cf, echo_index); in ucan_start_xmit()
1139 spin_lock_irqsave(&up->echo_skb_lock, flags); in ucan_start_xmit()
1140 can_put_echo_skb(skb, up->netdev, echo_index, 0); in ucan_start_xmit()
1141 spin_unlock_irqrestore(&up->echo_skb_lock, flags); in ucan_start_xmit()
1144 usb_anchor_urb(urb, &up->tx_urbs); in ucan_start_xmit()
1151 ucan_clean_up_tx_urb(up, urb); in ucan_start_xmit()
1152 if (!ucan_release_context(up, context)) in ucan_start_xmit()
1153 netdev_err(up->netdev, in ucan_start_xmit()
1159 spin_lock_irqsave(&up->echo_skb_lock, flags); in ucan_start_xmit()
1160 can_free_echo_skb(up->netdev, echo_index, NULL); in ucan_start_xmit()
1161 spin_unlock_irqrestore(&up->echo_skb_lock, flags); in ucan_start_xmit()
1164 netif_device_detach(up->netdev); in ucan_start_xmit()
1166 netdev_warn(up->netdev, in ucan_start_xmit()
1169 up->netdev->stats.tx_dropped++; in ucan_start_xmit()
1182 if (!ucan_release_context(up, context)) in ucan_start_xmit()
1183 netdev_err(up->netdev, in ucan_start_xmit()
1186 up->netdev->stats.tx_dropped++; in ucan_start_xmit()
1198 struct ucan_priv *up = netdev_priv(netdev); in ucan_close() local
1200 up->can.state = CAN_STATE_STOPPED; in ucan_close()
1203 usb_kill_anchored_urbs(&up->tx_urbs); in ucan_close()
1206 usb_kill_anchored_urbs(&up->rx_urbs); in ucan_close()
1209 ret = ucan_ctrl_command_out(up, UCAN_COMMAND_STOP, 0, 0); in ucan_close()
1211 netdev_err(up->netdev, in ucan_close()
1215 ret = ucan_ctrl_command_out(up, UCAN_COMMAND_RESET, 0, 0); in ucan_close()
1217 netdev_err(up->netdev, in ucan_close()
1223 ucan_release_context_array(up); in ucan_close()
1225 close_candev(up->netdev); in ucan_close()
1245 struct ucan_priv *up = netdev_priv(netdev); in ucan_set_bittiming() local
1248 cmd_set_bittiming = &up->ctl_msg_buffer->cmd_set_bittiming; in ucan_set_bittiming()
1249 cmd_set_bittiming->tq = cpu_to_le32(up->can.bittiming.tq); in ucan_set_bittiming()
1250 cmd_set_bittiming->brp = cpu_to_le16(up->can.bittiming.brp); in ucan_set_bittiming()
1252 cpu_to_le16(up->can.bittiming.sample_point); in ucan_set_bittiming()
1253 cmd_set_bittiming->prop_seg = up->can.bittiming.prop_seg; in ucan_set_bittiming()
1254 cmd_set_bittiming->phase_seg1 = up->can.bittiming.phase_seg1; in ucan_set_bittiming()
1255 cmd_set_bittiming->phase_seg2 = up->can.bittiming.phase_seg2; in ucan_set_bittiming()
1256 cmd_set_bittiming->sjw = up->can.bittiming.sjw; in ucan_set_bittiming()
1258 ret = ucan_ctrl_command_out(up, UCAN_COMMAND_SET_BITTIMING, 0, in ucan_set_bittiming()
1270 struct ucan_priv *up = netdev_priv(netdev); in ucan_set_mode() local
1274 netdev_dbg(up->netdev, "restarting device\n"); in ucan_set_mode()
1276 ret = ucan_ctrl_command_out(up, UCAN_COMMAND_RESTART, 0, 0); in ucan_set_mode()
1277 up->can.state = CAN_STATE_ERROR_ACTIVE; in ucan_set_mode()
1283 spin_lock_irqsave(&up->context_lock, flags); in ucan_set_mode()
1285 if (up->available_tx_urbs > 0) in ucan_set_mode()
1286 netif_wake_queue(up->netdev); in ucan_set_mode()
1288 spin_unlock_irqrestore(&up->context_lock, flags); in ucan_set_mode()
1306 struct ucan_priv *up; in ucan_probe() local
1495 up = netdev_priv(netdev); in ucan_probe()
1498 up->udev = udev; in ucan_probe()
1499 up->intf = intf; in ucan_probe()
1500 up->netdev = netdev; in ucan_probe()
1501 up->intf_index = iface_desc->desc.bInterfaceNumber; in ucan_probe()
1502 up->in_ep_addr = in_ep_addr; in ucan_probe()
1503 up->out_ep_addr = out_ep_addr; in ucan_probe()
1504 up->in_ep_size = in_ep_size; in ucan_probe()
1505 up->ctl_msg_buffer = ctl_msg_buffer; in ucan_probe()
1506 up->context_array = NULL; in ucan_probe()
1507 up->available_tx_urbs = 0; in ucan_probe()
1509 up->can.state = CAN_STATE_STOPPED; in ucan_probe()
1510 up->can.bittiming_const = &up->device_info.bittiming_const; in ucan_probe()
1511 up->can.do_set_bittiming = ucan_set_bittiming; in ucan_probe()
1512 up->can.do_set_mode = &ucan_set_mode; in ucan_probe()
1513 spin_lock_init(&up->context_lock); in ucan_probe()
1514 spin_lock_init(&up->echo_skb_lock); in ucan_probe()
1517 usb_set_intfdata(intf, up); in ucan_probe()
1524 ucan_parse_device_info(up, &ctl_msg_buffer->cmd_get_device_info); in ucan_probe()
1527 ret = ucan_device_request_in(up, UCAN_DEVICE_GET_FW_STRING, 0, in ucan_probe()
1531 strncpy(firmware_str, up->ctl_msg_buffer->raw, in ucan_probe()
1539 ret = ucan_ctrl_command_out(up, UCAN_COMMAND_RESET, 0, 0); in ucan_probe()
1543 init_usb_anchor(&up->rx_urbs); in ucan_probe()
1544 init_usb_anchor(&up->tx_urbs); in ucan_probe()
1546 up->can.state = CAN_STATE_STOPPED; in ucan_probe()
1554 netdev_info(up->netdev, "registered device\n"); in ucan_probe()
1555 netdev_info(up->netdev, "firmware string: %s\n", firmware_str); in ucan_probe()
1574 struct ucan_priv *up = usb_get_intfdata(intf); in ucan_disconnect() local
1578 if (up) { in ucan_disconnect()
1579 unregister_netdev(up->netdev); in ucan_disconnect()
1580 free_candev(up->netdev); in ucan_disconnect()