Loading...
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Xilinx SDFEC
4 *
5 * Copyright (C) 2019 Xilinx, Inc.
6 *
7 * Description:
8 * This driver is developed for SDFEC16 (Soft Decision FEC 16nm)
9 * IP. It exposes a char device which supports file operations
10 * like open(), close() and ioctl().
11 */
12
13#include <linux/miscdevice.h>
14#include <linux/io.h>
15#include <linux/interrupt.h>
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/of.h>
19#include <linux/platform_device.h>
20#include <linux/poll.h>
21#include <linux/slab.h>
22#include <linux/clk.h>
23#include <linux/compat.h>
24#include <linux/highmem.h>
25
26#include <uapi/misc/xilinx_sdfec.h>
27
28#define DEV_NAME_LEN 12
29
30static DEFINE_IDA(dev_nrs);
31
32/* Xilinx SDFEC Register Map */
33/* CODE_WRI_PROTECT Register */
34#define XSDFEC_CODE_WR_PROTECT_ADDR (0x4)
35
36/* ACTIVE Register */
37#define XSDFEC_ACTIVE_ADDR (0x8)
38#define XSDFEC_IS_ACTIVITY_SET (0x1)
39
40/* AXIS_WIDTH Register */
41#define XSDFEC_AXIS_WIDTH_ADDR (0xC)
42#define XSDFEC_AXIS_DOUT_WORDS_LSB (5)
43#define XSDFEC_AXIS_DOUT_WIDTH_LSB (3)
44#define XSDFEC_AXIS_DIN_WORDS_LSB (2)
45#define XSDFEC_AXIS_DIN_WIDTH_LSB (0)
46
47/* AXIS_ENABLE Register */
48#define XSDFEC_AXIS_ENABLE_ADDR (0x10)
49#define XSDFEC_AXIS_OUT_ENABLE_MASK (0x38)
50#define XSDFEC_AXIS_IN_ENABLE_MASK (0x7)
51#define XSDFEC_AXIS_ENABLE_MASK \
52 (XSDFEC_AXIS_OUT_ENABLE_MASK | XSDFEC_AXIS_IN_ENABLE_MASK)
53
54/* FEC_CODE Register */
55#define XSDFEC_FEC_CODE_ADDR (0x14)
56
57/* ORDER Register Map */
58#define XSDFEC_ORDER_ADDR (0x18)
59
60/* Interrupt Status Register */
61#define XSDFEC_ISR_ADDR (0x1C)
62/* Interrupt Status Register Bit Mask */
63#define XSDFEC_ISR_MASK (0x3F)
64
65/* Write Only - Interrupt Enable Register */
66#define XSDFEC_IER_ADDR (0x20)
67/* Write Only - Interrupt Disable Register */
68#define XSDFEC_IDR_ADDR (0x24)
69/* Read Only - Interrupt Mask Register */
70#define XSDFEC_IMR_ADDR (0x28)
71
72/* ECC Interrupt Status Register */
73#define XSDFEC_ECC_ISR_ADDR (0x2C)
74/* Single Bit Errors */
75#define XSDFEC_ECC_ISR_SBE_MASK (0x7FF)
76/* PL Initialize Single Bit Errors */
77#define XSDFEC_PL_INIT_ECC_ISR_SBE_MASK (0x3C00000)
78/* Multi Bit Errors */
79#define XSDFEC_ECC_ISR_MBE_MASK (0x3FF800)
80/* PL Initialize Multi Bit Errors */
81#define XSDFEC_PL_INIT_ECC_ISR_MBE_MASK (0x3C000000)
82/* Multi Bit Error to Event Shift */
83#define XSDFEC_ECC_ISR_MBE_TO_EVENT_SHIFT (11)
84/* PL Initialize Multi Bit Error to Event Shift */
85#define XSDFEC_PL_INIT_ECC_ISR_MBE_TO_EVENT_SHIFT (4)
86/* ECC Interrupt Status Bit Mask */
87#define XSDFEC_ECC_ISR_MASK (XSDFEC_ECC_ISR_SBE_MASK | XSDFEC_ECC_ISR_MBE_MASK)
88/* ECC Interrupt Status PL Initialize Bit Mask */
89#define XSDFEC_PL_INIT_ECC_ISR_MASK \
90 (XSDFEC_PL_INIT_ECC_ISR_SBE_MASK | XSDFEC_PL_INIT_ECC_ISR_MBE_MASK)
91/* ECC Interrupt Status All Bit Mask */
92#define XSDFEC_ALL_ECC_ISR_MASK \
93 (XSDFEC_ECC_ISR_MASK | XSDFEC_PL_INIT_ECC_ISR_MASK)
94/* ECC Interrupt Status Single Bit Errors Mask */
95#define XSDFEC_ALL_ECC_ISR_SBE_MASK \
96 (XSDFEC_ECC_ISR_SBE_MASK | XSDFEC_PL_INIT_ECC_ISR_SBE_MASK)
97/* ECC Interrupt Status Multi Bit Errors Mask */
98#define XSDFEC_ALL_ECC_ISR_MBE_MASK \
99 (XSDFEC_ECC_ISR_MBE_MASK | XSDFEC_PL_INIT_ECC_ISR_MBE_MASK)
100
101/* Write Only - ECC Interrupt Enable Register */
102#define XSDFEC_ECC_IER_ADDR (0x30)
103/* Write Only - ECC Interrupt Disable Register */
104#define XSDFEC_ECC_IDR_ADDR (0x34)
105/* Read Only - ECC Interrupt Mask Register */
106#define XSDFEC_ECC_IMR_ADDR (0x38)
107
108/* BYPASS Register */
109#define XSDFEC_BYPASS_ADDR (0x3C)
110
111/* Turbo Code Register */
112#define XSDFEC_TURBO_ADDR (0x100)
113#define XSDFEC_TURBO_SCALE_MASK (0xFFF)
114#define XSDFEC_TURBO_SCALE_BIT_POS (8)
115#define XSDFEC_TURBO_SCALE_MAX (15)
116
117/* REG0 Register */
118#define XSDFEC_LDPC_CODE_REG0_ADDR_BASE (0x2000)
119#define XSDFEC_LDPC_CODE_REG0_ADDR_HIGH (0x27F0)
120#define XSDFEC_REG0_N_MIN (4)
121#define XSDFEC_REG0_N_MAX (32768)
122#define XSDFEC_REG0_N_MUL_P (256)
123#define XSDFEC_REG0_N_LSB (0)
124#define XSDFEC_REG0_K_MIN (2)
125#define XSDFEC_REG0_K_MAX (32766)
126#define XSDFEC_REG0_K_MUL_P (256)
127#define XSDFEC_REG0_K_LSB (16)
128
129/* REG1 Register */
130#define XSDFEC_LDPC_CODE_REG1_ADDR_BASE (0x2004)
131#define XSDFEC_LDPC_CODE_REG1_ADDR_HIGH (0x27f4)
132#define XSDFEC_REG1_PSIZE_MIN (2)
133#define XSDFEC_REG1_PSIZE_MAX (512)
134#define XSDFEC_REG1_NO_PACKING_MASK (0x400)
135#define XSDFEC_REG1_NO_PACKING_LSB (10)
136#define XSDFEC_REG1_NM_MASK (0xFF800)
137#define XSDFEC_REG1_NM_LSB (11)
138#define XSDFEC_REG1_BYPASS_MASK (0x100000)
139
140/* REG2 Register */
141#define XSDFEC_LDPC_CODE_REG2_ADDR_BASE (0x2008)
142#define XSDFEC_LDPC_CODE_REG2_ADDR_HIGH (0x27f8)
143#define XSDFEC_REG2_NLAYERS_MIN (1)
144#define XSDFEC_REG2_NLAYERS_MAX (256)
145#define XSDFEC_REG2_NNMQC_MASK (0xFFE00)
146#define XSDFEC_REG2_NMQC_LSB (9)
147#define XSDFEC_REG2_NORM_TYPE_MASK (0x100000)
148#define XSDFEC_REG2_NORM_TYPE_LSB (20)
149#define XSDFEC_REG2_SPECIAL_QC_MASK (0x200000)
150#define XSDFEC_REG2_SPEICAL_QC_LSB (21)
151#define XSDFEC_REG2_NO_FINAL_PARITY_MASK (0x400000)
152#define XSDFEC_REG2_NO_FINAL_PARITY_LSB (22)
153#define XSDFEC_REG2_MAX_SCHEDULE_MASK (0x1800000)
154#define XSDFEC_REG2_MAX_SCHEDULE_LSB (23)
155
156/* REG3 Register */
157#define XSDFEC_LDPC_CODE_REG3_ADDR_BASE (0x200C)
158#define XSDFEC_LDPC_CODE_REG3_ADDR_HIGH (0x27FC)
159#define XSDFEC_REG3_LA_OFF_LSB (8)
160#define XSDFEC_REG3_QC_OFF_LSB (16)
161
162#define XSDFEC_LDPC_REG_JUMP (0x10)
163#define XSDFEC_REG_WIDTH_JUMP (4)
164
165/* The maximum number of pinned pages */
166#define MAX_NUM_PAGES ((XSDFEC_QC_TABLE_DEPTH / PAGE_SIZE) + 1)
167
168/**
169 * struct xsdfec_clks - For managing SD-FEC clocks
170 * @core_clk: Main processing clock for core
171 * @axi_clk: AXI4-Lite memory-mapped clock
172 * @din_words_clk: DIN Words AXI4-Stream Slave clock
173 * @din_clk: DIN AXI4-Stream Slave clock
174 * @dout_clk: DOUT Words AXI4-Stream Slave clock
175 * @dout_words_clk: DOUT AXI4-Stream Slave clock
176 * @ctrl_clk: Control AXI4-Stream Slave clock
177 * @status_clk: Status AXI4-Stream Slave clock
178 */
179struct xsdfec_clks {
180 struct clk *core_clk;
181 struct clk *axi_clk;
182 struct clk *din_words_clk;
183 struct clk *din_clk;
184 struct clk *dout_clk;
185 struct clk *dout_words_clk;
186 struct clk *ctrl_clk;
187 struct clk *status_clk;
188};
189
190/**
191 * struct xsdfec_dev - Driver data for SDFEC
192 * @miscdev: Misc device handle
193 * @clks: Clocks managed by the SDFEC driver
194 * @waitq: Driver wait queue
195 * @config: Configuration of the SDFEC device
196 * @dev_name: Device name
197 * @flags: spinlock flags
198 * @regs: device physical base address
199 * @dev: pointer to device struct
200 * @state: State of the SDFEC device
201 * @error_data_lock: Error counter and states spinlock
202 * @dev_id: Device ID
203 * @isr_err_count: Count of ISR errors
204 * @cecc_count: Count of Correctable ECC errors (SBE)
205 * @uecc_count: Count of Uncorrectable ECC errors (MBE)
206 * @irq: IRQ number
207 * @state_updated: indicates State updated by interrupt handler
208 * @stats_updated: indicates Stats updated by interrupt handler
209 * @intr_enabled: indicates IRQ enabled
210 *
211 * This structure contains necessary state for SDFEC driver to operate
212 */
213struct xsdfec_dev {
214 struct miscdevice miscdev;
215 struct xsdfec_clks clks;
216 wait_queue_head_t waitq;
217 struct xsdfec_config config;
218 char dev_name[DEV_NAME_LEN];
219 unsigned long flags;
220 void __iomem *regs;
221 struct device *dev;
222 enum xsdfec_state state;
223 /* Spinlock to protect state_updated and stats_updated */
224 spinlock_t error_data_lock;
225 int dev_id;
226 u32 isr_err_count;
227 u32 cecc_count;
228 u32 uecc_count;
229 int irq;
230 bool state_updated;
231 bool stats_updated;
232 bool intr_enabled;
233};
234
235static inline void xsdfec_regwrite(struct xsdfec_dev *xsdfec, u32 addr,
236 u32 value)
237{
238 dev_dbg(xsdfec->dev, "Writing 0x%x to offset 0x%x", value, addr);
239 iowrite32(value, xsdfec->regs + addr);
240}
241
242static inline u32 xsdfec_regread(struct xsdfec_dev *xsdfec, u32 addr)
243{
244 u32 rval;
245
246 rval = ioread32(xsdfec->regs + addr);
247 dev_dbg(xsdfec->dev, "Read value = 0x%x from offset 0x%x", rval, addr);
248 return rval;
249}
250
251static void update_bool_config_from_reg(struct xsdfec_dev *xsdfec,
252 u32 reg_offset, u32 bit_num,
253 char *config_value)
254{
255 u32 reg_val;
256 u32 bit_mask = 1 << bit_num;
257
258 reg_val = xsdfec_regread(xsdfec, reg_offset);
259 *config_value = (reg_val & bit_mask) > 0;
260}
261
262static void update_config_from_hw(struct xsdfec_dev *xsdfec)
263{
264 u32 reg_value;
265 bool sdfec_started;
266
267 /* Update the Order */
268 reg_value = xsdfec_regread(xsdfec, XSDFEC_ORDER_ADDR);
269 xsdfec->config.order = reg_value;
270
271 update_bool_config_from_reg(xsdfec, XSDFEC_BYPASS_ADDR,
272 0, /* Bit Number, maybe change to mask */
273 &xsdfec->config.bypass);
274
275 update_bool_config_from_reg(xsdfec, XSDFEC_CODE_WR_PROTECT_ADDR,
276 0, /* Bit Number */
277 &xsdfec->config.code_wr_protect);
278
279 reg_value = xsdfec_regread(xsdfec, XSDFEC_IMR_ADDR);
280 xsdfec->config.irq.enable_isr = (reg_value & XSDFEC_ISR_MASK) > 0;
281
282 reg_value = xsdfec_regread(xsdfec, XSDFEC_ECC_IMR_ADDR);
283 xsdfec->config.irq.enable_ecc_isr =
284 (reg_value & XSDFEC_ECC_ISR_MASK) > 0;
285
286 reg_value = xsdfec_regread(xsdfec, XSDFEC_AXIS_ENABLE_ADDR);
287 sdfec_started = (reg_value & XSDFEC_AXIS_IN_ENABLE_MASK) > 0;
288 if (sdfec_started)
289 xsdfec->state = XSDFEC_STARTED;
290 else
291 xsdfec->state = XSDFEC_STOPPED;
292}
293
294static int xsdfec_get_status(struct xsdfec_dev *xsdfec, void __user *arg)
295{
296 struct xsdfec_status status;
297 int err;
298
299 memset(&status, 0, sizeof(status));
300 spin_lock_irqsave(&xsdfec->error_data_lock, xsdfec->flags);
301 status.state = xsdfec->state;
302 xsdfec->state_updated = false;
303 spin_unlock_irqrestore(&xsdfec->error_data_lock, xsdfec->flags);
304 status.activity = (xsdfec_regread(xsdfec, XSDFEC_ACTIVE_ADDR) &
305 XSDFEC_IS_ACTIVITY_SET);
306
307 err = copy_to_user(arg, &status, sizeof(status));
308 if (err)
309 err = -EFAULT;
310
311 return err;
312}
313
314static int xsdfec_get_config(struct xsdfec_dev *xsdfec, void __user *arg)
315{
316 int err;
317
318 err = copy_to_user(arg, &xsdfec->config, sizeof(xsdfec->config));
319 if (err)
320 err = -EFAULT;
321
322 return err;
323}
324
325static int xsdfec_isr_enable(struct xsdfec_dev *xsdfec, bool enable)
326{
327 u32 mask_read;
328
329 if (enable) {
330 /* Enable */
331 xsdfec_regwrite(xsdfec, XSDFEC_IER_ADDR, XSDFEC_ISR_MASK);
332 mask_read = xsdfec_regread(xsdfec, XSDFEC_IMR_ADDR);
333 if (mask_read & XSDFEC_ISR_MASK) {
334 dev_dbg(xsdfec->dev,
335 "SDFEC enabling irq with IER failed");
336 return -EIO;
337 }
338 } else {
339 /* Disable */
340 xsdfec_regwrite(xsdfec, XSDFEC_IDR_ADDR, XSDFEC_ISR_MASK);
341 mask_read = xsdfec_regread(xsdfec, XSDFEC_IMR_ADDR);
342 if ((mask_read & XSDFEC_ISR_MASK) != XSDFEC_ISR_MASK) {
343 dev_dbg(xsdfec->dev,
344 "SDFEC disabling irq with IDR failed");
345 return -EIO;
346 }
347 }
348 return 0;
349}
350
351static int xsdfec_ecc_isr_enable(struct xsdfec_dev *xsdfec, bool enable)
352{
353 u32 mask_read;
354
355 if (enable) {
356 /* Enable */
357 xsdfec_regwrite(xsdfec, XSDFEC_ECC_IER_ADDR,
358 XSDFEC_ALL_ECC_ISR_MASK);
359 mask_read = xsdfec_regread(xsdfec, XSDFEC_ECC_IMR_ADDR);
360 if (mask_read & XSDFEC_ALL_ECC_ISR_MASK) {
361 dev_dbg(xsdfec->dev,
362 "SDFEC enabling ECC irq with ECC IER failed");
363 return -EIO;
364 }
365 } else {
366 /* Disable */
367 xsdfec_regwrite(xsdfec, XSDFEC_ECC_IDR_ADDR,
368 XSDFEC_ALL_ECC_ISR_MASK);
369 mask_read = xsdfec_regread(xsdfec, XSDFEC_ECC_IMR_ADDR);
370 if (!(((mask_read & XSDFEC_ALL_ECC_ISR_MASK) ==
371 XSDFEC_ECC_ISR_MASK) ||
372 ((mask_read & XSDFEC_ALL_ECC_ISR_MASK) ==
373 XSDFEC_PL_INIT_ECC_ISR_MASK))) {
374 dev_dbg(xsdfec->dev,
375 "SDFEC disable ECC irq with ECC IDR failed");
376 return -EIO;
377 }
378 }
379 return 0;
380}
381
382static int xsdfec_set_irq(struct xsdfec_dev *xsdfec, void __user *arg)
383{
384 struct xsdfec_irq irq;
385 int err;
386 int isr_err;
387 int ecc_err;
388
389 err = copy_from_user(&irq, arg, sizeof(irq));
390 if (err)
391 return -EFAULT;
392
393 /* Setup tlast related IRQ */
394 isr_err = xsdfec_isr_enable(xsdfec, irq.enable_isr);
395 if (!isr_err)
396 xsdfec->config.irq.enable_isr = irq.enable_isr;
397
398 /* Setup ECC related IRQ */
399 ecc_err = xsdfec_ecc_isr_enable(xsdfec, irq.enable_ecc_isr);
400 if (!ecc_err)
401 xsdfec->config.irq.enable_ecc_isr = irq.enable_ecc_isr;
402
403 if (isr_err < 0 || ecc_err < 0)
404 err = -EIO;
405
406 return err;
407}
408
409static int xsdfec_set_turbo(struct xsdfec_dev *xsdfec, void __user *arg)
410{
411 struct xsdfec_turbo turbo;
412 int err;
413 u32 turbo_write;
414
415 err = copy_from_user(&turbo, arg, sizeof(turbo));
416 if (err)
417 return -EFAULT;
418
419 if (turbo.alg >= XSDFEC_TURBO_ALG_MAX)
420 return -EINVAL;
421
422 if (turbo.scale > XSDFEC_TURBO_SCALE_MAX)
423 return -EINVAL;
424
425 /* Check to see what device tree says about the FEC codes */
426 if (xsdfec->config.code == XSDFEC_LDPC_CODE)
427 return -EIO;
428
429 turbo_write = ((turbo.scale & XSDFEC_TURBO_SCALE_MASK)
430 << XSDFEC_TURBO_SCALE_BIT_POS) |
431 turbo.alg;
432 xsdfec_regwrite(xsdfec, XSDFEC_TURBO_ADDR, turbo_write);
433 return err;
434}
435
436static int xsdfec_get_turbo(struct xsdfec_dev *xsdfec, void __user *arg)
437{
438 u32 reg_value;
439 struct xsdfec_turbo turbo_params;
440 int err;
441
442 if (xsdfec->config.code == XSDFEC_LDPC_CODE)
443 return -EIO;
444
445 memset(&turbo_params, 0, sizeof(turbo_params));
446 reg_value = xsdfec_regread(xsdfec, XSDFEC_TURBO_ADDR);
447
448 turbo_params.scale = (reg_value & XSDFEC_TURBO_SCALE_MASK) >>
449 XSDFEC_TURBO_SCALE_BIT_POS;
450 turbo_params.alg = reg_value & 0x1;
451
452 err = copy_to_user(arg, &turbo_params, sizeof(turbo_params));
453 if (err)
454 err = -EFAULT;
455
456 return err;
457}
458
459static int xsdfec_reg0_write(struct xsdfec_dev *xsdfec, u32 n, u32 k, u32 psize,
460 u32 offset)
461{
462 u32 wdata;
463
464 if (n < XSDFEC_REG0_N_MIN || n > XSDFEC_REG0_N_MAX || psize == 0 ||
465 (n > XSDFEC_REG0_N_MUL_P * psize) || n <= k || ((n % psize) != 0)) {
466 dev_dbg(xsdfec->dev, "N value is not in range");
467 return -EINVAL;
468 }
469 n <<= XSDFEC_REG0_N_LSB;
470
471 if (k < XSDFEC_REG0_K_MIN || k > XSDFEC_REG0_K_MAX ||
472 (k > XSDFEC_REG0_K_MUL_P * psize) || ((k % psize) != 0)) {
473 dev_dbg(xsdfec->dev, "K value is not in range");
474 return -EINVAL;
475 }
476 k = k << XSDFEC_REG0_K_LSB;
477 wdata = k | n;
478
479 if (XSDFEC_LDPC_CODE_REG0_ADDR_BASE + (offset * XSDFEC_LDPC_REG_JUMP) >
480 XSDFEC_LDPC_CODE_REG0_ADDR_HIGH) {
481 dev_dbg(xsdfec->dev, "Writing outside of LDPC reg0 space 0x%x",
482 XSDFEC_LDPC_CODE_REG0_ADDR_BASE +
483 (offset * XSDFEC_LDPC_REG_JUMP));
484 return -EINVAL;
485 }
486 xsdfec_regwrite(xsdfec,
487 XSDFEC_LDPC_CODE_REG0_ADDR_BASE +
488 (offset * XSDFEC_LDPC_REG_JUMP),
489 wdata);
490 return 0;
491}
492
493static int xsdfec_reg1_write(struct xsdfec_dev *xsdfec, u32 psize,
494 u32 no_packing, u32 nm, u32 offset)
495{
496 u32 wdata;
497
498 if (psize < XSDFEC_REG1_PSIZE_MIN || psize > XSDFEC_REG1_PSIZE_MAX) {
499 dev_dbg(xsdfec->dev, "Psize is not in range");
500 return -EINVAL;
501 }
502
503 if (no_packing != 0 && no_packing != 1)
504 dev_dbg(xsdfec->dev, "No-packing bit register invalid");
505 no_packing = ((no_packing << XSDFEC_REG1_NO_PACKING_LSB) &
506 XSDFEC_REG1_NO_PACKING_MASK);
507
508 if (nm & ~(XSDFEC_REG1_NM_MASK >> XSDFEC_REG1_NM_LSB))
509 dev_dbg(xsdfec->dev, "NM is beyond 10 bits");
510 nm = (nm << XSDFEC_REG1_NM_LSB) & XSDFEC_REG1_NM_MASK;
511
512 wdata = nm | no_packing | psize;
513 if (XSDFEC_LDPC_CODE_REG1_ADDR_BASE + (offset * XSDFEC_LDPC_REG_JUMP) >
514 XSDFEC_LDPC_CODE_REG1_ADDR_HIGH) {
515 dev_dbg(xsdfec->dev, "Writing outside of LDPC reg1 space 0x%x",
516 XSDFEC_LDPC_CODE_REG1_ADDR_BASE +
517 (offset * XSDFEC_LDPC_REG_JUMP));
518 return -EINVAL;
519 }
520 xsdfec_regwrite(xsdfec,
521 XSDFEC_LDPC_CODE_REG1_ADDR_BASE +
522 (offset * XSDFEC_LDPC_REG_JUMP),
523 wdata);
524 return 0;
525}
526
527static int xsdfec_reg2_write(struct xsdfec_dev *xsdfec, u32 nlayers, u32 nmqc,
528 u32 norm_type, u32 special_qc, u32 no_final_parity,
529 u32 max_schedule, u32 offset)
530{
531 u32 wdata;
532
533 if (nlayers < XSDFEC_REG2_NLAYERS_MIN ||
534 nlayers > XSDFEC_REG2_NLAYERS_MAX) {
535 dev_dbg(xsdfec->dev, "Nlayers is not in range");
536 return -EINVAL;
537 }
538
539 if (nmqc & ~(XSDFEC_REG2_NNMQC_MASK >> XSDFEC_REG2_NMQC_LSB))
540 dev_dbg(xsdfec->dev, "NMQC exceeds 11 bits");
541 nmqc = (nmqc << XSDFEC_REG2_NMQC_LSB) & XSDFEC_REG2_NNMQC_MASK;
542
543 if (norm_type > 1)
544 dev_dbg(xsdfec->dev, "Norm type is invalid");
545 norm_type = ((norm_type << XSDFEC_REG2_NORM_TYPE_LSB) &
546 XSDFEC_REG2_NORM_TYPE_MASK);
547 if (special_qc > 1)
548 dev_dbg(xsdfec->dev, "Special QC in invalid");
549 special_qc = ((special_qc << XSDFEC_REG2_SPEICAL_QC_LSB) &
550 XSDFEC_REG2_SPECIAL_QC_MASK);
551
552 if (no_final_parity > 1)
553 dev_dbg(xsdfec->dev, "No final parity check invalid");
554 no_final_parity =
555 ((no_final_parity << XSDFEC_REG2_NO_FINAL_PARITY_LSB) &
556 XSDFEC_REG2_NO_FINAL_PARITY_MASK);
557 if (max_schedule &
558 ~(XSDFEC_REG2_MAX_SCHEDULE_MASK >> XSDFEC_REG2_MAX_SCHEDULE_LSB))
559 dev_dbg(xsdfec->dev, "Max Schedule exceeds 2 bits");
560 max_schedule = ((max_schedule << XSDFEC_REG2_MAX_SCHEDULE_LSB) &
561 XSDFEC_REG2_MAX_SCHEDULE_MASK);
562
563 wdata = (max_schedule | no_final_parity | special_qc | norm_type |
564 nmqc | nlayers);
565
566 if (XSDFEC_LDPC_CODE_REG2_ADDR_BASE + (offset * XSDFEC_LDPC_REG_JUMP) >
567 XSDFEC_LDPC_CODE_REG2_ADDR_HIGH) {
568 dev_dbg(xsdfec->dev, "Writing outside of LDPC reg2 space 0x%x",
569 XSDFEC_LDPC_CODE_REG2_ADDR_BASE +
570 (offset * XSDFEC_LDPC_REG_JUMP));
571 return -EINVAL;
572 }
573 xsdfec_regwrite(xsdfec,
574 XSDFEC_LDPC_CODE_REG2_ADDR_BASE +
575 (offset * XSDFEC_LDPC_REG_JUMP),
576 wdata);
577 return 0;
578}
579
580static int xsdfec_reg3_write(struct xsdfec_dev *xsdfec, u8 sc_off, u8 la_off,
581 u16 qc_off, u32 offset)
582{
583 u32 wdata;
584
585 wdata = ((qc_off << XSDFEC_REG3_QC_OFF_LSB) |
586 (la_off << XSDFEC_REG3_LA_OFF_LSB) | sc_off);
587 if (XSDFEC_LDPC_CODE_REG3_ADDR_BASE + (offset * XSDFEC_LDPC_REG_JUMP) >
588 XSDFEC_LDPC_CODE_REG3_ADDR_HIGH) {
589 dev_dbg(xsdfec->dev, "Writing outside of LDPC reg3 space 0x%x",
590 XSDFEC_LDPC_CODE_REG3_ADDR_BASE +
591 (offset * XSDFEC_LDPC_REG_JUMP));
592 return -EINVAL;
593 }
594 xsdfec_regwrite(xsdfec,
595 XSDFEC_LDPC_CODE_REG3_ADDR_BASE +
596 (offset * XSDFEC_LDPC_REG_JUMP),
597 wdata);
598 return 0;
599}
600
601static int xsdfec_table_write(struct xsdfec_dev *xsdfec, u32 offset,
602 u32 *src_ptr, u32 len, const u32 base_addr,
603 const u32 depth)
604{
605 u32 reg = 0;
606 int res, i, nr_pages;
607 u32 n;
608 u32 *addr = NULL;
609 struct page *pages[MAX_NUM_PAGES];
610
611 /*
612 * Writes that go beyond the length of
613 * Shared Scale(SC) table should fail
614 */
615 if (offset > depth / XSDFEC_REG_WIDTH_JUMP ||
616 len > depth / XSDFEC_REG_WIDTH_JUMP ||
617 offset + len > depth / XSDFEC_REG_WIDTH_JUMP) {
618 dev_dbg(xsdfec->dev, "Write exceeds SC table length");
619 return -EINVAL;
620 }
621
622 n = (len * XSDFEC_REG_WIDTH_JUMP) / PAGE_SIZE;
623 if ((len * XSDFEC_REG_WIDTH_JUMP) % PAGE_SIZE)
624 n += 1;
625
626 if (WARN_ON_ONCE(n > INT_MAX))
627 return -EINVAL;
628
629 nr_pages = n;
630
631 res = pin_user_pages_fast((unsigned long)src_ptr, nr_pages, 0, pages);
632 if (res < nr_pages) {
633 if (res > 0)
634 unpin_user_pages(pages, res);
635
636 return -EINVAL;
637 }
638
639 for (i = 0; i < nr_pages; i++) {
640 addr = kmap_local_page(pages[i]);
641 do {
642 xsdfec_regwrite(xsdfec,
643 base_addr + ((offset + reg) *
644 XSDFEC_REG_WIDTH_JUMP),
645 addr[reg]);
646 reg++;
647 } while ((reg < len) &&
648 ((reg * XSDFEC_REG_WIDTH_JUMP) % PAGE_SIZE));
649 kunmap_local(addr);
650 unpin_user_page(pages[i]);
651 }
652 return 0;
653}
654
655static int xsdfec_add_ldpc(struct xsdfec_dev *xsdfec, void __user *arg)
656{
657 struct xsdfec_ldpc_params *ldpc;
658 int ret, n;
659
660 ldpc = memdup_user(arg, sizeof(*ldpc));
661 if (IS_ERR(ldpc))
662 return PTR_ERR(ldpc);
663
664 if (xsdfec->config.code == XSDFEC_TURBO_CODE) {
665 ret = -EIO;
666 goto err_out;
667 }
668
669 /* Verify Device has not started */
670 if (xsdfec->state == XSDFEC_STARTED) {
671 ret = -EIO;
672 goto err_out;
673 }
674
675 if (xsdfec->config.code_wr_protect) {
676 ret = -EIO;
677 goto err_out;
678 }
679
680 /* Write Reg 0 */
681 ret = xsdfec_reg0_write(xsdfec, ldpc->n, ldpc->k, ldpc->psize,
682 ldpc->code_id);
683 if (ret)
684 goto err_out;
685
686 /* Write Reg 1 */
687 ret = xsdfec_reg1_write(xsdfec, ldpc->psize, ldpc->no_packing, ldpc->nm,
688 ldpc->code_id);
689 if (ret)
690 goto err_out;
691
692 /* Write Reg 2 */
693 ret = xsdfec_reg2_write(xsdfec, ldpc->nlayers, ldpc->nmqc,
694 ldpc->norm_type, ldpc->special_qc,
695 ldpc->no_final_parity, ldpc->max_schedule,
696 ldpc->code_id);
697 if (ret)
698 goto err_out;
699
700 /* Write Reg 3 */
701 ret = xsdfec_reg3_write(xsdfec, ldpc->sc_off, ldpc->la_off,
702 ldpc->qc_off, ldpc->code_id);
703 if (ret)
704 goto err_out;
705
706 /* Write Shared Codes */
707 n = ldpc->nlayers / 4;
708 if (ldpc->nlayers % 4)
709 n++;
710
711 ret = xsdfec_table_write(xsdfec, ldpc->sc_off, ldpc->sc_table, n,
712 XSDFEC_LDPC_SC_TABLE_ADDR_BASE,
713 XSDFEC_SC_TABLE_DEPTH);
714 if (ret < 0)
715 goto err_out;
716
717 ret = xsdfec_table_write(xsdfec, 4 * ldpc->la_off, ldpc->la_table,
718 ldpc->nlayers, XSDFEC_LDPC_LA_TABLE_ADDR_BASE,
719 XSDFEC_LA_TABLE_DEPTH);
720 if (ret < 0)
721 goto err_out;
722
723 ret = xsdfec_table_write(xsdfec, 4 * ldpc->qc_off, ldpc->qc_table,
724 ldpc->nqc, XSDFEC_LDPC_QC_TABLE_ADDR_BASE,
725 XSDFEC_QC_TABLE_DEPTH);
726err_out:
727 kfree(ldpc);
728 return ret;
729}
730
731static int xsdfec_set_order(struct xsdfec_dev *xsdfec, void __user *arg)
732{
733 bool order_invalid;
734 enum xsdfec_order order;
735 int err;
736
737 err = get_user(order, (enum xsdfec_order __user *)arg);
738 if (err)
739 return -EFAULT;
740
741 order_invalid = (order != XSDFEC_MAINTAIN_ORDER) &&
742 (order != XSDFEC_OUT_OF_ORDER);
743 if (order_invalid)
744 return -EINVAL;
745
746 /* Verify Device has not started */
747 if (xsdfec->state == XSDFEC_STARTED)
748 return -EIO;
749
750 xsdfec_regwrite(xsdfec, XSDFEC_ORDER_ADDR, order);
751
752 xsdfec->config.order = order;
753
754 return 0;
755}
756
757static int xsdfec_set_bypass(struct xsdfec_dev *xsdfec, bool __user *arg)
758{
759 bool bypass;
760 int err;
761
762 err = get_user(bypass, arg);
763 if (err)
764 return -EFAULT;
765
766 /* Verify Device has not started */
767 if (xsdfec->state == XSDFEC_STARTED)
768 return -EIO;
769
770 if (bypass)
771 xsdfec_regwrite(xsdfec, XSDFEC_BYPASS_ADDR, 1);
772 else
773 xsdfec_regwrite(xsdfec, XSDFEC_BYPASS_ADDR, 0);
774
775 xsdfec->config.bypass = bypass;
776
777 return 0;
778}
779
780static int xsdfec_is_active(struct xsdfec_dev *xsdfec, bool __user *arg)
781{
782 u32 reg_value;
783 bool is_active;
784 int err;
785
786 reg_value = xsdfec_regread(xsdfec, XSDFEC_ACTIVE_ADDR);
787 /* using a double ! operator instead of casting */
788 is_active = !!(reg_value & XSDFEC_IS_ACTIVITY_SET);
789 err = put_user(is_active, arg);
790 if (err)
791 return -EFAULT;
792
793 return err;
794}
795
796static u32
797xsdfec_translate_axis_width_cfg_val(enum xsdfec_axis_width axis_width_cfg)
798{
799 u32 axis_width_field = 0;
800
801 switch (axis_width_cfg) {
802 case XSDFEC_1x128b:
803 axis_width_field = 0;
804 break;
805 case XSDFEC_2x128b:
806 axis_width_field = 1;
807 break;
808 case XSDFEC_4x128b:
809 axis_width_field = 2;
810 break;
811 }
812
813 return axis_width_field;
814}
815
816static u32 xsdfec_translate_axis_words_cfg_val(enum xsdfec_axis_word_include
817 axis_word_inc_cfg)
818{
819 u32 axis_words_field = 0;
820
821 if (axis_word_inc_cfg == XSDFEC_FIXED_VALUE ||
822 axis_word_inc_cfg == XSDFEC_IN_BLOCK)
823 axis_words_field = 0;
824 else if (axis_word_inc_cfg == XSDFEC_PER_AXI_TRANSACTION)
825 axis_words_field = 1;
826
827 return axis_words_field;
828}
829
830static int xsdfec_cfg_axi_streams(struct xsdfec_dev *xsdfec)
831{
832 u32 reg_value;
833 u32 dout_words_field;
834 u32 dout_width_field;
835 u32 din_words_field;
836 u32 din_width_field;
837 struct xsdfec_config *config = &xsdfec->config;
838
839 /* translate config info to register values */
840 dout_words_field =
841 xsdfec_translate_axis_words_cfg_val(config->dout_word_include);
842 dout_width_field =
843 xsdfec_translate_axis_width_cfg_val(config->dout_width);
844 din_words_field =
845 xsdfec_translate_axis_words_cfg_val(config->din_word_include);
846 din_width_field =
847 xsdfec_translate_axis_width_cfg_val(config->din_width);
848
849 reg_value = dout_words_field << XSDFEC_AXIS_DOUT_WORDS_LSB;
850 reg_value |= dout_width_field << XSDFEC_AXIS_DOUT_WIDTH_LSB;
851 reg_value |= din_words_field << XSDFEC_AXIS_DIN_WORDS_LSB;
852 reg_value |= din_width_field << XSDFEC_AXIS_DIN_WIDTH_LSB;
853
854 xsdfec_regwrite(xsdfec, XSDFEC_AXIS_WIDTH_ADDR, reg_value);
855
856 return 0;
857}
858
859static int xsdfec_start(struct xsdfec_dev *xsdfec)
860{
861 u32 regread;
862
863 regread = xsdfec_regread(xsdfec, XSDFEC_FEC_CODE_ADDR);
864 regread &= 0x1;
865 if (regread != xsdfec->config.code) {
866 dev_dbg(xsdfec->dev,
867 "%s SDFEC HW code does not match driver code, reg %d, code %d",
868 __func__, regread, xsdfec->config.code);
869 return -EINVAL;
870 }
871
872 /* Set AXIS enable */
873 xsdfec_regwrite(xsdfec, XSDFEC_AXIS_ENABLE_ADDR,
874 XSDFEC_AXIS_ENABLE_MASK);
875 /* Done */
876 xsdfec->state = XSDFEC_STARTED;
877 return 0;
878}
879
880static int xsdfec_stop(struct xsdfec_dev *xsdfec)
881{
882 u32 regread;
883
884 if (xsdfec->state != XSDFEC_STARTED)
885 dev_dbg(xsdfec->dev, "Device not started correctly");
886 /* Disable AXIS_ENABLE Input interfaces only */
887 regread = xsdfec_regread(xsdfec, XSDFEC_AXIS_ENABLE_ADDR);
888 regread &= (~XSDFEC_AXIS_IN_ENABLE_MASK);
889 xsdfec_regwrite(xsdfec, XSDFEC_AXIS_ENABLE_ADDR, regread);
890 /* Stop */
891 xsdfec->state = XSDFEC_STOPPED;
892 return 0;
893}
894
895static int xsdfec_clear_stats(struct xsdfec_dev *xsdfec)
896{
897 spin_lock_irqsave(&xsdfec->error_data_lock, xsdfec->flags);
898 xsdfec->isr_err_count = 0;
899 xsdfec->uecc_count = 0;
900 xsdfec->cecc_count = 0;
901 spin_unlock_irqrestore(&xsdfec->error_data_lock, xsdfec->flags);
902
903 return 0;
904}
905
906static int xsdfec_get_stats(struct xsdfec_dev *xsdfec, void __user *arg)
907{
908 int err;
909 struct xsdfec_stats user_stats;
910
911 spin_lock_irqsave(&xsdfec->error_data_lock, xsdfec->flags);
912 user_stats.isr_err_count = xsdfec->isr_err_count;
913 user_stats.cecc_count = xsdfec->cecc_count;
914 user_stats.uecc_count = xsdfec->uecc_count;
915 xsdfec->stats_updated = false;
916 spin_unlock_irqrestore(&xsdfec->error_data_lock, xsdfec->flags);
917
918 err = copy_to_user(arg, &user_stats, sizeof(user_stats));
919 if (err)
920 err = -EFAULT;
921
922 return err;
923}
924
925static int xsdfec_set_default_config(struct xsdfec_dev *xsdfec)
926{
927 /* Ensure registers are aligned with core configuration */
928 xsdfec_regwrite(xsdfec, XSDFEC_FEC_CODE_ADDR, xsdfec->config.code);
929 xsdfec_cfg_axi_streams(xsdfec);
930 update_config_from_hw(xsdfec);
931
932 return 0;
933}
934
935static long xsdfec_dev_ioctl(struct file *fptr, unsigned int cmd,
936 unsigned long data)
937{
938 struct xsdfec_dev *xsdfec;
939 void __user *arg = (void __user *)data;
940 int rval;
941
942 xsdfec = container_of(fptr->private_data, struct xsdfec_dev, miscdev);
943
944 /* In failed state allow only reset and get status IOCTLs */
945 if (xsdfec->state == XSDFEC_NEEDS_RESET &&
946 (cmd != XSDFEC_SET_DEFAULT_CONFIG && cmd != XSDFEC_GET_STATUS &&
947 cmd != XSDFEC_GET_STATS && cmd != XSDFEC_CLEAR_STATS)) {
948 return -EPERM;
949 }
950
951 switch (cmd) {
952 case XSDFEC_START_DEV:
953 rval = xsdfec_start(xsdfec);
954 break;
955 case XSDFEC_STOP_DEV:
956 rval = xsdfec_stop(xsdfec);
957 break;
958 case XSDFEC_CLEAR_STATS:
959 rval = xsdfec_clear_stats(xsdfec);
960 break;
961 case XSDFEC_GET_STATS:
962 rval = xsdfec_get_stats(xsdfec, arg);
963 break;
964 case XSDFEC_GET_STATUS:
965 rval = xsdfec_get_status(xsdfec, arg);
966 break;
967 case XSDFEC_GET_CONFIG:
968 rval = xsdfec_get_config(xsdfec, arg);
969 break;
970 case XSDFEC_SET_DEFAULT_CONFIG:
971 rval = xsdfec_set_default_config(xsdfec);
972 break;
973 case XSDFEC_SET_IRQ:
974 rval = xsdfec_set_irq(xsdfec, arg);
975 break;
976 case XSDFEC_SET_TURBO:
977 rval = xsdfec_set_turbo(xsdfec, arg);
978 break;
979 case XSDFEC_GET_TURBO:
980 rval = xsdfec_get_turbo(xsdfec, arg);
981 break;
982 case XSDFEC_ADD_LDPC_CODE_PARAMS:
983 rval = xsdfec_add_ldpc(xsdfec, arg);
984 break;
985 case XSDFEC_SET_ORDER:
986 rval = xsdfec_set_order(xsdfec, arg);
987 break;
988 case XSDFEC_SET_BYPASS:
989 rval = xsdfec_set_bypass(xsdfec, arg);
990 break;
991 case XSDFEC_IS_ACTIVE:
992 rval = xsdfec_is_active(xsdfec, (bool __user *)arg);
993 break;
994 default:
995 rval = -ENOTTY;
996 break;
997 }
998 return rval;
999}
1000
1001static __poll_t xsdfec_poll(struct file *file, poll_table *wait)
1002{
1003 __poll_t mask = 0;
1004 struct xsdfec_dev *xsdfec;
1005
1006 xsdfec = container_of(file->private_data, struct xsdfec_dev, miscdev);
1007
1008 poll_wait(file, &xsdfec->waitq, wait);
1009
1010 /* XSDFEC ISR detected an error */
1011 spin_lock_irqsave(&xsdfec->error_data_lock, xsdfec->flags);
1012 if (xsdfec->state_updated)
1013 mask |= EPOLLIN | EPOLLPRI;
1014
1015 if (xsdfec->stats_updated)
1016 mask |= EPOLLIN | EPOLLRDNORM;
1017 spin_unlock_irqrestore(&xsdfec->error_data_lock, xsdfec->flags);
1018
1019 return mask;
1020}
1021
1022static const struct file_operations xsdfec_fops = {
1023 .owner = THIS_MODULE,
1024 .unlocked_ioctl = xsdfec_dev_ioctl,
1025 .poll = xsdfec_poll,
1026 .compat_ioctl = compat_ptr_ioctl,
1027};
1028
1029static int xsdfec_parse_of(struct xsdfec_dev *xsdfec)
1030{
1031 struct device *dev = xsdfec->dev;
1032 struct device_node *node = dev->of_node;
1033 int rval;
1034 const char *fec_code;
1035 u32 din_width;
1036 u32 din_word_include;
1037 u32 dout_width;
1038 u32 dout_word_include;
1039
1040 rval = of_property_read_string(node, "xlnx,sdfec-code", &fec_code);
1041 if (rval < 0)
1042 return rval;
1043
1044 if (!strcasecmp(fec_code, "ldpc"))
1045 xsdfec->config.code = XSDFEC_LDPC_CODE;
1046 else if (!strcasecmp(fec_code, "turbo"))
1047 xsdfec->config.code = XSDFEC_TURBO_CODE;
1048 else
1049 return -EINVAL;
1050
1051 rval = of_property_read_u32(node, "xlnx,sdfec-din-words",
1052 &din_word_include);
1053 if (rval < 0)
1054 return rval;
1055
1056 if (din_word_include < XSDFEC_AXIS_WORDS_INCLUDE_MAX)
1057 xsdfec->config.din_word_include = din_word_include;
1058 else
1059 return -EINVAL;
1060
1061 rval = of_property_read_u32(node, "xlnx,sdfec-din-width", &din_width);
1062 if (rval < 0)
1063 return rval;
1064
1065 switch (din_width) {
1066 /* Fall through and set for valid values */
1067 case XSDFEC_1x128b:
1068 case XSDFEC_2x128b:
1069 case XSDFEC_4x128b:
1070 xsdfec->config.din_width = din_width;
1071 break;
1072 default:
1073 return -EINVAL;
1074 }
1075
1076 rval = of_property_read_u32(node, "xlnx,sdfec-dout-words",
1077 &dout_word_include);
1078 if (rval < 0)
1079 return rval;
1080
1081 if (dout_word_include < XSDFEC_AXIS_WORDS_INCLUDE_MAX)
1082 xsdfec->config.dout_word_include = dout_word_include;
1083 else
1084 return -EINVAL;
1085
1086 rval = of_property_read_u32(node, "xlnx,sdfec-dout-width", &dout_width);
1087 if (rval < 0)
1088 return rval;
1089
1090 switch (dout_width) {
1091 /* Fall through and set for valid values */
1092 case XSDFEC_1x128b:
1093 case XSDFEC_2x128b:
1094 case XSDFEC_4x128b:
1095 xsdfec->config.dout_width = dout_width;
1096 break;
1097 default:
1098 return -EINVAL;
1099 }
1100
1101 /* Write LDPC to CODE Register */
1102 xsdfec_regwrite(xsdfec, XSDFEC_FEC_CODE_ADDR, xsdfec->config.code);
1103
1104 xsdfec_cfg_axi_streams(xsdfec);
1105
1106 return 0;
1107}
1108
1109static irqreturn_t xsdfec_irq_thread(int irq, void *dev_id)
1110{
1111 struct xsdfec_dev *xsdfec = dev_id;
1112 irqreturn_t ret = IRQ_HANDLED;
1113 u32 ecc_err;
1114 u32 isr_err;
1115 u32 uecc_count;
1116 u32 cecc_count;
1117 u32 isr_err_count;
1118 u32 aecc_count;
1119 u32 tmp;
1120
1121 WARN_ON(xsdfec->irq != irq);
1122
1123 /* Mask Interrupts */
1124 xsdfec_isr_enable(xsdfec, false);
1125 xsdfec_ecc_isr_enable(xsdfec, false);
1126 /* Read ISR */
1127 ecc_err = xsdfec_regread(xsdfec, XSDFEC_ECC_ISR_ADDR);
1128 isr_err = xsdfec_regread(xsdfec, XSDFEC_ISR_ADDR);
1129 /* Clear the interrupts */
1130 xsdfec_regwrite(xsdfec, XSDFEC_ECC_ISR_ADDR, ecc_err);
1131 xsdfec_regwrite(xsdfec, XSDFEC_ISR_ADDR, isr_err);
1132
1133 tmp = ecc_err & XSDFEC_ALL_ECC_ISR_MBE_MASK;
1134 /* Count uncorrectable 2-bit errors */
1135 uecc_count = hweight32(tmp);
1136 /* Count all ECC errors */
1137 aecc_count = hweight32(ecc_err);
1138 /* Number of correctable 1-bit ECC error */
1139 cecc_count = aecc_count - 2 * uecc_count;
1140 /* Count ISR errors */
1141 isr_err_count = hweight32(isr_err);
1142 dev_dbg(xsdfec->dev, "tmp=%x, uecc=%x, aecc=%x, cecc=%x, isr=%x", tmp,
1143 uecc_count, aecc_count, cecc_count, isr_err_count);
1144 dev_dbg(xsdfec->dev, "uecc=%x, cecc=%x, isr=%x", xsdfec->uecc_count,
1145 xsdfec->cecc_count, xsdfec->isr_err_count);
1146
1147 spin_lock_irqsave(&xsdfec->error_data_lock, xsdfec->flags);
1148 /* Add new errors to a 2-bits counter */
1149 if (uecc_count)
1150 xsdfec->uecc_count += uecc_count;
1151 /* Add new errors to a 1-bits counter */
1152 if (cecc_count)
1153 xsdfec->cecc_count += cecc_count;
1154 /* Add new errors to a ISR counter */
1155 if (isr_err_count)
1156 xsdfec->isr_err_count += isr_err_count;
1157
1158 /* Update state/stats flag */
1159 if (uecc_count) {
1160 if (ecc_err & XSDFEC_ECC_ISR_MBE_MASK)
1161 xsdfec->state = XSDFEC_NEEDS_RESET;
1162 else if (ecc_err & XSDFEC_PL_INIT_ECC_ISR_MBE_MASK)
1163 xsdfec->state = XSDFEC_PL_RECONFIGURE;
1164 xsdfec->stats_updated = true;
1165 xsdfec->state_updated = true;
1166 }
1167
1168 if (cecc_count)
1169 xsdfec->stats_updated = true;
1170
1171 if (isr_err_count) {
1172 xsdfec->state = XSDFEC_NEEDS_RESET;
1173 xsdfec->stats_updated = true;
1174 xsdfec->state_updated = true;
1175 }
1176
1177 spin_unlock_irqrestore(&xsdfec->error_data_lock, xsdfec->flags);
1178 dev_dbg(xsdfec->dev, "state=%x, stats=%x", xsdfec->state_updated,
1179 xsdfec->stats_updated);
1180
1181 /* Enable another polling */
1182 if (xsdfec->state_updated || xsdfec->stats_updated)
1183 wake_up_interruptible(&xsdfec->waitq);
1184 else
1185 ret = IRQ_NONE;
1186
1187 /* Unmask Interrupts */
1188 xsdfec_isr_enable(xsdfec, true);
1189 xsdfec_ecc_isr_enable(xsdfec, true);
1190
1191 return ret;
1192}
1193
1194static int xsdfec_clk_init(struct platform_device *pdev,
1195 struct xsdfec_clks *clks)
1196{
1197 int err;
1198
1199 clks->core_clk = devm_clk_get(&pdev->dev, "core_clk");
1200 if (IS_ERR(clks->core_clk)) {
1201 dev_err(&pdev->dev, "failed to get core_clk");
1202 return PTR_ERR(clks->core_clk);
1203 }
1204
1205 clks->axi_clk = devm_clk_get(&pdev->dev, "s_axi_aclk");
1206 if (IS_ERR(clks->axi_clk)) {
1207 dev_err(&pdev->dev, "failed to get axi_clk");
1208 return PTR_ERR(clks->axi_clk);
1209 }
1210
1211 clks->din_words_clk = devm_clk_get(&pdev->dev, "s_axis_din_words_aclk");
1212 if (IS_ERR(clks->din_words_clk)) {
1213 if (PTR_ERR(clks->din_words_clk) != -ENOENT) {
1214 err = PTR_ERR(clks->din_words_clk);
1215 return err;
1216 }
1217 clks->din_words_clk = NULL;
1218 }
1219
1220 clks->din_clk = devm_clk_get(&pdev->dev, "s_axis_din_aclk");
1221 if (IS_ERR(clks->din_clk)) {
1222 if (PTR_ERR(clks->din_clk) != -ENOENT) {
1223 err = PTR_ERR(clks->din_clk);
1224 return err;
1225 }
1226 clks->din_clk = NULL;
1227 }
1228
1229 clks->dout_clk = devm_clk_get(&pdev->dev, "m_axis_dout_aclk");
1230 if (IS_ERR(clks->dout_clk)) {
1231 if (PTR_ERR(clks->dout_clk) != -ENOENT) {
1232 err = PTR_ERR(clks->dout_clk);
1233 return err;
1234 }
1235 clks->dout_clk = NULL;
1236 }
1237
1238 clks->dout_words_clk =
1239 devm_clk_get(&pdev->dev, "s_axis_dout_words_aclk");
1240 if (IS_ERR(clks->dout_words_clk)) {
1241 if (PTR_ERR(clks->dout_words_clk) != -ENOENT) {
1242 err = PTR_ERR(clks->dout_words_clk);
1243 return err;
1244 }
1245 clks->dout_words_clk = NULL;
1246 }
1247
1248 clks->ctrl_clk = devm_clk_get(&pdev->dev, "s_axis_ctrl_aclk");
1249 if (IS_ERR(clks->ctrl_clk)) {
1250 if (PTR_ERR(clks->ctrl_clk) != -ENOENT) {
1251 err = PTR_ERR(clks->ctrl_clk);
1252 return err;
1253 }
1254 clks->ctrl_clk = NULL;
1255 }
1256
1257 clks->status_clk = devm_clk_get(&pdev->dev, "m_axis_status_aclk");
1258 if (IS_ERR(clks->status_clk)) {
1259 if (PTR_ERR(clks->status_clk) != -ENOENT) {
1260 err = PTR_ERR(clks->status_clk);
1261 return err;
1262 }
1263 clks->status_clk = NULL;
1264 }
1265
1266 err = clk_prepare_enable(clks->core_clk);
1267 if (err) {
1268 dev_err(&pdev->dev, "failed to enable core_clk (%d)", err);
1269 return err;
1270 }
1271
1272 err = clk_prepare_enable(clks->axi_clk);
1273 if (err) {
1274 dev_err(&pdev->dev, "failed to enable axi_clk (%d)", err);
1275 goto err_disable_core_clk;
1276 }
1277
1278 err = clk_prepare_enable(clks->din_clk);
1279 if (err) {
1280 dev_err(&pdev->dev, "failed to enable din_clk (%d)", err);
1281 goto err_disable_axi_clk;
1282 }
1283
1284 err = clk_prepare_enable(clks->din_words_clk);
1285 if (err) {
1286 dev_err(&pdev->dev, "failed to enable din_words_clk (%d)", err);
1287 goto err_disable_din_clk;
1288 }
1289
1290 err = clk_prepare_enable(clks->dout_clk);
1291 if (err) {
1292 dev_err(&pdev->dev, "failed to enable dout_clk (%d)", err);
1293 goto err_disable_din_words_clk;
1294 }
1295
1296 err = clk_prepare_enable(clks->dout_words_clk);
1297 if (err) {
1298 dev_err(&pdev->dev, "failed to enable dout_words_clk (%d)",
1299 err);
1300 goto err_disable_dout_clk;
1301 }
1302
1303 err = clk_prepare_enable(clks->ctrl_clk);
1304 if (err) {
1305 dev_err(&pdev->dev, "failed to enable ctrl_clk (%d)", err);
1306 goto err_disable_dout_words_clk;
1307 }
1308
1309 err = clk_prepare_enable(clks->status_clk);
1310 if (err) {
1311 dev_err(&pdev->dev, "failed to enable status_clk (%d)\n", err);
1312 goto err_disable_ctrl_clk;
1313 }
1314
1315 return err;
1316
1317err_disable_ctrl_clk:
1318 clk_disable_unprepare(clks->ctrl_clk);
1319err_disable_dout_words_clk:
1320 clk_disable_unprepare(clks->dout_words_clk);
1321err_disable_dout_clk:
1322 clk_disable_unprepare(clks->dout_clk);
1323err_disable_din_words_clk:
1324 clk_disable_unprepare(clks->din_words_clk);
1325err_disable_din_clk:
1326 clk_disable_unprepare(clks->din_clk);
1327err_disable_axi_clk:
1328 clk_disable_unprepare(clks->axi_clk);
1329err_disable_core_clk:
1330 clk_disable_unprepare(clks->core_clk);
1331
1332 return err;
1333}
1334
1335static void xsdfec_disable_all_clks(struct xsdfec_clks *clks)
1336{
1337 clk_disable_unprepare(clks->status_clk);
1338 clk_disable_unprepare(clks->ctrl_clk);
1339 clk_disable_unprepare(clks->dout_words_clk);
1340 clk_disable_unprepare(clks->dout_clk);
1341 clk_disable_unprepare(clks->din_words_clk);
1342 clk_disable_unprepare(clks->din_clk);
1343 clk_disable_unprepare(clks->core_clk);
1344 clk_disable_unprepare(clks->axi_clk);
1345}
1346
1347static int xsdfec_probe(struct platform_device *pdev)
1348{
1349 struct xsdfec_dev *xsdfec;
1350 struct device *dev;
1351 int err;
1352 bool irq_enabled = true;
1353
1354 xsdfec = devm_kzalloc(&pdev->dev, sizeof(*xsdfec), GFP_KERNEL);
1355 if (!xsdfec)
1356 return -ENOMEM;
1357
1358 xsdfec->dev = &pdev->dev;
1359 spin_lock_init(&xsdfec->error_data_lock);
1360
1361 err = xsdfec_clk_init(pdev, &xsdfec->clks);
1362 if (err)
1363 return err;
1364
1365 dev = xsdfec->dev;
1366 xsdfec->regs = devm_platform_ioremap_resource(pdev, 0);
1367 if (IS_ERR(xsdfec->regs)) {
1368 err = PTR_ERR(xsdfec->regs);
1369 goto err_xsdfec_dev;
1370 }
1371
1372 xsdfec->irq = platform_get_irq(pdev, 0);
1373 if (xsdfec->irq < 0) {
1374 dev_dbg(dev, "platform_get_irq failed");
1375 irq_enabled = false;
1376 }
1377
1378 err = xsdfec_parse_of(xsdfec);
1379 if (err < 0)
1380 goto err_xsdfec_dev;
1381
1382 update_config_from_hw(xsdfec);
1383
1384 /* Save driver private data */
1385 platform_set_drvdata(pdev, xsdfec);
1386
1387 if (irq_enabled) {
1388 init_waitqueue_head(&xsdfec->waitq);
1389 /* Register IRQ thread */
1390 err = devm_request_threaded_irq(dev, xsdfec->irq, NULL,
1391 xsdfec_irq_thread, IRQF_ONESHOT,
1392 "xilinx-sdfec16", xsdfec);
1393 if (err < 0) {
1394 dev_err(dev, "unable to request IRQ%d", xsdfec->irq);
1395 goto err_xsdfec_dev;
1396 }
1397 }
1398
1399 err = ida_alloc(&dev_nrs, GFP_KERNEL);
1400 if (err < 0)
1401 goto err_xsdfec_dev;
1402 xsdfec->dev_id = err;
1403
1404 snprintf(xsdfec->dev_name, DEV_NAME_LEN, "xsdfec%d", xsdfec->dev_id);
1405 xsdfec->miscdev.minor = MISC_DYNAMIC_MINOR;
1406 xsdfec->miscdev.name = xsdfec->dev_name;
1407 xsdfec->miscdev.fops = &xsdfec_fops;
1408 xsdfec->miscdev.parent = dev;
1409 err = misc_register(&xsdfec->miscdev);
1410 if (err) {
1411 dev_err(dev, "error:%d. Unable to register device", err);
1412 goto err_xsdfec_ida;
1413 }
1414 return 0;
1415
1416err_xsdfec_ida:
1417 ida_free(&dev_nrs, xsdfec->dev_id);
1418err_xsdfec_dev:
1419 xsdfec_disable_all_clks(&xsdfec->clks);
1420 return err;
1421}
1422
1423static int xsdfec_remove(struct platform_device *pdev)
1424{
1425 struct xsdfec_dev *xsdfec;
1426
1427 xsdfec = platform_get_drvdata(pdev);
1428 misc_deregister(&xsdfec->miscdev);
1429 ida_free(&dev_nrs, xsdfec->dev_id);
1430 xsdfec_disable_all_clks(&xsdfec->clks);
1431 return 0;
1432}
1433
1434static const struct of_device_id xsdfec_of_match[] = {
1435 {
1436 .compatible = "xlnx,sd-fec-1.1",
1437 },
1438 { /* end of table */ }
1439};
1440MODULE_DEVICE_TABLE(of, xsdfec_of_match);
1441
1442static struct platform_driver xsdfec_driver = {
1443 .driver = {
1444 .name = "xilinx-sdfec",
1445 .of_match_table = xsdfec_of_match,
1446 },
1447 .probe = xsdfec_probe,
1448 .remove = xsdfec_remove,
1449};
1450
1451module_platform_driver(xsdfec_driver);
1452
1453MODULE_AUTHOR("Xilinx, Inc");
1454MODULE_DESCRIPTION("Xilinx SD-FEC16 Driver");
1455MODULE_LICENSE("GPL");
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Xilinx SDFEC
4 *
5 * Copyright (C) 2019 Xilinx, Inc.
6 *
7 * Description:
8 * This driver is developed for SDFEC16 (Soft Decision FEC 16nm)
9 * IP. It exposes a char device which supports file operations
10 * like open(), close() and ioctl().
11 */
12
13#include <linux/miscdevice.h>
14#include <linux/io.h>
15#include <linux/interrupt.h>
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/of_platform.h>
19#include <linux/poll.h>
20#include <linux/slab.h>
21#include <linux/clk.h>
22#include <linux/compat.h>
23#include <linux/highmem.h>
24
25#include <uapi/misc/xilinx_sdfec.h>
26
27#define DEV_NAME_LEN 12
28
29static DEFINE_IDA(dev_nrs);
30
31/* Xilinx SDFEC Register Map */
32/* CODE_WRI_PROTECT Register */
33#define XSDFEC_CODE_WR_PROTECT_ADDR (0x4)
34
35/* ACTIVE Register */
36#define XSDFEC_ACTIVE_ADDR (0x8)
37#define XSDFEC_IS_ACTIVITY_SET (0x1)
38
39/* AXIS_WIDTH Register */
40#define XSDFEC_AXIS_WIDTH_ADDR (0xC)
41#define XSDFEC_AXIS_DOUT_WORDS_LSB (5)
42#define XSDFEC_AXIS_DOUT_WIDTH_LSB (3)
43#define XSDFEC_AXIS_DIN_WORDS_LSB (2)
44#define XSDFEC_AXIS_DIN_WIDTH_LSB (0)
45
46/* AXIS_ENABLE Register */
47#define XSDFEC_AXIS_ENABLE_ADDR (0x10)
48#define XSDFEC_AXIS_OUT_ENABLE_MASK (0x38)
49#define XSDFEC_AXIS_IN_ENABLE_MASK (0x7)
50#define XSDFEC_AXIS_ENABLE_MASK \
51 (XSDFEC_AXIS_OUT_ENABLE_MASK | XSDFEC_AXIS_IN_ENABLE_MASK)
52
53/* FEC_CODE Register */
54#define XSDFEC_FEC_CODE_ADDR (0x14)
55
56/* ORDER Register Map */
57#define XSDFEC_ORDER_ADDR (0x18)
58
59/* Interrupt Status Register */
60#define XSDFEC_ISR_ADDR (0x1C)
61/* Interrupt Status Register Bit Mask */
62#define XSDFEC_ISR_MASK (0x3F)
63
64/* Write Only - Interrupt Enable Register */
65#define XSDFEC_IER_ADDR (0x20)
66/* Write Only - Interrupt Disable Register */
67#define XSDFEC_IDR_ADDR (0x24)
68/* Read Only - Interrupt Mask Register */
69#define XSDFEC_IMR_ADDR (0x28)
70
71/* ECC Interrupt Status Register */
72#define XSDFEC_ECC_ISR_ADDR (0x2C)
73/* Single Bit Errors */
74#define XSDFEC_ECC_ISR_SBE_MASK (0x7FF)
75/* PL Initialize Single Bit Errors */
76#define XSDFEC_PL_INIT_ECC_ISR_SBE_MASK (0x3C00000)
77/* Multi Bit Errors */
78#define XSDFEC_ECC_ISR_MBE_MASK (0x3FF800)
79/* PL Initialize Multi Bit Errors */
80#define XSDFEC_PL_INIT_ECC_ISR_MBE_MASK (0x3C000000)
81/* Multi Bit Error to Event Shift */
82#define XSDFEC_ECC_ISR_MBE_TO_EVENT_SHIFT (11)
83/* PL Initialize Multi Bit Error to Event Shift */
84#define XSDFEC_PL_INIT_ECC_ISR_MBE_TO_EVENT_SHIFT (4)
85/* ECC Interrupt Status Bit Mask */
86#define XSDFEC_ECC_ISR_MASK (XSDFEC_ECC_ISR_SBE_MASK | XSDFEC_ECC_ISR_MBE_MASK)
87/* ECC Interrupt Status PL Initialize Bit Mask */
88#define XSDFEC_PL_INIT_ECC_ISR_MASK \
89 (XSDFEC_PL_INIT_ECC_ISR_SBE_MASK | XSDFEC_PL_INIT_ECC_ISR_MBE_MASK)
90/* ECC Interrupt Status All Bit Mask */
91#define XSDFEC_ALL_ECC_ISR_MASK \
92 (XSDFEC_ECC_ISR_MASK | XSDFEC_PL_INIT_ECC_ISR_MASK)
93/* ECC Interrupt Status Single Bit Errors Mask */
94#define XSDFEC_ALL_ECC_ISR_SBE_MASK \
95 (XSDFEC_ECC_ISR_SBE_MASK | XSDFEC_PL_INIT_ECC_ISR_SBE_MASK)
96/* ECC Interrupt Status Multi Bit Errors Mask */
97#define XSDFEC_ALL_ECC_ISR_MBE_MASK \
98 (XSDFEC_ECC_ISR_MBE_MASK | XSDFEC_PL_INIT_ECC_ISR_MBE_MASK)
99
100/* Write Only - ECC Interrupt Enable Register */
101#define XSDFEC_ECC_IER_ADDR (0x30)
102/* Write Only - ECC Interrupt Disable Register */
103#define XSDFEC_ECC_IDR_ADDR (0x34)
104/* Read Only - ECC Interrupt Mask Register */
105#define XSDFEC_ECC_IMR_ADDR (0x38)
106
107/* BYPASS Register */
108#define XSDFEC_BYPASS_ADDR (0x3C)
109
110/* Turbo Code Register */
111#define XSDFEC_TURBO_ADDR (0x100)
112#define XSDFEC_TURBO_SCALE_MASK (0xFFF)
113#define XSDFEC_TURBO_SCALE_BIT_POS (8)
114#define XSDFEC_TURBO_SCALE_MAX (15)
115
116/* REG0 Register */
117#define XSDFEC_LDPC_CODE_REG0_ADDR_BASE (0x2000)
118#define XSDFEC_LDPC_CODE_REG0_ADDR_HIGH (0x27F0)
119#define XSDFEC_REG0_N_MIN (4)
120#define XSDFEC_REG0_N_MAX (32768)
121#define XSDFEC_REG0_N_MUL_P (256)
122#define XSDFEC_REG0_N_LSB (0)
123#define XSDFEC_REG0_K_MIN (2)
124#define XSDFEC_REG0_K_MAX (32766)
125#define XSDFEC_REG0_K_MUL_P (256)
126#define XSDFEC_REG0_K_LSB (16)
127
128/* REG1 Register */
129#define XSDFEC_LDPC_CODE_REG1_ADDR_BASE (0x2004)
130#define XSDFEC_LDPC_CODE_REG1_ADDR_HIGH (0x27f4)
131#define XSDFEC_REG1_PSIZE_MIN (2)
132#define XSDFEC_REG1_PSIZE_MAX (512)
133#define XSDFEC_REG1_NO_PACKING_MASK (0x400)
134#define XSDFEC_REG1_NO_PACKING_LSB (10)
135#define XSDFEC_REG1_NM_MASK (0xFF800)
136#define XSDFEC_REG1_NM_LSB (11)
137#define XSDFEC_REG1_BYPASS_MASK (0x100000)
138
139/* REG2 Register */
140#define XSDFEC_LDPC_CODE_REG2_ADDR_BASE (0x2008)
141#define XSDFEC_LDPC_CODE_REG2_ADDR_HIGH (0x27f8)
142#define XSDFEC_REG2_NLAYERS_MIN (1)
143#define XSDFEC_REG2_NLAYERS_MAX (256)
144#define XSDFEC_REG2_NNMQC_MASK (0xFFE00)
145#define XSDFEC_REG2_NMQC_LSB (9)
146#define XSDFEC_REG2_NORM_TYPE_MASK (0x100000)
147#define XSDFEC_REG2_NORM_TYPE_LSB (20)
148#define XSDFEC_REG2_SPECIAL_QC_MASK (0x200000)
149#define XSDFEC_REG2_SPEICAL_QC_LSB (21)
150#define XSDFEC_REG2_NO_FINAL_PARITY_MASK (0x400000)
151#define XSDFEC_REG2_NO_FINAL_PARITY_LSB (22)
152#define XSDFEC_REG2_MAX_SCHEDULE_MASK (0x1800000)
153#define XSDFEC_REG2_MAX_SCHEDULE_LSB (23)
154
155/* REG3 Register */
156#define XSDFEC_LDPC_CODE_REG3_ADDR_BASE (0x200C)
157#define XSDFEC_LDPC_CODE_REG3_ADDR_HIGH (0x27FC)
158#define XSDFEC_REG3_LA_OFF_LSB (8)
159#define XSDFEC_REG3_QC_OFF_LSB (16)
160
161#define XSDFEC_LDPC_REG_JUMP (0x10)
162#define XSDFEC_REG_WIDTH_JUMP (4)
163
164/* The maximum number of pinned pages */
165#define MAX_NUM_PAGES ((XSDFEC_QC_TABLE_DEPTH / PAGE_SIZE) + 1)
166
167/**
168 * struct xsdfec_clks - For managing SD-FEC clocks
169 * @core_clk: Main processing clock for core
170 * @axi_clk: AXI4-Lite memory-mapped clock
171 * @din_words_clk: DIN Words AXI4-Stream Slave clock
172 * @din_clk: DIN AXI4-Stream Slave clock
173 * @dout_clk: DOUT Words AXI4-Stream Slave clock
174 * @dout_words_clk: DOUT AXI4-Stream Slave clock
175 * @ctrl_clk: Control AXI4-Stream Slave clock
176 * @status_clk: Status AXI4-Stream Slave clock
177 */
178struct xsdfec_clks {
179 struct clk *core_clk;
180 struct clk *axi_clk;
181 struct clk *din_words_clk;
182 struct clk *din_clk;
183 struct clk *dout_clk;
184 struct clk *dout_words_clk;
185 struct clk *ctrl_clk;
186 struct clk *status_clk;
187};
188
189/**
190 * struct xsdfec_dev - Driver data for SDFEC
191 * @miscdev: Misc device handle
192 * @clks: Clocks managed by the SDFEC driver
193 * @waitq: Driver wait queue
194 * @config: Configuration of the SDFEC device
195 * @dev_name: Device name
196 * @flags: spinlock flags
197 * @regs: device physical base address
198 * @dev: pointer to device struct
199 * @state: State of the SDFEC device
200 * @error_data_lock: Error counter and states spinlock
201 * @dev_id: Device ID
202 * @isr_err_count: Count of ISR errors
203 * @cecc_count: Count of Correctable ECC errors (SBE)
204 * @uecc_count: Count of Uncorrectable ECC errors (MBE)
205 * @irq: IRQ number
206 * @state_updated: indicates State updated by interrupt handler
207 * @stats_updated: indicates Stats updated by interrupt handler
208 * @intr_enabled: indicates IRQ enabled
209 *
210 * This structure contains necessary state for SDFEC driver to operate
211 */
212struct xsdfec_dev {
213 struct miscdevice miscdev;
214 struct xsdfec_clks clks;
215 wait_queue_head_t waitq;
216 struct xsdfec_config config;
217 char dev_name[DEV_NAME_LEN];
218 unsigned long flags;
219 void __iomem *regs;
220 struct device *dev;
221 enum xsdfec_state state;
222 /* Spinlock to protect state_updated and stats_updated */
223 spinlock_t error_data_lock;
224 int dev_id;
225 u32 isr_err_count;
226 u32 cecc_count;
227 u32 uecc_count;
228 int irq;
229 bool state_updated;
230 bool stats_updated;
231 bool intr_enabled;
232};
233
234static inline void xsdfec_regwrite(struct xsdfec_dev *xsdfec, u32 addr,
235 u32 value)
236{
237 dev_dbg(xsdfec->dev, "Writing 0x%x to offset 0x%x", value, addr);
238 iowrite32(value, xsdfec->regs + addr);
239}
240
241static inline u32 xsdfec_regread(struct xsdfec_dev *xsdfec, u32 addr)
242{
243 u32 rval;
244
245 rval = ioread32(xsdfec->regs + addr);
246 dev_dbg(xsdfec->dev, "Read value = 0x%x from offset 0x%x", rval, addr);
247 return rval;
248}
249
250static void update_bool_config_from_reg(struct xsdfec_dev *xsdfec,
251 u32 reg_offset, u32 bit_num,
252 char *config_value)
253{
254 u32 reg_val;
255 u32 bit_mask = 1 << bit_num;
256
257 reg_val = xsdfec_regread(xsdfec, reg_offset);
258 *config_value = (reg_val & bit_mask) > 0;
259}
260
261static void update_config_from_hw(struct xsdfec_dev *xsdfec)
262{
263 u32 reg_value;
264 bool sdfec_started;
265
266 /* Update the Order */
267 reg_value = xsdfec_regread(xsdfec, XSDFEC_ORDER_ADDR);
268 xsdfec->config.order = reg_value;
269
270 update_bool_config_from_reg(xsdfec, XSDFEC_BYPASS_ADDR,
271 0, /* Bit Number, maybe change to mask */
272 &xsdfec->config.bypass);
273
274 update_bool_config_from_reg(xsdfec, XSDFEC_CODE_WR_PROTECT_ADDR,
275 0, /* Bit Number */
276 &xsdfec->config.code_wr_protect);
277
278 reg_value = xsdfec_regread(xsdfec, XSDFEC_IMR_ADDR);
279 xsdfec->config.irq.enable_isr = (reg_value & XSDFEC_ISR_MASK) > 0;
280
281 reg_value = xsdfec_regread(xsdfec, XSDFEC_ECC_IMR_ADDR);
282 xsdfec->config.irq.enable_ecc_isr =
283 (reg_value & XSDFEC_ECC_ISR_MASK) > 0;
284
285 reg_value = xsdfec_regread(xsdfec, XSDFEC_AXIS_ENABLE_ADDR);
286 sdfec_started = (reg_value & XSDFEC_AXIS_IN_ENABLE_MASK) > 0;
287 if (sdfec_started)
288 xsdfec->state = XSDFEC_STARTED;
289 else
290 xsdfec->state = XSDFEC_STOPPED;
291}
292
293static int xsdfec_get_status(struct xsdfec_dev *xsdfec, void __user *arg)
294{
295 struct xsdfec_status status;
296 int err;
297
298 memset(&status, 0, sizeof(status));
299 spin_lock_irqsave(&xsdfec->error_data_lock, xsdfec->flags);
300 status.state = xsdfec->state;
301 xsdfec->state_updated = false;
302 spin_unlock_irqrestore(&xsdfec->error_data_lock, xsdfec->flags);
303 status.activity = (xsdfec_regread(xsdfec, XSDFEC_ACTIVE_ADDR) &
304 XSDFEC_IS_ACTIVITY_SET);
305
306 err = copy_to_user(arg, &status, sizeof(status));
307 if (err)
308 err = -EFAULT;
309
310 return err;
311}
312
313static int xsdfec_get_config(struct xsdfec_dev *xsdfec, void __user *arg)
314{
315 int err;
316
317 err = copy_to_user(arg, &xsdfec->config, sizeof(xsdfec->config));
318 if (err)
319 err = -EFAULT;
320
321 return err;
322}
323
324static int xsdfec_isr_enable(struct xsdfec_dev *xsdfec, bool enable)
325{
326 u32 mask_read;
327
328 if (enable) {
329 /* Enable */
330 xsdfec_regwrite(xsdfec, XSDFEC_IER_ADDR, XSDFEC_ISR_MASK);
331 mask_read = xsdfec_regread(xsdfec, XSDFEC_IMR_ADDR);
332 if (mask_read & XSDFEC_ISR_MASK) {
333 dev_dbg(xsdfec->dev,
334 "SDFEC enabling irq with IER failed");
335 return -EIO;
336 }
337 } else {
338 /* Disable */
339 xsdfec_regwrite(xsdfec, XSDFEC_IDR_ADDR, XSDFEC_ISR_MASK);
340 mask_read = xsdfec_regread(xsdfec, XSDFEC_IMR_ADDR);
341 if ((mask_read & XSDFEC_ISR_MASK) != XSDFEC_ISR_MASK) {
342 dev_dbg(xsdfec->dev,
343 "SDFEC disabling irq with IDR failed");
344 return -EIO;
345 }
346 }
347 return 0;
348}
349
350static int xsdfec_ecc_isr_enable(struct xsdfec_dev *xsdfec, bool enable)
351{
352 u32 mask_read;
353
354 if (enable) {
355 /* Enable */
356 xsdfec_regwrite(xsdfec, XSDFEC_ECC_IER_ADDR,
357 XSDFEC_ALL_ECC_ISR_MASK);
358 mask_read = xsdfec_regread(xsdfec, XSDFEC_ECC_IMR_ADDR);
359 if (mask_read & XSDFEC_ALL_ECC_ISR_MASK) {
360 dev_dbg(xsdfec->dev,
361 "SDFEC enabling ECC irq with ECC IER failed");
362 return -EIO;
363 }
364 } else {
365 /* Disable */
366 xsdfec_regwrite(xsdfec, XSDFEC_ECC_IDR_ADDR,
367 XSDFEC_ALL_ECC_ISR_MASK);
368 mask_read = xsdfec_regread(xsdfec, XSDFEC_ECC_IMR_ADDR);
369 if (!(((mask_read & XSDFEC_ALL_ECC_ISR_MASK) ==
370 XSDFEC_ECC_ISR_MASK) ||
371 ((mask_read & XSDFEC_ALL_ECC_ISR_MASK) ==
372 XSDFEC_PL_INIT_ECC_ISR_MASK))) {
373 dev_dbg(xsdfec->dev,
374 "SDFEC disable ECC irq with ECC IDR failed");
375 return -EIO;
376 }
377 }
378 return 0;
379}
380
381static int xsdfec_set_irq(struct xsdfec_dev *xsdfec, void __user *arg)
382{
383 struct xsdfec_irq irq;
384 int err;
385 int isr_err;
386 int ecc_err;
387
388 err = copy_from_user(&irq, arg, sizeof(irq));
389 if (err)
390 return -EFAULT;
391
392 /* Setup tlast related IRQ */
393 isr_err = xsdfec_isr_enable(xsdfec, irq.enable_isr);
394 if (!isr_err)
395 xsdfec->config.irq.enable_isr = irq.enable_isr;
396
397 /* Setup ECC related IRQ */
398 ecc_err = xsdfec_ecc_isr_enable(xsdfec, irq.enable_ecc_isr);
399 if (!ecc_err)
400 xsdfec->config.irq.enable_ecc_isr = irq.enable_ecc_isr;
401
402 if (isr_err < 0 || ecc_err < 0)
403 err = -EIO;
404
405 return err;
406}
407
408static int xsdfec_set_turbo(struct xsdfec_dev *xsdfec, void __user *arg)
409{
410 struct xsdfec_turbo turbo;
411 int err;
412 u32 turbo_write;
413
414 err = copy_from_user(&turbo, arg, sizeof(turbo));
415 if (err)
416 return -EFAULT;
417
418 if (turbo.alg >= XSDFEC_TURBO_ALG_MAX)
419 return -EINVAL;
420
421 if (turbo.scale > XSDFEC_TURBO_SCALE_MAX)
422 return -EINVAL;
423
424 /* Check to see what device tree says about the FEC codes */
425 if (xsdfec->config.code == XSDFEC_LDPC_CODE)
426 return -EIO;
427
428 turbo_write = ((turbo.scale & XSDFEC_TURBO_SCALE_MASK)
429 << XSDFEC_TURBO_SCALE_BIT_POS) |
430 turbo.alg;
431 xsdfec_regwrite(xsdfec, XSDFEC_TURBO_ADDR, turbo_write);
432 return err;
433}
434
435static int xsdfec_get_turbo(struct xsdfec_dev *xsdfec, void __user *arg)
436{
437 u32 reg_value;
438 struct xsdfec_turbo turbo_params;
439 int err;
440
441 if (xsdfec->config.code == XSDFEC_LDPC_CODE)
442 return -EIO;
443
444 memset(&turbo_params, 0, sizeof(turbo_params));
445 reg_value = xsdfec_regread(xsdfec, XSDFEC_TURBO_ADDR);
446
447 turbo_params.scale = (reg_value & XSDFEC_TURBO_SCALE_MASK) >>
448 XSDFEC_TURBO_SCALE_BIT_POS;
449 turbo_params.alg = reg_value & 0x1;
450
451 err = copy_to_user(arg, &turbo_params, sizeof(turbo_params));
452 if (err)
453 err = -EFAULT;
454
455 return err;
456}
457
458static int xsdfec_reg0_write(struct xsdfec_dev *xsdfec, u32 n, u32 k, u32 psize,
459 u32 offset)
460{
461 u32 wdata;
462
463 if (n < XSDFEC_REG0_N_MIN || n > XSDFEC_REG0_N_MAX || psize == 0 ||
464 (n > XSDFEC_REG0_N_MUL_P * psize) || n <= k || ((n % psize) != 0)) {
465 dev_dbg(xsdfec->dev, "N value is not in range");
466 return -EINVAL;
467 }
468 n <<= XSDFEC_REG0_N_LSB;
469
470 if (k < XSDFEC_REG0_K_MIN || k > XSDFEC_REG0_K_MAX ||
471 (k > XSDFEC_REG0_K_MUL_P * psize) || ((k % psize) != 0)) {
472 dev_dbg(xsdfec->dev, "K value is not in range");
473 return -EINVAL;
474 }
475 k = k << XSDFEC_REG0_K_LSB;
476 wdata = k | n;
477
478 if (XSDFEC_LDPC_CODE_REG0_ADDR_BASE + (offset * XSDFEC_LDPC_REG_JUMP) >
479 XSDFEC_LDPC_CODE_REG0_ADDR_HIGH) {
480 dev_dbg(xsdfec->dev, "Writing outside of LDPC reg0 space 0x%x",
481 XSDFEC_LDPC_CODE_REG0_ADDR_BASE +
482 (offset * XSDFEC_LDPC_REG_JUMP));
483 return -EINVAL;
484 }
485 xsdfec_regwrite(xsdfec,
486 XSDFEC_LDPC_CODE_REG0_ADDR_BASE +
487 (offset * XSDFEC_LDPC_REG_JUMP),
488 wdata);
489 return 0;
490}
491
492static int xsdfec_reg1_write(struct xsdfec_dev *xsdfec, u32 psize,
493 u32 no_packing, u32 nm, u32 offset)
494{
495 u32 wdata;
496
497 if (psize < XSDFEC_REG1_PSIZE_MIN || psize > XSDFEC_REG1_PSIZE_MAX) {
498 dev_dbg(xsdfec->dev, "Psize is not in range");
499 return -EINVAL;
500 }
501
502 if (no_packing != 0 && no_packing != 1)
503 dev_dbg(xsdfec->dev, "No-packing bit register invalid");
504 no_packing = ((no_packing << XSDFEC_REG1_NO_PACKING_LSB) &
505 XSDFEC_REG1_NO_PACKING_MASK);
506
507 if (nm & ~(XSDFEC_REG1_NM_MASK >> XSDFEC_REG1_NM_LSB))
508 dev_dbg(xsdfec->dev, "NM is beyond 10 bits");
509 nm = (nm << XSDFEC_REG1_NM_LSB) & XSDFEC_REG1_NM_MASK;
510
511 wdata = nm | no_packing | psize;
512 if (XSDFEC_LDPC_CODE_REG1_ADDR_BASE + (offset * XSDFEC_LDPC_REG_JUMP) >
513 XSDFEC_LDPC_CODE_REG1_ADDR_HIGH) {
514 dev_dbg(xsdfec->dev, "Writing outside of LDPC reg1 space 0x%x",
515 XSDFEC_LDPC_CODE_REG1_ADDR_BASE +
516 (offset * XSDFEC_LDPC_REG_JUMP));
517 return -EINVAL;
518 }
519 xsdfec_regwrite(xsdfec,
520 XSDFEC_LDPC_CODE_REG1_ADDR_BASE +
521 (offset * XSDFEC_LDPC_REG_JUMP),
522 wdata);
523 return 0;
524}
525
526static int xsdfec_reg2_write(struct xsdfec_dev *xsdfec, u32 nlayers, u32 nmqc,
527 u32 norm_type, u32 special_qc, u32 no_final_parity,
528 u32 max_schedule, u32 offset)
529{
530 u32 wdata;
531
532 if (nlayers < XSDFEC_REG2_NLAYERS_MIN ||
533 nlayers > XSDFEC_REG2_NLAYERS_MAX) {
534 dev_dbg(xsdfec->dev, "Nlayers is not in range");
535 return -EINVAL;
536 }
537
538 if (nmqc & ~(XSDFEC_REG2_NNMQC_MASK >> XSDFEC_REG2_NMQC_LSB))
539 dev_dbg(xsdfec->dev, "NMQC exceeds 11 bits");
540 nmqc = (nmqc << XSDFEC_REG2_NMQC_LSB) & XSDFEC_REG2_NNMQC_MASK;
541
542 if (norm_type > 1)
543 dev_dbg(xsdfec->dev, "Norm type is invalid");
544 norm_type = ((norm_type << XSDFEC_REG2_NORM_TYPE_LSB) &
545 XSDFEC_REG2_NORM_TYPE_MASK);
546 if (special_qc > 1)
547 dev_dbg(xsdfec->dev, "Special QC in invalid");
548 special_qc = ((special_qc << XSDFEC_REG2_SPEICAL_QC_LSB) &
549 XSDFEC_REG2_SPECIAL_QC_MASK);
550
551 if (no_final_parity > 1)
552 dev_dbg(xsdfec->dev, "No final parity check invalid");
553 no_final_parity =
554 ((no_final_parity << XSDFEC_REG2_NO_FINAL_PARITY_LSB) &
555 XSDFEC_REG2_NO_FINAL_PARITY_MASK);
556 if (max_schedule &
557 ~(XSDFEC_REG2_MAX_SCHEDULE_MASK >> XSDFEC_REG2_MAX_SCHEDULE_LSB))
558 dev_dbg(xsdfec->dev, "Max Schedule exceeds 2 bits");
559 max_schedule = ((max_schedule << XSDFEC_REG2_MAX_SCHEDULE_LSB) &
560 XSDFEC_REG2_MAX_SCHEDULE_MASK);
561
562 wdata = (max_schedule | no_final_parity | special_qc | norm_type |
563 nmqc | nlayers);
564
565 if (XSDFEC_LDPC_CODE_REG2_ADDR_BASE + (offset * XSDFEC_LDPC_REG_JUMP) >
566 XSDFEC_LDPC_CODE_REG2_ADDR_HIGH) {
567 dev_dbg(xsdfec->dev, "Writing outside of LDPC reg2 space 0x%x",
568 XSDFEC_LDPC_CODE_REG2_ADDR_BASE +
569 (offset * XSDFEC_LDPC_REG_JUMP));
570 return -EINVAL;
571 }
572 xsdfec_regwrite(xsdfec,
573 XSDFEC_LDPC_CODE_REG2_ADDR_BASE +
574 (offset * XSDFEC_LDPC_REG_JUMP),
575 wdata);
576 return 0;
577}
578
579static int xsdfec_reg3_write(struct xsdfec_dev *xsdfec, u8 sc_off, u8 la_off,
580 u16 qc_off, u32 offset)
581{
582 u32 wdata;
583
584 wdata = ((qc_off << XSDFEC_REG3_QC_OFF_LSB) |
585 (la_off << XSDFEC_REG3_LA_OFF_LSB) | sc_off);
586 if (XSDFEC_LDPC_CODE_REG3_ADDR_BASE + (offset * XSDFEC_LDPC_REG_JUMP) >
587 XSDFEC_LDPC_CODE_REG3_ADDR_HIGH) {
588 dev_dbg(xsdfec->dev, "Writing outside of LDPC reg3 space 0x%x",
589 XSDFEC_LDPC_CODE_REG3_ADDR_BASE +
590 (offset * XSDFEC_LDPC_REG_JUMP));
591 return -EINVAL;
592 }
593 xsdfec_regwrite(xsdfec,
594 XSDFEC_LDPC_CODE_REG3_ADDR_BASE +
595 (offset * XSDFEC_LDPC_REG_JUMP),
596 wdata);
597 return 0;
598}
599
600static int xsdfec_table_write(struct xsdfec_dev *xsdfec, u32 offset,
601 u32 *src_ptr, u32 len, const u32 base_addr,
602 const u32 depth)
603{
604 u32 reg = 0;
605 u32 res;
606 u32 n, i;
607 u32 *addr = NULL;
608 struct page *page[MAX_NUM_PAGES];
609
610 /*
611 * Writes that go beyond the length of
612 * Shared Scale(SC) table should fail
613 */
614 if (offset > depth / XSDFEC_REG_WIDTH_JUMP ||
615 len > depth / XSDFEC_REG_WIDTH_JUMP ||
616 offset + len > depth / XSDFEC_REG_WIDTH_JUMP) {
617 dev_dbg(xsdfec->dev, "Write exceeds SC table length");
618 return -EINVAL;
619 }
620
621 n = (len * XSDFEC_REG_WIDTH_JUMP) / PAGE_SIZE;
622 if ((len * XSDFEC_REG_WIDTH_JUMP) % PAGE_SIZE)
623 n += 1;
624
625 res = get_user_pages_fast((unsigned long)src_ptr, n, 0, page);
626 if (res < n) {
627 for (i = 0; i < res; i++)
628 put_page(page[i]);
629 return -EINVAL;
630 }
631
632 for (i = 0; i < n; i++) {
633 addr = kmap(page[i]);
634 do {
635 xsdfec_regwrite(xsdfec,
636 base_addr + ((offset + reg) *
637 XSDFEC_REG_WIDTH_JUMP),
638 addr[reg]);
639 reg++;
640 } while ((reg < len) &&
641 ((reg * XSDFEC_REG_WIDTH_JUMP) % PAGE_SIZE));
642 put_page(page[i]);
643 }
644 return reg;
645}
646
647static int xsdfec_add_ldpc(struct xsdfec_dev *xsdfec, void __user *arg)
648{
649 struct xsdfec_ldpc_params *ldpc;
650 int ret, n;
651
652 ldpc = kzalloc(sizeof(*ldpc), GFP_KERNEL);
653 if (!ldpc)
654 return -ENOMEM;
655
656 if (copy_from_user(ldpc, arg, sizeof(*ldpc))) {
657 ret = -EFAULT;
658 goto err_out;
659 }
660
661 if (xsdfec->config.code == XSDFEC_TURBO_CODE) {
662 ret = -EIO;
663 goto err_out;
664 }
665
666 /* Verify Device has not started */
667 if (xsdfec->state == XSDFEC_STARTED) {
668 ret = -EIO;
669 goto err_out;
670 }
671
672 if (xsdfec->config.code_wr_protect) {
673 ret = -EIO;
674 goto err_out;
675 }
676
677 /* Write Reg 0 */
678 ret = xsdfec_reg0_write(xsdfec, ldpc->n, ldpc->k, ldpc->psize,
679 ldpc->code_id);
680 if (ret)
681 goto err_out;
682
683 /* Write Reg 1 */
684 ret = xsdfec_reg1_write(xsdfec, ldpc->psize, ldpc->no_packing, ldpc->nm,
685 ldpc->code_id);
686 if (ret)
687 goto err_out;
688
689 /* Write Reg 2 */
690 ret = xsdfec_reg2_write(xsdfec, ldpc->nlayers, ldpc->nmqc,
691 ldpc->norm_type, ldpc->special_qc,
692 ldpc->no_final_parity, ldpc->max_schedule,
693 ldpc->code_id);
694 if (ret)
695 goto err_out;
696
697 /* Write Reg 3 */
698 ret = xsdfec_reg3_write(xsdfec, ldpc->sc_off, ldpc->la_off,
699 ldpc->qc_off, ldpc->code_id);
700 if (ret)
701 goto err_out;
702
703 /* Write Shared Codes */
704 n = ldpc->nlayers / 4;
705 if (ldpc->nlayers % 4)
706 n++;
707
708 ret = xsdfec_table_write(xsdfec, ldpc->sc_off, ldpc->sc_table, n,
709 XSDFEC_LDPC_SC_TABLE_ADDR_BASE,
710 XSDFEC_SC_TABLE_DEPTH);
711 if (ret < 0)
712 goto err_out;
713
714 ret = xsdfec_table_write(xsdfec, 4 * ldpc->la_off, ldpc->la_table,
715 ldpc->nlayers, XSDFEC_LDPC_LA_TABLE_ADDR_BASE,
716 XSDFEC_LA_TABLE_DEPTH);
717 if (ret < 0)
718 goto err_out;
719
720 ret = xsdfec_table_write(xsdfec, 4 * ldpc->qc_off, ldpc->qc_table,
721 ldpc->nqc, XSDFEC_LDPC_QC_TABLE_ADDR_BASE,
722 XSDFEC_QC_TABLE_DEPTH);
723 if (ret > 0)
724 ret = 0;
725err_out:
726 kfree(ldpc);
727 return ret;
728}
729
730static int xsdfec_set_order(struct xsdfec_dev *xsdfec, void __user *arg)
731{
732 bool order_invalid;
733 enum xsdfec_order order;
734 int err;
735
736 err = get_user(order, (enum xsdfec_order *)arg);
737 if (err)
738 return -EFAULT;
739
740 order_invalid = (order != XSDFEC_MAINTAIN_ORDER) &&
741 (order != XSDFEC_OUT_OF_ORDER);
742 if (order_invalid)
743 return -EINVAL;
744
745 /* Verify Device has not started */
746 if (xsdfec->state == XSDFEC_STARTED)
747 return -EIO;
748
749 xsdfec_regwrite(xsdfec, XSDFEC_ORDER_ADDR, order);
750
751 xsdfec->config.order = order;
752
753 return 0;
754}
755
756static int xsdfec_set_bypass(struct xsdfec_dev *xsdfec, bool __user *arg)
757{
758 bool bypass;
759 int err;
760
761 err = get_user(bypass, arg);
762 if (err)
763 return -EFAULT;
764
765 /* Verify Device has not started */
766 if (xsdfec->state == XSDFEC_STARTED)
767 return -EIO;
768
769 if (bypass)
770 xsdfec_regwrite(xsdfec, XSDFEC_BYPASS_ADDR, 1);
771 else
772 xsdfec_regwrite(xsdfec, XSDFEC_BYPASS_ADDR, 0);
773
774 xsdfec->config.bypass = bypass;
775
776 return 0;
777}
778
779static int xsdfec_is_active(struct xsdfec_dev *xsdfec, bool __user *arg)
780{
781 u32 reg_value;
782 bool is_active;
783 int err;
784
785 reg_value = xsdfec_regread(xsdfec, XSDFEC_ACTIVE_ADDR);
786 /* using a double ! operator instead of casting */
787 is_active = !!(reg_value & XSDFEC_IS_ACTIVITY_SET);
788 err = put_user(is_active, arg);
789 if (err)
790 return -EFAULT;
791
792 return err;
793}
794
795static u32
796xsdfec_translate_axis_width_cfg_val(enum xsdfec_axis_width axis_width_cfg)
797{
798 u32 axis_width_field = 0;
799
800 switch (axis_width_cfg) {
801 case XSDFEC_1x128b:
802 axis_width_field = 0;
803 break;
804 case XSDFEC_2x128b:
805 axis_width_field = 1;
806 break;
807 case XSDFEC_4x128b:
808 axis_width_field = 2;
809 break;
810 }
811
812 return axis_width_field;
813}
814
815static u32 xsdfec_translate_axis_words_cfg_val(enum xsdfec_axis_word_include
816 axis_word_inc_cfg)
817{
818 u32 axis_words_field = 0;
819
820 if (axis_word_inc_cfg == XSDFEC_FIXED_VALUE ||
821 axis_word_inc_cfg == XSDFEC_IN_BLOCK)
822 axis_words_field = 0;
823 else if (axis_word_inc_cfg == XSDFEC_PER_AXI_TRANSACTION)
824 axis_words_field = 1;
825
826 return axis_words_field;
827}
828
829static int xsdfec_cfg_axi_streams(struct xsdfec_dev *xsdfec)
830{
831 u32 reg_value;
832 u32 dout_words_field;
833 u32 dout_width_field;
834 u32 din_words_field;
835 u32 din_width_field;
836 struct xsdfec_config *config = &xsdfec->config;
837
838 /* translate config info to register values */
839 dout_words_field =
840 xsdfec_translate_axis_words_cfg_val(config->dout_word_include);
841 dout_width_field =
842 xsdfec_translate_axis_width_cfg_val(config->dout_width);
843 din_words_field =
844 xsdfec_translate_axis_words_cfg_val(config->din_word_include);
845 din_width_field =
846 xsdfec_translate_axis_width_cfg_val(config->din_width);
847
848 reg_value = dout_words_field << XSDFEC_AXIS_DOUT_WORDS_LSB;
849 reg_value |= dout_width_field << XSDFEC_AXIS_DOUT_WIDTH_LSB;
850 reg_value |= din_words_field << XSDFEC_AXIS_DIN_WORDS_LSB;
851 reg_value |= din_width_field << XSDFEC_AXIS_DIN_WIDTH_LSB;
852
853 xsdfec_regwrite(xsdfec, XSDFEC_AXIS_WIDTH_ADDR, reg_value);
854
855 return 0;
856}
857
858static int xsdfec_dev_open(struct inode *iptr, struct file *fptr)
859{
860 return 0;
861}
862
863static int xsdfec_dev_release(struct inode *iptr, struct file *fptr)
864{
865 return 0;
866}
867
868static int xsdfec_start(struct xsdfec_dev *xsdfec)
869{
870 u32 regread;
871
872 regread = xsdfec_regread(xsdfec, XSDFEC_FEC_CODE_ADDR);
873 regread &= 0x1;
874 if (regread != xsdfec->config.code) {
875 dev_dbg(xsdfec->dev,
876 "%s SDFEC HW code does not match driver code, reg %d, code %d",
877 __func__, regread, xsdfec->config.code);
878 return -EINVAL;
879 }
880
881 /* Set AXIS enable */
882 xsdfec_regwrite(xsdfec, XSDFEC_AXIS_ENABLE_ADDR,
883 XSDFEC_AXIS_ENABLE_MASK);
884 /* Done */
885 xsdfec->state = XSDFEC_STARTED;
886 return 0;
887}
888
889static int xsdfec_stop(struct xsdfec_dev *xsdfec)
890{
891 u32 regread;
892
893 if (xsdfec->state != XSDFEC_STARTED)
894 dev_dbg(xsdfec->dev, "Device not started correctly");
895 /* Disable AXIS_ENABLE Input interfaces only */
896 regread = xsdfec_regread(xsdfec, XSDFEC_AXIS_ENABLE_ADDR);
897 regread &= (~XSDFEC_AXIS_IN_ENABLE_MASK);
898 xsdfec_regwrite(xsdfec, XSDFEC_AXIS_ENABLE_ADDR, regread);
899 /* Stop */
900 xsdfec->state = XSDFEC_STOPPED;
901 return 0;
902}
903
904static int xsdfec_clear_stats(struct xsdfec_dev *xsdfec)
905{
906 spin_lock_irqsave(&xsdfec->error_data_lock, xsdfec->flags);
907 xsdfec->isr_err_count = 0;
908 xsdfec->uecc_count = 0;
909 xsdfec->cecc_count = 0;
910 spin_unlock_irqrestore(&xsdfec->error_data_lock, xsdfec->flags);
911
912 return 0;
913}
914
915static int xsdfec_get_stats(struct xsdfec_dev *xsdfec, void __user *arg)
916{
917 int err;
918 struct xsdfec_stats user_stats;
919
920 spin_lock_irqsave(&xsdfec->error_data_lock, xsdfec->flags);
921 user_stats.isr_err_count = xsdfec->isr_err_count;
922 user_stats.cecc_count = xsdfec->cecc_count;
923 user_stats.uecc_count = xsdfec->uecc_count;
924 xsdfec->stats_updated = false;
925 spin_unlock_irqrestore(&xsdfec->error_data_lock, xsdfec->flags);
926
927 err = copy_to_user(arg, &user_stats, sizeof(user_stats));
928 if (err)
929 err = -EFAULT;
930
931 return err;
932}
933
934static int xsdfec_set_default_config(struct xsdfec_dev *xsdfec)
935{
936 /* Ensure registers are aligned with core configuration */
937 xsdfec_regwrite(xsdfec, XSDFEC_FEC_CODE_ADDR, xsdfec->config.code);
938 xsdfec_cfg_axi_streams(xsdfec);
939 update_config_from_hw(xsdfec);
940
941 return 0;
942}
943
944static long xsdfec_dev_ioctl(struct file *fptr, unsigned int cmd,
945 unsigned long data)
946{
947 struct xsdfec_dev *xsdfec;
948 void __user *arg = NULL;
949 int rval = -EINVAL;
950
951 xsdfec = container_of(fptr->private_data, struct xsdfec_dev, miscdev);
952
953 /* In failed state allow only reset and get status IOCTLs */
954 if (xsdfec->state == XSDFEC_NEEDS_RESET &&
955 (cmd != XSDFEC_SET_DEFAULT_CONFIG && cmd != XSDFEC_GET_STATUS &&
956 cmd != XSDFEC_GET_STATS && cmd != XSDFEC_CLEAR_STATS)) {
957 return -EPERM;
958 }
959
960 if (_IOC_TYPE(cmd) != XSDFEC_MAGIC)
961 return -ENOTTY;
962
963 /* check if ioctl argument is present and valid */
964 if (_IOC_DIR(cmd) != _IOC_NONE) {
965 arg = (void __user *)data;
966 if (!arg)
967 return rval;
968 }
969
970 switch (cmd) {
971 case XSDFEC_START_DEV:
972 rval = xsdfec_start(xsdfec);
973 break;
974 case XSDFEC_STOP_DEV:
975 rval = xsdfec_stop(xsdfec);
976 break;
977 case XSDFEC_CLEAR_STATS:
978 rval = xsdfec_clear_stats(xsdfec);
979 break;
980 case XSDFEC_GET_STATS:
981 rval = xsdfec_get_stats(xsdfec, arg);
982 break;
983 case XSDFEC_GET_STATUS:
984 rval = xsdfec_get_status(xsdfec, arg);
985 break;
986 case XSDFEC_GET_CONFIG:
987 rval = xsdfec_get_config(xsdfec, arg);
988 break;
989 case XSDFEC_SET_DEFAULT_CONFIG:
990 rval = xsdfec_set_default_config(xsdfec);
991 break;
992 case XSDFEC_SET_IRQ:
993 rval = xsdfec_set_irq(xsdfec, arg);
994 break;
995 case XSDFEC_SET_TURBO:
996 rval = xsdfec_set_turbo(xsdfec, arg);
997 break;
998 case XSDFEC_GET_TURBO:
999 rval = xsdfec_get_turbo(xsdfec, arg);
1000 break;
1001 case XSDFEC_ADD_LDPC_CODE_PARAMS:
1002 rval = xsdfec_add_ldpc(xsdfec, arg);
1003 break;
1004 case XSDFEC_SET_ORDER:
1005 rval = xsdfec_set_order(xsdfec, arg);
1006 break;
1007 case XSDFEC_SET_BYPASS:
1008 rval = xsdfec_set_bypass(xsdfec, arg);
1009 break;
1010 case XSDFEC_IS_ACTIVE:
1011 rval = xsdfec_is_active(xsdfec, (bool __user *)arg);
1012 break;
1013 default:
1014 /* Should not get here */
1015 break;
1016 }
1017 return rval;
1018}
1019
1020#ifdef CONFIG_COMPAT
1021static long xsdfec_dev_compat_ioctl(struct file *file, unsigned int cmd,
1022 unsigned long data)
1023{
1024 return xsdfec_dev_ioctl(file, cmd, (unsigned long)compat_ptr(data));
1025}
1026#endif
1027
1028static unsigned int xsdfec_poll(struct file *file, poll_table *wait)
1029{
1030 unsigned int mask = 0;
1031 struct xsdfec_dev *xsdfec;
1032
1033 xsdfec = container_of(file->private_data, struct xsdfec_dev, miscdev);
1034
1035 if (!xsdfec)
1036 return POLLNVAL | POLLHUP;
1037
1038 poll_wait(file, &xsdfec->waitq, wait);
1039
1040 /* XSDFEC ISR detected an error */
1041 spin_lock_irqsave(&xsdfec->error_data_lock, xsdfec->flags);
1042 if (xsdfec->state_updated)
1043 mask |= POLLIN | POLLPRI;
1044
1045 if (xsdfec->stats_updated)
1046 mask |= POLLIN | POLLRDNORM;
1047 spin_unlock_irqrestore(&xsdfec->error_data_lock, xsdfec->flags);
1048
1049 return mask;
1050}
1051
1052static const struct file_operations xsdfec_fops = {
1053 .owner = THIS_MODULE,
1054 .open = xsdfec_dev_open,
1055 .release = xsdfec_dev_release,
1056 .unlocked_ioctl = xsdfec_dev_ioctl,
1057 .poll = xsdfec_poll,
1058#ifdef CONFIG_COMPAT
1059 .compat_ioctl = xsdfec_dev_compat_ioctl,
1060#endif
1061};
1062
1063static int xsdfec_parse_of(struct xsdfec_dev *xsdfec)
1064{
1065 struct device *dev = xsdfec->dev;
1066 struct device_node *node = dev->of_node;
1067 int rval;
1068 const char *fec_code;
1069 u32 din_width;
1070 u32 din_word_include;
1071 u32 dout_width;
1072 u32 dout_word_include;
1073
1074 rval = of_property_read_string(node, "xlnx,sdfec-code", &fec_code);
1075 if (rval < 0)
1076 return rval;
1077
1078 if (!strcasecmp(fec_code, "ldpc"))
1079 xsdfec->config.code = XSDFEC_LDPC_CODE;
1080 else if (!strcasecmp(fec_code, "turbo"))
1081 xsdfec->config.code = XSDFEC_TURBO_CODE;
1082 else
1083 return -EINVAL;
1084
1085 rval = of_property_read_u32(node, "xlnx,sdfec-din-words",
1086 &din_word_include);
1087 if (rval < 0)
1088 return rval;
1089
1090 if (din_word_include < XSDFEC_AXIS_WORDS_INCLUDE_MAX)
1091 xsdfec->config.din_word_include = din_word_include;
1092 else
1093 return -EINVAL;
1094
1095 rval = of_property_read_u32(node, "xlnx,sdfec-din-width", &din_width);
1096 if (rval < 0)
1097 return rval;
1098
1099 switch (din_width) {
1100 /* Fall through and set for valid values */
1101 case XSDFEC_1x128b:
1102 case XSDFEC_2x128b:
1103 case XSDFEC_4x128b:
1104 xsdfec->config.din_width = din_width;
1105 break;
1106 default:
1107 return -EINVAL;
1108 }
1109
1110 rval = of_property_read_u32(node, "xlnx,sdfec-dout-words",
1111 &dout_word_include);
1112 if (rval < 0)
1113 return rval;
1114
1115 if (dout_word_include < XSDFEC_AXIS_WORDS_INCLUDE_MAX)
1116 xsdfec->config.dout_word_include = dout_word_include;
1117 else
1118 return -EINVAL;
1119
1120 rval = of_property_read_u32(node, "xlnx,sdfec-dout-width", &dout_width);
1121 if (rval < 0)
1122 return rval;
1123
1124 switch (dout_width) {
1125 /* Fall through and set for valid values */
1126 case XSDFEC_1x128b:
1127 case XSDFEC_2x128b:
1128 case XSDFEC_4x128b:
1129 xsdfec->config.dout_width = dout_width;
1130 break;
1131 default:
1132 return -EINVAL;
1133 }
1134
1135 /* Write LDPC to CODE Register */
1136 xsdfec_regwrite(xsdfec, XSDFEC_FEC_CODE_ADDR, xsdfec->config.code);
1137
1138 xsdfec_cfg_axi_streams(xsdfec);
1139
1140 return 0;
1141}
1142
1143static irqreturn_t xsdfec_irq_thread(int irq, void *dev_id)
1144{
1145 struct xsdfec_dev *xsdfec = dev_id;
1146 irqreturn_t ret = IRQ_HANDLED;
1147 u32 ecc_err;
1148 u32 isr_err;
1149 u32 uecc_count;
1150 u32 cecc_count;
1151 u32 isr_err_count;
1152 u32 aecc_count;
1153 u32 tmp;
1154
1155 WARN_ON(xsdfec->irq != irq);
1156
1157 /* Mask Interrupts */
1158 xsdfec_isr_enable(xsdfec, false);
1159 xsdfec_ecc_isr_enable(xsdfec, false);
1160 /* Read ISR */
1161 ecc_err = xsdfec_regread(xsdfec, XSDFEC_ECC_ISR_ADDR);
1162 isr_err = xsdfec_regread(xsdfec, XSDFEC_ISR_ADDR);
1163 /* Clear the interrupts */
1164 xsdfec_regwrite(xsdfec, XSDFEC_ECC_ISR_ADDR, ecc_err);
1165 xsdfec_regwrite(xsdfec, XSDFEC_ISR_ADDR, isr_err);
1166
1167 tmp = ecc_err & XSDFEC_ALL_ECC_ISR_MBE_MASK;
1168 /* Count uncorrectable 2-bit errors */
1169 uecc_count = hweight32(tmp);
1170 /* Count all ECC errors */
1171 aecc_count = hweight32(ecc_err);
1172 /* Number of correctable 1-bit ECC error */
1173 cecc_count = aecc_count - 2 * uecc_count;
1174 /* Count ISR errors */
1175 isr_err_count = hweight32(isr_err);
1176 dev_dbg(xsdfec->dev, "tmp=%x, uecc=%x, aecc=%x, cecc=%x, isr=%x", tmp,
1177 uecc_count, aecc_count, cecc_count, isr_err_count);
1178 dev_dbg(xsdfec->dev, "uecc=%x, cecc=%x, isr=%x", xsdfec->uecc_count,
1179 xsdfec->cecc_count, xsdfec->isr_err_count);
1180
1181 spin_lock_irqsave(&xsdfec->error_data_lock, xsdfec->flags);
1182 /* Add new errors to a 2-bits counter */
1183 if (uecc_count)
1184 xsdfec->uecc_count += uecc_count;
1185 /* Add new errors to a 1-bits counter */
1186 if (cecc_count)
1187 xsdfec->cecc_count += cecc_count;
1188 /* Add new errors to a ISR counter */
1189 if (isr_err_count)
1190 xsdfec->isr_err_count += isr_err_count;
1191
1192 /* Update state/stats flag */
1193 if (uecc_count) {
1194 if (ecc_err & XSDFEC_ECC_ISR_MBE_MASK)
1195 xsdfec->state = XSDFEC_NEEDS_RESET;
1196 else if (ecc_err & XSDFEC_PL_INIT_ECC_ISR_MBE_MASK)
1197 xsdfec->state = XSDFEC_PL_RECONFIGURE;
1198 xsdfec->stats_updated = true;
1199 xsdfec->state_updated = true;
1200 }
1201
1202 if (cecc_count)
1203 xsdfec->stats_updated = true;
1204
1205 if (isr_err_count) {
1206 xsdfec->state = XSDFEC_NEEDS_RESET;
1207 xsdfec->stats_updated = true;
1208 xsdfec->state_updated = true;
1209 }
1210
1211 spin_unlock_irqrestore(&xsdfec->error_data_lock, xsdfec->flags);
1212 dev_dbg(xsdfec->dev, "state=%x, stats=%x", xsdfec->state_updated,
1213 xsdfec->stats_updated);
1214
1215 /* Enable another polling */
1216 if (xsdfec->state_updated || xsdfec->stats_updated)
1217 wake_up_interruptible(&xsdfec->waitq);
1218 else
1219 ret = IRQ_NONE;
1220
1221 /* Unmask Interrupts */
1222 xsdfec_isr_enable(xsdfec, true);
1223 xsdfec_ecc_isr_enable(xsdfec, true);
1224
1225 return ret;
1226}
1227
1228static int xsdfec_clk_init(struct platform_device *pdev,
1229 struct xsdfec_clks *clks)
1230{
1231 int err;
1232
1233 clks->core_clk = devm_clk_get(&pdev->dev, "core_clk");
1234 if (IS_ERR(clks->core_clk)) {
1235 dev_err(&pdev->dev, "failed to get core_clk");
1236 return PTR_ERR(clks->core_clk);
1237 }
1238
1239 clks->axi_clk = devm_clk_get(&pdev->dev, "s_axi_aclk");
1240 if (IS_ERR(clks->axi_clk)) {
1241 dev_err(&pdev->dev, "failed to get axi_clk");
1242 return PTR_ERR(clks->axi_clk);
1243 }
1244
1245 clks->din_words_clk = devm_clk_get(&pdev->dev, "s_axis_din_words_aclk");
1246 if (IS_ERR(clks->din_words_clk)) {
1247 if (PTR_ERR(clks->din_words_clk) != -ENOENT) {
1248 err = PTR_ERR(clks->din_words_clk);
1249 return err;
1250 }
1251 clks->din_words_clk = NULL;
1252 }
1253
1254 clks->din_clk = devm_clk_get(&pdev->dev, "s_axis_din_aclk");
1255 if (IS_ERR(clks->din_clk)) {
1256 if (PTR_ERR(clks->din_clk) != -ENOENT) {
1257 err = PTR_ERR(clks->din_clk);
1258 return err;
1259 }
1260 clks->din_clk = NULL;
1261 }
1262
1263 clks->dout_clk = devm_clk_get(&pdev->dev, "m_axis_dout_aclk");
1264 if (IS_ERR(clks->dout_clk)) {
1265 if (PTR_ERR(clks->dout_clk) != -ENOENT) {
1266 err = PTR_ERR(clks->dout_clk);
1267 return err;
1268 }
1269 clks->dout_clk = NULL;
1270 }
1271
1272 clks->dout_words_clk =
1273 devm_clk_get(&pdev->dev, "s_axis_dout_words_aclk");
1274 if (IS_ERR(clks->dout_words_clk)) {
1275 if (PTR_ERR(clks->dout_words_clk) != -ENOENT) {
1276 err = PTR_ERR(clks->dout_words_clk);
1277 return err;
1278 }
1279 clks->dout_words_clk = NULL;
1280 }
1281
1282 clks->ctrl_clk = devm_clk_get(&pdev->dev, "s_axis_ctrl_aclk");
1283 if (IS_ERR(clks->ctrl_clk)) {
1284 if (PTR_ERR(clks->ctrl_clk) != -ENOENT) {
1285 err = PTR_ERR(clks->ctrl_clk);
1286 return err;
1287 }
1288 clks->ctrl_clk = NULL;
1289 }
1290
1291 clks->status_clk = devm_clk_get(&pdev->dev, "m_axis_status_aclk");
1292 if (IS_ERR(clks->status_clk)) {
1293 if (PTR_ERR(clks->status_clk) != -ENOENT) {
1294 err = PTR_ERR(clks->status_clk);
1295 return err;
1296 }
1297 clks->status_clk = NULL;
1298 }
1299
1300 err = clk_prepare_enable(clks->core_clk);
1301 if (err) {
1302 dev_err(&pdev->dev, "failed to enable core_clk (%d)", err);
1303 return err;
1304 }
1305
1306 err = clk_prepare_enable(clks->axi_clk);
1307 if (err) {
1308 dev_err(&pdev->dev, "failed to enable axi_clk (%d)", err);
1309 goto err_disable_core_clk;
1310 }
1311
1312 err = clk_prepare_enable(clks->din_clk);
1313 if (err) {
1314 dev_err(&pdev->dev, "failed to enable din_clk (%d)", err);
1315 goto err_disable_axi_clk;
1316 }
1317
1318 err = clk_prepare_enable(clks->din_words_clk);
1319 if (err) {
1320 dev_err(&pdev->dev, "failed to enable din_words_clk (%d)", err);
1321 goto err_disable_din_clk;
1322 }
1323
1324 err = clk_prepare_enable(clks->dout_clk);
1325 if (err) {
1326 dev_err(&pdev->dev, "failed to enable dout_clk (%d)", err);
1327 goto err_disable_din_words_clk;
1328 }
1329
1330 err = clk_prepare_enable(clks->dout_words_clk);
1331 if (err) {
1332 dev_err(&pdev->dev, "failed to enable dout_words_clk (%d)",
1333 err);
1334 goto err_disable_dout_clk;
1335 }
1336
1337 err = clk_prepare_enable(clks->ctrl_clk);
1338 if (err) {
1339 dev_err(&pdev->dev, "failed to enable ctrl_clk (%d)", err);
1340 goto err_disable_dout_words_clk;
1341 }
1342
1343 err = clk_prepare_enable(clks->status_clk);
1344 if (err) {
1345 dev_err(&pdev->dev, "failed to enable status_clk (%d)\n", err);
1346 goto err_disable_ctrl_clk;
1347 }
1348
1349 return err;
1350
1351err_disable_ctrl_clk:
1352 clk_disable_unprepare(clks->ctrl_clk);
1353err_disable_dout_words_clk:
1354 clk_disable_unprepare(clks->dout_words_clk);
1355err_disable_dout_clk:
1356 clk_disable_unprepare(clks->dout_clk);
1357err_disable_din_words_clk:
1358 clk_disable_unprepare(clks->din_words_clk);
1359err_disable_din_clk:
1360 clk_disable_unprepare(clks->din_clk);
1361err_disable_axi_clk:
1362 clk_disable_unprepare(clks->axi_clk);
1363err_disable_core_clk:
1364 clk_disable_unprepare(clks->core_clk);
1365
1366 return err;
1367}
1368
1369static void xsdfec_disable_all_clks(struct xsdfec_clks *clks)
1370{
1371 clk_disable_unprepare(clks->status_clk);
1372 clk_disable_unprepare(clks->ctrl_clk);
1373 clk_disable_unprepare(clks->dout_words_clk);
1374 clk_disable_unprepare(clks->dout_clk);
1375 clk_disable_unprepare(clks->din_words_clk);
1376 clk_disable_unprepare(clks->din_clk);
1377 clk_disable_unprepare(clks->core_clk);
1378 clk_disable_unprepare(clks->axi_clk);
1379}
1380
1381static int xsdfec_probe(struct platform_device *pdev)
1382{
1383 struct xsdfec_dev *xsdfec;
1384 struct device *dev;
1385 struct resource *res;
1386 int err;
1387 bool irq_enabled = true;
1388
1389 xsdfec = devm_kzalloc(&pdev->dev, sizeof(*xsdfec), GFP_KERNEL);
1390 if (!xsdfec)
1391 return -ENOMEM;
1392
1393 xsdfec->dev = &pdev->dev;
1394 spin_lock_init(&xsdfec->error_data_lock);
1395
1396 err = xsdfec_clk_init(pdev, &xsdfec->clks);
1397 if (err)
1398 return err;
1399
1400 dev = xsdfec->dev;
1401 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1402 xsdfec->regs = devm_ioremap_resource(dev, res);
1403 if (IS_ERR(xsdfec->regs)) {
1404 err = PTR_ERR(xsdfec->regs);
1405 goto err_xsdfec_dev;
1406 }
1407
1408 xsdfec->irq = platform_get_irq(pdev, 0);
1409 if (xsdfec->irq < 0) {
1410 dev_dbg(dev, "platform_get_irq failed");
1411 irq_enabled = false;
1412 }
1413
1414 err = xsdfec_parse_of(xsdfec);
1415 if (err < 0)
1416 goto err_xsdfec_dev;
1417
1418 update_config_from_hw(xsdfec);
1419
1420 /* Save driver private data */
1421 platform_set_drvdata(pdev, xsdfec);
1422
1423 if (irq_enabled) {
1424 init_waitqueue_head(&xsdfec->waitq);
1425 /* Register IRQ thread */
1426 err = devm_request_threaded_irq(dev, xsdfec->irq, NULL,
1427 xsdfec_irq_thread, IRQF_ONESHOT,
1428 "xilinx-sdfec16", xsdfec);
1429 if (err < 0) {
1430 dev_err(dev, "unable to request IRQ%d", xsdfec->irq);
1431 goto err_xsdfec_dev;
1432 }
1433 }
1434
1435 err = ida_alloc(&dev_nrs, GFP_KERNEL);
1436 if (err < 0)
1437 goto err_xsdfec_dev;
1438 xsdfec->dev_id = err;
1439
1440 snprintf(xsdfec->dev_name, DEV_NAME_LEN, "xsdfec%d", xsdfec->dev_id);
1441 xsdfec->miscdev.minor = MISC_DYNAMIC_MINOR;
1442 xsdfec->miscdev.name = xsdfec->dev_name;
1443 xsdfec->miscdev.fops = &xsdfec_fops;
1444 xsdfec->miscdev.parent = dev;
1445 err = misc_register(&xsdfec->miscdev);
1446 if (err) {
1447 dev_err(dev, "error:%d. Unable to register device", err);
1448 goto err_xsdfec_ida;
1449 }
1450 return 0;
1451
1452err_xsdfec_ida:
1453 ida_free(&dev_nrs, xsdfec->dev_id);
1454err_xsdfec_dev:
1455 xsdfec_disable_all_clks(&xsdfec->clks);
1456 return err;
1457}
1458
1459static int xsdfec_remove(struct platform_device *pdev)
1460{
1461 struct xsdfec_dev *xsdfec;
1462
1463 xsdfec = platform_get_drvdata(pdev);
1464 misc_deregister(&xsdfec->miscdev);
1465 ida_free(&dev_nrs, xsdfec->dev_id);
1466 xsdfec_disable_all_clks(&xsdfec->clks);
1467 return 0;
1468}
1469
1470static const struct of_device_id xsdfec_of_match[] = {
1471 {
1472 .compatible = "xlnx,sd-fec-1.1",
1473 },
1474 { /* end of table */ }
1475};
1476MODULE_DEVICE_TABLE(of, xsdfec_of_match);
1477
1478static struct platform_driver xsdfec_driver = {
1479 .driver = {
1480 .name = "xilinx-sdfec",
1481 .of_match_table = xsdfec_of_match,
1482 },
1483 .probe = xsdfec_probe,
1484 .remove = xsdfec_remove,
1485};
1486
1487static int __init xsdfec_init(void)
1488{
1489 int err;
1490
1491 err = platform_driver_register(&xsdfec_driver);
1492 if (err < 0) {
1493 pr_err("%s Unabled to register SDFEC driver", __func__);
1494 return err;
1495 }
1496 return 0;
1497}
1498
1499static void __exit xsdfec_exit(void)
1500{
1501 platform_driver_unregister(&xsdfec_driver);
1502}
1503
1504module_init(xsdfec_init);
1505module_exit(xsdfec_exit);
1506
1507MODULE_AUTHOR("Xilinx, Inc");
1508MODULE_DESCRIPTION("Xilinx SD-FEC16 Driver");
1509MODULE_LICENSE("GPL");