Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Bestcomm FEC tasks driver
0004  *
0005  * Copyright (C) 2006-2007 Sylvain Munaut <tnt@246tNt.com>
0006  * Copyright (C) 2003-2004 MontaVista, Software, Inc.
0007  *                         ( by Dale Farnsworth <dfarnsworth@mvista.com> )
0008  */
0009 
0010 #include <linux/kernel.h>
0011 #include <linux/module.h>
0012 #include <linux/types.h>
0013 #include <asm/io.h>
0014 
0015 #include <linux/fsl/bestcomm/bestcomm.h>
0016 #include <linux/fsl/bestcomm/bestcomm_priv.h>
0017 #include <linux/fsl/bestcomm/fec.h>
0018 
0019 
0020 /* ======================================================================== */
0021 /* Task image/var/inc                                                       */
0022 /* ======================================================================== */
0023 
0024 /* fec tasks images */
0025 extern u32 bcom_fec_rx_task[];
0026 extern u32 bcom_fec_tx_task[];
0027 
0028 /* rx task vars that need to be set before enabling the task */
0029 struct bcom_fec_rx_var {
0030     u32 enable;     /* (u16*) address of task's control register */
0031     u32 fifo;       /* (u32*) address of fec's fifo */
0032     u32 bd_base;        /* (struct bcom_bd*) beginning of ring buffer */
0033     u32 bd_last;        /* (struct bcom_bd*) end of ring buffer */
0034     u32 bd_start;       /* (struct bcom_bd*) current bd */
0035     u32 buffer_size;    /* size of receive buffer */
0036 };
0037 
0038 /* rx task incs that need to be set before enabling the task */
0039 struct bcom_fec_rx_inc {
0040     u16 pad0;
0041     s16 incr_bytes;
0042     u16 pad1;
0043     s16 incr_dst;
0044     u16 pad2;
0045     s16 incr_dst_ma;
0046 };
0047 
0048 /* tx task vars that need to be set before enabling the task */
0049 struct bcom_fec_tx_var {
0050     u32 DRD;        /* (u32*) address of self-modified DRD */
0051     u32 fifo;       /* (u32*) address of fec's fifo */
0052     u32 enable;     /* (u16*) address of task's control register */
0053     u32 bd_base;        /* (struct bcom_bd*) beginning of ring buffer */
0054     u32 bd_last;        /* (struct bcom_bd*) end of ring buffer */
0055     u32 bd_start;       /* (struct bcom_bd*) current bd */
0056     u32 buffer_size;    /* set by uCode for each packet */
0057 };
0058 
0059 /* tx task incs that need to be set before enabling the task */
0060 struct bcom_fec_tx_inc {
0061     u16 pad0;
0062     s16 incr_bytes;
0063     u16 pad1;
0064     s16 incr_src;
0065     u16 pad2;
0066     s16 incr_src_ma;
0067 };
0068 
0069 /* private structure in the task */
0070 struct bcom_fec_priv {
0071     phys_addr_t fifo;
0072     int     maxbufsize;
0073 };
0074 
0075 
0076 /* ======================================================================== */
0077 /* Task support code                                                        */
0078 /* ======================================================================== */
0079 
0080 struct bcom_task *
0081 bcom_fec_rx_init(int queue_len, phys_addr_t fifo, int maxbufsize)
0082 {
0083     struct bcom_task *tsk;
0084     struct bcom_fec_priv *priv;
0085 
0086     tsk = bcom_task_alloc(queue_len, sizeof(struct bcom_fec_bd),
0087                 sizeof(struct bcom_fec_priv));
0088     if (!tsk)
0089         return NULL;
0090 
0091     tsk->flags = BCOM_FLAGS_NONE;
0092 
0093     priv = tsk->priv;
0094     priv->fifo = fifo;
0095     priv->maxbufsize = maxbufsize;
0096 
0097     if (bcom_fec_rx_reset(tsk)) {
0098         bcom_task_free(tsk);
0099         return NULL;
0100     }
0101 
0102     return tsk;
0103 }
0104 EXPORT_SYMBOL_GPL(bcom_fec_rx_init);
0105 
0106 int
0107 bcom_fec_rx_reset(struct bcom_task *tsk)
0108 {
0109     struct bcom_fec_priv *priv = tsk->priv;
0110     struct bcom_fec_rx_var *var;
0111     struct bcom_fec_rx_inc *inc;
0112 
0113     /* Shutdown the task */
0114     bcom_disable_task(tsk->tasknum);
0115 
0116     /* Reset the microcode */
0117     var = (struct bcom_fec_rx_var *) bcom_task_var(tsk->tasknum);
0118     inc = (struct bcom_fec_rx_inc *) bcom_task_inc(tsk->tasknum);
0119 
0120     if (bcom_load_image(tsk->tasknum, bcom_fec_rx_task))
0121         return -1;
0122 
0123     var->enable = bcom_eng->regs_base +
0124                 offsetof(struct mpc52xx_sdma, tcr[tsk->tasknum]);
0125     var->fifo   = (u32) priv->fifo;
0126     var->bd_base    = tsk->bd_pa;
0127     var->bd_last    = tsk->bd_pa + ((tsk->num_bd-1) * tsk->bd_size);
0128     var->bd_start   = tsk->bd_pa;
0129     var->buffer_size = priv->maxbufsize;
0130 
0131     inc->incr_bytes = -(s16)sizeof(u32);    /* These should be in the   */
0132     inc->incr_dst   = sizeof(u32);      /* task image, but we stick */
0133     inc->incr_dst_ma= sizeof(u8);       /* to the official ones     */
0134 
0135     /* Reset the BDs */
0136     tsk->index = 0;
0137     tsk->outdex = 0;
0138 
0139     memset_io(tsk->bd, 0x00, tsk->num_bd * tsk->bd_size);
0140 
0141     /* Configure some stuff */
0142     bcom_set_task_pragma(tsk->tasknum, BCOM_FEC_RX_BD_PRAGMA);
0143     bcom_set_task_auto_start(tsk->tasknum, tsk->tasknum);
0144 
0145     out_8(&bcom_eng->regs->ipr[BCOM_INITIATOR_FEC_RX], BCOM_IPR_FEC_RX);
0146 
0147     out_be32(&bcom_eng->regs->IntPend, 1<<tsk->tasknum);    /* Clear ints */
0148 
0149     return 0;
0150 }
0151 EXPORT_SYMBOL_GPL(bcom_fec_rx_reset);
0152 
0153 void
0154 bcom_fec_rx_release(struct bcom_task *tsk)
0155 {
0156     /* Nothing special for the FEC tasks */
0157     bcom_task_free(tsk);
0158 }
0159 EXPORT_SYMBOL_GPL(bcom_fec_rx_release);
0160 
0161 
0162 
0163     /* Return 2nd to last DRD */
0164     /* This is an ugly hack, but at least it's only done
0165        once at initialization */
0166 static u32 *self_modified_drd(int tasknum)
0167 {
0168     u32 *desc;
0169     int num_descs;
0170     int drd_count;
0171     int i;
0172 
0173     num_descs = bcom_task_num_descs(tasknum);
0174     desc = bcom_task_desc(tasknum) + num_descs - 1;
0175     drd_count = 0;
0176     for (i=0; i<num_descs; i++, desc--)
0177         if (bcom_desc_is_drd(*desc) && ++drd_count == 3)
0178             break;
0179     return desc;
0180 }
0181 
0182 struct bcom_task *
0183 bcom_fec_tx_init(int queue_len, phys_addr_t fifo)
0184 {
0185     struct bcom_task *tsk;
0186     struct bcom_fec_priv *priv;
0187 
0188     tsk = bcom_task_alloc(queue_len, sizeof(struct bcom_fec_bd),
0189                 sizeof(struct bcom_fec_priv));
0190     if (!tsk)
0191         return NULL;
0192 
0193     tsk->flags = BCOM_FLAGS_ENABLE_TASK;
0194 
0195     priv = tsk->priv;
0196     priv->fifo = fifo;
0197 
0198     if (bcom_fec_tx_reset(tsk)) {
0199         bcom_task_free(tsk);
0200         return NULL;
0201     }
0202 
0203     return tsk;
0204 }
0205 EXPORT_SYMBOL_GPL(bcom_fec_tx_init);
0206 
0207 int
0208 bcom_fec_tx_reset(struct bcom_task *tsk)
0209 {
0210     struct bcom_fec_priv *priv = tsk->priv;
0211     struct bcom_fec_tx_var *var;
0212     struct bcom_fec_tx_inc *inc;
0213 
0214     /* Shutdown the task */
0215     bcom_disable_task(tsk->tasknum);
0216 
0217     /* Reset the microcode */
0218     var = (struct bcom_fec_tx_var *) bcom_task_var(tsk->tasknum);
0219     inc = (struct bcom_fec_tx_inc *) bcom_task_inc(tsk->tasknum);
0220 
0221     if (bcom_load_image(tsk->tasknum, bcom_fec_tx_task))
0222         return -1;
0223 
0224     var->enable = bcom_eng->regs_base +
0225                 offsetof(struct mpc52xx_sdma, tcr[tsk->tasknum]);
0226     var->fifo   = (u32) priv->fifo;
0227     var->DRD    = bcom_sram_va2pa(self_modified_drd(tsk->tasknum));
0228     var->bd_base    = tsk->bd_pa;
0229     var->bd_last    = tsk->bd_pa + ((tsk->num_bd-1) * tsk->bd_size);
0230     var->bd_start   = tsk->bd_pa;
0231 
0232     inc->incr_bytes = -(s16)sizeof(u32);    /* These should be in the   */
0233     inc->incr_src   = sizeof(u32);      /* task image, but we stick */
0234     inc->incr_src_ma= sizeof(u8);       /* to the official ones     */
0235 
0236     /* Reset the BDs */
0237     tsk->index = 0;
0238     tsk->outdex = 0;
0239 
0240     memset_io(tsk->bd, 0x00, tsk->num_bd * tsk->bd_size);
0241 
0242     /* Configure some stuff */
0243     bcom_set_task_pragma(tsk->tasknum, BCOM_FEC_TX_BD_PRAGMA);
0244     bcom_set_task_auto_start(tsk->tasknum, tsk->tasknum);
0245 
0246     out_8(&bcom_eng->regs->ipr[BCOM_INITIATOR_FEC_TX], BCOM_IPR_FEC_TX);
0247 
0248     out_be32(&bcom_eng->regs->IntPend, 1<<tsk->tasknum);    /* Clear ints */
0249 
0250     return 0;
0251 }
0252 EXPORT_SYMBOL_GPL(bcom_fec_tx_reset);
0253 
0254 void
0255 bcom_fec_tx_release(struct bcom_task *tsk)
0256 {
0257     /* Nothing special for the FEC tasks */
0258     bcom_task_free(tsk);
0259 }
0260 EXPORT_SYMBOL_GPL(bcom_fec_tx_release);
0261 
0262 
0263 MODULE_DESCRIPTION("BestComm FEC tasks driver");
0264 MODULE_AUTHOR("Dale Farnsworth <dfarnsworth@mvista.com>");
0265 MODULE_LICENSE("GPL v2");