thunderbolt: Introducing Thunderbolt(TM) networking
Subsystems (5)
v3 cover thunderbolt: Introducing Thunderbolt(TM) networking
This is version 3 of Thunderbolt(TM) driver for non-Apple hardware.
Changes since v2:
- Moved ICM code to subdirectory - thunderbolt/icm
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 2:
[v2]: https://lkml.org/lkml/2016/6/29/160
Amir Levy (8):
thunderbolt: Macro rename
thunderbolt: Updating device IDs
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 | 1631 +++++++++++++++++++++ drivers/thunderbolt/icm/icm_nhi.h | 84 ++ drivers/thunderbolt/icm/net.c | 2277 ++++++++++++++++++++++++++++++ drivers/thunderbolt/icm/net.h | 274 ++++ drivers/thunderbolt/nhi_regs.h | 115 +- include/linux/pci_ids.h | 44 +- 11 files changed, 4592 insertions(+), 26 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 v3 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
PATCH v3 2/8 thunderbolt: Updating device IDs
In reply to Amir LevyAdding the new Thunderbolt(TM) device IDs to the list.
--- include/linux/pci_ids.h | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-)
include/linux/pci_ids.h +26 -18
@@ -2604,24 +2604,32 @@#define PCI_DEVICE_ID_INTEL_82441 0x1237#define PCI_DEVICE_ID_INTEL_82380FB 0x124b#define PCI_DEVICE_ID_INTEL_82439 0x1250 -#define PCI_DEVICE_ID_INTEL_LIGHT_RIDGE 0x1513/* Tbt 1 Gen 1 */ -#define PCI_DEVICE_ID_INTEL_EAGLE_RIDGE 0x151a -#define PCI_DEVICE_ID_INTEL_LIGHT_PEAK 0x151b -#define PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C 0x1547/* Tbt 1 Gen 2 */ -#define PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_2C 0x1548 -#define PCI_DEVICE_ID_INTEL_PORT_RIDGE 0x1549 -#define PCI_DEVICE_ID_INTEL_REDWOOD_RIDGE_2C_NHI 0x1566/* Tbt 1 Gen 3 */ -#define PCI_DEVICE_ID_INTEL_REDWOOD_RIDGE_2C_BRIDGE 0x1567 -#define PCI_DEVICE_ID_INTEL_REDWOOD_RIDGE_4C_NHI 0x1568 -#define PCI_DEVICE_ID_INTEL_REDWOOD_RIDGE_4C_BRIDGE 0x1569 -#define PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_NHI 0x156a/* Thunderbolt 2 */ -#define PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_BRIDGE 0x156b -#define PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_NHI 0x156c -#define PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_BRIDGE 0x156d -#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_NHI 0x1575/* Thunderbolt 3 */ -#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_BRIDGE 0x1576 -#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_NHI 0x1577 -#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_BRIDGE 0x1578 +#define PCI_DEVICE_ID_INTEL_LIGHT_RIDGE 0x1513/* Tbt 1 Gen 1 */ +#define PCI_DEVICE_ID_INTEL_EAGLE_RIDGE 0x151a +#define PCI_DEVICE_ID_INTEL_LIGHT_PEAK 0x151b +#define PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C 0x1547/* Tbt 1 Gen 2 */ +#define PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_2C 0x1548 +#define PCI_DEVICE_ID_INTEL_PORT_RIDGE 0x1549 +#define PCI_DEVICE_ID_INTEL_REDWOOD_RIDGE_2C_NHI 0x1566/* Tbt 1 Gen 3 */ +#define PCI_DEVICE_ID_INTEL_REDWOOD_RIDGE_2C_BRIDGE 0x1567 +#define PCI_DEVICE_ID_INTEL_REDWOOD_RIDGE_4C_NHI 0x1568 +#define PCI_DEVICE_ID_INTEL_REDWOOD_RIDGE_4C_BRIDGE 0x1569 +#define PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_NHI 0x156a/* Thunderbolt 2 */ +#define PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_BRIDGE 0x156b +#define PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_NHI 0x156c +#define PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_BRIDGE 0x156d +#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_NHI 0x1575/* Thunderbolt 3 */ +#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_BRIDGE 0x1576 +#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_NHI 0x1577 +#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_BRIDGE 0x1578 +#define PCI_DEVICE_ID_INTEL_WIN_RIDGE_2C_NHI 0x157d/* Tbt 2 Low Pwr */ +#define PCI_DEVICE_ID_INTEL_WIN_RIDGE_2C_BRIDGE 0x157e +#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_NHI 0x15bf/* Tbt 3 Low Pwr */ +#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_BRIDGE 0x15c0 +#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_NHI 0x15d2/* Thunderbolt 3 */ +#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_BRIDGE 0x15d3 +#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_NHI 0x15d9 +#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_BRIDGE 0x15da#define PCI_DEVICE_ID_INTEL_80960_RP 0x1960#define PCI_DEVICE_ID_INTEL_82840_HB 0x1a21#define PCI_DEVICE_ID_INTEL_82845_HB 0x1a30
Signature · 1 line
2.7.4
PATCH v3 3/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
PATCH v3 4/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
PATCH v3 5/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 | 1332 +++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/icm/icm_nhi.h | 84 +++ drivers/thunderbolt/icm/net.h | 200 ++++++ 5 files changed, 1645 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 +1332 -0
1,332 lines not on this page · raw message
drivers/thunderbolt/icm/icm_nhi.h new file +84 -0
84 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 v3 6/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 | 304 ++++++++++++++- drivers/thunderbolt/icm/net.c | 802 ++++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/icm/net.h | 74 ++++ 4 files changed, 1171 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 +802 -0
802 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 v3 7/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 | 1475 +++++++++++++++++++++++++++++++++++++ 2 files changed, 1490 insertions(+)
drivers/thunderbolt/icm/icm_nhi.c +15 -0
@@ -1045,6 +1045,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 );
@@ -1067,6 +1068,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
PATCH v3 8/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 v3 5/8] thunderbolt: Communication with the ICM (firmware)
In reply to Amir LevyQuoted 65 lines
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 | 1332 +++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/icm/icm_nhi.h | 84 +++ drivers/thunderbolt/icm/net.h | 200 ++++++ 5 files changed, 1645 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 +0
-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.oeeprom.o
drivers/thunderbolt/Makefile +1
-0+obj-${CONFIG_THUNDERBOLT_ICM} += icm/drivers/thunderbolt/icm/Makefile new file +1
-0@@ -0,0 +1,28 @@ +################################################################################
drivers/thunderbolt/icm/Makefile new file +10
-0+# +# 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 ofMERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License fordrivers/thunderbolt/icm/Makefile new file +13
-0+# 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/Makefile line 28
Quoted 3 lines
drivers/thunderbolt/icm/Makefile new file +3
-0+ +obj-${CONFIG_THUNDERBOLT_ICM} += thunderbolt-icm.o +thunderbolt-icm-objs := icm_nhi.o
It would be cleaner if you add the Makefile + Kconfig in a separate patch
Quoted 66 lines
drivers/thunderbolt/icm/icm_nhi.c new file +1
-0@@ -0,0 +1,1332 @@ +/********************************************************* **********************
+ *
+ * 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 new file +12
-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 + +#define DEVICE_DATA(num_ports, dma_port, nvm_ver_offset,nvm_auth_on_boot,\
drivers/thunderbolt/icm/icm_nhi.c new file +5
-0+ support_full_e2e) \ + ((num_ports) | ((dma_port) <<4 ) | ((nvm_ver_offset) <<10 ) | \ + ((nvm_auth_on_boot) << 22) | ((support_full_e2e) << 23)) +#define DEVICE_DATA_NUM_PORTS (device_data) ((device_data) & 0xf) +#define DEVICE_DATA_DMA_PORT (device_data) (((device_data) >> 4) &
0x3f)
+#defineDEVICE_DATA_NVM_VER_OFFSET(device_data)(((device_data)Quoted 1 line
Quoted 1 line
10) &
0xfff)+#define
DEVICE_DATA_NVM_AUTH_ON_BOOT(device_data)(((device_data) >> 22) &0x1)
+#defineDEVICE_DATA_SUPPORT_FULL_E2E(device_data)(((device_data)Quoted 1 line
Quoted 1 line
23) &
0x1)drivers/thunderbolt/icm/icm_nhi.c new file +2
-0+ +#define USEC_TO_256_NSECS (usec) DIV_ROUND_UP((usec) *
NSEC_PER_USEC, 256)
drivers/thunderbolt/icm/icm_nhi.c line 51
Quoted 4 lines
drivers/thunderbolt/icm/icm_nhi.c new file +4
-0+ +/* +* FW->SW responses +* RC = response code
More verbose will be better
Quoted 5 lines
+ */
drivers/thunderbolt/icm/icm_nhi.c new file +4
-0+enum { +RC_GET_TBT_TOPOLOGY =1 , +RC_GET_VIDEO_RESOURCES_DATA , +RC_DRV_READY ,
drivers/thunderbolt/icm/icm_nhi.c line 66
Quoted 10 lines
drivers/thunderbolt/icm/icm_nhi.c new file +10
-0+RC_APPROVE_PCI_CONNEXION , +RC_CHALLENGE_PCI_CONNEXION , +RC_ADD_DEVICE_AND_KEY , +RC_INTER_DOMAIN_PKT_SENT =8 , + RC_APPROVE_INTER_DOMAIN_CONNEXION = 0x10 +}; + +/* +* FW->SW notifications +* NC = notification code
Same here
Quoted 13 lines
+ */
drivers/thunderbolt/icm/icm_nhi.c new file +12
-0+enum { +NC_DEVICE_CONNECTED =3 , +NC_DEVICE_DISCONNECTED , +NC_DP_DEVICE_CONNECTED_NOT_TUNNELED , +NC_INTER_DOMAIN_CONNECTED , +NC_INTER_DOMAIN_DISCONNECTED +}; + +/* NHI genetlink commands */ +enum { +NHI_CMD_UNSPEC , +NHI_CMD_SUBSCRIBE ,
drivers/thunderbolt/icm/icm_nhi.c line 89
Quoted 10 lines
drivers/thunderbolt/icm/icm_nhi.c new file +10
-0+NHI_CMD_UNSUBSCRIBE , +NHI_CMD_QUERY_INFORMATION , +NHI_CMD_MSG_TO_ICM , +NHI_CMD_MSG_FROM_ICM , +NHI_CMD_MAILBOX , +NHI_CMD_APPROVE_TBT_NETWORKING , +NHI_CMD_ICM_IN_SAFE_MODE , + __NHI_CMD_MAX, +}; +#define NHI_CMD_MAX (__NHI_CMD_MAX - 1)
NHI_CMD_MAX = NHI_CMD_ICM_IN_SAFE_MODE ?
Quoted 40 lines
drivers/thunderbolt/icm/icm_nhi.c new file +3
-0+/* NHI genetlink policy */ +static const struct nla_policy nhi_genl_policy[NHI_ATTR_MAX +1 ] = { + [NHI_ATTR_DRV_VERSION ] = { .type =NLA_NUL_STRING ,},
drivers/thunderbolt/icm/icm_nhi.c new file +8
-0+ [NHI_ATTR_NVM_VER_OFFSET] = { .type = NLA_U16, }, + [NHI_ATTR_NUM_PORTS] = { .type = NLA_U8, }, + [NHI_ATTR_DMA_PORT] = { .type = NLA_U8, }, + [NHI_ATTR_SUPPORT_FULL_E2E] = { .type = NLA_FLAG, }, + [NHI_ATTR_MAILBOX_CMD] = { .type = NLA_U32, }, + [NHI_ATTR_PDF] = { .type = NLA_U32, }, + [NHI_ATTR_MSG_TO_ICM ] = { .type =NLA_BINARY , + .len =
TBT_ICM_RING_MAX_FRAME_SIZE},drivers/thunderbolt/icm/icm_nhi.c new file +2
-0+ [NHI_ATTR_MSG_FROM_ICM ] = { .type =NLA_BINARY , + .len =
TBT_ICM_RING_MAX_FRAME_SIZE},drivers/thunderbolt/icm/icm_nhi.c new file +24
-0+}; + +/* NHI genetlink family */ +static struct genl_family nhi_genl_family = { + .id =GENL_ID_GENERATE , + .hdrsize = FIELD_SIZEOF(struct tbt_nhi_ctxt, id), + .name =NHI_GENL_NAME , + .version =NHI_GENL_VERSION , + .maxattr =NHI_ATTR_MAX , +}; + +static LIST_HEAD (controllers_list); +static DECLARE_RWSEM (controllers_list_rwsem); +static atomic_t subscribers =ATOMIC_INIT (0 ); +static u32 portid; + +static bool nhi_nvm_authenticated (struct tbt_nhi_ctxt *nhi_ctxt) +{ +enum icm_operation_mode op_mode; +u32 *msg_head, port_id, reg; +struct sk_buff *skb; +int i; + +if (!nhi_ctxt->nvm_auth_on_boot)
drivers/thunderbolt/icm/icm_nhi.c line 137
Quoted 10 lines
drivers/thunderbolt/icm/icm_nhi.c new file +10
-0+return true; + +for (i =0 ; i <5 ; i++) { +u32 status; + + status =ioread32 (nhi_ctxt->iobase +REG_FW_STS ); + +if (status ®_FW_STS_NVM_AUTH_DONE ) +break ; +msleep (30 );
30 is big number, for polling, what is behind this?
Quoted 131 lines
drivers/thunderbolt/icm/icm_nhi.c new file +5
-0+ } +/* +* The check for authentication is done after checking if iCM +* is present so it shouldn't reach the max tries (=5). +* Anyway, the check for full functionality below covers the error case.
drivers/thunderbolt/icm/icm_nhi.c new file +8
-0+*/ + reg =ioread32 (nhi_ctxt->iobase +REG_OUTMAIL_CMD ); + op_mode = (reg ®_OUTMAIL_CMD_OP_MODE_MASK ) >> +REG_OUTMAIL_CMD_OP_MODE_SHIFT ; +if (op_mode ==FULL_FUNCTIONALITY ) +return true; + + dev_warn(&nhi_ctxt->pdev->dev, "controller id %#x is in operationmode %#x status %#lx\n",
drivers/thunderbolt/icm/icm_nhi.c new file +2
-0+ nhi_ctxt->id, op_mode, + (reg ®_OUTMAIL_CMD_STS_MASK)>>REG_OUTMAIL_CMD_STS_SHIFT);
drivers/thunderbolt/icm/icm_nhi.c new file +2
-0+ + skb = genlmsg_new(NLMSG_ALIGN(nhi_genl_family.hdrsize),
GFP_KERNEL);drivers/thunderbolt/icm/icm_nhi.c new file +2
-0+if (!skb) { + dev_err(&nhi_ctxt->pdev->dev, "genlmsg_new failed: notenough memory to send controller operational mode\n");
drivers/thunderbolt/icm/icm_nhi.c new file +10
-0+return false; + } + +/* keeping port_id into a local variable for next use */ + port_id = portid; + msg_head =genlmsg_put (skb, port_id,0 , &nhi_genl_family,0 , +NHI_CMD_ICM_IN_SAFE_MODE ); +if (!msg_head) { +nlmsg_free (skb); + dev_err(&nhi_ctxt->pdev->dev, "genlmsg_put failed: notenough memory to send controller operational mode\n");
drivers/thunderbolt/icm/icm_nhi.c new file +18
-0+return false; + } + + *msg_head = nhi_ctxt->id; + +genlmsg_end (skb, msg_head); + +genlmsg_unicast (&init_net, skb, port_id); + +return false; +} + +int nhi_send_message (struct tbt_nhi_ctxt *nhi_ctxt,enum pdf_value pdf, +u32 msg_len,const u8 *msg,bool ignore_icm_resp) +{ +u32 prod_cons, prod, cons, attr; +struct tbt_icm_ring_shared_memory *shared_mem; + void __iomem *reg = TBT_RING_CONS_PROD_REG(nhi_ctxt-Quoted 1 line
iobase,
drivers/thunderbolt/icm/icm_nhi.c new file +5
-0+REG_TX_RING_BASE , + TBT_ICM_RING_NUM); + + dev_dbg(&nhi_ctxt->pdev->dev, + "send msg: controller id %#x pdf %u cmd %hhu msg len%u\n",
drivers/thunderbolt/icm/icm_nhi.c new file +19
-0+ nhi_ctxt->id, pdf, msg[3], msg_len); + +if (nhi_ctxt->d0_exit) { +dev_notice (&nhi_ctxt->pdev->dev, +"controller id %#x is exiting D0\n" , + nhi_ctxt->id); +return -ENODEV ; + } + + prod_cons =ioread32 (reg); + prod =TBT_REG_RING_PROD_EXTRACT (prod_cons); + cons =TBT_REG_RING_CONS_EXTRACT (prod_cons); +if (prod >=TBT_ICM_RING_NUM_TX_BUFS ) { +dev_warn (&nhi_ctxt->pdev->dev, +"controller id %#x producer %u out of range\n" , + nhi_ctxt->id, prod); +return -ENODEV ; + } + if (TBT_TX_RING_FULL(prod, cons,
TBT_ICM_RING_NUM_TX_BUFS)) {drivers/thunderbolt/icm/icm_nhi.c new file +7
-0+dev_err (&nhi_ctxt->pdev->dev, +"controller id %#x TX ring full\n" , + nhi_ctxt->id); +return -ENOSPC ; + } + + attr = (msg_len << DESC_ATTR_LEN_SHIFT) &
DESC_ATTR_LEN_MASK;drivers/thunderbolt/icm/icm_nhi.c new file +16
-0+ attr |= (pdf <<DESC_ATTR_EOF_SHIFT ) &DESC_ATTR_EOF_MASK ; + + shared_mem = nhi_ctxt->icm_ring_shared_mem; + shared_mem->tx_buf_desc[prod].attributes =cpu_to_le32 (attr); + +memcpy (shared_mem->tx_buf[prod], msg, msg_len); + + prod_cons &= ~REG_RING_PROD_MASK ; + prod_cons |= (((prod +1 ) %TBT_ICM_RING_NUM_TX_BUFS ) << +REG_RING_PROD_SHIFT ) ®_RING_PROD_MASK ; + +if (likely (!nhi_ctxt->wait_for_icm_resp)) + nhi_ctxt->wait_for_icm_resp = true; +else + dev_dbg(&nhi_ctxt->pdev->dev, + "controller id %#x wait_for_icm_resp should havebeen cleared\n",
drivers/thunderbolt/icm/icm_nhi.c new file +26
-0+ nhi_ctxt->id); + + nhi_ctxt->ignore_icm_resp = ignore_icm_resp; + +iowrite32 (prod_cons, reg); + +return 0 ; +} + +static int nhi_send_driver_ready_command (struct tbt_nhi_ctxt *nhi_ctxt) +{ +struct driver_ready_command { +__be32 req_code; +__be32 crc; + } drv_rdy_cmd = { + .req_code =cpu_to_be32 (CC_DRV_READY ), + }; +u32 crc32; + + crc32 =__crc32c_le (~0 , (unsigned char const *)&drv_rdy_cmd, + offsetof(struct driver_ready_command , crc)); + + drv_rdy_cmd.crc =cpu_to_be32 (~crc32); + + return nhi_send_message(nhi_ctxt, PDF_SW_TO_FW_COMMAND, + sizeof(drv_rdy_cmd), (u8 *)&drv_rdy_cmd,
drivers/thunderbolt/icm/icm_nhi.c line 267
Quoted 10 lines
drivers/thunderbolt/icm/icm_nhi.c new file +10
-0+ false); +} + +static struct tbt_nhi_ctxt *nhi_search_ctxt (u32 id) +{ +struct tbt_nhi_ctxt *nhi_ctxt; + +list_for_each_entry (nhi_ctxt, &controllers_list, node) +if (nhi_ctxt->id == id) +return nhi_ctxt;
Don't you need to lock this list with the controllers_list_rwsem ?
Quoted 1,183 lines
drivers/thunderbolt/icm/icm_nhi.c new file +12
-0+ +return NULL ; +} + +static int nhi_genl_subscribe (__always_unused struct sk_buff *u_skb, +struct genl_info *info) + __acquires(&nhi_ctxt->send_sem) +{ +struct tbt_nhi_ctxt *nhi_ctxt; + +/* +* To send driver ready command to iCM, need at least one subscriber
drivers/thunderbolt/icm/icm_nhi.c new file +16
-0+* that will handle the response. +* Currently the assumption is one user mode daemon as subscriber +* so one portid global variable (without locking). +*/ +if (atomic_inc_return (&subscribers) >=1 ) { + portid = info->snd_portid; +down_read (&controllers_list_rwsem); +list_for_each_entry (nhi_ctxt, &controllers_list, node) { +int res; + +if (nhi_ctxt->d0_exit || + !nhi_nvm_authenticated (nhi_ctxt)) +continue ; + + res = down_timeout(&nhi_ctxt->send_sem, +
msecs_to_jiffies(10*MSEC_PER_SEC));drivers/thunderbolt/icm/icm_nhi.c new file +3
-0+if (res) { + dev_err(&nhi_ctxt->pdev->dev, + "%s: controller id %#x timeout onsend semaphore\n",
drivers/thunderbolt/icm/icm_nhi.c new file +5
-0+ __func__, nhi_ctxt->id); +continue ; + } + + if (!mutex_trylock(&nhi_ctxt-Quoted 1 line
d0_exit_send_mutex)) {drivers/thunderbolt/icm/icm_nhi.c new file +25
-0+up (&nhi_ctxt->send_sem); +continue ; + } + + res =nhi_send_driver_ready_command (nhi_ctxt); + +mutex_unlock (&nhi_ctxt->d0_exit_send_mutex); +if (res) +up (&nhi_ctxt->send_sem); + } +up_read (&controllers_list_rwsem); + } + +return 0 ; +} + +static int nhi_genl_unsubscribe (__always_unused struct sk_buff *u_skb, +__always_unused struct genl_info *info) +{ +atomic_dec_if_positive (&subscribers); + +return 0 ; +} + +static int nhi_genl_query_information(__always_unused struct sk_buff
*u_skb,drivers/thunderbolt/icm/icm_nhi.c new file +17
-0+ struct genl_info *info) +{ +struct tbt_nhi_ctxt *nhi_ctxt; +struct sk_buff *skb; +bool msg_too_long; +int res = -ENODEV ; +u32 *msg_head; + +if (!info || !info->userhdr) +return -EINVAL ; + + skb = genlmsg_new(NLMSG_ALIGN(nhi_genl_family.hdrsize) + + nla_total_size(sizeof(DRV_VERSION)) + + nla_total_size(sizeof(nhi_ctxt->nvm_ver_offset)) + + nla_total_size(sizeof(nhi_ctxt->num_ports)) + + nla_total_size(sizeof(nhi_ctxt->dma_port)) + + nla_total_size(0), /* nhi_ctxt-Quoted 1 line
support_full_e2e*/drivers/thunderbolt/icm/icm_nhi.c new file +18
-0+ GFP_KERNEL); +if (!skb) +return -ENOMEM ; + + msg_head =genlmsg_put_reply (skb, info, &nhi_genl_family,0 , +NHI_CMD_QUERY_INFORMATION ); +if (!msg_head) { + res = -ENOMEM ; + goto genl_put_reply_failure; + } + +down_read (&controllers_list_rwsem); + + nhi_ctxt =nhi_search_ctxt (*(u32 *)info->userhdr); +if (nhi_ctxt && !nhi_ctxt->d0_exit) { + *msg_head = nhi_ctxt->id; + + msg_too_long = !!nla_put_string(skb,
NHI_ATTR_DRV_VERSION,drivers/thunderbolt/icm/icm_nhi.c new file +52
-0+ DRV_VERSION); + + msg_too_long = msg_too_long || +nla_put_u16 (skb,NHI_ATTR_NVM_VER_OFFSET , + nhi_ctxt->nvm_ver_offset); + + msg_too_long = msg_too_long || +nla_put_u8 (skb,NHI_ATTR_NUM_PORTS , + nhi_ctxt->num_ports); + + msg_too_long = msg_too_long || +nla_put_u8 (skb,NHI_ATTR_DMA_PORT , + nhi_ctxt->dma_port); + +if (msg_too_long) { + res = -EMSGSIZE ; + goto release_ctl_list_lock; + } + +if (nhi_ctxt->support_full_e2e && +nla_put_flag (skb,NHI_ATTR_SUPPORT_FULL_E2E )) { + res = -EMSGSIZE ; + goto release_ctl_list_lock; + } +up_read (&controllers_list_rwsem); + +genlmsg_end (skb, msg_head); + +return genlmsg_reply (skb, info); + } + +release_ctl_list_lock: +up_read (&controllers_list_rwsem); +genlmsg_cancel (skb, msg_head); + +genl_put_reply_failure: +nlmsg_free (skb); + +return res; +} + +static int nhi_genl_msg_to_icm(__always_unused struct sk_buff *u_skb, + struct genl_info *info) + __acquires(&nhi_ctxt->send_sem) +{ + struct tbt_nhi_ctxt *nhi_ctxt; + int res = -ENODEV; + int msg_len; + void *msg; + + if (!info || !info->userhdr || !info->attrs || + !info->attrs[NHI_ATTR_PDF] || !info-Quoted 1 line
attrs[NHI_ATTR_MSG_TO_ICM])
drivers/thunderbolt/icm/icm_nhi.c new file +19
-0+return -EINVAL ; + + msg_len =nla_len (info->attrs[NHI_ATTR_MSG_TO_ICM ]); +if (msg_len >TBT_ICM_RING_MAX_FRAME_SIZE ) +return -ENOBUFS ; + + msg =nla_data (info->attrs[NHI_ATTR_MSG_TO_ICM ]); + +down_read (&controllers_list_rwsem); + nhi_ctxt =nhi_search_ctxt (*(u32 *)info->userhdr); +if (nhi_ctxt && !nhi_ctxt->d0_exit) { +/* +* waiting 10 seconds to receive a FW response +* if not, just give up and pop up an error +*/ + res =down_timeout (&nhi_ctxt->send_sem, +msecs_to_jiffies (10 *MSEC_PER_SEC )); +if (res) { + void __iomem *rx_prod_cons =TBT_RING_CONS_PROD_REG(
drivers/thunderbolt/icm/icm_nhi.c new file +3
-0+ nhi_ctxt->iobase, + REG_RX_RING_BASE, +TBT_ICM_RING_NUM);drivers/thunderbolt/icm/icm_nhi.c new file +1
-0+ void __iomem *tx_prod_cons =TBT_RING_CONS_PROD_REG(
drivers/thunderbolt/icm/icm_nhi.c new file +3
-0+ nhi_ctxt->iobase, + REG_TX_RING_BASE, +TBT_ICM_RING_NUM);drivers/thunderbolt/icm/icm_nhi.c new file +2
-0+ dev_err(&nhi_ctxt->pdev->dev, + "controller id %#x timeout on sendsemaphore\n",
drivers/thunderbolt/icm/icm_nhi.c new file +3
-0+ nhi_ctxt->id); + dev_dbg(&nhi_ctxt->pdev->dev, + "controller id %#x, tx prod&cons=%#x, rxprod&cons=%#x\n",
drivers/thunderbolt/icm/icm_nhi.c new file +18
-0+ nhi_ctxt->id, +ioread32 (tx_prod_cons), + ioread32(rx_prod_cons)); + goto release_ctl_list_lock; + } + +if (!mutex_trylock (&nhi_ctxt->d0_exit_send_mutex)) { +up (&nhi_ctxt->send_sem); +dev_notice (&nhi_ctxt->pdev->dev, +"controller id %#x is exiting D0\n" , + nhi_ctxt->id); + goto release_ctl_list_lock; + } + +up_read (&controllers_list_rwsem); + + res = nhi_send_message(nhi_ctxt, + nla_get_u32(info-Quoted 1 line
attrs[NHI_ATTR_PDF]),
drivers/thunderbolt/icm/icm_nhi.c new file +15
-0+ msg_len, msg, false); + +mutex_unlock (&nhi_ctxt->d0_exit_send_mutex); +if (res) +up (&nhi_ctxt->send_sem); + +return res; + } + +release_ctl_list_lock: +up_read (&controllers_list_rwsem); +return res; +} + +int nhi_mailbox(struct tbt_nhi_ctxt *nhi_ctxt, u32 cmd, u32 data, booldeinit)
drivers/thunderbolt/icm/icm_nhi.c new file +5
-0+{ +u32 delay = deinit ?U32_C (20 ) :U32_C (100 ); +int i; + + dev_dbg(&nhi_ctxt->pdev->dev, "controller id %#x mbox command%#x\n",
drivers/thunderbolt/icm/icm_nhi.c new file +43
-0+ nhi_ctxt->id, cmd); +iowrite32 (data, nhi_ctxt->iobase +REG_INMAIL_DATA ); +iowrite32 (cmd, nhi_ctxt->iobase +REG_INMAIL_CMD ); + +#define NHI_INMAIL_CMD_RETRIES 50 +/* +* READ_ONCE fetches the value of nhi_ctxt->d0_exit every time +* and avoid optimization. +* deinit = true to continue the loop even if D3 process has been +* carried out. +*/ +for (i =0 ; (i <NHI_INMAIL_CMD_RETRIES ) && + (deinit || !READ_ONCE (nhi_ctxt->d0_exit)); i++) { + cmd =ioread32 (nhi_ctxt->iobase +REG_INMAIL_CMD ); + +if (cmd ®_INMAIL_CMD_ERROR ) { +/* +* when deinit this just informative as it may +* due to unplug of the cable +*/ +if (!deinit) +dev_err (&nhi_ctxt->pdev->dev, +"inmail error after %d msecs\n" , + i * delay); +else +dev_info (&nhi_ctxt->pdev->dev, +"inmail error after %d msecs\n" , + i * delay); + +return -EIO ; + } + +if (!(cmd ®_INMAIL_CMD_REQUEST )) +break ; + +msleep (delay); + } + +if (i ==NHI_INMAIL_CMD_RETRIES ) { +if (!deinit) +dev_err (&nhi_ctxt->pdev->dev,"inmail timeout\n" ); +else + dev_info(&nhi_ctxt->pdev->dev, "inmailtimeout\n");
drivers/thunderbolt/icm/icm_nhi.c new file +50
-0+return -ETIMEDOUT ; + } + +return 0 ; +} + +static int nhi_mailbox_generic (struct tbt_nhi_ctxt *nhi_ctxt,u32 mb_cmd) + __releases(&controllers_list_rwsem) +{ +int res = -ENODEV ; + +if (mutex_lock_interruptible (&nhi_ctxt->mailbox_mutex)) { + res = -ERESTART ; + goto release_ctl_list_lock; + } + +if (!mutex_trylock (&nhi_ctxt->d0_exit_mailbox_mutex)) { +mutex_unlock (&nhi_ctxt->mailbox_mutex); +dev_notice (&nhi_ctxt->pdev->dev, +"controller id %#x is exiting D0\n" , + nhi_ctxt->id); + goto release_ctl_list_lock; + } + +up_read (&controllers_list_rwsem); + + res =nhi_mailbox (nhi_ctxt, mb_cmd,0 , false); +mutex_unlock (&nhi_ctxt->d0_exit_mailbox_mutex); +mutex_unlock (&nhi_ctxt->mailbox_mutex); + +return res; + +release_ctl_list_lock: +up_read (&controllers_list_rwsem); +return res; +} + +static int nhi_genl_mailbox (__always_unused struct sk_buff *u_skb, +struct genl_info *info) +{ +struct tbt_nhi_ctxt *nhi_ctxt; +u32 cmd, mb_cmd; + +if (!info || !info->userhdr || !info->attrs || + !info->attrs[NHI_ATTR_MAILBOX_CMD ]) +return -EINVAL ; + + cmd =nla_get_u32 (info->attrs[NHI_ATTR_MAILBOX_CMD ]); + mb_cmd = ((cmd <<REG_INMAIL_CMD_CMD_SHIFT ) & + REG_INMAIL_CMD_CMD_MASK) |
REG_INMAIL_CMD_REQUEST;drivers/thunderbolt/icm/icm_nhi.c new file +13
-0+ +down_read (&controllers_list_rwsem); + + nhi_ctxt =nhi_search_ctxt (*(u32 *)info->userhdr); +if (nhi_ctxt && !nhi_ctxt->d0_exit) +return nhi_mailbox_generic (nhi_ctxt, mb_cmd); + +up_read (&controllers_list_rwsem); +return -ENODEV ; +} + + +static int nhi_genl_send_msg(struct tbt_nhi_ctxt *nhi_ctxt, enum
pdf_valuepdf,drivers/thunderbolt/icm/icm_nhi.c new file +8
-0+ const u8 *msg, u32 msg_len) +{ +u32 *msg_head, port_id; +struct sk_buff *skb; +int res; + +if (atomic_read (&subscribers) <1 ) { + dev_notice(&nhi_ctxt->pdev->dev, "no subscribers forcontroller id %#x, dropping message - pdf %u cmd %hhu msg len %u\n",
drivers/thunderbolt/icm/icm_nhi.c new file +53
-0+ nhi_ctxt->id, pdf, msg[3], msg_len); +return -ENOTCONN ; + } + + skb =genlmsg_new (NLMSG_ALIGN (nhi_genl_family.hdrsize) + +nla_total_size (msg_len) + +nla_total_size (sizeof (pdf)), +GFP_KERNEL ); +if (!skb) +return -ENOMEM ; + + port_id = portid; + msg_head =genlmsg_put (skb, port_id,0 , &nhi_genl_family,0 , +NHI_CMD_MSG_FROM_ICM ); +if (!msg_head) { + res = -ENOMEM ; + goto genl_put_reply_failure; + } + + *msg_head = nhi_ctxt->id; + +if (nla_put_u32 (skb,NHI_ATTR_PDF , pdf) || +nla_put (skb,NHI_ATTR_MSG_FROM_ICM , msg_len, msg)) { + res = -EMSGSIZE ; + goto nla_put_failure; + } + +genlmsg_end (skb, msg_head); + +return genlmsg_unicast (&init_net, skb, port_id); + +nla_put_failure: +genlmsg_cancel (skb, msg_head); +genl_put_reply_failure: +nlmsg_free (skb); + +return res; +} + +static bool nhi_msg_from_icm_analysis (struct tbt_nhi_ctxt *nhi_ctxt, +enum pdf_value pdf, +const u8 *msg,u32 msg_len) +{ +/* +* preparation for messages that won't be sent, +* currently unused in this patch. +*/ +bool send_event = true; + +switch (pdf) { +case PDF_ERROR_NOTIFICATION : + dev_err(&nhi_ctxt->pdev->dev, + "controller id %#x PDF_ERROR_NOTIFICATION %hhumsg len %u\n",
drivers/thunderbolt/icm/icm_nhi.c new file +32
-0+ nhi_ctxt->id, msg[11], msg_len); +/* fallthrough */ +case PDF_WRITE_CONFIGURATION_REGISTERS : +/* fallthrough */ +case PDF_READ_CONFIGURATION_REGISTERS : +if (nhi_ctxt->wait_for_icm_resp) { + nhi_ctxt->wait_for_icm_resp = false; +up (&nhi_ctxt->send_sem); + } +break ; + +case PDF_FW_TO_SW_RESPONSE : +if (nhi_ctxt->wait_for_icm_resp) { + nhi_ctxt->wait_for_icm_resp = false; +up (&nhi_ctxt->send_sem); + } +break ; + +default : +dev_warn (&nhi_ctxt->pdev->dev, +"controller id %#x pdf %u isn't handled/expected\n" , + nhi_ctxt->id, pdf); +break ; + } + +return send_event; +} + +static void nhi_msgs_from_icm (struct work_struct *work) + __releases(&nhi_ctxt->send_sem) +{ + struct tbt_nhi_ctxt *nhi_ctxt = container_of(work,
typeof(*nhi_ctxt),drivers/thunderbolt/icm/icm_nhi.c new file +2
-0+ icm_msgs_work); + void __iomem *reg = TBT_RING_CONS_PROD_REG(nhi_ctxt-Quoted 1 line
iobase,
drivers/thunderbolt/icm/icm_nhi.c new file +21
-0+ REG_RX_RING_BASE, + TBT_ICM_RING_NUM); +u32 prod_cons, prod, cons; + + prod_cons =ioread32 (reg); + prod =TBT_REG_RING_PROD_EXTRACT (prod_cons); + cons =TBT_REG_RING_CONS_EXTRACT (prod_cons); +if (prod >=TBT_ICM_RING_NUM_RX_BUFS ) { +dev_warn (&nhi_ctxt->pdev->dev, +"controller id %#x producer %u out of range\n" , + nhi_ctxt->id, prod); +return ; + } +if (cons >=TBT_ICM_RING_NUM_RX_BUFS ) { +dev_warn (&nhi_ctxt->pdev->dev, +"controller id %#x consumer %u out of range\n" , + nhi_ctxt->id, cons); +return ; + } + + while (!TBT_RX_RING_EMPTY(prod, cons,
TBT_ICM_RING_NUM_RX_BUFS) &&drivers/thunderbolt/icm/icm_nhi.c new file +9
-0+ !nhi_ctxt->d0_exit) { +struct tbt_buf_desc *rx_desc; +u8 *msg; +u32 msg_len; +enum pdf_value pdf; +bool send_event; + + cons = (cons +1 ) %TBT_ICM_RING_NUM_RX_BUFS ; + rx_desc = &(nhi_ctxt->icm_ring_shared_mem-Quoted 1 line
rx_buf_desc[cons]);
drivers/thunderbolt/icm/icm_nhi.c new file +7
-0+if (!(le32_to_cpu (rx_desc->attributes) & +DESC_ATTR_DESC_DONE )) { +usleep_range (10 ,20 ); +if (unlikely (!(le32_to_cpu (rx_desc->attributes) & +DESC_ATTR_DESC_DONE ))) + dev_err(&nhi_ctxt->pdev->dev, + "controller id %#x buffer %u mightnot completely processed\n",
drivers/thunderbolt/icm/icm_nhi.c new file +4
-0+ nhi_ctxt->id, cons); + } + +rmb ();/* read the descriptor and the buffer after DD check */
drivers/thunderbolt/icm/icm_nhi.c new file +1
-0+ pdf = (le32_to_cpu(rx_desc->attributes) &
DESC_ATTR_EOF_MASK)drivers/thunderbolt/icm/icm_nhi.c new file +3
-0+ >> DESC_ATTR_EOF_SHIFT; + msg = nhi_ctxt->icm_ring_shared_mem->rx_buf[cons]; + msg_len = (le32_to_cpu(rx_desc-Quoted 1 line
attributes)&DESC_ATTR_LEN_MASK)
drivers/thunderbolt/icm/icm_nhi.c new file +4
-0+ >> DESC_ATTR_LEN_SHIFT; + + dev_dbg(&nhi_ctxt->pdev->dev, + "%s: controller id %#x pdf %u cmd %hhu msg len%u\n",
drivers/thunderbolt/icm/icm_nhi.c new file +3
-0+ __func__, nhi_ctxt->id, pdf, msg[3], msg_len); + + send_event = nhi_msg_from_icm_analysis(nhi_ctxt, pdf,msg,
drivers/thunderbolt/icm/icm_nhi.c new file +14
-0+ msg_len); + +if (send_event) +nhi_genl_send_msg (nhi_ctxt, pdf, msg, msg_len); + +/* set the descriptor for another receive */ + rx_desc->attributes =cpu_to_le32 (DESC_ATTR_REQ_STS | +DESC_ATTR_INT_EN ); + rx_desc->time =0 ; + } + +/* free the descriptors for more receive */ + prod_cons &= ~REG_RING_CONS_MASK ; + prod_cons |= (cons << REG_RING_CONS_SHIFT) &
REG_RING_CONS_MASK;drivers/thunderbolt/icm/icm_nhi.c new file +8
-0+iowrite32 (prod_cons, reg); + +if (!nhi_ctxt->d0_exit) { +unsigned long flags; + +spin_lock_irqsave (&nhi_ctxt->lock, flags); +/* enable RX interrupt */ + RING_INT_ENABLE_RX(nhi_ctxt->iobase,
TBT_ICM_RING_NUM,drivers/thunderbolt/icm/icm_nhi.c new file +7
-0+ nhi_ctxt->num_paths); + +spin_unlock_irqrestore (&nhi_ctxt->lock, flags); + } +} + +static irqreturn_t nhi_icm_ring_rx_msix(int __always_unused irq, void*data)
drivers/thunderbolt/icm/icm_nhi.c new file +28
-0+{ +struct tbt_nhi_ctxt *nhi_ctxt = data; + +spin_lock (&nhi_ctxt->lock); +/* +* disable RX interrupt +* We like to allow interrupt mitigation until the work item +* will be completed. +*/ +RING_INT_DISABLE_RX (nhi_ctxt->iobase,TBT_ICM_RING_NUM , + nhi_ctxt->num_paths); + +spin_unlock (&nhi_ctxt->lock); + +schedule_work (&nhi_ctxt->icm_msgs_work); + +return IRQ_HANDLED ; +} + +static irqreturn_t nhi_msi (int __always_unused irq,void *data) +{ +struct tbt_nhi_ctxt *nhi_ctxt = data; +u32 isr0, isr1, imr0, imr1; + +/* clear on read */ + isr0 =ioread32 (nhi_ctxt->iobase +REG_RING_NOTIFY_BASE ); + isr1 = ioread32(nhi_ctxt->iobase + REG_RING_NOTIFY_BASE + +REG_RING_NOTIFY_STEP);drivers/thunderbolt/icm/icm_nhi.c new file +80
-0+if (unlikely (!isr0 && !isr1)) +return IRQ_NONE ; + +spin_lock (&nhi_ctxt->lock); + + imr0 =ioread32 (nhi_ctxt->iobase +REG_RING_INTERRUPT_BASE ); + imr1 =ioread32 (nhi_ctxt->iobase +REG_RING_INTERRUPT_BASE + +REG_RING_INTERRUPT_STEP ); +/* disable the arrived interrupts */ +iowrite32 (imr0 & ~isr0, + nhi_ctxt->iobase +REG_RING_INTERRUPT_BASE ); +iowrite32 (imr1 & ~isr1, + nhi_ctxt->iobase +REG_RING_INTERRUPT_BASE + +REG_RING_INTERRUPT_STEP ); + +spin_unlock (&nhi_ctxt->lock); + +if (isr0 ®_RING_INT_RX_PROCESSED (TBT_ICM_RING_NUM , + nhi_ctxt->num_paths)) +schedule_work (&nhi_ctxt->icm_msgs_work); + +return IRQ_HANDLED ; +} + +/** +* nhi_set_int_vec - Mapping of the MSIX vector entry to the ring +* @nhi_ctxt: contains data on NHI controller +* @path: ring to be mapped +* @msix_msg_id: msix entry to be mapped +*/ +static inline void nhi_set_int_vec (struct tbt_nhi_ctxt *nhi_ctxt,u32 path, +u8 msix_msg_id) +{ +void __iomem *reg; +u32 step, shift, ivr; + +if (msix_msg_id %2 ) + path += nhi_ctxt->num_paths; + + step = path /REG_INT_VEC_ALLOC_PER_REG ; + shift = (path %REG_INT_VEC_ALLOC_PER_REG ) * +REG_INT_VEC_ALLOC_FIELD_BITS ; + reg = nhi_ctxt->iobase +REG_INT_VEC_ALLOC_BASE + + (step *REG_INT_VEC_ALLOC_STEP ); + ivr =ioread32 (reg) & ~(REG_INT_VEC_ALLOC_FIELD_MASK << shift); +iowrite32 (ivr | (msix_msg_id << shift), reg); +} + +/* NHI genetlink operations array */ +static const struct genl_ops nhi_ops[] = { + { + .cmd =NHI_CMD_SUBSCRIBE , + .policy = nhi_genl_policy, + .doit = nhi_genl_subscribe, + }, + { + .cmd =NHI_CMD_UNSUBSCRIBE , + .policy = nhi_genl_policy, + .doit = nhi_genl_unsubscribe, + }, + { + .cmd =NHI_CMD_QUERY_INFORMATION , + .policy = nhi_genl_policy, + .doit = nhi_genl_query_information, + }, + { + .cmd =NHI_CMD_MSG_TO_ICM , + .policy = nhi_genl_policy, + .doit = nhi_genl_msg_to_icm, + .flags =GENL_ADMIN_PERM , + }, + { + .cmd =NHI_CMD_MAILBOX , + .policy = nhi_genl_policy, + .doit = nhi_genl_mailbox, + .flags =GENL_ADMIN_PERM , + }, +}; + +static int nhi_suspend(struct device *dev) __releases(&nhi_ctxt-Quoted 1 line
send_sem)drivers/thunderbolt/icm/icm_nhi.c new file +6
-0+{ +struct tbt_nhi_ctxt *nhi_ctxt =pci_get_drvdata (to_pci_dev (dev)); +void __iomem *rx_reg, *tx_reg; +u32 rx_reg_val, tx_reg_val; + +/* must be after negotiation_events, since messages might be sent */
drivers/thunderbolt/icm/icm_nhi.c new file +45
-0+ nhi_ctxt->d0_exit = true; + + rx_reg = nhi_ctxt->iobase +REG_RX_OPTIONS_BASE + + (TBT_ICM_RING_NUM *REG_OPTS_STEP ); + rx_reg_val =ioread32 (rx_reg) & ~REG_OPTS_E2E_EN ; + tx_reg = nhi_ctxt->iobase +REG_TX_OPTIONS_BASE + + (TBT_ICM_RING_NUM *REG_OPTS_STEP ); + tx_reg_val =ioread32 (tx_reg) & ~REG_OPTS_E2E_EN ; +/* disable RX flow control */ +iowrite32 (rx_reg_val, rx_reg); +/* disable TX flow control */ +iowrite32 (tx_reg_val, tx_reg); +/* disable RX ring */ +iowrite32 (rx_reg_val & ~REG_OPTS_VALID , rx_reg); + +mutex_lock (&nhi_ctxt->d0_exit_mailbox_mutex); +mutex_lock (&nhi_ctxt->d0_exit_send_mutex); + +cancel_work_sync (&nhi_ctxt->icm_msgs_work); + +if (nhi_ctxt->wait_for_icm_resp) { + nhi_ctxt->wait_for_icm_resp = false; + nhi_ctxt->ignore_icm_resp = false; +/* +* if there is response, it is lost, so unlock the send +* for the next resume. +*/ +up (&nhi_ctxt->send_sem); + } + +mutex_unlock (&nhi_ctxt->d0_exit_send_mutex); +mutex_unlock (&nhi_ctxt->d0_exit_mailbox_mutex); + +/* wait for all TX to finish */ +usleep_range (5 *USEC_PER_MSEC ,7 *USEC_PER_MSEC ); + +/* disable all interrupts */ +iowrite32 (0 , nhi_ctxt->iobase +REG_RING_INTERRUPT_BASE ); +/* disable TX ring */ +iowrite32 (tx_reg_val & ~REG_OPTS_VALID , tx_reg); + +return 0 ; +} + +static int nhi_resume(struct device *dev) __acquires(&nhi_ctxt-Quoted 1 line
send_sem)drivers/thunderbolt/icm/icm_nhi.c new file +11
-0+{ +dma_addr_t phys; +struct tbt_nhi_ctxt *nhi_ctxt =pci_get_drvdata (to_pci_dev (dev)); +struct tbt_buf_desc *desc; +void __iomem *iobase = nhi_ctxt->iobase; +void __iomem *reg; +int i; + +if (nhi_ctxt->msix_entries) { + iowrite32(ioread32(iobase + REG_DMA_MISC) | +
REG_DMA_MISC_INT_AUTO_CLEAR,drivers/thunderbolt/icm/icm_nhi.c new file +9
-0+ iobase + REG_DMA_MISC); +/* +* Vector #0, which is TX complete to ICM, +* isn't been used currently. +*/ +nhi_set_int_vec (nhi_ctxt,0 ,1 ); + +for (i =2 ; i < nhi_ctxt->num_vectors; i++) + nhi_set_int_vec(nhi_ctxt, nhi_ctxt->num_paths -(i/2),
drivers/thunderbolt/icm/icm_nhi.c new file +30
-0+ i); + } + +/* configure TX descriptors */ +for (i =0 , phys = nhi_ctxt->icm_ring_shared_mem_dma_addr; + i <TBT_ICM_RING_NUM_TX_BUFS ; + i++, phys +=TBT_ICM_RING_MAX_FRAME_SIZE ) { + desc = &nhi_ctxt->icm_ring_shared_mem->tx_buf_desc[i]; + desc->phys =cpu_to_le64 (phys); + desc->attributes =cpu_to_le32 (DESC_ATTR_REQ_STS ); + } +/* configure RX descriptors */ +for (i =0 ; + i <TBT_ICM_RING_NUM_RX_BUFS ; + i++, phys +=TBT_ICM_RING_MAX_FRAME_SIZE ) { + desc = &nhi_ctxt->icm_ring_shared_mem->rx_buf_desc[i]; + desc->phys =cpu_to_le64 (phys); + desc->attributes =cpu_to_le32 (DESC_ATTR_REQ_STS | +DESC_ATTR_INT_EN ); + } + +/* configure throttling rate for interrupts */ +for (i =0 , reg = iobase +REG_INT_THROTTLING_RATE ; + i <NUM_INT_VECTORS ; + i++, reg +=REG_INT_THROTTLING_RATE_STEP ) { +iowrite32 (USEC_TO_256_NSECS (128 ), reg); + } + +/* configure TX for ICM ring */ + reg = iobase + REG_TX_RING_BASE + (TBT_ICM_RING_NUM *
REG_RING_STEP);drivers/thunderbolt/icm/icm_nhi.c new file +5
-0+ phys = nhi_ctxt->icm_ring_shared_mem_dma_addr + + offsetof(struct tbt_icm_ring_shared_memory , tx_buf_desc); +iowrite32 (lower_32_bits (phys), reg +REG_RING_PHYS_LO_OFFSET ); +iowrite32 (upper_32_bits (phys), reg +REG_RING_PHYS_HI_OFFSET ); + iowrite32((TBT_ICM_RING_NUM_TX_BUFS <<
REG_RING_SIZE_SHIFT) &drivers/thunderbolt/icm/icm_nhi.c new file +4
-0+REG_RING_SIZE_MASK , + reg + REG_RING_SIZE_OFFSET); + + reg = iobase + REG_TX_OPTIONS_BASE +(TBT_ICM_RING_NUM*REG_OPTS_STEP);
drivers/thunderbolt/icm/icm_nhi.c new file +4
-0+iowrite32 (REG_OPTS_RAW |REG_OPTS_VALID , reg); + +/* configure RX for ICM ring */ + reg = iobase + REG_RX_RING_BASE + (TBT_ICM_RING_NUM *
REG_RING_STEP);drivers/thunderbolt/icm/icm_nhi.c new file +5
-0+ phys = nhi_ctxt->icm_ring_shared_mem_dma_addr + + offsetof(struct tbt_icm_ring_shared_memory , rx_buf_desc); +iowrite32 (lower_32_bits (phys), reg +REG_RING_PHYS_LO_OFFSET ); +iowrite32 (upper_32_bits (phys), reg +REG_RING_PHYS_HI_OFFSET ); + iowrite32(((TBT_ICM_RING_NUM_RX_BUFS <<
REG_RING_SIZE_SHIFT) &drivers/thunderbolt/icm/icm_nhi.c new file +2
-0+ REG_RING_SIZE_MASK) | + ((TBT_ICM_RING_MAX_FRAME_SIZE <<
REG_RING_BUF_SIZE_SHIFT) &drivers/thunderbolt/icm/icm_nhi.c new file +3
-0+ REG_RING_BUF_SIZE_MASK), + reg + REG_RING_SIZE_OFFSET); + iowrite32(((TBT_ICM_RING_NUM_RX_BUFS - 1) <<
REG_RING_CONS_SHIFT) &drivers/thunderbolt/icm/icm_nhi.c new file +4
-0+REG_RING_CONS_MASK , + reg + REG_RING_CONS_PROD_OFFSET); + + reg = iobase + REG_RX_OPTIONS_BASE +(TBT_ICM_RING_NUM*REG_OPTS_STEP);
drivers/thunderbolt/icm/icm_nhi.c new file +4
-0+iowrite32 (REG_OPTS_RAW |REG_OPTS_VALID , reg); + +/* enable RX interrupt */ + RING_INT_ENABLE_RX(iobase, TBT_ICM_RING_NUM, nhi_ctxt-Quoted 1 line
num_paths);drivers/thunderbolt/icm/icm_nhi.c new file +40
-0+ +if (likely ((atomic_read (&subscribers) >0 ) && +nhi_nvm_authenticated (nhi_ctxt))) { +down (&nhi_ctxt->send_sem); + nhi_ctxt->d0_exit = false; +mutex_lock (&nhi_ctxt->d0_exit_send_mutex); +/* +* interrupts are enabled here before send due to +* implicit barrier in mutex +*/ +nhi_send_driver_ready_command (nhi_ctxt); +mutex_unlock (&nhi_ctxt->d0_exit_send_mutex); + }else { + nhi_ctxt->d0_exit = false; + } + +return 0 ; +} + +static void icm_nhi_shutdown (struct pci_dev *pdev) +{ +nhi_suspend (&pdev->dev); +} + +static void icm_nhi_remove (struct pci_dev *pdev) +{ +struct tbt_nhi_ctxt *nhi_ctxt =pci_get_drvdata (pdev); +int i; + +nhi_suspend (&pdev->dev); + +if (nhi_ctxt->net_workqueue) +destroy_workqueue (nhi_ctxt->net_workqueue); + +/* +* disable irq for msix or msi +*/ +if (likely (nhi_ctxt->msix_entries)) { +/* Vector #0 isn't been used currently */ + devm_free_irq(&pdev->dev, nhi_ctxt-Quoted 1 line
msix_entries[1].vector,
drivers/thunderbolt/icm/icm_nhi.c new file +17
-0+ nhi_ctxt); +pci_disable_msix (pdev); + }else { +devm_free_irq (&pdev->dev, pdev->irq, nhi_ctxt); +pci_disable_msi (pdev); + } + +/* +* remove controller from the controllers list +*/ +down_write (&controllers_list_rwsem); +list_del (&nhi_ctxt->node); +up_write (&controllers_list_rwsem); + + nhi_mailbox( + nhi_ctxt, +((
CC_DRV_UNLOADS_AND_DISCONNECT_INTER_DOMAIN_PATHSdrivers/thunderbolt/icm/icm_nhi.c new file +16
-0+ << REG_INMAIL_CMD_CMD_SHIFT) & + REG_INMAIL_CMD_CMD_MASK) | +REG_INMAIL_CMD_REQUEST , + 0, true); + +usleep_range (1 *USEC_PER_MSEC ,5 *USEC_PER_MSEC ); +iowrite32 (1 , nhi_ctxt->iobase +REG_HOST_INTERFACE_RST ); + +mutex_destroy (&nhi_ctxt->d0_exit_send_mutex); +mutex_destroy (&nhi_ctxt->d0_exit_mailbox_mutex); +mutex_destroy (&nhi_ctxt->mailbox_mutex); +for (i =0 ; i < nhi_ctxt->num_ports; i++) +mutex_destroy (&(nhi_ctxt->net_devices[i].state_mutex)); +} + +static int icm_nhi_probe(struct pci_dev *pdev, const struct pci_device_id*id)
drivers/thunderbolt/icm/icm_nhi.c new file +9
-0+{ +struct tbt_nhi_ctxt *nhi_ctxt; +void __iomem *iobase; +int i, res; +bool enable_msi = false; + + res =pcim_enable_device (pdev); +if (res) { + dev_err(&pdev->dev, "cannot enable PCI device,aborting\n");
drivers/thunderbolt/icm/icm_nhi.c new file +4
-0+return res; + } + + res = pcim_iomap_regions(pdev, 1 << NHI_MMIO_BAR,
pci_name(pdev));drivers/thunderbolt/icm/icm_nhi.c new file +2
-0+if (res) { + dev_err(&pdev->dev, "cannot obtain PCI resources,aborting\n");
drivers/thunderbolt/icm/icm_nhi.c new file +13
-0+return res; + } + +/* cannot fail - table is allocated in pcim_iomap_regions */ + iobase =pcim_iomap_table (pdev)[NHI_MMIO_BAR ]; + +/* check if ICM is running */ +if (!(ioread32 (iobase +REG_FW_STS ) ®_FW_STS_ICM_EN )) { +dev_err (&pdev->dev,"ICM isn't present, aborting\n" ); +return -ENODEV ; + } + + nhi_ctxt = devm_kzalloc(&pdev->dev, sizeof(*nhi_ctxt),
GFP_KERNEL);drivers/thunderbolt/icm/icm_nhi.c new file +6
-0+if (!nhi_ctxt) +return -ENOMEM ; + + nhi_ctxt->pdev = pdev; + nhi_ctxt->iobase = iobase; + nhi_ctxt->id = (PCI_DEVID(pdev->bus->number, pdev->devfn) <<16) |
drivers/thunderbolt/icm/icm_nhi.c new file +7
-0+ id->device; +/* +* Number of paths represents the number of rings available for +* the controller. +*/ + nhi_ctxt->num_paths = ioread32(iobase + REG_HOP_COUNT) & +REG_HOP_COUNT_TOTAL_PATHS_MASK;drivers/thunderbolt/icm/icm_nhi.c new file +2
-0+ + nhi_ctxt->nvm_auth_on_boot =DEVICE_DATA_NVM_AUTH_ON_BOOT(
drivers/thunderbolt/icm/icm_nhi.c new file +9
-0+ id->driver_data); + nhi_ctxt->support_full_e2e =DEVICE_DATA_SUPPORT_FULL_E2E ( + id->driver_data); + + nhi_ctxt->dma_port =DEVICE_DATA_DMA_PORT (id->driver_data); +/* +* Number of ports in the controller +*/ + nhi_ctxt->num_ports = DEVICE_DATA_NUM_PORTS(id-Quoted 1 line
driver_data);drivers/thunderbolt/icm/icm_nhi.c new file +1
-0+ nhi_ctxt->nvm_ver_offset = DEVICE_DATA_NVM_VER_OFFSET(id-Quoted 1 line
driver_data);drivers/thunderbolt/icm/icm_nhi.c new file +65
-0+ +mutex_init (&nhi_ctxt->d0_exit_send_mutex); +mutex_init (&nhi_ctxt->d0_exit_mailbox_mutex); +mutex_init (&nhi_ctxt->mailbox_mutex); + +sema_init (&nhi_ctxt->send_sem,1 ); + +INIT_WORK (&nhi_ctxt->icm_msgs_work, nhi_msgs_from_icm); + +spin_lock_init (&nhi_ctxt->lock); + + nhi_ctxt->net_devices =devm_kcalloc (&pdev->dev, + nhi_ctxt->num_ports, +sizeof (struct port_net_dev ), +GFP_KERNEL ); +if (!nhi_ctxt->net_devices) +return -ENOMEM ; + +for (i =0 ; i < nhi_ctxt->num_ports; i++) +mutex_init (&(nhi_ctxt->net_devices[i].state_mutex)); + +/* +* allocating RX and TX vectors for ICM and per port +* for thunderbolt networking. +* The mapping of the vector is carried out by +* nhi_set_int_vec and looks like: +* 0=tx icm, 1=rx icm, 2=tx data port 0, +* 3=rx data port 0... +*/ + nhi_ctxt->num_vectors = (1 + nhi_ctxt->num_ports) *2 ; + nhi_ctxt->msix_entries =devm_kcalloc (&pdev->dev, + nhi_ctxt->num_vectors, +sizeof (struct msix_entry ), +GFP_KERNEL ); +if (likely (nhi_ctxt->msix_entries)) { +for (i =0 ; i < nhi_ctxt->num_vectors; i++) + nhi_ctxt->msix_entries[i].entry = i; + res =pci_enable_msix_exact (pdev, + nhi_ctxt->msix_entries, + nhi_ctxt->num_vectors); + +if (res || +/* +* Allocating ICM RX only. +* vector #0, which is TX complete to ICM, +* isn't been used currently +*/ +devm_request_irq (&pdev->dev, + nhi_ctxt->msix_entries[1 ].vector, + nhi_icm_ring_rx_msix,0 ,pci_name (pdev), + nhi_ctxt)) { +devm_kfree (&pdev->dev, nhi_ctxt->msix_entries); + nhi_ctxt->msix_entries =NULL ; + enable_msi = true; + } + }else { + enable_msi = true; + } +/* +* In case allocation didn't succeed, use msi instead of msix +*/ +if (enable_msi) { + res =pci_enable_msi (pdev); +if (res) { + dev_err(&pdev->dev, "cannot enable MSI,aborting\n");
drivers/thunderbolt/icm/icm_nhi.c new file +15
-0+return res; + } + res =devm_request_irq (&pdev->dev, pdev->irq, nhi_msi,0 , +pci_name (pdev), nhi_ctxt); +if (res) { +dev_err (&pdev->dev, +"request_irq failed %d, aborting\n" , res); +return res; + } + } +/* +* try to work with address space of 64 bits. +* In case this doesn't work, work with 32 bits. +*/ + if (!dma_set_mask_and_coherent(&pdev->dev,
DMA_BIT_MASK(64))) {drivers/thunderbolt/icm/icm_nhi.c new file +3
-0+ nhi_ctxt->pci_using_dac = true; + }else { + res = dma_set_mask_and_coherent(&pdev->dev,
DMA_BIT_MASK(32));drivers/thunderbolt/icm/icm_nhi.c new file +9
-0+if (res) { +dev_err (&pdev->dev, +"No suitable DMA available, aborting\n" ); +return res; + } + } + +BUILD_BUG_ON (sizeof (struct tbt_buf_desc ) !=16 ); + BUILD_BUG_ON(sizeof(struct tbt_icm_ring_shared_memory) >
PAGE_SIZE);drivers/thunderbolt/icm/icm_nhi.c new file +2
-0+ nhi_ctxt->icm_ring_shared_mem = dmam_alloc_coherent( + &pdev->dev, sizeof(*nhi_ctxt-Quoted 1 line
icm_ring_shared_mem),drivers/thunderbolt/icm/icm_nhi.c new file +4
-0+ &nhi_ctxt->icm_ring_shared_mem_dma_addr, + GFP_KERNEL | __GFP_ZERO); +if (nhi_ctxt->icm_ring_shared_mem ==NULL ) { + dev_err(&pdev->dev, "dmam_alloc_coherent failed,aborting\n");
drivers/thunderbolt/icm/icm_nhi.c new file +4
-0+return -ENOMEM ; + } + + nhi_ctxt->net_workqueue =
create_singlethread_workqueue(DRV_NAME);drivers/thunderbolt/icm/icm_nhi.c new file +2
-0+if (!nhi_ctxt->net_workqueue) { + dev_err(&pdev->dev, "create_singlethread_workqueuefailed, aborting\n");
drivers/thunderbolt/icm/icm_nhi.c new file +20
-0+return -ENOMEM ; + } + +pci_set_master (pdev); +pci_set_drvdata (pdev, nhi_ctxt); + +nhi_resume (&pdev->dev); +/* +* Add the new controller at the end of the list +*/ +down_write (&controllers_list_rwsem); +list_add_tail (&nhi_ctxt->node, &controllers_list); +up_write (&controllers_list_rwsem); + +return res; +} + +/* +* The tunneled pci bridges are siblings of us. Use resume_noirq to reenable +* the tunnels asap. A corresponding pci quirk blocks the downstream bridges
+ *resume_noirquntil we are done.
+ */drivers/thunderbolt/icm/icm_nhi.c new file +6
-0+static const struct dev_pm_ops icm_nhi_pm_ops = { +SET_SYSTEM_SLEEP_PM_OPS (nhi_suspend, nhi_resume) +}; + +static const struct pci_device_id nhi_pci_device_ids[] = { + { PCI_VDEVICE(INTEL,
PCI_DEVICE_ID_INTEL_REDWOOD_RIDGE_2C_NHI),drivers/thunderbolt/icm/icm_nhi.c new file +2
-0+ DEVICE_DATA(1, 5, 0xa, false, false) }, + { PCI_VDEVICE(INTEL,
PCI_DEVICE_ID_INTEL_REDWOOD_RIDGE_4C_NHI),drivers/thunderbolt/icm/icm_nhi.c new file +2
-0+ DEVICE_DATA(2, 5, 0xa, false, false) }, + { PCI_VDEVICE(INTEL,
PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_NHI),drivers/thunderbolt/icm/icm_nhi.c new file +2
-0+ DEVICE_DATA(1, 5, 0xa, false, false) }, + { PCI_VDEVICE(INTEL,
PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_NHI),drivers/thunderbolt/icm/icm_nhi.c new file +4
-0+ DEVICE_DATA(2, 5, 0xa, false, false) }, + {PCI_VDEVICE (INTEL ,PCI_DEVICE_ID_INTEL_WIN_RIDGE_2C_NHI ), + DEVICE_DATA(1, 3, 0xa, false, false) }, + { PCI_VDEVICE(INTEL,
PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_NHI),drivers/thunderbolt/icm/icm_nhi.c new file +2
-0+ DEVICE_DATA(1, 5, 0xa, true, true) }, + { PCI_VDEVICE(INTEL,
PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_NHI),drivers/thunderbolt/icm/icm_nhi.c new file +2
-0+ DEVICE_DATA(2, 5, 0xa, true, true) }, + { PCI_VDEVICE(INTEL,
PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_NHI),drivers/thunderbolt/icm/icm_nhi.c new file +2
-0+ DEVICE_DATA(1, 3, 0xa, true, true) }, + { PCI_VDEVICE(INTEL,
PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_NHI),drivers/thunderbolt/icm/icm_nhi.c new file +2
-0+ DEVICE_DATA(1, 5, 0xa, true, true) }, + { PCI_VDEVICE(INTEL,
PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_NHI),drivers/thunderbolt/icm/icm_nhi.c new file +50
-0+ DEVICE_DATA(2, 5, 0xa, true, true) }, + { 0, } +}; + +MODULE_DEVICE_TABLE (pci, nhi_pci_device_ids); +MODULE_LICENSE ("GPL" ); +MODULE_VERSION (DRV_VERSION ); + +static struct pci_driver icm_nhi_driver = { + .name =DRV_NAME , + .id_table = nhi_pci_device_ids, + .probe = icm_nhi_probe, + .remove = icm_nhi_remove, + .shutdown = icm_nhi_shutdown, + .driver.pm = &icm_nhi_pm_ops, +}; + +static int __init icm_nhi_init (void ) +{ +int rc; + +if (dmi_match (DMI_BOARD_VENDOR ,"Apple Inc." )) +return -ENODEV ; + + rc =genl_register_family_with_ops (&nhi_genl_family, nhi_ops); +if (rc) + goto failure; + + rc =pci_register_driver (&icm_nhi_driver); +if (rc) + goto failure_genl; + +return 0 ; + +failure_genl: +genl_unregister_family (&nhi_genl_family); + +failure: +pr_debug ("nhi: error %d occurred in %s\n" , rc, __func__); +return rc; +} + +static void __exit icm_nhi_unload(void) +{ +genl_unregister_family (&nhi_genl_family); +pci_unregister_driver (&icm_nhi_driver); +} + +module_init (icm_nhi_init); +module_exit (icm_nhi_unload);drivers/thunderbolt/icm/icm_nhi.h new file +1
-0@@ -0,0 +1,84 @@ +/********************************************************* **********************
+ *
+ * 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.h line 33
Quoted 8 lines
drivers/thunderbolt/icm/icm_nhi.h new file +8
-0+ +#ifndef ICM_NHI_H_ +#define ICM_NHI_H_ + +#include <linux/pci.h> +#include "../nhi_regs.h" + +#define DRV_VERSION "16.1.51.1"
Will you really keep up with versioning of the driver ?
drivers/thunderbolt/icm/icm_nhi.h line 45
Quoted 13 lines
drivers/thunderbolt/icm/icm_nhi.h new file +5
-0+#define DRV_NAME "thunderbolt" + +#define TBT_ICM_RING_MAX_FRAME_SIZE 256 +#define TBT_ICM_RING_NUM 0 +#define TBT_RING_MAX_FRM_DATA_SZ (TBT_RING_MAX_FRAME_SIZE - \drivers/thunderbolt/icm/icm_nhi.h new file +7
-0+ sizeof(struct tbt_frame_header)) + +enum icm_operation_mode { +SAFE_MODE , +AUTHENTICATION_MODE_FUNCTIONALITY , +ENDPOINT_OPERATION_MODE , +FULL_FUNCTIONALITY ,
I would use some OP_MODE_ prefix
Quoted 253 lines
drivers/thunderbolt/icm/icm_nhi.h new file +4
-0+}; + +#define TBT_ICM_RING_NUM_TX_BUFS TBT_RING_MIN_NUM_BUFFERS +#define TBT_ICM_RING_NUM_RX_BUFS ((PAGE_SIZE -(
TBT_ICM_RING_NUM_TX_BUFS* \drivers/thunderbolt/icm/icm_nhi.h new file +1
-0+ (sizeof(struct tbt_buf_desc) + TBT_ICM_RING_MAX_FRAME_SIZE)))/ \
drivers/thunderbolt/icm/icm_nhi.h new file +5
-0+ (sizeof(struct tbt_buf_desc) + TBT_ICM_RING_MAX_FRAME_SIZE)) + +/* struct tbt_icm_ring_shared_memory - memory area for DMA */ +struct tbt_icm_ring_shared_memory { +u8 tx_buf[TBT_ICM_RING_NUM_TX_BUFS][TBT_ICM_RING_MAX_FRAME_SIZ E];
drivers/thunderbolt/icm/icm_nhi.h new file +1
-0+ u8rx_buf[TBT_ICM_RING_NUM_RX_BUFS][TBT_ICM_RING_MAX_FRAME_SIZ E];
drivers/thunderbolt/icm/icm_nhi.h new file +11
-0+struct tbt_buf_desc tx_buf_desc[TBT_ICM_RING_NUM_TX_BUFS ]; +struct tbt_buf_desc rx_buf_desc[TBT_ICM_RING_NUM_RX_BUFS ]; +}__aligned(TBT_ICM_RING_MAX_FRAME_SIZE) ; + +/* mailbox data from SW */ +#define REG_INMAIL_DATA 0x39900 + +/* mailbox command from SW */ +#define REG_INMAIL_CMD 0x39904 +#define REG_INMAIL_CMD_CMD_SHIFT 0 +#define REG_INMAIL_CMD_CMD_MASK GENMASK(7,
REG_INMAIL_CMD_CMD_SHIFT)drivers/thunderbolt/icm/icm_nhi.h new file +7
-0+#define REG_INMAIL_CMD_ERROR BIT(30) +#define REG_INMAIL_CMD_REQUEST BIT(31) + +/* mailbox command from FW */ +#define REG_OUTMAIL_CMD 0x3990C +#define REG_OUTMAIL_CMD_STS_SHIFT 0 +#define REG_OUTMAIL_CMD_STS_MASK GENMASK(7,
REG_OUTMAIL_CMD_STS_SHIFT)drivers/thunderbolt/icm/icm_nhi.h new file +3
-0+#define REG_OUTMAIL_CMD_OP_MODE_SHIFT 8 +#define REG_OUTMAIL_CMD_OP_MODE_MASK \ + GENMASK(11,
REG_OUTMAIL_CMD_OP_MODE_SHIFT)drivers/thunderbolt/icm/icm_nhi.h new file +7
-0+#define REG_OUTMAIL_CMD_REQUEST BIT(31) + +#define REG_FW_STS 0x39944 +#define REG_FW_STS_ICM_EN GENMASK(1, 0) +#define REG_FW_STS_NVM_AUTH_DONE BIT(31) + +#endif drivers/thunderbolt/icm/net.h new file +1
-0@@ -0,0 +1,200 @@ +/********************************************************* **********************
+ *
+ * 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/net.h new file +20
-0+ +#ifndef NET_H_ +#define NET_H_ + +#include <linux/pci.h> +#include <linux/netdevice.h> +#include <linux/mutex.h> +#include <linux/semaphore.h> +#include <net/genetlink.h> + +/* +* Each physical port contains 2 channels. +* Devices are exposed to user based on physical ports. +*/ +#define CHANNELS_PER_PORT_NUM 2 +/* +* Calculate host physical port number (Zero-based numbering) from +* host channel/link which starts from 1. +*/ +#define PORT_NUM_FROM_LINK (link) (((link) - 1) /
CHANNELS_PER_PORT_NUM)drivers/thunderbolt/icm/net.h new file +2
-0+ +#define TBT_TX_RING_FULL (prod, cons, size) ((((prod) + 1) % (size)) ==(cons))
drivers/thunderbolt/icm/net.h new file +3
-0+#define TBT_TX_RING_EMPTY (prod, cons) ((prod) == (cons)) +#define TBT_RX_RING_FULL (prod, cons) ((prod) == (cons)) +#define TBT_RX_RING_EMPTY (prod, cons, size) ((((cons) + 1) % (size)) ==(prod))
drivers/thunderbolt/icm/net.h new file +2
-0+ +#define PATH_FROM_PORT (num_paths, port_num) (((num_paths) - 1) -(
port_num))drivers/thunderbolt/icm/net.h new file +89
-0+ +/* PDF values for SW<->FW communication in raw mode */ +enum pdf_value { +PDF_READ_CONFIGURATION_REGISTERS =1 , +PDF_WRITE_CONFIGURATION_REGISTERS , +PDF_ERROR_NOTIFICATION , +PDF_ERROR_ACKNOWLEDGMENT , +PDF_PLUG_EVENT_NOTIFICATION , +PDF_INTER_DOMAIN_REQUEST , +PDF_INTER_DOMAIN_RESPONSE , +PDF_CM_OVERRIDE , +PDF_RESET_CIO_SWITCH , +PDF_FW_TO_SW_NOTIFICATION , +PDF_SW_TO_FW_COMMAND , +PDF_FW_TO_SW_RESPONSE +}; + +/* +* SW->FW commands +* CC = Command Code +*/ +enum { +CC_GET_THUNDERBOLT_TOPOLOGY =1 , +CC_GET_VIDEO_RESOURCES_DATA , +CC_DRV_READY , +CC_APPROVE_PCI_CONNECTION , +CC_CHALLENGE_PCI_CONNECTION , +CC_ADD_DEVICE_AND_KEY , +CC_APPROVE_INTER_DOMAIN_CONNECTION =0x10 +}; + +/* +* SW -> FW mailbox commands +* CC = Command Code +*/ +enum { +CC_STOP_CM_ACTIVITY , +CC_ENTER_PASS_THROUGH_MODE , +CC_ENTER_CM_OWNERSHIP_MODE , +CC_DRV_LOADED , +CC_DRV_UNLOADED , +CC_SAVE_CURRENT_CONNECTED_DEVICES , +CC_DISCONNECT_PCIE_PATHS , +CC_DRV_UNLOADS_AND_DISCONNECT_INTER_DOMAIN_PATHS , +DISCONNECT_PORT_A_INTER_DOMAIN_PATH =0x10 , +DISCONNECT_PORT_B_INTER_DOMAIN_PATH , +DP_TUNNEL_MODE_IN_ORDER_PER_CAPABILITIES =0x1E , +DP_TUNNEL_MODE_MAXIMIZE_SNK_SRC_TUNNELS , +CC_SET_FW_MODE_FD1_D1_CERT =0x20 , +CC_SET_FW_MODE_FD1_D1_ALL , +CC_SET_FW_MODE_FD1_DA_CERT , +CC_SET_FW_MODE_FD1_DA_ALL , +CC_SET_FW_MODE_FDA_D1_CERT , +CC_SET_FW_MODE_FDA_D1_ALL , +CC_SET_FW_MODE_FDA_DA_CERT , +CC_SET_FW_MODE_FDA_DA_ALL +}; + + +/* NHI genetlink attributes */ +enum { +NHI_ATTR_UNSPEC , +NHI_ATTR_DRV_VERSION , +NHI_ATTR_NVM_VER_OFFSET , +NHI_ATTR_NUM_PORTS , +NHI_ATTR_DMA_PORT , +NHI_ATTR_SUPPORT_FULL_E2E , +NHI_ATTR_MAILBOX_CMD , +NHI_ATTR_PDF , +NHI_ATTR_MSG_TO_ICM , +NHI_ATTR_MSG_FROM_ICM , + __NHI_ATTR_MAX, +}; +#define NHI_ATTR_MAX (__NHI_ATTR_MAX - 1) + +struct port_net_dev { +struct net_device *net_dev; +struct mutex state_mutex; +}; + +/** +* struct tbt_nhi_ctxt - thunderbolt native host interface context +* @node: node in the controllers list. +* @pdev: pci device information. +* @iobase: address of I/O. +* @msix_entries: MSI-X vectors. +* @icm_ring_shared_mem: virtual address of iCM ring. +* @icm_ring_shared_mem_dma_addr: DMA addr of iCM ring. +* @send_sem: semaphore for sending messages to iCM
+ * one at a time.
+ * @mailbox_mutex: mutex for sending mailbox
commands to
+ * iCM one at a time.
+ * @d0_exit_send_mutex: synchronizing the d0 exit with
messages.
+ * @d0_exit_mailbox_mutex: synchronizing the d0 exit with
mailbox.
+ * @lock: synchronizing the interrupt registers
+ * access.
+ * @icm_msgs_work: work queue for handling messages
+ * from iCM.+ * @net_devices: net devices per port. + * @net_workqueue: work queue to send net messages. + * @id: id of the controller. + * @num_paths: number of paths supported by controller. + * @nvm_ver_offset: offset of NVM version in NVM. + * @num_vectors: number of MSI-X vectors. + * @num_ports: number of ports in the controller. + * @dma_port: DMA port. + * @d0_exit: whether controller exit D0 state. + * @nvm_auth_on_boot: whether iCM authenticatesthe NVM
+ * during boot.
+ * @wait_for_icm_resp: whether to wait for iCM
response.
+ * @ignore_icm_resp: whether to ignore iCM
response.
+ * @pci_using_dac: whether using DAC.
+ * @support_full_e2e: whether controller support
full E2E.
+ */drivers/thunderbolt/icm/net.h new file +13
-0+struct tbt_nhi_ctxt { +struct list_head node; +struct pci_dev *pdev; +void __iomem *iobase; +struct msix_entry *msix_entries; +struct tbt_icm_ring_shared_memory *icm_ring_shared_mem; +dma_addr_t icm_ring_shared_mem_dma_addr; +struct semaphore send_sem; +struct mutex mailbox_mutex; +struct mutex d0_exit_send_mutex; +struct mutex d0_exit_mailbox_mutex; +spinlock_t lock; +struct work_struct icm_msgs_work;
drivers/thunderbolt/icm/net.h line 189
Quoted 10 lines
drivers/thunderbolt/icm/net.h new file +10
-0+struct port_net_dev *net_devices; +struct workqueue_struct *net_workqueue; +u32 id; +u32 num_paths; +u16 nvm_ver_offset; +u8 num_vectors; +u8 num_ports; +u8 dma_port; +bool d0_exit; + bool nvm_auth_on_boot : 1;
Don't use bool with bit fields use u32
Quoted 14 lines
drivers/thunderbolt/icm/net.h new file +9
-0+ bool wait_for_icm_resp : 1; + bool ignore_icm_resp : 1; + bool pci_using_dac : 1; + bool support_full_e2e : 1; +}; + +int nhi_send_message (struct tbt_nhi_ctxt *nhi_ctxt,enum pdf_value pdf, +u32 msg_len,const u8 *msg,bool ignore_icm_resp); +int nhi_mailbox(struct tbt_nhi_ctxt *nhi_ctxt, u32 cmd, u32 data, booldeinit);
drivers/thunderbolt/icm/net.h new file +2
-1+ +#endif --2.7.4
RE: [PATCH v3 5/8] thunderbolt: Communication with the ICM (firmware)
Hi Tomas,
Thanks for your comments.
Quoted 7 lines · Tomas
Quoted 7 lines
drivers/thunderbolt/icm/icm_nhi.c new file +7
-0+/* NHI genetlink commands */ +enum { +NHI_CMD_UNSPEC , +NHI_CMD_SUBSCRIBE , +NHI_CMD_UNSUBSCRIBE , +NHI_CMD_QUERY_INFORMATION , +NHI_CMD_MSG_TO_ICM ,
Quoted 9 lines
drivers/thunderbolt/icm/icm_nhi.c line 89
Quoted 7 lines
drivers/thunderbolt/icm/icm_nhi.c new file +7
-0+NHI_CMD_MSG_FROM_ICM , +NHI_CMD_MAILBOX , +NHI_CMD_APPROVE_TBT_NETWORKING , +NHI_CMD_ICM_IN_SAFE_MODE , + __NHI_CMD_MAX, +}; +#define NHI_CMD_MAX (__NHI_CMD_MAX - 1)
NHI_CMD_MAX=NHI_CMD_ICM_IN_SAFE_MODE?
This template is used a lot with (generic) netlink.
Few examples:
http://lxr.free-electrons.com/source/drivers/acpi/event.c#L62
http://lxr.free-electrons.com/source/include/uapi/linux/irda.h#L224
It is easier to maintain - adding entry in the list will automatically update MAX.
[...]
Quoted 10 lines
drivers/thunderbolt/icm/icm_nhi.c line 137
Quoted 7 lines
drivers/thunderbolt/icm/icm_nhi.c new file +7
-0+u32 status; + + status =ioread32 (nhi_ctxt->iobase +REG_FW_STS ); + +if (status ®_FW_STS_NVM_AUTH_DONE ) +break ; +msleep (30 );30 is big number, for polling, what is behind this?
The NVM authentication can take time for ICM. This number comes from experiments.
[...]
Quoted 10 lines
drivers/thunderbolt/icm/icm_nhi.c line 267
Quoted 7 lines
drivers/thunderbolt/icm/icm_nhi.c new file +7
-0+static struct tbt_nhi_ctxt *nhi_search_ctxt (u32 id) +{ +struct tbt_nhi_ctxt *nhi_ctxt; + +list_for_each_entry (nhi_ctxt, &controllers_list, node) +if (nhi_ctxt->id == id) +return nhi_ctxt;Don't you need to lock this list with the
controllers_list_rwsem?
This is a helper function for searching the list. The callers take and release the lock.
[...]
Quoted 2 lines
drivers/thunderbolt/icm/net.h line 189
Quoted 1 line
drivers/thunderbolt/icm/net.h new file +1
-0+ bool nvm_auth_on_boot : 1;Don't use bool with bit fields use u32
What is the concern here?
If it is size of bool, it doesn't matter for this struct. It is more readable that the expected value is bool, and it is used a lot in kernel, for example:
http://lxr.free-electrons.com/source/include/linux/pm.h#L558
RE: [PATCH v3 5/8] thunderbolt: Communication with the ICM (firmware)
In reply to Winkler, TomasHi Amir,
Here are my 2 cents:
This method always returns true, should be void (unless you will change PDF_ERROR_NOTIFICATION or other pdf values to return false), and likewise its invocation should not check return value.
Quoted 33 lines
drivers/thunderbolt/icm/icm_nhi.c new file +14
-0+static bool nhi_msg_from_icm_analysis (struct tbt_nhi_ctxt *nhi_ctxt, +enum pdf_value pdf, +const u8 *msg,u32 msg_len) +{ +/* +* preparation for messages that won't be sent, +* currently unused in this patch. +*/ +bool send_event = true; + +switch (pdf) { +case PDF_ERROR_NOTIFICATION : + dev_err(&nhi_ctxt->pdev->dev, + "controller id %#x PDF_ERROR_NOTIFICATION %hhumsg len %u\n",
drivers/thunderbolt/icm/icm_nhi.c new file +18
-0+ nhi_ctxt->id, msg[11], msg_len); +/* fallthrough */ +case PDF_WRITE_CONFIGURATION_REGISTERS : +/* fallthrough */ +case PDF_READ_CONFIGURATION_REGISTERS : +if (nhi_ctxt->wait_for_icm_resp) { + nhi_ctxt->wait_for_icm_resp = false; +up (&nhi_ctxt->send_sem); + } +break ; + +case PDF_FW_TO_SW_RESPONSE : +if (nhi_ctxt->wait_for_icm_resp) { + nhi_ctxt->wait_for_icm_resp = false; +up (&nhi_ctxt->send_sem); + } +break ; +
drivers/thunderbolt/icm/icm_nhi.c line 679
Quoted 10 lines
drivers/thunderbolt/icm/icm_nhi.c new file +10
-0+default : +dev_warn (&nhi_ctxt->pdev->dev, +"controller id %#x pdf %u isn't handled/expected\n" , + nhi_ctxt->id, pdf); +break ; + } + +return send_event; +} +
This methods always returns 0, should be void.
Quoted 43 lines
+static int
nhi_suspend(struct device *dev)__releases(&nhi_ctxt-Quoted 1 line
send_sem)drivers/thunderbolt/icm/icm_nhi.c new file +6
-0+{ +struct tbt_nhi_ctxt *nhi_ctxt =pci_get_drvdata (to_pci_dev (dev)); +void __iomem *rx_reg, *tx_reg; +u32 rx_reg_val, tx_reg_val; + +/* must be after negotiation_events, since messages might be sent */
drivers/thunderbolt/icm/icm_nhi.c new file +34
-0+ nhi_ctxt->d0_exit = true; + + rx_reg = nhi_ctxt->iobase +REG_RX_OPTIONS_BASE + + (TBT_ICM_RING_NUM *REG_OPTS_STEP ); + rx_reg_val =ioread32 (rx_reg) & ~REG_OPTS_E2E_EN ; + tx_reg = nhi_ctxt->iobase +REG_TX_OPTIONS_BASE + + (TBT_ICM_RING_NUM *REG_OPTS_STEP ); + tx_reg_val =ioread32 (tx_reg) & ~REG_OPTS_E2E_EN ; +/* disable RX flow control */ +iowrite32 (rx_reg_val, rx_reg); +/* disable TX flow control */ +iowrite32 (tx_reg_val, tx_reg); +/* disable RX ring */ +iowrite32 (rx_reg_val & ~REG_OPTS_VALID , rx_reg); + +mutex_lock (&nhi_ctxt->d0_exit_mailbox_mutex); +mutex_lock (&nhi_ctxt->d0_exit_send_mutex); + +cancel_work_sync (&nhi_ctxt->icm_msgs_work); + +if (nhi_ctxt->wait_for_icm_resp) { + nhi_ctxt->wait_for_icm_resp = false; + nhi_ctxt->ignore_icm_resp = false; +/* +* if there is response, it is lost, so unlock the send +* for the next resume. +*/ +up (&nhi_ctxt->send_sem); + } + +mutex_unlock (&nhi_ctxt->d0_exit_send_mutex); +mutex_unlock (&nhi_ctxt->d0_exit_mailbox_mutex); + +/* wait for all TX to finish */
drivers/thunderbolt/icm/icm_nhi.c line 924
Quoted 10 lines
drivers/thunderbolt/icm/icm_nhi.c new file +10
-0+usleep_range (5 *USEC_PER_MSEC ,7 *USEC_PER_MSEC ); + +/* disable all interrupts */ +iowrite32 (0 , nhi_ctxt->iobase +REG_RING_INTERRUPT_BASE ); +/* disable TX ring */ +iowrite32 (tx_reg_val & ~REG_OPTS_VALID , tx_reg); + +return 0 ; +} +
This methods also always returns 0, should be void.
Quoted 102 lines
+static int
nhi_resume(struct device *dev)__acquires(&nhi_ctxt-Quoted 1 line
send_sem)drivers/thunderbolt/icm/icm_nhi.c new file +11
-0+{ +dma_addr_t phys; +struct tbt_nhi_ctxt *nhi_ctxt =pci_get_drvdata (to_pci_dev (dev)); +struct tbt_buf_desc *desc; +void __iomem *iobase = nhi_ctxt->iobase; +void __iomem *reg; +int i; + +if (nhi_ctxt->msix_entries) { + iowrite32(ioread32(iobase + REG_DMA_MISC) | +
REG_DMA_MISC_INT_AUTO_CLEAR,drivers/thunderbolt/icm/icm_nhi.c new file +9
-0+ iobase + REG_DMA_MISC); +/* +* Vector #0, which is TX complete to ICM, +* isn't been used currently. +*/ +nhi_set_int_vec (nhi_ctxt,0 ,1 ); + +for (i =2 ; i < nhi_ctxt->num_vectors; i++) + nhi_set_int_vec(nhi_ctxt, nhi_ctxt->num_paths -(i/2),
drivers/thunderbolt/icm/icm_nhi.c new file +30
-0+ i); + } + +/* configure TX descriptors */ +for (i =0 , phys = nhi_ctxt->icm_ring_shared_mem_dma_addr; + i <TBT_ICM_RING_NUM_TX_BUFS ; + i++, phys +=TBT_ICM_RING_MAX_FRAME_SIZE ) { + desc = &nhi_ctxt->icm_ring_shared_mem->tx_buf_desc[i]; + desc->phys =cpu_to_le64 (phys); + desc->attributes =cpu_to_le32 (DESC_ATTR_REQ_STS ); + } +/* configure RX descriptors */ +for (i =0 ; + i <TBT_ICM_RING_NUM_RX_BUFS ; + i++, phys +=TBT_ICM_RING_MAX_FRAME_SIZE ) { + desc = &nhi_ctxt->icm_ring_shared_mem->rx_buf_desc[i]; + desc->phys =cpu_to_le64 (phys); + desc->attributes =cpu_to_le32 (DESC_ATTR_REQ_STS | +DESC_ATTR_INT_EN ); + } + +/* configure throttling rate for interrupts */ +for (i =0 , reg = iobase +REG_INT_THROTTLING_RATE ; + i <NUM_INT_VECTORS ; + i++, reg +=REG_INT_THROTTLING_RATE_STEP ) { +iowrite32 (USEC_TO_256_NSECS (128 ), reg); + } + +/* configure TX for ICM ring */ + reg = iobase + REG_TX_RING_BASE + (TBT_ICM_RING_NUM *
REG_RING_STEP);drivers/thunderbolt/icm/icm_nhi.c new file +5
-0+ phys = nhi_ctxt->icm_ring_shared_mem_dma_addr + + offsetof(struct tbt_icm_ring_shared_memory , tx_buf_desc); +iowrite32 (lower_32_bits (phys), reg +REG_RING_PHYS_LO_OFFSET ); +iowrite32 (upper_32_bits (phys), reg +REG_RING_PHYS_HI_OFFSET ); + iowrite32((TBT_ICM_RING_NUM_TX_BUFS <<
REG_RING_SIZE_SHIFT) &drivers/thunderbolt/icm/icm_nhi.c new file +4
-0+REG_RING_SIZE_MASK , + reg + REG_RING_SIZE_OFFSET); + + reg = iobase + REG_TX_OPTIONS_BASE +(TBT_ICM_RING_NUM*REG_OPTS_STEP);
drivers/thunderbolt/icm/icm_nhi.c new file +4
-0+iowrite32 (REG_OPTS_RAW |REG_OPTS_VALID , reg); + +/* configure RX for ICM ring */ + reg = iobase + REG_RX_RING_BASE + (TBT_ICM_RING_NUM *
REG_RING_STEP);drivers/thunderbolt/icm/icm_nhi.c new file +5
-0+ phys = nhi_ctxt->icm_ring_shared_mem_dma_addr + + offsetof(struct tbt_icm_ring_shared_memory , rx_buf_desc); +iowrite32 (lower_32_bits (phys), reg +REG_RING_PHYS_LO_OFFSET ); +iowrite32 (upper_32_bits (phys), reg +REG_RING_PHYS_HI_OFFSET ); + iowrite32(((TBT_ICM_RING_NUM_RX_BUFS <<
REG_RING_SIZE_SHIFT) &(quoted diff) +2
-0+ REG_RING_SIZE_MASK) | + ((TBT_ICM_RING_MAX_FRAME_SIZE <<
REG_RING_BUF_SIZE_SHIFT) &drivers/thunderbolt/icm/icm_nhi.c new file +3
-0+ REG_RING_BUF_SIZE_MASK), + reg + REG_RING_SIZE_OFFSET); + iowrite32(((TBT_ICM_RING_NUM_RX_BUFS - 1) <<
REG_RING_CONS_SHIFT) &drivers/thunderbolt/icm/icm_nhi.c new file +4
-0+REG_RING_CONS_MASK , + reg + REG_RING_CONS_PROD_OFFSET); + + reg = iobase + REG_RX_OPTIONS_BASE +(TBT_ICM_RING_NUM*REG_OPTS_STEP);
drivers/thunderbolt/icm/icm_nhi.c new file +4
-0+iowrite32 (REG_OPTS_RAW |REG_OPTS_VALID , reg); + +/* enable RX interrupt */ + RING_INT_ENABLE_RX(iobase, TBT_ICM_RING_NUM, nhi_ctxt-Quoted 1 line
num_paths);drivers/thunderbolt/icm/icm_nhi.c new file +8
-0+ +if (likely ((atomic_read (&subscribers) >0 ) && +nhi_nvm_authenticated (nhi_ctxt))) { +down (&nhi_ctxt->send_sem); + nhi_ctxt->d0_exit = false; +mutex_lock (&nhi_ctxt->d0_exit_send_mutex); +/* +* interrupts are enabled here before send due to
drivers/thunderbolt/icm/icm_nhi.c line 1024
Quoted 10 lines
drivers/thunderbolt/icm/icm_nhi.c new file +10
-0+* implicit barrier in mutex +*/ +nhi_send_driver_ready_command (nhi_ctxt); +mutex_unlock (&nhi_ctxt->d0_exit_send_mutex); + }else { + nhi_ctxt->d0_exit = false; + } + +return 0 ; +}
Regards,
Rami Rosen
Intel Corporation
RE: [PATCH v3 5/8] thunderbolt: Communication with the ICM (firmware)
Quoted 1 line · Rami
Hi Amir,
Hi Rami,
Quoted 6 lines
Here are my 2 cents:
This method always returns true, should be void (unless you will change
PDF_ERROR_NOTIFICATIONor other pdf values to return false), and likewise its invocation should not check return value.
This patch is the communication with the FW.
The network functionality is added in the next patches in the series and with it, more messages from FW.
Indeed this function always returns true in this patch,
but while writing it, I predicted that the network functionality will use the send_event flag differently.
You can see the documentation of send_event - currently unused in this patch. I don't see any harm that in this patch, this function will always return true, while applying the rest of the series will change it.
Quoted 37 lines
Quoted 37 lines
drivers/thunderbolt/icm/icm_nhi.c new file +14
-0+static bool nhi_msg_from_icm_analysis (struct tbt_nhi_ctxt *nhi_ctxt, +enum pdf_value pdf, +const u8 *msg,u32 msg_len) +{ +/* +* preparation for messages that won't be sent, +* currently unused in this patch. +*/ +bool send_event = true; + +switch (pdf) { +case PDF_ERROR_NOTIFICATION : + dev_err(&nhi_ctxt->pdev->dev, + "controller id %#x PDF_ERROR_NOTIFICATION %hhumsg len %u\n",
drivers/thunderbolt/icm/icm_nhi.c new file +22
-0+ nhi_ctxt->id, msg[11], msg_len); +/* fallthrough */ +case PDF_WRITE_CONFIGURATION_REGISTERS : +/* fallthrough */ +case PDF_READ_CONFIGURATION_REGISTERS : +if (nhi_ctxt->wait_for_icm_resp) { + nhi_ctxt->wait_for_icm_resp = false; +up (&nhi_ctxt->send_sem); + } +break ; + +case PDF_FW_TO_SW_RESPONSE : +if (nhi_ctxt->wait_for_icm_resp) { + nhi_ctxt->wait_for_icm_resp = false; +up (&nhi_ctxt->send_sem); + } +break ; + +default : +dev_warn (&nhi_ctxt->pdev->dev, +"controller id %#x pdf %u isn't handled/expected\n" , + nhi_ctxt->id, pdf);
Quoted 9 lines
drivers/thunderbolt/icm/icm_nhi.c line 679
Quoted 6 lines
drivers/thunderbolt/icm/icm_nhi.c new file +6
-0+break ; + } + +return send_event; +} +This methods always returns 0, should be void.
The prototype of suspend is return int:
http://lxr.free-electrons.com/source/include/linux/pm.h#L295
Quoted 47 lines
Quoted 47 lines
+static int
nhi_suspend(struct device *dev)__releases(&nhi_ctxt-Quoted 1 line
send_sem)drivers/thunderbolt/icm/icm_nhi.c new file +6
-0+{ +struct tbt_nhi_ctxt *nhi_ctxt =pci_get_drvdata (to_pci_dev (dev)); +void __iomem *rx_reg, *tx_reg; +u32 rx_reg_val, tx_reg_val; + +/* must be after negotiation_events, since messages might be sent */
drivers/thunderbolt/icm/icm_nhi.c new file +38
-0+ nhi_ctxt->d0_exit = true; + + rx_reg = nhi_ctxt->iobase +REG_RX_OPTIONS_BASE + + (TBT_ICM_RING_NUM *REG_OPTS_STEP ); + rx_reg_val =ioread32 (rx_reg) & ~REG_OPTS_E2E_EN ; + tx_reg = nhi_ctxt->iobase +REG_TX_OPTIONS_BASE + + (TBT_ICM_RING_NUM *REG_OPTS_STEP ); + tx_reg_val =ioread32 (tx_reg) & ~REG_OPTS_E2E_EN ; +/* disable RX flow control */ +iowrite32 (rx_reg_val, rx_reg); +/* disable TX flow control */ +iowrite32 (tx_reg_val, tx_reg); +/* disable RX ring */ +iowrite32 (rx_reg_val & ~REG_OPTS_VALID , rx_reg); + +mutex_lock (&nhi_ctxt->d0_exit_mailbox_mutex); +mutex_lock (&nhi_ctxt->d0_exit_send_mutex); + +cancel_work_sync (&nhi_ctxt->icm_msgs_work); + +if (nhi_ctxt->wait_for_icm_resp) { + nhi_ctxt->wait_for_icm_resp = false; + nhi_ctxt->ignore_icm_resp = false; +/* +* if there is response, it is lost, so unlock the send +* for the next resume. +*/ +up (&nhi_ctxt->send_sem); + } + +mutex_unlock (&nhi_ctxt->d0_exit_send_mutex); +mutex_unlock (&nhi_ctxt->d0_exit_mailbox_mutex); + +/* wait for all TX to finish */ +usleep_range (5 *USEC_PER_MSEC ,7 *USEC_PER_MSEC ); + +/* disable all interrupts */ +iowrite32 (0 , nhi_ctxt->iobase +REG_RING_INTERRUPT_BASE );
Quoted 9 lines
drivers/thunderbolt/icm/icm_nhi.c line 924
Quoted 6 lines
drivers/thunderbolt/icm/icm_nhi.c new file +6
-0+/* disable TX ring */ +iowrite32 (tx_reg_val & ~REG_OPTS_VALID , tx_reg); + +return 0 ; +} +This methods also always returns 0, should be void.
The prototype of resume is return int:
http://lxr.free-electrons.com/source/include/linux/pm.h#L295
Quoted 117 lines
Quoted 102 lines
+static int
nhi_resume(struct device *dev)__acquires(&nhi_ctxt-Quoted 1 line
send_sem)drivers/thunderbolt/icm/icm_nhi.c new file +11
-0+{ +dma_addr_t phys; +struct tbt_nhi_ctxt *nhi_ctxt =pci_get_drvdata (to_pci_dev (dev)); +struct tbt_buf_desc *desc; +void __iomem *iobase = nhi_ctxt->iobase; +void __iomem *reg; +int i; + +if (nhi_ctxt->msix_entries) { + iowrite32(ioread32(iobase + REG_DMA_MISC) | +
REG_DMA_MISC_INT_AUTO_CLEAR,drivers/thunderbolt/icm/icm_nhi.c new file +9
-0+ iobase + REG_DMA_MISC); +/* +* Vector #0, which is TX complete to ICM, +* isn't been used currently. +*/ +nhi_set_int_vec (nhi_ctxt,0 ,1 ); + +for (i =2 ; i < nhi_ctxt->num_vectors; i++) + nhi_set_int_vec(nhi_ctxt, nhi_ctxt->num_paths -(i/2),
drivers/thunderbolt/icm/icm_nhi.c new file +30
-0+ i); + } + +/* configure TX descriptors */ +for (i =0 , phys = nhi_ctxt->icm_ring_shared_mem_dma_addr; + i <TBT_ICM_RING_NUM_TX_BUFS ; + i++, phys +=TBT_ICM_RING_MAX_FRAME_SIZE ) { + desc = &nhi_ctxt->icm_ring_shared_mem->tx_buf_desc[i]; + desc->phys =cpu_to_le64 (phys); + desc->attributes =cpu_to_le32 (DESC_ATTR_REQ_STS ); + } +/* configure RX descriptors */ +for (i =0 ; + i <TBT_ICM_RING_NUM_RX_BUFS ; + i++, phys +=TBT_ICM_RING_MAX_FRAME_SIZE ) { + desc = &nhi_ctxt->icm_ring_shared_mem->rx_buf_desc[i]; + desc->phys =cpu_to_le64 (phys); + desc->attributes =cpu_to_le32 (DESC_ATTR_REQ_STS | +DESC_ATTR_INT_EN ); + } + +/* configure throttling rate for interrupts */ +for (i =0 , reg = iobase +REG_INT_THROTTLING_RATE ; + i <NUM_INT_VECTORS ; + i++, reg +=REG_INT_THROTTLING_RATE_STEP ) { +iowrite32 (USEC_TO_256_NSECS (128 ), reg); + } + +/* configure TX for ICM ring */ + reg = iobase + REG_TX_RING_BASE + (TBT_ICM_RING_NUM *
REG_RING_STEP);drivers/thunderbolt/icm/icm_nhi.c new file +5
-0+ phys = nhi_ctxt->icm_ring_shared_mem_dma_addr + + offsetof(struct tbt_icm_ring_shared_memory , tx_buf_desc); +iowrite32 (lower_32_bits (phys), reg +REG_RING_PHYS_LO_OFFSET ); +iowrite32 (upper_32_bits (phys), reg +REG_RING_PHYS_HI_OFFSET ); + iowrite32((TBT_ICM_RING_NUM_TX_BUFS <<
REG_RING_SIZE_SHIFT) &drivers/thunderbolt/icm/icm_nhi.c new file +4
-0+REG_RING_SIZE_MASK , + reg + REG_RING_SIZE_OFFSET); + + reg = iobase + REG_TX_OPTIONS_BASE +(TBT_ICM_RING_NUM*REG_OPTS_STEP);
drivers/thunderbolt/icm/icm_nhi.c new file +4
-0+iowrite32 (REG_OPTS_RAW |REG_OPTS_VALID , reg); + +/* configure RX for ICM ring */ + reg = iobase + REG_RX_RING_BASE + (TBT_ICM_RING_NUM *
REG_RING_STEP);drivers/thunderbolt/icm/icm_nhi.c new file +5
-0+ phys = nhi_ctxt->icm_ring_shared_mem_dma_addr + + offsetof(struct tbt_icm_ring_shared_memory , rx_buf_desc); +iowrite32 (lower_32_bits (phys), reg +REG_RING_PHYS_LO_OFFSET ); +iowrite32 (upper_32_bits (phys), reg +REG_RING_PHYS_HI_OFFSET ); + iowrite32(((TBT_ICM_RING_NUM_RX_BUFS <<
REG_RING_SIZE_SHIFT) &(quoted diff) +2
-0+ REG_RING_SIZE_MASK) | + ((TBT_ICM_RING_MAX_FRAME_SIZE <<
REG_RING_BUF_SIZE_SHIFT) &drivers/thunderbolt/icm/icm_nhi.c new file +3
-0+ REG_RING_BUF_SIZE_MASK), + reg + REG_RING_SIZE_OFFSET); + iowrite32(((TBT_ICM_RING_NUM_RX_BUFS - 1) <<
REG_RING_CONS_SHIFT) &drivers/thunderbolt/icm/icm_nhi.c new file +4
-0+REG_RING_CONS_MASK , + reg + REG_RING_CONS_PROD_OFFSET); + + reg = iobase + REG_RX_OPTIONS_BASE +(TBT_ICM_RING_NUM*REG_OPTS_STEP);
drivers/thunderbolt/icm/icm_nhi.c new file +4
-0+iowrite32 (REG_OPTS_RAW |REG_OPTS_VALID , reg); + +/* enable RX interrupt */ + RING_INT_ENABLE_RX(iobase, TBT_ICM_RING_NUM, nhi_ctxt-Quoted 1 line
num_paths);drivers/thunderbolt/icm/icm_nhi.c new file +8
-0+ +if (likely ((atomic_read (&subscribers) >0 ) && +nhi_nvm_authenticated (nhi_ctxt))) { +down (&nhi_ctxt->send_sem); + nhi_ctxt->d0_exit = false; +mutex_lock (&nhi_ctxt->d0_exit_send_mutex); +/* +* interrupts are enabled here before send due to drivers/thunderbolt/icm/icm_nhi.c line 1024
Quoted 10 lines
drivers/thunderbolt/icm/icm_nhi.c new file +10
-0+* implicit barrier in mutex +*/ +nhi_send_driver_ready_command (nhi_ctxt); +mutex_unlock (&nhi_ctxt->d0_exit_send_mutex); + }else { + nhi_ctxt->d0_exit = false; + } + +return 0 ; +}Regards,
Rami Rosen
Intel Corporation
RE: [PATCH v3 5/8] thunderbolt: Communication with the ICM (firmware)
Hi, Amir,
Quoted 9 lines
This patch is the communication with the FW.
The network functionality is added in the next patches in the series and with it, more messages from FW.
Indeed this function always returns true in this patch,
but while writing it, I predicted that the network functionality will use thesend_eventflag differently.
You can see the documentation ofsend_event- currently unused in this patch. I don't see any harm that in this patch, this function will always return true, while applying the rest of the series will change it.
Ok, seems reasonable.
Quoted 5 lines
The prototype of suspend is return int:
http://lxr.free-electrons.com/source/include/linux/pm.h#L295The prototype of resume is return int:
http://lxr.free-electrons.com/source/include/linux/pm.h#L295
You are right about this, I missed the macro invocation in your code, SET_SYSTEM_SLEEP_PM_OPS(nhi_suspend, nhi_resume), apologies.
Regards,
Rami Rosen
Intel Corporation
Re: [PATCH v3 6/8] thunderbolt: Networking state machine
In reply to Amir LevyQuoted 423 lines · 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.Signed-off-by Amir Levy <[email protected]>--- drivers/thunderbolt/icm/Makefile | 2 +- drivers/thunderbolt/icm/icm_nhi.c | 304 ++++++++++++++- drivers/thunderbolt/icm/net.c | 802 ++++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/icm/net.h | 74 ++++ 4 files changed, 1171 insertions(+), 11 deletions(-) create mode 100644 drivers/thunderbolt/icm/net.cdrivers/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.odrivers/thunderbolt/icm/icm_nhi.c +294
-10@@ -101,6 +101,12 @@ static const struct nla_policy nhi_genl_policy[NHI_ATTR_MAX + 1] = { .len = TBT_ICM_RING_MAX_FRAME_SIZE }, [NHI_ATTR_MSG_FROM_ICM] = { .type = NLA_BINARY, .len = TBT_ICM_RING_MAX_FRAME_SIZE }, + [NHI_ATTR_LOCAL_ROUTE_STRING] = {.len = sizeof(struct route_string)}, + [NHI_ATTR_LOCAL_UNIQUE_ID] = { .len = sizeof(unique_id) }, + [NHI_ATTR_REMOTE_UNIQUE_ID] = { .len = sizeof(unique_id) }, + [NHI_ATTR_LOCAL_DEPTH] = { .type = NLA_U8, }, + [NHI_ATTR_ENABLE_FULL_E2E] = { .type = NLA_FLAG, }, + [NHI_ATTR_MATCH_FRAME_ID] = { .type = NLA_FLAG, }, };/* NHI genetlink family */ @@ -531,6 +537,29 @@ int nhi_mailbox(struct tbt_nhi_ctxt *nhi_ctxt, u32 cmd, u32 data, bool deinit)return 0 ; } +static inline bool nhi_is_path_disconnected (u32 cmd,u8 num_ports) +{ +return (cmd >=DISCONNECT_PORT_A_INTER_DOMAIN_PATH && + cmd < (DISCONNECT_PORT_A_INTER_DOMAIN_PATH + num_ports)); +} + +static int nhi_mailbox_disconn_path (struct tbt_nhi_ctxt *nhi_ctxt,u32 cmd) + __releases(&controllers_list_rwsem) +{ +struct port_net_dev *port; +u32 port_num = cmd -DISCONNECT_PORT_A_INTER_DOMAIN_PATH ; + + port = &(nhi_ctxt->net_devices[port_num]); +mutex_lock (&port->state_mutex); + +up_read (&controllers_list_rwsem); + port->medium_sts =MEDIUM_READY_FOR_APPROVAL ; +if (port->net_dev) +negotiation_events (port->net_dev,MEDIUM_DISCONNECTED ); +mutex_unlock (&port->state_mutex); +return 0 ; +} +static int nhi_mailbox_generic (struct tbt_nhi_ctxt *nhi_ctxt,u32 mb_cmd) __releases(&controllers_list_rwsem) {@@ -579,13 +608,93 @@ static int nhi_genl_mailbox(__always_unused struct sk_buff *u_skb,down_read (&controllers_list_rwsem); nhi_ctxt =nhi_search_ctxt (*(u32 *)info->userhdr); -if (nhi_ctxt && !nhi_ctxt->d0_exit) -return nhi_mailbox_generic (nhi_ctxt, mb_cmd); +if (nhi_ctxt && !nhi_ctxt->d0_exit) { + +/* rwsem is released later by the below functions */ +if (nhi_is_path_disconnected (cmd, nhi_ctxt->num_ports)) +return nhi_mailbox_disconn_path (nhi_ctxt, cmd); +else +return nhi_mailbox_generic (nhi_ctxt, mb_cmd); + + }up_read (&controllers_list_rwsem);return -ENODEV ; } +static int nhi_genl_approve_networking (__always_unused struct sk_buff *u_skb, +struct genl_info *info) +{ +struct tbt_nhi_ctxt *nhi_ctxt; +struct route_string *route_str; +int res = -ENODEV ; +u8 port_num; + +if (!info || !info->userhdr || !info->attrs || + !info->attrs[NHI_ATTR_LOCAL_ROUTE_STRING ] || + !info->attrs[NHI_ATTR_LOCAL_UNIQUE_ID ] || + !info->attrs[NHI_ATTR_REMOTE_UNIQUE_ID ] || + !info->attrs[NHI_ATTR_LOCAL_DEPTH ]) +return -EINVAL ; + +/* +* route_str is an unique topological address +* used for approving remote controller +*/ + route_str =nla_data (info->attrs[NHI_ATTR_LOCAL_ROUTE_STRING ]); +/* extracts the port we're connected to */ + port_num =PORT_NUM_FROM_LINK (L0_PORT_NUM (route_str->lo)); + +down_read (&controllers_list_rwsem); + + nhi_ctxt =nhi_search_ctxt (*(u32 *)info->userhdr); +if (nhi_ctxt && !nhi_ctxt->d0_exit) { +struct port_net_dev *port; + +if (port_num >= nhi_ctxt->num_ports) { + res = -EINVAL ; + goto free_ctl_list; + } + + port = &(nhi_ctxt->net_devices[port_num]); + +mutex_lock (&port->state_mutex); +up_read (&controllers_list_rwsem); + +if (port->medium_sts !=MEDIUM_READY_FOR_APPROVAL ) { +dev_info (&nhi_ctxt->pdev->dev, +"%s: controller id %#x in state %u <> MEDIUM_READY_FOR_APPROVAL\n" , + __func__, nhi_ctxt->id, port->medium_sts); + goto unlock; + } + + port->medium_sts =MEDIUM_READY_FOR_CONNECTION ; + +if (!port->net_dev) { + port->net_dev =nhi_alloc_etherdev (nhi_ctxt, port_num, + info); +if (!port->net_dev) { +mutex_unlock (&port->state_mutex); +return -ENOMEM ; + } + }else { +nhi_update_etherdev (nhi_ctxt, port->net_dev, info); + +negotiation_events (port->net_dev, +MEDIUM_READY_FOR_CONNECTION ); + } + +unlock: +mutex_unlock (&port->state_mutex); + +return 0 ; + } + +free_ctl_list: +up_read (&controllers_list_rwsem); + +return res; +}static int nhi_genl_send_msg (struct tbt_nhi_ctxt *nhi_ctxt,enum pdf_value pdf,const u8 *msg,u32 msg_len)@@ -635,17 +744,169 @@ genl_put_reply_failure:return res; } +static bool nhi_handle_inter_domain_msg (struct tbt_nhi_ctxt *nhi_ctxt, +struct thunderbolt_ip_header *hdr) +{ +struct port_net_dev *port; +u8 port_num; + +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 ) { +dev_dbg (&nhi_ctxt->pdev->dev, +"controller id %#x XDomain discovery message\n" , + nhi_ctxt->id); +return true; + } + +dev_dbg (&nhi_ctxt->pdev->dev, +"controller id %#x ThunderboltIP %u\n" , + nhi_ctxt->id,be32_to_cpu (hdr->packet_type)); + + port_num =PORT_NUM_FROM_LINK ( +L0_PORT_NUM (be32_to_cpu (hdr->route_str.lo))); + +if (unlikely (port_num >= nhi_ctxt->num_ports)) { +dev_err (&nhi_ctxt->pdev->dev, +"controller id %#x invalid port %u in ThunderboltIP message\n" , + nhi_ctxt->id, port_num); +return false; + } + + port = &(nhi_ctxt->net_devices[port_num]); +mutex_lock (&port->state_mutex); +if (likely (port->net_dev !=NULL )) +negotiation_messages (port->net_dev, hdr); +else +dev_notice (&nhi_ctxt->pdev->dev, +"controller id %#x port %u in ThunderboltIP message was not initialized\n" , + nhi_ctxt->id, port_num); +mutex_unlock (&port->state_mutex); + +return false; +} + +static void nhi_handle_notification_msg (struct tbt_nhi_ctxt *nhi_ctxt, +const u8 *msg) +{ +struct port_net_dev *port; +u8 port_num; + +#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 )) + nhi_ctxt->net_devices[ + port_num].medium_sts = +MEDIUM_READY_FOR_APPROVAL ; + }else { +dev_err (&nhi_ctxt->pdev->dev, +"controller id %#x invalid port %u in inter domain connected message\n" , + nhi_ctxt->id, port_num); + } +break ; + +case NC_INTER_DOMAIN_DISCONNECTED : + port_num =PORT_NUM_FROM_MSG (msg[5 ]); + +if (unlikely (port_num >= nhi_ctxt->num_ports)) { +dev_err (&nhi_ctxt->pdev->dev, +"controller id %#x invalid port %u in inter domain disconnected message\n" , + nhi_ctxt->id, port_num); +break ; + } + + port = &(nhi_ctxt->net_devices[port_num]); +mutex_lock (&port->state_mutex); + port->medium_sts =MEDIUM_DISCONNECTED ; + +if (likely (port->net_dev !=NULL )) +negotiation_events (port->net_dev, +MEDIUM_DISCONNECTED ); +else +dev_notice (&nhi_ctxt->pdev->dev, +"controller id %#x port %u in inter domain disconnected message was not initialized\n" , + nhi_ctxt->id, port_num); +mutex_unlock (&port->state_mutex); +break ; + } +} + +static bool nhi_handle_icm_response_msg (struct tbt_nhi_ctxt *nhi_ctxt, +const u8 *msg) +{ +struct port_net_dev *port; +bool send_event = true; +u8 port_num; + +if (nhi_ctxt->ignore_icm_resp && + msg[3 ] ==RC_INTER_DOMAIN_PKT_SENT ) { + nhi_ctxt->ignore_icm_resp = false; + send_event = false; + } +if (nhi_ctxt->wait_for_icm_resp) { + nhi_ctxt->wait_for_icm_resp = false; +up (&nhi_ctxt->send_sem); + } + +if (msg[3 ] ==RC_APPROVE_INTER_DOMAIN_CONNEXION ) { +#define APPROVE_INTER_DOMAIN_ERROR BIT(0) +if (unlikely (msg[2 ] &APPROVE_INTER_DOMAIN_ERROR )) { +dev_err (&nhi_ctxt->pdev->dev, +"controller id %#x inter domain approve error\n" , + nhi_ctxt->id); +return send_event; + } + port_num =PORT_NUM_FROM_LINK ((msg[5 ]&INTER_DOMAIN_LINK_MASK )>> +INTER_DOMAIN_LINK_SHIFT ); + +if (unlikely (port_num >= nhi_ctxt->num_ports)) { +dev_err (&nhi_ctxt->pdev->dev, +"controller id %#x invalid port %u in inter domain approve message\n" , + nhi_ctxt->id, port_num); +return send_event; + } + + port = &(nhi_ctxt->net_devices[port_num]); +mutex_lock (&port->state_mutex); + port->medium_sts =MEDIUM_CONNECTED ; + +if (likely (port->net_dev !=NULL )) +negotiation_events (port->net_dev,MEDIUM_CONNECTED ); +else +dev_err (&nhi_ctxt->pdev->dev, +"controller id %#x port %u in inter domain approve message was not initialized\n" , + nhi_ctxt->id, port_num); +mutex_unlock (&port->state_mutex); + } + +return send_event; +} +static bool nhi_msg_from_icm_analysis (struct tbt_nhi_ctxt *nhi_ctxt,enum pdf_value pdf,const u8 *msg,u32 msg_len) { -/* -* preparation for messages that won't be sent, -* currently unused in this patch. -*/ bool send_event = true;switch (pdf) { +case PDF_INTER_DOMAIN_REQUEST : +case PDF_INTER_DOMAIN_RESPONSE : + send_event =nhi_handle_inter_domain_msg ( + nhi_ctxt, + (struct thunderbolt_ip_header *)msg); +break ; + +case PDF_FW_TO_SW_NOTIFICATION : +nhi_handle_notification_msg (nhi_ctxt, msg); +break ; +case PDF_ERROR_NOTIFICATION : dev_err(&nhi_ctxt->pdev->dev, "controller id %#x PDF_ERROR_NOTIFICATION %hhu msg len %u\n",@@ -661,10 +922,7 @@ static bool nhi_msg_from_icm_analysis(struct tbt_nhi_ctxt *nhi_ctxt,break ;case PDF_FW_TO_SW_RESPONSE : -if (nhi_ctxt->wait_for_icm_resp) { - nhi_ctxt->wait_for_icm_resp = false; -up (&nhi_ctxt->send_sem); - } + send_event =nhi_handle_icm_response_msg (nhi_ctxt, msg);break ;default :@@ -869,6 +1127,12 @@ static const struct genl_ops nhi_ops[] = { .doit = nhi_genl_mailbox, .flags = GENL_ADMIN_PERM, }, + { + .cmd = NHI_CMD_APPROVE_TBT_NETWORKING, + .policy = nhi_genl_policy, + .doit = nhi_genl_approve_networking, + .flags = GENL_ADMIN_PERM, + }, }; static int nhi_suspend(struct device *dev) __releases(&nhi_ctxt->send_sem)@@ -876,6 +1140,17 @@ static int nhi_suspend(struct device *dev) __releases(&nhi_ctxt->send_sem)struct tbt_nhi_ctxt *nhi_ctxt =pci_get_drvdata (to_pci_dev (dev));void __iomem *rx_reg, *tx_reg;u32 rx_reg_val, tx_reg_val; +int i; + +for (i =0 ; i < nhi_ctxt->num_ports; i++) { +struct port_net_dev *port = &nhi_ctxt->net_devices[i]; + +mutex_lock (&port->state_mutex); + port->medium_sts =MEDIUM_DISCONNECTED ; +if (port->net_dev) +negotiation_events (port->net_dev,MEDIUM_DISCONNECTED ); +mutex_unlock (&port->state_mutex); + }/* must be after negotiation_events, since messages might be sent */ nhi_ctxt->d0_exit = true;@@ -1035,6 +1310,15 @@ static void icm_nhi_remove(struct pci_dev *pdev)nhi_suspend (&pdev->dev); +for (i =0 ; i < nhi_ctxt->num_ports; i++) { +mutex_lock (&nhi_ctxt->net_devices[i].state_mutex); +if (nhi_ctxt->net_devices[i].net_dev) { +nhi_dealloc_etherdev (nhi_ctxt->net_devices[i].net_dev); + nhi_ctxt->net_devices[i].net_dev =NULL ; + } +mutex_unlock (&nhi_ctxt->net_devices[i].state_mutex); + } +if (nhi_ctxt->net_workqueue)destroy_workqueue (nhi_ctxt->net_workqueue);drivers/thunderbolt/icm/net.c new file +17
-0@@ -0,0 +1,802 @@ +/******************************************************************************* +* +* 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/>. +*
drivers/thunderbolt/icm/net.c line 27
Quoted 10 lines
drivers/thunderbolt/icm/net.c new file +10
-0+* 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 +* +******************************************************************************/ + +#include <linux/module.h>
I did not see anything like module_init in this driver; I think it seems like you
want linux/moduleparam.h here.
Thanks,
Paul.
--
Quoted 11 lines
drivers/thunderbolt/icm/net.c new file +10
-0+#include <linux/etherdevice.h> +#include <linux/crc32.h> +#include <linux/prefetch.h> +#include <linux/highmem.h> +#include <linux/if_vlan.h> +#include <linux/jhash.h> +#include <linux/vmalloc.h> +#include <net/ip6_checksum.h> +#include "icm_nhi.h" +#include "net.h"
David Miller
maintainerRe: [PATCH v3 2/8] thunderbolt: Updating device IDs
In reply to Amir LevyFrom: Amir Levy <[email protected]>
Date: Thu, 14 Jul 2016 14:28:16 +0300
Quoted 3 lines
Adding the new Thunderbolt(TM) device IDs to the list.
Signed-off-by Amir Levy <[email protected]>
Unless these PCI-IDs, all of them, are going to be used in multiple spots in the kernel, it is not appropriate to add them here.
They belong as private macros in the drivers themselves, instead.
RE: [PATCH v3 2/8] thunderbolt: Updating device IDs
Quoted 11 lines · David Miller
From: Amir Levy <[email protected]>
Date: Thu, 14 Jul 2016 14:28:16 +0300Quoted 3 lines
Adding the new Thunderbolt(TM) device IDs to the list.
Signed-off-by Amir Levy <[email protected]>Unless these PCI-IDs, all of them, are going to be used in multiple spots in the kernel, it is not appropriate to add them here.
They belong as private macros in the drivers themselves, instead.
They might be used: http://www.spinics.net/lists/linux-pci/msg51331.html
David Miller
maintainerRe: [PATCH v3 2/8] thunderbolt: Updating device IDs
From: "Levy, Amir (Jer)" <[email protected]>
Date: Fri, 15 Jul 2016 18:56:39 +0000
Quoted 6 lines · David Miller
Quoted 5 lines
From: Amir Levy <[email protected]>
Date: Thu, 14 Jul 2016 14:28:16 +0300Quoted 2 lines
Adding the new Thunderbolt(TM) device IDs to the list.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Signed-off-by Amir Levy <[email protected]>Unless these PCI-IDs, all of them, are going to be used in multiple spots in the kernel, it is not appropriate to add them here.
They belong as private macros in the drivers themselves, instead.
They might be used: http://www.spinics.net/lists/linux-pci/msg51331.html
Then move them to the common location when this "might" thing actually happens.
RE: [PATCH v3 5/8] thunderbolt: Communication with the ICM (firmware)
In reply to Levy, Amir (Jer)Quoted 35 lines
-----Original Message-----
From: Levy, Amir (Jer)
Sent: Thursday, July 14, 2016 17:50
To: Winkler, Tomas <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; thunderbolt-linux <[email protected]>; Westerberg, Mika <[email protected]>
Subject: RE: [PATCH v3 5/8] thunderbolt: Communication with the ICM (firmware)Hi Tomas,
Thanks for your comments.Quoted 7 lines · Tomas
Quoted 7 lines
drivers/thunderbolt/icm/icm_nhi.c new file +7
-0+/* NHI genetlink commands */ +enum { +NHI_CMD_UNSPEC , +NHI_CMD_SUBSCRIBE , +NHI_CMD_UNSUBSCRIBE , +NHI_CMD_QUERY_INFORMATION , +NHI_CMD_MSG_TO_ICM ,Quoted 9 lines
drivers/thunderbolt/icm/icm_nhi.c line 89
Quoted 7 lines
drivers/thunderbolt/icm/icm_nhi.c new file +7
-0+NHI_CMD_MSG_FROM_ICM , +NHI_CMD_MAILBOX , +NHI_CMD_APPROVE_TBT_NETWORKING , +NHI_CMD_ICM_IN_SAFE_MODE , + __NHI_CMD_MAX, +}; +#define NHI_CMD_MAX (__NHI_CMD_MAX - 1)
NHI_CMD_MAX=NHI_CMD_ICM_IN_SAFE_MODE?
Quoted 6 lines
This template is used a lot with (generic) netlink.
Few examples:
http://lxr.free-electrons.com/source/drivers/acpi/event.c#L62
http://lxr.free-electrons.com/source/include/uapi/linux/irda.h#L224
It is easier to maintain - adding entry in the list will automatically update MAX.
Fair enough.
Quoted 13 lines
[...]
Quoted 10 lines
drivers/thunderbolt/icm/icm_nhi.c line 137
Quoted 7 lines
drivers/thunderbolt/icm/icm_nhi.c new file +7
-0+u32 status; + + status =ioread32 (nhi_ctxt->iobase +REG_FW_STS ); + +if (status ®_FW_STS_NVM_AUTH_DONE ) +break ; +msleep (30 );30 is big number, for polling, what is behind this?
Quoted 2 lines
The NVM authentication can take time for ICM.
This number comes from experiments.
This deserve some comment, this look very random.
Quoted 12 lines
[...]
Quoted 9 lines
drivers/thunderbolt/icm/icm_nhi.c line 267
Quoted 6 lines
drivers/thunderbolt/icm/icm_nhi.c new file +6
-0+static struct tbt_nhi_ctxt *nhi_search_ctxt (u32 id) { +struct tbt_nhi_ctxt *nhi_ctxt; + +list_for_each_entry (nhi_ctxt, &controllers_list, node) +if (nhi_ctxt->id == id) +return nhi_ctxt;Don't you need to lock this list with the
controllers_list_rwsem?
Quoted 2 lines
This is a helper function for searching the list.
The callers take and release the lock.
Since this doesn't fit the patterns in your code, the function deserves a comment, that it should be used under lock.
Quoted 11 lines
[...]
Quoted 2 lines
drivers/thunderbolt/icm/net.h line 189
Quoted 1 line
drivers/thunderbolt/icm/net.h new file +1
-0+ bool nvm_auth_on_boot : 1;Don't use bool with bit fields use u32
What is the concern here?
If it is size of bool, it doesn't matter for this struct.
It is more readable that the expected value is bool, and it is used a lot in kernel, for example:
http://lxr.free-electrons.com/source/include/linux/pm.h#L558
Hmm, actually a nice feature I wasn't aware of, save some space and got bool type checking.
Thanks
RE: [PATCH v3 6/8] thunderbolt: Networking state machine
In reply to Paul GortmakerT24gRnJpLCBKdWwgMTUgMjAxNiwgMDM6MjUgQU0sIFBhdWwgR29ydG1ha2VyIHdyb3RlOg0KPiA+ IGRpZmYgLS1naXQgYS9kcml2ZXJzL3RodW5kZXJib2x0L2ljbS9uZXQuYw0KPiA+IGIvZHJpdmVy cy90aHVuZGVyYm9sdC9pY20vbmV0LmMgbmV3IGZpbGUgbW9kZSAxMDA2NDQgaW5kZXgNCj4gPiAw MDAwMDAwLi5lOTgzZGZiDQo+ID4gLS0tIC9kZXYvbnVsbA0KPiA+ICsrKyBiL2RyaXZlcnMvdGh1 bmRlcmJvbHQvaWNtL25ldC5jDQo+ID4gQEAgLTAsMCArMSw4MDIgQEANCj4gPg0KPiArLyoqKioq KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg0KPiAq KioqKioqKioqKg0KPiA+ICsqKioqKioqKioqKg0KPiA+ICsgKg0KPiA+ICsgKiBJbnRlbCBUaHVu ZGVyYm9sdChUTSkgZHJpdmVyDQo+ID4gKyAqIENvcHlyaWdodChjKSAyMDE0IC0gMjAxNiBJbnRl bCBDb3Jwb3JhdGlvbi4NCj4gPiArICoNCj4gPiArICogVGhpcyBwcm9ncmFtIGlzIGZyZWUgc29m dHdhcmU7IHlvdSBjYW4gcmVkaXN0cmlidXRlIGl0IGFuZC9vcg0KPiA+ICttb2RpZnkgaXQNCj4g PiArICogdW5kZXIgdGhlIHRlcm1zIGFuZCBjb25kaXRpb25zIG9mIHRoZSBHTlUgR2VuZXJhbCBQ dWJsaWMgTGljZW5zZSwNCj4gPiArICogdmVyc2lvbiAyLCBhcyBwdWJsaXNoZWQgYnkgdGhlIEZy ZWUgU29mdHdhcmUgRm91bmRhdGlvbi4NCj4gPiArICoNCj4gPiArICogVGhpcyBwcm9ncmFtIGlz IGRpc3RyaWJ1dGVkIGluIHRoZSBob3BlIGl0IHdpbGwgYmUgdXNlZnVsLCBidXQNCj4gPiArV0lU SE9VVA0KPiA+ICsgKiBBTlkgV0FSUkFOVFk7IHdpdGhvdXQgZXZlbiB0aGUgaW1wbGllZCB3YXJy YW50eSBvZg0KPiBNRVJDSEFOVEFCSUxJVFkNCj4gPiArb3INCj4gPiArICogRklUTkVTUyBGT1Ig QSBQQVJUSUNVTEFSIFBVUlBPU0UuICBTZWUgdGhlIEdOVSBHZW5lcmFsIFB1YmxpYw0KPiA+ICtM aWNlbnNlIGZvcg0KPiA+ICsgKiBtb3JlIGRldGFpbHMuDQo+ID4gKyAqDQo+ID4gKyAqIFlvdSBz aG91bGQgaGF2ZSByZWNlaXZlZCBhIGNvcHkgb2YgdGhlIEdOVSBHZW5lcmFsIFB1YmxpYyBMaWNl bnNlDQo+ID4gK2Fsb25nDQo+ID4gKyAqIHdpdGggdGhpcyBwcm9ncmFtLiAgSWYgbm90LCBzZWUg PGh0dHA6Ly93d3cuZ251Lm9yZy9saWNlbnNlcy8+Lg0KPiA+ICsgKg0KPiA+ICsgKiBUaGUgZnVs bCBHTlUgR2VuZXJhbCBQdWJsaWMgTGljZW5zZSBpcyBpbmNsdWRlZCBpbiB0aGlzDQo+ID4gK2Rp c3RyaWJ1dGlvbiBpbg0KPiA+ICsgKiB0aGUgZmlsZSBjYWxsZWQgIkNPUFlJTkciLg0KPiA+ICsg Kg0KPiA+ICsgKiBDb250YWN0IEluZm9ybWF0aW9uOg0KPiA+ICsgKiBJbnRlbCBUaHVuZGVyYm9s dCBNYWlsaW5nIExpc3QgPHRodW5kZXJib2x0LXNvZnR3YXJlQGxpc3RzLjAxLm9yZz4NCj4gPiAr ICogSW50ZWwgQ29ycG9yYXRpb24sIDUyMDAgTi5FLiBFbGFtIFlvdW5nIFBhcmt3YXksIEhpbGxz Ym9ybywgT1INCj4gPiArOTcxMjQtNjQ5Nw0KPiA+ICsgKg0KPiA+ICsNCj4gPg0KPiArKioqKioq KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqDQo+ICoq KioqKioqKioqKg0KPiA+ICsqKioqKioqKiovDQo+ID4gKw0KPiA+ICsjaW5jbHVkZSA8bGludXgv bW9kdWxlLmg+DQo+IA0KPiBJIGRpZCBub3Qgc2VlIGFueXRoaW5nIGxpa2UgbW9kdWxlX2luaXQg aW4gdGhpcyBkcml2ZXI7ICBJIHRoaW5rIGl0IHNlZW1zIGxpa2UgeW91DQo+IHdhbnQgbGludXgv bW9kdWxlcGFyYW0uaCBoZXJlLg0KPiANCg0KSGkgUGF1bCwNCkl0IGxvb2tzIGxpa2UgbGVmdG92 ZXIgZnJvbSB0aGUgZWFybHkgZGV2ZWxvcG1lbnQgc3RhZ2VzLg0KSSdsbCByZW1vdmUgaXQuDQpU aGUgbW9kdWxlX2luaXQgaXMgaW4gaWNtX25oaS5jLg0KDQpUaGFua3MsDQpBbWlyDQo=
RE: [PATCH v3 2/8] thunderbolt: Updating device IDs
In reply to David MillerQuoted 14 lines · David Miller
From: "Levy, Amir (Jer)" <[email protected]>
Date: Fri, 15 Jul 2016 18:56:39 +0000Quoted 11 lines · David Miller
Quoted 10 lines
From: Amir Levy <[email protected]>
Date: Thu, 14 Jul 2016 14:28:16 +0300Quoted 3 lines
Adding the new Thunderbolt(TM) device IDs to the list.
Signed-off-by Amir Levy <[email protected]>Unless these PCI-IDs, all of them, are going to be used in multiple spots in the kernel, it is not appropriate to add them here.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
They belong as private macros in the drivers themselves, instead.
They might be used:
http://www.spinics.net/lists/linux-pci/msg51331.htmlThen move them to the common location when this "might" thing actually happens.
There are several contradicting comments about this change (http://www.spinics.net/lists/linux-pci/msg51331.html and http://www.spinics.net/lists/linux-pci/msg51302.html)
I've decided for now to make the new device ids private to the driver.
This can be changed later when updating quirks for Apple hardware.
Regards,
Amir