cvmx-raid.c revision 210286
1/***********************license start*************** 2 * Copyright (c) 2003-2008 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 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 24 * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS 25 * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH 26 * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY 27 * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT 28 * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES 29 * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR 30 * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET 31 * POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT 32 * OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU. 33 * 34 * 35 * For any questions regarding licensing please contact marketing@caviumnetworks.com 36 * 37 ***********************license end**************************************/ 38 39 40 41 42 43 44/** 45 * @file 46 * 47 * Interface to RAID block. This is not available on all chips. 48 * 49 * <hr>$Revision: 41586 $<hr> 50 */ 51#include "executive-config.h" 52#include "cvmx-config.h" 53#include "cvmx.h" 54#include "cvmx-cmd-queue.h" 55#include "cvmx-raid.h" 56 57#ifdef CVMX_ENABLE_PKO_FUNCTIONS 58 59/** 60 * Initialize the RAID block 61 * 62 * @param polynomial Coefficients for the RAID polynomial 63 * 64 * @return Zero on success, negative on failure 65 */ 66int cvmx_raid_initialize(cvmx_rad_reg_polynomial_t polynomial) 67{ 68 cvmx_cmd_queue_result_t result; 69 cvmx_rad_reg_cmd_buf_t rad_reg_cmd_buf; 70 71 cvmx_write_csr(CVMX_RAD_REG_POLYNOMIAL, polynomial.u64); 72 73 result = cvmx_cmd_queue_initialize(CVMX_CMD_QUEUE_RAID, 0, 74 CVMX_FPA_OUTPUT_BUFFER_POOL, 75 CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE); 76 if (result != CVMX_CMD_QUEUE_SUCCESS) 77 return -1; 78 79 rad_reg_cmd_buf.u64 = 0; 80 rad_reg_cmd_buf.s.dwb = CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE/128; 81 rad_reg_cmd_buf.s.pool = CVMX_FPA_OUTPUT_BUFFER_POOL; 82 rad_reg_cmd_buf.s.size = CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE/8; 83 rad_reg_cmd_buf.s.ptr = cvmx_ptr_to_phys(cvmx_cmd_queue_buffer(CVMX_CMD_QUEUE_RAID))>>7; 84 cvmx_write_csr(CVMX_RAD_REG_CMD_BUF, rad_reg_cmd_buf.u64); 85 return 0; 86} 87 88 89/** 90 * Shutdown the RAID block. RAID must be idle when 91 * this function is called. 92 * 93 * @return Zero on success, negative on failure 94 */ 95int cvmx_raid_shutdown(void) 96{ 97 cvmx_rad_reg_ctl_t rad_reg_ctl; 98 99 if (cvmx_cmd_queue_length(CVMX_CMD_QUEUE_RAID)) 100 { 101 cvmx_dprintf("ERROR: cvmx_raid_shutdown: RAID not idle.\n"); 102 return -1; 103 } 104 105 rad_reg_ctl.u64 = cvmx_read_csr(CVMX_RAD_REG_CTL); 106 rad_reg_ctl.s.reset = 1; 107 cvmx_write_csr(CVMX_RAD_REG_CTL, rad_reg_ctl.u64); 108 cvmx_wait(100); 109 110 cvmx_cmd_queue_shutdown(CVMX_CMD_QUEUE_RAID); 111 cvmx_write_csr(CVMX_RAD_REG_CMD_BUF, 0); 112 return 0; 113} 114 115 116/** 117 * Submit a command to the RAID block 118 * 119 * @param num_words Number of command words to submit 120 * @param words Command words 121 * 122 * @return Zero on success, negative on failure 123 */ 124int cvmx_raid_submit(int num_words, cvmx_raid_word_t words[]) 125{ 126 cvmx_cmd_queue_result_t result = cvmx_cmd_queue_write(CVMX_CMD_QUEUE_RAID, 1, num_words, (uint64_t *)words); 127 if (result == CVMX_CMD_QUEUE_SUCCESS) 128 cvmx_write_csr(CVMX_ADDR_DID(CVMX_FULL_DID(14, 0)), num_words); 129 return result; 130} 131 132#endif 133