source: rtems-libbsd/linux/drivers/net/ethernet/freescale/dpaa/dpaa_eth.h @ 28ee86a

55-freebsd-126-freebsd-12
Last change on this file since 28ee86a was 28ee86a, checked in by Sebastian Huber <sebastian.huber@…>, on 04/27/16 at 09:58:19

Import DPAA driver snapshot

Imported from Freescale Linux repository

git://git.freescale.com/ppc/upstream/linux.git

commit 2774c204cd8bfc56a200ff4dcdfc9cdf5b6fc161.

Linux compatibility layer is partly from FreeBSD.

  • Property mode set to 100644
File size: 14.8 KB
Line 
1/* Copyright 2008 - 2015 Freescale Semiconductor Inc.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5 *     * Redistributions of source code must retain the above copyright
6 *       notice, this list of conditions and the following disclaimer.
7 *     * Redistributions in binary form must reproduce the above copyright
8 *       notice, this list of conditions and the following disclaimer in the
9 *       documentation and/or other materials provided with the distribution.
10 *     * Neither the name of Freescale Semiconductor nor the
11 *       names of its contributors may be used to endorse or promote products
12 *       derived from this software without specific prior written permission.
13 *
14 * ALTERNATIVELY, this software may be distributed under the terms of the
15 * GNU General Public License ("GPL") as published by the Free Software
16 * Foundation, either version 2 of that License or (at your option) any
17 * later version.
18 *
19 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef __DPA_H
32#define __DPA_H
33
34#include <linux/netdevice.h>
35#include <soc/fsl/qman.h>
36
37#include "fman.h"
38#include "mac.h"
39#include "dpaa_eth_trace.h"
40
41#ifndef __rtems__
42extern int dpa_rx_extra_headroom;
43extern int dpa_max_frm;
44
45#define dpa_get_rx_extra_headroom() dpa_rx_extra_headroom
46#define dpa_get_max_frm() dpa_max_frm
47#else /* __rtems__ */
48#define dpa_get_rx_extra_headroom fman_get_rx_extra_headroom
49#define dpa_get_max_frm fman_get_max_frm
50#endif /* __rtems__ */
51
52#define dpa_get_max_mtu()       \
53        (dpa_get_max_frm() - (VLAN_ETH_HLEN + ETH_FCS_LEN))
54
55/* Simple enum of FQ types - used for array indexing */
56enum port_type {RX, TX};
57
58struct dpa_buffer_layout_s {
59        u16 priv_data_size;
60        bool parse_results;
61        bool time_stamp;
62        bool hash_results;
63        u16 data_align;
64};
65
66#define DPA_ERR_ON(cond)
67
68#define DPA_TX_PRIV_DATA_SIZE   16
69#define DPA_PARSE_RESULTS_SIZE sizeof(struct fman_prs_result)
70#define DPA_TIME_STAMP_SIZE 8
71#define DPA_HASH_RESULTS_SIZE 8
72#define DPA_RX_PRIV_DATA_SIZE   (DPA_TX_PRIV_DATA_SIZE + \
73                                        dpa_get_rx_extra_headroom())
74
75#define FM_FD_STAT_RX_ERRORS                                            \
76        (FM_FD_ERR_DMA | FM_FD_ERR_PHYSICAL     | \
77         FM_FD_ERR_SIZE | FM_FD_ERR_CLS_DISCARD | \
78         FM_FD_ERR_EXTRACTION | FM_FD_ERR_NO_SCHEME     | \
79         FM_FD_ERR_PRS_TIMEOUT | FM_FD_ERR_PRS_ILL_INSTRUCT | \
80         FM_FD_ERR_PRS_HDR_ERR)
81
82#define FM_FD_STAT_TX_ERRORS \
83        (FM_FD_ERR_UNSUPPORTED_FORMAT | \
84         FM_FD_ERR_LENGTH | FM_FD_ERR_DMA)
85
86/* The raw buffer size must be cacheline aligned.
87 * Normally we use 2K buffers.
88 */
89#define DPA_BP_RAW_SIZE         2048
90
91/* This is what FMan is ever allowed to use.
92 * FMan-DMA requires 16-byte alignment for Rx buffers, but SKB_DATA_ALIGN is
93 * even stronger (SMP_CACHE_BYTES-aligned), so we just get away with that,
94 * via SKB_WITH_OVERHEAD(). We can't rely on netdev_alloc_frag() giving us
95 * half-page-aligned buffers (can we?), so we reserve some more space
96 * for start-of-buffer alignment.
97 */
98#ifndef __rtems__
99#define dpa_bp_size(buffer_layout)      (SKB_WITH_OVERHEAD(DPA_BP_RAW_SIZE) - \
100                                                SMP_CACHE_BYTES)
101#else /* __rtems__ */
102/*
103 * FIXME: 4 bytes would be enough for the mbuf pointer.  However, jumbo receive
104 * frames overwrite this area if < 64 bytes.
105 */
106#define DPA_OUT_OF_BAND_SIZE 64
107#define DPA_MBUF_POINTER_OFFSET (DPA_BP_RAW_SIZE - DPA_OUT_OF_BAND_SIZE)
108#define dpa_bp_size(buffer_layout) DPA_MBUF_POINTER_OFFSET
109#endif /* __rtems__ */
110/* We must ensure that skb_shinfo is always cacheline-aligned. */
111#define DPA_SKB_SIZE(size)      ((size) & ~(SMP_CACHE_BYTES - 1))
112
113/* Largest value that the FQD's OAL field can hold.
114 * This is DPAA-1.x specific.
115 */
116#define FSL_QMAN_MAX_OAL        127
117
118/* Default alignment for start of data in an Rx FD */
119#define DPA_FD_DATA_ALIGNMENT  16
120
121/* Values for the L3R field of the FM Parse Results
122 */
123/* L3 Type field: First IP Present IPv4 */
124#define FM_L3_PARSE_RESULT_IPV4 0x8000
125/* L3 Type field: First IP Present IPv6 */
126#define FM_L3_PARSE_RESULT_IPV6 0x4000
127
128/* Values for the L4R field of the FM Parse Results
129 * See $8.8.4.7.20 - L4 HXS - L4 Results from DPAA-Rev2 Reference Manual.
130 */
131/* L4 Type field: UDP */
132#define FM_L4_PARSE_RESULT_UDP  0x40
133/* L4 Type field: TCP */
134#define FM_L4_PARSE_RESULT_TCP  0x20
135
136/* number of Tx queues to FMan */
137#define DPAA_ETH_TX_QUEUES      NR_CPUS
138
139#define DPAA_ETH_RX_QUEUES      128
140
141#define FSL_DPAA_ETH_MAX_BUF_COUNT      128
142#define FSL_DPAA_ETH_REFILL_THRESHOLD   80
143
144/* More detailed FQ types - used for fine-grained WQ assignments */
145enum dpa_fq_type {
146        FQ_TYPE_RX_DEFAULT = 1, /* Rx Default FQs */
147        FQ_TYPE_RX_ERROR,       /* Rx Error FQs */
148        FQ_TYPE_RX_PCD,         /* User-defined PCDs */
149        FQ_TYPE_TX,             /* "Real" Tx FQs */
150        FQ_TYPE_TX_CONFIRM,     /* Tx default Conf FQ (actually an Rx FQ) */
151        FQ_TYPE_TX_CONF_MQ,     /* Tx conf FQs (one for each Tx FQ) */
152        FQ_TYPE_TX_ERROR,       /* Tx Error FQs (these are actually Rx FQs) */
153};
154
155struct dpa_fq {
156        struct qman_fq fq_base;
157        struct list_head list;
158        struct net_device *net_dev;
159        bool init;
160        u32 fqid;
161        u32 flags;
162        u16 channel;
163        u8 wq;
164        enum dpa_fq_type fq_type;
165};
166
167struct dpa_fq_cbs_t {
168        struct qman_fq rx_defq;
169        struct qman_fq tx_defq;
170        struct qman_fq rx_errq;
171        struct qman_fq tx_errq;
172        struct qman_fq egress_ern;
173};
174
175struct fqid_cell {
176        u32 start;
177        u32 count;
178};
179
180struct dpa_bp {
181        struct bman_pool *pool;
182        u8 bpid;
183#ifndef __rtems__
184        struct device *dev;
185#endif /* __rtems__ */
186        /* the buffer pools used for the private ports are initialized
187         * with config_count buffers for each CPU; at runtime the
188         * number of buffers per CPU is constantly brought back to this
189         * level
190         */
191        int config_count;
192        size_t size;
193        bool seed_pool;
194        /* physical address of the contiguous memory used by the pool to store
195         * the buffers
196         */
197        dma_addr_t paddr;
198        /* virtual address of the contiguous memory used by the pool to store
199         * the buffers
200         */
201        void __iomem *vaddr;
202        /* current number of buffers in the bpool alloted to this CPU */
203        int __percpu *percpu_count;
204        atomic_t refs;
205        /* some bpools need to be seeded before use by this cb */
206        int (*seed_cb)(struct dpa_bp *);
207        /* some bpools need to be emptied before freeing; this cb is used
208         * for freeing of individual buffers taken from the pool
209         */
210        void (*free_buf_cb)(void *addr);
211};
212
213struct dpa_rx_errors {
214        u64 dme;                /* DMA Error */
215        u64 fpe;                /* Frame Physical Error */
216        u64 fse;                /* Frame Size Error */
217        u64 phe;                /* Header Error */
218};
219
220/* Counters for QMan ERN frames - one counter per rejection code */
221struct dpa_ern_cnt {
222        u64 cg_tdrop;           /* Congestion group taildrop */
223        u64 wred;               /* WRED congestion */
224        u64 err_cond;           /* Error condition */
225        u64 early_window;       /* Order restoration, frame too early */
226        u64 late_window;        /* Order restoration, frame too late */
227        u64 fq_tdrop;           /* FQ taildrop */
228        u64 fq_retired;         /* FQ is retired */
229        u64 orp_zero;           /* ORP disabled */
230};
231
232struct dpa_napi_portal {
233#ifndef __rtems__
234        struct napi_struct napi;
235#endif /* __rtems__ */
236        struct qman_portal *p;
237};
238
239struct dpa_percpu_priv_s {
240        struct net_device *net_dev;
241        struct dpa_napi_portal *np;
242        u64 in_interrupt;
243        u64 tx_confirm;
244        /* fragmented (non-linear) skbuffs received from the stack */
245        u64 tx_frag_skbuffs;
246#ifndef __rtems__
247        struct rtnl_link_stats64 stats;
248#endif /* __rtems__ */
249        struct dpa_rx_errors rx_errors;
250        struct dpa_ern_cnt ern_cnt;
251};
252
253struct dpa_priv_s {
254        struct dpa_percpu_priv_s __percpu *percpu_priv;
255        struct dpa_bp *dpa_bp;
256        /* Store here the needed Tx headroom for convenience and speed
257         * (even though it can be computed based on the fields of buf_layout)
258         */
259        u16 tx_headroom;
260        struct net_device *net_dev;
261        struct mac_device *mac_dev;
262        struct qman_fq *egress_fqs[DPAA_ETH_TX_QUEUES];
263        struct qman_fq *conf_fqs[DPAA_ETH_TX_QUEUES];
264
265        size_t bp_count;
266
267        u16 channel;    /* "fsl,qman-channel-id" */
268        struct list_head dpa_fq_list;
269
270#ifndef __rtems__
271        u32 msg_enable; /* net_device message level */
272#endif /* __rtems__ */
273
274        struct {
275                /* All egress queues to a given net device belong to one
276                 * (and the same) congestion group.
277                 */
278                struct qman_cgr cgr;
279                /* If congested, when it began. Used for performance stats. */
280                u32 congestion_start_jiffies;
281                /* Number of jiffies the Tx port was congested. */
282                u32 congested_jiffies;
283                /* Counter for the number of times the CGR
284                 * entered congestion state
285                 */
286                u32 cgr_congested_count;
287        } cgr_data;
288        /* Use a per-port CGR for ingress traffic. */
289        bool use_ingress_cgr;
290        struct qman_cgr ingress_cgr;
291
292        struct dpa_buffer_layout_s *buf_layout;
293        u16 rx_headroom;
294};
295
296struct fm_port_fqs {
297        struct dpa_fq *tx_defq;
298        struct dpa_fq *tx_errq;
299        struct dpa_fq *rx_defq;
300        struct dpa_fq *rx_errq;
301};
302
303int dpa_bp_priv_seed(struct dpa_bp *dpa_bp);
304int dpaa_eth_refill_bpools(struct dpa_bp *dpa_bp, int *count_ptr);
305void _dpa_rx(struct net_device *net_dev,
306             struct qman_portal *portal,
307             const struct dpa_priv_s *priv,
308             struct dpa_percpu_priv_s *percpu_priv,
309             const struct qm_fd *fd,
310             u32 fqid,
311             int *count_ptr);
312#ifndef __rtems__
313int dpa_tx(struct sk_buff *skb, struct net_device *net_dev);
314struct sk_buff *_dpa_cleanup_tx_fd(const struct dpa_priv_s *priv,
315                                   const struct qm_fd *fd);
316
317/* Turn on HW checksum computation for this outgoing frame.
318 * If the current protocol is not something we support in this regard
319 * (or if the stack has already computed the SW checksum), we do nothing.
320 *
321 * Returns 0 if all goes well (or HW csum doesn't apply), and a negative value
322 * otherwise.
323 *
324 * Note that this function may modify the fd->cmd field and the skb data buffer
325 * (the Parse Results area).
326 */
327int dpa_enable_tx_csum(struct dpa_priv_s *priv, struct sk_buff *skb,
328                       struct qm_fd *fd, char *parse_results);
329#else /* __rtems__ */
330void _dpa_cleanup_tx_fd(struct ifnet *ifp, const struct qm_fd *fd);
331#endif /* __rtems__ */
332
333static inline int dpaa_eth_napi_schedule(struct dpa_percpu_priv_s *percpu_priv,
334                                         struct qman_portal *portal)
335{
336#ifndef __rtems__
337        /* In case of threaded ISR for RT enable kernel,
338         * in_irq() does not return appropriate value, so use
339         * in_serving_softirq to distinguish softirq or irq context.
340         */
341        if (unlikely(in_irq() || !in_serving_softirq())) {
342                /* Disable QMan IRQ and invoke NAPI */
343                int ret = qman_p_irqsource_remove(portal, QM_PIRQ_DQRI);
344
345                if (likely(!ret)) {
346                        const struct qman_portal_config *pc =
347                                        qman_p_get_portal_config(portal);
348                        struct dpa_napi_portal *np =
349                                        &percpu_priv->np[pc->channel];
350
351                        np->p = portal;
352                        napi_schedule(&np->napi);
353                        percpu_priv->in_interrupt++;
354                        return 1;
355                }
356        }
357#else /* __rtems__ */
358        /* FIXME */
359#endif /* __rtems__ */
360        return 0;
361}
362
363static inline ssize_t __const dpa_fd_length(const struct qm_fd *fd)
364{
365        return fd->length20;
366}
367
368static inline ssize_t __const dpa_fd_offset(const struct qm_fd *fd)
369{
370        return fd->offset;
371}
372
373#ifndef __rtems__
374/* Verifies if the skb length is below the interface MTU */
375static inline int dpa_check_rx_mtu(struct sk_buff *skb, int mtu)
376{
377        if (unlikely(skb->len > mtu))
378                if ((skb->protocol != htons(ETH_P_8021Q)) ||
379                    (skb->len > mtu + 4))
380                        return -1;
381
382        return 0;
383}
384#endif /* __rtems__ */
385
386static inline u16 dpa_get_headroom(struct dpa_buffer_layout_s *bl)
387{
388        u16 headroom;
389        /* The frame headroom must accommodate:
390         * - the driver private data area
391         * - parse results, hash results, timestamp if selected
392         * If either hash results or time stamp are selected, both will
393         * be copied to/from the frame headroom, as TS is located between PR and
394         * HR in the IC and IC copy size has a granularity of 16bytes
395         * (see description of FMBM_RICP and FMBM_TICP registers in DPAARM)
396         *
397         * Also make sure the headroom is a multiple of data_align bytes
398         */
399        headroom = (u16)(bl->priv_data_size +
400                   (bl->parse_results ? DPA_PARSE_RESULTS_SIZE : 0) +
401                   (bl->hash_results || bl->time_stamp ?
402                    DPA_TIME_STAMP_SIZE + DPA_HASH_RESULTS_SIZE : 0));
403
404        return bl->data_align ? ALIGN(headroom, bl->data_align) : headroom;
405}
406
407#ifndef __rtems__
408void dpaa_eth_sysfs_remove(struct device *dev);
409void dpaa_eth_sysfs_init(struct device *dev);
410
411void dpa_private_napi_del(struct net_device *net_dev);
412#endif /* __rtems__ */
413
414static inline void clear_fd(struct qm_fd *fd)
415{
416        fd->opaque_addr = 0;
417        fd->opaque = 0;
418        fd->cmd = 0;
419}
420
421static inline int _dpa_tx_fq_to_id(const struct dpa_priv_s *priv,
422                struct qman_fq *tx_fq)
423{
424        int i;
425
426        for (i = 0; i < DPAA_ETH_TX_QUEUES; i++)
427                if (priv->egress_fqs[i] == tx_fq)
428                        return i;
429
430        return -EINVAL;
431}
432
433#ifndef __rtems__
434static inline int dpa_xmit(struct dpa_priv_s *priv,
435                           struct rtnl_link_stats64 *percpu_stats,
436                           int queue,
437                           struct qm_fd *fd)
438{
439        int err, i;
440        struct qman_fq *egress_fq;
441
442        egress_fq = priv->egress_fqs[queue];
443        if (fd->bpid == 0xff)
444                fd->cmd |= qman_fq_fqid(priv->conf_fqs[queue]);
445
446        /* Trace this Tx fd */
447        trace_dpa_tx_fd(priv->net_dev, egress_fq, fd);
448
449        for (i = 0; i < 100000; i++) {
450                err = qman_enqueue(egress_fq, fd, 0);
451                if (err != -EBUSY)
452                        break;
453        }
454
455        if (unlikely(err < 0)) {
456                percpu_stats->tx_errors++;
457                percpu_stats->tx_fifo_errors++;
458                return err;
459        }
460
461        percpu_stats->tx_packets++;
462        percpu_stats->tx_bytes += dpa_fd_length(fd);
463
464        return 0;
465}
466#endif /* __rtems__ */
467
468/* Use multiple WQs for FQ assignment:
469 *      - Tx Confirmation queues go to WQ1.
470 *      - Rx Default and Tx queues go to WQ3 (no differentiation between
471 *        Rx and Tx traffic).
472 *      - Rx Error and Tx Error queues go to WQ2 (giving them a better chance
473 *        to be scheduled, in case there are many more FQs in WQ3).
474 * This ensures that Tx-confirmed buffers are timely released. In particular,
475 * it avoids congestion on the Tx Confirm FQs, which can pile up PFDRs if they
476 * are greatly outnumbered by other FQs in the system, while
477 * dequeue scheduling is round-robin.
478 */
479static inline void _dpa_assign_wq(struct dpa_fq *fq)
480{
481        switch (fq->fq_type) {
482        case FQ_TYPE_TX_CONFIRM:
483        case FQ_TYPE_TX_CONF_MQ:
484                fq->wq = 1;
485                break;
486        case FQ_TYPE_RX_DEFAULT:
487        case FQ_TYPE_TX:
488                fq->wq = 3;
489                break;
490        case FQ_TYPE_RX_ERROR:
491        case FQ_TYPE_TX_ERROR:
492                fq->wq = 2;
493                break;
494        default:
495                WARN(1, "Invalid FQ type %d for FQID %d!\n",
496                     fq->fq_type, fq->fqid);
497        }
498}
499
500#ifdef CONFIG_FSL_DPAA_ETH_USE_NDO_SELECT_QUEUE
501/* Use in lieu of skb_get_queue_mapping() */
502#define dpa_get_queue_mapping(skb) \
503        raw_smp_processor_id()
504#else
505/* Use the queue selected by XPS */
506#define dpa_get_queue_mapping(skb) \
507        skb_get_queue_mapping(skb)
508#endif
509
510static inline void _dpa_bp_free_pf(void *addr)
511{
512#ifndef __rtems__
513        put_page(virt_to_head_page(addr));
514#else /* __rtems__ */
515        BSD_ASSERT(0);
516#endif /* __rtems__ */
517}
518
519#endif  /* __DPA_H */
Note: See TracBrowser for help on using the repository browser.