From patchwork Wed Sep 28 12:50:11 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Hartkopp X-Patchwork-Id: 116786 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 9B15EB6F94 for ; Wed, 28 Sep 2011 22:50:24 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754116Ab1I1MuS (ORCPT ); Wed, 28 Sep 2011 08:50:18 -0400 Received: from mo-p00-ob.rzone.de ([81.169.146.160]:28389 "EHLO mo-p00-ob.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752396Ab1I1MuR (ORCPT ); Wed, 28 Sep 2011 08:50:17 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; t=1317214215; l=1612; s=domk; d=hartkopp.net; h=Content-Transfer-Encoding:Content-Type:Subject:CC:To:MIME-Version: From:Date:X-RZG-CLASS-ID:X-RZG-AUTH; bh=VKrpTLU6Y0RN2i0NnTlWdO1sNok=; b=YtRM+Bcj9c6c//kUpYtLxX0FJ37SX0acoMrmOBMY4Tx8/c47P+M99XJcU6gDL4DqIvE JsoW8K8hDPBJfz4Tx22IL+/gJglS7bHZTUbJYwAsQ0GZxffr+nHHqhlp3teaXA5e89JYs yrgDnQ46jEI5BVbd1+CHLPwOYvlCjaz1FyQ= X-RZG-AUTH: :P2MHfkW8eP4Mre39l357AZT/I7AY/7nT2yrT1q0ngWNsKR9Dbc7nsXB+5kzFuK2VLZ8= X-RZG-CLASS-ID: mo00 Received: from [192.168.178.36] (p5B0B0EFE.dip0.t-ipconnect.de [91.11.14.254]) by smtp.strato.de (jimi mo5) (RZmta 26.7) with ESMTPA id Y01896n8SCI2Pf ; Wed, 28 Sep 2011 14:50:11 +0200 (MEST) Message-ID: <4E831803.7020409@hartkopp.net> Date: Wed, 28 Sep 2011 14:50:11 +0200 From: Oliver Hartkopp User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.21) Gecko/20110831 Icedove/3.1.13 MIME-Version: 1.0 To: David Miller CC: Linux Netdev List , Wolfgang Grandegger , SocketCAN Core Mailing List Subject: [PATCH net-next v3] candev: allow SJW user setting for bittiming calculation Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch adds support for SJW user settings to not set the synchronization jump width (SJW) to 1 in any case when using the in-kernel bittiming calculation. The ip-tool from iproute2 already supports to pass the user defined SJW value. The given SJW value is sanitized with the controller specific sjw_max and the calculated tseg2 value. As the SJW can have values up to 4 providing this value will lead to the maximum possible SJW automatically. A higher SJW allows higher controller oscillator tolerances. Signed-off-by: Oliver Hartkopp Acked-by: Wolfgang Grandegger --- v2: Resend due to wrong mail address header encoding. v3: - Detected malformed patch format due to line break in function name - Added Acked-by: from Wolfgang Grandegger -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c index 9bf1116..25695bd 100644 --- a/drivers/net/can/dev.c +++ b/drivers/net/can/dev.c @@ -150,7 +150,19 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt) bt->prop_seg = tseg1 / 2; bt->phase_seg1 = tseg1 - bt->prop_seg; bt->phase_seg2 = tseg2; - bt->sjw = 1; + + /* check for sjw user settings */ + if (!bt->sjw || !btc->sjw_max) + bt->sjw = 1; + else { + /* bt->sjw is at least 1 -> sanitize upper bound to sjw_max */ + if (bt->sjw > btc->sjw_max) + bt->sjw = btc->sjw_max; + /* bt->sjw must not be higher than tseg2 */ + if (tseg2 < bt->sjw) + bt->sjw = tseg2; + } + bt->brp = best_brp; /* real bit-rate */ bt->bitrate = priv->clock.freq / (bt->brp * (tseg1 + tseg2 + 1));