]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/contrib/octeon-sdk/cvmx-raid.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / contrib / octeon-sdk / cvmx-raid.c
1 /***********************license start***************
2  * Copyright (c) 2003-2010  Cavium Inc. (support@cavium.com). All rights
3  * reserved.
4  *
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  *   * Redistributions of source code must retain the above copyright
11  *     notice, this list of conditions and the following disclaimer.
12  *
13  *   * Redistributions in binary form must reproduce the above
14  *     copyright notice, this list of conditions and the following
15  *     disclaimer in the documentation and/or other materials provided
16  *     with the distribution.
17
18  *   * Neither the name of Cavium Inc. nor the names of
19  *     its contributors may be used to endorse or promote products
20  *     derived from this software without specific prior written
21  *     permission.
22
23  * This Software, including technical data, may be subject to U.S. export  control
24  * laws, including the U.S. Export Administration Act and its  associated
25  * regulations, and may be subject to export or import  regulations in other
26  * countries.
27
28  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29  * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
30  * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31  * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32  * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33  * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34  * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35  * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36  * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
37  * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38  ***********************license end**************************************/
39
40
41
42
43
44
45
46 /**
47  * @file
48  *
49  * Interface to RAID block. This is not available on all chips.
50  *
51  * <hr>$Revision: 70030 $<hr>
52  */
53 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
54 #include <linux/module.h>
55 #include <asm/octeon/cvmx.h>
56 #include <asm/octeon/cvmx-config.h>
57 #include <asm/octeon/cvmx-cmd-queue.h>
58 #include <asm/octeon/cvmx-raid.h>
59 #else
60 #include "executive-config.h"
61 #include "cvmx-config.h"
62 #include "cvmx.h"
63 #include "cvmx-cmd-queue.h"
64 #include "cvmx-raid.h"
65 #endif
66
67 #ifdef CVMX_ENABLE_PKO_FUNCTIONS
68
69 /**
70  * Initialize the RAID block
71  *
72  * @param polynomial Coefficients for the RAID polynomial
73  *
74  * @return Zero on success, negative on failure
75  */
76 int cvmx_raid_initialize(cvmx_rad_reg_polynomial_t polynomial)
77 {
78     cvmx_cmd_queue_result_t result;
79     cvmx_rad_reg_cmd_buf_t rad_reg_cmd_buf;
80
81     cvmx_write_csr(CVMX_RAD_REG_POLYNOMIAL, polynomial.u64);
82
83     result = cvmx_cmd_queue_initialize(CVMX_CMD_QUEUE_RAID, 0,
84                                        CVMX_FPA_OUTPUT_BUFFER_POOL,
85                                        CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE);
86     if (result != CVMX_CMD_QUEUE_SUCCESS)
87         return -1;
88
89     rad_reg_cmd_buf.u64 = 0;
90     rad_reg_cmd_buf.s.dwb = CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE/128;
91     rad_reg_cmd_buf.s.pool = CVMX_FPA_OUTPUT_BUFFER_POOL;
92     rad_reg_cmd_buf.s.size = CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE/8;
93     rad_reg_cmd_buf.s.ptr = cvmx_ptr_to_phys(cvmx_cmd_queue_buffer(CVMX_CMD_QUEUE_RAID))>>7;
94     cvmx_write_csr(CVMX_RAD_REG_CMD_BUF, rad_reg_cmd_buf.u64);
95     return 0;
96 }
97 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
98 EXPORT_SYMBOL(cvmx_raid_initialize);
99 #endif
100
101 /**
102  * Shutdown the RAID block. RAID must be idle when
103  * this function is called.
104  *
105  * @return Zero on success, negative on failure
106  */
107 int cvmx_raid_shutdown(void)
108 {
109     cvmx_rad_reg_ctl_t rad_reg_ctl;
110
111     if (cvmx_cmd_queue_length(CVMX_CMD_QUEUE_RAID))
112     {
113         cvmx_dprintf("ERROR: cvmx_raid_shutdown: RAID not idle.\n");
114         return -1;
115     }
116
117     rad_reg_ctl.u64 = cvmx_read_csr(CVMX_RAD_REG_CTL);
118     rad_reg_ctl.s.reset = 1;
119     cvmx_write_csr(CVMX_RAD_REG_CTL, rad_reg_ctl.u64);
120     cvmx_wait(100);
121
122     cvmx_cmd_queue_shutdown(CVMX_CMD_QUEUE_RAID);
123     cvmx_write_csr(CVMX_RAD_REG_CMD_BUF, 0);
124     return 0;
125 }
126 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
127 EXPORT_SYMBOL(cvmx_raid_shutdown);
128 #endif
129
130 /**
131  * Submit a command to the RAID block
132  *
133  * @param num_words Number of command words to submit
134  * @param words     Command words
135  *
136  * @return Zero on success, negative on failure
137  */
138 int cvmx_raid_submit(int num_words, cvmx_raid_word_t words[])
139 {
140     cvmx_cmd_queue_result_t result = cvmx_cmd_queue_write(CVMX_CMD_QUEUE_RAID, 1, num_words, (uint64_t *)words);
141     if (result == CVMX_CMD_QUEUE_SUCCESS)
142         cvmx_write_csr(CVMX_ADDR_DID(CVMX_FULL_DID(14, 0)), num_words);
143     return result;
144 }
145 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
146 EXPORT_SYMBOL(cvmx_raid_submit);
147 #endif
148 #endif