Lines Matching refs:op

199 	struct bcm_op *op;
208 list_for_each_entry(op, &bo->rx_ops, list) {
213 if (!op->frames_abs)
216 seq_printf(m, "rx_op: %03X %-5s ", op->can_id,
217 bcm_proc_getifname(net, ifname, op->ifindex));
219 if (op->flags & CAN_FD_FRAME)
220 seq_printf(m, "(%u)", op->nframes);
222 seq_printf(m, "[%u]", op->nframes);
224 seq_printf(m, "%c ", (op->flags & RX_CHECK_DLC) ? 'd' : ' ');
226 if (op->kt_ival1)
228 (long long)ktime_to_us(op->kt_ival1));
230 if (op->kt_ival2)
232 (long long)ktime_to_us(op->kt_ival2));
235 op->frames_filtered, op->frames_abs);
237 reduction = 100 - (op->frames_filtered * 100) / op->frames_abs;
243 list_for_each_entry(op, &bo->tx_ops, list) {
245 seq_printf(m, "tx_op: %03X %s ", op->can_id,
246 bcm_proc_getifname(net, ifname, op->ifindex));
248 if (op->flags & CAN_FD_FRAME)
249 seq_printf(m, "(%u) ", op->nframes);
251 seq_printf(m, "[%u] ", op->nframes);
253 if (op->kt_ival1)
255 (long long)ktime_to_us(op->kt_ival1));
257 if (op->kt_ival2)
259 (long long)ktime_to_us(op->kt_ival2));
261 seq_printf(m, "# sent %ld\n", op->frames_abs);
270 * of the given bcm tx op
272 static void bcm_can_tx(struct bcm_op *op)
276 struct canfd_frame *cf = op->frames + op->cfsiz * op->currframe;
280 if (!op->ifindex)
283 dev = dev_get_by_index(sock_net(op->sk), op->ifindex);
289 skb = alloc_skb(op->cfsiz + sizeof(struct can_skb_priv), gfp_any());
297 skb_put_data(skb, cf, op->cfsiz);
301 can_skb_set_owner(skb, op->sk);
304 op->frames_abs++;
306 op->currframe++;
309 if (op->currframe >= op->nframes)
310 op->currframe = 0;
319 static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head,
325 struct sock *sk = op->sk;
326 unsigned int datalen = head->nframes * op->cfsiz;
353 skb->tstamp = op->rx_stamp;
367 addr->can_ifindex = op->rx_ifindex;
379 static bool bcm_tx_set_expiry(struct bcm_op *op, struct hrtimer *hrt)
383 if (op->kt_ival1 && op->count)
384 ival = op->kt_ival1;
385 else if (op->kt_ival2)
386 ival = op->kt_ival2;
394 static void bcm_tx_start_timer(struct bcm_op *op)
396 if (bcm_tx_set_expiry(op, &op->timer))
397 hrtimer_start_expires(&op->timer, HRTIMER_MODE_ABS_SOFT);
403 struct bcm_op *op = container_of(hrtimer, struct bcm_op, timer);
406 if (op->kt_ival1 && (op->count > 0)) {
407 op->count--;
408 if (!op->count && (op->flags & TX_COUNTEVT)) {
413 msg_head.flags = op->flags;
414 msg_head.count = op->count;
415 msg_head.ival1 = op->ival1;
416 msg_head.ival2 = op->ival2;
417 msg_head.can_id = op->can_id;
420 bcm_send_to_user(op, &msg_head, NULL, 0);
422 bcm_can_tx(op);
424 } else if (op->kt_ival2) {
425 bcm_can_tx(op);
428 return bcm_tx_set_expiry(op, &op->timer) ?
435 static void bcm_rx_changed(struct bcm_op *op, struct canfd_frame *data)
440 op->frames_filtered++;
443 if (op->frames_filtered > ULONG_MAX/100)
444 op->frames_filtered = op->frames_abs = 0;
451 head.flags = op->flags;
452 head.count = op->count;
453 head.ival1 = op->ival1;
454 head.ival2 = op->ival2;
455 head.can_id = op->can_id;
458 bcm_send_to_user(op, &head, data, 1);
466 static void bcm_rx_update_and_send(struct bcm_op *op,
470 memcpy(lastdata, rxdata, op->cfsiz);
476 if (!op->kt_ival2) {
478 bcm_rx_changed(op, lastdata);
483 if (hrtimer_active(&op->thrtimer))
487 if (!op->kt_lastmsg)
491 if (ktime_us_delta(ktime_get(), op->kt_lastmsg) <
492 ktime_to_us(op->kt_ival2)) {
494 hrtimer_start(&op->thrtimer,
495 ktime_add(op->kt_lastmsg, op->kt_ival2),
502 bcm_rx_changed(op, lastdata);
503 op->kt_lastmsg = ktime_get();
508 * received data stored in op->last_frames[]
510 static void bcm_rx_cmp_to_index(struct bcm_op *op, unsigned int index,
513 struct canfd_frame *cf = op->frames + op->cfsiz * index;
514 struct canfd_frame *lcf = op->last_frames + op->cfsiz * index;
524 bcm_rx_update_and_send(op, lcf, rxdata);
532 bcm_rx_update_and_send(op, lcf, rxdata);
537 if (op->flags & RX_CHECK_DLC) {
540 bcm_rx_update_and_send(op, lcf, rxdata);
549 static void bcm_rx_starttimer(struct bcm_op *op)
551 if (op->flags & RX_NO_AUTOTIMER)
554 if (op->kt_ival1)
555 hrtimer_start(&op->timer, op->kt_ival1, HRTIMER_MODE_REL_SOFT);
561 struct bcm_op *op = container_of(hrtimer, struct bcm_op, timer);
565 if ((op->flags & RX_ANNOUNCE_RESUME) && op->last_frames) {
567 memset(op->last_frames, 0, op->nframes * op->cfsiz);
573 msg_head.flags = op->flags;
574 msg_head.count = op->count;
575 msg_head.ival1 = op->ival1;
576 msg_head.ival2 = op->ival2;
577 msg_head.can_id = op->can_id;
580 bcm_send_to_user(op, &msg_head, NULL, 0);
588 static inline int bcm_rx_do_flush(struct bcm_op *op, unsigned int index)
590 struct canfd_frame *lcf = op->last_frames + op->cfsiz * index;
592 if ((op->last_frames) && (lcf->flags & RX_THR)) {
593 bcm_rx_changed(op, lcf);
602 static int bcm_rx_thr_flush(struct bcm_op *op)
606 if (op->nframes > 1) {
610 for (i = 1; i < op->nframes; i++)
611 updated += bcm_rx_do_flush(op, i);
615 updated += bcm_rx_do_flush(op, 0);
627 struct bcm_op *op = container_of(hrtimer, struct bcm_op, thrtimer);
629 if (bcm_rx_thr_flush(op)) {
630 hrtimer_forward(hrtimer, ktime_get(), op->kt_ival2);
634 op->kt_lastmsg = 0;
644 struct bcm_op *op = (struct bcm_op *)data;
648 if (op->can_id != rxframe->can_id)
652 if (skb->len != op->cfsiz)
656 hrtimer_cancel(&op->timer);
659 op->rx_stamp = skb->tstamp;
661 op->rx_ifindex = skb->dev->ifindex;
663 op->frames_abs++;
665 if (op->flags & RX_RTR_FRAME) {
666 /* send reply for RTR-request (placed in op->frames[0]) */
667 bcm_can_tx(op);
671 if (op->flags & RX_FILTER_ID) {
673 bcm_rx_update_and_send(op, op->last_frames, rxframe);
677 if (op->nframes == 1) {
679 bcm_rx_cmp_to_index(op, 0, rxframe);
683 if (op->nframes > 1) {
692 for (i = 1; i < op->nframes; i++) {
693 if ((get_u64(op->frames, 0) & get_u64(rxframe, 0)) ==
694 (get_u64(op->frames, 0) &
695 get_u64(op->frames + op->cfsiz * i, 0))) {
696 bcm_rx_cmp_to_index(op, i, rxframe);
703 bcm_rx_starttimer(op);
707 * helpers for bcm_op handling: find & delete bcm [rx|tx] op elements
712 struct bcm_op *op;
714 list_for_each_entry(op, ops, list) {
715 if ((op->can_id == mh->can_id) && (op->ifindex == ifindex) &&
716 (op->flags & CAN_FD_FRAME) == (mh->flags & CAN_FD_FRAME))
717 return op;
725 struct bcm_op *op = container_of(rcu_head, struct bcm_op, rcu);
727 if ((op->frames) && (op->frames != &op->sframe))
728 kfree(op->frames);
730 if ((op->last_frames) && (op->last_frames != &op->last_sframe))
731 kfree(op->last_frames);
733 kfree(op);
736 static void bcm_remove_op(struct bcm_op *op)
738 hrtimer_cancel(&op->timer);
739 hrtimer_cancel(&op->thrtimer);
741 call_rcu(&op->rcu, bcm_free_op_rcu);
744 static void bcm_rx_unreg(struct net_device *dev, struct bcm_op *op)
746 if (op->rx_reg_dev == dev) {
747 can_rx_unregister(dev_net(dev), dev, op->can_id,
748 REGMASK(op->can_id), bcm_rx_handler, op);
751 op->rx_reg_dev = NULL;
754 "mismatch %p %p\n", op->rx_reg_dev, dev);
758 * bcm_delete_rx_op - find and remove a rx op (returns number of removed ops)
763 struct bcm_op *op, *n;
765 list_for_each_entry_safe(op, n, ops, list) {
766 if ((op->can_id == mh->can_id) && (op->ifindex == ifindex) &&
767 (op->flags & CAN_FD_FRAME) == (mh->flags & CAN_FD_FRAME)) {
770 op->flags |= RX_NO_AUTOTIMER;
777 if (op->ifindex) {
783 if (op->rx_reg_dev) {
786 dev = dev_get_by_index(sock_net(op->sk),
787 op->ifindex);
789 bcm_rx_unreg(dev, op);
794 can_rx_unregister(sock_net(op->sk), NULL,
795 op->can_id,
796 REGMASK(op->can_id),
797 bcm_rx_handler, op);
799 list_del(&op->list);
800 bcm_remove_op(op);
809 * bcm_delete_tx_op - find and remove a tx op (returns number of removed ops)
814 struct bcm_op *op, *n;
816 list_for_each_entry_safe(op, n, ops, list) {
817 if ((op->can_id == mh->can_id) && (op->ifindex == ifindex) &&
818 (op->flags & CAN_FD_FRAME) == (mh->flags & CAN_FD_FRAME)) {
819 list_del(&op->list);
820 bcm_remove_op(op);
834 struct bcm_op *op = bcm_find_op(ops, msg_head, ifindex);
836 if (!op)
840 msg_head->flags = op->flags;
841 msg_head->count = op->count;
842 msg_head->ival1 = op->ival1;
843 msg_head->ival2 = op->ival2;
844 msg_head->nframes = op->nframes;
846 bcm_send_to_user(op, msg_head, op->frames, 0);
852 * bcm_tx_setup - create or update a bcm tx op (for bcm_sendmsg)
858 struct bcm_op *op;
876 op = bcm_find_op(&bo->tx_ops, msg_head, ifindex);
877 if (op) {
885 if (msg_head->nframes > op->nframes)
891 cf = op->frames + op->cfsiz * i;
892 err = memcpy_from_msg((u8 *)cf, msg, op->cfsiz);
894 if (op->flags & CAN_FD_FRAME) {
910 op->flags = msg_head->flags;
915 op = kzalloc(OPSIZ, GFP_KERNEL);
916 if (!op)
919 op->can_id = msg_head->can_id;
920 op->cfsiz = CFSIZ(msg_head->flags);
921 op->flags = msg_head->flags;
925 op->frames = kmalloc_array(msg_head->nframes,
926 op->cfsiz,
928 if (!op->frames) {
929 kfree(op);
933 op->frames = &op->sframe;
937 cf = op->frames + op->cfsiz * i;
938 err = memcpy_from_msg((u8 *)cf, msg, op->cfsiz);
942 if (op->flags & CAN_FD_FRAME) {
960 op->last_frames = NULL;
963 op->sk = sk;
964 op->ifindex = ifindex;
967 hrtimer_init(&op->timer, CLOCK_MONOTONIC,
969 op->timer.function = bcm_tx_timeout_handler;
972 hrtimer_init(&op->thrtimer, CLOCK_MONOTONIC,
976 list_add(&op->list, &bo->tx_ops);
978 } /* if ((op = bcm_find_op(&bo->tx_ops, msg_head->can_id, ifindex))) */
980 if (op->nframes != msg_head->nframes) {
981 op->nframes = msg_head->nframes;
983 op->currframe = 0;
988 if (op->flags & TX_RESET_MULTI_IDX) {
990 op->currframe = 0;
993 if (op->flags & SETTIMER) {
995 op->count = msg_head->count;
996 op->ival1 = msg_head->ival1;
997 op->ival2 = msg_head->ival2;
998 op->kt_ival1 = bcm_timeval_to_ktime(msg_head->ival1);
999 op->kt_ival2 = bcm_timeval_to_ktime(msg_head->ival2);
1002 if (!op->kt_ival1 && !op->kt_ival2)
1003 hrtimer_cancel(&op->timer);
1006 if (op->flags & STARTTIMER) {
1007 hrtimer_cancel(&op->timer);
1009 op->flags |= TX_ANNOUNCE;
1012 if (op->flags & TX_ANNOUNCE) {
1013 bcm_can_tx(op);
1014 if (op->count)
1015 op->count--;
1018 if (op->flags & STARTTIMER)
1019 bcm_tx_start_timer(op);
1021 return msg_head->nframes * op->cfsiz + MHSIZ;
1024 if (op->frames != &op->sframe)
1025 kfree(op->frames);
1026 kfree(op);
1031 * bcm_rx_setup - create or update a bcm rx op (for bcm_sendmsg)
1037 struct bcm_op *op;
1062 op = bcm_find_op(&bo->rx_ops, msg_head, ifindex);
1063 if (op) {
1071 if (msg_head->nframes > op->nframes)
1076 err = memcpy_from_msg(op->frames, msg,
1077 msg_head->nframes * op->cfsiz);
1082 memset(op->last_frames, 0, msg_head->nframes * op->cfsiz);
1085 op->nframes = msg_head->nframes;
1086 op->flags = msg_head->flags;
1093 op = kzalloc(OPSIZ, GFP_KERNEL);
1094 if (!op)
1097 op->can_id = msg_head->can_id;
1098 op->nframes = msg_head->nframes;
1099 op->cfsiz = CFSIZ(msg_head->flags);
1100 op->flags = msg_head->flags;
1104 op->frames = kmalloc_array(msg_head->nframes,
1105 op->cfsiz,
1107 if (!op->frames) {
1108 kfree(op);
1113 op->last_frames = kcalloc(msg_head->nframes,
1114 op->cfsiz,
1116 if (!op->last_frames) {
1117 kfree(op->frames);
1118 kfree(op);
1123 op->frames = &op->sframe;
1124 op->last_frames = &op->last_sframe;
1128 err = memcpy_from_msg(op->frames, msg,
1129 msg_head->nframes * op->cfsiz);
1131 if (op->frames != &op->sframe)
1132 kfree(op->frames);
1133 if (op->last_frames != &op->last_sframe)
1134 kfree(op->last_frames);
1135 kfree(op);
1141 op->sk = sk;
1142 op->ifindex = ifindex;
1145 op->rx_ifindex = ifindex;
1148 hrtimer_init(&op->timer, CLOCK_MONOTONIC,
1150 op->timer.function = bcm_rx_timeout_handler;
1152 hrtimer_init(&op->thrtimer, CLOCK_MONOTONIC,
1154 op->thrtimer.function = bcm_rx_thr_handler;
1157 list_add(&op->list, &bo->rx_ops);
1162 } /* if ((op = bcm_find_op(&bo->rx_ops, msg_head->can_id, ifindex))) */
1166 if (op->flags & RX_RTR_FRAME) {
1167 struct canfd_frame *frame0 = op->frames;
1170 hrtimer_cancel(&op->thrtimer);
1171 hrtimer_cancel(&op->timer);
1178 if ((op->flags & TX_CP_CAN_ID) ||
1179 (frame0->can_id == op->can_id))
1180 frame0->can_id = op->can_id & ~CAN_RTR_FLAG;
1183 if (op->flags & SETTIMER) {
1186 op->ival1 = msg_head->ival1;
1187 op->ival2 = msg_head->ival2;
1188 op->kt_ival1 = bcm_timeval_to_ktime(msg_head->ival1);
1189 op->kt_ival2 = bcm_timeval_to_ktime(msg_head->ival2);
1192 if (!op->kt_ival1)
1193 hrtimer_cancel(&op->timer);
1199 op->kt_lastmsg = 0;
1200 hrtimer_cancel(&op->thrtimer);
1201 bcm_rx_thr_flush(op);
1204 if ((op->flags & STARTTIMER) && op->kt_ival1)
1205 hrtimer_start(&op->timer, op->kt_ival1,
1217 op->can_id,
1218 REGMASK(op->can_id),
1219 bcm_rx_handler, op,
1222 op->rx_reg_dev = dev;
1227 err = can_rx_register(sock_net(sk), NULL, op->can_id,
1228 REGMASK(op->can_id),
1229 bcm_rx_handler, op, "bcm", sk);
1231 /* this bcm rx op is broken -> remove it */
1232 list_del(&op->list);
1233 bcm_remove_op(op);
1238 return msg_head->nframes * op->cfsiz + MHSIZ;
1408 struct bcm_op *op;
1420 list_for_each_entry(op, &bo->rx_ops, list)
1421 if (op->rx_reg_dev == dev)
1422 bcm_rx_unreg(dev, op);
1507 struct bcm_op *op, *next;
1534 list_for_each_entry_safe(op, next, &bo->tx_ops, list)
1535 bcm_remove_op(op);
1537 list_for_each_entry_safe(op, next, &bo->rx_ops, list) {
1542 if (op->ifindex) {
1548 if (op->rx_reg_dev) {
1551 dev = dev_get_by_index(net, op->ifindex);
1553 bcm_rx_unreg(dev, op);
1558 can_rx_unregister(net, NULL, op->can_id,
1559 REGMASK(op->can_id),
1560 bcm_rx_handler, op);
1566 list_for_each_entry_safe(op, next, &bo->rx_ops, list)
1567 bcm_remove_op(op);