cvmx-raid.c revision 215990
1/***********************license start*************** 2 * Copyright (c) 2003-2010 Cavium Networks (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 Networks 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 NETWORKS 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: 49448 $<hr> 52 */ 53#include "executive-config.h" 54#include "cvmx-config.h" 55#include "cvmx.h" 56#include "cvmx-cmd-queue.h" 57#include "cvmx-raid.h" 58 59#ifdef CVMX_ENABLE_PKO_FUNCTIONS 60 61/** 62 * Initialize the RAID block 63 * 64 * @param polynomial Coefficients for the RAID polynomial 65 * 66 * @return Zero on success, negative on failure 67 */ 68int cvmx_raid_initialize(cvmx_rad_reg_polynomial_t polynomial) 69{ 70 cvmx_cmd_queue_result_t result; 71 cvmx_rad_reg_cmd_buf_t rad_reg_cmd_buf; 72 73 cvmx_write_csr(CVMX_RAD_REG_POLYNOMIAL, polynomial.u64); 74 75 result = cvmx_cmd_queue_initialize(CVMX_CMD_QUEUE_RAID, 0, 76 CVMX_FPA_OUTPUT_BUFFER_POOL, 77 CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE); 78 if (result != CVMX_CMD_QUEUE_SUCCESS) 79 return -1; 80 81 rad_reg_cmd_buf.u64 = 0; 82 rad_reg_cmd_buf.s.dwb = CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE/128; 83 rad_reg_cmd_buf.s.pool = CVMX_FPA_OUTPUT_BUFFER_POOL; 84 rad_reg_cmd_buf.s.size = CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE/8; 85 rad_reg_cmd_buf.s.ptr = cvmx_ptr_to_phys(cvmx_cmd_queue_buffer(CVMX_CMD_QUEUE_RAID))>>7; 86 cvmx_write_csr(CVMX_RAD_REG_CMD_BUF, rad_reg_cmd_buf.u64); 87 return 0; 88} 89 90 91/** 92 * Shutdown the RAID block. RAID must be idle when 93 * this function is called. 94 * 95 * @return Zero on success, negative on failure 96 */ 97int cvmx_raid_shutdown(void) 98{ 99 cvmx_rad_reg_ctl_t rad_reg_ctl; 100 101 if (cvmx_cmd_queue_length(CVMX_CMD_QUEUE_RAID)) 102 { 103 cvmx_dprintf("ERROR: cvmx_raid_shutdown: RAID not idle.\n"); 104 return -1; 105 } 106 107 rad_reg_ctl.u64 = cvmx_read_csr(CVMX_RAD_REG_CTL); 108 rad_reg_ctl.s.reset = 1; 109 cvmx_write_csr(CVMX_RAD_REG_CTL, rad_reg_ctl.u64); 110 cvmx_wait(100); 111 112 cvmx_cmd_queue_shutdown(CVMX_CMD_QUEUE_RAID); 113 cvmx_write_csr(CVMX_RAD_REG_CMD_BUF, 0); 114 return 0; 115} 116 117 118/** 119 * Submit a command to the RAID block 120 * 121 * @param num_words Number of command words to submit 122 * @param words Command words 123 * 124 * @return Zero on success, negative on failure 125 */ 126int cvmx_raid_submit(int num_words, cvmx_raid_word_t words[]) 127{ 128 cvmx_cmd_queue_result_t result = cvmx_cmd_queue_write(CVMX_CMD_QUEUE_RAID, 1, num_words, (uint64_t *)words); 129 if (result == CVMX_CMD_QUEUE_SUCCESS) 130 cvmx_write_csr(CVMX_ADDR_DID(CVMX_FULL_DID(14, 0)), num_words); 131 return result; 132} 133 134#endif 135