Lines Matching refs:op
213 struct bcm_op *op;
224 list_for_each_entry_rcu(op, &bo->rx_ops, list) {
229 if (!op->frames_abs)
232 seq_printf(m, "rx_op: %03X %-5s ", op->can_id,
233 bcm_proc_getifname(net, ifname, op->ifindex));
235 if (op->flags & CAN_FD_FRAME)
236 seq_printf(m, "(%u)", op->nframes);
238 seq_printf(m, "[%u]", op->nframes);
240 seq_printf(m, "%c ", (op->flags & RX_CHECK_DLC) ? 'd' : ' ');
242 if (op->kt_ival1)
244 (long long)ktime_to_us(op->kt_ival1));
246 if (op->kt_ival2)
248 (long long)ktime_to_us(op->kt_ival2));
251 op->frames_filtered, op->frames_abs);
253 reduction = 100 - (op->frames_filtered * 100) / op->frames_abs;
259 list_for_each_entry(op, &bo->tx_ops, list) {
261 seq_printf(m, "tx_op: %03X %s ", op->can_id,
262 bcm_proc_getifname(net, ifname, op->ifindex));
264 if (op->flags & CAN_FD_FRAME)
265 seq_printf(m, "(%u) ", op->nframes);
267 seq_printf(m, "[%u] ", op->nframes);
269 if (op->kt_ival1)
271 (long long)ktime_to_us(op->kt_ival1));
273 if (op->kt_ival2)
275 (long long)ktime_to_us(op->kt_ival2));
277 seq_printf(m, "# sent %ld\n", op->frames_abs);
289 * of the given bcm tx op
291 static void bcm_can_tx(struct bcm_op *op)
299 if (!op->ifindex)
303 spin_lock_bh(&op->bcm_tx_lock);
304 cf = op->frames + op->cfsiz * op->currframe;
305 spin_unlock_bh(&op->bcm_tx_lock);
307 dev = dev_get_by_index(sock_net(op->sk), op->ifindex);
313 skb = alloc_skb(op->cfsiz + sizeof(struct can_skb_priv), gfp_any());
321 skb_put_data(skb, cf, op->cfsiz);
325 can_skb_set_owner(skb, op->sk);
329 spin_lock_bh(&op->bcm_tx_lock);
332 op->frames_abs++;
334 op->currframe++;
337 if (op->currframe >= op->nframes)
338 op->currframe = 0;
340 if (op->count > 0)
341 op->count--;
343 spin_unlock_bh(&op->bcm_tx_lock);
352 static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head,
358 struct sock *sk = op->sk;
359 unsigned int datalen = head->nframes * op->cfsiz;
402 skb->tstamp = op->rx_stamp;
415 addr->can_ifindex = op->rx_ifindex;
427 static bool bcm_tx_set_expiry(struct bcm_op *op, struct hrtimer *hrt)
431 if (op->kt_ival1 && op->count)
432 ival = op->kt_ival1;
433 else if (op->kt_ival2)
434 ival = op->kt_ival2;
442 static void bcm_tx_start_timer(struct bcm_op *op)
444 if (bcm_tx_set_expiry(op, &op->timer))
445 hrtimer_start_expires(&op->timer, HRTIMER_MODE_ABS_SOFT);
451 struct bcm_op *op = container_of(hrtimer, struct bcm_op, timer);
454 if (op->kt_ival1 && (op->count > 0)) {
455 bcm_can_tx(op);
456 if (!op->count && (op->flags & TX_COUNTEVT)) {
461 msg_head.flags = op->flags;
462 msg_head.count = op->count;
463 msg_head.ival1 = op->ival1;
464 msg_head.ival2 = op->ival2;
465 msg_head.can_id = op->can_id;
468 bcm_send_to_user(op, &msg_head, NULL, 0);
471 } else if (op->kt_ival2) {
472 bcm_can_tx(op);
475 return bcm_tx_set_expiry(op, &op->timer) ?
482 static void bcm_rx_changed(struct bcm_op *op, struct canfd_frame *data)
487 op->frames_filtered++;
490 if (op->frames_filtered > ULONG_MAX/100)
491 op->frames_filtered = op->frames_abs = 0;
498 head.flags = op->flags;
499 head.count = op->count;
500 head.ival1 = op->ival1;
501 head.ival2 = op->ival2;
502 head.can_id = op->can_id;
505 bcm_send_to_user(op, &head, data, 1);
513 static void bcm_rx_update_and_send(struct bcm_op *op,
518 memcpy(lastdata, rxdata, op->cfsiz);
527 if (!op->kt_ival2) {
529 bcm_rx_changed(op, lastdata);
534 if (hrtimer_active(&op->thrtimer))
538 if (!op->kt_lastmsg)
542 if (ktime_us_delta(ktime_get(), op->kt_lastmsg) <
543 ktime_to_us(op->kt_ival2)) {
545 hrtimer_start(&op->thrtimer,
546 ktime_add(op->kt_lastmsg, op->kt_ival2),
553 bcm_rx_changed(op, lastdata);
554 op->kt_lastmsg = ktime_get();
559 * received data stored in op->last_frames[]
561 static void bcm_rx_cmp_to_index(struct bcm_op *op, unsigned int index,
565 struct canfd_frame *cf = op->frames + op->cfsiz * index;
566 struct canfd_frame *lcf = op->last_frames + op->cfsiz * index;
576 bcm_rx_update_and_send(op, lcf, rxdata, traffic_flags);
584 bcm_rx_update_and_send(op, lcf, rxdata, traffic_flags);
589 if (op->flags & RX_CHECK_DLC) {
592 bcm_rx_update_and_send(op, lcf, rxdata, traffic_flags);
601 static void bcm_rx_starttimer(struct bcm_op *op)
603 if (op->flags & RX_NO_AUTOTIMER)
606 if (op->kt_ival1)
607 hrtimer_start(&op->timer, op->kt_ival1, HRTIMER_MODE_REL_SOFT);
613 struct bcm_op *op = container_of(hrtimer, struct bcm_op, timer);
617 if ((op->flags & RX_ANNOUNCE_RESUME) && op->last_frames) {
619 memset(op->last_frames, 0, op->nframes * op->cfsiz);
625 msg_head.flags = op->flags;
626 msg_head.count = op->count;
627 msg_head.ival1 = op->ival1;
628 msg_head.ival2 = op->ival2;
629 msg_head.can_id = op->can_id;
632 bcm_send_to_user(op, &msg_head, NULL, 0);
640 static inline int bcm_rx_do_flush(struct bcm_op *op, unsigned int index)
642 struct canfd_frame *lcf = op->last_frames + op->cfsiz * index;
644 if ((op->last_frames) && (lcf->flags & RX_THR)) {
645 bcm_rx_changed(op, lcf);
654 static int bcm_rx_thr_flush(struct bcm_op *op)
658 if (op->nframes > 1) {
662 for (i = 1; i < op->nframes; i++)
663 updated += bcm_rx_do_flush(op, i);
667 updated += bcm_rx_do_flush(op, 0);
679 struct bcm_op *op = container_of(hrtimer, struct bcm_op, thrtimer);
681 if (bcm_rx_thr_flush(op)) {
682 hrtimer_forward_now(hrtimer, op->kt_ival2);
686 op->kt_lastmsg = 0;
696 struct bcm_op *op = (struct bcm_op *)data;
701 if (op->can_id != rxframe->can_id)
705 if (op->flags & CAN_FD_FRAME) {
714 hrtimer_cancel(&op->timer);
717 op->rx_stamp = skb->tstamp;
719 op->rx_ifindex = skb->dev->ifindex;
721 op->frames_abs++;
723 if (op->flags & RX_RTR_FRAME) {
724 /* send reply for RTR-request (placed in op->frames[0]) */
725 bcm_can_tx(op);
733 if (skb->sk == op->sk)
737 if (op->flags & RX_FILTER_ID) {
739 bcm_rx_update_and_send(op, op->last_frames, rxframe,
744 if (op->nframes == 1) {
746 bcm_rx_cmp_to_index(op, 0, rxframe, traffic_flags);
750 if (op->nframes > 1) {
759 for (i = 1; i < op->nframes; i++) {
760 if ((get_u64(op->frames, 0) & get_u64(rxframe, 0)) ==
761 (get_u64(op->frames, 0) &
762 get_u64(op->frames + op->cfsiz * i, 0))) {
763 bcm_rx_cmp_to_index(op, i, rxframe,
771 bcm_rx_starttimer(op);
775 * helpers for bcm_op handling: find & delete bcm [rx|tx] op elements
780 struct bcm_op *op;
782 list_for_each_entry(op, ops, list) {
783 if ((op->can_id == mh->can_id) && (op->ifindex == ifindex) &&
784 (op->flags & CAN_FD_FRAME) == (mh->flags & CAN_FD_FRAME))
785 return op;
793 struct bcm_op *op = container_of(rcu_head, struct bcm_op, rcu);
795 if ((op->frames) && (op->frames != &op->sframe))
796 kfree(op->frames);
798 if ((op->last_frames) && (op->last_frames != &op->last_sframe))
799 kfree(op->last_frames);
801 kfree(op);
804 static void bcm_remove_op(struct bcm_op *op)
806 hrtimer_cancel(&op->timer);
807 hrtimer_cancel(&op->thrtimer);
809 call_rcu(&op->rcu, bcm_free_op_rcu);
812 static void bcm_rx_unreg(struct net_device *dev, struct bcm_op *op)
814 if (op->rx_reg_dev == dev) {
815 can_rx_unregister(dev_net(dev), dev, op->can_id,
816 REGMASK(op->can_id), bcm_rx_handler, op);
819 op->rx_reg_dev = NULL;
822 "mismatch %p %p\n", op->rx_reg_dev, dev);
826 * bcm_delete_rx_op - find and remove a rx op (returns number of removed ops)
831 struct bcm_op *op, *n;
833 list_for_each_entry_safe(op, n, ops, list) {
834 if ((op->can_id == mh->can_id) && (op->ifindex == ifindex) &&
835 (op->flags & CAN_FD_FRAME) == (mh->flags & CAN_FD_FRAME)) {
838 op->flags |= RX_NO_AUTOTIMER;
845 if (op->ifindex) {
851 if (op->rx_reg_dev) {
854 dev = dev_get_by_index(sock_net(op->sk),
855 op->ifindex);
857 bcm_rx_unreg(dev, op);
862 can_rx_unregister(sock_net(op->sk), NULL,
863 op->can_id,
864 REGMASK(op->can_id),
865 bcm_rx_handler, op);
867 list_del_rcu(&op->list);
868 bcm_remove_op(op);
877 * bcm_delete_tx_op - find and remove a tx op (returns number of removed ops)
882 struct bcm_op *op, *n;
884 list_for_each_entry_safe(op, n, ops, list) {
885 if ((op->can_id == mh->can_id) && (op->ifindex == ifindex) &&
886 (op->flags & CAN_FD_FRAME) == (mh->flags & CAN_FD_FRAME)) {
887 list_del_rcu(&op->list);
888 bcm_remove_op(op);
902 struct bcm_op *op = bcm_find_op(ops, msg_head, ifindex);
904 if (!op)
908 msg_head->flags = op->flags;
909 msg_head->count = op->count;
910 msg_head->ival1 = op->ival1;
911 msg_head->ival2 = op->ival2;
912 msg_head->nframes = op->nframes;
914 bcm_send_to_user(op, msg_head, op->frames, 0);
920 * bcm_tx_setup - create or update a bcm tx op (for bcm_sendmsg)
926 struct bcm_op *op;
944 op = bcm_find_op(&bo->tx_ops, msg_head, ifindex);
945 if (op) {
953 if (msg_head->nframes > op->nframes)
959 cf = op->frames + op->cfsiz * i;
960 err = memcpy_from_msg((u8 *)cf, msg, op->cfsiz);
962 if (op->flags & CAN_FD_FRAME) {
978 op->flags = msg_head->flags;
981 if (op->nframes != msg_head->nframes ||
982 op->flags & TX_RESET_MULTI_IDX ||
983 op->flags & SETTIMER) {
985 spin_lock_bh(&op->bcm_tx_lock);
987 if (op->nframes != msg_head->nframes ||
988 op->flags & TX_RESET_MULTI_IDX) {
990 op->nframes = msg_head->nframes;
992 op->currframe = 0;
995 if (op->flags & SETTIMER)
996 op->count = msg_head->count;
998 spin_unlock_bh(&op->bcm_tx_lock);
1004 op = kzalloc(OPSIZ, GFP_KERNEL);
1005 if (!op)
1008 spin_lock_init(&op->bcm_tx_lock);
1009 op->can_id = msg_head->can_id;
1010 op->cfsiz = CFSIZ(msg_head->flags);
1011 op->flags = msg_head->flags;
1012 op->nframes = msg_head->nframes;
1014 if (op->flags & SETTIMER)
1015 op->count = msg_head->count;
1019 op->frames = kmalloc_array(msg_head->nframes,
1020 op->cfsiz,
1022 if (!op->frames) {
1023 kfree(op);
1027 op->frames = &op->sframe;
1031 cf = op->frames + op->cfsiz * i;
1032 err = memcpy_from_msg((u8 *)cf, msg, op->cfsiz);
1036 if (op->flags & CAN_FD_FRAME) {
1054 op->last_frames = NULL;
1057 op->sk = sk;
1058 op->ifindex = ifindex;
1061 hrtimer_setup(&op->timer, bcm_tx_timeout_handler, CLOCK_MONOTONIC,
1065 hrtimer_setup(&op->thrtimer, hrtimer_dummy_timeout, CLOCK_MONOTONIC,
1069 list_add(&op->list, &bo->tx_ops);
1071 } /* if ((op = bcm_find_op(&bo->tx_ops, msg_head->can_id, ifindex))) */
1073 if (op->flags & SETTIMER) {
1075 op->ival1 = msg_head->ival1;
1076 op->ival2 = msg_head->ival2;
1077 op->kt_ival1 = bcm_timeval_to_ktime(msg_head->ival1);
1078 op->kt_ival2 = bcm_timeval_to_ktime(msg_head->ival2);
1081 if (!op->kt_ival1 && !op->kt_ival2)
1082 hrtimer_cancel(&op->timer);
1085 if (op->flags & STARTTIMER) {
1086 hrtimer_cancel(&op->timer);
1088 op->flags |= TX_ANNOUNCE;
1091 if (op->flags & TX_ANNOUNCE)
1092 bcm_can_tx(op);
1094 if (op->flags & STARTTIMER)
1095 bcm_tx_start_timer(op);
1097 return msg_head->nframes * op->cfsiz + MHSIZ;
1100 if (op->frames != &op->sframe)
1101 kfree(op->frames);
1102 kfree(op);
1107 * bcm_rx_setup - create or update a bcm rx op (for bcm_sendmsg)
1113 struct bcm_op *op;
1138 op = bcm_find_op(&bo->rx_ops, msg_head, ifindex);
1139 if (op) {
1147 if (msg_head->nframes > op->nframes)
1152 err = memcpy_from_msg(op->frames, msg,
1153 msg_head->nframes * op->cfsiz);
1158 memset(op->last_frames, 0, msg_head->nframes * op->cfsiz);
1161 op->nframes = msg_head->nframes;
1162 op->flags = msg_head->flags;
1169 op = kzalloc(OPSIZ, GFP_KERNEL);
1170 if (!op)
1173 op->can_id = msg_head->can_id;
1174 op->nframes = msg_head->nframes;
1175 op->cfsiz = CFSIZ(msg_head->flags);
1176 op->flags = msg_head->flags;
1180 op->frames = kmalloc_array(msg_head->nframes,
1181 op->cfsiz,
1183 if (!op->frames) {
1184 kfree(op);
1189 op->last_frames = kcalloc(msg_head->nframes,
1190 op->cfsiz,
1192 if (!op->last_frames) {
1193 kfree(op->frames);
1194 kfree(op);
1199 op->frames = &op->sframe;
1200 op->last_frames = &op->last_sframe;
1204 err = memcpy_from_msg(op->frames, msg,
1205 msg_head->nframes * op->cfsiz);
1207 if (op->frames != &op->sframe)
1208 kfree(op->frames);
1209 if (op->last_frames != &op->last_sframe)
1210 kfree(op->last_frames);
1211 kfree(op);
1217 op->sk = sk;
1218 op->ifindex = ifindex;
1221 op->rx_ifindex = ifindex;
1224 hrtimer_setup(&op->timer, bcm_rx_timeout_handler, CLOCK_MONOTONIC,
1226 hrtimer_setup(&op->thrtimer, bcm_rx_thr_handler, CLOCK_MONOTONIC,
1230 list_add(&op->list, &bo->rx_ops);
1235 } /* if ((op = bcm_find_op(&bo->rx_ops, msg_head->can_id, ifindex))) */
1239 if (op->flags & RX_RTR_FRAME) {
1240 struct canfd_frame *frame0 = op->frames;
1243 hrtimer_cancel(&op->thrtimer);
1244 hrtimer_cancel(&op->timer);
1251 if ((op->flags & TX_CP_CAN_ID) ||
1252 (frame0->can_id == op->can_id))
1253 frame0->can_id = op->can_id & ~CAN_RTR_FLAG;
1256 if (op->flags & SETTIMER) {
1259 op->ival1 = msg_head->ival1;
1260 op->ival2 = msg_head->ival2;
1261 op->kt_ival1 = bcm_timeval_to_ktime(msg_head->ival1);
1262 op->kt_ival2 = bcm_timeval_to_ktime(msg_head->ival2);
1265 if (!op->kt_ival1)
1266 hrtimer_cancel(&op->timer);
1272 op->kt_lastmsg = 0;
1273 hrtimer_cancel(&op->thrtimer);
1274 bcm_rx_thr_flush(op);
1277 if ((op->flags & STARTTIMER) && op->kt_ival1)
1278 hrtimer_start(&op->timer, op->kt_ival1,
1290 op->can_id,
1291 REGMASK(op->can_id),
1292 bcm_rx_handler, op,
1295 op->rx_reg_dev = dev;
1300 err = can_rx_register(sock_net(sk), NULL, op->can_id,
1301 REGMASK(op->can_id),
1302 bcm_rx_handler, op, "bcm", sk);
1304 /* this bcm rx op is broken -> remove it */
1305 list_del_rcu(&op->list);
1306 bcm_remove_op(op);
1311 return msg_head->nframes * op->cfsiz + MHSIZ;
1481 struct bcm_op *op;
1493 list_for_each_entry(op, &bo->rx_ops, list)
1494 if (op->rx_reg_dev == dev)
1495 bcm_rx_unreg(dev, op);
1582 struct bcm_op *op, *next;
1609 list_for_each_entry_safe(op, next, &bo->tx_ops, list)
1610 bcm_remove_op(op);
1612 list_for_each_entry_safe(op, next, &bo->rx_ops, list) {
1617 if (op->ifindex) {
1623 if (op->rx_reg_dev) {
1626 dev = dev_get_by_index(net, op->ifindex);
1628 bcm_rx_unreg(dev, op);
1633 can_rx_unregister(net, NULL, op->can_id,
1634 REGMASK(op->can_id),
1635 bcm_rx_handler, op);
1641 list_for_each_entry_safe(op, next, &bo->rx_ops, list)
1642 bcm_remove_op(op);