Skip to content

Commit e8817de

Browse files
gustavoSNPSLorenzo Pieralisi
authored andcommitted
pci-epf-test/pci_endpoint_test: Cleanup PCI_ENDPOINT_TEST memspace
Cleanup PCI_ENDPOINT_TEST memspace (by moving the interrupt number away from command section). Add IRQ_TYPE register to identify the triggered ID interrupt required for the READ/WRITE/COPY tests and raise IRQ test commands. Update documentation accordingly. Signed-off-by: Gustavo Pimentel <[email protected]> Signed-off-by: Lorenzo Pieralisi <[email protected]> Acked-by: Kishon Vijay Abraham I <[email protected]>
1 parent cb22d40 commit e8817de

File tree

3 files changed

+114
-55
lines changed

3 files changed

+114
-55
lines changed

Documentation/PCI/endpoint/pci-test-function.txt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ The PCI endpoint test device has the following registers:
2020
5) PCI_ENDPOINT_TEST_DST_ADDR
2121
6) PCI_ENDPOINT_TEST_SIZE
2222
7) PCI_ENDPOINT_TEST_CHECKSUM
23+
8) PCI_ENDPOINT_TEST_IRQ_TYPE
24+
9) PCI_ENDPOINT_TEST_IRQ_NUMBER
2325

2426
*) PCI_ENDPOINT_TEST_MAGIC
2527

@@ -34,10 +36,10 @@ that the endpoint device must perform.
3436
Bitfield Description:
3537
Bit 0 : raise legacy IRQ
3638
Bit 1 : raise MSI IRQ
37-
Bit 2 - 7 : MSI interrupt number
38-
Bit 8 : read command (read data from RC buffer)
39-
Bit 9 : write command (write data to RC buffer)
40-
Bit 10 : copy command (copy data from one RC buffer to another
39+
Bit 2 : raise MSI-X IRQ (reserved for future implementation)
40+
Bit 3 : read command (read data from RC buffer)
41+
Bit 4 : write command (write data to RC buffer)
42+
Bit 5 : copy command (copy data from one RC buffer to another
4143
RC buffer)
4244

4345
*) PCI_ENDPOINT_TEST_STATUS
@@ -64,3 +66,20 @@ COPY/READ command.
6466

6567
This register contains the destination address (RC buffer address) for
6668
the COPY/WRITE command.
69+
70+
*) PCI_ENDPOINT_TEST_IRQ_TYPE
71+
72+
This register contains the interrupt type (Legacy/MSI) triggered
73+
for the READ/WRITE/COPY and raise IRQ (Legacy/MSI) commands.
74+
75+
Possible types:
76+
- Legacy : 0
77+
- MSI : 1
78+
79+
*) PCI_ENDPOINT_TEST_IRQ_NUMBER
80+
81+
This register contains the triggered ID interrupt.
82+
83+
Admissible values:
84+
- Legacy : 0
85+
- MSI : [1 .. 32]

drivers/misc/pci_endpoint_test.c

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,38 +35,43 @@
3535

3636
#include <uapi/linux/pcitest.h>
3737

38-
#define DRV_MODULE_NAME "pci-endpoint-test"
39-
40-
#define PCI_ENDPOINT_TEST_MAGIC 0x0
41-
42-
#define PCI_ENDPOINT_TEST_COMMAND 0x4
43-
#define COMMAND_RAISE_LEGACY_IRQ BIT(0)
44-
#define COMMAND_RAISE_MSI_IRQ BIT(1)
45-
#define MSI_NUMBER_SHIFT 2
46-
/* 6 bits for MSI number */
47-
#define COMMAND_READ BIT(8)
48-
#define COMMAND_WRITE BIT(9)
49-
#define COMMAND_COPY BIT(10)
50-
51-
#define PCI_ENDPOINT_TEST_STATUS 0x8
52-
#define STATUS_READ_SUCCESS BIT(0)
53-
#define STATUS_READ_FAIL BIT(1)
54-
#define STATUS_WRITE_SUCCESS BIT(2)
55-
#define STATUS_WRITE_FAIL BIT(3)
56-
#define STATUS_COPY_SUCCESS BIT(4)
57-
#define STATUS_COPY_FAIL BIT(5)
58-
#define STATUS_IRQ_RAISED BIT(6)
59-
#define STATUS_SRC_ADDR_INVALID BIT(7)
60-
#define STATUS_DST_ADDR_INVALID BIT(8)
61-
62-
#define PCI_ENDPOINT_TEST_LOWER_SRC_ADDR 0xc
38+
#define DRV_MODULE_NAME "pci-endpoint-test"
39+
40+
#define IRQ_TYPE_LEGACY 0
41+
#define IRQ_TYPE_MSI 1
42+
43+
#define PCI_ENDPOINT_TEST_MAGIC 0x0
44+
45+
#define PCI_ENDPOINT_TEST_COMMAND 0x4
46+
#define COMMAND_RAISE_LEGACY_IRQ BIT(0)
47+
#define COMMAND_RAISE_MSI_IRQ BIT(1)
48+
/* BIT(2) is reserved for raising MSI-X IRQ command */
49+
#define COMMAND_READ BIT(3)
50+
#define COMMAND_WRITE BIT(4)
51+
#define COMMAND_COPY BIT(5)
52+
53+
#define PCI_ENDPOINT_TEST_STATUS 0x8
54+
#define STATUS_READ_SUCCESS BIT(0)
55+
#define STATUS_READ_FAIL BIT(1)
56+
#define STATUS_WRITE_SUCCESS BIT(2)
57+
#define STATUS_WRITE_FAIL BIT(3)
58+
#define STATUS_COPY_SUCCESS BIT(4)
59+
#define STATUS_COPY_FAIL BIT(5)
60+
#define STATUS_IRQ_RAISED BIT(6)
61+
#define STATUS_SRC_ADDR_INVALID BIT(7)
62+
#define STATUS_DST_ADDR_INVALID BIT(8)
63+
64+
#define PCI_ENDPOINT_TEST_LOWER_SRC_ADDR 0x0c
6365
#define PCI_ENDPOINT_TEST_UPPER_SRC_ADDR 0x10
6466

6567
#define PCI_ENDPOINT_TEST_LOWER_DST_ADDR 0x14
6668
#define PCI_ENDPOINT_TEST_UPPER_DST_ADDR 0x18
6769

68-
#define PCI_ENDPOINT_TEST_SIZE 0x1c
69-
#define PCI_ENDPOINT_TEST_CHECKSUM 0x20
70+
#define PCI_ENDPOINT_TEST_SIZE 0x1c
71+
#define PCI_ENDPOINT_TEST_CHECKSUM 0x20
72+
73+
#define PCI_ENDPOINT_TEST_IRQ_TYPE 0x24
74+
#define PCI_ENDPOINT_TEST_IRQ_NUMBER 0x28
7075

7176
static DEFINE_IDA(pci_endpoint_test_ida);
7277

@@ -179,6 +184,9 @@ static bool pci_endpoint_test_legacy_irq(struct pci_endpoint_test *test)
179184
{
180185
u32 val;
181186

187+
pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE,
188+
IRQ_TYPE_LEGACY);
189+
pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 0);
182190
pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND,
183191
COMMAND_RAISE_LEGACY_IRQ);
184192
val = wait_for_completion_timeout(&test->irq_raised,
@@ -195,8 +203,10 @@ static bool pci_endpoint_test_msi_irq(struct pci_endpoint_test *test,
195203
u32 val;
196204
struct pci_dev *pdev = test->pdev;
197205

206+
pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE,
207+
IRQ_TYPE_MSI);
208+
pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, msi_num);
198209
pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND,
199-
msi_num << MSI_NUMBER_SHIFT |
200210
COMMAND_RAISE_MSI_IRQ);
201211
val = wait_for_completion_timeout(&test->irq_raised,
202212
msecs_to_jiffies(1000));
@@ -281,8 +291,11 @@ static bool pci_endpoint_test_copy(struct pci_endpoint_test *test, size_t size)
281291
pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_SIZE,
282292
size);
283293

294+
pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE,
295+
no_msi ? IRQ_TYPE_LEGACY : IRQ_TYPE_MSI);
296+
pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1);
284297
pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND,
285-
1 << MSI_NUMBER_SHIFT | COMMAND_COPY);
298+
COMMAND_COPY);
286299

287300
wait_for_completion(&test->irq_raised);
288301

@@ -348,8 +361,11 @@ static bool pci_endpoint_test_write(struct pci_endpoint_test *test, size_t size)
348361

349362
pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_SIZE, size);
350363

364+
pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE,
365+
no_msi ? IRQ_TYPE_LEGACY : IRQ_TYPE_MSI);
366+
pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1);
351367
pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND,
352-
1 << MSI_NUMBER_SHIFT | COMMAND_READ);
368+
COMMAND_READ);
353369

354370
wait_for_completion(&test->irq_raised);
355371

@@ -403,8 +419,11 @@ static bool pci_endpoint_test_read(struct pci_endpoint_test *test, size_t size)
403419

404420
pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_SIZE, size);
405421

422+
pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE,
423+
no_msi ? IRQ_TYPE_LEGACY : IRQ_TYPE_MSI);
424+
pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1);
406425
pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND,
407-
1 << MSI_NUMBER_SHIFT | COMMAND_WRITE);
426+
COMMAND_WRITE);
408427

409428
wait_for_completion(&test->irq_raised);
410429

drivers/pci/endpoint/functions/pci-epf-test.c

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
#include <linux/pci-epf.h>
1919
#include <linux/pci_regs.h>
2020

21+
#define IRQ_TYPE_LEGACY 0
22+
#define IRQ_TYPE_MSI 1
23+
2124
#define COMMAND_RAISE_LEGACY_IRQ BIT(0)
2225
#define COMMAND_RAISE_MSI_IRQ BIT(1)
23-
#define MSI_NUMBER_SHIFT 2
24-
#define MSI_NUMBER_MASK (0x3f << MSI_NUMBER_SHIFT)
25-
#define COMMAND_READ BIT(8)
26-
#define COMMAND_WRITE BIT(9)
27-
#define COMMAND_COPY BIT(10)
26+
/* BIT(2) is reserved for raising MSI-X IRQ command */
27+
#define COMMAND_READ BIT(3)
28+
#define COMMAND_WRITE BIT(4)
29+
#define COMMAND_COPY BIT(5)
2830

2931
#define STATUS_READ_SUCCESS BIT(0)
3032
#define STATUS_READ_FAIL BIT(1)
@@ -56,6 +58,8 @@ struct pci_epf_test_reg {
5658
u64 dst_addr;
5759
u32 size;
5860
u32 checksum;
61+
u32 irq_type;
62+
u32 irq_number;
5963
} __packed;
6064

6165
static struct pci_epf_header test_header = {
@@ -244,31 +248,39 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test)
244248
return ret;
245249
}
246250

247-
static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, u8 irq)
251+
static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, u8 irq_type,
252+
u16 irq)
248253
{
249-
u8 msi_count;
250254
struct pci_epf *epf = epf_test->epf;
255+
struct device *dev = &epf->dev;
251256
struct pci_epc *epc = epf->epc;
252257
enum pci_barno test_reg_bar = epf_test->test_reg_bar;
253258
struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar];
254259

255260
reg->status |= STATUS_IRQ_RAISED;
256-
msi_count = pci_epc_get_msi(epc, epf->func_no);
257-
if (irq > msi_count || msi_count <= 0)
261+
262+
switch (irq_type) {
263+
case IRQ_TYPE_LEGACY:
258264
pci_epc_raise_irq(epc, epf->func_no, PCI_EPC_IRQ_LEGACY, 0);
259-
else
265+
break;
266+
case IRQ_TYPE_MSI:
260267
pci_epc_raise_irq(epc, epf->func_no, PCI_EPC_IRQ_MSI, irq);
268+
break;
269+
default:
270+
dev_err(dev, "Failed to raise IRQ, unknown type\n");
271+
break;
272+
}
261273
}
262274

263275
static void pci_epf_test_cmd_handler(struct work_struct *work)
264276
{
265277
int ret;
266-
u8 irq;
267-
u8 msi_count;
278+
int count;
268279
u32 command;
269280
struct pci_epf_test *epf_test = container_of(work, struct pci_epf_test,
270281
cmd_handler.work);
271282
struct pci_epf *epf = epf_test->epf;
283+
struct device *dev = &epf->dev;
272284
struct pci_epc *epc = epf->epc;
273285
enum pci_barno test_reg_bar = epf_test->test_reg_bar;
274286
struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar];
@@ -280,7 +292,10 @@ static void pci_epf_test_cmd_handler(struct work_struct *work)
280292
reg->command = 0;
281293
reg->status = 0;
282294

283-
irq = (command & MSI_NUMBER_MASK) >> MSI_NUMBER_SHIFT;
295+
if (reg->irq_type > IRQ_TYPE_MSI) {
296+
dev_err(dev, "Failed to detect IRQ type\n");
297+
goto reset_handler;
298+
}
284299

285300
if (command & COMMAND_RAISE_LEGACY_IRQ) {
286301
reg->status = STATUS_IRQ_RAISED;
@@ -294,7 +309,8 @@ static void pci_epf_test_cmd_handler(struct work_struct *work)
294309
reg->status |= STATUS_WRITE_FAIL;
295310
else
296311
reg->status |= STATUS_WRITE_SUCCESS;
297-
pci_epf_test_raise_irq(epf_test, irq);
312+
pci_epf_test_raise_irq(epf_test, reg->irq_type,
313+
reg->irq_number);
298314
goto reset_handler;
299315
}
300316

@@ -304,7 +320,8 @@ static void pci_epf_test_cmd_handler(struct work_struct *work)
304320
reg->status |= STATUS_READ_SUCCESS;
305321
else
306322
reg->status |= STATUS_READ_FAIL;
307-
pci_epf_test_raise_irq(epf_test, irq);
323+
pci_epf_test_raise_irq(epf_test, reg->irq_type,
324+
reg->irq_number);
308325
goto reset_handler;
309326
}
310327

@@ -314,16 +331,18 @@ static void pci_epf_test_cmd_handler(struct work_struct *work)
314331
reg->status |= STATUS_COPY_SUCCESS;
315332
else
316333
reg->status |= STATUS_COPY_FAIL;
317-
pci_epf_test_raise_irq(epf_test, irq);
334+
pci_epf_test_raise_irq(epf_test, reg->irq_type,
335+
reg->irq_number);
318336
goto reset_handler;
319337
}
320338

321339
if (command & COMMAND_RAISE_MSI_IRQ) {
322-
msi_count = pci_epc_get_msi(epc, epf->func_no);
323-
if (irq > msi_count || msi_count <= 0)
340+
count = pci_epc_get_msi(epc, epf->func_no);
341+
if (reg->irq_number > count || count <= 0)
324342
goto reset_handler;
325343
reg->status = STATUS_IRQ_RAISED;
326-
pci_epc_raise_irq(epc, epf->func_no, PCI_EPC_IRQ_MSI, irq);
344+
pci_epc_raise_irq(epc, epf->func_no, PCI_EPC_IRQ_MSI,
345+
reg->irq_number);
327346
goto reset_handler;
328347
}
329348

@@ -457,8 +476,10 @@ static int pci_epf_test_bind(struct pci_epf *epf)
457476
return ret;
458477

459478
ret = pci_epc_set_msi(epc, epf->func_no, epf->msi_interrupts);
460-
if (ret)
479+
if (ret) {
480+
dev_err(dev, "MSI configuration failed\n");
461481
return ret;
482+
}
462483

463484
if (!epf_test->linkup_notifier)
464485
queue_work(kpcitest_workqueue, &epf_test->cmd_handler.work);

0 commit comments

Comments
 (0)