blob: 16e544018a68a986ad5b6b63d17822f387fe2890 [file] [log] [blame]
Rob Ricea24532f2016-06-30 15:59:23 -04001/*
2 * Copyright 2016 Broadcom
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2, as
6 * published by the Free Software Foundation (the "GPL").
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License version 2 (GPLv2) for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 2 (GPLv2) along with this source code.
15 */
16
17/*
18 * Broadcom PDC Mailbox Driver
19 * The PDC provides a ring based programming interface to one or more hardware
20 * offload engines. For example, the PDC driver works with both SPU-M and SPU2
21 * cryptographic offload hardware. In some chips the PDC is referred to as MDE.
22 *
23 * The PDC driver registers with the Linux mailbox framework as a mailbox
24 * controller, once for each PDC instance. Ring 0 for each PDC is registered as
25 * a mailbox channel. The PDC driver uses interrupts to determine when data
26 * transfers to and from an offload engine are complete. The PDC driver uses
27 * threaded IRQs so that response messages are handled outside of interrupt
28 * context.
29 *
30 * The PDC driver allows multiple messages to be pending in the descriptor
31 * rings. The tx_msg_start descriptor index indicates where the last message
32 * starts. The txin_numd value at this index indicates how many descriptor
33 * indexes make up the message. Similar state is kept on the receive side. When
34 * an rx interrupt indicates a response is ready, the PDC driver processes numd
35 * descriptors from the tx and rx ring, thus processing one response at a time.
36 */
37
38#include <linux/errno.h>
39#include <linux/module.h>
40#include <linux/init.h>
41#include <linux/slab.h>
42#include <linux/debugfs.h>
43#include <linux/interrupt.h>
44#include <linux/wait.h>
45#include <linux/platform_device.h>
46#include <linux/io.h>
47#include <linux/of.h>
48#include <linux/of_device.h>
49#include <linux/of_address.h>
50#include <linux/of_irq.h>
51#include <linux/mailbox_controller.h>
52#include <linux/mailbox/brcm-message.h>
53#include <linux/scatterlist.h>
54#include <linux/dma-direction.h>
55#include <linux/dma-mapping.h>
56#include <linux/dmapool.h>
57
58#define PDC_SUCCESS 0
59
60#define RING_ENTRY_SIZE sizeof(struct dma64dd)
61
62/* # entries in PDC dma ring */
Rob Riceab8d1b22016-11-14 13:25:58 -050063#define PDC_RING_ENTRIES 512
64/*
65 * Minimum number of ring descriptor entries that must be free to tell mailbox
66 * framework that it can submit another request
67 */
68#define PDC_RING_SPACE_MIN 15
69
Rob Ricea24532f2016-06-30 15:59:23 -040070#define PDC_RING_SIZE (PDC_RING_ENTRIES * RING_ENTRY_SIZE)
71/* Rings are 8k aligned */
72#define RING_ALIGN_ORDER 13
73#define RING_ALIGN BIT(RING_ALIGN_ORDER)
74
75#define RX_BUF_ALIGN_ORDER 5
76#define RX_BUF_ALIGN BIT(RX_BUF_ALIGN_ORDER)
77
78/* descriptor bumping macros */
79#define XXD(x, max_mask) ((x) & (max_mask))
80#define TXD(x, max_mask) XXD((x), (max_mask))
81#define RXD(x, max_mask) XXD((x), (max_mask))
82#define NEXTTXD(i, max_mask) TXD((i) + 1, (max_mask))
83#define PREVTXD(i, max_mask) TXD((i) - 1, (max_mask))
84#define NEXTRXD(i, max_mask) RXD((i) + 1, (max_mask))
85#define PREVRXD(i, max_mask) RXD((i) - 1, (max_mask))
86#define NTXDACTIVE(h, t, max_mask) TXD((t) - (h), (max_mask))
87#define NRXDACTIVE(h, t, max_mask) RXD((t) - (h), (max_mask))
88
89/* Length of BCM header at start of SPU msg, in bytes */
90#define BCM_HDR_LEN 8
91
92/*
93 * PDC driver reserves ringset 0 on each SPU for its own use. The driver does
94 * not currently support use of multiple ringsets on a single PDC engine.
95 */
96#define PDC_RINGSET 0
97
98/*
99 * Interrupt mask and status definitions. Enable interrupts for tx and rx on
100 * ring 0
101 */
Rob Ricea24532f2016-06-30 15:59:23 -0400102#define PDC_RCVINT_0 (16 + PDC_RINGSET)
Rob Ricea24532f2016-06-30 15:59:23 -0400103#define PDC_RCVINTEN_0 BIT(PDC_RCVINT_0)
Rob Riceab8d1b22016-11-14 13:25:58 -0500104#define PDC_INTMASK (PDC_RCVINTEN_0)
Rob Ricea24532f2016-06-30 15:59:23 -0400105#define PDC_LAZY_FRAMECOUNT 1
106#define PDC_LAZY_TIMEOUT 10000
107#define PDC_LAZY_INT (PDC_LAZY_TIMEOUT | (PDC_LAZY_FRAMECOUNT << 24))
108#define PDC_INTMASK_OFFSET 0x24
109#define PDC_INTSTATUS_OFFSET 0x20
110#define PDC_RCVLAZY0_OFFSET (0x30 + 4 * PDC_RINGSET)
111
112/*
113 * For SPU2, configure MDE_CKSUM_CONTROL to write 17 bytes of metadata
114 * before frame
115 */
116#define PDC_SPU2_RESP_HDR_LEN 17
117#define PDC_CKSUM_CTRL BIT(27)
118#define PDC_CKSUM_CTRL_OFFSET 0x400
119
120#define PDC_SPUM_RESP_HDR_LEN 32
121
122/*
123 * Sets the following bits for write to transmit control reg:
Rob Ricea24532f2016-06-30 15:59:23 -0400124 * 11 - PtyChkDisable - parity check is disabled
125 * 20:18 - BurstLen = 3 -> 2^7 = 128 byte data reads from memory
126 */
Steve Lin9fb0f9a2016-11-14 13:25:56 -0500127#define PDC_TX_CTL 0x000C0800
128
129/* Bit in tx control reg to enable tx channel */
130#define PDC_TX_ENABLE 0x1
Rob Ricea24532f2016-06-30 15:59:23 -0400131
132/*
133 * Sets the following bits for write to receive control reg:
Rob Ricea24532f2016-06-30 15:59:23 -0400134 * 7:1 - RcvOffset - size in bytes of status region at start of rx frame buf
135 * 9 - SepRxHdrDescEn - place start of new frames only in descriptors
136 * that have StartOfFrame set
137 * 10 - OflowContinue - on rx FIFO overflow, clear rx fifo, discard all
138 * remaining bytes in current frame, report error
139 * in rx frame status for current frame
140 * 11 - PtyChkDisable - parity check is disabled
141 * 20:18 - BurstLen = 3 -> 2^7 = 128 byte data reads from memory
142 */
Steve Lin9fb0f9a2016-11-14 13:25:56 -0500143#define PDC_RX_CTL 0x000C0E00
144
145/* Bit in rx control reg to enable rx channel */
146#define PDC_RX_ENABLE 0x1
Rob Ricea24532f2016-06-30 15:59:23 -0400147
148#define CRYPTO_D64_RS0_CD_MASK ((PDC_RING_ENTRIES * RING_ENTRY_SIZE) - 1)
149
150/* descriptor flags */
151#define D64_CTRL1_EOT BIT(28) /* end of descriptor table */
152#define D64_CTRL1_IOC BIT(29) /* interrupt on complete */
153#define D64_CTRL1_EOF BIT(30) /* end of frame */
154#define D64_CTRL1_SOF BIT(31) /* start of frame */
155
156#define RX_STATUS_OVERFLOW 0x00800000
157#define RX_STATUS_LEN 0x0000FFFF
158
159#define PDC_TXREGS_OFFSET 0x200
160#define PDC_RXREGS_OFFSET 0x220
161
162/* Maximum size buffer the DMA engine can handle */
163#define PDC_DMA_BUF_MAX 16384
164
165struct pdc_dma_map {
166 void *ctx; /* opaque context associated with frame */
167};
168
169/* dma descriptor */
170struct dma64dd {
171 u32 ctrl1; /* misc control bits */
172 u32 ctrl2; /* buffer count and address extension */
173 u32 addrlow; /* memory address of the date buffer, bits 31:0 */
174 u32 addrhigh; /* memory address of the date buffer, bits 63:32 */
175};
176
177/* dma registers per channel(xmt or rcv) */
178struct dma64_regs {
179 u32 control; /* enable, et al */
180 u32 ptr; /* last descriptor posted to chip */
181 u32 addrlow; /* descriptor ring base address low 32-bits */
182 u32 addrhigh; /* descriptor ring base address bits 63:32 */
183 u32 status0; /* last rx descriptor written by hw */
184 u32 status1; /* driver does not use */
185};
186
187/* cpp contortions to concatenate w/arg prescan */
188#ifndef PAD
189#define _PADLINE(line) pad ## line
190#define _XSTR(line) _PADLINE(line)
191#define PAD _XSTR(__LINE__)
192#endif /* PAD */
193
194/* dma registers. matches hw layout. */
195struct dma64 {
196 struct dma64_regs dmaxmt; /* dma tx */
197 u32 PAD[2];
198 struct dma64_regs dmarcv; /* dma rx */
199 u32 PAD[2];
200};
201
202/* PDC registers */
203struct pdc_regs {
204 u32 devcontrol; /* 0x000 */
205 u32 devstatus; /* 0x004 */
206 u32 PAD;
207 u32 biststatus; /* 0x00c */
208 u32 PAD[4];
209 u32 intstatus; /* 0x020 */
210 u32 intmask; /* 0x024 */
211 u32 gptimer; /* 0x028 */
212
213 u32 PAD;
214 u32 intrcvlazy_0; /* 0x030 */
215 u32 intrcvlazy_1; /* 0x034 */
216 u32 intrcvlazy_2; /* 0x038 */
217 u32 intrcvlazy_3; /* 0x03c */
218
219 u32 PAD[48];
220 u32 removed_intrecvlazy; /* 0x100 */
221 u32 flowctlthresh; /* 0x104 */
222 u32 wrrthresh; /* 0x108 */
223 u32 gmac_idle_cnt_thresh; /* 0x10c */
224
225 u32 PAD[4];
226 u32 ifioaccessaddr; /* 0x120 */
227 u32 ifioaccessbyte; /* 0x124 */
228 u32 ifioaccessdata; /* 0x128 */
229
230 u32 PAD[21];
231 u32 phyaccess; /* 0x180 */
232 u32 PAD;
233 u32 phycontrol; /* 0x188 */
234 u32 txqctl; /* 0x18c */
235 u32 rxqctl; /* 0x190 */
236 u32 gpioselect; /* 0x194 */
237 u32 gpio_output_en; /* 0x198 */
238 u32 PAD; /* 0x19c */
239 u32 txq_rxq_mem_ctl; /* 0x1a0 */
240 u32 memory_ecc_status; /* 0x1a4 */
241 u32 serdes_ctl; /* 0x1a8 */
242 u32 serdes_status0; /* 0x1ac */
243 u32 serdes_status1; /* 0x1b0 */
244 u32 PAD[11]; /* 0x1b4-1dc */
245 u32 clk_ctl_st; /* 0x1e0 */
246 u32 hw_war; /* 0x1e4 */
247 u32 pwrctl; /* 0x1e8 */
248 u32 PAD[5];
249
250#define PDC_NUM_DMA_RINGS 4
251 struct dma64 dmaregs[PDC_NUM_DMA_RINGS]; /* 0x0200 - 0x2fc */
252
253 /* more registers follow, but we don't use them */
254};
255
256/* structure for allocating/freeing DMA rings */
257struct pdc_ring_alloc {
258 dma_addr_t dmabase; /* DMA address of start of ring */
259 void *vbase; /* base kernel virtual address of ring */
260 u32 size; /* ring allocation size in bytes */
261};
262
263/* PDC state structure */
264struct pdc_state {
Rob Ricea24532f2016-06-30 15:59:23 -0400265 /* Index of the PDC whose state is in this structure instance */
266 u8 pdc_idx;
267
268 /* Platform device for this PDC instance */
269 struct platform_device *pdev;
270
271 /*
272 * Each PDC instance has a mailbox controller. PDC receives request
273 * messages through mailboxes, and sends response messages through the
274 * mailbox framework.
275 */
276 struct mbox_controller mbc;
277
278 unsigned int pdc_irq;
279
280 /*
281 * Last interrupt status read from PDC device. Saved in interrupt
282 * handler so the handler can clear the interrupt in the device,
283 * and the interrupt thread called later can know which interrupt
284 * bits are active.
285 */
286 unsigned long intstatus;
287
Rob Rice8aef00f2016-11-14 13:26:01 -0500288 /* tasklet for deferred processing after DMA rx interrupt */
289 struct tasklet_struct rx_tasklet;
290
Rob Ricea24532f2016-06-30 15:59:23 -0400291 /* Number of bytes of receive status prior to each rx frame */
292 u32 rx_status_len;
293 /* Whether a BCM header is prepended to each frame */
294 bool use_bcm_hdr;
295 /* Sum of length of BCM header and rx status header */
296 u32 pdc_resp_hdr_len;
297
298 /* The base virtual address of DMA hw registers */
299 void __iomem *pdc_reg_vbase;
300
301 /* Pool for allocation of DMA rings */
302 struct dma_pool *ring_pool;
303
304 /* Pool for allocation of metadata buffers for response messages */
305 struct dma_pool *rx_buf_pool;
306
307 /*
308 * The base virtual address of DMA tx/rx descriptor rings. Corresponding
309 * DMA address and size of ring allocation.
310 */
311 struct pdc_ring_alloc tx_ring_alloc;
312 struct pdc_ring_alloc rx_ring_alloc;
313
314 struct pdc_regs *regs; /* start of PDC registers */
315
316 struct dma64_regs *txregs_64; /* dma tx engine registers */
317 struct dma64_regs *rxregs_64; /* dma rx engine registers */
318
319 /*
320 * Arrays of PDC_RING_ENTRIES descriptors
321 * To use multiple ringsets, this needs to be extended
322 */
323 struct dma64dd *txd_64; /* tx descriptor ring */
324 struct dma64dd *rxd_64; /* rx descriptor ring */
325
326 /* descriptor ring sizes */
327 u32 ntxd; /* # tx descriptors */
328 u32 nrxd; /* # rx descriptors */
329 u32 nrxpost; /* # rx buffers to keep posted */
330 u32 ntxpost; /* max number of tx buffers that can be posted */
331
332 /*
333 * Index of next tx descriptor to reclaim. That is, the descriptor
334 * index of the oldest tx buffer for which the host has yet to process
335 * the corresponding response.
336 */
337 u32 txin;
338
339 /*
340 * Index of the first receive descriptor for the sequence of
341 * message fragments currently under construction. Used to build up
342 * the rxin_numd count for a message. Updated to rxout when the host
343 * starts a new sequence of rx buffers for a new message.
344 */
345 u32 tx_msg_start;
346
347 /* Index of next tx descriptor to post. */
348 u32 txout;
349
350 /*
351 * Number of tx descriptors associated with the message that starts
352 * at this tx descriptor index.
353 */
354 u32 txin_numd[PDC_RING_ENTRIES];
355
356 /*
357 * Index of next rx descriptor to reclaim. This is the index of
358 * the next descriptor whose data has yet to be processed by the host.
359 */
360 u32 rxin;
361
362 /*
363 * Index of the first receive descriptor for the sequence of
364 * message fragments currently under construction. Used to build up
365 * the rxin_numd count for a message. Updated to rxout when the host
366 * starts a new sequence of rx buffers for a new message.
367 */
368 u32 rx_msg_start;
369
370 /*
371 * Saved value of current hardware rx descriptor index.
372 * The last rx buffer written by the hw is the index previous to
373 * this one.
374 */
375 u32 last_rx_curr;
376
377 /* Index of next rx descriptor to post. */
378 u32 rxout;
379
380 /*
381 * opaque context associated with frame that starts at each
382 * rx ring index.
383 */
384 void *rxp_ctx[PDC_RING_ENTRIES];
385
386 /*
387 * Scatterlists used to form request and reply frames beginning at a
388 * given ring index. Retained in order to unmap each sg after reply
389 * is processed
390 */
391 struct scatterlist *src_sg[PDC_RING_ENTRIES];
392 struct scatterlist *dst_sg[PDC_RING_ENTRIES];
393
394 /*
395 * Number of rx descriptors associated with the message that starts
396 * at this descriptor index. Not set for every index. For example,
397 * if descriptor index i points to a scatterlist with 4 entries, then
398 * the next three descriptor indexes don't have a value set.
399 */
400 u32 rxin_numd[PDC_RING_ENTRIES];
401
402 void *resp_hdr[PDC_RING_ENTRIES];
403 dma_addr_t resp_hdr_daddr[PDC_RING_ENTRIES];
404
405 struct dentry *debugfs_stats; /* debug FS stats file for this PDC */
406
407 /* counters */
Rob Riceab8d1b22016-11-14 13:25:58 -0500408 u32 pdc_requests; /* number of request messages submitted */
409 u32 pdc_replies; /* number of reply messages received */
410 u32 last_tx_not_done; /* too few tx descriptors to indicate done */
411 u32 tx_ring_full; /* unable to accept msg because tx ring full */
412 u32 rx_ring_full; /* unable to accept msg because rx ring full */
413 u32 txnobuf; /* unable to create tx descriptor */
414 u32 rxnobuf; /* unable to create rx descriptor */
415 u32 rx_oflow; /* count of rx overflows */
Rob Ricea24532f2016-06-30 15:59:23 -0400416};
417
418/* Global variables */
419
420struct pdc_globals {
421 /* Actual number of SPUs in hardware, as reported by device tree */
422 u32 num_spu;
423};
424
425static struct pdc_globals pdcg;
426
427/* top level debug FS directory for PDC driver */
428static struct dentry *debugfs_dir;
429
430static ssize_t pdc_debugfs_read(struct file *filp, char __user *ubuf,
431 size_t count, loff_t *offp)
432{
433 struct pdc_state *pdcs;
434 char *buf;
435 ssize_t ret, out_offset, out_count;
436
437 out_count = 512;
438
439 buf = kmalloc(out_count, GFP_KERNEL);
440 if (!buf)
441 return -ENOMEM;
442
443 pdcs = filp->private_data;
444 out_offset = 0;
445 out_offset += snprintf(buf + out_offset, out_count - out_offset,
446 "SPU %u stats:\n", pdcs->pdc_idx);
447 out_offset += snprintf(buf + out_offset, out_count - out_offset,
Rob Riceab8d1b22016-11-14 13:25:58 -0500448 "PDC requests....................%u\n",
Rob Ricea24532f2016-06-30 15:59:23 -0400449 pdcs->pdc_requests);
450 out_offset += snprintf(buf + out_offset, out_count - out_offset,
Rob Riceab8d1b22016-11-14 13:25:58 -0500451 "PDC responses...................%u\n",
Rob Ricea24532f2016-06-30 15:59:23 -0400452 pdcs->pdc_replies);
453 out_offset += snprintf(buf + out_offset, out_count - out_offset,
Rob Riceab8d1b22016-11-14 13:25:58 -0500454 "Tx not done.....................%u\n",
455 pdcs->last_tx_not_done);
456 out_offset += snprintf(buf + out_offset, out_count - out_offset,
457 "Tx ring full....................%u\n",
458 pdcs->tx_ring_full);
459 out_offset += snprintf(buf + out_offset, out_count - out_offset,
460 "Rx ring full....................%u\n",
461 pdcs->rx_ring_full);
462 out_offset += snprintf(buf + out_offset, out_count - out_offset,
463 "Tx desc write fail. Ring full...%u\n",
Rob Ricea24532f2016-06-30 15:59:23 -0400464 pdcs->txnobuf);
465 out_offset += snprintf(buf + out_offset, out_count - out_offset,
Rob Riceab8d1b22016-11-14 13:25:58 -0500466 "Rx desc write fail. Ring full...%u\n",
Rob Ricea24532f2016-06-30 15:59:23 -0400467 pdcs->rxnobuf);
468 out_offset += snprintf(buf + out_offset, out_count - out_offset,
Rob Riceab8d1b22016-11-14 13:25:58 -0500469 "Receive overflow................%u\n",
Rob Ricea24532f2016-06-30 15:59:23 -0400470 pdcs->rx_oflow);
Rob Riceab8d1b22016-11-14 13:25:58 -0500471 out_offset += snprintf(buf + out_offset, out_count - out_offset,
472 "Num frags in rx ring............%u\n",
473 NRXDACTIVE(pdcs->rxin, pdcs->last_rx_curr,
474 pdcs->nrxpost));
Rob Ricea24532f2016-06-30 15:59:23 -0400475
476 if (out_offset > out_count)
477 out_offset = out_count;
478
479 ret = simple_read_from_buffer(ubuf, count, offp, buf, out_offset);
480 kfree(buf);
481 return ret;
482}
483
484static const struct file_operations pdc_debugfs_stats = {
485 .owner = THIS_MODULE,
486 .open = simple_open,
487 .read = pdc_debugfs_read,
488};
489
490/**
491 * pdc_setup_debugfs() - Create the debug FS directories. If the top-level
492 * directory has not yet been created, create it now. Create a stats file in
493 * this directory for a SPU.
494 * @pdcs: PDC state structure
495 */
Baoyou Xiea75e4a82016-08-28 01:15:24 +0800496static void pdc_setup_debugfs(struct pdc_state *pdcs)
Rob Ricea24532f2016-06-30 15:59:23 -0400497{
498 char spu_stats_name[16];
499
500 if (!debugfs_initialized())
501 return;
502
503 snprintf(spu_stats_name, 16, "pdc%d_stats", pdcs->pdc_idx);
504 if (!debugfs_dir)
505 debugfs_dir = debugfs_create_dir(KBUILD_MODNAME, NULL);
506
Rob Rice9b1b2b32016-11-14 13:25:55 -0500507 /* S_IRUSR == 0400 */
508 pdcs->debugfs_stats = debugfs_create_file(spu_stats_name, 0400,
Rob Ricea24532f2016-06-30 15:59:23 -0400509 debugfs_dir, pdcs,
510 &pdc_debugfs_stats);
511}
512
Baoyou Xiea75e4a82016-08-28 01:15:24 +0800513static void pdc_free_debugfs(void)
Rob Ricea24532f2016-06-30 15:59:23 -0400514{
Steve Lin9310f1d2016-11-14 13:25:57 -0500515 debugfs_remove_recursive(debugfs_dir);
516 debugfs_dir = NULL;
Rob Ricea24532f2016-06-30 15:59:23 -0400517}
518
519/**
520 * pdc_build_rxd() - Build DMA descriptor to receive SPU result.
521 * @pdcs: PDC state for SPU that will generate result
522 * @dma_addr: DMA address of buffer that descriptor is being built for
523 * @buf_len: Length of the receive buffer, in bytes
524 * @flags: Flags to be stored in descriptor
525 */
526static inline void
527pdc_build_rxd(struct pdc_state *pdcs, dma_addr_t dma_addr,
528 u32 buf_len, u32 flags)
529{
530 struct device *dev = &pdcs->pdev->dev;
531
532 dev_dbg(dev,
533 "Writing rx descriptor for PDC %u at index %u with length %u. flags %#x\n",
534 pdcs->pdc_idx, pdcs->rxout, buf_len, flags);
535
536 iowrite32(lower_32_bits(dma_addr),
537 (void *)&pdcs->rxd_64[pdcs->rxout].addrlow);
538 iowrite32(upper_32_bits(dma_addr),
539 (void *)&pdcs->rxd_64[pdcs->rxout].addrhigh);
540 iowrite32(flags, (void *)&pdcs->rxd_64[pdcs->rxout].ctrl1);
541 iowrite32(buf_len, (void *)&pdcs->rxd_64[pdcs->rxout].ctrl2);
542 /* bump ring index and return */
543 pdcs->rxout = NEXTRXD(pdcs->rxout, pdcs->nrxpost);
544}
545
546/**
547 * pdc_build_txd() - Build a DMA descriptor to transmit a SPU request to
548 * hardware.
549 * @pdcs: PDC state for the SPU that will process this request
550 * @dma_addr: DMA address of packet to be transmitted
551 * @buf_len: Length of tx buffer, in bytes
552 * @flags: Flags to be stored in descriptor
553 */
554static inline void
555pdc_build_txd(struct pdc_state *pdcs, dma_addr_t dma_addr, u32 buf_len,
556 u32 flags)
557{
558 struct device *dev = &pdcs->pdev->dev;
559
560 dev_dbg(dev,
561 "Writing tx descriptor for PDC %u at index %u with length %u, flags %#x\n",
562 pdcs->pdc_idx, pdcs->txout, buf_len, flags);
563
564 iowrite32(lower_32_bits(dma_addr),
565 (void *)&pdcs->txd_64[pdcs->txout].addrlow);
566 iowrite32(upper_32_bits(dma_addr),
567 (void *)&pdcs->txd_64[pdcs->txout].addrhigh);
568 iowrite32(flags, (void *)&pdcs->txd_64[pdcs->txout].ctrl1);
569 iowrite32(buf_len, (void *)&pdcs->txd_64[pdcs->txout].ctrl2);
570
571 /* bump ring index and return */
572 pdcs->txout = NEXTTXD(pdcs->txout, pdcs->ntxpost);
573}
574
575/**
Rob Ricee004c7e2016-11-14 13:25:59 -0500576 * pdc_receive_one() - Receive a response message from a given SPU.
Rob Ricea24532f2016-06-30 15:59:23 -0400577 * @pdcs: PDC state for the SPU to receive from
Rob Ricea24532f2016-06-30 15:59:23 -0400578 *
579 * When the return code indicates success, the response message is available in
580 * the receive buffers provided prior to submission of the request.
581 *
Rob Ricea24532f2016-06-30 15:59:23 -0400582 * Return: PDC_SUCCESS if one or more receive descriptors was processed
583 * -EAGAIN indicates that no response message is available
584 * -EIO an error occurred
585 */
586static int
Rob Ricee004c7e2016-11-14 13:25:59 -0500587pdc_receive_one(struct pdc_state *pdcs)
Rob Ricea24532f2016-06-30 15:59:23 -0400588{
589 struct device *dev = &pdcs->pdev->dev;
Rob Ricee004c7e2016-11-14 13:25:59 -0500590 struct mbox_controller *mbc;
591 struct mbox_chan *chan;
592 struct brcm_message mssg;
Rob Ricea24532f2016-06-30 15:59:23 -0400593 u32 len, rx_status;
594 u32 num_frags;
595 int i;
596 u8 *resp_hdr; /* virtual addr of start of resp message DMA header */
597 u32 frags_rdy; /* number of fragments ready to read */
598 u32 rx_idx; /* ring index of start of receive frame */
599 dma_addr_t resp_hdr_daddr;
600
Rob Ricee004c7e2016-11-14 13:25:59 -0500601 mbc = &pdcs->mbc;
602 chan = &mbc->chans[0];
603 mssg.type = BRCM_MESSAGE_SPU;
604
Rob Ricea24532f2016-06-30 15:59:23 -0400605 /*
606 * return if a complete response message is not yet ready.
607 * rxin_numd[rxin] is the number of fragments in the next msg
608 * to read.
609 */
610 frags_rdy = NRXDACTIVE(pdcs->rxin, pdcs->last_rx_curr, pdcs->nrxpost);
Rob Ricee004c7e2016-11-14 13:25:59 -0500611 if ((frags_rdy == 0) || (frags_rdy < pdcs->rxin_numd[pdcs->rxin]))
612 /* No response ready */
613 return -EAGAIN;
Rob Ricea24532f2016-06-30 15:59:23 -0400614
615 num_frags = pdcs->txin_numd[pdcs->txin];
Rob Ricee004c7e2016-11-14 13:25:59 -0500616 WARN_ON(num_frags == 0);
617
Rob Ricea24532f2016-06-30 15:59:23 -0400618 dma_unmap_sg(dev, pdcs->src_sg[pdcs->txin],
619 sg_nents(pdcs->src_sg[pdcs->txin]), DMA_TO_DEVICE);
620
621 for (i = 0; i < num_frags; i++)
622 pdcs->txin = NEXTTXD(pdcs->txin, pdcs->ntxpost);
623
624 dev_dbg(dev, "PDC %u reclaimed %d tx descriptors",
625 pdcs->pdc_idx, num_frags);
626
627 rx_idx = pdcs->rxin;
628 num_frags = pdcs->rxin_numd[rx_idx];
629 /* Return opaque context with result */
Rob Ricee004c7e2016-11-14 13:25:59 -0500630 mssg.ctx = pdcs->rxp_ctx[rx_idx];
Rob Ricea24532f2016-06-30 15:59:23 -0400631 pdcs->rxp_ctx[rx_idx] = NULL;
632 resp_hdr = pdcs->resp_hdr[rx_idx];
633 resp_hdr_daddr = pdcs->resp_hdr_daddr[rx_idx];
634 dma_unmap_sg(dev, pdcs->dst_sg[rx_idx],
635 sg_nents(pdcs->dst_sg[rx_idx]), DMA_FROM_DEVICE);
636
637 for (i = 0; i < num_frags; i++)
638 pdcs->rxin = NEXTRXD(pdcs->rxin, pdcs->nrxpost);
639
Rob Ricea24532f2016-06-30 15:59:23 -0400640 dev_dbg(dev, "PDC %u reclaimed %d rx descriptors",
641 pdcs->pdc_idx, num_frags);
642
643 dev_dbg(dev,
644 "PDC %u txin %u, txout %u, rxin %u, rxout %u, last_rx_curr %u\n",
645 pdcs->pdc_idx, pdcs->txin, pdcs->txout, pdcs->rxin,
646 pdcs->rxout, pdcs->last_rx_curr);
647
648 if (pdcs->pdc_resp_hdr_len == PDC_SPUM_RESP_HDR_LEN) {
649 /*
650 * For SPU-M, get length of response msg and rx overflow status.
651 */
652 rx_status = *((u32 *)resp_hdr);
653 len = rx_status & RX_STATUS_LEN;
654 dev_dbg(dev,
655 "SPU response length %u bytes", len);
656 if (unlikely(((rx_status & RX_STATUS_OVERFLOW) || (!len)))) {
657 if (rx_status & RX_STATUS_OVERFLOW) {
658 dev_err_ratelimited(dev,
659 "crypto receive overflow");
660 pdcs->rx_oflow++;
661 } else {
662 dev_info_ratelimited(dev, "crypto rx len = 0");
663 }
664 return -EIO;
665 }
666 }
667
668 dma_pool_free(pdcs->rx_buf_pool, resp_hdr, resp_hdr_daddr);
669
Rob Ricee004c7e2016-11-14 13:25:59 -0500670 mbox_chan_received_data(chan, &mssg);
671
Rob Ricea24532f2016-06-30 15:59:23 -0400672 pdcs->pdc_replies++;
Rob Ricee004c7e2016-11-14 13:25:59 -0500673 return PDC_SUCCESS;
674}
675
676/**
677 * pdc_receive() - Process as many responses as are available in the rx ring.
678 * @pdcs: PDC state
679 *
680 * Called within the hard IRQ.
681 * Return:
682 */
683static int
684pdc_receive(struct pdc_state *pdcs)
685{
686 int rx_status;
687
688 /* read last_rx_curr from register once */
689 pdcs->last_rx_curr =
690 (ioread32((void *)&pdcs->rxregs_64->status0) &
691 CRYPTO_D64_RS0_CD_MASK) / RING_ENTRY_SIZE;
692
693 do {
694 /* Could be many frames ready */
695 rx_status = pdc_receive_one(pdcs);
696 } while (rx_status == PDC_SUCCESS);
697
698 return 0;
Rob Ricea24532f2016-06-30 15:59:23 -0400699}
700
701/**
702 * pdc_tx_list_sg_add() - Add the buffers in a scatterlist to the transmit
703 * descriptors for a given SPU. The scatterlist buffers contain the data for a
704 * SPU request message.
705 * @spu_idx: The index of the SPU to submit the request to, [0, max_spu)
706 * @sg: Scatterlist whose buffers contain part of the SPU request
707 *
708 * If a scatterlist buffer is larger than PDC_DMA_BUF_MAX, multiple descriptors
709 * are written for that buffer, each <= PDC_DMA_BUF_MAX byte in length.
710 *
711 * Return: PDC_SUCCESS if successful
712 * < 0 otherwise
713 */
714static int pdc_tx_list_sg_add(struct pdc_state *pdcs, struct scatterlist *sg)
715{
716 u32 flags = 0;
717 u32 eot;
718 u32 tx_avail;
719
720 /*
721 * Num descriptors needed. Conservatively assume we need a descriptor
722 * for every entry in sg.
723 */
724 u32 num_desc;
725 u32 desc_w = 0; /* Number of tx descriptors written */
726 u32 bufcnt; /* Number of bytes of buffer pointed to by descriptor */
727 dma_addr_t databufptr; /* DMA address to put in descriptor */
728
729 num_desc = (u32)sg_nents(sg);
730
731 /* check whether enough tx descriptors are available */
732 tx_avail = pdcs->ntxpost - NTXDACTIVE(pdcs->txin, pdcs->txout,
733 pdcs->ntxpost);
734 if (unlikely(num_desc > tx_avail)) {
735 pdcs->txnobuf++;
736 return -ENOSPC;
737 }
738
739 /* build tx descriptors */
740 if (pdcs->tx_msg_start == pdcs->txout) {
741 /* Start of frame */
742 pdcs->txin_numd[pdcs->tx_msg_start] = 0;
743 pdcs->src_sg[pdcs->txout] = sg;
744 flags = D64_CTRL1_SOF;
745 }
746
747 while (sg) {
748 if (unlikely(pdcs->txout == (pdcs->ntxd - 1)))
749 eot = D64_CTRL1_EOT;
750 else
751 eot = 0;
752
753 /*
754 * If sg buffer larger than PDC limit, split across
755 * multiple descriptors
756 */
757 bufcnt = sg_dma_len(sg);
758 databufptr = sg_dma_address(sg);
759 while (bufcnt > PDC_DMA_BUF_MAX) {
760 pdc_build_txd(pdcs, databufptr, PDC_DMA_BUF_MAX,
761 flags | eot);
762 desc_w++;
763 bufcnt -= PDC_DMA_BUF_MAX;
764 databufptr += PDC_DMA_BUF_MAX;
765 if (unlikely(pdcs->txout == (pdcs->ntxd - 1)))
766 eot = D64_CTRL1_EOT;
767 else
768 eot = 0;
769 }
770 sg = sg_next(sg);
771 if (!sg)
772 /* Writing last descriptor for frame */
773 flags |= (D64_CTRL1_EOF | D64_CTRL1_IOC);
774 pdc_build_txd(pdcs, databufptr, bufcnt, flags | eot);
775 desc_w++;
776 /* Clear start of frame after first descriptor */
777 flags &= ~D64_CTRL1_SOF;
778 }
779 pdcs->txin_numd[pdcs->tx_msg_start] += desc_w;
780
781 return PDC_SUCCESS;
782}
783
784/**
785 * pdc_tx_list_final() - Initiate DMA transfer of last frame written to tx
786 * ring.
787 * @pdcs: PDC state for SPU to process the request
788 *
789 * Sets the index of the last descriptor written in both the rx and tx ring.
790 *
791 * Return: PDC_SUCCESS
792 */
793static int pdc_tx_list_final(struct pdc_state *pdcs)
794{
795 /*
796 * write barrier to ensure all register writes are complete
797 * before chip starts to process new request
798 */
799 wmb();
800 iowrite32(pdcs->rxout << 4, (void *)&pdcs->rxregs_64->ptr);
801 iowrite32(pdcs->txout << 4, (void *)&pdcs->txregs_64->ptr);
802 pdcs->pdc_requests++;
803
804 return PDC_SUCCESS;
805}
806
807/**
808 * pdc_rx_list_init() - Start a new receive descriptor list for a given PDC.
809 * @pdcs: PDC state for SPU handling request
810 * @dst_sg: scatterlist providing rx buffers for response to be returned to
811 * mailbox client
812 * @ctx: Opaque context for this request
813 *
814 * Posts a single receive descriptor to hold the metadata that precedes a
815 * response. For example, with SPU-M, the metadata is a 32-byte DMA header and
816 * an 8-byte BCM header. Moves the msg_start descriptor indexes for both tx and
817 * rx to indicate the start of a new message.
818 *
819 * Return: PDC_SUCCESS if successful
820 * < 0 if an error (e.g., rx ring is full)
821 */
822static int pdc_rx_list_init(struct pdc_state *pdcs, struct scatterlist *dst_sg,
823 void *ctx)
824{
825 u32 flags = 0;
826 u32 rx_avail;
827 u32 rx_pkt_cnt = 1; /* Adding a single rx buffer */
828 dma_addr_t daddr;
829 void *vaddr;
830
831 rx_avail = pdcs->nrxpost - NRXDACTIVE(pdcs->rxin, pdcs->rxout,
832 pdcs->nrxpost);
833 if (unlikely(rx_pkt_cnt > rx_avail)) {
834 pdcs->rxnobuf++;
835 return -ENOSPC;
836 }
837
838 /* allocate a buffer for the dma rx status */
839 vaddr = dma_pool_zalloc(pdcs->rx_buf_pool, GFP_ATOMIC, &daddr);
Rob Rice7493cde2016-11-14 13:26:00 -0500840 if (unlikely(!vaddr))
Rob Ricea24532f2016-06-30 15:59:23 -0400841 return -ENOMEM;
842
843 /*
844 * Update msg_start indexes for both tx and rx to indicate the start
845 * of a new sequence of descriptor indexes that contain the fragments
846 * of the same message.
847 */
848 pdcs->rx_msg_start = pdcs->rxout;
849 pdcs->tx_msg_start = pdcs->txout;
850
851 /* This is always the first descriptor in the receive sequence */
852 flags = D64_CTRL1_SOF;
853 pdcs->rxin_numd[pdcs->rx_msg_start] = 1;
854
855 if (unlikely(pdcs->rxout == (pdcs->nrxd - 1)))
856 flags |= D64_CTRL1_EOT;
857
858 pdcs->rxp_ctx[pdcs->rxout] = ctx;
859 pdcs->dst_sg[pdcs->rxout] = dst_sg;
860 pdcs->resp_hdr[pdcs->rxout] = vaddr;
861 pdcs->resp_hdr_daddr[pdcs->rxout] = daddr;
862 pdc_build_rxd(pdcs, daddr, pdcs->pdc_resp_hdr_len, flags);
863 return PDC_SUCCESS;
864}
865
866/**
867 * pdc_rx_list_sg_add() - Add the buffers in a scatterlist to the receive
868 * descriptors for a given SPU. The caller must have already DMA mapped the
869 * scatterlist.
870 * @spu_idx: Indicates which SPU the buffers are for
871 * @sg: Scatterlist whose buffers are added to the receive ring
872 *
873 * If a receive buffer in the scatterlist is larger than PDC_DMA_BUF_MAX,
874 * multiple receive descriptors are written, each with a buffer <=
875 * PDC_DMA_BUF_MAX.
876 *
877 * Return: PDC_SUCCESS if successful
878 * < 0 otherwise (e.g., receive ring is full)
879 */
880static int pdc_rx_list_sg_add(struct pdc_state *pdcs, struct scatterlist *sg)
881{
882 u32 flags = 0;
883 u32 rx_avail;
884
885 /*
886 * Num descriptors needed. Conservatively assume we need a descriptor
887 * for every entry from our starting point in the scatterlist.
888 */
889 u32 num_desc;
890 u32 desc_w = 0; /* Number of tx descriptors written */
891 u32 bufcnt; /* Number of bytes of buffer pointed to by descriptor */
892 dma_addr_t databufptr; /* DMA address to put in descriptor */
893
894 num_desc = (u32)sg_nents(sg);
895
896 rx_avail = pdcs->nrxpost - NRXDACTIVE(pdcs->rxin, pdcs->rxout,
897 pdcs->nrxpost);
898 if (unlikely(num_desc > rx_avail)) {
899 pdcs->rxnobuf++;
900 return -ENOSPC;
901 }
902
903 while (sg) {
904 if (unlikely(pdcs->rxout == (pdcs->nrxd - 1)))
905 flags = D64_CTRL1_EOT;
906 else
907 flags = 0;
908
909 /*
910 * If sg buffer larger than PDC limit, split across
911 * multiple descriptors
912 */
913 bufcnt = sg_dma_len(sg);
914 databufptr = sg_dma_address(sg);
915 while (bufcnt > PDC_DMA_BUF_MAX) {
916 pdc_build_rxd(pdcs, databufptr, PDC_DMA_BUF_MAX, flags);
917 desc_w++;
918 bufcnt -= PDC_DMA_BUF_MAX;
919 databufptr += PDC_DMA_BUF_MAX;
920 if (unlikely(pdcs->rxout == (pdcs->nrxd - 1)))
921 flags = D64_CTRL1_EOT;
922 else
923 flags = 0;
924 }
925 pdc_build_rxd(pdcs, databufptr, bufcnt, flags);
926 desc_w++;
927 sg = sg_next(sg);
928 }
929 pdcs->rxin_numd[pdcs->rx_msg_start] += desc_w;
930
931 return PDC_SUCCESS;
932}
933
934/**
935 * pdc_irq_handler() - Interrupt handler called in interrupt context.
936 * @irq: Interrupt number that has fired
Rob Rice8aef00f2016-11-14 13:26:01 -0500937 * @data: device struct for DMA engine that generated the interrupt
Rob Ricea24532f2016-06-30 15:59:23 -0400938 *
939 * We have to clear the device interrupt status flags here. So cache the
940 * status for later use in the thread function. Other than that, just return
941 * WAKE_THREAD to invoke the thread function.
942 *
943 * Return: IRQ_WAKE_THREAD if interrupt is ours
944 * IRQ_NONE otherwise
945 */
Rob Rice8aef00f2016-11-14 13:26:01 -0500946static irqreturn_t pdc_irq_handler(int irq, void *data)
Rob Ricea24532f2016-06-30 15:59:23 -0400947{
Rob Rice8aef00f2016-11-14 13:26:01 -0500948 struct device *dev = (struct device *)data;
949 struct pdc_state *pdcs = dev_get_drvdata(dev);
Rob Ricea24532f2016-06-30 15:59:23 -0400950 u32 intstatus = ioread32(pdcs->pdc_reg_vbase + PDC_INTSTATUS_OFFSET);
951
Rob Rice7493cde2016-11-14 13:26:00 -0500952 if (likely(intstatus & PDC_RCVINTEN_0))
Rob Ricea24532f2016-06-30 15:59:23 -0400953 set_bit(PDC_RCVINT_0, &pdcs->intstatus);
954
955 /* Clear interrupt flags in device */
956 iowrite32(intstatus, pdcs->pdc_reg_vbase + PDC_INTSTATUS_OFFSET);
957
958 /* Wakeup IRQ thread */
Rob Rice8aef00f2016-11-14 13:26:01 -0500959 if (likely(pdcs && (irq == pdcs->pdc_irq) &&
960 (intstatus & PDC_INTMASK))) {
961 tasklet_schedule(&pdcs->rx_tasklet);
Rob Ricea24532f2016-06-30 15:59:23 -0400962 return IRQ_HANDLED;
963 }
964 return IRQ_NONE;
965}
966
Rob Rice8aef00f2016-11-14 13:26:01 -0500967static void pdc_tasklet_cb(unsigned long data)
968{
969 struct pdc_state *pdcs = (struct pdc_state *)data;
970 bool rx_int;
971
972 rx_int = test_and_clear_bit(PDC_RCVINT_0, &pdcs->intstatus);
973 if (likely(pdcs && rx_int))
974 pdc_receive(pdcs);
975}
976
Rob Ricea24532f2016-06-30 15:59:23 -0400977/**
978 * pdc_ring_init() - Allocate DMA rings and initialize constant fields of
979 * descriptors in one ringset.
980 * @pdcs: PDC instance state
981 * @ringset: index of ringset being used
982 *
983 * Return: PDC_SUCCESS if ring initialized
984 * < 0 otherwise
985 */
986static int pdc_ring_init(struct pdc_state *pdcs, int ringset)
987{
988 int i;
989 int err = PDC_SUCCESS;
990 struct dma64 *dma_reg;
991 struct device *dev = &pdcs->pdev->dev;
992 struct pdc_ring_alloc tx;
993 struct pdc_ring_alloc rx;
994
995 /* Allocate tx ring */
996 tx.vbase = dma_pool_zalloc(pdcs->ring_pool, GFP_KERNEL, &tx.dmabase);
Rob Rice7493cde2016-11-14 13:26:00 -0500997 if (unlikely(!tx.vbase)) {
Rob Ricea24532f2016-06-30 15:59:23 -0400998 err = -ENOMEM;
999 goto done;
1000 }
1001
1002 /* Allocate rx ring */
1003 rx.vbase = dma_pool_zalloc(pdcs->ring_pool, GFP_KERNEL, &rx.dmabase);
Rob Rice7493cde2016-11-14 13:26:00 -05001004 if (unlikely(!rx.vbase)) {
Rob Ricea24532f2016-06-30 15:59:23 -04001005 err = -ENOMEM;
1006 goto fail_dealloc;
1007 }
1008
Rob Ricea68b2162016-07-28 11:54:20 -04001009 dev_dbg(dev, " - base DMA addr of tx ring %pad", &tx.dmabase);
Rob Ricea24532f2016-06-30 15:59:23 -04001010 dev_dbg(dev, " - base virtual addr of tx ring %p", tx.vbase);
Rob Ricea68b2162016-07-28 11:54:20 -04001011 dev_dbg(dev, " - base DMA addr of rx ring %pad", &rx.dmabase);
Rob Ricea24532f2016-06-30 15:59:23 -04001012 dev_dbg(dev, " - base virtual addr of rx ring %p", rx.vbase);
1013
Rob Ricea24532f2016-06-30 15:59:23 -04001014 memcpy(&pdcs->tx_ring_alloc, &tx, sizeof(tx));
1015 memcpy(&pdcs->rx_ring_alloc, &rx, sizeof(rx));
1016
1017 pdcs->rxin = 0;
1018 pdcs->rx_msg_start = 0;
1019 pdcs->last_rx_curr = 0;
1020 pdcs->rxout = 0;
1021 pdcs->txin = 0;
1022 pdcs->tx_msg_start = 0;
1023 pdcs->txout = 0;
1024
1025 /* Set descriptor array base addresses */
1026 pdcs->txd_64 = (struct dma64dd *)pdcs->tx_ring_alloc.vbase;
1027 pdcs->rxd_64 = (struct dma64dd *)pdcs->rx_ring_alloc.vbase;
1028
1029 /* Tell device the base DMA address of each ring */
1030 dma_reg = &pdcs->regs->dmaregs[ringset];
Steve Lin9fb0f9a2016-11-14 13:25:56 -05001031
1032 /* But first disable DMA and set curptr to 0 for both TX & RX */
1033 iowrite32(PDC_TX_CTL, &dma_reg->dmaxmt.control);
1034 iowrite32((PDC_RX_CTL + (pdcs->rx_status_len << 1)),
1035 (void *)&dma_reg->dmarcv.control);
1036 iowrite32(0, (void *)&dma_reg->dmaxmt.ptr);
1037 iowrite32(0, (void *)&dma_reg->dmarcv.ptr);
1038
1039 /* Set base DMA addresses */
Rob Ricea24532f2016-06-30 15:59:23 -04001040 iowrite32(lower_32_bits(pdcs->tx_ring_alloc.dmabase),
1041 (void *)&dma_reg->dmaxmt.addrlow);
1042 iowrite32(upper_32_bits(pdcs->tx_ring_alloc.dmabase),
1043 (void *)&dma_reg->dmaxmt.addrhigh);
1044
1045 iowrite32(lower_32_bits(pdcs->rx_ring_alloc.dmabase),
1046 (void *)&dma_reg->dmarcv.addrlow);
1047 iowrite32(upper_32_bits(pdcs->rx_ring_alloc.dmabase),
1048 (void *)&dma_reg->dmarcv.addrhigh);
1049
Steve Lin9fb0f9a2016-11-14 13:25:56 -05001050 /* Re-enable DMA */
1051 iowrite32(PDC_TX_CTL | PDC_TX_ENABLE, &dma_reg->dmaxmt.control);
1052 iowrite32((PDC_RX_CTL | PDC_RX_ENABLE | (pdcs->rx_status_len << 1)),
1053 (void *)&dma_reg->dmarcv.control);
1054
Rob Ricea24532f2016-06-30 15:59:23 -04001055 /* Initialize descriptors */
1056 for (i = 0; i < PDC_RING_ENTRIES; i++) {
1057 /* Every tx descriptor can be used for start of frame. */
1058 if (i != pdcs->ntxpost) {
1059 iowrite32(D64_CTRL1_SOF | D64_CTRL1_EOF,
1060 (void *)&pdcs->txd_64[i].ctrl1);
1061 } else {
1062 /* Last descriptor in ringset. Set End of Table. */
1063 iowrite32(D64_CTRL1_SOF | D64_CTRL1_EOF |
1064 D64_CTRL1_EOT,
1065 (void *)&pdcs->txd_64[i].ctrl1);
1066 }
1067
1068 /* Every rx descriptor can be used for start of frame */
1069 if (i != pdcs->nrxpost) {
1070 iowrite32(D64_CTRL1_SOF,
1071 (void *)&pdcs->rxd_64[i].ctrl1);
1072 } else {
1073 /* Last descriptor in ringset. Set End of Table. */
1074 iowrite32(D64_CTRL1_SOF | D64_CTRL1_EOT,
1075 (void *)&pdcs->rxd_64[i].ctrl1);
1076 }
1077 }
Rob Ricea24532f2016-06-30 15:59:23 -04001078 return PDC_SUCCESS;
1079
1080fail_dealloc:
1081 dma_pool_free(pdcs->ring_pool, tx.vbase, tx.dmabase);
1082done:
1083 return err;
1084}
1085
1086static void pdc_ring_free(struct pdc_state *pdcs)
1087{
1088 if (pdcs->tx_ring_alloc.vbase) {
1089 dma_pool_free(pdcs->ring_pool, pdcs->tx_ring_alloc.vbase,
1090 pdcs->tx_ring_alloc.dmabase);
1091 pdcs->tx_ring_alloc.vbase = NULL;
1092 }
1093
1094 if (pdcs->rx_ring_alloc.vbase) {
1095 dma_pool_free(pdcs->ring_pool, pdcs->rx_ring_alloc.vbase,
1096 pdcs->rx_ring_alloc.dmabase);
1097 pdcs->rx_ring_alloc.vbase = NULL;
1098 }
1099}
1100
1101/**
Rob Riceab8d1b22016-11-14 13:25:58 -05001102 * pdc_desc_count() - Count the number of DMA descriptors that will be required
1103 * for a given scatterlist. Account for the max length of a DMA buffer.
1104 * @sg: Scatterlist to be DMA'd
1105 * Return: Number of descriptors required
1106 */
1107static u32 pdc_desc_count(struct scatterlist *sg)
1108{
1109 u32 cnt = 0;
1110
1111 while (sg) {
1112 cnt += ((sg->length / PDC_DMA_BUF_MAX) + 1);
1113 sg = sg_next(sg);
1114 }
1115 return cnt;
1116}
1117
1118/**
1119 * pdc_rings_full() - Check whether the tx ring has room for tx_cnt descriptors
1120 * and the rx ring has room for rx_cnt descriptors.
1121 * @pdcs: PDC state
1122 * @tx_cnt: The number of descriptors required in the tx ring
1123 * @rx_cnt: The number of descriptors required i the rx ring
1124 *
1125 * Return: true if one of the rings does not have enough space
1126 * false if sufficient space is available in both rings
1127 */
1128static bool pdc_rings_full(struct pdc_state *pdcs, int tx_cnt, int rx_cnt)
1129{
1130 u32 rx_avail;
1131 u32 tx_avail;
1132 bool full = false;
1133
1134 /* Check if the tx and rx rings are likely to have enough space */
1135 rx_avail = pdcs->nrxpost - NRXDACTIVE(pdcs->rxin, pdcs->rxout,
1136 pdcs->nrxpost);
1137 if (unlikely(rx_cnt > rx_avail)) {
1138 pdcs->rx_ring_full++;
1139 full = true;
1140 }
1141
1142 if (likely(!full)) {
1143 tx_avail = pdcs->ntxpost - NTXDACTIVE(pdcs->txin, pdcs->txout,
1144 pdcs->ntxpost);
1145 if (unlikely(tx_cnt > tx_avail)) {
1146 pdcs->tx_ring_full++;
1147 full = true;
1148 }
1149 }
1150 return full;
1151}
1152
1153/**
1154 * pdc_last_tx_done() - If both the tx and rx rings have at least
1155 * PDC_RING_SPACE_MIN descriptors available, then indicate that the mailbox
1156 * framework can submit another message.
1157 * @chan: mailbox channel to check
1158 * Return: true if PDC can accept another message on this channel
1159 */
1160static bool pdc_last_tx_done(struct mbox_chan *chan)
1161{
1162 struct pdc_state *pdcs = chan->con_priv;
1163 bool ret;
1164
1165 if (unlikely(pdc_rings_full(pdcs, PDC_RING_SPACE_MIN,
1166 PDC_RING_SPACE_MIN))) {
1167 pdcs->last_tx_not_done++;
1168 ret = false;
1169 } else {
1170 ret = true;
1171 }
1172 return ret;
1173}
1174
1175/**
Rob Ricea24532f2016-06-30 15:59:23 -04001176 * pdc_send_data() - mailbox send_data function
1177 * @chan: The mailbox channel on which the data is sent. The channel
1178 * corresponds to a DMA ringset.
1179 * @data: The mailbox message to be sent. The message must be a
1180 * brcm_message structure.
1181 *
1182 * This function is registered as the send_data function for the mailbox
1183 * controller. From the destination scatterlist in the mailbox message, it
1184 * creates a sequence of receive descriptors in the rx ring. From the source
1185 * scatterlist, it creates a sequence of transmit descriptors in the tx ring.
1186 * After creating the descriptors, it writes the rx ptr and tx ptr registers to
1187 * initiate the DMA transfer.
1188 *
1189 * This function does the DMA map and unmap of the src and dst scatterlists in
1190 * the mailbox message.
1191 *
1192 * Return: 0 if successful
1193 * -ENOTSUPP if the mailbox message is a type this driver does not
1194 * support
1195 * < 0 if an error
1196 */
1197static int pdc_send_data(struct mbox_chan *chan, void *data)
1198{
1199 struct pdc_state *pdcs = chan->con_priv;
1200 struct device *dev = &pdcs->pdev->dev;
1201 struct brcm_message *mssg = data;
1202 int err = PDC_SUCCESS;
1203 int src_nent;
1204 int dst_nent;
1205 int nent;
Rob Riceab8d1b22016-11-14 13:25:58 -05001206 u32 tx_desc_req;
1207 u32 rx_desc_req;
Rob Ricea24532f2016-06-30 15:59:23 -04001208
Rob Rice7493cde2016-11-14 13:26:00 -05001209 if (unlikely(mssg->type != BRCM_MESSAGE_SPU))
Rob Ricea24532f2016-06-30 15:59:23 -04001210 return -ENOTSUPP;
1211
1212 src_nent = sg_nents(mssg->spu.src);
Rob Rice7493cde2016-11-14 13:26:00 -05001213 if (likely(src_nent)) {
Rob Ricea24532f2016-06-30 15:59:23 -04001214 nent = dma_map_sg(dev, mssg->spu.src, src_nent, DMA_TO_DEVICE);
Rob Rice7493cde2016-11-14 13:26:00 -05001215 if (unlikely(nent == 0))
Rob Ricea24532f2016-06-30 15:59:23 -04001216 return -EIO;
1217 }
1218
1219 dst_nent = sg_nents(mssg->spu.dst);
Rob Rice7493cde2016-11-14 13:26:00 -05001220 if (likely(dst_nent)) {
Rob Ricea24532f2016-06-30 15:59:23 -04001221 nent = dma_map_sg(dev, mssg->spu.dst, dst_nent,
1222 DMA_FROM_DEVICE);
Rob Rice7493cde2016-11-14 13:26:00 -05001223 if (unlikely(nent == 0)) {
Rob Ricea24532f2016-06-30 15:59:23 -04001224 dma_unmap_sg(dev, mssg->spu.src, src_nent,
1225 DMA_TO_DEVICE);
1226 return -EIO;
1227 }
1228 }
1229
Rob Riceab8d1b22016-11-14 13:25:58 -05001230 /*
1231 * Check if the tx and rx rings have enough space. Do this prior to
1232 * writing any tx or rx descriptors. Need to ensure that we do not write
1233 * a partial set of descriptors, or write just rx descriptors but
1234 * corresponding tx descriptors don't fit. Note that we want this check
1235 * and the entire sequence of descriptor to happen without another
1236 * thread getting in. The channel spin lock in the mailbox framework
1237 * ensures this.
1238 */
1239 tx_desc_req = pdc_desc_count(mssg->spu.src);
1240 rx_desc_req = pdc_desc_count(mssg->spu.dst);
Rob Rice7493cde2016-11-14 13:26:00 -05001241 if (unlikely(pdc_rings_full(pdcs, tx_desc_req, rx_desc_req + 1)))
Rob Riceab8d1b22016-11-14 13:25:58 -05001242 return -ENOSPC;
Rob Ricea24532f2016-06-30 15:59:23 -04001243
1244 /* Create rx descriptors to SPU catch response */
1245 err = pdc_rx_list_init(pdcs, mssg->spu.dst, mssg->ctx);
1246 err |= pdc_rx_list_sg_add(pdcs, mssg->spu.dst);
1247
1248 /* Create tx descriptors to submit SPU request */
1249 err |= pdc_tx_list_sg_add(pdcs, mssg->spu.src);
1250 err |= pdc_tx_list_final(pdcs); /* initiate transfer */
1251
Rob Rice7493cde2016-11-14 13:26:00 -05001252 if (unlikely(err))
Rob Ricea24532f2016-06-30 15:59:23 -04001253 dev_err(&pdcs->pdev->dev,
1254 "%s failed with error %d", __func__, err);
1255
1256 return err;
1257}
1258
1259static int pdc_startup(struct mbox_chan *chan)
1260{
1261 return pdc_ring_init(chan->con_priv, PDC_RINGSET);
1262}
1263
1264static void pdc_shutdown(struct mbox_chan *chan)
1265{
1266 struct pdc_state *pdcs = chan->con_priv;
1267
Dan Carpenter068cf292016-08-04 08:30:31 +03001268 if (!pdcs)
1269 return;
Rob Ricea24532f2016-06-30 15:59:23 -04001270
Dan Carpenter068cf292016-08-04 08:30:31 +03001271 dev_dbg(&pdcs->pdev->dev,
1272 "Shutdown mailbox channel for PDC %u", pdcs->pdc_idx);
Rob Ricea24532f2016-06-30 15:59:23 -04001273 pdc_ring_free(pdcs);
1274}
1275
1276/**
1277 * pdc_hw_init() - Use the given initialization parameters to initialize the
1278 * state for one of the PDCs.
1279 * @pdcs: state of the PDC
1280 */
1281static
1282void pdc_hw_init(struct pdc_state *pdcs)
1283{
1284 struct platform_device *pdev;
1285 struct device *dev;
1286 struct dma64 *dma_reg;
1287 int ringset = PDC_RINGSET;
1288
1289 pdev = pdcs->pdev;
1290 dev = &pdev->dev;
1291
1292 dev_dbg(dev, "PDC %u initial values:", pdcs->pdc_idx);
1293 dev_dbg(dev, "state structure: %p",
1294 pdcs);
1295 dev_dbg(dev, " - base virtual addr of hw regs %p",
1296 pdcs->pdc_reg_vbase);
1297
1298 /* initialize data structures */
1299 pdcs->regs = (struct pdc_regs *)pdcs->pdc_reg_vbase;
1300 pdcs->txregs_64 = (struct dma64_regs *)
1301 (void *)(((u8 *)pdcs->pdc_reg_vbase) +
1302 PDC_TXREGS_OFFSET + (sizeof(struct dma64) * ringset));
1303 pdcs->rxregs_64 = (struct dma64_regs *)
1304 (void *)(((u8 *)pdcs->pdc_reg_vbase) +
1305 PDC_RXREGS_OFFSET + (sizeof(struct dma64) * ringset));
1306
1307 pdcs->ntxd = PDC_RING_ENTRIES;
1308 pdcs->nrxd = PDC_RING_ENTRIES;
1309 pdcs->ntxpost = PDC_RING_ENTRIES - 1;
1310 pdcs->nrxpost = PDC_RING_ENTRIES - 1;
Steve Lin9fb0f9a2016-11-14 13:25:56 -05001311 iowrite32(0, &pdcs->regs->intmask);
Rob Ricea24532f2016-06-30 15:59:23 -04001312
1313 dma_reg = &pdcs->regs->dmaregs[ringset];
Rob Ricea24532f2016-06-30 15:59:23 -04001314
Steve Lin9fb0f9a2016-11-14 13:25:56 -05001315 /* Configure DMA but will enable later in pdc_ring_init() */
1316 iowrite32(PDC_TX_CTL, &dma_reg->dmaxmt.control);
Rob Ricea24532f2016-06-30 15:59:23 -04001317
1318 iowrite32(PDC_RX_CTL + (pdcs->rx_status_len << 1),
1319 (void *)&dma_reg->dmarcv.control);
1320
Steve Lin9fb0f9a2016-11-14 13:25:56 -05001321 /* Reset current index pointers after making sure DMA is disabled */
1322 iowrite32(0, &dma_reg->dmaxmt.ptr);
1323 iowrite32(0, &dma_reg->dmarcv.ptr);
1324
Rob Ricea24532f2016-06-30 15:59:23 -04001325 if (pdcs->pdc_resp_hdr_len == PDC_SPU2_RESP_HDR_LEN)
1326 iowrite32(PDC_CKSUM_CTRL,
1327 pdcs->pdc_reg_vbase + PDC_CKSUM_CTRL_OFFSET);
1328}
1329
1330/**
Steve Lin9fb0f9a2016-11-14 13:25:56 -05001331 * pdc_hw_disable() - Disable the tx and rx control in the hw.
1332 * @pdcs: PDC state structure
1333 *
1334 */
1335static void pdc_hw_disable(struct pdc_state *pdcs)
1336{
1337 struct dma64 *dma_reg;
1338
1339 dma_reg = &pdcs->regs->dmaregs[PDC_RINGSET];
1340 iowrite32(PDC_TX_CTL, &dma_reg->dmaxmt.control);
1341 iowrite32(PDC_RX_CTL + (pdcs->rx_status_len << 1),
1342 &dma_reg->dmarcv.control);
1343}
1344
1345/**
Rob Ricea24532f2016-06-30 15:59:23 -04001346 * pdc_rx_buf_pool_create() - Pool of receive buffers used to catch the metadata
1347 * header returned with each response message.
1348 * @pdcs: PDC state structure
1349 *
1350 * The metadata is not returned to the mailbox client. So the PDC driver
1351 * manages these buffers.
1352 *
1353 * Return: PDC_SUCCESS
1354 * -ENOMEM if pool creation fails
1355 */
1356static int pdc_rx_buf_pool_create(struct pdc_state *pdcs)
1357{
1358 struct platform_device *pdev;
1359 struct device *dev;
1360
1361 pdev = pdcs->pdev;
1362 dev = &pdev->dev;
1363
1364 pdcs->pdc_resp_hdr_len = pdcs->rx_status_len;
1365 if (pdcs->use_bcm_hdr)
1366 pdcs->pdc_resp_hdr_len += BCM_HDR_LEN;
1367
1368 pdcs->rx_buf_pool = dma_pool_create("pdc rx bufs", dev,
1369 pdcs->pdc_resp_hdr_len,
1370 RX_BUF_ALIGN, 0);
1371 if (!pdcs->rx_buf_pool)
1372 return -ENOMEM;
1373
1374 return PDC_SUCCESS;
1375}
1376
1377/**
1378 * pdc_interrupts_init() - Initialize the interrupt configuration for a PDC and
1379 * specify a threaded IRQ handler for deferred handling of interrupts outside of
1380 * interrupt context.
1381 * @pdcs: PDC state
1382 *
1383 * Set the interrupt mask for transmit and receive done.
1384 * Set the lazy interrupt frame count to generate an interrupt for just one pkt.
1385 *
1386 * Return: PDC_SUCCESS
1387 * <0 if threaded irq request fails
1388 */
1389static int pdc_interrupts_init(struct pdc_state *pdcs)
1390{
1391 struct platform_device *pdev = pdcs->pdev;
1392 struct device *dev = &pdev->dev;
1393 struct device_node *dn = pdev->dev.of_node;
1394 int err;
1395
1396 pdcs->intstatus = 0;
1397
1398 /* interrupt configuration */
1399 iowrite32(PDC_INTMASK, pdcs->pdc_reg_vbase + PDC_INTMASK_OFFSET);
1400 iowrite32(PDC_LAZY_INT, pdcs->pdc_reg_vbase + PDC_RCVLAZY0_OFFSET);
1401
1402 /* read irq from device tree */
1403 pdcs->pdc_irq = irq_of_parse_and_map(dn, 0);
1404 dev_dbg(dev, "pdc device %s irq %u for pdcs %p",
1405 dev_name(dev), pdcs->pdc_irq, pdcs);
Rob Rice8aef00f2016-11-14 13:26:01 -05001406
1407 err = devm_request_irq(dev, pdcs->pdc_irq, pdc_irq_handler, 0,
1408 dev_name(dev), dev);
Rob Ricea24532f2016-06-30 15:59:23 -04001409 if (err) {
Rob Rice8aef00f2016-11-14 13:26:01 -05001410 dev_err(dev, "IRQ %u request failed with err %d\n",
Rob Ricea24532f2016-06-30 15:59:23 -04001411 pdcs->pdc_irq, err);
1412 return err;
1413 }
1414 return PDC_SUCCESS;
1415}
1416
1417static const struct mbox_chan_ops pdc_mbox_chan_ops = {
1418 .send_data = pdc_send_data,
Rob Riceab8d1b22016-11-14 13:25:58 -05001419 .last_tx_done = pdc_last_tx_done,
Rob Ricea24532f2016-06-30 15:59:23 -04001420 .startup = pdc_startup,
1421 .shutdown = pdc_shutdown
1422};
1423
1424/**
1425 * pdc_mb_init() - Initialize the mailbox controller.
1426 * @pdcs: PDC state
1427 *
1428 * Each PDC is a mailbox controller. Each ringset is a mailbox channel. Kernel
1429 * driver only uses one ringset and thus one mb channel. PDC uses the transmit
1430 * complete interrupt to determine when a mailbox message has successfully been
1431 * transmitted.
1432 *
1433 * Return: 0 on success
1434 * < 0 if there is an allocation or registration failure
1435 */
1436static int pdc_mb_init(struct pdc_state *pdcs)
1437{
1438 struct device *dev = &pdcs->pdev->dev;
1439 struct mbox_controller *mbc;
1440 int chan_index;
1441 int err;
1442
1443 mbc = &pdcs->mbc;
1444 mbc->dev = dev;
1445 mbc->ops = &pdc_mbox_chan_ops;
1446 mbc->num_chans = 1;
1447 mbc->chans = devm_kcalloc(dev, mbc->num_chans, sizeof(*mbc->chans),
1448 GFP_KERNEL);
1449 if (!mbc->chans)
1450 return -ENOMEM;
1451
Rob Riceab8d1b22016-11-14 13:25:58 -05001452 mbc->txdone_irq = false;
1453 mbc->txdone_poll = true;
1454 mbc->txpoll_period = 1;
Rob Ricea24532f2016-06-30 15:59:23 -04001455 for (chan_index = 0; chan_index < mbc->num_chans; chan_index++)
1456 mbc->chans[chan_index].con_priv = pdcs;
1457
1458 /* Register mailbox controller */
1459 err = mbox_controller_register(mbc);
1460 if (err) {
1461 dev_crit(dev,
1462 "Failed to register PDC mailbox controller. Error %d.",
1463 err);
1464 return err;
1465 }
1466 return 0;
1467}
1468
1469/**
1470 * pdc_dt_read() - Read application-specific data from device tree.
1471 * @pdev: Platform device
1472 * @pdcs: PDC state
1473 *
1474 * Reads the number of bytes of receive status that precede each received frame.
1475 * Reads whether transmit and received frames should be preceded by an 8-byte
1476 * BCM header.
1477 *
1478 * Return: 0 if successful
1479 * -ENODEV if device not available
1480 */
1481static int pdc_dt_read(struct platform_device *pdev, struct pdc_state *pdcs)
1482{
1483 struct device *dev = &pdev->dev;
1484 struct device_node *dn = pdev->dev.of_node;
1485 int err;
1486
1487 err = of_property_read_u32(dn, "brcm,rx-status-len",
1488 &pdcs->rx_status_len);
1489 if (err < 0)
1490 dev_err(dev,
1491 "%s failed to get DMA receive status length from device tree",
1492 __func__);
1493
1494 pdcs->use_bcm_hdr = of_property_read_bool(dn, "brcm,use-bcm-hdr");
1495
1496 return 0;
1497}
1498
1499/**
1500 * pdc_probe() - Probe function for PDC driver.
1501 * @pdev: PDC platform device
1502 *
1503 * Reserve and map register regions defined in device tree.
1504 * Allocate and initialize tx and rx DMA rings.
1505 * Initialize a mailbox controller for each PDC.
1506 *
1507 * Return: 0 if successful
1508 * < 0 if an error
1509 */
1510static int pdc_probe(struct platform_device *pdev)
1511{
1512 int err = 0;
1513 struct device *dev = &pdev->dev;
1514 struct resource *pdc_regs;
1515 struct pdc_state *pdcs;
1516
1517 /* PDC state for one SPU */
1518 pdcs = devm_kzalloc(dev, sizeof(*pdcs), GFP_KERNEL);
1519 if (!pdcs) {
1520 err = -ENOMEM;
1521 goto cleanup;
1522 }
1523
Rob Ricea24532f2016-06-30 15:59:23 -04001524 pdcs->pdev = pdev;
1525 platform_set_drvdata(pdev, pdcs);
1526 pdcs->pdc_idx = pdcg.num_spu;
1527 pdcg.num_spu++;
1528
1529 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
1530 if (err) {
1531 dev_warn(dev, "PDC device cannot perform DMA. Error %d.", err);
1532 goto cleanup;
1533 }
1534
1535 /* Create DMA pool for tx ring */
1536 pdcs->ring_pool = dma_pool_create("pdc rings", dev, PDC_RING_SIZE,
1537 RING_ALIGN, 0);
1538 if (!pdcs->ring_pool) {
1539 err = -ENOMEM;
1540 goto cleanup;
1541 }
1542
1543 err = pdc_dt_read(pdev, pdcs);
1544 if (err)
1545 goto cleanup_ring_pool;
1546
1547 pdc_regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1548 if (!pdc_regs) {
1549 err = -ENODEV;
1550 goto cleanup_ring_pool;
1551 }
Rob Ricea68b2162016-07-28 11:54:20 -04001552 dev_dbg(dev, "PDC register region res.start = %pa, res.end = %pa",
1553 &pdc_regs->start, &pdc_regs->end);
Rob Ricea24532f2016-06-30 15:59:23 -04001554
1555 pdcs->pdc_reg_vbase = devm_ioremap_resource(&pdev->dev, pdc_regs);
1556 if (IS_ERR(pdcs->pdc_reg_vbase)) {
1557 err = PTR_ERR(pdcs->pdc_reg_vbase);
1558 dev_err(&pdev->dev, "Failed to map registers: %d\n", err);
1559 goto cleanup_ring_pool;
1560 }
1561
1562 /* create rx buffer pool after dt read to know how big buffers are */
1563 err = pdc_rx_buf_pool_create(pdcs);
1564 if (err)
1565 goto cleanup_ring_pool;
1566
1567 pdc_hw_init(pdcs);
1568
Rob Rice8aef00f2016-11-14 13:26:01 -05001569 /* Init tasklet for deferred DMA rx processing */
1570 tasklet_init(&pdcs->rx_tasklet, pdc_tasklet_cb, (unsigned long) pdcs);
1571
Rob Ricea24532f2016-06-30 15:59:23 -04001572 err = pdc_interrupts_init(pdcs);
1573 if (err)
1574 goto cleanup_buf_pool;
1575
1576 /* Initialize mailbox controller */
1577 err = pdc_mb_init(pdcs);
1578 if (err)
1579 goto cleanup_buf_pool;
1580
1581 pdcs->debugfs_stats = NULL;
1582 pdc_setup_debugfs(pdcs);
1583
1584 dev_dbg(dev, "pdc_probe() successful");
1585 return PDC_SUCCESS;
1586
1587cleanup_buf_pool:
Rob Rice8aef00f2016-11-14 13:26:01 -05001588 tasklet_kill(&pdcs->rx_tasklet);
Rob Ricea24532f2016-06-30 15:59:23 -04001589 dma_pool_destroy(pdcs->rx_buf_pool);
1590
1591cleanup_ring_pool:
1592 dma_pool_destroy(pdcs->ring_pool);
1593
1594cleanup:
1595 return err;
1596}
1597
1598static int pdc_remove(struct platform_device *pdev)
1599{
1600 struct pdc_state *pdcs = platform_get_drvdata(pdev);
1601
1602 pdc_free_debugfs();
1603
Rob Rice8aef00f2016-11-14 13:26:01 -05001604 tasklet_kill(&pdcs->rx_tasklet);
1605
Steve Lin9fb0f9a2016-11-14 13:25:56 -05001606 pdc_hw_disable(pdcs);
1607
Rob Ricea24532f2016-06-30 15:59:23 -04001608 mbox_controller_unregister(&pdcs->mbc);
1609
1610 dma_pool_destroy(pdcs->rx_buf_pool);
1611 dma_pool_destroy(pdcs->ring_pool);
1612 return 0;
1613}
1614
1615static const struct of_device_id pdc_mbox_of_match[] = {
1616 {.compatible = "brcm,iproc-pdc-mbox"},
1617 { /* sentinel */ }
1618};
1619MODULE_DEVICE_TABLE(of, pdc_mbox_of_match);
1620
1621static struct platform_driver pdc_mbox_driver = {
1622 .probe = pdc_probe,
1623 .remove = pdc_remove,
1624 .driver = {
1625 .name = "brcm-iproc-pdc-mbox",
1626 .of_match_table = of_match_ptr(pdc_mbox_of_match),
1627 },
1628};
1629module_platform_driver(pdc_mbox_driver);
1630
1631MODULE_AUTHOR("Rob Rice <rob.rice@broadcom.com>");
1632MODULE_DESCRIPTION("Broadcom PDC mailbox driver");
1633MODULE_LICENSE("GPL v2");