thunderbolt: Introducing Thunderbolt(TM) networking
Subsystems (5)
v4 cover thunderbolt: Introducing Thunderbolt(TM) networking
This is version 4 of Thunderbolt(TM) driver for non-Apple hardware.
Changes since v3:
- Moved new Thunderbolt device IDs from pci_ids.h to icm_nhi.h.
- Cleanup and added some comments in code.
These patches were pushed to GitHub where they can be reviewed more comfortably with green/red highlighting:
https://github.com/01org/thunderbolt-software-kernel-tree
Daemon code:
https://github.com/01org/thunderbolt-software-daemon
For reference, here's a link to version 3:
[v3]: https://lkml.org/lkml/2016/7/14/311
Amir Levy (7):
thunderbolt: Macro rename
thunderbolt: Updating the register definitions
thunderbolt: Kconfig for Thunderbolt(TM) networking
thunderbolt: Communication with the ICM (firmware)
thunderbolt: Networking state machine
thunderbolt: Networking transmit and receive
thunderbolt: Networking doc
Documentation/00-INDEX | 2 + Documentation/thunderbolt-networking.txt | 135 ++ drivers/thunderbolt/Kconfig | 25 +- drivers/thunderbolt/Makefile | 3 +- drivers/thunderbolt/icm/Makefile | 28 + drivers/thunderbolt/icm/icm_nhi.c | 1642 +++++++++++++++++++++ drivers/thunderbolt/icm/icm_nhi.h | 93 ++ drivers/thunderbolt/icm/net.c | 2276 ++++++++++++++++++++++++++++++ drivers/thunderbolt/icm/net.h | 274 ++++ drivers/thunderbolt/nhi_regs.h | 115 +- 10 files changed, 4585 insertions(+), 8 deletions(-) create mode 100644 Documentation/thunderbolt-networking.txt create mode 100644 drivers/thunderbolt/icm/Makefile create mode 100644 drivers/thunderbolt/icm/icm_nhi.c create mode 100644 drivers/thunderbolt/icm/icm_nhi.h create mode 100644 drivers/thunderbolt/icm/net.c create mode 100644 drivers/thunderbolt/icm/net.h
Signature · 1 line
2.7.4
PATCH v4 1/7 thunderbolt: Macro rename
This first patch updates the registers file to
reflect that it isn't only for Cactus Ridge.
No functional change intended.
--- drivers/thunderbolt/nhi_regs.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/thunderbolt/nhi_regs.h +3 -3
@@ -1,11 +1,11 @@/* -* Thunderbolt Cactus Ridge driver - NHI registers +* Thunderbolt driver - NHI registers * * Copyright (c) 2014 Andreas Noever <[email protected]> */ -#ifndef DSL3510_REGS_H_ -#define DSL3510_REGS_H_ +#ifndef NHI_REGS_H_ +#define NHI_REGS_H_ #include <linux/types.h>
Signature · 1 line
2.7.4
PATCH v4 2/7 thunderbolt: Updating the register definitions
In reply to Amir LevyAdding more Thunderbolt(TM) register definitions
and some helper macros.
--- drivers/thunderbolt/nhi_regs.h | 109 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+)
drivers/thunderbolt/nhi_regs.h +109 -0
@@ -9,6 +9,11 @@#include <linux/types.h> +#define NHI_MMIO_BAR 0 + +#define TBT_RING_MIN_NUM_BUFFERS 2 +#define TBT_RING_MAX_FRAME_SIZE (4 * 1024) +enum ring_flags {RING_FLAG_ISOCH_ENABLE =1 <<27 ,/* TX only? */ RING_FLAG_E2E_FLOW_CONTROL =1 <<28 ,
@@ -39,6 +44,33 @@ struct ring_desc {u32 time;/* write zero */ } __packed; +/** +* struct tbt_buf_desc - TX/RX ring buffer descriptor. +* This is same as struct ring_desc, but without the use of bitfields and +* with explicit endianity. +*/ +struct tbt_buf_desc { +__le64 phys; +__le32 attributes; +__le32 time; +}; + +#define DESC_ATTR_LEN_SHIFT 0 +#define DESC_ATTR_LEN_MASK GENMASK(11, DESC_ATTR_LEN_SHIFT) +#define DESC_ATTR_EOF_SHIFT 12 +#define DESC_ATTR_EOF_MASK GENMASK(15, DESC_ATTR_EOF_SHIFT) +#define DESC_ATTR_SOF_SHIFT 16 +#define DESC_ATTR_SOF_MASK GENMASK(19, DESC_ATTR_SOF_SHIFT) +#define DESC_ATTR_TX_ISOCH_DMA_EN BIT(20)/* TX */ +#define DESC_ATTR_RX_CRC_ERR BIT(20)/* RX after use */ +#define DESC_ATTR_DESC_DONE BIT(21) +#define DESC_ATTR_REQ_STS BIT(22)/* TX and RX before use */ +#define DESC_ATTR_RX_BUF_OVRN_ERR BIT(22)/* RX after use */ +#define DESC_ATTR_INT_EN BIT(23) +#define DESC_ATTR_OFFSET_SHIFT 24 +#define DESC_ATTR_OFFSET_MASK GENMASK(31, DESC_ATTR_OFFSET_SHIFT) + +/* NHI registers in bar 0 */ /*
@@ -60,6 +92,30 @@ struct ring_desc {*/ #define REG_RX_RING_BASE 0x08000 +#define REG_RING_STEP 16 +#define REG_RING_PHYS_LO_OFFSET 0 +#define REG_RING_PHYS_HI_OFFSET 4 +#define REG_RING_CONS_PROD_OFFSET 8/* cons - RO, prod - RW */ +#define REG_RING_CONS_SHIFT 0 +#define REG_RING_CONS_MASK GENMASK(15, REG_RING_CONS_SHIFT) +#define REG_RING_PROD_SHIFT 16 +#define REG_RING_PROD_MASK GENMASK(31, REG_RING_PROD_SHIFT) +#define REG_RING_SIZE_OFFSET 12 +#define REG_RING_SIZE_SHIFT 0 +#define REG_RING_SIZE_MASK GENMASK(15, REG_RING_SIZE_SHIFT) +#define REG_RING_BUF_SIZE_SHIFT 16 +#define REG_RING_BUF_SIZE_MASK GENMASK(27, REG_RING_BUF_SIZE_SHIFT) + +#define TBT_RING_CONS_PROD_REG (iobase, ringbase, ringnumber) \ + ((iobase) + (ringbase) + \ + ((ringnumber) * REG_RING_STEP) + \ + REG_RING_CONS_PROD_OFFSET) + +#define TBT_REG_RING_PROD_EXTRACT (val) (((val) & REG_RING_PROD_MASK) >> \ + REG_RING_PROD_SHIFT) + +#define TBT_REG_RING_CONS_EXTRACT (val) (((val) & REG_RING_CONS_MASK) >> \ + REG_RING_CONS_SHIFT)/* * 32 bytes per entry, one entry for every hop (REG_HOP_COUNT) * 00: enum_ring_flags
@@ -77,6 +133,19 @@ struct ring_desc {* ..: unknown */ #define REG_RX_OPTIONS_BASE 0x29800 +#define REG_RX_OPTS_TX_E2E_HOP_ID_SHIFT 12 +#define REG_RX_OPTS_TX_E2E_HOP_ID_MASK \ + GENMASK(22, REG_RX_OPTS_TX_E2E_HOP_ID_SHIFT) +#define REG_RX_OPTS_MASK_OFFSET 4 +#define REG_RX_OPTS_MASK_EOF_SHIFT 0 +#define REG_RX_OPTS_MASK_EOF_MASK GENMASK(15, REG_RX_OPTS_MASK_EOF_SHIFT) +#define REG_RX_OPTS_MASK_SOF_SHIFT 16 +#define REG_RX_OPTS_MASK_SOF_MASK GENMASK(31, REG_RX_OPTS_MASK_SOF_SHIFT) + +#define REG_OPTS_STEP 32 +#define REG_OPTS_E2E_EN BIT(28) +#define REG_OPTS_RAW BIT(30) +#define REG_OPTS_VALID BIT(31)/* * three bitfields: tx, rx, rx overflow
@@ -86,6 +155,7 @@ struct ring_desc {*/ #define REG_RING_NOTIFY_BASE 0x37800#define RING_NOTIFY_REG_COUNT (nhi) ((31 + 3 * nhi->hop_count) / 32) +#define REG_RING_NOTIFY_STEP 4/* * two bitfields: rx, tx
@@ -94,8 +164,47 @@ struct ring_desc {*/ #define REG_RING_INTERRUPT_BASE 0x38200#define RING_INTERRUPT_REG_COUNT (nhi) ((31 + 2 * nhi->hop_count) / 32) +#define REG_RING_INT_TX_PROCESSED (ring_num) BIT(ring_num) +#define REG_RING_INT_RX_PROCESSED (ring_num, num_paths) BIT((ring_num) + \ + (num_paths)) +#define RING_INT_DISABLE (base, val) iowrite32( \ + ioread32((base) + REG_RING_INTERRUPT_BASE) & ~(val), \ + (base) + REG_RING_INTERRUPT_BASE) +#define RING_INT_ENABLE (base, val) iowrite32( \ + ioread32((base) + REG_RING_INTERRUPT_BASE) | (val), \ + (base) + REG_RING_INTERRUPT_BASE) +#define RING_INT_DISABLE_TX (base, ring_num) \ + RING_INT_DISABLE(base, REG_RING_INT_TX_PROCESSED(ring_num)) +#define RING_INT_DISABLE_RX (base, ring_num, num_paths) \ + RING_INT_DISABLE(base, REG_RING_INT_RX_PROCESSED(ring_num, num_paths)) +#define RING_INT_ENABLE_TX (base, ring_num) \ + RING_INT_ENABLE(base, REG_RING_INT_TX_PROCESSED(ring_num)) +#define RING_INT_ENABLE_RX (base, ring_num, num_paths) \ + RING_INT_ENABLE(base, REG_RING_INT_RX_PROCESSED(ring_num, num_paths)) +#define RING_INT_DISABLE_TX_RX (base, ring_num, num_paths) \ + RING_INT_DISABLE(base, REG_RING_INT_TX_PROCESSED(ring_num) | \ + REG_RING_INT_RX_PROCESSED(ring_num, num_paths)) + +#define REG_RING_INTERRUPT_STEP 4 + +#define REG_INT_THROTTLING_RATE 0x38c00 +#define REG_INT_THROTTLING_RATE_STEP 4 +#define NUM_INT_VECTORS 16 + +#define REG_INT_VEC_ALLOC_BASE 0x38c40 +#define REG_INT_VEC_ALLOC_STEP 4 +#define REG_INT_VEC_ALLOC_FIELD_BITS 4 +#define REG_INT_VEC_ALLOC_FIELD_MASK (BIT(REG_INT_VEC_ALLOC_FIELD_BITS) - 1) +#define REG_INT_VEC_ALLOC_PER_REG ((BITS_PER_BYTE * sizeof(u32)) / \ + REG_INT_VEC_ALLOC_FIELD_BITS)/* The last 11 bits contain the number of hops supported by the NHI port. */ #define REG_HOP_COUNT 0x39640 +#define REG_HOP_COUNT_TOTAL_PATHS_MASK GENMASK(10, 0) + +#define REG_HOST_INTERFACE_RST 0x39858 + +#define REG_DMA_MISC 0x39864 +#define REG_DMA_MISC_INT_AUTO_CLEAR BIT(2)#endif
Signature · 1 line
2.7.4
PATCH v4 3/7 thunderbolt: Kconfig for Thunderbolt(TM) networking
In reply to Amir LevyUpdating the Kconfig Thunderbolt(TM) description.
--- drivers/thunderbolt/Kconfig | 25 +++++++++++++++++++++---- drivers/thunderbolt/Makefile | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-)
drivers/thunderbolt/Kconfig +21 -4
@@ -1,13 +1,30 @@ -menuconfig THUNDERBOLT - tristate "Thunderbolt support for Apple devices" +config THUNDERBOLT + tristate "Thunderbolt(TM) support" depends on PCI select CRC32 help - Cactus Ridge Thunderbolt Controller driver + Thunderbolt(TM) Controller driver + +if THUNDERBOLT + +config THUNDERBOLT_APPLE + tristate "Apple hardware support" + help This driver is required if you want to hotplug Thunderbolt devices on Apple hardware. Device chaining is currently not supported. - To compile this driver a module, choose M here. The module will be + To compile this driver as a module, choose M here. The module will be called thunderbolt. + +config THUNDERBOLT_ICM + tristate "Thunderbolt(TM) Networking" + help + This driver is required if you want Thunderbolt(TM) Networking on + non-Apple hardware. + + To compile this driver as a module, choose M here. The module will be + called thunderbolt_icm. + +endif
drivers/thunderbolt/Makefile +1 -1
@@ -1,3 +1,3 @@ -obj-${CONFIG_THUNDERBOLT} := thunderbolt.o +obj-${CONFIG_THUNDERBOLT_APPLE} := thunderbolt.o thunderbolt-objs := nhi.o ctl.o tb.o switch.o cap.o path.o tunnel_pci.o eeprom.o
Signature · 1 line
2.7.4
PATCH v4 4/7 thunderbolt: Communication with the ICM (firmware)
In reply to Amir LevyFirmware-based (a.k.a ICM - Intel Connection Manager) controller is used for establishing and maintaining the Thunderbolt Networking connection. We need to be able to communicate with it.
--- drivers/thunderbolt/Makefile | 1 + drivers/thunderbolt/icm/Makefile | 28 + drivers/thunderbolt/icm/icm_nhi.c | 1343 +++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/icm/icm_nhi.h | 93 +++ drivers/thunderbolt/icm/net.h | 200 ++++++ 5 files changed, 1665 insertions(+) create mode 100644 drivers/thunderbolt/icm/Makefile create mode 100644 drivers/thunderbolt/icm/icm_nhi.c create mode 100644 drivers/thunderbolt/icm/icm_nhi.h create mode 100644 drivers/thunderbolt/icm/net.h
drivers/thunderbolt/Makefile +1 -0
@@ -1,3 +1,4 @@ obj-${CONFIG_THUNDERBOLT_APPLE} := thunderbolt.o thunderbolt-objs := nhi.o ctl.o tb.o switch.o cap.o path.o tunnel_pci.o eeprom.o +obj-${CONFIG_THUNDERBOLT_ICM} += icm/
drivers/thunderbolt/icm/Makefile new file +28 -0
@@ -0,0 +1,28 @@ +################################################################################ +# +# Intel Thunderbolt(TM) driver +# Copyright(c) 2014 - 2016 Intel Corporation. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms and conditions of the GNU General Public License, +# version 2, as published by the Free Software Foundation. +# +# This program is distributed in the hope it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see <http://www.gnu.org/licenses/>. +# +# The full GNU General Public License is included in this distribution in +# the file called "COPYING". +# +# Contact Information: +# Intel Thunderbolt Mailing List <[email protected]> +# Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 +# +################################################################################ + +obj-${CONFIG_THUNDERBOLT_ICM} += thunderbolt-icm.o +thunderbolt-icm-objs := icm_nhi.o
drivers/thunderbolt/icm/icm_nhi.c new file +1343 -0
1,343 lines not on this page · raw message
drivers/thunderbolt/icm/icm_nhi.h new file +93 -0
93 lines not on this page · raw message
drivers/thunderbolt/icm/net.h new file +200 -0
200 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v4 5/7 thunderbolt: Networking state machine
In reply to Amir LevyNegotiation states that a peer goes through in order to establish the communication with the second peer.
This includes communication with upper layer and additional infrastructure support to communicate with the second peer through ICM.
--- drivers/thunderbolt/icm/Makefile | 2 +- drivers/thunderbolt/icm/icm_nhi.c | 304 ++++++++++++++- drivers/thunderbolt/icm/net.c | 801 ++++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/icm/net.h | 74 ++++ 4 files changed, 1170 insertions(+), 11 deletions(-) create mode 100644 drivers/thunderbolt/icm/net.c
drivers/thunderbolt/icm/Makefile +1 -1
@@ -25,4 +25,4 @@ ################################################################################ obj-${CONFIG_THUNDERBOLT_ICM} += thunderbolt-icm.o -thunderbolt-icm-objs := icm_nhi.o +thunderbolt-icm-objs := icm_nhi.o net.o
drivers/thunderbolt/icm/icm_nhi.c +294 -10
364 lines not on this page · raw message
drivers/thunderbolt/icm/net.c new file +801 -0
801 lines not on this page · raw message
drivers/thunderbolt/icm/net.h +74 -0
109 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v4 7/7 thunderbolt: Networking doc
In reply to Amir LevyAdding Thunderbolt(TM) networking documentation.
--- Documentation/00-INDEX | 2 + Documentation/thunderbolt-networking.txt | 135 +++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 Documentation/thunderbolt-networking.txt
Documentation/00-INDEX +2 -0
@@ -439,6 +439,8 @@ this_cpu_ops.txt - List rationale behind and the way to use this_cpu operations. thermal/ - directory with information on managing thermal issues (CPU/temp) +thunderbolt-networking.txt + - Thunderbolt(TM) Networking driver description. trace/ - directory with info on tracing technologies within linux unaligned-memory-access.txt
Documentation/thunderbolt-networking.txt new file +135 -0
135 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v4 6/7 thunderbolt: Networking transmit and receive
In reply to Amir LevyHandling the transmission to second peer and receiving from it. This includes communication with upper layer, the network stack and configuration of Thunderbolt(TM) HW.
--- drivers/thunderbolt/icm/icm_nhi.c | 15 + drivers/thunderbolt/icm/net.c | 1475 +++++++++++++++++++++++++++++++++++++ 2 files changed, 1490 insertions(+)
drivers/thunderbolt/icm/icm_nhi.c +15 -0
@@ -1056,6 +1056,7 @@ static irqreturn_t nhi_msi(int __always_unused irq, void *data) {struct tbt_nhi_ctxt *nhi_ctxt = data;u32 isr0, isr1, imr0, imr1; +int i;/* clear on read */ isr0 =ioread32 (nhi_ctxt->iobase +REG_RING_NOTIFY_BASE );
@@ -1078,6 +1079,20 @@ static irqreturn_t nhi_msi(int __always_unused irq, void *data)spin_unlock (&nhi_ctxt->lock); +for (i =0 ; i < nhi_ctxt->num_ports; ++i) { +struct net_device *net_dev = + nhi_ctxt->net_devices[i].net_dev; +if (net_dev) { +u8 path =PATH_FROM_PORT (nhi_ctxt->num_paths, i); + +if (isr0 ®_RING_INT_RX_PROCESSED ( + path, nhi_ctxt->num_paths)) +tbt_net_rx_msi (net_dev); +if (isr0 ®_RING_INT_TX_PROCESSED (path)) +tbt_net_tx_msi (net_dev); + } + } +if (isr0 ®_RING_INT_RX_PROCESSED (TBT_ICM_RING_NUM , nhi_ctxt->num_paths))schedule_work (&nhi_ctxt->icm_msgs_work);
drivers/thunderbolt/icm/net.c +1475 -0
1,567 lines not on this page · raw message
Signature · 1 line
2.7.4
Quoted 1 line · Amir Levy
This is version 4 of Thunderbolt(TM) driver for non-Apple hardware.
[]
Quoted 10 lines
Documentation/00-INDEX | 2 +
Documentation/thunderbolt-networking.txt| 135 ++ drivers/thunderbolt/Kconfig | 25 +- drivers/thunderbolt/Makefile | 3 +- drivers/thunderbolt/icm/Makefile | 28 + drivers/thunderbolt/icm/icm_nhi.c | 1642 +++++++++++++++++++++ drivers/thunderbolt/icm/icm_nhi.h | 93 ++ drivers/thunderbolt/icm/net.c | 2276 ++++++++++++++++++++++++++++++ drivers/thunderbolt/icm/net.h | 274 ++++ drivers/thunderbolt/nhi_regs.h | 115 +-
Quoted 7 lines
10 files changed, 4585 insertions(+), 8 deletions(-)create mode 100644
Documentation/thunderbolt-networking.txtcreate mode 100644drivers/thunderbolt/icm/Makefilecreate mode 100644drivers/thunderbolt/icm/icm_nhi.ccreate mode 100644drivers/thunderbolt/icm/icm_nhi.hcreate mode 100644drivers/thunderbolt/icm/net.ccreate mode 100644drivers/thunderbolt/icm/net.h
Is a MAINTAINERS update necessary or is Andreas going to be the maintainer?
Quoted 34 lines · Amir Levy
This is version 4 of Thunderbolt(TM) driver for non-Apple hardware.
Changes since v3:
- Moved new Thunderbolt device IDs frompci_ids.htoicm_nhi.h.
- Cleanup and added some comments in code.These patches were pushed to GitHub where they can be reviewed more comfortably with green/red highlighting:
https://github.com/01org/thunderbolt-software-kernel-treeDaemon code:
https://github.com/01org/thunderbolt-software-daemonFor reference, here's a link to version 3:
[v3]: https://lkml.org/lkml/2016/7/14/311Amir Levy (7):
thunderbolt: Macro rename
thunderbolt: Updating the register definitions
thunderbolt:Kconfigfor Thunderbolt(TM) networking
thunderbolt: Communication with the ICM (firmware)
thunderbolt: Networking state machine
thunderbolt: Networking transmit and receive
thunderbolt: Networking docDocumentation/00-INDEX | 2 + Documentation/thunderbolt-networking.txt | 135 ++ drivers/thunderbolt/Kconfig | 25 +- drivers/thunderbolt/Makefile | 3 +- drivers/thunderbolt/icm/Makefile | 28 + drivers/thunderbolt/icm/icm_nhi.c | 1642 +++++++++++++++++++++ drivers/thunderbolt/icm/icm_nhi.h | 93 ++ drivers/thunderbolt/icm/net.c | 2276 ++++++++++++++++++++++++++++++ drivers/thunderbolt/icm/net.h | 274 ++++
Quoted 8 lines
drivers/thunderbolt/nhi_regs.h | 115 +- 10 files changed, 4585 insertions(+), 8 deletions(-) create mode 100644 Documentation/thunderbolt-networking.txt create mode 100644 drivers/thunderbolt/icm/Makefile create mode 100644 drivers/thunderbolt/icm/icm_nhi.c create mode 100644 drivers/thunderbolt/icm/icm_nhi.h create mode 100644 drivers/thunderbolt/icm/net.c create mode 100644 drivers/thunderbolt/icm/net.h
Andreas, I assume you'll handle this.
Quoted 22 lines · Joe Perches
Quoted 1 line · Amir Levy
This is version 4 of Thunderbolt(TM) driver for non-Apple hardware.
[]
Quoted 11 lines
Documentation/00-INDEX | 2 +
Documentation/thunderbolt-networking.txt| 135 ++ drivers/thunderbolt/Kconfig | 25 +- drivers/thunderbolt/Makefile | 3 +- drivers/thunderbolt/icm/Makefile | 28 + drivers/thunderbolt/icm/icm_nhi.c | 1642 +++++++++++++++++++++ drivers/thunderbolt/icm/icm_nhi.h | 93 ++ drivers/thunderbolt/icm/net.c | 2276
++++++++++++++++++++++++++++++
drivers/thunderbolt/icm/net.h | 274 ++++ drivers/thunderbolt/nhi_regs.h | 115 +-Quoted 7 lines
10 files changed, 4585 insertions(+), 8 deletions(-)create mode 100644
Documentation/thunderbolt-networking.txtcreate mode 100644drivers/thunderbolt/icm/Makefilecreate mode 100644drivers/thunderbolt/icm/icm_nhi.ccreate mode 100644drivers/thunderbolt/icm/icm_nhi.hcreate mode 100644drivers/thunderbolt/icm/net.ccreate mode 100644drivers/thunderbolt/icm/net.h
Quoted 2 lines
Is a
MAINTAINERSupdate necessary or is Andreas going to be the maintainer?
Now that the drivers are completely separated it make sense that I'll maintain the thunderbolt/icm driver, if there are no objections.
Quoted 22 lines · Amir (Jer)
Quoted 21 lines · Joe Perches
Quoted 2 lines · Amir Levy
This is version 4 of Thunderbolt(TM) driver for non-Apple hardware.
[]
Quoted 17 lines
Documentation/00-INDEX | 2 +
Documentation/thunderbolt-networking.txt| 135 ++ drivers/thunderbolt/Kconfig | 25 +- drivers/thunderbolt/Makefile | 3 +- drivers/thunderbolt/icm/Makefile | 28 + drivers/thunderbolt/icm/icm_nhi.c | 1642 +++++++++++++++++++++ drivers/thunderbolt/icm/icm_nhi.h | 93 ++ drivers/thunderbolt/icm/net.c | 2276 ++++++++++++++++++++++++++++++ drivers/thunderbolt/icm/net.h | 274 ++++ drivers/thunderbolt/nhi_regs.h | 115 +-10 files changed, 4585 insertions(+), 8 deletions(-)create mode 100644
Documentation/thunderbolt-networking.txtcreate mode 100644drivers/thunderbolt/icm/Makefilecreate mode 100644drivers/thunderbolt/icm/icm_nhi.ccreate mode 100644drivers/thunderbolt/icm/icm_nhi.hcreate mode 100644drivers/thunderbolt/icm/net.ccreate mode 100644drivers/thunderbolt/icm/net.h
Quoted 4 lines
Quoted 2 lines
Is a
MAINTAINERSupdate necessary or is Andreas going to be the maintainer?Now that the drivers are completely separated it make sense that I'll maintain the thunderbolt/icm driver, if there are no objections.
I think that's fine and the MAINTAINERS file should have a new section entry for this driver with your name too.
Re: [PATCH v4 5/7] thunderbolt: Networking state machine
In reply to Amir Levydrivers/thunderbolt/icm/icm_nhi.c genl_put_reply_failure: · line 767
Quoted 4 lines · Amir Levy
drivers/thunderbolt/icm/icm_nhi.c +4
-0+const unique_id_be proto_uuid =APPLE_THUNDERBOLT_IP_PROTOCOL_UUID ; + +if (memcmp (proto_uuid, hdr->apple_tbt_ip_proto_uuid, +sizeof (proto_uuid)) !=0 ) {
You may want to use the uuid_be data type provided by <linux/uuid.h> instead of rolling your own, as well as the helper uuid_be_cmp() defined ibidem.
Thanks,
Lukas
Andreas Noever
maintainerQuoted 44 lines · Bjorn Helgaas
Quoted 34 lines · Amir Levy
This is version 4 of Thunderbolt(TM) driver for non-Apple hardware.
Changes since v3:
- Moved new Thunderbolt device IDs frompci_ids.htoicm_nhi.h.
- Cleanup and added some comments in code.These patches were pushed to GitHub where they can be reviewed more comfortably with green/red highlighting:
https://github.com/01org/thunderbolt-software-kernel-treeDaemon code:
https://github.com/01org/thunderbolt-software-daemonFor reference, here's a link to version 3:
[v3]: https://lkml.org/lkml/2016/7/14/311Amir Levy (7):
thunderbolt: Macro rename
thunderbolt: Updating the register definitions
thunderbolt:Kconfigfor Thunderbolt(TM) networking
thunderbolt: Communication with the ICM (firmware)
thunderbolt: Networking state machine
thunderbolt: Networking transmit and receive
thunderbolt: Networking docDocumentation/00-INDEX | 2 + Documentation/thunderbolt-networking.txt | 135 ++ drivers/thunderbolt/Kconfig | 25 +- drivers/thunderbolt/Makefile | 3 +- drivers/thunderbolt/icm/Makefile | 28 + drivers/thunderbolt/icm/icm_nhi.c | 1642 +++++++++++++++++++++ drivers/thunderbolt/icm/icm_nhi.h | 93 ++ drivers/thunderbolt/icm/net.c | 2276 ++++++++++++++++++++++++++++++ drivers/thunderbolt/icm/net.h | 274 ++++Quoted 8 lines
drivers/thunderbolt/nhi_regs.h | 115 +- 10 files changed, 4585 insertions(+), 8 deletions(-) create mode 100644 Documentation/thunderbolt-networking.txt create mode 100644 drivers/thunderbolt/icm/Makefile create mode 100644 drivers/thunderbolt/icm/icm_nhi.c create mode 100644 drivers/thunderbolt/icm/icm_nhi.h create mode 100644 drivers/thunderbolt/icm/net.c create mode 100644 drivers/thunderbolt/icm/net.h
Quoted 1 line
Andreas, I assume you'll handle this.
No, this is a separate driver.
Andreas Noever
maintainerRe: [PATCH v4 2/7] thunderbolt: Updating the register definitions
In reply to Amir LevyQuoted 28 lines · Amir Levy
Adding more Thunderbolt(TM) register definitions
and some helper macros.Signed-off-by Amir Levy <[email protected]>--- drivers/thunderbolt/nhi_regs.h | 109 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+)drivers/thunderbolt/nhi_regs.h +5
-0@@ -9,6 +9,11 @@#include <linux/types.h> +#define NHI_MMIO_BAR 0 + +#define TBT_RING_MIN_NUM_BUFFERS 2 +#define TBT_RING_MAX_FRAME_SIZE (4 * 1024) +enum ring_flags {RING_FLAG_ISOCH_ENABLE =1 <<27 ,/* TX only? */ RING_FLAG_E2E_FLOW_CONTROL =1 <<28 ,@@ -39,6 +44,33 @@ struct ring_desc {u32 time;/* write zero */ } __packed;
drivers/thunderbolt/nhi_regs.h struct ring_desc { · line 56
Quoted 10 lines
drivers/thunderbolt/nhi_regs.h +10
-0+/** +* struct tbt_buf_desc - TX/RX ring buffer descriptor. +* This is same as struct ring_desc, but without the use of bitfields and +* with explicit endianity. +*/ +struct tbt_buf_desc { +__le64 phys; +__le32 attributes; +__le32 time; +};
Does sharing this file make sense? The style seems to be quite different (structs with bitfields vs explicit bit-access). I think I would prefer separate register definitions, unless you are reusing a substantial amount (I have not checked).
Andreas
Quoted 130 lines
drivers/thunderbolt/nhi_regs.h +94
-1+ +#define DESC_ATTR_LEN_SHIFT 0 +#define DESC_ATTR_LEN_MASK GENMASK(11, DESC_ATTR_LEN_SHIFT) +#define DESC_ATTR_EOF_SHIFT 12 +#define DESC_ATTR_EOF_MASK GENMASK(15, DESC_ATTR_EOF_SHIFT) +#define DESC_ATTR_SOF_SHIFT 16 +#define DESC_ATTR_SOF_MASK GENMASK(19, DESC_ATTR_SOF_SHIFT) +#define DESC_ATTR_TX_ISOCH_DMA_EN BIT(20)/* TX */ +#define DESC_ATTR_RX_CRC_ERR BIT(20)/* RX after use */ +#define DESC_ATTR_DESC_DONE BIT(21) +#define DESC_ATTR_REQ_STS BIT(22)/* TX and RX before use */ +#define DESC_ATTR_RX_BUF_OVRN_ERR BIT(22)/* RX after use */ +#define DESC_ATTR_INT_EN BIT(23) +#define DESC_ATTR_OFFSET_SHIFT 24 +#define DESC_ATTR_OFFSET_MASK GENMASK(31, DESC_ATTR_OFFSET_SHIFT) + +/* NHI registers in bar 0 */ /* @@ -60,6 +92,30 @@ struct ring_desc {*/ #define REG_RX_RING_BASE 0x08000 +#define REG_RING_STEP 16 +#define REG_RING_PHYS_LO_OFFSET 0 +#define REG_RING_PHYS_HI_OFFSET 4 +#define REG_RING_CONS_PROD_OFFSET 8/* cons - RO, prod - RW */ +#define REG_RING_CONS_SHIFT 0 +#define REG_RING_CONS_MASK GENMASK(15, REG_RING_CONS_SHIFT) +#define REG_RING_PROD_SHIFT 16 +#define REG_RING_PROD_MASK GENMASK(31, REG_RING_PROD_SHIFT) +#define REG_RING_SIZE_OFFSET 12 +#define REG_RING_SIZE_SHIFT 0 +#define REG_RING_SIZE_MASK GENMASK(15, REG_RING_SIZE_SHIFT) +#define REG_RING_BUF_SIZE_SHIFT 16 +#define REG_RING_BUF_SIZE_MASK GENMASK(27, REG_RING_BUF_SIZE_SHIFT) + +#define TBT_RING_CONS_PROD_REG (iobase, ringbase, ringnumber) \ + ((iobase) + (ringbase) + \ + ((ringnumber) * REG_RING_STEP) + \ + REG_RING_CONS_PROD_OFFSET) + +#define TBT_REG_RING_PROD_EXTRACT (val) (((val) & REG_RING_PROD_MASK) >> \ + REG_RING_PROD_SHIFT) + +#define TBT_REG_RING_CONS_EXTRACT (val) (((val) & REG_RING_CONS_MASK) >> \ + REG_RING_CONS_SHIFT)/* * 32 bytes per entry, one entry for every hop (REG_HOP_COUNT) * 00: enum_ring_flags @@ -77,6 +133,19 @@ struct ring_desc {* ..: unknown */ #define REG_RX_OPTIONS_BASE 0x29800 +#define REG_RX_OPTS_TX_E2E_HOP_ID_SHIFT 12 +#define REG_RX_OPTS_TX_E2E_HOP_ID_MASK \ + GENMASK(22, REG_RX_OPTS_TX_E2E_HOP_ID_SHIFT) +#define REG_RX_OPTS_MASK_OFFSET 4 +#define REG_RX_OPTS_MASK_EOF_SHIFT 0 +#define REG_RX_OPTS_MASK_EOF_MASK GENMASK(15, REG_RX_OPTS_MASK_EOF_SHIFT) +#define REG_RX_OPTS_MASK_SOF_SHIFT 16 +#define REG_RX_OPTS_MASK_SOF_MASK GENMASK(31, REG_RX_OPTS_MASK_SOF_SHIFT) + +#define REG_OPTS_STEP 32 +#define REG_OPTS_E2E_EN BIT(28) +#define REG_OPTS_RAW BIT(30) +#define REG_OPTS_VALID BIT(31)/* * three bitfields: tx, rx, rx overflow @@ -86,6 +155,7 @@ struct ring_desc {*/ #define REG_RING_NOTIFY_BASE 0x37800#define RING_NOTIFY_REG_COUNT (nhi) ((31 + 3 * nhi->hop_count) / 32) +#define REG_RING_NOTIFY_STEP 4/* * two bitfields: rx, tx @@ -94,8 +164,47 @@ struct ring_desc {*/ #define REG_RING_INTERRUPT_BASE 0x38200#define RING_INTERRUPT_REG_COUNT (nhi) ((31 + 2 * nhi->hop_count) / 32) +#define REG_RING_INT_TX_PROCESSED (ring_num) BIT(ring_num) +#define REG_RING_INT_RX_PROCESSED (ring_num, num_paths) BIT((ring_num) + \ + (num_paths)) +#define RING_INT_DISABLE (base, val) iowrite32( \ + ioread32((base) + REG_RING_INTERRUPT_BASE) & ~(val), \ + (base) + REG_RING_INTERRUPT_BASE) +#define RING_INT_ENABLE (base, val) iowrite32( \ + ioread32((base) + REG_RING_INTERRUPT_BASE) | (val), \ + (base) + REG_RING_INTERRUPT_BASE) +#define RING_INT_DISABLE_TX (base, ring_num) \ + RING_INT_DISABLE(base, REG_RING_INT_TX_PROCESSED(ring_num)) +#define RING_INT_DISABLE_RX (base, ring_num, num_paths) \ + RING_INT_DISABLE(base, REG_RING_INT_RX_PROCESSED(ring_num, num_paths)) +#define RING_INT_ENABLE_TX (base, ring_num) \ + RING_INT_ENABLE(base, REG_RING_INT_TX_PROCESSED(ring_num)) +#define RING_INT_ENABLE_RX (base, ring_num, num_paths) \ + RING_INT_ENABLE(base, REG_RING_INT_RX_PROCESSED(ring_num, num_paths)) +#define RING_INT_DISABLE_TX_RX (base, ring_num, num_paths) \ + RING_INT_DISABLE(base, REG_RING_INT_TX_PROCESSED(ring_num) | \ + REG_RING_INT_RX_PROCESSED(ring_num, num_paths)) + +#define REG_RING_INTERRUPT_STEP 4 + +#define REG_INT_THROTTLING_RATE 0x38c00 +#define REG_INT_THROTTLING_RATE_STEP 4 +#define NUM_INT_VECTORS 16 + +#define REG_INT_VEC_ALLOC_BASE 0x38c40 +#define REG_INT_VEC_ALLOC_STEP 4 +#define REG_INT_VEC_ALLOC_FIELD_BITS 4 +#define REG_INT_VEC_ALLOC_FIELD_MASK (BIT(REG_INT_VEC_ALLOC_FIELD_BITS) - 1) +#define REG_INT_VEC_ALLOC_PER_REG ((BITS_PER_BYTE * sizeof(u32)) / \ + REG_INT_VEC_ALLOC_FIELD_BITS)/* The last 11 bits contain the number of hops supported by the NHI port. */ #define REG_HOP_COUNT 0x39640 +#define REG_HOP_COUNT_TOTAL_PATHS_MASK GENMASK(10, 0) + +#define REG_HOST_INTERFACE_RST 0x39858 + +#define REG_DMA_MISC 0x39864 +#define REG_DMA_MISC_INT_AUTO_CLEAR BIT(2)#endif --2.7.4
RE: [PATCH v4 2/7] thunderbolt: Updating the register definitions
Quoted 31 lines · Andreas Noever
Quoted 29 lines · Amir Levy
Adding more Thunderbolt(TM) register definitions and some helper macros.
Signed-off-by Amir Levy <[email protected]>--- drivers/thunderbolt/nhi_regs.h | 109 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+)(quoted diff) +0
-0
b/drivers/thunderbolt/nhi_regs.hindex 75cf069..b8e961f 100644drivers/thunderbolt/nhi_regs.h +5
-0@@ -9,6 +9,11 @@#include <linux/types.h> +#define NHI_MMIO_BAR 0 + +#define TBT_RING_MIN_NUM_BUFFERS 2 +#define TBT_RING_MAX_FRAME_SIZE (4 * 1024) +enum ring_flags {RING_FLAG_ISOCH_ENABLE =1 <<27 ,/* TX only? */ RING_FLAG_E2E_FLOW_CONTROL = 1 << 28, @@ -39,6 +44,33 @@struct ring_desc { u32 time; /* write zero */}
__packed;
Quoted 16 lines
drivers/thunderbolt/nhi_regs.h struct ring_desc { · line 56
Quoted 11 lines
drivers/thunderbolt/nhi_regs.h +11
-0+/** +* struct tbt_buf_desc - TX/RX ring buffer descriptor. +* This is same as struct ring_desc, but without the use of bitfields +and +* with explicit endianity. +*/ +struct tbt_buf_desc { +__le64 phys; +__le32 attributes; +__le32 time; +};Does sharing this file make sense? The style seems to be quite different (structs with bitfields vs explicit bit-access). I think I would prefer separate register definitions, unless you are reusing a substantial amount (I have not checked).
I'm using all the macros from the original file, except the struct with the bitfields.
Amir
RE: [PATCH v4 5/7] thunderbolt: Networking state machine
In reply to Lukas WunnerQuoted 11 lines · Lukas Wunner
Review
Quoted 1 line · Amir Levy
(quoted diff) +1
-0+ const unique_id_be proto_uuid =
APPLE_THUNDERBOLT_IP_PROTOCOL_UUID;drivers/thunderbolt/icm/icm_nhi.c genl_put_reply_failure: · line 767
Quoted 3 lines
drivers/thunderbolt/icm/icm_nhi.c +3
-0+ +if (memcmp (proto_uuid, hdr->apple_tbt_ip_proto_uuid, +sizeof (proto_uuid)) !=0 ) {You may want to use the
uuid_bedata type provided by <linux/uuid.h> instead of rolling your own, as well as the helperuuid_be_cmp()defined ibidem.
All the messages in Thunderbolt consist BE DWORDs.
I didn't find uuid definition in the kernel that accurately describes the uuid structure in the messages, which is 4 BE DWORDs. But on the other hand, all the driver does is copy/compare of uuids, and it can treat uuids as byte array (i.e. uuid_be). I'll change it in the next patches.