Received: by 10.223.164.202 with SMTP id h10csp2281878wrb; Thu, 16 Nov 2017 12:26:00 -0800 (PST) X-Google-Smtp-Source: AGs4zMZxfNmm8mDix/IAts+NDeqQfkKJlIMC/UHbdttwMT6P3sybYFq9CiEeOSh4qAHr8ppvhQ63 X-Received: by 10.84.254.1 with SMTP id b1mr2797442plm.363.1510863960642; Thu, 16 Nov 2017 12:26:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510863960; cv=none; d=google.com; s=arc-20160816; b=WO0z0PQEm8eraZgHgoQPjEaXo2IMTTKx8SXCwRj5icXkvdrtbJPNDgIKJ5WsG72G3Q xfMSW/iwNAtIW6EtMfDMMZkGNU30GURvOav5UYXJDMdwFo8axA1yyIdLNYtmI3Ik/9SU 8iQH1PrSUaCz+0CEd8AQbvWwH+Z01Aow0GStoG5VJvhtRBN0zEGdls5+fmpd217U5xXM sE8AXf1TdnGwLHKtGeLVIs3u+K8k1YR20SfX9Wff4sYiOXivQ/0enDAdG2qUxRM8fBNa wDyY+TU8Omz4Mekqxw8ldNCGYycQE5m2CFkV3U7swUHYwSNzX5LjAqA1h2AG+1wYp0Zw WuQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=ImtJ2Tg0epgdPZNAN2YHbQz2ttLZdmwmLW3b4WbzkQ4=; b=Mw4wqhdd6Z4Tx5nOfG1T7e3CE1K/bR7geSvkFQ2qurM9cabyQIiUlXyRNn4N/yt8OH QiCJLF22FHpzRtYuJipmiHVyoixbc3NG8B3AvSvgVcQ2WCkMbG0SOAihfPhMYN5rRCu/ VOgL85RpBLXg9NmSRkru77/BRt39b1HEibaa2pgJP0gY8Dcfd65Kx4vle4Wt73cMCHTr ZwzRpKa6kC9VQ+PuCytxliU9M6C0ftgMqBS9UgOJ5L3aoWS0MboXAh/aI5NlQOjqnImR 3/Ie7ci+VJ0F9bPIFrTl0a+Z/MXQUvyefrD2+ZhKHKKmj1aqJT3zEhT9ZpygWW44dg/X UXsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gateworks-com.20150623.gappssmtp.com header.s=20150623 header.b=R740NPyj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x5si1393920pgb.437.2017.11.16.12.25.32; Thu, 16 Nov 2017 12:26:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gateworks-com.20150623.gappssmtp.com header.s=20150623 header.b=R740NPyj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760076AbdKPQOD (ORCPT + 91 others); Thu, 16 Nov 2017 11:14:03 -0500 Received: from mail-wr0-f182.google.com ([209.85.128.182]:52736 "EHLO mail-wr0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760059AbdKPQN4 (ORCPT ); Thu, 16 Nov 2017 11:13:56 -0500 Received: by mail-wr0-f182.google.com with SMTP id o14so4370552wrf.9 for ; Thu, 16 Nov 2017 08:13:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gateworks-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=ImtJ2Tg0epgdPZNAN2YHbQz2ttLZdmwmLW3b4WbzkQ4=; b=R740NPyjkr6jkRia4SZKFRQa2+Gh9OuCUdJ27VOslWLyvESvF6Un8cjwADlnFxpRHi f86Kkp2NtA0efDVCBQuqfL35rwRGqojctCYF0WftbeD0GBCSUQB+Xg0NYYdh1LTdVmZz zQHAUHmz8iQzeLhhp8Y3/eeTqvo+RDOvTd2exBOMqMOHD1Fu3ly71YwICF5sAN+4QAjw WqswlKamfU3epLdQMPDPzRSlbHH/xc6X47RsTWwC9NGlhyp2WE7gA64oZWCzVqpEMsii aThQqKq1M4iRCsl6p8BIEuizQG6mPfCP4cVpFnOWZt0Xtq0gCmvCmvp9NUoWXlOZZiH4 4gfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=ImtJ2Tg0epgdPZNAN2YHbQz2ttLZdmwmLW3b4WbzkQ4=; b=SkUcQqYHImhDZCgCV1cPTs0NOxmE6fh1DHKMyPiEWPMEdnGG2tzLkbfE0HneSqJikt 57LtwTPv1DMkZX/iaw8BkNvnVJRmkWnSnDV0nv0VzMK46jKbbDgidPfnLigjVWHD0eRT d+Vh0sNdTfcHuncmtkvDnLn2qC67qSBhv1fRxVvKWds2c3PmZH136bY9vl4zQPbgBkag ff53crS4v0l5q0FktAGDBIiTt+99CHJzk8saXulg6t+hBZ0WRGLZjDhYjGH2YCBp4/oW CXxoDKv5sP36S5aXf82wGvP1n1/AsmcOe4z47j7FE1U9OtiuE5dBI2ZmKcGxPDA3VdmX Df/w== X-Gm-Message-State: AJaThX78zXbdtXbuxNEYZgW6W/KdTP/M1Di2Caw0xSRp+ZJKsHRG8VvM n3SClIyRpjOxypvbmdR8L+EBtJx2/TRM+V0C0R8VCQ== X-Received: by 10.223.161.210 with SMTP id v18mr2076149wrv.76.1510848834995; Thu, 16 Nov 2017 08:13:54 -0800 (PST) MIME-Version: 1.0 Received: by 10.28.209.197 with HTTP; Thu, 16 Nov 2017 08:13:54 -0800 (PST) In-Reply-To: References: <2771c4a8-ed85-86c1-a08c-5b62d177b107@caviumnetworks.com> From: Tim Harvey Date: Thu, 16 Nov 2017 08:13:54 -0800 Message-ID: Subject: Re: MCP251x SPI CAN controller on Cavium ThunderX To: Marc Kleine-Budde Cc: David Daney , Jan Glauber , Mark Brown , linux-spi@vger.kernel.org, "linux-kernel@vger.kernel.org" , Wolfgang Grandegger Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 16, 2017 at 4:12 AM, Marc Kleine-Budde wrote: > On 11/16/2017 12:18 AM, Tim Harvey wrote: >> David / Jan, >> >> For reference, the HM describes TXNUM/TOTNUM as: >> TXNUM - Number of bytes to transmit >> TOTNUM - Total number of bytes to shift (transmit and receive) >> >> Here are some experiments that show somewhat inconsistent results: >> - full duplex 3byte tx / 3byte rx to MCP251x >> mpi_dat0 => 0x03 // READ >> mpi_dat1 => 0x0e // CANSTAT >> mip_dat2 => 0xa5 // dummy (but making it 0xa5 instead of 0x00 to prove a point) >> mpi_tx => 0x100303 // TXNUM=3 TOTNUM=3; we see 24 clock cycles >> // wait for completion >> mpi_dat0 <= 0xff >> mpi_dat1 <= 0xff > > Do you see 0xff 0xff on the MISO wire for byte 1 and 2? Yes > >> mpi_dat2 <=0xa5 // this the dummy byte we sent out MOSI not what came >> in on MISO which the scope shows as 0x80 > > Oh, the device reads what you have shifed out? This is not good. Yes... its not good. My first theory was that until TXNUM bytes have been shifted out it shifts in the data it's sending (there's a mux that can select from MOSI or MISO) but this doesn't hold true on some of the other test cases. if you perform a SPI transaction on a CN80xx that has no SPI slave device you can see this as well. > >> if I set TXNUM=3 TOTNUM=4: >> mpi_dat0 => 0x03 // READ >> mpi_dat1 => 0x0e // CANSTAT >> mip_dat2 => 0xa5 // dummy >> mpi_tx => 0x100304 // TXNUM=3 TOTNUM=4; we see 32 clock cycles > > What's on MOSI for byte 4? whatever was in the buffer - 0 in my test cases. The TOTNUM=4 causes 4*8 clock cycles. The TXNUM somehow steers the MUX that selects if MOSI or MISO gets shifted into MPI_DAT for the input side but its not entirely clear what it's logic is. I don't really understand why you would ever want to read in MOSI and I don't see a way to control this mux directly. > >> // wait for completion >> mpi_dat0 <= 0xff >> mpi_dat1 <= 0xff >> mpi_dat2 <= 0x80 // response for CANSTAT reg 0x0e >> mpi_dat3 <= 0x87 // response for CANCTRL reg 0x0f (because we shifted >> 32 clock cycles) > > Looks correct. Right, the data is correct but in this case I didn't want to clock an extra byte just to be able to get the response. > >> if I set TXNUM=2 TOTNUM=3: >> mpi_dat0 => 0x03 // READ >> mpi_dat1 => 0x0e // CANSTAT >> mpi_tx => 0x100203 // TXNUM=2 TOTNUM=3; we see 24 clock cycles > > What's on MOSI for byte 3? whatever was in the buffer - 0 in my case. > >> // wait for completion >> mpi_dat0 <= 0xff >> mpi_dat1 <= 0xff >> mpi_dat2 <= 0x80 // response for CANSTAT reg 0x0e >> >> if I set TXNUM=1 TOTNUM=1 to send a RESET command: >> mpi_dat0 => 0xc0 // RESET >> mpi_tx => 0x100101 // TXNUM=1 TOTNUM=1; we see 8 clock cycles >> // wait for completion >> mpi_dat0 <= 0xc0 >> >> In all cases above what is seen on MISO in relation to CLK matches the >> expectations of the mcp251x but the CN80xx MPI_DAT registers don't >> return what I see on MISO. Am I missing a consistent pattern of >> MPI_DAT vs TXNUM/TOTNUM here that would allow us to work-around this? >> Is this a CN80xx chip errata? There is no known errata for the CN80XX >> MPI engine. >> >> I could re-write the mcp251x driver to not use full-duplex but I'm >> assuming most SPI drivers use full-duplex transactions. > > ACK. > > You don't want to use the mcp251x chip anyways for CAN, the SPI is quite > slow and the load of the CPU is relatively high. Don't expect to get > many messages over CAN and prepare for dropped frames. Better use a > USB-CAN dongle. Or a proper card with some sort of PCI interface. > Understood. I'm not clear what the use case is for CAN on our products but we have customers ask for it and they haven't specified what sort of throughput they expect. We liked the MCP251x because it was a small package and has an integrated transceiver. I'm not aware of any USB based CAN controller chips with transceiver - all the devices I see in drivers/net/can/usb seem to be non-on-board products implementing CAN via on-board ARM CPU's. I see a driver for SPI based HI311x CAN controller in the kernel as well which at least doubles the clock of the MCP251x to 20MHz (the CN80xx/CN81xx SPI clock can go up to 50MHz assuming we can get it to work). What are typical datarates you see used for CAN applications? Tim From 1584235042767982152@xxx Thu Nov 16 14:57:51 +0000 2017 X-GM-THRID: 1583987213767022680 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread