Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'linux-can-next-for-4.1-20150401' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next

Marc Kleine-Budde says:

====================
pull-request: can-next 2015-04-01

this is a pull request of 5 patches for net-next/master.

There are two patches for the ems_usb driver by Gerhard Uttenthaler and
me, which fix sparse endianess warnings. Oliver Hartkopp adds two
patches to improve and extend the CAN-ID filter handling on RAW CAN
sockets. The last patch is by me, it silences an uninitialized variable
warning in the peak_usb driver.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+74 -10
+18 -2
Documentation/networking/can.txt
··· 22 22 4.1.3 RAW socket option CAN_RAW_LOOPBACK 23 23 4.1.4 RAW socket option CAN_RAW_RECV_OWN_MSGS 24 24 4.1.5 RAW socket option CAN_RAW_FD_FRAMES 25 - 4.1.6 RAW socket returned message flags 25 + 4.1.6 RAW socket option CAN_RAW_JOIN_FILTERS 26 + 4.1.7 RAW socket returned message flags 26 27 4.2 Broadcast Manager protocol sockets (SOCK_DGRAM) 27 28 4.2.1 Broadcast Manager operations 28 29 4.2.2 Broadcast Manager message flags ··· 602 601 CAN FD frames by checking if the device maximum transfer unit is CANFD_MTU. 603 602 The CAN device MTU can be retrieved e.g. with a SIOCGIFMTU ioctl() syscall. 604 603 605 - 4.1.6 RAW socket returned message flags 604 + 4.1.6 RAW socket option CAN_RAW_JOIN_FILTERS 605 + 606 + The CAN_RAW socket can set multiple CAN identifier specific filters that 607 + lead to multiple filters in the af_can.c filter processing. These filters 608 + are indenpendent from each other which leads to logical OR'ed filters when 609 + applied (see 4.1.1). 610 + 611 + This socket option joines the given CAN filters in the way that only CAN 612 + frames are passed to user space that matched *all* given CAN filters. The 613 + semantic for the applied filters is therefore changed to a logical AND. 614 + 615 + This is useful especially when the filterset is a combination of filters 616 + where the CAN_INV_FILTER flag is set in order to notch single CAN IDs or 617 + CAN ID ranges from the incoming traffic. 618 + 619 + 4.1.7 RAW socket returned message flags 606 620 607 621 When using recvmsg() call, the msg->msg_flags may contain following flags: 608 622
+4 -7
drivers/net/can/usb/ems_usb.c
··· 123 123 * CPC_MSG_TYPE_EXT_CAN_FRAME or CPC_MSG_TYPE_EXT_RTR_FRAME. 124 124 */ 125 125 struct cpc_can_msg { 126 - u32 id; 126 + __le32 id; 127 127 u8 length; 128 128 u8 msg[8]; 129 129 }; ··· 200 200 u8 type; /* type of message */ 201 201 u8 length; /* length of data within union 'msg' */ 202 202 u8 msgid; /* confirmation handle */ 203 - u32 ts_sec; /* timestamp in seconds */ 204 - u32 ts_nsec; /* timestamp in nano seconds */ 203 + __le32 ts_sec; /* timestamp in seconds */ 204 + __le32 ts_nsec; /* timestamp in nano seconds */ 205 205 206 206 union { 207 207 u8 generic[64]; ··· 765 765 766 766 msg = (struct ems_cpc_msg *)&buf[CPC_HEADER_SIZE]; 767 767 768 - msg->msg.can_msg.id = cf->can_id & CAN_ERR_MASK; 768 + msg->msg.can_msg.id = cpu_to_le32(cf->can_id & CAN_ERR_MASK); 769 769 msg->msg.can_msg.length = cf->can_dlc; 770 770 771 771 if (cf->can_id & CAN_RTR_FLAG) { ··· 782 782 783 783 msg->length = CPC_CAN_MSG_MIN_SIZE + cf->can_dlc; 784 784 } 785 - 786 - /* Respect byte order */ 787 - msg->msg.can_msg.id = cpu_to_le32(msg->msg.can_msg.id); 788 785 789 786 for (i = 0; i < MAX_TX_URBS; i++) { 790 787 if (dev->tx_contexts[i].echo_index == MAX_TX_URBS) {
+1 -1
drivers/net/can/usb/peak_usb/pcan_usb_fd.c
··· 182 182 static int pcan_usb_fd_send_cmd(struct peak_usb_device *dev, void *cmd_tail) 183 183 { 184 184 void *cmd_head = pcan_usb_fd_cmd_buffer(dev); 185 - int err; 185 + int err = 0; 186 186 u8 *packet_ptr; 187 187 int i, n = 1, packet_len; 188 188 ptrdiff_t cmd_len;
+1
include/uapi/linux/can/raw.h
··· 57 57 CAN_RAW_LOOPBACK, /* local loopback (default:on) */ 58 58 CAN_RAW_RECV_OWN_MSGS, /* receive my own msgs (default:off) */ 59 59 CAN_RAW_FD_FRAMES, /* allow CAN FD frames (default:off) */ 60 + CAN_RAW_JOIN_FILTERS, /* all filters must match to trigger */ 60 61 }; 61 62 62 63 #endif /* !_UAPI_CAN_RAW_H */
+50
net/can/raw.c
··· 74 74 * storing the single filter in dfilter, to avoid using dynamic memory. 75 75 */ 76 76 77 + struct uniqframe { 78 + ktime_t tstamp; 79 + const struct sk_buff *skb; 80 + unsigned int join_rx_count; 81 + }; 82 + 77 83 struct raw_sock { 78 84 struct sock sk; 79 85 int bound; ··· 88 82 int loopback; 89 83 int recv_own_msgs; 90 84 int fd_frames; 85 + int join_filters; 91 86 int count; /* number of active filters */ 92 87 struct can_filter dfilter; /* default/single filter */ 93 88 struct can_filter *filter; /* pointer to filter(s) */ 94 89 can_err_mask_t err_mask; 90 + struct uniqframe __percpu *uniq; 95 91 }; 96 92 97 93 /* ··· 130 122 /* do not pass non-CAN2.0 frames to a legacy socket */ 131 123 if (!ro->fd_frames && oskb->len != CAN_MTU) 132 124 return; 125 + 126 + /* eliminate multiple filter matches for the same skb */ 127 + if (this_cpu_ptr(ro->uniq)->skb == oskb && 128 + ktime_equal(this_cpu_ptr(ro->uniq)->tstamp, oskb->tstamp)) { 129 + if (ro->join_filters) { 130 + this_cpu_inc(ro->uniq->join_rx_count); 131 + /* drop frame until all enabled filters matched */ 132 + if (this_cpu_ptr(ro->uniq)->join_rx_count < ro->count) 133 + return; 134 + } else { 135 + return; 136 + } 137 + } else { 138 + this_cpu_ptr(ro->uniq)->skb = oskb; 139 + this_cpu_ptr(ro->uniq)->tstamp = oskb->tstamp; 140 + this_cpu_ptr(ro->uniq)->join_rx_count = 1; 141 + /* drop first frame to check all enabled filters? */ 142 + if (ro->join_filters && ro->count > 1) 143 + return; 144 + } 133 145 134 146 /* clone the given skb to be able to enqueue it into the rcv queue */ 135 147 skb = skb_clone(oskb, GFP_ATOMIC); ··· 324 296 ro->loopback = 1; 325 297 ro->recv_own_msgs = 0; 326 298 ro->fd_frames = 0; 299 + ro->join_filters = 0; 300 + 301 + /* alloc_percpu provides zero'ed memory */ 302 + ro->uniq = alloc_percpu(struct uniqframe); 303 + if (unlikely(!ro->uniq)) 304 + return -ENOMEM; 327 305 328 306 /* set notifier */ 329 307 ro->notifier.notifier_call = raw_notifier; ··· 373 339 ro->ifindex = 0; 374 340 ro->bound = 0; 375 341 ro->count = 0; 342 + free_percpu(ro->uniq); 376 343 377 344 sock_orphan(sk); 378 345 sock->sk = NULL; ··· 618 583 619 584 break; 620 585 586 + case CAN_RAW_JOIN_FILTERS: 587 + if (optlen != sizeof(ro->join_filters)) 588 + return -EINVAL; 589 + 590 + if (copy_from_user(&ro->join_filters, optval, optlen)) 591 + return -EFAULT; 592 + 593 + break; 594 + 621 595 default: 622 596 return -ENOPROTOOPT; 623 597 } ··· 689 645 if (len > sizeof(int)) 690 646 len = sizeof(int); 691 647 val = &ro->fd_frames; 648 + break; 649 + 650 + case CAN_RAW_JOIN_FILTERS: 651 + if (len > sizeof(int)) 652 + len = sizeof(int); 653 + val = &ro->join_filters; 692 654 break; 693 655 694 656 default: