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_now(hrtimer, 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 (op->flags & CAN_FD_FRAME) {
661 hrtimer_cancel(&op->timer);
664 op->rx_stamp = skb->tstamp;
666 op->rx_ifindex = skb->dev->ifindex;
668 op->frames_abs++;
670 if (op->flags & RX_RTR_FRAME) {
671 /* send reply for RTR-request (placed in op->frames[0]) */
672 bcm_can_tx(op);
676 if (op->flags & RX_FILTER_ID) {
678 bcm_rx_update_and_send(op, op->last_frames, rxframe);
682 if (op->nframes == 1) {
684 bcm_rx_cmp_to_index(op, 0, rxframe);
688 if (op->nframes > 1) {
697 for (i = 1; i < op->nframes; i++) {
698 if ((get_u64(op->frames, 0) & get_u64(rxframe, 0)) ==
699 (get_u64(op->frames, 0) &
700 get_u64(op->frames + op->cfsiz * i, 0))) {
701 bcm_rx_cmp_to_index(op, i, rxframe);
708 bcm_rx_starttimer(op);
712 * helpers for bcm_op handling: find & delete bcm [rx|tx] op elements
717 struct bcm_op *op;
719 list_for_each_entry(op, ops, list) {
720 if ((op->can_id == mh->can_id) && (op->ifindex == ifindex) &&
721 (op->flags & CAN_FD_FRAME) == (mh->flags & CAN_FD_FRAME))
722 return op;
730 struct bcm_op *op = container_of(rcu_head, struct bcm_op, rcu);
732 if ((op->frames) && (op->frames != &op->sframe))
733 kfree(op->frames);
735 if ((op->last_frames) && (op->last_frames != &op->last_sframe))
736 kfree(op->last_frames);
738 kfree(op);
741 static void bcm_remove_op(struct bcm_op *op)
743 hrtimer_cancel(&op->timer);
744 hrtimer_cancel(&op->thrtimer);
746 call_rcu(&op->rcu, bcm_free_op_rcu);
749 static void bcm_rx_unreg(struct net_device *dev, struct bcm_op *op)
751 if (op->rx_reg_dev == dev) {
752 can_rx_unregister(dev_net(dev), dev, op->can_id,
753 REGMASK(op->can_id), bcm_rx_handler, op);
756 op->rx_reg_dev = NULL;
759 "mismatch %p %p\n", op->rx_reg_dev, dev);
763 * bcm_delete_rx_op - find and remove a rx op (returns number of removed ops)
768 struct bcm_op *op, *n;
770 list_for_each_entry_safe(op, n, ops, list) {
771 if ((op->can_id == mh->can_id) && (op->ifindex == ifindex) &&
772 (op->flags & CAN_FD_FRAME) == (mh->flags & CAN_FD_FRAME)) {
775 op->flags |= RX_NO_AUTOTIMER;
782 if (op->ifindex) {
788 if (op->rx_reg_dev) {
791 dev = dev_get_by_index(sock_net(op->sk),
792 op->ifindex);
794 bcm_rx_unreg(dev, op);
799 can_rx_unregister(sock_net(op->sk), NULL,
800 op->can_id,
801 REGMASK(op->can_id),
802 bcm_rx_handler, op);
804 list_del(&op->list);
805 bcm_remove_op(op);
814 * bcm_delete_tx_op - find and remove a tx op (returns number of removed ops)
819 struct bcm_op *op, *n;
821 list_for_each_entry_safe(op, n, ops, list) {
822 if ((op->can_id == mh->can_id) && (op->ifindex == ifindex) &&
823 (op->flags & CAN_FD_FRAME) == (mh->flags & CAN_FD_FRAME)) {
824 list_del(&op->list);
825 bcm_remove_op(op);
839 struct bcm_op *op = bcm_find_op(ops, msg_head, ifindex);
841 if (!op)
845 msg_head->flags = op->flags;
846 msg_head->count = op->count;
847 msg_head->ival1 = op->ival1;
848 msg_head->ival2 = op->ival2;
849 msg_head->nframes = op->nframes;
851 bcm_send_to_user(op, msg_head, op->frames, 0);
857 * bcm_tx_setup - create or update a bcm tx op (for bcm_sendmsg)
863 struct bcm_op *op;
881 op = bcm_find_op(&bo->tx_ops, msg_head, ifindex);
882 if (op) {
890 if (msg_head->nframes > op->nframes)
896 cf = op->frames + op->cfsiz * i;
897 err = memcpy_from_msg((u8 *)cf, msg, op->cfsiz);
899 if (op->flags & CAN_FD_FRAME) {
915 op->flags = msg_head->flags;
920 op = kzalloc(OPSIZ, GFP_KERNEL);
921 if (!op)
924 op->can_id = msg_head->can_id;
925 op->cfsiz = CFSIZ(msg_head->flags);
926 op->flags = msg_head->flags;
930 op->frames = kmalloc_array(msg_head->nframes,
931 op->cfsiz,
933 if (!op->frames) {
934 kfree(op);
938 op->frames = &op->sframe;
942 cf = op->frames + op->cfsiz * i;
943 err = memcpy_from_msg((u8 *)cf, msg, op->cfsiz);
947 if (op->flags & CAN_FD_FRAME) {
965 op->last_frames = NULL;
968 op->sk = sk;
969 op->ifindex = ifindex;
972 hrtimer_init(&op->timer, CLOCK_MONOTONIC,
974 op->timer.function = bcm_tx_timeout_handler;
977 hrtimer_init(&op->thrtimer, CLOCK_MONOTONIC,
981 list_add(&op->list, &bo->tx_ops);
983 } /* if ((op = bcm_find_op(&bo->tx_ops, msg_head->can_id, ifindex))) */
985 if (op->nframes != msg_head->nframes) {
986 op->nframes = msg_head->nframes;
988 op->currframe = 0;
993 if (op->flags & TX_RESET_MULTI_IDX) {
995 op->currframe = 0;
998 if (op->flags & SETTIMER) {
1000 op->count = msg_head->count;
1001 op->ival1 = msg_head->ival1;
1002 op->ival2 = msg_head->ival2;
1003 op->kt_ival1 = bcm_timeval_to_ktime(msg_head->ival1);
1004 op->kt_ival2 = bcm_timeval_to_ktime(msg_head->ival2);
1007 if (!op->kt_ival1 && !op->kt_ival2)
1008 hrtimer_cancel(&op->timer);
1011 if (op->flags & STARTTIMER) {
1012 hrtimer_cancel(&op->timer);
1014 op->flags |= TX_ANNOUNCE;
1017 if (op->flags & TX_ANNOUNCE) {
1018 bcm_can_tx(op);
1019 if (op->count)
1020 op->count--;
1023 if (op->flags & STARTTIMER)
1024 bcm_tx_start_timer(op);
1026 return msg_head->nframes * op->cfsiz + MHSIZ;
1029 if (op->frames != &op->sframe)
1030 kfree(op->frames);
1031 kfree(op);
1036 * bcm_rx_setup - create or update a bcm rx op (for bcm_sendmsg)
1042 struct bcm_op *op;
1067 op = bcm_find_op(&bo->rx_ops, msg_head, ifindex);
1068 if (op) {
1076 if (msg_head->nframes > op->nframes)
1081 err = memcpy_from_msg(op->frames, msg,
1082 msg_head->nframes * op->cfsiz);
1087 memset(op->last_frames, 0, msg_head->nframes * op->cfsiz);
1090 op->nframes = msg_head->nframes;
1091 op->flags = msg_head->flags;
1098 op = kzalloc(OPSIZ, GFP_KERNEL);
1099 if (!op)
1102 op->can_id = msg_head->can_id;
1103 op->nframes = msg_head->nframes;
1104 op->cfsiz = CFSIZ(msg_head->flags);
1105 op->flags = msg_head->flags;
1109 op->frames = kmalloc_array(msg_head->nframes,
1110 op->cfsiz,
1112 if (!op->frames) {
1113 kfree(op);
1118 op->last_frames = kcalloc(msg_head->nframes,
1119 op->cfsiz,
1121 if (!op->last_frames) {
1122 kfree(op->frames);
1123 kfree(op);
1128 op->frames = &op->sframe;
1129 op->last_frames = &op->last_sframe;
1133 err = memcpy_from_msg(op->frames, msg,
1134 msg_head->nframes * op->cfsiz);
1136 if (op->frames != &op->sframe)
1137 kfree(op->frames);
1138 if (op->last_frames != &op->last_sframe)
1139 kfree(op->last_frames);
1140 kfree(op);
1146 op->sk = sk;
1147 op->ifindex = ifindex;
1150 op->rx_ifindex = ifindex;
1153 hrtimer_init(&op->timer, CLOCK_MONOTONIC,
1155 op->timer.function = bcm_rx_timeout_handler;
1157 hrtimer_init(&op->thrtimer, CLOCK_MONOTONIC,
1159 op->thrtimer.function = bcm_rx_thr_handler;
1162 list_add(&op->list, &bo->rx_ops);
1167 } /* if ((op = bcm_find_op(&bo->rx_ops, msg_head->can_id, ifindex))) */
1171 if (op->flags & RX_RTR_FRAME) {
1172 struct canfd_frame *frame0 = op->frames;
1175 hrtimer_cancel(&op->thrtimer);
1176 hrtimer_cancel(&op->timer);
1183 if ((op->flags & TX_CP_CAN_ID) ||
1184 (frame0->can_id == op->can_id))
1185 frame0->can_id = op->can_id & ~CAN_RTR_FLAG;
1188 if (op->flags & SETTIMER) {
1191 op->ival1 = msg_head->ival1;
1192 op->ival2 = msg_head->ival2;
1193 op->kt_ival1 = bcm_timeval_to_ktime(msg_head->ival1);
1194 op->kt_ival2 = bcm_timeval_to_ktime(msg_head->ival2);
1197 if (!op->kt_ival1)
1198 hrtimer_cancel(&op->timer);
1204 op->kt_lastmsg = 0;
1205 hrtimer_cancel(&op->thrtimer);
1206 bcm_rx_thr_flush(op);
1209 if ((op->flags & STARTTIMER) && op->kt_ival1)
1210 hrtimer_start(&op->timer, op->kt_ival1,
1222 op->can_id,
1223 REGMASK(op->can_id),
1224 bcm_rx_handler, op,
1227 op->rx_reg_dev = dev;
1232 err = can_rx_register(sock_net(sk), NULL, op->can_id,
1233 REGMASK(op->can_id),
1234 bcm_rx_handler, op, "bcm", sk);
1236 /* this bcm rx op is broken -> remove it */
1237 list_del(&op->list);
1238 bcm_remove_op(op);
1243 return msg_head->nframes * op->cfsiz + MHSIZ;
1413 struct bcm_op *op;
1425 list_for_each_entry(op, &bo->rx_ops, list)
1426 if (op->rx_reg_dev == dev)
1427 bcm_rx_unreg(dev, op);
1508 struct bcm_op *op, *next;
1535 list_for_each_entry_safe(op, next, &bo->tx_ops, list)
1536 bcm_remove_op(op);
1538 list_for_each_entry_safe(op, next, &bo->rx_ops, list) {
1543 if (op->ifindex) {
1549 if (op->rx_reg_dev) {
1552 dev = dev_get_by_index(net, op->ifindex);
1554 bcm_rx_unreg(dev, op);
1559 can_rx_unregister(net, NULL, op->can_id,
1560 REGMASK(op->can_id),
1561 bcm_rx_handler, op);
1567 list_for_each_entry_safe(op, next, &bo->rx_ops, list)
1568 bcm_remove_op(op);