thunderbolt: Introducing Thunderbolt(TM) networking
Subsystems (5)
v6 cover thunderbolt: Introducing Thunderbolt(TM) networking
This is version 6 of Thunderbolt(TM) driver for non-Apple hardware.
Changes since v5:
- Removed the padding of short packets in receive
- Replaced RW semaphore with mutex
- Cleanup
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 5:
[v5]: https://lkml.org/lkml/2016/7/28/85
Amir Levy (8):
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
thunderbolt: Adding maintainer entry
Documentation/00-INDEX | 2 + Documentation/thunderbolt-networking.txt | 135 ++ MAINTAINERS | 8 +- drivers/thunderbolt/Kconfig | 25 +- drivers/thunderbolt/Makefile | 3 +- drivers/thunderbolt/icm/Makefile | 28 + drivers/thunderbolt/icm/icm_nhi.c | 1622 +++++++++++++++++++++ drivers/thunderbolt/icm/icm_nhi.h | 93 ++ drivers/thunderbolt/icm/net.c | 2264 ++++++++++++++++++++++++++++++ drivers/thunderbolt/icm/net.h | 297 ++++ drivers/thunderbolt/nhi_regs.h | 115 +- 11 files changed, 4583 insertions(+), 9 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 v6 1/8 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
Andreas Noever
maintainerRe: [PATCH v6 1/8] thunderbolt: Macro rename
Quoted 29 lines · Amir Levy
This first patch updates the registers file to
reflect that it isn't only for Cactus Ridge.
No functional change intended.Signed-off-by Amir Levy <[email protected]>--- drivers/thunderbolt/nhi_regs.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/thunderbolt/nhi_regs.h +3
-4@@ -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> --
Quoted 1 line
2.7.4
PATCH v6 2/8 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
Andreas Noever
maintainerRe: [PATCH v6 2/8] thunderbolt: Updating the register definitions
Quoted 2 lines · Amir Levy
Adding more Thunderbolt(TM) register definitions
and some helper macros.
Thinking about this again I would prefer it if you would put your definitions into a separate file under icm/ (even if there is some duplication). The style (bitfields vs. genmask) is different between the drivers and for a reader it is difficult to find out what is actually supposed to be used by the two drivers (ring_desc vs tbt_buf_desc or the ring RING_INT_EN/DISABLE macros in the header file vs. ring_interrupt_active in nhi.c).
This would also completely separate the two drivers.
Andreas
Quoted 165 lines
Signed-off-by Amir Levy <[email protected]>--- drivers/thunderbolt/nhi_regs.h | 109 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+)drivers/thunderbolt/nhi_regs.h +109
-1@@ -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 --2.7.4
RE: [PATCH v6 2/8] thunderbolt: Updating the register definitions
Quoted 11 lines · Andreas Noever
Quoted 2 lines · Amir Levy
Adding more Thunderbolt(TM) register definitions and some helper macros.
Thinking about this again I would prefer it if you would put your definitions into a separate file under icm/ (even if there is some duplication). The style (bitfields vs. genmask) is different between the drivers and for a reader it is difficult to find out what is actually supposed to be used by the two drivers (
ring_descvstbt_buf_descor the ring RING_INT_EN/DISABLE macros in the header file vs.ring_interrupt_activeinnhi.c).
Quoted 4 lines
This would also completely separate the two drivers.
Andreas
I'm also in favor of completely separating the drivers, but is it the right thing to do with the register definitions when the underlying registers layout is exactly the same?
Note that bitfields are not so recommended when you care about the format/order of bits, like in the ring descriptor.
Amir
PATCH v6 3/8 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
Re: [PATCH v6 3/8] thunderbolt: Kconfig for Thunderbolt(TM) networking
Quoted 1 line · Amir Levy
Updating the
KconfigThunderbolt(TM) description.
Why are you inserting a (TM) in here? Do you see that in any other kernel Kconfig file? Please don't start adding it here, it's not needed from what I can tell.
thanks,
greg k-h
Re: [PATCH v6 3/8] thunderbolt: Kconfig for Thunderbolt(TM) networking
In reply to Amir LevyQuoted 17 lines · Amir Levy
Updating the
KconfigThunderbolt(TM) description.Signed-off-by Amir Levy <[email protected]>--- drivers/thunderbolt/Kconfig | 25 +++++++++++++++++++++---- drivers/thunderbolt/Makefile | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-)drivers/thunderbolt/Kconfig +2
-2@@ -1,13 +1,30 @@ -menuconfig THUNDERBOLT - tristate "Thunderbolt support for Apple devices" +config THUNDERBOLT + tristate "Thunderbolt(TM) support"
drivers/thunderbolt/Kconfig line 11
Quoted 10 lines
drivers/thunderbolt/Kconfig +6
-1depends on PCI select CRC32 help - Cactus Ridge Thunderbolt Controller driver + Thunderbolt(TM) Controller driver + +if THUNDERBOLT + +config THUNDERBOLT_APPLE + tristate "Apple hardware support"
Wait, what? What about my non-apple thunderbolt hardware? Did that just suddenly stop working? Why rename this option?
greg k-h
PATCH v6 4/8 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 | 1324 +++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/icm/icm_nhi.h | 93 +++ drivers/thunderbolt/icm/net.h | 227 +++++++ 5 files changed, 1673 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 +1324 -0
1,324 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 +227 -0
227 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v6 4/8] thunderbolt: Communication with the ICM (firmware)
Quoted 41 lines · Amir Levy
Firmware-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.
Signed-off-by Amir Levy <[email protected]>--- drivers/thunderbolt/Makefile | 1 + drivers/thunderbolt/icm/Makefile | 28 + drivers/thunderbolt/icm/icm_nhi.c | 1324 +++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/icm/icm_nhi.h | 93 +++ drivers/thunderbolt/icm/net.h | 227 +++++++ 5 files changed, 1673 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.hdrivers/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 +9
-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. +#
drivers/thunderbolt/icm/Makefile line 19
Quoted 10 lines
drivers/thunderbolt/icm/Makefile new file +10
-0+# 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".
Why are these two paragraphs needed?
drivers/thunderbolt/icm/Makefile line 23
Quoted 4 lines
drivers/thunderbolt/icm/Makefile new file +4
-0+# +# Contact Information: +# Intel Thunderbolt Mailing List <[email protected]> +# Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
We try to stay away from addresses in kernel files as no one wants to maintain the corporate movements of companies for years to come. Are you willing to do this for the next 40 years?
drivers/thunderbolt/icm/Makefile line 28
Quoted 5 lines
drivers/thunderbolt/icm/Makefile new file +5
-0+# +################################################################################ + +obj-${CONFIG_THUNDERBOLT_ICM} += thunderbolt-icm.o +thunderbolt-icm-objs := icm_nhi.o
All of that for a simple 2 line Makefile? Please no, just have a 2 line Makefile...
And you don't have a Kconfig file that adds this option, right?
What exactly does this driver do? Why would I want it enabled? I'm lost...
Quoted 31 lines
drivers/thunderbolt/icm/icm_nhi.c new file +25
-0@@ -0,0 +1,1324 @@ +/******************************************************************************* +* +* 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 +* +******************************************************************************/
drivers/thunderbolt/icm/icm_nhi.c line 35
Quoted 10 lines
drivers/thunderbolt/icm/icm_nhi.c new file +10
-0+ +#include <linux/printk.h> +#include <linux/crc32.h> +#include <linux/delay.h> +#include <linux/dmi.h> +#include "icm_nhi.h" +#include "net.h" + +#define NHI_GENL_VERSION 1 +#define NHI_GENL_NAME DRV_NAME
Why not just use DRV_NAME?
Why have this at all? Why even have DRV_NAME? Seems useless as you are not going to change it.
thanks,
greg k-h
PATCH v6 5/8 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 | 303 ++++++++++++++- drivers/thunderbolt/icm/net.c | 793 ++++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/icm/net.h | 70 ++++ 4 files changed, 1157 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 +293 -10
363 lines not on this page · raw message
drivers/thunderbolt/icm/net.c new file +793 -0
793 lines not on this page · raw message
drivers/thunderbolt/icm/net.h +70 -0
105 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v6 5/8] thunderbolt: Networking state machine
Quoted 2 lines · Amir Levy
Negotiation states that a peer goes through in order to establish the communication with the second peer.
I can not parse that sentance, what exactly does that mean?
Quoted 2 lines
This includes communication with upper layer and additional infrastructure support to communicate with the second peer through ICM.
This too is unparsable. Please explain what this patch does in terms that are understandable for someone with at least a passing understanding of hardware busses. As it is, I have no idea what this patch does at all, and I should be your target audience for this changelog.
thanks,
greg k-h
PATCH v6 6/8 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 | 1471 +++++++++++++++++++++++++++++++++++++ 2 files changed, 1486 insertions(+)
drivers/thunderbolt/icm/icm_nhi.c +15 -0
@@ -1036,6 +1036,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 );
@@ -1058,6 +1059,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 +1471 -0
1,563 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v6 7/8 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
Re: [PATCH v6 7/8] thunderbolt: Networking doc
Quoted 6 lines · Amir Levy
Adding Thunderbolt(TM) networking documentation.
Signed-off-by Amir Levy <[email protected]>--- Documentation/00-INDEX | 2 + Documentation/thunderbolt-networking.txt | 135 +++++++++++++++++++++++++++++++
Documentation/thunderbolt/networking.txt?
Quoted 25 lines
2 files changed, 137 insertions(+) create mode 100644 Documentation/thunderbolt-networking.txtDocumentation/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.txtDocumentation/thunderbolt-networking.txt new file +3
-0@@ -0,0 +1,135 @@ +Intel Thunderbolt(TM) Linux driver +================================== +
Documentation/thunderbolt-networking.txt line 13
Quoted 10 lines
Documentation/thunderbolt-networking.txt new file +10
-0+Copyright(c) 2013 - 2016 Intel Corporation. + +Contact Information: +Intel Thunderbolt mailing list <[email protected]> +Edited by Michael Jamet <[email protected]> + +Overview +======== + +Thunderbolt(TM) Networking mode is introduced with this driver.
What is "this driver"?
Documentation/thunderbolt-networking.txt line 15
Quoted 2 lines
Documentation/thunderbolt-networking.txt new file +2
-0+This kernel code creates an ethernet device utilized in computer to computer +communication over a Thunderbolt cable.
What kernel code?
Documentation/thunderbolt-networking.txt line 18
Quoted 3 lines
Documentation/thunderbolt-networking.txt new file +3
-0+This driver has been added on the top of the existing thunderbolt driver +for systems with firwmare (FW) based Thunderbolt controllers supporting +Thunderbolt Networking.
How do I know if my hardware supports this or not?
Documentation/thunderbolt-networking.txt line 28
Quoted 10 lines
Documentation/thunderbolt-networking.txt new file +10
-0+ +Files +===== + +- icm_nhi.c/h: These files allow communication with the FW (a.k.a ICM) based controller. + In addition, they create an interface for netlink communication with + a user space daemon. + +- net.c/net.h: These files implement the 'eth' interface for the Thunderbolt(TM) + networking.
Where are these files? Not in this documentation directory :(
Quoted 20 lines
Documentation/thunderbolt-networking.txt new file +20
-0+ +Interface to user space +======================= + +The interface to the user space module is implemented through a Generic Netlink. +In order to be accessed by the user space module, both kernel and user space +modules have to register with the same GENL_NAME. In our case, this is +simply "thunderbolt". +The registration is done at driver initialization time for all instances of +the Thunderbolt controllers. +The communication is then carried through pre-defined Thunderbolt messages. +Each specific message has a callback function that is called when +the related message is received. + +The messages are defined as follows: +* NHI_CMD_UNSPEC: Not used. +* NHI_CMD_SUBSCRIBE: Subscription request from daemon to driver to open the + communication channel. +* NHI_CMD_UNSUBSCRIBE: Request from daemon to driver to unsubscribe + to close communication channel.
Documentation/thunderbolt-networking.txt line 58
Quoted 10 lines
Documentation/thunderbolt-networking.txt new file +10
-0+* NHI_CMD_QUERY_INFORMATION: Request information from the driver such as + driver version, FW version offset, number of ports in the controller + and DMA port. +* NHI_CMD_MSG_TO_ICM: Message from user space module to FW. +* NHI_CMD_MSG_FROM_ICM: Response from FW to user space module. +* NHI_CMD_MAILBOX: Message that uses mailbox mechanism such as FW policy + changes or disconnect path. +* NHI_CMD_APPROVE_TBT_NETWORKING: Request from user space + module to FW to establish path. +* NHI_CMD_ICM_IN_SAFE_MODE: Indication that the FW has entered safe mode.
I want an ack from the network maintainers that this is an acceptable way to configure a network device, and that you aren't just reimplementing something that can already be done with existing tools.
Creating new apis seems really strange to me, you will have to really convince me why you are "special" and need one.
Documentation/thunderbolt-networking.txt line 64
Quoted 6 lines
Documentation/thunderbolt-networking.txt new file +6
-0+ +Communication with ICM (Firmware) +================================= + +The communication with ICM is principally achieved through +a DMA mechanism on Ring 0.
Where is this ring 0?
Why does a user/developer care about it?
Documentation/thunderbolt-networking.txt line 66
Quoted 2 lines
Documentation/thunderbolt-networking.txt new file +2
-0+The driver allocates a shared memory that is physically mapped onto +the DMA physical space at Ring 0.
Again ring 0?
Quoted 12 lines
Documentation/thunderbolt-networking.txt new file +12
-0+ +Interrupts +========== + +Thunderbolt relies on MSI-X interrupts. +The MSI-X vector is allocated as follows: +ICM + - Tx: MSI-X vector index 0 + - Rx: MSI-X vector index 1 + +Port 0 + - Tx: MSI-X vector index 2
Documentation/thunderbolt-networking.txt line 88
Quoted 10 lines
Documentation/thunderbolt-networking.txt new file +10
-0+ - Rx: MSI-X vector index 3 + +Port 1 + - Tx: MSI-X vector index 4 + - Rx: MSI-X vector index 5 + +ICM interrupts are used for communication with ICM only. +Port 0 and Port 1 interrupts are used for Thunderbolt Networking +communications. +In case MSI-X is not available, the driver requests to enable MSI only.
Is this section even really needed? What can anyone do with it?
Quoted 15 lines
Documentation/thunderbolt-networking.txt new file +15
-0+ +Mutexes, semaphores and spinlocks +================================= + +The driver should be able to operate in an environment where hardware +is asynchronously accessed by multiple entities such as netlink, +multiple controllers etc. + +* send_sem: This semaphore enforces unique sender (one sender at a time) + to avoid wrong impairing with responses. FW may process one message + at the time. +* d0_exit_send_mutex: This mutex protects D0 exit (D3) situation + to avoid continuing to send messages to FW. +* d0_exit_mailbox_mutex: This mutex protects D0 exit (D3) situation to + avoid continuing to send commands to mailbox.
Documentation/thunderbolt-networking.txt line 113
Quoted 10 lines
Documentation/thunderbolt-networking.txt new file +10
-0+* mailbox_mutex: This mutex enforces unique sender (one sender at a time) + for the mailbox command. + A mutex is sufficient since the mailbox mechanism uses a polling mechanism + to get the command response. +* lock: This spinlock protects from simultaneous changes during + disable/enable interrupts. +* state_lock: This mutex comes to protect changes during net device state + changes and net_device operations. +* controllers_list_mutex: This mutex syncs the access to the controllers + list when there are multiple controllers in the system.
Why aren't these locks documented in the code itself? Having it out here makes no sense as it will get out of date and will never be looked at. Put it in the code please.
Documentation/thunderbolt-networking.txt line 119
Quoted 6 lines
Documentation/thunderbolt-networking.txt new file +6
-0+ +FW path enablement +================== + +In order to SW to communicate with the FW, the driver needs to send to FW +the PDF driver ready command and receive response from FW.
PDF? What does that mean? This is the first time I've seen that term in this file.
Documentation/thunderbolt-networking.txt line 120
Quoted 1 line
Documentation/thunderbolt-networking.txt new file +1
-0+The driver ready command PDF value is 12 and the response is 13.
Ok, so?
Documentation/thunderbolt-networking.txt line 123
Quoted 3 lines
Documentation/thunderbolt-networking.txt new file +3
-0+Once the exchange is completed, the user space module should be able to send +messages through the driver to the FW and FW starts to send notifications +about HW/FW events.
What does userspace have to do with this? Why do they care?
This documentation is really confusing, and I thought I understood how thunderbolt systems worked :(
greg k-h
PATCH v6 8/8 thunderbolt: Adding maintainer entry
In reply to Amir LevyAdd Amir Levy as maintainer for Thunderbolt(TM) ICM driver
--- MAINTAINERS | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
MAINTAINERS +7 -1
@@ -10193,7 +10193,13 @@ F: include/uapi/linux/stm.h THUNDERBOLT DRIVER M: Andreas Noever <[email protected]> S: Maintained -F: drivers/thunderbolt/ +F: drivers/thunderbolt/* + +THUNDERBOLT ICM DRIVER +M: Amir Levy <[email protected]> +S: Maintained +F: drivers/thunderbolt/icm/ +F: Documentation/thunderbolt-networking.txt TI BQ27XXX POWER SUPPLY DRIVER R: Andrew F. Davis <[email protected]>
Signature · 1 line
2.7.4
Quoted 11 lines · Amir Levy
This is version 6 of Thunderbolt(TM) driver for non-Apple hardware.
Changes since v5:
- Removed the padding of short packets in receive
- Replaced RW semaphore with mutex
- CleanupThese patches were pushed to GitHub where they can be reviewed more comfortably with green/red highlighting:
https://github.com/01org/thunderbolt-software-kernel-tree
Quoted 5 lines
Daemon code:
https://github.com/01org/thunderbolt-software-daemonFor reference, here's a link to version 5:
[v5]: https://lkml.org/lkml/2016/7/28/85
Without acks from the thunderbolt maintainer, or any network driver developers, I'm not going to take this series. Please work to get that review.
thanks,
greg k-h
Andreas Noever
maintainerQuoted 15 lines · Greg KH
Quoted 14 lines · Amir Levy
This is version 6 of Thunderbolt(TM) driver for non-Apple hardware.
Changes since v5:
- Removed the padding of short packets in receive
- Replaced RW semaphore with mutex
- CleanupThese 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-daemon
Quoted 6 lines
Quoted 2 lines
For reference, here's a link to version 5:
[v5]: https://lkml.org/lkml/2016/7/28/85Without acks from the thunderbolt maintainer, or any network driver developers, I'm not going to take this series. Please work to get that review.
Sorry for the late response. I was away for the last two weeks and will be away again for the next week.
This driver is independent from mine. It uses an interface provided by the firmware which is not present on Apple hardware and with which I am not familiar (also it does networking, not pci with which I am also not familiar). So I cannot comment on the driver itself. I don't mind a second driver, if that is what you are asking.
Andreas