Skip to contentSkip to conversation

thunderbolt: Introducing Thunderbolt(TM) networking

PATCH Superseded Amir Levy 5 participants 20 messages Jul 28, 2016 – Aug 1, 2016

Subsystems (5)

v5 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Amir Levy

author
#0 lore raw

v5 cover thunderbolt: Introducing Thunderbolt(TM) networking

This is version 5 of Thunderbolt(TM) driver for non-Apple hardware.

Changes since v4:
- Added Amir Levy as maintainer of thunderbolt/icm
- Replaced private uuid definitions with uuid_be

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 4:
[v4]: https://lkml.org/lkml/2016/7/18/171

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        | 1641 +++++++++++++++++++++
 drivers/thunderbolt/icm/icm_nhi.h        |   93 ++
 drivers/thunderbolt/icm/net.c            | 2267 ++++++++++++++++++++++++++++++
 drivers/thunderbolt/icm/net.h            |  270 ++++
 drivers/thunderbolt/nhi_regs.h           |  115 +-
 11 files changed, 4578 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
author
#1 lore raw

PATCH v5 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
index 86b996c..75cf069 100644
@@ -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
author
#2 lore raw

PATCH v5 2/8 thunderbolt: Updating the register definitions

In reply to Amir Levy

Adding 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
index 75cf069..b8e961f 100644
@@ -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
author
#3 lore raw

PATCH v5 3/8 thunderbolt: Kconfig for Thunderbolt(TM) networking

In reply to Amir Levy

Updating 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
index c121acc..d34b0f5 100644
@@ -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
index 5d1053c..7a85bd1 100644
@@ -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
author
#4 lore raw

PATCH v5 4/8 thunderbolt: Communication with the ICM (firmware)

In reply to 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.

---
 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
index 7a85bd1..b6aa6a3 100644
@@ -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
new file mode 100644
index 0000000..3adfc35
@@ -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
#5 lore raw

Re: [PATCH v5 4/8] thunderbolt: Communication with the ICM (firmware)

drivers/thunderbolt/icm/icm_nhi.c line 116

Quoted 2 lines · On Thu, 28 Jul 2016 11:15:17 +0300 Amir Levy <[email protected]> wrote:
drivers/thunderbolt/icm/icm_nhi.c new file +2 -0
+static LIST_HEAD(controllers_list);
+static DECLARE_RWSEM(controllers_list_rwsem);

Why use a semaphore when simple spinlock or mutex would be better?

#6 lore raw

Re: [PATCH v5 4/8] thunderbolt: Communication with the ICM (firmware)

Quoted 7 lines · Stephen Hemminger

drivers/thunderbolt/icm/icm_nhi.c line 116

Quoted 2 lines · On Thu, 28 Jul 2016 11:15:17 +0300 Amir Levy <[email protected]> wrote:
drivers/thunderbolt/icm/icm_nhi.c new file +2 -0
+static LIST_HEAD(controllers_list);
+static DECLARE_RWSEM(controllers_list_rwsem);

Why use a semaphore when simple spinlock or mutex would be better?

And never use a RW semaphore unless you can benchmark the difference from a normal lock. If you can't benchmark it, then don't use it...

#7 lore raw

RE: [PATCH v5 4/8] thunderbolt: Communication with the ICM (firmware)

Quoted 11 lines · Greg KH
Quoted 7 lines · Stephen Hemminger

Review

Quoted 2 lines · On Thu, 28 Jul 2016 11:15:17 +0300 Amir Levy <[email protected]> wrote:
(quoted diff) +2 -0
+static LIST_HEAD(controllers_list); static
+DECLARE_RWSEM(controllers_list_rwsem);

Why use a semaphore when simple spinlock or mutex would be better?

And never use a RW semaphore unless you can benchmark the difference from a normal lock. If you can't benchmark it, then don't use it...

I used RW semaphore since most of the time the list will be accessed for read. Since it is used in non-time sensitive flows, I'll change it to mutex.

#8 lore raw

Re: [PATCH v5 4/8] thunderbolt: Communication with the ICM (firmware)

In reply to Amir Levy

drivers/thunderbolt/icm/icm_nhi.c line 184

Quoted 3 lines · On Thu, 28 Jul 2016 11:15:17 +0300 Amir Levy <[email protected]> wrote:
drivers/thunderbolt/icm/icm_nhi.c new file +3 -0
+int nhi_send_message(struct tbt_nhi_ctxt *nhi_ctxt, enum pdf_value pdf,
+		     u32 msg_len, const u8 *msg, bool ignore_icm_resp)
+{

Why not make msg a void * and not have to do so many casts?

#9 lore raw

RE: [PATCH v5 4/8] thunderbolt: Communication with the ICM (firmware)

Quoted 8 lines · Stephen Hemminger
Quoted 1 line · On Thu, 28 Jul 2016 11:15:17 +0300 Amir Levy <[email protected]> wrote:

+int nhi_send_message(struct tbt_nhi_ctxt *nhi_ctxt, enum pdf_value

pdf,

Review

Quoted 1 line
(quoted diff) +1 -0
+		     u32 msg_len, const u8 *msg, bool ignore_icm_resp) {

Why not make msg a void * and not have to do so many casts?

I couldn't agree more.

author
#10 lore raw

PATCH v5 5/8 thunderbolt: Networking state machine

In reply to Amir Levy

Negotiation 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     | 792 ++++++++++++++++++++++++++++++++++++++
 drivers/thunderbolt/icm/net.h     |  70 ++++
 4 files changed, 1156 insertions(+), 11 deletions(-)
 create mode 100644 drivers/thunderbolt/icm/net.c
drivers/thunderbolt/icm/Makefile +1 -1
index 3adfc35..624ee31 100644
@@ -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 +792 -0

792 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
#11 lore raw

Re: [PATCH v5 5/8] thunderbolt: Networking state machine

Quoted 5 lines · Amir Levy
drivers/thunderbolt/icm/icm_nhi.c +5 -0
+static void nhi_handle_notification_msg(struct tbt_nhi_ctxt *nhi_ctxt,
+					const u8 *msg)
+{
+	struct port_net_dev *port;
+	u8 port_num;

drivers/thunderbolt/icm/icm_nhi.c genl_put_reply_failure: · line 814

Quoted 10 lines
drivers/thunderbolt/icm/icm_nhi.c +10 -0
+
+#define INTER_DOMAIN_LINK_SHIFT 0
+#define INTER_DOMAIN_LINK_MASK	GENMASK(2, INTER_DOMAIN_LINK_SHIFT)
+	switch (msg[3]) {
+
+	case NC_INTER_DOMAIN_CONNECTED:
+		port_num = PORT_NUM_FROM_MSG(msg[5]);
+#define INTER_DOMAIN_APPROVED BIT(3)
+		if (likely(port_num < nhi_ctxt->num_ports)) {
+			if (!(msg[5] & INTER_DOMAIN_APPROVED))

I find these interspersed #defines make the code hard to read, but maybe that's just me.

drivers/thunderbolt/icm/icm_nhi.c genl_put_reply_failure: · line 816

Quoted 2 lines
drivers/thunderbolt/icm/icm_nhi.c +2 -0
+				nhi_ctxt->net_devices[
+					port_num].medium_sts =

Looks like a carriage return slipped in here.

In patch [4/8], I've found it a bit puzzling that FW->SW responses and FW->SW notifications are defined in icm_nhi.c, whereas SW->FW commands are defined in net.h. It would perhaps be more logical to have them all in the header file. The FW->SW responses and SW->FW commands are almost identical, there are odd spelling differences (CONNEXION vs. CONNECTION).

It would probably be good to explain the PDF acronym somewhere.

I've skimmed over all patches in the series, too superficial to provide a Reviewed-by, it's just too much code to review thoroughly and I also lack the hardware to test it, but broadly this LGTM.

Thanks,

Lukas

#12 lore raw

RE: [PATCH v5 5/8] thunderbolt: Networking state machine

Quoted 5 lines · Lukas Wunner

drivers/thunderbolt/icm/icm_nhi.c genl_put_reply_failure: · line 816

Quoted 2 lines · Amir Levy
drivers/thunderbolt/icm/icm_nhi.c +2 -0
+				nhi_ctxt->net_devices[
+					port_num].medium_sts =

Looks like a carriage return slipped in here.

Will be fixed.

Quoted 7 lines

In patch [4/8], I've found it a bit puzzling that FW->SW responses and FW->SW notifications are defined in icm_nhi.c, whereas SW->FW commands are defined in net.h. It would perhaps be more logical to have them all in the header file. The FW->SW responses and SW->FW commands are almost identical, there are odd spelling differences (CONNEXION vs. CONNECTION).

Will move them to the header and will change to CONNECTION.

Quoted 2 lines

It would probably be good to explain the PDF acronym somewhere.

Will explain in the enum.

Quoted 4 lines

I've skimmed over all patches in the series, too superficial to provide a Reviewed-by, it's just too much code to review thoroughly and I also lack the hardware to test it, but broadly this LGTM.

Thank you for the review.

author
#13 lore raw

PATCH v5 6/8 thunderbolt: Networking transmit and receive

In reply to Amir Levy

Handling 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
index e491b0e..efadf9c 100644
@@ -1055,6 +1055,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);
@@ -1077,6 +1078,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 & REG_RING_INT_RX_PROCESSED(
+					path, nhi_ctxt->num_paths))
+				tbt_net_rx_msi(net_dev);
+			if (isr0 & REG_RING_INT_TX_PROCESSED(path))
+				tbt_net_tx_msi(net_dev);
+		}
+	}
+
 	if (isr0 & REG_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
#14 lore raw

Re: [PATCH v5 6/8] thunderbolt: Networking transmit and receive

drivers/thunderbolt/icm/net.c static void tbt_net_tear_down(struct net_device *net_dev, bool send_logout) · line 902

Quoted 11 lines · On Thu, 28 Jul 2016 11:15:19 +0300 Amir Levy <[email protected]> wrote:
drivers/thunderbolt/icm/net.c +11 -0
+		/* pad short packets */
+		if (unlikely(skb->len < ETH_ZLEN)) {
+			int pad_len = ETH_ZLEN - skb->len;
+
+			/* The skb is freed on error */
+			if (unlikely(skb_pad(skb, pad_len))) {
+				cleaned_count += frame_count;
+				continue;
+			}
+			__skb_put(skb, pad_len);
+		}

Packets should be padded on transmit, not on receive??

#15 lore raw

RE: [PATCH v5 6/8] thunderbolt: Networking transmit and receive

Quoted 16 lines · Stephen Hemminger

drivers/thunderbolt/icm/net.c static void tbt_net_tear_down(struct net_device *net_dev, bool send_logout) · line 902

Quoted 11 lines · On Thu, 28 Jul 2016 11:15:19 +0300 Amir Levy <[email protected]> wrote:
drivers/thunderbolt/icm/net.c +11 -0
+		/* pad short packets */
+		if (unlikely(skb->len < ETH_ZLEN)) {
+			int pad_len = ETH_ZLEN - skb->len;
+
+			/* The skb is freed on error */
+			if (unlikely(skb_pad(skb, pad_len))) {
+				cleaned_count += frame_count;
+				continue;
+			}
+			__skb_put(skb, pad_len);
+		}

Packets should be padded on transmit, not on receive??

This driver emulates an Ethernet adapter on top of Thunderbolt technology.
The Thunderbolt medium hasn't any restriction on minimum frame size and doesn't have the Ethernet collision detection limitation. So moving this code from transmit is actually an optimization - sending the minimum on the wire.
The network stack thinks it is Ethernet, it might not accept Runt frames, so the driver pads the frame in receive.

Looks like it deserves a comment in the code. Will add it.

maintainer
#16 lore raw

Re: [PATCH v5 6/8] thunderbolt: Networking transmit and receive

From: "Levy, Amir (Jer)" <[email protected]>
Date: Sun, 31 Jul 2016 10:15:52 +0000

Quoted 2 lines

The network stack thinks it is Ethernet, it might not accept Runt frames, so the driver pads the frame in receive.

The network stack doesn't care about this at all. It's wasted effort on your part.

#17 lore raw

RE: [PATCH v5 6/8] thunderbolt: Networking transmit and receive

Quoted 8 lines · David Miller

From: "Levy, Amir (Jer)" <[email protected]>
Date: Sun, 31 Jul 2016 10:15:52 +0000

Quoted 2 lines

The network stack thinks it is Ethernet, it might not accept Runt frames, so the driver pads the frame in receive.

The network stack doesn't care about this at all. It's wasted effort on your part.

Great, I'll remove this code.

author
#18 lore raw

PATCH v5 7/8 thunderbolt: Networking doc

In reply to Amir Levy

Adding 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
index cb9a6c6..80a6706 100644
@@ -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
author
#19 lore raw

PATCH v5 8/8 thunderbolt: Adding maintainer entry

In reply to Amir Levy

Add Amir Levy as maintainer for Thunderbolt(TM) ICM driver

---
 MAINTAINERS | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
MAINTAINERS +7 -1
index 771c31c..5f24eb2 100644
@@ -10141,7 +10141,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