Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Port FreeBSD's ismt(4) driver. ismt(4) supports Intel Chipse...



details:   https://anonhg.NetBSD.org/src/rev/3d8e86694651
branches:  trunk
changeset: 342687:3d8e86694651
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Tue Jan 05 11:24:43 2016 +0000

description:
Port FreeBSD's ismt(4) driver. ismt(4) supports Intel Chipset internal
SMBus 2.0 controller with DMA. It's different from ichsmb(4). Supported
chipsets are S1200 and C2000.

diffstat:

 share/man/man4/Makefile |    5 +-
 share/man/man4/ismt.4   |   79 ++++
 sys/dev/pci/ismt.c      |  881 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 963 insertions(+), 2 deletions(-)

diffs (truncated from 987 to 300 lines):

diff -r e2722f21ef60 -r 3d8e86694651 share/man/man4/Makefile
--- a/share/man/man4/Makefile   Tue Jan 05 10:20:22 2016 +0000
+++ b/share/man/man4/Makefile   Tue Jan 05 11:24:43 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.625 2015/12/16 08:20:03 jdc Exp $
+#      $NetBSD: Makefile,v 1.626 2016/01/05 11:24:43 msaitoh Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/18/93
 
 MAN=   aac.4 ac97.4 acardide.4 aceride.4 acphy.4 \
@@ -33,7 +33,8 @@
        ifmedia.4 igmafb.4 igphy.4 igsfb.4 iha.4 ihphy.4 iic.4 inet.4 ikphy.4 \
        inphy.4 intersil7170.4 \
        ioasic.4 ioat.4 iop.4 iophy.4 iopsp.4 ip.4 ipkdb.4 ipmi.4 ipw.4 \
-       irmce.4 isp.4 isv.4 itesio.4 iteide.4 iwi.4 iwm.4 iwn.4 ixg.4 ixpide.4 \
+       irmce.4 isp.4 ismt.4 isv.4 itesio.4 iteide.4 iwi.4 iwm.4 iwn.4 ixg.4 \
+       ixpide.4 \
        jme.4 jmide.4 joy.4 \
        kloader.4 kse.4 ksyms.4 kttcp.4 \
        lc.4 ld.4 lii.4 lo.4 lua.4 lxtphy.4 \
diff -r e2722f21ef60 -r 3d8e86694651 share/man/man4/ismt.4
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/man/man4/ismt.4     Tue Jan 05 11:24:43 2016 +0000
@@ -0,0 +1,79 @@
+.\" $NetBSD: ismt.4,v 1.1 2016/01/05 11:24:43 msaitoh Exp $
+.\"
+.\" Copyright (c) 2015 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Masanobu SAITOH.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd January 5, 2016
+.Dt ISMT 4
+.Os
+.Sh NAME
+.Nm ismt
+.Nd Intel Chipset internal SMBus 2.0 controller with DMA
+.Sh SYNOPSIS
+.Cd "ismt* at pci? dev ? function ?"
+.Cd "iic* at ismt?"
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for the Intel chipset internal SMBus 2.0 host interface
+with DMA to be used with the
+.Xr iic 4
+framework.
+.Pp
+Supported chipsets:
+.Pp
+.Bl -bullet -compact -offset indent
+.It
+S1200 series.
+.It
+C2000 series.
+.El
+.Sh SEE ALSO
+.Xr iic 4 ,
+.Xr intro 4 ,
+.Xr pci 4
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Fx 11.0
+and in
+.Nx 8.0 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+driver was written by
+.An Jim Harris
+.Aq jimharris%freebsd.org@localhost
+for
+.Fx
+and ported to
+.Nx
+by
+.An Masanobu SAITOH
+.Aq msaitoh%NetBSD.org@localhost .
diff -r e2722f21ef60 -r 3d8e86694651 sys/dev/pci/ismt.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pci/ismt.c        Tue Jan 05 11:24:43 2016 +0000
@@ -0,0 +1,881 @@
+/*-
+ * Copyright (c) 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Masanobu SAITOH.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*-
+ * Copyright (C) 2014 Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Intel Corporation nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#if 0
+__FBSDID("$FreeBSD: head/sys/dev/ismt/ismt.c 266474 2014-05-20 19:55:06Z jimharris $");
+#endif
+__KERNEL_RCSID(0, "$NetBSD: ismt.c,v 1.1 2016/01/05 11:24:43 msaitoh Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/errno.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/mutex.h>
+#include <sys/proc.h>
+
+#include <sys/bus.h>
+
+#include <dev/pci/pcidevs.h>
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+
+#include <dev/i2c/i2cvar.h>
+
+#define ISMT_DESC_ENTRIES      32
+
+/* Hardware Descriptor Constants - Control Field */
+#define ISMT_DESC_CWRL 0x01    /* Command/Write Length */
+#define ISMT_DESC_BLK  0X04    /* Perform Block Transaction */
+#define ISMT_DESC_FAIR 0x08    /* Set fairness flag upon successful arbit. */
+#define ISMT_DESC_PEC  0x10    /* Packet Error Code */
+#define ISMT_DESC_I2C  0x20    /* I2C Enable */
+#define ISMT_DESC_INT  0x40    /* Interrupt */
+#define ISMT_DESC_SOE  0x80    /* Stop On Error */
+
+/* Hardware Descriptor Constants - Status Field */
+#define ISMT_DESC_SCS  0x01    /* Success */
+#define ISMT_DESC_DLTO 0x04    /* Data Low Time Out */
+#define ISMT_DESC_NAK  0x08    /* NAK Received */
+#define ISMT_DESC_CRC  0x10    /* CRC Error */
+#define ISMT_DESC_CLTO 0x20    /* Clock Low Time Out */
+#define ISMT_DESC_COL  0x40    /* Collisions */
+#define ISMT_DESC_LPR  0x80    /* Large Packet Received */
+
+/* Macros */
+#define ISMT_DESC_ADDR_RW(addr, is_read) ((addr << 1) | (is_read))
+
+/* iSMT General Register address offsets (SMBBAR + <addr>) */
+#define ISMT_GR_GCTRL          0x000   /* General Control */
+#define ISMT_GR_SMTICL         0x008   /* SMT Interrupt Cause Location */
+#define ISMT_GR_ERRINTMSK      0x010   /* Error Interrupt Mask */
+#define ISMT_GR_ERRAERMSK      0x014   /* Error AER Mask */
+#define ISMT_GR_ERRSTS         0x018   /* Error Status */
+#define ISMT_GR_ERRINFO                0x01c   /* Error Information */
+
+/* iSMT Master Registers */
+#define ISMT_MSTR_MDBA         0x100   /* Master Descriptor Base Address */
+#define ISMT_MSTR_MCTRL                0x108   /* Master Control */
+#define ISMT_MSTR_MSTS         0x10c   /* Master Status */
+#define ISMT_MSTR_MDS          0x110   /* Master Descriptor Size */
+#define ISMT_MSTR_RPOLICY      0x114   /* Retry Policy */
+
+/* iSMT Miscellaneous Registers */
+#define ISMT_SPGT      0x300   /* SMBus PHY Global Timing */
+
+/* General Control Register (GCTRL) bit definitions */
+#define ISMT_GCTRL_TRST        0x04    /* Target Reset */
+#define ISMT_GCTRL_KILL        0x08    /* Kill */
+#define ISMT_GCTRL_SRST        0x40    /* Soft Reset */
+
+/* Master Control Register (MCTRL) bit definitions */
+#define ISMT_MCTRL_SS  0x01            /* Start/Stop */
+#define ISMT_MCTRL_MEIE        0x10            /* Master Error Interrupt Enable */
+#define ISMT_MCTRL_FMHP        0x00ff0000      /* Firmware Master Head Ptr (FMHP) */
+
+/* Master Status Register (MSTS) bit definitions */
+#define ISMT_MSTS_HMTP 0xff0000        /* HW Master Tail Pointer (HMTP) */
+#define ISMT_MSTS_MIS  0x20            /* Master Interrupt Status (MIS) */
+#define ISMT_MSTS_MEIS 0x10            /* Master Error Int Status (MEIS) */
+#define ISMT_MSTS_IP   0x01            /* In Progress */
+
+/* Master Descriptor Size (MDS) bit definitions */
+#define ISMT_MDS_MASK  0xff    /* Master Descriptor Size mask (MDS) */
+
+/* SMBus PHY Global Timing Register (SPGT) bit definitions */
+#define ISMT_SPGT_SPD_MASK     0xc0000000      /* SMBus Speed mask */
+#define ISMT_SPGT_SPD_80K      0x00            /* 80 kHz */
+#define ISMT_SPGT_SPD_100K     (0x1 << 30)     /* 100 kHz */
+#define ISMT_SPGT_SPD_400K     (0x2 << 30)     /* 400 kHz */
+#define ISMT_SPGT_SPD_1M       (0x3 << 30)     /* 1 MHz */
+
+/* MSI Control Register (MSICTL) bit definitions */
+#define ISMT_MSICTL_MSIE       0x01    /* MSI Enable */
+
+#define ISMT_MAX_BLOCK_SIZE    32 /* per SMBus spec */
+
+#define ISMT_INTR_TIMEOUT      (hz / 50) /* 0.02s */
+#define ISMT_POLL_DELAY                100     /* 100usec */
+#define ISMT_POLL_COUNT                200     /* 100usec * 200 = 0.02s */
+
+//#define ISMT_DEBUG   aprint_debug_dev
+#ifndef ISMT_DEBUG
+#define ISMT_DEBUG(...)
+#endif
+
+/* iSMT Hardware Descriptor */
+struct ismt_desc {
+       uint8_t tgtaddr_rw;     /* target address & r/w bit */
+       uint8_t wr_len_cmd;     /* write length in bytes or a command */
+       uint8_t rd_len;         /* read length */
+       uint8_t control;        /* control bits */
+       uint8_t status;         /* status bits */
+       uint8_t retry;          /* collision retry and retry count */
+       uint8_t rxbytes;        /* received bytes */
+       uint8_t txbytes;        /* transmitted bytes */
+       uint32_t dptr_low;      /* lower 32 bit of the data pointer */
+       uint32_t dptr_high;     /* upper 32 bit of the data pointer */
+} __packed;
+
+#define DESC_SIZE      (ISMT_DESC_ENTRIES * sizeof(struct ismt_desc))
+
+#define DMA_BUFFER_SIZE        64
+
+struct ismt_softc {
+       device_t                pcidev;
+       device_t                smbdev;
+
+       struct i2c_controller   sc_i2c_tag;
+       kmutex_t                sc_i2c_mutex;
+
+       pci_chipset_tag_t       sc_pc;
+       pcitag_t                sc_pcitag;
+       pci_intr_handle_t       *sc_pihp;
+       void                    *sc_ih;
+
+       bus_space_tag_t         mmio_tag;
+       bus_space_handle_t      mmio_handle;



Home | Main Index | Thread Index | Old Index