Skip to content

Commit cd1be4b

Browse files
committed
Merge tag 'thunderbolt-for-v7.1-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt into usb-next
Mika writes: thunderbolt: Changes for v7.1 merge window This includes following USB4/Thunderbolt changes for the v7.1 merge window: - Disable CL-states for Titan Ridge based devices with older firmware. - MAINTAINER update. - Simplify allocation of various structures with kzalloc_flex(). All these have been in linux-next with no reported issues. * tag 'thunderbolt-for-v7.1-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt: thunderbolt: tunnel: Simplify allocation thunderbolt: Use kzalloc_flex() for struct tb_path allocation thunderbolt: dma_port: kmalloc_array + kzalloc to flex MAINTAINERS: Remove bouncing maintainer, Mika takes over DMA test driver thunderbolt: Disable CLx on Titan Ridge-based devices with old firmware thunderbolt: Read router NVM version before applying quirks
2 parents 8f993d3 + 498c058 commit cd1be4b

8 files changed

Lines changed: 52 additions & 50 deletions

File tree

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26310,7 +26310,7 @@ F: drivers/media/i2c/thp7312.c
2631026310
F: include/uapi/linux/thp7312.h
2631126311

2631226312
THUNDERBOLT DMA TRAFFIC TEST DRIVER
26313-
M: Isaac Hazan <isaac.hazan@intel.com>
26313+
M: Mika Westerberg <westeri@kernel.org>
2631426314
L: linux-usb@vger.kernel.org
2631526315
S: Maintained
2631626316
F: drivers/thunderbolt/dma_test.c

drivers/thunderbolt/dma_port.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct tb_dma_port {
5555
struct tb_switch *sw;
5656
u8 port;
5757
u32 base;
58-
u8 *buf;
58+
u8 buf[];
5959
};
6060

6161
/*
@@ -209,16 +209,10 @@ struct tb_dma_port *dma_port_alloc(struct tb_switch *sw)
209209
if (port < 0)
210210
return NULL;
211211

212-
dma = kzalloc_obj(*dma);
212+
dma = kzalloc_flex(*dma, buf, MAIL_DATA_DWORDS);
213213
if (!dma)
214214
return NULL;
215215

216-
dma->buf = kmalloc_array(MAIL_DATA_DWORDS, sizeof(u32), GFP_KERNEL);
217-
if (!dma->buf) {
218-
kfree(dma);
219-
return NULL;
220-
}
221-
222216
dma->sw = sw;
223217
dma->port = port;
224218
dma->base = DMA_PORT_CAP;
@@ -232,10 +226,7 @@ struct tb_dma_port *dma_port_alloc(struct tb_switch *sw)
232226
*/
233227
void dma_port_free(struct tb_dma_port *dma)
234228
{
235-
if (dma) {
236-
kfree(dma->buf);
237-
kfree(dma);
238-
}
229+
kfree(dma);
239230
}
240231

241232
static int dma_port_wait_for_completion(struct tb_dma_port *dma,

drivers/thunderbolt/path.c

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,17 @@ struct tb_path *tb_path_discover(struct tb_port *src, int src_hopid,
150150
num_hops++;
151151
}
152152

153-
path = kzalloc_obj(*path);
153+
path = kzalloc_flex(*path, hops, num_hops);
154154
if (!path)
155155
return NULL;
156156

157+
path->path_length = num_hops;
158+
157159
path->name = name;
158160
path->tb = src->sw->tb;
159-
path->path_length = num_hops;
160161
path->activated = true;
161162
path->alloc_hopid = alloc_hopid;
162163

163-
path->hops = kzalloc_objs(*path->hops, num_hops);
164-
if (!path->hops) {
165-
kfree(path);
166-
return NULL;
167-
}
168-
169164
tb_dbg(path->tb, "discovering %s path starting from %llx:%u\n",
170165
path->name, tb_route(src->sw), src->port);
171166

@@ -245,10 +240,6 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid,
245240
size_t num_hops;
246241
int i, ret;
247242

248-
path = kzalloc_obj(*path);
249-
if (!path)
250-
return NULL;
251-
252243
first_port = last_port = NULL;
253244
i = 0;
254245
tb_for_each_port_on_path(src, dst, in_port) {
@@ -259,20 +250,17 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid,
259250
}
260251

261252
/* Check that src and dst are reachable */
262-
if (first_port != src || last_port != dst) {
263-
kfree(path);
253+
if (first_port != src || last_port != dst)
264254
return NULL;
265-
}
266255

267256
/* Each hop takes two ports */
268257
num_hops = i / 2;
269258

270-
path->hops = kzalloc_objs(*path->hops, num_hops);
271-
if (!path->hops) {
272-
kfree(path);
259+
path = kzalloc_flex(*path, hops, num_hops);
260+
if (!path)
273261
return NULL;
274-
}
275262

263+
path->path_length = num_hops;
276264
path->alloc_hopid = true;
277265

278266
in_hopid = src_hopid;
@@ -339,7 +327,6 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid,
339327
}
340328

341329
path->tb = tb;
342-
path->path_length = num_hops;
343330
path->name = name;
344331

345332
return path;
@@ -372,7 +359,6 @@ void tb_path_free(struct tb_path *path)
372359
}
373360
}
374361

375-
kfree(path->hops);
376362
kfree(path);
377363
}
378364

drivers/thunderbolt/quirks.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ static void quirk_dp_credit_allocation(struct tb_switch *sw)
2323

2424
static void quirk_clx_disable(struct tb_switch *sw)
2525
{
26+
if (tb_switch_is_titan_ridge(sw) && sw->nvm && sw->nvm->major >= 0x65)
27+
return;
28+
2629
sw->quirks |= QUIRK_NO_CLX;
2730
tb_sw_dbg(sw, "disabling CL states\n");
2831
}
@@ -61,6 +64,10 @@ static const struct tb_quirk tb_quirks[] = {
6164
/* Dell WD19TB supports self-authentication on unplug */
6265
{ 0x0000, 0x0000, 0x00d4, 0xb070, quirk_force_power_link },
6366
{ 0x0000, 0x0000, 0x00d4, 0xb071, quirk_force_power_link },
67+
68+
/* Intel Titan Ridge CLx is unstable on early firmware versions */
69+
{ 0x8086, PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_BRIDGE, 0x0000, 0x0000,
70+
quirk_clx_disable },
6471
/*
6572
* Intel Goshen Ridge NVM 27 and before report wrong number of
6673
* DP buffers.

drivers/thunderbolt/switch.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ static int nvm_write(void *priv, unsigned int offset, void *val, size_t bytes)
347347
return ret;
348348
}
349349

350-
static int tb_switch_nvm_add(struct tb_switch *sw)
350+
static int tb_switch_nvm_init(struct tb_switch *sw)
351351
{
352352
struct tb_nvm *nvm;
353353
int ret;
@@ -365,6 +365,26 @@ static int tb_switch_nvm_add(struct tb_switch *sw)
365365
if (ret)
366366
goto err_nvm;
367367

368+
sw->nvm = nvm;
369+
return 0;
370+
371+
err_nvm:
372+
tb_sw_dbg(sw, "NVM upgrade disabled\n");
373+
sw->no_nvm_upgrade = true;
374+
if (!IS_ERR(nvm))
375+
tb_nvm_free(nvm);
376+
377+
return ret;
378+
}
379+
380+
static int tb_switch_nvm_add(struct tb_switch *sw)
381+
{
382+
struct tb_nvm *nvm = sw->nvm;
383+
int ret;
384+
385+
if (!nvm)
386+
return 0;
387+
368388
/*
369389
* If the switch is in safe-mode the only accessible portion of
370390
* the NVM is the non-active one where userspace is expected to
@@ -383,14 +403,12 @@ static int tb_switch_nvm_add(struct tb_switch *sw)
383403
goto err_nvm;
384404
}
385405

386-
sw->nvm = nvm;
387406
return 0;
388407

389408
err_nvm:
390409
tb_sw_dbg(sw, "NVM upgrade disabled\n");
391410
sw->no_nvm_upgrade = true;
392-
if (!IS_ERR(nvm))
393-
tb_nvm_free(nvm);
411+
tb_nvm_free(nvm);
394412

395413
return ret;
396414
}
@@ -3311,6 +3329,10 @@ int tb_switch_add(struct tb_switch *sw)
33113329
return ret;
33123330
}
33133331

3332+
ret = tb_switch_nvm_init(sw);
3333+
if (ret)
3334+
return ret;
3335+
33143336
if (!sw->safe_mode) {
33153337
tb_switch_credits_init(sw);
33163338

drivers/thunderbolt/tb.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,9 @@ enum tb_path_port {
419419
* @activated: Is the path active
420420
* @clear_fc: Clear all flow control from the path config space entries
421421
* when deactivating this path
422-
* @hops: Path hops
423422
* @path_length: How many hops the path uses
424423
* @alloc_hopid: Does this path consume port HopID
424+
* @hops: Path hops
425425
*
426426
* A path consists of a number of hops (see &struct tb_path_hop). To
427427
* establish a PCIe tunnel two paths have to be created between the two
@@ -440,9 +440,10 @@ struct tb_path {
440440
bool drop_packages;
441441
bool activated;
442442
bool clear_fc;
443-
struct tb_path_hop *hops;
444443
int path_length;
445444
bool alloc_hopid;
445+
446+
struct tb_path_hop hops[] __counted_by(path_length);
446447
};
447448

448449
/* HopIDs 0-7 are reserved by the Thunderbolt protocol */

drivers/thunderbolt/tunnel.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,14 @@ static struct tb_tunnel *tb_tunnel_alloc(struct tb *tb, size_t npaths,
180180
{
181181
struct tb_tunnel *tunnel;
182182

183-
tunnel = kzalloc_obj(*tunnel);
183+
tunnel = kzalloc_flex(*tunnel, paths, npaths);
184184
if (!tunnel)
185185
return NULL;
186186

187-
tunnel->paths = kzalloc_objs(tunnel->paths[0], npaths);
188-
if (!tunnel->paths) {
189-
kfree(tunnel);
190-
return NULL;
191-
}
187+
tunnel->npaths = npaths;
192188

193189
INIT_LIST_HEAD(&tunnel->list);
194190
tunnel->tb = tb;
195-
tunnel->npaths = npaths;
196191
tunnel->type = type;
197192
kref_init(&tunnel->kref);
198193

@@ -219,7 +214,6 @@ static void tb_tunnel_destroy(struct kref *kref)
219214
tb_path_free(tunnel->paths[i]);
220215
}
221216

222-
kfree(tunnel->paths);
223217
kfree(tunnel);
224218
}
225219

drivers/thunderbolt/tunnel.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ enum tb_tunnel_state {
3737
* @src_port: Source port of the tunnel
3838
* @dst_port: Destination port of the tunnel. For discovered incomplete
3939
* tunnels may be %NULL or null adapter port instead.
40-
* @paths: All paths required by the tunnel
4140
* @npaths: Number of paths in @paths
4241
* @pre_activate: Optional tunnel specific initialization called before
4342
* activation. Can touch hardware.
@@ -69,13 +68,13 @@ enum tb_tunnel_state {
6968
* @dprx_work: Worker that is scheduled to poll completion of DPRX capabilities read
7069
* @callback: Optional callback called when DP tunnel is fully activated
7170
* @callback_data: Optional data for @callback
71+
* @paths: All paths required by the tunnel
7272
*/
7373
struct tb_tunnel {
7474
struct kref kref;
7575
struct tb *tb;
7676
struct tb_port *src_port;
7777
struct tb_port *dst_port;
78-
struct tb_path **paths;
7978
size_t npaths;
8079
int (*pre_activate)(struct tb_tunnel *tunnel);
8180
int (*activate)(struct tb_tunnel *tunnel, bool activate);
@@ -107,6 +106,8 @@ struct tb_tunnel {
107106
struct delayed_work dprx_work;
108107
void (*callback)(struct tb_tunnel *tunnel, void *data);
109108
void *callback_data;
109+
110+
struct tb_path *paths[] __counted_by(npaths);
110111
};
111112

112113
struct tb_tunnel *tb_tunnel_discover_pci(struct tb *tb, struct tb_port *down,

0 commit comments

Comments
 (0)